roosterjs-content-model-core 9.50.1 → 9.51.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 +3 -3
- package/lib/command/exportContent/exportContent.js +2 -2
- package/lib/command/exportContent/exportContent.js.map +1 -1
- package/lib/coreApi/createEditorContext/createEditorContext.js +2 -2
- package/lib/coreApi/createEditorContext/createEditorContext.js.map +1 -1
- package/lib/editor/core/DOMHelperImpl.d.ts +3 -0
- package/lib/editor/core/DOMHelperImpl.js +3 -9
- package/lib/editor/core/DOMHelperImpl.js.map +1 -1
- package/lib/editor/core/createEditorCore.js +2 -4
- package/lib/editor/core/createEditorCore.js.map +1 -1
- package/lib-amd/command/exportContent/exportContent.d.ts +3 -3
- package/lib-amd/command/exportContent/exportContent.js +2 -2
- package/lib-amd/command/exportContent/exportContent.js.map +1 -1
- package/lib-amd/coreApi/createEditorContext/createEditorContext.js +2 -2
- package/lib-amd/coreApi/createEditorContext/createEditorContext.js.map +1 -1
- package/lib-amd/editor/core/DOMHelperImpl.d.ts +3 -0
- package/lib-amd/editor/core/DOMHelperImpl.js +3 -9
- package/lib-amd/editor/core/DOMHelperImpl.js.map +1 -1
- package/lib-amd/editor/core/createEditorCore.js +2 -4
- package/lib-amd/editor/core/createEditorCore.js.map +1 -1
- package/lib-mjs/command/exportContent/exportContent.d.ts +3 -3
- package/lib-mjs/command/exportContent/exportContent.js +2 -2
- package/lib-mjs/command/exportContent/exportContent.js.map +1 -1
- package/lib-mjs/coreApi/createEditorContext/createEditorContext.js +2 -2
- package/lib-mjs/coreApi/createEditorContext/createEditorContext.js.map +1 -1
- package/lib-mjs/editor/core/DOMHelperImpl.d.ts +3 -0
- package/lib-mjs/editor/core/DOMHelperImpl.js +3 -9
- package/lib-mjs/editor/core/DOMHelperImpl.js.map +1 -1
- package/lib-mjs/editor/core/createEditorCore.js +2 -4
- package/lib-mjs/editor/core/createEditorCore.js.map +1 -1
- package/package.json +3 -3
|
@@ -2,7 +2,7 @@ import type { IEditor, ModelToDomOption, ModelToTextCallbacks } from 'roosterjs-
|
|
|
2
2
|
/**
|
|
3
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 Specify HTML to get HTML.
|
|
5
|
+
* @param mode Specify HTML to get HTML.
|
|
6
6
|
* @param options @optional Options for Model to DOM conversion
|
|
7
7
|
*/
|
|
8
8
|
export declare function exportContent(editor: IEditor, mode?: 'HTML', options?: ModelToDomOption): string;
|
|
@@ -10,9 +10,9 @@ export declare function exportContent(editor: IEditor, mode?: 'HTML', options?:
|
|
|
10
10
|
* Export HTML content. If there are entities, this will cause EntityOperation event with option = 'replaceTemporaryContent' to get a dehydrated entity.
|
|
11
11
|
* This is a fast version, it retrieve HTML content directly from editor without going through content model conversion.
|
|
12
12
|
* @param editor The editor to get content from
|
|
13
|
-
* @param mode Specify HTMLFast to get HTML result.
|
|
13
|
+
* @param mode Specify HTMLFast to get HTML result. This is the default option
|
|
14
14
|
*/
|
|
15
|
-
export declare function exportContent(editor: IEditor, mode
|
|
15
|
+
export declare function exportContent(editor: IEditor, mode?: 'HTMLFast'): string;
|
|
16
16
|
/**
|
|
17
17
|
* Export plain text content
|
|
18
18
|
* @param editor The editor to get content from
|
|
@@ -5,7 +5,7 @@ var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
|
|
|
5
5
|
// Here I didn't add 'HTMLFast' to ExportContentMode type because it will make this a breaking change and EditorAdapter will see build time error without bumping version
|
|
6
6
|
// Once we are confident that 'HTMLFast' is stable, we can fully switch 'HTML' to use the 'HTMLFast' approach
|
|
7
7
|
function exportContent(editor, mode, optionsOrCallbacks) {
|
|
8
|
-
if (mode === void 0) { mode = '
|
|
8
|
+
if (mode === void 0) { mode = 'HTMLFast'; }
|
|
9
9
|
var model;
|
|
10
10
|
switch (mode) {
|
|
11
11
|
case 'PlainTextFast':
|
|
@@ -14,6 +14,7 @@ function exportContent(editor, mode, optionsOrCallbacks) {
|
|
|
14
14
|
model = editor.getContentModelCopy('clean');
|
|
15
15
|
return (0, roosterjs_content_model_dom_1.contentModelToText)(model, undefined /*separator*/, optionsOrCallbacks);
|
|
16
16
|
case 'HTMLFast':
|
|
17
|
+
default:
|
|
17
18
|
var clonedRoot = editor.getDOMHelper().getClonedRoot();
|
|
18
19
|
if (editor.isDarkMode()) {
|
|
19
20
|
(0, roosterjs_content_model_dom_1.transformColor)(clonedRoot, false /*includeSelf*/, 'darkToLight', editor.getColorManager(), {
|
|
@@ -22,7 +23,6 @@ function exportContent(editor, mode, optionsOrCallbacks) {
|
|
|
22
23
|
}
|
|
23
24
|
return getHTMLFromDOM(editor, clonedRoot);
|
|
24
25
|
case 'HTML':
|
|
25
|
-
default:
|
|
26
26
|
model = editor.getContentModelCopy('clean');
|
|
27
27
|
var doc = editor.getDocument();
|
|
28
28
|
var div = doc.createElement('div');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exportContent.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/command/exportContent/exportContent.ts"],"names":[],"mappings":";;;AAAA,2EAKqC;AA6CrC,yKAAyK;AACzK,6GAA6G;AAC7G,SAAgB,aAAa,CACzB,MAAe,EACf,
|
|
1
|
+
{"version":3,"file":"exportContent.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/command/exportContent/exportContent.ts"],"names":[],"mappings":";;;AAAA,2EAKqC;AA6CrC,yKAAyK;AACzK,6GAA6G;AAC7G,SAAgB,aAAa,CACzB,MAAe,EACf,IAAiD,EACjD,kBAA4D;IAD5D,qBAAA,EAAA,iBAAiD;IAGjD,IAAI,KAA2B,CAAC;IAEhC,QAAQ,IAAI,EAAE;QACV,KAAK,eAAe;YAChB,OAAO,MAAM,CAAC,YAAY,EAAE,CAAC,cAAc,EAAE,CAAC;QAClD,KAAK,WAAW;YACZ,KAAK,GAAG,MAAM,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC;YAE5C,OAAO,IAAA,gDAAkB,EACrB,KAAK,EACL,SAAS,CAAC,aAAa,EACvB,kBAA0C,CAC7C,CAAC;QAEN,KAAK,UAAU,CAAC;QAChB;YACI,IAAM,UAAU,GAAG,MAAM,CAAC,YAAY,EAAE,CAAC,aAAa,EAAE,CAAC;YAEzD,IAAI,MAAM,CAAC,UAAU,EAAE,EAAE;gBACrB,IAAA,4CAAc,EACV,UAAU,EACV,KAAK,CAAC,eAAe,EACrB,aAAa,EACb,MAAM,CAAC,eAAe,EAAE,EACxB;oBACI,YAAY,EAAE,MAAM,CAAC,4BAA4B,CAC7C,4BAA4B,CAC/B;iBACJ,CACJ,CAAC;aACL;YAED,OAAO,cAAc,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;QAE9C,KAAK,MAAM;YACP,KAAK,GAAG,MAAM,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC;YAE5C,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,OAAO,cAAc,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KAC1C;AACL,CAAC;AAzDD,sCAyDC;AAED,SAAS,cAAc,CAAC,MAAe,EAAE,IAAiB;IACtD,MAAM,CAAC,YAAY,CAAC,uBAAuB,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IAEvF,OAAO,IAAI,CAAC,SAAS,CAAC;AAC1B,CAAC","sourcesContent":["import {\n contentModelToDom,\n contentModelToText,\n createModelToDomContext,\n transformColor,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelDocument,\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 HTML.\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 HTML content. If there are entities, this will cause EntityOperation event with option = 'replaceTemporaryContent' to get a dehydrated entity.\n * This is a fast version, it retrieve HTML content directly from editor without going through content model conversion.\n * @param editor The editor to get content from\n * @param mode Specify HTMLFast to get HTML result. This is the default option\n */\nexport function exportContent(editor: IEditor, mode?: 'HTMLFast'): 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\n// Here I didn't add 'HTMLFast' to ExportContentMode type because it will make this a breaking change and EditorAdapter will see build time error without bumping version\n// Once we are confident that 'HTMLFast' is stable, we can fully switch 'HTML' to use the 'HTMLFast' approach\nexport function exportContent(\n editor: IEditor,\n mode: ExportContentMode | 'HTMLFast' = 'HTMLFast',\n optionsOrCallbacks?: ModelToDomOption | ModelToTextCallbacks\n): string {\n let model: ContentModelDocument;\n\n switch (mode) {\n case 'PlainTextFast':\n return editor.getDOMHelper().getTextContent();\n case 'PlainText':\n model = editor.getContentModelCopy('clean');\n\n return contentModelToText(\n model,\n undefined /*separator*/,\n optionsOrCallbacks as ModelToTextCallbacks\n );\n\n case 'HTMLFast':\n default:\n const clonedRoot = editor.getDOMHelper().getClonedRoot();\n\n if (editor.isDarkMode()) {\n transformColor(\n clonedRoot,\n false /*includeSelf*/,\n 'darkToLight',\n editor.getColorManager(),\n {\n tableBorders: editor.isExperimentalFeatureEnabled(\n 'TransformTableBorderColors'\n ),\n }\n );\n }\n\n return getHTMLFromDOM(editor, clonedRoot);\n\n case 'HTML':\n model = editor.getContentModelCopy('clean');\n\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 return getHTMLFromDOM(editor, div);\n }\n}\n\nfunction getHTMLFromDOM(editor: IEditor, root: HTMLElement): string {\n editor.triggerEvent('extractContentWithDom', { clonedRoot: root }, true /*broadcast*/);\n\n return root.innerHTML;\n}\n"]}
|
|
@@ -8,10 +8,10 @@ var getRootComputedStyleForContext_1 = require("./getRootComputedStyleForContext
|
|
|
8
8
|
* Create a EditorContext object used by ContentModel API
|
|
9
9
|
*/
|
|
10
10
|
var createEditorContext = function (core, saveIndex) {
|
|
11
|
-
var _a, _b
|
|
11
|
+
var _a, _b;
|
|
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
|
-
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,
|
|
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(), experimentalFeatures: (_b = core.experimentalFeatures) !== null && _b !== void 0 ? _b : [], paragraphMap: core.cache.paragraphMap, editorViewWidth: domHelper.getClientWidth() }, (0, getRootComputedStyleForContext_1.getRootComputedStyleForContext)(logicalRoot.ownerDocument));
|
|
15
15
|
if (core.domHelper.isRightToLeft()) {
|
|
16
16
|
context.isRootRtl = true;
|
|
17
17
|
}
|
|
@@ -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,
|
|
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,EACzC,oBAAoB,EAAE,MAAA,IAAI,CAAC,oBAAoB,mCAAI,EAAE,EACrD,YAAY,EAAE,IAAI,CAAC,KAAK,CAAC,YAAY,EACrC,eAAe,EAAE,SAAS,CAAC,cAAc,EAAE,IACxC,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;AAzBW,QAAA,mBAAmB,uBAyB9B","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 experimentalFeatures: core.experimentalFeatures ?? [],\n paragraphMap: core.cache.paragraphMap,\n editorViewWidth: domHelper.getClientWidth(),\n ...getRootComputedStyleForContext(logicalRoot.ownerDocument),\n };\n\n if (core.domHelper.isRightToLeft()) {\n context.isRootRtl = true;\n }\n\n return context;\n};\n"]}
|
|
@@ -5,7 +5,6 @@ var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
|
|
|
5
5
|
var DOMHelperImpl = /** @class */ (function () {
|
|
6
6
|
function DOMHelperImpl(contentDiv, options) {
|
|
7
7
|
this.contentDiv = contentDiv;
|
|
8
|
-
this.options = options;
|
|
9
8
|
}
|
|
10
9
|
DOMHelperImpl.prototype.queryElements = function (selector) {
|
|
11
10
|
return (0, roosterjs_content_model_dom_1.toArray)(this.contentDiv.querySelectorAll(selector));
|
|
@@ -94,14 +93,9 @@ var DOMHelperImpl = /** @class */ (function () {
|
|
|
94
93
|
* Get a deep cloned root element
|
|
95
94
|
*/
|
|
96
95
|
DOMHelperImpl.prototype.getClonedRoot = function () {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
return clone;
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
return this.contentDiv.cloneNode(true /*deep*/);
|
|
104
|
-
}
|
|
96
|
+
var doc = this.contentDiv.ownerDocument.implementation.createHTMLDocument();
|
|
97
|
+
var clone = doc.importNode(this.contentDiv, true /*deep*/);
|
|
98
|
+
return clone;
|
|
105
99
|
};
|
|
106
100
|
/**
|
|
107
101
|
* Get format of the container element
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DOMHelperImpl.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/editor/core/DOMHelperImpl.ts"],"names":[],"mappings":";;;AAAA,2EAOqC;AAcrC;IACI,uBAAoB,UAAuB,EAAU,OAA4B;QAA7D,eAAU,GAAV,UAAU,CAAa;QAAU,YAAO,GAAP,OAAO,CAAqB;IAAG,CAAC;IAErF,qCAAa,GAAb,UAAc,QAAgB;QAC1B,OAAO,IAAA,qCAAO,EAAC,IAAI,CAAC,UAAU,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAkB,CAAC;IAChF,CAAC;IAED,sCAAc,GAAd;QACI,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,IAAI,EAAE,CAAC;IAC7C,CAAC;IAED,sCAAc,GAAd,UAAe,IAAU,EAAE,WAAqB;QAC5C,OAAO,WAAW,IAAI,IAAI,IAAI,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC3F,CAAC;IAED,0CAAkB,GAAlB;;QACI,IAAM,aAAa,GAAG,CAAA,MAAA,IAAI,CAAC,UAAU,CAAC,qBAAqB,EAAE,0CAAE,KAAK,KAAI,CAAC,CAAC;QAC1E,IAAM,WAAW,GAAG,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC;QAEhD,OAAO,WAAW,GAAG,CAAC,IAAI,aAAa,GAAG,CAAC;YACvC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,aAAa,GAAG,WAAW,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG;YACvD,CAAC,CAAC,CAAC,CAAC;IACZ,CAAC;IAED,uCAAe,GAAf,UAAgB,IAAY,EAAE,KAAoB;QAC9C,IAAI,KAAK,KAAK,IAAI,EAAE;YAChB,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC,I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SAAkB;QAChE,OAAO,IAAA,6CAAe,EAAC,IAAI,CAAC,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC;IAC/F,CAAC;IACL,oBAAC;AAAD,CAAC,AAvKD,IAuKC;AAED;;GAEG;AACH,SAAgB,eAAe,CAC3B,UAAuB,EACvB,OAAiC;IAAjC,wBAAA,EAAA,YAAiC;IAEjC,OAAO,IAAI,aAAa,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;AAClD,CAAC;AALD,0CAKC","sourcesContent":["import {\n getColor,\n getRangesByText,\n isBlockElement,\n isNodeOfType,\n parseValueWithUnit,\n toArray,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelSegmentFormat,\n DarkColorHandler,\n DOMHelper,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport interface DOMHelperImplOption {\n cloneIndependentRoot?: boolean;\n}\n\nclass DOMHelperImpl implements DOMHelper {\n constructor(private contentDiv: HTMLElement, private options: DOMHelperImplOption) {}\n\n queryElements(selector: string): HTMLElement[] {\n return toArray(this.contentDiv.querySelectorAll(selector)) as HTMLElement[];\n }\n\n getTextContent(): string {\n return this.contentDiv.textContent || '';\n }\n\n isNodeInEditor(node: Node, excludeRoot?: boolean): boolean {\n return excludeRoot && node == this.contentDiv ? false : this.contentDiv.contains(node);\n }\n\n calculateZoomScale(): number {\n const originalWidth = this.contentDiv.getBoundingClientRect()?.width || 0;\n const visualWidth = this.contentDiv.offsetWidth;\n\n return visualWidth > 0 && originalWidth > 0\n ? Math.round((originalWidth / visualWidth) * 100) / 100\n : 1;\n }\n\n setDomAttribute(name: string, value: string | null) {\n if (value === null) {\n this.contentDiv.removeAttribute(name);\n } else {\n this.contentDiv.setAttribute(name, value);\n }\n }\n\n getDomAttribute(name: string): string | null {\n return this.contentDiv.getAttribute(name);\n }\n\n getDomStyle<T extends keyof CSSStyleDeclaration>(style: T): CSSStyleDeclaration[T] {\n return this.contentDiv.style[style];\n }\n\n findClosestElementAncestor(startFrom: Node, selector?: string): HTMLElement | null {\n const startElement = isNodeOfType(startFrom, 'ELEMENT_NODE')\n ? startFrom\n : startFrom.parentElement;\n const closestElement = selector\n ? (startElement?.closest(selector) as HTMLElement | null)\n : startElement;\n\n return closestElement &&\n this.isNodeInEditor(closestElement) &&\n closestElement != this.contentDiv\n ? closestElement\n : null;\n }\n\n /**\n * Find the closest block element ancestor from the given node within current editing scope\n * @param startFrom The node to start the search from\n * @returns The closest block element ancestor\n */\n findClosestBlockElement(startFrom: Node): HTMLElement {\n let node: Node | null = startFrom;\n\n while (node && this.isNodeInEditor(node)) {\n if (isNodeOfType(node, 'ELEMENT_NODE') && isBlockElement(node)) {\n return node;\n }\n\n node = node.parentElement;\n }\n\n return this.contentDiv;\n }\n\n hasFocus(): boolean {\n const activeElement = this.contentDiv.ownerDocument.activeElement;\n return !!(activeElement && this.contentDiv.contains(activeElement));\n }\n\n /**\n * Check if the root element is in RTL mode\n */\n isRightToLeft(): boolean {\n const contentDiv = this.contentDiv;\n const style = contentDiv.ownerDocument.defaultView?.getComputedStyle(contentDiv);\n\n return style?.direction == 'rtl';\n }\n\n /**\n * Get the width of the editable area of the editor content div\n */\n getClientWidth(): number {\n const contentDiv = this.contentDiv;\n const style = contentDiv.ownerDocument.defaultView?.getComputedStyle(contentDiv);\n const paddingLeft = parseValueWithUnit(style?.paddingLeft);\n const paddingRight = parseValueWithUnit(style?.paddingRight);\n return this.contentDiv.clientWidth - (paddingLeft + paddingRight);\n }\n\n /**\n * Get a deep cloned root element\n */\n getClonedRoot(): HTMLElement {\n if (this.options.cloneIndependentRoot) {\n const doc = this.contentDiv.ownerDocument.implementation.createHTMLDocument();\n const clone = doc.importNode(this.contentDiv, true /*deep*/);\n\n return clone;\n } else {\n return this.contentDiv.cloneNode(true /*deep*/) as HTMLElement;\n }\n }\n\n /**\n * Get format of the container element\n * @param isInDarkMode Optional flag to indicate if the environment is in dark mode\n * @param darkColorHandler Optional DarkColorHandler to retrieve dark mode colors\n */\n getContainerFormat(\n isInDarkMode?: boolean,\n darkColorHandler?: DarkColorHandler\n ): ContentModelSegmentFormat {\n const window = this.contentDiv.ownerDocument.defaultView;\n\n const style = window?.getComputedStyle(this.contentDiv);\n\n return style\n ? {\n fontSize: style.fontSize,\n fontFamily: style.fontFamily,\n fontWeight: style.fontWeight,\n textColor: getColor(\n this.contentDiv,\n false /*isBackgroundColor*/,\n !!isInDarkMode,\n darkColorHandler,\n style.color\n ),\n backgroundColor: getColor(\n this.contentDiv,\n true /*isBackgroundColor*/,\n !!isInDarkMode,\n darkColorHandler,\n style.backgroundColor\n ),\n italic: style.fontStyle == 'italic',\n letterSpacing: style.letterSpacing,\n lineHeight: style.lineHeight,\n strikethrough: style.textDecoration?.includes('line-through'),\n superOrSubScriptSequence: style.verticalAlign,\n underline: style.textDecoration?.includes('underline'),\n }\n : {};\n }\n\n /**\n * Get text ranges by searching for a specific text, with options to match case and whole word.\n * This will only search within editable elements.\n * @param text The text to search for\n * @param matchCase Whether to match case\n * @param wholeWord Whether to match whole word\n * @returns An array of Ranges that match the search criteria\n */\n getRangesByText(text: string, matchCase: boolean, wholeWord: boolean): Range[] {\n return getRangesByText(this.contentDiv, text, matchCase, wholeWord, true /*editableOnly*/);\n }\n}\n\n/**\n * @internal Create new instance of DOMHelper\n */\nexport function createDOMHelper(\n contentDiv: HTMLElement,\n options: DOMHelperImplOption = {}\n): DOMHelper {\n return new DOMHelperImpl(contentDiv, options);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"DOMHelperImpl.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/editor/core/DOMHelperImpl.ts"],"names":[],"mappings":";;;AAAA,2EAOqC;AAiBrC;IACI,uBAAoB,UAAuB,EAAE,OAA6B;QAAtD,eAAU,GAAV,UAAU,CAAa;IAAkC,CAAC;IAE9E,qCAAa,GAAb,UAAc,QAAgB;QAC1B,OAAO,IAAA,qCAAO,EAAC,I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,UAAU;gBAC5B,SAAS,EAAE,IAAA,sCAAQ,EACf,IAAI,CAAC,UAAU,EACf,KAAK,CAAC,qBAAqB,EAC3B,CAAC,CAAC,YAAY,EACd,gBAAgB,EAChB,KAAK,CAAC,KAAK,CACd;gBACD,eAAe,EAAE,IAAA,sCAAQ,EACrB,IAAI,CAAC,UAAU,EACf,IAAI,CAAC,qBAAqB,EAC1B,CAAC,CAAC,YAAY,EACd,gBAAgB,EAChB,KAAK,CAAC,eAAe,CACxB;gBACD,MAAM,EAAE,KAAK,CAAC,SAAS,IAAI,QAAQ;gBACnC,aAAa,EAAE,KAAK,CAAC,aAAa;gBAClC,UAAU,EAAE,KAAK,CAAC,UAAU;gBAC5B,aAAa,EAAE,MAAA,KAAK,CAAC,cAAc,0CAAE,QAAQ,CAAC,cAAc,CAAC;gBAC7D,wBAAwB,EAAE,KAAK,CAAC,aAAa;gBAC7C,SAAS,EAAE,MAAA,KAAK,CAAC,cAAc,0CAAE,QAAQ,CAAC,WAAW,CAAC;aACzD;YACH,CAAC,CAAC,EAAE,CAAC;IACb,CAAC;IAED;;;;;;;OAOG;IACH,uCAAe,GAAf,UAAgB,IAAY,EAAE,SAAkB,EAAE,SAAkB;QAChE,OAAO,IAAA,6CAAe,EAAC,IAAI,CAAC,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC;IAC/F,CAAC;IACL,oBAAC;AAAD,CAAC,AAnKD,IAmKC;AAED;;GAEG;AACH,SAAgB,eAAe,CAC3B,UAAuB,EACvB,OAAiC;IAAjC,wBAAA,EAAA,YAAiC;IAEjC,OAAO,IAAI,aAAa,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;AAClD,CAAC;AALD,0CAKC","sourcesContent":["import {\n getColor,\n getRangesByText,\n isBlockElement,\n isNodeOfType,\n parseValueWithUnit,\n toArray,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelSegmentFormat,\n DarkColorHandler,\n DOMHelper,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport interface DOMHelperImplOption {\n /**\n * @deprecated This is always treated as true now\n */\n cloneIndependentRoot?: boolean;\n}\n\nclass DOMHelperImpl implements DOMHelper {\n constructor(private contentDiv: HTMLElement, options?: DOMHelperImplOption) {}\n\n queryElements(selector: string): HTMLElement[] {\n return toArray(this.contentDiv.querySelectorAll(selector)) as HTMLElement[];\n }\n\n getTextContent(): string {\n return this.contentDiv.textContent || '';\n }\n\n isNodeInEditor(node: Node, excludeRoot?: boolean): boolean {\n return excludeRoot && node == this.contentDiv ? false : this.contentDiv.contains(node);\n }\n\n calculateZoomScale(): number {\n const originalWidth = this.contentDiv.getBoundingClientRect()?.width || 0;\n const visualWidth = this.contentDiv.offsetWidth;\n\n return visualWidth > 0 && originalWidth > 0\n ? Math.round((originalWidth / visualWidth) * 100) / 100\n : 1;\n }\n\n setDomAttribute(name: string, value: string | null) {\n if (value === null) {\n this.contentDiv.removeAttribute(name);\n } else {\n this.contentDiv.setAttribute(name, value);\n }\n }\n\n getDomAttribute(name: string): string | null {\n return this.contentDiv.getAttribute(name);\n }\n\n getDomStyle<T extends keyof CSSStyleDeclaration>(style: T): CSSStyleDeclaration[T] {\n return this.contentDiv.style[style];\n }\n\n findClosestElementAncestor(startFrom: Node, selector?: string): HTMLElement | null {\n const startElement = isNodeOfType(startFrom, 'ELEMENT_NODE')\n ? startFrom\n : startFrom.parentElement;\n const closestElement = selector\n ? (startElement?.closest(selector) as HTMLElement | null)\n : startElement;\n\n return closestElement &&\n this.isNodeInEditor(closestElement) &&\n closestElement != this.contentDiv\n ? closestElement\n : null;\n }\n\n /**\n * Find the closest block element ancestor from the given node within current editing scope\n * @param startFrom The node to start the search from\n * @returns The closest block element ancestor\n */\n findClosestBlockElement(startFrom: Node): HTMLElement {\n let node: Node | null = startFrom;\n\n while (node && this.isNodeInEditor(node)) {\n if (isNodeOfType(node, 'ELEMENT_NODE') && isBlockElement(node)) {\n return node;\n }\n\n node = node.parentElement;\n }\n\n return this.contentDiv;\n }\n\n hasFocus(): boolean {\n const activeElement = this.contentDiv.ownerDocument.activeElement;\n return !!(activeElement && this.contentDiv.contains(activeElement));\n }\n\n /**\n * Check if the root element is in RTL mode\n */\n isRightToLeft(): boolean {\n const contentDiv = this.contentDiv;\n const style = contentDiv.ownerDocument.defaultView?.getComputedStyle(contentDiv);\n\n return style?.direction == 'rtl';\n }\n\n /**\n * Get the width of the editable area of the editor content div\n */\n getClientWidth(): number {\n const contentDiv = this.contentDiv;\n const style = contentDiv.ownerDocument.defaultView?.getComputedStyle(contentDiv);\n const paddingLeft = parseValueWithUnit(style?.paddingLeft);\n const paddingRight = parseValueWithUnit(style?.paddingRight);\n return this.contentDiv.clientWidth - (paddingLeft + paddingRight);\n }\n\n /**\n * Get a deep cloned root element\n */\n getClonedRoot(): HTMLElement {\n const doc = this.contentDiv.ownerDocument.implementation.createHTMLDocument();\n const clone = doc.importNode(this.contentDiv, true /*deep*/);\n\n return clone;\n }\n\n /**\n * Get format of the container element\n * @param isInDarkMode Optional flag to indicate if the environment is in dark mode\n * @param darkColorHandler Optional DarkColorHandler to retrieve dark mode colors\n */\n getContainerFormat(\n isInDarkMode?: boolean,\n darkColorHandler?: DarkColorHandler\n ): ContentModelSegmentFormat {\n const window = this.contentDiv.ownerDocument.defaultView;\n\n const style = window?.getComputedStyle(this.contentDiv);\n\n return style\n ? {\n fontSize: style.fontSize,\n fontFamily: style.fontFamily,\n fontWeight: style.fontWeight,\n textColor: getColor(\n this.contentDiv,\n false /*isBackgroundColor*/,\n !!isInDarkMode,\n darkColorHandler,\n style.color\n ),\n backgroundColor: getColor(\n this.contentDiv,\n true /*isBackgroundColor*/,\n !!isInDarkMode,\n darkColorHandler,\n style.backgroundColor\n ),\n italic: style.fontStyle == 'italic',\n letterSpacing: style.letterSpacing,\n lineHeight: style.lineHeight,\n strikethrough: style.textDecoration?.includes('line-through'),\n superOrSubScriptSequence: style.verticalAlign,\n underline: style.textDecoration?.includes('underline'),\n }\n : {};\n }\n\n /**\n * Get text ranges by searching for a specific text, with options to match case and whole word.\n * This will only search within editable elements.\n * @param text The text to search for\n * @param matchCase Whether to match case\n * @param wholeWord Whether to match whole word\n * @returns An array of Ranges that match the search criteria\n */\n getRangesByText(text: string, matchCase: boolean, wholeWord: boolean): Range[] {\n return getRangesByText(this.contentDiv, text, matchCase, wholeWord, true /*editableOnly*/);\n }\n}\n\n/**\n * @internal Create new instance of DOMHelper\n */\nexport function createDOMHelper(\n contentDiv: HTMLElement,\n options: DOMHelperImplOption = {}\n): DOMHelper {\n return new DOMHelperImpl(contentDiv, options);\n}\n"]}
|
|
@@ -14,7 +14,7 @@ var createEditorCorePlugins_1 = require("../../corePlugin/createEditorCorePlugin
|
|
|
14
14
|
* @param options Editor options
|
|
15
15
|
*/
|
|
16
16
|
function createEditorCore(contentDiv, options) {
|
|
17
|
-
var _a, _b
|
|
17
|
+
var _a, _b;
|
|
18
18
|
var corePlugins = (0, createEditorCorePlugins_1.createEditorCorePlugins)(options, contentDiv);
|
|
19
19
|
var domCreator = (0, domCreator_1.createDOMCreator)(options.trustedHTMLHandler);
|
|
20
20
|
return (0, tslib_1.__assign)((0, tslib_1.__assign)({ physicalRoot: contentDiv, logicalRoot: contentDiv, api: (0, tslib_1.__assign)((0, tslib_1.__assign)({}, coreApiMap_1.coreApiMap), options.coreApiOverride), originalApi: (0, tslib_1.__assign)({}, coreApiMap_1.coreApiMap), plugins: (0, tslib_1.__spreadArray)((0, tslib_1.__spreadArray)([
|
|
@@ -30,9 +30,7 @@ function createEditorCore(contentDiv, options) {
|
|
|
30
30
|
corePlugins.lifecycle,
|
|
31
31
|
], false), environment: createEditorEnvironment(contentDiv, options), darkColorHandler: (0, DarkColorHandlerImpl_1.createDarkColorHandler)(contentDiv, (_b = options.getDarkColor) !== null && _b !== void 0 ? _b : getDarkColorFallback, options.knownColors, options.generateColorKey), trustedHTMLHandler: options.trustedHTMLHandler && !(0, domCreator_1.isDOMCreator)(options.trustedHTMLHandler)
|
|
32
32
|
? options.trustedHTMLHandler
|
|
33
|
-
: (0, domCreator_1.createTrustedHTMLHandler)(domCreator), domCreator: domCreator, domHelper: (0, DOMHelperImpl_1.createDOMHelper)(contentDiv, {
|
|
34
|
-
cloneIndependentRoot: (_c = options.experimentalFeatures) === null || _c === void 0 ? void 0 : _c.includes('CloneIndependentRoot'),
|
|
35
|
-
}) }, getPluginState(corePlugins)), { disposeErrorHandler: options.disposeErrorHandler, onFixUpModel: options.onFixUpModel, experimentalFeatures: options.experimentalFeatures ? (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(options.experimentalFeatures), false) : [] });
|
|
33
|
+
: (0, domCreator_1.createTrustedHTMLHandler)(domCreator), domCreator: domCreator, domHelper: (0, DOMHelperImpl_1.createDOMHelper)(contentDiv) }, getPluginState(corePlugins)), { disposeErrorHandler: options.disposeErrorHandler, onFixUpModel: options.onFixUpModel, experimentalFeatures: options.experimentalFeatures ? (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(options.experimentalFeatures), false) : [] });
|
|
36
34
|
}
|
|
37
35
|
exports.createEditorCore = createEditorCore;
|
|
38
36
|
function createEditorEnvironment(contentDiv, options) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createEditorCore.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/editor/core/createEditorCore.ts"],"names":[],"mappings":";;;;AAAA,uDAAsD;AACtD,+DAAgE;AAChE,qDAAkG;AAClG,iDAAkD;AAClD,6EAAmG;AACnG,oFAAmF;AASnF;;;;GAIG;AACH,SAAgB,gBAAgB,CAAC,UAA0B,EAAE,OAAsB;;IAC/E,IAAM,WAAW,GAAG,IAAA,iDAAuB,EAAC,OAAO,EAAE,UAAU,CAAC,CAAC;IACjE,IAAM,UAAU,GAAG,IAAA,6BAAgB,EAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAEhE,qDACI,YAAY,EAAE,UAAU,EACxB,WAAW,EAAE,UAAU,EACvB,GAAG,kDAAO,uBAAU,GAAK,OAAO,CAAC,eAAe,GAChD,WAAW,4BAAO,uBAAU,GAC5B,OAAO;YACH,WAAW,CAAC,KAAK;YACjB,WAAW,CAAC,MAAM;YAClB,WAAW,CAAC,SAAS;YACrB,WAAW,CAAC,QAAQ;YACpB,WAAW,CAAC,SAAS;YACrB,WAAW,CAAC,MAAM;+BACf,CAAC,MAAA,OAAO,CAAC,OAAO,mCAAI,EAAE,CAAC,CAAC,MAAM,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,CAAC,EAAH,CAAG,CAAC;YAC3C,WAAW,CAAC,IAAI;YAChB,WAAW,CAAC,WAAW;YACvB,WAAW,CAAC,SAAS;mBAEzB,WAAW,EAAE,uBAAuB,CAAC,UAAU,EAAE,OAAO,CAAC,EACzD,gBAAgB,EAAE,IAAA,6CAAsB,EACpC,UAAU,EACV,MAAA,OAAO,CAAC,YAAY,mCAAI,oBAAoB,EAC5C,OAAO,CAAC,WAAW,EACnB,OAAO,CAAC,gBAAgB,CAC3B,EACD,kBAAkB,EACd,OAAO,CAAC,kBAAkB,IAAI,CAAC,IAAA,yBAAY,EAAC,OAAO,CAAC,kBAAkB,CAAC;YACnE,CAAC,CAAC,OAAO,CAAC,kBAAkB;YAC5B,CAAC,CAAC,IAAA,qCAAwB,EAAC,UAAU,CAAC,EAC9C,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,IAAA,+BAAe,EAAC,UAAU,
|
|
1
|
+
{"version":3,"file":"createEditorCore.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/editor/core/createEditorCore.ts"],"names":[],"mappings":";;;;AAAA,uDAAsD;AACtD,+DAAgE;AAChE,qDAAkG;AAClG,iDAAkD;AAClD,6EAAmG;AACnG,oFAAmF;AASnF;;;;GAIG;AACH,SAAgB,gBAAgB,CAAC,UAA0B,EAAE,OAAsB;;IAC/E,IAAM,WAAW,GAAG,IAAA,iDAAuB,EAAC,O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C;KACf;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AAED,SAAS,cAAc,CAAC,WAA8B;IAClD,OAAO;QACH,QAAQ,EAAE,WAAW,CAAC,QAAQ,CAAC,QAAQ,EAAE;QACzC,SAAS,EAAE,WAAW,CAAC,SAAS,CAAC,QAAQ,EAAE;QAC3C,KAAK,EAAE,WAAW,CAAC,KAAK,CAAC,QAAQ,EAAE;QACnC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,QAAQ,EAAE;QACrC,SAAS,EAAE,WAAW,CAAC,SAAS,CAAC,QAAQ,EAAE;QAC3C,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,QAAQ,EAAE;QACrC,SAAS,EAAE,WAAW,CAAC,SAAS,CAAC,QAAQ,EAAE;QAC3C,WAAW,EAAE,WAAW,CAAC,WAAW,CAAC,QAAQ,EAAE;QAC/C,IAAI,EAAE,WAAW,CAAC,IAAI,CAAC,QAAQ,EAAE;KACpC,CAAC;AACN,CAAC;AAED;;;GAGG;AACH,SAAgB,oBAAoB,CAAC,KAAa;IAC9C,OAAO,KAAK,CAAC;AACjB,CAAC;AAFD,oDAEC","sourcesContent":["import { coreApiMap } from '../../coreApi/coreApiMap';\nimport { createDarkColorHandler } from './DarkColorHandlerImpl';\nimport { createDOMCreator, createTrustedHTMLHandler, isDOMCreator } from '../../utils/domCreator';\nimport { createDOMHelper } from './DOMHelperImpl';\nimport { createDomToModelSettings, createModelToDomSettings } from './createEditorDefaultSettings';\nimport { createEditorCorePlugins } from '../../corePlugin/createEditorCorePlugins';\nimport type {\n EditorEnvironment,\n PluginState,\n EditorCore,\n EditorCorePlugins,\n EditorOptions,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal Create core object for editor\n * @param contentDiv Editor content DIV\n * @param options Editor options\n */\nexport function createEditorCore(contentDiv: HTMLDivElement, options: EditorOptions): EditorCore {\n const corePlugins = createEditorCorePlugins(options, contentDiv);\n const domCreator = createDOMCreator(options.trustedHTMLHandler);\n\n return {\n physicalRoot: contentDiv,\n logicalRoot: contentDiv,\n api: { ...coreApiMap, ...options.coreApiOverride },\n originalApi: { ...coreApiMap },\n plugins: [\n corePlugins.cache,\n corePlugins.format,\n corePlugins.copyPaste,\n corePlugins.domEvent,\n corePlugins.selection,\n corePlugins.entity,\n ...(options.plugins ?? []).filter(x => !!x),\n corePlugins.undo,\n corePlugins.contextMenu,\n corePlugins.lifecycle,\n ],\n environment: createEditorEnvironment(contentDiv, options),\n darkColorHandler: createDarkColorHandler(\n contentDiv,\n options.getDarkColor ?? getDarkColorFallback,\n options.knownColors,\n options.generateColorKey\n ),\n trustedHTMLHandler:\n options.trustedHTMLHandler && !isDOMCreator(options.trustedHTMLHandler)\n ? options.trustedHTMLHandler\n : createTrustedHTMLHandler(domCreator),\n domCreator: domCreator,\n domHelper: createDOMHelper(contentDiv),\n ...getPluginState(corePlugins),\n disposeErrorHandler: options.disposeErrorHandler,\n onFixUpModel: options.onFixUpModel,\n experimentalFeatures: options.experimentalFeatures ? [...options.experimentalFeatures] : [],\n };\n}\n\nfunction createEditorEnvironment(\n contentDiv: HTMLElement,\n options: EditorOptions\n): EditorEnvironment {\n const navigator = contentDiv.ownerDocument.defaultView?.navigator;\n const userAgent = navigator?.userAgent ?? '';\n const appVersion = navigator?.appVersion ?? '';\n\n return {\n document: contentDiv.ownerDocument,\n domToModelSettings: createDomToModelSettings(options),\n modelToDomSettings: createModelToDomSettings(options),\n isMac: appVersion.indexOf('Mac') != -1,\n isAndroid: /android/i.test(userAgent),\n isIOS: /iPad|iPhone/.test(userAgent),\n isSafari:\n userAgent.indexOf('AppleWebKit') >= 0 &&\n userAgent.indexOf('Chrome') < 0 &&\n userAgent.indexOf('Android') < 0,\n isMobileOrTablet: getIsMobileOrTablet(userAgent),\n };\n}\n\nfunction getIsMobileOrTablet(userAgent: string) {\n // Reference: http://detectmobilebrowsers.com/\n // The default regex on the website doesn't consider tablet.\n // To support tablet, add |android|ipad|playbook|silk to the first regex according to the info in /about page\n if (\n /(android|bb\\d+|meego).+mobile|avantgo|bada\\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i.test(\n userAgent\n ) ||\n /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\\-(n|u)|c55\\/|capi|ccwa|cdm\\-|cell|chtm|cldc|cmd\\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\\-s|devi|dica|dmob|do(c|p)o|ds(12|\\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\\-|_)|g1 u|g560|gene|gf\\-5|g\\-mo|go(\\.w|od)|gr(ad|un)|haie|hcit|hd\\-(m|p|t)|hei\\-|hi(pt|ta)|hp( i|ip)|hs\\-c|ht(c(\\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\\-(20|go|ma)|i230|iac( |\\-|\\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\\/)|klon|kpt |kwc\\-|kyo(c|k)|le(no|xi)|lg( g|\\/(k|l|u)|50|54|\\-[a-w])|libw|lynx|m1\\-w|m3ga|m50\\/|ma(te|ui|xo)|mc(01|21|ca)|m\\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\\-2|po(ck|rt|se)|prox|psio|pt\\-g|qa\\-a|qc(07|12|21|32|60|\\-[2-7]|i\\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\\-|oo|p\\-)|sdk\\/|se(c(\\-|0|1)|47|mc|nd|ri)|sgh\\-|shar|sie(\\-|m)|sk\\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\\-|v\\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\\-|tdg\\-|tel(i|m)|tim\\-|t\\-mo|to(pl|sh)|ts(70|m\\-|m3|m5)|tx\\-9|up(\\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\\-|your|zeto|zte\\-/i.test(\n userAgent.substring(0, 4)\n )\n ) {\n return true;\n }\n return false;\n}\n\nfunction getPluginState(corePlugins: EditorCorePlugins): PluginState {\n return {\n domEvent: corePlugins.domEvent.getState(),\n copyPaste: corePlugins.copyPaste.getState(),\n cache: corePlugins.cache.getState(),\n format: corePlugins.format.getState(),\n lifecycle: corePlugins.lifecycle.getState(),\n entity: corePlugins.entity.getState(),\n selection: corePlugins.selection.getState(),\n contextMenu: corePlugins.contextMenu.getState(),\n undo: corePlugins.undo.getState(),\n };\n}\n\n/**\n * @internal Export for test only\n * A fallback function, always return original color\n */\nexport function getDarkColorFallback(color: string) {\n return color;\n}\n"]}
|
|
@@ -2,7 +2,7 @@ import type { IEditor, ModelToDomOption, ModelToTextCallbacks } from 'roosterjs-
|
|
|
2
2
|
/**
|
|
3
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 Specify HTML to get HTML.
|
|
5
|
+
* @param mode Specify HTML to get HTML.
|
|
6
6
|
* @param options @optional Options for Model to DOM conversion
|
|
7
7
|
*/
|
|
8
8
|
export declare function exportContent(editor: IEditor, mode?: 'HTML', options?: ModelToDomOption): string;
|
|
@@ -10,9 +10,9 @@ export declare function exportContent(editor: IEditor, mode?: 'HTML', options?:
|
|
|
10
10
|
* Export HTML content. If there are entities, this will cause EntityOperation event with option = 'replaceTemporaryContent' to get a dehydrated entity.
|
|
11
11
|
* This is a fast version, it retrieve HTML content directly from editor without going through content model conversion.
|
|
12
12
|
* @param editor The editor to get content from
|
|
13
|
-
* @param mode Specify HTMLFast to get HTML result.
|
|
13
|
+
* @param mode Specify HTMLFast to get HTML result. This is the default option
|
|
14
14
|
*/
|
|
15
|
-
export declare function exportContent(editor: IEditor, mode
|
|
15
|
+
export declare function exportContent(editor: IEditor, mode?: 'HTMLFast'): string;
|
|
16
16
|
/**
|
|
17
17
|
* Export plain text content
|
|
18
18
|
* @param editor The editor to get content from
|
|
@@ -5,7 +5,7 @@ define(["require", "exports", "roosterjs-content-model-dom"], function (require,
|
|
|
5
5
|
// Here I didn't add 'HTMLFast' to ExportContentMode type because it will make this a breaking change and EditorAdapter will see build time error without bumping version
|
|
6
6
|
// Once we are confident that 'HTMLFast' is stable, we can fully switch 'HTML' to use the 'HTMLFast' approach
|
|
7
7
|
function exportContent(editor, mode, optionsOrCallbacks) {
|
|
8
|
-
if (mode === void 0) { mode = '
|
|
8
|
+
if (mode === void 0) { mode = 'HTMLFast'; }
|
|
9
9
|
var model;
|
|
10
10
|
switch (mode) {
|
|
11
11
|
case 'PlainTextFast':
|
|
@@ -14,6 +14,7 @@ define(["require", "exports", "roosterjs-content-model-dom"], function (require,
|
|
|
14
14
|
model = editor.getContentModelCopy('clean');
|
|
15
15
|
return (0, roosterjs_content_model_dom_1.contentModelToText)(model, undefined /*separator*/, optionsOrCallbacks);
|
|
16
16
|
case 'HTMLFast':
|
|
17
|
+
default:
|
|
17
18
|
var clonedRoot = editor.getDOMHelper().getClonedRoot();
|
|
18
19
|
if (editor.isDarkMode()) {
|
|
19
20
|
(0, roosterjs_content_model_dom_1.transformColor)(clonedRoot, false /*includeSelf*/, 'darkToLight', editor.getColorManager(), {
|
|
@@ -22,7 +23,6 @@ define(["require", "exports", "roosterjs-content-model-dom"], function (require,
|
|
|
22
23
|
}
|
|
23
24
|
return getHTMLFromDOM(editor, clonedRoot);
|
|
24
25
|
case 'HTML':
|
|
25
|
-
default:
|
|
26
26
|
model = editor.getContentModelCopy('clean');
|
|
27
27
|
var doc = editor.getDocument();
|
|
28
28
|
var div = doc.createElement('div');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exportContent.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/command/exportContent/exportContent.ts"],"names":[],"mappings":";;;;IAkDA,yKAAyK;IACzK,6GAA6G;IAC7G,SAAgB,aAAa,CACzB,MAAe,EACf,
|
|
1
|
+
{"version":3,"file":"exportContent.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/command/exportContent/exportContent.ts"],"names":[],"mappings":";;;;IAkDA,yKAAyK;IACzK,6GAA6G;IAC7G,SAAgB,aAAa,CACzB,MAAe,EACf,IAAiD,EACjD,kBAA4D;QAD5D,qBAAA,EAAA,iBAAiD;QAGjD,IAAI,KAA2B,CAAC;QAEhC,QAAQ,IAAI,EAAE;YACV,KAAK,eAAe;gBAChB,OAAO,MAAM,CAAC,YAAY,EAAE,CAAC,cAAc,EAAE,CAAC;YAClD,KAAK,WAAW;gBACZ,KAAK,GAAG,MAAM,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC;gBAE5C,OAAO,IAAA,gDAAkB,EACrB,KAAK,EACL,SAAS,CAAC,aAAa,EACvB,kBAA0C,CAC7C,CAAC;YAEN,KAAK,UAAU,CAAC;YAChB;gBACI,IAAM,UAAU,GAAG,MAAM,CAAC,YAAY,EAAE,CAAC,aAAa,EAAE,CAAC;gBAEzD,IAAI,MAAM,CAAC,UAAU,EAAE,EAAE;oBACrB,IAAA,4CAAc,EACV,UAAU,EACV,KAAK,CAAC,eAAe,EACrB,aAAa,EACb,MAAM,CAAC,eAAe,EAAE,EACxB;wBACI,YAAY,EAAE,MAAM,CAAC,4BAA4B,CAC7C,4BAA4B,CAC/B;qBACJ,CACJ,CAAC;iBACL;gBAED,OAAO,cAAc,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;YAE9C,KAAK,MAAM;gBACP,KAAK,GAAG,MAAM,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC;gBAE5C,IAAM,GAAG,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC;gBACjC,IAAM,GAAG,GAAG,GAAG,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;gBAErC,IAAA,+CAAiB,EACb,GAAG,EACH,GAAG,EACH,KAAK,EACL,IAAA,qDAAuB,EACnB,SAAS,CAAC,iBAAiB,EAC3B,kBAAsC,CACzC,CACJ,CAAC;gBAEF,OAAO,cAAc,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;SAC1C;IACL,CAAC;IAzDD,sCAyDC;IAED,SAAS,cAAc,CAAC,MAAe,EAAE,IAAiB;QACtD,MAAM,CAAC,YAAY,CAAC,uBAAuB,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;QAEvF,OAAO,IAAI,CAAC,SAAS,CAAC;IAC1B,CAAC","sourcesContent":["import {\n contentModelToDom,\n contentModelToText,\n createModelToDomContext,\n transformColor,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelDocument,\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 HTML.\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 HTML content. If there are entities, this will cause EntityOperation event with option = 'replaceTemporaryContent' to get a dehydrated entity.\n * This is a fast version, it retrieve HTML content directly from editor without going through content model conversion.\n * @param editor The editor to get content from\n * @param mode Specify HTMLFast to get HTML result. This is the default option\n */\nexport function exportContent(editor: IEditor, mode?: 'HTMLFast'): 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\n// Here I didn't add 'HTMLFast' to ExportContentMode type because it will make this a breaking change and EditorAdapter will see build time error without bumping version\n// Once we are confident that 'HTMLFast' is stable, we can fully switch 'HTML' to use the 'HTMLFast' approach\nexport function exportContent(\n editor: IEditor,\n mode: ExportContentMode | 'HTMLFast' = 'HTMLFast',\n optionsOrCallbacks?: ModelToDomOption | ModelToTextCallbacks\n): string {\n let model: ContentModelDocument;\n\n switch (mode) {\n case 'PlainTextFast':\n return editor.getDOMHelper().getTextContent();\n case 'PlainText':\n model = editor.getContentModelCopy('clean');\n\n return contentModelToText(\n model,\n undefined /*separator*/,\n optionsOrCallbacks as ModelToTextCallbacks\n );\n\n case 'HTMLFast':\n default:\n const clonedRoot = editor.getDOMHelper().getClonedRoot();\n\n if (editor.isDarkMode()) {\n transformColor(\n clonedRoot,\n false /*includeSelf*/,\n 'darkToLight',\n editor.getColorManager(),\n {\n tableBorders: editor.isExperimentalFeatureEnabled(\n 'TransformTableBorderColors'\n ),\n }\n );\n }\n\n return getHTMLFromDOM(editor, clonedRoot);\n\n case 'HTML':\n model = editor.getContentModelCopy('clean');\n\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 return getHTMLFromDOM(editor, div);\n }\n}\n\nfunction getHTMLFromDOM(editor: IEditor, root: HTMLElement): string {\n editor.triggerEvent('extractContentWithDom', { clonedRoot: root }, true /*broadcast*/);\n\n return root.innerHTML;\n}\n"]}
|
|
@@ -7,10 +7,10 @@ define(["require", "exports", "tslib", "./getRootComputedStyleForContext"], func
|
|
|
7
7
|
* Create a EditorContext object used by ContentModel API
|
|
8
8
|
*/
|
|
9
9
|
var createEditorContext = function (core, saveIndex) {
|
|
10
|
-
var _a, _b
|
|
10
|
+
var _a, _b;
|
|
11
11
|
var lifecycle = core.lifecycle, format = core.format, darkColorHandler = core.darkColorHandler, logicalRoot = core.logicalRoot, cache = core.cache, domHelper = core.domHelper;
|
|
12
12
|
saveIndex = saveIndex && !core.lifecycle.shadowEditFragment;
|
|
13
|
-
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,
|
|
13
|
+
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(), experimentalFeatures: (_b = core.experimentalFeatures) !== null && _b !== void 0 ? _b : [], paragraphMap: core.cache.paragraphMap, editorViewWidth: domHelper.getClientWidth() }, (0, getRootComputedStyleForContext_1.getRootComputedStyleForContext)(logicalRoot.ownerDocument));
|
|
14
14
|
if (core.domHelper.isRightToLeft()) {
|
|
15
15
|
context.isRootRtl = true;
|
|
16
16
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createEditorContext.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/coreApi/createEditorContext/createEditorContext.ts"],"names":[],"mappings":";;;;IAGA;;;OAGG;IACI,IAAM,mBAAmB,GAAwB,UAAC,IAAI,EAAE,SAAS;;QAC5D,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;QAEpF,SAAS,GAAG,SAAS,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,kBAAkB,CAAC;QAE5D,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,
|
|
1
|
+
{"version":3,"file":"createEditorContext.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/coreApi/createEditorContext/createEditorContext.ts"],"names":[],"mappings":";;;;IAGA;;;OAGG;IACI,IAAM,mBAAmB,GAAwB,UAAC,IAAI,EAAE,SAAS;;QAC5D,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;QAEpF,SAAS,GAAG,SAAS,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,kBAAkB,CAAC;QAE5D,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,EACzC,oBAAoB,EAAE,MAAA,IAAI,CAAC,oBAAoB,mCAAI,EAAE,EACrD,YAAY,EAAE,IAAI,CAAC,KAAK,CAAC,YAAY,EACrC,eAAe,EAAE,SAAS,CAAC,cAAc,EAAE,IACxC,IAAA,+DAA8B,EAAC,WAAW,CAAC,aAAa,CAAC,CAC/D,CAAC;QAEF,IAAI,IAAI,CAAC,SAAS,CAAC,aAAa,EAAE,EAAE;YAChC,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;SAC5B;QAED,OAAO,OAAO,CAAC;IACnB,CAAC,CAAC;IAzBW,QAAA,mBAAmB,uBAyB9B","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 experimentalFeatures: core.experimentalFeatures ?? [],\n paragraphMap: core.cache.paragraphMap,\n editorViewWidth: domHelper.getClientWidth(),\n ...getRootComputedStyleForContext(logicalRoot.ownerDocument),\n };\n\n if (core.domHelper.isRightToLeft()) {\n context.isRootRtl = true;\n }\n\n return context;\n};\n"]}
|
|
@@ -5,7 +5,6 @@ define(["require", "exports", "roosterjs-content-model-dom"], function (require,
|
|
|
5
5
|
var DOMHelperImpl = /** @class */ (function () {
|
|
6
6
|
function DOMHelperImpl(contentDiv, options) {
|
|
7
7
|
this.contentDiv = contentDiv;
|
|
8
|
-
this.options = options;
|
|
9
8
|
}
|
|
10
9
|
DOMHelperImpl.prototype.queryElements = function (selector) {
|
|
11
10
|
return (0, roosterjs_content_model_dom_1.toArray)(this.contentDiv.querySelectorAll(selector));
|
|
@@ -94,14 +93,9 @@ define(["require", "exports", "roosterjs-content-model-dom"], function (require,
|
|
|
94
93
|
* Get a deep cloned root element
|
|
95
94
|
*/
|
|
96
95
|
DOMHelperImpl.prototype.getClonedRoot = function () {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
return clone;
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
return this.contentDiv.cloneNode(true /*deep*/);
|
|
104
|
-
}
|
|
96
|
+
var doc = this.contentDiv.ownerDocument.implementation.createHTMLDocument();
|
|
97
|
+
var clone = doc.importNode(this.contentDiv, true /*deep*/);
|
|
98
|
+
return clone;
|
|
105
99
|
};
|
|
106
100
|
/**
|
|
107
101
|
* Get format of the container element
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DOMHelperImpl.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/editor/core/DOMHelperImpl.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AAgB,CAAC,CAAC;QAC/F,CAAC;QACL,oBAAC;IAAD,CAAC,AAvKD,IAuKC;IAED;;OAEG;IACH,SAAgB,eAAe,CAC3B,UAAuB,EACvB,OAAiC;QAAjC,wBAAA,EAAA,YAAiC;QAEjC,OAAO,IAAI,aAAa,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IAClD,CAAC;IALD,0CAKC","sourcesContent":["import {\n getColor,\n getRangesByText,\n isBlockElement,\n isNodeOfType,\n parseValueWithUnit,\n toArray,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelSegmentFormat,\n DarkColorHandler,\n DOMHelper,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport interface DOMHelperImplOption {\n cloneIndependentRoot?: boolean;\n}\n\nclass DOMHelperImpl implements DOMHelper {\n constructor(private contentDiv: HTMLElement, private options: DOMHelperImplOption) {}\n\n queryElements(selector: string): HTMLElement[] {\n return toArray(this.contentDiv.querySelectorAll(selector)) as HTMLElement[];\n }\n\n getTextContent(): string {\n return this.contentDiv.textContent || '';\n }\n\n isNodeInEditor(node: Node, excludeRoot?: boolean): boolean {\n return excludeRoot && node == this.contentDiv ? false : this.contentDiv.contains(node);\n }\n\n calculateZoomScale(): number {\n const originalWidth = this.contentDiv.getBoundingClientRect()?.width || 0;\n const visualWidth = this.contentDiv.offsetWidth;\n\n return visualWidth > 0 && originalWidth > 0\n ? Math.round((originalWidth / visualWidth) * 100) / 100\n : 1;\n }\n\n setDomAttribute(name: string, value: string | null) {\n if (value === null) {\n this.contentDiv.removeAttribute(name);\n } else {\n this.contentDiv.setAttribute(name, value);\n }\n }\n\n getDomAttribute(name: string): string | null {\n return this.contentDiv.getAttribute(name);\n }\n\n getDomStyle<T extends keyof CSSStyleDeclaration>(style: T): CSSStyleDeclaration[T] {\n return this.contentDiv.style[style];\n }\n\n findClosestElementAncestor(startFrom: Node, selector?: string): HTMLElement | null {\n const startElement = isNodeOfType(startFrom, 'ELEMENT_NODE')\n ? startFrom\n : startFrom.parentElement;\n const closestElement = selector\n ? (startElement?.closest(selector) as HTMLElement | null)\n : startElement;\n\n return closestElement &&\n this.isNodeInEditor(closestElement) &&\n closestElement != this.contentDiv\n ? closestElement\n : null;\n }\n\n /**\n * Find the closest block element ancestor from the given node within current editing scope\n * @param startFrom The node to start the search from\n * @returns The closest block element ancestor\n */\n findClosestBlockElement(startFrom: Node): HTMLElement {\n let node: Node | null = startFrom;\n\n while (node && this.isNodeInEditor(node)) {\n if (isNodeOfType(node, 'ELEMENT_NODE') && isBlockElement(node)) {\n return node;\n }\n\n node = node.parentElement;\n }\n\n return this.contentDiv;\n }\n\n hasFocus(): boolean {\n const activeElement = this.contentDiv.ownerDocument.activeElement;\n return !!(activeElement && this.contentDiv.contains(activeElement));\n }\n\n /**\n * Check if the root element is in RTL mode\n */\n isRightToLeft(): boolean {\n const contentDiv = this.contentDiv;\n const style = contentDiv.ownerDocument.defaultView?.getComputedStyle(contentDiv);\n\n return style?.direction == 'rtl';\n }\n\n /**\n * Get the width of the editable area of the editor content div\n */\n getClientWidth(): number {\n const contentDiv = this.contentDiv;\n const style = contentDiv.ownerDocument.defaultView?.getComputedStyle(contentDiv);\n const paddingLeft = parseValueWithUnit(style?.paddingLeft);\n const paddingRight = parseValueWithUnit(style?.paddingRight);\n return this.contentDiv.clientWidth - (paddingLeft + paddingRight);\n }\n\n /**\n * Get a deep cloned root element\n */\n getClonedRoot(): HTMLElement {\n if (this.options.cloneIndependentRoot) {\n const doc = this.contentDiv.ownerDocument.implementation.createHTMLDocument();\n const clone = doc.importNode(this.contentDiv, true /*deep*/);\n\n return clone;\n } else {\n return this.contentDiv.cloneNode(true /*deep*/) as HTMLElement;\n }\n }\n\n /**\n * Get format of the container element\n * @param isInDarkMode Optional flag to indicate if the environment is in dark mode\n * @param darkColorHandler Optional DarkColorHandler to retrieve dark mode colors\n */\n getContainerFormat(\n isInDarkMode?: boolean,\n darkColorHandler?: DarkColorHandler\n ): ContentModelSegmentFormat {\n const window = this.contentDiv.ownerDocument.defaultView;\n\n const style = window?.getComputedStyle(this.contentDiv);\n\n return style\n ? {\n fontSize: style.fontSize,\n fontFamily: style.fontFamily,\n fontWeight: style.fontWeight,\n textColor: getColor(\n this.contentDiv,\n false /*isBackgroundColor*/,\n !!isInDarkMode,\n darkColorHandler,\n style.color\n ),\n backgroundColor: getColor(\n this.contentDiv,\n true /*isBackgroundColor*/,\n !!isInDarkMode,\n darkColorHandler,\n style.backgroundColor\n ),\n italic: style.fontStyle == 'italic',\n letterSpacing: style.letterSpacing,\n lineHeight: style.lineHeight,\n strikethrough: style.textDecoration?.includes('line-through'),\n superOrSubScriptSequence: style.verticalAlign,\n underline: style.textDecoration?.includes('underline'),\n }\n : {};\n }\n\n /**\n * Get text ranges by searching for a specific text, with options to match case and whole word.\n * This will only search within editable elements.\n * @param text The text to search for\n * @param matchCase Whether to match case\n * @param wholeWord Whether to match whole word\n * @returns An array of Ranges that match the search criteria\n */\n getRangesByText(text: string, matchCase: boolean, wholeWord: boolean): Range[] {\n return getRangesByText(this.contentDiv, text, matchCase, wholeWord, true /*editableOnly*/);\n }\n}\n\n/**\n * @internal Create new instance of DOMHelper\n */\nexport function createDOMHelper(\n contentDiv: HTMLElement,\n options: DOMHelperImplOption = {}\n): DOMHelper {\n return new DOMHelperImpl(contentDiv, options);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"DOMHelperImpl.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/editor/core/DOMHelperImpl.ts"],"names":[],"mappings":";;;;IAwBA;QACI,uBAAoB,UAAuB,EAAE,OAA6B;YAAtD,eAAU,GAAV,UAAU,CAAa;QAAkC,CAAC;QAE9E,qCAAa,GAAb,UAAc,QAAgB;YAC1B,OAAO,IAAA,qCAAO,EAAC,IAAI,CAAC,UAAU,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAkB,CAAC;QAChF,CAAC;QAED,sCAAc,GAAd;YACI,OAAO,IAAI,CAAC,UAAU,CAAC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C,YAAY,EACd,gBAAgB,EAChB,KAAK,CAAC,KAAK,CACd;oBACD,eAAe,EAAE,IAAA,sCAAQ,EACrB,IAAI,CAAC,UAAU,EACf,IAAI,CAAC,qBAAqB,EAC1B,CAAC,CAAC,YAAY,EACd,gBAAgB,EAChB,KAAK,CAAC,eAAe,CACxB;oBACD,MAAM,EAAE,KAAK,CAAC,SAAS,IAAI,QAAQ;oBACnC,aAAa,EAAE,KAAK,CAAC,aAAa;oBAClC,UAAU,EAAE,KAAK,CAAC,UAAU;oBAC5B,aAAa,EAAE,MAAA,KAAK,CAAC,cAAc,0CAAE,QAAQ,CAAC,cAAc,CAAC;oBAC7D,wBAAwB,EAAE,KAAK,CAAC,aAAa;oBAC7C,SAAS,EAAE,MAAA,KAAK,CAAC,cAAc,0CAAE,QAAQ,CAAC,WAAW,CAAC;iBACzD;gBACH,CAAC,CAAC,EAAE,CAAC;QACb,CAAC;QAED;;;;;;;WAOG;QACH,uCAAe,GAAf,UAAgB,IAAY,EAAE,SAAkB,EAAE,SAAkB;YAChE,OAAO,IAAA,6CAAe,EAAC,IAAI,CAAC,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC;QAC/F,CAAC;QACL,oBAAC;IAAD,CAAC,AAnKD,IAmKC;IAED;;OAEG;IACH,SAAgB,eAAe,CAC3B,UAAuB,EACvB,OAAiC;QAAjC,wBAAA,EAAA,YAAiC;QAEjC,OAAO,IAAI,aAAa,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IAClD,CAAC;IALD,0CAKC","sourcesContent":["import {\n getColor,\n getRangesByText,\n isBlockElement,\n isNodeOfType,\n parseValueWithUnit,\n toArray,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelSegmentFormat,\n DarkColorHandler,\n DOMHelper,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport interface DOMHelperImplOption {\n /**\n * @deprecated This is always treated as true now\n */\n cloneIndependentRoot?: boolean;\n}\n\nclass DOMHelperImpl implements DOMHelper {\n constructor(private contentDiv: HTMLElement, options?: DOMHelperImplOption) {}\n\n queryElements(selector: string): HTMLElement[] {\n return toArray(this.contentDiv.querySelectorAll(selector)) as HTMLElement[];\n }\n\n getTextContent(): string {\n return this.contentDiv.textContent || '';\n }\n\n isNodeInEditor(node: Node, excludeRoot?: boolean): boolean {\n return excludeRoot && node == this.contentDiv ? false : this.contentDiv.contains(node);\n }\n\n calculateZoomScale(): number {\n const originalWidth = this.contentDiv.getBoundingClientRect()?.width || 0;\n const visualWidth = this.contentDiv.offsetWidth;\n\n return visualWidth > 0 && originalWidth > 0\n ? Math.round((originalWidth / visualWidth) * 100) / 100\n : 1;\n }\n\n setDomAttribute(name: string, value: string | null) {\n if (value === null) {\n this.contentDiv.removeAttribute(name);\n } else {\n this.contentDiv.setAttribute(name, value);\n }\n }\n\n getDomAttribute(name: string): string | null {\n return this.contentDiv.getAttribute(name);\n }\n\n getDomStyle<T extends keyof CSSStyleDeclaration>(style: T): CSSStyleDeclaration[T] {\n return this.contentDiv.style[style];\n }\n\n findClosestElementAncestor(startFrom: Node, selector?: string): HTMLElement | null {\n const startElement = isNodeOfType(startFrom, 'ELEMENT_NODE')\n ? startFrom\n : startFrom.parentElement;\n const closestElement = selector\n ? (startElement?.closest(selector) as HTMLElement | null)\n : startElement;\n\n return closestElement &&\n this.isNodeInEditor(closestElement) &&\n closestElement != this.contentDiv\n ? closestElement\n : null;\n }\n\n /**\n * Find the closest block element ancestor from the given node within current editing scope\n * @param startFrom The node to start the search from\n * @returns The closest block element ancestor\n */\n findClosestBlockElement(startFrom: Node): HTMLElement {\n let node: Node | null = startFrom;\n\n while (node && this.isNodeInEditor(node)) {\n if (isNodeOfType(node, 'ELEMENT_NODE') && isBlockElement(node)) {\n return node;\n }\n\n node = node.parentElement;\n }\n\n return this.contentDiv;\n }\n\n hasFocus(): boolean {\n const activeElement = this.contentDiv.ownerDocument.activeElement;\n return !!(activeElement && this.contentDiv.contains(activeElement));\n }\n\n /**\n * Check if the root element is in RTL mode\n */\n isRightToLeft(): boolean {\n const contentDiv = this.contentDiv;\n const style = contentDiv.ownerDocument.defaultView?.getComputedStyle(contentDiv);\n\n return style?.direction == 'rtl';\n }\n\n /**\n * Get the width of the editable area of the editor content div\n */\n getClientWidth(): number {\n const contentDiv = this.contentDiv;\n const style = contentDiv.ownerDocument.defaultView?.getComputedStyle(contentDiv);\n const paddingLeft = parseValueWithUnit(style?.paddingLeft);\n const paddingRight = parseValueWithUnit(style?.paddingRight);\n return this.contentDiv.clientWidth - (paddingLeft + paddingRight);\n }\n\n /**\n * Get a deep cloned root element\n */\n getClonedRoot(): HTMLElement {\n const doc = this.contentDiv.ownerDocument.implementation.createHTMLDocument();\n const clone = doc.importNode(this.contentDiv, true /*deep*/);\n\n return clone;\n }\n\n /**\n * Get format of the container element\n * @param isInDarkMode Optional flag to indicate if the environment is in dark mode\n * @param darkColorHandler Optional DarkColorHandler to retrieve dark mode colors\n */\n getContainerFormat(\n isInDarkMode?: boolean,\n darkColorHandler?: DarkColorHandler\n ): ContentModelSegmentFormat {\n const window = this.contentDiv.ownerDocument.defaultView;\n\n const style = window?.getComputedStyle(this.contentDiv);\n\n return style\n ? {\n fontSize: style.fontSize,\n fontFamily: style.fontFamily,\n fontWeight: style.fontWeight,\n textColor: getColor(\n this.contentDiv,\n false /*isBackgroundColor*/,\n !!isInDarkMode,\n darkColorHandler,\n style.color\n ),\n backgroundColor: getColor(\n this.contentDiv,\n true /*isBackgroundColor*/,\n !!isInDarkMode,\n darkColorHandler,\n style.backgroundColor\n ),\n italic: style.fontStyle == 'italic',\n letterSpacing: style.letterSpacing,\n lineHeight: style.lineHeight,\n strikethrough: style.textDecoration?.includes('line-through'),\n superOrSubScriptSequence: style.verticalAlign,\n underline: style.textDecoration?.includes('underline'),\n }\n : {};\n }\n\n /**\n * Get text ranges by searching for a specific text, with options to match case and whole word.\n * This will only search within editable elements.\n * @param text The text to search for\n * @param matchCase Whether to match case\n * @param wholeWord Whether to match whole word\n * @returns An array of Ranges that match the search criteria\n */\n getRangesByText(text: string, matchCase: boolean, wholeWord: boolean): Range[] {\n return getRangesByText(this.contentDiv, text, matchCase, wholeWord, true /*editableOnly*/);\n }\n}\n\n/**\n * @internal Create new instance of DOMHelper\n */\nexport function createDOMHelper(\n contentDiv: HTMLElement,\n options: DOMHelperImplOption = {}\n): DOMHelper {\n return new DOMHelperImpl(contentDiv, options);\n}\n"]}
|
|
@@ -8,7 +8,7 @@ define(["require", "exports", "tslib", "../../coreApi/coreApiMap", "./DarkColorH
|
|
|
8
8
|
* @param options Editor options
|
|
9
9
|
*/
|
|
10
10
|
function createEditorCore(contentDiv, options) {
|
|
11
|
-
var _a, _b
|
|
11
|
+
var _a, _b;
|
|
12
12
|
var corePlugins = (0, createEditorCorePlugins_1.createEditorCorePlugins)(options, contentDiv);
|
|
13
13
|
var domCreator = (0, domCreator_1.createDOMCreator)(options.trustedHTMLHandler);
|
|
14
14
|
return (0, tslib_1.__assign)((0, tslib_1.__assign)({ physicalRoot: contentDiv, logicalRoot: contentDiv, api: (0, tslib_1.__assign)((0, tslib_1.__assign)({}, coreApiMap_1.coreApiMap), options.coreApiOverride), originalApi: (0, tslib_1.__assign)({}, coreApiMap_1.coreApiMap), plugins: (0, tslib_1.__spreadArray)((0, tslib_1.__spreadArray)([
|
|
@@ -24,9 +24,7 @@ define(["require", "exports", "tslib", "../../coreApi/coreApiMap", "./DarkColorH
|
|
|
24
24
|
corePlugins.lifecycle,
|
|
25
25
|
], false), environment: createEditorEnvironment(contentDiv, options), darkColorHandler: (0, DarkColorHandlerImpl_1.createDarkColorHandler)(contentDiv, (_b = options.getDarkColor) !== null && _b !== void 0 ? _b : getDarkColorFallback, options.knownColors, options.generateColorKey), trustedHTMLHandler: options.trustedHTMLHandler && !(0, domCreator_1.isDOMCreator)(options.trustedHTMLHandler)
|
|
26
26
|
? options.trustedHTMLHandler
|
|
27
|
-
: (0, domCreator_1.createTrustedHTMLHandler)(domCreator), domCreator: domCreator, domHelper: (0, DOMHelperImpl_1.createDOMHelper)(contentDiv, {
|
|
28
|
-
cloneIndependentRoot: (_c = options.experimentalFeatures) === null || _c === void 0 ? void 0 : _c.includes('CloneIndependentRoot'),
|
|
29
|
-
}) }, getPluginState(corePlugins)), { disposeErrorHandler: options.disposeErrorHandler, onFixUpModel: options.onFixUpModel, experimentalFeatures: options.experimentalFeatures ? (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(options.experimentalFeatures), false) : [] });
|
|
27
|
+
: (0, domCreator_1.createTrustedHTMLHandler)(domCreator), domCreator: domCreator, domHelper: (0, DOMHelperImpl_1.createDOMHelper)(contentDiv) }, getPluginState(corePlugins)), { disposeErrorHandler: options.disposeErrorHandler, onFixUpModel: options.onFixUpModel, experimentalFeatures: options.experimentalFeatures ? (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(options.experimentalFeatures), false) : [] });
|
|
30
28
|
}
|
|
31
29
|
exports.createEditorCore = createEditorCore;
|
|
32
30
|
function createEditorEnvironment(contentDiv, options) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createEditorCore.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/editor/core/createEditorCore.ts"],"names":[],"mappings":";;;;IAcA;;;;OAIG;IACH,SAAgB,gBAAgB,CAAC,UAA0B,EAAE,OAAsB;;QAC/E,IAAM,WAAW,GAAG,IAAA,iDAAuB,EAAC,OAAO,EAAE,UAAU,CAAC,CAAC;QACjE,IAAM,UAAU,GAAG,IAAA,6BAAgB,EAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;QAEhE,qDACI,YAAY,EAAE,UAAU,EACxB,WAAW,EAAE,UAAU,EACvB,GAAG,kDAAO,uBAAU,GAAK,OAAO,CAAC,eAAe,GAChD,WAAW,4BAAO,uBAAU,GAC5B,OAAO;gBACH,WAAW,CAAC,KAAK;gBACjB,WAAW,CAAC,MAAM;gBAClB,WAAW,CAAC,SAAS;gBACrB,WAAW,CAAC,QAAQ;gBACpB,WAAW,CAAC,SAAS;gBACrB,WAAW,CAAC,MAAM;mCACf,CAAC,MAAA,OAAO,CAAC,OAAO,mCAAI,EAAE,CAAC,CAAC,MAAM,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,CAAC,EAAH,CAAG,CAAC;gBAC3C,WAAW,CAAC,IAAI;gBAChB,WAAW,CAAC,WAAW;gBACvB,WAAW,CAAC,SAAS;uBAEzB,WAAW,EAAE,uBAAuB,CAAC,UAAU,EAAE,OAAO,CAAC,EACzD,gBAAgB,EAAE,IAAA,6CAAsB,EACpC,UAAU,EACV,MAAA,OAAO,CAAC,YAAY,mCAAI,oBAAoB,EAC5C,OAAO,CAAC,WAAW,EACnB,OAAO,CAAC,gBAAgB,CAC3B,EACD,kBAAkB,EACd,OAAO,CAAC,kBAAkB,IAAI,CAAC,IAAA,yBAAY,EAAC,OAAO,CAAC,kBAAkB,CAAC;gBACnE,CAAC,CAAC,OAAO,CAAC,kBAAkB;gBAC5B,CAAC,CAAC,IAAA,qCAAwB,EAAC,UAAU,CAAC,EAC9C,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,IAAA,+BAAe,EAAC,UAAU,
|
|
1
|
+
{"version":3,"file":"createEditorCore.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/editor/core/createEditorCore.ts"],"names":[],"mappings":";;;;IAcA;;;;OAIG;IACH,SAAgB,gBAAgB,CAAC,UAA0B,EAAE,OAAsB;;QAC/E,IAAM,WAAW,GAAG,IAAA,iDAAuB,EAAC,OAAO,EAAE,UAAU,CAAC,CAAC;QACjE,IAAM,UAAU,GAAG,IAAA,6BAAgB,EAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;QAEhE,qDACI,YAAY,EAAE,UAAU,EACxB,WAAW,EAAE,UAAU,EACvB,GAAG,kDAAO,uBAAU,GAAK,OAAO,CAAC,eAAe,GAChD,WAAW,4BAAO,uBAAU,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AAC,KAAK,CAAC,QAAQ,EAAE;YACnC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,QAAQ,EAAE;YACrC,SAAS,EAAE,WAAW,CAAC,SAAS,CAAC,QAAQ,EAAE;YAC3C,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,QAAQ,EAAE;YACrC,SAAS,EAAE,WAAW,CAAC,SAAS,CAAC,QAAQ,EAAE;YAC3C,WAAW,EAAE,WAAW,CAAC,WAAW,CAAC,QAAQ,EAAE;YAC/C,IAAI,EAAE,WAAW,CAAC,IAAI,CAAC,QAAQ,EAAE;SACpC,CAAC;IACN,CAAC;IAED;;;OAGG;IACH,SAAgB,oBAAoB,CAAC,KAAa;QAC9C,OAAO,KAAK,CAAC;IACjB,CAAC;IAFD,oDAEC","sourcesContent":["import { coreApiMap } from '../../coreApi/coreApiMap';\nimport { createDarkColorHandler } from './DarkColorHandlerImpl';\nimport { createDOMCreator, createTrustedHTMLHandler, isDOMCreator } from '../../utils/domCreator';\nimport { createDOMHelper } from './DOMHelperImpl';\nimport { createDomToModelSettings, createModelToDomSettings } from './createEditorDefaultSettings';\nimport { createEditorCorePlugins } from '../../corePlugin/createEditorCorePlugins';\nimport type {\n EditorEnvironment,\n PluginState,\n EditorCore,\n EditorCorePlugins,\n EditorOptions,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal Create core object for editor\n * @param contentDiv Editor content DIV\n * @param options Editor options\n */\nexport function createEditorCore(contentDiv: HTMLDivElement, options: EditorOptions): EditorCore {\n const corePlugins = createEditorCorePlugins(options, contentDiv);\n const domCreator = createDOMCreator(options.trustedHTMLHandler);\n\n return {\n physicalRoot: contentDiv,\n logicalRoot: contentDiv,\n api: { ...coreApiMap, ...options.coreApiOverride },\n originalApi: { ...coreApiMap },\n plugins: [\n corePlugins.cache,\n corePlugins.format,\n corePlugins.copyPaste,\n corePlugins.domEvent,\n corePlugins.selection,\n corePlugins.entity,\n ...(options.plugins ?? []).filter(x => !!x),\n corePlugins.undo,\n corePlugins.contextMenu,\n corePlugins.lifecycle,\n ],\n environment: createEditorEnvironment(contentDiv, options),\n darkColorHandler: createDarkColorHandler(\n contentDiv,\n options.getDarkColor ?? getDarkColorFallback,\n options.knownColors,\n options.generateColorKey\n ),\n trustedHTMLHandler:\n options.trustedHTMLHandler && !isDOMCreator(options.trustedHTMLHandler)\n ? options.trustedHTMLHandler\n : createTrustedHTMLHandler(domCreator),\n domCreator: domCreator,\n domHelper: createDOMHelper(contentDiv),\n ...getPluginState(corePlugins),\n disposeErrorHandler: options.disposeErrorHandler,\n onFixUpModel: options.onFixUpModel,\n experimentalFeatures: options.experimentalFeatures ? [...options.experimentalFeatures] : [],\n };\n}\n\nfunction createEditorEnvironment(\n contentDiv: HTMLElement,\n options: EditorOptions\n): EditorEnvironment {\n const navigator = contentDiv.ownerDocument.defaultView?.navigator;\n const userAgent = navigator?.userAgent ?? '';\n const appVersion = navigator?.appVersion ?? '';\n\n return {\n document: contentDiv.ownerDocument,\n domToModelSettings: createDomToModelSettings(options),\n modelToDomSettings: createModelToDomSettings(options),\n isMac: appVersion.indexOf('Mac') != -1,\n isAndroid: /android/i.test(userAgent),\n isIOS: /iPad|iPhone/.test(userAgent),\n isSafari:\n userAgent.indexOf('AppleWebKit') >= 0 &&\n userAgent.indexOf('Chrome') < 0 &&\n userAgent.indexOf('Android') < 0,\n isMobileOrTablet: getIsMobileOrTablet(userAgent),\n };\n}\n\nfunction getIsMobileOrTablet(userAgent: string) {\n // Reference: http://detectmobilebrowsers.com/\n // The default regex on the website doesn't consider tablet.\n // To support tablet, add |android|ipad|playbook|silk to the first regex according to the info in /about page\n if (\n /(android|bb\\d+|meego).+mobile|avantgo|bada\\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i.test(\n userAgent\n ) ||\n /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\\-(n|u)|c55\\/|capi|ccwa|cdm\\-|cell|chtm|cldc|cmd\\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\\-s|devi|dica|dmob|do(c|p)o|ds(12|\\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\\-|_)|g1 u|g560|gene|gf\\-5|g\\-mo|go(\\.w|od)|gr(ad|un)|haie|hcit|hd\\-(m|p|t)|hei\\-|hi(pt|ta)|hp( i|ip)|hs\\-c|ht(c(\\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\\-(20|go|ma)|i230|iac( |\\-|\\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\\/)|klon|kpt |kwc\\-|kyo(c|k)|le(no|xi)|lg( g|\\/(k|l|u)|50|54|\\-[a-w])|libw|lynx|m1\\-w|m3ga|m50\\/|ma(te|ui|xo)|mc(01|21|ca)|m\\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\\-2|po(ck|rt|se)|prox|psio|pt\\-g|qa\\-a|qc(07|12|21|32|60|\\-[2-7]|i\\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\\-|oo|p\\-)|sdk\\/|se(c(\\-|0|1)|47|mc|nd|ri)|sgh\\-|shar|sie(\\-|m)|sk\\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\\-|v\\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\\-|tdg\\-|tel(i|m)|tim\\-|t\\-mo|to(pl|sh)|ts(70|m\\-|m3|m5)|tx\\-9|up(\\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\\-|your|zeto|zte\\-/i.test(\n userAgent.substring(0, 4)\n )\n ) {\n return true;\n }\n return false;\n}\n\nfunction getPluginState(corePlugins: EditorCorePlugins): PluginState {\n return {\n domEvent: corePlugins.domEvent.getState(),\n copyPaste: corePlugins.copyPaste.getState(),\n cache: corePlugins.cache.getState(),\n format: corePlugins.format.getState(),\n lifecycle: corePlugins.lifecycle.getState(),\n entity: corePlugins.entity.getState(),\n selection: corePlugins.selection.getState(),\n contextMenu: corePlugins.contextMenu.getState(),\n undo: corePlugins.undo.getState(),\n };\n}\n\n/**\n * @internal Export for test only\n * A fallback function, always return original color\n */\nexport function getDarkColorFallback(color: string) {\n return color;\n}\n"]}
|
|
@@ -2,7 +2,7 @@ import type { IEditor, ModelToDomOption, ModelToTextCallbacks } from 'roosterjs-
|
|
|
2
2
|
/**
|
|
3
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 Specify HTML to get HTML.
|
|
5
|
+
* @param mode Specify HTML to get HTML.
|
|
6
6
|
* @param options @optional Options for Model to DOM conversion
|
|
7
7
|
*/
|
|
8
8
|
export declare function exportContent(editor: IEditor, mode?: 'HTML', options?: ModelToDomOption): string;
|
|
@@ -10,9 +10,9 @@ export declare function exportContent(editor: IEditor, mode?: 'HTML', options?:
|
|
|
10
10
|
* Export HTML content. If there are entities, this will cause EntityOperation event with option = 'replaceTemporaryContent' to get a dehydrated entity.
|
|
11
11
|
* This is a fast version, it retrieve HTML content directly from editor without going through content model conversion.
|
|
12
12
|
* @param editor The editor to get content from
|
|
13
|
-
* @param mode Specify HTMLFast to get HTML result.
|
|
13
|
+
* @param mode Specify HTMLFast to get HTML result. This is the default option
|
|
14
14
|
*/
|
|
15
|
-
export declare function exportContent(editor: IEditor, mode
|
|
15
|
+
export declare function exportContent(editor: IEditor, mode?: 'HTMLFast'): string;
|
|
16
16
|
/**
|
|
17
17
|
* Export plain text content
|
|
18
18
|
* @param editor The editor to get content from
|
|
@@ -2,7 +2,7 @@ import { contentModelToDom, contentModelToText, createModelToDomContext, transfo
|
|
|
2
2
|
// Here I didn't add 'HTMLFast' to ExportContentMode type because it will make this a breaking change and EditorAdapter will see build time error without bumping version
|
|
3
3
|
// Once we are confident that 'HTMLFast' is stable, we can fully switch 'HTML' to use the 'HTMLFast' approach
|
|
4
4
|
export function exportContent(editor, mode, optionsOrCallbacks) {
|
|
5
|
-
if (mode === void 0) { mode = '
|
|
5
|
+
if (mode === void 0) { mode = 'HTMLFast'; }
|
|
6
6
|
var model;
|
|
7
7
|
switch (mode) {
|
|
8
8
|
case 'PlainTextFast':
|
|
@@ -11,6 +11,7 @@ export function exportContent(editor, mode, optionsOrCallbacks) {
|
|
|
11
11
|
model = editor.getContentModelCopy('clean');
|
|
12
12
|
return contentModelToText(model, undefined /*separator*/, optionsOrCallbacks);
|
|
13
13
|
case 'HTMLFast':
|
|
14
|
+
default:
|
|
14
15
|
var clonedRoot = editor.getDOMHelper().getClonedRoot();
|
|
15
16
|
if (editor.isDarkMode()) {
|
|
16
17
|
transformColor(clonedRoot, false /*includeSelf*/, 'darkToLight', editor.getColorManager(), {
|
|
@@ -19,7 +20,6 @@ export function exportContent(editor, mode, optionsOrCallbacks) {
|
|
|
19
20
|
}
|
|
20
21
|
return getHTMLFromDOM(editor, clonedRoot);
|
|
21
22
|
case 'HTML':
|
|
22
|
-
default:
|
|
23
23
|
model = editor.getContentModelCopy('clean');
|
|
24
24
|
var doc = editor.getDocument();
|
|
25
25
|
var div = doc.createElement('div');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exportContent.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/command/exportContent/exportContent.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,iBAAiB,EACjB,kBAAkB,EAClB,uBAAuB,EACvB,cAAc,GACjB,MAAM,6BAA6B,CAAC;AA6CrC,yKAAyK;AACzK,6GAA6G;AAC7G,MAAM,UAAU,aAAa,CACzB,MAAe,EACf,
|
|
1
|
+
{"version":3,"file":"exportContent.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/command/exportContent/exportContent.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,iBAAiB,EACjB,kBAAkB,EAClB,uBAAuB,EACvB,cAAc,GACjB,MAAM,6BAA6B,CAAC;AA6CrC,yKAAyK;AACzK,6GAA6G;AAC7G,MAAM,UAAU,aAAa,CACzB,MAAe,EACf,IAAiD,EACjD,kBAA4D;IAD5D,qBAAA,EAAA,iBAAiD;IAGjD,IAAI,KAA2B,CAAC;IAEhC,QAAQ,IAAI,EAAE;QACV,KAAK,eAAe;YAChB,OAAO,MAAM,CAAC,YAAY,EAAE,CAAC,cAAc,EAAE,CAAC;QAClD,KAAK,WAAW;YACZ,KAAK,GAAG,MAAM,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC;YAE5C,OAAO,kBAAkB,CACrB,KAAK,EACL,SAAS,CAAC,aAAa,EACvB,kBAA0C,CAC7C,CAAC;QAEN,KAAK,UAAU,CAAC;QAChB;YACI,IAAM,UAAU,GAAG,MAAM,CAAC,YAAY,EAAE,CAAC,aAAa,EAAE,CAAC;YAEzD,IAAI,MAAM,CAAC,UAAU,EAAE,EAAE;gBACrB,cAAc,CACV,UAAU,EACV,KAAK,CAAC,eAAe,EACrB,aAAa,EACb,MAAM,CAAC,eAAe,EAAE,EACxB;oBACI,YAAY,EAAE,MAAM,CAAC,4BAA4B,CAC7C,4BAA4B,CAC/B;iBACJ,CACJ,CAAC;aACL;YAED,OAAO,cAAc,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;QAE9C,KAAK,MAAM;YACP,KAAK,GAAG,MAAM,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC;YAE5C,IAAM,GAAG,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC;YACjC,IAAM,GAAG,GAAG,GAAG,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;YAErC,iBAAiB,CACb,GAAG,EACH,GAAG,EACH,KAAK,EACL,uBAAuB,CACnB,SAAS,CAAC,iBAAiB,EAC3B,kBAAsC,CACzC,CACJ,CAAC;YAEF,OAAO,cAAc,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KAC1C;AACL,CAAC;AAED,SAAS,cAAc,CAAC,MAAe,EAAE,IAAiB;IACtD,MAAM,CAAC,YAAY,CAAC,uBAAuB,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IAEvF,OAAO,IAAI,CAAC,SAAS,CAAC;AAC1B,CAAC","sourcesContent":["import {\n contentModelToDom,\n contentModelToText,\n createModelToDomContext,\n transformColor,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelDocument,\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 HTML.\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 HTML content. If there are entities, this will cause EntityOperation event with option = 'replaceTemporaryContent' to get a dehydrated entity.\n * This is a fast version, it retrieve HTML content directly from editor without going through content model conversion.\n * @param editor The editor to get content from\n * @param mode Specify HTMLFast to get HTML result. This is the default option\n */\nexport function exportContent(editor: IEditor, mode?: 'HTMLFast'): 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\n// Here I didn't add 'HTMLFast' to ExportContentMode type because it will make this a breaking change and EditorAdapter will see build time error without bumping version\n// Once we are confident that 'HTMLFast' is stable, we can fully switch 'HTML' to use the 'HTMLFast' approach\nexport function exportContent(\n editor: IEditor,\n mode: ExportContentMode | 'HTMLFast' = 'HTMLFast',\n optionsOrCallbacks?: ModelToDomOption | ModelToTextCallbacks\n): string {\n let model: ContentModelDocument;\n\n switch (mode) {\n case 'PlainTextFast':\n return editor.getDOMHelper().getTextContent();\n case 'PlainText':\n model = editor.getContentModelCopy('clean');\n\n return contentModelToText(\n model,\n undefined /*separator*/,\n optionsOrCallbacks as ModelToTextCallbacks\n );\n\n case 'HTMLFast':\n default:\n const clonedRoot = editor.getDOMHelper().getClonedRoot();\n\n if (editor.isDarkMode()) {\n transformColor(\n clonedRoot,\n false /*includeSelf*/,\n 'darkToLight',\n editor.getColorManager(),\n {\n tableBorders: editor.isExperimentalFeatureEnabled(\n 'TransformTableBorderColors'\n ),\n }\n );\n }\n\n return getHTMLFromDOM(editor, clonedRoot);\n\n case 'HTML':\n model = editor.getContentModelCopy('clean');\n\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 return getHTMLFromDOM(editor, div);\n }\n}\n\nfunction getHTMLFromDOM(editor: IEditor, root: HTMLElement): string {\n editor.triggerEvent('extractContentWithDom', { clonedRoot: root }, true /*broadcast*/);\n\n return root.innerHTML;\n}\n"]}
|
|
@@ -5,10 +5,10 @@ import { getRootComputedStyleForContext } from './getRootComputedStyleForContext
|
|
|
5
5
|
* Create a EditorContext object used by ContentModel API
|
|
6
6
|
*/
|
|
7
7
|
export var createEditorContext = function (core, saveIndex) {
|
|
8
|
-
var _a, _b
|
|
8
|
+
var _a, _b;
|
|
9
9
|
var lifecycle = core.lifecycle, format = core.format, darkColorHandler = core.darkColorHandler, logicalRoot = core.logicalRoot, cache = core.cache, domHelper = core.domHelper;
|
|
10
10
|
saveIndex = saveIndex && !core.lifecycle.shadowEditFragment;
|
|
11
|
-
var context = __assign({ isDarkMode: lifecycle.isDarkMode, defaultFormat: format.defaultFormat, pendingFormat: (_a = format.pendingFormat) !== null && _a !== void 0 ? _a : undefined, darkColorHandler: darkColorHandler, addDelimiterForEntity: true, allowCacheElement: true,
|
|
11
|
+
var context = __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(), experimentalFeatures: (_b = core.experimentalFeatures) !== null && _b !== void 0 ? _b : [], paragraphMap: core.cache.paragraphMap, editorViewWidth: domHelper.getClientWidth() }, getRootComputedStyleForContext(logicalRoot.ownerDocument));
|
|
12
12
|
if (core.domHelper.isRightToLeft()) {
|
|
13
13
|
context.isRootRtl = true;
|
|
14
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createEditorContext.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/coreApi/createEditorContext/createEditorContext.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,8BAA8B,EAAE,MAAM,kCAAkC,CAAC;AAGlF;;;GAGG;AACH,MAAM,CAAC,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,cACT,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,
|
|
1
|
+
{"version":3,"file":"createEditorContext.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/coreApi/createEditorContext/createEditorContext.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,8BAA8B,EAAE,MAAM,kCAAkC,CAAC;AAGlF;;;GAGG;AACH,MAAM,CAAC,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,cACT,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,EACzC,oBAAoB,EAAE,MAAA,IAAI,CAAC,oBAAoB,mCAAI,EAAE,EACrD,YAAY,EAAE,IAAI,CAAC,KAAK,CAAC,YAAY,EACrC,eAAe,EAAE,SAAS,CAAC,cAAc,EAAE,IACxC,8BAA8B,CAAC,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","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 experimentalFeatures: core.experimentalFeatures ?? [],\n paragraphMap: core.cache.paragraphMap,\n editorViewWidth: domHelper.getClientWidth(),\n ...getRootComputedStyleForContext(logicalRoot.ownerDocument),\n };\n\n if (core.domHelper.isRightToLeft()) {\n context.isRootRtl = true;\n }\n\n return context;\n};\n"]}
|
|
@@ -2,7 +2,6 @@ import { getColor, getRangesByText, isBlockElement, isNodeOfType, parseValueWith
|
|
|
2
2
|
var DOMHelperImpl = /** @class */ (function () {
|
|
3
3
|
function DOMHelperImpl(contentDiv, options) {
|
|
4
4
|
this.contentDiv = contentDiv;
|
|
5
|
-
this.options = options;
|
|
6
5
|
}
|
|
7
6
|
DOMHelperImpl.prototype.queryElements = function (selector) {
|
|
8
7
|
return toArray(this.contentDiv.querySelectorAll(selector));
|
|
@@ -91,14 +90,9 @@ var DOMHelperImpl = /** @class */ (function () {
|
|
|
91
90
|
* Get a deep cloned root element
|
|
92
91
|
*/
|
|
93
92
|
DOMHelperImpl.prototype.getClonedRoot = function () {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
return clone;
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
return this.contentDiv.cloneNode(true /*deep*/);
|
|
101
|
-
}
|
|
93
|
+
var doc = this.contentDiv.ownerDocument.implementation.createHTMLDocument();
|
|
94
|
+
var clone = doc.importNode(this.contentDiv, true /*deep*/);
|
|
95
|
+
return clone;
|
|
102
96
|
};
|
|
103
97
|
/**
|
|
104
98
|
* Get format of the container element
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DOMHelperImpl.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/editor/core/DOMHelperImpl.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,QAAQ,EACR,eAAe,EACf,cAAc,EACd,YAAY,EACZ,kBAAkB,EAClB,OAAO,GACV,MAAM,6BAA6B,CAAC;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UAAuB,EACvB,OAAiC;IAAjC,wBAAA,EAAA,YAAiC;IAEjC,OAAO,IAAI,aAAa,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;AAClD,CAAC","sourcesContent":["import {\n getColor,\n getRangesByText,\n isBlockElement,\n isNodeOfType,\n parseValueWithUnit,\n toArray,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelSegmentFormat,\n DarkColorHandler,\n DOMHelper,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport interface DOMHelperImplOption {\n cloneIndependentRoot?: boolean;\n}\n\nclass DOMHelperImpl implements DOMHelper {\n constructor(private contentDiv: HTMLElement, private options: DOMHelperImplOption) {}\n\n queryElements(selector: string): HTMLElement[] {\n return toArray(this.contentDiv.querySelectorAll(selector)) as HTMLElement[];\n }\n\n getTextContent(): string {\n return this.contentDiv.textContent || '';\n }\n\n isNodeInEditor(node: Node, excludeRoot?: boolean): boolean {\n return excludeRoot && node == this.contentDiv ? false : this.contentDiv.contains(node);\n }\n\n calculateZoomScale(): number {\n const originalWidth = this.contentDiv.getBoundingClientRect()?.width || 0;\n const visualWidth = this.contentDiv.offsetWidth;\n\n return visualWidth > 0 && originalWidth > 0\n ? Math.round((originalWidth / visualWidth) * 100) / 100\n : 1;\n }\n\n setDomAttribute(name: string, value: string | null) {\n if (value === null) {\n this.contentDiv.removeAttribute(name);\n } else {\n this.contentDiv.setAttribute(name, value);\n }\n }\n\n getDomAttribute(name: string): string | null {\n return this.contentDiv.getAttribute(name);\n }\n\n getDomStyle<T extends keyof CSSStyleDeclaration>(style: T): CSSStyleDeclaration[T] {\n return this.contentDiv.style[style];\n }\n\n findClosestElementAncestor(startFrom: Node, selector?: string): HTMLElement | null {\n const startElement = isNodeOfType(startFrom, 'ELEMENT_NODE')\n ? startFrom\n : startFrom.parentElement;\n const closestElement = selector\n ? (startElement?.closest(selector) as HTMLElement | null)\n : startElement;\n\n return closestElement &&\n this.isNodeInEditor(closestElement) &&\n closestElement != this.contentDiv\n ? closestElement\n : null;\n }\n\n /**\n * Find the closest block element ancestor from the given node within current editing scope\n * @param startFrom The node to start the search from\n * @returns The closest block element ancestor\n */\n findClosestBlockElement(startFrom: Node): HTMLElement {\n let node: Node | null = startFrom;\n\n while (node && this.isNodeInEditor(node)) {\n if (isNodeOfType(node, 'ELEMENT_NODE') && isBlockElement(node)) {\n return node;\n }\n\n node = node.parentElement;\n }\n\n return this.contentDiv;\n }\n\n hasFocus(): boolean {\n const activeElement = this.contentDiv.ownerDocument.activeElement;\n return !!(activeElement && this.contentDiv.contains(activeElement));\n }\n\n /**\n * Check if the root element is in RTL mode\n */\n isRightToLeft(): boolean {\n const contentDiv = this.contentDiv;\n const style = contentDiv.ownerDocument.defaultView?.getComputedStyle(contentDiv);\n\n return style?.direction == 'rtl';\n }\n\n /**\n * Get the width of the editable area of the editor content div\n */\n getClientWidth(): number {\n const contentDiv = this.contentDiv;\n const style = contentDiv.ownerDocument.defaultView?.getComputedStyle(contentDiv);\n const paddingLeft = parseValueWithUnit(style?.paddingLeft);\n const paddingRight = parseValueWithUnit(style?.paddingRight);\n return this.contentDiv.clientWidth - (paddingLeft + paddingRight);\n }\n\n /**\n * Get a deep cloned root element\n */\n getClonedRoot(): HTMLElement {\n if (this.options.cloneIndependentRoot) {\n const doc = this.contentDiv.ownerDocument.implementation.createHTMLDocument();\n const clone = doc.importNode(this.contentDiv, true /*deep*/);\n\n return clone;\n } else {\n return this.contentDiv.cloneNode(true /*deep*/) as HTMLElement;\n }\n }\n\n /**\n * Get format of the container element\n * @param isInDarkMode Optional flag to indicate if the environment is in dark mode\n * @param darkColorHandler Optional DarkColorHandler to retrieve dark mode colors\n */\n getContainerFormat(\n isInDarkMode?: boolean,\n darkColorHandler?: DarkColorHandler\n ): ContentModelSegmentFormat {\n const window = this.contentDiv.ownerDocument.defaultView;\n\n const style = window?.getComputedStyle(this.contentDiv);\n\n return style\n ? {\n fontSize: style.fontSize,\n fontFamily: style.fontFamily,\n fontWeight: style.fontWeight,\n textColor: getColor(\n this.contentDiv,\n false /*isBackgroundColor*/,\n !!isInDarkMode,\n darkColorHandler,\n style.color\n ),\n backgroundColor: getColor(\n this.contentDiv,\n true /*isBackgroundColor*/,\n !!isInDarkMode,\n darkColorHandler,\n style.backgroundColor\n ),\n italic: style.fontStyle == 'italic',\n letterSpacing: style.letterSpacing,\n lineHeight: style.lineHeight,\n strikethrough: style.textDecoration?.includes('line-through'),\n superOrSubScriptSequence: style.verticalAlign,\n underline: style.textDecoration?.includes('underline'),\n }\n : {};\n }\n\n /**\n * Get text ranges by searching for a specific text, with options to match case and whole word.\n * This will only search within editable elements.\n * @param text The text to search for\n * @param matchCase Whether to match case\n * @param wholeWord Whether to match whole word\n * @returns An array of Ranges that match the search criteria\n */\n getRangesByText(text: string, matchCase: boolean, wholeWord: boolean): Range[] {\n return getRangesByText(this.contentDiv, text, matchCase, wholeWord, true /*editableOnly*/);\n }\n}\n\n/**\n * @internal Create new instance of DOMHelper\n */\nexport function createDOMHelper(\n contentDiv: HTMLElement,\n options: DOMHelperImplOption = {}\n): DOMHelper {\n return new DOMHelperImpl(contentDiv, options);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"DOMHelperImpl.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/editor/core/DOMHelperImpl.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,QAAQ,EACR,eAAe,EACf,cAAc,EACd,YAAY,EACZ,kBAAkB,EAClB,OAAO,GACV,MAAM,6BAA6B,CAAC;AAiBrC;IACI,uBAAoB,UAAuB,EAAE,OAA6B;QAAtD,eAAU,GAAV,UAAU,CAAa;IAAkC,CAAC;IAE9E,qCAAa,GAAb,UAAc,QAAgB;QAC1B,OAAO,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAkB,CAAC;IAChF,CAAC;IAED,sCAAc,GAAd;QACI,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,IAAI,EAAE,C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IAAI,CAAC,UAAU,EACf,IAAI,CAAC,qBAAqB,EAC1B,CAAC,CAAC,YAAY,EACd,gBAAgB,EAChB,KAAK,CAAC,eAAe,CACxB;gBACD,MAAM,EAAE,KAAK,CAAC,SAAS,IAAI,QAAQ;gBACnC,aAAa,EAAE,KAAK,CAAC,aAAa;gBAClC,UAAU,EAAE,KAAK,CAAC,UAAU;gBAC5B,aAAa,EAAE,MAAA,KAAK,CAAC,cAAc,0CAAE,QAAQ,CAAC,cAAc,CAAC;gBAC7D,wBAAwB,EAAE,KAAK,CAAC,aAAa;gBAC7C,SAAS,EAAE,MAAA,KAAK,CAAC,cAAc,0CAAE,QAAQ,CAAC,WAAW,CAAC;aACzD;YACH,CAAC,CAAC,EAAE,CAAC;IACb,CAAC;IAED;;;;;;;OAOG;IACH,uCAAe,GAAf,UAAgB,IAAY,EAAE,SAAkB,EAAE,SAAkB;QAChE,OAAO,eAAe,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC;IAC/F,CAAC;IACL,oBAAC;AAAD,CAAC,AAnKD,IAmKC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAC3B,UAAuB,EACvB,OAAiC;IAAjC,wBAAA,EAAA,YAAiC;IAEjC,OAAO,IAAI,aAAa,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;AAClD,CAAC","sourcesContent":["import {\n getColor,\n getRangesByText,\n isBlockElement,\n isNodeOfType,\n parseValueWithUnit,\n toArray,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelSegmentFormat,\n DarkColorHandler,\n DOMHelper,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport interface DOMHelperImplOption {\n /**\n * @deprecated This is always treated as true now\n */\n cloneIndependentRoot?: boolean;\n}\n\nclass DOMHelperImpl implements DOMHelper {\n constructor(private contentDiv: HTMLElement, options?: DOMHelperImplOption) {}\n\n queryElements(selector: string): HTMLElement[] {\n return toArray(this.contentDiv.querySelectorAll(selector)) as HTMLElement[];\n }\n\n getTextContent(): string {\n return this.contentDiv.textContent || '';\n }\n\n isNodeInEditor(node: Node, excludeRoot?: boolean): boolean {\n return excludeRoot && node == this.contentDiv ? false : this.contentDiv.contains(node);\n }\n\n calculateZoomScale(): number {\n const originalWidth = this.contentDiv.getBoundingClientRect()?.width || 0;\n const visualWidth = this.contentDiv.offsetWidth;\n\n return visualWidth > 0 && originalWidth > 0\n ? Math.round((originalWidth / visualWidth) * 100) / 100\n : 1;\n }\n\n setDomAttribute(name: string, value: string | null) {\n if (value === null) {\n this.contentDiv.removeAttribute(name);\n } else {\n this.contentDiv.setAttribute(name, value);\n }\n }\n\n getDomAttribute(name: string): string | null {\n return this.contentDiv.getAttribute(name);\n }\n\n getDomStyle<T extends keyof CSSStyleDeclaration>(style: T): CSSStyleDeclaration[T] {\n return this.contentDiv.style[style];\n }\n\n findClosestElementAncestor(startFrom: Node, selector?: string): HTMLElement | null {\n const startElement = isNodeOfType(startFrom, 'ELEMENT_NODE')\n ? startFrom\n : startFrom.parentElement;\n const closestElement = selector\n ? (startElement?.closest(selector) as HTMLElement | null)\n : startElement;\n\n return closestElement &&\n this.isNodeInEditor(closestElement) &&\n closestElement != this.contentDiv\n ? closestElement\n : null;\n }\n\n /**\n * Find the closest block element ancestor from the given node within current editing scope\n * @param startFrom The node to start the search from\n * @returns The closest block element ancestor\n */\n findClosestBlockElement(startFrom: Node): HTMLElement {\n let node: Node | null = startFrom;\n\n while (node && this.isNodeInEditor(node)) {\n if (isNodeOfType(node, 'ELEMENT_NODE') && isBlockElement(node)) {\n return node;\n }\n\n node = node.parentElement;\n }\n\n return this.contentDiv;\n }\n\n hasFocus(): boolean {\n const activeElement = this.contentDiv.ownerDocument.activeElement;\n return !!(activeElement && this.contentDiv.contains(activeElement));\n }\n\n /**\n * Check if the root element is in RTL mode\n */\n isRightToLeft(): boolean {\n const contentDiv = this.contentDiv;\n const style = contentDiv.ownerDocument.defaultView?.getComputedStyle(contentDiv);\n\n return style?.direction == 'rtl';\n }\n\n /**\n * Get the width of the editable area of the editor content div\n */\n getClientWidth(): number {\n const contentDiv = this.contentDiv;\n const style = contentDiv.ownerDocument.defaultView?.getComputedStyle(contentDiv);\n const paddingLeft = parseValueWithUnit(style?.paddingLeft);\n const paddingRight = parseValueWithUnit(style?.paddingRight);\n return this.contentDiv.clientWidth - (paddingLeft + paddingRight);\n }\n\n /**\n * Get a deep cloned root element\n */\n getClonedRoot(): HTMLElement {\n const doc = this.contentDiv.ownerDocument.implementation.createHTMLDocument();\n const clone = doc.importNode(this.contentDiv, true /*deep*/);\n\n return clone;\n }\n\n /**\n * Get format of the container element\n * @param isInDarkMode Optional flag to indicate if the environment is in dark mode\n * @param darkColorHandler Optional DarkColorHandler to retrieve dark mode colors\n */\n getContainerFormat(\n isInDarkMode?: boolean,\n darkColorHandler?: DarkColorHandler\n ): ContentModelSegmentFormat {\n const window = this.contentDiv.ownerDocument.defaultView;\n\n const style = window?.getComputedStyle(this.contentDiv);\n\n return style\n ? {\n fontSize: style.fontSize,\n fontFamily: style.fontFamily,\n fontWeight: style.fontWeight,\n textColor: getColor(\n this.contentDiv,\n false /*isBackgroundColor*/,\n !!isInDarkMode,\n darkColorHandler,\n style.color\n ),\n backgroundColor: getColor(\n this.contentDiv,\n true /*isBackgroundColor*/,\n !!isInDarkMode,\n darkColorHandler,\n style.backgroundColor\n ),\n italic: style.fontStyle == 'italic',\n letterSpacing: style.letterSpacing,\n lineHeight: style.lineHeight,\n strikethrough: style.textDecoration?.includes('line-through'),\n superOrSubScriptSequence: style.verticalAlign,\n underline: style.textDecoration?.includes('underline'),\n }\n : {};\n }\n\n /**\n * Get text ranges by searching for a specific text, with options to match case and whole word.\n * This will only search within editable elements.\n * @param text The text to search for\n * @param matchCase Whether to match case\n * @param wholeWord Whether to match whole word\n * @returns An array of Ranges that match the search criteria\n */\n getRangesByText(text: string, matchCase: boolean, wholeWord: boolean): Range[] {\n return getRangesByText(this.contentDiv, text, matchCase, wholeWord, true /*editableOnly*/);\n }\n}\n\n/**\n * @internal Create new instance of DOMHelper\n */\nexport function createDOMHelper(\n contentDiv: HTMLElement,\n options: DOMHelperImplOption = {}\n): DOMHelper {\n return new DOMHelperImpl(contentDiv, options);\n}\n"]}
|
|
@@ -11,7 +11,7 @@ import { createEditorCorePlugins } from '../../corePlugin/createEditorCorePlugin
|
|
|
11
11
|
* @param options Editor options
|
|
12
12
|
*/
|
|
13
13
|
export function createEditorCore(contentDiv, options) {
|
|
14
|
-
var _a, _b
|
|
14
|
+
var _a, _b;
|
|
15
15
|
var corePlugins = createEditorCorePlugins(options, contentDiv);
|
|
16
16
|
var domCreator = createDOMCreator(options.trustedHTMLHandler);
|
|
17
17
|
return __assign(__assign({ physicalRoot: contentDiv, logicalRoot: contentDiv, api: __assign(__assign({}, coreApiMap), options.coreApiOverride), originalApi: __assign({}, coreApiMap), plugins: __spreadArray(__spreadArray([
|
|
@@ -27,9 +27,7 @@ export function createEditorCore(contentDiv, options) {
|
|
|
27
27
|
corePlugins.lifecycle,
|
|
28
28
|
], false), environment: createEditorEnvironment(contentDiv, options), darkColorHandler: createDarkColorHandler(contentDiv, (_b = options.getDarkColor) !== null && _b !== void 0 ? _b : getDarkColorFallback, options.knownColors, options.generateColorKey), trustedHTMLHandler: options.trustedHTMLHandler && !isDOMCreator(options.trustedHTMLHandler)
|
|
29
29
|
? options.trustedHTMLHandler
|
|
30
|
-
: createTrustedHTMLHandler(domCreator), domCreator: domCreator, domHelper: createDOMHelper(contentDiv, {
|
|
31
|
-
cloneIndependentRoot: (_c = options.experimentalFeatures) === null || _c === void 0 ? void 0 : _c.includes('CloneIndependentRoot'),
|
|
32
|
-
}) }, getPluginState(corePlugins)), { disposeErrorHandler: options.disposeErrorHandler, onFixUpModel: options.onFixUpModel, experimentalFeatures: options.experimentalFeatures ? __spreadArray([], __read(options.experimentalFeatures), false) : [] });
|
|
30
|
+
: createTrustedHTMLHandler(domCreator), domCreator: domCreator, domHelper: createDOMHelper(contentDiv) }, getPluginState(corePlugins)), { disposeErrorHandler: options.disposeErrorHandler, onFixUpModel: options.onFixUpModel, experimentalFeatures: options.experimentalFeatures ? __spreadArray([], __read(options.experimentalFeatures), false) : [] });
|
|
33
31
|
}
|
|
34
32
|
function createEditorEnvironment(contentDiv, options) {
|
|
35
33
|
var _a, _b, _c;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createEditorCore.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/editor/core/createEditorCore.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAClG,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACnG,OAAO,EAAE,uBAAuB,EAAE,MAAM,0CAA0C,CAAC;AASnF;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,UAA0B,EAAE,OAAsB;;IAC/E,IAAM,WAAW,GAAG,uBAAuB,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;IACjE,IAAM,UAAU,GAAG,gBAAgB,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAEhE,2BACI,YAAY,EAAE,UAAU,EACxB,WAAW,EAAE,UAAU,EACvB,GAAG,wBAAO,UAAU,GAAK,OAAO,CAAC,eAAe,GAChD,WAAW,eAAO,UAAU,GAC5B,OAAO;YACH,WAAW,CAAC,KAAK;YACjB,WAAW,CAAC,MAAM;YAClB,WAAW,CAAC,SAAS;YACrB,WAAW,CAAC,QAAQ;YACpB,WAAW,CAAC,SAAS;YACrB,WAAW,CAAC,MAAM;kBACf,CAAC,MAAA,OAAO,CAAC,OAAO,mCAAI,EAAE,CAAC,CAAC,MAAM,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,CAAC,EAAH,CAAG,CAAC;YAC3C,WAAW,CAAC,IAAI;YAChB,WAAW,CAAC,WAAW;YACvB,WAAW,CAAC,SAAS;mBAEzB,WAAW,EAAE,uBAAuB,CAAC,UAAU,EAAE,OAAO,CAAC,EACzD,gBAAgB,EAAE,sBAAsB,CACpC,UAAU,EACV,MAAA,OAAO,CAAC,YAAY,mCAAI,oBAAoB,EAC5C,OAAO,CAAC,WAAW,EACnB,OAAO,CAAC,gBAAgB,CAC3B,EACD,kBAAkB,EACd,OAAO,CAAC,kBAAkB,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,kBAAkB,CAAC;YACnE,CAAC,CAAC,OAAO,CAAC,kBAAkB;YAC5B,CAAC,CAAC,wBAAwB,CAAC,UAAU,CAAC,EAC9C,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,eAAe,CAAC,UAAU,
|
|
1
|
+
{"version":3,"file":"createEditorCore.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/editor/core/createEditorCore.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAClG,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACnG,OAAO,EAAE,uBAAuB,EAAE,MAAM,0CAA0C,CAAC;AASnF;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,UAA0B,EAAE,OAAsB;;IAC/E,IAAM,WAAW,GAAG,uBAAuB,CAAC,OAAO,EAAE,UAAU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AAO;QACH,QAAQ,EAAE,WAAW,CAAC,QAAQ,CAAC,QAAQ,EAAE;QACzC,SAAS,EAAE,WAAW,CAAC,SAAS,CAAC,QAAQ,EAAE;QAC3C,KAAK,EAAE,WAAW,CAAC,KAAK,CAAC,QAAQ,EAAE;QACnC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,QAAQ,EAAE;QACrC,SAAS,EAAE,WAAW,CAAC,SAAS,CAAC,QAAQ,EAAE;QAC3C,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,QAAQ,EAAE;QACrC,SAAS,EAAE,WAAW,CAAC,SAAS,CAAC,QAAQ,EAAE;QAC3C,WAAW,EAAE,WAAW,CAAC,WAAW,CAAC,QAAQ,EAAE;QAC/C,IAAI,EAAE,WAAW,CAAC,IAAI,CAAC,QAAQ,EAAE;KACpC,CAAC;AACN,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAa;IAC9C,OAAO,KAAK,CAAC;AACjB,CAAC","sourcesContent":["import { coreApiMap } from '../../coreApi/coreApiMap';\nimport { createDarkColorHandler } from './DarkColorHandlerImpl';\nimport { createDOMCreator, createTrustedHTMLHandler, isDOMCreator } from '../../utils/domCreator';\nimport { createDOMHelper } from './DOMHelperImpl';\nimport { createDomToModelSettings, createModelToDomSettings } from './createEditorDefaultSettings';\nimport { createEditorCorePlugins } from '../../corePlugin/createEditorCorePlugins';\nimport type {\n EditorEnvironment,\n PluginState,\n EditorCore,\n EditorCorePlugins,\n EditorOptions,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal Create core object for editor\n * @param contentDiv Editor content DIV\n * @param options Editor options\n */\nexport function createEditorCore(contentDiv: HTMLDivElement, options: EditorOptions): EditorCore {\n const corePlugins = createEditorCorePlugins(options, contentDiv);\n const domCreator = createDOMCreator(options.trustedHTMLHandler);\n\n return {\n physicalRoot: contentDiv,\n logicalRoot: contentDiv,\n api: { ...coreApiMap, ...options.coreApiOverride },\n originalApi: { ...coreApiMap },\n plugins: [\n corePlugins.cache,\n corePlugins.format,\n corePlugins.copyPaste,\n corePlugins.domEvent,\n corePlugins.selection,\n corePlugins.entity,\n ...(options.plugins ?? []).filter(x => !!x),\n corePlugins.undo,\n corePlugins.contextMenu,\n corePlugins.lifecycle,\n ],\n environment: createEditorEnvironment(contentDiv, options),\n darkColorHandler: createDarkColorHandler(\n contentDiv,\n options.getDarkColor ?? getDarkColorFallback,\n options.knownColors,\n options.generateColorKey\n ),\n trustedHTMLHandler:\n options.trustedHTMLHandler && !isDOMCreator(options.trustedHTMLHandler)\n ? options.trustedHTMLHandler\n : createTrustedHTMLHandler(domCreator),\n domCreator: domCreator,\n domHelper: createDOMHelper(contentDiv),\n ...getPluginState(corePlugins),\n disposeErrorHandler: options.disposeErrorHandler,\n onFixUpModel: options.onFixUpModel,\n experimentalFeatures: options.experimentalFeatures ? [...options.experimentalFeatures] : [],\n };\n}\n\nfunction createEditorEnvironment(\n contentDiv: HTMLElement,\n options: EditorOptions\n): EditorEnvironment {\n const navigator = contentDiv.ownerDocument.defaultView?.navigator;\n const userAgent = navigator?.userAgent ?? '';\n const appVersion = navigator?.appVersion ?? '';\n\n return {\n document: contentDiv.ownerDocument,\n domToModelSettings: createDomToModelSettings(options),\n modelToDomSettings: createModelToDomSettings(options),\n isMac: appVersion.indexOf('Mac') != -1,\n isAndroid: /android/i.test(userAgent),\n isIOS: /iPad|iPhone/.test(userAgent),\n isSafari:\n userAgent.indexOf('AppleWebKit') >= 0 &&\n userAgent.indexOf('Chrome') < 0 &&\n userAgent.indexOf('Android') < 0,\n isMobileOrTablet: getIsMobileOrTablet(userAgent),\n };\n}\n\nfunction getIsMobileOrTablet(userAgent: string) {\n // Reference: http://detectmobilebrowsers.com/\n // The default regex on the website doesn't consider tablet.\n // To support tablet, add |android|ipad|playbook|silk to the first regex according to the info in /about page\n if (\n /(android|bb\\d+|meego).+mobile|avantgo|bada\\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i.test(\n userAgent\n ) ||\n /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\\-(n|u)|c55\\/|capi|ccwa|cdm\\-|cell|chtm|cldc|cmd\\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\\-s|devi|dica|dmob|do(c|p)o|ds(12|\\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\\-|_)|g1 u|g560|gene|gf\\-5|g\\-mo|go(\\.w|od)|gr(ad|un)|haie|hcit|hd\\-(m|p|t)|hei\\-|hi(pt|ta)|hp( i|ip)|hs\\-c|ht(c(\\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\\-(20|go|ma)|i230|iac( |\\-|\\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\\/)|klon|kpt |kwc\\-|kyo(c|k)|le(no|xi)|lg( g|\\/(k|l|u)|50|54|\\-[a-w])|libw|lynx|m1\\-w|m3ga|m50\\/|ma(te|ui|xo)|mc(01|21|ca)|m\\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\\-2|po(ck|rt|se)|prox|psio|pt\\-g|qa\\-a|qc(07|12|21|32|60|\\-[2-7]|i\\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\\-|oo|p\\-)|sdk\\/|se(c(\\-|0|1)|47|mc|nd|ri)|sgh\\-|shar|sie(\\-|m)|sk\\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\\-|v\\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\\-|tdg\\-|tel(i|m)|tim\\-|t\\-mo|to(pl|sh)|ts(70|m\\-|m3|m5)|tx\\-9|up(\\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\\-|your|zeto|zte\\-/i.test(\n userAgent.substring(0, 4)\n )\n ) {\n return true;\n }\n return false;\n}\n\nfunction getPluginState(corePlugins: EditorCorePlugins): PluginState {\n return {\n domEvent: corePlugins.domEvent.getState(),\n copyPaste: corePlugins.copyPaste.getState(),\n cache: corePlugins.cache.getState(),\n format: corePlugins.format.getState(),\n lifecycle: corePlugins.lifecycle.getState(),\n entity: corePlugins.entity.getState(),\n selection: corePlugins.selection.getState(),\n contextMenu: corePlugins.contextMenu.getState(),\n undo: corePlugins.undo.getState(),\n };\n}\n\n/**\n * @internal Export for test only\n * A fallback function, always return original color\n */\nexport function getDarkColorFallback(color: string) {\n return color;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
"description": "Core editor for roosterjs",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"tslib": "^2.3.1",
|
|
6
|
-
"roosterjs-content-model-dom": "^9.
|
|
7
|
-
"roosterjs-content-model-types": "^9.
|
|
6
|
+
"roosterjs-content-model-dom": "^9.51.0",
|
|
7
|
+
"roosterjs-content-model-types": "^9.51.0"
|
|
8
8
|
},
|
|
9
|
-
"version": "9.
|
|
9
|
+
"version": "9.51.0",
|
|
10
10
|
"main": "./lib/index.js",
|
|
11
11
|
"typings": "./lib/index.d.ts",
|
|
12
12
|
"module": "./lib-mjs/index.js",
|