From 96ffb00527b9e0f8359724e6c20966aba670cb81 Mon Sep 17 00:00:00 2001 From: Lars Gebhardt-Kusche Date: Wed, 28 Jan 2026 23:58:28 +0100 Subject: [PATCH] asddd --- config/current.ver | 2 +- public/editor/bridge-core.js | 93 +++++++++++++++++++++++++----------- 2 files changed, 65 insertions(+), 30 deletions(-) diff --git a/config/current.ver b/config/current.ver index 3361394..b1471d3 100644 --- a/config/current.ver +++ b/config/current.ver @@ -1 +1 @@ -1.1.48 \ No newline at end of file +1.1.49 \ No newline at end of file diff --git a/public/editor/bridge-core.js b/public/editor/bridge-core.js index 72f3588..37038de 100644 --- a/public/editor/bridge-core.js +++ b/public/editor/bridge-core.js @@ -368,6 +368,33 @@ .replace(/\scontenteditable="[^"]*"/gi, '') .trim(); }; + const getModelHtml = (model) => { + if (!model) return ''; + let html = ''; + try { + html = String(model.get ? model.get('content') || '' : '').trim(); + } catch {} + if (!html && model.components) { + try { + const comps = model.components(); + if (comps && typeof comps.toHTML === 'function') { + html = String(comps.toHTML() || '').trim(); + } + } catch {} + } + if (!html && typeof model.toHTML === 'function') { + try { + const full = String(model.toHTML() || '').trim(); + if (full) { + const wrapper = document.createElement('div'); + wrapper.innerHTML = full; + const first = wrapper.firstElementChild; + html = first ? String(first.innerHTML || '').trim() : String(wrapper.innerHTML || '').trim(); + } + } catch {} + } + return html; + }; const storeSnapshot = (model, snap) => { if (!model || !snap) return; const key = model.cid || model; @@ -413,7 +440,7 @@ if (!isTextLike(target) || !target.view || !target.view.el) return; const el = target.view.el; if (el.isContentEditable || el.getAttribute('contenteditable') === 'true') return; - const modelHtml = String(target.get ? target.get('content') || '' : '').trim(); + const modelHtml = String(getModelHtml(target) || '').trim(); if (!modelHtml) return; const viewHtml = String(el.innerHTML || '').trim(); if (viewHtml) return; @@ -433,17 +460,12 @@ if (window.__bridgeRteOpen) return; const viewHtml = normalizeViewHtmlForModel(target.view.el.innerHTML || ''); if (!viewHtml) return; - const modelHtml = normalizeViewHtmlForModel(target.get ? target.get('content') || '' : ''); + const modelHtml = normalizeViewHtmlForModel(getModelHtml(target)); if (viewHtml === modelHtml) return; try { syncing.add(target); if (target.components) { - try { - const comps = target.components(); - if (!comps || !comps.length) { - target.components(viewHtml); - } - } catch {} + try { target.components(viewHtml); } catch {} } if (target.set) target.set('content', viewHtml); target.trigger && target.trigger('change:content'); @@ -471,18 +493,14 @@ if (window.__bridgeRteOpen) return; const viewHtml = normalizeViewHtmlForModel(target.view.el.innerHTML || ''); if (!viewHtml) return; - const modelHtml = normalizeViewHtmlForModel(target.get ? target.get('content') || '' : ''); + const modelHtml = normalizeViewHtmlForModel(getModelHtml(target)); 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 { - if (!hasComps) { - target.components(viewHtml); - } - } catch {} + try { target.components(viewHtml); } catch {} } if (target.set) target.set('content', viewHtml); target.trigger && target.trigger('change:content'); @@ -516,12 +534,39 @@ const setupBlurLogger = (editor) => { if (!editor || !editor.Canvas || !editor.Canvas.getBody) return; + const getModelHtmlForLog = (model) => { + if (!model) return ''; + let html = ''; + try { + html = String(model.get ? model.get('content') || '' : '').trim(); + } catch {} + if (!html && model.components) { + try { + const comps = model.components(); + if (comps && typeof comps.toHTML === 'function') { + html = String(comps.toHTML() || '').trim(); + } + } catch {} + } + if (!html && typeof model.toHTML === 'function') { + try { + const full = String(model.toHTML() || '').trim(); + if (full) { + const wrapper = document.createElement('div'); + wrapper.innerHTML = full; + const first = wrapper.firstElementChild; + html = first ? String(first.innerHTML || '').trim() : String(wrapper.innerHTML || '').trim(); + } + } catch {} + } + return html; + }; const logComponentInput = (model, label) => { try { const modelType = model && model.get ? model.get('type') : undefined; const selectedEl = model && model.view && model.view.el; const viewOuter = selectedEl ? String(selectedEl.outerHTML || '') : ''; - const modelContent = model && model.get ? String(model.get('content') || '') : ''; + const modelContent = String(getModelHtmlForLog(model) || ''); const editorHtml = editor && typeof editor.getHtml === 'function' ? String(editor.getHtml() || '') : ''; console.warn(`[UI EDIT ${label}]`, { modelType, @@ -575,7 +620,7 @@ const buildSnapshot = (target, selected, selectedEl, editorHtml) => { let modelContent = ''; try { - modelContent = selected && selected.get ? String(selected.get('content') || '') : ''; + modelContent = String(getModelHtmlForLog(selected) || ''); } catch {} let viewOuter = ''; try { @@ -616,17 +661,12 @@ if (!viewEl) return; const viewHtml = normalizeViewHtml(viewEl.innerHTML || ''); if (!viewHtml) return; - const modelHtml = normalizeViewHtml(component.get ? component.get('content') || '' : ''); + const modelHtml = normalizeViewHtml(getModelHtml(component)); if (viewHtml === modelHtml) return; try { syncing.add(component); if (component.components) { - try { - const comps = component.components(); - if (!comps || !comps.length) { - component.components(viewHtml); - } - } catch {} + try { component.components(viewHtml); } catch {} } if (component.set) component.set('content', viewHtml); component.trigger && component.trigger('change:content'); @@ -693,12 +733,7 @@ if (!viewHtml) return; syncing.add(selected); if (selected.components) { - try { - const comps = selected.components(); - if (!comps || !comps.length) { - selected.components(viewHtml); - } - } catch {} + try { selected.components(viewHtml); } catch {} } if (selected.set) selected.set('content', viewHtml); selected.trigger && selected.trigger('change:content');