@particle-academy/fancy-cms-ui 0.4.0 → 0.5.1

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/editor.d.cts CHANGED
@@ -1,6 +1,7 @@
1
- export { C as Canvas, a as CanvasProps, E as Editor, b as EditorAction, c as EditorApi, d as EditorProps, e as EditorState, I as Inspector, f as InspectorProps, L as LayersPanel, g as LayersPanelProps, i as editorReduce, j as initEditor, u as useEditor } from './useEditor-BQtAHLHl.cjs';
1
+ export { C as Canvas, a as CanvasProps, E as Editor, b as EditorAction, c as EditorApi, d as EditorProps, e as EditorState, I as Inspector, f as InspectorProps, L as LayersPanel, g as LayersPanelProps, i as editorReduce, j as initEditor, u as useEditor } from './useEditor-Dr_Gg7gu.cjs';
2
2
  import { ReactNode, ReactElement } from 'react';
3
- import { P as PageDoc, h as ElementRegistry, g as DataContext, N as Node, p as StyleProps, L as LayoutMode } from './registry-D5y5IgCR.cjs';
3
+ import { P as PageDoc, h as ElementRegistry, g as DataContext, N as Node, q as StyleProps, L as LayoutMode } from './registry-CvzbUd5E.cjs';
4
+ import '@particle-academy/fancy-doc-commons';
4
5
 
5
6
  /** Animatable per-node transform (mirrors fancy-motion's NodeState, kept local to avoid a hard dep). */
6
7
  interface NodeTransform {
@@ -76,4 +77,4 @@ interface NodeInspectorProps {
76
77
  */
77
78
  declare function NodeInspector({ node, transform, measured, onProps, onStyle, onLayout, onTransform, onRemove, onClose, }: NodeInspectorProps): ReactElement;
78
79
 
79
- export { EditablePage, type EditablePageProps, NodeInspector, type NodeInspectorProps };
80
+ export { EditablePage, type EditablePageProps, NodeInspector, type NodeInspectorProps, type NodeTransform };
package/dist/editor.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- export { C as Canvas, a as CanvasProps, E as Editor, b as EditorAction, c as EditorApi, d as EditorProps, e as EditorState, I as Inspector, f as InspectorProps, L as LayersPanel, g as LayersPanelProps, i as editorReduce, j as initEditor, u as useEditor } from './useEditor-CpX-LbfH.js';
1
+ export { C as Canvas, a as CanvasProps, E as Editor, b as EditorAction, c as EditorApi, d as EditorProps, e as EditorState, I as Inspector, f as InspectorProps, L as LayersPanel, g as LayersPanelProps, i as editorReduce, j as initEditor, u as useEditor } from './useEditor-BGKnLQuK.js';
2
2
  import { ReactNode, ReactElement } from 'react';
3
- import { P as PageDoc, h as ElementRegistry, g as DataContext, N as Node, p as StyleProps, L as LayoutMode } from './registry-D5y5IgCR.js';
3
+ import { P as PageDoc, h as ElementRegistry, g as DataContext, N as Node, q as StyleProps, L as LayoutMode } from './registry-CvzbUd5E.js';
4
+ import '@particle-academy/fancy-doc-commons';
4
5
 
5
6
  /** Animatable per-node transform (mirrors fancy-motion's NodeState, kept local to avoid a hard dep). */
6
7
  interface NodeTransform {
@@ -76,4 +77,4 @@ interface NodeInspectorProps {
76
77
  */
77
78
  declare function NodeInspector({ node, transform, measured, onProps, onStyle, onLayout, onTransform, onRemove, onClose, }: NodeInspectorProps): ReactElement;
78
79
 
79
- export { EditablePage, type EditablePageProps, NodeInspector, type NodeInspectorProps };
80
+ export { EditablePage, type EditablePageProps, NodeInspector, type NodeInspectorProps, type NodeTransform };
package/dist/editor.js CHANGED
@@ -1,8 +1,9 @@
1
- import { useEditor, useLatestRef, CONTAINER_TYPES, keyBetween, ADD_DEFAULTS, ADD_MENU } from './chunk-6Q7DKNDZ.js';
2
- export { Canvas, Editor, Inspector, LayersPanel, editorReduce, initEditor, useEditor } from './chunk-6Q7DKNDZ.js';
3
- import { isBinding, childrenOf, CmsPage, defaultRegistry } from './chunk-GOXVGEKU.js';
1
+ import { useEditor, useLatestRef, CONTAINER_TYPES, ADD_DEFAULTS, ADD_MENU } from './chunk-5VNXIAHG.js';
2
+ export { Canvas, Editor, Inspector, LayersPanel, editorReduce, initEditor, useEditor } from './chunk-5VNXIAHG.js';
3
+ import { isBinding, lastRootId, childrenOf, CmsPage, defaultRegistry } from './chunk-FDCP3LVR.js';
4
4
  import { useState, useRef, useEffect, useCallback, useLayoutEffect } from 'react';
5
5
  import { ContextMenu } from '@particle-academy/react-fancy';
6
+ import { fractionalKey } from '@particle-academy/fancy-doc-commons';
6
7
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
7
8
 
8
9
  var CONTAINER_TYPES2 = /* @__PURE__ */ new Set(["section", "frame", "stack", "grid", "shape", "card", "device"]);
@@ -265,8 +266,6 @@ var input = {
265
266
  };
266
267
  var iconBtn = { background: "transparent", border: "none", color: "#e2e8f0", cursor: "pointer", fontSize: 13, padding: 4, borderRadius: 6 };
267
268
  var miniBtn = { font: "inherit", fontSize: 11, color: "#e2e8f0", background: "#334155", border: "1px solid #475569", borderRadius: 6, padding: "5px 10px", cursor: "pointer" };
268
-
269
- // src/editor/editorOps.ts
270
269
  function childrenOfMap(nodes, parent) {
271
270
  return Object.values(nodes).filter((n) => n.parent === parent).sort((a, b) => a.order < b.order ? -1 : a.order > b.order ? 1 : 0);
272
271
  }
@@ -300,20 +299,20 @@ function duplicateOps(doc, id) {
300
299
  if (!node) return { ops: [], newRootId: null };
301
300
  const sibs = childrenOf(doc, node.parent);
302
301
  const idx = sibs.findIndex((s) => s.id === id);
303
- const newOrder = keyBetween(node.order, sibs[idx + 1]?.order ?? null);
302
+ const newOrder = fractionalKey(node.order, sibs[idx + 1]?.order ?? null);
304
303
  const { ops, newRootId } = cloneFrom(doc.nodes, id, node.parent, newOrder, doc.seq);
305
304
  if (node.parent === null && newRootId) {
306
- const base = doc.sections;
305
+ const base = childrenOf(doc, null).map((n) => n.id);
307
306
  const at = base.indexOf(id);
308
- ops.push({ t: "reorder_sections", order: [...base.slice(0, at + 1), newRootId, ...base.slice(at + 1)] });
307
+ ops.push({ t: "reorder_roots", order: [...base.slice(0, at + 1), newRootId, ...base.slice(at + 1)] });
309
308
  }
310
309
  return { ops, newRootId };
311
310
  }
312
311
  function pasteOps(doc, clip, target, containerTypes) {
313
312
  const sel = target ? doc.nodes[target] : null;
314
- const parent = sel ? containerTypes.has(sel.type) ? sel.id : sel.parent : doc.sections[doc.sections.length - 1] ?? null;
313
+ const parent = sel ? containerTypes.has(sel.type) ? sel.id : sel.parent : lastRootId(doc);
315
314
  const sibs = childrenOf(doc, parent);
316
- const newOrder = keyBetween(sibs.length ? sibs[sibs.length - 1].order : null, null);
315
+ const newOrder = fractionalKey(sibs.length ? sibs[sibs.length - 1].order : null, null);
317
316
  const { ops, newRootId } = cloneFrom(clip.nodes, clip.rootId, parent, newOrder, doc.seq);
318
317
  return { ops, newRootId };
319
318
  }
@@ -321,14 +320,14 @@ function reorderOps(doc, id, dir) {
321
320
  const node = doc.nodes[id];
322
321
  if (!node) return [];
323
322
  if (node.parent === null) {
324
- const s = [...doc.sections];
323
+ const s = childrenOf(doc, null).map((n) => n.id);
325
324
  const i = s.indexOf(id);
326
325
  if (i < 0) return [];
327
326
  s.splice(i, 1);
328
327
  if (dir === "front") s.unshift(id);
329
328
  else if (dir === "back") s.push(id);
330
329
  else s.splice(Math.max(0, Math.min(s.length, dir === "up" ? i - 1 : i + 1)), 0, id);
331
- return [{ t: "reorder_sections", order: s }];
330
+ return [{ t: "reorder_roots", order: s }];
332
331
  }
333
332
  const sibs = childrenOf(doc, node.parent);
334
333
  const idx = sibs.findIndex((sb) => sb.id === id);
@@ -337,16 +336,16 @@ function reorderOps(doc, id, dir) {
337
336
  let newOrder;
338
337
  if (dir === "up") {
339
338
  if (idx <= 0) return [];
340
- newOrder = keyBetween(sibs[idx - 2]?.order ?? null, sibs[idx - 1].order);
339
+ newOrder = fractionalKey(sibs[idx - 2]?.order ?? null, sibs[idx - 1].order);
341
340
  } else if (dir === "down") {
342
341
  if (idx >= last) return [];
343
- newOrder = keyBetween(sibs[idx + 1].order, sibs[idx + 2]?.order ?? null);
342
+ newOrder = fractionalKey(sibs[idx + 1].order, sibs[idx + 2]?.order ?? null);
344
343
  } else if (dir === "front") {
345
344
  if (idx >= last) return [];
346
- newOrder = keyBetween(sibs[last].order, null);
345
+ newOrder = fractionalKey(sibs[last].order, null);
347
346
  } else {
348
347
  if (idx <= 0) return [];
349
- newOrder = keyBetween(null, sibs[0].order);
348
+ newOrder = fractionalKey(null, sibs[0].order);
350
349
  }
351
350
  return [{ t: "move_node", id, parent: node.parent, order: newOrder }];
352
351
  }
@@ -479,9 +478,9 @@ function EditablePage({
479
478
  const addNode = useCallback(
480
479
  (kind) => {
481
480
  const doc2 = ed.state.doc;
482
- const parent = selNode ? CONTAINER_TYPES.has(selNode.type) ? selNode.id : selNode.parent : doc2.sections[doc2.sections.length - 1] ?? null;
481
+ const parent = selNode ? CONTAINER_TYPES.has(selNode.type) ? selNode.id : selNode.parent : lastRootId(doc2);
483
482
  const siblings = childrenOf(doc2, parent);
484
- const order = keyBetween(siblings.length ? siblings[siblings.length - 1].order : null, null);
483
+ const order = fractionalKey(siblings.length ? siblings[siblings.length - 1].order : null, null);
485
484
  const id = `n${doc2.seq + 1}-${Math.floor(performance.now())}`;
486
485
  const def = ADD_DEFAULTS[kind];
487
486
  ed.apply({ t: "insert_node", node: { id, type: def.type, parent, order, layout: def.layout, props: { ...def.props }, style: { base: { ...def.style } } } });
@@ -493,9 +492,9 @@ function EditablePage({
493
492
  (kind, targetId) => {
494
493
  const doc2 = ed.state.doc;
495
494
  const target = targetId ? doc2.nodes[targetId] : null;
496
- const parent = target ? CONTAINER_TYPES.has(target.type) ? target.id : target.parent : doc2.sections[doc2.sections.length - 1] ?? null;
495
+ const parent = target ? CONTAINER_TYPES.has(target.type) ? target.id : target.parent : lastRootId(doc2);
497
496
  const siblings = childrenOf(doc2, parent);
498
- const order = keyBetween(siblings.length ? siblings[siblings.length - 1].order : null, null);
497
+ const order = fractionalKey(siblings.length ? siblings[siblings.length - 1].order : null, null);
499
498
  const id = `n${doc2.seq + 1}-${Math.floor(performance.now())}`;
500
499
  const def = ADD_DEFAULTS[kind];
501
500
  ed.apply({ t: "insert_node", node: { id, type: def.type, parent, order, layout: def.layout, props: { ...def.props }, style: { base: { ...def.style } } } });
@@ -539,15 +538,15 @@ function EditablePage({
539
538
  let parent;
540
539
  let order;
541
540
  if (!hint.id || hint.edge === "inside") {
542
- parent = hint.id ?? (doc2.sections[doc2.sections.length - 1] ?? null);
541
+ parent = hint.id ?? lastRootId(doc2);
543
542
  const sib = childrenOf(doc2, parent);
544
- order = keyBetween(sib.length ? sib[sib.length - 1].order : null, null);
543
+ order = fractionalKey(sib.length ? sib[sib.length - 1].order : null, null);
545
544
  } else {
546
545
  const target = doc2.nodes[hint.id];
547
546
  parent = target.parent;
548
547
  const sib = childrenOf(doc2, parent);
549
548
  const idx = sib.findIndex((n) => n.id === hint.id);
550
- order = hint.edge === "before" ? keyBetween(idx > 0 ? sib[idx - 1].order : null, target.order) : keyBetween(target.order, idx < sib.length - 1 ? sib[idx + 1].order : null);
549
+ order = hint.edge === "before" ? fractionalKey(idx > 0 ? sib[idx - 1].order : null, target.order) : fractionalKey(target.order, idx < sib.length - 1 ? sib[idx + 1].order : null);
551
550
  }
552
551
  const id = `n${doc2.seq + 1}-${Math.floor(performance.now())}`;
553
552
  const def = ADD_DEFAULTS[kind];