datocms-react-ui 3.1.0-next.10 → 3.1.0-next.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/InsertGap.js +2 -2
- package/dist/styles.css +364 -52
- package/dist/ui-public/icons/index.js +304 -300
- package/dist/ui-public/icons/lucide/arrow-down-wide-narrow.js +28 -0
- package/dist/ui-public/icons/lucide/arrow-up-narrow-wide.js +28 -0
- package/dist/ui-public/locales/en.js +1 -0
- package/dist/ui-public/src/UiTextKey.d.ts +1 -1
- package/dist/ui-public/src/actions/Actions/index.d.ts +1 -1
- package/dist/ui-public/src/actions/Actions/registry.d.ts +23 -1
- package/dist/ui-public/src/actions/Actions/registry.js +38 -6
- package/dist/ui-public/src/form/SelectInput/SelectMenu.js +1 -1
- package/dist/ui-public/src/form/SelectInput/SortableMultiValue.js +1 -1
- package/dist/ui-public/src/form/SwitchInput.d.ts +17 -2
- package/dist/ui-public/src/form/SwitchInput.js +57 -38
- package/dist/ui-public/src/form/SwitchList.d.ts +2 -1
- package/dist/ui-public/src/form/SwitchList.js +2 -1
- package/dist/ui-public/src/layout/SidebarPanel.d.ts +15 -1
- package/dist/ui-public/src/layout/SidebarPanel.js +30 -17
- package/dist/ui-public/src/layout/SplitPane/index.js +1 -0
- package/dist/ui-public/src/layout/Toolbar/FilterToggle.d.ts +2 -2
- package/dist/ui-public/src/layout/Toolbar/FilterToggle.js +6 -6
- package/dist/ui-public/src/layout/Toolbar/Help.d.ts +7 -1
- package/dist/ui-public/src/layout/Toolbar/Help.js +5 -4
- package/dist/ui-public/src/layout/Toolbar/index.d.ts +1 -1
- package/dist/ui-public/src/layout/Toolbar/index.js +1 -1
- package/dist/ui-public/src/lists/InfoList/Value.d.ts +22 -2
- package/dist/ui-public/src/lists/InfoList/Value.js +25 -1
- package/dist/ui-public/src/lists/InfoList/index.d.ts +2 -1
- package/dist/ui-public/src/lists/InsertGap/index.d.ts +31 -1
- package/dist/ui-public/src/lists/InsertGap/index.js +23 -3
- package/dist/ui-public/src/lists/InsertGap/parts.d.ts +2 -1
- package/dist/ui-public/src/lists/InsertGap/parts.js +60 -27
- package/dist/ui-public/src/lists/Table/cells/TimeCell.d.ts +1 -1
- package/dist/ui-public/src/lists/Table/cells/TimeCell.js +8 -5
- package/dist/ui-public/src/lists/Table/layout.js +3 -3
- package/dist/ui-public/src/lists/Table/types.d.ts +6 -0
- package/dist/ui-public/src/lists/UploadCard.js +7 -4
- package/dist/ui-public/src/overlays/Modal/Layer.d.ts +18 -0
- package/dist/ui-public/src/overlays/Modal/Layer.js +3 -2
- package/dist/ui-public/src/overlays/Modal/index.d.ts +10 -1
- package/dist/ui-public/src/overlays/Modal/index.js +2 -1
- package/dist/ui-public/src/overlays/Popover.js +4 -1
- package/dist/ui-public/src/patterns/ListDetail/Split.js +1 -0
- package/dist/ui-public/src/utils/pointerNearGap.d.ts +23 -0
- package/dist/ui-public/src/utils/pointerNearGap.js +211 -11
- package/package.json +1 -1
|
@@ -1,11 +1,35 @@
|
|
|
1
1
|
var NEAR_ATTRIBUTE = "data-near";
|
|
2
2
|
var LIST_SELECTOR = "[data-gap-list]";
|
|
3
|
-
var
|
|
3
|
+
var GAP_ATTRIBUTE = "data-gap";
|
|
4
|
+
var GAP_SELECTOR = `[${GAP_ATTRIBUTE}]`;
|
|
5
|
+
var MARGIN_BOUNDARY_ATTRIBUTE = "data-gap-margin-boundary";
|
|
6
|
+
var MARGIN_OBSTACLE_ATTRIBUTE = "data-gap-margin-obstacle";
|
|
7
|
+
var LABEL_FITS_ATTRIBUTE = "data-label-fits";
|
|
8
|
+
var END_ATTRIBUTE = "data-gap-end";
|
|
9
|
+
var NEAREST_ATTRIBUTE = "data-nearest";
|
|
10
|
+
var SHIFT_PROPERTY = "--InsertGap-shift";
|
|
11
|
+
var LABEL_SELECTOR = ".InsertGap__label";
|
|
12
|
+
var LABEL_MARGIN = 8;
|
|
4
13
|
function isNested(list) {
|
|
5
14
|
return Boolean(list.parentElement?.closest(LIST_SELECTOR));
|
|
6
15
|
}
|
|
7
|
-
function
|
|
8
|
-
|
|
16
|
+
function ownGapsOf(list) {
|
|
17
|
+
return Array.from(list.querySelectorAll(GAP_SELECTOR)).filter((gap) => gap.closest(LIST_SELECTOR) === list);
|
|
18
|
+
}
|
|
19
|
+
function edgeItemIn(item, edge) {
|
|
20
|
+
const gaps = Array.from(item.querySelectorAll(LIST_SELECTOR)).map((list) => ({
|
|
21
|
+
gaps: ownGapsOf(list),
|
|
22
|
+
rect: list.getBoundingClientRect()
|
|
23
|
+
})).filter(({ gaps, rect }) => gaps.length > 0 && rect.height > 0).sort((a, b) => edge === "top" ? a.rect.top - b.rect.top : b.rect.bottom - a.rect.bottom)[0]?.gaps ?? [];
|
|
24
|
+
return (edge === "top" ? gaps[0] : gaps[gaps.length - 1])?.parentElement ?? null;
|
|
25
|
+
}
|
|
26
|
+
function zoneLimitIn(item, edge) {
|
|
27
|
+
const edgeItem = edgeItemIn(item, edge);
|
|
28
|
+
if (edgeItem) return zoneLimitIn(edgeItem, edge);
|
|
29
|
+
const rect = item.getBoundingClientRect();
|
|
30
|
+
return edge === "top" ? rect.bottom : rect.top;
|
|
31
|
+
}
|
|
32
|
+
function zoneOf(gap, { top, bottom, height }) {
|
|
9
33
|
if (height === 0) return null;
|
|
10
34
|
const item = gap.parentElement;
|
|
11
35
|
const itemRect = item?.getBoundingClientRect();
|
|
@@ -13,23 +37,198 @@ function zoneOf(gap) {
|
|
|
13
37
|
const itemAbove = isAbove ? item?.previousElementSibling : item;
|
|
14
38
|
const itemBelow = isAbove ? item : null;
|
|
15
39
|
return {
|
|
16
|
-
top: Math.max(top - 100, itemAbove
|
|
17
|
-
bottom: Math.min(bottom + 100, itemBelow
|
|
40
|
+
top: Math.max(top - 100, itemAbove ? zoneLimitIn(itemAbove, "bottom") : Number.NEGATIVE_INFINITY),
|
|
41
|
+
bottom: Math.min(bottom + 100, itemBelow ? zoneLimitIn(itemBelow, "top") : Number.POSITIVE_INFINITY)
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The index of the value nearest to `y`, or -1 when there are no values.
|
|
46
|
+
* The first value wins a tie.
|
|
47
|
+
*/
|
|
48
|
+
function nearestIndex(centers, y) {
|
|
49
|
+
let best = -1;
|
|
50
|
+
centers.forEach((center, index) => {
|
|
51
|
+
if (best === -1 || Math.abs(center - y) < Math.abs(centers[best] - y)) best = index;
|
|
52
|
+
});
|
|
53
|
+
return best;
|
|
54
|
+
}
|
|
55
|
+
function isSurface(style) {
|
|
56
|
+
const hasBackground = style.backgroundColor !== "transparent" && style.backgroundColor !== "rgba(0, 0, 0, 0)";
|
|
57
|
+
const hasLeftBorder = style.borderLeftStyle !== "none" && Number.parseFloat(style.borderLeftWidth) > 0;
|
|
58
|
+
return hasBackground || hasLeftBorder;
|
|
59
|
+
}
|
|
60
|
+
function endsMargin(element) {
|
|
61
|
+
if (element.hasAttribute("data-gap-margin-boundary")) return true;
|
|
62
|
+
const style = getComputedStyle(element);
|
|
63
|
+
return style.overflowX !== "visible" || isSurface(style);
|
|
64
|
+
}
|
|
65
|
+
var margins = /* @__PURE__ */ new WeakMap();
|
|
66
|
+
function marginOf(root) {
|
|
67
|
+
let margin = margins.get(root);
|
|
68
|
+
if (!margin) {
|
|
69
|
+
let end = root.parentElement;
|
|
70
|
+
while (end && !endsMargin(end)) end = end.parentElement;
|
|
71
|
+
margin = {
|
|
72
|
+
end,
|
|
73
|
+
obstacles: Array.from((end ?? document).querySelectorAll(`[${MARGIN_OBSTACLE_ATTRIBUTE}]`)),
|
|
74
|
+
listPadding: Number.parseFloat(getComputedStyle(root).paddingLeft) || 0
|
|
75
|
+
};
|
|
76
|
+
margins.set(root, margin);
|
|
77
|
+
}
|
|
78
|
+
return margin;
|
|
79
|
+
}
|
|
80
|
+
function marginStartOf({ end }) {
|
|
81
|
+
if (!end) return 0;
|
|
82
|
+
const { left } = end.getBoundingClientRect();
|
|
83
|
+
return end.hasAttribute("data-gap-margin-boundary") ? left : left + end.clientLeft;
|
|
84
|
+
}
|
|
85
|
+
/** The two boxes have a common point. An edge that touches counts. */
|
|
86
|
+
function overlaps(a, b) {
|
|
87
|
+
return a.left <= b.right && b.left <= a.right && a.top <= b.bottom && b.top <= a.bottom;
|
|
88
|
+
}
|
|
89
|
+
function appliedShiftOf(gap) {
|
|
90
|
+
return gap.hasAttribute("data-label-fits") ? Number.parseFloat(gap.style.getPropertyValue(SHIFT_PROPERTY)) || 0 : 0;
|
|
91
|
+
}
|
|
92
|
+
function boxInColumn(label, move) {
|
|
93
|
+
return {
|
|
94
|
+
top: label.top,
|
|
95
|
+
right: label.right + move,
|
|
96
|
+
bottom: label.bottom,
|
|
97
|
+
left: label.left + move
|
|
18
98
|
};
|
|
19
99
|
}
|
|
100
|
+
function pointsOnMiddleLine({ top, right, bottom, left }) {
|
|
101
|
+
const y = (top + bottom) / 2;
|
|
102
|
+
return [
|
|
103
|
+
0,
|
|
104
|
+
.25,
|
|
105
|
+
.5,
|
|
106
|
+
.75,
|
|
107
|
+
1
|
|
108
|
+
].map((part) => ({
|
|
109
|
+
x: left + 1 + part * (right - left - 2),
|
|
110
|
+
y
|
|
111
|
+
}));
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* The label of a gap would cover something in the margin: a column at the
|
|
115
|
+
* side of the list, a panel, a button. `box` is the box of the label. The
|
|
116
|
+
* elements around the list, the elements of the list and the gaps can be
|
|
117
|
+
* in it. The elements of the list are in the gutter of their items, for
|
|
118
|
+
* example a grip, and the label of a gap can show above them. Mark an
|
|
119
|
+
* element of the list that the label must not cover as an obstacle (see
|
|
120
|
+
* insertGapMarginObstacleProps). The function gives false when it cannot
|
|
121
|
+
* know: a point of the box is out of the window.
|
|
122
|
+
*/
|
|
123
|
+
function coversSomething(root, box) {
|
|
124
|
+
return pointsOnMiddleLine(box).some(({ x, y }) => {
|
|
125
|
+
for (const element of document.elementsFromPoint(x, y)) {
|
|
126
|
+
if (element.contains(root)) return false;
|
|
127
|
+
if (root.contains(element)) continue;
|
|
128
|
+
if (!element.closest(GAP_SELECTOR)) return true;
|
|
129
|
+
}
|
|
130
|
+
return false;
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
function isCovered(root, rect) {
|
|
134
|
+
const top = document.elementFromPoint(rect.left + rect.width / 2, rect.top + rect.height / 2);
|
|
135
|
+
return Boolean(top) && !root.contains(top) && !top?.contains(root);
|
|
136
|
+
}
|
|
137
|
+
function writeAttribute(element, name, value) {
|
|
138
|
+
if (value !== element.hasAttribute(name)) element.toggleAttribute(name, value);
|
|
139
|
+
}
|
|
140
|
+
function writeMarginLabels(root, rootLeft, gaps, endGap, y) {
|
|
141
|
+
const margin = marginOf(root);
|
|
142
|
+
const itemsStart = rootLeft + margin.listPadding;
|
|
143
|
+
const columnGaps = gaps.filter(({ rect }) => rect.height > 0).map((labelled) => {
|
|
144
|
+
const { gap, itemLeft, label } = labelled;
|
|
145
|
+
const shift = Math.round(itemLeft - itemsStart);
|
|
146
|
+
return {
|
|
147
|
+
...labelled,
|
|
148
|
+
shift,
|
|
149
|
+
labelInColumn: label && boxInColumn(label, appliedShiftOf(gap) - shift)
|
|
150
|
+
};
|
|
151
|
+
});
|
|
152
|
+
const labelStarts = columnGaps.flatMap(({ labelInColumn }) => labelInColumn ? [labelInColumn.left] : []);
|
|
153
|
+
const hasRoom = labelStarts.length > 0 && Math.min(...labelStarts) - LABEL_MARGIN >= marginStartOf(margin);
|
|
154
|
+
const obstacles = hasRoom ? margin.obstacles.map((obstacle) => obstacle.getBoundingClientRect()).filter(({ width, height }) => width > 0 || height > 0) : [];
|
|
155
|
+
const near = columnGaps.filter(({ isNear }) => isNear);
|
|
156
|
+
const nearest = y === null ? void 0 : near[nearestIndex(near.map(({ rect }) => rect.top + rect.height / 2), y)];
|
|
157
|
+
const fits = columnGaps.map(({ gap, rect, isNear, labelInColumn }) => {
|
|
158
|
+
if (!hasRoom || !labelInColumn || obstacles.some((obstacle) => overlaps(obstacle, labelInColumn))) return false;
|
|
159
|
+
if (!isNear && gap !== endGap) return true;
|
|
160
|
+
return isCovered(root, rect) ? gap.hasAttribute(LABEL_FITS_ATTRIBUTE) : !coversSomething(root, labelInColumn);
|
|
161
|
+
});
|
|
162
|
+
columnGaps.forEach(({ gap, shift }, index) => {
|
|
163
|
+
const shiftValue = `${shift}px`;
|
|
164
|
+
if (gap.style.getPropertyValue(SHIFT_PROPERTY) !== shiftValue) gap.style.setProperty(SHIFT_PROPERTY, shiftValue);
|
|
165
|
+
writeAttribute(gap, LABEL_FITS_ATTRIBUTE, fits[index]);
|
|
166
|
+
if (y !== null) writeAttribute(gap, NEAREST_ATTRIBUTE, gap === nearest?.gap);
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
function endGapOf(root, gaps) {
|
|
170
|
+
const ownGaps = gaps.filter((gap) => gap.closest(LIST_SELECTOR) === root);
|
|
171
|
+
const last = ownGaps[ownGaps.length - 1];
|
|
172
|
+
return last?.getAttribute("data-gap") === "after" ? last : null;
|
|
173
|
+
}
|
|
20
174
|
function update(root, y) {
|
|
21
|
-
const
|
|
22
|
-
|
|
175
|
+
const gaps = Array.from(root.querySelectorAll(GAP_SELECTOR));
|
|
176
|
+
const rootLeft = root.getBoundingClientRect().left;
|
|
177
|
+
const states = gaps.map((gap) => {
|
|
178
|
+
const rect = gap.getBoundingClientRect();
|
|
179
|
+
const zone = y === null ? null : zoneOf(gap, rect);
|
|
23
180
|
return {
|
|
24
181
|
gap,
|
|
25
|
-
|
|
182
|
+
rect,
|
|
183
|
+
isNear: zone && y !== null ? y >= zone.top && y <= zone.bottom : false,
|
|
184
|
+
itemLeft: gap.parentElement?.getBoundingClientRect().left ?? 0,
|
|
185
|
+
label: gap.querySelector(LABEL_SELECTOR)?.getBoundingClientRect()
|
|
26
186
|
};
|
|
27
187
|
});
|
|
28
|
-
|
|
188
|
+
const endGap = endGapOf(root, gaps);
|
|
189
|
+
for (const { gap, isNear } of states) {
|
|
190
|
+
writeAttribute(gap, END_ATTRIBUTE, gap === endGap);
|
|
191
|
+
if (y !== null) writeAttribute(gap, NEAR_ATTRIBUTE, isNear);
|
|
192
|
+
}
|
|
193
|
+
writeMarginLabels(root, rootLeft, states, endGap, y);
|
|
194
|
+
}
|
|
195
|
+
function updateAtRest(root) {
|
|
196
|
+
margins.delete(root);
|
|
197
|
+
update(root, null);
|
|
198
|
+
margins.delete(root);
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* The gap at the end of an outermost list always shows its "+" (see
|
|
202
|
+
* _InsertGap.css). Thus the script must find that gap, and put it at its
|
|
203
|
+
* position in the margin, also when the pointer is not on the list. This
|
|
204
|
+
* function sets the gaps of the list of `gap` when `gap` shows, and when
|
|
205
|
+
* the list or the window changes its size. It does nothing for a gap of a
|
|
206
|
+
* nested list. It gives the function that stops the watch.
|
|
207
|
+
*/
|
|
208
|
+
function watchEndGap(gap) {
|
|
209
|
+
const root = gap.closest(LIST_SELECTOR);
|
|
210
|
+
if (!root || isNested(root) || typeof ResizeObserver === "undefined") return;
|
|
211
|
+
let frame = 0;
|
|
212
|
+
const schedule = () => {
|
|
213
|
+
cancelAnimationFrame(frame);
|
|
214
|
+
frame = requestAnimationFrame(() => updateAtRest(root));
|
|
215
|
+
};
|
|
216
|
+
const resizeObserver = new ResizeObserver(schedule);
|
|
217
|
+
const intersectionObserver = new IntersectionObserver(schedule);
|
|
218
|
+
resizeObserver.observe(root);
|
|
219
|
+
intersectionObserver.observe(gap);
|
|
220
|
+
window.addEventListener("resize", schedule);
|
|
221
|
+
return () => {
|
|
222
|
+
cancelAnimationFrame(frame);
|
|
223
|
+
resizeObserver.disconnect();
|
|
224
|
+
intersectionObserver.disconnect();
|
|
225
|
+
window.removeEventListener("resize", schedule);
|
|
226
|
+
};
|
|
29
227
|
}
|
|
30
228
|
function clear(root) {
|
|
31
|
-
root.querySelectorAll(`[${NEAR_ATTRIBUTE}]`).forEach((gap) => {
|
|
229
|
+
root.querySelectorAll(`[${NEAR_ATTRIBUTE}], [${NEAREST_ATTRIBUTE}]`).forEach((gap) => {
|
|
32
230
|
gap.removeAttribute(NEAR_ATTRIBUTE);
|
|
231
|
+
gap.removeAttribute(NEAREST_ATTRIBUTE);
|
|
33
232
|
});
|
|
34
233
|
}
|
|
35
234
|
var pendingY = /* @__PURE__ */ new WeakMap();
|
|
@@ -50,7 +249,8 @@ function handlePointerLeaveList(event) {
|
|
|
50
249
|
const root = event.currentTarget;
|
|
51
250
|
if (isNested(root)) return;
|
|
52
251
|
pendingY.delete(root);
|
|
252
|
+
margins.delete(root);
|
|
53
253
|
clear(root);
|
|
54
254
|
}
|
|
55
255
|
//#endregion
|
|
56
|
-
export { NEAR_ATTRIBUTE, handlePointerLeaveList, handlePointerMoveList };
|
|
256
|
+
export { GAP_ATTRIBUTE, GAP_SELECTOR, LABEL_FITS_ATTRIBUTE, MARGIN_BOUNDARY_ATTRIBUTE, MARGIN_OBSTACLE_ATTRIBUTE, NEAR_ATTRIBUTE, handlePointerLeaveList, handlePointerMoveList, nearestIndex, overlaps, watchEndGap };
|