@canvas-components/react-drag-any 0.0.0-stage → 1.0.0
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 +21 -0
- package/README.md +113 -2
- package/dist/index.cjs +2129 -0
- package/dist/index.css +160 -0
- package/dist/index.d.cts +180 -0
- package/dist/index.d.ts +180 -0
- package/dist/index.js +2116 -0
- package/package.json +44 -3
package/dist/index.js
ADDED
|
@@ -0,0 +1,2116 @@
|
|
|
1
|
+
import { DragDocumentError, indexDragDocument, DragAnyGroup, dragAnyGroupProjection, dragAnyProjection, getHeaderRegions, getDefaultContextMenuItems, dragContextMenuActions, getContentPlainText, resolveTheme, normalizeContent, DragContentError, contentOwnerKey } from '@canvas-components/drag-any';
|
|
2
|
+
import { createContext, forwardRef, useContext, useRef, useState, useLayoutEffect, useImperativeHandle, useSyncExternalStore, useMemo, useCallback, useInsertionEffect, useId, isValidElement, Fragment as Fragment$1, cloneElement } from 'react';
|
|
3
|
+
import { createPortal } from 'react-dom';
|
|
4
|
+
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
5
|
+
import { UI, compileUIJSX } from '@canvas-components/react-canvas-ui';
|
|
6
|
+
|
|
7
|
+
var __defProp = Object.defineProperty;
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, key + "" , value);
|
|
10
|
+
function overlayRoot(owner) {
|
|
11
|
+
const doc = owner?.ownerDocument ?? document;
|
|
12
|
+
return doc.fullscreenElement ?? doc.body;
|
|
13
|
+
}
|
|
14
|
+
function overlayTheme(theme) {
|
|
15
|
+
const t = resolveTheme(theme);
|
|
16
|
+
return {
|
|
17
|
+
"--drag-overlay-bg": t.backgroundColor,
|
|
18
|
+
"--drag-overlay-border": t.borderColor,
|
|
19
|
+
"--drag-overlay-text": t.textColor,
|
|
20
|
+
"--drag-overlay-muted": t.mutedTextColor,
|
|
21
|
+
"--drag-overlay-hover": t.hoverBackgroundColor,
|
|
22
|
+
"--drag-overlay-shadow": t.fixedShadowColor,
|
|
23
|
+
"--drag-overlay-focus": t.placeholderBorderColor,
|
|
24
|
+
"--drag-overlay-danger": t.forbiddenColor,
|
|
25
|
+
fontFamily: t.fontFamily,
|
|
26
|
+
fontSize: t.fontSize
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function useOverlayPosition(ref, root, anchor, parent) {
|
|
30
|
+
const [style, setStyle] = useState({});
|
|
31
|
+
useLayoutEffect(() => {
|
|
32
|
+
const el = ref.current;
|
|
33
|
+
const win = root.ownerDocument.defaultView;
|
|
34
|
+
if (!el || !win) return;
|
|
35
|
+
function update() {
|
|
36
|
+
if (!el || !win) return;
|
|
37
|
+
const viewport = win.visualViewport;
|
|
38
|
+
const visibleLeft = (viewport?.offsetLeft ?? 0) + 4;
|
|
39
|
+
const visibleTop = (viewport?.offsetTop ?? 0) + 4;
|
|
40
|
+
const visibleRight = visibleLeft + (viewport?.width ?? win.innerWidth) - 8;
|
|
41
|
+
const visibleBottom = visibleTop + (viewport?.height ?? win.innerHeight) - 8;
|
|
42
|
+
const bounds = root === root.ownerDocument.body ? void 0 : root.getBoundingClientRect();
|
|
43
|
+
const left = bounds ? Math.max(visibleLeft, bounds.left + 4) : visibleLeft;
|
|
44
|
+
const top = bounds ? Math.max(visibleTop, bounds.top + 4) : visibleTop;
|
|
45
|
+
const right = bounds ? Math.min(visibleRight, bounds.right - 4) : visibleRight;
|
|
46
|
+
const bottom = bounds ? Math.min(visibleBottom, bounds.bottom - 4) : visibleBottom;
|
|
47
|
+
const maxWidth = Math.max(0, right - left);
|
|
48
|
+
const maxHeight = Math.max(0, bottom - top);
|
|
49
|
+
const width = Math.min(el.offsetWidth, maxWidth);
|
|
50
|
+
const height = Math.min(el.offsetHeight, maxHeight);
|
|
51
|
+
const parentRect = parent?.getBoundingClientRect();
|
|
52
|
+
const x = parentRect ? parentRect.right + width > right ? parentRect.left - width : parentRect.right : anchor.x;
|
|
53
|
+
setStyle({
|
|
54
|
+
left: Math.max(left, Math.min(x, right - width)),
|
|
55
|
+
top: Math.max(
|
|
56
|
+
top,
|
|
57
|
+
Math.min(parentRect?.top ?? anchor.y, bottom - height)
|
|
58
|
+
),
|
|
59
|
+
maxWidth,
|
|
60
|
+
maxHeight,
|
|
61
|
+
"--drag-overlay-max-width": `${maxWidth}px`
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
update();
|
|
65
|
+
const resize = typeof ResizeObserver === "undefined" ? void 0 : new ResizeObserver(update);
|
|
66
|
+
resize?.observe(el);
|
|
67
|
+
win.addEventListener("resize", update);
|
|
68
|
+
win.visualViewport?.addEventListener("resize", update);
|
|
69
|
+
win.visualViewport?.addEventListener("scroll", update);
|
|
70
|
+
return () => {
|
|
71
|
+
resize?.disconnect();
|
|
72
|
+
win.removeEventListener("resize", update);
|
|
73
|
+
win.visualViewport?.removeEventListener("resize", update);
|
|
74
|
+
win.visualViewport?.removeEventListener("scroll", update);
|
|
75
|
+
};
|
|
76
|
+
}, [ref, root, anchor.x, anchor.y, parent]);
|
|
77
|
+
return style;
|
|
78
|
+
}
|
|
79
|
+
function MenuLevel({
|
|
80
|
+
items,
|
|
81
|
+
root,
|
|
82
|
+
request,
|
|
83
|
+
parent,
|
|
84
|
+
focusOnOpen = true,
|
|
85
|
+
onBack,
|
|
86
|
+
onSelect,
|
|
87
|
+
onClose
|
|
88
|
+
}) {
|
|
89
|
+
const panel = useRef(null);
|
|
90
|
+
const [submenu, setSubmenu] = useState();
|
|
91
|
+
const style = useOverlayPosition(panel, root, request.clientAnchor, parent);
|
|
92
|
+
const enabled = () => Array.from(
|
|
93
|
+
panel.current?.querySelectorAll(
|
|
94
|
+
':scope > [role="menuitem"]:not(:disabled)'
|
|
95
|
+
) ?? []
|
|
96
|
+
);
|
|
97
|
+
useLayoutEffect(() => {
|
|
98
|
+
if (focusOnOpen)
|
|
99
|
+
(enabled()[0] ?? panel.current)?.focus({ preventScroll: true });
|
|
100
|
+
}, [focusOnOpen]);
|
|
101
|
+
function handleKey(event) {
|
|
102
|
+
const buttons = enabled();
|
|
103
|
+
const index = buttons.indexOf(event.target);
|
|
104
|
+
const button = buttons[index];
|
|
105
|
+
switch (event.key) {
|
|
106
|
+
case "ArrowDown":
|
|
107
|
+
buttons[(index + 1) % buttons.length]?.focus();
|
|
108
|
+
break;
|
|
109
|
+
case "ArrowUp":
|
|
110
|
+
buttons[(index <= 0 ? buttons.length : index) - 1]?.focus();
|
|
111
|
+
break;
|
|
112
|
+
case "Home":
|
|
113
|
+
buttons[0]?.focus();
|
|
114
|
+
break;
|
|
115
|
+
case "End":
|
|
116
|
+
buttons[buttons.length - 1]?.focus();
|
|
117
|
+
break;
|
|
118
|
+
case "Enter":
|
|
119
|
+
case " ":
|
|
120
|
+
button?.click();
|
|
121
|
+
break;
|
|
122
|
+
case "ArrowRight":
|
|
123
|
+
if (button?.hasAttribute("aria-haspopup")) button.click();
|
|
124
|
+
break;
|
|
125
|
+
case "ArrowLeft":
|
|
126
|
+
onBack?.();
|
|
127
|
+
break;
|
|
128
|
+
case "Escape":
|
|
129
|
+
(onBack ?? onClose)();
|
|
130
|
+
break;
|
|
131
|
+
case "Tab":
|
|
132
|
+
onClose();
|
|
133
|
+
break;
|
|
134
|
+
default:
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
event.preventDefault();
|
|
138
|
+
event.stopPropagation();
|
|
139
|
+
}
|
|
140
|
+
const active = items.find(
|
|
141
|
+
(item) => item.key === submenu?.key && !item.disabled
|
|
142
|
+
);
|
|
143
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
144
|
+
/* @__PURE__ */ jsx(
|
|
145
|
+
"div",
|
|
146
|
+
{
|
|
147
|
+
ref: panel,
|
|
148
|
+
className: "drag-any-menu",
|
|
149
|
+
role: "menu",
|
|
150
|
+
"aria-label": "\u64CD\u4F5C\u83DC\u5355",
|
|
151
|
+
tabIndex: -1,
|
|
152
|
+
style,
|
|
153
|
+
onKeyDown: handleKey,
|
|
154
|
+
onScroll: (event) => {
|
|
155
|
+
if (!submenu) return;
|
|
156
|
+
event.currentTarget.focus({ preventScroll: true });
|
|
157
|
+
setSubmenu(void 0);
|
|
158
|
+
},
|
|
159
|
+
children: items.map((item) => /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
160
|
+
item.separatorBefore && /* @__PURE__ */ jsx("div", { role: "separator" }),
|
|
161
|
+
/* @__PURE__ */ jsxs(
|
|
162
|
+
"button",
|
|
163
|
+
{
|
|
164
|
+
role: "menuitem",
|
|
165
|
+
type: "button",
|
|
166
|
+
tabIndex: -1,
|
|
167
|
+
disabled: item.disabled,
|
|
168
|
+
"data-danger": item.danger || void 0,
|
|
169
|
+
"aria-haspopup": item.children?.length ? "menu" : void 0,
|
|
170
|
+
"aria-expanded": item.children?.length ? submenu?.key === item.key : void 0,
|
|
171
|
+
onMouseEnter: (event) => {
|
|
172
|
+
if (item.disabled) return;
|
|
173
|
+
event.currentTarget.focus({ preventScroll: true });
|
|
174
|
+
setSubmenu(
|
|
175
|
+
item.children?.length ? {
|
|
176
|
+
key: item.key,
|
|
177
|
+
anchor: event.currentTarget,
|
|
178
|
+
focus: false
|
|
179
|
+
} : void 0
|
|
180
|
+
);
|
|
181
|
+
},
|
|
182
|
+
onClick: (event) => {
|
|
183
|
+
if (item.children?.length)
|
|
184
|
+
setSubmenu({
|
|
185
|
+
key: item.key,
|
|
186
|
+
anchor: event.currentTarget,
|
|
187
|
+
focus: true
|
|
188
|
+
});
|
|
189
|
+
else onSelect(item.key);
|
|
190
|
+
},
|
|
191
|
+
children: [
|
|
192
|
+
/* @__PURE__ */ jsx("span", { children: item.label }),
|
|
193
|
+
!!item.children?.length && /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: "\u203A" })
|
|
194
|
+
]
|
|
195
|
+
}
|
|
196
|
+
)
|
|
197
|
+
] }, item.key))
|
|
198
|
+
}
|
|
199
|
+
),
|
|
200
|
+
submenu && !!active?.children?.length && /* @__PURE__ */ jsx(
|
|
201
|
+
MenuLevel,
|
|
202
|
+
{
|
|
203
|
+
items: active.children,
|
|
204
|
+
root,
|
|
205
|
+
request,
|
|
206
|
+
parent: submenu.anchor,
|
|
207
|
+
focusOnOpen: submenu.focus,
|
|
208
|
+
onClose,
|
|
209
|
+
onSelect,
|
|
210
|
+
onBack: () => {
|
|
211
|
+
submenu.anchor.focus({ preventScroll: true });
|
|
212
|
+
setSubmenu(void 0);
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
active.key
|
|
216
|
+
)
|
|
217
|
+
] });
|
|
218
|
+
}
|
|
219
|
+
function ContextMenuView(props) {
|
|
220
|
+
return /* @__PURE__ */ jsx(MenuSession, { ...props }, props.request.requestId);
|
|
221
|
+
}
|
|
222
|
+
function MenuSession({
|
|
223
|
+
request,
|
|
224
|
+
items,
|
|
225
|
+
onAction,
|
|
226
|
+
onClose,
|
|
227
|
+
theme,
|
|
228
|
+
owner,
|
|
229
|
+
returnFocus,
|
|
230
|
+
revision,
|
|
231
|
+
dragging,
|
|
232
|
+
isTargetValid
|
|
233
|
+
}) {
|
|
234
|
+
const root = overlayRoot(owner);
|
|
235
|
+
const doc = root.ownerDocument;
|
|
236
|
+
const menu = useRef(null);
|
|
237
|
+
const close = useRef(onClose);
|
|
238
|
+
close.current = onClose;
|
|
239
|
+
const previousFocus = useRef(returnFocus ?? doc.activeElement);
|
|
240
|
+
const valid = () => !dragging && (revision === void 0 || revision === request.modelRevision) && (isTargetValid?.(request) ?? true);
|
|
241
|
+
const invalid = !valid();
|
|
242
|
+
useLayoutEffect(() => {
|
|
243
|
+
if (invalid) onClose();
|
|
244
|
+
}, [invalid, onClose]);
|
|
245
|
+
useLayoutEffect(() => {
|
|
246
|
+
function outside(event) {
|
|
247
|
+
if (!event.composedPath().includes(menu.current)) close.current();
|
|
248
|
+
}
|
|
249
|
+
function dismiss() {
|
|
250
|
+
close.current();
|
|
251
|
+
}
|
|
252
|
+
doc.addEventListener("pointerdown", outside, true);
|
|
253
|
+
doc.addEventListener("scroll", outside, true);
|
|
254
|
+
doc.addEventListener("fullscreenchange", dismiss);
|
|
255
|
+
doc.defaultView?.addEventListener("blur", dismiss);
|
|
256
|
+
return () => {
|
|
257
|
+
doc.removeEventListener("pointerdown", outside, true);
|
|
258
|
+
doc.removeEventListener("scroll", outside, true);
|
|
259
|
+
doc.removeEventListener("fullscreenchange", dismiss);
|
|
260
|
+
doc.defaultView?.removeEventListener("blur", dismiss);
|
|
261
|
+
const previous = previousFocus.current;
|
|
262
|
+
if (previous?.isConnected) previous.focus?.({ preventScroll: true });
|
|
263
|
+
};
|
|
264
|
+
}, [doc]);
|
|
265
|
+
if (invalid || !items.length) return null;
|
|
266
|
+
return createPortal(
|
|
267
|
+
/* @__PURE__ */ jsx(
|
|
268
|
+
"div",
|
|
269
|
+
{
|
|
270
|
+
ref: menu,
|
|
271
|
+
className: "drag-any-overlay",
|
|
272
|
+
style: overlayTheme(theme),
|
|
273
|
+
onPointerDown: (event) => event.stopPropagation(),
|
|
274
|
+
onWheel: (event) => event.stopPropagation(),
|
|
275
|
+
onContextMenu: (event) => {
|
|
276
|
+
event.preventDefault();
|
|
277
|
+
event.stopPropagation();
|
|
278
|
+
},
|
|
279
|
+
children: /* @__PURE__ */ jsx(
|
|
280
|
+
MenuLevel,
|
|
281
|
+
{
|
|
282
|
+
items,
|
|
283
|
+
root,
|
|
284
|
+
request,
|
|
285
|
+
onClose,
|
|
286
|
+
onSelect: (key) => {
|
|
287
|
+
const canExecute = valid();
|
|
288
|
+
onClose();
|
|
289
|
+
if (canExecute) onAction(key, request);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
)
|
|
293
|
+
}
|
|
294
|
+
),
|
|
295
|
+
root
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
async function copyContextMenuText(text, onError, owner) {
|
|
299
|
+
try {
|
|
300
|
+
const clipboard = (owner?.ownerDocument.defaultView ?? window).navigator.clipboard;
|
|
301
|
+
if (!clipboard) throw new Error("\u5F53\u524D\u73AF\u5883\u65E0\u6CD5\u8BBF\u95EE\u526A\u8D34\u677F");
|
|
302
|
+
await clipboard.writeText(text);
|
|
303
|
+
} catch (error) {
|
|
304
|
+
onError?.(error instanceof Error ? error : new Error(String(error)));
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
var numberFields = {
|
|
308
|
+
thickness: "\u539A\u5EA6",
|
|
309
|
+
thumbRadius: "\u6ED1\u5757\u5706\u89D2",
|
|
310
|
+
maxScrollSpeed: "\u6700\u5927\u6EDA\u52A8\u901F\u5EA6"
|
|
311
|
+
};
|
|
312
|
+
var colorFields = {
|
|
313
|
+
thumbColor: "\u6ED1\u5757\u989C\u8272",
|
|
314
|
+
trackColor: "\u8F68\u9053\u989C\u8272",
|
|
315
|
+
buttonColor: "\u6309\u94AE\u989C\u8272",
|
|
316
|
+
buttonHoverColor: "\u6309\u94AE\u60AC\u505C\u989C\u8272",
|
|
317
|
+
buttonPressedColor: "\u6309\u94AE\u6309\u4E0B\u989C\u8272"
|
|
318
|
+
};
|
|
319
|
+
var marginFields = [
|
|
320
|
+
"horizontalLeft",
|
|
321
|
+
"horizontalRight",
|
|
322
|
+
"horizontalBottom",
|
|
323
|
+
"verticalTop",
|
|
324
|
+
"verticalRight",
|
|
325
|
+
"verticalBottom"
|
|
326
|
+
];
|
|
327
|
+
var numericKeys = [...Object.keys(numberFields), ...marginFields];
|
|
328
|
+
function storageName(key) {
|
|
329
|
+
return `canvas-components:drag-any:${key}:scrollbar:v1`;
|
|
330
|
+
}
|
|
331
|
+
function isSettings(value) {
|
|
332
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
333
|
+
const options = value;
|
|
334
|
+
return (options.mode === void 0 || options.mode === "button" || options.mode === "scrollbar") && (options.visible === void 0 || typeof options.visible === "boolean") && numericKeys.every(
|
|
335
|
+
(key) => options[key] === void 0 || Number.isFinite(options[key])
|
|
336
|
+
) && Object.keys(colorFields).every(
|
|
337
|
+
(key) => options[key] === void 0 || typeof options[key] === "string"
|
|
338
|
+
) && [options.horizontal, options.vertical].every(
|
|
339
|
+
(axis) => axis === void 0 || axis === false || isSettings(axis)
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
function readScrollbarSettings(storageKey, owner) {
|
|
343
|
+
if (!storageKey) return void 0;
|
|
344
|
+
try {
|
|
345
|
+
const raw = (owner?.ownerDocument.defaultView ?? window).localStorage.getItem(storageName(storageKey));
|
|
346
|
+
const value = raw === null ? void 0 : JSON.parse(raw);
|
|
347
|
+
return isSettings(value) ? value : void 0;
|
|
348
|
+
} catch {
|
|
349
|
+
return void 0;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
function saveScrollbarSettings(storageKey, value, owner, onError) {
|
|
353
|
+
if (!storageKey) return;
|
|
354
|
+
try {
|
|
355
|
+
const storage = (owner?.ownerDocument.defaultView ?? window).localStorage;
|
|
356
|
+
if (value === void 0) storage.removeItem(storageName(storageKey));
|
|
357
|
+
else storage.setItem(storageName(storageKey), JSON.stringify(value));
|
|
358
|
+
} catch (error) {
|
|
359
|
+
onError?.(error instanceof Error ? error : new Error(String(error)));
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
function ScrollbarDialog({
|
|
363
|
+
title,
|
|
364
|
+
value,
|
|
365
|
+
onConfirm,
|
|
366
|
+
onClose,
|
|
367
|
+
storageKey,
|
|
368
|
+
theme,
|
|
369
|
+
owner,
|
|
370
|
+
onError,
|
|
371
|
+
children
|
|
372
|
+
}) {
|
|
373
|
+
const panel = useRef(null);
|
|
374
|
+
const titleId = useId();
|
|
375
|
+
const root = overlayRoot(owner);
|
|
376
|
+
useLayoutEffect(() => {
|
|
377
|
+
const dialog = panel.current;
|
|
378
|
+
const doc = root.ownerDocument;
|
|
379
|
+
const previous = doc.activeElement;
|
|
380
|
+
if (typeof dialog.showModal === "function") dialog.showModal();
|
|
381
|
+
else dialog.setAttribute("open", "");
|
|
382
|
+
(dialog.querySelector("select,input,button") ?? dialog).focus();
|
|
383
|
+
return () => {
|
|
384
|
+
if (typeof dialog.close === "function") dialog.close();
|
|
385
|
+
if (previous?.isConnected) previous.focus({ preventScroll: true });
|
|
386
|
+
};
|
|
387
|
+
}, [root]);
|
|
388
|
+
return createPortal(
|
|
389
|
+
/* @__PURE__ */ jsx(
|
|
390
|
+
"div",
|
|
391
|
+
{
|
|
392
|
+
className: "drag-any-overlay drag-any-dialog-backdrop",
|
|
393
|
+
style: overlayTheme(theme),
|
|
394
|
+
onWheel: (event) => event.stopPropagation(),
|
|
395
|
+
onPointerDown: (event) => {
|
|
396
|
+
event.stopPropagation();
|
|
397
|
+
if (event.target === event.currentTarget) onClose();
|
|
398
|
+
},
|
|
399
|
+
children: /* @__PURE__ */ jsx(
|
|
400
|
+
"dialog",
|
|
401
|
+
{
|
|
402
|
+
ref: panel,
|
|
403
|
+
className: "drag-any-dialog",
|
|
404
|
+
role: "dialog",
|
|
405
|
+
"aria-modal": "true",
|
|
406
|
+
"aria-labelledby": titleId,
|
|
407
|
+
onCancel: (event) => {
|
|
408
|
+
event.preventDefault();
|
|
409
|
+
onClose();
|
|
410
|
+
},
|
|
411
|
+
onKeyDown: (event) => {
|
|
412
|
+
event.stopPropagation();
|
|
413
|
+
if (event.key === "Escape") {
|
|
414
|
+
event.preventDefault();
|
|
415
|
+
onClose();
|
|
416
|
+
}
|
|
417
|
+
},
|
|
418
|
+
onPointerDown: (event) => {
|
|
419
|
+
if (event.target === event.currentTarget) {
|
|
420
|
+
const bounds = event.currentTarget.getBoundingClientRect();
|
|
421
|
+
if (event.clientX < bounds.left || event.clientX > bounds.right || event.clientY < bounds.top || event.clientY > bounds.bottom)
|
|
422
|
+
onClose();
|
|
423
|
+
}
|
|
424
|
+
},
|
|
425
|
+
children: /* @__PURE__ */ jsxs(
|
|
426
|
+
"form",
|
|
427
|
+
{
|
|
428
|
+
onSubmit: (event) => {
|
|
429
|
+
event.preventDefault();
|
|
430
|
+
saveScrollbarSettings(storageKey, value, owner, onError);
|
|
431
|
+
onConfirm(value);
|
|
432
|
+
},
|
|
433
|
+
children: [
|
|
434
|
+
/* @__PURE__ */ jsx("h2", { id: titleId, children: title }),
|
|
435
|
+
/* @__PURE__ */ jsx("div", { className: "drag-any-dialog-fields", children }),
|
|
436
|
+
/* @__PURE__ */ jsxs("footer", { children: [
|
|
437
|
+
/* @__PURE__ */ jsx("button", { type: "button", onClick: onClose, children: "\u53D6\u6D88" }),
|
|
438
|
+
/* @__PURE__ */ jsx("button", { type: "submit", "data-primary": true, children: "\u786E\u5B9A" })
|
|
439
|
+
] })
|
|
440
|
+
]
|
|
441
|
+
}
|
|
442
|
+
)
|
|
443
|
+
}
|
|
444
|
+
)
|
|
445
|
+
}
|
|
446
|
+
),
|
|
447
|
+
root
|
|
448
|
+
);
|
|
449
|
+
}
|
|
450
|
+
function withField(value, key, field) {
|
|
451
|
+
const next = { ...value };
|
|
452
|
+
if (field === void 0) delete next[key];
|
|
453
|
+
else next[key] = field;
|
|
454
|
+
return next;
|
|
455
|
+
}
|
|
456
|
+
function SettingsDialog(props) {
|
|
457
|
+
const [draft, setDraft] = useState(props.value);
|
|
458
|
+
const [scope, setScope] = useState(
|
|
459
|
+
"common"
|
|
460
|
+
);
|
|
461
|
+
const axis = scope === "common" ? draft : draft[scope];
|
|
462
|
+
const fields = axis || {};
|
|
463
|
+
function update(key, value) {
|
|
464
|
+
if (scope === "common") setDraft(withField(draft, key, value));
|
|
465
|
+
else setDraft(withField(draft, scope, withField(fields, key, value)));
|
|
466
|
+
}
|
|
467
|
+
return /* @__PURE__ */ jsxs(ScrollbarDialog, { ...props, value: draft, title: "\u6EDA\u52A8\u6761\u5C5E\u6027", children: [
|
|
468
|
+
/* @__PURE__ */ jsxs("label", { children: [
|
|
469
|
+
"\u8BBE\u7F6E\u8303\u56F4",
|
|
470
|
+
/* @__PURE__ */ jsxs(
|
|
471
|
+
"select",
|
|
472
|
+
{
|
|
473
|
+
value: scope,
|
|
474
|
+
onChange: (event) => setScope(event.target.value),
|
|
475
|
+
children: [
|
|
476
|
+
/* @__PURE__ */ jsx("option", { value: "common", children: "\u4E24\u8F74\u5171\u7528" }),
|
|
477
|
+
/* @__PURE__ */ jsx("option", { value: "horizontal", children: "\u6C34\u5E73\u8F74" }),
|
|
478
|
+
/* @__PURE__ */ jsx("option", { value: "vertical", children: "\u5782\u76F4\u8F74" })
|
|
479
|
+
]
|
|
480
|
+
}
|
|
481
|
+
)
|
|
482
|
+
] }),
|
|
483
|
+
scope !== "common" && /* @__PURE__ */ jsxs("label", { children: [
|
|
484
|
+
"\u542F\u7528\u6B64\u8F74",
|
|
485
|
+
/* @__PURE__ */ jsx(
|
|
486
|
+
"input",
|
|
487
|
+
{
|
|
488
|
+
type: "checkbox",
|
|
489
|
+
checked: axis !== false,
|
|
490
|
+
onChange: (event) => setDraft(
|
|
491
|
+
withField(
|
|
492
|
+
draft,
|
|
493
|
+
scope,
|
|
494
|
+
event.target.checked ? void 0 : false
|
|
495
|
+
)
|
|
496
|
+
)
|
|
497
|
+
}
|
|
498
|
+
)
|
|
499
|
+
] }),
|
|
500
|
+
axis !== false && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
501
|
+
/* @__PURE__ */ jsxs("label", { children: [
|
|
502
|
+
"\u6A21\u5F0F",
|
|
503
|
+
/* @__PURE__ */ jsxs(
|
|
504
|
+
"select",
|
|
505
|
+
{
|
|
506
|
+
value: fields.mode ?? "",
|
|
507
|
+
onChange: (event) => update(
|
|
508
|
+
"mode",
|
|
509
|
+
event.target.value || void 0
|
|
510
|
+
),
|
|
511
|
+
children: [
|
|
512
|
+
/* @__PURE__ */ jsx("option", { value: "", children: "\u9ED8\u8BA4" }),
|
|
513
|
+
/* @__PURE__ */ jsx("option", { value: "scrollbar", children: "\u6ED1\u5757" }),
|
|
514
|
+
/* @__PURE__ */ jsx("option", { value: "button", children: "\u6309\u94AE" })
|
|
515
|
+
]
|
|
516
|
+
}
|
|
517
|
+
)
|
|
518
|
+
] }),
|
|
519
|
+
/* @__PURE__ */ jsxs("label", { children: [
|
|
520
|
+
"\u53EF\u89C1\u6027",
|
|
521
|
+
/* @__PURE__ */ jsxs(
|
|
522
|
+
"select",
|
|
523
|
+
{
|
|
524
|
+
value: fields.visible === void 0 ? "" : String(fields.visible),
|
|
525
|
+
onChange: (event) => update(
|
|
526
|
+
"visible",
|
|
527
|
+
event.target.value ? event.target.value === "true" : void 0
|
|
528
|
+
),
|
|
529
|
+
children: [
|
|
530
|
+
/* @__PURE__ */ jsx("option", { value: "", children: "\u9ED8\u8BA4" }),
|
|
531
|
+
/* @__PURE__ */ jsx("option", { value: "true", children: "\u663E\u793A" }),
|
|
532
|
+
/* @__PURE__ */ jsx("option", { value: "false", children: "\u9690\u85CF" })
|
|
533
|
+
]
|
|
534
|
+
}
|
|
535
|
+
)
|
|
536
|
+
] }),
|
|
537
|
+
Object.keys(numberFields).map(
|
|
538
|
+
(key) => /* @__PURE__ */ jsxs("label", { children: [
|
|
539
|
+
numberFields[key],
|
|
540
|
+
/* @__PURE__ */ jsx(
|
|
541
|
+
"input",
|
|
542
|
+
{
|
|
543
|
+
type: "number",
|
|
544
|
+
min: 0,
|
|
545
|
+
step: "any",
|
|
546
|
+
value: fields[key] ?? "",
|
|
547
|
+
onChange: (event) => update(
|
|
548
|
+
key,
|
|
549
|
+
Number.isFinite(event.target.valueAsNumber) ? event.target.valueAsNumber : void 0
|
|
550
|
+
)
|
|
551
|
+
}
|
|
552
|
+
)
|
|
553
|
+
] }, key)
|
|
554
|
+
),
|
|
555
|
+
Object.keys(colorFields).map(
|
|
556
|
+
(key) => /* @__PURE__ */ jsxs("label", { children: [
|
|
557
|
+
colorFields[key],
|
|
558
|
+
/* @__PURE__ */ jsx(
|
|
559
|
+
"input",
|
|
560
|
+
{
|
|
561
|
+
value: fields[key] ?? "",
|
|
562
|
+
onChange: (event) => update(key, event.target.value || void 0)
|
|
563
|
+
}
|
|
564
|
+
)
|
|
565
|
+
] }, key)
|
|
566
|
+
)
|
|
567
|
+
] })
|
|
568
|
+
] });
|
|
569
|
+
}
|
|
570
|
+
var margins = {
|
|
571
|
+
horizontalLeft: "\u6A2A\u6761\u5DE6\u8FB9\u8DDD",
|
|
572
|
+
horizontalRight: "\u6A2A\u6761\u53F3\u8FB9\u8DDD",
|
|
573
|
+
horizontalBottom: "\u6A2A\u6761\u4E0B\u8FB9\u8DDD",
|
|
574
|
+
verticalTop: "\u7AD6\u6761\u4E0A\u8FB9\u8DDD",
|
|
575
|
+
verticalRight: "\u7AD6\u6761\u53F3\u8FB9\u8DDD",
|
|
576
|
+
verticalBottom: "\u7AD6\u6761\u4E0B\u8FB9\u8DDD"
|
|
577
|
+
};
|
|
578
|
+
function PositionDialog(props) {
|
|
579
|
+
const [draft, setDraft] = useState(props.value);
|
|
580
|
+
return /* @__PURE__ */ jsx(ScrollbarDialog, { ...props, value: draft, title: "\u6EDA\u52A8\u6761\u4F4D\u7F6E", children: Object.keys(margins).map((key) => /* @__PURE__ */ jsxs("label", { children: [
|
|
581
|
+
margins[key],
|
|
582
|
+
/* @__PURE__ */ jsx(
|
|
583
|
+
"input",
|
|
584
|
+
{
|
|
585
|
+
type: "number",
|
|
586
|
+
min: 0,
|
|
587
|
+
step: "any",
|
|
588
|
+
value: draft[key] ?? "",
|
|
589
|
+
onChange: (event) => {
|
|
590
|
+
const value = event.target.valueAsNumber;
|
|
591
|
+
const next = { ...draft };
|
|
592
|
+
if (Number.isFinite(value)) next[key] = value;
|
|
593
|
+
else delete next[key];
|
|
594
|
+
setDraft(next);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
)
|
|
598
|
+
] }, key)) });
|
|
599
|
+
}
|
|
600
|
+
function Tooltip({ request, owner, theme }) {
|
|
601
|
+
const panel = useRef(null);
|
|
602
|
+
const root = overlayRoot(owner);
|
|
603
|
+
const position = useOverlayPosition(panel, root, {
|
|
604
|
+
x: request.clientAnchor.x + 10,
|
|
605
|
+
y: request.clientAnchor.y + 14
|
|
606
|
+
});
|
|
607
|
+
return createPortal(
|
|
608
|
+
/* @__PURE__ */ jsx("div", { className: "drag-any-overlay", style: overlayTheme(theme), children: /* @__PURE__ */ jsx(
|
|
609
|
+
"div",
|
|
610
|
+
{
|
|
611
|
+
ref: panel,
|
|
612
|
+
className: "drag-any-tooltip",
|
|
613
|
+
role: "tooltip",
|
|
614
|
+
style: position,
|
|
615
|
+
children: request.text
|
|
616
|
+
}
|
|
617
|
+
) }),
|
|
618
|
+
root
|
|
619
|
+
);
|
|
620
|
+
}
|
|
621
|
+
function EditorHost({
|
|
622
|
+
request,
|
|
623
|
+
onClose,
|
|
624
|
+
owner,
|
|
625
|
+
theme
|
|
626
|
+
}) {
|
|
627
|
+
const panel = useRef(null);
|
|
628
|
+
const root = overlayRoot(owner);
|
|
629
|
+
const style = useOverlayPosition(panel, root, request.clientAnchor);
|
|
630
|
+
return createPortal(
|
|
631
|
+
/* @__PURE__ */ jsx("div", { className: "drag-any-overlay", style: overlayTheme(theme), children: /* @__PURE__ */ jsx(
|
|
632
|
+
"div",
|
|
633
|
+
{
|
|
634
|
+
ref: panel,
|
|
635
|
+
className: "drag-any-editor-host",
|
|
636
|
+
style,
|
|
637
|
+
onPointerDown: (event) => event.stopPropagation(),
|
|
638
|
+
onKeyDown: (event) => {
|
|
639
|
+
event.stopPropagation();
|
|
640
|
+
if (event.key === "Escape" && !event.defaultPrevented) onClose();
|
|
641
|
+
},
|
|
642
|
+
children: request.view
|
|
643
|
+
}
|
|
644
|
+
) }),
|
|
645
|
+
root
|
|
646
|
+
);
|
|
647
|
+
}
|
|
648
|
+
var pixelStyles = /* @__PURE__ */ new Set([
|
|
649
|
+
"width",
|
|
650
|
+
"height",
|
|
651
|
+
"gap",
|
|
652
|
+
"padding",
|
|
653
|
+
"paddingTop",
|
|
654
|
+
"paddingRight",
|
|
655
|
+
"paddingBottom",
|
|
656
|
+
"paddingLeft",
|
|
657
|
+
"margin",
|
|
658
|
+
"marginTop",
|
|
659
|
+
"marginRight",
|
|
660
|
+
"marginBottom",
|
|
661
|
+
"marginLeft",
|
|
662
|
+
"fontSize",
|
|
663
|
+
"lineHeight",
|
|
664
|
+
"borderWidth",
|
|
665
|
+
"borderRadius"
|
|
666
|
+
]);
|
|
667
|
+
var pixelValue = /^(-?(?:\d+(?:\.\d+)?|\.\d+))px$/;
|
|
668
|
+
var svgNumber = "[+-]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:[eE][+-]?\\d+)?";
|
|
669
|
+
var svgViewBox = new RegExp(
|
|
670
|
+
`^\\s*(${svgNumber})[\\s,]+(${svgNumber})[\\s,]+(${svgNumber})[\\s,]+(${svgNumber})\\s*$`
|
|
671
|
+
);
|
|
672
|
+
var ContentCompileError = class extends DragContentError {
|
|
673
|
+
constructor(cardId, code, nodePath) {
|
|
674
|
+
super(code, nodePath);
|
|
675
|
+
__publicField(this, "cardId", cardId);
|
|
676
|
+
this.name = "ContentCompileError";
|
|
677
|
+
this.message = `\u5361\u7247 ${JSON.stringify(cardId)} \u5185\u5BB9\u9519\u8BEF\uFF08${code}\uFF09\u4F4D\u4E8E ${nodePath}`;
|
|
678
|
+
}
|
|
679
|
+
};
|
|
680
|
+
function checkProps(props, allowed, path) {
|
|
681
|
+
for (const key of Object.keys(props)) {
|
|
682
|
+
if (!allowed.includes(key))
|
|
683
|
+
throw new DragContentError("unsupported-property", `${path}.${key}`);
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
function mapStyle(props) {
|
|
687
|
+
const { style, width, height } = props;
|
|
688
|
+
if (style === void 0 && width === void 0 && height === void 0)
|
|
689
|
+
return void 0;
|
|
690
|
+
if (style !== void 0 && (typeof style !== "object" || style === null || ![Object.prototype, null].includes(Object.getPrototypeOf(style)))) {
|
|
691
|
+
return style;
|
|
692
|
+
}
|
|
693
|
+
const mapped = /* @__PURE__ */ Object.create(null);
|
|
694
|
+
if (width !== void 0) mapped.width = width;
|
|
695
|
+
if (height !== void 0) mapped.height = height;
|
|
696
|
+
const descriptors = {
|
|
697
|
+
...Object.getOwnPropertyDescriptors(mapped),
|
|
698
|
+
...style === void 0 ? {} : Object.getOwnPropertyDescriptors(style)
|
|
699
|
+
};
|
|
700
|
+
for (const key of pixelStyles) {
|
|
701
|
+
const descriptor = descriptors[key];
|
|
702
|
+
if (typeof descriptor?.value !== "string") continue;
|
|
703
|
+
const match = pixelValue.exec(descriptor.value);
|
|
704
|
+
if (match) descriptor.value = Number(match[1]);
|
|
705
|
+
}
|
|
706
|
+
return Object.defineProperties({}, descriptors);
|
|
707
|
+
}
|
|
708
|
+
function textOnly(input, path, depth) {
|
|
709
|
+
if (depth > 100) throw new DragContentError("max-depth", path);
|
|
710
|
+
if (input == null || typeof input === "boolean") return "";
|
|
711
|
+
if (typeof input === "string" || typeof input === "number" && Number.isFinite(input))
|
|
712
|
+
return String(input);
|
|
713
|
+
if (Array.isArray(input)) {
|
|
714
|
+
return input.map((item, index) => textOnly(item, `${path}[${index}]`, depth + 1)).join("");
|
|
715
|
+
}
|
|
716
|
+
if (isValidElement(input) && input.type === Fragment$1) {
|
|
717
|
+
checkProps(input.props, ["children"], path);
|
|
718
|
+
return textOnly(input.props.children, path, depth + 1);
|
|
719
|
+
}
|
|
720
|
+
throw new DragContentError("invalid-value", path);
|
|
721
|
+
}
|
|
722
|
+
function iconProps(props, path) {
|
|
723
|
+
const childPath = `${path}.children[0]`;
|
|
724
|
+
const child = props.children;
|
|
725
|
+
if (!isValidElement(child) || child.type !== "path") {
|
|
726
|
+
throw new DragContentError("invalid-value", childPath);
|
|
727
|
+
}
|
|
728
|
+
checkProps(child.props, ["d"], childPath);
|
|
729
|
+
const result = { path: child.props.d };
|
|
730
|
+
if (props.viewBox === void 0) return result;
|
|
731
|
+
const match = typeof props.viewBox === "string" && svgViewBox.exec(props.viewBox);
|
|
732
|
+
if (!match || match.slice(1).some((number) => !Number.isFinite(Number(number))) || Number(match[3]) <= 0 || Number(match[4]) <= 0) {
|
|
733
|
+
throw new DragContentError("invalid-value", `${path}.viewBox`);
|
|
734
|
+
}
|
|
735
|
+
return { ...result, viewBox: props.viewBox };
|
|
736
|
+
}
|
|
737
|
+
function compileJSX(input, context) {
|
|
738
|
+
const compiled = compileUIJSX(input, {
|
|
739
|
+
owner: context.ownerKey ?? context.cardId,
|
|
740
|
+
onDiagnostic: context.onDiagnostic
|
|
741
|
+
});
|
|
742
|
+
if (compiled) return compiled;
|
|
743
|
+
const handlers = /* @__PURE__ */ new Map();
|
|
744
|
+
const namespace = [context.boardId, context.cardId, context.contentVersion];
|
|
745
|
+
const ancestors = /* @__PURE__ */ new Set();
|
|
746
|
+
let visited = 0;
|
|
747
|
+
function visit(value, nodes, parentPath, stablePath, slot, depth, root = false) {
|
|
748
|
+
const path = root ? parentPath : `${parentPath}.children[${nodes.length}]`;
|
|
749
|
+
if (depth > 100) throw new DragContentError("max-depth", path);
|
|
750
|
+
if (++visited > 1e4) throw new DragContentError("max-nodes", path);
|
|
751
|
+
if (value == null || typeof value === "boolean") return;
|
|
752
|
+
if (typeof value === "string" || typeof value === "number" && Number.isFinite(value)) {
|
|
753
|
+
nodes.push({ kind: "text", text: String(value) });
|
|
754
|
+
return;
|
|
755
|
+
}
|
|
756
|
+
if (Array.isArray(value)) {
|
|
757
|
+
if (ancestors.has(value)) throw new DragContentError("cycle", path);
|
|
758
|
+
ancestors.add(value);
|
|
759
|
+
const prefix = [...stablePath, slot];
|
|
760
|
+
value.forEach(
|
|
761
|
+
(child, index) => visit(child, nodes, parentPath, prefix, String(index), depth + 1)
|
|
762
|
+
);
|
|
763
|
+
ancestors.delete(value);
|
|
764
|
+
return;
|
|
765
|
+
}
|
|
766
|
+
if (!isValidElement(value))
|
|
767
|
+
throw new DragContentError("invalid-value", path);
|
|
768
|
+
const { type, props, key } = value;
|
|
769
|
+
const nodePath = [...stablePath, key === null ? slot : `key:${key}`];
|
|
770
|
+
if (type === Fragment$1) {
|
|
771
|
+
checkProps(props, ["children"], path);
|
|
772
|
+
visit(
|
|
773
|
+
props.children,
|
|
774
|
+
nodes,
|
|
775
|
+
parentPath,
|
|
776
|
+
nodePath,
|
|
777
|
+
"fragment",
|
|
778
|
+
depth + 1,
|
|
779
|
+
root && !Array.isArray(props.children)
|
|
780
|
+
);
|
|
781
|
+
return;
|
|
782
|
+
}
|
|
783
|
+
const keyed = key === null ? {} : { key };
|
|
784
|
+
const actions = () => {
|
|
785
|
+
if (props.onClick === void 0) return {};
|
|
786
|
+
if (typeof props.onClick !== "function")
|
|
787
|
+
throw new DragContentError("invalid-value", `${path}.onClick`);
|
|
788
|
+
const click = `jsx:${JSON.stringify([...namespace, nodePath])}`;
|
|
789
|
+
if (handlers.has(click))
|
|
790
|
+
throw new DragContentError("invalid-value", `${path}.key`);
|
|
791
|
+
handlers.set(click, props.onClick);
|
|
792
|
+
return { actions: { click } };
|
|
793
|
+
};
|
|
794
|
+
const decorated = () => {
|
|
795
|
+
const style = mapStyle(props);
|
|
796
|
+
return {
|
|
797
|
+
...keyed,
|
|
798
|
+
...style === void 0 ? {} : { style },
|
|
799
|
+
...actions()
|
|
800
|
+
};
|
|
801
|
+
};
|
|
802
|
+
const common = ["style", "onClick"];
|
|
803
|
+
switch (type) {
|
|
804
|
+
case "div":
|
|
805
|
+
case "span": {
|
|
806
|
+
checkProps(props, [...common, "children"], path);
|
|
807
|
+
const children = [];
|
|
808
|
+
visit(props.children, children, path, nodePath, "children", depth + 1);
|
|
809
|
+
nodes.push({ kind: "element", tag: type, ...decorated(), children });
|
|
810
|
+
return;
|
|
811
|
+
}
|
|
812
|
+
case "br":
|
|
813
|
+
checkProps(props, [], path);
|
|
814
|
+
nodes.push({ kind: "break", ...keyed });
|
|
815
|
+
return;
|
|
816
|
+
case "img": {
|
|
817
|
+
checkProps(props, [...common, "src", "alt", "width", "height"], path);
|
|
818
|
+
const { src, alt } = props;
|
|
819
|
+
nodes.push({
|
|
820
|
+
kind: "leaf",
|
|
821
|
+
leafType: "image",
|
|
822
|
+
...decorated(),
|
|
823
|
+
props: {
|
|
824
|
+
src,
|
|
825
|
+
...alt === void 0 ? {} : { alt }
|
|
826
|
+
}
|
|
827
|
+
});
|
|
828
|
+
return;
|
|
829
|
+
}
|
|
830
|
+
case "button": {
|
|
831
|
+
checkProps(props, [...common, "children", "disabled", "type"], path);
|
|
832
|
+
const { disabled } = props;
|
|
833
|
+
if (props.type !== void 0 && props.type !== "button") {
|
|
834
|
+
throw new DragContentError("invalid-value", `${path}.type`);
|
|
835
|
+
}
|
|
836
|
+
nodes.push({
|
|
837
|
+
kind: "leaf",
|
|
838
|
+
leafType: "button",
|
|
839
|
+
...decorated(),
|
|
840
|
+
props: {
|
|
841
|
+
text: textOnly(props.children, `${path}.children`, depth + 1),
|
|
842
|
+
...disabled === void 0 ? {} : { disabled }
|
|
843
|
+
}
|
|
844
|
+
});
|
|
845
|
+
return;
|
|
846
|
+
}
|
|
847
|
+
case "input": {
|
|
848
|
+
checkProps(
|
|
849
|
+
props,
|
|
850
|
+
[...common, "type", "checked", "disabled", "aria-label"],
|
|
851
|
+
path
|
|
852
|
+
);
|
|
853
|
+
if (props.type !== "checkbox")
|
|
854
|
+
throw new DragContentError("invalid-value", `${path}.type`);
|
|
855
|
+
const { checked, disabled, "aria-label": label } = props;
|
|
856
|
+
nodes.push({
|
|
857
|
+
kind: "leaf",
|
|
858
|
+
leafType: "checkbox",
|
|
859
|
+
...decorated(),
|
|
860
|
+
props: {
|
|
861
|
+
checked: checked === void 0 ? false : checked,
|
|
862
|
+
...disabled === void 0 ? {} : { disabled },
|
|
863
|
+
...label === void 0 ? {} : { label }
|
|
864
|
+
}
|
|
865
|
+
});
|
|
866
|
+
return;
|
|
867
|
+
}
|
|
868
|
+
case "progress": {
|
|
869
|
+
checkProps(
|
|
870
|
+
props,
|
|
871
|
+
[...common, "value", "max", "children", "aria-label"],
|
|
872
|
+
path
|
|
873
|
+
);
|
|
874
|
+
const { max, "aria-label": ariaLabel } = props;
|
|
875
|
+
const childLabel = props.children == null ? void 0 : textOnly(props.children, `${path}.children`, depth + 1);
|
|
876
|
+
const label = ariaLabel ?? childLabel;
|
|
877
|
+
nodes.push({
|
|
878
|
+
kind: "leaf",
|
|
879
|
+
leafType: "progress",
|
|
880
|
+
...decorated(),
|
|
881
|
+
props: {
|
|
882
|
+
value: props.value,
|
|
883
|
+
...max === void 0 ? {} : { max },
|
|
884
|
+
...label === void 0 ? {} : { label }
|
|
885
|
+
}
|
|
886
|
+
});
|
|
887
|
+
return;
|
|
888
|
+
}
|
|
889
|
+
case "svg":
|
|
890
|
+
checkProps(
|
|
891
|
+
props,
|
|
892
|
+
[...common, "children", "viewBox", "width", "height"],
|
|
893
|
+
path
|
|
894
|
+
);
|
|
895
|
+
nodes.push({
|
|
896
|
+
kind: "leaf",
|
|
897
|
+
leafType: "icon",
|
|
898
|
+
...decorated(),
|
|
899
|
+
props: iconProps(props, path)
|
|
900
|
+
});
|
|
901
|
+
return;
|
|
902
|
+
default:
|
|
903
|
+
throw new DragContentError("invalid-value", path);
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
try {
|
|
907
|
+
const nodes = [];
|
|
908
|
+
visit(input, nodes, "$.root", [], "root", 1, true);
|
|
909
|
+
const root = nodes.length === 0 ? { kind: "text", text: "" } : nodes.length === 1 ? nodes[0] : { kind: "element", tag: "div", children: nodes };
|
|
910
|
+
const document2 = normalizeContent({
|
|
911
|
+
type: "drag-content",
|
|
912
|
+
version: 1,
|
|
913
|
+
root
|
|
914
|
+
});
|
|
915
|
+
return { document: document2, handlers, dispose: () => handlers.clear() };
|
|
916
|
+
} catch (error) {
|
|
917
|
+
if (error instanceof DragContentError) {
|
|
918
|
+
throw new ContentCompileError(
|
|
919
|
+
context.cardId ?? context.ownerKey ?? "content",
|
|
920
|
+
error.code,
|
|
921
|
+
error.nodePath
|
|
922
|
+
);
|
|
923
|
+
}
|
|
924
|
+
throw error;
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
// src/content-bindings.ts
|
|
929
|
+
var emptyHandlers = /* @__PURE__ */ new Map();
|
|
930
|
+
function compileInput(input, context) {
|
|
931
|
+
if (input === null || typeof input === "string" || typeof input === "number" || typeof input === "object" && Object.prototype.hasOwnProperty.call(input, "type") && !Object.prototype.hasOwnProperty.call(input, "$$typeof")) {
|
|
932
|
+
try {
|
|
933
|
+
return {
|
|
934
|
+
document: normalizeContent(input),
|
|
935
|
+
handlers: emptyHandlers,
|
|
936
|
+
dispose() {
|
|
937
|
+
}
|
|
938
|
+
};
|
|
939
|
+
} catch (error) {
|
|
940
|
+
if (error instanceof DragContentError) {
|
|
941
|
+
throw new ContentCompileError(
|
|
942
|
+
context.cardId ?? context.ownerKey ?? "content",
|
|
943
|
+
error.code,
|
|
944
|
+
error.nodePath
|
|
945
|
+
);
|
|
946
|
+
}
|
|
947
|
+
throw error;
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
return compileJSX(input, context);
|
|
951
|
+
}
|
|
952
|
+
function createContentBindings() {
|
|
953
|
+
let preparedBindings = /* @__PURE__ */ new WeakMap();
|
|
954
|
+
const active = /* @__PURE__ */ new Map();
|
|
955
|
+
const latest = /* @__PURE__ */ new Map();
|
|
956
|
+
let sequence = 0;
|
|
957
|
+
let destroyed = false;
|
|
958
|
+
function release(prepared) {
|
|
959
|
+
const binding = preparedBindings.get(prepared);
|
|
960
|
+
if (!binding) return;
|
|
961
|
+
if (active.get(binding.ownerKey) === prepared)
|
|
962
|
+
active.delete(binding.ownerKey);
|
|
963
|
+
preparedBindings.delete(prepared);
|
|
964
|
+
binding.content.dispose();
|
|
965
|
+
}
|
|
966
|
+
return {
|
|
967
|
+
prepare(input, context) {
|
|
968
|
+
const ownerKey = context.ownerKey ?? context.cardId;
|
|
969
|
+
const previous = active.get(ownerKey);
|
|
970
|
+
const binding = previous && preparedBindings.get(previous);
|
|
971
|
+
const reuse = isValidElement(input) && binding?.staticInput === input && binding.version === context.contentVersion;
|
|
972
|
+
const content = reuse ? {
|
|
973
|
+
document: binding.content.document,
|
|
974
|
+
handlers: emptyHandlers,
|
|
975
|
+
dispose() {
|
|
976
|
+
}
|
|
977
|
+
} : compileInput(input, context);
|
|
978
|
+
const isStatic = isValidElement(input) && !content.handlers.size && !("runtimeBindings" in content && content.runtimeBindings);
|
|
979
|
+
const prepared = {
|
|
980
|
+
layoutKey: isStatic ? content.document : void 0,
|
|
981
|
+
document: content.document,
|
|
982
|
+
get handlers() {
|
|
983
|
+
return preparedBindings.get(prepared)?.content.handlers ?? emptyHandlers;
|
|
984
|
+
},
|
|
985
|
+
dispose: () => release(prepared)
|
|
986
|
+
};
|
|
987
|
+
if (destroyed) content.dispose();
|
|
988
|
+
else
|
|
989
|
+
preparedBindings.set(prepared, {
|
|
990
|
+
ownerKey,
|
|
991
|
+
staticInput: isStatic ? input : void 0,
|
|
992
|
+
version: context.contentVersion,
|
|
993
|
+
context: context.renderContext,
|
|
994
|
+
order: ++sequence,
|
|
995
|
+
content
|
|
996
|
+
});
|
|
997
|
+
return prepared;
|
|
998
|
+
},
|
|
999
|
+
commit(prepared) {
|
|
1000
|
+
const binding = preparedBindings.get(prepared);
|
|
1001
|
+
if (!binding) return;
|
|
1002
|
+
const { ownerKey, order } = binding;
|
|
1003
|
+
if (order < (latest.get(ownerKey) ?? 0)) {
|
|
1004
|
+
release(prepared);
|
|
1005
|
+
return;
|
|
1006
|
+
}
|
|
1007
|
+
const previous = active.get(ownerKey);
|
|
1008
|
+
if (previous && previous !== prepared) release(previous);
|
|
1009
|
+
latest.set(ownerKey, order);
|
|
1010
|
+
active.set(ownerKey, prepared);
|
|
1011
|
+
},
|
|
1012
|
+
dispatch(action) {
|
|
1013
|
+
const { actionId } = action;
|
|
1014
|
+
const key = "target" in action ? contentOwnerKey(action.target) : action.cardId;
|
|
1015
|
+
const prepared = active.get(key);
|
|
1016
|
+
const handler = prepared?.handlers.get(actionId);
|
|
1017
|
+
if (!handler) return false;
|
|
1018
|
+
if (!("target" in action)) handler();
|
|
1019
|
+
else handler(action, preparedBindings.get(prepared)?.context);
|
|
1020
|
+
return true;
|
|
1021
|
+
},
|
|
1022
|
+
release,
|
|
1023
|
+
destroy() {
|
|
1024
|
+
for (const prepared of active.values()) release(prepared);
|
|
1025
|
+
preparedBindings = /* @__PURE__ */ new WeakMap();
|
|
1026
|
+
latest.clear();
|
|
1027
|
+
destroyed = true;
|
|
1028
|
+
}
|
|
1029
|
+
};
|
|
1030
|
+
}
|
|
1031
|
+
function useCommitted(value) {
|
|
1032
|
+
const ref = useRef(value);
|
|
1033
|
+
useInsertionEffect(() => {
|
|
1034
|
+
ref.current = value;
|
|
1035
|
+
}, [value]);
|
|
1036
|
+
return ref;
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
// src/hooks/use-drag-any.ts
|
|
1040
|
+
function shallowEqual(left, right) {
|
|
1041
|
+
if (left === right) return true;
|
|
1042
|
+
if (!left || !right) return false;
|
|
1043
|
+
const a = Object.entries(left);
|
|
1044
|
+
const b = right;
|
|
1045
|
+
return a.length === Object.keys(b).length && a.every(([key, value]) => Object.is(value, b[key]));
|
|
1046
|
+
}
|
|
1047
|
+
function sameScrollbar(left, right) {
|
|
1048
|
+
if (left === right) return true;
|
|
1049
|
+
if (!left || !right) return false;
|
|
1050
|
+
const { horizontal: leftX, vertical: leftY, ...leftCommon } = left;
|
|
1051
|
+
const { horizontal: rightX, vertical: rightY, ...rightCommon } = right;
|
|
1052
|
+
return shallowEqual(leftCommon, rightCommon) && (leftX === rightX || !!leftX && !!rightX && shallowEqual(leftX, rightX)) && (leftY === rightY || !!leftY && !!rightY && shallowEqual(leftY, rightY));
|
|
1053
|
+
}
|
|
1054
|
+
function createContent(bindings, {
|
|
1055
|
+
id,
|
|
1056
|
+
renderCard,
|
|
1057
|
+
render: renderer,
|
|
1058
|
+
renderVersion: version
|
|
1059
|
+
}) {
|
|
1060
|
+
function read(context) {
|
|
1061
|
+
return propsRender(context);
|
|
1062
|
+
}
|
|
1063
|
+
function propsRender(context) {
|
|
1064
|
+
const result = renderer?.(context);
|
|
1065
|
+
if (result !== void 0) return result;
|
|
1066
|
+
return context.target.kind === "card" && "card" in context ? renderCard ? renderCard(context) : context.card.id : context.target.kind === "corner" ? null : "id" in context.target ? context.target.id : null;
|
|
1067
|
+
}
|
|
1068
|
+
function compileContext(context) {
|
|
1069
|
+
return {
|
|
1070
|
+
boardId: id,
|
|
1071
|
+
ownerKey: contentOwnerKey(context.target),
|
|
1072
|
+
target: context.target,
|
|
1073
|
+
cardId: context.target.kind === "card" ? context.target.cardId : void 0,
|
|
1074
|
+
contentVersion: version ?? ("card" in context ? context.card.contentVersion : void 0),
|
|
1075
|
+
renderContext: context
|
|
1076
|
+
};
|
|
1077
|
+
}
|
|
1078
|
+
return {
|
|
1079
|
+
contentRuntime: {
|
|
1080
|
+
createSnapshot(context) {
|
|
1081
|
+
const full = {
|
|
1082
|
+
...context,
|
|
1083
|
+
target: {
|
|
1084
|
+
kind: "card",
|
|
1085
|
+
cardId: context.card.id,
|
|
1086
|
+
containerId: context.container.id
|
|
1087
|
+
}
|
|
1088
|
+
};
|
|
1089
|
+
const prepared = compileInput(read(full), compileContext(full));
|
|
1090
|
+
return {
|
|
1091
|
+
content: prepared.document,
|
|
1092
|
+
dispose: () => prepared.dispose()
|
|
1093
|
+
};
|
|
1094
|
+
},
|
|
1095
|
+
createRegion(context) {
|
|
1096
|
+
const prepared = bindings.prepare(
|
|
1097
|
+
read(context),
|
|
1098
|
+
compileContext(context)
|
|
1099
|
+
);
|
|
1100
|
+
bindings.commit(prepared);
|
|
1101
|
+
return {
|
|
1102
|
+
layoutKey: prepared.layoutKey,
|
|
1103
|
+
content: prepared.document,
|
|
1104
|
+
dispose: () => bindings.release(prepared)
|
|
1105
|
+
};
|
|
1106
|
+
},
|
|
1107
|
+
create(context) {
|
|
1108
|
+
const full = {
|
|
1109
|
+
...context,
|
|
1110
|
+
target: {
|
|
1111
|
+
kind: "card",
|
|
1112
|
+
cardId: context.card.id,
|
|
1113
|
+
containerId: context.container.id
|
|
1114
|
+
}
|
|
1115
|
+
};
|
|
1116
|
+
const prepared = bindings.prepare(read(full), compileContext(full));
|
|
1117
|
+
bindings.commit(prepared);
|
|
1118
|
+
return {
|
|
1119
|
+
content: prepared.document,
|
|
1120
|
+
dispose: () => bindings.release(prepared)
|
|
1121
|
+
};
|
|
1122
|
+
}
|
|
1123
|
+
},
|
|
1124
|
+
renderCard(context) {
|
|
1125
|
+
const full = {
|
|
1126
|
+
...context,
|
|
1127
|
+
target: {
|
|
1128
|
+
kind: "card",
|
|
1129
|
+
cardId: context.card.id,
|
|
1130
|
+
containerId: context.container.id
|
|
1131
|
+
}
|
|
1132
|
+
};
|
|
1133
|
+
const compiled = compileInput(read(full), compileContext(full));
|
|
1134
|
+
compiled.dispose();
|
|
1135
|
+
return compiled.document;
|
|
1136
|
+
}
|
|
1137
|
+
};
|
|
1138
|
+
}
|
|
1139
|
+
function useDragAny(props, owner, group, events) {
|
|
1140
|
+
if (group && (props.model !== void 0 || props.acknowledgedTransactionId !== void 0 || props.onMoveRequest !== void 0)) {
|
|
1141
|
+
throw new Error("\u753B\u5E03\u7EC4\u6210\u5458\u5FC5\u987B\u7531\u4E0A\u5C42\u753B\u5E03\u7EC4\u63D0\u4F9B\u6A21\u578B\u548C\u79FB\u52A8\u56DE\u8C03");
|
|
1142
|
+
}
|
|
1143
|
+
const latest = useCommitted(props);
|
|
1144
|
+
const handlers = useCommitted(events);
|
|
1145
|
+
const instance = useRef();
|
|
1146
|
+
function optionsFor(current, content, scrollbar, bridge2) {
|
|
1147
|
+
return {
|
|
1148
|
+
...content,
|
|
1149
|
+
scrollbar,
|
|
1150
|
+
layout: current.layout,
|
|
1151
|
+
renderVersion: current.renderVersion,
|
|
1152
|
+
animation: current.animation,
|
|
1153
|
+
annotations: current.annotations,
|
|
1154
|
+
input: current.input,
|
|
1155
|
+
contentScroll: current.contentScroll,
|
|
1156
|
+
contextMenu: current.contextMenu,
|
|
1157
|
+
theme: current.theme,
|
|
1158
|
+
selectedCardIds: current.selectedCardIds,
|
|
1159
|
+
...bridge2,
|
|
1160
|
+
canDrag: current.canDrag ? bridge2.canDrag : void 0,
|
|
1161
|
+
canDrop: current.canDrop ? bridge2.canDrop : void 0
|
|
1162
|
+
};
|
|
1163
|
+
}
|
|
1164
|
+
const bridgeRef = useRef();
|
|
1165
|
+
if (!bridgeRef.current) {
|
|
1166
|
+
bridgeRef.current = {
|
|
1167
|
+
onMoveRequest: (proposal) => latest.current.onMoveRequest?.(proposal),
|
|
1168
|
+
onDragCancel: (reason) => latest.current.onDragCancel?.(reason),
|
|
1169
|
+
onDragEnd: () => latest.current.onDragEnd?.(),
|
|
1170
|
+
onDragTargetChange: (target, verdict) => latest.current.onDragTargetChange?.(target, verdict),
|
|
1171
|
+
onSelectionChange: (cardIds) => latest.current.onSelectionChange?.(cardIds),
|
|
1172
|
+
onError: (error) => latest.current.onError?.(error),
|
|
1173
|
+
onContentError: (event) => latest.current.onContentError?.(event),
|
|
1174
|
+
onContextMenuRequest: (request) => handlers.current.onContextMenuRequest?.(request),
|
|
1175
|
+
onDragStart: (context) => handlers.current.onDragStart?.(context),
|
|
1176
|
+
onRegionContentAction: (action) => {
|
|
1177
|
+
instance.current?.bindings.dispatch(action);
|
|
1178
|
+
if (!action.nativeEvent.cancelBubble) {
|
|
1179
|
+
if (latest.current.onRegionContentAction)
|
|
1180
|
+
latest.current.onRegionContentAction(action);
|
|
1181
|
+
else if (action.target.kind === "card")
|
|
1182
|
+
latest.current.onContentAction?.({
|
|
1183
|
+
...action,
|
|
1184
|
+
cardId: action.target.cardId,
|
|
1185
|
+
containerId: action.target.containerId
|
|
1186
|
+
});
|
|
1187
|
+
}
|
|
1188
|
+
},
|
|
1189
|
+
onContentAction: (action) => {
|
|
1190
|
+
if (!action.nativeEvent.cancelBubble)
|
|
1191
|
+
latest.current.onContentAction?.(action);
|
|
1192
|
+
},
|
|
1193
|
+
canDrag: (context) => latest.current.canDrag?.(context) ?? true,
|
|
1194
|
+
canDrop: (context) => latest.current.canDrop?.(context) ?? { allowed: true }
|
|
1195
|
+
};
|
|
1196
|
+
}
|
|
1197
|
+
const bridge = bridgeRef.current;
|
|
1198
|
+
useLayoutEffect(() => {
|
|
1199
|
+
function mount() {
|
|
1200
|
+
const host = owner.current;
|
|
1201
|
+
const current = latest.current;
|
|
1202
|
+
const model = group ? group.getModel(current.id) : current.model;
|
|
1203
|
+
if (!model) {
|
|
1204
|
+
if (group) return;
|
|
1205
|
+
throw new Error("\u72EC\u7ACB\u753B\u5E03\u5FC5\u987B\u63D0\u4F9B\u6A21\u578B");
|
|
1206
|
+
}
|
|
1207
|
+
const bindings = createContentBindings();
|
|
1208
|
+
const content = createContent(bindings, current);
|
|
1209
|
+
const scrollbar = readScrollbarSettings(current.storageKey, host) ?? current.scrollbar;
|
|
1210
|
+
const options = optionsFor(current, content, scrollbar, bridge);
|
|
1211
|
+
const board = dragAnyProjection.create({
|
|
1212
|
+
...options,
|
|
1213
|
+
id: current.id,
|
|
1214
|
+
model
|
|
1215
|
+
});
|
|
1216
|
+
if (group && !group.ensureGroup().register(board)) {
|
|
1217
|
+
board.destroy();
|
|
1218
|
+
bindings.destroy();
|
|
1219
|
+
return;
|
|
1220
|
+
}
|
|
1221
|
+
const view = host.ownerDocument.defaultView;
|
|
1222
|
+
let frame;
|
|
1223
|
+
let suspended = false;
|
|
1224
|
+
function updateVisibility() {
|
|
1225
|
+
const hidden = latest.current.active === false || !host.clientWidth || !host.clientHeight;
|
|
1226
|
+
if (hidden === suspended) return;
|
|
1227
|
+
suspended = hidden;
|
|
1228
|
+
if (hidden) {
|
|
1229
|
+
board.suspend();
|
|
1230
|
+
handlers.current.onContextMenuRequest?.(null);
|
|
1231
|
+
} else {
|
|
1232
|
+
board.resume();
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
function queueVisibility() {
|
|
1236
|
+
frame ?? (frame = view.requestAnimationFrame(() => {
|
|
1237
|
+
frame = void 0;
|
|
1238
|
+
updateVisibility();
|
|
1239
|
+
}));
|
|
1240
|
+
}
|
|
1241
|
+
instance.current = {
|
|
1242
|
+
board,
|
|
1243
|
+
bindings,
|
|
1244
|
+
props: current,
|
|
1245
|
+
content,
|
|
1246
|
+
options,
|
|
1247
|
+
scrollbar,
|
|
1248
|
+
updateVisibility
|
|
1249
|
+
};
|
|
1250
|
+
board.mount(host);
|
|
1251
|
+
updateVisibility();
|
|
1252
|
+
const observer = view.ResizeObserver ? new view.ResizeObserver(queueVisibility) : void 0;
|
|
1253
|
+
observer?.observe(host);
|
|
1254
|
+
view.addEventListener("resize", queueVisibility);
|
|
1255
|
+
return () => {
|
|
1256
|
+
instance.current = void 0;
|
|
1257
|
+
if (frame !== void 0) view.cancelAnimationFrame(frame);
|
|
1258
|
+
view.removeEventListener("resize", queueVisibility);
|
|
1259
|
+
observer?.disconnect();
|
|
1260
|
+
board.destroy();
|
|
1261
|
+
bindings.destroy();
|
|
1262
|
+
};
|
|
1263
|
+
}
|
|
1264
|
+
let dispose = mount();
|
|
1265
|
+
const unsubscribe = group?.subscribe(() => {
|
|
1266
|
+
if (group.getModel(props.id)) {
|
|
1267
|
+
dispose ?? (dispose = mount());
|
|
1268
|
+
} else if (dispose) {
|
|
1269
|
+
const cleanup = dispose;
|
|
1270
|
+
dispose = void 0;
|
|
1271
|
+
cleanup();
|
|
1272
|
+
handlers.current.onContextMenuRequest?.(null);
|
|
1273
|
+
}
|
|
1274
|
+
});
|
|
1275
|
+
return () => {
|
|
1276
|
+
unsubscribe?.();
|
|
1277
|
+
dispose?.();
|
|
1278
|
+
};
|
|
1279
|
+
}, [bridge, group, handlers, latest, owner, props.id]);
|
|
1280
|
+
useLayoutEffect(() => {
|
|
1281
|
+
const current = instance.current;
|
|
1282
|
+
if (!current) return;
|
|
1283
|
+
const previous = current.props;
|
|
1284
|
+
current.props = props;
|
|
1285
|
+
if (previous.storageKey !== props.storageKey) {
|
|
1286
|
+
current.scrollbar = readScrollbarSettings(props.storageKey, owner.current) ?? props.scrollbar;
|
|
1287
|
+
} else if (!sameScrollbar(previous.scrollbar, props.scrollbar)) {
|
|
1288
|
+
current.scrollbar = props.scrollbar;
|
|
1289
|
+
}
|
|
1290
|
+
if (previous.renderCard !== props.renderCard || previous.render !== props.render || previous.renderVersion !== props.renderVersion)
|
|
1291
|
+
current.content = createContent(current.bindings, props);
|
|
1292
|
+
if (!group && props.model && (previous.model !== props.model || previous.acknowledgedTransactionId !== props.acknowledgedTransactionId)) {
|
|
1293
|
+
dragAnyProjection.update(current.board, props.model, {
|
|
1294
|
+
transactionId: props.acknowledgedTransactionId,
|
|
1295
|
+
layout: props.model.documentKind ? props.layout : void 0
|
|
1296
|
+
});
|
|
1297
|
+
}
|
|
1298
|
+
const options = optionsFor(
|
|
1299
|
+
props,
|
|
1300
|
+
current.content,
|
|
1301
|
+
current.scrollbar,
|
|
1302
|
+
bridge
|
|
1303
|
+
);
|
|
1304
|
+
if (Object.keys(options).some(
|
|
1305
|
+
(key) => options[key] !== current.options[key]
|
|
1306
|
+
)) {
|
|
1307
|
+
current.options = options;
|
|
1308
|
+
dragAnyProjection.configure(current.board, options);
|
|
1309
|
+
}
|
|
1310
|
+
if (previous.active !== props.active) current.updateVisibility();
|
|
1311
|
+
});
|
|
1312
|
+
return instance;
|
|
1313
|
+
}
|
|
1314
|
+
function declaration(name) {
|
|
1315
|
+
throw new Error(name + " \u987B\u58F0\u660E\u5728 ReactDragAny \u5185");
|
|
1316
|
+
}
|
|
1317
|
+
function Lanes(_props) {
|
|
1318
|
+
return declaration("Lanes");
|
|
1319
|
+
}
|
|
1320
|
+
function Lane(_props) {
|
|
1321
|
+
return declaration("Lane");
|
|
1322
|
+
}
|
|
1323
|
+
function SparseGrid(_props) {
|
|
1324
|
+
return declaration("SparseGrid");
|
|
1325
|
+
}
|
|
1326
|
+
function GridSlot(_props) {
|
|
1327
|
+
return declaration("GridSlot");
|
|
1328
|
+
}
|
|
1329
|
+
function Queue(_props) {
|
|
1330
|
+
return declaration("Queue");
|
|
1331
|
+
}
|
|
1332
|
+
function Flow(_props) {
|
|
1333
|
+
return declaration("Flow");
|
|
1334
|
+
}
|
|
1335
|
+
function Card(_props) {
|
|
1336
|
+
return declaration("Card");
|
|
1337
|
+
}
|
|
1338
|
+
function readStructureElements(input, path, depth = 0) {
|
|
1339
|
+
if (depth > 100) throw new DragDocumentError(path, "\u7ED3\u6784\u5D4C\u5957\u8FC7\u6DF1");
|
|
1340
|
+
if (input == null || typeof input === "boolean") return [];
|
|
1341
|
+
if (Array.isArray(input))
|
|
1342
|
+
return input.flatMap(
|
|
1343
|
+
(item, i) => readStructureElements(item, `${path}[${i}]`, depth + 1)
|
|
1344
|
+
);
|
|
1345
|
+
if (!isValidElement(input))
|
|
1346
|
+
throw new DragDocumentError(path, "\u987B\u4E3A\u753B\u5E03\u7ED3\u6784\u58F0\u660E");
|
|
1347
|
+
if (input.type === Fragment$1)
|
|
1348
|
+
return readStructureElements(
|
|
1349
|
+
input.props.children,
|
|
1350
|
+
path,
|
|
1351
|
+
depth + 1
|
|
1352
|
+
);
|
|
1353
|
+
return [input];
|
|
1354
|
+
}
|
|
1355
|
+
function readCollection(props, name, path, type, read) {
|
|
1356
|
+
if (props[name] !== void 0) {
|
|
1357
|
+
if (props.children !== void 0)
|
|
1358
|
+
throw new DragDocumentError(path, `${name} \u4E0E children \u4E92\u65A5`);
|
|
1359
|
+
return props[name];
|
|
1360
|
+
}
|
|
1361
|
+
return readStructureElements(
|
|
1362
|
+
props.children,
|
|
1363
|
+
path + ".children"
|
|
1364
|
+
).map((node, index) => {
|
|
1365
|
+
const at = `${path}.children[${index}]`;
|
|
1366
|
+
if (node.type !== type) throw new DragDocumentError(at, "\u7ED3\u6784\u5D4C\u5957\u4E0D\u5408\u6CD5");
|
|
1367
|
+
return read(node.props, at);
|
|
1368
|
+
});
|
|
1369
|
+
}
|
|
1370
|
+
function readCard({ children, ...props }, path) {
|
|
1371
|
+
if (children !== void 0 && props.content !== void 0)
|
|
1372
|
+
throw new DragDocumentError(path, "content \u4E0E children \u4E92\u65A5");
|
|
1373
|
+
return children === void 0 ? props : { ...props, content: children };
|
|
1374
|
+
}
|
|
1375
|
+
function readContainer(props, path) {
|
|
1376
|
+
const cards = readCollection(props, "cards", path, Card, readCard);
|
|
1377
|
+
const { children: _children, ...data } = props;
|
|
1378
|
+
return { ...data, cards };
|
|
1379
|
+
}
|
|
1380
|
+
function compileDragStructure(children) {
|
|
1381
|
+
const roots = readStructureElements(children, "$");
|
|
1382
|
+
if (roots.length !== 1) throw new DragDocumentError("$", "\u987B\u6709\u4E00\u4E2A\u5E03\u5C40\u6839");
|
|
1383
|
+
const [{ type, props }] = roots;
|
|
1384
|
+
const { children: _children, ...data } = props;
|
|
1385
|
+
if (type === Lanes)
|
|
1386
|
+
return {
|
|
1387
|
+
...data,
|
|
1388
|
+
type: "lanes",
|
|
1389
|
+
lanes: readCollection(props, "lanes", "$", Lane, readContainer)
|
|
1390
|
+
};
|
|
1391
|
+
if (type === SparseGrid)
|
|
1392
|
+
return {
|
|
1393
|
+
...data,
|
|
1394
|
+
type: "sparse-grid",
|
|
1395
|
+
slots: readCollection(props, "slots", "$", GridSlot, readContainer)
|
|
1396
|
+
};
|
|
1397
|
+
if (type === Queue || type === Flow)
|
|
1398
|
+
return {
|
|
1399
|
+
...readContainer(props, "$"),
|
|
1400
|
+
type: type === Queue ? "queue" : "flow"
|
|
1401
|
+
};
|
|
1402
|
+
throw new DragDocumentError("$", "\u65E0\u6548\u7684\u5E03\u5C40\u6839");
|
|
1403
|
+
}
|
|
1404
|
+
|
|
1405
|
+
// src/components/compile-ui-structure.ts
|
|
1406
|
+
var pixelValue2 = /^(-?(?:\d+(?:\.\d+)?|\.\d+))px$/;
|
|
1407
|
+
var contentTags = new Set(Object.values(UI));
|
|
1408
|
+
function readPixels(value, path, allowZero = false) {
|
|
1409
|
+
if (value === void 0) return void 0;
|
|
1410
|
+
const match = typeof value === "string" ? pixelValue2.exec(value) : null;
|
|
1411
|
+
const pixels = match ? Number(match[1]) : value;
|
|
1412
|
+
if (typeof pixels !== "number" || !Number.isFinite(pixels) || (allowZero ? pixels < 0 : pixels <= 0))
|
|
1413
|
+
throw new DragDocumentError(
|
|
1414
|
+
path,
|
|
1415
|
+
allowZero ? "\u987B\u4E3A\u975E\u8D1F\u50CF\u7D20\u503C" : "\u987B\u4E3A\u6B63\u50CF\u7D20\u503C"
|
|
1416
|
+
);
|
|
1417
|
+
return pixels;
|
|
1418
|
+
}
|
|
1419
|
+
function readStyle(node, path) {
|
|
1420
|
+
const { style } = node.props;
|
|
1421
|
+
if (style === void 0) return {};
|
|
1422
|
+
if (style === null || typeof style !== "object" || Array.isArray(style))
|
|
1423
|
+
throw new DragDocumentError(path + ".style", "\u987B\u4E3A Canvas UI \u6837\u5F0F");
|
|
1424
|
+
return style;
|
|
1425
|
+
}
|
|
1426
|
+
function readContainer2(node, path, axis, dimensions) {
|
|
1427
|
+
const style = readStyle(node, path);
|
|
1428
|
+
const fixedAxis = node.type === UI.Col ? "column" : node.type === UI.Row ? "row" : void 0;
|
|
1429
|
+
const direction = fixedAxis ?? (node.type === UI.Flex ? style.flexDirection ?? node.props.direction ?? "row" : void 0);
|
|
1430
|
+
if (direction !== axis)
|
|
1431
|
+
throw new DragDocumentError(
|
|
1432
|
+
path,
|
|
1433
|
+
axis === "row" ? "\u987B\u4F7F\u7528\u6A2A\u5411 Canvas UI \u5BB9\u5668" : "\u987B\u4F7F\u7528\u7EB5\u5411 Canvas UI \u5BB9\u5668"
|
|
1434
|
+
);
|
|
1435
|
+
const fixedStyle = {
|
|
1436
|
+
...fixedAxis ? {} : { flexDirection: axis },
|
|
1437
|
+
display: "flex",
|
|
1438
|
+
flexWrap: "nowrap",
|
|
1439
|
+
alignItems: "stretch",
|
|
1440
|
+
justifyContent: "flex-start",
|
|
1441
|
+
...Object.fromEntries(dimensions.map((name) => [name, style[name]]))
|
|
1442
|
+
};
|
|
1443
|
+
for (const [name, value] of Object.entries(style)) {
|
|
1444
|
+
if (value !== void 0 && (!Object.prototype.hasOwnProperty.call(fixedStyle, name) || fixedStyle[name] !== value))
|
|
1445
|
+
throw new DragDocumentError(
|
|
1446
|
+
`${path}.style.${name}`,
|
|
1447
|
+
"\u5F53\u524D\u62D6\u62FD\u5E03\u5C40\u65E0\u6CD5\u6295\u5F71\u6B64\u6837\u5F0F"
|
|
1448
|
+
);
|
|
1449
|
+
}
|
|
1450
|
+
const fixedProps = {
|
|
1451
|
+
children: node.props.children,
|
|
1452
|
+
style: node.props.style,
|
|
1453
|
+
visible: true,
|
|
1454
|
+
...dimensions.includes("gap") ? { gap: node.props.gap } : {},
|
|
1455
|
+
...fixedAxis ? {} : { direction: axis },
|
|
1456
|
+
align: "stretch",
|
|
1457
|
+
justify: "flex-start"
|
|
1458
|
+
};
|
|
1459
|
+
for (const [name, value] of Object.entries(node.props)) {
|
|
1460
|
+
if (value !== void 0 && (!Object.prototype.hasOwnProperty.call(fixedProps, name) || fixedProps[name] !== value))
|
|
1461
|
+
throw new DragDocumentError(
|
|
1462
|
+
`${path}.${name}`,
|
|
1463
|
+
"\u5F53\u524D\u62D6\u62FD\u5E03\u5C40\u65E0\u6CD5\u6295\u5F71\u6B64\u5C5E\u6027"
|
|
1464
|
+
);
|
|
1465
|
+
}
|
|
1466
|
+
if (dimensions.includes("flex") && style.flex !== void 0 && style.flex !== 1)
|
|
1467
|
+
throw new DragDocumentError(path + ".style.flex", "\u5361\u7247\u7EC4\u4EC5\u652F\u6301 flex: 1");
|
|
1468
|
+
return style;
|
|
1469
|
+
}
|
|
1470
|
+
function readGap(node, style, path) {
|
|
1471
|
+
return style.gap === void 0 ? readPixels(node.props.gap, path + ".gap", true) : readPixels(style.gap, path + ".style.gap", true);
|
|
1472
|
+
}
|
|
1473
|
+
function readContent(node, path, dimension) {
|
|
1474
|
+
if (!contentTags.has(node.type))
|
|
1475
|
+
throw new DragDocumentError(path, "\u5361\u7247\u548C\u6807\u9898\u987B\u4F7F\u7528 Canvas UI JSX");
|
|
1476
|
+
const style = readStyle(node, path);
|
|
1477
|
+
const size = readPixels(style[dimension], `${path}.style.${dimension}`);
|
|
1478
|
+
if (style.flexShrink !== void 0 && style.flexShrink !== 0)
|
|
1479
|
+
throw new DragDocumentError(
|
|
1480
|
+
path + ".style.flexShrink",
|
|
1481
|
+
"\u5361\u7247\u548C\u6807\u9898\u4EC5\u652F\u6301 flexShrink: 0"
|
|
1482
|
+
);
|
|
1483
|
+
let content = node;
|
|
1484
|
+
if (size !== void 0 || style.flexShrink !== void 0) {
|
|
1485
|
+
const { [dimension]: _size, flexShrink: _shrink, ...contentStyle } = style;
|
|
1486
|
+
content = cloneElement(node, { style: contentStyle });
|
|
1487
|
+
}
|
|
1488
|
+
return { size, content };
|
|
1489
|
+
}
|
|
1490
|
+
function sharedPixels(description) {
|
|
1491
|
+
let current;
|
|
1492
|
+
return {
|
|
1493
|
+
read() {
|
|
1494
|
+
return current;
|
|
1495
|
+
},
|
|
1496
|
+
add(value, path) {
|
|
1497
|
+
if (value === void 0) return;
|
|
1498
|
+
if (current !== void 0 && current !== value)
|
|
1499
|
+
throw new DragDocumentError(path, `\u6240\u6709\u6CF3\u9053\u7684${description}\u987B\u4E00\u81F4`);
|
|
1500
|
+
current = value;
|
|
1501
|
+
}
|
|
1502
|
+
};
|
|
1503
|
+
}
|
|
1504
|
+
function readChildren(node, path) {
|
|
1505
|
+
const at = path + ".children";
|
|
1506
|
+
return readStructureElements(node.props.children, at).map(
|
|
1507
|
+
(element, index) => ({ node: element, path: `${at}[${index}]` })
|
|
1508
|
+
);
|
|
1509
|
+
}
|
|
1510
|
+
function readId(ids, id, path) {
|
|
1511
|
+
if (typeof id !== "string" || id.length === 0)
|
|
1512
|
+
throw new DragDocumentError(path, "\u4E1A\u52A1 ID \u987B\u4E3A\u975E\u7A7A\u5B57\u7B26\u4E32");
|
|
1513
|
+
if (ids.has(id)) throw new DragDocumentError(path, `\u4E1A\u52A1 ID \u91CD\u590D\uFF1A${id}`);
|
|
1514
|
+
ids.add(id);
|
|
1515
|
+
}
|
|
1516
|
+
function compileDragUIStructure(children, options) {
|
|
1517
|
+
const { dragLayout, getDragRole } = options;
|
|
1518
|
+
const roots = readStructureElements(children, "$");
|
|
1519
|
+
if (roots.length !== 1) throw new DragDocumentError("$", "\u987B\u6709\u4E00\u4E2A\u5E03\u5C40\u6839");
|
|
1520
|
+
const root = roots[0];
|
|
1521
|
+
const rootStyle = readContainer2(root, "$", "column", ["gap"]);
|
|
1522
|
+
const rootGap = readGap(root, rootStyle, "$");
|
|
1523
|
+
const keys = /* @__PURE__ */ new Set();
|
|
1524
|
+
const cardIds = /* @__PURE__ */ new Set();
|
|
1525
|
+
function readRole(node, path, ...expected) {
|
|
1526
|
+
const key = node.key;
|
|
1527
|
+
if (key == null || key === "")
|
|
1528
|
+
throw new DragDocumentError(path + ".key", "\u7ED3\u6784\u8282\u70B9\u987B\u58F0\u660E\u975E\u7A7A JSX key");
|
|
1529
|
+
if (keys.has(key))
|
|
1530
|
+
throw new DragDocumentError(path + ".key", `\u7ED3\u6784\u952E\u91CD\u590D\uFF1A${key}`);
|
|
1531
|
+
keys.add(key);
|
|
1532
|
+
const role = getDragRole(key);
|
|
1533
|
+
if (!role || !expected.some((kind) => kind === role.kind))
|
|
1534
|
+
throw new DragDocumentError(
|
|
1535
|
+
path,
|
|
1536
|
+
`\u7ED3\u6784\u8282\u70B9 ${key} \u987B\u7ED1\u5B9A\u89D2\u8272 ${expected.join(" \u6216 ")}`
|
|
1537
|
+
);
|
|
1538
|
+
return role;
|
|
1539
|
+
}
|
|
1540
|
+
function readCards(node, path, dimension) {
|
|
1541
|
+
return readChildren(node, path).map(({ node: card, path: at }) => {
|
|
1542
|
+
const role = readRole(card, at, "card");
|
|
1543
|
+
readId(cardIds, role.id, at);
|
|
1544
|
+
const { content, size } = readContent(card, at, dimension);
|
|
1545
|
+
return {
|
|
1546
|
+
id: role.id,
|
|
1547
|
+
data: role.data,
|
|
1548
|
+
content,
|
|
1549
|
+
...role.disabled === void 0 ? {} : { disabled: role.disabled },
|
|
1550
|
+
...size === void 0 ? {} : { size: { [dimension]: size } }
|
|
1551
|
+
};
|
|
1552
|
+
});
|
|
1553
|
+
}
|
|
1554
|
+
if (dragLayout === "queue")
|
|
1555
|
+
return {
|
|
1556
|
+
type: "queue",
|
|
1557
|
+
cardGap: rootGap,
|
|
1558
|
+
cards: readCards(root, "$", "height")
|
|
1559
|
+
};
|
|
1560
|
+
if (rootGap)
|
|
1561
|
+
throw new DragDocumentError(
|
|
1562
|
+
rootStyle.gap === void 0 ? "$.gap" : "$.style.gap",
|
|
1563
|
+
"\u5F53\u524D\u5E03\u5C40\u4E0D\u652F\u6301\u6CF3\u9053\u95F4\u8DDD"
|
|
1564
|
+
);
|
|
1565
|
+
const regionIds = /* @__PURE__ */ new Set();
|
|
1566
|
+
const laneHeight = sharedPixels("\u9AD8\u5EA6");
|
|
1567
|
+
const headerWidth = sharedPixels("\u6807\u9898\u5BBD\u5EA6");
|
|
1568
|
+
const cardGap = sharedPixels("\u5361\u7247\u95F4\u8DDD");
|
|
1569
|
+
const padding = sharedPixels("\u5361\u7247\u7EC4\u5185\u8FB9\u8DDD");
|
|
1570
|
+
let hasHeader = false;
|
|
1571
|
+
const lanes = readChildren(root, "$").map(
|
|
1572
|
+
({ node: lane, path }) => {
|
|
1573
|
+
const role = readRole(lane, path, "region");
|
|
1574
|
+
readId(regionIds, role.id, path);
|
|
1575
|
+
const laneStyle = readContainer2(lane, path, "row", ["height"]);
|
|
1576
|
+
const heightPath = path + ".style.height";
|
|
1577
|
+
laneHeight.add(readPixels(laneStyle.height, heightPath), heightPath);
|
|
1578
|
+
let header = null;
|
|
1579
|
+
let cards;
|
|
1580
|
+
for (const { node, path: at } of readChildren(lane, path)) {
|
|
1581
|
+
const childRole = readRole(node, at, "header", "items");
|
|
1582
|
+
if (childRole.kind === "header") {
|
|
1583
|
+
if (header || cards)
|
|
1584
|
+
throw new DragDocumentError(
|
|
1585
|
+
at,
|
|
1586
|
+
"\u6807\u9898\u53EA\u80FD\u51FA\u73B0\u4E00\u6B21\u4E14\u987B\u4F4D\u4E8E\u5361\u7247\u7EC4\u4E4B\u524D"
|
|
1587
|
+
);
|
|
1588
|
+
const { size, content } = readContent(node, at, "width");
|
|
1589
|
+
header = content;
|
|
1590
|
+
hasHeader = true;
|
|
1591
|
+
headerWidth.add(size, at + ".style.width");
|
|
1592
|
+
} else {
|
|
1593
|
+
if (cards)
|
|
1594
|
+
throw new DragDocumentError(at, "\u6CF3\u9053\u987B\u6709\u4E14\u4EC5\u6709\u4E00\u4E2A\u5361\u7247\u7EC4");
|
|
1595
|
+
const itemsStyle = readContainer2(node, at, "row", [
|
|
1596
|
+
"gap",
|
|
1597
|
+
"flex",
|
|
1598
|
+
"padding"
|
|
1599
|
+
]);
|
|
1600
|
+
cardGap.add(
|
|
1601
|
+
readGap(node, itemsStyle, at),
|
|
1602
|
+
at + (itemsStyle.gap === void 0 ? ".gap" : ".style.gap")
|
|
1603
|
+
);
|
|
1604
|
+
const paddingPath = at + ".style.padding";
|
|
1605
|
+
padding.add(
|
|
1606
|
+
readPixels(itemsStyle.padding, paddingPath, true),
|
|
1607
|
+
paddingPath
|
|
1608
|
+
);
|
|
1609
|
+
cards = readCards(node, at, "width");
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
if (!cards) throw new DragDocumentError(path, "\u6CF3\u9053\u987B\u6709\u4E00\u4E2A\u5361\u7247\u7EC4");
|
|
1613
|
+
return { id: role.id, dropDisabled: role.dropDisabled, header, cards };
|
|
1614
|
+
}
|
|
1615
|
+
);
|
|
1616
|
+
return {
|
|
1617
|
+
type: "lanes",
|
|
1618
|
+
laneHeight: laneHeight.read(),
|
|
1619
|
+
headerWidth: hasHeader ? headerWidth.read() : 0,
|
|
1620
|
+
cardGap: cardGap.read(),
|
|
1621
|
+
padding: padding.read(),
|
|
1622
|
+
lanes
|
|
1623
|
+
};
|
|
1624
|
+
}
|
|
1625
|
+
var DragGroupContext = createContext(
|
|
1626
|
+
null
|
|
1627
|
+
);
|
|
1628
|
+
function isEnabledAction(items, key) {
|
|
1629
|
+
return items.some(
|
|
1630
|
+
(item) => !item.disabled && (item.children?.length ? isEnabledAction(item.children, key) : item.key === key)
|
|
1631
|
+
);
|
|
1632
|
+
}
|
|
1633
|
+
function Board(props, ref) {
|
|
1634
|
+
const group = useContext(DragGroupContext);
|
|
1635
|
+
const owner = useRef(null);
|
|
1636
|
+
const [mounted, setMounted] = useState(false);
|
|
1637
|
+
const [menu, setMenu] = useState();
|
|
1638
|
+
const request = menu?.request;
|
|
1639
|
+
const [dialog, setDialog] = useState();
|
|
1640
|
+
const menuOpen = useRef(false);
|
|
1641
|
+
function closeMenu() {
|
|
1642
|
+
if (!menuOpen.current) return;
|
|
1643
|
+
menuOpen.current = false;
|
|
1644
|
+
setMenu(void 0);
|
|
1645
|
+
}
|
|
1646
|
+
const instance = useDragAny(props, owner, group, {
|
|
1647
|
+
onContextMenuRequest(next) {
|
|
1648
|
+
if (next && isTargetValid(next)) {
|
|
1649
|
+
const nextItems = menuItems(next);
|
|
1650
|
+
menuOpen.current = nextItems.length > 0;
|
|
1651
|
+
setMenu(
|
|
1652
|
+
menuOpen.current ? { request: next, items: nextItems } : void 0
|
|
1653
|
+
);
|
|
1654
|
+
} else {
|
|
1655
|
+
closeMenu();
|
|
1656
|
+
}
|
|
1657
|
+
props.onContextMenuRequest?.(next);
|
|
1658
|
+
},
|
|
1659
|
+
onDragStart(context) {
|
|
1660
|
+
closeMenu();
|
|
1661
|
+
props.onDragStart?.(context);
|
|
1662
|
+
}
|
|
1663
|
+
});
|
|
1664
|
+
useLayoutEffect(() => {
|
|
1665
|
+
setMounted(true);
|
|
1666
|
+
}, []);
|
|
1667
|
+
useImperativeHandle(props.rootRef, () => owner.current, []);
|
|
1668
|
+
useImperativeHandle(
|
|
1669
|
+
ref,
|
|
1670
|
+
() => ({
|
|
1671
|
+
scrollTo(target) {
|
|
1672
|
+
return instance.current?.board.scrollTo(target) ?? false;
|
|
1673
|
+
},
|
|
1674
|
+
focusCard(cardId) {
|
|
1675
|
+
return instance.current?.board.focusCard(cardId) ?? false;
|
|
1676
|
+
},
|
|
1677
|
+
cancelDrag(reason) {
|
|
1678
|
+
instance.current?.board.cancelDrag(reason);
|
|
1679
|
+
},
|
|
1680
|
+
rejectMove(transactionId, reason) {
|
|
1681
|
+
const board = instance.current?.board;
|
|
1682
|
+
return board ? (group?.ensureGroup() ?? board).rejectMove(transactionId, reason) : false;
|
|
1683
|
+
},
|
|
1684
|
+
getSnapshot: () => instance.current?.board.getSnapshot()
|
|
1685
|
+
}),
|
|
1686
|
+
[group, instance]
|
|
1687
|
+
);
|
|
1688
|
+
function isTargetValid(menu2) {
|
|
1689
|
+
const snapshot = instance.current?.board.getSnapshot();
|
|
1690
|
+
if (!snapshot || props.active === false || props.contextMenu === false || menu2.boardId !== props.id || menu2.modelRevision !== snapshot.model.revision || snapshot.session.phase !== "idle" && snapshot.session.phase !== "potential")
|
|
1691
|
+
return false;
|
|
1692
|
+
if (menu2.cardId !== void 0 && !snapshot.model.cards.has(menu2.cardId))
|
|
1693
|
+
return false;
|
|
1694
|
+
if (menu2.containerId !== void 0 && !snapshot.model.containers.has(menu2.containerId))
|
|
1695
|
+
return false;
|
|
1696
|
+
return menu2.headerId === void 0 || getHeaderRegions(snapshot.layout, snapshot.index).some(
|
|
1697
|
+
(region) => region.id === menu2.headerId && region.kind === menu2.region
|
|
1698
|
+
);
|
|
1699
|
+
}
|
|
1700
|
+
function copyText(menu2) {
|
|
1701
|
+
const current = instance.current;
|
|
1702
|
+
const model = current?.board.getSnapshot().model;
|
|
1703
|
+
const card = menu2.cardId === void 0 ? void 0 : model?.cards.get(menu2.cardId);
|
|
1704
|
+
const container = menu2.containerId === void 0 ? void 0 : model?.containers.get(menu2.containerId);
|
|
1705
|
+
if (!card || !container || !current) return void 0;
|
|
1706
|
+
try {
|
|
1707
|
+
return getContentPlainText(
|
|
1708
|
+
current.content.renderCard({
|
|
1709
|
+
card,
|
|
1710
|
+
container,
|
|
1711
|
+
selected: props.selectedCardIds?.includes(card.id) ?? false,
|
|
1712
|
+
disabled: !!(card.disabled || container.disabled)
|
|
1713
|
+
})
|
|
1714
|
+
);
|
|
1715
|
+
} catch (error) {
|
|
1716
|
+
props.onError?.(error);
|
|
1717
|
+
return void 0;
|
|
1718
|
+
}
|
|
1719
|
+
}
|
|
1720
|
+
function menuItems(menu2) {
|
|
1721
|
+
const defaults = getDefaultContextMenuItems(menu2, copyText(menu2));
|
|
1722
|
+
try {
|
|
1723
|
+
return [
|
|
1724
|
+
...defaults,
|
|
1725
|
+
...props.contextMenu && props.contextMenu.getItems?.(menu2) || []
|
|
1726
|
+
];
|
|
1727
|
+
} catch (error) {
|
|
1728
|
+
props.onError?.(error);
|
|
1729
|
+
return defaults;
|
|
1730
|
+
}
|
|
1731
|
+
}
|
|
1732
|
+
useLayoutEffect(() => {
|
|
1733
|
+
if (!request) return;
|
|
1734
|
+
if (!isTargetValid(request)) closeMenu();
|
|
1735
|
+
else setMenu({ request, items: menuItems(request) });
|
|
1736
|
+
}, [
|
|
1737
|
+
props.contextMenu,
|
|
1738
|
+
props.renderCard,
|
|
1739
|
+
props.active,
|
|
1740
|
+
props.id,
|
|
1741
|
+
props.layout,
|
|
1742
|
+
props.model
|
|
1743
|
+
]);
|
|
1744
|
+
useLayoutEffect(() => {
|
|
1745
|
+
if (!request || !group) return;
|
|
1746
|
+
return group.subscribe(() => {
|
|
1747
|
+
if (!isTargetValid(request)) closeMenu();
|
|
1748
|
+
});
|
|
1749
|
+
}, [group, request]);
|
|
1750
|
+
useLayoutEffect(() => {
|
|
1751
|
+
if (props.active === false) setDialog(void 0);
|
|
1752
|
+
}, [props.active]);
|
|
1753
|
+
function applyScrollbar(value) {
|
|
1754
|
+
const current = instance.current;
|
|
1755
|
+
if (!current) return;
|
|
1756
|
+
current.scrollbar = value ?? props.scrollbar;
|
|
1757
|
+
current.options = { ...current.options, scrollbar: current.scrollbar };
|
|
1758
|
+
current.board.updateOptions({ scrollbar: current.scrollbar });
|
|
1759
|
+
props.onScrollbarChange?.(value);
|
|
1760
|
+
}
|
|
1761
|
+
function onMenuAction(key, menu2) {
|
|
1762
|
+
const current = instance.current;
|
|
1763
|
+
if (!current || !isTargetValid(menu2)) return;
|
|
1764
|
+
const { board } = current;
|
|
1765
|
+
const { index, layout, viewport } = board.getSnapshot();
|
|
1766
|
+
const keys = dragContextMenuActions;
|
|
1767
|
+
switch (key) {
|
|
1768
|
+
case keys.copyText: {
|
|
1769
|
+
const text = copyText(menu2);
|
|
1770
|
+
if (text?.trim())
|
|
1771
|
+
void copyContextMenuText(text, props.onError, owner.current);
|
|
1772
|
+
return;
|
|
1773
|
+
}
|
|
1774
|
+
case keys.scrollToCard:
|
|
1775
|
+
if (menu2.cardId !== void 0) board.scrollTo({ cardId: menu2.cardId });
|
|
1776
|
+
return;
|
|
1777
|
+
case keys.scrollToStart:
|
|
1778
|
+
case keys.scrollToEnd: {
|
|
1779
|
+
const rect = menu2.containerId === void 0 ? void 0 : index.getContainerRect(menu2.containerId);
|
|
1780
|
+
if (!rect) return;
|
|
1781
|
+
board.scrollTo(
|
|
1782
|
+
key === keys.scrollToStart ? { scrollLeft: rect.x, scrollTop: rect.y } : {
|
|
1783
|
+
scrollLeft: Math.max(
|
|
1784
|
+
rect.x,
|
|
1785
|
+
rect.x + rect.width - viewport.width
|
|
1786
|
+
),
|
|
1787
|
+
scrollTop: Math.max(
|
|
1788
|
+
rect.y,
|
|
1789
|
+
rect.y + rect.height - viewport.height
|
|
1790
|
+
)
|
|
1791
|
+
}
|
|
1792
|
+
);
|
|
1793
|
+
return;
|
|
1794
|
+
}
|
|
1795
|
+
case keys.scrollToHeader: {
|
|
1796
|
+
const region = getHeaderRegions(layout, index).find(
|
|
1797
|
+
(region2) => region2.id === menu2.headerId && region2.kind === menu2.region
|
|
1798
|
+
);
|
|
1799
|
+
if (region)
|
|
1800
|
+
board.scrollTo(
|
|
1801
|
+
region.axis === "x" ? { scrollLeft: region.offset } : { scrollTop: region.offset }
|
|
1802
|
+
);
|
|
1803
|
+
return;
|
|
1804
|
+
}
|
|
1805
|
+
case keys.scrollbarTrack:
|
|
1806
|
+
case keys.scrollbarButton: {
|
|
1807
|
+
const value = {
|
|
1808
|
+
...current.scrollbar,
|
|
1809
|
+
mode: key === keys.scrollbarTrack ? "scrollbar" : "button"
|
|
1810
|
+
};
|
|
1811
|
+
saveScrollbarSettings(
|
|
1812
|
+
props.storageKey,
|
|
1813
|
+
value,
|
|
1814
|
+
owner.current,
|
|
1815
|
+
props.onError
|
|
1816
|
+
);
|
|
1817
|
+
applyScrollbar(value);
|
|
1818
|
+
return;
|
|
1819
|
+
}
|
|
1820
|
+
case keys.scrollbarReset:
|
|
1821
|
+
saveScrollbarSettings(
|
|
1822
|
+
props.storageKey,
|
|
1823
|
+
void 0,
|
|
1824
|
+
owner.current,
|
|
1825
|
+
props.onError
|
|
1826
|
+
);
|
|
1827
|
+
applyScrollbar(void 0);
|
|
1828
|
+
return;
|
|
1829
|
+
case keys.scrollbarSettings:
|
|
1830
|
+
setDialog("settings");
|
|
1831
|
+
return;
|
|
1832
|
+
case keys.scrollbarPosition:
|
|
1833
|
+
setDialog("position");
|
|
1834
|
+
return;
|
|
1835
|
+
default:
|
|
1836
|
+
try {
|
|
1837
|
+
if (props.contextMenu && isEnabledAction(props.contextMenu.getItems?.(menu2) ?? [], key)) {
|
|
1838
|
+
props.contextMenu.onAction?.(key, menu2);
|
|
1839
|
+
}
|
|
1840
|
+
} catch (error) {
|
|
1841
|
+
props.onError?.(error);
|
|
1842
|
+
}
|
|
1843
|
+
}
|
|
1844
|
+
}
|
|
1845
|
+
const active = mounted && props.active !== false;
|
|
1846
|
+
const Dialog = dialog === "settings" ? SettingsDialog : PositionDialog;
|
|
1847
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1848
|
+
/* @__PURE__ */ jsx(
|
|
1849
|
+
"div",
|
|
1850
|
+
{
|
|
1851
|
+
ref: owner,
|
|
1852
|
+
"data-drag-any-host": "",
|
|
1853
|
+
role: "region",
|
|
1854
|
+
"aria-label": props.id,
|
|
1855
|
+
className: props.className,
|
|
1856
|
+
style: {
|
|
1857
|
+
position: "relative",
|
|
1858
|
+
width: "100%",
|
|
1859
|
+
height: props.height ?? 400,
|
|
1860
|
+
overflow: "hidden",
|
|
1861
|
+
...props.style
|
|
1862
|
+
}
|
|
1863
|
+
}
|
|
1864
|
+
),
|
|
1865
|
+
active && request && props.contextMenu !== false && /* @__PURE__ */ jsx(
|
|
1866
|
+
ContextMenuView,
|
|
1867
|
+
{
|
|
1868
|
+
request,
|
|
1869
|
+
items: menu.items,
|
|
1870
|
+
onAction: onMenuAction,
|
|
1871
|
+
onClose: closeMenu,
|
|
1872
|
+
owner: owner.current,
|
|
1873
|
+
returnFocus: owner.current,
|
|
1874
|
+
theme: props.theme,
|
|
1875
|
+
isTargetValid
|
|
1876
|
+
}
|
|
1877
|
+
),
|
|
1878
|
+
active && dialog && /* @__PURE__ */ jsx(
|
|
1879
|
+
Dialog,
|
|
1880
|
+
{
|
|
1881
|
+
value: instance.current?.scrollbar ?? {},
|
|
1882
|
+
storageKey: props.storageKey,
|
|
1883
|
+
owner: owner.current,
|
|
1884
|
+
theme: props.theme,
|
|
1885
|
+
onError: props.onError,
|
|
1886
|
+
onClose: () => setDialog(void 0),
|
|
1887
|
+
onConfirm: (value) => {
|
|
1888
|
+
applyScrollbar(value);
|
|
1889
|
+
setDialog(void 0);
|
|
1890
|
+
}
|
|
1891
|
+
}
|
|
1892
|
+
),
|
|
1893
|
+
active && props.tooltip && /* @__PURE__ */ jsx(
|
|
1894
|
+
Tooltip,
|
|
1895
|
+
{
|
|
1896
|
+
request: props.tooltip,
|
|
1897
|
+
owner: owner.current,
|
|
1898
|
+
theme: props.theme
|
|
1899
|
+
}
|
|
1900
|
+
),
|
|
1901
|
+
active && props.editor && /* @__PURE__ */ jsx(
|
|
1902
|
+
EditorHost,
|
|
1903
|
+
{
|
|
1904
|
+
...props.editor,
|
|
1905
|
+
owner: owner.current,
|
|
1906
|
+
theme: props.theme
|
|
1907
|
+
}
|
|
1908
|
+
)
|
|
1909
|
+
] });
|
|
1910
|
+
}
|
|
1911
|
+
var ModelBoard = forwardRef(Board);
|
|
1912
|
+
function DeclarativeBoard(props, ref) {
|
|
1913
|
+
const { document: document2, children, store, dragLayout, getDragRole, ...board } = props;
|
|
1914
|
+
const stored = useSyncExternalStore(
|
|
1915
|
+
store?.subscribe ?? emptySubscription,
|
|
1916
|
+
store?.getSnapshot ?? emptySnapshot,
|
|
1917
|
+
store?.getSnapshot ?? emptySnapshot
|
|
1918
|
+
);
|
|
1919
|
+
const group = useContext(DragGroupContext);
|
|
1920
|
+
if (Number(document2 !== void 0) + Number(children !== void 0) + Number(store !== void 0) !== 1)
|
|
1921
|
+
throw new DragDocumentError("$", "document\u3001children \u4E0E store \u987B\u9009\u62E9\u5176\u4E00");
|
|
1922
|
+
for (const key of [
|
|
1923
|
+
"model",
|
|
1924
|
+
"layout",
|
|
1925
|
+
"render",
|
|
1926
|
+
"renderCard",
|
|
1927
|
+
"renderVersion"
|
|
1928
|
+
])
|
|
1929
|
+
if (board[key] !== void 0)
|
|
1930
|
+
throw new DragDocumentError("$." + key, "\u4E0D\u80FD\u4E0E\u7ED3\u6784\u58F0\u660E\u540C\u65F6\u4F20\u5165");
|
|
1931
|
+
const prepared = useMemo(() => {
|
|
1932
|
+
try {
|
|
1933
|
+
let source = stored?.document ?? document2;
|
|
1934
|
+
if (dragLayout !== void 0 || getDragRole !== void 0) {
|
|
1935
|
+
if (store !== void 0 || document2 !== void 0 || children === void 0 || dragLayout !== "queue" && dragLayout !== "lanes" || typeof getDragRole !== "function")
|
|
1936
|
+
throw new DragDocumentError(
|
|
1937
|
+
"$",
|
|
1938
|
+
"\u901A\u7528 JSX \u5165\u53E3\u987B\u540C\u65F6\u63D0\u4F9B children\u3001dragLayout \u548C getDragRole"
|
|
1939
|
+
);
|
|
1940
|
+
source = compileDragUIStructure(children, { dragLayout, getDragRole });
|
|
1941
|
+
}
|
|
1942
|
+
return {
|
|
1943
|
+
indexed: indexDragDocument(
|
|
1944
|
+
source ?? compileDragStructure(children),
|
|
1945
|
+
0,
|
|
1946
|
+
(value) => value
|
|
1947
|
+
)
|
|
1948
|
+
};
|
|
1949
|
+
} catch (error) {
|
|
1950
|
+
return { error };
|
|
1951
|
+
}
|
|
1952
|
+
}, [stored, store, document2, children, dragLayout, getDragRole]);
|
|
1953
|
+
const [committed, setCommitted] = useState({
|
|
1954
|
+
indexed: prepared.indexed,
|
|
1955
|
+
revision: stored?.revision ?? 0
|
|
1956
|
+
});
|
|
1957
|
+
const indexed = prepared.indexed ?? committed.indexed;
|
|
1958
|
+
if (prepared.indexed && committed.indexed !== prepared.indexed)
|
|
1959
|
+
setCommitted({
|
|
1960
|
+
indexed: prepared.indexed,
|
|
1961
|
+
revision: committed.revision + 1
|
|
1962
|
+
});
|
|
1963
|
+
const onError = useRef(board.onError);
|
|
1964
|
+
useLayoutEffect(() => {
|
|
1965
|
+
onError.current = board.onError;
|
|
1966
|
+
}, [board.onError]);
|
|
1967
|
+
useLayoutEffect(() => {
|
|
1968
|
+
if ("error" in prepared) onError.current?.(prepared.error);
|
|
1969
|
+
}, [prepared]);
|
|
1970
|
+
const projection = useMemo(
|
|
1971
|
+
() => indexed && {
|
|
1972
|
+
model: { ...indexed.model, revision: committed.revision },
|
|
1973
|
+
layout: indexed.layout,
|
|
1974
|
+
render: indexed.render
|
|
1975
|
+
},
|
|
1976
|
+
[indexed, committed.revision]
|
|
1977
|
+
);
|
|
1978
|
+
useLayoutEffect(
|
|
1979
|
+
() => projection && group?.stageProjection?.(props.id, projection),
|
|
1980
|
+
[group, props.id, projection]
|
|
1981
|
+
);
|
|
1982
|
+
const readProjection = useCallback(
|
|
1983
|
+
() => group?.getProjection?.(props.id),
|
|
1984
|
+
[group, props.id]
|
|
1985
|
+
);
|
|
1986
|
+
const published = useSyncExternalStore(
|
|
1987
|
+
group?.subscribe ?? emptySubscription,
|
|
1988
|
+
readProjection,
|
|
1989
|
+
emptySnapshot
|
|
1990
|
+
);
|
|
1991
|
+
if (!projection) throw prepared.error;
|
|
1992
|
+
if (group) {
|
|
1993
|
+
if (!published) return null;
|
|
1994
|
+
const {
|
|
1995
|
+
onMoveRequest: _move,
|
|
1996
|
+
acknowledgedTransactionId: _ack,
|
|
1997
|
+
...member
|
|
1998
|
+
} = board;
|
|
1999
|
+
return /* @__PURE__ */ jsx(
|
|
2000
|
+
ModelBoard,
|
|
2001
|
+
{
|
|
2002
|
+
...member,
|
|
2003
|
+
ref,
|
|
2004
|
+
layout: published.layout,
|
|
2005
|
+
render: published.render,
|
|
2006
|
+
canDrag: group.allowsMove ? board.canDrag : denyDrag
|
|
2007
|
+
}
|
|
2008
|
+
);
|
|
2009
|
+
}
|
|
2010
|
+
return /* @__PURE__ */ jsx(
|
|
2011
|
+
ModelBoard,
|
|
2012
|
+
{
|
|
2013
|
+
...board,
|
|
2014
|
+
canDrag: board.onMoveRequest ? board.canDrag : denyDrag,
|
|
2015
|
+
ref,
|
|
2016
|
+
model: projection.model,
|
|
2017
|
+
layout: projection.layout,
|
|
2018
|
+
render: projection.render
|
|
2019
|
+
}
|
|
2020
|
+
);
|
|
2021
|
+
}
|
|
2022
|
+
var emptySubscription = () => () => {
|
|
2023
|
+
};
|
|
2024
|
+
var emptySnapshot = () => void 0;
|
|
2025
|
+
var denyDrag = () => false;
|
|
2026
|
+
var StructureBoard = forwardRef(DeclarativeBoard);
|
|
2027
|
+
var ReactDragAny = StructureBoard;
|
|
2028
|
+
function Group(props, ref) {
|
|
2029
|
+
const committed = useCommitted(props);
|
|
2030
|
+
if (props.state !== void 0)
|
|
2031
|
+
throw new TypeError("\u753B\u5E03\u7EC4\u901A\u8FC7\u6210\u5458\u58F0\u660E\u63A5\u6536\u6570\u636E");
|
|
2032
|
+
const current = useRef();
|
|
2033
|
+
const listeners = useRef(/* @__PURE__ */ new Set());
|
|
2034
|
+
const projected = useRef(/* @__PURE__ */ new Map());
|
|
2035
|
+
const published = useRef(/* @__PURE__ */ new Map());
|
|
2036
|
+
const scheduled = useRef(false);
|
|
2037
|
+
const previousAck = useRef();
|
|
2038
|
+
const allowsMove = props.onMoveRequest !== void 0;
|
|
2039
|
+
const manager = useMemo(
|
|
2040
|
+
() => ({
|
|
2041
|
+
allowsMove,
|
|
2042
|
+
getProjection: (id) => published.current.get(id),
|
|
2043
|
+
stageProjection(id, projection) {
|
|
2044
|
+
projected.current.set(id, projection);
|
|
2045
|
+
queuePublish();
|
|
2046
|
+
return () => {
|
|
2047
|
+
if (projected.current.get(id) === projection) {
|
|
2048
|
+
projected.current.delete(id);
|
|
2049
|
+
queuePublish();
|
|
2050
|
+
}
|
|
2051
|
+
};
|
|
2052
|
+
},
|
|
2053
|
+
ensureGroup() {
|
|
2054
|
+
if (current.current) return current.current;
|
|
2055
|
+
const group = new DragAnyGroup({
|
|
2056
|
+
onMoveRequest: (proposal) => committed.current.onMoveRequest?.(proposal),
|
|
2057
|
+
onError: (error) => committed.current.onError?.(error)
|
|
2058
|
+
});
|
|
2059
|
+
current.current = group;
|
|
2060
|
+
return group;
|
|
2061
|
+
},
|
|
2062
|
+
getModel: (id) => published.current.get(id)?.model,
|
|
2063
|
+
subscribe(listener) {
|
|
2064
|
+
listeners.current.add(listener);
|
|
2065
|
+
return () => {
|
|
2066
|
+
listeners.current.delete(listener);
|
|
2067
|
+
};
|
|
2068
|
+
}
|
|
2069
|
+
}),
|
|
2070
|
+
[committed, allowsMove]
|
|
2071
|
+
);
|
|
2072
|
+
function queuePublish() {
|
|
2073
|
+
if (scheduled.current) return;
|
|
2074
|
+
scheduled.current = true;
|
|
2075
|
+
queueMicrotask(() => {
|
|
2076
|
+
scheduled.current = false;
|
|
2077
|
+
const group = current.current;
|
|
2078
|
+
if (!group) return;
|
|
2079
|
+
const next = new Map(projected.current);
|
|
2080
|
+
const ack = committed.current.acknowledgedTransactionId;
|
|
2081
|
+
const transaction = ack !== previousAck.current ? ack : void 0;
|
|
2082
|
+
if (!dragAnyGroupProjection.replaceProjected(group, next, transaction))
|
|
2083
|
+
return;
|
|
2084
|
+
previousAck.current = ack;
|
|
2085
|
+
published.current = next;
|
|
2086
|
+
for (const listener of listeners.current) listener();
|
|
2087
|
+
});
|
|
2088
|
+
}
|
|
2089
|
+
useLayoutEffect(() => {
|
|
2090
|
+
manager.ensureGroup();
|
|
2091
|
+
return () => {
|
|
2092
|
+
const group = current.current;
|
|
2093
|
+
current.current = void 0;
|
|
2094
|
+
group?.destroy();
|
|
2095
|
+
};
|
|
2096
|
+
}, [manager]);
|
|
2097
|
+
useLayoutEffect(queuePublish, [props.acknowledgedTransactionId, manager]);
|
|
2098
|
+
useImperativeHandle(
|
|
2099
|
+
ref,
|
|
2100
|
+
() => ({
|
|
2101
|
+
cancelDrag: (reason) => current.current?.cancelDrag(reason),
|
|
2102
|
+
rejectMove: (transactionId, reason) => current.current?.rejectMove(transactionId, reason) ?? false
|
|
2103
|
+
}),
|
|
2104
|
+
[]
|
|
2105
|
+
);
|
|
2106
|
+
return /* @__PURE__ */ jsx(
|
|
2107
|
+
DragGroupContext.Provider,
|
|
2108
|
+
{
|
|
2109
|
+
value: manager,
|
|
2110
|
+
children: props.children
|
|
2111
|
+
}
|
|
2112
|
+
);
|
|
2113
|
+
}
|
|
2114
|
+
var ReactDragAnyGroup = forwardRef(Group);
|
|
2115
|
+
|
|
2116
|
+
export { Card, ContentCompileError, Flow, GridSlot, Lane, Lanes, Queue, ReactDragAny, ReactDragAnyGroup, SparseGrid, compileJSX, createContentBindings };
|