@jbpark/live-editor 1.4.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ko.md +1 -1
- package/README.md +1 -1
- package/dist/ast-CXRFs1hO.mjs +788 -0
- package/dist/ast-CXRFs1hO.mjs.map +1 -0
- package/dist/{ast-fX6Whrjc.mjs → document-BkOqiV4R.mjs} +9940 -9340
- package/dist/document-BkOqiV4R.mjs.map +1 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +112 -60
- package/dist/index.mjs.map +1 -1
- package/dist/utils/ast/index.d.mts +23 -3
- package/dist/utils/ast/index.mjs +3 -2
- package/dist/utils/index.d.mts +2 -1
- package/dist/utils/index.mjs +3 -2
- package/dist/{utils-INSWI9h0.mjs → utils-YMe7_mya.mjs} +14 -40
- package/dist/{utils-INSWI9h0.mjs.map → utils-YMe7_mya.mjs.map} +1 -1
- package/package.json +8 -2
- package/dist/ast-fX6Whrjc.mjs.map +0 -1
- package/dist/enums-3yleLgqV.mjs +0 -1237
- package/dist/enums-3yleLgqV.mjs.map +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -58,7 +58,7 @@ declare class ErrorBoundary extends React$1.Component<Props$6, State> {
|
|
|
58
58
|
constructor(props: Props$6);
|
|
59
59
|
static getDerivedStateFromError(error: Error): State;
|
|
60
60
|
componentDidCatch(error: Error, errorInfo: React$1.ErrorInfo): void;
|
|
61
|
-
render(): string | number | bigint | boolean | Iterable<React$1.ReactNode> | Promise<string | number | bigint | boolean | React$1.ReactPortal | React$1.ReactElement<unknown, string | React$1.JSXElementConstructor<any>> | Iterable<React$1.ReactNode> | null | undefined> |
|
|
61
|
+
render(): string | number | bigint | boolean | react_jsx_runtime0.JSX.Element | Iterable<React$1.ReactNode> | Promise<string | number | bigint | boolean | React$1.ReactPortal | React$1.ReactElement<unknown, string | React$1.JSXElementConstructor<any>> | Iterable<React$1.ReactNode> | null | undefined> | null | undefined;
|
|
62
62
|
}
|
|
63
63
|
//#endregion
|
|
64
64
|
//#region src/components/error/error.d.ts
|
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as
|
|
3
|
-
import {
|
|
1
|
+
import { _ as DRAGGABLE_ITEMS, b as __toESM, d as require_lib$1, f as require_lib, g as DEFAULT_TEMPLATE, p as BINDING_PROP } from "./document-BkOqiV4R.mjs";
|
|
2
|
+
import { a as detectTypeScript, c as generateSections, 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-YMe7_mya.mjs";
|
|
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-CXRFs1hO.mjs";
|
|
4
4
|
import { generateTailwindCSS } from "./utils/tailwind/index.mjs";
|
|
5
5
|
import "@jbpark/ui-kit/style.css";
|
|
6
|
-
import React, { createContext, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
7
|
-
import { Button, Card, Checkbox, ColorPicker, DatePicker, Drawer, Input, Select, Space, Typography, Upload } from "@jbpark/ui-kit";
|
|
6
|
+
import React, { createContext, memo, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
7
|
+
import { Button, Card, Checkbox, ColorPicker, DatePicker, Drawer, Input, Select, Space, Toast, Typography, Upload } from "@jbpark/ui-kit";
|
|
8
8
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
9
9
|
import { DndContext, DragOverlay, PointerSensor, closestCenter, useDndContext, useDraggable, useDroppable, useSensor, useSensors } from "@dnd-kit/core";
|
|
10
10
|
import { restrictToVerticalAxis } from "@dnd-kit/modifiers";
|
|
@@ -397,13 +397,12 @@ const Droppable = ({ children, className }) => {
|
|
|
397
397
|
|
|
398
398
|
//#endregion
|
|
399
399
|
//#region src/components/dnd/renderer.tsx
|
|
400
|
-
const Renderer = ({
|
|
400
|
+
const Renderer = ({ preview, headers, modules, frame, provider }) => {
|
|
401
401
|
const memoizedModules = useMemo(() => ({
|
|
402
402
|
...baseModules,
|
|
403
403
|
...modules
|
|
404
404
|
}), [modules]);
|
|
405
|
-
const
|
|
406
|
-
const module = useMemo(() => compile(memoizedSection, memoizedModules), [memoizedSection, memoizedModules]);
|
|
405
|
+
const module = useMemo(() => compile(preview, memoizedModules), [preview, memoizedModules]);
|
|
407
406
|
const renderProvider = (component) => {
|
|
408
407
|
return provider ? provider(component) : component;
|
|
409
408
|
};
|
|
@@ -422,6 +421,7 @@ const Renderer = ({ fullCode, code, headers, modules, frame, provider }) => {
|
|
|
422
421
|
})
|
|
423
422
|
});
|
|
424
423
|
};
|
|
424
|
+
var renderer_default = memo(Renderer);
|
|
425
425
|
|
|
426
426
|
//#endregion
|
|
427
427
|
//#region src/components/dnd/sortable.tsx
|
|
@@ -477,19 +477,23 @@ const Overlay = ({ sections, renderProps }) => {
|
|
|
477
477
|
return /* @__PURE__ */ jsx(Draggable, { item });
|
|
478
478
|
}
|
|
479
479
|
const section = sections.find((s) => s.id === active.id);
|
|
480
|
-
if (section)
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
480
|
+
if (section) {
|
|
481
|
+
const preview = generateSection(section.code, renderProps.fullCode);
|
|
482
|
+
return /* @__PURE__ */ jsx(Sortable, {
|
|
483
|
+
id: section.id,
|
|
484
|
+
name: section.name,
|
|
485
|
+
children: /* @__PURE__ */ jsx(renderer_default, {
|
|
486
|
+
preview,
|
|
487
|
+
modules: renderProps.modules,
|
|
488
|
+
frame: renderProps.frame
|
|
489
|
+
})
|
|
490
|
+
});
|
|
491
|
+
}
|
|
488
492
|
return null;
|
|
489
493
|
};
|
|
490
494
|
|
|
491
495
|
//#endregion
|
|
492
|
-
//#region node_modules/.pnpm/@marijn+find-cluster-break@1.0.
|
|
496
|
+
//#region node_modules/.pnpm/@marijn+find-cluster-break@1.0.3/node_modules/@marijn/find-cluster-break/src/index.js
|
|
493
497
|
let rangeFrom = [], rangeTo = [];
|
|
494
498
|
(() => {
|
|
495
499
|
let numbers = "lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,3b,f,,w,1j,,,,4,8,4,,3,7,a,2,t,,1m,,,,2,4,8,,9,,a,2,q,,2,2,1l,,4,2,4,2,2,3,3,,u,2,3,,b,2,1l,,4,5,,2,4,,k,2,m,6,,,1m,,,2,,4,8,,7,3,a,2,u,,1n,,,,c,,9,,14,,3,,1l,3,5,3,,4,7,2,b,2,t,,1m,,2,,2,,3,,5,2,7,2,b,2,s,2,1l,2,,,2,4,8,,9,,a,2,t,,20,,4,,2,3,,,8,,29,,2,7,c,8,2q,,2,9,b,6,22,2,r,,,,,,1j,e,,5,,2,5,b,,10,9,,2u,4,,6,,2,2,2,p,2,4,3,g,4,d,,2,2,6,,f,,jj,3,qa,3,t,3,t,2,u,2,1s,2,,7,8,,2,b,9,,19,3,3b,2,y,,3a,3,4,2,9,,6,3,63,2,2,,1m,,,7,,,,,2,8,6,a,2,,1c,h,1r,4,1c,7,,,5,,14,9,c,2,w,4,2,2,,3,1k,,,2,3,,,3,1m,8,2,2,48,3,,d,,7,4,,6,,3,2,5i,1m,,5,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,p,2,5,,47,2,q,i,d,,12,8,p,b,1a,3,1c,,2,4,2,2,13,,1v,6,2,2,2,2,c,,8,,1b,,1f,,,3,2,2,5,2,,,16,2,8,,6m,,2,,4,,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,ar,2,49,b,4w,,1i,f,1k,3,1d,4,2,2,1x,3,10,5,,8,1q,,c,2,1g,9,a,4,2,,2n,3,2,,,2,6,,4g,,3,8,l,2,1l,2,,,,,m,,e,7,3,5,5f,8,2,3,,,n,,29,,2,6,,,2,,,2,,2,6j,,2,4,6,2,,2,r,2,2d,8,2,,,2,2y,,,,2,6,,,2t,3,2,4,,5,77,9,,2,6t,,a,2,,,4,,40,4,2,2,4,,w,a,14,6,2,4,8,,9,6,2,3,1a,d,,2,ba,7,,6,,,2a,m,2,7,,2,,2,3e,6,3,,,2,,7,,,20,2,3,,,,9n,2,f0b,5,1n,7,t4,,1r,4,29,,f5k,2,43q,,,3,4,5,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,79,7,c5,4,15s,7,31,7,240,5,gx7k,2o,3k,6o".split(",").map((s) => s ? parseInt(s, 36) : 1);
|
|
@@ -535,7 +539,7 @@ function nextClusterBreak(str, pos, includeExtending) {
|
|
|
535
539
|
return pos;
|
|
536
540
|
}
|
|
537
541
|
function prevClusterBreak(str, pos, includeExtending) {
|
|
538
|
-
while (pos >
|
|
542
|
+
while (pos > 1) {
|
|
539
543
|
let found = nextClusterBreak(str, pos - 2, includeExtending);
|
|
540
544
|
if (found < pos) return found;
|
|
541
545
|
pos--;
|
|
@@ -560,7 +564,7 @@ function codePointSize(code) {
|
|
|
560
564
|
}
|
|
561
565
|
|
|
562
566
|
//#endregion
|
|
563
|
-
//#region node_modules/.pnpm/@codemirror+state@6.
|
|
567
|
+
//#region node_modules/.pnpm/@codemirror+state@6.7.1/node_modules/@codemirror/state/dist/index.js
|
|
564
568
|
/**
|
|
565
569
|
The data structure for documents. @nonabstract
|
|
566
570
|
*/
|
|
@@ -1621,10 +1625,11 @@ is enabled, a [selection](https://codemirror.net/6/docs/ref/#state.EditorSelecti
|
|
|
1621
1625
|
multiple ranges. By default, selections hold exactly one range.
|
|
1622
1626
|
*/
|
|
1623
1627
|
var SelectionRange = class SelectionRange {
|
|
1624
|
-
constructor(from, to, flags) {
|
|
1628
|
+
constructor(from, to, flags, goalColumn) {
|
|
1625
1629
|
this.from = from;
|
|
1626
1630
|
this.to = to;
|
|
1627
1631
|
this.flags = flags;
|
|
1632
|
+
this.goalColumn = goalColumn;
|
|
1628
1633
|
}
|
|
1629
1634
|
/**
|
|
1630
1635
|
The anchor of the range—the side that doesn't move when you
|
|
@@ -1656,6 +1661,16 @@ var SelectionRange = class SelectionRange {
|
|
|
1656
1661
|
return this.flags & 8 ? -1 : this.flags & 16 ? 1 : 0;
|
|
1657
1662
|
}
|
|
1658
1663
|
/**
|
|
1664
|
+
A flag that, when set, makes some selection-extending commands
|
|
1665
|
+
treat the range's head and anchor as exchangeable, so that for
|
|
1666
|
+
example Shift-ArrowUp will make the lower side of the selection
|
|
1667
|
+
the anchor, even if that was the head before. Used to implement
|
|
1668
|
+
MacOS-style undirectional selections.
|
|
1669
|
+
*/
|
|
1670
|
+
get undirectional() {
|
|
1671
|
+
return (this.flags & 64) > 0;
|
|
1672
|
+
}
|
|
1673
|
+
/**
|
|
1659
1674
|
The bidirectional text level associated with this cursor, if
|
|
1660
1675
|
any.
|
|
1661
1676
|
*/
|
|
@@ -1664,16 +1679,6 @@ var SelectionRange = class SelectionRange {
|
|
|
1664
1679
|
return level == 7 ? null : level;
|
|
1665
1680
|
}
|
|
1666
1681
|
/**
|
|
1667
|
-
The goal column (stored vertical offset) associated with a
|
|
1668
|
-
cursor. This is used to preserve the vertical position when
|
|
1669
|
-
[moving](https://codemirror.net/6/docs/ref/#view.EditorView.moveVertically) across
|
|
1670
|
-
lines of different length.
|
|
1671
|
-
*/
|
|
1672
|
-
get goalColumn() {
|
|
1673
|
-
let value = this.flags >> 6;
|
|
1674
|
-
return value == 16777215 ? void 0 : value;
|
|
1675
|
-
}
|
|
1676
|
-
/**
|
|
1677
1682
|
Map this range through a change, producing a valid range in the
|
|
1678
1683
|
updated document.
|
|
1679
1684
|
*/
|
|
@@ -1684,15 +1689,15 @@ var SelectionRange = class SelectionRange {
|
|
|
1684
1689
|
from = change.mapPos(this.from, 1);
|
|
1685
1690
|
to = change.mapPos(this.to, -1);
|
|
1686
1691
|
}
|
|
1687
|
-
return from == this.from && to == this.to ? this : new SelectionRange(from, to, this.flags);
|
|
1692
|
+
return from == this.from && to == this.to ? this : new SelectionRange(from, to, this.flags, this.goalColumn);
|
|
1688
1693
|
}
|
|
1689
1694
|
/**
|
|
1690
1695
|
Extend this range to cover at least `from` to `to`.
|
|
1691
1696
|
*/
|
|
1692
|
-
extend(from, to = from) {
|
|
1693
|
-
if (from <= this.anchor && to >= this.anchor) return EditorSelection.range(from, to);
|
|
1697
|
+
extend(from, to = from, assoc = 0) {
|
|
1698
|
+
if (from <= this.anchor && to >= this.anchor) return EditorSelection.range(from, to, void 0, void 0, assoc);
|
|
1694
1699
|
let head = Math.abs(from - this.anchor) > Math.abs(to - this.anchor) ? from : to;
|
|
1695
|
-
return EditorSelection.range(this.anchor, head);
|
|
1700
|
+
return EditorSelection.range(this.anchor, head, void 0, void 0, assoc);
|
|
1696
1701
|
}
|
|
1697
1702
|
/**
|
|
1698
1703
|
Compare this range to another range.
|
|
@@ -1720,8 +1725,8 @@ var SelectionRange = class SelectionRange {
|
|
|
1720
1725
|
/**
|
|
1721
1726
|
@internal
|
|
1722
1727
|
*/
|
|
1723
|
-
static create(from, to, flags) {
|
|
1724
|
-
return new SelectionRange(from, to, flags);
|
|
1728
|
+
static create(from, to, flags, goalColumn) {
|
|
1729
|
+
return new SelectionRange(from, to, flags, goalColumn);
|
|
1725
1730
|
}
|
|
1726
1731
|
};
|
|
1727
1732
|
/**
|
|
@@ -1822,14 +1827,23 @@ var EditorSelection = class EditorSelection {
|
|
|
1822
1827
|
safely ignore the optional arguments in most situations.
|
|
1823
1828
|
*/
|
|
1824
1829
|
static cursor(pos, assoc = 0, bidiLevel, goalColumn) {
|
|
1825
|
-
return SelectionRange.create(pos, pos, (assoc == 0 ? 0 : assoc < 0 ? 8 : 16) | (bidiLevel == null ? 7 : Math.min(6, bidiLevel))
|
|
1830
|
+
return SelectionRange.create(pos, pos, (assoc == 0 ? 0 : assoc < 0 ? 8 : 16) | (bidiLevel == null ? 7 : Math.min(6, bidiLevel)), goalColumn);
|
|
1826
1831
|
}
|
|
1827
1832
|
/**
|
|
1828
1833
|
Create a selection range.
|
|
1829
1834
|
*/
|
|
1830
|
-
static range(anchor, head, goalColumn, bidiLevel) {
|
|
1831
|
-
let flags =
|
|
1832
|
-
|
|
1835
|
+
static range(anchor, head, goalColumn, bidiLevel, assoc) {
|
|
1836
|
+
let flags = bidiLevel == null ? 7 : Math.min(6, bidiLevel);
|
|
1837
|
+
if (!assoc && anchor != head) assoc = head < anchor ? 1 : -1;
|
|
1838
|
+
if (assoc) flags |= assoc < 0 ? 8 : 16;
|
|
1839
|
+
return head < anchor ? SelectionRange.create(head, anchor, flags | 32, goalColumn) : SelectionRange.create(anchor, head, flags, goalColumn);
|
|
1840
|
+
}
|
|
1841
|
+
/**
|
|
1842
|
+
Create an [undirectional](https://codemirror.net/6/docs/ref/#state.SelectionRange.undirectional)
|
|
1843
|
+
selection range.
|
|
1844
|
+
*/
|
|
1845
|
+
static undirectionalRange(from, to) {
|
|
1846
|
+
return SelectionRange.create(from, to, 64, void 0);
|
|
1833
1847
|
}
|
|
1834
1848
|
/**
|
|
1835
1849
|
@internal
|
|
@@ -1975,6 +1989,9 @@ var FacetProvider = class {
|
|
|
1975
1989
|
}
|
|
1976
1990
|
};
|
|
1977
1991
|
}
|
|
1992
|
+
get extension() {
|
|
1993
|
+
return this;
|
|
1994
|
+
}
|
|
1978
1995
|
};
|
|
1979
1996
|
function compareArray(a, b, compare) {
|
|
1980
1997
|
if (a.length != b.length) return false;
|
|
@@ -2143,6 +2160,9 @@ var PrecExtension = class {
|
|
|
2143
2160
|
this.inner = inner;
|
|
2144
2161
|
this.prec = prec;
|
|
2145
2162
|
}
|
|
2163
|
+
get extension() {
|
|
2164
|
+
return this;
|
|
2165
|
+
}
|
|
2146
2166
|
};
|
|
2147
2167
|
/**
|
|
2148
2168
|
Extension compartments can be used to make a configuration
|
|
@@ -2182,6 +2202,9 @@ var CompartmentInstance = class {
|
|
|
2182
2202
|
this.compartment = compartment;
|
|
2183
2203
|
this.inner = inner;
|
|
2184
2204
|
}
|
|
2205
|
+
get extension() {
|
|
2206
|
+
return this;
|
|
2207
|
+
}
|
|
2185
2208
|
};
|
|
2186
2209
|
var Configuration = class Configuration {
|
|
2187
2210
|
constructor(base, compartments, dynamicSlots, address, staticValues, facets) {
|
|
@@ -2270,7 +2293,8 @@ function flatten(extension, compartments, newCompartments) {
|
|
|
2270
2293
|
if (ext.facet.extensions) inner(ext.facet.extensions, Prec_.default);
|
|
2271
2294
|
} else {
|
|
2272
2295
|
let content = ext.extension;
|
|
2273
|
-
if (!content) throw new Error(`Unrecognized extension value in extension set (${ext})
|
|
2296
|
+
if (!content) throw new Error(`Unrecognized extension value in extension set (${ext}).`);
|
|
2297
|
+
if (content == ext) throw new Error(`Unrecognized extension value in extension set (${ext}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);
|
|
2274
2298
|
inner(content, prec);
|
|
2275
2299
|
}
|
|
2276
2300
|
}
|
|
@@ -11511,12 +11535,13 @@ const BulkActionsBar = ({ count, onDuplicate, onMoveUp, onMoveDown, onDelete, on
|
|
|
11511
11535
|
});
|
|
11512
11536
|
};
|
|
11513
11537
|
const Items = ({ value, render, onChange, onChildChange }) => {
|
|
11514
|
-
const { objectItems, primitiveItems, allElements } = useMemo(() => {
|
|
11538
|
+
const { objectItems, primitiveItems, allElements, parseError } = useMemo(() => {
|
|
11515
11539
|
const ast = parseArrayExpression(value);
|
|
11516
11540
|
if (!ast) return {
|
|
11517
11541
|
objectItems: [],
|
|
11518
11542
|
primitiveItems: [],
|
|
11519
|
-
allElements: []
|
|
11543
|
+
allElements: [],
|
|
11544
|
+
parseError: true
|
|
11520
11545
|
};
|
|
11521
11546
|
const objectItems = [];
|
|
11522
11547
|
const primitiveItems = [];
|
|
@@ -11564,14 +11589,21 @@ const Items = ({ value, render, onChange, onChildChange }) => {
|
|
|
11564
11589
|
return {
|
|
11565
11590
|
objectItems,
|
|
11566
11591
|
primitiveItems,
|
|
11567
|
-
allElements
|
|
11592
|
+
allElements,
|
|
11593
|
+
parseError: false
|
|
11568
11594
|
};
|
|
11569
11595
|
}, [value]);
|
|
11596
|
+
useEffect(() => {
|
|
11597
|
+
if (parseError) Toast.error("Failed to parse items", { description: "Check the console for details." });
|
|
11598
|
+
}, [parseError]);
|
|
11570
11599
|
const isPrimitive = primitiveItems.length > 0 && objectItems.length === 0;
|
|
11571
11600
|
const selection = useMultiSelect(isPrimitive ? primitiveItems.length : objectItems.length);
|
|
11572
11601
|
const updatePrimitive = (index, next) => {
|
|
11573
11602
|
const ast = parseArrayExpression(value);
|
|
11574
|
-
if (!ast)
|
|
11603
|
+
if (!ast) {
|
|
11604
|
+
Toast.error("Failed to update this item", { description: "Check the console for details." });
|
|
11605
|
+
return;
|
|
11606
|
+
}
|
|
11575
11607
|
const elements = ast.elements.filter(Boolean);
|
|
11576
11608
|
const item = primitiveItems.find((p) => p.index === index);
|
|
11577
11609
|
if (!item) return;
|
|
@@ -12514,26 +12546,32 @@ const Node = ({ data, onChange }) => {
|
|
|
12514
12546
|
|
|
12515
12547
|
//#endregion
|
|
12516
12548
|
//#region src/components/dnd/panel/panel.tsx
|
|
12517
|
-
const Panel = ({ item, onChange }) => {
|
|
12518
|
-
const { dataAttrNodes, updatedCode } = useMemo(() => {
|
|
12549
|
+
const Panel = ({ item, onChange, onDelete }) => {
|
|
12550
|
+
const { dataAttrNodes, updatedCode, parseError } = useMemo(() => {
|
|
12519
12551
|
if (!item?.code) return {
|
|
12520
12552
|
dataAttrNodes: [],
|
|
12521
|
-
updatedCode: ""
|
|
12553
|
+
updatedCode: "",
|
|
12554
|
+
parseError: false
|
|
12522
12555
|
};
|
|
12523
12556
|
try {
|
|
12524
12557
|
const updatedCode = fillIds(item.code);
|
|
12525
12558
|
return {
|
|
12526
12559
|
dataAttrNodes: extract(updatedCode).filter((node) => node.tagName !== "section"),
|
|
12527
|
-
updatedCode: updatedCode !== item.code ? updatedCode : item.code
|
|
12560
|
+
updatedCode: updatedCode !== item.code ? updatedCode : item.code,
|
|
12561
|
+
parseError: false
|
|
12528
12562
|
};
|
|
12529
12563
|
} catch (e) {
|
|
12530
12564
|
console.warn("⚠️ Parsing error", e);
|
|
12531
12565
|
return {
|
|
12532
12566
|
dataAttrNodes: [],
|
|
12533
|
-
updatedCode: ""
|
|
12567
|
+
updatedCode: "",
|
|
12568
|
+
parseError: true
|
|
12534
12569
|
};
|
|
12535
12570
|
}
|
|
12536
12571
|
}, [item?.code]);
|
|
12572
|
+
useEffect(() => {
|
|
12573
|
+
if (parseError) Toast.error("Failed to parse this section", { description: "Check the console for details." });
|
|
12574
|
+
}, [parseError]);
|
|
12537
12575
|
if (!item) return /* @__PURE__ */ jsx(Typography.Paragraph, {
|
|
12538
12576
|
className: cn("p-4 text-sm text-gray-500"),
|
|
12539
12577
|
children: "Please select a section."
|
|
@@ -12541,9 +12579,16 @@ const Panel = ({ item, onChange }) => {
|
|
|
12541
12579
|
return /* @__PURE__ */ jsxs("div", {
|
|
12542
12580
|
className: cn("h-full space-y-4 p-4", "overflow-x-hidden overflow-y-auto"),
|
|
12543
12581
|
children: [
|
|
12544
|
-
/* @__PURE__ */
|
|
12545
|
-
className: "
|
|
12546
|
-
children:
|
|
12582
|
+
/* @__PURE__ */ jsxs("div", {
|
|
12583
|
+
className: "flex items-center justify-between",
|
|
12584
|
+
children: [/* @__PURE__ */ jsx(Typography.Title, {
|
|
12585
|
+
className: "text-lg font-semibold",
|
|
12586
|
+
children: item.name
|
|
12587
|
+
}), onDelete && /* @__PURE__ */ jsx(Button, {
|
|
12588
|
+
danger: true,
|
|
12589
|
+
icon: /* @__PURE__ */ jsx(Trash, {}),
|
|
12590
|
+
onClick: () => onDelete(item.id)
|
|
12591
|
+
})]
|
|
12547
12592
|
}),
|
|
12548
12593
|
!dataAttrNodes.length && /* @__PURE__ */ jsx(Typography.Text, {
|
|
12549
12594
|
className: "text-xs text-gray-400",
|
|
@@ -12552,9 +12597,14 @@ const Panel = ({ item, onChange }) => {
|
|
|
12552
12597
|
dataAttrNodes.map((node, index) => /* @__PURE__ */ jsx(Node, {
|
|
12553
12598
|
data: node,
|
|
12554
12599
|
onChange: ({ id, label, value }) => {
|
|
12600
|
+
const result = update(updatedCode, id, label, value);
|
|
12601
|
+
if (!result.success) {
|
|
12602
|
+
Toast.error("Failed to update this field", { description: "Check the console for details." });
|
|
12603
|
+
return;
|
|
12604
|
+
}
|
|
12555
12605
|
onChange?.({
|
|
12556
12606
|
...item,
|
|
12557
|
-
code:
|
|
12607
|
+
code: result.code
|
|
12558
12608
|
});
|
|
12559
12609
|
}
|
|
12560
12610
|
}, `${item.id}-${index}`))
|
|
@@ -12578,6 +12628,7 @@ const Dnd = ({ value: _value, props, modules = {}, onChange: _onChange, classNam
|
|
|
12578
12628
|
const sensors = useSensors(useSensor(PointerSensor, { activationConstraint: { distance: 10 } }));
|
|
12579
12629
|
const value = _value || DEFAULT_TEMPLATE;
|
|
12580
12630
|
const sections = useMemo(() => extractSections(value), [value]);
|
|
12631
|
+
const previews = useMemo(() => generateSections(sections.map((s) => s.code), value), [sections, value]);
|
|
12581
12632
|
const onDragStart = (_) => {};
|
|
12582
12633
|
const onDragOver = (_e) => {};
|
|
12583
12634
|
const onDragEnd = (event) => {
|
|
@@ -12714,16 +12765,15 @@ const Dnd = ({ value: _value, props, modules = {}, onChange: _onChange, classNam
|
|
|
12714
12765
|
}) : /* @__PURE__ */ jsx(SortableContext, {
|
|
12715
12766
|
items: sections.map((s) => s.id),
|
|
12716
12767
|
strategy: verticalListSortingStrategy,
|
|
12717
|
-
children: sections.map((section) => /* @__PURE__ */ jsx(Sortable, {
|
|
12768
|
+
children: sections.map((section, index) => /* @__PURE__ */ jsx(Sortable, {
|
|
12718
12769
|
id: section.id,
|
|
12719
12770
|
name: section.name,
|
|
12720
12771
|
selected: selectedId === section.id,
|
|
12721
12772
|
onClick: () => onSelect(section.id),
|
|
12722
12773
|
onDelete,
|
|
12723
12774
|
onCopy,
|
|
12724
|
-
children: /* @__PURE__ */ jsx(
|
|
12725
|
-
|
|
12726
|
-
code: section.code,
|
|
12775
|
+
children: /* @__PURE__ */ jsx(renderer_default, {
|
|
12776
|
+
preview: previews[index],
|
|
12727
12777
|
modules,
|
|
12728
12778
|
frame,
|
|
12729
12779
|
provider,
|
|
@@ -12737,7 +12787,8 @@ const Dnd = ({ value: _value, props, modules = {}, onChange: _onChange, classNam
|
|
|
12737
12787
|
className: "hidden w-1/5 md:block",
|
|
12738
12788
|
children: /* @__PURE__ */ jsx(Panel, {
|
|
12739
12789
|
item: sections.find((s) => s.id === selectedId),
|
|
12740
|
-
onChange
|
|
12790
|
+
onChange,
|
|
12791
|
+
onDelete
|
|
12741
12792
|
})
|
|
12742
12793
|
}),
|
|
12743
12794
|
/* @__PURE__ */ jsx(Button, {
|
|
@@ -12767,7 +12818,8 @@ const Dnd = ({ value: _value, props, modules = {}, onChange: _onChange, classNam
|
|
|
12767
12818
|
title: "Properties",
|
|
12768
12819
|
children: /* @__PURE__ */ jsx(Panel, {
|
|
12769
12820
|
item: sections.find((s) => s.id === selectedId),
|
|
12770
|
-
onChange
|
|
12821
|
+
onChange,
|
|
12822
|
+
onDelete
|
|
12771
12823
|
})
|
|
12772
12824
|
})
|
|
12773
12825
|
]
|