@momoi-labs/kiso-react 0.8.1 → 0.10.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/README.md CHANGED
@@ -68,6 +68,8 @@ Controls and forms
68
68
  field. Each chip reads as a call: scope, name, value, then one segment per
69
69
  option as name=value or name=[a, b].
70
70
  - ValidationMessage, for a field error referenced by `aria-describedby`.
71
+ - FilterInput, for typed field/operator/value conditions, IN lists, and nested
72
+ AND/OR groups. ChipInput keeps its existing API for structured stored values.
71
73
 
72
74
  Data and structure
73
75
 
@@ -84,6 +86,8 @@ Data and structure
84
86
  - LogView, LogViewLine, LogViewTime, and LogViewLevel.
85
87
  - StepList, a run's steps with a state each, and StepBar, the same run as
86
88
  one segment per step for a summary, a table cell, or a toast.
89
+ - Lifecycle, a detail screen's status, verbs and destructive action in one
90
+ row, and StatusBadge, a state in one of three tones.
87
91
  - Stat, StatHeader, StatLabel, StatValue, StatFoot, and StatDelta.
88
92
  - KV, KVKey, and KVValue, a description list of fixed facts.
89
93
  - Separator, horizontal or vertical, and Dot and `dotVariants`.
@@ -99,7 +103,8 @@ Navigation
99
103
  - Tabs, TabsList, TabsTrigger, TabsContent.
100
104
  - ThemeSelector, a controlled selector. The application owns theme persistence
101
105
  and applies `data-theme="light"` or `data-theme="dark"` to the document root.
102
- Remove the attribute for system mode.
106
+ Remove the attribute for system mode. The default `variant="compact"` uses
107
+ icons. Set `variant="cards"` for labeled options with light and dark previews.
103
108
  - AccentSelector, a controlled selector, plus the `accents` list and `Accent`
104
109
  type. The application owns accent persistence and applies
105
110
  `data-accent="<name>"` to the document root, or to any container that should
@@ -148,6 +153,45 @@ the package owns the repeated Sidebar, Navigation, Header, and main
148
153
  arrangement. With `layout="topbar"`, omit navigation and footer: brand and
149
154
  primary action move into Header beside the existing header slot.
150
155
 
156
+ Add `collapsible` to let the user reduce the sidebar to compact navigation.
157
+ Use destination `leading` slots for icons. The toggle preserves accessible
158
+ names, the active destination, and keyboard focus. `defaultCollapsed` sets the
159
+ initial state; `collapsed` with `onCollapsedChange` lets the product control or
160
+ persist the preference. On narrow screens the navigation keeps its labels and
161
+ returns to the chosen state when the viewport widens. Existing appearance
162
+ settings apply to both states.
163
+
164
+ PageHeader accepts `variant="editorial"` for a larger responsive title and
165
+ more space around the heading.
166
+ AppShell and ApplicationShell accept `variant="inset"` to put the main content
167
+ inside a frame with space around it. These options work independently and
168
+ preserve the current Appearance settings.
169
+
170
+ Set `data-visual-style="editorial"` on `html` to share the editorial hierarchy
171
+ across headings, cards, metrics, and page layouts. Buttons, fields, and tables
172
+ keep their existing density. A region with `data-visual-style="default"` keeps
173
+ the compact composition. The earlier `data-page-header` attribute still works
174
+ for heading-only styling.
175
+
176
+ `data-app-shell="inset"` chooses the application frame independently.
177
+ PageHeader and AppShell follow these preferences when `variant` is omitted;
178
+ an explicit `variant` overrides the corresponding treatment. Without
179
+ preferences, the existing heading sizes, spacing, and frame remain the default.
180
+
181
+ ```tsx
182
+ <ApplicationShell variant="inset" collapsible brand={brand} navigation={groups}>
183
+ <div className="page">
184
+ <PageHeader variant="editorial" actions={<Button>Deploy application</Button>}>
185
+ <PageHeaderTitle>Your homelab</PageHeaderTitle>
186
+ <PageHeaderDescription>
187
+ Applications, machines, and images in one place.
188
+ </PageHeaderDescription>
189
+ </PageHeader>
190
+ {content}
191
+ </div>
192
+ </ApplicationShell>
193
+ ```
194
+
151
195
  Navigation, Sidebar, and Link know nothing about routing. Mark the current
152
196
  destination with `active`, and pass `asChild` to render a router's own link
153
197
  component. CommandPalette is controlled: it owns the overlay, focus, and its
@@ -203,10 +247,44 @@ import { BrandMark, TerminalIcon } from '@momoi-labs/kiso-react';
203
247
  </div>
204
248
  ```
205
249
 
250
+ ## Structured filters
251
+
252
+ `FilterInput` turns completed conditions into editable chips. The application
253
+ supplies a field schema and owns the confirmed filter tree and search results.
254
+
255
+ ```tsx
256
+ import { useState } from 'react';
257
+ import { FilterInput, type FilterField, type FilterNode } from '@momoi-labs/kiso-react';
258
+
259
+ const fields: FilterField[] = [
260
+ { key: 'status', type: 'text', values: ['active', 'paused'] },
261
+ { key: 'region', type: 'text', values: ['us', 'eu', 'ap'] },
262
+ { key: 'lag', type: 'number' },
263
+ ];
264
+
265
+ export function ReplicaFilters() {
266
+ const [filters, setFilters] = useState<FilterNode[]>([]);
267
+ return <FilterInput label="Find replicas" fields={fields}
268
+ value={filters} onValueChange={setFilters} />;
269
+ }
270
+ ```
271
+
272
+ Type `status=active ` to create a chip, or
273
+ `(region IN (us, eu,) OR lag>100)` to create a group. Click a chip's field,
274
+ operator, or value to edit that segment. Use Edit expression to change grouping
275
+ across existing chips.
276
+
277
+ `parseFilterExpression` validates saved text against the schema;
278
+ `serializeFilterExpression` converts the confirmed tree back to text. The
279
+ component does not execute queries. Products own server validation and
280
+ parameterized query translation. See the
281
+ [FilterInput contract](../../kiso/docs/components/filter-input.md) for syntax,
282
+ draft handling, keyboard behavior, and mobile states.
283
+
206
284
  ## Development
207
285
 
208
286
  From the repository root, run `npm ci`, then `npm run prototype`. The component
209
- gallery opens at <http://127.0.0.1:5173/#components> and covers all 44 Kiso
287
+ gallery opens at <http://127.0.0.1:5173/#components> and covers the Kiso
210
288
  catalog entries, each rendering the component this package exports. Its sample
211
289
  data is simulated in memory.
212
290
 
@@ -1,5 +1,7 @@
1
1
  import * as React from "react";
2
- declare function AppShell({ className, ...props }: React.ComponentProps<"div">): React.JSX.Element;
2
+ declare function AppShell({ className, variant, ...props }: React.ComponentProps<"div"> & {
3
+ variant?: "default" | "inset";
4
+ }): React.JSX.Element;
3
5
  declare function AppShellMain({ className, ...props }: React.ComponentProps<"main">): React.JSX.Element;
4
6
  type ApplicationShellDestination = {
5
7
  href: string;
@@ -25,12 +27,20 @@ type ApplicationShellSidebarProps = ApplicationShellSharedProps & {
25
27
  navigation: readonly ApplicationShellGroup[];
26
28
  navigationLabel?: string;
27
29
  footer?: React.ReactNode;
30
+ collapsible?: boolean;
31
+ collapsed?: boolean;
32
+ defaultCollapsed?: boolean;
33
+ onCollapsedChange?: (collapsed: boolean) => void;
28
34
  };
29
35
  type ApplicationShellTopbarProps = ApplicationShellSharedProps & {
30
36
  layout: "topbar";
31
37
  navigation?: never;
32
38
  navigationLabel?: never;
33
39
  footer?: never;
40
+ collapsible?: never;
41
+ collapsed?: never;
42
+ defaultCollapsed?: never;
43
+ onCollapsedChange?: never;
34
44
  };
35
45
  type ApplicationShellProps = ApplicationShellSidebarProps | ApplicationShellTopbarProps;
36
46
  declare function ApplicationShell(props: ApplicationShellProps): React.JSX.Element;
package/dist/app-shell.js CHANGED
@@ -1,30 +1,55 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ // Adapted from shadcn/ui new-york-v4. See ../SHADCN-LICENSE.
2
+ "use client";
3
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
4
+ import * as React from "react";
2
5
  import { clsx as cn } from "clsx";
6
+ import { Button } from "./button.js";
3
7
  import { Header } from "./header.js";
8
+ import { useIsomorphicLayoutEffect } from "./use-isomorphic-layout-effect.js";
4
9
  import { Navigation, NavigationGroup, NavigationItem, NavigationLink, NavigationList, } from "./navigation.js";
5
10
  import { Sidebar, SidebarBody, SidebarFooter, SidebarHeader } from "./sidebar.js";
6
- function AppShell({ className, ...props }) {
7
- return (_jsx("div", { "data-slot": "app-shell", className: cn("app-shell", className), ...props }));
11
+ function AppShell({ className, variant, ...props }) {
12
+ return (_jsx("div", { "data-slot": "app-shell", "data-variant": variant, className: cn("app-shell", className), ...props }));
8
13
  }
9
14
  /* `grow` carries the `min-width: 0` the main column needs so a wide table or
10
15
  log line cannot push the sidebar off the screen. */
11
16
  function AppShellMain({ className, ...props }) {
12
17
  return (_jsx("main", { "data-slot": "app-shell-main", className: cn("grow", className), ...props }));
13
18
  }
14
- function ApplicationShellNavigation({ navigation, navigationLabel, }) {
15
- return (_jsx(Navigation, { "aria-label": navigationLabel, children: navigation.map((group, groupIndex) => (_jsx(NavigationGroup, { label: group.label, children: group.destinations.length > 0 ? (_jsx(NavigationList, { children: group.destinations.map((destination, destinationIndex) => (_jsx(NavigationItem, { children: _jsxs(NavigationLink, { href: destination.href, active: destination.active, onClick: (event) => {
19
+ function ApplicationShellNavigation({ navigation, navigationLabel, collapsible = false, }) {
20
+ return (_jsx(Navigation, { "aria-label": navigationLabel, children: navigation.map((group, groupIndex) => (_jsx(NavigationGroup, { label: group.label, children: group.destinations.length > 0 ? (_jsx(NavigationList, { children: group.destinations.map((destination, destinationIndex) => (_jsx(NavigationItem, { children: _jsx(NavigationLink, { href: destination.href, active: destination.active, className: collapsible && destination.leading ? "sidebar-link-with-icon" : undefined, title: collapsible && typeof destination.label === "string" ? destination.label : undefined, onClick: (event) => {
16
21
  if (!destination.onClick)
17
22
  return;
18
23
  event.preventDefault();
19
24
  destination.onClick();
20
- }, children: [destination.leading, _jsx("span", { className: "grow truncate", children: destination.label }), destination.trailing] }) }, `${destination.href}-${destinationIndex}`))) })) : (group.empty) }, group.label ?? groupIndex))) }));
25
+ }, children: collapsible ? _jsxs(_Fragment, { children: [destination.leading && _jsx("span", { className: "sidebar-link-icon", "aria-hidden": "true", children: destination.leading }), _jsx("span", { className: "sidebar-link-label grow truncate", children: destination.label }), destination.trailing && _jsx("span", { className: "sidebar-link-trailing", children: destination.trailing })] }) : _jsxs(_Fragment, { children: [destination.leading, _jsx("span", { className: "grow truncate", children: destination.label }), destination.trailing] }) }) }, `${destination.href}-${destinationIndex}`))) })) : (group.empty) }, group.label ?? groupIndex))) }));
21
26
  }
22
27
  function ApplicationShell(props) {
23
28
  if (props.layout === "topbar") {
24
29
  const { brand, primaryAction, header, children, layout: _layout, ...shellProps } = props;
25
30
  return (_jsx(AppShell, { ...shellProps, "data-layout": "topbar", children: _jsxs(AppShellMain, { children: [_jsxs(Header, { children: [brand, primaryAction, header] }), children] }) }));
26
31
  }
27
- const { brand, primaryAction, navigation, navigationLabel = "Primary", footer, header, children, layout: _layout, ...shellProps } = props;
28
- return (_jsxs(AppShell, { ...shellProps, children: [_jsxs(Sidebar, { children: [_jsxs(SidebarHeader, { children: [brand, primaryAction] }), _jsx(SidebarBody, { children: _jsx(ApplicationShellNavigation, { navigation: navigation, navigationLabel: navigationLabel }) }), footer && _jsx(SidebarFooter, { children: footer })] }), _jsxs(AppShellMain, { children: [header && _jsx(Header, { children: header }), children] })] }));
32
+ return _jsx(ApplicationShellSidebar, { ...props });
33
+ }
34
+ function ApplicationShellSidebar({ brand, primaryAction, navigation, navigationLabel = "Primary", footer, header, children, layout: _layout, collapsible = false, collapsed, defaultCollapsed = false, onCollapsedChange, ...shellProps }) {
35
+ const [internalCollapsed, setInternalCollapsed] = React.useState(defaultCollapsed);
36
+ const isCollapsed = collapsible && (collapsed ?? internalCollapsed);
37
+ const sidebarId = React.useId();
38
+ const sidebarRef = React.useRef(null);
39
+ const toggleRef = React.useRef(null);
40
+ useIsomorphicLayoutEffect(() => {
41
+ const sidebar = sidebarRef.current;
42
+ const focused = sidebar?.ownerDocument.activeElement;
43
+ if (isCollapsed && focused && sidebar?.contains(focused) && !focused.getClientRects().length) {
44
+ toggleRef.current?.focus();
45
+ }
46
+ }, [isCollapsed]);
47
+ function toggleSidebar() {
48
+ const next = !isCollapsed;
49
+ if (collapsed === undefined)
50
+ setInternalCollapsed(next);
51
+ onCollapsedChange?.(next);
52
+ }
53
+ return (_jsxs(AppShell, { ...shellProps, children: [_jsxs(Sidebar, { ref: sidebarRef, id: sidebarId, collapsed: isCollapsed, children: [_jsx(SidebarHeader, { className: collapsible ? "sidebar-header-collapsible" : undefined, children: collapsible ? _jsxs(_Fragment, { children: [_jsxs("div", { className: "sidebar-expanded-content", children: [brand, primaryAction] }), _jsx(Button, { ref: toggleRef, variant: "ghost", size: "sm", className: "sidebar-toggle btn-icon", "aria-controls": sidebarId, "aria-expanded": !isCollapsed, "aria-label": isCollapsed ? "Expand sidebar" : "Collapse sidebar", title: isCollapsed ? "Expand sidebar" : "Collapse sidebar", onClick: toggleSidebar, children: _jsxs("svg", { className: "icon", viewBox: "0 0 16 16", "aria-hidden": "true", children: [_jsx("rect", { x: "1.5", y: "2", width: "13", height: "12", rx: "1.5" }), _jsx("path", { d: "M5.5 2v12" }), _jsx("path", { d: isCollapsed ? "m8.5 5.5 2.5 2.5-2.5 2.5" : "m11 5.5-2.5 2.5 2.5 2.5" })] }) })] }) : _jsxs(_Fragment, { children: [brand, primaryAction] }) }), _jsx(SidebarBody, { children: _jsx(ApplicationShellNavigation, { navigation: navigation, navigationLabel: navigationLabel, collapsible: collapsible }) }), footer && _jsx(SidebarFooter, { className: collapsible ? "sidebar-expanded-content" : undefined, children: footer })] }), _jsxs(AppShellMain, { children: [header && _jsx(Header, { children: header }), children] })] }));
29
54
  }
30
55
  export { AppShell, AppShellMain, ApplicationShell };
@@ -3,7 +3,7 @@ declare function ChipInput({ className, ...props }: React.ComponentProps<"div">)
3
3
  declare function ChipInputBox({ className, disabled, onMouseDown, ...props }: React.ComponentProps<"div"> & {
4
4
  disabled?: boolean;
5
5
  }): React.JSX.Element;
6
- declare function ChipInputField({ className, onKeyDown, onRemoveLast, ...props }: React.ComponentProps<"input"> & {
6
+ declare function ChipInputField({ className, onKeyDown, onChange, onRemoveLast, onCompositionStart, onCompositionEnd, ...props }: React.ComponentProps<"input"> & {
7
7
  onRemoveLast?: () => void;
8
8
  }): React.JSX.Element;
9
9
  declare function ChipInputList({ className, "aria-label": ariaLabel, ...props }: React.ComponentProps<"div">): React.JSX.Element;
@@ -39,5 +39,5 @@ declare function ChipOption({ className, name, value, label, editLabel, confirmL
39
39
  declare function ChipOptionAdd({ className, label, placeholder, editLabel, confirmLabel, ...props }: Omit<React.ComponentProps<typeof EditableSegment>, "slot" | "value" | "display"> & {
40
40
  label: string;
41
41
  }): React.JSX.Element;
42
- declare function ChipRemove({ className, ...props }: React.ComponentProps<"button">): React.JSX.Element;
42
+ declare function ChipRemove({ className, onClick, ...props }: React.ComponentProps<"button">): React.JSX.Element;
43
43
  export { Chip, ChipInput, ChipInputBox, ChipInputEmpty, ChipInputField, ChipInputList, ChipInputOption, ChipName, ChipOption, ChipOptionAdd, ChipRemove, ChipScope, ChipValue, };
@@ -37,35 +37,56 @@ function ChipInputBox({ className, disabled = false, onMouseDown, ...props }) {
37
37
  onMouseDown?.(event);
38
38
  }, ...props }));
39
39
  }
40
- function ChipInputField({ className, onKeyDown, onRemoveLast, ...props }) {
41
- const { activeId, setActiveId, listId, listRef, fieldRef, open } = useChipInput();
40
+ function ChipInputField({ className, onKeyDown, onChange, onRemoveLast, onCompositionStart, onCompositionEnd, ...props }) {
41
+ const { activeId, setActiveId, listId, listRef, fieldRef, open, setOpen } = useChipInput();
42
+ const composing = React.useRef(false);
42
43
  // Typing changes the list under the highlight, so re-anchor it every render
43
44
  // instead of tracking an index the filter invalidates.
44
45
  React.useEffect(() => {
45
- const visible = options(listRef.current);
46
+ const visible = open ? options(listRef.current) : [];
46
47
  if (!visible.some((option) => option.id === activeId)) {
47
48
  setActiveId(visible[0]?.id ?? "");
48
49
  }
49
50
  });
51
+ // Reopening must render the list before scrolling its highlight.
52
+ React.useEffect(() => {
53
+ if (open)
54
+ options(listRef.current).find((option) => option.id === activeId)?.scrollIntoView({ block: "nearest" });
55
+ }, [activeId, open, listRef]);
50
56
  function keys(event) {
51
- const visible = options(listRef.current);
57
+ if (composing.current || event.nativeEvent.isComposing || event.keyCode === 229) {
58
+ event.stopPropagation();
59
+ return;
60
+ }
61
+ const visible = open ? options(listRef.current) : [];
52
62
  const index = visible.findIndex((option) => option.id === activeId);
53
63
  if (event.key === "ArrowDown" || event.key === "ArrowUp") {
54
64
  event.preventDefault();
55
- if (!visible.length)
65
+ const available = options(listRef.current);
66
+ if (!available.length)
56
67
  return;
68
+ setOpen(true);
57
69
  const step = event.key === "ArrowDown" ? 1 : -1;
58
- const next = visible[(index + step + visible.length) % visible.length];
70
+ const next = available[index < 0
71
+ ? (step > 0 ? 0 : available.length - 1)
72
+ : (index + step + available.length) % available.length];
59
73
  setActiveId(next.id);
60
- next.scrollIntoView({ block: "nearest" });
61
74
  }
62
- else if ((event.key === "Enter" || event.key === "Tab") && index >= 0) {
75
+ else if ((event.key === "Enter" || (event.key === "Tab" && !event.shiftKey)) &&
76
+ index >= 0) {
63
77
  // Tab only commits a highlighted suggestion; with none it still leaves
64
78
  // the field, so the box never traps the keyboard. Enter with no
65
79
  // highlight falls through to the product, which may take the query.
66
80
  event.preventDefault();
67
81
  visible[index]?.click();
68
82
  }
83
+ else if (event.key === "Enter" && event.currentTarget.value === "") {
84
+ event.preventDefault();
85
+ }
86
+ else if (event.key === "Escape") {
87
+ setOpen(false);
88
+ setActiveId("");
89
+ }
69
90
  else if (event.key === "Backspace" &&
70
91
  event.currentTarget.value === "" &&
71
92
  onRemoveLast) {
@@ -74,15 +95,25 @@ function ChipInputField({ className, onKeyDown, onRemoveLast, ...props }) {
74
95
  }
75
96
  onKeyDown?.(event);
76
97
  }
77
- return (_jsx("input", { ref: fieldRef, "data-slot": "chip-input-field", role: "combobox", "aria-expanded": open, "aria-controls": listId, "aria-activedescendant": activeId || undefined, "aria-autocomplete": "list", autoComplete: "off", onKeyDown: keys, className: cn("chip-input-field", className), ...props }));
98
+ return (_jsx("input", { ref: fieldRef, "data-slot": "chip-input-field", role: "combobox", "aria-expanded": open, "aria-controls": listId, "aria-activedescendant": open && activeId ? activeId : undefined, "aria-autocomplete": "list", autoComplete: "off", onKeyDown: keys, onChange: (event) => {
99
+ if (listRef.current)
100
+ setOpen(true);
101
+ onChange?.(event);
102
+ }, onCompositionStart: (event) => {
103
+ composing.current = true;
104
+ onCompositionStart?.(event);
105
+ }, onCompositionEnd: (event) => {
106
+ composing.current = false;
107
+ onCompositionEnd?.(event);
108
+ }, className: cn("chip-input-field", className), ...props }));
78
109
  }
79
110
  function ChipInputList({ className, "aria-label": ariaLabel = "Suggestions", ...props }) {
80
- const { listId, listRef, setOpen } = useChipInput();
111
+ const { listId, listRef, open, setOpen } = useChipInput();
81
112
  React.useEffect(() => {
82
113
  setOpen(true);
83
114
  return () => setOpen(false);
84
115
  }, [setOpen]);
85
- return (_jsx("div", { id: listId, ref: listRef, role: "listbox", "aria-label": ariaLabel, "data-slot": "chip-input-list", className: cn("menu chip-input-list", className), ...props }));
116
+ return (_jsx("div", { id: listId, ref: listRef, role: "listbox", hidden: !open, "aria-label": ariaLabel, "data-slot": "chip-input-list", className: cn("menu chip-input-list", className), ...props }));
86
117
  }
87
118
  function ChipInputOption({ className, disabled = false, onSelect, onClick, ...props }) {
88
119
  const id = React.useId();
@@ -108,10 +139,24 @@ function ChipScope({ className, ...props }) {
108
139
  function ChipName({ className, ...props }) {
109
140
  return (_jsx("span", { "data-slot": "chip-name", className: cn("chip-name truncate", className), ...props }));
110
141
  }
142
+ // Resolve the control after the parent's update: adding an option can replace
143
+ // the editor's entire component, so a ref on its old button is not enough.
144
+ function restoreSegmentFocus(editor) {
145
+ const chip = editor?.parentElement;
146
+ if (!chip || !editor)
147
+ return;
148
+ const controls = 'button[data-slot], input[data-slot]';
149
+ const index = Array.from(chip.querySelectorAll(controls)).indexOf(editor);
150
+ requestAnimationFrame(() => {
151
+ chip.querySelectorAll(controls)[index]?.focus();
152
+ });
153
+ }
111
154
  // Every editable segment behaves the same: press it, it becomes an input
112
155
  // sized to its text, Enter or the check confirms, Escape restores.
113
156
  function EditableSegment({ slot, className, value, placeholder, display, onCommit, editable = true, editLabel, confirmLabel, maxWidth = 48, ...props }) {
114
157
  const [draft, setDraft] = React.useState(null);
158
+ const composing = React.useRef(false);
159
+ const editorRef = React.useRef(null);
115
160
  if (!editable || !onCommit) {
116
161
  return (_jsx("span", { "data-slot": slot, className: cn(className), children: value ? (display ?? value) : placeholder }));
117
162
  }
@@ -121,22 +166,27 @@ function EditableSegment({ slot, className, value, placeholder, display, onCommi
121
166
  setDraft(null);
122
167
  }
123
168
  if (draft !== null) {
124
- return (_jsxs(_Fragment, { children: [_jsx("input", { "data-slot": `${slot}-input`, className: cn(className, "is-editing"), "aria-label": editLabel, value: draft, autoFocus: true, size: 1, style: {
169
+ return (_jsxs(_Fragment, { children: [_jsx("input", { ref: editorRef, "data-slot": `${slot}-input`, className: cn(className, "is-editing"), "aria-label": editLabel, value: draft, autoFocus: true, size: 1, style: {
125
170
  width: `${Math.min(Math.max(draft.length + 1, 6), maxWidth)}ch`,
126
- }, onChange: (event) => setDraft(event.target.value), onBlur: () => commit(draft), onKeyDown: (event) => {
171
+ }, onChange: (event) => setDraft(event.target.value), onBlur: () => commit(draft), onCompositionStart: () => { composing.current = true; }, onCompositionEnd: () => { composing.current = false; }, onKeyDown: (event) => {
172
+ event.stopPropagation();
173
+ if (composing.current || event.nativeEvent.isComposing || event.keyCode === 229)
174
+ return;
127
175
  if (event.key === "Enter") {
128
176
  event.preventDefault();
177
+ restoreSegmentFocus(editorRef.current);
129
178
  commit(draft);
130
179
  }
131
180
  else if (event.key === "Escape") {
132
181
  event.preventDefault();
182
+ restoreSegmentFocus(editorRef.current);
133
183
  setDraft(null);
134
184
  }
135
- event.stopPropagation();
136
185
  } }), _jsx("button", { type: "button", className: "chip-action", "aria-label": confirmLabel,
137
186
  // Commit before the input's blur can unmount this button.
138
187
  onMouseDown: (event) => {
139
188
  event.preventDefault();
189
+ restoreSegmentFocus(editorRef.current);
140
190
  commit(draft);
141
191
  }, children: _jsx(CheckIcon, {}) })] }));
142
192
  }
@@ -162,8 +212,19 @@ function ChipOption({ className, name, value, label, editLabel, confirmLabel, ..
162
212
  function ChipOptionAdd({ className, label, placeholder = "+", editLabel, confirmLabel, ...props }) {
163
213
  return (_jsx(EditableSegment, { slot: "chip-option-add", className: cn("chip-option", className), value: "", placeholder: placeholder, editLabel: editLabel ?? `Add an option to ${label}`, confirmLabel: confirmLabel ?? `Confirm the new option on ${label}`, ...props }));
164
214
  }
165
- function ChipRemove({ className, ...props }) {
166
- return (_jsx("button", { type: "button", "data-slot": "chip-remove", className: cn("chip-action", className), ...props, children: _jsx(CloseIcon, {}) }));
215
+ function ChipRemove({ className, onClick, ...props }) {
216
+ return (_jsx("button", { type: "button", "data-slot": "chip-remove", className: cn("chip-action", className), ...props, onClick: (event) => {
217
+ const button = event.currentTarget;
218
+ const root = button.closest('[data-slot="chip-input"]');
219
+ onClick?.(event);
220
+ if (event.defaultPrevented)
221
+ return;
222
+ requestAnimationFrame(() => {
223
+ if (!button.isConnected) {
224
+ root?.querySelector('[data-slot="chip-input-field"]')?.focus();
225
+ }
226
+ });
227
+ }, children: _jsx(CloseIcon, {}) }));
167
228
  }
168
229
  function CheckIcon() {
169
230
  return (_jsx("svg", { className: "icon", viewBox: "0 0 16 16", "aria-hidden": "true", children: _jsx("path", { d: "m3.5 8.5 3 3 6-7" }) }));
@@ -4,7 +4,7 @@ declare function CommandPalette({ className, label, children, ...props }: React.
4
4
  className?: string;
5
5
  label?: string;
6
6
  }): React.JSX.Element;
7
- declare function CommandPaletteInput({ className, onKeyDown, ...props }: React.ComponentProps<"input">): React.JSX.Element;
7
+ declare function CommandPaletteInput({ className, onKeyDown, onCompositionStart, onCompositionEnd, ...props }: React.ComponentProps<"input">): React.JSX.Element;
8
8
  declare function CommandPaletteList({ className, "aria-label": ariaLabel, ...props }: React.ComponentProps<"div">): React.JSX.Element;
9
9
  declare function CommandPaletteGroup({ className, heading, children, ...props }: React.ComponentProps<"div"> & {
10
10
  heading: string;
@@ -20,12 +20,16 @@ function items(list) {
20
20
  }
21
21
  function CommandPalette({ className, label = "Command palette", children, ...props }) {
22
22
  const [activeId, setActiveId] = React.useState("");
23
+ const composing = React.useRef(false);
23
24
  const listId = React.useId();
24
25
  const listRef = React.useRef(null);
25
- return (_jsx(DialogPrimitive.Root, { "data-slot": "command-palette", ...props, children: _jsxs(DialogPortal, { children: [_jsx(DialogOverlay, {}), _jsxs(DialogPrimitive.Content, { "aria-modal": "true", "data-slot": "command-palette-content", className: cn("palette kiso-react-palette", className), children: [_jsx(VisuallyHidden.Root, { asChild: true, children: _jsx(DialogPrimitive.Title, { children: label }) }), _jsx(CommandPaletteContext.Provider, { value: { activeId, setActiveId, listId, listRef }, children: children })] })] }) }));
26
+ return (_jsx(DialogPrimitive.Root, { "data-slot": "command-palette", ...props, children: _jsxs(DialogPortal, { children: [_jsx(DialogOverlay, {}), _jsxs(DialogPrimitive.Content, { "aria-modal": "true", onEscapeKeyDown: (event) => {
27
+ if (composing.current || event.isComposing || event.keyCode === 229)
28
+ event.preventDefault();
29
+ }, "data-slot": "command-palette-content", className: cn("palette kiso-react-palette", className), children: [_jsx(VisuallyHidden.Root, { asChild: true, children: _jsx(DialogPrimitive.Title, { children: label }) }), _jsx(CommandPaletteContext.Provider, { value: { composing, activeId, setActiveId, listId, listRef }, children: children })] })] }) }));
26
30
  }
27
- function CommandPaletteInput({ className, onKeyDown, ...props }) {
28
- const { activeId, setActiveId, listId, listRef } = useCommandPalette();
31
+ function CommandPaletteInput({ className, onKeyDown, onCompositionStart, onCompositionEnd, ...props }) {
32
+ const { composing, activeId, setActiveId, listId, listRef } = useCommandPalette();
29
33
  // The query changes the list under the highlight, so re-anchor it every
30
34
  // render rather than tracking an index that the filter invalidates.
31
35
  React.useEffect(() => {
@@ -35,6 +39,10 @@ function CommandPaletteInput({ className, onKeyDown, ...props }) {
35
39
  }
36
40
  });
37
41
  function move(event) {
42
+ if (composing.current || event.nativeEvent.isComposing || event.keyCode === 229) {
43
+ event.stopPropagation();
44
+ return;
45
+ }
38
46
  const visible = items(listRef.current);
39
47
  const index = visible.findIndex((item) => item.id === activeId);
40
48
  if (event.key === "ArrowDown" || event.key === "ArrowUp") {
@@ -52,7 +60,13 @@ function CommandPaletteInput({ className, onKeyDown, ...props }) {
52
60
  }
53
61
  onKeyDown?.(event);
54
62
  }
55
- return (_jsxs("div", { className: "palette-input", "data-slot": "command-palette-input", children: [_jsxs("svg", { className: "icon muted", viewBox: "0 0 16 16", fill: "none", stroke: "currentColor", "aria-hidden": "true", children: [_jsx("circle", { cx: "7", cy: "7", r: "4.5" }), _jsx("path", { d: "m10.5 10.5 3 3" })] }), _jsx("input", { role: "combobox", "aria-expanded": "true", "aria-controls": listId, "aria-activedescendant": activeId || undefined, "aria-autocomplete": "list", autoComplete: "off", autoFocus: true, onKeyDown: move, className: className, ...props })] }));
63
+ return (_jsxs("div", { className: "palette-input", "data-slot": "command-palette-input", children: [_jsxs("svg", { className: "icon muted", viewBox: "0 0 16 16", fill: "none", stroke: "currentColor", "aria-hidden": "true", children: [_jsx("circle", { cx: "7", cy: "7", r: "4.5" }), _jsx("path", { d: "m10.5 10.5 3 3" })] }), _jsx("input", { role: "combobox", "aria-expanded": "true", "aria-controls": listId, "aria-activedescendant": activeId || undefined, "aria-autocomplete": "list", autoComplete: "off", autoFocus: true, onKeyDown: move, onCompositionStart: (event) => {
64
+ composing.current = true;
65
+ onCompositionStart?.(event);
66
+ }, onCompositionEnd: (event) => {
67
+ composing.current = false;
68
+ onCompositionEnd?.(event);
69
+ }, className: className, ...props })] }));
56
70
  }
57
71
  function CommandPaletteList({ className, "aria-label": ariaLabel = "Commands", ...props }) {
58
72
  const { listId, listRef } = useCommandPalette();
@@ -3,8 +3,8 @@ import { cva } from "class-variance-authority";
3
3
  import { clsx as cn } from "clsx";
4
4
  import { Slot } from "radix-ui";
5
5
  // Emptiness is not an error: the variants change which action belongs here, not
6
- // the colour of the surface.
7
- const emptyStateVariants = cva("empty", {
6
+ // the colour of the surface. The hatch says "this region is not data".
7
+ const emptyStateVariants = cva("empty hatch", {
8
8
  variants: {
9
9
  variant: { "first-run": "", "no-results": "", informational: "" },
10
10
  size: { md: "", sm: "empty-sm" },
@@ -0,0 +1,49 @@
1
+ /** Structured filters. Parsing is opt-in and does not change ChipInput. */
2
+ export type FilterOperator = "=" | "!=" | ">" | ">=" | "<" | "<=" | "IN" | "CONTAINS" | "IS NULL";
3
+ export type FilterScalar = string | number;
4
+ export type FilterJoin = "AND" | "OR";
5
+ export type FilterField = {
6
+ key: string;
7
+ label?: string;
8
+ type: "text" | "number";
9
+ nullable?: boolean;
10
+ operators?: readonly FilterOperator[];
11
+ values?: readonly FilterScalar[];
12
+ };
13
+ export type FilterCondition = {
14
+ kind: "condition";
15
+ field: string;
16
+ operator: FilterOperator;
17
+ value: FilterScalar | FilterScalar[] | null;
18
+ /** The first node's join is ignored. AND binds before OR within each group. */
19
+ join: FilterJoin;
20
+ };
21
+ export type FilterGroup = {
22
+ kind: "group";
23
+ children: FilterNode[];
24
+ join: FilterJoin;
25
+ };
26
+ export type FilterNode = FilterCondition | FilterGroup;
27
+ export type FilterParseResult = {
28
+ ok: true;
29
+ value: FilterNode[];
30
+ } | {
31
+ ok: false;
32
+ error: string;
33
+ };
34
+ export type FilterSuggestion = {
35
+ label: string;
36
+ text: string;
37
+ description: string;
38
+ };
39
+ export declare function filterOperators(field: FilterField): readonly FilterOperator[];
40
+ export declare function formatFilterScalar(value: FilterScalar): string;
41
+ export declare function formatFilterValue(condition: FilterCondition): string;
42
+ export declare function serializeFilterNode(node: FilterNode): string;
43
+ export declare function serializeFilterExpression(nodes: readonly FilterNode[]): string;
44
+ /** Empty input is an empty filter. Incomplete input returns an error without partial results. */
45
+ export declare function parseFilterExpression(source: string, fields: readonly FilterField[], options?: {
46
+ allowLeadingJoin?: boolean;
47
+ }): FilterParseResult;
48
+ /** Suggestions replace only the condition at the end of the draft, including inside groups. */
49
+ export declare function getFilterSuggestions(source: string, fields: readonly FilterField[], existing?: boolean): FilterSuggestion[];