@sveltia/ui 0.83.0 → 0.85.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.
@@ -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);
@@ -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.83.0";
4
+ export const UI_VERSION: "0.85.0";
@@ -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.83.0';
6
+ export const UI_VERSION = '0.85.0';
@@ -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,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
  };
@@ -0,0 +1,129 @@
1
+ <!--
2
+ @component
3
+ A color swatch button that opens the browser’s color picker. The equivalent of the HTML
4
+ `<input type="color">` element, styled like the other controls.
5
+ @todo Replace the native `<input>` with a custom component.
6
+ @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/color
7
+ -->
8
+ <script>
9
+ /**
10
+ * @import { CommonEventHandlers, InputEventHandlers } from '../../typedefs.js';
11
+ */
12
+
13
+ /**
14
+ * @typedef {object} Props
15
+ * @property {string} [value] Input value, a lowercase hex color in the `#rrggbb` format. The
16
+ * swatch shows black if no value is given.
17
+ * @property {HTMLInputElement} [element] Reference to the `<input>` element.
18
+ * @property {string} [class] The `class` attribute on the `<input>` element.
19
+ * @property {boolean} [disabled] Whether to disable the widget. An alias of the `aria-disabled`
20
+ * attribute.
21
+ * @property {boolean} [readonly] Whether to make the widget read-only. An alias of the
22
+ * `aria-readonly` attribute. A native color input doesn’t support the `readonly` attribute, so
23
+ * the picker is kept from opening instead, while the input stays focusable, so the current color
24
+ * can still be reached and read by keyboard and assistive technology users, unlike with
25
+ * `disabled`.
26
+ * @property {boolean} [required] Whether to mark the widget required. An alias of the
27
+ * `aria-required` attribute.
28
+ * @property {boolean} [invalid] Whether to mark the widget invalid. An alias of the
29
+ * `aria-invalid` attribute.
30
+ * @property {string} [ariaLabel] `aria-label` attribute.
31
+ */
32
+
33
+ /**
34
+ * @type {CommonEventHandlers & InputEventHandlers & Props & Record<string, any>}
35
+ */
36
+ let {
37
+ /* eslint-disable prefer-const */
38
+ value = $bindable(),
39
+ element = $bindable(),
40
+ class: className,
41
+ disabled = false,
42
+ readonly = false,
43
+ required = false,
44
+ invalid = false,
45
+ ariaLabel = undefined,
46
+ onclick,
47
+ oninput,
48
+ ...restProps
49
+ /* eslint-enable prefer-const */
50
+ } = $props();
51
+
52
+ /**
53
+ * Handle the `click` event. Prevent the picker from opening while read-only; the keyboard
54
+ * activation with the Enter or Space key also fires a `click` event.
55
+ * @param {MouseEvent} event The `click` event object.
56
+ */
57
+ const handleClick = (event) => {
58
+ if (readonly) {
59
+ event.preventDefault();
60
+ }
61
+
62
+ onclick?.(event);
63
+ };
64
+
65
+ /**
66
+ * Update the `value` and call the `oninput` callback.
67
+ * @param {Event} event The `input` event object.
68
+ */
69
+ const handleInput = (event) => {
70
+ value = /** @type {HTMLInputElement} */ (event.currentTarget).value;
71
+ oninput?.(event);
72
+ };
73
+ </script>
74
+
75
+ <input
76
+ bind:this={element}
77
+ {...restProps}
78
+ value={value ?? ''}
79
+ type="color"
80
+ class="sui color-input {className}"
81
+ disabled={disabled || undefined}
82
+ aria-label={ariaLabel ?? restProps['aria-label']}
83
+ aria-disabled={disabled}
84
+ aria-readonly={readonly}
85
+ aria-required={required}
86
+ aria-invalid={invalid}
87
+ onclick={handleClick}
88
+ oninput={handleInput}
89
+ />
90
+
91
+ <style>.color-input {
92
+ display: inline-block;
93
+ margin: var(--sui-focus-ring-width);
94
+ border-width: var(--sui-color-input-border-width, 1px);
95
+ border-color: var(--sui-color-input-border-color, var(--sui-control-border-color));
96
+ border-radius: var(--sui-color-input-border-radius, var(--sui-button-medium-border-radius));
97
+ padding: var(--sui-color-input-padding, 3px);
98
+ width: var(--sui-color-input-width, calc(var(--sui-button-medium-height) * 1.5));
99
+ height: var(--sui-color-input-height, var(--sui-button-medium-height));
100
+ color: inherit;
101
+ background-color: var(--sui-color-input-background-color, var(--sui-textbox-background-color));
102
+ font-family: var(--sui-textbox-font-family);
103
+ cursor: pointer;
104
+ transition: all 200ms;
105
+ }
106
+ .color-input:is(:hover, :focus-visible) {
107
+ background-color: var(--sui-color-input-background-color-focus, var(--sui-hover-background-color));
108
+ }
109
+ .color-input:active {
110
+ background-color: var(--sui-color-input-background-color-active, var(--sui-active-background-color));
111
+ }
112
+ .color-input[aria-readonly=true] {
113
+ cursor: default;
114
+ background-color: var(--sui-disabled-background-color);
115
+ }
116
+ .color-input[aria-invalid=true] {
117
+ border-color: var(--sui-error-border-color);
118
+ }
119
+ .color-input::-webkit-color-swatch-wrapper {
120
+ padding: 0;
121
+ }
122
+ .color-input::-webkit-color-swatch {
123
+ border: 1px solid var(--sui-secondary-border-color);
124
+ border-radius: calc(var(--sui-button-medium-border-radius) / 2);
125
+ }
126
+ .color-input::-moz-color-swatch {
127
+ border: 1px solid var(--sui-secondary-border-color);
128
+ border-radius: calc(var(--sui-button-medium-border-radius) / 2);
129
+ }</style>
@@ -0,0 +1,96 @@
1
+ export default ColorInput;
2
+ type ColorInput = {
3
+ $on?(type: string, callback: (e: any) => void): () => void;
4
+ $set?(props: Partial<KeyboardEventHandlers & MouseEventHandlers & PointerEventHandlers & FocusEventHandlers & DragEventHandlers & InputEventHandlers & Props & Record<string, any>>): void;
5
+ };
6
+ /**
7
+ * A color swatch button that opens the browser’s color picker. The equivalent of the HTML
8
+ * `<input type="color">` element, styled like the other controls.
9
+ * @todo Replace the native `<input>` with a custom component.
10
+ * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/color
11
+ */
12
+ declare const ColorInput: import("svelte").Component<import("../../typedefs.js").KeyboardEventHandlers & import("../../typedefs.js").MouseEventHandlers & import("../../typedefs.js").PointerEventHandlers & import("../../typedefs.js").FocusEventHandlers & import("../../typedefs.js").DragEventHandlers & InputEventHandlers & {
13
+ /**
14
+ * Input value, a lowercase hex color in the `#rrggbb` format. The
15
+ * swatch shows black if no value is given.
16
+ */
17
+ value?: string | undefined;
18
+ /**
19
+ * Reference to the `<input>` element.
20
+ */
21
+ element?: HTMLInputElement | undefined;
22
+ /**
23
+ * The `class` attribute on the `<input>` element.
24
+ */
25
+ class?: string | undefined;
26
+ /**
27
+ * Whether to disable the widget. An alias of the `aria-disabled`
28
+ * attribute.
29
+ */
30
+ disabled?: boolean | undefined;
31
+ /**
32
+ * Whether to make the widget read-only. An alias of the
33
+ * `aria-readonly` attribute. A native color input doesn’t support the `readonly` attribute, so
34
+ * the picker is kept from opening instead, while the input stays focusable, so the current color
35
+ * can still be reached and read by keyboard and assistive technology users, unlike with
36
+ * `disabled`.
37
+ */
38
+ readonly?: boolean | undefined;
39
+ /**
40
+ * Whether to mark the widget required. An alias of the
41
+ * `aria-required` attribute.
42
+ */
43
+ required?: boolean | undefined;
44
+ /**
45
+ * Whether to mark the widget invalid. An alias of the
46
+ * `aria-invalid` attribute.
47
+ */
48
+ invalid?: boolean | undefined;
49
+ /**
50
+ * `aria-label` attribute.
51
+ */
52
+ ariaLabel?: string | undefined;
53
+ } & Record<string, any>, {}, "value" | "element">;
54
+ type Props = {
55
+ /**
56
+ * Input value, a lowercase hex color in the `#rrggbb` format. The
57
+ * swatch shows black if no value is given.
58
+ */
59
+ value?: string | undefined;
60
+ /**
61
+ * Reference to the `<input>` element.
62
+ */
63
+ element?: HTMLInputElement | undefined;
64
+ /**
65
+ * The `class` attribute on the `<input>` element.
66
+ */
67
+ class?: string | undefined;
68
+ /**
69
+ * Whether to disable the widget. An alias of the `aria-disabled`
70
+ * attribute.
71
+ */
72
+ disabled?: boolean | undefined;
73
+ /**
74
+ * Whether to make the widget read-only. An alias of the
75
+ * `aria-readonly` attribute. A native color input doesn’t support the `readonly` attribute, so
76
+ * the picker is kept from opening instead, while the input stays focusable, so the current color
77
+ * can still be reached and read by keyboard and assistive technology users, unlike with
78
+ * `disabled`.
79
+ */
80
+ readonly?: boolean | undefined;
81
+ /**
82
+ * Whether to mark the widget required. An alias of the
83
+ * `aria-required` attribute.
84
+ */
85
+ required?: boolean | undefined;
86
+ /**
87
+ * Whether to mark the widget invalid. An alias of the
88
+ * `aria-invalid` attribute.
89
+ */
90
+ invalid?: boolean | undefined;
91
+ /**
92
+ * `aria-label` attribute.
93
+ */
94
+ ariaLabel?: string | undefined;
95
+ };
96
+ import type { InputEventHandlers } from '../../typedefs.js';
@@ -0,0 +1,131 @@
1
+ <!--
2
+ @component
3
+ A date and/or time field. The equivalent of the HTML `<input type="date">`,
4
+ `<input type="datetime-local">` and `<input type="time">` elements, styled like the other text
5
+ fields. The browser’s native picker is kept, and follows the light or dark theme through the
6
+ inherited `color-scheme`.
7
+ @todo Replace the native `<input>` with a custom component.
8
+ @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date
9
+ @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/datetime-local
10
+ @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/time
11
+ -->
12
+ <script>
13
+ /**
14
+ * @import { CommonEventHandlers, InputEventHandlers } from '../../typedefs.js';
15
+ */
16
+
17
+ /**
18
+ * @typedef {object} Props
19
+ * @property {string} [value] Input value, in the native input’s format: `YYYY-MM-DD` for `date`,
20
+ * `YYYY-MM-DDTHH:mm` (with optional seconds) for `datetime-local`, and `HH:mm` (with optional
21
+ * seconds) for `time`. An empty string if no value is entered.
22
+ * @property {HTMLInputElement} [element] Reference to the `<input>` element.
23
+ * @property {'date' | 'datetime-local' | 'time'} [type] The `type` attribute on the `<input>`.
24
+ * @property {string} [min] Minimum allowed value, in the same format as `value`.
25
+ * @property {string} [max] Maximum allowed value, in the same format as `value`.
26
+ * @property {number | 'any'} [step] Stepping interval: in days for `date`, in seconds for
27
+ * `datetime-local` and `time`. A step under 60 for the latter two shows the seconds.
28
+ * @property {string} [class] The `class` attribute on the `<input>` element.
29
+ * @property {boolean} [disabled] Whether to disable the widget. An alias of the `aria-disabled`
30
+ * 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
+ * @property {string} [ariaLabel] `aria-label` attribute.
38
+ */
39
+
40
+ /**
41
+ * @type {CommonEventHandlers & InputEventHandlers & Props & Record<string, any>}
42
+ */
43
+ let {
44
+ /* eslint-disable prefer-const */
45
+ value = $bindable(),
46
+ element = $bindable(),
47
+ type = 'date',
48
+ min = undefined,
49
+ max = undefined,
50
+ step = undefined,
51
+ class: className,
52
+ disabled = false,
53
+ readonly = false,
54
+ required = false,
55
+ invalid = false,
56
+ ariaLabel = undefined,
57
+ oninput,
58
+ ...restProps
59
+ /* eslint-enable prefer-const */
60
+ } = $props();
61
+
62
+ /**
63
+ * Update the `value` and call the `oninput` callback.
64
+ * @param {Event} event The `input` event object.
65
+ */
66
+ const handleInput = (event) => {
67
+ value = /** @type {HTMLInputElement} */ (event.currentTarget).value;
68
+ oninput?.(event);
69
+ };
70
+ </script>
71
+
72
+ <input
73
+ bind:this={element}
74
+ {...restProps}
75
+ value={value ?? ''}
76
+ {type}
77
+ {min}
78
+ {max}
79
+ {step}
80
+ class="sui date-time-input {className}"
81
+ disabled={disabled || undefined}
82
+ readonly={readonly || undefined}
83
+ aria-label={ariaLabel ?? restProps['aria-label']}
84
+ aria-disabled={disabled}
85
+ aria-readonly={readonly}
86
+ aria-required={required}
87
+ aria-invalid={invalid}
88
+ oninput={handleInput}
89
+ />
90
+
91
+ <style>.date-time-input {
92
+ display: inline-block;
93
+ margin: var(--sui-focus-ring-width);
94
+ border-width: var(--sui-textbox-border-width, 1px);
95
+ border-color: var(--sui-textbox-border-color);
96
+ border-radius: var(--sui-textbox-border-radius);
97
+ padding: var(--sui-textbox-singleline-padding);
98
+ width: auto;
99
+ min-width: 0;
100
+ height: var(--sui-textbox-height);
101
+ color: var(--sui-textbox-foreground-color);
102
+ background-color: var(--sui-textbox-background-color);
103
+ font-family: var(--sui-textbox-font-family);
104
+ font-size: var(--sui-textbox-font-size);
105
+ line-height: var(--sui-textbox-singleline-line-height);
106
+ font-weight: var(--sui-textbox-font-weight, var(--sui-font-weight-normal, normal));
107
+ text-transform: var(--sui-date-time-input-text-transform, uppercase);
108
+ letter-spacing: var(--sui-textbox-letter-spacing, normal);
109
+ font-variant-numeric: tabular-nums;
110
+ transition: all 200ms;
111
+ }
112
+ .date-time-input:focus {
113
+ color: var(--sui-textbox-foreground-color-focus, var(--sui-textbox-foreground-color));
114
+ background-color: var(--sui-textbox-background-color-focus, var(--sui-textbox-background-color));
115
+ }
116
+ .date-time-input:read-only {
117
+ color: var(--sui-secondary-foreground-color);
118
+ border-color: var(--sui-textbox-border-color) !important;
119
+ }
120
+ .date-time-input:is(:disabled, :read-only) {
121
+ background-color: var(--sui-disabled-background-color);
122
+ }
123
+ .date-time-input[aria-invalid=true] {
124
+ border-color: var(--sui-error-border-color);
125
+ }
126
+ .date-time-input::-webkit-calendar-picker-indicator {
127
+ cursor: pointer;
128
+ }
129
+ .date-time-input:is(:disabled, :read-only)::-webkit-calendar-picker-indicator {
130
+ cursor: default;
131
+ }</style>
@@ -0,0 +1,130 @@
1
+ export default DateTimeInput;
2
+ type DateTimeInput = {
3
+ $on?(type: string, callback: (e: any) => void): () => void;
4
+ $set?(props: Partial<KeyboardEventHandlers & MouseEventHandlers & PointerEventHandlers & FocusEventHandlers & DragEventHandlers & InputEventHandlers & Props & Record<string, any>>): void;
5
+ };
6
+ /**
7
+ * A date and/or time field. The equivalent of the HTML `<input type="date">`,
8
+ * `<input type="datetime-local">` and `<input type="time">` elements, styled like the other text
9
+ * fields. The browser’s native picker is kept, and follows the light or dark theme through the
10
+ * inherited `color-scheme`.
11
+ * @todo Replace the native `<input>` with a custom component.
12
+ * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date
13
+ * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/datetime-local
14
+ * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/time
15
+ */
16
+ declare const DateTimeInput: import("svelte").Component<import("../../typedefs.js").KeyboardEventHandlers & import("../../typedefs.js").MouseEventHandlers & import("../../typedefs.js").PointerEventHandlers & import("../../typedefs.js").FocusEventHandlers & import("../../typedefs.js").DragEventHandlers & InputEventHandlers & {
17
+ /**
18
+ * Input value, in the native input’s format: `YYYY-MM-DD` for `date`,
19
+ * `YYYY-MM-DDTHH:mm` (with optional seconds) for `datetime-local`, and `HH:mm` (with optional
20
+ * seconds) for `time`. An empty string if no value is entered.
21
+ */
22
+ value?: string | undefined;
23
+ /**
24
+ * Reference to the `<input>` element.
25
+ */
26
+ element?: HTMLInputElement | undefined;
27
+ /**
28
+ * The `type` attribute on the `<input>`.
29
+ */
30
+ type?: "time" | "date" | "datetime-local" | undefined;
31
+ /**
32
+ * Minimum allowed value, in the same format as `value`.
33
+ */
34
+ min?: string | undefined;
35
+ /**
36
+ * Maximum allowed value, in the same format as `value`.
37
+ */
38
+ max?: string | undefined;
39
+ /**
40
+ * Stepping interval: in days for `date`, in seconds for
41
+ * `datetime-local` and `time`. A step under 60 for the latter two shows the seconds.
42
+ */
43
+ step?: number | "any" | undefined;
44
+ /**
45
+ * The `class` attribute on the `<input>` element.
46
+ */
47
+ class?: string | undefined;
48
+ /**
49
+ * Whether to disable the widget. An alias of the `aria-disabled`
50
+ * attribute.
51
+ */
52
+ disabled?: boolean | undefined;
53
+ /**
54
+ * Whether to make the widget read-only. An alias of the
55
+ * `aria-readonly` attribute.
56
+ */
57
+ readonly?: boolean | undefined;
58
+ /**
59
+ * Whether to mark the widget required. An alias of the
60
+ * `aria-required` attribute.
61
+ */
62
+ required?: boolean | undefined;
63
+ /**
64
+ * Whether to mark the widget invalid. An alias of the
65
+ * `aria-invalid` attribute.
66
+ */
67
+ invalid?: boolean | undefined;
68
+ /**
69
+ * `aria-label` attribute.
70
+ */
71
+ ariaLabel?: string | undefined;
72
+ } & Record<string, any>, {}, "value" | "element">;
73
+ type Props = {
74
+ /**
75
+ * Input value, in the native input’s format: `YYYY-MM-DD` for `date`,
76
+ * `YYYY-MM-DDTHH:mm` (with optional seconds) for `datetime-local`, and `HH:mm` (with optional
77
+ * seconds) for `time`. An empty string if no value is entered.
78
+ */
79
+ value?: string | undefined;
80
+ /**
81
+ * Reference to the `<input>` element.
82
+ */
83
+ element?: HTMLInputElement | undefined;
84
+ /**
85
+ * The `type` attribute on the `<input>`.
86
+ */
87
+ type?: "time" | "date" | "datetime-local" | undefined;
88
+ /**
89
+ * Minimum allowed value, in the same format as `value`.
90
+ */
91
+ min?: string | undefined;
92
+ /**
93
+ * Maximum allowed value, in the same format as `value`.
94
+ */
95
+ max?: string | undefined;
96
+ /**
97
+ * Stepping interval: in days for `date`, in seconds for
98
+ * `datetime-local` and `time`. A step under 60 for the latter two shows the seconds.
99
+ */
100
+ step?: number | "any" | undefined;
101
+ /**
102
+ * The `class` attribute on the `<input>` element.
103
+ */
104
+ class?: string | undefined;
105
+ /**
106
+ * Whether to disable the widget. An alias of the `aria-disabled`
107
+ * attribute.
108
+ */
109
+ disabled?: boolean | undefined;
110
+ /**
111
+ * Whether to make the widget read-only. An alias of the
112
+ * `aria-readonly` attribute.
113
+ */
114
+ readonly?: boolean | undefined;
115
+ /**
116
+ * Whether to mark the widget required. An alias of the
117
+ * `aria-required` attribute.
118
+ */
119
+ required?: boolean | undefined;
120
+ /**
121
+ * Whether to mark the widget invalid. An alias of the
122
+ * `aria-invalid` attribute.
123
+ */
124
+ invalid?: boolean | undefined;
125
+ /**
126
+ * `aria-label` attribute.
127
+ */
128
+ ariaLabel?: string | undefined;
129
+ };
130
+ import type { InputEventHandlers } from '../../typedefs.js';
package/dist/index.d.ts CHANGED
@@ -64,6 +64,8 @@ export { default as TabPanels } from "./components/tabs/tab-panels.svelte";
64
64
  export { default as Tab } from "./components/tabs/tab.svelte";
65
65
  export { default as CodeEditor } from "./components/text-editor/code-editor.svelte";
66
66
  export { default as TextEditor } from "./components/text-editor/text-editor.svelte";
67
+ export { default as ColorInput } from "./components/text-field/color-input.svelte";
68
+ export { default as DateTimeInput } from "./components/text-field/date-time-input.svelte";
67
69
  export { default as NumberInput } from "./components/text-field/number-input.svelte";
68
70
  export { default as PasswordInput } from "./components/text-field/password-input.svelte";
69
71
  export { default as SearchBar } from "./components/text-field/search-bar.svelte";
package/dist/index.js CHANGED
@@ -64,6 +64,8 @@ export { default as TabPanels } from './components/tabs/tab-panels.svelte';
64
64
  export { default as Tab } from './components/tabs/tab.svelte';
65
65
  export { default as CodeEditor } from './components/text-editor/code-editor.svelte';
66
66
  export { default as TextEditor } from './components/text-editor/text-editor.svelte';
67
+ export { default as ColorInput } from './components/text-field/color-input.svelte';
68
+ export { default as DateTimeInput } from './components/text-field/date-time-input.svelte';
67
69
  export { default as NumberInput } from './components/text-field/number-input.svelte';
68
70
  export { default as PasswordInput } from './components/text-field/password-input.svelte';
69
71
  export { default as SearchBar } from './components/text-field/search-bar.svelte';
@@ -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
  /**
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltia/ui",
3
- "version": "0.83.0",
3
+ "version": "0.85.0",
4
4
  "description": "A collection of Svelte components and utilities for building user interfaces.",
5
5
  "repository": {
6
6
  "type": "git",