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 +297 -155
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +297 -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-BxCzVAiu.cjs → tableSettings-C450XPgW.cjs} +25 -15
- package/dist/{tableSettings-BxCzVAiu.cjs.map → tableSettings-C450XPgW.cjs.map} +1 -1
- package/dist/{tableSettings-C5bAcuVw.js → tableSettings-DFnt2SZO.js} +25 -15
- package/dist/{tableSettings-C5bAcuVw.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.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ExporterEntry } from "./exporter-ztSF5GbY.cjs";
|
|
2
|
-
import { Column, CommonFilterProps, FilterImplementation, FunctionWithDeps, Id, InternalColumn, InternalTableState, MemoizedTableTheme, PartialTableTheme, Sort, SortDirection, TableItem, TableProps, TableRef, TableStateStorage, TableTheme } from "./types-
|
|
2
|
+
import { Column, CommonFilterProps, FilterImplementation, FunctionWithDeps, Id, InternalColumn, InternalTableState, MemoizedTableTheme, PartialTableTheme, Sort, SortDirection, TableItem, TableProps, TableRef, TableStateStorage, TableTheme } from "./types-DzYx_oT1.cjs";
|
|
3
3
|
import * as _emotion_react_jsx_runtime1 from "@emotion/react/jsx-runtime";
|
|
4
4
|
import * as react0 from "react";
|
|
5
5
|
import { ComponentType, ForwardedRef, HTMLProps, ReactNode } from "react";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ExporterEntry } from "./exporter-BxgFAyWA.js";
|
|
2
|
-
import { Column, CommonFilterProps, FilterImplementation, FunctionWithDeps, Id, InternalColumn, InternalTableState, MemoizedTableTheme, PartialTableTheme, Sort, SortDirection, TableItem, TableProps, TableRef, TableStateStorage, TableTheme } from "./types-
|
|
2
|
+
import { Column, CommonFilterProps, FilterImplementation, FunctionWithDeps, Id, InternalColumn, InternalTableState, MemoizedTableTheme, PartialTableTheme, Sort, SortDirection, TableItem, TableProps, TableRef, TableStateStorage, TableTheme } from "./types-k3mbd-dT.js";
|
|
3
3
|
import * as react0 from "react";
|
|
4
4
|
import { ComponentType, ForwardedRef, HTMLProps, ReactNode } from "react";
|
|
5
5
|
import * as _emotion_react_jsx_runtime1 from "@emotion/react/jsx-runtime";
|
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
|
|
@@ -809,64 +931,67 @@ function defaults(first, ...more) {
|
|
|
809
931
|
}, first);
|
|
810
932
|
}
|
|
811
933
|
|
|
934
|
+
//#endregion
|
|
935
|
+
//#region src/hooks/useLatestRef.ts
|
|
936
|
+
function useLatestRef(value) {
|
|
937
|
+
const latestValue = useRef(value);
|
|
938
|
+
useEffect(() => {
|
|
939
|
+
latestValue.current = value;
|
|
940
|
+
}, [value]);
|
|
941
|
+
return latestValue;
|
|
942
|
+
}
|
|
943
|
+
|
|
812
944
|
//#endregion
|
|
813
945
|
//#region src/components/dateInput.tsx
|
|
814
946
|
const className$1 = "schummar-table-date-input";
|
|
815
947
|
const defaultDate$1 = new Date(1970, 0, 1);
|
|
816
948
|
const isIncludedType$1 = (type) => type === "day" || type === "month" || type === "year";
|
|
817
|
-
const
|
|
818
|
-
day:
|
|
819
|
-
month:
|
|
820
|
-
year:
|
|
949
|
+
const maxValues$1 = {
|
|
950
|
+
day: 31,
|
|
951
|
+
month: 12,
|
|
952
|
+
year: 9999
|
|
821
953
|
};
|
|
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];
|
|
954
|
+
const tabNext$1 = (event, id) => {
|
|
955
|
+
const all = Array.from(document.querySelectorAll(`.${className$1}-${id}`));
|
|
956
|
+
const next = all[all.indexOf(event) + 1];
|
|
831
957
|
if (next instanceof HTMLElement) next.focus();
|
|
832
958
|
};
|
|
959
|
+
function buildDate(value, baseDate = /* @__PURE__ */ new Date()) {
|
|
960
|
+
const date = new Date(baseDate);
|
|
961
|
+
if (value.year) date.setFullYear(Number(value.year));
|
|
962
|
+
if (value.month) date.setMonth(Number(value.month) - 1);
|
|
963
|
+
if (value.day) date.setDate(Number(value.day));
|
|
964
|
+
return date;
|
|
965
|
+
}
|
|
833
966
|
function DateInput({ value, onChange, locale }) {
|
|
834
|
-
const
|
|
835
|
-
const
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
if (
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
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, {
|
|
967
|
+
const id = useMemo(() => nanoid(), []);
|
|
968
|
+
const [localValue, setLocalValue] = useState();
|
|
969
|
+
const latestValue = useLatestRef(value);
|
|
970
|
+
const commit = useMemo(() => debounce((localValue$1 = {}, value$1, onChange$1) => {
|
|
971
|
+
if (value$1 !== latestValue.current) return;
|
|
972
|
+
const date = buildDate(localValue$1, value$1 ?? void 0);
|
|
973
|
+
setLocalValue(void 0);
|
|
974
|
+
onChange$1(isNaN(date.getTime()) ? null : date);
|
|
975
|
+
}, 100), []);
|
|
976
|
+
const format = useMemo(() => new Intl.DateTimeFormat(locale, {
|
|
858
977
|
day: "2-digit",
|
|
859
978
|
month: "2-digit",
|
|
860
979
|
year: "numeric"
|
|
861
|
-
}), [locale])
|
|
980
|
+
}), [locale]);
|
|
981
|
+
let parts;
|
|
982
|
+
try {
|
|
983
|
+
parts = format.formatToParts(value ?? defaultDate$1);
|
|
984
|
+
} catch {
|
|
985
|
+
parts = format.formatToParts(defaultDate$1);
|
|
986
|
+
}
|
|
862
987
|
const isEmpty = !value;
|
|
863
988
|
return /* @__PURE__ */ jsx("div", {
|
|
864
989
|
css: {
|
|
865
990
|
display: "flex",
|
|
866
991
|
alignItems: "baseline"
|
|
867
992
|
},
|
|
868
|
-
children: parts.map(({ type, value:
|
|
869
|
-
className: className$1
|
|
993
|
+
children: parts.map(({ type, value: partValue }, index) => /* @__PURE__ */ jsx(Fragment, { children: isIncludedType$1(type) ? /* @__PURE__ */ jsx("input", {
|
|
994
|
+
className: `${className$1}-${id}`,
|
|
870
995
|
css: {
|
|
871
996
|
boxSizing: "content-box",
|
|
872
997
|
overflow: "visible",
|
|
@@ -882,19 +1007,28 @@ function DateInput({ value, onChange, locale }) {
|
|
|
882
1007
|
},
|
|
883
1008
|
"&:focus": { borderBottom: "2px solid var(--primaryMain)" }
|
|
884
1009
|
},
|
|
885
|
-
style: { width: `${
|
|
886
|
-
placeholder: "".padEnd(
|
|
887
|
-
value:
|
|
1010
|
+
style: { width: `${String(maxValues$1[type]).length}ch` },
|
|
1011
|
+
placeholder: "".padEnd(String(maxValues$1[type]).length, "0"),
|
|
1012
|
+
value: localValue?.[type] ?? (isEmpty ? "" : partValue),
|
|
888
1013
|
onChange: (event) => {
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
1014
|
+
const input = event.target.value;
|
|
1015
|
+
if (!/^\d*$/.test(input)) return;
|
|
1016
|
+
const newValue = {
|
|
1017
|
+
...localValue,
|
|
1018
|
+
[type]: input
|
|
1019
|
+
};
|
|
1020
|
+
if (Number(input) > maxValues$1[type]) newValue[type] = String(maxValues$1[type]);
|
|
1021
|
+
setLocalValue(newValue);
|
|
1022
|
+
if (input.length >= String(maxValues$1[type]).length) setTimeout(() => tabNext$1(event.target, id));
|
|
1023
|
+
},
|
|
1024
|
+
onFocus: (event) => {
|
|
1025
|
+
commit.cancel();
|
|
1026
|
+
event.target.select();
|
|
894
1027
|
},
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
1028
|
+
onBlur: () => {
|
|
1029
|
+
commit(localValue, value, onChange);
|
|
1030
|
+
}
|
|
1031
|
+
}) : type === "literal" ? /* @__PURE__ */ jsx("span", { children: partValue }) : null }, index))
|
|
898
1032
|
});
|
|
899
1033
|
}
|
|
900
1034
|
|
|
@@ -909,59 +1043,52 @@ function Text({ id }) {
|
|
|
909
1043
|
const className = "schummar-table-time-input";
|
|
910
1044
|
const defaultDate = new Date(1970, 0, 1);
|
|
911
1045
|
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
|
|
1046
|
+
const maxValues = {
|
|
1047
|
+
hour: 23,
|
|
1048
|
+
minute: 59,
|
|
1049
|
+
second: 59
|
|
921
1050
|
};
|
|
922
|
-
const
|
|
923
|
-
const
|
|
924
|
-
const
|
|
925
|
-
const next = all[(all.indexOf(event) + 1) % all.length];
|
|
1051
|
+
const tabNext = (event, id) => {
|
|
1052
|
+
const all = Array.from(document.querySelectorAll(`.${className}-${id}`));
|
|
1053
|
+
const next = all[all.indexOf(event) + 1];
|
|
926
1054
|
if (next instanceof HTMLElement) next.focus();
|
|
927
1055
|
};
|
|
1056
|
+
function buildTime(value, baseDate = /* @__PURE__ */ new Date()) {
|
|
1057
|
+
const date = new Date(baseDate);
|
|
1058
|
+
if (value.hour) date.setHours(Number(value.hour));
|
|
1059
|
+
if (value.minute) date.setMinutes(Number(value.minute));
|
|
1060
|
+
if (value.second) date.setSeconds(Number(value.second));
|
|
1061
|
+
return date;
|
|
1062
|
+
}
|
|
928
1063
|
function TimeInput({ value, onChange, locale, showSeconds = true }) {
|
|
929
|
-
const
|
|
930
|
-
const
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
if (
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
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, {
|
|
1064
|
+
const id = useMemo(() => nanoid(), []);
|
|
1065
|
+
const [localValue, setLocalValue] = useState();
|
|
1066
|
+
const latestValue = useLatestRef(value);
|
|
1067
|
+
const commit = useMemo(() => debounce((localValue$1 = {}, value$1, onChange$1) => {
|
|
1068
|
+
if (value$1 !== latestValue.current) return;
|
|
1069
|
+
const date = buildTime(localValue$1, value$1 ?? void 0);
|
|
1070
|
+
setLocalValue(void 0);
|
|
1071
|
+
onChange$1(isNaN(date.getTime()) ? null : date);
|
|
1072
|
+
}, 100), []);
|
|
1073
|
+
const format = useMemo(() => new Intl.DateTimeFormat(locale, {
|
|
953
1074
|
hour: "2-digit",
|
|
954
1075
|
minute: "2-digit",
|
|
955
1076
|
second: showSeconds ? "2-digit" : void 0
|
|
956
|
-
}), [locale])
|
|
1077
|
+
}), [locale]);
|
|
1078
|
+
let parts;
|
|
1079
|
+
try {
|
|
1080
|
+
parts = format.formatToParts(value ?? defaultDate);
|
|
1081
|
+
} catch {
|
|
1082
|
+
parts = format.formatToParts(defaultDate);
|
|
1083
|
+
}
|
|
957
1084
|
const isEmpty = !value;
|
|
958
1085
|
return /* @__PURE__ */ jsx("div", {
|
|
959
1086
|
css: {
|
|
960
1087
|
display: "flex",
|
|
961
1088
|
alignItems: "baseline"
|
|
962
1089
|
},
|
|
963
|
-
children: parts.map(({ type, value:
|
|
964
|
-
className
|
|
1090
|
+
children: parts.map(({ type, value: partValue }, index) => /* @__PURE__ */ jsx(Fragment, { children: isIncludedType(type) ? /* @__PURE__ */ jsx("input", {
|
|
1091
|
+
className: `${className}-${id}`,
|
|
965
1092
|
css: {
|
|
966
1093
|
boxSizing: "content-box",
|
|
967
1094
|
overflow: "visible",
|
|
@@ -977,19 +1104,28 @@ function TimeInput({ value, onChange, locale, showSeconds = true }) {
|
|
|
977
1104
|
},
|
|
978
1105
|
"&:focus": { borderBottom: "2px solid var(--primaryMain)" }
|
|
979
1106
|
},
|
|
980
|
-
style: { width: `${
|
|
981
|
-
placeholder: "".padEnd(
|
|
982
|
-
value:
|
|
1107
|
+
style: { width: `${String(maxValues[type]).length}ch` },
|
|
1108
|
+
placeholder: "".padEnd(String(maxValues[type]).length, "0"),
|
|
1109
|
+
value: localValue?.[type] ?? (isEmpty ? "" : partValue),
|
|
983
1110
|
onChange: (event) => {
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
1111
|
+
const input = event.target.value;
|
|
1112
|
+
if (!/^\d*$/.test(input)) return;
|
|
1113
|
+
const newValue = {
|
|
1114
|
+
...localValue,
|
|
1115
|
+
[type]: input
|
|
1116
|
+
};
|
|
1117
|
+
if (Number(input) > maxValues[type]) newValue[type] = String(maxValues[type]);
|
|
1118
|
+
setLocalValue(newValue);
|
|
1119
|
+
if (input.length >= String(maxValues[type]).length) setTimeout(() => tabNext(event.target, id));
|
|
989
1120
|
},
|
|
990
|
-
onFocus: (event) =>
|
|
991
|
-
|
|
992
|
-
|
|
1121
|
+
onFocus: (event) => {
|
|
1122
|
+
commit.cancel();
|
|
1123
|
+
event.target.select();
|
|
1124
|
+
},
|
|
1125
|
+
onBlur: () => {
|
|
1126
|
+
commit(localValue, value, onChange);
|
|
1127
|
+
}
|
|
1128
|
+
}) : type === "literal" ? /* @__PURE__ */ jsx("span", { children: partValue }) : null }, index))
|
|
993
1129
|
});
|
|
994
1130
|
}
|
|
995
1131
|
|
|
@@ -1278,20 +1414,20 @@ function DatePicker(props) {
|
|
|
1278
1414
|
},
|
|
1279
1415
|
children: [/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx(DateInput, {
|
|
1280
1416
|
value: min ?? null,
|
|
1281
|
-
onChange: (
|
|
1417
|
+
onChange: (newMin) => set("input", newMin ?? void 0, max, "min"),
|
|
1282
1418
|
locale
|
|
1283
1419
|
}), showTime && /* @__PURE__ */ jsx(TimeInput, {
|
|
1284
1420
|
value: min ?? null,
|
|
1285
|
-
onChange: (
|
|
1421
|
+
onChange: (newMin) => set("input", newMin ?? void 0, max, "min"),
|
|
1286
1422
|
locale,
|
|
1287
1423
|
showSeconds: typeof showTime === "boolean" ? true : showTime.showSeconds
|
|
1288
1424
|
})] }), rangeSelect && /* @__PURE__ */ jsxs(Fragment$1, { children: [" - ", /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx(DateInput, {
|
|
1289
1425
|
value: max ?? null,
|
|
1290
|
-
onChange: (
|
|
1426
|
+
onChange: (newMax) => set("input", min, newMax ?? void 0, "max"),
|
|
1291
1427
|
locale
|
|
1292
1428
|
}), showTime && /* @__PURE__ */ jsx(TimeInput, {
|
|
1293
1429
|
value: max ?? null,
|
|
1294
|
-
onChange: (
|
|
1430
|
+
onChange: (newMax) => set("input", min, newMax ?? void 0, "max"),
|
|
1295
1431
|
locale,
|
|
1296
1432
|
showSeconds: typeof showTime === "boolean" ? true : showTime.showSeconds
|
|
1297
1433
|
})] })] })]
|
|
@@ -1454,7 +1590,7 @@ function convertDateOrArray(x) {
|
|
|
1454
1590
|
return convertDateOrRange(x);
|
|
1455
1591
|
}
|
|
1456
1592
|
function DateFilter({ locale, firstDayOfWeek, defaultDateInView, quickOptions, singleSelect, filterBy = convertDateOrArray, minDate, maxDate, showCalendarWeek, showTime,...props }) {
|
|
1457
|
-
const { value = null, onChange } = useFilter({
|
|
1593
|
+
const { value = null, onChange, close } = useFilter({
|
|
1458
1594
|
...props,
|
|
1459
1595
|
filterBy,
|
|
1460
1596
|
id: "dateFilter",
|
|
@@ -1473,7 +1609,10 @@ function DateFilter({ locale, firstDayOfWeek, defaultDateInView, quickOptions, s
|
|
|
1473
1609
|
children: /* @__PURE__ */ jsx(DatePicker, {
|
|
1474
1610
|
rangeSelect: !singleSelect,
|
|
1475
1611
|
value,
|
|
1476
|
-
onChange,
|
|
1612
|
+
onChange: (value$1, source) => {
|
|
1613
|
+
onChange(value$1);
|
|
1614
|
+
if (source !== "input") close();
|
|
1615
|
+
},
|
|
1477
1616
|
locale,
|
|
1478
1617
|
firstDayOfWeek,
|
|
1479
1618
|
defaultDateInView,
|
|
@@ -3506,7 +3645,7 @@ function TextFilter({ compare = textMatch, filterBy = asStringOrArray, placehold
|
|
|
3506
3645
|
const IconButton$1 = useTheme((t) => t.components.IconButton);
|
|
3507
3646
|
const Search$1 = useTheme((t) => t.icons.Search);
|
|
3508
3647
|
const Clear$1 = useTheme((t) => t.icons.Clear);
|
|
3509
|
-
const { value = "", onChange } = useFilter({
|
|
3648
|
+
const { value = "", onChange, close } = useFilter({
|
|
3510
3649
|
...props,
|
|
3511
3650
|
filterBy,
|
|
3512
3651
|
id: "textFilter",
|
|
@@ -3525,6 +3664,9 @@ function TextFilter({ compare = textMatch, filterBy = asStringOrArray, placehold
|
|
|
3525
3664
|
children: /* @__PURE__ */ jsx(AutoFocusTextField, {
|
|
3526
3665
|
value,
|
|
3527
3666
|
onChange: (event) => onChange(event.target.value),
|
|
3667
|
+
onKeyUp: (event) => {
|
|
3668
|
+
if (event.key === "Enter") close();
|
|
3669
|
+
},
|
|
3528
3670
|
endIcon: /* @__PURE__ */ jsx(IconButton$1, {
|
|
3529
3671
|
onClick: () => onChange(""),
|
|
3530
3672
|
children: !value ? /* @__PURE__ */ jsx(Search$1, {}) : /* @__PURE__ */ jsx(Clear$1, {})
|