@c9up/nebula 0.1.9 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. package/dist/atoms/Avatar.d.ts +36 -9
  2. package/dist/atoms/Avatar.js +66 -27
  3. package/dist/atoms/index.d.ts +1 -1
  4. package/dist/atoms/index.js +1 -1
  5. package/dist/configure.d.ts +6 -0
  6. package/dist/configure.js +4 -22
  7. package/dist/lib/children.d.ts +30 -0
  8. package/dist/lib/id.d.ts +13 -29
  9. package/dist/lib/id.js +13 -39
  10. package/dist/lib/motion.d.ts +10 -0
  11. package/dist/lib/motion.js +10 -0
  12. package/dist/molecules/Accordion.d.ts +36 -15
  13. package/dist/molecules/Accordion.js +68 -45
  14. package/dist/molecules/Breadcrumb.d.ts +29 -11
  15. package/dist/molecules/Breadcrumb.js +52 -52
  16. package/dist/molecules/Collapsible.d.ts +18 -17
  17. package/dist/molecules/Collapsible.js +42 -34
  18. package/dist/molecules/Field.d.ts +66 -30
  19. package/dist/molecules/Field.js +106 -55
  20. package/dist/molecules/InputGroup.d.ts +39 -21
  21. package/dist/molecules/InputGroup.js +43 -27
  22. package/dist/molecules/InputOTP.d.ts +26 -3
  23. package/dist/molecules/InputOTP.js +109 -76
  24. package/dist/molecules/Message.js +5 -4
  25. package/dist/molecules/Pagination.d.ts +36 -11
  26. package/dist/molecules/Pagination.js +58 -74
  27. package/dist/molecules/RadioGroup.d.ts +25 -17
  28. package/dist/molecules/RadioGroup.js +47 -43
  29. package/dist/molecules/Resizable.d.ts +32 -7
  30. package/dist/molecules/Resizable.js +76 -49
  31. package/dist/molecules/Tabs.d.ts +49 -11
  32. package/dist/molecules/Tabs.js +107 -51
  33. package/dist/molecules/ToggleGroup.d.ts +16 -10
  34. package/dist/molecules/ToggleGroup.js +37 -21
  35. package/dist/molecules/index.d.ts +11 -11
  36. package/dist/molecules/index.js +11 -11
  37. package/dist/organisms/AlertDialog.d.ts +80 -28
  38. package/dist/organisms/AlertDialog.js +192 -67
  39. package/dist/organisms/Carousel.d.ts +25 -3
  40. package/dist/organisms/Carousel.js +75 -43
  41. package/dist/organisms/Combobox.d.ts +2 -1
  42. package/dist/organisms/Combobox.js +46 -16
  43. package/dist/organisms/Command.d.ts +73 -32
  44. package/dist/organisms/Command.js +209 -131
  45. package/dist/organisms/CommandDialog.js +5 -5
  46. package/dist/organisms/ContextMenu.d.ts +41 -19
  47. package/dist/organisms/ContextMenu.js +112 -71
  48. package/dist/organisms/DataTable.js +42 -8
  49. package/dist/organisms/Dialog.d.ts +97 -31
  50. package/dist/organisms/Dialog.js +193 -68
  51. package/dist/organisms/Drawer.d.ts +33 -10
  52. package/dist/organisms/Drawer.js +130 -52
  53. package/dist/organisms/DropdownMenu.d.ts +58 -11
  54. package/dist/organisms/DropdownMenu.js +137 -50
  55. package/dist/organisms/Form.js +9 -11
  56. package/dist/organisms/HoverCard.d.ts +39 -19
  57. package/dist/organisms/HoverCard.js +116 -40
  58. package/dist/organisms/Menubar.d.ts +55 -19
  59. package/dist/organisms/Menubar.js +166 -82
  60. package/dist/organisms/NavigationMenu.d.ts +77 -31
  61. package/dist/organisms/NavigationMenu.js +169 -98
  62. package/dist/organisms/Popover.d.ts +72 -12
  63. package/dist/organisms/Popover.js +132 -25
  64. package/dist/organisms/Questionnaire.js +5 -5
  65. package/dist/organisms/Select.d.ts +99 -18
  66. package/dist/organisms/Select.js +253 -111
  67. package/dist/organisms/Sheet.d.ts +57 -13
  68. package/dist/organisms/Sheet.js +141 -54
  69. package/dist/organisms/Sidebar.d.ts +146 -56
  70. package/dist/organisms/Sidebar.js +236 -128
  71. package/dist/organisms/Tooltip.d.ts +88 -14
  72. package/dist/organisms/Tooltip.js +210 -47
  73. package/dist/organisms/index.d.ts +15 -15
  74. package/dist/organisms/index.js +15 -15
  75. package/dist/primitives/floating.js +25 -0
  76. package/dist/primitives/floatingSurface.d.ts +11 -0
  77. package/dist/primitives/floatingSurface.js +8 -0
  78. package/dist/primitives/menu.d.ts +45 -1
  79. package/dist/primitives/menu.js +45 -14
  80. package/dist/primitives/menuParts.d.ts +113 -0
  81. package/dist/primitives/menuParts.js +207 -0
  82. package/dist/stubs.d.ts +13 -0
  83. package/dist/stubs.js +14 -0
  84. package/nebula.css +1 -1
  85. package/package.json +4 -3
  86. package/registry.json +18 -6
  87. package/src/atoms/Avatar.ts +141 -37
  88. package/src/atoms/index.ts +13 -1
  89. package/src/configure.ts +10 -23
  90. package/src/lib/children.ts +31 -0
  91. package/src/lib/id.ts +11 -39
  92. package/src/lib/motion.ts +12 -0
  93. package/src/molecules/Accordion.ts +120 -60
  94. package/src/molecules/Breadcrumb.ts +77 -76
  95. package/src/molecules/Collapsible.ts +77 -41
  96. package/src/molecules/Field.ts +187 -72
  97. package/src/molecules/InputGroup.ts +88 -35
  98. package/src/molecules/InputOTP.ts +150 -86
  99. package/src/molecules/Message.ts +6 -4
  100. package/src/molecules/Pagination.ts +96 -101
  101. package/src/molecules/RadioGroup.ts +70 -59
  102. package/src/molecules/Resizable.ts +138 -75
  103. package/src/molecules/Tabs.ts +187 -74
  104. package/src/molecules/ToggleGroup.ts +77 -38
  105. package/src/molecules/index.ts +85 -8
  106. package/src/organisms/AlertDialog.ts +319 -82
  107. package/src/organisms/Carousel.ts +129 -52
  108. package/src/organisms/Combobox.ts +64 -19
  109. package/src/organisms/Command.ts +342 -159
  110. package/src/organisms/CommandDialog.ts +6 -6
  111. package/src/organisms/ContextMenu.ts +185 -83
  112. package/src/organisms/DataTable.ts +56 -10
  113. package/src/organisms/Dialog.ts +312 -102
  114. package/src/organisms/Drawer.ts +219 -71
  115. package/src/organisms/DropdownMenu.ts +219 -61
  116. package/src/organisms/Form.ts +48 -34
  117. package/src/organisms/HoverCard.ts +187 -53
  118. package/src/organisms/Menubar.ts +247 -87
  119. package/src/organisms/NavigationMenu.ts +306 -128
  120. package/src/organisms/Popover.ts +215 -39
  121. package/src/organisms/Questionnaire.ts +9 -6
  122. package/src/organisms/Select.ts +397 -130
  123. package/src/organisms/Sheet.ts +252 -83
  124. package/src/organisms/Sidebar.ts +438 -185
  125. package/src/organisms/Tooltip.ts +315 -65
  126. package/src/organisms/index.ts +284 -14
  127. package/src/primitives/floating.ts +33 -0
  128. package/src/primitives/floatingSurface.ts +19 -0
  129. package/src/primitives/menu.ts +79 -18
  130. package/src/primitives/menuParts.ts +371 -0
  131. package/src/stubs.ts +16 -0
  132. package/stubs/config/nebula.stub +21 -0
@@ -1,46 +1,87 @@
1
1
  /**
2
- * Command — a searchable list of actions.
2
+ * Command — the palette: type to filter, arrows to move, Enter to run.
3
3
  *
4
- * The palette pattern: type to filter, arrows to move, Enter to run. Used on
5
- * its own — inside a Popover, a Sheet, or a page — while `CommandDialog` wraps
6
- * this same component in a modal for the full-screen palette.
4
+ * Command({ children: () => html`
5
+ * ${CommandInput({ placeholder: "Search…" })}
6
+ * ${CommandList({ children: () => html`
7
+ * ${CommandEmpty({ children: "Nothing found." })}
8
+ * ${CommandGroup({ heading: "Actions", children: () => html`
9
+ * ${CommandItem({ value: "new", children: "New file", onSelect: create })}
10
+ * ` })}
11
+ * ` })}
12
+ * ` })
7
13
  *
8
- * The filter is the interesting decision. `cmdk`, which shadcn wraps, scores
9
- * matches with a fuzzy algorithm; nebula matches on substring, plus an
10
- * optional `keywords` list per item. Fuzzy matching is impressive on a demo
11
- * and frustrating in use — it surfaces items the user did not type anything
12
- * resembling, and the ranking is impossible to predict. Substring plus
13
- * keywords is predictable, and "s" reaching "Settings" is a keyword, not an
14
- * algorithm.
14
+ * Filtering happens WITHOUT re-rendering. Each item registers itself as it is
15
+ * built and then hides itself when the query stops matching — Aurora never
16
+ * re-runs a component's setup, so a palette that rebuilt its list on every
17
+ * keystroke would lose the DOM the highlight and the scroll position live in.
18
+ * A group hides itself the same way, once none of its own items are showing,
19
+ * so an empty heading never sits over nothing.
15
20
  *
16
- * Focus stays in the search input the whole time; the highlighted item is
17
- * named with `aria-activedescendant`. Moving DOM focus onto the list would
18
- * take it out of the input and the next keystroke would go nowhere.
21
+ * `role="combobox"` on the input with `aria-activedescendant`, and focus never
22
+ * leaves it. The list is a `listbox` whose options are named rather than
23
+ * focused, which is what lets a screen reader read each result as the arrows
24
+ * pass over it while typing continues to work.
19
25
  */
20
- import type { Child } from "../lib/children.js";
26
+ import type { Parts, Slot } from "../lib/children.js";
21
27
  import { type Reactive } from "../lib/props.js";
22
- export interface CommandItem {
23
- /** Stable key. */
28
+ /** What the filter is given. */
29
+ export interface CommandCandidate {
30
+ readonly value: string;
31
+ /** The visible text, or `textValue` when the children are markup. */
32
+ readonly textValue: string;
33
+ /** Extra terms that should match this item. */
34
+ readonly keywords: readonly string[];
35
+ }
36
+ export declare function defaultFilter(candidate: CommandCandidate, query: string): boolean;
37
+ export interface CommandProps {
38
+ /** Replace the built-in substring filter. */
39
+ filter?: (candidate: CommandCandidate, query: string) => boolean;
40
+ onSelect?: (value: string) => void;
41
+ class?: Reactive<string>;
42
+ children?: Parts;
43
+ }
44
+ export declare const Command: (props?: CommandProps | undefined) => import("@c9up/aurora").TemplateResult;
45
+ export interface CommandInputProps {
46
+ placeholder?: string;
47
+ class?: Reactive<string>;
48
+ }
49
+ export declare const CommandInput: (props?: CommandInputProps | undefined) => import("@c9up/aurora").TemplateResult;
50
+ export interface CommandListProps {
51
+ children?: Parts;
52
+ class?: Reactive<string>;
53
+ }
54
+ export declare const CommandList: (props?: CommandListProps | undefined) => import("@c9up/aurora").TemplateResult;
55
+ export interface CommandEmptyProps {
56
+ children?: Slot;
57
+ class?: Reactive<string>;
58
+ }
59
+ /** Shown when the query matches nothing. Hidden, not removed — see `Command`. */
60
+ export declare const CommandEmpty: (props?: CommandEmptyProps | undefined) => import("@c9up/aurora").TemplateResult;
61
+ export interface CommandGroupProps {
62
+ heading?: Slot;
63
+ children?: Parts;
64
+ class?: Reactive<string>;
65
+ }
66
+ export declare const CommandGroup: (props?: CommandGroupProps | undefined) => import("@c9up/aurora").TemplateResult;
67
+ export interface CommandItemProps {
24
68
  value: string;
25
- label: string;
26
- icon?: Child;
69
+ children?: Slot;
70
+ /** What the filter matches, when the children are markup. */
71
+ textValue?: string;
27
72
  /** Extra terms that should match this item. */
28
73
  keywords?: readonly string[];
29
- shortcut?: string;
30
74
  disabled?: boolean;
31
- group?: string;
32
75
  onSelect?: () => void;
76
+ class?: Reactive<string>;
33
77
  }
34
- export interface CommandProps {
35
- items: readonly CommandItem[];
36
- placeholder?: string;
37
- /** Shown when the filter matches nothing. */
38
- emptyMessage?: Child;
39
- /** Replace the built-in substring filter. */
40
- filter?: (item: CommandItem, query: string) => boolean;
78
+ export declare const CommandItem: (props?: CommandItemProps | undefined) => import("@c9up/aurora").TemplateResult;
79
+ export interface CommandSeparatorProps {
41
80
  class?: Reactive<string>;
42
- onSelect?: (item: CommandItem) => void;
43
81
  }
44
- /** Substring over the label, then over each keyword. */
45
- export declare function defaultFilter(item: CommandItem, query: string): boolean;
46
- export declare const Command: (props?: CommandProps | undefined) => import("@c9up/aurora").TemplateResult;
82
+ export declare const CommandSeparator: (props?: CommandSeparatorProps | undefined) => import("@c9up/aurora").TemplateResult;
83
+ export interface CommandShortcutProps {
84
+ children?: Slot;
85
+ class?: Reactive<string>;
86
+ }
87
+ export declare const CommandShortcut: (props?: CommandShortcutProps | undefined) => import("@c9up/aurora").TemplateResult;
@@ -1,53 +1,91 @@
1
1
  /**
2
- * Command — a searchable list of actions.
2
+ * Command — the palette: type to filter, arrows to move, Enter to run.
3
3
  *
4
- * The palette pattern: type to filter, arrows to move, Enter to run. Used on
5
- * its own — inside a Popover, a Sheet, or a page — while `CommandDialog` wraps
6
- * this same component in a modal for the full-screen palette.
4
+ * Command({ children: () => html`
5
+ * ${CommandInput({ placeholder: "Search…" })}
6
+ * ${CommandList({ children: () => html`
7
+ * ${CommandEmpty({ children: "Nothing found." })}
8
+ * ${CommandGroup({ heading: "Actions", children: () => html`
9
+ * ${CommandItem({ value: "new", children: "New file", onSelect: create })}
10
+ * ` })}
11
+ * ` })}
12
+ * ` })
7
13
  *
8
- * The filter is the interesting decision. `cmdk`, which shadcn wraps, scores
9
- * matches with a fuzzy algorithm; nebula matches on substring, plus an
10
- * optional `keywords` list per item. Fuzzy matching is impressive on a demo
11
- * and frustrating in use — it surfaces items the user did not type anything
12
- * resembling, and the ranking is impossible to predict. Substring plus
13
- * keywords is predictable, and "s" reaching "Settings" is a keyword, not an
14
- * algorithm.
14
+ * Filtering happens WITHOUT re-rendering. Each item registers itself as it is
15
+ * built and then hides itself when the query stops matching — Aurora never
16
+ * re-runs a component's setup, so a palette that rebuilt its list on every
17
+ * keystroke would lose the DOM the highlight and the scroll position live in.
18
+ * A group hides itself the same way, once none of its own items are showing,
19
+ * so an empty heading never sits over nothing.
15
20
  *
16
- * Focus stays in the search input the whole time; the highlighted item is
17
- * named with `aria-activedescendant`. Moving DOM focus onto the list would
18
- * take it out of the input and the next keystroke would go nowhere.
21
+ * `role="combobox"` on the input with `aria-activedescendant`, and focus never
22
+ * leaves it. The list is a `listbox` whose options are named rather than
23
+ * focused, which is what lets a screen reader read each result as the arrows
24
+ * pass over it while typing continues to work.
19
25
  */
20
- import { component, html, signal } from "@c9up/aurora";
26
+ import { component, createContext, html, inject, provide, signal, } from "@c9up/aurora";
27
+ import { slot } from "../lib/children.js";
21
28
  import { cn } from "../lib/cn.js";
22
29
  import { SearchIcon } from "../lib/icons.js";
23
30
  import { uid } from "../lib/id.js";
24
31
  import { read } from "../lib/props.js";
25
- /** Substring over the label, then over each keyword. */
26
- export function defaultFilter(item, query) {
32
+ export function defaultFilter(candidate, query) {
27
33
  if (query === "")
28
34
  return true;
29
35
  const needle = query.toLowerCase();
30
- if (item.label.toLowerCase().includes(needle))
36
+ if (candidate.textValue.toLowerCase().includes(needle))
31
37
  return true;
32
- return (item.keywords ?? []).some((keyword) => keyword.toLowerCase().includes(needle));
38
+ return candidate.keywords.some((keyword) => keyword.toLowerCase().includes(needle));
33
39
  }
40
+ const CommandContext = createContext("Command");
41
+ /**
42
+ * Which group an item belongs to.
43
+ *
44
+ * Defaulted rather than required: an item outside any group is ordinary, so
45
+ * there is nothing to raise about.
46
+ */
47
+ const CommandGroupContext = createContext("CommandGroup", undefined);
34
48
  export const Command = component((props) => {
35
49
  const inputId = uid("command-input");
36
50
  const listId = uid("command-list");
51
+ const items = [];
52
+ /** Per instance, not per module: two palettes may offer the same value. */
37
53
  const itemIds = new Map();
38
- for (const item of props.items)
39
- itemIds.set(item.value, uid("command-item"));
40
54
  const query = signal("");
41
- const active = signal(undefined);
55
+ function itemId(value) {
56
+ let id = itemIds.get(value);
57
+ if (id === undefined) {
58
+ id = uid("command-item");
59
+ itemIds.set(value, id);
60
+ }
61
+ return id;
62
+ }
63
+ /**
64
+ * The highlighted value, or `undefined` for "the first match".
65
+ *
66
+ * DERIVED rather than seeded at registration. Writing it while the items
67
+ * registered would be a signal write during the render that is building
68
+ * them, and a surface rebuilds its content inside an effect — the write
69
+ * re-entered that effect and the palette recursed until the stack gave out.
70
+ * Nothing needs the value stored before the user moves.
71
+ */
72
+ const explicitActive = signal(undefined);
73
+ function active() {
74
+ const chosen = explicitActive();
75
+ if (chosen !== undefined)
76
+ return chosen;
77
+ return matches()[0]?.value;
78
+ }
42
79
  function matches() {
43
80
  const filter = props.filter ?? defaultFilter;
44
- return props.items.filter((item) => item.disabled !== true && filter(item, query()));
81
+ return items.filter((item) => !item.disabled && filter(item, query()));
45
82
  }
46
- function run(item) {
47
- if (item.disabled === true)
83
+ function run(value) {
84
+ const item = items.find((entry) => entry.value === value);
85
+ if (item === undefined || item.disabled)
48
86
  return;
49
- item.onSelect?.();
50
- props.onSelect?.(item);
87
+ item.run();
88
+ props.onSelect?.(value);
51
89
  }
52
90
  function move(delta) {
53
91
  const list = matches();
@@ -58,114 +96,154 @@ export const Command = component((props) => {
58
96
  // Wrapping is right here, unlike in a menu: a palette is a search result
59
97
  // list and the user is scanning it, not navigating a fixed structure.
60
98
  const target = list[(next + list.length) % list.length];
61
- if (target !== undefined) {
62
- active(target.value);
63
- scrollIntoView(target.value);
64
- }
65
- }
66
- function scrollIntoView(value) {
67
- const id = itemIds.get(value);
68
- if (id === undefined)
69
- return;
70
- document.getElementById(id)?.scrollIntoView({ block: "nearest" });
71
- }
72
- function onKeyDown(event) {
73
- if (event.key === "ArrowDown") {
74
- event.preventDefault();
75
- move(1);
76
- }
77
- else if (event.key === "ArrowUp") {
78
- event.preventDefault();
79
- move(-1);
80
- }
81
- else if (event.key === "Enter") {
82
- event.preventDefault();
83
- const current = matches().find((item) => item.value === active());
84
- if (current !== undefined)
85
- run(current);
86
- }
87
- }
88
- function onInput(event) {
89
- const target = event.target;
90
- if (!(target instanceof HTMLInputElement))
99
+ if (target === undefined)
91
100
  return;
92
- query(target.value);
93
- // Re-point the highlight at the first result: leaving it on an item the
94
- // new query filtered out means Enter runs something invisible.
95
- active(matches()[0]?.value);
101
+ explicitActive(target.value);
102
+ document.getElementById(target.id)?.scrollIntoView({ block: "nearest" });
96
103
  }
104
+ provide(CommandContext, {
105
+ inputId,
106
+ listId,
107
+ query: () => query(),
108
+ active,
109
+ setActive: (value) => explicitActive(value),
110
+ itemId,
111
+ register(item) {
112
+ items.push({ ...item, id: itemId(item.value) });
113
+ },
114
+ isVisible(value) {
115
+ return matches().some((item) => item.value === value);
116
+ },
117
+ groupHasMatches(groupId) {
118
+ return matches().some((item) => item.groupId === groupId);
119
+ },
120
+ hasMatches: () => matches().length > 0,
121
+ run,
122
+ onInput(event) {
123
+ const target = event.target;
124
+ if (!(target instanceof HTMLInputElement))
125
+ return;
126
+ query(target.value);
127
+ // Back to "the first match": leaving the highlight on an item the new
128
+ // query filtered out means Enter runs something invisible.
129
+ explicitActive(undefined);
130
+ },
131
+ onKeyDown(event) {
132
+ if (event.key === "ArrowDown") {
133
+ event.preventDefault();
134
+ move(1);
135
+ }
136
+ else if (event.key === "ArrowUp") {
137
+ event.preventDefault();
138
+ move(-1);
139
+ }
140
+ else if (event.key === "Enter") {
141
+ event.preventDefault();
142
+ const current = active();
143
+ if (current !== undefined && matches().some((i) => i.value === current))
144
+ run(current);
145
+ }
146
+ },
147
+ });
97
148
  return html `<div
98
149
  data-slot="command"
99
150
  class="${() => cn("bg-popover text-popover-foreground flex size-full flex-col overflow-hidden rounded-md", read(props.class))}"
100
- >
101
- <div data-slot="command-input-wrapper" class="flex h-9 items-center gap-2 border-b px-3">
102
- ${SearchIcon({ class: "size-4 shrink-0 opacity-50" })}
103
- <input
104
- data-slot="command-input"
105
- id="${inputId}"
106
- type="text"
107
- role="combobox"
108
- autocomplete="off"
109
- aria-expanded="true"
110
- aria-controls="${listId}"
111
- aria-activedescendant="${() => {
112
- const current = active();
113
- return current === undefined ? undefined : itemIds.get(current);
151
+ >${props.children?.()}</div>`;
152
+ });
153
+ export const CommandInput = component((props) => {
154
+ const command = inject(CommandContext);
155
+ return html `<div
156
+ data-slot="command-input-wrapper"
157
+ class="flex h-9 items-center gap-2 border-b px-3"
158
+ >${SearchIcon({ class: "size-4 shrink-0 opacity-50" })}<input
159
+ data-slot="command-input"
160
+ id="${command.inputId}"
161
+ type="text"
162
+ role="combobox"
163
+ autocomplete="off"
164
+ aria-expanded="true"
165
+ aria-controls="${command.listId}"
166
+ aria-activedescendant="${() => {
167
+ const current = command.active();
168
+ return current === undefined ? undefined : command.itemId(current);
114
169
  }}"
115
- placeholder="${props.placeholder ?? "Type a command or search…"}"
116
- class="placeholder:text-muted-foreground flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-none disabled:cursor-not-allowed disabled:opacity-50"
117
- @input="${onInput}"
118
- @keydown="${onKeyDown}"
119
- />
120
- </div>
121
- <div
122
- data-slot="command-list"
123
- id="${listId}"
124
- role="listbox"
125
- class="max-h-[300px] scroll-py-1 overflow-x-hidden overflow-y-auto p-1"
126
- >
127
- ${() => renderResults()}
128
- </div>
129
- </div>`;
130
- function renderResults() {
131
- const list = matches();
132
- if (list.length === 0) {
133
- return html `<div
134
- data-slot="command-empty"
135
- role="presentation"
136
- class="py-6 text-center text-sm"
137
- >${props.emptyMessage ?? "No results found."}</div>`;
138
- }
139
- let lastGroup;
140
- return list.map((item) => {
141
- const heading = item.group !== undefined && item.group !== lastGroup
142
- ? html `<div
143
- role="presentation"
144
- class="text-muted-foreground px-2 py-1.5 text-xs font-medium"
145
- >${item.group}</div>`
146
- : null;
147
- lastGroup = item.group;
148
- return [heading, renderItem(item)];
149
- });
150
- }
151
- function renderItem(item) {
152
- return html `<div
153
- role="option"
154
- data-slot="command-item"
155
- id="${itemIds.get(item.value)}"
156
- aria-selected="${() => (active() === item.value ? "true" : "false")}"
157
- data-active="${() => (active() === item.value ? "" : undefined)}"
158
- class="relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none data-[active]:bg-accent data-[active]:text-accent-foreground [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4"
159
- @click="${() => run(item)}"
160
- @pointerenter="${() => active(item.value)}"
161
- >
162
- ${item.icon}
163
- <span class="flex-1 truncate">${item.label}</span>
164
- ${item.shortcut === undefined
165
- ? null
166
- : html `<span class="text-muted-foreground ml-auto text-xs tracking-widest"
167
- >${item.shortcut}</span
168
- >`}
169
- </div>`;
170
- }
170
+ placeholder="${props.placeholder ?? "Type a command or search…"}"
171
+ class="${() => cn("placeholder:text-muted-foreground flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-hidden disabled:cursor-not-allowed disabled:opacity-50", read(props.class))}"
172
+ @input="${(event) => command.onInput(event)}"
173
+ @keydown="${(event) => command.onKeyDown(event)}"
174
+ /></div>`;
175
+ });
176
+ export const CommandList = component((props) => {
177
+ const command = inject(CommandContext);
178
+ return html `<div
179
+ data-slot="command-list"
180
+ id="${command.listId}"
181
+ role="listbox"
182
+ class="${() => cn("max-h-[300px] scroll-py-1 overflow-x-hidden overflow-y-auto p-1", read(props.class))}"
183
+ >${props.children?.()}</div>`;
184
+ });
185
+ /** Shown when the query matches nothing. Hidden, not removed — see `Command`. */
186
+ export const CommandEmpty = component((props) => {
187
+ const command = inject(CommandContext);
188
+ return html `<div
189
+ data-slot="command-empty"
190
+ role="presentation"
191
+ ?hidden="${() => command.hasMatches()}"
192
+ class="${() => cn("py-6 text-center text-sm", read(props.class))}"
193
+ >${slot(props.children)}</div>`;
194
+ });
195
+ export const CommandGroup = component((props) => {
196
+ const command = inject(CommandContext);
197
+ const groupId = uid("command-group");
198
+ provide(CommandGroupContext, { groupId });
199
+ const rows = props.children?.();
200
+ return html `<div
201
+ data-slot="command-group"
202
+ role="group"
203
+ ?hidden="${() => !command.groupHasMatches(groupId)}"
204
+ class="${() => cn("text-foreground overflow-hidden p-1", read(props.class))}"
205
+ >${props.heading === undefined
206
+ ? null
207
+ : html `<div
208
+ role="presentation"
209
+ class="text-muted-foreground px-2 py-1.5 text-xs font-medium"
210
+ >${slot(props.heading)}</div>`}${rows}</div>`;
211
+ });
212
+ export const CommandItem = component((props) => {
213
+ const command = inject(CommandContext);
214
+ const group = inject(CommandGroupContext);
215
+ const children = props.children;
216
+ const id = command.itemId(props.value);
217
+ command.register({
218
+ value: props.value,
219
+ textValue: props.textValue ??
220
+ (typeof children === "string" ? children : props.value),
221
+ keywords: props.keywords ?? [],
222
+ disabled: props.disabled === true,
223
+ groupId: group?.groupId,
224
+ run: () => props.onSelect?.(),
225
+ });
226
+ const chosen = () => command.active() === props.value;
227
+ return html `<div
228
+ data-slot="command-item"
229
+ id="${id}"
230
+ role="option"
231
+ ?hidden="${() => !command.isVisible(props.value)}"
232
+ aria-selected="${() => (chosen() ? "true" : "false")}"
233
+ aria-disabled="${props.disabled === true ? "true" : undefined}"
234
+ data-active="${() => (chosen() ? "" : undefined)}"
235
+ data-disabled="${props.disabled === true ? "" : undefined}"
236
+ class="${() => cn("relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[active]:bg-accent data-[active]:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4", read(props.class))}"
237
+ @click="${() => command.run(props.value)}"
238
+ @pointerenter="${() => command.setActive(props.value)}"
239
+ >${slot(children)}</div>`;
171
240
  });
241
+ export const CommandSeparator = component((props) => html `<div
242
+ data-slot="command-separator"
243
+ role="separator"
244
+ class="${() => cn("bg-border -mx-1 h-px", read(props.class))}"
245
+ ></div>`);
246
+ export const CommandShortcut = component((props) => html `<span
247
+ data-slot="command-shortcut"
248
+ class="${() => cn("text-muted-foreground ml-auto text-xs tracking-widest", read(props.class))}"
249
+ >${slot(props.children)}</span>`);
@@ -64,8 +64,8 @@ export const CommandDialog = component((props) => {
64
64
  function close() {
65
65
  state.set(false);
66
66
  }
67
- function runAndClose(item) {
68
- props.onSelect?.(item);
67
+ function runAndClose(value) {
68
+ props.onSelect?.(value);
69
69
  // Closing after the action, not before: a handler that opens another
70
70
  // surface should not have this one tearing down focus underneath it.
71
71
  close();
@@ -100,11 +100,11 @@ export const CommandDialog = component((props) => {
100
100
  ? null
101
101
  : html `<p id="${descriptionId}" class="sr-only">${props.description}</p>`}
102
102
  ${Command({
103
- items: props.items,
104
- placeholder: props.placeholder,
105
- emptyMessage: props.emptyMessage,
106
103
  filter: props.filter,
107
104
  onSelect: runAndClose,
105
+ // Passed straight through: `Command` calls it inside its own
106
+ // setup, which is where the parts find its context.
107
+ children: props.children,
108
108
  })}
109
109
  </div>
110
110
  </div>`,
@@ -1,29 +1,51 @@
1
1
  /**
2
- * ContextMenu — a menu opened by right-clicking a region.
2
+ * ContextMenu — the menu a right-click opens.
3
3
  *
4
- * Same panel as DropdownMenu; the difference is the anchor. There is no
5
- * trigger element to position against — the menu belongs at the pointer, which
6
- * could be anywhere inside the region.
4
+ * ContextMenu({ children: () => html`
5
+ * ${ContextMenuTrigger({ children: "Right-click me" })}
6
+ * ${ContextMenuContent({ children: () => html`
7
+ * ${ContextMenuItem({ children: "Cut", onSelect: cut })}
8
+ * ` })}
9
+ * ` })
7
10
  *
8
- * So a zero-size element is parked at the click coordinates and used as the
9
- * anchor. It is a real element on purpose: `autoPosition` measures its rect,
10
- * and that rect flips and shifts exactly like a button's would, which is what
11
- * gets a menu opened near the bottom of the window to open upwards instead of
12
- * off screen.
11
+ * The rows come from `createMenuParts`, so a context menu and a dropdown menu
12
+ * cannot drift apart. What is specific here is the anchor: a context menu
13
+ * opens at the POINTER, not against a control, so a zero-size element is moved
14
+ * to the click coordinates and the surface is positioned against that.
13
15
  *
14
- * Long-press opens it on touch, where there is no right button. The 500ms
15
- * threshold matches the platform convention, and any movement cancels it so a
16
- * scroll gesture does not surface a menu.
16
+ * Touch gets a long press, because there is no right button. It is cancelled
17
+ * by movement, so a scroll that starts on the region does not open a menu
18
+ * under the thumb.
17
19
  */
18
- import { type Slot } from "../lib/children.js";
20
+ import { type TemplateResult } from "@c9up/aurora";
21
+ import type { Parts, Slot } from "../lib/children.js";
19
22
  import { type Reactive } from "../lib/props.js";
20
- import { type MenuEntry } from "../primitives/menu.js";
21
23
  export interface ContextMenuProps {
22
- /** The region that answers to right-click. */
23
- children?: Slot;
24
- entries: readonly MenuEntry[];
25
24
  onOpenChange?: (open: boolean) => void;
25
+ children?: Parts;
26
+ }
27
+ export declare const ContextMenu: (props?: ContextMenuProps | undefined) => TemplateResult;
28
+ export interface ContextMenuTriggerProps {
29
+ children?: Slot;
30
+ class?: Reactive<string>;
31
+ }
32
+ /** The region that answers to right-click, and the anchor the menu opens at. */
33
+ export declare const ContextMenuTrigger: (props?: ContextMenuTriggerProps | undefined) => TemplateResult;
34
+ export interface ContextMenuContentProps {
35
+ children?: Parts;
26
36
  class?: Reactive<string>;
27
- contentClass?: Reactive<string>;
28
37
  }
29
- export declare const ContextMenu: (props?: ContextMenuProps | undefined) => import("@c9up/aurora").TemplateResult;
38
+ export declare const ContextMenuContent: (props?: ContextMenuContentProps | undefined) => TemplateResult;
39
+ export declare const ContextMenuGroup: (props?: import("./ContextMenu.js").ContextMenuGroupProps) => TemplateResult;
40
+ export declare const ContextMenuItem: (props?: import("./ContextMenu.js").ContextMenuItemProps) => TemplateResult;
41
+ export declare const ContextMenuCheckboxItem: (props?: import("./ContextMenu.js").ContextMenuCheckboxItemProps) => TemplateResult;
42
+ export declare const ContextMenuRadioGroup: (props?: import("./ContextMenu.js").ContextMenuRadioGroupProps) => TemplateResult;
43
+ export declare const ContextMenuRadioItem: (props: import("./ContextMenu.js").ContextMenuRadioItemProps) => TemplateResult;
44
+ export declare const ContextMenuLabel: (props?: import("./ContextMenu.js").ContextMenuLabelProps) => TemplateResult;
45
+ export declare const ContextMenuSeparator: (props?: import("./ContextMenu.js").ContextMenuSeparatorProps) => TemplateResult;
46
+ export declare const ContextMenuShortcut: (props?: import("./ContextMenu.js").ContextMenuShortcutProps) => TemplateResult;
47
+ export declare const ContextMenuSub: (props?: import("./ContextMenu.js").ContextMenuSubProps) => TemplateResult;
48
+ export declare const ContextMenuSubTrigger: (props?: import("./ContextMenu.js").ContextMenuSubTriggerProps) => TemplateResult;
49
+ export declare const ContextMenuSubContent: (props?: import("./ContextMenu.js").ContextMenuSubContentProps) => TemplateResult;
50
+ export declare const ContextMenuPortal: (props?: import("./ContextMenu.js").ContextMenuPortalProps) => TemplateResult;
51
+ export type { MenuCheckboxItemProps as ContextMenuCheckboxItemProps, MenuGroupProps as ContextMenuGroupProps, MenuItemProps as ContextMenuItemProps, MenuLabelProps as ContextMenuLabelProps, MenuPortalProps as ContextMenuPortalProps, MenuRadioGroupProps as ContextMenuRadioGroupProps, MenuRadioItemProps as ContextMenuRadioItemProps, MenuSeparatorProps as ContextMenuSeparatorProps, MenuShortcutProps as ContextMenuShortcutProps, MenuSubContentProps as ContextMenuSubContentProps, MenuSubProps as ContextMenuSubProps, MenuSubTriggerProps as ContextMenuSubTriggerProps, } from "../primitives/menuParts.js";