@jbpark/live-editor 1.12.0 → 1.13.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-9E8pNi7j.mjs → ast-Dq1EfxA5.js} +113 -135
- package/dist/ast-Dq1EfxA5.js.map +1 -0
- package/dist/{document-DocoSXLT.mjs → document-CSIscFpL.js} +54 -369
- package/dist/document-CSIscFpL.js.map +1 -0
- package/dist/{document-BVWq-dmf.d.mts → document-DXOwpvWM.d.ts} +15 -3
- package/dist/{utils/ast/index.d.mts → index-BVjSMVya.d.ts} +3 -3
- package/dist/{index.d.mts → index.d.ts} +18 -2
- package/dist/{index.mjs → index.js} +139 -59
- package/dist/index.js.map +1 -0
- package/dist/{tailwind-CzPhj3D9.mjs → tailwind-CzPhj3D9.js} +1 -1
- package/dist/tailwind-CzPhj3D9.js.map +1 -0
- package/dist/utils/ast/index.d.ts +3 -0
- package/dist/utils/ast/{index.mjs → index.js} +2 -2
- package/dist/utils/{index.d.mts → index.d.ts} +2 -3
- package/dist/utils/{index.mjs → index.js} +2 -2
- package/dist/utils/tailwind/{index.d.mts → index.d.ts} +1 -1
- package/dist/utils/tailwind/{index.mjs → index.js} +1 -1
- package/dist/{utils-DP9WPbBJ.mjs → utils-B11t9ZYd.js} +2 -2
- package/dist/utils-B11t9ZYd.js.map +1 -0
- package/package.json +9 -11
- package/dist/ast-9E8pNi7j.mjs.map +0 -1
- package/dist/document-DocoSXLT.mjs.map +0 -1
- package/dist/index-C8h8TcIl.d.mts +0 -15
- package/dist/index.mjs.map +0 -1
- package/dist/tailwind-CzPhj3D9.mjs.map +0 -1
- package/dist/utils-DP9WPbBJ.mjs.map +0 -1
|
@@ -1,4 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/types/index.d.ts
|
|
2
|
+
interface Module {
|
|
3
|
+
exports: {
|
|
4
|
+
default?: React.ComponentType<Record<string, unknown>>;
|
|
5
|
+
};
|
|
6
|
+
error?: string;
|
|
7
|
+
}
|
|
8
|
+
interface Section {
|
|
9
|
+
id: string;
|
|
10
|
+
name: string;
|
|
11
|
+
code: string;
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
2
14
|
//#region node_modules/.pnpm/@babel+types@7.29.8/node_modules/@babel/types/lib/index-legacy.d.ts
|
|
3
15
|
// NOTE: This file is autogenerated. Do not modify.
|
|
4
16
|
// See packages/babel-types/scripts/generators/typescript-legacy.ts for script used.
|
|
@@ -1516,5 +1528,5 @@ interface SectionPreviewCache {
|
|
|
1516
1528
|
}
|
|
1517
1529
|
declare const createSectionPreviewCache: () => SectionPreviewCache;
|
|
1518
1530
|
//#endregion
|
|
1519
|
-
export { generateDocumentCode as a, getSections as c, ArrayExpression as d, Expression as f, ObjectExpression as h, createSectionPreviewCache as i, parseDocument as l, Node as m, SectionPreviewCache as n, generateSectionPreview as o, File as p, clearDocumentParseCache as r, generateSectionPreviews as s, DocumentTree as t, replaceDocumentSections as u };
|
|
1520
|
-
//# sourceMappingURL=document-
|
|
1531
|
+
export { Section as _, generateDocumentCode as a, getSections as c, ArrayExpression as d, Expression as f, Module as g, ObjectExpression as h, createSectionPreviewCache as i, parseDocument as l, Node as m, SectionPreviewCache as n, generateSectionPreview as o, File as p, clearDocumentParseCache as r, generateSectionPreviews as s, DocumentTree as t, replaceDocumentSections as u };
|
|
1532
|
+
//# sourceMappingURL=document-DXOwpvWM.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { d as ArrayExpression, f as Expression, h as ObjectExpression, m as Node, p as File } from "./document-DXOwpvWM.js";
|
|
2
2
|
//#region src/utils/ast/types.d.ts
|
|
3
3
|
interface Attribute {
|
|
4
4
|
name: string;
|
|
@@ -134,5 +134,5 @@ interface ValidationResult {
|
|
|
134
134
|
}
|
|
135
135
|
declare const validateBindingValue: (binding: BindingItem, value: unknown) => ValidationResult;
|
|
136
136
|
//#endregion
|
|
137
|
-
export {
|
|
138
|
-
//# sourceMappingURL=index.d.
|
|
137
|
+
export { BindingRenderMap as C, ExtractedNodeValue as D, EditableNodeValueType as E, NodeValueType as O, BindingRenderLeaf as S, DataAttrNode as T, findEditableChildren as _, replaceIds as a, BindingItem as b, clearExtractCache as c, arrayExpressionToCode as d, createNodeFromValue as f, parseValue as g, parseArrayExpression as h, fillIds as i, extract as l, extractObjectProperties as m, validateBindingValue as n, bulkUpdate as o, extractNodeValue as p, clone as r, update as s, ValidationResult as t, generateCode as u, getCurrentValue as v, BindingType as w, BindingOption as x, parseBinding as y };
|
|
138
|
+
//# sourceMappingURL=index-BVjSMVya.d.ts.map
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { _ as Section } from "./document-DXOwpvWM.js";
|
|
2
|
+
import { w as BindingType, x as BindingOption } from "./index-BVjSMVya.js";
|
|
2
3
|
import "@jbpark/ui-kit/style.css";
|
|
3
4
|
import React$1, { ReactNode } from "react";
|
|
4
5
|
import { Extension } from "@uiw/react-codemirror";
|
|
@@ -135,11 +136,26 @@ interface PaletteRenderData {
|
|
|
135
136
|
items: Section[];
|
|
136
137
|
onAdd: (item: Section) => void;
|
|
137
138
|
DraggableItem: typeof DraggableItem;
|
|
139
|
+
isMobile: boolean;
|
|
138
140
|
}
|
|
139
141
|
interface PanelRenderData {
|
|
140
142
|
item?: Section;
|
|
141
143
|
onChange: (next: Partial<Section>) => void;
|
|
142
144
|
onDelete: (id: string) => void;
|
|
145
|
+
onMoveUp: () => void;
|
|
146
|
+
onMoveDown: () => void;
|
|
147
|
+
canMoveUp: boolean;
|
|
148
|
+
canMoveDown: boolean;
|
|
149
|
+
bindings: PanelBinding[];
|
|
150
|
+
}
|
|
151
|
+
interface PanelBinding {
|
|
152
|
+
id: string;
|
|
153
|
+
label: string;
|
|
154
|
+
property: string;
|
|
155
|
+
type?: BindingType;
|
|
156
|
+
options?: BindingOption[];
|
|
157
|
+
value: string;
|
|
158
|
+
onChange: (value: string) => void;
|
|
143
159
|
}
|
|
144
160
|
interface Props extends Omit<React.ComponentPropsWithRef<'div'>, 'onChange'> {
|
|
145
161
|
value?: string;
|
|
@@ -182,4 +198,4 @@ declare const App: {
|
|
|
182
198
|
declare const LiveRenderer: ({ code, props, modules, dynamicTailwind, provider, ...restProps }: Props$7) => import("react").JSX.Element;
|
|
183
199
|
//#endregion
|
|
184
200
|
export { Dnd as LiveDnd, Editor as LiveEditor, Error$1 as LiveError, Preview as LivePreview, App as LiveProvider, App as default, LiveRenderer };
|
|
185
|
-
//# sourceMappingURL=index.d.
|
|
201
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { _ as DEFAULT_TEMPLATE, f as require_lib$1, m as BINDING_PROP, n as createSectionPreviewCache, p as require_lib, v as DRAGGABLE_ITEMS, x as __toESM } from "./document-
|
|
2
|
-
import { a as detectTypeScript, d as replaceSections, i as compile, l as getCachedScriptBlob, n as clearCompilationCache, o as extractSections, r as cn, s as generateSection, t as baseModules, u as preloadScripts } from "./utils-
|
|
3
|
-
import { _ as parseArrayExpression, c as extract, d as getCurrentValue, f as parseBinding, g as extractObjectProperties, h as extractNodeValue, i as replaceIds, l as nanoid, m as createNodeFromValue, n as clone, o as update, p as arrayExpressionToCode, r as fillIds, t as validateBindingValue, u as findEditableChildren, v as parseValue, y as generateCode } from "./ast-
|
|
4
|
-
import { t as generateTailwindCSS } from "./tailwind-CzPhj3D9.
|
|
1
|
+
import { _ as DEFAULT_TEMPLATE, f as require_lib$1, m as BINDING_PROP, n as createSectionPreviewCache, p as require_lib, v as DRAGGABLE_ITEMS, x as __toESM } from "./document-CSIscFpL.js";
|
|
2
|
+
import { a as detectTypeScript, d as replaceSections, i as compile, l as getCachedScriptBlob, n as clearCompilationCache, o as extractSections, r as cn, s as generateSection, t as baseModules, u as preloadScripts } from "./utils-B11t9ZYd.js";
|
|
3
|
+
import { _ as parseArrayExpression, c as extract, d as getCurrentValue, f as parseBinding, g as extractObjectProperties, h as extractNodeValue, i as replaceIds, l as nanoid, m as createNodeFromValue, n as clone, o as update, p as arrayExpressionToCode, r as fillIds, t as validateBindingValue, u as findEditableChildren, v as parseValue, y as generateCode } from "./ast-Dq1EfxA5.js";
|
|
4
|
+
import { t as generateTailwindCSS } from "./tailwind-CzPhj3D9.js";
|
|
5
5
|
import "@jbpark/ui-kit/style.css";
|
|
6
6
|
import React, { createContext, memo, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
7
7
|
import { Button, Card, Checkbox, ColorPicker, DatePicker, Drawer, Input, Select, Space, Toast, Typography, Upload } from "@jbpark/ui-kit";
|
|
@@ -10,7 +10,7 @@ import { DndContext, DragOverlay, PointerSensor, closestCenter, useDndContext, u
|
|
|
10
10
|
import { restrictToVerticalAxis } from "@dnd-kit/modifiers";
|
|
11
11
|
import { SortableContext, arrayMove, useSortable, verticalListSortingStrategy } from "@dnd-kit/sortable";
|
|
12
12
|
import { useDebounce, useDebouncedValue, useEventListener, useMultiSelect, useMutationObserver, useResizeObserver, useResponsiveSize } from "@jbpark/use-hooks";
|
|
13
|
-
import { AlertCircle, ArrowDown, ArrowLeft, ArrowRight, ArrowUp, Bell, Bookmark, Calendar, Camera, Check, ChevronDown, ChevronRight, 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";
|
|
13
|
+
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";
|
|
14
14
|
import { v4 } from "uuid";
|
|
15
15
|
import { createPortal } from "react-dom";
|
|
16
16
|
import { CSS } from "@dnd-kit/utilities";
|
|
@@ -237,6 +237,7 @@ const IFrame = ({ title = "Live Preview", sandbox, style = {}, scripts = EMPTY_S
|
|
|
237
237
|
prevStylesheetCountRef.current = stylesheets.length;
|
|
238
238
|
}, [styles, stylesheets]);
|
|
239
239
|
const CONTAINER_STYLE_ID = "autoheight-container";
|
|
240
|
+
const HIDE_SCROLLBAR_STYLE_ID = "autoheight-hide-scrollbar";
|
|
240
241
|
const ensureContainerStyle = (doc, probeHeight) => {
|
|
241
242
|
let styleEl = doc.getElementById(CONTAINER_STYLE_ID);
|
|
242
243
|
if (!styleEl) {
|
|
@@ -304,6 +305,20 @@ const IFrame = ({ title = "Live Preview", sandbox, style = {}, scripts = EMPTY_S
|
|
|
304
305
|
if (shouldAutoHeight) return;
|
|
305
306
|
iframeRef.current?.contentDocument?.getElementById(CONTAINER_STYLE_ID)?.remove();
|
|
306
307
|
}, [shouldAutoHeight]);
|
|
308
|
+
useEffect(() => {
|
|
309
|
+
const doc = iframeRef.current?.contentDocument;
|
|
310
|
+
if (!doc?.head) return;
|
|
311
|
+
const existing = doc.getElementById(HIDE_SCROLLBAR_STYLE_ID);
|
|
312
|
+
if (!shouldAutoHeight) {
|
|
313
|
+
existing?.remove();
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
if (existing) return;
|
|
317
|
+
const styleEl = doc.createElement("style");
|
|
318
|
+
styleEl.id = HIDE_SCROLLBAR_STYLE_ID;
|
|
319
|
+
styleEl.textContent = ["html, body { scrollbar-width: none !important; }", "html::-webkit-scrollbar, body::-webkit-scrollbar { display: none !important; }"].join("\n");
|
|
320
|
+
doc.head.appendChild(styleEl);
|
|
321
|
+
}, [shouldAutoHeight, mountNode]);
|
|
307
322
|
useEffect(() => {
|
|
308
323
|
updateHeight();
|
|
309
324
|
}, [updateHeight]);
|
|
@@ -405,13 +420,14 @@ const DraggableItem = ({ item, children }) => {
|
|
|
405
420
|
isDragging
|
|
406
421
|
});
|
|
407
422
|
};
|
|
408
|
-
const DefaultDraggableItem = ({ item, onAdd }) => /* @__PURE__ */ jsx(DraggableItem, {
|
|
423
|
+
const DefaultDraggableItem = ({ item, onAdd, tapToAdd = false }) => /* @__PURE__ */ jsx(DraggableItem, {
|
|
409
424
|
item,
|
|
410
425
|
children: ({ ref, dragProps, isDragging }) => /* @__PURE__ */ jsx(Card, {
|
|
411
426
|
ref,
|
|
412
427
|
style: { opacity: isDragging ? .5 : 1 },
|
|
413
428
|
...dragProps,
|
|
414
429
|
className: cn("cursor-grab", "outline-none", "hover:border-blue-300 hover:shadow-md", isDragging && "opacity-50"),
|
|
430
|
+
onClick: tapToAdd && onAdd ? () => onAdd(item) : void 0,
|
|
415
431
|
onDoubleClick: onAdd ? () => onAdd(item) : void 0,
|
|
416
432
|
children: item.name
|
|
417
433
|
})
|
|
@@ -12861,33 +12877,7 @@ const Node = ({ data, onChange }) => {
|
|
|
12861
12877
|
};
|
|
12862
12878
|
//#endregion
|
|
12863
12879
|
//#region src/components/dnd/panel/panel.tsx
|
|
12864
|
-
const Panel = ({ item,
|
|
12865
|
-
const code = item?.code;
|
|
12866
|
-
const { dataAttrNodes, updatedCode, parseError } = useMemo(() => {
|
|
12867
|
-
if (!code) return {
|
|
12868
|
-
dataAttrNodes: [],
|
|
12869
|
-
updatedCode: "",
|
|
12870
|
-
parseError: false
|
|
12871
|
-
};
|
|
12872
|
-
try {
|
|
12873
|
-
const updatedCode = fillIds(code);
|
|
12874
|
-
return {
|
|
12875
|
-
dataAttrNodes: extract(updatedCode).filter((node) => node.tagName !== "section"),
|
|
12876
|
-
updatedCode: updatedCode !== code ? updatedCode : code,
|
|
12877
|
-
parseError: false
|
|
12878
|
-
};
|
|
12879
|
-
} catch (e) {
|
|
12880
|
-
console.warn("⚠️ Parsing error", e);
|
|
12881
|
-
return {
|
|
12882
|
-
dataAttrNodes: [],
|
|
12883
|
-
updatedCode: "",
|
|
12884
|
-
parseError: true
|
|
12885
|
-
};
|
|
12886
|
-
}
|
|
12887
|
-
}, [code]);
|
|
12888
|
-
useEffect(() => {
|
|
12889
|
-
if (parseError) Toast.error("Failed to parse this section", { description: "Check the console for details." });
|
|
12890
|
-
}, [parseError]);
|
|
12880
|
+
const Panel = ({ item, onDelete, onMoveUp, onMoveDown, canMoveUp = false, canMoveDown = false, fields, onFieldChange }) => {
|
|
12891
12881
|
if (!item) return /* @__PURE__ */ jsx(Typography.Paragraph, {
|
|
12892
12882
|
className: cn("p-4 text-sm text-gray-500"),
|
|
12893
12883
|
children: "Please select a section."
|
|
@@ -12900,29 +12890,37 @@ const Panel = ({ item, onChange, onDelete }) => {
|
|
|
12900
12890
|
children: [/* @__PURE__ */ jsx(Typography.Title, {
|
|
12901
12891
|
className: "text-lg font-semibold",
|
|
12902
12892
|
children: item.name
|
|
12903
|
-
}),
|
|
12904
|
-
|
|
12905
|
-
|
|
12906
|
-
|
|
12893
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
12894
|
+
className: "flex items-center gap-1",
|
|
12895
|
+
children: [
|
|
12896
|
+
onMoveUp && /* @__PURE__ */ jsx(Button, {
|
|
12897
|
+
icon: /* @__PURE__ */ jsx(ChevronUp, {}),
|
|
12898
|
+
disabled: !canMoveUp,
|
|
12899
|
+
onClick: onMoveUp,
|
|
12900
|
+
"aria-label": "Move section up"
|
|
12901
|
+
}),
|
|
12902
|
+
onMoveDown && /* @__PURE__ */ jsx(Button, {
|
|
12903
|
+
icon: /* @__PURE__ */ jsx(ChevronDown, {}),
|
|
12904
|
+
disabled: !canMoveDown,
|
|
12905
|
+
onClick: onMoveDown,
|
|
12906
|
+
"aria-label": "Move section down"
|
|
12907
|
+
}),
|
|
12908
|
+
onDelete && /* @__PURE__ */ jsx(Button, {
|
|
12909
|
+
danger: true,
|
|
12910
|
+
icon: /* @__PURE__ */ jsx(Trash, {}),
|
|
12911
|
+
onClick: () => onDelete(item.id),
|
|
12912
|
+
"aria-label": "Delete section"
|
|
12913
|
+
})
|
|
12914
|
+
]
|
|
12907
12915
|
})]
|
|
12908
12916
|
}),
|
|
12909
|
-
!
|
|
12917
|
+
!fields.length && /* @__PURE__ */ jsx(Typography.Text, {
|
|
12910
12918
|
className: "text-xs text-gray-400",
|
|
12911
12919
|
children: "No editable elements."
|
|
12912
12920
|
}),
|
|
12913
|
-
|
|
12921
|
+
fields.map((node, index) => /* @__PURE__ */ jsx(Node, {
|
|
12914
12922
|
data: node,
|
|
12915
|
-
onChange:
|
|
12916
|
-
const result = update(updatedCode, id, label, value);
|
|
12917
|
-
if (!result.success) {
|
|
12918
|
-
Toast.error("Failed to update this field", { description: "Check the console for details." });
|
|
12919
|
-
return;
|
|
12920
|
-
}
|
|
12921
|
-
onChange?.({
|
|
12922
|
-
...item,
|
|
12923
|
-
code: result.code
|
|
12924
|
-
});
|
|
12925
|
-
}
|
|
12923
|
+
onChange: onFieldChange
|
|
12926
12924
|
}, `${item.id}-${index}`))
|
|
12927
12925
|
]
|
|
12928
12926
|
});
|
|
@@ -12943,6 +12941,7 @@ const Dnd$1 = ({ value: _value, props, modules = {}, onChange: _onChange, classN
|
|
|
12943
12941
|
const sensors = useSensors(useSensor(PointerSensor, { activationConstraint: { distance: 10 } }));
|
|
12944
12942
|
const value = _value || DEFAULT_TEMPLATE;
|
|
12945
12943
|
const sections = useMemo(() => extractSections(value), [value]);
|
|
12944
|
+
const selectedItem = useMemo(() => sections.find((s) => s.id === selectedId), [sections, selectedId]);
|
|
12946
12945
|
const [previewCache] = useState(() => createSectionPreviewCache());
|
|
12947
12946
|
const previews = useMemo(() => previewCache.compute(value, sections), [
|
|
12948
12947
|
previewCache,
|
|
@@ -13006,6 +13005,16 @@ const Dnd$1 = ({ value: _value, props, modules = {}, onChange: _onChange, classN
|
|
|
13006
13005
|
_onChange?.(nextCode);
|
|
13007
13006
|
setCode(nextCode);
|
|
13008
13007
|
};
|
|
13008
|
+
const moveSection = (id, direction) => {
|
|
13009
|
+
const index = sections.findIndex((s) => s.id === id);
|
|
13010
|
+
const targetIndex = direction === "up" ? index - 1 : index + 1;
|
|
13011
|
+
if (index < 0 || targetIndex < 0 || targetIndex >= sections.length) return;
|
|
13012
|
+
const nextSections = arrayMove(sections, index, targetIndex);
|
|
13013
|
+
const nextCode = replaceSections(value, nextSections.map((s) => s.code));
|
|
13014
|
+
_onChange?.(nextCode);
|
|
13015
|
+
setCode(nextCode);
|
|
13016
|
+
setSelectedId(String(targetIndex));
|
|
13017
|
+
};
|
|
13009
13018
|
const onCopy = (id) => {
|
|
13010
13019
|
const sectionIndex = sections.findIndex((s) => s.id === id);
|
|
13011
13020
|
const sectionToCopy = sections[sectionIndex];
|
|
@@ -13039,36 +13048,107 @@ const Dnd$1 = ({ value: _value, props, modules = {}, onChange: _onChange, classN
|
|
|
13039
13048
|
_onChange?.(nextCode);
|
|
13040
13049
|
setCode(nextCode);
|
|
13041
13050
|
};
|
|
13051
|
+
const selectedCode = selectedItem?.code;
|
|
13052
|
+
const { fields, updatedCode, parseError } = useMemo(() => {
|
|
13053
|
+
if (!selectedCode) return {
|
|
13054
|
+
fields: [],
|
|
13055
|
+
updatedCode: "",
|
|
13056
|
+
parseError: false
|
|
13057
|
+
};
|
|
13058
|
+
try {
|
|
13059
|
+
const updated = fillIds(selectedCode);
|
|
13060
|
+
return {
|
|
13061
|
+
fields: extract(updated).filter((node) => node.tagName !== "section"),
|
|
13062
|
+
updatedCode: updated !== selectedCode ? updated : selectedCode,
|
|
13063
|
+
parseError: false
|
|
13064
|
+
};
|
|
13065
|
+
} catch (e) {
|
|
13066
|
+
console.warn("⚠️ Parsing error", e);
|
|
13067
|
+
return {
|
|
13068
|
+
fields: [],
|
|
13069
|
+
updatedCode: "",
|
|
13070
|
+
parseError: true
|
|
13071
|
+
};
|
|
13072
|
+
}
|
|
13073
|
+
}, [selectedCode]);
|
|
13074
|
+
useEffect(() => {
|
|
13075
|
+
if (parseError) Toast.error("Failed to parse this section", { description: "Check the console for details." });
|
|
13076
|
+
}, [parseError]);
|
|
13077
|
+
const onFieldChange = ({ id, label, value: fieldValue }) => {
|
|
13078
|
+
const result = update(updatedCode, id, label, fieldValue);
|
|
13079
|
+
if (!result.success) {
|
|
13080
|
+
Toast.error("Failed to update this field", { description: "Check the console for details." });
|
|
13081
|
+
return;
|
|
13082
|
+
}
|
|
13083
|
+
if (selectedItem) onChange({
|
|
13084
|
+
...selectedItem,
|
|
13085
|
+
code: result.code
|
|
13086
|
+
});
|
|
13087
|
+
};
|
|
13088
|
+
const bindings = useMemo(() => {
|
|
13089
|
+
return fields.flatMap((node) => {
|
|
13090
|
+
const dataId = node.dataAttributes.find((a) => a.name === "data-id")?.value;
|
|
13091
|
+
const bindingAttr = node.dataAttributes.find((a) => a.name === "data-binding")?.value;
|
|
13092
|
+
if (!dataId || !bindingAttr) return [];
|
|
13093
|
+
return (node.bindings ?? parseBinding(bindingAttr)).map((binding) => ({
|
|
13094
|
+
id: dataId,
|
|
13095
|
+
label: binding.label,
|
|
13096
|
+
property: binding.property,
|
|
13097
|
+
type: binding.type,
|
|
13098
|
+
options: binding.options,
|
|
13099
|
+
value: getCurrentValue(node, binding.property),
|
|
13100
|
+
onChange: (value) => onFieldChange({
|
|
13101
|
+
id: dataId,
|
|
13102
|
+
label: binding.label,
|
|
13103
|
+
value
|
|
13104
|
+
})
|
|
13105
|
+
}));
|
|
13106
|
+
});
|
|
13107
|
+
}, [fields]);
|
|
13042
13108
|
useEffect(() => {
|
|
13043
13109
|
if (frame?.scripts?.length) preloadScripts(frame.scripts);
|
|
13044
13110
|
}, [frame?.scripts]);
|
|
13045
|
-
const renderPaletteItems = (onAdd) => {
|
|
13111
|
+
const renderPaletteItems = (onAdd, forMobileDrawer = false) => {
|
|
13046
13112
|
const paletteItems = items?.length ? items : DRAGGABLE_ITEMS;
|
|
13047
13113
|
if (renderPalette) return renderPalette({
|
|
13048
13114
|
items: paletteItems,
|
|
13049
13115
|
onAdd,
|
|
13050
|
-
DraggableItem
|
|
13116
|
+
DraggableItem,
|
|
13117
|
+
isMobile: forMobileDrawer
|
|
13051
13118
|
});
|
|
13052
13119
|
return /* @__PURE__ */ jsx(Space, {
|
|
13053
13120
|
orientation: "vertical",
|
|
13054
13121
|
align: "start",
|
|
13055
13122
|
children: paletteItems.map((item) => /* @__PURE__ */ jsx(DefaultDraggableItem, {
|
|
13056
13123
|
item,
|
|
13057
|
-
onAdd
|
|
13124
|
+
onAdd,
|
|
13125
|
+
tapToAdd: forMobileDrawer
|
|
13058
13126
|
}, item.id))
|
|
13059
13127
|
});
|
|
13060
13128
|
};
|
|
13061
13129
|
const renderPanelContent = () => {
|
|
13062
|
-
const
|
|
13130
|
+
const selectedIndex = sections.findIndex((s) => s.id === selectedId);
|
|
13131
|
+
const canMoveUp = selectedIndex > 0;
|
|
13132
|
+
const canMoveDown = selectedIndex >= 0 && selectedIndex < sections.length - 1;
|
|
13063
13133
|
if (renderPanel) return renderPanel({
|
|
13064
13134
|
item: selectedItem,
|
|
13065
13135
|
onChange,
|
|
13066
|
-
onDelete
|
|
13136
|
+
onDelete,
|
|
13137
|
+
onMoveUp: () => moveSection(selectedId, "up"),
|
|
13138
|
+
onMoveDown: () => moveSection(selectedId, "down"),
|
|
13139
|
+
canMoveUp,
|
|
13140
|
+
canMoveDown,
|
|
13141
|
+
bindings
|
|
13067
13142
|
});
|
|
13068
13143
|
return /* @__PURE__ */ jsx(Panel, {
|
|
13069
13144
|
item: selectedItem,
|
|
13070
|
-
|
|
13071
|
-
|
|
13145
|
+
onDelete,
|
|
13146
|
+
onMoveUp: () => moveSection(selectedId, "up"),
|
|
13147
|
+
onMoveDown: () => moveSection(selectedId, "down"),
|
|
13148
|
+
canMoveUp,
|
|
13149
|
+
canMoveDown,
|
|
13150
|
+
fields,
|
|
13151
|
+
onFieldChange
|
|
13072
13152
|
});
|
|
13073
13153
|
};
|
|
13074
13154
|
return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs(DndContext, {
|
|
@@ -13148,7 +13228,7 @@ const Dnd$1 = ({ value: _value, props, modules = {}, onChange: _onChange, classN
|
|
|
13148
13228
|
children: renderPaletteItems((item) => {
|
|
13149
13229
|
addItem(item);
|
|
13150
13230
|
setMobilePaletteOpen(false);
|
|
13151
|
-
})
|
|
13231
|
+
}, true)
|
|
13152
13232
|
}),
|
|
13153
13233
|
/* @__PURE__ */ jsx(Drawer, {
|
|
13154
13234
|
open: isMobile && Boolean(selectedId),
|
|
@@ -13528,4 +13608,4 @@ App.Dnd = Dnd;
|
|
|
13528
13608
|
//#endregion
|
|
13529
13609
|
export { Dnd as LiveDnd, Editor as LiveEditor, Error$1 as LiveError, Preview as LivePreview, App as LiveProvider, App as default, LiveRenderer };
|
|
13530
13610
|
|
|
13531
|
-
//# sourceMappingURL=index.
|
|
13611
|
+
//# sourceMappingURL=index.js.map
|