Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | 1x 1x 74x 37x 37x 37x 135x 135x 135x 53x 27x 29x 2x 53x 82x 82x 82x 82x 2x 2x 2x 1x 1x 1x 2x 135x 37x 27x 27x 27x 137x 137x 137x 31x 31x 106x 27x 137x 27x 28x 27x 27x 27x 58x 58x | import { getAllEntityWrappers, isBlockEntityContainer, isEntityDelimiter, isEntityElement, isNodeOfType, parseEntityFormat, reuseCachedElement, } from 'roosterjs-content-model-dom'; import type { Snapshot, EditorCore, KnownEntityItem } from 'roosterjs-content-model-types'; /** * @internal */ export function restoreSnapshotHTML(core: EditorCore, snapshot: Snapshot) { const { physicalRoot, entity: { entityMap }, } = core; let refNode: Node | null = physicalRoot.firstChild; const body = core.domCreator.htmlToDOM(snapshot.html).body; for (let currentNode = body.firstChild; currentNode; ) { const next = currentNode.nextSibling; const originalEntityElement = tryGetEntityElement(entityMap, currentNode); if (originalEntityElement) { // After restoring the snapshot, we need to clear the delimiter indexes since cached model will be cleared if (isBlockEntityContainer(originalEntityElement)) { for (let node = originalEntityElement.firstChild; node; node = node.nextSibling) { if (isNodeOfType(node, 'ELEMENT_NODE') && isEntityDelimiter(node)) { core.cache.domIndexer?.clearIndex(node); } } } refNode = reuseCachedElement(physicalRoot, originalEntityElement, refNode); } else { physicalRoot.insertBefore(currentNode, refNode); Eif (isNodeOfType(currentNode, 'ELEMENT_NODE')) { const childEntities = getAllEntityWrappers(currentNode); childEntities.forEach(element => { const wrapper = tryGetEntityElement(entityMap, element); Eif (wrapper) { if (wrapper == refNode) { // In case the node we are moving is just the ref node, // We create a temporary clone and insert it before the refNode, and use this cloned node as refNode // After replaceChild(), the original refNode will be moved away const markerNode = wrapper.cloneNode(); physicalRoot.insertBefore(markerNode, refNode); refNode = markerNode; } element.parentNode?.replaceChild(wrapper, element); } }); } } currentNode = next; } while (refNode) { const next = refNode.nextSibling; refNode.parentNode?.removeChild(refNode); refNode = next; } } function tryGetEntityElement( entityMap: Record<string, KnownEntityItem>, node: Node ): HTMLElement | null { let result: HTMLElement | null = null; Eif (isNodeOfType(node, 'ELEMENT_NODE')) { if (isEntityElement(node)) { const format = parseEntityFormat(node); result = getEntityWrapperForReuse(entityMap, format.id); } else if (isBlockEntityContainer(node)) { result = tryGetEntityFromContainer(node, entityMap); } } return result; } function tryGetEntityFromContainer( element: HTMLElement, entityMap: Record<string, KnownEntityItem> ): HTMLElement | null { for (let node = element.firstChild; node; node = node.nextSibling) { if (isEntityElement(node) && isNodeOfType(node, 'ELEMENT_NODE')) { const format = parseEntityFormat(node); const parent = getEntityWrapperForReuse(entityMap, format.id)?.parentElement; return isNodeOfType(parent, 'ELEMENT_NODE') && isBlockEntityContainer(parent) ? parent : null; } } return null; } function getEntityWrapperForReuse( entityMap: Record<string, KnownEntityItem>, entityId: string | undefined ): HTMLElement | null { const entry = entityId ? entityMap[entityId] : undefined; return entry?.canPersist ? entry.element : null; } |