@jbpark/live-editor 2.2.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{ast-CAhr9WXv.js → ast-DRg6HV4H.js} +2 -2
- package/dist/ast-DRg6HV4H.js.map +1 -0
- package/dist/{boundary-DQiKrXhI.js → boundary-BF7iZp6e.js} +2 -2
- package/dist/{boundary-DQiKrXhI.js.map → boundary-BF7iZp6e.js.map} +1 -1
- package/dist/{context-CJ0_ptf4.js → context-DH70wj9d.js} +3 -3
- package/dist/{context-CJ0_ptf4.js.map → context-DH70wj9d.js.map} +1 -1
- package/dist/{core-D5Hn-6ow.js → core-CbuS_p_d.js} +2 -2
- package/dist/{core-D5Hn-6ow.js.map → core-CbuS_p_d.js.map} +1 -1
- package/dist/dnd/index.d.ts +2 -2
- package/dist/dnd/index.js +2 -2
- package/dist/{dnd-DRivgZdt.js → dnd-Bl_oqayG.js} +311 -269
- package/dist/dnd-Bl_oqayG.js.map +1 -0
- package/dist/{document-CgUTKVQo.js → document-C6bNHl7l.js} +2 -2
- package/dist/document-C6bNHl7l.js.map +1 -0
- package/dist/editor/index.js +2 -2
- package/dist/{editor-Ds-mUYs_.js → editor-Ct9wuhLm.js} +3 -3
- package/dist/{editor-Ds-mUYs_.js.map → editor-Ct9wuhLm.js.map} +1 -1
- package/dist/error/index.js +2 -2
- package/dist/{error-B5MciRP7.js → error-lsJey-it.js} +2 -2
- package/dist/{error-B5MciRP7.js.map → error-lsJey-it.js.map} +1 -1
- package/dist/{index-DYm4nsej.d.ts → index-Bqc5kUAG.d.ts} +45 -35
- package/dist/index.d.ts +7 -4
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/preview/index.js +1 -1
- package/dist/{preview-DtBbnlwy.js → preview-CNVXyDgY.js} +4 -4
- package/dist/{preview-DtBbnlwy.js.map → preview-CNVXyDgY.js.map} +1 -1
- package/dist/provider/index.js +1 -1
- package/dist/{use-dynamic-tailwind-cdaivJXJ.js → use-dynamic-tailwind-C0Onss1A.js} +2 -2
- package/dist/use-dynamic-tailwind-C0Onss1A.js.map +1 -0
- package/dist/utils/ast/index.js +2 -2
- package/dist/utils/index.js +2 -2
- package/dist/{utils-DbfbS1yV.js → utils-BwEgY5pe.js} +2 -2
- package/dist/{utils-DbfbS1yV.js.map → utils-BwEgY5pe.js.map} +1 -1
- package/package.json +1 -1
- package/dist/ast-CAhr9WXv.js.map +0 -1
- package/dist/dnd-DRivgZdt.js.map +0 -1
- package/dist/document-CgUTKVQo.js.map +0 -1
- package/dist/use-dynamic-tailwind-cdaivJXJ.js.map +0 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { C as __toESM, b as DRAGGABLE_ITEMS, f as nanoid, g as BINDING_PROP, m as require_lib, n as createSectionPreviewCache, r as fillSectionIds, y as DEFAULT_TEMPLATE } from "./document-
|
|
2
|
-
import { d as replaceSections, o as extractSections, r as cn, s as generateSection, u as preloadScripts } from "./utils-
|
|
1
|
+
import { C as __toESM, b as DRAGGABLE_ITEMS, f as nanoid, g as BINDING_PROP, m as require_lib, n as createSectionPreviewCache, r as fillSectionIds, y as DEFAULT_TEMPLATE } from "./document-C6bNHl7l.js";
|
|
2
|
+
import { d as replaceSections, o as extractSections, r as cn, s as generateSection, u as preloadScripts } from "./utils-BwEgY5pe.js";
|
|
3
3
|
import { i as usePreview } from "./states-Ci1AvoQ9.js";
|
|
4
|
-
import { A as parseValue, D as extractObjectProperties, E as extractNodeValue, M as generateCode, S as parseBinding, _ as moveSelectedIndices, a as extract, b as getCurrentValue, c as moveArrayItem, d as removeArrayItems, f as updateArrayItemProperty, g as replaceIds, h as fillIds, k as parseArrayExpression, l as moveArrayItems, o as appendArrayItem, p as updateArrayItemValue, r as update, s as duplicateArrayItems, t as validateBindingValue, v as removeIndices, x as getStructuredValue, y as findEditableChildren } from "./ast-
|
|
5
|
-
import { n as useCompiledModule, r as Frame, t as useDynamicTailwind } from "./use-dynamic-tailwind-
|
|
6
|
-
import {
|
|
7
|
-
import { t as
|
|
8
|
-
import { memo, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
4
|
+
import { A as parseValue, D as extractObjectProperties, E as extractNodeValue, M as generateCode, S as parseBinding, _ as moveSelectedIndices, a as extract, b as getCurrentValue, c as moveArrayItem, d as removeArrayItems, f as updateArrayItemProperty, g as replaceIds, h as fillIds, k as parseArrayExpression, l as moveArrayItems, o as appendArrayItem, p as updateArrayItemValue, r as update, s as duplicateArrayItems, t as validateBindingValue, v as removeIndices, x as getStructuredValue, y as findEditableChildren } from "./ast-DRg6HV4H.js";
|
|
5
|
+
import { n as useCompiledModule, r as Frame, t as useDynamicTailwind } from "./use-dynamic-tailwind-C0Onss1A.js";
|
|
6
|
+
import { t as Core } from "./core-CbuS_p_d.js";
|
|
7
|
+
import { n as Error$1, t as ErrorBoundary } from "./boundary-BF7iZp6e.js";
|
|
8
|
+
import { Children, createContext, memo, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
9
9
|
import { Button, Card, Checkbox, ColorPicker, DatePicker, Drawer, Input, RichTextEditor, Select, Space, Splitter, Toast, Typography, Upload } from "@jbpark/ui-kit";
|
|
10
10
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
11
11
|
import { DndContext, DragOverlay, PointerSensor, closestCenter, useDndContext, useDraggable, useDroppable, useSensor, useSensors } from "@dnd-kit/core";
|
|
@@ -14,6 +14,28 @@ import { SortableContext, arrayMove, useSortable, verticalListSortingStrategy }
|
|
|
14
14
|
import { useDebounce, useMultiSelect, useResponsiveSize } from "@jbpark/use-hooks";
|
|
15
15
|
import { AlertCircle, ArrowDown, ArrowLeft, ArrowRight, ArrowUp, Bell, Bookmark, Calendar, Camera, Check, ChevronDown, ChevronRight, ChevronUp, Clock, Copy, Download, Edit, Eye, Filter, Heart, Home, Image, Info, LayoutGrid, Link, Mail, Map as Map$1, Menu, MessageCircle, Phone, Plus, Search, Settings, Share, ShoppingCart, Star, Trash, Upload as Upload$1, User, X } from "lucide-react";
|
|
16
16
|
import { CSS } from "@dnd-kit/utilities";
|
|
17
|
+
//#region src/components/dnd/droppable.tsx
|
|
18
|
+
var import_lib = /* @__PURE__ */ __toESM(require_lib(), 1);
|
|
19
|
+
const Droppable = ({ children, className }) => {
|
|
20
|
+
const { setNodeRef, isOver, active } = useDroppable({ id: "sortable-area" });
|
|
21
|
+
const { setNodeRef: setBottomRef, isOver: isBottomOver } = useDroppable({ id: "sortable-area-bottom" });
|
|
22
|
+
const isNewItemDragging = active?.data.current?.type === "new-item";
|
|
23
|
+
const shouldHighlight = isOver && isNewItemDragging;
|
|
24
|
+
const shouldHighlightBottom = isBottomOver && isNewItemDragging;
|
|
25
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
26
|
+
ref: setNodeRef,
|
|
27
|
+
className: cn("min-h-full", "border-2 border-dashed p-1", shouldHighlight ? "border-blue-300 bg-blue-50" : "border-gray-200", className),
|
|
28
|
+
children: [children, isNewItemDragging && /* @__PURE__ */ jsx("div", {
|
|
29
|
+
ref: setBottomRef,
|
|
30
|
+
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"),
|
|
31
|
+
children: /* @__PURE__ */ jsx(Typography.Text, {
|
|
32
|
+
className: "text-sm text-gray-500",
|
|
33
|
+
children: shouldHighlightBottom ? "Drop here" : "Drag here to add at bottom"
|
|
34
|
+
})
|
|
35
|
+
})]
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
//#endregion
|
|
17
39
|
//#region src/components/dnd/draggable.tsx
|
|
18
40
|
const DraggableItem = ({ item, children }) => {
|
|
19
41
|
const { attributes, listeners, setNodeRef, isDragging } = useDraggable({
|
|
@@ -45,129 +67,18 @@ const DefaultDraggableItem = ({ item, onAdd, tapToAdd = false }) => /* @__PURE__
|
|
|
45
67
|
})
|
|
46
68
|
});
|
|
47
69
|
//#endregion
|
|
48
|
-
//#region src/components/dnd/
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const shouldHighlightBottom = isBottomOver && isNewItemDragging;
|
|
55
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
56
|
-
ref: setNodeRef,
|
|
57
|
-
className: cn("min-h-full", "border-2 border-dashed p-1", shouldHighlight ? "border-blue-300 bg-blue-50" : "border-gray-200", className),
|
|
58
|
-
children: [children, isNewItemDragging && /* @__PURE__ */ jsx("div", {
|
|
59
|
-
ref: setBottomRef,
|
|
60
|
-
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"),
|
|
61
|
-
children: /* @__PURE__ */ jsx(Typography.Text, {
|
|
62
|
-
className: "text-sm text-gray-500",
|
|
63
|
-
children: shouldHighlightBottom ? "Drop here" : "Drag here to add at bottom"
|
|
64
|
-
})
|
|
65
|
-
})]
|
|
66
|
-
});
|
|
67
|
-
};
|
|
68
|
-
//#endregion
|
|
69
|
-
//#region src/components/dnd/renderer.tsx
|
|
70
|
-
const Renderer = ({ preview, headers, modules, frame, dynamicTailwind = false, provider }) => {
|
|
71
|
-
const module = useCompiledModule(preview, modules);
|
|
72
|
-
const { ref: wrapperRef, css: dynamicCSS } = useDynamicTailwind(preview, dynamicTailwind);
|
|
73
|
-
const renderProvider = (component) => {
|
|
74
|
-
return provider ? provider(component) : component;
|
|
75
|
-
};
|
|
76
|
-
if (module?.error) return /* @__PURE__ */ jsx(Error, {
|
|
77
|
-
message: module.error,
|
|
78
|
-
title: "Compile Error"
|
|
79
|
-
});
|
|
80
|
-
const Component = module?.exports?.default;
|
|
81
|
-
if (!Component) return null;
|
|
82
|
-
return /* @__PURE__ */ jsx(Frame, {
|
|
83
|
-
...frame,
|
|
84
|
-
autoHeight: true,
|
|
85
|
-
children: (container) => /* @__PURE__ */ jsx("div", {
|
|
86
|
-
ref: wrapperRef,
|
|
87
|
-
className: "w-full overflow-x-hidden",
|
|
88
|
-
"data-editor-mode": true,
|
|
89
|
-
children: /* @__PURE__ */ jsx(ErrorBoundary, {
|
|
90
|
-
resetKeys: [preview],
|
|
91
|
-
children: renderProvider(/* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Component, {
|
|
92
|
-
headers,
|
|
93
|
-
container
|
|
94
|
-
}), dynamicTailwind && dynamicCSS && /* @__PURE__ */ jsx("style", { children: dynamicCSS })] }))
|
|
95
|
-
})
|
|
96
|
-
})
|
|
97
|
-
});
|
|
98
|
-
};
|
|
99
|
-
var renderer_default = memo(Renderer);
|
|
100
|
-
//#endregion
|
|
101
|
-
//#region src/components/dnd/sortable.tsx
|
|
102
|
-
const Sortable = ({ id, children, selected, onClick, onDelete: _onDelete, onCopy: _onCopy }) => {
|
|
103
|
-
const { attributes, listeners, setNodeRef, transform, transition, isDragging, isOver, active } = useSortable({ id });
|
|
104
|
-
const style = {
|
|
105
|
-
transform: CSS.Transform.toString(transform),
|
|
106
|
-
transition,
|
|
107
|
-
opacity: isDragging ? .5 : 1,
|
|
108
|
-
cursor: "grab"
|
|
109
|
-
};
|
|
110
|
-
const isNewItemOver = isOver && active?.data.current?.type === "new-item";
|
|
111
|
-
const onDelete = (e) => {
|
|
112
|
-
e.stopPropagation();
|
|
113
|
-
_onDelete?.(id);
|
|
114
|
-
};
|
|
115
|
-
const onCopy = (e) => {
|
|
116
|
-
e.stopPropagation();
|
|
117
|
-
_onCopy?.(id);
|
|
118
|
-
};
|
|
119
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
120
|
-
ref: setNodeRef,
|
|
121
|
-
style,
|
|
122
|
-
...attributes,
|
|
123
|
-
...listeners,
|
|
124
|
-
onClick,
|
|
125
|
-
className: cn("relative", selected && "z-10 outline-2 outline-offset-2 outline-blue-500", isNewItemOver && "border-t-4 border-t-green-500"),
|
|
126
|
-
children: [
|
|
127
|
-
/* @__PURE__ */ jsx("div", { className: cn("absolute inset-0 z-50") }),
|
|
128
|
-
children,
|
|
129
|
-
selected && /* @__PURE__ */ jsxs(Space, {
|
|
130
|
-
className: cn("absolute top-1 right-1 z-60"),
|
|
131
|
-
children: [/* @__PURE__ */ jsx(Button, {
|
|
132
|
-
icon: /* @__PURE__ */ jsx(Copy, {}),
|
|
133
|
-
onClick: onCopy
|
|
134
|
-
}), /* @__PURE__ */ jsx(Button, {
|
|
135
|
-
danger: true,
|
|
136
|
-
icon: /* @__PURE__ */ jsx(Trash, {}),
|
|
137
|
-
onClick: onDelete
|
|
138
|
-
})]
|
|
139
|
-
})
|
|
140
|
-
]
|
|
141
|
-
});
|
|
142
|
-
};
|
|
143
|
-
//#endregion
|
|
144
|
-
//#region src/components/dnd/overlay.tsx
|
|
145
|
-
const Overlay = ({ sections, renderProps }) => {
|
|
146
|
-
const { active } = useDndContext();
|
|
147
|
-
if (!active) return null;
|
|
148
|
-
if (active.data.current?.type === "new-item") {
|
|
149
|
-
const item = active.data.current.item;
|
|
150
|
-
return /* @__PURE__ */ jsx(DefaultDraggableItem, { item });
|
|
151
|
-
}
|
|
152
|
-
const section = sections.find((s) => s.id === active.id);
|
|
153
|
-
if (section) {
|
|
154
|
-
const preview = generateSection(section.code, renderProps.fullCode);
|
|
155
|
-
return /* @__PURE__ */ jsx(Sortable, {
|
|
156
|
-
id: section.id,
|
|
157
|
-
name: section.name,
|
|
158
|
-
children: /* @__PURE__ */ jsx(renderer_default, {
|
|
159
|
-
preview,
|
|
160
|
-
modules: renderProps.modules,
|
|
161
|
-
frame: renderProps.frame,
|
|
162
|
-
dynamicTailwind: renderProps.dynamicTailwind
|
|
163
|
-
})
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
return null;
|
|
70
|
+
//#region src/components/dnd/layout-context.ts
|
|
71
|
+
const DndRegionContext = createContext(null);
|
|
72
|
+
const useDndRegions = (subject) => {
|
|
73
|
+
const regions = useContext(DndRegionContext);
|
|
74
|
+
if (!regions) throw new Error(`${subject} must be used inside <Live.Dnd>.`);
|
|
75
|
+
return regions;
|
|
167
76
|
};
|
|
77
|
+
const useDndPalette = () => useDndRegions("useDndPalette()").palette;
|
|
78
|
+
const useDndPanel = () => useDndRegions("useDndPanel()").panel;
|
|
79
|
+
const useDndLayout = () => useDndRegions("useDndLayout()");
|
|
168
80
|
//#endregion
|
|
169
81
|
//#region src/components/dnd/panel/use-items-editor.ts
|
|
170
|
-
var import_lib = /* @__PURE__ */ __toESM(require_lib(), 1);
|
|
171
82
|
const resolveLeaf = (render, key) => {
|
|
172
83
|
const leaf = render?.[key];
|
|
173
84
|
return leaf && "type" in leaf ? leaf : null;
|
|
@@ -694,7 +605,7 @@ const Node = ({ data, onChange }) => {
|
|
|
694
605
|
};
|
|
695
606
|
//#endregion
|
|
696
607
|
//#region src/components/dnd/panel/children.tsx
|
|
697
|
-
const Children = ({ value, onChange, onNodeChange }) => {
|
|
608
|
+
const Children$1 = ({ value, onChange, onNodeChange }) => {
|
|
698
609
|
const items = useMemo(() => Array.isArray(value) ? value : [], [value]);
|
|
699
610
|
const selection = useMultiSelect(items.length);
|
|
700
611
|
const editableChildrenMap = useMemo(() => {
|
|
@@ -1028,7 +939,7 @@ const Field = ({ binding, onNodeChange }) => {
|
|
|
1028
939
|
}
|
|
1029
940
|
});
|
|
1030
941
|
}
|
|
1031
|
-
if (binding.property === "children" && Array.isArray(value)) return /* @__PURE__ */ jsx(Children, {
|
|
942
|
+
if (binding.property === "children" && Array.isArray(value)) return /* @__PURE__ */ jsx(Children$1, {
|
|
1032
943
|
value,
|
|
1033
944
|
onChange,
|
|
1034
945
|
onNodeChange
|
|
@@ -1249,7 +1160,7 @@ const groupBindingsById = (bindings) => {
|
|
|
1249
1160
|
}
|
|
1250
1161
|
return [...groups.values()];
|
|
1251
1162
|
};
|
|
1252
|
-
const Panel = ({ item, onDelete, onMoveUp, onMoveDown, canMoveUp = false, canMoveDown = false, bindings, onNodeChange }) => {
|
|
1163
|
+
const Panel$1 = ({ item, onDelete, onMoveUp, onMoveDown, canMoveUp = false, canMoveDown = false, bindings, onNodeChange }) => {
|
|
1253
1164
|
const groups = useMemo(() => groupBindingsById(bindings), [bindings]);
|
|
1254
1165
|
if (!item) return /* @__PURE__ */ jsx(Typography.Paragraph, {
|
|
1255
1166
|
className: cn("p-4 text-sm text-gray-500"),
|
|
@@ -1299,6 +1210,211 @@ const Panel = ({ item, onDelete, onMoveUp, onMoveDown, canMoveUp = false, canMov
|
|
|
1299
1210
|
});
|
|
1300
1211
|
};
|
|
1301
1212
|
//#endregion
|
|
1213
|
+
//#region src/components/dnd/layout.tsx
|
|
1214
|
+
const PaletteItems = ({ subject }) => {
|
|
1215
|
+
const { palette: { items, onAdd }, isMobile } = useDndRegions(subject);
|
|
1216
|
+
return /* @__PURE__ */ jsx(Space, {
|
|
1217
|
+
orientation: "vertical",
|
|
1218
|
+
align: "start",
|
|
1219
|
+
children: items.map((item) => /* @__PURE__ */ jsx(DefaultDraggableItem, {
|
|
1220
|
+
item,
|
|
1221
|
+
onAdd,
|
|
1222
|
+
tapToAdd: isMobile
|
|
1223
|
+
}, item.id))
|
|
1224
|
+
});
|
|
1225
|
+
};
|
|
1226
|
+
const PanelFields = ({ subject }) => {
|
|
1227
|
+
const { panel: { item, onDelete, onMoveUp, onMoveDown, canMoveUp, canMoveDown, bindings, onNodeChange } } = useDndRegions(subject);
|
|
1228
|
+
return /* @__PURE__ */ jsx(Panel$1, {
|
|
1229
|
+
item,
|
|
1230
|
+
onDelete,
|
|
1231
|
+
onMoveUp,
|
|
1232
|
+
onMoveDown,
|
|
1233
|
+
canMoveUp,
|
|
1234
|
+
canMoveDown,
|
|
1235
|
+
bindings,
|
|
1236
|
+
onNodeChange
|
|
1237
|
+
});
|
|
1238
|
+
};
|
|
1239
|
+
const Palette = ({ className, ...restProps }) => /* @__PURE__ */ jsx("div", {
|
|
1240
|
+
className: cn("h-full overflow-y-auto bg-gray-50 p-4", className),
|
|
1241
|
+
...restProps,
|
|
1242
|
+
children: /* @__PURE__ */ jsx(PaletteItems, { subject: "<Live.Dnd.Palette>" })
|
|
1243
|
+
});
|
|
1244
|
+
const Canvas = ({ className, style, ...restProps }) => {
|
|
1245
|
+
const { canvas } = useDndRegions("<Live.Dnd.Canvas>");
|
|
1246
|
+
return /* @__PURE__ */ jsx("div", {
|
|
1247
|
+
className: cn("relative h-full w-full overflow-y-auto", className),
|
|
1248
|
+
"data-frame-container": true,
|
|
1249
|
+
style: {
|
|
1250
|
+
isolation: "isolate",
|
|
1251
|
+
contain: "layout style",
|
|
1252
|
+
transform: "translateZ(0)",
|
|
1253
|
+
...style
|
|
1254
|
+
},
|
|
1255
|
+
...restProps,
|
|
1256
|
+
children: canvas
|
|
1257
|
+
});
|
|
1258
|
+
};
|
|
1259
|
+
const Panel = ({ className, ...restProps }) => /* @__PURE__ */ jsx("div", {
|
|
1260
|
+
className: cn("h-full", className),
|
|
1261
|
+
...restProps,
|
|
1262
|
+
children: /* @__PURE__ */ jsx(PanelFields, { subject: "<Live.Dnd.Panel>" })
|
|
1263
|
+
});
|
|
1264
|
+
const Layout = ({ palette, panel }) => {
|
|
1265
|
+
const { isMobile, selectedId, clearSelection, paletteOpen, setPaletteOpen } = useDndRegions("<Live.Dnd.Layout>");
|
|
1266
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1267
|
+
isMobile ? /* @__PURE__ */ jsx(Canvas, {}) : /* @__PURE__ */ jsxs(Splitter, {
|
|
1268
|
+
withHandle: true,
|
|
1269
|
+
orientation: "horizontal",
|
|
1270
|
+
children: [
|
|
1271
|
+
/* @__PURE__ */ jsx(Splitter.Panel, {
|
|
1272
|
+
defaultSize: "20%",
|
|
1273
|
+
minSize: "15%",
|
|
1274
|
+
maxSize: "35%",
|
|
1275
|
+
collapsible: true,
|
|
1276
|
+
children: palette ?? /* @__PURE__ */ jsx(Palette, {})
|
|
1277
|
+
}),
|
|
1278
|
+
/* @__PURE__ */ jsx(Splitter.Panel, {
|
|
1279
|
+
defaultSize: "60%",
|
|
1280
|
+
children: /* @__PURE__ */ jsx(Canvas, {})
|
|
1281
|
+
}),
|
|
1282
|
+
/* @__PURE__ */ jsx(Splitter.Panel, {
|
|
1283
|
+
defaultSize: "20%",
|
|
1284
|
+
minSize: "15%",
|
|
1285
|
+
maxSize: "35%",
|
|
1286
|
+
collapsible: true,
|
|
1287
|
+
children: panel ?? /* @__PURE__ */ jsx(Panel, {})
|
|
1288
|
+
})
|
|
1289
|
+
]
|
|
1290
|
+
}),
|
|
1291
|
+
/* @__PURE__ */ jsx(Button, {
|
|
1292
|
+
type: "primary",
|
|
1293
|
+
shape: "circle",
|
|
1294
|
+
icon: /* @__PURE__ */ jsx(LayoutGrid, {}),
|
|
1295
|
+
"aria-label": "Components",
|
|
1296
|
+
className: "fixed right-4 bottom-4 z-20 md:hidden",
|
|
1297
|
+
onClick: () => setPaletteOpen(true)
|
|
1298
|
+
}),
|
|
1299
|
+
/* @__PURE__ */ jsx(Drawer, {
|
|
1300
|
+
open: isMobile && paletteOpen,
|
|
1301
|
+
onClose: () => setPaletteOpen(false),
|
|
1302
|
+
direction: "bottom",
|
|
1303
|
+
size: "large",
|
|
1304
|
+
title: "Components",
|
|
1305
|
+
children: palette ?? /* @__PURE__ */ jsx(PaletteItems, { subject: "<Live.Dnd.Layout>" })
|
|
1306
|
+
}),
|
|
1307
|
+
/* @__PURE__ */ jsx(Drawer, {
|
|
1308
|
+
open: isMobile && Boolean(selectedId),
|
|
1309
|
+
onClose: clearSelection,
|
|
1310
|
+
direction: "bottom",
|
|
1311
|
+
size: "large",
|
|
1312
|
+
title: "Properties",
|
|
1313
|
+
children: panel ?? /* @__PURE__ */ jsx(PanelFields, { subject: "<Live.Dnd.Layout>" })
|
|
1314
|
+
})
|
|
1315
|
+
] });
|
|
1316
|
+
};
|
|
1317
|
+
//#endregion
|
|
1318
|
+
//#region src/components/dnd/renderer.tsx
|
|
1319
|
+
const Renderer = ({ preview, headers, modules, frame, dynamicTailwind = false, provider }) => {
|
|
1320
|
+
const module = useCompiledModule(preview, modules);
|
|
1321
|
+
const { ref: wrapperRef, css: dynamicCSS } = useDynamicTailwind(preview, dynamicTailwind);
|
|
1322
|
+
const renderProvider = (component) => {
|
|
1323
|
+
return provider ? provider(component) : component;
|
|
1324
|
+
};
|
|
1325
|
+
if (module?.error) return /* @__PURE__ */ jsx(Error$1, {
|
|
1326
|
+
message: module.error,
|
|
1327
|
+
title: "Compile Error"
|
|
1328
|
+
});
|
|
1329
|
+
const Component = module?.exports?.default;
|
|
1330
|
+
if (!Component) return null;
|
|
1331
|
+
return /* @__PURE__ */ jsx(Frame, {
|
|
1332
|
+
...frame,
|
|
1333
|
+
autoHeight: true,
|
|
1334
|
+
children: (container) => /* @__PURE__ */ jsx("div", {
|
|
1335
|
+
ref: wrapperRef,
|
|
1336
|
+
className: "w-full overflow-x-hidden",
|
|
1337
|
+
"data-editor-mode": true,
|
|
1338
|
+
children: /* @__PURE__ */ jsx(ErrorBoundary, {
|
|
1339
|
+
resetKeys: [preview],
|
|
1340
|
+
children: renderProvider(/* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Component, {
|
|
1341
|
+
headers,
|
|
1342
|
+
container
|
|
1343
|
+
}), dynamicTailwind && dynamicCSS && /* @__PURE__ */ jsx("style", { children: dynamicCSS })] }))
|
|
1344
|
+
})
|
|
1345
|
+
})
|
|
1346
|
+
});
|
|
1347
|
+
};
|
|
1348
|
+
var renderer_default = memo(Renderer);
|
|
1349
|
+
//#endregion
|
|
1350
|
+
//#region src/components/dnd/sortable.tsx
|
|
1351
|
+
const Sortable = ({ id, children, selected, onClick, onDelete: _onDelete, onCopy: _onCopy }) => {
|
|
1352
|
+
const { attributes, listeners, setNodeRef, transform, transition, isDragging, isOver, active } = useSortable({ id });
|
|
1353
|
+
const style = {
|
|
1354
|
+
transform: CSS.Transform.toString(transform),
|
|
1355
|
+
transition,
|
|
1356
|
+
opacity: isDragging ? .5 : 1,
|
|
1357
|
+
cursor: "grab"
|
|
1358
|
+
};
|
|
1359
|
+
const isNewItemOver = isOver && active?.data.current?.type === "new-item";
|
|
1360
|
+
const onDelete = (e) => {
|
|
1361
|
+
e.stopPropagation();
|
|
1362
|
+
_onDelete?.(id);
|
|
1363
|
+
};
|
|
1364
|
+
const onCopy = (e) => {
|
|
1365
|
+
e.stopPropagation();
|
|
1366
|
+
_onCopy?.(id);
|
|
1367
|
+
};
|
|
1368
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1369
|
+
ref: setNodeRef,
|
|
1370
|
+
style,
|
|
1371
|
+
...attributes,
|
|
1372
|
+
...listeners,
|
|
1373
|
+
onClick,
|
|
1374
|
+
className: cn("relative", selected && "z-10 outline-2 outline-offset-2 outline-blue-500", isNewItemOver && "border-t-4 border-t-green-500"),
|
|
1375
|
+
children: [
|
|
1376
|
+
/* @__PURE__ */ jsx("div", { className: cn("absolute inset-0 z-50") }),
|
|
1377
|
+
children,
|
|
1378
|
+
selected && /* @__PURE__ */ jsxs(Space, {
|
|
1379
|
+
className: cn("absolute top-1 right-1 z-60"),
|
|
1380
|
+
children: [/* @__PURE__ */ jsx(Button, {
|
|
1381
|
+
icon: /* @__PURE__ */ jsx(Copy, {}),
|
|
1382
|
+
onClick: onCopy
|
|
1383
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
1384
|
+
danger: true,
|
|
1385
|
+
icon: /* @__PURE__ */ jsx(Trash, {}),
|
|
1386
|
+
onClick: onDelete
|
|
1387
|
+
})]
|
|
1388
|
+
})
|
|
1389
|
+
]
|
|
1390
|
+
});
|
|
1391
|
+
};
|
|
1392
|
+
//#endregion
|
|
1393
|
+
//#region src/components/dnd/overlay.tsx
|
|
1394
|
+
const Overlay = ({ sections, renderProps }) => {
|
|
1395
|
+
const { active } = useDndContext();
|
|
1396
|
+
if (!active) return null;
|
|
1397
|
+
if (active.data.current?.type === "new-item") {
|
|
1398
|
+
const item = active.data.current.item;
|
|
1399
|
+
return /* @__PURE__ */ jsx(DefaultDraggableItem, { item });
|
|
1400
|
+
}
|
|
1401
|
+
const section = sections.find((s) => s.id === active.id);
|
|
1402
|
+
if (section) {
|
|
1403
|
+
const preview = generateSection(section.code, renderProps.fullCode);
|
|
1404
|
+
return /* @__PURE__ */ jsx(Sortable, {
|
|
1405
|
+
id: section.id,
|
|
1406
|
+
name: section.name,
|
|
1407
|
+
children: /* @__PURE__ */ jsx(renderer_default, {
|
|
1408
|
+
preview,
|
|
1409
|
+
modules: renderProps.modules,
|
|
1410
|
+
frame: renderProps.frame,
|
|
1411
|
+
dynamicTailwind: renderProps.dynamicTailwind
|
|
1412
|
+
})
|
|
1413
|
+
});
|
|
1414
|
+
}
|
|
1415
|
+
return null;
|
|
1416
|
+
};
|
|
1417
|
+
//#endregion
|
|
1302
1418
|
//#region src/components/dnd/use-section-document.ts
|
|
1303
1419
|
const useSectionDocument = (value, onChange) => {
|
|
1304
1420
|
const { setCode } = usePreview();
|
|
@@ -1418,7 +1534,7 @@ const conditionalModifiers = (args) => {
|
|
|
1418
1534
|
if (active?.data.current?.type === "new-item") return args.transform;
|
|
1419
1535
|
return restrictToVerticalAxis(args);
|
|
1420
1536
|
};
|
|
1421
|
-
const Dnd$1 = ({ value: _value, props, modules = {}, onChange: _onChange, className, items = [], frame, dynamicTailwind = false, provider,
|
|
1537
|
+
const Dnd$1 = ({ value: _value, props, modules = {}, onChange: _onChange, className, items = [], frame, dynamicTailwind = false, provider, children, ...restProps }) => {
|
|
1422
1538
|
const [mobilePaletteOpen, setMobilePaletteOpen] = useState(false);
|
|
1423
1539
|
const { breakpoint } = useResponsiveSize();
|
|
1424
1540
|
const isMobile = breakpoint.current === "xs" || breakpoint.current === "sm";
|
|
@@ -1514,88 +1630,54 @@ const Dnd$1 = ({ value: _value, props, modules = {}, onChange: _onChange, classN
|
|
|
1514
1630
|
useEffect(() => {
|
|
1515
1631
|
if (frame?.scripts?.length) preloadScripts(frame.scripts);
|
|
1516
1632
|
}, [frame?.scripts]);
|
|
1517
|
-
const
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
isMobile: forMobileDrawer
|
|
1524
|
-
});
|
|
1525
|
-
return /* @__PURE__ */ jsx(Space, {
|
|
1526
|
-
orientation: "vertical",
|
|
1527
|
-
align: "start",
|
|
1528
|
-
children: paletteItems.map((item) => /* @__PURE__ */ jsx(DefaultDraggableItem, {
|
|
1529
|
-
item,
|
|
1530
|
-
onAdd,
|
|
1531
|
-
tapToAdd: forMobileDrawer
|
|
1532
|
-
}, item.id))
|
|
1533
|
-
});
|
|
1633
|
+
const palette = {
|
|
1634
|
+
items: items?.length ? items : DRAGGABLE_ITEMS,
|
|
1635
|
+
onAdd: (item) => {
|
|
1636
|
+
addItem(item);
|
|
1637
|
+
setMobilePaletteOpen(false);
|
|
1638
|
+
}
|
|
1534
1639
|
};
|
|
1535
|
-
const
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
canMoveDown,
|
|
1546
|
-
bindings,
|
|
1547
|
-
onNodeChange: onFieldChange
|
|
1548
|
-
});
|
|
1549
|
-
return /* @__PURE__ */ jsx(Panel, {
|
|
1550
|
-
item: selectedItem,
|
|
1551
|
-
onDelete,
|
|
1552
|
-
onMoveUp: () => moveSection(selectedId, "up"),
|
|
1553
|
-
onMoveDown: () => moveSection(selectedId, "down"),
|
|
1554
|
-
canMoveUp,
|
|
1555
|
-
canMoveDown,
|
|
1556
|
-
bindings,
|
|
1557
|
-
onNodeChange: onFieldChange
|
|
1558
|
-
});
|
|
1640
|
+
const panel = {
|
|
1641
|
+
item: selectedItem,
|
|
1642
|
+
onChange,
|
|
1643
|
+
onDelete,
|
|
1644
|
+
onMoveUp: () => moveSection(selectedId, "up"),
|
|
1645
|
+
onMoveDown: () => moveSection(selectedId, "down"),
|
|
1646
|
+
canMoveUp: selectedIndex > 0,
|
|
1647
|
+
canMoveDown: selectedIndex >= 0 && selectedIndex < sections.length - 1,
|
|
1648
|
+
bindings,
|
|
1649
|
+
onNodeChange: onFieldChange
|
|
1559
1650
|
};
|
|
1560
|
-
const canvas = /* @__PURE__ */ jsx(
|
|
1561
|
-
className: "
|
|
1562
|
-
"
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
children: /* @__PURE__ */ jsx(Droppable, {
|
|
1569
|
-
className: cn(!sections.length && "h-full"),
|
|
1570
|
-
children: !sections.length ? /* @__PURE__ */ jsx("div", {
|
|
1571
|
-
className: cn("flex items-center justify-center", "h-full", "text-gray-500"),
|
|
1572
|
-
children: /* @__PURE__ */ jsxs(Space, {
|
|
1573
|
-
orientation: "vertical",
|
|
1574
|
-
align: "center",
|
|
1575
|
-
children: [/* @__PURE__ */ jsx(Typography.Paragraph, { children: "No sections available" }), /* @__PURE__ */ jsx(Typography.Text, { children: isMobile ? "Tap a component to add it" : "Drag a component from the left to add it" })]
|
|
1576
|
-
})
|
|
1577
|
-
}) : /* @__PURE__ */ jsx(SortableContext, {
|
|
1578
|
-
items: sections.map((s) => s.id),
|
|
1579
|
-
strategy: verticalListSortingStrategy,
|
|
1580
|
-
children: sections.map((section, index) => /* @__PURE__ */ jsx(Sortable, {
|
|
1581
|
-
id: section.id,
|
|
1582
|
-
name: section.name,
|
|
1583
|
-
selected: selectedId === section.id,
|
|
1584
|
-
onClick: () => onSelect(section.id),
|
|
1585
|
-
onDelete,
|
|
1586
|
-
onCopy,
|
|
1587
|
-
children: /* @__PURE__ */ jsx(renderer_default, {
|
|
1588
|
-
preview: previews[index],
|
|
1589
|
-
modules,
|
|
1590
|
-
frame,
|
|
1591
|
-
dynamicTailwind,
|
|
1592
|
-
provider,
|
|
1593
|
-
...props
|
|
1594
|
-
})
|
|
1595
|
-
}, section.id))
|
|
1651
|
+
const canvas = /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(Droppable, {
|
|
1652
|
+
className: cn(!sections.length && "h-full"),
|
|
1653
|
+
children: !sections.length ? /* @__PURE__ */ jsx("div", {
|
|
1654
|
+
className: cn("flex items-center justify-center", "h-full", "text-gray-500"),
|
|
1655
|
+
children: /* @__PURE__ */ jsxs(Space, {
|
|
1656
|
+
orientation: "vertical",
|
|
1657
|
+
align: "center",
|
|
1658
|
+
children: [/* @__PURE__ */ jsx(Typography.Paragraph, { children: "No sections available" }), /* @__PURE__ */ jsx(Typography.Text, { children: isMobile ? "Tap a component to add it" : "Drag a component from the left to add it" })]
|
|
1596
1659
|
})
|
|
1660
|
+
}) : /* @__PURE__ */ jsx(SortableContext, {
|
|
1661
|
+
items: sections.map((s) => s.id),
|
|
1662
|
+
strategy: verticalListSortingStrategy,
|
|
1663
|
+
children: sections.map((section, index) => /* @__PURE__ */ jsx(Sortable, {
|
|
1664
|
+
id: section.id,
|
|
1665
|
+
name: section.name,
|
|
1666
|
+
selected: selectedId === section.id,
|
|
1667
|
+
onClick: () => onSelect(section.id),
|
|
1668
|
+
onDelete,
|
|
1669
|
+
onCopy,
|
|
1670
|
+
children: /* @__PURE__ */ jsx(renderer_default, {
|
|
1671
|
+
preview: previews[index],
|
|
1672
|
+
modules,
|
|
1673
|
+
frame,
|
|
1674
|
+
dynamicTailwind,
|
|
1675
|
+
provider,
|
|
1676
|
+
...props
|
|
1677
|
+
})
|
|
1678
|
+
}, section.id))
|
|
1597
1679
|
})
|
|
1598
|
-
});
|
|
1680
|
+
}) });
|
|
1599
1681
|
return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs(DndContext, {
|
|
1600
1682
|
sensors,
|
|
1601
1683
|
collisionDetection: closestCenter,
|
|
@@ -1603,65 +1685,22 @@ const Dnd$1 = ({ value: _value, props, modules = {}, onChange: _onChange, classN
|
|
|
1603
1685
|
onDragStart,
|
|
1604
1686
|
onDragOver,
|
|
1605
1687
|
onDragEnd,
|
|
1606
|
-
children: [/* @__PURE__ */
|
|
1688
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
1607
1689
|
className: cn("relative flex h-full w-full", className),
|
|
1608
1690
|
...restProps,
|
|
1609
|
-
children:
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
})
|
|
1623
|
-
}),
|
|
1624
|
-
/* @__PURE__ */ jsx(Splitter.Panel, {
|
|
1625
|
-
defaultSize: "60%",
|
|
1626
|
-
children: canvas
|
|
1627
|
-
}),
|
|
1628
|
-
/* @__PURE__ */ jsx(Splitter.Panel, {
|
|
1629
|
-
defaultSize: "20%",
|
|
1630
|
-
minSize: "15%",
|
|
1631
|
-
maxSize: "35%",
|
|
1632
|
-
collapsible: true,
|
|
1633
|
-
children: renderPanelContent()
|
|
1634
|
-
})
|
|
1635
|
-
]
|
|
1636
|
-
}),
|
|
1637
|
-
/* @__PURE__ */ jsx(Button, {
|
|
1638
|
-
type: "primary",
|
|
1639
|
-
shape: "circle",
|
|
1640
|
-
icon: /* @__PURE__ */ jsx(LayoutGrid, {}),
|
|
1641
|
-
"aria-label": "Components",
|
|
1642
|
-
className: "fixed right-4 bottom-4 z-20 md:hidden",
|
|
1643
|
-
onClick: () => setMobilePaletteOpen(true)
|
|
1644
|
-
}),
|
|
1645
|
-
/* @__PURE__ */ jsx(Drawer, {
|
|
1646
|
-
open: isMobile && mobilePaletteOpen,
|
|
1647
|
-
onClose: () => setMobilePaletteOpen(false),
|
|
1648
|
-
direction: "bottom",
|
|
1649
|
-
size: "large",
|
|
1650
|
-
title: "Components",
|
|
1651
|
-
children: renderPaletteItems((item) => {
|
|
1652
|
-
addItem(item);
|
|
1653
|
-
setMobilePaletteOpen(false);
|
|
1654
|
-
}, true)
|
|
1655
|
-
}),
|
|
1656
|
-
/* @__PURE__ */ jsx(Drawer, {
|
|
1657
|
-
open: isMobile && Boolean(selectedId),
|
|
1658
|
-
onClose: clearSelection,
|
|
1659
|
-
direction: "bottom",
|
|
1660
|
-
size: "large",
|
|
1661
|
-
title: "Properties",
|
|
1662
|
-
children: renderPanelContent()
|
|
1663
|
-
})
|
|
1664
|
-
]
|
|
1691
|
+
children: /* @__PURE__ */ jsx(DndRegionContext.Provider, {
|
|
1692
|
+
value: {
|
|
1693
|
+
palette,
|
|
1694
|
+
panel,
|
|
1695
|
+
canvas,
|
|
1696
|
+
isMobile,
|
|
1697
|
+
selectedId,
|
|
1698
|
+
clearSelection,
|
|
1699
|
+
paletteOpen: mobilePaletteOpen,
|
|
1700
|
+
setPaletteOpen: setMobilePaletteOpen
|
|
1701
|
+
},
|
|
1702
|
+
children: Children.toArray(children).length ? children : /* @__PURE__ */ jsx(Layout, {})
|
|
1703
|
+
})
|
|
1665
1704
|
}), /* @__PURE__ */ jsx(DragOverlay, { children: /* @__PURE__ */ jsx(Overlay, {
|
|
1666
1705
|
sections,
|
|
1667
1706
|
renderProps: {
|
|
@@ -1678,9 +1717,12 @@ const Dnd$1 = ({ value: _value, props, modules = {}, onChange: _onChange, classN
|
|
|
1678
1717
|
//#region src/components/dnd/index.ts
|
|
1679
1718
|
const Dnd = Dnd$1;
|
|
1680
1719
|
Dnd.DraggableItem = DraggableItem;
|
|
1681
|
-
Dnd.DefaultPanel = Panel;
|
|
1682
1720
|
Dnd.Field = Field;
|
|
1721
|
+
Dnd.Palette = Palette;
|
|
1722
|
+
Dnd.Canvas = Canvas;
|
|
1723
|
+
Dnd.Panel = Panel;
|
|
1724
|
+
Dnd.Layout = Layout;
|
|
1683
1725
|
//#endregion
|
|
1684
|
-
export {
|
|
1726
|
+
export { Panel as a, ICON_OPTIONS as c, useDndPalette as d, useDndPanel as f, Palette as i, useItemsEditor as l, Canvas as n, Field as o, DraggableItem as p, Layout as r, ICON_MAP as s, Dnd as t, useDndLayout as u };
|
|
1685
1727
|
|
|
1686
|
-
//# sourceMappingURL=dnd-
|
|
1728
|
+
//# sourceMappingURL=dnd-Bl_oqayG.js.map
|