@flytedan/flytebot-design-system 0.34.0 → 0.36.0

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
@@ -3631,7 +3631,28 @@ function MultiSelectPanel({
3631
3631
  );
3632
3632
  }) }) : null
3633
3633
  ] });
3634
- const footer = mode2 === "paste" ? /* @__PURE__ */ jsx45(Button, { size: "sm", variant: "secondary", onClick: doResolve, disabled: pasteLoading || !pasteText.trim(), children: pasteLoading ? "Resolving\u2026" : "Resolve" }) : void 0;
3634
+ const resolveDisabled = pasteLoading || !pasteText.trim();
3635
+ const footer = mode2 === "paste" ? /* @__PURE__ */ jsx45(
3636
+ Button,
3637
+ {
3638
+ size: "sm",
3639
+ variant: "secondary",
3640
+ "aria-disabled": resolveDisabled,
3641
+ onClick: (e) => {
3642
+ if (resolveDisabled) {
3643
+ e.preventDefault();
3644
+ return;
3645
+ }
3646
+ doResolve();
3647
+ },
3648
+ onKeyDown: (e) => {
3649
+ if (resolveDisabled && (e.key === "Enter" || e.key === " ")) {
3650
+ e.preventDefault();
3651
+ }
3652
+ },
3653
+ children: pasteLoading ? "Resolving\u2026" : "Resolve"
3654
+ }
3655
+ ) : void 0;
3635
3656
  return /* @__PURE__ */ jsx45(
3636
3657
  Popover,
3637
3658
  {
@@ -3700,6 +3721,28 @@ function useReseedFromProps(value, applies, reseed) {
3700
3721
  if (!sameValue(value, applies())) reseed(value);
3701
3722
  }, [value, applies, reseed]);
3702
3723
  }
3724
+ function usePreserveFocusAcrossRemount(seed, fields) {
3725
+ const pendingName = React25.useRef(null);
3726
+ const fieldsRef = useLatest(fields);
3727
+ const capture = () => {
3728
+ const active = document.activeElement;
3729
+ pendingName.current = null;
3730
+ if (!(active instanceof HTMLElement)) return;
3731
+ for (const [name, ref] of Object.entries(fieldsRef.current)) {
3732
+ if (ref.current?.contains(active)) {
3733
+ pendingName.current = name;
3734
+ break;
3735
+ }
3736
+ }
3737
+ };
3738
+ React25.useLayoutEffect(() => {
3739
+ const name = pendingName.current;
3740
+ if (!name) return;
3741
+ pendingName.current = null;
3742
+ fieldsRef.current[name]?.current?.querySelector("input,textarea,select,button")?.focus();
3743
+ }, [seed]);
3744
+ return capture;
3745
+ }
3703
3746
  var rangeDraft = (value) => ({ min: value?.min, max: value?.max });
3704
3747
  function RangePanel({
3705
3748
  field,
@@ -3710,6 +3753,11 @@ function RangePanel({
3710
3753
  }) {
3711
3754
  const [draft, setDraft] = React25.useState(() => rangeDraft(value));
3712
3755
  const [seed, setSeed] = React25.useState(0);
3756
+ const minId = React25.useId();
3757
+ const maxId = React25.useId();
3758
+ const minWrapRef = React25.useRef(null);
3759
+ const maxWrapRef = React25.useRef(null);
3760
+ const preserveFocus = usePreserveFocusAcrossRemount(seed, { min: minWrapRef, max: maxWrapRef });
3713
3761
  const draftRef = React25.useRef(draft);
3714
3762
  const shown = () => {
3715
3763
  const { min, max } = draftRef.current;
@@ -3720,6 +3768,7 @@ function RangePanel({
3720
3768
  };
3721
3769
  const validity = useTextValidity(publish);
3722
3770
  useReseedFromProps(value, shown, (next) => {
3771
+ preserveFocus();
3723
3772
  draftRef.current = rangeDraft(next);
3724
3773
  setDraft(draftRef.current);
3725
3774
  validity.reset();
@@ -3749,9 +3798,10 @@ function RangePanel({
3749
3798
  label: field.label,
3750
3799
  footer: /* @__PURE__ */ jsx45(Button, { size: "sm", variant: "secondary", onClick: onClose, disabled: doneDisabled, children: "Done" }),
3751
3800
  children: /* @__PURE__ */ jsxs39("span", { className: "fd-stack fd-gap-sm", children: [
3752
- /* @__PURE__ */ jsx45(
3801
+ /* @__PURE__ */ jsx45("span", { ref: minWrapRef, children: /* @__PURE__ */ jsx45(
3753
3802
  NumberInput,
3754
3803
  {
3804
+ id: minId,
3755
3805
  label: field.minLabel || "At least",
3756
3806
  value: draftMin ?? "",
3757
3807
  min: field.min,
@@ -3763,10 +3813,11 @@ function RangePanel({
3763
3813
  onValidityChange: validity.report("min")
3764
3814
  },
3765
3815
  "min-" + seed
3766
- ),
3767
- /* @__PURE__ */ jsx45(
3816
+ ) }),
3817
+ /* @__PURE__ */ jsx45("span", { ref: maxWrapRef, children: /* @__PURE__ */ jsx45(
3768
3818
  NumberInput,
3769
3819
  {
3820
+ id: maxId,
3770
3821
  label: field.maxLabel || "At most",
3771
3822
  value: draftMax ?? "",
3772
3823
  min: field.min,
@@ -3779,7 +3830,7 @@ function RangePanel({
3779
3830
  onValidityChange: validity.report("max")
3780
3831
  },
3781
3832
  "max-" + seed
3782
- )
3833
+ ) })
3783
3834
  ] })
3784
3835
  }
3785
3836
  );
@@ -3806,6 +3857,9 @@ function DatePanel({
3806
3857
  const daysConfirmed = React25.useRef(value?.kind === "withinDays");
3807
3858
  const [between, setBetween] = React25.useState(initial.between);
3808
3859
  const [seed, setSeed] = React25.useState(0);
3860
+ const daysId = React25.useId();
3861
+ const daysWrapRef = React25.useRef(null);
3862
+ const preserveFocus = usePreserveFocusAcrossRemount(seed, { days: daysWrapRef });
3809
3863
  const shownWithinDays = () => {
3810
3864
  const days = daysRef.current;
3811
3865
  return applicable(field, days == null ? void 0 : { kind: "withinDays", days }, validity.allValid());
@@ -3821,6 +3875,7 @@ function DatePanel({
3821
3875
  return daysConfirmed.current ? shownWithinDays() : void 0;
3822
3876
  };
3823
3877
  useReseedFromProps(value, applies, (next) => {
3878
+ preserveFocus();
3824
3879
  const d = dateDraft(field, next);
3825
3880
  setKind(d.kind);
3826
3881
  daysRef.current = d.days;
@@ -3887,9 +3942,10 @@ function DatePanel({
3887
3942
  onChange: (k) => switchKind(k)
3888
3943
  }
3889
3944
  ),
3890
- kind === "withinDays" ? /* @__PURE__ */ jsx45(
3945
+ kind === "withinDays" ? /* @__PURE__ */ jsx45("span", { ref: daysWrapRef, children: /* @__PURE__ */ jsx45(
3891
3946
  NumberInput,
3892
3947
  {
3948
+ id: daysId,
3893
3949
  label: "Days",
3894
3950
  min: 1,
3895
3951
  max: maxDays,
@@ -3900,7 +3956,7 @@ function DatePanel({
3900
3956
  onValidityChange: validity.report("days")
3901
3957
  },
3902
3958
  "days-" + seed
3903
- ) : /* @__PURE__ */ jsx45(
3959
+ ) }) : /* @__PURE__ */ jsx45(
3904
3960
  DatePicker,
3905
3961
  {
3906
3962
  range: true,