@funstack/ui 0.1.0-alpha.13 → 0.1.0-alpha.15

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 (106) hide show
  1. package/dist/accordion/accordion-root.d.mts.map +1 -1
  2. package/dist/accordion/accordion-root.mjs +5 -4
  3. package/dist/accordion/accordion-root.mjs.map +1 -1
  4. package/dist/checkbox-group/checkbox-group-root.d.mts.map +1 -1
  5. package/dist/checkbox-group/checkbox-group-root.mjs +4 -5
  6. package/dist/checkbox-group/checkbox-group-root.mjs.map +1 -1
  7. package/dist/combobox/combobox-context.mjs.map +1 -1
  8. package/dist/combobox/combobox-input.d.mts +7 -6
  9. package/dist/combobox/combobox-input.d.mts.map +1 -1
  10. package/dist/combobox/combobox-input.mjs +6 -5
  11. package/dist/combobox/combobox-input.mjs.map +1 -1
  12. package/dist/combobox/combobox-label.d.mts +2 -1
  13. package/dist/combobox/combobox-label.d.mts.map +1 -1
  14. package/dist/combobox/combobox-label.mjs +2 -1
  15. package/dist/combobox/combobox-label.mjs.map +1 -1
  16. package/dist/combobox/combobox-popup.d.mts +4 -2
  17. package/dist/combobox/combobox-popup.d.mts.map +1 -1
  18. package/dist/combobox/combobox-popup.mjs +7 -3
  19. package/dist/combobox/combobox-popup.mjs.map +1 -1
  20. package/dist/combobox/combobox-root.d.mts.map +1 -1
  21. package/dist/combobox/combobox-root.mjs +9 -80
  22. package/dist/combobox/combobox-root.mjs.map +1 -1
  23. package/dist/combobox/combobox-trigger.d.mts +15 -10
  24. package/dist/combobox/combobox-trigger.d.mts.map +1 -1
  25. package/dist/combobox/combobox-trigger.mjs +28 -19
  26. package/dist/combobox/combobox-trigger.mjs.map +1 -1
  27. package/dist/combobox/index.d.mts +2 -2
  28. package/dist/combobox/index.mjs +2 -2
  29. package/dist/combobox/index.mjs.map +1 -1
  30. package/dist/combobox/use-deferred-leave.mjs +105 -0
  31. package/dist/combobox/use-deferred-leave.mjs.map +1 -0
  32. package/dist/dialog/dialog-context.mjs.map +1 -1
  33. package/dist/dialog/dialog-popup.d.mts.map +1 -1
  34. package/dist/dialog/dialog-popup.mjs +5 -4
  35. package/dist/dialog/dialog-popup.mjs.map +1 -1
  36. package/dist/dialog/dialog-trigger.mjs.map +1 -1
  37. package/dist/form/form-root.mjs +1 -1
  38. package/dist/form/form-root.mjs.map +1 -1
  39. package/dist/internal/anchor-position.mjs.map +1 -1
  40. package/dist/internal/announce.mjs +12 -7
  41. package/dist/internal/announce.mjs.map +1 -1
  42. package/dist/internal/focus-first-invalid.mjs +2 -11
  43. package/dist/internal/focus-first-invalid.mjs.map +1 -1
  44. package/dist/internal/focus-visible.mjs +26 -0
  45. package/dist/internal/focus-visible.mjs.map +1 -0
  46. package/dist/internal/invokers.mjs +63 -0
  47. package/dist/internal/invokers.mjs.map +1 -0
  48. package/dist/internal/platform-attributes.d.mts +2 -1
  49. package/dist/internal/platform-attributes.d.mts.map +1 -1
  50. package/dist/internal/pointer-capture.mjs +1 -1
  51. package/dist/internal/pointer-capture.mjs.map +1 -1
  52. package/dist/internal/render-element.mjs.map +1 -1
  53. package/dist/internal/trigger-ref.mjs +3 -3
  54. package/dist/internal/trigger-ref.mjs.map +1 -1
  55. package/dist/internal/use-interest-dismiss.mjs +84 -0
  56. package/dist/internal/use-interest-dismiss.mjs.map +1 -0
  57. package/dist/internal/use-overlay-root.mjs +2 -1
  58. package/dist/internal/use-overlay-root.mjs.map +1 -1
  59. package/dist/internal/use-popover-popup.mjs +59 -48
  60. package/dist/internal/use-popover-popup.mjs.map +1 -1
  61. package/dist/internal/use-popover-trigger.d.mts.map +1 -1
  62. package/dist/internal/use-popover-trigger.mjs +37 -15
  63. package/dist/internal/use-popover-trigger.mjs.map +1 -1
  64. package/dist/internal/use-resolved-placement.mjs +1 -1
  65. package/dist/internal/use-resolved-placement.mjs.map +1 -1
  66. package/dist/internal/use-value-set.mjs +20 -0
  67. package/dist/internal/use-value-set.mjs.map +1 -0
  68. package/dist/menu/menu-context.mjs.map +1 -1
  69. package/dist/menu/menu-popup.d.mts +3 -1
  70. package/dist/menu/menu-popup.d.mts.map +1 -1
  71. package/dist/menu/menu-popup.mjs +15 -18
  72. package/dist/menu/menu-popup.mjs.map +1 -1
  73. package/dist/menu/menu-submenu-trigger.d.mts +11 -9
  74. package/dist/menu/menu-submenu-trigger.d.mts.map +1 -1
  75. package/dist/menu/menu-submenu-trigger.mjs +11 -10
  76. package/dist/menu/menu-submenu-trigger.mjs.map +1 -1
  77. package/dist/menu/menu-trigger.d.mts +13 -10
  78. package/dist/menu/menu-trigger.d.mts.map +1 -1
  79. package/dist/menu/menu-trigger.mjs +10 -14
  80. package/dist/menu/menu-trigger.mjs.map +1 -1
  81. package/dist/number-field/number-field-root.mjs +1 -1
  82. package/dist/popover/index.d.mts +1 -1
  83. package/dist/popover/index.mjs +1 -1
  84. package/dist/popover/index.mjs.map +1 -1
  85. package/dist/popover/popover-close.d.mts +5 -3
  86. package/dist/popover/popover-close.d.mts.map +1 -1
  87. package/dist/popover/popover-close.mjs +3 -1
  88. package/dist/popover/popover-close.mjs.map +1 -1
  89. package/dist/popover/popover-popup.d.mts +1 -1
  90. package/dist/popover/popover-popup.mjs +1 -1
  91. package/dist/popover/popover-popup.mjs.map +1 -1
  92. package/dist/popover/popover-root.d.mts +1 -1
  93. package/dist/popover/popover-root.mjs +1 -1
  94. package/dist/popover/popover-root.mjs.map +1 -1
  95. package/dist/popover/popover-trigger.d.mts +10 -9
  96. package/dist/popover/popover-trigger.d.mts.map +1 -1
  97. package/dist/popover/popover-trigger.mjs +9 -8
  98. package/dist/popover/popover-trigger.mjs.map +1 -1
  99. package/dist/toast/toast-root.mjs.map +1 -1
  100. package/dist/toast/toast-viewport.d.mts.map +1 -1
  101. package/dist/toast/toast-viewport.mjs +4 -5
  102. package/dist/toast/toast-viewport.mjs.map +1 -1
  103. package/dist/toggle-group/toggle-group-root.d.mts.map +1 -1
  104. package/dist/toggle-group/toggle-group-root.mjs +4 -5
  105. package/dist/toggle-group/toggle-group-root.mjs.map +1 -1
  106. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"focus-first-invalid.mjs","names":[],"sources":["../../src/internal/focus-first-invalid.ts"],"sourcesContent":["// Directive-free: the module-level first-invalid collector (design/components/field-form.md 2.5).\nimport type { AriaNotifyTarget } from \"./announce.js\";\nimport { sortByDocumentOrder } from \"./dom-order.js\";\n\ninterface Batch {\n /** The elements whose `invalid` event was collected (a group's members, not its target). */\n readonly sources: Set<Element>;\n readonly targets: HTMLElement[];\n /** The message each target's Field shows, for the announcement when focus does not move. */\n readonly messages: Map<HTMLElement, string>;\n /** `document.activeElement` when the first target arrived. */\n readonly activeBefore: Element | null;\n /** The batch moved focus (later microtasks then re-focus, never announce). */\n moved: boolean;\n /** The target already announced. */\n announced: HTMLElement | null;\n}\n\ntype NotifyingElement = HTMLElement & AriaNotifyTarget;\n\n/**\n * Speaks `message` through `element.ariaNotify()` where the browser has it (design 5.3: the\n * error is read when focus moves to the control; when focus is already there nothing would be\n * read). Does nothing without `ariaNotify` or with an empty message.\n */\nexport function announce(element: HTMLElement, message: string): void {\n const notifying = element as NotifyingElement;\n if (message === \"\" || typeof notifying.ariaNotify !== \"function\") return;\n notifying.ariaNotify(message);\n}\n\n/** The submission attempt in progress: every target added during the current task. */\nlet batch: Batch | null = null;\n\n/**\n * Adds a control whose `invalid` event (fired on `source`) a Field cancelled during a submission\n * attempt, and focuses the first collected control in document order in a microtask, so the\n * result does not depend on the browser's dispatch order or on how many forms are on the page.\n *\n * The batch lives until the end of the task (a `setTimeout`), not just one microtask: when the\n * browser dispatches the `invalid` events itself (a click on a submit button), it runs a\n * microtask checkpoint after each listener, so the microtask of the first event runs before the\n * second event fires. Every add therefore queues a focus of the batch's first target; later ones\n * re-focus the same element, which is a no-op.\n *\n * A second `invalid` for the same `source` (the element the event fired on) starts a new batch:\n * one validation fires it once per element, so it belongs to the next attempt, even when that\n * attempt comes before the timer (two attempts in one task, or a test that does not yield to\n * timers between them). Joining the old batch would compare focus with the old attempt's.\n *\n * Skips the focus when focus moved during the attempt to an element that is not one of the\n * collected targets: a plain `<input required>` with no Field kept the platform's behaviour\n * (bubble and focus), and the library does not fight it.\n */\nexport function collectInvalid(target: HTMLElement | null, message: string, source: Element): void {\n if (target === null) return;\n if (batch !== null && batch.sources.has(source)) batch = null;\n if (batch === null) {\n const created: Batch = {\n sources: new Set(),\n targets: [],\n messages: new Map(),\n activeBefore: target.ownerDocument.activeElement,\n moved: false,\n announced: null,\n };\n batch = created;\n setTimeout(() => {\n if (batch === created) batch = null;\n }, 0);\n }\n const current = batch;\n current.sources.add(source);\n if (!current.targets.includes(target)) current.targets.push(target);\n current.messages.set(target, message);\n queueMicrotask(() => focusFirst(current));\n}\n\nfunction focusFirst(current: Batch): void {\n const { targets, activeBefore } = current;\n const connected = targets.filter((t) => t.isConnected);\n if (connected.length === 0) return;\n const active = connected[0]!.ownerDocument.activeElement;\n if (active !== activeBefore && active !== null && !connected.includes(active as HTMLElement)) {\n return;\n }\n const first = sortByDocumentOrder(connected, (t) => t)[0]!;\n if (active !== first) {\n current.moved = true;\n first.focus();\n } else if (!current.moved && current.announced !== first) {\n // Focus was already on the first invalid control (an implicit submission with Enter): the\n // cancelled bubble was the only announcement, so speak the message instead.\n current.announced = first;\n announce(first, current.messages.get(first) ?? \"\");\n }\n}\n"],"mappings":";;;;;;;AAyBA,SAAgB,SAAS,SAAsB,SAAuB;CACpE,MAAM,YAAY;CAClB,IAAI,YAAY,MAAM,OAAO,UAAU,eAAe,YAAY;CAClE,UAAU,WAAW,OAAO;AAC9B;;AAGA,IAAI,QAAsB;;;;;;;;;;;;;;;;;;;;;AAsB1B,SAAgB,eAAe,QAA4B,SAAiB,QAAuB;CACjG,IAAI,WAAW,MAAM;CACrB,IAAI,UAAU,QAAQ,MAAM,QAAQ,IAAI,MAAM,GAAG,QAAQ;CACzD,IAAI,UAAU,MAAM;EAClB,MAAM,UAAiB;GACrB,yBAAS,IAAI,IAAI;GACjB,SAAS,CAAC;GACV,0BAAU,IAAI,IAAI;GAClB,cAAc,OAAO,cAAc;GACnC,OAAO;GACP,WAAW;EACb;EACA,QAAQ;EACR,iBAAiB;GACf,IAAI,UAAU,SAAS,QAAQ;EACjC,GAAG,CAAC;CACN;CACA,MAAM,UAAU;CAChB,QAAQ,QAAQ,IAAI,MAAM;CAC1B,IAAI,CAAC,QAAQ,QAAQ,SAAS,MAAM,GAAG,QAAQ,QAAQ,KAAK,MAAM;CAClE,QAAQ,SAAS,IAAI,QAAQ,OAAO;CACpC,qBAAqB,WAAW,OAAO,CAAC;AAC1C;AAEA,SAAS,WAAW,SAAsB;CACxC,MAAM,EAAE,SAAS,iBAAiB;CAClC,MAAM,YAAY,QAAQ,QAAQ,MAAM,EAAE,WAAW;CACrD,IAAI,UAAU,WAAW,GAAG;CAC5B,MAAM,SAAS,UAAU,EAAE,CAAE,cAAc;CAC3C,IAAI,WAAW,gBAAgB,WAAW,QAAQ,CAAC,UAAU,SAAS,MAAqB,GACzF;CAEF,MAAM,QAAQ,oBAAoB,YAAY,MAAM,CAAC,CAAC,CAAC;CACvD,IAAI,WAAW,OAAO;EACpB,QAAQ,QAAQ;EAChB,MAAM,MAAM;CACd,OAAO,IAAI,CAAC,QAAQ,SAAS,QAAQ,cAAc,OAAO;EAGxD,QAAQ,YAAY;EACpB,SAAS,OAAO,QAAQ,SAAS,IAAI,KAAK,KAAK,EAAE;CACnD;AACF"}
1
+ {"version":3,"file":"focus-first-invalid.mjs","names":[],"sources":["../../src/internal/focus-first-invalid.ts"],"sourcesContent":["// Directive-free: the module-level first-invalid collector (design/components/field-form.md 2.5).\nimport { announce } from \"./announce.js\";\nimport { sortByDocumentOrder } from \"./dom-order.js\";\n\ninterface Batch {\n /** The elements whose `invalid` event was collected (a group's members, not its target). */\n readonly sources: Set<Element>;\n readonly targets: HTMLElement[];\n /** The message each target's Field shows, for the announcement when focus does not move. */\n readonly messages: Map<HTMLElement, string>;\n /** `document.activeElement` when the first target arrived. */\n readonly activeBefore: Element | null;\n /** The batch moved focus (later microtasks then re-focus, never announce). */\n moved: boolean;\n /** The target already announced. */\n announced: HTMLElement | null;\n}\n\n/** The submission attempt in progress: every target added during the current task. */\nlet batch: Batch | null = null;\n\n/**\n * Adds a control whose `invalid` event (fired on `source`) a Field cancelled during a submission\n * attempt, and focuses the first collected control in document order in a microtask, so the\n * result does not depend on the browser's dispatch order or on how many forms are on the page.\n *\n * The batch lives until the end of the task (a `setTimeout`), not just one microtask: when the\n * browser dispatches the `invalid` events itself (a click on a submit button), it runs a\n * microtask checkpoint after each listener, so the microtask of the first event runs before the\n * second event fires. Every add therefore queues a focus of the batch's first target; later ones\n * re-focus the same element, which is a no-op.\n *\n * A second `invalid` for the same `source` (the element the event fired on) starts a new batch:\n * one validation fires it once per element, so it belongs to the next attempt, even when that\n * attempt comes before the timer (two attempts in one task, or a test that does not yield to\n * timers between them). Joining the old batch would compare focus with the old attempt's.\n *\n * Skips the focus when focus moved during the attempt to an element that is not one of the\n * collected targets: a plain `<input required>` with no Field kept the platform's behaviour\n * (bubble and focus), and the library does not fight it.\n */\nexport function collectInvalid(target: HTMLElement | null, message: string, source: Element): void {\n if (target === null) return;\n if (batch !== null && batch.sources.has(source)) batch = null;\n if (batch === null) {\n const created: Batch = {\n sources: new Set(),\n targets: [],\n messages: new Map(),\n activeBefore: target.ownerDocument.activeElement,\n moved: false,\n announced: null,\n };\n batch = created;\n setTimeout(() => {\n if (batch === created) batch = null;\n }, 0);\n }\n const current = batch;\n current.sources.add(source);\n if (!current.targets.includes(target)) current.targets.push(target);\n current.messages.set(target, message);\n queueMicrotask(() => focusFirst(current));\n}\n\n/**\n * Tests only: forget the submission attempt in progress. Its timer is a task away, and the next\n * test can start before it runs (no task in between); its attempt would then join this one and\n * compare focus with an element of the previous test.\n */\nexport function resetInvalidBatch(): void {\n batch = null;\n}\n\nfunction focusFirst(current: Batch): void {\n const { targets, activeBefore } = current;\n const connected = targets.filter((t) => t.isConnected);\n if (connected.length === 0) return;\n const active = connected[0]!.ownerDocument.activeElement;\n if (active !== activeBefore && active !== null && !connected.includes(active as HTMLElement)) {\n return;\n }\n const first = sortByDocumentOrder(connected, (t) => t)[0]!;\n if (active !== first) {\n current.moved = true;\n first.focus();\n } else if (!current.moved && current.announced !== first) {\n // Focus was already on the first invalid control (an implicit submission with Enter): the\n // cancelled bubble was the only announcement, so speak the message instead.\n current.announced = first;\n announce(first, current.messages.get(first) ?? \"\");\n }\n}\n"],"mappings":";;;;AAmBA,IAAI,QAAsB;;;;;;;;;;;;;;;;;;;;;AAsB1B,SAAgB,eAAe,QAA4B,SAAiB,QAAuB;CACjG,IAAI,WAAW,MAAM;CACrB,IAAI,UAAU,QAAQ,MAAM,QAAQ,IAAI,MAAM,GAAG,QAAQ;CACzD,IAAI,UAAU,MAAM;EAClB,MAAM,UAAiB;GACrB,yBAAS,IAAI,IAAI;GACjB,SAAS,CAAC;GACV,0BAAU,IAAI,IAAI;GAClB,cAAc,OAAO,cAAc;GACnC,OAAO;GACP,WAAW;EACb;EACA,QAAQ;EACR,iBAAiB;GACf,IAAI,UAAU,SAAS,QAAQ;EACjC,GAAG,CAAC;CACN;CACA,MAAM,UAAU;CAChB,QAAQ,QAAQ,IAAI,MAAM;CAC1B,IAAI,CAAC,QAAQ,QAAQ,SAAS,MAAM,GAAG,QAAQ,QAAQ,KAAK,MAAM;CAClE,QAAQ,SAAS,IAAI,QAAQ,OAAO;CACpC,qBAAqB,WAAW,OAAO,CAAC;AAC1C;AAWA,SAAS,WAAW,SAAsB;CACxC,MAAM,EAAE,SAAS,iBAAiB;CAClC,MAAM,YAAY,QAAQ,QAAQ,MAAM,EAAE,WAAW;CACrD,IAAI,UAAU,WAAW,GAAG;CAC5B,MAAM,SAAS,UAAU,EAAE,CAAE,cAAc;CAC3C,IAAI,WAAW,gBAAgB,WAAW,QAAQ,CAAC,UAAU,SAAS,MAAqB,GACzF;CAEF,MAAM,QAAQ,oBAAoB,YAAY,MAAM,CAAC,CAAC,CAAC;CACvD,IAAI,WAAW,OAAO;EACpB,QAAQ,QAAQ;EAChB,MAAM,MAAM;CACd,OAAO,IAAI,CAAC,QAAQ,SAAS,QAAQ,cAAc,OAAO;EAGxD,QAAQ,YAAY;EACpB,SAAS,OAAO,QAAQ,SAAS,IAAI,KAAK,KAAK,EAAE;CACnD;AACF"}
@@ -0,0 +1,26 @@
1
+ //#region src/internal/focus-visible.ts
2
+ let focusVisibleOption;
3
+ /**
4
+ * The engine reads the `focusVisible` member of `focus()`'s options (Chromium 145, Firefox 104,
5
+ * Safari 18.4). Detected once through a getter: the bindings convert the dictionary before the
6
+ * method runs, so a detached element is enough and nothing is focused.
7
+ */
8
+ function supportsFocusVisibleOption(doc) {
9
+ if (focusVisibleOption === void 0) {
10
+ let read = false;
11
+ try {
12
+ doc.createElement("div").focus({ get focusVisible() {
13
+ read = true;
14
+ return false;
15
+ } });
16
+ } catch {
17
+ read = false;
18
+ }
19
+ focusVisibleOption = read;
20
+ }
21
+ return focusVisibleOption;
22
+ }
23
+ //#endregion
24
+ export { supportsFocusVisibleOption };
25
+
26
+ //# sourceMappingURL=focus-visible.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"focus-visible.mjs","names":[],"sources":["../../src/internal/focus-visible.ts"],"sourcesContent":["// Directive-free: the `focus({ focusVisible })` probe behind a pointer open's quiet initial focus\n// (design/components/popover.md 6.1, menu.md 6.1).\n\n/**\n * An initial focus target opened by a pointer: where the engine reads `focus({ focusVisible })`,\n * the library focuses it with `focusVisible: false` right after `showPopover()` instead of\n * writing `autofocus` (WebKit shows the ring for an `autofocus` target after a click).\n * Elsewhere it is an ordinary target.\n */\nexport interface QuietFocusTarget {\n readonly element: HTMLElement;\n readonly focusVisible: false;\n}\n\nlet focusVisibleOption: boolean | undefined;\n\n/**\n * The engine reads the `focusVisible` member of `focus()`'s options (Chromium 145, Firefox 104,\n * Safari 18.4). Detected once through a getter: the bindings convert the dictionary before the\n * method runs, so a detached element is enough and nothing is focused.\n */\nexport function supportsFocusVisibleOption(doc: Document): boolean {\n if (focusVisibleOption === undefined) {\n let read = false;\n try {\n doc.createElement(\"div\").focus({\n get focusVisible() {\n read = true;\n return false;\n },\n } as FocusOptions);\n } catch {\n read = false;\n }\n focusVisibleOption = read;\n }\n return focusVisibleOption;\n}\n\n/** Tests only: forget the detection, so the next pointer open detects the option again. */\nexport function resetFocusVisibleOption(): void {\n focusVisibleOption = undefined;\n}\n"],"mappings":";AAcA,IAAI;;;;;;AAOJ,SAAgB,2BAA2B,KAAwB;CACjE,IAAI,uBAAuB,KAAA,GAAW;EACpC,IAAI,OAAO;EACX,IAAI;GACF,IAAI,cAAc,KAAK,CAAC,CAAC,MAAM,EAC7B,IAAI,eAAe;IACjB,OAAO;IACP,OAAO;GACT,EACF,CAAiB;EACnB,QAAQ;GACN,OAAO;EACT;EACA,qBAAqB;CACvB;CACA,OAAO;AACT"}
@@ -0,0 +1,63 @@
1
+ //#region src/internal/invokers.ts
2
+ /**
3
+ * The `source` of a `ToggleEvent` (Chromium 140, Firefox 145, Safari 26.5), a `CommandEvent` or
4
+ * an `InterestEvent`: the invoker that caused it, `null` without one. Not in TypeScript's DOM lib
5
+ * for all three.
6
+ */
7
+ function eventSource(event) {
8
+ return event.source ?? null;
9
+ }
10
+ /**
11
+ * Whether the `ToggleEvent.source` of a close is a `popovertarget` invoker of `popup`. A
12
+ * `commandfor` or `interestfor` invoker sets `source` too (Chromium's lost-interest hide, a
13
+ * dismissal), and so names no `popovertarget` here.
14
+ */
15
+ function closedByPopoverTarget(event, popup) {
16
+ const source = eventSource(event);
17
+ return (source instanceof HTMLButtonElement || source instanceof HTMLInputElement) && source.popoverTargetElement === popup;
18
+ }
19
+ /** The `<input>` types HTML counts as buttons: the ones `popovertarget` applies to. */
20
+ const INPUT_BUTTON_TYPES = /* @__PURE__ */ new Set([
21
+ "submit",
22
+ "image",
23
+ "reset",
24
+ "button"
25
+ ]);
26
+ /**
27
+ * Whether a press on `target` is a press on a foreign invoker of `popup`: its closest button (a
28
+ * `<button>`, or an `<input>` of a button type) is outside the popup and names it through
29
+ * `popovertarget`, or (a `<button>`) through `commandfor` with a popover command
30
+ * (`toggle-popover`, `show-popover`, `hide-popover`). HTML's invoker relationship, the one light
31
+ * dismiss exempts (conventions 3.5): a disabled button and a submit button with a form owner
32
+ * invoke nothing. Read through the IDL, so an engine without it has no such invoker.
33
+ */
34
+ function isPopoverInvoker(target, popup) {
35
+ if (!(target instanceof Element)) return false;
36
+ const button = target.closest("button, input");
37
+ if (button === null || popup.contains(button)) return false;
38
+ const isInput = button.tagName === "INPUT";
39
+ if (isInput && !INPUT_BUTTON_TYPES.has(button.type)) return false;
40
+ if (button.disabled) return false;
41
+ if (button.form !== null && (button.type === "submit" || button.type === "image")) return false;
42
+ const invoker = button;
43
+ if (invoker.popoverTargetElement === popup) return true;
44
+ return !isInput && invoker.commandForElement === popup && /-popover$/.test(invoker.command ?? "");
45
+ }
46
+ /**
47
+ * While a popup that closes on focus leaving is shown: a primary-button `mousedown` on a foreign
48
+ * invoker of it moves no focus (conventions 3.5). Chromium and Firefox focus a button on
49
+ * press, which would close the popup at the `focusout` before the click's own toggle (as
50
+ * `"dismiss"`, and the toggle then re-showed it). Returns the cleanup.
51
+ */
52
+ function listenInvokerPresses(popup) {
53
+ const doc = popup.ownerDocument;
54
+ const onMouseDown = (event) => {
55
+ if (event.button === 0 && isPopoverInvoker(event.target, popup)) event.preventDefault();
56
+ };
57
+ doc.addEventListener("mousedown", onMouseDown, true);
58
+ return () => doc.removeEventListener("mousedown", onMouseDown, true);
59
+ }
60
+ //#endregion
61
+ export { closedByPopoverTarget, eventSource, isPopoverInvoker, listenInvokerPresses };
62
+
63
+ //# sourceMappingURL=invokers.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invokers.mjs","names":[],"sources":["../../src/internal/invokers.ts"],"sourcesContent":["// No directive: DOM reads and listeners only (conventions 7.1). The platform's invoker\n// relationship between a button and a popover, as the overlays read it.\n\n/** An invoker button's IDL; absent where the engine lacks the Popover API or Invoker Commands. */\ninterface InvokerButton {\n readonly popoverTargetElement?: Element | null;\n readonly commandForElement?: Element | null;\n readonly command?: string;\n}\n\n/**\n * The `source` of a `ToggleEvent` (Chromium 140, Firefox 145, Safari 26.5), a `CommandEvent` or\n * an `InterestEvent`: the invoker that caused it, `null` without one. Not in TypeScript's DOM lib\n * for all three.\n */\nexport function eventSource(event: Event): Element | null {\n return (event as Event & { readonly source?: Element | null }).source ?? null;\n}\n\n/**\n * Whether the `ToggleEvent.source` of a close is a `popovertarget` invoker of `popup`. A\n * `commandfor` or `interestfor` invoker sets `source` too (Chromium's lost-interest hide, a\n * dismissal), and so names no `popovertarget` here.\n */\nexport function closedByPopoverTarget(event: ToggleEvent, popup: HTMLElement): boolean {\n const source = eventSource(event);\n return (\n (source instanceof HTMLButtonElement || source instanceof HTMLInputElement) &&\n source.popoverTargetElement === popup\n );\n}\n\n/** The `<input>` types HTML counts as buttons: the ones `popovertarget` applies to. */\nconst INPUT_BUTTON_TYPES = new Set([\"submit\", \"image\", \"reset\", \"button\"]);\n\n/**\n * Whether a press on `target` is a press on a foreign invoker of `popup`: its closest button (a\n * `<button>`, or an `<input>` of a button type) is outside the popup and names it through\n * `popovertarget`, or (a `<button>`) through `commandfor` with a popover command\n * (`toggle-popover`, `show-popover`, `hide-popover`). HTML's invoker relationship, the one light\n * dismiss exempts (conventions 3.5): a disabled button and a submit button with a form owner\n * invoke nothing. Read through the IDL, so an engine without it has no such invoker.\n */\nexport function isPopoverInvoker(target: EventTarget | null, popup: Element): boolean {\n if (!(target instanceof Element)) return false;\n const button = target.closest<HTMLButtonElement | HTMLInputElement>(\"button, input\");\n if (button === null || popup.contains(button)) return false;\n const isInput = button.tagName === \"INPUT\";\n if (isInput && !INPUT_BUTTON_TYPES.has(button.type)) return false;\n if (button.disabled) return false;\n if (button.form !== null && (button.type === \"submit\" || button.type === \"image\")) return false;\n const invoker = button as InvokerButton;\n if (invoker.popoverTargetElement === popup) return true;\n return !isInput && invoker.commandForElement === popup && /-popover$/.test(invoker.command ?? \"\");\n}\n\n/**\n * While a popup that closes on focus leaving is shown: a primary-button `mousedown` on a foreign\n * invoker of it moves no focus (conventions 3.5). Chromium and Firefox focus a button on\n * press, which would close the popup at the `focusout` before the click's own toggle (as\n * `\"dismiss\"`, and the toggle then re-showed it). Returns the cleanup.\n */\nexport function listenInvokerPresses(popup: HTMLElement): () => void {\n const doc = popup.ownerDocument;\n const onMouseDown = (event: MouseEvent) => {\n if (event.button === 0 && isPopoverInvoker(event.target, popup)) event.preventDefault();\n };\n doc.addEventListener(\"mousedown\", onMouseDown, true);\n return () => doc.removeEventListener(\"mousedown\", onMouseDown, true);\n}\n"],"mappings":";;;;;;AAeA,SAAgB,YAAY,OAA8B;CACxD,OAAQ,MAAuD,UAAU;AAC3E;;;;;;AAOA,SAAgB,sBAAsB,OAAoB,OAA6B;CACrF,MAAM,SAAS,YAAY,KAAK;CAChC,QACG,kBAAkB,qBAAqB,kBAAkB,qBAC1D,OAAO,yBAAyB;AAEpC;;AAGA,MAAM,qCAAqB,IAAI,IAAI;CAAC;CAAU;CAAS;CAAS;AAAQ,CAAC;;;;;;;;;AAUzE,SAAgB,iBAAiB,QAA4B,OAAyB;CACpF,IAAI,EAAE,kBAAkB,UAAU,OAAO;CACzC,MAAM,SAAS,OAAO,QAA8C,eAAe;CACnF,IAAI,WAAW,QAAQ,MAAM,SAAS,MAAM,GAAG,OAAO;CACtD,MAAM,UAAU,OAAO,YAAY;CACnC,IAAI,WAAW,CAAC,mBAAmB,IAAI,OAAO,IAAI,GAAG,OAAO;CAC5D,IAAI,OAAO,UAAU,OAAO;CAC5B,IAAI,OAAO,SAAS,SAAS,OAAO,SAAS,YAAY,OAAO,SAAS,UAAU,OAAO;CAC1F,MAAM,UAAU;CAChB,IAAI,QAAQ,yBAAyB,OAAO,OAAO;CACnD,OAAO,CAAC,WAAW,QAAQ,sBAAsB,SAAS,YAAY,KAAK,QAAQ,WAAW,EAAE;AAClG;;;;;;;AAQA,SAAgB,qBAAqB,OAAgC;CACnE,MAAM,MAAM,MAAM;CAClB,MAAM,eAAe,UAAsB;EACzC,IAAI,MAAM,WAAW,KAAK,iBAAiB,MAAM,QAAQ,KAAK,GAAG,MAAM,eAAe;CACxF;CACA,IAAI,iBAAiB,aAAa,aAAa,IAAI;CACnD,aAAa,IAAI,oBAAoB,aAAa,aAAa,IAAI;AACrE"}
@@ -24,7 +24,8 @@ declare module "react" {
24
24
  interestfor?: string | undefined;
25
25
  /**
26
26
  * `commandfor` (Invoker Commands): id of the element the button's `command` acts on.
27
- * Not in `@types/react` 19.3.0 (DefinitelyTyped #74664).
27
+ * Not in `@types/react` 19.3.0 (DefinitelyTyped #74664). Rendered by `Popover.Close`, the
28
+ * Dialog parts and `Button`; the overlay Triggers use `popovertarget`.
28
29
  */
29
30
  commandfor?: string | undefined;
30
31
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"platform-attributes.d.mts","names":[],"sources":["../../src/internal/platform-attributes.ts"],"mappings":";;;YAkBY,eAAe;;;;;;IAMvB;;;;;;IAMA;;YAGQ,qBAAqB;;;;;;IAM7B;;;;;IAKA;;;;;;IAMA;;YAWQ,qBAAqB;;IAE7B;;YAGQ,mBAAmB;;IAE3B;;YAGQ;cACE;;;;;;;MAOR,iBAAiB,MAAM,kBAAkB,MAAM,eAAe,cAAc;;;YAItE;;IAER;;IAEA;;IAEA"}
1
+ {"version":3,"file":"platform-attributes.d.mts","names":[],"sources":["../../src/internal/platform-attributes.ts"],"mappings":";;;YAkBY,eAAe;;;;;;IAMvB;;;;;;IAMA;;YAGQ,qBAAqB;;;;;;IAM7B;;;;;;IAMA;;;;;;IAMA;;YAWQ,qBAAqB;;IAE7B;;YAGQ,mBAAmB;;IAE3B;;YAGQ;cACE;;;;;;;MAOR,iBAAiB,MAAM,kBAAkB,MAAM,eAAe,cAAc;;;YAItE;;IAER;;IAEA;;IAEA"}
@@ -3,7 +3,7 @@
3
3
  * `setPointerCapture`, which throws `NotFoundError` for a pointer the engine no longer tracks
4
4
  * (context-menu.md 2.1). A silent no-op when no button is down. `true` when the capture was
5
5
  * taken (the Menu's press-drag-release gesture runs only then, 2.6). The Combobox Input uses it
6
- * to keep a press on the field from light-dismissing the listbox (combobox.md 5.4, #123).
6
+ * to keep a press on the field from light-dismissing the listbox (combobox.md 5.4).
7
7
  */
8
8
  function capturePointer(element, pointerId) {
9
9
  if (element === null || pointerId === void 0) return false;
@@ -1 +1 @@
1
- {"version":3,"file":"pointer-capture.mjs","names":[],"sources":["../../src/internal/pointer-capture.ts"],"sourcesContent":["// No directive: a pure DOM call (conventions 7.1).\n\n/**\n * `setPointerCapture`, which throws `NotFoundError` for a pointer the engine no longer tracks\n * (context-menu.md 2.1). A silent no-op when no button is down. `true` when the capture was\n * taken (the Menu's press-drag-release gesture runs only then, 2.6). The Combobox Input uses it\n * to keep a press on the field from light-dismissing the listbox (combobox.md 5.4, #123).\n */\nexport function capturePointer(element: Element | null, pointerId: number | undefined): boolean {\n if (element === null || pointerId === undefined) return false;\n try {\n element.setPointerCapture(pointerId);\n return true;\n } catch {\n // Not an active pointer (a synthetic event, a released button): nothing to capture.\n return false;\n }\n}\n"],"mappings":";;;;;;;AAQA,SAAgB,eAAe,SAAyB,WAAwC;CAC9F,IAAI,YAAY,QAAQ,cAAc,KAAA,GAAW,OAAO;CACxD,IAAI;EACF,QAAQ,kBAAkB,SAAS;EACnC,OAAO;CACT,QAAQ;EAEN,OAAO;CACT;AACF"}
1
+ {"version":3,"file":"pointer-capture.mjs","names":[],"sources":["../../src/internal/pointer-capture.ts"],"sourcesContent":["// No directive: a pure DOM call (conventions 7.1).\n\n/**\n * `setPointerCapture`, which throws `NotFoundError` for a pointer the engine no longer tracks\n * (context-menu.md 2.1). A silent no-op when no button is down. `true` when the capture was\n * taken (the Menu's press-drag-release gesture runs only then, 2.6). The Combobox Input uses it\n * to keep a press on the field from light-dismissing the listbox (combobox.md 5.4).\n */\nexport function capturePointer(element: Element | null, pointerId: number | undefined): boolean {\n if (element === null || pointerId === undefined) return false;\n try {\n element.setPointerCapture(pointerId);\n return true;\n } catch {\n // Not an active pointer (a synthetic event, a released button): nothing to capture.\n return false;\n }\n}\n"],"mappings":";;;;;;;AAQA,SAAgB,eAAe,SAAyB,WAAwC;CAC9F,IAAI,YAAY,QAAQ,cAAc,KAAA,GAAW,OAAO;CACxD,IAAI;EACF,QAAQ,kBAAkB,SAAS;EACnC,OAAO;CACT,QAAQ;EAEN,OAAO;CACT;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"render-element.mjs","names":[],"sources":["../../src/internal/render-element.ts"],"sourcesContent":["// No \"use client\": the pure half of `useRender`, usable from a directive-free part (a Root that\n// may run as a Server Component, design/components/progress.md 8.1 and implementation note 14.1).\nimport { cloneElement, createElement, isValidElement } from \"react\";\nimport type { CSSProperties, ReactNode, Ref } from \"react\";\nimport { mergeProps, mergeRefs } from \"./merge-props.js\";\nimport type { RenderProp, StateValue } from \"./types.js\";\n\nexport interface ElementLikeProps {\n className?: string | undefined;\n style?: CSSProperties | undefined;\n children?: ReactNode;\n ref?: Ref<unknown> | undefined;\n}\n\n/** `data-*` attributes are valid JSX but absent from the element prop types. */\nexport type DataAttributes = { [key: `data-${string}`]: string | undefined };\n\nexport interface RenderElementOptions<Props extends ElementLikeProps, State> {\n /** Intrinsic element rendered when `render` is not given. */\n defaultElement: string;\n render: RenderProp<Props, State> | undefined;\n state: State;\n className: StateValue<string | undefined, State> | undefined;\n style: StateValue<CSSProperties | undefined, State> | undefined;\n children: StateValue<ReactNode, State> | undefined;\n /**\n * The part's pass-through props for the element. A `render` element's own props win over\n * these. Their `ref` is replaced by `ref` below.\n */\n props: Omit<Props, \"className\" | \"style\" | \"children\"> & DataAttributes;\n /**\n * Library-controlled attributes the part computes (`role`, `aria-*` state, id wiring, `data-*`\n * state, the library's own event handlers). These win over a `render` element's props\n * (conventions 1.2).\n */\n libraryProps?: Partial<Omit<Props, \"className\" | \"style\" | \"children\">> & DataAttributes;\n /**\n * The element's ref, already merged from the library's ref, the consumer's `ref` and the\n * `render` element's ref. The `render` element's own ref is not attached separately.\n */\n ref: Ref<unknown> | undefined;\n}\n\nexport function resolveStateValue<T, State>(value: StateValue<T, State>, state: State): T {\n return typeof value === \"function\" ? (value as (state: State) => T)(state) : value;\n}\n\n/**\n * Whether a part whose default element is a `<button>` should add `type=\"button\"` (conventions\n * 1.2): no `render`, the function form (it receives button props and decides itself what to\n * spread), a host `<button>` element, or a **component** element (assumed to render a\n * `<button>`; if it renders a link, `type` is a harmless ignored attribute, while a missing\n * `type` on a `<button>` in a form is a silent submit). Only a host element of another tag (an\n * `<a>`) does not get it.\n */\nexport function rendersButton<Props, State>(render: RenderProp<Props, State> | undefined): boolean {\n if (render === undefined || typeof render === \"function\") return true;\n if (!isValidElement(render)) return false;\n return typeof render.type !== \"string\" || render.type === \"button\";\n}\n\n/**\n * Whether the rendered element is certainly a host `<button>`: no `render`, the function form, or\n * a host `\"button\"` element. The strict predicate for native `disabled`, which means nothing on a\n * link and would expose it as enabled to assistive technology; anything else (a link, a\n * component) takes the `aria-disabled` branch (design/components/button.md).\n */\nexport function isHostButton<Props, State>(render: RenderProp<Props, State> | undefined): boolean {\n if (render === undefined || typeof render === \"function\") return true;\n return isValidElement(render) && render.type === \"button\";\n}\n\nexport interface DisabledButton {\n /**\n * Owned keys, spread where `disabled` goes: `disabled` (owned as absent in the focusable\n * branch, where the element may not be a host `<button>` and the part's click handler refuses,\n * so a render element's own is removed), and in that branch only `aria-disabled` (a host\n * button keeps a consumer's own).\n */\n readonly props: {\n readonly disabled: boolean | undefined;\n readonly \"aria-disabled\"?: true | undefined;\n };\n /**\n * Whether an invoker part may render `commandfor` / `command`: not when disabled in the\n * focusable branch, where nothing native stops the command (a component render spreading onto\n * a real `<button>` would be a live invoker before hydration).\n */\n readonly invoker: boolean;\n}\n\n/**\n * The disabled rule of a button-like part that accepts an arbitrary `render`\n * (conventions 1.2, design/components/button.md 17): native `disabled` on a host `<button>`, or\n * where the browser handles the click (`handlesClick: false`: a JS-free command, which only\n * native `disabled` stops); `aria-disabled` otherwise. `alwaysFocusable` always takes the\n * `aria-disabled` branch (a menu item stays focusable).\n */\nexport function disabledButton<Props, State>(\n render: RenderProp<Props, State> | undefined,\n disabled: boolean,\n options: { readonly handlesClick?: boolean; readonly alwaysFocusable?: boolean } = {},\n): DisabledButton {\n const { handlesClick = true, alwaysFocusable = false } = options;\n const focusable = alwaysFocusable || (handlesClick && !isHostButton(render));\n return {\n props: {\n disabled: focusable ? undefined : disabled,\n ...(focusable && { \"aria-disabled\": disabled ? true : undefined }),\n },\n invoker: !(focusable && disabled),\n };\n}\n\n/**\n * The ref of a part with no library ref, merged from the consumer's `ref` and a `render`\n * element's ref without memoisation (a directive-free part cannot `useMemo`, design\n * progress.md 14.1). A fresh callback ref per render is correct because every merged callback\n * returns a cleanup; a single ref is passed through untouched.\n */\nexport function mergeRenderRef(\n consumerRef: Ref<unknown> | undefined,\n render: unknown,\n): Ref<unknown> | undefined {\n const elementRef = isValidElement<ElementLikeProps>(render) ? render.props.ref : undefined;\n if (consumerRef != null && elementRef != null) return mergeRefs(consumerRef, elementRef);\n return consumerRef ?? elementRef;\n}\n\n/**\n * Resolves `render` and the function-form `className` / `style` / `children` of a part against\n * its state and produces the element (conventions 1.2, 1.3, 1.4). Pure: the caller merges the\n * refs (`useRender` memoises the merge; a directive-free part merges unmemoised).\n */\nexport function renderElement<Props extends ElementLikeProps, State>(\n options: RenderElementOptions<Props, State>,\n): ReactNode {\n const { defaultElement, render, state, className, style, children, props, libraryProps, ref } =\n options;\n\n const partProps = {\n ...props,\n ref,\n className: resolveStateValue(className, state),\n style: resolveStateValue(style, state),\n children: resolveStateValue(children, state),\n } as Record<string, unknown>;\n const controlled = (libraryProps ?? {}) as Record<string, unknown>;\n\n if (isValidElement<ElementLikeProps>(render)) {\n // The element's ref is already part of `ref`.\n const { ref: _ignored, ...elementProps } = render.props as Record<string, unknown>;\n return cloneElement(render, mergeProps(partProps, elementProps, controlled) as Partial<Props>);\n }\n const resolved = mergeProps(partProps, {}, controlled) as unknown as Props;\n if (typeof render === \"function\") {\n return render(resolved, state);\n }\n return createElement(defaultElement, resolved);\n}\n"],"mappings":";;;AA2CA,SAAgB,kBAA4B,OAA6B,OAAiB;CACxF,OAAO,OAAO,UAAU,aAAc,MAA8B,KAAK,IAAI;AAC/E;;;;;;;;;AAUA,SAAgB,cAA4B,QAAuD;CACjG,IAAI,WAAW,KAAA,KAAa,OAAO,WAAW,YAAY,OAAO;CACjE,IAAI,CAAC,eAAe,MAAM,GAAG,OAAO;CACpC,OAAO,OAAO,OAAO,SAAS,YAAY,OAAO,SAAS;AAC5D;;;;;;;AAQA,SAAgB,aAA2B,QAAuD;CAChG,IAAI,WAAW,KAAA,KAAa,OAAO,WAAW,YAAY,OAAO;CACjE,OAAO,eAAe,MAAM,KAAK,OAAO,SAAS;AACnD;;;;;;;;AA4BA,SAAgB,eACd,QACA,UACA,UAAmF,CAAC,GACpE;CAChB,MAAM,EAAE,eAAe,MAAM,kBAAkB,UAAU;CACzD,MAAM,YAAY,mBAAoB,gBAAgB,CAAC,aAAa,MAAM;CAC1E,OAAO;EACL,OAAO;GACL,UAAU,YAAY,KAAA,IAAY;GAClC,GAAI,aAAa,EAAE,iBAAiB,WAAW,OAAO,KAAA,EAAU;EAClE;EACA,SAAS,EAAE,aAAa;CAC1B;AACF;;;;;;;AAQA,SAAgB,eACd,aACA,QAC0B;CAC1B,MAAM,aAAa,eAAiC,MAAM,IAAI,OAAO,MAAM,MAAM,KAAA;CACjF,IAAI,eAAe,QAAQ,cAAc,MAAM,OAAO,UAAU,aAAa,UAAU;CACvF,OAAO,eAAe;AACxB;;;;;;AAOA,SAAgB,cACd,SACW;CACX,MAAM,EAAE,gBAAgB,QAAQ,OAAO,WAAW,OAAO,UAAU,OAAO,cAAc,QACtF;CAEF,MAAM,YAAY;EAChB,GAAG;EACH;EACA,WAAW,kBAAkB,WAAW,KAAK;EAC7C,OAAO,kBAAkB,OAAO,KAAK;EACrC,UAAU,kBAAkB,UAAU,KAAK;CAC7C;CACA,MAAM,aAAc,gBAAgB,CAAC;CAErC,IAAI,eAAiC,MAAM,GAAG;EAE5C,MAAM,EAAE,KAAK,UAAU,GAAG,iBAAiB,OAAO;EAClD,OAAO,aAAa,QAAQ,WAAW,WAAW,cAAc,UAAU,CAAmB;CAC/F;CACA,MAAM,WAAW,WAAW,WAAW,CAAC,GAAG,UAAU;CACrD,IAAI,OAAO,WAAW,YACpB,OAAO,OAAO,UAAU,KAAK;CAE/B,OAAO,cAAc,gBAAgB,QAAQ;AAC/C"}
1
+ {"version":3,"file":"render-element.mjs","names":[],"sources":["../../src/internal/render-element.ts"],"sourcesContent":["// No \"use client\": the pure half of `useRender`, usable from a directive-free part (a Root that\n// may run as a Server Component, design/components/progress.md 8.1 and implementation note 14.1).\nimport { cloneElement, createElement, isValidElement } from \"react\";\nimport type { CSSProperties, ReactNode, Ref } from \"react\";\nimport { mergeProps, mergeRefs } from \"./merge-props.js\";\nimport type { RenderProp, StateValue } from \"./types.js\";\n\nexport interface ElementLikeProps {\n className?: string | undefined;\n style?: CSSProperties | undefined;\n children?: ReactNode;\n ref?: Ref<unknown> | undefined;\n}\n\n/** `data-*` attributes are valid JSX but absent from the element prop types. */\nexport type DataAttributes = { [key: `data-${string}`]: string | undefined };\n\nexport interface RenderElementOptions<Props extends ElementLikeProps, State> {\n /** Intrinsic element rendered when `render` is not given. */\n defaultElement: string;\n render: RenderProp<Props, State> | undefined;\n state: State;\n className: StateValue<string | undefined, State> | undefined;\n style: StateValue<CSSProperties | undefined, State> | undefined;\n children: StateValue<ReactNode, State> | undefined;\n /**\n * The part's pass-through props for the element. A `render` element's own props win over\n * these. Their `ref` is replaced by `ref` below.\n */\n props: Omit<Props, \"className\" | \"style\" | \"children\"> & DataAttributes;\n /**\n * Library-controlled attributes the part computes (`role`, `aria-*` state, id wiring, `data-*`\n * state, the library's own event handlers). These win over a `render` element's props\n * (conventions 1.2).\n */\n libraryProps?: Partial<Omit<Props, \"className\" | \"style\" | \"children\">> & DataAttributes;\n /**\n * The element's ref, already merged from the library's ref, the consumer's `ref` and the\n * `render` element's ref. The `render` element's own ref is not attached separately.\n */\n ref: Ref<unknown> | undefined;\n}\n\nexport function resolveStateValue<T, State>(value: StateValue<T, State>, state: State): T {\n return typeof value === \"function\" ? (value as (state: State) => T)(state) : value;\n}\n\n/**\n * Whether a part whose default element is a `<button>` should add `type=\"button\"` (conventions\n * 1.2): no `render`, the function form (it receives button props and decides itself what to\n * spread), a host `<button>` element, or a **component** element (assumed to render a\n * `<button>`; if it renders a link, `type` is a harmless ignored attribute, while a missing\n * `type` on a `<button>` in a form is a silent submit). Only a host element of another tag (an\n * `<a>`) does not get it.\n */\nexport function rendersButton<Props, State>(render: RenderProp<Props, State> | undefined): boolean {\n if (render === undefined || typeof render === \"function\") return true;\n if (!isValidElement(render)) return false;\n return typeof render.type !== \"string\" || render.type === \"button\";\n}\n\n/**\n * Whether the rendered element is certainly a host `<button>`: no `render`, the function form, or\n * a host `\"button\"` element. The strict predicate for native `disabled`, which means nothing on a\n * link and would expose it as enabled to assistive technology; anything else (a link, a\n * component) takes the `aria-disabled` branch (design/components/button.md).\n */\nexport function isHostButton<Props, State>(render: RenderProp<Props, State> | undefined): boolean {\n if (render === undefined || typeof render === \"function\") return true;\n return isValidElement(render) && render.type === \"button\";\n}\n\nexport interface DisabledButton {\n /**\n * Owned keys, spread where `disabled` goes: `disabled` (owned as absent in the focusable\n * branch, where the element may not be a host `<button>` and the part's click handler refuses,\n * so a render element's own is removed), and in that branch only `aria-disabled` (a host\n * button keeps a consumer's own).\n */\n readonly props: {\n readonly disabled: boolean | undefined;\n readonly \"aria-disabled\"?: true | undefined;\n };\n /**\n * Whether an invoker part may render `popovertarget` or `commandfor` / `command`: not when disabled in the\n * focusable branch, where nothing native stops the command (a component render spreading onto\n * a real `<button>` would be a live invoker before hydration).\n */\n readonly invoker: boolean;\n}\n\n/**\n * The disabled rule of a button-like part that accepts an arbitrary `render`\n * (conventions 1.2, design/components/button.md 17): native `disabled` on a host `<button>`, or\n * where the browser handles the click (`handlesClick: false`: a JS-free command, which only\n * native `disabled` stops); `aria-disabled` otherwise. `alwaysFocusable` always takes the\n * `aria-disabled` branch (a menu item stays focusable).\n */\nexport function disabledButton<Props, State>(\n render: RenderProp<Props, State> | undefined,\n disabled: boolean,\n options: { readonly handlesClick?: boolean; readonly alwaysFocusable?: boolean } = {},\n): DisabledButton {\n const { handlesClick = true, alwaysFocusable = false } = options;\n const focusable = alwaysFocusable || (handlesClick && !isHostButton(render));\n return {\n props: {\n disabled: focusable ? undefined : disabled,\n ...(focusable && { \"aria-disabled\": disabled ? true : undefined }),\n },\n invoker: !(focusable && disabled),\n };\n}\n\n/**\n * The ref of a part with no library ref, merged from the consumer's `ref` and a `render`\n * element's ref without memoisation (a directive-free part cannot `useMemo`, design\n * progress.md 14.1). A fresh callback ref per render is correct because every merged callback\n * returns a cleanup; a single ref is passed through untouched.\n */\nexport function mergeRenderRef(\n consumerRef: Ref<unknown> | undefined,\n render: unknown,\n): Ref<unknown> | undefined {\n const elementRef = isValidElement<ElementLikeProps>(render) ? render.props.ref : undefined;\n if (consumerRef != null && elementRef != null) return mergeRefs(consumerRef, elementRef);\n return consumerRef ?? elementRef;\n}\n\n/**\n * Resolves `render` and the function-form `className` / `style` / `children` of a part against\n * its state and produces the element (conventions 1.2, 1.3, 1.4). Pure: the caller merges the\n * refs (`useRender` memoises the merge; a directive-free part merges unmemoised).\n */\nexport function renderElement<Props extends ElementLikeProps, State>(\n options: RenderElementOptions<Props, State>,\n): ReactNode {\n const { defaultElement, render, state, className, style, children, props, libraryProps, ref } =\n options;\n\n const partProps = {\n ...props,\n ref,\n className: resolveStateValue(className, state),\n style: resolveStateValue(style, state),\n children: resolveStateValue(children, state),\n } as Record<string, unknown>;\n const controlled = (libraryProps ?? {}) as Record<string, unknown>;\n\n if (isValidElement<ElementLikeProps>(render)) {\n // The element's ref is already part of `ref`.\n const { ref: _ignored, ...elementProps } = render.props as Record<string, unknown>;\n return cloneElement(render, mergeProps(partProps, elementProps, controlled) as Partial<Props>);\n }\n const resolved = mergeProps(partProps, {}, controlled) as unknown as Props;\n if (typeof render === \"function\") {\n return render(resolved, state);\n }\n return createElement(defaultElement, resolved);\n}\n"],"mappings":";;;AA2CA,SAAgB,kBAA4B,OAA6B,OAAiB;CACxF,OAAO,OAAO,UAAU,aAAc,MAA8B,KAAK,IAAI;AAC/E;;;;;;;;;AAUA,SAAgB,cAA4B,QAAuD;CACjG,IAAI,WAAW,KAAA,KAAa,OAAO,WAAW,YAAY,OAAO;CACjE,IAAI,CAAC,eAAe,MAAM,GAAG,OAAO;CACpC,OAAO,OAAO,OAAO,SAAS,YAAY,OAAO,SAAS;AAC5D;;;;;;;AAQA,SAAgB,aAA2B,QAAuD;CAChG,IAAI,WAAW,KAAA,KAAa,OAAO,WAAW,YAAY,OAAO;CACjE,OAAO,eAAe,MAAM,KAAK,OAAO,SAAS;AACnD;;;;;;;;AA4BA,SAAgB,eACd,QACA,UACA,UAAmF,CAAC,GACpE;CAChB,MAAM,EAAE,eAAe,MAAM,kBAAkB,UAAU;CACzD,MAAM,YAAY,mBAAoB,gBAAgB,CAAC,aAAa,MAAM;CAC1E,OAAO;EACL,OAAO;GACL,UAAU,YAAY,KAAA,IAAY;GAClC,GAAI,aAAa,EAAE,iBAAiB,WAAW,OAAO,KAAA,EAAU;EAClE;EACA,SAAS,EAAE,aAAa;CAC1B;AACF;;;;;;;AAQA,SAAgB,eACd,aACA,QAC0B;CAC1B,MAAM,aAAa,eAAiC,MAAM,IAAI,OAAO,MAAM,MAAM,KAAA;CACjF,IAAI,eAAe,QAAQ,cAAc,MAAM,OAAO,UAAU,aAAa,UAAU;CACvF,OAAO,eAAe;AACxB;;;;;;AAOA,SAAgB,cACd,SACW;CACX,MAAM,EAAE,gBAAgB,QAAQ,OAAO,WAAW,OAAO,UAAU,OAAO,cAAc,QACtF;CAEF,MAAM,YAAY;EAChB,GAAG;EACH;EACA,WAAW,kBAAkB,WAAW,KAAK;EAC7C,OAAO,kBAAkB,OAAO,KAAK;EACrC,UAAU,kBAAkB,UAAU,KAAK;CAC7C;CACA,MAAM,aAAc,gBAAgB,CAAC;CAErC,IAAI,eAAiC,MAAM,GAAG;EAE5C,MAAM,EAAE,KAAK,UAAU,GAAG,iBAAiB,OAAO;EAClD,OAAO,aAAa,QAAQ,WAAW,WAAW,cAAc,UAAU,CAAmB;CAC/F;CACA,MAAM,WAAW,WAAW,WAAW,CAAC,GAAG,UAAU;CACrD,IAAI,OAAO,WAAW,YACpB,OAAO,OAAO,UAAU,KAAK;CAE/B,OAAO,cAAc,gBAAgB,QAAQ;AAC/C"}
@@ -5,14 +5,14 @@ const warned = /* @__PURE__ */ new WeakSet();
5
5
  /**
6
6
  * Registers `element` as the Root's one Trigger (`triggerRef`, last mounted wins) and returns
7
7
  * the ref cleanup. In development, a second Trigger mounting while another is registered
8
- * warns once per Root (#113 API3): only the registered one is the popup's `source` (anchor,
9
- * focus return, `aria-expanded`), so a press on the other while open counts as outside.
8
+ * warns once per Root (popover.md 14.2): only the registered one is the popup's `source` (anchor,
9
+ * focus return) and, in JS-free mode, the one whose `data-open` is kept current.
10
10
  */
11
11
  function registerTrigger(triggerRef, element, part) {
12
12
  if (isDev && triggerRef.current !== null) {
13
13
  if (!warned.has(triggerRef)) {
14
14
  warned.add(triggerRef);
15
- console.error(`${part}: a second ${part} mounted in the same Root. A Root supports one ${part}: the popup only follows the last one mounted (its anchor, focus return and aria-expanded). Render one ${part} per Root.`);
15
+ console.error(`${part}: a second ${part} mounted in the same Root. A Root supports one ${part}: the popup only follows the last one mounted (its anchor, focus return and, without an action, data-open). Render one ${part} per Root.`);
16
16
  }
17
17
  }
18
18
  triggerRef.current = element;
@@ -1 +1 @@
1
- {"version":3,"file":"trigger-ref.mjs","names":[],"sources":["../../src/internal/trigger-ref.ts"],"sourcesContent":["import type { RefObject } from \"react\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/** The Roots that already warned about a second Trigger, keyed by their `triggerRef`. */\nconst warned = new WeakSet<RefObject<HTMLElement | null>>();\n\n/**\n * Registers `element` as the Root's one Trigger (`triggerRef`, last mounted wins) and returns\n * the ref cleanup. In development, a second Trigger mounting while another is registered\n * warns once per Root (#113 API3): only the registered one is the popup's `source` (anchor,\n * focus return, `aria-expanded`), so a press on the other while open counts as outside.\n */\nexport function registerTrigger(\n triggerRef: RefObject<HTMLElement | null>,\n element: HTMLElement,\n part: string,\n): () => void {\n // A Trigger's own cleanup clears the ref first (a remount, StrictMode, a ref change), so a\n // registered element here is another, still mounted Trigger.\n if (isDev && triggerRef.current !== null) {\n if (!warned.has(triggerRef)) {\n warned.add(triggerRef);\n console.error(\n `${part}: a second ${part} mounted in the same Root. A Root supports one ${part}: ` +\n \"the popup only follows the last one mounted (its anchor, focus return and \" +\n `aria-expanded). Render one ${part} per Root.`,\n );\n }\n }\n triggerRef.current = element;\n return () => {\n if (triggerRef.current === element) triggerRef.current = null;\n };\n}\n"],"mappings":";AAEA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;AAGvC,MAAM,yBAAS,IAAI,QAAuC;;;;;;;AAQ1D,SAAgB,gBACd,YACA,SACA,MACY;CAGZ,IAAI,SAAS,WAAW,YAAY,MAC9B;MAAA,CAAC,OAAO,IAAI,UAAU,GAAG;GAC3B,OAAO,IAAI,UAAU;GACrB,QAAQ,MACN,GAAG,KAAK,aAAa,KAAK,iDAAiD,KAAK,yGAEhD,KAAK,WACvC;EACF;;CAEF,WAAW,UAAU;CACrB,aAAa;EACX,IAAI,WAAW,YAAY,SAAS,WAAW,UAAU;CAC3D;AACF"}
1
+ {"version":3,"file":"trigger-ref.mjs","names":[],"sources":["../../src/internal/trigger-ref.ts"],"sourcesContent":["import type { RefObject } from \"react\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/** The Roots that already warned about a second Trigger, keyed by their `triggerRef`. */\nconst warned = new WeakSet<RefObject<HTMLElement | null>>();\n\n/**\n * Registers `element` as the Root's one Trigger (`triggerRef`, last mounted wins) and returns\n * the ref cleanup. In development, a second Trigger mounting while another is registered\n * warns once per Root (popover.md 14.2): only the registered one is the popup's `source` (anchor,\n * focus return) and, in JS-free mode, the one whose `data-open` is kept current.\n */\nexport function registerTrigger(\n triggerRef: RefObject<HTMLElement | null>,\n element: HTMLElement,\n part: string,\n): () => void {\n // A Trigger's own cleanup clears the ref first (a remount, StrictMode, a ref change), so a\n // registered element here is another, still mounted Trigger.\n if (isDev && triggerRef.current !== null) {\n if (!warned.has(triggerRef)) {\n warned.add(triggerRef);\n console.error(\n `${part}: a second ${part} mounted in the same Root. A Root supports one ${part}: ` +\n \"the popup only follows the last one mounted (its anchor, focus return and, \" +\n `without an action, data-open). Render one ${part} per Root.`,\n );\n }\n }\n triggerRef.current = element;\n return () => {\n if (triggerRef.current === element) triggerRef.current = null;\n };\n}\n"],"mappings":";AAEA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;AAGvC,MAAM,yBAAS,IAAI,QAAuC;;;;;;;AAQ1D,SAAgB,gBACd,YACA,SACA,MACY;CAGZ,IAAI,SAAS,WAAW,YAAY,MAC9B;MAAA,CAAC,OAAO,IAAI,UAAU,GAAG;GAC3B,OAAO,IAAI,UAAU;GACrB,QAAQ,MACN,GAAG,KAAK,aAAa,KAAK,iDAAiD,KAAK,yHAEjC,KAAK,WACtD;EACF;;CAEF,WAAW,UAAU;CACrB,aAAa;EACX,IAAI,WAAW,YAAY,SAAS,WAAW,UAAU;CAC3D;AACF"}
@@ -0,0 +1,84 @@
1
+ "use client";
2
+ import { isPopoverOpen } from "./popover-open.mjs";
3
+ import { eventSource } from "./invokers.mjs";
4
+ import { useCallback, useRef } from "react";
5
+ //#region src/internal/use-interest-dismiss.ts
6
+ /**
7
+ * Lost interest of an `interestfor` button naming the popup (library mode; Chromium; popover.md
8
+ * lost-interest amendment), for `usePopoverPopup`. The platform hides only a popover its own
9
+ * interest show opened (`invokedVia == kInterest`), and the library cancels that show and
10
+ * re-shows with `showPopover({ source })`, so the platform never hides: the library does, as a
11
+ * dismissal. Chromium also fires `loseinterest` from inside every hide of the popup while the
12
+ * button has interest (Escape, script, the library's own close), before the state flips, and a
13
+ * `hidePopover()` called from there re-enters the hide and loses its `toggle`: the hide waits one
14
+ * task and runs only if the popup is still shown and still meant to be open, and returns no focus
15
+ * to the Trigger. A pending interest open is cancelled instead.
16
+ */
17
+ function useInterestDismiss(ctx) {
18
+ const isLibrary = ctx.mode === "library";
19
+ const { popupRef } = ctx;
20
+ const interestInvoker = useRef(null);
21
+ const interestOpen = useRef(false);
22
+ const interestHideTask = useRef(void 0);
23
+ const interestHide = useRef(false);
24
+ const onInterest = (event) => {
25
+ const element = popupRef.current;
26
+ if (!isLibrary || element === null || event.target !== element) return;
27
+ interestInvoker.current = eventSource(event);
28
+ };
29
+ const onLoseInterest = (event) => {
30
+ const element = popupRef.current;
31
+ if (!isLibrary || element === null || event.target !== element) return;
32
+ const source = eventSource(event);
33
+ if (source === null || source !== interestInvoker.current) return;
34
+ interestInvoker.current = null;
35
+ if (!interestOpen.current) return;
36
+ if (isPopoverOpen(element)) {
37
+ clearTimeout(interestHideTask.current);
38
+ interestHideTask.current = setTimeout(() => {
39
+ interestHideTask.current = void 0;
40
+ if (!isPopoverOpen(element) || !ctx.intended()) return;
41
+ if (interestInvoker.current !== null) return;
42
+ ctx.recordCloseIntent({
43
+ reason: "dismiss",
44
+ event
45
+ });
46
+ interestHide.current = true;
47
+ element.hidePopover();
48
+ }, 0);
49
+ } else if (ctx.intended()) {
50
+ interestOpen.current = false;
51
+ ctx.requestClose(event, "dismiss");
52
+ }
53
+ };
54
+ const noteOpen = (event) => {
55
+ const source = eventSource(event);
56
+ interestOpen.current = source !== null && source === interestInvoker.current;
57
+ };
58
+ const noteClosed = () => {
59
+ interestOpen.current = false;
60
+ };
61
+ const takeLostInterest = () => {
62
+ const lostInterest = interestHide.current;
63
+ interestHide.current = false;
64
+ return lostInterest;
65
+ };
66
+ return {
67
+ onInterest,
68
+ onLoseInterest,
69
+ noteOpen,
70
+ noteClosed,
71
+ takeLostInterest,
72
+ reset: useCallback(() => {
73
+ clearTimeout(interestHideTask.current);
74
+ interestHideTask.current = void 0;
75
+ interestHide.current = false;
76
+ interestInvoker.current = null;
77
+ interestOpen.current = false;
78
+ }, [])
79
+ };
80
+ }
81
+ //#endregion
82
+ export { useInterestDismiss };
83
+
84
+ //# sourceMappingURL=use-interest-dismiss.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-interest-dismiss.mjs","names":[],"sources":["../../src/internal/use-interest-dismiss.ts"],"sourcesContent":["\"use client\";\nimport { useCallback, useRef } from \"react\";\nimport { eventSource } from \"./invokers.js\";\nimport { isPopoverOpen } from \"./popover-open.js\";\nimport type { PopoverRootValue } from \"./use-overlay-root.js\";\n\nexport interface InterestDismiss {\n /** `interest` at the popup: remembers the button that has interest in it. */\n onInterest(event: Event): void;\n /** `loseinterest` at the popup: the lost-interest hide (see `useInterestDismiss`). */\n onLoseInterest(event: Event): void;\n /** The opening `beforetoggle` the Root routes: whether it is the interest invoker's open. */\n noteOpen(event: ToggleEvent): void;\n /** The popup's `toggle` reported it hidden: the interest open is over. */\n noteClosed(): void;\n /** Whether the hide whose `toggle` arrived was the lost-interest hide; clears it. */\n takeLostInterest(): boolean;\n /** The popup element detached: cancels a pending hide and forgets everything. Stable. */\n reset(): void;\n}\n\n/**\n * Lost interest of an `interestfor` button naming the popup (library mode; Chromium; popover.md\n * lost-interest amendment), for `usePopoverPopup`. The platform hides only a popover its own\n * interest show opened (`invokedVia == kInterest`), and the library cancels that show and\n * re-shows with `showPopover({ source })`, so the platform never hides: the library does, as a\n * dismissal. Chromium also fires `loseinterest` from inside every hide of the popup while the\n * button has interest (Escape, script, the library's own close), before the state flips, and a\n * `hidePopover()` called from there re-enters the hide and loses its `toggle`: the hide waits one\n * task and runs only if the popup is still shown and still meant to be open, and returns no focus\n * to the Trigger. A pending interest open is cancelled instead.\n */\nexport function useInterestDismiss(ctx: PopoverRootValue): InterestDismiss {\n const isLibrary = ctx.mode === \"library\";\n const { popupRef } = ctx;\n // The button that has interest in the popup (`InterestEvent.source`), whether the current open\n // was that button's interest open, the task that hides the popup on its lost interest, and\n // whether the hide in flight is that one.\n const interestInvoker = useRef<Element | null>(null);\n const interestOpen = useRef(false);\n const interestHideTask = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n const interestHide = useRef(false);\n\n const onInterest = (event: Event): void => {\n const element = popupRef.current;\n if (!isLibrary || element === null || event.target !== element) return;\n interestInvoker.current = eventSource(event);\n };\n\n const onLoseInterest = (event: Event): void => {\n const element = popupRef.current;\n if (!isLibrary || element === null || event.target !== element) return;\n const source = eventSource(event);\n if (source === null || source !== interestInvoker.current) return;\n interestInvoker.current = null;\n if (!interestOpen.current) return;\n if (isPopoverOpen(element)) {\n clearTimeout(interestHideTask.current);\n interestHideTask.current = setTimeout(() => {\n interestHideTask.current = undefined;\n if (!isPopoverOpen(element) || !ctx.intended()) return;\n // Interest regained meanwhile (the pointer came back): the popup stays.\n if (interestInvoker.current !== null) return;\n // Recorded right before the hide, so its one-task clear cannot run first.\n ctx.recordCloseIntent({ reason: \"dismiss\", event });\n interestHide.current = true;\n element.hidePopover();\n }, 0);\n } else if (ctx.intended()) {\n interestOpen.current = false;\n ctx.requestClose(event, \"dismiss\");\n }\n };\n\n const noteOpen = (event: ToggleEvent): void => {\n // Chromium dispatches `interest` and then the interest show in one step, so a show whose\n // `source` is the remembered interest invoker is that button's interest open.\n const source = eventSource(event);\n interestOpen.current = source !== null && source === interestInvoker.current;\n };\n\n const noteClosed = (): void => {\n interestOpen.current = false;\n };\n\n const takeLostInterest = (): boolean => {\n const lostInterest = interestHide.current;\n interestHide.current = false;\n return lostInterest;\n };\n\n const reset = useCallback((): void => {\n clearTimeout(interestHideTask.current);\n interestHideTask.current = undefined;\n interestHide.current = false;\n interestInvoker.current = null;\n interestOpen.current = false;\n }, []);\n\n return { onInterest, onLoseInterest, noteOpen, noteClosed, takeLostInterest, reset };\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAgCA,SAAgB,mBAAmB,KAAwC;CACzE,MAAM,YAAY,IAAI,SAAS;CAC/B,MAAM,EAAE,aAAa;CAIrB,MAAM,kBAAkB,OAAuB,IAAI;CACnD,MAAM,eAAe,OAAO,KAAK;CACjC,MAAM,mBAAmB,OAAkD,KAAA,CAAS;CACpF,MAAM,eAAe,OAAO,KAAK;CAEjC,MAAM,cAAc,UAAuB;EACzC,MAAM,UAAU,SAAS;EACzB,IAAI,CAAC,aAAa,YAAY,QAAQ,MAAM,WAAW,SAAS;EAChE,gBAAgB,UAAU,YAAY,KAAK;CAC7C;CAEA,MAAM,kBAAkB,UAAuB;EAC7C,MAAM,UAAU,SAAS;EACzB,IAAI,CAAC,aAAa,YAAY,QAAQ,MAAM,WAAW,SAAS;EAChE,MAAM,SAAS,YAAY,KAAK;EAChC,IAAI,WAAW,QAAQ,WAAW,gBAAgB,SAAS;EAC3D,gBAAgB,UAAU;EAC1B,IAAI,CAAC,aAAa,SAAS;EAC3B,IAAI,cAAc,OAAO,GAAG;GAC1B,aAAa,iBAAiB,OAAO;GACrC,iBAAiB,UAAU,iBAAiB;IAC1C,iBAAiB,UAAU,KAAA;IAC3B,IAAI,CAAC,cAAc,OAAO,KAAK,CAAC,IAAI,SAAS,GAAG;IAEhD,IAAI,gBAAgB,YAAY,MAAM;IAEtC,IAAI,kBAAkB;KAAE,QAAQ;KAAW;IAAM,CAAC;IAClD,aAAa,UAAU;IACvB,QAAQ,YAAY;GACtB,GAAG,CAAC;EACN,OAAO,IAAI,IAAI,SAAS,GAAG;GACzB,aAAa,UAAU;GACvB,IAAI,aAAa,OAAO,SAAS;EACnC;CACF;CAEA,MAAM,YAAY,UAA6B;EAG7C,MAAM,SAAS,YAAY,KAAK;EAChC,aAAa,UAAU,WAAW,QAAQ,WAAW,gBAAgB;CACvE;CAEA,MAAM,mBAAyB;EAC7B,aAAa,UAAU;CACzB;CAEA,MAAM,yBAAkC;EACtC,MAAM,eAAe,aAAa;EAClC,aAAa,UAAU;EACvB,OAAO;CACT;CAUA,OAAO;EAAE;EAAY;EAAgB;EAAU;EAAY;EAAkB,OAR/D,kBAAwB;GACpC,aAAa,iBAAiB,OAAO;GACrC,iBAAiB,UAAU,KAAA;GAC3B,aAAa,UAAU;GACvB,gBAAgB,UAAU;GAC1B,aAAa,UAAU;EACzB,GAAG,CAAC,CAE6E;CAAE;AACrF"}
@@ -54,7 +54,8 @@ function useOverlayRoot(options) {
54
54
  const nextOpenGeneration = useCallback(() => {
55
55
  generation.current++;
56
56
  }, []);
57
- const recordCloseIntent = useCallback((intent) => {
57
+ const recordCloseIntent = useCallback((intent, options) => {
58
+ if (options?.unlessRecorded === true && closeIntent.current !== void 0) return;
58
59
  closeIntent.current = intent;
59
60
  if (intent !== void 0) clearLater(closeIntent, intent, popupRef, callbacks.current.isShown ?? isPopoverOpen);
60
61
  }, [callbacks]);
@@ -1 +1 @@
1
- {"version":3,"file":"use-overlay-root.mjs","names":[],"sources":["../../src/internal/use-overlay-root.ts"],"sourcesContent":["\"use client\";\nimport { useCallback, useId, useMemo, useRef, useState } from \"react\";\nimport type { RefObject } from \"react\";\nimport { createActionDetails } from \"./action-details.js\";\nimport { isPopoverOpen } from \"./popover-open.js\";\nimport { transitionTypes } from \"./transition-types.js\";\nimport type { ActionDetails, ChangeAction, ChangeReason } from \"./types.js\";\nimport { useControllableAction } from \"./use-controllable-action.js\";\nimport { useDevWarning } from \"./use-dev-warning.js\";\nimport { useLatest } from \"./use-latest.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/**\n * \"static\": JS-free mode, the browser owns open and close through Invoker Commands. \"library\":\n * opening and part-initiated closing are library-owned (transitions keyed on committed state);\n * dismissals are the browser's and notified (design/components/popover.md section 2).\n */\nexport type OverlayMode = \"static\" | \"library\";\n\n/**\n * What caused the next close, recorded just before it happens (design 2.3). The `toggle` event\n * carries no source; without an intent a close is a `\"dismiss\"`.\n */\nexport interface OverlayCloseIntent {\n readonly reason: ChangeReason;\n readonly event: Event | undefined;\n}\n\n/** The `details` every overlay `openChangeAction` receives (Dialog's adds `returnValue`). */\nexport interface OverlayDetails extends ActionDetails {\n readonly reason: ChangeReason;\n}\n\n/**\n * The Root's state and machinery, shared by Popover, Menu, Combobox (design 14) and Dialog. The\n * component puts it in its own context; `usePopoverTrigger` and `usePopoverPopup` take it as their\n * first argument. `Popup` is the popup element's type; `CloseArgs` are the extra arguments of a\n * close (Dialog's `returnValue`), passed on to the `details` builder.\n */\nexport interface OverlayRootValue<Popup extends HTMLElement, CloseArgs extends unknown[]> {\n readonly mode: OverlayMode;\n /** `useId`-based ids: the popup, its Title and its Description. */\n readonly ids: { readonly popup: string; readonly title: string; readonly description: string };\n /** Committed open state (library mode); `false` in JS-free mode. */\n readonly committed: boolean;\n /** Optimistic open state (library mode); `false` in JS-free mode. */\n readonly optimistic: boolean;\n /**\n * The popup is in the top layer, mirrored from its `toggle` (urgent, conventions 3.5): what\n * `aria-expanded` renders (#118). Written by a popover Popup in library mode; Dialog does not\n * maintain it.\n */\n readonly shown: boolean;\n /** Writes `shown` from the DOM (`:popover-open`); the Popup's `toggle`, ref attach and detach. */\n readonly setShown: (shown: boolean) => void;\n /** The Root's transition is pending (library mode). */\n readonly pending: boolean;\n /**\n * What the user already intends: the latest in-flight dispatch's `next`, else the optimistic\n * value of the last commit. Safe to call from handlers and effects (layout effects included,\n * also in the commit that changed it), and after an `await`. Not during render.\n */\n readonly intended: () => boolean;\n /**\n * A counter that grows with every open (a requested open, or the popup being shown). A part\n * whose close runs after an `await` records it first and drops the close when it changed: the\n * user dismissed and re-opened meanwhile (Popover.Close, design 3.4). Handlers only.\n */\n readonly openGeneration: () => number;\n /** Advance `openGeneration` (the Popup's `beforetoggle` for an open). */\n readonly nextOpenGeneration: () => void;\n /**\n * Open through the Root's transition (library mode): a Trigger click, a foreign open caught at\n * `beforetoggle`, or mount reconciliation. A no-op when `true` is already intended.\n */\n readonly requestOpen: (event: Event | undefined, reason: ChangeReason) => void;\n /**\n * A library-owned close (library mode): a Trigger click while open, a Close part, Menu's item\n * activation. `openChangeAction(false)` is awaited and the popup hides in the commit. A no-op\n * when `false` is already intended.\n */\n readonly requestClose: (\n event: Event | undefined,\n reason: ChangeReason,\n ...args: CloseArgs\n ) => void;\n /**\n * The browser hid the popup (a dismissal or a foreign invoker): dispatch the `false`\n * notification unless `false` is already intended (the library's own echo, or a dismissal\n * during a pending part-initiated close).\n */\n readonly notifyClosed: (\n event: Event | undefined,\n reason: ChangeReason,\n ...args: CloseArgs\n ) => void;\n /** From `useControllableAction`: the latest in-flight intent, or `null`. */\n readonly latestInFlight: () => { readonly next: boolean } | null;\n /** The registered Trigger: `showPopover({ source })` and the focus-return fallback. */\n readonly triggerRef: RefObject<HTMLElement | null>;\n /** The popup element, set by the Popup's ref; how Close reaches `hidePopover()` / `close()`. */\n readonly popupRef: RefObject<Popup | null>;\n /** Record what causes the next close. Cleared after a task if the popover did not close. */\n readonly recordCloseIntent: (intent: OverlayCloseIntent | undefined) => void;\n /** Read and clear the recorded intent (the Popup's `toggle` listener). */\n readonly takeCloseIntent: () => OverlayCloseIntent | undefined;\n}\n\n/** The root value of the popover-like components (Popover, Menu, Combobox). */\nexport type PopoverRootValue = OverlayRootValue<HTMLElement, []>;\n\nexport interface UseOverlayRootOptions<\n Details extends ActionDetails,\n Popup extends HTMLElement = HTMLElement,\n CloseArgs extends unknown[] = [],\n> {\n /** Transition types and messages: `\"popover\"` gives `fsui-popover`, `fsui-popover-open`, … */\n readonly component: string;\n /** Public name of the Root part for development warnings (`\"Popover.Root\"`). */\n readonly part: string;\n readonly open: boolean | undefined;\n readonly defaultOpen: boolean | undefined;\n readonly openChangeAction: ChangeAction<boolean, Details> | undefined;\n /**\n * `\"library\"` forces library mode whatever the props (Menu, which has no JS-free mode). Default:\n * detected from `open` / `defaultOpen` / `openChangeAction` on the first render.\n */\n readonly mode?: \"library\";\n /**\n * Called synchronously for every dispatch, before the action runs (Menu: cancel hover timers,\n * read the open cause).\n */\n readonly onDispatch?: (next: boolean, details: Details) => void;\n /** Builds the `details` of a dispatch (`popoverDetails`: `{ reason }`); an open passes no args. */\n readonly details: (\n event: Event | undefined,\n reason: ChangeReason,\n ...args: CloseArgs | []\n ) => Details;\n /** Whether the popup is shown, for a stale close intent. Default: `:popover-open`. */\n readonly isShown?: (popup: Popup) => boolean;\n}\n\n/** How long a recorded close intent survives when the popup did not close (design 2.3). */\nfunction clearLater<Popup extends HTMLElement>(\n intentRef: { current: OverlayCloseIntent | undefined },\n intent: OverlayCloseIntent,\n popupRef: { current: Popup | null },\n isShown: (popup: Popup) => boolean,\n): void {\n setTimeout(() => {\n // Closed: its `toggle` / `close` event (queued as a task) consumes the intent. Still open: the\n // close was cancelled or invalid, so the intent is stale.\n const popup = popupRef.current;\n if (intentRef.current === intent && popup !== null && isShown(popup)) {\n intentRef.current = undefined;\n }\n }, 0);\n}\n\n/** The `details` of a popover-like component: `{ reason }` (and `event`). */\nexport const popoverDetails = (event: Event | undefined, reason: ChangeReason): OverlayDetails =>\n createActionDetails(event, { reason });\n\n/**\n * The Root of an overlay without its public props: mode detection (once, from the first\n * render), `useControllableAction<boolean>`, ids, refs, close intents, the open generation and\n * the intent-aware `requestOpen` / `requestClose` / `notifyClosed`.\n */\nexport function useOverlayRoot<\n Details extends ActionDetails,\n Popup extends HTMLElement = HTMLElement,\n CloseArgs extends unknown[] = [],\n>(options: UseOverlayRootOptions<Details, Popup, CloseArgs>): OverlayRootValue<Popup, CloseArgs> {\n const { component, part, open, defaultOpen, openChangeAction, details, onDispatch } = options;\n\n // Mode is decided once, from the first render's props (design 2).\n const isLibraryNow =\n options.mode === \"library\" ||\n open !== undefined ||\n defaultOpen !== undefined ||\n openChangeAction !== undefined;\n const [mode] = useState<OverlayMode>(isLibraryNow ? \"library\" : \"static\");\n const isLibrary = mode === \"library\";\n useDevWarning(\n isLibrary !== isLibraryNow,\n isDev &&\n `${part}: the mode changed after mount (\\`open\\`, \\`defaultOpen\\` and \\`openChangeAction\\` ` +\n \"were all absent on one render and present on another). Switching between JS-free and \" +\n \"library mode is not supported.\",\n );\n\n // Hooks cannot be conditional: JS-free mode calls the hook too and never dispatches.\n const { committed, optimistic, pending, dispatch, latestInFlight } = useControllableAction<\n boolean,\n Details\n >({\n controlled: isLibrary ? open : undefined,\n defaultValue: isLibrary ? defaultOpen : undefined,\n initialValue: false,\n action: isLibrary ? openChangeAction : undefined,\n transitionTypes: (next) => transitionTypes(component, next ? \"open\" : \"close\"),\n warn: { component: part, prop: \"open\" },\n });\n\n const id = useId();\n const triggerRef = useRef<HTMLElement | null>(null);\n const popupRef = useRef<Popup | null>(null);\n const closeIntent = useRef<OverlayCloseIntent | undefined>(undefined);\n\n // The optimistic value of the last commit, for callers that run after an `await` (a Close\n // action's continuation) and would otherwise read the value of the render they were created in.\n // An insertion effect runs in the mutation phase, before any layout effect of the same commit\n // (a child's included), so `intended()` is current there too.\n const committedOptimistic = useLatest(optimistic);\n // `details`, `onDispatch` and `isShown` are usually inline functions: read the committed render's\n // through a ref so that the functions below, and with them the returned value, stay stable.\n const callbacks = useLatest({ details, onDispatch, isShown: options.isShown });\n const generation = useRef(0);\n const openGeneration = useCallback(() => generation.current, []);\n const nextOpenGeneration = useCallback(() => {\n generation.current++;\n }, []);\n\n const recordCloseIntent = useCallback(\n (intent: OverlayCloseIntent | undefined) => {\n closeIntent.current = intent;\n if (intent !== undefined) {\n clearLater(closeIntent, intent, popupRef, callbacks.current.isShown ?? isPopoverOpen);\n }\n },\n [callbacks],\n );\n const takeCloseIntent = useCallback(() => {\n const intent = closeIntent.current;\n closeIntent.current = undefined;\n return intent;\n }, []);\n\n // Conventions 3.8 rule 1: judge no-ops against what the user already intends. That also\n // deduplicates the StrictMode re-run of the mount reconciliation and recognises the library's\n // own `hidePopover()` echoing back through `toggle`.\n const intended = useCallback(\n (): boolean => latestInFlight()?.next ?? committedOptimistic.current,\n [latestInFlight, committedOptimistic],\n );\n\n const send = useCallback(\n (next: boolean, event: Event | undefined, reason: ChangeReason, args: CloseArgs | []): void => {\n const { details, onDispatch } = callbacks.current;\n const built = details(event, reason, ...args);\n if (next) nextOpenGeneration();\n onDispatch?.(next, built);\n dispatch(next, built);\n },\n [callbacks, nextOpenGeneration, dispatch],\n );\n\n const requestOpen = useCallback(\n (event: Event | undefined, reason: ChangeReason): void => {\n if (!isLibrary || intended()) return;\n send(true, event, reason, []);\n },\n [isLibrary, intended, send],\n );\n\n const requestClose = useCallback(\n (event: Event | undefined, reason: ChangeReason, ...args: CloseArgs): void => {\n if (!isLibrary || !intended()) return;\n send(false, event, reason, args);\n },\n [isLibrary, intended, send],\n );\n\n const [shown, setShown] = useState(false);\n\n const ids = useMemo(\n () => ({ popup: id, title: `${id}-title`, description: `${id}-description` }),\n [id],\n );\n\n // Memoised: every function above is stable, so the value changes only with the open state and\n // pending, and the components' context values built on it are reused otherwise.\n return useMemo(\n () => ({\n mode,\n ids,\n committed: isLibrary && committed,\n optimistic: isLibrary && optimistic,\n shown,\n setShown,\n pending: isLibrary && pending,\n intended,\n openGeneration,\n nextOpenGeneration,\n requestOpen,\n requestClose,\n // The same function as `requestClose`; a separate name because the callers mean different\n // things (a part asks to close; the platform already closed).\n notifyClosed: requestClose,\n latestInFlight,\n triggerRef,\n popupRef,\n recordCloseIntent,\n takeCloseIntent,\n }),\n [\n mode,\n ids,\n isLibrary,\n committed,\n optimistic,\n shown,\n pending,\n intended,\n openGeneration,\n nextOpenGeneration,\n requestOpen,\n requestClose,\n latestInFlight,\n recordCloseIntent,\n takeCloseIntent,\n ],\n );\n}\n"],"mappings":"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"}
1
+ {"version":3,"file":"use-overlay-root.mjs","names":[],"sources":["../../src/internal/use-overlay-root.ts"],"sourcesContent":["\"use client\";\nimport { useCallback, useId, useMemo, useRef, useState } from \"react\";\nimport type { RefObject } from \"react\";\nimport { createActionDetails } from \"./action-details.js\";\nimport { isPopoverOpen } from \"./popover-open.js\";\nimport { transitionTypes } from \"./transition-types.js\";\nimport type { ActionDetails, ChangeAction, ChangeReason } from \"./types.js\";\nimport { useControllableAction } from \"./use-controllable-action.js\";\nimport { useDevWarning } from \"./use-dev-warning.js\";\nimport { useLatest } from \"./use-latest.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/**\n * \"static\": JS-free mode, the browser owns open and close through Invoker Commands. \"library\":\n * opening and part-initiated closing are library-owned (transitions keyed on committed state);\n * dismissals are the browser's and notified (design/components/popover.md section 2).\n */\nexport type OverlayMode = \"static\" | \"library\";\n\n/**\n * What caused the next close, recorded just before it happens (design 2.3). The `toggle` event\n * names no cause beyond its invoker (`ToggleEvent.source`: a `popovertarget`, `commandfor` or\n * `interestfor` button); without an intent a close is a `\"dismiss\"`.\n */\nexport interface OverlayCloseIntent {\n readonly reason: ChangeReason;\n readonly event: Event | undefined;\n}\n\n/** The `details` every overlay `openChangeAction` receives (Dialog's adds `returnValue`). */\nexport interface OverlayDetails extends ActionDetails {\n readonly reason: ChangeReason;\n}\n\n/**\n * The Root's state and machinery, shared by Popover, Menu, Combobox (design 14) and Dialog. The\n * component puts it in its own context; `usePopoverTrigger` and `usePopoverPopup` take it as their\n * first argument. `Popup` is the popup element's type; `CloseArgs` are the extra arguments of a\n * close (Dialog's `returnValue`), passed on to the `details` builder.\n */\nexport interface OverlayRootValue<Popup extends HTMLElement, CloseArgs extends unknown[]> {\n readonly mode: OverlayMode;\n /** `useId`-based ids: the popup, its Title and its Description. */\n readonly ids: { readonly popup: string; readonly title: string; readonly description: string };\n /** Committed open state (library mode); `false` in JS-free mode. */\n readonly committed: boolean;\n /** Optimistic open state (library mode); `false` in JS-free mode. */\n readonly optimistic: boolean;\n /**\n * The popup is in the top layer, mirrored from its `toggle` (urgent, conventions 3.5): what\n * `aria-expanded` renders on a non-button Trigger and the Combobox Input (a `<button>`\n * Trigger renders none). Written by a popover Popup in library mode; Dialog does not\n * maintain it, and its context omits it.\n */\n readonly shown: boolean;\n /** Writes `shown` from the DOM (`:popover-open`); the Popup's `toggle`, ref attach and detach. */\n readonly setShown: (shown: boolean) => void;\n /** The Root's transition is pending (library mode). */\n readonly pending: boolean;\n /**\n * What the user already intends: the latest in-flight dispatch's `next`, else the optimistic\n * value of the last commit. Safe to call from handlers and effects (layout effects included,\n * also in the commit that changed it), and after an `await`. Not during render.\n */\n readonly intended: () => boolean;\n /**\n * A counter that grows with every open (a requested open, or the popup being shown). A part\n * whose close runs after an `await` records it first and drops the close when it changed: the\n * user dismissed and re-opened meanwhile (Popover.Close, design 3.4). Handlers only.\n */\n readonly openGeneration: () => number;\n /** Advance `openGeneration` (the Popup's `beforetoggle` for an open). */\n readonly nextOpenGeneration: () => void;\n /**\n * Open through the Root's transition (library mode): a Trigger click, a foreign open caught at\n * `beforetoggle`, or mount reconciliation. A no-op when `true` is already intended.\n */\n readonly requestOpen: (event: Event | undefined, reason: ChangeReason) => void;\n /**\n * A library-owned close (library mode): a Trigger click while open, a Close part, Menu's item\n * activation. `openChangeAction(false)` is awaited and the popup hides in the commit. A no-op\n * when `false` is already intended.\n */\n readonly requestClose: (\n event: Event | undefined,\n reason: ChangeReason,\n ...args: CloseArgs\n ) => void;\n /**\n * The browser hid the popup (a dismissal or a foreign invoker): dispatch the `false`\n * notification unless `false` is already intended (the library's own echo, or a dismissal\n * during a pending part-initiated close).\n */\n readonly notifyClosed: (\n event: Event | undefined,\n reason: ChangeReason,\n ...args: CloseArgs\n ) => void;\n /** From `useControllableAction`: the latest in-flight intent, or `null`. */\n readonly latestInFlight: () => { readonly next: boolean } | null;\n /** The registered Trigger: `showPopover({ source })` and the focus-return fallback. */\n readonly triggerRef: RefObject<HTMLElement | null>;\n /** The popup element, set by the Popup's ref; how Close reaches `hidePopover()` / `close()`. */\n readonly popupRef: RefObject<Popup | null>;\n /**\n * Record what causes the next close. Cleared after a task if the popover did not close.\n * `unlessRecorded`: keep an intent already recorded for this close (the `command` listener runs\n * before the `beforetoggle` of the same click).\n */\n readonly recordCloseIntent: (\n intent: OverlayCloseIntent | undefined,\n options?: { readonly unlessRecorded?: boolean },\n ) => void;\n /** Read and clear the recorded intent (the Popup's `toggle` listener). */\n readonly takeCloseIntent: () => OverlayCloseIntent | undefined;\n}\n\n/** The root value of the popover-like components (Popover, Menu, Combobox). */\nexport type PopoverRootValue = OverlayRootValue<HTMLElement, []>;\n\nexport interface UseOverlayRootOptions<\n Details extends ActionDetails,\n Popup extends HTMLElement = HTMLElement,\n CloseArgs extends unknown[] = [],\n> {\n /** Transition types and messages: `\"popover\"` gives `fsui-popover`, `fsui-popover-open`, … */\n readonly component: string;\n /** Public name of the Root part for development warnings (`\"Popover.Root\"`). */\n readonly part: string;\n readonly open: boolean | undefined;\n readonly defaultOpen: boolean | undefined;\n readonly openChangeAction: ChangeAction<boolean, Details> | undefined;\n /**\n * `\"library\"` forces library mode whatever the props (Menu, which has no JS-free mode). Default:\n * detected from `open` / `defaultOpen` / `openChangeAction` on the first render.\n */\n readonly mode?: \"library\";\n /**\n * Called synchronously for every dispatch, before the action runs (Menu: cancel hover timers,\n * read the open cause).\n */\n readonly onDispatch?: (next: boolean, details: Details) => void;\n /** Builds the `details` of a dispatch (`popoverDetails`: `{ reason }`); an open passes no args. */\n readonly details: (\n event: Event | undefined,\n reason: ChangeReason,\n ...args: CloseArgs | []\n ) => Details;\n /** Whether the popup is shown, for a stale close intent. Default: `:popover-open`. */\n readonly isShown?: (popup: Popup) => boolean;\n}\n\n/** How long a recorded close intent survives when the popup did not close (design 2.3). */\nfunction clearLater<Popup extends HTMLElement>(\n intentRef: { current: OverlayCloseIntent | undefined },\n intent: OverlayCloseIntent,\n popupRef: { current: Popup | null },\n isShown: (popup: Popup) => boolean,\n): void {\n setTimeout(() => {\n // Closed: its `toggle` / `close` event (queued as a task) consumes the intent. Still open: the\n // close was cancelled or invalid, so the intent is stale.\n const popup = popupRef.current;\n if (intentRef.current === intent && popup !== null && isShown(popup)) {\n intentRef.current = undefined;\n }\n }, 0);\n}\n\n/** The `details` of a popover-like component: `{ reason }` (and `event`). */\nexport const popoverDetails = (event: Event | undefined, reason: ChangeReason): OverlayDetails =>\n createActionDetails(event, { reason });\n\n/**\n * The Root of an overlay without its public props: mode detection (once, from the first\n * render), `useControllableAction<boolean>`, ids, refs, close intents, the open generation and\n * the intent-aware `requestOpen` / `requestClose` / `notifyClosed`.\n */\nexport function useOverlayRoot<\n Details extends ActionDetails,\n Popup extends HTMLElement = HTMLElement,\n CloseArgs extends unknown[] = [],\n>(options: UseOverlayRootOptions<Details, Popup, CloseArgs>): OverlayRootValue<Popup, CloseArgs> {\n const { component, part, open, defaultOpen, openChangeAction, details, onDispatch } = options;\n\n // Mode is decided once, from the first render's props (design 2).\n const isLibraryNow =\n options.mode === \"library\" ||\n open !== undefined ||\n defaultOpen !== undefined ||\n openChangeAction !== undefined;\n const [mode] = useState<OverlayMode>(isLibraryNow ? \"library\" : \"static\");\n const isLibrary = mode === \"library\";\n useDevWarning(\n isLibrary !== isLibraryNow,\n isDev &&\n `${part}: the mode changed after mount (\\`open\\`, \\`defaultOpen\\` and \\`openChangeAction\\` ` +\n \"were all absent on one render and present on another). Switching between JS-free and \" +\n \"library mode is not supported.\",\n );\n\n // Hooks cannot be conditional: JS-free mode calls the hook too and never dispatches.\n const { committed, optimistic, pending, dispatch, latestInFlight } = useControllableAction<\n boolean,\n Details\n >({\n controlled: isLibrary ? open : undefined,\n defaultValue: isLibrary ? defaultOpen : undefined,\n initialValue: false,\n action: isLibrary ? openChangeAction : undefined,\n transitionTypes: (next) => transitionTypes(component, next ? \"open\" : \"close\"),\n warn: { component: part, prop: \"open\" },\n });\n\n const id = useId();\n const triggerRef = useRef<HTMLElement | null>(null);\n const popupRef = useRef<Popup | null>(null);\n const closeIntent = useRef<OverlayCloseIntent | undefined>(undefined);\n\n // The optimistic value of the last commit, for callers that run after an `await` (a Close\n // action's continuation) and would otherwise read the value of the render they were created in.\n // An insertion effect runs in the mutation phase, before any layout effect of the same commit\n // (a child's included), so `intended()` is current there too.\n const committedOptimistic = useLatest(optimistic);\n // `details`, `onDispatch` and `isShown` are usually inline functions: read the committed render's\n // through a ref so that the functions below, and with them the returned value, stay stable.\n const callbacks = useLatest({ details, onDispatch, isShown: options.isShown });\n const generation = useRef(0);\n const openGeneration = useCallback(() => generation.current, []);\n const nextOpenGeneration = useCallback(() => {\n generation.current++;\n }, []);\n\n const recordCloseIntent = useCallback(\n (intent: OverlayCloseIntent | undefined, options?: { readonly unlessRecorded?: boolean }) => {\n if (options?.unlessRecorded === true && closeIntent.current !== undefined) return;\n closeIntent.current = intent;\n if (intent !== undefined) {\n clearLater(closeIntent, intent, popupRef, callbacks.current.isShown ?? isPopoverOpen);\n }\n },\n [callbacks],\n );\n const takeCloseIntent = useCallback(() => {\n const intent = closeIntent.current;\n closeIntent.current = undefined;\n return intent;\n }, []);\n\n // Conventions 3.8 rule 1: judge no-ops against what the user already intends. That also\n // deduplicates the StrictMode re-run of the mount reconciliation and recognises the library's\n // own `hidePopover()` echoing back through `toggle`.\n const intended = useCallback(\n (): boolean => latestInFlight()?.next ?? committedOptimistic.current,\n [latestInFlight, committedOptimistic],\n );\n\n const send = useCallback(\n (next: boolean, event: Event | undefined, reason: ChangeReason, args: CloseArgs | []): void => {\n const { details, onDispatch } = callbacks.current;\n const built = details(event, reason, ...args);\n if (next) nextOpenGeneration();\n onDispatch?.(next, built);\n dispatch(next, built);\n },\n [callbacks, nextOpenGeneration, dispatch],\n );\n\n const requestOpen = useCallback(\n (event: Event | undefined, reason: ChangeReason): void => {\n if (!isLibrary || intended()) return;\n send(true, event, reason, []);\n },\n [isLibrary, intended, send],\n );\n\n const requestClose = useCallback(\n (event: Event | undefined, reason: ChangeReason, ...args: CloseArgs): void => {\n if (!isLibrary || !intended()) return;\n send(false, event, reason, args);\n },\n [isLibrary, intended, send],\n );\n\n const [shown, setShown] = useState(false);\n\n const ids = useMemo(\n () => ({ popup: id, title: `${id}-title`, description: `${id}-description` }),\n [id],\n );\n\n // Memoised: every function above is stable, so the value changes only with the open state and\n // pending, and the components' context values built on it are reused otherwise.\n return useMemo(\n () => ({\n mode,\n ids,\n committed: isLibrary && committed,\n optimistic: isLibrary && optimistic,\n shown,\n setShown,\n pending: isLibrary && pending,\n intended,\n openGeneration,\n nextOpenGeneration,\n requestOpen,\n requestClose,\n // The same function as `requestClose`; a separate name because the callers mean different\n // things (a part asks to close; the platform already closed).\n notifyClosed: requestClose,\n latestInFlight,\n triggerRef,\n popupRef,\n recordCloseIntent,\n takeCloseIntent,\n }),\n [\n mode,\n ids,\n isLibrary,\n committed,\n optimistic,\n shown,\n pending,\n intended,\n openGeneration,\n nextOpenGeneration,\n requestOpen,\n requestClose,\n latestInFlight,\n recordCloseIntent,\n takeCloseIntent,\n ],\n );\n}\n"],"mappings":"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"}