roosterjs-content-model-plugins 9.2.0 → 9.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/edit/keyboardDelete.js +1 -0
- package/lib/edit/keyboardDelete.js.map +1 -1
- package/lib/edit/keyboardInput.js +1 -0
- package/lib/edit/keyboardInput.js.map +1 -1
- package/lib/hyperlink/HyperlinkPlugin.js +4 -1
- package/lib/hyperlink/HyperlinkPlugin.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js.map +1 -1
- package/lib/tableEdit/OnTableEditorCreatedCallback.d.ts +2 -1
- package/lib/tableEdit/OnTableEditorCreatedCallback.js.map +1 -1
- package/lib/tableEdit/TableEditPlugin.d.ts +4 -1
- package/lib/tableEdit/TableEditPlugin.js +4 -2
- package/lib/tableEdit/TableEditPlugin.js.map +1 -1
- package/lib/tableEdit/editors/TableEditor.d.ts +6 -1
- package/lib/tableEdit/editors/TableEditor.js +32 -12
- package/lib/tableEdit/editors/TableEditor.js.map +1 -1
- package/lib/tableEdit/editors/features/CellResizer.d.ts +9 -1
- package/lib/tableEdit/editors/features/CellResizer.js +11 -3
- package/lib/tableEdit/editors/features/CellResizer.js.map +1 -1
- package/lib/tableEdit/editors/features/TableEditFeature.d.ts +1 -1
- package/lib/tableEdit/editors/features/TableEditFeature.js +6 -6
- package/lib/tableEdit/editors/features/TableEditFeature.js.map +1 -1
- package/lib/tableEdit/editors/features/TableEditFeatureName.d.ts +4 -0
- package/lib/tableEdit/editors/features/TableEditFeatureName.js +3 -0
- package/lib/tableEdit/editors/features/TableEditFeatureName.js.map +1 -0
- package/lib/tableEdit/editors/features/TableInserter.d.ts +9 -1
- package/lib/tableEdit/editors/features/TableInserter.js +11 -3
- package/lib/tableEdit/editors/features/TableInserter.js.map +1 -1
- package/lib/tableEdit/editors/features/TableMover.d.ts +48 -4
- package/lib/tableEdit/editors/features/TableMover.js +209 -18
- package/lib/tableEdit/editors/features/TableMover.js.map +1 -1
- package/lib/tableEdit/editors/features/TableResizer.d.ts +5 -1
- package/lib/tableEdit/editors/features/TableResizer.js +6 -3
- package/lib/tableEdit/editors/features/TableResizer.js.map +1 -1
- package/lib/watermark/WatermarkPlugin.d.ts +1 -1
- package/lib/watermark/WatermarkPlugin.js +2 -1
- package/lib/watermark/WatermarkPlugin.js.map +1 -1
- package/lib/watermark/isModelEmptyFast.js +4 -0
- package/lib/watermark/isModelEmptyFast.js.map +1 -1
- package/lib-amd/edit/keyboardDelete.js +1 -0
- package/lib-amd/edit/keyboardDelete.js.map +1 -1
- package/lib-amd/edit/keyboardInput.js +1 -0
- package/lib-amd/edit/keyboardInput.js.map +1 -1
- package/lib-amd/hyperlink/HyperlinkPlugin.js +4 -1
- package/lib-amd/hyperlink/HyperlinkPlugin.js.map +1 -1
- package/lib-amd/index.d.ts +1 -0
- package/lib-amd/index.js.map +1 -1
- package/lib-amd/tableEdit/OnTableEditorCreatedCallback.d.ts +2 -1
- package/lib-amd/tableEdit/OnTableEditorCreatedCallback.js.map +1 -1
- package/lib-amd/tableEdit/TableEditPlugin.d.ts +4 -1
- package/lib-amd/tableEdit/TableEditPlugin.js +4 -2
- package/lib-amd/tableEdit/TableEditPlugin.js.map +1 -1
- package/lib-amd/tableEdit/editors/TableEditor.d.ts +6 -1
- package/lib-amd/tableEdit/editors/TableEditor.js +32 -12
- package/lib-amd/tableEdit/editors/TableEditor.js.map +1 -1
- package/lib-amd/tableEdit/editors/features/CellResizer.d.ts +9 -1
- package/lib-amd/tableEdit/editors/features/CellResizer.js +11 -3
- package/lib-amd/tableEdit/editors/features/CellResizer.js.map +1 -1
- package/lib-amd/tableEdit/editors/features/TableEditFeature.d.ts +1 -1
- package/lib-amd/tableEdit/editors/features/TableEditFeature.js +6 -6
- package/lib-amd/tableEdit/editors/features/TableEditFeature.js.map +1 -1
- package/lib-amd/tableEdit/editors/features/TableEditFeatureName.d.ts +4 -0
- package/lib-amd/tableEdit/editors/features/TableEditFeatureName.js +5 -0
- package/lib-amd/tableEdit/editors/features/TableEditFeatureName.js.map +1 -0
- package/lib-amd/tableEdit/editors/features/TableInserter.d.ts +9 -1
- package/lib-amd/tableEdit/editors/features/TableInserter.js +11 -3
- package/lib-amd/tableEdit/editors/features/TableInserter.js.map +1 -1
- package/lib-amd/tableEdit/editors/features/TableMover.d.ts +48 -4
- package/lib-amd/tableEdit/editors/features/TableMover.js +209 -19
- package/lib-amd/tableEdit/editors/features/TableMover.js.map +1 -1
- package/lib-amd/tableEdit/editors/features/TableResizer.d.ts +5 -1
- package/lib-amd/tableEdit/editors/features/TableResizer.js +6 -3
- package/lib-amd/tableEdit/editors/features/TableResizer.js.map +1 -1
- package/lib-amd/watermark/WatermarkPlugin.d.ts +1 -1
- package/lib-amd/watermark/WatermarkPlugin.js +2 -1
- package/lib-amd/watermark/WatermarkPlugin.js.map +1 -1
- package/lib-amd/watermark/isModelEmptyFast.js +4 -0
- package/lib-amd/watermark/isModelEmptyFast.js.map +1 -1
- package/lib-mjs/edit/keyboardDelete.js +1 -0
- package/lib-mjs/edit/keyboardDelete.js.map +1 -1
- package/lib-mjs/edit/keyboardInput.js +1 -0
- package/lib-mjs/edit/keyboardInput.js.map +1 -1
- package/lib-mjs/hyperlink/HyperlinkPlugin.js +4 -1
- package/lib-mjs/hyperlink/HyperlinkPlugin.js.map +1 -1
- package/lib-mjs/index.d.ts +1 -0
- package/lib-mjs/index.js.map +1 -1
- package/lib-mjs/tableEdit/OnTableEditorCreatedCallback.d.ts +2 -1
- package/lib-mjs/tableEdit/OnTableEditorCreatedCallback.js.map +1 -1
- package/lib-mjs/tableEdit/TableEditPlugin.d.ts +4 -1
- package/lib-mjs/tableEdit/TableEditPlugin.js +4 -2
- package/lib-mjs/tableEdit/TableEditPlugin.js.map +1 -1
- package/lib-mjs/tableEdit/editors/TableEditor.d.ts +6 -1
- package/lib-mjs/tableEdit/editors/TableEditor.js +32 -12
- package/lib-mjs/tableEdit/editors/TableEditor.js.map +1 -1
- package/lib-mjs/tableEdit/editors/features/CellResizer.d.ts +9 -1
- package/lib-mjs/tableEdit/editors/features/CellResizer.js +10 -2
- package/lib-mjs/tableEdit/editors/features/CellResizer.js.map +1 -1
- package/lib-mjs/tableEdit/editors/features/TableEditFeature.d.ts +1 -1
- package/lib-mjs/tableEdit/editors/features/TableEditFeature.js +6 -6
- package/lib-mjs/tableEdit/editors/features/TableEditFeature.js.map +1 -1
- package/lib-mjs/tableEdit/editors/features/TableEditFeatureName.d.ts +4 -0
- package/lib-mjs/tableEdit/editors/features/TableEditFeatureName.js +2 -0
- package/lib-mjs/tableEdit/editors/features/TableEditFeatureName.js.map +1 -0
- package/lib-mjs/tableEdit/editors/features/TableInserter.d.ts +9 -1
- package/lib-mjs/tableEdit/editors/features/TableInserter.js +10 -2
- package/lib-mjs/tableEdit/editors/features/TableInserter.js.map +1 -1
- package/lib-mjs/tableEdit/editors/features/TableMover.d.ts +48 -4
- package/lib-mjs/tableEdit/editors/features/TableMover.js +206 -18
- package/lib-mjs/tableEdit/editors/features/TableMover.js.map +1 -1
- package/lib-mjs/tableEdit/editors/features/TableResizer.d.ts +5 -1
- package/lib-mjs/tableEdit/editors/features/TableResizer.js +4 -1
- package/lib-mjs/tableEdit/editors/features/TableResizer.js.map +1 -1
- package/lib-mjs/watermark/WatermarkPlugin.d.ts +1 -1
- package/lib-mjs/watermark/WatermarkPlugin.js +2 -1
- package/lib-mjs/watermark/WatermarkPlugin.js.map +1 -1
- package/lib-mjs/watermark/isModelEmptyFast.js +4 -0
- package/lib-mjs/watermark/isModelEmptyFast.js.map +1 -1
- package/package.json +5 -5
|
@@ -27,6 +27,7 @@ function keyboardDelete(editor, rawEvent) {
|
|
|
27
27
|
rawEvent: rawEvent,
|
|
28
28
|
changeSource: roosterjs_content_model_dom_1.ChangeSource.Keyboard,
|
|
29
29
|
getChangeData: function () { return rawEvent.which; },
|
|
30
|
+
scrollCaretIntoView: false,
|
|
30
31
|
apiName: rawEvent.key == 'Delete' ? 'handleDeleteKey' : 'handleBackspaceKey',
|
|
31
32
|
});
|
|
32
33
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyboardDelete.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/edit/keyboardDelete.ts"],"names":[],"mappings":";;;AAAA,+EAA8E;AAC9E,mEAAkE;AAClE,uDAAsD;AACtD,2EAKqC;AACrC,yEAIqC;AACrC,yEAG2C;AAC3C,mFAGgD;AAGhD;;;;;;GAMG;AACH,SAAgB,cAAc,CAAC,MAAe,EAAE,QAAuB;IACnE,IAAI,OAAO,GAAG,KAAK,CAAC;IACpB,IAAM,SAAS,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC;IAE3C,IAAI,4BAA4B,CAAC,SAAS,EAAE,QAAQ,CAAC,EAAE;QACnD,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;YACX,IAAM,MAAM,GAAG,IAAA,6CAAe,EAC1B,KAAK,EACL,cAAc,CAAC,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC,KAAK,CAAC,EACzD,OAAO,CACV,CAAC,YAAY,CAAC;YAEf,OAAO,GAAG,IAAA,qDAAyB,EAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;YAC9E,OAAO,OAAO,CAAC;QACnB,CAAC,EACD;YACI,QAAQ,UAAA;YACR,YAAY,EAAE,0CAAY,CAAC,QAAQ;YACnC,aAAa,EAAE,cAAM,OAAA,QAAQ,CAAC,KAAK,EAAd,CAAc;YACnC,OAAO,EAAE,QAAQ,CAAC,GAAG,IAAI,QAAQ,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,oBAAoB;SAC/E,CACJ,CAAC;KACL;IAED,OAAO,OAAO,CAAC;AACnB,CAAC;
|
|
1
|
+
{"version":3,"file":"keyboardDelete.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-pl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I,WAAW,IAAI,KAAK,CAAC,WAAW,GAAG,CAAC,CAAC;AAChE,CAAC;AAED,SAAS,cAAc,CAAC,QAAuB,EAAE,KAAY;;IACzD,OAAO,CACH,QAAQ,CAAC,GAAG,IAAI,QAAQ;QACxB,KAAK,CAAC,WAAW,GAAG,CAAC,MAAA,MAAA,KAAK,CAAC,cAAc,CAAC,SAAS,0CAAE,MAAM,mCAAI,CAAC,CAAC,GAAG,CAAC,CACxE,CAAC;AACN,CAAC","sourcesContent":["import { deleteAllSegmentBefore } from './deleteSteps/deleteAllSegmentBefore';\nimport { deleteEmptyQuote } from './deleteSteps/deleteEmptyQuote';\nimport { deleteList } from './deleteSteps/deleteList';\nimport {\n ChangeSource,\n deleteSelection,\n isModifierKey,\n isNodeOfType,\n} from 'roosterjs-content-model-dom';\nimport {\n handleKeyboardEventResult,\n shouldDeleteAllSegmentsBefore,\n shouldDeleteWord,\n} from './handleKeyboardEventCommon';\nimport {\n backwardDeleteWordSelection,\n forwardDeleteWordSelection,\n} from './deleteSteps/deleteWordSelection';\nimport {\n backwardDeleteCollapsedSelection,\n forwardDeleteCollapsedSelection,\n} from './deleteSteps/deleteCollapsedSelection';\nimport type { DOMSelection, DeleteSelectionStep, IEditor } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n * Do keyboard event handling for DELETE/BACKSPACE key\n * @param editor The editor object\n * @param rawEvent DOM keyboard event\n * @returns True if the event is handled by content model, otherwise false\n */\nexport function keyboardDelete(editor: IEditor, rawEvent: KeyboardEvent) {\n let handled = false;\n const selection = editor.getDOMSelection();\n\n if (shouldDeleteWithContentModel(selection, rawEvent)) {\n editor.formatContentModel(\n (model, context) => {\n const result = deleteSelection(\n model,\n getDeleteSteps(rawEvent, !!editor.getEnvironment().isMac),\n context\n ).deleteResult;\n\n handled = handleKeyboardEventResult(editor, model, rawEvent, result, context);\n return handled;\n },\n {\n rawEvent,\n changeSource: ChangeSource.Keyboard,\n getChangeData: () => rawEvent.which,\n scrollCaretIntoView: false, // TODO #2633: Make a full fix to the scroll behavior\n apiName: rawEvent.key == 'Delete' ? 'handleDeleteKey' : 'handleBackspaceKey',\n }\n );\n }\n\n return handled;\n}\n\nfunction getDeleteSteps(rawEvent: KeyboardEvent, isMac: boolean): (DeleteSelectionStep | null)[] {\n const isForward = rawEvent.key == 'Delete';\n const deleteAllSegmentBeforeStep =\n shouldDeleteAllSegmentsBefore(rawEvent) && !isForward ? deleteAllSegmentBefore : null;\n const deleteWordSelection = shouldDeleteWord(rawEvent, isMac)\n ? isForward\n ? forwardDeleteWordSelection\n : backwardDeleteWordSelection\n : null;\n const deleteCollapsedSelection = isForward\n ? forwardDeleteCollapsedSelection\n : backwardDeleteCollapsedSelection;\n const deleteQuote = !isForward ? deleteEmptyQuote : null;\n return [\n deleteAllSegmentBeforeStep,\n deleteWordSelection,\n isForward ? null : deleteList,\n deleteCollapsedSelection,\n deleteQuote,\n ];\n}\n\nfunction shouldDeleteWithContentModel(selection: DOMSelection | null, rawEvent: KeyboardEvent) {\n if (!selection) {\n return false; // Nothing to delete\n } else if (selection.type != 'range' || !selection.range.collapsed) {\n return true; // Selection is not collapsed, need to delete all selections\n } else {\n const range = selection.range;\n\n // When selection is collapsed and is in middle of text node, no need to use Content Model to delete\n return !(\n isNodeOfType(range.startContainer, 'TEXT_NODE') &&\n !isModifierKey(rawEvent) &&\n (canDeleteBefore(rawEvent, range) || canDeleteAfter(rawEvent, range))\n );\n }\n}\n\nfunction canDeleteBefore(rawEvent: KeyboardEvent, range: Range) {\n return rawEvent.key == 'Backspace' && range.startOffset > 1;\n}\n\nfunction canDeleteAfter(rawEvent: KeyboardEvent, range: Range) {\n return (\n rawEvent.key == 'Delete' &&\n range.startOffset < (range.startContainer.nodeValue?.length ?? 0) - 1\n );\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyboardInput.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/edit/keyboardInput.ts"],"names":[],"mappings":";;;AAAA,mEAAkE;AAClE,2EAAoG;AACpG,oEAAmE;AAGnE;;GAEG;AACH,SAAgB,aAAa,CAAC,MAAe,EAAE,QAAuB;IAClE,IAAM,SAAS,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC;IAE3C,IAAI,2BAA2B,CAAC,SAAS,EAAE,QAAQ,CAAC,EAAE;QAClD,MAAM,CAAC,YAAY,EAAE,CAAC;QAEtB,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;;YACX,IAAM,MAAM,GAAG,IAAA,6CAAe,EAAC,KAAK,EAAE,aAAa,CAAC,SAAS,EAAE,QAAQ,CAAC,EAAE,OAAO,CAAC,CAAC;YAEnF,0EAA0E;YAC1E,qFAAqF;YACrF,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;YAE/B,oJAAoJ;YACpJ,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC;YAEhC,IAAI,MAAM,CAAC,YAAY,IAAI,OAAO,EAAE;gBAChC,2HAA2H;gBAC3H,OAAO,CAAC,gBAAgB,GAAG,MAAA,MAAM,CAAC,WAAW,0CAAE,MAAM,CAAC,MAAM,CAAC;gBAE7D,IAAA,mDAAqB,EAAC,KAAK,CAAC,CAAC;gBAE7B,sFAAsF;gBACtF,OAAO,IAAI,CAAC;aACf;iBAAM;gBACH,OAAO,KAAK,CAAC;aAChB;QACL,CAAC,EACD;YACI,QAAQ,UAAA;SACX,CACJ,CAAC;QAEF,OAAO,IAAI,CAAC;KACf;AACL,CAAC;
|
|
1
|
+
{"version":3,"file":"keyboardInput.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/edit/keyboardInput.ts"],"names":[],"mappings":";;;AAAA,mEAAkE;AAClE,2EAAoG;AACpG,oEAAmE;AAGnE;;GAEG;AACH,SAAgB,aAAa,CAAC,MAAe,EAAE,QAAuB;IAClE,IAAM,SAAS,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC;IAE3C,IAAI,2BAA2B,CAA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I,OAAO,IAAI,QAAQ,CAAC,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC,EAClF;QACE,OAAO,CACH,SAAS,CAAC,IAAI,IAAI,OAAO;YACzB,CAAC,SAAS,CAAC,KAAK,CAAC,SAAS;YAC1B,oBAAoB,CAAC,SAAS,EAAE,QAAQ,CAAC,CAC5C,CAAC;KACL;SAAM;QACH,OAAO,KAAK,CAAC;KAChB;AACL,CAAC;AAED,IAAM,oBAAoB,GAAG,UAAC,SAA8B,EAAE,QAAuB;IACjF,OAAO,SAAS,IAAI,SAAS,CAAC,IAAI,IAAI,OAAO,IAAI,QAAQ,CAAC,GAAG,IAAI,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC;AACnG,CAAC,CAAC","sourcesContent":["import { deleteEmptyQuote } from './deleteSteps/deleteEmptyQuote';\nimport { deleteSelection, isModifierKey, normalizeContentModel } from 'roosterjs-content-model-dom';\nimport { handleEnterOnList } from './inputSteps/handleEnterOnList';\nimport type { DOMSelection, IEditor } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function keyboardInput(editor: IEditor, rawEvent: KeyboardEvent) {\n const selection = editor.getDOMSelection();\n\n if (shouldInputWithContentModel(selection, rawEvent)) {\n editor.takeSnapshot();\n\n editor.formatContentModel(\n (model, context) => {\n const result = deleteSelection(model, getInputSteps(selection, rawEvent), context);\n\n // We have deleted selection then we will let browser to handle the input.\n // With this combined operation, we don't wan to mass up the cached model so clear it\n context.clearModelCache = true;\n\n // Skip undo snapshot here and add undo snapshot before the operation so that we don't add another undo snapshot in middle of this replace operation\n context.skipUndoSnapshot = true;\n\n if (result.deleteResult == 'range') {\n // We have deleted something, next input should inherit the segment format from deleted content, so set pending format here\n context.newPendingFormat = result.insertPoint?.marker.format;\n\n normalizeContentModel(model);\n\n // Do not preventDefault since we still want browser to handle the final input for now\n return true;\n } else {\n return false;\n }\n },\n {\n scrollCaretIntoView: false, // TODO #2633: Make a full fix to the scroll behavior\n rawEvent,\n }\n );\n\n return true;\n }\n}\n\nfunction getInputSteps(selection: DOMSelection | null, rawEvent: KeyboardEvent) {\n return shouldHandleEnterKey(selection, rawEvent) ? [handleEnterOnList, deleteEmptyQuote] : [];\n}\n\nfunction shouldInputWithContentModel(selection: DOMSelection | null, rawEvent: KeyboardEvent) {\n if (!selection) {\n return false; // Nothing to delete\n } else if (\n !isModifierKey(rawEvent) &&\n (rawEvent.key == 'Enter' || rawEvent.key == 'Space' || rawEvent.key.length == 1)\n ) {\n return (\n selection.type != 'range' ||\n !selection.range.collapsed ||\n shouldHandleEnterKey(selection, rawEvent)\n );\n } else {\n return false;\n }\n}\n\nconst shouldHandleEnterKey = (selection: DOMSelection | null, rawEvent: KeyboardEvent) => {\n return selection && selection.type == 'range' && rawEvent.key == 'Enter' && !rawEvent.shiftKey;\n};\n"]}
|
|
@@ -78,7 +78,7 @@ var HyperlinkPlugin = /** @class */ (function () {
|
|
|
78
78
|
*/
|
|
79
79
|
HyperlinkPlugin.prototype.onPluginEvent = function (event) {
|
|
80
80
|
var _this = this;
|
|
81
|
-
var _a, _b;
|
|
81
|
+
var _a, _b, _c;
|
|
82
82
|
var matchedLink;
|
|
83
83
|
if (event.eventType == 'keyDown') {
|
|
84
84
|
var selection = (_a = this.editor) === null || _a === void 0 ? void 0 : _a.getDOMSelection();
|
|
@@ -123,6 +123,9 @@ var HyperlinkPlugin = /** @class */ (function () {
|
|
|
123
123
|
}
|
|
124
124
|
});
|
|
125
125
|
}
|
|
126
|
+
else if (event.eventType == 'contentChanged') {
|
|
127
|
+
(_c = this.domHelper) === null || _c === void 0 ? void 0 : _c.setDomAttribute('title', null /*value*/);
|
|
128
|
+
}
|
|
126
129
|
};
|
|
127
130
|
HyperlinkPlugin.prototype.runWithHyperlink = function (node, callback) {
|
|
128
131
|
var _a;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HyperlinkPlugin.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/hyperlink/H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K,CAAC,QAAQ,CAAC,cAAc,EAAE,CAAC;oBAEhC,IAAM,MAAM,GAAG,KAAI,CAAC,MAAM,IAAI,QAAQ,CAAC;oBACvC,IAAM,QAAM,GAAG,MAAA,KAAI,CAAC,MAAM,0CAAE,WAAW,GAAG,WAAW,CAAC;oBAEtD,IAAI;wBACA,QAAM,aAAN,QAAM,uBAAN,QAAM,CAAE,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;qBAC9B;oBAAC,WAAM,GAAE;iBACb;YACL,CAAC,CAAC,CAAC;SACN;IACL,CAAC;IAcO,0CAAgB,GAAxB,UAAyB,IAAU,EAAE,QAAsD;;QACvF,IAAM,CAAC,GAAG,MAAA,IAAI,CAAC,SAAS,0CAAE,0BAA0B,CAChD,IAAI,EACJ,SAAS,CACgB,CAAC;QAC9B,IAAM,IAAI,GAAG,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,YAAY,CAAC,MAAM,CAAC,CAAC;QAErC,IAAI,IAAI,IAAI,CAAC,EAAE;YACX,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;SACrB;IACL,CAAC;IAEO,6CAAmB,GAA3B,UAA4B,KAAiC;QACzD,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC;IACtD,CAAC;IACL,sBAAC;AAAD,CAAC,AAjJD,IAiJC;AAjJY,0CAAe","sourcesContent":["import { matchLink } from 'roosterjs-content-model-api';\nimport type { HyperlinkToolTip } from './HyperlinkToolTip';\nimport type {\n DOMHelper,\n EditorPlugin,\n IEditor,\n PluginEvent,\n LinkData,\n} from 'roosterjs-content-model-types';\n\nconst defaultToolTipCallback: HyperlinkToolTip = (url: string) => url;\n\n/**\n * Hyperlink plugin does the following jobs for a hyperlink in editor:\n * 1. When hover on a link, show a tool tip\n * 2. When Ctrl+Click on a link, open a new window with the link\n * 3. When type directly on a link whose text matches its link url, update the link url with the link text\n */\nexport class HyperlinkPlugin implements EditorPlugin {\n private editor: IEditor | null = null;\n private domHelper: DOMHelper | null = null;\n private isMac: boolean = false;\n private disposer: (() => void) | null = null;\n\n private currentNode: Node | null = null;\n private currentLink: HTMLAnchorElement | null = null;\n\n /**\n * Create a new instance of HyperLink class\n * @param tooltip Tooltip to show when mouse hover over a link\n * Default value is to return the href itself. If null, there will be no tooltip text.\n * @param target (Optional) Target window name for hyperlink. If null, will use \"_blank\"\n * @param onLinkClick (Optional) Open link callback (return false to use default behavior)\n */\n constructor(\n private tooltip: HyperlinkToolTip = defaultToolTipCallback,\n private target?: string,\n private onLinkClick?: (anchor: HTMLAnchorElement, mouseEvent: MouseEvent) => boolean | void\n ) {}\n\n /**\n * Get a friendly name of this plugin\n */\n getName() {\n return 'Hyperlink';\n }\n\n /**\n * Initialize this plugin\n * @param editor The editor instance\n */\n public initialize(editor: IEditor): void {\n this.editor = editor;\n this.domHelper = editor.getDOMHelper();\n this.isMac = !!editor.getEnvironment().isMac;\n this.disposer = editor.attachDomEvent({\n mouseover: { beforeDispatch: this.onMouse },\n mouseout: { beforeDispatch: this.onMouse },\n });\n }\n\n /**\n * Dispose this plugin\n */\n public dispose(): void {\n if (this.disposer) {\n this.disposer();\n this.disposer = null;\n }\n\n this.currentNode = null;\n this.currentLink = null;\n this.editor = null;\n }\n\n /**\n * Handle events triggered from editor\n * @param event PluginEvent object\n */\n public onPluginEvent(event: PluginEvent): void {\n let matchedLink: LinkData | null;\n\n if (event.eventType == 'keyDown') {\n const selection = this.editor?.getDOMSelection();\n const node =\n selection?.type == 'range' ? selection.range.commonAncestorContainer : null;\n\n if (node && node != this.currentNode) {\n this.currentNode = node;\n this.currentLink = null;\n\n this.runWithHyperlink(node, (href, a) => {\n if (\n node.textContent &&\n (matchedLink = matchLink(node.textContent)) &&\n matchedLink.normalizedUrl == href\n ) {\n this.currentLink = a;\n }\n });\n }\n } else if (event.eventType == 'keyUp') {\n const selection = this.editor?.getDOMSelection();\n const node =\n selection?.type == 'range' ? selection.range.commonAncestorContainer : null;\n\n if (\n node &&\n node == this.currentNode &&\n this.currentLink &&\n this.currentLink.contains(node) &&\n node.textContent &&\n (matchedLink = matchLink(node.textContent))\n ) {\n this.currentLink.setAttribute('href', matchedLink.normalizedUrl);\n }\n } else if (event.eventType == 'mouseUp' && event.isClicking) {\n this.runWithHyperlink(event.rawEvent.target as Node, (href, anchor) => {\n if (\n !this.onLinkClick?.(anchor, event.rawEvent) &&\n this.isCtrlOrMetaPressed(event.rawEvent) &&\n event.rawEvent.button === 0\n ) {\n event.rawEvent.preventDefault();\n\n const target = this.target || '_blank';\n const window = this.editor?.getDocument().defaultView;\n\n try {\n window?.open(href, target);\n } catch {}\n }\n });\n }\n }\n\n protected onMouse = (e: Event) => {\n this.runWithHyperlink(e.target as Node, (href, a) => {\n const tooltip =\n e.type == 'mouseover'\n ? typeof this.tooltip == 'function'\n ? this.tooltip(href, a)\n : this.tooltip\n : null;\n this.domHelper?.setDomAttribute('title', tooltip);\n });\n };\n\n private runWithHyperlink(node: Node, callback: (href: string, a: HTMLAnchorElement) => void) {\n const a = this.domHelper?.findClosestElementAncestor(\n node,\n 'a[href]'\n ) as HTMLAnchorElement | null;\n const href = a?.getAttribute('href');\n\n if (href && a) {\n callback(href, a);\n }\n }\n\n private isCtrlOrMetaPressed(event: KeyboardEvent | MouseEvent): boolean {\n return this.isMac ? event.metaKey : event.ctrlKey;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"HyperlinkPlugin.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/hyperlink/HyperlinkPlugin.ts"],"names":[],"mappings":";;;AAAA,2EAAwD;AAUxD,IAAM,sBAAsB,GAAqB,UAAC,GAAW,IAAK,OAAA,GAAG,EAAH,CAAG,CAAC;AAEtE;;;;;GAKG;AACH;IASI;;;;;;OAMG;IACH,yBACY,OAAkD,EAClD,MAAe,EACf,WAAmF;QAH/F,iBAII;QAHQ,wBAAA,EAAA,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E,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;qBAC9B;oBAAC,WAAM,GAAE;iBACb;YACL,CAAC,CAAC,CAAC;SACN;aAAM,IAAI,KAAK,CAAC,SAAS,IAAI,gBAAgB,EAAE;YAC5C,MAAA,IAAI,CAAC,SAAS,0CAAE,eAAe,CAAC,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;SAC5D;IACL,CAAC;IAcO,0CAAgB,GAAxB,UAAyB,IAAU,EAAE,QAAsD;;QACvF,IAAM,CAAC,GAAG,MAAA,IAAI,CAAC,SAAS,0CAAE,0BAA0B,CAChD,IAAI,EACJ,SAAS,CACgB,CAAC;QAC9B,IAAM,IAAI,GAAG,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,YAAY,CAAC,MAAM,CAAC,CAAC;QAErC,IAAI,IAAI,IAAI,CAAC,EAAE;YACX,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;SACrB;IACL,CAAC;IAEO,6CAAmB,GAA3B,UAA4B,KAAiC;QACzD,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC;IACtD,CAAC;IACL,sBAAC;AAAD,CAAC,AAnJD,IAmJC;AAnJY,0CAAe","sourcesContent":["import { matchLink } from 'roosterjs-content-model-api';\nimport type { HyperlinkToolTip } from './HyperlinkToolTip';\nimport type {\n DOMHelper,\n EditorPlugin,\n IEditor,\n PluginEvent,\n LinkData,\n} from 'roosterjs-content-model-types';\n\nconst defaultToolTipCallback: HyperlinkToolTip = (url: string) => url;\n\n/**\n * Hyperlink plugin does the following jobs for a hyperlink in editor:\n * 1. When hover on a link, show a tool tip\n * 2. When Ctrl+Click on a link, open a new window with the link\n * 3. When type directly on a link whose text matches its link url, update the link url with the link text\n */\nexport class HyperlinkPlugin implements EditorPlugin {\n private editor: IEditor | null = null;\n private domHelper: DOMHelper | null = null;\n private isMac: boolean = false;\n private disposer: (() => void) | null = null;\n\n private currentNode: Node | null = null;\n private currentLink: HTMLAnchorElement | null = null;\n\n /**\n * Create a new instance of HyperLink class\n * @param tooltip Tooltip to show when mouse hover over a link\n * Default value is to return the href itself. If null, there will be no tooltip text.\n * @param target (Optional) Target window name for hyperlink. If null, will use \"_blank\"\n * @param onLinkClick (Optional) Open link callback (return false to use default behavior)\n */\n constructor(\n private tooltip: HyperlinkToolTip = defaultToolTipCallback,\n private target?: string,\n private onLinkClick?: (anchor: HTMLAnchorElement, mouseEvent: MouseEvent) => boolean | void\n ) {}\n\n /**\n * Get a friendly name of this plugin\n */\n getName() {\n return 'Hyperlink';\n }\n\n /**\n * Initialize this plugin\n * @param editor The editor instance\n */\n public initialize(editor: IEditor): void {\n this.editor = editor;\n this.domHelper = editor.getDOMHelper();\n this.isMac = !!editor.getEnvironment().isMac;\n this.disposer = editor.attachDomEvent({\n mouseover: { beforeDispatch: this.onMouse },\n mouseout: { beforeDispatch: this.onMouse },\n });\n }\n\n /**\n * Dispose this plugin\n */\n public dispose(): void {\n if (this.disposer) {\n this.disposer();\n this.disposer = null;\n }\n\n this.currentNode = null;\n this.currentLink = null;\n this.editor = null;\n }\n\n /**\n * Handle events triggered from editor\n * @param event PluginEvent object\n */\n public onPluginEvent(event: PluginEvent): void {\n let matchedLink: LinkData | null;\n\n if (event.eventType == 'keyDown') {\n const selection = this.editor?.getDOMSelection();\n const node =\n selection?.type == 'range' ? selection.range.commonAncestorContainer : null;\n\n if (node && node != this.currentNode) {\n this.currentNode = node;\n this.currentLink = null;\n\n this.runWithHyperlink(node, (href, a) => {\n if (\n node.textContent &&\n (matchedLink = matchLink(node.textContent)) &&\n matchedLink.normalizedUrl == href\n ) {\n this.currentLink = a;\n }\n });\n }\n } else if (event.eventType == 'keyUp') {\n const selection = this.editor?.getDOMSelection();\n const node =\n selection?.type == 'range' ? selection.range.commonAncestorContainer : null;\n\n if (\n node &&\n node == this.currentNode &&\n this.currentLink &&\n this.currentLink.contains(node) &&\n node.textContent &&\n (matchedLink = matchLink(node.textContent))\n ) {\n this.currentLink.setAttribute('href', matchedLink.normalizedUrl);\n }\n } else if (event.eventType == 'mouseUp' && event.isClicking) {\n this.runWithHyperlink(event.rawEvent.target as Node, (href, anchor) => {\n if (\n !this.onLinkClick?.(anchor, event.rawEvent) &&\n this.isCtrlOrMetaPressed(event.rawEvent) &&\n event.rawEvent.button === 0\n ) {\n event.rawEvent.preventDefault();\n\n const target = this.target || '_blank';\n const window = this.editor?.getDocument().defaultView;\n\n try {\n window?.open(href, target);\n } catch {}\n }\n });\n } else if (event.eventType == 'contentChanged') {\n this.domHelper?.setDomAttribute('title', null /*value*/);\n }\n }\n\n protected onMouse = (e: Event) => {\n this.runWithHyperlink(e.target as Node, (href, a) => {\n const tooltip =\n e.type == 'mouseover'\n ? typeof this.tooltip == 'function'\n ? this.tooltip(href, a)\n : this.tooltip\n : null;\n this.domHelper?.setDomAttribute('title', tooltip);\n });\n };\n\n private runWithHyperlink(node: Node, callback: (href: string, a: HTMLAnchorElement) => void) {\n const a = this.domHelper?.findClosestElementAncestor(\n node,\n 'a[href]'\n ) as HTMLAnchorElement | null;\n const href = a?.getAttribute('href');\n\n if (href && a) {\n callback(href, a);\n }\n }\n\n private isCtrlOrMetaPressed(event: KeyboardEvent | MouseEvent): boolean {\n return this.isMac ? event.metaKey : event.ctrlKey;\n }\n}\n"]}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { TableEditPlugin } from './tableEdit/TableEditPlugin';
|
|
2
2
|
export { OnTableEditorCreatedCallback } from './tableEdit/OnTableEditorCreatedCallback';
|
|
3
|
+
export { TableEditFeatureName } from './tableEdit/editors/features/TableEditFeatureName';
|
|
3
4
|
export { PastePlugin } from './paste/PastePlugin';
|
|
4
5
|
export { EditPlugin } from './edit/EditPlugin';
|
|
5
6
|
export { AutoFormatPlugin, AutoFormatOptions } from './autoFormat/AutoFormatPlugin';
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../packages/roosterjs-content-model-plugins/lib/index.ts"],"names":[],"mappings":";;;AAAA,+DAA8D;AAArD,kHAAA,eAAe,OAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../packages/roosterjs-content-model-plugins/lib/index.ts"],"names":[],"mappings":";;;AAAA,+DAA8D;AAArD,kHAAA,eAAe,OAAA;AAGxB,mDAAkD;AAAzC,0GAAA,WAAW,OAAA;AACpB,gDAA+C;AAAtC,wGAAA,UAAU,OAAA;AACnB,kEAAoF;AAA3E,oHAAA,gBAAgB,OAAA;AAEzB,kDAgB8B;AAf1B,yGAAA,YAAY,OAAA;AACZ,2GAAA,cAAc,OAAA;AACd,8GAAA,iBAAiB,OAAA;AACjB,gHAAA,mBAAmB,OAAA;AACnB,yGAAA,YAAY,OAAA;AACZ,0GAAA,aAAa,OAAA;AACb,yGAAA,YAAY,OAAA;AACZ,4GAAA,eAAe,OAAA;AACf,8GAAA,iBAAiB,OAAA;AACjB,2GAAA,cAAc,OAAA;AACd,8GAAA,iBAAiB,OAAA;AACjB,iHAAA,oBAAoB,OAAA;AACpB,iHAAA,oBAAoB,OAAA;AACpB,+GAAA,kBAAkB,OAAA;AAClB,gHAAA,mBAAmB,OAAA;AAEvB,4DAA2D;AAAlD,gHAAA,cAAc,OAAA;AAEvB,iFAAoG;AAA3F,8HAAA,qBAAqB,OAAA;AAC9B,+DAA8D;AAArD,kHAAA,eAAe,OAAA;AAExB,4DAA4E;AAAnE,gHAAA,cAAc,OAAA;AACvB,+DAA8D;AAArD,kHAAA,eAAe,OAAA;AAExB,sDAAqD;AAA5C,4GAAA,YAAY,OAAA;AAGrB,2EAAyF;AAAhF,0HAAA,mBAAmB,OAAA;AAE5B,kFAAiF;AAAxE,8HAAA,qBAAqB,OAAA","sourcesContent":["export { TableEditPlugin } from './tableEdit/TableEditPlugin';\nexport { OnTableEditorCreatedCallback } from './tableEdit/OnTableEditorCreatedCallback';\nexport { TableEditFeatureName } from './tableEdit/editors/features/TableEditFeatureName';\nexport { PastePlugin } from './paste/PastePlugin';\nexport { EditPlugin } from './edit/EditPlugin';\nexport { AutoFormatPlugin, AutoFormatOptions } from './autoFormat/AutoFormatPlugin';\n\nexport {\n ShortcutBold,\n ShortcutItalic,\n ShortcutUnderline,\n ShortcutClearFormat,\n ShortcutUndo,\n ShortcutUndo2,\n ShortcutRedo,\n ShortcutRedoAlt,\n ShortcutRedoMacOS,\n ShortcutBullet,\n ShortcutNumbering,\n ShortcutIncreaseFont,\n ShortcutDecreaseFont,\n ShortcutIndentList,\n ShortcutOutdentList,\n} from './shortcut/shortcuts';\nexport { ShortcutPlugin } from './shortcut/ShortcutPlugin';\nexport { ShortcutKeyDefinition, ShortcutCommand } from './shortcut/ShortcutCommand';\nexport { ContextMenuPluginBase, ContextMenuOptions } from './contextMenuBase/ContextMenuPluginBase';\nexport { WatermarkPlugin } from './watermark/WatermarkPlugin';\nexport { WatermarkFormat } from './watermark/WatermarkFormat';\nexport { MarkdownPlugin, MarkdownOptions } from './markdown/MarkdownPlugin';\nexport { HyperlinkPlugin } from './hyperlink/HyperlinkPlugin';\nexport { HyperlinkToolTip } from './hyperlink/HyperlinkToolTip';\nexport { PickerPlugin } from './picker/PickerPlugin';\nexport { PickerHelper } from './picker/PickerHelper';\nexport { PickerSelectionChangMode, PickerDirection, PickerHandler } from './picker/PickerHandler';\nexport { CustomReplacePlugin, CustomReplace } from './customReplace/CustomReplacePlugin';\n\nexport { getDOMInsertPointRect } from './pluginUtils/Rect/getDOMInsertPointRect';\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
+
import type { TableEditFeatureName } from './editors/features/TableEditFeatureName';
|
|
1
2
|
/**
|
|
2
3
|
* Optional callback when creating a TableEditPlugin, allows to customize the Selectors element as required.
|
|
3
4
|
*/
|
|
4
|
-
export declare type OnTableEditorCreatedCallback = (
|
|
5
|
+
export declare type OnTableEditorCreatedCallback = (featureType: TableEditFeatureName, element: HTMLElement) => () => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OnTableEditorCreatedCallback.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/tableEdit/OnTableEditorCreatedCallback.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Optional callback when creating a TableEditPlugin, allows to customize the Selectors element as required.\n */\nexport type OnTableEditorCreatedCallback = (\n
|
|
1
|
+
{"version":3,"file":"OnTableEditorCreatedCallback.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/tableEdit/OnTableEditorCreatedCallback.ts"],"names":[],"mappings":"","sourcesContent":["import type { TableEditFeatureName } from './editors/features/TableEditFeatureName';\n\n/**\n * Optional callback when creating a TableEditPlugin, allows to customize the Selectors element as required.\n */\nexport type OnTableEditorCreatedCallback = (\n featureType: TableEditFeatureName,\n element: HTMLElement\n) => () => void;\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { TableEditFeatureName } from './editors/features/TableEditFeatureName';
|
|
1
2
|
import type { OnTableEditorCreatedCallback } from './OnTableEditorCreatedCallback';
|
|
2
3
|
import type { EditorPlugin, IEditor, PluginEvent } from 'roosterjs-content-model-types';
|
|
3
4
|
/**
|
|
@@ -6,6 +7,7 @@ import type { EditorPlugin, IEditor, PluginEvent } from 'roosterjs-content-model
|
|
|
6
7
|
export declare class TableEditPlugin implements EditorPlugin {
|
|
7
8
|
private anchorContainerSelector?;
|
|
8
9
|
private onTableEditorCreated?;
|
|
10
|
+
private disableFeatures?;
|
|
9
11
|
private editor;
|
|
10
12
|
private onMouseMoveDisposer;
|
|
11
13
|
private tableRectMap;
|
|
@@ -16,8 +18,9 @@ export declare class TableEditPlugin implements EditorPlugin {
|
|
|
16
18
|
* The container must not be affected by transform: scale(), otherwise the position calculation will be wrong.
|
|
17
19
|
* If not specified, the plugin will be inserted in document.body
|
|
18
20
|
* @param onTableEditorCreated An optional callback to customize the Table Editors elements when created.
|
|
21
|
+
* @param disableFeatures An optional array of TableEditFeatures to disable
|
|
19
22
|
*/
|
|
20
|
-
constructor(anchorContainerSelector?: string | undefined, onTableEditorCreated?: OnTableEditorCreatedCallback | undefined);
|
|
23
|
+
constructor(anchorContainerSelector?: string | undefined, onTableEditorCreated?: OnTableEditorCreatedCallback | undefined, disableFeatures?: TableEditFeatureName[] | undefined);
|
|
21
24
|
/**
|
|
22
25
|
* Get a friendly name of this plugin
|
|
23
26
|
*/
|
|
@@ -14,11 +14,13 @@ var TableEditPlugin = /** @class */ (function () {
|
|
|
14
14
|
* The container must not be affected by transform: scale(), otherwise the position calculation will be wrong.
|
|
15
15
|
* If not specified, the plugin will be inserted in document.body
|
|
16
16
|
* @param onTableEditorCreated An optional callback to customize the Table Editors elements when created.
|
|
17
|
+
* @param disableFeatures An optional array of TableEditFeatures to disable
|
|
17
18
|
*/
|
|
18
|
-
function TableEditPlugin(anchorContainerSelector, onTableEditorCreated) {
|
|
19
|
+
function TableEditPlugin(anchorContainerSelector, onTableEditorCreated, disableFeatures) {
|
|
19
20
|
var _this = this;
|
|
20
21
|
this.anchorContainerSelector = anchorContainerSelector;
|
|
21
22
|
this.onTableEditorCreated = onTableEditorCreated;
|
|
23
|
+
this.disableFeatures = disableFeatures;
|
|
22
24
|
this.editor = null;
|
|
23
25
|
this.onMouseMoveDisposer = null;
|
|
24
26
|
this.tableRectMap = null;
|
|
@@ -127,7 +129,7 @@ var TableEditPlugin = /** @class */ (function () {
|
|
|
127
129
|
var container = this.anchorContainerSelector
|
|
128
130
|
? this.editor.getDocument().querySelector(this.anchorContainerSelector)
|
|
129
131
|
: undefined;
|
|
130
|
-
this.tableEditor = new TableEditor_1.TableEditor(this.editor, table, this.invalidateTableRects, (0, roosterjs_content_model_dom_1.isNodeOfType)(container, 'ELEMENT_NODE') ? container : undefined, event === null || event === void 0 ? void 0 : event.currentTarget, this.onTableEditorCreated);
|
|
132
|
+
this.tableEditor = new TableEditor_1.TableEditor(this.editor, table, this.invalidateTableRects, (0, roosterjs_content_model_dom_1.isNodeOfType)(container, 'ELEMENT_NODE') ? container : undefined, event === null || event === void 0 ? void 0 : event.currentTarget, this.onTableEditorCreated, this.disableFeatures);
|
|
131
133
|
}
|
|
132
134
|
};
|
|
133
135
|
TableEditPlugin.prototype.disposeTableEditor = function () {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TableEditPlugin.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/tableEdit/TableEditPlugin.ts"],"names":[],"mappings":";;;AAAA,2EAA0E;AAC1E,qDAAoD;AAIpD,IAAM,oBAAoB,GAAG,EAAE,CAAC;AAEhC;;GAEG;AACH;IAMI;;;;;;OAMG;IACH,yBACY,uBAAgC,EAChC,oBAAmD;QAF/D,iBAGI;QAFQ,4BAAuB,GAAvB,uBAAuB,CAAS;QAChC,yBAAoB,GAApB,oBAAoB,CAA+B;QAdvD,WAAM,GAAmB,IAAI,CAAC;QAC9B,wBAAmB,GAAwB,IAAI,CAAC;QAChD,iBAAY,GAAqD,IAAI,CAAC;QACtE,gBAAW,GAAuB,IAAI,CAAC;QAkCvC,eAAU,GAAG,UAAC,EAA4C;gBAA1C,aAAa,mBAAA,EAAE,aAAa,mBAAA;YAChD,IAAM,iBAAiB,GAAG,aAAqB,CAAC;YAChD,IAAM,iBAAiB,GAAG,aAAqB,CAAC;YAChD,IACI,IAAA,0CAAY,EAAC,iBAAiB,EAAE,cAAc,CAAC;gBAC/C,IAAA,0CAAY,EAAC,iBAAiB,EAAE,cAAc,CAAC;gBAC/C,KAAI,CAAC,WAAW;gBAChB,CAAC,KAAI,CAAC,WAAW,CAAC,cAAc,CAAC,iBAAiB,CAAC;gBACnD,CAAC,iBAAiB,CAAC,QAAQ,CAAC,iBAAiB,CAAC,EAChD;gBACE,KAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;aAC7B;QACL,CAAC,CAAC;QAgCM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AAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;YACjE,MAAM,CAAC,OAAO,CAAC,UAAA,KAAK;gBAChB,IAAI,KAAK,CAAC,iBAAiB,EAAE;oBACzB,IAAM,IAAI,GAAG,IAAA,2CAAa,EAAC,KAAK,CAAC,qBAAqB,EAAE,CAAC,CAAC;oBAC1D,IAAI,IAAI,IAAI,KAAI,CAAC,YAAY,EAAE;wBAC3B,KAAI,CAAC,YAAY,CAAC,IAAI,CAAC;4BACnB,KAAK,OAAA;4BACL,IAAI,MAAA;yBACP,CAAC,CAAC;qBACN;iBACJ;YACL,CAAC,CAAC,CAAC;SACN;IACL,CAAC;IACL,sBAAC;AAAD,CAAC,AA3KD,IA2KC;AA3KY,0CAAe","sourcesContent":["import { isNodeOfType, normalizeRect } from 'roosterjs-content-model-dom';\nimport { TableEditor } from './editors/TableEditor';\nimport type { OnTableEditorCreatedCallback } from './OnTableEditorCreatedCallback';\nimport type { EditorPlugin, IEditor, PluginEvent, Rect } from 'roosterjs-content-model-types';\n\nconst TABLE_RESIZER_LENGTH = 12;\n\n/**\n * TableEdit plugin, provides the ability to resize a table by drag-and-drop\n */\nexport class TableEditPlugin implements EditorPlugin {\n private editor: IEditor | null = null;\n private onMouseMoveDisposer: (() => void) | null = null;\n private tableRectMap: { table: HTMLTableElement; rect: Rect }[] | null = null;\n private tableEditor: TableEditor | null = null;\n\n /**\n * Construct a new instance of TableResize plugin\n * @param anchorContainerSelector An optional selector string to specify the container to host the plugin.\n * The container must not be affected by transform: scale(), otherwise the position calculation will be wrong.\n * If not specified, the plugin will be inserted in document.body\n * @param onTableEditorCreated An optional callback to customize the Table Editors elements when created.\n */\n constructor(\n private anchorContainerSelector?: string,\n private onTableEditorCreated?: OnTableEditorCreatedCallback\n ) {}\n\n /**\n * Get a friendly name of this plugin\n */\n getName() {\n return 'TableEdit';\n }\n\n /**\n * Initialize this plugin. This should only be called from Editor\n * @param editor Editor instance\n */\n initialize(editor: IEditor) {\n this.editor = editor;\n this.onMouseMoveDisposer = this.editor.attachDomEvent({\n mousemove: { beforeDispatch: this.onMouseMove },\n });\n const scrollContainer = this.editor.getScrollContainer();\n scrollContainer.addEventListener('mouseout', this.onMouseOut);\n }\n\n private onMouseOut = ({ relatedTarget, currentTarget }: MouseEvent) => {\n const relatedTargetNode = relatedTarget as Node;\n const currentTargetNode = currentTarget as Node;\n if (\n isNodeOfType(relatedTargetNode, 'ELEMENT_NODE') &&\n isNodeOfType(currentTargetNode, 'ELEMENT_NODE') &&\n this.tableEditor &&\n !this.tableEditor.isOwnedElement(relatedTargetNode) &&\n !currentTargetNode.contains(relatedTargetNode)\n ) {\n this.setTableEditor(null);\n }\n };\n\n /**\n * Dispose this plugin\n */\n dispose() {\n const scrollContainer = this.editor?.getScrollContainer();\n scrollContainer?.removeEventListener('mouseout', this.onMouseOut);\n this.onMouseMoveDisposer?.();\n this.invalidateTableRects();\n this.disposeTableEditor();\n this.editor = null;\n this.onMouseMoveDisposer = null;\n this.onTableEditorCreated = undefined;\n }\n\n /**\n * Handle events triggered from editor\n * @param event PluginEvent object\n */\n onPluginEvent(e: PluginEvent) {\n switch (e.eventType) {\n case 'input':\n case 'contentChanged':\n case 'scroll':\n case 'zoomChanged':\n this.setTableEditor(null);\n this.invalidateTableRects();\n break;\n }\n }\n\n private onMouseMove = (event: Event) => {\n const e = event as MouseEvent;\n\n if (e.buttons > 0 || !this.editor) {\n return;\n }\n\n this.ensureTableRects();\n\n const editorWindow = this.editor.getDocument().defaultView || window;\n const x = e.pageX - editorWindow.scrollX;\n const y = e.pageY - editorWindow.scrollY;\n let currentTable: HTMLTableElement | null = null;\n\n //Find table in range of mouse\n if (this.tableRectMap) {\n for (let i = this.tableRectMap.length - 1; i >= 0; i--) {\n const { table, rect } = this.tableRectMap[i];\n\n if (\n x >= rect.left - TABLE_RESIZER_LENGTH &&\n x <= rect.right + TABLE_RESIZER_LENGTH &&\n y >= rect.top - TABLE_RESIZER_LENGTH &&\n y <= rect.bottom + TABLE_RESIZER_LENGTH\n ) {\n currentTable = table;\n break;\n }\n }\n }\n\n this.setTableEditor(currentTable, e);\n this.tableEditor?.onMouseMove(x, y);\n };\n\n /**\n * @internal Public only for unit test\n * @param table Table to use when setting the Editors\n * @param event (Optional) Mouse event\n */\n public setTableEditor(table: HTMLTableElement | null, event?: MouseEvent) {\n if (this.tableEditor && !this.tableEditor.isEditing() && table != this.tableEditor.table) {\n this.disposeTableEditor();\n }\n\n if (!this.tableEditor && table && this.editor && table.rows.length > 0) {\n // anchorContainerSelector is used to specify the container to host the plugin, which can be outside of the editor's div\n const container = this.anchorContainerSelector\n ? this.editor.getDocument().querySelector(this.anchorContainerSelector)\n : undefined;\n\n this.tableEditor = new TableEditor(\n this.editor,\n table,\n this.invalidateTableRects,\n isNodeOfType(container, 'ELEMENT_NODE') ? container : undefined,\n event?.currentTarget,\n this.onTableEditorCreated\n );\n }\n }\n\n private invalidateTableRects = () => {\n this.tableRectMap = null;\n };\n\n private disposeTableEditor() {\n this.tableEditor?.dispose();\n this.tableEditor = null;\n }\n\n private ensureTableRects() {\n if (!this.tableRectMap && this.editor) {\n this.tableRectMap = [];\n\n const tables = this.editor.getDOMHelper().queryElements('table');\n tables.forEach(table => {\n if (table.isContentEditable) {\n const rect = normalizeRect(table.getBoundingClientRect());\n if (rect && this.tableRectMap) {\n this.tableRectMap.push({\n table,\n rect,\n });\n }\n }\n });\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"TableEditPlugin.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/tableEdit/TableEditPlugin.ts"],"names":[],"mappings":";;;AAAA,2EAA0E;AAC1E,qDAAoD;AAKpD,IAAM,oBAAoB,GAAG,EAAE,CAAC;AAEhC;;GAEG;AACH;IAMI;;;;;;;OAOG;IACH,yBACY,uBAAgC,EAChC,oBAAmD,EACnD,eAAwC;QAHpD,iBAII;QAHQ,4BAAuB,GAAvB,uBAAuB,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eOfType, normalizeRect } from 'roosterjs-content-model-dom';\nimport { TableEditor } from './editors/TableEditor';\nimport type { TableEditFeatureName } from './editors/features/TableEditFeatureName';\nimport type { OnTableEditorCreatedCallback } from './OnTableEditorCreatedCallback';\nimport type { EditorPlugin, IEditor, PluginEvent, Rect } from 'roosterjs-content-model-types';\n\nconst TABLE_RESIZER_LENGTH = 12;\n\n/**\n * TableEdit plugin, provides the ability to resize a table by drag-and-drop\n */\nexport class TableEditPlugin implements EditorPlugin {\n private editor: IEditor | null = null;\n private onMouseMoveDisposer: (() => void) | null = null;\n private tableRectMap: { table: HTMLTableElement; rect: Rect }[] | null = null;\n private tableEditor: TableEditor | null = null;\n\n /**\n * Construct a new instance of TableResize plugin\n * @param anchorContainerSelector An optional selector string to specify the container to host the plugin.\n * The container must not be affected by transform: scale(), otherwise the position calculation will be wrong.\n * If not specified, the plugin will be inserted in document.body\n * @param onTableEditorCreated An optional callback to customize the Table Editors elements when created.\n * @param disableFeatures An optional array of TableEditFeatures to disable\n */\n constructor(\n private anchorContainerSelector?: string,\n private onTableEditorCreated?: OnTableEditorCreatedCallback,\n private disableFeatures?: TableEditFeatureName[]\n ) {}\n\n /**\n * Get a friendly name of this plugin\n */\n getName() {\n return 'TableEdit';\n }\n\n /**\n * Initialize this plugin. This should only be called from Editor\n * @param editor Editor instance\n */\n initialize(editor: IEditor) {\n this.editor = editor;\n this.onMouseMoveDisposer = this.editor.attachDomEvent({\n mousemove: { beforeDispatch: this.onMouseMove },\n });\n const scrollContainer = this.editor.getScrollContainer();\n scrollContainer.addEventListener('mouseout', this.onMouseOut);\n }\n\n private onMouseOut = ({ relatedTarget, currentTarget }: MouseEvent) => {\n const relatedTargetNode = relatedTarget as Node;\n const currentTargetNode = currentTarget as Node;\n if (\n isNodeOfType(relatedTargetNode, 'ELEMENT_NODE') &&\n isNodeOfType(currentTargetNode, 'ELEMENT_NODE') &&\n this.tableEditor &&\n !this.tableEditor.isOwnedElement(relatedTargetNode) &&\n !currentTargetNode.contains(relatedTargetNode)\n ) {\n this.setTableEditor(null);\n }\n };\n\n /**\n * Dispose this plugin\n */\n dispose() {\n const scrollContainer = this.editor?.getScrollContainer();\n scrollContainer?.removeEventListener('mouseout', this.onMouseOut);\n this.onMouseMoveDisposer?.();\n this.invalidateTableRects();\n this.disposeTableEditor();\n this.editor = null;\n this.onMouseMoveDisposer = null;\n this.onTableEditorCreated = undefined;\n }\n\n /**\n * Handle events triggered from editor\n * @param event PluginEvent object\n */\n onPluginEvent(e: PluginEvent) {\n switch (e.eventType) {\n case 'input':\n case 'contentChanged':\n case 'scroll':\n case 'zoomChanged':\n this.setTableEditor(null);\n this.invalidateTableRects();\n break;\n }\n }\n\n private onMouseMove = (event: Event) => {\n const e = event as MouseEvent;\n\n if (e.buttons > 0 || !this.editor) {\n return;\n }\n\n this.ensureTableRects();\n\n const editorWindow = this.editor.getDocument().defaultView || window;\n const x = e.pageX - editorWindow.scrollX;\n const y = e.pageY - editorWindow.scrollY;\n let currentTable: HTMLTableElement | null = null;\n\n //Find table in range of mouse\n if (this.tableRectMap) {\n for (let i = this.tableRectMap.length - 1; i >= 0; i--) {\n const { table, rect } = this.tableRectMap[i];\n\n if (\n x >= rect.left - TABLE_RESIZER_LENGTH &&\n x <= rect.right + TABLE_RESIZER_LENGTH &&\n y >= rect.top - TABLE_RESIZER_LENGTH &&\n y <= rect.bottom + TABLE_RESIZER_LENGTH\n ) {\n currentTable = table;\n break;\n }\n }\n }\n\n this.setTableEditor(currentTable, e);\n this.tableEditor?.onMouseMove(x, y);\n };\n\n /**\n * @internal Public only for unit test\n * @param table Table to use when setting the Editors\n * @param event (Optional) Mouse event\n */\n public setTableEditor(table: HTMLTableElement | null, event?: MouseEvent) {\n if (this.tableEditor && !this.tableEditor.isEditing() && table != this.tableEditor.table) {\n this.disposeTableEditor();\n }\n\n if (!this.tableEditor && table && this.editor && table.rows.length > 0) {\n // anchorContainerSelector is used to specify the container to host the plugin, which can be outside of the editor's div\n const container = this.anchorContainerSelector\n ? this.editor.getDocument().querySelector(this.anchorContainerSelector)\n : undefined;\n\n this.tableEditor = new TableEditor(\n this.editor,\n table,\n this.invalidateTableRects,\n isNodeOfType(container, 'ELEMENT_NODE') ? container : undefined,\n event?.currentTarget,\n this.onTableEditorCreated,\n this.disableFeatures\n );\n }\n }\n\n private invalidateTableRects = () => {\n this.tableRectMap = null;\n };\n\n private disposeTableEditor() {\n this.tableEditor?.dispose();\n this.tableEditor = null;\n }\n\n private ensureTableRects() {\n if (!this.tableRectMap && this.editor) {\n this.tableRectMap = [];\n\n const tables = this.editor.getDOMHelper().queryElements('table');\n tables.forEach(table => {\n if (table.isContentEditable) {\n const rect = normalizeRect(table.getBoundingClientRect());\n if (rect && this.tableRectMap) {\n this.tableRectMap.push({\n table,\n rect,\n });\n }\n }\n });\n }\n }\n}\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { OnTableEditorCreatedCallback } from '../OnTableEditorCreatedCallback';
|
|
2
2
|
import type { IEditor } from 'roosterjs-content-model-types';
|
|
3
|
+
import type { TableEditFeatureName } from './features/TableEditFeatureName';
|
|
3
4
|
/**
|
|
4
5
|
* @internal
|
|
5
6
|
*
|
|
@@ -36,6 +37,7 @@ export declare class TableEditor {
|
|
|
36
37
|
private anchorContainer?;
|
|
37
38
|
private contentDiv?;
|
|
38
39
|
private onTableEditorCreated?;
|
|
40
|
+
private disableFeatures?;
|
|
39
41
|
private horizontalInserter;
|
|
40
42
|
private verticalInserter;
|
|
41
43
|
private horizontalResizer;
|
|
@@ -45,7 +47,7 @@ export declare class TableEditor {
|
|
|
45
47
|
private isRTL;
|
|
46
48
|
private range;
|
|
47
49
|
private isCurrentlyEditing;
|
|
48
|
-
constructor(editor: IEditor, table: HTMLTableElement, onChanged: () => void, anchorContainer?: HTMLElement | undefined, contentDiv?: EventTarget | null | undefined, onTableEditorCreated?: OnTableEditorCreatedCallback | undefined);
|
|
50
|
+
constructor(editor: IEditor, table: HTMLTableElement, onChanged: () => void, anchorContainer?: HTMLElement | undefined, contentDiv?: EventTarget | null | undefined, onTableEditorCreated?: OnTableEditorCreatedCallback | undefined, disableFeatures?: TableEditFeatureName[] | undefined);
|
|
49
51
|
dispose(): void;
|
|
50
52
|
isEditing(): boolean;
|
|
51
53
|
isOwnedElement(node: Node): boolean;
|
|
@@ -65,7 +67,9 @@ export declare class TableEditor {
|
|
|
65
67
|
private onFinishEditing;
|
|
66
68
|
private onStartTableResize;
|
|
67
69
|
private onStartCellResize;
|
|
70
|
+
private onStartTableMove;
|
|
68
71
|
private onStartResize;
|
|
72
|
+
private onEndTableMove;
|
|
69
73
|
private onInserted;
|
|
70
74
|
/**
|
|
71
75
|
* Public only for testing purposes
|
|
@@ -73,4 +77,5 @@ export declare class TableEditor {
|
|
|
73
77
|
*/
|
|
74
78
|
onSelect: (table: HTMLTableElement) => void;
|
|
75
79
|
private getOnMouseOut;
|
|
80
|
+
private isFeatureDisabled;
|
|
76
81
|
}
|
|
@@ -43,7 +43,7 @@ var TOP_OR_SIDE;
|
|
|
43
43
|
* When set a different current table or change current TD, we need to update these areas
|
|
44
44
|
*/
|
|
45
45
|
var TableEditor = /** @class */ (function () {
|
|
46
|
-
function TableEditor(editor, table, onChanged, anchorContainer, contentDiv, onTableEditorCreated) {
|
|
46
|
+
function TableEditor(editor, table, onChanged, anchorContainer, contentDiv, onTableEditorCreated, disableFeatures) {
|
|
47
47
|
var _this = this;
|
|
48
48
|
var _a;
|
|
49
49
|
this.editor = editor;
|
|
@@ -52,6 +52,7 @@ var TableEditor = /** @class */ (function () {
|
|
|
52
52
|
this.anchorContainer = anchorContainer;
|
|
53
53
|
this.contentDiv = contentDiv;
|
|
54
54
|
this.onTableEditorCreated = onTableEditorCreated;
|
|
55
|
+
this.disableFeatures = disableFeatures;
|
|
55
56
|
// 1, 2 - Insert a column or a row
|
|
56
57
|
this.horizontalInserter = null;
|
|
57
58
|
this.verticalInserter = null;
|
|
@@ -63,9 +64,9 @@ var TableEditor = /** @class */ (function () {
|
|
|
63
64
|
// 6 - Move as well as select whole table
|
|
64
65
|
this.tableMover = null;
|
|
65
66
|
this.range = null;
|
|
66
|
-
this.onEditorCreated = function (
|
|
67
|
+
this.onEditorCreated = function (featureType, element) {
|
|
67
68
|
var _a;
|
|
68
|
-
var disposer = (_a = _this.onTableEditorCreated) === null || _a === void 0 ? void 0 : _a.call(_this,
|
|
69
|
+
var disposer = (_a = _this.onTableEditorCreated) === null || _a === void 0 ? void 0 : _a.call(_this, featureType, element);
|
|
69
70
|
var onMouseOut = element && _this.getOnMouseOut(element);
|
|
70
71
|
if (onMouseOut) {
|
|
71
72
|
element.addEventListener('mouseout', onMouseOut);
|
|
@@ -96,6 +97,16 @@ var TableEditor = /** @class */ (function () {
|
|
|
96
97
|
_this.disposeTableResizer();
|
|
97
98
|
_this.onStartResize();
|
|
98
99
|
};
|
|
100
|
+
this.onStartTableMove = function () {
|
|
101
|
+
_this.isCurrentlyEditing = true;
|
|
102
|
+
_this.disposeTableResizer();
|
|
103
|
+
_this.disposeTableInserter();
|
|
104
|
+
_this.disposeCellResizers();
|
|
105
|
+
};
|
|
106
|
+
this.onEndTableMove = function () {
|
|
107
|
+
_this.disposeTableMover();
|
|
108
|
+
return _this.onFinishEditing();
|
|
109
|
+
};
|
|
99
110
|
this.onInserted = function () {
|
|
100
111
|
_this.disposeTableResizer();
|
|
101
112
|
_this.onFinishEditing();
|
|
@@ -126,7 +137,8 @@ var TableEditor = /** @class */ (function () {
|
|
|
126
137
|
ev.relatedTarget != feature &&
|
|
127
138
|
(0, roosterjs_content_model_dom_1.isNodeOfType)(_this.contentDiv, 'ELEMENT_NODE') &&
|
|
128
139
|
(0, roosterjs_content_model_dom_1.isNodeOfType)(ev.relatedTarget, 'ELEMENT_NODE') &&
|
|
129
|
-
!(_this.contentDiv == ev.relatedTarget)
|
|
140
|
+
!(_this.contentDiv == ev.relatedTarget) &&
|
|
141
|
+
!_this.isEditing()) {
|
|
130
142
|
_this.dispose();
|
|
131
143
|
}
|
|
132
144
|
};
|
|
@@ -197,7 +209,8 @@ var TableEditor = /** @class */ (function () {
|
|
|
197
209
|
if (i === 0 && topOrSide == 0 /* top */) {
|
|
198
210
|
var center = (tdRect.left + tdRect.right) / 2;
|
|
199
211
|
var isOnRightHalf = this.isRTL ? x < center : x > center;
|
|
200
|
-
this.
|
|
212
|
+
!this.isFeatureDisabled('VerticalTableInserter') &&
|
|
213
|
+
this.setInserterTd(isOnRightHalf ? td : tr.cells[j - 1], false /*isHorizontal*/);
|
|
201
214
|
}
|
|
202
215
|
else if (j === 0 && topOrSide == 1 /* side */) {
|
|
203
216
|
var tdAbove = (_a = this.table.rows[i - 1]) === null || _a === void 0 ? void 0 : _a.cells[0];
|
|
@@ -209,14 +222,15 @@ var TableEditor = /** @class */ (function () {
|
|
|
209
222
|
: this.isRTL
|
|
210
223
|
? tdAboveRect.right === tdRect.right
|
|
211
224
|
: tdAboveRect.left === tdRect.left;
|
|
212
|
-
this.
|
|
213
|
-
|
|
214
|
-
|
|
225
|
+
!this.isFeatureDisabled('HorizontalTableInserter') &&
|
|
226
|
+
this.setInserterTd(y < (tdRect.top + tdRect.bottom) / 2 && isTdNotAboveMerged
|
|
227
|
+
? tdAbove
|
|
228
|
+
: td, true /*isHorizontal*/);
|
|
215
229
|
}
|
|
216
230
|
else {
|
|
217
231
|
this.setInserterTd(null);
|
|
218
232
|
}
|
|
219
|
-
this.setResizingTd(td);
|
|
233
|
+
!this.isFeatureDisabled('CellResizer') && this.setResizingTd(td);
|
|
220
234
|
//Cell found
|
|
221
235
|
break;
|
|
222
236
|
}
|
|
@@ -229,10 +243,12 @@ var TableEditor = /** @class */ (function () {
|
|
|
229
243
|
this.setEditorFeatures();
|
|
230
244
|
};
|
|
231
245
|
TableEditor.prototype.setEditorFeatures = function () {
|
|
232
|
-
|
|
233
|
-
|
|
246
|
+
var disableSelector = this.isFeatureDisabled('TableSelector');
|
|
247
|
+
var disableMovement = this.isFeatureDisabled('TableMover');
|
|
248
|
+
if (!this.tableMover && !(disableSelector && disableMovement)) {
|
|
249
|
+
this.tableMover = (0, TableMover_1.createTableMover)(this.table, this.editor, this.isRTL, disableSelector ? function () { } : this.onSelect, this.onStartTableMove, this.onEndTableMove, this.contentDiv, this.anchorContainer, this.onEditorCreated, disableMovement);
|
|
234
250
|
}
|
|
235
|
-
if (!this.tableResizer) {
|
|
251
|
+
if (!this.tableResizer && !this.isFeatureDisabled('TableResizer')) {
|
|
236
252
|
this.tableResizer = (0, TableResizer_1.createTableResizer)(this.table, this.editor, this.isRTL, this.onStartTableResize, this.onFinishEditing, this.contentDiv, this.anchorContainer, this.onTableEditorCreated);
|
|
237
253
|
}
|
|
238
254
|
};
|
|
@@ -304,6 +320,10 @@ var TableEditor = /** @class */ (function () {
|
|
|
304
320
|
}
|
|
305
321
|
this.editor.takeSnapshot();
|
|
306
322
|
};
|
|
323
|
+
TableEditor.prototype.isFeatureDisabled = function (feature) {
|
|
324
|
+
var _a;
|
|
325
|
+
return (_a = this.disableFeatures) === null || _a === void 0 ? void 0 : _a.includes(feature);
|
|
326
|
+
};
|
|
307
327
|
return TableEditor;
|
|
308
328
|
}());
|
|
309
329
|
exports.TableEditor = TableEditor;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TableEditor.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/tableEdit/editors/TableEditor.ts"],"names":[],"mappings":";;;AAAA,sDAA2D;AAC3D,0DAA+D;AAC/D,oDAAyD;AACzD,wDAA6D;AAC7D,gEAAsE;AACtE,2EAA2F;AAK3F,IAAM,qBAAqB,GAAG,CAAC,CAAC;AAChC,IAAW,WAGV;AAHD,WAAW,WAAW;IAClB,2CAAO,CAAA;IACP,6CAAQ,CAAA;AACZ,CAAC,EAHU,WAAW,KAAX,WAAW,QAGrB;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH;IAmBI,qBACY,MAAe,EACP,KAAuB,EAC/B,SAAqB,EACrB,eA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,CAAC,eAAe,GAAG,IAAI,CAAC;SAC/B;IACL,CAAC;IAEO,uCAAiB,GAAzB;QACI,IAAI,IAAI,CAAC,UAAU,EAAE;YACjB,IAAA,0CAAuB,EAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YACzC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;SAC1B;IACL,CAAC;IA2BO,mCAAa,GAArB;QACI,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC;QAC/B,IAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,eAAe,EAAE,CAAC;QAE5C,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,IAAI,OAAO,EAAE;YAChC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;SAC5B;QAED,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC;IAC/B,CAAC;IA0CL,kBAAC;AAAD,CAAC,AA5WD,IA4WC;AA5WY,kCAAW","sourcesContent":["import { createCellResizer } from './features/CellResizer';\nimport { createTableInserter } from './features/TableInserter';\nimport { createTableMover } from './features/TableMover';\nimport { createTableResizer } from './features/TableResizer';\nimport { disposeTableEditFeature } from './features/TableEditFeature';\nimport { isNodeOfType, normalizeRect, parseTableCells } from 'roosterjs-content-model-dom';\nimport type { OnTableEditorCreatedCallback } from '../OnTableEditorCreatedCallback';\nimport type { TableEditFeature } from './features/TableEditFeature';\nimport type { IEditor, TableSelection } from 'roosterjs-content-model-types';\n\nconst INSERTER_HOVER_OFFSET = 6;\nconst enum TOP_OR_SIDE {\n top = 0,\n side = 1,\n}\n/**\n * @internal\n *\n * A table has 6 hot areas to be resized/edited (take LTR example):\n *\n * [6] [ ]\n * +[ 1 ]+--------------------+\n * |[ ]| |\n * [ ] [ ] |\n * [ ] [ ] |\n * [2] [3] |\n * [ ] [ ] |\n * [ ][ 4 ]| |\n * +------------------+--------------------+\n * | | |\n * | | |\n * | | |\n * +------------------+--------------------+\n * [5]\n *\n * 1 - Hover area to show insert column button\n * 2 - Hover area to show insert row button\n * 3 - Hover area to show vertical resizing bar\n * 4 - Hover area to show horizontal resizing bar\n * 5 - Hover area to show whole table resize handle\n * 6 - Hover area to show whole table mover handle\n *\n * When set a different current table or change current TD, we need to update these areas\n */\nexport class TableEditor {\n // 1, 2 - Insert a column or a row\n private horizontalInserter: TableEditFeature | null = null;\n private verticalInserter: TableEditFeature | null = null;\n\n // 3, 4 - Resize a column or a row from a cell\n private horizontalResizer: TableEditFeature | null = null;\n private verticalResizer: TableEditFeature | null = null;\n\n // 5 - Resize whole table\n private tableResizer: TableEditFeature | null = null;\n\n // 6 - Move as well as select whole table\n private tableMover: TableEditFeature | null = null;\n\n private isRTL: boolean;\n private range: Range | null = null;\n private isCurrentlyEditing: boolean;\n\n constructor(\n private editor: IEditor,\n public readonly table: HTMLTableElement,\n private onChanged: () => void,\n private anchorContainer?: HTMLElement,\n private contentDiv?: EventTarget | null,\n private onTableEditorCreated?: OnTableEditorCreatedCallback\n ) {\n this.isRTL = editor.getDocument().defaultView?.getComputedStyle(table).direction == 'rtl';\n this.setEditorFeatures();\n this.isCurrentlyEditing = false;\n }\n\n dispose() {\n this.disposeTableResizer();\n this.disposeCellResizers();\n this.disposeTableInserter();\n this.disposeTableMover();\n }\n\n isEditing(): boolean {\n return this.isCurrentlyEditing;\n }\n\n isOwnedElement(node: Node) {\n return [\n this.tableResizer,\n this.tableMover,\n this.horizontalInserter,\n this.verticalInserter,\n this.horizontalResizer,\n this.verticalResizer,\n ]\n .filter(feature => !!feature?.div)\n .some(feature => feature?.div == node);\n }\n\n onMouseMove(x: number, y: number) {\n // Get whole table rect\n const tableRect = normalizeRect(this.table.getBoundingClientRect());\n\n if (!tableRect) {\n return;\n }\n\n // Determine if cursor is on top or side\n const topOrSide =\n y <= tableRect.top + INSERTER_HOVER_OFFSET\n ? TOP_OR_SIDE.top\n : this.isRTL\n ? x >= tableRect.right - INSERTER_HOVER_OFFSET\n ? TOP_OR_SIDE.side\n : undefined\n : x <= tableRect.left + INSERTER_HOVER_OFFSET\n ? TOP_OR_SIDE.side\n : undefined;\n const topOrSideBinary = topOrSide ? 1 : 0;\n\n // i is row index, j is column index\n for (let i = 0; i < this.table.rows.length; i++) {\n const tr = this.table.rows[i];\n let j = 0;\n for (; j < tr.cells.length; j++) {\n const td = tr.cells[j];\n const tdRect = normalizeRect(td.getBoundingClientRect());\n\n if (!tdRect || !tableRect) {\n continue;\n }\n\n // Determine the cell the cursor is in range of\n // Offset is only used for first row and column\n const lessThanBottom = y <= tdRect.bottom;\n const lessThanRight = this.isRTL\n ? x <= tdRect.right + INSERTER_HOVER_OFFSET * topOrSideBinary\n : x <= tdRect.right;\n const moreThanLeft = this.isRTL\n ? x >= tdRect.left\n : x >= tdRect.left - INSERTER_HOVER_OFFSET * topOrSideBinary;\n\n if (lessThanBottom && lessThanRight && moreThanLeft) {\n if (i === 0 && topOrSide == TOP_OR_SIDE.top) {\n const center = (tdRect.left + tdRect.right) / 2;\n const isOnRightHalf = this.isRTL ? x < center : x > center;\n this.setInserterTd(\n isOnRightHalf ? td : tr.cells[j - 1],\n false /*isHorizontal*/\n );\n } else if (j === 0 && topOrSide == TOP_OR_SIDE.side) {\n const tdAbove = this.table.rows[i - 1]?.cells[0];\n const tdAboveRect = tdAbove\n ? normalizeRect(tdAbove.getBoundingClientRect())\n : null;\n\n const isTdNotAboveMerged = !tdAboveRect\n ? null\n : this.isRTL\n ? tdAboveRect.right === tdRect.right\n : tdAboveRect.left === tdRect.left;\n\n this.setInserterTd(\n y < (tdRect.top + tdRect.bottom) / 2 && isTdNotAboveMerged\n ? tdAbove\n : td,\n true /*isHorizontal*/\n );\n } else {\n this.setInserterTd(null);\n }\n\n this.setResizingTd(td);\n\n //Cell found\n break;\n }\n }\n\n if (j < tr.cells.length) {\n break;\n }\n }\n\n // Create Mover and Resizer\n this.setEditorFeatures();\n }\n\n private setEditorFeatures() {\n if (!this.tableMover) {\n this.tableMover = createTableMover(\n this.table,\n this.editor,\n this.isRTL,\n this.onSelect,\n this.contentDiv,\n this.anchorContainer,\n this.onEditorCreated\n );\n }\n\n if (!this.tableResizer) {\n this.tableResizer = createTableResizer(\n this.table,\n this.editor,\n this.isRTL,\n this.onStartTableResize,\n this.onFinishEditing,\n this.contentDiv,\n this.anchorContainer,\n this.onTableEditorCreated\n );\n }\n }\n\n private onEditorCreated = (\n editorType:\n | 'HorizontalTableInserter'\n | 'VerticalTableInserter'\n | 'TableMover'\n | 'TableResizer',\n element: HTMLElement\n ) => {\n const disposer = this.onTableEditorCreated?.(editorType, element);\n const onMouseOut = element && this.getOnMouseOut(element);\n if (onMouseOut) {\n element.addEventListener('mouseout', onMouseOut);\n }\n\n return () => {\n disposer?.();\n if (onMouseOut) {\n element.removeEventListener('mouseout', onMouseOut);\n }\n };\n };\n\n private setResizingTd(td: HTMLTableCellElement) {\n if (this.horizontalResizer && this.horizontalResizer.node != td) {\n this.disposeCellResizers();\n }\n\n if (!this.horizontalResizer && td) {\n this.horizontalResizer = createCellResizer(\n this.editor,\n td,\n this.table,\n this.isRTL,\n true /*isHorizontal*/,\n this.onStartCellResize,\n this.onFinishEditing,\n this.anchorContainer\n );\n this.verticalResizer = createCellResizer(\n this.editor,\n td,\n this.table,\n this.isRTL,\n false /*isHorizontal*/,\n this.onStartCellResize,\n this.onFinishEditing,\n this.anchorContainer\n );\n }\n }\n\n /**\n * create or remove TableInserter\n * @param td td to attach to, set this to null to remove inserters (both horizontal and vertical)\n */\n private setInserterTd(td: HTMLTableCellElement | null, isHorizontal?: boolean) {\n const inserter = isHorizontal ? this.horizontalInserter : this.verticalInserter;\n if (td === null || (inserter && inserter.node != td)) {\n this.disposeTableInserter();\n }\n\n if (!this.horizontalInserter && !this.verticalInserter && td) {\n const newInserter = createTableInserter(\n this.editor,\n td,\n this.table,\n this.isRTL,\n !!isHorizontal,\n this.onInserted,\n this.anchorContainer,\n this.onEditorCreated\n );\n if (isHorizontal) {\n this.horizontalInserter = newInserter;\n } else {\n this.verticalInserter = newInserter;\n }\n }\n }\n\n private disposeTableResizer() {\n if (this.tableResizer) {\n disposeTableEditFeature(this.tableResizer);\n this.tableResizer = null;\n }\n }\n\n private disposeTableInserter() {\n if (this.horizontalInserter) {\n disposeTableEditFeature(this.horizontalInserter);\n this.horizontalInserter = null;\n }\n if (this.verticalInserter) {\n disposeTableEditFeature(this.verticalInserter);\n this.verticalInserter = null;\n }\n }\n\n private disposeCellResizers() {\n if (this.horizontalResizer) {\n disposeTableEditFeature(this.horizontalResizer);\n this.horizontalResizer = null;\n }\n if (this.verticalResizer) {\n disposeTableEditFeature(this.verticalResizer);\n this.verticalResizer = null;\n }\n }\n\n private disposeTableMover() {\n if (this.tableMover) {\n disposeTableEditFeature(this.tableMover);\n this.tableMover = null;\n }\n }\n\n private onFinishEditing = (): false => {\n this.editor.focus();\n\n if (this.range) {\n this.editor.setDOMSelection({ type: 'range', range: this.range, isReverted: false });\n }\n\n this.editor.takeSnapshot(); // Pass in an empty callback to make sure ContentChangedEvent is triggered\n this.onChanged();\n this.isCurrentlyEditing = false;\n\n return false;\n };\n\n private onStartTableResize = () => {\n this.isCurrentlyEditing = true;\n this.onStartResize();\n };\n\n private onStartCellResize = () => {\n this.isCurrentlyEditing = true;\n this.disposeTableResizer();\n this.onStartResize();\n };\n\n private onStartResize() {\n this.isCurrentlyEditing = true;\n const range = this.editor.getDOMSelection();\n\n if (range && range.type == 'range') {\n this.range = range.range;\n }\n\n this.editor.takeSnapshot();\n }\n\n private onInserted = () => {\n this.disposeTableResizer();\n this.onFinishEditing();\n };\n\n /**\n * Public only for testing purposes\n * @param table the table to select\n */\n public onSelect = (table: HTMLTableElement) => {\n this.editor.focus();\n\n if (table) {\n const parsedTable = parseTableCells(table);\n const selection: TableSelection = {\n table: table,\n firstRow: 0,\n firstColumn: 0,\n lastRow: parsedTable.length - 1,\n lastColumn: (parsedTable[0]?.length ?? 0) - 1,\n type: 'table',\n };\n\n this.editor.setDOMSelection(selection);\n }\n };\n\n private getOnMouseOut = (feature: HTMLElement) => {\n return (ev: MouseEvent) => {\n if (\n feature &&\n ev.relatedTarget != feature &&\n isNodeOfType(this.contentDiv as Node, 'ELEMENT_NODE') &&\n isNodeOfType(ev.relatedTarget as Node, 'ELEMENT_NODE') &&\n !(this.contentDiv == ev.relatedTarget)\n ) {\n this.dispose();\n }\n };\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"TableEditor.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/tableEdit/editors/TableEditor.ts"],"names":[],"mappings":";;;AAAA,sDAA2D;AAC3D,0DAA+D;AAC/D,oDAAyD;AACzD,wDAA6D;AAC7D,gEAAsE;AACtE,2EAA2F;AAM3F,IAAM,qBAAqB,GAAG,CAAC,CAAC;AAChC,IAAW,WAGV;AAHD,WAAW,WAAW;IAClB,2CAAO,CAAA;IACP,6CAAQ,CAAA;AACZ,CAAC,EAHU,WAAW,KAAX,WAAW,QAGrB;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH;IAmBI,qBACY,MAAe,EACP,KAAuB,EAC/B,SAAqB,EACrB,eAA6B,EAC7B,UAA+B,EAC/B,oBAAmD,EACnD,eAAwC;QAPpD,iBAYC;;QAXW,WAAM,GAAN,MAAM,CAAS;QACP,UAAK,GAAL,KAAK,CAAkB;QAC/B,cAAS,GAAT,SAAS,CAAY;QACrB,oBAAe,GAAf,eAAe,CAAc;QAC7B,eAAU,GAAV,UAAU,CAAqB;QAC/B,yBAAoB,GAApB,oBAAoB,CAA+B;QACnD,oBAAe,GAAf,eAAe,CAAyB;QAzBpD,kCAAkC;QAC1B,uBAAkB,GAA4B,IAAI,CAAC;QACnD,qBAAgB,GAA4B,IAAI,CAAC;QAEzD,8CAA8C;QACtC,sBAAiB,GAA4B,IAAI,CAAC;QAClD,oBAAe,GAA4B,IAAI,CAAC;QAExD,yBAAyB;QACjB,iBAAY,GAA4B,IAAI,CAAC;QAErD,yCAAyC;QACjC,eAAU,GAA4B,IAAI,CAAC;QA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IAAI,CAAC,gBAAgB,CAAC,CAAC;YAC/C,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC;SAChC;IACL,CAAC;IAEO,yCAAmB,GAA3B;QACI,IAAI,IAAI,CAAC,iBAAiB,EAAE;YACxB,IAAA,0CAAuB,EAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;YAChD,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC;SACjC;QACD,IAAI,IAAI,CAAC,eAAe,EAAE;YACtB,IAAA,0CAAuB,EAAC,IAAI,CAAC,eAAe,CAAC,CAAC;YAC9C,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC;SAC/B;IACL,CAAC;IAEO,uCAAiB,GAAzB;QACI,IAAI,IAAI,CAAC,UAAU,EAAE;YACjB,IAAA,0CAAuB,EAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YACzC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;SAC1B;IACL,CAAC;IAkCO,mCAAa,GAArB;QACI,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC;QAC/B,IAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,eAAe,EAAE,CAAC;QAE5C,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,IAAI,OAAO,EAAE;YAChC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;SAC5B;QAED,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC;IAC/B,CAAC;IAiDO,uCAAiB,GAAzB,UAA0B,OAA6B;;QACnD,OAAO,MAAA,IAAI,CAAC,eAAe,0CAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;IACnD,CAAC;IACL,kBAAC;AAAD,CAAC,AA9XD,IA8XC;AA9XY,kCAAW","sourcesContent":["import { createCellResizer } from './features/CellResizer';\nimport { createTableInserter } from './features/TableInserter';\nimport { createTableMover } from './features/TableMover';\nimport { createTableResizer } from './features/TableResizer';\nimport { disposeTableEditFeature } from './features/TableEditFeature';\nimport { isNodeOfType, normalizeRect, parseTableCells } from 'roosterjs-content-model-dom';\nimport type { OnTableEditorCreatedCallback } from '../OnTableEditorCreatedCallback';\nimport type { TableEditFeature } from './features/TableEditFeature';\nimport type { IEditor, TableSelection } from 'roosterjs-content-model-types';\nimport type { TableEditFeatureName } from './features/TableEditFeatureName';\n\nconst INSERTER_HOVER_OFFSET = 6;\nconst enum TOP_OR_SIDE {\n top = 0,\n side = 1,\n}\n/**\n * @internal\n *\n * A table has 6 hot areas to be resized/edited (take LTR example):\n *\n * [6] [ ]\n * +[ 1 ]+--------------------+\n * |[ ]| |\n * [ ] [ ] |\n * [ ] [ ] |\n * [2] [3] |\n * [ ] [ ] |\n * [ ][ 4 ]| |\n * +------------------+--------------------+\n * | | |\n * | | |\n * | | |\n * +------------------+--------------------+\n * [5]\n *\n * 1 - Hover area to show insert column button\n * 2 - Hover area to show insert row button\n * 3 - Hover area to show vertical resizing bar\n * 4 - Hover area to show horizontal resizing bar\n * 5 - Hover area to show whole table resize handle\n * 6 - Hover area to show whole table mover handle\n *\n * When set a different current table or change current TD, we need to update these areas\n */\nexport class TableEditor {\n // 1, 2 - Insert a column or a row\n private horizontalInserter: TableEditFeature | null = null;\n private verticalInserter: TableEditFeature | null = null;\n\n // 3, 4 - Resize a column or a row from a cell\n private horizontalResizer: TableEditFeature | null = null;\n private verticalResizer: TableEditFeature | null = null;\n\n // 5 - Resize whole table\n private tableResizer: TableEditFeature | null = null;\n\n // 6 - Move as well as select whole table\n private tableMover: TableEditFeature | null = null;\n\n private isRTL: boolean;\n private range: Range | null = null;\n private isCurrentlyEditing: boolean;\n\n constructor(\n private editor: IEditor,\n public readonly table: HTMLTableElement,\n private onChanged: () => void,\n private anchorContainer?: HTMLElement,\n private contentDiv?: EventTarget | null,\n private onTableEditorCreated?: OnTableEditorCreatedCallback,\n private disableFeatures?: TableEditFeatureName[]\n ) {\n this.isRTL = editor.getDocument().defaultView?.getComputedStyle(table).direction == 'rtl';\n this.setEditorFeatures();\n this.isCurrentlyEditing = false;\n }\n\n dispose() {\n this.disposeTableResizer();\n this.disposeCellResizers();\n this.disposeTableInserter();\n this.disposeTableMover();\n }\n\n isEditing(): boolean {\n return this.isCurrentlyEditing;\n }\n\n isOwnedElement(node: Node) {\n return [\n this.tableResizer,\n this.tableMover,\n this.horizontalInserter,\n this.verticalInserter,\n this.horizontalResizer,\n this.verticalResizer,\n ]\n .filter(feature => !!feature?.div)\n .some(feature => feature?.div == node);\n }\n\n onMouseMove(x: number, y: number) {\n // Get whole table rect\n const tableRect = normalizeRect(this.table.getBoundingClientRect());\n\n if (!tableRect) {\n return;\n }\n\n // Determine if cursor is on top or side\n const topOrSide =\n y <= tableRect.top + INSERTER_HOVER_OFFSET\n ? TOP_OR_SIDE.top\n : this.isRTL\n ? x >= tableRect.right - INSERTER_HOVER_OFFSET\n ? TOP_OR_SIDE.side\n : undefined\n : x <= tableRect.left + INSERTER_HOVER_OFFSET\n ? TOP_OR_SIDE.side\n : undefined;\n const topOrSideBinary = topOrSide ? 1 : 0;\n\n // i is row index, j is column index\n for (let i = 0; i < this.table.rows.length; i++) {\n const tr = this.table.rows[i];\n let j = 0;\n for (; j < tr.cells.length; j++) {\n const td = tr.cells[j];\n const tdRect = normalizeRect(td.getBoundingClientRect());\n\n if (!tdRect || !tableRect) {\n continue;\n }\n\n // Determine the cell the cursor is in range of\n // Offset is only used for first row and column\n const lessThanBottom = y <= tdRect.bottom;\n const lessThanRight = this.isRTL\n ? x <= tdRect.right + INSERTER_HOVER_OFFSET * topOrSideBinary\n : x <= tdRect.right;\n const moreThanLeft = this.isRTL\n ? x >= tdRect.left\n : x >= tdRect.left - INSERTER_HOVER_OFFSET * topOrSideBinary;\n\n if (lessThanBottom && lessThanRight && moreThanLeft) {\n if (i === 0 && topOrSide == TOP_OR_SIDE.top) {\n const center = (tdRect.left + tdRect.right) / 2;\n const isOnRightHalf = this.isRTL ? x < center : x > center;\n !this.isFeatureDisabled('VerticalTableInserter') &&\n this.setInserterTd(\n isOnRightHalf ? td : tr.cells[j - 1],\n false /*isHorizontal*/\n );\n } else if (j === 0 && topOrSide == TOP_OR_SIDE.side) {\n const tdAbove = this.table.rows[i - 1]?.cells[0];\n const tdAboveRect = tdAbove\n ? normalizeRect(tdAbove.getBoundingClientRect())\n : null;\n\n const isTdNotAboveMerged = !tdAboveRect\n ? null\n : this.isRTL\n ? tdAboveRect.right === tdRect.right\n : tdAboveRect.left === tdRect.left;\n\n !this.isFeatureDisabled('HorizontalTableInserter') &&\n this.setInserterTd(\n y < (tdRect.top + tdRect.bottom) / 2 && isTdNotAboveMerged\n ? tdAbove\n : td,\n true /*isHorizontal*/\n );\n } else {\n this.setInserterTd(null);\n }\n\n !this.isFeatureDisabled('CellResizer') && this.setResizingTd(td);\n\n //Cell found\n break;\n }\n }\n\n if (j < tr.cells.length) {\n break;\n }\n }\n\n // Create Mover and Resizer\n this.setEditorFeatures();\n }\n\n private setEditorFeatures() {\n const disableSelector = this.isFeatureDisabled('TableSelector');\n const disableMovement = this.isFeatureDisabled('TableMover');\n if (!this.tableMover && !(disableSelector && disableMovement)) {\n this.tableMover = createTableMover(\n this.table,\n this.editor,\n this.isRTL,\n disableSelector ? () => {} : this.onSelect,\n this.onStartTableMove,\n this.onEndTableMove,\n this.contentDiv,\n this.anchorContainer,\n this.onEditorCreated,\n disableMovement\n );\n }\n\n if (!this.tableResizer && !this.isFeatureDisabled('TableResizer')) {\n this.tableResizer = createTableResizer(\n this.table,\n this.editor,\n this.isRTL,\n this.onStartTableResize,\n this.onFinishEditing,\n this.contentDiv,\n this.anchorContainer,\n this.onTableEditorCreated\n );\n }\n }\n\n private onEditorCreated = (featureType: TableEditFeatureName, element: HTMLElement) => {\n const disposer = this.onTableEditorCreated?.(featureType, element);\n const onMouseOut = element && this.getOnMouseOut(element);\n if (onMouseOut) {\n element.addEventListener('mouseout', onMouseOut);\n }\n\n return () => {\n disposer?.();\n if (onMouseOut) {\n element.removeEventListener('mouseout', onMouseOut);\n }\n };\n };\n\n private setResizingTd(td: HTMLTableCellElement) {\n if (this.horizontalResizer && this.horizontalResizer.node != td) {\n this.disposeCellResizers();\n }\n\n if (!this.horizontalResizer && td) {\n this.horizontalResizer = createCellResizer(\n this.editor,\n td,\n this.table,\n this.isRTL,\n true /*isHorizontal*/,\n this.onStartCellResize,\n this.onFinishEditing,\n this.anchorContainer\n );\n this.verticalResizer = createCellResizer(\n this.editor,\n td,\n this.table,\n this.isRTL,\n false /*isHorizontal*/,\n this.onStartCellResize,\n this.onFinishEditing,\n this.anchorContainer\n );\n }\n }\n\n /**\n * create or remove TableInserter\n * @param td td to attach to, set this to null to remove inserters (both horizontal and vertical)\n */\n private setInserterTd(td: HTMLTableCellElement | null, isHorizontal?: boolean) {\n const inserter = isHorizontal ? this.horizontalInserter : this.verticalInserter;\n if (td === null || (inserter && inserter.node != td)) {\n this.disposeTableInserter();\n }\n\n if (!this.horizontalInserter && !this.verticalInserter && td) {\n const newInserter = createTableInserter(\n this.editor,\n td,\n this.table,\n this.isRTL,\n !!isHorizontal,\n this.onInserted,\n this.anchorContainer,\n this.onEditorCreated\n );\n if (isHorizontal) {\n this.horizontalInserter = newInserter;\n } else {\n this.verticalInserter = newInserter;\n }\n }\n }\n\n private disposeTableResizer() {\n if (this.tableResizer) {\n disposeTableEditFeature(this.tableResizer);\n this.tableResizer = null;\n }\n }\n\n private disposeTableInserter() {\n if (this.horizontalInserter) {\n disposeTableEditFeature(this.horizontalInserter);\n this.horizontalInserter = null;\n }\n if (this.verticalInserter) {\n disposeTableEditFeature(this.verticalInserter);\n this.verticalInserter = null;\n }\n }\n\n private disposeCellResizers() {\n if (this.horizontalResizer) {\n disposeTableEditFeature(this.horizontalResizer);\n this.horizontalResizer = null;\n }\n if (this.verticalResizer) {\n disposeTableEditFeature(this.verticalResizer);\n this.verticalResizer = null;\n }\n }\n\n private disposeTableMover() {\n if (this.tableMover) {\n disposeTableEditFeature(this.tableMover);\n this.tableMover = null;\n }\n }\n\n private onFinishEditing = (): false => {\n this.editor.focus();\n\n if (this.range) {\n this.editor.setDOMSelection({ type: 'range', range: this.range, isReverted: false });\n }\n\n this.editor.takeSnapshot(); // Pass in an empty callback to make sure ContentChangedEvent is triggered\n this.onChanged();\n this.isCurrentlyEditing = false;\n\n return false;\n };\n\n private onStartTableResize = () => {\n this.isCurrentlyEditing = true;\n this.onStartResize();\n };\n\n private onStartCellResize = () => {\n this.isCurrentlyEditing = true;\n this.disposeTableResizer();\n this.onStartResize();\n };\n\n private onStartTableMove = () => {\n this.isCurrentlyEditing = true;\n this.disposeTableResizer();\n this.disposeTableInserter();\n this.disposeCellResizers();\n };\n\n private onStartResize() {\n this.isCurrentlyEditing = true;\n const range = this.editor.getDOMSelection();\n\n if (range && range.type == 'range') {\n this.range = range.range;\n }\n\n this.editor.takeSnapshot();\n }\n\n private onEndTableMove = () => {\n this.disposeTableMover();\n return this.onFinishEditing();\n };\n\n private onInserted = () => {\n this.disposeTableResizer();\n this.onFinishEditing();\n };\n\n /**\n * Public only for testing purposes\n * @param table the table to select\n */\n public onSelect = (table: HTMLTableElement) => {\n this.editor.focus();\n\n if (table) {\n const parsedTable = parseTableCells(table);\n const selection: TableSelection = {\n table: table,\n firstRow: 0,\n firstColumn: 0,\n lastRow: parsedTable.length - 1,\n lastColumn: (parsedTable[0]?.length ?? 0) - 1,\n type: 'table',\n };\n\n this.editor.setDOMSelection(selection);\n }\n };\n\n private getOnMouseOut = (feature: HTMLElement) => {\n return (ev: MouseEvent) => {\n if (\n feature &&\n ev.relatedTarget != feature &&\n isNodeOfType(this.contentDiv as Node, 'ELEMENT_NODE') &&\n isNodeOfType(ev.relatedTarget as Node, 'ELEMENT_NODE') &&\n !(this.contentDiv == ev.relatedTarget) &&\n !this.isEditing()\n ) {\n this.dispose();\n }\n };\n };\n\n private isFeatureDisabled(feature: TableEditFeatureName) {\n return this.disableFeatures?.includes(feature);\n }\n}\n"]}
|
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
import type { IEditor } from 'roosterjs-content-model-types';
|
|
2
1
|
import type { TableEditFeature } from './TableEditFeature';
|
|
2
|
+
import type { IEditor } from 'roosterjs-content-model-types';
|
|
3
|
+
/**
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
export declare const HORIZONTAL_RESIZER_ID = "horizontalResizer";
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export declare const VERTICAL_RESIZER_ID = "verticalResizer";
|
|
3
11
|
/**
|
|
4
12
|
* @internal
|
|
5
13
|
*/
|