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 +283 -155
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +13 -13
- package/dist/index.js +283 -155
- package/dist/index.js.map +1 -1
- package/dist/mui4Theme.cjs +1 -1
- package/dist/mui4Theme.d.cts +1 -1
- package/dist/mui4Theme.d.ts +1 -1
- package/dist/mui4Theme.js +1 -1
- package/dist/mui5Theme.cjs +1 -1
- package/dist/mui5Theme.d.cts +1 -1
- package/dist/mui5Theme.d.ts +1 -1
- package/dist/mui5Theme.js +1 -1
- package/dist/{tableSettings-CmqSZu-Q.cjs → tableSettings-C450XPgW.cjs} +28 -17
- package/dist/{tableSettings-CmqSZu-Q.cjs.map → tableSettings-C450XPgW.cjs.map} +1 -1
- package/dist/{tableSettings-C_spVpBs.js → tableSettings-DFnt2SZO.js} +28 -17
- package/dist/{tableSettings-C_spVpBs.js.map → tableSettings-DFnt2SZO.js.map} +1 -1
- package/dist/{types-lBtXAU-l.d.cts → types-DzYx_oT1.d.cts} +4 -1
- package/dist/{types-CemO-cBr.d.ts → types-k3mbd-dT.d.ts} +4 -1
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __export } from "./chunk-CTAAG5j7.js";
|
|
2
|
-
import { Popover, Store, StoreScope, TableSettingsContext, TableSettingsProvider, configureTableTheme, defaultClasses, globalTableTheme, mergeThemes, throttle } from "./tableSettings-
|
|
2
|
+
import { Popover, Store, StoreScope, TableSettingsContext, TableSettingsProvider, configureTableTheme, defaultClasses, globalTableTheme, mergeThemes, throttle } from "./tableSettings-DFnt2SZO.js";
|
|
3
3
|
import "./csvExporter-DRm4V8We.js";
|
|
4
4
|
import { Fragment, cloneElement, createContext, forwardRef, memo, useContext, useEffect, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
5
5
|
import { castDraft } from "immer";
|
|
@@ -565,12 +565,15 @@ const FilterControlContext = createContext({
|
|
|
565
565
|
isActive: false,
|
|
566
566
|
close: () => void 0
|
|
567
567
|
});
|
|
568
|
-
function FilterControl(
|
|
568
|
+
function FilterControl() {
|
|
569
569
|
const table = useTableContext();
|
|
570
570
|
const columnId = useColumnContext();
|
|
571
571
|
const Popover$1 = useTheme((t) => t.components.Popover);
|
|
572
572
|
const classes = useTheme((t) => t.classes);
|
|
573
573
|
const styles = useTheme((t) => t.styles);
|
|
574
|
+
const IconButton$1 = useTheme((t) => t.components.IconButton);
|
|
575
|
+
const FilterList$1 = useTheme((t) => t.icons.FilterList);
|
|
576
|
+
const ArrowDropDown$1 = useTheme((t) => t.icons.ArrowDropDown);
|
|
574
577
|
const cssVariables = useCssVariables();
|
|
575
578
|
const [anchor, setAnchor] = useState(null);
|
|
576
579
|
const isActive = table.useState((state) => {
|
|
@@ -589,21 +592,24 @@ function FilterControl({ component: Component = DefaultButton, onClose }) {
|
|
|
589
592
|
state.filterValues.delete(columnId);
|
|
590
593
|
});
|
|
591
594
|
}
|
|
592
|
-
const context = useMemo(() => ({
|
|
593
|
-
isActive: !!anchor,
|
|
594
|
-
close: () => setAnchor(null)
|
|
595
|
-
}), [anchor]);
|
|
596
595
|
if (!filter) return null;
|
|
596
|
+
function close() {
|
|
597
|
+
setAnchor(null);
|
|
598
|
+
}
|
|
597
599
|
return /* @__PURE__ */ jsxs(FilterControlContext.Provider, {
|
|
598
|
-
value:
|
|
599
|
-
|
|
600
|
+
value: {
|
|
601
|
+
isActive: !!anchor,
|
|
602
|
+
close
|
|
603
|
+
},
|
|
604
|
+
children: [/* @__PURE__ */ jsx(IconButton$1, {
|
|
600
605
|
onClick: (event) => setAnchor(event.currentTarget),
|
|
601
606
|
onContextMenu: (event) => {
|
|
602
607
|
reset();
|
|
603
608
|
event.preventDefault();
|
|
604
609
|
return false;
|
|
605
610
|
},
|
|
606
|
-
isActive
|
|
611
|
+
css: [{ color: "#b0bac9" }, isActive && { color: "var(--primaryMain) !important" }],
|
|
612
|
+
children: isActive ? /* @__PURE__ */ jsx(FilterList$1, {}) : /* @__PURE__ */ jsx(ArrowDropDown$1, {})
|
|
607
613
|
}), /* @__PURE__ */ jsx("div", {
|
|
608
614
|
onPointerDown: (event) => {
|
|
609
615
|
event.stopPropagation();
|
|
@@ -614,10 +620,7 @@ function FilterControl({ component: Component = DefaultButton, onClose }) {
|
|
|
614
620
|
children: /* @__PURE__ */ jsx(ClassNames, { children: ({ css: css$1, cx: cx$1 }) => /* @__PURE__ */ jsx(Popover$1, {
|
|
615
621
|
open: true,
|
|
616
622
|
hidden: !anchor,
|
|
617
|
-
onClose:
|
|
618
|
-
setAnchor(null);
|
|
619
|
-
onClose?.();
|
|
620
|
-
},
|
|
623
|
+
onClose: close,
|
|
621
624
|
anchorEl: anchor ?? document.body,
|
|
622
625
|
css: [cssVariables, styles?.popover],
|
|
623
626
|
className: cx$1(classes?.popover, filterClassNames?.popover),
|
|
@@ -627,16 +630,6 @@ function FilterControl({ component: Component = DefaultButton, onClose }) {
|
|
|
627
630
|
})]
|
|
628
631
|
});
|
|
629
632
|
}
|
|
630
|
-
function DefaultButton({ isActive,...props }) {
|
|
631
|
-
const IconButton$1 = useTheme((t) => t.components.IconButton);
|
|
632
|
-
const FilterList$1 = useTheme((t) => t.icons.FilterList);
|
|
633
|
-
const ArrowDropDown$1 = useTheme((t) => t.icons.ArrowDropDown);
|
|
634
|
-
return /* @__PURE__ */ jsx(IconButton$1, {
|
|
635
|
-
...props,
|
|
636
|
-
css: [{ color: "#b0bac9" }, isActive && { color: "var(--primaryMain) !important" }],
|
|
637
|
-
children: isActive ? /* @__PURE__ */ jsx(FilterList$1, {}) : /* @__PURE__ */ jsx(ArrowDropDown$1, {})
|
|
638
|
-
});
|
|
639
|
-
}
|
|
640
633
|
|
|
641
634
|
//#endregion
|
|
642
635
|
//#region src/components/autoFocusTextField.tsx
|
|
@@ -672,12 +665,21 @@ function debounce(function_, ms) {
|
|
|
672
665
|
lastArgs = args;
|
|
673
666
|
if (timeout) clearTimeout(timeout);
|
|
674
667
|
timeout = setTimeout(run, ms);
|
|
675
|
-
}, {
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
668
|
+
}, {
|
|
669
|
+
flush() {
|
|
670
|
+
if (timeout) {
|
|
671
|
+
clearTimeout(timeout);
|
|
672
|
+
run();
|
|
673
|
+
}
|
|
674
|
+
},
|
|
675
|
+
cancel() {
|
|
676
|
+
if (timeout) {
|
|
677
|
+
clearTimeout(timeout);
|
|
678
|
+
timeout = void 0;
|
|
679
|
+
lastArgs = void 0;
|
|
680
|
+
}
|
|
679
681
|
}
|
|
680
|
-
}
|
|
682
|
+
});
|
|
681
683
|
}
|
|
682
684
|
|
|
683
685
|
//#endregion
|
|
@@ -742,6 +744,143 @@ function useFilter(impl) {
|
|
|
742
744
|
};
|
|
743
745
|
}
|
|
744
746
|
|
|
747
|
+
//#endregion
|
|
748
|
+
//#region src/components/filterDialog.tsx
|
|
749
|
+
var filterDialog_default = forwardRef(FilterDialog);
|
|
750
|
+
function FilterDialog(_props, ref) {
|
|
751
|
+
const table = useTableContext();
|
|
752
|
+
const columnId = useColumnContext();
|
|
753
|
+
const classes = useTheme((t) => t.classes);
|
|
754
|
+
const styles = useTheme((t) => t.styles);
|
|
755
|
+
const IconButton$1 = useTheme((t) => t.components.IconButton);
|
|
756
|
+
const FilterList$1 = useTheme((t) => t.icons.FilterList);
|
|
757
|
+
const filter = table.useState((state) => state.activeColumns.find((column) => column.id === columnId)?.filter);
|
|
758
|
+
const label = table.useState((state) => {
|
|
759
|
+
return state.activeColumns.find((column) => column.id === columnId)?.header ?? null;
|
|
760
|
+
});
|
|
761
|
+
const isActive = table.useState((state) => {
|
|
762
|
+
const filter$1 = state.filters.get(columnId);
|
|
763
|
+
const filterValue = state.filterValues.get(columnId);
|
|
764
|
+
return filter$1 !== void 0 && filterValue !== void 0 && filter$1.isActive(filterValue);
|
|
765
|
+
});
|
|
766
|
+
const { close } = useContext(FilterControlContext);
|
|
767
|
+
return /* @__PURE__ */ jsx("dialog", {
|
|
768
|
+
ref,
|
|
769
|
+
onClick: close,
|
|
770
|
+
className: classes?.dialog,
|
|
771
|
+
css: [{
|
|
772
|
+
padding: 0,
|
|
773
|
+
border: "none",
|
|
774
|
+
borderRadius: 4,
|
|
775
|
+
"::backdrop": { backgroundColor: "rgba(0, 0, 0, 0.7)" }
|
|
776
|
+
}, styles?.dialog],
|
|
777
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
778
|
+
onClick: (e) => e.stopPropagation(),
|
|
779
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
780
|
+
css: {
|
|
781
|
+
position: "relative",
|
|
782
|
+
padding: 10,
|
|
783
|
+
display: "flex",
|
|
784
|
+
justifyContent: "center",
|
|
785
|
+
alignItems: "center",
|
|
786
|
+
gap: 10
|
|
787
|
+
},
|
|
788
|
+
children: [
|
|
789
|
+
/* @__PURE__ */ jsx(FilterList$1, { css: { color: isActive ? "var(--primaryMain)" : "#b0bac9" } }),
|
|
790
|
+
/* @__PURE__ */ jsx("div", {
|
|
791
|
+
css: {
|
|
792
|
+
whiteSpace: "nowrap",
|
|
793
|
+
overflow: "hidden",
|
|
794
|
+
textOverflow: "ellipsis",
|
|
795
|
+
paddingRight: "2em"
|
|
796
|
+
},
|
|
797
|
+
children: label
|
|
798
|
+
}),
|
|
799
|
+
/* @__PURE__ */ jsx(IconButton$1, {
|
|
800
|
+
onClick: close,
|
|
801
|
+
css: {
|
|
802
|
+
position: "absolute",
|
|
803
|
+
right: 0,
|
|
804
|
+
top: 0,
|
|
805
|
+
fontSize: "1em",
|
|
806
|
+
padding: "0.5em",
|
|
807
|
+
margin: "0.5em",
|
|
808
|
+
lineHeight: 1
|
|
809
|
+
},
|
|
810
|
+
children: "✕"
|
|
811
|
+
})
|
|
812
|
+
]
|
|
813
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
814
|
+
css: { overflow: "auto" },
|
|
815
|
+
children: filter
|
|
816
|
+
})]
|
|
817
|
+
})
|
|
818
|
+
});
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
//#endregion
|
|
822
|
+
//#region src/components/nestedFilterControl.tsx
|
|
823
|
+
function NestedFilterControl() {
|
|
824
|
+
const table = useTableContext();
|
|
825
|
+
const columnId = useColumnContext();
|
|
826
|
+
const Button$1 = useTheme((t) => t.components.Button);
|
|
827
|
+
const FilterList$1 = useTheme((t) => t.icons.FilterList);
|
|
828
|
+
const dialog = useRef(null);
|
|
829
|
+
const label = table.useState((state) => {
|
|
830
|
+
return state.activeColumns.find((column) => column.id === columnId)?.header ?? null;
|
|
831
|
+
});
|
|
832
|
+
const isActive = table.useState((state) => {
|
|
833
|
+
const filter$1 = state.filters.get(columnId);
|
|
834
|
+
const filterValue = state.filterValues.get(columnId);
|
|
835
|
+
return filter$1 !== void 0 && filterValue !== void 0 && filter$1.isActive(filterValue);
|
|
836
|
+
});
|
|
837
|
+
const filter = table.useState((state) => state.activeColumns.find((column) => column.id === columnId)?.filter);
|
|
838
|
+
useEffect(() => () => {
|
|
839
|
+
dialog.current?.close();
|
|
840
|
+
}, []);
|
|
841
|
+
if (!filter) return null;
|
|
842
|
+
function reset() {
|
|
843
|
+
const impl = table.getState().filters.get(columnId);
|
|
844
|
+
impl?.onChange?.(void 0);
|
|
845
|
+
if (impl?.value === void 0) table.update((state) => {
|
|
846
|
+
state.filterValues.delete(columnId);
|
|
847
|
+
});
|
|
848
|
+
}
|
|
849
|
+
const parentContext = useContext(FilterControlContext);
|
|
850
|
+
function close() {
|
|
851
|
+
dialog.current?.close();
|
|
852
|
+
parentContext.close();
|
|
853
|
+
}
|
|
854
|
+
return /* @__PURE__ */ jsxs(FilterControlContext.Provider, {
|
|
855
|
+
value: {
|
|
856
|
+
isActive: true,
|
|
857
|
+
close
|
|
858
|
+
},
|
|
859
|
+
children: [/* @__PURE__ */ jsx(Button$1, {
|
|
860
|
+
onClick: () => dialog.current?.showModal(),
|
|
861
|
+
onContextMenu: (event) => {
|
|
862
|
+
reset();
|
|
863
|
+
event.preventDefault();
|
|
864
|
+
return false;
|
|
865
|
+
},
|
|
866
|
+
startIcon: /* @__PURE__ */ jsx(FilterList$1, { css: { color: isActive ? "var(--primaryMain)" : "#b0bac9" } }),
|
|
867
|
+
css: {
|
|
868
|
+
width: "100%",
|
|
869
|
+
color: isActive ? "var(--primaryMain)" : "var(--color-text)"
|
|
870
|
+
},
|
|
871
|
+
children: label
|
|
872
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
873
|
+
onPointerDown: (event) => {
|
|
874
|
+
event.stopPropagation();
|
|
875
|
+
},
|
|
876
|
+
onPointerMove: (event) => {
|
|
877
|
+
event.stopPropagation();
|
|
878
|
+
},
|
|
879
|
+
children: /* @__PURE__ */ jsx(filterDialog_default, { ref: dialog })
|
|
880
|
+
})]
|
|
881
|
+
});
|
|
882
|
+
}
|
|
883
|
+
|
|
745
884
|
//#endregion
|
|
746
885
|
//#region src/components/combinedFilter.tsx
|
|
747
886
|
function CombinedFilter({ columnIds: inputColumnIds,...props }) {
|
|
@@ -778,26 +917,9 @@ function CombinedFilter({ columnIds: inputColumnIds,...props }) {
|
|
|
778
917
|
});
|
|
779
918
|
return /* @__PURE__ */ jsx("div", { children: columnIds.map((columnId) => /* @__PURE__ */ jsx(ColumnContext.Provider, {
|
|
780
919
|
value: columnId,
|
|
781
|
-
children: /* @__PURE__ */ jsx(
|
|
920
|
+
children: /* @__PURE__ */ jsx(NestedFilterControl, {})
|
|
782
921
|
}, columnId)) });
|
|
783
922
|
}
|
|
784
|
-
function Filter({ isActive,...props }) {
|
|
785
|
-
const table = useTableContext();
|
|
786
|
-
const columnId = useColumnContext();
|
|
787
|
-
const FilterList$1 = useTheme((t) => t.icons.FilterList);
|
|
788
|
-
const label = table.useState((state) => {
|
|
789
|
-
return state.activeColumns.find((column) => column.id === columnId)?.header ?? null;
|
|
790
|
-
});
|
|
791
|
-
return /* @__PURE__ */ jsx(useTheme((t) => t.components.Button), {
|
|
792
|
-
...props,
|
|
793
|
-
startIcon: /* @__PURE__ */ jsx(FilterList$1, { css: { color: isActive ? "var(--primaryMain)" : "#b0bac9" } }),
|
|
794
|
-
css: {
|
|
795
|
-
width: "100%",
|
|
796
|
-
color: isActive ? "var(--primaryMain)" : "var(--color-text)"
|
|
797
|
-
},
|
|
798
|
-
children: label
|
|
799
|
-
});
|
|
800
|
-
}
|
|
801
923
|
|
|
802
924
|
//#endregion
|
|
803
925
|
//#region src/misc/defaults.ts
|
|
@@ -814,59 +936,50 @@ function defaults(first, ...more) {
|
|
|
814
936
|
const className$1 = "schummar-table-date-input";
|
|
815
937
|
const defaultDate$1 = new Date(1970, 0, 1);
|
|
816
938
|
const isIncludedType$1 = (type) => type === "day" || type === "month" || type === "year";
|
|
817
|
-
const
|
|
818
|
-
day:
|
|
819
|
-
month:
|
|
820
|
-
year:
|
|
939
|
+
const maxValues$1 = {
|
|
940
|
+
day: 31,
|
|
941
|
+
month: 12,
|
|
942
|
+
year: 9999
|
|
821
943
|
};
|
|
822
|
-
const
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
year: Number.POSITIVE_INFINITY
|
|
826
|
-
};
|
|
827
|
-
const length$1 = (type, value) => Math.max(value.length, defaultLengths$1[type]);
|
|
828
|
-
const tabNext$1 = (event) => {
|
|
829
|
-
const all = Array.from(document.querySelectorAll(`.${className$1}`));
|
|
830
|
-
const next = all[(all.indexOf(event) + 1) % all.length];
|
|
944
|
+
const tabNext$1 = (event, id) => {
|
|
945
|
+
const all = Array.from(document.querySelectorAll(`.${className$1}-${id}`));
|
|
946
|
+
const next = all[all.indexOf(event) + 1];
|
|
831
947
|
if (next instanceof HTMLElement) next.focus();
|
|
832
948
|
};
|
|
949
|
+
function buildDate(value, baseDate = /* @__PURE__ */ new Date()) {
|
|
950
|
+
const date = new Date(baseDate);
|
|
951
|
+
if (value.year) date.setFullYear(Number(value.year));
|
|
952
|
+
if (value.month) date.setMonth(Number(value.month) - 1);
|
|
953
|
+
if (value.day) date.setDate(Number(value.day));
|
|
954
|
+
return date;
|
|
955
|
+
}
|
|
833
956
|
function DateInput({ value, onChange, locale }) {
|
|
834
|
-
const
|
|
835
|
-
const
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
const newValue = value ? new Date(value) : /* @__PURE__ */ new Date();
|
|
843
|
-
switch (override.type) {
|
|
844
|
-
case "day":
|
|
845
|
-
newValue.setDate(Number(override.value));
|
|
846
|
-
break;
|
|
847
|
-
case "month":
|
|
848
|
-
newValue.setMonth(Number(override.value) - 1);
|
|
849
|
-
break;
|
|
850
|
-
case "year":
|
|
851
|
-
newValue.setFullYear(Number(override.value));
|
|
852
|
-
break;
|
|
853
|
-
default: break;
|
|
854
|
-
}
|
|
855
|
-
onChange(newValue);
|
|
856
|
-
};
|
|
857
|
-
const parts = useMemo(() => new Intl.DateTimeFormat(locale, {
|
|
957
|
+
const id = useMemo(() => nanoid(), []);
|
|
958
|
+
const [localValue, setLocalValue] = useState();
|
|
959
|
+
const commit = useMemo(() => debounce((localValue$1 = {}, value$1, onChange$1) => {
|
|
960
|
+
const date = buildDate(localValue$1, value$1 ?? void 0);
|
|
961
|
+
setLocalValue(void 0);
|
|
962
|
+
onChange$1(isNaN(date.getTime()) ? null : date);
|
|
963
|
+
}, 100), []);
|
|
964
|
+
const format = useMemo(() => new Intl.DateTimeFormat(locale, {
|
|
858
965
|
day: "2-digit",
|
|
859
966
|
month: "2-digit",
|
|
860
967
|
year: "numeric"
|
|
861
|
-
}), [locale])
|
|
968
|
+
}), [locale]);
|
|
969
|
+
let parts;
|
|
970
|
+
try {
|
|
971
|
+
parts = format.formatToParts(value ?? defaultDate$1);
|
|
972
|
+
} catch {
|
|
973
|
+
parts = format.formatToParts(defaultDate$1);
|
|
974
|
+
}
|
|
862
975
|
const isEmpty = !value;
|
|
863
976
|
return /* @__PURE__ */ jsx("div", {
|
|
864
977
|
css: {
|
|
865
978
|
display: "flex",
|
|
866
979
|
alignItems: "baseline"
|
|
867
980
|
},
|
|
868
|
-
children: parts.map(({ type, value:
|
|
869
|
-
className: className$1
|
|
981
|
+
children: parts.map(({ type, value: partValue }, index) => /* @__PURE__ */ jsx(Fragment, { children: isIncludedType$1(type) ? /* @__PURE__ */ jsx("input", {
|
|
982
|
+
className: `${className$1}-${id}`,
|
|
870
983
|
css: {
|
|
871
984
|
boxSizing: "content-box",
|
|
872
985
|
overflow: "visible",
|
|
@@ -882,19 +995,28 @@ function DateInput({ value, onChange, locale }) {
|
|
|
882
995
|
},
|
|
883
996
|
"&:focus": { borderBottom: "2px solid var(--primaryMain)" }
|
|
884
997
|
},
|
|
885
|
-
style: { width: `${
|
|
886
|
-
placeholder: "".padEnd(
|
|
887
|
-
value:
|
|
998
|
+
style: { width: `${String(maxValues$1[type]).length}ch` },
|
|
999
|
+
placeholder: "".padEnd(String(maxValues$1[type]).length, "0"),
|
|
1000
|
+
value: localValue?.[type] ?? (isEmpty ? "" : partValue),
|
|
888
1001
|
onChange: (event) => {
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
1002
|
+
const input = event.target.value;
|
|
1003
|
+
if (!/^\d*$/.test(input)) return;
|
|
1004
|
+
const newValue = {
|
|
1005
|
+
...localValue,
|
|
1006
|
+
[type]: input
|
|
1007
|
+
};
|
|
1008
|
+
if (Number(input) > maxValues$1[type]) newValue[type] = String(maxValues$1[type]);
|
|
1009
|
+
setLocalValue(newValue);
|
|
1010
|
+
if (input.length >= String(maxValues$1[type]).length) setTimeout(() => tabNext$1(event.target, id));
|
|
1011
|
+
},
|
|
1012
|
+
onFocus: (event) => {
|
|
1013
|
+
commit.cancel();
|
|
1014
|
+
event.target.select();
|
|
894
1015
|
},
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
1016
|
+
onBlur: () => {
|
|
1017
|
+
commit(localValue, value, onChange);
|
|
1018
|
+
}
|
|
1019
|
+
}) : type === "literal" ? /* @__PURE__ */ jsx("span", { children: partValue }) : null }, index))
|
|
898
1020
|
});
|
|
899
1021
|
}
|
|
900
1022
|
|
|
@@ -909,59 +1031,50 @@ function Text({ id }) {
|
|
|
909
1031
|
const className = "schummar-table-time-input";
|
|
910
1032
|
const defaultDate = new Date(1970, 0, 1);
|
|
911
1033
|
const isIncludedType = (type) => type === "hour" || type === "minute" || type === "second";
|
|
912
|
-
const
|
|
913
|
-
hour:
|
|
914
|
-
minute:
|
|
915
|
-
second:
|
|
916
|
-
};
|
|
917
|
-
const maxLengths = {
|
|
918
|
-
hour: 2,
|
|
919
|
-
minute: 2,
|
|
920
|
-
second: 2
|
|
1034
|
+
const maxValues = {
|
|
1035
|
+
hour: 23,
|
|
1036
|
+
minute: 59,
|
|
1037
|
+
second: 59
|
|
921
1038
|
};
|
|
922
|
-
const
|
|
923
|
-
const
|
|
924
|
-
const
|
|
925
|
-
const next = all[(all.indexOf(event) + 1) % all.length];
|
|
1039
|
+
const tabNext = (event, id) => {
|
|
1040
|
+
const all = Array.from(document.querySelectorAll(`.${className}-${id}`));
|
|
1041
|
+
const next = all[all.indexOf(event) + 1];
|
|
926
1042
|
if (next instanceof HTMLElement) next.focus();
|
|
927
1043
|
};
|
|
1044
|
+
function buildTime(value, baseDate = /* @__PURE__ */ new Date()) {
|
|
1045
|
+
const date = new Date(baseDate);
|
|
1046
|
+
if (value.hour) date.setHours(Number(value.hour));
|
|
1047
|
+
if (value.minute) date.setMinutes(Number(value.minute));
|
|
1048
|
+
if (value.second) date.setSeconds(Number(value.second));
|
|
1049
|
+
return date;
|
|
1050
|
+
}
|
|
928
1051
|
function TimeInput({ value, onChange, locale, showSeconds = true }) {
|
|
929
|
-
const
|
|
930
|
-
const
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
const newValue = value ? new Date(value) : /* @__PURE__ */ new Date();
|
|
938
|
-
switch (override.type) {
|
|
939
|
-
case "hour":
|
|
940
|
-
newValue.setHours(Number(override.value));
|
|
941
|
-
break;
|
|
942
|
-
case "minute":
|
|
943
|
-
newValue.setMinutes(Number(override.value));
|
|
944
|
-
break;
|
|
945
|
-
case "second":
|
|
946
|
-
newValue.setSeconds(Number(override.value));
|
|
947
|
-
break;
|
|
948
|
-
default: break;
|
|
949
|
-
}
|
|
950
|
-
onChange(newValue);
|
|
951
|
-
};
|
|
952
|
-
const parts = useMemo(() => new Intl.DateTimeFormat(locale, {
|
|
1052
|
+
const id = useMemo(() => nanoid(), []);
|
|
1053
|
+
const [localValue, setLocalValue] = useState();
|
|
1054
|
+
const commit = useMemo(() => debounce((localValue$1 = {}, value$1, onChange$1) => {
|
|
1055
|
+
const date = buildTime(localValue$1, value$1 ?? void 0);
|
|
1056
|
+
setLocalValue(void 0);
|
|
1057
|
+
onChange$1(isNaN(date.getTime()) ? null : date);
|
|
1058
|
+
}, 100), []);
|
|
1059
|
+
const format = useMemo(() => new Intl.DateTimeFormat(locale, {
|
|
953
1060
|
hour: "2-digit",
|
|
954
1061
|
minute: "2-digit",
|
|
955
1062
|
second: showSeconds ? "2-digit" : void 0
|
|
956
|
-
}), [locale])
|
|
1063
|
+
}), [locale]);
|
|
1064
|
+
let parts;
|
|
1065
|
+
try {
|
|
1066
|
+
parts = format.formatToParts(value ?? defaultDate);
|
|
1067
|
+
} catch {
|
|
1068
|
+
parts = format.formatToParts(defaultDate);
|
|
1069
|
+
}
|
|
957
1070
|
const isEmpty = !value;
|
|
958
1071
|
return /* @__PURE__ */ jsx("div", {
|
|
959
1072
|
css: {
|
|
960
1073
|
display: "flex",
|
|
961
1074
|
alignItems: "baseline"
|
|
962
1075
|
},
|
|
963
|
-
children: parts.map(({ type, value:
|
|
964
|
-
className
|
|
1076
|
+
children: parts.map(({ type, value: partValue }, index) => /* @__PURE__ */ jsx(Fragment, { children: isIncludedType(type) ? /* @__PURE__ */ jsx("input", {
|
|
1077
|
+
className: `${className}-${id}`,
|
|
965
1078
|
css: {
|
|
966
1079
|
boxSizing: "content-box",
|
|
967
1080
|
overflow: "visible",
|
|
@@ -977,19 +1090,28 @@ function TimeInput({ value, onChange, locale, showSeconds = true }) {
|
|
|
977
1090
|
},
|
|
978
1091
|
"&:focus": { borderBottom: "2px solid var(--primaryMain)" }
|
|
979
1092
|
},
|
|
980
|
-
style: { width: `${
|
|
981
|
-
placeholder: "".padEnd(
|
|
982
|
-
value:
|
|
1093
|
+
style: { width: `${String(maxValues[type]).length}ch` },
|
|
1094
|
+
placeholder: "".padEnd(String(maxValues[type]).length, "0"),
|
|
1095
|
+
value: localValue?.[type] ?? (isEmpty ? "" : partValue),
|
|
983
1096
|
onChange: (event) => {
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
1097
|
+
const input = event.target.value;
|
|
1098
|
+
if (!/^\d*$/.test(input)) return;
|
|
1099
|
+
const newValue = {
|
|
1100
|
+
...localValue,
|
|
1101
|
+
[type]: input
|
|
1102
|
+
};
|
|
1103
|
+
if (Number(input) > maxValues[type]) newValue[type] = String(maxValues[type]);
|
|
1104
|
+
setLocalValue(newValue);
|
|
1105
|
+
if (input.length >= String(maxValues[type]).length) setTimeout(() => tabNext(event.target, id));
|
|
989
1106
|
},
|
|
990
|
-
onFocus: (event) =>
|
|
991
|
-
|
|
992
|
-
|
|
1107
|
+
onFocus: (event) => {
|
|
1108
|
+
commit.cancel();
|
|
1109
|
+
event.target.select();
|
|
1110
|
+
},
|
|
1111
|
+
onBlur: () => {
|
|
1112
|
+
commit(localValue, value, onChange);
|
|
1113
|
+
}
|
|
1114
|
+
}) : type === "literal" ? /* @__PURE__ */ jsx("span", { children: partValue }) : null }, index))
|
|
993
1115
|
});
|
|
994
1116
|
}
|
|
995
1117
|
|
|
@@ -1278,20 +1400,20 @@ function DatePicker(props) {
|
|
|
1278
1400
|
},
|
|
1279
1401
|
children: [/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx(DateInput, {
|
|
1280
1402
|
value: min ?? null,
|
|
1281
|
-
onChange: (
|
|
1403
|
+
onChange: (newMin) => set("input", newMin ?? void 0, max, "min"),
|
|
1282
1404
|
locale
|
|
1283
1405
|
}), showTime && /* @__PURE__ */ jsx(TimeInput, {
|
|
1284
1406
|
value: min ?? null,
|
|
1285
|
-
onChange: (
|
|
1407
|
+
onChange: (newMin) => set("input", newMin ?? void 0, max, "min"),
|
|
1286
1408
|
locale,
|
|
1287
1409
|
showSeconds: typeof showTime === "boolean" ? true : showTime.showSeconds
|
|
1288
1410
|
})] }), rangeSelect && /* @__PURE__ */ jsxs(Fragment$1, { children: [" - ", /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx(DateInput, {
|
|
1289
1411
|
value: max ?? null,
|
|
1290
|
-
onChange: (
|
|
1412
|
+
onChange: (newMax) => set("input", min, newMax ?? void 0, "max"),
|
|
1291
1413
|
locale
|
|
1292
1414
|
}), showTime && /* @__PURE__ */ jsx(TimeInput, {
|
|
1293
1415
|
value: max ?? null,
|
|
1294
|
-
onChange: (
|
|
1416
|
+
onChange: (newMax) => set("input", min, newMax ?? void 0, "max"),
|
|
1295
1417
|
locale,
|
|
1296
1418
|
showSeconds: typeof showTime === "boolean" ? true : showTime.showSeconds
|
|
1297
1419
|
})] })] })]
|
|
@@ -1454,7 +1576,7 @@ function convertDateOrArray(x) {
|
|
|
1454
1576
|
return convertDateOrRange(x);
|
|
1455
1577
|
}
|
|
1456
1578
|
function DateFilter({ locale, firstDayOfWeek, defaultDateInView, quickOptions, singleSelect, filterBy = convertDateOrArray, minDate, maxDate, showCalendarWeek, showTime,...props }) {
|
|
1457
|
-
const { value = null, onChange } = useFilter({
|
|
1579
|
+
const { value = null, onChange, close } = useFilter({
|
|
1458
1580
|
...props,
|
|
1459
1581
|
filterBy,
|
|
1460
1582
|
id: "dateFilter",
|
|
@@ -1473,7 +1595,10 @@ function DateFilter({ locale, firstDayOfWeek, defaultDateInView, quickOptions, s
|
|
|
1473
1595
|
children: /* @__PURE__ */ jsx(DatePicker, {
|
|
1474
1596
|
rangeSelect: !singleSelect,
|
|
1475
1597
|
value,
|
|
1476
|
-
onChange,
|
|
1598
|
+
onChange: (value$1, source) => {
|
|
1599
|
+
onChange(value$1);
|
|
1600
|
+
if (source !== "input") close();
|
|
1601
|
+
},
|
|
1477
1602
|
locale,
|
|
1478
1603
|
firstDayOfWeek,
|
|
1479
1604
|
defaultDateInView,
|
|
@@ -3506,7 +3631,7 @@ function TextFilter({ compare = textMatch, filterBy = asStringOrArray, placehold
|
|
|
3506
3631
|
const IconButton$1 = useTheme((t) => t.components.IconButton);
|
|
3507
3632
|
const Search$1 = useTheme((t) => t.icons.Search);
|
|
3508
3633
|
const Clear$1 = useTheme((t) => t.icons.Clear);
|
|
3509
|
-
const { value = "", onChange } = useFilter({
|
|
3634
|
+
const { value = "", onChange, close } = useFilter({
|
|
3510
3635
|
...props,
|
|
3511
3636
|
filterBy,
|
|
3512
3637
|
id: "textFilter",
|
|
@@ -3525,6 +3650,9 @@ function TextFilter({ compare = textMatch, filterBy = asStringOrArray, placehold
|
|
|
3525
3650
|
children: /* @__PURE__ */ jsx(AutoFocusTextField, {
|
|
3526
3651
|
value,
|
|
3527
3652
|
onChange: (event) => onChange(event.target.value),
|
|
3653
|
+
onKeyUp: (event) => {
|
|
3654
|
+
if (event.key === "Enter") close();
|
|
3655
|
+
},
|
|
3528
3656
|
endIcon: /* @__PURE__ */ jsx(IconButton$1, {
|
|
3529
3657
|
onClick: () => onChange(""),
|
|
3530
3658
|
children: !value ? /* @__PURE__ */ jsx(Search$1, {}) : /* @__PURE__ */ jsx(Clear$1, {})
|