@zag-js/popover 0.2.4 → 0.2.6

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.
package/dist/index.js CHANGED
@@ -41,15 +41,50 @@ var anatomy = (0, import_anatomy.createAnatomy)("popover").parts(
41
41
  );
42
42
  var parts = anatomy.build();
43
43
 
44
- // ../../utilities/dom/dist/index.mjs
44
+ // ../../utilities/dom/src/attrs.ts
45
45
  var dataAttr = (guard) => {
46
46
  return guard ? "" : void 0;
47
47
  };
48
+
49
+ // ../../utilities/core/src/array.ts
50
+ function nextIndex(v, idx, opts = {}) {
51
+ const { step = 1, loop = true } = opts;
52
+ const next2 = idx + step;
53
+ const len = v.length;
54
+ const last = len - 1;
55
+ if (idx === -1)
56
+ return step > 0 ? 0 : last;
57
+ if (next2 < 0)
58
+ return loop ? last : 0;
59
+ if (next2 >= len)
60
+ return loop ? 0 : idx > len ? len : idx;
61
+ return next2;
62
+ }
63
+ function next(v, idx, opts = {}) {
64
+ return v[nextIndex(v, idx, opts)];
65
+ }
66
+
67
+ // ../../utilities/core/src/functions.ts
48
68
  var runIfFn = (v, ...a) => {
49
69
  const res = typeof v === "function" ? v(...a) : v;
50
70
  return res != null ? res : void 0;
51
71
  };
72
+
73
+ // ../../utilities/core/src/guard.ts
74
+ var isArray = (v) => Array.isArray(v);
75
+ var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
52
76
  var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
77
+
78
+ // ../../utilities/core/src/object.ts
79
+ function compact(obj) {
80
+ if (obj === void 0)
81
+ return obj;
82
+ return Object.fromEntries(
83
+ Object.entries(obj).filter(([, value]) => value !== void 0).map(([key, value]) => [key, isObject(value) ? compact(value) : value])
84
+ );
85
+ }
86
+
87
+ // ../../utilities/dom/src/query.ts
53
88
  function isDocument(el) {
54
89
  return el.nodeType === Node.DOCUMENT_NODE;
55
90
  }
@@ -117,7 +152,11 @@ function isVisible(el) {
117
152
  return false;
118
153
  return el.offsetWidth > 0 || el.offsetHeight > 0 || el.getClientRects().length > 0;
119
154
  }
155
+
156
+ // ../../utilities/dom/src/event.ts
120
157
  var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
158
+
159
+ // ../../utilities/dom/src/focusable.ts
121
160
  function hasNegativeTabIndex(element) {
122
161
  const tabIndex = parseInt(element.getAttribute("tabindex") || "0", 10);
123
162
  return tabIndex < 0;
@@ -176,6 +215,8 @@ function getLastTabbable(container, includeContainer) {
176
215
  const elements = getTabbables(container, includeContainer);
177
216
  return elements[elements.length - 1] || null;
178
217
  }
218
+
219
+ // ../../utilities/dom/src/listener.ts
179
220
  var isRef = (v) => hasProp(v, "current");
180
221
  function addDomEvent(target, eventName, handler, options) {
181
222
  const node = isRef(target) ? target.current : runIfFn(target);
@@ -184,6 +225,8 @@ function addDomEvent(target, eventName, handler, options) {
184
225
  node == null ? void 0 : node.removeEventListener(eventName, handler, options);
185
226
  };
186
227
  }
228
+
229
+ // ../../utilities/dom/src/next-tick.ts
187
230
  function nextTick(fn) {
188
231
  const set = /* @__PURE__ */ new Set();
189
232
  function raf2(fn2) {
@@ -207,37 +250,6 @@ function raf(fn) {
207
250
  // src/popover.connect.ts
208
251
  var import_popper = require("@zag-js/popper");
209
252
 
210
- // ../../utilities/core/dist/index.mjs
211
- function nextIndex(v, idx, opts = {}) {
212
- const { step = 1, loop = true } = opts;
213
- const next2 = idx + step;
214
- const len = v.length;
215
- const last2 = len - 1;
216
- if (idx === -1)
217
- return step > 0 ? 0 : last2;
218
- if (next2 < 0)
219
- return loop ? last2 : 0;
220
- if (next2 >= len)
221
- return loop ? 0 : idx > len ? len : idx;
222
- return next2;
223
- }
224
- function next(v, idx, opts = {}) {
225
- return v[nextIndex(v, idx, opts)];
226
- }
227
- var runIfFn2 = (v, ...a) => {
228
- const res = typeof v === "function" ? v(...a) : v;
229
- return res != null ? res : void 0;
230
- };
231
- var isArray = (v) => Array.isArray(v);
232
- var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
233
- function compact(obj) {
234
- if (obj === void 0)
235
- return obj;
236
- return Object.fromEntries(
237
- Object.entries(obj).filter(([, value]) => value !== void 0).map(([key, value]) => [key, isObject(value) ? compact(value) : value])
238
- );
239
- }
240
-
241
253
  // src/popover.dom.ts
242
254
  var dom = defineDomHelpers({
243
255
  getActiveEl: (ctx) => dom.getDoc(ctx).activeElement,
@@ -280,7 +292,7 @@ var dom = defineDomHelpers({
280
292
  getFirstTabbableEl: (ctx) => getFirstTabbable(dom.getContentEl(ctx), "if-empty"),
281
293
  getLastTabbableEl: (ctx) => getLastTabbable(dom.getContentEl(ctx), "if-empty"),
282
294
  getInitialFocusEl: (ctx) => {
283
- let el = runIfFn2(ctx.initialFocusEl);
295
+ let el = runIfFn(ctx.initialFocusEl);
284
296
  if (!el && ctx.autoFocus)
285
297
  el = dom.getFirstFocusableEl(ctx);
286
298
  if (!el)
@@ -565,7 +577,7 @@ function machine(userContext) {
565
577
  returnFocusOnDeactivate: true,
566
578
  document: dom.getDoc(ctx2),
567
579
  fallbackFocus: el,
568
- initialFocus: runIfFn2(ctx2.initialFocusEl)
580
+ initialFocus: runIfFn(ctx2.initialFocusEl)
569
581
  });
570
582
  try {
571
583
  trap.activate();