@valbuild/react 0.154.1 → 0.154.2
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/CHANGELOG.md +36 -0
- package/analytics/dist/valbuild-react-analytics.browser.esm.js +2 -1
- package/analytics/dist/valbuild-react-analytics.cjs.dev.js +6 -5
- package/analytics/dist/valbuild-react-analytics.cjs.prod.js +6 -5
- package/analytics/dist/valbuild-react-analytics.esm.js +2 -1
- package/analytics/dist/valbuild-react-analytics.worker.esm.js +2 -1
- package/dist/ValComponentEditorChrome-440d086a.cjs.dev.js +966 -0
- package/dist/ValComponentEditorChrome-4ac9dc79.worker.esm.js +952 -0
- package/dist/ValComponentEditorChrome-93321513.esm.js +952 -0
- package/dist/ValComponentEditorChrome-bf2fefc6.browser.esm.js +952 -0
- package/dist/ValComponentEditorChrome-c0b30556.cjs.js +7 -0
- package/dist/ValComponentEditorChrome-c0b30556.cjs.prod.js +966 -0
- package/dist/ValPreviewBridgeCore-00015d00.esm.js +157 -0
- package/dist/ValPreviewBridgeCore-023ffffb.browser.esm.js +157 -0
- package/dist/ValPreviewBridgeCore-9b984cb0.cjs.js +7 -0
- package/dist/ValPreviewBridgeCore-9b984cb0.cjs.prod.js +161 -0
- package/dist/ValPreviewBridgeCore-bbedf957.cjs.dev.js +161 -0
- package/dist/ValPreviewBridgeCore-e0d5a840.worker.esm.js +157 -0
- package/dist/{createForOfIteratorHelper-598a2f85.cjs.prod.js → createForOfIteratorHelper-6f9dc6fa.cjs.prod.js} +0 -17
- package/dist/{createForOfIteratorHelper-522d616d.cjs.dev.js → createForOfIteratorHelper-8a871dc3.cjs.dev.js} +0 -17
- package/dist/{createForOfIteratorHelper-595d57b7.esm.js → createForOfIteratorHelper-8bd0009a.browser.esm.js} +2 -18
- package/dist/{createForOfIteratorHelper-548f1578.worker.esm.js → createForOfIteratorHelper-93215c75.worker.esm.js} +2 -18
- package/dist/{createForOfIteratorHelper-3316a633.browser.esm.js → createForOfIteratorHelper-9b22d0cd.esm.js} +2 -18
- package/dist/declarations/src/internal/ValComponentEditor.d.ts +54 -0
- package/dist/declarations/src/internal/ValPreviewBridgeCore.d.ts +22 -0
- package/dist/declarations/src/internal/componentPreview.d.ts +39 -0
- package/dist/declarations/src/internal/index.d.ts +3 -0
- package/dist/declarations/src/read/jsonValues.d.ts +2 -0
- package/dist/declarations/src/stega/stegaEncode.d.ts +9 -218
- package/dist/objectSpread2-3c87fb4f.cjs.prod.js +52 -0
- package/dist/objectSpread2-69569a13.worker.esm.js +48 -0
- package/dist/objectSpread2-792eb2c2.cjs.dev.js +52 -0
- package/dist/objectSpread2-af6b2a44.browser.esm.js +48 -0
- package/dist/objectSpread2-be6bfc61.esm.js +48 -0
- package/dist/{raw-15ce77ae.browser.esm.js → raw-0561be8e.browser.esm.js} +81 -90
- package/dist/{raw-d504f4fd.cjs.prod.js → raw-a69a8d13.cjs.prod.js} +80 -92
- package/dist/{raw-534fcde0.esm.js → raw-aa7a3ac4.esm.js} +81 -90
- package/dist/{raw-67d24dd6.cjs.dev.js → raw-de032c12.cjs.dev.js} +80 -92
- package/dist/{raw-645a854a.worker.esm.js → raw-f32dca84.worker.esm.js} +81 -90
- package/dist/toConsumableArray-203e636a.cjs.prod.js +21 -0
- package/dist/toConsumableArray-257d6741.esm.js +19 -0
- package/dist/toConsumableArray-2fc46f85.browser.esm.js +19 -0
- package/dist/toConsumableArray-d7cf1601.cjs.dev.js +21 -0
- package/dist/toConsumableArray-e4f48095.worker.esm.js +19 -0
- package/internal/dist/valbuild-react-internal.browser.esm.js +405 -7
- package/internal/dist/valbuild-react-internal.cjs.dev.js +430 -24
- package/internal/dist/valbuild-react-internal.cjs.prod.js +430 -24
- package/internal/dist/valbuild-react-internal.esm.js +405 -7
- package/internal/dist/valbuild-react-internal.worker.esm.js +405 -7
- package/package.json +4 -4
- package/stega/dist/valbuild-react-stega.browser.esm.js +5 -3
- package/stega/dist/valbuild-react-stega.cjs.dev.js +11 -9
- package/stega/dist/valbuild-react-stega.cjs.prod.js +11 -9
- package/stega/dist/valbuild-react-stega.esm.js +5 -3
- package/stega/dist/valbuild-react-stega.worker.esm.js +5 -3
|
@@ -0,0 +1,952 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { _ as _objectSpread2, b as _defineProperty } from './objectSpread2-69569a13.worker.esm.js';
|
|
3
|
+
import { _ as _createForOfIteratorHelper } from './createForOfIteratorHelper-93215c75.worker.esm.js';
|
|
4
|
+
import { _ as _slicedToArray } from './slicedToArray-106ca5f3.worker.esm.js';
|
|
5
|
+
import { Internal } from '@valbuild/core';
|
|
6
|
+
import { isValCanvasFrame, VAL_CANVAS_EDITING_ATTRIBUTE, VAL_COMPONENT_DRAGGING_ATTRIBUTE, VAL_CANVAS_CONTROLS_ATTRIBUTE, VAL_CANVAS_MESSAGE, VAL_COMPONENT_ATTRIBUTE, VAL_CANVAS_SELECTION_PROPERTY, DEFAULT_CANVAS_SELECTION } from '@valbuild/shared/client';
|
|
7
|
+
export { VAL_COMPONENT_ATTRIBUTE } from '@valbuild/shared/client';
|
|
8
|
+
import { createContext, useRef, useContext, useSyncExternalStore, useState, useCallback, useEffect } from 'react';
|
|
9
|
+
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
10
|
+
|
|
11
|
+
/** On the element around a list, with the list's path once there is one. */
|
|
12
|
+
var VAL_COMPONENT_LIST_ATTRIBUTE = "data-val-component-list";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* `true` where a list must not be arranged although the document is inside
|
|
16
|
+
* the Studio: the preview of ONE component beside its fields
|
|
17
|
+
* (`ValPreviewBridgeCore`). That frame is in the Studio too, so it looks like
|
|
18
|
+
* the canvas from the inside, but nothing there is listening for an edit to
|
|
19
|
+
* a list - the controls would be buttons that do nothing.
|
|
20
|
+
*/
|
|
21
|
+
var ValComponentControlsOff = /*#__PURE__*/createContext(false);
|
|
22
|
+
|
|
23
|
+
/** A rectangle in the viewport: what `getBoundingClientRect` gives. */
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Whether a list runs across rather than down: its first two items sit side
|
|
27
|
+
* by side. A list of one has no direction, and down is the answer that costs
|
|
28
|
+
* nothing when it is wrong.
|
|
29
|
+
*/
|
|
30
|
+
function isHorizontal(rects) {
|
|
31
|
+
var _rects = _slicedToArray(rects, 2),
|
|
32
|
+
first = _rects[0],
|
|
33
|
+
second = _rects[1];
|
|
34
|
+
if (first === undefined || second === undefined) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
return second.left >= first.left + first.width / 2;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* How far in from an item's edge its outline can be grabbed to drag it. Wider
|
|
42
|
+
* than the 2px outline that is drawn, so it can be hit, and narrow enough to
|
|
43
|
+
* leave what the component has near its edge clickable.
|
|
44
|
+
*/
|
|
45
|
+
var BORDER_GRAB = 8;
|
|
46
|
+
|
|
47
|
+
/** Marks the strips along an item's outline that start a drag. */
|
|
48
|
+
var VAL_COMPONENT_BORDER_ATTRIBUTE = "data-val-component-border";
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The four strips along the inside of an item's outline. A side shorter than
|
|
52
|
+
* twice the grab width is all strip, which is still only the item itself.
|
|
53
|
+
*/
|
|
54
|
+
function borderStrips(rect) {
|
|
55
|
+
var grabX = Math.min(BORDER_GRAB, rect.width / 2);
|
|
56
|
+
var grabY = Math.min(BORDER_GRAB, rect.height / 2);
|
|
57
|
+
return [{
|
|
58
|
+
edge: "top",
|
|
59
|
+
style: {
|
|
60
|
+
top: rect.top,
|
|
61
|
+
left: rect.left,
|
|
62
|
+
width: rect.width,
|
|
63
|
+
height: grabY
|
|
64
|
+
}
|
|
65
|
+
}, {
|
|
66
|
+
edge: "bottom",
|
|
67
|
+
style: {
|
|
68
|
+
top: rect.top + rect.height - grabY,
|
|
69
|
+
left: rect.left,
|
|
70
|
+
width: rect.width,
|
|
71
|
+
height: grabY
|
|
72
|
+
}
|
|
73
|
+
}, {
|
|
74
|
+
edge: "left",
|
|
75
|
+
style: {
|
|
76
|
+
top: rect.top + grabY,
|
|
77
|
+
left: rect.left,
|
|
78
|
+
width: grabX,
|
|
79
|
+
height: Math.max(rect.height - 2 * grabY, 0)
|
|
80
|
+
}
|
|
81
|
+
}, {
|
|
82
|
+
edge: "right",
|
|
83
|
+
style: {
|
|
84
|
+
top: rect.top + grabY,
|
|
85
|
+
left: rect.left + rect.width - grabX,
|
|
86
|
+
width: grabX,
|
|
87
|
+
height: Math.max(rect.height - 2 * grabY, 0)
|
|
88
|
+
}
|
|
89
|
+
}];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Where a dragged item would land if it were let go at `point`: the number of
|
|
94
|
+
* items that come before that place, so `0` is the top of the list and
|
|
95
|
+
* `rects.length` is the end of it.
|
|
96
|
+
*
|
|
97
|
+
* An item comes before the pointer once the pointer has passed its middle,
|
|
98
|
+
* which is what makes a section give way when it is half covered instead of
|
|
99
|
+
* at its very edge.
|
|
100
|
+
*/
|
|
101
|
+
function slotAt(rects, point) {
|
|
102
|
+
var horizontal = isHorizontal(rects);
|
|
103
|
+
var slot = 0;
|
|
104
|
+
var _iterator = _createForOfIteratorHelper(rects),
|
|
105
|
+
_step;
|
|
106
|
+
try {
|
|
107
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
108
|
+
var rect = _step.value;
|
|
109
|
+
var middle = horizontal ? rect.left + rect.width / 2 : rect.top + rect.height / 2;
|
|
110
|
+
if ((horizontal ? point.x : point.y) < middle) {
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
slot++;
|
|
114
|
+
}
|
|
115
|
+
} catch (err) {
|
|
116
|
+
_iterator.e(err);
|
|
117
|
+
} finally {
|
|
118
|
+
_iterator.f();
|
|
119
|
+
}
|
|
120
|
+
return slot;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* The index an item ends up at when it is dropped in `slot`, or `null` when
|
|
125
|
+
* that is where it already is. The two slots on either side of an item are
|
|
126
|
+
* both its own place; past it, taking the item out moves everything up one.
|
|
127
|
+
*/
|
|
128
|
+
function moveTarget(from, slot) {
|
|
129
|
+
if (slot === from || slot === from + 1) {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
return slot > from ? slot - 1 : slot;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* The element around a list of components, and - in the Studio's canvas - the
|
|
137
|
+
* controls to arrange it. See `ValComponentEditor`.
|
|
138
|
+
*
|
|
139
|
+
* The controls exist only when three things are true: the page is in the
|
|
140
|
+
* canvas frame, so there is a Studio to hear what was asked for; the list
|
|
141
|
+
* has a path, which it has when the page is showing draft content; and the
|
|
142
|
+
* Studio's Select is on. Anywhere else this is one element and its children.
|
|
143
|
+
*/
|
|
144
|
+
function ValComponentList(_ref) {
|
|
145
|
+
var path = _ref.path,
|
|
146
|
+
className = _ref.className,
|
|
147
|
+
count = _ref.count,
|
|
148
|
+
children = _ref.children;
|
|
149
|
+
var ref = useRef(null);
|
|
150
|
+
var inCanvas = useIsCanvasFrame();
|
|
151
|
+
var off = useContext(ValComponentControlsOff);
|
|
152
|
+
var editMode = useEditMode();
|
|
153
|
+
var editing = inCanvas && editMode && !off && path !== undefined;
|
|
154
|
+
return /*#__PURE__*/jsxs("div", _objectSpread2(_objectSpread2({
|
|
155
|
+
ref: ref,
|
|
156
|
+
className: className
|
|
157
|
+
}, _defineProperty({}, VAL_COMPONENT_LIST_ATTRIBUTE, path !== null && path !== void 0 ? path : "")), {}, {
|
|
158
|
+
children: [children, editing && count === 0 && /*#__PURE__*/jsx(EmptyList, {
|
|
159
|
+
path: path
|
|
160
|
+
}), editing && /*#__PURE__*/jsx(ListControls, {
|
|
161
|
+
listRef: ref,
|
|
162
|
+
path: path
|
|
163
|
+
})]
|
|
164
|
+
}));
|
|
165
|
+
}
|
|
166
|
+
function subscribeToNothing() {
|
|
167
|
+
return function () {};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Whether this document is the Studio's canvas. `false` on the server and
|
|
172
|
+
* for the first render in the browser, so what is hydrated is what was sent.
|
|
173
|
+
*/
|
|
174
|
+
function useIsCanvasFrame() {
|
|
175
|
+
return useSyncExternalStore(subscribeToNothing, function () {
|
|
176
|
+
return isValCanvasFrame(window.location.search, readParentPathname());
|
|
177
|
+
}, function () {
|
|
178
|
+
return false;
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
function readParentPathname() {
|
|
182
|
+
try {
|
|
183
|
+
if (window.parent === window) {
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
return window.parent.location.pathname;
|
|
187
|
+
} catch (_unused) {
|
|
188
|
+
// A parent on another origin: not the Studio, whose canvas is the same app
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
function send(message) {
|
|
193
|
+
// To the Studio, which is the same app: nothing on another origin is told
|
|
194
|
+
// what an editor did.
|
|
195
|
+
window.parent.postMessage(message, window.location.origin);
|
|
196
|
+
}
|
|
197
|
+
function sendEdit(edit) {
|
|
198
|
+
send({
|
|
199
|
+
val: VAL_CANVAS_MESSAGE,
|
|
200
|
+
type: "componentEdit",
|
|
201
|
+
edit: edit
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Whether the Studio's Select is on, which the canvas bridge says on `<html>`
|
|
207
|
+
* ({@link VAL_CANVAS_EDITING_ATTRIBUTE}). Off, the page in the canvas is a
|
|
208
|
+
* page - read and clicked as a visitor would - and nothing is drawn on it.
|
|
209
|
+
*/
|
|
210
|
+
function subscribeToEditMode(onChange) {
|
|
211
|
+
var observer = new MutationObserver(onChange);
|
|
212
|
+
observer.observe(document.documentElement, {
|
|
213
|
+
attributes: true,
|
|
214
|
+
attributeFilter: [VAL_CANVAS_EDITING_ATTRIBUTE]
|
|
215
|
+
});
|
|
216
|
+
return function () {
|
|
217
|
+
return observer.disconnect();
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
function useEditMode() {
|
|
221
|
+
return useSyncExternalStore(subscribeToEditMode, function () {
|
|
222
|
+
return document.documentElement.hasAttribute(VAL_CANVAS_EDITING_ATTRIBUTE);
|
|
223
|
+
}, function () {
|
|
224
|
+
return false;
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* The Studio's selection colour, which the canvas bridge sets on the page's
|
|
230
|
+
* root ({@link VAL_CANVAS_SELECTION_PROPERTY}), or Val's green. A CSS value
|
|
231
|
+
* rather than a colour read from a message: a list rendered after the Studio
|
|
232
|
+
* said it - one inside a section just added, or on a page navigated to - was
|
|
233
|
+
* not there to hear it.
|
|
234
|
+
*/
|
|
235
|
+
var SELECTION_COLOR = "var(".concat(VAL_CANVAS_SELECTION_PROPERTY, ", ").concat(DEFAULT_CANVAS_SELECTION, ")");
|
|
236
|
+
|
|
237
|
+
/** A list with nothing in it has nothing to hover: the way in is a button. */
|
|
238
|
+
function EmptyList(_ref3) {
|
|
239
|
+
var path = _ref3.path;
|
|
240
|
+
var color = SELECTION_COLOR;
|
|
241
|
+
return /*#__PURE__*/jsxs("button", {
|
|
242
|
+
type: "button",
|
|
243
|
+
onClick: function onClick() {
|
|
244
|
+
return sendEdit({
|
|
245
|
+
op: "insert",
|
|
246
|
+
list: path,
|
|
247
|
+
index: 0
|
|
248
|
+
});
|
|
249
|
+
},
|
|
250
|
+
style: {
|
|
251
|
+
all: "unset",
|
|
252
|
+
boxSizing: "border-box",
|
|
253
|
+
display: "flex",
|
|
254
|
+
alignItems: "center",
|
|
255
|
+
justifyContent: "center",
|
|
256
|
+
gap: 8,
|
|
257
|
+
width: "100%",
|
|
258
|
+
minHeight: 96,
|
|
259
|
+
border: "1px dashed ".concat(color),
|
|
260
|
+
borderRadius: 8,
|
|
261
|
+
color: color,
|
|
262
|
+
font: CONTROL_FONT,
|
|
263
|
+
cursor: "pointer"
|
|
264
|
+
},
|
|
265
|
+
children: [/*#__PURE__*/jsx(Icon, {
|
|
266
|
+
name: "plus"
|
|
267
|
+
}), "Add a section"]
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
var CONTROL_FONT = '500 13px/1 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif';
|
|
271
|
+
|
|
272
|
+
/** The toolbar's height: its buttons, and the padding around them. */
|
|
273
|
+
var TOOLBAR_HEIGHT = 32;
|
|
274
|
+
|
|
275
|
+
/** Above the page, below nothing: the controls must not be covered. */
|
|
276
|
+
var CONTROL_Z_INDEX = 2147483000;
|
|
277
|
+
|
|
278
|
+
/** How near the edge of the window a drag starts scrolling, and how fast. */
|
|
279
|
+
var SCROLL_EDGE = 48;
|
|
280
|
+
var SCROLL_STEP = 14;
|
|
281
|
+
function itemsOf(list) {
|
|
282
|
+
if (list === null) {
|
|
283
|
+
return [];
|
|
284
|
+
}
|
|
285
|
+
var items = [];
|
|
286
|
+
for (var _i = 0, _Array$from = Array.from(list.children); _i < _Array$from.length; _i++) {
|
|
287
|
+
var child = _Array$from[_i];
|
|
288
|
+
if (child instanceof HTMLElement && child.hasAttribute(VAL_COMPONENT_ATTRIBUTE)) {
|
|
289
|
+
items.push(child);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return items;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* A rectangle measured in the window, as offsets from `origin`: where the
|
|
297
|
+
* controls' layer actually is, which is the window's corner unless an
|
|
298
|
+
* ancestor made itself the containing block of fixed elements.
|
|
299
|
+
*/
|
|
300
|
+
function relativeTo(rect, origin) {
|
|
301
|
+
return {
|
|
302
|
+
top: rect.top - origin.y,
|
|
303
|
+
left: rect.left - origin.x,
|
|
304
|
+
width: rect.width,
|
|
305
|
+
height: rect.height
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
function rectOf(element) {
|
|
309
|
+
var _element$getBoundingC = element.getBoundingClientRect(),
|
|
310
|
+
top = _element$getBoundingC.top,
|
|
311
|
+
left = _element$getBoundingC.left,
|
|
312
|
+
width = _element$getBoundingC.width,
|
|
313
|
+
height = _element$getBoundingC.height;
|
|
314
|
+
return {
|
|
315
|
+
top: top,
|
|
316
|
+
left: left,
|
|
317
|
+
width: width,
|
|
318
|
+
height: height
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* The controls on a list, drawn over the page rather than in it: a layer of
|
|
324
|
+
* its own, positioned from where the items are, so nothing about the page's
|
|
325
|
+
* own layout has to make room for them.
|
|
326
|
+
*
|
|
327
|
+
* The layer is the list's last child and not a portal on `<body>`, which
|
|
328
|
+
* would need `react-dom`: this file is reached from `val.config.ts` (through
|
|
329
|
+
* the framework package's entry), which Val also evaluates where there is no
|
|
330
|
+
* DOM to import. It is `position: fixed`, so it takes no room in the list;
|
|
331
|
+
* and it is measured rather than assumed to sit at the window's corner,
|
|
332
|
+
* because an ancestor with a `transform` or a `filter` moves a fixed
|
|
333
|
+
* element's origin to itself ({@link relativeTo}).
|
|
334
|
+
*/
|
|
335
|
+
function ListControls(_ref4) {
|
|
336
|
+
var listRef = _ref4.listRef,
|
|
337
|
+
path = _ref4.path;
|
|
338
|
+
var color = SELECTION_COLOR;
|
|
339
|
+
var layerRef = useRef(null);
|
|
340
|
+
var _useState = useState(null),
|
|
341
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
342
|
+
hover = _useState2[0],
|
|
343
|
+
setHover = _useState2[1];
|
|
344
|
+
// The item being dragged, and the place it would land in if let go now
|
|
345
|
+
var _useState3 = useState(null),
|
|
346
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
347
|
+
dragFrom = _useState4[0],
|
|
348
|
+
setDragFrom = _useState4[1];
|
|
349
|
+
var _useState5 = useState(0),
|
|
350
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
351
|
+
dragSlot = _useState6[0],
|
|
352
|
+
setDragSlot = _useState6[1];
|
|
353
|
+
// The item whose removal is waiting for a second click
|
|
354
|
+
var _useState7 = useState(null),
|
|
355
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
356
|
+
confirming = _useState8[0],
|
|
357
|
+
setConfirming = _useState8[1];
|
|
358
|
+
// Where the items are, in the window. Measured when something could have
|
|
359
|
+
// moved them - the pointer reaching another item, a scroll, a resize, a
|
|
360
|
+
// drag - and never while rendering.
|
|
361
|
+
var _useState9 = useState([]),
|
|
362
|
+
_useState0 = _slicedToArray(_useState9, 2),
|
|
363
|
+
rects = _useState0[0],
|
|
364
|
+
setRects = _useState0[1];
|
|
365
|
+
var measureItems = useCallback(function () {
|
|
366
|
+
var _layerRef$current, _layer$left, _layer$top;
|
|
367
|
+
var layer = (_layerRef$current = layerRef.current) === null || _layerRef$current === void 0 ? void 0 : _layerRef$current.getBoundingClientRect();
|
|
368
|
+
var origin = {
|
|
369
|
+
x: (_layer$left = layer === null || layer === void 0 ? void 0 : layer.left) !== null && _layer$left !== void 0 ? _layer$left : 0,
|
|
370
|
+
y: (_layer$top = layer === null || layer === void 0 ? void 0 : layer.top) !== null && _layer$top !== void 0 ? _layer$top : 0
|
|
371
|
+
};
|
|
372
|
+
return itemsOf(listRef.current).map(function (item) {
|
|
373
|
+
return relativeTo(rectOf(item), origin);
|
|
374
|
+
});
|
|
375
|
+
}, [listRef]);
|
|
376
|
+
var measure = useCallback(function () {
|
|
377
|
+
setRects(measureItems());
|
|
378
|
+
}, [measureItems]);
|
|
379
|
+
// What `hover` is, for the handlers: they compare against it on every move
|
|
380
|
+
// of the pointer, and must not wait for a render to know it.
|
|
381
|
+
var hovered = useRef(null);
|
|
382
|
+
var hoverOn = useCallback(function (next) {
|
|
383
|
+
if (hovered.current === next) return;
|
|
384
|
+
hovered.current = next;
|
|
385
|
+
setHover(next);
|
|
386
|
+
// A confirmation is for the item it was asked on, and no other
|
|
387
|
+
setConfirming(null);
|
|
388
|
+
if (next !== null) {
|
|
389
|
+
measure();
|
|
390
|
+
}
|
|
391
|
+
}, [measure]);
|
|
392
|
+
var dragging = dragFrom !== null;
|
|
393
|
+
|
|
394
|
+
// Which item the pointer is over.
|
|
395
|
+
useEffect(function () {
|
|
396
|
+
if (dragging) return;
|
|
397
|
+
var onMove = function onMove(event) {
|
|
398
|
+
var _layerRef$current2;
|
|
399
|
+
var target = event.target;
|
|
400
|
+
if (!(target instanceof Element)) return;
|
|
401
|
+
// On the controls themselves: they belong to the item they are on.
|
|
402
|
+
if ((_layerRef$current2 = layerRef.current) !== null && _layerRef$current2 !== void 0 && _layerRef$current2.contains(target)) return;
|
|
403
|
+
// The NEAREST component only, so a list inside a component of another
|
|
404
|
+
// list answers for its own items and the outer one stays out of it.
|
|
405
|
+
var item = target.closest("[".concat(VAL_COMPONENT_ATTRIBUTE, "]"));
|
|
406
|
+
var index = item instanceof HTMLElement && item.parentElement === listRef.current ? itemsOf(listRef.current).indexOf(item) : -1;
|
|
407
|
+
hoverOn(index === -1 ? null : index);
|
|
408
|
+
};
|
|
409
|
+
var onLeave = function onLeave() {
|
|
410
|
+
return hoverOn(null);
|
|
411
|
+
};
|
|
412
|
+
document.addEventListener("pointermove", onMove);
|
|
413
|
+
document.documentElement.addEventListener("pointerleave", onLeave);
|
|
414
|
+
return function () {
|
|
415
|
+
document.removeEventListener("pointermove", onMove);
|
|
416
|
+
document.documentElement.removeEventListener("pointerleave", onLeave);
|
|
417
|
+
};
|
|
418
|
+
}, [dragging, listRef, hoverOn]);
|
|
419
|
+
|
|
420
|
+
// The page scrolls and resizes under the controls.
|
|
421
|
+
var active = hover !== null || dragging;
|
|
422
|
+
useEffect(function () {
|
|
423
|
+
if (!active) return;
|
|
424
|
+
window.addEventListener("scroll", measure, {
|
|
425
|
+
passive: true,
|
|
426
|
+
capture: true
|
|
427
|
+
});
|
|
428
|
+
window.addEventListener("resize", measure);
|
|
429
|
+
return function () {
|
|
430
|
+
window.removeEventListener("scroll", measure, {
|
|
431
|
+
capture: true
|
|
432
|
+
});
|
|
433
|
+
window.removeEventListener("resize", measure);
|
|
434
|
+
};
|
|
435
|
+
}, [active, measure]);
|
|
436
|
+
|
|
437
|
+
// A drag, once started, is the whole document's: the pointer leaves the
|
|
438
|
+
// handle at once, and has to be followed wherever it goes.
|
|
439
|
+
useEffect(function () {
|
|
440
|
+
if (dragFrom === null) return;
|
|
441
|
+
// Kept here as well as in state: letting go has to know the slot the
|
|
442
|
+
// pointer is over NOW, and must send its edit exactly once - from the
|
|
443
|
+
// handler, never from a state updater, which React may run twice.
|
|
444
|
+
var slot = dragFrom;
|
|
445
|
+
var pointer = null;
|
|
446
|
+
var place = function place() {
|
|
447
|
+
if (pointer === null) return;
|
|
448
|
+
setRects(measureItems());
|
|
449
|
+
// In the window's own coordinates, which is what the pointer is in
|
|
450
|
+
slot = slotAt(itemsOf(listRef.current).map(rectOf), pointer);
|
|
451
|
+
setDragSlot(slot);
|
|
452
|
+
};
|
|
453
|
+
// Scrolling while the pointer rests near an edge: a pointer that is held
|
|
454
|
+
// still sends no events, so the page is moved on every frame instead.
|
|
455
|
+
var frame = requestAnimationFrame(function scroll() {
|
|
456
|
+
frame = requestAnimationFrame(scroll);
|
|
457
|
+
if (pointer === null) return;
|
|
458
|
+
var step = pointer.y < SCROLL_EDGE ? -SCROLL_STEP : pointer.y > window.innerHeight - SCROLL_EDGE ? SCROLL_STEP : 0;
|
|
459
|
+
if (step !== 0) {
|
|
460
|
+
window.scrollBy(0, step);
|
|
461
|
+
place();
|
|
462
|
+
}
|
|
463
|
+
});
|
|
464
|
+
var end = function end() {
|
|
465
|
+
setDragFrom(null);
|
|
466
|
+
hoverOn(null);
|
|
467
|
+
};
|
|
468
|
+
var onMove = function onMove(event) {
|
|
469
|
+
pointer = {
|
|
470
|
+
x: event.clientX,
|
|
471
|
+
y: event.clientY
|
|
472
|
+
};
|
|
473
|
+
place();
|
|
474
|
+
};
|
|
475
|
+
var onUp = function onUp() {
|
|
476
|
+
var to = moveTarget(dragFrom, slot);
|
|
477
|
+
if (to !== null) {
|
|
478
|
+
sendEdit({
|
|
479
|
+
op: "move",
|
|
480
|
+
list: path,
|
|
481
|
+
from: dragFrom,
|
|
482
|
+
to: to
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
end();
|
|
486
|
+
};
|
|
487
|
+
var onKey = function onKey(event) {
|
|
488
|
+
if (event.key === "Escape") {
|
|
489
|
+
end();
|
|
490
|
+
}
|
|
491
|
+
};
|
|
492
|
+
var selectable = document.body.style.userSelect;
|
|
493
|
+
document.body.style.userSelect = "none";
|
|
494
|
+
document.documentElement.setAttribute(VAL_COMPONENT_DRAGGING_ATTRIBUTE, "");
|
|
495
|
+
document.addEventListener("pointermove", onMove);
|
|
496
|
+
document.addEventListener("pointerup", onUp);
|
|
497
|
+
document.addEventListener("pointercancel", end);
|
|
498
|
+
document.addEventListener("keydown", onKey);
|
|
499
|
+
return function () {
|
|
500
|
+
cancelAnimationFrame(frame);
|
|
501
|
+
document.body.style.userSelect = selectable;
|
|
502
|
+
document.documentElement.removeAttribute(VAL_COMPONENT_DRAGGING_ATTRIBUTE);
|
|
503
|
+
document.removeEventListener("pointermove", onMove);
|
|
504
|
+
document.removeEventListener("pointerup", onUp);
|
|
505
|
+
document.removeEventListener("pointercancel", end);
|
|
506
|
+
document.removeEventListener("keydown", onKey);
|
|
507
|
+
};
|
|
508
|
+
}, [dragFrom, listRef, path, measureItems, hoverOn]);
|
|
509
|
+
var open = useCallback(function (index) {
|
|
510
|
+
var itemPath = Internal.createValPathOfItem(path, index);
|
|
511
|
+
if (itemPath !== undefined) {
|
|
512
|
+
send({
|
|
513
|
+
val: VAL_CANVAS_MESSAGE,
|
|
514
|
+
type: "clicked",
|
|
515
|
+
paths: [itemPath]
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
}, [path]);
|
|
519
|
+
var horizontal = isHorizontal(rects);
|
|
520
|
+
var shown = dragFrom !== null ? dragFrom : hover;
|
|
521
|
+
var rect = shown !== null ? rects[shown] : undefined;
|
|
522
|
+
var controls = null;
|
|
523
|
+
if (dragFrom !== null) {
|
|
524
|
+
// The line at the start of slot `k`: before item `k`, or - past the
|
|
525
|
+
// last item - after it.
|
|
526
|
+
var lineAt = function lineAt(k) {
|
|
527
|
+
var before = rects[k];
|
|
528
|
+
var last = rects[rects.length - 1];
|
|
529
|
+
if (before !== undefined) {
|
|
530
|
+
return horizontal ? {
|
|
531
|
+
top: before.top,
|
|
532
|
+
left: before.left - 2,
|
|
533
|
+
height: before.height
|
|
534
|
+
} : {
|
|
535
|
+
top: before.top - 2,
|
|
536
|
+
left: before.left,
|
|
537
|
+
width: before.width
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
if (last !== undefined) {
|
|
541
|
+
return horizontal ? {
|
|
542
|
+
top: last.top,
|
|
543
|
+
left: last.left + last.width - 2,
|
|
544
|
+
height: last.height
|
|
545
|
+
} : {
|
|
546
|
+
top: last.top + last.height - 2,
|
|
547
|
+
left: last.left,
|
|
548
|
+
width: last.width
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
return null;
|
|
552
|
+
};
|
|
553
|
+
var places = [];
|
|
554
|
+
for (var k = 0; k <= rects.length; k++) {
|
|
555
|
+
// The two places next to the item are where it already is
|
|
556
|
+
if (moveTarget(dragFrom, k) === null) continue;
|
|
557
|
+
var line = lineAt(k);
|
|
558
|
+
if (line === null) continue;
|
|
559
|
+
var chosen = k === dragSlot;
|
|
560
|
+
places.push(/*#__PURE__*/jsx(DropMarker, {
|
|
561
|
+
chosen: chosen,
|
|
562
|
+
horizontal: horizontal,
|
|
563
|
+
color: color,
|
|
564
|
+
line: line
|
|
565
|
+
}, k));
|
|
566
|
+
}
|
|
567
|
+
controls = /*#__PURE__*/jsxs(Fragment, {
|
|
568
|
+
children: [rect !== undefined && /*#__PURE__*/jsx("div", {
|
|
569
|
+
style: _objectSpread2(_objectSpread2({
|
|
570
|
+
position: "absolute"
|
|
571
|
+
}, rect), {}, {
|
|
572
|
+
background: color,
|
|
573
|
+
opacity: 0.12,
|
|
574
|
+
pointerEvents: "none"
|
|
575
|
+
})
|
|
576
|
+
}), places]
|
|
577
|
+
});
|
|
578
|
+
} else if (hover !== null && rect !== undefined) {
|
|
579
|
+
var count = rects.length;
|
|
580
|
+
var startDrag = function startDrag(event) {
|
|
581
|
+
if (event.button !== 0) return;
|
|
582
|
+
event.preventDefault();
|
|
583
|
+
setDragSlot(hover);
|
|
584
|
+
setDragFrom(hover);
|
|
585
|
+
};
|
|
586
|
+
controls = /*#__PURE__*/jsxs(Fragment, {
|
|
587
|
+
children: [/*#__PURE__*/jsx("div", {
|
|
588
|
+
style: _objectSpread2(_objectSpread2({
|
|
589
|
+
position: "absolute"
|
|
590
|
+
}, rect), {}, {
|
|
591
|
+
outline: "2px solid ".concat(color),
|
|
592
|
+
outlineOffset: -2,
|
|
593
|
+
pointerEvents: "none"
|
|
594
|
+
})
|
|
595
|
+
}), borderStrips(rect).map(function (strip) {
|
|
596
|
+
return /*#__PURE__*/jsx("div", _objectSpread2(_objectSpread2({}, _defineProperty({}, VAL_COMPONENT_BORDER_ATTRIBUTE, strip.edge)), {}, {
|
|
597
|
+
onPointerDown: startDrag,
|
|
598
|
+
style: _objectSpread2(_objectSpread2({
|
|
599
|
+
position: "absolute"
|
|
600
|
+
}, strip.style), {}, {
|
|
601
|
+
cursor: "grab",
|
|
602
|
+
touchAction: "none"
|
|
603
|
+
})
|
|
604
|
+
}), strip.edge);
|
|
605
|
+
}), /*#__PURE__*/jsx(AddButton, {
|
|
606
|
+
title: "Add a section before this one",
|
|
607
|
+
color: color,
|
|
608
|
+
style: horizontal ? {
|
|
609
|
+
top: rect.top + rect.height / 2 - 12,
|
|
610
|
+
left: rect.left - 12
|
|
611
|
+
} : {
|
|
612
|
+
top: rect.top - 12,
|
|
613
|
+
left: rect.left + rect.width / 2 - 12
|
|
614
|
+
},
|
|
615
|
+
onClick: function onClick() {
|
|
616
|
+
return sendEdit({
|
|
617
|
+
op: "insert",
|
|
618
|
+
list: path,
|
|
619
|
+
index: hover
|
|
620
|
+
});
|
|
621
|
+
}
|
|
622
|
+
}), /*#__PURE__*/jsx(AddButton, {
|
|
623
|
+
title: "Add a section after this one",
|
|
624
|
+
color: color,
|
|
625
|
+
style: horizontal ? {
|
|
626
|
+
top: rect.top + rect.height / 2 - 12,
|
|
627
|
+
left: rect.left + rect.width - 12
|
|
628
|
+
} : {
|
|
629
|
+
top: rect.top + rect.height - 12,
|
|
630
|
+
left: rect.left + rect.width / 2 - 12
|
|
631
|
+
},
|
|
632
|
+
onClick: function onClick() {
|
|
633
|
+
return sendEdit({
|
|
634
|
+
op: "insert",
|
|
635
|
+
list: path,
|
|
636
|
+
index: hover + 1
|
|
637
|
+
});
|
|
638
|
+
}
|
|
639
|
+
}), /*#__PURE__*/jsxs("div", {
|
|
640
|
+
"data-val-component-toolbar": "",
|
|
641
|
+
style: {
|
|
642
|
+
position: "absolute",
|
|
643
|
+
// On top of the item's corner rather than in it, so a small
|
|
644
|
+
// component is not covered by its own controls - and touching
|
|
645
|
+
// it, so the pointer reaches them without crossing anything
|
|
646
|
+
// else. Never off the top of the window: a section that starts
|
|
647
|
+
// above it keeps its controls in reach, inside its corner.
|
|
648
|
+
top: Math.max(rect.top - TOOLBAR_HEIGHT, 8),
|
|
649
|
+
left: Math.max(rect.left + rect.width, TOOLBAR_HEIGHT * 5),
|
|
650
|
+
transform: "translateX(-100%)",
|
|
651
|
+
display: "flex",
|
|
652
|
+
alignItems: "center",
|
|
653
|
+
gap: 2,
|
|
654
|
+
padding: 3,
|
|
655
|
+
borderRadius: 8,
|
|
656
|
+
background: "#18181b",
|
|
657
|
+
color: "#fafafa",
|
|
658
|
+
boxShadow: "0 4px 14px rgba(0, 0, 0, 0.28)",
|
|
659
|
+
font: CONTROL_FONT,
|
|
660
|
+
whiteSpace: "nowrap"
|
|
661
|
+
},
|
|
662
|
+
children: [/*#__PURE__*/jsx(ToolbarButton, {
|
|
663
|
+
title: "Drag to move",
|
|
664
|
+
style: {
|
|
665
|
+
cursor: "grab",
|
|
666
|
+
touchAction: "none"
|
|
667
|
+
},
|
|
668
|
+
onPointerDown: startDrag,
|
|
669
|
+
children: /*#__PURE__*/jsx(Icon, {
|
|
670
|
+
name: "grip"
|
|
671
|
+
})
|
|
672
|
+
}), /*#__PURE__*/jsx(ToolbarButton, {
|
|
673
|
+
title: "Move up",
|
|
674
|
+
disabled: hover === 0,
|
|
675
|
+
onClick: function onClick() {
|
|
676
|
+
sendEdit({
|
|
677
|
+
op: "move",
|
|
678
|
+
list: path,
|
|
679
|
+
from: hover,
|
|
680
|
+
to: hover - 1
|
|
681
|
+
});
|
|
682
|
+
hoverOn(null);
|
|
683
|
+
},
|
|
684
|
+
children: /*#__PURE__*/jsx(Icon, {
|
|
685
|
+
name: horizontal ? "left" : "up"
|
|
686
|
+
})
|
|
687
|
+
}), /*#__PURE__*/jsx(ToolbarButton, {
|
|
688
|
+
title: "Move down",
|
|
689
|
+
disabled: hover === count - 1,
|
|
690
|
+
onClick: function onClick() {
|
|
691
|
+
sendEdit({
|
|
692
|
+
op: "move",
|
|
693
|
+
list: path,
|
|
694
|
+
from: hover,
|
|
695
|
+
to: hover + 1
|
|
696
|
+
});
|
|
697
|
+
hoverOn(null);
|
|
698
|
+
},
|
|
699
|
+
children: /*#__PURE__*/jsx(Icon, {
|
|
700
|
+
name: horizontal ? "right" : "down"
|
|
701
|
+
})
|
|
702
|
+
}), /*#__PURE__*/jsx(ToolbarButton, {
|
|
703
|
+
title: "Edit the content",
|
|
704
|
+
onClick: function onClick() {
|
|
705
|
+
return open(hover);
|
|
706
|
+
},
|
|
707
|
+
children: /*#__PURE__*/jsx(Icon, {
|
|
708
|
+
name: "pencil"
|
|
709
|
+
})
|
|
710
|
+
}), confirming === hover ? /*#__PURE__*/jsx(ToolbarButton, {
|
|
711
|
+
title: "Remove this section",
|
|
712
|
+
style: {
|
|
713
|
+
background: "#dc2626",
|
|
714
|
+
padding: "0 8px"
|
|
715
|
+
},
|
|
716
|
+
onClick: function onClick() {
|
|
717
|
+
sendEdit({
|
|
718
|
+
op: "remove",
|
|
719
|
+
list: path,
|
|
720
|
+
index: hover
|
|
721
|
+
});
|
|
722
|
+
hoverOn(null);
|
|
723
|
+
},
|
|
724
|
+
children: "Remove?"
|
|
725
|
+
}) : /*#__PURE__*/jsx(ToolbarButton, {
|
|
726
|
+
title: "Remove this section",
|
|
727
|
+
onClick: function onClick() {
|
|
728
|
+
return setConfirming(hover);
|
|
729
|
+
},
|
|
730
|
+
children: /*#__PURE__*/jsx(Icon, {
|
|
731
|
+
name: "trash"
|
|
732
|
+
})
|
|
733
|
+
})]
|
|
734
|
+
})]
|
|
735
|
+
});
|
|
736
|
+
}
|
|
737
|
+
return /*#__PURE__*/jsx("div", _objectSpread2(_objectSpread2({
|
|
738
|
+
ref: layerRef
|
|
739
|
+
}, _defineProperty({}, VAL_CANVAS_CONTROLS_ATTRIBUTE, "")), {}, {
|
|
740
|
+
style: {
|
|
741
|
+
position: "fixed",
|
|
742
|
+
top: 0,
|
|
743
|
+
left: 0,
|
|
744
|
+
zIndex: CONTROL_Z_INDEX
|
|
745
|
+
},
|
|
746
|
+
children: controls
|
|
747
|
+
}));
|
|
748
|
+
}
|
|
749
|
+
function ToolbarButton(_ref7) {
|
|
750
|
+
var title = _ref7.title,
|
|
751
|
+
disabled = _ref7.disabled,
|
|
752
|
+
style = _ref7.style,
|
|
753
|
+
onClick = _ref7.onClick,
|
|
754
|
+
onPointerDown = _ref7.onPointerDown,
|
|
755
|
+
children = _ref7.children;
|
|
756
|
+
return /*#__PURE__*/jsx("button", {
|
|
757
|
+
type: "button",
|
|
758
|
+
title: title,
|
|
759
|
+
"aria-label": title,
|
|
760
|
+
disabled: disabled,
|
|
761
|
+
onClick: onClick,
|
|
762
|
+
onPointerDown: onPointerDown,
|
|
763
|
+
style: _objectSpread2({
|
|
764
|
+
all: "unset",
|
|
765
|
+
boxSizing: "border-box",
|
|
766
|
+
display: "inline-flex",
|
|
767
|
+
alignItems: "center",
|
|
768
|
+
justifyContent: "center",
|
|
769
|
+
minWidth: 26,
|
|
770
|
+
height: 26,
|
|
771
|
+
borderRadius: 5,
|
|
772
|
+
cursor: disabled ? "default" : "pointer",
|
|
773
|
+
opacity: disabled ? 0.35 : 1
|
|
774
|
+
}, style),
|
|
775
|
+
children: children
|
|
776
|
+
});
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
/** How long a place a section could go to takes to fade from full to faint. */
|
|
780
|
+
var MARKER_FADE_MS = 700;
|
|
781
|
+
var MARKER_FAINT = 0.35;
|
|
782
|
+
|
|
783
|
+
/**
|
|
784
|
+
* One place the dragged section could land. All of them are drawn at full
|
|
785
|
+
* strength when the drag starts, so the editor sees where they are, and then
|
|
786
|
+
* settle to faint so the page can be read. The place it would land in now
|
|
787
|
+
* stays solid and carries `data-val-component-drop`.
|
|
788
|
+
*
|
|
789
|
+
* The fade runs once, when the marker appears: `animate` is the Web
|
|
790
|
+
* Animations API, so it needs no stylesheet in the customer's page and does
|
|
791
|
+
* not restart when the marker is re-rendered as the pointer moves.
|
|
792
|
+
*/
|
|
793
|
+
function DropMarker(_ref8) {
|
|
794
|
+
var chosen = _ref8.chosen,
|
|
795
|
+
horizontal = _ref8.horizontal,
|
|
796
|
+
color = _ref8.color,
|
|
797
|
+
line = _ref8.line;
|
|
798
|
+
var ref = useRef(null);
|
|
799
|
+
useEffect(function () {
|
|
800
|
+
var element = ref.current;
|
|
801
|
+
// Not every environment has it (jsdom); the marker is simply faint then
|
|
802
|
+
if (!element || typeof element.animate !== "function") return;
|
|
803
|
+
var fade = element.animate([{
|
|
804
|
+
opacity: 1
|
|
805
|
+
}, {
|
|
806
|
+
opacity: MARKER_FAINT
|
|
807
|
+
}], {
|
|
808
|
+
duration: MARKER_FADE_MS,
|
|
809
|
+
easing: "ease-out"
|
|
810
|
+
});
|
|
811
|
+
return function () {
|
|
812
|
+
return fade.cancel();
|
|
813
|
+
};
|
|
814
|
+
}, []);
|
|
815
|
+
return /*#__PURE__*/jsx("div", _objectSpread2(_objectSpread2({
|
|
816
|
+
ref: ref
|
|
817
|
+
// Only the place it would land in is THE drop line; the rest say where
|
|
818
|
+
// else it could go.
|
|
819
|
+
}, chosen ? {
|
|
820
|
+
"data-val-component-drop": ""
|
|
821
|
+
} : {
|
|
822
|
+
"data-val-component-slot": ""
|
|
823
|
+
}), {}, {
|
|
824
|
+
style: _objectSpread2(_objectSpread2(_objectSpread2({
|
|
825
|
+
position: "absolute"
|
|
826
|
+
}, horizontal ? {
|
|
827
|
+
width: chosen ? 4 : 2
|
|
828
|
+
} : {
|
|
829
|
+
height: chosen ? 4 : 2
|
|
830
|
+
}), line), {}, {
|
|
831
|
+
background: color,
|
|
832
|
+
opacity: chosen ? 1 : MARKER_FAINT,
|
|
833
|
+
transition: "opacity 150ms",
|
|
834
|
+
borderRadius: 2,
|
|
835
|
+
pointerEvents: "none"
|
|
836
|
+
})
|
|
837
|
+
}));
|
|
838
|
+
}
|
|
839
|
+
function AddButton(_ref9) {
|
|
840
|
+
var title = _ref9.title,
|
|
841
|
+
color = _ref9.color,
|
|
842
|
+
style = _ref9.style,
|
|
843
|
+
onClick = _ref9.onClick;
|
|
844
|
+
return /*#__PURE__*/jsx("button", {
|
|
845
|
+
type: "button",
|
|
846
|
+
title: title,
|
|
847
|
+
"aria-label": title,
|
|
848
|
+
"data-val-component-add": "",
|
|
849
|
+
onClick: onClick,
|
|
850
|
+
style: _objectSpread2({
|
|
851
|
+
all: "unset",
|
|
852
|
+
boxSizing: "border-box",
|
|
853
|
+
position: "absolute",
|
|
854
|
+
display: "flex",
|
|
855
|
+
alignItems: "center",
|
|
856
|
+
justifyContent: "center",
|
|
857
|
+
width: 24,
|
|
858
|
+
height: 24,
|
|
859
|
+
borderRadius: 12,
|
|
860
|
+
background: color,
|
|
861
|
+
color: "#ffffff",
|
|
862
|
+
boxShadow: "0 2px 8px rgba(0, 0, 0, 0.25)",
|
|
863
|
+
cursor: "pointer"
|
|
864
|
+
}, style),
|
|
865
|
+
children: /*#__PURE__*/jsx(Icon, {
|
|
866
|
+
name: "plus"
|
|
867
|
+
})
|
|
868
|
+
});
|
|
869
|
+
}
|
|
870
|
+
/**
|
|
871
|
+
* A function, and not a table of elements: a table is built when this file
|
|
872
|
+
* is imported, and this file is imported wherever `val.config.ts` is - the
|
|
873
|
+
* CLI and the language server included, which evaluate it with no React to
|
|
874
|
+
* build an element with. Nothing here may run before a component renders.
|
|
875
|
+
*/
|
|
876
|
+
function iconPaths(name) {
|
|
877
|
+
switch (name) {
|
|
878
|
+
case "grip":
|
|
879
|
+
return /*#__PURE__*/jsxs(Fragment, {
|
|
880
|
+
children: [/*#__PURE__*/jsx("circle", {
|
|
881
|
+
cx: "9",
|
|
882
|
+
cy: "6",
|
|
883
|
+
r: "1"
|
|
884
|
+
}), /*#__PURE__*/jsx("circle", {
|
|
885
|
+
cx: "9",
|
|
886
|
+
cy: "12",
|
|
887
|
+
r: "1"
|
|
888
|
+
}), /*#__PURE__*/jsx("circle", {
|
|
889
|
+
cx: "9",
|
|
890
|
+
cy: "18",
|
|
891
|
+
r: "1"
|
|
892
|
+
}), /*#__PURE__*/jsx("circle", {
|
|
893
|
+
cx: "15",
|
|
894
|
+
cy: "6",
|
|
895
|
+
r: "1"
|
|
896
|
+
}), /*#__PURE__*/jsx("circle", {
|
|
897
|
+
cx: "15",
|
|
898
|
+
cy: "12",
|
|
899
|
+
r: "1"
|
|
900
|
+
}), /*#__PURE__*/jsx("circle", {
|
|
901
|
+
cx: "15",
|
|
902
|
+
cy: "18",
|
|
903
|
+
r: "1"
|
|
904
|
+
})]
|
|
905
|
+
});
|
|
906
|
+
case "up":
|
|
907
|
+
return /*#__PURE__*/jsx("path", {
|
|
908
|
+
d: "M12 19V5M5 12l7-7 7 7"
|
|
909
|
+
});
|
|
910
|
+
case "down":
|
|
911
|
+
return /*#__PURE__*/jsx("path", {
|
|
912
|
+
d: "M12 5v14M19 12l-7 7-7-7"
|
|
913
|
+
});
|
|
914
|
+
case "left":
|
|
915
|
+
return /*#__PURE__*/jsx("path", {
|
|
916
|
+
d: "M19 12H5M12 19l-7-7 7-7"
|
|
917
|
+
});
|
|
918
|
+
case "right":
|
|
919
|
+
return /*#__PURE__*/jsx("path", {
|
|
920
|
+
d: "M5 12h14M12 5l7 7-7 7"
|
|
921
|
+
});
|
|
922
|
+
case "pencil":
|
|
923
|
+
return /*#__PURE__*/jsx("path", {
|
|
924
|
+
d: "M17 3a2.85 2.83 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5ZM15 5l4 4"
|
|
925
|
+
});
|
|
926
|
+
case "trash":
|
|
927
|
+
return /*#__PURE__*/jsx("path", {
|
|
928
|
+
d: "M3 6h18M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2M10 11v6M14 11v6"
|
|
929
|
+
});
|
|
930
|
+
case "plus":
|
|
931
|
+
return /*#__PURE__*/jsx("path", {
|
|
932
|
+
d: "M5 12h14M12 5v14"
|
|
933
|
+
});
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
function Icon(_ref0) {
|
|
937
|
+
var name = _ref0.name;
|
|
938
|
+
return /*#__PURE__*/jsx("svg", {
|
|
939
|
+
width: "15",
|
|
940
|
+
height: "15",
|
|
941
|
+
viewBox: "0 0 24 24",
|
|
942
|
+
fill: "none",
|
|
943
|
+
stroke: "currentColor",
|
|
944
|
+
strokeWidth: "2",
|
|
945
|
+
strokeLinecap: "round",
|
|
946
|
+
strokeLinejoin: "round",
|
|
947
|
+
"aria-hidden": "true",
|
|
948
|
+
children: iconPaths(name)
|
|
949
|
+
});
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
export { VAL_COMPONENT_LIST_ATTRIBUTE, ValComponentControlsOff, ValComponentList, borderStrips, isHorizontal, moveTarget, relativeTo, slotAt };
|