@jbpark/live-editor 4.5.0 → 4.6.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/README.ko.md +4 -1
- package/README.md +5 -1
- package/dist/{boundary-DnjGgsK6.js → boundary-BLB80tyw.js} +2 -2
- package/dist/boundary-BLB80tyw.js.map +1 -0
- package/dist/cache-B0-XcIxJ.js.map +1 -1
- package/dist/{compile-DDfk5P25.js → compile-Dxas-D05.js} +3 -3
- package/dist/compile-Dxas-D05.js.map +1 -0
- package/dist/{constants-h1JAgOeW.js → constants-DU17Tdwo.js} +3 -3
- package/dist/constants-DU17Tdwo.js.map +1 -0
- package/dist/{context-DsEXJl4h.js → context-B8MzP7_p.js} +3 -3
- package/dist/context-B8MzP7_p.js.map +1 -0
- package/dist/{core-CRsAGpei.js → core-Bgfek364.js} +2 -2
- package/dist/core-Bgfek364.js.map +1 -0
- package/dist/{detect-typescript-CCj9ALXc.js → detect-typescript-Dr_oLniM.js} +2 -2
- package/dist/detect-typescript-Dr_oLniM.js.map +1 -0
- package/dist/dnd/index.d.ts +1 -1
- package/dist/dnd/index.js +1 -1
- package/dist/{dnd-DGNp20Nk.js → dnd-UoJILA75.js} +431 -408
- package/dist/dnd-UoJILA75.js.map +1 -0
- package/dist/{document-DGHTfrda.js → document-CGbe6bSV.js} +2 -2
- package/dist/{document-DGHTfrda.js.map → document-CGbe6bSV.js.map} +1 -1
- package/dist/editor/index.js +2 -2
- package/dist/{editor-DQ8Q--qR.js → editor-CMElfHer.js} +2 -2
- package/dist/editor-CMElfHer.js.map +1 -0
- package/dist/editor-caches-ClMvdcQF.js.map +1 -1
- package/dist/error/index.d.ts +1 -1
- package/dist/error/index.js +2 -2
- package/dist/{error-DwqwjJ2C.js → error-CN_GCnXB.js} +3 -3
- package/dist/{error-DwqwjJ2C.js.map → error-CN_GCnXB.js.map} +1 -1
- package/dist/{index-P9Aifaui.d.ts → index-C69Lv-jR.d.ts} +71 -69
- package/dist/{index-vtyggWy0.d.ts → index-CRwEhJ7w.d.ts} +2 -2
- package/dist/{index-CHknA6k1.d.ts → index-DKYUxi-E.d.ts} +10 -4
- package/dist/{index-WQgFy510.d.ts → index-DrWtSKXu.d.ts} +2 -2
- package/dist/index.d.ts +4 -4
- package/dist/index.js +6 -6
- package/dist/{items-DdrwGxJw.js → items-B6OXxcLG.js} +178 -259
- package/dist/items-B6OXxcLG.js.map +1 -0
- package/dist/{messages-CzUPVnzH.js → messages-CSrMI4Rm.js} +2 -1
- package/dist/messages-CSrMI4Rm.js.map +1 -0
- package/dist/{messages-Cp3g1mn1.d.ts → messages-IBPs4TkZ.d.ts} +2 -1
- package/dist/preview/index.js +2 -2
- package/dist/{preview-BKFgq_5u.js → preview-CtyG5UbH.js} +4 -4
- package/dist/{preview-BKFgq_5u.js.map → preview-CtyG5UbH.js.map} +1 -1
- package/dist/provider/index.d.ts +2 -2
- package/dist/provider/index.js +2 -2
- package/dist/{sections-BRH3KHYc.js → sections-BYWOBISr.js} +3 -3
- package/dist/sections-BYWOBISr.js.map +1 -0
- package/dist/states-Ci1AvoQ9.js.map +1 -1
- package/dist/{use-dynamic-tailwind-T9r9ExbR.js → use-dynamic-tailwind-BP1toJkW.js} +59 -39
- package/dist/use-dynamic-tailwind-BP1toJkW.js.map +1 -0
- package/dist/utils/ast/index.d.ts +1 -1
- package/dist/utils/ast/index.js +86 -2
- package/dist/utils/ast/index.js.map +1 -1
- package/dist/utils/index.js +4 -4
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/tailwind/index.js.map +1 -1
- package/dist/validate-iLo8IONY.js.map +1 -1
- package/package.json +1 -1
- package/dist/boundary-DnjGgsK6.js.map +0 -1
- package/dist/compile-DDfk5P25.js.map +0 -1
- package/dist/constants-h1JAgOeW.js.map +0 -1
- package/dist/context-DsEXJl4h.js.map +0 -1
- package/dist/core-CRsAGpei.js.map +0 -1
- package/dist/detect-typescript-CCj9ALXc.js.map +0 -1
- package/dist/dnd-DGNp20Nk.js.map +0 -1
- package/dist/editor-DQ8Q--qR.js.map +0 -1
- package/dist/items-DdrwGxJw.js.map +0 -1
- package/dist/messages-CzUPVnzH.js.map +0 -1
- package/dist/sections-BRH3KHYc.js.map +0 -1
- package/dist/use-dynamic-tailwind-T9r9ExbR.js.map +0 -1
|
@@ -1,38 +1,48 @@
|
|
|
1
|
-
import { S as require_lib, c as inspectDocument, h as replaceIds, m as fillIdsFrom, n as createSectionPreviewCache, r as fillSectionIds, w as __toESM, x as nanoid } from "./document-
|
|
2
|
-
import { c as RESERVED_BINDING_PROPERTIES, o as
|
|
1
|
+
import { S as require_lib, c as inspectDocument, h as replaceIds, m as fillIdsFrom, n as createSectionPreviewCache, r as fillSectionIds, w as __toESM, x as nanoid } from "./document-CGbe6bSV.js";
|
|
2
|
+
import { c as RESERVED_BINDING_PROPERTIES, o as PALETTE_SECTIONS, r as DATA_ATTR, t as BINDING_PROP } from "./constants-DU17Tdwo.js";
|
|
3
3
|
import { n as validateBindingValue } from "./validate-iLo8IONY.js";
|
|
4
|
-
import { i as useLiveMessages } from "./messages-
|
|
4
|
+
import { i as useLiveMessages } from "./messages-CSrMI4Rm.js";
|
|
5
5
|
import { i as usePreview } from "./states-Ci1AvoQ9.js";
|
|
6
|
-
import { A as extractNodeValue,
|
|
6
|
+
import { A as extractNodeValue, C as getStructuredValue, D as readNodeBindings, M as parseArrayExpression, N as parseValue, b as getCurrentValue, c as updateArrayItemValue, f as updateAll, g as moveSelectedIndices, h as getChildrenSignatures, i as moveArrayItems, j as extractObjectProperties, k as canLosslesslyEvaluateSource, l as canStructurallyEditArray, n as duplicateArrayItems, o as removeArrayItems, r as moveArrayItem, s as updateArrayItemProperty, t as appendArrayItem, v as extract, y as findEditableChildren } from "./items-B6OXxcLG.js";
|
|
7
7
|
import { t as cn } from "./cn-CAnad2vL.js";
|
|
8
|
-
import { o as preloadScripts } from "./compile-
|
|
9
|
-
import { a as
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import { Children, createContext, memo, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
8
|
+
import { o as preloadScripts } from "./compile-Dxas-D05.js";
|
|
9
|
+
import { a as useStableModules, i as Frame, n as useCompiledModule, t as useDynamicTailwind } from "./use-dynamic-tailwind-BP1toJkW.js";
|
|
10
|
+
import { i as generateSection, o as replaceSections, r as extractSections } from "./sections-BYWOBISr.js";
|
|
11
|
+
import { n as Error$1, t as ErrorBoundary } from "./boundary-BLB80tyw.js";
|
|
12
|
+
import { t as Core } from "./core-Bgfek364.js";
|
|
13
|
+
import { Children, createContext, memo, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
14
14
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
15
15
|
import { DndContext, DragOverlay, KeyboardSensor, MouseSensor, PointerSensor, TouchSensor, closestCenter, useDndContext, useDraggable, useDroppable, useSensor, useSensors } from "@dnd-kit/core";
|
|
16
16
|
import { restrictToParentElement, restrictToVerticalAxis } from "@dnd-kit/modifiers";
|
|
17
17
|
import { SortableContext, arrayMove, sortableKeyboardCoordinates, useSortable, verticalListSortingStrategy } from "@dnd-kit/sortable";
|
|
18
18
|
import { Button, Card, Checkbox, ColorPicker, DatePicker, Drawer, Input, RichTextEditor, Select, Space, Splitter, Toast, Typography } from "@jbpark/ui-kit";
|
|
19
19
|
import { useDebounce, useMultiSelect, useResponsiveSize } from "@jbpark/use-hooks";
|
|
20
|
-
import { createPortal } from "react-dom";
|
|
21
|
-
import { ArrowDown, ArrowUp, ChevronDown, ChevronRight, ChevronUp, Copy, Crosshair, GripVertical, LayoutGrid, Plus, Trash, X } from "lucide-react";
|
|
22
20
|
import { CSS as CSS$1 } from "@dnd-kit/utilities";
|
|
23
|
-
|
|
21
|
+
import { ArrowDown, ArrowUp, ChevronDown, ChevronRight, ChevronUp, Copy, Crosshair, GripVertical, LayoutGrid, Plus, Trash, X } from "lucide-react";
|
|
22
|
+
//#region src/components/dnd/palette/palette-drag.ts
|
|
24
23
|
var import_lib = /* @__PURE__ */ __toESM(require_lib(), 1);
|
|
24
|
+
const PALETTE_SECTION = "palette-section";
|
|
25
|
+
const paletteDragData = (section) => ({
|
|
26
|
+
type: PALETTE_SECTION,
|
|
27
|
+
section
|
|
28
|
+
});
|
|
29
|
+
const paletteSectionOf = (data) => {
|
|
30
|
+
const current = data?.current;
|
|
31
|
+
return current?.type === PALETTE_SECTION ? current.section : void 0;
|
|
32
|
+
};
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region src/components/dnd/canvas/droppable.tsx
|
|
25
35
|
const Droppable = ({ children, className }) => {
|
|
26
36
|
const { setNodeRef, isOver, active } = useDroppable({ id: "sortable-area" });
|
|
27
37
|
const { setNodeRef: setBottomRef, isOver: isBottomOver } = useDroppable({ id: "sortable-area-bottom" });
|
|
28
|
-
const
|
|
29
|
-
const shouldHighlight = isOver &&
|
|
30
|
-
const shouldHighlightBottom = isBottomOver &&
|
|
38
|
+
const isPaletteSectionDragging = !!paletteSectionOf(active?.data);
|
|
39
|
+
const shouldHighlight = isOver && isPaletteSectionDragging;
|
|
40
|
+
const shouldHighlightBottom = isBottomOver && isPaletteSectionDragging;
|
|
31
41
|
const messages = useLiveMessages();
|
|
32
42
|
return /* @__PURE__ */ jsxs("div", {
|
|
33
43
|
ref: setNodeRef,
|
|
34
44
|
className: cn("min-h-full", "border-2 border-dashed p-1", shouldHighlight ? "border-blue-300 bg-blue-50" : "border-gray-200", className),
|
|
35
|
-
children: [children,
|
|
45
|
+
children: [children, isPaletteSectionDragging && /* @__PURE__ */ jsx("div", {
|
|
36
46
|
ref: setBottomRef,
|
|
37
47
|
className: cn("mt-2 min-h-24", "rounded-lg border-2 border-dashed", "transition-all duration-200", "flex items-center justify-center", shouldHighlightBottom ? "border-blue-400 bg-blue-100" : "border-gray-300 bg-gray-50"),
|
|
38
48
|
children: /* @__PURE__ */ jsx(Typography.Text, {
|
|
@@ -43,6 +53,308 @@ const Droppable = ({ children, className }) => {
|
|
|
43
53
|
});
|
|
44
54
|
};
|
|
45
55
|
//#endregion
|
|
56
|
+
//#region src/components/dnd/canvas/inspector-highlight.tsx
|
|
57
|
+
const InspectorHighlight = ({ rect }) => {
|
|
58
|
+
const ref = useRef(null);
|
|
59
|
+
useLayoutEffect(() => {
|
|
60
|
+
const box = ref.current;
|
|
61
|
+
const container = box?.closest("[data-frame-container]");
|
|
62
|
+
if (!box || !rect || !container) return;
|
|
63
|
+
const outer = container.getBoundingClientRect();
|
|
64
|
+
box.style.left = `${rect.left - outer.left - container.clientLeft + container.scrollLeft}px`;
|
|
65
|
+
box.style.top = `${rect.top - outer.top - container.clientTop + container.scrollTop}px`;
|
|
66
|
+
box.style.width = `${rect.width}px`;
|
|
67
|
+
box.style.height = `${rect.height}px`;
|
|
68
|
+
}, [rect]);
|
|
69
|
+
return rect ? /* @__PURE__ */ jsx("div", {
|
|
70
|
+
ref,
|
|
71
|
+
"aria-hidden": true,
|
|
72
|
+
"data-dnd-inspector-highlight": true,
|
|
73
|
+
style: {
|
|
74
|
+
position: "absolute",
|
|
75
|
+
pointerEvents: "none",
|
|
76
|
+
outline: "2px solid #3b82f6",
|
|
77
|
+
outlineOffset: -1,
|
|
78
|
+
background: "rgba(59, 130, 246, 0.12)",
|
|
79
|
+
zIndex: 65
|
|
80
|
+
}
|
|
81
|
+
}) : null;
|
|
82
|
+
};
|
|
83
|
+
//#endregion
|
|
84
|
+
//#region src/components/dnd/palette/draggable.tsx
|
|
85
|
+
const DraggableItem = ({ item, children }) => {
|
|
86
|
+
const { attributes, listeners, setNodeRef, isDragging } = useDraggable({
|
|
87
|
+
id: item.id,
|
|
88
|
+
data: paletteDragData(item)
|
|
89
|
+
});
|
|
90
|
+
return children({
|
|
91
|
+
ref: setNodeRef,
|
|
92
|
+
dragProps: {
|
|
93
|
+
...listeners,
|
|
94
|
+
...attributes
|
|
95
|
+
},
|
|
96
|
+
isDragging
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
const DefaultDraggableItem = ({ item, onAdd, tapToAdd = false }) => /* @__PURE__ */ jsx(DraggableItem, {
|
|
100
|
+
item,
|
|
101
|
+
children: ({ ref, dragProps, isDragging }) => /* @__PURE__ */ jsx(Card, {
|
|
102
|
+
ref,
|
|
103
|
+
style: { opacity: isDragging ? .5 : 1 },
|
|
104
|
+
...dragProps,
|
|
105
|
+
className: cn("cursor-grab", "outline-none focus-visible:ring-2 focus-visible:ring-blue-500", "hover:border-blue-300 hover:shadow-md", isDragging && "opacity-50"),
|
|
106
|
+
onClick: tapToAdd && onAdd ? () => onAdd(item) : void 0,
|
|
107
|
+
onDoubleClick: onAdd ? () => onAdd(item) : void 0,
|
|
108
|
+
onKeyDown: (event) => {
|
|
109
|
+
dragProps.onKeyDown?.(event);
|
|
110
|
+
if (onAdd && event.key === "Enter" && event.target === event.currentTarget && !event.defaultPrevented) {
|
|
111
|
+
event.preventDefault();
|
|
112
|
+
onAdd(item);
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
children: item.name
|
|
116
|
+
})
|
|
117
|
+
});
|
|
118
|
+
//#endregion
|
|
119
|
+
//#region src/components/dnd/canvas/section-fallback-context.ts
|
|
120
|
+
const SectionFallbackContext = createContext(void 0);
|
|
121
|
+
//#endregion
|
|
122
|
+
//#region src/components/dnd/canvas/section-fallback.tsx
|
|
123
|
+
const ConsumerFallback = ({ render, args, builtin }) => {
|
|
124
|
+
const node = render(args);
|
|
125
|
+
return node === void 0 ? builtin : /* @__PURE__ */ jsx(Fragment, { children: node });
|
|
126
|
+
};
|
|
127
|
+
const SectionFallback = ({ args, builtin }) => {
|
|
128
|
+
const render = useContext(SectionFallbackContext);
|
|
129
|
+
if (!render) return builtin;
|
|
130
|
+
return /* @__PURE__ */ jsx(ErrorBoundary, {
|
|
131
|
+
fallback: () => builtin,
|
|
132
|
+
children: /* @__PURE__ */ jsx(ConsumerFallback, {
|
|
133
|
+
render,
|
|
134
|
+
args,
|
|
135
|
+
builtin
|
|
136
|
+
})
|
|
137
|
+
});
|
|
138
|
+
};
|
|
139
|
+
//#endregion
|
|
140
|
+
//#region src/components/dnd/canvas/renderer.tsx
|
|
141
|
+
const Renderer = ({ preview, sectionId = "", sectionName = "", sectionCode = preview, forceFallback = false, headers, modules, frame, dynamicTailwind = false, provider }) => {
|
|
142
|
+
const module = useCompiledModule(forceFallback ? "" : preview, modules);
|
|
143
|
+
const section = {
|
|
144
|
+
id: sectionId,
|
|
145
|
+
name: sectionName,
|
|
146
|
+
code: sectionCode
|
|
147
|
+
};
|
|
148
|
+
const messages = useLiveMessages();
|
|
149
|
+
const { ref: wrapperRef, css: dynamicCSS } = useDynamicTailwind(preview, dynamicTailwind && !forceFallback);
|
|
150
|
+
const renderProvider = (component) => {
|
|
151
|
+
return provider ? provider(component) : component;
|
|
152
|
+
};
|
|
153
|
+
if (forceFallback) return /* @__PURE__ */ jsx(SectionFallback, {
|
|
154
|
+
args: {
|
|
155
|
+
section,
|
|
156
|
+
reason: "forced"
|
|
157
|
+
},
|
|
158
|
+
builtin: /* @__PURE__ */ jsx(Error$1, {
|
|
159
|
+
message: messages.errors.sectionNotRendered,
|
|
160
|
+
title: messages.errors.sectionUnavailable
|
|
161
|
+
})
|
|
162
|
+
});
|
|
163
|
+
if (module?.error) return /* @__PURE__ */ jsx(SectionFallback, {
|
|
164
|
+
args: {
|
|
165
|
+
section,
|
|
166
|
+
reason: "compile",
|
|
167
|
+
message: module.error
|
|
168
|
+
},
|
|
169
|
+
builtin: /* @__PURE__ */ jsx(Error$1, {
|
|
170
|
+
message: module.error,
|
|
171
|
+
title: messages.errors.compile
|
|
172
|
+
})
|
|
173
|
+
});
|
|
174
|
+
const Component = module?.exports?.default;
|
|
175
|
+
if (!Component) return null;
|
|
176
|
+
return /* @__PURE__ */ jsx(Frame, {
|
|
177
|
+
...frame,
|
|
178
|
+
autoHeight: true,
|
|
179
|
+
children: (container) => /* @__PURE__ */ jsx("div", {
|
|
180
|
+
ref: wrapperRef,
|
|
181
|
+
className: "w-full overflow-x-hidden",
|
|
182
|
+
"data-editor-mode": true,
|
|
183
|
+
children: /* @__PURE__ */ jsx(ErrorBoundary, {
|
|
184
|
+
resetKeys: [preview],
|
|
185
|
+
fallback: (message, reset) => /* @__PURE__ */ jsx(SectionFallback, {
|
|
186
|
+
args: {
|
|
187
|
+
section,
|
|
188
|
+
reason: "runtime",
|
|
189
|
+
message
|
|
190
|
+
},
|
|
191
|
+
builtin: /* @__PURE__ */ jsx(Error$1, {
|
|
192
|
+
message,
|
|
193
|
+
onReset: reset,
|
|
194
|
+
title: messages.errors.rendering
|
|
195
|
+
})
|
|
196
|
+
}),
|
|
197
|
+
children: renderProvider(/* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Component, {
|
|
198
|
+
headers,
|
|
199
|
+
container
|
|
200
|
+
}), dynamicTailwind && dynamicCSS && /* @__PURE__ */ jsx("style", { children: dynamicCSS })] }))
|
|
201
|
+
})
|
|
202
|
+
})
|
|
203
|
+
});
|
|
204
|
+
};
|
|
205
|
+
const sameValue = (a, b) => {
|
|
206
|
+
if (Object.is(a, b)) return true;
|
|
207
|
+
if (Array.isArray(a) && Array.isArray(b)) return a.length === b.length && a.every((item, i) => Object.is(item, b[i]));
|
|
208
|
+
if (a && b && typeof a === "object" && typeof b === "object" && Object.getPrototypeOf(a) === Object.prototype && Object.getPrototypeOf(b) === Object.prototype) {
|
|
209
|
+
const aKeys = Object.keys(a);
|
|
210
|
+
return aKeys.length === Object.keys(b).length && aKeys.every((key) => Object.is(a[key], b[key]));
|
|
211
|
+
}
|
|
212
|
+
return false;
|
|
213
|
+
};
|
|
214
|
+
const sameFrame = (a, b) => {
|
|
215
|
+
if (a === b) return true;
|
|
216
|
+
if (!a || !b) return false;
|
|
217
|
+
return [.../* @__PURE__ */ new Set([...Object.keys(a), ...Object.keys(b)])].every((key) => sameValue(a[key], b[key]));
|
|
218
|
+
};
|
|
219
|
+
const arePropsEqual = (prev, next) => {
|
|
220
|
+
return [.../* @__PURE__ */ new Set([...Object.keys(prev), ...Object.keys(next)])].every((key) => key === "frame" ? sameFrame(prev.frame, next.frame) : Object.is(prev[key], next[key]));
|
|
221
|
+
};
|
|
222
|
+
var renderer_default = memo(Renderer, arePropsEqual);
|
|
223
|
+
//#endregion
|
|
224
|
+
//#region src/components/dnd/canvas/sortable.tsx
|
|
225
|
+
const NAVIGATION_KEYS = {
|
|
226
|
+
ArrowUp: "previous",
|
|
227
|
+
ArrowDown: "next",
|
|
228
|
+
Home: "first",
|
|
229
|
+
End: "last"
|
|
230
|
+
};
|
|
231
|
+
const Sortable = ({ id, children, selected, onClick, onDelete: _onDelete, onCopy: _onCopy, onMoveUp, onMoveDown, canMoveUp = false, canMoveDown = false, nodeRef, onNavigate, onDeleteKey, inspecting = false, onInspectMove, onInspectPick, onInspectLeave }) => {
|
|
232
|
+
const { attributes, listeners, setNodeRef, setActivatorNodeRef, transform, transition, isDragging, isOver, active } = useSortable({
|
|
233
|
+
id,
|
|
234
|
+
disabled: inspecting
|
|
235
|
+
});
|
|
236
|
+
const messages = useLiveMessages();
|
|
237
|
+
const style = {
|
|
238
|
+
transform: CSS$1.Transform.toString(transform),
|
|
239
|
+
transition,
|
|
240
|
+
opacity: isDragging ? .5 : 1,
|
|
241
|
+
cursor: inspecting ? "crosshair" : "grab"
|
|
242
|
+
};
|
|
243
|
+
const isPaletteSectionOver = isOver && !!paletteSectionOf(active?.data);
|
|
244
|
+
const onKeyDown = (e) => {
|
|
245
|
+
listeners?.onKeyDown?.(e);
|
|
246
|
+
if (e.target !== e.currentTarget || active || e.defaultPrevented) return;
|
|
247
|
+
if (e.key === "Enter") {
|
|
248
|
+
e.preventDefault();
|
|
249
|
+
onClick?.();
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
const to = NAVIGATION_KEYS[e.key];
|
|
253
|
+
if (to && onNavigate) {
|
|
254
|
+
e.preventDefault();
|
|
255
|
+
onNavigate(to);
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
if ((e.key === "Delete" || e.key === "Backspace") && onDeleteKey) {
|
|
259
|
+
e.preventDefault();
|
|
260
|
+
onDeleteKey();
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
const setRefs = (node) => {
|
|
264
|
+
setNodeRef(node);
|
|
265
|
+
setActivatorNodeRef(node);
|
|
266
|
+
nodeRef?.(node);
|
|
267
|
+
};
|
|
268
|
+
const onDelete = (e) => {
|
|
269
|
+
e.stopPropagation();
|
|
270
|
+
_onDelete?.(id);
|
|
271
|
+
};
|
|
272
|
+
const onCopy = (e) => {
|
|
273
|
+
e.stopPropagation();
|
|
274
|
+
_onCopy?.(id);
|
|
275
|
+
};
|
|
276
|
+
const press = (action) => (e) => {
|
|
277
|
+
e.stopPropagation();
|
|
278
|
+
action?.();
|
|
279
|
+
};
|
|
280
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
281
|
+
ref: setRefs,
|
|
282
|
+
style,
|
|
283
|
+
...attributes,
|
|
284
|
+
...listeners,
|
|
285
|
+
onKeyDown,
|
|
286
|
+
onClick,
|
|
287
|
+
className: cn("relative", selected && "z-10 outline-2 outline-offset-2 outline-blue-500", isPaletteSectionOver && "border-t-4 border-t-green-500"),
|
|
288
|
+
children: [
|
|
289
|
+
/* @__PURE__ */ jsx("div", {
|
|
290
|
+
className: cn("absolute inset-0 z-50"),
|
|
291
|
+
onPointerMove: inspecting ? (e) => onInspectMove?.(e.currentTarget.parentElement, e.currentTarget, e.clientX, e.clientY) : void 0,
|
|
292
|
+
onPointerLeave: inspecting ? onInspectLeave : void 0,
|
|
293
|
+
onClick: inspecting ? (e) => {
|
|
294
|
+
e.stopPropagation();
|
|
295
|
+
onInspectPick?.(e.currentTarget.parentElement, e.currentTarget, e.clientX, e.clientY);
|
|
296
|
+
} : void 0
|
|
297
|
+
}),
|
|
298
|
+
children,
|
|
299
|
+
selected && /* @__PURE__ */ jsxs(Space, {
|
|
300
|
+
className: cn("absolute top-1 right-1 z-60"),
|
|
301
|
+
children: [
|
|
302
|
+
onMoveUp && /* @__PURE__ */ jsx(Button, {
|
|
303
|
+
icon: /* @__PURE__ */ jsx(ChevronUp, {}),
|
|
304
|
+
disabled: !canMoveUp,
|
|
305
|
+
onClick: press(onMoveUp),
|
|
306
|
+
"aria-label": messages.section.moveUp
|
|
307
|
+
}),
|
|
308
|
+
onMoveDown && /* @__PURE__ */ jsx(Button, {
|
|
309
|
+
icon: /* @__PURE__ */ jsx(ChevronDown, {}),
|
|
310
|
+
disabled: !canMoveDown,
|
|
311
|
+
onClick: press(onMoveDown),
|
|
312
|
+
"aria-label": messages.section.moveDown
|
|
313
|
+
}),
|
|
314
|
+
/* @__PURE__ */ jsx(Button, {
|
|
315
|
+
icon: /* @__PURE__ */ jsx(Copy, {}),
|
|
316
|
+
onClick: onCopy,
|
|
317
|
+
"aria-label": messages.section.duplicate
|
|
318
|
+
}),
|
|
319
|
+
/* @__PURE__ */ jsx(Button, {
|
|
320
|
+
danger: true,
|
|
321
|
+
icon: /* @__PURE__ */ jsx(Trash, {}),
|
|
322
|
+
onClick: onDelete,
|
|
323
|
+
"aria-label": messages.section.delete
|
|
324
|
+
})
|
|
325
|
+
]
|
|
326
|
+
})
|
|
327
|
+
]
|
|
328
|
+
});
|
|
329
|
+
};
|
|
330
|
+
//#endregion
|
|
331
|
+
//#region src/components/dnd/canvas/overlay.tsx
|
|
332
|
+
const Overlay = ({ sections, isForced, renderProps }) => {
|
|
333
|
+
const { active } = useDndContext();
|
|
334
|
+
if (!active) return null;
|
|
335
|
+
const paletteSection = paletteSectionOf(active.data);
|
|
336
|
+
if (paletteSection) return /* @__PURE__ */ jsx(DefaultDraggableItem, { item: paletteSection });
|
|
337
|
+
const section = sections.find((s) => s.id === active.id);
|
|
338
|
+
if (section) {
|
|
339
|
+
const preview = generateSection(section.code, renderProps.fullCode, { containerId: renderProps.containerId });
|
|
340
|
+
return /* @__PURE__ */ jsx(Sortable, {
|
|
341
|
+
id: section.id,
|
|
342
|
+
name: section.name,
|
|
343
|
+
children: /* @__PURE__ */ jsx(renderer_default, {
|
|
344
|
+
preview,
|
|
345
|
+
sectionId: section.id,
|
|
346
|
+
sectionName: section.name,
|
|
347
|
+
sectionCode: section.code,
|
|
348
|
+
forceFallback: isForced?.(section) ?? false,
|
|
349
|
+
modules: renderProps.modules,
|
|
350
|
+
frame: renderProps.frame,
|
|
351
|
+
dynamicTailwind: renderProps.dynamicTailwind
|
|
352
|
+
})
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
return null;
|
|
356
|
+
};
|
|
357
|
+
//#endregion
|
|
46
358
|
//#region src/components/dnd/edit-options.ts
|
|
47
359
|
const toastEditError = (error) => {
|
|
48
360
|
Toast.error(error.title, error.description ? { description: error.description } : void 0);
|
|
@@ -94,72 +406,16 @@ const findElementById = (section, id) => {
|
|
|
94
406
|
const viewportRect = (element) => {
|
|
95
407
|
const rect = element.getBoundingClientRect();
|
|
96
408
|
let x = rect.left;
|
|
97
|
-
let y = rect.top;
|
|
98
|
-
let frame = element.ownerDocument.defaultView?.frameElement ?? null;
|
|
99
|
-
while (frame) {
|
|
100
|
-
const frameRect = frame.getBoundingClientRect();
|
|
101
|
-
x += frameRect.left;
|
|
102
|
-
y += frameRect.top;
|
|
103
|
-
frame = frame.ownerDocument.defaultView?.frameElement ?? null;
|
|
104
|
-
}
|
|
105
|
-
return new DOMRect(x, y, rect.width, rect.height);
|
|
106
|
-
};
|
|
107
|
-
//#endregion
|
|
108
|
-
//#region src/components/dnd/inspector-highlight.tsx
|
|
109
|
-
const InspectorHighlight = ({ rect }) => rect ? createPortal(/* @__PURE__ */ jsx("div", {
|
|
110
|
-
"aria-hidden": true,
|
|
111
|
-
"data-dnd-inspector-highlight": true,
|
|
112
|
-
style: {
|
|
113
|
-
position: "fixed",
|
|
114
|
-
left: rect.left,
|
|
115
|
-
top: rect.top,
|
|
116
|
-
width: rect.width,
|
|
117
|
-
height: rect.height,
|
|
118
|
-
pointerEvents: "none",
|
|
119
|
-
outline: "2px solid #3b82f6",
|
|
120
|
-
outlineOffset: -1,
|
|
121
|
-
background: "rgba(59, 130, 246, 0.12)",
|
|
122
|
-
zIndex: 2147483647
|
|
123
|
-
}
|
|
124
|
-
}), document.body) : null;
|
|
125
|
-
//#endregion
|
|
126
|
-
//#region src/components/dnd/draggable.tsx
|
|
127
|
-
const DraggableItem = ({ item, children }) => {
|
|
128
|
-
const { attributes, listeners, setNodeRef, isDragging } = useDraggable({
|
|
129
|
-
id: item.id,
|
|
130
|
-
data: {
|
|
131
|
-
type: "new-item",
|
|
132
|
-
item
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
return children({
|
|
136
|
-
ref: setNodeRef,
|
|
137
|
-
dragProps: {
|
|
138
|
-
...listeners,
|
|
139
|
-
...attributes
|
|
140
|
-
},
|
|
141
|
-
isDragging
|
|
142
|
-
});
|
|
143
|
-
};
|
|
144
|
-
const DefaultDraggableItem = ({ item, onAdd, tapToAdd = false }) => /* @__PURE__ */ jsx(DraggableItem, {
|
|
145
|
-
item,
|
|
146
|
-
children: ({ ref, dragProps, isDragging }) => /* @__PURE__ */ jsx(Card, {
|
|
147
|
-
ref,
|
|
148
|
-
style: { opacity: isDragging ? .5 : 1 },
|
|
149
|
-
...dragProps,
|
|
150
|
-
className: cn("cursor-grab", "outline-none focus-visible:ring-2 focus-visible:ring-blue-500", "hover:border-blue-300 hover:shadow-md", isDragging && "opacity-50"),
|
|
151
|
-
onClick: tapToAdd && onAdd ? () => onAdd(item) : void 0,
|
|
152
|
-
onDoubleClick: onAdd ? () => onAdd(item) : void 0,
|
|
153
|
-
onKeyDown: (event) => {
|
|
154
|
-
dragProps.onKeyDown?.(event);
|
|
155
|
-
if (onAdd && event.key === "Enter" && event.target === event.currentTarget && !event.defaultPrevented) {
|
|
156
|
-
event.preventDefault();
|
|
157
|
-
onAdd(item);
|
|
158
|
-
}
|
|
159
|
-
},
|
|
160
|
-
children: item.name
|
|
161
|
-
})
|
|
162
|
-
});
|
|
409
|
+
let y = rect.top;
|
|
410
|
+
let frame = element.ownerDocument.defaultView?.frameElement ?? null;
|
|
411
|
+
while (frame) {
|
|
412
|
+
const frameRect = frame.getBoundingClientRect();
|
|
413
|
+
x += frameRect.left;
|
|
414
|
+
y += frameRect.top;
|
|
415
|
+
frame = frame.ownerDocument.defaultView?.frameElement ?? null;
|
|
416
|
+
}
|
|
417
|
+
return new DOMRect(x, y, rect.width, rect.height);
|
|
418
|
+
};
|
|
163
419
|
//#endregion
|
|
164
420
|
//#region src/components/dnd/layout-context.ts
|
|
165
421
|
const DndRegionContext = createContext(null);
|
|
@@ -1733,248 +1989,7 @@ const Layout = ({ palette, panel }) => {
|
|
|
1733
1989
|
] });
|
|
1734
1990
|
};
|
|
1735
1991
|
//#endregion
|
|
1736
|
-
//#region src/components/dnd/
|
|
1737
|
-
const SectionFallbackContext = createContext(void 0);
|
|
1738
|
-
//#endregion
|
|
1739
|
-
//#region src/components/dnd/section-fallback.tsx
|
|
1740
|
-
const ConsumerFallback = ({ render, args, builtin }) => {
|
|
1741
|
-
const node = render(args);
|
|
1742
|
-
return node === void 0 ? builtin : /* @__PURE__ */ jsx(Fragment, { children: node });
|
|
1743
|
-
};
|
|
1744
|
-
const SectionFallback = ({ args, builtin }) => {
|
|
1745
|
-
const render = useContext(SectionFallbackContext);
|
|
1746
|
-
if (!render) return builtin;
|
|
1747
|
-
return /* @__PURE__ */ jsx(ErrorBoundary, {
|
|
1748
|
-
fallback: () => builtin,
|
|
1749
|
-
children: /* @__PURE__ */ jsx(ConsumerFallback, {
|
|
1750
|
-
render,
|
|
1751
|
-
args,
|
|
1752
|
-
builtin
|
|
1753
|
-
})
|
|
1754
|
-
});
|
|
1755
|
-
};
|
|
1756
|
-
//#endregion
|
|
1757
|
-
//#region src/components/dnd/renderer.tsx
|
|
1758
|
-
const Renderer = ({ preview, sectionId = "", sectionName = "", sectionCode = preview, forceFallback = false, headers, modules, frame, dynamicTailwind = false, provider }) => {
|
|
1759
|
-
const module = useCompiledModule(forceFallback ? "" : preview, modules);
|
|
1760
|
-
const section = {
|
|
1761
|
-
id: sectionId,
|
|
1762
|
-
name: sectionName,
|
|
1763
|
-
code: sectionCode
|
|
1764
|
-
};
|
|
1765
|
-
const messages = useLiveMessages();
|
|
1766
|
-
const { ref: wrapperRef, css: dynamicCSS } = useDynamicTailwind(preview, dynamicTailwind && !forceFallback);
|
|
1767
|
-
const renderProvider = (component) => {
|
|
1768
|
-
return provider ? provider(component) : component;
|
|
1769
|
-
};
|
|
1770
|
-
if (forceFallback) return /* @__PURE__ */ jsx(SectionFallback, {
|
|
1771
|
-
args: {
|
|
1772
|
-
section,
|
|
1773
|
-
reason: "forced"
|
|
1774
|
-
},
|
|
1775
|
-
builtin: /* @__PURE__ */ jsx(Error$1, {
|
|
1776
|
-
message: messages.errors.sectionNotRendered,
|
|
1777
|
-
title: messages.errors.sectionUnavailable
|
|
1778
|
-
})
|
|
1779
|
-
});
|
|
1780
|
-
if (module?.error) return /* @__PURE__ */ jsx(SectionFallback, {
|
|
1781
|
-
args: {
|
|
1782
|
-
section,
|
|
1783
|
-
reason: "compile",
|
|
1784
|
-
message: module.error
|
|
1785
|
-
},
|
|
1786
|
-
builtin: /* @__PURE__ */ jsx(Error$1, {
|
|
1787
|
-
message: module.error,
|
|
1788
|
-
title: messages.errors.compile
|
|
1789
|
-
})
|
|
1790
|
-
});
|
|
1791
|
-
const Component = module?.exports?.default;
|
|
1792
|
-
if (!Component) return null;
|
|
1793
|
-
return /* @__PURE__ */ jsx(Frame, {
|
|
1794
|
-
...frame,
|
|
1795
|
-
autoHeight: true,
|
|
1796
|
-
children: (container) => /* @__PURE__ */ jsx("div", {
|
|
1797
|
-
ref: wrapperRef,
|
|
1798
|
-
className: "w-full overflow-x-hidden",
|
|
1799
|
-
"data-editor-mode": true,
|
|
1800
|
-
children: /* @__PURE__ */ jsx(ErrorBoundary, {
|
|
1801
|
-
resetKeys: [preview],
|
|
1802
|
-
fallback: (message, reset) => /* @__PURE__ */ jsx(SectionFallback, {
|
|
1803
|
-
args: {
|
|
1804
|
-
section,
|
|
1805
|
-
reason: "runtime",
|
|
1806
|
-
message
|
|
1807
|
-
},
|
|
1808
|
-
builtin: /* @__PURE__ */ jsx(Error$1, {
|
|
1809
|
-
message,
|
|
1810
|
-
onReset: reset,
|
|
1811
|
-
title: messages.errors.rendering
|
|
1812
|
-
})
|
|
1813
|
-
}),
|
|
1814
|
-
children: renderProvider(/* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Component, {
|
|
1815
|
-
headers,
|
|
1816
|
-
container
|
|
1817
|
-
}), dynamicTailwind && dynamicCSS && /* @__PURE__ */ jsx("style", { children: dynamicCSS })] }))
|
|
1818
|
-
})
|
|
1819
|
-
})
|
|
1820
|
-
});
|
|
1821
|
-
};
|
|
1822
|
-
const sameValue = (a, b) => {
|
|
1823
|
-
if (Object.is(a, b)) return true;
|
|
1824
|
-
if (Array.isArray(a) && Array.isArray(b)) return a.length === b.length && a.every((item, i) => Object.is(item, b[i]));
|
|
1825
|
-
if (a && b && typeof a === "object" && typeof b === "object" && Object.getPrototypeOf(a) === Object.prototype && Object.getPrototypeOf(b) === Object.prototype) {
|
|
1826
|
-
const aKeys = Object.keys(a);
|
|
1827
|
-
return aKeys.length === Object.keys(b).length && aKeys.every((key) => Object.is(a[key], b[key]));
|
|
1828
|
-
}
|
|
1829
|
-
return false;
|
|
1830
|
-
};
|
|
1831
|
-
const sameFrame = (a, b) => {
|
|
1832
|
-
if (a === b) return true;
|
|
1833
|
-
if (!a || !b) return false;
|
|
1834
|
-
return [.../* @__PURE__ */ new Set([...Object.keys(a), ...Object.keys(b)])].every((key) => sameValue(a[key], b[key]));
|
|
1835
|
-
};
|
|
1836
|
-
const arePropsEqual = (prev, next) => {
|
|
1837
|
-
return [.../* @__PURE__ */ new Set([...Object.keys(prev), ...Object.keys(next)])].every((key) => key === "frame" ? sameFrame(prev.frame, next.frame) : Object.is(prev[key], next[key]));
|
|
1838
|
-
};
|
|
1839
|
-
var renderer_default = memo(Renderer, arePropsEqual);
|
|
1840
|
-
//#endregion
|
|
1841
|
-
//#region src/components/dnd/sortable.tsx
|
|
1842
|
-
const NAVIGATION_KEYS = {
|
|
1843
|
-
ArrowUp: "previous",
|
|
1844
|
-
ArrowDown: "next",
|
|
1845
|
-
Home: "first",
|
|
1846
|
-
End: "last"
|
|
1847
|
-
};
|
|
1848
|
-
const Sortable = ({ id, children, selected, onClick, onDelete: _onDelete, onCopy: _onCopy, onMoveUp, onMoveDown, canMoveUp = false, canMoveDown = false, nodeRef, onNavigate, onDeleteKey, inspecting = false, onInspectMove, onInspectPick, onInspectLeave }) => {
|
|
1849
|
-
const { attributes, listeners, setNodeRef, setActivatorNodeRef, transform, transition, isDragging, isOver, active } = useSortable({
|
|
1850
|
-
id,
|
|
1851
|
-
disabled: inspecting
|
|
1852
|
-
});
|
|
1853
|
-
const messages = useLiveMessages();
|
|
1854
|
-
const style = {
|
|
1855
|
-
transform: CSS$1.Transform.toString(transform),
|
|
1856
|
-
transition,
|
|
1857
|
-
opacity: isDragging ? .5 : 1,
|
|
1858
|
-
cursor: inspecting ? "crosshair" : "grab"
|
|
1859
|
-
};
|
|
1860
|
-
const isNewItemOver = isOver && active?.data.current?.type === "new-item";
|
|
1861
|
-
const onKeyDown = (e) => {
|
|
1862
|
-
listeners?.onKeyDown?.(e);
|
|
1863
|
-
if (e.target !== e.currentTarget || active || e.defaultPrevented) return;
|
|
1864
|
-
if (e.key === "Enter") {
|
|
1865
|
-
e.preventDefault();
|
|
1866
|
-
onClick?.();
|
|
1867
|
-
return;
|
|
1868
|
-
}
|
|
1869
|
-
const to = NAVIGATION_KEYS[e.key];
|
|
1870
|
-
if (to && onNavigate) {
|
|
1871
|
-
e.preventDefault();
|
|
1872
|
-
onNavigate(to);
|
|
1873
|
-
return;
|
|
1874
|
-
}
|
|
1875
|
-
if ((e.key === "Delete" || e.key === "Backspace") && onDeleteKey) {
|
|
1876
|
-
e.preventDefault();
|
|
1877
|
-
onDeleteKey();
|
|
1878
|
-
}
|
|
1879
|
-
};
|
|
1880
|
-
const setRefs = (node) => {
|
|
1881
|
-
setNodeRef(node);
|
|
1882
|
-
setActivatorNodeRef(node);
|
|
1883
|
-
nodeRef?.(node);
|
|
1884
|
-
};
|
|
1885
|
-
const onDelete = (e) => {
|
|
1886
|
-
e.stopPropagation();
|
|
1887
|
-
_onDelete?.(id);
|
|
1888
|
-
};
|
|
1889
|
-
const onCopy = (e) => {
|
|
1890
|
-
e.stopPropagation();
|
|
1891
|
-
_onCopy?.(id);
|
|
1892
|
-
};
|
|
1893
|
-
const press = (action) => (e) => {
|
|
1894
|
-
e.stopPropagation();
|
|
1895
|
-
action?.();
|
|
1896
|
-
};
|
|
1897
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
1898
|
-
ref: setRefs,
|
|
1899
|
-
style,
|
|
1900
|
-
...attributes,
|
|
1901
|
-
...listeners,
|
|
1902
|
-
onKeyDown,
|
|
1903
|
-
onClick,
|
|
1904
|
-
className: cn("relative", selected && "z-10 outline-2 outline-offset-2 outline-blue-500", isNewItemOver && "border-t-4 border-t-green-500"),
|
|
1905
|
-
children: [
|
|
1906
|
-
/* @__PURE__ */ jsx("div", {
|
|
1907
|
-
className: cn("absolute inset-0 z-50"),
|
|
1908
|
-
onPointerMove: inspecting ? (e) => onInspectMove?.(e.currentTarget.parentElement, e.currentTarget, e.clientX, e.clientY) : void 0,
|
|
1909
|
-
onPointerLeave: inspecting ? onInspectLeave : void 0,
|
|
1910
|
-
onClick: inspecting ? (e) => {
|
|
1911
|
-
e.stopPropagation();
|
|
1912
|
-
onInspectPick?.(e.currentTarget.parentElement, e.currentTarget, e.clientX, e.clientY);
|
|
1913
|
-
} : void 0
|
|
1914
|
-
}),
|
|
1915
|
-
children,
|
|
1916
|
-
selected && /* @__PURE__ */ jsxs(Space, {
|
|
1917
|
-
className: cn("absolute top-1 right-1 z-60"),
|
|
1918
|
-
children: [
|
|
1919
|
-
onMoveUp && /* @__PURE__ */ jsx(Button, {
|
|
1920
|
-
icon: /* @__PURE__ */ jsx(ChevronUp, {}),
|
|
1921
|
-
disabled: !canMoveUp,
|
|
1922
|
-
onClick: press(onMoveUp),
|
|
1923
|
-
"aria-label": messages.section.moveUp
|
|
1924
|
-
}),
|
|
1925
|
-
onMoveDown && /* @__PURE__ */ jsx(Button, {
|
|
1926
|
-
icon: /* @__PURE__ */ jsx(ChevronDown, {}),
|
|
1927
|
-
disabled: !canMoveDown,
|
|
1928
|
-
onClick: press(onMoveDown),
|
|
1929
|
-
"aria-label": messages.section.moveDown
|
|
1930
|
-
}),
|
|
1931
|
-
/* @__PURE__ */ jsx(Button, {
|
|
1932
|
-
icon: /* @__PURE__ */ jsx(Copy, {}),
|
|
1933
|
-
onClick: onCopy,
|
|
1934
|
-
"aria-label": messages.section.duplicate
|
|
1935
|
-
}),
|
|
1936
|
-
/* @__PURE__ */ jsx(Button, {
|
|
1937
|
-
danger: true,
|
|
1938
|
-
icon: /* @__PURE__ */ jsx(Trash, {}),
|
|
1939
|
-
onClick: onDelete,
|
|
1940
|
-
"aria-label": messages.section.delete
|
|
1941
|
-
})
|
|
1942
|
-
]
|
|
1943
|
-
})
|
|
1944
|
-
]
|
|
1945
|
-
});
|
|
1946
|
-
};
|
|
1947
|
-
//#endregion
|
|
1948
|
-
//#region src/components/dnd/overlay.tsx
|
|
1949
|
-
const Overlay = ({ sections, isForced, renderProps }) => {
|
|
1950
|
-
const { active } = useDndContext();
|
|
1951
|
-
if (!active) return null;
|
|
1952
|
-
if (active.data.current?.type === "new-item") {
|
|
1953
|
-
const item = active.data.current.item;
|
|
1954
|
-
return /* @__PURE__ */ jsx(DefaultDraggableItem, { item });
|
|
1955
|
-
}
|
|
1956
|
-
const section = sections.find((s) => s.id === active.id);
|
|
1957
|
-
if (section) {
|
|
1958
|
-
const preview = generateSection(section.code, renderProps.fullCode, { containerId: renderProps.containerId });
|
|
1959
|
-
return /* @__PURE__ */ jsx(Sortable, {
|
|
1960
|
-
id: section.id,
|
|
1961
|
-
name: section.name,
|
|
1962
|
-
children: /* @__PURE__ */ jsx(renderer_default, {
|
|
1963
|
-
preview,
|
|
1964
|
-
sectionId: section.id,
|
|
1965
|
-
sectionName: section.name,
|
|
1966
|
-
sectionCode: section.code,
|
|
1967
|
-
forceFallback: isForced?.(section) ?? false,
|
|
1968
|
-
modules: renderProps.modules,
|
|
1969
|
-
frame: renderProps.frame,
|
|
1970
|
-
dynamicTailwind: renderProps.dynamicTailwind
|
|
1971
|
-
})
|
|
1972
|
-
});
|
|
1973
|
-
}
|
|
1974
|
-
return null;
|
|
1975
|
-
};
|
|
1976
|
-
//#endregion
|
|
1977
|
-
//#region src/components/dnd/use-delete-flow.ts
|
|
1992
|
+
//#region src/components/dnd/state/use-delete-flow.ts
|
|
1978
1993
|
const useDeleteFlow = ({ sections, remove, onBeforeDelete }) => {
|
|
1979
1994
|
const removeRef = useRef(remove);
|
|
1980
1995
|
useEffect(() => {
|
|
@@ -2008,7 +2023,7 @@ const useDeleteFlow = ({ sections, remove, onBeforeDelete }) => {
|
|
|
2008
2023
|
};
|
|
2009
2024
|
};
|
|
2010
2025
|
//#endregion
|
|
2011
|
-
//#region src/components/dnd/use-dnd-keyboard.ts
|
|
2026
|
+
//#region src/components/dnd/state/use-dnd-keyboard.ts
|
|
2012
2027
|
const KEYBOARD_CODES = {
|
|
2013
2028
|
start: ["Space"],
|
|
2014
2029
|
cancel: ["Escape"],
|
|
@@ -2042,7 +2057,7 @@ const useDndKeyboard = ({ sections, selectedId, selectedIndex, selectOnly, move,
|
|
|
2042
2057
|
keyboardCodes: KEYBOARD_CODES
|
|
2043
2058
|
}));
|
|
2044
2059
|
const nameOf = (id, data) => {
|
|
2045
|
-
return (data
|
|
2060
|
+
return paletteSectionOf(data)?.name ?? sections.find((section) => section.id === id)?.name ?? say.section;
|
|
2046
2061
|
};
|
|
2047
2062
|
const positionOf = (id) => sections.findIndex((section) => section.id === id) + 1;
|
|
2048
2063
|
const announcements = {
|
|
@@ -2095,7 +2110,7 @@ const useDndKeyboard = ({ sections, selectedId, selectedIndex, selectOnly, move,
|
|
|
2095
2110
|
};
|
|
2096
2111
|
};
|
|
2097
2112
|
//#endregion
|
|
2098
|
-
//#region src/components/dnd/use-inspector-state.ts
|
|
2113
|
+
//#region src/components/dnd/state/use-inspector-state.ts
|
|
2099
2114
|
const useInspectorState = ({ selectedId, selectOnly, sectionNodes, onNodePick }) => {
|
|
2100
2115
|
const [inspecting, setInspecting] = useState(false);
|
|
2101
2116
|
const [picked, setPicked] = useState(null);
|
|
@@ -2173,7 +2188,7 @@ const useInspectorState = ({ selectedId, selectOnly, sectionNodes, onNodePick })
|
|
|
2173
2188
|
};
|
|
2174
2189
|
};
|
|
2175
2190
|
//#endregion
|
|
2176
|
-
//#region src/components/dnd/use-section-document.ts
|
|
2191
|
+
//#region src/components/dnd/state/use-section-document.ts
|
|
2177
2192
|
const createLastParsed = () => {
|
|
2178
2193
|
let last = null;
|
|
2179
2194
|
return {
|
|
@@ -2226,7 +2241,7 @@ const useSectionDocument = (value, onChange, { containerId, sectionNameFallback,
|
|
|
2226
2241
|
view.document
|
|
2227
2242
|
]);
|
|
2228
2243
|
const selectedIndex = sections.findIndex((s) => s.id === selectedId);
|
|
2229
|
-
const
|
|
2244
|
+
const selectedSection = selectedIndex >= 0 ? sections[selectedIndex] : void 0;
|
|
2230
2245
|
const pendingRef = useRef(null);
|
|
2231
2246
|
useEffect(() => {
|
|
2232
2247
|
pendingRef.current = null;
|
|
@@ -2272,17 +2287,17 @@ const useSectionDocument = (value, onChange, { containerId, sectionNameFallback,
|
|
|
2272
2287
|
sections,
|
|
2273
2288
|
previews,
|
|
2274
2289
|
selectedId,
|
|
2275
|
-
|
|
2290
|
+
selectedSection,
|
|
2276
2291
|
selectedIndex,
|
|
2277
2292
|
select: useCallback((id) => {
|
|
2278
2293
|
setSelectedId((prev) => prev === id ? null : id);
|
|
2279
2294
|
}, []),
|
|
2280
2295
|
selectOnly: useCallback((id) => setSelectedId(id), []),
|
|
2281
2296
|
clearSelection: useCallback(() => setSelectedId(null), []),
|
|
2282
|
-
add: useCallback((
|
|
2297
|
+
add: useCallback((section, atIndex) => {
|
|
2283
2298
|
if (refuse()) return;
|
|
2284
2299
|
const current = latestSections();
|
|
2285
|
-
const next = { code:
|
|
2300
|
+
const next = { code: section.code };
|
|
2286
2301
|
commit(atIndex === void 0 || atIndex < 0 ? [...current, next] : [
|
|
2287
2302
|
...current.slice(0, atIndex),
|
|
2288
2303
|
next,
|
|
@@ -2403,6 +2418,10 @@ const describeUpdateFailure = (failure, label, { editErrors: m }) => {
|
|
|
2403
2418
|
title: m.updateFailed(label),
|
|
2404
2419
|
description: m.elementNotFound
|
|
2405
2420
|
};
|
|
2421
|
+
case "self-closing": return {
|
|
2422
|
+
title: m.cannotEdit(label),
|
|
2423
|
+
description: m.selfClosing(failure.property)
|
|
2424
|
+
};
|
|
2406
2425
|
case "unsupported-syntax": return {
|
|
2407
2426
|
title: m.cannotEdit(label),
|
|
2408
2427
|
description: m.unsupportedSyntax(failure.property)
|
|
@@ -2424,7 +2443,7 @@ const blockedEditError = (error, { editErrors: m }) => ({
|
|
|
2424
2443
|
});
|
|
2425
2444
|
const conditionalModifiers = (args) => {
|
|
2426
2445
|
const { active } = args;
|
|
2427
|
-
if (active?.data
|
|
2446
|
+
if (paletteSectionOf(active?.data)) return args.transform;
|
|
2428
2447
|
return restrictToVerticalAxis(args);
|
|
2429
2448
|
};
|
|
2430
2449
|
const NO_MODULES = {};
|
|
@@ -2454,7 +2473,7 @@ const Dnd$1 = ({ value: _value, props, modules: _modules = NO_MODULES, onChange:
|
|
|
2454
2473
|
const onBlockedEdit = useCallback((problem) => {
|
|
2455
2474
|
if (problem.reason === "parse-error") reportErrorRef.current(blockedEditError(problem.error, messagesRef.current));
|
|
2456
2475
|
}, []);
|
|
2457
|
-
const { sections, previews, selectedId,
|
|
2476
|
+
const { sections, previews, selectedId, selectedSection, selectedIndex, select, selectOnly, clearSelection, add: addSection, remove, copy: onCopy, move: moveSection, reorder, patch, getCommittedSection, problem, stale } = useSectionDocument(value, _onChange, {
|
|
2458
2477
|
containerId,
|
|
2459
2478
|
sectionNameFallback,
|
|
2460
2479
|
onBlockedEdit
|
|
@@ -2463,10 +2482,10 @@ const Dnd$1 = ({ value: _value, props, modules: _modules = NO_MODULES, onChange:
|
|
|
2463
2482
|
const onDragEnd = (event) => {
|
|
2464
2483
|
const { active, over } = event;
|
|
2465
2484
|
if (!over) return;
|
|
2466
|
-
|
|
2467
|
-
|
|
2485
|
+
const section = paletteSectionOf(active.data);
|
|
2486
|
+
if (section) {
|
|
2468
2487
|
const atBottom = over.id === "sortable-area" || over.id === "sortable-area-bottom";
|
|
2469
|
-
|
|
2488
|
+
addSection(section, atBottom ? void 0 : sections.findIndex((s) => s.id === over.id));
|
|
2470
2489
|
return;
|
|
2471
2490
|
}
|
|
2472
2491
|
if (active.id !== over.id && sections.some((s) => s.id === active.id)) reorder(String(active.id), String(over.id));
|
|
@@ -2500,8 +2519,8 @@ const Dnd$1 = ({ value: _value, props, modules: _modules = NO_MODULES, onChange:
|
|
|
2500
2519
|
bindings: bindingRegistry,
|
|
2501
2520
|
bindingKeys
|
|
2502
2521
|
}), [bindingRegistry, bindingKeys]);
|
|
2503
|
-
const selectedCode =
|
|
2504
|
-
const selectedSectionId =
|
|
2522
|
+
const selectedCode = selectedSection?.code;
|
|
2523
|
+
const selectedSectionId = selectedSection?.id;
|
|
2505
2524
|
const { fields, updatedCode, parseError } = useMemo(() => {
|
|
2506
2525
|
if (!selectedCode) return {
|
|
2507
2526
|
fields: [],
|
|
@@ -2553,7 +2572,7 @@ const Dnd$1 = ({ value: _value, props, modules: _modules = NO_MODULES, onChange:
|
|
|
2553
2572
|
reportError(blockedEditError(problem.error, messages));
|
|
2554
2573
|
return;
|
|
2555
2574
|
}
|
|
2556
|
-
const committed =
|
|
2575
|
+
const committed = selectedSection && getCommittedSection(selectedSection.id)?.code;
|
|
2557
2576
|
const result = updateAll(committed && committed !== selectedCode ? committed : updatedCode, changes.map(({ id, label, property, value: changeValue }) => ({
|
|
2558
2577
|
dataId: id,
|
|
2559
2578
|
label,
|
|
@@ -2572,8 +2591,8 @@ const Dnd$1 = ({ value: _value, props, modules: _modules = NO_MODULES, onChange:
|
|
|
2572
2591
|
});
|
|
2573
2592
|
return;
|
|
2574
2593
|
}
|
|
2575
|
-
if (
|
|
2576
|
-
...
|
|
2594
|
+
if (selectedSection) onChange({
|
|
2595
|
+
...selectedSection,
|
|
2577
2596
|
code: result.code
|
|
2578
2597
|
});
|
|
2579
2598
|
};
|
|
@@ -2584,14 +2603,14 @@ const Dnd$1 = ({ value: _value, props, modules: _modules = NO_MODULES, onChange:
|
|
|
2584
2603
|
if (frame?.scripts?.length) preloadScripts(frame.scripts);
|
|
2585
2604
|
}, [frame?.scripts]);
|
|
2586
2605
|
const palette = {
|
|
2587
|
-
items: items?.length ? items :
|
|
2588
|
-
onAdd: (
|
|
2589
|
-
|
|
2606
|
+
items: items?.length ? items : PALETTE_SECTIONS,
|
|
2607
|
+
onAdd: (section) => {
|
|
2608
|
+
addSection(section);
|
|
2590
2609
|
setMobilePaletteOpen(false);
|
|
2591
2610
|
}
|
|
2592
2611
|
};
|
|
2593
2612
|
const panel = {
|
|
2594
|
-
item:
|
|
2613
|
+
item: selectedSection,
|
|
2595
2614
|
onChange,
|
|
2596
2615
|
onDelete,
|
|
2597
2616
|
onMoveUp: () => moveSection(selectedId, "up"),
|
|
@@ -2604,63 +2623,67 @@ const Dnd$1 = ({ value: _value, props, modules: _modules = NO_MODULES, onChange:
|
|
|
2604
2623
|
readOnly: stale,
|
|
2605
2624
|
bindingOptions
|
|
2606
2625
|
};
|
|
2607
|
-
const canvas = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
className: cn(
|
|
2615
|
-
children:
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
items: sections.map((s) => s.id),
|
|
2630
|
-
strategy: verticalListSortingStrategy,
|
|
2631
|
-
children: sections.map((section, index) => /* @__PURE__ */ jsx(Sortable, {
|
|
2632
|
-
id: section.id,
|
|
2633
|
-
name: section.name,
|
|
2634
|
-
selected: selectedId === section.id,
|
|
2635
|
-
onClick: () => onSelect(section.id),
|
|
2636
|
-
onDelete,
|
|
2637
|
-
onCopy,
|
|
2638
|
-
onMoveUp: () => onMoveButton(section.id, "up"),
|
|
2639
|
-
onMoveDown: () => onMoveButton(section.id, "down"),
|
|
2640
|
-
canMoveUp: index > 0,
|
|
2641
|
-
canMoveDown: index < sections.length - 1,
|
|
2642
|
-
nodeRef: sectionNodes.register(section.id),
|
|
2643
|
-
onNavigate: (to) => onNavigate(section.id, to),
|
|
2644
|
-
onDeleteKey: () => onDeleteKey(section.id),
|
|
2645
|
-
inspecting,
|
|
2646
|
-
onInspectMove,
|
|
2647
|
-
onInspectPick: (...args) => onInspectPick(section.id, ...args),
|
|
2648
|
-
onInspectLeave,
|
|
2649
|
-
children: /* @__PURE__ */ jsx(renderer_default, {
|
|
2650
|
-
preview: previews[index],
|
|
2651
|
-
sectionId: section.id,
|
|
2652
|
-
sectionName: section.name,
|
|
2653
|
-
sectionCode: section.code,
|
|
2654
|
-
forceFallback: isForced(section),
|
|
2655
|
-
modules,
|
|
2656
|
-
frame,
|
|
2657
|
-
dynamicTailwind,
|
|
2658
|
-
provider,
|
|
2659
|
-
...props
|
|
2626
|
+
const canvas = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2627
|
+
stale && /* @__PURE__ */ jsx("div", {
|
|
2628
|
+
role: "status",
|
|
2629
|
+
className: cn("sticky top-0 z-70", "border-b border-amber-200 bg-amber-50 px-3 py-2", "text-sm text-amber-900"),
|
|
2630
|
+
children: messages.canvas.stale
|
|
2631
|
+
}),
|
|
2632
|
+
/* @__PURE__ */ jsx(Droppable, {
|
|
2633
|
+
className: cn(!sections.length && "h-full"),
|
|
2634
|
+
children: !sections.length ? /* @__PURE__ */ jsx("div", {
|
|
2635
|
+
className: cn("flex items-center justify-center", "h-full", "text-gray-500"),
|
|
2636
|
+
children: problem?.reason === "parse-error" ? /* @__PURE__ */ jsxs(Space, {
|
|
2637
|
+
orientation: "vertical",
|
|
2638
|
+
align: "center",
|
|
2639
|
+
children: [/* @__PURE__ */ jsx(Typography.Paragraph, { children: messages.canvas.syntaxError }), /* @__PURE__ */ jsx(Typography.Text, { children: messages.canvas.syntaxErrorDetail })]
|
|
2640
|
+
}) : missingContainer !== null ? /* @__PURE__ */ jsxs(Space, {
|
|
2641
|
+
orientation: "vertical",
|
|
2642
|
+
align: "center",
|
|
2643
|
+
children: [/* @__PURE__ */ jsx(Typography.Paragraph, { children: messages.canvas.missingContainer(missingContainer) }), /* @__PURE__ */ jsx(Typography.Text, { children: messages.canvas.missingContainerDetail(missingContainer) })]
|
|
2644
|
+
}) : /* @__PURE__ */ jsxs(Space, {
|
|
2645
|
+
orientation: "vertical",
|
|
2646
|
+
align: "center",
|
|
2647
|
+
children: [/* @__PURE__ */ jsx(Typography.Paragraph, { children: messages.canvas.empty }), /* @__PURE__ */ jsx(Typography.Text, { children: isMobile ? messages.canvas.emptyHintTouch : messages.canvas.emptyHintDrag })]
|
|
2660
2648
|
})
|
|
2661
|
-
},
|
|
2662
|
-
|
|
2663
|
-
|
|
2649
|
+
}) : /* @__PURE__ */ jsx(SortableContext, {
|
|
2650
|
+
items: sections.map((s) => s.id),
|
|
2651
|
+
strategy: verticalListSortingStrategy,
|
|
2652
|
+
children: sections.map((section, index) => /* @__PURE__ */ jsx(Sortable, {
|
|
2653
|
+
id: section.id,
|
|
2654
|
+
name: section.name,
|
|
2655
|
+
selected: selectedId === section.id,
|
|
2656
|
+
onClick: () => onSelect(section.id),
|
|
2657
|
+
onDelete,
|
|
2658
|
+
onCopy,
|
|
2659
|
+
onMoveUp: () => onMoveButton(section.id, "up"),
|
|
2660
|
+
onMoveDown: () => onMoveButton(section.id, "down"),
|
|
2661
|
+
canMoveUp: index > 0,
|
|
2662
|
+
canMoveDown: index < sections.length - 1,
|
|
2663
|
+
nodeRef: sectionNodes.register(section.id),
|
|
2664
|
+
onNavigate: (to) => onNavigate(section.id, to),
|
|
2665
|
+
onDeleteKey: () => onDeleteKey(section.id),
|
|
2666
|
+
inspecting,
|
|
2667
|
+
onInspectMove,
|
|
2668
|
+
onInspectPick: (...args) => onInspectPick(section.id, ...args),
|
|
2669
|
+
onInspectLeave,
|
|
2670
|
+
children: /* @__PURE__ */ jsx(renderer_default, {
|
|
2671
|
+
preview: previews[index],
|
|
2672
|
+
sectionId: section.id,
|
|
2673
|
+
sectionName: section.name,
|
|
2674
|
+
sectionCode: section.code,
|
|
2675
|
+
forceFallback: isForced(section),
|
|
2676
|
+
modules,
|
|
2677
|
+
frame,
|
|
2678
|
+
dynamicTailwind,
|
|
2679
|
+
provider,
|
|
2680
|
+
...props
|
|
2681
|
+
})
|
|
2682
|
+
}, section.id))
|
|
2683
|
+
})
|
|
2684
|
+
}),
|
|
2685
|
+
/* @__PURE__ */ jsx(InspectorHighlight, { rect: highlightRect })
|
|
2686
|
+
] });
|
|
2664
2687
|
return /* @__PURE__ */ jsx(SectionFallbackContext.Provider, {
|
|
2665
2688
|
value: renderSectionFallback,
|
|
2666
2689
|
children: /* @__PURE__ */ jsxs(DndContext, {
|
|
@@ -2675,13 +2698,13 @@ const Dnd$1 = ({ value: _value, props, modules: _modules = NO_MODULES, onChange:
|
|
|
2675
2698
|
children: [/* @__PURE__ */ jsx("div", {
|
|
2676
2699
|
className: cn("relative flex h-full w-full", className),
|
|
2677
2700
|
...restProps,
|
|
2678
|
-
children: /* @__PURE__ */
|
|
2701
|
+
children: /* @__PURE__ */ jsx(DndEditOptionsContext.Provider, {
|
|
2679
2702
|
value: {
|
|
2680
2703
|
renderField,
|
|
2681
2704
|
reportError,
|
|
2682
2705
|
bindingOptions
|
|
2683
2706
|
},
|
|
2684
|
-
children:
|
|
2707
|
+
children: /* @__PURE__ */ jsx(DndRegionContext.Provider, {
|
|
2685
2708
|
value: {
|
|
2686
2709
|
palette,
|
|
2687
2710
|
panel,
|
|
@@ -2697,7 +2720,7 @@ const Dnd$1 = ({ value: _value, props, modules: _modules = NO_MODULES, onChange:
|
|
|
2697
2720
|
value: inspector,
|
|
2698
2721
|
children: Children.toArray(children).length ? children : /* @__PURE__ */ jsx(Layout, {})
|
|
2699
2722
|
})
|
|
2700
|
-
})
|
|
2723
|
+
})
|
|
2701
2724
|
})
|
|
2702
2725
|
}), /* @__PURE__ */ jsx(DragOverlay, { children: /* @__PURE__ */ jsx(Overlay, {
|
|
2703
2726
|
sections,
|
|
@@ -2728,6 +2751,6 @@ const useItemsEditor = useDndItems;
|
|
|
2728
2751
|
/** @deprecated Renamed to `useDndChildren`. */
|
|
2729
2752
|
const useChildrenEditor = useDndChildren;
|
|
2730
2753
|
//#endregion
|
|
2731
|
-
export { useDndPanel as _, Layout as a, Field as c, isStructuralFieldKind as d, useDndChildren as f, useDndPalette as g, useDndLayout as h, Canvas as i, useDndItems as l, withPanelCommit as m, useChildrenEditor as n, Palette as o, resolvePanelBindings as p, useItemsEditor as r, Panel as s, Dnd as t, getFieldKind as u,
|
|
2754
|
+
export { useDndPanel as _, Layout as a, Field as c, isStructuralFieldKind as d, useDndChildren as f, useDndPalette as g, useDndLayout as h, Canvas as i, useDndItems as l, withPanelCommit as m, useChildrenEditor as n, Palette as o, resolvePanelBindings as p, useItemsEditor as r, Panel as s, Dnd as t, getFieldKind as u, useDndInspector as v, DraggableItem as y };
|
|
2732
2755
|
|
|
2733
|
-
//# sourceMappingURL=dnd-
|
|
2756
|
+
//# sourceMappingURL=dnd-UoJILA75.js.map
|