@zag-js/tabs 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
@@ -40,6 +40,22 @@ __export(src_exports, {
40
40
  module.exports = __toCommonJS(src_exports);
41
41
 
42
42
  // ../../utilities/dom/dist/index.mjs
43
+ var __defProp2 = Object.defineProperty;
44
+ var __getOwnPropSymbols2 = Object.getOwnPropertySymbols;
45
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
46
+ var __propIsEnum2 = Object.prototype.propertyIsEnumerable;
47
+ var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
48
+ var __spreadValues2 = (a, b) => {
49
+ for (var prop in b || (b = {}))
50
+ if (__hasOwnProp2.call(b, prop))
51
+ __defNormalProp2(a, prop, b[prop]);
52
+ if (__getOwnPropSymbols2)
53
+ for (var prop of __getOwnPropSymbols2(b)) {
54
+ if (__propIsEnum2.call(b, prop))
55
+ __defNormalProp2(a, prop, b[prop]);
56
+ }
57
+ return a;
58
+ };
43
59
  var dataAttr = (guard) => {
44
60
  return guard ? "" : void 0;
45
61
  };
@@ -53,9 +69,37 @@ var pt = (v) => isDom() && v.test(getPlatform());
53
69
  var vn = (v) => isDom() && v.test(navigator.vendor);
54
70
  var isSafari = () => isApple() && vn(/apple/i);
55
71
  var isApple = () => pt(/mac|iphone|ipad|ipod/i);
72
+ function isDocument(el) {
73
+ return el.nodeType === Node.DOCUMENT_NODE;
74
+ }
75
+ function isWindow(value) {
76
+ return (value == null ? void 0 : value.toString()) === "[object Window]";
77
+ }
56
78
  function isFrame(element) {
57
79
  return element.localName === "iframe";
58
80
  }
81
+ function getDocument(el) {
82
+ var _a;
83
+ if (isWindow(el))
84
+ return el.document;
85
+ if (isDocument(el))
86
+ return el;
87
+ return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
88
+ }
89
+ function withRootHelpers(domUtils) {
90
+ const roots = {
91
+ getRootNode: (ctx) => {
92
+ var _a, _b;
93
+ return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
94
+ },
95
+ getDoc: (ctx) => getDocument(roots.getRootNode(ctx)),
96
+ getWin: (ctx) => {
97
+ var _a;
98
+ return (_a = roots.getDoc(ctx).defaultView) != null ? _a : window;
99
+ }
100
+ };
101
+ return __spreadValues2(__spreadValues2({}, roots), domUtils);
102
+ }
59
103
  function isHTMLElement(v) {
60
104
  return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string";
61
105
  }
@@ -161,36 +205,28 @@ var first = (v) => v[0];
161
205
  var last = (v) => v[v.length - 1];
162
206
 
163
207
  // src/tabs.dom.ts
164
- var dom = {
165
- getDoc: (ctx) => {
166
- var _a;
167
- return (_a = ctx.doc) != null ? _a : document;
168
- },
169
- getRootNode: (ctx) => {
170
- var _a;
171
- return (_a = ctx.rootNode) != null ? _a : dom.getDoc(ctx);
172
- },
208
+ var dom = withRootHelpers({
173
209
  getRootId: (ctx) => {
174
210
  var _a, _b;
175
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `tabs:${ctx.uid}`;
211
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `tabs:${ctx.id}`;
176
212
  },
177
213
  getTriggerGroupId: (ctx) => {
178
214
  var _a, _b;
179
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.triggerGroup) != null ? _b : `tabs:${ctx.uid}:trigger-group`;
215
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.triggerGroup) != null ? _b : `tabs:${ctx.id}:trigger-group`;
180
216
  },
181
217
  getContentId: (ctx, id) => {
182
218
  var _a, _b;
183
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.content) != null ? _b : `tabs:${ctx.uid}:content-${id}`;
219
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.content) != null ? _b : `tabs:${ctx.id}:content-${id}`;
184
220
  },
185
221
  getContentGroupId: (ctx) => {
186
222
  var _a, _b;
187
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.contentGroup) != null ? _b : `tabs:${ctx.uid}:content-group`;
223
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.contentGroup) != null ? _b : `tabs:${ctx.id}:content-group`;
188
224
  },
189
225
  getTriggerId: (ctx, id) => {
190
226
  var _a, _b;
191
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.trigger) != null ? _b : `tabs:${ctx.uid}:trigger-${id}`;
227
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.trigger) != null ? _b : `tabs:${ctx.id}:trigger-${id}`;
192
228
  },
193
- getIndicatorId: (ctx) => `tabs:${ctx.uid}:indicator`,
229
+ getIndicatorId: (ctx) => `tabs:${ctx.id}:indicator`,
194
230
  getTriggerGroupEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getTriggerGroupId(ctx)),
195
231
  getContentEl: (ctx, id) => dom.getRootNode(ctx).getElementById(dom.getContentId(ctx, id)),
196
232
  getTriggerEl: (ctx, id) => dom.getRootNode(ctx).getElementById(dom.getTriggerId(ctx, id)),
@@ -230,7 +266,7 @@ var dom = {
230
266
  width: `${tab.offsetWidth}px`
231
267
  };
232
268
  }
233
- };
269
+ });
234
270
 
235
271
  // src/tabs.connect.ts
236
272
  function connect(state, send, normalize) {
@@ -377,7 +413,7 @@ function connect(state, send, normalize) {
377
413
  // src/tabs.machine.ts
378
414
  var import_core = require("@zag-js/core");
379
415
  var { not } = import_core.guards;
380
- function machine(ctx = {}) {
416
+ function machine(ctx) {
381
417
  return (0, import_core.createMachine)({
382
418
  initial: "unknown",
383
419
  context: __spreadValues({
@@ -386,7 +422,6 @@ function machine(ctx = {}) {
386
422
  activationMode: "automatic",
387
423
  value: null,
388
424
  focusedValue: null,
389
- uid: "",
390
425
  previousValues: [],
391
426
  indicatorRect: { left: "0px", top: "0px", width: "0px", height: "0px" },
392
427
  hasMeasuredRect: false,
@@ -417,7 +452,7 @@ function machine(ctx = {}) {
417
452
  on: {
418
453
  SETUP: {
419
454
  target: "idle",
420
- actions: ["setupDocument", "checkRenderedElements", "setIndicatorRect", "setContentTabIndex"]
455
+ actions: ["checkRenderedElements", "setIndicatorRect", "setContentTabIndex"]
421
456
  }
422
457
  }
423
458
  },
@@ -487,13 +522,6 @@ function machine(ctx = {}) {
487
522
  selectOnFocus: (ctx2) => ctx2.activationMode === "automatic"
488
523
  },
489
524
  actions: {
490
- setupDocument(ctx2, evt) {
491
- ctx2.uid = evt.id;
492
- if (evt.doc)
493
- ctx2.doc = (0, import_core.ref)(evt.doc);
494
- if (evt.root)
495
- ctx2.rootNode = (0, import_core.ref)(evt.root);
496
- },
497
525
  setFocusedValue(ctx2, evt) {
498
526
  ctx2.focusedValue = evt.value;
499
527
  },
package/dist/index.mjs CHANGED
@@ -16,6 +16,22 @@ var __spreadValues = (a, b) => {
16
16
  };
17
17
 
18
18
  // ../../utilities/dom/dist/index.mjs
19
+ var __defProp2 = Object.defineProperty;
20
+ var __getOwnPropSymbols2 = Object.getOwnPropertySymbols;
21
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
22
+ var __propIsEnum2 = Object.prototype.propertyIsEnumerable;
23
+ var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
24
+ var __spreadValues2 = (a, b) => {
25
+ for (var prop in b || (b = {}))
26
+ if (__hasOwnProp2.call(b, prop))
27
+ __defNormalProp2(a, prop, b[prop]);
28
+ if (__getOwnPropSymbols2)
29
+ for (var prop of __getOwnPropSymbols2(b)) {
30
+ if (__propIsEnum2.call(b, prop))
31
+ __defNormalProp2(a, prop, b[prop]);
32
+ }
33
+ return a;
34
+ };
19
35
  var dataAttr = (guard) => {
20
36
  return guard ? "" : void 0;
21
37
  };
@@ -29,9 +45,37 @@ var pt = (v) => isDom() && v.test(getPlatform());
29
45
  var vn = (v) => isDom() && v.test(navigator.vendor);
30
46
  var isSafari = () => isApple() && vn(/apple/i);
31
47
  var isApple = () => pt(/mac|iphone|ipad|ipod/i);
48
+ function isDocument(el) {
49
+ return el.nodeType === Node.DOCUMENT_NODE;
50
+ }
51
+ function isWindow(value) {
52
+ return (value == null ? void 0 : value.toString()) === "[object Window]";
53
+ }
32
54
  function isFrame(element) {
33
55
  return element.localName === "iframe";
34
56
  }
57
+ function getDocument(el) {
58
+ var _a;
59
+ if (isWindow(el))
60
+ return el.document;
61
+ if (isDocument(el))
62
+ return el;
63
+ return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
64
+ }
65
+ function withRootHelpers(domUtils) {
66
+ const roots = {
67
+ getRootNode: (ctx) => {
68
+ var _a, _b;
69
+ return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
70
+ },
71
+ getDoc: (ctx) => getDocument(roots.getRootNode(ctx)),
72
+ getWin: (ctx) => {
73
+ var _a;
74
+ return (_a = roots.getDoc(ctx).defaultView) != null ? _a : window;
75
+ }
76
+ };
77
+ return __spreadValues2(__spreadValues2({}, roots), domUtils);
78
+ }
35
79
  function isHTMLElement(v) {
36
80
  return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string";
37
81
  }
@@ -137,36 +181,28 @@ var first = (v) => v[0];
137
181
  var last = (v) => v[v.length - 1];
138
182
 
139
183
  // src/tabs.dom.ts
140
- var dom = {
141
- getDoc: (ctx) => {
142
- var _a;
143
- return (_a = ctx.doc) != null ? _a : document;
144
- },
145
- getRootNode: (ctx) => {
146
- var _a;
147
- return (_a = ctx.rootNode) != null ? _a : dom.getDoc(ctx);
148
- },
184
+ var dom = withRootHelpers({
149
185
  getRootId: (ctx) => {
150
186
  var _a, _b;
151
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `tabs:${ctx.uid}`;
187
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `tabs:${ctx.id}`;
152
188
  },
153
189
  getTriggerGroupId: (ctx) => {
154
190
  var _a, _b;
155
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.triggerGroup) != null ? _b : `tabs:${ctx.uid}:trigger-group`;
191
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.triggerGroup) != null ? _b : `tabs:${ctx.id}:trigger-group`;
156
192
  },
157
193
  getContentId: (ctx, id) => {
158
194
  var _a, _b;
159
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.content) != null ? _b : `tabs:${ctx.uid}:content-${id}`;
195
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.content) != null ? _b : `tabs:${ctx.id}:content-${id}`;
160
196
  },
161
197
  getContentGroupId: (ctx) => {
162
198
  var _a, _b;
163
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.contentGroup) != null ? _b : `tabs:${ctx.uid}:content-group`;
199
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.contentGroup) != null ? _b : `tabs:${ctx.id}:content-group`;
164
200
  },
165
201
  getTriggerId: (ctx, id) => {
166
202
  var _a, _b;
167
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.trigger) != null ? _b : `tabs:${ctx.uid}:trigger-${id}`;
203
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.trigger) != null ? _b : `tabs:${ctx.id}:trigger-${id}`;
168
204
  },
169
- getIndicatorId: (ctx) => `tabs:${ctx.uid}:indicator`,
205
+ getIndicatorId: (ctx) => `tabs:${ctx.id}:indicator`,
170
206
  getTriggerGroupEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getTriggerGroupId(ctx)),
171
207
  getContentEl: (ctx, id) => dom.getRootNode(ctx).getElementById(dom.getContentId(ctx, id)),
172
208
  getTriggerEl: (ctx, id) => dom.getRootNode(ctx).getElementById(dom.getTriggerId(ctx, id)),
@@ -206,7 +242,7 @@ var dom = {
206
242
  width: `${tab.offsetWidth}px`
207
243
  };
208
244
  }
209
- };
245
+ });
210
246
 
211
247
  // src/tabs.connect.ts
212
248
  function connect(state, send, normalize) {
@@ -351,9 +387,9 @@ function connect(state, send, normalize) {
351
387
  }
352
388
 
353
389
  // src/tabs.machine.ts
354
- import { createMachine, guards, ref } from "@zag-js/core";
390
+ import { createMachine, guards } from "@zag-js/core";
355
391
  var { not } = guards;
356
- function machine(ctx = {}) {
392
+ function machine(ctx) {
357
393
  return createMachine({
358
394
  initial: "unknown",
359
395
  context: __spreadValues({
@@ -362,7 +398,6 @@ function machine(ctx = {}) {
362
398
  activationMode: "automatic",
363
399
  value: null,
364
400
  focusedValue: null,
365
- uid: "",
366
401
  previousValues: [],
367
402
  indicatorRect: { left: "0px", top: "0px", width: "0px", height: "0px" },
368
403
  hasMeasuredRect: false,
@@ -393,7 +428,7 @@ function machine(ctx = {}) {
393
428
  on: {
394
429
  SETUP: {
395
430
  target: "idle",
396
- actions: ["setupDocument", "checkRenderedElements", "setIndicatorRect", "setContentTabIndex"]
431
+ actions: ["checkRenderedElements", "setIndicatorRect", "setContentTabIndex"]
397
432
  }
398
433
  }
399
434
  },
@@ -463,13 +498,6 @@ function machine(ctx = {}) {
463
498
  selectOnFocus: (ctx2) => ctx2.activationMode === "automatic"
464
499
  },
465
500
  actions: {
466
- setupDocument(ctx2, evt) {
467
- ctx2.uid = evt.id;
468
- if (evt.doc)
469
- ctx2.doc = ref(evt.doc);
470
- if (evt.root)
471
- ctx2.rootNode = ref(evt.root);
472
- },
473
501
  setFocusedValue(ctx2, evt) {
474
502
  ctx2.focusedValue = evt.value;
475
503
  },
@@ -1,7 +1,15 @@
1
1
  import type { MachineContext as Ctx } from "./tabs.types";
2
2
  export declare const dom: {
3
- getDoc: (ctx: Ctx) => Document;
4
- getRootNode: (ctx: Ctx) => Document | ShadowRoot;
3
+ getRootNode: (ctx: {
4
+ getRootNode?: () => Node | Document | ShadowRoot;
5
+ }) => Document | ShadowRoot;
6
+ getDoc: (ctx: {
7
+ getRootNode?: () => Node | Document | ShadowRoot;
8
+ }) => Document;
9
+ getWin: (ctx: {
10
+ getRootNode?: () => Node | Document | ShadowRoot;
11
+ }) => Window & typeof globalThis;
12
+ } & {
5
13
  getRootId: (ctx: Ctx) => string;
6
14
  getTriggerGroupId: (ctx: Ctx) => string;
7
15
  getContentId: (ctx: Ctx, id: string) => string;
@@ -1,2 +1,2 @@
1
1
  import type { MachineContext, MachineState, UserDefinedContext } from "./tabs.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,5 +1,5 @@
1
1
  import type { StateMachine as S } from "@zag-js/core";
2
- import type { Context, DirectionProperty } from "@zag-js/types";
2
+ import type { CommonProperties, Context, DirectionProperty, RequiredBy } from "@zag-js/types";
3
3
  declare type IntlMessages = {
4
4
  tablistLabel?: string;
5
5
  deleteLabel?(value: string): string;
@@ -11,7 +11,7 @@ declare type ElementIds = Partial<{
11
11
  contentGroup: string;
12
12
  content: string;
13
13
  }>;
14
- declare type PublicContext = DirectionProperty & {
14
+ declare type PublicContext = DirectionProperty & CommonProperties & {
15
15
  /**
16
16
  * The ids of the elements in the tabs. Useful for composition.
17
17
  */
@@ -67,7 +67,7 @@ declare type PublicContext = DirectionProperty & {
67
67
  value: string;
68
68
  }) => void;
69
69
  };
70
- export declare type UserDefinedContext = Partial<PublicContext>;
70
+ export declare type UserDefinedContext = RequiredBy<PublicContext, "id">;
71
71
  declare type ComputedContext = Readonly<{
72
72
  /**
73
73
  * @computed
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/tabs",
3
- "version": "0.0.0-dev-20220706194607",
3
+ "version": "0.0.0-dev-20220709094240",
4
4
  "description": "Core logic for the tabs widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -29,9 +29,9 @@
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/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/types": "0.0.0-dev-20220709094240",
35
35
  "@zag-js/utils": "0.1.2"
36
36
  },
37
37
  "scripts": {