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