This commit is contained in:
2026-01-28 01:15:25 +01:00
parent 67cf3bbd27
commit 5a788448dd
3 changed files with 29 additions and 21 deletions

View File

@@ -428,6 +428,7 @@
const syncTextFromViewOnDeselect = (model) => {
const target = resolveTextModel(model);
if (!isTextLike(target) || !target.view || !target.view.el || syncing.has(target)) return;
if (window.__bridgeRteOpen) return;
const viewHtml = normalizeViewHtmlForModel(target.view.el.innerHTML || '');
if (!viewHtml) return;
const modelHtml = normalizeViewHtmlForModel(target.get ? target.get('content') || '' : '');
@@ -459,11 +460,35 @@
syncing.delete(target);
}
};
const syncTextFromViewOnInput = (model) => {
const target = resolveTextModel(model);
if (!isTextLike(target) || !target.view || !target.view.el || syncing.has(target)) return;
if (window.__bridgeRteOpen) return;
const viewHtml = normalizeViewHtmlForModel(target.view.el.innerHTML || '');
if (!viewHtml) return;
const modelHtml = normalizeViewHtmlForModel(target.get ? target.get('content') || '' : '');
const comps = target.components ? target.components() : null;
const hasComps = !!(comps && comps.length);
if (viewHtml === modelHtml && hasComps) return;
try {
syncing.add(target);
if (target.components) {
try { target.components(viewHtml); } catch {}
}
if (target.set) target.set('content', viewHtml);
target.trigger && target.trigger('change:content');
} catch {} finally {
syncing.delete(target);
}
};
editor.on('component:update', (model) => {
restoreIfEmpty(model);
ensureViewMatchesModel(model);
});
editor.on('component:input', (model) => restoreIfEmpty(model));
editor.on('component:input', (model) => {
syncTextFromViewOnInput(model);
restoreIfEmpty(model);
});
editor.on('component:deselected', (model) => {
syncTextFromViewOnDeselect(model);
restoreIfEmpty(model);
@@ -480,25 +505,6 @@
try {
const modelType = model && model.get ? model.get('type') : undefined;
const selectedEl = model && model.view && model.view.el;
const normalizeViewHtmlForModel = (html) => {
return String(html || '')
.replace(/<br\b[^>]*>/gi, '<br>')
.replace(/\sdata-gjs-type="[^"]*"/gi, '')
.replace(/\sdraggable="[^"]*"/gi, '')
.replace(/\scontenteditable="[^"]*"/gi, '')
.trim();
};
if (label === 'DESELECT' && modelType === 'text' && selectedEl) {
try {
const viewHtml = normalizeViewHtmlForModel(selectedEl.innerHTML || '');
if (viewHtml && model && model.set) {
if (model.components) {
try { model.components(viewHtml); } catch {}
}
model.set('content', viewHtml);
}
} catch {}
}
const viewOuter = selectedEl ? String(selectedEl.outerHTML || '') : '';
const modelContent = model && model.get ? String(model.get('content') || '') : '';
const editorHtml = editor && typeof editor.getHtml === 'function' ? String(editor.getHtml() || '') : '';