@zag-js/popover 0.0.0-dev-20220416104915 → 0.0.0-dev-20220418165817

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 "./popover.connect";
2
2
  export { machine } from "./popover.machine";
3
- export type { MachineContext, MachineState } from "./popover.types";
3
+ export type { UserDefinedContext as Context } from "./popover.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,mBAAmB,CAAA;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAC3C,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAC3C,YAAY,EAAE,kBAAkB,IAAI,OAAO,EAAE,MAAM,iBAAiB,CAAA"}
package/dist/index.js CHANGED
@@ -574,29 +574,29 @@ var dom = {
574
574
  getActiveEl: (ctx) => dom.getDoc(ctx).activeElement,
575
575
  getAnchorId: (ctx) => {
576
576
  var _a, _b;
577
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.anchor) != null ? _b : `popover-${ctx.uid}-anchor`;
577
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.anchor) != null ? _b : `popover:${ctx.uid}:anchor`;
578
578
  },
579
579
  getTriggerId: (ctx) => {
580
580
  var _a, _b;
581
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.trigger) != null ? _b : `popover-${ctx.uid}-trigger`;
581
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.trigger) != null ? _b : `popover:${ctx.uid}:trigger`;
582
582
  },
583
583
  getContentId: (ctx) => {
584
584
  var _a, _b;
585
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.content) != null ? _b : `popover-${ctx.uid}-content`;
585
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.content) != null ? _b : `popover:${ctx.uid}:content`;
586
586
  },
587
- getPositionerId: (ctx) => `popover-${ctx.uid}-popper`,
588
- getArrowId: (ctx) => `popover-${ctx.uid}-arrow`,
587
+ getPositionerId: (ctx) => `popover:${ctx.uid}:popper`,
588
+ getArrowId: (ctx) => `popover:${ctx.uid}:arrow`,
589
589
  getTitleId: (ctx) => {
590
590
  var _a, _b;
591
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.title) != null ? _b : `popover-${ctx.uid}-title`;
591
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.title) != null ? _b : `popover:${ctx.uid}:title`;
592
592
  },
593
593
  getDescriptionId: (ctx) => {
594
594
  var _a, _b;
595
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.description) != null ? _b : `popover-${ctx.uid}-desc`;
595
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.description) != null ? _b : `popover:${ctx.uid}:desc`;
596
596
  },
597
597
  getCloseButtonId: (ctx) => {
598
598
  var _a, _b;
599
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.closeBtn) != null ? _b : `popover-${ctx.uid}-close-button`;
599
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.closeBtn) != null ? _b : `popover:${ctx.uid}:close-button`;
600
600
  },
601
601
  getAnchorEl: (ctx) => dom.getDoc(ctx).getElementById(dom.getAnchorId(ctx)),
602
602
  getTriggerEl: (ctx) => dom.getDoc(ctx).getElementById(dom.getTriggerId(ctx)),
@@ -727,245 +727,249 @@ var import_popper2 = require("@zag-js/popper");
727
727
  var import_aria_hidden = require("aria-hidden");
728
728
  var import_focus_trap = require("focus-trap");
729
729
  var { and, or } = import_core.guards;
730
- var machine = (0, import_core.createMachine)({
731
- id: "popover",
732
- initial: "unknown",
733
- context: {
734
- isTitleRendered: true,
735
- isDescriptionRendered: true,
736
- isAnchorRendered: false,
737
- uid: "",
738
- closeOnBlur: true,
739
- closeOnEsc: true,
740
- autoFocus: true,
741
- modal: false,
742
- positioning: { placement: "bottom" },
743
- currentPlacement: void 0
744
- },
745
- computed: {
746
- currentPortalled: (ctx) => !!ctx.modal || !!ctx.portalled
747
- },
748
- states: {
749
- unknown: {
750
- on: {
751
- SETUP: {
752
- target: "closed",
753
- actions: ["setupDocument", "checkRenderedElements"]
754
- }
755
- }
730
+ function machine(ctx = {}) {
731
+ return (0, import_core.createMachine)({
732
+ id: "popover",
733
+ initial: "unknown",
734
+ context: __spreadValues({
735
+ isTitleRendered: true,
736
+ isDescriptionRendered: true,
737
+ isAnchorRendered: false,
738
+ uid: "",
739
+ closeOnBlur: true,
740
+ closeOnEsc: true,
741
+ autoFocus: true,
742
+ modal: false,
743
+ positioning: __spreadValues({
744
+ placement: "bottom"
745
+ }, ctx.positioning),
746
+ currentPlacement: void 0
747
+ }, ctx),
748
+ computed: {
749
+ currentPortalled: (ctx2) => !!ctx2.modal || !!ctx2.portalled
756
750
  },
757
- closed: {
758
- entry: ["clearPointerDown", "invokeOnClose"],
759
- on: {
760
- TRIGGER_CLICK: "open",
761
- OPEN: "open"
762
- }
763
- },
764
- open: {
765
- activities: [
766
- "trackPointerDown",
767
- "trapFocus",
768
- "preventScroll",
769
- "hideContentBelow",
770
- "disableOutsidePointerEvents",
771
- "computePlacement"
772
- ],
773
- entry: (0, import_core.choose)([
774
- {
775
- guard: "autoFocus",
776
- actions: ["setInitialFocus", "invokeOnOpen"]
777
- },
778
- { actions: ["focusContent", "invokeOnOpen"] }
779
- ]),
780
- on: {
781
- CLOSE: {
782
- target: "closed",
783
- actions: "focusTrigger"
784
- },
785
- TRIGGER_CLICK: {
786
- target: "closed",
787
- actions: "focusTrigger"
788
- },
789
- ESCAPE: {
790
- guard: "closeOnEsc",
791
- target: "closed",
792
- actions: "focusTrigger"
793
- },
794
- TAB: {
795
- guard: and("isLastTabbableElement", "closeOnBlur", "portalled"),
796
- target: "closed",
797
- actions: "focusNextTabbableElementAfterTrigger"
798
- },
799
- SHIFT_TAB: {
800
- guard: and(or("isFirstTabbableElement", "isContentFocused"), "closeOnBlur", "portalled"),
801
- target: "closed",
802
- actions: "focusTrigger"
803
- },
804
- INTERACT_OUTSIDE: [
751
+ states: {
752
+ unknown: {
753
+ on: {
754
+ SETUP: {
755
+ target: "closed",
756
+ actions: ["setupDocument", "checkRenderedElements"]
757
+ }
758
+ }
759
+ },
760
+ closed: {
761
+ entry: ["clearPointerDown", "invokeOnClose"],
762
+ on: {
763
+ TRIGGER_CLICK: "open",
764
+ OPEN: "open"
765
+ }
766
+ },
767
+ open: {
768
+ activities: [
769
+ "trackPointerDown",
770
+ "trapFocus",
771
+ "preventScroll",
772
+ "hideContentBelow",
773
+ "disableOutsidePointerEvents",
774
+ "computePlacement"
775
+ ],
776
+ entry: (0, import_core.choose)([
805
777
  {
806
- guard: and("closeOnBlur", "isRelatedTargetFocusable"),
807
- target: "closed"
778
+ guard: "autoFocus",
779
+ actions: ["setInitialFocus", "invokeOnOpen"]
808
780
  },
809
- {
810
- guard: "closeOnBlur",
781
+ { actions: ["focusContent", "invokeOnOpen"] }
782
+ ]),
783
+ on: {
784
+ CLOSE: {
811
785
  target: "closed",
812
786
  actions: "focusTrigger"
813
- }
814
- ]
787
+ },
788
+ TRIGGER_CLICK: {
789
+ target: "closed",
790
+ actions: "focusTrigger"
791
+ },
792
+ ESCAPE: {
793
+ guard: "closeOnEsc",
794
+ target: "closed",
795
+ actions: "focusTrigger"
796
+ },
797
+ TAB: {
798
+ guard: and("isLastTabbableElement", "closeOnBlur", "portalled"),
799
+ target: "closed",
800
+ actions: "focusNextTabbableElementAfterTrigger"
801
+ },
802
+ SHIFT_TAB: {
803
+ guard: and(or("isFirstTabbableElement", "isContentFocused"), "closeOnBlur", "portalled"),
804
+ target: "closed",
805
+ actions: "focusTrigger"
806
+ },
807
+ INTERACT_OUTSIDE: [
808
+ {
809
+ guard: and("closeOnBlur", "isRelatedTargetFocusable"),
810
+ target: "closed"
811
+ },
812
+ {
813
+ guard: "closeOnBlur",
814
+ target: "closed",
815
+ actions: "focusTrigger"
816
+ }
817
+ ]
818
+ }
815
819
  }
816
820
  }
817
- }
818
- }, {
819
- activities: {
820
- computePlacement(ctx) {
821
- ctx.currentPlacement = ctx.positioning.placement;
822
- const anchorEl = ctx.isAnchorRendered ? dom.getAnchorEl(ctx) : dom.getTriggerEl(ctx);
823
- return (0, import_popper2.getPlacement)(anchorEl, dom.getPositionerEl(ctx), __spreadProps(__spreadValues({}, ctx.positioning), {
824
- onComplete(data) {
825
- ctx.currentPlacement = data.placement;
826
- ctx.isPlacementComplete = true;
827
- },
828
- onCleanup() {
829
- ctx.currentPlacement = void 0;
830
- ctx.isPlacementComplete = false;
831
- }
832
- }));
833
- },
834
- trackPointerDown(ctx) {
835
- return trackPointerDown(dom.getDoc(ctx), (el) => {
836
- ctx.pointerdownNode = (0, import_core.ref)(el);
837
- });
838
- },
839
- disableOutsidePointerEvents(ctx) {
840
- const el = dom.getContentEl(ctx);
841
- return preventBodyPointerEvents(el, {
842
- document: dom.getDoc(ctx),
843
- disabled: !ctx.modal
844
- });
845
- },
846
- hideContentBelow(ctx) {
847
- if (!ctx.modal)
848
- return;
849
- let unhide;
850
- nextTick(() => {
851
- const el = dom.getContentEl(ctx);
852
- if (!el)
821
+ }, {
822
+ activities: {
823
+ computePlacement(ctx2) {
824
+ ctx2.currentPlacement = ctx2.positioning.placement;
825
+ const anchorEl = ctx2.isAnchorRendered ? dom.getAnchorEl(ctx2) : dom.getTriggerEl(ctx2);
826
+ return (0, import_popper2.getPlacement)(anchorEl, dom.getPositionerEl(ctx2), __spreadProps(__spreadValues({}, ctx2.positioning), {
827
+ onComplete(data) {
828
+ ctx2.currentPlacement = data.placement;
829
+ ctx2.isPlacementComplete = true;
830
+ },
831
+ onCleanup() {
832
+ ctx2.currentPlacement = void 0;
833
+ ctx2.isPlacementComplete = false;
834
+ }
835
+ }));
836
+ },
837
+ trackPointerDown(ctx2) {
838
+ return trackPointerDown(dom.getDoc(ctx2), (el) => {
839
+ ctx2.pointerdownNode = (0, import_core.ref)(el);
840
+ });
841
+ },
842
+ disableOutsidePointerEvents(ctx2) {
843
+ const el = dom.getContentEl(ctx2);
844
+ return preventBodyPointerEvents(el, {
845
+ document: dom.getDoc(ctx2),
846
+ disabled: !ctx2.modal
847
+ });
848
+ },
849
+ hideContentBelow(ctx2) {
850
+ if (!ctx2.modal)
853
851
  return;
854
- try {
855
- unhide = (0, import_aria_hidden.hideOthers)(el);
856
- } catch (e2) {
857
- }
858
- });
859
- return () => unhide == null ? void 0 : unhide();
860
- },
861
- preventScroll(ctx) {
862
- return preventBodyScroll({
863
- allowPinchZoom: true,
864
- disabled: !ctx.modal,
865
- document: dom.getDoc(ctx)
866
- });
867
- },
868
- trapFocus(ctx) {
869
- if (!ctx.modal)
870
- return;
871
- let trap;
872
- nextTick(() => {
873
- const el = dom.getContentEl(ctx);
874
- if (!el)
852
+ let unhide;
853
+ nextTick(() => {
854
+ const el = dom.getContentEl(ctx2);
855
+ if (!el)
856
+ return;
857
+ try {
858
+ unhide = (0, import_aria_hidden.hideOthers)(el);
859
+ } catch (e2) {
860
+ }
861
+ });
862
+ return () => unhide == null ? void 0 : unhide();
863
+ },
864
+ preventScroll(ctx2) {
865
+ return preventBodyScroll({
866
+ allowPinchZoom: true,
867
+ disabled: !ctx2.modal,
868
+ document: dom.getDoc(ctx2)
869
+ });
870
+ },
871
+ trapFocus(ctx2) {
872
+ if (!ctx2.modal)
875
873
  return;
876
- trap = (0, import_focus_trap.createFocusTrap)(el, {
877
- escapeDeactivates: false,
878
- allowOutsideClick: true,
879
- returnFocusOnDeactivate: true,
880
- document: dom.getDoc(ctx),
881
- fallbackFocus: el,
882
- initialFocus: runIfFn2(ctx.initialFocusEl)
874
+ let trap;
875
+ nextTick(() => {
876
+ const el = dom.getContentEl(ctx2);
877
+ if (!el)
878
+ return;
879
+ trap = (0, import_focus_trap.createFocusTrap)(el, {
880
+ escapeDeactivates: false,
881
+ allowOutsideClick: true,
882
+ returnFocusOnDeactivate: true,
883
+ document: dom.getDoc(ctx2),
884
+ fallbackFocus: el,
885
+ initialFocus: runIfFn2(ctx2.initialFocusEl)
886
+ });
887
+ try {
888
+ trap.activate();
889
+ } catch (e2) {
890
+ }
883
891
  });
884
- try {
885
- trap.activate();
886
- } catch (e2) {
887
- }
888
- });
889
- return () => trap == null ? void 0 : trap.deactivate();
890
- }
891
- },
892
- guards: {
893
- closeOnEsc: (ctx) => !!ctx.closeOnEsc,
894
- autoFocus: (ctx) => !!ctx.autoFocus,
895
- modal: (ctx) => !!ctx.modal,
896
- portalled: (ctx) => !!ctx.portalled,
897
- isRelatedTargetFocusable: (_ctx, evt) => evt.focusable,
898
- closeOnBlur: (ctx) => !!ctx.closeOnBlur,
899
- isContentFocused: (ctx) => dom.getContentEl(ctx) === dom.getActiveEl(ctx),
900
- isFirstTabbableElement: (ctx) => dom.getFirstTabbableEl(ctx) === dom.getActiveEl(ctx),
901
- isLastTabbableElement: (ctx) => dom.getLastTabbableEl(ctx) === dom.getActiveEl(ctx)
902
- },
903
- actions: {
904
- checkRenderedElements(ctx) {
905
- raf(() => {
906
- ctx.isAnchorRendered = !!dom.getAnchorEl(ctx);
907
- ctx.isTitleRendered = !!dom.getTitleEl(ctx);
908
- ctx.isDescriptionRendered = !!dom.getDescriptionEl(ctx);
909
- });
910
- },
911
- setupDocument(ctx, evt) {
912
- if (evt.doc)
913
- ctx.doc = (0, import_core.ref)(evt.doc);
914
- ctx.uid = evt.id;
892
+ return () => trap == null ? void 0 : trap.deactivate();
893
+ }
915
894
  },
916
- clearPointerDown(ctx) {
917
- ctx.pointerdownNode = null;
895
+ guards: {
896
+ closeOnEsc: (ctx2) => !!ctx2.closeOnEsc,
897
+ autoFocus: (ctx2) => !!ctx2.autoFocus,
898
+ modal: (ctx2) => !!ctx2.modal,
899
+ portalled: (ctx2) => !!ctx2.portalled,
900
+ isRelatedTargetFocusable: (_ctx, evt) => evt.focusable,
901
+ closeOnBlur: (ctx2) => !!ctx2.closeOnBlur,
902
+ isContentFocused: (ctx2) => dom.getContentEl(ctx2) === dom.getActiveEl(ctx2),
903
+ isFirstTabbableElement: (ctx2) => dom.getFirstTabbableEl(ctx2) === dom.getActiveEl(ctx2),
904
+ isLastTabbableElement: (ctx2) => dom.getLastTabbableEl(ctx2) === dom.getActiveEl(ctx2)
918
905
  },
919
- focusContent(ctx) {
920
- nextTick(() => {
921
- var _a;
922
- (_a = dom.getContentEl(ctx)) == null ? void 0 : _a.focus();
923
- });
924
- },
925
- setInitialFocus(ctx) {
926
- nextTick(() => {
906
+ actions: {
907
+ checkRenderedElements(ctx2) {
908
+ raf(() => {
909
+ ctx2.isAnchorRendered = !!dom.getAnchorEl(ctx2);
910
+ ctx2.isTitleRendered = !!dom.getTitleEl(ctx2);
911
+ ctx2.isDescriptionRendered = !!dom.getDescriptionEl(ctx2);
912
+ });
913
+ },
914
+ setupDocument(ctx2, evt) {
915
+ if (evt.doc)
916
+ ctx2.doc = (0, import_core.ref)(evt.doc);
917
+ ctx2.uid = evt.id;
918
+ },
919
+ clearPointerDown(ctx2) {
920
+ ctx2.pointerdownNode = null;
921
+ },
922
+ focusContent(ctx2) {
923
+ nextTick(() => {
924
+ var _a;
925
+ (_a = dom.getContentEl(ctx2)) == null ? void 0 : _a.focus();
926
+ });
927
+ },
928
+ setInitialFocus(ctx2) {
929
+ nextTick(() => {
930
+ var _a;
931
+ (_a = dom.getInitialFocusEl(ctx2)) == null ? void 0 : _a.focus();
932
+ });
933
+ },
934
+ focusTrigger(ctx2) {
935
+ nextTick(() => {
936
+ var _a;
937
+ (_a = dom.getTriggerEl(ctx2)) == null ? void 0 : _a.focus();
938
+ });
939
+ },
940
+ invokeOnOpen(ctx2, evt) {
927
941
  var _a;
928
- (_a = dom.getInitialFocusEl(ctx)) == null ? void 0 : _a.focus();
929
- });
930
- },
931
- focusTrigger(ctx) {
932
- nextTick(() => {
942
+ if (evt.type !== "SETUP") {
943
+ (_a = ctx2.onOpen) == null ? void 0 : _a.call(ctx2);
944
+ }
945
+ },
946
+ invokeOnClose(ctx2, evt) {
933
947
  var _a;
934
- (_a = dom.getTriggerEl(ctx)) == null ? void 0 : _a.focus();
935
- });
936
- },
937
- invokeOnOpen(ctx, evt) {
938
- var _a;
939
- if (evt.type !== "SETUP") {
940
- (_a = ctx.onOpen) == null ? void 0 : _a.call(ctx);
941
- }
942
- },
943
- invokeOnClose(ctx, evt) {
944
- var _a;
945
- if (evt.type !== "SETUP") {
946
- (_a = ctx.onClose) == null ? void 0 : _a.call(ctx);
947
- }
948
- },
949
- focusNextTabbableElementAfterTrigger(ctx, evt) {
950
- const content = dom.getContentEl(ctx);
951
- const doc = dom.getDoc(ctx);
952
- const button = dom.getTriggerEl(ctx);
953
- if (!content || !button)
954
- return;
955
- const lastTabbable = dom.getLastTabbableEl(ctx);
956
- if (lastTabbable !== doc.activeElement)
957
- return;
958
- let tabbables = dom.getDocTabbableEls(ctx);
959
- let elementAfterTrigger = next(tabbables, tabbables.indexOf(button), { loop: false });
960
- if (elementAfterTrigger === content) {
961
- tabbables = tabbables.filter((el) => !contains(content, el));
962
- elementAfterTrigger = next(tabbables, tabbables.indexOf(button), { loop: false });
948
+ if (evt.type !== "SETUP") {
949
+ (_a = ctx2.onClose) == null ? void 0 : _a.call(ctx2);
950
+ }
951
+ },
952
+ focusNextTabbableElementAfterTrigger(ctx2, evt) {
953
+ const content = dom.getContentEl(ctx2);
954
+ const doc = dom.getDoc(ctx2);
955
+ const button = dom.getTriggerEl(ctx2);
956
+ if (!content || !button)
957
+ return;
958
+ const lastTabbable = dom.getLastTabbableEl(ctx2);
959
+ if (lastTabbable !== doc.activeElement)
960
+ return;
961
+ let tabbables = dom.getDocTabbableEls(ctx2);
962
+ let elementAfterTrigger = next(tabbables, tabbables.indexOf(button), { loop: false });
963
+ if (elementAfterTrigger === content) {
964
+ tabbables = tabbables.filter((el) => !contains(content, el));
965
+ elementAfterTrigger = next(tabbables, tabbables.indexOf(button), { loop: false });
966
+ }
967
+ if (!elementAfterTrigger || elementAfterTrigger === button)
968
+ return;
969
+ evt.preventDefault();
970
+ nextTick(() => elementAfterTrigger == null ? void 0 : elementAfterTrigger.focus());
963
971
  }
964
- if (!elementAfterTrigger || elementAfterTrigger === button)
965
- return;
966
- evt.preventDefault();
967
- nextTick(() => elementAfterTrigger == null ? void 0 : elementAfterTrigger.focus());
968
972
  }
969
- }
970
- });
973
+ });
974
+ }
971
975
  //# sourceMappingURL=index.js.map