adfsf
This commit is contained in:
@@ -329,13 +329,15 @@
|
|||||||
const closeModal = () => {
|
const closeModal = () => {
|
||||||
editor.__bridgeRteAllowClose = true;
|
editor.__bridgeRteAllowClose = true;
|
||||||
editor.__bridgeRteModalOpen = false;
|
editor.__bridgeRteModalOpen = false;
|
||||||
const mdl = modal.getModel && modal.getModel();
|
if (typeof modal.close === 'function') {
|
||||||
if (modal.__bridgeOriginalClose) {
|
modal.close();
|
||||||
modal.__bridgeOriginalClose();
|
} else {
|
||||||
} else if (mdl && typeof mdl.set === 'function') {
|
const mdl = modal.getModel && modal.getModel();
|
||||||
mdl.set('open', false);
|
if (mdl && typeof mdl.set === 'function') {
|
||||||
} else if (modal.el) {
|
mdl.set('open', false);
|
||||||
modal.el.style.display = 'none';
|
} else if (modal.el) {
|
||||||
|
modal.el.style.display = 'none';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -343,10 +345,21 @@
|
|||||||
modal.__bridgeCloseLocked = true;
|
modal.__bridgeCloseLocked = true;
|
||||||
modal.__bridgeOriginalClose = modal.close ? modal.close.bind(modal) : null;
|
modal.__bridgeOriginalClose = modal.close ? modal.close.bind(modal) : null;
|
||||||
modal.close = function (...args) {
|
modal.close = function (...args) {
|
||||||
|
if (!editor.__bridgeRteModalOpen && typeof modal.__bridgeOriginalClose === 'function') {
|
||||||
|
return modal.__bridgeOriginalClose(...args);
|
||||||
|
}
|
||||||
if (editor.__bridgeRteAllowClose && typeof modal.__bridgeOriginalClose === 'function') {
|
if (editor.__bridgeRteAllowClose && typeof modal.__bridgeOriginalClose === 'function') {
|
||||||
editor.__bridgeRteAllowClose = false;
|
editor.__bridgeRteAllowClose = false;
|
||||||
return modal.__bridgeOriginalClose(...args);
|
return modal.__bridgeOriginalClose(...args);
|
||||||
}
|
}
|
||||||
|
if (!editor.__bridgeRteModalOpen && !modal.__bridgeOriginalClose) {
|
||||||
|
const mdl = modal.getModel && modal.getModel();
|
||||||
|
if (mdl && typeof mdl.set === 'function') {
|
||||||
|
mdl.set('open', false);
|
||||||
|
} else if (modal.el) {
|
||||||
|
modal.el.style.display = 'none';
|
||||||
|
}
|
||||||
|
}
|
||||||
if (editor.__bridgeRteAllowClose && !modal.__bridgeOriginalClose) {
|
if (editor.__bridgeRteAllowClose && !modal.__bridgeOriginalClose) {
|
||||||
editor.__bridgeRteAllowClose = false;
|
editor.__bridgeRteAllowClose = false;
|
||||||
const mdl = modal.getModel && modal.getModel();
|
const mdl = modal.getModel && modal.getModel();
|
||||||
@@ -535,12 +548,11 @@
|
|||||||
const isTextLike = component && component.is && (component.is('text') || component.is('button') || component.is('link'));
|
const isTextLike = component && component.is && (component.is('text') || component.is('button') || component.is('link'));
|
||||||
const hasTags = /<[^>]+>/.test(html);
|
const hasTags = /<[^>]+>/.test(html);
|
||||||
try {
|
try {
|
||||||
if (!isTextLike && component.components) {
|
if (component.components) {
|
||||||
component.components(html);
|
component.components(html);
|
||||||
}
|
}
|
||||||
if (component.set) {
|
if (component.set) {
|
||||||
const nextContent = (!hasTags && isTextLike) ? html : html;
|
component.set('content', html);
|
||||||
component.set('content', nextContent);
|
|
||||||
component.trigger && component.trigger('change:content');
|
component.trigger && component.trigger('change:content');
|
||||||
component.trigger && component.trigger('change:components');
|
component.trigger && component.trigger('change:components');
|
||||||
}
|
}
|
||||||
@@ -590,6 +602,15 @@
|
|||||||
} catch {
|
} catch {
|
||||||
modal.open();
|
modal.open();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const modalEl = modal.getEl ? modal.getEl() : modal.el;
|
||||||
|
const closeBtn = modalEl && modalEl.querySelector ? modalEl.querySelector('.gjs-mdl-btn-close') : null;
|
||||||
|
if (closeBtn && !closeBtn.__bridgeRteBound) {
|
||||||
|
closeBtn.__bridgeRteBound = true;
|
||||||
|
closeBtn.addEventListener('click', () => {
|
||||||
|
editor.__bridgeRteAllowClose = true;
|
||||||
|
}, true);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const setupRichTextEditor = (editor) => {
|
const setupRichTextEditor = (editor) => {
|
||||||
@@ -724,6 +745,12 @@
|
|||||||
const setupPlainTextPreserver = (editor) => {
|
const setupPlainTextPreserver = (editor) => {
|
||||||
const isTextLike = (model) => !!(model && model.is && (model.is('text') || model.is('button') || model.is('link')));
|
const isTextLike = (model) => !!(model && model.is && (model.is('text') || model.is('button') || model.is('link')));
|
||||||
const lastContent = new Map();
|
const lastContent = new Map();
|
||||||
|
const normalizeHtml = (value) => {
|
||||||
|
return String(value || '')
|
||||||
|
.replace(/<br\s*\/?>/gi, '')
|
||||||
|
.replace(/ /g, '')
|
||||||
|
.trim();
|
||||||
|
};
|
||||||
const snapshotContent = (model) => {
|
const snapshotContent = (model) => {
|
||||||
const el = model.view && model.view.el;
|
const el = model.view && model.view.el;
|
||||||
const html = String(model.get ? (model.get('content') || '') : '').trim();
|
const html = String(model.get ? (model.get('content') || '') : '').trim();
|
||||||
@@ -732,26 +759,28 @@
|
|||||||
const composite = html || inner || text;
|
const composite = html || inner || text;
|
||||||
return {
|
return {
|
||||||
html: composite,
|
html: composite,
|
||||||
text,
|
normalized: normalizeHtml(composite),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
const rememberIfPresent = (model) => {
|
const rememberIfPresent = (model) => {
|
||||||
if (!isTextLike(model)) return;
|
if (!isTextLike(model)) return;
|
||||||
const snap = snapshotContent(model);
|
const snap = snapshotContent(model);
|
||||||
if (!snap.html) return;
|
if (!snap.normalized) return;
|
||||||
lastContent.set(model.cid || model, snap);
|
lastContent.set(model.cid || model, snap);
|
||||||
};
|
};
|
||||||
const restoreIfEmpty = (model) => {
|
const restoreIfEmpty = (model) => {
|
||||||
if (!isTextLike(model) || !model.get) return;
|
if (!isTextLike(model) || !model.get) return;
|
||||||
const current = snapshotContent(model);
|
const current = snapshotContent(model);
|
||||||
if (current.html) {
|
if (current.normalized) {
|
||||||
rememberIfPresent(model);
|
rememberIfPresent(model);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const stored = lastContent.get(model.cid || model);
|
const stored = lastContent.get(model.cid || model);
|
||||||
if (!stored || !stored.html) return;
|
if (!stored || !stored.normalized) return;
|
||||||
if (model.components && model.components().length) return;
|
|
||||||
try {
|
try {
|
||||||
|
if (model.components) {
|
||||||
|
model.components(stored.html);
|
||||||
|
}
|
||||||
model.set('content', stored.html);
|
model.set('content', stored.html);
|
||||||
model.trigger && model.trigger('change:content');
|
model.trigger && model.trigger('change:content');
|
||||||
} catch {}
|
} catch {}
|
||||||
|
|||||||
Reference in New Issue
Block a user