asasss
This commit is contained in:
@@ -360,23 +360,13 @@
|
||||
normalized: normalizeHtml(composite),
|
||||
};
|
||||
};
|
||||
const buildTextComponentsFromHtml = (html) => {
|
||||
const wrapper = document.createElement('div');
|
||||
wrapper.innerHTML = String(html || '');
|
||||
const newComps = [];
|
||||
wrapper.childNodes.forEach((node) => {
|
||||
if (node.nodeType === 3) {
|
||||
newComps.push({ type: 'textnode', content: node.textContent || '' });
|
||||
} else if (node.nodeType === 1) {
|
||||
const tag = node.tagName ? node.tagName.toLowerCase() : '';
|
||||
if (tag === 'br') {
|
||||
newComps.push({ tagName: 'br', void: true });
|
||||
} else {
|
||||
newComps.push(node.outerHTML);
|
||||
}
|
||||
}
|
||||
});
|
||||
return newComps.length ? newComps : html;
|
||||
const normalizeViewHtmlForModel = (html) => {
|
||||
return String(html || '')
|
||||
.replace(/<br\b[^>]*>/gi, '<br>')
|
||||
.replace(/\sdata-gjs-type="[^"]*"/gi, '')
|
||||
.replace(/\sdraggable="[^"]*"/gi, '')
|
||||
.replace(/\scontenteditable="[^"]*"/gi, '')
|
||||
.trim();
|
||||
};
|
||||
const storeSnapshot = (model, snap) => {
|
||||
if (!model || !snap) return;
|
||||
@@ -413,9 +403,6 @@
|
||||
: null);
|
||||
if (!stored || !stored.normalized) return;
|
||||
try {
|
||||
if (target.components) {
|
||||
target.components(buildTextComponentsFromHtml(stored.html));
|
||||
}
|
||||
target.set('content', stored.html);
|
||||
target.trigger && target.trigger('change:content');
|
||||
try { console.log('[PLAIN TEXT RESTORE] Inhalt wiederhergestellt.'); } catch {}
|
||||
@@ -441,18 +428,23 @@
|
||||
const syncTextFromViewOnDeselect = (model) => {
|
||||
const target = resolveTextModel(model);
|
||||
if (!isTextLike(target) || !target.view || !target.view.el || syncing.has(target)) return;
|
||||
const viewHtml = String(target.view.el.innerHTML || '').trim();
|
||||
const viewHtml = normalizeViewHtmlForModel(target.view.el.innerHTML || '');
|
||||
if (!viewHtml) return;
|
||||
const modelHtml = String(target.get ? target.get('content') || '' : '').trim();
|
||||
const modelHtml = normalizeViewHtmlForModel(target.get ? target.get('content') || '' : '');
|
||||
if (viewHtml === modelHtml) return;
|
||||
try {
|
||||
syncing.add(target);
|
||||
if (target.components) target.components(buildTextComponentsFromHtml(viewHtml));
|
||||
if (target.set) target.set('content', viewHtml);
|
||||
target.trigger && target.trigger('change:content');
|
||||
if (target.view && typeof target.view.render === 'function') {
|
||||
target.view.render();
|
||||
}
|
||||
if (editor && typeof editor.trigger === 'function') {
|
||||
editor.trigger('component:update', target);
|
||||
}
|
||||
const reapply = () => {
|
||||
try {
|
||||
const current = String(target.view.el.innerHTML || '').trim();
|
||||
const current = normalizeViewHtmlForModel(target.view.el.innerHTML || '');
|
||||
if (current !== viewHtml) target.view.el.innerHTML = viewHtml;
|
||||
} catch {}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user