@zonsh/ui 0.2.0 → 0.5.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.
- package/LICENSE +22 -0
- package/README.md +19 -13
- package/dist/components/accordion.js +1 -1
- package/dist/components/alert-dialog.js +1 -1
- package/dist/components/ascii-field.d.ts +1 -1
- package/dist/components/ascii-field.js +2 -1
- package/dist/components/bottom-nav.d.ts +86 -0
- package/dist/components/bottom-nav.js +175 -0
- package/dist/components/breadcrumb.d.ts +9 -0
- package/dist/components/breadcrumb.js +6 -1
- package/dist/components/button-group.d.ts +1 -1
- package/dist/components/button-group.js +2 -2
- package/dist/components/button.js +1 -1
- package/dist/components/calendar.d.ts +1 -1
- package/dist/components/calendar.js +18 -3
- package/dist/components/carousel.d.ts +22 -3
- package/dist/components/carousel.js +25 -7
- package/dist/components/chart.d.ts +20 -0
- package/dist/components/chart.js +52 -3
- package/dist/components/code-block.d.ts +20 -10
- package/dist/components/code-block.js +54 -12
- package/dist/components/collapsible.js +3 -3
- package/dist/components/color-picker.d.ts +30 -8
- package/dist/components/color-picker.js +48 -27
- package/dist/components/combobox.d.ts +21 -3
- package/dist/components/combobox.js +79 -7
- package/dist/components/command.d.ts +23 -3
- package/dist/components/command.js +63 -18
- package/dist/components/conversation.d.ts +10 -1
- package/dist/components/conversation.js +24 -7
- package/dist/components/copy-button.d.ts +15 -6
- package/dist/components/copy-button.js +27 -10
- package/dist/components/data-table.d.ts +66 -6
- package/dist/components/data-table.js +376 -23
- package/dist/components/date-picker.d.ts +73 -4
- package/dist/components/date-picker.js +138 -7
- package/dist/components/dialog.d.ts +10 -1
- package/dist/components/dialog.js +6 -3
- package/dist/components/drawer.d.ts +10 -1
- package/dist/components/drawer.js +6 -3
- package/dist/components/feature-list.js +2 -2
- package/dist/components/field.d.ts +27 -8
- package/dist/components/field.js +49 -4
- package/dist/components/file-drop.d.ts +26 -4
- package/dist/components/file-drop.js +125 -64
- package/dist/components/filter-bar.d.ts +50 -3
- package/dist/components/filter-bar.js +71 -33
- package/dist/components/form.d.ts +4 -2
- package/dist/components/form.js +24 -2
- package/dist/components/graph.d.ts +41 -0
- package/dist/components/graph.js +106 -50
- package/dist/components/illustration.js +51 -4
- package/dist/components/input-group.d.ts +18 -7
- package/dist/components/input-group.js +41 -19
- package/dist/components/input.d.ts +2 -2
- package/dist/components/input.js +3 -3
- package/dist/components/kbd.d.ts +17 -0
- package/dist/components/kbd.js +8 -1
- package/dist/components/layout.d.ts +2 -1
- package/dist/components/layout.js +55 -11
- package/dist/components/lightbox.d.ts +100 -0
- package/dist/components/lightbox.js +457 -0
- package/dist/components/locale.d.ts +44 -0
- package/dist/components/locale.js +37 -0
- package/dist/components/logo.js +1 -1
- package/dist/components/menu.js +3 -1
- package/dist/components/menubar.js +60 -13
- package/dist/components/message.d.ts +3 -3
- package/dist/components/message.js +12 -8
- package/dist/components/meter.js +3 -1
- package/dist/components/money-input.d.ts +80 -0
- package/dist/components/money-input.js +253 -0
- package/dist/components/navigation-menu.js +4 -2
- package/dist/components/number-field.d.ts +21 -2
- package/dist/components/number-field.js +53 -28
- package/dist/components/otp-field.d.ts +14 -1
- package/dist/components/otp-field.js +10 -2
- package/dist/components/pagination.d.ts +13 -7
- package/dist/components/pagination.js +18 -7
- package/dist/components/pdf-viewer.d.ts +67 -2
- package/dist/components/pdf-viewer.js +88 -21
- package/dist/components/phone-input.d.ts +79 -0
- package/dist/components/phone-input.js +282 -0
- package/dist/components/popover.js +1 -1
- package/dist/components/progress.js +3 -1
- package/dist/components/prompt-input.d.ts +34 -9
- package/dist/components/prompt-input.js +37 -17
- package/dist/components/radio-group.js +7 -2
- package/dist/components/rating.d.ts +73 -0
- package/dist/components/rating.js +124 -0
- package/dist/components/reasoning.d.ts +16 -1
- package/dist/components/reasoning.js +10 -7
- package/dist/components/resizable.d.ts +10 -1
- package/dist/components/resizable.js +4 -1
- package/dist/components/response.d.ts +17 -5
- package/dist/components/response.js +58 -18
- package/dist/components/scroll-area.d.ts +1 -1
- package/dist/components/select.js +14 -3
- package/dist/components/separator.js +1 -1
- package/dist/components/sidebar.d.ts +20 -4
- package/dist/components/sidebar.js +70 -35
- package/dist/components/site-header.d.ts +46 -12
- package/dist/components/site-header.js +78 -19
- package/dist/components/skeleton.d.ts +1 -1
- package/dist/components/skeleton.js +1 -1
- package/dist/components/slider.js +3 -1
- package/dist/components/sortable.d.ts +178 -0
- package/dist/components/sortable.js +1282 -0
- package/dist/components/sources.d.ts +17 -2
- package/dist/components/sources.js +11 -4
- package/dist/components/spinner.d.ts +13 -1
- package/dist/components/spinner.js +5 -2
- package/dist/components/stat.d.ts +91 -0
- package/dist/components/stat.js +141 -0
- package/dist/components/stepper.d.ts +71 -0
- package/dist/components/stepper.js +101 -0
- package/dist/components/switch.d.ts +2 -2
- package/dist/components/switch.js +2 -2
- package/dist/components/table.d.ts +13 -3
- package/dist/components/table.js +231 -41
- package/dist/components/tabs.js +8 -4
- package/dist/components/tags-input.d.ts +18 -2
- package/dist/components/tags-input.js +66 -34
- package/dist/components/theme.d.ts +16 -2
- package/dist/components/theme.js +34 -8
- package/dist/components/time-field.d.ts +24 -4
- package/dist/components/time-field.js +32 -9
- package/dist/components/timeline.d.ts +18 -2
- package/dist/components/timeline.js +13 -4
- package/dist/components/tippy.d.ts +48 -0
- package/dist/components/tippy.js +648 -0
- package/dist/components/toast.d.ts +18 -2
- package/dist/components/toast.js +12 -3
- package/dist/components/toggle-group.js +1 -0
- package/dist/components/tool-call.d.ts +19 -8
- package/dist/components/tool-call.js +23 -7
- package/dist/components/toolbar.d.ts +1 -1
- package/dist/components/toolbar.js +10 -2
- package/dist/components/tooltip.d.ts +4 -2
- package/dist/components/tooltip.js +10 -4
- package/dist/components/tour.d.ts +127 -0
- package/dist/components/tour.js +673 -0
- package/dist/components/tree.js +45 -9
- package/dist/components/video-player.d.ts +10 -2
- package/dist/components/video-player.js +134 -38
- package/dist/illustration.d.ts +2 -0
- package/dist/illustration.js +7 -0
- package/dist/index.d.ts +11 -3
- package/dist/index.js +11 -3
- package/dist/lib/code-highlight.d.ts +3 -16
- package/dist/lib/code-highlight.js +160 -10
- package/dist/lib/code-theme.js +3 -3
- package/dist/lib/digit-roll.js +8 -8
- package/dist/lib/field-errors.d.ts +28 -0
- package/dist/lib/field-errors.js +24 -0
- package/dist/lib/field-value.d.ts +13 -0
- package/dist/lib/field-value.js +44 -0
- package/dist/lib/glide.d.ts +5 -4
- package/dist/lib/glide.js +5 -4
- package/dist/lib/graph-layout.js +11 -2
- package/dist/lib/money.d.ts +73 -0
- package/dist/lib/money.js +343 -0
- package/dist/lib/phone-countries.d.ts +1 -0
- package/dist/lib/phone-countries.js +281 -0
- package/dist/lib/phone.d.ts +90 -0
- package/dist/lib/phone.js +286 -0
- package/dist/lib/platform.d.ts +8 -3
- package/dist/lib/platform.js +13 -6
- package/dist/lib/row-index.d.ts +15 -0
- package/dist/lib/row-index.js +136 -0
- package/dist/lib/table-fit.d.ts +3 -2
- package/dist/lib/table-fit.js +52 -23
- package/dist/lib/theme-script.d.ts +15 -2
- package/dist/lib/theme-script.js +23 -3
- package/dist/lib/tippy/pixels.d.ts +47 -0
- package/dist/lib/tippy/pixels.js +187 -0
- package/dist/lib/tippy/sprite.d.ts +86 -0
- package/dist/lib/tippy/sprite.js +753 -0
- package/dist/messages/de.d.ts +12 -0
- package/dist/messages/de.js +326 -0
- package/dist/styles/expressive.css +60 -26
- package/dist/styles/index.css +11 -2
- package/dist/styles/material.css +47 -23
- package/dist/styles/parts/ai.css +4 -2
- package/dist/styles/parts/controls.css +85 -32
- package/dist/styles/parts/data.css +33 -5
- package/dist/styles/parts/feedback.css +110 -13
- package/dist/styles/parts/foundations.css +1 -1
- package/dist/styles/parts/navigation.css +230 -5
- package/dist/styles/parts/overlays.css +98 -11
- package/dist/styles/parts/pdf.css +13 -7
- package/dist/styles/tokens.css +28 -4
- package/dist/vite.d.ts +0 -50
- package/dist/vite.js +0 -100
- package/package.json +28 -33
- package/dist/components/code-highlight.d.ts +0 -13
- package/dist/components/code-highlight.js +0 -107
- package/dist/components/whiteboard.d.ts +0 -80
- package/dist/components/whiteboard.js +0 -389
- package/dist/styles/parts/whiteboard.css +0 -855
package/dist/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// Generated by scripts/gen-index.mjs — do not edit by hand.
|
|
2
2
|
export * from "./lib/cn.js";
|
|
3
|
-
export { createThemeScript, themeScript, THEME_STORAGE_KEY } from "./lib/theme-script.js";
|
|
4
|
-
export { illustrationKinds, illustrations } from "./lib/illustration-info.js";
|
|
3
|
+
export { createThemeScript, themeScript, PAGE_TONE, THEME_STORAGE_KEY } from "./lib/theme-script.js";
|
|
5
4
|
export { zonCodeTheme } from "./lib/code-theme.js";
|
|
6
5
|
export * from "./components/accordion.js";
|
|
7
6
|
export * from "./components/alert-dialog.js";
|
|
@@ -10,6 +9,7 @@ export * from "./components/ascii-field.js";
|
|
|
10
9
|
export * from "./components/aspect-ratio.js";
|
|
11
10
|
export * from "./components/avatar.js";
|
|
12
11
|
export * from "./components/badge.js";
|
|
12
|
+
export * from "./components/bottom-nav.js";
|
|
13
13
|
export * from "./components/breadcrumb.js";
|
|
14
14
|
export * from "./components/button-group.js";
|
|
15
15
|
export * from "./components/button.js";
|
|
@@ -31,29 +31,33 @@ export * from "./components/feature-list.js";
|
|
|
31
31
|
export * from "./components/field.js";
|
|
32
32
|
export * from "./components/file-drop.js";
|
|
33
33
|
export * from "./components/form.js";
|
|
34
|
-
export * from "./components/illustration.js";
|
|
35
34
|
export * from "./components/input-group.js";
|
|
36
35
|
export * from "./components/input.js";
|
|
37
36
|
export * from "./components/item.js";
|
|
38
37
|
export * from "./components/kbd.js";
|
|
39
38
|
export * from "./components/label.js";
|
|
40
39
|
export * from "./components/layout.js";
|
|
40
|
+
export * from "./components/lightbox.js";
|
|
41
|
+
export * from "./components/locale.js";
|
|
41
42
|
export * from "./components/logo.js";
|
|
42
43
|
export * from "./components/menu.js";
|
|
43
44
|
export * from "./components/menubar.js";
|
|
44
45
|
export * from "./components/message.js";
|
|
45
46
|
export * from "./components/meter.js";
|
|
47
|
+
export * from "./components/money-input.js";
|
|
46
48
|
export * from "./components/native-select.js";
|
|
47
49
|
export * from "./components/navigation-menu.js";
|
|
48
50
|
export * from "./components/number-field.js";
|
|
49
51
|
export * from "./components/otp-field.js";
|
|
50
52
|
export * from "./components/pagination.js";
|
|
53
|
+
export * from "./components/phone-input.js";
|
|
51
54
|
export * from "./components/popover.js";
|
|
52
55
|
export * from "./components/preview-card.js";
|
|
53
56
|
export * from "./components/progress.js";
|
|
54
57
|
export * from "./components/prompt-input.js";
|
|
55
58
|
export * from "./components/quote.js";
|
|
56
59
|
export * from "./components/radio-group.js";
|
|
60
|
+
export * from "./components/rating.js";
|
|
57
61
|
export * from "./components/reasoning.js";
|
|
58
62
|
export * from "./components/response.js";
|
|
59
63
|
export * from "./components/scroll-area.js";
|
|
@@ -63,8 +67,11 @@ export * from "./components/sidebar.js";
|
|
|
63
67
|
export * from "./components/site-header.js";
|
|
64
68
|
export * from "./components/skeleton.js";
|
|
65
69
|
export * from "./components/slider.js";
|
|
70
|
+
export * from "./components/sortable.js";
|
|
66
71
|
export * from "./components/sources.js";
|
|
67
72
|
export * from "./components/spinner.js";
|
|
73
|
+
export * from "./components/stat.js";
|
|
74
|
+
export * from "./components/stepper.js";
|
|
68
75
|
export * from "./components/suggestions.js";
|
|
69
76
|
export * from "./components/switch.js";
|
|
70
77
|
export * from "./components/table.js";
|
|
@@ -81,6 +88,7 @@ export * from "./components/toggle.js";
|
|
|
81
88
|
export * from "./components/tool-call.js";
|
|
82
89
|
export * from "./components/toolbar.js";
|
|
83
90
|
export * from "./components/tooltip.js";
|
|
91
|
+
export * from "./components/tour.js";
|
|
84
92
|
export * from "./components/tree.js";
|
|
85
93
|
export * from "./components/typography.js";
|
|
86
94
|
export * from "./components/video-player.js";
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
1
|
/** One run of source text in one colour, as the highlighter splits a line. */
|
|
3
2
|
export interface CodeToken {
|
|
4
3
|
content: string;
|
|
@@ -7,23 +6,11 @@ export interface CodeToken {
|
|
|
7
6
|
/** Italic, bold and underline as Shiki's FontStyle bit flags (1, 2, 4). */
|
|
8
7
|
fontStyle?: number;
|
|
9
8
|
}
|
|
10
|
-
/**
|
|
11
|
-
* What CodeBlock needs from a highlighter: a way to load a language, then to split code into
|
|
12
|
-
* coloured tokens synchronously, so a block that changes on every frame (a streaming reply)
|
|
13
|
-
* colours as it renders. `@zonsh/ui/code-highlight` supplies one, on Shiki; the main entry only
|
|
14
|
-
* knows this shape, so it never pulls Shiki in.
|
|
15
|
-
*/
|
|
16
|
-
export interface CodeHighlighter {
|
|
17
|
-
/** Resolves `true` once `language` can be tokenised, `false` if it is unknown. */
|
|
18
|
-
load(language: string): Promise<boolean>;
|
|
19
|
-
/** The code as lines of tokens, or `null` while `language` is not loaded. */
|
|
20
|
-
tokenize(code: string, language: string): CodeToken[][] | null;
|
|
21
|
-
}
|
|
22
|
-
export declare const CodeHighlighterContext: React.Context<CodeHighlighter | null>;
|
|
23
9
|
/**
|
|
24
10
|
* The tokens for `code` once its language has loaded, and `null` until then (or when there is no
|
|
25
|
-
*
|
|
26
|
-
* `pending` is true while colours are on their way, false once they are in or
|
|
11
|
+
* language, Shiki does not know it, or `enabled` is false), so the block shows plain mono meanwhile
|
|
12
|
+
* and on the server. `pending` is true while colours are on their way, false once they are in or
|
|
13
|
+
* never will be.
|
|
27
14
|
*/
|
|
28
15
|
export declare function useCodeTokens(code: string, language: string | undefined, enabled: boolean): {
|
|
29
16
|
tokens: CodeToken[][] | null;
|
|
@@ -1,24 +1,174 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
|
|
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
|
-
*
|
|
6
|
-
* `pending` is true while colours are on their way, false once they are in or
|
|
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 || !
|
|
113
|
+
if (!enabled || !language)
|
|
14
114
|
return;
|
|
15
115
|
let live = true;
|
|
16
|
-
|
|
116
|
+
loadLanguage(language).then((ok) => live && (ok ? setLoaded(language) : setFailed(language)));
|
|
17
117
|
return () => {
|
|
18
118
|
live = false;
|
|
19
119
|
};
|
|
20
|
-
}, [enabled,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
}
|
package/dist/lib/code-theme.js
CHANGED
|
@@ -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 (
|
|
8
|
-
*
|
|
9
|
-
*
|
|
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
|
/**
|
package/dist/lib/digit-roll.js
CHANGED
|
@@ -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
|
-
//
|
|
22
|
-
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
+
}
|
package/dist/lib/glide.d.ts
CHANGED
|
@@ -44,10 +44,11 @@ export declare function useGlide(container: React.RefObject<HTMLElement | null>,
|
|
|
44
44
|
/** Inline style that places an absolutely positioned indicator over the glide target. */
|
|
45
45
|
export declare function glideStyle({ rect }: Glide): React.CSSProperties | undefined;
|
|
46
46
|
/**
|
|
47
|
-
* The indicator's motion: translate and size in
|
|
48
|
-
* --duration. Put `data-instant` on it while
|
|
49
|
-
* Reduced motion sets --duration to 0, so it
|
|
47
|
+
* The indicator's motion: translate and size in --duration-glide on --ease-glide, the one speed and
|
|
48
|
+
* curve of every gliding indicator; opacity in --duration-fade. Put `data-instant` on it while
|
|
49
|
+
* `glide.instant`, `data-visible` while visible. Reduced motion sets --duration-glide to 0, so it
|
|
50
|
+
* moves instantly and only fades.
|
|
50
51
|
*/
|
|
51
|
-
export declare const glideMotion = "pointer-events-none absolute top-0 left-0 opacity-0 data-visible:opacity-100 transition-[translate,width,height,opacity]
|
|
52
|
+
export declare const glideMotion = "pointer-events-none absolute top-0 left-0 opacity-0 data-visible:opacity-100 transition-[translate,width,height,opacity] ease-(--ease-glide) [transition-duration:var(--duration-glide),var(--duration-glide),var(--duration-glide),var(--duration-fade)] data-instant:transition-none";
|
|
52
53
|
/** Merges a component's own ref with the one passed in by the caller. */
|
|
53
54
|
export declare function useMergedRef<T>(ref: React.Ref<T> | undefined): [React.RefObject<T | null>, (node: T | null) => void];
|
package/dist/lib/glide.js
CHANGED
|
@@ -119,11 +119,12 @@ export function glideStyle({ rect }) {
|
|
|
119
119
|
return rect ? { translate: `${rect.x}px ${rect.y}px`, width: rect.width, height: rect.height } : undefined;
|
|
120
120
|
}
|
|
121
121
|
/**
|
|
122
|
-
* The indicator's motion: translate and size in
|
|
123
|
-
* --duration. Put `data-instant` on it while
|
|
124
|
-
* Reduced motion sets --duration to 0, so it
|
|
122
|
+
* The indicator's motion: translate and size in --duration-glide on --ease-glide, the one speed and
|
|
123
|
+
* curve of every gliding indicator; opacity in --duration-fade. Put `data-instant` on it while
|
|
124
|
+
* `glide.instant`, `data-visible` while visible. Reduced motion sets --duration-glide to 0, so it
|
|
125
|
+
* moves instantly and only fades.
|
|
125
126
|
*/
|
|
126
|
-
export const glideMotion = "pointer-events-none absolute top-0 left-0 opacity-0 data-visible:opacity-100 transition-[translate,width,height,opacity]
|
|
127
|
+
export const glideMotion = "pointer-events-none absolute top-0 left-0 opacity-0 data-visible:opacity-100 transition-[translate,width,height,opacity] ease-(--ease-glide) [transition-duration:var(--duration-glide),var(--duration-glide),var(--duration-glide),var(--duration-fade)] data-instant:transition-none";
|
|
127
128
|
/** Merges a component's own ref with the one passed in by the caller. */
|
|
128
129
|
export function useMergedRef(ref) {
|
|
129
130
|
const own = React.useRef(null);
|
package/dist/lib/graph-layout.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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;
|