@zag-js/tabs 0.0.0-dev-20220416152643 → 0.0.0-dev-20220418173111

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
@@ -1,4 +1,4 @@
1
1
  export { connect } from "./tabs.connect";
2
2
  export { machine } from "./tabs.machine";
3
- export type { MachineContext, MachineState } from "./tabs.types";
3
+ export type { UserDefinedContext as Context } from "./tabs.types";
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AACxC,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AACxC,YAAY,EAAE,kBAAkB,IAAI,OAAO,EAAE,MAAM,cAAc,CAAA"}
package/dist/index.js CHANGED
@@ -399,204 +399,206 @@ function connect(state, send, normalize = normalizeProp) {
399
399
  // src/tabs.machine.ts
400
400
  var import_core = require("@zag-js/core");
401
401
  var { not } = import_core.guards;
402
- var machine = (0, import_core.createMachine)({
403
- initial: "unknown",
404
- context: {
405
- dir: "ltr",
406
- orientation: "horizontal",
407
- activationMode: "automatic",
408
- value: null,
409
- focusedValue: null,
410
- uid: "",
411
- previousValues: [],
412
- indicatorRect: { left: "0px", top: "0px", width: "0px", height: "0px" },
413
- hasMeasuredRect: false,
414
- isIndicatorRendered: false,
415
- loop: true,
416
- messages: {}
417
- },
418
- computed: {
419
- isHorizontal: (ctx) => ctx.orientation === "horizontal",
420
- isVertical: (ctx) => ctx.orientation === "vertical"
421
- },
422
- created: ["setPrevSelectedTabs"],
423
- watch: {
424
- focusedValue: "invokeOnFocus",
425
- value: ["invokeOnChange", "setPrevSelectedTabs", "setIndicatorRect", "setContentTabIndex"],
426
- dir: ["clearMeasured", "setIndicatorRect"]
427
- },
428
- on: {
429
- SET_VALUE: {
430
- actions: "setValue"
402
+ function machine(ctx = {}) {
403
+ return (0, import_core.createMachine)({
404
+ initial: "unknown",
405
+ context: __spreadValues({
406
+ dir: "ltr",
407
+ orientation: "horizontal",
408
+ activationMode: "automatic",
409
+ value: null,
410
+ focusedValue: null,
411
+ uid: "",
412
+ previousValues: [],
413
+ indicatorRect: { left: "0px", top: "0px", width: "0px", height: "0px" },
414
+ hasMeasuredRect: false,
415
+ isIndicatorRendered: false,
416
+ loop: true,
417
+ messages: {}
418
+ }, ctx),
419
+ computed: {
420
+ isHorizontal: (ctx2) => ctx2.orientation === "horizontal",
421
+ isVertical: (ctx2) => ctx2.orientation === "vertical"
431
422
  },
432
- DELETE: {
433
- actions: "deleteValue"
434
- }
435
- },
436
- states: {
437
- unknown: {
438
- on: {
439
- SETUP: {
440
- target: "idle",
441
- actions: ["setupDocument", "checkRenderedElements", "setIndicatorRect", "setContentTabIndex"]
442
- }
443
- }
423
+ created: ["setPrevSelectedTabs"],
424
+ watch: {
425
+ focusedValue: "invokeOnFocus",
426
+ value: ["invokeOnChange", "setPrevSelectedTabs", "setIndicatorRect", "setContentTabIndex"],
427
+ dir: ["clearMeasured", "setIndicatorRect"]
444
428
  },
445
- idle: {
446
- on: {
447
- TAB_FOCUS: {
448
- guard: "selectOnFocus",
449
- target: "focused",
450
- actions: ["setFocusedValue", "setValue"]
451
- },
452
- TAB_CLICK: {
453
- target: "focused",
454
- actions: ["setFocusedValue", "setValue"]
455
- }
429
+ on: {
430
+ SET_VALUE: {
431
+ actions: "setValue"
432
+ },
433
+ DELETE: {
434
+ actions: "deleteValue"
456
435
  }
457
436
  },
458
- focused: {
459
- on: {
460
- TAB_CLICK: {
461
- target: "focused",
462
- actions: ["setFocusedValue", "setValue"]
463
- },
464
- ARROW_LEFT: {
465
- guard: "isHorizontal",
466
- actions: "focusPrevTab"
467
- },
468
- ARROW_RIGHT: {
469
- guard: "isHorizontal",
470
- actions: "focusNextTab"
471
- },
472
- ARROW_UP: {
473
- guard: "isVertical",
474
- actions: "focusPrevTab"
475
- },
476
- ARROW_DOWN: {
477
- guard: "isVertical",
478
- actions: "focusNextTab"
479
- },
480
- HOME: {
481
- actions: "focusFirstTab"
482
- },
483
- END: {
484
- actions: "focusLastTab"
485
- },
486
- ENTER: {
487
- guard: not("selectOnFocus"),
488
- actions: "setValue"
489
- },
490
- TAB_FOCUS: [
491
- {
437
+ states: {
438
+ unknown: {
439
+ on: {
440
+ SETUP: {
441
+ target: "idle",
442
+ actions: ["setupDocument", "checkRenderedElements", "setIndicatorRect", "setContentTabIndex"]
443
+ }
444
+ }
445
+ },
446
+ idle: {
447
+ on: {
448
+ TAB_FOCUS: {
492
449
  guard: "selectOnFocus",
450
+ target: "focused",
493
451
  actions: ["setFocusedValue", "setValue"]
494
452
  },
495
- { actions: "setFocusedValue" }
496
- ],
497
- TAB_BLUR: {
498
- target: "idle",
499
- actions: "clearFocusedValue"
453
+ TAB_CLICK: {
454
+ target: "focused",
455
+ actions: ["setFocusedValue", "setValue"]
456
+ }
457
+ }
458
+ },
459
+ focused: {
460
+ on: {
461
+ TAB_CLICK: {
462
+ target: "focused",
463
+ actions: ["setFocusedValue", "setValue"]
464
+ },
465
+ ARROW_LEFT: {
466
+ guard: "isHorizontal",
467
+ actions: "focusPrevTab"
468
+ },
469
+ ARROW_RIGHT: {
470
+ guard: "isHorizontal",
471
+ actions: "focusNextTab"
472
+ },
473
+ ARROW_UP: {
474
+ guard: "isVertical",
475
+ actions: "focusPrevTab"
476
+ },
477
+ ARROW_DOWN: {
478
+ guard: "isVertical",
479
+ actions: "focusNextTab"
480
+ },
481
+ HOME: {
482
+ actions: "focusFirstTab"
483
+ },
484
+ END: {
485
+ actions: "focusLastTab"
486
+ },
487
+ ENTER: {
488
+ guard: not("selectOnFocus"),
489
+ actions: "setValue"
490
+ },
491
+ TAB_FOCUS: [
492
+ {
493
+ guard: "selectOnFocus",
494
+ actions: ["setFocusedValue", "setValue"]
495
+ },
496
+ { actions: "setFocusedValue" }
497
+ ],
498
+ TAB_BLUR: {
499
+ target: "idle",
500
+ actions: "clearFocusedValue"
501
+ }
500
502
  }
501
503
  }
502
504
  }
503
- }
504
- }, {
505
- guards: {
506
- isVertical: (ctx) => ctx.isVertical,
507
- isHorizontal: (ctx) => ctx.isHorizontal,
508
- selectOnFocus: (ctx) => ctx.activationMode === "automatic"
509
- },
510
- actions: {
511
- setupDocument(ctx, evt) {
512
- ctx.uid = evt.id;
513
- if (evt.doc)
514
- ctx.doc = (0, import_core.ref)(evt.doc);
515
- },
516
- setFocusedValue(ctx, evt) {
517
- ctx.focusedValue = evt.value;
518
- },
519
- clearFocusedValue(ctx) {
520
- ctx.focusedValue = null;
521
- },
522
- setValue(ctx, evt) {
523
- ctx.value = evt.value;
524
- },
525
- invokeOnDelete(ctx, evt) {
526
- var _a;
527
- (_a = ctx.onDelete) == null ? void 0 : _a.call(ctx, { value: evt.value });
505
+ }, {
506
+ guards: {
507
+ isVertical: (ctx2) => ctx2.isVertical,
508
+ isHorizontal: (ctx2) => ctx2.isHorizontal,
509
+ selectOnFocus: (ctx2) => ctx2.activationMode === "automatic"
528
510
  },
529
- focusFirstTab(ctx) {
530
- nextTick(() => {
511
+ actions: {
512
+ setupDocument(ctx2, evt) {
513
+ ctx2.uid = evt.id;
514
+ if (evt.doc)
515
+ ctx2.doc = (0, import_core.ref)(evt.doc);
516
+ },
517
+ setFocusedValue(ctx2, evt) {
518
+ ctx2.focusedValue = evt.value;
519
+ },
520
+ clearFocusedValue(ctx2) {
521
+ ctx2.focusedValue = null;
522
+ },
523
+ setValue(ctx2, evt) {
524
+ ctx2.value = evt.value;
525
+ },
526
+ invokeOnDelete(ctx2, evt) {
531
527
  var _a;
532
- return (_a = dom.getFirstEl(ctx)) == null ? void 0 : _a.focus();
533
- });
534
- },
535
- focusLastTab(ctx) {
536
- nextTick(() => {
537
- var _a;
538
- return (_a = dom.getLastEl(ctx)) == null ? void 0 : _a.focus();
539
- });
540
- },
541
- focusNextTab(ctx) {
542
- if (!ctx.focusedValue)
543
- return;
544
- const next = dom.getNextEl(ctx, ctx.focusedValue);
545
- nextTick(() => next == null ? void 0 : next.focus());
546
- },
547
- focusPrevTab(ctx) {
548
- if (!ctx.focusedValue)
549
- return;
550
- const prev = dom.getPrevEl(ctx, ctx.focusedValue);
551
- nextTick(() => prev == null ? void 0 : prev.focus());
552
- },
553
- setIndicatorRect(ctx) {
554
- nextTick(() => {
555
- if (!ctx.isIndicatorRendered || !ctx.value)
528
+ (_a = ctx2.onDelete) == null ? void 0 : _a.call(ctx2, { value: evt.value });
529
+ },
530
+ focusFirstTab(ctx2) {
531
+ nextTick(() => {
532
+ var _a;
533
+ return (_a = dom.getFirstEl(ctx2)) == null ? void 0 : _a.focus();
534
+ });
535
+ },
536
+ focusLastTab(ctx2) {
537
+ nextTick(() => {
538
+ var _a;
539
+ return (_a = dom.getLastEl(ctx2)) == null ? void 0 : _a.focus();
540
+ });
541
+ },
542
+ focusNextTab(ctx2) {
543
+ if (!ctx2.focusedValue)
556
544
  return;
557
- ctx.indicatorRect = dom.getRectById(ctx, ctx.value);
558
- if (ctx.hasMeasuredRect)
545
+ const next = dom.getNextEl(ctx2, ctx2.focusedValue);
546
+ nextTick(() => next == null ? void 0 : next.focus());
547
+ },
548
+ focusPrevTab(ctx2) {
549
+ if (!ctx2.focusedValue)
559
550
  return;
551
+ const prev = dom.getPrevEl(ctx2, ctx2.focusedValue);
552
+ nextTick(() => prev == null ? void 0 : prev.focus());
553
+ },
554
+ setIndicatorRect(ctx2) {
560
555
  nextTick(() => {
561
- ctx.hasMeasuredRect = true;
556
+ if (!ctx2.isIndicatorRendered || !ctx2.value)
557
+ return;
558
+ ctx2.indicatorRect = dom.getRectById(ctx2, ctx2.value);
559
+ if (ctx2.hasMeasuredRect)
560
+ return;
561
+ nextTick(() => {
562
+ ctx2.hasMeasuredRect = true;
563
+ });
562
564
  });
563
- });
564
- },
565
- checkRenderedElements(ctx) {
566
- nextTick(() => {
567
- ctx.isIndicatorRendered = !!dom.getIndicatorEl(ctx);
568
- });
569
- },
570
- clearMeasured(ctx) {
571
- ctx.hasMeasuredRect = false;
572
- },
573
- invokeOnChange(ctx) {
574
- var _a;
575
- (_a = ctx.onChange) == null ? void 0 : _a.call(ctx, { value: ctx.value });
576
- },
577
- invokeOnFocus(ctx) {
578
- var _a;
579
- (_a = ctx.onFocus) == null ? void 0 : _a.call(ctx, { value: ctx.focusedValue });
580
- },
581
- setPrevSelectedTabs(ctx) {
582
- if (ctx.value != null) {
583
- const newSelected = Array.from(ctx.previousValues).concat(ctx.value);
584
- ctx.previousValues = Array.from(new Set(newSelected));
585
- }
586
- },
587
- setContentTabIndex(ctx) {
588
- nextTick(() => {
589
- const panel = dom.getActiveContentEl(ctx);
590
- if (!panel)
591
- return;
592
- const focusables = getFocusables(panel);
593
- if (focusables.length > 0) {
594
- panel.removeAttribute("tabindex");
595
- } else {
596
- panel.setAttribute("tabindex", "0");
565
+ },
566
+ checkRenderedElements(ctx2) {
567
+ nextTick(() => {
568
+ ctx2.isIndicatorRendered = !!dom.getIndicatorEl(ctx2);
569
+ });
570
+ },
571
+ clearMeasured(ctx2) {
572
+ ctx2.hasMeasuredRect = false;
573
+ },
574
+ invokeOnChange(ctx2) {
575
+ var _a;
576
+ (_a = ctx2.onChange) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
577
+ },
578
+ invokeOnFocus(ctx2) {
579
+ var _a;
580
+ (_a = ctx2.onFocus) == null ? void 0 : _a.call(ctx2, { value: ctx2.focusedValue });
581
+ },
582
+ setPrevSelectedTabs(ctx2) {
583
+ if (ctx2.value != null) {
584
+ const newSelected = Array.from(ctx2.previousValues).concat(ctx2.value);
585
+ ctx2.previousValues = Array.from(new Set(newSelected));
597
586
  }
598
- });
587
+ },
588
+ setContentTabIndex(ctx2) {
589
+ nextTick(() => {
590
+ const panel = dom.getActiveContentEl(ctx2);
591
+ if (!panel)
592
+ return;
593
+ const focusables = getFocusables(panel);
594
+ if (focusables.length > 0) {
595
+ panel.removeAttribute("tabindex");
596
+ } else {
597
+ panel.setAttribute("tabindex", "0");
598
+ }
599
+ });
600
+ }
599
601
  }
600
- }
601
- });
602
+ });
603
+ }
602
604
  //# sourceMappingURL=index.js.map