This commit is contained in:
2026-02-05 00:32:32 +01:00
parent 7813b4401d
commit e8a4967296
3 changed files with 37 additions and 62 deletions

View File

@@ -480,13 +480,14 @@
return;
}
// Minimaler Sync: nur aktives Text-Element (Selection) in das Model schreiben
// Kein aktives Sync mehr vor dem Speichern, nur Logging
try {
const doc = editor.Canvas && editor.Canvas.getDocument ? editor.Canvas.getDocument() : null;
const active = doc && doc.activeElement;
const selectionNode = doc && doc.getSelection ? (doc.getSelection().focusNode || doc.getSelection().anchorNode) : null;
const selectionEl = selectionNode ? (selectionNode.nodeType === 1 ? selectionNode : selectionNode.parentElement) : null;
const selected = editor.getSelected && editor.getSelected();
<<<<<<< ours
let syncResult = null;
let syncReason = 'no-editable-selection';
@@ -509,11 +510,37 @@
return false;
};
const win = doc && doc.defaultView;
const lastEl = win && win.__bridgeLastEditableEl;
const lastCompId = win && win.__bridgeLastEditableCompId;
<<<<<<< ours
<<<<<<< ours
<<<<<<< ours
// 1) Selection im DOM suchen (bevorzugt)
=======
=======
>>>>>>> theirs
// 1) Bevorzugt: ausgewähltes Component-Element aus der View
if (selected) {
const selEl = (selected.getEl && selected.getEl()) || (selected.view && selected.view.el);
if (selEl && (selEl.isContentEditable || (selEl.getAttribute && selEl.getAttribute('contenteditable') === 'true'))) {
syncFromElement(selected, selEl, 'selected:view');
}
<<<<<<< ours
}
// 2) Fallback: Selection im DOM suchen
>>>>>>> theirs
=======
// 1) Wenn ein ContentEditable aktiv ist, Blur auslösen, damit GrapesJS den Model-Content übernimmt
if (active && (active.isContentEditable || (active.getAttribute && active.getAttribute('contenteditable') === 'true'))) {
try {
active.dispatchEvent(new Event('blur', { bubbles: true }));
syncReason = 'blur:dispatched';
} catch {}
=======
>>>>>>> theirs
}
// 2) Fallback: Selection im DOM suchen
>>>>>>> theirs
if (!syncResult && doc && selectionEl && (selectionEl.isContentEditable || (selectionEl.getAttribute && selectionEl.getAttribute('contenteditable') === 'true'))) {
const root = (selectionEl.closest && selectionEl.closest('[data-gjs-type="text"]')) || selectionEl;
const id = root && root.getAttribute ? root.getAttribute('id') : null;
@@ -521,50 +548,14 @@
if (id && wrapper && wrapper.find) {
const found = wrapper.find(`#${id}`);
const comp = found && found[0];
const type = comp && comp.get ? comp.get('type') : null;
if (!type || type === 'text' || type === 'textnode') {
syncFromElement(comp, root, 'selection:root');
}
}
}
// 2) Fallback: zuletzt fokussiertes Element
if (!syncResult && lastEl && (lastEl.isContentEditable || (lastEl.getAttribute && lastEl.getAttribute('contenteditable') === 'true'))) {
const root = (lastEl.closest && lastEl.closest('[data-gjs-type="text"]')) || lastEl;
const id = root && root.getAttribute ? root.getAttribute('id') : null;
const wrapper = editor.getWrapper && editor.getWrapper();
if (id && wrapper && wrapper.find) {
const found = wrapper.find(`#${id}`);
const comp = found && found[0];
const type = comp && comp.get ? comp.get('type') : null;
if (!type || type === 'text' || type === 'textnode') {
syncFromElement(comp, root, 'last:element');
}
}
}
if (!syncResult && lastCompId) {
const wrapper = editor.getWrapper && editor.getWrapper();
if (wrapper && wrapper.find) {
const found = wrapper.find(`#${lastCompId}`);
const comp = found && found[0];
const type = comp && comp.get ? comp.get('type') : null;
const el = comp && comp.view && comp.view.el;
if (el && (!type || type === 'text' || type === 'textnode')) {
syncFromElement(comp, el, 'last:compId');
}
}
}
// 3) Fallback: ausgewähltes Component-Element aus der View
if (!syncResult && selected) {
const selEl = (selected.getEl && selected.getEl()) || (selected.view && selected.view.el);
const type = selected.get ? selected.get('type') : null;
if (selEl && (!type || type === 'text' || type === 'textnode') &&
(selEl.isContentEditable || (selEl.getAttribute && selEl.getAttribute('contenteditable') === 'true'))) {
syncFromElement(selected, selEl, 'selected:view');
syncFromElement(comp, root, 'selection:root');
}
}
=======
>>>>>>> theirs
writeDebugLog({
event: 'save:sync:minimal',
event: 'save:sync:skipped',
entityId: CURRENT_ENTITY_ID,
sectionId: SECTION_ID || null,
active: active ? {
@@ -580,8 +571,6 @@
type: selected.get ? selected.get('type') : null,
contentLen: selected.get ? String(selected.get('content') || '').length : 0,
} : null,
syncResult,
syncReason,
editorHtmlLen: (editor.getHtml && String(editor.getHtml() || '').length) || 0,
editorHtmlPreview: (editor.getHtml && String(editor.getHtml() || '').slice(0, 300)) || '',
});

View File

@@ -772,12 +772,6 @@
if (!target) return;
const isEditable = !!(target.isContentEditable || (target.getAttribute && target.getAttribute('contenteditable') === 'true'));
if (!isEditable) return;
try {
const win = target.ownerDocument && target.ownerDocument.defaultView;
if (win) {
win.__bridgeLastEditableEl = target;
}
} catch {}
const selected = editor.getSelected && editor.getSelected();
const selectedEl = selected && selected.view && selected.view.el;
let editorHtml = '';
@@ -798,14 +792,6 @@
const selectedEl = selected && selected.view && selected.view.el;
if (!selected || !selectedEl) return;
if (syncing.has(selected)) return;
try {
const win = target.ownerDocument && target.ownerDocument.defaultView;
if (win) {
win.__bridgeLastEditableEl = target;
const id = selected.getId ? selected.getId() : (selected.get && selected.get('id'));
if (id) win.__bridgeLastEditableCompId = id;
}
} catch {}
try {
const viewHtml = normalizeViewHtml(selectedEl.innerHTML || '');
if (!viewHtml) return;