@sveltia/ui 0.91.0 → 0.92.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (226) 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/conversion/editor-components.js +4 -4
  102. package/dist/components/text-editor/conversion/html/export.js +1 -1
  103. package/dist/components/text-editor/conversion/import.js +32 -26
  104. package/dist/components/text-editor/conversion/markdown/block-conversion.d.ts +4 -0
  105. package/dist/components/text-editor/conversion/markdown/block-conversion.js +154 -0
  106. package/dist/components/text-editor/conversion/markdown/block-structure.d.ts +16 -0
  107. package/dist/components/text-editor/conversion/markdown/block-structure.js +254 -0
  108. package/dist/components/text-editor/conversion/markdown/code-blocks.d.ts +57 -0
  109. package/dist/components/text-editor/conversion/markdown/code-blocks.js +279 -0
  110. package/dist/components/text-editor/conversion/markdown/code-spans.d.ts +19 -0
  111. package/dist/components/text-editor/conversion/markdown/code-spans.js +71 -0
  112. package/dist/components/text-editor/conversion/markdown/formatting.d.ts +22 -0
  113. package/dist/components/text-editor/conversion/markdown/formatting.js +451 -0
  114. package/dist/components/text-editor/conversion/markdown/index.d.ts +10 -0
  115. package/dist/components/text-editor/conversion/markdown/index.js +55 -0
  116. package/dist/components/text-editor/conversion/markdown/placeholders.d.ts +2 -0
  117. package/dist/components/text-editor/conversion/markdown/placeholders.js +229 -0
  118. package/dist/components/text-editor/conversion/markdown/syntax.d.ts +99 -0
  119. package/dist/components/text-editor/conversion/markdown/syntax.js +206 -0
  120. package/dist/components/text-editor/conversion/placeholder-chars.d.ts +43 -0
  121. package/dist/components/text-editor/conversion/placeholder-chars.js +51 -0
  122. package/dist/components/text-editor/conversion/transformers/block-escape.d.ts +1 -0
  123. package/dist/components/text-editor/conversion/transformers/block-escape.js +53 -26
  124. package/dist/components/text-editor/conversion/transformers/code.d.ts +3 -14
  125. package/dist/components/text-editor/conversion/transformers/code.js +78 -16
  126. package/dist/components/text-editor/conversion/transformers/formatted-code.js +3 -18
  127. package/dist/components/text-editor/conversion/transformers/inline-code.js +3 -1
  128. package/dist/components/text-editor/conversion/transformers/link.js +3 -1
  129. package/dist/components/text-editor/conversion/transformers/raw-syntax.d.ts +0 -19
  130. package/dist/components/text-editor/conversion/transformers/raw-syntax.js +22 -93
  131. package/dist/components/text-editor/conversion/transformers/table.js +57 -16
  132. package/dist/components/text-editor/conversion/update.d.ts +19 -2
  133. package/dist/components/text-editor/conversion/update.js +63 -39
  134. package/dist/components/text-editor/core.d.ts +12 -51
  135. package/dist/components/text-editor/core.js +44 -66
  136. package/dist/components/text-editor/editing/raw-markdown.d.ts +3 -0
  137. package/dist/components/text-editor/editing/raw-markdown.js +46 -2
  138. package/dist/components/text-editor/lexical-root.svelte +49 -47
  139. package/dist/components/text-editor/lexical-root.svelte.d.ts +4 -67
  140. package/dist/components/text-editor/shiki/{facade.d.ts → engine.d.ts} +8 -8
  141. package/dist/components/text-editor/shiki/{facade.js → engine.js} +53 -156
  142. package/dist/components/text-editor/shiki/highlighter.js +5 -5
  143. package/dist/components/text-editor/shiki/lexical.d.ts +6 -0
  144. package/dist/components/text-editor/shiki/lexical.js +165 -0
  145. package/dist/components/text-editor/shiki/preload.js +1 -1
  146. package/dist/components/text-editor/shiki/source-highlight.svelte.d.ts +15 -0
  147. package/dist/components/text-editor/shiki/source-highlight.svelte.js +120 -0
  148. package/dist/components/text-editor/shiki/version.d.ts +1 -1
  149. package/dist/components/text-editor/shiki/version.js +1 -1
  150. package/dist/components/text-editor/store.svelte.js +65 -16
  151. package/dist/components/text-editor/text-editor.svelte +53 -145
  152. package/dist/components/text-editor/text-editor.svelte.d.ts +5 -103
  153. package/dist/components/text-editor/toolbar/actions.d.ts +25 -0
  154. package/dist/components/text-editor/toolbar/actions.js +107 -0
  155. package/dist/components/text-editor/toolbar/align-menu-button.svelte +16 -14
  156. package/dist/components/text-editor/toolbar/format-text-button.svelte +26 -24
  157. package/dist/components/text-editor/toolbar/insert-horizontal-rule-button.svelte +23 -23
  158. package/dist/components/text-editor/toolbar/insert-item-button.svelte +1 -1
  159. package/dist/components/text-editor/toolbar/insert-link-button.svelte +47 -51
  160. package/dist/components/text-editor/toolbar/insert-menu-button.svelte +1 -1
  161. package/dist/components/text-editor/toolbar/insert-table-button.svelte +35 -52
  162. package/dist/components/text-editor/toolbar/table-action-menu.svelte +19 -17
  163. package/dist/components/text-editor/toolbar/text-editor-toolbar.svelte +16 -4
  164. package/dist/components/text-editor/toolbar/text-editor-toolbar.svelte.d.ts +0 -8
  165. package/dist/components/text-editor/toolbar/toggle-block-menu-item.svelte +34 -33
  166. package/dist/components/text-editor/widgets/emoji-autocomplete.svelte +7 -6
  167. package/dist/components/text-editor/widgets/floating-link-editor.svelte +19 -32
  168. package/dist/components/text-editor/widgets/table-cell-menu-button.svelte +28 -32
  169. package/dist/components/text-field/date-time-input.svelte +7 -8
  170. package/dist/components/text-field/date-time-input.svelte.d.ts +3 -32
  171. package/dist/components/text-field/number-input.d.ts +0 -2
  172. package/dist/components/text-field/number-input.js +25 -25
  173. package/dist/components/text-field/number-input.svelte +18 -9
  174. package/dist/components/text-field/number-input.svelte.d.ts +1 -1
  175. package/dist/components/text-field/text-area.d.ts +2 -0
  176. package/dist/components/text-field/text-area.js +31 -0
  177. package/dist/components/text-field/text-area.svelte +12 -25
  178. package/dist/components/text-field/text-area.svelte.d.ts +5 -67
  179. package/dist/components/toast/toast.svelte +31 -8
  180. package/dist/components/toast/toast.svelte.d.ts +6 -6
  181. package/dist/components/toolbar/toolbar.svelte +2 -7
  182. package/dist/components/toolbar/toolbar.svelte.d.ts +4 -37
  183. package/dist/components/tree/tree-item.svelte +2 -6
  184. package/dist/components/tree/tree-item.svelte.d.ts +3 -22
  185. package/dist/components/tree/tree.svelte +3 -10
  186. package/dist/components/tree/tree.svelte.d.ts +4 -39
  187. package/dist/components/util/group.svelte +2 -7
  188. package/dist/components/util/group.svelte.d.ts +4 -37
  189. package/dist/components/util/modal.d.ts +9 -0
  190. package/dist/components/util/modal.js +30 -0
  191. package/dist/components/util/modal.svelte +33 -14
  192. package/dist/index.d.ts +1 -1
  193. package/dist/index.js +1 -1
  194. package/dist/locales/hu.yaml +176 -0
  195. package/dist/services/composite-widget.svelte.d.ts +76 -0
  196. package/dist/services/composite-widget.svelte.js +157 -0
  197. package/dist/services/focus.d.ts +2 -0
  198. package/dist/services/focus.js +68 -0
  199. package/dist/services/group.svelte.d.ts +17 -69
  200. package/dist/services/group.svelte.js +128 -391
  201. package/dist/services/label.d.ts +9 -0
  202. package/dist/services/label.js +22 -0
  203. package/dist/services/menu.d.ts +8 -0
  204. package/dist/services/menu.js +237 -0
  205. package/dist/services/navigation.d.ts +9 -0
  206. package/dist/services/navigation.js +13 -0
  207. package/dist/services/number.d.ts +2 -0
  208. package/dist/services/number.js +27 -0
  209. package/dist/services/pointer-drag.d.ts +14 -0
  210. package/dist/services/pointer-drag.js +89 -0
  211. package/dist/services/popup.svelte.js +123 -103
  212. package/dist/services/text.d.ts +3 -0
  213. package/dist/services/text.js +17 -0
  214. package/dist/services/tree.svelte.d.ts +29 -43
  215. package/dist/services/tree.svelte.js +58 -105
  216. package/dist/services/type-ahead.d.ts +10 -1
  217. package/dist/services/type-ahead.js +56 -34
  218. package/dist/typedefs.d.ts +103 -4
  219. package/dist/typedefs.js +60 -4
  220. package/package.json +2 -2
  221. package/dist/components/text-editor/conversion/markdown.d.ts +0 -56
  222. package/dist/components/text-editor/conversion/markdown.js +0 -949
  223. package/dist/components/text-editor/toolbar/code-editor-toolbar.svelte +0 -28
  224. package/dist/components/text-editor/toolbar/code-editor-toolbar.svelte.d.ts +0 -37
  225. package/dist/components/text-editor/toolbar/insert-component.d.ts +0 -3
  226. package/dist/components/text-editor/toolbar/insert-component.js +0 -37
@@ -13,15 +13,16 @@
13
13
  import Icon from '../../icon/icon.svelte';
14
14
  import NumberInput from '../../text-field/number-input.svelte';
15
15
  import { AVAILABLE_BUTTONS, DEFAULT_TABLE_SIZE, MAX_TABLE_SIZE } from '../constants.js';
16
- import { focusEditor } from '../editing/caret.js';
17
16
  import { editRawText, insertMarkdown } from '../editing/raw-markdown.js';
18
17
  import {
19
18
  $insertTable as insertTable,
20
19
  createTableMarkdown,
21
20
  parseTableSize,
22
21
  } from '../editing/table.js';
22
+ import { refocusEditor, runEditorAction } from './actions.js';
23
23
 
24
24
  /**
25
+ * @import { LexicalEditor } from 'lexical';
25
26
  * @import { TextEditorStore } from '../../../typedefs.js';
26
27
  */
27
28
 
@@ -85,42 +86,40 @@
85
86
  };
86
87
 
87
88
  /**
88
- * Insert the table into the rich text editor, then move the focus back to it, where the caret is
89
- * in the first cell.
89
+ * Insert the table: a table node into the rich text editor, then move the focus back to it, or
90
+ * the table’s Markdown into the `<textarea>`. Either way, the caret ends up in the first cell.
90
91
  * @param {TableSize} size Table size.
92
+ * @returns {Promise<void>} Nothing.
91
93
  */
92
- const insertRichText = async ({ rows: rowSize, columns: columnSize }) => {
93
- const { editor } = editorStore;
94
-
95
- // The button is only enabled while the editor is there
96
- /* v8 ignore next 3 */
97
- if (!editor) {
98
- return;
99
- }
100
-
101
- editor.update(() => {
102
- insertTable(rowSize, columnSize);
94
+ const insert = ({ rows: rowSize, columns: columnSize }) =>
95
+ runEditorAction(editorStore, {
96
+ /**
97
+ * Insert the table’s Markdown, with the caret in the first cell.
98
+ * @param {HTMLTextAreaElement} textArea `<textarea>` element.
99
+ * @returns {void | Promise<void>} Nothing.
100
+ */
101
+ raw: (textArea) => {
102
+ const markdown = createTableMarkdown(rowSize, columnSize);
103
+
104
+ return editRawText(textArea, (state) => {
105
+ const edit = insertMarkdown(state, markdown, { block: true });
106
+ // Right after the leading pipe and space of the first cell
107
+ const caret = edit.start + edit.text.indexOf(markdown) + 2;
108
+
109
+ return { ...edit, selectionStart: caret, selectionEnd: caret };
110
+ });
111
+ },
112
+ /**
113
+ * Insert a table node.
114
+ * @param {LexicalEditor} editor Editor instance.
115
+ */
116
+ rich: (editor) => {
117
+ editor.update(() => {
118
+ insertTable(rowSize, columnSize);
119
+ });
120
+ },
103
121
  });
104
122
 
105
- await focusEditor(editor);
106
- };
107
-
108
- /**
109
- * Insert the table’s Markdown into the `<textarea>`, with the caret in the first cell.
110
- * @param {TableSize} size Table size.
111
- */
112
- const insertPlainText = async ({ rows: rowSize, columns: columnSize }) => {
113
- const markdown = createTableMarkdown(rowSize, columnSize);
114
-
115
- await editRawText(editorStore.textArea, (state) => {
116
- const edit = insertMarkdown(state, markdown, { block: true });
117
- // Right after the leading pipe and space of the first cell
118
- const caret = edit.start + edit.text.indexOf(markdown) + 2;
119
-
120
- return { ...edit, selectionStart: caret, selectionEnd: caret };
121
- });
122
- };
123
-
124
123
  /**
125
124
  * Handle `close` event fired on the dialog. Insert the table unless the dialog has been canceled.
126
125
  * @param {CustomEvent} event `close` event.
@@ -129,26 +128,10 @@
129
128
  const canceled = event.detail.returnValue === 'cancel';
130
129
 
131
130
  if (!canceled && rowCount && columnCount) {
132
- const size = { rows: rowCount, columns: columnCount };
133
-
134
- if (editorStore.useRichText) {
135
- await insertRichText(size);
136
- } else {
137
- await insertPlainText(size);
138
- }
139
-
140
- return;
141
- }
142
-
143
- // The dialog leaves the focus alone (see `restoreFocus` below), so bring it back here
144
- if (editorStore.useRichText) {
145
- // The button is only enabled while the editor is there
146
- /* v8 ignore else */
147
- if (editorStore.editor) {
148
- await focusEditor(editorStore.editor);
149
- }
131
+ await insert({ rows: rowCount, columns: columnCount });
150
132
  } else {
151
- editorStore.textArea?.focus();
133
+ // The dialog leaves the focus alone (see `restoreFocus` below), so bring it back here
134
+ await refocusEditor(editorStore);
152
135
  }
153
136
  };
154
137
  </script>
@@ -9,11 +9,12 @@
9
9
  import Divider from '../../divider/divider.svelte';
10
10
  import MenuItem from '../../menu/menu-item.svelte';
11
11
  import Menu from '../../menu/menu.svelte';
12
- import { focusEditor } from '../editing/caret.js';
13
12
  import { isRightToLeftTable, $runTableAction as runTableAction } from '../editing/table.js';
13
+ import { runEditorAction } from './actions.js';
14
14
  import { waitForMenuToClose } from './menu.js';
15
15
 
16
16
  /**
17
+ * @import { LexicalEditor } from 'lexical';
17
18
  * @import { TextEditorStore } from '../../../typedefs.js';
18
19
  * @import { TableAction } from '../editing/table.js';
19
20
  */
@@ -57,26 +58,27 @@
57
58
  * Run the given operation on the cell, then move the focus back to the editor.
58
59
  * @param {TableAction} action Operation.
59
60
  * @param {HTMLElement} item Menu item chosen.
61
+ * @returns {Promise<void>} Nothing.
60
62
  */
61
- const runAction = async (action, item) => {
62
- const { editor } = editorStore;
63
+ const runAction = (action, item) =>
64
+ // The menu is only shown for a cell in the rich text editor
65
+ runEditorAction(editorStore, {
66
+ /**
67
+ * Run the operation, and wait for the menu to close.
68
+ * @param {LexicalEditor} editor Editor instance.
69
+ * @returns {Promise<void>} Nothing.
70
+ */
71
+ rich: async (editor) => {
72
+ const cell = editor.getElementByKey(cellKey);
73
+ const rtl = !!cell && isRightToLeftTable(cell);
63
74
 
64
- // The menu is only shown for a cell in the editor
65
- /* v8 ignore next 3 */
66
- if (!editor) {
67
- return;
68
- }
75
+ editor.update(() => {
76
+ runTableAction(action, cellKey, { rtl });
77
+ });
69
78
 
70
- const cell = editor.getElementByKey(cellKey);
71
- const rtl = !!cell && isRightToLeftTable(cell);
72
-
73
- editor.update(() => {
74
- runTableAction(action, cellKey, { rtl });
79
+ await waitForMenuToClose(item);
80
+ },
75
81
  });
76
-
77
- await waitForMenuToClose(item);
78
- await focusEditor(editor);
79
- };
80
82
  </script>
81
83
 
82
84
  <Menu ariaLabel={_('_sui.text_editor.table_options')}>
@@ -15,6 +15,7 @@
15
15
  INLINE_BUTTON_TYPES,
16
16
  isHtmlOnlyButton,
17
17
  } from '../constants.js';
18
+ import { getEditorSetup } from '../config.js';
18
19
  import { isInlineComponent } from '../conversion/editor-components.js';
19
20
  import CodeLanguageSwitcher from './code-language-switcher.svelte';
20
21
  import AlignMenuButton from './align-menu-button.svelte';
@@ -29,12 +30,16 @@
29
30
  import ToolbarWrapper from './toolbar-wrapper.svelte';
30
31
 
31
32
  /**
32
- * @import { TextEditorBlockType, TextEditorInlineType, TextEditorStore } from '../../../typedefs.js';
33
+ * @import {
34
+ * TextEditorBlockType,
35
+ * TextEditorInlineType,
36
+ * TextEditorStore,
37
+ * } from '../../../typedefs.js';
38
+ * @import { NormalizedEditorConfig } from '../config.js';
33
39
  */
34
40
 
35
41
  /**
36
42
  * @typedef {object} Props
37
- * @property {boolean} [hidden] Whether to hide the widget.
38
43
  * @property {boolean} [disabled] Whether to disable the widget. An alias of the `aria-disabled`
39
44
  * attribute.
40
45
  * @property {boolean} [readonly] Whether to make the widget read-only. An alias of the
@@ -81,11 +86,13 @@
81
86
  */
82
87
  const canUseHtmlOnlyButtons = $derived(isHtml && editorStore.useRichText);
83
88
 
84
- const hasTable = $derived(editorStore.config.enabledButtons.includes('table'));
89
+ // The store holds the configuration normalized
90
+ const { hasTable, hasHorizontalRule } = $derived(
91
+ getEditorSetup(/** @type {NormalizedEditorConfig} */ (editorStore.config)),
92
+ );
85
93
  const canAlign = $derived(
86
94
  canUseHtmlOnlyButtons && editorStore.config.enabledButtons.includes('align'),
87
95
  );
88
- const hasHorizontalRule = $derived(editorStore.config.enabledButtons.includes('horizontal-rule'));
89
96
  /**
90
97
  * Key of the table cell the caret is in, if any. The table menu only works with the rich text
91
98
  * editor.
@@ -225,6 +232,11 @@
225
232
  pressed={!editorStore.useRichText}
226
233
  aria-label={_(`_sui.text_editor.${isHtml ? 'edit_in_html' : 'edit_in_markdown'}`)}
227
234
  onclick={() => {
235
+ // The source shows the value, which has to include what was just typed
236
+ if (editorStore.useRichText) {
237
+ editorStore.flushExport();
238
+ }
239
+
228
240
  editorStore.useRichText = !editorStore.useRichText;
229
241
 
230
242
  if (editorStore.useRichText) {
@@ -4,10 +4,6 @@ type TextEditorToolbar = {
4
4
  $set?(props: Partial<Props & Record<string, any>>): void;
5
5
  };
6
6
  declare const TextEditorToolbar: import("svelte").Component<{
7
- /**
8
- * Whether to hide the widget.
9
- */
10
- hidden?: boolean | undefined;
11
7
  /**
12
8
  * Whether to disable the widget. An alias of the `aria-disabled`
13
9
  * attribute.
@@ -20,10 +16,6 @@ declare const TextEditorToolbar: import("svelte").Component<{
20
16
  readonly?: boolean | undefined;
21
17
  } & Record<string, any>, {}, "">;
22
18
  type Props = {
23
- /**
24
- * Whether to hide the widget.
25
- */
26
- hidden?: boolean | undefined;
27
19
  /**
28
20
  * Whether to disable the widget. An alias of the `aria-disabled`
29
21
  * attribute.
@@ -14,13 +14,13 @@
14
14
  import Icon from '../../icon/icon.svelte';
15
15
  import MenuItemCheckbox from '../../menu/menu-item-checkbox.svelte';
16
16
  import { AVAILABLE_BUTTONS, LIST_TYPES } from '../constants.js';
17
- import { focusEditor } from '../editing/caret.js';
18
17
  import { editRawText, setBlockType } from '../editing/raw-markdown.js';
18
+ import { runEditorAction } from './actions.js';
19
19
 
20
20
  /**
21
21
  * @import { TextEditorBlockType, TextEditorStore } from '../../../typedefs.js';
22
22
  * @import { HeadingTagType } from '@lexical/rich-text';
23
- * @import { ElementNode } from 'lexical';
23
+ * @import { ElementNode, LexicalEditor } from 'lexical';
24
24
  */
25
25
 
26
26
  /**
@@ -54,42 +54,43 @@
54
54
 
55
55
  /**
56
56
  * Change the current selection’s type to {@link type}.
57
+ * @returns {Promise<void>} Nothing.
57
58
  */
58
- const changeBlockType = async () => {
59
- if (!editorStore.useRichText) {
60
- // The item is only clickable while the `<textarea>` is there
61
- editRawText(editorStore.textArea, (state) => setBlockType(state, type));
59
+ const changeBlockType = () =>
60
+ runEditorAction(editorStore, {
61
+ /**
62
+ * Change the block type in the Markdown.
63
+ * @param {HTMLTextAreaElement} textArea `<textarea>` element.
64
+ * @returns {void | Promise<void>} Nothing.
65
+ */
66
+ raw: (textArea) => editRawText(textArea, (state) => setBlockType(state, type)),
67
+ /**
68
+ * Change the block type of the selection.
69
+ * @param {LexicalEditor} editor Editor instance.
70
+ */
71
+ rich: (editor) => {
72
+ const [, headingLevel] = type.match(/^heading-(\d)$/) ?? [];
62
73
 
63
- return;
64
- }
74
+ const createNode = headingLevel
75
+ ? () => createHeadingNode(/** @type {HeadingTagType} */ (`h${headingLevel}`))
76
+ : NODE_FACTORIES[type];
65
77
 
66
- // The item is only clickable while the editor is there
67
- /* v8 ignore next */
68
- if (!editorStore.editor) {
69
- return;
70
- }
78
+ if (createNode) {
79
+ editor.update(() => {
80
+ setBlocksType(getSelection(), createNode);
81
+ });
82
+ }
71
83
 
72
- await focusEditor(editorStore.editor);
84
+ // A list is toggled by its command instead
85
+ const list = LIST_TYPES.find((item) => item.type === type);
73
86
 
74
- const [, headingLevel] = type.match(/^heading-(\d)$/) ?? [];
75
-
76
- const createNode = headingLevel
77
- ? () => createHeadingNode(/** @type {HeadingTagType} */ (`h${headingLevel}`))
78
- : NODE_FACTORIES[type];
79
-
80
- if (createNode) {
81
- editorStore.editor.update(() => {
82
- setBlocksType(getSelection(), createNode);
83
- });
84
- }
85
-
86
- // A list is toggled by its command instead
87
- const list = LIST_TYPES.find((item) => item.type === type);
88
-
89
- if (list) {
90
- editorStore.editor.dispatchCommand(list.command, undefined);
91
- }
92
- };
87
+ if (list) {
88
+ editor.dispatchCommand(list.command, undefined);
89
+ }
90
+ },
91
+ // The block type applies to the selection, which the focus restores
92
+ focus: 'before',
93
+ });
93
94
  </script>
94
95
 
95
96
  {#key selectionTypeMatches}
@@ -22,6 +22,7 @@
22
22
  import { getContext } from 'svelte';
23
23
  import { detectEmojiTrigger, getEmojiInsertText } from '../../emoji/emoji.js';
24
24
  import EmojiSuggestions from '../../emoji/emoji-suggestions.svelte';
25
+ import { mergeUnregisters } from '../utils.js';
25
26
 
26
27
  /**
27
28
  * @import { EmojiAnchorRect, EmojiEntry, EmojiTrigger, TextEditorStore } from '../../../typedefs.js';
@@ -135,7 +136,7 @@
135
136
  * shortcodes. The shortcuts are registered with the highest priority, so they take precedence
136
137
  * over the editor’s own handling while the list is open, and return `false` otherwise to leave
137
138
  * the editor alone.
138
- * @returns {Array<() => void>} Cleanup handlers.
139
+ * @returns {() => void} Cleanup handler.
139
140
  */
140
141
  const registerCommands = () => {
141
142
  const { editor } = editorStore;
@@ -143,7 +144,7 @@
143
144
  // Only called from the effect below, once the editor is there
144
145
  /* v8 ignore next */
145
146
  if (!editor) {
146
- return [];
147
+ return mergeUnregisters();
147
148
  }
148
149
 
149
150
  /**
@@ -162,7 +163,7 @@
162
163
  return true;
163
164
  };
164
165
 
165
- return [
166
+ return mergeUnregisters(
166
167
  editor.registerCommand(
167
168
  KEY_ARROW_DOWN_COMMAND,
168
169
  whileOpen(() => list?.moveSelection(1)),
@@ -198,7 +199,7 @@
198
199
 
199
200
  list?.update(trigger);
200
201
  }),
201
- ];
202
+ );
202
203
  };
203
204
 
204
205
  $effect(() => {
@@ -208,10 +209,10 @@
208
209
  return undefined;
209
210
  }
210
211
 
211
- const unregisters = registerCommands();
212
+ const unregister = registerCommands();
212
213
 
213
214
  return () => {
214
- unregisters.forEach((unregister) => unregister());
215
+ unregister();
215
216
  list?.close();
216
217
  };
217
218
  });
@@ -26,17 +26,19 @@
26
26
  $setSelection as setSelection,
27
27
  } from 'lexical';
28
28
  import { getContext, onMount, tick, untrack } from 'svelte';
29
+ import { on } from 'svelte/events';
29
30
  import Button from '../../button/button.svelte';
30
31
  import { getSuggestionListPosition } from '../../emoji/position.js';
31
32
  import Icon from '../../icon/icon.svelte';
32
33
  import TextInput from '../../text-field/text-input.svelte';
33
34
  import { OPEN_LINK_EDITOR_COMMAND } from '../constants.js';
34
- import { focusEditor } from '../editing/caret.js';
35
35
  import {
36
36
  $findSelectedLink as findSelectedLink,
37
37
  getLinkAnchorRect,
38
38
  isSafeLinkURL,
39
39
  } from '../editing/link.js';
40
+ import { refocusEditor } from '../toolbar/actions.js';
41
+ import { mergeUnregisters } from '../utils.js';
40
42
 
41
43
  /**
42
44
  * @import { LexicalEditor, RangeSelection } from 'lexical';
@@ -194,17 +196,6 @@
194
196
  openInNewTab = false;
195
197
  };
196
198
 
197
- /**
198
- * Move the focus back to the editor, where the selection is restored, after the popup is done.
199
- */
200
- const refocusEditor = async () => {
201
- // The editor is there for as long as the popup can be shown
202
- /* v8 ignore else */
203
- if (editorStore.editor) {
204
- await focusEditor(editorStore.editor);
205
- }
206
- };
207
-
208
199
  /**
209
200
  * Start editing the link at the selection, or start linking the selected text. This is the
210
201
  * handler for {@link OPEN_LINK_EDITOR_COMMAND}.
@@ -302,7 +293,8 @@
302
293
  );
303
294
  }
304
295
 
305
- await refocusEditor();
296
+ // Move the focus back to the editor, where the selection is restored
297
+ await refocusEditor(editorStore);
306
298
  };
307
299
 
308
300
  /**
@@ -310,7 +302,7 @@
310
302
  */
311
303
  const cancelEditing = async () => {
312
304
  stopEditing();
313
- await refocusEditor();
305
+ await refocusEditor(editorStore);
314
306
  };
315
307
 
316
308
  /**
@@ -338,7 +330,7 @@
338
330
  }
339
331
  });
340
332
 
341
- await refocusEditor();
333
+ await refocusEditor(editorStore);
342
334
  };
343
335
 
344
336
  /**
@@ -432,12 +424,12 @@
432
424
  }
433
425
  });
434
426
 
435
- return () => {
436
- unregisterCommand();
437
- unregisterEscape();
438
- unregisterUpdateListener();
439
- unregisterEditableListener();
440
- };
427
+ return mergeUnregisters(
428
+ unregisterCommand,
429
+ unregisterEscape,
430
+ unregisterUpdateListener,
431
+ unregisterEditableListener,
432
+ );
441
433
  });
442
434
 
443
435
  // The rich text editor can be swapped for the plain text one at any time, in which case there is
@@ -516,17 +508,12 @@
516
508
  }
517
509
  };
518
510
 
519
- window.addEventListener('scroll', reposition, { capture: true, passive: true });
520
- window.addEventListener('resize', reposition, { passive: true });
521
- document.addEventListener('focusin', onFocusIn);
522
- document.addEventListener('focusout', onFocusOut);
523
-
524
- return () => {
525
- window.removeEventListener('scroll', reposition, { capture: true });
526
- window.removeEventListener('resize', reposition);
527
- document.removeEventListener('focusin', onFocusIn);
528
- document.removeEventListener('focusout', onFocusOut);
529
- };
511
+ return mergeUnregisters(
512
+ on(window, 'scroll', reposition, { capture: true, passive: true }),
513
+ on(window, 'resize', reposition, { passive: true }),
514
+ on(document, 'focusin', onFocusIn),
515
+ on(document, 'focusout', onFocusOut),
516
+ );
530
517
  });
531
518
  </script>
532
519
 
@@ -8,6 +8,7 @@
8
8
  <script>
9
9
  import { _ } from '@sveltia/i18n';
10
10
  import { getContext, onMount } from 'svelte';
11
+ import { on } from 'svelte/events';
11
12
  import Icon from '../../icon/icon.svelte';
12
13
  import MenuButton from '../../menu/menu-button.svelte';
13
14
  import {
@@ -15,6 +16,7 @@
15
16
  isRightToLeftTable,
16
17
  } from '../editing/table.js';
17
18
  import TableActionMenu from '../toolbar/table-action-menu.svelte';
19
+ import { mergeUnregisters } from '../utils.js';
18
20
 
19
21
  /**
20
22
  * @import { PopupPosition, TextEditorStore } from '../../../typedefs.js';
@@ -140,44 +142,38 @@
140
142
  return undefined;
141
143
  }
142
144
 
143
- const unregisterUpdateListener = editor.registerUpdateListener(({ editorState }) => {
144
- cellKey = editorState.read(getSelectedTableCellKey);
145
- reposition();
146
- });
147
-
148
- // Follow the cell when a wide table is scrolled, or the editor is resized
149
- const unregisterRootListener = editor.registerRootListener((root) => {
150
- if (!root) {
151
- return undefined;
152
- }
153
-
154
- const resizeObserver = new ResizeObserver(reposition);
155
-
156
- root.addEventListener('scroll', reposition, { capture: true });
157
- resizeObserver.observe(root);
158
-
159
- return () => {
160
- root.removeEventListener('scroll', reposition, { capture: true });
161
- resizeObserver.disconnect();
162
- };
163
- });
164
-
165
- return () => {
166
- unregisterUpdateListener();
167
- unregisterRootListener();
168
- };
145
+ return mergeUnregisters(
146
+ editor.registerUpdateListener(({ editorState }) => {
147
+ cellKey = editorState.read(getSelectedTableCellKey);
148
+ reposition();
149
+ }),
150
+ // Follow the cell when a wide table is scrolled, or the editor is resized
151
+ editor.registerRootListener((root) => {
152
+ if (!root) {
153
+ return undefined;
154
+ }
155
+
156
+ const resizeObserver = new ResizeObserver(reposition);
157
+
158
+ resizeObserver.observe(root);
159
+
160
+ return mergeUnregisters(on(root, 'scroll', reposition, { capture: true }), () => {
161
+ resizeObserver.disconnect();
162
+ });
163
+ }),
164
+ );
169
165
  });
170
166
 
171
167
  onMount(() => {
172
- window.addEventListener('resize', reposition);
173
- document.addEventListener('focusin', updateFocus);
174
- document.addEventListener('focusout', updateFocus);
168
+ const unregister = mergeUnregisters(
169
+ on(window, 'resize', reposition),
170
+ on(document, 'focusin', updateFocus),
171
+ on(document, 'focusout', updateFocus),
172
+ );
175
173
 
176
174
  return () => {
177
175
  window.clearTimeout(focusTimer);
178
- window.removeEventListener('resize', reposition);
179
- document.removeEventListener('focusin', updateFocus);
180
- document.removeEventListener('focusout', updateFocus);
176
+ unregister();
181
177
  };
182
178
  });
183
179
  </script>
@@ -11,7 +11,11 @@
11
11
  -->
12
12
  <script>
13
13
  /**
14
- * @import { CommonEventHandlers, InputEventHandlers } from '../../typedefs.js';
14
+ * @import {
15
+ * CommonEventHandlers,
16
+ * FormFieldStateProps,
17
+ * InputEventHandlers,
18
+ * } from '../../typedefs.js';
15
19
  */
16
20
 
17
21
  /**
@@ -28,17 +32,12 @@
28
32
  * @property {string} [class] The `class` attribute on the `<input>` element.
29
33
  * @property {boolean} [disabled] Whether to disable the widget. An alias of the `aria-disabled`
30
34
  * attribute.
31
- * @property {boolean} [readonly] Whether to make the widget read-only. An alias of the
32
- * `aria-readonly` attribute.
33
- * @property {boolean} [required] Whether to mark the widget required. An alias of the
34
- * `aria-required` attribute.
35
- * @property {boolean} [invalid] Whether to mark the widget invalid. An alias of the
36
- * `aria-invalid` attribute.
37
35
  * @property {string} [ariaLabel] `aria-label` attribute.
38
36
  */
39
37
 
40
38
  /**
41
- * @type {CommonEventHandlers & InputEventHandlers & Props & Record<string, any>}
39
+ * @type {CommonEventHandlers & InputEventHandlers & FormFieldStateProps & Props &
40
+ * Record<string, any>}
42
41
  */
43
42
  let {
44
43
  /* eslint-disable prefer-const */