@c9up/nebula 0.1.8 → 0.2.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/dist/atoms/Avatar.d.ts +36 -9
- package/dist/atoms/Avatar.js +66 -27
- package/dist/atoms/index.d.ts +1 -1
- package/dist/atoms/index.js +1 -1
- package/dist/lib/children.d.ts +30 -0
- package/dist/lib/motion.d.ts +10 -0
- package/dist/lib/motion.js +10 -0
- package/dist/molecules/Accordion.d.ts +36 -15
- package/dist/molecules/Accordion.js +68 -45
- package/dist/molecules/Breadcrumb.d.ts +29 -11
- package/dist/molecules/Breadcrumb.js +52 -52
- package/dist/molecules/Collapsible.d.ts +18 -17
- package/dist/molecules/Collapsible.js +42 -34
- package/dist/molecules/Field.d.ts +66 -30
- package/dist/molecules/Field.js +106 -55
- package/dist/molecules/InputGroup.d.ts +39 -21
- package/dist/molecules/InputGroup.js +43 -27
- package/dist/molecules/InputOTP.d.ts +26 -3
- package/dist/molecules/InputOTP.js +109 -76
- package/dist/molecules/Message.js +5 -4
- package/dist/molecules/Pagination.d.ts +36 -11
- package/dist/molecules/Pagination.js +58 -74
- package/dist/molecules/RadioGroup.d.ts +25 -17
- package/dist/molecules/RadioGroup.js +47 -43
- package/dist/molecules/Resizable.d.ts +32 -7
- package/dist/molecules/Resizable.js +76 -49
- package/dist/molecules/Tabs.d.ts +49 -11
- package/dist/molecules/Tabs.js +107 -51
- package/dist/molecules/ToggleGroup.d.ts +16 -10
- package/dist/molecules/ToggleGroup.js +37 -21
- package/dist/molecules/index.d.ts +11 -11
- package/dist/molecules/index.js +11 -11
- package/dist/organisms/AlertDialog.d.ts +80 -28
- package/dist/organisms/AlertDialog.js +192 -67
- package/dist/organisms/Carousel.d.ts +25 -3
- package/dist/organisms/Carousel.js +75 -43
- package/dist/organisms/Combobox.d.ts +2 -1
- package/dist/organisms/Combobox.js +46 -16
- package/dist/organisms/Command.d.ts +73 -32
- package/dist/organisms/Command.js +209 -131
- package/dist/organisms/CommandDialog.js +5 -5
- package/dist/organisms/ContextMenu.d.ts +41 -19
- package/dist/organisms/ContextMenu.js +112 -71
- package/dist/organisms/DataTable.js +42 -8
- package/dist/organisms/Dialog.d.ts +97 -31
- package/dist/organisms/Dialog.js +193 -68
- package/dist/organisms/Drawer.d.ts +33 -10
- package/dist/organisms/Drawer.js +130 -52
- package/dist/organisms/DropdownMenu.d.ts +58 -11
- package/dist/organisms/DropdownMenu.js +137 -50
- package/dist/organisms/Form.js +9 -11
- package/dist/organisms/HoverCard.d.ts +39 -19
- package/dist/organisms/HoverCard.js +116 -40
- package/dist/organisms/Menubar.d.ts +55 -19
- package/dist/organisms/Menubar.js +166 -82
- package/dist/organisms/NavigationMenu.d.ts +77 -31
- package/dist/organisms/NavigationMenu.js +169 -98
- package/dist/organisms/Popover.d.ts +72 -12
- package/dist/organisms/Popover.js +132 -25
- package/dist/organisms/Questionnaire.js +5 -5
- package/dist/organisms/Select.d.ts +99 -18
- package/dist/organisms/Select.js +253 -111
- package/dist/organisms/Sheet.d.ts +57 -13
- package/dist/organisms/Sheet.js +141 -54
- package/dist/organisms/Sidebar.d.ts +146 -56
- package/dist/organisms/Sidebar.js +236 -128
- package/dist/organisms/Tooltip.d.ts +88 -14
- package/dist/organisms/Tooltip.js +210 -47
- package/dist/organisms/index.d.ts +15 -15
- package/dist/organisms/index.js +15 -15
- package/dist/primitives/floating.js +25 -0
- package/dist/primitives/floatingSurface.d.ts +11 -0
- package/dist/primitives/floatingSurface.js +8 -0
- package/dist/primitives/menu.d.ts +45 -1
- package/dist/primitives/menu.js +45 -14
- package/dist/primitives/menuParts.d.ts +113 -0
- package/dist/primitives/menuParts.js +207 -0
- package/nebula.css +1 -1
- package/package.json +5 -4
- package/registry.json +18 -6
- package/src/atoms/Avatar.ts +141 -37
- package/src/atoms/index.ts +13 -1
- package/src/lib/children.ts +31 -0
- package/src/lib/motion.ts +12 -0
- package/src/molecules/Accordion.ts +120 -60
- package/src/molecules/Breadcrumb.ts +77 -76
- package/src/molecules/Collapsible.ts +77 -41
- package/src/molecules/Field.ts +187 -72
- package/src/molecules/InputGroup.ts +88 -35
- package/src/molecules/InputOTP.ts +150 -86
- package/src/molecules/Message.ts +6 -4
- package/src/molecules/Pagination.ts +96 -101
- package/src/molecules/RadioGroup.ts +70 -59
- package/src/molecules/Resizable.ts +138 -75
- package/src/molecules/Tabs.ts +187 -74
- package/src/molecules/ToggleGroup.ts +77 -38
- package/src/molecules/index.ts +85 -8
- package/src/organisms/AlertDialog.ts +319 -82
- package/src/organisms/Carousel.ts +129 -52
- package/src/organisms/Combobox.ts +64 -19
- package/src/organisms/Command.ts +342 -159
- package/src/organisms/CommandDialog.ts +6 -6
- package/src/organisms/ContextMenu.ts +185 -83
- package/src/organisms/DataTable.ts +56 -10
- package/src/organisms/Dialog.ts +312 -102
- package/src/organisms/Drawer.ts +219 -71
- package/src/organisms/DropdownMenu.ts +219 -61
- package/src/organisms/Form.ts +48 -34
- package/src/organisms/HoverCard.ts +187 -53
- package/src/organisms/Menubar.ts +247 -87
- package/src/organisms/NavigationMenu.ts +306 -128
- package/src/organisms/Popover.ts +215 -39
- package/src/organisms/Questionnaire.ts +9 -6
- package/src/organisms/Select.ts +397 -130
- package/src/organisms/Sheet.ts +252 -83
- package/src/organisms/Sidebar.ts +438 -185
- package/src/organisms/Tooltip.ts +315 -65
- package/src/organisms/index.ts +284 -14
- package/src/primitives/floating.ts +33 -0
- package/src/primitives/floatingSurface.ts +19 -0
- package/src/primitives/menu.ts +79 -18
- package/src/primitives/menuParts.ts +371 -0
|
@@ -1,46 +1,87 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Command —
|
|
2
|
+
* Command — the palette: type to filter, arrows to move, Enter to run.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
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
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
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
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
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 {
|
|
26
|
+
import type { Parts, Slot } from "../lib/children.js";
|
|
21
27
|
import { type Reactive } from "../lib/props.js";
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
26
|
-
|
|
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
|
|
35
|
-
|
|
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
|
-
|
|
45
|
-
export
|
|
46
|
-
|
|
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 —
|
|
2
|
+
* Command — the palette: type to filter, arrows to move, Enter to run.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
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
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
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
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
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
|
-
|
|
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 (
|
|
36
|
+
if (candidate.textValue.toLowerCase().includes(needle))
|
|
31
37
|
return true;
|
|
32
|
-
return
|
|
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
|
-
|
|
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
|
|
81
|
+
return items.filter((item) => !item.disabled && filter(item, query()));
|
|
45
82
|
}
|
|
46
|
-
function run(
|
|
47
|
-
|
|
83
|
+
function run(value) {
|
|
84
|
+
const item = items.find((entry) => entry.value === value);
|
|
85
|
+
if (item === undefined || item.disabled)
|
|
48
86
|
return;
|
|
49
|
-
item.
|
|
50
|
-
props.onSelect?.(
|
|
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
|
|
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
|
-
|
|
93
|
-
|
|
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
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
?
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
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(
|
|
68
|
-
props.onSelect?.(
|
|
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 —
|
|
2
|
+
* ContextMenu — the menu a right-click opens.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
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
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
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
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
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
|
|
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
|
|
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";
|