@jbpark/live-editor 1.5.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/dist/index.mjs CHANGED
@@ -1,9 +1,9 @@
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";
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";
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";
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";
@@ -397,13 +397,12 @@ const Droppable = ({ children, className }) => {
397
397
 
398
398
  //#endregion
399
399
  //#region src/components/dnd/renderer.tsx
400
- const Renderer = ({ fullCode, code, headers, modules, frame, provider }) => {
400
+ const Renderer = ({ preview, headers, modules, frame, provider }) => {
401
401
  const memoizedModules = useMemo(() => ({
402
402
  ...baseModules,
403
403
  ...modules
404
404
  }), [modules]);
405
- const memoizedSection = useMemo(() => generateSection(code, fullCode), [code, fullCode]);
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,14 +477,18 @@ 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) return /* @__PURE__ */ jsx(Sortable, {
481
- id: section.id,
482
- name: section.name,
483
- children: /* @__PURE__ */ jsx(Renderer, {
484
- ...renderProps,
485
- code: section.code
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
 
@@ -12624,6 +12628,7 @@ const Dnd = ({ value: _value, props, modules = {}, onChange: _onChange, classNam
12624
12628
  const sensors = useSensors(useSensor(PointerSensor, { activationConstraint: { distance: 10 } }));
12625
12629
  const value = _value || DEFAULT_TEMPLATE;
12626
12630
  const sections = useMemo(() => extractSections(value), [value]);
12631
+ const previews = useMemo(() => generateSections(sections.map((s) => s.code), value), [sections, value]);
12627
12632
  const onDragStart = (_) => {};
12628
12633
  const onDragOver = (_e) => {};
12629
12634
  const onDragEnd = (event) => {
@@ -12760,16 +12765,15 @@ const Dnd = ({ value: _value, props, modules = {}, onChange: _onChange, classNam
12760
12765
  }) : /* @__PURE__ */ jsx(SortableContext, {
12761
12766
  items: sections.map((s) => s.id),
12762
12767
  strategy: verticalListSortingStrategy,
12763
- children: sections.map((section) => /* @__PURE__ */ jsx(Sortable, {
12768
+ children: sections.map((section, index) => /* @__PURE__ */ jsx(Sortable, {
12764
12769
  id: section.id,
12765
12770
  name: section.name,
12766
12771
  selected: selectedId === section.id,
12767
12772
  onClick: () => onSelect(section.id),
12768
12773
  onDelete,
12769
12774
  onCopy,
12770
- children: /* @__PURE__ */ jsx(Renderer, {
12771
- fullCode: value,
12772
- code: section.code,
12775
+ children: /* @__PURE__ */ jsx(renderer_default, {
12776
+ preview: previews[index],
12773
12777
  modules,
12774
12778
  frame,
12775
12779
  provider,