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
@@ -0,0 +1,116 @@
1
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
2
+ import { renderElement } from "../../core/renderElement.js";
3
+ import { createSlot } from "../../core/slot.js";
4
+ import { createPopoverClose } from "../../floating/dismissal/popoverClose.js";
5
+ import { createInitialFocus } from "../../floating/focus/initialFocus.js";
6
+ import { createReturnFocus } from "../../floating/focus/returnFocus.js";
7
+ import { createPosition } from "../../floating/positioning/createPosition.js";
8
+ import { flip } from "../../floating/positioning/flip.js";
9
+ import { offset } from "../../floating/positioning/offset.js";
10
+ import { shift } from "../../floating/positioning/shift.js";
11
+ import { createPresence } from "../../floating/presence/presence.js";
12
+ import { usePopoverRootContext } from "../root/PopoverRootContext.js";
13
+ import { PopoverPopupContext } from "./PopoverPopupContext.js";
14
+ import { createComponent, spread, template } from "@solidjs/web";
15
+ import { merge, omit } from "solid-js";
16
+ // src/popover/popup/PopoverPopup.tsx
17
+ var _tmpl$ = /* @__PURE__ */ template(`<div>`);
18
+ /**
19
+ * The popover itself: a `<div popover="auto" role="dialog">` in the top
20
+ * layer, placed against the Trigger. A press outside, Escape and the
21
+ * Trigger close it; the page stays usable. Named by `Popover.Title` and
22
+ * described by `Popover.Description` when they are rendered inside it.
23
+ * Place it inside `Popover.Root`, right after `Popover.Trigger`, so that
24
+ * Tab moves from the Trigger into it.
25
+ */
26
+ function PopoverPopup(props) {
27
+ const root = usePopoverRootContext();
28
+ let popup;
29
+ let focusInside = false;
30
+ const [arrow, registerArrow] = createSlot();
31
+ const options = {
32
+ get popup() {
33
+ return popup;
34
+ },
35
+ get trigger() {
36
+ return root.trigger;
37
+ },
38
+ get open() {
39
+ return root.open();
40
+ },
41
+ onDismiss: (details) => root.setOpen(false, details),
42
+ get initialFocus() {
43
+ return props.initialFocus;
44
+ },
45
+ get returnFocus() {
46
+ return props.returnFocus ?? ((focused) => focused ?? (focusInside ? root.trigger : void 0));
47
+ }
48
+ };
49
+ createPresence(options);
50
+ createPopoverClose(options);
51
+ createInitialFocus(options);
52
+ createReturnFocus(options);
53
+ const position = createPosition({
54
+ get anchor() {
55
+ const anchor = props.anchor;
56
+ return (typeof anchor === "function" ? anchor() : anchor) ?? root.trigger;
57
+ },
58
+ get popup() {
59
+ return popup;
60
+ },
61
+ get open() {
62
+ return root.open();
63
+ },
64
+ get side() {
65
+ return props.side;
66
+ },
67
+ get align() {
68
+ return props.align;
69
+ },
70
+ get middleware() {
71
+ const padding = props.collisionPadding ?? 5;
72
+ const middleware = [
73
+ offset({
74
+ mainAxis: props.sideOffset ?? 0,
75
+ alignmentAxis: props.alignOffset ?? 0
76
+ }),
77
+ flip({ padding }),
78
+ shift({ padding })
79
+ ];
80
+ const arrowMiddleware = arrow();
81
+ return arrowMiddleware ? [...middleware, arrowMiddleware] : middleware;
82
+ }
83
+ });
84
+ const ownProps = merge(root.attributes, {
85
+ id: root.popupId,
86
+ popover: "auto",
87
+ role: "dialog",
88
+ get "aria-labelledby"() {
89
+ return props["aria-labelledby"] ?? root.titleId();
90
+ },
91
+ get "aria-describedby"() {
92
+ return props["aria-describedby"] ?? root.descriptionId();
93
+ },
94
+ onBeforeToggle: (event) => {
95
+ focusInside = event.newState === "closed" && popup.contains(document.activeElement);
96
+ },
97
+ ref: (element) => {
98
+ popup = element;
99
+ }
100
+ });
101
+ const elementProps = mergeElementProps(ownProps, omit(props, "render", "side", "align", "sideOffset", "alignOffset", "collisionPadding", "anchor", "initialFocus", "returnFocus", "aria-labelledby", "aria-describedby", "id"));
102
+ return createComponent(PopoverPopupContext, {
103
+ value: {
104
+ position,
105
+ registerArrow
106
+ },
107
+ get children() {
108
+ return renderElement(props, elementProps, (p) => (() => {
109
+ var _el$ = _tmpl$();
110
+ spread(_el$, p, false);
111
+ return _el$;
112
+ })());
113
+ }
114
+ });
115
+ }
116
+ export { PopoverPopup };
@@ -0,0 +1,10 @@
1
+ import { isDev } from "@solidjs/web";
2
+ import { createContext, useContext } from "solid-js";
3
+ // src/popover/popup/PopoverPopupContext.ts
4
+ var PopoverPopupContext = createContext(null);
5
+ function usePopoverPopupContext() {
6
+ const context = useContext(PopoverPopupContext);
7
+ if (isDev && !context) throw new Error("[menhir] Popover.Arrow must be placed within <Popover.Popup>.");
8
+ return context;
9
+ }
10
+ export { PopoverPopupContext, usePopoverPopupContext };
@@ -0,0 +1,50 @@
1
+ import { createControllableSignal } from "../../core/createControllableSignal.js";
2
+ import { createIdSlot } from "../../core/slot.js";
3
+ import { PopoverRootContext } from "./PopoverRootContext.js";
4
+ import { createComponent } from "@solidjs/web";
5
+ import { createUniqueId } from "solid-js";
6
+ // src/popover/root/PopoverRoot.tsx
7
+ /**
8
+ * A non-modal popup placed against its trigger: holds whether it is open
9
+ * and shares it with `Popover.Trigger`, `Popover.Popup` and the parts
10
+ * inside it. Renders no element of its own.
11
+ */
12
+ function PopoverRoot(props) {
13
+ const [open, setOpen] = createControllableSignal({
14
+ get value() {
15
+ return props.open;
16
+ },
17
+ get defaultValue() {
18
+ return props.defaultOpen ?? false;
19
+ },
20
+ onChange: (value, details) => props.onOpenChange?.(value, details)
21
+ });
22
+ const attributes = {
23
+ get "data-open"() {
24
+ return open() ? "" : void 0;
25
+ },
26
+ get "data-closed"() {
27
+ return open() ? void 0 : "";
28
+ }
29
+ };
30
+ const [titleId, registerTitleId] = createIdSlot();
31
+ const [descriptionId, registerDescriptionId] = createIdSlot();
32
+ const context = {
33
+ open,
34
+ setOpen,
35
+ popupId: createUniqueId(),
36
+ trigger: void 0,
37
+ titleId,
38
+ registerTitleId,
39
+ descriptionId,
40
+ registerDescriptionId,
41
+ attributes
42
+ };
43
+ return createComponent(PopoverRootContext, {
44
+ value: context,
45
+ get children() {
46
+ return props.children;
47
+ }
48
+ });
49
+ }
50
+ export { PopoverRoot };
@@ -0,0 +1,10 @@
1
+ import { isDev } from "@solidjs/web";
2
+ import { createContext, useContext } from "solid-js";
3
+ // src/popover/root/PopoverRootContext.ts
4
+ var PopoverRootContext = createContext(null);
5
+ function usePopoverRootContext() {
6
+ const context = useContext(PopoverRootContext);
7
+ if (isDev && !context) throw new Error("[menhir] Popover parts must be placed within <Popover.Root>.");
8
+ return context;
9
+ }
10
+ export { PopoverRootContext, usePopoverRootContext };
@@ -0,0 +1,27 @@
1
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
2
+ import { renderElement } from "../../core/renderElement.js";
3
+ import { usePopoverRootContext } from "../root/PopoverRootContext.js";
4
+ import { spread, template } from "@solidjs/web";
5
+ import { createUniqueId, merge, omit, onSettled } from "solid-js";
6
+ // src/popover/title/PopoverTitle.tsx
7
+ var _tmpl$ = /* @__PURE__ */ template(`<h2>`);
8
+ /**
9
+ * The popover's title, which names the Popup in `aria-labelledby`: an
10
+ * `<h2>`. Place it inside `Popover.Popup`.
11
+ */
12
+ function PopoverTitle(props) {
13
+ const root = usePopoverRootContext();
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 { PopoverTitle };
@@ -0,0 +1,44 @@
1
+ import { warnUnlessButton } from "../../core/button.js";
2
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
3
+ import { renderElement } from "../../core/renderElement.js";
4
+ import { usePopoverRootContext } from "../root/PopoverRootContext.js";
5
+ import { isDev, spread, template } from "@solidjs/web";
6
+ import { merge, omit } from "solid-js";
7
+ // src/popover/trigger/PopoverTrigger.tsx
8
+ var _tmpl$ = /* @__PURE__ */ template(`<button>`);
9
+ /**
10
+ * The button that opens and closes the popover: a `<button type="button"
11
+ * aria-haspopup="dialog">` with `aria-expanded`, naming the Popup in
12
+ * `popovertarget` and `aria-controls`. Place it inside `Popover.Root`,
13
+ * right before `Popover.Popup`.
14
+ */
15
+ function PopoverTrigger(props) {
16
+ const root = usePopoverRootContext();
17
+ const ownProps = merge(root.attributes, {
18
+ type: "button",
19
+ popovertarget: root.popupId,
20
+ "aria-haspopup": "dialog",
21
+ get "aria-expanded"() {
22
+ return root.open() ? "true" : "false";
23
+ },
24
+ "aria-controls": root.popupId,
25
+ onClick: (event) => {
26
+ event.preventDefault();
27
+ root.setOpen(!root.open(), {
28
+ reason: "trigger-press",
29
+ event
30
+ });
31
+ },
32
+ ref: (element) => {
33
+ root.trigger = element;
34
+ if (isDev) warnUnlessButton(element, "Popover.Trigger");
35
+ }
36
+ });
37
+ const elementProps = mergeElementProps(ownProps, omit(props, "render"));
38
+ return renderElement(props, elementProps, (p) => (() => {
39
+ var _el$ = _tmpl$();
40
+ spread(_el$, p, false);
41
+ return _el$;
42
+ })());
43
+ }
44
+ export { PopoverTrigger };
@@ -0,0 +1 @@
1
+ export * as AlertDialog from "./index.parts.ts";
@@ -0,0 +1 @@
1
+ export * as AlertDialog from "./index.parts.js";
@@ -0,0 +1,6 @@
1
+ export { DialogRoot as Root } from "../dialog/root/DialogRoot.tsx";
2
+ export { DialogTrigger as Trigger } from "../dialog/trigger/DialogTrigger.tsx";
3
+ export { AlertDialogPopup as Popup } from "./popup/AlertDialogPopup.tsx";
4
+ export { DialogTitle as Title } from "../dialog/title/DialogTitle.tsx";
5
+ export { DialogDescription as Description } from "../dialog/description/DialogDescription.tsx";
6
+ export { DialogClose as Close } from "../dialog/close/DialogClose.tsx";
@@ -0,0 +1,7 @@
1
+ // Dialog's parts, but the Popup (README, "Decisions"; #32).
2
+ export { DialogRoot as Root } from "../dialog/root/DialogRoot.jsx";
3
+ export { DialogTrigger as Trigger } from "../dialog/trigger/DialogTrigger.jsx";
4
+ export { AlertDialogPopup as Popup } from "./popup/AlertDialogPopup.jsx";
5
+ export { DialogTitle as Title } from "../dialog/title/DialogTitle.jsx";
6
+ export { DialogDescription as Description } from "../dialog/description/DialogDescription.jsx";
7
+ export { DialogClose as Close } from "../dialog/close/DialogClose.jsx";
@@ -0,0 +1,10 @@
1
+ import type { DialogPopupProps } from "../../dialog/popup/renderDialogPopup.tsx";
2
+ export type AlertDialogPopupProps = DialogPopupProps;
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
+ export declare function AlertDialogPopup(props: AlertDialogPopupProps): import("@solidjs/web").JSX.Element;
@@ -0,0 +1,11 @@
1
+ import { renderDialogPopup } from "../../dialog/popup/renderDialogPopup.jsx";
2
+ /**
3
+ * The alert dialog itself: a `<dialog role="alertdialog">`, opened with
4
+ * `showModal()`, so it is modal, in the top layer, over an inert page.
5
+ * Named by `AlertDialog.Title` and described by `AlertDialog.Description`,
6
+ * the message, when they are rendered inside it. Escape closes it; a press
7
+ * on the backdrop does not. Place it inside `AlertDialog.Root`.
8
+ */
9
+ export function AlertDialogPopup(props) {
10
+ return renderDialogPopup(props, undefined, "alertdialog");
11
+ }
@@ -18,10 +18,11 @@ import type { Accessor } from "solid-js";
18
18
  * (`onFlush`), so async work that `onChange` starts does not hold it back.
19
19
  * Setting the value it already has, counting earlier sets in the same turn,
20
20
  * does nothing. Set from event handlers, not from a component body or a
21
- * memo.
21
+ * memo. A set may pass `details`, such as why a popup closed, which
22
+ * `onChange` receives after the value.
22
23
  */
23
- export declare function createControllableSignal<T>(options: {
24
+ export declare function createControllableSignal<T, Details = void>(options: {
24
25
  readonly value?: T;
25
26
  readonly defaultValue: T;
26
- onChange?: (value: T) => void;
27
- }): [value: Accessor<T>, setValue: (next: T) => void];
27
+ onChange?: (value: T, details: Details) => void;
28
+ }): [value: Accessor<T>, setValue: (next: T, details: Details) => void];
@@ -19,7 +19,8 @@ import { createSignal, onFlush, untrack } from "solid-js";
19
19
  * (`onFlush`), so async work that `onChange` starts does not hold it back.
20
20
  * Setting the value it already has, counting earlier sets in the same turn,
21
21
  * does nothing. Set from event handlers, not from a component body or a
22
- * memo.
22
+ * memo. A set may pass `details`, such as why a popup closed, which
23
+ * `onChange` receives after the value.
23
24
  */
24
25
  export function createControllableSignal(options) {
25
26
  // A writable derived signal that reads the default once, untracked, so a
@@ -51,7 +52,7 @@ export function createControllableSignal(options) {
51
52
  // Reads lag writes, so a set is compared with the last value set in this
52
53
  // turn, if any, not with what `value` still reads.
53
54
  let pending;
54
- const setValue = (next) => {
55
+ const setValue = (next, details) => {
55
56
  if (Object.is(next, pending ? pending[0] : untrack(value)))
56
57
  return;
57
58
  // The part's own write is an update of its own, after the pending
@@ -60,7 +61,7 @@ export function createControllableSignal(options) {
60
61
  // until that work settled.
61
62
  if (!untrack(isControlled))
62
63
  onFlush(() => setInternal(() => next));
63
- options.onChange?.(next);
64
+ options.onChange?.(next, details);
64
65
  const set = [next];
65
66
  pending = set;
66
67
  // `onFlush` callbacks run in call order, each flushed before the next,
@@ -0,0 +1,21 @@
1
+ /**
2
+ * A value that one part registers once mounted, for another part to read,
3
+ * such as the Arrow's middleware, which a popup's Popup uses to place it.
4
+ * Returns the value, `undefined` while none is registered, and `register`,
5
+ * which takes the value as a getter and returns what unregisters it, for
6
+ * the part's disposal. Unregistering removes only the part's own value, so
7
+ * one that another part registered after it stays.
8
+ */
9
+ export declare function createSlot<T>(): [
10
+ value: () => T | undefined,
11
+ register: (value: () => T) => () => void
12
+ ];
13
+ /**
14
+ * A slot for the `id` of a part that another part names, such as a popup's
15
+ * Title, which the Popup names in `aria-labelledby`. `false`, a consumer's
16
+ * way to remove the part's `id`, names nothing.
17
+ */
18
+ export declare function createIdSlot(): [
19
+ id: () => string | undefined,
20
+ register: (id: () => string | false) => () => void
21
+ ];
@@ -0,0 +1,28 @@
1
+ import { createSignal } from "solid-js";
2
+ /**
3
+ * A value that one part registers once mounted, for another part to read,
4
+ * such as the Arrow's middleware, which a popup's Popup uses to place it.
5
+ * Returns the value, `undefined` while none is registered, and `register`,
6
+ * which takes the value as a getter and returns what unregisters it, for
7
+ * the part's disposal. Unregistering removes only the part's own value, so
8
+ * one that another part registered after it stays.
9
+ */
10
+ export function createSlot() {
11
+ const [slot, setSlot] = createSignal();
12
+ const value = () => slot()?.();
13
+ const register = (next) => {
14
+ setSlot(() => next);
15
+ return () => setSlot((current) => (current === next ? undefined : current));
16
+ };
17
+ return [value, register];
18
+ }
19
+ /**
20
+ * A slot for the `id` of a part that another part names, such as a popup's
21
+ * Title, which the Popup names in `aria-labelledby`. `false`, a consumer's
22
+ * way to remove the part's `id`, names nothing.
23
+ */
24
+ export function createIdSlot() {
25
+ const [slot, register] = createSlot();
26
+ const id = () => slot() || undefined;
27
+ return [id, register];
28
+ }
@@ -0,0 +1,11 @@
1
+ import type { JSX } from "@solidjs/web";
2
+ import type { RenderProp } from "../../core/renderElement.tsx";
3
+ export interface DialogCloseProps extends JSX.HTMLAttributes<HTMLElement> {
4
+ render?: RenderProp;
5
+ }
6
+ /**
7
+ * A button that closes the dialog: a `<button type="button">`, such as
8
+ * "Cancel" or a close icon with an `aria-label`. Place it inside
9
+ * `Dialog.Popup`.
10
+ */
11
+ export declare function DialogClose(props: DialogCloseProps): JSX.Element;
@@ -0,0 +1,25 @@
1
+ import { isDev } from "@solidjs/web";
2
+ import { merge, omit } from "solid-js";
3
+ import { warnUnlessButton } from "../../core/button.js";
4
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
5
+ import { renderElement } from "../../core/renderElement.jsx";
6
+ import { useDialogRootContext } from "../root/DialogRootContext.js";
7
+ /**
8
+ * A button that closes the dialog: a `<button type="button">`, such as
9
+ * "Cancel" or a close icon with an `aria-label`. Place it inside
10
+ * `Dialog.Popup`.
11
+ */
12
+ export function DialogClose(props) {
13
+ const root = useDialogRootContext();
14
+ const ownProps = merge(root.attributes, {
15
+ type: "button",
16
+ onClick: (event) => root.setOpen(false, { reason: "close-press", event }),
17
+ ref: (element) => {
18
+ // Production builds drop the check with `isDev`.
19
+ if (isDev)
20
+ warnUnlessButton(element, "Dialog.Close");
21
+ },
22
+ });
23
+ const elementProps = mergeElementProps(ownProps, omit(props, "render"));
24
+ return renderElement(props, elementProps, (p) => <button {...p}/>);
25
+ }
@@ -0,0 +1,10 @@
1
+ import type { JSX } from "@solidjs/web";
2
+ import type { RenderProp } from "../../core/renderElement.tsx";
3
+ export interface DialogDescriptionProps extends JSX.HTMLAttributes<HTMLElement> {
4
+ render?: RenderProp;
5
+ }
6
+ /**
7
+ * What the dialog is for, which describes the Popup in
8
+ * `aria-describedby`: a `<p>`. Place it inside `Dialog.Popup`.
9
+ */
10
+ export declare function DialogDescription(props: DialogDescriptionProps): JSX.Element;
@@ -0,0 +1,26 @@
1
+ import { createUniqueId, merge, omit, onSettled } from "solid-js";
2
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
3
+ import { renderElement } from "../../core/renderElement.jsx";
4
+ import { useDialogRootContext } from "../root/DialogRootContext.js";
5
+ /**
6
+ * What the dialog is for, which describes the Popup in
7
+ * `aria-describedby`: a `<p>`. Place it inside `Dialog.Popup`.
8
+ */
9
+ export function DialogDescription(props) {
10
+ const root = useDialogRootContext();
11
+ const generated = createUniqueId();
12
+ // The consumer's `id`, else the generated one. Kept out of the merge,
13
+ // where a wrapper's `id={undefined}` would remove it ("`undefined` is a
14
+ // value", PLAN.md section 8).
15
+ const id = () => props.id ?? generated;
16
+ // Named once mounted, so the Popup names only a Description that is
17
+ // rendered, and none in the server HTML (README, "Decisions").
18
+ onSettled(() => root.registerDescriptionId(id));
19
+ const ownProps = merge(root.attributes, {
20
+ get id() {
21
+ return id();
22
+ },
23
+ });
24
+ const elementProps = mergeElementProps(ownProps, omit(props, "render", "id"));
25
+ return renderElement(props, elementProps, (p) => <p {...p}/>);
26
+ }
@@ -0,0 +1 @@
1
+ export * as Dialog from "./index.parts.ts";
@@ -0,0 +1 @@
1
+ export * as Dialog from "./index.parts.js";
@@ -0,0 +1,6 @@
1
+ export { DialogRoot as Root } from "./root/DialogRoot.tsx";
2
+ export { DialogTrigger as Trigger } from "./trigger/DialogTrigger.tsx";
3
+ export { DialogPopup as Popup } from "./popup/DialogPopup.tsx";
4
+ export { DialogTitle as Title } from "./title/DialogTitle.tsx";
5
+ export { DialogDescription as Description } from "./description/DialogDescription.tsx";
6
+ export { DialogClose as Close } from "./close/DialogClose.tsx";
@@ -0,0 +1,6 @@
1
+ export { DialogRoot as Root } from "./root/DialogRoot.jsx";
2
+ export { DialogTrigger as Trigger } from "./trigger/DialogTrigger.jsx";
3
+ export { DialogPopup as Popup } from "./popup/DialogPopup.jsx";
4
+ export { DialogTitle as Title } from "./title/DialogTitle.jsx";
5
+ export { DialogDescription as Description } from "./description/DialogDescription.jsx";
6
+ export { DialogClose as Close } from "./close/DialogClose.jsx";
@@ -0,0 +1,9 @@
1
+ import type { DialogPopupProps } from "./renderDialogPopup.tsx";
2
+ export type { DialogPopupProps } from "./renderDialogPopup.tsx";
3
+ /**
4
+ * The dialog itself: a `<dialog>`, opened with `showModal()`, so it is
5
+ * modal, in the top layer, over an inert page. Named by `Dialog.Title` and
6
+ * described by `Dialog.Description` when they are rendered inside it. A
7
+ * press on the backdrop closes it. Place it inside `Dialog.Root`.
8
+ */
9
+ export declare function DialogPopup(props: DialogPopupProps): import("@solidjs/web").JSX.Element;
@@ -0,0 +1,11 @@
1
+ import { createOutsidePress } from "../../floating/dismissal/outsidePress.js";
2
+ import { renderDialogPopup } from "./renderDialogPopup.jsx";
3
+ /**
4
+ * The dialog itself: a `<dialog>`, opened with `showModal()`, so it is
5
+ * modal, in the top layer, over an inert page. Named by `Dialog.Title` and
6
+ * described by `Dialog.Description` when they are rendered inside it. A
7
+ * press on the backdrop closes it. Place it inside `Dialog.Root`.
8
+ */
9
+ export function DialogPopup(props) {
10
+ return renderDialogPopup(props, createOutsidePress);
11
+ }
@@ -0,0 +1,40 @@
1
+ import type { JSX } from "@solidjs/web";
2
+ import type { ElementProps } from "../../core/renderElement.tsx";
3
+ import type { OpenChangeDetails } from "../../floating/dismissal/reason.ts";
4
+ import type { FocusTarget } from "../../floating/focus/target.ts";
5
+ type DialogElementProps = Omit<ElementProps, "tabindex">;
6
+ export interface DialogPopupProps extends Omit<JSX.HTMLAttributes<HTMLElement>, "tabindex"> {
7
+ /**
8
+ * Where focus goes once the dialog has opened, instead of the browser's
9
+ * choice: the element with `autofocus`, else the first focusable one. An
10
+ * element, or a function called on each opening with the browser's
11
+ * choice, such as `() => input` for an element reached through a ref.
12
+ */
13
+ initialFocus?: FocusTarget;
14
+ /**
15
+ * Where focus goes once the dialog has closed, instead of the browser's
16
+ * choice: the element focused before it opened. An element, or a function
17
+ * called with the browser's choice, or `null` when it found none, such as
18
+ * `(focused) => focused ?? fallback`.
19
+ */
20
+ returnFocus?: FocusTarget;
21
+ /** Must render a `<dialog>`, which the Popup opens with `showModal()`. */
22
+ render?: (props: DialogElementProps) => JSX.Element;
23
+ }
24
+ /** What the Popup hands to `outsidePress`, as getters. */
25
+ export interface DialogPopupOptions {
26
+ readonly dialog: HTMLDialogElement | undefined;
27
+ readonly open: boolean;
28
+ onDismiss(details: OpenChangeDetails): void;
29
+ }
30
+ /**
31
+ * What a modal dialog's Popup does, for `Dialog.Popup` and
32
+ * `AlertDialog.Popup` (#32): a `<dialog>` opened with `showModal()`, closed
33
+ * by a close request, with Tab wrapping inside, the focus props, the page's
34
+ * scroll locked, and named by its Title and Description. `outsidePress`
35
+ * adds Dialog's press on the backdrop, so that Alert Dialog does not bundle
36
+ * it; `role` is Alert Dialog's `alertdialog`. Two arguments, not an
37
+ * options object, which measured 14 B more in `menhir/dialog`.
38
+ */
39
+ export declare function renderDialogPopup(props: DialogPopupProps, outsidePress?: (options: DialogPopupOptions) => void, role?: "alertdialog"): JSX.Element;
40
+ export {};
@@ -0,0 +1,73 @@
1
+ import { isDev } from "@solidjs/web";
2
+ import { merge, omit } from "solid-js";
3
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
4
+ import { renderElement } from "../../core/renderElement.jsx";
5
+ import { createDialogClose } from "../../floating/dismissal/dialogClose.js";
6
+ import { createInitialFocus } from "../../floating/focus/initialFocus.js";
7
+ import { createReturnFocus } from "../../floating/focus/returnFocus.js";
8
+ import { createTabWrap } from "../../floating/focus/tabWrap.js";
9
+ import { createPresence } from "../../floating/presence/presence.js";
10
+ import { createScrollLock } from "../../floating/scroll-lock/scrollLock.js";
11
+ import { useDialogRootContext } from "../root/DialogRootContext.js";
12
+ /**
13
+ * What a modal dialog's Popup does, for `Dialog.Popup` and
14
+ * `AlertDialog.Popup` (#32): a `<dialog>` opened with `showModal()`, closed
15
+ * by a close request, with Tab wrapping inside, the focus props, the page's
16
+ * scroll locked, and named by its Title and Description. `outsidePress`
17
+ * adds Dialog's press on the backdrop, so that Alert Dialog does not bundle
18
+ * it; `role` is Alert Dialog's `alertdialog`. Two arguments, not an
19
+ * options object, which measured 14 B more in `menhir/dialog`.
20
+ */
21
+ export function renderDialogPopup(props, outsidePress, role) {
22
+ const root = useDialogRootContext();
23
+ let dialog;
24
+ // What every module of the `floating` layer takes, as getters.
25
+ const options = {
26
+ get dialog() {
27
+ return dialog;
28
+ },
29
+ get popup() {
30
+ return dialog;
31
+ },
32
+ get open() {
33
+ return root.open();
34
+ },
35
+ onDismiss: (details) => root.setOpen(false, details),
36
+ get initialFocus() {
37
+ return props.initialFocus;
38
+ },
39
+ get returnFocus() {
40
+ return props.returnFocus;
41
+ },
42
+ };
43
+ createPresence(options);
44
+ createDialogClose(options);
45
+ outsidePress?.(options);
46
+ createScrollLock(options);
47
+ createTabWrap(options);
48
+ createInitialFocus(options);
49
+ createReturnFocus(options);
50
+ const ownProps = merge(root.attributes, {
51
+ role,
52
+ // The consumer's, else the Title's and Description's ids. Kept out of
53
+ // the merge, where a wrapper's `aria-labelledby={undefined}` would
54
+ // remove the Title's ("`undefined` is a value", PLAN.md section 8);
55
+ // `false` removes it.
56
+ get "aria-labelledby"() {
57
+ return props["aria-labelledby"] ?? root.titleId();
58
+ },
59
+ get "aria-describedby"() {
60
+ return props["aria-describedby"] ?? root.descriptionId();
61
+ },
62
+ ref: (element) => {
63
+ // Production builds drop the check, and the part's name, with `isDev`.
64
+ if (isDev && !(element instanceof HTMLDialogElement)) {
65
+ console.warn(`[menhir] ${role ? "AlertDialog" : "Dialog"}.Popup's render function rendered a <${element.tagName.toLowerCase()}>. ` +
66
+ "Render a <dialog>, which the Popup opens with showModal().");
67
+ }
68
+ dialog = element;
69
+ },
70
+ });
71
+ const elementProps = mergeElementProps(ownProps, omit(props, "render", "initialFocus", "returnFocus", "aria-labelledby", "aria-describedby"));
72
+ return renderElement(props, elementProps, (p) => (<dialog {...p}/>));
73
+ }