@chaibuilder/sdk 2.6.2 → 2.6.4

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/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "author": "Suraj Air",
6
6
  "license": "BSD-3-Clause",
7
7
  "homepage": "https://chaibuilder.com",
8
- "version": "2.6.2",
8
+ "version": "2.6.4",
9
9
  "type": "module",
10
10
  "repository": {
11
11
  "type": "git",
@@ -124,7 +124,7 @@
124
124
  "fuse.js": "7.1.0",
125
125
  "himalaya": "^1.1.0",
126
126
  "i18next": "25.3.4",
127
- "jotai": "2.13.1",
127
+ "jotai": "2.14.0",
128
128
  "lodash": "^4.17.21",
129
129
  "lodash-es": "4.17.21",
130
130
  "lucide-react": "0.539.0",
@@ -164,7 +164,7 @@
164
164
  "eslint-plugin-react-refresh": "^0.4.18",
165
165
  "husky": "^9.1.7",
166
166
  "jest-environment-jsdom": "^29.7.0",
167
- "jotai-devtools": "0.12.0",
167
+ "jotai-devtools": "0.13.0",
168
168
  "jsdoc": "^4.0.4",
169
169
  "msw": "^2.7.0",
170
170
  "postcss": "^8.5.1",
@@ -1,267 +0,0 @@
1
- import { getRegisteredChaiBlock as $ } from "@chaibuilder/runtime";
2
- import { memoize as k, get as p, cloneDeep as h, forEach as _, keys as f, isString as x, 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
- if (e = e.replace(E, ""), !e) return { baseClasses: "", classes: "" };
6
- const s = e.split(/,(?![^\[]*\])/);
7
- if (s.length === 1)
8
- return { baseClasses: "", classes: s[0].trim() };
9
- const [t, ...n] = s;
10
- return {
11
- baseClasses: t.trim(),
12
- classes: n.join(",").trim().replace(/ +(?= )/g, "")
13
- };
14
- };
15
- import.meta.vitest && describe("getSplitChaiClasses", () => {
16
- it("should return the base classes and the classes", () => {
17
- const e = {
18
- ",styles-2": { baseClasses: "", classes: "styles-2" },
19
- "styles-1,styles-2": { baseClasses: "styles-1", classes: "styles-2" },
20
- ",bg-[linear-gradient(-10deg,black,transparent_100%)]": {
21
- baseClasses: "",
22
- classes: "bg-[linear-gradient(-10deg,black,transparent_100%)]"
23
- },
24
- "styles-1,bg-[linear-gradient(-10deg,black,transparent_100%)]": {
25
- baseClasses: "styles-1",
26
- classes: "bg-[linear-gradient(-10deg,black,transparent_100%)]"
27
- },
28
- someclass: {
29
- baseClasses: "",
30
- classes: "someclass"
31
- },
32
- ",bg-red-500 text-center font-bold": {
33
- baseClasses: "",
34
- classes: "bg-red-500 text-center font-bold"
35
- },
36
- "bg-[linear-gradient(-10deg,black,transparent_100%)], bg-[linear-gradient(-10deg,black,transparent_100%)]": {
37
- baseClasses: "bg-[linear-gradient(-10deg,black,transparent_100%)]",
38
- classes: "bg-[linear-gradient(-10deg,black,transparent_100%)]"
39
- }
40
- };
41
- for (let s in e) {
42
- const t = I(`${E}${s}`);
43
- expect(t).toEqual(e[s]);
44
- }
45
- });
46
- });
47
- function w(e, s, t) {
48
- const n = p(t, "i18nProps", []);
49
- if (b(s) || b(n)) return e;
50
- const a = h(e);
51
- return _(f(a), (r) => {
52
- if (C(n, r) && !b(s)) {
53
- const o = p(a, `${r}-${s}`, ""), l = p(a, r, "");
54
- a[r] = x(o) && o.trim() || l;
55
- }
56
- }), a;
57
- }
58
- const v = k((e) => {
59
- const { baseClasses: s, classes: t } = I(e);
60
- return D(s, t);
61
- });
62
- function T(e, s) {
63
- return p(e, `${s}_attrs`, {});
64
- }
65
- function A(e, s = !0) {
66
- const t = {};
67
- return Object.keys(e).forEach((n) => {
68
- if (x(e[n]) && e[n].startsWith(E)) {
69
- const a = v(e[n]), r = T(e, n);
70
- t[n] = {
71
- ...!b(a) && { className: a },
72
- ...r,
73
- ...s ? {
74
- "data-style-prop": n,
75
- "data-block-parent": e._id,
76
- "data-style-id": `${n}-${e._id}`
77
- } : {}
78
- };
79
- }
80
- }), t;
81
- }
82
- const N = k((e) => {
83
- const s = $(e), t = p(s, "schema.properties", {});
84
- return Object.fromEntries(Object.entries(t).filter(([, n]) => p(n, "runtime", !1)));
85
- }), j = (e, s) => {
86
- if (!g(e)) return e;
87
- let t = e, n;
88
- return typeof s.limit == "number" && s.limit > 0 && (n = s.limit), n !== void 0 && (t = t.slice(0, n)), t;
89
- }, z = (e, s) => {
90
- const t = h(e);
91
- return _(f(t), (n) => {
92
- if (x(t[n]) && !m(n, "_")) {
93
- let a = t[n];
94
- n === "repeaterItems" && (t.repeaterItemsBinding = a);
95
- const r = /\{\{(.*?)\}\}/g, o = a.match(r);
96
- o && o.forEach((l) => {
97
- let c = l.slice(2, -2);
98
- const d = p(s, c, l);
99
- a = g(d) ? d : a.replace(l, d);
100
- }), t[n] = a;
101
- }
102
- }), t;
103
- }, i = (e, s, { index: t, key: n }) => {
104
- if (x(e)) {
105
- let a = e;
106
- const r = /\{\{(.*?)\}\}/g, o = e.match(r);
107
- return o && o.forEach((l) => {
108
- let c = l.slice(2, -2).trim(), d = n.slice(2, -2).trim();
109
- t !== -1 && m(c, "$index.") ? c = `${d}.${t}.${c.slice(7)}` : t !== -1 && m(c, "$index") && (c = `${d}.${t}`);
110
- const y = p(s, c, l);
111
- a = g(y) ? y : a.replace(l, y);
112
- }), a;
113
- }
114
- if (g(e))
115
- return e.map((a) => i(a, s, { index: t, key: n }));
116
- if (e && typeof e == "object") {
117
- const a = {};
118
- return _(f(e), (r) => {
119
- !m(r, "_") && r !== "$repeaterItemsKey" ? a[r] = i(e[r], s, { index: t, key: n }) : a[r] = e[r];
120
- }), a;
121
- }
122
- return e;
123
- }, u = (e, s, { index: t, key: n }) => {
124
- let a = h(e);
125
- 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 });
126
- };
127
- import.meta.vitest && (describe("applyBindingToValue", () => {
128
- it("should handle string values with bindings", () => {
129
- const t = i("Hello {{user.name}}", { user: { name: "John" } }, { index: -1, key: "" });
130
- expect(t).toBe("Hello John");
131
- }), it("should handle nested object properties", () => {
132
- const t = i({
133
- name: "John",
134
- address: {
135
- city: "{{user.city}}",
136
- street: "123 Main St"
137
- }
138
- }, { user: { city: "New York" } }, { index: -1, key: "" });
139
- expect(t).toEqual({
140
- name: "John",
141
- address: {
142
- city: "New York",
143
- street: "123 Main St"
144
- }
145
- });
146
- }), it("should handle arrays of values", () => {
147
- const t = i(["Hello {{user.name}}", "Welcome {{user.role}}"], { user: { name: "John", role: "Admin" } }, { index: -1, key: "" });
148
- expect(t).toEqual(["Hello John", "Welcome Admin"]);
149
- }), it("should handle $index binding in repeater context", () => {
150
- const t = i("Item {{$index}}", { items: ["a", "b", "c"] }, { index: 1, key: "{{items}}" });
151
- expect(t).toBe("Item b");
152
- }), it("should handle $index binding with dot notation", () => {
153
- const t = i("Item {{$index.value}}", { items: [{ value: "apple" }, { value: "banana" }, { value: "cherry" }] }, { index: 1, key: "{{items}}" });
154
- expect(t).toBe("Item banana");
155
- }), it("should preserve private properties starting with _", () => {
156
- const s = i({
157
- name: "John",
158
- _private: "secret"
159
- }, {}, { index: -1, key: "" });
160
- expect(s).toEqual({
161
- name: "John",
162
- _private: "secret"
163
- });
164
- });
165
- }), describe("applyBindingToBlockProps", () => {
166
- it("should handle basic block with bindings", () => {
167
- const t = u({
168
- _id: "test-block",
169
- _type: "text",
170
- type: "text",
171
- content: "Hello {{user.name}}",
172
- style: {
173
- color: "{{theme.color}}"
174
- }
175
- }, { user: { name: "John" }, theme: { color: "blue" } }, { index: -1, key: "" });
176
- expect(t).toEqual({
177
- _id: "test-block",
178
- _type: "text",
179
- type: "text",
180
- content: "Hello John",
181
- style: {
182
- color: "blue"
183
- }
184
- });
185
- }), it("should handle repeaterItems and repeaterItemsBinding", () => {
186
- const t = u({
187
- _id: "test-block",
188
- _type: "repeater",
189
- type: "repeater",
190
- repeaterItems: "{{items}}",
191
- items: ["a", "b", "c"]
192
- }, { items: ["x", "y", "z"] }, { index: -1, key: "" });
193
- expect(t).toEqual({
194
- _id: "test-block",
195
- _type: "repeater",
196
- type: "repeater",
197
- $repeaterItemsKey: "{{items}}",
198
- repeaterItems: ["x", "y", "z"],
199
- items: ["a", "b", "c"]
200
- });
201
- }), it("should handle nested blocks with bindings", () => {
202
- const t = u({
203
- _id: "test-block",
204
- _type: "container",
205
- type: "container",
206
- children: [
207
- {
208
- _id: "child-block",
209
- _type: "text",
210
- type: "text",
211
- content: "Item {{$index}}",
212
- style: {
213
- color: "{{theme.color}}"
214
- }
215
- }
216
- ]
217
- }, { theme: { color: "red" }, items: ["x", "y", "z"] }, { index: 2, key: "{{items}}" });
218
- expect(t).toEqual({
219
- _id: "test-block",
220
- _type: "container",
221
- type: "container",
222
- children: [
223
- {
224
- _id: "child-block",
225
- _type: "text",
226
- type: "text",
227
- content: "Item z",
228
- style: {
229
- color: "red"
230
- }
231
- }
232
- ]
233
- });
234
- }), it("should handle arrays of blocks", () => {
235
- const t = u({
236
- _id: "test-block",
237
- _type: "list",
238
- type: "list",
239
- items: [
240
- { _id: "item1", content: "Item {{$index}}" },
241
- { _id: "item2", content: "Item {{$index}}" }
242
- ]
243
- }, { items: ["x", "y", "z"] }, { index: 0, key: "{{items}}" });
244
- expect(t).toEqual({
245
- _id: "test-block",
246
- _type: "list",
247
- type: "list",
248
- items: [
249
- { _id: "item1", content: "Item x" },
250
- { _id: "item2", content: "Item x" }
251
- ]
252
- });
253
- });
254
- }));
255
- export {
256
- B as C,
257
- q as R,
258
- E as S,
259
- u as a,
260
- w as b,
261
- N as c,
262
- j as d,
263
- z as e,
264
- I as f,
265
- A as g,
266
- P as h
267
- };
@@ -1 +0,0 @@
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=>{if(t.includes(n,l)&&!t.isEmpty(i)){const o=t.get(s,`${l}-${i}`,""),r=t.get(s,l,"");s[l]=t.isString(o)&&o.trim()||r}}),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,o=s.match(l);o&&o.forEach(r=>{let c=r.slice(2,-2);const p=t.get(i,c,r);s=t.isArray(p)?p:s.replace(r,p)}),a[n]=s}}),a},u=(e,i,{index:a,key:n})=>{if(t.isString(e)){let s=e;const l=/\{\{(.*?)\}\}/g,o=e.match(l);return o&&o.forEach(r=>{let c=r.slice(2,-2).trim(),p=n.slice(2,-2).trim();a!==-1&&t.startsWith(c,"$index.")?c=`${p}.${a}.${c.slice(7)}`:a!==-1&&t.startsWith(c,"$index")&&(c=`${p}.${a}`);const d=t.get(i,c,r);s=t.isArray(d)?d:s.replace(r,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;