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.
- package/README.md +8 -0
- package/lib/command/createModelFromHtml/createDomToModelContextForSanitizing.d.ts +2 -2
- package/lib/command/createModelFromHtml/createDomToModelContextForSanitizing.js +2 -2
- package/lib/command/createModelFromHtml/createDomToModelContextForSanitizing.js.map +1 -1
- package/lib/command/paste/mergePasteContent.js +16 -5
- package/lib/command/paste/mergePasteContent.js.map +1 -1
- package/lib/command/paste/paste.js +4 -5
- package/lib/command/paste/paste.js.map +1 -1
- package/lib/coreApi/formatContentModel/formatContentModel.js +1 -1
- package/lib/coreApi/formatContentModel/formatContentModel.js.map +1 -1
- package/lib/coreApi/setDOMSelection/setTableCellsStyle.d.ts +4 -0
- package/lib/coreApi/setDOMSelection/setTableCellsStyle.js +7 -4
- package/lib/coreApi/setDOMSelection/setTableCellsStyle.js.map +1 -1
- package/lib/coreApi/setDOMSelection/toggleCaret.d.ts +4 -0
- package/lib/coreApi/setDOMSelection/toggleCaret.js +6 -3
- package/lib/coreApi/setDOMSelection/toggleCaret.js.map +1 -1
- package/lib/corePlugin/selection/SelectionPlugin.js +61 -10
- package/lib/corePlugin/selection/SelectionPlugin.js.map +1 -1
- package/lib/editor/Editor.d.ts +5 -0
- package/lib/editor/Editor.js +7 -0
- package/lib/editor/Editor.js.map +1 -1
- package/lib-amd/command/createModelFromHtml/createDomToModelContextForSanitizing.d.ts +2 -2
- package/lib-amd/command/createModelFromHtml/createDomToModelContextForSanitizing.js +2 -2
- package/lib-amd/command/createModelFromHtml/createDomToModelContextForSanitizing.js.map +1 -1
- package/lib-amd/command/paste/mergePasteContent.js +16 -5
- package/lib-amd/command/paste/mergePasteContent.js.map +1 -1
- package/lib-amd/command/paste/paste.js +5 -5
- package/lib-amd/command/paste/paste.js.map +1 -1
- package/lib-amd/coreApi/formatContentModel/formatContentModel.js +1 -1
- package/lib-amd/coreApi/formatContentModel/formatContentModel.js.map +1 -1
- package/lib-amd/coreApi/setDOMSelection/setTableCellsStyle.d.ts +4 -0
- package/lib-amd/coreApi/setDOMSelection/setTableCellsStyle.js +7 -4
- package/lib-amd/coreApi/setDOMSelection/setTableCellsStyle.js.map +1 -1
- package/lib-amd/coreApi/setDOMSelection/toggleCaret.d.ts +4 -0
- package/lib-amd/coreApi/setDOMSelection/toggleCaret.js +6 -3
- package/lib-amd/coreApi/setDOMSelection/toggleCaret.js.map +1 -1
- package/lib-amd/corePlugin/selection/SelectionPlugin.js +60 -11
- package/lib-amd/corePlugin/selection/SelectionPlugin.js.map +1 -1
- package/lib-amd/editor/Editor.d.ts +5 -0
- package/lib-amd/editor/Editor.js +7 -0
- package/lib-amd/editor/Editor.js.map +1 -1
- package/lib-mjs/command/createModelFromHtml/createDomToModelContextForSanitizing.d.ts +2 -2
- package/lib-mjs/command/createModelFromHtml/createDomToModelContextForSanitizing.js +2 -2
- package/lib-mjs/command/createModelFromHtml/createDomToModelContextForSanitizing.js.map +1 -1
- package/lib-mjs/command/paste/mergePasteContent.js +16 -5
- package/lib-mjs/command/paste/mergePasteContent.js.map +1 -1
- package/lib-mjs/command/paste/paste.js +4 -5
- package/lib-mjs/command/paste/paste.js.map +1 -1
- package/lib-mjs/coreApi/formatContentModel/formatContentModel.js +1 -1
- package/lib-mjs/coreApi/formatContentModel/formatContentModel.js.map +1 -1
- package/lib-mjs/coreApi/setDOMSelection/setTableCellsStyle.d.ts +4 -0
- package/lib-mjs/coreApi/setDOMSelection/setTableCellsStyle.js +4 -1
- package/lib-mjs/coreApi/setDOMSelection/setTableCellsStyle.js.map +1 -1
- package/lib-mjs/coreApi/setDOMSelection/toggleCaret.d.ts +4 -0
- package/lib-mjs/coreApi/setDOMSelection/toggleCaret.js +4 -1
- package/lib-mjs/coreApi/setDOMSelection/toggleCaret.js.map +1 -1
- package/lib-mjs/corePlugin/selection/SelectionPlugin.js +62 -11
- package/lib-mjs/corePlugin/selection/SelectionPlugin.js.map +1 -1
- package/lib-mjs/editor/Editor.d.ts +5 -0
- package/lib-mjs/editor/Editor.js +7 -0
- package/lib-mjs/editor/Editor.js.map +1 -1
- package/package.json +3 -3
- package/lib/command/paste/createPasteFragment.d.ts +0 -5
- package/lib/command/paste/createPasteFragment.js +0 -79
- package/lib/command/paste/createPasteFragment.js.map +0 -1
- package/lib-amd/command/paste/createPasteFragment.d.ts +0 -5
- package/lib-amd/command/paste/createPasteFragment.js +0 -80
- package/lib-amd/command/paste/createPasteFragment.js.map +0 -1
- package/lib-mjs/command/paste/createPasteFragment.d.ts +0 -5
- package/lib-mjs/command/paste/createPasteFragment.js +0 -75
- 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":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"paste.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/command/paste/paste.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AACtF,OAAO,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AAC3E,OAAO,EAAE,8BAA8B,EAAE,MAAM,kCAAkC,CAAC;AAClF,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAQtD;;;;;GAKG;AACH,MAAM,UAAU,KAAK,CACjB,MAAe,EACf,aAA4B,EAC5B,iBAA+C;;IAA/C,kCAAA,EAAA,4BAA+C;IAE/C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AAa,EACb,cAAc,EACd,iBAAiB,EACjB,SAAS,CACZ,CAAC;IAEF,sCAAsC;IACtC,gBAAgB,CAAC,WAAW,CAAC,QAAQ,EAAE,iBAAiB,CAAC,cAAc,CAAC,CAAC;IAEzE,kDAAkD;IAClD,iBAAiB,CAAC,MAAM,EAAE,WAAW,EAAE,YAAY,CAAC,CAAC;AACzD,CAAC;AAED,SAAS,iBAAiB,CACtB,IAA+B,EAC/B,UAAsB;IAEtB,OAAO,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AACpD,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"]}
|
|
@@ -37,7 +37,7 @@ export var formatContentModel = function (core, formatter, options, domToModelOp
|
|
|
37
37
|
try {
|
|
38
38
|
handleImages(core, context);
|
|
39
39
|
selection =
|
|
40
|
-
(_a = core.api.setContentModel(core, model, hasFocus ? undefined : { ignoreSelection: true }, // If editor did not have focus before format, do not set focus after format
|
|
40
|
+
(_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
|
|
41
41
|
onNodeCreated)) !== null && _a !== void 0 ? _a : undefined;
|
|
42
42
|
handlePendingFormat(core, context, selection);
|
|
43
43
|
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":";AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAU5D;;;;;;;;;GASG;AACH,MAAM,CAAC,IAAM,kBAAkB,GAAuB,UAClD,IAAI,EACJ,SAAS,EACT,OAAO,EACP,iBAAiB;;IAEX,IAAA,KACF,OAAO,IAAI,EAAE,EADT,aAAa,mBAAA,EAAE,QAAQ,cAAA,EAAE,iBAAiB,uBAAA,EAAuB,MAAM,yBAC9D,CAAC;IAClB,IAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,kBAAkB,CAAC,IAAI,EAAE,iBAAiB,EAAE,iBAAiB,CAAC,CAAC;IACtF,IAAM,OAAO,GAA8B;QACvC,WAAW,EAAE,EAAE;QACf,eAAe,EAAE,EAAE;QACnB,QAAQ,UAAA;QACR,SAAS,EAAE,EAAE;QACb,gBAAgB,EAAE,IAAI,CAAC,KAAK,CAAC,YAAY;KAC5C,CAAC;IAEF,IAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC;IAE3C,IAAM,OAAO,GAAG,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAClC,IAAA,gBAAgB,GAAwD,OAAO,iBAA/D,EAAE,eAAe,GAAuC,OAAO,gBAA9C,EAAE,YAAY,GAAyB,OAAO,aAAhC,EAAE,kBAAkB,GAAK,OAAO,mBAAZ,CAAa;IAExF,IAAI,OAAO,EAAE;QACT,IAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;QACpC,IAAM,iBAAiB,GACnB,CAAC,CAAC,gBAAgB,IAAI,gBAAgB,IAAI,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC;QACxE,IAAM,oBAAoB,GACtB,CAAC,gBAAgB,KA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,EAAE,aAAa,CAAC,CAAC,cAAM,aAAa,EAAG,CAAC,CAAC,SAAS;YACxD,eAAe,EAAE,sBAAsB,CAAC,CAAC,cAAM,sBAAsB,EAAG,CAAC,CAAC,SAAS;YACnF,WAAW,EAAE;gBACT,IAAI,EAAE,SAAS,CAAC,KAAK,CAAC,cAAc;gBACpC,MAAM,EAAE,SAAS,CAAC,KAAK,CAAC,WAAW;aACtC;SACJ,CAAC;KACL;AACL,CAAC;AAED,SAAS,kBAAkB,CACvB,OAAkC,EAClC,QAAgB;IAEhB,OAAO,OAAO,CAAC,yBAAyB;QACpC,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,OAAO,CAAC,WAAW;aACd,GAAG,CACA,UAAC,MAAM,IAAoB,OAAA,CAAC;YACxB,MAAM,QAAA;YACN,SAAS,EAAE,WAAW;YACtB,QAAQ,UAAA;SACX,CAAC,EAJyB,CAIzB,CACL;aACA,MAAM,CACH,OAAO,CAAC,eAAe,CAAC,GAAG,CAAC,UAAA,KAAK,IAAI,OAAA,CAAC;YAClC,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,QAAQ,UAAA;SACX,CAAC,EAJmC,CAInC,CAAC,CACN,CAAC;AAChB,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":["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IAAI,CAAC,MAAM,CAAC,aAAa,GAAG;YACxB,MAAM,EAAE,aAAa,CAAC,CAAC,cAAM,aAAa,EAAG,CAAC,CAAC,SAAS;YACxD,eAAe,EAAE,sBAAsB,CAAC,CAAC,cAAM,sBAAsB,EAAG,CAAC,CAAC,SAAS;YACnF,WAAW,EAAE;gBACT,IAAI,EAAE,SAAS,CAAC,KAAK,CAAC,cAAc;gBACpC,MAAM,EAAE,SAAS,CAAC,KAAK,CAAC,WAAW;aACtC;SACJ,CAAC;KACL;AACL,CAAC;AAED,SAAS,kBAAkB,CACvB,OAAkC,EAClC,QAAgB;IAEhB,OAAO,OAAO,CAAC,yBAAyB;QACpC,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,OAAO,CAAC,WAAW;aACd,GAAG,CACA,UAAC,MAAM,IAAoB,OAAA,CAAC;YACxB,MAAM,QAAA;YACN,SAAS,EAAE,WAAW;YACtB,QAAQ,UAAA;SACX,CAAC,EAJyB,CAIzB,CACL;aACA,MAAM,CACH,OAAO,CAAC,eAAe,CAAC,GAAG,CAAC,UAAA,KAAK,IAAI,OAAA,CAAC;YAClC,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,QAAQ,UAAA;SACX,CAAC,EAJmC,CAInC,CAAC,CACN,CAAC;AAChB,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,6 +1,9 @@
|
|
|
1
1
|
import { ensureUniqueId } from '../setEditorStyle/ensureUniqueId';
|
|
2
2
|
import { getSafeIdSelector, isNodeOfType, toArray } from 'roosterjs-content-model-dom';
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
export var DOM_SELECTION_CSS_KEY = '_DOMSelection';
|
|
4
7
|
var TABLE_ID = 'table';
|
|
5
8
|
/**
|
|
6
9
|
* @internal
|
|
@@ -1 +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;
|
|
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;;GAEG;AACH,MAAM,CAAC,IAAM,qBAAqB,GAAG,eAAe,CAAC;AACrD,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,WA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I,SAAS,CAAC,GAAG;oBACzB,QAAQ,IAAI,QAAQ,CAAC,GAAG;oBACxB,SAAS,IAAI,SAAS,CAAC,GAAG;oBAC1B,SAAS,IAAI,QAAQ,CAAC,GAAG,EAC3B;oBACE,IAAM,QAAQ,GAAG,KAAG,aAAa,GAAG,gBAAgB,sBAAiB,UAAU,UAAK,IAAI,CAAC,OAAO,mBAAc,OAAO,MAAG,CAAC;oBAEzH,SAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC,CAAC;iBAC7C;aACJ;SACJ;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,SAAS,CAAC;AACrB,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,5 +1,8 @@
|
|
|
1
1
|
var CARET_CSS_RULE = 'caret-color: transparent';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* @internal
|
|
4
|
+
*/
|
|
5
|
+
export var HIDE_CURSOR_CSS_KEY = '_DOMSelectionHideCursor';
|
|
3
6
|
/**
|
|
4
7
|
* @internal Show/Hide caret in editor
|
|
5
8
|
* @param core The editor core
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toggleCaret.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/coreApi/setDOMSelection/toggleCaret.ts"],"names":[],"mappings":"AAEA,IAAM,cAAc,GAAG,0BAA0B,CAAC;AAClD,IAAM,mBAAmB,GAAG,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"toggleCaret.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/coreApi/setDOMSelection/toggleCaret.ts"],"names":[],"mappings":"AAEA,IAAM,cAAc,GAAG,0BAA0B,CAAC;AAClD;;GAEG;AACH,MAAM,CAAC,IAAM,mBAAmB,GAAG,yBAAyB,CAAC;AAE7D;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,IAAgB,EAAE,QAAiB;IAC3D,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,EAAE,mBAAmB,EAAE,QAAQ,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AACzF,CAAC","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"]}
|
|
@@ -2,7 +2,9 @@ import { findCoordinate } from './findCoordinate';
|
|
|
2
2
|
import { findTableCellElement } from '../../coreApi/setDOMSelection/findTableCellElement';
|
|
3
3
|
import { isSingleImageInSelection } from './isSingleImageInSelection';
|
|
4
4
|
import { normalizePos } from './normalizePos';
|
|
5
|
-
import { getDOMInsertPointRect, getNodePositionFromEvent, isCharacterValue, isElementOfType, isModifierKey, isNodeOfType, parseTableCells, toArray, } from 'roosterjs-content-model-dom';
|
|
5
|
+
import { ChangeSource, getDOMInsertPointRect, getNodePositionFromEvent, isCharacterValue, isElementOfType, isModifierKey, isNodeOfType, parseTableCells, toArray, } from 'roosterjs-content-model-dom';
|
|
6
|
+
import { DOM_SELECTION_CSS_KEY } from '../../coreApi/setDOMSelection/setTableCellsStyle';
|
|
7
|
+
import { HIDE_CURSOR_CSS_KEY } from '../../coreApi/setDOMSelection/toggleCaret';
|
|
6
8
|
var MouseLeftButton = 0;
|
|
7
9
|
var MouseRightButton = 2;
|
|
8
10
|
var Up = 'ArrowUp';
|
|
@@ -10,6 +12,7 @@ var Down = 'ArrowDown';
|
|
|
10
12
|
var Left = 'ArrowLeft';
|
|
11
13
|
var Right = 'ArrowRight';
|
|
12
14
|
var Tab = 'Tab';
|
|
15
|
+
var F10 = 'F10';
|
|
13
16
|
/**
|
|
14
17
|
* @internal
|
|
15
18
|
*/
|
|
@@ -26,8 +29,8 @@ var SelectionPlugin = /** @class */ (function () {
|
|
|
26
29
|
this.disposer = null;
|
|
27
30
|
this.logicalRootDisposer = null;
|
|
28
31
|
this.isSafari = false;
|
|
29
|
-
this.isMac = false;
|
|
30
32
|
this.scrollTopCache = 0;
|
|
33
|
+
this.isInsideSelection = false;
|
|
31
34
|
this.onMouseMove = function (event) {
|
|
32
35
|
var _a, _b, _c;
|
|
33
36
|
if (_this.editor && _this.state.tableSelection) {
|
|
@@ -78,7 +81,7 @@ var SelectionPlugin = /** @class */ (function () {
|
|
|
78
81
|
// MacOS will not create a mouseUp event if contextMenu event is not prevent defaulted.
|
|
79
82
|
// Make sure we capture image target even if image is wrapped
|
|
80
83
|
this.getContainedTargetImage = function (event, previousSelection) {
|
|
81
|
-
if (!
|
|
84
|
+
if (!previousSelection || previousSelection.type !== 'image') {
|
|
82
85
|
return null;
|
|
83
86
|
}
|
|
84
87
|
var target = event.target;
|
|
@@ -118,11 +121,11 @@ var SelectionPlugin = /** @class */ (function () {
|
|
|
118
121
|
if (((_a = _this.editor) === null || _a === void 0 ? void 0 : _a.hasFocus()) && !_this.editor.isInShadowEdit()) {
|
|
119
122
|
var newSelection = _this.editor.getDOMSelection();
|
|
120
123
|
var domHelper = _this.editor.getDOMHelper();
|
|
121
|
-
//If
|
|
124
|
+
// If an image selection changed to a wider range due to a keyboard event, we should update the selection
|
|
122
125
|
var range = domHelper.getSelectionRange();
|
|
123
126
|
if (range) {
|
|
124
127
|
var image = isSingleImageInSelection(range);
|
|
125
|
-
if ((newSelection === null || newSelection === void 0 ? void 0 : newSelection.type) == 'image' && !image) {
|
|
128
|
+
if ((newSelection === null || newSelection === void 0 ? void 0 : newSelection.type) == 'image' && !image && !range.collapsed) {
|
|
126
129
|
var sel = (_b = _this.editor.getDocument().defaultView) === null || _b === void 0 ? void 0 : _b.getSelection();
|
|
127
130
|
var isReverted = sel
|
|
128
131
|
? sel.focusNode != range.endContainer || sel.focusOffset != range.endOffset
|
|
@@ -181,7 +184,6 @@ var SelectionPlugin = /** @class */ (function () {
|
|
|
181
184
|
var env = this.editor.getEnvironment();
|
|
182
185
|
var document = this.editor.getDocument();
|
|
183
186
|
this.isSafari = !!env.isSafari;
|
|
184
|
-
this.isMac = !!env.isMac;
|
|
185
187
|
document.addEventListener('selectionchange', this.onSelectionChange);
|
|
186
188
|
if (this.isSafari) {
|
|
187
189
|
this.disposer = this.editor.attachDomEvent({
|
|
@@ -228,6 +230,10 @@ var SelectionPlugin = /** @class */ (function () {
|
|
|
228
230
|
this.onKeyDown(this.editor, event.rawEvent);
|
|
229
231
|
break;
|
|
230
232
|
case 'contentChanged':
|
|
233
|
+
if (event.source == ChangeSource.Drop && this.isInsideSelection) {
|
|
234
|
+
this.setDOMSelection(null /* DOMSelection */, null /* tableSelection */);
|
|
235
|
+
this.isInsideSelection = false;
|
|
236
|
+
}
|
|
231
237
|
this.state.tableSelection = null;
|
|
232
238
|
break;
|
|
233
239
|
case 'scroll':
|
|
@@ -275,14 +281,22 @@ var SelectionPlugin = /** @class */ (function () {
|
|
|
275
281
|
return;
|
|
276
282
|
}
|
|
277
283
|
// Table selection
|
|
284
|
+
var target = rawEvent.target;
|
|
285
|
+
var tableSelection = target
|
|
286
|
+
? this.parseTableSelection(target, target, editor.getDOMHelper())
|
|
287
|
+
: null;
|
|
288
|
+
if ((selection === null || selection === void 0 ? void 0 : selection.type) == 'table' &&
|
|
289
|
+
tableSelection &&
|
|
290
|
+
this.isInsideTableSelection(selection, tableSelection) &&
|
|
291
|
+
rawEvent.detail == 1) {
|
|
292
|
+
this.isInsideSelection = true;
|
|
293
|
+
this.setTableDragSelection(editor, rawEvent);
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
278
296
|
if ((selection === null || selection === void 0 ? void 0 : selection.type) == 'table' && rawEvent.button == MouseLeftButton) {
|
|
279
297
|
this.setDOMSelection(null /*domSelection*/, null /*tableSelection*/);
|
|
280
298
|
}
|
|
281
|
-
|
|
282
|
-
var target = rawEvent.target;
|
|
283
|
-
if (target &&
|
|
284
|
-
rawEvent.button == MouseLeftButton &&
|
|
285
|
-
(tableSelection = this.parseTableSelection(target, target, editor.getDOMHelper()))) {
|
|
299
|
+
if (target && rawEvent.button == MouseLeftButton && tableSelection) {
|
|
286
300
|
this.state.tableSelection = tableSelection;
|
|
287
301
|
if (rawEvent.detail >= 3) {
|
|
288
302
|
var lastCo = findCoordinate(tableSelection.parsedTable, rawEvent.target, editor.getDOMHelper());
|
|
@@ -302,6 +316,10 @@ var SelectionPlugin = /** @class */ (function () {
|
|
|
302
316
|
}
|
|
303
317
|
};
|
|
304
318
|
SelectionPlugin.prototype.onMouseUp = function () {
|
|
319
|
+
if (this.isInsideSelection) {
|
|
320
|
+
this.setDOMSelection(null /*domSelection*/, null /*tableSelection*/);
|
|
321
|
+
this.isInsideSelection = false;
|
|
322
|
+
}
|
|
305
323
|
this.detachMouseEvent();
|
|
306
324
|
};
|
|
307
325
|
SelectionPlugin.prototype.onKeyDown = function (editor, rawEvent) {
|
|
@@ -334,6 +352,7 @@ var SelectionPlugin = /** @class */ (function () {
|
|
|
334
352
|
}
|
|
335
353
|
break;
|
|
336
354
|
case 'range':
|
|
355
|
+
var image = void 0;
|
|
337
356
|
if (key == Up || key == Down || key == Left || key == Right || key == Tab) {
|
|
338
357
|
var start = selection.range.startContainer;
|
|
339
358
|
this.state.tableSelection = this.parseTableSelection(start, start, editor.getDOMHelper());
|
|
@@ -349,6 +368,14 @@ var SelectionPlugin = /** @class */ (function () {
|
|
|
349
368
|
}
|
|
350
369
|
}
|
|
351
370
|
}
|
|
371
|
+
else if (key == F10 &&
|
|
372
|
+
rawEvent.shiftKey &&
|
|
373
|
+
(image = isSingleImageInSelection(selection.range))) {
|
|
374
|
+
this.setDOMSelection({
|
|
375
|
+
type: 'image',
|
|
376
|
+
image: image,
|
|
377
|
+
}, null /* tableSelection */);
|
|
378
|
+
}
|
|
352
379
|
break;
|
|
353
380
|
case 'table':
|
|
354
381
|
// After a content change event is handled tableSelection state is reset to null
|
|
@@ -487,6 +514,30 @@ var SelectionPlugin = /** @class */ (function () {
|
|
|
487
514
|
}
|
|
488
515
|
}
|
|
489
516
|
};
|
|
517
|
+
SelectionPlugin.prototype.isInsideTableSelection = function (prevSelection, tableSelection) {
|
|
518
|
+
var selectedCell = tableSelection.firstCo;
|
|
519
|
+
return (selectedCell.row >= prevSelection.firstRow &&
|
|
520
|
+
selectedCell.row <= prevSelection.lastRow &&
|
|
521
|
+
selectedCell.col >= prevSelection.firstColumn &&
|
|
522
|
+
selectedCell.col <= prevSelection.lastColumn);
|
|
523
|
+
};
|
|
524
|
+
SelectionPlugin.prototype.setTableDragSelection = function (editor, rawEvent) {
|
|
525
|
+
var doc = editor.getDocument();
|
|
526
|
+
var cell = editor
|
|
527
|
+
.getDOMHelper()
|
|
528
|
+
.findClosestElementAncestor(rawEvent.target, 'td,th');
|
|
529
|
+
if (cell) {
|
|
530
|
+
// Hide the table cell selection styles (grey cell background applied by
|
|
531
|
+
// setDOMSelection) and the native selection highlight so that only the
|
|
532
|
+
// dragged content is visible while dragging. Also restore the caret which
|
|
533
|
+
// is hidden while a table selection is active.
|
|
534
|
+
editor.setEditorStyle(DOM_SELECTION_CSS_KEY, null /*cssRule*/);
|
|
535
|
+
editor.setEditorStyle(HIDE_CURSOR_CSS_KEY, null /*cssRule*/);
|
|
536
|
+
var range = doc.createRange();
|
|
537
|
+
range.selectNodeContents(cell);
|
|
538
|
+
editor.getDOMHelper().setSelectionRange(range);
|
|
539
|
+
}
|
|
540
|
+
};
|
|
490
541
|
SelectionPlugin.prototype.getTextOffset = function (editor, range, td, isKeyUp) {
|
|
491
542
|
var doc = editor.getDocument();
|
|
492
543
|
var cursorRect = range
|