@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
@@ -33,10 +33,31 @@ import { portal } from "./portal.js";
33
33
  import { rovingFocus } from "./rovingFocus.js";
34
34
  import { typeahead } from "./typeahead.js";
35
35
  // ─── classes ─────────────────────────────────────────────────────────
36
- export const menuPanelClasses = "bg-popover text-popover-foreground z-50 min-w-[8rem] max-h-(--nebula-available-height) overflow-x-hidden overflow-y-auto rounded-md border p-1 shadow-md outline-none";
37
- const itemClasses = "relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4";
36
+ /**
37
+ * Upstream's class strings, shared by the three menus built on this module.
38
+ *
39
+ * shadcn repeats them in `dropdown-menu.tsx`, `context-menu.tsx` and
40
+ * `menubar.tsx` because each file is copied on its own. Here all three already
41
+ * depend on this module, and the registry copies it with them, so repeating
42
+ * the strings would only be three places to update when one of them changes.
43
+ *
44
+ * `--nebula-available-height` and `--nebula-transform-origin` stand in for
45
+ * Radix's per-component custom properties; `autoPosition` writes both.
46
+ */
47
+ export const menuPanelClasses = "bg-popover text-popover-foreground z-50 max-h-(--nebula-available-height) min-w-[8rem] origin-(--nebula-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border p-1 shadow-md outline-none";
48
+ /** A submenu panel: no height cap, a deeper shadow. */
49
+ export const menuSubPanelClasses = "bg-popover text-popover-foreground z-50 min-w-[8rem] origin-(--nebula-transform-origin) overflow-hidden rounded-md border p-1 shadow-lg outline-none";
50
+ export const menuItemClasses = "relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground data-[variant=destructive]:*:[svg]:text-destructive!";
51
+ /** Checkbox and radio rows: the same, indented to leave room for the mark. */
52
+ export const menuCheckItemClasses = "relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4";
53
+ export const menuIndicatorClasses = "pointer-events-none absolute left-2 flex size-3.5 items-center justify-center";
54
+ export const menuLabelClasses = "px-2 py-1.5 text-sm font-medium data-[inset]:pl-8";
55
+ export const menuSeparatorClasses = "bg-border -mx-1 my-1 h-px";
56
+ export const menuShortcutClasses = "text-muted-foreground ml-auto text-xs tracking-widest";
57
+ export const menuSubTriggerClasses = "flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[inset]:pl-8 data-[state=open]:bg-accent data-[state=open]:text-accent-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground";
58
+ const itemClasses = menuItemClasses;
38
59
  const destructiveClasses = "text-destructive focus:bg-destructive/10 focus:text-destructive [&_svg]:text-destructive";
39
- const indentedItemClasses = `${itemClasses} py-1.5 pr-2 pl-8`;
60
+ const indentedItemClasses = menuCheckItemClasses;
40
61
  /** The panel's markup. Behaviour is attached separately by `wireMenu`. */
41
62
  export function menuPanel(options) {
42
63
  return html `<div
@@ -64,7 +85,7 @@ function renderEntry(entry, closeAll) {
64
85
  if (isRadioGroup(entry))
65
86
  return renderRadioGroup(entry, closeAll);
66
87
  if (isSubmenu(entry))
67
- return renderSubmenuTrigger(entry);
88
+ return renderSubmenuTrigger(entry, closeAll);
68
89
  return renderAction(entry, closeAll);
69
90
  }
70
91
  function renderAction(entry, closeAll) {
@@ -128,8 +149,8 @@ function renderRadioGroup(entry, closeAll) {
128
149
  * those into the DOM is not possible. `wireMenu` reads them back when the row
129
150
  * is opened.
130
151
  */
131
- const submenuEntries = new WeakMap();
132
- function renderSubmenuTrigger(entry) {
152
+ const submenuPanels = new WeakMap();
153
+ function renderSubmenuTrigger(entry, closeAll) {
133
154
  const id = uid("menu-sub-trigger");
134
155
  const row = html `<div
135
156
  role="menuitem"
@@ -145,7 +166,8 @@ function renderSubmenuTrigger(entry) {
145
166
  <span class="flex-1 truncate">${entry.label}</span>
146
167
  ${ChevronRightIcon({ class: "ml-auto size-4" })}
147
168
  </div>`;
148
- pendingSubmenus.set(id, entry.entries);
169
+ const entries = entry.entries;
170
+ pendingSubmenus.set(id, ({ id: panelId }) => menuPanel({ id: panelId, entries, onCloseAll: closeAll }));
149
171
  return row;
150
172
  }
151
173
  /**
@@ -199,12 +221,12 @@ export function wireMenu(panel, options) {
199
221
  onMatch: (item) => focusSilently(item),
200
222
  });
201
223
  function openSubmenu(trigger) {
202
- const entries = submenuEntries.get(trigger);
203
- if (entries === undefined || entries.length === 0)
224
+ const build = submenuPanels.get(trigger);
225
+ if (build === undefined)
204
226
  return;
205
227
  closeSubmenusFrom(0);
206
228
  const panelId = uid("menu-sub");
207
- const mount = portal(menuPanel({ id: panelId, entries, onCloseAll: options.onCloseAll }));
229
+ const mount = portal(build({ id: panelId }));
208
230
  const element = mount.host.firstElementChild;
209
231
  if (!(element instanceof HTMLElement)) {
210
232
  mount.close();
@@ -321,19 +343,28 @@ export function wireMenu(panel, options) {
321
343
  group.destroy();
322
344
  };
323
345
  }
324
- /** Move each submenu's entries from the build-time map onto its element. */
346
+ /** Move each submenu's panel factory from the build-time map onto its element. */
325
347
  function claimSubmenuEntries(panel) {
326
348
  for (const node of panel.querySelectorAll("[data-submenu]")) {
327
349
  const id = node.getAttribute("data-submenu");
328
350
  if (id === null)
329
351
  continue;
330
- const entries = pendingSubmenus.get(id);
331
- if (entries === undefined)
352
+ const build = pendingSubmenus.get(id);
353
+ if (build === undefined)
332
354
  continue;
333
- submenuEntries.set(node, entries);
355
+ submenuPanels.set(node, build);
334
356
  pendingSubmenus.delete(id);
335
357
  }
336
358
  }
359
+ /**
360
+ * Register a composed submenu panel against a trigger id.
361
+ *
362
+ * The parts in `DropdownMenu` and friends build their own markup, so they hand
363
+ * the factory over directly instead of going through `MenuEntry`.
364
+ */
365
+ export function registerSubmenu(id, build) {
366
+ pendingSubmenus.set(id, build);
367
+ }
337
368
  // ─── entry guards ────────────────────────────────────────────────────
338
369
  //
339
370
  // Discriminating on an optional `type` needs real guards: `entry.type ===
@@ -0,0 +1,113 @@
1
+ /**
2
+ * The rows every menu is made of.
3
+ *
4
+ * DropdownMenu, ContextMenu and Menubar are the same menu with three different
5
+ * opening gestures: a button, a right-click, a bar. Upstream repeats all
6
+ * fifteen row components in each of the three files, because each file is
7
+ * copied on its own and has to stand alone. Here the three already share
8
+ * `menu.ts` — its class strings, its keyboard model, its submenu registry —
9
+ * and the registry copies it with them, so repeating the rows would only be
10
+ * three places to fix when one of them is wrong.
11
+ *
12
+ * const parts = createMenuParts("context-menu", ContextMenuContext);
13
+ * export const ContextMenuItem = parts.Item;
14
+ *
15
+ * What differs between the three is exactly two things: the `data-slot`
16
+ * prefix, and which context tells a row how to close the menu it is in. Both
17
+ * are arguments.
18
+ *
19
+ * The rows carry `data-nebula-item` and a `role`, which is the whole of the
20
+ * contract `wireMenu` reads — roving focus, type-ahead, arrows and submenu
21
+ * traversal all work on the rendered DOM, so a row built here behaves the same
22
+ * as one written by hand.
23
+ */
24
+ import { type Context, type TemplateResult } from "@c9up/aurora";
25
+ import type { Parts, Slot } from "../lib/children.js";
26
+ import { type Reactive } from "../lib/props.js";
27
+ /** What a row needs from the menu it is in. */
28
+ export interface MenuOwner {
29
+ /** A row was chosen: the whole stack closes. */
30
+ closeAll(): void;
31
+ }
32
+ export interface MenuGroupProps {
33
+ children?: Slot;
34
+ class?: Reactive<string>;
35
+ }
36
+ export interface MenuItemProps {
37
+ children?: Slot;
38
+ /** Indent to line up with the checkbox and radio rows. */
39
+ inset?: boolean;
40
+ variant?: "default" | "destructive";
41
+ disabled?: boolean;
42
+ onSelect?: () => void;
43
+ class?: Reactive<string>;
44
+ }
45
+ export interface MenuCheckboxItemProps {
46
+ children?: Slot;
47
+ checked?: Reactive<boolean>;
48
+ onCheckedChange?: (checked: boolean) => void;
49
+ disabled?: boolean;
50
+ class?: Reactive<string>;
51
+ }
52
+ export interface MenuRadioGroupProps {
53
+ children?: Parts;
54
+ value?: Reactive<string | undefined>;
55
+ onValueChange?: (value: string) => void;
56
+ class?: Reactive<string>;
57
+ }
58
+ export interface MenuRadioItemProps {
59
+ children?: Slot;
60
+ value: string;
61
+ disabled?: boolean;
62
+ class?: Reactive<string>;
63
+ }
64
+ export interface MenuLabelProps {
65
+ children?: Slot;
66
+ inset?: boolean;
67
+ class?: Reactive<string>;
68
+ }
69
+ export interface MenuSeparatorProps {
70
+ class?: Reactive<string>;
71
+ }
72
+ export interface MenuShortcutProps {
73
+ children?: Slot;
74
+ class?: Reactive<string>;
75
+ }
76
+ export interface MenuSubProps {
77
+ children?: Parts;
78
+ }
79
+ export interface MenuSubTriggerProps {
80
+ children?: Slot;
81
+ inset?: boolean;
82
+ disabled?: boolean;
83
+ class?: Reactive<string>;
84
+ }
85
+ export interface MenuSubContentProps {
86
+ children?: Parts;
87
+ class?: Reactive<string>;
88
+ }
89
+ export interface MenuPortalProps {
90
+ children?: Slot;
91
+ container?: () => Element | null;
92
+ }
93
+ export interface MenuParts {
94
+ Group: (props?: MenuGroupProps) => TemplateResult;
95
+ Item: (props?: MenuItemProps) => TemplateResult;
96
+ CheckboxItem: (props?: MenuCheckboxItemProps) => TemplateResult;
97
+ RadioGroup: (props?: MenuRadioGroupProps) => TemplateResult;
98
+ RadioItem: (props: MenuRadioItemProps) => TemplateResult;
99
+ Label: (props?: MenuLabelProps) => TemplateResult;
100
+ Separator: (props?: MenuSeparatorProps) => TemplateResult;
101
+ Shortcut: (props?: MenuShortcutProps) => TemplateResult;
102
+ Sub: (props?: MenuSubProps) => TemplateResult;
103
+ SubTrigger: (props?: MenuSubTriggerProps) => TemplateResult;
104
+ SubContent: (props?: MenuSubContentProps) => TemplateResult;
105
+ Portal: (props?: MenuPortalProps) => TemplateResult;
106
+ }
107
+ /**
108
+ * Build one menu's fifteen rows.
109
+ *
110
+ * @param prefix The `data-slot` prefix, e.g. `"dropdown-menu"`.
111
+ * @param owner The context carrying that menu's `closeAll`.
112
+ */
113
+ export declare function createMenuParts(prefix: string, owner: Context<MenuOwner>): MenuParts;
@@ -0,0 +1,207 @@
1
+ /**
2
+ * The rows every menu is made of.
3
+ *
4
+ * DropdownMenu, ContextMenu and Menubar are the same menu with three different
5
+ * opening gestures: a button, a right-click, a bar. Upstream repeats all
6
+ * fifteen row components in each of the three files, because each file is
7
+ * copied on its own and has to stand alone. Here the three already share
8
+ * `menu.ts` — its class strings, its keyboard model, its submenu registry —
9
+ * and the registry copies it with them, so repeating the rows would only be
10
+ * three places to fix when one of them is wrong.
11
+ *
12
+ * const parts = createMenuParts("context-menu", ContextMenuContext);
13
+ * export const ContextMenuItem = parts.Item;
14
+ *
15
+ * What differs between the three is exactly two things: the `data-slot`
16
+ * prefix, and which context tells a row how to close the menu it is in. Both
17
+ * are arguments.
18
+ *
19
+ * The rows carry `data-nebula-item` and a `role`, which is the whole of the
20
+ * contract `wireMenu` reads — roving focus, type-ahead, arrows and submenu
21
+ * traversal all work on the rendered DOM, so a row built here behaves the same
22
+ * as one written by hand.
23
+ */
24
+ import { component, createContext, html, inject, provide, } from "@c9up/aurora";
25
+ import { slot } from "../lib/children.js";
26
+ import { cn } from "../lib/cn.js";
27
+ import { CheckIcon, ChevronRightIcon, CircleIcon } from "../lib/icons.js";
28
+ import { uid } from "../lib/id.js";
29
+ import { slideInFromSide, zoomInOut } from "../lib/motion.js";
30
+ import { read } from "../lib/props.js";
31
+ import { menuCheckItemClasses, menuIndicatorClasses, menuItemClasses, menuLabelClasses, menuSeparatorClasses, menuShortcutClasses, menuSubPanelClasses, menuSubTriggerClasses, registerSubmenu, } from "./menu.js";
32
+ import { portal } from "./portal.js";
33
+ /**
34
+ * Build one menu's fifteen rows.
35
+ *
36
+ * @param prefix The `data-slot` prefix, e.g. `"dropdown-menu"`.
37
+ * @param owner The context carrying that menu's `closeAll`.
38
+ */
39
+ export function createMenuParts(prefix, owner) {
40
+ const RadioGroupContext = createContext(`${prefix}-radio-group`);
41
+ const SubContext = createContext(`${prefix}-sub`);
42
+ const Group = component((props) => html `<div
43
+ data-slot="${`${prefix}-group`}"
44
+ role="group"
45
+ class="${() => cn(read(props.class))}"
46
+ >${slot(props.children)}</div>`);
47
+ const Item = component((props) => {
48
+ const menu = inject(owner);
49
+ function activate() {
50
+ if (props.disabled === true)
51
+ return;
52
+ props.onSelect?.();
53
+ menu.closeAll();
54
+ }
55
+ return html `<div
56
+ data-slot="${`${prefix}-item`}"
57
+ data-nebula-item
58
+ role="menuitem"
59
+ data-inset="${props.inset === true ? "" : undefined}"
60
+ data-variant="${props.variant ?? "default"}"
61
+ data-disabled="${props.disabled === true ? "" : undefined}"
62
+ aria-disabled="${props.disabled === true ? "true" : undefined}"
63
+ tabindex="-1"
64
+ class="${() => cn(menuItemClasses, read(props.class))}"
65
+ @click="${activate}"
66
+ >${slot(props.children)}</div>`;
67
+ });
68
+ const CheckboxItem = component((props) => {
69
+ const menu = inject(owner);
70
+ const checked = () => read(props.checked) === true;
71
+ function activate() {
72
+ if (props.disabled === true)
73
+ return;
74
+ props.onCheckedChange?.(!checked());
75
+ menu.closeAll();
76
+ }
77
+ return html `<div
78
+ data-slot="${`${prefix}-checkbox-item`}"
79
+ data-nebula-item
80
+ role="menuitemcheckbox"
81
+ aria-checked="${() => (checked() ? "true" : "false")}"
82
+ data-disabled="${props.disabled === true ? "" : undefined}"
83
+ aria-disabled="${props.disabled === true ? "true" : undefined}"
84
+ tabindex="-1"
85
+ class="${() => cn(menuCheckItemClasses, read(props.class))}"
86
+ @click="${activate}"
87
+ ><span class="${menuIndicatorClasses}">${() => checked() ? CheckIcon({ class: "size-4" }) : null}</span>${slot(props.children)}</div>`;
88
+ });
89
+ const RadioGroup = component((props) => {
90
+ const menu = inject(owner);
91
+ provide(RadioGroupContext, {
92
+ value: () => read(props.value),
93
+ select(next) {
94
+ props.onValueChange?.(next);
95
+ menu.closeAll();
96
+ },
97
+ });
98
+ const rows = props.children?.();
99
+ return html `<div
100
+ data-slot="${`${prefix}-radio-group`}"
101
+ role="group"
102
+ class="${() => cn(read(props.class))}"
103
+ >${rows}</div>`;
104
+ });
105
+ const RadioItem = component((props) => {
106
+ const group = inject(RadioGroupContext);
107
+ const selected = () => group.value() === props.value;
108
+ function activate() {
109
+ if (props.disabled === true)
110
+ return;
111
+ group.select(props.value);
112
+ }
113
+ return html `<div
114
+ data-slot="${`${prefix}-radio-item`}"
115
+ data-nebula-item
116
+ role="menuitemradio"
117
+ aria-checked="${() => (selected() ? "true" : "false")}"
118
+ data-disabled="${props.disabled === true ? "" : undefined}"
119
+ aria-disabled="${props.disabled === true ? "true" : undefined}"
120
+ tabindex="-1"
121
+ class="${() => cn(menuCheckItemClasses, read(props.class))}"
122
+ @click="${activate}"
123
+ ><span class="${menuIndicatorClasses}">${() => selected()
124
+ ? CircleIcon({ class: "size-2 fill-current" })
125
+ : null}</span>${slot(props.children)}</div>`;
126
+ });
127
+ const Label = component((props) => html `<div
128
+ data-slot="${`${prefix}-label`}"
129
+ data-inset="${props.inset === true ? "" : undefined}"
130
+ class="${() => cn(menuLabelClasses, read(props.class))}"
131
+ >${slot(props.children)}</div>`);
132
+ const Separator = component((props) => html `<div
133
+ data-slot="${`${prefix}-separator`}"
134
+ role="separator"
135
+ class="${() => cn(menuSeparatorClasses, read(props.class))}"
136
+ ></div>`);
137
+ const Shortcut = component((props) => html `<span
138
+ data-slot="${`${prefix}-shortcut`}"
139
+ class="${() => cn(menuShortcutClasses, read(props.class))}"
140
+ >${slot(props.children)}</span>`);
141
+ const Sub = component((props) => {
142
+ const triggerId = uid(`${prefix}-sub-trigger`);
143
+ let body;
144
+ let panelClass;
145
+ provide(SubContext, {
146
+ triggerId,
147
+ register(registered, className) {
148
+ body = registered;
149
+ panelClass = className;
150
+ },
151
+ });
152
+ const parts = props.children?.();
153
+ // Registered AFTER the parts are built, so `body` is the panel the
154
+ // `SubContent` among them just handed over. A submenu is built fresh on
155
+ // each open, which is why this is a factory.
156
+ registerSubmenu(triggerId, ({ id }) => html `<div
157
+ data-slot="${`${prefix}-sub-content`}"
158
+ id="${id}"
159
+ role="menu"
160
+ aria-orientation="vertical"
161
+ tabindex="-1"
162
+ class="${cn(menuSubPanelClasses, zoomInOut, slideInFromSide, read(panelClass))}"
163
+ >${body}</div>`);
164
+ return html `${parts}`;
165
+ });
166
+ const SubTrigger = component((props) => {
167
+ const sub = inject(SubContext);
168
+ return html `<div
169
+ data-slot="${`${prefix}-sub-trigger`}"
170
+ data-nebula-item
171
+ data-submenu="${sub.triggerId}"
172
+ role="menuitem"
173
+ aria-haspopup="menu"
174
+ aria-expanded="false"
175
+ data-inset="${props.inset === true ? "" : undefined}"
176
+ data-disabled="${props.disabled === true ? "" : undefined}"
177
+ tabindex="-1"
178
+ class="${() => cn(menuSubTriggerClasses, read(props.class))}"
179
+ >${slot(props.children)}${ChevronRightIcon({ class: "ml-auto size-4" })}</div>`;
180
+ });
181
+ const SubContent = component((props) => {
182
+ const sub = inject(SubContext);
183
+ sub.register(props.children?.(), props.class);
184
+ return html ``;
185
+ });
186
+ const Portal = component((props) => {
187
+ const mounted = portal(html `${slot(props.children)}`, {
188
+ container: props.container,
189
+ });
190
+ mounted.host.setAttribute("data-slot", `${prefix}-portal`);
191
+ return html ``;
192
+ });
193
+ return {
194
+ Group,
195
+ Item,
196
+ CheckboxItem,
197
+ RadioGroup,
198
+ RadioItem,
199
+ Label,
200
+ Separator,
201
+ Shortcut,
202
+ Sub,
203
+ SubTrigger,
204
+ SubContent,
205
+ Portal,
206
+ };
207
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Where this package's stubs live.
3
+ *
4
+ * Its own module, as upstream keeps it: a stub root is a path a package
5
+ * publishes, and a caller importing it should not have to import the
6
+ * configure hook to get it.
7
+ *
8
+ * `import.meta.dirname` rather than a URL — upstream reads it straight off
9
+ * `import.meta`, and deriving it from `import.meta.url` breaks wherever that
10
+ * is not a `file://` URL, which is what a test runner serving modules over
11
+ * HTTP hands you.
12
+ */
13
+ export declare const stubsRoot: string;
package/dist/stubs.js ADDED
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Where this package's stubs live.
3
+ *
4
+ * Its own module, as upstream keeps it: a stub root is a path a package
5
+ * publishes, and a caller importing it should not have to import the
6
+ * configure hook to get it.
7
+ *
8
+ * `import.meta.dirname` rather than a URL — upstream reads it straight off
9
+ * `import.meta`, and deriving it from `import.meta.url` breaks wherever that
10
+ * is not a `file://` URL, which is what a test runner serving modules over
11
+ * HTTP hands you.
12
+ */
13
+ import { join } from "node:path";
14
+ export const stubsRoot = join(import.meta.dirname, "..", "stubs");