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.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_chunk = require('./chunk-pbleEpgJ.cjs');
|
|
2
|
-
const require_tableSettings = require('./tableSettings-
|
|
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(
|
|
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:
|
|
605
|
-
|
|
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
|
-
}, {
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
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)(
|
|
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
|
|
824
|
-
day:
|
|
825
|
-
month:
|
|
826
|
-
year:
|
|
955
|
+
const maxValues$1 = {
|
|
956
|
+
day: 31,
|
|
957
|
+
month: 12,
|
|
958
|
+
year: 9999
|
|
827
959
|
};
|
|
828
|
-
const
|
|
829
|
-
|
|
830
|
-
|
|
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
|
|
841
|
-
const
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
if (
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
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])
|
|
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:
|
|
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: `${
|
|
892
|
-
placeholder: "".padEnd(
|
|
893
|
-
value:
|
|
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
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
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
|
-
|
|
902
|
-
|
|
903
|
-
|
|
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
|
|
919
|
-
hour:
|
|
920
|
-
minute:
|
|
921
|
-
second:
|
|
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
|
|
929
|
-
const
|
|
930
|
-
const
|
|
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
|
|
936
|
-
const
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
if (
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
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])
|
|
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:
|
|
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: `${
|
|
987
|
-
placeholder: "".padEnd(
|
|
988
|
-
value:
|
|
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
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
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) =>
|
|
997
|
-
|
|
998
|
-
|
|
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: (
|
|
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: (
|
|
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: (
|
|
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: (
|
|
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, {})
|