roosterjs-content-model-core 0.23.0 → 0.24.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/addUndoSnapshot.js +4 -3
- package/lib/coreApi/addUndoSnapshot.js.map +1 -1
- package/lib/coreApi/attachDomEvent.js.map +1 -1
- package/lib/coreApi/createEditorContext.js +2 -0
- package/lib/coreApi/createEditorContext.js.map +1 -1
- package/lib/coreApi/formatContentModel.js +2 -4
- package/lib/coreApi/formatContentModel.js.map +1 -1
- package/lib/coreApi/getVisibleViewport.js.map +1 -1
- package/lib/coreApi/paste.js.map +1 -1
- package/lib/coreApi/restoreUndoSnapshot.js +2 -2
- package/lib/coreApi/restoreUndoSnapshot.js.map +1 -1
- package/lib/coreApi/setDOMSelection.js +2 -3
- package/lib/coreApi/setDOMSelection.js.map +1 -1
- package/lib/coreApi/switchShadowEdit.js +2 -4
- package/lib/coreApi/switchShadowEdit.js.map +1 -1
- package/lib/coreApi/triggerEvent.js +4 -4
- package/lib/coreApi/triggerEvent.js.map +1 -1
- package/lib/corePlugin/ContentModelCachePlugin.d.ts +1 -2
- package/lib/corePlugin/ContentModelCachePlugin.js +5 -5
- package/lib/corePlugin/ContentModelCachePlugin.js.map +1 -1
- package/lib/corePlugin/ContentModelCopyPastePlugin.d.ts +1 -2
- package/lib/corePlugin/ContentModelCopyPastePlugin.js +2 -2
- package/lib/corePlugin/ContentModelCopyPastePlugin.js.map +1 -1
- package/lib/corePlugin/ContentModelFormatPlugin.d.ts +1 -2
- package/lib/corePlugin/ContentModelFormatPlugin.js +5 -5
- package/lib/corePlugin/ContentModelFormatPlugin.js.map +1 -1
- package/lib/corePlugin/DOMEventPlugin.d.ts +1 -2
- package/lib/corePlugin/DOMEventPlugin.js +10 -10
- package/lib/corePlugin/DOMEventPlugin.js.map +1 -1
- package/lib/corePlugin/EntityPlugin.d.ts +1 -2
- package/lib/corePlugin/EntityPlugin.js +9 -21
- package/lib/corePlugin/EntityPlugin.js.map +1 -1
- package/lib/corePlugin/LifecyclePlugin.d.ts +1 -2
- package/lib/corePlugin/LifecyclePlugin.js +6 -8
- package/lib/corePlugin/LifecyclePlugin.js.map +1 -1
- package/lib/corePlugin/SelectionPlugin.d.ts +1 -2
- package/lib/corePlugin/SelectionPlugin.js +3 -3
- package/lib/corePlugin/SelectionPlugin.js.map +1 -1
- package/lib/corePlugin/UndoPlugin.d.ts +1 -2
- package/lib/corePlugin/UndoPlugin.js +8 -8
- package/lib/corePlugin/UndoPlugin.js.map +1 -1
- package/lib/editor/DarkColorHandlerImpl.d.ts +2 -53
- package/lib/editor/DarkColorHandlerImpl.js +27 -170
- package/lib/editor/DarkColorHandlerImpl.js.map +1 -1
- package/lib/editor/SnapshotsManagerImpl.d.ts +1 -0
- package/lib/editor/SnapshotsManagerImpl.js +10 -4
- package/lib/editor/SnapshotsManagerImpl.js.map +1 -1
- package/lib/editor/StandaloneEditor.d.ts +19 -8
- package/lib/editor/StandaloneEditor.js +37 -11
- package/lib/editor/StandaloneEditor.js.map +1 -1
- package/lib/editor/createStandaloneEditorCore.js +1 -1
- package/lib/editor/createStandaloneEditorCore.js.map +1 -1
- package/lib/index.d.ts +0 -1
- package/lib/index.js +1 -3
- package/lib/index.js.map +1 -1
- package/{lib-mjs/override/containerWidthFormatParser.d.ts → lib/override/containerSizeFormatParser.d.ts} +1 -1
- package/lib/override/{containerWidthFormatParser.js → containerSizeFormatParser.js} +5 -4
- package/lib/override/containerSizeFormatParser.js.map +1 -0
- package/lib/publicApi/color/transformColor.d.ts +2 -2
- package/lib/publicApi/color/transformColor.js +5 -1
- package/lib/publicApi/color/transformColor.js.map +1 -1
- package/lib/publicApi/model/createModelFromHtml.d.ts +1 -2
- package/lib/publicApi/model/createModelFromHtml.js.map +1 -1
- package/lib/publicApi/table/setTableCellBackgroundColor.d.ts +0 -6
- package/lib/publicApi/table/setTableCellBackgroundColor.js +3 -34
- package/lib/publicApi/table/setTableCellBackgroundColor.js.map +1 -1
- package/lib/utils/paste/generatePasteOptionFromPlugins.d.ts +2 -2
- package/lib/utils/paste/generatePasteOptionFromPlugins.js +2 -24
- package/lib/utils/paste/generatePasteOptionFromPlugins.js.map +1 -1
- package/lib/utils/paste/mergePasteContent.d.ts +2 -2
- package/lib/utils/paste/mergePasteContent.js +3 -3
- package/lib/utils/paste/mergePasteContent.js.map +1 -1
- package/lib/utils/restoreSnapshotColors.js +2 -5
- package/lib/utils/restoreSnapshotColors.js.map +1 -1
- package/lib-amd/coreApi/addUndoSnapshot.js +4 -3
- package/lib-amd/coreApi/addUndoSnapshot.js.map +1 -1
- package/lib-amd/coreApi/attachDomEvent.js.map +1 -1
- package/lib-amd/coreApi/createEditorContext.js +2 -0
- package/lib-amd/coreApi/createEditorContext.js.map +1 -1
- package/lib-amd/coreApi/formatContentModel.js +2 -4
- package/lib-amd/coreApi/formatContentModel.js.map +1 -1
- package/lib-amd/coreApi/getVisibleViewport.js.map +1 -1
- package/lib-amd/coreApi/paste.js.map +1 -1
- package/lib-amd/coreApi/restoreUndoSnapshot.js +2 -2
- package/lib-amd/coreApi/restoreUndoSnapshot.js.map +1 -1
- package/lib-amd/coreApi/setDOMSelection.js +2 -3
- package/lib-amd/coreApi/setDOMSelection.js.map +1 -1
- package/lib-amd/coreApi/switchShadowEdit.js +2 -4
- package/lib-amd/coreApi/switchShadowEdit.js.map +1 -1
- package/lib-amd/coreApi/triggerEvent.js +4 -4
- package/lib-amd/coreApi/triggerEvent.js.map +1 -1
- package/lib-amd/corePlugin/ContentModelCachePlugin.d.ts +1 -2
- package/lib-amd/corePlugin/ContentModelCachePlugin.js +5 -5
- package/lib-amd/corePlugin/ContentModelCachePlugin.js.map +1 -1
- package/lib-amd/corePlugin/ContentModelCopyPastePlugin.d.ts +1 -2
- package/lib-amd/corePlugin/ContentModelCopyPastePlugin.js +2 -2
- package/lib-amd/corePlugin/ContentModelCopyPastePlugin.js.map +1 -1
- package/lib-amd/corePlugin/ContentModelFormatPlugin.d.ts +1 -2
- package/lib-amd/corePlugin/ContentModelFormatPlugin.js +5 -5
- package/lib-amd/corePlugin/ContentModelFormatPlugin.js.map +1 -1
- package/lib-amd/corePlugin/DOMEventPlugin.d.ts +1 -2
- package/lib-amd/corePlugin/DOMEventPlugin.js +10 -10
- package/lib-amd/corePlugin/DOMEventPlugin.js.map +1 -1
- package/lib-amd/corePlugin/EntityPlugin.d.ts +1 -2
- package/lib-amd/corePlugin/EntityPlugin.js +9 -21
- package/lib-amd/corePlugin/EntityPlugin.js.map +1 -1
- package/lib-amd/corePlugin/LifecyclePlugin.d.ts +1 -2
- package/lib-amd/corePlugin/LifecyclePlugin.js +6 -8
- package/lib-amd/corePlugin/LifecyclePlugin.js.map +1 -1
- package/lib-amd/corePlugin/SelectionPlugin.d.ts +1 -2
- package/lib-amd/corePlugin/SelectionPlugin.js +3 -3
- package/lib-amd/corePlugin/SelectionPlugin.js.map +1 -1
- package/lib-amd/corePlugin/UndoPlugin.d.ts +1 -2
- package/lib-amd/corePlugin/UndoPlugin.js +8 -8
- package/lib-amd/corePlugin/UndoPlugin.js.map +1 -1
- package/lib-amd/editor/DarkColorHandlerImpl.d.ts +2 -53
- package/lib-amd/editor/DarkColorHandlerImpl.js +28 -170
- package/lib-amd/editor/DarkColorHandlerImpl.js.map +1 -1
- package/lib-amd/editor/SnapshotsManagerImpl.d.ts +1 -0
- package/lib-amd/editor/SnapshotsManagerImpl.js +10 -4
- package/lib-amd/editor/SnapshotsManagerImpl.js.map +1 -1
- package/lib-amd/editor/StandaloneEditor.d.ts +19 -8
- package/lib-amd/editor/StandaloneEditor.js +37 -11
- package/lib-amd/editor/StandaloneEditor.js.map +1 -1
- package/lib-amd/editor/createStandaloneEditorCore.js +1 -1
- package/lib-amd/editor/createStandaloneEditorCore.js.map +1 -1
- package/lib-amd/index.d.ts +0 -1
- package/lib-amd/index.js +2 -3
- package/lib-amd/index.js.map +1 -1
- package/lib-amd/override/{containerWidthFormatParser.d.ts → containerSizeFormatParser.d.ts} +1 -1
- package/lib-amd/override/{containerWidthFormatParser.js → containerSizeFormatParser.js} +5 -4
- package/lib-amd/override/containerSizeFormatParser.js.map +1 -0
- package/lib-amd/publicApi/color/transformColor.d.ts +2 -2
- package/lib-amd/publicApi/color/transformColor.js +5 -2
- package/lib-amd/publicApi/color/transformColor.js.map +1 -1
- package/lib-amd/publicApi/model/createModelFromHtml.d.ts +1 -2
- package/lib-amd/publicApi/model/createModelFromHtml.js.map +1 -1
- package/lib-amd/publicApi/table/setTableCellBackgroundColor.d.ts +0 -6
- package/lib-amd/publicApi/table/setTableCellBackgroundColor.js +3 -35
- package/lib-amd/publicApi/table/setTableCellBackgroundColor.js.map +1 -1
- package/lib-amd/utils/paste/generatePasteOptionFromPlugins.d.ts +2 -2
- package/lib-amd/utils/paste/generatePasteOptionFromPlugins.js +2 -24
- package/lib-amd/utils/paste/generatePasteOptionFromPlugins.js.map +1 -1
- package/lib-amd/utils/paste/mergePasteContent.d.ts +2 -2
- package/lib-amd/utils/paste/mergePasteContent.js +3 -3
- package/lib-amd/utils/paste/mergePasteContent.js.map +1 -1
- package/lib-amd/utils/restoreSnapshotColors.js +2 -5
- package/lib-amd/utils/restoreSnapshotColors.js.map +1 -1
- package/lib-mjs/coreApi/addUndoSnapshot.js +4 -3
- package/lib-mjs/coreApi/addUndoSnapshot.js.map +1 -1
- package/lib-mjs/coreApi/attachDomEvent.js.map +1 -1
- package/lib-mjs/coreApi/createEditorContext.js +2 -0
- package/lib-mjs/coreApi/createEditorContext.js.map +1 -1
- package/lib-mjs/coreApi/formatContentModel.js +2 -4
- package/lib-mjs/coreApi/formatContentModel.js.map +1 -1
- package/lib-mjs/coreApi/getVisibleViewport.js.map +1 -1
- package/lib-mjs/coreApi/paste.js.map +1 -1
- package/lib-mjs/coreApi/restoreUndoSnapshot.js +2 -2
- package/lib-mjs/coreApi/restoreUndoSnapshot.js.map +1 -1
- package/lib-mjs/coreApi/setDOMSelection.js +2 -3
- package/lib-mjs/coreApi/setDOMSelection.js.map +1 -1
- package/lib-mjs/coreApi/switchShadowEdit.js +2 -4
- package/lib-mjs/coreApi/switchShadowEdit.js.map +1 -1
- package/lib-mjs/coreApi/triggerEvent.js +4 -4
- package/lib-mjs/coreApi/triggerEvent.js.map +1 -1
- package/lib-mjs/corePlugin/ContentModelCachePlugin.d.ts +1 -2
- package/lib-mjs/corePlugin/ContentModelCachePlugin.js +5 -5
- package/lib-mjs/corePlugin/ContentModelCachePlugin.js.map +1 -1
- package/lib-mjs/corePlugin/ContentModelCopyPastePlugin.d.ts +1 -2
- package/lib-mjs/corePlugin/ContentModelCopyPastePlugin.js +2 -2
- package/lib-mjs/corePlugin/ContentModelCopyPastePlugin.js.map +1 -1
- package/lib-mjs/corePlugin/ContentModelFormatPlugin.d.ts +1 -2
- package/lib-mjs/corePlugin/ContentModelFormatPlugin.js +5 -5
- package/lib-mjs/corePlugin/ContentModelFormatPlugin.js.map +1 -1
- package/lib-mjs/corePlugin/DOMEventPlugin.d.ts +1 -2
- package/lib-mjs/corePlugin/DOMEventPlugin.js +10 -10
- package/lib-mjs/corePlugin/DOMEventPlugin.js.map +1 -1
- package/lib-mjs/corePlugin/EntityPlugin.d.ts +1 -2
- package/lib-mjs/corePlugin/EntityPlugin.js +9 -21
- package/lib-mjs/corePlugin/EntityPlugin.js.map +1 -1
- package/lib-mjs/corePlugin/LifecyclePlugin.d.ts +1 -2
- package/lib-mjs/corePlugin/LifecyclePlugin.js +6 -8
- package/lib-mjs/corePlugin/LifecyclePlugin.js.map +1 -1
- package/lib-mjs/corePlugin/SelectionPlugin.d.ts +1 -2
- package/lib-mjs/corePlugin/SelectionPlugin.js +3 -3
- package/lib-mjs/corePlugin/SelectionPlugin.js.map +1 -1
- package/lib-mjs/corePlugin/UndoPlugin.d.ts +1 -2
- package/lib-mjs/corePlugin/UndoPlugin.js +8 -8
- package/lib-mjs/corePlugin/UndoPlugin.js.map +1 -1
- package/lib-mjs/editor/DarkColorHandlerImpl.d.ts +2 -53
- package/lib-mjs/editor/DarkColorHandlerImpl.js +26 -169
- package/lib-mjs/editor/DarkColorHandlerImpl.js.map +1 -1
- package/lib-mjs/editor/SnapshotsManagerImpl.d.ts +1 -0
- package/lib-mjs/editor/SnapshotsManagerImpl.js +10 -4
- package/lib-mjs/editor/SnapshotsManagerImpl.js.map +1 -1
- package/lib-mjs/editor/StandaloneEditor.d.ts +19 -8
- package/lib-mjs/editor/StandaloneEditor.js +37 -11
- package/lib-mjs/editor/StandaloneEditor.js.map +1 -1
- package/lib-mjs/editor/createStandaloneEditorCore.js +1 -1
- package/lib-mjs/editor/createStandaloneEditorCore.js.map +1 -1
- package/lib-mjs/index.d.ts +0 -1
- package/lib-mjs/index.js +0 -1
- package/lib-mjs/index.js.map +1 -1
- package/{lib/override/containerWidthFormatParser.d.ts → lib-mjs/override/containerSizeFormatParser.d.ts} +1 -1
- package/lib-mjs/override/{containerWidthFormatParser.js → containerSizeFormatParser.js} +3 -2
- package/lib-mjs/override/containerSizeFormatParser.js.map +1 -0
- package/lib-mjs/publicApi/color/transformColor.d.ts +2 -2
- package/lib-mjs/publicApi/color/transformColor.js +5 -1
- package/lib-mjs/publicApi/color/transformColor.js.map +1 -1
- package/lib-mjs/publicApi/model/createModelFromHtml.d.ts +1 -2
- package/lib-mjs/publicApi/model/createModelFromHtml.js.map +1 -1
- package/lib-mjs/publicApi/table/setTableCellBackgroundColor.d.ts +0 -6
- package/lib-mjs/publicApi/table/setTableCellBackgroundColor.js +1 -31
- package/lib-mjs/publicApi/table/setTableCellBackgroundColor.js.map +1 -1
- package/lib-mjs/utils/paste/generatePasteOptionFromPlugins.d.ts +2 -2
- package/lib-mjs/utils/paste/generatePasteOptionFromPlugins.js +2 -24
- package/lib-mjs/utils/paste/generatePasteOptionFromPlugins.js.map +1 -1
- package/lib-mjs/utils/paste/mergePasteContent.d.ts +2 -2
- package/lib-mjs/utils/paste/mergePasteContent.js +3 -3
- package/lib-mjs/utils/paste/mergePasteContent.js.map +1 -1
- package/lib-mjs/utils/restoreSnapshotColors.js +2 -5
- package/lib-mjs/utils/restoreSnapshotColors.js.map +1 -1
- package/package.json +3 -4
- package/lib/override/containerWidthFormatParser.js.map +0 -1
- package/lib-amd/override/containerWidthFormatParser.js.map +0 -1
- package/lib-mjs/override/containerWidthFormatParser.js.map +0 -1
|
@@ -12,12 +12,12 @@ var createSnapshotSelection_1 = require("../utils/createSnapshotSelection");
|
|
|
12
12
|
* when undo/redo to this snapshot
|
|
13
13
|
*/
|
|
14
14
|
var addUndoSnapshot = function (core, canUndoByBackspace, entityStates) {
|
|
15
|
-
var lifecycle = core.lifecycle, api = core.api, contentDiv = core.contentDiv,
|
|
15
|
+
var lifecycle = core.lifecycle, api = core.api, contentDiv = core.contentDiv, undo = core.undo;
|
|
16
|
+
var snapshot = null;
|
|
16
17
|
if (!lifecycle.shadowEditFragment) {
|
|
17
18
|
var selection = api.getDOMSelection(core);
|
|
18
|
-
|
|
19
|
+
snapshot = {
|
|
19
20
|
html: contentDiv.innerHTML,
|
|
20
|
-
knownColors: darkColorHandler.getKnownColorsCopy(),
|
|
21
21
|
entityStates: entityStates,
|
|
22
22
|
isDarkMode: !!lifecycle.isDarkMode,
|
|
23
23
|
selection: (0, createSnapshotSelection_1.createSnapshotSelection)(contentDiv, selection),
|
|
@@ -25,6 +25,7 @@ var addUndoSnapshot = function (core, canUndoByBackspace, entityStates) {
|
|
|
25
25
|
undo.snapshotsManager.addSnapshot(snapshot, !!canUndoByBackspace);
|
|
26
26
|
undo.snapshotsManager.hasNewContent = false;
|
|
27
27
|
}
|
|
28
|
+
return snapshot;
|
|
28
29
|
};
|
|
29
30
|
exports.addUndoSnapshot = addUndoSnapshot;
|
|
30
31
|
//# sourceMappingURL=addUndoSnapshot.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addUndoSnapshot.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-core/lib/coreApi/addUndoSnapshot.ts"],"names":[],"mappings":";;;AAAA,4EAA2E;AAG3E;;;;;;;;GAQG;AACI,IAAM,eAAe,GAAoB,UAAC,IAAI,EAAE,kBAAkB,EAAE,YAAY;IAC3E,IAAA,SAAS,
|
|
1
|
+
{"version":3,"file":"addUndoSnapshot.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-core/lib/coreApi/addUndoSnapshot.ts"],"names":[],"mappings":";;;AAAA,4EAA2E;AAG3E;;;;;;;;GAQG;AACI,IAAM,eAAe,GAAoB,UAAC,IAAI,EAAE,kBAAkB,EAAE,YAAY;IAC3E,IAAA,SAAS,GAA4B,IAAI,UAAhC,EAAE,GAAG,GAAuB,IAAI,IAA3B,EAAE,UAAU,GAAW,IAAI,WAAf,EAAE,IAAI,GAAK,IAAI,KAAT,CAAU;IAClD,IAAI,QAAQ,GAAoB,IAAI,CAAC;IAErC,IAAI,CAAC,SAAS,CAAC,kBAAkB,EAAE;QAC/B,IAAM,SAAS,GAAG,GAAG,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;QAE5C,QAAQ,GAAG;YACP,IAAI,EAAE,UAAU,CAAC,SAAS;YAC1B,YAAY,cAAA;YACZ,UAAU,EAAE,CAAC,CAAC,SAAS,CAAC,UAAU;YAClC,SAAS,EAAE,IAAA,iDAAuB,EAAC,UAAU,EAAE,SAAS,CAAC;SAC5D,CAAC;QAEF,IAAI,CAAC,gBAAgB,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC,CAAC,kBAAkB,CAAC,CAAC;QAClE,IAAI,CAAC,gBAAgB,CAAC,aAAa,GAAG,KAAK,CAAC;KAC/C;IAED,OAAO,QAAQ,CAAC;AACpB,CAAC,CAAC;AAnBW,QAAA,eAAe,mBAmB1B","sourcesContent":["import { createSnapshotSelection } from '../utils/createSnapshotSelection';\nimport type { AddUndoSnapshot, Snapshot } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n * Add an undo snapshot to current undo snapshot stack\n * @param core The StandaloneEditorCore object\n * @param canUndoByBackspace True if this action can be undone when user press Backspace key (aka Auto Complete).\n * @param entityStates @optional Entity states related to this snapshot.\n * Each entity state will cause an EntityOperation event with operation = EntityOperation.UpdateEntityState\n * when undo/redo to this snapshot\n */\nexport const addUndoSnapshot: AddUndoSnapshot = (core, canUndoByBackspace, entityStates) => {\n const { lifecycle, api, contentDiv, undo } = core;\n let snapshot: Snapshot | null = null;\n\n if (!lifecycle.shadowEditFragment) {\n const selection = api.getDOMSelection(core);\n\n snapshot = {\n html: contentDiv.innerHTML,\n entityStates,\n isDarkMode: !!lifecycle.isDarkMode,\n selection: createSnapshotSelection(contentDiv, selection),\n };\n\n undo.snapshotsManager.addSnapshot(snapshot, !!canUndoByBackspace);\n undo.snapshotsManager.hasNewContent = false;\n }\n\n return snapshot;\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attachDomEvent.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-core/lib/coreApi/attachDomEvent.ts"],"names":[],"mappings":";;;AAAA,2EAA4D;
|
|
1
|
+
{"version":3,"file":"attachDomEvent.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-core/lib/coreApi/attachDomEvent.ts"],"names":[],"mappings":";;;AAAA,2EAA4D;AAG5D;;;;;;;GAOG;AACI,IAAM,cAAc,GAAmB,UAAC,IAAI,EAAE,QAAQ;IACzD,IAAM,SAAS,GAAG,IAAA,2CAAa,EAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,UAAA,GAAG;QAC7C,IAAA,KAAsC,QAAQ,CAAC,GAAG,CAAC,EAAjD,eAAe,qBAAA,EAAE,cAAc,oBAAkB,CAAC;QAC1D,IAAM,SAAS,GAAG,GAAgC,CAAC;QACnD,IAAM,OAAO,GAAG,UAAC,KAA4C;YACzD,IAAI,cAAc,EAAE;gBAChB,cAAc,CAAC,KAAK,CAAC,CAAC;aACzB;YAED,IAAI,eAAe,IAAI,IAAI,EAAE;gBACzB,IAAI,CAAC,GAAG,CAAC,YAAY,CACjB,IAAI,EACS;oBACT,SAAS,EAAE,eAAe;oBAC1B,QAAQ,EAAE,KAAK;iBAClB,EACD,KAAK,CAAC,aAAa,CACtB,CAAC;aACL;QACL,CAAC,CAAC;QAEF,IAAI,CAAC,UAAU,CAAC,gBAAgB,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QAErD,OAAO;YACH,IAAI,CAAC,UAAU,CAAC,mBAAmB,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QAC5D,CAAC,CAAC;IACN,CAAC,CAAC,CAAC;IAEH,OAAO,cAAM,OAAA,SAAS,CAAC,OAAO,CAAC,UAAA,SAAS,IAAI,OAAA,SAAS,EAAE,EAAX,CAAW,CAAC,EAA3C,CAA2C,CAAC;AAC7D,CAAC,CAAC;AA7BW,QAAA,cAAc,kBA6BzB","sourcesContent":["import { getObjectKeys } from 'roosterjs-content-model-dom';\nimport type { AttachDomEvent, PluginEvent } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n * Attach a DOM event to the editor content DIV\n * @param core The StandaloneEditorCore object\n * @param eventName The DOM event name\n * @param pluginEventType Optional event type. When specified, editor will trigger a plugin event with this name when the DOM event is triggered\n * @param beforeDispatch Optional callback function to be invoked when the DOM event is triggered before trigger plugin event\n */\nexport const attachDomEvent: AttachDomEvent = (core, eventMap) => {\n const disposers = getObjectKeys(eventMap || {}).map(key => {\n const { pluginEventType, beforeDispatch } = eventMap[key];\n const eventName = key as keyof HTMLElementEventMap;\n const onEvent = (event: HTMLElementEventMap[typeof eventName]) => {\n if (beforeDispatch) {\n beforeDispatch(event);\n }\n\n if (pluginEventType != null) {\n core.api.triggerEvent(\n core,\n <PluginEvent>{\n eventType: pluginEventType,\n rawEvent: event,\n },\n false /*broadcast*/\n );\n }\n };\n\n core.contentDiv.addEventListener(eventName, onEvent);\n\n return () => {\n core.contentDiv.removeEventListener(eventName, onEvent);\n };\n });\n\n return () => disposers.forEach(disposers => disposers());\n};\n"]}
|
|
@@ -6,10 +6,12 @@ exports.createEditorContext = void 0;
|
|
|
6
6
|
* Create a EditorContext object used by ContentModel API
|
|
7
7
|
*/
|
|
8
8
|
var createEditorContext = function (core) {
|
|
9
|
+
var _a;
|
|
9
10
|
var lifecycle = core.lifecycle, format = core.format, darkColorHandler = core.darkColorHandler, contentDiv = core.contentDiv, cache = core.cache;
|
|
10
11
|
var context = {
|
|
11
12
|
isDarkMode: lifecycle.isDarkMode,
|
|
12
13
|
defaultFormat: format.defaultFormat,
|
|
14
|
+
pendingFormat: (_a = format.pendingFormat) !== null && _a !== void 0 ? _a : undefined,
|
|
13
15
|
darkColorHandler: darkColorHandler,
|
|
14
16
|
addDelimiterForEntity: true,
|
|
15
17
|
allowCacheElement: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createEditorContext.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-core/lib/coreApi/createEditorContext.ts"],"names":[],"mappings":";;;AAEA;;;GAGG;AACI,IAAM,mBAAmB,GAAwB,UAAA,IAAI
|
|
1
|
+
{"version":3,"file":"createEditorContext.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-core/lib/coreApi/createEditorContext.ts"],"names":[],"mappings":";;;AAEA;;;GAGG;AACI,IAAM,mBAAmB,GAAwB,UAAA,IAAI;;IAChD,IAAA,SAAS,GAAkD,IAAI,UAAtD,EAAE,MAAM,GAA0C,IAAI,OAA9C,EAAE,gBAAgB,GAAwB,IAAI,iBAA5B,EAAE,UAAU,GAAY,IAAI,WAAhB,EAAE,KAAK,GAAK,IAAI,MAAT,CAAU;IAExE,IAAM,OAAO,GAAkB;QAC3B,UAAU,EAAE,SAAS,CAAC,UAAU;QAChC,aAAa,EAAE,MAAM,CAAC,aAAa;QACnC,aAAa,EAAE,MAAA,MAAM,CAAC,aAAa,mCAAI,SAAS;QAChD,gBAAgB,EAAE,gBAAgB;QAClC,qBAAqB,EAAE,IAAI;QAC3B,iBAAiB,EAAE,IAAI;QACvB,UAAU,EAAE,KAAK,CAAC,UAAU;KAC/B,CAAC;IAEF,YAAY,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IAClC,cAAc,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IAEpC,OAAO,OAAO,CAAC;AACnB,CAAC,CAAC;AAjBW,QAAA,mBAAmB,uBAiB9B;AAEF,SAAS,cAAc,CAAC,OAAoB,EAAE,OAAsB;;IAChE,IAAM,aAAa,GAAG,CAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,qBAAqB,EAAE,0CAAE,KAAK,KAAI,CAAC,CAAC;IACnE,IAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IAExC,IAAI,WAAW,GAAG,CAAC,IAAI,aAAa,GAAG,CAAC,EAAE;QACtC,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,aAAa,GAAG,WAAW,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;KAC7E;AACL,CAAC;AAED,SAAS,YAAY,CAAC,OAAoB,EAAE,OAAsB;;IAC9D,IAAM,KAAK,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,aAAa,CAAC,WAAW,0CAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAE5E,IAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SAAS,KAAI,KAAK,EAAE;QAC3B,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;KAC5B;AACL,CAAC","sourcesContent":["import type { EditorContext, CreateEditorContext } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n * Create a EditorContext object used by ContentModel API\n */\nexport const createEditorContext: CreateEditorContext = core => {\n const { lifecycle, format, darkColorHandler, contentDiv, cache } = core;\n\n const context: EditorContext = {\n isDarkMode: lifecycle.isDarkMode,\n defaultFormat: format.defaultFormat,\n pendingFormat: format.pendingFormat ?? undefined,\n darkColorHandler: darkColorHandler,\n addDelimiterForEntity: true,\n allowCacheElement: true,\n domIndexer: cache.domIndexer,\n };\n\n checkRootRtl(contentDiv, context);\n checkZoomScale(contentDiv, context);\n\n return context;\n};\n\nfunction checkZoomScale(element: HTMLElement, context: EditorContext) {\n const originalWidth = element?.getBoundingClientRect()?.width || 0;\n const visualWidth = element.offsetWidth;\n\n if (visualWidth > 0 && originalWidth > 0) {\n context.zoomScale = Math.round((originalWidth / visualWidth) * 100) / 100;\n }\n}\n\nfunction checkRootRtl(element: HTMLElement, context: EditorContext) {\n const style = element?.ownerDocument.defaultView?.getComputedStyle(element);\n\n if (style?.direction == 'rtl') {\n context.isRootRtl = true;\n }\n}\n"]}
|
|
@@ -52,14 +52,12 @@ var formatContentModel = function (core, formatter, options) {
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
var eventData = {
|
|
55
|
-
eventType:
|
|
55
|
+
eventType: 'contentChanged',
|
|
56
56
|
contentModel: clearModelCache ? undefined : model,
|
|
57
57
|
selection: clearModelCache ? undefined : selection,
|
|
58
58
|
source: changeSource || ChangeSource_1.ChangeSource.Format,
|
|
59
59
|
data: getChangeData === null || getChangeData === void 0 ? void 0 : getChangeData(),
|
|
60
|
-
|
|
61
|
-
formatApiName: apiName,
|
|
62
|
-
},
|
|
60
|
+
formatApiName: apiName,
|
|
63
61
|
changedEntities: getChangedEntities(context, rawEvent),
|
|
64
62
|
};
|
|
65
63
|
core.api.triggerEvent(core, eventData, true /*broadcast*/);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatContentModel.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-core/lib/coreApi/formatContentModel.ts"],"names":[],"mappings":";;;;AAAA,0DAAyD;
|
|
1
|
+
{"version":3,"file":"formatContentModel.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-core/lib/coreApi/formatContentModel.ts"],"names":[],"mappings":";;;;AAAA,0DAAyD;AAUzD;;;;;;;;;GASG;AACI,IAAM,kBAAkB,GAAuB,UAAC,I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AEnC,IAAI,aAAa,IAAI,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,IAAI,KAAI,OAAO,IAAI,SAAS,CAAC,KAAK,CAAC,SAAS,EAAE;QAC1E,IAAI,CAAC,MAAM,CAAC,aAAa,GAAG;YACxB,MAAM,4BAAO,aAAa,CAAE;YAC5B,YAAY,EAAE,SAAS,CAAC,KAAK,CAAC,cAAc;YAC5C,SAAS,EAAE,SAAS,CAAC,KAAK,CAAC,WAAW;SACzC,CAAC;KACL;AACL,CAAC;AAED,SAAS,kBAAkB,CACvB,OAAsC,EACtC,QAAgB;IAEhB,OAAO,OAAO,CAAC,WAAW;SACrB,GAAG,CACA,UAAC,MAAM,IAAoB,OAAA,CAAC;QACxB,MAAM,QAAA;QACN,SAAS,EAAE,WAAW;QACtB,QAAQ,UAAA;KACX,CAAC,EAJyB,CAIzB,CACL;SACA,MAAM,CACH,OAAO,CAAC,eAAe,CAAC,GAAG,CAAC,UAAA,KAAK,IAAI,OAAA,CAAC;QAClC,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,QAAQ,UAAA;KACX,CAAC,EAJmC,CAInC,CAAC,CACN,CAAC;AACV,CAAC","sourcesContent":["import { ChangeSource } from '../constants/ChangeSource';\nimport type {\n ChangedEntity,\n ContentChangedEvent,\n DOMSelection,\n FormatContentModel,\n FormatWithContentModelContext,\n StandaloneEditorCore,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n * The general API to do format change with Content Model\n * It will grab a Content Model for current editor content, and invoke a callback function\n * to do format change. Then according to the return value, write back the modified content model into editor.\n * If there is cached model, it will be used and updated.\n * @param core The StandaloneEditorCore object\n * @param formatter Formatter function, see ContentModelFormatter\n * @param options More options, see FormatWithContentModelOptions\n */\nexport const formatContentModel: FormatContentModel = (core, formatter, options) => {\n const { apiName, onNodeCreated, getChangeData, changeSource, rawEvent, selectionOverride } =\n options || {};\n\n const model = core.api.createContentModel(core, undefined /*option*/, selectionOverride);\n const context: FormatWithContentModelContext = {\n newEntities: [],\n deletedEntities: [],\n rawEvent,\n newImages: [],\n };\n\n const hasFocus = core.api.hasFocus(core);\n\n const changed = formatter(model, context);\n const { skipUndoSnapshot, clearModelCache, entityStates, canUndoByBackspace } = context;\n\n if (changed) {\n const isNested = core.undo.isNested;\n const shouldAddSnapshot = !skipUndoSnapshot && !isNested;\n let selection: DOMSelection | undefined;\n\n if (shouldAddSnapshot) {\n core.undo.isNested = true;\n\n if (core.undo.snapshotsManager.hasNewContent || entityStates) {\n core.api.addUndoSnapshot(core, !!canUndoByBackspace);\n }\n }\n\n try {\n handleImages(core, context);\n\n selection =\n core.api.setContentModel(\n core,\n model,\n hasFocus ? undefined : { ignoreSelection: true }, // If editor did not have focus before format, do not set focus after format\n onNodeCreated\n ) ?? undefined;\n\n handlePendingFormat(core, context, selection);\n\n if (shouldAddSnapshot) {\n core.api.addUndoSnapshot(core, !!canUndoByBackspace, entityStates);\n }\n } finally {\n if (!isNested) {\n core.undo.isNested = false;\n }\n }\n\n const eventData: ContentChangedEvent = {\n eventType: 'contentChanged',\n contentModel: clearModelCache ? undefined : model,\n selection: clearModelCache ? undefined : selection,\n source: changeSource || ChangeSource.Format,\n data: getChangeData?.(),\n formatApiName: apiName,\n changedEntities: getChangedEntities(context, rawEvent),\n };\n\n core.api.triggerEvent(core, eventData, true /*broadcast*/);\n\n if (canUndoByBackspace && selection?.type == 'range') {\n core.undo.snapshotsManager.hasNewContent = false;\n core.undo.posContainer = selection.range.startContainer;\n core.undo.posOffset = selection.range.startOffset;\n }\n } else {\n if (clearModelCache) {\n core.cache.cachedModel = undefined;\n core.cache.cachedSelection = undefined;\n }\n\n handlePendingFormat(core, context, core.api.getDOMSelection(core));\n }\n};\n\nfunction handleImages(core: StandaloneEditorCore, context: FormatWithContentModelContext) {\n if (context.newImages.length > 0) {\n const viewport = core.api.getVisibleViewport(core);\n\n if (viewport) {\n const { left, right } = viewport;\n const minMaxImageSize = 10;\n const maxWidth = Math.max(right - left, minMaxImageSize);\n context.newImages.forEach(image => {\n image.format.maxWidth = `${maxWidth}px`;\n });\n }\n }\n}\n\nfunction handlePendingFormat(\n core: StandaloneEditorCore,\n context: FormatWithContentModelContext,\n selection?: DOMSelection | null\n) {\n const pendingFormat =\n context.newPendingFormat == 'preserve'\n ? core.format.pendingFormat?.format\n : context.newPendingFormat;\n\n if (pendingFormat && selection?.type == 'range' && selection.range.collapsed) {\n core.format.pendingFormat = {\n format: { ...pendingFormat },\n posContainer: selection.range.startContainer,\n posOffset: selection.range.startOffset,\n };\n }\n}\n\nfunction getChangedEntities(\n context: FormatWithContentModelContext,\n rawEvent?: Event\n): ChangedEntity[] {\n return context.newEntities\n .map(\n (entity): ChangedEntity => ({\n entity,\n operation: 'newEntity',\n rawEvent,\n })\n )\n .concat(\n context.deletedEntities.map(entry => ({\n entity: entry.entity,\n operation: entry.operation,\n rawEvent,\n }))\n );\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getVisibleViewport.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-core/lib/coreApi/getVisibleViewport.ts"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"getVisibleViewport.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-core/lib/coreApi/getVisibleViewport.ts"],"names":[],"mappings":";;;;AAEA;;;;GAIG;AACI,IAAM,kBAAkB,GAAuB,UAAA,IAAI;IACtD,IAAM,eAAe,GAAG,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC;IAEtD,OAAO,kBAAkB,CACrB,eAAe,IAAI,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,eAAe,EAAE,IAAI,CAAC,UAAU,CAAC,CAC9F,CAAC;AACN,CAAC,CAAC;AANW,QAAA,kBAAkB,sBAM7B;AAEF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG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AAC,EAAE,GAAG,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,EAD3D,IAAI,UAAA,EAAE,KAAK,WAAA,EAAE,GAAG,SAAA,EAAE,MAAM,YACmC,CAAC;IACpE,OAAO,IAAI,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,MAAM,KAAK,CAAC;QACzD,CAAC,CAAC,IAAI;QACN,CAAC,CAAC;YACI,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;YACtB,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC;YACxB,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC;YACpB,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;SAC7B,CAAC;AACZ,CAAC","sourcesContent":["import type { GetVisibleViewport, Rect } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n * Retrieves the rect of the visible viewport of the editor.\n * @param core The StandaloneEditorCore object\n */\nexport const getVisibleViewport: GetVisibleViewport = core => {\n const scrollContainer = core.domEvent.scrollContainer;\n\n return getIntersectedRect(\n scrollContainer == core.contentDiv ? [scrollContainer] : [scrollContainer, core.contentDiv]\n );\n};\n\n/**\n * Get the intersected Rect of elements provided\n *\n * @example\n * The result of the following Elements Rects would be:\n {\n top: Element2.top,\n bottom: Element1.bottom,\n left: Element2.left,\n right: Element2.right\n }\n +-------------------------+\n | Element 1 |\n | +-----------------+ |\n | | Element2 | |\n | | | |\n | | | |\n +-------------------------+\n | |\n +-----------------+\n\n * @param elements Elements to use.\n * @param additionalRects additional rects to use\n * @returns If the Rect is valid return the rect, if not, return null.\n */\nfunction getIntersectedRect(elements: HTMLElement[], additionalRects: Rect[] = []): Rect | null {\n const rects = elements\n .map(element => normalizeRect(element.getBoundingClientRect()))\n .concat(additionalRects)\n .filter((rect: Rect | null): rect is Rect => !!rect);\n\n const result: Rect = {\n top: Math.max(...rects.map(r => r.top)),\n bottom: Math.min(...rects.map(r => r.bottom)),\n left: Math.max(...rects.map(r => r.left)),\n right: Math.min(...rects.map(r => r.right)),\n };\n\n return result.top < result.bottom && result.left < result.right ? result : null;\n}\n\nfunction normalizeRect(clientRect: DOMRect): Rect | null {\n const { left, right, top, bottom } =\n clientRect || <DOMRect>{ left: 0, right: 0, top: 0, bottom: 0 };\n return left === 0 && right === 0 && top === 0 && bottom === 0\n ? null\n : {\n left: Math.round(left),\n right: Math.round(right),\n top: Math.round(top),\n bottom: Math.round(bottom),\n };\n}\n"]}
|
package/lib/coreApi/paste.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paste.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-core/lib/coreApi/paste.ts"],"names":[],"mappings":";;;AAAA,0DAAyD;AACzD,4DAA2D;AAC3D,oEAAmE;AACnE,0EAAyE;AACzE,gGAA+F;AAC/F,sEAAqE;AACrE,oEAAmE;AAUnE,IAAM,WAAW,GAAsB;IACnC,oBAAoB,EAAE,UAAC,IAAI,EAAE,IAAI,IAAK,OAAA,CAAC,IAAI,IAAI,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,EAApC,CAAoC;CAC7E,CAAC;AAEF;;;;;;GAMG;AACI,IAAM,KAAK,GAAU,UACxB,IAA0B,EAC1B,aAA4B,EAC5B,SAA+B;IAA/B,0BAAA,EAAA,oBAA+B;IAE/B,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAErB,IAAI,aAAa,CAAC,gBAAgB,EAAE;QAChC,IAAI,CAAC,GAAG,CAAC,eAAe,CAAC,IAAI,EAAE,IAAA,uBAAU,EAAC,aAAa,CAAC,gBAAgB,EAAE,WAAW,CAAC,CAAC,CAAC;KAC3F;SAAM;QACH,aAAa,CAAC,gBAAgB,GAAG,IAAA,uBAAU,EAAC,IAAI,CAAC,GAAG,CAAC,kBAAkB,CAAC,IA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B,kBAAsC;IAEtC,OAAO,IAAI,CAAC,CAAC,CAAC,IAAI,SAAS,EAAE,CAAC,eAAe,CAAC,kBAAkB,CAAC,IAAI,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAChG,CAAC","sourcesContent":["import { ChangeSource } from '../constants/ChangeSource';\nimport { cloneModel } from '../publicApi/model/cloneModel';\nimport { convertInlineCss } from '../utils/paste/convertInlineCss';\nimport { createPasteFragment } from '../utils/paste/createPasteFragment';\nimport { generatePasteOptionFromPlugins } from '../utils/paste/generatePasteOptionFromPlugins';\nimport { mergePasteContent } from '../utils/paste/mergePasteContent';\nimport { retrieveHtmlInfo } from '../utils/paste/retrieveHtmlInfo';\nimport type { CloneModelOptions } from '../publicApi/model/cloneModel';\nimport type {\n PasteType,\n ClipboardData,\n Paste,\n StandaloneEditorCore,\n} from 'roosterjs-content-model-types';\
|
|
1
|
+
{"version":3,"file":"paste.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-core/lib/coreApi/paste.ts"],"names":[],"mappings":";;;AAAA,0DAAyD;AACzD,4DAA2D;AAC3D,oEAAmE;AACnE,0EAAyE;AACzE,gGAA+F;AAC/F,sEAAqE;AACrE,oEAAmE;AAUnE,IAAM,WAAW,GAAsB;IACnC,oBAAoB,EAAE,UAAC,IAAI,EAAE,IAAI,IAAK,OAAA,CAAC,IAAI,IAAI,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,EAApC,CAAoC;CAC7E,CAAC;AAEF;;;;;;GAMG;AACI,IAAM,KAAK,GAAU,UACxB,IAA0B,EAC1B,aAA4B,EAC5B,SAA+B;IAA/B,0BAAA,EAAA,oBAA+B;IAE/B,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAErB,IAAI,aAAa,CAAC,gBAAgB,EAAE;QAChC,IAAI,CAAC,GAAG,CAAC,eAAe,CAAC,IAAI,EAAE,IAAA,uBAA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a,EAAE,cAAM,OAAA,aAAa,EAAb,CAAa;QAClC,OAAO,EAAE,OAAO;KACnB,CACJ,CAAC;AACN,CAAC,CAAC;AAxDW,QAAA,KAAK,SAwDhB;AAEF,SAAS,iBAAiB,CACtB,IAA+B,EAC/B,kBAAsC;IAEtC,OAAO,IAAI,CAAC,CAAC,CAAC,IAAI,SAAS,EAAE,CAAC,eAAe,CAAC,kBAAkB,CAAC,IAAI,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAChG,CAAC","sourcesContent":["import { ChangeSource } from '../constants/ChangeSource';\nimport { cloneModel } from '../publicApi/model/cloneModel';\nimport { convertInlineCss } from '../utils/paste/convertInlineCss';\nimport { createPasteFragment } from '../utils/paste/createPasteFragment';\nimport { generatePasteOptionFromPlugins } from '../utils/paste/generatePasteOptionFromPlugins';\nimport { mergePasteContent } from '../utils/paste/mergePasteContent';\nimport { retrieveHtmlInfo } from '../utils/paste/retrieveHtmlInfo';\nimport type { CloneModelOptions } from '../publicApi/model/cloneModel';\nimport type {\n PasteType,\n ClipboardData,\n Paste,\n StandaloneEditorCore,\n TrustedHTMLHandler,\n} from 'roosterjs-content-model-types';\n\nconst CloneOption: CloneModelOptions = {\n includeCachedElement: (node, type) => (type == 'cache' ? undefined : node),\n};\n\n/**\n * @internal\n * Paste into editor using a clipboardData object\n * @param core The StandaloneEditorCore object.\n * @param clipboardData Clipboard data retrieved from clipboard\n * @param pasteType Type of content to paste. @default normal\n */\nexport const paste: Paste = (\n core: StandaloneEditorCore,\n clipboardData: ClipboardData,\n pasteType: PasteType = 'normal'\n) => {\n core.api.focus(core);\n\n if (clipboardData.modelBeforePaste) {\n core.api.setContentModel(core, cloneModel(clipboardData.modelBeforePaste, CloneOption));\n } else {\n clipboardData.modelBeforePaste = cloneModel(core.api.createContentModel(core), CloneOption);\n }\n\n core.api.formatContentModel(\n core,\n (model, context) => {\n // 1. Prepare variables\n const doc = createDOMFromHtml(clipboardData.rawHtml, core.trustedHTMLHandler);\n\n // 2. Handle HTML from clipboard\n const htmlFromClipboard = retrieveHtmlInfo(doc, clipboardData);\n\n // 3. Create target fragment\n const sourceFragment = createPasteFragment(\n core.contentDiv.ownerDocument,\n clipboardData,\n pasteType,\n (clipboardData.rawHtml == clipboardData.html\n ? doc\n : createDOMFromHtml(clipboardData.html, core.trustedHTMLHandler)\n )?.body\n );\n\n // 4. Trigger BeforePaste event to allow plugins modify the fragment\n const eventResult = generatePasteOptionFromPlugins(\n core,\n clipboardData,\n sourceFragment,\n htmlFromClipboard,\n pasteType\n );\n\n // 5. Convert global CSS to inline CSS\n convertInlineCss(eventResult.fragment, htmlFromClipboard.globalCssRules);\n\n // 6. Merge pasted content into main Content Model\n mergePasteContent(model, context, eventResult, core.domToModelSettings.customized);\n\n return true;\n },\n {\n changeSource: ChangeSource.Paste,\n getChangeData: () => clipboardData,\n apiName: 'paste',\n }\n );\n};\n\nfunction createDOMFromHtml(\n html: string | null | undefined,\n trustedHTMLHandler: TrustedHTMLHandler\n): Document | null {\n return html ? new DOMParser().parseFromString(trustedHTMLHandler(html), 'text/html') : null;\n}\n"]}
|
|
@@ -13,7 +13,7 @@ var restoreSnapshotSelection_1 = require("../utils/restoreSnapshotSelection");
|
|
|
13
13
|
*/
|
|
14
14
|
var restoreUndoSnapshot = function (core, snapshot) {
|
|
15
15
|
core.api.triggerEvent(core, {
|
|
16
|
-
eventType:
|
|
16
|
+
eventType: 'beforeSetContent',
|
|
17
17
|
newContent: snapshot.html,
|
|
18
18
|
}, true /*broadcast*/);
|
|
19
19
|
try {
|
|
@@ -22,7 +22,7 @@ var restoreUndoSnapshot = function (core, snapshot) {
|
|
|
22
22
|
(0, restoreSnapshotSelection_1.restoreSnapshotSelection)(core, snapshot);
|
|
23
23
|
(0, restoreSnapshotColors_1.restoreSnapshotColors)(core, snapshot);
|
|
24
24
|
var event_1 = {
|
|
25
|
-
eventType:
|
|
25
|
+
eventType: 'contentChanged',
|
|
26
26
|
entityStates: snapshot.entityStates,
|
|
27
27
|
source: ChangeSource_1.ChangeSource.SetContent,
|
|
28
28
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"restoreUndoSnapshot.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-core/lib/coreApi/restoreUndoSnapshot.ts"],"names":[],"mappings":";;;AAAA,0DAAyD;
|
|
1
|
+
{"version":3,"file":"restoreUndoSnapshot.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-core/lib/coreApi/restoreUndoSnapshot.ts"],"names":[],"mappings":";;;AAAA,0DAAyD;AACzD,wEAAuE;AACvE,oEAAmE;AACnE,8EAA6E;AAG7E;;;;;GAKG;AACI,IAAM,mBAAmB,GAAwB,UAAC,IAAI,EAAE,QAAQ;IACnE,IAAI,CAAC,GAAG,CAAC,YAAY,CACjB,IAAI,EACJ;QACI,SAAS,EAAE,kBAAkB;QAC7B,UAAU,EAAE,QAAQ,CAAC,IAAI;KAC5B,EACD,IAAI,CAAC,aAAa,CACrB,CAAC;IAEF,IAAI;QACA,IAAI,CAAC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QAE7B,IAAA,yCAAmB,EAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QACpC,IAAA,mDAAwB,EAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QACzC,IAAA,6CAAqB,EAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QAEtC,IAAM,OAAK,GAAwB;YAC/B,SAAS,EAAE,gBAAgB;YAC3B,YAAY,EAAE,QAAQ,CAAC,YAAY;YACnC,MAAM,EAAE,2BAAY,CAAC,UAAU;SAClC,CAAC;QAEF,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,EAAE,OAAK,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC;KAC3D;YAAS;QACN,IAAI,CAAC,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;KACjC;AACL,CAAC,CAAC;AA3BW,QAAA,mBAAmB,uBA2B9B","sourcesContent":["import { ChangeSource } from '../constants/ChangeSource';\nimport { restoreSnapshotColors } from '../utils/restoreSnapshotColors';\nimport { restoreSnapshotHTML } from '../utils/restoreSnapshotHTML';\nimport { restoreSnapshotSelection } from '../utils/restoreSnapshotSelection';\nimport type { ContentChangedEvent, RestoreUndoSnapshot } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n * Restore an undo snapshot into editor\n * @param core The editor core object\n * @param step Steps to move, can be 0, positive or negative\n */\nexport const restoreUndoSnapshot: RestoreUndoSnapshot = (core, snapshot) => {\n core.api.triggerEvent(\n core,\n {\n eventType: 'beforeSetContent',\n newContent: snapshot.html,\n },\n true /*broadcast*/\n );\n\n try {\n core.undo.isRestoring = true;\n\n restoreSnapshotHTML(core, snapshot);\n restoreSnapshotSelection(core, snapshot);\n restoreSnapshotColors(core, snapshot);\n\n const event: ContentChangedEvent = {\n eventType: 'contentChanged',\n entityStates: snapshot.entityStates,\n source: ChangeSource.SetContent,\n };\n\n core.api.triggerEvent(core, event, false /*broadcast*/);\n } finally {\n core.undo.isRestoring = false;\n }\n};\n"]}
|
|
@@ -62,9 +62,8 @@ var setDOMSelection = function (core, selection, skipSelectionChangedEvent) {
|
|
|
62
62
|
}
|
|
63
63
|
if (!skipSelectionChangedEvent) {
|
|
64
64
|
var eventData = {
|
|
65
|
-
eventType:
|
|
65
|
+
eventType: 'selectionChanged',
|
|
66
66
|
newSelection: selection,
|
|
67
|
-
selectionRangeEx: null,
|
|
68
67
|
};
|
|
69
68
|
core.api.triggerEvent(core, eventData, true /*broadcast*/);
|
|
70
69
|
}
|
|
@@ -145,7 +144,7 @@ function handleTableSelected(rootSelector, selection, cells) {
|
|
|
145
144
|
return selectors;
|
|
146
145
|
}
|
|
147
146
|
function setRangeSelection(doc, element) {
|
|
148
|
-
if (element) {
|
|
147
|
+
if (element && doc.contains(element)) {
|
|
149
148
|
var range = doc.createRange();
|
|
150
149
|
range.selectNode(element);
|
|
151
150
|
range.collapse();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setDOMSelection.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-core/lib/coreApi/setDOMSelection.ts"],"names":[],"mappings":";;;AAAA,+EAA8E;AAC9E,2EAAoE;AACpE,uEAAuE;AAQvE,IAAM,QAAQ,GAAG,OAAO,CAAC;AACzB,IAAM,QAAQ,GAAG,OAAO,CAAC;AACzB,IAAM,cAAc,GAAG,YAAY,CAAC;AACpC,IAAM,8BAA8B,GAAG,SAAS,CAAC;AACjD,IAAM,cAAc,GAAG,kDAAkD,CAAC;AAC1E,IAAM,cAAc,GAAG,4BAA4B,CAAC;AACpD,IAAM,wBAAwB,GAAG,IAAI,CAAC;AAEtC;;GAEG;AACI,IAAM,eAAe,GAAoB,UAAC,IAAI,EAAE,SAAS,EAAE,yBAAyB;;IACvF,iGAAiG;IACjG,gDAAgD;IAChD,IAAM,mBAAmB,GAAG,IAAI,CAAC,SAAS,CAAC,mBAAmB,CAAC;IAE/D,IAAM,GAAG,GAAG,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC;IAC1C,IAAM,KAAK,GAAG,MAAA,IAAI,CAAC,SAAS,CAAC,kBAAkB,0CAAE,KAAK,CAAC;IAEvD,IAAI,CAAC,SAAS,CAAC,mBAAmB,GAAG,IAAI,CAAC;IAE1C,IAAI;QACA,IAAI,cAAc,SAAsB,CAAC;QACzC,IAAM,YAAY,GAAG,GAAG,GAAG,WAAW,CAAC,IAAI,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;QAExE,QAAQ,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,IAAI,EAAE;YACrB,KAAK,OAAO;gBACR,IAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC;gBAE9B,cAAc,GAAG,aAAa,CAC1B,YAAY,EACZ,WAAW,CAAC,KAAK,EAAE,QAAQ,CAAC,EAC5B,IAAI,CAAC,SAAS,CAAC,yBAAyB,CAC3C,CAAC;gBACF,IAA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s-content-model-dom';\nimport { parseTableCells } from '../publicApi/domUtils/tableCellUtils';\nimport { PluginEventType } from 'roosterjs-editor-types';\nimport type {\n ContentModelSelectionChangedEvent,\n SetDOMSelection,\n TableSelection,\n} from 'roosterjs-content-model-types';\n\nconst IMAGE_ID = 'image';\nconst TABLE_ID = 'table';\nconst CONTENT_DIV_ID = 'contentDiv';\nconst DEFAULT_SELECTION_BORDER_COLOR = '#DB626C';\nconst TABLE_CSS_RULE = '{background-color: rgb(198,198,198) !important;}';\nconst CARET_CSS_RULE = '{caret-color: transparent}';\nconst MAX_RULE_SELECTOR_LENGTH = 9000;\n\n/**\n * @internal\n */\nexport const setDOMSelection: SetDOMSelection = (core, selection, skipSelectionChangedEvent) => {\n // We are applying a new selection, so we don't need to apply cached selection in DOMEventPlugin.\n // Set skipReselectOnFocus to skip this behavior\n const skipReselectOnFocus = core.selection.skipReselectOnFocus;\n\n const doc = core.contentDiv.ownerDocument;\n const sheet = core.selection.selectionStyleNode?.sheet;\n\n core.selection.skipReselectOnFocus = true;\n\n try {\n let selectionRules: string[] | undefined;\n const rootSelector = '#' + addUniqueId(core.contentDiv, CONTENT_DIV_ID);\n\n switch (selection?.type) {\n case 'image':\n const image = selection.image;\n\n selectionRules = buildImageCSS(\n rootSelector,\n addUniqueId(image, IMAGE_ID),\n core.selection.imageSelectionBorderColor\n );\n core.selection.selection = selection;\n\n setRangeSelection(doc, image);\n break;\n case 'table':\n const { table, firstColumn, firstRow } = selection;\n\n selectionRules = buildTableCss(\n rootSelector,\n addUniqueId(table, TABLE_ID),\n selection\n );\n core.selection.selection = selection;\n\n setRangeSelection(doc, table.rows[firstRow]?.cells[firstColumn]);\n break;\n case 'range':\n addRangeToSelection(doc, selection.range);\n\n core.selection.selection = core.api.hasFocus(core) ? null : selection;\n break;\n\n default:\n core.selection.selection = null;\n break;\n }\n\n if (sheet) {\n for (let i = sheet.cssRules.length - 1; i >= 0; i--) {\n sheet.deleteRule(i);\n }\n\n if (selectionRules) {\n for (let i = 0; i < selectionRules.length; i++) {\n sheet.insertRule(selectionRules[i]);\n }\n }\n }\n } finally {\n core.selection.skipReselectOnFocus = skipReselectOnFocus;\n }\n\n if (!skipSelectionChangedEvent) {\n const eventData: ContentModelSelectionChangedEvent = {\n eventType: PluginEventType.SelectionChanged,\n newSelection: selection,\n selectionRangeEx: null,\n };\n\n core.api.triggerEvent(core, eventData, true /*broadcast*/);\n }\n};\n\nfunction buildImageCSS(editorSelector: string, imageId: string, borderColor?: string): string[] {\n const color = borderColor || DEFAULT_SELECTION_BORDER_COLOR;\n\n return [\n `${editorSelector} #${imageId} {outline-style:auto!important;outline-color:${color}!important;}`,\n `${editorSelector} ${CARET_CSS_RULE}`,\n ];\n}\n\nfunction buildTableCss(\n editorSelector: string,\n tableId: string,\n selection: TableSelection\n): string[] {\n const { firstColumn, firstRow, lastColumn, lastRow } = selection;\n const cells = parseTableCells(selection.table);\n const isAllTableSelected =\n firstRow == 0 &&\n firstColumn == 0 &&\n lastRow == cells.length - 1 &&\n lastColumn == (cells[lastRow]?.length ?? 0) - 1;\n const rootSelector = editorSelector + ' #' + tableId;\n const selectors = isAllTableSelected\n ? [rootSelector, `${rootSelector} *`]\n : handleTableSelected(rootSelector, selection, cells);\n\n const cssRules: string[] = [`${editorSelector} ${CARET_CSS_RULE}`];\n let currentRules: string = '';\n\n for (let i = 0; i < selectors.length; i++) {\n currentRules += (currentRules.length > 0 ? ',' : '') + selectors[i] || '';\n\n if (\n currentRules.length + (selectors[0]?.length || 0) > MAX_RULE_SELECTOR_LENGTH ||\n i == selectors.length - 1\n ) {\n cssRules.push(currentRules + ' ' + TABLE_CSS_RULE);\n currentRules = '';\n }\n }\n\n return cssRules;\n}\n\nfunction handleTableSelected(\n rootSelector: string,\n selection: TableSelection,\n cells: (HTMLTableCellElement | null)[][]\n) {\n const { firstRow, firstColumn, lastRow, lastColumn, table } = selection;\n const selectors: string[] = [];\n\n // Get whether table has thead, tbody or tfoot, then Set the start and end of each of the table children,\n // so we can build the selector according the element between the table and the row.\n let cont = 0;\n const indexes = toArray(table.childNodes)\n .filter(\n (node): node is HTMLTableSectionElement =>\n ['THEAD', 'TBODY', 'TFOOT'].indexOf(\n isNodeOfType(node, 'ELEMENT_NODE') ? node.tagName : ''\n ) > -1\n )\n .map(node => {\n const result = {\n el: node.tagName,\n start: cont,\n end: node.childNodes.length + cont,\n };\n\n cont = result.end;\n return result;\n });\n\n cells.forEach((row, rowIndex) => {\n let tdCount = 0;\n\n //Get current TBODY/THEAD/TFOOT\n const midElement = indexes.filter(ind => ind.start <= rowIndex && ind.end > rowIndex)[0];\n const middleElSelector = midElement ? '>' + midElement.el + '>' : '>';\n const currentRow =\n midElement && rowIndex + 1 >= midElement.start\n ? rowIndex + 1 - midElement.start\n : rowIndex + 1;\n\n for (let cellIndex = 0; cellIndex < row.length; cellIndex++) {\n const cell = row[cellIndex];\n\n if (cell) {\n tdCount++;\n\n if (\n rowIndex >= firstRow &&\n rowIndex <= lastRow &&\n cellIndex >= firstColumn &&\n cellIndex <= lastColumn\n ) {\n const selector = `${rootSelector}${middleElSelector} tr:nth-child(${currentRow})>${cell.tagName}:nth-child(${tdCount})`;\n\n selectors.push(selector, selector + ' *');\n }\n }\n }\n });\n\n return selectors;\n}\n\nfunction setRangeSelection(doc: Document, element: HTMLElement | undefined) {\n if (element) {\n const range = doc.createRange();\n\n range.selectNode(element);\n range.collapse();\n\n addRangeToSelection(doc, range);\n }\n}\n\nfunction addUniqueId(element: HTMLElement, idPrefix: string): string {\n idPrefix = element.id || idPrefix;\n\n const doc = element.ownerDocument;\n let i = 0;\n\n while (!element.id || doc.querySelectorAll('#' + element.id).length > 1) {\n element.id = idPrefix + '_' + i++;\n }\n\n return element.id;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"setDOMSelection.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-core/lib/coreApi/setDOMSelection.ts"],"names":[],"mappings":";;;AAAA,+EAA8E;AAC9E,2EAAoE;AACpE,u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AG,gBAAgB,sBAAiB,UAAU,UAAK,IAAI,CAAC,OAAO,mBAAc,OAAO,MAAG,CAAC;oBAExH,SAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC,CAAC;iBAC7C;aACJ;SACJ;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,SAAS,CAAC;AACrB,CAAC;AAED,SAAS,iBAAiB,CAAC,GAAa,EAAE,OAAgC;IACtE,IAAI,OAAO,IAAI,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;QAClC,IAAM,KAAK,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC;QAEhC,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QAC1B,KAAK,CAAC,QAAQ,EAAE,CAAC;QAEjB,IAAA,yCAAmB,EAAC,GAAG,EAAE,KAAK,CAAC,CAAC;KACnC;AACL,CAAC;AAED,SAAS,WAAW,CAAC,OAAoB,EAAE,QAAgB;IACvD,QAAQ,GAAG,OAAO,CAAC,EAAE,IAAI,QAAQ,CAAC;IAElC,IAAM,GAAG,GAAG,OAAO,CAAC,aAAa,CAAC;IAClC,IAAI,CAAC,GAAG,CAAC,CAAC;IAEV,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,GAAG,CAAC,gBAAgB,CAAC,GAAG,GAAG,OAAO,CAAC,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;QACrE,OAAO,CAAC,EAAE,GAAG,QAAQ,GAAG,GAAG,GAAG,CAAC,EAAE,CAAC;KACrC;IAED,OAAO,OAAO,CAAC,EAAE,CAAC;AACtB,CAAC","sourcesContent":["import { addRangeToSelection } from '../corePlugin/utils/addRangeToSelection';\nimport { isNodeOfType, toArray } from 'roosterjs-content-model-dom';\nimport { parseTableCells } from '../publicApi/domUtils/tableCellUtils';\nimport type {\n SelectionChangedEvent,\n SetDOMSelection,\n TableSelection,\n} from 'roosterjs-content-model-types';\n\nconst IMAGE_ID = 'image';\nconst TABLE_ID = 'table';\nconst CONTENT_DIV_ID = 'contentDiv';\nconst DEFAULT_SELECTION_BORDER_COLOR = '#DB626C';\nconst TABLE_CSS_RULE = '{background-color: rgb(198,198,198) !important;}';\nconst CARET_CSS_RULE = '{caret-color: transparent}';\nconst MAX_RULE_SELECTOR_LENGTH = 9000;\n\n/**\n * @internal\n */\nexport const setDOMSelection: SetDOMSelection = (core, selection, skipSelectionChangedEvent) => {\n // We are applying a new selection, so we don't need to apply cached selection in DOMEventPlugin.\n // Set skipReselectOnFocus to skip this behavior\n const skipReselectOnFocus = core.selection.skipReselectOnFocus;\n\n const doc = core.contentDiv.ownerDocument;\n const sheet = core.selection.selectionStyleNode?.sheet;\n\n core.selection.skipReselectOnFocus = true;\n\n try {\n let selectionRules: string[] | undefined;\n const rootSelector = '#' + addUniqueId(core.contentDiv, CONTENT_DIV_ID);\n\n switch (selection?.type) {\n case 'image':\n const image = selection.image;\n\n selectionRules = buildImageCSS(\n rootSelector,\n addUniqueId(image, IMAGE_ID),\n core.selection.imageSelectionBorderColor\n );\n core.selection.selection = selection;\n\n setRangeSelection(doc, image);\n break;\n case 'table':\n const { table, firstColumn, firstRow } = selection;\n\n selectionRules = buildTableCss(\n rootSelector,\n addUniqueId(table, TABLE_ID),\n selection\n );\n core.selection.selection = selection;\n\n setRangeSelection(doc, table.rows[firstRow]?.cells[firstColumn]);\n break;\n case 'range':\n addRangeToSelection(doc, selection.range);\n\n core.selection.selection = core.api.hasFocus(core) ? null : selection;\n break;\n\n default:\n core.selection.selection = null;\n break;\n }\n\n if (sheet) {\n for (let i = sheet.cssRules.length - 1; i >= 0; i--) {\n sheet.deleteRule(i);\n }\n\n if (selectionRules) {\n for (let i = 0; i < selectionRules.length; i++) {\n sheet.insertRule(selectionRules[i]);\n }\n }\n }\n } finally {\n core.selection.skipReselectOnFocus = skipReselectOnFocus;\n }\n\n if (!skipSelectionChangedEvent) {\n const eventData: SelectionChangedEvent = {\n eventType: 'selectionChanged',\n newSelection: selection,\n };\n\n core.api.triggerEvent(core, eventData, true /*broadcast*/);\n }\n};\n\nfunction buildImageCSS(editorSelector: string, imageId: string, borderColor?: string): string[] {\n const color = borderColor || DEFAULT_SELECTION_BORDER_COLOR;\n\n return [\n `${editorSelector} #${imageId} {outline-style:auto!important;outline-color:${color}!important;}`,\n `${editorSelector} ${CARET_CSS_RULE}`,\n ];\n}\n\nfunction buildTableCss(\n editorSelector: string,\n tableId: string,\n selection: TableSelection\n): string[] {\n const { firstColumn, firstRow, lastColumn, lastRow } = selection;\n const cells = parseTableCells(selection.table);\n const isAllTableSelected =\n firstRow == 0 &&\n firstColumn == 0 &&\n lastRow == cells.length - 1 &&\n lastColumn == (cells[lastRow]?.length ?? 0) - 1;\n const rootSelector = editorSelector + ' #' + tableId;\n const selectors = isAllTableSelected\n ? [rootSelector, `${rootSelector} *`]\n : handleTableSelected(rootSelector, selection, cells);\n\n const cssRules: string[] = [`${editorSelector} ${CARET_CSS_RULE}`];\n let currentRules: string = '';\n\n for (let i = 0; i < selectors.length; i++) {\n currentRules += (currentRules.length > 0 ? ',' : '') + selectors[i] || '';\n\n if (\n currentRules.length + (selectors[0]?.length || 0) > MAX_RULE_SELECTOR_LENGTH ||\n i == selectors.length - 1\n ) {\n cssRules.push(currentRules + ' ' + TABLE_CSS_RULE);\n currentRules = '';\n }\n }\n\n return cssRules;\n}\n\nfunction handleTableSelected(\n rootSelector: string,\n selection: TableSelection,\n cells: (HTMLTableCellElement | null)[][]\n) {\n const { firstRow, firstColumn, lastRow, lastColumn, table } = selection;\n const selectors: string[] = [];\n\n // Get whether table has thead, tbody or tfoot, then Set the start and end of each of the table children,\n // so we can build the selector according the element between the table and the row.\n let cont = 0;\n const indexes = toArray(table.childNodes)\n .filter(\n (node): node is HTMLTableSectionElement =>\n ['THEAD', 'TBODY', 'TFOOT'].indexOf(\n isNodeOfType(node, 'ELEMENT_NODE') ? node.tagName : ''\n ) > -1\n )\n .map(node => {\n const result = {\n el: node.tagName,\n start: cont,\n end: node.childNodes.length + cont,\n };\n\n cont = result.end;\n return result;\n });\n\n cells.forEach((row, rowIndex) => {\n let tdCount = 0;\n\n //Get current TBODY/THEAD/TFOOT\n const midElement = indexes.filter(ind => ind.start <= rowIndex && ind.end > rowIndex)[0];\n const middleElSelector = midElement ? '>' + midElement.el + '>' : '>';\n const currentRow =\n midElement && rowIndex + 1 >= midElement.start\n ? rowIndex + 1 - midElement.start\n : rowIndex + 1;\n\n for (let cellIndex = 0; cellIndex < row.length; cellIndex++) {\n const cell = row[cellIndex];\n\n if (cell) {\n tdCount++;\n\n if (\n rowIndex >= firstRow &&\n rowIndex <= lastRow &&\n cellIndex >= firstColumn &&\n cellIndex <= lastColumn\n ) {\n const selector = `${rootSelector}${middleElSelector} tr:nth-child(${currentRow})>${cell.tagName}:nth-child(${tdCount})`;\n\n selectors.push(selector, selector + ' *');\n }\n }\n }\n });\n\n return selectors;\n}\n\nfunction setRangeSelection(doc: Document, element: HTMLElement | undefined) {\n if (element && doc.contains(element)) {\n const range = doc.createRange();\n\n range.selectNode(element);\n range.collapse();\n\n addRangeToSelection(doc, range);\n }\n}\n\nfunction addUniqueId(element: HTMLElement, idPrefix: string): string {\n idPrefix = element.id || idPrefix;\n\n const doc = element.ownerDocument;\n let i = 0;\n\n while (!element.id || doc.querySelectorAll('#' + element.id).length > 1) {\n element.id = idPrefix + '_' + i++;\n }\n\n return element.id;\n}\n"]}
|
|
@@ -21,9 +21,7 @@ var switchShadowEdit = function (editorCore, isOn) {
|
|
|
21
21
|
var clonedRoot = core.contentDiv.cloneNode(true /*deep*/);
|
|
22
22
|
(0, roosterjs_content_model_dom_1.moveChildNodes)(fragment, clonedRoot);
|
|
23
23
|
core.api.triggerEvent(core, {
|
|
24
|
-
eventType:
|
|
25
|
-
fragment: fragment,
|
|
26
|
-
selectionPath: null,
|
|
24
|
+
eventType: 'enteredShadowEdit',
|
|
27
25
|
}, false /*broadcast*/);
|
|
28
26
|
// This need to be done after EnteredShadowEdit event is triggered since EnteredShadowEdit event will cause a SelectionChanged event
|
|
29
27
|
// if current selection is table selection or image selection
|
|
@@ -35,7 +33,7 @@ var switchShadowEdit = function (editorCore, isOn) {
|
|
|
35
33
|
else {
|
|
36
34
|
core.lifecycle.shadowEditFragment = null;
|
|
37
35
|
core.api.triggerEvent(core, {
|
|
38
|
-
eventType:
|
|
36
|
+
eventType: 'leavingShadowEdit',
|
|
39
37
|
}, false /*broadcast*/);
|
|
40
38
|
if (core.cache.cachedModel) {
|
|
41
39
|
// Force clear cached element from selected block
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"switchShadowEdit.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-core/lib/coreApi/switchShadowEdit.ts"],"names":[],"mappings":";;;AAAA,8EAA6E;AAC7E,2EAA6D;
|
|
1
|
+
{"version":3,"file":"switchShadowEdit.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-core/lib/coreApi/switchShadowEdit.ts"],"names":[],"mappings":";;;AAAA,8EAA6E;AAC7E,2EAA6D;AAG7D;;;;;GAKG;AACI,IAAM,gBAAgB,GAAqB,UAAC,UAAU,EAAE,IAAI;IAC/D,4CAA4C;IAC5C,IAAM,IAAI,GAAG,UAAU,CAAC;IAExB,IAAI,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,kBAAkB,EAAE;QAC7C,IAAI,IAAI,EAAE;YACN,IAAM,KAAK,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;YAEjF,sFAAsF;YACtF,wEAAwE;YACxE,IAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,sBAAsB,EAAE,CAAC;YACxE,IAAM,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAE5D,IAAA,4CAAc,EAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;YAErC,IAAI,CAAC,GAAG,CAAC,YAAY,CACjB,IAAI,EACJ;gBACI,SAAS,EAAE,mBAAmB;aACjC,EACD,KAAK,CAAC,aAAa,CACtB,CAAC;YAEF,oIAAoI;YACpI,6DAA6D;YAC7D,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,IAAI,KAAK,EAAE;gBAClC,IAAI,CAAC,KAAK,CAAC,WAAW,GAAG,KAAK,CAAC;aAClC;YAED,IAAI,CAAC,SAAS,CAAC,kBAAkB,GAAG,QAAQ,CAAC;SAChD;aAAM;YACH,IAAI,CAAC,SAAS,CAAC,kBAAkB,GAAG,IAAI,CAAC;YAEzC,IAAI,CAAC,GAAG,CAAC,YAAY,CACjB,IAAI,EACJ;gBACI,SAAS,EAAE,mBAAmB;aACjC,EACD,KAAK,CAAC,aAAa,CACtB,CAAC;YAEF,IAAI,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE;gBACxB,iDAAiD;gBACjD,IAAA,qCAAiB,EAAC,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,cAAO,CAAC,CAAC,CAAC;gBAEpD,IAAI,CAAC,GAAG,CAAC,eAAe,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE;oBACnD,eAAe,EAAE,IAAI,EAAE,qGAAqG;iBAC/H,CAAC,CAAC;aACN;SACJ;KACJ;AACL,CAAC,CAAC;AAnDW,QAAA,gBAAgB,oBAmD3B","sourcesContent":["import { iterateSelections } from '../publicApi/selection/iterateSelections';\nimport { moveChildNodes } from 'roosterjs-content-model-dom';\nimport type { SwitchShadowEdit } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n * Switch the Shadow Edit mode of editor On/Off\n * @param editorCore The StandaloneEditorCore object\n * @param isOn True to switch On, False to switch Off\n */\nexport const switchShadowEdit: SwitchShadowEdit = (editorCore, isOn): void => {\n // TODO: Use strong-typed editor core object\n const core = editorCore;\n\n if (isOn != !!core.lifecycle.shadowEditFragment) {\n if (isOn) {\n const model = !core.cache.cachedModel ? core.api.createContentModel(core) : null;\n\n // Fake object, not used in Content Model Editor, just to satisfy original editor code\n // TODO: we can remove them once we have standalone Content Model Editor\n const fragment = core.contentDiv.ownerDocument.createDocumentFragment();\n const clonedRoot = core.contentDiv.cloneNode(true /*deep*/);\n\n moveChildNodes(fragment, clonedRoot);\n\n core.api.triggerEvent(\n core,\n {\n eventType: 'enteredShadowEdit',\n },\n false /*broadcast*/\n );\n\n // This need to be done after EnteredShadowEdit event is triggered since EnteredShadowEdit event will cause a SelectionChanged event\n // if current selection is table selection or image selection\n if (!core.cache.cachedModel && model) {\n core.cache.cachedModel = model;\n }\n\n core.lifecycle.shadowEditFragment = fragment;\n } else {\n core.lifecycle.shadowEditFragment = null;\n\n core.api.triggerEvent(\n core,\n {\n eventType: 'leavingShadowEdit',\n },\n false /*broadcast*/\n );\n\n if (core.cache.cachedModel) {\n // Force clear cached element from selected block\n iterateSelections(core.cache.cachedModel, () => {});\n\n core.api.setContentModel(core, core.cache.cachedModel, {\n ignoreSelection: true, // Do not set focus and selection when quit shadow edit, focus may remain in UI control (picker, ...)\n });\n }\n }\n }\n};\n"]}
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.triggerEvent = void 0;
|
|
4
4
|
var allowedEventsInShadowEdit = [
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
'editorReady',
|
|
6
|
+
'beforeDispose',
|
|
7
|
+
'extractContentWithDom',
|
|
8
|
+
'zoomChanged',
|
|
9
9
|
];
|
|
10
10
|
/**
|
|
11
11
|
* @internal
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"triggerEvent.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-core/lib/coreApi/triggerEvent.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"triggerEvent.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-core/lib/coreApi/triggerEvent.ts"],"names":[],"mappings":";;;AAOA,IAAM,yBAAyB,GAAsB;IACjD,aAAa;IACb,eAAe;IACf,uBAAuB;IACvB,aAAa;CAChB,CAAC;AAEF;;;;;;GAMG;AACI,IAAM,YAAY,GAAiB,UAAC,IAAI,EAAE,WAAW,EAAE,SAAS;IACnE,IACI,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,kBAAkB;QAC/B,yBAAyB,CAAC,OAAO,CAAC,WAAW,CAAC,SAA4B,CAAC,IAAI,CAAC,CAAC;QACrF,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,UAAA,MAAM,IAAI,OAAA,kBAAkB,CAAC,WAAW,EAAE,MAAM,CAAC,EAAvC,CAAuC,CAAC,CAAC,EACtF;QACE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,UAAA,MAAM;YACvB,IAAI,MAAM,CAAC,aAAa,EAAE;gBACtB,MAAM,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;aACrC;QACL,CAAC,CAAC,CAAC;KACN;AACL,CAAC,CAAC;AAZW,QAAA,YAAY,gBAYvB;AAEF,SAAS,kBAAkB,CAAC,KAAkB,EAAE,MAAoB;;IAChE,IAAI,MAAM,CAAC,aAAa,KAAI,MAAA,MAAM,CAAC,0BAA0B,+CAAjC,MAAM,EAA8B,KAAK,CAAC,CAAA,EAAE;QACpE,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QAC5B,OAAO,IAAI,CAAC;KACf;IAED,OAAO,KAAK,CAAC;AACjB,CAAC","sourcesContent":["import type {\n EditorPlugin,\n PluginEvent,\n PluginEventType,\n TriggerEvent,\n} from 'roosterjs-content-model-types';\n\nconst allowedEventsInShadowEdit: PluginEventType[] = [\n 'editorReady',\n 'beforeDispose',\n 'extractContentWithDom',\n 'zoomChanged',\n];\n\n/**\n * @internal\n * Trigger a plugin event\n * @param core The StandaloneEditorCore object\n * @param pluginEvent The event object to trigger\n * @param broadcast Set to true to skip the shouldHandleEventExclusively check\n */\nexport const triggerEvent: TriggerEvent = (core, pluginEvent, broadcast) => {\n if (\n (!core.lifecycle.shadowEditFragment ||\n allowedEventsInShadowEdit.indexOf(pluginEvent.eventType as PluginEventType) >= 0) &&\n (broadcast || !core.plugins.some(plugin => handledExclusively(pluginEvent, plugin)))\n ) {\n core.plugins.forEach(plugin => {\n if (plugin.onPluginEvent) {\n plugin.onPluginEvent(pluginEvent);\n }\n });\n }\n};\n\nfunction handledExclusively(event: PluginEvent, plugin: EditorPlugin): boolean {\n if (plugin.onPluginEvent && plugin.willHandleEventExclusively?.(event)) {\n plugin.onPluginEvent(event);\n return true;\n }\n\n return false;\n}\n"]}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { ContentModelCachePluginState, StandaloneEditorOptions } from 'roosterjs-content-model-types';
|
|
2
|
-
import type { PluginWithState } from 'roosterjs-editor-types';
|
|
1
|
+
import type { ContentModelCachePluginState, PluginWithState, StandaloneEditorOptions } from 'roosterjs-content-model-types';
|
|
3
2
|
/**
|
|
4
3
|
* @internal
|
|
5
4
|
* Create a new instance of ContentModelCachePlugin class.
|
|
@@ -72,22 +72,22 @@ var ContentModelCachePlugin = /** @class */ (function () {
|
|
|
72
72
|
return;
|
|
73
73
|
}
|
|
74
74
|
switch (event.eventType) {
|
|
75
|
-
case
|
|
75
|
+
case 'keyDown':
|
|
76
76
|
if (this.shouldClearCache(event)) {
|
|
77
77
|
this.invalidateCache();
|
|
78
78
|
}
|
|
79
79
|
break;
|
|
80
|
-
case
|
|
80
|
+
case 'input':
|
|
81
81
|
{
|
|
82
82
|
this.updateCachedModel(this.editor, true /*forceUpdate*/);
|
|
83
83
|
}
|
|
84
84
|
break;
|
|
85
|
-
case
|
|
85
|
+
case 'selectionChanged':
|
|
86
86
|
this.updateCachedModel(this.editor);
|
|
87
87
|
break;
|
|
88
|
-
case
|
|
88
|
+
case 'contentChanged':
|
|
89
89
|
{
|
|
90
|
-
var
|
|
90
|
+
var contentModel = event.contentModel, selection = event.selection;
|
|
91
91
|
if (contentModel && this.state.domIndexer) {
|
|
92
92
|
this.state.cachedModel = contentModel;
|
|
93
93
|
this.state.cachedSelection = selection;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContentModelCachePlugin.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-core/lib/corePlugin/ContentModelCachePlugin.ts"],"names":[],"mappings":";;;AAAA,6DAA4D;AAC5D,yEAAwE;AACxE,+DAAoE;AAepE;;GAEG;AACH;IAII;;;OAGG;IACH,iCAAY,MAA+B;QAA3C,iBAIC;QAXO,WAAM,GAA6B,IAAI,CAAC;QAiGxC,4BAAuB,GAAG;;YAC9B,IAAI,MAAA,KAAI,CAAC,MAAM,0CAAE,QAAQ,EAAE,EAAE;gBACzB,KAAI,CAAC,iBAAiB,CAAC,KAAI,CAAC,MAAM,CAAC,CAAC;aACvC;QACL,CAAC,CAAC;QA7FE,IAAI,CAAC,KAAK,GAAG;YACT,UAAU,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,+CAAsB,CAAC,CAAC,CAAC,SAAS;SACrE,CAAC;IACN,CAAC;IAED;;OAEG;IACH,yCAAO,GAAP;QACI,OAAO,mBAAmB,CAAC;IAC/B,CAAC;IAED;;;;;OAKG;IACH,4CAAU,GAAV,UAAW,MAAe;QACtB,gFAAgF;QAChF,IAAI,CAAC,MAAM,GAAG,MAAqC,CAAC;QACpD,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,gBAAgB,CAAC,iBAAiB,EAAE,IAAI,CAAC,uBAAuB,CAAC,CAAC;IAChG,CAAC;IAED;;;;OAIG;IACH,yCAAO,GAAP;QACI,IAAI,IAAI,CAAC,MAAM,EAAE;YACb,IAAI,CAAC,MAAM;iBACN,WAAW,EAAE;iBACb,mBAAmB,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jG,IACI,CAAC,CAAA,MAAA,IAAI,CAAC,KAAK,CAAC,eAAe,0CAAE,IAAI,KAAI,OAAO;YACxC,CAAC,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,KAAK,CAAC,SAAS,CAAC;YAChD,IAAA,6BAAgB,EAAC,QAAQ,CAAC,EAC5B;YACE,OAAO,IAAI,CAAC;SACf;QAED,OAAO,KAAK,CAAC;IACjB,CAAC;IACL,8BAAC;AAAD,CAAC,AA1KD,IA0KC;AAED;;;;GAIG;AACH,SAAgB,6BAA6B,CACzC,MAA+B;IAE/B,OAAO,IAAI,uBAAuB,CAAC,MAAM,CAAC,CAAC;AAC/C,CAAC;AAJD,sEAIC","sourcesContent":["import { areSameSelection } from './utils/areSameSelection';\nimport { contentModelDomIndexer } from './utils/contentModelDomIndexer';\nimport { isCharacterValue } from '../publicApi/domUtils/eventUtils';\nimport { PluginEventType } from 'roosterjs-editor-types';\nimport type {\n ContentModelCachePluginState,\n ContentModelContentChangedEvent,\n IStandaloneEditor,\n StandaloneEditorOptions,\n} from 'roosterjs-content-model-types';\nimport type {\n IEditor,\n PluginEvent,\n PluginKeyDownEvent,\n PluginWithState,\n} from 'roosterjs-editor-types';\n\n/**\n * ContentModel cache plugin manages cached Content Model, and refresh the cache when necessary\n */\nclass ContentModelCachePlugin implements PluginWithState<ContentModelCachePluginState> {\n private editor: IStandaloneEditor | null = null;\n private state: ContentModelCachePluginState;\n\n /**\n * Construct a new instance of ContentModelEditPlugin class\n * @param option The editor option\n */\n constructor(option: StandaloneEditorOptions) {\n this.state = {\n domIndexer: option.cacheModel ? contentModelDomIndexer : undefined,\n };\n }\n\n /**\n * Get name of this plugin\n */\n getName() {\n return 'ContentModelCache';\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 // TODO: Later we may need a different interface for Content Model editor plugin\n this.editor = editor as IEditor & IStandaloneEditor;\n this.editor.getDocument().addEventListener('selectionchange', this.onNativeSelectionChange);\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 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(): ContentModelCachePluginState {\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 PluginEventType.KeyDown:\n if (this.shouldClearCache(event)) {\n this.invalidateCache();\n }\n break;\n\n case PluginEventType.Input:\n {\n this.updateCachedModel(this.editor, true /*forceUpdate*/);\n }\n break;\n\n case PluginEventType.SelectionChanged:\n this.updateCachedModel(this.editor);\n break;\n\n case PluginEventType.ContentChanged:\n {\n const { contentModel, selection } = event as ContentModelContentChangedEvent;\n\n if (contentModel && this.state.domIndexer) {\n this.state.cachedModel = contentModel;\n this.state.cachedSelection = selection;\n } else {\n this.invalidateCache();\n }\n }\n\n break;\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 this.state.cachedModel = undefined;\n this.state.cachedSelection = undefined;\n }\n }\n\n private updateCachedModel(editor: IStandaloneEditor, forceUpdate?: boolean) {\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 !areSameSelection(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 this.state.cachedSelection = newRangeEx;\n }\n } else {\n this.state.cachedSelection = cachedSelection;\n }\n }\n\n private shouldClearCache(event: PluginKeyDownEvent) {\n const { rawEvent, handledByEditFeature } = event;\n\n // In these cases we can't update the model, so clear cache:\n // 1. It is already handled by Content Edit Features\n if (handledByEditFeature) {\n return true;\n }\n\n // 2. Default behavior is prevented, which means other plugins has handled the event\n if (rawEvent.defaultPrevented) {\n return true;\n }\n\n // 3. ENTER key is pressed. ENTER key will create new paragraph, so need to update cache to reflect this change\n // TODO: Handle ENTER key to better reuse content model\n\n if (rawEvent.key == 'Enter') {\n return true;\n }\n\n // 4. Current selection is image or table or expanded range selection, and is inputting some text\n if (\n (this.state.cachedSelection?.type != 'range' ||\n !this.state.cachedSelection.range.collapsed) &&\n isCharacterValue(rawEvent)\n ) {\n return true;\n }\n\n return false;\n }\n}\n\n/**\n * @internal\n * Create a new instance of ContentModelCachePlugin class.\n * @param option The editor option\n */\nexport function createContentModelCachePlugin(\n option: StandaloneEditorOptions\n): PluginWithState<ContentModelCachePluginState> {\n return new ContentModelCachePlugin(option);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ContentModelCachePlugin.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-core/lib/corePlugin/ContentModelCachePlugin.ts"],"names":[],"mappings":";;;AAAA,6DAA4D;AAC5D,yEAAwE;AACxE,+DAAoE;AAUpE;;GAEG;AACH;IAII;;;OAGG;IACH,iCAAY,MAA+B;QAA3C,iBAIC;QAXO,WAAM,GAA6B,IAAI,CAAC;QAiGxC,4BAAuB,GAAG;;YAC9B,IAAI,MAAA,KAAI,CAAC,MAAM,0CAAE,QAAQ,EAAE,EAAE;gBACzB,KAAI,CAAC,iBAAiB,CAAC,KAAI,CAAC,MAAM,CAAC,CAAC;a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,EAAE,eAAe,CAAC,CAAA,EAChF;gBACE,IAAI,CAAC,eAAe,EAAE,CAAC;aAC1B;iBAAM;gBACH,IAAI,CAAC,KAAK,CAAC,eAAe,GAAG,UAAU,CAAC;aAC3C;SACJ;aAAM;YACH,IAAI,CAAC,KAAK,CAAC,eAAe,GAAG,eAAe,CAAC;SAChD;IACL,CAAC;IAEO,kDAAgB,GAAxB,UAAyB,KAAmB;;QAChC,IAAA,QAAQ,GAA2B,KAAK,SAAhC,EAAE,oBAAoB,GAAK,KAAK,qBAAV,CAAW;QAEjD,4DAA4D;QAC5D,oDAAoD;QACpD,IAAI,oBAAoB,EAAE;YACtB,OAAO,IAAI,CAAC;SACf;QAED,oFAAoF;QACpF,IAAI,QAAQ,CAAC,gBAAgB,EAAE;YAC3B,OAAO,IAAI,CAAC;SACf;QAED,+GAA+G;QAC/G,uDAAuD;QAEvD,IAAI,QAAQ,CAAC,GAAG,IAAI,OAAO,EAAE;YACzB,OAAO,IAAI,CAAC;SACf;QAED,iGAAiG;QACjG,IACI,CAAC,CAAA,MAAA,IAAI,CAAC,KAAK,CAAC,eAAe,0CAAE,IAAI,KAAI,OAAO;YACxC,CAAC,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,KAAK,CAAC,SAAS,CAAC;YAChD,IAAA,6BAAgB,EAAC,QAAQ,CAAC,EAC5B;YACE,OAAO,IAAI,CAAC;SACf;QAED,OAAO,KAAK,CAAC;IACjB,CAAC;IACL,8BAAC;AAAD,CAAC,AA1KD,IA0KC;AAED;;;;GAIG;AACH,SAAgB,6BAA6B,CACzC,MAA+B;IAE/B,OAAO,IAAI,uBAAuB,CAAC,MAAM,CAAC,CAAC;AAC/C,CAAC;AAJD,sEAIC","sourcesContent":["import { areSameSelection } from './utils/areSameSelection';\nimport { contentModelDomIndexer } from './utils/contentModelDomIndexer';\nimport { isCharacterValue } from '../publicApi/domUtils/eventUtils';\nimport type {\n ContentModelCachePluginState,\n IStandaloneEditor,\n KeyDownEvent,\n PluginEvent,\n PluginWithState,\n StandaloneEditorOptions,\n} from 'roosterjs-content-model-types';\n\n/**\n * ContentModel cache plugin manages cached Content Model, and refresh the cache when necessary\n */\nclass ContentModelCachePlugin implements PluginWithState<ContentModelCachePluginState> {\n private editor: IStandaloneEditor | null = null;\n private state: ContentModelCachePluginState;\n\n /**\n * Construct a new instance of ContentModelEditPlugin class\n * @param option The editor option\n */\n constructor(option: StandaloneEditorOptions) {\n this.state = {\n domIndexer: option.cacheModel ? contentModelDomIndexer : undefined,\n };\n }\n\n /**\n * Get name of this plugin\n */\n getName() {\n return 'ContentModelCache';\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: IStandaloneEditor) {\n // TODO: Later we may need a different interface for Content Model editor plugin\n this.editor = editor;\n this.editor.getDocument().addEventListener('selectionchange', this.onNativeSelectionChange);\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 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(): ContentModelCachePluginState {\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 'keyDown':\n if (this.shouldClearCache(event)) {\n this.invalidateCache();\n }\n break;\n\n case 'input':\n {\n this.updateCachedModel(this.editor, true /*forceUpdate*/);\n }\n break;\n\n case 'selectionChanged':\n this.updateCachedModel(this.editor);\n break;\n\n case 'contentChanged':\n {\n const { contentModel, selection } = event;\n\n if (contentModel && this.state.domIndexer) {\n this.state.cachedModel = contentModel;\n this.state.cachedSelection = selection;\n } else {\n this.invalidateCache();\n }\n }\n\n break;\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 this.state.cachedModel = undefined;\n this.state.cachedSelection = undefined;\n }\n }\n\n private updateCachedModel(editor: IStandaloneEditor, forceUpdate?: boolean) {\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 !areSameSelection(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 this.state.cachedSelection = newRangeEx;\n }\n } else {\n this.state.cachedSelection = cachedSelection;\n }\n }\n\n private shouldClearCache(event: KeyDownEvent) {\n const { rawEvent, handledByEditFeature } = event;\n\n // In these cases we can't update the model, so clear cache:\n // 1. It is already handled by Content Edit Features\n if (handledByEditFeature) {\n return true;\n }\n\n // 2. Default behavior is prevented, which means other plugins has handled the event\n if (rawEvent.defaultPrevented) {\n return true;\n }\n\n // 3. ENTER key is pressed. ENTER key will create new paragraph, so need to update cache to reflect this change\n // TODO: Handle ENTER key to better reuse content model\n\n if (rawEvent.key == 'Enter') {\n return true;\n }\n\n // 4. Current selection is image or table or expanded range selection, and is inputting some text\n if (\n (this.state.cachedSelection?.type != 'range' ||\n !this.state.cachedSelection.range.collapsed) &&\n isCharacterValue(rawEvent)\n ) {\n return true;\n }\n\n return false;\n }\n}\n\n/**\n * @internal\n * Create a new instance of ContentModelCachePlugin class.\n * @param option The editor option\n */\nexport function createContentModelCachePlugin(\n option: StandaloneEditorOptions\n): PluginWithState<ContentModelCachePluginState> {\n return new ContentModelCachePlugin(option);\n}\n"]}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { CopyPastePluginState, ContentModelTable, OnNodeCreated, StandaloneEditorOptions, ContentModelDocument } from 'roosterjs-content-model-types';
|
|
2
|
-
import type { PluginWithState } from 'roosterjs-editor-types';
|
|
1
|
+
import type { CopyPastePluginState, ContentModelTable, OnNodeCreated, StandaloneEditorOptions, PluginWithState, ContentModelDocument } from 'roosterjs-content-model-types';
|
|
3
2
|
/**
|
|
4
3
|
* @internal
|
|
5
4
|
* Exported only for unit testing
|
|
@@ -43,7 +43,7 @@ var ContentModelCopyPastePlugin = /** @class */ (function () {
|
|
|
43
43
|
return undefined;
|
|
44
44
|
}
|
|
45
45
|
var result = node.cloneNode(true /*deep*/);
|
|
46
|
-
var colorHandler = _this.editor.
|
|
46
|
+
var colorHandler = _this.editor.getColorManager();
|
|
47
47
|
(0, transformColor_1.transformColor)(result, true /*includeSelf*/, 'darkToLight', colorHandler);
|
|
48
48
|
result.style.color = result.style.color || 'inherit';
|
|
49
49
|
result.style.backgroundColor = result.style.backgroundColor || 'inherit';
|
|
@@ -132,7 +132,7 @@ var ContentModelCopyPastePlugin = /** @class */ (function () {
|
|
|
132
132
|
? domSelectionToRange(doc, selectionForCopy)
|
|
133
133
|
: null;
|
|
134
134
|
if (newRange) {
|
|
135
|
-
newRange = this.editor.
|
|
135
|
+
newRange = this.editor.triggerEvent('beforeCutCopy', {
|
|
136
136
|
clonedRoot: tempDiv_1,
|
|
137
137
|
range: newRange,
|
|
138
138
|
rawEvent: event,
|