@zag-js/tooltip 0.0.0-dev-20220706194607 → 0.0.0-dev-20220709094240

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
  };
@@ -81,6 +97,9 @@ var pt = (v) => isDom() && v.test(getPlatform());
81
97
  var vn = (v) => isDom() && v.test(navigator.vendor);
82
98
  var isSafari = () => isApple() && vn(/apple/i);
83
99
  var isApple = () => pt(/mac|iphone|ipad|ipod/i);
100
+ function isDocument(el) {
101
+ return el.nodeType === Node.DOCUMENT_NODE;
102
+ }
84
103
  function isWindow(value) {
85
104
  return (value == null ? void 0 : value.toString()) === "[object Window]";
86
105
  }
@@ -88,6 +107,8 @@ function getDocument(el) {
88
107
  var _a;
89
108
  if (isWindow(el))
90
109
  return el.document;
110
+ if (isDocument(el))
111
+ return el;
91
112
  return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
92
113
  }
93
114
  function getWindow(el) {
@@ -104,6 +125,20 @@ function getParent(el) {
104
125
  return el;
105
126
  return el.assignedSlot || el.parentElement || doc.documentElement;
106
127
  }
128
+ function withRootHelpers(domUtils) {
129
+ const roots = {
130
+ getRootNode: (ctx) => {
131
+ var _a, _b;
132
+ return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
133
+ },
134
+ getDoc: (ctx) => getDocument(roots.getRootNode(ctx)),
135
+ getWin: (ctx) => {
136
+ var _a;
137
+ return (_a = roots.getDoc(ctx).defaultView) != null ? _a : window;
138
+ }
139
+ };
140
+ return __spreadValues2(__spreadValues2({}, roots), domUtils);
141
+ }
107
142
  function isHTMLElement(v) {
108
143
  return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string";
109
144
  }
@@ -224,19 +259,7 @@ function getScrollParents(el, list = []) {
224
259
  var import_popper = require("@zag-js/popper");
225
260
 
226
261
  // src/tooltip.dom.ts
227
- var dom = {
228
- getDoc: (ctx) => {
229
- var _a;
230
- return (_a = ctx.doc) != null ? _a : document;
231
- },
232
- getWin: (ctx) => {
233
- var _a, _b;
234
- return (_b = (_a = ctx.doc) == null ? void 0 : _a.defaultView) != null ? _b : window;
235
- },
236
- getRootNode: (ctx) => {
237
- var _a;
238
- return (_a = ctx.rootNode) != null ? _a : dom.getDoc(ctx);
239
- },
262
+ var dom = withRootHelpers({
240
263
  getTriggerId: (ctx) => {
241
264
  var _a, _b;
242
265
  return (_b = (_a = ctx.ids) == null ? void 0 : _a.trigger) != null ? _b : `tooltip:${ctx.id}:trigger`;
@@ -259,7 +282,7 @@ var dom = {
259
282
  portal.id = dom.portalId;
260
283
  return portal;
261
284
  }
262
- };
285
+ });
263
286
 
264
287
  // src/tooltip.store.ts
265
288
  var import_core = require("@zag-js/core");
@@ -385,12 +408,11 @@ var noop = () => {
385
408
  };
386
409
 
387
410
  // src/tooltip.machine.ts
388
- function machine(ctx = {}) {
411
+ function machine(ctx) {
389
412
  return (0, import_core2.createMachine)({
390
413
  id: "tooltip",
391
414
  initial: "unknown",
392
415
  context: __spreadProps(__spreadValues({
393
- id: "",
394
416
  openDelay: 1e3,
395
417
  closeDelay: 500,
396
418
  closeOnPointerDown: true,
@@ -412,10 +434,7 @@ function machine(ctx = {}) {
412
434
  states: {
413
435
  unknown: {
414
436
  on: {
415
- SETUP: {
416
- target: "closed",
417
- actions: "setupDocument"
418
- }
437
+ SETUP: "closed"
419
438
  }
420
439
  },
421
440
  closed: {
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
  };
@@ -57,6 +73,9 @@ var pt = (v) => isDom() && v.test(getPlatform());
57
73
  var vn = (v) => isDom() && v.test(navigator.vendor);
58
74
  var isSafari = () => isApple() && vn(/apple/i);
59
75
  var isApple = () => pt(/mac|iphone|ipad|ipod/i);
76
+ function isDocument(el) {
77
+ return el.nodeType === Node.DOCUMENT_NODE;
78
+ }
60
79
  function isWindow(value) {
61
80
  return (value == null ? void 0 : value.toString()) === "[object Window]";
62
81
  }
@@ -64,6 +83,8 @@ function getDocument(el) {
64
83
  var _a;
65
84
  if (isWindow(el))
66
85
  return el.document;
86
+ if (isDocument(el))
87
+ return el;
67
88
  return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
68
89
  }
69
90
  function getWindow(el) {
@@ -80,6 +101,20 @@ function getParent(el) {
80
101
  return el;
81
102
  return el.assignedSlot || el.parentElement || doc.documentElement;
82
103
  }
104
+ function withRootHelpers(domUtils) {
105
+ const roots = {
106
+ getRootNode: (ctx) => {
107
+ var _a, _b;
108
+ return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
109
+ },
110
+ getDoc: (ctx) => getDocument(roots.getRootNode(ctx)),
111
+ getWin: (ctx) => {
112
+ var _a;
113
+ return (_a = roots.getDoc(ctx).defaultView) != null ? _a : window;
114
+ }
115
+ };
116
+ return __spreadValues2(__spreadValues2({}, roots), domUtils);
117
+ }
83
118
  function isHTMLElement(v) {
84
119
  return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string";
85
120
  }
@@ -200,19 +235,7 @@ function getScrollParents(el, list = []) {
200
235
  import { getPlacementStyles } from "@zag-js/popper";
201
236
 
202
237
  // src/tooltip.dom.ts
203
- var dom = {
204
- getDoc: (ctx) => {
205
- var _a;
206
- return (_a = ctx.doc) != null ? _a : document;
207
- },
208
- getWin: (ctx) => {
209
- var _a, _b;
210
- return (_b = (_a = ctx.doc) == null ? void 0 : _a.defaultView) != null ? _b : window;
211
- },
212
- getRootNode: (ctx) => {
213
- var _a;
214
- return (_a = ctx.rootNode) != null ? _a : dom.getDoc(ctx);
215
- },
238
+ var dom = withRootHelpers({
216
239
  getTriggerId: (ctx) => {
217
240
  var _a, _b;
218
241
  return (_b = (_a = ctx.ids) == null ? void 0 : _a.trigger) != null ? _b : `tooltip:${ctx.id}:trigger`;
@@ -235,7 +258,7 @@ var dom = {
235
258
  portal.id = dom.portalId;
236
259
  return portal;
237
260
  }
238
- };
261
+ });
239
262
 
240
263
  // src/tooltip.store.ts
241
264
  import { proxy } from "@zag-js/core";
@@ -361,12 +384,11 @@ var noop = () => {
361
384
  };
362
385
 
363
386
  // src/tooltip.machine.ts
364
- function machine(ctx = {}) {
387
+ function machine(ctx) {
365
388
  return createMachine({
366
389
  id: "tooltip",
367
390
  initial: "unknown",
368
391
  context: __spreadProps(__spreadValues({
369
- id: "",
370
392
  openDelay: 1e3,
371
393
  closeDelay: 500,
372
394
  closeOnPointerDown: true,
@@ -388,10 +410,7 @@ function machine(ctx = {}) {
388
410
  states: {
389
411
  unknown: {
390
412
  on: {
391
- SETUP: {
392
- target: "closed",
393
- actions: "setupDocument"
394
- }
413
+ SETUP: "closed"
395
414
  }
396
415
  },
397
416
  closed: {
@@ -1,8 +1,15 @@
1
1
  import type { MachineContext as Ctx } from "./tooltip.types";
2
2
  export declare const dom: {
3
- getDoc: (ctx: Ctx) => Document;
4
- getWin: (ctx: Ctx) => Window & typeof globalThis;
5
- getRootNode: (ctx: Ctx) => Document | ShadowRoot;
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
+ } & {
6
13
  getTriggerId: (ctx: Ctx) => string;
7
14
  getContentId: (ctx: Ctx) => string;
8
15
  getArrowId: (ctx: Ctx) => string;
@@ -1,2 +1,2 @@
1
1
  import type { MachineContext, MachineState, UserDefinedContext } from "./tooltip.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,11 +1,11 @@
1
1
  import type { StateMachine as S } from "@zag-js/core";
2
2
  import type { Placement, PositioningOptions } from "@zag-js/popper";
3
- import type { RootProperties } from "@zag-js/types";
3
+ import type { CommonProperties, RequiredBy, RootProperties } from "@zag-js/types";
4
4
  declare type ElementIds = Partial<{
5
5
  trigger: string;
6
6
  content: string;
7
7
  }>;
8
- declare type PublicContext = {
8
+ declare type PublicContext = CommonProperties & {
9
9
  /**
10
10
  * The ids of the elements in the tooltip. Useful for composition.
11
11
  */
@@ -53,7 +53,7 @@ declare type PublicContext = {
53
53
  */
54
54
  positioning: PositioningOptions;
55
55
  };
56
- export declare type UserDefinedContext = Partial<PublicContext>;
56
+ export declare type UserDefinedContext = RequiredBy<PublicContext, "id">;
57
57
  declare type ComputedContext = Readonly<{
58
58
  /**
59
59
  * @computed Whether an `aria-label` is set.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/tooltip",
3
- "version": "0.0.0-dev-20220706194607",
3
+ "version": "0.0.0-dev-20220709094240",
4
4
  "description": "Core logic for the tooltip widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -29,10 +29,10 @@
29
29
  "url": "https://github.com/chakra-ui/zag/issues"
30
30
  },
31
31
  "dependencies": {
32
- "@zag-js/core": "0.0.0-dev-20220706194607",
33
- "@zag-js/dom-utils": "0.0.0-dev-20220706194607",
34
- "@zag-js/popper": "0.0.0-dev-20220706194607",
35
- "@zag-js/types": "0.0.0-dev-20220706194607"
32
+ "@zag-js/core": "0.1.7",
33
+ "@zag-js/dom-utils": "0.0.0-dev-20220709094240",
34
+ "@zag-js/popper": "0.0.0-dev-20220709094240",
35
+ "@zag-js/types": "0.0.0-dev-20220709094240"
36
36
  },
37
37
  "scripts": {
38
38
  "build:fast": "zag build",