roosterjs-content-model-core 9.56.0 → 9.58.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 (71) hide show
  1. package/README.md +8 -0
  2. package/lib/command/createModelFromHtml/createDomToModelContextForSanitizing.d.ts +2 -2
  3. package/lib/command/createModelFromHtml/createDomToModelContextForSanitizing.js +2 -2
  4. package/lib/command/createModelFromHtml/createDomToModelContextForSanitizing.js.map +1 -1
  5. package/lib/command/paste/mergePasteContent.js +16 -5
  6. package/lib/command/paste/mergePasteContent.js.map +1 -1
  7. package/lib/command/paste/paste.js +4 -5
  8. package/lib/command/paste/paste.js.map +1 -1
  9. package/lib/coreApi/formatContentModel/formatContentModel.js +1 -1
  10. package/lib/coreApi/formatContentModel/formatContentModel.js.map +1 -1
  11. package/lib/coreApi/setDOMSelection/setTableCellsStyle.d.ts +4 -0
  12. package/lib/coreApi/setDOMSelection/setTableCellsStyle.js +7 -4
  13. package/lib/coreApi/setDOMSelection/setTableCellsStyle.js.map +1 -1
  14. package/lib/coreApi/setDOMSelection/toggleCaret.d.ts +4 -0
  15. package/lib/coreApi/setDOMSelection/toggleCaret.js +6 -3
  16. package/lib/coreApi/setDOMSelection/toggleCaret.js.map +1 -1
  17. package/lib/corePlugin/selection/SelectionPlugin.js +61 -10
  18. package/lib/corePlugin/selection/SelectionPlugin.js.map +1 -1
  19. package/lib/editor/Editor.d.ts +5 -0
  20. package/lib/editor/Editor.js +7 -0
  21. package/lib/editor/Editor.js.map +1 -1
  22. package/lib-amd/command/createModelFromHtml/createDomToModelContextForSanitizing.d.ts +2 -2
  23. package/lib-amd/command/createModelFromHtml/createDomToModelContextForSanitizing.js +2 -2
  24. package/lib-amd/command/createModelFromHtml/createDomToModelContextForSanitizing.js.map +1 -1
  25. package/lib-amd/command/paste/mergePasteContent.js +16 -5
  26. package/lib-amd/command/paste/mergePasteContent.js.map +1 -1
  27. package/lib-amd/command/paste/paste.js +5 -5
  28. package/lib-amd/command/paste/paste.js.map +1 -1
  29. package/lib-amd/coreApi/formatContentModel/formatContentModel.js +1 -1
  30. package/lib-amd/coreApi/formatContentModel/formatContentModel.js.map +1 -1
  31. package/lib-amd/coreApi/setDOMSelection/setTableCellsStyle.d.ts +4 -0
  32. package/lib-amd/coreApi/setDOMSelection/setTableCellsStyle.js +7 -4
  33. package/lib-amd/coreApi/setDOMSelection/setTableCellsStyle.js.map +1 -1
  34. package/lib-amd/coreApi/setDOMSelection/toggleCaret.d.ts +4 -0
  35. package/lib-amd/coreApi/setDOMSelection/toggleCaret.js +6 -3
  36. package/lib-amd/coreApi/setDOMSelection/toggleCaret.js.map +1 -1
  37. package/lib-amd/corePlugin/selection/SelectionPlugin.js +60 -11
  38. package/lib-amd/corePlugin/selection/SelectionPlugin.js.map +1 -1
  39. package/lib-amd/editor/Editor.d.ts +5 -0
  40. package/lib-amd/editor/Editor.js +7 -0
  41. package/lib-amd/editor/Editor.js.map +1 -1
  42. package/lib-mjs/command/createModelFromHtml/createDomToModelContextForSanitizing.d.ts +2 -2
  43. package/lib-mjs/command/createModelFromHtml/createDomToModelContextForSanitizing.js +2 -2
  44. package/lib-mjs/command/createModelFromHtml/createDomToModelContextForSanitizing.js.map +1 -1
  45. package/lib-mjs/command/paste/mergePasteContent.js +16 -5
  46. package/lib-mjs/command/paste/mergePasteContent.js.map +1 -1
  47. package/lib-mjs/command/paste/paste.js +4 -5
  48. package/lib-mjs/command/paste/paste.js.map +1 -1
  49. package/lib-mjs/coreApi/formatContentModel/formatContentModel.js +1 -1
  50. package/lib-mjs/coreApi/formatContentModel/formatContentModel.js.map +1 -1
  51. package/lib-mjs/coreApi/setDOMSelection/setTableCellsStyle.d.ts +4 -0
  52. package/lib-mjs/coreApi/setDOMSelection/setTableCellsStyle.js +4 -1
  53. package/lib-mjs/coreApi/setDOMSelection/setTableCellsStyle.js.map +1 -1
  54. package/lib-mjs/coreApi/setDOMSelection/toggleCaret.d.ts +4 -0
  55. package/lib-mjs/coreApi/setDOMSelection/toggleCaret.js +4 -1
  56. package/lib-mjs/coreApi/setDOMSelection/toggleCaret.js.map +1 -1
  57. package/lib-mjs/corePlugin/selection/SelectionPlugin.js +62 -11
  58. package/lib-mjs/corePlugin/selection/SelectionPlugin.js.map +1 -1
  59. package/lib-mjs/editor/Editor.d.ts +5 -0
  60. package/lib-mjs/editor/Editor.js +7 -0
  61. package/lib-mjs/editor/Editor.js.map +1 -1
  62. package/package.json +3 -3
  63. package/lib/command/paste/createPasteFragment.d.ts +0 -5
  64. package/lib/command/paste/createPasteFragment.js +0 -79
  65. package/lib/command/paste/createPasteFragment.js.map +0 -1
  66. package/lib-amd/command/paste/createPasteFragment.d.ts +0 -5
  67. package/lib-amd/command/paste/createPasteFragment.js +0 -80
  68. package/lib-amd/command/paste/createPasteFragment.js.map +0 -1
  69. package/lib-mjs/command/paste/createPasteFragment.d.ts +0 -5
  70. package/lib-mjs/command/paste/createPasteFragment.js +0 -75
  71. package/lib-mjs/command/paste/createPasteFragment.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"paste.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/command/paste/paste.ts"],"names":[],"mappings":";;;;IAcA;;;;;OAKG;IACH,SAAgB,KAAK,CACjB,MAAe,EACf,aAA4B,EAC5B,iBAA+C;;QAA/C,kCAAA,EAAA,4BAA+C;QAE/C,MAAM,CAAC,KAAK,EAAE,CAAC;QACf,IAAI,YAAY,GAAG,KAAK,CAAC;QAEzB,IAAI,CAAC,aAAa,CAAC,gBAAgB,EAAE;YACjC,YAAY,GAAG,IAAI,CAAC;YAEpB,MAAM,CAAC,kBAAkB,CAAC,UAAA,KAAK;gBAC3B,aAAa,CAAC,gBAAgB,GAAG,IAAA,gDAAkB,EAAC,KAAK,CAAC,CAAC;gBAE3D,OAAO,KAAK,CAAC;YACjB,CAAC,CAAC,CAAC;SACN;QAED,uBAAuB;QACvB,IAAM,UAAU,GAAG,MAAM,CAAC,aAAa,E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CAAC,IAAI,CAAC;IACpD,CAAC","sourcesContent":["import { cleanHtmlComments } from './cleanHtmlComments';\nimport { cloneModelForPaste } from 'roosterjs-content-model-dom';\nimport { convertInlineCss } from '../createModelFromHtml/convertInlineCss';\nimport { createPasteFragment } from './createPasteFragment';\nimport { generatePasteOptionFromPlugins } from './generatePasteOptionFromPlugins';\nimport { mergePasteContent } from './mergePasteContent';\nimport { retrieveHtmlInfo } from './retrieveHtmlInfo';\nimport type {\n PasteTypeOrGetter,\n ClipboardData,\n IEditor,\n DOMCreator,\n} from 'roosterjs-content-model-types';\n\n/**\n * Paste into editor using a clipboardData object\n * @param editor The Editor object.\n * @param clipboardData Clipboard data retrieved from clipboard\n * @param pasteTypeOrGetter Type of content to paste or function that returns the Paste Type to use based on the document and the clipboard Data. @default normal\n */\nexport function paste(\n editor: IEditor,\n clipboardData: ClipboardData,\n pasteTypeOrGetter: PasteTypeOrGetter = 'normal'\n) {\n editor.focus();\n let isFirstPaste = false;\n\n if (!clipboardData.modelBeforePaste) {\n isFirstPaste = true;\n\n editor.formatContentModel(model => {\n clipboardData.modelBeforePaste = cloneModelForPaste(model);\n\n return false;\n });\n }\n\n // 1. Prepare variables\n const domCreator = editor.getDOMCreator();\n if (!domCreator.isBypassed && clipboardData.rawHtml) {\n clipboardData.rawHtml = cleanHtmlComments(clipboardData.rawHtml);\n }\n const doc = createDOMFromHtml(clipboardData.rawHtml, domCreator);\n const pasteType =\n typeof pasteTypeOrGetter == 'function'\n ? pasteTypeOrGetter(doc, clipboardData)\n : pasteTypeOrGetter;\n\n // 2. Handle HTML from clipboard\n const htmlFromClipboard = retrieveHtmlInfo(doc, clipboardData);\n\n // 3. Create target fragment\n const sourceFragment = createPasteFragment(\n editor.getDocument(),\n clipboardData,\n pasteType,\n (clipboardData.rawHtml == clipboardData.html\n ? doc\n : createDOMFromHtml(clipboardData.html, domCreator)\n )?.body\n );\n\n // 4. Trigger BeforePaste event to allow plugins modify the fragment\n const eventResult = generatePasteOptionFromPlugins(\n editor,\n clipboardData,\n sourceFragment,\n htmlFromClipboard,\n pasteType\n );\n\n // 5. Convert global CSS to inline CSS\n convertInlineCss(eventResult.fragment, htmlFromClipboard.globalCssRules);\n\n // 6. Merge pasted content into main Content Model\n mergePasteContent(editor, eventResult, isFirstPaste);\n}\n\nfunction createDOMFromHtml(\n html: string | null | undefined,\n domCreator: DOMCreator\n): Document | null {\n return html ? domCreator.htmlToDOM(html) : null;\n}\n"]}
1
+ {"version":3,"file":"paste.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/command/paste/paste.ts"],"names":[],"mappings":";;;;IAaA;;;;;OAKG;IACH,SAAgB,KAAK,CACjB,MAAe,EACf,aAA4B,EAC5B,iBAA+C;;QAA/C,kCAAA,EAAA,4BAA+C;QAE/C,MAAM,CAAC,KAAK,EAAE,CAAC;QACf,IAAI,YAAY,GAAG,KAAK,CAAC;QAEzB,IAAI,CAAC,aAAa,CAAC,gBAAgB,EAAE;YACjC,YAAY,GAAG,IAAI,CAAC;YAEpB,MAAM,CAAC,kBAAkB,CAAC,UAAA,KAAK;gBAC3B,aAAa,CAAC,gBAAgB,GAAG,IAAA,gDAAkB,EAAC,KAAK,CAAC,CAAC;gBAE3D,OAAO,KAAK,CAAC;YACjB,CAAC,CAAC,CAAC;SACN;QAED,uBAAuB;QACvB,IAAM,UAAU,GAAG,MAAM,CAAC,aAAa,EAAE,CAAC;QAC1C,IAAI,CAAC,UAAU,CAAC,UAAU,IAAI,aAAa,CAAC,OAAO,EAAE;YACjD,aAAa,CAAC,OAAO,GAAG,IAAA,qCAAiB,EAAC,aAAa,CAAC,OAAO,CAAC,CAAC;SACpE;QACD,IAAM,GAAG,GAAG,iBAAiB,CAAC,aAAa,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;QAEjE,gCAAgC;QAChC,IAAM,iBAAiB,GAAG,IAAA,mCAAgB,EAAC,GAAG,EAAE,aAAa,CAAC,CAAC;QAE/D,IAAM,SAAS,GACX,OAAO,iBAAiB,IAAI,UAAU;YAClC,CAAC,CAAC,iBAAiB,CACb,GAAG,EACH,aAAa,EACb,MAAM,CAAC,cAAc,EAAE,EACvB,iBAAiB,CAAC,QAAQ,CAC7B;YACH,CAAC,CAAC,iBAAiB,CAAC;QAE5B,4BAA4B;QAC5B,IAAM,cAAc,GAAG,IAAA,iDAAmB,EACtC,MAAM,CAAC,WAAW,EAAE,EACpB,aAAa,EACb,SAAS,EACT,MAAA,CAAC,aAAa,CAAC,OAAO,IAAI,aAAa,CAAC,IAAI;YACxC,CAAC,CAAC,GAAG;YACL,CAAC,CAAC,iBAAiB,CAAC,aAAa,CAAC,IAAI,EAAE,UAAU,CAAC,CACtD,0CAAE,IAAI,CACV,CAAC;QAEF,oEAAoE;QACpE,IAAM,WAAW,GAAG,IAAA,+DAA8B,EAC9C,MAAM,EACN,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,SAAS,CACZ,CAAC;QAEF,sCAAsC;QACtC,IAAA,mCAAgB,EAAC,WAAW,CAAC,QAAQ,EAAE,iBAAiB,CAAC,cAAc,CAAC,CAAC;QAEzE,kDAAkD;QAClD,IAAA,qCAAiB,EAAC,MAAM,EAAE,WAAW,EAAE,YAAY,CAAC,CAAC;IACzD,CAAC;IA/DD,sBA+DC;IAED,SAAS,iBAAiB,CACtB,IAA+B,EAC/B,UAAsB;QAEtB,OAAO,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACpD,CAAC","sourcesContent":["import { cleanHtmlComments } from './cleanHtmlComments';\nimport { cloneModelForPaste, createPasteFragment } from 'roosterjs-content-model-dom';\nimport { convertInlineCss } from '../createModelFromHtml/convertInlineCss';\nimport { generatePasteOptionFromPlugins } from './generatePasteOptionFromPlugins';\nimport { mergePasteContent } from './mergePasteContent';\nimport { retrieveHtmlInfo } from './retrieveHtmlInfo';\nimport type {\n PasteTypeOrGetter,\n ClipboardData,\n IEditor,\n DOMCreator,\n} from 'roosterjs-content-model-types';\n\n/**\n * Paste into editor using a clipboardData object\n * @param editor The Editor object.\n * @param clipboardData Clipboard data retrieved from clipboard\n * @param pasteTypeOrGetter Type of content to paste or function that returns the Paste Type to use based on the document and the clipboard Data. @default normal\n */\nexport function paste(\n editor: IEditor,\n clipboardData: ClipboardData,\n pasteTypeOrGetter: PasteTypeOrGetter = 'normal'\n) {\n editor.focus();\n let isFirstPaste = false;\n\n if (!clipboardData.modelBeforePaste) {\n isFirstPaste = true;\n\n editor.formatContentModel(model => {\n clipboardData.modelBeforePaste = cloneModelForPaste(model);\n\n return false;\n });\n }\n\n // 1. Prepare variables\n const domCreator = editor.getDOMCreator();\n if (!domCreator.isBypassed && clipboardData.rawHtml) {\n clipboardData.rawHtml = cleanHtmlComments(clipboardData.rawHtml);\n }\n const doc = createDOMFromHtml(clipboardData.rawHtml, domCreator);\n\n // 2. Handle HTML from clipboard\n const htmlFromClipboard = retrieveHtmlInfo(doc, clipboardData);\n\n const pasteType =\n typeof pasteTypeOrGetter == 'function'\n ? pasteTypeOrGetter(\n doc,\n clipboardData,\n editor.getEnvironment(),\n htmlFromClipboard.metadata\n )\n : pasteTypeOrGetter;\n\n // 3. Create target fragment\n const sourceFragment = createPasteFragment(\n editor.getDocument(),\n clipboardData,\n pasteType,\n (clipboardData.rawHtml == clipboardData.html\n ? doc\n : createDOMFromHtml(clipboardData.html, domCreator)\n )?.body\n );\n\n // 4. Trigger BeforePaste event to allow plugins modify the fragment\n const eventResult = generatePasteOptionFromPlugins(\n editor,\n clipboardData,\n sourceFragment,\n htmlFromClipboard,\n pasteType\n );\n\n // 5. Convert global CSS to inline CSS\n convertInlineCss(eventResult.fragment, htmlFromClipboard.globalCssRules);\n\n // 6. Merge pasted content into main Content Model\n mergePasteContent(editor, eventResult, isFirstPaste);\n}\n\nfunction createDOMFromHtml(\n html: string | null | undefined,\n domCreator: DOMCreator\n): Document | null {\n return html ? domCreator.htmlToDOM(html) : null;\n}\n"]}
@@ -38,7 +38,7 @@ define(["require", "exports", "tslib", "roosterjs-content-model-dom", "./scrollC
38
38
  try {
39
39
  handleImages(core, context);
40
40
  selection =
41
- (_a = core.api.setContentModel(core, model, hasFocus ? undefined : { ignoreSelection: true }, // If editor did not have focus before format, do not set focus after format
41
+ (_a = core.api.setContentModel(core, model, hasFocus && !(options === null || options === void 0 ? void 0 : options.skipDOMSelection) ? undefined : { ignoreSelection: true }, // If editor did not have focus before format, do not set focus after format
42
42
  onNodeCreated)) !== null && _a !== void 0 ? _a : undefined;
43
43
  handlePendingFormat(core, context, selection);
44
44
  if (scroll && ((selection === null || selection === void 0 ? void 0 : selection.type) == 'range' || (selection === null || selection === void 0 ? void 0 : selection.type) == 'image')) {
@@ -1 +1 @@
1
- {"version":3,"file":"formatContentModel.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/coreApi/formatContentModel/formatContentModel.ts"],"names":[],"mappings":";;;;IAWA;;;;;;;;;OASG;IACI,IAAM,kBAAkB,GAAuB,UAClD,IAAI,EACJ,SAAS,EACT,OAAO,EACP,iBAAiB;;QAEX,IAAA,KACF,OAAO,IAAI,EAAE,EADT,aAAa,mBAAA,EAAE,QAAQ,cAAA,EAAE,iBAAiB,uBAAA,EAAuB,MAAM,yBAC9D,CAAC;QAClB,IAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,kBAAkB,CAAC,IAAI,EAAE,iBAAiB,EAAE,iBAAiB,CAAC,CAAC;QACtF,IAAM,OAAO,GAA8B;YACvC,WAAW,EAAE,EAAE;YACf,eAAe,EAAE,EAAE;YACnB,QAAQ,UAAA;YACR,SAAS,EAAE,EAAE;YACb,gBAAgB,EAAE,IAAI,CAAC,KAAK,CAAC,YAAY;SAC5C,CAAC;QAEF,IAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC;QAE3C,IAAM,OAAO,GAAG,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAClC,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AAC;IAChB,CAAC","sourcesContent":["import { ChangeSource } from 'roosterjs-content-model-dom';\nimport { scrollCaretIntoView } from './scrollCaretIntoView';\nimport type {\n ChangedEntity,\n ContentChangedEvent,\n DOMSelection,\n FormatContentModel,\n FormatContentModelContext,\n EditorCore,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n * The general API to do format change with Content Model\n * It will grab a Content Model for current editor content, and invoke a callback function\n * to do format change. Then according to the return value, write back the modified content model into editor.\n * If there is cached model, it will be used and updated.\n * @param core The EditorCore object\n * @param formatter Formatter function, see ContentModelFormatter\n * @param options More options, see FormatContentModelOptions\n */\nexport const formatContentModel: FormatContentModel = (\n core,\n formatter,\n options,\n domToModelOptions\n) => {\n const { onNodeCreated, rawEvent, selectionOverride, scrollCaretIntoView: scroll } =\n options || {};\n const model = core.api.createContentModel(core, domToModelOptions, selectionOverride);\n const context: FormatContentModelContext = {\n newEntities: [],\n deletedEntities: [],\n rawEvent,\n newImages: [],\n paragraphIndexer: core.cache.paragraphMap,\n };\n\n const hasFocus = core.domHelper.hasFocus();\n\n const changed = formatter(model, context);\n const { skipUndoSnapshot, clearModelCache, entityStates, canUndoByBackspace } = context;\n\n if (changed) {\n const isNested = core.undo.isNested;\n const shouldAddSnapshot =\n (!skipUndoSnapshot || skipUndoSnapshot == 'DoNotSkip') && !isNested;\n const shouldMarkNewContent =\n (skipUndoSnapshot === true || skipUndoSnapshot == 'MarkNewContent') && !isNested;\n let selection: DOMSelection | undefined;\n\n if (shouldAddSnapshot) {\n core.undo.isNested = true;\n\n core.api.addUndoSnapshot(core, !!canUndoByBackspace, entityStates);\n }\n\n try {\n handleImages(core, context);\n\n selection =\n core.api.setContentModel(\n core,\n model,\n hasFocus ? undefined : { ignoreSelection: true }, // If editor did not have focus before format, do not set focus after format\n onNodeCreated\n ) ?? undefined;\n\n handlePendingFormat(core, context, selection);\n\n if (scroll && (selection?.type == 'range' || selection?.type == 'image')) {\n scrollCaretIntoView(core, selection);\n }\n\n const eventData: ContentChangedEvent = {\n eventType: 'contentChanged',\n contentModel: clearModelCache ? undefined : model,\n selection: clearModelCache ? undefined : selection,\n source: options?.changeSource || ChangeSource.Format,\n data: options?.getChangeData?.(),\n formatApiName: options?.apiName,\n changedEntities: getChangedEntities(context, rawEvent),\n skipUndo:\n !(shouldMarkNewContent || shouldAddSnapshot) ||\n options?.changeSource == ChangeSource.Keyboard, // Keyboard changes will be handled separately in undo plugin, so we need to skip handling it again\n };\n\n core.api.triggerEvent(core, eventData, true /*broadcast*/);\n\n if (canUndoByBackspace && selection?.type == 'range') {\n core.undo.autoCompleteInsertPoint = {\n node: selection.range.startContainer,\n offset: selection.range.startOffset,\n };\n }\n\n if (shouldAddSnapshot) {\n core.api.addUndoSnapshot(core, false /*canUndoByBackspace*/, entityStates);\n }\n\n if (shouldMarkNewContent) {\n core.undo.snapshotsManager.hasNewContent = true;\n }\n } finally {\n if (!isNested) {\n core.undo.isNested = false;\n }\n }\n } else {\n if (clearModelCache) {\n core.cache.cachedModel = undefined;\n core.cache.cachedSelection = undefined;\n }\n\n handlePendingFormat(core, context, core.api.getDOMSelection(core));\n }\n\n if (context.announceData) {\n core.api.announce(core, context.announceData);\n }\n};\n\nfunction handleImages(core: EditorCore, context: FormatContentModelContext) {\n if (context.newImages.length > 0) {\n const width = core.domHelper.getClientWidth();\n const minMaxImageSize = 10;\n const maxWidth = Math.max(width, minMaxImageSize);\n context.newImages.forEach(image => {\n image.format.maxWidth = `${maxWidth}px`;\n });\n }\n}\n\nfunction handlePendingFormat(\n core: EditorCore,\n context: FormatContentModelContext,\n selection?: DOMSelection | null\n) {\n const pendingFormat =\n context.newPendingFormat == 'preserve'\n ? core.format.pendingFormat?.format\n : context.newPendingFormat;\n const pendingParagraphFormat =\n context.newPendingParagraphFormat == 'preserve'\n ? core.format.pendingFormat?.paragraphFormat\n : context.newPendingParagraphFormat;\n\n if (\n (pendingFormat || pendingParagraphFormat) &&\n selection?.type == 'range' &&\n selection.range.collapsed\n ) {\n core.format.pendingFormat = {\n format: pendingFormat ? { ...pendingFormat } : undefined,\n paragraphFormat: pendingParagraphFormat ? { ...pendingParagraphFormat } : undefined,\n insertPoint: {\n node: selection.range.startContainer,\n offset: selection.range.startOffset,\n },\n };\n }\n}\n\nfunction getChangedEntities(\n context: FormatContentModelContext,\n rawEvent?: Event\n): ChangedEntity[] | undefined {\n return context.autoDetectChangedEntities\n ? undefined\n : context.newEntities\n .map(\n (entity): ChangedEntity => ({\n entity,\n operation: 'newEntity',\n rawEvent,\n })\n )\n .concat(\n context.deletedEntities.map(entry => ({\n entity: entry.entity,\n operation: entry.operation,\n rawEvent,\n }))\n );\n}\n"]}
1
+ {"version":3,"file":"formatContentModel.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/coreApi/formatContentModel/formatContentModel.ts"],"names":[],"mappings":";;;;IAWA;;;;;;;;;OASG;IACI,IAAM,kBAAkB,GAAuB,UAClD,IAAI,EACJ,SAAS,EACT,OAAO,EACP,iBAAiB;;QAEX,IAAA,KACF,OAAO,IAAI,EAAE,EADT,aAAa,mBAAA,EAAE,QAAQ,cAAA,EAAE,iBAAiB,uBAAA,EAAuB,MAAM,yBAC9D,CAAC;QAClB,IAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,kBAAkB,CAAC,IAAI,EAAE,iBAAiB,EAAE,iBAAiB,CAAC,CAAC;QACtF,IAAM,OAAO,GAA8B;YACvC,WAAW,EAAE,EAAE;YACf,eAAe,EAAE,EAAE;YACnB,QAAQ,UAAA;YACR,SAAS,EAAE,EAAE;YACb,gBAAgB,EAAE,IAAI,CAAC,KAAK,CAAC,YAAY;SAC5C,CAAC;QAEF,IAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC;QAE3C,IAAM,OAAO,GAAG,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAClC,IAAA,gBAAgB,GAAwD,OAAO,iBAA/D,EAAE,eAAe,GAAuC,OAAO,g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,CACN,CAAC;IAChB,CAAC","sourcesContent":["import { ChangeSource } from 'roosterjs-content-model-dom';\nimport { scrollCaretIntoView } from './scrollCaretIntoView';\nimport type {\n ChangedEntity,\n ContentChangedEvent,\n DOMSelection,\n FormatContentModel,\n FormatContentModelContext,\n EditorCore,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n * The general API to do format change with Content Model\n * It will grab a Content Model for current editor content, and invoke a callback function\n * to do format change. Then according to the return value, write back the modified content model into editor.\n * If there is cached model, it will be used and updated.\n * @param core The EditorCore object\n * @param formatter Formatter function, see ContentModelFormatter\n * @param options More options, see FormatContentModelOptions\n */\nexport const formatContentModel: FormatContentModel = (\n core,\n formatter,\n options,\n domToModelOptions\n) => {\n const { onNodeCreated, rawEvent, selectionOverride, scrollCaretIntoView: scroll } =\n options || {};\n const model = core.api.createContentModel(core, domToModelOptions, selectionOverride);\n const context: FormatContentModelContext = {\n newEntities: [],\n deletedEntities: [],\n rawEvent,\n newImages: [],\n paragraphIndexer: core.cache.paragraphMap,\n };\n\n const hasFocus = core.domHelper.hasFocus();\n\n const changed = formatter(model, context);\n const { skipUndoSnapshot, clearModelCache, entityStates, canUndoByBackspace } = context;\n\n if (changed) {\n const isNested = core.undo.isNested;\n const shouldAddSnapshot =\n (!skipUndoSnapshot || skipUndoSnapshot == 'DoNotSkip') && !isNested;\n const shouldMarkNewContent =\n (skipUndoSnapshot === true || skipUndoSnapshot == 'MarkNewContent') && !isNested;\n let selection: DOMSelection | undefined;\n\n if (shouldAddSnapshot) {\n core.undo.isNested = true;\n\n core.api.addUndoSnapshot(core, !!canUndoByBackspace, entityStates);\n }\n\n try {\n handleImages(core, context);\n\n selection =\n core.api.setContentModel(\n core,\n model,\n hasFocus && !options?.skipDOMSelection ? undefined : { ignoreSelection: true }, // If editor did not have focus before format, do not set focus after format\n onNodeCreated\n ) ?? undefined;\n\n handlePendingFormat(core, context, selection);\n\n if (scroll && (selection?.type == 'range' || selection?.type == 'image')) {\n scrollCaretIntoView(core, selection);\n }\n\n const eventData: ContentChangedEvent = {\n eventType: 'contentChanged',\n contentModel: clearModelCache ? undefined : model,\n selection: clearModelCache ? undefined : selection,\n source: options?.changeSource || ChangeSource.Format,\n data: options?.getChangeData?.(),\n formatApiName: options?.apiName,\n changedEntities: getChangedEntities(context, rawEvent),\n skipUndo:\n !(shouldMarkNewContent || shouldAddSnapshot) ||\n options?.changeSource == ChangeSource.Keyboard, // Keyboard changes will be handled separately in undo plugin, so we need to skip handling it again\n };\n\n core.api.triggerEvent(core, eventData, true /*broadcast*/);\n\n if (canUndoByBackspace && selection?.type == 'range') {\n core.undo.autoCompleteInsertPoint = {\n node: selection.range.startContainer,\n offset: selection.range.startOffset,\n };\n }\n\n if (shouldAddSnapshot) {\n core.api.addUndoSnapshot(core, false /*canUndoByBackspace*/, entityStates);\n }\n\n if (shouldMarkNewContent) {\n core.undo.snapshotsManager.hasNewContent = true;\n }\n } finally {\n if (!isNested) {\n core.undo.isNested = false;\n }\n }\n } else {\n if (clearModelCache) {\n core.cache.cachedModel = undefined;\n core.cache.cachedSelection = undefined;\n }\n\n handlePendingFormat(core, context, core.api.getDOMSelection(core));\n }\n\n if (context.announceData) {\n core.api.announce(core, context.announceData);\n }\n};\n\nfunction handleImages(core: EditorCore, context: FormatContentModelContext) {\n if (context.newImages.length > 0) {\n const width = core.domHelper.getClientWidth();\n const minMaxImageSize = 10;\n const maxWidth = Math.max(width, minMaxImageSize);\n context.newImages.forEach(image => {\n image.format.maxWidth = `${maxWidth}px`;\n });\n }\n}\n\nfunction handlePendingFormat(\n core: EditorCore,\n context: FormatContentModelContext,\n selection?: DOMSelection | null\n) {\n const pendingFormat =\n context.newPendingFormat == 'preserve'\n ? core.format.pendingFormat?.format\n : context.newPendingFormat;\n const pendingParagraphFormat =\n context.newPendingParagraphFormat == 'preserve'\n ? core.format.pendingFormat?.paragraphFormat\n : context.newPendingParagraphFormat;\n\n if (\n (pendingFormat || pendingParagraphFormat) &&\n selection?.type == 'range' &&\n selection.range.collapsed\n ) {\n core.format.pendingFormat = {\n format: pendingFormat ? { ...pendingFormat } : undefined,\n paragraphFormat: pendingParagraphFormat ? { ...pendingParagraphFormat } : undefined,\n insertPoint: {\n node: selection.range.startContainer,\n offset: selection.range.startOffset,\n },\n };\n }\n}\n\nfunction getChangedEntities(\n context: FormatContentModelContext,\n rawEvent?: Event\n): ChangedEntity[] | undefined {\n return context.autoDetectChangedEntities\n ? undefined\n : context.newEntities\n .map(\n (entity): ChangedEntity => ({\n entity,\n operation: 'newEntity',\n rawEvent,\n })\n )\n .concat(\n context.deletedEntities.map(entry => ({\n entity: entry.entity,\n operation: entry.operation,\n rawEvent,\n }))\n );\n}\n"]}
@@ -1,4 +1,8 @@
1
1
  import type { EditorCore, ParsedTable, TableCellCoordinate } from 'roosterjs-content-model-types';
2
+ /**
3
+ * @internal
4
+ */
5
+ export declare const DOM_SELECTION_CSS_KEY = "_DOMSelection";
2
6
  /**
3
7
  * @internal
4
8
  * Remove table cell selection styles
@@ -1,8 +1,11 @@
1
1
  define(["require", "exports", "../setEditorStyle/ensureUniqueId", "roosterjs-content-model-dom"], function (require, exports, ensureUniqueId_1, roosterjs_content_model_dom_1) {
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.setTableCellsStyle = exports.removeTableCellsStyle = void 0;
5
- var DOM_SELECTION_CSS_KEY = '_DOMSelection';
4
+ exports.setTableCellsStyle = exports.removeTableCellsStyle = exports.DOM_SELECTION_CSS_KEY = void 0;
5
+ /**
6
+ * @internal
7
+ */
8
+ exports.DOM_SELECTION_CSS_KEY = '_DOMSelection';
6
9
  var TABLE_ID = 'table';
7
10
  /**
8
11
  * @internal
@@ -10,7 +13,7 @@ define(["require", "exports", "../setEditorStyle/ensureUniqueId", "roosterjs-con
10
13
  * @param core The EditorCore object
11
14
  */
12
15
  function removeTableCellsStyle(core) {
13
- core.api.setEditorStyle(core, DOM_SELECTION_CSS_KEY, '');
16
+ core.api.setEditorStyle(core, exports.DOM_SELECTION_CSS_KEY, '');
14
17
  }
15
18
  exports.removeTableCellsStyle = removeTableCellsStyle;
16
19
  /**
@@ -35,7 +38,7 @@ define(["require", "exports", "../setEditorStyle/ensureUniqueId", "roosterjs-con
35
38
  lastCell.col == ((_b = (_a = parsedTable[lastCell.row]) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) - 1
36
39
  ? [tableSelector, tableSelector + " *"]
37
40
  : buildTableSelectors(parsedTable, tableSelector, table, firstCell, lastCell);
38
- core.api.setEditorStyle(core, DOM_SELECTION_CSS_KEY, "background-color:" + tableSelectionColor + "!important;", tableSelectors);
41
+ core.api.setEditorStyle(core, exports.DOM_SELECTION_CSS_KEY, "background-color:" + tableSelectionColor + "!important;", tableSelectors);
39
42
  }
40
43
  exports.setTableCellsStyle = setTableCellsStyle;
41
44
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"setTableCellsStyle.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/coreApi/setDOMSelection/setTableCellsStyle.ts"],"names":[],"mappings":";;;;IAIA,IAAM,qBAAqB,GAAG,eAAe,CAAC;IAC9C,IAAM,QAAQ,GAAG,OAAO,CAAC;IAEzB;;;;OAIG;IACH,SAAgB,qBAAqB,CAAC,IAAgB;QAClD,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,EAAE,qBAAqB,EAAE,EAAE,CAAC,CAAC;IAC7D,CAAC;IAFD,sDAEC;IAED;;;;;;;;OAQG;IACH,SAAgB,kBAAkB,CAC9B,IAAgB,EAChB,KAAuB,EACvB,WAAwB,EACxB,SAA8B,EAC9B,QAA6B;;QAE7B,IAAM,OAAO,GAAG,IAAA,+BAAc,EAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QAChD,IAAM,aAAa,GAAG,IAAA,+CAAiB,EAAC,OAAO,CAAC,CAAC;QACjD,IAAM,mBAAmB,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU;YACjD,CAAC,C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AAgB,sBAAiB,UAAU,UAAK,IAAI,CAAC,OAAO,mBAAc,OAAO,MAAG,CAAC;wBAEzH,SAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC,CAAC;qBAC7C;iBACJ;aACJ;QACL,CAAC,CAAC,CAAC;QAEH,OAAO,SAAS,CAAC;IACrB,CAAC","sourcesContent":["import { ensureUniqueId } from '../setEditorStyle/ensureUniqueId';\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"]}
1
+ {"version":3,"file":"setTableCellsStyle.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/coreApi/setDOMSelection/setTableCellsStyle.ts"],"names":[],"mappings":";;;;IAIA;;OAEG;IACU,QAAA,qBAAqB,GAAG,eAAe,CAAC;IACrD,IAAM,QAAQ,GAAG,OAAO,CAAC;IAEzB;;;;OAIG;IACH,SAAgB,qBAAqB,CAAC,IAAgB;QAClD,IAAI,CAAC,GAAG,CAAC,cAAc,C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SAAS,GAAG,GAAG,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE;gBACzD,IAAM,IAAI,GAAG,GAAG,CAAC,SAAS,CAAC,CAAC;gBAE5B,IAAI,OAAO,IAAI,IAAI,QAAQ,EAAE;oBACzB,OAAO,EAAE,CAAC;oBAEV,IACI,QAAQ,IAAI,SAAS,CAAC,GAAG;wBACzB,QAAQ,IAAI,QAAQ,CAAC,GAAG;wBACxB,SAAS,IAAI,SAAS,CAAC,GAAG;wBAC1B,SAAS,IAAI,QAAQ,CAAC,GAAG,EAC3B;wBACE,IAAM,QAAQ,GAAG,KAAG,aAAa,GAAG,gBAAgB,sBAAiB,UAAU,UAAK,IAAI,CAAC,OAAO,mBAAc,OAAO,MAAG,CAAC;wBAEzH,SAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC,CAAC;qBAC7C;iBACJ;aACJ;QACL,CAAC,CAAC,CAAC;QAEH,OAAO,SAAS,CAAC;IACrB,CAAC","sourcesContent":["import { ensureUniqueId } from '../setEditorStyle/ensureUniqueId';\nimport { getSafeIdSelector, isNodeOfType, toArray } from 'roosterjs-content-model-dom';\nimport type { EditorCore, ParsedTable, TableCellCoordinate } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport const 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"]}
@@ -1,4 +1,8 @@
1
1
  import type { EditorCore } from 'roosterjs-content-model-types';
2
+ /**
3
+ * @internal
4
+ */
5
+ export declare const HIDE_CURSOR_CSS_KEY = "_DOMSelectionHideCursor";
2
6
  /**
3
7
  * @internal Show/Hide caret in editor
4
8
  * @param core The editor core
@@ -1,16 +1,19 @@
1
1
  define(["require", "exports"], function (require, exports) {
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.toggleCaret = void 0;
4
+ exports.toggleCaret = exports.HIDE_CURSOR_CSS_KEY = void 0;
5
5
  var CARET_CSS_RULE = 'caret-color: transparent';
6
- var HIDE_CURSOR_CSS_KEY = '_DOMSelectionHideCursor';
6
+ /**
7
+ * @internal
8
+ */
9
+ exports.HIDE_CURSOR_CSS_KEY = '_DOMSelectionHideCursor';
7
10
  /**
8
11
  * @internal Show/Hide caret in editor
9
12
  * @param core The editor core
10
13
  * @param isHiding True to hide caret, false to show caret
11
14
  */
12
15
  function toggleCaret(core, isHiding) {
13
- core.api.setEditorStyle(core, HIDE_CURSOR_CSS_KEY, isHiding ? CARET_CSS_RULE : null);
16
+ core.api.setEditorStyle(core, exports.HIDE_CURSOR_CSS_KEY, isHiding ? CARET_CSS_RULE : null);
14
17
  }
15
18
  exports.toggleCaret = toggleCaret;
16
19
  });
@@ -1 +1 @@
1
- {"version":3,"file":"toggleCaret.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/coreApi/setDOMSelection/toggleCaret.ts"],"names":[],"mappings":";;;;IAEA,IAAM,cAAc,GAAG,0BAA0B,CAAC;IAClD,IAAM,mBAAmB,GAAG,yBAAyB,CAAC;IAEtD;;;;OAIG;IACH,SAAgB,WAAW,CAAC,IAAgB,EAAE,QAAiB;QAC3D,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,EAAE,mBAAmB,EAAE,QAAQ,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IACzF,CAAC;IAFD,kCAEC","sourcesContent":["import type { EditorCore } from 'roosterjs-content-model-types';\n\nconst CARET_CSS_RULE = 'caret-color: transparent';\nconst HIDE_CURSOR_CSS_KEY = '_DOMSelectionHideCursor';\n\n/**\n * @internal Show/Hide caret in editor\n * @param core The editor core\n * @param isHiding True to hide caret, false to show caret\n */\nexport function toggleCaret(core: EditorCore, isHiding: boolean) {\n core.api.setEditorStyle(core, HIDE_CURSOR_CSS_KEY, isHiding ? CARET_CSS_RULE : null);\n}\n"]}
1
+ {"version":3,"file":"toggleCaret.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/coreApi/setDOMSelection/toggleCaret.ts"],"names":[],"mappings":";;;;IAEA,IAAM,cAAc,GAAG,0BAA0B,CAAC;IAClD;;OAEG;IACU,QAAA,mBAAmB,GAAG,yBAAyB,CAAC;IAE7D;;;;OAIG;IACH,SAAgB,WAAW,CAAC,IAAgB,EAAE,QAAiB;QAC3D,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,EAAE,2BAAmB,EAAE,QAAQ,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IACzF,CAAC;IAFD,kCAEC","sourcesContent":["import type { EditorCore } from 'roosterjs-content-model-types';\n\nconst CARET_CSS_RULE = 'caret-color: transparent';\n/**\n * @internal\n */\nexport const HIDE_CURSOR_CSS_KEY = '_DOMSelectionHideCursor';\n\n/**\n * @internal Show/Hide caret in editor\n * @param core The editor core\n * @param isHiding True to hide caret, false to show caret\n */\nexport function toggleCaret(core: EditorCore, isHiding: boolean) {\n core.api.setEditorStyle(core, HIDE_CURSOR_CSS_KEY, isHiding ? CARET_CSS_RULE : null);\n}\n"]}
@@ -1,4 +1,4 @@
1
- define(["require", "exports", "./findCoordinate", "../../coreApi/setDOMSelection/findTableCellElement", "./isSingleImageInSelection", "./normalizePos", "roosterjs-content-model-dom"], function (require, exports, findCoordinate_1, findTableCellElement_1, isSingleImageInSelection_1, normalizePos_1, roosterjs_content_model_dom_1) {
1
+ define(["require", "exports", "./findCoordinate", "../../coreApi/setDOMSelection/findTableCellElement", "./isSingleImageInSelection", "./normalizePos", "roosterjs-content-model-dom", "../../coreApi/setDOMSelection/setTableCellsStyle", "../../coreApi/setDOMSelection/toggleCaret"], function (require, exports, findCoordinate_1, findTableCellElement_1, isSingleImageInSelection_1, normalizePos_1, roosterjs_content_model_dom_1, setTableCellsStyle_1, toggleCaret_1) {
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.createSelectionPlugin = exports.DEFAULT_TABLE_CELL_SELECTION_BACKGROUND_COLOR = exports.DEFAULT_SELECTION_BORDER_COLOR = void 0;
@@ -9,6 +9,7 @@ define(["require", "exports", "./findCoordinate", "../../coreApi/setDOMSelection
9
9
  var Left = 'ArrowLeft';
10
10
  var Right = 'ArrowRight';
11
11
  var Tab = 'Tab';
12
+ var F10 = 'F10';
12
13
  /**
13
14
  * @internal
14
15
  */
@@ -25,8 +26,8 @@ define(["require", "exports", "./findCoordinate", "../../coreApi/setDOMSelection
25
26
  this.disposer = null;
26
27
  this.logicalRootDisposer = null;
27
28
  this.isSafari = false;
28
- this.isMac = false;
29
29
  this.scrollTopCache = 0;
30
+ this.isInsideSelection = false;
30
31
  this.onMouseMove = function (event) {
31
32
  var _a, _b, _c;
32
33
  if (_this.editor && _this.state.tableSelection) {
@@ -77,7 +78,7 @@ define(["require", "exports", "./findCoordinate", "../../coreApi/setDOMSelection
77
78
  // MacOS will not create a mouseUp event if contextMenu event is not prevent defaulted.
78
79
  // Make sure we capture image target even if image is wrapped
79
80
  this.getContainedTargetImage = function (event, previousSelection) {
80
- if (!_this.isMac || !previousSelection || previousSelection.type !== 'image') {
81
+ if (!previousSelection || previousSelection.type !== 'image') {
81
82
  return null;
82
83
  }
83
84
  var target = event.target;
@@ -117,11 +118,11 @@ define(["require", "exports", "./findCoordinate", "../../coreApi/setDOMSelection
117
118
  if (((_a = _this.editor) === null || _a === void 0 ? void 0 : _a.hasFocus()) && !_this.editor.isInShadowEdit()) {
118
119
  var newSelection = _this.editor.getDOMSelection();
119
120
  var domHelper = _this.editor.getDOMHelper();
120
- //If am image selection changed to a wider range due a keyboard event, we should update the selection
121
+ // If an image selection changed to a wider range due to a keyboard event, we should update the selection
121
122
  var range = domHelper.getSelectionRange();
122
123
  if (range) {
123
124
  var image = (0, isSingleImageInSelection_1.isSingleImageInSelection)(range);
124
- if ((newSelection === null || newSelection === void 0 ? void 0 : newSelection.type) == 'image' && !image) {
125
+ if ((newSelection === null || newSelection === void 0 ? void 0 : newSelection.type) == 'image' && !image && !range.collapsed) {
125
126
  var sel = (_b = _this.editor.getDocument().defaultView) === null || _b === void 0 ? void 0 : _b.getSelection();
126
127
  var isReverted = sel
127
128
  ? sel.focusNode != range.endContainer || sel.focusOffset != range.endOffset
@@ -180,7 +181,6 @@ define(["require", "exports", "./findCoordinate", "../../coreApi/setDOMSelection
180
181
  var env = this.editor.getEnvironment();
181
182
  var document = this.editor.getDocument();
182
183
  this.isSafari = !!env.isSafari;
183
- this.isMac = !!env.isMac;
184
184
  document.addEventListener('selectionchange', this.onSelectionChange);
185
185
  if (this.isSafari) {
186
186
  this.disposer = this.editor.attachDomEvent({
@@ -227,6 +227,10 @@ define(["require", "exports", "./findCoordinate", "../../coreApi/setDOMSelection
227
227
  this.onKeyDown(this.editor, event.rawEvent);
228
228
  break;
229
229
  case 'contentChanged':
230
+ if (event.source == roosterjs_content_model_dom_1.ChangeSource.Drop && this.isInsideSelection) {
231
+ this.setDOMSelection(null /* DOMSelection */, null /* tableSelection */);
232
+ this.isInsideSelection = false;
233
+ }
230
234
  this.state.tableSelection = null;
231
235
  break;
232
236
  case 'scroll':
@@ -274,14 +278,22 @@ define(["require", "exports", "./findCoordinate", "../../coreApi/setDOMSelection
274
278
  return;
275
279
  }
276
280
  // Table selection
281
+ var target = rawEvent.target;
282
+ var tableSelection = target
283
+ ? this.parseTableSelection(target, target, editor.getDOMHelper())
284
+ : null;
285
+ if ((selection === null || selection === void 0 ? void 0 : selection.type) == 'table' &&
286
+ tableSelection &&
287
+ this.isInsideTableSelection(selection, tableSelection) &&
288
+ rawEvent.detail == 1) {
289
+ this.isInsideSelection = true;
290
+ this.setTableDragSelection(editor, rawEvent);
291
+ return;
292
+ }
277
293
  if ((selection === null || selection === void 0 ? void 0 : selection.type) == 'table' && rawEvent.button == MouseLeftButton) {
278
294
  this.setDOMSelection(null /*domSelection*/, null /*tableSelection*/);
279
295
  }
280
- var tableSelection;
281
- var target = rawEvent.target;
282
- if (target &&
283
- rawEvent.button == MouseLeftButton &&
284
- (tableSelection = this.parseTableSelection(target, target, editor.getDOMHelper()))) {
296
+ if (target && rawEvent.button == MouseLeftButton && tableSelection) {
285
297
  this.state.tableSelection = tableSelection;
286
298
  if (rawEvent.detail >= 3) {
287
299
  var lastCo = (0, findCoordinate_1.findCoordinate)(tableSelection.parsedTable, rawEvent.target, editor.getDOMHelper());
@@ -301,6 +313,10 @@ define(["require", "exports", "./findCoordinate", "../../coreApi/setDOMSelection
301
313
  }
302
314
  };
303
315
  SelectionPlugin.prototype.onMouseUp = function () {
316
+ if (this.isInsideSelection) {
317
+ this.setDOMSelection(null /*domSelection*/, null /*tableSelection*/);
318
+ this.isInsideSelection = false;
319
+ }
304
320
  this.detachMouseEvent();
305
321
  };
306
322
  SelectionPlugin.prototype.onKeyDown = function (editor, rawEvent) {
@@ -333,6 +349,7 @@ define(["require", "exports", "./findCoordinate", "../../coreApi/setDOMSelection
333
349
  }
334
350
  break;
335
351
  case 'range':
352
+ var image = void 0;
336
353
  if (key == Up || key == Down || key == Left || key == Right || key == Tab) {
337
354
  var start = selection.range.startContainer;
338
355
  this.state.tableSelection = this.parseTableSelection(start, start, editor.getDOMHelper());
@@ -348,6 +365,14 @@ define(["require", "exports", "./findCoordinate", "../../coreApi/setDOMSelection
348
365
  }
349
366
  }
350
367
  }
368
+ else if (key == F10 &&
369
+ rawEvent.shiftKey &&
370
+ (image = (0, isSingleImageInSelection_1.isSingleImageInSelection)(selection.range))) {
371
+ this.setDOMSelection({
372
+ type: 'image',
373
+ image: image,
374
+ }, null /* tableSelection */);
375
+ }
351
376
  break;
352
377
  case 'table':
353
378
  // After a content change event is handled tableSelection state is reset to null
@@ -486,6 +511,30 @@ define(["require", "exports", "./findCoordinate", "../../coreApi/setDOMSelection
486
511
  }
487
512
  }
488
513
  };
514
+ SelectionPlugin.prototype.isInsideTableSelection = function (prevSelection, tableSelection) {
515
+ var selectedCell = tableSelection.firstCo;
516
+ return (selectedCell.row >= prevSelection.firstRow &&
517
+ selectedCell.row <= prevSelection.lastRow &&
518
+ selectedCell.col >= prevSelection.firstColumn &&
519
+ selectedCell.col <= prevSelection.lastColumn);
520
+ };
521
+ SelectionPlugin.prototype.setTableDragSelection = function (editor, rawEvent) {
522
+ var doc = editor.getDocument();
523
+ var cell = editor
524
+ .getDOMHelper()
525
+ .findClosestElementAncestor(rawEvent.target, 'td,th');
526
+ if (cell) {
527
+ // Hide the table cell selection styles (grey cell background applied by
528
+ // setDOMSelection) and the native selection highlight so that only the
529
+ // dragged content is visible while dragging. Also restore the caret which
530
+ // is hidden while a table selection is active.
531
+ editor.setEditorStyle(setTableCellsStyle_1.DOM_SELECTION_CSS_KEY, null /*cssRule*/);
532
+ editor.setEditorStyle(toggleCaret_1.HIDE_CURSOR_CSS_KEY, null /*cssRule*/);
533
+ var range = doc.createRange();
534
+ range.selectNodeContents(cell);
535
+ editor.getDOMHelper().setSelectionRange(range);
536
+ }
537
+ };
489
538
  SelectionPlugin.prototype.getTextOffset = function (editor, range, td, isKeyUp) {
490
539
  var doc = editor.getDocument();
491
540
  var cursorRect = range