@sveltia/ui 0.90.0 → 0.92.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 (284) hide show
  1. package/dist/components/bottom-navigation/bottom-navigation.svelte +3 -9
  2. package/dist/components/bottom-navigation/bottom-navigation.svelte.d.ts +4 -39
  3. package/dist/components/button/button-group.svelte +2 -4
  4. package/dist/components/button/button-group.svelte.d.ts +3 -19
  5. package/dist/components/button/select-button-group.svelte +2 -13
  6. package/dist/components/button/select-button-group.svelte.d.ts +5 -67
  7. package/dist/components/calendar/calendar.d.ts +9 -0
  8. package/dist/components/calendar/calendar.js +43 -0
  9. package/dist/components/calendar/calendar.svelte +26 -27
  10. package/dist/components/checkbox/checkbox-group.svelte +2 -8
  11. package/dist/components/checkbox/checkbox-group.svelte.d.ts +4 -39
  12. package/dist/components/dialog/alert-dialog.svelte.d.ts +2 -3
  13. package/dist/components/dialog/confirmation-dialog.svelte.d.ts +2 -3
  14. package/dist/components/dialog/dialog.svelte +6 -7
  15. package/dist/components/dialog/dialog.svelte.d.ts +2 -3
  16. package/dist/components/dialog/prompt-dialog.svelte +2 -2
  17. package/dist/components/dialog/prompt-dialog.svelte.d.ts +2 -3
  18. package/dist/components/disclosure/disclosure.svelte +14 -16
  19. package/dist/components/disclosure/disclosure.svelte.d.ts +4 -38
  20. package/dist/components/drawer/drawer.svelte +22 -39
  21. package/dist/components/drawer/drawer.svelte.d.ts +3 -24
  22. package/dist/components/grid/grid-body.svelte +2 -3
  23. package/dist/components/grid/grid-body.svelte.d.ts +3 -18
  24. package/dist/components/grid/grid-cell.svelte +2 -8
  25. package/dist/components/grid/grid-cell.svelte.d.ts +3 -22
  26. package/dist/components/grid/grid-col-header.svelte +2 -4
  27. package/dist/components/grid/grid-col-header.svelte.d.ts +3 -19
  28. package/dist/components/grid/grid-foot.svelte +4 -9
  29. package/dist/components/grid/grid-foot.svelte.d.ts +3 -22
  30. package/dist/components/grid/grid-head.svelte +4 -9
  31. package/dist/components/grid/grid-head.svelte.d.ts +3 -22
  32. package/dist/components/grid/grid-row-header.svelte +2 -8
  33. package/dist/components/grid/grid-row-header.svelte.d.ts +3 -22
  34. package/dist/components/grid/grid-row.svelte +4 -5
  35. package/dist/components/grid/grid-row.svelte.d.ts +3 -19
  36. package/dist/components/grid/grid.d.ts +10 -0
  37. package/dist/components/grid/grid.js +11 -0
  38. package/dist/components/grid/grid.svelte +6 -7
  39. package/dist/components/grid/grid.svelte.d.ts +5 -21
  40. package/dist/components/listbox/listbox.svelte +34 -15
  41. package/dist/components/listbox/listbox.svelte.d.ts +5 -69
  42. package/dist/components/listbox/option-group.svelte +2 -8
  43. package/dist/components/listbox/option-group.svelte.d.ts +4 -39
  44. package/dist/components/listbox/option.svelte +2 -1
  45. package/dist/components/menu/menu-item-group.svelte +2 -6
  46. package/dist/components/menu/menu-item-group.svelte.d.ts +3 -22
  47. package/dist/components/menu/menu-item.svelte +5 -1
  48. package/dist/components/menu/menu.svelte +2 -8
  49. package/dist/components/menu/menu.svelte.d.ts +4 -39
  50. package/dist/components/radio/radio-group.svelte +2 -17
  51. package/dist/components/radio/radio-group.svelte.d.ts +5 -67
  52. package/dist/components/radio/radio.svelte +19 -22
  53. package/dist/components/radio/radio.svelte.d.ts +10 -40
  54. package/dist/components/resizable-pane/resizable-handle.svelte +42 -49
  55. package/dist/components/resizable-pane/resizable-pane-group.svelte +44 -58
  56. package/dist/components/resizable-pane/resizable-pane-group.svelte.d.ts +3 -19
  57. package/dist/components/resizable-pane/resizable-pane.svelte +2 -5
  58. package/dist/components/resizable-pane/resizable-pane.svelte.d.ts +3 -19
  59. package/dist/components/resizable-pane/sizing.d.ts +24 -0
  60. package/dist/components/resizable-pane/sizing.js +83 -0
  61. package/dist/components/select/combobox.svelte +35 -39
  62. package/dist/components/select/select-tags.svelte +3 -13
  63. package/dist/components/select/select-tags.svelte.d.ts +5 -67
  64. package/dist/components/slider/slider.d.ts +5 -4
  65. package/dist/components/slider/slider.js +28 -23
  66. package/dist/components/slider/slider.svelte +64 -62
  67. package/dist/components/slider/slider.svelte.d.ts +4 -37
  68. package/dist/components/switch/switch.svelte +2 -13
  69. package/dist/components/switch/switch.svelte.d.ts +5 -67
  70. package/dist/components/table/table-body.svelte +2 -4
  71. package/dist/components/table/table-body.svelte.d.ts +3 -19
  72. package/dist/components/table/table-cell.svelte +2 -8
  73. package/dist/components/table/table-cell.svelte.d.ts +3 -22
  74. package/dist/components/table/table-col-header.svelte +2 -8
  75. package/dist/components/table/table-col-header.svelte.d.ts +3 -22
  76. package/dist/components/table/table-foot.svelte +2 -8
  77. package/dist/components/table/table-foot.svelte.d.ts +3 -22
  78. package/dist/components/table/table-head.svelte +2 -8
  79. package/dist/components/table/table-head.svelte.d.ts +3 -22
  80. package/dist/components/table/table-part.svelte +2 -4
  81. package/dist/components/table/table-part.svelte.d.ts +3 -19
  82. package/dist/components/table/table-row-header.svelte +2 -8
  83. package/dist/components/table/table-row-header.svelte.d.ts +3 -22
  84. package/dist/components/table/table-row.svelte +2 -8
  85. package/dist/components/table/table-row.svelte.d.ts +3 -22
  86. package/dist/components/table/table.svelte +2 -4
  87. package/dist/components/table/table.svelte.d.ts +3 -19
  88. package/dist/components/tabs/tab-box.svelte +2 -4
  89. package/dist/components/tabs/tab-box.svelte.d.ts +3 -19
  90. package/dist/components/tabs/tab-list.svelte +2 -7
  91. package/dist/components/tabs/tab-list.svelte.d.ts +4 -37
  92. package/dist/components/tabs/tab-panel.svelte +2 -8
  93. package/dist/components/tabs/tab-panel.svelte.d.ts +3 -22
  94. package/dist/components/tabs/tab-panels.svelte +2 -8
  95. package/dist/components/tabs/tab-panels.svelte.d.ts +3 -22
  96. package/dist/components/text-editor/code-editor.js +14 -7
  97. package/dist/components/text-editor/code-editor.svelte +14 -22
  98. package/dist/components/text-editor/code-editor.svelte.d.ts +5 -103
  99. package/dist/components/text-editor/config.d.ts +73 -0
  100. package/dist/components/text-editor/config.js +110 -0
  101. package/dist/components/text-editor/constants.d.ts +40 -6
  102. package/dist/components/text-editor/constants.js +81 -7
  103. package/dist/components/text-editor/conversion/editor-components.js +4 -4
  104. package/dist/components/text-editor/conversion/html/components.d.ts +16 -0
  105. package/dist/components/text-editor/conversion/html/components.js +87 -0
  106. package/dist/components/text-editor/conversion/html/export.d.ts +10 -0
  107. package/dist/components/text-editor/conversion/html/export.js +360 -0
  108. package/dist/components/text-editor/conversion/html/import-rules.d.ts +12 -0
  109. package/dist/components/text-editor/conversion/html/import-rules.js +234 -0
  110. package/dist/components/text-editor/conversion/html/index.d.ts +10 -0
  111. package/dist/components/text-editor/conversion/html/index.js +33 -0
  112. package/dist/components/text-editor/conversion/html/paragraph.d.ts +1 -0
  113. package/dist/components/text-editor/conversion/html/paragraph.js +123 -0
  114. package/dist/components/text-editor/conversion/html/task-list.d.ts +13 -0
  115. package/dist/components/text-editor/conversion/html/task-list.js +82 -0
  116. package/dist/components/text-editor/conversion/html/unsupported.d.ts +2 -0
  117. package/dist/components/text-editor/conversion/html/unsupported.js +122 -0
  118. package/dist/components/text-editor/conversion/html/utils.d.ts +6 -0
  119. package/dist/components/text-editor/conversion/html/utils.js +34 -0
  120. package/dist/components/text-editor/conversion/import.js +33 -27
  121. package/dist/components/text-editor/conversion/markdown/block-conversion.d.ts +4 -0
  122. package/dist/components/text-editor/conversion/markdown/block-conversion.js +154 -0
  123. package/dist/components/text-editor/conversion/markdown/block-structure.d.ts +16 -0
  124. package/dist/components/text-editor/conversion/markdown/block-structure.js +254 -0
  125. package/dist/components/text-editor/conversion/markdown/code-blocks.d.ts +57 -0
  126. package/dist/components/text-editor/conversion/markdown/code-blocks.js +279 -0
  127. package/dist/components/text-editor/conversion/markdown/code-spans.d.ts +19 -0
  128. package/dist/components/text-editor/conversion/markdown/code-spans.js +71 -0
  129. package/dist/components/text-editor/conversion/markdown/formatting.d.ts +22 -0
  130. package/dist/components/text-editor/conversion/markdown/formatting.js +451 -0
  131. package/dist/components/text-editor/conversion/markdown/index.d.ts +10 -0
  132. package/dist/components/text-editor/conversion/markdown/index.js +55 -0
  133. package/dist/components/text-editor/conversion/markdown/placeholders.d.ts +2 -0
  134. package/dist/components/text-editor/conversion/markdown/placeholders.js +229 -0
  135. package/dist/components/text-editor/conversion/markdown/syntax.d.ts +99 -0
  136. package/dist/components/text-editor/conversion/markdown/syntax.js +206 -0
  137. package/dist/components/text-editor/conversion/placeholder-chars.d.ts +43 -0
  138. package/dist/components/text-editor/conversion/placeholder-chars.js +51 -0
  139. package/dist/components/text-editor/conversion/transformers/block-escape.d.ts +1 -0
  140. package/dist/components/text-editor/conversion/transformers/block-escape.js +53 -26
  141. package/dist/components/text-editor/conversion/transformers/code.d.ts +3 -14
  142. package/dist/components/text-editor/conversion/transformers/code.js +78 -16
  143. package/dist/components/text-editor/conversion/transformers/formatted-code.js +3 -18
  144. package/dist/components/text-editor/conversion/transformers/inline-code.js +3 -1
  145. package/dist/components/text-editor/conversion/transformers/link.js +3 -1
  146. package/dist/components/text-editor/conversion/transformers/raw-syntax.d.ts +0 -19
  147. package/dist/components/text-editor/conversion/transformers/raw-syntax.js +22 -93
  148. package/dist/components/text-editor/conversion/transformers/table.js +57 -16
  149. package/dist/components/text-editor/conversion/transformers/task-list.d.ts +24 -0
  150. package/dist/components/text-editor/conversion/transformers/task-list.js +53 -0
  151. package/dist/components/text-editor/conversion/update.d.ts +19 -2
  152. package/dist/components/text-editor/conversion/update.js +64 -40
  153. package/dist/components/text-editor/core.d.ts +12 -51
  154. package/dist/components/text-editor/core.js +47 -77
  155. package/dist/components/text-editor/editing/commands.js +9 -18
  156. package/dist/components/text-editor/editing/guards.d.ts +7 -0
  157. package/dist/components/text-editor/editing/guards.js +123 -0
  158. package/dist/components/text-editor/editing/raw-markdown.d.ts +7 -2
  159. package/dist/components/text-editor/editing/raw-markdown.js +68 -8
  160. package/dist/components/text-editor/editing/selection.js +6 -2
  161. package/dist/components/text-editor/lexical-root.svelte +89 -47
  162. package/dist/components/text-editor/lexical-root.svelte.d.ts +4 -67
  163. package/dist/components/text-editor/shiki/{facade.d.ts → engine.d.ts} +8 -8
  164. package/dist/components/text-editor/shiki/{facade.js → engine.js} +53 -156
  165. package/dist/components/text-editor/shiki/highlighter.js +5 -5
  166. package/dist/components/text-editor/shiki/lexical.d.ts +6 -0
  167. package/dist/components/text-editor/shiki/lexical.js +165 -0
  168. package/dist/components/text-editor/shiki/preload.js +1 -1
  169. package/dist/components/text-editor/shiki/source-highlight.svelte.d.ts +15 -0
  170. package/dist/components/text-editor/shiki/source-highlight.svelte.js +120 -0
  171. package/dist/components/text-editor/shiki/version.d.ts +1 -1
  172. package/dist/components/text-editor/shiki/version.js +1 -1
  173. package/dist/components/text-editor/store.svelte.js +65 -16
  174. package/dist/components/text-editor/text-editor.svelte +57 -146
  175. package/dist/components/text-editor/text-editor.svelte.d.ts +9 -105
  176. package/dist/components/text-editor/toolbar/actions.d.ts +25 -0
  177. package/dist/components/text-editor/toolbar/actions.js +107 -0
  178. package/dist/components/text-editor/toolbar/align-menu-button.svelte +16 -14
  179. package/dist/components/text-editor/toolbar/format-text-button.svelte +27 -19
  180. package/dist/components/text-editor/toolbar/insert-horizontal-rule-button.svelte +23 -23
  181. package/dist/components/text-editor/toolbar/insert-item-button.svelte +1 -1
  182. package/dist/components/text-editor/toolbar/insert-link-button.svelte +47 -51
  183. package/dist/components/text-editor/toolbar/insert-menu-button.svelte +1 -1
  184. package/dist/components/text-editor/toolbar/insert-table-button.svelte +35 -52
  185. package/dist/components/text-editor/toolbar/table-action-menu.svelte +19 -17
  186. package/dist/components/text-editor/toolbar/text-editor-toolbar.svelte +34 -11
  187. package/dist/components/text-editor/toolbar/text-editor-toolbar.svelte.d.ts +0 -8
  188. package/dist/components/text-editor/toolbar/toggle-block-menu-item.svelte +35 -41
  189. package/dist/components/text-editor/widgets/emoji-autocomplete.svelte +7 -6
  190. package/dist/components/text-editor/widgets/floating-link-editor.svelte +19 -32
  191. package/dist/components/text-editor/widgets/table-cell-menu-button.svelte +28 -32
  192. package/dist/components/text-field/date-time-input.svelte +7 -8
  193. package/dist/components/text-field/date-time-input.svelte.d.ts +3 -32
  194. package/dist/components/text-field/number-input.d.ts +0 -2
  195. package/dist/components/text-field/number-input.js +25 -25
  196. package/dist/components/text-field/number-input.svelte +18 -9
  197. package/dist/components/text-field/number-input.svelte.d.ts +1 -1
  198. package/dist/components/text-field/text-area.d.ts +2 -0
  199. package/dist/components/text-field/text-area.js +31 -0
  200. package/dist/components/text-field/text-area.svelte +12 -25
  201. package/dist/components/text-field/text-area.svelte.d.ts +5 -67
  202. package/dist/components/toast/toast.svelte +31 -8
  203. package/dist/components/toast/toast.svelte.d.ts +6 -6
  204. package/dist/components/toolbar/toolbar.svelte +2 -7
  205. package/dist/components/toolbar/toolbar.svelte.d.ts +4 -37
  206. package/dist/components/tree/tree-item.svelte +2 -6
  207. package/dist/components/tree/tree-item.svelte.d.ts +3 -22
  208. package/dist/components/tree/tree.svelte +3 -10
  209. package/dist/components/tree/tree.svelte.d.ts +4 -39
  210. package/dist/components/util/group.svelte +2 -7
  211. package/dist/components/util/group.svelte.d.ts +4 -37
  212. package/dist/components/util/modal.d.ts +9 -0
  213. package/dist/components/util/modal.js +30 -0
  214. package/dist/components/util/modal.svelte +16 -12
  215. package/dist/index.d.ts +1 -1
  216. package/dist/index.js +1 -1
  217. package/dist/locales/ar.yaml +2 -0
  218. package/dist/locales/bg.yaml +2 -0
  219. package/dist/locales/ca.yaml +2 -0
  220. package/dist/locales/cs.yaml +2 -0
  221. package/dist/locales/da.yaml +2 -0
  222. package/dist/locales/de.yaml +2 -0
  223. package/dist/locales/el.yaml +2 -0
  224. package/dist/locales/en-CA.yaml +2 -0
  225. package/dist/locales/en-GB.yaml +2 -0
  226. package/dist/locales/en-US.yaml +2 -0
  227. package/dist/locales/en-ZA.yaml +2 -0
  228. package/dist/locales/es-CO.yaml +2 -0
  229. package/dist/locales/es-ES.yaml +2 -0
  230. package/dist/locales/fa.yaml +2 -0
  231. package/dist/locales/fi.yaml +2 -0
  232. package/dist/locales/fr.yaml +2 -0
  233. package/dist/locales/he.yaml +2 -0
  234. package/dist/locales/hr.yaml +2 -0
  235. package/dist/locales/hu.yaml +176 -0
  236. package/dist/locales/it.yaml +2 -0
  237. package/dist/locales/ja.yaml +2 -0
  238. package/dist/locales/ko.yaml +2 -0
  239. package/dist/locales/nl.yaml +2 -0
  240. package/dist/locales/pl.yaml +2 -0
  241. package/dist/locales/pt-BR.yaml +2 -0
  242. package/dist/locales/pt-PT.yaml +2 -0
  243. package/dist/locales/ru.yaml +2 -0
  244. package/dist/locales/sk.yaml +2 -0
  245. package/dist/locales/sv.yaml +2 -0
  246. package/dist/locales/tr.yaml +2 -0
  247. package/dist/locales/uk.yaml +2 -0
  248. package/dist/locales/vi.yaml +2 -0
  249. package/dist/locales/zh-CN.yaml +2 -0
  250. package/dist/locales/zh-TW.yaml +2 -0
  251. package/dist/services/composite-widget.svelte.d.ts +76 -0
  252. package/dist/services/composite-widget.svelte.js +157 -0
  253. package/dist/services/focus.d.ts +2 -0
  254. package/dist/services/focus.js +68 -0
  255. package/dist/services/group.svelte.d.ts +17 -69
  256. package/dist/services/group.svelte.js +128 -391
  257. package/dist/services/label.d.ts +9 -0
  258. package/dist/services/label.js +22 -0
  259. package/dist/services/menu.d.ts +8 -0
  260. package/dist/services/menu.js +237 -0
  261. package/dist/services/navigation.d.ts +9 -0
  262. package/dist/services/navigation.js +13 -0
  263. package/dist/services/number.d.ts +2 -0
  264. package/dist/services/number.js +27 -0
  265. package/dist/services/pointer-drag.d.ts +14 -0
  266. package/dist/services/pointer-drag.js +89 -0
  267. package/dist/services/popup.svelte.js +123 -103
  268. package/dist/services/text.d.ts +3 -0
  269. package/dist/services/text.js +17 -0
  270. package/dist/services/tree.svelte.d.ts +29 -43
  271. package/dist/services/tree.svelte.js +58 -105
  272. package/dist/services/type-ahead.d.ts +10 -1
  273. package/dist/services/type-ahead.js +56 -34
  274. package/dist/typedefs.d.ts +108 -6
  275. package/dist/typedefs.js +63 -6
  276. package/package.json +5 -5
  277. package/dist/components/text-editor/conversion/html.d.ts +0 -30
  278. package/dist/components/text-editor/conversion/html.js +0 -857
  279. package/dist/components/text-editor/conversion/markdown.d.ts +0 -56
  280. package/dist/components/text-editor/conversion/markdown.js +0 -949
  281. package/dist/components/text-editor/toolbar/code-editor-toolbar.svelte +0 -28
  282. package/dist/components/text-editor/toolbar/code-editor-toolbar.svelte.d.ts +0 -37
  283. package/dist/components/text-editor/toolbar/insert-component.d.ts +0 -3
  284. package/dist/components/text-editor/toolbar/insert-component.js +0 -37
@@ -1,10 +1,10 @@
1
1
  export default TextEditor;
2
2
  type TextEditor = {
3
3
  $on?(type: string, callback: (e: any) => void): () => void;
4
- $set?(props: Partial<Props & Record<string, any>>): void;
4
+ $set?(props: Partial<EditorCommonProps & WidgetStateProps & FormFieldStateProps & Props & Record<string, any>>): void;
5
5
  };
6
6
  /** A rich text editor based on Lexical. */
7
- declare const TextEditor: import("svelte").Component<{
7
+ declare const TextEditor: import("svelte").Component<EditorCommonProps & WidgetStateProps & FormFieldStateProps & {
8
8
  /**
9
9
  * Input value in the {@link format}. A value set from outside
10
10
  * is kept as is until the user changes the content, although the rich text editor writes Markdown
@@ -25,10 +25,6 @@ declare const TextEditor: import("svelte").Component<{
25
25
  * change before reading the value, for example to save it. Read-only.
26
26
  */
27
27
  pending?: boolean | undefined;
28
- /**
29
- * Make the text input container flexible.
30
- */
31
- flex?: boolean | undefined;
32
28
  /**
33
29
  * The `dir` attribute on the editable text box, both
34
30
  * the rich text editor and the `<textarea>` element of the plain text mode.
@@ -39,7 +35,8 @@ declare const TextEditor: import("svelte").Component<{
39
35
  */
40
36
  modes?: TextEditorMode[] | undefined;
41
37
  /**
42
- * Enabled buttons.
38
+ * Enabled buttons. All the inline and block level
39
+ * buttons by default, except the HTML-only `underline`.
43
40
  */
44
41
  buttons?: TextEditorNodeType[] | undefined;
45
42
  /**
@@ -70,52 +67,6 @@ declare const TextEditor: import("svelte").Component<{
70
67
  * types a shortcode, like `:smi`.
71
68
  */
72
69
  useEmojiAutocomplete?: boolean | undefined;
73
- /**
74
- * The `class` attribute on the wrapper element.
75
- */
76
- class?: string | undefined;
77
- /**
78
- * Whether to hide the widget.
79
- */
80
- hidden?: boolean | undefined;
81
- /**
82
- * Whether to disable the widget. An alias of the `aria-disabled`
83
- * attribute.
84
- */
85
- disabled?: boolean | undefined;
86
- /**
87
- * Whether to make the widget read-only. An alias of the
88
- * `aria-readonly` attribute.
89
- */
90
- readonly?: boolean | undefined;
91
- /**
92
- * Whether to mark the widget required. An alias of the
93
- * `aria-required` attribute.
94
- */
95
- required?: boolean | undefined;
96
- /**
97
- * Whether to mark the widget invalid. An alias of the
98
- * `aria-invalid` attribute.
99
- */
100
- invalid?: boolean | undefined;
101
- /**
102
- * The `aria-label` attribute on the editable text box. Either
103
- * this or `ariaLabelledby` is required for the editor to have an accessible name.
104
- */
105
- ariaLabel?: string | undefined;
106
- /**
107
- * The `aria-labelledby` attribute on the editable text box.
108
- */
109
- ariaLabelledby?: string | undefined;
110
- /**
111
- * The `aria-describedby` attribute on the editable text
112
- * box.
113
- */
114
- ariaDescribedby?: string | undefined;
115
- /**
116
- * Primary slot content.
117
- */
118
- children?: Snippet<[]> | undefined;
119
70
  } & Record<string, any>, {}, "value" | "pending">;
120
71
  type Props = {
121
72
  /**
@@ -138,10 +89,6 @@ type Props = {
138
89
  * change before reading the value, for example to save it. Read-only.
139
90
  */
140
91
  pending?: boolean | undefined;
141
- /**
142
- * Make the text input container flexible.
143
- */
144
- flex?: boolean | undefined;
145
92
  /**
146
93
  * The `dir` attribute on the editable text box, both
147
94
  * the rich text editor and the `<textarea>` element of the plain text mode.
@@ -152,7 +99,8 @@ type Props = {
152
99
  */
153
100
  modes?: TextEditorMode[] | undefined;
154
101
  /**
155
- * Enabled buttons.
102
+ * Enabled buttons. All the inline and block level
103
+ * buttons by default, except the HTML-only `underline`.
156
104
  */
157
105
  buttons?: TextEditorNodeType[] | undefined;
158
106
  /**
@@ -183,55 +131,11 @@ type Props = {
183
131
  * types a shortcode, like `:smi`.
184
132
  */
185
133
  useEmojiAutocomplete?: boolean | undefined;
186
- /**
187
- * The `class` attribute on the wrapper element.
188
- */
189
- class?: string | undefined;
190
- /**
191
- * Whether to hide the widget.
192
- */
193
- hidden?: boolean | undefined;
194
- /**
195
- * Whether to disable the widget. An alias of the `aria-disabled`
196
- * attribute.
197
- */
198
- disabled?: boolean | undefined;
199
- /**
200
- * Whether to make the widget read-only. An alias of the
201
- * `aria-readonly` attribute.
202
- */
203
- readonly?: boolean | undefined;
204
- /**
205
- * Whether to mark the widget required. An alias of the
206
- * `aria-required` attribute.
207
- */
208
- required?: boolean | undefined;
209
- /**
210
- * Whether to mark the widget invalid. An alias of the
211
- * `aria-invalid` attribute.
212
- */
213
- invalid?: boolean | undefined;
214
- /**
215
- * The `aria-label` attribute on the editable text box. Either
216
- * this or `ariaLabelledby` is required for the editor to have an accessible name.
217
- */
218
- ariaLabel?: string | undefined;
219
- /**
220
- * The `aria-labelledby` attribute on the editable text box.
221
- */
222
- ariaLabelledby?: string | undefined;
223
- /**
224
- * The `aria-describedby` attribute on the editable text
225
- * box.
226
- */
227
- ariaDescribedby?: string | undefined;
228
- /**
229
- * Primary slot content.
230
- */
231
- children?: Snippet<[]> | undefined;
232
134
  };
135
+ import type { EditorCommonProps } from '../../typedefs.js';
136
+ import type { WidgetStateProps } from '../../typedefs.js';
137
+ import type { FormFieldStateProps } from '../../typedefs.js';
233
138
  import type { TextEditorValueFormat } from '../../typedefs.js';
234
139
  import type { TextEditorMode } from '../../typedefs.js';
235
140
  import type { TextEditorNodeType } from '../../typedefs.js';
236
141
  import type { TextEditorComponent } from '../../typedefs.js';
237
- import type { Snippet } from 'svelte';
@@ -0,0 +1,25 @@
1
+ export function runEditorAction(editorStore: TextEditorStore, { raw, rich, focus }: EditorAction): Promise<void>;
2
+ export function refocusEditor(editorStore: TextEditorStore): Promise<void>;
3
+ export function insertEditorComponent(editorStore: TextEditorStore, component: TextEditorComponent): Promise<void>;
4
+ export type EditorAction = {
5
+ /**
6
+ * Edit the `<textarea>`
7
+ * in the plain text mode, which also moves the focus there. Without it, nothing happens in the
8
+ * plain text mode.
9
+ */
10
+ raw?: ((textArea: HTMLTextAreaElement) => void | Promise<void>) | undefined;
11
+ /**
12
+ * Edit the Lexical editor in the
13
+ * rich text mode.
14
+ */
15
+ rich: (editor: LexicalEditor) => void | Promise<void>;
16
+ /**
17
+ * When to move the focus back to the Lexical
18
+ * editor: `after` the edit (default), `before` it, for an edit that applies to the selection the
19
+ * focus restores, or not at all, for an edit that moves the focus on its own.
20
+ */
21
+ focus?: false | "after" | "before" | undefined;
22
+ };
23
+ import type { TextEditorStore } from '../../../typedefs.js';
24
+ import type { TextEditorComponent } from '../../../typedefs.js';
25
+ import type { LexicalEditor } from 'lexical';
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Toolbar actions that work in both the rich text and plain text modes.
3
+ */
4
+
5
+ import { $createParagraphNode as createParagraphNode, $insertNodes as insertNodes } from 'lexical';
6
+ import { focusEditor } from '../editing/caret.js';
7
+ import { insertComponent } from '../editing/raw-markdown.js';
8
+
9
+ /**
10
+ * @import { LexicalEditor } from 'lexical';
11
+ * @import { TextEditorComponent, TextEditorStore } from '../../../typedefs.js';
12
+ */
13
+
14
+ /**
15
+ * @typedef {object} EditorAction
16
+ * @property {(textArea: HTMLTextAreaElement) => void | Promise<void>} [raw] Edit the `<textarea>`
17
+ * in the plain text mode, which also moves the focus there. Without it, nothing happens in the
18
+ * plain text mode.
19
+ * @property {(editor: LexicalEditor) => void | Promise<void>} rich Edit the Lexical editor in the
20
+ * rich text mode.
21
+ * @property {'after' | 'before' | false} [focus] When to move the focus back to the Lexical
22
+ * editor: `after` the edit (default), `before` it, for an edit that applies to the selection the
23
+ * focus restores, or not at all, for an edit that moves the focus on its own.
24
+ */
25
+
26
+ /**
27
+ * Run a toolbar action in the mode the editor is in.
28
+ * @param {TextEditorStore} editorStore Editor store.
29
+ * @param {EditorAction} action Action.
30
+ * @returns {Promise<void>} Nothing.
31
+ */
32
+ export const runEditorAction = async (editorStore, { raw, rich, focus = 'after' }) => {
33
+ const { editor, textArea, useRichText } = editorStore;
34
+
35
+ if (!useRichText) {
36
+ // The toolbar is only enabled while the `<textarea>` is there
37
+ /* v8 ignore else */
38
+ if (raw && textArea) {
39
+ await raw(textArea);
40
+ }
41
+
42
+ return;
43
+ }
44
+
45
+ // The toolbar is only enabled while the editor is there
46
+ /* v8 ignore next 3 */
47
+ if (!editor) {
48
+ return;
49
+ }
50
+
51
+ if (focus === 'before') {
52
+ await focusEditor(editor);
53
+ }
54
+
55
+ await rich(editor);
56
+
57
+ if (focus === 'after') {
58
+ await focusEditor(editor);
59
+ }
60
+ };
61
+
62
+ /**
63
+ * Move the focus back to the editor shown, the Lexical editor or the `<textarea>`, like after a
64
+ * dialog that leaves the focus alone has been closed without changing anything.
65
+ * @param {TextEditorStore} editorStore Editor store.
66
+ * @returns {Promise<void>} Nothing.
67
+ */
68
+ export const refocusEditor = async (editorStore) => {
69
+ const { editor, textArea, useRichText } = editorStore;
70
+
71
+ if (!useRichText) {
72
+ textArea?.focus();
73
+ } else if (editor) {
74
+ await focusEditor(editor);
75
+ }
76
+ };
77
+
78
+ /**
79
+ * Insert a new instance of the given editor component into the editor: its Markdown in the plain
80
+ * text mode, or its node in the rich text mode. The focus is left to the component.
81
+ * @param {TextEditorStore} editorStore Editor store.
82
+ * @param {TextEditorComponent} component Editor component.
83
+ * @returns {Promise<void>} Nothing.
84
+ */
85
+ export const insertEditorComponent = (editorStore, component) =>
86
+ runEditorAction(editorStore, {
87
+ /**
88
+ * Insert the component’s Markdown.
89
+ * @param {HTMLTextAreaElement} textArea `<textarea>` element.
90
+ * @returns {void | Promise<void>} Nothing.
91
+ */
92
+ raw: (textArea) => insertComponent(textArea, component),
93
+ /**
94
+ * Insert the component’s node.
95
+ * @param {LexicalEditor} editor Editor instance.
96
+ */
97
+ rich: (editor) => {
98
+ editor.update(() => {
99
+ const node = component.createNode();
100
+
101
+ // Add an additional paragraph after a block for easier editing. An inline node stays
102
+ // within the text, which may be in a table cell where a paragraph can’t be added
103
+ insertNodes(node.isInline() ? [node] : [node, createParagraphNode()]);
104
+ });
105
+ },
106
+ focus: false,
107
+ });
@@ -12,10 +12,11 @@
12
12
  import MenuItemRadio from '../../menu/menu-item-radio.svelte';
13
13
  import Menu from '../../menu/menu.svelte';
14
14
  import { ALIGNMENT_OPTIONS } from '../constants.js';
15
- import { focusEditor } from '../editing/caret.js';
15
+ import { runEditorAction } from './actions.js';
16
16
  import { waitForMenuToClose } from './menu.js';
17
17
 
18
18
  /**
19
+ * @import { LexicalEditor } from 'lexical';
19
20
  * @import { TextEditorStore } from '../../../typedefs.js';
20
21
  */
21
22
 
@@ -35,20 +36,21 @@
35
36
  * Align the selected blocks, then move the focus back to the editor.
36
37
  * @param {(typeof ALIGNMENT_OPTIONS)[number]['type']} type Alignment.
37
38
  * @param {HTMLElement} item Menu item chosen.
39
+ * @returns {Promise<void>} Nothing.
38
40
  */
39
- const align = async (type, item) => {
40
- const { editor } = editorStore;
41
-
42
- // The menu is only shown in the rich text mode, where the editor is there
43
- /* v8 ignore next 3 */
44
- if (!editor) {
45
- return;
46
- }
47
-
48
- editor.dispatchCommand(FORMAT_ELEMENT_COMMAND, type);
49
- await waitForMenuToClose(item);
50
- await focusEditor(editor);
51
- };
41
+ const align = (type, item) =>
42
+ // The menu is only shown in the rich text mode
43
+ runEditorAction(editorStore, {
44
+ /**
45
+ * Align the selected blocks, and wait for the menu to close.
46
+ * @param {LexicalEditor} editor Editor instance.
47
+ * @returns {Promise<void>} Nothing.
48
+ */
49
+ rich: async (editor) => {
50
+ editor.dispatchCommand(FORMAT_ELEMENT_COMMAND, type);
51
+ await waitForMenuToClose(item);
52
+ },
53
+ });
52
54
  </script>
53
55
 
54
56
  <MenuButton
@@ -4,15 +4,16 @@
4
4
  import { getContext } from 'svelte';
5
5
  import Button from '../../button/button.svelte';
6
6
  import Icon from '../../icon/icon.svelte';
7
- import { AVAILABLE_BUTTONS } from '../constants.js';
8
- import { focusEditor } from '../editing/caret.js';
7
+ import { AVAILABLE_BUTTONS, isHtmlOnlyButton } from '../constants.js';
9
8
  import {
10
9
  editRawText,
11
10
  registerRawTextShortcut,
12
11
  toggleInlineFormat,
13
12
  } from '../editing/raw-markdown.js';
13
+ import { runEditorAction } from './actions.js';
14
14
 
15
15
  /**
16
+ * @import { LexicalEditor } from 'lexical';
16
17
  * @import { TextEditorFormatType, TextEditorStore } from '../../../typedefs.js';
17
18
  */
18
19
 
@@ -42,24 +43,31 @@
42
43
 
43
44
  /**
44
45
  * Format the selection.
46
+ * @returns {Promise<void>} Nothing.
45
47
  */
46
- const format = async () => {
47
- const { editor, textArea, useRichText } = editorStore;
48
-
49
- if (!useRichText) {
50
- // The button is only enabled while the `<textarea>` is there
51
- editRawText(textArea, (state) => toggleInlineFormat(state, type));
52
-
53
- return;
54
- }
55
-
56
- // The button is only enabled while the editor is there
57
- /* v8 ignore else */
58
- if (editor) {
59
- await focusEditor(editor);
60
- editor.dispatchCommand(FORMAT_TEXT_COMMAND, type);
61
- }
62
- };
48
+ const format = () =>
49
+ runEditorAction(editorStore, {
50
+ /**
51
+ * Format the selected Markdown.
52
+ * @param {HTMLTextAreaElement} textArea `<textarea>` element.
53
+ */
54
+ raw: (textArea) => {
55
+ // The `<textarea>` is only there for Markdown, which hides the HTML-only formats
56
+ /* v8 ignore else */
57
+ if (!isHtmlOnlyButton(type)) {
58
+ editRawText(textArea, (state) => toggleInlineFormat(state, type));
59
+ }
60
+ },
61
+ /**
62
+ * Format the selection.
63
+ * @param {LexicalEditor} editor Editor instance.
64
+ */
65
+ rich: (editor) => {
66
+ editor.dispatchCommand(FORMAT_TEXT_COMMAND, type);
67
+ },
68
+ // The format applies to the selection, which the focus restores
69
+ focus: 'before',
70
+ });
63
71
 
64
72
  $effect(() => {
65
73
  const { textArea } = editorStore;
@@ -10,11 +10,12 @@
10
10
  import Icon from '../../icon/icon.svelte';
11
11
  import { $insertHorizontalRule as insertHorizontalRule } from '../editing/block.js';
12
12
  import { AVAILABLE_BUTTONS } from '../constants.js';
13
- import { focusEditor } from '../editing/caret.js';
14
13
  import { editRawText, insertMarkdown } from '../editing/raw-markdown.js';
15
14
  import { HORIZONTAL_RULE_MARKDOWN } from '../conversion/transformers/hr.js';
15
+ import { runEditorAction } from './actions.js';
16
16
 
17
17
  /**
18
+ * @import { LexicalEditor } from 'lexical';
18
19
  * @import { TextEditorStore } from '../../../typedefs.js';
19
20
  */
20
21
 
@@ -25,30 +26,29 @@
25
26
 
26
27
  /**
27
28
  * Insert a horizontal rule, then move the focus back to the editor.
29
+ * @returns {Promise<void>} Nothing.
28
30
  */
29
- const insert = async () => {
30
- const { editor, textArea, useRichText } = editorStore;
31
-
32
- if (!useRichText) {
33
- await editRawText(textArea, (state) =>
34
- insertMarkdown(state, HORIZONTAL_RULE_MARKDOWN, { block: true }),
35
- );
36
-
37
- return;
38
- }
39
-
40
- // The button is only enabled while the editor is there
41
- /* v8 ignore next 3 */
42
- if (!editor) {
43
- return;
44
- }
45
-
46
- editor.update(() => {
47
- insertHorizontalRule();
31
+ const insert = () =>
32
+ runEditorAction(editorStore, {
33
+ /**
34
+ * Insert the Markdown.
35
+ * @param {HTMLTextAreaElement} textArea `<textarea>` element.
36
+ * @returns {void | Promise<void>} Nothing.
37
+ */
38
+ raw: (textArea) =>
39
+ editRawText(textArea, (state) =>
40
+ insertMarkdown(state, HORIZONTAL_RULE_MARKDOWN, { block: true }),
41
+ ),
42
+ /**
43
+ * Insert a horizontal rule node.
44
+ * @param {LexicalEditor} editor Editor instance.
45
+ */
46
+ rich: (editor) => {
47
+ editor.update(() => {
48
+ insertHorizontalRule();
49
+ });
50
+ },
48
51
  });
49
-
50
- await focusEditor(editor);
51
- };
52
52
  </script>
53
53
 
54
54
  <Button
@@ -2,7 +2,7 @@
2
2
  import { getContext } from 'svelte';
3
3
  import Button from '../../button/button.svelte';
4
4
  import Icon from '../../icon/icon.svelte';
5
- import { insertEditorComponent } from './insert-component.js';
5
+ import { insertEditorComponent } from './actions.js';
6
6
 
7
7
  /**
8
8
  * @import { TextEditorComponent, TextEditorStore } from '../../../typedefs.js';
@@ -30,8 +30,10 @@
30
30
  insertLink,
31
31
  registerRawTextShortcut,
32
32
  } from '../editing/raw-markdown.js';
33
+ import { refocusEditor, runEditorAction } from './actions.js';
33
34
 
34
35
  /**
36
+ * @import { LexicalEditor } from 'lexical';
35
37
  * @import { TextEditorStore } from '../../../typedefs.js';
36
38
  */
37
39
 
@@ -128,61 +130,55 @@
128
130
  * @see https://github.com/facebook/lexical/discussions/3013
129
131
  */
130
132
  const onDialogClose = async (event) => {
131
- const { textArea, useRichText } = editorStore;
132
-
133
- if (!useRichText) {
134
- // The dialog can only be opened from the button, which needs the `<textarea>`
135
- /* v8 ignore else */
136
- if (textArea) {
137
- if (event.detail.returnValue !== 'cancel') {
133
+ if (event.detail.returnValue === 'cancel') {
134
+ // The dialog leaves the focus alone (see `restoreFocus` below), so bring it back here
135
+ await refocusEditor(editorStore);
136
+ } else {
137
+ await runEditorAction(editorStore, {
138
+ /**
139
+ * Insert the link’s Markdown.
140
+ * @param {HTMLTextAreaElement} textArea `<textarea>` element.
141
+ * @returns {void | Promise<void>} Nothing.
142
+ */
143
+ raw: (textArea) =>
138
144
  editRawText(textArea, (state) =>
139
145
  insertLink(state, { url: anchorURL.trim(), text: hasAnchor ? undefined : anchorText }),
146
+ ),
147
+ /**
148
+ * Insert the link text if needed, and link the selection.
149
+ * @param {LexicalEditor} editor Editor instance.
150
+ * @returns {Promise<void>} Nothing.
151
+ */
152
+ rich: async (editor) => {
153
+ await new Promise((resolve) => {
154
+ editor.update(async () => {
155
+ let _selection = getSelection() ?? getPreviousSelection()?.clone();
156
+
157
+ if (!isRangeSelection(_selection)) {
158
+ _selection = createRangeSelection();
159
+ }
160
+
161
+ if (!hasAnchor) {
162
+ anchorText = anchorText.trim();
163
+ anchorText ||= anchorURL;
164
+ insertNodes([createTextNode(anchorText)]);
165
+ }
166
+
167
+ setSelection(_selection);
168
+ resolve(undefined);
169
+ });
170
+ });
171
+
172
+ // The link applies to the selection, which the focus restores
173
+ await focusEditor(editor);
174
+ editor.dispatchCommand(
175
+ TOGGLE_LINK_COMMAND,
176
+ canSetTarget && openInNewTab ? { url: anchorURL, target: '_blank' } : anchorURL,
140
177
  );
141
- } else {
142
- textArea.focus();
143
- }
144
- }
145
-
146
- anchorURL = '';
147
- anchorText = '';
148
-
149
- return;
150
- }
151
-
152
- if (event.detail.returnValue !== 'cancel') {
153
- // The dialog can only be opened from the button, which needs the editor
154
- /* v8 ignore next */
155
- if (!editorStore.editor) {
156
- return;
157
- }
158
-
159
- await new Promise((resolve) => {
160
- editorStore.editor?.update(async () => {
161
- let _selection = getSelection() ?? getPreviousSelection()?.clone();
162
-
163
- if (!isRangeSelection(_selection)) {
164
- _selection = createRangeSelection();
165
- }
166
-
167
- if (!hasAnchor) {
168
- anchorText = anchorText.trim();
169
- anchorText ||= anchorURL;
170
- insertNodes([createTextNode(anchorText)]);
171
- }
172
-
173
- setSelection(_selection);
174
- resolve(undefined);
175
- });
178
+ },
179
+ // Moved within the edit above, between inserting the text and linking it
180
+ focus: false,
176
181
  });
177
-
178
- await focusEditor(editorStore.editor);
179
- editorStore.editor.dispatchCommand(
180
- TOGGLE_LINK_COMMAND,
181
- canSetTarget && openInNewTab ? { url: anchorURL, target: '_blank' } : anchorURL,
182
- );
183
- } else /* v8 ignore else */ if (editorStore.editor) {
184
- // The dialog leaves the focus alone (see `restoreFocus` below), so bring it back here
185
- await focusEditor(editorStore.editor);
186
182
  }
187
183
 
188
184
  anchorURL = '';
@@ -5,7 +5,7 @@
5
5
  import MenuButton from '../../menu/menu-button.svelte';
6
6
  import MenuItem from '../../menu/menu-item.svelte';
7
7
  import Menu from '../../menu/menu.svelte';
8
- import { insertEditorComponent } from './insert-component.js';
8
+ import { insertEditorComponent } from './actions.js';
9
9
 
10
10
  /**
11
11
  * @import { TextEditorComponent, TextEditorStore } from '../../../typedefs.js';