@vokality/design-system 2.0.0 → 3.0.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 (161) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +49 -3
  3. package/dist/browser.d.ts +13 -0
  4. package/dist/browser.js +7 -0
  5. package/dist/charts/chart.d.ts +6 -5
  6. package/dist/charts/chart.js +44 -25
  7. package/dist/chat.d.ts +54 -0
  8. package/dist/chat.js +1 -0
  9. package/dist/components/Accordion/Accordion.js +1 -1
  10. package/dist/components/Alert/Alert.js +5 -2
  11. package/dist/components/AppShell/AppShell.js +10 -14
  12. package/dist/components/Avatar/Avatar.js +2 -2
  13. package/dist/components/AvatarGroup/AvatarGroup.js +2 -2
  14. package/dist/components/BarChart/BarChart.js +17 -15
  15. package/dist/components/Breadcrumbs/Breadcrumbs.js +6 -3
  16. package/dist/components/Calendar/Calendar.js +6 -5
  17. package/dist/components/Card/Card.js +2 -3
  18. package/dist/components/ChatInbox/ChatInbox.d.ts +11 -0
  19. package/dist/components/ChatInbox/ChatInbox.js +49 -0
  20. package/dist/components/ChatPanel/ChatPanel.d.ts +3 -0
  21. package/dist/components/ChatPanel/ChatPanel.js +13 -0
  22. package/dist/components/ChatPanel/composer.d.ts +5 -0
  23. package/dist/components/ChatPanel/composer.js +32 -0
  24. package/dist/components/ChatPanel/transcript.d.ts +13 -0
  25. package/dist/components/ChatPanel/transcript.js +39 -0
  26. package/dist/components/ChatWidget/ChatWidget.d.ts +12 -0
  27. package/dist/components/ChatWidget/ChatWidget.js +42 -0
  28. package/dist/components/Checkbox/Checkbox.d.ts +5 -10
  29. package/dist/components/Checkbox/Checkbox.js +5 -19
  30. package/dist/components/CodeBlock/CodeBlock.js +19 -5
  31. package/dist/components/Combobox/Combobox.js +22 -15
  32. package/dist/components/Combobox/ListPanel.js +20 -9
  33. package/dist/components/CommandPalette/CommandPalette.js +33 -14
  34. package/dist/components/ContextMenu/ContextMenu.d.ts +2 -2
  35. package/dist/components/ContextMenu/ContextMenu.js +5 -50
  36. package/dist/components/DatePicker/DatePicker.js +35 -29
  37. package/dist/components/DescriptionList/DescriptionList.js +1 -1
  38. package/dist/components/Dialog/Dialog.d.ts +24 -7
  39. package/dist/components/Dialog/Dialog.js +30 -41
  40. package/dist/components/Drawer/Drawer.d.ts +4 -2
  41. package/dist/components/EmptyState/EmptyState.js +2 -2
  42. package/dist/components/ErrorSummary/ErrorSummary.js +5 -3
  43. package/dist/components/FaqList/FaqList.js +1 -1
  44. package/dist/components/Field/Field.js +2 -2
  45. package/dist/components/FileUpload/FileUpload.js +17 -9
  46. package/dist/components/Grid/Grid.d.ts +5 -5
  47. package/dist/components/Grid/Grid.js +1 -1
  48. package/dist/components/Heading/Heading.js +2 -1
  49. package/dist/components/Icon/Icon.js +4 -2
  50. package/dist/components/Inline/Inline.d.ts +7 -7
  51. package/dist/components/LineChart/LineChart.js +17 -15
  52. package/dist/components/LinkProvider/LinkProvider.d.ts +1 -1
  53. package/dist/components/LinkProvider/LinkProvider.js +6 -2
  54. package/dist/components/List/List.js +1 -1
  55. package/dist/components/MediaCard/MediaCard.js +2 -2
  56. package/dist/components/Menu/Menu.js +6 -43
  57. package/dist/components/Menu/entries.d.ts +1 -30
  58. package/dist/components/Menu/entries.js +16 -100
  59. package/dist/components/MultiSelect/MultiSelect.js +43 -34
  60. package/dist/components/NumberInput/NumberInput.js +17 -18
  61. package/dist/components/OtpInput/OtpInput.d.ts +1 -1
  62. package/dist/components/OtpInput/OtpInput.js +10 -67
  63. package/dist/components/PageHeader/PageHeader.js +2 -2
  64. package/dist/components/Pagination/Pagination.js +3 -1
  65. package/dist/components/PasswordInput/PasswordInput.d.ts +1 -1
  66. package/dist/components/PasswordInput/PasswordInput.js +9 -4
  67. package/dist/components/Popover/Popover.d.ts +6 -7
  68. package/dist/components/Popover/Popover.js +2 -19
  69. package/dist/components/Progress/Progress.d.ts +1 -1
  70. package/dist/components/Progress/Progress.js +7 -11
  71. package/dist/components/Radio/Radio.d.ts +4 -2
  72. package/dist/components/RadioGroup/RadioGroup.d.ts +5 -12
  73. package/dist/components/RadioGroup/RadioGroup.js +6 -33
  74. package/dist/components/RichTextEditor/RichTextEditor.d.ts +63 -0
  75. package/dist/components/RichTextEditor/RichTextEditor.js +175 -0
  76. package/dist/components/RichTextEditor/toolbar.d.ts +15 -0
  77. package/dist/components/RichTextEditor/toolbar.js +142 -0
  78. package/dist/components/RichTextEditor/uploads.d.ts +41 -0
  79. package/dist/components/RichTextEditor/uploads.js +124 -0
  80. package/dist/components/SearchInput/SearchInput.js +4 -2
  81. package/dist/components/SectionHeader/SectionHeader.js +1 -3
  82. package/dist/components/SegmentedControl/SegmentedControl.js +2 -12
  83. package/dist/components/Select/Select.d.ts +15 -16
  84. package/dist/components/Select/Select.js +11 -252
  85. package/dist/components/Slider/Slider.js +11 -21
  86. package/dist/components/Sparkline/Sparkline.js +8 -3
  87. package/dist/components/Spinner/Spinner.js +5 -2
  88. package/dist/components/Stack/Stack.d.ts +5 -5
  89. package/dist/components/Stat/Stat.js +6 -3
  90. package/dist/components/Steps/Steps.js +6 -3
  91. package/dist/components/Switch/Switch.d.ts +7 -7
  92. package/dist/components/Switch/Switch.js +4 -10
  93. package/dist/components/Table/Table.js +38 -19
  94. package/dist/components/Tabs/Tabs.js +2 -22
  95. package/dist/components/Tag/Tag.js +3 -1
  96. package/dist/components/Text/Text.d.ts +1 -1
  97. package/dist/components/TileGrid/TileGrid.js +1 -1
  98. package/dist/components/TimePicker/TimePicker.js +35 -33
  99. package/dist/components/Timeline/Timeline.js +5 -4
  100. package/dist/components/Toaster/Toaster.js +21 -17
  101. package/dist/components/Tooltip/Tooltip.d.ts +6 -6
  102. package/dist/components/Tooltip/Tooltip.js +3 -17
  103. package/dist/components/TreeView/TreeView.js +15 -12
  104. package/dist/components.css +179 -8
  105. package/dist/hooks/useTheme.js +6 -6
  106. package/dist/icons/message-circle.svg +1 -0
  107. package/dist/internal/CharCount.js +3 -1
  108. package/dist/internal/choice.d.ts +10 -48
  109. package/dist/internal/choice.js +8 -96
  110. package/dist/internal/options.d.ts +10 -5
  111. package/dist/internal/options.js +25 -11
  112. package/dist/internal/status.d.ts +3 -2
  113. package/dist/internal/status.js +10 -2
  114. package/dist/internal/useScrollActive.js +2 -2
  115. package/dist/internal/useToday.d.ts +3 -0
  116. package/dist/internal/useToday.js +42 -0
  117. package/dist/lib/dates.js +25 -15
  118. package/dist/lib/format.js +11 -8
  119. package/dist/lib/icons.d.ts +5 -0
  120. package/dist/lib/icons.js +2 -0
  121. package/dist/lib/math.js +17 -5
  122. package/dist/lib/rich-text.d.ts +13 -0
  123. package/dist/lib/rich-text.js +62 -0
  124. package/dist/lib/space.d.ts +1 -2
  125. package/dist/lib/space.js +4 -1
  126. package/dist/lib/text.js +1 -1
  127. package/dist/lib/theme.js +1 -1
  128. package/dist/localization.d.ts +166 -0
  129. package/dist/localization.js +142 -0
  130. package/dist/vokality.css +179 -8
  131. package/dist/vokality.iife.js +35986 -9685
  132. package/docs/brand.md +6 -3
  133. package/docs/components/AppShell/README.md +1 -1
  134. package/docs/components/BarChart/README.md +1 -0
  135. package/docs/components/ChatInbox/README.md +41 -0
  136. package/docs/components/ChatWidget/README.md +47 -0
  137. package/docs/components/Checkbox/README.md +7 -3
  138. package/docs/components/ContextMenu/README.md +7 -3
  139. package/docs/components/Dialog/README.md +9 -4
  140. package/docs/components/Drawer/README.md +1 -1
  141. package/docs/components/Field/README.md +1 -1
  142. package/docs/components/Fieldset/README.md +2 -2
  143. package/docs/components/LineChart/README.md +1 -0
  144. package/docs/components/LocaleProvider/README.md +48 -0
  145. package/docs/components/Menu/README.md +13 -8
  146. package/docs/components/OtpInput/README.md +9 -5
  147. package/docs/components/PasswordInput/README.md +11 -2
  148. package/docs/components/Popover/README.md +6 -3
  149. package/docs/components/Progress/README.md +3 -1
  150. package/docs/components/RadioGroup/README.md +5 -2
  151. package/docs/components/RichTextEditor/README.md +84 -0
  152. package/docs/components/SegmentedControl/README.md +2 -0
  153. package/docs/components/Select/README.md +13 -17
  154. package/docs/components/Skeleton/README.md +1 -1
  155. package/docs/components/Slider/README.md +4 -2
  156. package/docs/components/Steps/README.md +1 -1
  157. package/docs/components/Switch/README.md +5 -2
  158. package/docs/components/Tabs/README.md +4 -2
  159. package/docs/components/Toaster/README.md +3 -1
  160. package/docs/components/Tooltip/README.md +5 -3
  161. package/package.json +49 -5
@@ -1,14 +1,21 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { useRef, useState } from "react";
3
+ import { useLocale } from "../../localization.js";
4
+ import { createElement, useRef, useState } from "react";
4
5
  import { Icon } from "../Icon/Icon.js";
5
6
  import { IconButton } from "../IconButton/IconButton.js";
6
7
  import { useUid } from "../../internal/useUid.js";
7
8
  import { cx } from "../../lib/cx.js";
8
- import { formatBytes } from "../../lib/format.js";
9
+ import { formatNumber } from "../../lib/format.js";
9
10
  import { para } from "../../lib/text.js";
10
11
  /** Drop zone with a browse button for attaching files, and a list of the chosen files with sizes and errors. */
11
12
  export function FileUpload(props) {
13
+ const { locale, messages } = useLocale();
14
+ const sizeLabel = (size) => {
15
+ const value = size < 1024 ? size : size < 1048576 ? size / 1024 : size / 1048576;
16
+ const decimals = size >= 1048576 || (size >= 1024 && size < 10240) ? 1 : 0;
17
+ return formatNumber(value, { locale, minimumFractionDigits: decimals, maximumFractionDigits: decimals }) + (size < 1024 ? " B" : size < 1048576 ? " KB" : " MB");
18
+ };
12
19
  const uid = useUid("vk-file");
13
20
  const id = props.id || uid;
14
21
  const [files, setFiles] = useState(props.defaultFiles || []);
@@ -21,27 +28,28 @@ export function FileUpload(props) {
21
28
  };
22
29
  const accept = (list) => {
23
30
  const incoming = Array.from(list, (f) => {
24
- const error = props.maxSize && f.size > props.maxSize ? "Larger than " + formatBytes(props.maxSize) + "." : null;
31
+ const error = props.maxSize && f.size > props.maxSize ? messages.fileTooLarge(sizeLabel(props.maxSize)) : null;
25
32
  return { name: f.name, size: f.size, file: f, error };
26
33
  });
27
34
  update(props.multiple ? files.concat(incoming) : incoming.slice(0, 1));
28
35
  };
29
- const remove = (i) => update(files.filter((_, j) => j !== i));
30
- const Hint = para(props.hint);
36
+ const remove = (i) => { update(files.filter((_, j) => j !== i)); };
31
37
  return (_jsxs("div", { className: cx("vk-upload", props.className), children: [_jsxs("div", { className: cx("vk-dropzone", dragging && "vk-dropzone-active", props.disabled && "vk-dropzone-disabled"), onDragOver: (e) => {
32
38
  if (props.disabled)
33
39
  return;
34
40
  e.preventDefault();
35
41
  setDragging(true);
36
- }, onDragLeave: () => setDragging(false), onDrop: (e) => {
42
+ }, onDragLeave: () => { setDragging(false); }, onDrop: (e) => {
37
43
  e.preventDefault();
38
44
  setDragging(false);
39
45
  if (!props.disabled)
40
46
  accept(e.dataTransfer.files);
41
- }, children: [_jsx(Icon, { name: "upload", className: "vk-dropzone-icon" }), _jsxs("div", { className: "vk-dropzone-text", children: [_jsxs("p", { className: "vk-dropzone-title", children: [props.title || (props.multiple ? "Drop files here" : "Drop a file here"), " or ", _jsx("button", { type: "button", className: "vk-link vk-dropzone-browse", disabled: props.disabled, onClick: () => inputRef.current?.click(), children: "browse" })] }), props.hint ? _jsx(Hint, { className: "vk-dropzone-hint", children: props.hint }) : null] }), _jsx("input", { ref: inputRef, id: id, type: "file", className: "vk-sr-only", tabIndex: -1, accept: props.accept, multiple: props.multiple, disabled: props.disabled, name: props.name, "aria-label": props["aria-label"], "aria-labelledby": props["aria-labelledby"], "aria-describedby": props["aria-describedby"], onChange: (e) => {
47
+ }, children: [_jsx(Icon, { name: "upload", className: "vk-dropzone-icon" }), _jsxs("div", { className: "vk-dropzone-text", children: [_jsxs("p", { className: "vk-dropzone-title", children: [props.title || (props.multiple ? messages.dropFiles : messages.dropFile), messages.or, _jsx("button", { type: "button", className: "vk-link vk-dropzone-browse", disabled: props.disabled, onClick: () => inputRef.current?.click(), children: messages.browse })] }), props.hint ? createElement(para(props.hint), { className: "vk-dropzone-hint" }, props.hint) : null] }), _jsx("input", { ref: inputRef, id: id, type: "file", className: "vk-sr-only", tabIndex: -1, accept: props.accept, multiple: props.multiple, disabled: props.disabled, name: props.name, "aria-label": props["aria-label"], "aria-labelledby": props["aria-labelledby"], "aria-describedby": props["aria-describedby"], onChange: (e) => {
42
48
  // A file input always has a FileList.
43
- accept(e.target.files);
49
+ const chosen = e.target.files;
50
+ if (chosen)
51
+ accept(chosen);
44
52
  // Clear it so choosing the same file again still fires onChange.
45
53
  e.target.value = "";
46
- } })] }), files.length ? (_jsx("ul", { className: "vk-upload-list", children: files.map((f, i) => (_jsxs("li", { className: cx("vk-upload-item", f.error && "vk-upload-item-error"), children: [_jsx(Icon, { name: f.error ? "circle-alert" : "file", size: 16, className: "vk-upload-icon" }), _jsx("span", { className: "vk-upload-name", children: f.name }), f.error ? _jsx("span", { className: "vk-upload-error", children: f.error }) : _jsx("span", { className: "vk-upload-size", children: formatBytes(f.size) }), _jsx(IconButton, { icon: "x", size: 16, label: "Remove " + f.name, onClick: () => remove(i) })] }, f.name + i))) })) : null] }));
54
+ } })] }), files.length ? (_jsx("ul", { className: "vk-upload-list", children: files.map((f, i) => (_jsxs("li", { className: cx("vk-upload-item", f.error && "vk-upload-item-error"), children: [_jsx(Icon, { name: f.error ? "circle-alert" : "file", size: 16, className: "vk-upload-icon" }), _jsx("span", { className: "vk-upload-name", children: f.name }), f.error ? _jsx("span", { className: "vk-upload-error", children: f.file && props.maxSize && f.size > props.maxSize ? messages.fileTooLarge(sizeLabel(props.maxSize)) : f.error }) : _jsx("span", { className: "vk-upload-size", children: sizeLabel(f.size) }), _jsx(IconButton, { icon: "x", size: 16, label: messages.remove(f.name), onClick: () => { remove(i); } })] }, f.name + String(i)))) })) : null] }));
47
55
  }
@@ -1,9 +1,9 @@
1
1
  import { type CSSProperties, type ReactNode } from "react";
2
- import type { ElementTag, PolymorphicProps, SpaceStep } from "../../types.js";
2
+ import type { ElementTag, PolymorphicProps } from "../../types.js";
3
3
  export interface GridOwnProps {
4
4
  columns?: number;
5
5
  min?: string;
6
- gap?: SpaceStep | string;
6
+ gap?: string;
7
7
  children?: ReactNode;
8
8
  className?: string;
9
9
  style?: CSSProperties;
@@ -181,6 +181,7 @@ export declare function Grid<T extends ElementTag = "div">({ as, columns, min, g
181
181
  gridRowEnd?: import("csstype").Property.GridRowEnd | undefined;
182
182
  gridRowStart?: import("csstype").Property.GridRowStart | undefined;
183
183
  gridTemplateAreas?: import("csstype").Property.GridTemplateAreas | undefined;
184
+ gridTemplateColumns: import("csstype").Property.GridTemplateColumns<string | number>;
184
185
  gridTemplateRows?: import("csstype").Property.GridTemplateRows<string | number> | undefined;
185
186
  hangingPunctuation?: import("csstype").Property.HangingPunctuation | undefined;
186
187
  height?: import("csstype").Property.Height<string | number> | undefined;
@@ -468,6 +469,7 @@ export declare function Grid<T extends ElementTag = "div">({ as, columns, min, g
468
469
  flex?: import("csstype").Property.Flex<string | number> | undefined;
469
470
  flexFlow?: import("csstype").Property.FlexFlow | undefined;
470
471
  font?: import("csstype").Property.Font | undefined;
472
+ gap: import("csstype").Property.Gap<string | number>;
471
473
  grid?: import("csstype").Property.Grid | undefined;
472
474
  gridArea?: import("csstype").Property.GridArea | undefined;
473
475
  gridColumn?: import("csstype").Property.GridColumn | undefined;
@@ -868,7 +870,5 @@ export declare function Grid<T extends ElementTag = "div">({ as, columns, min, g
868
870
  colorInterpolation?: import("csstype").Property.ColorInterpolation | undefined;
869
871
  colorRendering?: import("csstype").Property.ColorRendering | undefined;
870
872
  glyphOrientationVertical?: import("csstype").Property.GlyphOrientationVertical | undefined;
871
- gap: import("csstype").Property.Gap<string | number>;
872
- gridTemplateColumns: import("csstype").Property.GridTemplateColumns<string | number>;
873
873
  };
874
- } & Omit<GridProps<T>, "as" | "children" | "className" | "columns" | "gap" | "min" | "style">, string | import("react").JSXElementConstructor<any>>;
874
+ } & Omit<GridProps<T>, "min" | "columns" | "gap" | "style" | "className" | "children" | "as">, string | import("react").JSXElementConstructor<any>>;
@@ -4,6 +4,6 @@ import { space } from "../../lib/space.js";
4
4
  /** A responsive grid: a fixed number of columns, or as many columns of at least `min` width as fit. */
5
5
  export function Grid({ as, columns, min, gap, children, className, style, ...rest }) {
6
6
  const fixed = typeof columns === "number";
7
- const template = fixed ? "repeat(" + columns + ", minmax(0, 1fr))" : "repeat(auto-fit, minmax(min(" + (min || "16rem") + ", 100%), 1fr))";
7
+ const template = fixed ? "repeat(" + String(columns) + ", minmax(0, 1fr))" : "repeat(auto-fit, minmax(min(" + (min || "16rem") + ", 100%), 1fr))";
8
8
  return createElement(as || "div", { className: cx("vk-layout-grid", fixed ? "vk-layout-grid-fixed" : null, className), style: { gap: space(gap, "lg"), gridTemplateColumns: template, ...style }, ...rest }, children);
9
9
  }
@@ -6,6 +6,7 @@ export const HEADING_SIZE = { 1: "heading-1", 2: "heading-2", 3: "title", 4: "ti
6
6
  export function Heading({ level: levelProp, size, id, children, className }) {
7
7
  const level = levelProp || 2;
8
8
  const style = size || HEADING_SIZE[level];
9
- const Tag = `h${level}`;
9
+ const tags = { 1: "h1", 2: "h2", 3: "h3", 4: "h4" };
10
+ const Tag = tags[level];
10
11
  return _jsx(Tag, { id: id, className: cx("vk-heading", "vk-text-" + style, className), children: children });
11
12
  }
@@ -1,9 +1,11 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { cx } from "../../lib/cx.js";
3
3
  import { ICONS } from "../../lib/icons.js";
4
+ // Lookup remains optional at the runtime boundary for untyped consumers.
5
+ const definitions = ICONS;
4
6
  /** Lucide outline icon, stroke currentColor. */
5
7
  export function Icon({ name, size, className }) {
6
- const def = ICONS[name];
8
+ const def = definitions[name];
7
9
  if (!def)
8
10
  return null;
9
11
  const px = size || def.size;
@@ -11,7 +13,7 @@ export function Icon({ name, size, className }) {
11
13
  const circles = def.circle ? (Array.isArray(def.circle) ? def.circle : [def.circle]) : [];
12
14
  const kids = [
13
15
  ...def.d.map((d, i) => _jsx("path", { d: d, ...common }, i)),
14
- ...circles.map((c, i) => _jsx("circle", { ...c, ...common }, "c" + i)),
16
+ ...circles.map((c, i) => _jsx("circle", { ...c, ...common }, "c" + String(i))),
15
17
  ];
16
18
  return (_jsx("svg", { className: cx("vk-icon", className), viewBox: "0 0 24 24", width: px, height: px, fill: "none", "aria-hidden": "true", children: kids }));
17
19
  }
@@ -1,7 +1,7 @@
1
1
  import { type CSSProperties, type ReactNode } from "react";
2
- import type { ElementTag, PolymorphicProps, SpaceStep } from "../../types.js";
2
+ import type { ElementTag, PolymorphicProps } from "../../types.js";
3
3
  export interface InlineOwnProps {
4
- gap?: SpaceStep | string;
4
+ gap?: string;
5
5
  align?: CSSProperties['alignItems'];
6
6
  justify?: CSSProperties['justifyContent'];
7
7
  wrap?: boolean;
@@ -16,6 +16,7 @@ export declare function Inline<T extends ElementTag = "div">({ as, gap, align, j
16
16
  style: {
17
17
  accentColor?: import("csstype").Property.AccentColor | undefined;
18
18
  alignContent?: import("csstype").Property.AlignContent | undefined;
19
+ alignItems: import("csstype").Property.AlignItems;
19
20
  alignSelf?: import("csstype").Property.AlignSelf | undefined;
20
21
  alignTracks?: import("csstype").Property.AlignTracks | undefined;
21
22
  alignmentBaseline?: import("csstype").Property.AlignmentBaseline | undefined;
@@ -142,6 +143,7 @@ export declare function Inline<T extends ElementTag = "div">({ as, gap, align, j
142
143
  flexDirection?: import("csstype").Property.FlexDirection | undefined;
143
144
  flexGrow?: import("csstype").Property.FlexGrow | undefined;
144
145
  flexShrink?: import("csstype").Property.FlexShrink | undefined;
146
+ flexWrap: string;
145
147
  float?: import("csstype").Property.Float | undefined;
146
148
  floodColor?: import("csstype").Property.FloodColor | undefined;
147
149
  floodOpacity?: import("csstype").Property.FloodOpacity | undefined;
@@ -199,6 +201,7 @@ export declare function Inline<T extends ElementTag = "div">({ as, gap, align, j
199
201
  insetInlineStart?: import("csstype").Property.InsetInlineStart<string | number> | undefined;
200
202
  interpolateSize?: import("csstype").Property.InterpolateSize | undefined;
201
203
  isolation?: import("csstype").Property.Isolation | undefined;
204
+ justifyContent: import("csstype").Property.JustifyContent | undefined;
202
205
  justifyItems?: import("csstype").Property.JustifyItems | undefined;
203
206
  justifySelf?: import("csstype").Property.JustifySelf | undefined;
204
207
  justifyTracks?: import("csstype").Property.JustifyTracks | undefined;
@@ -467,6 +470,7 @@ export declare function Inline<T extends ElementTag = "div">({ as, gap, align, j
467
470
  flex?: import("csstype").Property.Flex<string | number> | undefined;
468
471
  flexFlow?: import("csstype").Property.FlexFlow | undefined;
469
472
  font?: import("csstype").Property.Font | undefined;
473
+ gap: import("csstype").Property.Gap<string | number>;
470
474
  grid?: import("csstype").Property.Grid | undefined;
471
475
  gridArea?: import("csstype").Property.GridArea | undefined;
472
476
  gridColumn?: import("csstype").Property.GridColumn | undefined;
@@ -867,9 +871,5 @@ export declare function Inline<T extends ElementTag = "div">({ as, gap, align, j
867
871
  colorInterpolation?: import("csstype").Property.ColorInterpolation | undefined;
868
872
  colorRendering?: import("csstype").Property.ColorRendering | undefined;
869
873
  glyphOrientationVertical?: import("csstype").Property.GlyphOrientationVertical | undefined;
870
- gap: import("csstype").Property.Gap<string | number>;
871
- alignItems: import("csstype").Property.AlignItems;
872
- justifyContent: import("csstype").Property.JustifyContent | undefined;
873
- flexWrap: string;
874
874
  };
875
- } & Omit<InlineProps<T>, "align" | "as" | "children" | "className" | "gap" | "justify" | "style" | "wrap">, string | import("react").JSXElementConstructor<any>>;
875
+ } & Omit<InlineProps<T>, "gap" | "style" | "className" | "children" | "wrap" | "justify" | "as" | "align">, string | import("react").JSXElementConstructor<any>>;
@@ -1,44 +1,46 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useLocale } from "../../localization.js";
3
4
  import { ChartFrame, cellLabel, cellNumber, chartKeys, chartTooltip, seriesColor, useChart } from "../../charts/chart.js";
4
5
  import { niceTicks } from "../../lib/math.js";
5
6
  /** Lines for change over time: one to four series, each labeled directly at its end. */
6
7
  export function LineChart(props) {
7
- const c = useChart(props);
8
- const data = props.data || [];
8
+ const { messages } = useLocale(props.locale);
9
+ const { setPlotElement, width, active, setActive, fmt, series, xKey } = useChart(props);
10
+ const data = props.data;
9
11
  const height = props.height || 240;
10
- const label = c.series.length <= 4 && props.directLabels !== false;
12
+ const label = series.length <= 4 && props.directLabels !== false;
11
13
  const pad = { top: 12, right: label ? 96 : 12, bottom: 28, left: 48 };
12
14
  let max = 0;
13
15
  for (const d of data)
14
- for (const s of c.series)
16
+ for (const s of series)
15
17
  max = Math.max(max, cellNumber(d, s.key));
16
- const ticks = niceTicks(max, 4), top = ticks[ticks.length - 1];
17
- const plotW = Math.max(10, c.width - pad.left - pad.right), plotH = height - pad.top - pad.bottom;
18
+ const ticks = niceTicks(max, 4), top = ticks.at(-1) ?? 1;
19
+ const plotW = Math.max(10, width - pad.left - pad.right), plotH = height - pad.top - pad.bottom;
18
20
  const x = (i) => pad.left + (data.length < 2 ? plotW / 2 : (plotW * i) / (data.length - 1));
19
21
  const y = (v) => pad.top + plotH - (v / top) * plotH;
20
- const fmtTick = props.tickFormat || c.fmt;
22
+ const fmtTick = props.tickFormat || fmt;
21
23
  // Label every nth point so x labels stay about 72px apart.
22
24
  const every = Math.max(1, Math.ceil(data.length / Math.max(2, Math.floor(plotW / 72))));
23
- const view = { ...props, data, series: c.series, format: c.fmt, xKey: c.xKey };
25
+ const view = { ...props, data, series, format: fmt, xKey };
24
26
  const lastY = [];
25
27
  const onMouseMove = (e) => {
26
28
  const r = e.currentTarget.getBoundingClientRect(), px = e.clientX - r.left;
27
29
  const i = Math.round(((px - pad.left) / plotW) * (data.length - 1));
28
- c.setActive(Math.max(0, Math.min(data.length - 1, i)));
30
+ setActive(Math.max(0, Math.min(data.length - 1, i)));
29
31
  };
30
- return (_jsx(ChartFrame, { ...view, children: _jsxs("div", { ref: c.ref, className: "vk-chart-plot", tabIndex: 0, role: "img", "aria-label": (props.title || "Line chart") + ". Use the arrow keys to read each value.", onKeyDown: chartKeys(c, data.length), onMouseLeave: () => c.setActive(null), onBlur: () => c.setActive(null), onMouseMove: onMouseMove, children: [_jsxs("svg", { width: c.width, height: height, viewBox: "0 0 " + c.width + " " + height, "aria-hidden": "true", className: "vk-chart-svg", children: [ticks.map((t) => (_jsxs("g", { children: [_jsx("line", { x1: pad.left, x2: pad.left + plotW, y1: y(t), y2: y(t), className: t === 0 ? "vk-chart-baseline" : "vk-chart-grid" }), _jsx("text", { x: pad.left - 8, y: y(t), dy: "0.32em", textAnchor: "end", className: "vk-chart-tick", children: fmtTick(t) })] }, t))), data.map((d, i) => i % every === 0 || i === data.length - 1 ? _jsx("text", { x: x(i), y: height - 8, textAnchor: i === 0 ? "start" : i === data.length - 1 ? "end" : "middle", className: "vk-chart-tick", children: cellLabel(d, c.xKey) }, "x" + i) : null), c.active != null ? _jsx("line", { x1: x(c.active), x2: x(c.active), y1: pad.top, y2: pad.top + plotH, className: "vk-chart-crosshair" }) : null, c.series.map((s, si) => {
31
- const pts = data.map((d, i) => x(i) + "," + y(cellNumber(d, s.key))).join(" ");
32
+ return (_jsx(ChartFrame, { ...view, children: _jsxs("div", { ref: setPlotElement, className: "vk-chart-plot", tabIndex: 0, role: "img", "aria-label": messages.chartInstructions(props.title || messages.lineChart), onKeyDown: chartKeys({ active, setActive }, data.length), onMouseLeave: () => { setActive(null); }, onBlur: () => { setActive(null); }, onMouseMove: onMouseMove, children: [_jsxs("svg", { width: width, height: height, viewBox: `0 0 ${String(width)} ${String(height)}`, "aria-hidden": "true", className: "vk-chart-svg", children: [ticks.map((t) => (_jsxs("g", { children: [_jsx("line", { x1: pad.left, x2: pad.left + plotW, y1: y(t), y2: y(t), className: t === 0 ? "vk-chart-baseline" : "vk-chart-grid" }), _jsx("text", { x: pad.left - 8, y: y(t), dy: "0.32em", textAnchor: "end", className: "vk-chart-tick", children: fmtTick(t) })] }, t))), data.map((d, i) => i % every === 0 || i === data.length - 1 ? _jsx("text", { x: x(i), y: height - 8, textAnchor: i === 0 ? "start" : i === data.length - 1 ? "end" : "middle", className: "vk-chart-tick", children: cellLabel(d, xKey) }, `x${String(i)}`) : null), active != null ? _jsx("line", { x1: x(active), x2: x(active), y1: pad.top, y2: pad.top + plotH, className: "vk-chart-crosshair" }) : null, series.map((s, si) => {
33
+ const pts = data.map((d, i) => `${String(x(i))},${String(y(cellNumber(d, s.key)))}`).join(" ");
32
34
  return _jsx("polyline", { points: pts, fill: "none", stroke: seriesColor(si), strokeWidth: 2, strokeLinejoin: "round", strokeLinecap: "round" }, s.key);
33
- }), c.series.map((s, si) => {
35
+ }), series.map((s, si) => {
34
36
  // A point on each line at the active row, or at the last one.
35
- const i = c.active == null ? data.length - 1 : c.active;
37
+ const i = active == null ? data.length - 1 : active;
36
38
  const d = data[i];
37
39
  if (!d)
38
40
  return null;
39
41
  return _jsx("circle", { cx: x(i), cy: y(cellNumber(d, s.key)), r: 4, fill: seriesColor(si), className: "vk-chart-point" }, "p" + s.key);
40
42
  }), label
41
- ? c.series.map((s) => {
43
+ ? series.map((s) => {
42
44
  const d = data[data.length - 1];
43
45
  if (!d)
44
46
  return null;
@@ -49,5 +51,5 @@ export function LineChart(props) {
49
51
  lastY.push(ly);
50
52
  return _jsx("text", { x: x(data.length - 1) + 10, y: ly, dy: "0.32em", className: "vk-chart-direct", children: s.label }, "l" + s.key);
51
53
  })
52
- : null] }), chartTooltip(view, c.active, c.active == null ? 0 : x(c.active), c.width)] }) }));
54
+ : null] }), chartTooltip(view, active, active == null ? 0 : x(active), width)] }) }));
53
55
  }
@@ -4,7 +4,7 @@ export type LinkComponent = ElementType<{
4
4
  href: string;
5
5
  className?: string;
6
6
  children?: ReactNode;
7
- } & Record<string, unknown>>;
7
+ } & Record<string, unknown>, "a">;
8
8
  export interface LinkProviderProps {
9
9
  component: LinkComponent;
10
10
  children?: ReactNode;
@@ -8,14 +8,18 @@ export const LinkContext = createContext(null);
8
8
  * Hash, external, mailto: and tel: links, and links with target or download, stay plain <a>.
9
9
  */
10
10
  export function LinkProvider({ component, children }) {
11
- return _jsx(LinkContext.Provider, { value: component || null, children: children });
11
+ return _jsx(LinkContext.Provider, { value: component, children: children });
12
12
  }
13
13
  /** Hash links, links with a scheme (https:, mailto:, tel:) and protocol-relative links. */
14
14
  export const PLAIN_HREF = /^(#|[a-z][a-z0-9+.-]*:|\/\/)/i;
15
+ /** The router adapter is an existing component type supplied by the provider. */
16
+ const RouterAnchor = forwardRef(function RouterAnchor({ component: Component, href, ...props }, ref) {
17
+ return _jsx(Component, { ...props, href: href, ref: ref });
18
+ });
15
19
  /** The <a> behind every link in the system: the LinkProvider's component for internal links, else a plain <a>. */
16
20
  export const Anchor = forwardRef(function Anchor(props, ref) {
17
21
  const Comp = useContext(LinkContext);
18
22
  if (!Comp || typeof props.href !== "string" || PLAIN_HREF.test(props.href) || props.target || props.download)
19
23
  return _jsx("a", { ref: ref, ...props });
20
- return _jsx(Comp, { ref: ref, ...props });
24
+ return _jsx(RouterAnchor, { component: Comp, ...props, href: props.href, ref: ref });
21
25
  });
@@ -1,4 +1,4 @@
1
- import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { Anchor } from "../LinkProvider/LinkProvider.js";
3
3
  import { cx } from "../../lib/cx.js";
4
4
  /** Rows of records: people, files, notifications, recent items. */
@@ -1,4 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { createElement } from "react";
2
3
  import { Badge } from "../Badge/Badge.js";
3
4
  import { Icon } from "../Icon/Icon.js";
4
5
  import { Anchor } from "../LinkProvider/LinkProvider.js";
@@ -6,8 +7,7 @@ import { cx } from "../../lib/cx.js";
6
7
  import { para } from "../../lib/text.js";
7
8
  // The text under the image.
8
9
  function MediaCardBody({ title, eyebrow, meta, description, badge, href, linkLabel, outlined }) {
9
- const Description = para(description);
10
- return (_jsxs("div", { className: "vk-media-card-body", children: [eyebrow ? _jsx("span", { className: "vk-card-eyebrow", children: eyebrow }) : null, _jsxs("span", { className: cx(outlined ? "vk-card-title" : "vk-media-card-title", "vk-media-title-row"), children: [title, badge ? _jsx(Badge, { children: badge }) : null] }), meta ? _jsx("span", { className: "vk-media-card-meta", children: meta }) : null, description ? (_jsx(Description, { className: outlined ? "vk-card-body" : "vk-media-card-services", children: description })) : null, href && linkLabel ? (_jsxs("span", { className: "vk-media-card-link", children: [_jsx("span", { children: linkLabel }), _jsx(Icon, { name: "arrow-up-right", className: "vk-media-card-arrow" })] })) : null] }));
10
+ return (_jsxs("div", { className: "vk-media-card-body", children: [eyebrow ? _jsx("span", { className: "vk-card-eyebrow", children: eyebrow }) : null, _jsxs("span", { className: cx(outlined ? "vk-card-title" : "vk-media-card-title", "vk-media-title-row"), children: [title, badge ? _jsx(Badge, { children: badge }) : null] }), meta ? _jsx("span", { className: "vk-media-card-meta", children: meta }) : null, description ? (createElement(para(description), { className: outlined ? "vk-card-body" : "vk-media-card-services" }, description)) : null, href && linkLabel ? (_jsxs("span", { className: "vk-media-card-link", children: [_jsx("span", { children: linkLabel }), _jsx(Icon, { name: "arrow-up-right", className: "vk-media-card-arrow" })] })) : null] }));
11
11
  }
12
12
  // With an href the whole card is one link; external links open in a new tab.
13
13
  function MediaCardWrap({ href, children }) {
@@ -1,53 +1,16 @@
1
1
  "use client";
2
- import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { useRef, useState } from "react";
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { useLocale } from "../../localization.js";
4
4
  import { DropdownMenu as Primitive } from "radix-ui";
5
5
  import { Icon } from "../Icon/Icon.js";
6
- import { focusables } from "../../internal/focusables.js";
7
6
  import { cx } from "../../lib/cx.js";
8
- import { MenuEntries, useDeferredSelect, useFocusOnOpen, moveFocusNow } from "./entries.js";
7
+ import { MenuEntries } from "./entries.js";
9
8
  /** Menu button (WAI-ARIA), built on Radix DropdownMenu. */
10
9
  export function Menu({ items, label, icon, triggerLabel, variant, size, align, disabled, className }) {
11
- const [open, setOpen] = useState(false);
12
- // Which item takes focus as the menu opens: the last one after ↑ on the trigger, else the first.
13
- const openWith = useRef("first");
14
- // Set when Tab closed the menu: focus moves on from the trigger in that direction.
15
- const tabOut = useRef(0);
16
- const triggerRef = useRef(null);
17
- const { defer, flush } = useDeferredSelect();
18
- const { arm, onFocus } = useFocusOnOpen();
19
- const onOpenChange = (next) => {
20
- arm(next ? openWith.current : null);
21
- setOpen(next);
22
- };
10
+ const { messages } = useLocale();
23
11
  // An icon with no label makes an icon button, named by triggerLabel.
24
12
  const iconOnly = label ? undefined : icon;
25
- return (_jsx("div", { className: cx("vk-menu-root", className), children: _jsxs(Primitive.Root, { open: open, onOpenChange: onOpenChange, modal: false, children: [_jsx(Primitive.Trigger, { ref: triggerRef, disabled: disabled, className: iconOnly ? "vk-icon-btn vk-icon-btn-" + (variant || "ghost") : cx("vk-btn", "vk-btn-" + (variant || "outline"), size === "sm" ? "vk-btn-sm" : null), "aria-label": iconOnly ? triggerLabel || "More actions" : undefined, title: iconOnly ? triggerLabel || "More actions" : undefined, onPointerDown: () => { openWith.current = "first"; }, onKeyDown: (e) => {
26
- openWith.current = "first";
27
- if (e.key === "ArrowUp" && !disabled) {
28
- e.preventDefault();
29
- openWith.current = "last";
30
- onOpenChange(true);
31
- }
32
- }, children: iconOnly
13
+ return (_jsx("div", { className: cx("vk-menu-root", className), children: _jsxs(Primitive.Root, { children: [_jsx(Primitive.Trigger, { disabled: disabled, className: iconOnly ? "vk-icon-btn vk-icon-btn-" + (variant || "ghost") : cx("vk-btn", "vk-btn-" + (variant || "outline"), size === "sm" ? "vk-btn-sm" : null), "aria-label": iconOnly ? triggerLabel || messages.moreActions : undefined, title: iconOnly ? triggerLabel || messages.moreActions : undefined, children: iconOnly
33
14
  ? _jsx(Icon, { name: iconOnly })
34
- : _jsxs(_Fragment, { children: [_jsxs("span", { className: "vk-btn-label", children: [icon ? _jsx(Icon, { name: icon, size: 16, className: "vk-menu-trigger-icon" }) : null, label] }), _jsx("span", { className: "vk-btn-glyph", "aria-hidden": "true", children: _jsx(Icon, { name: "chevron-down", size: 14 }) })] }) }), _jsx(Primitive.Portal, { children: _jsx(Primitive.Content, { className: "vk-menu", side: "bottom", align: align === "end" ? "end" : "start", sideOffset: 4, collisionPadding: 8, loop: true, onFocus: onFocus, onKeyDownCapture: moveFocusNow, onCloseAutoFocus: (e) => {
35
- const dir = tabOut.current;
36
- tabOut.current = 0;
37
- if (dir) {
38
- // Tab closes the menu and moves on from the trigger, as if focus had stayed there.
39
- e.preventDefault();
40
- const trigger = triggerRef.current;
41
- const list = focusables(document.body);
42
- const at = trigger ? list.indexOf(trigger) : -1;
43
- (list[at + dir] || trigger)?.focus();
44
- }
45
- flush();
46
- }, onKeyDown: (e) => {
47
- if (e.key === "Tab") {
48
- e.preventDefault();
49
- tabOut.current = e.shiftKey ? -1 : 1;
50
- onOpenChange(false);
51
- }
52
- }, children: _jsx(MenuEntries, { parts: Primitive, items: items || [], defer: defer }) }) })] }) }));
15
+ : _jsxs(_Fragment, { children: [_jsxs("span", { className: "vk-btn-label", children: [icon ? _jsx(Icon, { name: icon, size: 16, className: "vk-menu-trigger-icon" }) : null, label] }), _jsx("span", { className: "vk-btn-glyph", "aria-hidden": "true", children: _jsx(Icon, { name: "chevron-down", size: 14 }) })] }) }), _jsx(Primitive.Portal, { children: _jsx(Primitive.Content, { className: "vk-menu", side: "bottom", align: align === "end" ? "end" : "start", sideOffset: 4, collisionPadding: 8, children: _jsx(MenuEntries, { parts: Primitive, items: items }) }) })] }) }));
53
16
  }
@@ -1,4 +1,3 @@
1
- import { type FocusEvent, type KeyboardEvent } from "react";
2
1
  import type { DropdownMenu } from "radix-ui";
3
2
  import type { MenuEntry } from "../../types.js";
4
3
  /** The Radix menu parts the entries are built from: DropdownMenu's or ContextMenu's (same shapes). */
@@ -6,35 +5,7 @@ export type MenuParts = Pick<typeof DropdownMenu, "Item" | "CheckboxItem" | "Rad
6
5
  interface MenuEntriesProps {
7
6
  parts: MenuParts;
8
7
  items: MenuEntry[];
9
- /** Runs a plain item's onSelect once the menu has closed and focus has gone back (see useDeferredSelect). */
10
- defer: (run: () => void) => void;
11
8
  }
12
- /**
13
- * Plain items' onSelect runs after the menu has closed and focus is back on the trigger,
14
- * so an action that opens a dialog captures the trigger as its return focus.
15
- * `defer` queues the action; call `flush` from the content's onCloseAutoFocus.
16
- */
17
- export declare function useDeferredSelect(): {
18
- defer: (run: () => void) => void;
19
- flush: () => void;
20
- };
21
- /** Focuses the first or last enabled item of a menu, or the menu itself when none can take focus. */
22
- export declare function focusEdgeItem(content: HTMLElement | null, edge: "first" | "last"): void;
23
- /**
24
- * Radix focuses a menu's content as it opens, and only moves on to the first item when it was
25
- * opened with the keyboard. `arm(edge)` before opening; the content's `onFocus` then moves
26
- * straight to the first (or last) item, however the menu was opened.
27
- */
28
- export declare function useFocusOnOpen(): {
29
- arm: (which: "first" | "last" | null) => void;
30
- onFocus: (e: FocusEvent<HTMLDivElement>) => void;
31
- };
32
- /**
33
- * onKeyDownCapture for a menu's content (root or submenu): ↓ ↑ Home End move focus in the same
34
- * keystroke, wrapping. Radix's roving focus moves it a task later (setTimeout), which lets a
35
- * key that follows at once act on the old item.
36
- */
37
- export declare function moveFocusNow(e: KeyboardEvent<HTMLDivElement>): void;
38
9
  /** Renders MenuEntry[] as Radix menu parts: items, checkbox and radio items, submenus, separators and labels. */
39
- export declare function MenuEntries({ parts: P, items, defer }: MenuEntriesProps): import("react/jsx-runtime").JSX.Element;
10
+ export declare function MenuEntries({ parts: P, items }: MenuEntriesProps): import("react/jsx-runtime").JSX.Element;
40
11
  export {};
@@ -1,92 +1,14 @@
1
1
  "use client";
2
- import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { Fragment, useCallback, useId, useRef, useState } from "react";
2
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { Fragment, useId } from "react";
4
4
  import { Icon } from "../Icon/Icon.js";
5
5
  import { cx } from "../../lib/cx.js";
6
- /**
7
- * Plain items' onSelect runs after the menu has closed and focus is back on the trigger,
8
- * so an action that opens a dialog captures the trigger as its return focus.
9
- * `defer` queues the action; call `flush` from the content's onCloseAutoFocus.
10
- */
11
- export function useDeferredSelect() {
12
- const pending = useRef(null);
13
- const defer = useCallback((run) => { pending.current = run; }, []);
14
- const flush = useCallback(() => {
15
- const run = pending.current;
16
- pending.current = null;
17
- // After Radix has moved focus back (it does so right after the onCloseAutoFocus handlers).
18
- if (run)
19
- queueMicrotask(run);
20
- }, []);
21
- return { defer, flush };
22
- }
23
- /** Focuses the first or last enabled item of a menu, or the menu itself when none can take focus. */
24
- export function focusEdgeItem(content, edge) {
25
- if (!content)
26
- return;
27
- const items = Array.from(content.querySelectorAll('[role^="menuitem"]:not([data-disabled])'));
28
- const target = edge === "last" ? items[items.length - 1] : items[0];
29
- (target || content).focus({ preventScroll: true });
30
- }
31
- /**
32
- * Radix focuses a menu's content as it opens, and only moves on to the first item when it was
33
- * opened with the keyboard. `arm(edge)` before opening; the content's `onFocus` then moves
34
- * straight to the first (or last) item, however the menu was opened.
35
- */
36
- export function useFocusOnOpen() {
37
- const edge = useRef(null);
38
- const arm = useCallback((which) => { edge.current = which; }, []);
39
- const onFocus = useCallback((e) => {
40
- const which = edge.current;
41
- if (!which || e.target !== e.currentTarget)
42
- return;
43
- edge.current = null;
44
- // Skips Radix's own entry focus (composed after this handler), which would pick the first item.
45
- e.preventDefault();
46
- focusEdgeItem(e.currentTarget, which);
47
- }, []);
48
- return { arm, onFocus };
49
- }
50
- const STEP = { ArrowDown: 1, ArrowUp: -1, Home: "first", End: "last", PageUp: "first", PageDown: "last" };
51
- /**
52
- * onKeyDownCapture for a menu's content (root or submenu): ↓ ↑ Home End move focus in the same
53
- * keystroke, wrapping. Radix's roving focus moves it a task later (setTimeout), which lets a
54
- * key that follows at once act on the old item.
55
- */
56
- export function moveFocusNow(e) {
57
- const step = STEP[e.key];
58
- if (step === undefined || e.metaKey || e.ctrlKey || e.altKey || e.shiftKey)
59
- return;
60
- const content = e.currentTarget;
61
- const target = e.target;
62
- // Keys from a submenu bubble through the React tree (portals included); each level handles its own.
63
- if (target.closest('[role="menu"]') !== content)
64
- return;
65
- const items = Array.from(content.querySelectorAll('[role^="menuitem"]:not([data-disabled])'));
66
- if (!items.length)
67
- return;
68
- const at = items.indexOf(target);
69
- let next;
70
- if (step === "first")
71
- next = items[0];
72
- else if (step === "last")
73
- next = items[items.length - 1];
74
- else if (at < 0)
75
- next = step === 1 ? items[0] : items[items.length - 1];
76
- else
77
- next = items[(at + step + items.length) % items.length];
78
- // Prevented, so Radix's own (deferred) handlers for the same key stand down.
79
- e.preventDefault();
80
- next.focus();
81
- }
82
6
  function Body({ icon, label, shortcut, sub }) {
83
7
  return (_jsxs(_Fragment, { children: [icon ? _jsx(Icon, { name: icon, size: 16, className: "vk-menu-item-icon" }) : _jsx("span", { className: "vk-menu-item-icon", "aria-hidden": "true" }), _jsx("span", { className: "vk-menu-item-label", children: label }), shortcut ? _jsx("kbd", { className: "vk-menu-shortcut", children: shortcut }) : null, sub ? _jsx(Icon, { name: "chevron-right", size: 14, className: "vk-menu-sub-icon" }) : null] }));
84
8
  }
85
- /** A submenu. Esc closes just this level and goes back to its item, like ← (Radix would close every level). */
86
- function SubEntry({ parts: P, entry, items, defer }) {
87
- const [open, setOpen] = useState(false);
88
- const triggerRef = useRef(null);
89
- return (_jsxs(P.Sub, { open: open, onOpenChange: setOpen, children: [_jsx(P.SubTrigger, { ref: triggerRef, className: cx("vk-menu-item", entry.danger ? "vk-menu-item-danger" : null), disabled: entry.disabled, textValue: entry.label, children: _jsx(Body, { icon: entry.icon, label: entry.label, shortcut: entry.shortcut, sub: true }) }), _jsx(P.Portal, { children: _jsx(P.SubContent, { className: "vk-menu vk-menu-sub", sideOffset: -4, alignOffset: -5, collisionPadding: 8, loop: true, onKeyDownCapture: moveFocusNow, onEscapeKeyDown: (e) => { e.preventDefault(); setOpen(false); triggerRef.current?.focus(); }, children: _jsx(MenuEntries, { parts: P, items: items, defer: defer }) }) })] }));
9
+ /** The primitive owns submenu opening, keyboard navigation and dismissal. */
10
+ function SubEntry({ parts: P, entry, items }) {
11
+ return (_jsxs(P.Sub, { children: [_jsx(P.SubTrigger, { className: cx("vk-menu-item", entry.danger ? "vk-menu-item-danger" : null), disabled: entry.disabled, textValue: entry.label, children: _jsx(Body, { icon: entry.icon, label: entry.label, shortcut: entry.shortcut, sub: true }) }), _jsx(P.Portal, { children: _jsx(P.SubContent, { className: "vk-menu vk-menu-sub", sideOffset: -4, alignOffset: -5, collisionPadding: 8, children: _jsx(MenuEntries, { parts: P, items: items }) }) })] }));
90
12
  }
91
13
  /** Splits entries into single entries and runs of consecutive radio entries. */
92
14
  function segments(items) {
@@ -107,40 +29,34 @@ function segments(items) {
107
29
  /** Consecutive radio entries as one group; `start` is the first one's index in the menu. */
108
30
  function RadioRun({ parts: P, run, start, labelledBy }) {
109
31
  const checked = run.findIndex((r) => r.checked);
110
- return (_jsx(P.RadioGroup, { value: checked >= 0 ? String(start + checked) : "", "aria-labelledby": labelledBy, children: run.map((r, k) => (_jsxs(P.RadioItem, { value: String(start + k), className: "vk-menu-item", disabled: r.disabled, textValue: r.label,
111
- // Choosing a radio item keeps the menu open.
112
- onSelect: (e) => { e.preventDefault(); r.onSelect?.(); }, children: [_jsx("span", { className: "vk-menu-item-icon vk-menu-check", "aria-hidden": "true", children: _jsx(P.ItemIndicator, { asChild: true, children: _jsx("span", { className: "vk-choice-dot vk-menu-dot" }) }) }), _jsx("span", { className: "vk-menu-item-label", children: r.label })] }, k + ":" + r.label))) }));
32
+ return (_jsx(P.RadioGroup, { value: checked >= 0 ? String(start + checked) : "", "aria-labelledby": labelledBy, children: run.map((r, k) => (_jsxs(P.RadioItem, { value: String(start + k), className: "vk-menu-item", disabled: r.disabled, textValue: r.label, onSelect: r.onSelect, children: [_jsx("span", { className: "vk-menu-item-icon vk-menu-check", "aria-hidden": "true", children: _jsx(P.ItemIndicator, { asChild: true, children: _jsx("span", { className: "vk-choice-dot vk-menu-dot" }) }) }), _jsx("span", { className: "vk-menu-item-label", children: r.label })] }, String(k) + ":" + r.label))) }));
113
33
  }
114
34
  function CheckboxItem({ parts: P, entry: it }) {
115
- return (_jsxs(P.CheckboxItem, { className: "vk-menu-item", checked: it.checked, disabled: it.disabled, textValue: it.label,
116
- // Keeps the menu open; onCheckedChange first, then onSelect (Radix's own onCheckedChange is unused).
117
- onSelect: (e) => { e.preventDefault(); it.onCheckedChange?.(!it.checked); it.onSelect?.(); }, children: [_jsx("span", { className: "vk-menu-item-icon vk-menu-check", "aria-hidden": "true", children: _jsx(P.ItemIndicator, { className: "vk-menu-indicator", children: _jsx(Icon, { name: "check", size: 16 }) }) }), _jsx("span", { className: "vk-menu-item-label", children: it.label })] }));
35
+ return (_jsxs(P.CheckboxItem, { className: "vk-menu-item", checked: it.checked, disabled: it.disabled, textValue: it.label, onCheckedChange: it.onCheckedChange, onSelect: it.onSelect, children: [_jsx("span", { className: "vk-menu-item-icon vk-menu-check", "aria-hidden": "true", children: _jsx(P.ItemIndicator, { className: "vk-menu-indicator", children: _jsx(Icon, { name: "check", size: 16 }) }) }), _jsx("span", { className: "vk-menu-item-label", children: it.label })] }));
118
36
  }
119
- function PlainItem({ parts: P, entry: it, defer }) {
120
- const onSelect = it.onSelect;
121
- return (_jsx(P.Item, { className: cx("vk-menu-item", it.danger ? "vk-menu-item-danger" : null), disabled: it.disabled, textValue: it.label, onSelect: () => { if (onSelect)
122
- defer(() => onSelect()); }, children: _jsx(Body, { icon: it.icon, label: it.label, shortcut: it.shortcut }) }));
37
+ function PlainItem({ parts: P, entry: it }) {
38
+ return (_jsx(P.Item, { className: cx("vk-menu-item", it.danger ? "vk-menu-item-danger" : null), disabled: it.disabled, textValue: it.label, onSelect: it.onSelect, children: _jsx(Body, { icon: it.icon, label: it.label, shortcut: it.shortcut }) }));
123
39
  }
124
40
  /** Renders MenuEntry[] as Radix menu parts: items, checkbox and radio items, submenus, separators and labels. */
125
- export function MenuEntries({ parts: P, items, defer }) {
41
+ export function MenuEntries({ parts: P, items }) {
126
42
  const uid = useId();
127
43
  return (_jsx(Fragment, { children: segments(items).map((s) => {
128
- const first = items[s.at];
129
- const key = s.at + ":" + ("label" in first ? first.label : first.type);
44
+ const first = "run" in s ? s.run[0] : s.entry;
45
+ const key = String(s.at) + ":" + ("label" in first ? first.label : first.type);
130
46
  if ("run" in s) {
131
47
  // A label right before a radio group names it.
132
48
  const prev = items[s.at - 1];
133
- return _jsx(RadioRun, { parts: P, run: s.run, start: s.at, labelledBy: prev && prev.type === "label" ? uid + "-l" + (s.at - 1) : undefined }, key);
49
+ return _jsx(RadioRun, { parts: P, run: s.run, start: s.at, labelledBy: prev?.type === "label" ? uid + "-l" + String(s.at - 1) : undefined }, key);
134
50
  }
135
51
  const it = s.entry;
136
52
  if (it.type === "separator")
137
53
  return _jsx(P.Separator, { className: "vk-menu-separator" }, key);
138
54
  if (it.type === "label")
139
- return _jsx(P.Label, { id: uid + "-l" + s.at, className: "vk-menu-label", children: it.label }, key);
55
+ return _jsx(P.Label, { id: uid + "-l" + String(s.at), className: "vk-menu-label", children: it.label }, key);
140
56
  if (it.type === "checkbox")
141
57
  return _jsx(CheckboxItem, { parts: P, entry: it }, key);
142
58
  if (it.items)
143
- return _jsx(SubEntry, { parts: P, entry: it, items: it.items, defer: defer }, key);
144
- return _jsx(PlainItem, { parts: P, entry: it, defer: defer }, key);
59
+ return _jsx(SubEntry, { parts: P, entry: it, items: it.items }, key);
60
+ return _jsx(PlainItem, { parts: P, entry: it }, key);
145
61
  }) }));
146
62
  }