roosterjs-content-model-plugins 9.41.0 → 9.43.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/lib/autoFormat/AutoFormatPlugin.js +9 -10
  2. package/lib/autoFormat/AutoFormatPlugin.js.map +1 -1
  3. package/lib/edit/inputSteps/handleEnterOnList.js +0 -33
  4. package/lib/edit/inputSteps/handleEnterOnList.js.map +1 -1
  5. package/lib/paste/PastePlugin.js +8 -32
  6. package/lib/paste/PastePlugin.js.map +1 -1
  7. package/lib/paste/WordDesktop/processPastedContentFromWordDesktop.js +7 -31
  8. package/lib/paste/WordDesktop/processPastedContentFromWordDesktop.js.map +1 -1
  9. package/lib/paste/parsers/adjustPercentileLineHeightParser.d.ts +8 -0
  10. package/lib/paste/parsers/adjustPercentileLineHeightParser.js +26 -0
  11. package/lib/paste/parsers/adjustPercentileLineHeightParser.js.map +1 -0
  12. package/lib/paste/parsers/blockElementParser.d.ts +7 -0
  13. package/lib/paste/parsers/blockElementParser.js +15 -0
  14. package/lib/paste/parsers/blockElementParser.js.map +1 -0
  15. package/lib/paste/parsers/imageSizeParser.d.ts +6 -0
  16. package/lib/paste/parsers/imageSizeParser.js +24 -0
  17. package/lib/paste/parsers/imageSizeParser.js.map +1 -0
  18. package/lib/paste/parsers/listLevelParser.d.ts +10 -0
  19. package/lib/paste/parsers/listLevelParser.js +19 -0
  20. package/lib/paste/parsers/listLevelParser.js.map +1 -0
  21. package/lib/paste/parsers/tableBorderParser.d.ts +5 -0
  22. package/lib/paste/parsers/tableBorderParser.js +28 -0
  23. package/lib/paste/parsers/tableBorderParser.js.map +1 -0
  24. package/lib/paste/parsers/wordTableParser.d.ts +8 -0
  25. package/lib/paste/parsers/wordTableParser.js +20 -0
  26. package/lib/paste/parsers/wordTableParser.js.map +1 -0
  27. package/lib-amd/autoFormat/AutoFormatPlugin.js +9 -10
  28. package/lib-amd/autoFormat/AutoFormatPlugin.js.map +1 -1
  29. package/lib-amd/edit/inputSteps/handleEnterOnList.js +0 -33
  30. package/lib-amd/edit/inputSteps/handleEnterOnList.js.map +1 -1
  31. package/lib-amd/paste/PastePlugin.js +5 -32
  32. package/lib-amd/paste/PastePlugin.js.map +1 -1
  33. package/lib-amd/paste/WordDesktop/processPastedContentFromWordDesktop.js +5 -32
  34. package/lib-amd/paste/WordDesktop/processPastedContentFromWordDesktop.js.map +1 -1
  35. package/lib-amd/paste/parsers/adjustPercentileLineHeightParser.d.ts +8 -0
  36. package/lib-amd/paste/parsers/adjustPercentileLineHeightParser.js +28 -0
  37. package/lib-amd/paste/parsers/adjustPercentileLineHeightParser.js.map +1 -0
  38. package/lib-amd/paste/parsers/blockElementParser.d.ts +7 -0
  39. package/lib-amd/paste/parsers/blockElementParser.js +17 -0
  40. package/lib-amd/paste/parsers/blockElementParser.js.map +1 -0
  41. package/lib-amd/paste/parsers/imageSizeParser.d.ts +6 -0
  42. package/lib-amd/paste/parsers/imageSizeParser.js +25 -0
  43. package/lib-amd/paste/parsers/imageSizeParser.js.map +1 -0
  44. package/lib-amd/paste/parsers/listLevelParser.d.ts +10 -0
  45. package/lib-amd/paste/parsers/listLevelParser.js +21 -0
  46. package/lib-amd/paste/parsers/listLevelParser.js.map +1 -0
  47. package/lib-amd/paste/parsers/tableBorderParser.d.ts +5 -0
  48. package/lib-amd/paste/parsers/tableBorderParser.js +29 -0
  49. package/lib-amd/paste/parsers/tableBorderParser.js.map +1 -0
  50. package/lib-amd/paste/parsers/wordTableParser.d.ts +8 -0
  51. package/lib-amd/paste/parsers/wordTableParser.js +22 -0
  52. package/lib-amd/paste/parsers/wordTableParser.js.map +1 -0
  53. package/lib-mjs/autoFormat/AutoFormatPlugin.js +9 -10
  54. package/lib-mjs/autoFormat/AutoFormatPlugin.js.map +1 -1
  55. package/lib-mjs/edit/inputSteps/handleEnterOnList.js +1 -34
  56. package/lib-mjs/edit/inputSteps/handleEnterOnList.js.map +1 -1
  57. package/lib-mjs/paste/PastePlugin.js +5 -29
  58. package/lib-mjs/paste/PastePlugin.js.map +1 -1
  59. package/lib-mjs/paste/WordDesktop/processPastedContentFromWordDesktop.js +3 -27
  60. package/lib-mjs/paste/WordDesktop/processPastedContentFromWordDesktop.js.map +1 -1
  61. package/lib-mjs/paste/parsers/adjustPercentileLineHeightParser.d.ts +8 -0
  62. package/lib-mjs/paste/parsers/adjustPercentileLineHeightParser.js +22 -0
  63. package/lib-mjs/paste/parsers/adjustPercentileLineHeightParser.js.map +1 -0
  64. package/lib-mjs/paste/parsers/blockElementParser.d.ts +7 -0
  65. package/lib-mjs/paste/parsers/blockElementParser.js +11 -0
  66. package/lib-mjs/paste/parsers/blockElementParser.js.map +1 -0
  67. package/lib-mjs/paste/parsers/imageSizeParser.d.ts +6 -0
  68. package/lib-mjs/paste/parsers/imageSizeParser.js +20 -0
  69. package/lib-mjs/paste/parsers/imageSizeParser.js.map +1 -0
  70. package/lib-mjs/paste/parsers/listLevelParser.d.ts +10 -0
  71. package/lib-mjs/paste/parsers/listLevelParser.js +15 -0
  72. package/lib-mjs/paste/parsers/listLevelParser.js.map +1 -0
  73. package/lib-mjs/paste/parsers/tableBorderParser.d.ts +5 -0
  74. package/lib-mjs/paste/parsers/tableBorderParser.js +24 -0
  75. package/lib-mjs/paste/parsers/tableBorderParser.js.map +1 -0
  76. package/lib-mjs/paste/parsers/wordTableParser.d.ts +8 -0
  77. package/lib-mjs/paste/parsers/wordTableParser.js +16 -0
  78. package/lib-mjs/paste/parsers/wordTableParser.js.map +1 -0
  79. package/package.json +5 -5
@@ -5,13 +5,13 @@ var tslib_1 = require("tslib");
5
5
  var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
6
6
  var checkAndInsertHorizontalLine_1 = require("./horizontalLine/checkAndInsertHorizontalLine");
7
7
  var createLink_1 = require("./link/createLink");
8
- var roosterjs_content_model_api_1 = require("roosterjs-content-model-api");
9
8
  var getListTypeStyle_1 = require("./list/getListTypeStyle");
10
9
  var keyboardListTrigger_1 = require("./list/keyboardListTrigger");
11
10
  var transformFraction_1 = require("./numbers/transformFraction");
12
11
  var transformHyphen_1 = require("./hyphen/transformHyphen");
13
12
  var transformOrdinals_1 = require("./numbers/transformOrdinals");
14
13
  var unlink_1 = require("./link/unlink");
14
+ var roosterjs_content_model_api_1 = require("roosterjs-content-model-api");
15
15
  /**
16
16
  * @internal
17
17
  */
@@ -141,7 +141,6 @@ var AutoFormatPlugin = /** @class */ (function () {
141
141
  this.editor = null;
142
142
  };
143
143
  AutoFormatPlugin.prototype.shouldHandleInputEventExclusively = function (editor, event) {
144
- var _this = this;
145
144
  var rawEvent = event.rawEvent;
146
145
  var selection = editor.getDOMSelection();
147
146
  var shouldHandle = false;
@@ -150,15 +149,15 @@ var AutoFormatPlugin = /** @class */ (function () {
150
149
  selection.type === 'range' &&
151
150
  selection.range.collapsed &&
152
151
  rawEvent.data == ' ') {
153
- (0, roosterjs_content_model_api_1.formatTextSegmentBeforeSelectionMarker)(editor, function (model, previousSegment, paragraph) {
154
- var _a = _this.options, autoLink = _a.autoLink, autoTel = _a.autoTel, autoMailto = _a.autoMailto, autoBullet = _a.autoBullet, autoNumbering = _a.autoNumbering;
155
- var list = (0, getListTypeStyle_1.getListTypeStyle)(model, autoBullet, autoNumbering);
156
- var link = (0, roosterjs_content_model_api_1.promoteLink)(previousSegment, paragraph, {
157
- autoLink: autoLink,
158
- autoTel: autoTel,
159
- autoMailto: autoMailto,
152
+ var _a = this.options, autoLink_1 = _a.autoLink, autoTel_1 = _a.autoTel, autoMailto_1 = _a.autoMailto, autoBullet_1 = _a.autoBullet, autoNumbering_1 = _a.autoNumbering;
153
+ (0, roosterjs_content_model_api_1.formatTextSegmentBeforeSelectionMarker)(editor, function (model, previousSegment, _paragraph, _markerFormat) {
154
+ var list = (0, getListTypeStyle_1.getListTypeStyle)(model, autoBullet_1, autoNumbering_1);
155
+ var promotedLink = (0, roosterjs_content_model_api_1.getPromoteLink)(previousSegment, {
156
+ autoLink: autoLink_1,
157
+ autoTel: autoTel_1,
158
+ autoMailto: autoMailto_1,
160
159
  });
161
- shouldHandle = !!link || !!list;
160
+ shouldHandle = !!promotedLink || !!list;
162
161
  return false;
163
162
  });
164
163
  }
@@ -1 +1 @@
1
- {"version":3,"file":"AutoFormatPlugin.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/AutoFormatPlugin.ts"],"names":[],"mappings":";;;;AAAA,2EAA2D;AAC3D,8FAA6F;AAC7F,gDAA+C;AAC/C,2EAAkG;AAClG,4DAA2D;AAC3D,kEAAiE;AACjE,iEAAgE;AAChE,4DAA2D;AAC3D,iEAAgE;AAChE,wCAAuC;AA+BvC;;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;IACnB,iBAAiB,EAAE,KAAK;IACxB,kBAAkB,EAAE,KAAK;CAC5B,CAAC;AAEF;;;GAGG;AACH;IAEI;;;;;;;;;;;;;OAaG;IACH,0BAAoB,OAA2C;QAA/D,iBAAmE;QAA/C,wBAAA,EAAA,wBAA2C;QAA3C,YAAO,GAAP,OAAO,CAAoC;QAfvD,WAAM,GAAmB,IAAI,CAAC;QAqG9B,aAAQ,GAAY;YACxB,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC;YACrF,iBAAiB,EAAE,UAAC,MAAM,EAAE,eAAe,EAAE,SAAS,EAAE,OAAO;;gBACrD,IAAA,KAAoC,KAAI,CAAC,OAAO,EAA9C,QAAQ,cAAA,EAAE,OAAO,aAAA,EAAE,UAAU,gBAAiB,CAAC;gBACvD,IAAM,WAAW,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BAAgB,EAAE;4BAC1C,KAAK,CAAC,QAAQ,CAAC,cAAc,EAAE,CAAC;yBACnC;qBACJ;oBACD,MAAM;gBACV,KAAK,OAAO;oBACR,IAAM,YAAY,GAAG,IAAI,CAAC,oBAAoB,CAAC,MAAM,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;oBAC3E,IAAI,YAAY,CAAC,OAAO,IAAI,oBAAoB,EAAE;wBAC9C,KAAK,CAAC,QAAQ,CAAC,cAAc,EAAE,CAAC;qBACnC;oBACD,MAAM;aACb;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,AA9QD,IA8QC;AA9QY,4CAAgB;AAgR7B,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 { checkAndInsertHorizontalLine } from './horizontalLine/checkAndInsertHorizontalLine';\nimport { createLink } from './link/createLink';\nimport { formatTextSegmentBeforeSelectionMarker, promoteLink } from 'roosterjs-content-model-api';\nimport { getListTypeStyle } from './list/getListTypeStyle';\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 ContentModelText,\n EditorInputEvent,\n EditorPlugin,\n FormatContentModelContext,\n FormatContentModelOptions,\n IEditor,\n KeyDownEvent,\n PluginEvent,\n ReadonlyContentModelDocument,\n ShallowMutableContentModelParagraph,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\ninterface Feature {\n enabled: boolean;\n transformFunction: (\n model: ReadonlyContentModelDocument,\n previousSegment: ContentModelText,\n paragraph: ShallowMutableContentModelParagraph,\n context: FormatContentModelContext\n ) => boolean | HTMLElement;\n changeSource: string;\n apiName: string;\n}\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 autoHorizontalLine: 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 * - autoHorizontalLine: A boolean that enables or disables automatic horizontal line creation. 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 private shouldHandleInputEventExclusively(editor: IEditor, event: EditorInputEvent) {\n const rawEvent = event.rawEvent;\n const selection = editor.getDOMSelection();\n let shouldHandle = false;\n if (\n rawEvent.inputType === 'insertText' &&\n selection &&\n selection.type === 'range' &&\n selection.range.collapsed &&\n rawEvent.data == ' '\n ) {\n formatTextSegmentBeforeSelectionMarker(editor, (model, previousSegment, paragraph) => {\n const { autoLink, autoTel, autoMailto, autoBullet, autoNumbering } = this.options;\n const list = getListTypeStyle(model, autoBullet, autoNumbering);\n const link = promoteLink(previousSegment, paragraph, {\n autoLink,\n autoTel,\n autoMailto,\n });\n shouldHandle = !!link || !!list;\n return false;\n });\n }\n return shouldHandle;\n }\n\n willHandleEventExclusively(event: PluginEvent) {\n if (this.editor) {\n switch (event.eventType) {\n case 'input':\n return this.shouldHandleInputEventExclusively(this.editor, event);\n }\n }\n return false;\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 autoLink: Feature = {\n enabled: !!(this.options.autoLink || this.options.autoTel || this.options.autoMailto),\n transformFunction: (_model, previousSegment, paragraph, context) => {\n const { autoLink, autoTel, autoMailto } = this.options;\n const linkSegment = promoteLink(previousSegment, paragraph, {\n autoLink,\n autoTel,\n autoMailto,\n });\n\n if (linkSegment) {\n return createAnchor(linkSegment.link?.format.href || '', linkSegment.text);\n }\n return false;\n },\n apiName: 'autoLink',\n changeSource: ChangeSource.AutoLink,\n };\n\n private tabFeatures: Feature[] = [\n {\n enabled: !!(this.options.autoBullet || this.options.autoNumbering),\n transformFunction: (model, _previousSegment, paragraph, context) =>\n keyboardListTrigger(\n model,\n paragraph,\n context,\n this.options.autoBullet,\n this.options.autoNumbering,\n this.options.removeListMargins\n ),\n apiName: 'autoToggleList',\n changeSource: ChangeSource.AutoFormat,\n },\n this.autoLink,\n ];\n\n private features: Feature[] = [\n ...this.tabFeatures,\n {\n enabled: !!this.options.autoHyphen,\n apiName: 'autoHyphen',\n changeSource: ChangeSource.Format,\n transformFunction: (_model, previousSegment, paragraph, context) =>\n transformHyphen(previousSegment, paragraph, context),\n },\n {\n enabled: !!this.options.autoFraction,\n apiName: 'autoFraction',\n changeSource: ChangeSource.Format,\n transformFunction: (_model, previousSegment, paragraph, context) =>\n transformFraction(previousSegment, paragraph, context),\n },\n {\n enabled: !!this.options.autoOrdinals,\n apiName: 'autoOrdinal',\n changeSource: ChangeSource.Format,\n transformFunction: (_model, previousSegment, paragraph, context) =>\n transformOrdinals(previousSegment, paragraph, context),\n },\n ];\n\n private enterFeatures: Feature[] = [\n {\n enabled: !!this.options.autoHorizontalLine,\n transformFunction: (model, _previousSegment, paragraph, context) =>\n checkAndInsertHorizontalLine(model, paragraph, context),\n apiName: 'autoHorizontalLine',\n changeSource: ChangeSource.AutoFormat,\n },\n this.autoLink,\n ];\n\n private handleKeyboardEvents(editor: IEditor, features: Feature[]): FormatContentModelOptions {\n const formatOptions: FormatContentModelOptions = {\n changeSource: '',\n apiName: '',\n getChangeData: undefined,\n };\n\n formatTextSegmentBeforeSelectionMarker(\n editor,\n (model, previousSegment, paragraph, _markerFormat, context) => {\n let featureApplied: Feature | undefined = undefined;\n for (const feature of features) {\n if (feature.enabled) {\n const result = feature.transformFunction(\n model,\n previousSegment,\n paragraph,\n context\n );\n if (result) {\n if (typeof result !== 'boolean') {\n formatOptions.getChangeData = () => result;\n }\n featureApplied = feature;\n break;\n }\n }\n }\n\n if (featureApplied) {\n formatOptions.changeSource = featureApplied.changeSource;\n formatOptions.apiName = featureApplied.apiName;\n }\n\n return !!featureApplied;\n },\n formatOptions\n );\n return formatOptions;\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 this.handleKeyboardEvents(editor, this.features);\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 const eventHandled = this.handleKeyboardEvents(editor, this.tabFeatures);\n if (eventHandled.apiName == 'autoToggleList') {\n event.rawEvent.preventDefault();\n }\n }\n break;\n case 'Enter':\n const eventHandled = this.handleKeyboardEvents(editor, this.enterFeatures);\n if (eventHandled.apiName == 'autoHorizontalLine') {\n event.rawEvent.preventDefault();\n }\n break;\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 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
+ {"version":3,"file":"AutoFormatPlugin.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/AutoFormatPlugin.ts"],"names":[],"mappings":";;;;AAAA,2EAA2D;AAC3D,8FAA6F;AAC7F,gDAA+C;AAC/C,4DAA2D;AAC3D,kEAAiE;AACjE,iEAAgE;AAChE,4DAA2D;AAC3D,iEAAgE;AAChE,wCAAuC;AACvC,2EAIqC;AA+BrC;;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;IACnB,iBAAiB,EAAE,KAAK;IACxB,kBAAkB,EAAE,KAAK;CAC5B,CAAC;AAEF;;;GAGG;AACH;IAEI;;;;;;;;;;;;;OAaG;IACH,0BAAoB,OAA2C;QAA/D,iBAAmE;QAA/C,wBAAA,EAAA,wBAA2C;QAA3C,YAAO,GAAP,OAAO,CAAoC;QAfvD,WAAM,GAAmB,IAAI,CAAC;QA0G9B,aAAQ,GAAY;YACxB,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC;YACrF,iBAAiB,EAAE,UAAC,MAAM,EAAE,eAAe,EAAE,SAAS,EAAE,OAAO;;gBACrD,IAAA,KAAoC,KAAI,CAAC,OAAO,EAA9C,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,CAAC,WAAW,CAAC,CAAC;wBACzE,IAAI,cAAY,CAAC,OAAO,IAAI,gBAAgB,EAAE;4BAC1C,KAAK,CAAC,QAAQ,CAAC,cAAc,EAAE,CAAC;yBACnC;qBACJ;oBACD,MAAM;gBACV,KAAK,OAAO;oBACR,IAAM,YAAY,GAAG,IAAI,CAAC,oBAAoB,CAAC,MAAM,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;oBAC3E,IAAI,YAAY,CAAC,OAAO,IAAI,oBAAoB,EAAE;wBAC9C,KAAK,CAAC,QAAQ,CAAC,cAAc,EAAE,CAAC;qBACnC;oBACD,MAAM;aACb;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,AApRD,IAoRC;AApRY,4CAAgB;AAsR7B,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 { checkAndInsertHorizontalLine } from './horizontalLine/checkAndInsertHorizontalLine';\nimport { createLink } from './link/createLink';\nimport { getListTypeStyle } from './list/getListTypeStyle';\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 {\n formatTextSegmentBeforeSelectionMarker,\n promoteLink,\n getPromoteLink,\n} from 'roosterjs-content-model-api';\nimport type { AutoFormatOptions } from './interface/AutoFormatOptions';\nimport type {\n ContentChangedEvent,\n ContentModelText,\n EditorInputEvent,\n EditorPlugin,\n FormatContentModelContext,\n FormatContentModelOptions,\n IEditor,\n KeyDownEvent,\n PluginEvent,\n ReadonlyContentModelDocument,\n ShallowMutableContentModelParagraph,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\ninterface Feature {\n enabled: boolean;\n transformFunction: (\n model: ReadonlyContentModelDocument,\n previousSegment: ContentModelText,\n paragraph: ShallowMutableContentModelParagraph,\n context: FormatContentModelContext\n ) => boolean | HTMLElement;\n changeSource: string;\n apiName: string;\n}\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 autoHorizontalLine: 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 * - autoHorizontalLine: A boolean that enables or disables automatic horizontal line creation. 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 private shouldHandleInputEventExclusively(editor: IEditor, event: EditorInputEvent) {\n const rawEvent = event.rawEvent;\n const selection = editor.getDOMSelection();\n let shouldHandle = false;\n if (\n rawEvent.inputType === 'insertText' &&\n selection &&\n selection.type === 'range' &&\n selection.range.collapsed &&\n rawEvent.data == ' '\n ) {\n const { autoLink, autoTel, autoMailto, autoBullet, autoNumbering } = this.options;\n\n formatTextSegmentBeforeSelectionMarker(\n editor,\n (model, previousSegment, _paragraph, _markerFormat) => {\n const list = getListTypeStyle(model, autoBullet, autoNumbering);\n const promotedLink = getPromoteLink(previousSegment, {\n autoLink,\n autoTel,\n autoMailto,\n });\n shouldHandle = !!promotedLink || !!list;\n\n return false;\n }\n );\n }\n return shouldHandle;\n }\n\n willHandleEventExclusively(event: PluginEvent) {\n if (this.editor) {\n switch (event.eventType) {\n case 'input':\n return this.shouldHandleInputEventExclusively(this.editor, event);\n }\n }\n return false;\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 autoLink: Feature = {\n enabled: !!(this.options.autoLink || this.options.autoTel || this.options.autoMailto),\n transformFunction: (_model, previousSegment, paragraph, context) => {\n const { autoLink, autoTel, autoMailto } = this.options;\n const linkSegment = promoteLink(previousSegment, paragraph, {\n autoLink,\n autoTel,\n autoMailto,\n });\n\n if (linkSegment) {\n return createAnchor(linkSegment.link?.format.href || '', linkSegment.text);\n }\n return false;\n },\n apiName: 'autoLink',\n changeSource: ChangeSource.AutoLink,\n };\n\n private tabFeatures: Feature[] = [\n {\n enabled: !!(this.options.autoBullet || this.options.autoNumbering),\n transformFunction: (model, _previousSegment, paragraph, context) =>\n keyboardListTrigger(\n model,\n paragraph,\n context,\n this.options.autoBullet,\n this.options.autoNumbering,\n this.options.removeListMargins\n ),\n apiName: 'autoToggleList',\n changeSource: ChangeSource.AutoFormat,\n },\n this.autoLink,\n ];\n\n private features: Feature[] = [\n ...this.tabFeatures,\n {\n enabled: !!this.options.autoHyphen,\n apiName: 'autoHyphen',\n changeSource: ChangeSource.Format,\n transformFunction: (_model, previousSegment, paragraph, context) =>\n transformHyphen(previousSegment, paragraph, context),\n },\n {\n enabled: !!this.options.autoFraction,\n apiName: 'autoFraction',\n changeSource: ChangeSource.Format,\n transformFunction: (_model, previousSegment, paragraph, context) =>\n transformFraction(previousSegment, paragraph, context),\n },\n {\n enabled: !!this.options.autoOrdinals,\n apiName: 'autoOrdinal',\n changeSource: ChangeSource.Format,\n transformFunction: (_model, previousSegment, paragraph, context) =>\n transformOrdinals(previousSegment, paragraph, context),\n },\n ];\n\n private enterFeatures: Feature[] = [\n {\n enabled: !!this.options.autoHorizontalLine,\n transformFunction: (model, _previousSegment, paragraph, context) =>\n checkAndInsertHorizontalLine(model, paragraph, context),\n apiName: 'autoHorizontalLine',\n changeSource: ChangeSource.AutoFormat,\n },\n this.autoLink,\n ];\n\n private handleKeyboardEvents(editor: IEditor, features: Feature[]): FormatContentModelOptions {\n const formatOptions: FormatContentModelOptions = {\n changeSource: '',\n apiName: '',\n getChangeData: undefined,\n };\n\n formatTextSegmentBeforeSelectionMarker(\n editor,\n (model, previousSegment, paragraph, _markerFormat, context) => {\n let featureApplied: Feature | undefined = undefined;\n for (const feature of features) {\n if (feature.enabled) {\n const result = feature.transformFunction(\n model,\n previousSegment,\n paragraph,\n context\n );\n\n if (result) {\n if (typeof result !== 'boolean') {\n formatOptions.getChangeData = () => result;\n }\n featureApplied = feature;\n break;\n }\n }\n }\n\n if (featureApplied) {\n formatOptions.changeSource = featureApplied.changeSource;\n formatOptions.apiName = featureApplied.apiName;\n }\n\n return !!featureApplied;\n },\n formatOptions\n );\n return formatOptions;\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 this.handleKeyboardEvents(editor, this.features);\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 const eventHandled = this.handleKeyboardEvents(editor, this.tabFeatures);\n if (eventHandled.apiName == 'autoToggleList') {\n event.rawEvent.preventDefault();\n }\n }\n break;\n case 'Enter':\n const eventHandled = this.handleKeyboardEvents(editor, this.enterFeatures);\n if (eventHandled.apiName == 'autoHorizontalLine') {\n event.rawEvent.preventDefault();\n }\n break;\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 createAnchor = (url: string, text: string) => {\n const anchor = document.createElement('a');\n anchor.href = url;\n anchor.textContent = text;\n return anchor;\n};\n"]}
@@ -28,24 +28,6 @@ var handleEnterOnList = function (context) {
28
28
  ], (0, tslib_1.__read)(path.slice(index + 1)), false));
29
29
  }
30
30
  }
31
- var listIndex = listParent.blocks.indexOf(listItem);
32
- var nextBlock = listParent.blocks[listIndex + 1];
33
- if (nextBlock) {
34
- if ((0, roosterjs_content_model_dom_1.isBlockGroupOfType)(nextBlock, 'ListItem') &&
35
- nextBlock.levels[0]) {
36
- nextBlock.levels.forEach(function (level) {
37
- // Remove startNumberOverride so that next list item can join current list, unless it is 1.
38
- // List start with 1 means it should be an explicit new list and should never join another list before it
39
- if (level.format.startNumberOverride !== 1) {
40
- level.format.startNumberOverride = undefined;
41
- }
42
- });
43
- if (listItem.levels.length == 0) {
44
- var nextBlockIndex = findIndex(listParent.blocks, nextBlock.levels.length);
45
- nextBlock.levels[nextBlock.levels.length - 1].format.startNumberOverride = nextBlockIndex;
46
- }
47
- }
48
- }
49
31
  context.deleteResult = 'range';
50
32
  }
51
33
  }
@@ -87,19 +69,4 @@ var createNewListLevel = function (listItem) {
87
69
  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);
88
70
  });
89
71
  };
90
- var findIndex = function (blocks, levelLength) {
91
- var counter = 1;
92
- for (var i = 0; i < blocks.length; i++) {
93
- var listItem = blocks[i];
94
- if ((0, roosterjs_content_model_dom_1.isBlockGroupOfType)(listItem, 'ListItem') &&
95
- listItem.levels.length === levelLength) {
96
- counter++;
97
- }
98
- else if ((0, roosterjs_content_model_dom_1.isBlockGroupOfType)(listItem, 'ListItem') &&
99
- listItem.levels.length == 0) {
100
- return counter;
101
- }
102
- }
103
- return counter;
104
- };
105
72
  //# sourceMappingURL=handleEnterOnList.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"handleEnterOnList.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/edit/inputSteps/handleEnterOnList.ts"],"names":[],"mappings":";;;;AAAA,2EAAkE;AAClE,0DAAyD;AACzD,2EAQqC;AAYrC;;GAEG;AACI,IAAM,iBAAiB,GAAwB,UAAA,OAAO;IACjD,IAAA,YAAY,GAAkB,OAAO,aAAzB,EAAE,WAAW,GAAK,OAAO,YAAZ,CAAa;IAE9C,IAAI,YAAY,IAAI,YAAY,IAAI,YAAY,IAAI,iBAAiB,EAAE;QAC3D,IAAA,IAAI,GAAK,WAAW,KAAhB,CAAiB;QAC7B,IAAM,KAAK,GAAG,IAAA,+DAAiC,EAC3C,IAAI,EACJ,CAAC,UAAU,CAAC,EACZ,CAAC,WAAW,EAAE,iBAAiB,CAAC,CACnC,CAAC;QAEF,IAAM,gBAAgB,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;QACrC,IAAM,UAAU,GAAG,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;QAEnC,IAAI,CAAA,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,cAAc,MAAK,UAAU,IAAI,UAAU,EAAE;YAC/D,IAAI,QAAQ,GAAG,IAAA,yCAAW,EAAC,gBAAgB,CAAC,CAAC;YAE7C,IAAI,eAAe,CAAC,QAAQ,CAAC,EAAE;gBAC3B,QAAQ,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC;aACzB;iBAAM;gBACH,QAAQ,GAAG,iBAAiB,CAAC,OAAO,EAAE,QAAQ,EAAE,U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E,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 copyFormat,\n createListItem,\n createListLevel,\n getClosestAncestorBlockGroupIndex,\n isBlockGroupOfType,\n ListFormats,\n mutateBlock,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelBlockFormat,\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 copyFormat<ContentModelBlockFormat>(newListItem.format, listItem.format, ListFormats);\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"]}
1
+ {"version":3,"file":"handleEnterOnList.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/edit/inputSteps/handleEnterOnList.ts"],"names":[],"mappings":";;;;AAAA,2EAAkE;AAClE,0DAAyD;AACzD,2EAOqC;AAWrC;;GAEG;AACI,IAAM,iBAAiB,GAAwB,UAAA,OAAO;IACjD,IAAA,YAAY,GAAkB,OAAO,aAAzB,EAAE,WAAW,GAAK,OAAO,YAAZ,CAAa;IAE9C,IAAI,YAAY,IAAI,YAAY,IAAI,YAAY,IAAI,iBAAiB,EAAE;QAC3D,IAAA,IAAI,GAAK,WAAW,KAAhB,CAAiB;QAC7B,IAAM,KAAK,GAAG,IAAA,+DAAiC,EAC3C,IAAI,EACJ,CAAC,UAAU,CAAC,EACZ,CAAC,WAAW,EAAE,iBAAiB,CAAC,CACnC,CAAC;QAEF,IAAM,gBAAgB,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;QACrC,IAAM,UAAU,GAAG,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;QAEnC,IAAI,CAAA,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,cAAc,MAAK,UAAU,IAAI,UAAU,EAAE;YAC/D,IAAI,QAAQ,GAAG,IAAA,yCAAW,EAAC,gBAAgB,CAAC,CAAC;YAE7C,IAAI,eAAe,CAAC,QAAQ,CAAC,EAAE;gBAC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,SAAS,KAElC,KAAK,CAAC,OAAO,CAChB,CAAC;IACN,CAAC,CAAC,CAAC;AACP,CAAC,CAAC","sourcesContent":["import { getListAnnounceData } from 'roosterjs-content-model-api';\nimport { splitParagraph } from '../utils/splitParagraph';\nimport {\n copyFormat,\n createListItem,\n createListLevel,\n getClosestAncestorBlockGroupIndex,\n ListFormats,\n mutateBlock,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelBlockFormat,\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 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 copyFormat<ContentModelBlockFormat>(newListItem.format, listItem.format, ListFormats);\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"]}
@@ -3,11 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PastePlugin = void 0;
4
4
  var tslib_1 = require("tslib");
5
5
  var addParser_1 = require("./utils/addParser");
6
- var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
6
+ var blockElementParser_1 = require("./parsers/blockElementParser");
7
7
  var chainSanitizerCallback_1 = require("./utils/chainSanitizerCallback");
8
8
  var DefaultSanitizers_1 = require("./DefaultSanitizers");
9
9
  var deprecatedColorParser_1 = require("./parsers/deprecatedColorParser");
10
+ var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
10
11
  var getPasteSource_1 = require("./pasteSourceValidations/getPasteSource");
12
+ var imageSizeParser_1 = require("./parsers/imageSizeParser");
11
13
  var linkParser_1 = require("./parsers/linkParser");
12
14
  var pasteButtonProcessor_1 = require("./processors/pasteButtonProcessor");
13
15
  var constants_1 = require("./pasteSourceValidations/constants");
@@ -17,6 +19,7 @@ var processPastedContentFromPowerPoint_1 = require("./PowerPoint/processPastedCo
17
19
  var processPastedContentFromWordDesktop_1 = require("./WordDesktop/processPastedContentFromWordDesktop");
18
20
  var processPastedContentWacComponents_1 = require("./WacComponents/processPastedContentWacComponents");
19
21
  var setProcessor_1 = require("./utils/setProcessor");
22
+ var tableBorderParser_1 = require("./parsers/tableBorderParser");
20
23
  /**
21
24
  * Paste plugin, handles BeforePaste event and reformat some special content, including:
22
25
  * 1. Content copied from Word
@@ -106,12 +109,13 @@ var PastePlugin = /** @class */ (function () {
106
109
  }
107
110
  (0, addParser_1.addParser)(event.domToModelOption, 'link', linkParser_1.parseLink);
108
111
  (0, addParser_1.addParser)(event.domToModelOption, 'tableCell', deprecatedColorParser_1.deprecatedBorderColorParser);
109
- (0, addParser_1.addParser)(event.domToModelOption, 'tableCell', tableBorderParser);
112
+ (0, addParser_1.addParser)(event.domToModelOption, 'tableCell', tableBorderParser_1.tableBorderParser);
110
113
  (0, addParser_1.addParser)(event.domToModelOption, 'table', deprecatedColorParser_1.deprecatedBorderColorParser);
114
+ (0, addParser_1.addParser)(event.domToModelOption, 'image', imageSizeParser_1.imageSizeParser);
111
115
  (0, setProcessor_1.setProcessor)(event.domToModelOption, 'button', pasteButtonProcessor_1.pasteButtonProcessor);
112
116
  if (pasteType === 'mergeFormat') {
113
- (0, addParser_1.addParser)(event.domToModelOption, 'block', blockElementParser);
114
- (0, addParser_1.addParser)(event.domToModelOption, 'listLevel', blockElementParser);
117
+ (0, addParser_1.addParser)(event.domToModelOption, 'block', blockElementParser_1.blockElementParser);
118
+ (0, addParser_1.addParser)(event.domToModelOption, 'listLevel', blockElementParser_1.blockElementParser);
115
119
  }
116
120
  this.setEventSanitizers(event);
117
121
  };
@@ -132,32 +136,4 @@ var PastePlugin = /** @class */ (function () {
132
136
  return PastePlugin;
133
137
  }());
134
138
  exports.PastePlugin = PastePlugin;
135
- /**
136
- * For block elements that have background color style, remove the background color when user selects the merge current format
137
- * paste option
138
- */
139
- var blockElementParser = function (format, element) {
140
- if (element.style.backgroundColor) {
141
- delete format.backgroundColor;
142
- }
143
- };
144
- var ElementBorderKeys = new Map([
145
- ['borderTop', { w: 'borderTopWidth', s: 'borderTopStyle', c: 'borderTopColor' }],
146
- ['borderRight', { w: 'borderRightWidth', s: 'borderRightStyle', c: 'borderRightColor' }],
147
- ['borderBottom', { w: 'borderBottomWidth', s: 'borderBottomStyle', c: 'borderBottomColor' }],
148
- ['borderLeft', { w: 'borderLeftWidth', s: 'borderLeftStyle', c: 'borderLeftColor' }],
149
- ]);
150
- function tableBorderParser(format, element) {
151
- roosterjs_content_model_dom_1.BorderKeys.forEach(function (key) {
152
- if (!format[key]) {
153
- var styleSet = ElementBorderKeys.get(key);
154
- if (styleSet &&
155
- element.style[styleSet.w] &&
156
- element.style[styleSet.s] &&
157
- !element.style[styleSet.c]) {
158
- format[key] = element.style[styleSet.w] + " " + element.style[styleSet.s];
159
- }
160
- }
161
- });
162
- }
163
139
  //# sourceMappingURL=PastePlugin.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PastePlugin.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/paste/PastePlugin.ts"],"names":[],"mappings":";;;;AAAA,+CAA8C;AAC9C,2EAAwE;AACxE,yEAAwE;AACxE,yDAAwD;AACxD,yEAA8E;AAC9E,0EAAyE;AACzE,mDAAiD;AACjD,0EAAyE;AACzE,gEAAwE;AACxE,uFAAsF;AACtF,6FAA4F;AAC5F,sGAAqG;AACrG,yGAAwG;AACxG,uGAAsG;AACtG,qDAAoD;AAapD;;;;;;GAMG;AACH;IAGI;;;;OAIG;IACH,qBACY,uBAAiC,EACjC,uBAWP;QAXO,wCAAA,EAAA;YAOJ,eAAe,EAAE,qCAAiB;YAClC,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,EAAE,CAAC;IACxF,CAAC,cAAc,EAAE,EAAE,CAAC,EAAE,mBAAmB,EAAE,CAAC,EAAE,mBAAmB,EAAE,CAAC,EAAE,mBAAmB,EAAE,CAAC;IAC5F,CAAC,YAAY,EAAE,EAAE,CAAC,EAAE,iBAAiB,EAAE,CAAC,EAAE,iBAAiB,EAAE,CAAC,EAAE,iBAAiB,EAAE,CAAC;CACvF,CAAC,CAAC;AAEH,SAAS,iBAAiB,CAAC,MAAmC,EAAE,OAAoB;IAChF,wCAAU,CAAC,OAAO,CAAC,UAAA,GAAG;QAClB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE;YACd,IAAM,QAAQ,GAAG,iBAAiB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAC5C,IACI,QAAQ;gBACR,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;gBACzB,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;gBACzB,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,EAC5B;gBACE,MAAM,CAAC,GAAG,CAAC,GAAM,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAI,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAG,CAAC;aAC7E;SACJ;IACL,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["import { addParser } from './utils/addParser';\nimport { BorderKeys, getObjectKeys } from 'roosterjs-content-model-dom';\nimport { chainSanitizerCallback } from './utils/chainSanitizerCallback';\nimport { DefaultSanitizers } from './DefaultSanitizers';\nimport { deprecatedBorderColorParser } from './parsers/deprecatedColorParser';\nimport { getPasteSource } from './pasteSourceValidations/getPasteSource';\nimport { parseLink } from './parsers/linkParser';\nimport { pasteButtonProcessor } from './processors/pasteButtonProcessor';\nimport { PastePropertyNames } from './pasteSourceValidations/constants';\nimport { processPastedContentFromExcel } from './Excel/processPastedContentFromExcel';\nimport { processPastedContentFromOneNote } from './oneNote/processPastedContentFromOneNote';\nimport { processPastedContentFromPowerPoint } from './PowerPoint/processPastedContentFromPowerPoint';\nimport { processPastedContentFromWordDesktop } from './WordDesktop/processPastedContentFromWordDesktop';\nimport { processPastedContentWacComponents } from './WacComponents/processPastedContentWacComponents';\nimport { setProcessor } from './utils/setProcessor';\nimport type {\n BeforePasteEvent,\n BorderFormat,\n ContentModelBlockFormat,\n ContentModelTableCellFormat,\n DomToModelOptionForSanitizing,\n EditorPlugin,\n FormatParser,\n IEditor,\n PluginEvent,\n} from 'roosterjs-content-model-types';\n\n/**\n * Paste plugin, handles BeforePaste event and reformat some special content, including:\n * 1. Content copied from Word\n * 2. Content copied from Excel\n * 3. Content copied from Word Online or OneNote Online\n * 4. Content copied from Power Point\n */\nexport class PastePlugin implements EditorPlugin {\n private editor: IEditor | null = null;\n\n /**\n * Construct a new instance of Paste class\n * @param unknownTagReplacement Replace solution of unknown tags, default behavior is to replace with SPAN\n * @param allowExcelNoBorderTable Allow table copied from Excel without border\n */\n constructor(\n private allowExcelNoBorderTable?: boolean,\n private domToModelForSanitizing: Pick<\n DomToModelOptionForSanitizing,\n | 'additionalAllowedTags'\n | 'additionalDisallowedTags'\n | 'styleSanitizers'\n | 'attributeSanitizers'\n > = {\n styleSanitizers: DefaultSanitizers,\n additionalAllowedTags: [],\n additionalDisallowedTags: [],\n attributeSanitizers: {},\n }\n ) {}\n\n /**\n * Get name of this plugin\n */\n getName() {\n return 'Paste';\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 || event.eventType != 'beforePaste') {\n return;\n }\n\n if (!event.domToModelOption) {\n return;\n }\n\n const pasteSource = getPasteSource(\n event,\n false /* shouldConvertSingleImage */,\n this.editor.getEnvironment()\n );\n const pasteType = event.pasteType;\n\n switch (pasteSource) {\n case 'wordDesktop':\n processPastedContentFromWordDesktop(event);\n break;\n case 'wacComponents':\n processPastedContentWacComponents(event);\n break;\n case 'excelOnline':\n case 'excelDesktop':\n case 'excelNonNativeEvent':\n if (pasteType === 'normal' || pasteType === 'mergeFormat') {\n // Handle HTML copied from Excel\n processPastedContentFromExcel(\n event,\n this.editor.getDOMCreator(),\n !!this.allowExcelNoBorderTable,\n pasteSource != 'excelNonNativeEvent' /* isNativeEvent */\n );\n }\n break;\n case 'googleSheets':\n event.domToModelOption.additionalAllowedTags.push(\n PastePropertyNames.GOOGLE_SHEET_NODE_NAME as Lowercase<string>\n );\n break;\n case 'powerPointDesktop':\n processPastedContentFromPowerPoint(event, this.editor.getDOMCreator());\n break;\n\n case 'oneNoteDesktop':\n processPastedContentFromOneNote(event);\n break;\n }\n\n addParser(event.domToModelOption, 'link', parseLink);\n addParser(event.domToModelOption, 'tableCell', deprecatedBorderColorParser);\n addParser(event.domToModelOption, 'tableCell', tableBorderParser);\n addParser(event.domToModelOption, 'table', deprecatedBorderColorParser);\n setProcessor(event.domToModelOption, 'button', pasteButtonProcessor);\n\n if (pasteType === 'mergeFormat') {\n addParser(event.domToModelOption, 'block', blockElementParser);\n addParser(event.domToModelOption, 'listLevel', blockElementParser);\n }\n\n this.setEventSanitizers(event);\n }\n\n private setEventSanitizers(event: BeforePasteEvent) {\n if (this.domToModelForSanitizing) {\n const {\n styleSanitizers,\n attributeSanitizers,\n additionalAllowedTags,\n additionalDisallowedTags,\n } = this.domToModelForSanitizing;\n getObjectKeys(styleSanitizers).forEach(key =>\n chainSanitizerCallback(\n event.domToModelOption.styleSanitizers,\n key,\n styleSanitizers[key]\n )\n );\n getObjectKeys(attributeSanitizers).forEach(key =>\n chainSanitizerCallback(\n event.domToModelOption.attributeSanitizers,\n key,\n attributeSanitizers[key]\n )\n );\n event.domToModelOption.additionalAllowedTags.push(...additionalAllowedTags);\n event.domToModelOption.additionalDisallowedTags.push(...additionalDisallowedTags);\n }\n }\n}\n\n/**\n * For block elements that have background color style, remove the background color when user selects the merge current format\n * paste option\n */\nconst blockElementParser: FormatParser<ContentModelBlockFormat> = (\n format: ContentModelBlockFormat,\n element: HTMLElement\n) => {\n if (element.style.backgroundColor) {\n delete format.backgroundColor;\n }\n};\n\nconst ElementBorderKeys = new Map<\n keyof BorderFormat,\n {\n c: keyof CSSStyleDeclaration;\n s: keyof CSSStyleDeclaration;\n w: keyof CSSStyleDeclaration;\n }\n>([\n ['borderTop', { w: 'borderTopWidth', s: 'borderTopStyle', c: 'borderTopColor' }],\n ['borderRight', { w: 'borderRightWidth', s: 'borderRightStyle', c: 'borderRightColor' }],\n ['borderBottom', { w: 'borderBottomWidth', s: 'borderBottomStyle', c: 'borderBottomColor' }],\n ['borderLeft', { w: 'borderLeftWidth', s: 'borderLeftStyle', c: 'borderLeftColor' }],\n]);\n\nfunction tableBorderParser(format: ContentModelTableCellFormat, element: HTMLElement): void {\n BorderKeys.forEach(key => {\n if (!format[key]) {\n const styleSet = ElementBorderKeys.get(key);\n if (\n styleSet &&\n element.style[styleSet.w] &&\n element.style[styleSet.s] &&\n !element.style[styleSet.c]\n ) {\n format[key] = `${element.style[styleSet.w]} ${element.style[styleSet.s]}`;\n }\n }\n });\n}\n"]}
1
+ {"version":3,"file":"PastePlugin.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/paste/PastePlugin.ts"],"names":[],"mappings":";;;;AAAA,+CAA8C;AAC9C,mEAAkE;AAClE,yEAAwE;AACxE,yDAAwD;AACxD,yEAA8E;AAC9E,2EAA4D;AAC5D,0EAAy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C;QAErE,IAAI,SAAS,KAAK,aAAa,EAAE;YAC7B,IAAA,qBAAS,EAAC,KAAK,CAAC,gBAAgB,EAAE,OAAO,EAAE,uCAAkB,CAAC,CAAC;YAC/D,IAAA,qBAAS,EAAC,KAAK,CAAC,gBAAgB,EAAE,WAAW,EAAE,uCAAkB,CAAC,CAAC;SACtE;QAED,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC;IAEO,wCAAkB,GAA1B,UAA2B,KAAuB;;QAC9C,IAAI,IAAI,CAAC,uBAAuB,EAAE;YACxB,IAAA,KAKF,IAAI,CAAC,uBAAuB,EAJ5B,iBAAe,qBAAA,EACf,qBAAmB,yBAAA,EACnB,qBAAqB,2BAAA,EACrB,wBAAwB,8BACI,CAAC;YACjC,IAAA,2CAAa,EAAC,iBAAe,CAAC,CAAC,OAAO,CAAC,UAAA,GAAG;gBACtC,OAAA,IAAA,+CAAsB,EAClB,KAAK,CAAC,gBAAgB,CAAC,eAAe,EACtC,GAAG,EACH,iBAAe,CAAC,GAAG,CAAC,CACvB;YAJD,CAIC,CACJ,CAAC;YACF,IAAA,2CAAa,EAAC,qBAAmB,CAAC,CAAC,OAAO,CAAC,UAAA,GAAG;gBAC1C,OAAA,IAAA,+CAAsB,EAClB,KAAK,CAAC,gBAAgB,CAAC,mBAAmB,EAC1C,GAAG,EACH,qBAAmB,CAAC,GAAG,CAAC,CAC3B;YAJD,CAIC,CACJ,CAAC;YACF,CAAA,KAAA,KAAK,CAAC,gBAAgB,CAAC,qBAAqB,CAAA,CAAC,IAAI,8DAAI,qBAAqB,WAAE;YAC5E,CAAA,KAAA,KAAK,CAAC,gBAAgB,CAAC,wBAAwB,CAAA,CAAC,IAAI,8DAAI,wBAAwB,WAAE;SACrF;IACL,CAAC;IACL,kBAAC;AAAD,CAAC,AAnJD,IAmJC;AAnJY,kCAAW","sourcesContent":["import { addParser } from './utils/addParser';\nimport { blockElementParser } from './parsers/blockElementParser';\nimport { chainSanitizerCallback } from './utils/chainSanitizerCallback';\nimport { DefaultSanitizers } from './DefaultSanitizers';\nimport { deprecatedBorderColorParser } from './parsers/deprecatedColorParser';\nimport { getObjectKeys } from 'roosterjs-content-model-dom';\nimport { getPasteSource } from './pasteSourceValidations/getPasteSource';\nimport { imageSizeParser } from './parsers/imageSizeParser';\nimport { parseLink } from './parsers/linkParser';\nimport { pasteButtonProcessor } from './processors/pasteButtonProcessor';\nimport { PastePropertyNames } from './pasteSourceValidations/constants';\nimport { processPastedContentFromExcel } from './Excel/processPastedContentFromExcel';\nimport { processPastedContentFromOneNote } from './oneNote/processPastedContentFromOneNote';\nimport { processPastedContentFromPowerPoint } from './PowerPoint/processPastedContentFromPowerPoint';\nimport { processPastedContentFromWordDesktop } from './WordDesktop/processPastedContentFromWordDesktop';\nimport { processPastedContentWacComponents } from './WacComponents/processPastedContentWacComponents';\nimport { setProcessor } from './utils/setProcessor';\nimport { tableBorderParser } from './parsers/tableBorderParser';\nimport type {\n BeforePasteEvent,\n DomToModelOptionForSanitizing,\n EditorPlugin,\n IEditor,\n PluginEvent,\n} from 'roosterjs-content-model-types';\n\n/**\n * Paste plugin, handles BeforePaste event and reformat some special content, including:\n * 1. Content copied from Word\n * 2. Content copied from Excel\n * 3. Content copied from Word Online or OneNote Online\n * 4. Content copied from Power Point\n */\nexport class PastePlugin implements EditorPlugin {\n private editor: IEditor | null = null;\n\n /**\n * Construct a new instance of Paste class\n * @param unknownTagReplacement Replace solution of unknown tags, default behavior is to replace with SPAN\n * @param allowExcelNoBorderTable Allow table copied from Excel without border\n */\n constructor(\n private allowExcelNoBorderTable?: boolean,\n private domToModelForSanitizing: Pick<\n DomToModelOptionForSanitizing,\n | 'additionalAllowedTags'\n | 'additionalDisallowedTags'\n | 'styleSanitizers'\n | 'attributeSanitizers'\n > = {\n styleSanitizers: DefaultSanitizers,\n additionalAllowedTags: [],\n additionalDisallowedTags: [],\n attributeSanitizers: {},\n }\n ) {}\n\n /**\n * Get name of this plugin\n */\n getName() {\n return 'Paste';\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 || event.eventType != 'beforePaste') {\n return;\n }\n\n if (!event.domToModelOption) {\n return;\n }\n\n const pasteSource = getPasteSource(\n event,\n false /* shouldConvertSingleImage */,\n this.editor.getEnvironment()\n );\n const pasteType = event.pasteType;\n\n switch (pasteSource) {\n case 'wordDesktop':\n processPastedContentFromWordDesktop(event);\n break;\n case 'wacComponents':\n processPastedContentWacComponents(event);\n break;\n case 'excelOnline':\n case 'excelDesktop':\n case 'excelNonNativeEvent':\n if (pasteType === 'normal' || pasteType === 'mergeFormat') {\n // Handle HTML copied from Excel\n processPastedContentFromExcel(\n event,\n this.editor.getDOMCreator(),\n !!this.allowExcelNoBorderTable,\n pasteSource != 'excelNonNativeEvent' /* isNativeEvent */\n );\n }\n break;\n case 'googleSheets':\n event.domToModelOption.additionalAllowedTags.push(\n PastePropertyNames.GOOGLE_SHEET_NODE_NAME as Lowercase<string>\n );\n break;\n case 'powerPointDesktop':\n processPastedContentFromPowerPoint(event, this.editor.getDOMCreator());\n break;\n\n case 'oneNoteDesktop':\n processPastedContentFromOneNote(event);\n break;\n }\n\n addParser(event.domToModelOption, 'link', parseLink);\n addParser(event.domToModelOption, 'tableCell', deprecatedBorderColorParser);\n addParser(event.domToModelOption, 'tableCell', tableBorderParser);\n addParser(event.domToModelOption, 'table', deprecatedBorderColorParser);\n addParser(event.domToModelOption, 'image', imageSizeParser);\n setProcessor(event.domToModelOption, 'button', pasteButtonProcessor);\n\n if (pasteType === 'mergeFormat') {\n addParser(event.domToModelOption, 'block', blockElementParser);\n addParser(event.domToModelOption, 'listLevel', blockElementParser);\n }\n\n this.setEventSanitizers(event);\n }\n\n private setEventSanitizers(event: BeforePasteEvent) {\n if (this.domToModelForSanitizing) {\n const {\n styleSanitizers,\n attributeSanitizers,\n additionalAllowedTags,\n additionalDisallowedTags,\n } = this.domToModelForSanitizing;\n getObjectKeys(styleSanitizers).forEach(key =>\n chainSanitizerCallback(\n event.domToModelOption.styleSanitizers,\n key,\n styleSanitizers[key]\n )\n );\n getObjectKeys(attributeSanitizers).forEach(key =>\n chainSanitizerCallback(\n event.domToModelOption.attributeSanitizers,\n key,\n attributeSanitizers[key]\n )\n );\n event.domToModelOption.additionalAllowedTags.push(...additionalAllowedTags);\n event.domToModelOption.additionalDisallowedTags.push(...additionalDisallowedTags);\n }\n }\n}\n"]}
@@ -2,15 +2,15 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.processPastedContentFromWordDesktop = void 0;
4
4
  var addParser_1 = require("../utils/addParser");
5
+ var adjustPercentileLineHeightParser_1 = require("../parsers/adjustPercentileLineHeightParser");
5
6
  var getStyleMetadata_1 = require("./getStyleMetadata");
6
7
  var getStyles_1 = require("../utils/getStyles");
8
+ var listLevelParser_1 = require("../parsers/listLevelParser");
7
9
  var processWordComments_1 = require("./processWordComments");
8
10
  var processWordLists_1 = require("./processWordLists");
9
11
  var removeNegativeTextIndentParser_1 = require("../parsers/removeNegativeTextIndentParser");
10
12
  var setProcessor_1 = require("../utils/setProcessor");
11
- var PERCENTAGE_REGEX = /%/;
12
- // Default line height in browsers according to https://developer.mozilla.org/en-US/docs/Web/CSS/line-height#normal
13
- var DEFAULT_BROWSER_LINE_HEIGHT_PERCENTAGE = 1.2;
13
+ var wordTableParser_1 = require("../parsers/wordTableParser");
14
14
  /**
15
15
  * @internal
16
16
  * Handles Pasted content when source is Word Desktop
@@ -19,11 +19,11 @@ var DEFAULT_BROWSER_LINE_HEIGHT_PERCENTAGE = 1.2;
19
19
  function processPastedContentFromWordDesktop(ev) {
20
20
  var metadataMap = (0, getStyleMetadata_1.getStyleMetadata)(ev);
21
21
  (0, setProcessor_1.setProcessor)(ev.domToModelOption, 'element', wordDesktopElementProcessor(metadataMap));
22
- (0, addParser_1.addParser)(ev.domToModelOption, 'block', adjustPercentileLineHeight);
22
+ (0, addParser_1.addParser)(ev.domToModelOption, 'block', adjustPercentileLineHeightParser_1.adjustPercentileLineHeight);
23
23
  (0, addParser_1.addParser)(ev.domToModelOption, 'block', removeNegativeTextIndentParser_1.removeNegativeTextIndentParser);
24
- (0, addParser_1.addParser)(ev.domToModelOption, 'listLevel', listLevelParser);
25
- (0, addParser_1.addParser)(ev.domToModelOption, 'container', wordTableParser);
26
- (0, addParser_1.addParser)(ev.domToModelOption, 'table', wordTableParser);
24
+ (0, addParser_1.addParser)(ev.domToModelOption, 'listLevel', listLevelParser_1.listLevelParser);
25
+ (0, addParser_1.addParser)(ev.domToModelOption, 'container', wordTableParser_1.wordTableParser);
26
+ (0, addParser_1.addParser)(ev.domToModelOption, 'table', wordTableParser_1.wordTableParser);
27
27
  }
28
28
  exports.processPastedContentFromWordDesktop = processPastedContentFromWordDesktop;
29
29
  var wordDesktopElementProcessor = function (metadataKey) {
@@ -36,28 +36,4 @@ var wordDesktopElementProcessor = function (metadataKey) {
36
36
  }
37
37
  };
38
38
  };
39
- function adjustPercentileLineHeight(format, element) {
40
- //If the line height is less than the browser default line height, line between the text is going to be too narrow
41
- var parsedLineHeight;
42
- if (PERCENTAGE_REGEX.test(element.style.lineHeight) &&
43
- !isNaN((parsedLineHeight = parseInt(element.style.lineHeight)))) {
44
- format.lineHeight = (DEFAULT_BROWSER_LINE_HEIGHT_PERCENTAGE *
45
- (parsedLineHeight / 100)).toString();
46
- }
47
- }
48
- var listLevelParser = function (format, element, _context, defaultStyle) {
49
- if (element.style.marginLeft != '') {
50
- format.marginLeft = defaultStyle.marginLeft;
51
- }
52
- format.marginBottom = undefined;
53
- };
54
- var wordTableParser = function (format, element) {
55
- var _a;
56
- if ((_a = format.marginLeft) === null || _a === void 0 ? void 0 : _a.startsWith('-')) {
57
- delete format.marginLeft;
58
- }
59
- if (format.htmlAlign) {
60
- delete format.htmlAlign;
61
- }
62
- };
63
39
  //# sourceMappingURL=processPastedContentFromWordDesktop.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"processPastedContentFromWordDesktop.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/paste/WordDesktop/processPastedContentFromWordDesktop.ts"],"names":[],"mappings":";;;AAAA,gDAA+C;AAC/C,uDAAsD;AACtD,gDAA+C;AAC/C,6DAA4D;AAC5D,uDAAqD;AACrD,4FAA2F;AAC3F,sDAAqD;AAYrD,IAAM,gBAAgB,GAAG,GAAG,CAAC;AAC7B,mHAAmH;AACnH,IAAM,sCAAsC,GAAG,GAAG,CAAC;AAEnD;;;;GAIG;AACH,SAAgB,mCAAmC,CAAC,EAAoB;IACpE,IAAM,WAAW,GAA8B,IAAA,mCAAgB,EAAC,EAAE,CAAC,CAAC;IAEpE,IAAA,2BAAY,EAAC,EAAE,CAAC,gBAAgB,EAAE,SAAS,EAAE,2BAA2B,CAAC,WAAW,CAAC,CAAC,CAAC;IACvF,IAAA,qBAAS,EAAC,EAAE,CAAC,gBAAgB,EAAE,OAAO,EAAE,0BAA0B,CAAC,CAAC;IACpE,IAAA,qBAAS,EAAC,EAAE,CAAC,gBAAgB,EAAE,OAAO,EAAE,+DAA8B,CAAC,CAAC;IACxE,IAAA,qBAAS,EAAC,EAAE,CAAC,gBAAgB,EAAE,WAAW,EAAE,eAAe,CAAC,CAAC;IAC7D,IAAA,qBAAS,EAAC,EAAE,CAAC,gBAAgB,EAAE,WAAW,EAAE,eAAe,CAAC,CAAC;IAC7D,IAAA,qBAAS,EAAC,EAAE,CAAC,gBAA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O;;IAC3E,IAAI,MAAA,MAAM,CAAC,UAAU,0CAAE,UAAU,CAAC,GAAG,CAAC,EAAE;QACpC,OAAO,MAAM,CAAC,UAAU,CAAC;KAC5B;IACD,IAAI,MAAM,CAAC,SAAS,EAAE;QAClB,OAAO,MAAM,CAAC,SAAS,CAAC;KAC3B;AACL,CAAC,CAAC","sourcesContent":["import { addParser } from '../utils/addParser';\nimport { getStyleMetadata } from './getStyleMetadata';\nimport { getStyles } from '../utils/getStyles';\nimport { processWordComments } from './processWordComments';\nimport { processWordList } from './processWordLists';\nimport { removeNegativeTextIndentParser } from '../parsers/removeNegativeTextIndentParser';\nimport { setProcessor } from '../utils/setProcessor';\nimport type { WordMetadata } from './WordMetadata';\nimport type {\n BeforePasteEvent,\n ContentModelBlockFormat,\n ContentModelListItemLevelFormat,\n ContentModelTableFormat,\n DomToModelContext,\n ElementProcessor,\n FormatParser,\n} from 'roosterjs-content-model-types';\n\nconst PERCENTAGE_REGEX = /%/;\n// Default line height in browsers according to https://developer.mozilla.org/en-US/docs/Web/CSS/line-height#normal\nconst DEFAULT_BROWSER_LINE_HEIGHT_PERCENTAGE = 1.2;\n\n/**\n * @internal\n * Handles Pasted content when source is Word Desktop\n * @param ev BeforePasteEvent\n */\nexport function processPastedContentFromWordDesktop(ev: BeforePasteEvent) {\n const metadataMap: Map<string, WordMetadata> = getStyleMetadata(ev);\n\n setProcessor(ev.domToModelOption, 'element', wordDesktopElementProcessor(metadataMap));\n addParser(ev.domToModelOption, 'block', adjustPercentileLineHeight);\n addParser(ev.domToModelOption, 'block', removeNegativeTextIndentParser);\n addParser(ev.domToModelOption, 'listLevel', listLevelParser);\n addParser(ev.domToModelOption, 'container', wordTableParser);\n addParser(ev.domToModelOption, 'table', wordTableParser);\n}\n\nconst wordDesktopElementProcessor = (\n metadataKey: Map<string, WordMetadata>\n): ElementProcessor<HTMLElement> => {\n return (group, element, context) => {\n const styles = getStyles(element);\n // Process Word Lists or Word Commands, otherwise use the default processor on this element.\n if (\n !(\n processWordList(styles, group, element, context, metadataKey) ||\n processWordComments(styles, element)\n )\n ) {\n context.defaultElementProcessors.element(group, element, context);\n }\n };\n};\n\nfunction adjustPercentileLineHeight(format: ContentModelBlockFormat, element: HTMLElement): void {\n //If the line height is less than the browser default line height, line between the text is going to be too narrow\n let parsedLineHeight: number;\n if (\n PERCENTAGE_REGEX.test(element.style.lineHeight) &&\n !isNaN((parsedLineHeight = parseInt(element.style.lineHeight)))\n ) {\n format.lineHeight = (\n DEFAULT_BROWSER_LINE_HEIGHT_PERCENTAGE *\n (parsedLineHeight / 100)\n ).toString();\n }\n}\n\nconst listLevelParser: FormatParser<ContentModelListItemLevelFormat> = (\n format: ContentModelListItemLevelFormat,\n element: HTMLElement,\n _context: DomToModelContext,\n defaultStyle: Readonly<Partial<CSSStyleDeclaration>>\n) => {\n if (element.style.marginLeft != '') {\n format.marginLeft = defaultStyle.marginLeft;\n }\n\n format.marginBottom = undefined;\n};\n\nconst wordTableParser: FormatParser<ContentModelTableFormat> = (format, element): void => {\n if (format.marginLeft?.startsWith('-')) {\n delete format.marginLeft;\n }\n if (format.htmlAlign) {\n delete format.htmlAlign;\n }\n};\n"]}
1
+ {"version":3,"file":"processPastedContentFromWordDesktop.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/paste/WordDesktop/processPastedContentFromWordDesktop.ts"],"names":[],"mappings":";;;AAAA,gDAA+C;AAC/C,gGAAyF;AACzF,uDAAsD;AACtD,gDAA+C;AAC/C,8DAA6D;AAC7D,6DAA4D;AAC5D,uDAAqD;AACrD,4FAA2F;AAC3F,sDAAqD;AACrD,8DAA6D;AAI7D;;;;GAIG;AACH,SAAgB,mCAAmC,CAAC,EAAoB;IACpE,IAAM,WAAW,GAA8B,IAAA,mCAAgB,EAAC,EAAE,CAAC,CAAC;IAEpE,IAAA,2BAAY,EAAC,EAAE,CAAC,gBAAgB,EAAE,SAAS,EAAE,2BAA2B,CAAC,WAAW,CAAC,CAAC,CAAC;IACvF,IAAA,qBAAS,EAAC,EAAE,CAAC,gBAAgB,EAAE,OAAO,EAAE,6DAA0B,CAAC,CAAC;IACpE,IAAA,qBAAS,EAAC,EAAE,CAAC,gBAAgB,EAAE,OAAO,EAAE,+DAA8B,CAAC,CAAC;IACxE,IAAA,qBAAS,EAAC,EAAE,CAAC,gBAAgB,EAAE,WAAW,EAAE,iCAAe,CAAC,CAAC;IAC7D,IAAA,qBAAS,EAAC,EAAE,CAAC,gBAAgB,EAAE,WAAW,EAAE,iCAAe,CAAC,CAAC;IAC7D,IAAA,qBAAS,EAAC,EAAE,CAAC,gBAAgB,EAAE,OAAO,EAAE,iCAAe,CAAC,CAAC;AAC7D,CAAC;AATD,kFASC;AAED,IAAM,2BAA2B,GAAG,UAChC,WAAsC;IAEtC,OAAO,UAAC,KAAK,EAAE,OAAO,EAAE,OAAO;QAC3B,IAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,OAAO,CAAC,CAAC;QAClC,4FAA4F;QAC5F,IACI,CAAC,CACG,IAAA,kCAAe,EAAC,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,CAAC;YAC7D,IAAA,yCAAmB,EAAC,MAAM,EAAE,OAAO,CAAC,CACvC,EACH;YACE,OAAO,CAAC,wBAAwB,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;SACrE;IACL,CAAC,CAAC;AACN,CAAC,CAAC","sourcesContent":["import { addParser } from '../utils/addParser';\nimport { adjustPercentileLineHeight } from '../parsers/adjustPercentileLineHeightParser';\nimport { getStyleMetadata } from './getStyleMetadata';\nimport { getStyles } from '../utils/getStyles';\nimport { listLevelParser } from '../parsers/listLevelParser';\nimport { processWordComments } from './processWordComments';\nimport { processWordList } from './processWordLists';\nimport { removeNegativeTextIndentParser } from '../parsers/removeNegativeTextIndentParser';\nimport { setProcessor } from '../utils/setProcessor';\nimport { wordTableParser } from '../parsers/wordTableParser';\nimport type { WordMetadata } from './WordMetadata';\nimport type { BeforePasteEvent, ElementProcessor } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n * Handles Pasted content when source is Word Desktop\n * @param ev BeforePasteEvent\n */\nexport function processPastedContentFromWordDesktop(ev: BeforePasteEvent) {\n const metadataMap: Map<string, WordMetadata> = getStyleMetadata(ev);\n\n setProcessor(ev.domToModelOption, 'element', wordDesktopElementProcessor(metadataMap));\n addParser(ev.domToModelOption, 'block', adjustPercentileLineHeight);\n addParser(ev.domToModelOption, 'block', removeNegativeTextIndentParser);\n addParser(ev.domToModelOption, 'listLevel', listLevelParser);\n addParser(ev.domToModelOption, 'container', wordTableParser);\n addParser(ev.domToModelOption, 'table', wordTableParser);\n}\n\nconst wordDesktopElementProcessor = (\n metadataKey: Map<string, WordMetadata>\n): ElementProcessor<HTMLElement> => {\n return (group, element, context) => {\n const styles = getStyles(element);\n // Process Word Lists or Word Commands, otherwise use the default processor on this element.\n if (\n !(\n processWordList(styles, group, element, context, metadataKey) ||\n processWordComments(styles, element)\n )\n ) {\n context.defaultElementProcessors.element(group, element, context);\n }\n };\n};\n"]}
@@ -0,0 +1,8 @@
1
+ import type { ContentModelBlockFormat } from 'roosterjs-content-model-types';
2
+ /**
3
+ * @internal
4
+ * Parser for adjusting percentage-based line heights and converting 'normal' to a specific percentage
5
+ * @param format The block format to modify
6
+ * @param element The HTML element being processed
7
+ */
8
+ export declare function adjustPercentileLineHeight(format: ContentModelBlockFormat, element: HTMLElement): void;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.adjustPercentileLineHeight = void 0;
4
+ var PERCENTAGE_REGEX = /%/;
5
+ // Default line height in browsers according to https://developer.mozilla.org/en-US/docs/Web/CSS/line-height#normal
6
+ var DEFAULT_BROWSER_LINE_HEIGHT_PERCENTAGE = 1.2;
7
+ /**
8
+ * @internal
9
+ * Parser for adjusting percentage-based line heights and converting 'normal' to a specific percentage
10
+ * @param format The block format to modify
11
+ * @param element The HTML element being processed
12
+ */
13
+ function adjustPercentileLineHeight(format, element) {
14
+ // If the line height is less than the browser default line height, line between the text is going to be too narrow
15
+ var parsedLineHeight;
16
+ if (PERCENTAGE_REGEX.test(element.style.lineHeight) &&
17
+ !isNaN((parsedLineHeight = parseInt(element.style.lineHeight)))) {
18
+ format.lineHeight = (DEFAULT_BROWSER_LINE_HEIGHT_PERCENTAGE *
19
+ (parsedLineHeight / 100)).toString();
20
+ }
21
+ else if (element.style.lineHeight.toLowerCase() === 'normal') {
22
+ format.lineHeight = '120%';
23
+ }
24
+ }
25
+ exports.adjustPercentileLineHeight = adjustPercentileLineHeight;
26
+ //# sourceMappingURL=adjustPercentileLineHeightParser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adjustPercentileLineHeightParser.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/paste/parsers/adjustPercentileLineHeightParser.ts"],"names":[],"mappings":";;;AAEA,IAAM,gBAAgB,GAAG,GAAG,CAAC;AAC7B,mHAAmH;AACnH,IAAM,sCAAsC,GAAG,GAAG,CAAC;AAEnD;;;;;GAKG;AACH,SAAgB,0BAA0B,CACtC,MAA+B,EAC/B,OAAoB;IAEpB,mHAAmH;IACnH,IAAI,gBAAwB,CAAC;IAC7B,IACI,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC;QAC/C,CAAC,KAAK,CAAC,CAAC,gBAAgB,GAAG,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,EACjE;QACE,MAAM,CAAC,UAAU,GAAG,CAChB,sCAAsC;YACtC,CAAC,gBAAgB,GAAG,GAAG,CAAC,CAC3B,CAAC,QAAQ,EAAE,CAAC;KAChB;SAAM,IAAI,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,WAAW,EAAE,KAAK,QAAQ,EAAE;QAC5D,MAAM,CAAC,UAAU,GAAG,MAAM,CAAC;KAC9B;AACL,CAAC;AAjBD,gEAiBC","sourcesContent":["import type { ContentModelBlockFormat } from 'roosterjs-content-model-types';\n\nconst PERCENTAGE_REGEX = /%/;\n// Default line height in browsers according to https://developer.mozilla.org/en-US/docs/Web/CSS/line-height#normal\nconst DEFAULT_BROWSER_LINE_HEIGHT_PERCENTAGE = 1.2;\n\n/**\n * @internal\n * Parser for adjusting percentage-based line heights and converting 'normal' to a specific percentage\n * @param format The block format to modify\n * @param element The HTML element being processed\n */\nexport function adjustPercentileLineHeight(\n format: ContentModelBlockFormat,\n element: HTMLElement\n): void {\n // If the line height is less than the browser default line height, line between the text is going to be too narrow\n let parsedLineHeight: number;\n if (\n PERCENTAGE_REGEX.test(element.style.lineHeight) &&\n !isNaN((parsedLineHeight = parseInt(element.style.lineHeight)))\n ) {\n format.lineHeight = (\n DEFAULT_BROWSER_LINE_HEIGHT_PERCENTAGE *\n (parsedLineHeight / 100)\n ).toString();\n } else if (element.style.lineHeight.toLowerCase() === 'normal') {\n format.lineHeight = '120%';\n }\n}\n"]}
@@ -0,0 +1,7 @@
1
+ import type { ContentModelBlockFormat, FormatParser } from 'roosterjs-content-model-types';
2
+ /**
3
+ * @internal
4
+ * For block elements that have background color style, remove the background color when user selects the merge current format
5
+ * paste option
6
+ */
7
+ export declare const blockElementParser: FormatParser<ContentModelBlockFormat>;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.blockElementParser = void 0;
4
+ /**
5
+ * @internal
6
+ * For block elements that have background color style, remove the background color when user selects the merge current format
7
+ * paste option
8
+ */
9
+ var blockElementParser = function (format, element) {
10
+ if (element.style.backgroundColor) {
11
+ delete format.backgroundColor;
12
+ }
13
+ };
14
+ exports.blockElementParser = blockElementParser;
15
+ //# sourceMappingURL=blockElementParser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"blockElementParser.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/paste/parsers/blockElementParser.ts"],"names":[],"mappings":";;;AAEA;;;;GAIG;AACI,IAAM,kBAAkB,GAA0C,UACrE,MAA+B,EAC/B,OAAoB;IAEpB,IAAI,OAAO,CAAC,KAAK,CAAC,eAAe,EAAE;QAC/B,OAAO,MAAM,CAAC,eAAe,CAAC;KACjC;AACL,CAAC,CAAC;AAPW,QAAA,kBAAkB,sBAO7B","sourcesContent":["import type { ContentModelBlockFormat, FormatParser } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n * For block elements that have background color style, remove the background color when user selects the merge current format\n * paste option\n */\nexport const blockElementParser: FormatParser<ContentModelBlockFormat> = (\n format: ContentModelBlockFormat,\n element: HTMLElement\n) => {\n if (element.style.backgroundColor) {\n delete format.backgroundColor;\n }\n};\n"]}
@@ -0,0 +1,6 @@
1
+ import type { ContentModelImageFormat, FormatParser } from 'roosterjs-content-model-types';
2
+ /**
3
+ * @internal
4
+ * Remove image size if it is larger than editor view width to let it auto size
5
+ */
6
+ export declare const imageSizeParser: FormatParser<ContentModelImageFormat>;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.imageSizeParser = void 0;
4
+ var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
5
+ // Only process absolute units (px, pt, in, cm, mm)
6
+ var AbsoluteUnitRegex = /^\s*\d+(\.\d+)?\s*(px|pt|in|cm|mm)\s*$/i;
7
+ /**
8
+ * @internal
9
+ * Remove image size if it is larger than editor view width to let it auto size
10
+ */
11
+ var imageSizeParser = function (format, element, context) {
12
+ var maxImageSize = context.editorViewWidth;
13
+ var width = format.width;
14
+ if (width && maxImageSize && AbsoluteUnitRegex.test(width)) {
15
+ var widthValue = (0, roosterjs_content_model_dom_1.parseValueWithUnit)(width, element);
16
+ // If the given width is larger than editor view width, we clear both width and height to let it auto size
17
+ if (widthValue > maxImageSize) {
18
+ delete format.width;
19
+ delete format.height;
20
+ }
21
+ }
22
+ };
23
+ exports.imageSizeParser = imageSizeParser;
24
+ //# sourceMappingURL=imageSizeParser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"imageSizeParser.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/paste/parsers/imageSizeParser.ts"],"names":[],"mappings":";;;AAAA,2EAAiE;AAGjE,mDAAmD;AACnD,IAAM,iBAAiB,GAAG,yCAAyC,CAAC;AAEpE;;;GAGG;AACI,IAAM,eAAe,GAA0C,UAClE,MAAM,EACN,OAAO,EACP,OAAO;IAEP,IAAM,YAAY,GAAG,OAAO,CAAC,eAAe,CAAC;IACrC,IAAA,KAAK,GAAK,MAAM,MAAX,CAAY;IAEzB,IAAI,KAAK,IAAI,YAAY,IAAI,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;QACxD,IAAM,UAAU,GAAG,IAAA,gDAAkB,EAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAEtD,0GAA0G;QAC1G,IAAI,UAAU,GAAG,YAAY,EAAE;YAC3B,OAAO,MAAM,CAAC,KAAK,CAAC;YACpB,OAAO,MAAM,CAAC,MAAM,CAAC;SACxB;KACJ;AACL,CAAC,CAAC;AAjBW,QAAA,eAAe,mBAiB1B","sourcesContent":["import { parseValueWithUnit } from 'roosterjs-content-model-dom';\nimport type { ContentModelImageFormat, FormatParser } from 'roosterjs-content-model-types';\n\n// Only process absolute units (px, pt, in, cm, mm)\nconst AbsoluteUnitRegex = /^\\s*\\d+(\\.\\d+)?\\s*(px|pt|in|cm|mm)\\s*$/i;\n\n/**\n * @internal\n * Remove image size if it is larger than editor view width to let it auto size\n */\nexport const imageSizeParser: FormatParser<ContentModelImageFormat> = (\n format,\n element,\n context\n) => {\n const maxImageSize = context.editorViewWidth;\n const { width } = format;\n\n if (width && maxImageSize && AbsoluteUnitRegex.test(width)) {\n const widthValue = parseValueWithUnit(width, element);\n\n // If the given width is larger than editor view width, we clear both width and height to let it auto size\n if (widthValue > maxImageSize) {\n delete format.width;\n delete format.height;\n }\n }\n};\n"]}
@@ -0,0 +1,10 @@
1
+ import type { ContentModelListItemLevelFormat, FormatParser } from 'roosterjs-content-model-types';
2
+ /**
3
+ * @internal
4
+ * Parser for processing list level formatting specific to Word Desktop
5
+ * @param format The list item level format to modify
6
+ * @param element The HTML element being processed
7
+ * @param _context The DOM to model context
8
+ * @param defaultStyle The default style properties
9
+ */
10
+ export declare const listLevelParser: FormatParser<ContentModelListItemLevelFormat>;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.listLevelParser = void 0;
4
+ /**
5
+ * @internal
6
+ * Parser for processing list level formatting specific to Word Desktop
7
+ * @param format The list item level format to modify
8
+ * @param element The HTML element being processed
9
+ * @param _context The DOM to model context
10
+ * @param defaultStyle The default style properties
11
+ */
12
+ var listLevelParser = function (format, element, _context, defaultStyle) {
13
+ if (element.style.marginLeft !== '') {
14
+ format.marginLeft = defaultStyle.marginLeft;
15
+ }
16
+ format.marginBottom = undefined;
17
+ };
18
+ exports.listLevelParser = listLevelParser;
19
+ //# sourceMappingURL=listLevelParser.js.map