@jbpark/live-editor 1.16.3 → 1.17.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.
Files changed (41) hide show
  1. package/dist/{ast-DK9INzeu.js → ast-Cyi-jw9Z.js} +12 -15
  2. package/dist/ast-Cyi-jw9Z.js.map +1 -0
  3. package/dist/{boundary-BWBdNmNi.js → boundary-DUTt8lXq.js} +2 -2
  4. package/dist/{boundary-BWBdNmNi.js.map → boundary-DUTt8lXq.js.map} +1 -1
  5. package/dist/{context-DrqO0VVu.js → context-fLmciLSw.js} +3 -3
  6. package/dist/{context-DrqO0VVu.js.map → context-fLmciLSw.js.map} +1 -1
  7. package/dist/{core-B7igZRDs.js → core-ttOtjNaX.js} +2 -2
  8. package/dist/{core-B7igZRDs.js.map → core-ttOtjNaX.js.map} +1 -1
  9. package/dist/dnd/index.d.ts +2 -2
  10. package/dist/dnd/index.js +2 -2
  11. package/dist/{dnd-A3lFh7yx.js → dnd-D8hsq1Fl.js} +106 -113
  12. package/dist/dnd-D8hsq1Fl.js.map +1 -0
  13. package/dist/{document-CSIscFpL.js → document-DhMip8lL.js} +52 -6
  14. package/dist/document-DhMip8lL.js.map +1 -0
  15. package/dist/{document-DXOwpvWM.d.ts → document-J9Lo9p81.d.ts} +3 -2
  16. package/dist/editor/index.js +2 -2
  17. package/dist/{editor-DmgTeTcG.js → editor-Du55469f.js} +3 -3
  18. package/dist/{editor-DmgTeTcG.js.map → editor-Du55469f.js.map} +1 -1
  19. package/dist/error/index.js +2 -2
  20. package/dist/{error-ClMPS96R.js → error-BbOmgZDR.js} +2 -2
  21. package/dist/{error-ClMPS96R.js.map → error-BbOmgZDR.js.map} +1 -1
  22. package/dist/{index-rlgLRNsK.d.ts → index-Ly0DcdIH.d.ts} +3 -2
  23. package/dist/{index-CfuDi3An.d.ts → index-qdhllaw-.d.ts} +9 -4
  24. package/dist/index.d.ts +2 -2
  25. package/dist/index.js +5 -5
  26. package/dist/preview/index.js +1 -1
  27. package/dist/{preview-j-rIHbDN.js → preview-CQf0nwE6.js} +4 -4
  28. package/dist/{preview-j-rIHbDN.js.map → preview-CQf0nwE6.js.map} +1 -1
  29. package/dist/provider/index.js +1 -1
  30. package/dist/{use-dynamic-tailwind-D-EEKBIy.js → use-dynamic-tailwind-DkK3r-as.js} +2 -2
  31. package/dist/{use-dynamic-tailwind-D-EEKBIy.js.map → use-dynamic-tailwind-DkK3r-as.js.map} +1 -1
  32. package/dist/utils/ast/index.d.ts +3 -3
  33. package/dist/utils/ast/index.js +3 -3
  34. package/dist/utils/index.d.ts +1 -1
  35. package/dist/utils/index.js +2 -2
  36. package/dist/{utils-BzfDKU6y.js → utils-CCrTYGUG.js} +2 -2
  37. package/dist/{utils-BzfDKU6y.js.map → utils-CCrTYGUG.js.map} +1 -1
  38. package/package.json +1 -1
  39. package/dist/ast-DK9INzeu.js.map +0 -1
  40. package/dist/dnd-A3lFh7yx.js.map +0 -1
  41. package/dist/document-CSIscFpL.js.map +0 -1
@@ -1,2 +1,2 @@
1
- import { a as Props, c as DraggableItemProps, i as PanelRenderData, n as PaletteRenderData, o as DraggableItem, r as PanelBinding, s as DraggableItemDragState, t as Dnd } from "../index-CfuDi3An.js";
2
- export { DraggableItem, type DraggableItemDragState, type DraggableItemProps, type PaletteRenderData, type PanelBinding, type PanelRenderData, type Props, Dnd as default };
1
+ import { a as PanelRenderData, c as DraggableItemDragState, i as PanelBinding, l as DraggableItemProps, n as ICON_MAP, o as Props, r as PaletteRenderData, s as DraggableItem, t as Dnd } from "../index-qdhllaw-.js";
2
+ export { DraggableItem, type DraggableItemDragState, type DraggableItemProps, ICON_MAP, type PaletteRenderData, type PanelBinding, type PanelRenderData, type Props, Dnd as default };
package/dist/dnd/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import { n as DraggableItem, t as Dnd } from "../dnd-A3lFh7yx.js";
2
- export { DraggableItem, Dnd as default };
1
+ import { n as ICON_MAP, r as DraggableItem, t as Dnd } from "../dnd-D8hsq1Fl.js";
2
+ export { DraggableItem, ICON_MAP, Dnd as default };
@@ -1,11 +1,11 @@
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 { d as replaceSections, o as extractSections, r as cn, s as generateSection, u as preloadScripts } from "./utils-BzfDKU6y.js";
1
+ import { C as __toESM, b as DRAGGABLE_ITEMS, f as nanoid, g as BINDING_PROP, h as require_lib, m as require_lib$1, n as createSectionPreviewCache, r as fillSectionIds, y as DEFAULT_TEMPLATE } from "./document-DhMip8lL.js";
2
+ import { d as replaceSections, o as extractSections, r as cn, s as generateSection, u as preloadScripts } from "./utils-CCrTYGUG.js";
3
3
  import { i as usePreview } from "./states-Ci1AvoQ9.js";
4
- import { 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 parseArrayExpression, x as generateCode, y as parseValue } from "./ast-DK9INzeu.js";
5
- import { n as useCompiledModule, r as Frame, t as useDynamicTailwind } from "./use-dynamic-tailwind-D-EEKBIy.js";
6
- import { n as Error, t as ErrorBoundary } from "./boundary-BWBdNmNi.js";
7
- import { t as Core } from "./core-B7igZRDs.js";
8
- import { memo, useEffect, useMemo, useRef, useState } from "react";
4
+ import { _ as parseArrayExpression, b as generateCode, c as extract, d as parseBinding, f as arrayExpressionToCode, h as extractObjectProperties, i as replaceIds, l as findEditableChildren, m as extractNodeValue, n as clone, o as update, p as createNodeFromValue, r as fillIds, t as validateBindingValue, u as getCurrentValue, v as parseValue } from "./ast-Cyi-jw9Z.js";
5
+ import { n as useCompiledModule, r as Frame, t as useDynamicTailwind } from "./use-dynamic-tailwind-DkK3r-as.js";
6
+ import { n as Error, t as ErrorBoundary } from "./boundary-DUTt8lXq.js";
7
+ import { t as Core } from "./core-ttOtjNaX.js";
8
+ import { memo, useCallback, useEffect, useMemo, useRef, useState } from "react";
9
9
  import { Button, Card, Checkbox, ColorPicker, DatePicker, Drawer, Input, Select, Space, 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";
@@ -13,7 +13,6 @@ import { restrictToVerticalAxis } from "@dnd-kit/modifiers";
13
13
  import { SortableContext, arrayMove, useSortable, verticalListSortingStrategy } from "@dnd-kit/sortable";
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
- import { v4 } from "uuid";
17
16
  import { CSS } from "@dnd-kit/utilities";
18
17
  import Placeholder from "@tiptap/extension-placeholder";
19
18
  import { EditorContent, useEditor } from "@tiptap/react";
@@ -1167,7 +1166,7 @@ const Field = ({ binding, id, value, onChange }) => {
1167
1166
  className: "mt-1 text-xs text-red-500",
1168
1167
  children: validationError
1169
1168
  })] });
1170
- if (binding.type === "icon-picker") {
1169
+ if (binding.widget === "icon-picker" || binding.type === "icon-picker") {
1171
1170
  const SelectedIcon = ICON_MAP[stringValue];
1172
1171
  return /* @__PURE__ */ jsxs("div", {
1173
1172
  className: "flex items-center gap-2",
@@ -1188,7 +1187,7 @@ const Field = ({ binding, id, value, onChange }) => {
1188
1187
  })]
1189
1188
  });
1190
1189
  }
1191
- if (binding.type === "asset-picker") {
1190
+ if (binding.widget === "asset-picker" || binding.type === "asset-picker") {
1192
1191
  const defaultUploadValue = stringValue ? [{
1193
1192
  uid: "current",
1194
1193
  name: stringValue.split("/").pop() || "asset",
@@ -1373,6 +1372,90 @@ const Panel = ({ item, onDelete, onMoveUp, onMoveDown, canMoveUp = false, canMov
1373
1372
  });
1374
1373
  };
1375
1374
  //#endregion
1375
+ //#region src/components/dnd/use-section-document.ts
1376
+ const useSectionDocument = (value, onChange) => {
1377
+ const { setCode } = usePreview();
1378
+ const [selectedId, setSelectedId] = useState(null);
1379
+ const document = useMemo(() => fillSectionIds(value), [value]);
1380
+ const sections = useMemo(() => extractSections(document), [document]);
1381
+ const [previewCache] = useState(() => createSectionPreviewCache());
1382
+ const previews = useMemo(() => previewCache.compute(document, sections), [
1383
+ previewCache,
1384
+ sections,
1385
+ document
1386
+ ]);
1387
+ const selectedIndex = sections.findIndex((s) => s.id === selectedId);
1388
+ const selectedItem = selectedIndex >= 0 ? sections[selectedIndex] : void 0;
1389
+ const commit = useCallback((nextSections) => {
1390
+ const nextCode = fillSectionIds(replaceSections(document, nextSections.map((s) => s.code)));
1391
+ onChange?.(nextCode);
1392
+ setCode(nextCode);
1393
+ return extractSections(nextCode);
1394
+ }, [
1395
+ document,
1396
+ onChange,
1397
+ setCode
1398
+ ]);
1399
+ return {
1400
+ sections,
1401
+ previews,
1402
+ selectedId,
1403
+ selectedItem,
1404
+ selectedIndex,
1405
+ select: useCallback((id) => {
1406
+ setSelectedId((prev) => prev === id ? null : id);
1407
+ }, []),
1408
+ clearSelection: useCallback(() => setSelectedId(null), []),
1409
+ add: useCallback((item, atIndex) => {
1410
+ const next = { code: item.code };
1411
+ commit(atIndex === void 0 || atIndex < 0 ? [...sections, next] : [
1412
+ ...sections.slice(0, atIndex),
1413
+ next,
1414
+ ...sections.slice(atIndex)
1415
+ ]);
1416
+ }, [commit, sections]),
1417
+ remove: useCallback((id) => {
1418
+ const index = sections.findIndex((s) => s.id === id);
1419
+ if (index < 0) return;
1420
+ if (id === selectedId) setSelectedId(null);
1421
+ commit(sections.filter((_, i) => i !== index));
1422
+ }, [
1423
+ commit,
1424
+ sections,
1425
+ selectedId
1426
+ ]),
1427
+ copy: useCallback((id) => {
1428
+ const index = sections.findIndex((s) => s.id === id);
1429
+ const source = sections[index];
1430
+ if (!source) return;
1431
+ const committed = commit([
1432
+ ...sections.slice(0, index + 1),
1433
+ { code: replaceIds(source.code) },
1434
+ ...sections.slice(index + 1)
1435
+ ]);
1436
+ setSelectedId(committed[index + 1]?.id ?? null);
1437
+ }, [commit, sections]),
1438
+ move: useCallback((id, direction) => {
1439
+ const index = sections.findIndex((s) => s.id === id);
1440
+ const targetIndex = direction === "up" ? index - 1 : index + 1;
1441
+ if (index < 0 || targetIndex < 0 || targetIndex >= sections.length) return;
1442
+ commit(arrayMove(sections, index, targetIndex));
1443
+ }, [commit, sections]),
1444
+ reorder: useCallback((activeId, overId) => {
1445
+ const prevIndex = sections.findIndex((s) => s.id === activeId);
1446
+ const nextIndex = sections.findIndex((s) => s.id === overId);
1447
+ if (prevIndex < 0 || nextIndex < 0 || prevIndex === nextIndex) return;
1448
+ commit(arrayMove(sections, prevIndex, nextIndex));
1449
+ }, [commit, sections]),
1450
+ patch: useCallback((next) => {
1451
+ commit(sections.map((s) => s.id === next.id ? {
1452
+ ...s,
1453
+ ...next
1454
+ } : s));
1455
+ }, [commit, sections])
1456
+ };
1457
+ };
1458
+ //#endregion
1376
1459
  //#region src/components/dnd/dnd.tsx
1377
1460
  const conditionalModifiers = (args) => {
1378
1461
  const { active } = args;
@@ -1380,120 +1463,30 @@ const conditionalModifiers = (args) => {
1380
1463
  return restrictToVerticalAxis(args);
1381
1464
  };
1382
1465
  const Dnd$1 = ({ value: _value, props, modules = {}, onChange: _onChange, className, items = [], frame, dynamicTailwind = false, provider, renderPalette, renderPanel, ...restProps }) => {
1383
- const [selectedId, setSelectedId] = useState(null);
1384
1466
  const [mobilePaletteOpen, setMobilePaletteOpen] = useState(false);
1385
1467
  const { breakpoint } = useResponsiveSize();
1386
1468
  const isMobile = breakpoint.current === "xs" || breakpoint.current === "sm";
1387
- const { code, setCode } = usePreview();
1469
+ const { code } = usePreview();
1388
1470
  const sensors = useSensors(useSensor(PointerSensor, { activationConstraint: { distance: 10 } }));
1389
1471
  const value = _value || code || DEFAULT_TEMPLATE;
1390
- const sections = useMemo(() => extractSections(value), [value]);
1391
- const selectedItem = useMemo(() => sections.find((s) => s.id === selectedId), [sections, selectedId]);
1392
- const [previewCache] = useState(() => createSectionPreviewCache());
1393
- const previews = useMemo(() => previewCache.compute(value, sections), [
1394
- previewCache,
1395
- sections,
1396
- value
1397
- ]);
1472
+ const { sections, previews, selectedId, selectedItem, selectedIndex, select, clearSelection, add: addItem, remove: onDelete, copy: onCopy, move: moveSection, reorder, patch } = useSectionDocument(value, _onChange);
1398
1473
  const onDragStart = (_) => {};
1399
1474
  const onDragOver = (_e) => {};
1400
1475
  const onDragEnd = (event) => {
1401
1476
  const { active, over } = event;
1402
1477
  if (!over) return;
1403
1478
  if (active.data.current?.type === "new-item") {
1404
- const newItem = active.data.current.item;
1405
- const newSection = {
1406
- id: v4(),
1407
- name: newItem.name,
1408
- code: newItem.code
1409
- };
1410
- let nextSections;
1411
- if (over.id === "sortable-area" || over.id === "sortable-area-bottom") nextSections = [...sections, newSection];
1412
- else {
1413
- const overIndex = sections.findIndex((s) => s.id === over.id);
1414
- if (overIndex >= 0) nextSections = [
1415
- ...sections.slice(0, overIndex),
1416
- newSection,
1417
- ...sections.slice(overIndex)
1418
- ];
1419
- else nextSections = [...sections, newSection];
1420
- }
1421
- const nextCode = replaceSections(value, nextSections.map((s) => s.code));
1422
- _onChange?.(nextCode);
1423
- setCode(nextCode);
1479
+ const item = active.data.current.item;
1480
+ const atBottom = over.id === "sortable-area" || over.id === "sortable-area-bottom";
1481
+ addItem(item, atBottom ? void 0 : sections.findIndex((s) => s.id === over.id));
1424
1482
  return;
1425
1483
  }
1426
- if (active.id !== over.id && sections.some((s) => s.id === active.id)) {
1427
- const prevIndex = sections.findIndex((s) => s.id === active.id);
1428
- const nextIndex = sections.findIndex((s) => s.id === over.id);
1429
- if (prevIndex >= 0 && nextIndex >= 0) {
1430
- const nextSections = arrayMove(sections, prevIndex, nextIndex);
1431
- const nextCode = replaceSections(value, nextSections.map((s) => s.code));
1432
- _onChange?.(nextCode);
1433
- setCode(nextCode);
1434
- }
1435
- }
1436
- };
1437
- const addItem = (item) => {
1438
- const newSection = {
1439
- id: v4(),
1440
- name: item.name,
1441
- code: item.code
1442
- };
1443
- const nextSections = [...sections, newSection];
1444
- const nextCode = replaceSections(value, nextSections.map((s) => s.code));
1445
- _onChange?.(nextCode);
1446
- setCode(nextCode);
1447
- };
1448
- const onDelete = (id) => {
1449
- const nextSections = sections.filter((s) => s.id !== id);
1450
- setSelectedId(null);
1451
- const nextCode = replaceSections(value, nextSections.map((s) => s.code));
1452
- _onChange?.(nextCode);
1453
- setCode(nextCode);
1454
- };
1455
- const moveSection = (id, direction) => {
1456
- const index = sections.findIndex((s) => s.id === id);
1457
- const targetIndex = direction === "up" ? index - 1 : index + 1;
1458
- if (index < 0 || targetIndex < 0 || targetIndex >= sections.length) return;
1459
- const nextSections = arrayMove(sections, index, targetIndex);
1460
- const nextCode = replaceSections(value, nextSections.map((s) => s.code));
1461
- _onChange?.(nextCode);
1462
- setCode(nextCode);
1463
- setSelectedId(String(targetIndex));
1464
- };
1465
- const onCopy = (id) => {
1466
- const sectionIndex = sections.findIndex((s) => s.id === id);
1467
- const sectionToCopy = sections[sectionIndex];
1468
- if (sectionToCopy) {
1469
- const nextId = v4();
1470
- const nextSection = {
1471
- id: nextId,
1472
- code: replaceIds(sectionToCopy.code),
1473
- name: sectionToCopy.name
1474
- };
1475
- const nextSections = [
1476
- ...sections.slice(0, sectionIndex + 1),
1477
- nextSection,
1478
- ...sections.slice(sectionIndex + 1)
1479
- ];
1480
- setSelectedId(nextId);
1481
- const nextCode = replaceSections(value, nextSections.map((s) => s.code));
1482
- _onChange?.(nextCode);
1483
- setCode(nextCode);
1484
- }
1485
- };
1486
- const onSelect = (id) => {
1487
- setSelectedId((prev) => prev === id ? null : id);
1484
+ if (active.id !== over.id && sections.some((s) => s.id === active.id)) reorder(String(active.id), String(over.id));
1488
1485
  };
1486
+ const onSelect = (id) => select(id);
1489
1487
  const onChange = (next) => {
1490
- const nextSections = sections.map((s) => s.id === next.id ? {
1491
- ...s,
1492
- ...next
1493
- } : s);
1494
- const nextCode = replaceSections(value, nextSections.map((s) => s.code));
1495
- _onChange?.(nextCode);
1496
- setCode(nextCode);
1488
+ if (!next.id) return;
1489
+ patch(next);
1497
1490
  };
1498
1491
  const selectedCode = selectedItem?.code;
1499
1492
  const { fields, updatedCode, parseError } = useMemo(() => {
@@ -1542,6 +1535,7 @@ const Dnd$1 = ({ value: _value, props, modules = {}, onChange: _onChange, classN
1542
1535
  label: binding.label,
1543
1536
  property: binding.property,
1544
1537
  type: binding.type,
1538
+ widget: binding.widget,
1545
1539
  options: binding.options,
1546
1540
  render: binding.render,
1547
1541
  min: binding.min,
@@ -1580,7 +1574,6 @@ const Dnd$1 = ({ value: _value, props, modules = {}, onChange: _onChange, classN
1580
1574
  });
1581
1575
  };
1582
1576
  const renderPanelContent = () => {
1583
- const selectedIndex = sections.findIndex((s) => s.id === selectedId);
1584
1577
  const canMoveUp = selectedIndex > 0;
1585
1578
  const canMoveDown = selectedIndex >= 0 && selectedIndex < sections.length - 1;
1586
1579
  if (renderPanel) return renderPanel({
@@ -1686,7 +1679,7 @@ const Dnd$1 = ({ value: _value, props, modules = {}, onChange: _onChange, classN
1686
1679
  }),
1687
1680
  /* @__PURE__ */ jsx(Drawer, {
1688
1681
  open: isMobile && Boolean(selectedId),
1689
- onClose: () => setSelectedId(null),
1682
+ onClose: clearSelection,
1690
1683
  direction: "bottom",
1691
1684
  size: "large",
1692
1685
  title: "Properties",
@@ -1710,6 +1703,6 @@ const Dnd$1 = ({ value: _value, props, modules = {}, onChange: _onChange, classN
1710
1703
  const Dnd = Dnd$1;
1711
1704
  Dnd.DraggableItem = DraggableItem;
1712
1705
  //#endregion
1713
- export { DraggableItem as n, Dnd as t };
1706
+ export { ICON_MAP as n, DraggableItem as r, Dnd as t };
1714
1707
 
1715
- //# sourceMappingURL=dnd-A3lFh7yx.js.map
1708
+ //# sourceMappingURL=dnd-D8hsq1Fl.js.map