roosterjs-content-model-core 9.1.0 → 9.3.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/command/exportContent/exportContent.d.ts +18 -7
- package/lib/command/exportContent/exportContent.js +3 -12
- package/lib/command/exportContent/exportContent.js.map +1 -1
- package/lib/command/paste/mergePasteContent.js +1 -0
- package/lib/command/paste/mergePasteContent.js.map +1 -1
- package/lib/command/paste/paste.js +4 -1
- package/lib/command/paste/paste.js.map +1 -1
- package/lib/coreApi/announce/announce.d.ts +8 -0
- package/lib/coreApi/announce/announce.js +53 -0
- package/lib/coreApi/announce/announce.js.map +1 -0
- package/lib/coreApi/coreApiMap.js +2 -0
- package/lib/coreApi/coreApiMap.js.map +1 -1
- package/lib/coreApi/createContentModel/createContentModel.js +24 -25
- package/lib/coreApi/createContentModel/createContentModel.js.map +1 -1
- package/lib/coreApi/createEditorContext/createEditorContext.js +3 -8
- package/lib/coreApi/createEditorContext/createEditorContext.js.map +1 -1
- package/lib/coreApi/formatContentModel/formatContentModel.js +15 -10
- package/lib/coreApi/formatContentModel/formatContentModel.js.map +1 -1
- package/lib/coreApi/restoreUndoSnapshot/restoreSnapshotHTML.js +2 -6
- package/lib/coreApi/restoreUndoSnapshot/restoreSnapshotHTML.js.map +1 -1
- package/lib/coreApi/setDOMSelection/setDOMSelection.js +19 -4
- package/lib/coreApi/setDOMSelection/setDOMSelection.js.map +1 -1
- package/lib/corePlugin/cache/domIndexerImpl.js +7 -0
- package/lib/corePlugin/cache/domIndexerImpl.js.map +1 -1
- package/lib/corePlugin/copyPaste/CopyPastePlugin.js +1 -1
- package/lib/corePlugin/copyPaste/CopyPastePlugin.js.map +1 -1
- package/lib/corePlugin/entity/adjustSelectionAroundEntity.d.ts +5 -0
- package/lib/corePlugin/entity/adjustSelectionAroundEntity.js +107 -0
- package/lib/corePlugin/entity/adjustSelectionAroundEntity.js.map +1 -0
- package/lib/corePlugin/entity/entityDelimiterUtils.js +69 -45
- package/lib/corePlugin/entity/entityDelimiterUtils.js.map +1 -1
- package/lib/corePlugin/lifecycle/LifecyclePlugin.js +7 -1
- package/lib/corePlugin/lifecycle/LifecyclePlugin.js.map +1 -1
- package/lib/corePlugin/selection/SelectionPlugin.js +12 -3
- package/lib/corePlugin/selection/SelectionPlugin.js.map +1 -1
- package/lib/corePlugin/undo/UndoPlugin.js +5 -0
- package/lib/corePlugin/undo/UndoPlugin.js.map +1 -1
- package/lib/editor/Editor.d.ts +6 -4
- package/lib/editor/Editor.js +9 -7
- package/lib/editor/Editor.js.map +1 -1
- package/lib/editor/core/DOMHelperImpl.js +20 -0
- package/lib/editor/core/DOMHelperImpl.js.map +1 -1
- package/lib/override/listMetadataApplier.js +22 -93
- package/lib/override/listMetadataApplier.js.map +1 -1
- package/lib-amd/command/exportContent/exportContent.d.ts +18 -7
- package/lib-amd/command/exportContent/exportContent.js +3 -12
- package/lib-amd/command/exportContent/exportContent.js.map +1 -1
- package/lib-amd/command/paste/mergePasteContent.js +1 -0
- package/lib-amd/command/paste/mergePasteContent.js.map +1 -1
- package/lib-amd/command/paste/paste.js +4 -1
- package/lib-amd/command/paste/paste.js.map +1 -1
- package/lib-amd/coreApi/announce/announce.d.ts +8 -0
- package/lib-amd/coreApi/announce/announce.js +55 -0
- package/lib-amd/coreApi/announce/announce.js.map +1 -0
- package/lib-amd/coreApi/coreApiMap.js +2 -1
- package/lib-amd/coreApi/coreApiMap.js.map +1 -1
- package/lib-amd/coreApi/createContentModel/createContentModel.js +24 -25
- package/lib-amd/coreApi/createContentModel/createContentModel.js.map +1 -1
- package/lib-amd/coreApi/createEditorContext/createEditorContext.js +3 -8
- package/lib-amd/coreApi/createEditorContext/createEditorContext.js.map +1 -1
- package/lib-amd/coreApi/formatContentModel/formatContentModel.js +15 -10
- package/lib-amd/coreApi/formatContentModel/formatContentModel.js.map +1 -1
- package/lib-amd/coreApi/restoreUndoSnapshot/restoreSnapshotHTML.js +2 -6
- package/lib-amd/coreApi/restoreUndoSnapshot/restoreSnapshotHTML.js.map +1 -1
- package/lib-amd/coreApi/setDOMSelection/setDOMSelection.js +19 -4
- package/lib-amd/coreApi/setDOMSelection/setDOMSelection.js.map +1 -1
- package/lib-amd/corePlugin/cache/domIndexerImpl.js +7 -0
- package/lib-amd/corePlugin/cache/domIndexerImpl.js.map +1 -1
- package/lib-amd/corePlugin/copyPaste/CopyPastePlugin.js +1 -1
- package/lib-amd/corePlugin/copyPaste/CopyPastePlugin.js.map +1 -1
- package/lib-amd/corePlugin/entity/adjustSelectionAroundEntity.d.ts +5 -0
- package/lib-amd/corePlugin/entity/adjustSelectionAroundEntity.js +107 -0
- package/lib-amd/corePlugin/entity/adjustSelectionAroundEntity.js.map +1 -0
- package/lib-amd/corePlugin/entity/entityDelimiterUtils.js +69 -46
- package/lib-amd/corePlugin/entity/entityDelimiterUtils.js.map +1 -1
- package/lib-amd/corePlugin/lifecycle/LifecyclePlugin.js +7 -1
- package/lib-amd/corePlugin/lifecycle/LifecyclePlugin.js.map +1 -1
- package/lib-amd/corePlugin/selection/SelectionPlugin.js +12 -3
- package/lib-amd/corePlugin/selection/SelectionPlugin.js.map +1 -1
- package/lib-amd/corePlugin/undo/UndoPlugin.js +5 -0
- package/lib-amd/corePlugin/undo/UndoPlugin.js.map +1 -1
- package/lib-amd/editor/Editor.d.ts +6 -4
- package/lib-amd/editor/Editor.js +9 -7
- package/lib-amd/editor/Editor.js.map +1 -1
- package/lib-amd/editor/core/DOMHelperImpl.js +20 -0
- package/lib-amd/editor/core/DOMHelperImpl.js.map +1 -1
- package/lib-amd/override/listMetadataApplier.js +23 -93
- package/lib-amd/override/listMetadataApplier.js.map +1 -1
- package/lib-mjs/command/exportContent/exportContent.d.ts +18 -7
- package/lib-mjs/command/exportContent/exportContent.js +3 -12
- package/lib-mjs/command/exportContent/exportContent.js.map +1 -1
- package/lib-mjs/command/paste/mergePasteContent.js +1 -0
- package/lib-mjs/command/paste/mergePasteContent.js.map +1 -1
- package/lib-mjs/command/paste/paste.js +4 -1
- package/lib-mjs/command/paste/paste.js.map +1 -1
- package/lib-mjs/coreApi/announce/announce.d.ts +8 -0
- package/lib-mjs/coreApi/announce/announce.js +49 -0
- package/lib-mjs/coreApi/announce/announce.js.map +1 -0
- package/lib-mjs/coreApi/coreApiMap.js +2 -0
- package/lib-mjs/coreApi/coreApiMap.js.map +1 -1
- package/lib-mjs/coreApi/createContentModel/createContentModel.js +24 -25
- package/lib-mjs/coreApi/createContentModel/createContentModel.js.map +1 -1
- package/lib-mjs/coreApi/createEditorContext/createEditorContext.js +3 -8
- package/lib-mjs/coreApi/createEditorContext/createEditorContext.js.map +1 -1
- package/lib-mjs/coreApi/formatContentModel/formatContentModel.js +16 -11
- package/lib-mjs/coreApi/formatContentModel/formatContentModel.js.map +1 -1
- package/lib-mjs/coreApi/restoreUndoSnapshot/restoreSnapshotHTML.js +1 -5
- package/lib-mjs/coreApi/restoreUndoSnapshot/restoreSnapshotHTML.js.map +1 -1
- package/lib-mjs/coreApi/setDOMSelection/setDOMSelection.js +20 -5
- package/lib-mjs/coreApi/setDOMSelection/setDOMSelection.js.map +1 -1
- package/lib-mjs/corePlugin/cache/domIndexerImpl.js +7 -0
- package/lib-mjs/corePlugin/cache/domIndexerImpl.js.map +1 -1
- package/lib-mjs/corePlugin/copyPaste/CopyPastePlugin.js +1 -1
- package/lib-mjs/corePlugin/copyPaste/CopyPastePlugin.js.map +1 -1
- package/lib-mjs/corePlugin/entity/adjustSelectionAroundEntity.d.ts +5 -0
- package/lib-mjs/corePlugin/entity/adjustSelectionAroundEntity.js +103 -0
- package/lib-mjs/corePlugin/entity/adjustSelectionAroundEntity.js.map +1 -0
- package/lib-mjs/corePlugin/entity/entityDelimiterUtils.js +69 -45
- package/lib-mjs/corePlugin/entity/entityDelimiterUtils.js.map +1 -1
- package/lib-mjs/corePlugin/lifecycle/LifecyclePlugin.js +7 -1
- package/lib-mjs/corePlugin/lifecycle/LifecyclePlugin.js.map +1 -1
- package/lib-mjs/corePlugin/selection/SelectionPlugin.js +12 -3
- package/lib-mjs/corePlugin/selection/SelectionPlugin.js.map +1 -1
- package/lib-mjs/corePlugin/undo/UndoPlugin.js +5 -0
- package/lib-mjs/corePlugin/undo/UndoPlugin.js.map +1 -1
- package/lib-mjs/editor/Editor.d.ts +6 -4
- package/lib-mjs/editor/Editor.js +9 -7
- package/lib-mjs/editor/Editor.js.map +1 -1
- package/lib-mjs/editor/core/DOMHelperImpl.js +21 -1
- package/lib-mjs/editor/core/DOMHelperImpl.js.map +1 -1
- package/lib-mjs/override/listMetadataApplier.js +23 -94
- package/lib-mjs/override/listMetadataApplier.js.map +1 -1
- package/package.json +3 -3
|
@@ -1,11 +1,22 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { IEditor, ModelToDomOption, ModelToTextCallbacks } from 'roosterjs-content-model-types';
|
|
2
2
|
/**
|
|
3
|
-
* Export
|
|
3
|
+
* Export HTML content. If there are entities, this will cause EntityOperation event with option = 'replaceTemporaryContent' to get a dehydrated entity
|
|
4
4
|
* @param editor The editor to get content from
|
|
5
|
-
* @param mode
|
|
6
|
-
* - HTML: Export HTML content. If there are entities, this will cause EntityOperation event with option = 'replaceTemporaryContent' to get a dehydrated entity
|
|
7
|
-
* - PlainText: Export plain text content
|
|
8
|
-
* - PlainTextFast: Export plain text using editor's textContent property directly
|
|
5
|
+
* @param mode Specify HTML to get plain text result. This is the default option
|
|
9
6
|
* @param options @optional Options for Model to DOM conversion
|
|
10
7
|
*/
|
|
11
|
-
export declare function exportContent(editor: IEditor, mode?:
|
|
8
|
+
export declare function exportContent(editor: IEditor, mode?: 'HTML', options?: ModelToDomOption): string;
|
|
9
|
+
/**
|
|
10
|
+
* Export plain text content
|
|
11
|
+
* @param editor The editor to get content from
|
|
12
|
+
* @param mode Specify PlainText to get plain text result
|
|
13
|
+
* @param callbacks @optional Callbacks to customize conversion behavior
|
|
14
|
+
*/
|
|
15
|
+
export declare function exportContent(editor: IEditor, mode: 'PlainText', callbacks?: ModelToTextCallbacks): string;
|
|
16
|
+
/**
|
|
17
|
+
* Export plain text using editor's textContent property directly
|
|
18
|
+
* @param editor The editor to get content from
|
|
19
|
+
* @param mode Specify PlainTextFast to get plain text result using textContent property
|
|
20
|
+
* @param options @optional Options for Model to DOM conversion
|
|
21
|
+
*/
|
|
22
|
+
export declare function exportContent(editor: IEditor, mode: 'PlainTextFast'): string;
|
|
@@ -2,16 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.exportContent = void 0;
|
|
4
4
|
var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
|
|
5
|
-
|
|
6
|
-
* Export string content of editor
|
|
7
|
-
* @param editor The editor to get content from
|
|
8
|
-
* @param mode Mode of content to export. It supports:
|
|
9
|
-
* - HTML: Export HTML content. If there are entities, this will cause EntityOperation event with option = 'replaceTemporaryContent' to get a dehydrated entity
|
|
10
|
-
* - PlainText: Export plain text content
|
|
11
|
-
* - PlainTextFast: Export plain text using editor's textContent property directly
|
|
12
|
-
* @param options @optional Options for Model to DOM conversion
|
|
13
|
-
*/
|
|
14
|
-
function exportContent(editor, mode, options) {
|
|
5
|
+
function exportContent(editor, mode, optionsOrCallbacks) {
|
|
15
6
|
if (mode === void 0) { mode = 'HTML'; }
|
|
16
7
|
if (mode == 'PlainTextFast') {
|
|
17
8
|
return editor.getDOMHelper().getTextContent();
|
|
@@ -19,12 +10,12 @@ function exportContent(editor, mode, options) {
|
|
|
19
10
|
else {
|
|
20
11
|
var model = editor.getContentModelCopy('clean');
|
|
21
12
|
if (mode == 'PlainText') {
|
|
22
|
-
return (0, roosterjs_content_model_dom_1.contentModelToText)(model);
|
|
13
|
+
return (0, roosterjs_content_model_dom_1.contentModelToText)(model, undefined /*separator*/, optionsOrCallbacks);
|
|
23
14
|
}
|
|
24
15
|
else {
|
|
25
16
|
var doc = editor.getDocument();
|
|
26
17
|
var div = doc.createElement('div');
|
|
27
|
-
(0, roosterjs_content_model_dom_1.contentModelToDom)(doc, div, model, (0, roosterjs_content_model_dom_1.createModelToDomContext)(undefined /*editorContext*/,
|
|
18
|
+
(0, roosterjs_content_model_dom_1.contentModelToDom)(doc, div, model, (0, roosterjs_content_model_dom_1.createModelToDomContext)(undefined /*editorContext*/, optionsOrCallbacks));
|
|
28
19
|
editor.triggerEvent('extractContentWithDom', { clonedRoot: div }, true /*broadcast*/);
|
|
29
20
|
return div.innerHTML;
|
|
30
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exportContent.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/command/exportContent/exportContent.ts"],"names":[],"mappings":";;;AAAA,2EAIqC;
|
|
1
|
+
{"version":3,"file":"exportContent.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/command/exportContent/exportContent.ts"],"names":[],"mappings":";;;AAAA,2EAIqC;AAoCrC,SAAgB,aAAa,CACzB,MAAe,EACf,IAAgC,EAChC,kBAA4D;IAD5D,qBAAA,EAAA,aAAgC;IAGhC,IAAI,IAAI,IAAI,eAAe,EAAE;QACzB,OAAO,MAAM,CAAC,YAAY,EAAE,CAAC,cAAc,EAAE,CAAC;KACjD;SAAM;QACH,IAAM,KAAK,GAAG,MAAM,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC;QAElD,IAAI,IAAI,IAAI,WAAW,EAAE;YACrB,OAAO,IAAA,gDAAkB,EACrB,KAAK,EACL,SAAS,CAAC,aAAa,EACvB,kBAA0C,CAC7C,CAAC;SACL;aAAM;YACH,IAAM,GAAG,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC;YACjC,IAAM,GAAG,GAAG,GAAG,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;YAErC,IAAA,+CAAiB,EACb,GAAG,EACH,GAAG,EACH,KAAK,EACL,IAAA,qDAAuB,EACnB,SAAS,CAAC,iBAAiB,EAC3B,kBAAsC,CACzC,CACJ,CAAC;YAEF,MAAM,CAAC,YAAY,CAAC,uBAAuB,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;YAEtF,OAAO,GAAG,CAAC,SAAS,CAAC;SACxB;KACJ;AACL,CAAC;AAnCD,sCAmCC","sourcesContent":["import {\n contentModelToDom,\n contentModelToText,\n createModelToDomContext,\n} from 'roosterjs-content-model-dom';\nimport type {\n ExportContentMode,\n IEditor,\n ModelToDomOption,\n ModelToTextCallbacks,\n} from 'roosterjs-content-model-types';\n\n/**\n * Export HTML content. If there are entities, this will cause EntityOperation event with option = 'replaceTemporaryContent' to get a dehydrated entity\n * @param editor The editor to get content from\n * @param mode Specify HTML to get plain text result. This is the default option\n * @param options @optional Options for Model to DOM conversion\n */\nexport function exportContent(editor: IEditor, mode?: 'HTML', options?: ModelToDomOption): string;\n\n/**\n * Export plain text content\n * @param editor The editor to get content from\n * @param mode Specify PlainText to get plain text result\n * @param callbacks @optional Callbacks to customize conversion behavior\n */\nexport function exportContent(\n editor: IEditor,\n mode: 'PlainText',\n callbacks?: ModelToTextCallbacks\n): string;\n\n/**\n * Export plain text using editor's textContent property directly\n * @param editor The editor to get content from\n * @param mode Specify PlainTextFast to get plain text result using textContent property\n * @param options @optional Options for Model to DOM conversion\n */\nexport function exportContent(editor: IEditor, mode: 'PlainTextFast'): string;\n\nexport function exportContent(\n editor: IEditor,\n mode: ExportContentMode = 'HTML',\n optionsOrCallbacks?: ModelToDomOption | ModelToTextCallbacks\n): string {\n if (mode == 'PlainTextFast') {\n return editor.getDOMHelper().getTextContent();\n } else {\n const model = editor.getContentModelCopy('clean');\n\n if (mode == 'PlainText') {\n return contentModelToText(\n model,\n undefined /*separator*/,\n optionsOrCallbacks as ModelToTextCallbacks\n );\n } else {\n const doc = editor.getDocument();\n const div = doc.createElement('div');\n\n contentModelToDom(\n doc,\n div,\n model,\n createModelToDomContext(\n undefined /*editorContext*/,\n optionsOrCallbacks as ModelToDomOption\n )\n );\n\n editor.triggerEvent('extractContentWithDom', { clonedRoot: div }, true /*broadcast*/);\n\n return div.innerHTML;\n }\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mergePasteContent.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/command/paste/mergePasteContent.ts"],"names":[],"mappings":";;;;AAAA,oHAAmH;AACnH,2EAOqC;AAWrC,IAAM,kBAAkB,GAAwC;IAC5D,eAAe,EAAE,EAAE;IACnB,UAAU,EAAE,EAAE;IACd,QAAQ,EAAE,EAAE;IACZ,UAAU,EAAE,EAAE;IACd,MAAM,EAAE,KAAK;IACb,aAAa,EAAE,EAAE;IACjB,UAAU,EAAE,EAAE;IACd,aAAa,EAAE,KAAK;IACpB,wBAAwB,EAAE,EAAE;IAC5B,SAAS,EAAE,EAAE;IACb,SAAS,EAAE,KAAK;CACnB,CAAC;AAEF,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;;GAEG;AACH,SAAgB,kBAAkB,CAAC,KAA2B;IAC1D,OAAO,IAAA,wCAAU,EAAC,KAAK,EAAE,WAAW,CAAC,CAAC;AAC1C,CAAC;AAFD,gDAEC;AAED;;GAEG;AACH,SAAgB,iBAAiB,CAC7B,MAAe,EACf,WAA6B,EAC7B,aAA4B;IAEpB,IAAA,QAAQ,GAAmD,WAAW,SAA9D,EAAE,gBAAgB,GAAiC,WAAW,iBAA5C,EAAE,eAAe,GAAgB,WAAW,gBAA3B,EAAE,SAAS,GAAK,WAAW,UAAhB,CAAiB;IAE/E,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;QACX,IAAI,aAAa,CAAC,gBAAgB,EAAE;YAChC,IAAM,WAAW,GAAG,kBAAkB,CAAC,aA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C;AACN,CAAC;
|
|
1
|
+
{"version":3,"file":"mergePasteContent.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/command/paste/mergePasteContent.ts"],"names":[],"mappings":";;;;AAAA,oHAAmH;AACnH,2EAOqC;AAWrC,IAAM,kBAAkB,GAAwC;IAC5D,eAAe,EAAE,EAAE;IACnB,UAAU,EAAE,EAAE;IACd,QAAQ,EAAE,EAAE;IACZ,UAAU,EAAE,EAAE;IACd,MAAM,EAAE,KAAK;IACb,aAAa,EAAE,EAAE;IACjB,UAAU,EAAE,EAAE;IACd,aAAa,EAAE,KAAK;IACpB,wBAAwB,EAAE,EAAE;IAC5B,SAAS,EAAE,EAAE;IACb,SAAS,EAAE,KAAK;CACnB,CAAC;AAEF,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;;GAEG;AACH,SAAgB,kBAAkB,CAAC,KAA2B;IAC1D,OAAO,IAAA,wCAAU,EAAC,KAAK,EAAE,WAAW,CAAC,CAAC;AAC1C,CAAC;AAFD,gDAEC;AAED;;GAEG;AACH,SAAgB,iBAAiB,CAC7B,MAAe,EACf,WAA6B,EAC7B,aAA4B;IAEpB,IAAA,QAAQ,GAAmD,WAAW,SAA9D,EAAE,gBAAgB,GAAiC,WAAW,iBAA5C,EAAE,eAAe,GAAgB,WAAW,gBAA3B,EAAE,SAAS,GAAK,WAAW,UAAhB,CAAiB;IAE/E,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;QACX,IAAI,aAAa,CAAC,gBAAgB,EAAE;YAChC,IAAM,WAAW,GAAG,kBAAkB,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC;YACvE,KAAK,CAAC,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC;SAC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IACtD,mIAAmI;IACnI,IACI,UAAU,CAAC,MAAM,CAAC,MAAM,IAAI,CAAC;QAC7B,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,KAAK,OAAO;QAC1C,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,KAAK,WAAW;QAC9C,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC;QAC1C,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,WAAW,KAAK,IAAI,EACvD;QACE,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;KAC/B;IACD,6DAA6D;IAC7D,OAAO,UAAU,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,KAAK,OAAO,CAAC;AACxF,CAAC","sourcesContent":["import { createDomToModelContextForSanitizing } from '../createModelFromHtml/createDomToModelContextForSanitizing';\nimport {\n ChangeSource,\n cloneModel,\n domToContentModel,\n getSegmentTextFormat,\n getSelectedSegments,\n mergeModel,\n} from 'roosterjs-content-model-dom';\nimport type {\n BeforePasteEvent,\n ClipboardData,\n CloneModelOptions,\n ContentModelDocument,\n ContentModelSegmentFormat,\n IEditor,\n MergeModelOption,\n} from 'roosterjs-content-model-types';\n\nconst EmptySegmentFormat: Required<ContentModelSegmentFormat> = {\n backgroundColor: '',\n fontFamily: '',\n fontSize: '',\n fontWeight: '',\n italic: false,\n letterSpacing: '',\n lineHeight: '',\n strikethrough: false,\n superOrSubScriptSequence: '',\n textColor: '',\n underline: false,\n};\n\nconst CloneOption: CloneModelOptions = {\n includeCachedElement: (node, type) => (type == 'cache' ? undefined : node),\n};\n\n/**\n * @internal\n */\nexport function cloneModelForPaste(model: ContentModelDocument) {\n return cloneModel(model, CloneOption);\n}\n\n/**\n * @internal\n */\nexport function mergePasteContent(\n editor: IEditor,\n eventResult: BeforePasteEvent,\n clipboardData: ClipboardData\n) {\n const { fragment, domToModelOption, customizedMerge, pasteType } = eventResult;\n\n editor.formatContentModel(\n (model, context) => {\n if (clipboardData.modelBeforePaste) {\n const clonedModel = cloneModelForPaste(clipboardData.modelBeforePaste);\n model.blocks = clonedModel.blocks;\n }\n\n const selectedSegment = getSelectedSegments(model, true /*includeFormatHolder*/)[0];\n const domToModelContext = createDomToModelContextForSanitizing(\n editor.getDocument(),\n undefined /*defaultFormat*/,\n editor.getEnvironment().domToModelSettings.customized,\n domToModelOption\n );\n\n domToModelContext.segmentFormat = selectedSegment\n ? getSegmentTextFormat(selectedSegment)\n : {};\n\n const pasteModel = domToContentModel(fragment, domToModelContext);\n const mergeOption: MergeModelOption = {\n mergeFormat: pasteType == 'mergeFormat' ? 'keepSourceEmphasisFormat' : 'none',\n mergeTable: shouldMergeTable(pasteModel),\n };\n\n const insertPoint = customizedMerge\n ? customizedMerge(model, pasteModel)\n : mergeModel(model, pasteModel, context, mergeOption);\n\n if (insertPoint) {\n context.newPendingFormat = {\n ...EmptySegmentFormat,\n ...model.format,\n ...insertPoint.marker.format,\n };\n }\n\n return true;\n },\n {\n changeSource: ChangeSource.Paste,\n getChangeData: () => clipboardData,\n scrollCaretIntoView: true,\n apiName: 'paste',\n }\n );\n}\n\nfunction shouldMergeTable(pasteModel: ContentModelDocument): boolean | undefined {\n // If model contains a table and a paragraph element after the table with a single BR segment, remove the Paragraph after the table\n if (\n pasteModel.blocks.length == 2 &&\n pasteModel.blocks[0].blockType === 'Table' &&\n pasteModel.blocks[1].blockType === 'Paragraph' &&\n pasteModel.blocks[1].segments.length === 1 &&\n pasteModel.blocks[1].segments[0].segmentType === 'Br'\n ) {\n pasteModel.blocks.splice(1);\n }\n // Only merge table when the document contain a single table.\n return pasteModel.blocks.length === 1 && pasteModel.blocks[0].blockType === 'Table';\n}\n"]}
|
|
@@ -18,7 +18,10 @@ function paste(editor, clipboardData, pasteType) {
|
|
|
18
18
|
editor.focus();
|
|
19
19
|
var trustedHTMLHandler = editor.getTrustedHTMLHandler();
|
|
20
20
|
if (!clipboardData.modelBeforePaste) {
|
|
21
|
-
|
|
21
|
+
editor.formatContentModel(function (model) {
|
|
22
|
+
clipboardData.modelBeforePaste = (0, mergePasteContent_1.cloneModelForPaste)(model);
|
|
23
|
+
return false;
|
|
24
|
+
});
|
|
22
25
|
}
|
|
23
26
|
// 1. Prepare variables
|
|
24
27
|
var doc = createDOMFromHtml(clipboardData.rawHtml, trustedHTMLHandler);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paste.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/command/paste/paste.ts"],"names":[],"mappings":";;;AAAA,yDAA4E;AAC5E,4EAA2E;AAC3E,6DAA4D;AAC5D,mFAAkF;AAClF,uDAAsD;AAQtD;;;;;GAKG;AACH,SAAgB,KAAK,CACjB,MAAe,EACf,aAA4B,EAC5B,SAA+B;;IAA/B,0BAAA,EAAA,oBAA+B;IAE/B,MAAM,CAAC,KAAK,EAAE,CAAC;IAEf,IAAM,kBAAkB,GAAG,MAAM,CAAC,qBAAqB,EAAE,CAAC;IAE1D,IAAI,CAAC,aAAa,CAAC,gBAAgB,EAAE;QACjC,aAAa,CAAC,gBAAgB,GAAG,IAAA,sCAAkB,
|
|
1
|
+
{"version":3,"file":"paste.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/command/paste/paste.ts"],"names":[],"mappings":";;;AAAA,yDAA4E;AAC5E,4EAA2E;AAC3E,6DAA4D;AAC5D,mFAAkF;AAClF,uDAAsD;AAQtD;;;;;GAKG;AACH,SAAgB,KAAK,CACjB,MAAe,EACf,aAA4B,EAC5B,SAA+B;;IAA/B,0BAAA,EAAA,oBAA+B;IAE/B,MAAM,CAAC,KAAK,EAAE,CAAC;IAEf,IAAM,kBAAkB,GAAG,MAAM,CAAC,qBAAqB,EAAE,CAAC;IAE1D,IA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","sourcesContent":["import { cloneModelForPaste, mergePasteContent } from './mergePasteContent';\nimport { convertInlineCss } from '../createModelFromHtml/convertInlineCss';\nimport { createPasteFragment } from './createPasteFragment';\nimport { generatePasteOptionFromPlugins } from './generatePasteOptionFromPlugins';\nimport { retrieveHtmlInfo } from './retrieveHtmlInfo';\nimport type {\n PasteType,\n ClipboardData,\n TrustedHTMLHandler,\n IEditor,\n} from 'roosterjs-content-model-types';\n\n/**\n * Paste into editor using a clipboardData object\n * @param editor The Editor object.\n * @param clipboardData Clipboard data retrieved from clipboard\n * @param pasteType Type of content to paste. @default normal\n */\nexport function paste(\n editor: IEditor,\n clipboardData: ClipboardData,\n pasteType: PasteType = 'normal'\n) {\n editor.focus();\n\n const trustedHTMLHandler = editor.getTrustedHTMLHandler();\n\n if (!clipboardData.modelBeforePaste) {\n editor.formatContentModel(model => {\n clipboardData.modelBeforePaste = cloneModelForPaste(model);\n\n return false;\n });\n }\n\n // 1. Prepare variables\n const doc = createDOMFromHtml(clipboardData.rawHtml, 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 editor.getDocument(),\n clipboardData,\n pasteType,\n (clipboardData.rawHtml == clipboardData.html\n ? doc\n : createDOMFromHtml(clipboardData.html, trustedHTMLHandler)\n )?.body\n );\n\n // 4. Trigger BeforePaste event to allow plugins modify the fragment\n const eventResult = generatePasteOptionFromPlugins(\n editor,\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(editor, eventResult, clipboardData);\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"]}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.announce = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
* Announce the given data
|
|
7
|
+
* @param core The EditorCore object
|
|
8
|
+
* @param announceData Data to announce
|
|
9
|
+
*/
|
|
10
|
+
var announce = function (core, announceData) {
|
|
11
|
+
var _a;
|
|
12
|
+
var text = announceData.text, defaultStrings = announceData.defaultStrings, _b = announceData.formatStrings, formatStrings = _b === void 0 ? [] : _b;
|
|
13
|
+
var announcerStringGetter = core.lifecycle.announcerStringGetter;
|
|
14
|
+
var template = defaultStrings && (announcerStringGetter === null || announcerStringGetter === void 0 ? void 0 : announcerStringGetter(defaultStrings));
|
|
15
|
+
var textToAnnounce = formatString(template || text, formatStrings);
|
|
16
|
+
if (textToAnnounce) {
|
|
17
|
+
var announceContainer = core.lifecycle.announceContainer;
|
|
18
|
+
if (!announceContainer || textToAnnounce == announceContainer.textContent) {
|
|
19
|
+
(_a = announceContainer === null || announceContainer === void 0 ? void 0 : announceContainer.parentElement) === null || _a === void 0 ? void 0 : _a.removeChild(announceContainer);
|
|
20
|
+
announceContainer = createAriaLiveElement(core.physicalRoot.ownerDocument);
|
|
21
|
+
core.lifecycle.announceContainer = announceContainer;
|
|
22
|
+
}
|
|
23
|
+
if (announceContainer) {
|
|
24
|
+
announceContainer.textContent = textToAnnounce;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
exports.announce = announce;
|
|
29
|
+
function formatString(text, formatStrings) {
|
|
30
|
+
if (text == undefined) {
|
|
31
|
+
return text;
|
|
32
|
+
}
|
|
33
|
+
text = text.replace(/\{(\d+)\}/g, function (_, sub) {
|
|
34
|
+
var index = parseInt(sub);
|
|
35
|
+
var replace = formatStrings[index];
|
|
36
|
+
return replace !== null && replace !== void 0 ? replace : '';
|
|
37
|
+
});
|
|
38
|
+
return text;
|
|
39
|
+
}
|
|
40
|
+
function createAriaLiveElement(document) {
|
|
41
|
+
var div = document.createElement('div');
|
|
42
|
+
div.style.clip = 'rect(0px, 0px, 0px, 0px)';
|
|
43
|
+
div.style.clipPath = 'inset(100%)';
|
|
44
|
+
div.style.height = '1px';
|
|
45
|
+
div.style.overflow = 'hidden';
|
|
46
|
+
div.style.position = 'absolute';
|
|
47
|
+
div.style.whiteSpace = 'nowrap';
|
|
48
|
+
div.style.width = '1px';
|
|
49
|
+
div.ariaLive = 'assertive';
|
|
50
|
+
document.body.appendChild(div);
|
|
51
|
+
return div;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=announce.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"announce.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/coreApi/announce/announce.ts"],"names":[],"mappings":";;;AAEA;;;;;GAKG;AACI,IAAM,QAAQ,GAAa,UAAC,IAAI,EAAE,YAAY;;IACzC,IAAA,IAAI,GAAyC,YAAY,KAArD,EAAE,cAAc,GAAyB,YAAY,eAArC,EAAE,KAAuB,YAAY,cAAjB,EAAlB,aAAa,mBAAG,EAAE,KAAA,CAAkB;IAC1D,IAAA,qBAAqB,GAAK,IAAI,CAAC,SAAS,sBAAnB,CAAoB;IACjD,IAAM,QAAQ,GAAG,cAAc,KAAI,qBAAqB,aAArB,qBAAqB,uBAArB,qBAAqB,CAAG,cAAc,CAAC,CAAA,CAAC;IAC3E,IAAM,cAAc,GAAG,YAAY,CAAC,QAAQ,IAAI,IAAI,EAAE,aAAa,CAAC,CAAC;IAErE,IAAI,cAAc,EAAE;QAChB,IAAI,iBAAiB,GAAG,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC;QAEzD,IAAI,CAAC,iBAAiB,IAAI,cAAc,IAAI,iBAAiB,CAAC,WAAW,EAAE;YACvE,MAAA,iBAAiB,aAAjB,iBAAiB,uBAAjB,iBAAiB,CAAE,aAA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G,CAAC,QAAQ,GAAG,WAAW,CAAC;IAE3B,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IAE/B,OAAO,GAAG,CAAC;AACf,CAAC","sourcesContent":["import type { Announce } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n * Announce the given data\n * @param core The EditorCore object\n * @param announceData Data to announce\n */\nexport const announce: Announce = (core, announceData) => {\n const { text, defaultStrings, formatStrings = [] } = announceData;\n const { announcerStringGetter } = core.lifecycle;\n const template = defaultStrings && announcerStringGetter?.(defaultStrings);\n const textToAnnounce = formatString(template || text, formatStrings);\n\n if (textToAnnounce) {\n let announceContainer = core.lifecycle.announceContainer;\n\n if (!announceContainer || textToAnnounce == announceContainer.textContent) {\n announceContainer?.parentElement?.removeChild(announceContainer);\n announceContainer = createAriaLiveElement(core.physicalRoot.ownerDocument);\n\n core.lifecycle.announceContainer = announceContainer;\n }\n\n if (announceContainer) {\n announceContainer.textContent = textToAnnounce;\n }\n }\n};\n\nfunction formatString(text: string | undefined, formatStrings: string[]) {\n if (text == undefined) {\n return text;\n }\n\n text = text.replace(/\\{(\\d+)\\}/g, (_, sub: string) => {\n const index = parseInt(sub);\n const replace = formatStrings[index];\n return replace ?? '';\n });\n\n return text;\n}\n\nfunction createAriaLiveElement(document: Document): HTMLDivElement {\n const div = document.createElement('div');\n\n div.style.clip = 'rect(0px, 0px, 0px, 0px)';\n div.style.clipPath = 'inset(100%)';\n div.style.height = '1px';\n div.style.overflow = 'hidden';\n div.style.position = 'absolute';\n div.style.whiteSpace = 'nowrap';\n div.style.width = '1px';\n div.ariaLive = 'assertive';\n\n document.body.appendChild(div);\n\n return div;\n}\n"]}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.coreApiMap = void 0;
|
|
4
4
|
var addUndoSnapshot_1 = require("./addUndoSnapshot/addUndoSnapshot");
|
|
5
|
+
var announce_1 = require("./announce/announce");
|
|
5
6
|
var attachDomEvent_1 = require("./attachDomEvent/attachDomEvent");
|
|
6
7
|
var createContentModel_1 = require("./createContentModel/createContentModel");
|
|
7
8
|
var createEditorContext_1 = require("./createEditorContext/createEditorContext");
|
|
@@ -36,5 +37,6 @@ exports.coreApiMap = {
|
|
|
36
37
|
switchShadowEdit: switchShadowEdit_1.switchShadowEdit,
|
|
37
38
|
getVisibleViewport: getVisibleViewport_1.getVisibleViewport,
|
|
38
39
|
setEditorStyle: setEditorStyle_1.setEditorStyle,
|
|
40
|
+
announce: announce_1.announce,
|
|
39
41
|
};
|
|
40
42
|
//# sourceMappingURL=coreApiMap.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coreApiMap.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-core/lib/coreApi/coreApiMap.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"coreApiMap.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-core/lib/coreApi/coreApiMap.ts"],"names":[],"mappings":";;;AAAA,qEAAoE;AACpE,gDAA+C;AAC/C,kEAAiE;AACjE,8EAA6E;AAC7E,iFAAgF;AAChF,uCAAsC;AACtC,8EAA6E;AAC7E,qEAAoE;AACpE,8EAA6E;AAC7E,iFAAgF;AAChF,qEAAoE;AACpE,qEAAoE;AACpE,kEAAiE;AACjE,kEAAiE;AACjE,wEAAuE;AACvE,4DAA2D;AAG3D;;;GAGG;AACU,QAAA,UAAU,GAAe;IAClC,kBAAkB,EAAE,uCAAkB;IACtC,mBAAmB,EAAE,yCAAmB;IACxC,kBAAkB,EAAE,uCAAkB;IACtC,eAAe,EAAE,iCAAe;IAChC,cAAc,EAAE,+BAAc;IAE9B,eAAe,EAAE,iCAAe;IAChC,eAAe,EAAE,iCAAe;IAChC,KAAK,EAAE,aAAK;IAEZ,eAAe,EAAE,iCAAe;IAChC,mBAAmB,EAAE,yCAAmB;IAExC,cAAc,EAAE,+BAAc;IAC9B,YAAY,EAAE,2BAAY;IAE1B,gBAAgB,EAAE,mCAAgB;IAClC,kBAAkB,EAAE,uCAAkB;IACtC,cAAc,EAAE,+BAAc;IAE9B,QAAQ,EAAE,mBAAQ;CACrB,CAAC","sourcesContent":["import { addUndoSnapshot } from './addUndoSnapshot/addUndoSnapshot';\nimport { announce } from './announce/announce';\nimport { attachDomEvent } from './attachDomEvent/attachDomEvent';\nimport { createContentModel } from './createContentModel/createContentModel';\nimport { createEditorContext } from './createEditorContext/createEditorContext';\nimport { focus } from './focus/focus';\nimport { formatContentModel } from './formatContentModel/formatContentModel';\nimport { getDOMSelection } from './getDOMSelection/getDOMSelection';\nimport { getVisibleViewport } from './getVisibleViewport/getVisibleViewport';\nimport { restoreUndoSnapshot } from './restoreUndoSnapshot/restoreUndoSnapshot';\nimport { setContentModel } from './setContentModel/setContentModel';\nimport { setDOMSelection } from './setDOMSelection/setDOMSelection';\nimport { setEditorStyle } from './setEditorStyle/setEditorStyle';\nimport { setLogicalRoot } from './setLogicalRoot/setLogicalRoot';\nimport { switchShadowEdit } from './switchShadowEdit/switchShadowEdit';\nimport { triggerEvent } from './triggerEvent/triggerEvent';\nimport type { CoreApiMap } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n * Core API map for Editor\n */\nexport const coreApiMap: CoreApiMap = {\n createContentModel: createContentModel,\n createEditorContext: createEditorContext,\n formatContentModel: formatContentModel,\n setContentModel: setContentModel,\n setLogicalRoot: setLogicalRoot,\n\n getDOMSelection: getDOMSelection,\n setDOMSelection: setDOMSelection,\n focus: focus,\n\n addUndoSnapshot: addUndoSnapshot,\n restoreUndoSnapshot: restoreUndoSnapshot,\n\n attachDomEvent: attachDomEvent,\n triggerEvent: triggerEvent,\n\n switchShadowEdit: switchShadowEdit,\n getVisibleViewport: getVisibleViewport,\n setEditorStyle: setEditorStyle,\n\n announce: announce,\n};\n"]}
|
|
@@ -14,34 +14,33 @@ var createContentModel = function (core, option, selectionOverride) {
|
|
|
14
14
|
var _a;
|
|
15
15
|
// Flush all mutations if any, so that we can get an up-to-date Content Model
|
|
16
16
|
(_a = core.cache.textMutationObserver) === null || _a === void 0 ? void 0 : _a.flushMutations();
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
if (!selectionOverride && (!option || option.tryGetFromCache)) {
|
|
18
|
+
var cachedModel = core.cache.cachedModel;
|
|
19
|
+
if (cachedModel) {
|
|
20
|
+
// When in shadow edit, use a cloned model so we won't pollute the cached one
|
|
21
|
+
return core.lifecycle.shadowEditFragment
|
|
22
|
+
? (0, roosterjs_content_model_dom_1.cloneModel)(cachedModel, { includeCachedElement: true })
|
|
23
|
+
: cachedModel;
|
|
24
|
+
}
|
|
21
25
|
}
|
|
22
|
-
|
|
23
|
-
|
|
26
|
+
var selection = selectionOverride == 'none'
|
|
27
|
+
? undefined
|
|
28
|
+
: selectionOverride || core.api.getDOMSelection(core) || undefined;
|
|
29
|
+
var saveIndex = !option && !selectionOverride;
|
|
30
|
+
var editorContext = core.api.createEditorContext(core, saveIndex);
|
|
31
|
+
var settings = core.environment.domToModelSettings;
|
|
32
|
+
var domToModelContext = option
|
|
33
|
+
? (0, roosterjs_content_model_dom_1.createDomToModelContext)(editorContext, settings.builtIn, settings.customized, option)
|
|
34
|
+
: (0, roosterjs_content_model_dom_1.createDomToModelContextWithConfig)(settings.calculated, editorContext);
|
|
35
|
+
if (selection) {
|
|
36
|
+
domToModelContext.selection = selection;
|
|
24
37
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
var saveIndex = !option && !selectionOverride;
|
|
30
|
-
var editorContext = core.api.createEditorContext(core, saveIndex);
|
|
31
|
-
var settings = core.environment.domToModelSettings;
|
|
32
|
-
var domToModelContext = option
|
|
33
|
-
? (0, roosterjs_content_model_dom_1.createDomToModelContext)(editorContext, settings.builtIn, settings.customized, option)
|
|
34
|
-
: (0, roosterjs_content_model_dom_1.createDomToModelContextWithConfig)(settings.calculated, editorContext);
|
|
35
|
-
if (selection) {
|
|
36
|
-
domToModelContext.selection = selection;
|
|
37
|
-
}
|
|
38
|
-
var model = (0, roosterjs_content_model_dom_1.domToContentModel)(core.logicalRoot, domToModelContext);
|
|
39
|
-
if (saveIndex) {
|
|
40
|
-
core.cache.cachedModel = model;
|
|
41
|
-
(0, updateCachedSelection_1.updateCachedSelection)(core.cache, selection);
|
|
42
|
-
}
|
|
43
|
-
return model;
|
|
38
|
+
var model = (0, roosterjs_content_model_dom_1.domToContentModel)(core.logicalRoot, domToModelContext);
|
|
39
|
+
if (saveIndex) {
|
|
40
|
+
core.cache.cachedModel = model;
|
|
41
|
+
(0, updateCachedSelection_1.updateCachedSelection)(core.cache, selection);
|
|
44
42
|
}
|
|
43
|
+
return model;
|
|
45
44
|
};
|
|
46
45
|
exports.createContentModel = createContentModel;
|
|
47
46
|
//# sourceMappingURL=createContentModel.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createContentModel.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/coreApi/createContentModel/createContentModel.ts"],"names":[],"mappings":";;;AAAA,sFAAqF;AACrF,2EAKqC;AAGrC;;;;;;GAMG;AACI,IAAM,kBAAkB,GAAuB,UAAC,IAAI,EAAE,MAAM,EAAE,iBAAiB;;IAClF,6EAA6E;IAC7E,MAAA,IAAI,CAAC,KAAK,CAAC,oBAAoB,0CAAE,cAAc,EAAE,CAAC;IAElD,IAAI,
|
|
1
|
+
{"version":3,"file":"createContentModel.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/coreApi/createContentModel/createContentModel.ts"],"names":[],"mappings":";;;AAAA,sFAAqF;AACrF,2EAKqC;AAGrC;;;;;;GAMG;AACI,IAAM,kBAAkB,GAAuB,UAAC,IAAI,EAAE,MAAM,EAAE,iBAAiB;;IAClF,6EAA6E;IAC7E,MAAA,IAAI,CAAC,KAAK,CAAC,oBAAoB,0CAAE,cAAc,EAAE,CAAC;IAElD,IA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AAC,IAAI,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;KAChD;IAED,OAAO,KAAK,CAAC;AACjB,CAAC,CAAC;AAtCW,QAAA,kBAAkB,sBAsC7B","sourcesContent":["import { updateCachedSelection } from '../../corePlugin/cache/updateCachedSelection';\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\n if (!selectionOverride && (!option || option.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 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 core.cache.cachedModel = model;\n updateCachedSelection(core.cache, selection);\n }\n\n return model;\n};\n"]}
|
|
@@ -12,15 +12,10 @@ var createEditorContext = function (core, saveIndex) {
|
|
|
12
12
|
var lifecycle = core.lifecycle, format = core.format, darkColorHandler = core.darkColorHandler, logicalRoot = core.logicalRoot, cache = core.cache, domHelper = core.domHelper;
|
|
13
13
|
saveIndex = saveIndex && !core.lifecycle.shadowEditFragment;
|
|
14
14
|
var context = (0, tslib_1.__assign)({ isDarkMode: lifecycle.isDarkMode, defaultFormat: format.defaultFormat, pendingFormat: (_a = format.pendingFormat) !== null && _a !== void 0 ? _a : undefined, darkColorHandler: darkColorHandler, addDelimiterForEntity: true, allowCacheElement: true, domIndexer: saveIndex ? cache.domIndexer : undefined, zoomScale: domHelper.calculateZoomScale() }, (0, getRootComputedStyleForContext_1.getRootComputedStyleForContext)(logicalRoot.ownerDocument));
|
|
15
|
-
|
|
15
|
+
if (core.domHelper.isRightToLeft()) {
|
|
16
|
+
context.isRootRtl = true;
|
|
17
|
+
}
|
|
16
18
|
return context;
|
|
17
19
|
};
|
|
18
20
|
exports.createEditorContext = createEditorContext;
|
|
19
|
-
function checkRootRtl(element, context) {
|
|
20
|
-
var _a;
|
|
21
|
-
var style = (_a = element === null || element === void 0 ? void 0 : element.ownerDocument.defaultView) === null || _a === void 0 ? void 0 : _a.getComputedStyle(element);
|
|
22
|
-
if ((style === null || style === void 0 ? void 0 : style.direction) == 'rtl') {
|
|
23
|
-
context.isRootRtl = true;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
21
|
//# sourceMappingURL=createEditorContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createEditorContext.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/coreApi/createEditorContext/createEditorContext.ts"],"names":[],"mappings":";;;;AAAA,mFAAkF;AAGlF;;;GAGG;AACI,IAAM,mBAAmB,GAAwB,UAAC,IAAI,EAAE,SAAS;;IAC5D,IAAA,SAAS,GAA8D,IAAI,UAAlE,EAAE,MAAM,GAAsD,IAAI,OAA1D,EAAE,gBAAgB,GAAoC,IAAI,iBAAxC,EAAE,WAAW,GAAuB,IAAI,YAA3B,EAAE,KAAK,GAAgB,IAAI,MAApB,EAAE,SAAS,GAAK,IAAI,UAAT,CAAU;IAEpF,SAAS,GAAG,SAAS,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,kBAAkB,CAAC;IAE5D,IAAM,OAAO,2BACT,UAAU,EAAE,SAAS,CAAC,UAAU,EAChC,aAAa,EAAE,MAAM,CAAC,aAAa,EACnC,aAAa,EAAE,MAAA,MAAM,CAAC,aAAa,mCAAI,SAAS,EAChD,gBAAgB,EAAE,gBAAgB,EAClC,qBAAqB,EAAE,IAAI,EAC3B,iBAAiB,EAAE,IAAI,EACvB,UAAU,EAAE,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,EACpD,SAAS,EAAE,SAAS,CAAC,kBAAkB,EAAE,IACtC,IAAA,+DAA8B,EAAC,WAAW,CAAC,aAAa,CAAC,CAC/D,CAAC;IAEF,
|
|
1
|
+
{"version":3,"file":"createEditorContext.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/coreApi/createEditorContext/createEditorContext.ts"],"names":[],"mappings":";;;;AAAA,mFAAkF;AAGlF;;;GAGG;AACI,IAAM,mBAAmB,GAAwB,UAAC,IAAI,EAAE,SAAS;;IAC5D,IAAA,SAAS,GAA8D,IAAI,UAAlE,EAAE,MAAM,GAAsD,IAAI,OAA1D,EAAE,gBAAgB,GAAoC,IAAI,iBAAxC,EAAE,WAAW,GAAuB,IAAI,YAA3B,EAAE,KAAK,GAAgB,IAAI,MAApB,EAAE,SAAS,GAAK,IAAI,UAAT,CAAU;IAEpF,SAAS,GAAG,SAAS,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,kBAAkB,CAAC;IAE5D,IAAM,OAAO,2BACT,UAAU,EAAE,SAAS,CAAC,UAAU,EAChC,aAAa,EAAE,MAAM,CAAC,aAAa,EACnC,aAAa,EAAE,MAAA,MAAM,CAAC,aAAa,mCAAI,SAAS,EAChD,gBAAgB,EAAE,gBAAgB,EAClC,qBAAqB,EAAE,IAAI,EAC3B,iBAAiB,EAAE,IAAI,EACvB,UAAU,EAAE,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,EACpD,SAAS,EAAE,SAAS,CAAC,kBAAkB,EAAE,IACtC,IAAA,+DAA8B,EAAC,WAAW,CAAC,aAAa,CAAC,CAC/D,CAAC;IAEF,IAAI,IAAI,CAAC,SAAS,CAAC,aAAa,EAAE,EAAE;QAChC,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;KAC5B;IAED,OAAO,OAAO,CAAC;AACnB,CAAC,CAAC;AAtBW,QAAA,mBAAmB,uBAsB9B","sourcesContent":["import { getRootComputedStyleForContext } from './getRootComputedStyleForContext';\nimport 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, saveIndex) => {\n const { lifecycle, format, darkColorHandler, logicalRoot, cache, domHelper } = core;\n\n saveIndex = saveIndex && !core.lifecycle.shadowEditFragment;\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: saveIndex ? cache.domIndexer : undefined,\n zoomScale: domHelper.calculateZoomScale(),\n ...getRootComputedStyleForContext(logicalRoot.ownerDocument),\n };\n\n if (core.domHelper.isRightToLeft()) {\n context.isRootRtl = true;\n }\n\n return context;\n};\n"]}
|
|
@@ -15,7 +15,7 @@ var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
|
|
|
15
15
|
*/
|
|
16
16
|
var formatContentModel = function (core, formatter, options, domToModelOptions) {
|
|
17
17
|
var _a;
|
|
18
|
-
var _b = options || {}, apiName = _b.apiName, onNodeCreated = _b.onNodeCreated, getChangeData = _b.getChangeData, changeSource = _b.changeSource, rawEvent = _b.rawEvent, selectionOverride = _b.selectionOverride;
|
|
18
|
+
var _b = options || {}, apiName = _b.apiName, onNodeCreated = _b.onNodeCreated, getChangeData = _b.getChangeData, changeSource = _b.changeSource, rawEvent = _b.rawEvent, selectionOverride = _b.selectionOverride, scrollCaretIntoView = _b.scrollCaretIntoView;
|
|
19
19
|
var model = core.api.createContentModel(core, domToModelOptions, selectionOverride);
|
|
20
20
|
var context = {
|
|
21
21
|
newEntities: [],
|
|
@@ -40,6 +40,11 @@ var formatContentModel = function (core, formatter, options, domToModelOptions)
|
|
|
40
40
|
(_a = core.api.setContentModel(core, model, hasFocus ? undefined : { ignoreSelection: true }, // If editor did not have focus before format, do not set focus after format
|
|
41
41
|
onNodeCreated)) !== null && _a !== void 0 ? _a : undefined;
|
|
42
42
|
handlePendingFormat(core, context, selection);
|
|
43
|
+
if (selection && scrollCaretIntoView) {
|
|
44
|
+
var selectionRoot = (0, roosterjs_content_model_dom_1.getSelectionRootNode)(selection);
|
|
45
|
+
var rootElement = selectionRoot && core.domHelper.findClosestElementAncestor(selectionRoot);
|
|
46
|
+
rootElement === null || rootElement === void 0 ? void 0 : rootElement.scrollIntoView();
|
|
47
|
+
}
|
|
43
48
|
var eventData = {
|
|
44
49
|
eventType: 'contentChanged',
|
|
45
50
|
contentModel: clearModelCache ? undefined : model,
|
|
@@ -76,19 +81,19 @@ var formatContentModel = function (core, formatter, options, domToModelOptions)
|
|
|
76
81
|
}
|
|
77
82
|
handlePendingFormat(core, context, core.api.getDOMSelection(core));
|
|
78
83
|
}
|
|
84
|
+
if (context.announceData) {
|
|
85
|
+
core.api.announce(core, context.announceData);
|
|
86
|
+
}
|
|
79
87
|
};
|
|
80
88
|
exports.formatContentModel = formatContentModel;
|
|
81
89
|
function handleImages(core, context) {
|
|
82
90
|
if (context.newImages.length > 0) {
|
|
83
|
-
var
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
image.format.maxWidth = maxWidth_1 + "px";
|
|
90
|
-
});
|
|
91
|
-
}
|
|
91
|
+
var width = core.domHelper.getClientWidth();
|
|
92
|
+
var minMaxImageSize = 10;
|
|
93
|
+
var maxWidth_1 = Math.max(width, minMaxImageSize);
|
|
94
|
+
context.newImages.forEach(function (image) {
|
|
95
|
+
image.format.maxWidth = maxWidth_1 + "px";
|
|
96
|
+
});
|
|
92
97
|
}
|
|
93
98
|
}
|
|
94
99
|
function handlePendingFormat(core, context, selection) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatContentModel.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/coreApi/formatContentModel/formatContentModel.ts"],"names":[],"mappings":";;;;AAAA,2EAA2D;AAU3D;;;;;;;;;GASG;AACI,IAAM,kBAAkB,GAAuB,UAClD,IAAI,EACJ,SAAS,EACT,OAAO,EACP,iBAAiB;;IAEX,IAAA,KACF,OAAO,IAAI,EAAE,EADT,OAAO,aAAA,EAAE,aAAa,mBAAA,EAAE,aAAa,mBAAA,EAAE,YAAY,kBAAA,EAAE,QAAQ,cAAA,EAAE,iBAAiB,uBACvE,CAAC;IAClB,IAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,kBAAkB,CAAC,IAAI,EAAE,iBAAiB,EAAE,iBAAiB,CAAC,CAAC;IACtF,IAAM,OAAO,GAA8B;QACvC,WAAW,EAAE,EAAE;QACf,eAAe,EAAE,EAAE;QACnB,QAAQ,UAAA;QACR,SAAS,EAAE,EAAE;KAChB,CAAC;IAEF,IAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC;IAE3C,IAAM,OAAO,GAAG,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAClC,IAAA,gBAAgB,GAAwD,OAAO,iBAA/D,EAAE,eAAe,GAAuC,OAAO,gBAA9C,EAAE,YAAY,GAAyB,OAAO,aAAhC,EAAE,kBAAkB,GAAK,OAAO,mBAAZ,CAAa;IAExF,IAAI,OAAO,EAAE;QACT,IAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAA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ntity,\n ContentChangedEvent,\n DOMSelection,\n FormatContentModel,\n FormatContentModelContext,\n EditorCore,\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 EditorCore object\n * @param formatter Formatter function, see ContentModelFormatter\n * @param options More options, see FormatContentModelOptions\n */\nexport const formatContentModel: FormatContentModel = (\n core,\n formatter,\n options,\n domToModelOptions\n) => {\n const { apiName, onNodeCreated, getChangeData, changeSource, rawEvent, selectionOverride } =\n options || {};\n const model = core.api.createContentModel(core, domToModelOptions, selectionOverride);\n const context: FormatContentModelContext = {\n newEntities: [],\n deletedEntities: [],\n rawEvent,\n newImages: [],\n };\n\n const hasFocus = core.domHelper.hasFocus();\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 core.api.addUndoSnapshot(core, !!canUndoByBackspace, entityStates);\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 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.autoCompleteInsertPoint = {\n node: selection.range.startContainer,\n offset: selection.range.startOffset,\n };\n }\n\n if (shouldAddSnapshot) {\n core.api.addUndoSnapshot(core, false /*canUndoByBackspace*/, entityStates);\n } else {\n core.undo.snapshotsManager.hasNewContent = true;\n }\n } finally {\n if (!isNested) {\n core.undo.isNested = false;\n }\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: EditorCore, context: FormatContentModelContext) {\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: EditorCore,\n context: FormatContentModelContext,\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 insertPoint: {\n node: selection.range.startContainer,\n offset: selection.range.startOffset,\n },\n };\n }\n}\n\nfunction getChangedEntities(context: FormatContentModelContext, rawEvent?: Event): 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
|
+
{"version":3,"file":"formatContentModel.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/coreApi/formatContentModel/formatContentModel.ts"],"names":[],"mappings":";;;;AAAA,2EAAiF;AAUjF;;;;;;;;;GASG;AACI,IAAM,kBAAkB,GAAuB,UAClD,IAAI,EACJ,SAAS,EACT,OAAO,EACP,iBAAiB;;IAEX,IAAA,KAQF,OAA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ACf,OAAO,CAAC,gBAAgB,IAAI,UAAU;QAClC,CAAC,CAAC,MAAA,IAAI,CAAC,MAAM,CAAC,aAAa,0CAAE,MAAM;QACnC,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC;IAEnC,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,WAAW,EAAE;gBACT,IAAI,EAAE,SAAS,CAAC,KAAK,CAAC,cAAc;gBACpC,MAAM,EAAE,SAAS,CAAC,KAAK,CAAC,WAAW;aACtC;SACJ,CAAC;KACL;AACL,CAAC;AAED,SAAS,kBAAkB,CAAC,OAAkC,EAAE,QAAgB;IAC5E,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, getSelectionRootNode } from 'roosterjs-content-model-dom';\nimport type {\n ChangedEntity,\n ContentChangedEvent,\n DOMSelection,\n FormatContentModel,\n FormatContentModelContext,\n EditorCore,\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 EditorCore object\n * @param formatter Formatter function, see ContentModelFormatter\n * @param options More options, see FormatContentModelOptions\n */\nexport const formatContentModel: FormatContentModel = (\n core,\n formatter,\n options,\n domToModelOptions\n) => {\n const {\n apiName,\n onNodeCreated,\n getChangeData,\n changeSource,\n rawEvent,\n selectionOverride,\n scrollCaretIntoView,\n } = options || {};\n const model = core.api.createContentModel(core, domToModelOptions, selectionOverride);\n const context: FormatContentModelContext = {\n newEntities: [],\n deletedEntities: [],\n rawEvent,\n newImages: [],\n };\n\n const hasFocus = core.domHelper.hasFocus();\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 core.api.addUndoSnapshot(core, !!canUndoByBackspace, entityStates);\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 (selection && scrollCaretIntoView) {\n const selectionRoot = getSelectionRootNode(selection);\n const rootElement =\n selectionRoot && core.domHelper.findClosestElementAncestor(selectionRoot);\n\n rootElement?.scrollIntoView();\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.autoCompleteInsertPoint = {\n node: selection.range.startContainer,\n offset: selection.range.startOffset,\n };\n }\n\n if (shouldAddSnapshot) {\n core.api.addUndoSnapshot(core, false /*canUndoByBackspace*/, entityStates);\n } else {\n core.undo.snapshotsManager.hasNewContent = true;\n }\n } finally {\n if (!isNested) {\n core.undo.isNested = false;\n }\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 if (context.announceData) {\n core.api.announce(core, context.announceData);\n }\n};\n\nfunction handleImages(core: EditorCore, context: FormatContentModelContext) {\n if (context.newImages.length > 0) {\n const width = core.domHelper.getClientWidth();\n const minMaxImageSize = 10;\n const maxWidth = Math.max(width, minMaxImageSize);\n context.newImages.forEach(image => {\n image.format.maxWidth = `${maxWidth}px`;\n });\n }\n}\n\nfunction handlePendingFormat(\n core: EditorCore,\n context: FormatContentModelContext,\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 insertPoint: {\n node: selection.range.startContainer,\n offset: selection.range.startOffset,\n },\n };\n }\n}\n\nfunction getChangedEntities(context: FormatContentModelContext, rawEvent?: Event): 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"]}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.restoreSnapshotHTML = void 0;
|
|
4
4
|
var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
|
|
5
|
-
var BlockEntityContainer = '_E_EBlockEntityContainer';
|
|
6
5
|
/**
|
|
7
6
|
* @internal
|
|
8
7
|
*/
|
|
@@ -54,22 +53,19 @@ function tryGetEntityElement(entityMap, node) {
|
|
|
54
53
|
var format = (0, roosterjs_content_model_dom_1.parseEntityFormat)(node);
|
|
55
54
|
result = getEntityWrapperForReuse(entityMap, format.id);
|
|
56
55
|
}
|
|
57
|
-
else if (isBlockEntityContainer(node)) {
|
|
56
|
+
else if ((0, roosterjs_content_model_dom_1.isBlockEntityContainer)(node)) {
|
|
58
57
|
result = tryGetEntityFromContainer(node, entityMap);
|
|
59
58
|
}
|
|
60
59
|
}
|
|
61
60
|
return result;
|
|
62
61
|
}
|
|
63
|
-
function isBlockEntityContainer(node) {
|
|
64
|
-
return node.classList.contains(BlockEntityContainer);
|
|
65
|
-
}
|
|
66
62
|
function tryGetEntityFromContainer(element, entityMap) {
|
|
67
63
|
var _a;
|
|
68
64
|
for (var node = element.firstChild; node; node = node.nextSibling) {
|
|
69
65
|
if ((0, roosterjs_content_model_dom_1.isEntityElement)(node) && (0, roosterjs_content_model_dom_1.isNodeOfType)(node, 'ELEMENT_NODE')) {
|
|
70
66
|
var format = (0, roosterjs_content_model_dom_1.parseEntityFormat)(node);
|
|
71
67
|
var parent_1 = (_a = getEntityWrapperForReuse(entityMap, format.id)) === null || _a === void 0 ? void 0 : _a.parentElement;
|
|
72
|
-
return (0, roosterjs_content_model_dom_1.isNodeOfType)(parent_1, 'ELEMENT_NODE') && isBlockEntityContainer(parent_1)
|
|
68
|
+
return (0, roosterjs_content_model_dom_1.isNodeOfType)(parent_1, 'ELEMENT_NODE') && (0, roosterjs_content_model_dom_1.isBlockEntityContainer)(parent_1)
|
|
73
69
|
? parent_1
|
|
74
70
|
: null;
|
|
75
71
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"restoreSnapshotHTML.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/coreApi/restoreUndoSnapshot/restoreSnapshotHTML.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"restoreSnapshotHTML.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/coreApi/restoreUndoSnapshot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AC,IAAI,CAAC,CAAC;YACvC,IAAM,QAAM,GAAG,MAAA,wBAAwB,CAAC,SAAS,EAAE,MAAM,CAAC,EAAE,CAAC,0CAAE,aAAa,CAAC;YAE7E,OAAO,IAAA,0CAAY,EAAC,QAAM,EAAE,cAAc,CAAC,IAAI,IAAA,oDAAsB,EAAC,QAAM,CAAC;gBACzE,CAAC,CAAC,QAAM;gBACR,CAAC,CAAC,IAAI,CAAC;SACd;KACJ;IAED,OAAO,IAAI,CAAC;AAChB,CAAC;AAED,SAAS,wBAAwB,CAC7B,SAA0C,EAC1C,QAA4B;IAE5B,IAAM,KAAK,GAAG,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAEzD,OAAO,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,UAAU,EAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC;AACpD,CAAC","sourcesContent":["import {\n getAllEntityWrappers,\n isBlockEntityContainer,\n isEntityElement,\n isNodeOfType,\n parseEntityFormat,\n reuseCachedElement,\n} from 'roosterjs-content-model-dom';\nimport type { Snapshot, EditorCore, KnownEntityItem } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function restoreSnapshotHTML(core: EditorCore, snapshot: Snapshot) {\n const {\n physicalRoot,\n entity: { entityMap },\n } = core;\n let refNode: Node | null = physicalRoot.firstChild;\n\n const body = new DOMParser().parseFromString(\n core.trustedHTMLHandler?.(snapshot.html) ?? snapshot.html,\n 'text/html'\n ).body;\n\n for (let currentNode = body.firstChild; currentNode; ) {\n const next = currentNode.nextSibling;\n const originalEntityElement = tryGetEntityElement(entityMap, currentNode);\n\n if (originalEntityElement) {\n refNode = reuseCachedElement(physicalRoot, originalEntityElement, refNode);\n } else {\n physicalRoot.insertBefore(currentNode, refNode);\n\n if (isNodeOfType(currentNode, 'ELEMENT_NODE')) {\n const childEntities = getAllEntityWrappers(currentNode);\n\n childEntities.forEach(element => {\n const wrapper = tryGetEntityElement(entityMap, element);\n\n if (wrapper) {\n if (wrapper == refNode) {\n // In case the node we are moving is just the ref node,\n // We create a temporary clone and insert it before the refNode, and use this cloned node as refNode\n // After replaceChild(), the original refNode will be moved away\n const markerNode = wrapper.cloneNode();\n\n physicalRoot.insertBefore(markerNode, refNode);\n refNode = markerNode;\n }\n\n element.parentNode?.replaceChild(wrapper, element);\n }\n });\n }\n }\n currentNode = next;\n }\n\n while (refNode) {\n const next = refNode.nextSibling;\n\n refNode.parentNode?.removeChild(refNode);\n refNode = next;\n }\n}\n\nfunction tryGetEntityElement(\n entityMap: Record<string, KnownEntityItem>,\n node: Node\n): HTMLElement | null {\n let result: HTMLElement | null = null;\n\n if (isNodeOfType(node, 'ELEMENT_NODE')) {\n if (isEntityElement(node)) {\n const format = parseEntityFormat(node);\n\n result = getEntityWrapperForReuse(entityMap, format.id);\n } else if (isBlockEntityContainer(node)) {\n result = tryGetEntityFromContainer(node, entityMap);\n }\n }\n\n return result;\n}\n\nfunction tryGetEntityFromContainer(\n element: HTMLElement,\n entityMap: Record<string, KnownEntityItem>\n): HTMLElement | null {\n for (let node = element.firstChild; node; node = node.nextSibling) {\n if (isEntityElement(node) && isNodeOfType(node, 'ELEMENT_NODE')) {\n const format = parseEntityFormat(node);\n const parent = getEntityWrapperForReuse(entityMap, format.id)?.parentElement;\n\n return isNodeOfType(parent, 'ELEMENT_NODE') && isBlockEntityContainer(parent)\n ? parent\n : null;\n }\n }\n\n return null;\n}\n\nfunction getEntityWrapperForReuse(\n entityMap: Record<string, KnownEntityItem>,\n entityId: string | undefined\n): HTMLElement | null {\n const entry = entityId ? entityMap[entityId] : undefined;\n\n return entry?.canPersist ? entry.element : null;\n}\n"]}
|
|
@@ -14,7 +14,7 @@ var TABLE_ID = 'table';
|
|
|
14
14
|
var DEFAULT_SELECTION_BORDER_COLOR = '#DB626C';
|
|
15
15
|
var TABLE_CSS_RULE = 'background-color:#C6C6C6!important;';
|
|
16
16
|
var CARET_CSS_RULE = 'caret-color: transparent';
|
|
17
|
-
var TRANSPARENT_SELECTION_CSS_RULE = 'background-color: transparent !important';
|
|
17
|
+
var TRANSPARENT_SELECTION_CSS_RULE = 'background-color: transparent !important;';
|
|
18
18
|
var SELECTION_SELECTOR = '*::selection';
|
|
19
19
|
/**
|
|
20
20
|
* @internal
|
|
@@ -32,9 +32,12 @@ var setDOMSelection = function (core, selection, skipSelectionChangedEvent) {
|
|
|
32
32
|
try {
|
|
33
33
|
switch (selection === null || selection === void 0 ? void 0 : selection.type) {
|
|
34
34
|
case 'image':
|
|
35
|
-
var image = selection.image;
|
|
36
|
-
core.selection.selection =
|
|
37
|
-
|
|
35
|
+
var image = ensureImageHasSpanParent(selection.image);
|
|
36
|
+
core.selection.selection = {
|
|
37
|
+
type: 'image',
|
|
38
|
+
image: image,
|
|
39
|
+
};
|
|
40
|
+
core.api.setEditorStyle(core, DOM_SELECTION_CSS_KEY, "outline-style:auto!important; outline-color:" + (core.selection.imageSelectionBorderColor || DEFAULT_SELECTION_BORDER_COLOR) + "!important;", ["span:has(>img#" + (0, ensureUniqueId_1.ensureUniqueId)(image, IMAGE_ID) + ")"]);
|
|
38
41
|
core.api.setEditorStyle(core, HIDE_SELECTION_CSS_KEY, TRANSPARENT_SELECTION_CSS_RULE, [SELECTION_SELECTOR]);
|
|
39
42
|
setRangeSelection(doc, image, false /* collapse */);
|
|
40
43
|
break;
|
|
@@ -165,4 +168,16 @@ function setRangeSelection(doc, element, collapse) {
|
|
|
165
168
|
(0, addRangeToSelection_1.addRangeToSelection)(doc, range, isReverted);
|
|
166
169
|
}
|
|
167
170
|
}
|
|
171
|
+
function ensureImageHasSpanParent(image) {
|
|
172
|
+
var parent = image.parentElement;
|
|
173
|
+
if (parent &&
|
|
174
|
+
(0, roosterjs_content_model_dom_1.isNodeOfType)(parent, 'ELEMENT_NODE') &&
|
|
175
|
+
(0, roosterjs_content_model_dom_1.isElementOfType)(parent, 'span') &&
|
|
176
|
+
parent.firstChild == image &&
|
|
177
|
+
parent.lastChild == image) {
|
|
178
|
+
return image;
|
|
179
|
+
}
|
|
180
|
+
(0, roosterjs_content_model_dom_1.wrap)(image.ownerDocument, image, 'span');
|
|
181
|
+
return image;
|
|
182
|
+
}
|
|
168
183
|
//# sourceMappingURL=setDOMSelection.js.map
|