@jbpark/live-editor 1.4.0 → 1.5.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/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> | react_jsx_runtime0.JSX.Element | 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 { S as __toESM, _ as parseArrayExpression, b as require_lib$1, 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, x as require_lib, y as generateCode } from "./ast-fX6Whrjc.mjs";
2
- import { a as DRAGGABLE_ITEMS, i as DEFAULT_TEMPLATE, t as BINDING_PROP } from "./enums-3yleLgqV.mjs";
3
- import { a as detectTypeScript, c as getCachedScriptBlob, i as compile, l as preloadScripts, n as clearCompilationCache, o as extractSections, r as cn, s as generateSection, t as baseModules, u as replaceSections } from "./utils-INSWI9h0.mjs";
1
+ import { S as __toESM, c as generateCode, h as BINDING_PROP, m as require_lib, p as require_lib$1, v as DEFAULT_TEMPLATE, y as DRAGGABLE_ITEMS } from "./document-BGG0pNR2.mjs";
2
+ import { a as detectTypeScript, c as getCachedScriptBlob, i as compile, l as preloadScripts, n as clearCompilationCache, o as extractSections, r as cn, s as generateSection, t as baseModules, u as replaceSections } from "./utils-UTqUJaVs.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 } from "./ast-DyDLUN5F.mjs";
4
4
  import { generateTailwindCSS } from "./utils/tailwind/index.mjs";
5
5
  import "@jbpark/ui-kit/style.css";
6
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";
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";
@@ -489,7 +489,7 @@ const Overlay = ({ sections, renderProps }) => {
489
489
  };
490
490
 
491
491
  //#endregion
492
- //#region node_modules/.pnpm/@marijn+find-cluster-break@1.0.2/node_modules/@marijn/find-cluster-break/src/index.js
492
+ //#region node_modules/.pnpm/@marijn+find-cluster-break@1.0.3/node_modules/@marijn/find-cluster-break/src/index.js
493
493
  let rangeFrom = [], rangeTo = [];
494
494
  (() => {
495
495
  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,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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 +535,7 @@ function nextClusterBreak(str, pos, includeExtending) {
535
535
  return pos;
536
536
  }
537
537
  function prevClusterBreak(str, pos, includeExtending) {
538
- while (pos > 0) {
538
+ while (pos > 1) {
539
539
  let found = nextClusterBreak(str, pos - 2, includeExtending);
540
540
  if (found < pos) return found;
541
541
  pos--;
@@ -560,7 +560,7 @@ function codePointSize(code) {
560
560
  }
561
561
 
562
562
  //#endregion
563
- //#region node_modules/.pnpm/@codemirror+state@6.5.4/node_modules/@codemirror/state/dist/index.js
563
+ //#region node_modules/.pnpm/@codemirror+state@6.7.1/node_modules/@codemirror/state/dist/index.js
564
564
  /**
565
565
  The data structure for documents. @nonabstract
566
566
  */
@@ -1621,10 +1621,11 @@ is enabled, a [selection](https://codemirror.net/6/docs/ref/#state.EditorSelecti
1621
1621
  multiple ranges. By default, selections hold exactly one range.
1622
1622
  */
1623
1623
  var SelectionRange = class SelectionRange {
1624
- constructor(from, to, flags) {
1624
+ constructor(from, to, flags, goalColumn) {
1625
1625
  this.from = from;
1626
1626
  this.to = to;
1627
1627
  this.flags = flags;
1628
+ this.goalColumn = goalColumn;
1628
1629
  }
1629
1630
  /**
1630
1631
  The anchor of the range—the side that doesn't move when you
@@ -1656,6 +1657,16 @@ var SelectionRange = class SelectionRange {
1656
1657
  return this.flags & 8 ? -1 : this.flags & 16 ? 1 : 0;
1657
1658
  }
1658
1659
  /**
1660
+ A flag that, when set, makes some selection-extending commands
1661
+ treat the range's head and anchor as exchangeable, so that for
1662
+ example Shift-ArrowUp will make the lower side of the selection
1663
+ the anchor, even if that was the head before. Used to implement
1664
+ MacOS-style undirectional selections.
1665
+ */
1666
+ get undirectional() {
1667
+ return (this.flags & 64) > 0;
1668
+ }
1669
+ /**
1659
1670
  The bidirectional text level associated with this cursor, if
1660
1671
  any.
1661
1672
  */
@@ -1664,16 +1675,6 @@ var SelectionRange = class SelectionRange {
1664
1675
  return level == 7 ? null : level;
1665
1676
  }
1666
1677
  /**
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
1678
  Map this range through a change, producing a valid range in the
1678
1679
  updated document.
1679
1680
  */
@@ -1684,15 +1685,15 @@ var SelectionRange = class SelectionRange {
1684
1685
  from = change.mapPos(this.from, 1);
1685
1686
  to = change.mapPos(this.to, -1);
1686
1687
  }
1687
- return from == this.from && to == this.to ? this : new SelectionRange(from, to, this.flags);
1688
+ return from == this.from && to == this.to ? this : new SelectionRange(from, to, this.flags, this.goalColumn);
1688
1689
  }
1689
1690
  /**
1690
1691
  Extend this range to cover at least `from` to `to`.
1691
1692
  */
1692
- extend(from, to = from) {
1693
- if (from <= this.anchor && to >= this.anchor) return EditorSelection.range(from, to);
1693
+ extend(from, to = from, assoc = 0) {
1694
+ if (from <= this.anchor && to >= this.anchor) return EditorSelection.range(from, to, void 0, void 0, assoc);
1694
1695
  let head = Math.abs(from - this.anchor) > Math.abs(to - this.anchor) ? from : to;
1695
- return EditorSelection.range(this.anchor, head);
1696
+ return EditorSelection.range(this.anchor, head, void 0, void 0, assoc);
1696
1697
  }
1697
1698
  /**
1698
1699
  Compare this range to another range.
@@ -1720,8 +1721,8 @@ var SelectionRange = class SelectionRange {
1720
1721
  /**
1721
1722
  @internal
1722
1723
  */
1723
- static create(from, to, flags) {
1724
- return new SelectionRange(from, to, flags);
1724
+ static create(from, to, flags, goalColumn) {
1725
+ return new SelectionRange(from, to, flags, goalColumn);
1725
1726
  }
1726
1727
  };
1727
1728
  /**
@@ -1822,14 +1823,23 @@ var EditorSelection = class EditorSelection {
1822
1823
  safely ignore the optional arguments in most situations.
1823
1824
  */
1824
1825
  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)) | (goalColumn !== null && goalColumn !== void 0 ? goalColumn : 16777215) << 6);
1826
+ return SelectionRange.create(pos, pos, (assoc == 0 ? 0 : assoc < 0 ? 8 : 16) | (bidiLevel == null ? 7 : Math.min(6, bidiLevel)), goalColumn);
1826
1827
  }
1827
1828
  /**
1828
1829
  Create a selection range.
1829
1830
  */
1830
- static range(anchor, head, goalColumn, bidiLevel) {
1831
- let flags = (goalColumn !== null && goalColumn !== void 0 ? goalColumn : 16777215) << 6 | (bidiLevel == null ? 7 : Math.min(6, bidiLevel));
1832
- return head < anchor ? SelectionRange.create(head, anchor, 48 | flags) : SelectionRange.create(anchor, head, (head > anchor ? 8 : 0) | flags);
1831
+ static range(anchor, head, goalColumn, bidiLevel, assoc) {
1832
+ let flags = bidiLevel == null ? 7 : Math.min(6, bidiLevel);
1833
+ if (!assoc && anchor != head) assoc = head < anchor ? 1 : -1;
1834
+ if (assoc) flags |= assoc < 0 ? 8 : 16;
1835
+ return head < anchor ? SelectionRange.create(head, anchor, flags | 32, goalColumn) : SelectionRange.create(anchor, head, flags, goalColumn);
1836
+ }
1837
+ /**
1838
+ Create an [undirectional](https://codemirror.net/6/docs/ref/#state.SelectionRange.undirectional)
1839
+ selection range.
1840
+ */
1841
+ static undirectionalRange(from, to) {
1842
+ return SelectionRange.create(from, to, 64, void 0);
1833
1843
  }
1834
1844
  /**
1835
1845
  @internal
@@ -1975,6 +1985,9 @@ var FacetProvider = class {
1975
1985
  }
1976
1986
  };
1977
1987
  }
1988
+ get extension() {
1989
+ return this;
1990
+ }
1978
1991
  };
1979
1992
  function compareArray(a, b, compare) {
1980
1993
  if (a.length != b.length) return false;
@@ -2143,6 +2156,9 @@ var PrecExtension = class {
2143
2156
  this.inner = inner;
2144
2157
  this.prec = prec;
2145
2158
  }
2159
+ get extension() {
2160
+ return this;
2161
+ }
2146
2162
  };
2147
2163
  /**
2148
2164
  Extension compartments can be used to make a configuration
@@ -2182,6 +2198,9 @@ var CompartmentInstance = class {
2182
2198
  this.compartment = compartment;
2183
2199
  this.inner = inner;
2184
2200
  }
2201
+ get extension() {
2202
+ return this;
2203
+ }
2185
2204
  };
2186
2205
  var Configuration = class Configuration {
2187
2206
  constructor(base, compartments, dynamicSlots, address, staticValues, facets) {
@@ -2270,7 +2289,8 @@ function flatten(extension, compartments, newCompartments) {
2270
2289
  if (ext.facet.extensions) inner(ext.facet.extensions, Prec_.default);
2271
2290
  } else {
2272
2291
  let content = ext.extension;
2273
- if (!content) throw new Error(`Unrecognized extension value in extension set (${ext}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);
2292
+ if (!content) throw new Error(`Unrecognized extension value in extension set (${ext}).`);
2293
+ 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
2294
  inner(content, prec);
2275
2295
  }
2276
2296
  }
@@ -11511,12 +11531,13 @@ const BulkActionsBar = ({ count, onDuplicate, onMoveUp, onMoveDown, onDelete, on
11511
11531
  });
11512
11532
  };
11513
11533
  const Items = ({ value, render, onChange, onChildChange }) => {
11514
- const { objectItems, primitiveItems, allElements } = useMemo(() => {
11534
+ const { objectItems, primitiveItems, allElements, parseError } = useMemo(() => {
11515
11535
  const ast = parseArrayExpression(value);
11516
11536
  if (!ast) return {
11517
11537
  objectItems: [],
11518
11538
  primitiveItems: [],
11519
- allElements: []
11539
+ allElements: [],
11540
+ parseError: true
11520
11541
  };
11521
11542
  const objectItems = [];
11522
11543
  const primitiveItems = [];
@@ -11564,14 +11585,21 @@ const Items = ({ value, render, onChange, onChildChange }) => {
11564
11585
  return {
11565
11586
  objectItems,
11566
11587
  primitiveItems,
11567
- allElements
11588
+ allElements,
11589
+ parseError: false
11568
11590
  };
11569
11591
  }, [value]);
11592
+ useEffect(() => {
11593
+ if (parseError) Toast.error("Failed to parse items", { description: "Check the console for details." });
11594
+ }, [parseError]);
11570
11595
  const isPrimitive = primitiveItems.length > 0 && objectItems.length === 0;
11571
11596
  const selection = useMultiSelect(isPrimitive ? primitiveItems.length : objectItems.length);
11572
11597
  const updatePrimitive = (index, next) => {
11573
11598
  const ast = parseArrayExpression(value);
11574
- if (!ast) return;
11599
+ if (!ast) {
11600
+ Toast.error("Failed to update this item", { description: "Check the console for details." });
11601
+ return;
11602
+ }
11575
11603
  const elements = ast.elements.filter(Boolean);
11576
11604
  const item = primitiveItems.find((p) => p.index === index);
11577
11605
  if (!item) return;
@@ -12514,26 +12542,32 @@ const Node = ({ data, onChange }) => {
12514
12542
 
12515
12543
  //#endregion
12516
12544
  //#region src/components/dnd/panel/panel.tsx
12517
- const Panel = ({ item, onChange }) => {
12518
- const { dataAttrNodes, updatedCode } = useMemo(() => {
12545
+ const Panel = ({ item, onChange, onDelete }) => {
12546
+ const { dataAttrNodes, updatedCode, parseError } = useMemo(() => {
12519
12547
  if (!item?.code) return {
12520
12548
  dataAttrNodes: [],
12521
- updatedCode: ""
12549
+ updatedCode: "",
12550
+ parseError: false
12522
12551
  };
12523
12552
  try {
12524
12553
  const updatedCode = fillIds(item.code);
12525
12554
  return {
12526
12555
  dataAttrNodes: extract(updatedCode).filter((node) => node.tagName !== "section"),
12527
- updatedCode: updatedCode !== item.code ? updatedCode : item.code
12556
+ updatedCode: updatedCode !== item.code ? updatedCode : item.code,
12557
+ parseError: false
12528
12558
  };
12529
12559
  } catch (e) {
12530
12560
  console.warn("⚠️ Parsing error", e);
12531
12561
  return {
12532
12562
  dataAttrNodes: [],
12533
- updatedCode: ""
12563
+ updatedCode: "",
12564
+ parseError: true
12534
12565
  };
12535
12566
  }
12536
12567
  }, [item?.code]);
12568
+ useEffect(() => {
12569
+ if (parseError) Toast.error("Failed to parse this section", { description: "Check the console for details." });
12570
+ }, [parseError]);
12537
12571
  if (!item) return /* @__PURE__ */ jsx(Typography.Paragraph, {
12538
12572
  className: cn("p-4 text-sm text-gray-500"),
12539
12573
  children: "Please select a section."
@@ -12541,9 +12575,16 @@ const Panel = ({ item, onChange }) => {
12541
12575
  return /* @__PURE__ */ jsxs("div", {
12542
12576
  className: cn("h-full space-y-4 p-4", "overflow-x-hidden overflow-y-auto"),
12543
12577
  children: [
12544
- /* @__PURE__ */ jsx(Typography.Title, {
12545
- className: "text-lg font-semibold",
12546
- children: item.name
12578
+ /* @__PURE__ */ jsxs("div", {
12579
+ className: "flex items-center justify-between",
12580
+ children: [/* @__PURE__ */ jsx(Typography.Title, {
12581
+ className: "text-lg font-semibold",
12582
+ children: item.name
12583
+ }), onDelete && /* @__PURE__ */ jsx(Button, {
12584
+ danger: true,
12585
+ icon: /* @__PURE__ */ jsx(Trash, {}),
12586
+ onClick: () => onDelete(item.id)
12587
+ })]
12547
12588
  }),
12548
12589
  !dataAttrNodes.length && /* @__PURE__ */ jsx(Typography.Text, {
12549
12590
  className: "text-xs text-gray-400",
@@ -12552,9 +12593,14 @@ const Panel = ({ item, onChange }) => {
12552
12593
  dataAttrNodes.map((node, index) => /* @__PURE__ */ jsx(Node, {
12553
12594
  data: node,
12554
12595
  onChange: ({ id, label, value }) => {
12596
+ const result = update(updatedCode, id, label, value);
12597
+ if (!result.success) {
12598
+ Toast.error("Failed to update this field", { description: "Check the console for details." });
12599
+ return;
12600
+ }
12555
12601
  onChange?.({
12556
12602
  ...item,
12557
- code: update(updatedCode, id, label, value)
12603
+ code: result.code
12558
12604
  });
12559
12605
  }
12560
12606
  }, `${item.id}-${index}`))
@@ -12737,7 +12783,8 @@ const Dnd = ({ value: _value, props, modules = {}, onChange: _onChange, classNam
12737
12783
  className: "hidden w-1/5 md:block",
12738
12784
  children: /* @__PURE__ */ jsx(Panel, {
12739
12785
  item: sections.find((s) => s.id === selectedId),
12740
- onChange
12786
+ onChange,
12787
+ onDelete
12741
12788
  })
12742
12789
  }),
12743
12790
  /* @__PURE__ */ jsx(Button, {
@@ -12767,7 +12814,8 @@ const Dnd = ({ value: _value, props, modules = {}, onChange: _onChange, classNam
12767
12814
  title: "Properties",
12768
12815
  children: /* @__PURE__ */ jsx(Panel, {
12769
12816
  item: sections.find((s) => s.id === selectedId),
12770
- onChange
12817
+ onChange,
12818
+ onDelete
12771
12819
  })
12772
12820
  })
12773
12821
  ]