upload
This commit is contained in:
@@ -181,13 +181,35 @@ const buildPlaceholderHTML = (payload) => {
|
|||||||
return wrapper;
|
return wrapper;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const buildTextnodeComponents = (el) => {
|
||||||
|
if (!el) return [];
|
||||||
|
const nodes = Array.from(el.childNodes || []);
|
||||||
|
const comps = [];
|
||||||
|
nodes.forEach((node) => {
|
||||||
|
if (!node) return;
|
||||||
|
if (node.nodeType === 3) {
|
||||||
|
const text = node.textContent;
|
||||||
|
if (text !== null && text !== undefined && text !== '') {
|
||||||
|
comps.push({ type: 'textnode', content: text });
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (node.nodeType === 1 && node.outerHTML) {
|
||||||
|
comps.push(node.outerHTML);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return comps;
|
||||||
|
};
|
||||||
|
|
||||||
const reparseTextComponent = (component, editor) => {
|
const reparseTextComponent = (component, editor) => {
|
||||||
if (!component || typeof component.components !== 'function') return;
|
if (!component || typeof component.components !== 'function') return;
|
||||||
const viewEl = component.view && component.view.el;
|
const viewEl = component.view && component.view.el;
|
||||||
if (!viewEl) return;
|
if (!viewEl) return;
|
||||||
const html = viewEl.innerHTML;
|
const comps = buildTextnodeComponents(viewEl);
|
||||||
try {
|
try {
|
||||||
component.components(html);
|
if (comps.length) {
|
||||||
|
component.components(comps);
|
||||||
|
}
|
||||||
if (component.em && typeof component.em.trigger === 'function') {
|
if (component.em && typeof component.em.trigger === 'function') {
|
||||||
component.em.trigger('component:update', component);
|
component.em.trigger('component:update', component);
|
||||||
} else if (editor && typeof editor.trigger === 'function') {
|
} else if (editor && typeof editor.trigger === 'function') {
|
||||||
|
|||||||
Reference in New Issue
Block a user