@chaibuilder/sdk 2.2.17 → 2.2.19

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.
@@ -1,15 +1,15 @@
1
- import { getRegisteredChaiBlock as B } from "@chaibuilder/runtime";
2
- import { memoize as k, get as c, cloneDeep as h, forEach as y, keys as _, isString as f, startsWith as u, isArray as b, isEmpty as g, includes as $ } from "lodash-es";
3
- import { twMerge as C } from "tailwind-merge";
4
- const E = "#styles:", w = "__ADD_BLOCK_INTERNAL_ROOT", I = (e) => {
1
+ import { getRegisteredChaiBlock as $ } from "@chaibuilder/runtime";
2
+ import { memoize as k, get as c, cloneDeep as y, forEach as h, keys as _, isString as f, startsWith as m, isArray as g, isEmpty as b, includes as C } from "lodash-es";
3
+ import { twMerge as D } from "tailwind-merge";
4
+ const E = "#styles:", P = "__ADD_BLOCK_INTERNAL_ROOT", q = "@", B = "#", I = (e) => {
5
5
  if (e = e.replace(E, ""), !e) return { baseClasses: "", classes: "" };
6
6
  const s = e.split(/,(?![^\[]*\])/);
7
7
  if (s.length === 1)
8
8
  return { baseClasses: "", classes: s[0].trim() };
9
- const [t, ...a] = s;
9
+ const [t, ...n] = s;
10
10
  return {
11
11
  baseClasses: t.trim(),
12
- classes: a.join(",").trim().replace(/ +(?= )/g, "")
12
+ classes: n.join(",").trim().replace(/ +(?= )/g, "")
13
13
  };
14
14
  };
15
15
  import.meta.vitest && describe("getSplitChaiClasses", () => {
@@ -44,84 +44,82 @@ import.meta.vitest && describe("getSplitChaiClasses", () => {
44
44
  }
45
45
  });
46
46
  });
47
- function O(e, s, t) {
48
- const a = c(t, "i18nProps", []);
49
- if (g(s) || g(a)) return e;
50
- const n = h(e);
51
- return y(_(n), (r) => {
52
- $(a, r) && !g(s) && (n[r] = c(n, `${r}-${s}`, n[r]));
53
- }), n;
47
+ function w(e, s, t) {
48
+ const n = c(t, "i18nProps", []);
49
+ if (b(s) || b(n)) return e;
50
+ const a = y(e);
51
+ return h(_(a), (r) => {
52
+ C(n, r) && !b(s) && (a[r] = c(a, `${r}-${s}`, a[r]));
53
+ }), a;
54
54
  }
55
- const D = k((e) => {
55
+ const v = k((e) => {
56
56
  const { baseClasses: s, classes: t } = I(e);
57
- return C(s, t);
57
+ return D(s, t);
58
58
  });
59
- function v(e, s) {
59
+ function T(e, s) {
60
60
  return c(e, `${s}_attrs`, {});
61
61
  }
62
- function R(e, s = !0) {
62
+ function A(e, s = !0) {
63
63
  const t = {};
64
- return Object.keys(e).forEach((a) => {
65
- if (f(e[a]) && e[a].startsWith(E)) {
66
- const n = D(e[a]), r = v(e, a);
67
- t[a] = {
68
- ...!g(n) && { className: n },
64
+ return Object.keys(e).forEach((n) => {
65
+ if (f(e[n]) && e[n].startsWith(E)) {
66
+ const a = v(e[n]), r = T(e, n);
67
+ t[n] = {
68
+ ...!b(a) && { className: a },
69
69
  ...r,
70
70
  ...s ? {
71
- "data-style-prop": a,
71
+ "data-style-prop": n,
72
72
  "data-block-parent": e._id,
73
- "data-style-id": `${a}-${e._id}`
73
+ "data-style-id": `${n}-${e._id}`
74
74
  } : {}
75
75
  };
76
76
  }
77
77
  }), t;
78
78
  }
79
- const A = k((e) => {
80
- const s = B(e), t = c(s, "schema.properties", {});
81
- return Object.fromEntries(Object.entries(t).filter(([, a]) => c(a, "runtime", !1)));
79
+ const N = k((e) => {
80
+ const s = $(e), t = c(s, "schema.properties", {});
81
+ return Object.fromEntries(Object.entries(t).filter(([, n]) => c(n, "runtime", !1)));
82
82
  }), j = (e, s) => {
83
- if (!b(e)) return e;
84
- let t = e, a;
85
- return typeof s.limit == "number" && s.limit > 0 && (a = s.limit), a !== void 0 && (t = t.slice(0, a)), t;
83
+ if (!g(e)) return e;
84
+ let t = e, n;
85
+ return typeof s.limit == "number" && s.limit > 0 && (n = s.limit), n !== void 0 && (t = t.slice(0, n)), t;
86
86
  }, z = (e, s) => {
87
- const t = h(e);
88
- return y(_(t), (a) => {
89
- if (f(t[a]) && !u(a, "_")) {
90
- let n = t[a];
91
- a === "repeaterItems" && (t.repeaterItemsBinding = n);
92
- const r = /\{\{(.*?)\}\}/g, d = n.match(r);
87
+ const t = y(e);
88
+ return h(_(t), (n) => {
89
+ if (f(t[n]) && !m(n, "_")) {
90
+ let a = t[n];
91
+ n === "repeaterItems" && (t.repeaterItemsBinding = a);
92
+ const r = /\{\{(.*?)\}\}/g, d = a.match(r);
93
93
  d && d.forEach((o) => {
94
94
  let l = o.slice(2, -2);
95
95
  const p = c(s, l, o);
96
- n = b(p) ? p : n.replace(o, p);
97
- }), t[a] = n;
96
+ a = g(p) ? p : a.replace(o, p);
97
+ }), t[n] = a;
98
98
  }
99
99
  }), t;
100
- }, i = (e, s, { index: t, key: a }) => {
100
+ }, i = (e, s, { index: t, key: n }) => {
101
101
  if (f(e)) {
102
- let n = e;
103
- if (e === "repeaterItems")
104
- return { value: e, repeaterItemsBinding: e };
102
+ let a = e;
105
103
  const r = /\{\{(.*?)\}\}/g, d = e.match(r);
106
104
  return d && d.forEach((o) => {
107
- let l = o.slice(2, -2).trim(), p = a.slice(2, -2).trim();
108
- t !== -1 && u(l, "$index.") ? l = `${p}.${t}.${l.slice(7)}` : t !== -1 && u(l, "$index") && (l = `${p}.${t}`);
105
+ let l = o.slice(2, -2).trim(), p = n.slice(2, -2).trim();
106
+ t !== -1 && m(l, "$index.") ? l = `${p}.${t}.${l.slice(7)}` : t !== -1 && m(l, "$index") && (l = `${p}.${t}`);
109
107
  const x = c(s, l, o);
110
- n = b(x) ? x : n.replace(o, x);
111
- }), n;
108
+ a = g(x) ? x : a.replace(o, x);
109
+ }), a;
112
110
  }
113
- if (b(e))
114
- return e.map((n) => i(n, s, { index: t, key: a }));
111
+ if (g(e))
112
+ return e.map((a) => i(a, s, { index: t, key: n }));
115
113
  if (e && typeof e == "object") {
116
- const n = {};
117
- return y(_(e), (r) => {
118
- u(r, "_") ? n[r] = e[r] : n[r] = i(e[r], s, { index: t, key: a });
119
- }), n;
114
+ const a = {};
115
+ return h(_(e), (r) => {
116
+ !m(r, "_") && r !== "$repeaterItemsKey" ? a[r] = i(e[r], s, { index: t, key: n }) : a[r] = e[r];
117
+ }), a;
120
118
  }
121
119
  return e;
122
- }, m = (e, s, { index: t, key: a }) => {
123
- const n = h(e), r = i(n, s, { index: t, key: a });
124
- return n.repeaterItems && (r.repeaterItemsBinding = n.repeaterItems), r;
120
+ }, u = (e, s, { index: t, key: n }) => {
121
+ let a = y(e);
122
+ return a.repeaterItems && (a.$repeaterItemsKey = a.repeaterItems, m(a.repeaterItems, `{{${B}`) && (a.$repeaterItemsKey = a.repeaterItems = `${a.repeaterItems.replace("}}", `/${a._id}}}`)}`)), i(a, s, { index: t, key: n });
125
123
  };
126
124
  import.meta.vitest && (describe("applyBindingToValue", () => {
127
125
  it("should handle string values with bindings", () => {
@@ -145,9 +143,6 @@ import.meta.vitest && (describe("applyBindingToValue", () => {
145
143
  }), it("should handle arrays of values", () => {
146
144
  const t = i(["Hello {{user.name}}", "Welcome {{user.role}}"], { user: { name: "John", role: "Admin" } }, { index: -1, key: "" });
147
145
  expect(t).toEqual(["Hello John", "Welcome Admin"]);
148
- }), it("should handle repeaterItems special case", () => {
149
- const s = i("repeaterItems", {}, { index: -1, key: "" });
150
- expect(s).toEqual({ value: "repeaterItems", repeaterItemsBinding: "repeaterItems" });
151
146
  }), it("should handle $index binding in repeater context", () => {
152
147
  const t = i("Item {{$index}}", { items: ["a", "b", "c"] }, { index: 1, key: "{{items}}" });
153
148
  expect(t).toBe("Item b");
@@ -166,7 +161,7 @@ import.meta.vitest && (describe("applyBindingToValue", () => {
166
161
  });
167
162
  }), describe("applyBindingToBlockProps", () => {
168
163
  it("should handle basic block with bindings", () => {
169
- const t = m({
164
+ const t = u({
170
165
  _id: "test-block",
171
166
  _type: "text",
172
167
  type: "text",
@@ -185,7 +180,7 @@ import.meta.vitest && (describe("applyBindingToValue", () => {
185
180
  }
186
181
  });
187
182
  }), it("should handle repeaterItems and repeaterItemsBinding", () => {
188
- const t = m({
183
+ const t = u({
189
184
  _id: "test-block",
190
185
  _type: "repeater",
191
186
  type: "repeater",
@@ -196,12 +191,12 @@ import.meta.vitest && (describe("applyBindingToValue", () => {
196
191
  _id: "test-block",
197
192
  _type: "repeater",
198
193
  type: "repeater",
194
+ $repeaterItemsKey: "{{items}}",
199
195
  repeaterItems: ["x", "y", "z"],
200
- repeaterItemsBinding: "{{items}}",
201
196
  items: ["a", "b", "c"]
202
197
  });
203
198
  }), it("should handle nested blocks with bindings", () => {
204
- const t = m({
199
+ const t = u({
205
200
  _id: "test-block",
206
201
  _type: "container",
207
202
  type: "container",
@@ -234,7 +229,7 @@ import.meta.vitest && (describe("applyBindingToValue", () => {
234
229
  ]
235
230
  });
236
231
  }), it("should handle arrays of blocks", () => {
237
- const t = m({
232
+ const t = u({
238
233
  _id: "test-block",
239
234
  _type: "list",
240
235
  type: "list",
@@ -255,13 +250,15 @@ import.meta.vitest && (describe("applyBindingToValue", () => {
255
250
  });
256
251
  }));
257
252
  export {
258
- w as R,
253
+ B as C,
254
+ q as R,
259
255
  E as S,
260
- m as a,
261
- O as b,
262
- A as c,
256
+ u as a,
257
+ w as b,
258
+ N as c,
263
259
  j as d,
264
260
  z as e,
265
261
  I as f,
266
- R as g
262
+ A as g,
263
+ P as h
267
264
  };
@@ -0,0 +1 @@
1
+ "use strict";const b=require("@chaibuilder/runtime"),t=require("lodash-es"),h=require("tailwind-merge"),g="#styles:",x="__ADD_BLOCK_INTERNAL_ROOT",E="@",m="#",y=e=>{if(e=e.replace(g,""),!e)return{baseClasses:"",classes:""};const i=e.split(/,(?![^\[]*\])/);if(i.length===1)return{baseClasses:"",classes:i[0].trim()};const[a,...n]=i;return{baseClasses:a.trim(),classes:n.join(",").trim().replace(/ +(?= )/g,"")}};function _(e,i,a){const n=t.get(a,"i18nProps",[]);if(t.isEmpty(i)||t.isEmpty(n))return e;const s=t.cloneDeep(e);return t.forEach(t.keys(s),l=>{t.includes(n,l)&&!t.isEmpty(i)&&(s[l]=t.get(s,`${l}-${i}`,s[l]))}),s}const f=t.memoize(e=>{const{baseClasses:i,classes:a}=y(e);return h.twMerge(i,a)});function k(e,i){return t.get(e,`${i}_attrs`,{})}function B(e,i=!0){const a={};return Object.keys(e).forEach(n=>{if(t.isString(e[n])&&e[n].startsWith(g)){const s=f(e[n]),l=k(e,n);a[n]={...!t.isEmpty(s)&&{className:s},...l,...i?{"data-style-prop":n,"data-block-parent":e._id,"data-style-id":`${n}-${e._id}`}:{}}}}),a}const I=t.memoize(e=>{const i=b.getRegisteredChaiBlock(e),a=t.get(i,"schema.properties",{});return Object.fromEntries(Object.entries(a).filter(([,n])=>t.get(n,"runtime",!1)))}),T=(e,i)=>{if(!t.isArray(e))return e;let a=e,n;return typeof i.limit=="number"&&i.limit>0&&(n=i.limit),n!==void 0&&(a=a.slice(0,n)),a},C=(e,i)=>{const a=t.cloneDeep(e);return t.forEach(t.keys(a),n=>{if(t.isString(a[n])&&!t.startsWith(n,"_")){let s=a[n];n==="repeaterItems"&&(a.repeaterItemsBinding=s);const l=/\{\{(.*?)\}\}/g,p=s.match(l);p&&p.forEach(o=>{let r=o.slice(2,-2);const c=t.get(i,r,o);s=t.isArray(c)?c:s.replace(o,c)}),a[n]=s}}),a},u=(e,i,{index:a,key:n})=>{if(t.isString(e)){let s=e;const l=/\{\{(.*?)\}\}/g,p=e.match(l);return p&&p.forEach(o=>{let r=o.slice(2,-2).trim(),c=n.slice(2,-2).trim();a!==-1&&t.startsWith(r,"$index.")?r=`${c}.${a}.${r.slice(7)}`:a!==-1&&t.startsWith(r,"$index")&&(r=`${c}.${a}`);const d=t.get(i,r,o);s=t.isArray(d)?d:s.replace(o,d)}),s}if(t.isArray(e))return e.map(s=>u(s,i,{index:a,key:n}));if(e&&typeof e=="object"){const s={};return t.forEach(t.keys(e),l=>{!t.startsWith(l,"_")&&l!=="$repeaterItemsKey"?s[l]=u(e[l],i,{index:a,key:n}):s[l]=e[l]}),s}return e},$=(e,i,{index:a,key:n})=>{let s=t.cloneDeep(e);return s.repeaterItems&&(s.$repeaterItemsKey=s.repeaterItems,t.startsWith(s.repeaterItems,`{{${m}`)&&(s.$repeaterItemsKey=s.repeaterItems=`${s.repeaterItems.replace("}}",`/${s._id}}}`)}`)),u(s,i,{index:a,key:n})};exports.COLLECTION_PREFIX=m;exports.REPEATER_PREFIX=E;exports.ROOT_TEMP_KEY=x;exports.STYLES_KEY=g;exports.applyBindingToBlockProps=$;exports.applyChaiDataBinding=C;exports.applyLanguage=_;exports.applyLimit=T;exports.getBlockRuntimeProps=I;exports.getBlockTagAttributes=B;exports.getSplitChaiClasses=y;