@zag-js/tabs 0.2.1 → 0.2.2

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.d.ts CHANGED
@@ -99,6 +99,7 @@ declare function connect<T extends PropTypes>(state: State, send: Send, normaliz
99
99
  focusedValue: string | null;
100
100
  previousValues: string[];
101
101
  setValue(value: string): void;
102
+ clearValue(): void;
102
103
  rootProps: T["element"];
103
104
  triggerGroupProps: T["element"];
104
105
  getTriggerProps(props: TabProps): T["button"];
package/dist/index.js CHANGED
@@ -279,6 +279,9 @@ function connect(state, send, normalize) {
279
279
  setValue(value) {
280
280
  send({ type: "SET_VALUE", value });
281
281
  },
282
+ clearValue() {
283
+ send({ type: "CLEAR_VALUE" });
284
+ },
282
285
  rootProps: normalize.element({
283
286
  "data-part": "root",
284
287
  id: dom.getRootId(state.context),
@@ -447,8 +450,8 @@ function machine(userContext) {
447
450
  SET_VALUE: {
448
451
  actions: "setValue"
449
452
  },
450
- DELETE: {
451
- actions: "deleteValue"
453
+ CLEAR_VALUE: {
454
+ actions: "clearValue"
452
455
  }
453
456
  },
454
457
  states: {
@@ -536,6 +539,9 @@ function machine(userContext) {
536
539
  setValue(ctx2, evt) {
537
540
  ctx2.value = evt.value;
538
541
  },
542
+ clearValue(ctx2) {
543
+ ctx2.value = null;
544
+ },
539
545
  invokeOnDelete(ctx2, evt) {
540
546
  var _a;
541
547
  (_a = ctx2.onDelete) == null ? void 0 : _a.call(ctx2, { value: evt.value });
@@ -592,8 +598,7 @@ function machine(userContext) {
592
598
  },
593
599
  setPrevSelectedTabs(ctx2) {
594
600
  if (ctx2.value != null) {
595
- const newSelected = Array.from(ctx2.previousValues).concat(ctx2.value);
596
- ctx2.previousValues = Array.from(new Set(newSelected));
601
+ ctx2.previousValues = pushUnique(Array.from(ctx2.previousValues), ctx2.value);
597
602
  }
598
603
  },
599
604
  setContentTabIndex(ctx2) {
@@ -613,6 +618,15 @@ function machine(userContext) {
613
618
  }
614
619
  );
615
620
  }
621
+ function pushUnique(arr, value) {
622
+ const newArr = arr.slice();
623
+ const index = newArr.indexOf(value);
624
+ if (index > -1) {
625
+ newArr.splice(index, 1);
626
+ }
627
+ newArr.push(value);
628
+ return newArr;
629
+ }
616
630
  // Annotate the CommonJS export names for ESM import in node:
617
631
  0 && (module.exports = {
618
632
  connect,
package/dist/index.mjs CHANGED
@@ -252,6 +252,9 @@ function connect(state, send, normalize) {
252
252
  setValue(value) {
253
253
  send({ type: "SET_VALUE", value });
254
254
  },
255
+ clearValue() {
256
+ send({ type: "CLEAR_VALUE" });
257
+ },
255
258
  rootProps: normalize.element({
256
259
  "data-part": "root",
257
260
  id: dom.getRootId(state.context),
@@ -420,8 +423,8 @@ function machine(userContext) {
420
423
  SET_VALUE: {
421
424
  actions: "setValue"
422
425
  },
423
- DELETE: {
424
- actions: "deleteValue"
426
+ CLEAR_VALUE: {
427
+ actions: "clearValue"
425
428
  }
426
429
  },
427
430
  states: {
@@ -509,6 +512,9 @@ function machine(userContext) {
509
512
  setValue(ctx2, evt) {
510
513
  ctx2.value = evt.value;
511
514
  },
515
+ clearValue(ctx2) {
516
+ ctx2.value = null;
517
+ },
512
518
  invokeOnDelete(ctx2, evt) {
513
519
  var _a;
514
520
  (_a = ctx2.onDelete) == null ? void 0 : _a.call(ctx2, { value: evt.value });
@@ -565,8 +571,7 @@ function machine(userContext) {
565
571
  },
566
572
  setPrevSelectedTabs(ctx2) {
567
573
  if (ctx2.value != null) {
568
- const newSelected = Array.from(ctx2.previousValues).concat(ctx2.value);
569
- ctx2.previousValues = Array.from(new Set(newSelected));
574
+ ctx2.previousValues = pushUnique(Array.from(ctx2.previousValues), ctx2.value);
570
575
  }
571
576
  },
572
577
  setContentTabIndex(ctx2) {
@@ -586,6 +591,15 @@ function machine(userContext) {
586
591
  }
587
592
  );
588
593
  }
594
+ function pushUnique(arr, value) {
595
+ const newArr = arr.slice();
596
+ const index = newArr.indexOf(value);
597
+ if (index > -1) {
598
+ newArr.splice(index, 1);
599
+ }
600
+ newArr.push(value);
601
+ return newArr;
602
+ }
589
603
  export {
590
604
  connect,
591
605
  machine
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/tabs",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Core logic for the tabs widget implemented as a state machine",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -29,12 +29,12 @@
29
29
  "url": "https://github.com/chakra-ui/zag/issues"
30
30
  },
31
31
  "dependencies": {
32
- "@zag-js/core": "0.2.1",
33
- "@zag-js/types": "0.3.0"
32
+ "@zag-js/core": "0.2.2",
33
+ "@zag-js/types": "0.3.1"
34
34
  },
35
35
  "devDependencies": {
36
- "@zag-js/dom-utils": "0.2.0",
37
- "@zag-js/utils": "0.3.0"
36
+ "@zag-js/dom-utils": "0.2.1",
37
+ "@zag-js/utils": "0.3.1"
38
38
  },
39
39
  "scripts": {
40
40
  "build-fast": "tsup src/index.ts --format=esm,cjs",