sdfdsf
This commit is contained in:
@@ -776,6 +776,13 @@
|
|||||||
|
|
||||||
const setupPlainTextPreserver = (editor) => {
|
const setupPlainTextPreserver = (editor) => {
|
||||||
const isTextLike = (model) => !!(model && model.is && (model.is('text') || model.is('button') || model.is('link') || model.is('textnode')));
|
const isTextLike = (model) => !!(model && model.is && (model.is('text') || model.is('button') || model.is('link') || model.is('textnode')));
|
||||||
|
const resolveTextModel = (model) => {
|
||||||
|
if (!model) return model;
|
||||||
|
if (model.is && model.is('textnode') && typeof model.parent === 'function') {
|
||||||
|
return model.parent();
|
||||||
|
}
|
||||||
|
return model;
|
||||||
|
};
|
||||||
const lastContent = new Map();
|
const lastContent = new Map();
|
||||||
const normalizeHtml = (value) => {
|
const normalizeHtml = (value) => {
|
||||||
return String(value || '')
|
return String(value || '')
|
||||||
@@ -795,31 +802,52 @@
|
|||||||
normalized: normalizeHtml(composite),
|
normalized: normalizeHtml(composite),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
const storeSnapshot = (model, snap) => {
|
||||||
|
if (!model || !snap) return;
|
||||||
|
const key = model.cid || model;
|
||||||
|
lastContent.set(key, snap);
|
||||||
|
model.__bridgeLastHtml = snap.html;
|
||||||
|
model.__bridgeLastNormalized = snap.normalized;
|
||||||
|
const el = model.view && model.view.el;
|
||||||
|
if (el) {
|
||||||
|
el.__bridgeLastHtml = snap.html;
|
||||||
|
el.__bridgeLastNormalized = snap.normalized;
|
||||||
|
}
|
||||||
|
};
|
||||||
const rememberIfPresent = (model) => {
|
const rememberIfPresent = (model) => {
|
||||||
if (!isTextLike(model)) return;
|
const target = resolveTextModel(model);
|
||||||
const snap = snapshotContent(model);
|
if (!isTextLike(target)) return;
|
||||||
|
const snap = snapshotContent(target);
|
||||||
if (!snap.normalized) return;
|
if (!snap.normalized) return;
|
||||||
lastContent.set(model.cid || model, snap);
|
storeSnapshot(target, snap);
|
||||||
};
|
};
|
||||||
const restoreIfEmpty = (model) => {
|
const restoreIfEmpty = (model) => {
|
||||||
if (!isTextLike(model) || !model.get) return;
|
const target = resolveTextModel(model);
|
||||||
const current = snapshotContent(model);
|
if (!isTextLike(target) || !target.get) return;
|
||||||
|
const current = snapshotContent(target);
|
||||||
if (current.normalized) {
|
if (current.normalized) {
|
||||||
rememberIfPresent(model);
|
rememberIfPresent(target);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const stored = lastContent.get(model.cid || model);
|
const key = target.cid || target;
|
||||||
|
const stored = lastContent.get(key)
|
||||||
|
|| (target.__bridgeLastNormalized ? { html: target.__bridgeLastHtml, normalized: target.__bridgeLastNormalized } : null)
|
||||||
|
|| ((target.view && target.view.el && target.view.el.__bridgeLastNormalized)
|
||||||
|
? { html: target.view.el.__bridgeLastHtml, normalized: target.view.el.__bridgeLastNormalized }
|
||||||
|
: null);
|
||||||
if (!stored || !stored.normalized) return;
|
if (!stored || !stored.normalized) return;
|
||||||
try {
|
try {
|
||||||
if (model.components) {
|
if (target.components) {
|
||||||
model.components(stored.html);
|
target.components(stored.html);
|
||||||
}
|
}
|
||||||
model.set('content', stored.html);
|
target.set('content', stored.html);
|
||||||
model.trigger && model.trigger('change:content');
|
target.trigger && target.trigger('change:content');
|
||||||
|
try { console.log('[PLAIN TEXT RESTORE] Inhalt wiederhergestellt.'); } catch {}
|
||||||
} catch {}
|
} catch {}
|
||||||
};
|
};
|
||||||
editor.on('component:update', (model) => restoreIfEmpty(model));
|
editor.on('component:update', (model) => restoreIfEmpty(model));
|
||||||
editor.on('component:input', (model) => restoreIfEmpty(model));
|
editor.on('component:input', (model) => restoreIfEmpty(model));
|
||||||
|
editor.on('component:deselected', (model) => restoreIfEmpty(model));
|
||||||
editor.on('component:add', (model) => rememberIfPresent(model));
|
editor.on('component:add', (model) => rememberIfPresent(model));
|
||||||
editor.on('rte:disable', (model) => {
|
editor.on('rte:disable', (model) => {
|
||||||
const target = model || (editor.getSelected && editor.getSelected());
|
const target = model || (editor.getSelected && editor.getSelected());
|
||||||
@@ -1108,7 +1136,7 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const ensurePlaceholderCommandStub = (editor) => {
|
const ensureCommandStubs = (editor) => {
|
||||||
if (!editor || !editor.Commands || !editor.Commands.add) return;
|
if (!editor || !editor.Commands || !editor.Commands.add) return;
|
||||||
editor.Commands.add('bridge-placeholder:edit', {
|
editor.Commands.add('bridge-placeholder:edit', {
|
||||||
__bridgePlaceholderStub: true,
|
__bridgePlaceholderStub: true,
|
||||||
@@ -1120,8 +1148,22 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
editor.Commands.add('bridge-open-richtext', {
|
||||||
|
__bridgeRteStub: true,
|
||||||
|
run(ed, sender, opts = {}) {
|
||||||
|
if (sender && sender.set) sender.set('active', 0);
|
||||||
|
const component = opts.component || ed.getSelected();
|
||||||
|
openRichTextModal(ed, component);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
editor.Commands.add('bridge-table:edit', {
|
||||||
|
__bridgeTableStub: true,
|
||||||
|
run(ed, sender, opts = {}) {
|
||||||
|
if (sender && sender.set) sender.set('active', 0);
|
||||||
|
},
|
||||||
|
});
|
||||||
};
|
};
|
||||||
ensurePlaceholderCommandStub(ed);
|
ensureCommandStubs(ed);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const textTags = ['p','span','div','br','b','strong','i','em','u','a','ul','ol','li'];
|
const textTags = ['p','span','div','br','b','strong','i','em','u','a','ul','ol','li'];
|
||||||
|
|||||||
Reference in New Issue
Block a user