@1771technologies/lytenyte-pro 0.0.39
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/LICENSE +15 -0
- package/dist/DialogPortalContext-C2WZTqJ3.js +47 -0
- package/dist/InternalBackdrop-Dm9czgoC.js +6746 -0
- package/dist/MenuRoot-9n64jNWP.js +724 -0
- package/dist/anchor-context-B9sGQdR5.js +35 -0
- package/dist/arrow-down-icon-B-3ldODD.js +27 -0
- package/dist/arrow-svg-evmXDI_J.js +29 -0
- package/dist/column-manager.js +1241 -0
- package/dist/cross-icon-CEMLAlFX.js +20 -0
- package/dist/dialog.js +506 -0
- package/dist/filter-manager.js +1056 -0
- package/dist/getPseudoElementBounds-BSHt6WYm.js +26 -0
- package/dist/grid-container.js +18 -0
- package/dist/icons.js +512 -0
- package/dist/index.js +3730 -0
- package/dist/lytenyte-pro.css +1948 -0
- package/dist/manage-columns-icon-D4CElo5H.js +146 -0
- package/dist/menu.js +1639 -0
- package/dist/pill-C4Jhdf8E.js +985 -0
- package/dist/pill-manager.js +674 -0
- package/dist/plus-icon-ToqW5CC-.js +15 -0
- package/dist/popover.js +770 -0
- package/dist/row-group-icon-BOOju5Vu.js +205 -0
- package/dist/search-icon-CcG1lqsn.js +86 -0
- package/dist/select-C6xOZZLq.js +2231 -0
- package/dist/sort-manager.js +298 -0
- package/dist/tickmark-icon-CoogRMoO.js +51 -0
- package/dist/types/cell-selection/cell-selection-containers.d.ts +3 -0
- package/dist/types/cell-selection/cell-selection-driver.d.ts +1 -0
- package/dist/types/cell-selection/cell-style-row.d.ts +8 -0
- package/dist/types/column-manager/column-manager-drag-box-controls.d.ts +1 -0
- package/dist/types/column-manager/column-manager-drag-box-expander.d.ts +1 -0
- package/dist/types/column-manager/column-manager-drag-box-label.d.ts +5 -0
- package/dist/types/column-manager/column-manager-drag-box.d.ts +13 -0
- package/dist/types/column-manager/column-manager-drag-placeholder.d.ts +5 -0
- package/dist/types/column-manager/column-manager-drop-zone.d.ts +10 -0
- package/dist/types/column-manager/column-manager-impl.d.ts +36 -0
- package/dist/types/column-manager/column-manager-pill.d.ts +4 -0
- package/dist/types/column-manager/column-manager-pivot-mode-toggle.d.ts +1 -0
- package/dist/types/column-manager/column-manager-search.d.ts +1 -0
- package/dist/types/column-manager/column-manager-state.d.ts +8 -0
- package/dist/types/column-manager/column-manager-tree-item.d.ts +6 -0
- package/dist/types/column-manager/column-manager-tree.d.ts +11 -0
- package/dist/types/column-manager/column-manager-types.d.ts +1 -0
- package/dist/types/column-manager/column-manager.d.ts +1 -0
- package/dist/types/column-manager/column-mananger-context.d.ts +12 -0
- package/dist/types/column-manager/utils/all-leafs.d.ts +3 -0
- package/dist/types/column-manager/utils/can-hide-item.d.ts +3 -0
- package/dist/types/column-manager/utils/handle-item-hide.d.ts +3 -0
- package/dist/types/components-internal/button/button.d.ts +9 -0
- package/dist/types/components-internal/grid-frame/grid-frame.d.ts +11 -0
- package/dist/types/components-internal/radio/radio.d.ts +5 -0
- package/dist/types/components-internal/separator/separator.d.ts +8 -0
- package/dist/types/components-internal/toggle/toggle.d.ts +7 -0
- package/dist/types/dialog/dialog-driver.d.ts +1 -0
- package/dist/types/dialog/dialog-impl.d.ts +6 -0
- package/dist/types/dialog/dialog.d.ts +8 -0
- package/dist/types/dialog/use-dialog-class.d.ts +1 -0
- package/dist/types/external.d.ts +2 -0
- package/dist/types/filter-manager/combined-to-flat.d.ts +3 -0
- package/dist/types/filter-manager/components/apply-filter-button.d.ts +1 -0
- package/dist/types/filter-manager/components/clear-filter-button.d.ts +1 -0
- package/dist/types/filter-manager/components/flatten-tree-items.d.ts +4 -0
- package/dist/types/filter-manager/components/get-child-values.d.ts +2 -0
- package/dist/types/filter-manager/components/in-filter-container.d.ts +1 -0
- package/dist/types/filter-manager/components/in-filter-error.d.ts +5 -0
- package/dist/types/filter-manager/components/in-filter-loading.d.ts +1 -0
- package/dist/types/filter-manager/components/in-filter-root.d.ts +11 -0
- package/dist/types/filter-manager/components/in-filter-tree.d.ts +15 -0
- package/dist/types/filter-manager/components/simple-filter-additional-switch.d.ts +1 -0
- package/dist/types/filter-manager/components/simple-filter-operator/date-operator.d.ts +1 -0
- package/dist/types/filter-manager/components/simple-filter-operator/number-operator.d.ts +1 -0
- package/dist/types/filter-manager/components/simple-filter-operator/simple-filter-operator.d.ts +1 -0
- package/dist/types/filter-manager/components/simple-filter-operator/text-operator.d.ts +1 -0
- package/dist/types/filter-manager/components/simple-filter-root.d.ts +9 -0
- package/dist/types/filter-manager/components/simple-filter-value/date-value.d.ts +1 -0
- package/dist/types/filter-manager/components/simple-filter-value/number-value.d.ts +1 -0
- package/dist/types/filter-manager/components/simple-filter-value/simple-filter-value.d.ts +1 -0
- package/dist/types/filter-manager/components/simple-filter-value/text-value.d.ts +1 -0
- package/dist/types/filter-manager/components/use-date-filter-callbacks.d.ts +9 -0
- package/dist/types/filter-manager/components/use-in-filter-item-loader.d.ts +7 -0
- package/dist/types/filter-manager/components/use-number-filter-callbacks.d.ts +8 -0
- package/dist/types/filter-manager/components/use-text-filter-callbacks.d.ts +8 -0
- package/dist/types/filter-manager/filter-manager-impl.d.ts +27 -0
- package/dist/types/filter-manager/filter-manager.d.ts +1 -0
- package/dist/types/filter-manager/filter-state-context.d.ts +16 -0
- package/dist/types/filter-manager/flat-to-combined.d.ts +3 -0
- package/dist/types/filter-manager/flatten-combined-filter.d.ts +3 -0
- package/dist/types/filter-manager/is-filter-complete.d.ts +2 -0
- package/dist/types/filter-manager/types.d.ts +15 -0
- package/dist/types/filter-manager/use-in-filter.d.ts +5 -0
- package/dist/types/filter-manager/use-simple-filters.d.ts +8 -0
- package/dist/types/grid-container/grid-container-impl.d.ts +6 -0
- package/dist/types/grid-container/grid-container.d.ts +2 -0
- package/dist/types/icons.d.ts +1 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/license.d.ts +12 -0
- package/dist/types/list-view/list-view-context.d.ts +21 -0
- package/dist/types/list-view/list-view.d.ts +26 -0
- package/dist/types/lytenyte-pro.d.ts +7 -0
- package/dist/types/menu/arrow-svg.d.ts +1 -0
- package/dist/types/menu/column-menu/column-menu-driver.d.ts +4 -0
- package/dist/types/menu/context-menu/context-menu-driver.d.ts +1 -0
- package/dist/types/menu/context-menu/use-context-menu-listener.d.ts +6 -0
- package/dist/types/menu/menu-impl.d.ts +17 -0
- package/dist/types/menu/menu.d.ts +18 -0
- package/dist/types/menu/use-menu-class-name.d.ts +1 -0
- package/dist/types/overlay/load-error-overlay.d.ts +1 -0
- package/dist/types/overlay/loading-overlay.d.ts +1 -0
- package/dist/types/overlay/no-data-overlay.d.ts +1 -0
- package/dist/types/overlay/overlay-driver.d.ts +1 -0
- package/dist/types/pill/pill.d.ts +5 -0
- package/dist/types/pill-manager/pill-manager-agg-menu.d.ts +7 -0
- package/dist/types/pill-manager/pill-manager-controls.d.ts +9 -0
- package/dist/types/pill-manager/pill-manager-drag-placeholder.d.ts +5 -0
- package/dist/types/pill-manager/pill-manager-expander.d.ts +1 -0
- package/dist/types/pill-manager/pill-manager-impl.d.ts +49 -0
- package/dist/types/pill-manager/pill-manager-pill.d.ts +4 -0
- package/dist/types/pill-manager/pill-manager-pills/pill-manager-pills.d.ts +2 -0
- package/dist/types/pill-manager/pill-manager-pills/use-aggregation-source.d.ts +2 -0
- package/dist/types/pill-manager/pill-manager-pills/use-column-pivot-source.d.ts +2 -0
- package/dist/types/pill-manager/pill-manager-pills/use-column-source.d.ts +2 -0
- package/dist/types/pill-manager/pill-manager-pills/use-measures-source.d.ts +2 -0
- package/dist/types/pill-manager/pill-manager-pills/use-row-groups-source.d.ts +2 -0
- package/dist/types/pill-manager/pill-manager-pills/utils.d.ts +3 -0
- package/dist/types/pill-manager/pill-manager-row-label.d.ts +22 -0
- package/dist/types/pill-manager/pill-manager-row.d.ts +12 -0
- package/dist/types/pill-manager/pill-manager-rows.d.ts +1 -0
- package/dist/types/pill-manager/pill-manager-separator.d.ts +1 -0
- package/dist/types/pill-manager/pill-manager-types.d.ts +36 -0
- package/dist/types/pill-manager/pill-manager.d.ts +1 -0
- package/dist/types/popover/anchor-context.d.ts +6 -0
- package/dist/types/popover/popover-driver.d.ts +1 -0
- package/dist/types/popover/popover-impl.d.ts +8 -0
- package/dist/types/popover/popover.d.ts +10 -0
- package/dist/types/popover/use-popover-class.d.ts +1 -0
- package/dist/types/select/select.d.ts +17 -0
- package/dist/types/sort-manager/sort-adder.d.ts +4 -0
- package/dist/types/sort-manager/sort-apply.d.ts +1 -0
- package/dist/types/sort-manager/sort-cancel.d.ts +1 -0
- package/dist/types/sort-manager/sort-clear.d.ts +1 -0
- package/dist/types/sort-manager/sort-column-select.d.ts +5 -0
- package/dist/types/sort-manager/sort-direction-select.d.ts +5 -0
- package/dist/types/sort-manager/sort-items-to-sort-model.d.ts +3 -0
- package/dist/types/sort-manager/sort-manager-container.d.ts +53 -0
- package/dist/types/sort-manager/sort-manager-context.d.ts +4 -0
- package/dist/types/sort-manager/sort-manager-impl.d.ts +30 -0
- package/dist/types/sort-manager/sort-manager.d.ts +1 -0
- package/dist/types/sort-manager/sort-model-to-sort-items.d.ts +4 -0
- package/dist/types/sort-manager/sort-remove.d.ts +4 -0
- package/dist/types/sort-manager/sort-sort-select.d.ts +5 -0
- package/dist/types/sort-manager/use-sort-state.d.ts +8 -0
- package/dist/types/sort-manager/use-sortable-column-items.d.ts +9 -0
- package/dist/types/types.d.ts +1 -0
- package/dist/types/use-client-data-source.d.ts +6 -0
- package/dist/types/use-edge-scroll.d.ts +7 -0
- package/dist/types/use-grid.d.ts +6 -0
- package/dist/types/use-lytenyte.d.ts +10 -0
- package/dist/types/use-tree-data-source.d.ts +3 -0
- package/dist/types/watermark.d.ts +3 -0
- package/dist/types.js +1 -0
- package/dist/use-grid-DKvzGZWc.js +916 -0
- package/dist/useAnchorPositioning-Cm44rb7y.js +252 -0
- package/dist/useBaseUiId-J66PFGv_.js +48 -0
- package/dist/useButton-Cy7tjZ__.js +183 -0
- package/dist/useCompositeListItem-I14CpQPi.js +51 -0
- package/dist/useScrollLock-D6h5lZYs.js +515 -0
- package/package.json +96 -0
|
@@ -0,0 +1,1056 @@
|
|
|
1
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useEffect, useCallback, createContext, useContext, useMemo, forwardRef } from "react";
|
|
3
|
+
import { I as Input, u as useGrid, C as Checkbox, G as GridProvider } from "./use-grid-DKvzGZWc.js";
|
|
4
|
+
import { S as Select } from "./select-C6xOZZLq.js";
|
|
5
|
+
import "@1771technologies/react-sizer";
|
|
6
|
+
import "@1771technologies/react-utils";
|
|
7
|
+
import "@1771technologies/grid-provider";
|
|
8
|
+
import { clsx } from "@1771technologies/js-utils";
|
|
9
|
+
import "@1771technologies/react-dragon";
|
|
10
|
+
import "@1771technologies/grid-core";
|
|
11
|
+
function isFilterComplete(c) {
|
|
12
|
+
if (!c) return false;
|
|
13
|
+
if (c.kind === "text") {
|
|
14
|
+
return c.operator;
|
|
15
|
+
}
|
|
16
|
+
if (c.kind === "number") {
|
|
17
|
+
return c.operator && typeof c.value === "number";
|
|
18
|
+
}
|
|
19
|
+
if (c.operator === "all_dates_in_the_period") return c.datePeriod;
|
|
20
|
+
if (c.operator === "after" || c.operator === "before" || c.operator === "equal") return c.value;
|
|
21
|
+
return !!c.operator;
|
|
22
|
+
}
|
|
23
|
+
function flattenCombinedFilter(c) {
|
|
24
|
+
const stack = [c];
|
|
25
|
+
const flat = [];
|
|
26
|
+
while (stack.length) {
|
|
27
|
+
const f = stack.pop();
|
|
28
|
+
flat.push([f.left, f.operator]);
|
|
29
|
+
flat.push([f.right, null]);
|
|
30
|
+
}
|
|
31
|
+
return flat;
|
|
32
|
+
}
|
|
33
|
+
function combinedToFlat(filter, column) {
|
|
34
|
+
const columnId = column.id;
|
|
35
|
+
let flat;
|
|
36
|
+
if (!filter) {
|
|
37
|
+
flat = [
|
|
38
|
+
[{ columnId, kind: column.type === "complex" ? "text" : column.type ?? "text" }, null]
|
|
39
|
+
];
|
|
40
|
+
} else if (filter.kind === "number" || filter.kind === "text" || filter.kind === "date") {
|
|
41
|
+
flat = [
|
|
42
|
+
[filter, "and"],
|
|
43
|
+
[{ columnId, kind: filter.kind }, null]
|
|
44
|
+
];
|
|
45
|
+
} else {
|
|
46
|
+
flat = flattenCombinedFilter(filter);
|
|
47
|
+
}
|
|
48
|
+
return flat;
|
|
49
|
+
}
|
|
50
|
+
function useSimpleFilters(api, column, showConditionalWhenFilterValid) {
|
|
51
|
+
const isPivot = api.columnIsPivot(column);
|
|
52
|
+
const state = api.getState();
|
|
53
|
+
const filterModel = state.filterModel.use();
|
|
54
|
+
const pivotFilterModel = state.internal.columnPivotFilterModel.use();
|
|
55
|
+
const filters = isPivot ? pivotFilterModel : filterModel;
|
|
56
|
+
const [flatFilters, setFlatFilters] = useState(() => {
|
|
57
|
+
const columnId = column.id;
|
|
58
|
+
const filter = filters[columnId];
|
|
59
|
+
return combinedToFlat(filter?.simple, column);
|
|
60
|
+
});
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
const columnId = column.id;
|
|
63
|
+
const filter = filters[columnId];
|
|
64
|
+
setFlatFilters(combinedToFlat(filter?.simple, column));
|
|
65
|
+
}, [column, filters]);
|
|
66
|
+
const onFilterChange = useCallback(
|
|
67
|
+
(flat) => {
|
|
68
|
+
if (flat.length === 1 && isFilterComplete(flat[0][0]) && showConditionalWhenFilterValid) {
|
|
69
|
+
const next = [
|
|
70
|
+
[flat[0][0], "and"],
|
|
71
|
+
[{ columnId: column.id, kind: flat[0][0].kind }, null]
|
|
72
|
+
];
|
|
73
|
+
setFlatFilters(next);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
setFlatFilters(flat);
|
|
77
|
+
},
|
|
78
|
+
[column.id, showConditionalWhenFilterValid]
|
|
79
|
+
);
|
|
80
|
+
return { flatFilters, onFilterChange, filters, isPivot };
|
|
81
|
+
}
|
|
82
|
+
const context$2 = createContext(null);
|
|
83
|
+
function FilterManagerStateProvider(props) {
|
|
84
|
+
return /* @__PURE__ */ jsx(context$2.Provider, { value: props.value, children: props.children });
|
|
85
|
+
}
|
|
86
|
+
const useFilterManagerState = () => useContext(context$2);
|
|
87
|
+
function useInFilter(api, column) {
|
|
88
|
+
const isPivot = api.columnIsPivot(column);
|
|
89
|
+
const state = api.getState();
|
|
90
|
+
const filterModel = state.filterModel.use();
|
|
91
|
+
const pivotFilterModel = state.internal.columnPivotFilterModel.use();
|
|
92
|
+
const filters = isPivot ? pivotFilterModel : filterModel;
|
|
93
|
+
const thisFilter = useMemo(() => {
|
|
94
|
+
const filter = filters[column.id]?.set;
|
|
95
|
+
if (!filter) return null;
|
|
96
|
+
return filter;
|
|
97
|
+
}, [column.id, filters]);
|
|
98
|
+
const [values, setValues] = useState(() => thisFilter ? new Set(thisFilter.set) : null);
|
|
99
|
+
useEffect(() => {
|
|
100
|
+
setValues(() => {
|
|
101
|
+
const filter = filters[column.id]?.set;
|
|
102
|
+
if (!filter) return null;
|
|
103
|
+
return new Set(filter ? new Set(filter.set) : null);
|
|
104
|
+
});
|
|
105
|
+
}, [column.id, filters]);
|
|
106
|
+
return { values, setValues };
|
|
107
|
+
}
|
|
108
|
+
const context$1 = createContext(
|
|
109
|
+
{}
|
|
110
|
+
);
|
|
111
|
+
function SimpleFilterRoot(props) {
|
|
112
|
+
const { flatFilters, onFilterChange } = useFilterManagerState();
|
|
113
|
+
const flatFilter = flatFilters[props.isAdditional ? 1 : 0];
|
|
114
|
+
const semiFilter = flatFilter?.[0];
|
|
115
|
+
const onChange = useCallback(
|
|
116
|
+
(filter) => {
|
|
117
|
+
const next = [...flatFilters];
|
|
118
|
+
const logical = flatFilter[1];
|
|
119
|
+
next[props.isAdditional ? 1 : 0] = [filter, logical];
|
|
120
|
+
onFilterChange(next);
|
|
121
|
+
},
|
|
122
|
+
[flatFilter, flatFilters, onFilterChange, props.isAdditional]
|
|
123
|
+
);
|
|
124
|
+
const value = useMemo(() => {
|
|
125
|
+
return { value: semiFilter, onChange };
|
|
126
|
+
}, [onChange, semiFilter]);
|
|
127
|
+
if (!flatFilter) return null;
|
|
128
|
+
return /* @__PURE__ */ jsx(context$1.Provider, { value, children: props.children });
|
|
129
|
+
}
|
|
130
|
+
const useSimpleFilterRoot = () => useContext(context$1);
|
|
131
|
+
function useDateFilterCallbacks() {
|
|
132
|
+
const { value, onChange: onFilterChange } = useSimpleFilterRoot();
|
|
133
|
+
const onChange = useCallback(
|
|
134
|
+
(item) => {
|
|
135
|
+
const currentOperator = value.operator;
|
|
136
|
+
if (currentOperator === item.value) return;
|
|
137
|
+
const nextFilter = {
|
|
138
|
+
kind: "date",
|
|
139
|
+
columnId: value.columnId,
|
|
140
|
+
operator: item.value,
|
|
141
|
+
value: "",
|
|
142
|
+
datePeriod: null
|
|
143
|
+
};
|
|
144
|
+
onFilterChange(nextFilter);
|
|
145
|
+
},
|
|
146
|
+
[onFilterChange, value.columnId, value.operator]
|
|
147
|
+
);
|
|
148
|
+
const onValueChange = useCallback(
|
|
149
|
+
(c) => {
|
|
150
|
+
const current = value.value;
|
|
151
|
+
if (current === c) return;
|
|
152
|
+
const nextFilter = {
|
|
153
|
+
kind: "date",
|
|
154
|
+
columnId: value.columnId,
|
|
155
|
+
operator: value.operator,
|
|
156
|
+
value: c,
|
|
157
|
+
datePeriod: null
|
|
158
|
+
};
|
|
159
|
+
onFilterChange(nextFilter);
|
|
160
|
+
},
|
|
161
|
+
[onFilterChange, value.columnId, value.operator, value.value]
|
|
162
|
+
);
|
|
163
|
+
const onDatePeriodChange = useCallback(
|
|
164
|
+
(c) => {
|
|
165
|
+
const current = value.datePeriod;
|
|
166
|
+
if (current === c) return;
|
|
167
|
+
const nextFilter = {
|
|
168
|
+
kind: "date",
|
|
169
|
+
columnId: value.columnId,
|
|
170
|
+
operator: value.operator,
|
|
171
|
+
value,
|
|
172
|
+
datePeriod: c
|
|
173
|
+
};
|
|
174
|
+
onFilterChange(nextFilter);
|
|
175
|
+
},
|
|
176
|
+
[onFilterChange, value]
|
|
177
|
+
);
|
|
178
|
+
return { onChange, onValueChange, onDatePeriodChange };
|
|
179
|
+
}
|
|
180
|
+
const operatorsWithDate$1 = ["equal", "after", "before"];
|
|
181
|
+
function DateOperatorSelect() {
|
|
182
|
+
const { value: v } = useSimpleFilterRoot();
|
|
183
|
+
const s = useDateFilterCallbacks();
|
|
184
|
+
const filter = v;
|
|
185
|
+
const value = useMemo(() => {
|
|
186
|
+
if (!filter.operator) return null;
|
|
187
|
+
return { label: valueToLabel$1[filter.operator], value: filter.operator };
|
|
188
|
+
}, [filter.operator]);
|
|
189
|
+
const operator = filter.operator;
|
|
190
|
+
const fullSpan = operator && !operatorsWithDate$1.includes(operator) && operator !== "all_dates_in_the_period";
|
|
191
|
+
return /* @__PURE__ */ jsx(
|
|
192
|
+
Select,
|
|
193
|
+
{
|
|
194
|
+
placeholder: "Select",
|
|
195
|
+
"data-full-span": fullSpan,
|
|
196
|
+
options: dateItems,
|
|
197
|
+
selected: value,
|
|
198
|
+
onSelect: s.onChange
|
|
199
|
+
}
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
const valueToLabel$1 = {
|
|
203
|
+
equal: "Equal",
|
|
204
|
+
before: "Before",
|
|
205
|
+
after: "After",
|
|
206
|
+
tomorrow: "Tomorrow",
|
|
207
|
+
today: "Today",
|
|
208
|
+
yesterday: "Yesterday",
|
|
209
|
+
next_week: "Next Week",
|
|
210
|
+
this_week: "This Week",
|
|
211
|
+
last_week: "Last Week",
|
|
212
|
+
next_month: "Next Month",
|
|
213
|
+
this_month: "This Month",
|
|
214
|
+
last_month: "Last Month",
|
|
215
|
+
next_quarter: "Next Quarter",
|
|
216
|
+
this_quarter: "This Quarter",
|
|
217
|
+
last_quarter: "Last Quarter",
|
|
218
|
+
next_year: "Next Year",
|
|
219
|
+
this_year: "This Year",
|
|
220
|
+
last_year: "Last Year",
|
|
221
|
+
ytd: "Year To Date",
|
|
222
|
+
all_dates_in_the_period: "All Dates In Period"
|
|
223
|
+
};
|
|
224
|
+
const dateItems = [
|
|
225
|
+
{ label: "Equal", value: "equal" },
|
|
226
|
+
{ label: "Before", value: "before" },
|
|
227
|
+
{ label: "After", value: "after" },
|
|
228
|
+
{ label: "Tomorrow", value: "tomorrow" },
|
|
229
|
+
{ label: "Today", value: "today" },
|
|
230
|
+
{ label: "Yesterday", value: "yesterday" },
|
|
231
|
+
{ label: "Next Week", value: "next_week" },
|
|
232
|
+
{ label: "This Week", value: "this_week" },
|
|
233
|
+
{ label: "Last Week", value: "last_week" },
|
|
234
|
+
{ label: "Next Month", value: "next_month" },
|
|
235
|
+
{ label: "This Month", value: "this_month" },
|
|
236
|
+
{ label: "Last Month", value: "last_month" },
|
|
237
|
+
{ label: "Next Quarter", value: "next_quarter" },
|
|
238
|
+
{ label: "This Quarter", value: "this_quarter" },
|
|
239
|
+
{ label: "Last Quarter", value: "last_quarter" },
|
|
240
|
+
{ label: "Next Year", value: "next_year" },
|
|
241
|
+
{ label: "This Year", value: "this_year" },
|
|
242
|
+
{ label: "Last Year", value: "last_year" },
|
|
243
|
+
{ label: "Year To Date", value: "ytd" },
|
|
244
|
+
{ label: "All Dates In Period", value: "all_dates_in_the_period" }
|
|
245
|
+
];
|
|
246
|
+
function useNumberFilterCallbacks() {
|
|
247
|
+
const { value, onChange: onFilterChange } = useSimpleFilterRoot();
|
|
248
|
+
const onChange = useCallback(
|
|
249
|
+
(c) => {
|
|
250
|
+
const current = value.operator;
|
|
251
|
+
if (current === c.value) return;
|
|
252
|
+
const nextFilter = {
|
|
253
|
+
kind: "number",
|
|
254
|
+
columnId: value.columnId,
|
|
255
|
+
operator: c.value,
|
|
256
|
+
value: ""
|
|
257
|
+
};
|
|
258
|
+
onFilterChange(nextFilter);
|
|
259
|
+
},
|
|
260
|
+
[onFilterChange, value.columnId, value.operator]
|
|
261
|
+
);
|
|
262
|
+
const onValueChange = useCallback(
|
|
263
|
+
(c) => {
|
|
264
|
+
const current = value.value;
|
|
265
|
+
if (current === c) return;
|
|
266
|
+
const nextFilter = {
|
|
267
|
+
kind: "number",
|
|
268
|
+
columnId: value.columnId,
|
|
269
|
+
operator: value.operator,
|
|
270
|
+
value: c
|
|
271
|
+
};
|
|
272
|
+
onFilterChange(nextFilter);
|
|
273
|
+
},
|
|
274
|
+
[onFilterChange, value.columnId, value.operator, value.value]
|
|
275
|
+
);
|
|
276
|
+
return { onChange, onValueChange };
|
|
277
|
+
}
|
|
278
|
+
function NumberOperatorSelect() {
|
|
279
|
+
const { value: v } = useSimpleFilterRoot();
|
|
280
|
+
const s = useNumberFilterCallbacks();
|
|
281
|
+
const filter = v;
|
|
282
|
+
const value = useMemo(() => {
|
|
283
|
+
if (!filter.operator) return null;
|
|
284
|
+
return { label: valueToLabel[filter.operator], value: filter.operator };
|
|
285
|
+
}, [filter.operator]);
|
|
286
|
+
return /* @__PURE__ */ jsx(
|
|
287
|
+
Select,
|
|
288
|
+
{
|
|
289
|
+
selected: value,
|
|
290
|
+
options: selectItems$1,
|
|
291
|
+
onSelect: s.onChange,
|
|
292
|
+
placeholder: "Select..."
|
|
293
|
+
}
|
|
294
|
+
);
|
|
295
|
+
}
|
|
296
|
+
const valueToLabel = {
|
|
297
|
+
equal: "Equal",
|
|
298
|
+
not_equal: "Not Equal",
|
|
299
|
+
greater_than: "Greater Than",
|
|
300
|
+
greater_than_or_equal: "Greater Than Or Equal To",
|
|
301
|
+
less_than: "Less Than",
|
|
302
|
+
less_than_or_equal: "Less Than Or Equal To"
|
|
303
|
+
};
|
|
304
|
+
const selectItems$1 = [
|
|
305
|
+
{ value: "equal", label: "Equal" },
|
|
306
|
+
{ value: "not_equal", label: "Not Equal" },
|
|
307
|
+
{ value: "greater_than", label: "Greater Than" },
|
|
308
|
+
{ value: "greater_than_or_equal", label: "Greater Than Or Equal To" },
|
|
309
|
+
{ value: "less_than", label: "Less Than" },
|
|
310
|
+
{ value: "less_than_or_equal", label: "Less Than Or Equal To" }
|
|
311
|
+
];
|
|
312
|
+
function useTextFilterCallbacks() {
|
|
313
|
+
const { value, onChange: onFilterChange } = useSimpleFilterRoot();
|
|
314
|
+
const onChange = useCallback(
|
|
315
|
+
(c) => {
|
|
316
|
+
const current = value.operator;
|
|
317
|
+
if (current === c.value) return;
|
|
318
|
+
const nextFilter = {
|
|
319
|
+
kind: "text",
|
|
320
|
+
columnId: value.columnId,
|
|
321
|
+
operator: c.value,
|
|
322
|
+
value: ""
|
|
323
|
+
};
|
|
324
|
+
onFilterChange(nextFilter);
|
|
325
|
+
},
|
|
326
|
+
[onFilterChange, value.columnId, value.operator]
|
|
327
|
+
);
|
|
328
|
+
const onValueChange = useCallback(
|
|
329
|
+
(c) => {
|
|
330
|
+
const current = value.value;
|
|
331
|
+
if (current === c) return;
|
|
332
|
+
const nextFilter = {
|
|
333
|
+
kind: "text",
|
|
334
|
+
columnId: value.columnId,
|
|
335
|
+
operator: value.operator,
|
|
336
|
+
value: c
|
|
337
|
+
};
|
|
338
|
+
onFilterChange(nextFilter);
|
|
339
|
+
},
|
|
340
|
+
[onFilterChange, value.columnId, value.operator, value.value]
|
|
341
|
+
);
|
|
342
|
+
return { onChange, onValueChange };
|
|
343
|
+
}
|
|
344
|
+
function TextOperatorSelect() {
|
|
345
|
+
const { value: v } = useSimpleFilterRoot();
|
|
346
|
+
const s = useTextFilterCallbacks();
|
|
347
|
+
const filter = v;
|
|
348
|
+
const value = useMemo(() => {
|
|
349
|
+
if (!filter.operator) return null;
|
|
350
|
+
return { label: valueToToLabel[filter.operator], value: filter.operator };
|
|
351
|
+
}, [filter.operator]);
|
|
352
|
+
return /* @__PURE__ */ jsx(
|
|
353
|
+
Select,
|
|
354
|
+
{
|
|
355
|
+
placeholder: "Select...",
|
|
356
|
+
options: selectItems,
|
|
357
|
+
selected: value,
|
|
358
|
+
onSelect: s.onChange
|
|
359
|
+
}
|
|
360
|
+
);
|
|
361
|
+
}
|
|
362
|
+
const valueToToLabel = {
|
|
363
|
+
equal: "Equal",
|
|
364
|
+
not_equal: "Not Equal",
|
|
365
|
+
begins_with: "Begins With",
|
|
366
|
+
not_begins_with: "Does Not Begin With",
|
|
367
|
+
ends_with: "Ends With",
|
|
368
|
+
not_ends_with: "Does Not End With",
|
|
369
|
+
contains: "Contains",
|
|
370
|
+
not_contains: "Does Not Contain"
|
|
371
|
+
};
|
|
372
|
+
const selectItems = [
|
|
373
|
+
{ value: "equal", label: "Equal" },
|
|
374
|
+
{ value: "not_equal", label: "Not Equal" },
|
|
375
|
+
{ value: "begins_with", label: "Begins With" },
|
|
376
|
+
{ value: "not_begins_with", label: "Does Not Begin With" },
|
|
377
|
+
{ value: "ends_with", label: "Ends With" },
|
|
378
|
+
{ value: "not_ends_with", label: "Does Not End With" },
|
|
379
|
+
{ value: "contains", label: "Contains" },
|
|
380
|
+
{ value: "not_contains", label: "Does Not Contain" }
|
|
381
|
+
];
|
|
382
|
+
function SimpleFilterOperator() {
|
|
383
|
+
const p = useSimpleFilterRoot();
|
|
384
|
+
const kind = p.value.kind;
|
|
385
|
+
if (kind === "date") {
|
|
386
|
+
return /* @__PURE__ */ jsx(DateOperatorSelect, {});
|
|
387
|
+
}
|
|
388
|
+
if (kind === "number") {
|
|
389
|
+
return /* @__PURE__ */ jsx(NumberOperatorSelect, {});
|
|
390
|
+
}
|
|
391
|
+
if (kind === "text") {
|
|
392
|
+
return /* @__PURE__ */ jsx(TextOperatorSelect, {});
|
|
393
|
+
}
|
|
394
|
+
return null;
|
|
395
|
+
}
|
|
396
|
+
const operatorsWithDate = ["equal", "after", "before"];
|
|
397
|
+
function DateValue() {
|
|
398
|
+
const { value } = useSimpleFilterRoot();
|
|
399
|
+
const filter = value;
|
|
400
|
+
const operator = filter.operator;
|
|
401
|
+
const { onValueChange, onDatePeriodChange } = useDateFilterCallbacks();
|
|
402
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
403
|
+
!operator && /* @__PURE__ */ jsx(Input, { disabled: true, type: "date" }),
|
|
404
|
+
operator && operatorsWithDate.includes(operator) && /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(
|
|
405
|
+
Input,
|
|
406
|
+
{
|
|
407
|
+
small: true,
|
|
408
|
+
type: "date",
|
|
409
|
+
onChange: (e) => onValueChange(e.target.value),
|
|
410
|
+
value: filter.value ?? ""
|
|
411
|
+
}
|
|
412
|
+
) }),
|
|
413
|
+
operator === "all_dates_in_the_period" && /* @__PURE__ */ jsx(
|
|
414
|
+
DatePeriodSelect,
|
|
415
|
+
{
|
|
416
|
+
value: filter.datePeriod ?? null,
|
|
417
|
+
onAllDatePeriodSelect: onDatePeriodChange
|
|
418
|
+
}
|
|
419
|
+
)
|
|
420
|
+
] });
|
|
421
|
+
}
|
|
422
|
+
function DatePeriodSelect({ value, onAllDatePeriodSelect }) {
|
|
423
|
+
const item = useMemo(() => {
|
|
424
|
+
if (!value) return null;
|
|
425
|
+
return { label: allDatePeriodValueToLabel[value], value };
|
|
426
|
+
}, [value]);
|
|
427
|
+
return /* @__PURE__ */ jsx(
|
|
428
|
+
Select,
|
|
429
|
+
{
|
|
430
|
+
options: allDatePeriodOptions,
|
|
431
|
+
selected: item,
|
|
432
|
+
placeholder: "Select...",
|
|
433
|
+
onSelect: (v) => {
|
|
434
|
+
onAllDatePeriodSelect(v.value);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
);
|
|
438
|
+
}
|
|
439
|
+
const allDatePeriodValueToLabel = {
|
|
440
|
+
"quarter-1": "Quarter 1",
|
|
441
|
+
"quarter-2": "Quarter 2",
|
|
442
|
+
"quarter-3": "Quarter 3",
|
|
443
|
+
"quarter-4": "Quarter 4",
|
|
444
|
+
january: "January",
|
|
445
|
+
february: "February",
|
|
446
|
+
march: "March",
|
|
447
|
+
april: "April",
|
|
448
|
+
may: "May",
|
|
449
|
+
june: "June",
|
|
450
|
+
july: "July",
|
|
451
|
+
august: "August",
|
|
452
|
+
september: "September",
|
|
453
|
+
october: "October",
|
|
454
|
+
november: "November",
|
|
455
|
+
december: "December"
|
|
456
|
+
};
|
|
457
|
+
const allDatePeriodOptions = [
|
|
458
|
+
{ label: "Quarter 1", value: "quarter-1" },
|
|
459
|
+
{ label: "Quarter 2", value: "quarter-2" },
|
|
460
|
+
{ label: "Quarter 3", value: "quarter-3" },
|
|
461
|
+
{ label: "Quarter 4", value: "quarter-4" },
|
|
462
|
+
{ label: "January", value: "january" },
|
|
463
|
+
{ label: "February", value: "february" },
|
|
464
|
+
{ label: "March", value: "march" },
|
|
465
|
+
{ label: "April", value: "april" },
|
|
466
|
+
{ label: "May", value: "may" },
|
|
467
|
+
{ label: "June", value: "june" },
|
|
468
|
+
{ label: "July", value: "july" },
|
|
469
|
+
{ label: "August", value: "august" },
|
|
470
|
+
{ label: "September", value: "september" },
|
|
471
|
+
{ label: "October", value: "october" },
|
|
472
|
+
{ label: "November", value: "november" },
|
|
473
|
+
{ label: "December", value: "december" }
|
|
474
|
+
];
|
|
475
|
+
function NumberValue() {
|
|
476
|
+
const { value } = useSimpleFilterRoot();
|
|
477
|
+
const filter = value;
|
|
478
|
+
const operator = filter.operator;
|
|
479
|
+
const { onValueChange } = useNumberFilterCallbacks();
|
|
480
|
+
return /* @__PURE__ */ jsx(
|
|
481
|
+
Input,
|
|
482
|
+
{
|
|
483
|
+
small: true,
|
|
484
|
+
type: "number",
|
|
485
|
+
disabled: !operator,
|
|
486
|
+
value: filter.value ?? "",
|
|
487
|
+
onChange: (e) => onValueChange(Number.parseFloat(e.target.value))
|
|
488
|
+
}
|
|
489
|
+
);
|
|
490
|
+
}
|
|
491
|
+
function TextValue() {
|
|
492
|
+
const { value } = useSimpleFilterRoot();
|
|
493
|
+
const filter = value;
|
|
494
|
+
const operator = filter.operator;
|
|
495
|
+
const { onValueChange } = useTextFilterCallbacks();
|
|
496
|
+
return /* @__PURE__ */ jsx(
|
|
497
|
+
Input,
|
|
498
|
+
{
|
|
499
|
+
small: true,
|
|
500
|
+
disabled: !operator,
|
|
501
|
+
value: filter.value ?? "",
|
|
502
|
+
onChange: (e) => onValueChange(e.target.value)
|
|
503
|
+
}
|
|
504
|
+
);
|
|
505
|
+
}
|
|
506
|
+
function SimpleFilterValue() {
|
|
507
|
+
const p = useSimpleFilterRoot();
|
|
508
|
+
const kind = p.value.kind;
|
|
509
|
+
if (kind === "date") {
|
|
510
|
+
return /* @__PURE__ */ jsx(DateValue, {});
|
|
511
|
+
}
|
|
512
|
+
if (kind === "number") {
|
|
513
|
+
return /* @__PURE__ */ jsx(NumberValue, {});
|
|
514
|
+
}
|
|
515
|
+
if (kind === "text") {
|
|
516
|
+
return /* @__PURE__ */ jsx(TextValue, {});
|
|
517
|
+
}
|
|
518
|
+
return null;
|
|
519
|
+
}
|
|
520
|
+
function Radio({
|
|
521
|
+
onCheckChange,
|
|
522
|
+
checked,
|
|
523
|
+
disabled,
|
|
524
|
+
...other
|
|
525
|
+
}) {
|
|
526
|
+
return /* @__PURE__ */ jsx(
|
|
527
|
+
"div",
|
|
528
|
+
{
|
|
529
|
+
className: clsx(
|
|
530
|
+
"lng1771-radio",
|
|
531
|
+
!disabled && "lng1771-radio--hover",
|
|
532
|
+
disabled && "lng1771-radio--disabled",
|
|
533
|
+
checked && "lng1771-radio--checked",
|
|
534
|
+
disabled && checked && "lng1771-radio--checked-disabled"
|
|
535
|
+
),
|
|
536
|
+
children: /* @__PURE__ */ jsx(
|
|
537
|
+
"input",
|
|
538
|
+
{
|
|
539
|
+
type: "radio",
|
|
540
|
+
checked,
|
|
541
|
+
onChange: (e) => onCheckChange?.(e.target.checked, e),
|
|
542
|
+
...other
|
|
543
|
+
}
|
|
544
|
+
)
|
|
545
|
+
}
|
|
546
|
+
);
|
|
547
|
+
}
|
|
548
|
+
const SimpleFilterAdditionalSwitch = forwardRef(function SimpleFilterAdditionalSwitch2(props, ref) {
|
|
549
|
+
const { flatFilters, onFilterChange } = useFilterManagerState();
|
|
550
|
+
const value = flatFilters[0][1];
|
|
551
|
+
if (!value) return null;
|
|
552
|
+
const onChange = (c) => {
|
|
553
|
+
const next = [...flatFilters];
|
|
554
|
+
next[0] = [flatFilters[0][0], c];
|
|
555
|
+
onFilterChange(next);
|
|
556
|
+
};
|
|
557
|
+
return /* @__PURE__ */ jsxs("div", { ...props, className: clsx("lng1771-filter-manager__switch", props.className), ref, children: [
|
|
558
|
+
/* @__PURE__ */ jsxs(
|
|
559
|
+
"div",
|
|
560
|
+
{
|
|
561
|
+
className: clsx(
|
|
562
|
+
"lng1771-filter-manager__switch-item",
|
|
563
|
+
"lng1771-filter-manager__switch-item--end"
|
|
564
|
+
),
|
|
565
|
+
children: [
|
|
566
|
+
/* @__PURE__ */ jsx(Radio, { checked: value === "and", onCheckChange: () => onChange("and") }),
|
|
567
|
+
"And"
|
|
568
|
+
]
|
|
569
|
+
}
|
|
570
|
+
),
|
|
571
|
+
/* @__PURE__ */ jsxs("div", { className: clsx("lng1771-filter-manager__switch-item"), children: [
|
|
572
|
+
/* @__PURE__ */ jsx(Radio, { checked: value === "or", onCheckChange: () => onChange("or") }),
|
|
573
|
+
"Or"
|
|
574
|
+
] })
|
|
575
|
+
] });
|
|
576
|
+
});
|
|
577
|
+
function flatToCombined(flat) {
|
|
578
|
+
const [left, right] = flat;
|
|
579
|
+
const leftFilter = isFilterComplete(left?.[0]) ? left?.[0] : null;
|
|
580
|
+
const rightFilter = isFilterComplete(right?.[0]) ? right?.[0] : null;
|
|
581
|
+
const operator = left?.[1];
|
|
582
|
+
if (!leftFilter && rightFilter) return { ...rightFilter };
|
|
583
|
+
if (leftFilter && !rightFilter) return { ...leftFilter };
|
|
584
|
+
if (!leftFilter && !rightFilter) return null;
|
|
585
|
+
const combined = {
|
|
586
|
+
kind: "combined",
|
|
587
|
+
left: leftFilter,
|
|
588
|
+
right: rightFilter,
|
|
589
|
+
operator
|
|
590
|
+
};
|
|
591
|
+
return combined;
|
|
592
|
+
}
|
|
593
|
+
const FilterManagerApplyButton = forwardRef(function FilterManagerApplyButton2({ className, onClick, children, ...props }, ref) {
|
|
594
|
+
const { api } = useGrid();
|
|
595
|
+
const { flatFilters, column, isPivot, filters, inFilterValue } = useFilterManagerState();
|
|
596
|
+
return /* @__PURE__ */ jsx(
|
|
597
|
+
"button",
|
|
598
|
+
{
|
|
599
|
+
...props,
|
|
600
|
+
className: clsx("lng1771-filter-manager__button", className),
|
|
601
|
+
onClick: (ev) => {
|
|
602
|
+
const combined = flatToCombined(flatFilters);
|
|
603
|
+
const newFilters = { ...filters };
|
|
604
|
+
if (combined) {
|
|
605
|
+
newFilters[column.id] ??= {};
|
|
606
|
+
newFilters[column.id].simple = combined;
|
|
607
|
+
}
|
|
608
|
+
if (inFilterValue) {
|
|
609
|
+
newFilters[column.id] ??= {};
|
|
610
|
+
newFilters[column.id].set = inFilterValue?.size ? {
|
|
611
|
+
columnId: column.id,
|
|
612
|
+
kind: "in",
|
|
613
|
+
operator: "notin",
|
|
614
|
+
set: inFilterValue
|
|
615
|
+
} : null;
|
|
616
|
+
}
|
|
617
|
+
if (isPivot) {
|
|
618
|
+
api.columnPivotSetFilterModel(newFilters);
|
|
619
|
+
} else {
|
|
620
|
+
api.getState().filterModel.set(newFilters);
|
|
621
|
+
}
|
|
622
|
+
onClick?.(ev);
|
|
623
|
+
},
|
|
624
|
+
ref,
|
|
625
|
+
children: children ? children : "Apply"
|
|
626
|
+
}
|
|
627
|
+
);
|
|
628
|
+
});
|
|
629
|
+
const FilterManagerClearButton = forwardRef(function FilterManagerClearButton2({ className, onClick, children, ...props }, ref) {
|
|
630
|
+
const { api } = useGrid();
|
|
631
|
+
const { filters, column, isPivot } = useFilterManagerState();
|
|
632
|
+
return /* @__PURE__ */ jsx(
|
|
633
|
+
"button",
|
|
634
|
+
{
|
|
635
|
+
...props,
|
|
636
|
+
className: clsx("lng1771-filter-manager__button", className),
|
|
637
|
+
onClick: (ev) => {
|
|
638
|
+
const newFilters = { ...filters };
|
|
639
|
+
delete newFilters[column.id];
|
|
640
|
+
if (isPivot) {
|
|
641
|
+
api.columnPivotSetFilterModel(newFilters);
|
|
642
|
+
} else {
|
|
643
|
+
api.getState().filterModel.set(newFilters);
|
|
644
|
+
}
|
|
645
|
+
onClick?.(ev);
|
|
646
|
+
},
|
|
647
|
+
ref,
|
|
648
|
+
children: children ? children : "Clear"
|
|
649
|
+
}
|
|
650
|
+
);
|
|
651
|
+
});
|
|
652
|
+
function useInFilterItemLoader(getTreeFilterItems) {
|
|
653
|
+
const [treeFilterItems, setTreeFilterItems] = useState([]);
|
|
654
|
+
const [hasError, setError] = useState(false);
|
|
655
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
656
|
+
const loadItems = useCallback(() => {
|
|
657
|
+
if (!getTreeFilterItems) return [];
|
|
658
|
+
const items = getTreeFilterItems();
|
|
659
|
+
if ("then" in items) {
|
|
660
|
+
setIsLoading(true);
|
|
661
|
+
items.then((res) => {
|
|
662
|
+
setTreeFilterItems(res);
|
|
663
|
+
}).catch((error) => {
|
|
664
|
+
console.error(error);
|
|
665
|
+
setError(true);
|
|
666
|
+
}).finally(() => {
|
|
667
|
+
setIsLoading(false);
|
|
668
|
+
});
|
|
669
|
+
} else {
|
|
670
|
+
setTreeFilterItems(items);
|
|
671
|
+
}
|
|
672
|
+
}, [getTreeFilterItems]);
|
|
673
|
+
useEffect(() => {
|
|
674
|
+
loadItems();
|
|
675
|
+
}, [loadItems]);
|
|
676
|
+
return { isLoading, hasError, treeFilterItems, retry: loadItems };
|
|
677
|
+
}
|
|
678
|
+
const context = createContext(null);
|
|
679
|
+
function InFilterRoot(props) {
|
|
680
|
+
const grid = useGrid();
|
|
681
|
+
const { column } = useFilterManagerState();
|
|
682
|
+
const getItems = useCallback(() => {
|
|
683
|
+
return grid.api.columnInFilterItems(column);
|
|
684
|
+
}, [column, grid.api]);
|
|
685
|
+
const state = useInFilterItemLoader(getItems);
|
|
686
|
+
return /* @__PURE__ */ jsx(context.Provider, { value: state, children: props.children });
|
|
687
|
+
}
|
|
688
|
+
const useInFilterState = () => useContext(context);
|
|
689
|
+
const InFilterError = forwardRef(function InFilterError2({ children, className, ...props }, ref) {
|
|
690
|
+
const { retry, hasError } = useInFilterState();
|
|
691
|
+
if (!hasError) return null;
|
|
692
|
+
return /* @__PURE__ */ jsx(
|
|
693
|
+
"div",
|
|
694
|
+
{
|
|
695
|
+
...props,
|
|
696
|
+
className: clsx("lng1771-filter-manager__in-filter-error", className),
|
|
697
|
+
ref,
|
|
698
|
+
children: children?.(retry)
|
|
699
|
+
}
|
|
700
|
+
);
|
|
701
|
+
});
|
|
702
|
+
const InFilterLoading = forwardRef(
|
|
703
|
+
function InFilterLoading2({ children, className, ...props }, ref) {
|
|
704
|
+
const { isLoading } = useInFilterState();
|
|
705
|
+
if (!isLoading) return null;
|
|
706
|
+
return /* @__PURE__ */ jsx(
|
|
707
|
+
"div",
|
|
708
|
+
{
|
|
709
|
+
...props,
|
|
710
|
+
className: clsx("lng1771-filter-manager__in-filter-loading", className),
|
|
711
|
+
ref,
|
|
712
|
+
children
|
|
713
|
+
}
|
|
714
|
+
);
|
|
715
|
+
}
|
|
716
|
+
);
|
|
717
|
+
function getChildValues(t) {
|
|
718
|
+
const stack = [...t.children];
|
|
719
|
+
const values = /* @__PURE__ */ new Set();
|
|
720
|
+
while (stack.length) {
|
|
721
|
+
const t2 = stack.pop();
|
|
722
|
+
if (t2.kind === "leaf") values.add(t2.value);
|
|
723
|
+
else stack.push(...t2.children);
|
|
724
|
+
}
|
|
725
|
+
return values;
|
|
726
|
+
}
|
|
727
|
+
function flattenTreeItems(items, expansions) {
|
|
728
|
+
const stack = [...items.map((c) => [c, 0])];
|
|
729
|
+
const flat = [];
|
|
730
|
+
while (stack.length) {
|
|
731
|
+
const [item, depth] = stack.shift();
|
|
732
|
+
if (item.kind === "parent" && expansions.has(item.label)) {
|
|
733
|
+
const children = item.children.map((c) => [c, depth + 1]);
|
|
734
|
+
stack.unshift(...children);
|
|
735
|
+
}
|
|
736
|
+
flat.push({ ...item, depth });
|
|
737
|
+
}
|
|
738
|
+
return flat;
|
|
739
|
+
}
|
|
740
|
+
function InFilterViewport({
|
|
741
|
+
itemHeight,
|
|
742
|
+
viewportHeight,
|
|
743
|
+
searchQuery
|
|
744
|
+
}) {
|
|
745
|
+
const { treeFilterItems, hasError, isLoading } = useInFilterState();
|
|
746
|
+
const { inFilterValue, setInFilterValue } = useFilterManagerState();
|
|
747
|
+
if (hasError || isLoading) return null;
|
|
748
|
+
return /* @__PURE__ */ jsx(
|
|
749
|
+
InFilterViewportImpl,
|
|
750
|
+
{
|
|
751
|
+
treeItems: treeFilterItems,
|
|
752
|
+
itemHeight: itemHeight ?? 28,
|
|
753
|
+
viewportHeight: viewportHeight ?? 300,
|
|
754
|
+
filterValue: searchQuery ?? "",
|
|
755
|
+
onValuesChange: setInFilterValue,
|
|
756
|
+
values: inFilterValue
|
|
757
|
+
}
|
|
758
|
+
);
|
|
759
|
+
}
|
|
760
|
+
function InFilterViewportImpl({
|
|
761
|
+
treeItems,
|
|
762
|
+
itemHeight,
|
|
763
|
+
viewportHeight,
|
|
764
|
+
values,
|
|
765
|
+
onValuesChange,
|
|
766
|
+
filterValue
|
|
767
|
+
}) {
|
|
768
|
+
const [rowStart, setRowStart] = useState(0);
|
|
769
|
+
const [rowEnd, setRowEnd] = useState(0);
|
|
770
|
+
const [vp, setVp] = useState(null);
|
|
771
|
+
const [expansions, setExpansions] = useState(() => /* @__PURE__ */ new Set());
|
|
772
|
+
const unfilteredFlat = useMemo(() => {
|
|
773
|
+
const selectAll = {
|
|
774
|
+
kind: "leaf",
|
|
775
|
+
label: "Select All",
|
|
776
|
+
value: null
|
|
777
|
+
};
|
|
778
|
+
return [selectAll, ...flattenTreeItems(treeItems, expansions)];
|
|
779
|
+
}, [expansions, treeItems]);
|
|
780
|
+
const flat = useMemo(() => {
|
|
781
|
+
if (!filterValue) return unfilteredFlat;
|
|
782
|
+
return unfilteredFlat.filter(
|
|
783
|
+
(c) => c.label.toLocaleLowerCase().includes(filterValue.toLocaleLowerCase())
|
|
784
|
+
);
|
|
785
|
+
}, [filterValue, unfilteredFlat]);
|
|
786
|
+
const allItemsAreLeafs = useMemo(() => {
|
|
787
|
+
return flat.every((c) => c.kind === "leaf");
|
|
788
|
+
}, [flat]);
|
|
789
|
+
const handleVpChange = useCallback(() => {
|
|
790
|
+
if (!vp) return;
|
|
791
|
+
const scrollTop = vp.scrollTop;
|
|
792
|
+
const height = vp.clientHeight;
|
|
793
|
+
const rowStart2 = Math.max(Math.floor(scrollTop / itemHeight) - 10, 0);
|
|
794
|
+
const rowEnd2 = Math.min(rowStart2 + Math.ceil(height / itemHeight) + 10, flat.length);
|
|
795
|
+
setRowStart(rowStart2);
|
|
796
|
+
setRowEnd(rowEnd2);
|
|
797
|
+
}, [flat.length, itemHeight, vp]);
|
|
798
|
+
useEffect(() => {
|
|
799
|
+
handleVpChange();
|
|
800
|
+
}, [expansions, handleVpChange]);
|
|
801
|
+
const indices = useMemo(() => {
|
|
802
|
+
return Array.from({ length: rowEnd - rowStart }, (_, i) => i + rowStart);
|
|
803
|
+
}, [rowEnd, rowStart]);
|
|
804
|
+
const isSelected = (c) => {
|
|
805
|
+
if (values === null) return true;
|
|
806
|
+
if (c.label === "Select All" && c.kind === "leaf" && c.value === null) {
|
|
807
|
+
return false;
|
|
808
|
+
}
|
|
809
|
+
if (c.kind === "leaf") return !values.has(c.value);
|
|
810
|
+
return c.children.every((c2) => isSelected(c2));
|
|
811
|
+
};
|
|
812
|
+
const isIndeterminate = (c) => {
|
|
813
|
+
if (c.label === "Select All" && c.kind === "leaf" && c.value === null) {
|
|
814
|
+
const allItems = new Set(
|
|
815
|
+
treeItems.flatMap(
|
|
816
|
+
(item) => item.kind === "parent" ? [...getChildValues(item)] : item.value
|
|
817
|
+
)
|
|
818
|
+
);
|
|
819
|
+
return values ? values.size > 0 && values.size !== allItems.size : false;
|
|
820
|
+
}
|
|
821
|
+
if (values === null) return false;
|
|
822
|
+
if (c.kind === "leaf") return false;
|
|
823
|
+
const childSet = [...getChildValues(c)];
|
|
824
|
+
return childSet.some((c2) => values.has(c2)) && !childSet.every((c2) => values.has(c2));
|
|
825
|
+
};
|
|
826
|
+
return /* @__PURE__ */ jsx(
|
|
827
|
+
"div",
|
|
828
|
+
{
|
|
829
|
+
ref: setVp,
|
|
830
|
+
onScroll: handleVpChange,
|
|
831
|
+
style: {
|
|
832
|
+
height: viewportHeight,
|
|
833
|
+
maxHeight: viewportHeight,
|
|
834
|
+
minHeight: viewportHeight,
|
|
835
|
+
overflowY: "auto",
|
|
836
|
+
overflowX: "hidden",
|
|
837
|
+
paddingBlock: 4,
|
|
838
|
+
boxSizing: "border-box",
|
|
839
|
+
position: "relative"
|
|
840
|
+
},
|
|
841
|
+
children: /* @__PURE__ */ jsx("div", { style: { height: itemHeight * flat.length }, children: indices.map((c, i) => {
|
|
842
|
+
const item = flat[c];
|
|
843
|
+
if (!item) return null;
|
|
844
|
+
const selected = isSelected(item);
|
|
845
|
+
const indeterminate = isIndeterminate(item);
|
|
846
|
+
const handleChange = () => {
|
|
847
|
+
const allItems = new Set(
|
|
848
|
+
treeItems.flatMap(
|
|
849
|
+
(item2) => item2.kind === "parent" ? [...getChildValues(item2)] : item2.value
|
|
850
|
+
)
|
|
851
|
+
);
|
|
852
|
+
if (item.label === "Select All" && item.kind === "leaf" && item.value === null) {
|
|
853
|
+
if (!values) {
|
|
854
|
+
onValuesChange(allItems);
|
|
855
|
+
} else {
|
|
856
|
+
onValuesChange(null);
|
|
857
|
+
}
|
|
858
|
+
return;
|
|
859
|
+
}
|
|
860
|
+
if (!values) {
|
|
861
|
+
const newSet2 = item.kind === "parent" ? getChildValues(item) : /* @__PURE__ */ new Set([item.value]);
|
|
862
|
+
onValuesChange(newSet2);
|
|
863
|
+
return;
|
|
864
|
+
}
|
|
865
|
+
if (item.kind === "leaf") {
|
|
866
|
+
const newSet2 = new Set(values);
|
|
867
|
+
if (newSet2.has(item.value)) newSet2.delete(item.value);
|
|
868
|
+
else newSet2.add(item.value);
|
|
869
|
+
onValuesChange(newSet2.size ? newSet2 : null);
|
|
870
|
+
return;
|
|
871
|
+
}
|
|
872
|
+
const newSet = new Set(values);
|
|
873
|
+
const nextValues = getChildValues(item);
|
|
874
|
+
if (indeterminate || !selected) {
|
|
875
|
+
for (const i2 of nextValues) {
|
|
876
|
+
newSet.delete(i2);
|
|
877
|
+
}
|
|
878
|
+
} else {
|
|
879
|
+
for (const i2 of nextValues) {
|
|
880
|
+
newSet.add(i2);
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
onValuesChange(newSet.size ? newSet : null);
|
|
884
|
+
};
|
|
885
|
+
return /* @__PURE__ */ jsxs(
|
|
886
|
+
"div",
|
|
887
|
+
{
|
|
888
|
+
tabIndex: i === 0 ? 0 : -1,
|
|
889
|
+
className: "lng1771-filter-manager__in-filter-tree",
|
|
890
|
+
onClick: () => {
|
|
891
|
+
handleChange();
|
|
892
|
+
},
|
|
893
|
+
onKeyDown: (e) => {
|
|
894
|
+
if (e.key === "ArrowUp") {
|
|
895
|
+
const prev = e.currentTarget.previousElementSibling;
|
|
896
|
+
if (prev) {
|
|
897
|
+
prev.focus();
|
|
898
|
+
e.preventDefault();
|
|
899
|
+
}
|
|
900
|
+
} else if (e.key === "ArrowDown") {
|
|
901
|
+
const next = e.currentTarget.nextElementSibling;
|
|
902
|
+
if (next) {
|
|
903
|
+
next.focus();
|
|
904
|
+
e.preventDefault();
|
|
905
|
+
}
|
|
906
|
+
} else if (e.key === "Enter") {
|
|
907
|
+
handleChange();
|
|
908
|
+
} else if (e.key === " ") {
|
|
909
|
+
if (item.kind === "parent") {
|
|
910
|
+
setExpansions((prev) => {
|
|
911
|
+
const next = new Set(prev);
|
|
912
|
+
if (prev.has(item.label)) {
|
|
913
|
+
next.delete(item.label);
|
|
914
|
+
} else next.add(item.label);
|
|
915
|
+
return next;
|
|
916
|
+
});
|
|
917
|
+
} else {
|
|
918
|
+
handleChange();
|
|
919
|
+
}
|
|
920
|
+
e.preventDefault();
|
|
921
|
+
}
|
|
922
|
+
},
|
|
923
|
+
style: {
|
|
924
|
+
height: itemHeight,
|
|
925
|
+
minHeight: itemHeight,
|
|
926
|
+
maxHeight: itemHeight,
|
|
927
|
+
paddingInlineStart: (item.depth ?? 0) * 16 + 8,
|
|
928
|
+
transform: `translate3d(0px, ${itemHeight * c}px, 0px)`
|
|
929
|
+
},
|
|
930
|
+
children: [
|
|
931
|
+
item.kind !== "parent" ? allItemsAreLeafs ? /* @__PURE__ */ jsx(Fragment, {}) : /* @__PURE__ */ jsx("div", { style: { width: 20, height: 20 }, role: "presentation" }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
932
|
+
expansions.has(item.label) && /* @__PURE__ */ jsx(
|
|
933
|
+
"button",
|
|
934
|
+
{
|
|
935
|
+
style: {
|
|
936
|
+
width: 20,
|
|
937
|
+
height: 20,
|
|
938
|
+
color: "var(--lng1771-gray-70)",
|
|
939
|
+
fontSize: 20
|
|
940
|
+
},
|
|
941
|
+
onClick: (event) => {
|
|
942
|
+
event.stopPropagation();
|
|
943
|
+
event.preventDefault();
|
|
944
|
+
setExpansions((prev) => {
|
|
945
|
+
const next = new Set(prev);
|
|
946
|
+
if (prev.has(item.label)) {
|
|
947
|
+
next.delete(item.label);
|
|
948
|
+
} else next.add(item.label);
|
|
949
|
+
return next;
|
|
950
|
+
});
|
|
951
|
+
},
|
|
952
|
+
children: /* @__PURE__ */ jsx("span", { style: { position: "relative", top: "-2px", insetInlineStart: "1px" }, children: "›" })
|
|
953
|
+
}
|
|
954
|
+
),
|
|
955
|
+
!expansions.has(item.label) && /* @__PURE__ */ jsx(
|
|
956
|
+
"button",
|
|
957
|
+
{
|
|
958
|
+
style: {
|
|
959
|
+
width: 20,
|
|
960
|
+
height: 20,
|
|
961
|
+
color: "var(--lng1771-gray-70)",
|
|
962
|
+
fontSize: 20
|
|
963
|
+
},
|
|
964
|
+
onClick: (event) => {
|
|
965
|
+
event.stopPropagation();
|
|
966
|
+
event.preventDefault();
|
|
967
|
+
setExpansions((prev) => {
|
|
968
|
+
const next = new Set(prev);
|
|
969
|
+
if (prev.has(item.label)) {
|
|
970
|
+
next.delete(item.label);
|
|
971
|
+
} else next.add(item.label);
|
|
972
|
+
return next;
|
|
973
|
+
});
|
|
974
|
+
},
|
|
975
|
+
children: /* @__PURE__ */ jsx(
|
|
976
|
+
"span",
|
|
977
|
+
{
|
|
978
|
+
style: {
|
|
979
|
+
position: "relative",
|
|
980
|
+
top: "-2px",
|
|
981
|
+
insetInlineStart: "1px"
|
|
982
|
+
},
|
|
983
|
+
children: "›"
|
|
984
|
+
}
|
|
985
|
+
)
|
|
986
|
+
}
|
|
987
|
+
)
|
|
988
|
+
] }),
|
|
989
|
+
/* @__PURE__ */ jsx(
|
|
990
|
+
Checkbox,
|
|
991
|
+
{
|
|
992
|
+
tabIndex: -1,
|
|
993
|
+
isChecked: selected || indeterminate,
|
|
994
|
+
isDeterminate: indeterminate,
|
|
995
|
+
onCheckChange: () => {
|
|
996
|
+
handleChange();
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
),
|
|
1000
|
+
/* @__PURE__ */ jsx("span", { children: item.label })
|
|
1001
|
+
]
|
|
1002
|
+
},
|
|
1003
|
+
c
|
|
1004
|
+
);
|
|
1005
|
+
}) })
|
|
1006
|
+
}
|
|
1007
|
+
);
|
|
1008
|
+
}
|
|
1009
|
+
const InFilterContainer = forwardRef(
|
|
1010
|
+
function InFilterContainer2(props, ref) {
|
|
1011
|
+
return /* @__PURE__ */ jsx(
|
|
1012
|
+
"div",
|
|
1013
|
+
{
|
|
1014
|
+
...props,
|
|
1015
|
+
className: clsx("lng1771-filter-manager__in-filter-container", props.className),
|
|
1016
|
+
ref
|
|
1017
|
+
}
|
|
1018
|
+
);
|
|
1019
|
+
}
|
|
1020
|
+
);
|
|
1021
|
+
function Root({ grid, column, children }) {
|
|
1022
|
+
const simpleState = useSimpleFilters(grid.api, column, true);
|
|
1023
|
+
const inFilterState = useInFilter(grid.api, column);
|
|
1024
|
+
return /* @__PURE__ */ jsx(GridProvider, { value: grid, children: /* @__PURE__ */ jsx(
|
|
1025
|
+
FilterManagerStateProvider,
|
|
1026
|
+
{
|
|
1027
|
+
value: useMemo(
|
|
1028
|
+
() => ({
|
|
1029
|
+
...simpleState,
|
|
1030
|
+
column,
|
|
1031
|
+
inFilterValue: inFilterState.values,
|
|
1032
|
+
setInFilterValue: inFilterState.setValues
|
|
1033
|
+
}),
|
|
1034
|
+
[column, inFilterState.setValues, inFilterState.values, simpleState]
|
|
1035
|
+
),
|
|
1036
|
+
children
|
|
1037
|
+
}
|
|
1038
|
+
) });
|
|
1039
|
+
}
|
|
1040
|
+
const FilterManager = {
|
|
1041
|
+
Root,
|
|
1042
|
+
SimpleRoot: SimpleFilterRoot,
|
|
1043
|
+
SimpleOperator: SimpleFilterOperator,
|
|
1044
|
+
SimpleValue: SimpleFilterValue,
|
|
1045
|
+
SimpleSwitch: SimpleFilterAdditionalSwitch,
|
|
1046
|
+
InFilterRoot,
|
|
1047
|
+
InFilterContainer,
|
|
1048
|
+
InFilterError,
|
|
1049
|
+
InFilterLoading,
|
|
1050
|
+
InFilterViewport,
|
|
1051
|
+
ApplyButton: FilterManagerApplyButton,
|
|
1052
|
+
ClearButton: FilterManagerClearButton
|
|
1053
|
+
};
|
|
1054
|
+
export {
|
|
1055
|
+
FilterManager
|
|
1056
|
+
};
|