@zonsh/ui 0.2.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (180) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +19 -13
  3. package/dist/components/alert-dialog.js +1 -1
  4. package/dist/components/ascii-field.d.ts +1 -1
  5. package/dist/components/bottom-nav.d.ts +86 -0
  6. package/dist/components/bottom-nav.js +175 -0
  7. package/dist/components/breadcrumb.d.ts +9 -0
  8. package/dist/components/breadcrumb.js +6 -1
  9. package/dist/components/button-group.d.ts +1 -1
  10. package/dist/components/button-group.js +2 -2
  11. package/dist/components/calendar.d.ts +1 -1
  12. package/dist/components/calendar.js +18 -3
  13. package/dist/components/carousel.d.ts +22 -3
  14. package/dist/components/carousel.js +25 -7
  15. package/dist/components/chart.d.ts +9 -0
  16. package/dist/components/chart.js +40 -3
  17. package/dist/components/code-block.d.ts +20 -10
  18. package/dist/components/code-block.js +54 -12
  19. package/dist/components/collapsible.js +2 -2
  20. package/dist/components/color-picker.d.ts +30 -8
  21. package/dist/components/color-picker.js +48 -27
  22. package/dist/components/combobox.d.ts +21 -3
  23. package/dist/components/combobox.js +79 -7
  24. package/dist/components/command.d.ts +23 -3
  25. package/dist/components/command.js +61 -16
  26. package/dist/components/conversation.d.ts +10 -1
  27. package/dist/components/conversation.js +14 -4
  28. package/dist/components/copy-button.d.ts +15 -6
  29. package/dist/components/copy-button.js +20 -5
  30. package/dist/components/data-table.d.ts +66 -6
  31. package/dist/components/data-table.js +376 -23
  32. package/dist/components/date-picker.d.ts +73 -4
  33. package/dist/components/date-picker.js +138 -7
  34. package/dist/components/dialog.d.ts +10 -1
  35. package/dist/components/dialog.js +6 -3
  36. package/dist/components/drawer.d.ts +10 -1
  37. package/dist/components/drawer.js +6 -3
  38. package/dist/components/feature-list.js +2 -2
  39. package/dist/components/field.d.ts +27 -8
  40. package/dist/components/field.js +49 -4
  41. package/dist/components/file-drop.d.ts +26 -4
  42. package/dist/components/file-drop.js +125 -64
  43. package/dist/components/filter-bar.d.ts +50 -3
  44. package/dist/components/filter-bar.js +71 -33
  45. package/dist/components/form.d.ts +4 -2
  46. package/dist/components/form.js +24 -2
  47. package/dist/components/graph.d.ts +41 -0
  48. package/dist/components/graph.js +84 -45
  49. package/dist/components/illustration.js +1 -1
  50. package/dist/components/input-group.d.ts +16 -5
  51. package/dist/components/input-group.js +35 -15
  52. package/dist/components/input.d.ts +2 -2
  53. package/dist/components/input.js +3 -3
  54. package/dist/components/kbd.d.ts +17 -0
  55. package/dist/components/kbd.js +8 -1
  56. package/dist/components/lightbox.d.ts +100 -0
  57. package/dist/components/lightbox.js +439 -0
  58. package/dist/components/locale.d.ts +44 -0
  59. package/dist/components/locale.js +37 -0
  60. package/dist/components/logo.js +1 -1
  61. package/dist/components/menu.js +3 -1
  62. package/dist/components/message.d.ts +3 -3
  63. package/dist/components/message.js +10 -7
  64. package/dist/components/meter.js +3 -1
  65. package/dist/components/money-input.d.ts +80 -0
  66. package/dist/components/money-input.js +253 -0
  67. package/dist/components/number-field.d.ts +21 -2
  68. package/dist/components/number-field.js +27 -16
  69. package/dist/components/otp-field.d.ts +14 -1
  70. package/dist/components/otp-field.js +10 -2
  71. package/dist/components/pagination.d.ts +13 -7
  72. package/dist/components/pagination.js +18 -7
  73. package/dist/components/pdf-viewer.d.ts +67 -2
  74. package/dist/components/pdf-viewer.js +88 -21
  75. package/dist/components/phone-input.d.ts +79 -0
  76. package/dist/components/phone-input.js +282 -0
  77. package/dist/components/popover.js +1 -1
  78. package/dist/components/progress.js +3 -1
  79. package/dist/components/prompt-input.d.ts +34 -9
  80. package/dist/components/prompt-input.js +28 -16
  81. package/dist/components/rating.d.ts +73 -0
  82. package/dist/components/rating.js +124 -0
  83. package/dist/components/reasoning.d.ts +16 -1
  84. package/dist/components/reasoning.js +10 -7
  85. package/dist/components/resizable.d.ts +10 -1
  86. package/dist/components/resizable.js +4 -1
  87. package/dist/components/response.d.ts +14 -3
  88. package/dist/components/response.js +36 -8
  89. package/dist/components/scroll-area.d.ts +1 -1
  90. package/dist/components/select.js +14 -3
  91. package/dist/components/separator.js +1 -1
  92. package/dist/components/sidebar.d.ts +20 -4
  93. package/dist/components/sidebar.js +34 -18
  94. package/dist/components/site-header.d.ts +46 -12
  95. package/dist/components/site-header.js +73 -19
  96. package/dist/components/slider.js +3 -1
  97. package/dist/components/sortable.d.ts +178 -0
  98. package/dist/components/sortable.js +1258 -0
  99. package/dist/components/sources.d.ts +17 -2
  100. package/dist/components/sources.js +11 -4
  101. package/dist/components/spinner.d.ts +13 -1
  102. package/dist/components/spinner.js +5 -2
  103. package/dist/components/stat.d.ts +91 -0
  104. package/dist/components/stat.js +141 -0
  105. package/dist/components/stepper.d.ts +71 -0
  106. package/dist/components/stepper.js +101 -0
  107. package/dist/components/switch.d.ts +2 -2
  108. package/dist/components/switch.js +2 -2
  109. package/dist/components/table.d.ts +12 -2
  110. package/dist/components/table.js +176 -39
  111. package/dist/components/tags-input.d.ts +18 -2
  112. package/dist/components/tags-input.js +65 -33
  113. package/dist/components/theme.d.ts +16 -2
  114. package/dist/components/theme.js +15 -7
  115. package/dist/components/time-field.d.ts +22 -3
  116. package/dist/components/time-field.js +19 -6
  117. package/dist/components/timeline.d.ts +18 -2
  118. package/dist/components/timeline.js +13 -4
  119. package/dist/components/tippy.d.ts +48 -0
  120. package/dist/components/tippy.js +648 -0
  121. package/dist/components/toast.d.ts +18 -2
  122. package/dist/components/toast.js +12 -3
  123. package/dist/components/tool-call.d.ts +19 -8
  124. package/dist/components/tool-call.js +18 -7
  125. package/dist/components/toolbar.js +6 -1
  126. package/dist/components/tour.d.ts +127 -0
  127. package/dist/components/tour.js +648 -0
  128. package/dist/components/tree.js +17 -4
  129. package/dist/components/video-player.d.ts +10 -2
  130. package/dist/components/video-player.js +73 -33
  131. package/dist/illustration.d.ts +2 -0
  132. package/dist/illustration.js +7 -0
  133. package/dist/index.d.ts +11 -3
  134. package/dist/index.js +11 -3
  135. package/dist/lib/code-highlight.d.ts +3 -16
  136. package/dist/lib/code-highlight.js +160 -10
  137. package/dist/lib/code-theme.js +3 -3
  138. package/dist/lib/digit-roll.js +8 -8
  139. package/dist/lib/field-errors.d.ts +28 -0
  140. package/dist/lib/field-errors.js +24 -0
  141. package/dist/lib/field-value.d.ts +13 -0
  142. package/dist/lib/field-value.js +44 -0
  143. package/dist/lib/graph-layout.js +11 -2
  144. package/dist/lib/money.d.ts +73 -0
  145. package/dist/lib/money.js +343 -0
  146. package/dist/lib/phone-countries.d.ts +1 -0
  147. package/dist/lib/phone-countries.js +281 -0
  148. package/dist/lib/phone.d.ts +90 -0
  149. package/dist/lib/phone.js +286 -0
  150. package/dist/lib/platform.d.ts +8 -3
  151. package/dist/lib/platform.js +13 -6
  152. package/dist/lib/row-index.d.ts +15 -0
  153. package/dist/lib/row-index.js +136 -0
  154. package/dist/lib/table-fit.js +23 -4
  155. package/dist/lib/theme-script.d.ts +15 -2
  156. package/dist/lib/theme-script.js +23 -3
  157. package/dist/lib/tippy/pixels.d.ts +47 -0
  158. package/dist/lib/tippy/pixels.js +187 -0
  159. package/dist/lib/tippy/sprite.d.ts +86 -0
  160. package/dist/lib/tippy/sprite.js +753 -0
  161. package/dist/messages/de.d.ts +12 -0
  162. package/dist/messages/de.js +326 -0
  163. package/dist/styles/expressive.css +20 -5
  164. package/dist/styles/index.css +3 -2
  165. package/dist/styles/material.css +7 -3
  166. package/dist/styles/parts/ai.css +2 -1
  167. package/dist/styles/parts/controls.css +62 -13
  168. package/dist/styles/parts/feedback.css +68 -1
  169. package/dist/styles/parts/foundations.css +1 -1
  170. package/dist/styles/parts/navigation.css +194 -2
  171. package/dist/styles/parts/overlays.css +7 -7
  172. package/dist/styles/tokens.css +12 -3
  173. package/dist/vite.d.ts +0 -50
  174. package/dist/vite.js +0 -100
  175. package/package.json +28 -33
  176. package/dist/components/code-highlight.d.ts +0 -13
  177. package/dist/components/code-highlight.js +0 -107
  178. package/dist/components/whiteboard.d.ts +0 -80
  179. package/dist/components/whiteboard.js +0 -389
  180. package/dist/styles/parts/whiteboard.css +0 -855
@@ -1,24 +1,174 @@
1
1
  import * as React from "react";
2
- export const CodeHighlighterContext = React.createContext(null);
2
+ import { zonCodeTheme } from "./code-theme.js";
3
+ /* One highlighter for the page, made the first time a block asks for colour: Shiki's core, its
4
+ JavaScript regex engine (no WebAssembly to fetch) and the grammars, each loaded only when a block
5
+ asks for its language. All of it is imported on demand, so a page without code never loads it,
6
+ and a build that has no CodeBlock leaves it out. */
7
+ let core;
8
+ const languages = new Map();
9
+ const getCore = () => (core ??= Promise.all([
10
+ import("shiki/core"),
11
+ import("shiki/engine/javascript"),
12
+ import("shiki/langs"),
13
+ ]).then(async ([{ createHighlighterCore }, { createJavaScriptRegexEngine }, { bundledLanguages }]) => ({
14
+ highlighter: await createHighlighterCore({
15
+ themes: [zonCodeTheme],
16
+ langs: [],
17
+ engine: createJavaScriptRegexEngine({ forgiving: true }),
18
+ }),
19
+ langs: bundledLanguages,
20
+ })));
21
+ let ready;
22
+ const loadedLanguages = new Set();
23
+ /** Longer lines stay mono, as in VS Code: a minified file or a data URL would take the page with it. */
24
+ const MAX_LINE = 5000;
25
+ /**
26
+ * The last few blocks coloured. Code that grows — a reply streaming in — keeps the lines it had:
27
+ * only the new ones, and the last (still being written), are tokenised again.
28
+ */
29
+ const recent = [];
30
+ /** `code`'s lines as tokens, and the state after them, going on from `state`. */
31
+ function tokenizeLines(highlighter, code, lang, state) {
32
+ const tokens = highlighter.codeToTokensBase(code, {
33
+ lang,
34
+ theme: "zon",
35
+ tokenizeMaxLineLength: MAX_LINE,
36
+ grammarState: state,
37
+ });
38
+ const lines = tokens.map((line) => line.map((token) => ({
39
+ content: token.content,
40
+ color: token.color,
41
+ fontStyle: token.fontStyle,
42
+ })));
43
+ return { lines, state: highlighter.getLastGrammarState(tokens) ?? state };
44
+ }
45
+ /** Resolves `true` once `language` can be tokenised, `false` if Shiki does not know it. */
46
+ function loadLanguage(language) {
47
+ const lang = language.toLowerCase();
48
+ let loading = languages.get(lang);
49
+ if (!loading) {
50
+ loading = getCore()
51
+ .then(async ({ highlighter, langs }) => {
52
+ // Its own keys only: a fence named `constructor` or `__proto__` is no grammar.
53
+ const grammar = Object.hasOwn(langs, lang) ? langs[lang] : undefined;
54
+ if (!grammar)
55
+ return false;
56
+ await highlighter.loadLanguage(grammar);
57
+ ready = highlighter;
58
+ loadedLanguages.add(lang);
59
+ return true;
60
+ })
61
+ .catch(() => false);
62
+ languages.set(lang, loading);
63
+ }
64
+ return loading;
65
+ }
66
+ /**
67
+ * The code as lines of tokens, or `null` while `language` is not loaded. Synchronous, so a block
68
+ * that changes on every frame (a streaming reply) colours as it renders.
69
+ */
70
+ function tokenize(code, language) {
71
+ const lang = language.toLowerCase();
72
+ if (!ready || !loadedLanguages.has(lang))
73
+ return null;
74
+ try {
75
+ const cut = code.lastIndexOf("\n");
76
+ const head = cut === -1 ? "" : code.slice(0, cut);
77
+ const at = recent.findIndex((r) => r.lang === lang && (head === r.head || head.startsWith(`${r.head}\n`)));
78
+ let lines = [];
79
+ let state;
80
+ if (at !== -1) {
81
+ const [hit] = recent.splice(at, 1);
82
+ ({ lines, state } = hit);
83
+ if (head !== hit.head) {
84
+ const more = tokenizeLines(ready, head.slice(hit.head.length + 1), lang, state);
85
+ lines = [...lines, ...more.lines];
86
+ state = more.state;
87
+ }
88
+ }
89
+ else if (cut !== -1) {
90
+ ({ lines, state } = tokenizeLines(ready, head, lang, undefined));
91
+ }
92
+ if (cut !== -1) {
93
+ recent.unshift({ lang, head, lines, state });
94
+ recent.length = Math.min(recent.length, 8);
95
+ }
96
+ return [...lines, ...tokenizeLines(ready, code.slice(cut + 1), lang, state).lines];
97
+ }
98
+ catch {
99
+ // A grammar that cannot take this code: it stays mono rather than taking the page down.
100
+ return null;
101
+ }
102
+ }
3
103
  /**
4
104
  * The tokens for `code` once its language has loaded, and `null` until then (or when there is no
5
- * highlighter, no language, or `enabled` is false), so the block shows plain mono meanwhile.
6
- * `pending` is true while colours are on their way, false once they are in or never will be.
105
+ * language, Shiki does not know it, or `enabled` is false), so the block shows plain mono meanwhile
106
+ * and on the server. `pending` is true while colours are on their way, false once they are in or
107
+ * never will be.
7
108
  */
8
109
  export function useCodeTokens(code, language, enabled) {
9
- const highlighter = React.useContext(CodeHighlighterContext);
10
110
  const [loaded, setLoaded] = React.useState(null);
11
111
  const [failed, setFailed] = React.useState(null);
12
112
  React.useEffect(() => {
13
- if (!enabled || !highlighter || !language)
113
+ if (!enabled || !language)
14
114
  return;
15
115
  let live = true;
16
- highlighter.load(language).then((ok) => live && (ok ? setLoaded(language) : setFailed(language)), () => live && setFailed(language));
116
+ loadLanguage(language).then((ok) => live && (ok ? setLoaded(language) : setFailed(language)));
17
117
  return () => {
18
118
  live = false;
19
119
  };
20
- }, [enabled, highlighter, language]);
21
- const tokens = React.useMemo(() => (enabled && highlighter && language && loaded === language ? highlighter.tokenize(code, language) : null), [enabled, loaded, language, highlighter, code]);
22
- const pending = enabled && highlighter != null && !!language && loaded !== language && failed !== language;
23
- return { tokens, pending };
120
+ }, [enabled, language]);
121
+ // Long code is coloured a slice at a time between frames, from the top: it shows plain at once
122
+ // and takes its colours as they come, instead of holding up the page for seconds.
123
+ const long = React.useMemo(() => countLines(code) > SLICED_FROM, [code]);
124
+ const tokens = React.useMemo(() => (enabled && language && loaded === language && !long ? tokenize(code, language) : null), [enabled, loaded, language, code, long]);
125
+ const [sliced, setSliced] = React.useState(null);
126
+ React.useEffect(() => {
127
+ if (!long || !enabled || !language || loaded !== language || !ready)
128
+ return;
129
+ const highlighter = ready;
130
+ const lang = language.toLowerCase();
131
+ const all = code.split("\n");
132
+ const lines = [];
133
+ let state;
134
+ let shown = 0;
135
+ let timer;
136
+ const step = () => {
137
+ const start = performance.now();
138
+ try {
139
+ while (lines.length < all.length && performance.now() - start < SLICE_MS) {
140
+ const more = tokenizeLines(highlighter, all.slice(lines.length, lines.length + 40).join("\n"), lang, state);
141
+ lines.push(...more.lines);
142
+ state = more.state;
143
+ }
144
+ }
145
+ catch {
146
+ return; // a grammar that cannot take this code: the rest stays mono
147
+ }
148
+ const done = lines.length >= all.length;
149
+ // Drawn every few hundred lines, not at every slice: each draw goes over the whole block.
150
+ if (done || lines.length - shown >= 400) {
151
+ shown = lines.length;
152
+ setSliced({ code, lines: lines.slice(), done });
153
+ }
154
+ if (!done)
155
+ timer = setTimeout(step, 0);
156
+ };
157
+ timer = setTimeout(step, 0);
158
+ return () => clearTimeout(timer);
159
+ }, [long, enabled, language, loaded, code]);
160
+ const pending = enabled &&
161
+ !!language &&
162
+ failed !== language &&
163
+ (loaded !== language || (long && !(sliced?.code === code && sliced.done)));
164
+ return { tokens: long ? (sliced?.code === code ? sliced.lines : null) : tokens, pending };
165
+ }
166
+ /** Code longer than this many lines is coloured in slices of about SLICE_MS. */
167
+ const SLICED_FROM = 400;
168
+ const SLICE_MS = 10;
169
+ function countLines(code) {
170
+ let n = 1;
171
+ for (let i = code.indexOf("\n"); i !== -1 && n <= SLICED_FROM; i = code.indexOf("\n", i + 1))
172
+ n++;
173
+ return n;
24
174
  }
@@ -4,9 +4,9 @@
4
4
  * one kind of token — keywords violet, strings lime, numbers and constants orange, functions
5
5
  * blue, types aqua, tags magenta — and added and removed lines take the status colours.
6
6
  *
7
- * Plain data in a plain module, so the package index can name it for server components (the
8
- * CodeHighlightProvider module, which exports it too, is a client module). Its type is spelled
9
- * out rather than taken from Shiki, so the index needs no Shiki.
7
+ * Plain data in a plain module, so the package index can name it for server components (a client
8
+ * module's exports reach the server only as references). Its type is spelled out rather than
9
+ * taken from Shiki, so the index imports no Shiki.
10
10
  */
11
11
  const v = (name) => `var(--code-${name})`;
12
12
  /**
@@ -18,14 +18,14 @@ export function DigitRoll({ roll, slot, className, onDone, }) {
18
18
  return () => clearTimeout(t);
19
19
  }, [onDone]);
20
20
  return (_jsx("span", { "aria-hidden": true, "data-slot": slot,
21
- // One flex item per character: in a right-to-left page they would line up backwards.
22
- dir: "ltr", className: cn("pointer-events-none absolute inset-0 flex items-center justify-center overflow-hidden font-mono whitespace-pre text-foreground tabular-nums", className), style: { "--roll-dir": roll.dir }, onAnimationEnd: (e) => {
21
+ // Laid out in the page's direction, so `justify-start` and `ps-*` put the value at its start.
22
+ className: cn("pointer-events-none absolute inset-0 flex items-center justify-center overflow-hidden font-mono whitespace-pre text-foreground tabular-nums", className), style: { "--roll-dir": roll.dir }, onAnimationEnd: (e) => {
23
23
  if (e.target.hasAttribute("data-new"))
24
24
  onDone();
25
- }, children: [...to].map((next, i) => {
26
- const prev = from[i];
27
- if (prev === next)
28
- return _jsx("span", { children: next }, i);
29
- return (_jsxs("span", { "data-roll": "", "data-grow": prev === " " ? "" : undefined, "data-shrink": next === " " ? "" : undefined, children: [_jsx("span", { "data-old": "", children: prev }), _jsx("span", { "data-new": "", children: next })] }, i));
30
- }) }));
25
+ }, children: _jsx("span", { dir: "ltr", className: "flex items-center", children: [...to].map((next, i) => {
26
+ const prev = from[i];
27
+ if (prev === next)
28
+ return _jsx("span", { children: next }, i);
29
+ return (_jsxs("span", { "data-roll": "", "data-grow": prev === " " ? "" : undefined, "data-shrink": next === " " ? "" : undefined, children: [_jsx("span", { "data-old": "", children: prev }), _jsx("span", { "data-new": "", children: next })] }, i));
30
+ }) }) }));
31
31
  }
@@ -0,0 +1,28 @@
1
+ import * as React from "react";
2
+ /**
3
+ * One error as a form library hands it over: a message, or an object with a `message` (React Hook
4
+ * Form's `fieldState.error`, a Standard Schema issue in TanStack Form's `field.state.meta.errors`).
5
+ * Nothing, `null`, `false` or an empty message means no error.
6
+ */
7
+ export type FieldErrorLike = string | {
8
+ message?: string | undefined;
9
+ } | null | undefined | false;
10
+ /** The distinct messages in `error`: one error, or a list of them. */
11
+ export declare function errorMessages(error: FieldErrorLike | readonly FieldErrorLike[]): string[];
12
+ interface FieldErrorsContextValue {
13
+ /** The messages of the `error` passed to the Field. */
14
+ messages: readonly string[];
15
+ /** The problems a `FieldError match="…"` in the Field has its own words for. */
16
+ covered: readonly string[];
17
+ /** Called by such a `FieldError`; returns the cleanup. */
18
+ cover: (problem: string) => () => void;
19
+ }
20
+ /** What the nearest `Field` tells its `FieldError`s. */
21
+ export declare const FieldErrorsContext: React.Context<FieldErrorsContextValue>;
22
+ /**
23
+ * The fields of a `Form` that show an error passed in by a library (`Field error`), by id. While
24
+ * there are any, the Form hands a submit to its `onSubmit` itself, so the library validates again
25
+ * rather than the Form stopping the submit at the first field the library marked.
26
+ */
27
+ export declare const LibraryErrorsContext: React.Context<Set<string> | null>;
28
+ export {};
@@ -0,0 +1,24 @@
1
+ import * as React from "react";
2
+ /** The distinct messages in `error`: one error, or a list of them. */
3
+ export function errorMessages(error) {
4
+ const list = Array.isArray(error) ? error : [error];
5
+ const messages = [];
6
+ for (const item of list) {
7
+ const message = typeof item === "string" ? item : item ? item.message : undefined;
8
+ if (message && !messages.includes(message))
9
+ messages.push(message);
10
+ }
11
+ return messages;
12
+ }
13
+ /** What the nearest `Field` tells its `FieldError`s. */
14
+ export const FieldErrorsContext = React.createContext({
15
+ messages: [],
16
+ covered: [],
17
+ cover: () => () => { },
18
+ });
19
+ /**
20
+ * The fields of a `Form` that show an error passed in by a library (`Field error`), by id. While
21
+ * there are any, the Form hands a submit to its `onSubmit` itself, so the library validates again
22
+ * rather than the Form stopping the submit at the first field the library marked.
23
+ */
24
+ export const LibraryErrorsContext = React.createContext(null);
@@ -0,0 +1,13 @@
1
+ import * as React from "react";
2
+ export declare function FieldValueInput({ message, valueRef, ref, ...props }: React.ComponentProps<"input"> & {
3
+ message: string;
4
+ /** The component's own handle on this input. */
5
+ valueRef: React.RefObject<HTMLInputElement | null>;
6
+ }): React.JSX.Element;
7
+ /**
8
+ * The locale to format in: the given one, else the browser's — except on the server and while
9
+ * hydrating, which can't know the browser's and use en-US, so the first render matches the HTML.
10
+ */
11
+ export declare function useFormatLocale(locale: string | undefined): string | undefined;
12
+ /** Calls `onReset` when the form around `node` resets — Base UI keeps no default of its own. */
13
+ export declare function useFormResetEffect(node: React.RefObject<HTMLElement | null>, onReset: () => void): void;
@@ -0,0 +1,44 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import * as React from "react";
3
+ import { mergeRefs } from "./merge-refs.js";
4
+ /*
5
+ * The Field's own input for a control whose visible text is not its value — MoneyInput shows
6
+ * "1,234.50" and submits "1234.50", PhoneInput shows "20 7946 0018" beside +44 and submits
7
+ * "+442079460018". Out of sight and out of the tab order, it holds the value for forms, carries
8
+ * `required`, and holds the control's own validity message, which a Field reads as it reads a
9
+ * native one: it marks the Field invalid and is what FieldError shows.
10
+ *
11
+ * The message is set in a layout effect, which runs before the Field's own (this input renders
12
+ * inside Field.Control): when the value changes, the Field already sees the new message.
13
+ */
14
+ export function FieldValueInput({ message, valueRef, ref, ...props }) {
15
+ const refs = React.useMemo(() => mergeRefs(valueRef, ref), [valueRef, ref]);
16
+ React.useLayoutEffect(() => {
17
+ valueRef.current?.setCustomValidity(message);
18
+ }, [message, valueRef]);
19
+ return (_jsx("input", { ...props,
20
+ // What was typed isn't a value yet: that is the message, not a missing value as well.
21
+ required: props.required && !message, ref: refs, "aria-hidden": true, tabIndex: -1, autoComplete: "off", className: "sr-only" }));
22
+ }
23
+ const noSubscribe = () => () => { };
24
+ /**
25
+ * The locale to format in: the given one, else the browser's — except on the server and while
26
+ * hydrating, which can't know the browser's and use en-US, so the first render matches the HTML.
27
+ */
28
+ export function useFormatLocale(locale) {
29
+ const hydrated = React.useSyncExternalStore(noSubscribe, () => true, () => false);
30
+ return locale ?? (hydrated ? undefined : "en-US");
31
+ }
32
+ /** Calls `onReset` when the form around `node` resets — Base UI keeps no default of its own. */
33
+ export function useFormResetEffect(node, onReset) {
34
+ const latest = React.useRef(onReset);
35
+ latest.current = onReset;
36
+ React.useEffect(() => {
37
+ const form = node.current?.closest("form");
38
+ if (!form)
39
+ return;
40
+ const reset = () => latest.current();
41
+ form.addEventListener("reset", reset);
42
+ return () => form.removeEventListener("reset", reset);
43
+ }, [node]);
44
+ }
@@ -82,7 +82,11 @@ export function networkSimulation(nodes, edges) {
82
82
  return s.r + t.r + 56 + 8 * Math.min(6, Math.max(degree.get(s.id) ?? 0, degree.get(t.id) ?? 0));
83
83
  })
84
84
  .strength(0.45))
85
- .force("charge", forceManyBody().strength(-1300).distanceMax(1400))
85
+ // A large network pushes apart in coarser cells (Barnes–Hut theta): seconds sooner, about as settled.
86
+ .force("charge", forceManyBody()
87
+ .strength(-1300)
88
+ .distanceMax(1400)
89
+ .theta(nodes.length > 500 ? 1.2 : 0.9))
86
90
  .force("collide", forceCollide((d) => d.r + 10).strength(0.95))
87
91
  .force("x", forceX(0).strength(0.03))
88
92
  .force("y", forceY(0).strength(0.05))
@@ -127,7 +131,12 @@ export function dragSimulation(nodes, edges, held) {
127
131
  /** Force layout, run to rest before the first paint. */
128
132
  export function network(nodes, edges) {
129
133
  const { simulation, sim } = networkSimulation(nodes, edges);
130
- const ticks = Math.ceil(Math.log(simulation.alphaMin()) / Math.log(1 - simulation.alphaDecay()));
134
+ // Each tick costs about the number of nodes: past a hundred and fifty, fewer and larger steps
135
+ // (down to a quarter as many) keep a big network from holding up the page for a minute.
136
+ const full = Math.ceil(Math.log(simulation.alphaMin()) / Math.log(1 - simulation.alphaDecay()));
137
+ const ticks = Math.max(Math.round(full / 4), Math.min(full, Math.round((full * 150) / Math.max(1, nodes.length))));
138
+ if (ticks < full)
139
+ simulation.alphaDecay(1 - Math.pow(simulation.alphaMin(), 1 / ticks));
131
140
  simulation.tick(ticks);
132
141
  const sizes = new Map(nodes.map((n) => [n.id, n]));
133
142
  const placed = new Map();
@@ -0,0 +1,73 @@
1
+ export type AmountParse = {
2
+ kind: "empty";
3
+ }
4
+ /** Not an amount: letters inside it, two decimal separators, groups in the wrong places. */
5
+ | {
6
+ kind: "invalid";
7
+ }
8
+ /**
9
+ * More fraction digits than the currency has. `definite` is false while the last separator
10
+ * could still turn out to be a thousands separator once more digits are typed ("1,5" → "1,500").
11
+ */
12
+ | {
13
+ kind: "precision";
14
+ definite: boolean;
15
+ value: string;
16
+ }
17
+ /** `value` is canonical: an optional "-", the integer, and exactly the currency's fraction digits. */
18
+ | {
19
+ kind: "ok";
20
+ value: string;
21
+ };
22
+ /** Any decimal digit, of any script, as 0–9; other characters unchanged. */
23
+ export declare function latinDigits(text: string): string;
24
+ /** The locale's decimal and grouping separators, as Intl writes them. */
25
+ export declare function localeSeparators(locale?: string): {
26
+ decimal: string;
27
+ group: string;
28
+ };
29
+ /** The number of fraction digits a currency has in ISO 4217, as Intl knows it: JPY 0, EUR 2, KWD 3. */
30
+ export declare function currencyFractionDigits(currency: string): number;
31
+ /**
32
+ * Reads an amount written by a person, for a currency with `fractionDigits` fraction digits.
33
+ * `locale` decides what a lone "." or "," means; both conventions are read either way.
34
+ */
35
+ export declare function parseAmount(text: string, { locale, fractionDigits }: {
36
+ locale?: string;
37
+ fractionDigits: number;
38
+ }): AmountParse;
39
+ /**
40
+ * A canonical amount for a currency from any exact decimal string or a number: "12.5" → "12.50".
41
+ * Returns null for anything that isn't a plain decimal, or that has more fraction digits than the
42
+ * currency (a number like 0.1 + 0.2 is refused, not rounded).
43
+ */
44
+ export declare function normalizeAmount(value: string | number | null | undefined, fractionDigits: number): string | null;
45
+ /** Compares two canonical amounts with the same fraction digits: −1, 0 or 1. */
46
+ export declare function compareAmounts(a: string, b: string): number;
47
+ /** A canonical amount as an integer of minor units (cents): "12.34" → 1234n. */
48
+ export declare function amountToMinor(value: string, fractionDigits: number): bigint;
49
+ /** An integer of minor units as a canonical amount: 1234n → "12.34". */
50
+ export declare function amountFromMinor(minor: bigint | number | string, fractionDigits: number): string;
51
+ /**
52
+ * A canonical amount as the locale writes it: "1234.5" → "1,234.50" (en-US), "1.234,50" (de-DE),
53
+ * "1 234,50" (fr-FR), "١٬٢٣٤٫٥٠" (ar-EG). `grouping: false` leaves out the thousands separators,
54
+ * for editing. `currency` adds the symbol or code where the locale puts it.
55
+ */
56
+ export declare function formatAmount(value: string, { locale, fractionDigits, grouping, currency, currencyDisplay, }: {
57
+ locale?: string;
58
+ fractionDigits: number;
59
+ grouping?: boolean;
60
+ currency?: string;
61
+ currencyDisplay?: "symbol" | "narrowSymbol" | "code";
62
+ }): string;
63
+ /** The currency's symbol (or code) in the locale, and whether the locale writes it before the number. */
64
+ export declare function currencyAffix(currency: string, locale?: string, currencyDisplay?: "symbol" | "narrowSymbol" | "code"): {
65
+ symbol: string;
66
+ before: boolean;
67
+ };
68
+ /**
69
+ * Text pasted into an amount field, cleaned of the currency around the number: a symbol or code
70
+ * before or after it ("€", "EUR", "CHF", "kr.", "R$"). Returns null when letters or a currency
71
+ * sign sit inside the number itself ("12abc34").
72
+ */
73
+ export declare function stripCurrency(text: string): string | null;