roosterjs-content-model-plugins 9.18.0 → 9.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/autoFormat/AutoFormatPlugin.d.ts +1 -0
- package/lib/autoFormat/AutoFormatPlugin.js +19 -6
- package/lib/autoFormat/AutoFormatPlugin.js.map +1 -1
- package/lib/autoFormat/interface/AutoFormatOptions.d.ts +4 -0
- package/lib/autoFormat/interface/AutoFormatOptions.js.map +1 -1
- package/lib/autoFormat/list/keyboardListTrigger.d.ts +1 -1
- package/lib/autoFormat/list/keyboardListTrigger.js +4 -4
- package/lib/autoFormat/list/keyboardListTrigger.js.map +1 -1
- package/lib/edit/inputSteps/handleEnterOnList.js +6 -6
- package/lib/edit/inputSteps/handleEnterOnList.js.map +1 -1
- package/lib/imageEdit/ImageEditPlugin.d.ts +3 -0
- package/lib/imageEdit/ImageEditPlugin.js +29 -3
- package/lib/imageEdit/ImageEditPlugin.js.map +1 -1
- package/lib/tableEdit/editors/features/CellResizer.d.ts +1 -0
- package/lib/tableEdit/editors/features/CellResizer.js +14 -1
- package/lib/tableEdit/editors/features/CellResizer.js.map +1 -1
- package/lib-amd/autoFormat/AutoFormatPlugin.d.ts +1 -0
- package/lib-amd/autoFormat/AutoFormatPlugin.js +19 -6
- package/lib-amd/autoFormat/AutoFormatPlugin.js.map +1 -1
- package/lib-amd/autoFormat/interface/AutoFormatOptions.d.ts +4 -0
- package/lib-amd/autoFormat/interface/AutoFormatOptions.js.map +1 -1
- package/lib-amd/autoFormat/list/keyboardListTrigger.d.ts +1 -1
- package/lib-amd/autoFormat/list/keyboardListTrigger.js +4 -4
- package/lib-amd/autoFormat/list/keyboardListTrigger.js.map +1 -1
- package/lib-amd/edit/inputSteps/handleEnterOnList.js +6 -6
- package/lib-amd/edit/inputSteps/handleEnterOnList.js.map +1 -1
- package/lib-amd/imageEdit/ImageEditPlugin.d.ts +3 -0
- package/lib-amd/imageEdit/ImageEditPlugin.js +29 -3
- package/lib-amd/imageEdit/ImageEditPlugin.js.map +1 -1
- package/lib-amd/tableEdit/editors/features/CellResizer.d.ts +1 -0
- package/lib-amd/tableEdit/editors/features/CellResizer.js +14 -1
- package/lib-amd/tableEdit/editors/features/CellResizer.js.map +1 -1
- package/lib-mjs/autoFormat/AutoFormatPlugin.d.ts +1 -0
- package/lib-mjs/autoFormat/AutoFormatPlugin.js +19 -6
- package/lib-mjs/autoFormat/AutoFormatPlugin.js.map +1 -1
- package/lib-mjs/autoFormat/interface/AutoFormatOptions.d.ts +4 -0
- package/lib-mjs/autoFormat/interface/AutoFormatOptions.js.map +1 -1
- package/lib-mjs/autoFormat/list/keyboardListTrigger.d.ts +1 -1
- package/lib-mjs/autoFormat/list/keyboardListTrigger.js +4 -4
- package/lib-mjs/autoFormat/list/keyboardListTrigger.js.map +1 -1
- package/lib-mjs/edit/inputSteps/handleEnterOnList.js +6 -6
- package/lib-mjs/edit/inputSteps/handleEnterOnList.js.map +1 -1
- package/lib-mjs/imageEdit/ImageEditPlugin.d.ts +3 -0
- package/lib-mjs/imageEdit/ImageEditPlugin.js +29 -3
- package/lib-mjs/imageEdit/ImageEditPlugin.js.map +1 -1
- package/lib-mjs/tableEdit/editors/features/CellResizer.d.ts +1 -0
- package/lib-mjs/tableEdit/editors/features/CellResizer.js +15 -2
- package/lib-mjs/tableEdit/editors/features/CellResizer.js.map +1 -1
- package/package.json +5 -5
|
@@ -11,6 +11,7 @@ export declare class AutoFormatPlugin implements EditorPlugin {
|
|
|
11
11
|
* @param options An optional parameter that takes in an object of type AutoFormatOptions, which includes the following properties:
|
|
12
12
|
* - autoBullet: A boolean that enables or disables automatic bullet list formatting. Defaults to false.
|
|
13
13
|
* - autoNumbering: A boolean that enables or disables automatic numbering formatting. Defaults to false.
|
|
14
|
+
* - removeListMargins: A boolean to remove list margins when it is automatically triggered. Defaults to false.
|
|
14
15
|
* - autoHyphen: A boolean that enables or disables automatic hyphen transformation. Defaults to false.
|
|
15
16
|
* - autoFraction: A boolean that enables or disables automatic fraction transformation. Defaults to false.
|
|
16
17
|
* - autoOrdinals: A boolean that enables or disables automatic ordinal number transformation. Defaults to false.
|
|
@@ -20,6 +20,7 @@ var DefaultOptions = {
|
|
|
20
20
|
autoHyphen: false,
|
|
21
21
|
autoFraction: false,
|
|
22
22
|
autoOrdinals: false,
|
|
23
|
+
removeListMargins: false,
|
|
23
24
|
};
|
|
24
25
|
/**
|
|
25
26
|
* Auto Format plugin handles auto formatting, such as transforming * characters into a bullet list.
|
|
@@ -30,6 +31,7 @@ var AutoFormatPlugin = /** @class */ (function () {
|
|
|
30
31
|
* @param options An optional parameter that takes in an object of type AutoFormatOptions, which includes the following properties:
|
|
31
32
|
* - autoBullet: A boolean that enables or disables automatic bullet list formatting. Defaults to false.
|
|
32
33
|
* - autoNumbering: A boolean that enables or disables automatic numbering formatting. Defaults to false.
|
|
34
|
+
* - removeListMargins: A boolean to remove list margins when it is automatically triggered. Defaults to false.
|
|
33
35
|
* - autoHyphen: A boolean that enables or disables automatic hyphen transformation. Defaults to false.
|
|
34
36
|
* - autoFraction: A boolean that enables or disables automatic fraction transformation. Defaults to false.
|
|
35
37
|
* - autoOrdinals: A boolean that enables or disables automatic ordinal number transformation. Defaults to false.
|
|
@@ -100,24 +102,29 @@ var AutoFormatPlugin = /** @class */ (function () {
|
|
|
100
102
|
var formatOptions_1 = {
|
|
101
103
|
changeSource: '',
|
|
102
104
|
apiName: '',
|
|
105
|
+
getChangeData: undefined,
|
|
103
106
|
};
|
|
104
107
|
(0, roosterjs_content_model_api_1.formatTextSegmentBeforeSelectionMarker)(editor, function (model, previousSegment, paragraph, _markerFormat, context) {
|
|
105
|
-
var _a
|
|
108
|
+
var _a;
|
|
109
|
+
var _b = _this.options, autoBullet = _b.autoBullet, autoNumbering = _b.autoNumbering, autoLink = _b.autoLink, autoHyphen = _b.autoHyphen, autoFraction = _b.autoFraction, autoOrdinals = _b.autoOrdinals, autoMailto = _b.autoMailto, autoTel = _b.autoTel, removeListMargins = _b.removeListMargins;
|
|
106
110
|
var shouldHyphen = false;
|
|
107
111
|
var shouldLink = false;
|
|
108
112
|
var shouldList = false;
|
|
109
113
|
var shouldFraction = false;
|
|
110
114
|
var shouldOrdinals = false;
|
|
111
115
|
if (autoBullet || autoNumbering) {
|
|
112
|
-
shouldList = (0, keyboardListTrigger_1.keyboardListTrigger)(model, paragraph, context, autoBullet, autoNumbering);
|
|
116
|
+
shouldList = (0, keyboardListTrigger_1.keyboardListTrigger)(model, paragraph, context, autoBullet, autoNumbering, removeListMargins);
|
|
113
117
|
}
|
|
114
118
|
if (autoLink || autoTel || autoMailto) {
|
|
115
|
-
|
|
119
|
+
var linkSegment = (0, roosterjs_content_model_api_1.promoteLink)(previousSegment, paragraph, {
|
|
116
120
|
autoLink: autoLink,
|
|
117
121
|
autoTel: autoTel,
|
|
118
122
|
autoMailto: autoMailto,
|
|
119
123
|
});
|
|
120
|
-
if (
|
|
124
|
+
if (linkSegment) {
|
|
125
|
+
var anchor_1 = createAnchor(((_a = linkSegment.link) === null || _a === void 0 ? void 0 : _a.format.href) || '', linkSegment.text);
|
|
126
|
+
formatOptions_1.getChangeData = function () { return anchor_1; };
|
|
127
|
+
shouldLink = true;
|
|
121
128
|
context.canUndoByBackspace = true;
|
|
122
129
|
}
|
|
123
130
|
}
|
|
@@ -155,10 +162,10 @@ var AutoFormatPlugin = /** @class */ (function () {
|
|
|
155
162
|
case 'Tab':
|
|
156
163
|
if (!rawEvent.shiftKey) {
|
|
157
164
|
(0, roosterjs_content_model_api_1.formatTextSegmentBeforeSelectionMarker)(editor, function (model, _previousSegment, paragraph, _markerFormat, context) {
|
|
158
|
-
var _a = _this.options, autoBullet = _a.autoBullet, autoNumbering = _a.autoNumbering;
|
|
165
|
+
var _a = _this.options, autoBullet = _a.autoBullet, autoNumbering = _a.autoNumbering, removeListMargins = _a.removeListMargins;
|
|
159
166
|
var shouldList = false;
|
|
160
167
|
if (autoBullet || autoNumbering) {
|
|
161
|
-
shouldList = (0, keyboardListTrigger_1.keyboardListTrigger)(model, paragraph, context, autoBullet, autoNumbering);
|
|
168
|
+
shouldList = (0, keyboardListTrigger_1.keyboardListTrigger)(model, paragraph, context, autoBullet, autoNumbering, removeListMargins);
|
|
162
169
|
context.canUndoByBackspace = shouldList;
|
|
163
170
|
}
|
|
164
171
|
if (shouldList) {
|
|
@@ -196,4 +203,10 @@ var getChangeSource = function (shouldList, shouldHyphen, shouldLink) {
|
|
|
196
203
|
? roosterjs_content_model_dom_1.ChangeSource.AutoLink
|
|
197
204
|
: '';
|
|
198
205
|
};
|
|
206
|
+
var createAnchor = function (url, text) {
|
|
207
|
+
var anchor = document.createElement('a');
|
|
208
|
+
anchor.href = url;
|
|
209
|
+
anchor.textContent = text;
|
|
210
|
+
return anchor;
|
|
211
|
+
};
|
|
199
212
|
//# sourceMappingURL=AutoFormatPlugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AutoFormatPlugin.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/AutoFormatPlugin.ts"],"names":[],"mappings":";;;AAAA,2EAA2D;AAC3D,gDAA+C;AAC/C,2EAAkG;AAClG,kEAAiE;AACjE,iEAAgE;AAChE,4DAA2D;AAC3D,iEAAgE;AAChE,wCAAuC;AAYvC;;GAEG;AACH,IAAM,cAAc,GAA+B;IAC/C,UAAU,EAAE,KAAK;IACjB,aAAa,EAAE,KAAK;IACpB,UAAU,EAAE,KAAK;IACjB,QAAQ,EAAE,KAAK;IACf,UAAU,EAAE,KAAK;IACjB,YAAY,EAAE,KAAK;IACnB,YAAY,EAAE,KAAK;CACtB,CAAC;AAEF;;;GAGG;AACH;IAEI;;;;;;;;;;;OAWG;IACH,0BAAoB,OAA2C;QAA3C,wBAAA,EAAA,wBAA2C;QAA3C,YAAO,GAAP,OAAO,CAAoC;QAbvD,WAAM,GAAmB,IAAI,CAAC;IAa4B,CAAC;IAEnE;;OAEG;IACH,kC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AAY,CAAC,UAAU;4BACrC,OAAO,EAAE,gBAAgB;yBAC5B,CACJ,CAAC;qBACL;aACR;SACJ;IACL,CAAC;IAEO,oDAAyB,GAAjC,UAAkC,MAAe,EAAE,KAA0B;QACnE,IAAA,KAAoC,IAAI,CAAC,OAAO,EAA9C,QAAQ,cAAA,EAAE,OAAO,aAAA,EAAE,UAAU,gBAAiB,CAAC;QACvD,IAAI,KAAK,CAAC,MAAM,IAAI,OAAO,IAAI,CAAC,QAAQ,IAAI,OAAO,IAAI,UAAU,CAAC,EAAE;YAChE,IAAA,uBAAU,EAAC,MAAM,EAAE;gBACf,QAAQ,UAAA;gBACR,OAAO,SAAA;gBACP,UAAU,YAAA;aACb,CAAC,CAAC;SACN;IACL,CAAC;IACL,uBAAC;AAAD,CAAC,AAtND,IAsNC;AAtNY,4CAAgB;AAwN7B,IAAM,UAAU,GAAG,UAAC,UAAmB,EAAE,YAAqB;IAC1D,OAAO,UAAU,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC;AAC5E,CAAC,CAAC;AAEF,IAAM,eAAe,GAAG,UAAC,UAAmB,EAAE,YAAqB,EAAE,UAAmB;IACpF,OAAO,UAAU,IAAI,YAAY;QAC7B,CAAC,CAAC,0CAAY,CAAC,UAAU;QACzB,CAAC,CAAC,UAAU;YACZ,CAAC,CAAC,0CAAY,CAAC,QAAQ;YACvB,CAAC,CAAC,EAAE,CAAC;AACb,CAAC,CAAC","sourcesContent":["import { ChangeSource } from 'roosterjs-content-model-dom';\nimport { createLink } from './link/createLink';\nimport { formatTextSegmentBeforeSelectionMarker, promoteLink } from 'roosterjs-content-model-api';\nimport { keyboardListTrigger } from './list/keyboardListTrigger';\nimport { transformFraction } from './numbers/transformFraction';\nimport { transformHyphen } from './hyphen/transformHyphen';\nimport { transformOrdinals } from './numbers/transformOrdinals';\nimport { unlink } from './link/unlink';\nimport type { AutoFormatOptions } from './interface/AutoFormatOptions';\nimport type {\n ContentChangedEvent,\n EditorInputEvent,\n EditorPlugin,\n FormatContentModelOptions,\n IEditor,\n KeyDownEvent,\n PluginEvent,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nconst DefaultOptions: Partial<AutoFormatOptions> = {\n autoBullet: false,\n autoNumbering: false,\n autoUnlink: false,\n autoLink: false,\n autoHyphen: false,\n autoFraction: false,\n autoOrdinals: false,\n};\n\n/**\n * Auto Format plugin handles auto formatting, such as transforming * characters into a bullet list.\n * It can be customized with options to enable or disable auto list features.\n */\nexport class AutoFormatPlugin implements EditorPlugin {\n private editor: IEditor | null = null;\n /**\n * @param options An optional parameter that takes in an object of type AutoFormatOptions, which includes the following properties:\n * - autoBullet: A boolean that enables or disables automatic bullet list formatting. Defaults to false.\n * - autoNumbering: A boolean that enables or disables automatic numbering formatting. Defaults to false.\n * - autoHyphen: A boolean that enables or disables automatic hyphen transformation. Defaults to false.\n * - autoFraction: A boolean that enables or disables automatic fraction transformation. Defaults to false.\n * - autoOrdinals: A boolean that enables or disables automatic ordinal number transformation. Defaults to false.\n * - autoLink: A boolean that enables or disables automatic hyperlink url address creation when pasting or typing content. Defaults to false.\n * - autoUnlink: A boolean that enables or disables automatic hyperlink removal when pressing backspace. Defaults to false.\n * - autoTel: A boolean that enables or disables automatic hyperlink telephone numbers transformation. Defaults to false.\n * - autoMailto: A boolean that enables or disables automatic hyperlink email address transformation. Defaults to false.\n */\n constructor(private options: AutoFormatOptions = DefaultOptions) {}\n\n /**\n * Get name of this plugin\n */\n getName() {\n return 'AutoFormat';\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 }\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 * 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) {\n switch (event.eventType) {\n case 'input':\n this.handleEditorInputEvent(this.editor, event);\n break;\n case 'keyDown':\n this.handleKeyDownEvent(this.editor, event);\n break;\n case 'contentChanged':\n this.handleContentChangedEvent(this.editor, event);\n break;\n }\n }\n }\n\n private handleEditorInputEvent(editor: IEditor, event: EditorInputEvent) {\n const rawEvent = event.rawEvent;\n const selection = editor.getDOMSelection();\n if (\n rawEvent.inputType === 'insertText' &&\n selection &&\n selection.type === 'range' &&\n selection.range.collapsed\n ) {\n switch (rawEvent.data) {\n case ' ':\n const formatOptions: FormatContentModelOptions = {\n changeSource: '',\n apiName: '',\n };\n formatTextSegmentBeforeSelectionMarker(\n editor,\n (model, previousSegment, paragraph, _markerFormat, context) => {\n const {\n autoBullet,\n autoNumbering,\n autoLink,\n autoHyphen,\n autoFraction,\n autoOrdinals,\n autoMailto,\n autoTel,\n } = this.options;\n let shouldHyphen = false;\n let shouldLink = false;\n let shouldList = false;\n let shouldFraction = false;\n let shouldOrdinals = false;\n\n if (autoBullet || autoNumbering) {\n shouldList = keyboardListTrigger(\n model,\n paragraph,\n context,\n autoBullet,\n autoNumbering\n );\n }\n\n if (autoLink || autoTel || autoMailto) {\n shouldLink = !!promoteLink(previousSegment, paragraph, {\n autoLink,\n autoTel,\n autoMailto,\n });\n\n if (shouldLink) {\n context.canUndoByBackspace = true;\n }\n }\n\n if (autoHyphen) {\n shouldHyphen = transformHyphen(previousSegment, paragraph, context);\n }\n\n if (autoFraction) {\n shouldFraction = transformFraction(\n previousSegment,\n paragraph,\n context\n );\n }\n\n if (autoOrdinals) {\n shouldOrdinals = transformOrdinals(\n previousSegment,\n paragraph,\n context\n );\n }\n\n formatOptions.apiName = getApiName(shouldList, shouldHyphen);\n formatOptions.changeSource = getChangeSource(\n shouldList,\n shouldHyphen,\n shouldLink\n );\n\n return (\n shouldList ||\n shouldHyphen ||\n shouldLink ||\n shouldFraction ||\n shouldOrdinals\n );\n },\n formatOptions\n );\n\n break;\n }\n }\n }\n\n private handleKeyDownEvent(editor: IEditor, event: KeyDownEvent) {\n const rawEvent = event.rawEvent;\n if (!rawEvent.defaultPrevented && !event.handledByEditFeature) {\n switch (rawEvent.key) {\n case 'Backspace':\n if (this.options.autoUnlink) {\n unlink(editor, rawEvent);\n }\n break;\n case 'Tab':\n if (!rawEvent.shiftKey) {\n formatTextSegmentBeforeSelectionMarker(\n editor,\n (model, _previousSegment, paragraph, _markerFormat, context) => {\n const { autoBullet, autoNumbering } = this.options;\n let shouldList = false;\n if (autoBullet || autoNumbering) {\n shouldList = keyboardListTrigger(\n model,\n paragraph,\n context,\n autoBullet,\n autoNumbering\n );\n context.canUndoByBackspace = shouldList;\n }\n if (shouldList) {\n event.rawEvent.preventDefault();\n }\n return shouldList;\n },\n {\n changeSource: ChangeSource.AutoFormat,\n apiName: 'autoToggleList',\n }\n );\n }\n }\n }\n }\n\n private handleContentChangedEvent(editor: IEditor, event: ContentChangedEvent) {\n const { autoLink, autoTel, autoMailto } = this.options;\n if (event.source == 'Paste' && (autoLink || autoTel || autoMailto)) {\n createLink(editor, {\n autoLink,\n autoTel,\n autoMailto,\n });\n }\n }\n}\n\nconst getApiName = (shouldList: boolean, shouldHyphen: boolean) => {\n return shouldList ? 'autoToggleList' : shouldHyphen ? 'autoHyphen' : '';\n};\n\nconst getChangeSource = (shouldList: boolean, shouldHyphen: boolean, shouldLink: boolean) => {\n return shouldList || shouldHyphen\n ? ChangeSource.AutoFormat\n : shouldLink\n ? ChangeSource.AutoLink\n : '';\n};\n"]}
|
|
1
|
+
{"version":3,"file":"AutoFormatPlugin.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/AutoFormatPlugin.ts"],"names":[],"mappings":";;;AAAA,2EA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U,EAAC,MAAM,EAAE;gBACf,QAAQ,UAAA;gBACR,OAAO,SAAA;gBACP,UAAU,YAAA;aACb,CAAC,CAAC;SACN;IACL,CAAC;IACL,uBAAC;AAAD,CAAC,AAtOD,IAsOC;AAtOY,4CAAgB;AAwO7B,IAAM,UAAU,GAAG,UAAC,UAAmB,EAAE,YAAqB;IAC1D,OAAO,UAAU,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC;AAC5E,CAAC,CAAC;AAEF,IAAM,eAAe,GAAG,UAAC,UAAmB,EAAE,YAAqB,EAAE,UAAmB;IACpF,OAAO,UAAU,IAAI,YAAY;QAC7B,CAAC,CAAC,0CAAY,CAAC,UAAU;QACzB,CAAC,CAAC,UAAU;YACZ,CAAC,CAAC,0CAAY,CAAC,QAAQ;YACvB,CAAC,CAAC,EAAE,CAAC;AACb,CAAC,CAAC;AAEF,IAAM,YAAY,GAAG,UAAC,GAAW,EAAE,IAAY;IAC3C,IAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;IAC3C,MAAM,CAAC,IAAI,GAAG,GAAG,CAAC;IAClB,MAAM,CAAC,WAAW,GAAG,IAAI,CAAC;IAC1B,OAAO,MAAM,CAAC;AAClB,CAAC,CAAC","sourcesContent":["import { ChangeSource } from 'roosterjs-content-model-dom';\nimport { createLink } from './link/createLink';\nimport { formatTextSegmentBeforeSelectionMarker, promoteLink } from 'roosterjs-content-model-api';\nimport { keyboardListTrigger } from './list/keyboardListTrigger';\nimport { transformFraction } from './numbers/transformFraction';\nimport { transformHyphen } from './hyphen/transformHyphen';\nimport { transformOrdinals } from './numbers/transformOrdinals';\nimport { unlink } from './link/unlink';\nimport type { AutoFormatOptions } from './interface/AutoFormatOptions';\nimport type {\n ContentChangedEvent,\n EditorInputEvent,\n EditorPlugin,\n FormatContentModelOptions,\n IEditor,\n KeyDownEvent,\n PluginEvent,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nconst DefaultOptions: Partial<AutoFormatOptions> = {\n autoBullet: false,\n autoNumbering: false,\n autoUnlink: false,\n autoLink: false,\n autoHyphen: false,\n autoFraction: false,\n autoOrdinals: false,\n removeListMargins: false,\n};\n\n/**\n * Auto Format plugin handles auto formatting, such as transforming * characters into a bullet list.\n * It can be customized with options to enable or disable auto list features.\n */\nexport class AutoFormatPlugin implements EditorPlugin {\n private editor: IEditor | null = null;\n /**\n * @param options An optional parameter that takes in an object of type AutoFormatOptions, which includes the following properties:\n * - autoBullet: A boolean that enables or disables automatic bullet list formatting. Defaults to false.\n * - autoNumbering: A boolean that enables or disables automatic numbering formatting. Defaults to false.\n * - removeListMargins: A boolean to remove list margins when it is automatically triggered. Defaults to false.\n * - autoHyphen: A boolean that enables or disables automatic hyphen transformation. Defaults to false.\n * - autoFraction: A boolean that enables or disables automatic fraction transformation. Defaults to false.\n * - autoOrdinals: A boolean that enables or disables automatic ordinal number transformation. Defaults to false.\n * - autoLink: A boolean that enables or disables automatic hyperlink url address creation when pasting or typing content. Defaults to false.\n * - autoUnlink: A boolean that enables or disables automatic hyperlink removal when pressing backspace. Defaults to false.\n * - autoTel: A boolean that enables or disables automatic hyperlink telephone numbers transformation. Defaults to false.\n * - autoMailto: A boolean that enables or disables automatic hyperlink email address transformation. Defaults to false.\n */\n constructor(private options: AutoFormatOptions = DefaultOptions) {}\n\n /**\n * Get name of this plugin\n */\n getName() {\n return 'AutoFormat';\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 }\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 * 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) {\n switch (event.eventType) {\n case 'input':\n this.handleEditorInputEvent(this.editor, event);\n break;\n case 'keyDown':\n this.handleKeyDownEvent(this.editor, event);\n break;\n case 'contentChanged':\n this.handleContentChangedEvent(this.editor, event);\n break;\n }\n }\n }\n\n private handleEditorInputEvent(editor: IEditor, event: EditorInputEvent) {\n const rawEvent = event.rawEvent;\n const selection = editor.getDOMSelection();\n if (\n rawEvent.inputType === 'insertText' &&\n selection &&\n selection.type === 'range' &&\n selection.range.collapsed\n ) {\n switch (rawEvent.data) {\n case ' ':\n const formatOptions: FormatContentModelOptions = {\n changeSource: '',\n apiName: '',\n getChangeData: undefined,\n };\n formatTextSegmentBeforeSelectionMarker(\n editor,\n (model, previousSegment, paragraph, _markerFormat, context) => {\n const {\n autoBullet,\n autoNumbering,\n autoLink,\n autoHyphen,\n autoFraction,\n autoOrdinals,\n autoMailto,\n autoTel,\n removeListMargins,\n } = this.options;\n let shouldHyphen = false;\n let shouldLink = false;\n let shouldList = false;\n let shouldFraction = false;\n let shouldOrdinals = false;\n\n if (autoBullet || autoNumbering) {\n shouldList = keyboardListTrigger(\n model,\n paragraph,\n context,\n autoBullet,\n autoNumbering,\n removeListMargins\n );\n }\n\n if (autoLink || autoTel || autoMailto) {\n const linkSegment = promoteLink(previousSegment, paragraph, {\n autoLink,\n autoTel,\n autoMailto,\n });\n\n if (linkSegment) {\n const anchor = createAnchor(\n linkSegment.link?.format.href || '',\n linkSegment.text\n );\n formatOptions.getChangeData = () => anchor;\n\n shouldLink = true;\n context.canUndoByBackspace = true;\n }\n }\n\n if (autoHyphen) {\n shouldHyphen = transformHyphen(previousSegment, paragraph, context);\n }\n\n if (autoFraction) {\n shouldFraction = transformFraction(\n previousSegment,\n paragraph,\n context\n );\n }\n\n if (autoOrdinals) {\n shouldOrdinals = transformOrdinals(\n previousSegment,\n paragraph,\n context\n );\n }\n\n formatOptions.apiName = getApiName(shouldList, shouldHyphen);\n formatOptions.changeSource = getChangeSource(\n shouldList,\n shouldHyphen,\n shouldLink\n );\n\n return (\n shouldList ||\n shouldHyphen ||\n shouldLink ||\n shouldFraction ||\n shouldOrdinals\n );\n },\n formatOptions\n );\n\n break;\n }\n }\n }\n\n private handleKeyDownEvent(editor: IEditor, event: KeyDownEvent) {\n const rawEvent = event.rawEvent;\n if (!rawEvent.defaultPrevented && !event.handledByEditFeature) {\n switch (rawEvent.key) {\n case 'Backspace':\n if (this.options.autoUnlink) {\n unlink(editor, rawEvent);\n }\n break;\n case 'Tab':\n if (!rawEvent.shiftKey) {\n formatTextSegmentBeforeSelectionMarker(\n editor,\n (model, _previousSegment, paragraph, _markerFormat, context) => {\n const {\n autoBullet,\n autoNumbering,\n removeListMargins,\n } = this.options;\n let shouldList = false;\n if (autoBullet || autoNumbering) {\n shouldList = keyboardListTrigger(\n model,\n paragraph,\n context,\n autoBullet,\n autoNumbering,\n removeListMargins\n );\n context.canUndoByBackspace = shouldList;\n }\n if (shouldList) {\n event.rawEvent.preventDefault();\n }\n return shouldList;\n },\n {\n changeSource: ChangeSource.AutoFormat,\n apiName: 'autoToggleList',\n }\n );\n }\n }\n }\n }\n\n private handleContentChangedEvent(editor: IEditor, event: ContentChangedEvent) {\n const { autoLink, autoTel, autoMailto } = this.options;\n if (event.source == 'Paste' && (autoLink || autoTel || autoMailto)) {\n createLink(editor, {\n autoLink,\n autoTel,\n autoMailto,\n });\n }\n }\n}\n\nconst getApiName = (shouldList: boolean, shouldHyphen: boolean) => {\n return shouldList ? 'autoToggleList' : shouldHyphen ? 'autoHyphen' : '';\n};\n\nconst getChangeSource = (shouldList: boolean, shouldHyphen: boolean, shouldLink: boolean) => {\n return shouldList || shouldHyphen\n ? ChangeSource.AutoFormat\n : shouldLink\n ? ChangeSource.AutoLink\n : '';\n};\n\nconst createAnchor = (url: string, text: string) => {\n const anchor = document.createElement('a');\n anchor.href = url;\n anchor.textContent = text;\n return anchor;\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AutoFormatOptions.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/interface/AutoFormatOptions.ts"],"names":[],"mappings":"","sourcesContent":["import type { AutoLinkOptions } from 'roosterjs-content-model-types';\n\n/**\n * Options to customize the Content Model Auto Format Plugin\n */\nexport interface AutoFormatOptions extends AutoLinkOptions {\n /**\n * When true, after type *, ->, -, --, => , —, > and space key a type of bullet list will be triggered.\n */\n autoBullet?: boolean;\n\n /**\n * When true, after type 1, A, a, i, I followed by ., ), - or between () and space key a type of numbering list will be triggered.\n */\n autoNumbering?: boolean;\n\n /**\n * Transform -- into hyphen, if typed between two words\n */\n autoHyphen?: boolean;\n\n /**\n * Transform 1/2, 1/4, 3/4 into fraction character\n */\n autoFraction?: boolean;\n\n /**\n * Transform ordinal numbers into superscript\n */\n autoOrdinals?: boolean;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"AutoFormatOptions.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/interface/AutoFormatOptions.ts"],"names":[],"mappings":"","sourcesContent":["import type { AutoLinkOptions } from 'roosterjs-content-model-types';\n\n/**\n * Options to customize the Content Model Auto Format Plugin\n */\nexport interface AutoFormatOptions extends AutoLinkOptions {\n /**\n * When true, after type *, ->, -, --, => , —, > and space key a type of bullet list will be triggered.\n */\n autoBullet?: boolean;\n\n /**\n * When true, after type 1, A, a, i, I followed by ., ), - or between () and space key a type of numbering list will be triggered.\n */\n autoNumbering?: boolean;\n\n /**\n * Transform -- into hyphen, if typed between two words\n */\n autoHyphen?: boolean;\n\n /**\n * Transform 1/2, 1/4, 3/4 into fraction character\n */\n autoFraction?: boolean;\n\n /**\n * Transform ordinal numbers into superscript\n */\n autoOrdinals?: boolean;\n\n /**\n * Remove the margins of auto triggered list\n */\n removeListMargins?: boolean;\n}\n"]}
|
|
@@ -2,4 +2,4 @@ import type { FormatContentModelContext, ReadonlyContentModelDocument, ShallowMu
|
|
|
2
2
|
/**
|
|
3
3
|
* @internal
|
|
4
4
|
*/
|
|
5
|
-
export declare function keyboardListTrigger(model: ReadonlyContentModelDocument, paragraph: ShallowMutableContentModelParagraph, context: FormatContentModelContext, shouldSearchForBullet?: boolean, shouldSearchForNumbering?: boolean): boolean;
|
|
5
|
+
export declare function keyboardListTrigger(model: ReadonlyContentModelDocument, paragraph: ShallowMutableContentModelParagraph, context: FormatContentModelContext, shouldSearchForBullet?: boolean, shouldSearchForNumbering?: boolean, removeListMargins?: boolean): boolean;
|
|
@@ -8,14 +8,14 @@ var roosterjs_content_model_api_1 = require("roosterjs-content-model-api");
|
|
|
8
8
|
/**
|
|
9
9
|
* @internal
|
|
10
10
|
*/
|
|
11
|
-
function keyboardListTrigger(model, paragraph, context, shouldSearchForBullet, shouldSearchForNumbering) {
|
|
11
|
+
function keyboardListTrigger(model, paragraph, context, shouldSearchForBullet, shouldSearchForNumbering, removeListMargins) {
|
|
12
12
|
if (shouldSearchForBullet === void 0) { shouldSearchForBullet = true; }
|
|
13
13
|
if (shouldSearchForNumbering === void 0) { shouldSearchForNumbering = true; }
|
|
14
14
|
var listStyleType = (0, getListTypeStyle_1.getListTypeStyle)(model, shouldSearchForBullet, shouldSearchForNumbering);
|
|
15
15
|
if (listStyleType) {
|
|
16
16
|
paragraph.segments.splice(0, 1);
|
|
17
17
|
var listType = listStyleType.listType, styleType = listStyleType.styleType, index = listStyleType.index;
|
|
18
|
-
triggerList(model, listType, styleType, index);
|
|
18
|
+
triggerList(model, listType, styleType, index, removeListMargins);
|
|
19
19
|
context.canUndoByBackspace = true;
|
|
20
20
|
setAnnounceData(model, context);
|
|
21
21
|
return true;
|
|
@@ -23,8 +23,8 @@ function keyboardListTrigger(model, paragraph, context, shouldSearchForBullet, s
|
|
|
23
23
|
return false;
|
|
24
24
|
}
|
|
25
25
|
exports.keyboardListTrigger = keyboardListTrigger;
|
|
26
|
-
var triggerList = function (model, listType, styleType, index) {
|
|
27
|
-
(0, roosterjs_content_model_api_1.setListType)(model, listType);
|
|
26
|
+
var triggerList = function (model, listType, styleType, index, removeListMargins) {
|
|
27
|
+
(0, roosterjs_content_model_api_1.setListType)(model, listType, removeListMargins);
|
|
28
28
|
var isOrderedList = listType == 'OL';
|
|
29
29
|
if (index && index > 0 && isOrderedList) {
|
|
30
30
|
(0, roosterjs_content_model_api_1.setModelListStartNumber)(model, index);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyboardListTrigger.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/list/keyboardListTrigger.ts"],"names":[],"mappings":";;;;AAAA,uDAAsD;AACtD,2EAAuF;AACvF,2EAKqC;AAQrC;;GAEG;AACH,SAAgB,mBAAmB,CAC/B,KAAmC,EACnC,SAA8C,EAC9C,OAAkC,EAClC,qBAAqC,EACrC,wBAAwC;
|
|
1
|
+
{"version":3,"file":"keyboardListTrigger.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/list/keyboardListTrigger.ts"],"names":[],"mappings":";;;;AAAA,uDAAsD;AACtD,2EAAuF;AACvF,2EAKqC;AAQrC;;GAEG;AACH,SAAgB,mBAAmB,CAC/B,KAAmC,EACnC,SAA8C,EAC9C,OAAkC,EAClC,qBAAqC,EACrC,wBAAwC,EACxC,iBAA2B;IAF3B,sCAAA,EAAA,4BAAqC;IACrC,yCAAA,EAAA,+BAAwC;IAGxC,IAAM,aAAa,GAAG,IAAA,mCAAgB,EAAC,KAAK,EAAE,qBAAqB,EAAE,wBAAwB,CAAC,CAAC;IAC/F,IAAI,aAAa,EAAE;QACf,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACxB,IAAA,QAAQ,GAAuB,aAAa,SAApC,EAAE,SAAS,GAAY,aAAa,UAAzB,EAAE,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GAAG,IAAA,iDAAmB,8BAAE,KAAK,uBAAK,IAAI,UAAE,CAAC;KAChE;AACL,CAAC","sourcesContent":["import { getListTypeStyle } from './getListTypeStyle';\nimport { getOperationalBlocks, isBlockGroupOfType } from 'roosterjs-content-model-dom';\nimport {\n getListAnnounceData,\n setListType,\n setModelListStartNumber,\n setModelListStyle,\n} from 'roosterjs-content-model-api';\nimport type {\n ContentModelListItem,\n FormatContentModelContext,\n ReadonlyContentModelDocument,\n ShallowMutableContentModelParagraph,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function keyboardListTrigger(\n model: ReadonlyContentModelDocument,\n paragraph: ShallowMutableContentModelParagraph,\n context: FormatContentModelContext,\n shouldSearchForBullet: boolean = true,\n shouldSearchForNumbering: boolean = true,\n removeListMargins?: boolean\n) {\n const listStyleType = getListTypeStyle(model, shouldSearchForBullet, shouldSearchForNumbering);\n if (listStyleType) {\n paragraph.segments.splice(0, 1);\n const { listType, styleType, index } = listStyleType;\n triggerList(model, listType, styleType, index, removeListMargins);\n context.canUndoByBackspace = true;\n setAnnounceData(model, context);\n\n return true;\n }\n return false;\n}\n\nconst triggerList = (\n model: ReadonlyContentModelDocument,\n listType: 'OL' | 'UL',\n styleType: number,\n index?: number,\n removeListMargins?: boolean\n) => {\n setListType(model, listType, removeListMargins);\n const isOrderedList = listType == 'OL';\n if (index && index > 0 && isOrderedList) {\n setModelListStartNumber(model, index);\n }\n setModelListStyle(\n model,\n isOrderedList\n ? {\n orderedStyleType: styleType,\n applyListStyleFromLevel: false,\n }\n : {\n unorderedStyleType: styleType,\n applyListStyleFromLevel: false,\n }\n );\n};\nfunction setAnnounceData(model: ReadonlyContentModelDocument, context: FormatContentModelContext) {\n const [paragraphOrListItems] = getOperationalBlocks<ContentModelListItem>(\n model,\n ['ListItem'],\n [] // Set stop types to be empty so we can find list items even cross the boundary of table, then we can always operation on the list item if any\n );\n\n if (paragraphOrListItems && isBlockGroupOfType(paragraphOrListItems.block, 'ListItem')) {\n const { path, block } = paragraphOrListItems;\n context.announceData = getListAnnounceData([block, ...path]);\n }\n}\n"]}
|
|
@@ -41,8 +41,8 @@ var handleEnterOnList = function (context) {
|
|
|
41
41
|
}
|
|
42
42
|
});
|
|
43
43
|
if (listItem.levels.length == 0) {
|
|
44
|
-
var
|
|
45
|
-
nextBlock.levels[nextBlock.levels.length - 1].format.startNumberOverride =
|
|
44
|
+
var nextBlockIndex = findIndex(listParent.blocks, nextBlock.levels.length);
|
|
45
|
+
nextBlock.levels[nextBlock.levels.length - 1].format.startNumberOverride = nextBlockIndex;
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
}
|
|
@@ -86,16 +86,16 @@ var createNewListLevel = function (listItem) {
|
|
|
86
86
|
return (0, roosterjs_content_model_dom_1.createListLevel)(level.listType, (0, tslib_1.__assign)((0, tslib_1.__assign)({}, level.format), { startNumberOverride: undefined, displayForDummyItem: undefined }), level.dataset);
|
|
87
87
|
});
|
|
88
88
|
};
|
|
89
|
-
var findIndex = function (blocks, levelLength
|
|
89
|
+
var findIndex = function (blocks, levelLength) {
|
|
90
90
|
var counter = 1;
|
|
91
|
-
for (var i =
|
|
91
|
+
for (var i = 0; i < blocks.length; i++) {
|
|
92
92
|
var listItem = blocks[i];
|
|
93
93
|
if ((0, roosterjs_content_model_dom_1.isBlockGroupOfType)(listItem, 'ListItem') &&
|
|
94
94
|
listItem.levels.length === levelLength) {
|
|
95
95
|
counter++;
|
|
96
96
|
}
|
|
97
|
-
else if (
|
|
98
|
-
listItem.levels.length == 0)
|
|
97
|
+
else if ((0, roosterjs_content_model_dom_1.isBlockGroupOfType)(listItem, 'ListItem') &&
|
|
98
|
+
listItem.levels.length == 0) {
|
|
99
99
|
return counter;
|
|
100
100
|
}
|
|
101
101
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleEnterOnList.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/edit/inputSteps/handleEnterOnList.ts"],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,GAAG,YAAY,CAAC;KACxC;IAED,OAAO,WAAW,CAAC;AACvB,CAAC,CAAC;AAEF,IAAM,kBAAkB,GAAG,UAAC,QAAsC;IAC9D,OAAO,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,UAAA,KAAK;QAC5B,OAAO,IAAA,6CAAe,EAClB,KAAK,CAAC,QAAQ,kDAEP,KAAK,CAAC,MAAM,KACf,mBAAmB,EAAE,SAAS,EAC9B,mBAAmB,EAAE,SAAS,KAElC,KAAK,CAAC,OAAO,CAChB,CAAC;IACN,CAAC,CAAC,CAAC;AACP,CAAC,CAAC;AAEF,IAAM,SAAS,GAAG,UACd,MAA4C,EAC5C,WAAmB,EACnB,KAAa;IAEb,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,KAAK,IAAI,CAAC,GAAG,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QAC7B,IAAM,QAAQ,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QAC3B,IACI,IAAA,gDAAkB,EAAuB,QAAQ,EAAE,UAAU,CAAC;YAC9D,QAAQ,CAAC,MAAM,CAAC,MAAM,KAAK,WAAW,EACxC;YACE,OAAO,EAAE,CAAC;SACb;aAAM,IACH,CAAC,CACG,IAAA,gDAAkB,EAAuB,QAAQ,EAAE,UAAU,CAAC;YAC9D,QAAQ,CAAC,MAAM,CAAC,MAAM,IAAI,CAAC,CAC9B,EACH;YACE,OAAO,OAAO,CAAC;SAClB;KACJ;IAED,OAAO,OAAO,CAAC;AACnB,CAAC,CAAC","sourcesContent":["import { getListAnnounceData } from 'roosterjs-content-model-api';\nimport { splitParagraph } from '../utils/splitParagraph';\nimport {\n createListItem,\n createListLevel,\n getClosestAncestorBlockGroupIndex,\n isBlockGroupOfType,\n mutateBlock,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelListItem,\n DeleteSelectionStep,\n ReadonlyContentModelBlock,\n ReadonlyContentModelBlockGroup,\n ReadonlyContentModelListItem,\n ShallowMutableContentModelListItem,\n ValidDeleteSelectionContext,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport const handleEnterOnList: DeleteSelectionStep = context => {\n const { deleteResult, insertPoint } = context;\n\n if (deleteResult == 'notDeleted' || deleteResult == 'nothingToDelete') {\n const { path } = insertPoint;\n const index = getClosestAncestorBlockGroupIndex(\n path,\n ['ListItem'],\n ['TableCell', 'FormatContainer']\n );\n\n const readonlyListItem = path[index];\n const listParent = path[index + 1];\n\n if (readonlyListItem?.blockGroupType === 'ListItem' && listParent) {\n let listItem = mutateBlock(readonlyListItem);\n\n if (isEmptyListItem(listItem)) {\n listItem.levels.pop();\n } else {\n listItem = createNewListItem(context, listItem, listParent);\n\n if (context.formatContext) {\n context.formatContext.announceData = getListAnnounceData([\n listItem,\n ...path.slice(index + 1),\n ]);\n }\n }\n\n const listIndex = listParent.blocks.indexOf(listItem);\n const nextBlock = listParent.blocks[listIndex + 1];\n\n if (nextBlock) {\n if (\n isBlockGroupOfType<ContentModelListItem>(nextBlock, 'ListItem') &&\n nextBlock.levels[0]\n ) {\n nextBlock.levels.forEach(level => {\n // Remove startNumberOverride so that next list item can join current list, unless it is 1.\n // List start with 1 means it should be an explicit new list and should never join another list before it\n if (level.format.startNumberOverride !== 1) {\n level.format.startNumberOverride = undefined;\n }\n });\n\n if (listItem.levels.length == 0) {\n const index = findIndex(\n listParent.blocks,\n nextBlock.levels.length,\n listIndex\n );\n nextBlock.levels[\n nextBlock.levels.length - 1\n ].format.startNumberOverride = index;\n }\n }\n }\n\n context.deleteResult = 'range';\n }\n }\n};\n\nconst isEmptyListItem = (listItem: ReadonlyContentModelListItem) => {\n return listItem.blocks.length === 1 && isEmptyParagraph(listItem.blocks[0]);\n};\n\nconst isEmptyParagraph = (block: ReadonlyContentModelBlock) => {\n return (\n block.blockType === 'Paragraph' &&\n block.segments.length === 2 &&\n block.segments[0].segmentType === 'SelectionMarker' &&\n block.segments[1].segmentType === 'Br'\n );\n};\n\nconst createNewListItem = (\n context: ValidDeleteSelectionContext,\n listItem: ReadonlyContentModelListItem,\n listParent: ReadonlyContentModelBlockGroup\n) => {\n const { insertPoint } = context;\n const listIndex = listParent.blocks.indexOf(listItem);\n const currentPara = insertPoint.paragraph;\n const paraIndex = listItem.blocks.indexOf(currentPara);\n const newParagraph = splitParagraph(insertPoint);\n\n const levels = createNewListLevel(listItem);\n const newListItem: ShallowMutableContentModelListItem = createListItem(\n levels,\n listItem.formatHolder.format\n );\n\n newListItem.blocks.push(newParagraph);\n\n const remainingBlockCount = listItem.blocks.length - paraIndex - 1;\n\n if (paraIndex >= 0 && remainingBlockCount > 0) {\n newListItem.blocks.push(\n ...mutateBlock(listItem).blocks.splice(paraIndex + 1, remainingBlockCount)\n );\n }\n\n insertPoint.paragraph = newParagraph;\n mutateBlock(listParent).blocks.splice(listIndex + 1, 0, newListItem);\n\n if (context.lastParagraph == currentPara) {\n context.lastParagraph = newParagraph;\n }\n\n return newListItem;\n};\n\nconst createNewListLevel = (listItem: ReadonlyContentModelListItem) => {\n return listItem.levels.map(level => {\n return createListLevel(\n level.listType,\n {\n ...level.format,\n startNumberOverride: undefined,\n displayForDummyItem: undefined, // When ENTER, we should create a new regular list item, so force its dummy item display to undefined\n },\n level.dataset\n );\n });\n};\n\nconst findIndex = (\n blocks: readonly ReadonlyContentModelBlock[],\n levelLength: number,\n index: number\n) => {\n let counter = 1;\n for (let i = index; i > -1; i--) {\n const listItem = blocks[i];\n if (\n isBlockGroupOfType<ContentModelListItem>(listItem, 'ListItem') &&\n listItem.levels.length === levelLength\n ) {\n counter++;\n } else if (\n !(\n isBlockGroupOfType<ContentModelListItem>(listItem, 'ListItem') &&\n listItem.levels.length == 0\n )\n ) {\n return counter;\n }\n }\n\n return counter;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"handleEnterOnList.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/edit/inputSteps/handleEnterOnList.ts"],"names":[],"mappings":";;;;AA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ED,OAAO,WAAW,CAAC;AACvB,CAAC,CAAC;AAEF,IAAM,kBAAkB,GAAG,UAAC,QAAsC;IAC9D,OAAO,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,UAAA,KAAK;QAC5B,OAAO,IAAA,6CAAe,EAClB,KAAK,CAAC,QAAQ,kDAEP,KAAK,CAAC,MAAM,KACf,mBAAmB,EAAE,SAAS,EAC9B,mBAAmB,EAAE,SAAS,KAElC,KAAK,CAAC,OAAO,CAChB,CAAC;IACN,CAAC,CAAC,CAAC;AACP,CAAC,CAAC;AAEF,IAAM,SAAS,GAAG,UAAC,MAA4C,EAAE,WAAmB;IAChF,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACpC,IAAM,QAAQ,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QAE3B,IACI,IAAA,gDAAkB,EAAuB,QAAQ,EAAE,UAAU,CAAC;YAC9D,QAAQ,CAAC,MAAM,CAAC,MAAM,KAAK,WAAW,EACxC;YACE,OAAO,EAAE,CAAC;SACb;aAAM,IACH,IAAA,gDAAkB,EAAuB,QAAQ,EAAE,UAAU,CAAC;YAC9D,QAAQ,CAAC,MAAM,CAAC,MAAM,IAAI,CAAC,EAC7B;YACE,OAAO,OAAO,CAAC;SAClB;KACJ;IAED,OAAO,OAAO,CAAC;AACnB,CAAC,CAAC","sourcesContent":["import { getListAnnounceData } from 'roosterjs-content-model-api';\nimport { splitParagraph } from '../utils/splitParagraph';\nimport {\n createListItem,\n createListLevel,\n getClosestAncestorBlockGroupIndex,\n isBlockGroupOfType,\n mutateBlock,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelListItem,\n DeleteSelectionStep,\n ReadonlyContentModelBlock,\n ReadonlyContentModelBlockGroup,\n ReadonlyContentModelListItem,\n ShallowMutableContentModelListItem,\n ValidDeleteSelectionContext,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport const handleEnterOnList: DeleteSelectionStep = context => {\n const { deleteResult, insertPoint } = context;\n\n if (deleteResult == 'notDeleted' || deleteResult == 'nothingToDelete') {\n const { path } = insertPoint;\n const index = getClosestAncestorBlockGroupIndex(\n path,\n ['ListItem'],\n ['TableCell', 'FormatContainer']\n );\n\n const readonlyListItem = path[index];\n const listParent = path[index + 1];\n\n if (readonlyListItem?.blockGroupType === 'ListItem' && listParent) {\n let listItem = mutateBlock(readonlyListItem);\n\n if (isEmptyListItem(listItem)) {\n listItem.levels.pop();\n } else {\n listItem = createNewListItem(context, listItem, listParent);\n\n if (context.formatContext) {\n context.formatContext.announceData = getListAnnounceData([\n listItem,\n ...path.slice(index + 1),\n ]);\n }\n }\n\n const listIndex = listParent.blocks.indexOf(listItem);\n const nextBlock = listParent.blocks[listIndex + 1];\n\n if (nextBlock) {\n if (\n isBlockGroupOfType<ContentModelListItem>(nextBlock, 'ListItem') &&\n nextBlock.levels[0]\n ) {\n nextBlock.levels.forEach(level => {\n // Remove startNumberOverride so that next list item can join current list, unless it is 1.\n // List start with 1 means it should be an explicit new list and should never join another list before it\n if (level.format.startNumberOverride !== 1) {\n level.format.startNumberOverride = undefined;\n }\n });\n\n if (listItem.levels.length == 0) {\n const nextBlockIndex = findIndex(\n listParent.blocks,\n nextBlock.levels.length\n );\n\n nextBlock.levels[\n nextBlock.levels.length - 1\n ].format.startNumberOverride = nextBlockIndex;\n }\n }\n }\n\n context.deleteResult = 'range';\n }\n }\n};\n\nconst isEmptyListItem = (listItem: ReadonlyContentModelListItem) => {\n return listItem.blocks.length === 1 && isEmptyParagraph(listItem.blocks[0]);\n};\n\nconst isEmptyParagraph = (block: ReadonlyContentModelBlock) => {\n return (\n block.blockType === 'Paragraph' &&\n block.segments.length === 2 &&\n block.segments[0].segmentType === 'SelectionMarker' &&\n block.segments[1].segmentType === 'Br'\n );\n};\n\nconst createNewListItem = (\n context: ValidDeleteSelectionContext,\n listItem: ReadonlyContentModelListItem,\n listParent: ReadonlyContentModelBlockGroup\n) => {\n const { insertPoint } = context;\n const listIndex = listParent.blocks.indexOf(listItem);\n const currentPara = insertPoint.paragraph;\n const paraIndex = listItem.blocks.indexOf(currentPara);\n const newParagraph = splitParagraph(insertPoint);\n\n const levels = createNewListLevel(listItem);\n const newListItem: ShallowMutableContentModelListItem = createListItem(\n levels,\n listItem.formatHolder.format\n );\n\n newListItem.blocks.push(newParagraph);\n\n const remainingBlockCount = listItem.blocks.length - paraIndex - 1;\n\n if (paraIndex >= 0 && remainingBlockCount > 0) {\n newListItem.blocks.push(\n ...mutateBlock(listItem).blocks.splice(paraIndex + 1, remainingBlockCount)\n );\n }\n\n insertPoint.paragraph = newParagraph;\n mutateBlock(listParent).blocks.splice(listIndex + 1, 0, newListItem);\n\n if (context.lastParagraph == currentPara) {\n context.lastParagraph = newParagraph;\n }\n\n return newListItem;\n};\n\nconst createNewListLevel = (listItem: ReadonlyContentModelListItem) => {\n return listItem.levels.map(level => {\n return createListLevel(\n level.listType,\n {\n ...level.format,\n startNumberOverride: undefined,\n displayForDummyItem: undefined, // When ENTER, we should create a new regular list item, so force its dummy item display to undefined\n },\n level.dataset\n );\n });\n};\n\nconst findIndex = (blocks: readonly ReadonlyContentModelBlock[], levelLength: number) => {\n let counter = 1;\n for (let i = 0; i < blocks.length; i++) {\n const listItem = blocks[i];\n\n if (\n isBlockGroupOfType<ContentModelListItem>(listItem, 'ListItem') &&\n listItem.levels.length === levelLength\n ) {\n counter++;\n } else if (\n isBlockGroupOfType<ContentModelListItem>(listItem, 'ListItem') &&\n listItem.levels.length == 0\n ) {\n return counter;\n }\n }\n\n return counter;\n};\n"]}
|
|
@@ -57,6 +57,9 @@ export declare class ImageEditPlugin implements ImageEditor, EditorPlugin {
|
|
|
57
57
|
private mouseDownHandler;
|
|
58
58
|
private onDropHandler;
|
|
59
59
|
private keyDownHandler;
|
|
60
|
+
private setContentHandler;
|
|
61
|
+
private formatEventHandler;
|
|
62
|
+
private contentChangedHandler;
|
|
60
63
|
/**
|
|
61
64
|
* EXPOSED FOR TESTING PURPOSE ONLY
|
|
62
65
|
*/
|
|
@@ -32,6 +32,7 @@ var MouseRightButton = 2;
|
|
|
32
32
|
var DRAG_ID = '_dragging';
|
|
33
33
|
var IMAGE_EDIT_CLASS = 'imageEdit';
|
|
34
34
|
var IMAGE_EDIT_CLASS_CARET = 'imageEditCaretColor';
|
|
35
|
+
var IMAGE_EDIT_FORMAT_EVENT = 'ImageEditEvent';
|
|
35
36
|
/**
|
|
36
37
|
* ImageEdit plugin handles the following image editing features:
|
|
37
38
|
* - Resize image
|
|
@@ -141,9 +142,7 @@ var ImageEditPlugin = /** @class */ (function () {
|
|
|
141
142
|
this.keyDownHandler(this.editor, event);
|
|
142
143
|
break;
|
|
143
144
|
case 'contentChanged':
|
|
144
|
-
|
|
145
|
-
this.onDropHandler(this.editor);
|
|
146
|
-
}
|
|
145
|
+
this.contentChangedHandler(this.editor, event);
|
|
147
146
|
break;
|
|
148
147
|
case 'extractContentWithDom':
|
|
149
148
|
this.removeImageEditing(event.clonedRoot);
|
|
@@ -220,6 +219,32 @@ var ImageEditPlugin = /** @class */ (function () {
|
|
|
220
219
|
}
|
|
221
220
|
}
|
|
222
221
|
};
|
|
222
|
+
ImageEditPlugin.prototype.setContentHandler = function (editor) {
|
|
223
|
+
var selection = editor.getDOMSelection();
|
|
224
|
+
if ((selection === null || selection === void 0 ? void 0 : selection.type) == 'image' && selection.image.dataset.isEditing && !this.isEditing) {
|
|
225
|
+
delete selection.image.dataset.isEditing;
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
ImageEditPlugin.prototype.formatEventHandler = function (event) {
|
|
229
|
+
if (this.isEditing && event.formatApiName !== IMAGE_EDIT_FORMAT_EVENT) {
|
|
230
|
+
this.cleanInfo();
|
|
231
|
+
this.isEditing = false;
|
|
232
|
+
this.isCropMode = false;
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
ImageEditPlugin.prototype.contentChangedHandler = function (editor, event) {
|
|
236
|
+
switch (event.source) {
|
|
237
|
+
case roosterjs_content_model_dom_1.ChangeSource.SetContent:
|
|
238
|
+
this.setContentHandler(editor);
|
|
239
|
+
break;
|
|
240
|
+
case roosterjs_content_model_dom_1.ChangeSource.Format:
|
|
241
|
+
this.formatEventHandler(event);
|
|
242
|
+
break;
|
|
243
|
+
case roosterjs_content_model_dom_1.ChangeSource.Drop:
|
|
244
|
+
this.onDropHandler(editor);
|
|
245
|
+
break;
|
|
246
|
+
}
|
|
247
|
+
};
|
|
223
248
|
/**
|
|
224
249
|
* EXPOSED FOR TESTING PURPOSE ONLY
|
|
225
250
|
*/
|
|
@@ -298,6 +323,7 @@ var ImageEditPlugin = /** @class */ (function () {
|
|
|
298
323
|
}
|
|
299
324
|
}
|
|
300
325
|
},
|
|
326
|
+
apiName: IMAGE_EDIT_FORMAT_EVENT,
|
|
301
327
|
}, {
|
|
302
328
|
tryGetFromCache: true,
|
|
303
329
|
});
|