roosterjs-content-model-core 9.53.0 → 9.54.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/coreApi/createContentModel/createContentModel.js +3 -0
- package/lib/coreApi/createContentModel/createContentModel.js.map +1 -1
- package/lib/corePlugin/cache/CachePlugin.js +5 -0
- package/lib/corePlugin/cache/CachePlugin.js.map +1 -1
- package/lib/corePlugin/cache/MutationType.d.ts +12 -1
- package/lib/corePlugin/cache/MutationType.js.map +1 -1
- package/lib/corePlugin/cache/domIndexerImpl.d.ts +1 -0
- package/lib/corePlugin/cache/domIndexerImpl.js +27 -0
- package/lib/corePlugin/cache/domIndexerImpl.js.map +1 -1
- package/lib/corePlugin/cache/textMutationObserver.js +10 -0
- package/lib/corePlugin/cache/textMutationObserver.js.map +1 -1
- package/lib-amd/coreApi/createContentModel/createContentModel.js +3 -0
- package/lib-amd/coreApi/createContentModel/createContentModel.js.map +1 -1
- package/lib-amd/corePlugin/cache/CachePlugin.js +5 -0
- package/lib-amd/corePlugin/cache/CachePlugin.js.map +1 -1
- package/lib-amd/corePlugin/cache/MutationType.d.ts +12 -1
- package/lib-amd/corePlugin/cache/MutationType.js.map +1 -1
- package/lib-amd/corePlugin/cache/domIndexerImpl.d.ts +1 -0
- package/lib-amd/corePlugin/cache/domIndexerImpl.js +27 -0
- package/lib-amd/corePlugin/cache/domIndexerImpl.js.map +1 -1
- package/lib-amd/corePlugin/cache/textMutationObserver.js +10 -0
- package/lib-amd/corePlugin/cache/textMutationObserver.js.map +1 -1
- package/lib-mjs/coreApi/createContentModel/createContentModel.js +3 -0
- package/lib-mjs/coreApi/createContentModel/createContentModel.js.map +1 -1
- package/lib-mjs/corePlugin/cache/CachePlugin.js +5 -0
- package/lib-mjs/corePlugin/cache/CachePlugin.js.map +1 -1
- package/lib-mjs/corePlugin/cache/MutationType.d.ts +12 -1
- package/lib-mjs/corePlugin/cache/MutationType.js.map +1 -1
- package/lib-mjs/corePlugin/cache/domIndexerImpl.d.ts +1 -0
- package/lib-mjs/corePlugin/cache/domIndexerImpl.js +27 -0
- package/lib-mjs/corePlugin/cache/domIndexerImpl.js.map +1 -1
- package/lib-mjs/corePlugin/cache/textMutationObserver.js +10 -0
- package/lib-mjs/corePlugin/cache/textMutationObserver.js.map +1 -1
- package/package.json +3 -3
|
@@ -10,6 +10,10 @@ export declare type MutationType =
|
|
|
10
10
|
* Element id is changed
|
|
11
11
|
*/
|
|
12
12
|
| 'elementId'
|
|
13
|
+
/**
|
|
14
|
+
* An attribute (such as src or data-*) is changed on an element
|
|
15
|
+
*/
|
|
16
|
+
| 'attribute'
|
|
13
17
|
/**
|
|
14
18
|
* Only text is changed
|
|
15
19
|
*/
|
|
@@ -35,6 +39,13 @@ export interface UnknownMutation extends MutationBase<'unknown'> {
|
|
|
35
39
|
export interface ElementIdMutation extends MutationBase<'elementId'> {
|
|
36
40
|
element: HTMLElement;
|
|
37
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* @internal
|
|
44
|
+
*/
|
|
45
|
+
export interface AttributeMutation extends MutationBase<'attribute'> {
|
|
46
|
+
element: HTMLElement;
|
|
47
|
+
attributeName: string;
|
|
48
|
+
}
|
|
38
49
|
/**
|
|
39
50
|
* @internal
|
|
40
51
|
*/
|
|
@@ -50,4 +61,4 @@ export interface ChildListMutation extends MutationBase<'childList'> {
|
|
|
50
61
|
/**
|
|
51
62
|
* @internal
|
|
52
63
|
*/
|
|
53
|
-
export declare type Mutation = UnknownMutation | ElementIdMutation | TextMutation | ChildListMutation;
|
|
64
|
+
export declare type Mutation = UnknownMutation | ElementIdMutation | AttributeMutation | TextMutation | ChildListMutation;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MutationType.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/corePlugin/cache/MutationType.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * @internal Type of mutations\n */\nexport type MutationType =\n /**\n * We found some change happened but we cannot handle it, so set mutation type as \"unknown\"\n */\n | 'unknown'\n /**\n * Element id is changed\n */\n | 'elementId'\n /**\n * Only text is changed\n */\n | 'text'\n /**\n * Child list is changed\n */\n | 'childList';\n\n/**\n * @internal\n */\nexport interface MutationBase<T extends MutationType> {\n type: T;\n}\n\n/**\n * @internal\n */\nexport interface UnknownMutation extends MutationBase<'unknown'> {}\n\n/**\n * @internal\n */\nexport interface ElementIdMutation extends MutationBase<'elementId'> {\n element: HTMLElement;\n}\n\n/**\n * @internal\n */\nexport interface TextMutation extends MutationBase<'text'> {}\n\n/**\n * @internal\n */\nexport interface ChildListMutation extends MutationBase<'childList'> {\n addedNodes: Node[];\n removedNodes: Node[];\n}\n\n/**\n * @internal\n */\nexport type Mutation
|
|
1
|
+
{"version":3,"file":"MutationType.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/corePlugin/cache/MutationType.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * @internal Type of mutations\n */\nexport type MutationType =\n /**\n * We found some change happened but we cannot handle it, so set mutation type as \"unknown\"\n */\n | 'unknown'\n /**\n * Element id is changed\n */\n | 'elementId'\n /**\n * An attribute (such as src or data-*) is changed on an element\n */\n | 'attribute'\n /**\n * Only text is changed\n */\n | 'text'\n /**\n * Child list is changed\n */\n | 'childList';\n\n/**\n * @internal\n */\nexport interface MutationBase<T extends MutationType> {\n type: T;\n}\n\n/**\n * @internal\n */\nexport interface UnknownMutation extends MutationBase<'unknown'> {}\n\n/**\n * @internal\n */\nexport interface ElementIdMutation extends MutationBase<'elementId'> {\n element: HTMLElement;\n}\n\n/**\n * @internal\n */\nexport interface AttributeMutation extends MutationBase<'attribute'> {\n element: HTMLElement;\n attributeName: string;\n}\n\n/**\n * @internal\n */\nexport interface TextMutation extends MutationBase<'text'> {}\n\n/**\n * @internal\n */\nexport interface ChildListMutation extends MutationBase<'childList'> {\n addedNodes: Node[];\n removedNodes: Node[];\n}\n\n/**\n * @internal\n */\nexport type Mutation =\n | UnknownMutation\n | ElementIdMutation\n | AttributeMutation\n | TextMutation\n | ChildListMutation;\n"]}
|
|
@@ -53,6 +53,7 @@ export declare class DomIndexerImpl implements DomIndexer {
|
|
|
53
53
|
reconcileSelection(model: ContentModelDocument, newSelection: DOMSelection, oldSelection?: CacheSelection): boolean;
|
|
54
54
|
reconcileChildList(addedNodes: ArrayLike<Node>, removedNodes: ArrayLike<Node>): boolean;
|
|
55
55
|
reconcileElementId(element: HTMLElement): boolean;
|
|
56
|
+
reconcileImageAttribute(element: HTMLElement, attributeName: string): boolean;
|
|
56
57
|
private onBlockEntityDelimiter;
|
|
57
58
|
private isCollapsed;
|
|
58
59
|
private reconcileNodeSelection;
|
|
@@ -232,6 +232,33 @@ define(["require", "exports", "tslib", "roosterjs-content-model-dom"], function
|
|
|
232
232
|
return false;
|
|
233
233
|
}
|
|
234
234
|
};
|
|
235
|
+
DomIndexerImpl.prototype.reconcileImageAttribute = function (element, attributeName) {
|
|
236
|
+
var _a, _b;
|
|
237
|
+
if ((0, roosterjs_content_model_dom_1.isElementOfType)(element, 'img')) {
|
|
238
|
+
var image = (_a = getIndexedSegmentItem(element)) === null || _a === void 0 ? void 0 : _a.segments[0];
|
|
239
|
+
if ((image === null || image === void 0 ? void 0 : image.segmentType) == 'Image') {
|
|
240
|
+
if (attributeName == 'src') {
|
|
241
|
+
// Use getAttribute('src') instead of retrieving src directly, in case the src
|
|
242
|
+
// has port and may be stripped by browser. This matches imageProcessor.
|
|
243
|
+
image.src = (_b = element.getAttribute('src')) !== null && _b !== void 0 ? _b : '';
|
|
244
|
+
return true;
|
|
245
|
+
}
|
|
246
|
+
else if (attributeName.indexOf('data-') == 0) {
|
|
247
|
+
// A data-* attribute may be added, modified or removed. Rebuild the whole
|
|
248
|
+
// dataset from DOM to keep it in sync, the same way imageProcessor builds it.
|
|
249
|
+
var dataset_1 = image.dataset;
|
|
250
|
+
(0, roosterjs_content_model_dom_1.getObjectKeys)(dataset_1).forEach(function (key) {
|
|
251
|
+
delete dataset_1[key];
|
|
252
|
+
});
|
|
253
|
+
(0, roosterjs_content_model_dom_1.getObjectKeys)(element.dataset).forEach(function (key) {
|
|
254
|
+
dataset_1[key] = element.dataset[key] || '';
|
|
255
|
+
});
|
|
256
|
+
return true;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return false;
|
|
261
|
+
};
|
|
235
262
|
DomIndexerImpl.prototype.onBlockEntityDelimiter = function (node, entity, parent) {
|
|
236
263
|
if ((0, roosterjs_content_model_dom_1.isNodeOfType)(node, 'ELEMENT_NODE') && (0, roosterjs_content_model_dom_1.isEntityDelimiter)(node) && node.firstChild) {
|
|
237
264
|
var indexedDelimiter = node.firstChild;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"domIndexerImpl.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/corePlugin/cache/domIndexerImpl.ts"],"names":[],"mappings":";;;;IAwGA,SAAS,gBAAgB,CAAC,IAAU;;QAC1B,IAAA,KAA0B,MAAC,IAA2B,CAAC,uBAAuB,mCAAI,EAAE,EAAlF,SAAS,eAAA,EAAE,QAAQ,cAA+D,CAAC;QAE3F,OAAO,CACH,SAAS;YACT,SAAS,CAAC,SAAS,IAAI,WAAW;YAClC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC;YACjC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC;YACvB,QAAQ,CAAC,KAAK,CAAC,UAAA,OAAO,IAAI,OAAA,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,EAApC,CAAoC,CAAC,CAClE,CAAC;IACN,CAAC;IAED,SAAS,kBAAkB,CAAC,IAAU;;QAC5B,IAAA,KAAqB,MAAC,IAA+B,CAAC,uBAAuB,mCAAI,EAAE,EAAjF,MAAM,YAAA,EAAE,MAAM,YAAmE,CAAC;QAE1F,OAAO,CACH,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,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AW,IAAI,iBAAiB,EACvC;gBACE,OAAO,YAAY,CAAC,KAAK,CAAC,uBAAuB,CAAC,uBAAuB,CAAC,SAAS;qBAC9E,QAAQ,CAAC,CAAC,CAAC,CAAC;aACpB;YACD,OAAO,SAAS,CAAC;QACrB,CAAC;QACL,qBAAC;IAAD,CAAC,AAtlBD,IAslBC;IAtlBY,wCAAc;IAwlB3B,SAAS,WAAW,CAAC,IAAiB;QAClC,OAAO,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,SAAS,EAAE;YACpB,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC;SACzB;QAED,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,SAAS,YAAY,CAAC,IAAiB;QACnC,OAAO,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,UAAU,EAAE;YACrB,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC;SAC1B;QAED,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,SAAS,kBAAkB,CAAC,SAAe;QACvC,OAAO,CAAC,SAA+B,CAAC,CAAC;QAEzC,KAAK,IAAI,IAAI,GAAG,SAAS,CAAC,UAAU,EAAE,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC,WAAW,EAAE;YACjE,kBAAkB,CAAC,IAAI,CAAC,CAAC;SAC5B;IACL,CAAC","sourcesContent":["import {\n EmptySegmentFormat,\n addCode,\n addLink,\n createParagraph,\n createSelectionMarker,\n createText,\n getObjectKeys,\n isElementOfType,\n isEntityDelimiter,\n isNodeOfType,\n setSelection,\n} from 'roosterjs-content-model-dom';\nimport type {\n CacheSelection,\n ContentModelBlockGroup,\n ContentModelDocument,\n ContentModelEntity,\n ContentModelParagraph,\n ContentModelSegment,\n ContentModelSegmentFormat,\n ContentModelSelectionMarker,\n ContentModelTable,\n ContentModelText,\n DomIndexer,\n DOMSelection,\n RangeSelectionForCache,\n Selectable,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal Export for test only\n */\nexport interface SegmentItem {\n paragraph: ContentModelParagraph;\n segments: ContentModelSegment[];\n}\n\n/**\n * @internal Export for test only\n */\nexport interface TableItem {\n table: ContentModelTable;\n}\n\n/**\n * @internal Export for test only\n */\nexport interface BlockEntityDelimiterItem {\n entity: ContentModelEntity;\n parent: ContentModelBlockGroup;\n}\n\n/**\n * @internal Export for test only\n */\nexport interface IndexedSegmentNode extends Node {\n __roosterjsContentModel: SegmentItem;\n}\n\n/**\n * @internal Export for test only\n */\nexport interface IndexedTableElement extends HTMLTableElement {\n __roosterjsContentModel: TableItem;\n}\n\n/**\n * @internal Export for test only\n */\nexport interface IndexedEntityDelimiter extends Text {\n __roosterjsContentModel: BlockEntityDelimiterItem;\n}\n\n/**\n * Context object used by DomIndexer when reconcile mutations with child list\n */\ninterface ReconcileChildListContext {\n /**\n * Index of segment in current paragraph\n */\n segIndex: number;\n\n /**\n * The current paragraph that we are handling\n */\n paragraph?: ContentModelParagraph;\n\n /**\n * Text node that is added from mutation but has not been handled. This can happen when we first see an added node then later we see a removed one.\n * e.g. Type text in an empty paragraph (<div><br></div>), so a text node will be added and <BR> will be removed.\n * Set to a valid text node means we need to handle it later. If it is finally not handled, that means we need to clear cache\n * Set to undefined (initial value) means no pending text node is hit yet (valid case)\n * Set to null means there was a pending text node which is already handled, so if we see another pending text node,\n * we should clear cache since we don't know how to handle it\n */\n pendingTextNode?: Text | null;\n\n /**\n * Format of the removed segment, this will be used as the format for newly created segment\n */\n format?: ContentModelSegmentFormat;\n}\n\nfunction isIndexedSegment(node: Node): node is IndexedSegmentNode {\n const { paragraph, segments } = (node as IndexedSegmentNode).__roosterjsContentModel ?? {};\n\n return (\n paragraph &&\n paragraph.blockType == 'Paragraph' &&\n Array.isArray(paragraph.segments) &&\n Array.isArray(segments) &&\n segments.every(segment => paragraph.segments.includes(segment))\n );\n}\n\nfunction isIndexedDelimiter(node: Node): node is IndexedEntityDelimiter {\n const { entity, parent } = (node as IndexedEntityDelimiter).__roosterjsContentModel ?? {};\n\n return (\n entity?.blockType == 'Entity' &&\n entity.wrapper &&\n parent?.blockGroupType &&\n Array.isArray(parent.blocks)\n );\n}\n\nfunction getIndexedSegmentItem(node: Node | null): SegmentItem | null {\n return node && isIndexedSegment(node) ? node.__roosterjsContentModel : null;\n}\n\nfunction getIndexedTableItem(element: HTMLTableElement): TableItem | null {\n const index = (element as IndexedTableElement).__roosterjsContentModel;\n const table = index?.table;\n\n if (\n table?.blockType == 'Table' &&\n Array.isArray(table.rows) &&\n table.rows.every(\n x => Array.isArray(x?.cells) && x.cells.every(y => y?.blockGroupType == 'TableCell')\n )\n ) {\n return index;\n } else {\n return null;\n }\n}\n\n// Make a node not indexed. Do not export this function since we should not let code outside here know this detail\nfunction unindex(node: Partial<IndexedSegmentNode>) {\n delete node.__roosterjsContentModel;\n}\n\n/**\n * @internal\n * Implementation of DomIndexer\n */\nexport class DomIndexerImpl implements DomIndexer {\n constructor(private readonly keepSelectionMarkerWhenEnteringTextNode?: boolean) {}\n\n onSegment(segmentNode: Node, paragraph: ContentModelParagraph, segment: ContentModelSegment[]) {\n const indexedText = segmentNode as IndexedSegmentNode;\n indexedText.__roosterjsContentModel = {\n paragraph,\n segments: segment,\n };\n }\n\n onParagraph(paragraphElement: HTMLElement) {\n let previousText: Text | null = null;\n\n for (let child = paragraphElement.firstChild; child; child = child.nextSibling) {\n if (isNodeOfType(child, 'TEXT_NODE')) {\n if (!previousText) {\n previousText = child;\n } else {\n const item = getIndexedSegmentItem(previousText);\n\n if (item && isIndexedSegment(child)) {\n item.segments = item.segments.concat(\n child.__roosterjsContentModel.segments\n );\n child.__roosterjsContentModel.segments = [];\n }\n }\n } else if (isNodeOfType(child, 'ELEMENT_NODE')) {\n previousText = null;\n\n this.onParagraph(child);\n } else {\n previousText = null;\n }\n }\n }\n\n onTable(tableElement: HTMLTableElement, table: ContentModelTable) {\n const indexedTable = tableElement as IndexedTableElement;\n indexedTable.__roosterjsContentModel = { table };\n }\n\n onBlockEntity(entity: ContentModelEntity, group: ContentModelBlockGroup) {\n this.onBlockEntityDelimiter(entity.wrapper.previousSibling, entity, group);\n this.onBlockEntityDelimiter(entity.wrapper.nextSibling, entity, group);\n }\n\n onMergeText(targetText: Text, sourceText: Text) {\n if (isIndexedSegment(targetText) && isIndexedSegment(sourceText)) {\n if (targetText.nextSibling == sourceText) {\n targetText.__roosterjsContentModel.segments.push(\n ...sourceText.__roosterjsContentModel.segments\n );\n\n unindex(sourceText);\n }\n } else {\n unindex(sourceText);\n unindex(targetText);\n }\n }\n\n clearIndex(container: Node) {\n internalClearIndex(container);\n }\n\n reconcileSelection(\n model: ContentModelDocument,\n newSelection: DOMSelection,\n oldSelection?: CacheSelection\n ): boolean {\n let selectionMarker: ContentModelSelectionMarker | undefined;\n if (oldSelection) {\n let startNode: Node | undefined;\n\n if (\n oldSelection.type == 'range' &&\n this.isCollapsed(oldSelection) &&\n (startNode = oldSelection.start.node) &&\n isNodeOfType(startNode, 'TEXT_NODE') &&\n isIndexedSegment(startNode) &&\n startNode.__roosterjsContentModel.segments.length > 0\n ) {\n this.reconcileTextSelection(startNode);\n } else {\n selectionMarker = this.selectionMarkerToKeepWhenEnteringTextNode(\n oldSelection,\n newSelection\n );\n\n setSelection(model);\n }\n }\n\n switch (newSelection.type) {\n case 'image':\n const indexedImage = getIndexedSegmentItem(newSelection.image);\n const image = indexedImage?.segments[0];\n\n if (image) {\n image.isSelected = true;\n setSelection(model, image);\n\n return true;\n } else {\n return false;\n }\n\n case 'table':\n const indexedTable = getIndexedTableItem(newSelection.table);\n\n if (indexedTable) {\n const firstCell =\n indexedTable.table.rows[newSelection.firstRow]?.cells[\n newSelection.firstColumn\n ];\n const lastCell =\n indexedTable.table.rows[newSelection.lastRow]?.cells[\n newSelection.lastColumn\n ];\n\n if (firstCell && lastCell) {\n setSelection(model, firstCell, lastCell);\n\n return true;\n }\n }\n\n return false;\n\n case 'range':\n const newRange = newSelection.range;\n if (newRange) {\n const {\n startContainer,\n startOffset,\n endContainer,\n endOffset,\n collapsed,\n } = newRange;\n\n delete model.hasRevertedRangeSelection;\n\n if (collapsed) {\n return !!this.reconcileNodeSelection(\n startContainer,\n startOffset,\n model.format,\n selectionMarker\n );\n } else if (\n startContainer == endContainer &&\n isNodeOfType(startContainer, 'TEXT_NODE')\n ) {\n if (newSelection.isReverted) {\n model.hasRevertedRangeSelection = true;\n }\n\n return (\n isIndexedSegment(startContainer) &&\n !!this.reconcileTextSelection(\n startContainer,\n startOffset,\n endOffset,\n selectionMarker\n )\n );\n } else {\n const marker1 = this.reconcileNodeSelection(startContainer, startOffset);\n // Pass marker1 to the second call so its adjacent-marker cleanup\n // does not consume the SelectionMarker we just inserted. Without\n // this guard, when marker1 lands directly next to endContainer's\n // segment in paragraph.segments (e.g. startOffset == startContainer\n // text length), the second splice would absorb marker1 and leave\n // setSelection with a dangling reference. See issue #3341.\n const marker2 = this.reconcileNodeSelection(\n endContainer,\n endOffset,\n undefined,\n undefined,\n marker1\n );\n\n if (marker1 && marker2) {\n if (newSelection.isReverted) {\n model.hasRevertedRangeSelection = true;\n }\n\n setSelection(model, marker1, marker2);\n return true;\n } else {\n return false;\n }\n }\n }\n\n break;\n }\n\n return false;\n }\n\n reconcileChildList(addedNodes: ArrayLike<Node>, removedNodes: ArrayLike<Node>): boolean {\n let canHandle = true;\n const context: ReconcileChildListContext = {\n segIndex: -1,\n };\n\n // First process added nodes\n const addedNode = addedNodes[0];\n\n if (addedNodes.length == 1 && isNodeOfType(addedNode, 'TEXT_NODE')) {\n canHandle = this.reconcileAddedNode(addedNode, context);\n } else if (addedNodes.length > 0) {\n canHandle = false;\n }\n\n // Second, process removed nodes\n const removedNode = removedNodes[0];\n\n if (canHandle && removedNodes.length == 1) {\n canHandle = this.reconcileRemovedNode(removedNode, context);\n } else if (removedNodes.length > 0) {\n canHandle = false;\n }\n\n return canHandle && !context.pendingTextNode;\n }\n\n reconcileElementId(element: HTMLElement) {\n if (isElementOfType(element, 'img')) {\n const indexedImg = getIndexedSegmentItem(element);\n\n if (indexedImg?.segments[0]?.segmentType == 'Image') {\n indexedImg.segments[0].format.id = element.id;\n\n return true;\n } else {\n return false;\n }\n } else if (isElementOfType(element, 'table')) {\n const indexedTable = getIndexedTableItem(element);\n\n if (indexedTable) {\n indexedTable.table.format.id = element.id;\n\n return true;\n } else {\n return false;\n }\n } else {\n return false;\n }\n }\n\n private onBlockEntityDelimiter(\n node: Node | null,\n entity: ContentModelEntity,\n parent: ContentModelBlockGroup\n ) {\n if (isNodeOfType(node, 'ELEMENT_NODE') && isEntityDelimiter(node) && node.firstChild) {\n const indexedDelimiter = node.firstChild as IndexedEntityDelimiter;\n\n indexedDelimiter.__roosterjsContentModel = { entity, parent };\n }\n }\n\n private isCollapsed(selection: RangeSelectionForCache): boolean {\n const { start, end } = selection;\n\n return start.node == end.node && start.offset == end.offset;\n }\n\n private reconcileNodeSelection(\n node: Node,\n offset: number,\n defaultFormat?: ContentModelSegmentFormat,\n selectionMarker?: ContentModelSelectionMarker,\n preserveMarker?: Selectable\n ): Selectable | undefined {\n if (isNodeOfType(node, 'TEXT_NODE')) {\n if (isIndexedSegment(node)) {\n return this.reconcileTextSelection(\n node,\n offset,\n undefined,\n selectionMarker,\n preserveMarker\n );\n } else if (isIndexedDelimiter(node)) {\n return this.reconcileDelimiterSelection(node, defaultFormat);\n } else {\n return undefined;\n }\n } else if (offset >= node.childNodes.length) {\n return this.insertMarker(node.lastChild, true /*isAfter*/);\n } else {\n return this.insertMarker(node.childNodes[offset], false /*isAfter*/);\n }\n }\n\n private insertMarker(node: Node | null, isAfter: boolean): Selectable | undefined {\n let marker: ContentModelSelectionMarker | undefined;\n const segmentItem = node && getIndexedSegmentItem(node);\n\n if (segmentItem) {\n const { paragraph, segments } = segmentItem;\n const index = paragraph.segments.indexOf(segments[0]);\n\n if (index >= 0) {\n const formatSegment =\n (!isAfter && paragraph.segments[index - 1]) || paragraph.segments[index];\n marker = createSelectionMarker(formatSegment.format);\n\n paragraph.segments.splice(isAfter ? index + 1 : index, 0, marker);\n }\n }\n\n return marker;\n }\n\n private reconcileTextSelection(\n textNode: IndexedSegmentNode,\n startOffset?: number,\n endOffset?: number,\n selectionMarker?: ContentModelSelectionMarker,\n preserveMarker?: Selectable\n ) {\n const { paragraph, segments } = textNode.__roosterjsContentModel;\n const first = segments[0];\n const last = segments[segments.length - 1];\n let selectable: Selectable | undefined;\n\n if (first?.segmentType == 'Text' && last?.segmentType == 'Text') {\n const newSegments: ContentModelSegment[] = [];\n const txt = textNode.nodeValue || '';\n const textSegments: ContentModelText[] = [];\n\n if (startOffset === undefined) {\n first.text = txt;\n newSegments.push(first);\n textSegments.push(first);\n } else {\n if (startOffset > 0) {\n first.text = txt.substring(0, startOffset);\n newSegments.push(first);\n textSegments.push(first);\n }\n\n if (endOffset === undefined) {\n const marker = createSelectionMarker(selectionMarker?.format ?? first.format);\n newSegments.push(marker);\n\n if (startOffset < (textNode.nodeValue ?? '').length) {\n if (first.link) {\n addLink(marker, first.link);\n }\n\n if (first.code) {\n addCode(marker, first.code);\n }\n }\n\n selectable = marker;\n endOffset = startOffset;\n } else if (endOffset > startOffset) {\n const middle = createText(\n txt.substring(startOffset, endOffset),\n selectionMarker?.format ?? first.format,\n first.link,\n first.code\n );\n\n middle.isSelected = true;\n newSegments.push(middle);\n textSegments.push(middle);\n selectable = middle;\n }\n\n if (endOffset < txt.length) {\n const newLast = createText(\n txt.substring(endOffset),\n selectionMarker?.format ?? first.format,\n first.link,\n first.code\n );\n newSegments.push(newLast);\n textSegments.push(newLast);\n }\n }\n\n let firstIndex = paragraph.segments.indexOf(first);\n let lastIndex = paragraph.segments.indexOf(last);\n\n if (firstIndex >= 0 && lastIndex >= 0) {\n while (\n firstIndex > 0 &&\n paragraph.segments[firstIndex - 1].segmentType == 'SelectionMarker' &&\n paragraph.segments[firstIndex - 1] !== preserveMarker\n ) {\n firstIndex--;\n }\n\n while (\n lastIndex < paragraph.segments.length - 1 &&\n paragraph.segments[lastIndex + 1].segmentType == 'SelectionMarker' &&\n paragraph.segments[lastIndex + 1] !== preserveMarker\n ) {\n lastIndex++;\n }\n\n paragraph.segments.splice(firstIndex, lastIndex - firstIndex + 1, ...newSegments);\n }\n\n this.onSegment(textNode, paragraph, textSegments);\n } else if (first?.segmentType == 'Entity' && first == last) {\n const wrapper = first.wrapper;\n const index = paragraph.segments.indexOf(first);\n const delimiter = textNode.parentElement;\n const isBefore = wrapper.previousSibling == delimiter;\n const isAfter = wrapper.nextSibling == delimiter;\n\n if (index >= 0 && delimiter && isEntityDelimiter(delimiter) && (isBefore || isAfter)) {\n const marker = createSelectionMarker(\n selectionMarker?.format ??\n (paragraph.segments[isAfter ? index + 1 : index - 1] ?? first).format\n );\n\n paragraph.segments.splice(isAfter ? index + 1 : index, 0, marker);\n\n selectable = marker;\n }\n }\n\n return selectable;\n }\n\n private reconcileDelimiterSelection(\n node: IndexedEntityDelimiter,\n defaultFormat?: ContentModelSegmentFormat\n ) {\n let marker: ContentModelSelectionMarker | undefined;\n\n const { entity, parent } = node.__roosterjsContentModel;\n const index = parent.blocks.indexOf(entity);\n const delimiter = node.parentElement;\n const wrapper = entity.wrapper;\n const isBefore = wrapper.previousSibling == delimiter;\n const isAfter = wrapper.nextSibling == delimiter;\n\n if (index >= 0 && delimiter && isEntityDelimiter(delimiter) && (isBefore || isAfter)) {\n marker = createSelectionMarker(defaultFormat);\n\n const para = createParagraph(\n true /*isImplicit*/,\n undefined /*blockFormat*/,\n defaultFormat\n );\n\n para.segments.push(marker);\n parent.blocks.splice(isBefore ? index : index + 1, 0, para);\n }\n\n return marker;\n }\n\n private reconcileAddedNode(node: Text, context: ReconcileChildListContext): boolean {\n let segmentItem: SegmentItem | null = null;\n let index = -1;\n let existingSegment: ContentModelSegment;\n const { previousSibling, nextSibling } = node;\n\n if (\n (segmentItem = getIndexedSegmentItem(getLastLeaf(previousSibling))) &&\n (existingSegment = segmentItem.segments[segmentItem.segments.length - 1]) &&\n (index = segmentItem.paragraph.segments.indexOf(existingSegment)) >= 0\n ) {\n // When we can find indexed segment before current one, use it as the insert index\n this.indexNode(segmentItem.paragraph, index + 1, node, existingSegment.format);\n } else if (\n (segmentItem = getIndexedSegmentItem(getFirstLeaf(nextSibling))) &&\n (existingSegment = segmentItem.segments[0]) &&\n (index = segmentItem.paragraph.segments.indexOf(existingSegment)) >= 0\n ) {\n // When we can find indexed segment after current one, use it as the insert index\n this.indexNode(segmentItem.paragraph, index, node, existingSegment.format);\n } else if (context.paragraph && context.segIndex >= 0) {\n // When there is indexed paragraph from removed nodes, we can use it as the insert index\n this.indexNode(context.paragraph, context.segIndex, node, context.format);\n } else if (context.pendingTextNode === undefined) {\n // When we can't find the insert index, set current node as pending node\n // so later we can pick it up when we have enough info when processing removed node\n // Only do this when pendingTextNode is undefined. If it is null it means there was already a pending node before\n // and in that case we should return false since we can't handle two pending text node\n context.pendingTextNode = node;\n } else {\n return false;\n }\n\n return true;\n }\n\n private reconcileRemovedNode(node: Node, context: ReconcileChildListContext): boolean {\n let segmentItem: SegmentItem | null = null;\n let removingSegment: ContentModelSegment;\n\n if (\n context.segIndex < 0 &&\n !context.paragraph && // No previous removed segment or related paragraph found, and\n (segmentItem = getIndexedSegmentItem(node)) && // The removed node is indexed, and\n (removingSegment = segmentItem.segments[0]) // There is at least one related segment\n ) {\n // Now we can remove the indexed segment from the paragraph, and remember it, later we may need to use it\n context.format = removingSegment.format;\n context.paragraph = segmentItem.paragraph;\n context.segIndex = segmentItem.paragraph.segments.indexOf(segmentItem.segments[0]);\n\n if (context.segIndex < 0) {\n // Indexed segment is not under paragraph, something wrong happens, we cannot keep handling\n return false;\n }\n\n for (let i = 0; i < segmentItem.segments.length; i++) {\n const index = segmentItem.paragraph.segments.indexOf(segmentItem.segments[i]);\n\n if (index >= 0) {\n segmentItem.paragraph.segments.splice(index, 1);\n }\n }\n\n if (context.pendingTextNode) {\n // If we have pending text node added but not indexed, do it now\n this.indexNode(\n context.paragraph,\n context.segIndex,\n context.pendingTextNode,\n segmentItem.segments[0].format\n );\n\n // Set to null since we have processed it.\n // Next time we see a pending node we know we have already processed one so it is a situation we cannot handle\n context.pendingTextNode = null;\n }\n\n return true;\n } else {\n return false;\n }\n }\n\n private indexNode(\n paragraph: ContentModelParagraph,\n index: number,\n textNode: Text,\n format?: ContentModelSegmentFormat\n ) {\n const copiedFormat = format ? { ...format } : undefined;\n\n if (copiedFormat) {\n getObjectKeys(copiedFormat).forEach(key => {\n if (EmptySegmentFormat[key] === undefined) {\n delete copiedFormat[key];\n }\n });\n }\n\n const text = createText(textNode.textContent ?? '', copiedFormat);\n\n paragraph.segments.splice(index, 0, text);\n this.onSegment(textNode, paragraph, [text]);\n }\n\n private selectionMarkerToKeepWhenEnteringTextNode(\n oldSelection: CacheSelection,\n newSelection: DOMSelection\n ): ContentModelSelectionMarker | undefined {\n // For CJK keyboard input on mobile, we may have a situation like this:\n // User toggle bold/italic/underline on an empty div, the pending format will be applied on the selection marker\n // then type some text, the selection move to the text node and the selection marker will be recreated during the reconciliation and lose its original formatting\n // In this case, we need to keep the original formatting of the selection marker to match the pending format\n\n if (\n this.keepSelectionMarkerWhenEnteringTextNode &&\n oldSelection.type == 'range' &&\n this.isCollapsed(oldSelection) &&\n newSelection.type == 'range' &&\n isNodeOfType(newSelection.range.commonAncestorContainer, 'TEXT_NODE') &&\n newSelection.range.commonAncestorContainer.parentElement == oldSelection.start.node &&\n isIndexedSegment(newSelection.range.commonAncestorContainer) &&\n newSelection.range.commonAncestorContainer.__roosterjsContentModel.paragraph.segments[0]\n .segmentType == 'SelectionMarker'\n ) {\n return newSelection.range.commonAncestorContainer.__roosterjsContentModel.paragraph\n .segments[0];\n }\n return undefined;\n }\n}\n\nfunction getLastLeaf(node: Node | null): Node | null {\n while (node?.lastChild) {\n node = node.lastChild;\n }\n\n return node;\n}\n\nfunction getFirstLeaf(node: Node | null): Node | null {\n while (node?.firstChild) {\n node = node.firstChild;\n }\n\n return node;\n}\n\nfunction internalClearIndex(container: Node) {\n unindex(container as IndexedSegmentNode);\n\n for (let node = container.firstChild; node; node = node.nextSibling) {\n internalClearIndex(node);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"domIndexerImpl.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/corePlugin/cache/domIndexerImpl.ts"],"names":[],"mappings":";;;;IAwGA,SAAS,gBAAgB,CAAC,IAAU;;QAC1B,IAAA,KAA0B,MAAC,IAA2B,CAAC,uBAAuB,mCAAI,EAAE,EAAlF,SAAS,eAAA,EAAE,QAAQ,cAA+D,CAAC;QAE3F,OAAO,CACH,SAAS;YACT,SAAS,CAAC,SAAS,IAAI,WAAW;YAClC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC;YACjC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC;YACvB,QAAQ,CAAC,KAAK,CAAC,UAAA,OAAO,IAAI,OAAA,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,EAApC,CAAoC,CAAC,CAClE,CAAC;IACN,CAAC;IAED,SAAS,kBAAkB,CAAC,IAAU;;QAC5B,IAAA,KAAqB,MAAC,IAA+B,CAAC,uBAAuB,mCAAI,EAAE,EAAjF,MAAM,YAAA,EAAE,MAAM,YAAmE,CAAC;QAE1F,OAAO,CACH,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,SAAS,KAAI,QAAQ;YAC7B,MAAM,CAAC,OAAO;aACd,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,cAAc,CAAA;YACtB,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAC/B,CAAC;IACN,CAAC;IAED,SAAS,qBAAqB,CAAC,IAAiB;QAC5C,OAAO,IAAI,IAAI,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC,CAAC,IAAI,CAAC;IAChF,CAAC;IAED,SAAS,mBAAmB,CAAC,OAAyB;QAClD,IAAM,KAAK,GAAI,OAA+B,CAAC,uB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BAAkB,CAAC,SAAe;QACvC,OAAO,CAAC,SAA+B,CAAC,CAAC;QAEzC,KAAK,IAAI,IAAI,GAAG,SAAS,CAAC,UAAU,EAAE,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC,WAAW,EAAE;YACjE,kBAAkB,CAAC,IAAI,CAAC,CAAC;SAC5B;IACL,CAAC","sourcesContent":["import {\n EmptySegmentFormat,\n addCode,\n addLink,\n createParagraph,\n createSelectionMarker,\n createText,\n getObjectKeys,\n isElementOfType,\n isEntityDelimiter,\n isNodeOfType,\n setSelection,\n} from 'roosterjs-content-model-dom';\nimport type {\n CacheSelection,\n ContentModelBlockGroup,\n ContentModelDocument,\n ContentModelEntity,\n ContentModelParagraph,\n ContentModelSegment,\n ContentModelSegmentFormat,\n ContentModelSelectionMarker,\n ContentModelTable,\n ContentModelText,\n DomIndexer,\n DOMSelection,\n RangeSelectionForCache,\n Selectable,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal Export for test only\n */\nexport interface SegmentItem {\n paragraph: ContentModelParagraph;\n segments: ContentModelSegment[];\n}\n\n/**\n * @internal Export for test only\n */\nexport interface TableItem {\n table: ContentModelTable;\n}\n\n/**\n * @internal Export for test only\n */\nexport interface BlockEntityDelimiterItem {\n entity: ContentModelEntity;\n parent: ContentModelBlockGroup;\n}\n\n/**\n * @internal Export for test only\n */\nexport interface IndexedSegmentNode extends Node {\n __roosterjsContentModel: SegmentItem;\n}\n\n/**\n * @internal Export for test only\n */\nexport interface IndexedTableElement extends HTMLTableElement {\n __roosterjsContentModel: TableItem;\n}\n\n/**\n * @internal Export for test only\n */\nexport interface IndexedEntityDelimiter extends Text {\n __roosterjsContentModel: BlockEntityDelimiterItem;\n}\n\n/**\n * Context object used by DomIndexer when reconcile mutations with child list\n */\ninterface ReconcileChildListContext {\n /**\n * Index of segment in current paragraph\n */\n segIndex: number;\n\n /**\n * The current paragraph that we are handling\n */\n paragraph?: ContentModelParagraph;\n\n /**\n * Text node that is added from mutation but has not been handled. This can happen when we first see an added node then later we see a removed one.\n * e.g. Type text in an empty paragraph (<div><br></div>), so a text node will be added and <BR> will be removed.\n * Set to a valid text node means we need to handle it later. If it is finally not handled, that means we need to clear cache\n * Set to undefined (initial value) means no pending text node is hit yet (valid case)\n * Set to null means there was a pending text node which is already handled, so if we see another pending text node,\n * we should clear cache since we don't know how to handle it\n */\n pendingTextNode?: Text | null;\n\n /**\n * Format of the removed segment, this will be used as the format for newly created segment\n */\n format?: ContentModelSegmentFormat;\n}\n\nfunction isIndexedSegment(node: Node): node is IndexedSegmentNode {\n const { paragraph, segments } = (node as IndexedSegmentNode).__roosterjsContentModel ?? {};\n\n return (\n paragraph &&\n paragraph.blockType == 'Paragraph' &&\n Array.isArray(paragraph.segments) &&\n Array.isArray(segments) &&\n segments.every(segment => paragraph.segments.includes(segment))\n );\n}\n\nfunction isIndexedDelimiter(node: Node): node is IndexedEntityDelimiter {\n const { entity, parent } = (node as IndexedEntityDelimiter).__roosterjsContentModel ?? {};\n\n return (\n entity?.blockType == 'Entity' &&\n entity.wrapper &&\n parent?.blockGroupType &&\n Array.isArray(parent.blocks)\n );\n}\n\nfunction getIndexedSegmentItem(node: Node | null): SegmentItem | null {\n return node && isIndexedSegment(node) ? node.__roosterjsContentModel : null;\n}\n\nfunction getIndexedTableItem(element: HTMLTableElement): TableItem | null {\n const index = (element as IndexedTableElement).__roosterjsContentModel;\n const table = index?.table;\n\n if (\n table?.blockType == 'Table' &&\n Array.isArray(table.rows) &&\n table.rows.every(\n x => Array.isArray(x?.cells) && x.cells.every(y => y?.blockGroupType == 'TableCell')\n )\n ) {\n return index;\n } else {\n return null;\n }\n}\n\n// Make a node not indexed. Do not export this function since we should not let code outside here know this detail\nfunction unindex(node: Partial<IndexedSegmentNode>) {\n delete node.__roosterjsContentModel;\n}\n\n/**\n * @internal\n * Implementation of DomIndexer\n */\nexport class DomIndexerImpl implements DomIndexer {\n constructor(private readonly keepSelectionMarkerWhenEnteringTextNode?: boolean) {}\n\n onSegment(segmentNode: Node, paragraph: ContentModelParagraph, segment: ContentModelSegment[]) {\n const indexedText = segmentNode as IndexedSegmentNode;\n indexedText.__roosterjsContentModel = {\n paragraph,\n segments: segment,\n };\n }\n\n onParagraph(paragraphElement: HTMLElement) {\n let previousText: Text | null = null;\n\n for (let child = paragraphElement.firstChild; child; child = child.nextSibling) {\n if (isNodeOfType(child, 'TEXT_NODE')) {\n if (!previousText) {\n previousText = child;\n } else {\n const item = getIndexedSegmentItem(previousText);\n\n if (item && isIndexedSegment(child)) {\n item.segments = item.segments.concat(\n child.__roosterjsContentModel.segments\n );\n child.__roosterjsContentModel.segments = [];\n }\n }\n } else if (isNodeOfType(child, 'ELEMENT_NODE')) {\n previousText = null;\n\n this.onParagraph(child);\n } else {\n previousText = null;\n }\n }\n }\n\n onTable(tableElement: HTMLTableElement, table: ContentModelTable) {\n const indexedTable = tableElement as IndexedTableElement;\n indexedTable.__roosterjsContentModel = { table };\n }\n\n onBlockEntity(entity: ContentModelEntity, group: ContentModelBlockGroup) {\n this.onBlockEntityDelimiter(entity.wrapper.previousSibling, entity, group);\n this.onBlockEntityDelimiter(entity.wrapper.nextSibling, entity, group);\n }\n\n onMergeText(targetText: Text, sourceText: Text) {\n if (isIndexedSegment(targetText) && isIndexedSegment(sourceText)) {\n if (targetText.nextSibling == sourceText) {\n targetText.__roosterjsContentModel.segments.push(\n ...sourceText.__roosterjsContentModel.segments\n );\n\n unindex(sourceText);\n }\n } else {\n unindex(sourceText);\n unindex(targetText);\n }\n }\n\n clearIndex(container: Node) {\n internalClearIndex(container);\n }\n\n reconcileSelection(\n model: ContentModelDocument,\n newSelection: DOMSelection,\n oldSelection?: CacheSelection\n ): boolean {\n let selectionMarker: ContentModelSelectionMarker | undefined;\n if (oldSelection) {\n let startNode: Node | undefined;\n\n if (\n oldSelection.type == 'range' &&\n this.isCollapsed(oldSelection) &&\n (startNode = oldSelection.start.node) &&\n isNodeOfType(startNode, 'TEXT_NODE') &&\n isIndexedSegment(startNode) &&\n startNode.__roosterjsContentModel.segments.length > 0\n ) {\n this.reconcileTextSelection(startNode);\n } else {\n selectionMarker = this.selectionMarkerToKeepWhenEnteringTextNode(\n oldSelection,\n newSelection\n );\n\n setSelection(model);\n }\n }\n\n switch (newSelection.type) {\n case 'image':\n const indexedImage = getIndexedSegmentItem(newSelection.image);\n const image = indexedImage?.segments[0];\n\n if (image) {\n image.isSelected = true;\n setSelection(model, image);\n\n return true;\n } else {\n return false;\n }\n\n case 'table':\n const indexedTable = getIndexedTableItem(newSelection.table);\n\n if (indexedTable) {\n const firstCell =\n indexedTable.table.rows[newSelection.firstRow]?.cells[\n newSelection.firstColumn\n ];\n const lastCell =\n indexedTable.table.rows[newSelection.lastRow]?.cells[\n newSelection.lastColumn\n ];\n\n if (firstCell && lastCell) {\n setSelection(model, firstCell, lastCell);\n\n return true;\n }\n }\n\n return false;\n\n case 'range':\n const newRange = newSelection.range;\n if (newRange) {\n const {\n startContainer,\n startOffset,\n endContainer,\n endOffset,\n collapsed,\n } = newRange;\n\n delete model.hasRevertedRangeSelection;\n\n if (collapsed) {\n return !!this.reconcileNodeSelection(\n startContainer,\n startOffset,\n model.format,\n selectionMarker\n );\n } else if (\n startContainer == endContainer &&\n isNodeOfType(startContainer, 'TEXT_NODE')\n ) {\n if (newSelection.isReverted) {\n model.hasRevertedRangeSelection = true;\n }\n\n return (\n isIndexedSegment(startContainer) &&\n !!this.reconcileTextSelection(\n startContainer,\n startOffset,\n endOffset,\n selectionMarker\n )\n );\n } else {\n const marker1 = this.reconcileNodeSelection(startContainer, startOffset);\n // Pass marker1 to the second call so its adjacent-marker cleanup\n // does not consume the SelectionMarker we just inserted. Without\n // this guard, when marker1 lands directly next to endContainer's\n // segment in paragraph.segments (e.g. startOffset == startContainer\n // text length), the second splice would absorb marker1 and leave\n // setSelection with a dangling reference. See issue #3341.\n const marker2 = this.reconcileNodeSelection(\n endContainer,\n endOffset,\n undefined,\n undefined,\n marker1\n );\n\n if (marker1 && marker2) {\n if (newSelection.isReverted) {\n model.hasRevertedRangeSelection = true;\n }\n\n setSelection(model, marker1, marker2);\n return true;\n } else {\n return false;\n }\n }\n }\n\n break;\n }\n\n return false;\n }\n\n reconcileChildList(addedNodes: ArrayLike<Node>, removedNodes: ArrayLike<Node>): boolean {\n let canHandle = true;\n const context: ReconcileChildListContext = {\n segIndex: -1,\n };\n\n // First process added nodes\n const addedNode = addedNodes[0];\n\n if (addedNodes.length == 1 && isNodeOfType(addedNode, 'TEXT_NODE')) {\n canHandle = this.reconcileAddedNode(addedNode, context);\n } else if (addedNodes.length > 0) {\n canHandle = false;\n }\n\n // Second, process removed nodes\n const removedNode = removedNodes[0];\n\n if (canHandle && removedNodes.length == 1) {\n canHandle = this.reconcileRemovedNode(removedNode, context);\n } else if (removedNodes.length > 0) {\n canHandle = false;\n }\n\n return canHandle && !context.pendingTextNode;\n }\n\n reconcileElementId(element: HTMLElement) {\n if (isElementOfType(element, 'img')) {\n const indexedImg = getIndexedSegmentItem(element);\n\n if (indexedImg?.segments[0]?.segmentType == 'Image') {\n indexedImg.segments[0].format.id = element.id;\n\n return true;\n } else {\n return false;\n }\n } else if (isElementOfType(element, 'table')) {\n const indexedTable = getIndexedTableItem(element);\n\n if (indexedTable) {\n indexedTable.table.format.id = element.id;\n\n return true;\n } else {\n return false;\n }\n } else {\n return false;\n }\n }\n\n reconcileImageAttribute(element: HTMLElement, attributeName: string) {\n if (isElementOfType(element, 'img')) {\n const image = getIndexedSegmentItem(element)?.segments[0];\n\n if (image?.segmentType == 'Image') {\n if (attributeName == 'src') {\n // Use getAttribute('src') instead of retrieving src directly, in case the src\n // has port and may be stripped by browser. This matches imageProcessor.\n image.src = element.getAttribute('src') ?? '';\n\n return true;\n } else if (attributeName.indexOf('data-') == 0) {\n // A data-* attribute may be added, modified or removed. Rebuild the whole\n // dataset from DOM to keep it in sync, the same way imageProcessor builds it.\n const { dataset } = image;\n\n getObjectKeys(dataset).forEach(key => {\n delete dataset[key];\n });\n\n getObjectKeys(element.dataset).forEach(key => {\n dataset[key] = element.dataset[key] || '';\n });\n\n return true;\n }\n }\n }\n\n return false;\n }\n\n private onBlockEntityDelimiter(\n node: Node | null,\n entity: ContentModelEntity,\n parent: ContentModelBlockGroup\n ) {\n if (isNodeOfType(node, 'ELEMENT_NODE') && isEntityDelimiter(node) && node.firstChild) {\n const indexedDelimiter = node.firstChild as IndexedEntityDelimiter;\n\n indexedDelimiter.__roosterjsContentModel = { entity, parent };\n }\n }\n\n private isCollapsed(selection: RangeSelectionForCache): boolean {\n const { start, end } = selection;\n\n return start.node == end.node && start.offset == end.offset;\n }\n\n private reconcileNodeSelection(\n node: Node,\n offset: number,\n defaultFormat?: ContentModelSegmentFormat,\n selectionMarker?: ContentModelSelectionMarker,\n preserveMarker?: Selectable\n ): Selectable | undefined {\n if (isNodeOfType(node, 'TEXT_NODE')) {\n if (isIndexedSegment(node)) {\n return this.reconcileTextSelection(\n node,\n offset,\n undefined,\n selectionMarker,\n preserveMarker\n );\n } else if (isIndexedDelimiter(node)) {\n return this.reconcileDelimiterSelection(node, defaultFormat);\n } else {\n return undefined;\n }\n } else if (offset >= node.childNodes.length) {\n return this.insertMarker(node.lastChild, true /*isAfter*/);\n } else {\n return this.insertMarker(node.childNodes[offset], false /*isAfter*/);\n }\n }\n\n private insertMarker(node: Node | null, isAfter: boolean): Selectable | undefined {\n let marker: ContentModelSelectionMarker | undefined;\n const segmentItem = node && getIndexedSegmentItem(node);\n\n if (segmentItem) {\n const { paragraph, segments } = segmentItem;\n const index = paragraph.segments.indexOf(segments[0]);\n\n if (index >= 0) {\n const formatSegment =\n (!isAfter && paragraph.segments[index - 1]) || paragraph.segments[index];\n marker = createSelectionMarker(formatSegment.format);\n\n paragraph.segments.splice(isAfter ? index + 1 : index, 0, marker);\n }\n }\n\n return marker;\n }\n\n private reconcileTextSelection(\n textNode: IndexedSegmentNode,\n startOffset?: number,\n endOffset?: number,\n selectionMarker?: ContentModelSelectionMarker,\n preserveMarker?: Selectable\n ) {\n const { paragraph, segments } = textNode.__roosterjsContentModel;\n const first = segments[0];\n const last = segments[segments.length - 1];\n let selectable: Selectable | undefined;\n\n if (first?.segmentType == 'Text' && last?.segmentType == 'Text') {\n const newSegments: ContentModelSegment[] = [];\n const txt = textNode.nodeValue || '';\n const textSegments: ContentModelText[] = [];\n\n if (startOffset === undefined) {\n first.text = txt;\n newSegments.push(first);\n textSegments.push(first);\n } else {\n if (startOffset > 0) {\n first.text = txt.substring(0, startOffset);\n newSegments.push(first);\n textSegments.push(first);\n }\n\n if (endOffset === undefined) {\n const marker = createSelectionMarker(selectionMarker?.format ?? first.format);\n newSegments.push(marker);\n\n if (startOffset < (textNode.nodeValue ?? '').length) {\n if (first.link) {\n addLink(marker, first.link);\n }\n\n if (first.code) {\n addCode(marker, first.code);\n }\n }\n\n selectable = marker;\n endOffset = startOffset;\n } else if (endOffset > startOffset) {\n const middle = createText(\n txt.substring(startOffset, endOffset),\n selectionMarker?.format ?? first.format,\n first.link,\n first.code\n );\n\n middle.isSelected = true;\n newSegments.push(middle);\n textSegments.push(middle);\n selectable = middle;\n }\n\n if (endOffset < txt.length) {\n const newLast = createText(\n txt.substring(endOffset),\n selectionMarker?.format ?? first.format,\n first.link,\n first.code\n );\n newSegments.push(newLast);\n textSegments.push(newLast);\n }\n }\n\n let firstIndex = paragraph.segments.indexOf(first);\n let lastIndex = paragraph.segments.indexOf(last);\n\n if (firstIndex >= 0 && lastIndex >= 0) {\n while (\n firstIndex > 0 &&\n paragraph.segments[firstIndex - 1].segmentType == 'SelectionMarker' &&\n paragraph.segments[firstIndex - 1] !== preserveMarker\n ) {\n firstIndex--;\n }\n\n while (\n lastIndex < paragraph.segments.length - 1 &&\n paragraph.segments[lastIndex + 1].segmentType == 'SelectionMarker' &&\n paragraph.segments[lastIndex + 1] !== preserveMarker\n ) {\n lastIndex++;\n }\n\n paragraph.segments.splice(firstIndex, lastIndex - firstIndex + 1, ...newSegments);\n }\n\n this.onSegment(textNode, paragraph, textSegments);\n } else if (first?.segmentType == 'Entity' && first == last) {\n const wrapper = first.wrapper;\n const index = paragraph.segments.indexOf(first);\n const delimiter = textNode.parentElement;\n const isBefore = wrapper.previousSibling == delimiter;\n const isAfter = wrapper.nextSibling == delimiter;\n\n if (index >= 0 && delimiter && isEntityDelimiter(delimiter) && (isBefore || isAfter)) {\n const marker = createSelectionMarker(\n selectionMarker?.format ??\n (paragraph.segments[isAfter ? index + 1 : index - 1] ?? first).format\n );\n\n paragraph.segments.splice(isAfter ? index + 1 : index, 0, marker);\n\n selectable = marker;\n }\n }\n\n return selectable;\n }\n\n private reconcileDelimiterSelection(\n node: IndexedEntityDelimiter,\n defaultFormat?: ContentModelSegmentFormat\n ) {\n let marker: ContentModelSelectionMarker | undefined;\n\n const { entity, parent } = node.__roosterjsContentModel;\n const index = parent.blocks.indexOf(entity);\n const delimiter = node.parentElement;\n const wrapper = entity.wrapper;\n const isBefore = wrapper.previousSibling == delimiter;\n const isAfter = wrapper.nextSibling == delimiter;\n\n if (index >= 0 && delimiter && isEntityDelimiter(delimiter) && (isBefore || isAfter)) {\n marker = createSelectionMarker(defaultFormat);\n\n const para = createParagraph(\n true /*isImplicit*/,\n undefined /*blockFormat*/,\n defaultFormat\n );\n\n para.segments.push(marker);\n parent.blocks.splice(isBefore ? index : index + 1, 0, para);\n }\n\n return marker;\n }\n\n private reconcileAddedNode(node: Text, context: ReconcileChildListContext): boolean {\n let segmentItem: SegmentItem | null = null;\n let index = -1;\n let existingSegment: ContentModelSegment;\n const { previousSibling, nextSibling } = node;\n\n if (\n (segmentItem = getIndexedSegmentItem(getLastLeaf(previousSibling))) &&\n (existingSegment = segmentItem.segments[segmentItem.segments.length - 1]) &&\n (index = segmentItem.paragraph.segments.indexOf(existingSegment)) >= 0\n ) {\n // When we can find indexed segment before current one, use it as the insert index\n this.indexNode(segmentItem.paragraph, index + 1, node, existingSegment.format);\n } else if (\n (segmentItem = getIndexedSegmentItem(getFirstLeaf(nextSibling))) &&\n (existingSegment = segmentItem.segments[0]) &&\n (index = segmentItem.paragraph.segments.indexOf(existingSegment)) >= 0\n ) {\n // When we can find indexed segment after current one, use it as the insert index\n this.indexNode(segmentItem.paragraph, index, node, existingSegment.format);\n } else if (context.paragraph && context.segIndex >= 0) {\n // When there is indexed paragraph from removed nodes, we can use it as the insert index\n this.indexNode(context.paragraph, context.segIndex, node, context.format);\n } else if (context.pendingTextNode === undefined) {\n // When we can't find the insert index, set current node as pending node\n // so later we can pick it up when we have enough info when processing removed node\n // Only do this when pendingTextNode is undefined. If it is null it means there was already a pending node before\n // and in that case we should return false since we can't handle two pending text node\n context.pendingTextNode = node;\n } else {\n return false;\n }\n\n return true;\n }\n\n private reconcileRemovedNode(node: Node, context: ReconcileChildListContext): boolean {\n let segmentItem: SegmentItem | null = null;\n let removingSegment: ContentModelSegment;\n\n if (\n context.segIndex < 0 &&\n !context.paragraph && // No previous removed segment or related paragraph found, and\n (segmentItem = getIndexedSegmentItem(node)) && // The removed node is indexed, and\n (removingSegment = segmentItem.segments[0]) // There is at least one related segment\n ) {\n // Now we can remove the indexed segment from the paragraph, and remember it, later we may need to use it\n context.format = removingSegment.format;\n context.paragraph = segmentItem.paragraph;\n context.segIndex = segmentItem.paragraph.segments.indexOf(segmentItem.segments[0]);\n\n if (context.segIndex < 0) {\n // Indexed segment is not under paragraph, something wrong happens, we cannot keep handling\n return false;\n }\n\n for (let i = 0; i < segmentItem.segments.length; i++) {\n const index = segmentItem.paragraph.segments.indexOf(segmentItem.segments[i]);\n\n if (index >= 0) {\n segmentItem.paragraph.segments.splice(index, 1);\n }\n }\n\n if (context.pendingTextNode) {\n // If we have pending text node added but not indexed, do it now\n this.indexNode(\n context.paragraph,\n context.segIndex,\n context.pendingTextNode,\n segmentItem.segments[0].format\n );\n\n // Set to null since we have processed it.\n // Next time we see a pending node we know we have already processed one so it is a situation we cannot handle\n context.pendingTextNode = null;\n }\n\n return true;\n } else {\n return false;\n }\n }\n\n private indexNode(\n paragraph: ContentModelParagraph,\n index: number,\n textNode: Text,\n format?: ContentModelSegmentFormat\n ) {\n const copiedFormat = format ? { ...format } : undefined;\n\n if (copiedFormat) {\n getObjectKeys(copiedFormat).forEach(key => {\n if (EmptySegmentFormat[key] === undefined) {\n delete copiedFormat[key];\n }\n });\n }\n\n const text = createText(textNode.textContent ?? '', copiedFormat);\n\n paragraph.segments.splice(index, 0, text);\n this.onSegment(textNode, paragraph, [text]);\n }\n\n private selectionMarkerToKeepWhenEnteringTextNode(\n oldSelection: CacheSelection,\n newSelection: DOMSelection\n ): ContentModelSelectionMarker | undefined {\n // For CJK keyboard input on mobile, we may have a situation like this:\n // User toggle bold/italic/underline on an empty div, the pending format will be applied on the selection marker\n // then type some text, the selection move to the text node and the selection marker will be recreated during the reconciliation and lose its original formatting\n // In this case, we need to keep the original formatting of the selection marker to match the pending format\n\n if (\n this.keepSelectionMarkerWhenEnteringTextNode &&\n oldSelection.type == 'range' &&\n this.isCollapsed(oldSelection) &&\n newSelection.type == 'range' &&\n isNodeOfType(newSelection.range.commonAncestorContainer, 'TEXT_NODE') &&\n newSelection.range.commonAncestorContainer.parentElement == oldSelection.start.node &&\n isIndexedSegment(newSelection.range.commonAncestorContainer) &&\n newSelection.range.commonAncestorContainer.__roosterjsContentModel.paragraph.segments[0]\n .segmentType == 'SelectionMarker'\n ) {\n return newSelection.range.commonAncestorContainer.__roosterjsContentModel.paragraph\n .segments[0];\n }\n return undefined;\n }\n}\n\nfunction getLastLeaf(node: Node | null): Node | null {\n while (node?.lastChild) {\n node = node.lastChild;\n }\n\n return node;\n}\n\nfunction getFirstLeaf(node: Node | null): Node | null {\n while (node?.firstChild) {\n node = node.firstChild;\n }\n\n return node;\n}\n\nfunction internalClearIndex(container: Node) {\n unindex(container as IndexedSegmentNode);\n\n for (let node = container.firstChild; node; node = node.nextSibling) {\n internalClearIndex(node);\n }\n}\n"]}
|
|
@@ -40,6 +40,16 @@ define(["require", "exports", "../../editor/core/DOMHelperImpl", "roosterjs-cont
|
|
|
40
40
|
(0, roosterjs_content_model_dom_1.isNodeOfType)(target, 'ELEMENT_NODE')) {
|
|
41
41
|
_this.onMutation({ type: 'elementId', element: target });
|
|
42
42
|
}
|
|
43
|
+
else if (mutation.attributeName &&
|
|
44
|
+
(0, roosterjs_content_model_dom_1.isNodeOfType)(target, 'ELEMENT_NODE') &&
|
|
45
|
+
(mutation.attributeName == 'src' ||
|
|
46
|
+
mutation.attributeName.indexOf('data-') == 0)) {
|
|
47
|
+
_this.onMutation({
|
|
48
|
+
type: 'attribute',
|
|
49
|
+
element: target,
|
|
50
|
+
attributeName: mutation.attributeName,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
43
53
|
else {
|
|
44
54
|
// We cannot handle attributes changes on editor content for now
|
|
45
55
|
canHandle = false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"textMutationObserver.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/corePlugin/cache/textMutationObserver.ts"],"names":[],"mappings":";;;;IASA;QAII,kCACY,UAA0B,EAC1B,UAAwC;YAFpD,iBAMC;YALW,eAAU,GAAV,UAAU,CAAgB;YAC1B,eAAU,GAAV,UAAU,CAA8B;YA2B5C,uBAAkB,GAAG,UAAC,SAA2B;gBACrD,IAAI,SAAS,GAAG,IAAI,CAAC;gBACrB,IAAI,WAAW,GAAgB,IAAI,CAAC;gBACpC,IAAI,kBAAkB,GAAgB,IAAI,CAAC;gBAC3C,IAAI,UAAU,GAAW,EAAE,CAAC;gBAC5B,IAAI,YAAY,GAAW,EAAE,CAAC;gBAC9B,IAAI,aAAa,GAAG,KAAK,CAAC;gBAE1B,IAAM,YAAY,GAAG,IAAI,GAAG,EAAQ,CAAC;gBACrC,IAAM,aAAa,GAAG,IAAI,GAAG,EAAQ,CAAC;gBAEtC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,IAAI,SAAS,EAAE,CAAC,EAAE,EAAE;oBACpD,IAAM,QAAQ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6BACxB;4BACD,MAAM;wBAEV,KAAK,WAAW;4BACZ,IAAI,CAAC,WAAW,EAAE;gCACd,WAAW,GAAG,QAAQ,CAAC,MAAM,CAAC;6BACjC;iCAAM,IAAI,WAAW,IAAI,QAAQ,CAAC,MAAM,EAAE;gCACvC,SAAS,GAAG,KAAK,CAAC;6BACrB;4BAED,IAAI,SAAS,EAAE;gCACX,UAAU,GAAG,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC;gCAChE,YAAY,GAAG,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,CAAC;6BACzE;4BAED,MAAM;qBACb;iBACJ;gBAED,IAAI,SAAS,EAAE;oBACX,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE;wBAClD,KAAI,CAAC,UAAU,CAAC;4BACZ,IAAI,EAAE,WAAW;4BACjB,UAAU,YAAA;4BACV,YAAY,cAAA;yBACf,CAAC,CAAC;qBACN;oBAED,IAAI,aAAa,EAAE;wBACf,KAAI,CAAC,UAAU,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;qBACrC;iBACJ;qBAAM;oBACH,KAAI,CAAC,UAAU,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;iBACxC;YACL,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"textMutationObserver.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/corePlugin/cache/textMutationObserver.ts"],"names":[],"mappings":";;;;IASA;QAII,kCACY,UAA0B,EAC1B,UAAwC;YAFpD,iBAMC;YALW,eAAU,GAAV,UAAU,CAAgB;YAC1B,eAAU,GAAV,UAAU,CAA8B;YA2B5C,uBAAkB,GAAG,UAAC,SAA2B;gBACrD,IAAI,SAAS,GAAG,IAAI,CAAC;gBACrB,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B,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IAChE,CAAC;IALD,gEAKC","sourcesContent":["import { createDOMHelper } from '../../editor/core/DOMHelperImpl';\nimport {\n findClosestBlockEntityContainer,\n findClosestEntityWrapper,\n isNodeOfType,\n} from 'roosterjs-content-model-dom';\nimport type { DOMHelper, TextMutationObserver } from 'roosterjs-content-model-types';\nimport type { Mutation } from './MutationType';\n\nclass TextMutationObserverImpl implements TextMutationObserver {\n private observer: MutationObserver;\n private domHelper: DOMHelper;\n\n constructor(\n private contentDiv: HTMLDivElement,\n private onMutation: (mutation: Mutation) => void\n ) {\n this.observer = new MutationObserver(this.onMutationInternal);\n this.domHelper = createDOMHelper(contentDiv);\n }\n\n startObserving() {\n this.observer.observe(this.contentDiv, {\n subtree: true,\n childList: true,\n attributes: true,\n characterData: true,\n });\n }\n\n stopObserving() {\n this.observer.disconnect();\n }\n\n flushMutations(ignoreMutations?: boolean) {\n const mutations = this.observer.takeRecords();\n\n if (!ignoreMutations) {\n this.onMutationInternal(mutations);\n }\n }\n\n private onMutationInternal = (mutations: MutationRecord[]) => {\n let canHandle = true;\n let firstTarget: Node | null = null;\n let lastTextChangeNode: Node | null = null;\n let addedNodes: Node[] = [];\n let removedNodes: Node[] = [];\n let reconcileText = false;\n\n const ignoredNodes = new Set<Node>();\n const includedNodes = new Set<Node>();\n\n for (let i = 0; i < mutations.length && canHandle; i++) {\n const mutation = mutations[i];\n const target = mutation.target;\n\n if (ignoredNodes.has(target)) {\n continue;\n } else if (!includedNodes.has(target)) {\n if (\n !this.domHelper.isNodeInEditor(target) ||\n findClosestEntityWrapper(target, this.domHelper) ||\n findClosestBlockEntityContainer(target, this.domHelper)\n ) {\n ignoredNodes.add(target);\n\n continue;\n } else {\n includedNodes.add(target);\n }\n }\n\n switch (mutation.type) {\n case 'attributes':\n if (this.domHelper.isNodeInEditor(target, true /*excludingSelf*/)) {\n if (\n mutation.attributeName == 'id' &&\n isNodeOfType(target, 'ELEMENT_NODE')\n ) {\n this.onMutation({ type: 'elementId', element: target });\n } else if (\n mutation.attributeName &&\n isNodeOfType(target, 'ELEMENT_NODE') &&\n (mutation.attributeName == 'src' ||\n mutation.attributeName.indexOf('data-') == 0)\n ) {\n this.onMutation({\n type: 'attribute',\n element: target,\n attributeName: mutation.attributeName,\n });\n } else {\n // We cannot handle attributes changes on editor content for now\n canHandle = false;\n }\n }\n break;\n\n case 'characterData':\n if (lastTextChangeNode && lastTextChangeNode != mutation.target) {\n // Multiple text nodes got changed, we don't know how to handle it\n canHandle = false;\n } else {\n lastTextChangeNode = mutation.target;\n reconcileText = true;\n }\n break;\n\n case 'childList':\n if (!firstTarget) {\n firstTarget = mutation.target;\n } else if (firstTarget != mutation.target) {\n canHandle = false;\n }\n\n if (canHandle) {\n addedNodes = addedNodes.concat(Array.from(mutation.addedNodes));\n removedNodes = removedNodes.concat(Array.from(mutation.removedNodes));\n }\n\n break;\n }\n }\n\n if (canHandle) {\n if (addedNodes.length > 0 || removedNodes.length > 0) {\n this.onMutation({\n type: 'childList',\n addedNodes,\n removedNodes,\n });\n }\n\n if (reconcileText) {\n this.onMutation({ type: 'text' });\n }\n } else {\n this.onMutation({ type: 'unknown' });\n }\n };\n}\n\n/**\n * @internal\n */\nexport function createTextMutationObserver(\n contentDiv: HTMLDivElement,\n onMutation: (mutation: Mutation) => void\n): TextMutationObserver {\n return new TextMutationObserverImpl(contentDiv, onMutation);\n}\n"]}
|
|
@@ -31,6 +31,9 @@ export var createContentModel = function (core, option, selectionOverride) {
|
|
|
31
31
|
var domToModelContext = option
|
|
32
32
|
? createDomToModelContext(editorContext, settings.builtIn, settings.customized, option)
|
|
33
33
|
: createDomToModelContextWithConfig(settings.calculated, editorContext);
|
|
34
|
+
if (option === null || option === void 0 ? void 0 : option.skipFormatContainerFallbackCheck) {
|
|
35
|
+
domToModelContext.skipFormatContainerFallbackCheck = true;
|
|
36
|
+
}
|
|
34
37
|
if (selection) {
|
|
35
38
|
domToModelContext.selection = selection;
|
|
36
39
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createContentModel.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/coreApi/createContentModel/createContentModel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AACjE,OAAO,EACH,UAAU,EACV,uBAAuB,EACvB,iCAAiC,EACjC,iBAAiB,GACpB,MAAM,6BAA6B,CAAC;AAGrC;;;;;;GAMG;AACH,MAAM,CAAC,IAAM,kBAAkB,GAAuB,UAAC,IAAI,EAAE,MAAM,EAAE,iBAAiB;;IAClF,6EAA6E;IAC7E,MAAA,IAAI,CAAC,KAAK,CAAC,oBAAoB,0CAAE,cAAc,EAAE,CAAC;IAClD,IAAM,eAAe,GACjB,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,eAAe,IAAI,OAAO,MAAM,CAAC,oBAAoB,KAAK,WAAW,CAAC,CAAC;IAE9F,IAAI,CAAC,iBAAiB,IAAI,eAAe,EAAE;QACvC,IAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC;QAE3C,IAAI,WAAW,EAAE;YACb,6EAA6E;YAC7E,OAAO,IAAI,CAAC,SAAS,CAAC,kBAAkB;gBACpC,CAAC,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,oBAAoB,EAAE,IAAI,EAAE,CAAC;gBACzD,CAAC,CAAC,WAAW,CAAC;SACrB;KACJ;IAED,IAAM,SAAS,GACX,iBAAiB,IAAI,MAAM;QACvB,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,iBAAiB,IAAI,IAAI,CAAC,GAAG,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,SAAS,CAAC;IAC3E,IAAM,SAAS,GAAG,CAAC,MAAM,IAAI,CAAC,iBAAiB,CAAC;IAChD,IAAM,aAAa,GAAG,IAAI,CAAC,GAAG,CAAC,mBAAmB,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IAEpE,aAAa,CAAC,oBAAoB,GAAG,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,oBAAoB,CAAC;IAElE,IAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,kBAAkB,CAAC;IACrD,IAAM,iBAAiB,GAAG,MAAM;QAC5B,CAAC,CAAC,uBAAuB,CAAC,aAAa,EAAE,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;QACvF,CAAC,CAAC,iCAAiC,CAAC,QAAQ,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;IAE5E,IAAI,SAAS,EAAE;QACX,iBAAiB,CAAC,SAAS,GAAG,SAAS,CAAC;KAC3C;IAED,IAAM,KAAK,GAAG,iBAAiB,CAAC,IAAI,CAAC,WAAW,EAAE,iBAAiB,CAAC,CAAC;IAErE,IAAI,SAAS,EAAE;QACX,WAAW,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC;KAC7C;IAED,OAAO,KAAK,CAAC;AACjB,CAAC,CAAC","sourcesContent":["import { updateCache } from '../../corePlugin/cache/updateCache';\nimport {\n cloneModel,\n createDomToModelContext,\n createDomToModelContextWithConfig,\n domToContentModel,\n} from 'roosterjs-content-model-dom';\nimport type { CreateContentModel } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n * Create Content Model from DOM tree in this editor\n * @param core The editor core object\n * @param option The option to customize the behavior of DOM to Content Model conversion\n * @param selectionOverride When passed, use this selection range instead of current selection in editor\n */\nexport const createContentModel: CreateContentModel = (core, option, selectionOverride) => {\n // Flush all mutations if any, so that we can get an up-to-date Content Model\n core.cache.textMutationObserver?.flushMutations();\n const tryGetFromCache =\n !option || (option.tryGetFromCache && typeof option.recalculateTableSize === 'undefined');\n\n if (!selectionOverride && tryGetFromCache) {\n const cachedModel = core.cache.cachedModel;\n\n if (cachedModel) {\n // When in shadow edit, use a cloned model so we won't pollute the cached one\n return core.lifecycle.shadowEditFragment\n ? cloneModel(cachedModel, { includeCachedElement: true })\n : cachedModel;\n }\n }\n\n const selection =\n selectionOverride == 'none'\n ? undefined\n : selectionOverride || core.api.getDOMSelection(core) || undefined;\n const saveIndex = !option && !selectionOverride;\n const editorContext = core.api.createEditorContext(core, saveIndex);\n\n editorContext.recalculateTableSize = option?.recalculateTableSize;\n\n const settings = core.environment.domToModelSettings;\n const domToModelContext = option\n ? createDomToModelContext(editorContext, settings.builtIn, settings.customized, option)\n : createDomToModelContextWithConfig(settings.calculated, editorContext);\n\n if (selection) {\n domToModelContext.selection = selection;\n }\n\n const model = domToContentModel(core.logicalRoot, domToModelContext);\n\n if (saveIndex) {\n updateCache(core.cache, model, selection);\n }\n\n return model;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"createContentModel.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/coreApi/createContentModel/createContentModel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AACjE,OAAO,EACH,UAAU,EACV,uBAAuB,EACvB,iCAAiC,EACjC,iBAAiB,GACpB,MAAM,6BAA6B,CAAC;AAGrC;;;;;;GAMG;AACH,MAAM,CAAC,IAAM,kBAAkB,GAAuB,UAAC,IAAI,EAAE,MAAM,EAAE,iBAAiB;;IAClF,6EAA6E;IAC7E,MAAA,IAAI,CAAC,KAAK,CAAC,oBAAoB,0CAAE,cAAc,EAAE,CAAC;IAClD,IAAM,eAAe,GACjB,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,eAAe,IAAI,OAAO,MAAM,CAAC,oBAAoB,KAAK,WAAW,CAAC,CAAC;IAE9F,IAAI,CAAC,iBAAiB,IAAI,eAAe,EAAE;QACvC,IAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC;QAE3C,IAAI,WAAW,EAAE;YACb,6EAA6E;YAC7E,OAAO,IAAI,CAAC,SAAS,CAAC,kBAAkB;gBACpC,CAAC,CAAC,UAAU,CAAC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/updateCache';\nimport {\n cloneModel,\n createDomToModelContext,\n createDomToModelContextWithConfig,\n domToContentModel,\n} from 'roosterjs-content-model-dom';\nimport type { CreateContentModel } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n * Create Content Model from DOM tree in this editor\n * @param core The editor core object\n * @param option The option to customize the behavior of DOM to Content Model conversion\n * @param selectionOverride When passed, use this selection range instead of current selection in editor\n */\nexport const createContentModel: CreateContentModel = (core, option, selectionOverride) => {\n // Flush all mutations if any, so that we can get an up-to-date Content Model\n core.cache.textMutationObserver?.flushMutations();\n const tryGetFromCache =\n !option || (option.tryGetFromCache && typeof option.recalculateTableSize === 'undefined');\n\n if (!selectionOverride && tryGetFromCache) {\n const cachedModel = core.cache.cachedModel;\n\n if (cachedModel) {\n // When in shadow edit, use a cloned model so we won't pollute the cached one\n return core.lifecycle.shadowEditFragment\n ? cloneModel(cachedModel, { includeCachedElement: true })\n : cachedModel;\n }\n }\n\n const selection =\n selectionOverride == 'none'\n ? undefined\n : selectionOverride || core.api.getDOMSelection(core) || undefined;\n const saveIndex = !option && !selectionOverride;\n const editorContext = core.api.createEditorContext(core, saveIndex);\n\n editorContext.recalculateTableSize = option?.recalculateTableSize;\n\n const settings = core.environment.domToModelSettings;\n const domToModelContext = option\n ? createDomToModelContext(editorContext, settings.builtIn, settings.customized, option)\n : createDomToModelContextWithConfig(settings.calculated, editorContext);\n\n if (option?.skipFormatContainerFallbackCheck) {\n domToModelContext.skipFormatContainerFallbackCheck = true;\n }\n\n if (selection) {\n domToModelContext.selection = selection;\n }\n\n const model = domToContentModel(core.logicalRoot, domToModelContext);\n\n if (saveIndex) {\n updateCache(core.cache, model, selection);\n }\n\n return model;\n};\n"]}
|
|
@@ -32,6 +32,11 @@ var CachePlugin = /** @class */ (function () {
|
|
|
32
32
|
_this.invalidateCache();
|
|
33
33
|
}
|
|
34
34
|
break;
|
|
35
|
+
case 'attribute':
|
|
36
|
+
if (!_this.state.domIndexer.reconcileImageAttribute(mutation.element, mutation.attributeName)) {
|
|
37
|
+
_this.invalidateCache();
|
|
38
|
+
}
|
|
39
|
+
break;
|
|
35
40
|
case 'unknown':
|
|
36
41
|
_this.invalidateCache();
|
|
37
42
|
break;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CachePlugin.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/corePlugin/cache/CachePlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAU5C;;GAEG;AACH;IAII;;;;OAIG;IACH,qBAAY,MAAqB,EAAE,UAA0B;QAA7D,iBAcC;QAtBO,WAAM,GAAmB,IAAI,CAAC;QAyG9B,eAAU,GAAG,UAAC,QAAkB;YACpC,IAAI,KAAI,CAAC,MAAM,EAAE;gBACb,QAAQ,QAAQ,CAAC,IAAI,EAAE;oBACnB,KAAK,WAAW;wBACZ,IACI,CAAC,KAAI,CAAC,KAAK,CAAC,UAAU,CAAC,kBAAkB,CACrC,QAAQ,CAAC,UAAU,EACnB,QAAQ,CAAC,YAAY,CACxB,EACH;4BACE,KAAI,CAAC,eAAe,EAAE,CAAC;yBAC1B;wBACD,MAAM;oBAEV,KAAK,MAAM;wBACP,KAAI,CAAC,iBAAiB,CAAC,KAAI,CAAC,MAAM,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;wBAC1D,MAAM;oBAEV,KAAK,WAAW;wBACZ,IAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC;wBAEjC,IAAI,CAAC,KAAI,CAAC,KAAK,CAAC,UAAU,CAAC,kBAAkB,CAAC,OAAO,CAAC,EAAE;4BACpD,KA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ections';\nimport { createParagraphMap } from './ParagraphMapImpl';\nimport { createTextMutationObserver } from './textMutationObserver';\nimport { DomIndexerImpl } from './domIndexerImpl';\nimport { updateCache } from './updateCache';\nimport type { Mutation } from './MutationType';\nimport type {\n CachePluginState,\n IEditor,\n PluginEvent,\n PluginWithState,\n EditorOptions,\n} from 'roosterjs-content-model-types';\n\n/**\n * ContentModel cache plugin manages cached Content Model, and refresh the cache when necessary\n */\nclass CachePlugin implements PluginWithState<CachePluginState> {\n private editor: IEditor | null = null;\n private state: CachePluginState;\n\n /**\n * Construct a new instance of CachePlugin class\n * @param option The editor option\n * @param contentDiv The editor content DIV\n */\n constructor(option: EditorOptions, contentDiv: HTMLDivElement) {\n this.state = {\n domIndexer: new DomIndexerImpl(\n option.experimentalFeatures &&\n option.experimentalFeatures.indexOf(\n 'KeepSelectionMarkerWhenEnteringTextNode'\n ) >= 0\n ),\n textMutationObserver: createTextMutationObserver(contentDiv, this.onMutation),\n };\n\n if (option.enableParagraphMap) {\n this.state.paragraphMap = createParagraphMap();\n }\n }\n\n /**\n * Get name of this plugin\n */\n getName() {\n return 'Cache';\n }\n\n /**\n * The first method that editor will call to a plugin when editor is initializing.\n * It will pass in the editor instance, plugin should take this chance to save the\n * editor reference so that it can call to any editor method or format API later.\n * @param editor The editor object\n */\n initialize(editor: IEditor) {\n this.editor = editor;\n this.editor.getDocument().addEventListener('selectionchange', this.onNativeSelectionChange);\n\n this.state.textMutationObserver.startObserving();\n }\n\n /**\n * The last method that editor will call to a plugin before it is disposed.\n * Plugin can take this chance to clear the reference to editor. After this method is\n * called, plugin should not call to any editor method since it will result in error.\n */\n dispose() {\n this.state.textMutationObserver.stopObserving();\n\n if (this.editor) {\n this.editor\n .getDocument()\n .removeEventListener('selectionchange', this.onNativeSelectionChange);\n this.editor = null;\n }\n }\n\n /**\n * Get plugin state object\n */\n getState(): CachePluginState {\n return this.state;\n }\n\n /**\n * Core method for a plugin. Once an event happens in editor, editor will call this\n * method of each plugin to handle the event as long as the event is not handled\n * exclusively by another plugin.\n * @param event The event to handle:\n */\n onPluginEvent(event: PluginEvent) {\n if (!this.editor) {\n return;\n }\n\n switch (event.eventType) {\n case 'logicalRootChanged':\n this.invalidateCache();\n\n this.state.textMutationObserver.stopObserving();\n this.state.textMutationObserver = createTextMutationObserver(\n event.logicalRoot,\n this.onMutation\n );\n this.state.textMutationObserver.startObserving();\n break;\n\n case 'selectionChanged':\n this.updateCachedModel(this.editor);\n break;\n\n case 'contentChanged':\n const { contentModel, selection } = event;\n\n if (contentModel) {\n updateCache(this.state, contentModel, selection);\n }\n\n break;\n }\n }\n\n private onMutation = (mutation: Mutation) => {\n if (this.editor) {\n switch (mutation.type) {\n case 'childList':\n if (\n !this.state.domIndexer.reconcileChildList(\n mutation.addedNodes,\n mutation.removedNodes\n )\n ) {\n this.invalidateCache();\n }\n break;\n\n case 'text':\n this.updateCachedModel(this.editor, true /*forceUpdate*/);\n break;\n\n case 'elementId':\n const element = mutation.element;\n\n if (!this.state.domIndexer.reconcileElementId(element)) {\n this.invalidateCache();\n }\n\n break;\n\n case 'unknown':\n this.invalidateCache();\n break;\n }\n }\n };\n\n private onNativeSelectionChange = () => {\n if (this.editor?.hasFocus()) {\n this.updateCachedModel(this.editor);\n }\n };\n\n private invalidateCache() {\n if (!this.editor?.isInShadowEdit()) {\n if (this.state.cachedModel) {\n this.state.cachedModel = undefined;\n }\n\n if (this.state.cachedSelection) {\n this.state.cachedSelection = undefined;\n }\n\n // Clear paragraph indexer to prevent stale references to old paragraphs\n // It will be rebuild next time when we create a new Content Model\n this.state.paragraphMap?.clear();\n }\n }\n\n private updateCachedModel(editor: IEditor, forceUpdate?: boolean) {\n if (editor.isInShadowEdit()) {\n return;\n }\n\n const cachedSelection = this.state.cachedSelection;\n this.state.cachedSelection = undefined; // Clear it to force getDOMSelection() retrieve the latest selection range\n\n const newRangeEx = editor.getDOMSelection() || undefined;\n const model = this.state.cachedModel;\n const isSelectionChanged =\n forceUpdate ||\n !cachedSelection ||\n !newRangeEx ||\n !areSameSelections(newRangeEx, cachedSelection);\n\n if (isSelectionChanged) {\n if (\n !model ||\n !newRangeEx ||\n !this.state.domIndexer.reconcileSelection(model, newRangeEx, cachedSelection)\n ) {\n this.invalidateCache();\n } else {\n updateCache(this.state, model, newRangeEx);\n }\n } else {\n this.state.cachedSelection = cachedSelection;\n }\n }\n}\n\n/**\n * @internal\n * Create a new instance of CachePlugin class.\n * @param option The editor option\n * @param contentDiv The editor content DIV\n */\nexport function createCachePlugin(\n option: EditorOptions,\n contentDiv: HTMLDivElement\n): PluginWithState<CachePluginState> {\n return new CachePlugin(option, contentDiv);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"CachePlugin.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/corePlugin/cache/CachePlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAU5C;;GAEG;AACH;IAII;;;;OAIG;IACH,qBAAY,MAAqB,EAAE,UAA0B;QAA7D,iBAcC;QAtBO,WAAM,GAAmB,IAAI,CAAC;QAyG9B,eAAU,GAAG,UAAC,QAAkB;YACpC,IAAI,KAAI,CAAC,MAAM,EAAE;gBACb,QAAQ,QAAQ,CAAC,IAAI,EAAE;oBACnB,KAAK,WAAW;wBACZ,IACI,CAAC,KAAI,CAAC,KAAK,CAAC,UAAU,CAAC,kBAAkB,CACrC,QAAQ,CAAC,UAAU,EACnB,QAAQ,CAAC,YAAY,CACxB,EACH;4BACE,KAAI,CAAC,eAAe,EAAE,CAAC;yBAC1B;wBACD,MAAM;oBAEV,KAAK,MAAM;wBACP,KAAI,CAA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,UAAU,EAAE,eAAe,CAAC,EAC/E;gBACE,IAAI,CAAC,eAAe,EAAE,CAAC;aAC1B;iBAAM;gBACH,WAAW,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC;aAC9C;SACJ;aAAM;YACH,IAAI,CAAC,KAAK,CAAC,eAAe,GAAG,eAAe,CAAC;SAChD;IACL,CAAC;IACL,kBAAC;AAAD,CAAC,AA5MD,IA4MC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAC7B,MAAqB,EACrB,UAA0B;IAE1B,OAAO,IAAI,WAAW,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;AAC/C,CAAC","sourcesContent":["import { areSameSelections } from './areSameSelections';\nimport { createParagraphMap } from './ParagraphMapImpl';\nimport { createTextMutationObserver } from './textMutationObserver';\nimport { DomIndexerImpl } from './domIndexerImpl';\nimport { updateCache } from './updateCache';\nimport type { Mutation } from './MutationType';\nimport type {\n CachePluginState,\n IEditor,\n PluginEvent,\n PluginWithState,\n EditorOptions,\n} from 'roosterjs-content-model-types';\n\n/**\n * ContentModel cache plugin manages cached Content Model, and refresh the cache when necessary\n */\nclass CachePlugin implements PluginWithState<CachePluginState> {\n private editor: IEditor | null = null;\n private state: CachePluginState;\n\n /**\n * Construct a new instance of CachePlugin class\n * @param option The editor option\n * @param contentDiv The editor content DIV\n */\n constructor(option: EditorOptions, contentDiv: HTMLDivElement) {\n this.state = {\n domIndexer: new DomIndexerImpl(\n option.experimentalFeatures &&\n option.experimentalFeatures.indexOf(\n 'KeepSelectionMarkerWhenEnteringTextNode'\n ) >= 0\n ),\n textMutationObserver: createTextMutationObserver(contentDiv, this.onMutation),\n };\n\n if (option.enableParagraphMap) {\n this.state.paragraphMap = createParagraphMap();\n }\n }\n\n /**\n * Get name of this plugin\n */\n getName() {\n return 'Cache';\n }\n\n /**\n * The first method that editor will call to a plugin when editor is initializing.\n * It will pass in the editor instance, plugin should take this chance to save the\n * editor reference so that it can call to any editor method or format API later.\n * @param editor The editor object\n */\n initialize(editor: IEditor) {\n this.editor = editor;\n this.editor.getDocument().addEventListener('selectionchange', this.onNativeSelectionChange);\n\n this.state.textMutationObserver.startObserving();\n }\n\n /**\n * The last method that editor will call to a plugin before it is disposed.\n * Plugin can take this chance to clear the reference to editor. After this method is\n * called, plugin should not call to any editor method since it will result in error.\n */\n dispose() {\n this.state.textMutationObserver.stopObserving();\n\n if (this.editor) {\n this.editor\n .getDocument()\n .removeEventListener('selectionchange', this.onNativeSelectionChange);\n this.editor = null;\n }\n }\n\n /**\n * Get plugin state object\n */\n getState(): CachePluginState {\n return this.state;\n }\n\n /**\n * Core method for a plugin. Once an event happens in editor, editor will call this\n * method of each plugin to handle the event as long as the event is not handled\n * exclusively by another plugin.\n * @param event The event to handle:\n */\n onPluginEvent(event: PluginEvent) {\n if (!this.editor) {\n return;\n }\n\n switch (event.eventType) {\n case 'logicalRootChanged':\n this.invalidateCache();\n\n this.state.textMutationObserver.stopObserving();\n this.state.textMutationObserver = createTextMutationObserver(\n event.logicalRoot,\n this.onMutation\n );\n this.state.textMutationObserver.startObserving();\n break;\n\n case 'selectionChanged':\n this.updateCachedModel(this.editor);\n break;\n\n case 'contentChanged':\n const { contentModel, selection } = event;\n\n if (contentModel) {\n updateCache(this.state, contentModel, selection);\n }\n\n break;\n }\n }\n\n private onMutation = (mutation: Mutation) => {\n if (this.editor) {\n switch (mutation.type) {\n case 'childList':\n if (\n !this.state.domIndexer.reconcileChildList(\n mutation.addedNodes,\n mutation.removedNodes\n )\n ) {\n this.invalidateCache();\n }\n break;\n\n case 'text':\n this.updateCachedModel(this.editor, true /*forceUpdate*/);\n break;\n\n case 'elementId':\n const element = mutation.element;\n\n if (!this.state.domIndexer.reconcileElementId(element)) {\n this.invalidateCache();\n }\n\n break;\n\n case 'attribute':\n if (\n !this.state.domIndexer.reconcileImageAttribute(\n mutation.element,\n mutation.attributeName\n )\n ) {\n this.invalidateCache();\n }\n\n break;\n\n case 'unknown':\n this.invalidateCache();\n break;\n }\n }\n };\n\n private onNativeSelectionChange = () => {\n if (this.editor?.hasFocus()) {\n this.updateCachedModel(this.editor);\n }\n };\n\n private invalidateCache() {\n if (!this.editor?.isInShadowEdit()) {\n if (this.state.cachedModel) {\n this.state.cachedModel = undefined;\n }\n\n if (this.state.cachedSelection) {\n this.state.cachedSelection = undefined;\n }\n\n // Clear paragraph indexer to prevent stale references to old paragraphs\n // It will be rebuild next time when we create a new Content Model\n this.state.paragraphMap?.clear();\n }\n }\n\n private updateCachedModel(editor: IEditor, forceUpdate?: boolean) {\n if (editor.isInShadowEdit()) {\n return;\n }\n\n const cachedSelection = this.state.cachedSelection;\n this.state.cachedSelection = undefined; // Clear it to force getDOMSelection() retrieve the latest selection range\n\n const newRangeEx = editor.getDOMSelection() || undefined;\n const model = this.state.cachedModel;\n const isSelectionChanged =\n forceUpdate ||\n !cachedSelection ||\n !newRangeEx ||\n !areSameSelections(newRangeEx, cachedSelection);\n\n if (isSelectionChanged) {\n if (\n !model ||\n !newRangeEx ||\n !this.state.domIndexer.reconcileSelection(model, newRangeEx, cachedSelection)\n ) {\n this.invalidateCache();\n } else {\n updateCache(this.state, model, newRangeEx);\n }\n } else {\n this.state.cachedSelection = cachedSelection;\n }\n }\n}\n\n/**\n * @internal\n * Create a new instance of CachePlugin class.\n * @param option The editor option\n * @param contentDiv The editor content DIV\n */\nexport function createCachePlugin(\n option: EditorOptions,\n contentDiv: HTMLDivElement\n): PluginWithState<CachePluginState> {\n return new CachePlugin(option, contentDiv);\n}\n"]}
|
|
@@ -10,6 +10,10 @@ export declare type MutationType =
|
|
|
10
10
|
* Element id is changed
|
|
11
11
|
*/
|
|
12
12
|
| 'elementId'
|
|
13
|
+
/**
|
|
14
|
+
* An attribute (such as src or data-*) is changed on an element
|
|
15
|
+
*/
|
|
16
|
+
| 'attribute'
|
|
13
17
|
/**
|
|
14
18
|
* Only text is changed
|
|
15
19
|
*/
|
|
@@ -35,6 +39,13 @@ export interface UnknownMutation extends MutationBase<'unknown'> {
|
|
|
35
39
|
export interface ElementIdMutation extends MutationBase<'elementId'> {
|
|
36
40
|
element: HTMLElement;
|
|
37
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* @internal
|
|
44
|
+
*/
|
|
45
|
+
export interface AttributeMutation extends MutationBase<'attribute'> {
|
|
46
|
+
element: HTMLElement;
|
|
47
|
+
attributeName: string;
|
|
48
|
+
}
|
|
38
49
|
/**
|
|
39
50
|
* @internal
|
|
40
51
|
*/
|
|
@@ -50,4 +61,4 @@ export interface ChildListMutation extends MutationBase<'childList'> {
|
|
|
50
61
|
/**
|
|
51
62
|
* @internal
|
|
52
63
|
*/
|
|
53
|
-
export declare type Mutation = UnknownMutation | ElementIdMutation | TextMutation | ChildListMutation;
|
|
64
|
+
export declare type Mutation = UnknownMutation | ElementIdMutation | AttributeMutation | TextMutation | ChildListMutation;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MutationType.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/corePlugin/cache/MutationType.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * @internal Type of mutations\n */\nexport type MutationType =\n /**\n * We found some change happened but we cannot handle it, so set mutation type as \"unknown\"\n */\n | 'unknown'\n /**\n * Element id is changed\n */\n | 'elementId'\n /**\n * Only text is changed\n */\n | 'text'\n /**\n * Child list is changed\n */\n | 'childList';\n\n/**\n * @internal\n */\nexport interface MutationBase<T extends MutationType> {\n type: T;\n}\n\n/**\n * @internal\n */\nexport interface UnknownMutation extends MutationBase<'unknown'> {}\n\n/**\n * @internal\n */\nexport interface ElementIdMutation extends MutationBase<'elementId'> {\n element: HTMLElement;\n}\n\n/**\n * @internal\n */\nexport interface TextMutation extends MutationBase<'text'> {}\n\n/**\n * @internal\n */\nexport interface ChildListMutation extends MutationBase<'childList'> {\n addedNodes: Node[];\n removedNodes: Node[];\n}\n\n/**\n * @internal\n */\nexport type Mutation
|
|
1
|
+
{"version":3,"file":"MutationType.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/corePlugin/cache/MutationType.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * @internal Type of mutations\n */\nexport type MutationType =\n /**\n * We found some change happened but we cannot handle it, so set mutation type as \"unknown\"\n */\n | 'unknown'\n /**\n * Element id is changed\n */\n | 'elementId'\n /**\n * An attribute (such as src or data-*) is changed on an element\n */\n | 'attribute'\n /**\n * Only text is changed\n */\n | 'text'\n /**\n * Child list is changed\n */\n | 'childList';\n\n/**\n * @internal\n */\nexport interface MutationBase<T extends MutationType> {\n type: T;\n}\n\n/**\n * @internal\n */\nexport interface UnknownMutation extends MutationBase<'unknown'> {}\n\n/**\n * @internal\n */\nexport interface ElementIdMutation extends MutationBase<'elementId'> {\n element: HTMLElement;\n}\n\n/**\n * @internal\n */\nexport interface AttributeMutation extends MutationBase<'attribute'> {\n element: HTMLElement;\n attributeName: string;\n}\n\n/**\n * @internal\n */\nexport interface TextMutation extends MutationBase<'text'> {}\n\n/**\n * @internal\n */\nexport interface ChildListMutation extends MutationBase<'childList'> {\n addedNodes: Node[];\n removedNodes: Node[];\n}\n\n/**\n * @internal\n */\nexport type Mutation =\n | UnknownMutation\n | ElementIdMutation\n | AttributeMutation\n | TextMutation\n | ChildListMutation;\n"]}
|
|
@@ -53,6 +53,7 @@ export declare class DomIndexerImpl implements DomIndexer {
|
|
|
53
53
|
reconcileSelection(model: ContentModelDocument, newSelection: DOMSelection, oldSelection?: CacheSelection): boolean;
|
|
54
54
|
reconcileChildList(addedNodes: ArrayLike<Node>, removedNodes: ArrayLike<Node>): boolean;
|
|
55
55
|
reconcileElementId(element: HTMLElement): boolean;
|
|
56
|
+
reconcileImageAttribute(element: HTMLElement, attributeName: string): boolean;
|
|
56
57
|
private onBlockEntityDelimiter;
|
|
57
58
|
private isCollapsed;
|
|
58
59
|
private reconcileNodeSelection;
|
|
@@ -230,6 +230,33 @@ var DomIndexerImpl = /** @class */ (function () {
|
|
|
230
230
|
return false;
|
|
231
231
|
}
|
|
232
232
|
};
|
|
233
|
+
DomIndexerImpl.prototype.reconcileImageAttribute = function (element, attributeName) {
|
|
234
|
+
var _a, _b;
|
|
235
|
+
if (isElementOfType(element, 'img')) {
|
|
236
|
+
var image = (_a = getIndexedSegmentItem(element)) === null || _a === void 0 ? void 0 : _a.segments[0];
|
|
237
|
+
if ((image === null || image === void 0 ? void 0 : image.segmentType) == 'Image') {
|
|
238
|
+
if (attributeName == 'src') {
|
|
239
|
+
// Use getAttribute('src') instead of retrieving src directly, in case the src
|
|
240
|
+
// has port and may be stripped by browser. This matches imageProcessor.
|
|
241
|
+
image.src = (_b = element.getAttribute('src')) !== null && _b !== void 0 ? _b : '';
|
|
242
|
+
return true;
|
|
243
|
+
}
|
|
244
|
+
else if (attributeName.indexOf('data-') == 0) {
|
|
245
|
+
// A data-* attribute may be added, modified or removed. Rebuild the whole
|
|
246
|
+
// dataset from DOM to keep it in sync, the same way imageProcessor builds it.
|
|
247
|
+
var dataset_1 = image.dataset;
|
|
248
|
+
getObjectKeys(dataset_1).forEach(function (key) {
|
|
249
|
+
delete dataset_1[key];
|
|
250
|
+
});
|
|
251
|
+
getObjectKeys(element.dataset).forEach(function (key) {
|
|
252
|
+
dataset_1[key] = element.dataset[key] || '';
|
|
253
|
+
});
|
|
254
|
+
return true;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return false;
|
|
259
|
+
};
|
|
233
260
|
DomIndexerImpl.prototype.onBlockEntityDelimiter = function (node, entity, parent) {
|
|
234
261
|
if (isNodeOfType(node, 'ELEMENT_NODE') && isEntityDelimiter(node) && node.firstChild) {
|
|
235
262
|
var indexedDelimiter = node.firstChild;
|