schummar-table 0.47.2 → 0.48.1

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-BxCzVAiu.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
@@ -815,64 +937,67 @@ function defaults(first, ...more) {
815
937
  }, first);
816
938
  }
817
939
 
940
+ //#endregion
941
+ //#region src/hooks/useLatestRef.ts
942
+ function useLatestRef(value) {
943
+ const latestValue = (0, react.useRef)(value);
944
+ (0, react.useEffect)(() => {
945
+ latestValue.current = value;
946
+ }, [value]);
947
+ return latestValue;
948
+ }
949
+
818
950
  //#endregion
819
951
  //#region src/components/dateInput.tsx
820
952
  const className$1 = "schummar-table-date-input";
821
953
  const defaultDate$1 = new Date(1970, 0, 1);
822
954
  const isIncludedType$1 = (type) => type === "day" || type === "month" || type === "year";
823
- const defaultLengths$1 = {
824
- day: 2,
825
- month: 2,
826
- year: 4
955
+ const maxValues$1 = {
956
+ day: 31,
957
+ month: 12,
958
+ year: 9999
827
959
  };
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];
960
+ const tabNext$1 = (event, id) => {
961
+ const all = Array.from(document.querySelectorAll(`.${className$1}-${id}`));
962
+ const next = all[all.indexOf(event) + 1];
837
963
  if (next instanceof HTMLElement) next.focus();
838
964
  };
965
+ function buildDate(value, baseDate = /* @__PURE__ */ new Date()) {
966
+ const date = new Date(baseDate);
967
+ if (value.year) date.setFullYear(Number(value.year));
968
+ if (value.month) date.setMonth(Number(value.month) - 1);
969
+ if (value.day) date.setDate(Number(value.day));
970
+ return date;
971
+ }
839
972
  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, {
973
+ const id = (0, react.useMemo)(() => (0, nanoid.nanoid)(), []);
974
+ const [localValue, setLocalValue] = (0, react.useState)();
975
+ const latestValue = useLatestRef(value);
976
+ const commit = (0, react.useMemo)(() => debounce((localValue$1 = {}, value$1, onChange$1) => {
977
+ if (value$1 !== latestValue.current) return;
978
+ const date = buildDate(localValue$1, value$1 ?? void 0);
979
+ setLocalValue(void 0);
980
+ onChange$1(isNaN(date.getTime()) ? null : date);
981
+ }, 100), []);
982
+ const format = (0, react.useMemo)(() => new Intl.DateTimeFormat(locale, {
864
983
  day: "2-digit",
865
984
  month: "2-digit",
866
985
  year: "numeric"
867
- }), [locale]).formatToParts(value ?? defaultDate$1);
986
+ }), [locale]);
987
+ let parts;
988
+ try {
989
+ parts = format.formatToParts(value ?? defaultDate$1);
990
+ } catch {
991
+ parts = format.formatToParts(defaultDate$1);
992
+ }
868
993
  const isEmpty = !value;
869
994
  return /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)("div", {
870
995
  css: {
871
996
  display: "flex",
872
997
  alignItems: "baseline"
873
998
  },
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,
999
+ 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", {
1000
+ className: `${className$1}-${id}`,
876
1001
  css: {
877
1002
  boxSizing: "content-box",
878
1003
  overflow: "visible",
@@ -888,19 +1013,28 @@ function DateInput({ value, onChange, locale }) {
888
1013
  },
889
1014
  "&:focus": { borderBottom: "2px solid var(--primaryMain)" }
890
1015
  },
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 : "",
1016
+ style: { width: `${String(maxValues$1[type]).length}ch` },
1017
+ placeholder: "".padEnd(String(maxValues$1[type]).length, "0"),
1018
+ value: localValue?.[type] ?? (isEmpty ? "" : partValue),
894
1019
  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));
1020
+ const input = event.target.value;
1021
+ if (!/^\d*$/.test(input)) return;
1022
+ const newValue = {
1023
+ ...localValue,
1024
+ [type]: input
1025
+ };
1026
+ if (Number(input) > maxValues$1[type]) newValue[type] = String(maxValues$1[type]);
1027
+ setLocalValue(newValue);
1028
+ if (input.length >= String(maxValues$1[type]).length) setTimeout(() => tabNext$1(event.target, id));
1029
+ },
1030
+ onFocus: (event) => {
1031
+ commit.cancel();
1032
+ event.target.select();
900
1033
  },
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))
1034
+ onBlur: () => {
1035
+ commit(localValue, value, onChange);
1036
+ }
1037
+ }) : type === "literal" ? /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)("span", { children: partValue }) : null }, index))
904
1038
  });
905
1039
  }
906
1040
 
@@ -915,59 +1049,52 @@ function Text({ id }) {
915
1049
  const className = "schummar-table-time-input";
916
1050
  const defaultDate = new Date(1970, 0, 1);
917
1051
  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
1052
+ const maxValues = {
1053
+ hour: 23,
1054
+ minute: 59,
1055
+ second: 59
927
1056
  };
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];
1057
+ const tabNext = (event, id) => {
1058
+ const all = Array.from(document.querySelectorAll(`.${className}-${id}`));
1059
+ const next = all[all.indexOf(event) + 1];
932
1060
  if (next instanceof HTMLElement) next.focus();
933
1061
  };
1062
+ function buildTime(value, baseDate = /* @__PURE__ */ new Date()) {
1063
+ const date = new Date(baseDate);
1064
+ if (value.hour) date.setHours(Number(value.hour));
1065
+ if (value.minute) date.setMinutes(Number(value.minute));
1066
+ if (value.second) date.setSeconds(Number(value.second));
1067
+ return date;
1068
+ }
934
1069
  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, {
1070
+ const id = (0, react.useMemo)(() => (0, nanoid.nanoid)(), []);
1071
+ const [localValue, setLocalValue] = (0, react.useState)();
1072
+ const latestValue = useLatestRef(value);
1073
+ const commit = (0, react.useMemo)(() => debounce((localValue$1 = {}, value$1, onChange$1) => {
1074
+ if (value$1 !== latestValue.current) return;
1075
+ const date = buildTime(localValue$1, value$1 ?? void 0);
1076
+ setLocalValue(void 0);
1077
+ onChange$1(isNaN(date.getTime()) ? null : date);
1078
+ }, 100), []);
1079
+ const format = (0, react.useMemo)(() => new Intl.DateTimeFormat(locale, {
959
1080
  hour: "2-digit",
960
1081
  minute: "2-digit",
961
1082
  second: showSeconds ? "2-digit" : void 0
962
- }), [locale]).formatToParts(value ?? defaultDate);
1083
+ }), [locale]);
1084
+ let parts;
1085
+ try {
1086
+ parts = format.formatToParts(value ?? defaultDate);
1087
+ } catch {
1088
+ parts = format.formatToParts(defaultDate);
1089
+ }
963
1090
  const isEmpty = !value;
964
1091
  return /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)("div", {
965
1092
  css: {
966
1093
  display: "flex",
967
1094
  alignItems: "baseline"
968
1095
  },
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,
1096
+ 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", {
1097
+ className: `${className}-${id}`,
971
1098
  css: {
972
1099
  boxSizing: "content-box",
973
1100
  overflow: "visible",
@@ -983,19 +1110,28 @@ function TimeInput({ value, onChange, locale, showSeconds = true }) {
983
1110
  },
984
1111
  "&:focus": { borderBottom: "2px solid var(--primaryMain)" }
985
1112
  },
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 : "",
1113
+ style: { width: `${String(maxValues[type]).length}ch` },
1114
+ placeholder: "".padEnd(String(maxValues[type]).length, "0"),
1115
+ value: localValue?.[type] ?? (isEmpty ? "" : partValue),
989
1116
  onChange: (event) => {
990
- setOverride({
991
- type,
992
- value: event.target.value
993
- });
994
- if (event.target.value.length >= maxLengths[type]) setTimeout(() => tabNext(event.target));
1117
+ const input = event.target.value;
1118
+ if (!/^\d*$/.test(input)) return;
1119
+ const newValue = {
1120
+ ...localValue,
1121
+ [type]: input
1122
+ };
1123
+ if (Number(input) > maxValues[type]) newValue[type] = String(maxValues[type]);
1124
+ setLocalValue(newValue);
1125
+ if (input.length >= String(maxValues[type]).length) setTimeout(() => tabNext(event.target, id));
995
1126
  },
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))
1127
+ onFocus: (event) => {
1128
+ commit.cancel();
1129
+ event.target.select();
1130
+ },
1131
+ onBlur: () => {
1132
+ commit(localValue, value, onChange);
1133
+ }
1134
+ }) : type === "literal" ? /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)("span", { children: partValue }) : null }, index))
999
1135
  });
1000
1136
  }
1001
1137
 
@@ -1284,20 +1420,20 @@ function DatePicker(props) {
1284
1420
  },
1285
1421
  children: [/* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)(DateInput, {
1286
1422
  value: min ?? null,
1287
- onChange: (date) => set("input", date ?? void 0, max, "min"),
1423
+ onChange: (newMin) => set("input", newMin ?? void 0, max, "min"),
1288
1424
  locale
1289
1425
  }), showTime && /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)(TimeInput, {
1290
1426
  value: min ?? null,
1291
- onChange: (date) => set("input", date ?? void 0, max, "min"),
1427
+ onChange: (newMin) => set("input", newMin ?? void 0, max, "min"),
1292
1428
  locale,
1293
1429
  showSeconds: typeof showTime === "boolean" ? true : showTime.showSeconds
1294
1430
  })] }), 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
1431
  value: max ?? null,
1296
- onChange: (date) => set("input", min, date ?? void 0, "max"),
1432
+ onChange: (newMax) => set("input", min, newMax ?? void 0, "max"),
1297
1433
  locale
1298
1434
  }), showTime && /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)(TimeInput, {
1299
1435
  value: max ?? null,
1300
- onChange: (date) => set("input", min, date ?? void 0, "max"),
1436
+ onChange: (newMax) => set("input", min, newMax ?? void 0, "max"),
1301
1437
  locale,
1302
1438
  showSeconds: typeof showTime === "boolean" ? true : showTime.showSeconds
1303
1439
  })] })] })]
@@ -1460,7 +1596,7 @@ function convertDateOrArray(x) {
1460
1596
  return convertDateOrRange(x);
1461
1597
  }
1462
1598
  function DateFilter({ locale, firstDayOfWeek, defaultDateInView, quickOptions, singleSelect, filterBy = convertDateOrArray, minDate, maxDate, showCalendarWeek, showTime,...props }) {
1463
- const { value = null, onChange } = useFilter({
1599
+ const { value = null, onChange, close } = useFilter({
1464
1600
  ...props,
1465
1601
  filterBy,
1466
1602
  id: "dateFilter",
@@ -1479,7 +1615,10 @@ function DateFilter({ locale, firstDayOfWeek, defaultDateInView, quickOptions, s
1479
1615
  children: /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)(DatePicker, {
1480
1616
  rangeSelect: !singleSelect,
1481
1617
  value,
1482
- onChange,
1618
+ onChange: (value$1, source) => {
1619
+ onChange(value$1);
1620
+ if (source !== "input") close();
1621
+ },
1483
1622
  locale,
1484
1623
  firstDayOfWeek,
1485
1624
  defaultDateInView,
@@ -3512,7 +3651,7 @@ function TextFilter({ compare = textMatch, filterBy = asStringOrArray, placehold
3512
3651
  const IconButton$1 = useTheme((t) => t.components.IconButton);
3513
3652
  const Search$1 = useTheme((t) => t.icons.Search);
3514
3653
  const Clear$1 = useTheme((t) => t.icons.Clear);
3515
- const { value = "", onChange } = useFilter({
3654
+ const { value = "", onChange, close } = useFilter({
3516
3655
  ...props,
3517
3656
  filterBy,
3518
3657
  id: "textFilter",
@@ -3531,6 +3670,9 @@ function TextFilter({ compare = textMatch, filterBy = asStringOrArray, placehold
3531
3670
  children: /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)(AutoFocusTextField, {
3532
3671
  value,
3533
3672
  onChange: (event) => onChange(event.target.value),
3673
+ onKeyUp: (event) => {
3674
+ if (event.key === "Enter") close();
3675
+ },
3534
3676
  endIcon: /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)(IconButton$1, {
3535
3677
  onClick: () => onChange(""),
3536
3678
  children: !value ? /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)(Search$1, {}) : /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsx)(Clear$1, {})