@jbpark/live-editor 4.5.0 → 4.6.1
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-V8NAxd_R.js} +435 -413
- package/dist/dnd-V8NAxd_R.js.map +1 -0
- package/dist/document-CHO215iP.js +33992 -0
- package/dist/document-CHO215iP.js.map +1 -0
- package/dist/{document-Ct4jW78J.d.ts → document-DqRSCtsx.d.ts} +496 -435
- 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-vtyggWy0.d.ts → index-CRwEhJ7w.d.ts} +2 -2
- package/dist/index-C_PfR4X9.d.ts +734 -0
- package/dist/{index-P9Aifaui.d.ts → index-CiWB0zFb.d.ts} +72 -70
- package/dist/{index-WQgFy510.d.ts → index-DrWtSKXu.d.ts} +2 -2
- package/dist/index.d.ts +5 -5
- package/dist/index.js +6 -6
- package/dist/{items-DdrwGxJw.js → items-BXXtMUNI.js} +307 -390
- package/dist/items-BXXtMUNI.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-jYuqS4KB.js} +3 -3
- package/dist/sections-jYuqS4KB.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 +2 -2
- package/dist/utils/ast/index.js +84 -2
- package/dist/utils/ast/index.js.map +1 -1
- package/dist/utils/index.d.ts +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 +5 -7
- 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/document-DGHTfrda.js +0 -38667
- package/dist/document-DGHTfrda.js.map +0 -1
- package/dist/editor-DQ8Q--qR.js.map +0 -1
- package/dist/index-CHknA6k1.d.ts +0 -221
- 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,47 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { c as RESERVED_BINDING_PROPERTIES, o as
|
|
1
|
+
import { A as isJSXElement, B as isObjectExpression, D as isExpression, N as isJSXFragment, O as isIdentifier, V as isObjectProperty, c as inspectDocument, h as replaceIds, m as fillIdsFrom, n as createSectionPreviewCache, r as fillSectionIds, x as nanoid } from "./document-CHO215iP.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-BXXtMUNI.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-jYuqS4KB.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
|
-
|
|
24
|
-
|
|
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
|
|
23
|
+
const PALETTE_SECTION = "palette-section";
|
|
24
|
+
const paletteDragData = (section) => ({
|
|
25
|
+
type: PALETTE_SECTION,
|
|
26
|
+
section
|
|
27
|
+
});
|
|
28
|
+
const paletteSectionOf = (data) => {
|
|
29
|
+
const current = data?.current;
|
|
30
|
+
return current?.type === PALETTE_SECTION ? current.section : void 0;
|
|
31
|
+
};
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/components/dnd/canvas/droppable.tsx
|
|
25
34
|
const Droppable = ({ children, className }) => {
|
|
26
35
|
const { setNodeRef, isOver, active } = useDroppable({ id: "sortable-area" });
|
|
27
36
|
const { setNodeRef: setBottomRef, isOver: isBottomOver } = useDroppable({ id: "sortable-area-bottom" });
|
|
28
|
-
const
|
|
29
|
-
const shouldHighlight = isOver &&
|
|
30
|
-
const shouldHighlightBottom = isBottomOver &&
|
|
37
|
+
const isPaletteSectionDragging = !!paletteSectionOf(active?.data);
|
|
38
|
+
const shouldHighlight = isOver && isPaletteSectionDragging;
|
|
39
|
+
const shouldHighlightBottom = isBottomOver && isPaletteSectionDragging;
|
|
31
40
|
const messages = useLiveMessages();
|
|
32
41
|
return /* @__PURE__ */ jsxs("div", {
|
|
33
42
|
ref: setNodeRef,
|
|
34
43
|
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,
|
|
44
|
+
children: [children, isPaletteSectionDragging && /* @__PURE__ */ jsx("div", {
|
|
36
45
|
ref: setBottomRef,
|
|
37
46
|
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
47
|
children: /* @__PURE__ */ jsx(Typography.Text, {
|
|
@@ -43,6 +52,308 @@ const Droppable = ({ children, className }) => {
|
|
|
43
52
|
});
|
|
44
53
|
};
|
|
45
54
|
//#endregion
|
|
55
|
+
//#region src/components/dnd/canvas/inspector-highlight.tsx
|
|
56
|
+
const InspectorHighlight = ({ rect }) => {
|
|
57
|
+
const ref = useRef(null);
|
|
58
|
+
useLayoutEffect(() => {
|
|
59
|
+
const box = ref.current;
|
|
60
|
+
const container = box?.closest("[data-frame-container]");
|
|
61
|
+
if (!box || !rect || !container) return;
|
|
62
|
+
const outer = container.getBoundingClientRect();
|
|
63
|
+
box.style.left = `${rect.left - outer.left - container.clientLeft + container.scrollLeft}px`;
|
|
64
|
+
box.style.top = `${rect.top - outer.top - container.clientTop + container.scrollTop}px`;
|
|
65
|
+
box.style.width = `${rect.width}px`;
|
|
66
|
+
box.style.height = `${rect.height}px`;
|
|
67
|
+
}, [rect]);
|
|
68
|
+
return rect ? /* @__PURE__ */ jsx("div", {
|
|
69
|
+
ref,
|
|
70
|
+
"aria-hidden": true,
|
|
71
|
+
"data-dnd-inspector-highlight": true,
|
|
72
|
+
style: {
|
|
73
|
+
position: "absolute",
|
|
74
|
+
pointerEvents: "none",
|
|
75
|
+
outline: "2px solid #3b82f6",
|
|
76
|
+
outlineOffset: -1,
|
|
77
|
+
background: "rgba(59, 130, 246, 0.12)",
|
|
78
|
+
zIndex: 65
|
|
79
|
+
}
|
|
80
|
+
}) : null;
|
|
81
|
+
};
|
|
82
|
+
//#endregion
|
|
83
|
+
//#region src/components/dnd/palette/draggable.tsx
|
|
84
|
+
const DraggableItem = ({ item, children }) => {
|
|
85
|
+
const { attributes, listeners, setNodeRef, isDragging } = useDraggable({
|
|
86
|
+
id: item.id,
|
|
87
|
+
data: paletteDragData(item)
|
|
88
|
+
});
|
|
89
|
+
return children({
|
|
90
|
+
ref: setNodeRef,
|
|
91
|
+
dragProps: {
|
|
92
|
+
...listeners,
|
|
93
|
+
...attributes
|
|
94
|
+
},
|
|
95
|
+
isDragging
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
const DefaultDraggableItem = ({ item, onAdd, tapToAdd = false }) => /* @__PURE__ */ jsx(DraggableItem, {
|
|
99
|
+
item,
|
|
100
|
+
children: ({ ref, dragProps, isDragging }) => /* @__PURE__ */ jsx(Card, {
|
|
101
|
+
ref,
|
|
102
|
+
style: { opacity: isDragging ? .5 : 1 },
|
|
103
|
+
...dragProps,
|
|
104
|
+
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"),
|
|
105
|
+
onClick: tapToAdd && onAdd ? () => onAdd(item) : void 0,
|
|
106
|
+
onDoubleClick: onAdd ? () => onAdd(item) : void 0,
|
|
107
|
+
onKeyDown: (event) => {
|
|
108
|
+
dragProps.onKeyDown?.(event);
|
|
109
|
+
if (onAdd && event.key === "Enter" && event.target === event.currentTarget && !event.defaultPrevented) {
|
|
110
|
+
event.preventDefault();
|
|
111
|
+
onAdd(item);
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
children: item.name
|
|
115
|
+
})
|
|
116
|
+
});
|
|
117
|
+
//#endregion
|
|
118
|
+
//#region src/components/dnd/canvas/section-fallback-context.ts
|
|
119
|
+
const SectionFallbackContext = createContext(void 0);
|
|
120
|
+
//#endregion
|
|
121
|
+
//#region src/components/dnd/canvas/section-fallback.tsx
|
|
122
|
+
const ConsumerFallback = ({ render, args, builtin }) => {
|
|
123
|
+
const node = render(args);
|
|
124
|
+
return node === void 0 ? builtin : /* @__PURE__ */ jsx(Fragment, { children: node });
|
|
125
|
+
};
|
|
126
|
+
const SectionFallback = ({ args, builtin }) => {
|
|
127
|
+
const render = useContext(SectionFallbackContext);
|
|
128
|
+
if (!render) return builtin;
|
|
129
|
+
return /* @__PURE__ */ jsx(ErrorBoundary, {
|
|
130
|
+
fallback: () => builtin,
|
|
131
|
+
children: /* @__PURE__ */ jsx(ConsumerFallback, {
|
|
132
|
+
render,
|
|
133
|
+
args,
|
|
134
|
+
builtin
|
|
135
|
+
})
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
//#endregion
|
|
139
|
+
//#region src/components/dnd/canvas/renderer.tsx
|
|
140
|
+
const Renderer = ({ preview, sectionId = "", sectionName = "", sectionCode = preview, forceFallback = false, headers, modules, frame, dynamicTailwind = false, provider }) => {
|
|
141
|
+
const module = useCompiledModule(forceFallback ? "" : preview, modules);
|
|
142
|
+
const section = {
|
|
143
|
+
id: sectionId,
|
|
144
|
+
name: sectionName,
|
|
145
|
+
code: sectionCode
|
|
146
|
+
};
|
|
147
|
+
const messages = useLiveMessages();
|
|
148
|
+
const { ref: wrapperRef, css: dynamicCSS } = useDynamicTailwind(preview, dynamicTailwind && !forceFallback);
|
|
149
|
+
const renderProvider = (component) => {
|
|
150
|
+
return provider ? provider(component) : component;
|
|
151
|
+
};
|
|
152
|
+
if (forceFallback) return /* @__PURE__ */ jsx(SectionFallback, {
|
|
153
|
+
args: {
|
|
154
|
+
section,
|
|
155
|
+
reason: "forced"
|
|
156
|
+
},
|
|
157
|
+
builtin: /* @__PURE__ */ jsx(Error$1, {
|
|
158
|
+
message: messages.errors.sectionNotRendered,
|
|
159
|
+
title: messages.errors.sectionUnavailable
|
|
160
|
+
})
|
|
161
|
+
});
|
|
162
|
+
if (module?.error) return /* @__PURE__ */ jsx(SectionFallback, {
|
|
163
|
+
args: {
|
|
164
|
+
section,
|
|
165
|
+
reason: "compile",
|
|
166
|
+
message: module.error
|
|
167
|
+
},
|
|
168
|
+
builtin: /* @__PURE__ */ jsx(Error$1, {
|
|
169
|
+
message: module.error,
|
|
170
|
+
title: messages.errors.compile
|
|
171
|
+
})
|
|
172
|
+
});
|
|
173
|
+
const Component = module?.exports?.default;
|
|
174
|
+
if (!Component) return null;
|
|
175
|
+
return /* @__PURE__ */ jsx(Frame, {
|
|
176
|
+
...frame,
|
|
177
|
+
autoHeight: true,
|
|
178
|
+
children: (container) => /* @__PURE__ */ jsx("div", {
|
|
179
|
+
ref: wrapperRef,
|
|
180
|
+
className: "w-full overflow-x-hidden",
|
|
181
|
+
"data-editor-mode": true,
|
|
182
|
+
children: /* @__PURE__ */ jsx(ErrorBoundary, {
|
|
183
|
+
resetKeys: [preview],
|
|
184
|
+
fallback: (message, reset) => /* @__PURE__ */ jsx(SectionFallback, {
|
|
185
|
+
args: {
|
|
186
|
+
section,
|
|
187
|
+
reason: "runtime",
|
|
188
|
+
message
|
|
189
|
+
},
|
|
190
|
+
builtin: /* @__PURE__ */ jsx(Error$1, {
|
|
191
|
+
message,
|
|
192
|
+
onReset: reset,
|
|
193
|
+
title: messages.errors.rendering
|
|
194
|
+
})
|
|
195
|
+
}),
|
|
196
|
+
children: renderProvider(/* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Component, {
|
|
197
|
+
headers,
|
|
198
|
+
container
|
|
199
|
+
}), dynamicTailwind && dynamicCSS && /* @__PURE__ */ jsx("style", { children: dynamicCSS })] }))
|
|
200
|
+
})
|
|
201
|
+
})
|
|
202
|
+
});
|
|
203
|
+
};
|
|
204
|
+
const sameValue = (a, b) => {
|
|
205
|
+
if (Object.is(a, b)) return true;
|
|
206
|
+
if (Array.isArray(a) && Array.isArray(b)) return a.length === b.length && a.every((item, i) => Object.is(item, b[i]));
|
|
207
|
+
if (a && b && typeof a === "object" && typeof b === "object" && Object.getPrototypeOf(a) === Object.prototype && Object.getPrototypeOf(b) === Object.prototype) {
|
|
208
|
+
const aKeys = Object.keys(a);
|
|
209
|
+
return aKeys.length === Object.keys(b).length && aKeys.every((key) => Object.is(a[key], b[key]));
|
|
210
|
+
}
|
|
211
|
+
return false;
|
|
212
|
+
};
|
|
213
|
+
const sameFrame = (a, b) => {
|
|
214
|
+
if (a === b) return true;
|
|
215
|
+
if (!a || !b) return false;
|
|
216
|
+
return [.../* @__PURE__ */ new Set([...Object.keys(a), ...Object.keys(b)])].every((key) => sameValue(a[key], b[key]));
|
|
217
|
+
};
|
|
218
|
+
const arePropsEqual = (prev, next) => {
|
|
219
|
+
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]));
|
|
220
|
+
};
|
|
221
|
+
var renderer_default = memo(Renderer, arePropsEqual);
|
|
222
|
+
//#endregion
|
|
223
|
+
//#region src/components/dnd/canvas/sortable.tsx
|
|
224
|
+
const NAVIGATION_KEYS = {
|
|
225
|
+
ArrowUp: "previous",
|
|
226
|
+
ArrowDown: "next",
|
|
227
|
+
Home: "first",
|
|
228
|
+
End: "last"
|
|
229
|
+
};
|
|
230
|
+
const Sortable = ({ id, children, selected, onClick, onDelete: _onDelete, onCopy: _onCopy, onMoveUp, onMoveDown, canMoveUp = false, canMoveDown = false, nodeRef, onNavigate, onDeleteKey, inspecting = false, onInspectMove, onInspectPick, onInspectLeave }) => {
|
|
231
|
+
const { attributes, listeners, setNodeRef, setActivatorNodeRef, transform, transition, isDragging, isOver, active } = useSortable({
|
|
232
|
+
id,
|
|
233
|
+
disabled: inspecting
|
|
234
|
+
});
|
|
235
|
+
const messages = useLiveMessages();
|
|
236
|
+
const style = {
|
|
237
|
+
transform: CSS$1.Transform.toString(transform),
|
|
238
|
+
transition,
|
|
239
|
+
opacity: isDragging ? .5 : 1,
|
|
240
|
+
cursor: inspecting ? "crosshair" : "grab"
|
|
241
|
+
};
|
|
242
|
+
const isPaletteSectionOver = isOver && !!paletteSectionOf(active?.data);
|
|
243
|
+
const onKeyDown = (e) => {
|
|
244
|
+
listeners?.onKeyDown?.(e);
|
|
245
|
+
if (e.target !== e.currentTarget || active || e.defaultPrevented) return;
|
|
246
|
+
if (e.key === "Enter") {
|
|
247
|
+
e.preventDefault();
|
|
248
|
+
onClick?.();
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
const to = NAVIGATION_KEYS[e.key];
|
|
252
|
+
if (to && onNavigate) {
|
|
253
|
+
e.preventDefault();
|
|
254
|
+
onNavigate(to);
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
if ((e.key === "Delete" || e.key === "Backspace") && onDeleteKey) {
|
|
258
|
+
e.preventDefault();
|
|
259
|
+
onDeleteKey();
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
const setRefs = (node) => {
|
|
263
|
+
setNodeRef(node);
|
|
264
|
+
setActivatorNodeRef(node);
|
|
265
|
+
nodeRef?.(node);
|
|
266
|
+
};
|
|
267
|
+
const onDelete = (e) => {
|
|
268
|
+
e.stopPropagation();
|
|
269
|
+
_onDelete?.(id);
|
|
270
|
+
};
|
|
271
|
+
const onCopy = (e) => {
|
|
272
|
+
e.stopPropagation();
|
|
273
|
+
_onCopy?.(id);
|
|
274
|
+
};
|
|
275
|
+
const press = (action) => (e) => {
|
|
276
|
+
e.stopPropagation();
|
|
277
|
+
action?.();
|
|
278
|
+
};
|
|
279
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
280
|
+
ref: setRefs,
|
|
281
|
+
style,
|
|
282
|
+
...attributes,
|
|
283
|
+
...listeners,
|
|
284
|
+
onKeyDown,
|
|
285
|
+
onClick,
|
|
286
|
+
className: cn("relative", selected && "z-10 outline-2 outline-offset-2 outline-blue-500", isPaletteSectionOver && "border-t-4 border-t-green-500"),
|
|
287
|
+
children: [
|
|
288
|
+
/* @__PURE__ */ jsx("div", {
|
|
289
|
+
className: cn("absolute inset-0 z-50"),
|
|
290
|
+
onPointerMove: inspecting ? (e) => onInspectMove?.(e.currentTarget.parentElement, e.currentTarget, e.clientX, e.clientY) : void 0,
|
|
291
|
+
onPointerLeave: inspecting ? onInspectLeave : void 0,
|
|
292
|
+
onClick: inspecting ? (e) => {
|
|
293
|
+
e.stopPropagation();
|
|
294
|
+
onInspectPick?.(e.currentTarget.parentElement, e.currentTarget, e.clientX, e.clientY);
|
|
295
|
+
} : void 0
|
|
296
|
+
}),
|
|
297
|
+
children,
|
|
298
|
+
selected && /* @__PURE__ */ jsxs(Space, {
|
|
299
|
+
className: cn("absolute top-1 right-1 z-60"),
|
|
300
|
+
children: [
|
|
301
|
+
onMoveUp && /* @__PURE__ */ jsx(Button, {
|
|
302
|
+
icon: /* @__PURE__ */ jsx(ChevronUp, {}),
|
|
303
|
+
disabled: !canMoveUp,
|
|
304
|
+
onClick: press(onMoveUp),
|
|
305
|
+
"aria-label": messages.section.moveUp
|
|
306
|
+
}),
|
|
307
|
+
onMoveDown && /* @__PURE__ */ jsx(Button, {
|
|
308
|
+
icon: /* @__PURE__ */ jsx(ChevronDown, {}),
|
|
309
|
+
disabled: !canMoveDown,
|
|
310
|
+
onClick: press(onMoveDown),
|
|
311
|
+
"aria-label": messages.section.moveDown
|
|
312
|
+
}),
|
|
313
|
+
/* @__PURE__ */ jsx(Button, {
|
|
314
|
+
icon: /* @__PURE__ */ jsx(Copy, {}),
|
|
315
|
+
onClick: onCopy,
|
|
316
|
+
"aria-label": messages.section.duplicate
|
|
317
|
+
}),
|
|
318
|
+
/* @__PURE__ */ jsx(Button, {
|
|
319
|
+
danger: true,
|
|
320
|
+
icon: /* @__PURE__ */ jsx(Trash, {}),
|
|
321
|
+
onClick: onDelete,
|
|
322
|
+
"aria-label": messages.section.delete
|
|
323
|
+
})
|
|
324
|
+
]
|
|
325
|
+
})
|
|
326
|
+
]
|
|
327
|
+
});
|
|
328
|
+
};
|
|
329
|
+
//#endregion
|
|
330
|
+
//#region src/components/dnd/canvas/overlay.tsx
|
|
331
|
+
const Overlay = ({ sections, isForced, renderProps }) => {
|
|
332
|
+
const { active } = useDndContext();
|
|
333
|
+
if (!active) return null;
|
|
334
|
+
const paletteSection = paletteSectionOf(active.data);
|
|
335
|
+
if (paletteSection) return /* @__PURE__ */ jsx(DefaultDraggableItem, { item: paletteSection });
|
|
336
|
+
const section = sections.find((s) => s.id === active.id);
|
|
337
|
+
if (section) {
|
|
338
|
+
const preview = generateSection(section.code, renderProps.fullCode, { containerId: renderProps.containerId });
|
|
339
|
+
return /* @__PURE__ */ jsx(Sortable, {
|
|
340
|
+
id: section.id,
|
|
341
|
+
name: section.name,
|
|
342
|
+
children: /* @__PURE__ */ jsx(renderer_default, {
|
|
343
|
+
preview,
|
|
344
|
+
sectionId: section.id,
|
|
345
|
+
sectionName: section.name,
|
|
346
|
+
sectionCode: section.code,
|
|
347
|
+
forceFallback: isForced?.(section) ?? false,
|
|
348
|
+
modules: renderProps.modules,
|
|
349
|
+
frame: renderProps.frame,
|
|
350
|
+
dynamicTailwind: renderProps.dynamicTailwind
|
|
351
|
+
})
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
return null;
|
|
355
|
+
};
|
|
356
|
+
//#endregion
|
|
46
357
|
//#region src/components/dnd/edit-options.ts
|
|
47
358
|
const toastEditError = (error) => {
|
|
48
359
|
Toast.error(error.title, error.description ? { description: error.description } : void 0);
|
|
@@ -94,72 +405,16 @@ const findElementById = (section, id) => {
|
|
|
94
405
|
const viewportRect = (element) => {
|
|
95
406
|
const rect = element.getBoundingClientRect();
|
|
96
407
|
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
|
-
});
|
|
408
|
+
let y = rect.top;
|
|
409
|
+
let frame = element.ownerDocument.defaultView?.frameElement ?? null;
|
|
410
|
+
while (frame) {
|
|
411
|
+
const frameRect = frame.getBoundingClientRect();
|
|
412
|
+
x += frameRect.left;
|
|
413
|
+
y += frameRect.top;
|
|
414
|
+
frame = frame.ownerDocument.defaultView?.frameElement ?? null;
|
|
415
|
+
}
|
|
416
|
+
return new DOMRect(x, y, rect.width, rect.height);
|
|
417
|
+
};
|
|
163
418
|
//#endregion
|
|
164
419
|
//#region src/components/dnd/layout-context.ts
|
|
165
420
|
const DndRegionContext = createContext(null);
|
|
@@ -679,8 +934,8 @@ const parseSource = (value, bindingOptions) => {
|
|
|
679
934
|
const objectItems = [];
|
|
680
935
|
const primitiveItems = [];
|
|
681
936
|
ast.elements.forEach((element, elementIndex) => {
|
|
682
|
-
if (!
|
|
683
|
-
if (!
|
|
937
|
+
if (!isExpression(element)) return;
|
|
938
|
+
if (!isObjectExpression(element)) {
|
|
684
939
|
const extracted = extractNodeValue(element);
|
|
685
940
|
primitiveItems.push({
|
|
686
941
|
id: nanoid(6),
|
|
@@ -695,7 +950,7 @@ const parseSource = (value, bindingOptions) => {
|
|
|
695
950
|
const jsxBindings = {};
|
|
696
951
|
const jsxFallbacks = {};
|
|
697
952
|
element.properties.forEach((prop) => {
|
|
698
|
-
if (!
|
|
953
|
+
if (!isObjectProperty(prop) || !isIdentifier(prop.key) || !(isJSXElement(prop.value) || isJSXFragment(prop.value))) return;
|
|
699
954
|
const propertyName = prop.key.name;
|
|
700
955
|
try {
|
|
701
956
|
const found = bindingsInJSX(value.slice(prop.value.start, prop.value.end), bindingOptions);
|
|
@@ -885,7 +1140,7 @@ const useDndItems = (value, { render, onChange, onNodeChange } = {}) => {
|
|
|
885
1140
|
commit(snapshot, null, void 0, snapshot.selected);
|
|
886
1141
|
return;
|
|
887
1142
|
}
|
|
888
|
-
const visible = parseArrayExpression(result.code)?.elements.flatMap((node, index) =>
|
|
1143
|
+
const visible = parseArrayExpression(result.code)?.elements.flatMap((node, index) => isExpression(node) && isObjectExpression(node) === !isPrimitive ? [index] : []) ?? [];
|
|
889
1144
|
commit(snapshot, result.code, nextIdentity.items, new Set(visible.flatMap((position, index) => result.indices.has(position) ? [index] : [])));
|
|
890
1145
|
},
|
|
891
1146
|
removeSelected: () => {
|
|
@@ -1733,248 +1988,7 @@ const Layout = ({ palette, panel }) => {
|
|
|
1733
1988
|
] });
|
|
1734
1989
|
};
|
|
1735
1990
|
//#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
|
|
1991
|
+
//#region src/components/dnd/state/use-delete-flow.ts
|
|
1978
1992
|
const useDeleteFlow = ({ sections, remove, onBeforeDelete }) => {
|
|
1979
1993
|
const removeRef = useRef(remove);
|
|
1980
1994
|
useEffect(() => {
|
|
@@ -2008,7 +2022,7 @@ const useDeleteFlow = ({ sections, remove, onBeforeDelete }) => {
|
|
|
2008
2022
|
};
|
|
2009
2023
|
};
|
|
2010
2024
|
//#endregion
|
|
2011
|
-
//#region src/components/dnd/use-dnd-keyboard.ts
|
|
2025
|
+
//#region src/components/dnd/state/use-dnd-keyboard.ts
|
|
2012
2026
|
const KEYBOARD_CODES = {
|
|
2013
2027
|
start: ["Space"],
|
|
2014
2028
|
cancel: ["Escape"],
|
|
@@ -2042,7 +2056,7 @@ const useDndKeyboard = ({ sections, selectedId, selectedIndex, selectOnly, move,
|
|
|
2042
2056
|
keyboardCodes: KEYBOARD_CODES
|
|
2043
2057
|
}));
|
|
2044
2058
|
const nameOf = (id, data) => {
|
|
2045
|
-
return (data
|
|
2059
|
+
return paletteSectionOf(data)?.name ?? sections.find((section) => section.id === id)?.name ?? say.section;
|
|
2046
2060
|
};
|
|
2047
2061
|
const positionOf = (id) => sections.findIndex((section) => section.id === id) + 1;
|
|
2048
2062
|
const announcements = {
|
|
@@ -2095,7 +2109,7 @@ const useDndKeyboard = ({ sections, selectedId, selectedIndex, selectOnly, move,
|
|
|
2095
2109
|
};
|
|
2096
2110
|
};
|
|
2097
2111
|
//#endregion
|
|
2098
|
-
//#region src/components/dnd/use-inspector-state.ts
|
|
2112
|
+
//#region src/components/dnd/state/use-inspector-state.ts
|
|
2099
2113
|
const useInspectorState = ({ selectedId, selectOnly, sectionNodes, onNodePick }) => {
|
|
2100
2114
|
const [inspecting, setInspecting] = useState(false);
|
|
2101
2115
|
const [picked, setPicked] = useState(null);
|
|
@@ -2173,7 +2187,7 @@ const useInspectorState = ({ selectedId, selectOnly, sectionNodes, onNodePick })
|
|
|
2173
2187
|
};
|
|
2174
2188
|
};
|
|
2175
2189
|
//#endregion
|
|
2176
|
-
//#region src/components/dnd/use-section-document.ts
|
|
2190
|
+
//#region src/components/dnd/state/use-section-document.ts
|
|
2177
2191
|
const createLastParsed = () => {
|
|
2178
2192
|
let last = null;
|
|
2179
2193
|
return {
|
|
@@ -2226,7 +2240,7 @@ const useSectionDocument = (value, onChange, { containerId, sectionNameFallback,
|
|
|
2226
2240
|
view.document
|
|
2227
2241
|
]);
|
|
2228
2242
|
const selectedIndex = sections.findIndex((s) => s.id === selectedId);
|
|
2229
|
-
const
|
|
2243
|
+
const selectedSection = selectedIndex >= 0 ? sections[selectedIndex] : void 0;
|
|
2230
2244
|
const pendingRef = useRef(null);
|
|
2231
2245
|
useEffect(() => {
|
|
2232
2246
|
pendingRef.current = null;
|
|
@@ -2272,17 +2286,17 @@ const useSectionDocument = (value, onChange, { containerId, sectionNameFallback,
|
|
|
2272
2286
|
sections,
|
|
2273
2287
|
previews,
|
|
2274
2288
|
selectedId,
|
|
2275
|
-
|
|
2289
|
+
selectedSection,
|
|
2276
2290
|
selectedIndex,
|
|
2277
2291
|
select: useCallback((id) => {
|
|
2278
2292
|
setSelectedId((prev) => prev === id ? null : id);
|
|
2279
2293
|
}, []),
|
|
2280
2294
|
selectOnly: useCallback((id) => setSelectedId(id), []),
|
|
2281
2295
|
clearSelection: useCallback(() => setSelectedId(null), []),
|
|
2282
|
-
add: useCallback((
|
|
2296
|
+
add: useCallback((section, atIndex) => {
|
|
2283
2297
|
if (refuse()) return;
|
|
2284
2298
|
const current = latestSections();
|
|
2285
|
-
const next = { code:
|
|
2299
|
+
const next = { code: section.code };
|
|
2286
2300
|
commit(atIndex === void 0 || atIndex < 0 ? [...current, next] : [
|
|
2287
2301
|
...current.slice(0, atIndex),
|
|
2288
2302
|
next,
|
|
@@ -2403,6 +2417,10 @@ const describeUpdateFailure = (failure, label, { editErrors: m }) => {
|
|
|
2403
2417
|
title: m.updateFailed(label),
|
|
2404
2418
|
description: m.elementNotFound
|
|
2405
2419
|
};
|
|
2420
|
+
case "self-closing": return {
|
|
2421
|
+
title: m.cannotEdit(label),
|
|
2422
|
+
description: m.selfClosing(failure.property)
|
|
2423
|
+
};
|
|
2406
2424
|
case "unsupported-syntax": return {
|
|
2407
2425
|
title: m.cannotEdit(label),
|
|
2408
2426
|
description: m.unsupportedSyntax(failure.property)
|
|
@@ -2424,7 +2442,7 @@ const blockedEditError = (error, { editErrors: m }) => ({
|
|
|
2424
2442
|
});
|
|
2425
2443
|
const conditionalModifiers = (args) => {
|
|
2426
2444
|
const { active } = args;
|
|
2427
|
-
if (active?.data
|
|
2445
|
+
if (paletteSectionOf(active?.data)) return args.transform;
|
|
2428
2446
|
return restrictToVerticalAxis(args);
|
|
2429
2447
|
};
|
|
2430
2448
|
const NO_MODULES = {};
|
|
@@ -2454,7 +2472,7 @@ const Dnd$1 = ({ value: _value, props, modules: _modules = NO_MODULES, onChange:
|
|
|
2454
2472
|
const onBlockedEdit = useCallback((problem) => {
|
|
2455
2473
|
if (problem.reason === "parse-error") reportErrorRef.current(blockedEditError(problem.error, messagesRef.current));
|
|
2456
2474
|
}, []);
|
|
2457
|
-
const { sections, previews, selectedId,
|
|
2475
|
+
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
2476
|
containerId,
|
|
2459
2477
|
sectionNameFallback,
|
|
2460
2478
|
onBlockedEdit
|
|
@@ -2463,10 +2481,10 @@ const Dnd$1 = ({ value: _value, props, modules: _modules = NO_MODULES, onChange:
|
|
|
2463
2481
|
const onDragEnd = (event) => {
|
|
2464
2482
|
const { active, over } = event;
|
|
2465
2483
|
if (!over) return;
|
|
2466
|
-
|
|
2467
|
-
|
|
2484
|
+
const section = paletteSectionOf(active.data);
|
|
2485
|
+
if (section) {
|
|
2468
2486
|
const atBottom = over.id === "sortable-area" || over.id === "sortable-area-bottom";
|
|
2469
|
-
|
|
2487
|
+
addSection(section, atBottom ? void 0 : sections.findIndex((s) => s.id === over.id));
|
|
2470
2488
|
return;
|
|
2471
2489
|
}
|
|
2472
2490
|
if (active.id !== over.id && sections.some((s) => s.id === active.id)) reorder(String(active.id), String(over.id));
|
|
@@ -2500,8 +2518,8 @@ const Dnd$1 = ({ value: _value, props, modules: _modules = NO_MODULES, onChange:
|
|
|
2500
2518
|
bindings: bindingRegistry,
|
|
2501
2519
|
bindingKeys
|
|
2502
2520
|
}), [bindingRegistry, bindingKeys]);
|
|
2503
|
-
const selectedCode =
|
|
2504
|
-
const selectedSectionId =
|
|
2521
|
+
const selectedCode = selectedSection?.code;
|
|
2522
|
+
const selectedSectionId = selectedSection?.id;
|
|
2505
2523
|
const { fields, updatedCode, parseError } = useMemo(() => {
|
|
2506
2524
|
if (!selectedCode) return {
|
|
2507
2525
|
fields: [],
|
|
@@ -2553,7 +2571,7 @@ const Dnd$1 = ({ value: _value, props, modules: _modules = NO_MODULES, onChange:
|
|
|
2553
2571
|
reportError(blockedEditError(problem.error, messages));
|
|
2554
2572
|
return;
|
|
2555
2573
|
}
|
|
2556
|
-
const committed =
|
|
2574
|
+
const committed = selectedSection && getCommittedSection(selectedSection.id)?.code;
|
|
2557
2575
|
const result = updateAll(committed && committed !== selectedCode ? committed : updatedCode, changes.map(({ id, label, property, value: changeValue }) => ({
|
|
2558
2576
|
dataId: id,
|
|
2559
2577
|
label,
|
|
@@ -2572,8 +2590,8 @@ const Dnd$1 = ({ value: _value, props, modules: _modules = NO_MODULES, onChange:
|
|
|
2572
2590
|
});
|
|
2573
2591
|
return;
|
|
2574
2592
|
}
|
|
2575
|
-
if (
|
|
2576
|
-
...
|
|
2593
|
+
if (selectedSection) onChange({
|
|
2594
|
+
...selectedSection,
|
|
2577
2595
|
code: result.code
|
|
2578
2596
|
});
|
|
2579
2597
|
};
|
|
@@ -2584,14 +2602,14 @@ const Dnd$1 = ({ value: _value, props, modules: _modules = NO_MODULES, onChange:
|
|
|
2584
2602
|
if (frame?.scripts?.length) preloadScripts(frame.scripts);
|
|
2585
2603
|
}, [frame?.scripts]);
|
|
2586
2604
|
const palette = {
|
|
2587
|
-
items: items?.length ? items :
|
|
2588
|
-
onAdd: (
|
|
2589
|
-
|
|
2605
|
+
items: items?.length ? items : PALETTE_SECTIONS,
|
|
2606
|
+
onAdd: (section) => {
|
|
2607
|
+
addSection(section);
|
|
2590
2608
|
setMobilePaletteOpen(false);
|
|
2591
2609
|
}
|
|
2592
2610
|
};
|
|
2593
2611
|
const panel = {
|
|
2594
|
-
item:
|
|
2612
|
+
item: selectedSection,
|
|
2595
2613
|
onChange,
|
|
2596
2614
|
onDelete,
|
|
2597
2615
|
onMoveUp: () => moveSection(selectedId, "up"),
|
|
@@ -2604,63 +2622,67 @@ const Dnd$1 = ({ value: _value, props, modules: _modules = NO_MODULES, onChange:
|
|
|
2604
2622
|
readOnly: stale,
|
|
2605
2623
|
bindingOptions
|
|
2606
2624
|
};
|
|
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
|
|
2625
|
+
const canvas = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2626
|
+
stale && /* @__PURE__ */ jsx("div", {
|
|
2627
|
+
role: "status",
|
|
2628
|
+
className: cn("sticky top-0 z-70", "border-b border-amber-200 bg-amber-50 px-3 py-2", "text-sm text-amber-900"),
|
|
2629
|
+
children: messages.canvas.stale
|
|
2630
|
+
}),
|
|
2631
|
+
/* @__PURE__ */ jsx(Droppable, {
|
|
2632
|
+
className: cn(!sections.length && "h-full"),
|
|
2633
|
+
children: !sections.length ? /* @__PURE__ */ jsx("div", {
|
|
2634
|
+
className: cn("flex items-center justify-center", "h-full", "text-gray-500"),
|
|
2635
|
+
children: problem?.reason === "parse-error" ? /* @__PURE__ */ jsxs(Space, {
|
|
2636
|
+
orientation: "vertical",
|
|
2637
|
+
align: "center",
|
|
2638
|
+
children: [/* @__PURE__ */ jsx(Typography.Paragraph, { children: messages.canvas.syntaxError }), /* @__PURE__ */ jsx(Typography.Text, { children: messages.canvas.syntaxErrorDetail })]
|
|
2639
|
+
}) : missingContainer !== null ? /* @__PURE__ */ jsxs(Space, {
|
|
2640
|
+
orientation: "vertical",
|
|
2641
|
+
align: "center",
|
|
2642
|
+
children: [/* @__PURE__ */ jsx(Typography.Paragraph, { children: messages.canvas.missingContainer(missingContainer) }), /* @__PURE__ */ jsx(Typography.Text, { children: messages.canvas.missingContainerDetail(missingContainer) })]
|
|
2643
|
+
}) : /* @__PURE__ */ jsxs(Space, {
|
|
2644
|
+
orientation: "vertical",
|
|
2645
|
+
align: "center",
|
|
2646
|
+
children: [/* @__PURE__ */ jsx(Typography.Paragraph, { children: messages.canvas.empty }), /* @__PURE__ */ jsx(Typography.Text, { children: isMobile ? messages.canvas.emptyHintTouch : messages.canvas.emptyHintDrag })]
|
|
2660
2647
|
})
|
|
2661
|
-
},
|
|
2662
|
-
|
|
2663
|
-
|
|
2648
|
+
}) : /* @__PURE__ */ jsx(SortableContext, {
|
|
2649
|
+
items: sections.map((s) => s.id),
|
|
2650
|
+
strategy: verticalListSortingStrategy,
|
|
2651
|
+
children: sections.map((section, index) => /* @__PURE__ */ jsx(Sortable, {
|
|
2652
|
+
id: section.id,
|
|
2653
|
+
name: section.name,
|
|
2654
|
+
selected: selectedId === section.id,
|
|
2655
|
+
onClick: () => onSelect(section.id),
|
|
2656
|
+
onDelete,
|
|
2657
|
+
onCopy,
|
|
2658
|
+
onMoveUp: () => onMoveButton(section.id, "up"),
|
|
2659
|
+
onMoveDown: () => onMoveButton(section.id, "down"),
|
|
2660
|
+
canMoveUp: index > 0,
|
|
2661
|
+
canMoveDown: index < sections.length - 1,
|
|
2662
|
+
nodeRef: sectionNodes.register(section.id),
|
|
2663
|
+
onNavigate: (to) => onNavigate(section.id, to),
|
|
2664
|
+
onDeleteKey: () => onDeleteKey(section.id),
|
|
2665
|
+
inspecting,
|
|
2666
|
+
onInspectMove,
|
|
2667
|
+
onInspectPick: (...args) => onInspectPick(section.id, ...args),
|
|
2668
|
+
onInspectLeave,
|
|
2669
|
+
children: /* @__PURE__ */ jsx(renderer_default, {
|
|
2670
|
+
preview: previews[index],
|
|
2671
|
+
sectionId: section.id,
|
|
2672
|
+
sectionName: section.name,
|
|
2673
|
+
sectionCode: section.code,
|
|
2674
|
+
forceFallback: isForced(section),
|
|
2675
|
+
modules,
|
|
2676
|
+
frame,
|
|
2677
|
+
dynamicTailwind,
|
|
2678
|
+
provider,
|
|
2679
|
+
...props
|
|
2680
|
+
})
|
|
2681
|
+
}, section.id))
|
|
2682
|
+
})
|
|
2683
|
+
}),
|
|
2684
|
+
/* @__PURE__ */ jsx(InspectorHighlight, { rect: highlightRect })
|
|
2685
|
+
] });
|
|
2664
2686
|
return /* @__PURE__ */ jsx(SectionFallbackContext.Provider, {
|
|
2665
2687
|
value: renderSectionFallback,
|
|
2666
2688
|
children: /* @__PURE__ */ jsxs(DndContext, {
|
|
@@ -2675,13 +2697,13 @@ const Dnd$1 = ({ value: _value, props, modules: _modules = NO_MODULES, onChange:
|
|
|
2675
2697
|
children: [/* @__PURE__ */ jsx("div", {
|
|
2676
2698
|
className: cn("relative flex h-full w-full", className),
|
|
2677
2699
|
...restProps,
|
|
2678
|
-
children: /* @__PURE__ */
|
|
2700
|
+
children: /* @__PURE__ */ jsx(DndEditOptionsContext.Provider, {
|
|
2679
2701
|
value: {
|
|
2680
2702
|
renderField,
|
|
2681
2703
|
reportError,
|
|
2682
2704
|
bindingOptions
|
|
2683
2705
|
},
|
|
2684
|
-
children:
|
|
2706
|
+
children: /* @__PURE__ */ jsx(DndRegionContext.Provider, {
|
|
2685
2707
|
value: {
|
|
2686
2708
|
palette,
|
|
2687
2709
|
panel,
|
|
@@ -2697,7 +2719,7 @@ const Dnd$1 = ({ value: _value, props, modules: _modules = NO_MODULES, onChange:
|
|
|
2697
2719
|
value: inspector,
|
|
2698
2720
|
children: Children.toArray(children).length ? children : /* @__PURE__ */ jsx(Layout, {})
|
|
2699
2721
|
})
|
|
2700
|
-
})
|
|
2722
|
+
})
|
|
2701
2723
|
})
|
|
2702
2724
|
}), /* @__PURE__ */ jsx(DragOverlay, { children: /* @__PURE__ */ jsx(Overlay, {
|
|
2703
2725
|
sections,
|
|
@@ -2728,6 +2750,6 @@ const useItemsEditor = useDndItems;
|
|
|
2728
2750
|
/** @deprecated Renamed to `useDndChildren`. */
|
|
2729
2751
|
const useChildrenEditor = useDndChildren;
|
|
2730
2752
|
//#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,
|
|
2753
|
+
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
2754
|
|
|
2733
|
-
//# sourceMappingURL=dnd-
|
|
2755
|
+
//# sourceMappingURL=dnd-V8NAxd_R.js.map
|