@zag-js/popover 0.2.10 → 0.2.12

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.
@@ -23,122 +23,29 @@ __export(popover_connect_exports, {
23
23
  connect: () => connect
24
24
  });
25
25
  module.exports = __toCommonJS(popover_connect_exports);
26
-
27
- // ../../utilities/dom/src/attrs.ts
28
- var dataAttr = (guard) => {
29
- return guard ? "" : void 0;
30
- };
31
-
32
- // ../../utilities/core/src/functions.ts
33
- var runIfFn = (v, ...a) => {
34
- const res = typeof v === "function" ? v(...a) : v;
35
- return res ?? void 0;
36
- };
37
-
38
- // ../../utilities/dom/src/query.ts
39
- function isDocument(el) {
40
- return el.nodeType === Node.DOCUMENT_NODE;
41
- }
42
- function isWindow(value) {
43
- return value?.toString() === "[object Window]";
44
- }
45
- function isFrame(element) {
46
- return element.localName === "iframe";
47
- }
48
- function getDocument(el) {
49
- if (isWindow(el))
50
- return el.document;
51
- if (isDocument(el))
52
- return el;
53
- return el?.ownerDocument ?? document;
54
- }
55
- function defineDomHelpers(helpers) {
56
- const dom2 = {
57
- getRootNode: (ctx) => ctx.getRootNode?.() ?? document,
58
- getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
59
- getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
60
- getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
61
- getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
62
- };
63
- return {
64
- ...dom2,
65
- ...helpers
66
- };
67
- }
68
- function isHTMLElement(v) {
69
- return typeof v === "object" && v?.nodeType === Node.ELEMENT_NODE && typeof v?.nodeName === "string";
70
- }
71
- function isVisible(el) {
72
- if (!isHTMLElement(el))
73
- return false;
74
- return el.offsetWidth > 0 || el.offsetHeight > 0 || el.getClientRects().length > 0;
75
- }
76
-
77
- // ../../utilities/dom/src/focusable.ts
78
- function hasNegativeTabIndex(element) {
79
- const tabIndex = parseInt(element.getAttribute("tabindex") || "0", 10);
80
- return tabIndex < 0;
81
- }
82
- var focusableSelector = "input:not([type='hidden']):not([disabled]), select:not([disabled]), textarea:not([disabled]), a[href], button:not([disabled]), [tabindex], iframe, object, embed, area[href], audio[controls], video[controls], [contenteditable]:not([contenteditable='false']), details > summary:first-of-type";
83
- var getFocusables = (container, includeContainer = false) => {
84
- if (!container)
85
- return [];
86
- const elements = Array.from(container.querySelectorAll(focusableSelector));
87
- const include = includeContainer == true || includeContainer == "if-empty" && elements.length === 0;
88
- if (include && isHTMLElement(container) && isFocusable(container)) {
89
- elements.unshift(container);
90
- }
91
- const focusableElements = elements.filter(isFocusable);
92
- focusableElements.forEach((element, i) => {
93
- if (isFrame(element) && element.contentDocument) {
94
- const frameBody = element.contentDocument.body;
95
- focusableElements.splice(i, 1, ...getFocusables(frameBody));
96
- }
97
- });
98
- return focusableElements;
99
- };
100
- function isFocusable(element) {
101
- if (!element)
102
- return false;
103
- return element.matches(focusableSelector) && isVisible(element);
104
- }
105
- function getTabbables(container, includeContainer) {
106
- if (!container)
107
- return [];
108
- const elements = Array.from(container.querySelectorAll(focusableSelector));
109
- const tabbableElements = elements.filter(isTabbable);
110
- if (includeContainer && isTabbable(container)) {
111
- tabbableElements.unshift(container);
112
- }
113
- tabbableElements.forEach((element, i) => {
114
- if (isFrame(element) && element.contentDocument) {
115
- const frameBody = element.contentDocument.body;
116
- const allFrameTabbable = getTabbables(frameBody);
117
- tabbableElements.splice(i, 1, ...allFrameTabbable);
118
- }
119
- });
120
- if (!tabbableElements.length && includeContainer) {
121
- return elements;
122
- }
123
- return tabbableElements;
124
- }
125
- function isTabbable(el) {
126
- return isFocusable(el) && !hasNegativeTabIndex(el);
127
- }
128
- function getFirstTabbable(container, includeContainer) {
129
- const [first] = getTabbables(container, includeContainer);
130
- return first || null;
131
- }
132
- function getLastTabbable(container, includeContainer) {
133
- const elements = getTabbables(container, includeContainer);
134
- return elements[elements.length - 1] || null;
135
- }
136
-
137
- // src/popover.connect.ts
26
+ var import_dom_query2 = require("@zag-js/dom-query");
138
27
  var import_popper = require("@zag-js/popper");
139
28
 
29
+ // src/popover.anatomy.ts
30
+ var import_anatomy = require("@zag-js/anatomy");
31
+ var anatomy = (0, import_anatomy.createAnatomy)("popover").parts(
32
+ "arrow",
33
+ "arrowTip",
34
+ "anchor",
35
+ "trigger",
36
+ "positioner",
37
+ "content",
38
+ "title",
39
+ "description",
40
+ "closeTrigger"
41
+ );
42
+ var parts = anatomy.build();
43
+
140
44
  // src/popover.dom.ts
141
- var dom = defineDomHelpers({
45
+ var import_dom_query = require("@zag-js/dom-query");
46
+ var import_tabbable = require("@zag-js/tabbable");
47
+ var import_utils = require("@zag-js/utils");
48
+ var dom = (0, import_dom_query.createScope)({
142
49
  getActiveEl: (ctx) => dom.getDoc(ctx).activeElement,
143
50
  getAnchorId: (ctx) => ctx.ids?.anchor ?? `popover:${ctx.id}:anchor`,
144
51
  getTriggerId: (ctx) => ctx.ids?.trigger ?? `popover:${ctx.id}:trigger`,
@@ -154,14 +61,14 @@ var dom = defineDomHelpers({
154
61
  getPositionerEl: (ctx) => dom.getById(ctx, dom.getPositionerId(ctx)),
155
62
  getTitleEl: (ctx) => dom.getById(ctx, dom.getTitleId(ctx)),
156
63
  getDescriptionEl: (ctx) => dom.getById(ctx, dom.getDescriptionId(ctx)),
157
- getFocusableEls: (ctx) => getFocusables(dom.getContentEl(ctx)),
64
+ getFocusableEls: (ctx) => (0, import_tabbable.getFocusables)(dom.getContentEl(ctx)),
158
65
  getFirstFocusableEl: (ctx) => dom.getFocusableEls(ctx)[0],
159
- getDocTabbableEls: (ctx) => getTabbables(dom.getDoc(ctx).body),
160
- getTabbableEls: (ctx) => getTabbables(dom.getContentEl(ctx), "if-empty"),
161
- getFirstTabbableEl: (ctx) => getFirstTabbable(dom.getContentEl(ctx), "if-empty"),
162
- getLastTabbableEl: (ctx) => getLastTabbable(dom.getContentEl(ctx), "if-empty"),
66
+ getDocTabbableEls: (ctx) => (0, import_tabbable.getTabbables)(dom.getDoc(ctx).body),
67
+ getTabbableEls: (ctx) => (0, import_tabbable.getTabbables)(dom.getContentEl(ctx), "if-empty"),
68
+ getFirstTabbableEl: (ctx) => (0, import_tabbable.getFirstTabbable)(dom.getContentEl(ctx), "if-empty"),
69
+ getLastTabbableEl: (ctx) => (0, import_tabbable.getLastTabbable)(dom.getContentEl(ctx), "if-empty"),
163
70
  getInitialFocusEl: (ctx) => {
164
- let el = runIfFn(ctx.initialFocusEl);
71
+ let el = (0, import_utils.runIfFn)(ctx.initialFocusEl);
165
72
  if (!el && ctx.autoFocus)
166
73
  el = dom.getFirstFocusableEl(ctx);
167
74
  if (!el)
@@ -170,21 +77,6 @@ var dom = defineDomHelpers({
170
77
  }
171
78
  });
172
79
 
173
- // src/popover.anatomy.ts
174
- var import_anatomy = require("@zag-js/anatomy");
175
- var anatomy = (0, import_anatomy.createAnatomy)("popover").parts(
176
- "arrow",
177
- "arrowTip",
178
- "anchor",
179
- "trigger",
180
- "positioner",
181
- "content",
182
- "title",
183
- "description",
184
- "closeTrigger"
185
- );
186
- var parts = anatomy.build();
187
-
188
80
  // src/popover.connect.ts
189
81
  function connect(state, send, normalize) {
190
82
  const isOpen = state.matches("open");
@@ -196,11 +88,23 @@ function connect(state, send, normalize) {
196
88
  placement: currentPlacement
197
89
  });
198
90
  return {
91
+ /**
92
+ * Whether the popover is portalled
93
+ */
199
94
  portalled,
95
+ /**
96
+ * Whether the popover is open
97
+ */
200
98
  isOpen,
99
+ /**
100
+ * Function to open the popover
101
+ */
201
102
  open() {
202
103
  send("OPEN");
203
104
  },
105
+ /**
106
+ * Function to close the popover
107
+ */
204
108
  close() {
205
109
  send("CLOSE");
206
110
  },
@@ -224,7 +128,7 @@ function connect(state, send, normalize) {
224
128
  id: dom.getTriggerId(state.context),
225
129
  "aria-haspopup": "dialog",
226
130
  "aria-expanded": isOpen,
227
- "data-expanded": dataAttr(isOpen),
131
+ "data-expanded": (0, import_dom_query2.dataAttr)(isOpen),
228
132
  "aria-controls": dom.getContentId(state.context),
229
133
  onClick() {
230
134
  send("TOGGLE");
@@ -244,7 +148,7 @@ function connect(state, send, normalize) {
244
148
  tabIndex: -1,
245
149
  role: "dialog",
246
150
  hidden: !isOpen,
247
- "data-expanded": dataAttr(isOpen),
151
+ "data-expanded": (0, import_dom_query2.dataAttr)(isOpen),
248
152
  "aria-labelledby": rendered.title ? dom.getTitleId(state.context) : void 0,
249
153
  "aria-describedby": rendered.description ? dom.getDescriptionId(state.context) : void 0,
250
154
  "data-placement": currentPlacement
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  connect
3
- } from "./chunk-JNFEFPEH.mjs";
3
+ } from "./chunk-GKHXQZZB.mjs";
4
4
  import "./chunk-KTOPDXGV.mjs";
5
- import "./chunk-2EVL5G6H.mjs";
5
+ import "./chunk-4IGGT6KB.mjs";
6
6
  export {
7
7
  connect
8
8
  };
@@ -6,20 +6,23 @@ import '@zag-js/types';
6
6
 
7
7
  declare const dom: {
8
8
  getRootNode: (ctx: {
9
- getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
10
- }) => Document | ShadowRoot;
9
+ getRootNode?: (() => Node | ShadowRoot | Document) | undefined;
10
+ }) => ShadowRoot | Document;
11
11
  getDoc: (ctx: {
12
- getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
12
+ getRootNode?: (() => Node | ShadowRoot | Document) | undefined;
13
13
  }) => Document;
14
14
  getWin: (ctx: {
15
- getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
15
+ getRootNode?: (() => Node | ShadowRoot | Document) | undefined;
16
16
  }) => Window & typeof globalThis;
17
17
  getActiveElement: (ctx: {
18
- getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
18
+ getRootNode?: (() => Node | ShadowRoot | Document) | undefined;
19
19
  }) => HTMLElement | null;
20
- getById: <T = HTMLElement>(ctx: {
21
- getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
20
+ getById: <T extends HTMLElement = HTMLElement>(ctx: {
21
+ getRootNode?: (() => Node | ShadowRoot | Document) | undefined;
22
22
  }, id: string) => T | null;
23
+ queryById: <T_1 extends HTMLElement = HTMLElement>(ctx: {
24
+ getRootNode?: (() => Node | ShadowRoot | Document) | undefined;
25
+ }, id: string) => T_1;
23
26
  } & {
24
27
  getActiveEl: (ctx: MachineContext) => Element | null;
25
28
  getAnchorId: (ctx: MachineContext) => string;
@@ -23,114 +23,10 @@ __export(popover_dom_exports, {
23
23
  dom: () => dom
24
24
  });
25
25
  module.exports = __toCommonJS(popover_dom_exports);
26
-
27
- // ../../utilities/core/src/functions.ts
28
- var runIfFn = (v, ...a) => {
29
- const res = typeof v === "function" ? v(...a) : v;
30
- return res ?? void 0;
31
- };
32
-
33
- // ../../utilities/dom/src/query.ts
34
- function isDocument(el) {
35
- return el.nodeType === Node.DOCUMENT_NODE;
36
- }
37
- function isWindow(value) {
38
- return value?.toString() === "[object Window]";
39
- }
40
- function isFrame(element) {
41
- return element.localName === "iframe";
42
- }
43
- function getDocument(el) {
44
- if (isWindow(el))
45
- return el.document;
46
- if (isDocument(el))
47
- return el;
48
- return el?.ownerDocument ?? document;
49
- }
50
- function defineDomHelpers(helpers) {
51
- const dom2 = {
52
- getRootNode: (ctx) => ctx.getRootNode?.() ?? document,
53
- getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
54
- getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
55
- getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
56
- getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
57
- };
58
- return {
59
- ...dom2,
60
- ...helpers
61
- };
62
- }
63
- function isHTMLElement(v) {
64
- return typeof v === "object" && v?.nodeType === Node.ELEMENT_NODE && typeof v?.nodeName === "string";
65
- }
66
- function isVisible(el) {
67
- if (!isHTMLElement(el))
68
- return false;
69
- return el.offsetWidth > 0 || el.offsetHeight > 0 || el.getClientRects().length > 0;
70
- }
71
-
72
- // ../../utilities/dom/src/focusable.ts
73
- function hasNegativeTabIndex(element) {
74
- const tabIndex = parseInt(element.getAttribute("tabindex") || "0", 10);
75
- return tabIndex < 0;
76
- }
77
- var focusableSelector = "input:not([type='hidden']):not([disabled]), select:not([disabled]), textarea:not([disabled]), a[href], button:not([disabled]), [tabindex], iframe, object, embed, area[href], audio[controls], video[controls], [contenteditable]:not([contenteditable='false']), details > summary:first-of-type";
78
- var getFocusables = (container, includeContainer = false) => {
79
- if (!container)
80
- return [];
81
- const elements = Array.from(container.querySelectorAll(focusableSelector));
82
- const include = includeContainer == true || includeContainer == "if-empty" && elements.length === 0;
83
- if (include && isHTMLElement(container) && isFocusable(container)) {
84
- elements.unshift(container);
85
- }
86
- const focusableElements = elements.filter(isFocusable);
87
- focusableElements.forEach((element, i) => {
88
- if (isFrame(element) && element.contentDocument) {
89
- const frameBody = element.contentDocument.body;
90
- focusableElements.splice(i, 1, ...getFocusables(frameBody));
91
- }
92
- });
93
- return focusableElements;
94
- };
95
- function isFocusable(element) {
96
- if (!element)
97
- return false;
98
- return element.matches(focusableSelector) && isVisible(element);
99
- }
100
- function getTabbables(container, includeContainer) {
101
- if (!container)
102
- return [];
103
- const elements = Array.from(container.querySelectorAll(focusableSelector));
104
- const tabbableElements = elements.filter(isTabbable);
105
- if (includeContainer && isTabbable(container)) {
106
- tabbableElements.unshift(container);
107
- }
108
- tabbableElements.forEach((element, i) => {
109
- if (isFrame(element) && element.contentDocument) {
110
- const frameBody = element.contentDocument.body;
111
- const allFrameTabbable = getTabbables(frameBody);
112
- tabbableElements.splice(i, 1, ...allFrameTabbable);
113
- }
114
- });
115
- if (!tabbableElements.length && includeContainer) {
116
- return elements;
117
- }
118
- return tabbableElements;
119
- }
120
- function isTabbable(el) {
121
- return isFocusable(el) && !hasNegativeTabIndex(el);
122
- }
123
- function getFirstTabbable(container, includeContainer) {
124
- const [first] = getTabbables(container, includeContainer);
125
- return first || null;
126
- }
127
- function getLastTabbable(container, includeContainer) {
128
- const elements = getTabbables(container, includeContainer);
129
- return elements[elements.length - 1] || null;
130
- }
131
-
132
- // src/popover.dom.ts
133
- var dom = defineDomHelpers({
26
+ var import_dom_query = require("@zag-js/dom-query");
27
+ var import_tabbable = require("@zag-js/tabbable");
28
+ var import_utils = require("@zag-js/utils");
29
+ var dom = (0, import_dom_query.createScope)({
134
30
  getActiveEl: (ctx) => dom.getDoc(ctx).activeElement,
135
31
  getAnchorId: (ctx) => ctx.ids?.anchor ?? `popover:${ctx.id}:anchor`,
136
32
  getTriggerId: (ctx) => ctx.ids?.trigger ?? `popover:${ctx.id}:trigger`,
@@ -146,14 +42,14 @@ var dom = defineDomHelpers({
146
42
  getPositionerEl: (ctx) => dom.getById(ctx, dom.getPositionerId(ctx)),
147
43
  getTitleEl: (ctx) => dom.getById(ctx, dom.getTitleId(ctx)),
148
44
  getDescriptionEl: (ctx) => dom.getById(ctx, dom.getDescriptionId(ctx)),
149
- getFocusableEls: (ctx) => getFocusables(dom.getContentEl(ctx)),
45
+ getFocusableEls: (ctx) => (0, import_tabbable.getFocusables)(dom.getContentEl(ctx)),
150
46
  getFirstFocusableEl: (ctx) => dom.getFocusableEls(ctx)[0],
151
- getDocTabbableEls: (ctx) => getTabbables(dom.getDoc(ctx).body),
152
- getTabbableEls: (ctx) => getTabbables(dom.getContentEl(ctx), "if-empty"),
153
- getFirstTabbableEl: (ctx) => getFirstTabbable(dom.getContentEl(ctx), "if-empty"),
154
- getLastTabbableEl: (ctx) => getLastTabbable(dom.getContentEl(ctx), "if-empty"),
47
+ getDocTabbableEls: (ctx) => (0, import_tabbable.getTabbables)(dom.getDoc(ctx).body),
48
+ getTabbableEls: (ctx) => (0, import_tabbable.getTabbables)(dom.getContentEl(ctx), "if-empty"),
49
+ getFirstTabbableEl: (ctx) => (0, import_tabbable.getFirstTabbable)(dom.getContentEl(ctx), "if-empty"),
50
+ getLastTabbableEl: (ctx) => (0, import_tabbable.getLastTabbable)(dom.getContentEl(ctx), "if-empty"),
155
51
  getInitialFocusEl: (ctx) => {
156
- let el = runIfFn(ctx.initialFocusEl);
52
+ let el = (0, import_utils.runIfFn)(ctx.initialFocusEl);
157
53
  if (!el && ctx.autoFocus)
158
54
  el = dom.getFirstFocusableEl(ctx);
159
55
  if (!el)
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  dom
3
- } from "./chunk-2EVL5G6H.mjs";
3
+ } from "./chunk-4IGGT6KB.mjs";
4
4
  export {
5
5
  dom
6
6
  };