roosterjs-content-model-plugins 9.1.0 → 9.2.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 (235) hide show
  1. package/lib/autoFormat/AutoFormatPlugin.d.ts +15 -5
  2. package/lib/autoFormat/AutoFormatPlugin.js +41 -4
  3. package/lib/autoFormat/AutoFormatPlugin.js.map +1 -1
  4. package/lib/autoFormat/link/createLink.js +2 -0
  5. package/lib/autoFormat/link/createLink.js.map +1 -1
  6. package/lib/autoFormat/list/keyboardListTrigger.js +7 -9
  7. package/lib/autoFormat/list/keyboardListTrigger.js.map +1 -1
  8. package/lib/autoFormat/numbers/transformFraction.d.ts +5 -0
  9. package/lib/autoFormat/numbers/transformFraction.js +27 -0
  10. package/lib/autoFormat/numbers/transformFraction.js.map +1 -0
  11. package/lib/autoFormat/numbers/transformOrdinals.d.ts +5 -0
  12. package/lib/autoFormat/numbers/transformOrdinals.js +32 -0
  13. package/lib/autoFormat/numbers/transformOrdinals.js.map +1 -0
  14. package/lib/customReplace/CustomReplacePlugin.d.ts +61 -0
  15. package/lib/customReplace/CustomReplacePlugin.js +87 -0
  16. package/lib/customReplace/CustomReplacePlugin.js.map +1 -0
  17. package/lib/edit/EditPlugin.js +19 -1
  18. package/lib/edit/EditPlugin.js.map +1 -1
  19. package/lib/edit/inputSteps/handleEnterOnList.js +8 -1
  20. package/lib/edit/inputSteps/handleEnterOnList.js.map +1 -1
  21. package/lib/edit/keyboardTab.js +5 -5
  22. package/lib/edit/keyboardTab.js.map +1 -1
  23. package/lib/edit/tabUtils/handleTabOnList.d.ts +2 -2
  24. package/lib/edit/tabUtils/handleTabOnList.js +3 -3
  25. package/lib/edit/tabUtils/handleTabOnList.js.map +1 -1
  26. package/lib/edit/tabUtils/handleTabOnParagraph.d.ts +2 -2
  27. package/lib/edit/tabUtils/handleTabOnParagraph.js +2 -2
  28. package/lib/edit/tabUtils/handleTabOnParagraph.js.map +1 -1
  29. package/lib/index.d.ts +7 -1
  30. package/lib/index.js +8 -1
  31. package/lib/index.js.map +1 -1
  32. package/lib/markdown/utils/setFormat.js +11 -9
  33. package/lib/markdown/utils/setFormat.js.map +1 -1
  34. package/lib/picker/PickerHandler.d.ts +112 -0
  35. package/lib/picker/PickerHandler.js +3 -0
  36. package/lib/picker/PickerHandler.js.map +1 -0
  37. package/lib/picker/PickerHelper.d.ts +22 -0
  38. package/lib/picker/PickerHelper.js +3 -0
  39. package/lib/picker/PickerHelper.js.map +1 -0
  40. package/lib/picker/PickerHelperImpl.d.ts +25 -0
  41. package/lib/picker/PickerHelperImpl.js +54 -0
  42. package/lib/picker/PickerHelperImpl.js.map +1 -0
  43. package/lib/picker/PickerPlugin.d.ts +54 -0
  44. package/lib/picker/PickerPlugin.js +217 -0
  45. package/lib/picker/PickerPlugin.js.map +1 -0
  46. package/lib/picker/getQueryString.d.ts +5 -0
  47. package/lib/picker/getQueryString.js +36 -0
  48. package/lib/picker/getQueryString.js.map +1 -0
  49. package/lib/pluginUtils/Rect/getDOMInsertPointRect.d.ts +7 -0
  50. package/lib/pluginUtils/Rect/getDOMInsertPointRect.js +57 -0
  51. package/lib/pluginUtils/Rect/getDOMInsertPointRect.js.map +1 -0
  52. package/lib/shortcut/ShortcutPlugin.js +1 -0
  53. package/lib/shortcut/ShortcutPlugin.js.map +1 -1
  54. package/lib/shortcut/shortcuts.d.ts +7 -0
  55. package/lib/shortcut/shortcuts.js +15 -1
  56. package/lib/shortcut/shortcuts.js.map +1 -1
  57. package/lib/shortcut/utils/setShortcutIndentationCommand.js +2 -2
  58. package/lib/shortcut/utils/setShortcutIndentationCommand.js.map +1 -1
  59. package/lib/tableEdit/OnTableEditorCreatedCallback.d.ts +4 -0
  60. package/lib/tableEdit/OnTableEditorCreatedCallback.js +3 -0
  61. package/lib/tableEdit/OnTableEditorCreatedCallback.js.map +1 -0
  62. package/lib/tableEdit/TableEditPlugin.d.ts +4 -1
  63. package/lib/tableEdit/TableEditPlugin.js +5 -2
  64. package/lib/tableEdit/TableEditPlugin.js.map +1 -1
  65. package/lib/tableEdit/editors/TableEditor.d.ts +4 -1
  66. package/lib/tableEdit/editors/TableEditor.js +23 -7
  67. package/lib/tableEdit/editors/TableEditor.js.map +1 -1
  68. package/lib/tableEdit/editors/features/TableEditFeature.js +3 -3
  69. package/lib/tableEdit/editors/features/TableEditFeature.js.map +1 -1
  70. package/lib/tableEdit/editors/features/TableInserter.d.ts +2 -1
  71. package/lib/tableEdit/editors/features/TableInserter.js +7 -9
  72. package/lib/tableEdit/editors/features/TableInserter.js.map +1 -1
  73. package/lib/tableEdit/editors/features/TableMover.d.ts +2 -1
  74. package/lib/tableEdit/editors/features/TableMover.js +8 -11
  75. package/lib/tableEdit/editors/features/TableMover.js.map +1 -1
  76. package/lib/tableEdit/editors/features/TableResizer.d.ts +2 -1
  77. package/lib/tableEdit/editors/features/TableResizer.js +19 -3
  78. package/lib/tableEdit/editors/features/TableResizer.js.map +1 -1
  79. package/lib-amd/autoFormat/AutoFormatPlugin.d.ts +15 -5
  80. package/lib-amd/autoFormat/AutoFormatPlugin.js +39 -5
  81. package/lib-amd/autoFormat/AutoFormatPlugin.js.map +1 -1
  82. package/lib-amd/autoFormat/link/createLink.js +2 -0
  83. package/lib-amd/autoFormat/link/createLink.js.map +1 -1
  84. package/lib-amd/autoFormat/list/keyboardListTrigger.js +7 -9
  85. package/lib-amd/autoFormat/list/keyboardListTrigger.js.map +1 -1
  86. package/lib-amd/autoFormat/numbers/transformFraction.d.ts +5 -0
  87. package/lib-amd/autoFormat/numbers/transformFraction.js +28 -0
  88. package/lib-amd/autoFormat/numbers/transformFraction.js.map +1 -0
  89. package/lib-amd/autoFormat/numbers/transformOrdinals.d.ts +5 -0
  90. package/lib-amd/autoFormat/numbers/transformOrdinals.js +33 -0
  91. package/lib-amd/autoFormat/numbers/transformOrdinals.js.map +1 -0
  92. package/lib-amd/customReplace/CustomReplacePlugin.d.ts +61 -0
  93. package/lib-amd/customReplace/CustomReplacePlugin.js +88 -0
  94. package/lib-amd/customReplace/CustomReplacePlugin.js.map +1 -0
  95. package/lib-amd/edit/EditPlugin.js +19 -1
  96. package/lib-amd/edit/EditPlugin.js.map +1 -1
  97. package/lib-amd/edit/inputSteps/handleEnterOnList.js +8 -2
  98. package/lib-amd/edit/inputSteps/handleEnterOnList.js.map +1 -1
  99. package/lib-amd/edit/keyboardTab.js +5 -5
  100. package/lib-amd/edit/keyboardTab.js.map +1 -1
  101. package/lib-amd/edit/tabUtils/handleTabOnList.d.ts +2 -2
  102. package/lib-amd/edit/tabUtils/handleTabOnList.js +3 -3
  103. package/lib-amd/edit/tabUtils/handleTabOnList.js.map +1 -1
  104. package/lib-amd/edit/tabUtils/handleTabOnParagraph.d.ts +2 -2
  105. package/lib-amd/edit/tabUtils/handleTabOnParagraph.js +2 -2
  106. package/lib-amd/edit/tabUtils/handleTabOnParagraph.js.map +1 -1
  107. package/lib-amd/index.d.ts +7 -1
  108. package/lib-amd/index.js +6 -2
  109. package/lib-amd/index.js.map +1 -1
  110. package/lib-amd/markdown/utils/setFormat.js +11 -9
  111. package/lib-amd/markdown/utils/setFormat.js.map +1 -1
  112. package/lib-amd/picker/PickerHandler.d.ts +112 -0
  113. package/lib-amd/picker/PickerHandler.js +5 -0
  114. package/lib-amd/picker/PickerHandler.js.map +1 -0
  115. package/lib-amd/picker/PickerHelper.d.ts +22 -0
  116. package/lib-amd/picker/PickerHelper.js +5 -0
  117. package/lib-amd/picker/PickerHelper.js.map +1 -0
  118. package/lib-amd/picker/PickerHelperImpl.d.ts +25 -0
  119. package/lib-amd/picker/PickerHelperImpl.js +53 -0
  120. package/lib-amd/picker/PickerHelperImpl.js.map +1 -0
  121. package/lib-amd/picker/PickerPlugin.d.ts +54 -0
  122. package/lib-amd/picker/PickerPlugin.js +215 -0
  123. package/lib-amd/picker/PickerPlugin.js.map +1 -0
  124. package/lib-amd/picker/getQueryString.d.ts +5 -0
  125. package/lib-amd/picker/getQueryString.js +37 -0
  126. package/lib-amd/picker/getQueryString.js.map +1 -0
  127. package/lib-amd/pluginUtils/Rect/getDOMInsertPointRect.d.ts +7 -0
  128. package/lib-amd/pluginUtils/Rect/getDOMInsertPointRect.js +58 -0
  129. package/lib-amd/pluginUtils/Rect/getDOMInsertPointRect.js.map +1 -0
  130. package/lib-amd/shortcut/ShortcutPlugin.js +1 -0
  131. package/lib-amd/shortcut/ShortcutPlugin.js.map +1 -1
  132. package/lib-amd/shortcut/shortcuts.d.ts +7 -0
  133. package/lib-amd/shortcut/shortcuts.js +15 -1
  134. package/lib-amd/shortcut/shortcuts.js.map +1 -1
  135. package/lib-amd/shortcut/utils/setShortcutIndentationCommand.js +2 -2
  136. package/lib-amd/shortcut/utils/setShortcutIndentationCommand.js.map +1 -1
  137. package/lib-amd/tableEdit/OnTableEditorCreatedCallback.d.ts +4 -0
  138. package/lib-amd/tableEdit/OnTableEditorCreatedCallback.js +5 -0
  139. package/lib-amd/tableEdit/OnTableEditorCreatedCallback.js.map +1 -0
  140. package/lib-amd/tableEdit/TableEditPlugin.d.ts +4 -1
  141. package/lib-amd/tableEdit/TableEditPlugin.js +5 -2
  142. package/lib-amd/tableEdit/TableEditPlugin.js.map +1 -1
  143. package/lib-amd/tableEdit/editors/TableEditor.d.ts +4 -1
  144. package/lib-amd/tableEdit/editors/TableEditor.js +23 -7
  145. package/lib-amd/tableEdit/editors/TableEditor.js.map +1 -1
  146. package/lib-amd/tableEdit/editors/features/TableEditFeature.js +3 -3
  147. package/lib-amd/tableEdit/editors/features/TableEditFeature.js.map +1 -1
  148. package/lib-amd/tableEdit/editors/features/TableInserter.d.ts +2 -1
  149. package/lib-amd/tableEdit/editors/features/TableInserter.js +7 -9
  150. package/lib-amd/tableEdit/editors/features/TableInserter.js.map +1 -1
  151. package/lib-amd/tableEdit/editors/features/TableMover.d.ts +2 -1
  152. package/lib-amd/tableEdit/editors/features/TableMover.js +8 -11
  153. package/lib-amd/tableEdit/editors/features/TableMover.js.map +1 -1
  154. package/lib-amd/tableEdit/editors/features/TableResizer.d.ts +2 -1
  155. package/lib-amd/tableEdit/editors/features/TableResizer.js +19 -4
  156. package/lib-amd/tableEdit/editors/features/TableResizer.js.map +1 -1
  157. package/lib-mjs/autoFormat/AutoFormatPlugin.d.ts +15 -5
  158. package/lib-mjs/autoFormat/AutoFormatPlugin.js +41 -4
  159. package/lib-mjs/autoFormat/AutoFormatPlugin.js.map +1 -1
  160. package/lib-mjs/autoFormat/link/createLink.js +3 -1
  161. package/lib-mjs/autoFormat/link/createLink.js.map +1 -1
  162. package/lib-mjs/autoFormat/list/keyboardListTrigger.js +7 -9
  163. package/lib-mjs/autoFormat/list/keyboardListTrigger.js.map +1 -1
  164. package/lib-mjs/autoFormat/numbers/transformFraction.d.ts +5 -0
  165. package/lib-mjs/autoFormat/numbers/transformFraction.js +23 -0
  166. package/lib-mjs/autoFormat/numbers/transformFraction.js.map +1 -0
  167. package/lib-mjs/autoFormat/numbers/transformOrdinals.d.ts +5 -0
  168. package/lib-mjs/autoFormat/numbers/transformOrdinals.js +28 -0
  169. package/lib-mjs/autoFormat/numbers/transformOrdinals.js.map +1 -0
  170. package/lib-mjs/customReplace/CustomReplacePlugin.d.ts +61 -0
  171. package/lib-mjs/customReplace/CustomReplacePlugin.js +84 -0
  172. package/lib-mjs/customReplace/CustomReplacePlugin.js.map +1 -0
  173. package/lib-mjs/edit/EditPlugin.js +19 -1
  174. package/lib-mjs/edit/EditPlugin.js.map +1 -1
  175. package/lib-mjs/edit/inputSteps/handleEnterOnList.js +8 -1
  176. package/lib-mjs/edit/inputSteps/handleEnterOnList.js.map +1 -1
  177. package/lib-mjs/edit/keyboardTab.js +5 -5
  178. package/lib-mjs/edit/keyboardTab.js.map +1 -1
  179. package/lib-mjs/edit/tabUtils/handleTabOnList.d.ts +2 -2
  180. package/lib-mjs/edit/tabUtils/handleTabOnList.js +3 -3
  181. package/lib-mjs/edit/tabUtils/handleTabOnList.js.map +1 -1
  182. package/lib-mjs/edit/tabUtils/handleTabOnParagraph.d.ts +2 -2
  183. package/lib-mjs/edit/tabUtils/handleTabOnParagraph.js +2 -2
  184. package/lib-mjs/edit/tabUtils/handleTabOnParagraph.js.map +1 -1
  185. package/lib-mjs/index.d.ts +7 -1
  186. package/lib-mjs/index.js +4 -1
  187. package/lib-mjs/index.js.map +1 -1
  188. package/lib-mjs/markdown/utils/setFormat.js +11 -9
  189. package/lib-mjs/markdown/utils/setFormat.js.map +1 -1
  190. package/lib-mjs/picker/PickerHandler.d.ts +112 -0
  191. package/lib-mjs/picker/PickerHandler.js +2 -0
  192. package/lib-mjs/picker/PickerHandler.js.map +1 -0
  193. package/lib-mjs/picker/PickerHelper.d.ts +22 -0
  194. package/lib-mjs/picker/PickerHelper.js +2 -0
  195. package/lib-mjs/picker/PickerHelper.js.map +1 -0
  196. package/lib-mjs/picker/PickerHelperImpl.d.ts +25 -0
  197. package/lib-mjs/picker/PickerHelperImpl.js +51 -0
  198. package/lib-mjs/picker/PickerHelperImpl.js.map +1 -0
  199. package/lib-mjs/picker/PickerPlugin.d.ts +54 -0
  200. package/lib-mjs/picker/PickerPlugin.js +214 -0
  201. package/lib-mjs/picker/PickerPlugin.js.map +1 -0
  202. package/lib-mjs/picker/getQueryString.d.ts +5 -0
  203. package/lib-mjs/picker/getQueryString.js +32 -0
  204. package/lib-mjs/picker/getQueryString.js.map +1 -0
  205. package/lib-mjs/pluginUtils/Rect/getDOMInsertPointRect.d.ts +7 -0
  206. package/lib-mjs/pluginUtils/Rect/getDOMInsertPointRect.js +53 -0
  207. package/lib-mjs/pluginUtils/Rect/getDOMInsertPointRect.js.map +1 -0
  208. package/lib-mjs/shortcut/ShortcutPlugin.js +2 -1
  209. package/lib-mjs/shortcut/ShortcutPlugin.js.map +1 -1
  210. package/lib-mjs/shortcut/shortcuts.d.ts +7 -0
  211. package/lib-mjs/shortcut/shortcuts.js +14 -0
  212. package/lib-mjs/shortcut/shortcuts.js.map +1 -1
  213. package/lib-mjs/shortcut/utils/setShortcutIndentationCommand.js +2 -2
  214. package/lib-mjs/shortcut/utils/setShortcutIndentationCommand.js.map +1 -1
  215. package/lib-mjs/tableEdit/OnTableEditorCreatedCallback.d.ts +4 -0
  216. package/lib-mjs/tableEdit/OnTableEditorCreatedCallback.js +2 -0
  217. package/lib-mjs/tableEdit/OnTableEditorCreatedCallback.js.map +1 -0
  218. package/lib-mjs/tableEdit/TableEditPlugin.d.ts +4 -1
  219. package/lib-mjs/tableEdit/TableEditPlugin.js +5 -2
  220. package/lib-mjs/tableEdit/TableEditPlugin.js.map +1 -1
  221. package/lib-mjs/tableEdit/editors/TableEditor.d.ts +4 -1
  222. package/lib-mjs/tableEdit/editors/TableEditor.js +24 -8
  223. package/lib-mjs/tableEdit/editors/TableEditor.js.map +1 -1
  224. package/lib-mjs/tableEdit/editors/features/TableEditFeature.js +3 -3
  225. package/lib-mjs/tableEdit/editors/features/TableEditFeature.js.map +1 -1
  226. package/lib-mjs/tableEdit/editors/features/TableInserter.d.ts +2 -1
  227. package/lib-mjs/tableEdit/editors/features/TableInserter.js +7 -9
  228. package/lib-mjs/tableEdit/editors/features/TableInserter.js.map +1 -1
  229. package/lib-mjs/tableEdit/editors/features/TableMover.d.ts +2 -1
  230. package/lib-mjs/tableEdit/editors/features/TableMover.js +8 -11
  231. package/lib-mjs/tableEdit/editors/features/TableMover.js.map +1 -1
  232. package/lib-mjs/tableEdit/editors/features/TableResizer.d.ts +2 -1
  233. package/lib-mjs/tableEdit/editors/features/TableResizer.js +19 -3
  234. package/lib-mjs/tableEdit/editors/features/TableResizer.js.map +1 -1
  235. package/package.json +5 -5
@@ -15,16 +15,18 @@ define(["require", "exports", "tslib", "roosterjs-content-model-api", "../../plu
15
15
  var firstCharIndex = previousSegment.text
16
16
  .substring(0, lastCharIndex - 1)
17
17
  .lastIndexOf(character);
18
- var formattedText = (0, splitTextSegment_1.splitTextSegment)(previousSegment, paragraph, firstCharIndex, lastCharIndex);
19
- formattedText.text = formattedText.text.replace(character, '').slice(0, -1);
20
- formattedText.format = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, formattedText.format), format);
21
- if (codeFormat) {
22
- formattedText.code = {
23
- format: codeFormat,
24
- };
18
+ if (lastCharIndex - firstCharIndex > 2) {
19
+ var formattedText = (0, splitTextSegment_1.splitTextSegment)(previousSegment, paragraph, firstCharIndex, lastCharIndex);
20
+ formattedText.text = formattedText.text.replace(character, '').slice(0, -1);
21
+ formattedText.format = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, formattedText.format), format);
22
+ if (codeFormat) {
23
+ formattedText.code = {
24
+ format: codeFormat,
25
+ };
26
+ }
27
+ context.canUndoByBackspace = true;
28
+ return true;
25
29
  }
26
- context.canUndoByBackspace = true;
27
- return true;
28
30
  }
29
31
  }
30
32
  return false;
@@ -1 +1 @@
1
- {"version":3,"file":"setFormat.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/markdown/utils/setFormat.ts"],"names":[],"mappings":";;;;IASA;;OAEG;IACH,SAAgB,SAAS,CACrB,MAAe,EACf,SAAiB,EACjB,MAAiC,EACjC,UAAmC;QAEnC,IAAA,oEAAsC,EAClC,MAAM,EACN,UAAC,MAAM,EAAE,eAAe,EAAE,SAAS,EAAE,YAAY,EAAE,OAAO;YACtD,IAAI,eAAe,CAAC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,SAAS,EAAE;gBACpE,IAAM,gBAAgB,GAAG,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;gBAC3D,OAAO,CAAC,gBAAgB,mDACjB,YAAY,KACf,aAAa,EAAE,CAAC,CAAC,YAAY,CAAC,aAAa,EAC3C,MAAM,EAAE,CAAC,CAAC,YAAY,CAAC,MAAM,EAC7B,UAAU,EAAE,CAAA,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,UAAU,EAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,GAC5D,CAAC;gBACF,IAAI,gBAAgB,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE;oBAC1C,IAAM,aAAa,GAAG,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC;oBAClD,IAAM,cAAc,GAAG,eAAe,CAAC,IAAI;yBACtC,SAAS,CAAC,CAAC,EAAE,aAAa,GAAG,CAAC,CAAC;yBAC/B,WAAW,CAAC,SAAS,CAAC,CAAC;oBAE5B,IAAM,aAAa,GAAG,IAAA,mCAAgB,EAClC,eAAe,EACf,SAAS,EACT,cAAc,EACd,aAAa,CAChB,CAAC;oBAEF,aAAa,CAAC,IAAI,GAAG,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;oBAC5E,aAAa,CAAC,MAAM,mDACb,aAAa,CAAC,MAAM,GACpB,MAAM,CACZ,CAAC;oBACF,IAAI,UAAU,EAAE;wBACZ,aAAa,CAAC,IAAI,GAAG;4BACjB,MAAM,EAAE,UAAU;yBACrB,CAAC;qBACL;oBAED,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;oBAClC,OAAO,IAAI,CAAC;iBACf;aACJ;YACD,OAAO,KAAK,CAAC;QACjB,CAAC,CACJ,CAAC;IACN,CAAC;IAhDD,8BAgDC","sourcesContent":["import { formatTextSegmentBeforeSelectionMarker } from 'roosterjs-content-model-api';\nimport { splitTextSegment } from '../../pluginUtils/splitTextSegment';\n\nimport type {\n ContentModelCodeFormat,\n ContentModelSegmentFormat,\n IEditor,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function setFormat(\n editor: IEditor,\n character: string,\n format: ContentModelSegmentFormat,\n codeFormat?: ContentModelCodeFormat\n) {\n formatTextSegmentBeforeSelectionMarker(\n editor,\n (_model, previousSegment, paragraph, markerFormat, context) => {\n if (previousSegment.text[previousSegment.text.length - 1] == character) {\n const textBeforeMarker = previousSegment.text.slice(0, -1);\n context.newPendingFormat = {\n ...markerFormat,\n strikethrough: !!markerFormat.strikethrough,\n italic: !!markerFormat.italic,\n fontWeight: markerFormat?.fontWeight ? 'bold' : undefined,\n };\n if (textBeforeMarker.indexOf(character) > -1) {\n const lastCharIndex = previousSegment.text.length;\n const firstCharIndex = previousSegment.text\n .substring(0, lastCharIndex - 1)\n .lastIndexOf(character);\n\n const formattedText = splitTextSegment(\n previousSegment,\n paragraph,\n firstCharIndex,\n lastCharIndex\n );\n\n formattedText.text = formattedText.text.replace(character, '').slice(0, -1);\n formattedText.format = {\n ...formattedText.format,\n ...format,\n };\n if (codeFormat) {\n formattedText.code = {\n format: codeFormat,\n };\n }\n\n context.canUndoByBackspace = true;\n return true;\n }\n }\n return false;\n }\n );\n}\n"]}
1
+ {"version":3,"file":"setFormat.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/markdown/utils/setFormat.ts"],"names":[],"mappings":";;;;IASA;;OAEG;IACH,SAAgB,SAAS,CACrB,MAAe,EACf,SAAiB,EACjB,MAAiC,EACjC,UAAmC;QAEnC,IAAA,oEAAsC,EAClC,MAAM,EACN,UAAC,MAAM,EAAE,eAAe,EAAE,SAAS,EAAE,YAAY,EAAE,OAAO;YACtD,IAAI,eAAe,CAAC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,SAAS,EAAE;gBACpE,IAAM,gBAAgB,GAAG,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;gBAC3D,OAAO,CAAC,gBAAgB,mDACjB,YAAY,KACf,aAAa,EAAE,CAAC,CAAC,YAAY,CAAC,aAAa,EAC3C,MAAM,EAAE,CAAC,CAAC,YAAY,CAAC,MAAM,EAC7B,UAAU,EAAE,CAAA,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,UAAU,EAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,GAC5D,CAAC;gBACF,IAAI,gBAAgB,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE;oBAC1C,IAAM,aAAa,GAAG,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC;oBAClD,IAAM,cAAc,GAAG,eAAe,CAAC,IAAI;yBACtC,SAAS,CAAC,CAAC,EAAE,aAAa,GAAG,CAAC,CAAC;yBAC/B,WAAW,CAAC,SAAS,CAAC,CAAC;oBAC5B,IAAI,aAAa,GAAG,cAAc,GAAG,CAAC,EAAE;wBACpC,IAAM,aAAa,GAAG,IAAA,mCAAgB,EAClC,eAAe,EACf,SAAS,EACT,cAAc,EACd,aAAa,CAChB,CAAC;wBAEF,aAAa,CAAC,IAAI,GAAG,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;wBAC5E,aAAa,CAAC,MAAM,mDACb,aAAa,CAAC,MAAM,GACpB,MAAM,CACZ,CAAC;wBACF,IAAI,UAAU,EAAE;4BACZ,aAAa,CAAC,IAAI,GAAG;gCACjB,MAAM,EAAE,UAAU;6BACrB,CAAC;yBACL;wBAED,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;wBAClC,OAAO,IAAI,CAAC;qBACf;iBACJ;aACJ;YACD,OAAO,KAAK,CAAC;QACjB,CAAC,CACJ,CAAC;IACN,CAAC;IAjDD,8BAiDC","sourcesContent":["import { formatTextSegmentBeforeSelectionMarker } from 'roosterjs-content-model-api';\nimport { splitTextSegment } from '../../pluginUtils/splitTextSegment';\n\nimport type {\n ContentModelCodeFormat,\n ContentModelSegmentFormat,\n IEditor,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function setFormat(\n editor: IEditor,\n character: string,\n format: ContentModelSegmentFormat,\n codeFormat?: ContentModelCodeFormat\n) {\n formatTextSegmentBeforeSelectionMarker(\n editor,\n (_model, previousSegment, paragraph, markerFormat, context) => {\n if (previousSegment.text[previousSegment.text.length - 1] == character) {\n const textBeforeMarker = previousSegment.text.slice(0, -1);\n context.newPendingFormat = {\n ...markerFormat,\n strikethrough: !!markerFormat.strikethrough,\n italic: !!markerFormat.italic,\n fontWeight: markerFormat?.fontWeight ? 'bold' : undefined,\n };\n if (textBeforeMarker.indexOf(character) > -1) {\n const lastCharIndex = previousSegment.text.length;\n const firstCharIndex = previousSegment.text\n .substring(0, lastCharIndex - 1)\n .lastIndexOf(character);\n if (lastCharIndex - firstCharIndex > 2) {\n const formattedText = splitTextSegment(\n previousSegment,\n paragraph,\n firstCharIndex,\n lastCharIndex\n );\n\n formattedText.text = formattedText.text.replace(character, '').slice(0, -1);\n formattedText.format = {\n ...formattedText.format,\n ...format,\n };\n if (codeFormat) {\n formattedText.code = {\n format: codeFormat,\n };\n }\n\n context.canUndoByBackspace = true;\n return true;\n }\n }\n }\n return false;\n }\n );\n}\n"]}
@@ -0,0 +1,112 @@
1
+ import type { PickerHelper } from './PickerHelper';
2
+ import type { DOMInsertPoint } from 'roosterjs-content-model-types';
3
+ /**
4
+ * Direction option for picker
5
+ */
6
+ export declare type PickerDirection =
7
+ /**
8
+ * Show options horizontally
9
+ */
10
+ 'horizontal'
11
+ /**
12
+ * Show options vertically
13
+ */
14
+ | 'vertical'
15
+ /**
16
+ * Show options in both direction (2-D picker)
17
+ */
18
+ | 'both';
19
+ /**
20
+ * Change mode that PickerPlugin will pass to child class
21
+ */
22
+ export declare type PickerSelectionChangMode =
23
+ /**
24
+ * When user press Right ("horizontal" mode or "both" mode) (Left in RTL) or Down ("vertical" mode),
25
+ * select the next option
26
+ */
27
+ 'next'
28
+ /**
29
+ * When user press Left ("horizontal" mode or "both" mode) (Right in RTL) or Up ("vertical" mode),
30
+ * select the previous option
31
+ */
32
+ | 'previous'
33
+ /**
34
+ * When user press Down ("both" mode),
35
+ * select the next row
36
+ */
37
+ | 'nextRow'
38
+ /**
39
+ * When user press Up ("both" mode),
40
+ * select the previous row
41
+ */
42
+ | 'previousRow'
43
+ /**
44
+ * When user press PageDown,
45
+ * switch to next page
46
+ */
47
+ | 'nextPage'
48
+ /**
49
+ * When user press PageUp,
50
+ * switch to previous page
51
+ */
52
+ | 'previousPage'
53
+ /**
54
+ * When user press Home,
55
+ * Select the first item in current row
56
+ */
57
+ | 'firstInRow'
58
+ /**
59
+ * When user press End,
60
+ * Select the last item in current row
61
+ */
62
+ | 'lastInRow'
63
+ /**
64
+ * When user press CTRL (or META on Mac) + Home,
65
+ * Select the very first item
66
+ */
67
+ | 'first'
68
+ /**
69
+ * When user press CTRL (or META on Mac) + End,
70
+ * Select the very last item
71
+ */
72
+ | 'last';
73
+ /**
74
+ * Represents the interface a handler for picker plugin. Developer need to implement this interface to create a new type of picker
75
+ */
76
+ export interface PickerHandler {
77
+ /**
78
+ * Initialize the picker handler, pass in editor and PickerPlugin instance so that the handler can save them
79
+ * @param editor The editor instance
80
+ * @param pickerPlugin The PickerPlugin instance
81
+ */
82
+ onInitialize: (helper: PickerHelper) => void;
83
+ /**
84
+ * Dispose the picker handler
85
+ */
86
+ onDispose: () => void;
87
+ /**
88
+ * Notify the picker handler that user has typed trigger character so handler should show picker now
89
+ * @param queryString Current query string
90
+ * @param insertPoint Insert point where user is typing, can be used for calculating picker position
91
+ * @returns A picker direction to let picker plugin know what kind of picker is opened. Picker plugin will use this value
92
+ * to decide how to handle keyboard event to change selection. Return null means picker is not actually opened
93
+ */
94
+ onTrigger: (queryString: string, insertPoint: DOMInsertPoint) => PickerDirection | null;
95
+ /**
96
+ * Notify the picker handler that picker should be closed now
97
+ */
98
+ onClosePicker?(): void;
99
+ /**
100
+ * Notify the picker handler that user has changed current typed query string
101
+ */
102
+ onQueryStringChanged?(queryString: string): void;
103
+ /**
104
+ * Notify the picker handler that user has decide to select the current option in picker
105
+ */
106
+ onSelect?(): void;
107
+ /**
108
+ * Notify the picker handler that user is using keyboard to change current selection
109
+ * @param mode The moving mode. Handler code can use this value to decide which item need to be selected
110
+ */
111
+ onSelectionChanged?(mode: PickerSelectionChangMode): void;
112
+ }
@@ -0,0 +1,5 @@
1
+ define(["require", "exports"], function (require, exports) {
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ });
5
+ //# sourceMappingURL=PickerHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PickerHandler.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/picker/PickerHandler.ts"],"names":[],"mappings":"","sourcesContent":["import type { PickerHelper } from './PickerHelper';\nimport type { DOMInsertPoint } from 'roosterjs-content-model-types';\n\n/**\n * Direction option for picker\n */\nexport type PickerDirection =\n /**\n * Show options horizontally\n */\n | 'horizontal'\n /**\n * Show options vertically\n */\n | 'vertical'\n\n /**\n * Show options in both direction (2-D picker)\n */\n | 'both';\n\n/**\n * Change mode that PickerPlugin will pass to child class\n */\nexport type PickerSelectionChangMode =\n /**\n * When user press Right (\"horizontal\" mode or \"both\" mode) (Left in RTL) or Down (\"vertical\" mode),\n * select the next option\n */\n | 'next'\n\n /**\n * When user press Left (\"horizontal\" mode or \"both\" mode) (Right in RTL) or Up (\"vertical\" mode),\n * select the previous option\n */\n | 'previous'\n\n /**\n * When user press Down (\"both\" mode),\n * select the next row\n */\n | 'nextRow'\n\n /**\n * When user press Up (\"both\" mode),\n * select the previous row\n */\n | 'previousRow'\n\n /**\n * When user press PageDown,\n * switch to next page\n */\n | 'nextPage'\n\n /**\n * When user press PageUp,\n * switch to previous page\n */\n | 'previousPage'\n\n /**\n * When user press Home,\n * Select the first item in current row\n */\n | 'firstInRow'\n\n /**\n * When user press End,\n * Select the last item in current row\n */\n | 'lastInRow'\n\n /**\n * When user press CTRL (or META on Mac) + Home,\n * Select the very first item\n */\n | 'first'\n\n /**\n * When user press CTRL (or META on Mac) + End,\n * Select the very last item\n */\n | 'last';\n\n/**\n * Represents the interface a handler for picker plugin. Developer need to implement this interface to create a new type of picker\n */\nexport interface PickerHandler {\n /**\n * Initialize the picker handler, pass in editor and PickerPlugin instance so that the handler can save them\n * @param editor The editor instance\n * @param pickerPlugin The PickerPlugin instance\n */\n onInitialize: (helper: PickerHelper) => void;\n\n /**\n * Dispose the picker handler\n */\n onDispose: () => void;\n\n /**\n * Notify the picker handler that user has typed trigger character so handler should show picker now\n * @param queryString Current query string\n * @param insertPoint Insert point where user is typing, can be used for calculating picker position\n * @returns A picker direction to let picker plugin know what kind of picker is opened. Picker plugin will use this value\n * to decide how to handle keyboard event to change selection. Return null means picker is not actually opened\n */\n onTrigger: (queryString: string, insertPoint: DOMInsertPoint) => PickerDirection | null;\n\n /**\n * Notify the picker handler that picker should be closed now\n */\n onClosePicker?(): void;\n\n /**\n * Notify the picker handler that user has changed current typed query string\n */\n onQueryStringChanged?(queryString: string): void;\n\n /**\n * Notify the picker handler that user has decide to select the current option in picker\n */\n onSelect?(): void;\n\n /**\n * Notify the picker handler that user is using keyboard to change current selection\n * @param mode The moving mode. Handler code can use this value to decide which item need to be selected\n */\n onSelectionChanged?(mode: PickerSelectionChangMode): void;\n}\n"]}
@@ -0,0 +1,22 @@
1
+ import type { ContentModelDocument, FormatContentModelOptions, IEditor } from 'roosterjs-content-model-types';
2
+ /**
3
+ * Represents the interface of picker plugin, provides necessary utility functions for pickers
4
+ */
5
+ export interface PickerHelper {
6
+ /**
7
+ * The editor instance
8
+ */
9
+ readonly editor: IEditor;
10
+ /**
11
+ * Replace the query string with a given Content Model.
12
+ * This is used for commit a change from picker and insert the committed content into editor.
13
+ * @param model The Content Model to insert
14
+ * @param options Options for formatting content model
15
+ * @param canUndoByBackspace Whether this change can be undone using Backspace key
16
+ */
17
+ replaceQueryString: (model: ContentModelDocument, options?: FormatContentModelOptions, canUndoByBackspace?: boolean) => void;
18
+ /**
19
+ * Notify Picker Plugin that picker is closed from the handler code, so picker plugin can quit the suggesting state
20
+ */
21
+ closePicker: () => void;
22
+ }
@@ -0,0 +1,5 @@
1
+ define(["require", "exports"], function (require, exports) {
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ });
5
+ //# sourceMappingURL=PickerHelper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PickerHelper.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/picker/PickerHelper.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n ContentModelDocument,\n FormatContentModelOptions,\n IEditor,\n} from 'roosterjs-content-model-types';\n\n/**\n * Represents the interface of picker plugin, provides necessary utility functions for pickers\n */\nexport interface PickerHelper {\n /**\n * The editor instance\n */\n readonly editor: IEditor;\n\n /**\n * Replace the query string with a given Content Model.\n * This is used for commit a change from picker and insert the committed content into editor.\n * @param model The Content Model to insert\n * @param options Options for formatting content model\n * @param canUndoByBackspace Whether this change can be undone using Backspace key\n */\n replaceQueryString: (\n model: ContentModelDocument,\n options?: FormatContentModelOptions,\n canUndoByBackspace?: boolean\n ) => void;\n\n /**\n * Notify Picker Plugin that picker is closed from the handler code, so picker plugin can quit the suggesting state\n */\n closePicker: () => void;\n}\n"]}
@@ -0,0 +1,25 @@
1
+ import type { ContentModelDocument, FormatContentModelOptions, IEditor } from 'roosterjs-content-model-types';
2
+ import type { PickerDirection, PickerHandler } from './PickerHandler';
3
+ import type { PickerHelper } from './PickerHelper';
4
+ /**
5
+ * @internal
6
+ */
7
+ export declare class PickerHelperImpl implements PickerHelper {
8
+ readonly editor: IEditor;
9
+ readonly handler: PickerHandler;
10
+ private triggerCharacter;
11
+ direction: PickerDirection | null;
12
+ constructor(editor: IEditor, handler: PickerHandler, triggerCharacter: string);
13
+ /**
14
+ * Replace the query string with a given Content Model.
15
+ * This is used for commit a change from picker and insert the committed content into editor.
16
+ * @param model The Content Model to insert
17
+ * @param options Options for formatting content model
18
+ * @param canUndoByBackspace Whether this change can be undone using Backspace key
19
+ */
20
+ replaceQueryString(model: ContentModelDocument, options?: FormatContentModelOptions, canUndoByBackspace?: boolean): void;
21
+ /**
22
+ * Notify Picker Plugin that picker is closed from the handler code, so picker plugin can quit the suggesting state
23
+ */
24
+ closePicker(): void;
25
+ }
@@ -0,0 +1,53 @@
1
+ define(["require", "exports", "roosterjs-content-model-api", "./getQueryString", "roosterjs-content-model-dom"], function (require, exports, roosterjs_content_model_api_1, getQueryString_1, roosterjs_content_model_dom_1) {
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.PickerHelperImpl = void 0;
5
+ /**
6
+ * @internal
7
+ */
8
+ var PickerHelperImpl = /** @class */ (function () {
9
+ function PickerHelperImpl(editor, handler, triggerCharacter) {
10
+ this.editor = editor;
11
+ this.handler = handler;
12
+ this.triggerCharacter = triggerCharacter;
13
+ this.direction = null;
14
+ }
15
+ /**
16
+ * Replace the query string with a given Content Model.
17
+ * This is used for commit a change from picker and insert the committed content into editor.
18
+ * @param model The Content Model to insert
19
+ * @param options Options for formatting content model
20
+ * @param canUndoByBackspace Whether this change can be undone using Backspace key
21
+ */
22
+ PickerHelperImpl.prototype.replaceQueryString = function (model, options, canUndoByBackspace) {
23
+ var _this = this;
24
+ this.editor.focus();
25
+ (0, roosterjs_content_model_api_1.formatTextSegmentBeforeSelectionMarker)(this.editor, function (target, previousSegment, paragraph, _, context) {
26
+ var potentialSegments = [];
27
+ var queryString = (0, getQueryString_1.getQueryString)(_this.triggerCharacter, paragraph, previousSegment, potentialSegments);
28
+ if (queryString) {
29
+ potentialSegments.forEach(function (x) { return (x.isSelected = true); });
30
+ (0, roosterjs_content_model_dom_1.mergeModel)(target, model, context);
31
+ context.canUndoByBackspace = canUndoByBackspace;
32
+ return true;
33
+ }
34
+ else {
35
+ return false;
36
+ }
37
+ }, options);
38
+ };
39
+ /**
40
+ * Notify Picker Plugin that picker is closed from the handler code, so picker plugin can quit the suggesting state
41
+ */
42
+ PickerHelperImpl.prototype.closePicker = function () {
43
+ var _a, _b;
44
+ if (this.direction) {
45
+ this.direction = null;
46
+ (_b = (_a = this.handler).onClosePicker) === null || _b === void 0 ? void 0 : _b.call(_a);
47
+ }
48
+ };
49
+ return PickerHelperImpl;
50
+ }());
51
+ exports.PickerHelperImpl = PickerHelperImpl;
52
+ });
53
+ //# sourceMappingURL=PickerHelperImpl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PickerHelperImpl.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/picker/PickerHelperImpl.ts"],"names":[],"mappings":";;;;IAYA;;OAEG;IACH;QAGI,0BACoB,MAAe,EACf,OAAsB,EAC9B,gBAAwB;YAFhB,WAAM,GAAN,MAAM,CAAS;YACf,YAAO,GAAP,OAAO,CAAe;YAC9B,qBAAgB,GAAhB,gBAAgB,CAAQ;YAL7B,cAAS,GAA2B,IAAI,CAAC;QAM7C,CAAC;QAEJ;;;;;;WAMG;QACH,6CAAkB,GAAlB,UACI,KAA2B,EAC3B,OAAmC,EACnC,kBAA4B;YAHhC,iBA6BC;YAxBG,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;YAEpB,IAAA,oEAAsC,EAClC,IAAI,CAAC,MAAM,EACX,UAAC,MAAM,EAAE,eAAe,EAAE,SAAS,EAAE,CAAC,EAAE,OAAO;gBAC3C,IAAM,iBAAiB,GAAuB,EAAE,CAAC;gBACjD,IAAM,WAAW,GAAG,IAAA,+BAAc,EAC9B,KAAI,CAAC,gBAAgB,EACrB,SAAS,EACT,eAAe,EACf,iBAAiB,CACpB,CAAC;gBAEF,IAAI,WAAW,EAAE;oBACb,iBAAiB,CAAC,OAAO,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,CAAC,UAAU,GAAG,IAAI,CAAC,EAArB,CAAqB,CAAC,CAAC;oBACtD,IAAA,wCAAU,EAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;oBACnC,OAAO,CAAC,kBAAkB,GAAG,kBAAkB,CAAC;oBAChD,OAAO,IAAI,CAAC;iBACf;qBAAM;oBACH,OAAO,KAAK,CAAC;iBAChB;YACL,CAAC,EACD,OAAO,CACV,CAAC;QACN,CAAC;QAED;;WAEG;QACH,sCAAW,GAAX;;YACI,IAAI,IAAI,CAAC,SAAS,EAAE;gBAChB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;gBACtB,MAAA,MAAA,IAAI,CAAC,OAAO,EAAC,aAAa,kDAAI,CAAC;aAClC;QACL,CAAC;QACL,uBAAC;IAAD,CAAC,AAxDD,IAwDC;IAxDY,4CAAgB","sourcesContent":["import { formatTextSegmentBeforeSelectionMarker } from 'roosterjs-content-model-api';\nimport { getQueryString } from './getQueryString';\nimport { mergeModel } from 'roosterjs-content-model-dom';\nimport type {\n ContentModelDocument,\n ContentModelText,\n FormatContentModelOptions,\n IEditor,\n} from 'roosterjs-content-model-types';\nimport type { PickerDirection, PickerHandler } from './PickerHandler';\nimport type { PickerHelper } from './PickerHelper';\n\n/**\n * @internal\n */\nexport class PickerHelperImpl implements PickerHelper {\n public direction: PickerDirection | null = null;\n\n constructor(\n public readonly editor: IEditor,\n public readonly handler: PickerHandler,\n private triggerCharacter: string\n ) {}\n\n /**\n * Replace the query string with a given Content Model.\n * This is used for commit a change from picker and insert the committed content into editor.\n * @param model The Content Model to insert\n * @param options Options for formatting content model\n * @param canUndoByBackspace Whether this change can be undone using Backspace key\n */\n replaceQueryString(\n model: ContentModelDocument,\n options?: FormatContentModelOptions,\n canUndoByBackspace?: boolean\n ): void {\n this.editor.focus();\n\n formatTextSegmentBeforeSelectionMarker(\n this.editor,\n (target, previousSegment, paragraph, _, context) => {\n const potentialSegments: ContentModelText[] = [];\n const queryString = getQueryString(\n this.triggerCharacter,\n paragraph,\n previousSegment,\n potentialSegments\n );\n\n if (queryString) {\n potentialSegments.forEach(x => (x.isSelected = true));\n mergeModel(target, model, context);\n context.canUndoByBackspace = canUndoByBackspace;\n return true;\n } else {\n return false;\n }\n },\n options\n );\n }\n\n /**\n * Notify Picker Plugin that picker is closed from the handler code, so picker plugin can quit the suggesting state\n */\n closePicker() {\n if (this.direction) {\n this.direction = null;\n this.handler.onClosePicker?.();\n }\n }\n}\n"]}
@@ -0,0 +1,54 @@
1
+ import type { PickerHandler } from './PickerHandler';
2
+ import type { EditorPlugin, IEditor, PluginEvent } from 'roosterjs-content-model-types';
3
+ /**
4
+ * PickerPlugin represents a plugin of editor which can handle picker related behaviors, including
5
+ * - Show picker when special trigger key is pressed
6
+ * - Hide picker
7
+ * - Change selection in picker by Up/Down/Left/Right
8
+ * - Apply selected item in picker
9
+ *
10
+ * PickerPlugin doesn't provide any UI, it just wraps related DOM events and invoke callback functions.
11
+ */
12
+ export declare class PickerPlugin implements EditorPlugin {
13
+ private triggerCharacter;
14
+ private readonly handler;
15
+ private isMac;
16
+ private lastQueryString;
17
+ private helper;
18
+ /**
19
+ * Construct a new instance of PickerPlugin class
20
+ * @param triggerCharacter The character to trigger a picker to be shown
21
+ * @param handler Picker handler for receiving picker state change events
22
+ */
23
+ constructor(triggerCharacter: string, handler: PickerHandler);
24
+ /**
25
+ * Get a friendly name
26
+ */
27
+ getName(): string;
28
+ /**
29
+ * Initialize this plugin. This should only be called from Editor
30
+ * @param editor Editor instance
31
+ */
32
+ initialize(editor: IEditor): void;
33
+ /**
34
+ * Dispose this plugin
35
+ */
36
+ dispose(): void;
37
+ /**
38
+ * Check if the plugin should handle the given event exclusively.
39
+ * Handle an event exclusively means other plugin will not receive this event in
40
+ * onPluginEvent method.
41
+ * If two plugins will return true in willHandleEventExclusively() for the same event,
42
+ * the final result depends on the order of the plugins are added into editor
43
+ * @param event The event to check
44
+ */
45
+ willHandleEventExclusively(event: PluginEvent): boolean;
46
+ /**
47
+ * Handle events triggered from editor
48
+ * @param event PluginEvent object
49
+ */
50
+ onPluginEvent(event: PluginEvent): void;
51
+ private onSuggestingKeyDown;
52
+ private onSuggestingInput;
53
+ private onInput;
54
+ }
@@ -0,0 +1,215 @@
1
+ define(["require", "exports", "roosterjs-content-model-dom", "roosterjs-content-model-api", "./getQueryString", "./PickerHelperImpl"], function (require, exports, roosterjs_content_model_dom_1, roosterjs_content_model_api_1, getQueryString_1, PickerHelperImpl_1) {
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.PickerPlugin = void 0;
5
+ /**
6
+ * PickerPlugin represents a plugin of editor which can handle picker related behaviors, including
7
+ * - Show picker when special trigger key is pressed
8
+ * - Hide picker
9
+ * - Change selection in picker by Up/Down/Left/Right
10
+ * - Apply selected item in picker
11
+ *
12
+ * PickerPlugin doesn't provide any UI, it just wraps related DOM events and invoke callback functions.
13
+ */
14
+ var PickerPlugin = /** @class */ (function () {
15
+ /**
16
+ * Construct a new instance of PickerPlugin class
17
+ * @param triggerCharacter The character to trigger a picker to be shown
18
+ * @param handler Picker handler for receiving picker state change events
19
+ */
20
+ function PickerPlugin(triggerCharacter, handler) {
21
+ this.triggerCharacter = triggerCharacter;
22
+ this.handler = handler;
23
+ this.isMac = false;
24
+ this.lastQueryString = '';
25
+ this.helper = null;
26
+ }
27
+ /**
28
+ * Get a friendly name
29
+ */
30
+ PickerPlugin.prototype.getName = function () {
31
+ return 'Picker';
32
+ };
33
+ /**
34
+ * Initialize this plugin. This should only be called from Editor
35
+ * @param editor Editor instance
36
+ */
37
+ PickerPlugin.prototype.initialize = function (editor) {
38
+ this.isMac = !!editor.getEnvironment().isMac;
39
+ this.helper = new PickerHelperImpl_1.PickerHelperImpl(editor, this.handler, this.triggerCharacter);
40
+ this.handler.onInitialize(this.helper);
41
+ };
42
+ /**
43
+ * Dispose this plugin
44
+ */
45
+ PickerPlugin.prototype.dispose = function () {
46
+ this.handler.onDispose();
47
+ this.helper = null;
48
+ };
49
+ /**
50
+ * Check if the plugin should handle the given event exclusively.
51
+ * Handle an event exclusively means other plugin will not receive this event in
52
+ * onPluginEvent method.
53
+ * If two plugins will return true in willHandleEventExclusively() for the same event,
54
+ * the final result depends on the order of the plugins are added into editor
55
+ * @param event The event to check
56
+ */
57
+ PickerPlugin.prototype.willHandleEventExclusively = function (event) {
58
+ var _a;
59
+ return (!!((_a = this.helper) === null || _a === void 0 ? void 0 : _a.direction) &&
60
+ event.eventType == 'keyDown' &&
61
+ ((0, roosterjs_content_model_dom_1.isCursorMovingKey)(event.rawEvent) ||
62
+ event.rawEvent.key == 'Enter' ||
63
+ event.rawEvent.key == 'Tab' ||
64
+ event.rawEvent.key == 'Escape'));
65
+ };
66
+ /**
67
+ * Handle events triggered from editor
68
+ * @param event PluginEvent object
69
+ */
70
+ PickerPlugin.prototype.onPluginEvent = function (event) {
71
+ if (!this.helper) {
72
+ return;
73
+ }
74
+ switch (event.eventType) {
75
+ case 'contentChanged':
76
+ if (this.helper.direction) {
77
+ if (event.source == roosterjs_content_model_dom_1.ChangeSource.SetContent) {
78
+ this.helper.closePicker();
79
+ }
80
+ else {
81
+ this.onSuggestingInput(this.helper);
82
+ }
83
+ }
84
+ break;
85
+ case 'keyDown':
86
+ if (this.helper.direction) {
87
+ this.onSuggestingKeyDown(this.helper, event.rawEvent);
88
+ }
89
+ break;
90
+ case 'input':
91
+ if (this.helper.direction) {
92
+ this.onSuggestingInput(this.helper);
93
+ }
94
+ else {
95
+ this.onInput(this.helper, event.rawEvent);
96
+ }
97
+ break;
98
+ case 'mouseUp':
99
+ if (this.helper.direction) {
100
+ this.helper.closePicker();
101
+ }
102
+ break;
103
+ }
104
+ };
105
+ PickerPlugin.prototype.onSuggestingKeyDown = function (helper, event) {
106
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
107
+ switch (event.key) {
108
+ case 'ArrowLeft':
109
+ case 'ArrowRight':
110
+ if (helper.direction == 'horizontal' || helper.direction == 'both') {
111
+ var isIncrement = event.key == 'ArrowRight';
112
+ if (helper.editor.getDOMHelper().isRightToLeft()) {
113
+ isIncrement = !isIncrement;
114
+ }
115
+ (_b = (_a = this.handler).onSelectionChanged) === null || _b === void 0 ? void 0 : _b.call(_a, isIncrement ? 'next' : 'previous');
116
+ }
117
+ event.preventDefault();
118
+ break;
119
+ case 'ArrowUp':
120
+ case 'ArrowDown':
121
+ {
122
+ var isIncrement = event.key == 'ArrowDown';
123
+ if (helper.direction != 'horizontal') {
124
+ (_d = (_c = this.handler).onSelectionChanged) === null || _d === void 0 ? void 0 : _d.call(_c, helper.direction == 'both'
125
+ ? isIncrement
126
+ ? 'nextRow'
127
+ : 'previousRow'
128
+ : isIncrement
129
+ ? 'next'
130
+ : 'previous');
131
+ }
132
+ }
133
+ event.preventDefault();
134
+ break;
135
+ case 'PageUp':
136
+ case 'PageDown':
137
+ (_f = (_e = this.handler).onSelectionChanged) === null || _f === void 0 ? void 0 : _f.call(_e, event.key == 'PageDown' ? 'nextPage' : 'previousPage');
138
+ event.preventDefault();
139
+ break;
140
+ case 'Home':
141
+ case 'End':
142
+ var hasCtrl = this.isMac ? event.metaKey : event.ctrlKey;
143
+ (_h = (_g = this.handler).onSelectionChanged) === null || _h === void 0 ? void 0 : _h.call(_g, event.key == 'Home'
144
+ ? hasCtrl
145
+ ? 'first'
146
+ : 'firstInRow'
147
+ : hasCtrl
148
+ ? 'last'
149
+ : 'lastInRow');
150
+ event.preventDefault();
151
+ break;
152
+ case 'Escape':
153
+ helper.closePicker();
154
+ event.preventDefault();
155
+ break;
156
+ case 'Enter':
157
+ case 'Tab':
158
+ (_k = (_j = this.handler).onSelect) === null || _k === void 0 ? void 0 : _k.call(_j);
159
+ event.preventDefault();
160
+ break;
161
+ }
162
+ };
163
+ PickerPlugin.prototype.onSuggestingInput = function (helper) {
164
+ var _this = this;
165
+ if (!(0, roosterjs_content_model_api_1.formatTextSegmentBeforeSelectionMarker)(helper.editor, function (_, segment, paragraph) {
166
+ var _a, _b;
167
+ var newQueryString = (0, getQueryString_1.getQueryString)(_this.triggerCharacter, paragraph, segment).replace(/[\u0020\u00A0]/g, ' ');
168
+ var oldQueryString = _this.lastQueryString;
169
+ if (newQueryString &&
170
+ ((newQueryString.length >= oldQueryString.length &&
171
+ newQueryString.indexOf(oldQueryString) == 0) ||
172
+ (newQueryString.length < oldQueryString.length &&
173
+ oldQueryString.indexOf(newQueryString) == 0))) {
174
+ _this.lastQueryString = newQueryString;
175
+ (_b = (_a = _this.handler).onQueryStringChanged) === null || _b === void 0 ? void 0 : _b.call(_a, newQueryString);
176
+ }
177
+ else {
178
+ helper.closePicker();
179
+ }
180
+ return false;
181
+ })) {
182
+ helper.closePicker();
183
+ }
184
+ };
185
+ PickerPlugin.prototype.onInput = function (helper, event) {
186
+ var _this = this;
187
+ if (event.inputType == 'insertText' && event.data == this.triggerCharacter) {
188
+ (0, roosterjs_content_model_api_1.formatTextSegmentBeforeSelectionMarker)(helper.editor, function (_, segment) {
189
+ if (segment.text.endsWith(_this.triggerCharacter)) {
190
+ var charBeforeTrigger = segment.text[segment.text.length - 2];
191
+ if (!charBeforeTrigger ||
192
+ !charBeforeTrigger.trim() ||
193
+ (0, roosterjs_content_model_dom_1.isPunctuation)(charBeforeTrigger)) {
194
+ var selection = helper.editor.getDOMSelection();
195
+ var pos = (selection === null || selection === void 0 ? void 0 : selection.type) == 'range' && selection.range.collapsed
196
+ ? {
197
+ node: selection.range.startContainer,
198
+ offset: selection.range.startOffset,
199
+ }
200
+ : null;
201
+ if (pos) {
202
+ _this.lastQueryString = _this.triggerCharacter;
203
+ helper.direction = _this.handler.onTrigger(_this.lastQueryString, pos);
204
+ }
205
+ }
206
+ }
207
+ return false;
208
+ });
209
+ }
210
+ };
211
+ return PickerPlugin;
212
+ }());
213
+ exports.PickerPlugin = PickerPlugin;
214
+ });
215
+ //# sourceMappingURL=PickerPlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PickerPlugin.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/picker/PickerPlugin.ts"],"names":[],"mappings":";;;;IAYA;;;;;;;;OAQG;IACH;QAKI;;;;WAIG;QACH,sBAAoB,gBAAwB,EAAmB,OAAsB;YAAjE,qBAAgB,GAAhB,gBAAgB,CAAQ;YAAmB,YAAO,GAAP,OAAO,CAAe;YAT7E,UAAK,GAAY,KAAK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AvOD,IAuOC;IAvOY,oCAAY","sourcesContent":["import { ChangeSource, isCursorMovingKey, isPunctuation } from 'roosterjs-content-model-dom';\nimport { formatTextSegmentBeforeSelectionMarker } from 'roosterjs-content-model-api';\nimport { getQueryString } from './getQueryString';\nimport { PickerHelperImpl } from './PickerHelperImpl';\nimport type { PickerHandler } from './PickerHandler';\nimport type {\n DOMInsertPoint,\n EditorPlugin,\n IEditor,\n PluginEvent,\n} from 'roosterjs-content-model-types';\n\n/**\n * PickerPlugin represents a plugin of editor which can handle picker related behaviors, including\n * - Show picker when special trigger key is pressed\n * - Hide picker\n * - Change selection in picker by Up/Down/Left/Right\n * - Apply selected item in picker\n *\n * PickerPlugin doesn't provide any UI, it just wraps related DOM events and invoke callback functions.\n */\nexport class PickerPlugin implements EditorPlugin {\n private isMac: boolean = false;\n private lastQueryString = '';\n private helper: PickerHelperImpl | null = null;\n\n /**\n * Construct a new instance of PickerPlugin class\n * @param triggerCharacter The character to trigger a picker to be shown\n * @param handler Picker handler for receiving picker state change events\n */\n constructor(private triggerCharacter: string, private readonly handler: PickerHandler) {}\n\n /**\n * Get a friendly name\n */\n getName() {\n return 'Picker';\n }\n\n /**\n * Initialize this plugin. This should only be called from Editor\n * @param editor Editor instance\n */\n initialize(editor: IEditor) {\n this.isMac = !!editor.getEnvironment().isMac;\n this.helper = new PickerHelperImpl(editor, this.handler, this.triggerCharacter);\n this.handler.onInitialize(this.helper);\n }\n\n /**\n * Dispose this plugin\n */\n dispose() {\n this.handler.onDispose();\n this.helper = null;\n }\n\n /**\n * Check if the plugin should handle the given event exclusively.\n * Handle an event exclusively means other plugin will not receive this event in\n * onPluginEvent method.\n * If two plugins will return true in willHandleEventExclusively() for the same event,\n * the final result depends on the order of the plugins are added into editor\n * @param event The event to check\n */\n willHandleEventExclusively(event: PluginEvent) {\n return (\n !!this.helper?.direction &&\n event.eventType == 'keyDown' &&\n (isCursorMovingKey(event.rawEvent) ||\n event.rawEvent.key == 'Enter' ||\n event.rawEvent.key == 'Tab' ||\n event.rawEvent.key == 'Escape')\n );\n }\n\n /**\n * Handle events triggered from editor\n * @param event PluginEvent object\n */\n onPluginEvent(event: PluginEvent) {\n if (!this.helper) {\n return;\n }\n\n switch (event.eventType) {\n case 'contentChanged':\n if (this.helper.direction) {\n if (event.source == ChangeSource.SetContent) {\n this.helper.closePicker();\n } else {\n this.onSuggestingInput(this.helper);\n }\n }\n break;\n\n case 'keyDown':\n if (this.helper.direction) {\n this.onSuggestingKeyDown(this.helper, event.rawEvent);\n }\n break;\n\n case 'input':\n if (this.helper.direction) {\n this.onSuggestingInput(this.helper);\n } else {\n this.onInput(this.helper, event.rawEvent);\n }\n break;\n\n case 'mouseUp':\n if (this.helper.direction) {\n this.helper.closePicker();\n }\n break;\n }\n }\n\n private onSuggestingKeyDown(helper: PickerHelperImpl, event: KeyboardEvent) {\n switch (event.key) {\n case 'ArrowLeft':\n case 'ArrowRight':\n if (helper.direction == 'horizontal' || helper.direction == 'both') {\n let isIncrement = event.key == 'ArrowRight';\n\n if (helper.editor.getDOMHelper().isRightToLeft()) {\n isIncrement = !isIncrement;\n }\n\n this.handler.onSelectionChanged?.(isIncrement ? 'next' : 'previous');\n }\n\n event.preventDefault();\n break;\n case 'ArrowUp':\n case 'ArrowDown':\n {\n const isIncrement = event.key == 'ArrowDown';\n\n if (helper.direction != 'horizontal') {\n this.handler.onSelectionChanged?.(\n helper.direction == 'both'\n ? isIncrement\n ? 'nextRow'\n : 'previousRow'\n : isIncrement\n ? 'next'\n : 'previous'\n );\n }\n }\n\n event.preventDefault();\n break;\n case 'PageUp':\n case 'PageDown':\n this.handler.onSelectionChanged?.(\n event.key == 'PageDown' ? 'nextPage' : 'previousPage'\n );\n\n event.preventDefault();\n break;\n case 'Home':\n case 'End':\n const hasCtrl = this.isMac ? event.metaKey : event.ctrlKey;\n this.handler.onSelectionChanged?.(\n event.key == 'Home'\n ? hasCtrl\n ? 'first'\n : 'firstInRow'\n : hasCtrl\n ? 'last'\n : 'lastInRow'\n );\n\n event.preventDefault();\n break;\n case 'Escape':\n helper.closePicker();\n event.preventDefault();\n break;\n\n case 'Enter':\n case 'Tab':\n this.handler.onSelect?.();\n event.preventDefault();\n break;\n }\n }\n\n private onSuggestingInput(helper: PickerHelperImpl) {\n if (\n !formatTextSegmentBeforeSelectionMarker(helper.editor, (_, segment, paragraph) => {\n const newQueryString = getQueryString(\n this.triggerCharacter,\n paragraph,\n segment\n ).replace(/[\\u0020\\u00A0]/g, ' ');\n const oldQueryString = this.lastQueryString;\n\n if (\n newQueryString &&\n ((newQueryString.length >= oldQueryString.length &&\n newQueryString.indexOf(oldQueryString) == 0) ||\n (newQueryString.length < oldQueryString.length &&\n oldQueryString.indexOf(newQueryString) == 0))\n ) {\n this.lastQueryString = newQueryString;\n this.handler.onQueryStringChanged?.(newQueryString);\n } else {\n helper.closePicker();\n }\n\n return false;\n })\n ) {\n helper.closePicker();\n }\n }\n\n private onInput(helper: PickerHelperImpl, event: InputEvent) {\n if (event.inputType == 'insertText' && event.data == this.triggerCharacter) {\n formatTextSegmentBeforeSelectionMarker(helper.editor, (_, segment) => {\n if (segment.text.endsWith(this.triggerCharacter)) {\n const charBeforeTrigger = segment.text[segment.text.length - 2];\n\n if (\n !charBeforeTrigger ||\n !charBeforeTrigger.trim() ||\n isPunctuation(charBeforeTrigger)\n ) {\n const selection = helper.editor.getDOMSelection();\n const pos: DOMInsertPoint | null =\n selection?.type == 'range' && selection.range.collapsed\n ? {\n node: selection.range.startContainer,\n offset: selection.range.startOffset,\n }\n : null;\n\n if (pos) {\n this.lastQueryString = this.triggerCharacter;\n helper.direction = this.handler.onTrigger(this.lastQueryString, pos);\n }\n }\n }\n\n return false;\n });\n }\n }\n}\n"]}
@@ -0,0 +1,5 @@
1
+ import type { ContentModelParagraph, ContentModelText } from 'roosterjs-content-model-types';
2
+ /**
3
+ * @internal
4
+ */
5
+ export declare function getQueryString(triggerCharacter: string, paragraph: ContentModelParagraph, previousSegment: ContentModelText, splittedSegmentResult?: ContentModelText[]): string;