roosterjs-content-model-core 9.45.2 → 9.46.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 (67) hide show
  1. package/lib/command/cutCopy/getContentForCopy.js +4 -15
  2. package/lib/command/cutCopy/getContentForCopy.js.map +1 -1
  3. package/lib/coreApi/setDOMSelection/setDOMSelection.js +5 -58
  4. package/lib/coreApi/setDOMSelection/setDOMSelection.js.map +1 -1
  5. package/lib/coreApi/setDOMSelection/setTableCellsStyle.d.ts +17 -0
  6. package/lib/coreApi/setDOMSelection/setTableCellsStyle.js +85 -0
  7. package/lib/coreApi/setDOMSelection/setTableCellsStyle.js.map +1 -0
  8. package/lib/coreApi/setDOMSelection/toggleTableSelection.d.ts +8 -0
  9. package/lib/coreApi/setDOMSelection/toggleTableSelection.js +34 -0
  10. package/lib/coreApi/setDOMSelection/toggleTableSelection.js.map +1 -0
  11. package/lib/coreApi/switchShadowEdit/switchShadowEdit.js +3 -0
  12. package/lib/coreApi/switchShadowEdit/switchShadowEdit.js.map +1 -1
  13. package/lib/corePlugin/selection/SelectionPlugin.js +3 -0
  14. package/lib/corePlugin/selection/SelectionPlugin.js.map +1 -1
  15. package/lib/editor/Editor.js +1 -1
  16. package/lib/editor/Editor.js.map +1 -1
  17. package/lib-amd/command/cutCopy/getContentForCopy.js +5 -14
  18. package/lib-amd/command/cutCopy/getContentForCopy.js.map +1 -1
  19. package/lib-amd/coreApi/setDOMSelection/setDOMSelection.js +4 -58
  20. package/lib-amd/coreApi/setDOMSelection/setDOMSelection.js.map +1 -1
  21. package/lib-amd/coreApi/setDOMSelection/setTableCellsStyle.d.ts +17 -0
  22. package/lib-amd/coreApi/setDOMSelection/setTableCellsStyle.js +85 -0
  23. package/lib-amd/coreApi/setDOMSelection/setTableCellsStyle.js.map +1 -0
  24. package/lib-amd/coreApi/setDOMSelection/toggleTableSelection.d.ts +8 -0
  25. package/lib-amd/coreApi/setDOMSelection/toggleTableSelection.js +34 -0
  26. package/lib-amd/coreApi/setDOMSelection/toggleTableSelection.js.map +1 -0
  27. package/lib-amd/coreApi/switchShadowEdit/switchShadowEdit.js +3 -1
  28. package/lib-amd/coreApi/switchShadowEdit/switchShadowEdit.js.map +1 -1
  29. package/lib-amd/corePlugin/selection/SelectionPlugin.js +3 -0
  30. package/lib-amd/corePlugin/selection/SelectionPlugin.js.map +1 -1
  31. package/lib-amd/editor/Editor.js +1 -1
  32. package/lib-amd/editor/Editor.js.map +1 -1
  33. package/lib-mjs/command/cutCopy/getContentForCopy.js +5 -16
  34. package/lib-mjs/command/cutCopy/getContentForCopy.js.map +1 -1
  35. package/lib-mjs/coreApi/setDOMSelection/setDOMSelection.js +5 -58
  36. package/lib-mjs/coreApi/setDOMSelection/setDOMSelection.js.map +1 -1
  37. package/lib-mjs/coreApi/setDOMSelection/setTableCellsStyle.d.ts +17 -0
  38. package/lib-mjs/coreApi/setDOMSelection/setTableCellsStyle.js +80 -0
  39. package/lib-mjs/coreApi/setDOMSelection/setTableCellsStyle.js.map +1 -0
  40. package/lib-mjs/coreApi/setDOMSelection/toggleTableSelection.d.ts +8 -0
  41. package/lib-mjs/coreApi/setDOMSelection/toggleTableSelection.js +30 -0
  42. package/lib-mjs/coreApi/setDOMSelection/toggleTableSelection.js.map +1 -0
  43. package/lib-mjs/coreApi/switchShadowEdit/switchShadowEdit.js +3 -0
  44. package/lib-mjs/coreApi/switchShadowEdit/switchShadowEdit.js.map +1 -1
  45. package/lib-mjs/corePlugin/selection/SelectionPlugin.js +3 -0
  46. package/lib-mjs/corePlugin/selection/SelectionPlugin.js.map +1 -1
  47. package/lib-mjs/editor/Editor.js +1 -1
  48. package/lib-mjs/editor/Editor.js.map +1 -1
  49. package/package.json +3 -3
  50. package/lib/command/cutCopy/preprocessTable.d.ts +0 -5
  51. package/lib/command/cutCopy/preprocessTable.js +0 -22
  52. package/lib/command/cutCopy/preprocessTable.js.map +0 -1
  53. package/lib/command/cutCopy/pruneUnselectedModel.d.ts +0 -5
  54. package/lib/command/cutCopy/pruneUnselectedModel.js +0 -135
  55. package/lib/command/cutCopy/pruneUnselectedModel.js.map +0 -1
  56. package/lib-amd/command/cutCopy/preprocessTable.d.ts +0 -5
  57. package/lib-amd/command/cutCopy/preprocessTable.js +0 -22
  58. package/lib-amd/command/cutCopy/preprocessTable.js.map +0 -1
  59. package/lib-amd/command/cutCopy/pruneUnselectedModel.d.ts +0 -5
  60. package/lib-amd/command/cutCopy/pruneUnselectedModel.js +0 -136
  61. package/lib-amd/command/cutCopy/pruneUnselectedModel.js.map +0 -1
  62. package/lib-mjs/command/cutCopy/preprocessTable.d.ts +0 -5
  63. package/lib-mjs/command/cutCopy/preprocessTable.js +0 -18
  64. package/lib-mjs/command/cutCopy/preprocessTable.js.map +0 -1
  65. package/lib-mjs/command/cutCopy/pruneUnselectedModel.d.ts +0 -5
  66. package/lib-mjs/command/cutCopy/pruneUnselectedModel.js +0 -131
  67. package/lib-mjs/command/cutCopy/pruneUnselectedModel.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"Editor.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-core/lib/editor/Editor.ts"],"names":[],"mappings":";;;;IAqCA;;OAEG;IACH;QAGI;;;;WAIG;QACH,gBAAY,UAA0B,EAAE,OAA2B;YAAnE,iBAcC;YAduC,wBAAA,EAAA,YAA2B;;YAP3D,SAAI,GAAsB,IAAI,CAAC;YAsZ/B,wBAAmB,GAAyB,UAAC,IAAI,EAAE,IAAI;gBAC3D,IAAI,IAAI,IAAI,OAAO,EAAE;oBACjB,OAAO,SAAS,CAAC;iBACpB;gBAED,IAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAgB,CAAC;gBAE5D,IAAI,KAAI,CAAC,UAAU,EAAE,EAAE;oBACnB,IAAM,YAAY,GAAG,KAAI,CAAC,eAAe,EAAE,CAAC;oBAE5C,IAAA,4CAAc,EAAC,MAAM,EAAE,IAAI,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,GAA5B,UAA6B,WAAyC;YAClE,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC,oBAAoB,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QACzE,CAAC;QAED;;;WAGG;QACO,wBAAO,GAAjB;YACI,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;gBACZ,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;aACjD;YACD,OAAO,IAAI,CAAC,IAAI,CAAC;QACrB,CAAC;QAsBL,aAAC;IAAD,CAAC,AA3aD,IA2aC;IA3aY,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 );\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 * @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":";;;;IAqCA;;OAEG;IACH;QAGI;;;;WAIG;QACH,gBAAY,UAA0B,EAAE,OAA2B;YAAnE,iBAcC;YAduC,wBAAA,EAAA,YAA2B;;YAP3D,SAAI,GAAsB,IAAI,CAAC;YAuZ/B,wBAAmB,GAAyB,UAAC,IAAI,EAAE,IAAI;gBAC3D,IAAI,IAAI,IAAI,OAAO,EAAE;oBACjB,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AAC,cAAc,CAAC,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;QAC9D,CAAC;QAED;;;WAGG;QACH,yBAAQ,GAAR,UAAS,YAA0B;YAC/B,IAAM,IAAI,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;YAE5B,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;QAC1C,CAAC;QAED;;;WAGG;QACH,6CAA4B,GAA5B,UAA6B,WAAyC;YAClE,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC,oBAAoB,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QACzE,CAAC;QAED;;;WAGG;QACO,wBAAO,GAAjB;YACI,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;gBACZ,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;aACjD;YACD,OAAO,IAAI,CAAC,IAAI,CAAC;QACrB,CAAC;QAsBL,aAAC;IAAD,CAAC,AA5aD,IA4aC;IA5aY,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 * @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,9 +1,7 @@
1
1
  import { adjustImageSelectionOnSafari } from './adjustImageSelectionOnSafari';
2
2
  import { adjustSelectionForCopyCut } from './adjustSelectionForCopyCut';
3
3
  import { onCreateCopyEntityNode } from '../../override/pasteCopyBlockEntityParser';
4
- import { preprocessTable } from './preprocessTable';
5
- import { pruneUnselectedModel } from './pruneUnselectedModel';
6
- import { contentModelToDom, contentModelToText, createModelToDomContext, isElementOfType, isNodeOfType, iterateSelections, wrap, } from 'roosterjs-content-model-dom';
4
+ import { contentModelToDom, contentModelToText, createModelToDomContext, trimModelForSelection, isElementOfType, isNodeOfType, wrap, } from 'roosterjs-content-model-dom';
7
5
  /**
8
6
  * @internal
9
7
  * Exported only for unit testing
@@ -27,22 +25,13 @@ export var onNodeCreated = function (modelElement, node) {
27
25
  export function getContentForCopy(editor, isCut, event) {
28
26
  var selection = editor.getDOMSelection();
29
27
  adjustImageSelectionOnSafari(editor, selection);
30
- if (selection && (selection.type != 'range' || !selection.range.collapsed)) {
28
+ if (selection && (selection.type !== 'range' || !selection.range.collapsed)) {
31
29
  var pasteModel = editor.getContentModelCopy('disconnected');
32
- pruneUnselectedModel(pasteModel);
33
- if (selection.type === 'table') {
34
- iterateSelections(pasteModel, function (_, tableContext) {
35
- if (tableContext === null || tableContext === void 0 ? void 0 : tableContext.table) {
36
- preprocessTable(tableContext.table);
37
- return true;
38
- }
39
- return false;
40
- });
41
- }
42
- else if (selection.type === 'range') {
30
+ var context = createModelToDomContext();
31
+ trimModelForSelection(pasteModel, selection);
32
+ if (selection.type === 'range') {
43
33
  adjustSelectionForCopyCut(pasteModel);
44
34
  }
45
- var context = createModelToDomContext();
46
35
  context.onNodeCreated = onNodeCreated;
47
36
  var doc = editor.getDocument();
48
37
  var tempDiv = doc.createElement('div');
@@ -1 +1 @@
1
- {"version":3,"file":"getContentForCopy.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/command/cutCopy/getContentForCopy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4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IAAI,QAAQ,GAAiB,IAAI,CAAC;IAElC,IAAI,SAAS,CAAC,IAAI,KAAK,OAAO,EAAE;QAC5B,IAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC;QAC9B,IAAM,eAAe,GACjB,CAAA,MAAA,KAAK,CAAC,aAAa,0CAAE,iBAAiB,KAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC;QAE9E,QAAQ,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC;QAC7B,QAAQ,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC;KACxC;SAAM,IAAI,SAAS,CAAC,IAAI,KAAK,OAAO,EAAE;QACnC,QAAQ,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC;QAC7B,QAAQ,CAAC,UAAU,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;KACxC;SAAM;QACH,QAAQ,GAAG,SAAS,CAAC,KAAK,CAAC;KAC9B;IAED,OAAO,QAAQ,CAAC;AACpB,CAAC","sourcesContent":["import { adjustImageSelectionOnSafari } from './adjustImageSelectionOnSafari';\nimport { adjustSelectionForCopyCut } from './adjustSelectionForCopyCut';\nimport { onCreateCopyEntityNode } from '../../override/pasteCopyBlockEntityParser';\nimport { preprocessTable } from './preprocessTable';\nimport { pruneUnselectedModel } from './pruneUnselectedModel';\nimport type {\n DOMSelection,\n IEditor,\n OnNodeCreated,\n TextAndHtmlContentForCopy,\n} from 'roosterjs-content-model-types';\nimport {\n contentModelToDom,\n contentModelToText,\n createModelToDomContext,\n isElementOfType,\n isNodeOfType,\n iterateSelections,\n wrap,\n} from 'roosterjs-content-model-dom';\n\n/**\n * @internal\n * Exported only for unit testing\n */\nexport const onNodeCreated: OnNodeCreated = (modelElement, node): void => {\n if (isNodeOfType(node, 'ELEMENT_NODE') && isElementOfType(node, 'table')) {\n wrap(node.ownerDocument, node, 'div');\n }\n if (isNodeOfType(node, 'ELEMENT_NODE') && !node.isContentEditable) {\n node.removeAttribute('contenteditable');\n }\n onCreateCopyEntityNode(modelElement, node);\n};\n\n/**\n * Get the content for the copy event\n * @param editor The editor object\n * @param isCut if the event cut the content.\n * @param event the clipboard event that triggered the copy/cut\n * @returns\n */\nexport function getContentForCopy(\n editor: IEditor,\n isCut: boolean,\n event: ClipboardEvent\n): TextAndHtmlContentForCopy | null {\n const selection = editor.getDOMSelection();\n adjustImageSelectionOnSafari(editor, selection);\n if (selection && (selection.type != 'range' || !selection.range.collapsed)) {\n const pasteModel = editor.getContentModelCopy('disconnected');\n pruneUnselectedModel(pasteModel);\n\n if (selection.type === 'table') {\n iterateSelections(pasteModel, (_, tableContext) => {\n if (tableContext?.table) {\n preprocessTable(tableContext.table);\n\n return true;\n }\n return false;\n });\n } else if (selection.type === 'range') {\n adjustSelectionForCopyCut(pasteModel);\n }\n const context = createModelToDomContext();\n\n context.onNodeCreated = onNodeCreated;\n const doc = editor.getDocument();\n const tempDiv = doc.createElement('div');\n\n const selectionForCopy = contentModelToDom(doc, tempDiv, pasteModel, context);\n const newRange = selectionForCopy ? domSelectionToRange(doc, selectionForCopy) : null;\n if (newRange) {\n const { clonedRoot } = editor.triggerEvent('beforeCutCopy', {\n clonedRoot: tempDiv,\n range: newRange,\n rawEvent: event,\n isCut,\n });\n\n return {\n htmlContent: clonedRoot,\n textContent: contentModelToText(pasteModel),\n };\n }\n }\n return null;\n}\n\nfunction domSelectionToRange(doc: Document, selection: DOMSelection): Range | null {\n let newRange: Range | null = null;\n\n if (selection.type === 'table') {\n const table = selection.table;\n const elementToSelect =\n table.parentElement?.childElementCount == 1 ? table.parentElement : table;\n\n newRange = doc.createRange();\n newRange.selectNode(elementToSelect);\n } else if (selection.type === 'image') {\n newRange = doc.createRange();\n newRange.selectNode(selection.image);\n } else {\n newRange = selection.range;\n }\n\n return newRange;\n}\n"]}
1
+ {"version":3,"file":"getContentForCopy.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/command/cutCopy/getContentForCopy.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,CAAC,eAAe,CAAC,CAAC;KACxC;SAAM,IAAI,SAAS,CAAC,IAAI,KAAK,OAAO,EAAE;QACnC,QAAQ,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC;QAC7B,QAAQ,CAAC,UAAU,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;KACxC;SAAM;QACH,QAAQ,GAAG,SAAS,CAAC,KAAK,CAAC;KAC9B;IAED,OAAO,QAAQ,CAAC;AACpB,CAAC","sourcesContent":["import { adjustImageSelectionOnSafari } from './adjustImageSelectionOnSafari';\nimport { adjustSelectionForCopyCut } from './adjustSelectionForCopyCut';\nimport { onCreateCopyEntityNode } from '../../override/pasteCopyBlockEntityParser';\nimport {\n contentModelToDom,\n contentModelToText,\n createModelToDomContext,\n trimModelForSelection,\n isElementOfType,\n isNodeOfType,\n wrap,\n} from 'roosterjs-content-model-dom';\nimport type {\n DOMSelection,\n IEditor,\n OnNodeCreated,\n TextAndHtmlContentForCopy,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n * Exported only for unit testing\n */\nexport const onNodeCreated: OnNodeCreated = (modelElement, node): void => {\n if (isNodeOfType(node, 'ELEMENT_NODE') && isElementOfType(node, 'table')) {\n wrap(node.ownerDocument, node, 'div');\n }\n if (isNodeOfType(node, 'ELEMENT_NODE') && !node.isContentEditable) {\n node.removeAttribute('contenteditable');\n }\n onCreateCopyEntityNode(modelElement, node);\n};\n\n/**\n * Get the content for the copy event\n * @param editor The editor object\n * @param isCut if the event cut the content.\n * @param event the clipboard event that triggered the copy/cut\n * @returns\n */\nexport function getContentForCopy(\n editor: IEditor,\n isCut: boolean,\n event: ClipboardEvent\n): TextAndHtmlContentForCopy | null {\n const selection = editor.getDOMSelection();\n adjustImageSelectionOnSafari(editor, selection);\n\n if (selection && (selection.type !== 'range' || !selection.range.collapsed)) {\n const pasteModel = editor.getContentModelCopy('disconnected');\n const context = createModelToDomContext();\n trimModelForSelection(pasteModel, selection);\n\n if (selection.type === 'range') {\n adjustSelectionForCopyCut(pasteModel);\n }\n\n context.onNodeCreated = onNodeCreated;\n const doc = editor.getDocument();\n const tempDiv = doc.createElement('div');\n\n const selectionForCopy = contentModelToDom(doc, tempDiv, pasteModel, context);\n const newRange = selectionForCopy ? domSelectionToRange(doc, selectionForCopy) : null;\n if (newRange) {\n const { clonedRoot } = editor.triggerEvent('beforeCutCopy', {\n clonedRoot: tempDiv,\n range: newRange,\n rawEvent: event,\n isCut,\n });\n\n return {\n htmlContent: clonedRoot,\n textContent: contentModelToText(pasteModel),\n };\n }\n }\n return null;\n}\n\nfunction domSelectionToRange(doc: Document, selection: DOMSelection): Range | null {\n let newRange: Range | null = null;\n\n if (selection.type === 'table') {\n const table = selection.table;\n const elementToSelect =\n table.parentElement?.childElementCount == 1 ? table.parentElement : table;\n\n newRange = doc.createRange();\n newRange.selectNode(elementToSelect);\n } else if (selection.type === 'image') {\n newRange = doc.createRange();\n newRange.selectNode(selection.image);\n } else {\n newRange = selection.range;\n }\n\n return newRange;\n}\n"]}
@@ -3,12 +3,12 @@ import { areSameSelections } from '../../corePlugin/cache/areSameSelections';
3
3
  import { ensureUniqueId } from '../setEditorStyle/ensureUniqueId';
4
4
  import { findLastedCoInMergedCell } from './findLastedCoInMergedCell';
5
5
  import { findTableCellElement } from './findTableCellElement';
6
+ import { getSafeIdSelector, parseTableCells } from 'roosterjs-content-model-dom';
7
+ import { setTableCellsStyle } from './setTableCellsStyle';
6
8
  import { toggleCaret } from './toggleCaret';
7
- import { getSafeIdSelector, isNodeOfType, parseTableCells, toArray, } from 'roosterjs-content-model-dom';
8
9
  var DOM_SELECTION_CSS_KEY = '_DOMSelection';
9
10
  var HIDE_SELECTION_CSS_KEY = '_DOMSelectionHideSelection';
10
11
  var IMAGE_ID = 'image';
11
- var TABLE_ID = 'table';
12
12
  var TRANSPARENT_SELECTION_CSS_RULE = 'background-color: transparent !important;';
13
13
  var SELECTION_SELECTOR = '*::selection';
14
14
  var DEFAULT_SELECTION_BORDER_COLOR = '#DB626C';
@@ -16,7 +16,7 @@ var DEFAULT_SELECTION_BORDER_COLOR = '#DB626C';
16
16
  * @internal
17
17
  */
18
18
  export var setDOMSelection = function (core, selection, skipSelectionChangedEvent) {
19
- var _a, _b, _c;
19
+ var _a;
20
20
  var existingSelection = core.api.getDOMSelection(core);
21
21
  if (existingSelection && selection && areSameSelections(existingSelection, selection)) {
22
22
  return;
@@ -71,22 +71,11 @@ export var setDOMSelection = function (core, selection, skipSelectionChangedEven
71
71
  lastColumn: lastCell.col,
72
72
  tableSelectionInfo: selection.tableSelectionInfo,
73
73
  };
74
- var tableId = ensureUniqueId(table, TABLE_ID);
75
- var tableSelector = getSafeIdSelector(tableId);
76
- var tableSelectors = firstCell.row == 0 &&
77
- firstCell.col == 0 &&
78
- lastCell.row == parsedTable.length - 1 &&
79
- lastCell.col == ((_b = (_a = parsedTable[lastCell.row]) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) - 1
80
- ? [tableSelector, tableSelector + " *"]
81
- : handleTableSelected(parsedTable, tableSelector, table, firstCell, lastCell);
82
74
  core.selection.selection = selection;
83
- var tableSelectionColor = isDarkMode
84
- ? core.selection.tableCellSelectionBackgroundColorDark
85
- : core.selection.tableCellSelectionBackgroundColor;
86
- core.api.setEditorStyle(core, DOM_SELECTION_CSS_KEY, "background-color:" + tableSelectionColor + "!important;", tableSelectors);
75
+ setTableCellsStyle(core, table, parsedTable, firstCell, lastCell);
87
76
  core.api.setEditorStyle(core, HIDE_SELECTION_CSS_KEY, TRANSPARENT_SELECTION_CSS_RULE, [SELECTION_SELECTOR]);
88
77
  toggleCaret(core, true /* hide */);
89
- var nodeToSelect = ((_c = firstCell.cell) === null || _c === void 0 ? void 0 : _c.firstElementChild) || firstCell.cell;
78
+ var nodeToSelect = ((_a = firstCell.cell) === null || _a === void 0 ? void 0 : _a.firstElementChild) || firstCell.cell;
90
79
  if (nodeToSelect) {
91
80
  setRangeSelection(doc, nodeToSelect || undefined, true /* collapse */);
92
81
  }
@@ -111,48 +100,6 @@ export var setDOMSelection = function (core, selection, skipSelectionChangedEven
111
100
  core.api.triggerEvent(core, eventData, true /*broadcast*/);
112
101
  }
113
102
  };
114
- function handleTableSelected(parsedTable, tableSelector, table, firstCell, lastCell) {
115
- var selectors = [];
116
- // Get whether table has thead, tbody or tfoot, then Set the start and end of each of the table children,
117
- // so we can build the selector according the element between the table and the row.
118
- var cont = 0;
119
- var indexes = toArray(table.childNodes)
120
- .filter(function (node) {
121
- return ['THEAD', 'TBODY', 'TFOOT'].indexOf(isNodeOfType(node, 'ELEMENT_NODE') ? node.tagName : '') > -1;
122
- })
123
- .map(function (node) {
124
- var result = {
125
- el: node.tagName,
126
- start: cont,
127
- end: node.childNodes.length + cont,
128
- };
129
- cont = result.end;
130
- return result;
131
- });
132
- parsedTable.forEach(function (row, rowIndex) {
133
- var tdCount = 0;
134
- //Get current TBODY/THEAD/TFOOT
135
- var midElement = indexes.filter(function (ind) { return ind.start <= rowIndex && ind.end > rowIndex; })[0];
136
- var middleElSelector = midElement ? '>' + midElement.el + '>' : '>';
137
- var currentRow = midElement && rowIndex + 1 >= midElement.start
138
- ? rowIndex + 1 - midElement.start
139
- : rowIndex + 1;
140
- for (var cellIndex = 0; cellIndex < row.length; cellIndex++) {
141
- var cell = row[cellIndex];
142
- if (typeof cell == 'object') {
143
- tdCount++;
144
- if (rowIndex >= firstCell.row &&
145
- rowIndex <= lastCell.row &&
146
- cellIndex >= firstCell.col &&
147
- cellIndex <= lastCell.col) {
148
- var selector = "" + tableSelector + middleElSelector + " tr:nth-child(" + currentRow + ")>" + cell.tagName + ":nth-child(" + tdCount + ")";
149
- selectors.push(selector, selector + ' *');
150
- }
151
- }
152
- }
153
- });
154
- return selectors;
155
- }
156
103
  function setRangeSelection(doc, element, collapse) {
157
104
  var _a;
158
105
  if (element && doc.contains(element)) {
@@ -1 +1 @@
1
- {"version":3,"file":"setDOMSelection.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/l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AQ,GAAG,IAAI,CAAC,CAAC;iBAC7C;aACJ;SACJ;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,SAAS,CAAC;AACrB,CAAC;AAED,SAAS,iBAAiB,CAAC,GAAa,EAAE,OAAgC,EAAE,QAAiB;;IACzF,IAAI,OAAO,IAAI,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;QAClC,IAAM,KAAK,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC;QAChC,IAAI,UAAU,GAAwB,SAAS,CAAC;QAEhD,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QAC1B,IAAI,QAAQ,EAAE;YACV,KAAK,CAAC,QAAQ,EAAE,CAAC;SACpB;aAAM;YACH,IAAM,SAAS,GAAG,MAAA,GAAG,CAAC,WAAW,0CAAE,YAAY,EAAE,CAAC;YAClD,IAAM,OAAK,GAAG,SAAS,IAAI,SAAS,CAAC,UAAU,GAAG,CAAC,IAAI,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;YAC/E,IAAI,SAAS,IAAI,OAAK,EAAE;gBACpB,UAAU;oBACN,SAAS,CAAC,SAAS,IAAI,OAAK,CAAC,YAAY;wBACzC,SAAS,CAAC,WAAW,IAAI,OAAK,CAAC,SAAS,CAAC;aAChD;SACJ;QAED,mBAAmB,CAAC,GAAG,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC;KAC/C;AACL,CAAC","sourcesContent":["import { addRangeToSelection } from './addRangeToSelection';\nimport { areSameSelections } from '../../corePlugin/cache/areSameSelections';\nimport { ensureUniqueId } from '../setEditorStyle/ensureUniqueId';\nimport { findLastedCoInMergedCell } from './findLastedCoInMergedCell';\nimport { findTableCellElement } from './findTableCellElement';\nimport { toggleCaret } from './toggleCaret';\nimport {\n getSafeIdSelector,\n isNodeOfType,\n parseTableCells,\n toArray,\n} from 'roosterjs-content-model-dom';\nimport type {\n ParsedTable,\n SelectionChangedEvent,\n SetDOMSelection,\n TableCellCoordinate,\n} from 'roosterjs-content-model-types';\n\nconst DOM_SELECTION_CSS_KEY = '_DOMSelection';\nconst HIDE_SELECTION_CSS_KEY = '_DOMSelectionHideSelection';\nconst IMAGE_ID = 'image';\nconst TABLE_ID = 'table';\nconst TRANSPARENT_SELECTION_CSS_RULE = 'background-color: transparent !important;';\nconst SELECTION_SELECTOR = '*::selection';\nconst DEFAULT_SELECTION_BORDER_COLOR = '#DB626C';\n\n/**\n * @internal\n */\nexport const setDOMSelection: SetDOMSelection = (core, selection, skipSelectionChangedEvent) => {\n const existingSelection = core.api.getDOMSelection(core);\n\n if (existingSelection && selection && areSameSelections(existingSelection, selection)) {\n return;\n }\n\n // We are applying a new selection, so we don't need to apply cached selection in DOMEventPlugin.\n // Set skipReselectOnFocus to skip this behavior\n const skipReselectOnFocus = core.selection.skipReselectOnFocus;\n\n const doc = core.physicalRoot.ownerDocument;\n const isDarkMode = core.lifecycle.isDarkMode;\n core.selection.skipReselectOnFocus = true;\n core.api.setEditorStyle(core, DOM_SELECTION_CSS_KEY, null /*cssRule*/);\n core.api.setEditorStyle(core, HIDE_SELECTION_CSS_KEY, null /*cssRule*/);\n\n toggleCaret(core, false /* hide */);\n\n try {\n switch (selection?.type) {\n case 'image':\n const image = selection.image;\n\n core.selection.selection = selection;\n\n const imageSelectionColor = isDarkMode\n ? core.selection.imageSelectionBorderColorDark\n : core.selection.imageSelectionBorderColor;\n\n core.api.setEditorStyle(\n core,\n DOM_SELECTION_CSS_KEY,\n `outline-style:solid!important; outline-color:${\n imageSelectionColor || DEFAULT_SELECTION_BORDER_COLOR\n }!important;`,\n [getSafeIdSelector(ensureUniqueId(image, IMAGE_ID))]\n );\n core.api.setEditorStyle(\n core,\n HIDE_SELECTION_CSS_KEY,\n TRANSPARENT_SELECTION_CSS_RULE,\n [SELECTION_SELECTOR]\n );\n\n setRangeSelection(doc, image, false /* collapse */);\n break;\n case 'table':\n const { table, firstColumn, firstRow, lastColumn, lastRow } = selection;\n const parsedTable = parseTableCells(selection.table);\n let firstCell = {\n row: Math.min(firstRow, lastRow),\n col: Math.min(firstColumn, lastColumn),\n cell: <HTMLTableCellElement | null>null,\n };\n let lastCell = {\n row: Math.max(firstRow, lastRow),\n col: Math.max(firstColumn, lastColumn),\n };\n\n firstCell = findTableCellElement(parsedTable, firstCell) || firstCell;\n lastCell = findLastedCoInMergedCell(parsedTable, lastCell) || lastCell;\n\n if (\n isNaN(firstCell.row) ||\n isNaN(firstCell.col) ||\n isNaN(lastCell.row) ||\n isNaN(lastCell.col)\n ) {\n return;\n }\n\n selection = {\n type: 'table',\n table,\n firstRow: firstCell.row,\n firstColumn: firstCell.col,\n lastRow: lastCell.row,\n lastColumn: lastCell.col,\n tableSelectionInfo: selection.tableSelectionInfo,\n };\n\n const tableId = ensureUniqueId(table, TABLE_ID);\n const tableSelector = getSafeIdSelector(tableId);\n\n const tableSelectors =\n firstCell.row == 0 &&\n firstCell.col == 0 &&\n lastCell.row == parsedTable.length - 1 &&\n lastCell.col == (parsedTable[lastCell.row]?.length ?? 0) - 1\n ? [tableSelector, `${tableSelector} *`]\n : handleTableSelected(\n parsedTable,\n tableSelector,\n table,\n firstCell,\n lastCell\n );\n\n core.selection.selection = selection;\n\n const tableSelectionColor = isDarkMode\n ? core.selection.tableCellSelectionBackgroundColorDark\n : core.selection.tableCellSelectionBackgroundColor;\n core.api.setEditorStyle(\n core,\n DOM_SELECTION_CSS_KEY,\n `background-color:${tableSelectionColor}!important;`,\n tableSelectors\n );\n core.api.setEditorStyle(\n core,\n HIDE_SELECTION_CSS_KEY,\n TRANSPARENT_SELECTION_CSS_RULE,\n [SELECTION_SELECTOR]\n );\n\n toggleCaret(core, true /* hide */);\n\n const nodeToSelect = firstCell.cell?.firstElementChild || firstCell.cell;\n\n if (nodeToSelect) {\n setRangeSelection(\n doc,\n (nodeToSelect as HTMLElement) || undefined,\n true /* collapse */\n );\n }\n\n break;\n case 'range':\n addRangeToSelection(doc, selection.range, selection.isReverted);\n\n core.selection.selection = core.domHelper.hasFocus() ? null : selection;\n break;\n\n default:\n core.selection.selection = null;\n break;\n }\n } finally {\n core.selection.skipReselectOnFocus = skipReselectOnFocus;\n }\n\n if (!skipSelectionChangedEvent) {\n const eventData: SelectionChangedEvent = {\n eventType: 'selectionChanged',\n newSelection: selection,\n };\n\n core.api.triggerEvent(core, eventData, true /*broadcast*/);\n }\n};\n\nfunction handleTableSelected(\n parsedTable: ParsedTable,\n tableSelector: string,\n table: HTMLTableElement,\n firstCell: TableCellCoordinate,\n lastCell: TableCellCoordinate\n) {\n const selectors: string[] = [];\n\n // Get whether table has thead, tbody or tfoot, then Set the start and end of each of the table children,\n // so we can build the selector according the element between the table and the row.\n let cont = 0;\n const indexes = toArray(table.childNodes)\n .filter(\n (node): node is HTMLTableSectionElement =>\n ['THEAD', 'TBODY', 'TFOOT'].indexOf(\n isNodeOfType(node, 'ELEMENT_NODE') ? node.tagName : ''\n ) > -1\n )\n .map(node => {\n const result = {\n el: node.tagName,\n start: cont,\n end: node.childNodes.length + cont,\n };\n\n cont = result.end;\n return result;\n });\n\n parsedTable.forEach((row, rowIndex) => {\n let tdCount = 0;\n\n //Get current TBODY/THEAD/TFOOT\n const midElement = indexes.filter(ind => ind.start <= rowIndex && ind.end > rowIndex)[0];\n const middleElSelector = midElement ? '>' + midElement.el + '>' : '>';\n const currentRow =\n midElement && rowIndex + 1 >= midElement.start\n ? rowIndex + 1 - midElement.start\n : rowIndex + 1;\n\n for (let cellIndex = 0; cellIndex < row.length; cellIndex++) {\n const cell = row[cellIndex];\n\n if (typeof cell == 'object') {\n tdCount++;\n\n if (\n rowIndex >= firstCell.row &&\n rowIndex <= lastCell.row &&\n cellIndex >= firstCell.col &&\n cellIndex <= lastCell.col\n ) {\n const selector = `${tableSelector}${middleElSelector} tr:nth-child(${currentRow})>${cell.tagName}:nth-child(${tdCount})`;\n\n selectors.push(selector, selector + ' *');\n }\n }\n }\n });\n\n return selectors;\n}\n\nfunction setRangeSelection(doc: Document, element: HTMLElement | undefined, collapse: boolean) {\n if (element && doc.contains(element)) {\n const range = doc.createRange();\n let isReverted: boolean | undefined = undefined;\n\n range.selectNode(element);\n if (collapse) {\n range.collapse();\n } else {\n const selection = doc.defaultView?.getSelection();\n const range = selection && selection.rangeCount > 0 && selection.getRangeAt(0);\n if (selection && range) {\n isReverted =\n selection.focusNode != range.endContainer ||\n selection.focusOffset != range.endOffset;\n }\n }\n\n addRangeToSelection(doc, range, isReverted);\n }\n}\n"]}
1
+ {"version":3,"file":"setDOMSelection.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/coreApi/setDOMSelection/setDOMSelection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AAC7E,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAClE,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AACjF,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C,IAAM,qBAAqB,GAAG,eAAe,CAAC;AAC9C,IAAM,sBAAsB,GAAG,4BAA4B,CAAC;AAC5D,IAAM,QAAQ,GAAG,OAAO,CAAC;AACzB,IAAM,8BAA8B,GAAG,2CAA2C,CAAC;AACnF,IAAM,kBAAkB,GAAG,cAAc,CAAC;AAC1C,IAAM,8BAA8B,GAAG,SAAS,CAAC;AAEjD;;GAEG;AACH,MAAM,CAAC,IAAM,eAAe,GAAoB,UAAC,IAAI,EAAE,SAAS,EAAE,yBAAyB;;IACvF,IAAM,iBAAiB,GAAG,IAAI,CAAC,GAAG,CAAC,eAAe,CAAC,IAAI,CAA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YAC7B,YAAY,EAAE,SAAS;SAC1B,CAAC;QAEF,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,EAAE,SAAS,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;KAC9D;AACL,CAAC,CAAC;AAEF,SAAS,iBAAiB,CAAC,GAAa,EAAE,OAAgC,EAAE,QAAiB;;IACzF,IAAI,OAAO,IAAI,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;QAClC,IAAM,KAAK,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC;QAChC,IAAI,UAAU,GAAwB,SAAS,CAAC;QAEhD,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QAC1B,IAAI,QAAQ,EAAE;YACV,KAAK,CAAC,QAAQ,EAAE,CAAC;SACpB;aAAM;YACH,IAAM,SAAS,GAAG,MAAA,GAAG,CAAC,WAAW,0CAAE,YAAY,EAAE,CAAC;YAClD,IAAM,OAAK,GAAG,SAAS,IAAI,SAAS,CAAC,UAAU,GAAG,CAAC,IAAI,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;YAC/E,IAAI,SAAS,IAAI,OAAK,EAAE;gBACpB,UAAU;oBACN,SAAS,CAAC,SAAS,IAAI,OAAK,CAAC,YAAY;wBACzC,SAAS,CAAC,WAAW,IAAI,OAAK,CAAC,SAAS,CAAC;aAChD;SACJ;QAED,mBAAmB,CAAC,GAAG,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC;KAC/C;AACL,CAAC","sourcesContent":["import { addRangeToSelection } from './addRangeToSelection';\nimport { areSameSelections } from '../../corePlugin/cache/areSameSelections';\nimport { ensureUniqueId } from '../setEditorStyle/ensureUniqueId';\nimport { findLastedCoInMergedCell } from './findLastedCoInMergedCell';\nimport { findTableCellElement } from './findTableCellElement';\nimport { getSafeIdSelector, parseTableCells } from 'roosterjs-content-model-dom';\nimport { setTableCellsStyle } from './setTableCellsStyle';\nimport { toggleCaret } from './toggleCaret';\nimport type { SelectionChangedEvent, SetDOMSelection } from 'roosterjs-content-model-types';\n\nconst DOM_SELECTION_CSS_KEY = '_DOMSelection';\nconst HIDE_SELECTION_CSS_KEY = '_DOMSelectionHideSelection';\nconst IMAGE_ID = 'image';\nconst TRANSPARENT_SELECTION_CSS_RULE = 'background-color: transparent !important;';\nconst SELECTION_SELECTOR = '*::selection';\nconst DEFAULT_SELECTION_BORDER_COLOR = '#DB626C';\n\n/**\n * @internal\n */\nexport const setDOMSelection: SetDOMSelection = (core, selection, skipSelectionChangedEvent) => {\n const existingSelection = core.api.getDOMSelection(core);\n\n if (existingSelection && selection && areSameSelections(existingSelection, selection)) {\n return;\n }\n\n // We are applying a new selection, so we don't need to apply cached selection in DOMEventPlugin.\n // Set skipReselectOnFocus to skip this behavior\n const skipReselectOnFocus = core.selection.skipReselectOnFocus;\n\n const doc = core.physicalRoot.ownerDocument;\n const isDarkMode = core.lifecycle.isDarkMode;\n core.selection.skipReselectOnFocus = true;\n core.api.setEditorStyle(core, DOM_SELECTION_CSS_KEY, null /*cssRule*/);\n core.api.setEditorStyle(core, HIDE_SELECTION_CSS_KEY, null /*cssRule*/);\n\n toggleCaret(core, false /* hide */);\n\n try {\n switch (selection?.type) {\n case 'image':\n const image = selection.image;\n\n core.selection.selection = selection;\n\n const imageSelectionColor = isDarkMode\n ? core.selection.imageSelectionBorderColorDark\n : core.selection.imageSelectionBorderColor;\n\n core.api.setEditorStyle(\n core,\n DOM_SELECTION_CSS_KEY,\n `outline-style:solid!important; outline-color:${\n imageSelectionColor || DEFAULT_SELECTION_BORDER_COLOR\n }!important;`,\n [getSafeIdSelector(ensureUniqueId(image, IMAGE_ID))]\n );\n core.api.setEditorStyle(\n core,\n HIDE_SELECTION_CSS_KEY,\n TRANSPARENT_SELECTION_CSS_RULE,\n [SELECTION_SELECTOR]\n );\n\n setRangeSelection(doc, image, false /* collapse */);\n break;\n case 'table':\n const { table, firstColumn, firstRow, lastColumn, lastRow } = selection;\n const parsedTable = parseTableCells(selection.table);\n let firstCell = {\n row: Math.min(firstRow, lastRow),\n col: Math.min(firstColumn, lastColumn),\n cell: <HTMLTableCellElement | null>null,\n };\n let lastCell = {\n row: Math.max(firstRow, lastRow),\n col: Math.max(firstColumn, lastColumn),\n };\n\n firstCell = findTableCellElement(parsedTable, firstCell) || firstCell;\n lastCell = findLastedCoInMergedCell(parsedTable, lastCell) || lastCell;\n\n if (\n isNaN(firstCell.row) ||\n isNaN(firstCell.col) ||\n isNaN(lastCell.row) ||\n isNaN(lastCell.col)\n ) {\n return;\n }\n\n selection = {\n type: 'table',\n table,\n firstRow: firstCell.row,\n firstColumn: firstCell.col,\n lastRow: lastCell.row,\n lastColumn: lastCell.col,\n tableSelectionInfo: selection.tableSelectionInfo,\n };\n\n core.selection.selection = selection;\n\n setTableCellsStyle(core, table, parsedTable, firstCell, lastCell);\n core.api.setEditorStyle(\n core,\n HIDE_SELECTION_CSS_KEY,\n TRANSPARENT_SELECTION_CSS_RULE,\n [SELECTION_SELECTOR]\n );\n\n toggleCaret(core, true /* hide */);\n\n const nodeToSelect = firstCell.cell?.firstElementChild || firstCell.cell;\n\n if (nodeToSelect) {\n setRangeSelection(\n doc,\n (nodeToSelect as HTMLElement) || undefined,\n true /* collapse */\n );\n }\n\n break;\n case 'range':\n addRangeToSelection(doc, selection.range, selection.isReverted);\n\n core.selection.selection = core.domHelper.hasFocus() ? null : selection;\n break;\n\n default:\n core.selection.selection = null;\n break;\n }\n } finally {\n core.selection.skipReselectOnFocus = skipReselectOnFocus;\n }\n\n if (!skipSelectionChangedEvent) {\n const eventData: SelectionChangedEvent = {\n eventType: 'selectionChanged',\n newSelection: selection,\n };\n\n core.api.triggerEvent(core, eventData, true /*broadcast*/);\n }\n};\n\nfunction setRangeSelection(doc: Document, element: HTMLElement | undefined, collapse: boolean) {\n if (element && doc.contains(element)) {\n const range = doc.createRange();\n let isReverted: boolean | undefined = undefined;\n\n range.selectNode(element);\n if (collapse) {\n range.collapse();\n } else {\n const selection = doc.defaultView?.getSelection();\n const range = selection && selection.rangeCount > 0 && selection.getRangeAt(0);\n if (selection && range) {\n isReverted =\n selection.focusNode != range.endContainer ||\n selection.focusOffset != range.endOffset;\n }\n }\n\n addRangeToSelection(doc, range, isReverted);\n }\n}\n"]}
@@ -0,0 +1,17 @@
1
+ import type { EditorCore, ParsedTable, TableCellCoordinate } from 'roosterjs-content-model-types';
2
+ /**
3
+ * @internal
4
+ * Remove table cell selection styles
5
+ * @param core The EditorCore object
6
+ */
7
+ export declare function removeTableCellsStyle(core: EditorCore): void;
8
+ /**
9
+ * @internal
10
+ * Set style for table cells in the selection
11
+ * @param core The EditorCore object
12
+ * @param table The HTML table element
13
+ * @param parsedTable The parsed table structure
14
+ * @param firstCell The coordinates of the first selected cell
15
+ * @param lastCell The coordinates of the last selected cell
16
+ */
17
+ export declare function setTableCellsStyle(core: EditorCore, table: HTMLTableElement, parsedTable: ParsedTable, firstCell: TableCellCoordinate, lastCell: TableCellCoordinate): void;
@@ -0,0 +1,80 @@
1
+ import { ensureUniqueId } from '../setEditorStyle/ensureUniqueId';
2
+ import { getSafeIdSelector, isNodeOfType, toArray } from 'roosterjs-content-model-dom';
3
+ var DOM_SELECTION_CSS_KEY = '_DOMSelection';
4
+ var TABLE_ID = 'table';
5
+ /**
6
+ * @internal
7
+ * Remove table cell selection styles
8
+ * @param core The EditorCore object
9
+ */
10
+ export function removeTableCellsStyle(core) {
11
+ core.api.setEditorStyle(core, DOM_SELECTION_CSS_KEY, '');
12
+ }
13
+ /**
14
+ * @internal
15
+ * Set style for table cells in the selection
16
+ * @param core The EditorCore object
17
+ * @param table The HTML table element
18
+ * @param parsedTable The parsed table structure
19
+ * @param firstCell The coordinates of the first selected cell
20
+ * @param lastCell The coordinates of the last selected cell
21
+ */
22
+ export function setTableCellsStyle(core, table, parsedTable, firstCell, lastCell) {
23
+ var _a, _b;
24
+ var tableId = ensureUniqueId(table, TABLE_ID);
25
+ var tableSelector = getSafeIdSelector(tableId);
26
+ var tableSelectionColor = core.lifecycle.isDarkMode
27
+ ? core.selection.tableCellSelectionBackgroundColorDark
28
+ : core.selection.tableCellSelectionBackgroundColor;
29
+ var tableSelectors = firstCell.row == 0 &&
30
+ firstCell.col == 0 &&
31
+ lastCell.row == parsedTable.length - 1 &&
32
+ lastCell.col == ((_b = (_a = parsedTable[lastCell.row]) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) - 1
33
+ ? [tableSelector, tableSelector + " *"]
34
+ : buildTableSelectors(parsedTable, tableSelector, table, firstCell, lastCell);
35
+ core.api.setEditorStyle(core, DOM_SELECTION_CSS_KEY, "background-color:" + tableSelectionColor + "!important;", tableSelectors);
36
+ }
37
+ /**
38
+ * @internal
39
+ * Build CSS selectors for table cells within the selection range
40
+ */
41
+ function buildTableSelectors(parsedTable, tableSelector, table, firstCell, lastCell) {
42
+ var selectors = [];
43
+ var cont = 0;
44
+ var indexes = toArray(table.childNodes)
45
+ .filter(function (node) {
46
+ return ['THEAD', 'TBODY', 'TFOOT'].indexOf(isNodeOfType(node, 'ELEMENT_NODE') ? node.tagName : '') > -1;
47
+ })
48
+ .map(function (node) {
49
+ var result = {
50
+ el: node.tagName,
51
+ start: cont,
52
+ end: node.childNodes.length + cont,
53
+ };
54
+ cont = result.end;
55
+ return result;
56
+ });
57
+ parsedTable.forEach(function (row, rowIndex) {
58
+ var tdCount = 0;
59
+ var midElement = indexes.filter(function (ind) { return ind.start <= rowIndex && ind.end > rowIndex; })[0];
60
+ var middleElSelector = midElement ? '>' + midElement.el + '>' : '>';
61
+ var currentRow = midElement && rowIndex + 1 >= midElement.start
62
+ ? rowIndex + 1 - midElement.start
63
+ : rowIndex + 1;
64
+ for (var cellIndex = 0; cellIndex < row.length; cellIndex++) {
65
+ var cell = row[cellIndex];
66
+ if (typeof cell == 'object') {
67
+ tdCount++;
68
+ if (rowIndex >= firstCell.row &&
69
+ rowIndex <= lastCell.row &&
70
+ cellIndex >= firstCell.col &&
71
+ cellIndex <= lastCell.col) {
72
+ var selector = "" + tableSelector + middleElSelector + " tr:nth-child(" + currentRow + ")>" + cell.tagName + ":nth-child(" + tdCount + ")";
73
+ selectors.push(selector, selector + ' *');
74
+ }
75
+ }
76
+ }
77
+ });
78
+ return selectors;
79
+ }
80
+ //# sourceMappingURL=setTableCellsStyle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setTableCellsStyle.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/coreApi/setDOMSelection/setTableCellsStyle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAGvF,IAAM,qBAAqB,GAAG,eAAe,CAAC;AAC9C,IAAM,QAAQ,GAAG,OAAO,CAAC;AAEzB;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAAgB;IAClD,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,EAAE,qBAAqB,EAAE,EAAE,CAAC,CAAC;AAC7D,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,kBAAkB,CAC9B,IAAgB,EAChB,KAAuB,EACvB,WAAwB,EACxB,SAA8B,EAC9B,QAA6B;;IAE7B,IAAM,OAAO,GAAG,cAAc,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IAChD,IAAM,aAAa,GAAG,iBAAiB,CAAC,OAAO,CAAC,CAAC;IACjD,IAAM,mBAAmB,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU;QACjD,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,qCAAqC;QACtD,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,iCAAiC,CAAC;IAEvD,IAAM,cAAc,GAChB,SAAS,CAAC,GAAG,IAAI,CAAC;QAClB,SAAS,CAAC,GAAG,IAAI,CAAC;QAClB,QAAQ,CAAC,GAAG,IAAI,WAAW,CAAC,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niqueId';\nimport { getSafeIdSelector, isNodeOfType, toArray } from 'roosterjs-content-model-dom';\nimport type { EditorCore, ParsedTable, TableCellCoordinate } from 'roosterjs-content-model-types';\n\nconst DOM_SELECTION_CSS_KEY = '_DOMSelection';\nconst TABLE_ID = 'table';\n\n/**\n * @internal\n * Remove table cell selection styles\n * @param core The EditorCore object\n */\nexport function removeTableCellsStyle(core: EditorCore) {\n core.api.setEditorStyle(core, DOM_SELECTION_CSS_KEY, '');\n}\n\n/**\n * @internal\n * Set style for table cells in the selection\n * @param core The EditorCore object\n * @param table The HTML table element\n * @param parsedTable The parsed table structure\n * @param firstCell The coordinates of the first selected cell\n * @param lastCell The coordinates of the last selected cell\n */\nexport function setTableCellsStyle(\n core: EditorCore,\n table: HTMLTableElement,\n parsedTable: ParsedTable,\n firstCell: TableCellCoordinate,\n lastCell: TableCellCoordinate\n) {\n const tableId = ensureUniqueId(table, TABLE_ID);\n const tableSelector = getSafeIdSelector(tableId);\n const tableSelectionColor = core.lifecycle.isDarkMode\n ? core.selection.tableCellSelectionBackgroundColorDark\n : core.selection.tableCellSelectionBackgroundColor;\n\n const tableSelectors =\n firstCell.row == 0 &&\n firstCell.col == 0 &&\n lastCell.row == parsedTable.length - 1 &&\n lastCell.col == (parsedTable[lastCell.row]?.length ?? 0) - 1\n ? [tableSelector, `${tableSelector} *`]\n : buildTableSelectors(parsedTable, tableSelector, table, firstCell, lastCell);\n\n core.api.setEditorStyle(\n core,\n DOM_SELECTION_CSS_KEY,\n `background-color:${tableSelectionColor}!important;`,\n tableSelectors\n );\n}\n\n/**\n * @internal\n * Build CSS selectors for table cells within the selection range\n */\nfunction buildTableSelectors(\n parsedTable: ParsedTable,\n tableSelector: string,\n table: HTMLTableElement,\n firstCell: TableCellCoordinate,\n lastCell: TableCellCoordinate\n): string[] {\n const selectors: string[] = [];\n\n let cont = 0;\n const indexes = toArray(table.childNodes)\n .filter(\n (node): node is HTMLTableSectionElement =>\n ['THEAD', 'TBODY', 'TFOOT'].indexOf(\n isNodeOfType(node, 'ELEMENT_NODE') ? node.tagName : ''\n ) > -1\n )\n .map(node => {\n const result = {\n el: node.tagName,\n start: cont,\n end: node.childNodes.length + cont,\n };\n\n cont = result.end;\n return result;\n });\n\n parsedTable.forEach((row, rowIndex) => {\n let tdCount = 0;\n\n const midElement = indexes.filter(ind => ind.start <= rowIndex && ind.end > rowIndex)[0];\n const middleElSelector = midElement ? '>' + midElement.el + '>' : '>';\n const currentRow =\n midElement && rowIndex + 1 >= midElement.start\n ? rowIndex + 1 - midElement.start\n : rowIndex + 1;\n\n for (let cellIndex = 0; cellIndex < row.length; cellIndex++) {\n const cell = row[cellIndex];\n\n if (typeof cell == 'object') {\n tdCount++;\n\n if (\n rowIndex >= firstCell.row &&\n rowIndex <= lastCell.row &&\n cellIndex >= firstCell.col &&\n cellIndex <= lastCell.col\n ) {\n const selector = `${tableSelector}${middleElSelector} tr:nth-child(${currentRow})>${cell.tagName}:nth-child(${tdCount})`;\n\n selectors.push(selector, selector + ' *');\n }\n }\n }\n });\n\n return selectors;\n}\n"]}
@@ -0,0 +1,8 @@
1
+ import type { EditorCore } from 'roosterjs-content-model-types';
2
+ /**
3
+ * @internal
4
+ * Toggle table selection styles on/off
5
+ * @param core The EditorCore object
6
+ * @param isHiding True to hide the table selection background, false to show it
7
+ */
8
+ export declare function toggleTableSelection(core: EditorCore, isHiding: boolean): void;
@@ -0,0 +1,30 @@
1
+ import { parseTableCells } from 'roosterjs-content-model-dom';
2
+ import { removeTableCellsStyle, setTableCellsStyle } from './setTableCellsStyle';
3
+ /**
4
+ * @internal
5
+ * Toggle table selection styles on/off
6
+ * @param core The EditorCore object
7
+ * @param isHiding True to hide the table selection background, false to show it
8
+ */
9
+ export function toggleTableSelection(core, isHiding) {
10
+ var selection = core.selection.selection;
11
+ if ((selection === null || selection === void 0 ? void 0 : selection.type) === 'table') {
12
+ if (isHiding) {
13
+ removeTableCellsStyle(core);
14
+ }
15
+ else {
16
+ var table = selection.table, firstColumn = selection.firstColumn, firstRow = selection.firstRow, lastColumn = selection.lastColumn, lastRow = selection.lastRow;
17
+ var parsedTable = parseTableCells(table);
18
+ var firstCell = {
19
+ row: Math.min(firstRow, lastRow),
20
+ col: Math.min(firstColumn, lastColumn),
21
+ };
22
+ var lastCell = {
23
+ row: Math.max(firstRow, lastRow),
24
+ col: Math.max(firstColumn, lastColumn),
25
+ };
26
+ setTableCellsStyle(core, table, parsedTable, firstCell, lastCell);
27
+ }
28
+ }
29
+ }
30
+ //# sourceMappingURL=toggleTableSelection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toggleTableSelection.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/coreApi/setDOMSelection/toggleTableSelection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAIjF;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAAC,IAAgB,EAAE,QAAiB;IACpE,IAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC;IAE3C,IAAI,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,IAAI,MAAK,OAAO,EAAE;QAC7B,IAAI,QAAQ,EAAE;YACV,qBAAqB,CAAC,IAAI,CAAC,CAAC;SAC/B;aAAM;YACK,IAAA,KAAK,GAAiD,SAAS,MAA1D,EAAE,WAAW,GAAoC,SAAS,YAA7C,EAAE,QAAQ,GAA0B,SAAS,SAAnC,EAAE,UAAU,GAAc,SAAS,WAAvB,EAAE,OAAO,GAAK,SAAS,QAAd,CAAe;YACxE,IAAM,WAAW,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;YAC3C,IAAM,SAAS,GAAwB;gBACnC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC;gBAChC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,UAAU,CAAC;aACzC,CAAC;YACF,IAAM,QAAQ,GAAwB;gBAClC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC;gBAChC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,UAAU,CAAC;aACzC,CAAC;YAEF,kBAAkB,CAAC,IAAI,EAAE,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;SACrE;KACJ;AACL,CAAC","sourcesContent":["import { parseTableCells } from 'roosterjs-content-model-dom';\nimport { removeTableCellsStyle, setTableCellsStyle } from './setTableCellsStyle';\n\nimport type { EditorCore, TableCellCoordinate } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n * Toggle table selection styles on/off\n * @param core The EditorCore object\n * @param isHiding True to hide the table selection background, false to show it\n */\nexport function toggleTableSelection(core: EditorCore, isHiding: boolean) {\n const selection = core.selection.selection;\n\n if (selection?.type === 'table') {\n if (isHiding) {\n removeTableCellsStyle(core);\n } else {\n const { table, firstColumn, firstRow, lastColumn, lastRow } = selection;\n const parsedTable = parseTableCells(table);\n const firstCell: TableCellCoordinate = {\n row: Math.min(firstRow, lastRow),\n col: Math.min(firstColumn, lastColumn),\n };\n const lastCell: TableCellCoordinate = {\n row: Math.max(firstRow, lastRow),\n col: Math.max(firstColumn, lastColumn),\n };\n\n setTableCellsStyle(core, table, parsedTable, firstCell, lastCell);\n }\n }\n}\n"]}
@@ -1,5 +1,6 @@
1
1
  import { iterateSelections, moveChildNodes } from 'roosterjs-content-model-dom';
2
2
  import { toggleCaret } from '../setDOMSelection/toggleCaret';
3
+ import { toggleTableSelection } from '../setDOMSelection/toggleTableSelection';
3
4
  /**
4
5
  * @internal
5
6
  * Switch the Shadow Edit mode of editor On/Off
@@ -23,11 +24,13 @@ export var switchShadowEdit = function (editorCore, isOn) {
23
24
  core.cache.cachedModel = model;
24
25
  }
25
26
  toggleCaret(core, true /* hide */);
27
+ toggleTableSelection(core, true /* hide */);
26
28
  core.lifecycle.shadowEditFragment = fragment;
27
29
  }
28
30
  else {
29
31
  core.lifecycle.shadowEditFragment = null;
30
32
  toggleCaret(core, false /* hide */);
33
+ toggleTableSelection(core, false /* hide */);
31
34
  core.api.triggerEvent(core, {
32
35
  eventType: 'leavingShadowEdit',
33
36
  }, false /*broadcast*/);
@@ -1 +1 @@
1
- {"version":3,"file":"switchShadowEdit.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/coreApi/switchShadowEdit/switchShadowEdit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAChF,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAG7D;;;;;GAKG;AACH,MAAM,CAAC,IAAM,gBAAgB,GAAqB,UAAC,UAAU,EAAE,IAAI;IAC/D,IAAM,IAAI,GAAG,UAAU,CAAC;IAExB,IAAI,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,kBAAkB,EAAE;QAC7C,IAAI,IAAI,EAAE;YACN,IAAM,KAAK,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;YACjF,IAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,sBAAsB,EAAE,CAAC;YACzE,IAAM,UAAU,GAAG,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAE7D,cAAc,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;YAErC,IAAI,CAAC,GAAG,CAAC,YAAY,CACjB,IAAI,EACJ;gBACI,SAAS,EAAE,mBAAmB;aACjC,EACD,KAAK,CAAC,aAAa,CACtB,CAAC;YAEF,oIAAoI;YACpI,6DAA6D;YAC7D,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,IAAI,KAAK,EAAE;gBAClC,IAAI,CAAC,KAAK,CAAC,WAAW,GAAG,KAAK,CAAC;aAClC;YAED,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;YAEnC,IAAI,CAAC,SAAS,CAAC,kBAAkB,GAAG,QAAQ,CAAC;SAChD;aAAM;YACH,IAAI,CAAC,SAAS,CAAC,kBAAkB,GAAG,IAAI,CAAC;YAEzC,WAAW,CAAC,IAAI,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;YAEpC,IAAI,CAAC,GAAG,CAAC,YAAY,CACjB,IAAI,EACJ;gBACI,SAAS,EAAE,mBAAmB;aACjC,EACD,KAAK,CAAC,aAAa,CACtB,CAAC;YAEF,IAAI,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE;gBACxB,iDAAiD;gBACjD,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,cAAO,CAAC,CAAC,CAAC;gBAEpD,IAAI,CAAC,GAAG,CAAC,eAAe,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE;oBACnD,eAAe,EAAE,IAAI,EAAE,qGAAqG;iBAC/H,CAAC,CAAC;aACN;SACJ;KACJ;AACL,CAAC,CAAC","sourcesContent":["import { iterateSelections, moveChildNodes } from 'roosterjs-content-model-dom';\nimport { toggleCaret } from '../setDOMSelection/toggleCaret';\nimport type { SwitchShadowEdit } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n * Switch the Shadow Edit mode of editor On/Off\n * @param editorCore The EditorCore object\n * @param isOn True to switch On, False to switch Off\n */\nexport const switchShadowEdit: SwitchShadowEdit = (editorCore, isOn): void => {\n const core = editorCore;\n\n if (isOn != !!core.lifecycle.shadowEditFragment) {\n if (isOn) {\n const model = !core.cache.cachedModel ? core.api.createContentModel(core) : null;\n const fragment = core.logicalRoot.ownerDocument.createDocumentFragment();\n const clonedRoot = core.logicalRoot.cloneNode(true /*deep*/);\n\n moveChildNodes(fragment, clonedRoot);\n\n core.api.triggerEvent(\n core,\n {\n eventType: 'enteredShadowEdit',\n },\n false /*broadcast*/\n );\n\n // This need to be done after EnteredShadowEdit event is triggered since EnteredShadowEdit event will cause a SelectionChanged event\n // if current selection is table selection or image selection\n if (!core.cache.cachedModel && model) {\n core.cache.cachedModel = model;\n }\n\n toggleCaret(core, true /* hide */);\n\n core.lifecycle.shadowEditFragment = fragment;\n } else {\n core.lifecycle.shadowEditFragment = null;\n\n toggleCaret(core, false /* hide */);\n\n core.api.triggerEvent(\n core,\n {\n eventType: 'leavingShadowEdit',\n },\n false /*broadcast*/\n );\n\n if (core.cache.cachedModel) {\n // Force clear cached element from selected block\n iterateSelections(core.cache.cachedModel, () => {});\n\n core.api.setContentModel(core, core.cache.cachedModel, {\n ignoreSelection: true, // Do not set focus and selection when quit shadow edit, focus may remain in UI control (picker, ...)\n });\n }\n }\n }\n};\n"]}
1
+ {"version":3,"file":"switchShadowEdit.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/coreApi/switchShadowEdit/switchShadowEdit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAChF,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAC;AAG/E;;;;;GAKG;AACH,MAAM,CAAC,IAAM,gBAAgB,GAAqB,UAAC,UAAU,EAAE,IAAI;IAC/D,IAAM,IAAI,GAAG,UAAU,CAAC;IAExB,IAAI,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,kBAAkB,EAAE;QAC7C,IAAI,IAAI,EAAE;YACN,IAAM,KAAK,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,kBAAkB,C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C,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE;oBACnD,eAAe,EAAE,IAAI,EAAE,qGAAqG;iBAC/H,CAAC,CAAC;aACN;SACJ;KACJ;AACL,CAAC,CAAC","sourcesContent":["import { iterateSelections, moveChildNodes } from 'roosterjs-content-model-dom';\nimport { toggleCaret } from '../setDOMSelection/toggleCaret';\nimport { toggleTableSelection } from '../setDOMSelection/toggleTableSelection';\nimport type { SwitchShadowEdit } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n * Switch the Shadow Edit mode of editor On/Off\n * @param editorCore The EditorCore object\n * @param isOn True to switch On, False to switch Off\n */\nexport const switchShadowEdit: SwitchShadowEdit = (editorCore, isOn): void => {\n const core = editorCore;\n\n if (isOn != !!core.lifecycle.shadowEditFragment) {\n if (isOn) {\n const model = !core.cache.cachedModel ? core.api.createContentModel(core) : null;\n const fragment = core.logicalRoot.ownerDocument.createDocumentFragment();\n const clonedRoot = core.logicalRoot.cloneNode(true /*deep*/);\n\n moveChildNodes(fragment, clonedRoot);\n\n core.api.triggerEvent(\n core,\n {\n eventType: 'enteredShadowEdit',\n },\n false /*broadcast*/\n );\n\n // This need to be done after EnteredShadowEdit event is triggered since EnteredShadowEdit event will cause a SelectionChanged event\n // if current selection is table selection or image selection\n if (!core.cache.cachedModel && model) {\n core.cache.cachedModel = model;\n }\n\n toggleCaret(core, true /* hide */);\n toggleTableSelection(core, true /* hide */);\n\n core.lifecycle.shadowEditFragment = fragment;\n } else {\n core.lifecycle.shadowEditFragment = null;\n\n toggleCaret(core, false /* hide */);\n toggleTableSelection(core, false /* hide */);\n\n core.api.triggerEvent(\n core,\n {\n eventType: 'leavingShadowEdit',\n },\n false /*broadcast*/\n );\n\n if (core.cache.cachedModel) {\n // Force clear cached element from selected block\n iterateSelections(core.cache.cachedModel, () => {});\n\n core.api.setContentModel(core, core.cache.cachedModel, {\n ignoreSelection: true, // Do not set focus and selection when quit shadow edit, focus may remain in UI control (picker, ...)\n });\n }\n }\n }\n};\n"]}
@@ -453,6 +453,9 @@ var SelectionPlugin = /** @class */ (function () {
453
453
  break;
454
454
  }
455
455
  }
456
+ if (this.editor.getSnapshotsManager().hasNewContent) {
457
+ this.editor.takeSnapshot();
458
+ }
456
459
  }
457
460
  else {
458
461
  this.state.tableSelection = null;