@particle-academy/fancy-cms-ui 0.5.1 → 0.7.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.cjs CHANGED
@@ -23,6 +23,39 @@ function emptyDoc(id, slug = "/") {
23
23
  nodes: {}
24
24
  };
25
25
  }
26
+
27
+ // src/document/bindings.ts
28
+ function isSource(v) {
29
+ return Array.isArray(v) && v.length > 0 && v.every((seg) => typeof seg === "string" || typeof seg === "number");
30
+ }
31
+ function isLiveBinding(v) {
32
+ return isBinding(v) && isSource(v.$source);
33
+ }
34
+ function eachBinding(value, visit) {
35
+ if (isBinding(value)) {
36
+ visit(value);
37
+ return;
38
+ }
39
+ if (Array.isArray(value)) {
40
+ for (const item of value) eachBinding(item, visit);
41
+ return;
42
+ }
43
+ if (typeof value === "object" && value !== null) {
44
+ for (const item of Object.values(value)) eachBinding(item, visit);
45
+ }
46
+ }
47
+ function bindingSources(doc) {
48
+ const seen = /* @__PURE__ */ new Map();
49
+ const take = (b) => {
50
+ if (!isLiveBinding(b)) return;
51
+ seen.set(JSON.stringify(b.$source), b.$source);
52
+ };
53
+ for (const node of Object.values(doc.nodes)) {
54
+ eachBinding(node.props, take);
55
+ if (node.repeat?.each) eachBinding(node.repeat.each, take);
56
+ }
57
+ return [...seen.values()];
58
+ }
26
59
  function childrenOf(doc, parent) {
27
60
  return fancyDocCommons.childrenOf(doc, parent);
28
61
  }
@@ -86,7 +119,7 @@ function reduce(doc, op, opts = {}) {
86
119
  seq: doc.seq + 1
87
120
  };
88
121
  }
89
- case "set_props": {
122
+ case "set_node_props": {
90
123
  if (!doc.nodes[op.id]) return invalid("node not found");
91
124
  return patchNode(doc, op.id, {
92
125
  props: { ...doc.nodes[op.id].props, ...op.patch }
@@ -186,12 +219,12 @@ function invert(doc, op) {
186
219
  }
187
220
  return back;
188
221
  }
189
- case "set_props": {
222
+ case "set_node_props": {
190
223
  const node = doc.nodes[op.id];
191
224
  if (!node) return [];
192
225
  const prev = {};
193
226
  for (const k of Object.keys(op.patch)) prev[k] = node.props[k];
194
- return [{ t: "set_props", id: op.id, patch: prev }];
227
+ return [{ t: "set_node_props", id: op.id, patch: prev }];
195
228
  }
196
229
  case "set_layout": {
197
230
  const node = doc.nodes[op.id];
@@ -746,7 +779,7 @@ function Inspector({ doc, selection, apply }) {
746
779
  }
747
780
  const s = node.style.base;
748
781
  const setStyle = (patch) => apply({ t: "set_style", id: node.id, breakpoint: "base", patch });
749
- const setProp = (key, value) => apply({ t: "set_props", id: node.id, patch: { [key]: value } });
782
+ const setProp = (key, value) => apply({ t: "set_node_props", id: node.id, patch: { [key]: value } });
750
783
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { overflow: "auto", padding: 16, fontFamily: "system-ui, sans-serif", height: "100%", boxSizing: "border-box" }, children: [
751
784
  /* @__PURE__ */ jsxRuntime.jsx("div", { style: { fontSize: 13, fontWeight: 600, color: "var(--fcms-fg)" }, children: node.type }),
752
785
  /* @__PURE__ */ jsxRuntime.jsx("div", { style: { fontSize: 11, color: "var(--fcms-muted)", marginBottom: 8 }, children: node.id }),
@@ -1079,6 +1112,7 @@ exports.Editor = Editor;
1079
1112
  exports.Inspector = Inspector;
1080
1113
  exports.LayersPanel = LayersPanel;
1081
1114
  exports.RenderNode = RenderNode;
1115
+ exports.bindingSources = bindingSources;
1082
1116
  exports.buildInsertOp = buildInsertOp;
1083
1117
  exports.childrenOf = childrenOf;
1084
1118
  exports.defaultRegistry = defaultRegistry;
@@ -1090,6 +1124,7 @@ exports.getPath = getPath;
1090
1124
  exports.initEditor = initEditor;
1091
1125
  exports.invert = invert;
1092
1126
  exports.isBinding = isBinding;
1127
+ exports.isLiveBinding = isLiveBinding;
1093
1128
  exports.lastRootId = lastRootId;
1094
1129
  exports.migrateDoc = migrateDoc;
1095
1130
  exports.migrateDocVerbose = migrateDocVerbose;