roosterjs-content-model-plugins 0.28.2 → 9.0.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/README.md +47 -37
- package/lib/autoFormat/AutoFormatPlugin.d.ts +5 -2
- package/lib/autoFormat/AutoFormatPlugin.js +23 -11
- package/lib/autoFormat/AutoFormatPlugin.js.map +1 -1
- package/lib/autoFormat/link/createLinkAfterSpace.js +28 -22
- package/lib/autoFormat/link/createLinkAfterSpace.js.map +1 -1
- package/lib/autoFormat/link/getLinkSegment.js +2 -2
- package/lib/autoFormat/link/getLinkSegment.js.map +1 -1
- package/lib/autoFormat/list/getListTypeStyle.js +14 -14
- package/lib/autoFormat/list/getListTypeStyle.js.map +1 -1
- package/lib/autoFormat/list/getNumberingListStyle.js +29 -29
- package/lib/autoFormat/list/getNumberingListStyle.js.map +1 -1
- package/lib/autoFormat/list/keyboardListTrigger.d.ts +1 -1
- package/lib/autoFormat/list/keyboardListTrigger.js +10 -11
- package/lib/autoFormat/list/keyboardListTrigger.js.map +1 -1
- package/lib/edit/deleteSteps/deleteAllSegmentBefore.js +2 -2
- package/lib/edit/deleteSteps/deleteAllSegmentBefore.js.map +1 -1
- package/lib/edit/deleteSteps/deleteCollapsedSelection.js +4 -5
- package/lib/edit/deleteSteps/deleteCollapsedSelection.js.map +1 -1
- package/lib/edit/deleteSteps/deleteEmptyQuote.js +2 -3
- package/lib/edit/deleteSteps/deleteEmptyQuote.js.map +1 -1
- package/lib/edit/deleteSteps/deleteList.js +3 -5
- package/lib/edit/deleteSteps/deleteList.js.map +1 -1
- package/lib/edit/deleteSteps/deleteWordSelection.js +3 -4
- package/lib/edit/deleteSteps/deleteWordSelection.js.map +1 -1
- package/lib/edit/inputSteps/handleEnterOnList.js +2 -3
- package/lib/edit/inputSteps/handleEnterOnList.js.map +1 -1
- package/lib/edit/keyboardDelete.js +4 -5
- package/lib/edit/keyboardDelete.js.map +1 -1
- package/lib/edit/keyboardInput.js +3 -4
- package/lib/edit/keyboardInput.js.map +1 -1
- package/lib/edit/keyboardTab.js +3 -3
- package/lib/edit/keyboardTab.js.map +1 -1
- package/lib/index.d.ts +3 -0
- package/lib/index.js +5 -1
- package/lib/index.js.map +1 -1
- package/lib/markdown/MarkdownPlugin.d.ts +55 -0
- package/lib/markdown/MarkdownPlugin.js +177 -0
- package/lib/markdown/MarkdownPlugin.js.map +1 -0
- package/lib/markdown/utils/setFormat.d.ts +5 -0
- package/lib/markdown/utils/setFormat.js +46 -0
- package/lib/markdown/utils/setFormat.js.map +1 -0
- package/lib/paste/WordDesktop/processWordLists.js +2 -3
- package/lib/paste/WordDesktop/processWordLists.js.map +1 -1
- package/lib/pluginUtils/splitTextSegment.d.ts +5 -0
- package/lib/pluginUtils/splitTextSegment.js +26 -0
- package/lib/pluginUtils/splitTextSegment.js.map +1 -0
- package/lib/shortcut/ShortcutPlugin.js +2 -2
- package/lib/shortcut/ShortcutPlugin.js.map +1 -1
- package/lib/shortcut/utils/setShortcutIndentationCommand.js +2 -2
- package/lib/shortcut/utils/setShortcutIndentationCommand.js.map +1 -1
- package/lib/tableEdit/editors/features/CellResizer.js +5 -6
- package/lib/tableEdit/editors/features/CellResizer.js.map +1 -1
- package/lib/tableEdit/editors/features/TableResizer.js +2 -3
- package/lib/tableEdit/editors/features/TableResizer.js.map +1 -1
- package/lib/watermark/WatermarkFormat.d.ts +5 -0
- package/lib/watermark/WatermarkFormat.js +3 -0
- package/lib/watermark/WatermarkFormat.js.map +1 -0
- package/lib/watermark/WatermarkPlugin.d.ts +37 -0
- package/lib/watermark/WatermarkPlugin.js +99 -0
- package/lib/watermark/WatermarkPlugin.js.map +1 -0
- package/lib/watermark/isModelEmptyFast.d.ts +6 -0
- package/lib/watermark/isModelEmptyFast.js +35 -0
- package/lib/watermark/isModelEmptyFast.js.map +1 -0
- package/lib-amd/autoFormat/AutoFormatPlugin.d.ts +5 -2
- package/lib-amd/autoFormat/AutoFormatPlugin.js +23 -11
- package/lib-amd/autoFormat/AutoFormatPlugin.js.map +1 -1
- package/lib-amd/autoFormat/link/createLinkAfterSpace.js +28 -22
- package/lib-amd/autoFormat/link/createLinkAfterSpace.js.map +1 -1
- package/lib-amd/autoFormat/link/getLinkSegment.js +2 -2
- package/lib-amd/autoFormat/link/getLinkSegment.js.map +1 -1
- package/lib-amd/autoFormat/list/getListTypeStyle.js +14 -14
- package/lib-amd/autoFormat/list/getListTypeStyle.js.map +1 -1
- package/lib-amd/autoFormat/list/getNumberingListStyle.js +29 -29
- package/lib-amd/autoFormat/list/getNumberingListStyle.js.map +1 -1
- package/lib-amd/autoFormat/list/keyboardListTrigger.d.ts +1 -1
- package/lib-amd/autoFormat/list/keyboardListTrigger.js +11 -11
- package/lib-amd/autoFormat/list/keyboardListTrigger.js.map +1 -1
- package/lib-amd/edit/deleteSteps/deleteAllSegmentBefore.js +2 -2
- package/lib-amd/edit/deleteSteps/deleteAllSegmentBefore.js.map +1 -1
- package/lib-amd/edit/deleteSteps/deleteCollapsedSelection.js +5 -5
- package/lib-amd/edit/deleteSteps/deleteCollapsedSelection.js.map +1 -1
- package/lib-amd/edit/deleteSteps/deleteEmptyQuote.js +3 -3
- package/lib-amd/edit/deleteSteps/deleteEmptyQuote.js.map +1 -1
- package/lib-amd/edit/deleteSteps/deleteList.js +3 -5
- package/lib-amd/edit/deleteSteps/deleteList.js.map +1 -1
- package/lib-amd/edit/deleteSteps/deleteWordSelection.js +4 -4
- package/lib-amd/edit/deleteSteps/deleteWordSelection.js.map +1 -1
- package/lib-amd/edit/inputSteps/handleEnterOnList.js +3 -3
- package/lib-amd/edit/inputSteps/handleEnterOnList.js.map +1 -1
- package/lib-amd/edit/keyboardDelete.js +4 -4
- package/lib-amd/edit/keyboardDelete.js.map +1 -1
- package/lib-amd/edit/keyboardInput.js +3 -3
- package/lib-amd/edit/keyboardInput.js.map +1 -1
- package/lib-amd/edit/keyboardTab.js +3 -3
- package/lib-amd/edit/keyboardTab.js.map +1 -1
- package/lib-amd/index.d.ts +3 -0
- package/lib-amd/index.js +4 -2
- package/lib-amd/index.js.map +1 -1
- package/lib-amd/markdown/MarkdownPlugin.d.ts +55 -0
- package/lib-amd/markdown/MarkdownPlugin.js +178 -0
- package/lib-amd/markdown/MarkdownPlugin.js.map +1 -0
- package/lib-amd/markdown/utils/setFormat.d.ts +5 -0
- package/lib-amd/markdown/utils/setFormat.js +45 -0
- package/lib-amd/markdown/utils/setFormat.js.map +1 -0
- package/lib-amd/paste/WordDesktop/processWordLists.js +3 -3
- package/lib-amd/paste/WordDesktop/processWordLists.js.map +1 -1
- package/lib-amd/pluginUtils/splitTextSegment.d.ts +5 -0
- package/lib-amd/pluginUtils/splitTextSegment.js +26 -0
- package/lib-amd/pluginUtils/splitTextSegment.js.map +1 -0
- package/lib-amd/shortcut/ShortcutPlugin.js +2 -2
- package/lib-amd/shortcut/ShortcutPlugin.js.map +1 -1
- package/lib-amd/shortcut/utils/setShortcutIndentationCommand.js +2 -2
- package/lib-amd/shortcut/utils/setShortcutIndentationCommand.js.map +1 -1
- package/lib-amd/tableEdit/editors/features/CellResizer.js +6 -6
- package/lib-amd/tableEdit/editors/features/CellResizer.js.map +1 -1
- package/lib-amd/tableEdit/editors/features/TableResizer.js +3 -3
- package/lib-amd/tableEdit/editors/features/TableResizer.js.map +1 -1
- package/lib-amd/watermark/WatermarkFormat.d.ts +5 -0
- package/lib-amd/watermark/WatermarkFormat.js +5 -0
- package/lib-amd/watermark/WatermarkFormat.js.map +1 -0
- package/lib-amd/watermark/WatermarkPlugin.d.ts +37 -0
- package/lib-amd/watermark/WatermarkPlugin.js +99 -0
- package/lib-amd/watermark/WatermarkPlugin.js.map +1 -0
- package/lib-amd/watermark/isModelEmptyFast.d.ts +6 -0
- package/lib-amd/watermark/isModelEmptyFast.js +37 -0
- package/lib-amd/watermark/isModelEmptyFast.js.map +1 -0
- package/lib-mjs/autoFormat/AutoFormatPlugin.d.ts +5 -2
- package/lib-mjs/autoFormat/AutoFormatPlugin.js +23 -11
- package/lib-mjs/autoFormat/AutoFormatPlugin.js.map +1 -1
- package/lib-mjs/autoFormat/link/createLinkAfterSpace.js +28 -22
- package/lib-mjs/autoFormat/link/createLinkAfterSpace.js.map +1 -1
- package/lib-mjs/autoFormat/link/getLinkSegment.js +1 -1
- package/lib-mjs/autoFormat/link/getLinkSegment.js.map +1 -1
- package/lib-mjs/autoFormat/list/getListTypeStyle.js +2 -2
- package/lib-mjs/autoFormat/list/getListTypeStyle.js.map +1 -1
- package/lib-mjs/autoFormat/list/getNumberingListStyle.js +1 -1
- package/lib-mjs/autoFormat/list/getNumberingListStyle.js.map +1 -1
- package/lib-mjs/autoFormat/list/keyboardListTrigger.d.ts +1 -1
- package/lib-mjs/autoFormat/list/keyboardListTrigger.js +11 -12
- package/lib-mjs/autoFormat/list/keyboardListTrigger.js.map +1 -1
- package/lib-mjs/edit/deleteSteps/deleteAllSegmentBefore.js +1 -1
- package/lib-mjs/edit/deleteSteps/deleteAllSegmentBefore.js.map +1 -1
- package/lib-mjs/edit/deleteSteps/deleteCollapsedSelection.js +1 -2
- package/lib-mjs/edit/deleteSteps/deleteCollapsedSelection.js.map +1 -1
- package/lib-mjs/edit/deleteSteps/deleteEmptyQuote.js +1 -2
- package/lib-mjs/edit/deleteSteps/deleteEmptyQuote.js.map +1 -1
- package/lib-mjs/edit/deleteSteps/deleteList.js +2 -4
- package/lib-mjs/edit/deleteSteps/deleteList.js.map +1 -1
- package/lib-mjs/edit/deleteSteps/deleteWordSelection.js +1 -2
- package/lib-mjs/edit/deleteSteps/deleteWordSelection.js.map +1 -1
- package/lib-mjs/edit/inputSteps/handleEnterOnList.js +1 -2
- package/lib-mjs/edit/inputSteps/handleEnterOnList.js.map +1 -1
- package/lib-mjs/edit/keyboardDelete.js +1 -2
- package/lib-mjs/edit/keyboardDelete.js.map +1 -1
- package/lib-mjs/edit/keyboardInput.js +1 -2
- package/lib-mjs/edit/keyboardInput.js.map +1 -1
- package/lib-mjs/edit/keyboardTab.js +1 -1
- package/lib-mjs/edit/keyboardTab.js.map +1 -1
- package/lib-mjs/index.d.ts +3 -0
- package/lib-mjs/index.js +2 -0
- package/lib-mjs/index.js.map +1 -1
- package/lib-mjs/markdown/MarkdownPlugin.d.ts +55 -0
- package/lib-mjs/markdown/MarkdownPlugin.js +174 -0
- package/lib-mjs/markdown/MarkdownPlugin.js.map +1 -0
- package/lib-mjs/markdown/utils/setFormat.d.ts +5 -0
- package/lib-mjs/markdown/utils/setFormat.js +42 -0
- package/lib-mjs/markdown/utils/setFormat.js.map +1 -0
- package/lib-mjs/paste/WordDesktop/processWordLists.js +1 -2
- package/lib-mjs/paste/WordDesktop/processWordLists.js.map +1 -1
- package/lib-mjs/pluginUtils/splitTextSegment.d.ts +5 -0
- package/lib-mjs/pluginUtils/splitTextSegment.js +22 -0
- package/lib-mjs/pluginUtils/splitTextSegment.js.map +1 -0
- package/lib-mjs/shortcut/ShortcutPlugin.js +1 -1
- package/lib-mjs/shortcut/ShortcutPlugin.js.map +1 -1
- package/lib-mjs/shortcut/utils/setShortcutIndentationCommand.js +1 -1
- package/lib-mjs/shortcut/utils/setShortcutIndentationCommand.js.map +1 -1
- package/lib-mjs/tableEdit/editors/features/CellResizer.js +1 -2
- package/lib-mjs/tableEdit/editors/features/CellResizer.js.map +1 -1
- package/lib-mjs/tableEdit/editors/features/TableResizer.js +1 -2
- package/lib-mjs/tableEdit/editors/features/TableResizer.js.map +1 -1
- package/lib-mjs/watermark/WatermarkFormat.d.ts +5 -0
- package/lib-mjs/watermark/WatermarkFormat.js +2 -0
- package/lib-mjs/watermark/WatermarkFormat.js.map +1 -0
- package/lib-mjs/watermark/WatermarkPlugin.d.ts +37 -0
- package/lib-mjs/watermark/WatermarkPlugin.js +96 -0
- package/lib-mjs/watermark/WatermarkPlugin.js.map +1 -0
- package/lib-mjs/watermark/isModelEmptyFast.d.ts +6 -0
- package/lib-mjs/watermark/isModelEmptyFast.js +31 -0
- package/lib-mjs/watermark/isModelEmptyFast.js.map +1 -0
- package/package.json +6 -6
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ShortcutPlugin = void 0;
|
|
4
|
-
var
|
|
4
|
+
var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
|
|
5
5
|
var shortcuts_1 = require("./shortcuts");
|
|
6
6
|
var defaultShortcuts = [
|
|
7
7
|
shortcuts_1.ShortcutBold,
|
|
@@ -88,7 +88,7 @@ var ShortcutPlugin = /** @class */ (function () {
|
|
|
88
88
|
};
|
|
89
89
|
ShortcutPlugin.prototype.cacheGetCommand = function (event) {
|
|
90
90
|
var _this = this;
|
|
91
|
-
return (0,
|
|
91
|
+
return (0, roosterjs_content_model_dom_1.cacheGetEventData)(event, CommandCacheKey, function (event) {
|
|
92
92
|
var editor = _this.editor;
|
|
93
93
|
return (editor &&
|
|
94
94
|
_this.shortcuts.filter(function (command) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ShortcutPlugin.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/shortcut/ShortcutPlugin.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"ShortcutPlugin.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/shortcut/ShortcutPlugin.ts"],"names":[],"mappings":";;;AAAA,2EAAgE;AAEhE,yCAeqB;AAQrB,IAAM,gBAAgB,GAAsB;IACxC,wBAAY;IACZ,0BAAc;IACd,6BAAiB;IACjB,+BAAmB;IACnB,wBAAY;IACZ,yBAAa;IACb,wBAAY;IACZ,6BAAiB;IACjB,0BAAc;IACd,6BAAiB;IACjB,gCAAoB;IACpB,gCAAoB;IACpB,8BAAkB;IAClB,+BAAmB;CACtB,CAAC;AACF,IAAM,eAAe,GAAG,wBAAwB,CAAC;AAEjD;;GAEG;AACH;IAII;;;OAGG;IACH,wBAAoB,SAA+C;QAA/C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IA2GC;AA3GY,wCAAc","sourcesContent":["import { cacheGetEventData } from 'roosterjs-content-model-dom';\nimport type { ShortcutCommand, ShortcutKeyDefinition } from './ShortcutCommand';\nimport {\n ShortcutBold,\n ShortcutBullet,\n ShortcutClearFormat,\n ShortcutDecreaseFont,\n ShortcutIncreaseFont,\n ShortcutIndentList,\n ShortcutItalic,\n ShortcutNumbering,\n ShortcutOutdentList,\n ShortcutRedo,\n ShortcutRedoMacOS,\n ShortcutUnderline,\n ShortcutUndo,\n ShortcutUndo2,\n} from './shortcuts';\nimport type {\n EditorPlugin,\n IEditor,\n KeyDownEvent,\n PluginEvent,\n} from 'roosterjs-content-model-types';\n\nconst defaultShortcuts: ShortcutCommand[] = [\n ShortcutBold,\n ShortcutItalic,\n ShortcutUnderline,\n ShortcutClearFormat,\n ShortcutUndo,\n ShortcutUndo2,\n ShortcutRedo,\n ShortcutRedoMacOS,\n ShortcutBullet,\n ShortcutNumbering,\n ShortcutIncreaseFont,\n ShortcutDecreaseFont,\n ShortcutIndentList,\n ShortcutOutdentList,\n];\nconst CommandCacheKey = '__ShortcutCommandCache';\n\n/**\n * Shortcut plugin hook on the specified shortcut keys and trigger related format API\n */\nexport class ShortcutPlugin implements EditorPlugin {\n private editor: IEditor | null = null;\n private isMac = false;\n\n /**\n * Create a new instance of ShortcutPlugin\n * @param [shortcuts=defaultShortcuts] Allowed commands\n */\n constructor(private shortcuts: ShortcutCommand[] = defaultShortcuts) {}\n\n /**\n * Get name of this plugin\n */\n getName() {\n return 'Shortcut';\n }\n\n /**\n * The first method that editor will call to a plugin when editor is initializing.\n * It will pass in the editor instance, plugin should take this chance to save the\n * editor reference so that it can call to any editor method or format API later.\n * @param editor The editor object\n */\n initialize(editor: IEditor) {\n this.editor = editor;\n this.isMac = !!this.editor.getEnvironment().isMac;\n }\n\n /**\n * The last method that editor will call to a plugin before it is disposed.\n * Plugin can take this chance to clear the reference to editor. After this method is\n * called, plugin should not call to any editor method since it will result in error.\n */\n dispose() {\n this.editor = null;\n }\n\n /**\n * Check if the plugin should handle the given event exclusively.\n * Handle an event exclusively means other plugin will not receive this event in\n * onPluginEvent method.\n * If two plugins will return true in willHandleEventExclusively() for the same event,\n * the final result depends on the order of the plugins are added into editor\n * @param event The event to check:\n */\n willHandleEventExclusively(event: PluginEvent) {\n return (\n event.eventType == 'keyDown' &&\n (event.rawEvent.ctrlKey || event.rawEvent.altKey || event.rawEvent.metaKey) &&\n !!this.cacheGetCommand(event)\n );\n }\n\n /**\n * Core method for a plugin. Once an event happens in editor, editor will call this\n * method of each plugin to handle the event as long as the event is not handled\n * exclusively by another plugin.\n * @param event The event to handle:\n */\n onPluginEvent(event: PluginEvent) {\n if (this.editor && event.eventType == 'keyDown') {\n const command = this.cacheGetCommand(event);\n\n if (command) {\n command.onClick(this.editor);\n event.rawEvent.preventDefault();\n }\n }\n }\n\n private cacheGetCommand(event: KeyDownEvent) {\n return cacheGetEventData(event, CommandCacheKey, event => {\n const editor = this.editor;\n\n return (\n editor &&\n this.shortcuts.filter(\n command =>\n this.matchOS(command.environment) &&\n this.matchShortcut(command.shortcutKey, event.rawEvent)\n )[0]\n );\n });\n }\n\n private matchOS(environment?: 'all' | 'mac' | 'nonMac') {\n switch (environment) {\n case 'mac':\n return this.isMac;\n\n case 'nonMac':\n return !this.isMac;\n\n default:\n return true;\n }\n }\n\n private matchShortcut(shortcutKey: ShortcutKeyDefinition, event: KeyboardEvent) {\n const { ctrlKey, altKey, shiftKey, which, metaKey } = event;\n const ctrlOrMeta = this.isMac ? metaKey : ctrlKey;\n const matchModifier =\n (shortcutKey.modifierKey == 'ctrl' && ctrlOrMeta && !altKey) ||\n (shortcutKey.modifierKey == 'alt' && altKey && !ctrlOrMeta);\n\n return matchModifier && shiftKey == shortcutKey.shiftKey && shortcutKey.which == which;\n }\n}\n"]}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.setShortcutIndentationCommand = void 0;
|
|
4
|
-
var
|
|
4
|
+
var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
|
|
5
5
|
var roosterjs_content_model_api_1 = require("roosterjs-content-model-api");
|
|
6
6
|
/**
|
|
7
7
|
* @internal
|
|
8
8
|
*/
|
|
9
9
|
function setShortcutIndentationCommand(editor, operation) {
|
|
10
10
|
editor.formatContentModel(function (model) {
|
|
11
|
-
var listItem = (0,
|
|
11
|
+
var listItem = (0, roosterjs_content_model_dom_1.getFirstSelectedListItem)(model);
|
|
12
12
|
if (listItem &&
|
|
13
13
|
listItem.blocks[0].blockType == 'Paragraph' &&
|
|
14
14
|
listItem.blocks[0].segments[0].segmentType == 'SelectionMarker') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setShortcutIndentationCommand.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/shortcut/utils/setShortcutIndentationCommand.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"setShortcutIndentationCommand.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/shortcut/utils/setShortcutIndentationCommand.ts"],"names":[],"mappings":";;;AAAA,2EAAuE;AACvE,2EAAkE;AAGlE;;GAEG;AACH,SAAgB,6BAA6B,CAAC,MAAe,EAAE,SAA+B;IAC1F,MAAM,CAAC,kBAAkB,CAAC,UAAA,KAAK;QAC3B,IAAM,QAAQ,GAAG,IAAA,sDAAwB,EAAC,KAAK,CAAC,CAAC;QAEjD,IACI,QAAQ;YACR,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,IAAI,WAAW;YAC3C,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,WAAW,IAAI,iBAAiB,EACjE;YACE,IAAA,iDAAmB,EAAC,KAAK,EAAE,SAAS,CAAC,CAAC;YACtC,OAAO,IAAI,CAAC;SACf;QACD,OAAO,KAAK,CAAC;IACjB,CAAC,CAAC,CAAC;AACP,CAAC;AAdD,sEAcC","sourcesContent":["import { getFirstSelectedListItem } from 'roosterjs-content-model-dom';\nimport { setModelIndentation } from 'roosterjs-content-model-api';\nimport type { IEditor } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function setShortcutIndentationCommand(editor: IEditor, operation: 'indent' | 'outdent') {\n editor.formatContentModel(model => {\n const listItem = getFirstSelectedListItem(model);\n\n if (\n listItem &&\n listItem.blocks[0].blockType == 'Paragraph' &&\n listItem.blocks[0].segments[0].segmentType == 'SelectionMarker'\n ) {\n setModelIndentation(model, operation);\n return true;\n }\n return false;\n });\n}\n"]}
|
|
@@ -5,7 +5,6 @@ var tslib_1 = require("tslib");
|
|
|
5
5
|
var createElement_1 = require("../../../pluginUtils/CreateElement/createElement");
|
|
6
6
|
var DragAndDropHelper_1 = require("../../../pluginUtils/DragAndDrop/DragAndDropHelper");
|
|
7
7
|
var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
|
|
8
|
-
var roosterjs_content_model_core_1 = require("roosterjs-content-model-core");
|
|
9
8
|
var CELL_RESIZER_WIDTH = 4;
|
|
10
9
|
/**
|
|
11
10
|
* @internal
|
|
@@ -61,7 +60,7 @@ function onDragStart(context, event) {
|
|
|
61
60
|
table: table,
|
|
62
61
|
});
|
|
63
62
|
// Get the table content model
|
|
64
|
-
var cmTable = (0,
|
|
63
|
+
var cmTable = (0, roosterjs_content_model_dom_1.getFirstSelectedTable)(editor.getContentModelCopy('disconnected'))[0];
|
|
65
64
|
// Restore selection
|
|
66
65
|
editor.setDOMSelection(selection);
|
|
67
66
|
if (rect && cmTable) {
|
|
@@ -92,7 +91,7 @@ function onDraggingHorizontal(context, event, initValue, deltaX, deltaY) {
|
|
|
92
91
|
// Modify the CM Table size
|
|
93
92
|
cmTable.rows[anchorRow].height = (anchorRowHeight !== null && anchorRowHeight !== void 0 ? anchorRowHeight : 0) + deltaY;
|
|
94
93
|
// Normalize the table
|
|
95
|
-
(0,
|
|
94
|
+
(0, roosterjs_content_model_dom_1.normalizeTable)(cmTable);
|
|
96
95
|
// Writeback CM Table size changes to DOM Table
|
|
97
96
|
var tableRow = table.rows[anchorRow];
|
|
98
97
|
for (var col = 0; col < tableRow.cells.length; col++) {
|
|
@@ -122,15 +121,15 @@ function onDraggingVertical(context, event, initValue, deltaX) {
|
|
|
122
121
|
// Any other two columns
|
|
123
122
|
var anchorChange = allWidths[anchorColumn] + change;
|
|
124
123
|
var nextAnchorChange = allWidths[anchorColumn + 1] - change;
|
|
125
|
-
if (anchorChange <
|
|
126
|
-
nextAnchorChange <
|
|
124
|
+
if (anchorChange < roosterjs_content_model_dom_1.MIN_ALLOWED_TABLE_CELL_WIDTH ||
|
|
125
|
+
nextAnchorChange < roosterjs_content_model_dom_1.MIN_ALLOWED_TABLE_CELL_WIDTH) {
|
|
127
126
|
return false;
|
|
128
127
|
}
|
|
129
128
|
cmTable.widths[anchorColumn] = anchorChange;
|
|
130
129
|
cmTable.widths[anchorColumn + 1] = nextAnchorChange;
|
|
131
130
|
}
|
|
132
131
|
// Normalize the table
|
|
133
|
-
(0,
|
|
132
|
+
(0, roosterjs_content_model_dom_1.normalizeTable)(cmTable);
|
|
134
133
|
// Writeback CM Table size changes to DOM Table
|
|
135
134
|
for (var row = 0; row < table.rows.length; row++) {
|
|
136
135
|
var tableRow = table.rows[row];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CellResizer.js","sourceRoot":"","sources":["../../../../../../packages/roosterjs-content-model-plugins/lib/tableEdit/editors/features/CellResizer.ts"],"names":[],"mappings":";;;;AAAA,kFAAiF;AACjF,wFAAuF;AACvF,2EAA6E;AAC7E,6EAIsC;AAKtC,IAAM,kBAAkB,GAAG,CAAC,CAAC;AAE7B;;GAEG;AACH,SAAgB,iBAAiB,CAC7B,MAAe,EACf,EAAwB,EACxB,KAAuB,EACvB,KAAc,EACd,YAAqB,EACrB,OAAmB,EACnB,KAAkB,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AAY,OAAO,GAAnB,EAAE,KAAK,GAAK,OAAO,MAAZ,CAAa;IAC9B,IAAM,IAAI,GAAG,IAAA,2CAAa,EAAC,EAAE,CAAC,qBAAqB,EAAE,CAAC,CAAC;IACvD,IAAI,IAAI,EAAE;QACN,OAAO,CAAC,EAAE,GAAG,iBAAiB,CAAC;QAC/B,OAAO,CAAC,KAAK,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC;QACpC,OAAO,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,kBAAkB,GAAG,CAAC,GAAG,IAAI,CAAC;QACtF,OAAO,CAAC,KAAK,CAAC,KAAK,GAAG,kBAAkB,GAAG,IAAI,CAAC;QAChD,OAAO,CAAC,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC;KACxD;AACL,CAAC","sourcesContent":["import { createElement } from '../../../pluginUtils/CreateElement/createElement';\nimport { DragAndDropHelper } from '../../../pluginUtils/DragAndDrop/DragAndDropHelper';\nimport { isElementOfType, normalizeRect } from 'roosterjs-content-model-dom';\nimport {\n getFirstSelectedTable,\n MIN_ALLOWED_TABLE_CELL_WIDTH,\n normalizeTable,\n} from 'roosterjs-content-model-core';\nimport type { DragAndDropHandler } from '../../../pluginUtils/DragAndDrop/DragAndDropHandler';\nimport type { ContentModelTable, IEditor } from 'roosterjs-content-model-types';\nimport type { TableEditFeature } from './TableEditFeature';\n\nconst CELL_RESIZER_WIDTH = 4;\n\n/**\n * @internal\n */\nexport function createCellResizer(\n editor: IEditor,\n td: HTMLTableCellElement,\n table: HTMLTableElement,\n isRTL: boolean,\n isHorizontal: boolean,\n onStart: () => void,\n onEnd: () => false,\n anchorContainer?: HTMLElement\n): TableEditFeature | null {\n const document = td.ownerDocument;\n const createElementData = {\n tag: 'div',\n style: `position: fixed; cursor: ${isHorizontal ? 'row' : 'col'}-resize; user-select: none`,\n };\n const zoomScale = editor.getDOMHelper().calculateZoomScale();\n\n const div = createElement(createElementData, document) as HTMLDivElement;\n\n (anchorContainer || document.body).appendChild(div);\n\n const context: DragAndDropContext = { editor, td, table, isRTL, zoomScale, onStart };\n const setPosition = isHorizontal ? setHorizontalPosition : setVerticalPosition;\n setPosition(context, div);\n\n const handler: DragAndDropHandler<DragAndDropContext, DragAndDropInitValue> = {\n onDragStart,\n // Horizontal modifies row height, vertical modifies column width\n onDragging: isHorizontal ? onDraggingHorizontal : onDraggingVertical,\n onDragEnd: onEnd,\n };\n\n const featureHandler = new DragAndDropHelper<DragAndDropContext, DragAndDropInitValue>(\n div,\n context,\n setPosition,\n handler,\n zoomScale,\n editor.getEnvironment().isMobileOrTablet\n );\n\n return { node: td, div, featureHandler };\n}\n\ninterface DragAndDropContext {\n editor: IEditor;\n td: HTMLTableCellElement;\n table: HTMLTableElement;\n isRTL: boolean;\n zoomScale: number;\n onStart: () => void;\n}\n\ninterface DragAndDropInitValue {\n cmTable: ContentModelTable | undefined;\n anchorColumn: number | undefined;\n anchorRow: number | undefined;\n anchorRowHeight: number;\n allWidths: number[];\n}\n\nfunction onDragStart(context: DragAndDropContext, event: MouseEvent): DragAndDropInitValue {\n const { td, onStart } = context;\n const rect = normalizeRect(td.getBoundingClientRect());\n\n // Get cell coordinates\n const columnIndex = td.cellIndex;\n const row =\n td.parentElement && isElementOfType(td.parentElement, 'tr') ? td.parentElement : undefined;\n const rowIndex = row?.rowIndex;\n\n if (rowIndex == undefined) {\n return {\n cmTable: undefined,\n anchorColumn: undefined,\n anchorRow: undefined,\n anchorRowHeight: -1,\n allWidths: [],\n }; // Just a fallback\n }\n\n const { editor, table } = context;\n\n // Get current selection\n const selection = editor.getDOMSelection();\n\n // Select first cell of the table\n editor.setDOMSelection({\n type: 'table',\n firstColumn: 0,\n firstRow: 0,\n lastColumn: 0,\n lastRow: 0,\n table: table,\n });\n\n // Get the table content model\n const cmTable = getFirstSelectedTable(editor.getContentModelCopy('disconnected'))[0];\n\n // Restore selection\n editor.setDOMSelection(selection);\n\n if (rect && cmTable) {\n onStart();\n\n return {\n cmTable,\n anchorColumn: columnIndex,\n anchorRow: rowIndex,\n anchorRowHeight: cmTable.rows[rowIndex].height,\n allWidths: [...cmTable.widths],\n };\n } else {\n return {\n cmTable,\n anchorColumn: undefined,\n anchorRow: undefined,\n anchorRowHeight: -1,\n allWidths: [],\n }; // Just a fallback\n }\n}\n\nfunction onDraggingHorizontal(\n context: DragAndDropContext,\n event: MouseEvent,\n initValue: DragAndDropInitValue,\n deltaX: number,\n deltaY: number\n) {\n const { table } = context;\n const { cmTable, anchorRow, anchorRowHeight } = initValue;\n\n // Assign new widths and heights to the CM table\n if (cmTable && anchorRow != undefined) {\n // Modify the CM Table size\n cmTable.rows[anchorRow].height = (anchorRowHeight ?? 0) + deltaY;\n\n // Normalize the table\n normalizeTable(cmTable);\n\n // Writeback CM Table size changes to DOM Table\n const tableRow = table.rows[anchorRow];\n for (let col = 0; col < tableRow.cells.length; col++) {\n const td = tableRow.cells[col];\n td.style.height = cmTable.rows[anchorRow].height + 'px';\n }\n\n return true;\n } else {\n return false;\n }\n}\n\nfunction onDraggingVertical(\n context: DragAndDropContext,\n event: MouseEvent,\n initValue: DragAndDropInitValue,\n deltaX: number\n) {\n const { table, isRTL } = context;\n const { cmTable, anchorColumn, allWidths } = initValue;\n\n // Assign new widths and heights to the CM table\n if (cmTable && anchorColumn != undefined) {\n // Modify the CM Table size\n const lastColumn = anchorColumn == cmTable.widths.length - 1;\n const change = deltaX * (isRTL ? -1 : 1);\n // This is the last column\n if (lastColumn) {\n // Only the last column changes\n cmTable.widths[anchorColumn] = allWidths[anchorColumn] + change;\n } else {\n // Any other two columns\n const anchorChange = allWidths[anchorColumn] + change;\n const nextAnchorChange = allWidths[anchorColumn + 1] - change;\n if (\n anchorChange < MIN_ALLOWED_TABLE_CELL_WIDTH ||\n nextAnchorChange < MIN_ALLOWED_TABLE_CELL_WIDTH\n ) {\n return false;\n }\n cmTable.widths[anchorColumn] = anchorChange;\n cmTable.widths[anchorColumn + 1] = nextAnchorChange;\n }\n\n // Normalize the table\n normalizeTable(cmTable);\n\n // Writeback CM Table size changes to DOM Table\n for (let row = 0; row < table.rows.length; row++) {\n const tableRow = table.rows[row];\n for (let col = 0; col < tableRow.cells.length; col++) {\n tableRow.cells[col].style.width = cmTable.widths[col] + 'px';\n }\n }\n\n return true;\n } else {\n return false;\n }\n}\n\nfunction setHorizontalPosition(context: DragAndDropContext, trigger: HTMLElement) {\n const { td } = context;\n const rect = normalizeRect(td.getBoundingClientRect());\n if (rect) {\n trigger.id = 'horizontalResizer';\n trigger.style.top = rect.bottom - CELL_RESIZER_WIDTH + 'px';\n trigger.style.left = rect.left + 'px';\n trigger.style.width = rect.right - rect.left + 'px';\n trigger.style.height = CELL_RESIZER_WIDTH + 'px';\n }\n}\n\nfunction setVerticalPosition(context: DragAndDropContext, trigger: HTMLElement) {\n const { td, isRTL } = context;\n const rect = normalizeRect(td.getBoundingClientRect());\n if (rect) {\n trigger.id = 'verticalResizer';\n trigger.style.top = rect.top + 'px';\n trigger.style.left = (isRTL ? rect.left : rect.right) - CELL_RESIZER_WIDTH + 1 + 'px';\n trigger.style.width = CELL_RESIZER_WIDTH + 'px';\n trigger.style.height = rect.bottom - rect.top + 'px';\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"CellResizer.js","sourceRoot":"","sources":["../../../../../../packages/roosterjs-content-model-plugins/lib/tableEdit/editors/features/CellResizer.ts"],"names":[],"mappings":";;;;AAAA,kFAAiF;AACjF,wFAAuF;AACvF,2EAMqC;AAKrC,IAAM,kBAAkB,GAAG,CAAC,CAAC;AAE7B;;GAEG;AACH,SAAgB,iBAAiB,CAC7B,MAAe,EACf,EAAwB,EACxB,KAAuB,EACvB,KAAc,EACd,YAAqB,EACrB,OAAmB,EACnB,KAAkB,EAClB,eAA6B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AAnB,EAAE,KAAK,GAAK,OAAO,MAAZ,CAAa;IAC9B,IAAM,IAAI,GAAG,IAAA,2CAAa,EAAC,EAAE,CAAC,qBAAqB,EAAE,CAAC,CAAC;IACvD,IAAI,IAAI,EAAE;QACN,OAAO,CAAC,EAAE,GAAG,iBAAiB,CAAC;QAC/B,OAAO,CAAC,KAAK,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC;QACpC,OAAO,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,kBAAkB,GAAG,CAAC,GAAG,IAAI,CAAC;QACtF,OAAO,CAAC,KAAK,CAAC,KAAK,GAAG,kBAAkB,GAAG,IAAI,CAAC;QAChD,OAAO,CAAC,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC;KACxD;AACL,CAAC","sourcesContent":["import { createElement } from '../../../pluginUtils/CreateElement/createElement';\nimport { DragAndDropHelper } from '../../../pluginUtils/DragAndDrop/DragAndDropHelper';\nimport {\n isElementOfType,\n normalizeRect,\n getFirstSelectedTable,\n MIN_ALLOWED_TABLE_CELL_WIDTH,\n normalizeTable,\n} from 'roosterjs-content-model-dom';\nimport type { DragAndDropHandler } from '../../../pluginUtils/DragAndDrop/DragAndDropHandler';\nimport type { ContentModelTable, IEditor } from 'roosterjs-content-model-types';\nimport type { TableEditFeature } from './TableEditFeature';\n\nconst CELL_RESIZER_WIDTH = 4;\n\n/**\n * @internal\n */\nexport function createCellResizer(\n editor: IEditor,\n td: HTMLTableCellElement,\n table: HTMLTableElement,\n isRTL: boolean,\n isHorizontal: boolean,\n onStart: () => void,\n onEnd: () => false,\n anchorContainer?: HTMLElement\n): TableEditFeature | null {\n const document = td.ownerDocument;\n const createElementData = {\n tag: 'div',\n style: `position: fixed; cursor: ${isHorizontal ? 'row' : 'col'}-resize; user-select: none`,\n };\n const zoomScale = editor.getDOMHelper().calculateZoomScale();\n\n const div = createElement(createElementData, document) as HTMLDivElement;\n\n (anchorContainer || document.body).appendChild(div);\n\n const context: DragAndDropContext = { editor, td, table, isRTL, zoomScale, onStart };\n const setPosition = isHorizontal ? setHorizontalPosition : setVerticalPosition;\n setPosition(context, div);\n\n const handler: DragAndDropHandler<DragAndDropContext, DragAndDropInitValue> = {\n onDragStart,\n // Horizontal modifies row height, vertical modifies column width\n onDragging: isHorizontal ? onDraggingHorizontal : onDraggingVertical,\n onDragEnd: onEnd,\n };\n\n const featureHandler = new DragAndDropHelper<DragAndDropContext, DragAndDropInitValue>(\n div,\n context,\n setPosition,\n handler,\n zoomScale,\n editor.getEnvironment().isMobileOrTablet\n );\n\n return { node: td, div, featureHandler };\n}\n\ninterface DragAndDropContext {\n editor: IEditor;\n td: HTMLTableCellElement;\n table: HTMLTableElement;\n isRTL: boolean;\n zoomScale: number;\n onStart: () => void;\n}\n\ninterface DragAndDropInitValue {\n cmTable: ContentModelTable | undefined;\n anchorColumn: number | undefined;\n anchorRow: number | undefined;\n anchorRowHeight: number;\n allWidths: number[];\n}\n\nfunction onDragStart(context: DragAndDropContext, event: MouseEvent): DragAndDropInitValue {\n const { td, onStart } = context;\n const rect = normalizeRect(td.getBoundingClientRect());\n\n // Get cell coordinates\n const columnIndex = td.cellIndex;\n const row =\n td.parentElement && isElementOfType(td.parentElement, 'tr') ? td.parentElement : undefined;\n const rowIndex = row?.rowIndex;\n\n if (rowIndex == undefined) {\n return {\n cmTable: undefined,\n anchorColumn: undefined,\n anchorRow: undefined,\n anchorRowHeight: -1,\n allWidths: [],\n }; // Just a fallback\n }\n\n const { editor, table } = context;\n\n // Get current selection\n const selection = editor.getDOMSelection();\n\n // Select first cell of the table\n editor.setDOMSelection({\n type: 'table',\n firstColumn: 0,\n firstRow: 0,\n lastColumn: 0,\n lastRow: 0,\n table: table,\n });\n\n // Get the table content model\n const cmTable = getFirstSelectedTable(editor.getContentModelCopy('disconnected'))[0];\n\n // Restore selection\n editor.setDOMSelection(selection);\n\n if (rect && cmTable) {\n onStart();\n\n return {\n cmTable,\n anchorColumn: columnIndex,\n anchorRow: rowIndex,\n anchorRowHeight: cmTable.rows[rowIndex].height,\n allWidths: [...cmTable.widths],\n };\n } else {\n return {\n cmTable,\n anchorColumn: undefined,\n anchorRow: undefined,\n anchorRowHeight: -1,\n allWidths: [],\n }; // Just a fallback\n }\n}\n\nfunction onDraggingHorizontal(\n context: DragAndDropContext,\n event: MouseEvent,\n initValue: DragAndDropInitValue,\n deltaX: number,\n deltaY: number\n) {\n const { table } = context;\n const { cmTable, anchorRow, anchorRowHeight } = initValue;\n\n // Assign new widths and heights to the CM table\n if (cmTable && anchorRow != undefined) {\n // Modify the CM Table size\n cmTable.rows[anchorRow].height = (anchorRowHeight ?? 0) + deltaY;\n\n // Normalize the table\n normalizeTable(cmTable);\n\n // Writeback CM Table size changes to DOM Table\n const tableRow = table.rows[anchorRow];\n for (let col = 0; col < tableRow.cells.length; col++) {\n const td = tableRow.cells[col];\n td.style.height = cmTable.rows[anchorRow].height + 'px';\n }\n\n return true;\n } else {\n return false;\n }\n}\n\nfunction onDraggingVertical(\n context: DragAndDropContext,\n event: MouseEvent,\n initValue: DragAndDropInitValue,\n deltaX: number\n) {\n const { table, isRTL } = context;\n const { cmTable, anchorColumn, allWidths } = initValue;\n\n // Assign new widths and heights to the CM table\n if (cmTable && anchorColumn != undefined) {\n // Modify the CM Table size\n const lastColumn = anchorColumn == cmTable.widths.length - 1;\n const change = deltaX * (isRTL ? -1 : 1);\n // This is the last column\n if (lastColumn) {\n // Only the last column changes\n cmTable.widths[anchorColumn] = allWidths[anchorColumn] + change;\n } else {\n // Any other two columns\n const anchorChange = allWidths[anchorColumn] + change;\n const nextAnchorChange = allWidths[anchorColumn + 1] - change;\n if (\n anchorChange < MIN_ALLOWED_TABLE_CELL_WIDTH ||\n nextAnchorChange < MIN_ALLOWED_TABLE_CELL_WIDTH\n ) {\n return false;\n }\n cmTable.widths[anchorColumn] = anchorChange;\n cmTable.widths[anchorColumn + 1] = nextAnchorChange;\n }\n\n // Normalize the table\n normalizeTable(cmTable);\n\n // Writeback CM Table size changes to DOM Table\n for (let row = 0; row < table.rows.length; row++) {\n const tableRow = table.rows[row];\n for (let col = 0; col < tableRow.cells.length; col++) {\n tableRow.cells[col].style.width = cmTable.widths[col] + 'px';\n }\n }\n\n return true;\n } else {\n return false;\n }\n}\n\nfunction setHorizontalPosition(context: DragAndDropContext, trigger: HTMLElement) {\n const { td } = context;\n const rect = normalizeRect(td.getBoundingClientRect());\n if (rect) {\n trigger.id = 'horizontalResizer';\n trigger.style.top = rect.bottom - CELL_RESIZER_WIDTH + 'px';\n trigger.style.left = rect.left + 'px';\n trigger.style.width = rect.right - rect.left + 'px';\n trigger.style.height = CELL_RESIZER_WIDTH + 'px';\n }\n}\n\nfunction setVerticalPosition(context: DragAndDropContext, trigger: HTMLElement) {\n const { td, isRTL } = context;\n const rect = normalizeRect(td.getBoundingClientRect());\n if (rect) {\n trigger.id = 'verticalResizer';\n trigger.style.top = rect.top + 'px';\n trigger.style.left = (isRTL ? rect.left : rect.right) - CELL_RESIZER_WIDTH + 1 + 'px';\n trigger.style.width = CELL_RESIZER_WIDTH + 'px';\n trigger.style.height = rect.bottom - rect.top + 'px';\n }\n}\n"]}
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createTableResizer = void 0;
|
|
4
4
|
var createElement_1 = require("../../../pluginUtils/CreateElement/createElement");
|
|
5
5
|
var DragAndDropHelper_1 = require("../../../pluginUtils/DragAndDrop/DragAndDropHelper");
|
|
6
|
-
var roosterjs_content_model_core_1 = require("roosterjs-content-model-core");
|
|
7
6
|
var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
|
|
8
7
|
var TABLE_RESIZER_LENGTH = 12;
|
|
9
8
|
var TABLE_RESIZER_ID = '_Table_Resizer';
|
|
@@ -61,7 +60,7 @@ function onDragStart(context, event) {
|
|
|
61
60
|
table: table,
|
|
62
61
|
});
|
|
63
62
|
// Get the table content model
|
|
64
|
-
var cmTable = (0,
|
|
63
|
+
var cmTable = (0, roosterjs_content_model_dom_1.getFirstSelectedTable)(editor.getContentModelCopy('disconnected'))[0];
|
|
65
64
|
// Restore selection
|
|
66
65
|
editor.setDOMSelection(selection);
|
|
67
66
|
// Save original widths and heights
|
|
@@ -109,7 +108,7 @@ function onDragging(context, event, initValue, deltaX, deltaY) {
|
|
|
109
108
|
}
|
|
110
109
|
}
|
|
111
110
|
// Normalize the table
|
|
112
|
-
(0,
|
|
111
|
+
(0, roosterjs_content_model_dom_1.normalizeTable)(cmTable);
|
|
113
112
|
// Writeback CM Table size changes to DOM Table
|
|
114
113
|
for (var row = 0; row < table.rows.length; row++) {
|
|
115
114
|
var tableRow = table.rows[row];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TableResizer.js","sourceRoot":"","sources":["../../../../../../packages/roosterjs-content-model-plugins/lib/tableEdit/editors/features/TableResizer.ts"],"names":[],"mappings":";;;AAAA,kFAAiF;AACjF,wFAAuF;AACvF,6EAAqF;AACrF,2EAA0E;AAI1E,IAAM,oBAAoB,GAAG,EAAE,CAAC;AAChC,IAAM,gBAAgB,GAAG,gBAAgB,CAAC;AAE1C;;GAEG;AACH,SAAgB,kBAAkB,CAC9B,KAAuB,EACvB,MAAe,EACf,KAAc,EACd,OAAmB,EACnB,KAAkB,EAClB,UAA+B,EAC/B,eAA6B;IAE7B,IAAM,IAAI,GAAG,IAAA,2CAAa,EAAC,KAAK,CAAC,qBAAqB,EAAE,CAAC,CAAC;IAE1D,IAAI,CAAC,oBAAoB,CAAC,MAAM,EAAE,IAAI,EAAE,UAAkB,CAAC,EAAE;QACzD,OAAO,IAAI,CAAC;KACf;IAED,IAAM,QAAQ,GAAG,KAAK,CAAC,aAAa,CAAC;IACrC,IAAM,SAAS,GAAG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AAC,kBAAkB,EAAE,CAAC;IACpD,IAAI,IAAA,0CAAY,EAAC,UAAU,EAAE,cAAc,CAAC,IAAI,eAAe,IAAI,IAAI,EAAE;QACrE,IAAM,aAAa,GAAG,IAAA,2CAAa,EAAC,UAAU,CAAC,qBAAqB,EAAE,CAAC,CAAC;QAExE,OAAO,CACH,CAAC,CAAC,aAAa;YACf,aAAa,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM;YACnC,eAAe,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,CACxC,CAAC;KACL;IAED,OAAO,IAAI,CAAC;AAChB,CAAC","sourcesContent":["import { createElement } from '../../../pluginUtils/CreateElement/createElement';\nimport { DragAndDropHelper } from '../../../pluginUtils/DragAndDrop/DragAndDropHelper';\nimport { getFirstSelectedTable, normalizeTable } from 'roosterjs-content-model-core';\nimport { isNodeOfType, normalizeRect } from 'roosterjs-content-model-dom';\nimport type { ContentModelTable, IEditor, Rect } from 'roosterjs-content-model-types';\nimport type { TableEditFeature } from './TableEditFeature';\n\nconst TABLE_RESIZER_LENGTH = 12;\nconst TABLE_RESIZER_ID = '_Table_Resizer';\n\n/**\n * @internal\n */\nexport function createTableResizer(\n table: HTMLTableElement,\n editor: IEditor,\n isRTL: boolean,\n onStart: () => void,\n onEnd: () => false,\n contentDiv?: EventTarget | null,\n anchorContainer?: HTMLElement\n): TableEditFeature | null {\n const rect = normalizeRect(table.getBoundingClientRect());\n\n if (!isTableBottomVisible(editor, rect, contentDiv as Node)) {\n return null;\n }\n\n const document = table.ownerDocument;\n const zoomScale = editor.getDOMHelper().calculateZoomScale();\n const createElementData = {\n tag: 'div',\n style: `position: fixed; cursor: ${\n isRTL ? 'ne' : 'nw'\n }-resize; user-select: none; border: 1px solid #808080`,\n };\n\n const div = createElement(createElementData, document) as HTMLDivElement;\n\n div.id = TABLE_RESIZER_ID;\n div.style.width = `${TABLE_RESIZER_LENGTH}px`;\n div.style.height = `${TABLE_RESIZER_LENGTH}px`;\n\n (anchorContainer || document.body).appendChild(div);\n\n const context: DragAndDropContext = {\n isRTL,\n table,\n zoomScale,\n onStart,\n onEnd,\n div,\n editor,\n contentDiv,\n };\n\n setDivPosition(context, div);\n\n const featureHandler = new DragAndDropHelper<DragAndDropContext, DragAndDropInitValue>(\n div,\n context,\n hideResizer, // Resizer is hidden while dragging only\n {\n onDragStart,\n onDragging,\n onDragEnd,\n },\n zoomScale,\n editor.getEnvironment().isMobileOrTablet\n );\n\n return { node: table, div, featureHandler };\n}\n\ninterface DragAndDropContext {\n table: HTMLTableElement;\n isRTL: boolean;\n zoomScale: number;\n onStart: () => void;\n onEnd: () => false;\n div: HTMLDivElement;\n editor: IEditor;\n contentDiv?: EventTarget | null;\n}\n\ninterface DragAndDropInitValue {\n originalRect: DOMRect;\n originalHeights: number[];\n originalWidths: number[];\n cmTable: ContentModelTable | undefined;\n}\n\nfunction onDragStart(context: DragAndDropContext, event: MouseEvent) {\n context.onStart();\n\n const { editor, table } = context;\n\n // Get current selection\n const selection = editor.getDOMSelection();\n\n // Select first cell of the table\n editor.setDOMSelection({\n type: 'table',\n firstColumn: 0,\n firstRow: 0,\n lastColumn: 0,\n lastRow: 0,\n table: table,\n });\n\n // Get the table content model\n const cmTable = getFirstSelectedTable(editor.getContentModelCopy('disconnected'))[0];\n\n // Restore selection\n editor.setDOMSelection(selection);\n\n // Save original widths and heights\n const heights: number[] = [];\n cmTable?.rows.forEach(row => {\n heights.push(row.height);\n });\n const widths: number[] = [];\n cmTable?.widths.forEach(width => {\n widths.push(width);\n });\n\n return {\n originalRect: table.getBoundingClientRect(),\n cmTable,\n originalHeights: heights ?? [],\n originalWidths: widths ?? [],\n };\n}\n\nfunction onDragging(\n context: DragAndDropContext,\n event: MouseEvent,\n initValue: DragAndDropInitValue,\n deltaX: number,\n deltaY: number\n) {\n const { isRTL, zoomScale, table } = context;\n const { originalRect, originalHeights, originalWidths, cmTable } = initValue;\n\n const ratioX = 1.0 + (deltaX / originalRect.width) * zoomScale * (isRTL ? -1 : 1);\n const ratioY = 1.0 + (deltaY / originalRect.height) * zoomScale;\n const shouldResizeX = Math.abs(ratioX - 1.0) > 1e-3;\n const shouldResizeY = Math.abs(ratioY - 1.0) > 1e-3;\n\n // If the width of some external table is fixed, we need to make it resizable\n table.style.setProperty('width', null);\n // If the height of some external table is fixed, we need to make it resizable\n table.style.setProperty('height', null);\n\n // Assign new widths and heights to the CM table\n if (cmTable && cmTable.rows && (shouldResizeX || shouldResizeY)) {\n // Modify the CM Table size\n for (let i = 0; i < cmTable.rows.length; i++) {\n for (let j = 0; j < cmTable.rows[i].cells.length; j++) {\n const cell = cmTable.rows[i].cells[j];\n if (cell) {\n if (shouldResizeX && i == 0) {\n cmTable.widths[j] = (originalWidths[j] ?? 0) * ratioX;\n }\n if (shouldResizeY && j == 0) {\n cmTable.rows[i].height = (originalHeights[i] ?? 0) * ratioY;\n }\n }\n }\n }\n\n // Normalize the table\n normalizeTable(cmTable);\n\n // Writeback CM Table size changes to DOM Table\n for (let row = 0; row < table.rows.length; row++) {\n const tableRow = table.rows[row];\n\n if (tableRow.cells.length == 0) {\n // Skip empty row\n continue;\n }\n\n for (let col = 0; col < tableRow.cells.length; col++) {\n const td = tableRow.cells[col];\n td.style.width = cmTable.widths[col] + 'px';\n td.style.height = cmTable.rows[row].height + 'px';\n }\n }\n return true;\n } else {\n return false;\n }\n}\n\nfunction onDragEnd(\n context: DragAndDropContext,\n event: MouseEvent,\n initValue: DragAndDropInitValue | undefined\n) {\n if (context.editor.isDisposed()) {\n return false;\n }\n if (\n isTableBottomVisible(\n context.editor,\n normalizeRect(context.table.getBoundingClientRect()),\n context.contentDiv as Node\n )\n ) {\n context.div.style.visibility = 'visible';\n setDivPosition(context, context.div);\n }\n context.onEnd();\n return false;\n}\n\nfunction setDivPosition(context: DragAndDropContext, trigger: HTMLElement) {\n const { table, isRTL } = context;\n const rect = normalizeRect(table.getBoundingClientRect());\n\n if (rect) {\n trigger.style.top = `${rect.bottom}px`;\n trigger.style.left = isRTL\n ? `${rect.left - TABLE_RESIZER_LENGTH - 2}px`\n : `${rect.right}px`;\n }\n}\n\nfunction hideResizer(context: DragAndDropContext, trigger: HTMLElement) {\n trigger.style.visibility = 'hidden';\n}\n\nfunction isTableBottomVisible(\n editor: IEditor,\n rect: Rect | null,\n contentDiv?: Node | null\n): boolean {\n const visibleViewport = editor.getVisibleViewport();\n if (isNodeOfType(contentDiv, 'ELEMENT_NODE') && visibleViewport && rect) {\n const containerRect = normalizeRect(contentDiv.getBoundingClientRect());\n\n return (\n !!containerRect &&\n containerRect.bottom >= rect.bottom &&\n visibleViewport.bottom >= rect.bottom\n );\n }\n\n return true;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"TableResizer.js","sourceRoot":"","sources":["../../../../../../packages/roosterjs-content-model-plugins/lib/tableEdit/editors/features/TableResizer.ts"],"names":[],"mappings":";;;AAAA,kFAAiF;AACjF,wFAAuF;AACvF,2EAKqC;AAIrC,IAAM,oBAAoB,GAAG,EAAE,CAAC;AAChC,IAAM,gBAAgB,GAAG,gBAAgB,CAAC;AAE1C;;GAEG;AACH,SAAgB,kBAAkB,CAC9B,KAAuB,EACvB,MAAe,EACf,KAAc,EACd,OAAmB,EACnB,KAAkB,EAClB,UAA+B,EAC/B,eAA6B;IAE7B,IAAM,IAAI,GAAG,IAAA,2CAAa,EAAC,KAAK,CAAC,qBAAqB,EAAE,CAAC,CAAC;IAE1D,IAAI,CAAC,oBAAoB,CAAC,MAAM,EAAE,IAAI,EAAE,UAAkB,CAAC,EAAE;QACzD,OAAO,IAAI,CAAC;KACf;IAED,IAAM,QAAQ,GAAG,KAAK,CAAC,aAAa,CAAC;IACrC,IAAM,SAAS,GAAG,MAAM,CAAC,YAAY,EAAE,CAAC,kBAAkB,EAAE,CAAC;IAC7D,IAAM,iBAAiB,GAAG;QACtB,GAAG,EAAE,KAAK;QACV,KAAK,EAAE,+BACH,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,2DACgC;K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AC;QAExE,OAAO,CACH,CAAC,CAAC,aAAa;YACf,aAAa,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM;YACnC,eAAe,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,CACxC,CAAC;KACL;IAED,OAAO,IAAI,CAAC;AAChB,CAAC","sourcesContent":["import { createElement } from '../../../pluginUtils/CreateElement/createElement';\nimport { DragAndDropHelper } from '../../../pluginUtils/DragAndDrop/DragAndDropHelper';\nimport {\n getFirstSelectedTable,\n isNodeOfType,\n normalizeRect,\n normalizeTable,\n} from 'roosterjs-content-model-dom';\nimport type { ContentModelTable, IEditor, Rect } from 'roosterjs-content-model-types';\nimport type { TableEditFeature } from './TableEditFeature';\n\nconst TABLE_RESIZER_LENGTH = 12;\nconst TABLE_RESIZER_ID = '_Table_Resizer';\n\n/**\n * @internal\n */\nexport function createTableResizer(\n table: HTMLTableElement,\n editor: IEditor,\n isRTL: boolean,\n onStart: () => void,\n onEnd: () => false,\n contentDiv?: EventTarget | null,\n anchorContainer?: HTMLElement\n): TableEditFeature | null {\n const rect = normalizeRect(table.getBoundingClientRect());\n\n if (!isTableBottomVisible(editor, rect, contentDiv as Node)) {\n return null;\n }\n\n const document = table.ownerDocument;\n const zoomScale = editor.getDOMHelper().calculateZoomScale();\n const createElementData = {\n tag: 'div',\n style: `position: fixed; cursor: ${\n isRTL ? 'ne' : 'nw'\n }-resize; user-select: none; border: 1px solid #808080`,\n };\n\n const div = createElement(createElementData, document) as HTMLDivElement;\n\n div.id = TABLE_RESIZER_ID;\n div.style.width = `${TABLE_RESIZER_LENGTH}px`;\n div.style.height = `${TABLE_RESIZER_LENGTH}px`;\n\n (anchorContainer || document.body).appendChild(div);\n\n const context: DragAndDropContext = {\n isRTL,\n table,\n zoomScale,\n onStart,\n onEnd,\n div,\n editor,\n contentDiv,\n };\n\n setDivPosition(context, div);\n\n const featureHandler = new DragAndDropHelper<DragAndDropContext, DragAndDropInitValue>(\n div,\n context,\n hideResizer, // Resizer is hidden while dragging only\n {\n onDragStart,\n onDragging,\n onDragEnd,\n },\n zoomScale,\n editor.getEnvironment().isMobileOrTablet\n );\n\n return { node: table, div, featureHandler };\n}\n\ninterface DragAndDropContext {\n table: HTMLTableElement;\n isRTL: boolean;\n zoomScale: number;\n onStart: () => void;\n onEnd: () => false;\n div: HTMLDivElement;\n editor: IEditor;\n contentDiv?: EventTarget | null;\n}\n\ninterface DragAndDropInitValue {\n originalRect: DOMRect;\n originalHeights: number[];\n originalWidths: number[];\n cmTable: ContentModelTable | undefined;\n}\n\nfunction onDragStart(context: DragAndDropContext, event: MouseEvent) {\n context.onStart();\n\n const { editor, table } = context;\n\n // Get current selection\n const selection = editor.getDOMSelection();\n\n // Select first cell of the table\n editor.setDOMSelection({\n type: 'table',\n firstColumn: 0,\n firstRow: 0,\n lastColumn: 0,\n lastRow: 0,\n table: table,\n });\n\n // Get the table content model\n const cmTable = getFirstSelectedTable(editor.getContentModelCopy('disconnected'))[0];\n\n // Restore selection\n editor.setDOMSelection(selection);\n\n // Save original widths and heights\n const heights: number[] = [];\n cmTable?.rows.forEach(row => {\n heights.push(row.height);\n });\n const widths: number[] = [];\n cmTable?.widths.forEach(width => {\n widths.push(width);\n });\n\n return {\n originalRect: table.getBoundingClientRect(),\n cmTable,\n originalHeights: heights ?? [],\n originalWidths: widths ?? [],\n };\n}\n\nfunction onDragging(\n context: DragAndDropContext,\n event: MouseEvent,\n initValue: DragAndDropInitValue,\n deltaX: number,\n deltaY: number\n) {\n const { isRTL, zoomScale, table } = context;\n const { originalRect, originalHeights, originalWidths, cmTable } = initValue;\n\n const ratioX = 1.0 + (deltaX / originalRect.width) * zoomScale * (isRTL ? -1 : 1);\n const ratioY = 1.0 + (deltaY / originalRect.height) * zoomScale;\n const shouldResizeX = Math.abs(ratioX - 1.0) > 1e-3;\n const shouldResizeY = Math.abs(ratioY - 1.0) > 1e-3;\n\n // If the width of some external table is fixed, we need to make it resizable\n table.style.setProperty('width', null);\n // If the height of some external table is fixed, we need to make it resizable\n table.style.setProperty('height', null);\n\n // Assign new widths and heights to the CM table\n if (cmTable && cmTable.rows && (shouldResizeX || shouldResizeY)) {\n // Modify the CM Table size\n for (let i = 0; i < cmTable.rows.length; i++) {\n for (let j = 0; j < cmTable.rows[i].cells.length; j++) {\n const cell = cmTable.rows[i].cells[j];\n if (cell) {\n if (shouldResizeX && i == 0) {\n cmTable.widths[j] = (originalWidths[j] ?? 0) * ratioX;\n }\n if (shouldResizeY && j == 0) {\n cmTable.rows[i].height = (originalHeights[i] ?? 0) * ratioY;\n }\n }\n }\n }\n\n // Normalize the table\n normalizeTable(cmTable);\n\n // Writeback CM Table size changes to DOM Table\n for (let row = 0; row < table.rows.length; row++) {\n const tableRow = table.rows[row];\n\n if (tableRow.cells.length == 0) {\n // Skip empty row\n continue;\n }\n\n for (let col = 0; col < tableRow.cells.length; col++) {\n const td = tableRow.cells[col];\n td.style.width = cmTable.widths[col] + 'px';\n td.style.height = cmTable.rows[row].height + 'px';\n }\n }\n return true;\n } else {\n return false;\n }\n}\n\nfunction onDragEnd(\n context: DragAndDropContext,\n event: MouseEvent,\n initValue: DragAndDropInitValue | undefined\n) {\n if (context.editor.isDisposed()) {\n return false;\n }\n if (\n isTableBottomVisible(\n context.editor,\n normalizeRect(context.table.getBoundingClientRect()),\n context.contentDiv as Node\n )\n ) {\n context.div.style.visibility = 'visible';\n setDivPosition(context, context.div);\n }\n context.onEnd();\n return false;\n}\n\nfunction setDivPosition(context: DragAndDropContext, trigger: HTMLElement) {\n const { table, isRTL } = context;\n const rect = normalizeRect(table.getBoundingClientRect());\n\n if (rect) {\n trigger.style.top = `${rect.bottom}px`;\n trigger.style.left = isRTL\n ? `${rect.left - TABLE_RESIZER_LENGTH - 2}px`\n : `${rect.right}px`;\n }\n}\n\nfunction hideResizer(context: DragAndDropContext, trigger: HTMLElement) {\n trigger.style.visibility = 'hidden';\n}\n\nfunction isTableBottomVisible(\n editor: IEditor,\n rect: Rect | null,\n contentDiv?: Node | null\n): boolean {\n const visibleViewport = editor.getVisibleViewport();\n if (isNodeOfType(contentDiv, 'ELEMENT_NODE') && visibleViewport && rect) {\n const containerRect = normalizeRect(contentDiv.getBoundingClientRect());\n\n return (\n !!containerRect &&\n containerRect.bottom >= rect.bottom &&\n visibleViewport.bottom >= rect.bottom\n );\n }\n\n return true;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WatermarkFormat.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/watermark/WatermarkFormat.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n FontFamilyFormat,\n FontSizeFormat,\n TextColorFormat,\n} from 'roosterjs-content-model-types';\n\n/**\n * Format type of watermark text\n */\nexport type WatermarkFormat = FontFamilyFormat & FontSizeFormat & TextColorFormat;\n"]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { WatermarkFormat } from './WatermarkFormat';
|
|
2
|
+
import type { EditorPlugin, IEditor, PluginEvent } from 'roosterjs-content-model-types';
|
|
3
|
+
/**
|
|
4
|
+
* A watermark plugin to manage watermark string for roosterjs
|
|
5
|
+
*/
|
|
6
|
+
export declare class WatermarkPlugin implements EditorPlugin {
|
|
7
|
+
private watermark;
|
|
8
|
+
private editor;
|
|
9
|
+
private format;
|
|
10
|
+
private isShowing;
|
|
11
|
+
/**
|
|
12
|
+
* Create an instance of Watermark plugin
|
|
13
|
+
* @param watermark The watermark string
|
|
14
|
+
*/
|
|
15
|
+
constructor(watermark: string, format?: WatermarkFormat);
|
|
16
|
+
/**
|
|
17
|
+
* Get a friendly name of this plugin
|
|
18
|
+
*/
|
|
19
|
+
getName(): string;
|
|
20
|
+
/**
|
|
21
|
+
* Initialize this plugin. This should only be called from Editor
|
|
22
|
+
* @param editor Editor instance
|
|
23
|
+
*/
|
|
24
|
+
initialize(editor: IEditor): void;
|
|
25
|
+
/**
|
|
26
|
+
* Dispose this plugin
|
|
27
|
+
*/
|
|
28
|
+
dispose(): void;
|
|
29
|
+
/**
|
|
30
|
+
* Handle events triggered from editor
|
|
31
|
+
* @param event PluginEvent object
|
|
32
|
+
*/
|
|
33
|
+
onPluginEvent(event: PluginEvent): void;
|
|
34
|
+
private showHide;
|
|
35
|
+
protected show(editor: IEditor): void;
|
|
36
|
+
protected hide(editor: IEditor): void;
|
|
37
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WatermarkPlugin = void 0;
|
|
4
|
+
var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
|
|
5
|
+
var isModelEmptyFast_1 = require("./isModelEmptyFast");
|
|
6
|
+
var WATERMARK_CONTENT_KEY = '_WatermarkContent';
|
|
7
|
+
var styleMap = {
|
|
8
|
+
fontFamily: 'font-family',
|
|
9
|
+
fontSize: 'font-size',
|
|
10
|
+
textColor: 'color',
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* A watermark plugin to manage watermark string for roosterjs
|
|
14
|
+
*/
|
|
15
|
+
var WatermarkPlugin = /** @class */ (function () {
|
|
16
|
+
/**
|
|
17
|
+
* Create an instance of Watermark plugin
|
|
18
|
+
* @param watermark The watermark string
|
|
19
|
+
*/
|
|
20
|
+
function WatermarkPlugin(watermark, format) {
|
|
21
|
+
this.watermark = watermark;
|
|
22
|
+
this.editor = null;
|
|
23
|
+
this.isShowing = false;
|
|
24
|
+
this.format = format || {
|
|
25
|
+
fontSize: '14px',
|
|
26
|
+
textColor: '#AAAAAA',
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Get a friendly name of this plugin
|
|
31
|
+
*/
|
|
32
|
+
WatermarkPlugin.prototype.getName = function () {
|
|
33
|
+
return 'Watermark';
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Initialize this plugin. This should only be called from Editor
|
|
37
|
+
* @param editor Editor instance
|
|
38
|
+
*/
|
|
39
|
+
WatermarkPlugin.prototype.initialize = function (editor) {
|
|
40
|
+
this.editor = editor;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Dispose this plugin
|
|
44
|
+
*/
|
|
45
|
+
WatermarkPlugin.prototype.dispose = function () {
|
|
46
|
+
this.editor = null;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Handle events triggered from editor
|
|
50
|
+
* @param event PluginEvent object
|
|
51
|
+
*/
|
|
52
|
+
WatermarkPlugin.prototype.onPluginEvent = function (event) {
|
|
53
|
+
var _this = this;
|
|
54
|
+
var editor = this.editor;
|
|
55
|
+
if (!editor) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (event.eventType == 'input' && event.rawEvent.inputType == 'insertText') {
|
|
59
|
+
// When input text, editor must not be empty, so we can do hide watermark now without checking content model
|
|
60
|
+
this.showHide(editor, false /*isEmpty*/);
|
|
61
|
+
}
|
|
62
|
+
else if (event.eventType == 'editorReady' ||
|
|
63
|
+
event.eventType == 'contentChanged' ||
|
|
64
|
+
event.eventType == 'input' ||
|
|
65
|
+
event.eventType == 'beforeDispose') {
|
|
66
|
+
editor.formatContentModel(function (model) {
|
|
67
|
+
var isEmpty = (0, isModelEmptyFast_1.isModelEmptyFast)(model);
|
|
68
|
+
_this.showHide(editor, isEmpty);
|
|
69
|
+
return false;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
WatermarkPlugin.prototype.showHide = function (editor, isEmpty) {
|
|
74
|
+
if (this.isShowing && !isEmpty) {
|
|
75
|
+
this.hide(editor);
|
|
76
|
+
}
|
|
77
|
+
else if (!this.isShowing && isEmpty) {
|
|
78
|
+
this.show(editor);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
WatermarkPlugin.prototype.show = function (editor) {
|
|
82
|
+
var _this = this;
|
|
83
|
+
var rule = "position: absolute; pointer-events: none; content: \"" + this.watermark + "\";";
|
|
84
|
+
(0, roosterjs_content_model_dom_1.getObjectKeys)(styleMap).forEach(function (x) {
|
|
85
|
+
if (_this.format[x]) {
|
|
86
|
+
rule += styleMap[x] + ": " + _this.format[x] + "!important;";
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
editor.setEditorStyle(WATERMARK_CONTENT_KEY, rule, 'before');
|
|
90
|
+
this.isShowing = true;
|
|
91
|
+
};
|
|
92
|
+
WatermarkPlugin.prototype.hide = function (editor) {
|
|
93
|
+
editor.setEditorStyle(WATERMARK_CONTENT_KEY, null);
|
|
94
|
+
this.isShowing = false;
|
|
95
|
+
};
|
|
96
|
+
return WatermarkPlugin;
|
|
97
|
+
}());
|
|
98
|
+
exports.WatermarkPlugin = WatermarkPlugin;
|
|
99
|
+
//# sourceMappingURL=WatermarkPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WatermarkPlugin.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/watermark/WatermarkPlugin.ts"],"names":[],"mappings":";;;AAAA,2EAA4D;AAC5D,uDAAsD;AAItD,IAAM,qBAAqB,GAAG,mBAAmB,CAAC;AAClD,IAAM,QAAQ,GAA0C;IACpD,UAAU,EAAE,aAAa;IACzB,QAAQ,EAAE,WAAW;IACrB,SAAS,EAAE,OAAO;CACrB,CAAC;AAEF;;GAEG;AACH;IAKI;;;OAGG;IACH,yBAAoB,SAAiB,EAAE,MAAwB;QAA3C,cAAS,GAAT,SAAS,CAAQ;QAR7B,WAAM,GAAmB,IAAI,CAAC;QAE9B,cAAS,GAAG,KAAK,CAAC;QAOtB,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI;YACpB,QAAQ,EAAE,MAAM;YAChB,SAAS,EAAE,SAAS;SACvB,CAAC;IACN,CAAC;IAED;;OAEG;IACH,iCAAO,GAAP;QACI,OAAO,WAAW,CAAC;IACvB,CAAC;IAED;;;OAGG;IACH,oCAAU,GAAV,UAAW,MAAe;QACtB,IAAI,CAAC,MAAM,GAAG,MAA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;QAErF,IAAA,2CAAa,EAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,UAAA,CAAC;YAC7B,IAAI,KAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE;gBAChB,IAAI,IAAO,QAAQ,CAAC,CAAC,CAAC,UAAK,KAAI,CAAC,MAAM,CAAC,CAAC,CAAC,gBAAa,CAAC;aAC1D;QACL,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,cAAc,CAAC,qBAAqB,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;QAE7D,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;IAC1B,CAAC;IAES,8BAAI,GAAd,UAAe,MAAe;QAC1B,MAAM,CAAC,cAAc,CAAC,qBAAqB,EAAE,IAAI,CAAC,CAAC;QACnD,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;IAC3B,CAAC;IACL,sBAAC;AAAD,CAAC,AA9FD,IA8FC;AA9FY,0CAAe","sourcesContent":["import { getObjectKeys } from 'roosterjs-content-model-dom';\nimport { isModelEmptyFast } from './isModelEmptyFast';\nimport type { WatermarkFormat } from './WatermarkFormat';\nimport type { EditorPlugin, IEditor, PluginEvent } from 'roosterjs-content-model-types';\n\nconst WATERMARK_CONTENT_KEY = '_WatermarkContent';\nconst styleMap: Record<keyof WatermarkFormat, string> = {\n fontFamily: 'font-family',\n fontSize: 'font-size',\n textColor: 'color',\n};\n\n/**\n * A watermark plugin to manage watermark string for roosterjs\n */\nexport class WatermarkPlugin implements EditorPlugin {\n private editor: IEditor | null = null;\n private format: WatermarkFormat;\n private isShowing = false;\n\n /**\n * Create an instance of Watermark plugin\n * @param watermark The watermark string\n */\n constructor(private watermark: string, format?: WatermarkFormat) {\n this.format = format || {\n fontSize: '14px',\n textColor: '#AAAAAA',\n };\n }\n\n /**\n * Get a friendly name of this plugin\n */\n getName() {\n return 'Watermark';\n }\n\n /**\n * Initialize this plugin. This should only be called from Editor\n * @param editor Editor instance\n */\n initialize(editor: IEditor) {\n this.editor = editor;\n }\n\n /**\n * Dispose this plugin\n */\n dispose() {\n this.editor = null;\n }\n\n /**\n * Handle events triggered from editor\n * @param event PluginEvent object\n */\n onPluginEvent(event: PluginEvent) {\n const editor = this.editor;\n\n if (!editor) {\n return;\n }\n\n if (event.eventType == 'input' && event.rawEvent.inputType == 'insertText') {\n // When input text, editor must not be empty, so we can do hide watermark now without checking content model\n this.showHide(editor, false /*isEmpty*/);\n } else if (\n event.eventType == 'editorReady' ||\n event.eventType == 'contentChanged' ||\n event.eventType == 'input' ||\n event.eventType == 'beforeDispose'\n ) {\n editor.formatContentModel(model => {\n const isEmpty = isModelEmptyFast(model);\n\n this.showHide(editor, isEmpty);\n\n return false;\n });\n }\n }\n\n private showHide(editor: IEditor, isEmpty: boolean) {\n if (this.isShowing && !isEmpty) {\n this.hide(editor);\n } else if (!this.isShowing && isEmpty) {\n this.show(editor);\n }\n }\n\n protected show(editor: IEditor) {\n let rule = `position: absolute; pointer-events: none; content: \"${this.watermark}\";`;\n\n getObjectKeys(styleMap).forEach(x => {\n if (this.format[x]) {\n rule += `${styleMap[x]}: ${this.format[x]}!important;`;\n }\n });\n\n editor.setEditorStyle(WATERMARK_CONTENT_KEY, rule, 'before');\n\n this.isShowing = true;\n }\n\n protected hide(editor: IEditor) {\n editor.setEditorStyle(WATERMARK_CONTENT_KEY, null);\n this.isShowing = false;\n }\n}\n"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isModelEmptyFast = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
* A fast way to check if content model is empty
|
|
7
|
+
*/
|
|
8
|
+
function isModelEmptyFast(model) {
|
|
9
|
+
var firstBlock = model.blocks[0];
|
|
10
|
+
if (model.blocks.length > 1) {
|
|
11
|
+
return false; // Multiple blocks, treat as not empty
|
|
12
|
+
}
|
|
13
|
+
else if (!firstBlock) {
|
|
14
|
+
return true; // No block, it is empty
|
|
15
|
+
}
|
|
16
|
+
else if (firstBlock.blockType != 'Paragraph') {
|
|
17
|
+
return false; // First block is not paragraph, treat as not empty
|
|
18
|
+
}
|
|
19
|
+
else if (firstBlock.segments.length == 0) {
|
|
20
|
+
return true; // No segment, it is empty
|
|
21
|
+
}
|
|
22
|
+
else if (firstBlock.segments.some(function (x) {
|
|
23
|
+
return x.segmentType == 'Entity' ||
|
|
24
|
+
x.segmentType == 'Image' ||
|
|
25
|
+
x.segmentType == 'General' ||
|
|
26
|
+
(x.segmentType == 'Text' && x.text);
|
|
27
|
+
})) {
|
|
28
|
+
return false; // Has meaningful segments, it is not empty
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
return firstBlock.segments.filter(function (x) { return x.segmentType == 'Br'; }).length <= 1; // If there are more than one BR, it is not empty, otherwise it is empty
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.isModelEmptyFast = isModelEmptyFast;
|
|
35
|
+
//# sourceMappingURL=isModelEmptyFast.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isModelEmptyFast.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/watermark/isModelEmptyFast.ts"],"names":[],"mappings":";;;AAEA;;;GAGG;AACH,SAAgB,gBAAgB,CAAC,KAA2B;IACxD,IAAM,UAAU,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAEnC,IAAI,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;QACzB,OAAO,KAAK,CAAC,CAAC,sCAAsC;KACvD;SAAM,IAAI,CAAC,UAAU,EAAE;QACpB,OAAO,IAAI,CAAC,CAAC,wBAAwB;KACxC;SAAM,IAAI,UAAU,CAAC,SAAS,IAAI,WAAW,EAAE;QAC5C,OAAO,KAAK,CAAC,CAAC,mDAAmD;KACpE;SAAM,IAAI,UAAU,CAAC,QAAQ,CAAC,MAAM,IAAI,CAAC,EAAE;QACxC,OAAO,IAAI,CAAC,CAAC,0BAA0B;KAC1C;SAAM,IACH,UAAU,CAAC,QAAQ,CAAC,IAAI,CACpB,UAAA,CAAC;QACG,OAAA,CAAC,CAAC,WAAW,IAAI,QAAQ;YACzB,CAAC,CAAC,WAAW,IAAI,OAAO;YACxB,CAAC,CAAC,WAAW,IAAI,SAAS;YAC1B,CAAC,CAAC,CAAC,WAAW,IAAI,MAAM,IAAI,CAAC,CAAC,IAAI,CAAC;IAHnC,CAGmC,CAC1C,EACH;QACE,OAAO,KAAK,CAAC,CAAC,2CAA2C;KAC5D;SAAM;QACH,OAAO,UAAU,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,WAAW,IAAI,IAAI,EAArB,CAAqB,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC,wEAAwE;KACtJ;AACL,CAAC;AAxBD,4CAwBC","sourcesContent":["import type { ContentModelDocument } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n * A fast way to check if content model is empty\n */\nexport function isModelEmptyFast(model: ContentModelDocument): boolean {\n const firstBlock = model.blocks[0];\n\n if (model.blocks.length > 1) {\n return false; // Multiple blocks, treat as not empty\n } else if (!firstBlock) {\n return true; // No block, it is empty\n } else if (firstBlock.blockType != 'Paragraph') {\n return false; // First block is not paragraph, treat as not empty\n } else if (firstBlock.segments.length == 0) {\n return true; // No segment, it is empty\n } else if (\n firstBlock.segments.some(\n x =>\n x.segmentType == 'Entity' ||\n x.segmentType == 'Image' ||\n x.segmentType == 'General' ||\n (x.segmentType == 'Text' && x.text)\n )\n ) {\n return false; // Has meaningful segments, it is not empty\n } else {\n return firstBlock.segments.filter(x => x.segmentType == 'Br').length <= 1; // If there are more than one BR, it is not empty, otherwise it is empty\n }\n}\n"]}
|
|
@@ -29,8 +29,10 @@ export declare class AutoFormatPlugin implements EditorPlugin {
|
|
|
29
29
|
private editor;
|
|
30
30
|
/**
|
|
31
31
|
* @param options An optional parameter that takes in an object of type AutoFormatOptions, which includes the following properties:
|
|
32
|
-
* - autoBullet: A boolean that enables or disables automatic bullet list formatting. Defaults to
|
|
33
|
-
* - autoNumbering: A boolean that enables or disables automatic numbering formatting. Defaults to
|
|
32
|
+
* - autoBullet: A boolean that enables or disables automatic bullet list formatting. Defaults to false.
|
|
33
|
+
* - autoNumbering: A boolean that enables or disables automatic numbering formatting. Defaults to false.
|
|
34
|
+
* - autoLink: A boolean that enables or disables automatic hyperlink creation when pasting or typing content. Defaults to false.
|
|
35
|
+
* - autoUnlink: A boolean that enables or disables automatic hyperlink removal when pressing backspace. Defaults to false.
|
|
34
36
|
*/
|
|
35
37
|
constructor(options?: AutoFormatOptions);
|
|
36
38
|
/**
|
|
@@ -57,6 +59,7 @@ export declare class AutoFormatPlugin implements EditorPlugin {
|
|
|
57
59
|
* @param event The event to handle:
|
|
58
60
|
*/
|
|
59
61
|
onPluginEvent(event: PluginEvent): void;
|
|
62
|
+
private handleEditorInputEvent;
|
|
60
63
|
private handleKeyDownEvent;
|
|
61
64
|
private handleContentChangedEvent;
|
|
62
65
|
}
|
|
@@ -6,10 +6,10 @@ define(["require", "exports", "./link/createLink", "./link/createLinkAfterSpace"
|
|
|
6
6
|
* @internal
|
|
7
7
|
*/
|
|
8
8
|
var DefaultOptions = {
|
|
9
|
-
autoBullet:
|
|
10
|
-
autoNumbering:
|
|
9
|
+
autoBullet: false,
|
|
10
|
+
autoNumbering: false,
|
|
11
11
|
autoUnlink: false,
|
|
12
|
-
autoLink:
|
|
12
|
+
autoLink: false,
|
|
13
13
|
};
|
|
14
14
|
/**
|
|
15
15
|
* Auto Format plugin handles auto formatting, such as transforming * characters into a bullet list.
|
|
@@ -18,8 +18,10 @@ define(["require", "exports", "./link/createLink", "./link/createLinkAfterSpace"
|
|
|
18
18
|
var AutoFormatPlugin = /** @class */ (function () {
|
|
19
19
|
/**
|
|
20
20
|
* @param options An optional parameter that takes in an object of type AutoFormatOptions, which includes the following properties:
|
|
21
|
-
* - autoBullet: A boolean that enables or disables automatic bullet list formatting. Defaults to
|
|
22
|
-
* - autoNumbering: A boolean that enables or disables automatic numbering formatting. Defaults to
|
|
21
|
+
* - autoBullet: A boolean that enables or disables automatic bullet list formatting. Defaults to false.
|
|
22
|
+
* - autoNumbering: A boolean that enables or disables automatic numbering formatting. Defaults to false.
|
|
23
|
+
* - autoLink: A boolean that enables or disables automatic hyperlink creation when pasting or typing content. Defaults to false.
|
|
24
|
+
* - autoUnlink: A boolean that enables or disables automatic hyperlink removal when pressing backspace. Defaults to false.
|
|
23
25
|
*/
|
|
24
26
|
function AutoFormatPlugin(options) {
|
|
25
27
|
if (options === void 0) { options = DefaultOptions; }
|
|
@@ -58,6 +60,9 @@ define(["require", "exports", "./link/createLink", "./link/createLinkAfterSpace"
|
|
|
58
60
|
AutoFormatPlugin.prototype.onPluginEvent = function (event) {
|
|
59
61
|
if (this.editor) {
|
|
60
62
|
switch (event.eventType) {
|
|
63
|
+
case 'input':
|
|
64
|
+
this.handleEditorInputEvent(this.editor, event);
|
|
65
|
+
break;
|
|
61
66
|
case 'keyDown':
|
|
62
67
|
this.handleKeyDownEvent(this.editor, event);
|
|
63
68
|
break;
|
|
@@ -67,19 +72,26 @@ define(["require", "exports", "./link/createLink", "./link/createLinkAfterSpace"
|
|
|
67
72
|
}
|
|
68
73
|
}
|
|
69
74
|
};
|
|
70
|
-
AutoFormatPlugin.prototype.
|
|
75
|
+
AutoFormatPlugin.prototype.handleEditorInputEvent = function (editor, event) {
|
|
71
76
|
var rawEvent = event.rawEvent;
|
|
72
|
-
if (
|
|
73
|
-
|
|
74
|
-
switch (rawEvent.key) {
|
|
77
|
+
if (rawEvent.inputType === 'insertText') {
|
|
78
|
+
switch (rawEvent.data) {
|
|
75
79
|
case ' ':
|
|
76
|
-
|
|
80
|
+
var _a = this.options, autoBullet = _a.autoBullet, autoNumbering = _a.autoNumbering, autoLink = _a.autoLink;
|
|
81
|
+
(0, keyboardListTrigger_1.keyboardListTrigger)(editor, autoBullet, autoNumbering);
|
|
77
82
|
if (autoLink) {
|
|
78
83
|
(0, createLinkAfterSpace_1.createLinkAfterSpace)(editor);
|
|
79
84
|
}
|
|
80
85
|
break;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
AutoFormatPlugin.prototype.handleKeyDownEvent = function (editor, event) {
|
|
90
|
+
var rawEvent = event.rawEvent;
|
|
91
|
+
if (!rawEvent.defaultPrevented && !event.handledByEditFeature) {
|
|
92
|
+
switch (rawEvent.key) {
|
|
81
93
|
case 'Backspace':
|
|
82
|
-
if (autoUnlink) {
|
|
94
|
+
if (this.options.autoUnlink) {
|
|
83
95
|
(0, unlink_1.unlink)(editor, rawEvent);
|
|
84
96
|
}
|
|
85
97
|
break;
|