@chaibuilder/sdk 2.2.18 → 2.2.20
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/{apply-binding-Z9D6RXG4.js → apply-binding-CkrtJykq.js} +65 -68
- package/dist/apply-binding-DpBwzIf9.cjs +1 -0
- package/dist/core.cjs +12 -13
- package/dist/core.d.ts +38 -6
- package/dist/core.js +1614 -1196
- package/dist/{get-chai-builder-theme-CeaKvOZ8.cjs → get-chai-builder-theme-B1tr_NJB.cjs} +1 -1
- package/dist/{get-chai-builder-theme-ByeXCyGx.js → get-chai-builder-theme-BarMkcGH.js} +1 -1
- package/dist/{plugin-fnBB3TCm.js → plugin-BOcGV_IY.js} +15 -14
- package/dist/{plugin-C01tjI6V.cjs → plugin-CSgw-f78.cjs} +5 -5
- package/dist/render.cjs +2 -2
- package/dist/render.js +57 -60
- package/dist/tailwind.cjs +1 -1
- package/dist/tailwind.js +2 -2
- package/dist/web-blocks.cjs +2 -2
- package/dist/web-blocks.js +241 -172
- package/package.json +6 -3
- package/dist/apply-binding-k6PclyA3.cjs +0 -1
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { getRegisteredChaiBlock as
|
|
2
|
-
import { memoize as k, get as c, cloneDeep as
|
|
3
|
-
import { twMerge as
|
|
4
|
-
const E = "#styles:",
|
|
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, ...
|
|
9
|
+
const [t, ...n] = s;
|
|
10
10
|
return {
|
|
11
11
|
baseClasses: t.trim(),
|
|
12
|
-
classes:
|
|
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
|
|
48
|
-
const
|
|
49
|
-
if (
|
|
50
|
-
const
|
|
51
|
-
return
|
|
52
|
-
|
|
53
|
-
}),
|
|
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
|
|
55
|
+
const v = k((e) => {
|
|
56
56
|
const { baseClasses: s, classes: t } = I(e);
|
|
57
|
-
return
|
|
57
|
+
return D(s, t);
|
|
58
58
|
});
|
|
59
|
-
function
|
|
59
|
+
function T(e, s) {
|
|
60
60
|
return c(e, `${s}_attrs`, {});
|
|
61
61
|
}
|
|
62
|
-
function
|
|
62
|
+
function A(e, s = !0) {
|
|
63
63
|
const t = {};
|
|
64
|
-
return Object.keys(e).forEach((
|
|
65
|
-
if (f(e[
|
|
66
|
-
const
|
|
67
|
-
t[
|
|
68
|
-
...!
|
|
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":
|
|
71
|
+
"data-style-prop": n,
|
|
72
72
|
"data-block-parent": e._id,
|
|
73
|
-
"data-style-id": `${
|
|
73
|
+
"data-style-id": `${n}-${e._id}`
|
|
74
74
|
} : {}
|
|
75
75
|
};
|
|
76
76
|
}
|
|
77
77
|
}), t;
|
|
78
78
|
}
|
|
79
|
-
const
|
|
80
|
-
const s =
|
|
81
|
-
return Object.fromEntries(Object.entries(t).filter(([,
|
|
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 (!
|
|
84
|
-
let t = e,
|
|
85
|
-
return typeof s.limit == "number" && s.limit > 0 && (
|
|
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 =
|
|
88
|
-
return
|
|
89
|
-
if (f(t[
|
|
90
|
-
let
|
|
91
|
-
|
|
92
|
-
const r = /\{\{(.*?)\}\}/g, d =
|
|
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
|
-
|
|
97
|
-
}), t[
|
|
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:
|
|
100
|
+
}, i = (e, s, { index: t, key: n }) => {
|
|
101
101
|
if (f(e)) {
|
|
102
|
-
let
|
|
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 =
|
|
108
|
-
t !== -1 &&
|
|
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
|
-
|
|
111
|
-
}),
|
|
108
|
+
a = g(x) ? x : a.replace(o, x);
|
|
109
|
+
}), a;
|
|
112
110
|
}
|
|
113
|
-
if (
|
|
114
|
-
return e.map((
|
|
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
|
|
117
|
-
return
|
|
118
|
-
|
|
119
|
-
}),
|
|
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
|
-
},
|
|
123
|
-
|
|
124
|
-
return
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
253
|
+
B as C,
|
|
254
|
+
q as R,
|
|
259
255
|
E as S,
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
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
|
-
|
|
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;
|