roosterjs-content-model-core 9.58.0 → 9.59.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.
Files changed (55) hide show
  1. package/lib/command/exportContent/exportContent.js +1 -1
  2. package/lib/command/exportContent/exportContent.js.map +1 -1
  3. package/lib/coreApi/restoreUndoSnapshot/restoreSnapshotColors.js +1 -1
  4. package/lib/coreApi/restoreUndoSnapshot/restoreSnapshotColors.js.map +1 -1
  5. package/lib/coreApi/triggerEvent/triggerEvent.js +2 -0
  6. package/lib/coreApi/triggerEvent/triggerEvent.js.map +1 -1
  7. package/lib/corePlugin/entity/EntityPlugin.js +1 -1
  8. package/lib/corePlugin/entity/EntityPlugin.js.map +1 -1
  9. package/lib/editor/Editor.js +5 -2
  10. package/lib/editor/Editor.js.map +1 -1
  11. package/lib/editor/core/createEditorCore.js +6 -4
  12. package/lib/editor/core/createEditorCore.js.map +1 -1
  13. package/lib/index.d.ts +1 -0
  14. package/lib/index.js +5 -2
  15. package/lib/index.js.map +1 -1
  16. package/lib/utils/devtoolsHook.d.ts +35 -0
  17. package/lib/utils/devtoolsHook.js +89 -0
  18. package/lib/utils/devtoolsHook.js.map +1 -0
  19. package/lib-amd/command/exportContent/exportContent.js +1 -1
  20. package/lib-amd/command/exportContent/exportContent.js.map +1 -1
  21. package/lib-amd/coreApi/restoreUndoSnapshot/restoreSnapshotColors.js +1 -1
  22. package/lib-amd/coreApi/restoreUndoSnapshot/restoreSnapshotColors.js.map +1 -1
  23. package/lib-amd/coreApi/triggerEvent/triggerEvent.js +2 -1
  24. package/lib-amd/coreApi/triggerEvent/triggerEvent.js.map +1 -1
  25. package/lib-amd/corePlugin/entity/EntityPlugin.js +1 -1
  26. package/lib-amd/corePlugin/entity/EntityPlugin.js.map +1 -1
  27. package/lib-amd/editor/Editor.js +5 -3
  28. package/lib-amd/editor/Editor.js.map +1 -1
  29. package/lib-amd/editor/core/createEditorCore.js +6 -4
  30. package/lib-amd/editor/core/createEditorCore.js.map +1 -1
  31. package/lib-amd/index.d.ts +1 -0
  32. package/lib-amd/index.js +3 -2
  33. package/lib-amd/index.js.map +1 -1
  34. package/lib-amd/utils/devtoolsHook.d.ts +35 -0
  35. package/lib-amd/utils/devtoolsHook.js +91 -0
  36. package/lib-amd/utils/devtoolsHook.js.map +1 -0
  37. package/lib-mjs/command/exportContent/exportContent.js +1 -1
  38. package/lib-mjs/command/exportContent/exportContent.js.map +1 -1
  39. package/lib-mjs/coreApi/restoreUndoSnapshot/restoreSnapshotColors.js +1 -1
  40. package/lib-mjs/coreApi/restoreUndoSnapshot/restoreSnapshotColors.js.map +1 -1
  41. package/lib-mjs/coreApi/triggerEvent/triggerEvent.js +2 -0
  42. package/lib-mjs/coreApi/triggerEvent/triggerEvent.js.map +1 -1
  43. package/lib-mjs/corePlugin/entity/EntityPlugin.js +1 -1
  44. package/lib-mjs/corePlugin/entity/EntityPlugin.js.map +1 -1
  45. package/lib-mjs/editor/Editor.js +5 -2
  46. package/lib-mjs/editor/Editor.js.map +1 -1
  47. package/lib-mjs/editor/core/createEditorCore.js +6 -4
  48. package/lib-mjs/editor/core/createEditorCore.js.map +1 -1
  49. package/lib-mjs/index.d.ts +1 -0
  50. package/lib-mjs/index.js +3 -1
  51. package/lib-mjs/index.js.map +1 -1
  52. package/lib-mjs/utils/devtoolsHook.d.ts +35 -0
  53. package/lib-mjs/utils/devtoolsHook.js +83 -0
  54. package/lib-mjs/utils/devtoolsHook.js.map +1 -0
  55. package/package.json +3 -3
@@ -18,7 +18,7 @@ function exportContent(editor, mode, optionsOrCallbacks) {
18
18
  var clonedRoot = editor.getDOMHelper().getClonedRoot();
19
19
  if (editor.isDarkMode()) {
20
20
  (0, roosterjs_content_model_dom_1.transformColor)(clonedRoot, false /*includeSelf*/, 'darkToLight', editor.getColorManager(), {
21
- tableBorders: editor.isExperimentalFeatureEnabled('TransformTableBorderColors'),
21
+ tableBorders: true,
22
22
  });
23
23
  }
24
24
  return getHTMLFromDOM(editor, clonedRoot);
@@ -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,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"]}
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;IAEh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1B,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: true,\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"]}
@@ -10,7 +10,7 @@ function restoreSnapshotColors(core, snapshot) {
10
10
  core.darkColorHandler.updateKnownColor(isDarkMode); // Pass no parameter to force update all colors
11
11
  if (!!snapshot.isDarkMode != !!isDarkMode) {
12
12
  (0, roosterjs_content_model_dom_1.transformColor)(core.physicalRoot, false /*includeSelf*/, isDarkMode ? 'lightToDark' : 'darkToLight', core.darkColorHandler, {
13
- tableBorders: core.experimentalFeatures.indexOf('TransformTableBorderColors') > -1,
13
+ tableBorders: true,
14
14
  });
15
15
  }
16
16
  }
@@ -1 +1 @@
1
- {"version":3,"file":"restoreSnapshotColors.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/coreApi/restoreUndoSnapshot/restoreSnapshotColors.ts"],"names":[],"mappings":";;;AAAA,2EAA6D;AAG7D;;GAEG;AACH,SAAgB,qBAAqB,CAAC,IAAgB,EAAE,QAAkB;IACtE,IAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC;IAE7C,IAAI,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC,CAAC,+CAA+C;IAEnG,IAAI,CAAC,CAAC,QAAQ,CAAC,UAAU,IAAI,CAAC,CAAC,UAAU,EAAE;QACvC,IAAA,4CAAc,EACV,IAAI,CAAC,YAAY,EACjB,KAAK,CAAC,eAAe,EACrB,UAAU,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,aAAa,EAC1C,IAAI,CAAC,gBAAgB,EACrB;YACI,YAAY,EAAE,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAAC,4BAA4B,CAAC,GAAG,CAAC,CAAC;SACrF,CACJ,CAAC;KACL;AACL,CAAC;AAhBD,sDAgBC","sourcesContent":["import { transformColor } from 'roosterjs-content-model-dom';\nimport type { EditorCore, Snapshot } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function restoreSnapshotColors(core: EditorCore, snapshot: Snapshot) {\n const isDarkMode = core.lifecycle.isDarkMode;\n\n core.darkColorHandler.updateKnownColor(isDarkMode); // Pass no parameter to force update all colors\n\n if (!!snapshot.isDarkMode != !!isDarkMode) {\n transformColor(\n core.physicalRoot,\n false /*includeSelf*/,\n isDarkMode ? 'lightToDark' : 'darkToLight',\n core.darkColorHandler,\n {\n tableBorders: core.experimentalFeatures.indexOf('TransformTableBorderColors') > -1,\n }\n );\n }\n}\n"]}
1
+ {"version":3,"file":"restoreSnapshotColors.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/coreApi/restoreUndoSnapshot/restoreSnapshotColors.ts"],"names":[],"mappings":";;;AAAA,2EAA6D;AAG7D;;GAEG;AACH,SAAgB,qBAAqB,CAAC,IAAgB,EAAE,QAAkB;IACtE,IAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC;IAE7C,IAAI,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC,CAAC,+CAA+C;IAEnG,IAAI,CAAC,CAAC,QAAQ,CAAC,UAAU,IAAI,CAAC,CAAC,UAAU,EAAE;QACvC,IAAA,4CAAc,EACV,IAAI,CAAC,YAAY,EACjB,KAAK,CAAC,eAAe,EACrB,UAAU,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,aAAa,EAC1C,IAAI,CAAC,gBAAgB,EACrB;YACI,YAAY,EAAE,IAAI;SACrB,CACJ,CAAC;KACL;AACL,CAAC;AAhBD,sDAgBC","sourcesContent":["import { transformColor } from 'roosterjs-content-model-dom';\nimport type { EditorCore, Snapshot } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function restoreSnapshotColors(core: EditorCore, snapshot: Snapshot) {\n const isDarkMode = core.lifecycle.isDarkMode;\n\n core.darkColorHandler.updateKnownColor(isDarkMode); // Pass no parameter to force update all colors\n\n if (!!snapshot.isDarkMode != !!isDarkMode) {\n transformColor(\n core.physicalRoot,\n false /*includeSelf*/,\n isDarkMode ? 'lightToDark' : 'darkToLight',\n core.darkColorHandler,\n {\n tableBorders: true,\n }\n );\n }\n}\n"]}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.triggerEvent = void 0;
4
+ var devtoolsHook_1 = require("../../utils/devtoolsHook");
4
5
  var allowedEventsInShadowEdit = [
5
6
  'editorReady',
6
7
  'beforeDispose',
@@ -24,6 +25,7 @@ var triggerEvent = function (core, pluginEvent, broadcast) {
24
25
  }
25
26
  });
26
27
  }
28
+ (0, devtoolsHook_1.notifyDevToolsPluginEvent)(core, pluginEvent);
27
29
  };
28
30
  exports.triggerEvent = triggerEvent;
29
31
  function handledExclusively(event, plugin) {
@@ -1 +1 @@
1
- {"version":3,"file":"triggerEvent.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/coreApi/triggerEvent/triggerEvent.ts"],"names":[],"mappings":";;;AAOA,IAAM,yBAAyB,GAAsB;IACjD,aAAa;IACb,eAAe;IACf,uBAAuB;IACvB,aAAa;CAChB,CAAC;AAEF;;;;;;GAMG;AACI,IAAM,YAAY,GAAiB,UAAC,IAAI,EAAE,WAAW,EAAE,SAAS;IACnE,IACI,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,kBAAkB;QAC/B,yBAAyB,CAAC,OAAO,CAAC,WAAW,CAAC,SAA4B,CAAC,IAAI,CAAC,CAAC;QACrF,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,UAAA,MAAM,IAAI,OAAA,kBAAkB,CAAC,WAAW,EAAE,MAAM,CAAC,EAAvC,CAAuC,CAAC,CAAC,EACtF;QACE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,UAAA,MAAM;YACvB,IAAI,MAAM,CAAC,aAAa,EAAE;gBACtB,MAAM,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;aACrC;QACL,CAAC,CAAC,CAAC;KACN;AACL,CAAC,CAAC;AAZW,QAAA,YAAY,gBAYvB;AAEF,SAAS,kBAAkB,CAAC,KAAkB,EAAE,MAAoB;;IAChE,IAAI,MAAM,CAAC,aAAa,KAAI,MAAA,MAAM,CAAC,0BAA0B,+CAAjC,MAAM,EAA8B,KAAK,CAAC,CAAA,EAAE;QACpE,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QAC5B,OAAO,IAAI,CAAC;KACf;IAED,OAAO,KAAK,CAAC;AACjB,CAAC","sourcesContent":["import type {\n EditorPlugin,\n PluginEvent,\n PluginEventType,\n TriggerEvent,\n} from 'roosterjs-content-model-types';\n\nconst allowedEventsInShadowEdit: PluginEventType[] = [\n 'editorReady',\n 'beforeDispose',\n 'extractContentWithDom',\n 'zoomChanged',\n];\n\n/**\n * @internal\n * Trigger a plugin event\n * @param core The EditorCore object\n * @param pluginEvent The event object to trigger\n * @param broadcast Set to true to skip the shouldHandleEventExclusively check\n */\nexport const triggerEvent: TriggerEvent = (core, pluginEvent, broadcast) => {\n if (\n (!core.lifecycle.shadowEditFragment ||\n allowedEventsInShadowEdit.indexOf(pluginEvent.eventType as PluginEventType) >= 0) &&\n (broadcast || !core.plugins.some(plugin => handledExclusively(pluginEvent, plugin)))\n ) {\n core.plugins.forEach(plugin => {\n if (plugin.onPluginEvent) {\n plugin.onPluginEvent(pluginEvent);\n }\n });\n }\n};\n\nfunction handledExclusively(event: PluginEvent, plugin: EditorPlugin): boolean {\n if (plugin.onPluginEvent && plugin.willHandleEventExclusively?.(event)) {\n plugin.onPluginEvent(event);\n return true;\n }\n\n return false;\n}\n"]}
1
+ {"version":3,"file":"triggerEvent.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/coreApi/triggerEvent/triggerEvent.ts"],"names":[],"mappings":";;;AAAA,yDAAqE;AAQrE,IAAM,yBAAyB,GAAsB;IACjD,aAAa;IACb,eAAe;IACf,uBAAuB;IACvB,aAAa;CAChB,CAAC;AAEF;;;;;;GAMG;AACI,IAAM,YAAY,GAAiB,UAAC,IAAI,EAAE,WAAW,EAAE,SAAS;IACnE,IACI,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,kBAAkB;QAC/B,yBAAyB,CAAC,OAAO,CAAC,WAAW,CAAC,SAA4B,CAAC,IAAI,CAAC,CAAC;QACrF,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,UAAA,MAAM,IAAI,OAAA,kBAAkB,CAAC,WAAW,EAAE,MAAM,CAAC,EAAvC,CAAuC,CAAC,CAAC,EACtF;QACE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,UAAA,MAAM;YACvB,IAAI,MAAM,CAAC,aAAa,EAAE;gBACtB,MAAM,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;aACrC;QACL,CAAC,CAAC,CAAC;KACN;IAED,IAAA,wCAAyB,EAAC,IAAI,EAAE,WAAW,CAAC,CAAC;AACjD,CAAC,CAAC;AAdW,QAAA,YAAY,gBAcvB;AAEF,SAAS,kBAAkB,CAAC,KAAkB,EAAE,MAAoB;;IAChE,IAAI,MAAM,CAAC,aAAa,KAAI,MAAA,MAAM,CAAC,0BAA0B,+CAAjC,MAAM,EAA8B,KAAK,CAAC,CAAA,EAAE;QACpE,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QAC5B,OAAO,IAAI,CAAC;KACf;IAED,OAAO,KAAK,CAAC;AACjB,CAAC","sourcesContent":["import { notifyDevToolsPluginEvent } from '../../utils/devtoolsHook';\nimport type {\n EditorPlugin,\n PluginEvent,\n PluginEventType,\n TriggerEvent,\n} from 'roosterjs-content-model-types';\n\nconst allowedEventsInShadowEdit: PluginEventType[] = [\n 'editorReady',\n 'beforeDispose',\n 'extractContentWithDom',\n 'zoomChanged',\n];\n\n/**\n * @internal\n * Trigger a plugin event\n * @param core The EditorCore object\n * @param pluginEvent The event object to trigger\n * @param broadcast Set to true to skip the shouldHandleEventExclusively check\n */\nexport const triggerEvent: TriggerEvent = (core, pluginEvent, broadcast) => {\n if (\n (!core.lifecycle.shadowEditFragment ||\n allowedEventsInShadowEdit.indexOf(pluginEvent.eventType as PluginEventType) >= 0) &&\n (broadcast || !core.plugins.some(plugin => handledExclusively(pluginEvent, plugin)))\n ) {\n core.plugins.forEach(plugin => {\n if (plugin.onPluginEvent) {\n plugin.onPluginEvent(pluginEvent);\n }\n });\n }\n\n notifyDevToolsPluginEvent(core, pluginEvent);\n};\n\nfunction handledExclusively(event: PluginEvent, plugin: EditorPlugin): boolean {\n if (plugin.onPluginEvent && plugin.willHandleEventExclusively?.(event)) {\n plugin.onPluginEvent(event);\n return true;\n }\n\n return false;\n}\n"]}
@@ -109,7 +109,7 @@ var EntityPlugin = /** @class */ (function () {
109
109
  };
110
110
  if (editor.isDarkMode()) {
111
111
  (0, roosterjs_content_model_dom_1.transformColor)(wrapper, true /*includeSelf*/, 'lightToDark', editor.getColorManager(), {
112
- tableBorders: editor.isExperimentalFeatureEnabled('TransformTableBorderColors'),
112
+ tableBorders: true,
113
113
  });
114
114
  }
115
115
  }
@@ -1 +1 @@
1
- {"version":3,"file":"EntityPlugin.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/corePlugin/entity/EntityPlugin.ts"],"names":[],"mappings":";;;AAAA,qDAAoD;AACpD,2EAQqC;AACrC,+DAIgC;AAYhC,IAAM,eAAe,GAAG,aAAa,CAAC;AAEtC;;GAEG;AACH;IAII;;OAEG;IACH;QANQ,WAAM,GAAmB,IAAI,CAAC;QAOlC,IAAI,CAAC,KAAK,GAAG;YACT,SAAS,EAAE,EAAE;SAChB,CAAC;IACN,CAAC;IAED;;OAEG;IACH,8BAAO,GAAP;QACI,OAAO,QAAQ,CAAC;IACpB,CAAC;IAED;;;OAGG;IACH,iCAAU,GAAV,UAAW,MAAe;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,8BAAO,GAAP;QACI,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACnB,IAAI,CAAC,KAAK,CAAC,SAAS,GAAG,EAAE,CAAC;IAC9B,CAAC;IAED;;OAEG;IACH,+BAAQ,GAAR;QACI,OAAO,IAAI,CAAC,KAAK,CAAC;IACtB,CAAC;IAED;;;OAGG;IACH,oCAAa,GAAb,UAAc,KAAkB;QAC5B,IAAI,IAAI,CAAC,MAAM,EAAE;YACb,QAAQ,KAAK,CAAC,SAAS,EAAE;gBACrB,KAAK,SAAS;oBACV,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;oBAC5C,MAAM;gBACV,KAAK,gBAAgB;oBACjB,IAAI,CAAC,yBAAyB,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;oBACnD,MAAM;gBACV,KAAK,SAAS;oBACV,IAAA,kDAA2B,EAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;oBAChD,MAAM;gBACV,KAAK,gBAAgB;oBACjB,IAAA,gDAAyB,EAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;oBAC9C,MA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AI,OAAO,EAAE;gBAClC,MAAM;aACT;SACJ;QAED,OAAO,KAAK,CAAC;IACjB,CAAC;IACL,mBAAC;AAAD,CAAC,AAnQD,IAmQC;AAED;;;GAGG;AACH,SAAgB,kBAAkB;IAC9B,OAAO,IAAI,YAAY,EAAE,CAAC;AAC9B,CAAC;AAFD,gDAEC","sourcesContent":["import { findAllEntities } from './findAllEntities';\nimport {\n createEntity,\n generateEntityClassNames,\n getAllEntityWrappers,\n getObjectKeys,\n isEntityElement,\n parseEntityFormat,\n transformColor,\n} from 'roosterjs-content-model-dom';\nimport {\n handleCompositionEndEvent,\n handleDelimiterContentChangedEvent,\n handleDelimiterKeyDownEvent,\n} from './entityDelimiterUtils';\nimport type {\n ChangedEntity,\n ContentChangedEvent,\n EntityOperation,\n EntityPluginState,\n IEditor,\n MouseUpEvent,\n PluginEvent,\n PluginWithState,\n} from 'roosterjs-content-model-types';\n\nconst ENTITY_ID_REGEX = /_(\\d{1,8})$/;\n\n/**\n * Entity Plugin helps handle all operations related to an entity and generate entity specified events\n */\nclass EntityPlugin implements PluginWithState<EntityPluginState> {\n private editor: IEditor | null = null;\n private state: EntityPluginState;\n\n /**\n * Construct a new instance of EntityPlugin\n */\n constructor() {\n this.state = {\n entityMap: {},\n };\n }\n\n /**\n * Get a friendly name of this plugin\n */\n getName() {\n return 'Entity';\n }\n\n /**\n * Initialize this plugin. This should only be called from Editor\n * @param editor Editor instance\n */\n initialize(editor: IEditor) {\n this.editor = editor;\n }\n\n /**\n * Dispose this plugin\n */\n dispose() {\n this.editor = null;\n this.state.entityMap = {};\n }\n\n /**\n * Get plugin state object\n */\n getState() {\n return this.state;\n }\n\n /**\n * Handle events triggered from editor\n * @param event PluginEvent object\n */\n onPluginEvent(event: PluginEvent) {\n if (this.editor) {\n switch (event.eventType) {\n case 'mouseUp':\n this.handleMouseUpEvent(this.editor, event);\n break;\n case 'contentChanged':\n this.handleContentChangedEvent(this.editor, event);\n break;\n case 'keyDown':\n handleDelimiterKeyDownEvent(this.editor, event);\n break;\n case 'compositionEnd':\n handleCompositionEndEvent(this.editor, event);\n break;\n case 'editorReady':\n this.handleContentChangedEvent(this.editor);\n break;\n case 'extractContentWithDom':\n this.handleExtractContentWithDomEvent(this.editor, event.clonedRoot);\n break;\n }\n }\n }\n\n private handleMouseUpEvent(editor: IEditor, event: MouseUpEvent) {\n const { rawEvent, isClicking } = event;\n let node: Node | null = rawEvent.target as Node;\n\n if (isClicking && this.editor) {\n while (node && this.editor.getDOMHelper().isNodeInEditor(node)) {\n if (isEntityElement(node)) {\n this.triggerEvent(editor, node as HTMLElement, 'click', rawEvent);\n break;\n } else {\n node = node.parentNode;\n }\n }\n }\n }\n\n private handleContentChangedEvent(editor: IEditor, event?: ContentChangedEvent) {\n const modifiedEntities: ChangedEntity[] =\n event?.changedEntities ?? this.getChangedEntities(editor);\n const entityStates = event?.entityStates;\n\n modifiedEntities.forEach(entry => {\n const { entity, operation, rawEvent } = entry;\n const {\n entityFormat: { id, entityType, isFakeEntity },\n wrapper,\n } = entity;\n\n if (entityType && !isFakeEntity) {\n if (operation == 'newEntity') {\n entity.entityFormat.id = this.ensureUniqueId(entityType, id ?? '', wrapper);\n wrapper.className = generateEntityClassNames(entity.entityFormat);\n\n if (entity.entityFormat.isReadonly) {\n wrapper.contentEditable = 'false';\n }\n\n const eventResult = this.triggerEvent(editor, wrapper, operation, rawEvent);\n\n this.state.entityMap[entity.entityFormat.id] = {\n element: wrapper,\n canPersist: eventResult?.shouldPersist,\n };\n\n if (editor.isDarkMode()) {\n transformColor(\n wrapper,\n true /*includeSelf*/,\n 'lightToDark',\n editor.getColorManager(),\n {\n tableBorders: editor.isExperimentalFeatureEnabled(\n 'TransformTableBorderColors'\n ),\n }\n );\n }\n } else if (id) {\n const mapEntry = this.state.entityMap[id];\n\n if (mapEntry) {\n mapEntry.isDeleted = true;\n }\n\n this.triggerEvent(editor, wrapper, operation, rawEvent);\n }\n }\n });\n\n entityStates?.forEach(entityState => {\n const { id, state } = entityState;\n const wrapper = this.state.entityMap[id]?.element;\n\n if (wrapper) {\n this.triggerEvent(\n editor,\n wrapper,\n 'updateEntityState',\n undefined /*rawEvent*/,\n state\n );\n }\n });\n\n handleDelimiterContentChangedEvent(editor);\n }\n\n private getChangedEntities(editor: IEditor): ChangedEntity[] {\n const result: ChangedEntity[] = [];\n\n editor.formatContentModel(model => {\n findAllEntities(model, result);\n return false;\n });\n\n getObjectKeys(this.state.entityMap).forEach(id => {\n const entry = this.state.entityMap[id];\n\n if (!entry.isDeleted) {\n const index = result.findIndex(\n x =>\n x.operation == 'newEntity' &&\n x.entity.entityFormat.id == id &&\n x.entity.wrapper == entry.element\n );\n\n if (index >= 0) {\n // Found matched entity in editor, so there is no change to this entity,\n // we can safely remove it from the new entity array\n result.splice(index, 1);\n } else {\n // Entity is not in editor, which means it is deleted, use a temporary entity here to represent this entity\n const format = parseEntityFormat(entry.element);\n\n if (!format.isFakeEntity) {\n const entity = createEntity(\n entry.element,\n format.isReadonly,\n {},\n format.entityType,\n format.id\n );\n\n result.push({\n entity: entity,\n operation: 'overwrite',\n });\n }\n }\n }\n });\n\n return result;\n }\n\n private handleExtractContentWithDomEvent(editor: IEditor, root: HTMLElement) {\n getAllEntityWrappers(root).forEach(element => {\n element.removeAttribute('contentEditable');\n\n this.triggerEvent(editor, element, 'replaceTemporaryContent');\n });\n }\n\n private triggerEvent(\n editor: IEditor,\n wrapper: HTMLElement,\n operation: EntityOperation,\n rawEvent?: Event,\n state?: string\n ) {\n const format = parseEntityFormat(wrapper);\n\n return format.id && format.entityType && !format.isFakeEntity\n ? editor.triggerEvent('entityOperation', {\n operation: operation,\n rawEvent,\n entity: {\n id: format.id,\n type: format.entityType,\n isReadonly: !!format.isReadonly,\n wrapper,\n },\n state: operation == 'updateEntityState' ? state : undefined,\n shouldPersist: operation == 'newEntity' ? true : undefined, // By default, we always persist entity now\n })\n : null;\n }\n\n private ensureUniqueId(type: string, id: string, wrapper: HTMLElement): string {\n const match = ENTITY_ID_REGEX.exec(id);\n const baseId = (match ? id.substr(0, id.length - match[0].length) : id) || type;\n\n // Make sure entity id is unique\n let newId = '';\n\n for (let num = (match && parseInt(match[1])) || 0; ; num++) {\n newId = num > 0 ? `${baseId}_${num}` : baseId;\n\n const item = this.state.entityMap[newId];\n\n if (!item || item.element == wrapper) {\n break;\n }\n }\n\n return newId;\n }\n}\n\n/**\n * @internal\n * Create a new instance of EntityPlugin.\n */\nexport function createEntityPlugin(): PluginWithState<EntityPluginState> {\n return new EntityPlugin();\n}\n"]}
1
+ {"version":3,"file":"EntityPlugin.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/corePlugin/entity/EntityPlugin.ts"],"names":[],"mappings":";;;AAAA,qDAAoD;AACpD,2EAQqC;AACrC,+DAIgC;AAYhC,IAAM,eAAe,GAAG,aAAa,CAAC;AAEtC;;GAEG;AACH;IAII;;OAEG;IACH;QANQ,WAAM,GAAmB,IAAI,CAAC;QAOlC,IAAI,CAAC,KAAK,GAAG;YACT,SAAS,EAAE,EAAE;SAChB,CAAC;IACN,CAAC;IAED;;OAEG;IACH,8BAAO,GAAP;QACI,OAAO,QAAQ,CAAC;IACpB,CAAC;IAED;;;OAGG;IACH,iCAAU,GAAV,UAAW,MAAe;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,8BAAO,GAAP;QACI,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACnB,IAAI,CAAC,KAAK,CAAC,SAAS,GAAG,EAAE,CAAC;IAC9B,CAAC;IAED;;OAEG;IACH,+BAAQ,GAAR;QACI,OAAO,IAAI,CAAC,KAAK,CAAC;IACtB,CAAC;IAED;;;OAGG;IACH,oCAAa,GAAb,UAAc,KAAkB;QAC5B,IAAI,IAAI,CAAC,MAAM,EAAE;YACb,QAAQ,KAAK,CAAC,SAAS,EAAE;gBACrB,KAAK,SAAS;oBACV,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,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QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAI,GAAG,EAAE,EAAE;YACxD,KAAK,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,CAAI,MAAM,SAAI,GAAK,CAAC,CAAC,CAAC,MAAM,CAAC;YAE9C,IAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;YAEzC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,OAAO,IAAI,OAAO,EAAE;gBAClC,MAAM;aACT;SACJ;QAED,OAAO,KAAK,CAAC;IACjB,CAAC;IACL,mBAAC;AAAD,CAAC,AAjQD,IAiQC;AAED;;;GAGG;AACH,SAAgB,kBAAkB;IAC9B,OAAO,IAAI,YAAY,EAAE,CAAC;AAC9B,CAAC;AAFD,gDAEC","sourcesContent":["import { findAllEntities } from './findAllEntities';\nimport {\n createEntity,\n generateEntityClassNames,\n getAllEntityWrappers,\n getObjectKeys,\n isEntityElement,\n parseEntityFormat,\n transformColor,\n} from 'roosterjs-content-model-dom';\nimport {\n handleCompositionEndEvent,\n handleDelimiterContentChangedEvent,\n handleDelimiterKeyDownEvent,\n} from './entityDelimiterUtils';\nimport type {\n ChangedEntity,\n ContentChangedEvent,\n EntityOperation,\n EntityPluginState,\n IEditor,\n MouseUpEvent,\n PluginEvent,\n PluginWithState,\n} from 'roosterjs-content-model-types';\n\nconst ENTITY_ID_REGEX = /_(\\d{1,8})$/;\n\n/**\n * Entity Plugin helps handle all operations related to an entity and generate entity specified events\n */\nclass EntityPlugin implements PluginWithState<EntityPluginState> {\n private editor: IEditor | null = null;\n private state: EntityPluginState;\n\n /**\n * Construct a new instance of EntityPlugin\n */\n constructor() {\n this.state = {\n entityMap: {},\n };\n }\n\n /**\n * Get a friendly name of this plugin\n */\n getName() {\n return 'Entity';\n }\n\n /**\n * Initialize this plugin. This should only be called from Editor\n * @param editor Editor instance\n */\n initialize(editor: IEditor) {\n this.editor = editor;\n }\n\n /**\n * Dispose this plugin\n */\n dispose() {\n this.editor = null;\n this.state.entityMap = {};\n }\n\n /**\n * Get plugin state object\n */\n getState() {\n return this.state;\n }\n\n /**\n * Handle events triggered from editor\n * @param event PluginEvent object\n */\n onPluginEvent(event: PluginEvent) {\n if (this.editor) {\n switch (event.eventType) {\n case 'mouseUp':\n this.handleMouseUpEvent(this.editor, event);\n break;\n case 'contentChanged':\n this.handleContentChangedEvent(this.editor, event);\n break;\n case 'keyDown':\n handleDelimiterKeyDownEvent(this.editor, event);\n break;\n case 'compositionEnd':\n handleCompositionEndEvent(this.editor, event);\n break;\n case 'editorReady':\n this.handleContentChangedEvent(this.editor);\n break;\n case 'extractContentWithDom':\n this.handleExtractContentWithDomEvent(this.editor, event.clonedRoot);\n break;\n }\n }\n }\n\n private handleMouseUpEvent(editor: IEditor, event: MouseUpEvent) {\n const { rawEvent, isClicking } = event;\n let node: Node | null = rawEvent.target as Node;\n\n if (isClicking && this.editor) {\n while (node && this.editor.getDOMHelper().isNodeInEditor(node)) {\n if (isEntityElement(node)) {\n this.triggerEvent(editor, node as HTMLElement, 'click', rawEvent);\n break;\n } else {\n node = node.parentNode;\n }\n }\n }\n }\n\n private handleContentChangedEvent(editor: IEditor, event?: ContentChangedEvent) {\n const modifiedEntities: ChangedEntity[] =\n event?.changedEntities ?? this.getChangedEntities(editor);\n const entityStates = event?.entityStates;\n\n modifiedEntities.forEach(entry => {\n const { entity, operation, rawEvent } = entry;\n const {\n entityFormat: { id, entityType, isFakeEntity },\n wrapper,\n } = entity;\n\n if (entityType && !isFakeEntity) {\n if (operation == 'newEntity') {\n entity.entityFormat.id = this.ensureUniqueId(entityType, id ?? '', wrapper);\n wrapper.className = generateEntityClassNames(entity.entityFormat);\n\n if (entity.entityFormat.isReadonly) {\n wrapper.contentEditable = 'false';\n }\n\n const eventResult = this.triggerEvent(editor, wrapper, operation, rawEvent);\n\n this.state.entityMap[entity.entityFormat.id] = {\n element: wrapper,\n canPersist: eventResult?.shouldPersist,\n };\n\n if (editor.isDarkMode()) {\n transformColor(\n wrapper,\n true /*includeSelf*/,\n 'lightToDark',\n editor.getColorManager(),\n {\n tableBorders: true,\n }\n );\n }\n } else if (id) {\n const mapEntry = this.state.entityMap[id];\n\n if (mapEntry) {\n mapEntry.isDeleted = true;\n }\n\n this.triggerEvent(editor, wrapper, operation, rawEvent);\n }\n }\n });\n\n entityStates?.forEach(entityState => {\n const { id, state } = entityState;\n const wrapper = this.state.entityMap[id]?.element;\n\n if (wrapper) {\n this.triggerEvent(\n editor,\n wrapper,\n 'updateEntityState',\n undefined /*rawEvent*/,\n state\n );\n }\n });\n\n handleDelimiterContentChangedEvent(editor);\n }\n\n private getChangedEntities(editor: IEditor): ChangedEntity[] {\n const result: ChangedEntity[] = [];\n\n editor.formatContentModel(model => {\n findAllEntities(model, result);\n return false;\n });\n\n getObjectKeys(this.state.entityMap).forEach(id => {\n const entry = this.state.entityMap[id];\n\n if (!entry.isDeleted) {\n const index = result.findIndex(\n x =>\n x.operation == 'newEntity' &&\n x.entity.entityFormat.id == id &&\n x.entity.wrapper == entry.element\n );\n\n if (index >= 0) {\n // Found matched entity in editor, so there is no change to this entity,\n // we can safely remove it from the new entity array\n result.splice(index, 1);\n } else {\n // Entity is not in editor, which means it is deleted, use a temporary entity here to represent this entity\n const format = parseEntityFormat(entry.element);\n\n if (!format.isFakeEntity) {\n const entity = createEntity(\n entry.element,\n format.isReadonly,\n {},\n format.entityType,\n format.id\n );\n\n result.push({\n entity: entity,\n operation: 'overwrite',\n });\n }\n }\n }\n });\n\n return result;\n }\n\n private handleExtractContentWithDomEvent(editor: IEditor, root: HTMLElement) {\n getAllEntityWrappers(root).forEach(element => {\n element.removeAttribute('contentEditable');\n\n this.triggerEvent(editor, element, 'replaceTemporaryContent');\n });\n }\n\n private triggerEvent(\n editor: IEditor,\n wrapper: HTMLElement,\n operation: EntityOperation,\n rawEvent?: Event,\n state?: string\n ) {\n const format = parseEntityFormat(wrapper);\n\n return format.id && format.entityType && !format.isFakeEntity\n ? editor.triggerEvent('entityOperation', {\n operation: operation,\n rawEvent,\n entity: {\n id: format.id,\n type: format.entityType,\n isReadonly: !!format.isReadonly,\n wrapper,\n },\n state: operation == 'updateEntityState' ? state : undefined,\n shouldPersist: operation == 'newEntity' ? true : undefined, // By default, we always persist entity now\n })\n : null;\n }\n\n private ensureUniqueId(type: string, id: string, wrapper: HTMLElement): string {\n const match = ENTITY_ID_REGEX.exec(id);\n const baseId = (match ? id.substr(0, id.length - match[0].length) : id) || type;\n\n // Make sure entity id is unique\n let newId = '';\n\n for (let num = (match && parseInt(match[1])) || 0; ; num++) {\n newId = num > 0 ? `${baseId}_${num}` : baseId;\n\n const item = this.state.entityMap[newId];\n\n if (!item || item.element == wrapper) {\n break;\n }\n }\n\n return newId;\n }\n}\n\n/**\n * @internal\n * Create a new instance of EntityPlugin.\n */\nexport function createEntityPlugin(): PluginWithState<EntityPluginState> {\n return new EntityPlugin();\n}\n"]}
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Editor = void 0;
4
4
  var tslib_1 = require("tslib");
5
5
  var createEditorCore_1 = require("./core/createEditorCore");
6
+ var devtoolsHook_1 = require("../utils/devtoolsHook");
6
7
  var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
7
8
  /**
8
9
  * The main editor class based on Content Model
@@ -26,7 +27,7 @@ var Editor = /** @class */ (function () {
26
27
  if (_this.isDarkMode()) {
27
28
  var colorHandler = _this.getColorManager();
28
29
  (0, roosterjs_content_model_dom_1.transformColor)(result, true /*includeSelf*/, 'darkToLight', colorHandler, {
29
- tableBorders: _this.isExperimentalFeatureEnabled('TransformTableBorderColors'),
30
+ tableBorders: true,
30
31
  });
31
32
  result.style.color = result.style.color || 'inherit';
32
33
  result.style.backgroundColor = result.style.backgroundColor || 'inherit';
@@ -37,6 +38,7 @@ var Editor = /** @class */ (function () {
37
38
  var initialModel = (_a = options.initialModel) !== null && _a !== void 0 ? _a : (0, roosterjs_content_model_dom_1.createEmptyModel)(this.core.format.defaultFormat);
38
39
  this.core.api.setContentModel(this.core, initialModel, { ignoreSelection: true }, undefined /*onNodeCreated*/, true /*isInitializing*/);
39
40
  this.core.plugins.forEach(function (plugin) { return plugin.initialize(_this); });
41
+ (0, devtoolsHook_1.notifyDevToolsEditorCreated)(this, this.core);
40
42
  }
41
43
  /**
42
44
  * Dispose this editor, dispose all plugins and custom data
@@ -44,6 +46,7 @@ var Editor = /** @class */ (function () {
44
46
  Editor.prototype.dispose = function () {
45
47
  var _a;
46
48
  var core = this.getCore();
49
+ (0, devtoolsHook_1.notifyDevToolsEditorDisposed)(this, core);
47
50
  for (var i = core.plugins.length - 1; i >= 0; i--) {
48
51
  var plugin = core.plugins[i];
49
52
  try {
@@ -228,7 +231,7 @@ var Editor = /** @class */ (function () {
228
231
  var core = this.getCore();
229
232
  if (!!isDarkMode != core.lifecycle.isDarkMode) {
230
233
  (0, roosterjs_content_model_dom_1.transformColor)(core.physicalRoot, false /*includeSelf*/, isDarkMode ? 'lightToDark' : 'darkToLight', core.darkColorHandler, {
231
- tableBorders: this.isExperimentalFeatureEnabled('TransformTableBorderColors'),
234
+ tableBorders: true,
232
235
  }, core.format.defaultFormat.textColor);
233
236
  core.lifecycle.isDarkMode = !!isDarkMode;
234
237
  core.api.triggerEvent(core, {
@@ -1 +1 @@
1
- {"version":3,"file":"Editor.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-core/lib/editor/Editor.ts"],"names":[],"mappings":";;;;AAAA,4DAA2D;AAC3D,2EAOqC;AA6BrC;;GAEG;AACH;IAGI;;;;OAIG;IACH,gBAAY,UAA0B,EAAE,OAA2B;QAAnE,iBAcC;QAduC,wBAAA,EAAA,YAA2B;;QAP3D,SAAI,GAAsB,IAAI,CAAC;QA+Z/B,wBAAmB,GAAyB,UAAC,IAAI,EAAE,IAAI;YAC3D,IAAI,IAAI,IAAI,OAAO,EAAE;gBACjB,OAAO,SAAS,CAAC;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,OAAO,EAAE,YAAY,CAAC,CAAC;IAC9D,CAAC;IAED;;;OAGG;IACH,yBAAQ,GAAR,UAAS,YAA0B;QAC/B,IAAM,IAAI,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;QAE5B,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;IAC1C,CAAC;IAED;;;OAGG;IACH,6CAA4B,GAA5B,UAA6B,WAAyC;QAClE,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC,oBAAoB,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IACzE,CAAC;IAED;;;SAGK;IACL,wCAAuB,GAAvB;QACI,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC,oBAA6C,CAAC;IACxE,CAAC;IAED;;;OAGG;IACO,wBAAO,GAAjB;QACI,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;YACZ,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;SACjD;QACD,OAAO,IAAI,CAAC,IAAI,CAAC;IACrB,CAAC;IAsBL,aAAC;AAAD,CAAC,AApbD,IAobC;AApbY,wBAAM","sourcesContent":["import { createEditorCore } from './core/createEditorCore';\nimport {\n createEmptyModel,\n ChangeSource,\n cloneModel,\n transformColor,\n createDomToModelContextWithConfig,\n domToContentModel,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelDocument,\n ContentModelFormatter,\n ContentModelSegmentFormat,\n DarkColorHandler,\n DOMEventRecord,\n DOMHelper,\n DOMSelection,\n EditorEnvironment,\n FormatContentModelOptions,\n IEditor,\n PluginEventData,\n PluginEventFromType,\n PluginEventType,\n Snapshot,\n SnapshotsManager,\n EditorCore,\n EditorOptions,\n Rect,\n EntityState,\n CachedElementHandler,\n DomToModelOptionForCreateModel,\n AnnounceData,\n ExperimentalFeature,\n LegacyTrustedHTMLHandler,\n DOMCreator,\n} from 'roosterjs-content-model-types';\n\n/**\n * The main editor class based on Content Model\n */\nexport class Editor implements IEditor {\n private core: EditorCore | null = null;\n\n /**\n * Creates an instance of Editor\n * @param contentDiv The DIV HTML element which will be the container element of editor\n * @param options An optional options object to customize the editor\n */\n constructor(contentDiv: HTMLDivElement, options: EditorOptions = {}) {\n this.core = createEditorCore(contentDiv, options);\n\n const initialModel =\n options.initialModel ?? createEmptyModel(this.core.format.defaultFormat);\n\n this.core.api.setContentModel(\n this.core,\n initialModel,\n { ignoreSelection: true },\n undefined /*onNodeCreated*/,\n true /*isInitializing*/\n );\n this.core.plugins.forEach(plugin => plugin.initialize(this));\n }\n\n /**\n * Dispose this editor, dispose all plugins and custom data\n */\n dispose() {\n const core = this.getCore();\n\n for (let i = core.plugins.length - 1; i >= 0; i--) {\n const plugin = core.plugins[i];\n\n try {\n plugin.dispose();\n } catch (e) {\n // Cache the error and pass it out, then keep going since dispose should always succeed\n core.disposeErrorHandler?.(plugin, e as Error);\n }\n }\n\n core.darkColorHandler.reset();\n\n this.core = null;\n }\n\n /**\n * Get whether this editor is disposed\n * @returns True if editor is disposed, otherwise false\n */\n isDisposed(): boolean {\n return !this.core;\n }\n\n /**\n * Create Content Model from DOM tree in this editor\n * @param mode What kind of Content Model we want. Currently we support the following values:\n * - disconnected: Returns a disconnected clone of Content Model from editor which you can do any change on it and it won't impact the editor content.\n * If there is any entity in editor, the returned object will contain cloned copy of entity wrapper element.\n * If editor is in dark mode, the cloned entity will be converted back to light mode.\n * - clean: Similar with disconnected, this will return a disconnected model, the difference is \"clean\" mode will not include any selection info.\n * This is usually used for exporting content\n */\n getContentModelCopy(mode: 'connected' | 'disconnected' | 'clean'): ContentModelDocument {\n const core = this.getCore();\n\n switch (mode) {\n case 'connected': // Get a connected model is deprecated. Now we will always return disconnected model\n case 'disconnected':\n return cloneModel(\n core.api.createContentModel(core, {\n tryGetFromCache: false,\n }),\n {\n includeCachedElement: this.cloneOptionCallback,\n }\n );\n\n case 'clean':\n const domToModelContext = createDomToModelContextWithConfig(\n core.environment.domToModelSettings.calculated,\n core.api.createEditorContext(core, false /*saveIndex*/)\n );\n\n return cloneModel(domToContentModel(core.physicalRoot, domToModelContext), {\n includeCachedElement: this.cloneOptionCallback,\n });\n }\n }\n\n /**\n * Get current running environment, such as if editor is running on Mac\n */\n getEnvironment(): EditorEnvironment {\n return this.getCore().environment;\n }\n\n /**\n * Get current DOM selection\n */\n getDOMSelection(): DOMSelection | null {\n const core = this.getCore();\n\n return core.api.getDOMSelection(core);\n }\n\n /**\n * Set DOMSelection into editor content.\n * @param selection The selection to set\n */\n setDOMSelection(selection: DOMSelection | null) {\n const core = this.getCore();\n\n core.api.setDOMSelection(core, selection);\n }\n\n /**\n * Set a new logical root (most likely due to focus change)\n * @param logicalRoot The new logical root (has to be child of physicalRoot)\n */\n setLogicalRoot(logicalRoot: HTMLDivElement) {\n const core = this.getCore();\n\n core.api.setLogicalRoot(core, logicalRoot);\n }\n\n /**\n * The general API to do format change with Content Model\n * It will grab a Content Model for current editor content, and invoke a callback function\n * to do format change. Then according to the return value, write back the modified content model into editor.\n * If there is cached model, it will be used and updated.\n * @param formatter Formatter function, see ContentModelFormatter\n * @param options More options, see FormatContentModelOptions\n */\n formatContentModel(\n formatter: ContentModelFormatter,\n options?: FormatContentModelOptions,\n domToModelOptions?: DomToModelOptionForCreateModel\n ): void {\n const core = this.getCore();\n\n core.api.formatContentModel(core, formatter, options, domToModelOptions);\n }\n\n /**\n * Get pending format of editor if any, or return null\n */\n getPendingFormat(): ContentModelSegmentFormat | null {\n return this.getCore().format.pendingFormat?.format ?? null;\n }\n\n /**\n * Get a DOM Helper object to help access DOM tree in editor\n */\n getDOMHelper(): DOMHelper {\n return this.getCore().domHelper;\n }\n\n /**\n * Add a single undo snapshot to undo stack\n * @param entityState @optional State for entity if we want to add entity state for this snapshot\n */\n takeSnapshot(entityState?: EntityState): Snapshot | null {\n const core = this.getCore();\n\n return core.api.addUndoSnapshot(\n core,\n false /*canUndoByBackspace*/,\n entityState ? [entityState] : undefined\n );\n }\n\n /**\n * Restore an undo snapshot into editor\n * @param snapshot The snapshot to restore\n */\n restoreSnapshot(snapshot: Snapshot): void {\n const core = this.getCore();\n\n core.api.restoreUndoSnapshot(core, snapshot);\n }\n\n /**\n * Get document which contains this editor\n * @returns The HTML document which contains this editor\n */\n getDocument(): Document {\n return this.getCore().environment.document;\n }\n\n /**\n * Focus to this editor, the selection was restored to where it was before, no unexpected scroll.\n */\n focus() {\n const core = this.getCore();\n core.api.focus(core);\n }\n\n /**\n * Check if focus is in editor now\n * @returns true if focus is in editor, otherwise false\n */\n hasFocus(): boolean {\n const core = this.getCore();\n return core.domHelper.hasFocus();\n }\n\n /**\n * Trigger an event to be dispatched to all plugins\n * @param eventType Type of the event\n * @param data data of the event with given type, this is the rest part of PluginEvent with the given type\n * @param broadcast indicates if the event needs to be dispatched to all plugins\n * True means to all, false means to allow exclusive handling from one plugin unless no one wants that\n * @returns the event object which is really passed into plugins. Some plugin may modify the event object so\n * the result of this function provides a chance to read the modified result\n */\n triggerEvent<T extends PluginEventType>(\n eventType: T,\n data: PluginEventData<T>,\n broadcast: boolean = false\n ): PluginEventFromType<T> {\n const core = this.getCore();\n const event = ({\n eventType,\n ...data,\n } as any) as PluginEventFromType<T>;\n core.api.triggerEvent(core, event, broadcast);\n\n return event;\n }\n\n /**\n * Attach a DOM event to the editor content DIV\n * @param eventMap A map from event name to its handler\n */\n attachDomEvent(eventMap: Record<string, DOMEventRecord>): () => void {\n const core = this.getCore();\n return core.api.attachDomEvent(core, eventMap);\n }\n\n /**\n * Get undo snapshots manager\n */\n getSnapshotsManager(): SnapshotsManager {\n const core = this.getCore();\n\n return core.undo.snapshotsManager;\n }\n\n /**\n * Check if the editor is in dark mode\n * @returns True if the editor is in dark mode, otherwise false\n */\n isDarkMode(): boolean {\n return this.getCore().lifecycle.isDarkMode;\n }\n\n /**\n * Set the dark mode state and transforms the content to match the new state.\n * @param isDarkMode The next status of dark mode. True if the editor should be in dark mode, false if not.\n */\n setDarkModeState(isDarkMode?: boolean) {\n const core = this.getCore();\n\n if (!!isDarkMode != core.lifecycle.isDarkMode) {\n transformColor(\n core.physicalRoot,\n false /*includeSelf*/,\n isDarkMode ? 'lightToDark' : 'darkToLight',\n core.darkColorHandler,\n {\n tableBorders: this.isExperimentalFeatureEnabled('TransformTableBorderColors'),\n },\n core.format.defaultFormat.textColor\n );\n\n core.lifecycle.isDarkMode = !!isDarkMode;\n\n core.api.triggerEvent(\n core,\n {\n eventType: 'contentChanged',\n source: isDarkMode\n ? ChangeSource.SwitchToDarkMode\n : ChangeSource.SwitchToLightMode,\n skipUndo: true,\n },\n true\n );\n }\n }\n\n /**\n * Check if editor is in Shadow Edit mode\n */\n isInShadowEdit() {\n return !!this.getCore().lifecycle.shadowEditFragment;\n }\n\n /**\n * Make the editor in \"Shadow Edit\" mode.\n * In Shadow Edit mode, all format change will finally be ignored.\n * This can be used for building a live preview feature for format button, to allow user\n * see format result without really apply it.\n * This function can be called repeated. If editor is already in shadow edit mode, we can still\n * use this function to do more shadow edit operation.\n */\n startShadowEdit() {\n const core = this.getCore();\n core.api.switchShadowEdit(core, true /*isOn*/);\n }\n\n /**\n * Leave \"Shadow Edit\" mode, all changes made during shadow edit will be discarded\n */\n stopShadowEdit() {\n const core = this.getCore();\n core.api.switchShadowEdit(core, false /*isOn*/);\n }\n\n /**\n * Get a color manager object for this editor.\n */\n getColorManager(): DarkColorHandler {\n return this.getCore().darkColorHandler;\n }\n\n /**\n * @deprecated\n * Get a function to convert HTML string to trusted HTML string.\n * By default it will just return the input HTML directly. To override this behavior,\n * pass your own trusted HTML handler to EditorOptions.trustedHTMLHandler\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/trusted-types\n */\n getTrustedHTMLHandler(): LegacyTrustedHTMLHandler {\n return this.getCore().trustedHTMLHandler;\n }\n\n /**\n * Get a function to convert HTML string to a trust Document.\n * By default it will just convert the original HTML string into a Document object directly.\n * To override, pass your own trusted HTML handler to EditorOptions.trustedHTMLHandler\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/trusted-types\n */\n getDOMCreator(): DOMCreator {\n return this.getCore().domCreator;\n }\n\n /**\n * Get the scroll container of the editor\n */\n getScrollContainer(): HTMLElement {\n return this.getCore().domEvent.scrollContainer;\n }\n\n /**\n * Retrieves the rect of the visible viewport of the editor.\n */\n getVisibleViewport(): Rect | null {\n return this.getCore().api.getVisibleViewport(this.getCore());\n }\n\n /**\n * Add CSS rules for editor\n * @param key A string to identify the CSS rule type. When set CSS rules with the same key again, existing rules with the same key will be replaced.\n * @param cssRule The CSS rule string, must be a valid CSS rule string, or browser may throw exception. Pass null to clear existing rules\n * @param subSelectors @optional If the rule is used for child element under editor, use this parameter to specify the child elements. Each item will be\n * combined with root selector together to build a separate rule.\n */\n setEditorStyle(\n key: string,\n cssRule: string | null,\n subSelectors?: 'before' | 'after' | string[]\n ): void {\n const core = this.getCore();\n\n core.api.setEditorStyle(core, key, cssRule, subSelectors);\n }\n\n /**\n * Announce the given data\n * @param announceData Data to announce\n */\n announce(announceData: AnnounceData): void {\n const core = this.getCore();\n\n core.api.announce(core, announceData);\n }\n\n /**\n * Check if a given feature is enabled\n * @param featureName The name of feature to check\n */\n isExperimentalFeatureEnabled(featureName: ExperimentalFeature | string): boolean {\n return this.getCore().experimentalFeatures.indexOf(featureName) >= 0;\n }\n\n /**\n * Get all experimental features enabled in this editor\n * @returns An array of experimental feature names\n * */\n getExperimentalFeatures(): ExperimentalFeature[] {\n return this.getCore().experimentalFeatures as ExperimentalFeature[];\n }\n\n /**\n * @returns the current EditorCore object\n * @throws a standard Error if there's no core object\n */\n protected getCore(): EditorCore {\n if (!this.core) {\n throw new Error('Editor is already disposed');\n }\n return this.core;\n }\n\n private cloneOptionCallback: CachedElementHandler = (node, type) => {\n if (type == 'cache') {\n return undefined;\n }\n\n const result = node.cloneNode(true /*deep*/) as HTMLElement;\n\n if (this.isDarkMode()) {\n const colorHandler = this.getColorManager();\n\n transformColor(result, true /*includeSelf*/, 'darkToLight', colorHandler, {\n tableBorders: this.isExperimentalFeatureEnabled('TransformTableBorderColors'),\n });\n\n result.style.color = result.style.color || 'inherit';\n result.style.backgroundColor = result.style.backgroundColor || 'inherit';\n }\n\n return result;\n };\n}\n"]}
1
+ {"version":3,"file":"Editor.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-core/lib/editor/Editor.ts"],"names":[],"mappings":";;;;AAAA,4DAA2D;AAC3D,sDAAkG;AAClG,2EAOqC;AA6BrC;;GAEG;AACH;IAGI;;;;OAIG;IACH,gBAAY,UAA0B,EAAE,OAA2B;QAAnE,iBAgBC;QAhBuC,wBAAA,EAAA,YAA2B;;QAP3D,SAAI,GAAsB,IAAI,CAAC;QAma/B,wBAAmB,GAAyB,UAAC,IAAI,EAAE,IAAI;YAC3D,IAAI,IAAI,IAAI,OAAO,EAAE;gBACjB,OAAO,SAAS,CAAC;aACpB;YAED,IAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAgB,CAAC;YAE5D,IAAI,KAAI,CAAC,UAAU,EAAE,EAAE;gBACnB,IAAM,YAAY,GAAG,KAAI,CAAC,eAAe,EAAE,CAAC;gBAE5C,IAAA,4CAAc,EAAC,MAAM,EAAE,IAAI,CAAC,eAAe,EAAE,aAAa,EAAE,YAAY,EAAE;oBACtE,YAAY,EAAE,IAAI;iBACrB,CAAC,CAAC;gBAEH,MAAM,CAAC,KAAK,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,IAAI,SAAS,CAAC;gBACrD,MAAM,CAAC,KAAK,CAAC,eAAe,GAAG,MAAM,CAAC,KAAK,CAAC,eAAe,IAAI,SAAS,CAAC;aAC5E;YAED,OAAO,MAAM,CAAC;QAClB,CAAC,CAAC;QA9aE,IAAI,CAAC,IAAI,GAAG,IAAA,mCAAgB,EAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QAElD,IAAM,YAAY,GACd,MAAA,OAAO,CAAC,YAA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;SACjD;QACD,OAAO,IAAI,CAAC,IAAI,CAAC;IACrB,CAAC;IAsBL,aAAC;AAAD,CAAC,AAxbD,IAwbC;AAxbY,wBAAM","sourcesContent":["import { createEditorCore } from './core/createEditorCore';\nimport { notifyDevToolsEditorCreated, notifyDevToolsEditorDisposed } from '../utils/devtoolsHook';\nimport {\n createEmptyModel,\n ChangeSource,\n cloneModel,\n transformColor,\n createDomToModelContextWithConfig,\n domToContentModel,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelDocument,\n ContentModelFormatter,\n ContentModelSegmentFormat,\n DarkColorHandler,\n DOMEventRecord,\n DOMHelper,\n DOMSelection,\n EditorEnvironment,\n FormatContentModelOptions,\n IEditor,\n PluginEventData,\n PluginEventFromType,\n PluginEventType,\n Snapshot,\n SnapshotsManager,\n EditorCore,\n EditorOptions,\n Rect,\n EntityState,\n CachedElementHandler,\n DomToModelOptionForCreateModel,\n AnnounceData,\n ExperimentalFeature,\n LegacyTrustedHTMLHandler,\n DOMCreator,\n} from 'roosterjs-content-model-types';\n\n/**\n * The main editor class based on Content Model\n */\nexport class Editor implements IEditor {\n private core: EditorCore | null = null;\n\n /**\n * Creates an instance of Editor\n * @param contentDiv The DIV HTML element which will be the container element of editor\n * @param options An optional options object to customize the editor\n */\n constructor(contentDiv: HTMLDivElement, options: EditorOptions = {}) {\n this.core = createEditorCore(contentDiv, options);\n\n const initialModel =\n options.initialModel ?? createEmptyModel(this.core.format.defaultFormat);\n\n this.core.api.setContentModel(\n this.core,\n initialModel,\n { ignoreSelection: true },\n undefined /*onNodeCreated*/,\n true /*isInitializing*/\n );\n this.core.plugins.forEach(plugin => plugin.initialize(this));\n\n notifyDevToolsEditorCreated(this, this.core);\n }\n\n /**\n * Dispose this editor, dispose all plugins and custom data\n */\n dispose() {\n const core = this.getCore();\n\n notifyDevToolsEditorDisposed(this, core);\n\n for (let i = core.plugins.length - 1; i >= 0; i--) {\n const plugin = core.plugins[i];\n\n try {\n plugin.dispose();\n } catch (e) {\n // Cache the error and pass it out, then keep going since dispose should always succeed\n core.disposeErrorHandler?.(plugin, e as Error);\n }\n }\n\n core.darkColorHandler.reset();\n\n this.core = null;\n }\n\n /**\n * Get whether this editor is disposed\n * @returns True if editor is disposed, otherwise false\n */\n isDisposed(): boolean {\n return !this.core;\n }\n\n /**\n * Create Content Model from DOM tree in this editor\n * @param mode What kind of Content Model we want. Currently we support the following values:\n * - disconnected: Returns a disconnected clone of Content Model from editor which you can do any change on it and it won't impact the editor content.\n * If there is any entity in editor, the returned object will contain cloned copy of entity wrapper element.\n * If editor is in dark mode, the cloned entity will be converted back to light mode.\n * - clean: Similar with disconnected, this will return a disconnected model, the difference is \"clean\" mode will not include any selection info.\n * This is usually used for exporting content\n */\n getContentModelCopy(mode: 'connected' | 'disconnected' | 'clean'): ContentModelDocument {\n const core = this.getCore();\n\n switch (mode) {\n case 'connected': // Get a connected model is deprecated. Now we will always return disconnected model\n case 'disconnected':\n return cloneModel(\n core.api.createContentModel(core, {\n tryGetFromCache: false,\n }),\n {\n includeCachedElement: this.cloneOptionCallback,\n }\n );\n\n case 'clean':\n const domToModelContext = createDomToModelContextWithConfig(\n core.environment.domToModelSettings.calculated,\n core.api.createEditorContext(core, false /*saveIndex*/)\n );\n\n return cloneModel(domToContentModel(core.physicalRoot, domToModelContext), {\n includeCachedElement: this.cloneOptionCallback,\n });\n }\n }\n\n /**\n * Get current running environment, such as if editor is running on Mac\n */\n getEnvironment(): EditorEnvironment {\n return this.getCore().environment;\n }\n\n /**\n * Get current DOM selection\n */\n getDOMSelection(): DOMSelection | null {\n const core = this.getCore();\n\n return core.api.getDOMSelection(core);\n }\n\n /**\n * Set DOMSelection into editor content.\n * @param selection The selection to set\n */\n setDOMSelection(selection: DOMSelection | null) {\n const core = this.getCore();\n\n core.api.setDOMSelection(core, selection);\n }\n\n /**\n * Set a new logical root (most likely due to focus change)\n * @param logicalRoot The new logical root (has to be child of physicalRoot)\n */\n setLogicalRoot(logicalRoot: HTMLDivElement) {\n const core = this.getCore();\n\n core.api.setLogicalRoot(core, logicalRoot);\n }\n\n /**\n * The general API to do format change with Content Model\n * It will grab a Content Model for current editor content, and invoke a callback function\n * to do format change. Then according to the return value, write back the modified content model into editor.\n * If there is cached model, it will be used and updated.\n * @param formatter Formatter function, see ContentModelFormatter\n * @param options More options, see FormatContentModelOptions\n */\n formatContentModel(\n formatter: ContentModelFormatter,\n options?: FormatContentModelOptions,\n domToModelOptions?: DomToModelOptionForCreateModel\n ): void {\n const core = this.getCore();\n\n core.api.formatContentModel(core, formatter, options, domToModelOptions);\n }\n\n /**\n * Get pending format of editor if any, or return null\n */\n getPendingFormat(): ContentModelSegmentFormat | null {\n return this.getCore().format.pendingFormat?.format ?? null;\n }\n\n /**\n * Get a DOM Helper object to help access DOM tree in editor\n */\n getDOMHelper(): DOMHelper {\n return this.getCore().domHelper;\n }\n\n /**\n * Add a single undo snapshot to undo stack\n * @param entityState @optional State for entity if we want to add entity state for this snapshot\n */\n takeSnapshot(entityState?: EntityState): Snapshot | null {\n const core = this.getCore();\n\n return core.api.addUndoSnapshot(\n core,\n false /*canUndoByBackspace*/,\n entityState ? [entityState] : undefined\n );\n }\n\n /**\n * Restore an undo snapshot into editor\n * @param snapshot The snapshot to restore\n */\n restoreSnapshot(snapshot: Snapshot): void {\n const core = this.getCore();\n\n core.api.restoreUndoSnapshot(core, snapshot);\n }\n\n /**\n * Get document which contains this editor\n * @returns The HTML document which contains this editor\n */\n getDocument(): Document {\n return this.getCore().environment.document;\n }\n\n /**\n * Focus to this editor, the selection was restored to where it was before, no unexpected scroll.\n */\n focus() {\n const core = this.getCore();\n core.api.focus(core);\n }\n\n /**\n * Check if focus is in editor now\n * @returns true if focus is in editor, otherwise false\n */\n hasFocus(): boolean {\n const core = this.getCore();\n return core.domHelper.hasFocus();\n }\n\n /**\n * Trigger an event to be dispatched to all plugins\n * @param eventType Type of the event\n * @param data data of the event with given type, this is the rest part of PluginEvent with the given type\n * @param broadcast indicates if the event needs to be dispatched to all plugins\n * True means to all, false means to allow exclusive handling from one plugin unless no one wants that\n * @returns the event object which is really passed into plugins. Some plugin may modify the event object so\n * the result of this function provides a chance to read the modified result\n */\n triggerEvent<T extends PluginEventType>(\n eventType: T,\n data: PluginEventData<T>,\n broadcast: boolean = false\n ): PluginEventFromType<T> {\n const core = this.getCore();\n const event = ({\n eventType,\n ...data,\n } as any) as PluginEventFromType<T>;\n core.api.triggerEvent(core, event, broadcast);\n\n return event;\n }\n\n /**\n * Attach a DOM event to the editor content DIV\n * @param eventMap A map from event name to its handler\n */\n attachDomEvent(eventMap: Record<string, DOMEventRecord>): () => void {\n const core = this.getCore();\n return core.api.attachDomEvent(core, eventMap);\n }\n\n /**\n * Get undo snapshots manager\n */\n getSnapshotsManager(): SnapshotsManager {\n const core = this.getCore();\n\n return core.undo.snapshotsManager;\n }\n\n /**\n * Check if the editor is in dark mode\n * @returns True if the editor is in dark mode, otherwise false\n */\n isDarkMode(): boolean {\n return this.getCore().lifecycle.isDarkMode;\n }\n\n /**\n * Set the dark mode state and transforms the content to match the new state.\n * @param isDarkMode The next status of dark mode. True if the editor should be in dark mode, false if not.\n */\n setDarkModeState(isDarkMode?: boolean) {\n const core = this.getCore();\n\n if (!!isDarkMode != core.lifecycle.isDarkMode) {\n transformColor(\n core.physicalRoot,\n false /*includeSelf*/,\n isDarkMode ? 'lightToDark' : 'darkToLight',\n core.darkColorHandler,\n {\n tableBorders: true,\n },\n core.format.defaultFormat.textColor\n );\n\n core.lifecycle.isDarkMode = !!isDarkMode;\n\n core.api.triggerEvent(\n core,\n {\n eventType: 'contentChanged',\n source: isDarkMode\n ? ChangeSource.SwitchToDarkMode\n : ChangeSource.SwitchToLightMode,\n skipUndo: true,\n },\n true\n );\n }\n }\n\n /**\n * Check if editor is in Shadow Edit mode\n */\n isInShadowEdit() {\n return !!this.getCore().lifecycle.shadowEditFragment;\n }\n\n /**\n * Make the editor in \"Shadow Edit\" mode.\n * In Shadow Edit mode, all format change will finally be ignored.\n * This can be used for building a live preview feature for format button, to allow user\n * see format result without really apply it.\n * This function can be called repeated. If editor is already in shadow edit mode, we can still\n * use this function to do more shadow edit operation.\n */\n startShadowEdit() {\n const core = this.getCore();\n core.api.switchShadowEdit(core, true /*isOn*/);\n }\n\n /**\n * Leave \"Shadow Edit\" mode, all changes made during shadow edit will be discarded\n */\n stopShadowEdit() {\n const core = this.getCore();\n core.api.switchShadowEdit(core, false /*isOn*/);\n }\n\n /**\n * Get a color manager object for this editor.\n */\n getColorManager(): DarkColorHandler {\n return this.getCore().darkColorHandler;\n }\n\n /**\n * @deprecated\n * Get a function to convert HTML string to trusted HTML string.\n * By default it will just return the input HTML directly. To override this behavior,\n * pass your own trusted HTML handler to EditorOptions.trustedHTMLHandler\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/trusted-types\n */\n getTrustedHTMLHandler(): LegacyTrustedHTMLHandler {\n return this.getCore().trustedHTMLHandler;\n }\n\n /**\n * Get a function to convert HTML string to a trust Document.\n * By default it will just convert the original HTML string into a Document object directly.\n * To override, pass your own trusted HTML handler to EditorOptions.trustedHTMLHandler\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/trusted-types\n */\n getDOMCreator(): DOMCreator {\n return this.getCore().domCreator;\n }\n\n /**\n * Get the scroll container of the editor\n */\n getScrollContainer(): HTMLElement {\n return this.getCore().domEvent.scrollContainer;\n }\n\n /**\n * Retrieves the rect of the visible viewport of the editor.\n */\n getVisibleViewport(): Rect | null {\n return this.getCore().api.getVisibleViewport(this.getCore());\n }\n\n /**\n * Add CSS rules for editor\n * @param key A string to identify the CSS rule type. When set CSS rules with the same key again, existing rules with the same key will be replaced.\n * @param cssRule The CSS rule string, must be a valid CSS rule string, or browser may throw exception. Pass null to clear existing rules\n * @param subSelectors @optional If the rule is used for child element under editor, use this parameter to specify the child elements. Each item will be\n * combined with root selector together to build a separate rule.\n */\n setEditorStyle(\n key: string,\n cssRule: string | null,\n subSelectors?: 'before' | 'after' | string[]\n ): void {\n const core = this.getCore();\n\n core.api.setEditorStyle(core, key, cssRule, subSelectors);\n }\n\n /**\n * Announce the given data\n * @param announceData Data to announce\n */\n announce(announceData: AnnounceData): void {\n const core = this.getCore();\n\n core.api.announce(core, announceData);\n }\n\n /**\n * Check if a given feature is enabled\n * @param featureName The name of feature to check\n */\n isExperimentalFeatureEnabled(featureName: ExperimentalFeature | string): boolean {\n return this.getCore().experimentalFeatures.indexOf(featureName) >= 0;\n }\n\n /**\n * Get all experimental features enabled in this editor\n * @returns An array of experimental feature names\n * */\n getExperimentalFeatures(): ExperimentalFeature[] {\n return this.getCore().experimentalFeatures as ExperimentalFeature[];\n }\n\n /**\n * @returns the current EditorCore object\n * @throws a standard Error if there's no core object\n */\n protected getCore(): EditorCore {\n if (!this.core) {\n throw new Error('Editor is already disposed');\n }\n return this.core;\n }\n\n private cloneOptionCallback: CachedElementHandler = (node, type) => {\n if (type == 'cache') {\n return undefined;\n }\n\n const result = node.cloneNode(true /*deep*/) as HTMLElement;\n\n if (this.isDarkMode()) {\n const colorHandler = this.getColorManager();\n\n transformColor(result, true /*includeSelf*/, 'darkToLight', colorHandler, {\n tableBorders: true,\n });\n\n result.style.color = result.style.color || 'inherit';\n result.style.backgroundColor = result.style.backgroundColor || 'inherit';\n }\n\n return result;\n };\n}\n"]}
@@ -37,10 +37,11 @@ function createEditorCore(contentDiv, options) {
37
37
  }
38
38
  exports.createEditorCore = createEditorCore;
39
39
  function createEditorEnvironment(contentDiv, options) {
40
- var _a, _b, _c;
41
- var navigator = (_a = contentDiv.ownerDocument.defaultView) === null || _a === void 0 ? void 0 : _a.navigator;
42
- var userAgent = (_b = navigator === null || navigator === void 0 ? void 0 : navigator.userAgent) !== null && _b !== void 0 ? _b : '';
43
- var appVersion = (_c = navigator === null || navigator === void 0 ? void 0 : navigator.appVersion) !== null && _c !== void 0 ? _c : '';
40
+ var _a, _b;
41
+ var defaultView = contentDiv.ownerDocument.defaultView;
42
+ var navigator = defaultView === null || defaultView === void 0 ? void 0 : defaultView.navigator;
43
+ var userAgent = (_a = navigator === null || navigator === void 0 ? void 0 : navigator.userAgent) !== null && _a !== void 0 ? _a : '';
44
+ var appVersion = (_b = navigator === null || navigator === void 0 ? void 0 : navigator.appVersion) !== null && _b !== void 0 ? _b : '';
44
45
  return {
45
46
  document: contentDiv.ownerDocument,
46
47
  domToModelSettings: (0, createEditorDefaultSettings_1.createDomToModelSettings)(options),
@@ -52,6 +53,7 @@ function createEditorEnvironment(contentDiv, options) {
52
53
  userAgent.indexOf('Chrome') < 0 &&
53
54
  userAgent.indexOf('Android') < 0,
54
55
  isMobileOrTablet: getIsMobileOrTablet(userAgent),
56
+ isTouchSupported: !!defaultView && ('ontouchstart' in defaultView || !!(navigator === null || navigator === void 0 ? void 0 : navigator.maxTouchPoints)),
55
57
  };
56
58
  }
57
59
  function getIsMobileOrTablet(userAgent) {
@@ -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;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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 useShadowDom:\n !!options.experimentalFeatures &&\n options.experimentalFeatures.indexOf('ShadowDom') >= 0,\n }),\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"]}
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,SAAg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AC;QAChD,gBAAgB,EACZ,CAAC,CAAC,WAAW,IAAI,CAAC,cAAc,IAAI,WAAW,IAAI,CAAC,CAAC,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,cAAc,CAAA,CAAC;KACtF,CAAC;AACN,CAAC;AAED,SAAS,mBAAmB,CAAC,SAAiB;IAC1C,8CAA8C;IAC9C,4DAA4D;IAC5D,6GAA6G;IAC7G,IACI,qVAAqV,CAAC,IAAI,CACtV,SAAS,CACZ;QACD,ykDAAykD,CAAC,IAAI,CAC1kD,SAAS,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAC5B,EACH;QACE,OAAO,IAAI,CAAC;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 useShadowDom:\n !!options.experimentalFeatures &&\n options.experimentalFeatures.indexOf('ShadowDom') >= 0,\n }),\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 defaultView = contentDiv.ownerDocument.defaultView;\n const navigator = 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 isTouchSupported:\n !!defaultView && ('ontouchstart' in defaultView || !!navigator?.maxTouchPoints),\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/lib/index.d.ts CHANGED
@@ -5,3 +5,4 @@ export { undo } from './command/undo/undo';
5
5
  export { redo } from './command/redo/redo';
6
6
  export { paste } from './command/paste/paste';
7
7
  export { getContentForCopy } from './command/cutCopy/getContentForCopy';
8
+ export { RoosterJsDevToolsHookVersion } from './utils/devtoolsHook';
package/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getContentForCopy = exports.paste = exports.redo = exports.undo = exports.exportContent = exports.createModelFromHtml = exports.Editor = void 0;
3
+ exports.RoosterJsDevToolsHookVersion = exports.getContentForCopy = exports.paste = exports.redo = exports.undo = exports.exportContent = exports.createModelFromHtml = exports.Editor = void 0;
4
4
  // Editor
5
5
  var Editor_1 = require("./editor/Editor");
6
6
  Object.defineProperty(exports, "Editor", { enumerable: true, get: function () { return Editor_1.Editor; } });
@@ -15,7 +15,10 @@ var redo_1 = require("./command/redo/redo");
15
15
  Object.defineProperty(exports, "redo", { enumerable: true, get: function () { return redo_1.redo; } });
16
16
  var paste_1 = require("./command/paste/paste");
17
17
  Object.defineProperty(exports, "paste", { enumerable: true, get: function () { return paste_1.paste; } });
18
- //Editor copy helper
18
+ // Editor copy helper
19
19
  var getContentForCopy_1 = require("./command/cutCopy/getContentForCopy");
20
20
  Object.defineProperty(exports, "getContentForCopy", { enumerable: true, get: function () { return getContentForCopy_1.getContentForCopy; } });
21
+ // Editor devtools
22
+ var devtoolsHook_1 = require("./utils/devtoolsHook");
23
+ Object.defineProperty(exports, "RoosterJsDevToolsHookVersion", { enumerable: true, get: function () { return devtoolsHook_1.RoosterJsDevToolsHookVersion; } });
21
24
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../packages/roosterjs-content-model-core/lib/index.ts"],"names":[],"mappings":";;;AAAA,SAAS;AACT,0CAAyC;AAAhC,gGAAA,MAAM,OAAA;AAEf,iBAAiB;AACjB,yFAAwF;AAA/E,0HAAA,mBAAmB,OAAA;AAC5B,uEAAsE;AAA7D,8GAAA,aAAa,OAAA;AACtB,4CAA2C;AAAlC,4FAAA,IAAI,OAAA;AACb,4CAA2C;AAAlC,4FAAA,IAAI,OAAA;AACb,+CAA8C;AAArC,8FAAA,KAAK,OAAA;AAEd,oBAAoB;AACpB,yEAAwE;AAA/D,sHAAA,iBAAiB,OAAA","sourcesContent":["// Editor\nexport { Editor } from './editor/Editor';\n\n// Editor command\nexport { createModelFromHtml } from './command/createModelFromHtml/createModelFromHtml';\nexport { exportContent } from './command/exportContent/exportContent';\nexport { undo } from './command/undo/undo';\nexport { redo } from './command/redo/redo';\nexport { paste } from './command/paste/paste';\n\n//Editor copy helper\nexport { getContentForCopy } from './command/cutCopy/getContentForCopy';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../packages/roosterjs-content-model-core/lib/index.ts"],"names":[],"mappings":";;;AAAA,SAAS;AACT,0CAAyC;AAAhC,gGAAA,MAAM,OAAA;AAEf,iBAAiB;AACjB,yFAAwF;AAA/E,0HAAA,mBAAmB,OAAA;AAC5B,uEAAsE;AAA7D,8GAAA,aAAa,OAAA;AACtB,4CAA2C;AAAlC,4FAAA,IAAI,OAAA;AACb,4CAA2C;AAAlC,4FAAA,IAAI,OAAA;AACb,+CAA8C;AAArC,8FAAA,KAAK,OAAA;AAEd,qBAAqB;AACrB,yEAAwE;AAA/D,sHAAA,iBAAiB,OAAA;AAE1B,kBAAkB;AAClB,qDAAoE;AAA3D,4HAAA,4BAA4B,OAAA","sourcesContent":["// Editor\nexport { Editor } from './editor/Editor';\n\n// Editor command\nexport { createModelFromHtml } from './command/createModelFromHtml/createModelFromHtml';\nexport { exportContent } from './command/exportContent/exportContent';\nexport { undo } from './command/undo/undo';\nexport { redo } from './command/redo/redo';\nexport { paste } from './command/paste/paste';\n\n// Editor copy helper\nexport { getContentForCopy } from './command/cutCopy/getContentForCopy';\n\n// Editor devtools\nexport { RoosterJsDevToolsHookVersion } from './utils/devtoolsHook';\n"]}
@@ -0,0 +1,35 @@
1
+ import type { EditorCore, IEditor, PluginEvent } from 'roosterjs-content-model-types';
2
+ /**
3
+ * The current version of the RoosterJS DevTools hook contract (see
4
+ * {@link RoosterJsDevToolsHook}). The editor stamps this onto the installed hook so a developer
5
+ * tool can adapt to the editor's capabilities. Bump this whenever the shape of the contract changes
6
+ * in a way tools may need to detect.
7
+ *
8
+ * History:
9
+ * - 1: onEditorCreated, onEditorDisposed, onPluginEvent
10
+ */
11
+ export declare const RoosterJsDevToolsHookVersion: number;
12
+ /**
13
+ * @internal
14
+ * Notify developer tools that an editor has been created. Failures are swallowed so developer
15
+ * tools can never break the editor.
16
+ * @param editor The editor that was created
17
+ * @param core The editor core, used to attribute later plugin events to this editor
18
+ */
19
+ export declare function notifyDevToolsEditorCreated(editor: IEditor, core: EditorCore): void;
20
+ /**
21
+ * @internal
22
+ * Notify developer tools that an editor is about to be disposed. Failures are swallowed so
23
+ * developer tools can never break the editor.
24
+ * @param editor The editor that is being disposed
25
+ * @param core The editor core to stop tracking
26
+ */
27
+ export declare function notifyDevToolsEditorDisposed(editor: IEditor, core: EditorCore): void;
28
+ /**
29
+ * @internal
30
+ * Forward a plugin event to developer tools, if a hook is installed. Failures are swallowed so
31
+ * developer tools can never break the editor.
32
+ * @param core The editor core that dispatched the event
33
+ * @param event The plugin event being dispatched
34
+ */
35
+ export declare function notifyDevToolsPluginEvent(core: EditorCore, event: PluginEvent): void;
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.notifyDevToolsPluginEvent = exports.notifyDevToolsEditorDisposed = exports.notifyDevToolsEditorCreated = exports.RoosterJsDevToolsHookVersion = void 0;
4
+ /**
5
+ * The current version of the RoosterJS DevTools hook contract (see
6
+ * {@link RoosterJsDevToolsHook}). The editor stamps this onto the installed hook so a developer
7
+ * tool can adapt to the editor's capabilities. Bump this whenever the shape of the contract changes
8
+ * in a way tools may need to detect.
9
+ *
10
+ * History:
11
+ * - 1: onEditorCreated, onEditorDisposed, onPluginEvent
12
+ */
13
+ exports.RoosterJsDevToolsHookVersion = 1;
14
+ // Maps an editor core back to its IEditor wrapper, so plugin events (which only carry the core)
15
+ // can be attributed to the right editor when forwarded to developer tools.
16
+ var coreToEditor = new WeakMap();
17
+ /**
18
+ * @internal
19
+ * Notify developer tools that an editor has been created. Failures are swallowed so developer
20
+ * tools can never break the editor.
21
+ * @param editor The editor that was created
22
+ * @param core The editor core, used to attribute later plugin events to this editor
23
+ */
24
+ function notifyDevToolsEditorCreated(editor, core) {
25
+ safeCall(function () {
26
+ var _a, _b;
27
+ coreToEditor.set(core, editor);
28
+ var win = editor.getDocument().defaultView;
29
+ if (win) {
30
+ var editors = (_a = win.__ROOSTERJS_DEVTOOLS_EDITORS__) !== null && _a !== void 0 ? _a : [];
31
+ editors.push(editor);
32
+ win.__ROOSTERJS_DEVTOOLS_EDITORS__ = editors;
33
+ var hook = win.__ROOSTERJS_DEVTOOLS_HOOK__;
34
+ if (hook) {
35
+ hook.version = exports.RoosterJsDevToolsHookVersion;
36
+ (_b = hook.onEditorCreated) === null || _b === void 0 ? void 0 : _b.call(hook, editor);
37
+ }
38
+ }
39
+ });
40
+ }
41
+ exports.notifyDevToolsEditorCreated = notifyDevToolsEditorCreated;
42
+ /**
43
+ * @internal
44
+ * Notify developer tools that an editor is about to be disposed. Failures are swallowed so
45
+ * developer tools can never break the editor.
46
+ * @param editor The editor that is being disposed
47
+ * @param core The editor core to stop tracking
48
+ */
49
+ function notifyDevToolsEditorDisposed(editor, core) {
50
+ safeCall(function () {
51
+ var _a, _b;
52
+ coreToEditor.delete(core);
53
+ var win = editor.getDocument().defaultView;
54
+ if (win) {
55
+ var editors = win.__ROOSTERJS_DEVTOOLS_EDITORS__;
56
+ var index = editors ? editors.indexOf(editor) : -1;
57
+ if (editors && index >= 0) {
58
+ editors.splice(index, 1);
59
+ }
60
+ (_b = (_a = win.__ROOSTERJS_DEVTOOLS_HOOK__) === null || _a === void 0 ? void 0 : _a.onEditorDisposed) === null || _b === void 0 ? void 0 : _b.call(_a, editor);
61
+ }
62
+ });
63
+ }
64
+ exports.notifyDevToolsEditorDisposed = notifyDevToolsEditorDisposed;
65
+ /**
66
+ * @internal
67
+ * Forward a plugin event to developer tools, if a hook is installed. Failures are swallowed so
68
+ * developer tools can never break the editor.
69
+ * @param core The editor core that dispatched the event
70
+ * @param event The plugin event being dispatched
71
+ */
72
+ function notifyDevToolsPluginEvent(core, event) {
73
+ safeCall(function () {
74
+ var _a, _b;
75
+ var editor = coreToEditor.get(core);
76
+ var win = editor === null || editor === void 0 ? void 0 : editor.getDocument().defaultView;
77
+ if (editor && win) {
78
+ (_b = (_a = win.__ROOSTERJS_DEVTOOLS_HOOK__) === null || _a === void 0 ? void 0 : _a.onPluginEvent) === null || _b === void 0 ? void 0 : _b.call(_a, editor, event);
79
+ }
80
+ });
81
+ }
82
+ exports.notifyDevToolsPluginEvent = notifyDevToolsPluginEvent;
83
+ function safeCall(callback) {
84
+ try {
85
+ callback();
86
+ }
87
+ catch (_a) { }
88
+ }
89
+ //# sourceMappingURL=devtoolsHook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"devtoolsHook.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-core/lib/utils/devtoolsHook.ts"],"names":[],"mappings":";;;AAOA;;;;;;;;GAQG;AACU,QAAA,4BAA4B,GAAW,CAAC,CAAC;AAetD,gGAAgG;AAChG,2EAA2E;AAC3E,IAAM,YAAY,GAAG,IAAI,OAAO,EAAuB,CAAC;AAExD;;;;;;GAMG;AACH,SAAgB,2BAA2B,CAAC,MAAe,EAAE,IAAgB;IACzE,QAAQ,CAAC;;QACL,YAAY,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAE/B,IAAM,GAAG,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC,WAAgD,CAAC;QAElF,IAAI,GAAG,EAAE;YACL,IAAM,OAAO,GAAG,MAAA,GAAG,CAAC,8BAA8B,mCAAI,EAAE,CAAC;YAEzD,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACrB,GAAG,CAAC,8BAA8B,GAAG,OAAO,CAAC;YAE7C,IAAM,IAAI,GAAG,GAAG,CAAC,2BAA2B,CAAC;YAE7C,IAAI,IAAI,EAAE;gBACN,IAAI,CAAC,OAAO,GAAG,oCAA4B,CAAC;gBAC5C,MAAA,IAAI,CAAC,eAAe,+CAApB,IAAI,EAAmB,MAAM,CAAC,CAAC;aAClC;SACJ;IACL,CAAC,CAAC,CAAC;AACP,CAAC;AApBD,kEAoBC;AAED;;;;;;GAMG;AACH,SAAgB,4BAA4B,CAAC,MAAe,EAAE,IAAgB;IAC1E,QAAQ,CAAC;;QACL,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAE1B,IAAM,GAAG,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC,WAAgD,CAAC;QAElF,IAAI,GAAG,EAAE;YACL,IAAM,OAAO,GAAG,GAAG,CAAC,8BAA8B,CAAC;YACnD,IAAM,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAErD,IAAI,OAAO,IAAI,KAAK,IAAI,CAAC,EAAE;gBACvB,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;aAC5B;YAED,MAAA,MAAA,GAAG,CAAC,2BAA2B,0CAAE,gBAAgB,mDAAG,MAAM,CAAC,CAAC;SAC/D;IACL,CAAC,CAAC,CAAC;AACP,CAAC;AAjBD,oEAiBC;AAED;;;;;;GAMG;AACH,SAAgB,yBAAyB,CAAC,IAAgB,EAAE,KAAkB;IAC1E,QAAQ,CAAC;;QACL,IAAM,MAAM,GAAG,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACtC,IAAM,GAAG,GAAG,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,WAAW,GAAG,WAAgD,CAAC;QAEnF,IAAI,MAAM,IAAI,GAAG,EAAE;YACf,MAAA,MAAA,GAAG,CAAC,2BAA2B,0CAAE,aAAa,mDAAG,MAAM,EAAE,KAAK,CAAC,CAAC;SACnE;IACL,CAAC,CAAC,CAAC;AACP,CAAC;AATD,8DASC;AAED,SAAS,QAAQ,CAAC,QAAoB;IAClC,IAAI;QACA,QAAQ,EAAE,CAAC;KACd;IAAC,WAAM,GAAE;AACd,CAAC","sourcesContent":["import type {\n EditorCore,\n IEditor,\n PluginEvent,\n RoosterJsDevToolsHook,\n} from 'roosterjs-content-model-types';\n\n/**\n * The current version of the RoosterJS DevTools hook contract (see\n * {@link RoosterJsDevToolsHook}). The editor stamps this onto the installed hook so a developer\n * tool can adapt to the editor's capabilities. Bump this whenever the shape of the contract changes\n * in a way tools may need to detect.\n *\n * History:\n * - 1: onEditorCreated, onEditorDisposed, onPluginEvent\n */\nexport const RoosterJsDevToolsHookVersion: number = 1;\n\ninterface DevToolsGlobals {\n /**\n * The hook object installed by a developer tool to receive editor notifications\n */\n __ROOSTERJS_DEVTOOLS_HOOK__?: RoosterJsDevToolsHook;\n\n /**\n * An array maintained by the library that always tracks the currently live editor instances on\n * the page, so a tool attaching after editors are created can still discover them.\n */\n __ROOSTERJS_DEVTOOLS_EDITORS__?: IEditor[];\n}\n\n// Maps an editor core back to its IEditor wrapper, so plugin events (which only carry the core)\n// can be attributed to the right editor when forwarded to developer tools.\nconst coreToEditor = new WeakMap<EditorCore, IEditor>();\n\n/**\n * @internal\n * Notify developer tools that an editor has been created. Failures are swallowed so developer\n * tools can never break the editor.\n * @param editor The editor that was created\n * @param core The editor core, used to attribute later plugin events to this editor\n */\nexport function notifyDevToolsEditorCreated(editor: IEditor, core: EditorCore) {\n safeCall(() => {\n coreToEditor.set(core, editor);\n\n const win = editor.getDocument().defaultView as (Window & DevToolsGlobals) | null;\n\n if (win) {\n const editors = win.__ROOSTERJS_DEVTOOLS_EDITORS__ ?? [];\n\n editors.push(editor);\n win.__ROOSTERJS_DEVTOOLS_EDITORS__ = editors;\n\n const hook = win.__ROOSTERJS_DEVTOOLS_HOOK__;\n\n if (hook) {\n hook.version = RoosterJsDevToolsHookVersion;\n hook.onEditorCreated?.(editor);\n }\n }\n });\n}\n\n/**\n * @internal\n * Notify developer tools that an editor is about to be disposed. Failures are swallowed so\n * developer tools can never break the editor.\n * @param editor The editor that is being disposed\n * @param core The editor core to stop tracking\n */\nexport function notifyDevToolsEditorDisposed(editor: IEditor, core: EditorCore) {\n safeCall(() => {\n coreToEditor.delete(core);\n\n const win = editor.getDocument().defaultView as (Window & DevToolsGlobals) | null;\n\n if (win) {\n const editors = win.__ROOSTERJS_DEVTOOLS_EDITORS__;\n const index = editors ? editors.indexOf(editor) : -1;\n\n if (editors && index >= 0) {\n editors.splice(index, 1);\n }\n\n win.__ROOSTERJS_DEVTOOLS_HOOK__?.onEditorDisposed?.(editor);\n }\n });\n}\n\n/**\n * @internal\n * Forward a plugin event to developer tools, if a hook is installed. Failures are swallowed so\n * developer tools can never break the editor.\n * @param core The editor core that dispatched the event\n * @param event The plugin event being dispatched\n */\nexport function notifyDevToolsPluginEvent(core: EditorCore, event: PluginEvent) {\n safeCall(() => {\n const editor = coreToEditor.get(core);\n const win = editor?.getDocument().defaultView as (Window & DevToolsGlobals) | null;\n\n if (editor && win) {\n win.__ROOSTERJS_DEVTOOLS_HOOK__?.onPluginEvent?.(editor, event);\n }\n });\n}\n\nfunction safeCall(callback: () => void) {\n try {\n callback();\n } catch {}\n}\n"]}
@@ -18,7 +18,7 @@ define(["require", "exports", "roosterjs-content-model-dom"], function (require,
18
18
  var clonedRoot = editor.getDOMHelper().getClonedRoot();
19
19
  if (editor.isDarkMode()) {
20
20
  (0, roosterjs_content_model_dom_1.transformColor)(clonedRoot, false /*includeSelf*/, 'darkToLight', editor.getColorManager(), {
21
- tableBorders: editor.isExperimentalFeatureEnabled('TransformTableBorderColors'),
21
+ tableBorders: true,
22
22
  });
23
23
  }
24
24
  return getHTMLFromDOM(editor, clonedRoot);