menhir 0.1.2 → 0.1.3

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 (155) hide show
  1. package/README.md +2 -2
  2. package/dist/alert-dialog/index.js +2 -0
  3. package/dist/alert-dialog/index.parts.js +7 -0
  4. package/dist/alert-dialog/popup/AlertDialogPopup.js +13 -0
  5. package/dist/core/createControllableSignal.js +4 -3
  6. package/dist/core/slot.js +30 -0
  7. package/dist/dialog/close/DialogClose.js +33 -0
  8. package/dist/dialog/description/DialogDescription.js +27 -0
  9. package/dist/dialog/index.js +2 -0
  10. package/dist/dialog/index.parts.js +7 -0
  11. package/dist/dialog/popup/DialogPopup.js +13 -0
  12. package/dist/dialog/popup/renderDialogPopup.js +71 -0
  13. package/dist/dialog/root/DialogRoot.js +46 -0
  14. package/dist/dialog/root/DialogRootContext.js +10 -0
  15. package/dist/dialog/title/DialogTitle.js +27 -0
  16. package/dist/dialog/trigger/DialogTrigger.js +33 -0
  17. package/dist/floating/dismissal/dialogClose.js +67 -0
  18. package/dist/floating/dismissal/escape.js +43 -0
  19. package/dist/floating/dismissal/outsidePress.js +52 -0
  20. package/dist/floating/dismissal/popoverClose.js +74 -0
  21. package/dist/floating/dismissal/reason.js +0 -0
  22. package/dist/floating/focus/initialFocus.js +33 -0
  23. package/dist/floating/focus/returnFocus.js +65 -0
  24. package/dist/floating/focus/tabWrap.js +55 -0
  25. package/dist/floating/focus/tabbable.js +50 -0
  26. package/dist/floating/focus/target.js +0 -0
  27. package/dist/floating/hover/group.js +36 -0
  28. package/dist/floating/hover/hover.js +105 -0
  29. package/dist/floating/hover/safeArea.js +64 -0
  30. package/dist/floating/presence/presence.js +57 -0
  31. package/dist/floating/scroll-lock/scrollLock.js +125 -0
  32. package/dist/popover/arrow/PopoverArrow.js +39 -0
  33. package/dist/popover/close/PopoverClose.js +33 -0
  34. package/dist/popover/description/PopoverDescription.js +27 -0
  35. package/dist/popover/index.js +2 -0
  36. package/dist/popover/index.parts.js +8 -0
  37. package/dist/popover/popup/PopoverPopup.js +116 -0
  38. package/dist/popover/popup/PopoverPopupContext.js +10 -0
  39. package/dist/popover/root/PopoverRoot.js +50 -0
  40. package/dist/popover/root/PopoverRootContext.js +10 -0
  41. package/dist/popover/title/PopoverTitle.js +27 -0
  42. package/dist/popover/trigger/PopoverTrigger.js +44 -0
  43. package/dist/source/alert-dialog/index.d.ts +1 -0
  44. package/dist/source/alert-dialog/index.js +1 -0
  45. package/dist/source/alert-dialog/index.parts.d.ts +6 -0
  46. package/dist/source/alert-dialog/index.parts.js +7 -0
  47. package/dist/source/alert-dialog/popup/AlertDialogPopup.d.ts +10 -0
  48. package/dist/source/alert-dialog/popup/AlertDialogPopup.jsx +11 -0
  49. package/dist/source/core/createControllableSignal.d.ts +5 -4
  50. package/dist/source/core/createControllableSignal.js +4 -3
  51. package/dist/source/core/slot.d.ts +21 -0
  52. package/dist/source/core/slot.js +28 -0
  53. package/dist/source/dialog/close/DialogClose.d.ts +11 -0
  54. package/dist/source/dialog/close/DialogClose.jsx +25 -0
  55. package/dist/source/dialog/description/DialogDescription.d.ts +10 -0
  56. package/dist/source/dialog/description/DialogDescription.jsx +26 -0
  57. package/dist/source/dialog/index.d.ts +1 -0
  58. package/dist/source/dialog/index.js +1 -0
  59. package/dist/source/dialog/index.parts.d.ts +6 -0
  60. package/dist/source/dialog/index.parts.js +6 -0
  61. package/dist/source/dialog/popup/DialogPopup.d.ts +9 -0
  62. package/dist/source/dialog/popup/DialogPopup.jsx +11 -0
  63. package/dist/source/dialog/popup/renderDialogPopup.d.ts +40 -0
  64. package/dist/source/dialog/popup/renderDialogPopup.jsx +73 -0
  65. package/dist/source/dialog/root/DialogRoot.d.ts +20 -0
  66. package/dist/source/dialog/root/DialogRoot.jsx +39 -0
  67. package/dist/source/dialog/root/DialogRootContext.d.ts +32 -0
  68. package/dist/source/dialog/root/DialogRootContext.js +14 -0
  69. package/dist/source/dialog/title/DialogTitle.d.ts +10 -0
  70. package/dist/source/dialog/title/DialogTitle.jsx +26 -0
  71. package/dist/source/dialog/trigger/DialogTrigger.d.ts +10 -0
  72. package/dist/source/dialog/trigger/DialogTrigger.jsx +27 -0
  73. package/dist/source/floating/dismissal/dialogClose.d.ts +26 -0
  74. package/dist/source/floating/dismissal/dialogClose.js +69 -0
  75. package/dist/source/floating/dismissal/escape.d.ts +23 -0
  76. package/dist/source/floating/dismissal/escape.js +47 -0
  77. package/dist/source/floating/dismissal/outsidePress.d.ts +26 -0
  78. package/dist/source/floating/dismissal/outsidePress.js +50 -0
  79. package/dist/source/floating/dismissal/popoverClose.d.ts +28 -0
  80. package/dist/source/floating/dismissal/popoverClose.js +82 -0
  81. package/dist/source/floating/dismissal/reason.d.ts +30 -0
  82. package/dist/source/floating/dismissal/reason.js +1 -0
  83. package/dist/source/floating/focus/initialFocus.d.ts +24 -0
  84. package/dist/source/floating/focus/initialFocus.js +38 -0
  85. package/dist/source/floating/focus/returnFocus.d.ts +27 -0
  86. package/dist/source/floating/focus/returnFocus.js +81 -0
  87. package/dist/source/floating/focus/tabWrap.d.ts +21 -0
  88. package/dist/source/floating/focus/tabWrap.js +69 -0
  89. package/dist/source/floating/focus/tabbable.d.ts +16 -0
  90. package/dist/source/floating/focus/tabbable.js +69 -0
  91. package/dist/source/floating/focus/target.d.ts +8 -0
  92. package/dist/source/floating/focus/target.js +1 -0
  93. package/dist/source/floating/hover/group.d.ts +39 -0
  94. package/dist/source/floating/hover/group.js +38 -0
  95. package/dist/source/floating/hover/hover.d.ts +35 -0
  96. package/dist/source/floating/hover/hover.js +130 -0
  97. package/dist/source/floating/hover/safeArea.d.ts +23 -0
  98. package/dist/source/floating/hover/safeArea.js +67 -0
  99. package/dist/source/floating/presence/presence.d.ts +24 -0
  100. package/dist/source/floating/presence/presence.js +73 -0
  101. package/dist/source/floating/scroll-lock/scrollLock.d.ts +27 -0
  102. package/dist/source/floating/scroll-lock/scrollLock.js +151 -0
  103. package/dist/source/popover/arrow/PopoverArrow.d.ts +11 -0
  104. package/dist/source/popover/arrow/PopoverArrow.jsx +32 -0
  105. package/dist/source/popover/close/PopoverClose.d.ts +11 -0
  106. package/dist/source/popover/close/PopoverClose.jsx +25 -0
  107. package/dist/source/popover/description/PopoverDescription.d.ts +10 -0
  108. package/dist/source/popover/description/PopoverDescription.jsx +26 -0
  109. package/dist/source/popover/index.d.ts +1 -0
  110. package/dist/source/popover/index.js +1 -0
  111. package/dist/source/popover/index.parts.d.ts +7 -0
  112. package/dist/source/popover/index.parts.js +7 -0
  113. package/dist/source/popover/popup/PopoverPopup.d.ts +47 -0
  114. package/dist/source/popover/popup/PopoverPopup.jsx +120 -0
  115. package/dist/source/popover/popup/PopoverPopupContext.d.ts +14 -0
  116. package/dist/source/popover/popup/PopoverPopupContext.js +11 -0
  117. package/dist/source/popover/root/PopoverRoot.d.ts +20 -0
  118. package/dist/source/popover/root/PopoverRoot.jsx +42 -0
  119. package/dist/source/popover/root/PopoverRootContext.d.ts +39 -0
  120. package/dist/source/popover/root/PopoverRootContext.js +13 -0
  121. package/dist/source/popover/title/PopoverTitle.d.ts +10 -0
  122. package/dist/source/popover/title/PopoverTitle.jsx +26 -0
  123. package/dist/source/popover/trigger/PopoverTrigger.d.ts +12 -0
  124. package/dist/source/popover/trigger/PopoverTrigger.jsx +40 -0
  125. package/dist/source/tooltip/arrow/TooltipArrow.d.ts +11 -0
  126. package/dist/source/tooltip/arrow/TooltipArrow.jsx +32 -0
  127. package/dist/source/tooltip/group/TooltipGroup.d.ts +20 -0
  128. package/dist/source/tooltip/group/TooltipGroup.jsx +18 -0
  129. package/dist/source/tooltip/group/TooltipGroupContext.d.ts +2 -0
  130. package/dist/source/tooltip/group/TooltipGroupContext.js +5 -0
  131. package/dist/source/tooltip/index.d.ts +1 -0
  132. package/dist/source/tooltip/index.js +1 -0
  133. package/dist/source/tooltip/index.parts.d.ts +5 -0
  134. package/dist/source/tooltip/index.parts.js +5 -0
  135. package/dist/source/tooltip/popup/TooltipPopup.d.ts +31 -0
  136. package/dist/source/tooltip/popup/TooltipPopup.jsx +77 -0
  137. package/dist/source/tooltip/popup/TooltipPopupContext.d.ts +14 -0
  138. package/dist/source/tooltip/popup/TooltipPopupContext.js +11 -0
  139. package/dist/source/tooltip/root/TooltipRoot.d.ts +31 -0
  140. package/dist/source/tooltip/root/TooltipRoot.jsx +80 -0
  141. package/dist/source/tooltip/root/TooltipRootContext.d.ts +35 -0
  142. package/dist/source/tooltip/root/TooltipRootContext.js +13 -0
  143. package/dist/source/tooltip/trigger/TooltipTrigger.d.ts +12 -0
  144. package/dist/source/tooltip/trigger/TooltipTrigger.jsx +52 -0
  145. package/dist/tooltip/arrow/TooltipArrow.js +39 -0
  146. package/dist/tooltip/group/TooltipGroup.js +26 -0
  147. package/dist/tooltip/group/TooltipGroupContext.js +4 -0
  148. package/dist/tooltip/index.js +2 -0
  149. package/dist/tooltip/index.parts.js +6 -0
  150. package/dist/tooltip/popup/TooltipPopup.js +86 -0
  151. package/dist/tooltip/popup/TooltipPopupContext.js +10 -0
  152. package/dist/tooltip/root/TooltipRoot.js +79 -0
  153. package/dist/tooltip/root/TooltipRootContext.js +10 -0
  154. package/dist/tooltip/trigger/TooltipTrigger.js +54 -0
  155. package/package.json +21 -1
package/README.md CHANGED
@@ -53,9 +53,9 @@ For everything else, go to the docs:
53
53
 
54
54
  ## Status
55
55
 
56
- Early 0.x versions: the API may change between minor versions. Dialog, Popover and the other popups come next; the plan and roadmap are in the [repository](https://github.com/j13n/menhir). Built so far:
56
+ Early 0.x versions: the API may change between minor versions. Menu and the other list popups come next; the plan and roadmap are in the [repository](https://github.com/j13n/menhir). Built so far:
57
57
 
58
- - Components: Accordion, Checkbox, Collapsible, Meter, Progress, Separator, Switch, Tabs, Toggle and Toggle Group.
58
+ - Components: Accordion, Alert Dialog, Checkbox, Collapsible, Dialog, Meter, Popover, Progress, Separator, Switch, Tabs, Toggle, Toggle Group and Tooltip.
59
59
  - Utilities: color scheme and theme, each with local-storage and cookie storage.
60
60
 
61
61
  ## Licence
@@ -0,0 +1,2 @@
1
+ import * as AlertDialog from "./index.parts.js";
2
+ export { AlertDialog };
@@ -0,0 +1,7 @@
1
+ import { DialogRoot } from "../dialog/root/DialogRoot.js";
2
+ import { DialogTrigger } from "../dialog/trigger/DialogTrigger.js";
3
+ import { AlertDialogPopup } from "./popup/AlertDialogPopup.js";
4
+ import { DialogTitle } from "../dialog/title/DialogTitle.js";
5
+ import { DialogDescription } from "../dialog/description/DialogDescription.js";
6
+ import { DialogClose } from "../dialog/close/DialogClose.js";
7
+ export { DialogClose as Close, DialogDescription as Description, AlertDialogPopup as Popup, DialogRoot as Root, DialogTitle as Title, DialogTrigger as Trigger };
@@ -0,0 +1,13 @@
1
+ import { renderDialogPopup } from "../../dialog/popup/renderDialogPopup.js";
2
+ // src/alert-dialog/popup/AlertDialogPopup.tsx
3
+ /**
4
+ * The alert dialog itself: a `<dialog role="alertdialog">`, opened with
5
+ * `showModal()`, so it is modal, in the top layer, over an inert page.
6
+ * Named by `AlertDialog.Title` and described by `AlertDialog.Description`,
7
+ * the message, when they are rendered inside it. Escape closes it; a press
8
+ * on the backdrop does not. Place it inside `AlertDialog.Root`.
9
+ */
10
+ function AlertDialogPopup(props) {
11
+ return renderDialogPopup(props, void 0, "alertdialog");
12
+ }
13
+ export { AlertDialogPopup };
@@ -20,7 +20,8 @@ import { createSignal, onFlush, untrack } from "solid-js";
20
20
  * (`onFlush`), so async work that `onChange` starts does not hold it back.
21
21
  * Setting the value it already has, counting earlier sets in the same turn,
22
22
  * does nothing. Set from event handlers, not from a component body or a
23
- * memo.
23
+ * memo. A set may pass `details`, such as why a popup closed, which
24
+ * `onChange` receives after the value.
24
25
  */
25
26
  function createControllableSignal(options) {
26
27
  const [internal, setInternal] = createSignal(() => untrack(() => options.defaultValue));
@@ -35,10 +36,10 @@ function createControllableSignal(options) {
35
36
  };
36
37
  const value = () => isControlled() ? options.value : internal();
37
38
  let pending;
38
- const setValue = (next) => {
39
+ const setValue = (next, details) => {
39
40
  if (Object.is(next, pending ? pending[0] : untrack(value))) return;
40
41
  if (!untrack(isControlled)) onFlush(() => setInternal(() => next));
41
- options.onChange?.(next);
42
+ options.onChange?.(next, details);
42
43
  const set = [next];
43
44
  pending = set;
44
45
  onFlush(() => {
@@ -0,0 +1,30 @@
1
+ import { createSignal } from "solid-js";
2
+ // src/core/slot.ts
3
+ /**
4
+ * A value that one part registers once mounted, for another part to read,
5
+ * such as the Arrow's middleware, which a popup's Popup uses to place it.
6
+ * Returns the value, `undefined` while none is registered, and `register`,
7
+ * which takes the value as a getter and returns what unregisters it, for
8
+ * the part's disposal. Unregistering removes only the part's own value, so
9
+ * one that another part registered after it stays.
10
+ */
11
+ function createSlot() {
12
+ const [slot, setSlot] = createSignal();
13
+ const value = () => slot()?.();
14
+ const register = (next) => {
15
+ setSlot(() => next);
16
+ return () => setSlot((current) => current === next ? void 0 : current);
17
+ };
18
+ return [value, register];
19
+ }
20
+ /**
21
+ * A slot for the `id` of a part that another part names, such as a popup's
22
+ * Title, which the Popup names in `aria-labelledby`. `false`, a consumer's
23
+ * way to remove the part's `id`, names nothing.
24
+ */
25
+ function createIdSlot() {
26
+ const [slot, register] = createSlot();
27
+ const id = () => slot() || void 0;
28
+ return [id, register];
29
+ }
30
+ export { createIdSlot, createSlot };
@@ -0,0 +1,33 @@
1
+ import { warnUnlessButton } from "../../core/button.js";
2
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
3
+ import { renderElement } from "../../core/renderElement.js";
4
+ import { useDialogRootContext } from "../root/DialogRootContext.js";
5
+ import { isDev, spread, template } from "@solidjs/web";
6
+ import { merge, omit } from "solid-js";
7
+ // src/dialog/close/DialogClose.tsx
8
+ var _tmpl$ = /* @__PURE__ */ template(`<button>`);
9
+ /**
10
+ * A button that closes the dialog: a `<button type="button">`, such as
11
+ * "Cancel" or a close icon with an `aria-label`. Place it inside
12
+ * `Dialog.Popup`.
13
+ */
14
+ function DialogClose(props) {
15
+ const root = useDialogRootContext();
16
+ const ownProps = merge(root.attributes, {
17
+ type: "button",
18
+ onClick: (event) => root.setOpen(false, {
19
+ reason: "close-press",
20
+ event
21
+ }),
22
+ ref: (element) => {
23
+ if (isDev) warnUnlessButton(element, "Dialog.Close");
24
+ }
25
+ });
26
+ const elementProps = mergeElementProps(ownProps, omit(props, "render"));
27
+ return renderElement(props, elementProps, (p) => (() => {
28
+ var _el$ = _tmpl$();
29
+ spread(_el$, p, false);
30
+ return _el$;
31
+ })());
32
+ }
33
+ export { DialogClose };
@@ -0,0 +1,27 @@
1
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
2
+ import { renderElement } from "../../core/renderElement.js";
3
+ import { useDialogRootContext } from "../root/DialogRootContext.js";
4
+ import { spread, template } from "@solidjs/web";
5
+ import { createUniqueId, merge, omit, onSettled } from "solid-js";
6
+ // src/dialog/description/DialogDescription.tsx
7
+ var _tmpl$ = /* @__PURE__ */ template(`<p>`);
8
+ /**
9
+ * What the dialog is for, which describes the Popup in
10
+ * `aria-describedby`: a `<p>`. Place it inside `Dialog.Popup`.
11
+ */
12
+ function DialogDescription(props) {
13
+ const root = useDialogRootContext();
14
+ const generated = createUniqueId();
15
+ const id = () => props.id ?? generated;
16
+ onSettled(() => root.registerDescriptionId(id));
17
+ const ownProps = merge(root.attributes, { get id() {
18
+ return id();
19
+ } });
20
+ const elementProps = mergeElementProps(ownProps, omit(props, "render", "id"));
21
+ return renderElement(props, elementProps, (p) => (() => {
22
+ var _el$ = _tmpl$();
23
+ spread(_el$, p, false);
24
+ return _el$;
25
+ })());
26
+ }
27
+ export { DialogDescription };
@@ -0,0 +1,2 @@
1
+ import * as Dialog from "./index.parts.js";
2
+ export { Dialog };
@@ -0,0 +1,7 @@
1
+ import { DialogRoot } from "./root/DialogRoot.js";
2
+ import { DialogTrigger } from "./trigger/DialogTrigger.js";
3
+ import { DialogPopup } from "./popup/DialogPopup.js";
4
+ import { DialogTitle } from "./title/DialogTitle.js";
5
+ import { DialogDescription } from "./description/DialogDescription.js";
6
+ import { DialogClose } from "./close/DialogClose.js";
7
+ export { DialogClose as Close, DialogDescription as Description, DialogPopup as Popup, DialogRoot as Root, DialogTitle as Title, DialogTrigger as Trigger };
@@ -0,0 +1,13 @@
1
+ import { createOutsidePress } from "../../floating/dismissal/outsidePress.js";
2
+ import { renderDialogPopup } from "./renderDialogPopup.js";
3
+ // src/dialog/popup/DialogPopup.tsx
4
+ /**
5
+ * The dialog itself: a `<dialog>`, opened with `showModal()`, so it is
6
+ * modal, in the top layer, over an inert page. Named by `Dialog.Title` and
7
+ * described by `Dialog.Description` when they are rendered inside it. A
8
+ * press on the backdrop closes it. Place it inside `Dialog.Root`.
9
+ */
10
+ function DialogPopup(props) {
11
+ return renderDialogPopup(props, createOutsidePress);
12
+ }
13
+ export { DialogPopup };
@@ -0,0 +1,71 @@
1
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
2
+ import { renderElement } from "../../core/renderElement.js";
3
+ import { createDialogClose } from "../../floating/dismissal/dialogClose.js";
4
+ import { createInitialFocus } from "../../floating/focus/initialFocus.js";
5
+ import { createReturnFocus } from "../../floating/focus/returnFocus.js";
6
+ import { createTabWrap } from "../../floating/focus/tabWrap.js";
7
+ import { createPresence } from "../../floating/presence/presence.js";
8
+ import { createScrollLock } from "../../floating/scroll-lock/scrollLock.js";
9
+ import { useDialogRootContext } from "../root/DialogRootContext.js";
10
+ import { isDev, spread, template } from "@solidjs/web";
11
+ import { merge, omit } from "solid-js";
12
+ // src/dialog/popup/renderDialogPopup.tsx
13
+ var _tmpl$ = /* @__PURE__ */ template(`<dialog>`);
14
+ /**
15
+ * What a modal dialog's Popup does, for `Dialog.Popup` and
16
+ * `AlertDialog.Popup` (#32): a `<dialog>` opened with `showModal()`, closed
17
+ * by a close request, with Tab wrapping inside, the focus props, the page's
18
+ * scroll locked, and named by its Title and Description. `outsidePress`
19
+ * adds Dialog's press on the backdrop, so that Alert Dialog does not bundle
20
+ * it; `role` is Alert Dialog's `alertdialog`. Two arguments, not an
21
+ * options object, which measured 14 B more in `menhir/dialog`.
22
+ */
23
+ function renderDialogPopup(props, outsidePress, role) {
24
+ const root = useDialogRootContext();
25
+ let dialog;
26
+ const options = {
27
+ get dialog() {
28
+ return dialog;
29
+ },
30
+ get popup() {
31
+ return dialog;
32
+ },
33
+ get open() {
34
+ return root.open();
35
+ },
36
+ onDismiss: (details) => root.setOpen(false, details),
37
+ get initialFocus() {
38
+ return props.initialFocus;
39
+ },
40
+ get returnFocus() {
41
+ return props.returnFocus;
42
+ }
43
+ };
44
+ createPresence(options);
45
+ createDialogClose(options);
46
+ outsidePress?.(options);
47
+ createScrollLock(options);
48
+ createTabWrap(options);
49
+ createInitialFocus(options);
50
+ createReturnFocus(options);
51
+ const ownProps = merge(root.attributes, {
52
+ role,
53
+ get "aria-labelledby"() {
54
+ return props["aria-labelledby"] ?? root.titleId();
55
+ },
56
+ get "aria-describedby"() {
57
+ return props["aria-describedby"] ?? root.descriptionId();
58
+ },
59
+ ref: (element) => {
60
+ if (isDev && !(element instanceof HTMLDialogElement)) console.warn(`[menhir] ${role ? "AlertDialog" : "Dialog"}.Popup's render function rendered a <${element.tagName.toLowerCase()}>. Render a <dialog>, which the Popup opens with showModal().`);
61
+ dialog = element;
62
+ }
63
+ });
64
+ const elementProps = mergeElementProps(ownProps, omit(props, "render", "initialFocus", "returnFocus", "aria-labelledby", "aria-describedby"));
65
+ return renderElement(props, elementProps, (p) => (() => {
66
+ var _el$ = _tmpl$();
67
+ spread(_el$, p, false);
68
+ return _el$;
69
+ })());
70
+ }
71
+ export { renderDialogPopup };
@@ -0,0 +1,46 @@
1
+ import { createControllableSignal } from "../../core/createControllableSignal.js";
2
+ import { createIdSlot } from "../../core/slot.js";
3
+ import { DialogRootContext } from "./DialogRootContext.js";
4
+ import { createComponent } from "@solidjs/web";
5
+ // src/dialog/root/DialogRoot.tsx
6
+ /**
7
+ * A modal dialog: holds whether it is open and shares it with
8
+ * `Dialog.Trigger`, `Dialog.Popup` and the parts inside it. Renders no
9
+ * element of its own.
10
+ */
11
+ function DialogRoot(props) {
12
+ const [open, setOpen] = createControllableSignal({
13
+ get value() {
14
+ return props.open;
15
+ },
16
+ get defaultValue() {
17
+ return props.defaultOpen ?? false;
18
+ },
19
+ onChange: (value, details) => props.onOpenChange?.(value, details)
20
+ });
21
+ const attributes = {
22
+ get "data-open"() {
23
+ return open() ? "" : void 0;
24
+ },
25
+ get "data-closed"() {
26
+ return open() ? void 0 : "";
27
+ }
28
+ };
29
+ const [titleId, registerTitleId] = createIdSlot();
30
+ const [descriptionId, registerDescriptionId] = createIdSlot();
31
+ return createComponent(DialogRootContext, {
32
+ value: {
33
+ open,
34
+ setOpen,
35
+ titleId,
36
+ registerTitleId,
37
+ descriptionId,
38
+ registerDescriptionId,
39
+ attributes
40
+ },
41
+ get children() {
42
+ return props.children;
43
+ }
44
+ });
45
+ }
46
+ export { DialogRoot };
@@ -0,0 +1,10 @@
1
+ import { isDev } from "@solidjs/web";
2
+ import { createContext, useContext } from "solid-js";
3
+ // src/dialog/root/DialogRootContext.ts
4
+ var DialogRootContext = createContext(null);
5
+ function useDialogRootContext() {
6
+ const context = useContext(DialogRootContext);
7
+ if (isDev && !context) throw new Error("[menhir] Dialog parts must be placed within <Dialog.Root>, and Alert Dialog parts within <AlertDialog.Root>.");
8
+ return context;
9
+ }
10
+ export { DialogRootContext, useDialogRootContext };
@@ -0,0 +1,27 @@
1
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
2
+ import { renderElement } from "../../core/renderElement.js";
3
+ import { useDialogRootContext } from "../root/DialogRootContext.js";
4
+ import { spread, template } from "@solidjs/web";
5
+ import { createUniqueId, merge, omit, onSettled } from "solid-js";
6
+ // src/dialog/title/DialogTitle.tsx
7
+ var _tmpl$ = /* @__PURE__ */ template(`<h2>`);
8
+ /**
9
+ * The dialog's title, which names the Popup in `aria-labelledby`: an
10
+ * `<h2>`. Place it inside `Dialog.Popup`.
11
+ */
12
+ function DialogTitle(props) {
13
+ const root = useDialogRootContext();
14
+ const generated = createUniqueId();
15
+ const id = () => props.id ?? generated;
16
+ onSettled(() => root.registerTitleId(id));
17
+ const ownProps = merge(root.attributes, { get id() {
18
+ return id();
19
+ } });
20
+ const elementProps = mergeElementProps(ownProps, omit(props, "render", "id"));
21
+ return renderElement(props, elementProps, (p) => (() => {
22
+ var _el$ = _tmpl$();
23
+ spread(_el$, p, false);
24
+ return _el$;
25
+ })());
26
+ }
27
+ export { DialogTitle };
@@ -0,0 +1,33 @@
1
+ import { warnUnlessButton } from "../../core/button.js";
2
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
3
+ import { renderElement } from "../../core/renderElement.js";
4
+ import { useDialogRootContext } from "../root/DialogRootContext.js";
5
+ import { isDev, spread, template } from "@solidjs/web";
6
+ import { merge, omit } from "solid-js";
7
+ // src/dialog/trigger/DialogTrigger.tsx
8
+ var _tmpl$ = /* @__PURE__ */ template(`<button>`);
9
+ /**
10
+ * The button that opens the dialog: a `<button type="button"
11
+ * aria-haspopup="dialog">`. Place it inside `Dialog.Root`.
12
+ */
13
+ function DialogTrigger(props) {
14
+ const root = useDialogRootContext();
15
+ const ownProps = merge(root.attributes, {
16
+ type: "button",
17
+ "aria-haspopup": "dialog",
18
+ onClick: (event) => root.setOpen(true, {
19
+ reason: "trigger-press",
20
+ event
21
+ }),
22
+ ref: (element) => {
23
+ if (isDev) warnUnlessButton(element, "Dialog.Trigger");
24
+ }
25
+ });
26
+ const elementProps = mergeElementProps(ownProps, omit(props, "render"));
27
+ return renderElement(props, elementProps, (p) => (() => {
28
+ var _el$ = _tmpl$();
29
+ spread(_el$, p, false);
30
+ return _el$;
31
+ })());
32
+ }
33
+ export { DialogTrigger };
@@ -0,0 +1,67 @@
1
+ import { createEffect, onFlush } from "solid-js";
2
+ // src/floating/dismissal/dialogClose.ts
3
+ /**
4
+ * Reports a modal `<dialog>` that the browser closes, while `open`: Escape
5
+ * and other close requests (`cancel`), and a `<form method="dialog">`
6
+ * (`close`). The popup closes through its own state:
7
+ *
8
+ * ```ts
9
+ * createDialogClose({
10
+ * get dialog() { return dialog; },
11
+ * get open() { return open(); },
12
+ * onDismiss: (details) => setOpen(false, details),
13
+ * });
14
+ * ```
15
+ *
16
+ * `cancel` is always prevented, so the state decides. The browser closes
17
+ * the dialog anyway when `cancel` cannot be prevented, such as on a second
18
+ * Escape: that close is reported once, and if the state still says open
19
+ * once it has settled, the dialog is opened again with `showModal()`. A
20
+ * close the popup made itself, after its state turned false, is not
21
+ * reported.
22
+ */
23
+ function createDialogClose(options) {
24
+ createEffect(() => options.open, (open) => {
25
+ const dialog = options.dialog;
26
+ if (!open || !dialog) return;
27
+ let escapeKey;
28
+ const keydown = (event) => {
29
+ if (event.key !== "Escape") return;
30
+ escapeKey = event;
31
+ setTimeout(() => {
32
+ if (escapeKey === event) escapeKey = void 0;
33
+ });
34
+ };
35
+ let reported = false;
36
+ const cancel = (event) => {
37
+ event.preventDefault();
38
+ reported = !event.cancelable;
39
+ options.onDismiss(escapeKey ? {
40
+ reason: "escape-key",
41
+ event: escapeKey
42
+ } : {
43
+ reason: "close-request",
44
+ event
45
+ });
46
+ };
47
+ const close = (event) => {
48
+ if (!reported) options.onDismiss({
49
+ reason: "close-request",
50
+ event
51
+ });
52
+ reported = false;
53
+ onFlush(() => {
54
+ if (options.open && !dialog.open) dialog.showModal();
55
+ });
56
+ };
57
+ document.addEventListener("keydown", keydown, true);
58
+ dialog.addEventListener("cancel", cancel);
59
+ dialog.addEventListener("close", close);
60
+ return () => {
61
+ document.removeEventListener("keydown", keydown, true);
62
+ dialog.removeEventListener("cancel", cancel);
63
+ dialog.removeEventListener("close", close);
64
+ };
65
+ });
66
+ }
67
+ export { createDialogClose };
@@ -0,0 +1,43 @@
1
+ import { createEffect } from "solid-js";
2
+ // src/floating/dismissal/escape.ts
3
+ /**
4
+ * Escape for a popup the browser does not close on Escape, a `manual`
5
+ * popover such as Tooltip's. While `open`, an Escape key calls `onDismiss`
6
+ * with the reason `escape-key`:
7
+ *
8
+ * ```ts
9
+ * createEscape({
10
+ * get open() { return open(); },
11
+ * onDismiss: (details) => setOpen(false, details),
12
+ * });
13
+ * ```
14
+ *
15
+ * Only the popup opened last closes, one per key. The key is marked
16
+ * handled (`preventDefault()`), so the browser does not also close a dialog
17
+ * or popover below, and carries on to the page's own listeners. A key
18
+ * already handled, or one pressed while an input method is composing, does
19
+ * nothing.
20
+ */
21
+ function createEscape(options) {
22
+ createEffect(() => options.open, (open) => {
23
+ if (!open) return;
24
+ const claim = (event) => {
25
+ event.menhirEscapeClaim = claim;
26
+ };
27
+ const close = (event) => {
28
+ if (event.key !== "Escape" || event.isComposing || event.defaultPrevented || event.menhirEscapeClaim !== claim) return;
29
+ event.preventDefault();
30
+ options.onDismiss({
31
+ reason: "escape-key",
32
+ event
33
+ });
34
+ };
35
+ document.addEventListener("keydown", claim, true);
36
+ document.addEventListener("keydown", close);
37
+ return () => {
38
+ document.removeEventListener("keydown", claim, true);
39
+ document.removeEventListener("keydown", close);
40
+ };
41
+ });
42
+ }
43
+ export { createEscape };
@@ -0,0 +1,52 @@
1
+ import { createEffect } from "solid-js";
2
+ // src/floating/dismissal/outsidePress.ts
3
+ /**
4
+ * Reports a press on a modal `<dialog>`'s backdrop, while `open`, with the
5
+ * reason `outside-press`. The popup closes through its own state:
6
+ *
7
+ * ```ts
8
+ * createOutsidePress({
9
+ * get dialog() { return dialog; },
10
+ * get open() { return open(); },
11
+ * onDismiss: (details) => setOpen(false, details),
12
+ * });
13
+ * ```
14
+ *
15
+ * A press on the backdrop targets the `<dialog>` itself, as one on its
16
+ * padding or its own scrollbar does, so the backdrop is where the target is
17
+ * the dialog and the point is outside its border box. It closes on release,
18
+ * as the browser's light dismiss does: on the `click` of a primary-button
19
+ * press that also started on the backdrop. So a press dragged out of the
20
+ * dialog, a secondary button (no `click`) and a touch that scrolls
21
+ * (`pointercancel`, no `click`) do not close it.
22
+ */
23
+ function createOutsidePress(options) {
24
+ createEffect(() => options.open, (open) => {
25
+ const dialog = options.dialog;
26
+ if (!open || !dialog) return;
27
+ const onBackdrop = (event) => {
28
+ if (event.target !== dialog) return false;
29
+ const { left, top, right, bottom } = dialog.getBoundingClientRect();
30
+ const { clientX: x, clientY: y } = event;
31
+ return x < left || x > right || y < top || y > bottom;
32
+ };
33
+ let pressed = false;
34
+ const pointerdown = (event) => {
35
+ pressed = event.button === 0 && onBackdrop(event);
36
+ };
37
+ const click = (event) => {
38
+ if (pressed && onBackdrop(event)) options.onDismiss({
39
+ reason: "outside-press",
40
+ event
41
+ });
42
+ pressed = false;
43
+ };
44
+ dialog.addEventListener("pointerdown", pointerdown);
45
+ dialog.addEventListener("click", click);
46
+ return () => {
47
+ dialog.removeEventListener("pointerdown", pointerdown);
48
+ dialog.removeEventListener("click", click);
49
+ };
50
+ });
51
+ }
52
+ export { createOutsidePress };
@@ -0,0 +1,74 @@
1
+ import { createEffect } from "solid-js";
2
+ // src/floating/dismissal/popoverClose.ts
3
+ /**
4
+ * Reports an `auto` popover that the browser closes, while `open`, with the
5
+ * reason. The popup closes through its own state:
6
+ *
7
+ * ```ts
8
+ * createPopoverClose({
9
+ * get popup() { return popup; },
10
+ * get trigger() { return trigger; },
11
+ * get open() { return open(); },
12
+ * onDismiss: (details) => setOpen(false, details),
13
+ * });
14
+ * ```
15
+ *
16
+ * The reason is the input event of the same task: an Escape key
17
+ * (`escape-key`), a pointer released outside the popover (`outside-press`,
18
+ * the browser's light dismiss) or a release or click on the trigger
19
+ * (`trigger-press`, its `popovertarget`); else `close-request`. The
20
+ * browser's close cannot be refused, so if the state still says open once
21
+ * it has settled, the popover is shown again. A close the popup made
22
+ * itself, after its state turned false, is not reported.
23
+ */
24
+ function createPopoverClose(options) {
25
+ createEffect(() => options.open, (open) => {
26
+ const popup = options.popup;
27
+ if (!open || !popup) return;
28
+ let cause;
29
+ const note = (reason, event) => {
30
+ const noted = {
31
+ reason,
32
+ event
33
+ };
34
+ cause = noted;
35
+ setTimeout(() => {
36
+ if (cause === noted) cause = void 0;
37
+ });
38
+ };
39
+ const keydown = (event) => {
40
+ if (event.key === "Escape") note("escape-key", event);
41
+ };
42
+ const pointerup = (event) => {
43
+ const target = event.target;
44
+ if (options.trigger?.contains(target)) note("trigger-press", event);
45
+ else if (!popup.contains(target)) note("outside-press", event);
46
+ };
47
+ const click = (event) => {
48
+ if (options.trigger?.contains(event.target)) note("trigger-press", event);
49
+ };
50
+ const beforetoggle = (event) => {
51
+ if (event.newState !== "closed" || !options.open) return;
52
+ options.onDismiss(cause ?? {
53
+ reason: "close-request",
54
+ event
55
+ });
56
+ };
57
+ const toggle = () => {
58
+ if (options.open && !popup.matches(":popover-open")) popup.showPopover();
59
+ };
60
+ document.addEventListener("keydown", keydown, true);
61
+ document.addEventListener("pointerup", pointerup, true);
62
+ document.addEventListener("click", click, true);
63
+ popup.addEventListener("beforetoggle", beforetoggle);
64
+ popup.addEventListener("toggle", toggle);
65
+ return () => {
66
+ document.removeEventListener("keydown", keydown, true);
67
+ document.removeEventListener("pointerup", pointerup, true);
68
+ document.removeEventListener("click", click, true);
69
+ popup.removeEventListener("beforetoggle", beforetoggle);
70
+ popup.removeEventListener("toggle", toggle);
71
+ };
72
+ });
73
+ }
74
+ export { createPopoverClose };
File without changes
@@ -0,0 +1,33 @@
1
+ import { createEffect } from "solid-js";
2
+ // src/floating/focus/initialFocus.ts
3
+ /**
4
+ * Moves focus to `initialFocus` once the popup has opened, instead of where
5
+ * the browser puts it: the element with `autofocus`, else a dialog's first
6
+ * focusable element, while a popover leaves focus on its trigger. Without
7
+ * `initialFocus` the browser decides.
8
+ *
9
+ * ```ts
10
+ * createInitialFocus({
11
+ * get popup() { return dialog; },
12
+ * get open() { return open(); },
13
+ * get initialFocus() { return props.initialFocus; },
14
+ * });
15
+ * ```
16
+ *
17
+ * A function is called on each opening with the element the browser focused
18
+ * inside the popup, or `null` when it focused none. The browser focuses
19
+ * first, so focus moves twice, in the same task, before anything is painted.
20
+ */
21
+ function createInitialFocus(options) {
22
+ createEffect(() => options.open, (open) => {
23
+ const popup = options.popup;
24
+ if (!open || !popup) return;
25
+ queueMicrotask(() => {
26
+ if (!popup.matches("[open], :popover-open")) return;
27
+ const active = document.activeElement;
28
+ const target = options.initialFocus;
29
+ (typeof target === "function" ? target(popup.contains(active) ? active : null) : target)?.focus();
30
+ });
31
+ });
32
+ }
33
+ export { createInitialFocus };