@particle-academy/fancy-cms-ui 0.7.0 → 0.7.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.cjs CHANGED
@@ -6,17 +6,50 @@ var jsxRuntime = require('react/jsx-runtime');
6
6
  var reactFancy = require('@particle-academy/react-fancy');
7
7
 
8
8
  // src/editor/Editor.tsx
9
+
10
+ // src/document/types.ts
11
+ function isBinding(v) {
12
+ return typeof v === "object" && v !== null && typeof v.$bind === "string";
13
+ }
14
+ function hasNodeMap(value) {
15
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
16
+ const nodes = value.nodes;
17
+ return typeof nodes === "object" && nodes !== null && !Array.isArray(nodes);
18
+ }
19
+ var DEFAULT_BREAKPOINTS = {
20
+ base: 0,
21
+ md: 768,
22
+ lg: 1024
23
+ };
24
+ function emptyDoc(id, slug = "/") {
25
+ return {
26
+ id,
27
+ seq: 0,
28
+ meta: { title: "Untitled", slug, scrollMode: "smooth" },
29
+ theme: { name: "default" },
30
+ breakpoints: ["base", "md", "lg"],
31
+ nodes: {}
32
+ };
33
+ }
34
+
35
+ // src/document/migrate.ts
36
+ function normalizeDoc(input3) {
37
+ if (hasNodeMap(input3)) return input3;
38
+ const id = typeof input3 === "object" && input3 !== null && !Array.isArray(input3) && typeof input3.id === "string" ? input3.id : "malformed";
39
+ return emptyDoc(id);
40
+ }
9
41
  function migrateDocVerbose(input3) {
10
- const legacy = input3;
42
+ const normalized = normalizeDoc(input3);
43
+ const legacy = normalized;
11
44
  const sections = legacy.sections;
12
45
  if (!Array.isArray(sections)) {
13
- return { doc: input3, migrated: false, danglingIds: [], unlistedRootIds: [] };
46
+ return { doc: normalized, migrated: false, danglingIds: [], unlistedRootIds: [] };
14
47
  }
15
48
  const danglingIds = [];
16
49
  const ordered = [];
17
50
  const seen = /* @__PURE__ */ new Set();
18
51
  for (const id of sections) {
19
- if (!input3.nodes[id]) {
52
+ if (!normalized.nodes[id]) {
20
53
  danglingIds.push(id);
21
54
  continue;
22
55
  }
@@ -24,9 +57,9 @@ function migrateDocVerbose(input3) {
24
57
  seen.add(id);
25
58
  ordered.push(id);
26
59
  }
27
- const unlistedRootIds = Object.values(input3.nodes).filter((n) => n.parent === null && !seen.has(n.id)).sort((a, b) => a.order < b.order ? -1 : a.order > b.order ? 1 : 0).map((n) => n.id);
60
+ const unlistedRootIds = Object.values(normalized.nodes).filter((n) => n.parent === null && !seen.has(n.id)).sort((a, b) => a.order < b.order ? -1 : a.order > b.order ? 1 : 0).map((n) => n.id);
28
61
  const finalOrder = [...ordered, ...unlistedRootIds];
29
- const nodes = { ...input3.nodes };
62
+ const nodes = { ...normalized.nodes };
30
63
  let prev = null;
31
64
  for (const id of finalOrder) {
32
65
  const key = fancyDocCommons.fractionalKey(prev, null);
@@ -48,6 +81,7 @@ function childrenOf(doc, parent) {
48
81
  return fancyDocCommons.childrenOf(doc, parent);
49
82
  }
50
83
  function rootIds(doc) {
84
+ if (!hasNodeMap(doc)) return [];
51
85
  return childrenOf(doc, null).map((n) => n.id);
52
86
  }
53
87
  function lastRootId(doc) {
@@ -255,26 +289,6 @@ function useLatestRef(value) {
255
289
  return ref;
256
290
  }
257
291
 
258
- // src/document/types.ts
259
- function isBinding(v) {
260
- return typeof v === "object" && v !== null && typeof v.$bind === "string";
261
- }
262
- var DEFAULT_BREAKPOINTS = {
263
- base: 0,
264
- md: 768,
265
- lg: 1024
266
- };
267
- function emptyDoc(id, slug = "/") {
268
- return {
269
- id,
270
- seq: 0,
271
- meta: { title: "Untitled", slug, scrollMode: "smooth" },
272
- theme: { name: "default" },
273
- breakpoints: ["base", "md", "lg"],
274
- nodes: {}
275
- };
276
- }
277
-
278
292
  // src/render/css.ts
279
293
  var selectorFor = (id) => `[data-cms="${id}"]`;
280
294
  function lengthToCss(len2) {
@@ -371,6 +385,7 @@ ${body2}
371
385
  ${indent}}`;
372
386
  }
373
387
  function emitDocCss(doc) {
388
+ if (!hasNodeMap(doc)) return "";
374
389
  const breakpointPx = DEFAULT_BREAKPOINTS;
375
390
  const blocks = [];
376
391
  for (const id of Object.keys(doc.nodes).sort()) {