This commit is contained in:
2026-01-16 01:52:05 +01:00
parent 2d408719ac
commit 38c746d45b

View File

@@ -830,6 +830,29 @@
.replace(/ /g, '')
.trim();
};
const syncFromDom = (model, reason) => {
const target = resolveTextModel(model);
if (!isTextLike(target)) return;
const el = target && target.view && target.view.el;
if (!el) return;
const html = String(el.innerHTML || '').trim();
if (!html) return;
try {
if (target.set) {
target.set('content', html);
target.trigger && target.trigger('change:content');
target.trigger && target.trigger('change:components');
}
try {
console.warn('[INLINE SYNC]', {
reason,
htmlLen: html.length,
modelType: target.get && target.get('type'),
modelId: target.getId ? target.getId() : target.get && target.get('id'),
});
} catch {}
} catch {}
};
const snapshotContent = (model) => {
const rawContent = model && model.get ? model.get('content') : '';
const el = model.view && model.view.el;
@@ -886,8 +909,14 @@
} catch {}
};
editor.on('component:update', (model) => restoreIfEmpty(model));
editor.on('component:input', (model) => restoreIfEmpty(model));
editor.on('component:deselected', (model) => restoreIfEmpty(model));
editor.on('component:input', (model) => {
syncFromDom(model, 'component:input');
restoreIfEmpty(model);
});
editor.on('component:deselected', (model) => {
syncFromDom(model, 'component:deselected');
restoreIfEmpty(model);
});
editor.on('component:add', (model) => rememberIfPresent(model));
editor.on('rte:disable', (model) => {
const target = model || (editor.getSelected && editor.getSelected());