@diegopluna/narvi 0.5.8 → 0.5.9

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.
@@ -23,7 +23,6 @@
23
23
  import Button from '../button/Button.svelte';
24
24
  import Notice from '../notice/Notice.svelte';
25
25
  import { nestDialog, popupContainer } from '../../internal/popup.js';
26
- import { unbindLater } from '../../internal/closing.svelte.js';
27
26
  import { dialog } from './styles.js';
28
27
 
29
28
  export type ConfirmDialogProps = {
@@ -186,7 +185,7 @@
186
185
  {#if words.description || words.warning}
187
186
  <AlertDialogDescription {...stylex.attrs(styles.describe)}>
188
187
  {#snippet render({ props })}
189
- <div {...unbindLater(props)}>
188
+ <div {...props}>
190
189
  {#if words.description}
191
190
  <p {...stylex.attrs(dialog.description)}>{words.description}</p>
192
191
  {/if}
@@ -3,7 +3,7 @@
3
3
  import { DialogDescription as UiDialogDescription } from '@ui-sdk/svelte/dialog';
4
4
  import type { Snippet } from 'svelte';
5
5
  import * as stylex from '@stylexjs/stylex';
6
- import { keepWhileClosing, place, unbindLater } from '../../internal/closing.svelte.js';
6
+ import { keepWhileClosing, place } from '../../internal/closing.svelte.js';
7
7
  import { attrs, type Sx } from '../../internal/sx.js';
8
8
  import { dialog } from './styles.js';
9
9
 
@@ -26,7 +26,7 @@
26
26
  <!-- A div, as bits-ui's was, so a description can hold more than a line of text -->
27
27
  <UiDialogDescription {...rest} {...attrs([dialog.description, sx], className)}>
28
28
  {#snippet render({ props })}
29
- <div bind:this={element} {...unbindLater(props)}>
29
+ <div bind:this={element} {...props}>
30
30
  {#if kept()}
31
31
  <span {...stylex.attrs(dialog.kept)} {@attach place(kept()!)}></span>
32
32
  {:else}
@@ -3,7 +3,7 @@
3
3
  import { DialogTitle as UiDialogTitle } from '@ui-sdk/svelte/dialog';
4
4
  import type { Snippet } from 'svelte';
5
5
  import * as stylex from '@stylexjs/stylex';
6
- import { keepWhileClosing, place, unbindLater } from '../../internal/closing.svelte.js';
6
+ import { keepWhileClosing, place } from '../../internal/closing.svelte.js';
7
7
  import { attrs, type Sx } from '../../internal/sx.js';
8
8
  import { dialog } from './styles.js';
9
9
 
@@ -28,7 +28,7 @@
28
28
  <!-- Names the dialog for assistive technology -->
29
29
  <UiDialogTitle {...rest} {...attrs([dialog.title, sx], className)}>
30
30
  {#snippet render({ props })}
31
- <svelte:element this={`h${level}`} bind:this={element} {...unbindLater(props)}>
31
+ <svelte:element this={`h${level}`} bind:this={element} {...props}>
32
32
  {#if kept()}
33
33
  <span {...stylex.attrs(dialog.kept)} {@attach place(kept()!)}></span>
34
34
  {:else}
@@ -1,11 +1,16 @@
1
1
  <script lang="ts" module>
2
2
  import * as stylex from '@stylexjs/stylex';
3
- import type { Snippet } from 'svelte';
3
+ import { DEV } from 'esm-env';
4
+ import { tick, type Snippet } from 'svelte';
4
5
  import type { ClassValue, HTMLInputAttributes } from 'svelte/elements';
5
6
  import '../../internal/icons.css';
6
7
  import { colors, density } from '../../tokens.stylex.js';
8
+ import { media } from '../../media.stylex.js';
7
9
  import { control, type ControlSize } from '../../internal/control.js';
10
+ import Glyph from '../../internal/Glyph.svelte';
11
+ import { inputMarker } from '../../internal/markers.stylex.js';
8
12
  import { attrs, type Sx } from '../../internal/sx.js';
13
+ import Button from '../button/Button.svelte';
9
14
  import { getFieldContext } from '../field/context.js';
10
15
 
11
16
  export type InputSize = ControlSize;
@@ -20,10 +25,24 @@
20
25
  * the field itself.
21
26
  */
22
27
  icon?: Snippet | undefined;
28
+ /**
29
+ * Controls at the end of the field, inside its edge, such as a `Button size="xs" iconOnly
30
+ * variant="ghost"` that clears it. They keep their own names and take the pointer; the
31
+ * text stops before them. With one, `sx` and `class` style the element around the field,
32
+ * as with `icon`.
33
+ */
34
+ end?: Snippet | undefined;
35
+ /**
36
+ * A password field with an eye at its end that shows and hides what is typed, whatever
37
+ * `type` says. It takes the place of `end`, which is not drawn beside it.
38
+ */
39
+ reveal?: boolean | undefined;
40
+ /** The eye's name, which stays the same while it is pressed. "Show password" by default. */
41
+ revealLabel?: string | undefined;
23
42
  sx?: Sx | undefined;
24
43
  /**
25
- * Styles for the field itself, whether or not there is an `icon`: its text, its fill,
26
- * its edge. Without an icon they go after `sx`.
44
+ * Styles for the field itself, whether or not there is an `icon` or an `end`: its text, its
45
+ * fill, its edge. Without either they go after `sx`.
27
46
  */
28
47
  inputSx?: Sx | undefined;
29
48
  /** Classes for the field itself, as `inputSx`. */
@@ -31,9 +50,18 @@
31
50
  ref?: HTMLInputElement | null | undefined;
32
51
  };
33
52
 
53
+ // Hover and focus as they happen, or as the catalog shows them, as in `internal/control.ts`
54
+ const HOVER = ':is(:hover, [data-preview~="hover"])';
55
+ const FOCUS = ':is(:focus-visible, [data-preview~="focus"])';
56
+
34
57
  /** A length at the window's density (`density` in the tokens). */
35
58
  const d = (rem: string) => `calc(${rem} * ${density.factor})`;
36
59
 
60
+ // What sits at the end is as wide as it measures; until it has been measured, one xs button
61
+ const END_WIDTH = `var(--narvi-input-end-width, ${d('1.5rem')})`;
62
+ // Between the end of the text and what sits at the end
63
+ const END_GAP = '0.25rem';
64
+
37
65
  const styles = stylex.create({
38
66
  frame: { position: 'relative', display: 'block', width: '100%', minWidth: 0 },
39
67
  // In the field's start padding, where the pointer passes through to the field
@@ -52,19 +80,57 @@
52
80
  // gap of 6px, which keep theirs
53
81
  besideSm: { paddingInlineStart: `calc(${d('0.5rem')} + 1.25rem)` },
54
82
  besideMd: { paddingInlineStart: `calc(${d('0.625rem')} + 1.375rem)` },
55
- besideLg: { paddingInlineStart: `calc(${d('0.75rem')} + 1.375rem)` }
83
+ besideLg: { paddingInlineStart: `calc(${d('0.75rem')} + 1.375rem)` },
84
+ // Inside the field's end, centred in its height. An xs button (24px) sits as far from the
85
+ // end as from the top and the bottom.
86
+ end: {
87
+ position: 'absolute',
88
+ insetBlock: 0,
89
+ display: 'flex',
90
+ alignItems: 'center',
91
+ gap: '0.125rem',
92
+ color: colors.textSubtle
93
+ },
94
+ endSm: { '--narvi-icon-size': '0.875rem', insetInlineEnd: d('0.125rem') },
95
+ endMd: { '--narvi-icon-size': '1rem', insetInlineEnd: d('0.3125rem') },
96
+ endLg: { '--narvi-icon-size': '1rem', insetInlineEnd: d('0.5rem') },
97
+ // The text stops before what sits at the end: its inset, its width and a gap
98
+ beforeSm: { paddingInlineEnd: `calc(${d('0.125rem')} + ${END_WIDTH} + ${END_GAP})` },
99
+ beforeMd: { paddingInlineEnd: `calc(${d('0.3125rem')} + ${END_WIDTH} + ${END_GAP})` },
100
+ beforeLg: { paddingInlineEnd: `calc(${d('0.5rem')} + ${END_WIDTH} + ${END_GAP})` },
101
+ // The pointer on a control at the end is still on the field: its edge stays firm
102
+ held: {
103
+ borderColor: {
104
+ default: colors.borderControl,
105
+ [HOVER]: { default: null, [media.hover]: colors.borderControlHover },
106
+ // The ancestor's hover outranks the field's own focus, so focus is said again in it
107
+ [stylex.when.ancestor(':hover', inputMarker)]: {
108
+ default: null,
109
+ [media.hover]: { default: colors.borderControlHover, [FOCUS]: colors.focusRing }
110
+ },
111
+ [FOCUS]: colors.focusRing
112
+ }
113
+ },
114
+ // Edge's own eye in a password field, beside Narvi's
115
+ noNativeReveal: { '::-ms-reveal': { display: 'none' } }
56
116
  });
57
117
 
58
118
  const iconStyles = { sm: styles.iconSm, md: styles.iconMd, lg: styles.iconLg };
59
119
  const besideStyles = { sm: styles.besideSm, md: styles.besideMd, lg: styles.besideLg };
120
+ const endStyles = { sm: styles.endSm, md: styles.endMd, lg: styles.endLg };
121
+ const beforeStyles = { sm: styles.beforeSm, md: styles.beforeMd, lg: styles.beforeLg };
60
122
  </script>
61
123
 
62
124
  <script lang="ts">
63
125
  let {
64
126
  value = $bindable(),
65
127
  size = 'md',
128
+ type,
66
129
  invalid,
67
130
  icon,
131
+ end,
132
+ reveal = false,
133
+ revealLabel = 'Show password',
68
134
  disabled,
69
135
  required,
70
136
  id,
@@ -77,31 +143,106 @@
77
143
  ...rest
78
144
  }: InputProps = $props();
79
145
 
146
+ $effect(() => {
147
+ if (DEV && reveal && end) {
148
+ console.warn(
149
+ 'Input: `reveal` draws its own eye at the end, so the `end` snippet is not drawn.'
150
+ );
151
+ }
152
+ });
153
+
80
154
  const field = getFieldContext();
81
155
  const isInvalid = $derived(invalid ?? field?.invalid ?? false);
156
+ const isDisabled = $derived(disabled ?? field?.disabled);
157
+ const inputId = $derived(id ?? field?.id);
158
+
159
+ let shown = $state(false);
160
+ const inputType = $derived(reveal ? (shown ? 'text' : 'password') : type);
161
+
162
+ const hasEnd = $derived(reveal || end !== undefined);
163
+ // Measured once it renders; 0 when the snippet renders nothing, as a clear button does once
164
+ // the field is empty, and the field takes its own padding back
165
+ let endWidth = $state<number | undefined>(undefined);
166
+ const endTaken = $derived(hasEnd && endWidth !== 0);
167
+
168
+ /** Shows or hides the password, keeping the caret and the selection where they were. */
169
+ async function toggle() {
170
+ const input = ref;
171
+ const focused = input !== null && input === document.activeElement;
172
+ const start = input?.selectionStart ?? null;
173
+ const finish = input?.selectionEnd ?? null;
174
+ const direction = input?.selectionDirection ?? undefined;
175
+ shown = !shown;
176
+ if (!focused || start === null || finish === null) return;
177
+ await tick();
178
+ input.setSelectionRange(start, finish, direction);
179
+ }
82
180
  </script>
83
181
 
84
- {#snippet input(own: Sx[], className?: ClassValue | null)}
182
+ {#snippet textField(own: Sx[], className?: ClassValue | null)}
85
183
  <input
86
184
  bind:this={ref}
87
185
  bind:value
88
- id={id ?? field?.id}
89
- disabled={disabled ?? field?.disabled}
186
+ type={inputType}
187
+ id={inputId}
188
+ disabled={isDisabled}
90
189
  required={required ?? field?.required}
91
190
  aria-invalid={isInvalid ? true : undefined}
92
191
  aria-describedby={describedBy ?? field?.describedBy}
93
192
  {...rest}
94
- {...attrs([control.base, control[size], isInvalid && control.invalid, ...own], className)}
193
+ {...attrs(
194
+ [
195
+ control.base,
196
+ control[size],
197
+ hasEnd && styles.held,
198
+ isInvalid && control.invalid,
199
+ reveal && styles.noNativeReveal,
200
+ ...own
201
+ ],
202
+ className
203
+ )}
204
+ style:--narvi-input-end-width={endWidth === undefined ? undefined : `${endWidth}px`}
95
205
  />
96
206
  {/snippet}
97
207
 
98
- {#if icon}
99
- <span data-slot="input" {...attrs([styles.frame, sx], className)}>
100
- <span data-icons aria-hidden="true" {...stylex.attrs(styles.icon, iconStyles[size])}>
101
- {@render icon()}
102
- </span>
103
- {@render input([besideStyles[size], inputSx], inputClass)}
208
+ {#if icon || hasEnd}
209
+ <span data-slot="input" {...attrs([styles.frame, hasEnd && inputMarker, sx], className)}>
210
+ {#if icon}
211
+ <span data-icons aria-hidden="true" {...stylex.attrs(styles.icon, iconStyles[size])}>
212
+ {@render icon()}
213
+ </span>
214
+ {/if}
215
+ {@render textField(
216
+ [icon && besideStyles[size], endTaken && beforeStyles[size], inputSx],
217
+ inputClass
218
+ )}
219
+ {#if hasEnd}
220
+ <span
221
+ data-slot="input-end"
222
+ data-icons
223
+ bind:offsetWidth={endWidth}
224
+ {...stylex.attrs(styles.end, endStyles[size])}
225
+ >
226
+ {#if reveal}
227
+ <Button
228
+ size="xs"
229
+ iconOnly
230
+ variant="ghost"
231
+ aria-label={revealLabel}
232
+ aria-controls={inputId}
233
+ pressed={shown}
234
+ disabled={isDisabled}
235
+ onmousedown={(event: MouseEvent) => event.preventDefault()}
236
+ onclick={toggle}
237
+ >
238
+ <Glyph name={shown ? 'conceal' : 'reveal'} size={14} stroke={1.75} />
239
+ </Button>
240
+ {:else}
241
+ {@render end?.()}
242
+ {/if}
243
+ </span>
244
+ {/if}
104
245
  </span>
105
246
  {:else}
106
- {@render input([sx, inputSx], [className, inputClass])}
247
+ {@render textField([sx, inputSx], [className, inputClass])}
107
248
  {/if}
@@ -1,4 +1,4 @@
1
- import type { Snippet } from 'svelte';
1
+ import { type Snippet } from 'svelte';
2
2
  import type { ClassValue, HTMLInputAttributes } from 'svelte/elements';
3
3
  import '../../internal/icons.css';
4
4
  import { type ControlSize } from '../../internal/control.js';
@@ -14,10 +14,24 @@ export type InputProps = Omit<HTMLInputAttributes, 'size' | 'children'> & {
14
14
  * the field itself.
15
15
  */
16
16
  icon?: Snippet | undefined;
17
+ /**
18
+ * Controls at the end of the field, inside its edge, such as a `Button size="xs" iconOnly
19
+ * variant="ghost"` that clears it. They keep their own names and take the pointer; the
20
+ * text stops before them. With one, `sx` and `class` style the element around the field,
21
+ * as with `icon`.
22
+ */
23
+ end?: Snippet | undefined;
24
+ /**
25
+ * A password field with an eye at its end that shows and hides what is typed, whatever
26
+ * `type` says. It takes the place of `end`, which is not drawn beside it.
27
+ */
28
+ reveal?: boolean | undefined;
29
+ /** The eye's name, which stays the same while it is pressed. "Show password" by default. */
30
+ revealLabel?: string | undefined;
17
31
  sx?: Sx | undefined;
18
32
  /**
19
- * Styles for the field itself, whether or not there is an `icon`: its text, its fill,
20
- * its edge. Without an icon they go after `sx`.
33
+ * Styles for the field itself, whether or not there is an `icon` or an `end`: its text, its
34
+ * fill, its edge. Without either they go after `sx`.
21
35
  */
22
36
  inputSx?: Sx | undefined;
23
37
  /** Classes for the field itself, as `inputSx`. */
@@ -26,6 +26,17 @@
26
26
  'M1.75 8S4 3.75 8 3.75 14.25 8 14.25 8 12 12.25 8 12.25 1.75 8 1.75 8Z',
27
27
  'M10 8a2 2 0 1 1-4 0 2 2 0 0 1 4 0Z'
28
28
  ],
29
+ // Showing and hiding a password: Lucide's eye and eye-off, on this grid
30
+ reveal: [
31
+ 'M1.37 8.23a.67.67 0 0 1 0-.46 7.17 7.17 0 0 1 13.26 0 .67.67 0 0 1 0 .46 7.17 7.17 0 0 1-13.26 0',
32
+ 'M10 8a2 2 0 1 1-4 0 2 2 0 0 1 4 0Z'
33
+ ],
34
+ conceal: [
35
+ 'M7.16 3.38a7.16 7.16 0 0 1 7.47 4.39.67.67 0 0 1 0 .46 7.16 7.16 0 0 1-.96 1.66',
36
+ 'M9.39 9.44a2 2 0 0 1-2.83-2.83',
37
+ 'M11.65 11.67a7.17 7.17 0 0 1-10.28-3.44.67.67 0 0 1 0-.46 7.17 7.17 0 0 1 2.96-3.43',
38
+ 'M1.33 1.33l13.34 13.34'
39
+ ],
29
40
  globe: [
30
41
  'M14 8A6 6 0 1 1 2 8a6 6 0 0 1 12 0Z',
31
42
  'M2 8h12',
@@ -13,6 +13,8 @@ declare const paths: {
13
13
  readonly terminal: readonly ["M3.5 4.5l3 3.25-3 3.25", "M8 11.5h4.5"];
14
14
  readonly pencil: readonly ["M10.5 3.5 12.5 5.5", "M3 13l.5-2.5 7.75-7.75a1.4 1.4 0 0 1 2 2L5.5 12.5Z"];
15
15
  readonly eye: readonly ["M1.75 8S4 3.75 8 3.75 14.25 8 14.25 8 12 12.25 8 12.25 1.75 8 1.75 8Z", "M10 8a2 2 0 1 1-4 0 2 2 0 0 1 4 0Z"];
16
+ readonly reveal: readonly ["M1.37 8.23a.67.67 0 0 1 0-.46 7.17 7.17 0 0 1 13.26 0 .67.67 0 0 1 0 .46 7.17 7.17 0 0 1-13.26 0", "M10 8a2 2 0 1 1-4 0 2 2 0 0 1 4 0Z"];
17
+ readonly conceal: readonly ["M7.16 3.38a7.16 7.16 0 0 1 7.47 4.39.67.67 0 0 1 0 .46 7.16 7.16 0 0 1-.96 1.66", "M9.39 9.44a2 2 0 0 1-2.83-2.83", "M11.65 11.67a7.17 7.17 0 0 1-10.28-3.44.67.67 0 0 1 0-.46 7.17 7.17 0 0 1 2.96-3.43", "M1.33 1.33l13.34 13.34"];
16
18
  readonly globe: readonly ["M14 8A6 6 0 1 1 2 8a6 6 0 0 1 12 0Z", "M2 8h12", "M8 2c1.7 1.7 2.5 3.7 2.5 6S9.7 12.3 8 14C6.3 12.3 5.5 10.3 5.5 8S6.3 3.7 8 2Z"];
17
19
  readonly sparkle: readonly ["M8 2.5 9.4 6.6 13.5 8 9.4 9.4 8 13.5 6.6 9.4 2.5 8 6.6 6.6Z"];
18
20
  readonly squarePen: readonly ["M8 2.75H4.25C3.56 2.75 3 3.31 3 4v7.75c0 .69.56 1.25 1.25 1.25H12c.69 0 1.25-.56 1.25-1.25V8", "M12.25 1.75a.67.67 0 0 1 2 2L8.24 9.76a1.33 1.33 0 0 1-.57.34l-1.92.56a.33.33 0 0 1-.41-.41l.56-1.92a1.33 1.33 0 0 1 .34-.57Z"];
@@ -8,9 +8,3 @@ export declare function provideDialogOpen(open: () => boolean): void;
8
8
  export declare function keepWhileClosing(element: () => Element | undefined): () => Node[] | undefined;
9
9
  /** Puts the kept nodes in an element. */
10
10
  export declare const place: (nodes: Node[]) => (element: Element) => void;
11
- /**
12
- * A ui-sdk part's props, with its binding let go of after Svelte's teardown when its element has
13
- * left the page. Spread them on the part's element. An element that stays, binding again, lets
14
- * go at once, before it binds.
15
- */
16
- export declare function unbindLater<T extends object>(props: T): T;
@@ -8,13 +8,6 @@
8
8
  * - The text is kept. Once the dialog's `open` turns false, its title and description show what
9
9
  * they showed until the dialog has gone, so it does not read "Revoke ?" as it fades. Opened
10
10
  * again, they follow their content again.
11
- * - A part that leaves the page lets ui-sdk go of it after Svelte's teardown. ui-sdk clears
12
- * a title's or a description's flag as the part unbinds, at once, and that re-applies the
13
- * dialog's props. Inside a teardown Svelte reads state as it was before the update, so the
14
- * props still said open, and the dialog was written open again: blank, its backdrop taking
15
- * every click on the page. Unbound a microtask later, ui-sdk reads the props as they are.
16
- * ui-sdk 0.1.0-beta.8 fixed it at its root (a part's unbind reads the options last delivered),
17
- * so this can go once Narvi moves past beta.7.
18
11
  */
19
12
  import { getContext, setContext, untrack } from 'svelte';
20
13
  const OPEN = Symbol('narvi.dialog-open');
@@ -48,29 +41,3 @@ export function keepWhileClosing(element) {
48
41
  }
49
42
  /** Puts the kept nodes in an element. */
50
43
  export const place = (nodes) => (element) => element.replaceChildren(...nodes);
51
- const later = new WeakMap();
52
- /**
53
- * A ui-sdk part's props, with its binding let go of after Svelte's teardown when its element has
54
- * left the page. Spread them on the part's element. An element that stays, binding again, lets
55
- * go at once, before it binds.
56
- */
57
- export function unbindLater(props) {
58
- const result = { ...props };
59
- for (const key of Object.getOwnPropertySymbols(props)) {
60
- const attach = props[key];
61
- if (typeof attach !== 'function')
62
- continue;
63
- let deferred = later.get(attach);
64
- if (!deferred) {
65
- deferred = (element) => {
66
- const release = attach(element);
67
- if (typeof release !== 'function')
68
- return release;
69
- return () => (element.isConnected ? release() : queueMicrotask(() => release()));
70
- };
71
- later.set(attach, deferred);
72
- }
73
- result[key] = deferred;
74
- }
75
- return result;
76
- }
@@ -24,3 +24,7 @@ export declare const tabStripTabMarker: Readonly<{
24
24
  export declare const appShellStripMarker: Readonly<{
25
25
  readonly marker: stylex.StyleXClassNameFor<"marker", symbol>;
26
26
  }>;
27
+ /** Placed around an Input with content at its end, so the field's edge stays firm while the pointer is on that content. */
28
+ export declare const inputMarker: Readonly<{
29
+ readonly marker: stylex.StyleXClassNameFor<"marker", symbol>;
30
+ }>;
@@ -14,3 +14,5 @@ export const sidebarItemMarker = stylex.defineMarker();
14
14
  export const tabStripTabMarker = stylex.defineMarker();
15
15
  /** Placed on AppShell.Strip, so the header that holds it takes a band's colour and no line. */
16
16
  export const appShellStripMarker = stylex.defineMarker();
17
+ /** Placed around an Input with content at its end, so the field's edge stays firm while the pointer is on that content. */
18
+ export const inputMarker = stylex.defineMarker();
@@ -1,11 +1,11 @@
1
1
  /**
2
2
  * Syntax highlighting for Narvi's Markdown, with Pierre's Highlights: a WebAssembly
3
- * highlighter with 152 languages that can tokenize code as it streams.
3
+ * highlighter with 190 languages that can tokenize code as it streams.
4
4
  *
5
5
  * import { highlight } from '@diegopluna/narvi/markdown/highlight';
6
6
  * <Markdown value={text} plugins={[highlight()]} />
7
7
  *
8
- * Importing this module loads the highlighter (about 150 KB gzipped), so import it where
8
+ * Importing this module loads the highlighter (about 190 KB gzipped), so import it where
9
9
  * Markdown with code is shown, or with a dynamic `import()` to keep it out of the first load.
10
10
  */
11
11
  import { type Theme } from '@pierre/highlights';
@@ -1,11 +1,11 @@
1
1
  /**
2
2
  * Syntax highlighting for Narvi's Markdown, with Pierre's Highlights: a WebAssembly
3
- * highlighter with 152 languages that can tokenize code as it streams.
3
+ * highlighter with 190 languages that can tokenize code as it streams.
4
4
  *
5
5
  * import { highlight } from '@diegopluna/narvi/markdown/highlight';
6
6
  * <Markdown value={text} plugins={[highlight()]} />
7
7
  *
8
- * Importing this module loads the highlighter (about 150 KB gzipped), so import it where
8
+ * Importing this module loads the highlighter (about 190 KB gzipped), so import it where
9
9
  * Markdown with code is shown, or with a dynamic `import()` to keep it out of the first load.
10
10
  */
11
11
  import { StreamTokenizer, codeToTokens, isSupportedLanguage } from '@pierre/highlights';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diegopluna/narvi",
3
- "version": "0.5.8",
3
+ "version": "0.5.9",
4
4
  "packageManager": "pnpm@12.18.0",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -112,13 +112,13 @@
112
112
  },
113
113
  "devDependencies": {
114
114
  "@codemirror/autocomplete": "^6.20.4",
115
- "@codemirror/commands": "^6.11.1",
115
+ "@codemirror/commands": "^6.11.2",
116
116
  "@codemirror/lang-css": "^6.3.1",
117
117
  "@codemirror/lang-html": "^6.4.12",
118
118
  "@codemirror/lang-javascript": "^6.2.5",
119
119
  "@codemirror/language": "^6.13.1",
120
120
  "@codemirror/state": "^6.7.6",
121
- "@codemirror/view": "^6.43.15",
121
+ "@codemirror/view": "^6.44.2",
122
122
  "@eslint/js": "^10.0.1",
123
123
  "@fontsource-variable/fraunces": "^5.3.0",
124
124
  "@fontsource-variable/geist": "^5.3.0",
@@ -130,24 +130,24 @@
130
130
  "@fontsource/ibm-plex-sans": "^5.3.0",
131
131
  "@fontsource/instrument-serif": "^5.3.0",
132
132
  "@humanspeak/svelte-markdown": "2.2.0",
133
- "@lezer/common": "^1.5.5",
133
+ "@lezer/common": "^1.5.7",
134
134
  "@lezer/highlight": "^1.2.5",
135
- "@lezer/javascript": "^1.5.6",
136
- "@lezer/lr": "^1.4.12",
135
+ "@lezer/javascript": "^1.5.7",
136
+ "@lezer/lr": "^1.4.13",
137
137
  "@replit/codemirror-lang-svelte": "^6.0.0",
138
138
  "@sveltejs/adapter-static": "^4.0.1",
139
- "@sveltejs/kit": "^3.4.0",
139
+ "@sveltejs/kit": "^3.4.1",
140
140
  "@sveltejs/package": "^2.5.8",
141
- "@sveltejs/vite-plugin-svelte": "^7.3.1",
141
+ "@sveltejs/vite-plugin-svelte": "^7.3.2",
142
142
  "@tanstack/intent": "0.5.6",
143
143
  "@types/markdown-it": "14.2.0",
144
- "@types/node": "^24.19.2",
144
+ "@types/node": "^24.19.4",
145
145
  "@types/react": "19.2.14",
146
146
  "@types/react-dom": "19.2.3",
147
147
  "@vitest/browser-playwright": "^4.1.12",
148
148
  "axe-core": "^4.14.1",
149
- "eslint": "^10.15.0",
150
- "eslint-config-prettier": "^10.1.8",
149
+ "eslint": "^10.16.0",
150
+ "eslint-config-prettier": "^10.1.9",
151
151
  "eslint-plugin-svelte": "^3.24.1",
152
152
  "globals": "^17.14.0",
153
153
  "markdown-it": "15.0.3",
@@ -166,30 +166,30 @@
166
166
  "remark-rehype": "11.1.2",
167
167
  "shiki": "^4.6.0",
168
168
  "streamdown": "2.7.1",
169
- "svelte": "^5.58.0",
169
+ "svelte": "^5.59.2",
170
170
  "svelte-check": "^4.7.8",
171
171
  "svelte-exmarkdown": "5.0.2",
172
172
  "svelte-streamdown": "5.0.0",
173
173
  "typescript": "^6.0.3",
174
- "typescript-eslint": "^8.73.0",
174
+ "typescript-eslint": "^8.74.0",
175
175
  "unified": "11.0.5",
176
- "vite": "^8.3.8",
176
+ "vite": "^8.4.0",
177
177
  "vitest": "^4.1.12",
178
178
  "vitest-browser-svelte": "^2.2.1",
179
- "wrangler": "^4.165.0"
179
+ "wrangler": "^4.169.1"
180
180
  },
181
181
  "peerDependencies": {
182
182
  "svelte": "^5.20.0",
183
183
  "vite": ">=6"
184
184
  },
185
185
  "dependencies": {
186
- "@pierre/highlights": "0.5.1",
186
+ "@pierre/highlights": "0.6.0",
187
187
  "@stylexjs/stylex": "0.19.2",
188
188
  "@stylexjs/unplugin": "0.19.2",
189
- "@ui-sdk/core": "0.1.0-beta.7",
190
- "@ui-sdk/svelte": "0.1.0-beta.7",
189
+ "@ui-sdk/core": "0.1.0-beta.23",
190
+ "@ui-sdk/svelte": "0.1.0-beta.23",
191
191
  "decode-named-character-reference": "1.3.0",
192
- "dompurify": "3.4.18",
192
+ "dompurify": "3.5.0",
193
193
  "esm-env": "^1.2.2",
194
194
  "katex": "0.19.1",
195
195
  "lightningcss": "^1.33.0",
@@ -12,7 +12,7 @@ metadata:
12
12
  Grid, and Narvi's conventions for colour, labels and copy.
13
13
  type: core
14
14
  library: '@diegopluna/narvi'
15
- library_version: '0.5.8'
15
+ library_version: '0.5.9'
16
16
  requires:
17
17
  - setup
18
18
  sources:
@@ -29,6 +29,7 @@ sources:
29
29
  - src/lib/components/dialog/ConfirmDialog.svelte
30
30
  - src/lib/components/notice/Notice.svelte
31
31
  - src/lib/components/field/Field.svelte
32
+ - src/lib/components/input/Input.svelte
32
33
  - src/lib/components/list/ListRoot.svelte
33
34
  - src/lib/components/table/*
34
35
  - src/lib/components/choice-cards/ChoiceCards.svelte
@@ -175,9 +176,8 @@ wires up `id`, `aria-describedby` and `aria-invalid`. Don't hand-write their `<l
175
176
  - `group` makes the Field a fieldset named by its legend, for several controls under one label
176
177
  (radios, a start and an end). The help and the error describe the group; its controls take
177
178
  no id from it.
178
- - `Input` takes an `icon` snippet at its start, sized to the field:
179
- `<Input>{#snippet icon()}<Search />{/snippet}</Input>`. Don't position an icon by hand. With
180
- an icon, `sx` styles the element around the field; `inputSx` and `inputClass` style the field.
179
+ - `Input` takes an `icon` snippet at its start, an `end` snippet for your controls inside its
180
+ end (a clear `Button size="xs" iconOnly variant="ghost"`), or `reveal` for a password's eye.
181
181
  - For one choice among a few that each need a line of detail, use `ChoiceCards`
182
182
  (`options: { value, label, detail?, icon?, disabled? }[]`, `bind:value`, `aria-label`).
183
183
 
@@ -480,7 +480,7 @@ Parts of a thread that are easy to redraw by hand, and shouldn't be:
480
480
  - **MEDIUM: a raw `<label>` beside an Input.** It misses Field's description and error wiring.
481
481
  - **HIGH: `Dialog.Content size="lg"` written for 44rem.** Since the sizes gained `lg` 36rem,
482
482
  `xl` 44 and `2xl` 56, the old `lg` is `xl`.
483
- - **MEDIUM: an Input's icon placed by hand.** Pass it as `icon`; the text starts after it.
483
+ - **MEDIUM: an icon, a clear button or an eye placed beside an Input.** Use `icon`, `end` or `reveal`.
484
484
  - **MEDIUM: a toast's `onDismiss` alone for "Undo, or else forget".** A toast that runs out of
485
485
  time calls `onAutoClose`, not `onDismiss`, so the forgetting never happens. Pass both.
486
486
  - **MEDIUM: a SettingsRow's `<label for>` on a group.** A `SegmentedControl` or a set of radios
@@ -66,27 +66,27 @@ Markdown's table styles: Markdown's tables and this one share their look.
66
66
 
67
67
  ## Controls and forms
68
68
 
69
- | Component | Use it for | Docs slug |
70
- | --------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------- |
71
- | `Button` | An action; `href` makes it a link; `variant` (12, from `primary` to `success-outline`), `size` (`micro` to `lg`), `shape`, `justify`, `loading`, `iconOnly`, `pressed`, `tooltip` | `button` |
72
- | `Field` | Label, help text and error around one control | `field` |
73
- | `Input` | One line of text | `input` |
74
- | `Textarea` | Several lines of text | `textarea` |
75
- | `Select` | One choice from a short list (`options: { value, label, icon?, detail?, detailMono?, group? }[]`, `align`, `optionIcon`) | `select` |
76
- | `Checkbox` | An option on or off, or several from a list | `checkbox` |
77
- | `ChoiceCards` | One choice among a few, each a card with a title and a line of detail | `choice-cards` |
78
- | `Switch` | A setting that takes effect at once | `switch` |
79
- | `SegmentedControl` | One of a few options, all visible (`options: { value, label, title? }[]`, `onchange`) | `segmented-control` |
80
- | `Slider` | A value or a range along a track | `slider` |
81
- | `ColorField` | A colour: a swatch that opens Narvi's picker, beside a hex field (`label`, `bind:value`, `onchange`, `size`, `labels`) | `color-field` |
82
- | `SplitButton` | A main action joined to a menu of how to do it (`menu`, `menuLabel`, `label`, `variant` incl. `ghost`, `shape`, `mainDisabled`, `mainSx`/`menuSx`, `menuMinWidth`) | `split-button` |
83
- | `Toggle` | A button that stays pressed (`tone`: `accent`, or `neutral` for toolbar icons) | `toggle` |
84
- | `ToggleGroup.Root`, `.Item` | Toggles that belong together: one pressed, or any number; toggle buttons (`aria-pressed`) either way, never radios | `toggle-group` |
85
- | `SettingsGroup` | A titled group of settings: a heading, an action, the rows on one card | `settings-group` |
86
- | `SettingsRow` | One setting: what it is, beside its control (`leading`, `dimmed`, `mono`) | `settings-row` |
87
- | `Tabs` | Views that share one place (`tabs: TabItem[]`, `label`, `bind:value`; `activation="manual"` for a slow panel) | `tabs` |
88
- | `SearchButton` | Looks like a search field and opens search (`label`, `shortcut`): for a window's bar | `search-button` |
89
- | `TabStrip` | Tabs for what is open in a pane: closable, addable, scrolling (`tabs`, `bind:value`, `onclose`, `onadd`); `menu`, `onmove`, `onrename`, `onkeep`, `trailing`, `variant`. The panels are yours | `tab-strip` |
69
+ | Component | Use it for | Docs slug |
70
+ | --------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------- |
71
+ | `Button` | An action; `href` makes it a link; `variant` (12, from `primary` to `success-outline`), `size` (`micro` to `lg`), `shape`, `justify`, `loading`, `iconOnly`, `pressed`, `tooltip` | `button` |
72
+ | `Field` | Label, help text and error around one control | `field` |
73
+ | `Input` | One line of text; an `icon` at its start, controls in an `end` snippet, or `reveal` for a password with an eye (`revealLabel`, "Show password"); with either, `inputSx` and `inputClass` style the field itself | `input` |
74
+ | `Textarea` | Several lines of text | `textarea` |
75
+ | `Select` | One choice from a short list (`options: { value, label, icon?, detail?, detailMono?, group? }[]`, `align`, `optionIcon`) | `select` |
76
+ | `Checkbox` | An option on or off, or several from a list | `checkbox` |
77
+ | `ChoiceCards` | One choice among a few, each a card with a title and a line of detail | `choice-cards` |
78
+ | `Switch` | A setting that takes effect at once | `switch` |
79
+ | `SegmentedControl` | One of a few options, all visible (`options: { value, label, title? }[]`, `onchange`) | `segmented-control` |
80
+ | `Slider` | A value or a range along a track | `slider` |
81
+ | `ColorField` | A colour: a swatch that opens Narvi's picker, beside a hex field (`label`, `bind:value`, `onchange`, `size`, `labels`) | `color-field` |
82
+ | `SplitButton` | A main action joined to a menu of how to do it (`menu`, `menuLabel`, `label`, `variant` incl. `ghost`, `shape`, `mainDisabled`, `mainSx`/`menuSx`, `menuMinWidth`) | `split-button` |
83
+ | `Toggle` | A button that stays pressed (`tone`: `accent`, or `neutral` for toolbar icons) | `toggle` |
84
+ | `ToggleGroup.Root`, `.Item` | Toggles that belong together: one pressed, or any number; toggle buttons (`aria-pressed`) either way, never radios | `toggle-group` |
85
+ | `SettingsGroup` | A titled group of settings: a heading, an action, the rows on one card | `settings-group` |
86
+ | `SettingsRow` | One setting: what it is, beside its control (`leading`, `dimmed`, `mono`) | `settings-row` |
87
+ | `Tabs` | Views that share one place (`tabs: TabItem[]`, `label`, `bind:value`; `activation="manual"` for a slow panel) | `tabs` |
88
+ | `SearchButton` | Looks like a search field and opens search (`label`, `shortcut`): for a window's bar | `search-button` |
89
+ | `TabStrip` | Tabs for what is open in a pane: closable, addable, scrolling (`tabs`, `bind:value`, `onclose`, `onadd`); `menu`, `onmove`, `onrename`, `onkeep`, `trailing`, `variant`. The panels are yours | `tab-strip` |
90
90
 
91
91
  ### Tab strips
92
92
 
@@ -176,11 +176,11 @@ browser; a `container` on a Root or a Content still wins, and the popups inside
176
176
  {@render children()}
177
177
  ```
178
178
 
179
- With a container outside the element the app is mounted on, as `document.body` is here, an Escape
180
- handler inside a popup that takes the key for itself (clearing a field, leaving an edit) calls
181
- `event.preventDefault()`. Stopping propagation alone lets the popup close: ui-sdk listens for
182
- Escape on `document` and skips only a key whose default is prevented, and Svelte runs a handler
183
- outside the mount target from `document` too, beside ui-sdk's listener.
179
+ An Escape handler inside a popup that takes the key for itself (clearing a field, leaving an
180
+ edit) calls `event.preventDefault()`, and the popup stays open. ui-sdk takes Escape in the popup
181
+ content's own keydown, after the handler, and skips a key whose default is prevented. Stopping
182
+ propagation works too, with the popup in a container on `document.body` as well, but
183
+ `preventDefault()` also tells other listeners the key was used.
184
184
 
185
185
  To drive `open` from the app, bind it, or pass it with an `onOpenChange` that keeps your state:
186
186
  `open={shown && !dragging} onOpenChange={(next) => (shown = next)}` follows `dragging` even after
@@ -12,7 +12,7 @@ metadata:
12
12
  patching the DOM, and decide which links and images text from a model may load.
13
13
  type: core
14
14
  library: '@diegopluna/narvi'
15
- library_version: '0.5.8'
15
+ library_version: '0.5.9'
16
16
  requires:
17
17
  - setup
18
18
  sources:
@@ -152,11 +152,11 @@ needs the component's state. Never write a new array in the markup:
152
152
  <Markdown value={text} streaming={!done} {plugins} />
153
153
  ```
154
154
 
155
- - **`highlight()`** colours code in 152 languages with `@pierre/highlights`. A block that
155
+ - **`highlight()`** colours code in 190 languages with `@pierre/highlights`. A block that
156
156
  streams is tokenized line by line as it arrives, never from the top again. Code takes Narvi's
157
157
  syntax colours by default. Pass `highlight({ themes: { light, dark } })` with Zed-compatible
158
158
  themes (for example from `@pierre/highlights/themes`) to use an editor theme. Importing the
159
- module loads about 150 KB (gzipped) of WebAssembly. To keep it out of the first load, import
159
+ module loads about 190 KB (gzipped) of WebAssembly. To keep it out of the first load, import
160
160
  it in the browser and add it to the plugins once, when it arrives (see below).
161
161
  - **`math()`** turns on formulas (`$x$`, `$$x$$`, `\(x\)`, `\[x\]` and a fenced `math` block)
162
162
  and typesets them with KaTeX, which loads on the first formula. Prices and shell variables
@@ -11,7 +11,7 @@ metadata:
11
11
  4 when the app uses it.
12
12
  type: lifecycle
13
13
  library: '@diegopluna/narvi'
14
- library_version: '0.5.8'
14
+ library_version: '0.5.9'
15
15
  sources:
16
16
  - src/lib/vite.ts
17
17
  - src/lib/base.css
@@ -12,7 +12,7 @@ metadata:
12
12
  hover, motion and forced-colour preferences.
13
13
  type: core
14
14
  library: '@diegopluna/narvi'
15
- library_version: '0.5.8'
15
+ library_version: '0.5.9'
16
16
  requires:
17
17
  - setup
18
18
  sources:
@@ -12,7 +12,7 @@ metadata:
12
12
  menus and dialogs, and resolve token colours for drawing code that cannot read CSS variables.
13
13
  type: core
14
14
  library: '@diegopluna/narvi'
15
- library_version: '0.5.8'
15
+ library_version: '0.5.9'
16
16
  requires:
17
17
  - setup
18
18
  sources: