fix(creator-studio): delete selected hidden blocks reliably

This commit is contained in:
kate522 committed 2026-11-10 20:01:16 +08:00
1 parent 304c59c8f3
commit d391b0fd00
4 files changed
+124 -21

No files matched your search

@@ -136,12 +136,12 @@ export const HIDE_BLOCKS: Record<HideKind, { open: string; close: string; label:
*
* .hide-before 里的短代码文本通过 CSS 的 font-size:0 隐藏,只显示 data-jio-hide-label;
* .hide-after 与前台投稿编辑器一致地保持 display:none。两者都留在 DOM 里,保存时
* 不需要额外的序列化转换。
* 不需要额外的序列化转换。外层不可编辑,只有正文子容器可编辑。
*/
export function hiddenContentMarkup(kind: HideKind, innerHtml: string): string {
const def = HIDE_BLOCKS[kind];
return (
`<div class="tinymce-hide" data-jio-hide-type="${kind}">` +
`<div class="tinymce-hide" data-jio-hide-type="${kind}" contenteditable="false">` +
`<p class="hide-before" data-jio-hide-label="${escapeHtml(def.label)}">${escapeHtml(def.open)}</p>` +
`<div contenteditable="true">${normalizeInner(innerHtml)}</div>` +
`<p class="hide-after">${escapeHtml(def.close)}</p>` +
@@ -154,6 +154,10 @@ export function hydrateBlocks(html: string): string {
container.innerHTML = html;
container.querySelectorAll('pre').forEach((pre) => hydrateCodeBlock(pre));
container.querySelectorAll<HTMLElement>('.tinymce-hide').forEach((block) => {
block.setAttribute('contenteditable', 'false');
block.querySelector(':scope > div')?.setAttribute('contenteditable', 'true');
});
container.querySelectorAll('p').forEach((paragraph) => {
const match = paragraph.textContent?.trim().match(/^\[jio_math display="1"\]([\s\S]*?)\[\/jio_math\]$/);
if (!match) {