@zag-js/popover 0.0.0-dev-20220707125149 → 0.0.0-dev-20220709094318

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
@@ -43,6 +43,22 @@ __export(src_exports, {
43
43
  module.exports = __toCommonJS(src_exports);
44
44
 
45
45
  // ../../utilities/dom/dist/index.mjs
46
+ var __defProp2 = Object.defineProperty;
47
+ var __getOwnPropSymbols2 = Object.getOwnPropertySymbols;
48
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
49
+ var __propIsEnum2 = Object.prototype.propertyIsEnumerable;
50
+ var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
51
+ var __spreadValues2 = (a, b) => {
52
+ for (var prop in b || (b = {}))
53
+ if (__hasOwnProp2.call(b, prop))
54
+ __defNormalProp2(a, prop, b[prop]);
55
+ if (__getOwnPropSymbols2)
56
+ for (var prop of __getOwnPropSymbols2(b)) {
57
+ if (__propIsEnum2.call(b, prop))
58
+ __defNormalProp2(a, prop, b[prop]);
59
+ }
60
+ return a;
61
+ };
46
62
  var dataAttr = (guard) => {
47
63
  return guard ? "" : void 0;
48
64
  };
@@ -51,6 +67,9 @@ var runIfFn = (v, ...a) => {
51
67
  return res != null ? res : void 0;
52
68
  };
53
69
  var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
70
+ function isDocument(el) {
71
+ return el.nodeType === Node.DOCUMENT_NODE;
72
+ }
54
73
  function isWindow(value) {
55
74
  return (value == null ? void 0 : value.toString()) === "[object Window]";
56
75
  }
@@ -61,12 +80,28 @@ function getDocument(el) {
61
80
  var _a;
62
81
  if (isWindow(el))
63
82
  return el.document;
83
+ if (isDocument(el))
84
+ return el;
64
85
  return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
65
86
  }
66
87
  function getEventTarget(event) {
67
88
  var _a, _b;
68
89
  return (_b = (_a = event.composedPath) == null ? void 0 : _a.call(event)[0]) != null ? _b : event.target;
69
90
  }
91
+ function withRootHelpers(domUtils) {
92
+ const roots = {
93
+ getRootNode: (ctx) => {
94
+ var _a, _b;
95
+ return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
96
+ },
97
+ getDoc: (ctx) => getDocument(roots.getRootNode(ctx)),
98
+ getWin: (ctx) => {
99
+ var _a;
100
+ return (_a = roots.getDoc(ctx).defaultView) != null ? _a : window;
101
+ }
102
+ };
103
+ return __spreadValues2(__spreadValues2({}, roots), domUtils);
104
+ }
70
105
  function contains(parent, child) {
71
106
  if (!parent)
72
107
  return false;
@@ -193,45 +228,33 @@ var runIfFn2 = (v, ...a) => {
193
228
  };
194
229
 
195
230
  // src/popover.dom.ts
196
- var dom = {
197
- getDoc: (ctx) => {
198
- var _a;
199
- return (_a = ctx.doc) != null ? _a : document;
200
- },
201
- getWin: (ctx) => {
202
- var _a;
203
- return (_a = dom.getDoc(ctx).defaultView) != null ? _a : window;
204
- },
231
+ var dom = withRootHelpers({
205
232
  getActiveEl: (ctx) => dom.getDoc(ctx).activeElement,
206
- getRootNode: (ctx) => {
207
- var _a;
208
- return (_a = ctx.rootNode) != null ? _a : dom.getDoc(ctx);
209
- },
210
233
  getAnchorId: (ctx) => {
211
234
  var _a, _b;
212
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.anchor) != null ? _b : `popover:${ctx.uid}:anchor`;
235
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.anchor) != null ? _b : `popover:${ctx.id}:anchor`;
213
236
  },
214
237
  getTriggerId: (ctx) => {
215
238
  var _a, _b;
216
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.trigger) != null ? _b : `popover:${ctx.uid}:trigger`;
239
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.trigger) != null ? _b : `popover:${ctx.id}:trigger`;
217
240
  },
218
241
  getContentId: (ctx) => {
219
242
  var _a, _b;
220
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.content) != null ? _b : `popover:${ctx.uid}:content`;
243
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.content) != null ? _b : `popover:${ctx.id}:content`;
221
244
  },
222
- getPositionerId: (ctx) => `popover:${ctx.uid}:popper`,
223
- getArrowId: (ctx) => `popover:${ctx.uid}:arrow`,
245
+ getPositionerId: (ctx) => `popover:${ctx.id}:popper`,
246
+ getArrowId: (ctx) => `popover:${ctx.id}:arrow`,
224
247
  getTitleId: (ctx) => {
225
248
  var _a, _b;
226
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.title) != null ? _b : `popover:${ctx.uid}:title`;
249
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.title) != null ? _b : `popover:${ctx.id}:title`;
227
250
  },
228
251
  getDescriptionId: (ctx) => {
229
252
  var _a, _b;
230
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.description) != null ? _b : `popover:${ctx.uid}:desc`;
253
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.description) != null ? _b : `popover:${ctx.id}:desc`;
231
254
  },
232
255
  getCloseButtonId: (ctx) => {
233
256
  var _a, _b;
234
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.closeBtn) != null ? _b : `popover:${ctx.uid}:close-button`;
257
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.closeBtn) != null ? _b : `popover:${ctx.id}:close-button`;
235
258
  },
236
259
  getAnchorEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getAnchorId(ctx)),
237
260
  getTriggerEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getTriggerId(ctx)),
@@ -253,7 +276,7 @@ var dom = {
253
276
  el = dom.getContentEl(ctx);
254
277
  return el;
255
278
  }
256
- };
279
+ });
257
280
 
258
281
  // src/popover.connect.ts
259
282
  function connect(state, send, normalize) {
@@ -358,6 +381,9 @@ function getPlatform() {
358
381
  var pt = (v) => isDom() && v.test(getPlatform());
359
382
  var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
360
383
  var isMac = () => pt(/^Mac/) && !isTouchDevice;
384
+ function isDocument2(el) {
385
+ return el.nodeType === Node.DOCUMENT_NODE;
386
+ }
361
387
  function isWindow2(value) {
362
388
  return (value == null ? void 0 : value.toString()) === "[object Window]";
363
389
  }
@@ -365,6 +391,8 @@ function getDocument2(el) {
365
391
  var _a;
366
392
  if (isWindow2(el))
367
393
  return el.document;
394
+ if (isDocument2(el))
395
+ return el;
368
396
  return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
369
397
  }
370
398
  function getWindow(el) {
@@ -665,12 +693,11 @@ var import_popper2 = require("@zag-js/popper");
665
693
  var import_remove_scroll = require("@zag-js/remove-scroll");
666
694
  var import_focus_trap = require("focus-trap");
667
695
  var { and, or, not } = import_core.guards;
668
- function machine(ctx = {}) {
696
+ function machine(ctx) {
669
697
  return (0, import_core.createMachine)({
670
698
  id: "popover",
671
699
  initial: "unknown",
672
700
  context: __spreadProps(__spreadValues({
673
- uid: "",
674
701
  closeOnInteractOutside: true,
675
702
  closeOnEsc: true,
676
703
  autoFocus: true,
@@ -695,7 +722,7 @@ function machine(ctx = {}) {
695
722
  on: {
696
723
  SETUP: {
697
724
  target: ctx.defaultOpen ? "open" : "closed",
698
- actions: ["setupDocument", "checkRenderedElements"]
725
+ actions: "checkRenderedElements"
699
726
  }
700
727
  }
701
728
  },
@@ -869,13 +896,6 @@ function machine(ctx = {}) {
869
896
  });
870
897
  });
871
898
  },
872
- setupDocument(ctx2, evt) {
873
- if (evt.doc)
874
- ctx2.doc = (0, import_core.ref)(evt.doc);
875
- if (evt.root)
876
- ctx2.rootNode = (0, import_core.ref)(evt.root);
877
- ctx2.uid = evt.id;
878
- },
879
899
  clearPointerDown(ctx2) {
880
900
  ctx2.pointerdownNode = null;
881
901
  },
package/dist/index.mjs CHANGED
@@ -19,6 +19,22 @@ var __spreadValues = (a, b) => {
19
19
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
20
 
21
21
  // ../../utilities/dom/dist/index.mjs
22
+ var __defProp2 = Object.defineProperty;
23
+ var __getOwnPropSymbols2 = Object.getOwnPropertySymbols;
24
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
25
+ var __propIsEnum2 = Object.prototype.propertyIsEnumerable;
26
+ var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
27
+ var __spreadValues2 = (a, b) => {
28
+ for (var prop in b || (b = {}))
29
+ if (__hasOwnProp2.call(b, prop))
30
+ __defNormalProp2(a, prop, b[prop]);
31
+ if (__getOwnPropSymbols2)
32
+ for (var prop of __getOwnPropSymbols2(b)) {
33
+ if (__propIsEnum2.call(b, prop))
34
+ __defNormalProp2(a, prop, b[prop]);
35
+ }
36
+ return a;
37
+ };
22
38
  var dataAttr = (guard) => {
23
39
  return guard ? "" : void 0;
24
40
  };
@@ -27,6 +43,9 @@ var runIfFn = (v, ...a) => {
27
43
  return res != null ? res : void 0;
28
44
  };
29
45
  var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
46
+ function isDocument(el) {
47
+ return el.nodeType === Node.DOCUMENT_NODE;
48
+ }
30
49
  function isWindow(value) {
31
50
  return (value == null ? void 0 : value.toString()) === "[object Window]";
32
51
  }
@@ -37,12 +56,28 @@ function getDocument(el) {
37
56
  var _a;
38
57
  if (isWindow(el))
39
58
  return el.document;
59
+ if (isDocument(el))
60
+ return el;
40
61
  return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
41
62
  }
42
63
  function getEventTarget(event) {
43
64
  var _a, _b;
44
65
  return (_b = (_a = event.composedPath) == null ? void 0 : _a.call(event)[0]) != null ? _b : event.target;
45
66
  }
67
+ function withRootHelpers(domUtils) {
68
+ const roots = {
69
+ getRootNode: (ctx) => {
70
+ var _a, _b;
71
+ return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
72
+ },
73
+ getDoc: (ctx) => getDocument(roots.getRootNode(ctx)),
74
+ getWin: (ctx) => {
75
+ var _a;
76
+ return (_a = roots.getDoc(ctx).defaultView) != null ? _a : window;
77
+ }
78
+ };
79
+ return __spreadValues2(__spreadValues2({}, roots), domUtils);
80
+ }
46
81
  function contains(parent, child) {
47
82
  if (!parent)
48
83
  return false;
@@ -169,45 +204,33 @@ var runIfFn2 = (v, ...a) => {
169
204
  };
170
205
 
171
206
  // src/popover.dom.ts
172
- var dom = {
173
- getDoc: (ctx) => {
174
- var _a;
175
- return (_a = ctx.doc) != null ? _a : document;
176
- },
177
- getWin: (ctx) => {
178
- var _a;
179
- return (_a = dom.getDoc(ctx).defaultView) != null ? _a : window;
180
- },
207
+ var dom = withRootHelpers({
181
208
  getActiveEl: (ctx) => dom.getDoc(ctx).activeElement,
182
- getRootNode: (ctx) => {
183
- var _a;
184
- return (_a = ctx.rootNode) != null ? _a : dom.getDoc(ctx);
185
- },
186
209
  getAnchorId: (ctx) => {
187
210
  var _a, _b;
188
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.anchor) != null ? _b : `popover:${ctx.uid}:anchor`;
211
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.anchor) != null ? _b : `popover:${ctx.id}:anchor`;
189
212
  },
190
213
  getTriggerId: (ctx) => {
191
214
  var _a, _b;
192
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.trigger) != null ? _b : `popover:${ctx.uid}:trigger`;
215
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.trigger) != null ? _b : `popover:${ctx.id}:trigger`;
193
216
  },
194
217
  getContentId: (ctx) => {
195
218
  var _a, _b;
196
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.content) != null ? _b : `popover:${ctx.uid}:content`;
219
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.content) != null ? _b : `popover:${ctx.id}:content`;
197
220
  },
198
- getPositionerId: (ctx) => `popover:${ctx.uid}:popper`,
199
- getArrowId: (ctx) => `popover:${ctx.uid}:arrow`,
221
+ getPositionerId: (ctx) => `popover:${ctx.id}:popper`,
222
+ getArrowId: (ctx) => `popover:${ctx.id}:arrow`,
200
223
  getTitleId: (ctx) => {
201
224
  var _a, _b;
202
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.title) != null ? _b : `popover:${ctx.uid}:title`;
225
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.title) != null ? _b : `popover:${ctx.id}:title`;
203
226
  },
204
227
  getDescriptionId: (ctx) => {
205
228
  var _a, _b;
206
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.description) != null ? _b : `popover:${ctx.uid}:desc`;
229
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.description) != null ? _b : `popover:${ctx.id}:desc`;
207
230
  },
208
231
  getCloseButtonId: (ctx) => {
209
232
  var _a, _b;
210
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.closeBtn) != null ? _b : `popover:${ctx.uid}:close-button`;
233
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.closeBtn) != null ? _b : `popover:${ctx.id}:close-button`;
211
234
  },
212
235
  getAnchorEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getAnchorId(ctx)),
213
236
  getTriggerEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getTriggerId(ctx)),
@@ -229,7 +252,7 @@ var dom = {
229
252
  el = dom.getContentEl(ctx);
230
253
  return el;
231
254
  }
232
- };
255
+ });
233
256
 
234
257
  // src/popover.connect.ts
235
258
  function connect(state, send, normalize) {
@@ -317,7 +340,7 @@ function connect(state, send, normalize) {
317
340
 
318
341
  // src/popover.machine.ts
319
342
  import { ariaHidden } from "@zag-js/aria-hidden";
320
- import { createMachine, guards, ref } from "@zag-js/core";
343
+ import { createMachine, guards } from "@zag-js/core";
321
344
 
322
345
  // ../../utilities/interact-outside/dist/index.mjs
323
346
  var runIfFn3 = (v, ...a) => {
@@ -334,6 +357,9 @@ function getPlatform() {
334
357
  var pt = (v) => isDom() && v.test(getPlatform());
335
358
  var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
336
359
  var isMac = () => pt(/^Mac/) && !isTouchDevice;
360
+ function isDocument2(el) {
361
+ return el.nodeType === Node.DOCUMENT_NODE;
362
+ }
337
363
  function isWindow2(value) {
338
364
  return (value == null ? void 0 : value.toString()) === "[object Window]";
339
365
  }
@@ -341,6 +367,8 @@ function getDocument2(el) {
341
367
  var _a;
342
368
  if (isWindow2(el))
343
369
  return el.document;
370
+ if (isDocument2(el))
371
+ return el;
344
372
  return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
345
373
  }
346
374
  function getWindow(el) {
@@ -641,12 +669,11 @@ import { getPlacement } from "@zag-js/popper";
641
669
  import { preventBodyScroll } from "@zag-js/remove-scroll";
642
670
  import { createFocusTrap } from "focus-trap";
643
671
  var { and, or, not } = guards;
644
- function machine(ctx = {}) {
672
+ function machine(ctx) {
645
673
  return createMachine({
646
674
  id: "popover",
647
675
  initial: "unknown",
648
676
  context: __spreadProps(__spreadValues({
649
- uid: "",
650
677
  closeOnInteractOutside: true,
651
678
  closeOnEsc: true,
652
679
  autoFocus: true,
@@ -671,7 +698,7 @@ function machine(ctx = {}) {
671
698
  on: {
672
699
  SETUP: {
673
700
  target: ctx.defaultOpen ? "open" : "closed",
674
- actions: ["setupDocument", "checkRenderedElements"]
701
+ actions: "checkRenderedElements"
675
702
  }
676
703
  }
677
704
  },
@@ -845,13 +872,6 @@ function machine(ctx = {}) {
845
872
  });
846
873
  });
847
874
  },
848
- setupDocument(ctx2, evt) {
849
- if (evt.doc)
850
- ctx2.doc = ref(evt.doc);
851
- if (evt.root)
852
- ctx2.rootNode = ref(evt.root);
853
- ctx2.uid = evt.id;
854
- },
855
875
  clearPointerDown(ctx2) {
856
876
  ctx2.pointerdownNode = null;
857
877
  },
@@ -1,9 +1,16 @@
1
1
  import type { MachineContext as Ctx } from "./popover.types";
2
2
  export declare const dom: {
3
- getDoc: (ctx: Ctx) => Document;
4
- getWin: (ctx: Ctx) => Window & typeof globalThis;
3
+ getRootNode: (ctx: {
4
+ getRootNode?: () => Document | Node | ShadowRoot;
5
+ }) => Document | ShadowRoot;
6
+ getDoc: (ctx: {
7
+ getRootNode?: () => Document | Node | ShadowRoot;
8
+ }) => Document;
9
+ getWin: (ctx: {
10
+ getRootNode?: () => Document | Node | ShadowRoot;
11
+ }) => Window & typeof globalThis;
12
+ } & {
5
13
  getActiveEl: (ctx: Ctx) => Element;
6
- getRootNode: (ctx: Ctx) => Document | ShadowRoot;
7
14
  getAnchorId: (ctx: Ctx) => string;
8
15
  getTriggerId: (ctx: Ctx) => string;
9
16
  getContentId: (ctx: Ctx) => string;
@@ -1,2 +1,2 @@
1
1
  import type { MachineContext, MachineState, UserDefinedContext } from "./popover.types";
2
- export declare function machine(ctx?: UserDefinedContext): import("@zag-js/core").Machine<MachineContext, MachineState, import("@zag-js/core").StateMachine.AnyEventObject>;
2
+ export declare function machine(ctx: UserDefinedContext): import("@zag-js/core").Machine<MachineContext, MachineState, import("@zag-js/core").StateMachine.AnyEventObject>;
@@ -1,7 +1,7 @@
1
1
  import type { StateMachine as S } from "@zag-js/core";
2
2
  import type { DismissableElementHandlers } from "@zag-js/dimissable";
3
3
  import type { PositioningOptions, Placement } from "@zag-js/popper";
4
- import type { Context, MaybeElement } from "@zag-js/types";
4
+ import type { CommonProperties, Context, MaybeElement, RequiredBy } from "@zag-js/types";
5
5
  declare type ElementIds = Partial<{
6
6
  anchor: string;
7
7
  trigger: string;
@@ -10,7 +10,7 @@ declare type ElementIds = Partial<{
10
10
  description: string;
11
11
  closeBtn: string;
12
12
  }>;
13
- declare type PublicContext = DismissableElementHandlers & {
13
+ declare type PublicContext = DismissableElementHandlers & CommonProperties & {
14
14
  /**
15
15
  * The ids of the elements in the popover. Useful for composition.
16
16
  */
@@ -59,7 +59,7 @@ declare type PublicContext = DismissableElementHandlers & {
59
59
  */
60
60
  defaultOpen?: boolean;
61
61
  };
62
- export declare type UserDefinedContext = Partial<PublicContext>;
62
+ export declare type UserDefinedContext = RequiredBy<PublicContext, "id">;
63
63
  declare type ComputedContext = Readonly<{
64
64
  /**
65
65
  * @computed
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/popover",
3
- "version": "0.0.0-dev-20220707125149",
3
+ "version": "0.0.0-dev-20220709094318",
4
4
  "description": "Core logic for the popover widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -30,11 +30,11 @@
30
30
  },
31
31
  "dependencies": {
32
32
  "@zag-js/aria-hidden": "0.1.0",
33
- "@zag-js/core": "0.0.0-dev-20220707125149",
34
- "@zag-js/dom-utils": "0.0.0-dev-20220707125149",
35
- "@zag-js/popper": "0.0.0-dev-20220707125149",
36
- "@zag-js/remove-scroll": "0.0.0-dev-20220707125149",
37
- "@zag-js/types": "0.0.0-dev-20220707125149",
33
+ "@zag-js/core": "0.1.7",
34
+ "@zag-js/dom-utils": "0.0.0-dev-20220709094318",
35
+ "@zag-js/popper": "0.0.0-dev-20220709094318",
36
+ "@zag-js/remove-scroll": "0.0.0-dev-20220709094318",
37
+ "@zag-js/types": "0.0.0-dev-20220709094318",
38
38
  "@zag-js/utils": "0.1.2",
39
39
  "focus-trap": "6.9.4"
40
40
  },