roosterjs-content-model-core 9.32.0 → 9.34.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/createModelFromHtml/createDomToModelContextForSanitizing.js +1 -0
- package/lib/command/createModelFromHtml/createDomToModelContextForSanitizing.js.map +1 -1
- package/lib/command/exportContent/exportContent.d.ts +8 -1
- package/lib/command/exportContent/exportContent.js +22 -11
- package/lib/command/exportContent/exportContent.js.map +1 -1
- package/lib/command/paste/generatePasteOptionFromPlugins.js +2 -0
- package/lib/command/paste/generatePasteOptionFromPlugins.js.map +1 -1
- package/lib/coreApi/attachDomEvent/attachDomEvent.js +5 -3
- package/lib/coreApi/attachDomEvent/attachDomEvent.js.map +1 -1
- package/lib/editor/core/DOMHelperImpl.js +5 -3
- package/lib/editor/core/DOMHelperImpl.js.map +1 -1
- package/lib-amd/command/createModelFromHtml/createDomToModelContextForSanitizing.js +1 -0
- package/lib-amd/command/createModelFromHtml/createDomToModelContextForSanitizing.js.map +1 -1
- package/lib-amd/command/exportContent/exportContent.d.ts +8 -1
- package/lib-amd/command/exportContent/exportContent.js +22 -11
- package/lib-amd/command/exportContent/exportContent.js.map +1 -1
- package/lib-amd/command/paste/generatePasteOptionFromPlugins.js +2 -0
- package/lib-amd/command/paste/generatePasteOptionFromPlugins.js.map +1 -1
- package/lib-amd/coreApi/attachDomEvent/attachDomEvent.js +5 -3
- package/lib-amd/coreApi/attachDomEvent/attachDomEvent.js.map +1 -1
- package/lib-amd/editor/core/DOMHelperImpl.js +5 -3
- package/lib-amd/editor/core/DOMHelperImpl.js.map +1 -1
- package/lib-mjs/command/createModelFromHtml/createDomToModelContextForSanitizing.js +1 -0
- package/lib-mjs/command/createModelFromHtml/createDomToModelContextForSanitizing.js.map +1 -1
- package/lib-mjs/command/exportContent/exportContent.d.ts +8 -1
- package/lib-mjs/command/exportContent/exportContent.js +23 -12
- package/lib-mjs/command/exportContent/exportContent.js.map +1 -1
- package/lib-mjs/command/paste/generatePasteOptionFromPlugins.js +2 -0
- package/lib-mjs/command/paste/generatePasteOptionFromPlugins.js.map +1 -1
- package/lib-mjs/coreApi/attachDomEvent/attachDomEvent.js +5 -3
- package/lib-mjs/coreApi/attachDomEvent/attachDomEvent.js.map +1 -1
- package/lib-mjs/editor/core/DOMHelperImpl.js +6 -4
- package/lib-mjs/editor/core/DOMHelperImpl.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createDomToModelContextForSanitizing.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/command/createModelFromHtml/createDomToModelContextForSanitizing.ts"],"names":[],"mappings":";;;;AAAA,sFAAqF;AACrF,2EAAsE;AACtE,4EAAiF;AACjF,8EAAmF;AACnF,mHAAkH;AAClH,wFAAmF;AACnF,oFAAmF;AACnF,wEAAuE;AACvE,0FAAyF;AAQzF,IAAM,uBAAuB,GAAkC;IAC3D,iBAAiB,EAAE,EAAE;IACrB,oBAAoB,EAAE,EAAE;IACxB,uBAAuB,EAAE,EAAE;IAC3B,qBAAqB,EAAE,EAAE;IACzB,wBAAwB,EAAE,EAAE;IAC5B,eAAe,EAAE,EAAE;IACnB,mBAAmB,EAAE,EAAE;
|
|
1
|
+
{"version":3,"file":"createDomToModelContextForSanitizing.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/command/createModelFromHtml/createDomToModelContextForSanitizing.ts"],"names":[],"mappings":";;;;AAAA,sFAAqF;AACrF,2EAAsE;AACtE,4EAAiF;AACjF,8EAAmF;AACnF,mHAAkH;AAClH,wFAAmF;AACnF,oFAAmF;AACnF,wEAAuE;AACvE,0FAAyF;AAQzF,IAAM,uBAAuB,GAAkC;IAC3D,iBAAiB,EAAE,EAAE;IACrB,oBAAoB,EAAE,EAAE;IACxB,uBAAuB,EAAE,EAAE;IAC3B,qBAAqB,EAAE,EAAE;IACzB,wBAAwB,EAAE,EAAE;IAC5B,eAAe,EAAE,EAAE;IACnB,mBAAmB,EAAE,EAAE;IACvB,yBAAyB,EAAE,KAAK;CACnC,CAAC;AAEF;;GAEG;AACH,SAAgB,oCAAoC,CAChD,QAAkB,EAClB,aAAyC,EACzC,aAAgC,EAChC,0BAAmE;IAEnE,IAAM,gBAAgB,mDACf,uBAAuB,GACvB,0BAA0B,CAChC,CAAC;IAEF,OAAO,IAAA,qDAAuB,gDAEtB,aAAa,eAAA,IACV,IAAA,+DAA8B,EAAC,QAAQ,CAAC,KAC3C,oBAAoB,EAAE,EAAE,KAE5B,aAAa,EACb;QACI,iBAAiB,EAAE;YACf,OAAO,EAAE,uCAAkB;YAC3B,MAAM,EAAE,IAAA,iDAA0B,EAAC,gBAAgB,CAAC;YACpD,GAAG,EAAE,IAAA,mDAA2B,EAAC,gBAAgB,CAAC;SACrD;QACD,oBAAoB,EAAE;YAClB,OAAO,EAAE,mDAAwB;YACjC,UAAU,EAAE,yDAA2B;SAC1C;QACD,uBAAuB,EAAE;YACrB,SAAS,EAAE,CAAC,qDAAyB,CAAC;YACtC,MAAM,EAAE,CAAC,mDAAsB,CAAC;SACnC;KACJ,EACD,gBAAgB,CACnB,CAAC;AACN,CAAC;AAnCD,oFAmCC","sourcesContent":["import { containerSizeFormatParser } from '../../override/containerSizeFormatParser';\nimport { createDomToModelContext } from 'roosterjs-content-model-dom';\nimport { createPasteEntityProcessor } from '../../override/pasteEntityProcessor';\nimport { createPasteGeneralProcessor } from '../../override/pasteGeneralProcessor';\nimport { getRootComputedStyleForContext } from '../../coreApi/createEditorContext/getRootComputedStyleForContext';\nimport { pasteBlockEntityParser } from '../../override/pasteCopyBlockEntityParser';\nimport { pasteDisplayFormatParser } from '../../override/pasteDisplayFormatParser';\nimport { pasteTextProcessor } from '../../override/pasteTextProcessor';\nimport { pasteWhiteSpaceFormatParser } from '../../override/pasteWhiteSpaceFormatParser';\nimport type {\n ContentModelSegmentFormat,\n DomToModelContext,\n DomToModelOption,\n DomToModelOptionForSanitizing,\n} from 'roosterjs-content-model-types';\n\nconst DefaultSanitizingOption: DomToModelOptionForSanitizing = {\n processorOverride: {},\n formatParserOverride: {},\n additionalFormatParsers: {},\n additionalAllowedTags: [],\n additionalDisallowedTags: [],\n styleSanitizers: {},\n attributeSanitizers: {},\n processNonVisibleElements: false,\n};\n\n/**\n * @internal\n */\nexport function createDomToModelContextForSanitizing(\n document: Document,\n defaultFormat?: ContentModelSegmentFormat,\n defaultOption?: DomToModelOption,\n additionalSanitizingOption?: Partial<DomToModelOptionForSanitizing>\n): DomToModelContext {\n const sanitizingOption: DomToModelOptionForSanitizing = {\n ...DefaultSanitizingOption,\n ...additionalSanitizingOption,\n };\n\n return createDomToModelContext(\n {\n defaultFormat,\n ...getRootComputedStyleForContext(document),\n experimentalFeatures: [],\n },\n defaultOption,\n {\n processorOverride: {\n '#text': pasteTextProcessor,\n entity: createPasteEntityProcessor(sanitizingOption),\n '*': createPasteGeneralProcessor(sanitizingOption),\n },\n formatParserOverride: {\n display: pasteDisplayFormatParser,\n whiteSpace: pasteWhiteSpaceFormatParser,\n },\n additionalFormatParsers: {\n container: [containerSizeFormatParser],\n entity: [pasteBlockEntityParser],\n },\n },\n sanitizingOption\n );\n}\n"]}
|
|
@@ -2,10 +2,17 @@ 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
|
|
5
|
+
* @param mode Specify HTML to get HTML. This is the default option
|
|
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;
|
|
9
|
+
/**
|
|
10
|
+
* Export HTML content. If there are entities, this will cause EntityOperation event with option = 'replaceTemporaryContent' to get a dehydrated entity.
|
|
11
|
+
* This is a fast version, it retrieve HTML content directly from editor without going through content model conversion.
|
|
12
|
+
* @param editor The editor to get content from
|
|
13
|
+
* @param mode Specify HTMLFast to get HTML result.
|
|
14
|
+
*/
|
|
15
|
+
export declare function exportContent(editor: IEditor, mode: 'HTMLFast'): string;
|
|
9
16
|
/**
|
|
10
17
|
* Export plain text content
|
|
11
18
|
* @param editor The editor to get content from
|
|
@@ -2,24 +2,35 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.exportContent = void 0;
|
|
4
4
|
var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
|
|
5
|
+
// 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
|
+
// Once we are confident that 'HTMLFast' is stable, we can fully switch 'HTML' to use the 'HTMLFast' approach
|
|
5
7
|
function exportContent(editor, mode, optionsOrCallbacks) {
|
|
6
8
|
if (mode === void 0) { mode = 'HTML'; }
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
var model;
|
|
10
|
+
switch (mode) {
|
|
11
|
+
case 'PlainTextFast':
|
|
12
|
+
return editor.getDOMHelper().getTextContent();
|
|
13
|
+
case 'PlainText':
|
|
14
|
+
model = editor.getContentModelCopy('clean');
|
|
13
15
|
return (0, roosterjs_content_model_dom_1.contentModelToText)(model, undefined /*separator*/, optionsOrCallbacks);
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
case 'HTMLFast':
|
|
17
|
+
var clonedRoot = editor.getDOMHelper().getClonedRoot();
|
|
18
|
+
if (editor.isDarkMode()) {
|
|
19
|
+
(0, roosterjs_content_model_dom_1.transformColor)(clonedRoot, false /*includeSelf*/, 'darkToLight', editor.getColorManager());
|
|
20
|
+
}
|
|
21
|
+
return getHTMLFromDOM(editor, clonedRoot);
|
|
22
|
+
case 'HTML':
|
|
23
|
+
default:
|
|
24
|
+
model = editor.getContentModelCopy('clean');
|
|
16
25
|
var doc = editor.getDocument();
|
|
17
26
|
var div = doc.createElement('div');
|
|
18
27
|
(0, roosterjs_content_model_dom_1.contentModelToDom)(doc, div, model, (0, roosterjs_content_model_dom_1.createModelToDomContext)(undefined /*editorContext*/, optionsOrCallbacks));
|
|
19
|
-
editor
|
|
20
|
-
return div.innerHTML;
|
|
21
|
-
}
|
|
28
|
+
return getHTMLFromDOM(editor, div);
|
|
22
29
|
}
|
|
23
30
|
}
|
|
24
31
|
exports.exportContent = exportContent;
|
|
32
|
+
function getHTMLFromDOM(editor, root) {
|
|
33
|
+
editor.triggerEvent('extractContentWithDom', { clonedRoot: root }, true /*broadcast*/);
|
|
34
|
+
return root.innerHTML;
|
|
35
|
+
}
|
|
25
36
|
//# sourceMappingURL=exportContent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exportContent.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/command/exportContent/exportContent.ts"],"names":[],"mappings":";;;AAAA,
|
|
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,IAA6C,EAC7C,kBAA4D;IAD5D,qBAAA,EAAA,aAA6C;IAG7C,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;YACX,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,CAC3B,CAAC;aACL;YAED,OAAO,cAAc,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;QAE9C,KAAK,MAAM,CAAC;QACZ;YACI,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;AApDD,sCAoDC;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. This is the default option\n * @param options @optional Options for Model to DOM conversion\n */\nexport function exportContent(editor: IEditor, mode?: 'HTML', options?: ModelToDomOption): string;\n\n/**\n * Export 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.\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' = 'HTML',\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 const clonedRoot = editor.getDOMHelper().getClonedRoot();\n\n if (editor.isDarkMode()) {\n transformColor(\n clonedRoot,\n false /*includeSelf*/,\n 'darkToLight',\n editor.getColorManager()\n );\n }\n\n return getHTMLFromDOM(editor, clonedRoot);\n\n case 'HTML':\n default:\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"]}
|
|
@@ -14,6 +14,8 @@ function generatePasteOptionFromPlugins(editor, clipboardData, fragment, htmlFro
|
|
|
14
14
|
processorOverride: {},
|
|
15
15
|
styleSanitizers: {},
|
|
16
16
|
attributeSanitizers: {},
|
|
17
|
+
processNonVisibleElements: !!editor.getEnvironment().domToModelSettings.customized
|
|
18
|
+
.processNonVisibleElements,
|
|
17
19
|
};
|
|
18
20
|
var event = {
|
|
19
21
|
eventType: 'beforePaste',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generatePasteOptionFromPlugins.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/command/paste/generatePasteOptionFromPlugins.ts"],"names":[],"mappings":";;;AASA;;GAEG;AACH,SAAgB,8BAA8B,CAC1C,MAAe,EACf,aAA4B,EAC5B,QAA0B,EAC1B,iBAAoC,EACpC,SAAoB;;IAEpB,IAAM,gBAAgB,GAAkC;QACpD,qBAAqB,EAAE,EAAE;QACzB,wBAAwB,EAAE,EAAE;QAC5B,uBAAuB,EAAE,EAAE;QAC3B,oBAAoB,EAAE,EAAE;QACxB,iBAAiB,EAAE,EAAE;QACrB,eAAe,EAAE,EAAE;QACnB,mBAAmB,EAAE,EAAE;
|
|
1
|
+
{"version":3,"file":"generatePasteOptionFromPlugins.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/command/paste/generatePasteOptionFromPlugins.ts"],"names":[],"mappings":";;;AASA;;GAEG;AACH,SAAgB,8BAA8B,CAC1C,MAAe,EACf,aAA4B,EAC5B,QAA0B,EAC1B,iBAAoC,EACpC,SAAoB;;IAEpB,IAAM,gBAAgB,GAAkC;QACpD,qBAAqB,EAAE,EAAE;QACzB,wBAAwB,EAAE,EAAE;QAC5B,uBAAuB,EAAE,EAAE;QAC3B,oBAAoB,EAAE,EAAE;QACxB,iBAAiB,EAAE,EAAE;QACrB,eAAe,EAAE,EAAE;QACnB,mBAAmB,EAAE,EAAE;QACvB,yBAAyB,EAAE,CAAC,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC,kBAAkB,CAAC,UAAU;aAC7E,yBAAyB;KACjC,CAAC;IAEF,IAAM,KAAK,GAAqB;QAC5B,SAAS,EAAE,aAAa;QACxB,aAAa,eAAA;QACb,QAAQ,UAAA;QACR,UAAU,EAAE,MAAA,iBAAiB,CAAC,UAAU,mCAAI,EAAE;QAC9C,SAAS,EAAE,MAAA,iBAAiB,CAAC,SAAS,mCAAI,EAAE;QAC5C,cAAc,EAAE,iBAAiB,CAAC,QAAQ;QAC1C,SAAS,EAAE,SAAS;QACpB,gBAAgB,kBAAA;QAChB,qBAAqB,EAAE,CAAC,CAAC,iBAAiB,CAAC,qBAAqB;KACnE,CAAC;IAEF,OAAO,MAAM,CAAC,YAAY,CAAC,aAAa,EAAE,KAAK,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;AAC3E,CAAC;AAhCD,wEAgCC","sourcesContent":["import type { HtmlFromClipboard } from './retrieveHtmlInfo';\nimport type {\n BeforePasteEvent,\n ClipboardData,\n DomToModelOptionForSanitizing,\n PasteType,\n IEditor,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function generatePasteOptionFromPlugins(\n editor: IEditor,\n clipboardData: ClipboardData,\n fragment: DocumentFragment,\n htmlFromClipboard: HtmlFromClipboard,\n pasteType: PasteType\n): BeforePasteEvent {\n const domToModelOption: DomToModelOptionForSanitizing = {\n additionalAllowedTags: [],\n additionalDisallowedTags: [],\n additionalFormatParsers: {},\n formatParserOverride: {},\n processorOverride: {},\n styleSanitizers: {},\n attributeSanitizers: {},\n processNonVisibleElements: !!editor.getEnvironment().domToModelSettings.customized\n .processNonVisibleElements,\n };\n\n const event: BeforePasteEvent = {\n eventType: 'beforePaste',\n clipboardData,\n fragment,\n htmlBefore: htmlFromClipboard.htmlBefore ?? '',\n htmlAfter: htmlFromClipboard.htmlAfter ?? '',\n htmlAttributes: htmlFromClipboard.metadata,\n pasteType: pasteType,\n domToModelOption,\n containsBlockElements: !!htmlFromClipboard.containsBlockElements,\n };\n\n return editor.triggerEvent('beforePaste', event, true /* broadcast */);\n}\n"]}
|
|
@@ -12,7 +12,7 @@ var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
|
|
|
12
12
|
*/
|
|
13
13
|
var attachDomEvent = function (core, eventMap) {
|
|
14
14
|
var disposers = (0, roosterjs_content_model_dom_1.getObjectKeys)(eventMap || {}).map(function (key) {
|
|
15
|
-
var _a = eventMap[key], pluginEventType = _a.pluginEventType, beforeDispatch = _a.beforeDispatch;
|
|
15
|
+
var _a = eventMap[key], pluginEventType = _a.pluginEventType, beforeDispatch = _a.beforeDispatch, capture = _a.capture;
|
|
16
16
|
var eventName = key;
|
|
17
17
|
var onEvent = function (event) {
|
|
18
18
|
if (beforeDispatch) {
|
|
@@ -25,9 +25,11 @@ var attachDomEvent = function (core, eventMap) {
|
|
|
25
25
|
}, false /*broadcast*/);
|
|
26
26
|
}
|
|
27
27
|
};
|
|
28
|
-
core.logicalRoot.addEventListener(eventName, onEvent);
|
|
28
|
+
core.logicalRoot.addEventListener(eventName, onEvent, { capture: capture });
|
|
29
29
|
return function () {
|
|
30
|
-
core.logicalRoot.removeEventListener(eventName, onEvent
|
|
30
|
+
core.logicalRoot.removeEventListener(eventName, onEvent, {
|
|
31
|
+
capture: capture,
|
|
32
|
+
});
|
|
31
33
|
};
|
|
32
34
|
});
|
|
33
35
|
return function () { return disposers.forEach(function (disposers) { return disposers(); }); };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attachDomEvent.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/coreApi/attachDomEvent/attachDomEvent.ts"],"names":[],"mappings":";;;AAAA,2EAA4D;AAG5D;;;;;;;GAOG;AACI,IAAM,cAAc,GAAmB,UAAC,IAAI,EAAE,QAAQ;IACzD,IAAM,SAAS,GAAG,IAAA,2CAAa,EAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,UAAA,GAAG;QAC7C,IAAA,
|
|
1
|
+
{"version":3,"file":"attachDomEvent.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/coreApi/attachDomEvent/attachDomEvent.ts"],"names":[],"mappings":";;;AAAA,2EAA4D;AAG5D;;;;;;;GAOG;AACI,IAAM,cAAc,GAAmB,UAAC,IAAI,EAAE,QAAQ;IACzD,IAAM,SAAS,GAAG,IAAA,2CAAa,EAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,UAAA,GAAG;QAC7C,IAAA,KAA+C,QAAQ,CAAC,GAAG,CAAC,EAA1D,eAAe,qBAAA,EAAE,cAAc,oBAAA,EAAE,OAAO,aAAkB,CAAC;QACnE,IAAM,SAAS,GAAG,GAAgC,CAAC;QACnD,IAAM,OAAO,GAAG,UAAC,KAA4C;YACzD,IAAI,cAAc,EAAE;gBAChB,cAAc,CAAC,KAAK,CAAC,CAAC;aACzB;YAED,IAAI,eAAe,IAAI,IAAI,EAAE;gBACzB,IAAI,CAAC,GAAG,CAAC,YAAY,CACjB,IAAI,EACS;oBACT,SAAS,EAAE,eAAe;oBAC1B,QAAQ,EAAE,KAAK;iBAClB,EACD,KAAK,CAAC,aAAa,CACtB,CAAC;aACL;QACL,CAAC,CAAC;QAEF,IAAI,CAAC,WAAW,CAAC,gBAAgB,CAAC,SAAS,EAAE,OAAO,EAAE,EAAE,OAAO,SAAA,EAAE,CAAC,CAAC;QAEnE,OAAO;YACH,IAAI,CAAC,WAAW,CAAC,mBAAmB,CAAC,SAAS,EAAE,OAAO,EAAE;gBACrD,OAAO,SAAA;aACV,CAAC,CAAC;QACP,CAAC,CAAC;IACN,CAAC,CAAC,CAAC;IAEH,OAAO,cAAM,OAAA,SAAS,CAAC,OAAO,CAAC,UAAA,SAAS,IAAI,OAAA,SAAS,EAAE,EAAX,CAAW,CAAC,EAA3C,CAA2C,CAAC;AAC7D,CAAC,CAAC;AA/BW,QAAA,cAAc,kBA+BzB","sourcesContent":["import { getObjectKeys } from 'roosterjs-content-model-dom';\nimport type { AttachDomEvent, PluginEvent } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n * Attach a DOM event to the editor content DIV\n * @param core The EditorCore object\n * @param eventName The DOM event name\n * @param pluginEventType Optional event type. When specified, editor will trigger a plugin event with this name when the DOM event is triggered\n * @param beforeDispatch Optional callback function to be invoked when the DOM event is triggered before trigger plugin event\n */\nexport const attachDomEvent: AttachDomEvent = (core, eventMap) => {\n const disposers = getObjectKeys(eventMap || {}).map(key => {\n const { pluginEventType, beforeDispatch, capture } = eventMap[key];\n const eventName = key as keyof HTMLElementEventMap;\n const onEvent = (event: HTMLElementEventMap[typeof eventName]) => {\n if (beforeDispatch) {\n beforeDispatch(event);\n }\n\n if (pluginEventType != null) {\n core.api.triggerEvent(\n core,\n <PluginEvent>{\n eventType: pluginEventType,\n rawEvent: event,\n },\n false /*broadcast*/\n );\n }\n };\n\n core.logicalRoot.addEventListener(eventName, onEvent, { capture });\n\n return () => {\n core.logicalRoot.removeEventListener(eventName, onEvent, {\n capture,\n });\n };\n });\n\n return () => disposers.forEach(disposers => disposers());\n};\n"]}
|
|
@@ -82,8 +82,10 @@ var DOMHelperImpl = /** @class */ (function () {
|
|
|
82
82
|
};
|
|
83
83
|
/**
|
|
84
84
|
* Get format of the container element
|
|
85
|
+
* @param isInDarkMode Optional flag to indicate if the environment is in dark mode
|
|
86
|
+
* @param darkColorHandler Optional DarkColorHandler to retrieve dark mode colors
|
|
85
87
|
*/
|
|
86
|
-
DOMHelperImpl.prototype.getContainerFormat = function () {
|
|
88
|
+
DOMHelperImpl.prototype.getContainerFormat = function (isInDarkMode, darkColorHandler) {
|
|
87
89
|
var _a, _b;
|
|
88
90
|
var window = this.contentDiv.ownerDocument.defaultView;
|
|
89
91
|
var style = window === null || window === void 0 ? void 0 : window.getComputedStyle(this.contentDiv);
|
|
@@ -92,8 +94,8 @@ var DOMHelperImpl = /** @class */ (function () {
|
|
|
92
94
|
fontSize: style.fontSize,
|
|
93
95
|
fontFamily: style.fontFamily,
|
|
94
96
|
fontWeight: style.fontWeight,
|
|
95
|
-
textColor: style.color,
|
|
96
|
-
backgroundColor: style.backgroundColor,
|
|
97
|
+
textColor: (0, roosterjs_content_model_dom_1.getColor)(this.contentDiv, false /*isBackgroundColor*/, !!isInDarkMode, darkColorHandler, style.color),
|
|
98
|
+
backgroundColor: (0, roosterjs_content_model_dom_1.getColor)(this.contentDiv, true /*isBackgroundColor*/, !!isInDarkMode, darkColorHandler, style.backgroundColor),
|
|
97
99
|
italic: style.fontStyle == 'italic',
|
|
98
100
|
letterSpacing: style.letterSpacing,
|
|
99
101
|
lineHeight: style.lineHeight,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DOMHelperImpl.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/editor/core/DOMHelperImpl.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"DOMHelperImpl.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/editor/core/DOMHelperImpl.ts"],"names":[],"mappings":";;;AAAA,2EAAkG;AAOlG;IACI,uBAAoB,UAAuB;QAAvB,eAAU,GAAV,UAAU,CAAa;IAAG,CAAC;IAE/C,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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;GAEG;AACH,SAAgB,eAAe,CAAC,UAAuB;IACnD,OAAO,IAAI,aAAa,CAAC,UAAU,CAAC,CAAC;AACzC,CAAC;AAFD,0CAEC","sourcesContent":["import { getColor, isNodeOfType, parseValueWithUnit, toArray } from 'roosterjs-content-model-dom';\nimport type {\n ContentModelSegmentFormat,\n DarkColorHandler,\n DOMHelper,\n} from 'roosterjs-content-model-types';\n\nclass DOMHelperImpl implements DOMHelper {\n constructor(private contentDiv: HTMLElement) {}\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 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 return this.contentDiv.cloneNode(true /*deep*/) as HTMLElement;\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/**\n * @internal Create new instance of DOMHelper\n */\nexport function createDOMHelper(contentDiv: HTMLElement): DOMHelper {\n return new DOMHelperImpl(contentDiv);\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createDomToModelContextForSanitizing.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/command/createModelFromHtml/createDomToModelContextForSanitizing.ts"],"names":[],"mappings":";;;;IAgBA,IAAM,uBAAuB,GAAkC;QAC3D,iBAAiB,EAAE,EAAE;QACrB,oBAAoB,EAAE,EAAE;QACxB,uBAAuB,EAAE,EAAE;QAC3B,qBAAqB,EAAE,EAAE;QACzB,wBAAwB,EAAE,EAAE;QAC5B,eAAe,EAAE,EAAE;QACnB,mBAAmB,EAAE,EAAE;
|
|
1
|
+
{"version":3,"file":"createDomToModelContextForSanitizing.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/command/createModelFromHtml/createDomToModelContextForSanitizing.ts"],"names":[],"mappings":";;;;IAgBA,IAAM,uBAAuB,GAAkC;QAC3D,iBAAiB,EAAE,EAAE;QACrB,oBAAoB,EAAE,EAAE;QACxB,uBAAuB,EAAE,EAAE;QAC3B,qBAAqB,EAAE,EAAE;QACzB,wBAAwB,EAAE,EAAE;QAC5B,eAAe,EAAE,EAAE;QACnB,mBAAmB,EAAE,EAAE;QACvB,yBAAyB,EAAE,KAAK;KACnC,CAAC;IAEF;;OAEG;IACH,SAAgB,oCAAoC,CAChD,QAAkB,EAClB,aAAyC,EACzC,aAAgC,EAChC,0BAAmE;QAEnE,IAAM,gBAAgB,mDACf,uBAAuB,GACvB,0BAA0B,CAChC,CAAC;QAEF,OAAO,IAAA,qDAAuB,gDAEtB,aAAa,eAAA,IACV,IAAA,+DAA8B,EAAC,QAAQ,CAAC,KAC3C,oBAAoB,EAAE,EAAE,KAE5B,aAAa,EACb;YACI,iBAAiB,EAAE;gBACf,OAAO,EAAE,uCAAkB;gBAC3B,MAAM,EAAE,IAAA,iDAA0B,EAAC,gBAAgB,CAAC;gBACpD,GAAG,EAAE,IAAA,mDAA2B,EAAC,gBAAgB,CAAC;aACrD;YACD,oBAAoB,EAAE;gBAClB,OAAO,EAAE,mDAAwB;gBACjC,UAAU,EAAE,yDAA2B;aAC1C;YACD,uBAAuB,EAAE;gBACrB,SAAS,EAAE,CAAC,qDAAyB,CAAC;gBACtC,MAAM,EAAE,CAAC,mDAAsB,CAAC;aACnC;SACJ,EACD,gBAAgB,CACnB,CAAC;IACN,CAAC;IAnCD,oFAmCC","sourcesContent":["import { containerSizeFormatParser } from '../../override/containerSizeFormatParser';\nimport { createDomToModelContext } from 'roosterjs-content-model-dom';\nimport { createPasteEntityProcessor } from '../../override/pasteEntityProcessor';\nimport { createPasteGeneralProcessor } from '../../override/pasteGeneralProcessor';\nimport { getRootComputedStyleForContext } from '../../coreApi/createEditorContext/getRootComputedStyleForContext';\nimport { pasteBlockEntityParser } from '../../override/pasteCopyBlockEntityParser';\nimport { pasteDisplayFormatParser } from '../../override/pasteDisplayFormatParser';\nimport { pasteTextProcessor } from '../../override/pasteTextProcessor';\nimport { pasteWhiteSpaceFormatParser } from '../../override/pasteWhiteSpaceFormatParser';\nimport type {\n ContentModelSegmentFormat,\n DomToModelContext,\n DomToModelOption,\n DomToModelOptionForSanitizing,\n} from 'roosterjs-content-model-types';\n\nconst DefaultSanitizingOption: DomToModelOptionForSanitizing = {\n processorOverride: {},\n formatParserOverride: {},\n additionalFormatParsers: {},\n additionalAllowedTags: [],\n additionalDisallowedTags: [],\n styleSanitizers: {},\n attributeSanitizers: {},\n processNonVisibleElements: false,\n};\n\n/**\n * @internal\n */\nexport function createDomToModelContextForSanitizing(\n document: Document,\n defaultFormat?: ContentModelSegmentFormat,\n defaultOption?: DomToModelOption,\n additionalSanitizingOption?: Partial<DomToModelOptionForSanitizing>\n): DomToModelContext {\n const sanitizingOption: DomToModelOptionForSanitizing = {\n ...DefaultSanitizingOption,\n ...additionalSanitizingOption,\n };\n\n return createDomToModelContext(\n {\n defaultFormat,\n ...getRootComputedStyleForContext(document),\n experimentalFeatures: [],\n },\n defaultOption,\n {\n processorOverride: {\n '#text': pasteTextProcessor,\n entity: createPasteEntityProcessor(sanitizingOption),\n '*': createPasteGeneralProcessor(sanitizingOption),\n },\n formatParserOverride: {\n display: pasteDisplayFormatParser,\n whiteSpace: pasteWhiteSpaceFormatParser,\n },\n additionalFormatParsers: {\n container: [containerSizeFormatParser],\n entity: [pasteBlockEntityParser],\n },\n },\n sanitizingOption\n );\n}\n"]}
|
|
@@ -2,10 +2,17 @@ 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
|
|
5
|
+
* @param mode Specify HTML to get HTML. This is the default option
|
|
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;
|
|
9
|
+
/**
|
|
10
|
+
* Export HTML content. If there are entities, this will cause EntityOperation event with option = 'replaceTemporaryContent' to get a dehydrated entity.
|
|
11
|
+
* This is a fast version, it retrieve HTML content directly from editor without going through content model conversion.
|
|
12
|
+
* @param editor The editor to get content from
|
|
13
|
+
* @param mode Specify HTMLFast to get HTML result.
|
|
14
|
+
*/
|
|
15
|
+
export declare function exportContent(editor: IEditor, mode: 'HTMLFast'): string;
|
|
9
16
|
/**
|
|
10
17
|
* Export plain text content
|
|
11
18
|
* @param editor The editor to get content from
|
|
@@ -2,25 +2,36 @@ define(["require", "exports", "roosterjs-content-model-dom"], function (require,
|
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.exportContent = void 0;
|
|
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
|
+
// Once we are confident that 'HTMLFast' is stable, we can fully switch 'HTML' to use the 'HTMLFast' approach
|
|
5
7
|
function exportContent(editor, mode, optionsOrCallbacks) {
|
|
6
8
|
if (mode === void 0) { mode = 'HTML'; }
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
var model;
|
|
10
|
+
switch (mode) {
|
|
11
|
+
case 'PlainTextFast':
|
|
12
|
+
return editor.getDOMHelper().getTextContent();
|
|
13
|
+
case 'PlainText':
|
|
14
|
+
model = editor.getContentModelCopy('clean');
|
|
13
15
|
return (0, roosterjs_content_model_dom_1.contentModelToText)(model, undefined /*separator*/, optionsOrCallbacks);
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
case 'HTMLFast':
|
|
17
|
+
var clonedRoot = editor.getDOMHelper().getClonedRoot();
|
|
18
|
+
if (editor.isDarkMode()) {
|
|
19
|
+
(0, roosterjs_content_model_dom_1.transformColor)(clonedRoot, false /*includeSelf*/, 'darkToLight', editor.getColorManager());
|
|
20
|
+
}
|
|
21
|
+
return getHTMLFromDOM(editor, clonedRoot);
|
|
22
|
+
case 'HTML':
|
|
23
|
+
default:
|
|
24
|
+
model = editor.getContentModelCopy('clean');
|
|
16
25
|
var doc = editor.getDocument();
|
|
17
26
|
var div = doc.createElement('div');
|
|
18
27
|
(0, roosterjs_content_model_dom_1.contentModelToDom)(doc, div, model, (0, roosterjs_content_model_dom_1.createModelToDomContext)(undefined /*editorContext*/, optionsOrCallbacks));
|
|
19
|
-
editor
|
|
20
|
-
return div.innerHTML;
|
|
21
|
-
}
|
|
28
|
+
return getHTMLFromDOM(editor, div);
|
|
22
29
|
}
|
|
23
30
|
}
|
|
24
31
|
exports.exportContent = exportContent;
|
|
32
|
+
function getHTMLFromDOM(editor, root) {
|
|
33
|
+
editor.triggerEvent('extractContentWithDom', { clonedRoot: root }, true /*broadcast*/);
|
|
34
|
+
return root.innerHTML;
|
|
35
|
+
}
|
|
25
36
|
});
|
|
26
37
|
//# sourceMappingURL=exportContent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exportContent.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/command/exportContent/exportContent.ts"],"names":[],"mappings":";;;;
|
|
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,IAA6C,EAC7C,kBAA4D;QAD5D,qBAAA,EAAA,aAA6C;QAG7C,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;gBACX,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,CAC3B,CAAC;iBACL;gBAED,OAAO,cAAc,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;YAE9C,KAAK,MAAM,CAAC;YACZ;gBACI,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;IApDD,sCAoDC;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. This is the default option\n * @param options @optional Options for Model to DOM conversion\n */\nexport function exportContent(editor: IEditor, mode?: 'HTML', options?: ModelToDomOption): string;\n\n/**\n * Export 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.\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' = 'HTML',\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 const clonedRoot = editor.getDOMHelper().getClonedRoot();\n\n if (editor.isDarkMode()) {\n transformColor(\n clonedRoot,\n false /*includeSelf*/,\n 'darkToLight',\n editor.getColorManager()\n );\n }\n\n return getHTMLFromDOM(editor, clonedRoot);\n\n case 'HTML':\n default:\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"]}
|
|
@@ -15,6 +15,8 @@ define(["require", "exports"], function (require, exports) {
|
|
|
15
15
|
processorOverride: {},
|
|
16
16
|
styleSanitizers: {},
|
|
17
17
|
attributeSanitizers: {},
|
|
18
|
+
processNonVisibleElements: !!editor.getEnvironment().domToModelSettings.customized
|
|
19
|
+
.processNonVisibleElements,
|
|
18
20
|
};
|
|
19
21
|
var event = {
|
|
20
22
|
eventType: 'beforePaste',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generatePasteOptionFromPlugins.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/command/paste/generatePasteOptionFromPlugins.ts"],"names":[],"mappings":";;;;IASA;;OAEG;IACH,SAAgB,8BAA8B,CAC1C,MAAe,EACf,aAA4B,EAC5B,QAA0B,EAC1B,iBAAoC,EACpC,SAAoB;;QAEpB,IAAM,gBAAgB,GAAkC;YACpD,qBAAqB,EAAE,EAAE;YACzB,wBAAwB,EAAE,EAAE;YAC5B,uBAAuB,EAAE,EAAE;YAC3B,oBAAoB,EAAE,EAAE;YACxB,iBAAiB,EAAE,EAAE;YACrB,eAAe,EAAE,EAAE;YACnB,mBAAmB,EAAE,EAAE;
|
|
1
|
+
{"version":3,"file":"generatePasteOptionFromPlugins.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/command/paste/generatePasteOptionFromPlugins.ts"],"names":[],"mappings":";;;;IASA;;OAEG;IACH,SAAgB,8BAA8B,CAC1C,MAAe,EACf,aAA4B,EAC5B,QAA0B,EAC1B,iBAAoC,EACpC,SAAoB;;QAEpB,IAAM,gBAAgB,GAAkC;YACpD,qBAAqB,EAAE,EAAE;YACzB,wBAAwB,EAAE,EAAE;YAC5B,uBAAuB,EAAE,EAAE;YAC3B,oBAAoB,EAAE,EAAE;YACxB,iBAAiB,EAAE,EAAE;YACrB,eAAe,EAAE,EAAE;YACnB,mBAAmB,EAAE,EAAE;YACvB,yBAAyB,EAAE,CAAC,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC,kBAAkB,CAAC,UAAU;iBAC7E,yBAAyB;SACjC,CAAC;QAEF,IAAM,KAAK,GAAqB;YAC5B,SAAS,EAAE,aAAa;YACxB,aAAa,eAAA;YACb,QAAQ,UAAA;YACR,UAAU,EAAE,MAAA,iBAAiB,CAAC,UAAU,mCAAI,EAAE;YAC9C,SAAS,EAAE,MAAA,iBAAiB,CAAC,SAAS,mCAAI,EAAE;YAC5C,cAAc,EAAE,iBAAiB,CAAC,QAAQ;YAC1C,SAAS,EAAE,SAAS;YACpB,gBAAgB,kBAAA;YAChB,qBAAqB,EAAE,CAAC,CAAC,iBAAiB,CAAC,qBAAqB;SACnE,CAAC;QAEF,OAAO,MAAM,CAAC,YAAY,CAAC,aAAa,EAAE,KAAK,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;IAC3E,CAAC;IAhCD,wEAgCC","sourcesContent":["import type { HtmlFromClipboard } from './retrieveHtmlInfo';\nimport type {\n BeforePasteEvent,\n ClipboardData,\n DomToModelOptionForSanitizing,\n PasteType,\n IEditor,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function generatePasteOptionFromPlugins(\n editor: IEditor,\n clipboardData: ClipboardData,\n fragment: DocumentFragment,\n htmlFromClipboard: HtmlFromClipboard,\n pasteType: PasteType\n): BeforePasteEvent {\n const domToModelOption: DomToModelOptionForSanitizing = {\n additionalAllowedTags: [],\n additionalDisallowedTags: [],\n additionalFormatParsers: {},\n formatParserOverride: {},\n processorOverride: {},\n styleSanitizers: {},\n attributeSanitizers: {},\n processNonVisibleElements: !!editor.getEnvironment().domToModelSettings.customized\n .processNonVisibleElements,\n };\n\n const event: BeforePasteEvent = {\n eventType: 'beforePaste',\n clipboardData,\n fragment,\n htmlBefore: htmlFromClipboard.htmlBefore ?? '',\n htmlAfter: htmlFromClipboard.htmlAfter ?? '',\n htmlAttributes: htmlFromClipboard.metadata,\n pasteType: pasteType,\n domToModelOption,\n containsBlockElements: !!htmlFromClipboard.containsBlockElements,\n };\n\n return editor.triggerEvent('beforePaste', event, true /* broadcast */);\n}\n"]}
|
|
@@ -12,7 +12,7 @@ define(["require", "exports", "roosterjs-content-model-dom"], function (require,
|
|
|
12
12
|
*/
|
|
13
13
|
var attachDomEvent = function (core, eventMap) {
|
|
14
14
|
var disposers = (0, roosterjs_content_model_dom_1.getObjectKeys)(eventMap || {}).map(function (key) {
|
|
15
|
-
var _a = eventMap[key], pluginEventType = _a.pluginEventType, beforeDispatch = _a.beforeDispatch;
|
|
15
|
+
var _a = eventMap[key], pluginEventType = _a.pluginEventType, beforeDispatch = _a.beforeDispatch, capture = _a.capture;
|
|
16
16
|
var eventName = key;
|
|
17
17
|
var onEvent = function (event) {
|
|
18
18
|
if (beforeDispatch) {
|
|
@@ -25,9 +25,11 @@ define(["require", "exports", "roosterjs-content-model-dom"], function (require,
|
|
|
25
25
|
}, false /*broadcast*/);
|
|
26
26
|
}
|
|
27
27
|
};
|
|
28
|
-
core.logicalRoot.addEventListener(eventName, onEvent);
|
|
28
|
+
core.logicalRoot.addEventListener(eventName, onEvent, { capture: capture });
|
|
29
29
|
return function () {
|
|
30
|
-
core.logicalRoot.removeEventListener(eventName, onEvent
|
|
30
|
+
core.logicalRoot.removeEventListener(eventName, onEvent, {
|
|
31
|
+
capture: capture,
|
|
32
|
+
});
|
|
31
33
|
};
|
|
32
34
|
});
|
|
33
35
|
return function () { return disposers.forEach(function (disposers) { return disposers(); }); };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attachDomEvent.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/coreApi/attachDomEvent/attachDomEvent.ts"],"names":[],"mappings":";;;;IAGA;;;;;;;OAOG;IACI,IAAM,cAAc,GAAmB,UAAC,IAAI,EAAE,QAAQ;QACzD,IAAM,SAAS,GAAG,IAAA,2CAAa,EAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,UAAA,GAAG;YAC7C,IAAA,
|
|
1
|
+
{"version":3,"file":"attachDomEvent.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/coreApi/attachDomEvent/attachDomEvent.ts"],"names":[],"mappings":";;;;IAGA;;;;;;;OAOG;IACI,IAAM,cAAc,GAAmB,UAAC,IAAI,EAAE,QAAQ;QACzD,IAAM,SAAS,GAAG,IAAA,2CAAa,EAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,UAAA,GAAG;YAC7C,IAAA,KAA+C,QAAQ,CAAC,GAAG,CAAC,EAA1D,eAAe,qBAAA,EAAE,cAAc,oBAAA,EAAE,OAAO,aAAkB,CAAC;YACnE,IAAM,SAAS,GAAG,GAAgC,CAAC;YACnD,IAAM,OAAO,GAAG,UAAC,KAA4C;gBACzD,IAAI,cAAc,EAAE;oBAChB,cAAc,CAAC,KAAK,CAAC,CAAC;iBACzB;gBAED,IAAI,eAAe,IAAI,IAAI,EAAE;oBACzB,IAAI,CAAC,GAAG,CAAC,YAAY,CACjB,IAAI,EACS;wBACT,SAAS,EAAE,eAAe;wBAC1B,QAAQ,EAAE,KAAK;qBAClB,EACD,KAAK,CAAC,aAAa,CACtB,CAAC;iBACL;YACL,CAAC,CAAC;YAEF,IAAI,CAAC,WAAW,CAAC,gBAAgB,CAAC,SAAS,EAAE,OAAO,EAAE,EAAE,OAAO,SAAA,EAAE,CAAC,CAAC;YAEnE,OAAO;gBACH,IAAI,CAAC,WAAW,CAAC,mBAAmB,CAAC,SAAS,EAAE,OAAO,EAAE;oBACrD,OAAO,SAAA;iBACV,CAAC,CAAC;YACP,CAAC,CAAC;QACN,CAAC,CAAC,CAAC;QAEH,OAAO,cAAM,OAAA,SAAS,CAAC,OAAO,CAAC,UAAA,SAAS,IAAI,OAAA,SAAS,EAAE,EAAX,CAAW,CAAC,EAA3C,CAA2C,CAAC;IAC7D,CAAC,CAAC;IA/BW,QAAA,cAAc,kBA+BzB","sourcesContent":["import { getObjectKeys } from 'roosterjs-content-model-dom';\nimport type { AttachDomEvent, PluginEvent } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n * Attach a DOM event to the editor content DIV\n * @param core The EditorCore object\n * @param eventName The DOM event name\n * @param pluginEventType Optional event type. When specified, editor will trigger a plugin event with this name when the DOM event is triggered\n * @param beforeDispatch Optional callback function to be invoked when the DOM event is triggered before trigger plugin event\n */\nexport const attachDomEvent: AttachDomEvent = (core, eventMap) => {\n const disposers = getObjectKeys(eventMap || {}).map(key => {\n const { pluginEventType, beforeDispatch, capture } = eventMap[key];\n const eventName = key as keyof HTMLElementEventMap;\n const onEvent = (event: HTMLElementEventMap[typeof eventName]) => {\n if (beforeDispatch) {\n beforeDispatch(event);\n }\n\n if (pluginEventType != null) {\n core.api.triggerEvent(\n core,\n <PluginEvent>{\n eventType: pluginEventType,\n rawEvent: event,\n },\n false /*broadcast*/\n );\n }\n };\n\n core.logicalRoot.addEventListener(eventName, onEvent, { capture });\n\n return () => {\n core.logicalRoot.removeEventListener(eventName, onEvent, {\n capture,\n });\n };\n });\n\n return () => disposers.forEach(disposers => disposers());\n};\n"]}
|
|
@@ -82,8 +82,10 @@ define(["require", "exports", "roosterjs-content-model-dom"], function (require,
|
|
|
82
82
|
};
|
|
83
83
|
/**
|
|
84
84
|
* Get format of the container element
|
|
85
|
+
* @param isInDarkMode Optional flag to indicate if the environment is in dark mode
|
|
86
|
+
* @param darkColorHandler Optional DarkColorHandler to retrieve dark mode colors
|
|
85
87
|
*/
|
|
86
|
-
DOMHelperImpl.prototype.getContainerFormat = function () {
|
|
88
|
+
DOMHelperImpl.prototype.getContainerFormat = function (isInDarkMode, darkColorHandler) {
|
|
87
89
|
var _a, _b;
|
|
88
90
|
var window = this.contentDiv.ownerDocument.defaultView;
|
|
89
91
|
var style = window === null || window === void 0 ? void 0 : window.getComputedStyle(this.contentDiv);
|
|
@@ -92,8 +94,8 @@ define(["require", "exports", "roosterjs-content-model-dom"], function (require,
|
|
|
92
94
|
fontSize: style.fontSize,
|
|
93
95
|
fontFamily: style.fontFamily,
|
|
94
96
|
fontWeight: style.fontWeight,
|
|
95
|
-
textColor: style.color,
|
|
96
|
-
backgroundColor: style.backgroundColor,
|
|
97
|
+
textColor: (0, roosterjs_content_model_dom_1.getColor)(this.contentDiv, false /*isBackgroundColor*/, !!isInDarkMode, darkColorHandler, style.color),
|
|
98
|
+
backgroundColor: (0, roosterjs_content_model_dom_1.getColor)(this.contentDiv, true /*isBackgroundColor*/, !!isInDarkMode, darkColorHandler, style.backgroundColor),
|
|
97
99
|
italic: style.fontStyle == 'italic',
|
|
98
100
|
letterSpacing: style.letterSpacing,
|
|
99
101
|
lineHeight: style.lineHeight,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DOMHelperImpl.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/editor/core/DOMHelperImpl.ts"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"DOMHelperImpl.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/editor/core/DOMHelperImpl.ts"],"names":[],"mappings":";;;;IAOA;QACI,uBAAoB,UAAuB;YAAvB,eAAU,GAAV,UAAU,CAAa;QAAG,CAAC;QAE/C,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,WAAW,IAAI,EAAE,CAAC;QAC7C,CAAC;QAED,sCAAc,GAAd,UAAe,IAAU,EAAE,WAAqB;YAC5C,OAAO,WAAW,IAAI,IAAI,IAAI,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC3F,CAAC;QAED,0CAAkB,GAAlB;;YACI,IAAM,aAAa,GAAG,CAAA,MAAA,IAAI,CAAC,UAAU,CAAC,qBAAqB,EAAE,0CAAE,KAAK,KAAI,CAAC,CAAC;YAC1E,IAAM,WAAW,GAAG,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC;YAEhD,OAAO,WAAW,GAAG,CAAC,IAAI,aAAa,GAAG,CAAC;gBACvC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,aAAa,GAAG,WAAW,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG;gBACvD,CAAC,CAAC,CAAC,CAAC;QACZ,CAAC;QAED,uCAAe,GAAf,UAAg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UAAU,EACf,KAAK,CAAC,qBAAqB,EAC3B,CAAC,CAAC,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;QACL,oBAAC;IAAD,CAAC,AAjID,IAiIC;IAED;;OAEG;IACH,SAAgB,eAAe,CAAC,UAAuB;QACnD,OAAO,IAAI,aAAa,CAAC,UAAU,CAAC,CAAC;IACzC,CAAC;IAFD,0CAEC","sourcesContent":["import { getColor, isNodeOfType, parseValueWithUnit, toArray } from 'roosterjs-content-model-dom';\nimport type {\n ContentModelSegmentFormat,\n DarkColorHandler,\n DOMHelper,\n} from 'roosterjs-content-model-types';\n\nclass DOMHelperImpl implements DOMHelper {\n constructor(private contentDiv: HTMLElement) {}\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 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 return this.contentDiv.cloneNode(true /*deep*/) as HTMLElement;\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/**\n * @internal Create new instance of DOMHelper\n */\nexport function createDOMHelper(contentDiv: HTMLElement): DOMHelper {\n return new DOMHelperImpl(contentDiv);\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createDomToModelContextForSanitizing.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/command/createModelFromHtml/createDomToModelContextForSanitizing.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,0CAA0C,CAAC;AACrF,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACtE,OAAO,EAAE,0BAA0B,EAAE,MAAM,qCAAqC,CAAC;AACjF,OAAO,EAAE,2BAA2B,EAAE,MAAM,sCAAsC,CAAC;AACnF,OAAO,EAAE,8BAA8B,EAAE,MAAM,kEAAkE,CAAC;AAClH,OAAO,EAAE,sBAAsB,EAAE,MAAM,2CAA2C,CAAC;AACnF,OAAO,EAAE,wBAAwB,EAAE,MAAM,yCAAyC,CAAC;AACnF,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,EAAE,2BAA2B,EAAE,MAAM,4CAA4C,CAAC;AAQzF,IAAM,uBAAuB,GAAkC;IAC3D,iBAAiB,EAAE,EAAE;IACrB,oBAAoB,EAAE,EAAE;IACxB,uBAAuB,EAAE,EAAE;IAC3B,qBAAqB,EAAE,EAAE;IACzB,wBAAwB,EAAE,EAAE;IAC5B,eAAe,EAAE,EAAE;IACnB,mBAAmB,EAAE,EAAE;
|
|
1
|
+
{"version":3,"file":"createDomToModelContextForSanitizing.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/command/createModelFromHtml/createDomToModelContextForSanitizing.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,0CAA0C,CAAC;AACrF,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACtE,OAAO,EAAE,0BAA0B,EAAE,MAAM,qCAAqC,CAAC;AACjF,OAAO,EAAE,2BAA2B,EAAE,MAAM,sCAAsC,CAAC;AACnF,OAAO,EAAE,8BAA8B,EAAE,MAAM,kEAAkE,CAAC;AAClH,OAAO,EAAE,sBAAsB,EAAE,MAAM,2CAA2C,CAAC;AACnF,OAAO,EAAE,wBAAwB,EAAE,MAAM,yCAAyC,CAAC;AACnF,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,EAAE,2BAA2B,EAAE,MAAM,4CAA4C,CAAC;AAQzF,IAAM,uBAAuB,GAAkC;IAC3D,iBAAiB,EAAE,EAAE;IACrB,oBAAoB,EAAE,EAAE;IACxB,uBAAuB,EAAE,EAAE;IAC3B,qBAAqB,EAAE,EAAE;IACzB,wBAAwB,EAAE,EAAE;IAC5B,eAAe,EAAE,EAAE;IACnB,mBAAmB,EAAE,EAAE;IACvB,yBAAyB,EAAE,KAAK;CACnC,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,oCAAoC,CAChD,QAAkB,EAClB,aAAyC,EACzC,aAAgC,EAChC,0BAAmE;IAEnE,IAAM,gBAAgB,yBACf,uBAAuB,GACvB,0BAA0B,CAChC,CAAC;IAEF,OAAO,uBAAuB,qBAEtB,aAAa,eAAA,IACV,8BAA8B,CAAC,QAAQ,CAAC,KAC3C,oBAAoB,EAAE,EAAE,KAE5B,aAAa,EACb;QACI,iBAAiB,EAAE;YACf,OAAO,EAAE,kBAAkB;YAC3B,MAAM,EAAE,0BAA0B,CAAC,gBAAgB,CAAC;YACpD,GAAG,EAAE,2BAA2B,CAAC,gBAAgB,CAAC;SACrD;QACD,oBAAoB,EAAE;YAClB,OAAO,EAAE,wBAAwB;YACjC,UAAU,EAAE,2BAA2B;SAC1C;QACD,uBAAuB,EAAE;YACrB,SAAS,EAAE,CAAC,yBAAyB,CAAC;YACtC,MAAM,EAAE,CAAC,sBAAsB,CAAC;SACnC;KACJ,EACD,gBAAgB,CACnB,CAAC;AACN,CAAC","sourcesContent":["import { containerSizeFormatParser } from '../../override/containerSizeFormatParser';\nimport { createDomToModelContext } from 'roosterjs-content-model-dom';\nimport { createPasteEntityProcessor } from '../../override/pasteEntityProcessor';\nimport { createPasteGeneralProcessor } from '../../override/pasteGeneralProcessor';\nimport { getRootComputedStyleForContext } from '../../coreApi/createEditorContext/getRootComputedStyleForContext';\nimport { pasteBlockEntityParser } from '../../override/pasteCopyBlockEntityParser';\nimport { pasteDisplayFormatParser } from '../../override/pasteDisplayFormatParser';\nimport { pasteTextProcessor } from '../../override/pasteTextProcessor';\nimport { pasteWhiteSpaceFormatParser } from '../../override/pasteWhiteSpaceFormatParser';\nimport type {\n ContentModelSegmentFormat,\n DomToModelContext,\n DomToModelOption,\n DomToModelOptionForSanitizing,\n} from 'roosterjs-content-model-types';\n\nconst DefaultSanitizingOption: DomToModelOptionForSanitizing = {\n processorOverride: {},\n formatParserOverride: {},\n additionalFormatParsers: {},\n additionalAllowedTags: [],\n additionalDisallowedTags: [],\n styleSanitizers: {},\n attributeSanitizers: {},\n processNonVisibleElements: false,\n};\n\n/**\n * @internal\n */\nexport function createDomToModelContextForSanitizing(\n document: Document,\n defaultFormat?: ContentModelSegmentFormat,\n defaultOption?: DomToModelOption,\n additionalSanitizingOption?: Partial<DomToModelOptionForSanitizing>\n): DomToModelContext {\n const sanitizingOption: DomToModelOptionForSanitizing = {\n ...DefaultSanitizingOption,\n ...additionalSanitizingOption,\n };\n\n return createDomToModelContext(\n {\n defaultFormat,\n ...getRootComputedStyleForContext(document),\n experimentalFeatures: [],\n },\n defaultOption,\n {\n processorOverride: {\n '#text': pasteTextProcessor,\n entity: createPasteEntityProcessor(sanitizingOption),\n '*': createPasteGeneralProcessor(sanitizingOption),\n },\n formatParserOverride: {\n display: pasteDisplayFormatParser,\n whiteSpace: pasteWhiteSpaceFormatParser,\n },\n additionalFormatParsers: {\n container: [containerSizeFormatParser],\n entity: [pasteBlockEntityParser],\n },\n },\n sanitizingOption\n );\n}\n"]}
|
|
@@ -2,10 +2,17 @@ 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
|
|
5
|
+
* @param mode Specify HTML to get HTML. This is the default option
|
|
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;
|
|
9
|
+
/**
|
|
10
|
+
* Export HTML content. If there are entities, this will cause EntityOperation event with option = 'replaceTemporaryContent' to get a dehydrated entity.
|
|
11
|
+
* This is a fast version, it retrieve HTML content directly from editor without going through content model conversion.
|
|
12
|
+
* @param editor The editor to get content from
|
|
13
|
+
* @param mode Specify HTMLFast to get HTML result.
|
|
14
|
+
*/
|
|
15
|
+
export declare function exportContent(editor: IEditor, mode: 'HTMLFast'): string;
|
|
9
16
|
/**
|
|
10
17
|
* Export plain text content
|
|
11
18
|
* @param editor The editor to get content from
|
|
@@ -1,21 +1,32 @@
|
|
|
1
|
-
import { contentModelToDom, contentModelToText, createModelToDomContext, } from 'roosterjs-content-model-dom';
|
|
1
|
+
import { contentModelToDom, contentModelToText, createModelToDomContext, transformColor, } from 'roosterjs-content-model-dom';
|
|
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
|
+
// Once we are confident that 'HTMLFast' is stable, we can fully switch 'HTML' to use the 'HTMLFast' approach
|
|
2
4
|
export function exportContent(editor, mode, optionsOrCallbacks) {
|
|
3
5
|
if (mode === void 0) { mode = 'HTML'; }
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
var model;
|
|
7
|
+
switch (mode) {
|
|
8
|
+
case 'PlainTextFast':
|
|
9
|
+
return editor.getDOMHelper().getTextContent();
|
|
10
|
+
case 'PlainText':
|
|
11
|
+
model = editor.getContentModelCopy('clean');
|
|
10
12
|
return contentModelToText(model, undefined /*separator*/, optionsOrCallbacks);
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
case 'HTMLFast':
|
|
14
|
+
var clonedRoot = editor.getDOMHelper().getClonedRoot();
|
|
15
|
+
if (editor.isDarkMode()) {
|
|
16
|
+
transformColor(clonedRoot, false /*includeSelf*/, 'darkToLight', editor.getColorManager());
|
|
17
|
+
}
|
|
18
|
+
return getHTMLFromDOM(editor, clonedRoot);
|
|
19
|
+
case 'HTML':
|
|
20
|
+
default:
|
|
21
|
+
model = editor.getContentModelCopy('clean');
|
|
13
22
|
var doc = editor.getDocument();
|
|
14
23
|
var div = doc.createElement('div');
|
|
15
24
|
contentModelToDom(doc, div, model, createModelToDomContext(undefined /*editorContext*/, optionsOrCallbacks));
|
|
16
|
-
editor
|
|
17
|
-
return div.innerHTML;
|
|
18
|
-
}
|
|
25
|
+
return getHTMLFromDOM(editor, div);
|
|
19
26
|
}
|
|
20
27
|
}
|
|
28
|
+
function getHTMLFromDOM(editor, root) {
|
|
29
|
+
editor.triggerEvent('extractContentWithDom', { clonedRoot: root }, true /*broadcast*/);
|
|
30
|
+
return root.innerHTML;
|
|
31
|
+
}
|
|
21
32
|
//# sourceMappingURL=exportContent.js.map
|
|
@@ -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,
|
|
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,IAA6C,EAC7C,kBAA4D;IAD5D,qBAAA,EAAA,aAA6C;IAG7C,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;YACX,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,CAC3B,CAAC;aACL;YAED,OAAO,cAAc,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;QAE9C,KAAK,MAAM,CAAC;QACZ;YACI,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. This is the default option\n * @param options @optional Options for Model to DOM conversion\n */\nexport function exportContent(editor: IEditor, mode?: 'HTML', options?: ModelToDomOption): string;\n\n/**\n * Export 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.\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' = 'HTML',\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 const clonedRoot = editor.getDOMHelper().getClonedRoot();\n\n if (editor.isDarkMode()) {\n transformColor(\n clonedRoot,\n false /*includeSelf*/,\n 'darkToLight',\n editor.getColorManager()\n );\n }\n\n return getHTMLFromDOM(editor, clonedRoot);\n\n case 'HTML':\n default:\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"]}
|
|
@@ -11,6 +11,8 @@ export function generatePasteOptionFromPlugins(editor, clipboardData, fragment,
|
|
|
11
11
|
processorOverride: {},
|
|
12
12
|
styleSanitizers: {},
|
|
13
13
|
attributeSanitizers: {},
|
|
14
|
+
processNonVisibleElements: !!editor.getEnvironment().domToModelSettings.customized
|
|
15
|
+
.processNonVisibleElements,
|
|
14
16
|
};
|
|
15
17
|
var event = {
|
|
16
18
|
eventType: 'beforePaste',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generatePasteOptionFromPlugins.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/command/paste/generatePasteOptionFromPlugins.ts"],"names":[],"mappings":"AASA;;GAEG;AACH,MAAM,UAAU,8BAA8B,CAC1C,MAAe,EACf,aAA4B,EAC5B,QAA0B,EAC1B,iBAAoC,EACpC,SAAoB;;IAEpB,IAAM,gBAAgB,GAAkC;QACpD,qBAAqB,EAAE,EAAE;QACzB,wBAAwB,EAAE,EAAE;QAC5B,uBAAuB,EAAE,EAAE;QAC3B,oBAAoB,EAAE,EAAE;QACxB,iBAAiB,EAAE,EAAE;QACrB,eAAe,EAAE,EAAE;QACnB,mBAAmB,EAAE,EAAE;
|
|
1
|
+
{"version":3,"file":"generatePasteOptionFromPlugins.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/command/paste/generatePasteOptionFromPlugins.ts"],"names":[],"mappings":"AASA;;GAEG;AACH,MAAM,UAAU,8BAA8B,CAC1C,MAAe,EACf,aAA4B,EAC5B,QAA0B,EAC1B,iBAAoC,EACpC,SAAoB;;IAEpB,IAAM,gBAAgB,GAAkC;QACpD,qBAAqB,EAAE,EAAE;QACzB,wBAAwB,EAAE,EAAE;QAC5B,uBAAuB,EAAE,EAAE;QAC3B,oBAAoB,EAAE,EAAE;QACxB,iBAAiB,EAAE,EAAE;QACrB,eAAe,EAAE,EAAE;QACnB,mBAAmB,EAAE,EAAE;QACvB,yBAAyB,EAAE,CAAC,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC,kBAAkB,CAAC,UAAU;aAC7E,yBAAyB;KACjC,CAAC;IAEF,IAAM,KAAK,GAAqB;QAC5B,SAAS,EAAE,aAAa;QACxB,aAAa,eAAA;QACb,QAAQ,UAAA;QACR,UAAU,EAAE,MAAA,iBAAiB,CAAC,UAAU,mCAAI,EAAE;QAC9C,SAAS,EAAE,MAAA,iBAAiB,CAAC,SAAS,mCAAI,EAAE;QAC5C,cAAc,EAAE,iBAAiB,CAAC,QAAQ;QAC1C,SAAS,EAAE,SAAS;QACpB,gBAAgB,kBAAA;QAChB,qBAAqB,EAAE,CAAC,CAAC,iBAAiB,CAAC,qBAAqB;KACnE,CAAC;IAEF,OAAO,MAAM,CAAC,YAAY,CAAC,aAAa,EAAE,KAAK,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;AAC3E,CAAC","sourcesContent":["import type { HtmlFromClipboard } from './retrieveHtmlInfo';\nimport type {\n BeforePasteEvent,\n ClipboardData,\n DomToModelOptionForSanitizing,\n PasteType,\n IEditor,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function generatePasteOptionFromPlugins(\n editor: IEditor,\n clipboardData: ClipboardData,\n fragment: DocumentFragment,\n htmlFromClipboard: HtmlFromClipboard,\n pasteType: PasteType\n): BeforePasteEvent {\n const domToModelOption: DomToModelOptionForSanitizing = {\n additionalAllowedTags: [],\n additionalDisallowedTags: [],\n additionalFormatParsers: {},\n formatParserOverride: {},\n processorOverride: {},\n styleSanitizers: {},\n attributeSanitizers: {},\n processNonVisibleElements: !!editor.getEnvironment().domToModelSettings.customized\n .processNonVisibleElements,\n };\n\n const event: BeforePasteEvent = {\n eventType: 'beforePaste',\n clipboardData,\n fragment,\n htmlBefore: htmlFromClipboard.htmlBefore ?? '',\n htmlAfter: htmlFromClipboard.htmlAfter ?? '',\n htmlAttributes: htmlFromClipboard.metadata,\n pasteType: pasteType,\n domToModelOption,\n containsBlockElements: !!htmlFromClipboard.containsBlockElements,\n };\n\n return editor.triggerEvent('beforePaste', event, true /* broadcast */);\n}\n"]}
|
|
@@ -9,7 +9,7 @@ import { getObjectKeys } from 'roosterjs-content-model-dom';
|
|
|
9
9
|
*/
|
|
10
10
|
export var attachDomEvent = function (core, eventMap) {
|
|
11
11
|
var disposers = getObjectKeys(eventMap || {}).map(function (key) {
|
|
12
|
-
var _a = eventMap[key], pluginEventType = _a.pluginEventType, beforeDispatch = _a.beforeDispatch;
|
|
12
|
+
var _a = eventMap[key], pluginEventType = _a.pluginEventType, beforeDispatch = _a.beforeDispatch, capture = _a.capture;
|
|
13
13
|
var eventName = key;
|
|
14
14
|
var onEvent = function (event) {
|
|
15
15
|
if (beforeDispatch) {
|
|
@@ -22,9 +22,11 @@ export var attachDomEvent = function (core, eventMap) {
|
|
|
22
22
|
}, false /*broadcast*/);
|
|
23
23
|
}
|
|
24
24
|
};
|
|
25
|
-
core.logicalRoot.addEventListener(eventName, onEvent);
|
|
25
|
+
core.logicalRoot.addEventListener(eventName, onEvent, { capture: capture });
|
|
26
26
|
return function () {
|
|
27
|
-
core.logicalRoot.removeEventListener(eventName, onEvent
|
|
27
|
+
core.logicalRoot.removeEventListener(eventName, onEvent, {
|
|
28
|
+
capture: capture,
|
|
29
|
+
});
|
|
28
30
|
};
|
|
29
31
|
});
|
|
30
32
|
return function () { return disposers.forEach(function (disposers) { return disposers(); }); };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attachDomEvent.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/coreApi/attachDomEvent/attachDomEvent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAG5D;;;;;;;GAOG;AACH,MAAM,CAAC,IAAM,cAAc,GAAmB,UAAC,IAAI,EAAE,QAAQ;IACzD,IAAM,SAAS,GAAG,aAAa,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,UAAA,GAAG;QAC7C,IAAA,
|
|
1
|
+
{"version":3,"file":"attachDomEvent.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/coreApi/attachDomEvent/attachDomEvent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAG5D;;;;;;;GAOG;AACH,MAAM,CAAC,IAAM,cAAc,GAAmB,UAAC,IAAI,EAAE,QAAQ;IACzD,IAAM,SAAS,GAAG,aAAa,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,UAAA,GAAG;QAC7C,IAAA,KAA+C,QAAQ,CAAC,GAAG,CAAC,EAA1D,eAAe,qBAAA,EAAE,cAAc,oBAAA,EAAE,OAAO,aAAkB,CAAC;QACnE,IAAM,SAAS,GAAG,GAAgC,CAAC;QACnD,IAAM,OAAO,GAAG,UAAC,KAA4C;YACzD,IAAI,cAAc,EAAE;gBAChB,cAAc,CAAC,KAAK,CAAC,CAAC;aACzB;YAED,IAAI,eAAe,IAAI,IAAI,EAAE;gBACzB,IAAI,CAAC,GAAG,CAAC,YAAY,CACjB,IAAI,EACS;oBACT,SAAS,EAAE,eAAe;oBAC1B,QAAQ,EAAE,KAAK;iBAClB,EACD,KAAK,CAAC,aAAa,CACtB,CAAC;aACL;QACL,CAAC,CAAC;QAEF,IAAI,CAAC,WAAW,CAAC,gBAAgB,CAAC,SAAS,EAAE,OAAO,EAAE,EAAE,OAAO,SAAA,EAAE,CAAC,CAAC;QAEnE,OAAO;YACH,IAAI,CAAC,WAAW,CAAC,mBAAmB,CAAC,SAAS,EAAE,OAAO,EAAE;gBACrD,OAAO,SAAA;aACV,CAAC,CAAC;QACP,CAAC,CAAC;IACN,CAAC,CAAC,CAAC;IAEH,OAAO,cAAM,OAAA,SAAS,CAAC,OAAO,CAAC,UAAA,SAAS,IAAI,OAAA,SAAS,EAAE,EAAX,CAAW,CAAC,EAA3C,CAA2C,CAAC;AAC7D,CAAC,CAAC","sourcesContent":["import { getObjectKeys } from 'roosterjs-content-model-dom';\nimport type { AttachDomEvent, PluginEvent } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n * Attach a DOM event to the editor content DIV\n * @param core The EditorCore object\n * @param eventName The DOM event name\n * @param pluginEventType Optional event type. When specified, editor will trigger a plugin event with this name when the DOM event is triggered\n * @param beforeDispatch Optional callback function to be invoked when the DOM event is triggered before trigger plugin event\n */\nexport const attachDomEvent: AttachDomEvent = (core, eventMap) => {\n const disposers = getObjectKeys(eventMap || {}).map(key => {\n const { pluginEventType, beforeDispatch, capture } = eventMap[key];\n const eventName = key as keyof HTMLElementEventMap;\n const onEvent = (event: HTMLElementEventMap[typeof eventName]) => {\n if (beforeDispatch) {\n beforeDispatch(event);\n }\n\n if (pluginEventType != null) {\n core.api.triggerEvent(\n core,\n <PluginEvent>{\n eventType: pluginEventType,\n rawEvent: event,\n },\n false /*broadcast*/\n );\n }\n };\n\n core.logicalRoot.addEventListener(eventName, onEvent, { capture });\n\n return () => {\n core.logicalRoot.removeEventListener(eventName, onEvent, {\n capture,\n });\n };\n });\n\n return () => disposers.forEach(disposers => disposers());\n};\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isNodeOfType, parseValueWithUnit, toArray } from 'roosterjs-content-model-dom';
|
|
1
|
+
import { getColor, isNodeOfType, parseValueWithUnit, toArray } from 'roosterjs-content-model-dom';
|
|
2
2
|
var DOMHelperImpl = /** @class */ (function () {
|
|
3
3
|
function DOMHelperImpl(contentDiv) {
|
|
4
4
|
this.contentDiv = contentDiv;
|
|
@@ -79,8 +79,10 @@ var DOMHelperImpl = /** @class */ (function () {
|
|
|
79
79
|
};
|
|
80
80
|
/**
|
|
81
81
|
* Get format of the container element
|
|
82
|
+
* @param isInDarkMode Optional flag to indicate if the environment is in dark mode
|
|
83
|
+
* @param darkColorHandler Optional DarkColorHandler to retrieve dark mode colors
|
|
82
84
|
*/
|
|
83
|
-
DOMHelperImpl.prototype.getContainerFormat = function () {
|
|
85
|
+
DOMHelperImpl.prototype.getContainerFormat = function (isInDarkMode, darkColorHandler) {
|
|
84
86
|
var _a, _b;
|
|
85
87
|
var window = this.contentDiv.ownerDocument.defaultView;
|
|
86
88
|
var style = window === null || window === void 0 ? void 0 : window.getComputedStyle(this.contentDiv);
|
|
@@ -89,8 +91,8 @@ var DOMHelperImpl = /** @class */ (function () {
|
|
|
89
91
|
fontSize: style.fontSize,
|
|
90
92
|
fontFamily: style.fontFamily,
|
|
91
93
|
fontWeight: style.fontWeight,
|
|
92
|
-
textColor: style.color,
|
|
93
|
-
backgroundColor: style.backgroundColor,
|
|
94
|
+
textColor: getColor(this.contentDiv, false /*isBackgroundColor*/, !!isInDarkMode, darkColorHandler, style.color),
|
|
95
|
+
backgroundColor: getColor(this.contentDiv, true /*isBackgroundColor*/, !!isInDarkMode, darkColorHandler, style.backgroundColor),
|
|
94
96
|
italic: style.fontStyle == 'italic',
|
|
95
97
|
letterSpacing: style.letterSpacing,
|
|
96
98
|
lineHeight: style.lineHeight,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DOMHelperImpl.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/editor/core/DOMHelperImpl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"DOMHelperImpl.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/editor/core/DOMHelperImpl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAOlG;IACI,uBAAoB,UAAuB;QAAvB,eAAU,GAAV,UAAU,CAAa;IAAG,CAAC;IAE/C,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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AAC;IACb,CAAC;IACL,oBAAC;AAAD,CAAC,AAjID,IAiIC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,UAAuB;IACnD,OAAO,IAAI,aAAa,CAAC,UAAU,CAAC,CAAC;AACzC,CAAC","sourcesContent":["import { getColor, isNodeOfType, parseValueWithUnit, toArray } from 'roosterjs-content-model-dom';\nimport type {\n ContentModelSegmentFormat,\n DarkColorHandler,\n DOMHelper,\n} from 'roosterjs-content-model-types';\n\nclass DOMHelperImpl implements DOMHelper {\n constructor(private contentDiv: HTMLElement) {}\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 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 return this.contentDiv.cloneNode(true /*deep*/) as HTMLElement;\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/**\n * @internal Create new instance of DOMHelper\n */\nexport function createDOMHelper(contentDiv: HTMLElement): DOMHelper {\n return new DOMHelperImpl(contentDiv);\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.34.0",
|
|
7
|
+
"roosterjs-content-model-types": "^9.34.0"
|
|
8
8
|
},
|
|
9
|
-
"version": "9.
|
|
9
|
+
"version": "9.34.0",
|
|
10
10
|
"main": "./lib/index.js",
|
|
11
11
|
"typings": "./lib/index.d.ts",
|
|
12
12
|
"module": "./lib-mjs/index.js",
|