@sveltia/ui 0.84.0 → 0.85.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.
@@ -138,7 +138,14 @@
138
138
  });
139
139
  </script>
140
140
 
141
- <div {...restProps} role="none" class="sui code-editor" class:flex {hidden}>
141
+ <div
142
+ {...restProps}
143
+ role="none"
144
+ class="sui code-editor"
145
+ class:flex
146
+ {hidden}
147
+ style:--sui-text-editor-toolbar-height="{editorStore.toolbarHeight}px"
148
+ >
142
149
  {#if showLanguageSwitcher}
143
150
  <CodeEditorToolbar {disabled} {readonly} />
144
151
  {/if}
@@ -162,4 +169,14 @@
162
169
  }
163
170
  .code-editor.flex:not([hidden]) {
164
171
  display: block;
172
+ }
173
+ .code-editor {
174
+ --sui-text-editor-toolbar-top: var(--sui-text-editor-inner-toolbar-top, 0px);
175
+ --sui-text-editor-toolbar-z-index: var(--sui-text-editor-inner-toolbar-z-index, 100);
176
+ }
177
+ .code-editor > :global(*) {
178
+ --sui-text-editor-inner-toolbar-top: calc(
179
+ var(--sui-text-editor-toolbar-top) + var(--sui-text-editor-toolbar-height)
180
+ );
181
+ --sui-text-editor-inner-toolbar-z-index: calc(var(--sui-text-editor-toolbar-z-index) - 1);
165
182
  }</style>
@@ -118,13 +118,13 @@ import {
118
118
  $getSelectedTableCellKey,
119
119
  $normalizeTableHeaders,
120
120
  } from './table.js';
121
- import { TABLE } from './transformers/table.js';
121
+ import { createTableTransformer } from './transformers/table.js';
122
122
 
123
123
  /**
124
124
  * @import { LexicalEditor, LexicalNode } from 'lexical';
125
125
  * @import { LinkAttributes } from '@lexical/link';
126
126
  * @import { ListType } from '@lexical/list';
127
- * @import { Transformer } from '@lexical/markdown';
127
+ * @import { TextMatchTransformer, Transformer } from '@lexical/markdown';
128
128
  * @import {
129
129
  * TextEditorBlockType,
130
130
  * TextEditorComponent,
@@ -977,9 +977,11 @@ export const initEditor = ({
977
977
  },
978
978
  });
979
979
 
980
+ const componentTransformers = components.map(({ transformer }) => transformer);
981
+
980
982
  /** @type {Transformer[]} */
981
983
  const enabledTransformers = [
982
- ...components.map(({ transformer }) => transformer),
984
+ ...componentTransformers,
983
985
  ...new Set(
984
986
  Object.entries(TRANSFORMER_MAP)
985
987
  .filter(([button]) => enabledButtons.includes(/** @type {TextEditorNodeType} */ (button)))
@@ -988,7 +990,16 @@ export const initEditor = ({
988
990
  ...(isCodeEditor
989
991
  ? [CODE]
990
992
  : // See the comment above for why we always include horizontal rules and tables
991
- [HR, TABLE]),
993
+ [
994
+ HR,
995
+ // A table cell can only have inline content, so only the components with a text match
996
+ // transformer can be used there
997
+ createTableTransformer(
998
+ /** @type {TextMatchTransformer[]} */ (
999
+ componentTransformers.filter(({ type }) => type === 'text-match')
1000
+ ),
1001
+ ),
1002
+ ]),
992
1003
  ];
993
1004
 
994
1005
  const editor = buildEditorFromExtensions(editorExtension);
@@ -198,7 +198,7 @@
198
198
  ></div>
199
199
 
200
200
  <style>.lexical-root {
201
- overflow: hidden;
201
+ overflow: clip;
202
202
  border: 1px solid var(--sui-textbox-border-color);
203
203
  border-radius: var(--sui-textbox-border-radius) !important;
204
204
  padding: var(--sui-textbox-multiline-padding);
@@ -1,4 +1,4 @@
1
1
  /**
2
2
  * Version of this package, used to resolve the prebuilt Shiki engine chunk from a CDN.
3
3
  */
4
- export const UI_VERSION: "0.84.0";
4
+ export const UI_VERSION: "0.85.1";
@@ -3,4 +3,4 @@
3
3
  /**
4
4
  * Version of this package, used to resolve the prebuilt Shiki engine chunk from a CDN.
5
5
  */
6
- export const UI_VERSION = '0.84.0';
6
+ export const UI_VERSION = '0.85.1';
@@ -39,6 +39,8 @@ export const createEditorStore = () => {
39
39
  let useRichText = $state(true);
40
40
  /** @type {HTMLTextAreaElement | undefined} */
41
41
  let textArea = $state();
42
+ /** @type {number} */
43
+ let toolbarHeight = $state(0);
42
44
  /** @type {boolean} */
43
45
  let hasConverterError = $state(false);
44
46
  /** @type {boolean} */
@@ -180,6 +182,12 @@ export const createEditorStore = () => {
180
182
  set textArea(newValue) {
181
183
  textArea = newValue;
182
184
  },
185
+ get toolbarHeight() {
186
+ return toolbarHeight;
187
+ },
188
+ set toolbarHeight(newValue) {
189
+ toolbarHeight = newValue;
190
+ },
183
191
  get useRichText() {
184
192
  return useRichText;
185
193
  },
@@ -304,7 +304,14 @@
304
304
  });
305
305
  </script>
306
306
 
307
- <div {...restProps} role="none" class="sui text-editor" class:flex {hidden}>
307
+ <div
308
+ {...restProps}
309
+ role="none"
310
+ class="sui text-editor"
311
+ class:flex
312
+ {hidden}
313
+ style:--sui-text-editor-toolbar-height="{editorStore.toolbarHeight}px"
314
+ >
308
315
  <TextEditorToolbar {disabled} {readonly} />
309
316
  <LexicalRoot
310
317
  {...labelAttrs}
@@ -371,4 +378,14 @@
371
378
  border-start-end-radius: 0 !important;
372
379
  border-end-start-radius: var(--sui-textbox-border-radius) !important;
373
380
  border-end-end-radius: var(--sui-textbox-border-radius) !important;
381
+ }
382
+ .text-editor {
383
+ --sui-text-editor-toolbar-top: var(--sui-text-editor-inner-toolbar-top, 0px);
384
+ --sui-text-editor-toolbar-z-index: var(--sui-text-editor-inner-toolbar-z-index, 100);
385
+ }
386
+ .text-editor > :global(*) {
387
+ --sui-text-editor-inner-toolbar-top: calc(
388
+ var(--sui-text-editor-toolbar-top) + var(--sui-text-editor-toolbar-height)
389
+ );
390
+ --sui-text-editor-inner-toolbar-z-index: calc(var(--sui-text-editor-toolbar-z-index) - 1);
374
391
  }</style>
@@ -1,3 +1,4 @@
1
+ export function isInlineComponent({ transformer }: TextEditorComponent): boolean;
1
2
  export function insertEditorComponent(editorStore: TextEditorStore, component: TextEditorComponent): void;
2
- import type { TextEditorStore } from '../../../typedefs.js';
3
3
  import type { TextEditorComponent } from '../../../typedefs.js';
4
+ import type { TextEditorStore } from '../../../typedefs.js';
@@ -5,6 +5,15 @@ import { insertComponent } from '../raw-markdown.js';
5
5
  * @import { TextEditorComponent, TextEditorStore } from '../../../typedefs.js';
6
6
  */
7
7
 
8
+ /**
9
+ * Check if the given editor component is inline, which means its Markdown is matched within a line
10
+ * of text by a text match transformer. Only an inline component can be inserted into a Markdown
11
+ * table cell.
12
+ * @param {TextEditorComponent} component Editor component.
13
+ * @returns {boolean} Result.
14
+ */
15
+ export const isInlineComponent = ({ transformer }) => transformer.type === 'text-match';
16
+
8
17
  /**
9
18
  * Insert a new instance of the given editor component into the editor: its Markdown in the plain
10
19
  * text mode, or its node in the rich text mode.
@@ -28,7 +37,10 @@ export const insertEditorComponent = (editorStore, component) => {
28
37
  const { createNode } = component;
29
38
 
30
39
  editorStore.editor?.update(() => {
31
- // Add an additional paragraph for easier editing
32
- insertNodes([createNode(), createParagraphNode()]);
40
+ const node = createNode();
41
+
42
+ // Add an additional paragraph after a block for easier editing. An inline node stays within the
43
+ // text, which may be in a table cell where a paragraph can’t be added
44
+ insertNodes(node.isInline() ? [node] : [node, createParagraphNode()]);
33
45
  });
34
46
  };
@@ -17,6 +17,7 @@
17
17
  import InsertItemButton from './insert-item-button.svelte';
18
18
  import InsertLinkButton from './insert-link-button.svelte';
19
19
  import InsertMenuButton from './insert-menu-button.svelte';
20
+ import { isInlineComponent } from './insert-component.js';
20
21
  import InsertTableButton from './insert-table-button.svelte';
21
22
  import TableActionMenu from './table-action-menu.svelte';
22
23
  import ToggleBlockMenuItem from './toggle-block-menu-item.svelte';
@@ -48,13 +49,6 @@
48
49
  /** @type {TextEditorStore} */
49
50
  const editorStore = getContext('editorStore');
50
51
 
51
- const buttons = $derived(
52
- editorStore.config.components.filter(({ trigger = 'menuitem' }) => trigger === 'button'),
53
- );
54
- const menuitems = $derived(
55
- editorStore.config.components.filter(({ trigger = 'menuitem' }) => trigger === 'menuitem'),
56
- );
57
-
58
52
  /**
59
53
  * Enabled block level buttons.
60
54
  * @type {TextEditorBlockType[]}
@@ -93,17 +87,28 @@
93
87
  );
94
88
  /**
95
89
  * Whether the caret is in a Markdown table cell, which can only have inline content, so neither
96
- * a horizontal rule nor an editor component can be inserted. A cell is also exported with the
97
- * standard Markdown syntax only, so an editor component would be lost.
90
+ * a horizontal rule nor a block editor component can be inserted.
98
91
  */
99
92
  const inMarkdownTable = $derived(!!tableCellKey && !isHtml);
93
+ /**
94
+ * Editor components that can be inserted at the caret: only the inline ones in a Markdown table
95
+ * cell.
96
+ */
97
+ const components = $derived(
98
+ inMarkdownTable
99
+ ? editorStore.config.components.filter(isInlineComponent)
100
+ : editorStore.config.components,
101
+ );
102
+ const buttons = $derived(components.filter(({ trigger = 'menuitem' }) => trigger === 'button'));
103
+ const menuitems = $derived(
104
+ components.filter(({ trigger = 'menuitem' }) => trigger === 'menuitem'),
105
+ );
100
106
  /**
101
107
  * Whether any of the buttons to insert a table, a horizontal rule or an editor component is
102
108
  * shown.
103
109
  */
104
110
  const hasInsertButtons = $derived(
105
- hasTable ||
106
- (!inMarkdownTable && (hasHorizontalRule || editorStore.config.components.length > 0)),
111
+ hasTable || (!inMarkdownTable && hasHorizontalRule) || components.length > 0,
107
112
  );
108
113
  /**
109
114
  * Whether the block level styles are available.
@@ -186,16 +191,14 @@
186
191
  <!-- Tables can’t be nested -->
187
192
  <InsertTableButton disabled={!!tableCellKey} />
188
193
  {/if}
189
- {#if !inMarkdownTable}
190
- {#if hasHorizontalRule}
191
- <InsertHorizontalRuleButton />
192
- {/if}
193
- {#each buttons as button (button.id)}
194
- <InsertItemButton component={button} />
195
- {/each}
196
- {#if menuitems.length}
197
- <InsertMenuButton components={menuitems} />
198
- {/if}
194
+ {#if hasHorizontalRule && !inMarkdownTable}
195
+ <InsertHorizontalRuleButton />
196
+ {/if}
197
+ {#each buttons as button (button.id)}
198
+ <InsertItemButton component={button} />
199
+ {/each}
200
+ {#if menuitems.length}
201
+ <InsertMenuButton components={menuitems} />
199
202
  {/if}
200
203
  {/if}
201
204
  {/if}
@@ -1,8 +1,10 @@
1
1
  <script>
2
+ import { getContext } from 'svelte';
2
3
  import Toolbar from '../../toolbar/toolbar.svelte';
3
4
 
4
5
  /**
5
6
  * @import { Snippet } from 'svelte';
7
+ * @import { TextEditorStore } from '../../../typedefs.js';
6
8
  */
7
9
 
8
10
  /**
@@ -22,10 +24,32 @@
22
24
  ...restProps
23
25
  /* eslint-enable prefer-const */
24
26
  } = $props();
27
+
28
+ /** @type {TextEditorStore} */
29
+ const editorStore = getContext('editorStore');
30
+
31
+ /**
32
+ * Keep the toolbar height in the store, so the sticky toolbars of nested editors can be placed
33
+ * below this one.
34
+ * @param {HTMLElement} toolbar Toolbar element.
35
+ * @returns {() => void} Cleanup function.
36
+ */
37
+ const observeHeight = (toolbar) => {
38
+ const observer = new ResizeObserver(([entry]) => {
39
+ editorStore.toolbarHeight = entry.borderBoxSize[0].blockSize;
40
+ });
41
+
42
+ observer.observe(toolbar);
43
+
44
+ return () => {
45
+ observer.disconnect();
46
+ editorStore.toolbarHeight = 0;
47
+ };
48
+ };
25
49
  </script>
26
50
 
27
51
  <div role="none" class="wrapper">
28
- <Toolbar {...restProps} {disabled}>
52
+ <Toolbar {...restProps} {disabled} {@attach observeHeight}>
29
53
  {@render children?.()}
30
54
  </Toolbar>
31
55
  </div>
@@ -35,8 +59,8 @@
35
59
  }
36
60
  .wrapper :global([role=toolbar]) {
37
61
  position: sticky;
38
- top: 0;
39
- z-index: 100;
62
+ top: var(--sui-text-editor-toolbar-top, 0px);
63
+ z-index: var(--sui-text-editor-toolbar-z-index, 100);
40
64
  display: flex;
41
65
  flex-wrap: wrap;
42
66
  gap: 4px;
@@ -1,9 +1,8 @@
1
1
  export function getTableColumnsSize(table: TableNode): number;
2
- export function mapToTableCells(textContent: string): TableCellNode[] | null;
3
- /**
4
- * @type {ElementTransformer}
5
- */
6
- export const TABLE: ElementTransformer;
2
+ export function mapToTableCells(textContent: string, transformers: Transformer[]): TableCellNode[] | null;
3
+ export function createTableTransformer(cellTransformers?: TextMatchTransformer[]): ElementTransformer;
7
4
  import { TableNode } from '@lexical/table';
5
+ import type { Transformer } from '@lexical/markdown';
8
6
  import { TableCellNode } from '@lexical/table';
7
+ import type { TextMatchTransformer } from '@lexical/markdown';
9
8
  import type { ElementTransformer } from '@lexical/markdown';
@@ -26,7 +26,7 @@ import { $isParagraphNode as isParagraphNode, $isTextNode as isTextNode } from '
26
26
  import { BLOCK_SYNTAX_ESCAPE } from './block-escape.js';
27
27
 
28
28
  /**
29
- * @import { ElementTransformer } from '@lexical/markdown';
29
+ * @import { ElementTransformer, TextMatchTransformer, Transformer } from '@lexical/markdown';
30
30
  */
31
31
 
32
32
  const TABLE_ROW_REG_EXP = /^(?:\|)(.+)(?:\|)\s?$/;
@@ -47,16 +47,17 @@ export const getTableColumnsSize = (table) => {
47
47
  /**
48
48
  * Creates a table cell with the given text content.
49
49
  * @param {string} textContent
50
+ * @param {Transformer[]} transformers Transformers to import the cell content with.
50
51
  * @returns {TableCellNode}
51
52
  */
52
- const createTableCell = (textContent) => {
53
+ const createTableCell = (textContent, transformers) => {
53
54
  // An escaped pipe is part of the cell, even within inline code, like GitHub Flavored Markdown.
54
55
  // The spaces around the content only separate it from the pipes
55
56
  textContent = textContent.trim().replace(/\\n/g, '\n').replace(/\\\|/g, '|');
56
57
 
57
58
  const cell = createTableCellNode(TableCellHeaderStates.NO_STATUS);
58
59
 
59
- convertFromMarkdownString(textContent, TRANSFORMERS, cell);
60
+ convertFromMarkdownString(textContent, transformers, cell);
60
61
 
61
62
  return cell;
62
63
  };
@@ -65,9 +66,10 @@ const createTableCell = (textContent) => {
65
66
  * Maps the given text content to an array of table cells.
66
67
  * @internal
67
68
  * @param {string} textContent
69
+ * @param {Transformer[]} transformers Transformers to import the cell content with.
68
70
  * @returns {TableCellNode[] | null}
69
71
  */
70
- export const mapToTableCells = (textContent) => {
72
+ export const mapToTableCells = (textContent, transformers) => {
71
73
  const [, match] = textContent.match(TABLE_ROW_REG_EXP) ?? [];
72
74
 
73
75
  if (!match) {
@@ -76,152 +78,163 @@ export const mapToTableCells = (textContent) => {
76
78
 
77
79
  // Split the row at the pipes that are not escaped, which are preceded by an even number of
78
80
  // backslashes
79
- return match.split(/(?<=(?<!\\)(?:\\\\)*)\|/).map((text) => createTableCell(text));
81
+ return match.split(/(?<=(?<!\\)(?:\\\\)*)\|/).map((text) => createTableCell(text, transformers));
80
82
  };
81
83
 
82
84
  /**
83
- * @type {ElementTransformer}
85
+ * Create a table transformer. A cell can only have inline content, so it’s converted with the
86
+ * standard Markdown transformers and the given text match transformers, like those of the inline
87
+ * editor components, which come first to take priority, as they do for the rest of the document.
88
+ * @param {TextMatchTransformer[]} [cellTransformers] Additional transformers for the cell content.
89
+ * @returns {ElementTransformer}
84
90
  */
85
- export const TABLE = {
86
- dependencies: [TableNode, TableRowNode, TableCellNode],
87
- export: (node) => {
88
- if (!isTableNode(node)) {
89
- return null;
90
- }
91
-
92
- /** @type {string[]} */
93
- const output = [];
91
+ export const createTableTransformer = (cellTransformers = []) => {
92
+ /** @type {Transformer[]} */
93
+ const transformers = [...cellTransformers, ...TRANSFORMERS];
94
+ /** @type {Transformer[]} */
95
+ const exportTransformers = [...transformers, BLOCK_SYNTAX_ESCAPE];
96
+
97
+ return {
98
+ dependencies: [TableNode, TableRowNode, TableCellNode],
99
+ export: (node) => {
100
+ if (!isTableNode(node)) {
101
+ return null;
102
+ }
94
103
 
95
- node.getChildren().forEach((row) => {
96
104
  /** @type {string[]} */
97
- const rowOutput = [];
105
+ const output = [];
98
106
 
99
- if (!isTableRowNode(row)) {
100
- return;
101
- }
107
+ node.getChildren().forEach((row) => {
108
+ /** @type {string[]} */
109
+ const rowOutput = [];
102
110
 
103
- let isHeaderRow = false;
104
-
105
- row.getChildren().forEach((cell) => {
106
- // It’s TableCellNode so it’s just to make flow happy
107
- if (isTableCellNode(cell)) {
108
- rowOutput.push(
109
- convertToMarkdownString([...TRANSFORMERS, BLOCK_SYNTAX_ESCAPE], cell)
110
- // Escape a pipe, which would otherwise end the cell, even within inline code
111
- .replace(/\|/g, '\\|')
112
- .replace(/\n/g, '\\n')
113
- .trim(),
114
- );
115
-
116
- if (cell.__headerState === TableCellHeaderStates.ROW) {
117
- isHeaderRow = true;
118
- }
111
+ if (!isTableRowNode(row)) {
112
+ return;
119
113
  }
120
- });
121
114
 
122
- output.push(`| ${rowOutput.join(' | ')} |`);
115
+ let isHeaderRow = false;
116
+
117
+ row.getChildren().forEach((cell) => {
118
+ // It’s TableCellNode so it’s just to make flow happy
119
+ if (isTableCellNode(cell)) {
120
+ rowOutput.push(
121
+ convertToMarkdownString(exportTransformers, cell)
122
+ // Escape a pipe, which would otherwise end the cell, even within inline code
123
+ .replace(/\|/g, '\\|')
124
+ .replace(/\n/g, '\\n')
125
+ .trim(),
126
+ );
127
+
128
+ if (cell.__headerState === TableCellHeaderStates.ROW) {
129
+ isHeaderRow = true;
130
+ }
131
+ }
132
+ });
123
133
 
124
- if (isHeaderRow) {
125
- output.push(`| ${rowOutput.map(() => '---').join(' | ')} |`);
126
- }
127
- });
134
+ output.push(`| ${rowOutput.join(' | ')} |`);
128
135
 
129
- return output.join('\n');
130
- },
131
- regExp: TABLE_ROW_REG_EXP,
132
- replace: (parentNode, _children, [textContent]) => {
133
- // Header row
134
- if (TABLE_ROW_DIVIDER_REG_EXP.test(textContent)) {
135
- const table = parentNode.getPreviousSibling();
136
+ if (isHeaderRow) {
137
+ output.push(`| ${rowOutput.map(() => '---').join(' | ')} |`);
138
+ }
139
+ });
136
140
 
137
- if (!table || !isTableNode(table)) {
138
- return;
139
- }
141
+ return output.join('\n');
142
+ },
143
+ regExp: TABLE_ROW_REG_EXP,
144
+ replace: (parentNode, _children, [textContent]) => {
145
+ // Header row
146
+ if (TABLE_ROW_DIVIDER_REG_EXP.test(textContent)) {
147
+ const table = parentNode.getPreviousSibling();
140
148
 
141
- const rows = table.getChildren();
142
- const lastRow = rows[rows.length - 1];
149
+ if (!table || !isTableNode(table)) {
150
+ return;
151
+ }
143
152
 
144
- if (!lastRow || !isTableRowNode(lastRow)) {
145
- return;
146
- }
153
+ const rows = table.getChildren();
154
+ const lastRow = rows[rows.length - 1];
147
155
 
148
- // Add header state to row cells
149
- lastRow.getChildren().forEach((cell) => {
150
- if (!isTableCellNode(cell)) {
156
+ if (!lastRow || !isTableRowNode(lastRow)) {
151
157
  return;
152
158
  }
153
159
 
154
- cell.setHeaderStyles(TableCellHeaderStates.ROW, TableCellHeaderStates.ROW);
155
- });
156
-
157
- // Remove line
158
- parentNode.remove();
160
+ // Add header state to row cells
161
+ lastRow.getChildren().forEach((cell) => {
162
+ if (!isTableCellNode(cell)) {
163
+ return;
164
+ }
159
165
 
160
- return;
161
- }
166
+ cell.setHeaderStyles(TableCellHeaderStates.ROW, TableCellHeaderStates.ROW);
167
+ });
162
168
 
163
- const matchCells = mapToTableCells(textContent);
169
+ // Remove line
170
+ parentNode.remove();
164
171
 
165
- if (!matchCells) {
166
- return;
167
- }
172
+ return;
173
+ }
168
174
 
169
- const rows = [matchCells];
170
- let sibling = parentNode.getPreviousSibling();
171
- let maxCells = matchCells.length;
175
+ const matchCells = mapToTableCells(textContent, transformers);
172
176
 
173
- while (sibling) {
174
- if (!isParagraphNode(sibling)) {
175
- break;
177
+ if (!matchCells) {
178
+ return;
176
179
  }
177
180
 
178
- if (sibling.getChildrenSize() !== 1) {
179
- break;
180
- }
181
+ const rows = [matchCells];
182
+ let sibling = parentNode.getPreviousSibling();
183
+ let maxCells = matchCells.length;
181
184
 
182
- const firstChild = sibling.getFirstChild();
185
+ while (sibling) {
186
+ if (!isParagraphNode(sibling)) {
187
+ break;
188
+ }
183
189
 
184
- if (!isTextNode(firstChild)) {
185
- break;
186
- }
190
+ if (sibling.getChildrenSize() !== 1) {
191
+ break;
192
+ }
187
193
 
188
- const cells = mapToTableCells(firstChild.getTextContent());
194
+ const firstChild = sibling.getFirstChild();
189
195
 
190
- if (!cells) {
191
- break;
192
- }
196
+ if (!isTextNode(firstChild)) {
197
+ break;
198
+ }
193
199
 
194
- maxCells = Math.max(maxCells, cells.length);
195
- rows.unshift(cells);
200
+ const cells = mapToTableCells(firstChild.getTextContent(), transformers);
196
201
 
197
- const previousSibling = sibling.getPreviousSibling();
202
+ if (!cells) {
203
+ break;
204
+ }
198
205
 
199
- sibling.remove();
200
- sibling = previousSibling;
201
- }
206
+ maxCells = Math.max(maxCells, cells.length);
207
+ rows.unshift(cells);
202
208
 
203
- const table = createTableNode();
209
+ const previousSibling = sibling.getPreviousSibling();
204
210
 
205
- rows.forEach((cells) => {
206
- const tableRow = createTableRowNode();
211
+ sibling.remove();
212
+ sibling = previousSibling;
213
+ }
207
214
 
208
- table.append(tableRow);
215
+ const table = createTableNode();
209
216
 
210
- for (let i = 0; i < maxCells; i += 1) {
211
- tableRow.append(i < cells.length ? cells[i] : createTableCell(''));
212
- }
213
- });
217
+ rows.forEach((cells) => {
218
+ const tableRow = createTableRowNode();
214
219
 
215
- const previousSibling = parentNode.getPreviousSibling();
220
+ table.append(tableRow);
216
221
 
217
- if (isTableNode(previousSibling) && getTableColumnsSize(previousSibling) === maxCells) {
218
- previousSibling.append(...table.getChildren());
219
- parentNode.remove();
220
- } else {
221
- parentNode.replace(table);
222
- }
222
+ for (let i = 0; i < maxCells; i += 1) {
223
+ tableRow.append(i < cells.length ? cells[i] : createTableCell('', transformers));
224
+ }
225
+ });
226
+
227
+ const previousSibling = parentNode.getPreviousSibling();
228
+
229
+ if (isTableNode(previousSibling) && getTableColumnsSize(previousSibling) === maxCells) {
230
+ previousSibling.append(...table.getChildren());
231
+ parentNode.remove();
232
+ } else {
233
+ parentNode.replace(table);
234
+ }
223
235
 
224
- table.selectEnd();
225
- },
226
- type: 'element',
236
+ table.selectEnd();
237
+ },
238
+ type: 'element',
239
+ };
227
240
  };
@@ -124,3 +124,22 @@
124
124
  @content;
125
125
  }
126
126
  }
127
+
128
+ // The root of a text or code editor, whose sticky toolbar stays below the toolbars of the outer
129
+ // editors when nested, e.g. in an editor component. The root sets the toolbar height inline, which
130
+ // is added to the offset for the inner editors, while their z-index goes down so the outer
131
+ // toolbars stay on top of an inner toolbar being scrolled away.
132
+ @mixin nestable-editor {
133
+ // Wrapped in `&` to keep the declarations before any nested rules of the including block
134
+ & {
135
+ --sui-text-editor-toolbar-top: var(--sui-text-editor-inner-toolbar-top, 0px);
136
+ --sui-text-editor-toolbar-z-index: var(--sui-text-editor-inner-toolbar-z-index, 100);
137
+ }
138
+
139
+ & > :global(*) {
140
+ --sui-text-editor-inner-toolbar-top: calc(
141
+ var(--sui-text-editor-toolbar-top) + var(--sui-text-editor-toolbar-height)
142
+ );
143
+ --sui-text-editor-inner-toolbar-z-index: calc(var(--sui-text-editor-toolbar-z-index) - 1);
144
+ }
145
+ }
@@ -761,7 +761,8 @@ export type TextEditorComponent = {
761
761
  */
762
762
  createNode: (props?: Record<string, any>) => LexicalNode;
763
763
  /**
764
- * Node transformer.
764
+ * Node transformer. A component with a text match transformer
765
+ * is inline, so it can also be inserted into, and read from, a Markdown table cell.
765
766
  */
766
767
  transformer: Transformer;
767
768
  /**
@@ -1047,6 +1048,11 @@ export type TextEditorStore = {
1047
1048
  * mode.
1048
1049
  */
1049
1050
  textArea: HTMLTextAreaElement | undefined;
1051
+ /**
1052
+ * Height of the sticky toolbar in pixels, which the toolbars of
1053
+ * nested editors are placed below. `0` while the toolbar isn’t rendered.
1054
+ */
1055
+ toolbarHeight: number;
1050
1056
  /**
1051
1057
  * ID of the editable element currently shown: the Lexical root in the
1052
1058
  * rich text mode, or the `<textarea>` in the plain text mode.
package/dist/typedefs.js CHANGED
@@ -326,7 +326,8 @@
326
326
  * for the same element type, like a link, with a `priority` of 4 or higher.
327
327
  * @property {(props?: Record<string, any>) => LexicalNode} createNode Function to create a new node
328
328
  * instance.
329
- * @property {Transformer} transformer Node transformer.
329
+ * @property {Transformer} transformer Node transformer. A component with a text match transformer
330
+ * is inline, so it can also be inserted into, and read from, a Markdown table cell.
330
331
  * @property {() => string} [createMarkdown] Function to create the Markdown inserted when the
331
332
  * component is chosen in the plain text mode. By default, a new node created with `createNode` is
332
333
  * exported with `transformer`, which may result in an empty string, for example if the output
@@ -454,6 +455,8 @@
454
455
  * plain text editor.
455
456
  * @property {HTMLTextAreaElement | undefined} textArea The `<textarea>` element of the plain text
456
457
  * mode.
458
+ * @property {number} toolbarHeight Height of the sticky toolbar in pixels, which the toolbars of
459
+ * nested editors are placed below. `0` while the toolbar isn’t rendered.
457
460
  * @property {string} controlId ID of the editable element currently shown: the Lexical root in the
458
461
  * rich text mode, or the `<textarea>` in the plain text mode.
459
462
  * @property {boolean} hasConverterError Whether there was an error while converting Markdown or
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltia/ui",
3
- "version": "0.84.0",
3
+ "version": "0.85.1",
4
4
  "description": "A collection of Svelte components and utilities for building user interfaces.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -76,7 +76,7 @@
76
76
  "@sveltejs/vite-plugin-svelte": "^7.3.1",
77
77
  "@vitest/browser-playwright": "^5.0.4",
78
78
  "@vitest/coverage-v8": "^5.0.4",
79
- "cspell": "^10.3.6",
79
+ "cspell": "^10.4.0",
80
80
  "eslint": "^9.39.5",
81
81
  "eslint-config-airbnb-extended": "^3.3.0",
82
82
  "eslint-config-prettier": "^10.1.8",
@@ -92,7 +92,7 @@
92
92
  "postcss-html": "^2.0.0",
93
93
  "prettier": "^3.9.10",
94
94
  "prettier-plugin-svelte": "^4.1.1",
95
- "rolldown": "^1.2.13",
95
+ "rolldown": "^1.2.14",
96
96
  "sass": "^1.105.1",
97
97
  "shiki": "^4.5.0",
98
98
  "stylelint": "^17.16.0",