@sveltia/ui 0.91.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 (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 +16 -12
  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 +1 -1
  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
@@ -3,26 +3,33 @@
3
3
  * block the underlying editor works with.
4
4
  */
5
5
 
6
- const BACKTICKS = '```';
7
-
8
6
  /**
9
- * Wrap code in a Markdown fenced code block.
7
+ * Wrap code in a Markdown fenced code block. Like Lexical, the fence is made longer than any
8
+ * backtick run in the code, so a fence line within the code, like a fenced code block in Markdown,
9
+ * doesn’t close the block.
10
10
  * @param {string} lang Language identifier, placed after the opening fence.
11
11
  * @param {string} code Code. If empty, the block has no content line at all.
12
12
  * @returns {string} Fenced code block.
13
13
  */
14
- export const toCodeBlock = (lang, code) =>
15
- code ? `${BACKTICKS}${lang}\n${code}\n${BACKTICKS}` : `${BACKTICKS}${lang}\n${BACKTICKS}`;
14
+ export const toCodeBlock = (lang, code) => {
15
+ // Not `Math.max(...runs)`, which would exceed the maximum number of arguments with many runs
16
+ const longestRun = (code.match(/`+/g) ?? []).reduce((max, run) => Math.max(max, run.length), 2);
17
+ const fence = '`'.repeat(longestRun + 1);
18
+
19
+ return code ? `${fence}${lang}\n${code}\n${fence}` : `${fence}${lang}\n${fence}`;
20
+ };
16
21
 
17
22
  /**
18
- * Take a Markdown fenced code block apart.
23
+ * Take a Markdown fenced code block apart. The fence can be longer than three backticks, as Lexical
24
+ * makes it when the code contains a fence line, and the closing fence has to be as long.
19
25
  * @param {string} markdown Fenced code block, as produced by {@link toCodeBlock}.
20
26
  * @returns {{ lang: string, code: string }} Language identifier, `plain` if the fence has none,
21
27
  * and the code, empty if the block has no content or `markdown` is not a code block at all.
22
28
  */
23
29
  export const parseCodeBlock = (markdown) => {
24
30
  const { lang = 'plain', code = '' } =
25
- markdown.match(/^```(?<lang>[^\s`]+)?\n(?:(?<code>.*)\n)?```/s)?.groups ?? {};
31
+ markdown.match(/^(?<fence>`{3,})(?<lang>[^\s`]+)?\n(?:(?<code>.*)\n)?\k<fence>(?!`)/s)
32
+ ?.groups ?? {};
26
33
 
27
34
  return { lang, code };
28
35
  };
@@ -10,10 +10,15 @@
10
10
  import { parseCodeBlock, toCodeBlock } from './code-editor.js';
11
11
  import LexicalRoot from './lexical-root.svelte';
12
12
  import { createEditorStore, syncEditorProps } from './store.svelte.js';
13
- import CodeEditorToolbar from './toolbar/code-editor-toolbar.svelte';
13
+ import CodeLanguageSwitcher from './toolbar/code-language-switcher.svelte';
14
+ import ToolbarWrapper from './toolbar/toolbar-wrapper.svelte';
14
15
 
15
16
  /**
16
- * @import { Snippet } from 'svelte';
17
+ * @import {
18
+ * EditorCommonProps,
19
+ * FormFieldStateProps,
20
+ * WidgetStateProps,
21
+ * } from '../../typedefs.js';
17
22
  */
18
23
 
19
24
  /**
@@ -24,27 +29,11 @@
24
29
  * update {@link code}, which it does a moment later. Bind it to wait for the change before
25
30
  * reading the code, for example to save it. Read-only.
26
31
  * @property {boolean} [showLanguageSwitcher] Whether to show the language selector.
27
- * @property {boolean} [flex] Make the text input container flexible.
28
- * @property {string} [class] The `class` attribute on the wrapper element.
29
- * @property {boolean} [hidden] Whether to hide the widget.
30
- * @property {boolean} [disabled] Whether to disable the widget. An alias of the `aria-disabled`
31
- * attribute.
32
- * @property {boolean} [readonly] Whether to make the widget read-only. An alias of the
33
- * `aria-readonly` attribute.
34
- * @property {boolean} [required] Whether to mark the widget required. An alias of the
35
- * `aria-required` attribute.
36
- * @property {boolean} [invalid] Whether to mark the widget invalid. An alias of the
37
- * `aria-invalid` attribute.
38
- * @property {string} [ariaLabel] The `aria-label` attribute on the editable text box. Either
39
- * this or `ariaLabelledby` is required for the editor to have an accessible name.
40
- * @property {string} [ariaLabelledby] The `aria-labelledby` attribute on the editable text box.
41
- * @property {string} [ariaDescribedby] The `aria-describedby` attribute on the editable text
42
- * box.
43
- * @property {Snippet} [children] Primary slot content.
44
32
  */
45
33
 
46
34
  /**
47
- * @type {Props & Record<string, any>}
35
+ * @type {EditorCommonProps & WidgetStateProps & FormFieldStateProps & Props &
36
+ * Record<string, any>}
48
37
  */
49
38
  let {
50
39
  /* eslint-disable prefer-const */
@@ -64,7 +53,8 @@
64
53
  'aria-label': ariaLabelAttr = undefined,
65
54
  'aria-labelledby': ariaLabelledbyAttr = undefined,
66
55
  'aria-describedby': ariaDescribedbyAttr = undefined,
67
- children,
56
+ // Not rendered, but kept out of `restProps`, which go on the wrapper element
57
+ children: _children,
68
58
  ...restProps
69
59
  /* eslint-enable prefer-const */
70
60
  } = $props();
@@ -130,7 +120,9 @@
130
120
  style:--sui-text-editor-toolbar-height="{editorStore.toolbarHeight}px"
131
121
  >
132
122
  {#if showLanguageSwitcher}
133
- <CodeEditorToolbar {disabled} {readonly} />
123
+ <ToolbarWrapper disabled={disabled || readonly} ariaLabel={_('_sui.text_editor.code_editor')}>
124
+ <CodeLanguageSwitcher disabled={disabled || readonly} />
125
+ </ToolbarWrapper>
134
126
  {/if}
135
127
  <LexicalRoot {...labelAttrs} {hidden} {disabled} {readonly} {required} {invalid} />
136
128
  </div>
@@ -1,10 +1,10 @@
1
1
  export default CodeEditor;
2
2
  type CodeEditor = {
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 code editor based on Lexical. */
7
- declare const CodeEditor: import("svelte").Component<{
7
+ declare const CodeEditor: import("svelte").Component<EditorCommonProps & WidgetStateProps & FormFieldStateProps & {
8
8
  /**
9
9
  * Input value.
10
10
  */
@@ -23,56 +23,6 @@ declare const CodeEditor: import("svelte").Component<{
23
23
  * Whether to show the language selector.
24
24
  */
25
25
  showLanguageSwitcher?: boolean | undefined;
26
- /**
27
- * Make the text input container flexible.
28
- */
29
- flex?: boolean | undefined;
30
- /**
31
- * The `class` attribute on the wrapper element.
32
- */
33
- class?: string | undefined;
34
- /**
35
- * Whether to hide the widget.
36
- */
37
- hidden?: boolean | undefined;
38
- /**
39
- * Whether to disable the widget. An alias of the `aria-disabled`
40
- * attribute.
41
- */
42
- disabled?: boolean | undefined;
43
- /**
44
- * Whether to make the widget read-only. An alias of the
45
- * `aria-readonly` attribute.
46
- */
47
- readonly?: boolean | undefined;
48
- /**
49
- * Whether to mark the widget required. An alias of the
50
- * `aria-required` attribute.
51
- */
52
- required?: boolean | undefined;
53
- /**
54
- * Whether to mark the widget invalid. An alias of the
55
- * `aria-invalid` attribute.
56
- */
57
- invalid?: boolean | undefined;
58
- /**
59
- * The `aria-label` attribute on the editable text box. Either
60
- * this or `ariaLabelledby` is required for the editor to have an accessible name.
61
- */
62
- ariaLabel?: string | undefined;
63
- /**
64
- * The `aria-labelledby` attribute on the editable text box.
65
- */
66
- ariaLabelledby?: string | undefined;
67
- /**
68
- * The `aria-describedby` attribute on the editable text
69
- * box.
70
- */
71
- ariaDescribedby?: string | undefined;
72
- /**
73
- * Primary slot content.
74
- */
75
- children?: Snippet<[]> | undefined;
76
26
  } & Record<string, any>, {}, "code" | "lang" | "pending">;
77
27
  type Props = {
78
28
  /**
@@ -93,55 +43,7 @@ type Props = {
93
43
  * Whether to show the language selector.
94
44
  */
95
45
  showLanguageSwitcher?: boolean | undefined;
96
- /**
97
- * Make the text input container flexible.
98
- */
99
- flex?: boolean | undefined;
100
- /**
101
- * The `class` attribute on the wrapper element.
102
- */
103
- class?: string | undefined;
104
- /**
105
- * Whether to hide the widget.
106
- */
107
- hidden?: boolean | undefined;
108
- /**
109
- * Whether to disable the widget. An alias of the `aria-disabled`
110
- * attribute.
111
- */
112
- disabled?: boolean | undefined;
113
- /**
114
- * Whether to make the widget read-only. An alias of the
115
- * `aria-readonly` attribute.
116
- */
117
- readonly?: boolean | undefined;
118
- /**
119
- * Whether to mark the widget required. An alias of the
120
- * `aria-required` attribute.
121
- */
122
- required?: boolean | undefined;
123
- /**
124
- * Whether to mark the widget invalid. An alias of the
125
- * `aria-invalid` attribute.
126
- */
127
- invalid?: boolean | undefined;
128
- /**
129
- * The `aria-label` attribute on the editable text box. Either
130
- * this or `ariaLabelledby` is required for the editor to have an accessible name.
131
- */
132
- ariaLabel?: string | undefined;
133
- /**
134
- * The `aria-labelledby` attribute on the editable text box.
135
- */
136
- ariaLabelledby?: string | undefined;
137
- /**
138
- * The `aria-describedby` attribute on the editable text
139
- * box.
140
- */
141
- ariaDescribedby?: string | undefined;
142
- /**
143
- * Primary slot content.
144
- */
145
- children?: Snippet<[]> | undefined;
146
46
  };
147
- import type { Snippet } from 'svelte';
47
+ import type { EditorCommonProps } from '../../typedefs.js';
48
+ import type { WidgetStateProps } from '../../typedefs.js';
49
+ import type { FormFieldStateProps } from '../../typedefs.js';
@@ -0,0 +1,73 @@
1
+ export function normalizeConfig({ modes, enabledButtons, components, isCodeEditor, useEmojiAutocomplete, defaultLanguage, format, multiline, ...rest }: Partial<TextEditorConfig>): NormalizedEditorConfig;
2
+ export function getEditorSetup(config: NormalizedEditorConfig): EditorSetup;
3
+ /**
4
+ * Editor configuration with the defaults applied.
5
+ */
6
+ export type NormalizedEditorConfig = TextEditorConfig & {
7
+ useEmojiAutocomplete: boolean;
8
+ defaultLanguage: string;
9
+ format: TextEditorValueFormat;
10
+ multiline: boolean;
11
+ };
12
+ /**
13
+ * Editor configuration with the defaults applied, and the features derived from it.
14
+ */
15
+ export type EditorSetup = {
16
+ /**
17
+ * Enabled buttons.
18
+ */
19
+ enabledButtons: TextEditorNodeType[];
20
+ /**
21
+ * Editor components.
22
+ */
23
+ components: TextEditorComponent[];
24
+ /**
25
+ * Whether to enable Markdown shortcuts.
26
+ */
27
+ useMarkdownShortcuts: boolean | undefined;
28
+ /**
29
+ * Whether the editor is a code editor.
30
+ */
31
+ isCodeEditor: boolean;
32
+ /**
33
+ * Default code block language.
34
+ */
35
+ defaultLanguage: string;
36
+ /**
37
+ * Value format.
38
+ */
39
+ format: TextEditorValueFormat;
40
+ /**
41
+ * Whether the editor accepts multiple lines.
42
+ */
43
+ multiline: boolean;
44
+ /**
45
+ * Whether to support code blocks.
46
+ */
47
+ hasCodeBlock: boolean;
48
+ /**
49
+ * Whether to support table editing.
50
+ */
51
+ hasTable: boolean;
52
+ /**
53
+ * Whether to support selecting a horizontal rule.
54
+ */
55
+ hasHorizontalRule: boolean;
56
+ /**
57
+ * Whether to support links.
58
+ */
59
+ hasLink: boolean;
60
+ /**
61
+ * Whether to support task lists.
62
+ */
63
+ hasTaskList: boolean;
64
+ /**
65
+ * Whether to support horizontal rules and tables in Markdown,
66
+ * even without their buttons.
67
+ */
68
+ hasBlockSyntax: boolean;
69
+ };
70
+ import type { TextEditorConfig } from '../../typedefs.js';
71
+ import type { TextEditorValueFormat } from '../../typedefs.js';
72
+ import type { TextEditorNodeType } from '../../typedefs.js';
73
+ import type { TextEditorComponent } from '../../typedefs.js';
@@ -0,0 +1,110 @@
1
+ /**
2
+ * The editor configuration: its defaults, and the features derived from it.
3
+ */
4
+
5
+ import { limitToSingleLine } from './editing/single-line.js';
6
+
7
+ /**
8
+ * @import {
9
+ * TextEditorComponent,
10
+ * TextEditorConfig,
11
+ * TextEditorNodeType,
12
+ * TextEditorValueFormat,
13
+ * } from '../../typedefs.js';
14
+ */
15
+
16
+ /**
17
+ * Editor configuration with the defaults applied.
18
+ * @typedef {TextEditorConfig & {
19
+ * useEmojiAutocomplete: boolean,
20
+ * defaultLanguage: string,
21
+ * format: TextEditorValueFormat,
22
+ * multiline: boolean,
23
+ * }} NormalizedEditorConfig
24
+ */
25
+
26
+ /**
27
+ * Editor configuration with the defaults applied, and the features derived from it.
28
+ * @typedef {object} EditorSetup
29
+ * @property {TextEditorNodeType[]} enabledButtons Enabled buttons.
30
+ * @property {TextEditorComponent[]} components Editor components.
31
+ * @property {boolean | undefined} useMarkdownShortcuts Whether to enable Markdown shortcuts.
32
+ * @property {boolean} isCodeEditor Whether the editor is a code editor.
33
+ * @property {string} defaultLanguage Default code block language.
34
+ * @property {TextEditorValueFormat} format Value format.
35
+ * @property {boolean} multiline Whether the editor accepts multiple lines.
36
+ * @property {boolean} hasCodeBlock Whether to support code blocks.
37
+ * @property {boolean} hasTable Whether to support table editing.
38
+ * @property {boolean} hasHorizontalRule Whether to support selecting a horizontal rule.
39
+ * @property {boolean} hasLink Whether to support links.
40
+ * @property {boolean} hasTaskList Whether to support task lists.
41
+ * @property {boolean} hasBlockSyntax Whether to support horizontal rules and tables in Markdown,
42
+ * even without their buttons.
43
+ */
44
+
45
+ /**
46
+ * Apply the defaults to the editor configuration, and limit it to the inline features if the editor
47
+ * is limited to a single line. Normalizing a configuration again gives an equal one.
48
+ * @param {Partial<TextEditorConfig>} config Editor configuration.
49
+ * @returns {NormalizedEditorConfig} Normalized configuration.
50
+ */
51
+ export const normalizeConfig = ({
52
+ modes = [],
53
+ enabledButtons = [],
54
+ components = [],
55
+ isCodeEditor = false,
56
+ useEmojiAutocomplete = false,
57
+ defaultLanguage = 'plain',
58
+ format = 'markdown',
59
+ multiline = true,
60
+ ...rest
61
+ }) =>
62
+ /** @type {NormalizedEditorConfig} */ (
63
+ limitToSingleLine({
64
+ ...rest,
65
+ // The store always gives one; a configuration without one has no Markdown shortcuts
66
+ useMarkdownShortcuts: /** @type {boolean} */ (rest.useMarkdownShortcuts),
67
+ modes,
68
+ enabledButtons,
69
+ components,
70
+ isCodeEditor,
71
+ useEmojiAutocomplete,
72
+ defaultLanguage,
73
+ format,
74
+ multiline,
75
+ })
76
+ );
77
+
78
+ /**
79
+ * Derive the features from the editor configuration.
80
+ * @param {NormalizedEditorConfig} config Editor configuration normalized with
81
+ * {@link normalizeConfig}, like the one the editor store holds.
82
+ * @returns {EditorSetup} Editor setup.
83
+ */
84
+ export const getEditorSetup = (config) => {
85
+ const {
86
+ enabledButtons,
87
+ components,
88
+ useMarkdownShortcuts,
89
+ isCodeEditor,
90
+ defaultLanguage,
91
+ format,
92
+ multiline,
93
+ } = config;
94
+
95
+ return {
96
+ enabledButtons,
97
+ components,
98
+ useMarkdownShortcuts,
99
+ isCodeEditor,
100
+ defaultLanguage,
101
+ format,
102
+ multiline,
103
+ hasCodeBlock: enabledButtons.includes('code-block') || isCodeEditor,
104
+ hasTable: enabledButtons.includes('table') && !isCodeEditor,
105
+ hasHorizontalRule: enabledButtons.includes('horizontal-rule') && !isCodeEditor,
106
+ hasLink: enabledButtons.includes('link'),
107
+ hasTaskList: enabledButtons.includes('task-list'),
108
+ hasBlockSyntax: !isCodeEditor && multiline,
109
+ };
110
+ };
@@ -7,9 +7,9 @@ import {
7
7
  $createParagraphNode as createParagraphNode,
8
8
  $getRoot as getRoot,
9
9
  } from 'lexical';
10
- import { removeImportPlaceholders } from './markdown.js';
11
- import { HTML_BLOCK_PLACEHOLDER } from './transformers/raw-syntax.js';
12
- import { onEditorUpdate } from './update.js';
10
+ import { removeImportPlaceholders } from './markdown/index.js';
11
+ import { HTML_BLOCK_PLACEHOLDER } from './placeholder-chars.js';
12
+ import { exportValue } from './update.js';
13
13
 
14
14
  /**
15
15
  * @import { Transformer } from '@lexical/markdown';
@@ -53,7 +53,7 @@ export const getComponentMarkdown = ({ node, createNode, transformer, createMark
53
53
  // An inline node needs a paragraph to live in
54
54
  getRoot().append(newNode.isInline() ? createParagraphNode().append(newNode) : newNode);
55
55
 
56
- markdown = onEditorUpdate(editor, [transformer]);
56
+ markdown = exportValue(editor, [transformer]);
57
57
  },
58
58
  { discrete: true },
59
59
  );
@@ -17,7 +17,7 @@ import {
17
17
  TabNode,
18
18
  TextNode,
19
19
  } from 'lexical';
20
- import { isPlainLanguage } from '../../shiki/facade.js';
20
+ import { isPlainLanguage } from '../../shiki/engine.js';
21
21
  import { decorateTaskList, decorateTaskListItem } from './task-list.js';
22
22
  import { splitParagraphAroundBlocks } from './paragraph.js';
23
23
  import { TEXT_FORMAT_TAGS } from './utils.js';
@@ -21,13 +21,11 @@ import {
21
21
  import { IMPORT_UPDATE_TAG } from '../constants.js';
22
22
  import { exportHtml, findUnsupportedNode, getCodeLanguage } from './html/index.js';
23
23
  import {
24
- addImportPlaceholders,
25
- convertSetextHeadings,
26
- convertTildeFences,
27
- padBlankBlockquoteLines,
24
+ convertBlockSyntax,
25
+ toLexicalMarkdown,
28
26
  removeImportPlaceholders,
29
- splitMultilineFormatting,
30
- } from './markdown.js';
27
+ } from './markdown/index.js';
28
+ import { findCodeBlocks, parseOpeningFence } from './markdown/code-blocks.js';
31
29
  import { loadCodeHighlighter } from '../shiki/preload.js';
32
30
  import { CODE } from './transformers/code.js';
33
31
  import { addCodeSpanSplit } from './transformers/formatted-code.js';
@@ -74,6 +72,25 @@ const removePlaceholders = (nodes) => {
74
72
  });
75
73
  };
76
74
 
75
+ /**
76
+ * Get the programming languages used in the code blocks of Markdown: the leading word of the info
77
+ * string of each opening backtick fence, like `js` in the info string ` js title=x`, as `CODE`
78
+ * reads it. A code block in a list item, like `- ~~~`, is left out, as it’s imported as the text
79
+ * of the item, and so is one with a tilde fence, which is only imported as a code block once
80
+ * converted.
81
+ * @param {string} markdown Markdown.
82
+ * @returns {string[]} Languages.
83
+ */
84
+ const getCodeBlockLanguages = (markdown) => {
85
+ const lines = markdown.split('\n');
86
+
87
+ return findCodeBlocks(lines).flatMap(({ start }) => {
88
+ const { fence = '', language } = parseOpeningFence(lines[start]) ?? {};
89
+
90
+ return fence.startsWith('`') && language ? [language] : [];
91
+ });
92
+ };
93
+
77
94
  /**
78
95
  * Prepare Markdown for the import: convert the syntax Lexical doesn’t support to the one it does,
79
96
  * if the element is enabled, and list the programming languages used in the code blocks.
@@ -82,10 +99,9 @@ const removePlaceholders = (nodes) => {
82
99
  * @returns {{ markdown: string, languages: string[] }} Normalized Markdown and the languages.
83
100
  */
84
101
  export const prepareMarkdown = (value, enabledTransformers) => {
85
- // Tilde code fences are converted to backtick ones, and setext headings to ATX ones. Otherwise
86
- // the syntax is kept as text, as written. A transformer is found by its regular expression,
87
- // because the transformers can come wrapped in a `$state` proxy, which leaves a regular
88
- // expression as is but not the transformer object itself
102
+ // A transformer is found by its regular expression, because the transformers can come wrapped
103
+ // in a `$state` proxy, which leaves a regular expression as is but not the transformer object
104
+ // itself
89
105
  const hasCodeBlocks = enabledTransformers.some(
90
106
  (transformer) => 'regExpStart' in transformer && transformer.regExpStart === CODE.regExpStart,
91
107
  );
@@ -94,16 +110,11 @@ export const prepareMarkdown = (value, enabledTransformers) => {
94
110
  (transformer) => 'regExp' in transformer && transformer.regExp === HEADING.regExp,
95
111
  );
96
112
 
97
- const fencedValue = hasCodeBlocks ? convertTildeFences(value) : value;
98
- const markdown = hasHeadings ? convertSetextHeadings(fencedValue) : fencedValue;
113
+ const markdown = convertBlockSyntax(value, { hasCodeBlocks, hasHeadings });
99
114
 
100
115
  return {
101
116
  markdown,
102
- // The language is the leading word of the info string, like `js` in ```` ``` js title=x ````;
103
- // see `CODE`
104
- languages: [...markdown.matchAll(/^`{3,}[ \t]*(?<lang>[\w-]+)/gm)].map(
105
- ({ groups: { lang = 'plain' } = {} }) => lang,
106
- ),
117
+ languages: getCodeBlockLanguages(markdown),
107
118
  };
108
119
  };
109
120
 
@@ -118,28 +129,23 @@ export const prepareMarkdown = (value, enabledTransformers) => {
118
129
  * @returns {LexicalNode[]} Imported nodes.
119
130
  */
120
131
  export const $importMarkdown = (markdown, enabledTransformers, { toRoot = false } = {}) => {
121
- // Split multiline formatting into separate lines to prevent Markdown parsing issues
122
- const splitValue = splitMultilineFormatting(markdown);
123
- // Add placeholders so Lexical reads the backslashes, the tabs in code spans and raw HTML right
124
- const markedValue = addImportPlaceholders(splitValue);
125
- // Pad blank blockquote lines so they are not imported as literal `>` text
126
- const paddedValue = padBlankBlockquoteLines(markedValue);
132
+ const { markdown: preparedValue, hasPlaceholders } = toLexicalMarkdown(markdown);
127
133
  // Keep the formatting around a code span after other formatting
128
134
  const transformers = addCodeSpanSplit(enabledTransformers);
129
135
  /** @type {LexicalNode[]} */
130
136
  let nodes;
131
137
 
132
138
  if (toRoot) {
133
- convertFromMarkdownString(paddedValue, transformers);
139
+ convertFromMarkdownString(preparedValue, transformers);
134
140
  nodes = getRoot().getChildren();
135
141
  } else {
136
- nodes = generateNodesFromMarkdownString(paddedValue, transformers);
142
+ nodes = generateNodesFromMarkdownString(preparedValue, transformers);
137
143
  }
138
144
 
139
145
  // The text of raw HTML and raw syntax is restored as well. The lines of an HTML block have a
140
146
  // placeholder. Other raw syntax, like an autolink or a definition label, only differs from its
141
147
  // text if Lexical has decoded an escape or a character reference in it
142
- if (markedValue !== splitValue || /[\\&]/.test(markedValue)) {
148
+ if (hasPlaceholders || /[\\&]/.test(preparedValue)) {
143
149
  removePlaceholders(nodes);
144
150
  }
145
151
 
@@ -0,0 +1,4 @@
1
+ export function convertTildeFences(value: string): string;
2
+ export function convertSetextHeadings(value: string): string;
3
+ export function padBlankBlockquoteLines(value: string): string;
4
+ export function trimBlankBlockquoteLines(value: string): string;