@volvel/ui 0.0.0-stage → 0.6.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.
Files changed (137) hide show
  1. package/LICENSE +202 -0
  2. package/THIRD_PARTY_NOTICES.md +23018 -0
  3. package/dist/Badge.d.ts +20 -0
  4. package/dist/Badge.js +35 -0
  5. package/dist/Button.d.ts +56 -0
  6. package/dist/Button.js +52 -0
  7. package/dist/Chart.d.ts +23 -0
  8. package/dist/Chart.js +98 -0
  9. package/dist/Combobox.d.ts +45 -0
  10. package/dist/Combobox.js +42 -0
  11. package/dist/ContextMenu.d.ts +16 -0
  12. package/dist/ContextMenu.js +11 -0
  13. package/dist/DateInput.d.ts +31 -0
  14. package/dist/DateInput.js +329 -0
  15. package/dist/Details.d.ts +12 -0
  16. package/dist/Details.js +9 -0
  17. package/dist/Dialog.d.ts +44 -0
  18. package/dist/Dialog.js +95 -0
  19. package/dist/Dialogs.d.ts +56 -0
  20. package/dist/Dialogs.js +95 -0
  21. package/dist/Doc.d.ts +25 -0
  22. package/dist/Doc.js +118 -0
  23. package/dist/DocServed.d.ts +6 -0
  24. package/dist/DocServed.js +154 -0
  25. package/dist/DocZoom.d.ts +11 -0
  26. package/dist/DocZoom.js +133 -0
  27. package/dist/Facts.d.ts +12 -0
  28. package/dist/Facts.js +10 -0
  29. package/dist/Fields.d.ts +184 -0
  30. package/dist/Fields.js +249 -0
  31. package/dist/Form.d.ts +47 -0
  32. package/dist/Form.js +189 -0
  33. package/dist/Grid.d.ts +118 -0
  34. package/dist/Grid.js +475 -0
  35. package/dist/HeadingSlot.d.ts +13 -0
  36. package/dist/HeadingSlot.js +19 -0
  37. package/dist/JsonView.d.ts +11 -0
  38. package/dist/JsonView.js +68 -0
  39. package/dist/LogViewer.d.ts +45 -0
  40. package/dist/LogViewer.js +299 -0
  41. package/dist/Markdown.d.ts +21 -0
  42. package/dist/Markdown.js +27 -0
  43. package/dist/MarkdownBody.d.ts +6 -0
  44. package/dist/MarkdownBody.js +14 -0
  45. package/dist/Menu.d.ts +29 -0
  46. package/dist/Menu.js +8 -0
  47. package/dist/MoveButtons.d.ts +19 -0
  48. package/dist/MoveButtons.js +22 -0
  49. package/dist/Notice.d.ts +47 -0
  50. package/dist/Notice.js +50 -0
  51. package/dist/PageShell.d.ts +42 -0
  52. package/dist/PageShell.js +14 -0
  53. package/dist/Pagination.d.ts +13 -0
  54. package/dist/Pagination.js +9 -0
  55. package/dist/Panel.d.ts +31 -0
  56. package/dist/Panel.js +33 -0
  57. package/dist/Pickers.d.ts +37 -0
  58. package/dist/Pickers.js +44 -0
  59. package/dist/Popover.d.ts +24 -0
  60. package/dist/Popover.js +12 -0
  61. package/dist/ResultView.d.ts +28 -0
  62. package/dist/ResultView.js +140 -0
  63. package/dist/SchemaForm.d.ts +45 -0
  64. package/dist/SchemaForm.js +626 -0
  65. package/dist/SideSheet.d.ts +31 -0
  66. package/dist/SideSheet.js +136 -0
  67. package/dist/Sparkline.d.ts +14 -0
  68. package/dist/Sparkline.js +23 -0
  69. package/dist/Surfaces.d.ts +30 -0
  70. package/dist/Surfaces.js +34 -0
  71. package/dist/Switch.d.ts +18 -0
  72. package/dist/Switch.js +11 -0
  73. package/dist/Table.d.ts +15 -0
  74. package/dist/Table.js +6 -0
  75. package/dist/Tabs.d.ts +32 -0
  76. package/dist/Tabs.js +11 -0
  77. package/dist/Term.d.ts +82 -0
  78. package/dist/Term.js +153 -0
  79. package/dist/Timeline.d.ts +29 -0
  80. package/dist/Timeline.js +39 -0
  81. package/dist/Toast.d.ts +43 -0
  82. package/dist/Toast.js +140 -0
  83. package/dist/Tooltip.d.ts +34 -0
  84. package/dist/Tooltip.js +70 -0
  85. package/dist/Tree.d.ts +51 -0
  86. package/dist/Tree.js +233 -0
  87. package/dist/chartEngine.d.ts +32 -0
  88. package/dist/chartEngine.js +72 -0
  89. package/dist/chartTheme.d.ts +41 -0
  90. package/dist/chartTheme.js +131 -0
  91. package/dist/contrast.d.ts +27 -0
  92. package/dist/contrast.js +110 -0
  93. package/dist/dates.d.ts +61 -0
  94. package/dist/dates.js +294 -0
  95. package/dist/drawer/Chips.d.ts +37 -0
  96. package/dist/drawer/Chips.js +32 -0
  97. package/dist/drawer/Choices.d.ts +47 -0
  98. package/dist/drawer/Choices.js +81 -0
  99. package/dist/drawer/Drawer.d.ts +125 -0
  100. package/dist/drawer/Drawer.js +150 -0
  101. package/dist/drawer/EditorBodies.d.ts +95 -0
  102. package/dist/drawer/EditorBodies.js +169 -0
  103. package/dist/drawer/NumberFormat.d.ts +36 -0
  104. package/dist/drawer/NumberFormat.js +98 -0
  105. package/dist/drawer/SortableRows.d.ts +35 -0
  106. package/dist/drawer/SortableRows.js +23 -0
  107. package/dist/drawer/edgeShadows.d.ts +7 -0
  108. package/dist/drawer/edgeShadows.js +17 -0
  109. package/dist/drawer/index.d.ts +8 -0
  110. package/dist/drawer/index.js +8 -0
  111. package/dist/drawer/useSortable.d.ts +53 -0
  112. package/dist/drawer/useSortable.js +323 -0
  113. package/dist/format.d.ts +6 -0
  114. package/dist/format.js +17 -0
  115. package/dist/icons.d.ts +20 -0
  116. package/dist/icons.js +16 -0
  117. package/dist/index.d.ts +48 -0
  118. package/dist/index.js +48 -0
  119. package/dist/markdownKnowledge.d.ts +45 -0
  120. package/dist/markdownKnowledge.js +37 -0
  121. package/dist/overlay.d.ts +7 -0
  122. package/dist/overlay.js +10 -0
  123. package/dist/pageIcons.d.ts +12 -0
  124. package/dist/pageIcons.js +32 -0
  125. package/dist/presence.d.ts +41 -0
  126. package/dist/presence.js +108 -0
  127. package/dist/returnFocus.d.ts +9 -0
  128. package/dist/returnFocus.js +44 -0
  129. package/dist/tokens.css +437 -0
  130. package/dist/type-scale.css +34 -0
  131. package/dist/useFlip.d.ts +32 -0
  132. package/dist/useFlip.js +118 -0
  133. package/fonts/OFL.txt +193 -0
  134. package/fonts/geist-latin.woff2 +0 -0
  135. package/fonts/geist-mono-latin.woff2 +0 -0
  136. package/package.json +47 -3
  137. package/README.md +0 -3
@@ -0,0 +1,37 @@
1
+ import { TERM_RESOURCES } from "@volvel/markup";
2
+ import { createContext, useContext } from "react";
3
+ const NOTHING = {};
4
+ const Knowledge = createContext(NOTHING);
5
+ /** Gives the Markdown drawn inside it what the host knows. */
6
+ export const MarkdownKnows = Knowledge.Provider;
7
+ export const useMarkdownKnowledge = () => useContext(Knowledge);
8
+ /**
9
+ * The knowledge a host builds from the workspace's words: a term by its `id` (or the word
10
+ * itself) from the glossary, a table, script, flow… by its path, and a column of a table, from
11
+ * their descriptions; a field from the kinds' own descriptions of them.
12
+ */
13
+ export function knowledgeFrom(words) {
14
+ const byId = new Map((words.terms ?? []).map((one) => [one.id, one]));
15
+ return {
16
+ term: (props) => {
17
+ if (props.id !== undefined) {
18
+ const found = byId.get(props.id);
19
+ if (!found)
20
+ return null;
21
+ return { short: found.short, ...(found.page ? { href: found.page.url } : {}) };
22
+ }
23
+ const kind = TERM_RESOURCES.find((one) => props[one] !== undefined);
24
+ if (!kind)
25
+ return null;
26
+ const resource = (words.resources ?? []).find((one) => one.kind === kind && one.path === props[kind]);
27
+ const said = props.column
28
+ ? resource?.columns?.find((one) => one.name === props.column)?.description
29
+ : resource?.description;
30
+ return said ? { short: said } : null;
31
+ },
32
+ field: (path) => {
33
+ const description = words.fields?.[path];
34
+ return description ? { description } : null;
35
+ },
36
+ };
37
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Whether what is drawn sits inside an open `Dialog` or `SideSheet`. A modal makes everything
3
+ * outside it inert, so anything that would open over the page (the help panel) must show its
4
+ * words inside the modal instead.
5
+ */
6
+ export declare const InOverlay: import("react").Context<boolean>;
7
+ export declare function useInOverlay(): boolean;
@@ -0,0 +1,10 @@
1
+ import { createContext, useContext } from "react";
2
+ /**
3
+ * Whether what is drawn sits inside an open `Dialog` or `SideSheet`. A modal makes everything
4
+ * outside it inert, so anything that would open over the page (the help panel) must show its
5
+ * words inside the modal instead.
6
+ */
7
+ export const InOverlay = createContext(false);
8
+ export function useInOverlay() {
9
+ return useContext(InOverlay);
10
+ }
@@ -0,0 +1,12 @@
1
+ import { type LucideIcon } from "lucide-react";
2
+ /**
3
+ * The icons a page of an app can have beside its title in the menu (`Page.icon`):
4
+ * a curated set, by the name each has in Lucide. The builder offers these, and the
5
+ * served app draws the one named, or none for a name it does not know.
6
+ */
7
+ export declare const PAGE_ICONS: Readonly<Record<string, {
8
+ label: string;
9
+ icon: LucideIcon;
10
+ }>>;
11
+ /** The icon a page names, if it is one of the set. */
12
+ export declare const pageIconOf: (name: string | undefined) => LucideIcon | undefined;
@@ -0,0 +1,32 @@
1
+ import { Banknote, Boxes, Calendar, ChartColumn, ClipboardList, File, FileText, Folder, HeartPulse, House, Inbox, Mail, Package, PawPrint, Receipt, Settings, ShoppingCart, Stethoscope, Truck, Users, Wallet, Wrench, } from "lucide-react";
2
+ /**
3
+ * The icons a page of an app can have beside its title in the menu (`Page.icon`):
4
+ * a curated set, by the name each has in Lucide. The builder offers these, and the
5
+ * served app draws the one named, or none for a name it does not know.
6
+ */
7
+ export const PAGE_ICONS = {
8
+ banknote: { label: "Banknote", icon: Banknote },
9
+ boxes: { label: "Boxes", icon: Boxes },
10
+ calendar: { label: "Calendar", icon: Calendar },
11
+ "chart-column": { label: "Chart", icon: ChartColumn },
12
+ "clipboard-list": { label: "Checklist", icon: ClipboardList },
13
+ file: { label: "File", icon: File },
14
+ "file-text": { label: "Document", icon: FileText },
15
+ folder: { label: "Folder", icon: Folder },
16
+ "heart-pulse": { label: "Health", icon: HeartPulse },
17
+ house: { label: "Home", icon: House },
18
+ inbox: { label: "Inbox", icon: Inbox },
19
+ mail: { label: "Mail", icon: Mail },
20
+ package: { label: "Package", icon: Package },
21
+ "paw-print": { label: "Paw", icon: PawPrint },
22
+ receipt: { label: "Receipt", icon: Receipt },
23
+ settings: { label: "Settings", icon: Settings },
24
+ "shopping-cart": { label: "Cart", icon: ShoppingCart },
25
+ stethoscope: { label: "Stethoscope", icon: Stethoscope },
26
+ truck: { label: "Truck", icon: Truck },
27
+ users: { label: "People", icon: Users },
28
+ wallet: { label: "Wallet", icon: Wallet },
29
+ wrench: { label: "Tools", icon: Wrench },
30
+ };
31
+ /** The icon a page names, if it is one of the set. */
32
+ export const pageIconOf = (name) => name ? PAGE_ICONS[name]?.icon : undefined;
@@ -0,0 +1,41 @@
1
+ import { type HTMLAttributes, type ReactNode, type Ref } from "react";
2
+ /**
3
+ * Whether a sheet or dialog is open, as its own parts are told. One that is
4
+ * put on the page already open is told it is shut first and open a moment
5
+ * later, so it arrives with the same motion as one that was waiting there:
6
+ * anything born open would otherwise skip its opening.
7
+ */
8
+ export declare function useOpening(open: boolean): boolean;
9
+ /**
10
+ * The last thing there was to show. A sheet stays on the page while it
11
+ * closes, and whoever opened it has already forgotten what it was about; this
12
+ * remembers, so the sheet closes showing what it showed.
13
+ */
14
+ export declare function useLast<T>(value: T | undefined): T | undefined;
15
+ /**
16
+ * A sheet or dialog that is about something: a row, a widget, a role. It is
17
+ * on the page while there is a subject, told it is open, and stays for as long
18
+ * as closing takes once there is none, told it is shut and still given the
19
+ * subject it had. So it leaves with the motion it arrived with, and the next
20
+ * one starts afresh.
21
+ *
22
+ * This is how a sheet is opened for a subject. Rendering one only while the
23
+ * subject is there, with `open` written bare, takes it away in one frame.
24
+ */
25
+ export declare function Closing<T>({ subject, children, }: {
26
+ subject: T | undefined | null | false;
27
+ children: (subject: T, open: boolean) => ReactNode;
28
+ }): import("react").JSX.Element | null;
29
+ /**
30
+ * A panel drawn by hand, such as a list of things to add under its button,
31
+ * that arrives and leaves with motion. It carries `data-starting-style` for
32
+ * its first frame and `data-ending-style` while it leaves, as a sheet or
33
+ * dialog does, so the same classes move it:
34
+ * `transition-[opacity,translate] motion-base data-[starting-style]:opacity-0`.
35
+ * It is marked `data-drawer`, which is what the browser tests watch.
36
+ */
37
+ export declare function Appear({ open, children, ref, ...rest }: {
38
+ open: boolean;
39
+ children: ReactNode;
40
+ ref?: Ref<HTMLDivElement>;
41
+ } & HTMLAttributes<HTMLDivElement>): import("react").JSX.Element | null;
@@ -0,0 +1,108 @@
1
+ import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
2
+ import { useEffect, useRef, useState } from "react";
3
+ /**
4
+ * Whether a sheet or dialog is open, as its own parts are told. One that is
5
+ * put on the page already open is told it is shut first and open a moment
6
+ * later, so it arrives with the same motion as one that was waiting there:
7
+ * anything born open would otherwise skip its opening.
8
+ */
9
+ export function useOpening(open) {
10
+ const [mounted, setMounted] = useState(false);
11
+ useEffect(() => setMounted(true), []);
12
+ return open && mounted;
13
+ }
14
+ /**
15
+ * The last thing there was to show. A sheet stays on the page while it
16
+ * closes, and whoever opened it has already forgotten what it was about; this
17
+ * remembers, so the sheet closes showing what it showed.
18
+ */
19
+ export function useLast(value) {
20
+ const last = useRef(value);
21
+ if (value !== undefined)
22
+ last.current = value;
23
+ return last.current;
24
+ }
25
+ /** As long as `motion-slow` and a little more: the time a sheet or dialog takes to close. */
26
+ const CLOSING_MS = 280;
27
+ const still = () => typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
28
+ /**
29
+ * A sheet or dialog that is about something: a row, a widget, a role. It is
30
+ * on the page while there is a subject, told it is open, and stays for as long
31
+ * as closing takes once there is none, told it is shut and still given the
32
+ * subject it had. So it leaves with the motion it arrived with, and the next
33
+ * one starts afresh.
34
+ *
35
+ * This is how a sheet is opened for a subject. Rendering one only while the
36
+ * subject is there, with `open` written bare, takes it away in one frame.
37
+ */
38
+ export function Closing({ subject, children, }) {
39
+ const here = subject !== undefined && subject !== null && subject !== false;
40
+ const last = useRef(undefined);
41
+ if (here)
42
+ last.current = subject;
43
+ const [present, setPresent] = useState(here);
44
+ if (here && !present)
45
+ setPresent(true);
46
+ useEffect(() => {
47
+ if (here || !present)
48
+ return;
49
+ if (still()) {
50
+ setPresent(false);
51
+ return;
52
+ }
53
+ const gone = setTimeout(() => setPresent(false), CLOSING_MS);
54
+ return () => clearTimeout(gone);
55
+ }, [here, present]);
56
+ if (!present && !here)
57
+ return null;
58
+ return _jsx(_Fragment, { children: children(last.current, here) });
59
+ }
60
+ /**
61
+ * A panel drawn by hand, such as a list of things to add under its button,
62
+ * that arrives and leaves with motion. It carries `data-starting-style` for
63
+ * its first frame and `data-ending-style` while it leaves, as a sheet or
64
+ * dialog does, so the same classes move it:
65
+ * `transition-[opacity,translate] motion-base data-[starting-style]:opacity-0`.
66
+ * It is marked `data-drawer`, which is what the browser tests watch.
67
+ */
68
+ export function Appear({ open, children, ref, ...rest }) {
69
+ const [present, setPresent] = useState(open);
70
+ const [phase, setPhase] = useState(open ? "starting" : undefined);
71
+ const was = useRef(open);
72
+ if (was.current !== open) {
73
+ was.current = open;
74
+ if (open) {
75
+ setPresent(true);
76
+ setPhase("starting");
77
+ }
78
+ else {
79
+ setPhase(still() ? undefined : "ending");
80
+ if (still())
81
+ setPresent(false);
82
+ }
83
+ }
84
+ useEffect(() => {
85
+ if (phase === "starting") {
86
+ // Two frames: one for the starting style to be drawn, one to leave it.
87
+ let second = 0;
88
+ const first = requestAnimationFrame(() => {
89
+ second = requestAnimationFrame(() => setPhase(undefined));
90
+ });
91
+ return () => {
92
+ cancelAnimationFrame(first);
93
+ cancelAnimationFrame(second);
94
+ };
95
+ }
96
+ if (phase === "ending") {
97
+ const gone = setTimeout(() => {
98
+ setPresent(false);
99
+ setPhase(undefined);
100
+ }, CLOSING_MS);
101
+ return () => clearTimeout(gone);
102
+ }
103
+ return undefined;
104
+ }, [phase]);
105
+ if (!present)
106
+ return null;
107
+ return (_jsx("div", { ...rest, ref: ref, "data-drawer": "", "data-starting-style": phase === "starting" ? "" : undefined, "data-ending-style": phase === "ending" ? "" : undefined, inert: phase === "ending", children: children }));
108
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Where the focus goes when a dialog or sheet closes: back to what opened it. When that has left
3
+ * the page (a Discard or a Keep removes the very button that was pressed), to the nearest thing
4
+ * that held it and is still there, so the person stays where they were and Tab goes on from
5
+ * there, rather than starting again at the top of the page. Nothing to go back to answers
6
+ * `true`, the library's own choice. When the focus already sits in another open dialog, it stays
7
+ * there (`false`).
8
+ */
9
+ export declare function useReturnFocus(open: boolean): () => HTMLElement | boolean;
@@ -0,0 +1,44 @@
1
+ import { useRef } from "react";
2
+ function noteOpener() {
3
+ const element = document.activeElement;
4
+ if (!(element instanceof HTMLElement) || element === document.body)
5
+ return undefined;
6
+ const holders = [];
7
+ for (let up = element.parentElement; up && up !== document.body; up = up.parentElement) {
8
+ holders.push(up);
9
+ }
10
+ return { element, holders };
11
+ }
12
+ /**
13
+ * Where the focus goes when a dialog or sheet closes: back to what opened it. When that has left
14
+ * the page (a Discard or a Keep removes the very button that was pressed), to the nearest thing
15
+ * that held it and is still there, so the person stays where they were and Tab goes on from
16
+ * there, rather than starting again at the top of the page. Nothing to go back to answers
17
+ * `true`, the library's own choice. When the focus already sits in another open dialog, it stays
18
+ * there (`false`).
19
+ */
20
+ export function useReturnFocus(open) {
21
+ const noted = useRef(undefined);
22
+ const was = useRef(false);
23
+ if (open && !was.current)
24
+ noted.current = noteOpener();
25
+ was.current = open;
26
+ return () => {
27
+ // Another dialog or sheet opened as this one closed (a question answered, and its answer
28
+ // shown in a dialog): the focus is in that one now, and is not taken back to the page behind it.
29
+ const on = document.activeElement;
30
+ if (on?.closest('[role="dialog"]:not([data-ending-style]), [role="alertdialog"]:not([data-ending-style])'))
31
+ return false;
32
+ const opener = noted.current;
33
+ if (!opener)
34
+ return true;
35
+ if (opener.element.isConnected)
36
+ return opener.element;
37
+ const holder = opener.holders.find((one) => one.isConnected);
38
+ if (!holder)
39
+ return true;
40
+ if (!holder.hasAttribute("tabindex"))
41
+ holder.setAttribute("tabindex", "-1");
42
+ return holder;
43
+ };
44
+ }