schummar-table 0.47.1 → 0.48.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.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  const require_chunk = require('./chunk-pbleEpgJ.cjs');
2
- const require_tableSettings = require('./tableSettings-CmqSZu-Q.cjs');
2
+ const require_tableSettings = require('./tableSettings-C450XPgW.cjs');
3
3
  require('./csvExporter-BGoiph1b.cjs');
4
4
  let react = require("react");
5
5
  react = require_chunk.__toESM(react);
@@ -571,12 +571,15 @@ const FilterControlContext = (0, react.createContext)({
571
571
  isActive: false,
572
572
  close: () => void 0
573
573
  });
574
- function FilterControl({ component: Component = DefaultButton, onClose }) {
574
+ function FilterControl() {
575
575
  const table = useTableContext();
576
576
  const columnId = useColumnContext();
577
577
  const Popover$1 = useTheme((t) => t.components.Popover);
578
578
  const classes = useTheme((t) => t.classes);
579
579
  const styles = useTheme((t) => t.styles);
580
+ const IconButton$1 = useTheme((t) => t.components.IconButton);
581
+ const FilterList$1 = useTheme((t) => t.icons.FilterList);
582
+ const ArrowDropDown$1 = useTheme((t) => t.icons.ArrowDropDown);
580
583
  const cssVariables = useCssVariables();
581
584
  const [anchor, setAnchor] = (0, react.useState)(null);
582
585
  const isActive = table.useState((state) => {
@@ -595,21 +598,24 @@ function FilterControl({ component: Component = DefaultButton, onClose }) {
595
598
  state.filterValues.delete(columnId);
596
599
  });
597
600
  }
598
- const context = (0, react.useMemo)(() => ({
599
- isActive: !!anchor,
600
- close: () => setAnchor(null)
601
- }), [anchor]);
602
601
  if (!filter) return null;
602
+ function close() {
603
+ setAnchor(null);
604
+ }
603
605
  return /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsxs)(FilterControlContext.Provider, {
604
- value: context,
605
- children: [/* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)(Component, {
606
+ value: {
607
+ isActive: !!anchor,
608
+ close
609
+ },
610
+ children: [/* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)(IconButton$1, {
606
611
  onClick: (event) => setAnchor(event.currentTarget),
607
612
  onContextMenu: (event) => {
608
613
  reset();
609
614
  event.preventDefault();
610
615
  return false;
611
616
  },
612
- isActive
617
+ css: [{ color: "#b0bac9" }, isActive && { color: "var(--primaryMain) !important" }],
618
+ children: isActive ? /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)(FilterList$1, {}) : /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)(ArrowDropDown$1, {})
613
619
  }), /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)("div", {
614
620
  onPointerDown: (event) => {
615
621
  event.stopPropagation();
@@ -620,10 +626,7 @@ function FilterControl({ component: Component = DefaultButton, onClose }) {
620
626
  children: /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)(__emotion_react.ClassNames, { children: ({ css: css$2, cx: cx$1 }) => /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)(Popover$1, {
621
627
  open: true,
622
628
  hidden: !anchor,
623
- onClose: () => {
624
- setAnchor(null);
625
- onClose?.();
626
- },
629
+ onClose: close,
627
630
  anchorEl: anchor ?? document.body,
628
631
  css: [cssVariables, styles?.popover],
629
632
  className: cx$1(classes?.popover, filterClassNames?.popover),
@@ -633,16 +636,6 @@ function FilterControl({ component: Component = DefaultButton, onClose }) {
633
636
  })]
634
637
  });
635
638
  }
636
- function DefaultButton({ isActive,...props }) {
637
- const IconButton$1 = useTheme((t) => t.components.IconButton);
638
- const FilterList$1 = useTheme((t) => t.icons.FilterList);
639
- const ArrowDropDown$1 = useTheme((t) => t.icons.ArrowDropDown);
640
- return /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)(IconButton$1, {
641
- ...props,
642
- css: [{ color: "#b0bac9" }, isActive && { color: "var(--primaryMain) !important" }],
643
- children: isActive ? /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)(FilterList$1, {}) : /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)(ArrowDropDown$1, {})
644
- });
645
- }
646
639
 
647
640
  //#endregion
648
641
  //#region src/components/autoFocusTextField.tsx
@@ -678,12 +671,21 @@ function debounce(function_, ms) {
678
671
  lastArgs = args;
679
672
  if (timeout) clearTimeout(timeout);
680
673
  timeout = setTimeout(run, ms);
681
- }, { flush() {
682
- if (timeout) {
683
- clearTimeout(timeout);
684
- run();
674
+ }, {
675
+ flush() {
676
+ if (timeout) {
677
+ clearTimeout(timeout);
678
+ run();
679
+ }
680
+ },
681
+ cancel() {
682
+ if (timeout) {
683
+ clearTimeout(timeout);
684
+ timeout = void 0;
685
+ lastArgs = void 0;
686
+ }
685
687
  }
686
- } });
688
+ });
687
689
  }
688
690
 
689
691
  //#endregion
@@ -748,6 +750,143 @@ function useFilter(impl) {
748
750
  };
749
751
  }
750
752
 
753
+ //#endregion
754
+ //#region src/components/filterDialog.tsx
755
+ var filterDialog_default = (0, react.forwardRef)(FilterDialog);
756
+ function FilterDialog(_props, ref) {
757
+ const table = useTableContext();
758
+ const columnId = useColumnContext();
759
+ const classes = useTheme((t) => t.classes);
760
+ const styles = useTheme((t) => t.styles);
761
+ const IconButton$1 = useTheme((t) => t.components.IconButton);
762
+ const FilterList$1 = useTheme((t) => t.icons.FilterList);
763
+ const filter = table.useState((state) => state.activeColumns.find((column) => column.id === columnId)?.filter);
764
+ const label = table.useState((state) => {
765
+ return state.activeColumns.find((column) => column.id === columnId)?.header ?? null;
766
+ });
767
+ const isActive = table.useState((state) => {
768
+ const filter$1 = state.filters.get(columnId);
769
+ const filterValue = state.filterValues.get(columnId);
770
+ return filter$1 !== void 0 && filterValue !== void 0 && filter$1.isActive(filterValue);
771
+ });
772
+ const { close } = (0, react.useContext)(FilterControlContext);
773
+ return /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)("dialog", {
774
+ ref,
775
+ onClick: close,
776
+ className: classes?.dialog,
777
+ css: [{
778
+ padding: 0,
779
+ border: "none",
780
+ borderRadius: 4,
781
+ "::backdrop": { backgroundColor: "rgba(0, 0, 0, 0.7)" }
782
+ }, styles?.dialog],
783
+ children: /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsxs)("div", {
784
+ onClick: (e) => e.stopPropagation(),
785
+ children: [/* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsxs)("div", {
786
+ css: {
787
+ position: "relative",
788
+ padding: 10,
789
+ display: "flex",
790
+ justifyContent: "center",
791
+ alignItems: "center",
792
+ gap: 10
793
+ },
794
+ children: [
795
+ /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)(FilterList$1, { css: { color: isActive ? "var(--primaryMain)" : "#b0bac9" } }),
796
+ /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)("div", {
797
+ css: {
798
+ whiteSpace: "nowrap",
799
+ overflow: "hidden",
800
+ textOverflow: "ellipsis",
801
+ paddingRight: "2em"
802
+ },
803
+ children: label
804
+ }),
805
+ /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)(IconButton$1, {
806
+ onClick: close,
807
+ css: {
808
+ position: "absolute",
809
+ right: 0,
810
+ top: 0,
811
+ fontSize: "1em",
812
+ padding: "0.5em",
813
+ margin: "0.5em",
814
+ lineHeight: 1
815
+ },
816
+ children: "✕"
817
+ })
818
+ ]
819
+ }), /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)("div", {
820
+ css: { overflow: "auto" },
821
+ children: filter
822
+ })]
823
+ })
824
+ });
825
+ }
826
+
827
+ //#endregion
828
+ //#region src/components/nestedFilterControl.tsx
829
+ function NestedFilterControl() {
830
+ const table = useTableContext();
831
+ const columnId = useColumnContext();
832
+ const Button$1 = useTheme((t) => t.components.Button);
833
+ const FilterList$1 = useTheme((t) => t.icons.FilterList);
834
+ const dialog = (0, react.useRef)(null);
835
+ const label = table.useState((state) => {
836
+ return state.activeColumns.find((column) => column.id === columnId)?.header ?? null;
837
+ });
838
+ const isActive = table.useState((state) => {
839
+ const filter$1 = state.filters.get(columnId);
840
+ const filterValue = state.filterValues.get(columnId);
841
+ return filter$1 !== void 0 && filterValue !== void 0 && filter$1.isActive(filterValue);
842
+ });
843
+ const filter = table.useState((state) => state.activeColumns.find((column) => column.id === columnId)?.filter);
844
+ (0, react.useEffect)(() => () => {
845
+ dialog.current?.close();
846
+ }, []);
847
+ if (!filter) return null;
848
+ function reset() {
849
+ const impl = table.getState().filters.get(columnId);
850
+ impl?.onChange?.(void 0);
851
+ if (impl?.value === void 0) table.update((state) => {
852
+ state.filterValues.delete(columnId);
853
+ });
854
+ }
855
+ const parentContext = (0, react.useContext)(FilterControlContext);
856
+ function close() {
857
+ dialog.current?.close();
858
+ parentContext.close();
859
+ }
860
+ return /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsxs)(FilterControlContext.Provider, {
861
+ value: {
862
+ isActive: true,
863
+ close
864
+ },
865
+ children: [/* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)(Button$1, {
866
+ onClick: () => dialog.current?.showModal(),
867
+ onContextMenu: (event) => {
868
+ reset();
869
+ event.preventDefault();
870
+ return false;
871
+ },
872
+ startIcon: /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)(FilterList$1, { css: { color: isActive ? "var(--primaryMain)" : "#b0bac9" } }),
873
+ css: {
874
+ width: "100%",
875
+ color: isActive ? "var(--primaryMain)" : "var(--color-text)"
876
+ },
877
+ children: label
878
+ }), /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)("div", {
879
+ onPointerDown: (event) => {
880
+ event.stopPropagation();
881
+ },
882
+ onPointerMove: (event) => {
883
+ event.stopPropagation();
884
+ },
885
+ children: /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)(filterDialog_default, { ref: dialog })
886
+ })]
887
+ });
888
+ }
889
+
751
890
  //#endregion
752
891
  //#region src/components/combinedFilter.tsx
753
892
  function CombinedFilter({ columnIds: inputColumnIds,...props }) {
@@ -784,26 +923,9 @@ function CombinedFilter({ columnIds: inputColumnIds,...props }) {
784
923
  });
785
924
  return /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)("div", { children: columnIds.map((columnId) => /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)(ColumnContext.Provider, {
786
925
  value: columnId,
787
- children: /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)(FilterControl, { component: Filter })
926
+ children: /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)(NestedFilterControl, {})
788
927
  }, columnId)) });
789
928
  }
790
- function Filter({ isActive,...props }) {
791
- const table = useTableContext();
792
- const columnId = useColumnContext();
793
- const FilterList$1 = useTheme((t) => t.icons.FilterList);
794
- const label = table.useState((state) => {
795
- return state.activeColumns.find((column) => column.id === columnId)?.header ?? null;
796
- });
797
- return /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)(useTheme((t) => t.components.Button), {
798
- ...props,
799
- startIcon: /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)(FilterList$1, { css: { color: isActive ? "var(--primaryMain)" : "#b0bac9" } }),
800
- css: {
801
- width: "100%",
802
- color: isActive ? "var(--primaryMain)" : "var(--color-text)"
803
- },
804
- children: label
805
- });
806
- }
807
929
 
808
930
  //#endregion
809
931
  //#region src/misc/defaults.ts
@@ -820,59 +942,50 @@ function defaults(first, ...more) {
820
942
  const className$1 = "schummar-table-date-input";
821
943
  const defaultDate$1 = new Date(1970, 0, 1);
822
944
  const isIncludedType$1 = (type) => type === "day" || type === "month" || type === "year";
823
- const defaultLengths$1 = {
824
- day: 2,
825
- month: 2,
826
- year: 4
945
+ const maxValues$1 = {
946
+ day: 31,
947
+ month: 12,
948
+ year: 9999
827
949
  };
828
- const maxLengths$1 = {
829
- day: 2,
830
- month: 2,
831
- year: Number.POSITIVE_INFINITY
832
- };
833
- const length$1 = (type, value) => Math.max(value.length, defaultLengths$1[type]);
834
- const tabNext$1 = (event) => {
835
- const all = Array.from(document.querySelectorAll(`.${className$1}`));
836
- const next = all[(all.indexOf(event) + 1) % all.length];
950
+ const tabNext$1 = (event, id) => {
951
+ const all = Array.from(document.querySelectorAll(`.${className$1}-${id}`));
952
+ const next = all[all.indexOf(event) + 1];
837
953
  if (next instanceof HTMLElement) next.focus();
838
954
  };
955
+ function buildDate(value, baseDate = /* @__PURE__ */ new Date()) {
956
+ const date = new Date(baseDate);
957
+ if (value.year) date.setFullYear(Number(value.year));
958
+ if (value.month) date.setMonth(Number(value.month) - 1);
959
+ if (value.day) date.setDate(Number(value.day));
960
+ return date;
961
+ }
839
962
  function DateInput({ value, onChange, locale }) {
840
- const [override, setOverride] = (0, react.useState)();
841
- const commit = () => {
842
- if (!override) return;
843
- setOverride(void 0);
844
- if (!override.value) {
845
- onChange(null);
846
- return;
847
- }
848
- const newValue = value ? new Date(value) : /* @__PURE__ */ new Date();
849
- switch (override.type) {
850
- case "day":
851
- newValue.setDate(Number(override.value));
852
- break;
853
- case "month":
854
- newValue.setMonth(Number(override.value) - 1);
855
- break;
856
- case "year":
857
- newValue.setFullYear(Number(override.value));
858
- break;
859
- default: break;
860
- }
861
- onChange(newValue);
862
- };
863
- const parts = (0, react.useMemo)(() => new Intl.DateTimeFormat(locale, {
963
+ const id = (0, react.useMemo)(() => (0, nanoid.nanoid)(), []);
964
+ const [localValue, setLocalValue] = (0, react.useState)();
965
+ const commit = (0, react.useMemo)(() => debounce((localValue$1 = {}, value$1, onChange$1) => {
966
+ const date = buildDate(localValue$1, value$1 ?? void 0);
967
+ setLocalValue(void 0);
968
+ onChange$1(isNaN(date.getTime()) ? null : date);
969
+ }, 100), []);
970
+ const format = (0, react.useMemo)(() => new Intl.DateTimeFormat(locale, {
864
971
  day: "2-digit",
865
972
  month: "2-digit",
866
973
  year: "numeric"
867
- }), [locale]).formatToParts(value ?? defaultDate$1);
974
+ }), [locale]);
975
+ let parts;
976
+ try {
977
+ parts = format.formatToParts(value ?? defaultDate$1);
978
+ } catch {
979
+ parts = format.formatToParts(defaultDate$1);
980
+ }
868
981
  const isEmpty = !value;
869
982
  return /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)("div", {
870
983
  css: {
871
984
  display: "flex",
872
985
  alignItems: "baseline"
873
986
  },
874
- children: parts.map(({ type, value: value$1 }, index) => /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)(react.Fragment, { children: isIncludedType$1(type) ? /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)("input", {
875
- className: className$1,
987
+ children: parts.map(({ type, value: partValue }, index) => /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)(react.Fragment, { children: isIncludedType$1(type) ? /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)("input", {
988
+ className: `${className$1}-${id}`,
876
989
  css: {
877
990
  boxSizing: "content-box",
878
991
  overflow: "visible",
@@ -888,19 +1001,28 @@ function DateInput({ value, onChange, locale }) {
888
1001
  },
889
1002
  "&:focus": { borderBottom: "2px solid var(--primaryMain)" }
890
1003
  },
891
- style: { width: `${length$1(type, value$1)}ch` },
892
- placeholder: "".padEnd(length$1(type, value$1), "0"),
893
- value: override?.type === type ? override.value : !isEmpty ? value$1 : "",
1004
+ style: { width: `${String(maxValues$1[type]).length}ch` },
1005
+ placeholder: "".padEnd(String(maxValues$1[type]).length, "0"),
1006
+ value: localValue?.[type] ?? (isEmpty ? "" : partValue),
894
1007
  onChange: (event) => {
895
- setOverride({
896
- type,
897
- value: event.target.value
898
- });
899
- if (event.target.value.length >= maxLengths$1[type]) setTimeout(() => tabNext$1(event.target));
1008
+ const input = event.target.value;
1009
+ if (!/^\d*$/.test(input)) return;
1010
+ const newValue = {
1011
+ ...localValue,
1012
+ [type]: input
1013
+ };
1014
+ if (Number(input) > maxValues$1[type]) newValue[type] = String(maxValues$1[type]);
1015
+ setLocalValue(newValue);
1016
+ if (input.length >= String(maxValues$1[type]).length) setTimeout(() => tabNext$1(event.target, id));
1017
+ },
1018
+ onFocus: (event) => {
1019
+ commit.cancel();
1020
+ event.target.select();
900
1021
  },
901
- onFocus: (event) => event.target.select(),
902
- onBlur: commit
903
- }) : type === "literal" ? /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)("span", { children: value$1 }) : null }, index))
1022
+ onBlur: () => {
1023
+ commit(localValue, value, onChange);
1024
+ }
1025
+ }) : type === "literal" ? /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)("span", { children: partValue }) : null }, index))
904
1026
  });
905
1027
  }
906
1028
 
@@ -915,59 +1037,50 @@ function Text({ id }) {
915
1037
  const className = "schummar-table-time-input";
916
1038
  const defaultDate = new Date(1970, 0, 1);
917
1039
  const isIncludedType = (type) => type === "hour" || type === "minute" || type === "second";
918
- const defaultLengths = {
919
- hour: 2,
920
- minute: 2,
921
- second: 2
922
- };
923
- const maxLengths = {
924
- hour: 2,
925
- minute: 2,
926
- second: 2
1040
+ const maxValues = {
1041
+ hour: 23,
1042
+ minute: 59,
1043
+ second: 59
927
1044
  };
928
- const length = (type, value) => Math.max(value.length, defaultLengths[type]);
929
- const tabNext = (event) => {
930
- const all = Array.from(document.querySelectorAll(`.${className}`));
931
- const next = all[(all.indexOf(event) + 1) % all.length];
1045
+ const tabNext = (event, id) => {
1046
+ const all = Array.from(document.querySelectorAll(`.${className}-${id}`));
1047
+ const next = all[all.indexOf(event) + 1];
932
1048
  if (next instanceof HTMLElement) next.focus();
933
1049
  };
1050
+ function buildTime(value, baseDate = /* @__PURE__ */ new Date()) {
1051
+ const date = new Date(baseDate);
1052
+ if (value.hour) date.setHours(Number(value.hour));
1053
+ if (value.minute) date.setMinutes(Number(value.minute));
1054
+ if (value.second) date.setSeconds(Number(value.second));
1055
+ return date;
1056
+ }
934
1057
  function TimeInput({ value, onChange, locale, showSeconds = true }) {
935
- const [override, setOverride] = (0, react.useState)();
936
- const commit = () => {
937
- if (!override) return;
938
- setOverride(void 0);
939
- if (!override.value) {
940
- onChange(null);
941
- return;
942
- }
943
- const newValue = value ? new Date(value) : /* @__PURE__ */ new Date();
944
- switch (override.type) {
945
- case "hour":
946
- newValue.setHours(Number(override.value));
947
- break;
948
- case "minute":
949
- newValue.setMinutes(Number(override.value));
950
- break;
951
- case "second":
952
- newValue.setSeconds(Number(override.value));
953
- break;
954
- default: break;
955
- }
956
- onChange(newValue);
957
- };
958
- const parts = (0, react.useMemo)(() => new Intl.DateTimeFormat(locale, {
1058
+ const id = (0, react.useMemo)(() => (0, nanoid.nanoid)(), []);
1059
+ const [localValue, setLocalValue] = (0, react.useState)();
1060
+ const commit = (0, react.useMemo)(() => debounce((localValue$1 = {}, value$1, onChange$1) => {
1061
+ const date = buildTime(localValue$1, value$1 ?? void 0);
1062
+ setLocalValue(void 0);
1063
+ onChange$1(isNaN(date.getTime()) ? null : date);
1064
+ }, 100), []);
1065
+ const format = (0, react.useMemo)(() => new Intl.DateTimeFormat(locale, {
959
1066
  hour: "2-digit",
960
1067
  minute: "2-digit",
961
1068
  second: showSeconds ? "2-digit" : void 0
962
- }), [locale]).formatToParts(value ?? defaultDate);
1069
+ }), [locale]);
1070
+ let parts;
1071
+ try {
1072
+ parts = format.formatToParts(value ?? defaultDate);
1073
+ } catch {
1074
+ parts = format.formatToParts(defaultDate);
1075
+ }
963
1076
  const isEmpty = !value;
964
1077
  return /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)("div", {
965
1078
  css: {
966
1079
  display: "flex",
967
1080
  alignItems: "baseline"
968
1081
  },
969
- children: parts.map(({ type, value: value$1 }, index) => /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)(react.Fragment, { children: isIncludedType(type) ? /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)("input", {
970
- className,
1082
+ children: parts.map(({ type, value: partValue }, index) => /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)(react.Fragment, { children: isIncludedType(type) ? /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)("input", {
1083
+ className: `${className}-${id}`,
971
1084
  css: {
972
1085
  boxSizing: "content-box",
973
1086
  overflow: "visible",
@@ -983,19 +1096,28 @@ function TimeInput({ value, onChange, locale, showSeconds = true }) {
983
1096
  },
984
1097
  "&:focus": { borderBottom: "2px solid var(--primaryMain)" }
985
1098
  },
986
- style: { width: `${length(type, value$1)}ch` },
987
- placeholder: "".padEnd(length(type, value$1), "0"),
988
- value: override?.type === type ? override.value : !isEmpty ? value$1 : "",
1099
+ style: { width: `${String(maxValues[type]).length}ch` },
1100
+ placeholder: "".padEnd(String(maxValues[type]).length, "0"),
1101
+ value: localValue?.[type] ?? (isEmpty ? "" : partValue),
989
1102
  onChange: (event) => {
990
- setOverride({
991
- type,
992
- value: event.target.value
993
- });
994
- if (event.target.value.length >= maxLengths[type]) setTimeout(() => tabNext(event.target));
1103
+ const input = event.target.value;
1104
+ if (!/^\d*$/.test(input)) return;
1105
+ const newValue = {
1106
+ ...localValue,
1107
+ [type]: input
1108
+ };
1109
+ if (Number(input) > maxValues[type]) newValue[type] = String(maxValues[type]);
1110
+ setLocalValue(newValue);
1111
+ if (input.length >= String(maxValues[type]).length) setTimeout(() => tabNext(event.target, id));
995
1112
  },
996
- onFocus: (event) => event.target.select(),
997
- onBlur: commit
998
- }) : type === "literal" ? /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)("span", { children: value$1 }) : null }, index))
1113
+ onFocus: (event) => {
1114
+ commit.cancel();
1115
+ event.target.select();
1116
+ },
1117
+ onBlur: () => {
1118
+ commit(localValue, value, onChange);
1119
+ }
1120
+ }) : type === "literal" ? /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)("span", { children: partValue }) : null }, index))
999
1121
  });
1000
1122
  }
1001
1123
 
@@ -1284,20 +1406,20 @@ function DatePicker(props) {
1284
1406
  },
1285
1407
  children: [/* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)(DateInput, {
1286
1408
  value: min ?? null,
1287
- onChange: (date) => set("input", date ?? void 0, max, "min"),
1409
+ onChange: (newMin) => set("input", newMin ?? void 0, max, "min"),
1288
1410
  locale
1289
1411
  }), showTime && /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)(TimeInput, {
1290
1412
  value: min ?? null,
1291
- onChange: (date) => set("input", date ?? void 0, max, "min"),
1413
+ onChange: (newMin) => set("input", newMin ?? void 0, max, "min"),
1292
1414
  locale,
1293
1415
  showSeconds: typeof showTime === "boolean" ? true : showTime.showSeconds
1294
1416
  })] }), rangeSelect && /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsxs)(__emotion_react_jsx_runtime.Fragment, { children: [" - ", /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)(DateInput, {
1295
1417
  value: max ?? null,
1296
- onChange: (date) => set("input", min, date ?? void 0, "max"),
1418
+ onChange: (newMax) => set("input", min, newMax ?? void 0, "max"),
1297
1419
  locale
1298
1420
  }), showTime && /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)(TimeInput, {
1299
1421
  value: max ?? null,
1300
- onChange: (date) => set("input", min, date ?? void 0, "max"),
1422
+ onChange: (newMax) => set("input", min, newMax ?? void 0, "max"),
1301
1423
  locale,
1302
1424
  showSeconds: typeof showTime === "boolean" ? true : showTime.showSeconds
1303
1425
  })] })] })]
@@ -1460,7 +1582,7 @@ function convertDateOrArray(x) {
1460
1582
  return convertDateOrRange(x);
1461
1583
  }
1462
1584
  function DateFilter({ locale, firstDayOfWeek, defaultDateInView, quickOptions, singleSelect, filterBy = convertDateOrArray, minDate, maxDate, showCalendarWeek, showTime,...props }) {
1463
- const { value = null, onChange } = useFilter({
1585
+ const { value = null, onChange, close } = useFilter({
1464
1586
  ...props,
1465
1587
  filterBy,
1466
1588
  id: "dateFilter",
@@ -1479,7 +1601,10 @@ function DateFilter({ locale, firstDayOfWeek, defaultDateInView, quickOptions, s
1479
1601
  children: /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)(DatePicker, {
1480
1602
  rangeSelect: !singleSelect,
1481
1603
  value,
1482
- onChange,
1604
+ onChange: (value$1, source) => {
1605
+ onChange(value$1);
1606
+ if (source !== "input") close();
1607
+ },
1483
1608
  locale,
1484
1609
  firstDayOfWeek,
1485
1610
  defaultDateInView,
@@ -3512,7 +3637,7 @@ function TextFilter({ compare = textMatch, filterBy = asStringOrArray, placehold
3512
3637
  const IconButton$1 = useTheme((t) => t.components.IconButton);
3513
3638
  const Search$1 = useTheme((t) => t.icons.Search);
3514
3639
  const Clear$1 = useTheme((t) => t.icons.Clear);
3515
- const { value = "", onChange } = useFilter({
3640
+ const { value = "", onChange, close } = useFilter({
3516
3641
  ...props,
3517
3642
  filterBy,
3518
3643
  id: "textFilter",
@@ -3531,6 +3656,9 @@ function TextFilter({ compare = textMatch, filterBy = asStringOrArray, placehold
3531
3656
  children: /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)(AutoFocusTextField, {
3532
3657
  value,
3533
3658
  onChange: (event) => onChange(event.target.value),
3659
+ onKeyUp: (event) => {
3660
+ if (event.key === "Enter") close();
3661
+ },
3534
3662
  endIcon: /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)(IconButton$1, {
3535
3663
  onClick: () => onChange(""),
3536
3664
  children: !value ? /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)(Search$1, {}) : /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)(Clear$1, {})