asdasd
This commit is contained in:
@@ -360,6 +360,24 @@
|
||||
normalized: normalizeHtml(composite),
|
||||
};
|
||||
};
|
||||
const buildTextComponentsFromHtml = (html) => {
|
||||
const wrapper = document.createElement('div');
|
||||
wrapper.innerHTML = String(html || '');
|
||||
const newComps = [];
|
||||
wrapper.childNodes.forEach((node) => {
|
||||
if (node.nodeType === 3) {
|
||||
newComps.push({ type: 'textnode', content: node.textContent || '' });
|
||||
} else if (node.nodeType === 1) {
|
||||
const tag = node.tagName ? node.tagName.toLowerCase() : '';
|
||||
if (tag === 'br') {
|
||||
newComps.push({ tagName: 'br', void: true });
|
||||
} else {
|
||||
newComps.push(node.outerHTML);
|
||||
}
|
||||
}
|
||||
});
|
||||
return newComps.length ? newComps : html;
|
||||
};
|
||||
const storeSnapshot = (model, snap) => {
|
||||
if (!model || !snap) return;
|
||||
const key = model.cid || model;
|
||||
@@ -396,7 +414,7 @@
|
||||
if (!stored || !stored.normalized) return;
|
||||
try {
|
||||
if (target.components) {
|
||||
target.components(stored.html);
|
||||
target.components(buildTextComponentsFromHtml(stored.html));
|
||||
}
|
||||
target.set('content', stored.html);
|
||||
target.trigger && target.trigger('change:content');
|
||||
@@ -429,7 +447,7 @@
|
||||
if (viewHtml === modelHtml) return;
|
||||
try {
|
||||
syncing.add(target);
|
||||
if (target.components) target.components(viewHtml);
|
||||
if (target.components) target.components(buildTextComponentsFromHtml(viewHtml));
|
||||
if (target.set) target.set('content', viewHtml);
|
||||
target.trigger && target.trigger('change:content');
|
||||
const reapply = () => {
|
||||
|
||||
Reference in New Issue
Block a user