This commit is contained in:
2026-01-28 00:30:36 +01:00
parent a7a936fac2
commit 779f3adb45
3 changed files with 17 additions and 50 deletions

View File

@@ -1 +1 @@
1.1.36 1.1.37

View File

@@ -173,31 +173,6 @@
const isText = (component.is && component.is('text')) const isText = (component.is && component.is('text'))
|| (component.get && component.get('type') === 'text'); || (component.get && component.get('type') === 'text');
try { try {
if (isText && component.components) {
try {
const comps = component.components();
if (comps && comps.reset) comps.reset();
} catch {}
try {
const wrapper = document.createElement('div');
wrapper.innerHTML = content;
const newComps = [];
wrapper.childNodes.forEach((node) => {
if (node.nodeType === 3) {
const text = node.textContent || '';
newComps.push({ type: 'textnode', content: text });
} 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);
}
}
});
component.components(newComps.length ? newComps : content);
} catch {}
}
if (component.set) component.set('content', content); if (component.set) component.set('content', content);
} catch {} } catch {}
if (component.view && typeof component.view.render === 'function') { if (component.view && typeof component.view.render === 'function') {

View File

@@ -360,23 +360,13 @@
normalized: normalizeHtml(composite), normalized: normalizeHtml(composite),
}; };
}; };
const buildTextComponentsFromHtml = (html) => { const normalizeViewHtmlForModel = (html) => {
const wrapper = document.createElement('div'); return String(html || '')
wrapper.innerHTML = String(html || ''); .replace(/<br\b[^>]*>/gi, '<br>')
const newComps = []; .replace(/\sdata-gjs-type="[^"]*"/gi, '')
wrapper.childNodes.forEach((node) => { .replace(/\sdraggable="[^"]*"/gi, '')
if (node.nodeType === 3) { .replace(/\scontenteditable="[^"]*"/gi, '')
newComps.push({ type: 'textnode', content: node.textContent || '' }); .trim();
} 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 storeSnapshot = (model, snap) => { const storeSnapshot = (model, snap) => {
if (!model || !snap) return; if (!model || !snap) return;
@@ -413,9 +403,6 @@
: null); : null);
if (!stored || !stored.normalized) return; if (!stored || !stored.normalized) return;
try { try {
if (target.components) {
target.components(buildTextComponentsFromHtml(stored.html));
}
target.set('content', stored.html); target.set('content', stored.html);
target.trigger && target.trigger('change:content'); target.trigger && target.trigger('change:content');
try { console.log('[PLAIN TEXT RESTORE] Inhalt wiederhergestellt.'); } catch {} try { console.log('[PLAIN TEXT RESTORE] Inhalt wiederhergestellt.'); } catch {}
@@ -441,18 +428,23 @@
const syncTextFromViewOnDeselect = (model) => { const syncTextFromViewOnDeselect = (model) => {
const target = resolveTextModel(model); const target = resolveTextModel(model);
if (!isTextLike(target) || !target.view || !target.view.el || syncing.has(target)) return; 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; if (!viewHtml) return;
const modelHtml = String(target.get ? target.get('content') || '' : '').trim(); const modelHtml = normalizeViewHtmlForModel(target.get ? target.get('content') || '' : '');
if (viewHtml === modelHtml) return; if (viewHtml === modelHtml) return;
try { try {
syncing.add(target); syncing.add(target);
if (target.components) target.components(buildTextComponentsFromHtml(viewHtml));
if (target.set) target.set('content', viewHtml); if (target.set) target.set('content', viewHtml);
target.trigger && target.trigger('change:content'); 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 = () => { const reapply = () => {
try { try {
const current = String(target.view.el.innerHTML || '').trim(); const current = normalizeViewHtmlForModel(target.view.el.innerHTML || '');
if (current !== viewHtml) target.view.el.innerHTML = viewHtml; if (current !== viewHtml) target.view.el.innerHTML = viewHtml;
} catch {} } catch {}
}; };