@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,985 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { useRef, useState, useCallback, useEffect, useMemo, forwardRef } from "react";
|
|
3
|
+
import { a as useDragStore, c as useStore, u as useGrid } from "./use-grid-DKvzGZWc.js";
|
|
4
|
+
import { arrayOverlap, clsx } from "@1771technologies/js-utils";
|
|
5
|
+
import { k as useForkRef, m as mergeProps, O as contains, v as useComponentRenderer, P as PropTypes, Q as pressableTriggerOpenStateMapping } from "./InternalBackdrop-Dm9czgoC.js";
|
|
6
|
+
import { u as useButton } from "./useButton-Cy7tjZ__.js";
|
|
7
|
+
import { o as ownerDocument } from "./useScrollLock-D6h5lZYs.js";
|
|
8
|
+
import { g as getPseudoElementBounds } from "./getPseudoElementBounds-BSHt6WYm.js";
|
|
9
|
+
import { u as useMenuRootContext } from "./MenuRoot-9n64jNWP.js";
|
|
10
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
11
|
+
import { Menu } from "./menu.js";
|
|
12
|
+
const toJSON = () => "";
|
|
13
|
+
function getVisibleBoundingBox(element) {
|
|
14
|
+
if (!element) return null;
|
|
15
|
+
let visibleBox = element.getBoundingClientRect();
|
|
16
|
+
let current = element.parentElement;
|
|
17
|
+
while (current && current !== document.body && current !== document.documentElement) {
|
|
18
|
+
const style = getComputedStyle(current);
|
|
19
|
+
const isClipping = style.overflow !== "visible";
|
|
20
|
+
if (isClipping) {
|
|
21
|
+
const parentRect = current.getBoundingClientRect();
|
|
22
|
+
visibleBox = {
|
|
23
|
+
top: Math.max(visibleBox.top, parentRect.top),
|
|
24
|
+
y: Math.max(visibleBox.top, parentRect.top),
|
|
25
|
+
right: Math.min(visibleBox.right, parentRect.right),
|
|
26
|
+
bottom: Math.min(visibleBox.bottom, parentRect.bottom),
|
|
27
|
+
left: Math.max(visibleBox.left, parentRect.left),
|
|
28
|
+
x: Math.max(visibleBox.left, parentRect.left),
|
|
29
|
+
width: 0,
|
|
30
|
+
// Initialized to 0 for now (calculated below)
|
|
31
|
+
height: 0,
|
|
32
|
+
// Initialized to 0 for now (calculated below)
|
|
33
|
+
toJSON
|
|
34
|
+
};
|
|
35
|
+
visibleBox.width = Math.max(0, visibleBox.right - visibleBox.left);
|
|
36
|
+
visibleBox.height = Math.max(0, visibleBox.bottom - visibleBox.top);
|
|
37
|
+
if (visibleBox.width === 0 || visibleBox.height === 0) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
current = current.parentElement;
|
|
42
|
+
}
|
|
43
|
+
return visibleBox;
|
|
44
|
+
}
|
|
45
|
+
function computeActiveDrag(mounted, tags, data, id, x, y) {
|
|
46
|
+
const targets = getDropTargets(mounted, x, y, tags);
|
|
47
|
+
const sortedRects = targets.sort((left, right) => {
|
|
48
|
+
const distanceToRootA = nodesToRoot(left.target);
|
|
49
|
+
const distanceToRootB = nodesToRoot(right.target);
|
|
50
|
+
return distanceToRootA - distanceToRootB;
|
|
51
|
+
});
|
|
52
|
+
return {
|
|
53
|
+
data,
|
|
54
|
+
id,
|
|
55
|
+
tags,
|
|
56
|
+
over: sortedRects,
|
|
57
|
+
x,
|
|
58
|
+
y
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function getDropTargets(mounted, x, y, tags) {
|
|
62
|
+
const overlapping = mounted.reduce((acc, c) => {
|
|
63
|
+
const bb = c.target.getBoundingClientRect();
|
|
64
|
+
const overlaps = x >= bb.x && x <= bb.x + bb.width && y >= bb.y && y < bb.y + bb.height;
|
|
65
|
+
if (!overlaps) return acc;
|
|
66
|
+
const v = getVisibleBoundingBox(c.target);
|
|
67
|
+
const visiblyOverlaps = v && x >= v.x && x < v.x + v.width && y >= v.y && y <= v.y + v.height;
|
|
68
|
+
if (!visiblyOverlaps) return acc;
|
|
69
|
+
acc.push({
|
|
70
|
+
id: c.id,
|
|
71
|
+
accepted: c.accepted,
|
|
72
|
+
target: c.target,
|
|
73
|
+
box: bb,
|
|
74
|
+
canDrop: c.accepted.some((c2) => tags.includes(c2)),
|
|
75
|
+
xHalf: x <= bb.x + bb.width / 2 ? "left" : "right",
|
|
76
|
+
yHalf: y <= bb.y + bb.height / 2 ? "top" : "bottom",
|
|
77
|
+
data: c.data
|
|
78
|
+
});
|
|
79
|
+
return acc;
|
|
80
|
+
}, []);
|
|
81
|
+
return overlapping;
|
|
82
|
+
}
|
|
83
|
+
function nodesToRoot(c) {
|
|
84
|
+
let current = 0;
|
|
85
|
+
while (c) {
|
|
86
|
+
current++;
|
|
87
|
+
c = c.parentElement;
|
|
88
|
+
}
|
|
89
|
+
return current;
|
|
90
|
+
}
|
|
91
|
+
function useDraggable({
|
|
92
|
+
id,
|
|
93
|
+
getTags,
|
|
94
|
+
getData,
|
|
95
|
+
onDragStart,
|
|
96
|
+
onDragMove,
|
|
97
|
+
onDragEnd,
|
|
98
|
+
onDragCancel
|
|
99
|
+
}) {
|
|
100
|
+
const hasDragStartedRef = useRef(false);
|
|
101
|
+
const [isActive, setIsActive] = useState(false);
|
|
102
|
+
const store = useDragStore();
|
|
103
|
+
const onPointerDown = useCallback(
|
|
104
|
+
(ev) => {
|
|
105
|
+
const startX = ev.clientX;
|
|
106
|
+
const startY = ev.clientY;
|
|
107
|
+
if (ev.pointerType === "mouse" && ev.button !== 0) return;
|
|
108
|
+
const c = new AbortController();
|
|
109
|
+
let anim = null;
|
|
110
|
+
const clickFix = (ev2) => {
|
|
111
|
+
ev2.preventDefault();
|
|
112
|
+
ev2.stopPropagation();
|
|
113
|
+
ev2.stopImmediatePropagation();
|
|
114
|
+
globalThis.removeEventListener("click", clickFix, { capture: true });
|
|
115
|
+
};
|
|
116
|
+
globalThis.addEventListener("click", clickFix, { capture: true });
|
|
117
|
+
document.addEventListener(
|
|
118
|
+
"pointermove",
|
|
119
|
+
(ev2) => {
|
|
120
|
+
if (!hasDragStartedRef.current && !shouldDragStart(ev2, startX, startY)) return;
|
|
121
|
+
const x = ev2.clientX;
|
|
122
|
+
const y = ev2.clientY;
|
|
123
|
+
if (!hasDragStartedRef.current) {
|
|
124
|
+
hasDragStartedRef.current = true;
|
|
125
|
+
const data = getData();
|
|
126
|
+
const tags = getTags();
|
|
127
|
+
const s = store.getState();
|
|
128
|
+
const next = computeActiveDrag(s.mounted, tags, data, id, x, y);
|
|
129
|
+
store.setState({ active: next });
|
|
130
|
+
onDragStart?.(next);
|
|
131
|
+
setIsActive(true);
|
|
132
|
+
}
|
|
133
|
+
if (anim) return;
|
|
134
|
+
anim = requestAnimationFrame(() => {
|
|
135
|
+
const s = store.getState();
|
|
136
|
+
const data = s.active.data;
|
|
137
|
+
const tags = s.active.tags;
|
|
138
|
+
const next = computeActiveDrag(s.mounted, tags, data, id, x, y);
|
|
139
|
+
store.setState({ active: next });
|
|
140
|
+
onDragMove?.(next);
|
|
141
|
+
anim = null;
|
|
142
|
+
});
|
|
143
|
+
},
|
|
144
|
+
{ signal: c.signal }
|
|
145
|
+
);
|
|
146
|
+
document.addEventListener(
|
|
147
|
+
"pointerup",
|
|
148
|
+
(ev2) => {
|
|
149
|
+
c.abort();
|
|
150
|
+
setTimeout(() => globalThis.removeEventListener("click", clickFix, { capture: true }));
|
|
151
|
+
if (!hasDragStartedRef.current) return;
|
|
152
|
+
endDrag(ev2.clientX, ev2.clientY);
|
|
153
|
+
},
|
|
154
|
+
{ signal: c.signal, capture: true }
|
|
155
|
+
);
|
|
156
|
+
document.addEventListener(
|
|
157
|
+
"pointercancel",
|
|
158
|
+
(ev2) => {
|
|
159
|
+
c.abort();
|
|
160
|
+
setTimeout(() => globalThis.removeEventListener("click", clickFix, { capture: true }));
|
|
161
|
+
if (!hasDragStartedRef.current) return;
|
|
162
|
+
endDrag(ev2.clientX, ev2.clientY, true);
|
|
163
|
+
},
|
|
164
|
+
{ signal: c.signal }
|
|
165
|
+
);
|
|
166
|
+
document.addEventListener(
|
|
167
|
+
"keydown",
|
|
168
|
+
(ev2) => {
|
|
169
|
+
c.abort();
|
|
170
|
+
setTimeout(() => globalThis.removeEventListener("click", clickFix, { capture: true }));
|
|
171
|
+
if (!hasDragStartedRef.current) return;
|
|
172
|
+
if (ev2.key === "Escape") {
|
|
173
|
+
ev2.preventDefault();
|
|
174
|
+
ev2.stopPropagation();
|
|
175
|
+
const s = store.getState().active;
|
|
176
|
+
endDrag(s.x, s.y, true);
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
{ signal: c.signal, capture: true }
|
|
180
|
+
);
|
|
181
|
+
function endDrag(x, y, isCancel = false) {
|
|
182
|
+
const s = store.getState();
|
|
183
|
+
setIsActive(false);
|
|
184
|
+
const next = computeActiveDrag(
|
|
185
|
+
s.mounted,
|
|
186
|
+
s.active.tags,
|
|
187
|
+
s.active.data,
|
|
188
|
+
s.active.id,
|
|
189
|
+
x,
|
|
190
|
+
y
|
|
191
|
+
);
|
|
192
|
+
if (isCancel) {
|
|
193
|
+
onDragCancel?.(next);
|
|
194
|
+
} else {
|
|
195
|
+
onDragEnd?.(next);
|
|
196
|
+
}
|
|
197
|
+
hasDragStartedRef.current = false;
|
|
198
|
+
store.setState({ active: null });
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
[getData, getTags, id, onDragCancel, onDragEnd, onDragMove, onDragStart, store]
|
|
202
|
+
);
|
|
203
|
+
return { onPointerDown, isActive };
|
|
204
|
+
}
|
|
205
|
+
function shouldDragStart(ev, startX, startY) {
|
|
206
|
+
const deltaY = Math.abs(ev.clientY - startY);
|
|
207
|
+
const deltaX = Math.abs(ev.clientX - startX);
|
|
208
|
+
return deltaX > 10 || deltaY > 10;
|
|
209
|
+
}
|
|
210
|
+
function useDroppable({ id, accepted, data, active = true }) {
|
|
211
|
+
const [target, ref] = useState(null);
|
|
212
|
+
const store = useDragStore();
|
|
213
|
+
const over = useStore(store, (s) => s.active?.over.find((c) => c.id === id));
|
|
214
|
+
const isNearestOver = useStore(store, (s) => s.active?.over.at(-1) === over);
|
|
215
|
+
const canDrop = !!over?.canDrop;
|
|
216
|
+
const isOver = !!over;
|
|
217
|
+
const isTarget = useStore(store, (s) => arrayOverlap(s.active?.tags ?? [], accepted));
|
|
218
|
+
useEffect(() => {
|
|
219
|
+
if (!target || !active) return;
|
|
220
|
+
store.setState((prev) => {
|
|
221
|
+
if (prev.mounted.find((c) => c.id === id)) return prev;
|
|
222
|
+
return {
|
|
223
|
+
mounted: [...prev.mounted, { accepted, id, target, data }]
|
|
224
|
+
};
|
|
225
|
+
});
|
|
226
|
+
return () => store.setState((prev) => {
|
|
227
|
+
return { mounted: prev.mounted.filter((c) => c.id !== id) };
|
|
228
|
+
});
|
|
229
|
+
}, [accepted, active, data, id, store, target]);
|
|
230
|
+
return { ref, isOver, isTarget, canDrop, yHalf: over?.yHalf, xHalf: over?.xHalf, isNearestOver };
|
|
231
|
+
}
|
|
232
|
+
const useEdgeScroll = ({
|
|
233
|
+
isActive,
|
|
234
|
+
threshold = 50,
|
|
235
|
+
direction = "both",
|
|
236
|
+
maxSpeed = 20,
|
|
237
|
+
acceleration = 0.5
|
|
238
|
+
}) => {
|
|
239
|
+
const [container, ref] = useState(null);
|
|
240
|
+
const scrollIntervalX = useRef(null);
|
|
241
|
+
const scrollIntervalY = useRef(null);
|
|
242
|
+
const speedX = useRef(0);
|
|
243
|
+
const speedY = useRef(0);
|
|
244
|
+
const stopScrollX = useCallback(() => {
|
|
245
|
+
if (scrollIntervalX.current) {
|
|
246
|
+
clearInterval(scrollIntervalX.current);
|
|
247
|
+
scrollIntervalX.current = null;
|
|
248
|
+
speedX.current = 0;
|
|
249
|
+
}
|
|
250
|
+
}, []);
|
|
251
|
+
const stopScrollY = useCallback(() => {
|
|
252
|
+
if (scrollIntervalY.current) {
|
|
253
|
+
clearInterval(scrollIntervalY.current);
|
|
254
|
+
scrollIntervalY.current = null;
|
|
255
|
+
speedY.current = 0;
|
|
256
|
+
}
|
|
257
|
+
}, []);
|
|
258
|
+
const stopScrolling = useCallback(() => {
|
|
259
|
+
stopScrollX();
|
|
260
|
+
stopScrollY();
|
|
261
|
+
}, [stopScrollX, stopScrollY]);
|
|
262
|
+
const startScrollingXLeft = useCallback(() => {
|
|
263
|
+
if (!scrollIntervalX.current) {
|
|
264
|
+
scrollIntervalX.current = setInterval(() => {
|
|
265
|
+
speedX.current = Math.min(speedX.current + acceleration, maxSpeed);
|
|
266
|
+
container?.scrollBy({ left: speedX.current * -1 });
|
|
267
|
+
}, 16);
|
|
268
|
+
}
|
|
269
|
+
}, [acceleration, container, maxSpeed]);
|
|
270
|
+
const startScrollingXRight = useCallback(() => {
|
|
271
|
+
if (!scrollIntervalX.current) {
|
|
272
|
+
scrollIntervalX.current = setInterval(() => {
|
|
273
|
+
speedX.current = Math.min(speedX.current + acceleration, maxSpeed);
|
|
274
|
+
container?.scrollBy({ left: speedX.current });
|
|
275
|
+
}, 16);
|
|
276
|
+
}
|
|
277
|
+
}, [acceleration, container, maxSpeed]);
|
|
278
|
+
const startScrollTop = useCallback(() => {
|
|
279
|
+
if (!scrollIntervalY.current) {
|
|
280
|
+
scrollIntervalY.current = setInterval(() => {
|
|
281
|
+
speedY.current = Math.min(speedY.current + acceleration, maxSpeed);
|
|
282
|
+
container?.scrollBy({ top: speedY.current * -1 });
|
|
283
|
+
}, 16);
|
|
284
|
+
}
|
|
285
|
+
}, [acceleration, container, maxSpeed]);
|
|
286
|
+
const startScrollBottom = useCallback(() => {
|
|
287
|
+
if (!scrollIntervalY.current) {
|
|
288
|
+
scrollIntervalY.current = setInterval(() => {
|
|
289
|
+
speedY.current = Math.min(speedY.current + acceleration, maxSpeed);
|
|
290
|
+
container?.scrollBy({ top: speedY.current });
|
|
291
|
+
}, 16);
|
|
292
|
+
}
|
|
293
|
+
}, [acceleration, container, maxSpeed]);
|
|
294
|
+
const controllerRef = useRef(null);
|
|
295
|
+
useEffect(() => {
|
|
296
|
+
if (!isActive) {
|
|
297
|
+
controllerRef.current?.abort();
|
|
298
|
+
controllerRef.current = null;
|
|
299
|
+
stopScrolling();
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
if (!container) return;
|
|
303
|
+
const handleMouseMove = (event) => {
|
|
304
|
+
const containerRect = container.getBoundingClientRect();
|
|
305
|
+
const distanceToTop = Math.abs(event.clientY - containerRect.top);
|
|
306
|
+
const distanceToBottom = Math.abs(event.clientY - containerRect.bottom);
|
|
307
|
+
const distanceToLeft = Math.abs(event.clientX - containerRect.left);
|
|
308
|
+
const distanceToRight = Math.abs(event.clientX - containerRect.right);
|
|
309
|
+
if (direction === "both" || direction === "horizontal") {
|
|
310
|
+
if (distanceToLeft < threshold) {
|
|
311
|
+
startScrollingXLeft();
|
|
312
|
+
} else if (distanceToRight < threshold) {
|
|
313
|
+
startScrollingXRight();
|
|
314
|
+
} else {
|
|
315
|
+
stopScrollX();
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
if (direction === "both" || direction === "vertical") {
|
|
319
|
+
if (distanceToTop < threshold) {
|
|
320
|
+
startScrollTop();
|
|
321
|
+
} else if (distanceToBottom < threshold) {
|
|
322
|
+
startScrollBottom();
|
|
323
|
+
} else {
|
|
324
|
+
stopScrollY();
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
const controller = new AbortController();
|
|
329
|
+
controllerRef.current = controller;
|
|
330
|
+
container.addEventListener("pointermove", handleMouseMove, {
|
|
331
|
+
passive: false,
|
|
332
|
+
capture: true,
|
|
333
|
+
signal: controller.signal
|
|
334
|
+
});
|
|
335
|
+
container.addEventListener("pointerleave", stopScrolling);
|
|
336
|
+
return () => {
|
|
337
|
+
controller.abort();
|
|
338
|
+
stopScrolling();
|
|
339
|
+
};
|
|
340
|
+
}, [
|
|
341
|
+
isActive,
|
|
342
|
+
threshold,
|
|
343
|
+
direction,
|
|
344
|
+
maxSpeed,
|
|
345
|
+
acceleration,
|
|
346
|
+
container,
|
|
347
|
+
stopScrolling,
|
|
348
|
+
startScrollingXLeft,
|
|
349
|
+
startScrollingXRight,
|
|
350
|
+
stopScrollX,
|
|
351
|
+
startScrollTop,
|
|
352
|
+
startScrollBottom,
|
|
353
|
+
stopScrollY
|
|
354
|
+
]);
|
|
355
|
+
return ref;
|
|
356
|
+
};
|
|
357
|
+
function useMenuTrigger(parameters) {
|
|
358
|
+
const BOUNDARY_OFFSET = 2;
|
|
359
|
+
const {
|
|
360
|
+
disabled = false,
|
|
361
|
+
rootRef: externalRef,
|
|
362
|
+
open,
|
|
363
|
+
setOpen,
|
|
364
|
+
setTriggerElement,
|
|
365
|
+
positionerRef,
|
|
366
|
+
allowMouseUpTriggerRef
|
|
367
|
+
} = parameters;
|
|
368
|
+
const triggerRef = React.useRef(null);
|
|
369
|
+
const mergedRef = useForkRef(externalRef, triggerRef);
|
|
370
|
+
const allowMouseUpTriggerTimeoutRef = React.useRef(-1);
|
|
371
|
+
const {
|
|
372
|
+
getButtonProps,
|
|
373
|
+
buttonRef
|
|
374
|
+
} = useButton({
|
|
375
|
+
disabled,
|
|
376
|
+
buttonRef: mergedRef
|
|
377
|
+
});
|
|
378
|
+
const handleRef = useForkRef(buttonRef, setTriggerElement);
|
|
379
|
+
React.useEffect(() => {
|
|
380
|
+
if (!open) {
|
|
381
|
+
allowMouseUpTriggerRef.current = false;
|
|
382
|
+
}
|
|
383
|
+
}, [allowMouseUpTriggerRef, open]);
|
|
384
|
+
const getTriggerProps = React.useCallback((externalProps) => {
|
|
385
|
+
return mergeProps({
|
|
386
|
+
"aria-haspopup": "menu",
|
|
387
|
+
tabIndex: 0,
|
|
388
|
+
// this is needed to make the button focused after click in Safari
|
|
389
|
+
ref: handleRef,
|
|
390
|
+
onMouseDown: (event) => {
|
|
391
|
+
if (open) {
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
allowMouseUpTriggerTimeoutRef.current = window.setTimeout(() => {
|
|
395
|
+
allowMouseUpTriggerRef.current = true;
|
|
396
|
+
}, 200);
|
|
397
|
+
const doc = ownerDocument(event.currentTarget);
|
|
398
|
+
function handleMouseUp(mouseEvent) {
|
|
399
|
+
if (!triggerRef.current) {
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
if (allowMouseUpTriggerTimeoutRef.current !== -1) {
|
|
403
|
+
clearTimeout(allowMouseUpTriggerTimeoutRef.current);
|
|
404
|
+
allowMouseUpTriggerTimeoutRef.current = -1;
|
|
405
|
+
}
|
|
406
|
+
allowMouseUpTriggerRef.current = false;
|
|
407
|
+
const mouseUpTarget = mouseEvent.target;
|
|
408
|
+
if (contains(triggerRef.current, mouseUpTarget) || contains(positionerRef.current, mouseUpTarget) || mouseUpTarget === triggerRef.current) {
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
const bounds = getPseudoElementBounds(triggerRef.current);
|
|
412
|
+
if (mouseEvent.clientX >= bounds.left - BOUNDARY_OFFSET && mouseEvent.clientX <= bounds.right + BOUNDARY_OFFSET && mouseEvent.clientY >= bounds.top - BOUNDARY_OFFSET && mouseEvent.clientY <= bounds.bottom + BOUNDARY_OFFSET) {
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
setOpen(false, mouseEvent);
|
|
416
|
+
}
|
|
417
|
+
doc.addEventListener("mouseup", handleMouseUp, {
|
|
418
|
+
once: true
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
}, externalProps, getButtonProps);
|
|
422
|
+
}, [getButtonProps, handleRef, open, setOpen, positionerRef, allowMouseUpTriggerRef]);
|
|
423
|
+
return React.useMemo(() => ({
|
|
424
|
+
getTriggerProps,
|
|
425
|
+
triggerRef: handleRef
|
|
426
|
+
}), [getTriggerProps, handleRef]);
|
|
427
|
+
}
|
|
428
|
+
const MenuTrigger = /* @__PURE__ */ React.forwardRef(function MenuTrigger2(props, forwardedRef) {
|
|
429
|
+
const {
|
|
430
|
+
render,
|
|
431
|
+
className,
|
|
432
|
+
disabled = false,
|
|
433
|
+
...other
|
|
434
|
+
} = props;
|
|
435
|
+
const {
|
|
436
|
+
triggerProps: rootTriggerProps,
|
|
437
|
+
disabled: menuDisabled,
|
|
438
|
+
setTriggerElement,
|
|
439
|
+
open,
|
|
440
|
+
mounted,
|
|
441
|
+
setOpen,
|
|
442
|
+
allowMouseUpTriggerRef,
|
|
443
|
+
positionerRef
|
|
444
|
+
} = useMenuRootContext();
|
|
445
|
+
const {
|
|
446
|
+
getTriggerProps
|
|
447
|
+
} = useMenuTrigger({
|
|
448
|
+
disabled: disabled || menuDisabled,
|
|
449
|
+
rootRef: forwardedRef,
|
|
450
|
+
setTriggerElement,
|
|
451
|
+
open,
|
|
452
|
+
setOpen,
|
|
453
|
+
allowMouseUpTriggerRef,
|
|
454
|
+
positionerRef
|
|
455
|
+
});
|
|
456
|
+
const state = React.useMemo(() => ({
|
|
457
|
+
disabled,
|
|
458
|
+
open: mounted
|
|
459
|
+
}), [disabled, mounted]);
|
|
460
|
+
const propGetter = React.useCallback((externalProps) => mergeProps(rootTriggerProps, externalProps, getTriggerProps), [getTriggerProps, rootTriggerProps]);
|
|
461
|
+
const {
|
|
462
|
+
renderElement
|
|
463
|
+
} = useComponentRenderer({
|
|
464
|
+
render: render || "button",
|
|
465
|
+
className,
|
|
466
|
+
state,
|
|
467
|
+
propGetter,
|
|
468
|
+
customStyleHookMapping: pressableTriggerOpenStateMapping,
|
|
469
|
+
extraProps: other
|
|
470
|
+
});
|
|
471
|
+
return renderElement();
|
|
472
|
+
});
|
|
473
|
+
process.env.NODE_ENV !== "production" ? MenuTrigger.propTypes = {
|
|
474
|
+
// ┌────────────────────────────── Warning ──────────────────────────────┐
|
|
475
|
+
// │ These PropTypes are generated from the TypeScript type definitions. │
|
|
476
|
+
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
|
|
477
|
+
// └─────────────────────────────────────────────────────────────────────┘
|
|
478
|
+
/**
|
|
479
|
+
* @ignore
|
|
480
|
+
*/
|
|
481
|
+
children: PropTypes.node,
|
|
482
|
+
/**
|
|
483
|
+
* CSS class applied to the element, or a function that
|
|
484
|
+
* returns a class based on the component’s state.
|
|
485
|
+
*/
|
|
486
|
+
className: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
|
|
487
|
+
/**
|
|
488
|
+
* Whether the component should ignore user interaction.
|
|
489
|
+
* @default false
|
|
490
|
+
*/
|
|
491
|
+
disabled: PropTypes.bool,
|
|
492
|
+
/**
|
|
493
|
+
* Allows you to replace the component’s HTML element
|
|
494
|
+
* with a different tag, or compose it with another component.
|
|
495
|
+
*
|
|
496
|
+
* Accepts a `ReactElement` or a function that returns the element to render.
|
|
497
|
+
*/
|
|
498
|
+
render: PropTypes.oneOfType([PropTypes.element, PropTypes.func])
|
|
499
|
+
} : void 0;
|
|
500
|
+
const canAgg = (c, base) => {
|
|
501
|
+
return Boolean(c.aggFnDefault ?? c.aggFnsAllowed?.length ?? base.aggFnsAllowed?.length);
|
|
502
|
+
};
|
|
503
|
+
const canMeasure = (c, base) => {
|
|
504
|
+
return Boolean(
|
|
505
|
+
c.measureFnDefault ?? c.measureFnsAllowed?.length ?? base.measureFnsAllowed?.length
|
|
506
|
+
);
|
|
507
|
+
};
|
|
508
|
+
function useAggregationSource(source) {
|
|
509
|
+
const { api, state: sx } = useGrid();
|
|
510
|
+
const columns = sx.columns.use();
|
|
511
|
+
const aggModel = sx.aggModel.use();
|
|
512
|
+
return useMemo(() => {
|
|
513
|
+
if (source !== "aggregations") return [];
|
|
514
|
+
const entries = Object.entries(aggModel);
|
|
515
|
+
const active = [];
|
|
516
|
+
for (const [key, m] of entries) {
|
|
517
|
+
let column = api.columnById(key) ?? null;
|
|
518
|
+
if (column && (api.columnIsPivot(column) || api.columnIsGridGenerated(column))) column = null;
|
|
519
|
+
const secondaryLabel = typeof m.fn === "string" ? `(${m.fn})` : "Fn(x)";
|
|
520
|
+
const onToggle = () => sx.aggModel.set((prev) => {
|
|
521
|
+
const next = { ...prev };
|
|
522
|
+
delete next[key];
|
|
523
|
+
return next;
|
|
524
|
+
});
|
|
525
|
+
if (column) {
|
|
526
|
+
active.push({
|
|
527
|
+
kind: "column",
|
|
528
|
+
active: true,
|
|
529
|
+
label: column.headerName ?? column.id,
|
|
530
|
+
secondaryLabel,
|
|
531
|
+
onClick: onToggle,
|
|
532
|
+
draggable: false,
|
|
533
|
+
dragTags: [],
|
|
534
|
+
dropId: `agg-${column.id}`,
|
|
535
|
+
column,
|
|
536
|
+
isAggregation: true,
|
|
537
|
+
dropTags: [],
|
|
538
|
+
dropData: {}
|
|
539
|
+
});
|
|
540
|
+
} else {
|
|
541
|
+
active.push({
|
|
542
|
+
kind: "column",
|
|
543
|
+
active: true,
|
|
544
|
+
label: key,
|
|
545
|
+
secondaryLabel,
|
|
546
|
+
onClick: onToggle,
|
|
547
|
+
draggable: false,
|
|
548
|
+
dragTags: [],
|
|
549
|
+
dropId: `agg-${key}`,
|
|
550
|
+
dropTags: [],
|
|
551
|
+
dropData: {}
|
|
552
|
+
});
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
const base = sx.columnBase.peek();
|
|
556
|
+
const inactive = columns.filter((c) => {
|
|
557
|
+
const agg = c.aggFnDefault ?? c.aggFnsAllowed?.length ?? base.aggFnsAllowed?.length;
|
|
558
|
+
const isAgged = !!aggModel[c.id];
|
|
559
|
+
return !!agg && !isAgged;
|
|
560
|
+
}).map((c) => {
|
|
561
|
+
const aggFn = c.aggFnDefault ?? c.aggFnsAllowed?.[0] ?? base.aggFnsAllowed?.at(0);
|
|
562
|
+
const onToggle = () => sx.aggModel.set((prev) => aggFn ? { ...prev, [c.id]: { fn: aggFn } } : prev);
|
|
563
|
+
const aggName = typeof aggFn === "string" ? `(${aggFn})` : "Fn(x)";
|
|
564
|
+
return {
|
|
565
|
+
kind: "column",
|
|
566
|
+
label: c.headerName ?? c.id,
|
|
567
|
+
active: false,
|
|
568
|
+
secondaryLabel: aggName,
|
|
569
|
+
onClick: onToggle,
|
|
570
|
+
draggable: false,
|
|
571
|
+
dropId: `agg-${c.id}`,
|
|
572
|
+
dropTags: [],
|
|
573
|
+
dragTags: [],
|
|
574
|
+
dropData: {}
|
|
575
|
+
};
|
|
576
|
+
});
|
|
577
|
+
return [...active, ...inactive];
|
|
578
|
+
}, [aggModel, api, columns, source, sx.aggModel, sx.columnBase]);
|
|
579
|
+
}
|
|
580
|
+
function useMeasuresSource(source) {
|
|
581
|
+
const { api, state: sx } = useGrid();
|
|
582
|
+
const columns = sx.columns.use();
|
|
583
|
+
const measureModel = sx.measureModel.use();
|
|
584
|
+
return useMemo(() => {
|
|
585
|
+
if (source !== "measures") return [];
|
|
586
|
+
const entries = Object.entries(measureModel);
|
|
587
|
+
const active = [];
|
|
588
|
+
for (const [key, m] of entries) {
|
|
589
|
+
let column = api.columnById(key) ?? null;
|
|
590
|
+
if (column && (api.columnIsPivot(column) || api.columnIsGridGenerated(column))) column = null;
|
|
591
|
+
const secondaryLabel = typeof m.fn === "string" ? `(${m.fn})` : "Fn(x)";
|
|
592
|
+
const onToggle = () => sx.measureModel.set((prev) => {
|
|
593
|
+
const next = { ...prev };
|
|
594
|
+
delete next[key];
|
|
595
|
+
return next;
|
|
596
|
+
});
|
|
597
|
+
if (column) {
|
|
598
|
+
active.push({
|
|
599
|
+
kind: "column",
|
|
600
|
+
active: true,
|
|
601
|
+
label: column.headerName ?? column.id,
|
|
602
|
+
secondaryLabel,
|
|
603
|
+
onClick: onToggle,
|
|
604
|
+
draggable: false,
|
|
605
|
+
dragTags: [],
|
|
606
|
+
dropTags: [],
|
|
607
|
+
dropData: {},
|
|
608
|
+
column,
|
|
609
|
+
isMeasure: true,
|
|
610
|
+
dropId: `measure-${key}`
|
|
611
|
+
});
|
|
612
|
+
} else {
|
|
613
|
+
active.push({
|
|
614
|
+
kind: "column",
|
|
615
|
+
active: true,
|
|
616
|
+
label: key,
|
|
617
|
+
secondaryLabel,
|
|
618
|
+
onClick: onToggle,
|
|
619
|
+
draggable: false,
|
|
620
|
+
dragTags: [],
|
|
621
|
+
dropTags: [],
|
|
622
|
+
dropData: {},
|
|
623
|
+
dropId: `measure-${key}`
|
|
624
|
+
});
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
const base = sx.columnBase.peek();
|
|
628
|
+
const inactive = columns.filter((c) => {
|
|
629
|
+
const measure = c.measureFnDefault ?? c.measureFnsAllowed?.length ?? base.measureFnsAllowed?.length;
|
|
630
|
+
const isMeasured = !!measureModel[c.id];
|
|
631
|
+
return !!measure && !isMeasured;
|
|
632
|
+
}).map((c) => {
|
|
633
|
+
const measureFn = c.measureFnDefault ?? c.measureFnsAllowed?.[0] ?? base.measureFnsAllowed?.at(0);
|
|
634
|
+
const measureName = typeof measureFn === "string" ? `(${measureFn})` : "Fn(x)";
|
|
635
|
+
const onToggle = () => sx.measureModel.set(
|
|
636
|
+
(prev) => measureFn ? { ...prev, [c.id]: { fn: measureFn } } : prev
|
|
637
|
+
);
|
|
638
|
+
return {
|
|
639
|
+
kind: "column",
|
|
640
|
+
label: c.headerName ?? c.id,
|
|
641
|
+
active: false,
|
|
642
|
+
secondaryLabel: measureName,
|
|
643
|
+
onClick: onToggle,
|
|
644
|
+
draggable: false,
|
|
645
|
+
dragTags: [],
|
|
646
|
+
dropTags: [],
|
|
647
|
+
dropData: {},
|
|
648
|
+
dropId: `measure-${c.id}`
|
|
649
|
+
};
|
|
650
|
+
});
|
|
651
|
+
return [...active, ...inactive];
|
|
652
|
+
}, [api, columns, measureModel, source, sx.columnBase, sx.measureModel]);
|
|
653
|
+
}
|
|
654
|
+
function useRowGroupsSource(source, dir = "horizontal") {
|
|
655
|
+
const { api, state: sx } = useGrid();
|
|
656
|
+
const rowModel = sx.rowGroupModel.use();
|
|
657
|
+
const columns = sx.columns.use();
|
|
658
|
+
const aggModel = sx.aggModel.use();
|
|
659
|
+
const measureModel = sx.measureModel.use();
|
|
660
|
+
const base = sx.columnBase.use();
|
|
661
|
+
return useMemo(() => {
|
|
662
|
+
if (source !== "row-groups") return [];
|
|
663
|
+
const activeItems = rowModel.map((c) => api.columnById(c)).map((c) => {
|
|
664
|
+
const onToggle = () => sx.rowGroupModel.set((prev) => prev.filter((x) => x !== c.id));
|
|
665
|
+
const dragTags = ["row-group"];
|
|
666
|
+
if (!api.columnIsVisible(c, true)) dragTags.push("columns");
|
|
667
|
+
if (api.columnIsPivotable(c)) dragTags.push("column-pivot");
|
|
668
|
+
if (!aggModel[c.id] && canAgg(c, base)) dragTags.push("aggregations");
|
|
669
|
+
if (!measureModel[c.id] && canMeasure(c, base)) dragTags.push("measures");
|
|
670
|
+
const dragEnd = (d) => {
|
|
671
|
+
const over = d.over.at(-1);
|
|
672
|
+
if (!over || !over.canDrop) return;
|
|
673
|
+
const isBefore = dir === "horizontal" ? (sx.rtl.peek() ? "right" : "left") === over.xHalf : over.yHalf === "top";
|
|
674
|
+
if (over.data.target === "row-group") {
|
|
675
|
+
const id = over.data.id;
|
|
676
|
+
if (id === c.id) return;
|
|
677
|
+
const myIndex = rowModel.indexOf(c.id);
|
|
678
|
+
const next = [...rowModel];
|
|
679
|
+
next.splice(myIndex, 1);
|
|
680
|
+
const targetIndex = next.indexOf(id);
|
|
681
|
+
next.splice(targetIndex + (isBefore ? 0 : 1), 0, c.id);
|
|
682
|
+
sx.rowGroupModel.set(next);
|
|
683
|
+
return;
|
|
684
|
+
}
|
|
685
|
+
if (over.id === "columns-pills") {
|
|
686
|
+
api.columnUpdate(c, { hide: false });
|
|
687
|
+
api.columnMoveToVisibleIndex([c.id], 0);
|
|
688
|
+
sx.rowGroupModel.set((prev) => prev.filter((x) => x !== c.id));
|
|
689
|
+
return;
|
|
690
|
+
}
|
|
691
|
+
if (over.data.target === "columns") {
|
|
692
|
+
const id = over.data.id;
|
|
693
|
+
if (id === c.id) return;
|
|
694
|
+
api.columnUpdate(c, { hide: false });
|
|
695
|
+
if (isBefore) api.columnMoveBefore([c.id], id);
|
|
696
|
+
else api.columnMoveAfter([c.id], id);
|
|
697
|
+
sx.rowGroupModel.set((prev) => prev.filter((x) => x !== c.id));
|
|
698
|
+
return;
|
|
699
|
+
}
|
|
700
|
+
if (over.id === "column-pivots-pills") {
|
|
701
|
+
sx.rowGroupModel.set((prev) => prev.filter((x) => x !== c.id));
|
|
702
|
+
sx.columnPivotModel.set((prev) => [...prev, c.id]);
|
|
703
|
+
return;
|
|
704
|
+
}
|
|
705
|
+
if (over.data.target === "column-pivot") {
|
|
706
|
+
const id = over.data.id;
|
|
707
|
+
if (id === c.id) return;
|
|
708
|
+
sx.rowGroupModel.set((prev) => prev.filter((x) => x !== c.id));
|
|
709
|
+
sx.columnPivotModel.set((prev) => {
|
|
710
|
+
const next = [...prev];
|
|
711
|
+
const index = next.indexOf(id) + (isBefore ? 0 : 1);
|
|
712
|
+
next.splice(index, 0, c.id);
|
|
713
|
+
return next;
|
|
714
|
+
});
|
|
715
|
+
}
|
|
716
|
+
if (over.id === "aggregations-pills") {
|
|
717
|
+
const aggFn = c.aggFnDefault ?? c.aggFnsAllowed?.at(0) ?? base.aggFnsAllowed?.at(0);
|
|
718
|
+
if (!aggFn) return;
|
|
719
|
+
sx.aggModel.set((prev) => ({ ...prev, [c.id]: { fn: aggFn } }));
|
|
720
|
+
sx.rowGroupModel.set((prev) => prev.filter((x) => x !== c.id));
|
|
721
|
+
}
|
|
722
|
+
if (over.id === "measures-pills") {
|
|
723
|
+
const measureFn = c.measureFnDefault ?? c.measureFnsAllowed?.at(0) ?? base.measureFnsAllowed?.at(0);
|
|
724
|
+
if (!measureFn) return;
|
|
725
|
+
sx.measureModel.set((prev) => ({ ...prev, [c.id]: { fn: measureFn } }));
|
|
726
|
+
sx.rowGroupModel.set((prev) => prev.filter((x) => x !== c.id));
|
|
727
|
+
}
|
|
728
|
+
};
|
|
729
|
+
return {
|
|
730
|
+
kind: "row-group",
|
|
731
|
+
label: c.headerName ?? c.id,
|
|
732
|
+
active: true,
|
|
733
|
+
onClick: onToggle,
|
|
734
|
+
draggable: true,
|
|
735
|
+
isRowGroup: true,
|
|
736
|
+
dragEnd,
|
|
737
|
+
dragTags,
|
|
738
|
+
dropTags: ["row-group"],
|
|
739
|
+
dropData: { target: "row-group", id: c.id },
|
|
740
|
+
dropId: `row-group-${c.id}`
|
|
741
|
+
};
|
|
742
|
+
});
|
|
743
|
+
const inactiveItems = columns.filter((c) => api.columnIsRowGroupable(c) && !rowModel.includes(c.id)).map((c) => {
|
|
744
|
+
const onToggle = () => sx.rowGroupModel.set((prev) => [...prev, c.id]);
|
|
745
|
+
return {
|
|
746
|
+
kind: "row-group",
|
|
747
|
+
label: c.headerName ?? c.id,
|
|
748
|
+
active: false,
|
|
749
|
+
onClick: onToggle,
|
|
750
|
+
draggable: false,
|
|
751
|
+
dragTags: [],
|
|
752
|
+
dropTags: [],
|
|
753
|
+
dropData: {},
|
|
754
|
+
dropId: `row-group-${c.id}`
|
|
755
|
+
};
|
|
756
|
+
});
|
|
757
|
+
return [...activeItems, ...inactiveItems];
|
|
758
|
+
}, [
|
|
759
|
+
aggModel,
|
|
760
|
+
api,
|
|
761
|
+
base,
|
|
762
|
+
columns,
|
|
763
|
+
dir,
|
|
764
|
+
measureModel,
|
|
765
|
+
rowModel,
|
|
766
|
+
source,
|
|
767
|
+
sx.aggModel,
|
|
768
|
+
sx.columnPivotModel,
|
|
769
|
+
sx.measureModel,
|
|
770
|
+
sx.rowGroupModel,
|
|
771
|
+
sx.rtl
|
|
772
|
+
]);
|
|
773
|
+
}
|
|
774
|
+
function useColumnPivotSource(source, dir = "horizontal") {
|
|
775
|
+
const { api, state: sx } = useGrid();
|
|
776
|
+
const columns = sx.columns.use();
|
|
777
|
+
const pivotModel = sx.columnPivotModel.use();
|
|
778
|
+
const aggModel = sx.aggModel.use();
|
|
779
|
+
const measureModel = sx.measureModel.use();
|
|
780
|
+
const base = sx.columnBase.use();
|
|
781
|
+
return useMemo(() => {
|
|
782
|
+
if (source !== "column-pivots") return [];
|
|
783
|
+
const appliedPivots = new Set(pivotModel);
|
|
784
|
+
const canBePivoted = columns.filter(
|
|
785
|
+
(c) => !appliedPivots.has(c.id) && api.columnIsPivotable(c)
|
|
786
|
+
);
|
|
787
|
+
const pivotedColumns = pivotModel.map((c) => api.columnById(c));
|
|
788
|
+
const activeItems = pivotedColumns.map((c) => {
|
|
789
|
+
const onToggle = () => sx.columnPivotModel.set((prev) => prev.filter((x) => x !== c.id));
|
|
790
|
+
const dragTags = ["column-pivot"];
|
|
791
|
+
if (api.columnIsRowGroupable(c)) dragTags.push("row-group");
|
|
792
|
+
if (!api.columnIsVisible(c, true)) dragTags.push("columns");
|
|
793
|
+
if (!aggModel[c.id] && canAgg(c, base)) dragTags.push("aggregations");
|
|
794
|
+
if (!measureModel[c.id] && canMeasure(c, base)) dragTags.push("measures");
|
|
795
|
+
const dragEnd = (d) => {
|
|
796
|
+
const over = d.over.at(-1);
|
|
797
|
+
if (!over || !over.canDrop) return;
|
|
798
|
+
const isBefore = dir === "horizontal" ? (sx.rtl.peek() ? "right" : "left") === over.xHalf : over.yHalf === "top";
|
|
799
|
+
if (over.data.target === "column-pivot") {
|
|
800
|
+
const id = over.data.id;
|
|
801
|
+
if (id === c.id) return;
|
|
802
|
+
const myIndex = pivotModel.indexOf(c.id);
|
|
803
|
+
const next = [...pivotModel];
|
|
804
|
+
next.splice(myIndex, 1);
|
|
805
|
+
const targetIndex = next.indexOf(id);
|
|
806
|
+
next.splice(targetIndex + (isBefore ? 0 : 1), 0, c.id);
|
|
807
|
+
sx.columnPivotModel.set(next);
|
|
808
|
+
return;
|
|
809
|
+
}
|
|
810
|
+
if (over.id === "columns-pills") {
|
|
811
|
+
api.columnUpdate(c, { hide: false });
|
|
812
|
+
api.columnMoveToVisibleIndex([c.id], 0);
|
|
813
|
+
sx.columnPivotModel.set((prev) => prev.filter((x) => x !== c.id));
|
|
814
|
+
return;
|
|
815
|
+
}
|
|
816
|
+
if (over.data.target === "columns") {
|
|
817
|
+
const id = over.data.id;
|
|
818
|
+
if (id === c.id) return;
|
|
819
|
+
api.columnUpdate(c, { hide: false });
|
|
820
|
+
if (isBefore) api.columnMoveBefore([c.id], id);
|
|
821
|
+
else api.columnMoveAfter([c.id], id);
|
|
822
|
+
sx.columnPivotModel.set((prev) => prev.filter((x) => x !== c.id));
|
|
823
|
+
return;
|
|
824
|
+
}
|
|
825
|
+
if (over.id === "row-groups-pills") {
|
|
826
|
+
sx.columnPivotModel.set((prev) => prev.filter((x) => x !== c.id));
|
|
827
|
+
sx.rowGroupModel.set((prev) => [...prev, c.id]);
|
|
828
|
+
return;
|
|
829
|
+
}
|
|
830
|
+
if (over.data.target === "row-group") {
|
|
831
|
+
const id = over.data.id;
|
|
832
|
+
if (id === c.id) return;
|
|
833
|
+
sx.columnPivotModel.set((prev) => prev.filter((x) => x !== c.id));
|
|
834
|
+
sx.rowGroupModel.set((prev) => {
|
|
835
|
+
const next = [...prev];
|
|
836
|
+
const index = next.indexOf(id) + (isBefore ? 0 : 1);
|
|
837
|
+
next.splice(index, 0, c.id);
|
|
838
|
+
return next;
|
|
839
|
+
});
|
|
840
|
+
}
|
|
841
|
+
if (over.id === "aggregations-pills") {
|
|
842
|
+
const aggFn = c.aggFnDefault ?? c.aggFnsAllowed?.at(0) ?? base.aggFnsAllowed?.at(0);
|
|
843
|
+
if (!aggFn) return;
|
|
844
|
+
sx.aggModel.set((prev) => ({ ...prev, [c.id]: { fn: aggFn } }));
|
|
845
|
+
sx.columnPivotModel.set((prev) => prev.filter((x) => x !== c.id));
|
|
846
|
+
}
|
|
847
|
+
if (over.id === "measures-pills") {
|
|
848
|
+
const measureFn = c.measureFnDefault ?? c.measureFnsAllowed?.at(0) ?? base.measureFnsAllowed?.at(0);
|
|
849
|
+
if (!measureFn) return;
|
|
850
|
+
sx.measureModel.set((prev) => ({ ...prev, [c.id]: { fn: measureFn } }));
|
|
851
|
+
sx.columnPivotModel.set((prev) => prev.filter((x) => x !== c.id));
|
|
852
|
+
}
|
|
853
|
+
};
|
|
854
|
+
return {
|
|
855
|
+
kind: "column-pivot",
|
|
856
|
+
label: c.headerName ?? c.id,
|
|
857
|
+
active: true,
|
|
858
|
+
onClick: onToggle,
|
|
859
|
+
dragEnd,
|
|
860
|
+
dropId: `pivot-${c.id}`,
|
|
861
|
+
draggable: true,
|
|
862
|
+
isColumnPivot: true,
|
|
863
|
+
dragTags,
|
|
864
|
+
dropTags: ["column-pivot"],
|
|
865
|
+
dropData: { target: "column-pivot", id: c.id }
|
|
866
|
+
};
|
|
867
|
+
});
|
|
868
|
+
const inactiveItems = canBePivoted.map((c) => {
|
|
869
|
+
const onToggle = () => sx.columnPivotModel.set((prev) => [...prev, c.id]);
|
|
870
|
+
return {
|
|
871
|
+
kind: "column-pivot",
|
|
872
|
+
label: c.headerName ?? c.id,
|
|
873
|
+
active: false,
|
|
874
|
+
onClick: onToggle,
|
|
875
|
+
draggable: false,
|
|
876
|
+
dropId: `pivot-${c.id}`,
|
|
877
|
+
dragTags: [],
|
|
878
|
+
dropTags: [],
|
|
879
|
+
dropData: {}
|
|
880
|
+
};
|
|
881
|
+
});
|
|
882
|
+
return [...activeItems, ...inactiveItems];
|
|
883
|
+
}, [
|
|
884
|
+
aggModel,
|
|
885
|
+
api,
|
|
886
|
+
base,
|
|
887
|
+
columns,
|
|
888
|
+
dir,
|
|
889
|
+
measureModel,
|
|
890
|
+
pivotModel,
|
|
891
|
+
source,
|
|
892
|
+
sx.aggModel,
|
|
893
|
+
sx.columnPivotModel,
|
|
894
|
+
sx.measureModel,
|
|
895
|
+
sx.rowGroupModel,
|
|
896
|
+
sx.rtl
|
|
897
|
+
]);
|
|
898
|
+
}
|
|
899
|
+
function PillManagerAggMenu({ column, grid }) {
|
|
900
|
+
const base = grid.state.columnBase.use();
|
|
901
|
+
const aggModel = grid.state.aggModel.use();
|
|
902
|
+
const agg = aggModel[column.id]?.fn;
|
|
903
|
+
let allowed = column.aggFnsAllowed ?? base.aggFnsAllowed ?? [];
|
|
904
|
+
if (typeof agg === "function") allowed = ["Fn(x)", ...allowed];
|
|
905
|
+
else if (typeof agg === "string" && !allowed.includes(agg)) allowed = [agg, ...allowed];
|
|
906
|
+
return /* @__PURE__ */ jsxs(Menu.Container, { children: [
|
|
907
|
+
/* @__PURE__ */ jsx(Menu.Arrow, {}),
|
|
908
|
+
/* @__PURE__ */ jsx(
|
|
909
|
+
Menu.RadioGroup,
|
|
910
|
+
{
|
|
911
|
+
value: typeof agg === "function" ? "Fn(x)" : agg ?? "",
|
|
912
|
+
onValueChange: (v) => {
|
|
913
|
+
if (v === "Fn(x)") return;
|
|
914
|
+
const next = { ...aggModel };
|
|
915
|
+
next[column.id].fn = v;
|
|
916
|
+
grid.state.aggModel.set(next);
|
|
917
|
+
},
|
|
918
|
+
children: allowed.map((c) => {
|
|
919
|
+
return /* @__PURE__ */ jsxs(Menu.Radio, { value: c, closeOnClick: true, children: [
|
|
920
|
+
c,
|
|
921
|
+
/* @__PURE__ */ jsx(Menu.RadioIndicator, {})
|
|
922
|
+
] }, c);
|
|
923
|
+
})
|
|
924
|
+
}
|
|
925
|
+
)
|
|
926
|
+
] });
|
|
927
|
+
}
|
|
928
|
+
function PillManagerMeasureMenu({ column, grid }) {
|
|
929
|
+
const base = grid.state.columnBase.use();
|
|
930
|
+
const measureModel = grid.state.measureModel.use();
|
|
931
|
+
const agg = measureModel[column.id].fn;
|
|
932
|
+
let allowed = column.measureFnsAllowed ?? base.measureFnsAllowed ?? [];
|
|
933
|
+
if (typeof agg === "function") allowed = ["Fn(x)", ...allowed];
|
|
934
|
+
else if (typeof agg === "string" && !allowed.includes(agg)) allowed = [agg, ...allowed];
|
|
935
|
+
return /* @__PURE__ */ jsxs(Menu.Container, { children: [
|
|
936
|
+
/* @__PURE__ */ jsx(Menu.Arrow, {}),
|
|
937
|
+
/* @__PURE__ */ jsx(
|
|
938
|
+
Menu.RadioGroup,
|
|
939
|
+
{
|
|
940
|
+
value: typeof agg === "function" ? "Fn(x)" : agg ?? "",
|
|
941
|
+
onValueChange: (v) => {
|
|
942
|
+
if (v === "Fn(x)") return;
|
|
943
|
+
const next = { ...measureModel };
|
|
944
|
+
next[column.id].fn = v;
|
|
945
|
+
grid.state.measureModel.set(next);
|
|
946
|
+
},
|
|
947
|
+
children: allowed.map((c) => {
|
|
948
|
+
return /* @__PURE__ */ jsxs(Menu.Radio, { value: c, closeOnClick: true, children: [
|
|
949
|
+
c,
|
|
950
|
+
/* @__PURE__ */ jsx(Menu.RadioIndicator, {})
|
|
951
|
+
] }, c);
|
|
952
|
+
})
|
|
953
|
+
}
|
|
954
|
+
)
|
|
955
|
+
] });
|
|
956
|
+
}
|
|
957
|
+
const Pill = forwardRef(
|
|
958
|
+
function Pill2({ className, interactive, kind = "plain", ...props }, ref) {
|
|
959
|
+
return /* @__PURE__ */ jsx(
|
|
960
|
+
"div",
|
|
961
|
+
{
|
|
962
|
+
...props,
|
|
963
|
+
className: clsx("lng1771-pill", className),
|
|
964
|
+
ref,
|
|
965
|
+
"data-pill-interactive": interactive,
|
|
966
|
+
"data-pill-kind": kind
|
|
967
|
+
}
|
|
968
|
+
);
|
|
969
|
+
}
|
|
970
|
+
);
|
|
971
|
+
export {
|
|
972
|
+
MenuTrigger as M,
|
|
973
|
+
Pill as P,
|
|
974
|
+
canMeasure as a,
|
|
975
|
+
useMeasuresSource as b,
|
|
976
|
+
canAgg as c,
|
|
977
|
+
useRowGroupsSource as d,
|
|
978
|
+
useColumnPivotSource as e,
|
|
979
|
+
useDroppable as f,
|
|
980
|
+
useEdgeScroll as g,
|
|
981
|
+
useDraggable as h,
|
|
982
|
+
PillManagerAggMenu as i,
|
|
983
|
+
PillManagerMeasureMenu as j,
|
|
984
|
+
useAggregationSource as u
|
|
985
|
+
};
|