@chaibuilder/sdk 2.2.2 → 2.2.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.
Files changed (37) hide show
  1. package/dist/CodeEditor-B7r9YjDC.cjs +1 -0
  2. package/dist/CodeEditor-HKrlrH8b.js +71 -0
  3. package/dist/core.cjs +5 -13
  4. package/dist/core.d.ts +88 -11
  5. package/dist/core.js +4085 -4123
  6. package/dist/get-chai-builder-theme-ByeXCyGx.js +12 -0
  7. package/dist/get-chai-builder-theme-CeaKvOZ8.cjs +1 -0
  8. package/dist/mockServiceWorker.js +1 -1
  9. package/dist/plugin-C01tjI6V.cjs +22 -0
  10. package/dist/plugin-fnBB3TCm.js +258 -0
  11. package/dist/render-chai-blocks-6SVNwoLW.js +201 -0
  12. package/dist/render-chai-blocks-Bvl2_fRE.cjs +1 -0
  13. package/dist/render.cjs +2 -2
  14. package/dist/render.d.ts +29 -3
  15. package/dist/render.js +38 -188
  16. package/dist/sooner-AJ7QkeLS.cjs +1 -0
  17. package/dist/sooner-DGhT8-JI.js +831 -0
  18. package/dist/tailwind.cjs +1 -1
  19. package/dist/tailwind.js +3 -2
  20. package/dist/ui.cjs +1 -1
  21. package/dist/ui.d.ts +36 -28
  22. package/dist/ui.js +232 -196
  23. package/dist/web-blocks.cjs +2 -2
  24. package/dist/web-blocks.js +1210 -1069
  25. package/package.json +5 -4
  26. package/dist/CodeEditor-CPR3N3wa.cjs +0 -1
  27. package/dist/CodeEditor-CuhsobXe.js +0 -65
  28. package/dist/chai-theme-helpers-BjWE6otR.cjs +0 -22
  29. package/dist/chai-theme-helpers-FO9vdd-R.js +0 -219
  30. package/dist/getSplitClasses-DodqA_KW.cjs +0 -1
  31. package/dist/getSplitClasses-DphwgQiE.js +0 -48
  32. package/dist/plugin-B09c0d5S.js +0 -24
  33. package/dist/plugin-BiiuylVf.cjs +0 -1
  34. package/dist/tooltip-BF2E5xPf.cjs +0 -1
  35. package/dist/tooltip-DGVZAvLU.js +0 -755
  36. /package/dist/{Functions-BGzDsf1z.js → common-functions-BGzDsf1z.js} +0 -0
  37. /package/dist/{Functions-BZmyleS1.cjs → common-functions-BZmyleS1.cjs} +0 -0
@@ -0,0 +1,12 @@
1
+ import { g as t, d as r } from "./plugin-fnBB3TCm.js";
2
+ const a = (e = r) => ({
3
+ container: {
4
+ center: !0,
5
+ padding: "1rem",
6
+ screens: { "2xl": "1400px" }
7
+ },
8
+ ...t(e)
9
+ });
10
+ export {
11
+ a as g
12
+ };
@@ -0,0 +1 @@
1
+ "use strict";const e=require("./plugin-C01tjI6V.cjs"),i=(t=e.defaultThemeOptions)=>({container:{center:!0,padding:"1rem",screens:{"2xl":"1400px"}},...e.getChaiThemeOptions(t)});exports.getChaiBuilderTheme=i;
@@ -8,7 +8,7 @@
8
8
  * - Please do NOT serve this file on production.
9
9
  */
10
10
 
11
- const PACKAGE_VERSION = '2.7.0'
11
+ const PACKAGE_VERSION = '2.7.4'
12
12
  const INTEGRITY_CHECKSUM = '00729d72e3b82faf54ca8b9621dbb96f'
13
13
  const IS_MOCKED_RESPONSE = Symbol('isMockedResponse')
14
14
  const activeClientIds = new Set()
@@ -0,0 +1,22 @@
1
+ "use strict";const b=require("@chaibuilder/runtime"),i=require("lodash-es"),B={fontFamily:{"font-heading":"Inter","font-body":"Inter"},borderRadius:"10px",colors:[{group:"Body",items:{background:["#FFFFFF","#121212"],foreground:["#121212","#FFFFFF"]}},{group:"Primary",items:{primary:["#2563EB","#3B82F6"],"primary-foreground":["#FFFFFF","#FFFFFF"]}},{group:"Secondary",items:{secondary:["#F3F4F6","#374151"],"secondary-foreground":["#1F2937","#F9FAFB"]}},{group:"Border, Input & Ring",items:{border:["#E5E7EB","#374151"],input:["#E5E7EB","#374151"],ring:["#2563EB","#3B82F6"]}},{group:"Card",items:{card:["#FFFFFF","#1F2937"],"card-foreground":["#121212","#FFFFFF"]}},{group:"Popover",items:{popover:["#FFFFFF","#1F2937"],"popover-foreground":["#121212","#FFFFFF"]}},{group:"Muted",items:{muted:["#F3F4F6","#374151"],"muted-foreground":["#6B7280","#9CA3AF"]}},{group:"Accent",items:{accent:["#F3F4F6","#374151"],"accent-foreground":["#1F2937","#FFFFFF"]}},{group:"Destructive",items:{destructive:["#DC2626","#EF4444"],"destructive-foreground":["#FFFFFF","#FFFFFF"]}}]},v={fontFamily:{heading:"Inter",body:"Inter"},borderRadius:"6px",colors:{background:["#FFFFFF","#09090B"],foreground:["#09090B","#FFFFFF"],primary:["#2563EB","#3B82F6"],"primary-foreground":["#FFFFFF","#FFFFFF"],secondary:["#F4F4F5","#27272A"],"secondary-foreground":["#09090B","#FFFFFF"],muted:["#F4F4F5","#27272A"],"muted-foreground":["#71717A","#A1A1AA"],accent:["#F4F4F5","#27272A"],"accent-foreground":["#09090B","#FFFFFF"],destructive:["#EF4444","#7F1D1D"],"destructive-foreground":["#FFFFFF","#FFFFFF"],border:["#E4E4E7","#27272A"],input:["#E4E4E7","#27272A"],ring:["#2563EB","#3B82F6"],card:["#FFFFFF","#09090B"],"card-foreground":["#09090B","#FFFFFF"],popover:["#FFFFFF","#09090B"],"popover-foreground":["#09090B","#FFFFFF"]}},_=e=>({fontFamily:e.fontFamily?i.keys(e.fontFamily).reduce((r,n)=>({...r,[n.replace("font-","")]:`var(--${n})`}),{}):{},borderRadius:e.borderRadius?{lg:"var(--radius)",md:"calc(var(--radius) - 2px)",sm:"calc(var(--radius) - 4px)"}:{},colors:e.colors?i.flatten(e.colors.map(r=>Object.entries(r.items))).reduce((r,[n])=>({...r,[n]:`hsl(var(--${n}))`}),{}):{}});function m(e){const t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);let r=parseInt(t[1],16),n=parseInt(t[2],16),o=parseInt(t[3],16);r/=255,n/=255,o/=255;const F=Math.max(r,n,o),u=Math.min(r,n,o);let a,d;const g=(F+u)/2;if(F==u)a=d=0;else{const l=F-u;switch(d=g>.5?l/(2-F-u):l/(F+u),F){case r:a=(n-o)/l+(n<o?6:0);break;case n:a=(o-r)/l+2;break;case o:a=(r-n)/l+4;break}a/=6}return`${Math.round(a*360)} ${Math.round(d*100)}% ${Math.round(g*100)}%`}const E=e=>{const r=b.getAllRegisteredFonts().find(n=>n.family===e);return`"${e}", ${i.get(r,"fallback","")}`},P=e=>`:root {
2
+ ${e.fontFamily&&Object.entries(e.fontFamily).map(([t,r])=>`--font-${t}: ${E(r)};`).join(`
3
+ `)}
4
+ ${e.borderRadius&&`--radius: ${e.borderRadius};`}
5
+ ${e.colors&&Object.entries(e.colors).map(([t,r])=>`--${t}: ${m(r[0])};`).join(`
6
+ `)}
7
+ }
8
+ .dark {
9
+ ${e.colors&&Object.entries(e.colors).map(([t,r])=>`--${t}: ${m(r[1])};`).join(`
10
+ `)}
11
+ }`,C=e=>!e||e.length===0?"":i.uniqBy(e,"family").map(t=>`<link rel="stylesheet" href="${t.url}" />`).join(`
12
+ `),A=e=>!e||e.length===0?"":i.uniqBy(e,"family").map(t=>`@import url("${t.url}");`).join(`
13
+ `),j=e=>!e||e.length===0?"":i.uniqBy(e,"family").map(t=>t.src.map(r=>`@font-face {
14
+ font-family: "${t.family}";
15
+ src: url("${r.url}") format("${r.format}");
16
+ font-display: swap;
17
+ ${r.fontWeight?`font-weight: ${r.fontWeight};`:""}
18
+ ${r.fontStyle?`font-style: ${r.fontStyle};`:""}
19
+ ${r.fontStretch?`font-stretch: ${r.fontStretch};`:""}
20
+ }`).join(`
21
+ `)).join(`
22
+ `);function k(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s={},c={},p;function M(){return p||(p=1,function(e){Object.defineProperty(e,"__esModule",{value:!0}),Object.defineProperty(e,"default",{enumerable:!0,get:function(){return r}});function t(n,o){return{handler:n,config:o}}t.withOptions=function(n,o=()=>({})){const F=function(u){return{__options:u,handler:n(u),config:o(u)}};return F.__isOptionsFunction=!0,F.__pluginFunction=n,F.__configFunction=o,F};const r=t}(c)),c}var y;function q(){return y||(y=1,function(e){Object.defineProperty(e,"__esModule",{value:!0}),Object.defineProperty(e,"default",{enumerable:!0,get:function(){return n}});const t=r(M());function r(o){return o&&o.__esModule?o:{default:o}}const n=t.default}(s)),s}var f,h;function O(){if(h)return f;h=1;let e=q();return f=(e.__esModule?e:{default:e}).default,f}var R=O();const $=k(R),I=$(function({addBase:e,theme:t}){e({"h1,h2,h3,h4,h5,h6":{fontFamily:t("fontFamily.heading")},body:{fontFamily:t("fontFamily.body"),color:t("colors.foreground"),backgroundColor:t("colors.background")}})});exports.chaiBuilderPlugin=I;exports.defaultThemeOptions=B;exports.defaultThemeValues=v;exports.getChaiThemeCssVariables=P;exports.getChaiThemeOptions=_;exports.getThemeCustomFontFace=j;exports.getThemeFontsCSSImport=A;exports.getThemeFontsLinkMarkup=C;exports.plugin=$;
@@ -0,0 +1,258 @@
1
+ import { getAllRegisteredFonts as b } from "@chaibuilder/runtime";
2
+ import { uniqBy as f, keys as h, flatten as v, get as B } from "lodash-es";
3
+ const O = {
4
+ fontFamily: {
5
+ "font-heading": "Inter",
6
+ "font-body": "Inter"
7
+ },
8
+ borderRadius: "10px",
9
+ colors: [
10
+ {
11
+ group: "Body",
12
+ items: {
13
+ background: ["#FFFFFF", "#121212"],
14
+ foreground: ["#121212", "#FFFFFF"]
15
+ }
16
+ },
17
+ {
18
+ group: "Primary",
19
+ items: {
20
+ primary: ["#2563EB", "#3B82F6"],
21
+ "primary-foreground": ["#FFFFFF", "#FFFFFF"]
22
+ }
23
+ },
24
+ {
25
+ group: "Secondary",
26
+ items: {
27
+ secondary: ["#F3F4F6", "#374151"],
28
+ "secondary-foreground": ["#1F2937", "#F9FAFB"]
29
+ }
30
+ },
31
+ {
32
+ group: "Border, Input & Ring",
33
+ items: {
34
+ border: ["#E5E7EB", "#374151"],
35
+ input: ["#E5E7EB", "#374151"],
36
+ ring: ["#2563EB", "#3B82F6"]
37
+ }
38
+ },
39
+ {
40
+ group: "Card",
41
+ items: {
42
+ card: ["#FFFFFF", "#1F2937"],
43
+ "card-foreground": ["#121212", "#FFFFFF"]
44
+ }
45
+ },
46
+ {
47
+ group: "Popover",
48
+ items: {
49
+ popover: ["#FFFFFF", "#1F2937"],
50
+ "popover-foreground": ["#121212", "#FFFFFF"]
51
+ }
52
+ },
53
+ {
54
+ group: "Muted",
55
+ items: {
56
+ muted: ["#F3F4F6", "#374151"],
57
+ "muted-foreground": ["#6B7280", "#9CA3AF"]
58
+ }
59
+ },
60
+ {
61
+ group: "Accent",
62
+ items: {
63
+ accent: ["#F3F4F6", "#374151"],
64
+ "accent-foreground": ["#1F2937", "#FFFFFF"]
65
+ }
66
+ },
67
+ {
68
+ group: "Destructive",
69
+ items: {
70
+ destructive: ["#DC2626", "#EF4444"],
71
+ "destructive-foreground": ["#FFFFFF", "#FFFFFF"]
72
+ }
73
+ }
74
+ ]
75
+ }, I = {
76
+ fontFamily: {
77
+ heading: "Inter",
78
+ body: "Inter"
79
+ },
80
+ borderRadius: "6px",
81
+ colors: {
82
+ background: ["#FFFFFF", "#09090B"],
83
+ foreground: ["#09090B", "#FFFFFF"],
84
+ primary: ["#2563EB", "#3B82F6"],
85
+ "primary-foreground": ["#FFFFFF", "#FFFFFF"],
86
+ secondary: ["#F4F4F5", "#27272A"],
87
+ "secondary-foreground": ["#09090B", "#FFFFFF"],
88
+ muted: ["#F4F4F5", "#27272A"],
89
+ "muted-foreground": ["#71717A", "#A1A1AA"],
90
+ accent: ["#F4F4F5", "#27272A"],
91
+ "accent-foreground": ["#09090B", "#FFFFFF"],
92
+ destructive: ["#EF4444", "#7F1D1D"],
93
+ "destructive-foreground": ["#FFFFFF", "#FFFFFF"],
94
+ border: ["#E4E4E7", "#27272A"],
95
+ input: ["#E4E4E7", "#27272A"],
96
+ ring: ["#2563EB", "#3B82F6"],
97
+ card: ["#FFFFFF", "#09090B"],
98
+ "card-foreground": ["#09090B", "#FFFFFF"],
99
+ popover: ["#FFFFFF", "#09090B"],
100
+ "popover-foreground": ["#09090B", "#FFFFFF"]
101
+ }
102
+ }, q = (r) => ({
103
+ fontFamily: r.fontFamily ? h(r.fontFamily).reduce(
104
+ (e, n) => ({
105
+ ...e,
106
+ [n.replace("font-", "")]: `var(--${n})`
107
+ }),
108
+ {}
109
+ ) : {},
110
+ borderRadius: r.borderRadius ? {
111
+ lg: "var(--radius)",
112
+ md: "calc(var(--radius) - 2px)",
113
+ sm: "calc(var(--radius) - 4px)"
114
+ } : {},
115
+ colors: r.colors ? v(r.colors.map((e) => Object.entries(e.items))).reduce(
116
+ (e, [n]) => ({ ...e, [n]: `hsl(var(--${n}))` }),
117
+ {}
118
+ ) : {}
119
+ });
120
+ function p(r) {
121
+ const t = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(r);
122
+ let e = parseInt(t[1], 16), n = parseInt(t[2], 16), F = parseInt(t[3], 16);
123
+ e /= 255, n /= 255, F /= 255;
124
+ const o = Math.max(e, n, F), u = Math.min(e, n, F);
125
+ let a, d;
126
+ const g = (o + u) / 2;
127
+ if (o == u)
128
+ a = d = 0;
129
+ else {
130
+ const i = o - u;
131
+ switch (d = g > 0.5 ? i / (2 - o - u) : i / (o + u), o) {
132
+ case e:
133
+ a = (n - F) / i + (n < F ? 6 : 0);
134
+ break;
135
+ case n:
136
+ a = (F - e) / i + 2;
137
+ break;
138
+ case F:
139
+ a = (e - n) / i + 4;
140
+ break;
141
+ }
142
+ a /= 6;
143
+ }
144
+ return `${Math.round(a * 360)} ${Math.round(d * 100)}% ${Math.round(g * 100)}%`;
145
+ }
146
+ const _ = (r) => {
147
+ const e = b().find((n) => n.family === r);
148
+ return `"${r}", ${B(e, "fallback", "")}`;
149
+ }, S = (r) => `:root {
150
+ ${r.fontFamily && Object.entries(r.fontFamily).map(([t, e]) => `--font-${t}: ${_(e)};`).join(`
151
+ `)}
152
+ ${r.borderRadius && `--radius: ${r.borderRadius};`}
153
+ ${r.colors && Object.entries(r.colors).map(([t, e]) => `--${t}: ${p(e[0])};`).join(`
154
+ `)}
155
+ }
156
+ .dark {
157
+ ${r.colors && Object.entries(r.colors).map(([t, e]) => `--${t}: ${p(e[1])};`).join(`
158
+ `)}
159
+ }`, w = (r) => !r || r.length === 0 ? "" : f(r, "family").map((t) => `<link rel="stylesheet" href="${t.url}" />`).join(`
160
+ `), x = (r) => !r || r.length === 0 ? "" : f(r, "family").map((t) => `@import url("${t.url}");`).join(`
161
+ `), D = (r) => !r || r.length === 0 ? "" : f(r, "family").map(
162
+ (t) => t.src.map(
163
+ (e) => `@font-face {
164
+ font-family: "${t.family}";
165
+ src: url("${e.url}") format("${e.format}");
166
+ font-display: swap;
167
+ ${e.fontWeight ? `font-weight: ${e.fontWeight};` : ""}
168
+ ${e.fontStyle ? `font-style: ${e.fontStyle};` : ""}
169
+ ${e.fontStretch ? `font-stretch: ${e.fontStretch};` : ""}
170
+ }`
171
+ ).join(`
172
+ `)
173
+ ).join(`
174
+ `);
175
+ function E(r) {
176
+ return r && r.__esModule && Object.prototype.hasOwnProperty.call(r, "default") ? r.default : r;
177
+ }
178
+ var l = {}, s = {}, m;
179
+ function P() {
180
+ return m || (m = 1, function(r) {
181
+ Object.defineProperty(r, "__esModule", {
182
+ value: !0
183
+ }), Object.defineProperty(r, "default", {
184
+ enumerable: !0,
185
+ get: function() {
186
+ return e;
187
+ }
188
+ });
189
+ function t(n, F) {
190
+ return {
191
+ handler: n,
192
+ config: F
193
+ };
194
+ }
195
+ t.withOptions = function(n, F = () => ({})) {
196
+ const o = function(u) {
197
+ return {
198
+ __options: u,
199
+ handler: n(u),
200
+ config: F(u)
201
+ };
202
+ };
203
+ return o.__isOptionsFunction = !0, o.__pluginFunction = n, o.__configFunction = F, o;
204
+ };
205
+ const e = t;
206
+ }(s)), s;
207
+ }
208
+ var y;
209
+ function A() {
210
+ return y || (y = 1, function(r) {
211
+ Object.defineProperty(r, "__esModule", {
212
+ value: !0
213
+ }), Object.defineProperty(r, "default", {
214
+ enumerable: !0,
215
+ get: function() {
216
+ return n;
217
+ }
218
+ });
219
+ const t = /* @__PURE__ */ e(P());
220
+ function e(F) {
221
+ return F && F.__esModule ? F : {
222
+ default: F
223
+ };
224
+ }
225
+ const n = t.default;
226
+ }(l)), l;
227
+ }
228
+ var c, $;
229
+ function j() {
230
+ if ($) return c;
231
+ $ = 1;
232
+ let r = A();
233
+ return c = (r.__esModule ? r : { default: r }).default, c;
234
+ }
235
+ var C = j();
236
+ const M = /* @__PURE__ */ E(C), L = M(function({ addBase: r, theme: t }) {
237
+ r({
238
+ "h1,h2,h3,h4,h5,h6": {
239
+ fontFamily: t("fontFamily.heading")
240
+ },
241
+ body: {
242
+ fontFamily: t("fontFamily.body"),
243
+ color: t("colors.foreground"),
244
+ backgroundColor: t("colors.background")
245
+ }
246
+ });
247
+ });
248
+ export {
249
+ S as a,
250
+ x as b,
251
+ L as c,
252
+ O as d,
253
+ w as e,
254
+ I as f,
255
+ q as g,
256
+ D as h,
257
+ M as p
258
+ };
@@ -0,0 +1,201 @@
1
+ import { jsx as g, jsxs as V } from "react/jsx-runtime";
2
+ import { has as y, omit as h, memoize as O, get as c, isEmpty as f, filter as b, uniqBy as z, cloneDeep as j, forEach as k, keys as B, isString as x, isObject as I, find as _, includes as w } from "lodash-es";
3
+ import S, { Suspense as C, createElement as W } from "react";
4
+ import { getRegisteredChaiBlock as L } from "@chaibuilder/runtime";
5
+ import { twMerge as G } from "tailwind-merge";
6
+ const p = "#styles:", ce = "__ADD_BLOCK_INTERNAL_ROOT", A = (e) => {
7
+ if (e = e.replace(p, ""), !e) return { baseClasses: "", classes: "" };
8
+ const t = e.split(/,(?![^\[]*\])/);
9
+ if (t.length === 1)
10
+ return { baseClasses: "", classes: t[0].trim() };
11
+ const [s, ...n] = t;
12
+ return {
13
+ baseClasses: s.trim(),
14
+ classes: n.join(",").trim().replace(/ +(?= )/g, "")
15
+ };
16
+ };
17
+ import.meta.vitest && describe("getSplitChaiClasses", () => {
18
+ it("should return the base classes and the classes", () => {
19
+ const e = {
20
+ ",styles-2": { baseClasses: "", classes: "styles-2" },
21
+ "styles-1,styles-2": { baseClasses: "styles-1", classes: "styles-2" },
22
+ ",bg-[linear-gradient(-10deg,black,transparent_100%)]": {
23
+ baseClasses: "",
24
+ classes: "bg-[linear-gradient(-10deg,black,transparent_100%)]"
25
+ },
26
+ "styles-1,bg-[linear-gradient(-10deg,black,transparent_100%)]": {
27
+ baseClasses: "styles-1",
28
+ classes: "bg-[linear-gradient(-10deg,black,transparent_100%)]"
29
+ },
30
+ someclass: {
31
+ baseClasses: "",
32
+ classes: "someclass"
33
+ },
34
+ ",bg-red-500 text-center font-bold": {
35
+ baseClasses: "",
36
+ classes: "bg-red-500 text-center font-bold"
37
+ },
38
+ "bg-[linear-gradient(-10deg,black,transparent_100%)], bg-[linear-gradient(-10deg,black,transparent_100%)]": {
39
+ baseClasses: "bg-[linear-gradient(-10deg,black,transparent_100%)]",
40
+ classes: "bg-[linear-gradient(-10deg,black,transparent_100%)]"
41
+ }
42
+ };
43
+ for (let t in e) {
44
+ const s = A(`${p}${t}`);
45
+ expect(s).toEqual(e[t]);
46
+ }
47
+ });
48
+ });
49
+ async function H(e) {
50
+ const t = await e.dataProvider({
51
+ pageProps: e.pageProps,
52
+ block: e.block,
53
+ lang: e.lang,
54
+ draft: e.draft,
55
+ inBuilder: e.inBuilder
56
+ });
57
+ return y(t, "$metadata") && e.dataProviderMetadataCallback(e.block, t.$metadata), /* @__PURE__ */ g(C, { children: S.createElement(e.component, {
58
+ ...h(e.props, ["dataProvider", "dataProviderMetadataCallback"]),
59
+ ...h(t, "$metadata"),
60
+ key: `${e.block._id}-async`
61
+ }) });
62
+ }
63
+ const J = O((e) => {
64
+ const { baseClasses: t, classes: s } = A(e);
65
+ return G(t, s).replace(p, "").trim();
66
+ }), T = (e, t) => {
67
+ const s = j(e);
68
+ return k(B(s), (n) => {
69
+ if (x(s[n])) {
70
+ let l = s[n];
71
+ const r = /\{\{(.*?)\}\}/g, o = l.match(r);
72
+ o && o.forEach((i) => {
73
+ const d = i.slice(2, -2), m = c(t, d, i);
74
+ l = l.replace(i, m);
75
+ }), s[n] = l;
76
+ }
77
+ I(s[n]) && (s[n] = T(s[n], t));
78
+ }), s;
79
+ };
80
+ function Q(e, t) {
81
+ const s = c(e, `${t}_attrs`, {}), n = B(s).join(" ");
82
+ return w(n, "x-show") && !w(n, "x-transition") && (s["x-transition"] = ""), s;
83
+ }
84
+ function U(e) {
85
+ const t = {};
86
+ return Object.keys(e).forEach((s) => {
87
+ if (x(e[s]) && e[s].startsWith(p)) {
88
+ const n = J(e[s]);
89
+ t[s] = {
90
+ className: n,
91
+ ...Q(e, s)
92
+ };
93
+ }
94
+ }), t;
95
+ }
96
+ function X(e, t, s) {
97
+ if (f(t)) return e;
98
+ const n = j(e), l = c(s, "i18nProps", []);
99
+ return k(B(n), (r) => {
100
+ l.includes(r) && !f(t) && (n[r] = c(n, `${r}-${t}`, n[r]));
101
+ }), n;
102
+ }
103
+ const Z = O((e) => {
104
+ const t = L(e), s = c(t, "schema.properties", {});
105
+ return Object.fromEntries(Object.entries(s).filter(([, n]) => c(n, "runtime", !1)));
106
+ }), ee = (e, t, s) => f(s) ? {} : Object.entries(s).reduce((n, [l, r]) => {
107
+ const o = [];
108
+ let i = _(e, { _id: t });
109
+ for (; i; )
110
+ o.push(i), i = _(e, { _id: i._parent });
111
+ const d = _(o, { _type: r.block });
112
+ return d && (n[l] = c(d, c(r, "prop"), null)), n;
113
+ }, {}), se = () => /* @__PURE__ */ g("span", { children: "Loading..." });
114
+ function oe(e) {
115
+ if (y(e, "metadata") && console.warn(" metadata is deprecated and will be removed in upcoming version, use forwardProps instead"), f(e.lang) && !f(e.fallbackLang))
116
+ throw new Error("lang prop is required when fallbackLang is provided");
117
+ const t = e.lang ?? "en", s = e.fallbackLang ?? t;
118
+ return /* @__PURE__ */ g(K, { ...e, lang: t, fallbackLang: s });
119
+ }
120
+ function K({
121
+ blocks: e,
122
+ parent: t,
123
+ externalData: s = {},
124
+ lang: n = "en",
125
+ fallbackLang: l = "en",
126
+ pageProps: r = {},
127
+ dataProviderMetadataCallback: o = () => {
128
+ },
129
+ draft: i = !1
130
+ }) {
131
+ const d = e, m = (a) => U(a), M = t ? b(e, { _parent: t }) : b(e, (a) => f(a._parent));
132
+ return z(M, "_id").map((a, N) => {
133
+ const E = {}, q = b(d, { _parent: a._id });
134
+ E.children = q.length > 0 ? /* @__PURE__ */ g(
135
+ K,
136
+ {
137
+ externalData: s,
138
+ parent: a._id,
139
+ blocks: d,
140
+ lang: n,
141
+ fallbackLang: l,
142
+ pageProps: r,
143
+ dataProviderMetadataCallback: o,
144
+ draft: i
145
+ },
146
+ `${a._id}-children`
147
+ ) : null;
148
+ const u = L(a._type);
149
+ if (u !== null) {
150
+ let P = a;
151
+ const $ = u.component;
152
+ P = { ...u.defaults, ...a };
153
+ const F = n === l ? "" : n, Y = ee(d, a._id, Z(a._type)), v = T(X(a, F, u), s), R = h(
154
+ {
155
+ ...P,
156
+ ...v,
157
+ ...m(v),
158
+ ...E,
159
+ ...Y,
160
+ index: N,
161
+ lang: n,
162
+ key: a._id,
163
+ draft: i,
164
+ pageProps: r,
165
+ blockProps: {},
166
+ inBuilder: !1
167
+ },
168
+ ["_parent"]
169
+ );
170
+ if (y(u, "dataProvider")) {
171
+ const D = c(u, "suspenseFallback", se);
172
+ return /* @__PURE__ */ g(C, { fallback: W(D), children: /* @__PURE__ */ g(
173
+ H,
174
+ {
175
+ inBuilder: !1,
176
+ dataProviderMetadataCallback: o,
177
+ lang: n,
178
+ pageProps: r,
179
+ dataProvider: u.dataProvider,
180
+ block: a,
181
+ component: $,
182
+ props: R,
183
+ draft: i
184
+ },
185
+ `${a._id}-async`
186
+ ) }, `${a._id}-suspense`);
187
+ }
188
+ return /* @__PURE__ */ g(C, { children: S.createElement($, R) }, `${a._id}-suspense`);
189
+ }
190
+ return /* @__PURE__ */ V("noscript", { children: [
191
+ a._type,
192
+ " not found"
193
+ ] }, `${a._id}-noscript`);
194
+ });
195
+ }
196
+ export {
197
+ oe as R,
198
+ p as S,
199
+ ce as a,
200
+ A as g
201
+ };
@@ -0,0 +1 @@
1
+ "use strict";const u=require("react/jsx-runtime"),s=require("lodash-es"),f=require("react"),E=require("@chaibuilder/runtime"),O=require("tailwind-merge"),p="#styles:",v="__ADD_BLOCK_INTERNAL_ROOT",B=e=>{if(e=e.replace(p,""),!e)return{baseClasses:"",classes:""};const n=e.split(/,(?![^\[]*\])/);if(n.length===1)return{baseClasses:"",classes:n[0].trim()};const[t,...a]=n;return{baseClasses:t.trim(),classes:a.join(",").trim().replace(/ +(?= )/g,"")}};async function L(e){const n=await e.dataProvider({pageProps:e.pageProps,block:e.block,lang:e.lang,draft:e.draft,inBuilder:e.inBuilder});return s.has(n,"$metadata")&&e.dataProviderMetadataCallback(e.block,n.$metadata),u.jsx(f.Suspense,{children:f.createElement(e.component,{...s.omit(e.props,["dataProvider","dataProviderMetadataCallback"]),...s.omit(n,"$metadata"),key:`${e.block._id}-async`})})}const T=s.memoize(e=>{const{baseClasses:n,classes:t}=B(e);return O.twMerge(n,t).replace(p,"").trim()}),S=(e,n)=>{const t=s.cloneDeep(e);return s.forEach(s.keys(t),a=>{if(s.isString(t[a])){let c=t[a];const i=/\{\{(.*?)\}\}/g,o=c.match(i);o&&o.forEach(l=>{const d=l.slice(2,-2),m=s.get(n,d,l);c=c.replace(l,m)}),t[a]=c}s.isObject(t[a])&&(t[a]=S(t[a],n))}),t};function q(e,n){const t=s.get(e,`${n}_attrs`,{}),a=s.keys(t).join(" ");return s.includes(a,"x-show")&&!s.includes(a,"x-transition")&&(t["x-transition"]=""),t}function M(e){const n={};return Object.keys(e).forEach(t=>{if(s.isString(e[t])&&e[t].startsWith(p)){const a=T(e[t]);n[t]={className:a,...q(e,t)}}}),n}function Y(e,n,t){if(s.isEmpty(n))return e;const a=s.cloneDeep(e),c=s.get(t,"i18nProps",[]);return s.forEach(s.keys(a),i=>{c.includes(i)&&!s.isEmpty(n)&&(a[i]=s.get(a,`${i}-${n}`,a[i]))}),a}const K=s.memoize(e=>{const n=E.getRegisteredChaiBlock(e),t=s.get(n,"schema.properties",{});return Object.fromEntries(Object.entries(t).filter(([,a])=>s.get(a,"runtime",!1)))}),A=(e,n,t)=>s.isEmpty(t)?{}:Object.entries(t).reduce((a,[c,i])=>{const o=[];let l=s.find(e,{_id:n});for(;l;)o.push(l),l=s.find(e,{_id:l._parent});const d=s.find(o,{_type:i.block});return d&&(a[c]=s.get(d,s.get(i,"prop"),null)),a},{}),N=()=>u.jsx("span",{children:"Loading..."});function D(e){if(s.has(e,"metadata")&&console.warn(" metadata is deprecated and will be removed in upcoming version, use forwardProps instead"),s.isEmpty(e.lang)&&!s.isEmpty(e.fallbackLang))throw new Error("lang prop is required when fallbackLang is provided");const n=e.lang??"en",t=e.fallbackLang??n;return u.jsx(j,{...e,lang:n,fallbackLang:t})}function j({blocks:e,parent:n,externalData:t={},lang:a="en",fallbackLang:c="en",pageProps:i={},dataProviderMetadataCallback:o=()=>{},draft:l=!1}){const d=e,m=r=>M(r),P=n?s.filter(e,{_parent:n}):s.filter(e,r=>s.isEmpty(r._parent));return s.uniqBy(P,"_id").map((r,k)=>{const _={},x=s.filter(d,{_parent:r._id});_.children=x.length>0?u.jsx(j,{externalData:t,parent:r._id,blocks:d,lang:a,fallbackLang:c,pageProps:i,dataProviderMetadataCallback:o,draft:l},`${r._id}-children`):null;const g=E.getRegisteredChaiBlock(r._type);if(g!==null){let b=r;const h=g.component;b={...g.defaults,...r};const R=a===c?"":a,$=A(d,r._id,K(r._type)),y=S(Y(r,R,g),t),C=s.omit({...b,...y,...m(y),..._,...$,index:k,lang:a,key:r._id,draft:l,pageProps:i,blockProps:{},inBuilder:!1},["_parent"]);if(s.has(g,"dataProvider")){const w=s.get(g,"suspenseFallback",N);return u.jsx(f.Suspense,{fallback:f.createElement(w),children:u.jsx(L,{inBuilder:!1,dataProviderMetadataCallback:o,lang:a,pageProps:i,dataProvider:g.dataProvider,block:r,component:h,props:C,draft:l},`${r._id}-async`)},`${r._id}-suspense`)}return u.jsx(f.Suspense,{children:f.createElement(h,C)},`${r._id}-suspense`)}return u.jsxs("noscript",{children:[r._type," not found"]},`${r._id}-noscript`)})}exports.ROOT_TEMP_KEY=v;exports.RenderChaiBlocks=D;exports.STYLES_KEY=p;exports.getSplitChaiClasses=B;
package/dist/render.cjs CHANGED
@@ -1,3 +1,3 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("./chai-theme-helpers-BjWE6otR.cjs"),n=require("lodash-es"),$=require("@mhsdesign/jit-browser-tailwindcss"),R=require("@tailwindcss/aspect-ratio"),O=require("@tailwindcss/container-queries"),F=require("@tailwindcss/forms"),L=require("@tailwindcss/typography"),C=require("./plugin-BiiuylVf.cjs"),u=require("react/jsx-runtime"),E=require("@chaibuilder/runtime"),f=require("react"),M=require("tailwind-merge"),m=require("./getSplitClasses-DodqA_KW.cjs"),N=e=>{if(!e)return[];try{return JSON.parse(A(e)).filter(t=>!t._type.startsWith("@chai"))}catch{return[{_type:"Paragraph",_id:"error",content:"Invalid JSON. Please check the JSON string."}]}};function A(e){const i=/(asset:\/\/|https:\/\/asset\.localhost\/)(?:localhost\/)?[^"']+/g;return e.replace(i,t=>{const s=decodeURIComponent(t),a=s.indexOf("public");return a!==-1?s.substring(a+6):s})}async function I(e,i,t=[],s="",a){return await $.createTailwindcss({tailwindConfig:{darkMode:"class",safelist:t,theme:{extend:C.getChaiBuilderTheme(e)},plugins:[F,L,R,O,C.chaiBuilderPlugin],corePlugins:{preflight:a},...s?{prefix:`${s}`}:{}}}).generateStylesFromContent(` ${a?"@tailwind base;":""}
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./plugin-C01tjI6V.cjs"),a=require("./render-chai-blocks-Bvl2_fRE.cjs");require("lodash-es");const c=require("@tailwindcss/aspect-ratio"),l=require("@tailwindcss/forms"),u=require("@tailwindcss/typography");require("tailwindcss-animate");const d=require("./get-chai-builder-theme-CeaKvOZ8.cjs"),g=require("@mhsdesign/jit-browser-tailwindcss"),h=require("@tailwindcss/container-queries"),p=e=>{if(!e)return[];try{return JSON.parse(m(e)).filter(r=>!r._type.startsWith("@chai"))}catch{return[{_type:"Paragraph",_id:"error",content:"Invalid JSON. Please check the JSON string."}]}};function m(e){const t=/(asset:\/\/|https:\/\/asset\.localhost\/)(?:localhost\/)?[^"']+/g;return e.replace(t,r=>{const i=decodeURIComponent(r),s=i.indexOf("public");return s!==-1?i.substring(s+6):i})}async function k(e,t,r=[],i="",s){return await g.createTailwindcss({tailwindConfig:{darkMode:"class",safelist:r,theme:{extend:d.getChaiBuilderTheme(e)},plugins:[l,u,c,h,n.chaiBuilderPlugin],corePlugins:{preflight:s},...i?{prefix:`${i}`}:{}}}).generateStylesFromContent(` ${s?"@tailwind base;":""}
2
2
  @tailwind components;
3
- @tailwind utilities;`,i)}const J=(e,i,t)=>{const s=JSON.stringify(e).replace(/#styles:([^"]*)/g,(a,c)=>`#styles:${c.replace(/,/g," ")}`.replace(/#styles:/g,""));return I(i,[s],[],"",t)},V=async(e,i=p.defaultThemeOptions,t=!1)=>await J(e,i,t);async function Y(e){const i=await e.dataProvider({pageProps:e.pageProps,block:e.block,lang:e.lang,draft:e.draft,inBuilder:e.inBuilder});return n.has(i,"$metadata")&&e.dataProviderMetadataCallback(e.block,i.$metadata),u.jsx(f.Suspense,{children:f.createElement(e.component,{...n.omit(e.props,["dataProvider","dataProviderMetadataCallback"]),...n.omit(i,"$metadata"),key:`${e.block._id}-async`})})}const K=n.memoize(e=>{const{baseClasses:i,classes:t}=m.getSplitChaiClasses(e);return M.twMerge(i,t).replace(m.STYLES_KEY,"").trim()}),P=(e,i)=>{const t=n.cloneDeep(e);return n.forEach(n.keys(t),s=>{if(n.isString(t[s])){let a=t[s];const c=/\{\{(.*?)\}\}/g,l=a.match(c);l&&l.forEach(o=>{const d=o.slice(2,-2),h=n.get(i,d,o);a=a.replace(o,h)}),t[s]=a}n.isObject(t[s])&&(t[s]=P(t[s],i))}),t};function z(e,i){const t=n.get(e,`${i}_attrs`,{}),s=n.keys(t).join(" ");return n.includes(s,"x-show")&&!n.includes(s,"x-transition")&&(t["x-transition"]=""),t}function U(e){const i={};return Object.keys(e).forEach(t=>{if(n.isString(e[t])&&e[t].startsWith(m.STYLES_KEY)){const s=K(e[t]);i[t]={className:s,...z(e,t)}}}),i}function W(e,i,t){if(n.isEmpty(i))return e;const s=n.cloneDeep(e),a=n.get(t,"i18nProps",[]);return n.forEach(n.keys(s),c=>{a.includes(c)&&!n.isEmpty(i)&&(s[c]=n.get(s,`${c}-${i}`,s[c]))}),s}const D=n.memoize(e=>{const i=E.getRegisteredChaiBlock(e),t=n.get(i,"schema.properties",{});return Object.fromEntries(Object.entries(t).filter(([,s])=>n.get(s,"runtime",!1)))}),H=(e,i,t)=>n.isEmpty(t)?{}:Object.entries(t).reduce((s,[a,c])=>{const l=[];let o=n.find(e,{_id:i});for(;o;)l.push(o),o=n.find(e,{_id:o._parent});const d=n.find(l,{_type:c.block});return d&&(s[a]=n.get(d,n.get(c,"prop"),null)),s},{}),G=()=>u.jsx("span",{children:"Loading..."});function Q(e){if(n.has(e,"metadata")&&console.warn(" metadata is deprecated and will be removed in upcoming version, use forwardProps instead"),n.isEmpty(e.lang)&&!n.isEmpty(e.fallbackLang))throw new Error("lang prop is required when fallbackLang is provided");const i=e.lang??"en",t=e.fallbackLang??i;return u.jsx(T,{...e,lang:i,fallbackLang:t})}function T({blocks:e,parent:i,externalData:t={},lang:s="en",fallbackLang:a="en",pageProps:c={},dataProviderMetadataCallback:l=()=>{},draft:o=!1}){const d=e,h=r=>U(r),b=i?n.filter(e,{_parent:i}):n.filter(e,r=>n.isEmpty(r._parent));return n.uniqBy(b,"_id").map((r,k)=>{const S={},j=n.filter(d,{_parent:r._id});S.children=j.length>0?u.jsx(T,{externalData:t,parent:r._id,blocks:d,lang:s,fallbackLang:a,pageProps:c,dataProviderMetadataCallback:l,draft:o},`${r._id}-children`):null;const g=E.getRegisteredChaiBlock(r._type);if(g!==null){let y=r;const w=g.component;y={...g.defaults,...r};const x=s===a?"":s,v=H(d,r._id,D(r._type)),_=P(W(r,x,g),t),B=n.omit({...y,..._,...h(_),...S,...v,index:k,lang:s,key:r._id,draft:o,pageProps:c,blockProps:{},inBuilder:!1},["_parent"]);if(n.has(g,"dataProvider")){const q=n.get(g,"suspenseFallback",G);return u.jsx(f.Suspense,{fallback:f.createElement(q),children:u.jsx(Y,{inBuilder:!1,dataProviderMetadataCallback:l,lang:s,pageProps:c,dataProvider:g.dataProvider,block:r,component:w,props:B,draft:o},`${r._id}-async`)},`${r._id}-suspense`)}return u.jsx(f.Suspense,{children:f.createElement(w,B)},`${r._id}-suspense`)}return u.jsxs("noscript",{children:[r._type," not found"]},`${r._id}-noscript`)})}exports.getChaiThemeCssVariables=p.getChaiThemeCssVariables;exports.getThemeFontsCSSImport=p.getThemeFontsCSSImport;exports.getThemeFontsLinkMarkup=p.getThemeFontsLinkMarkup;exports.RenderChaiBlocks=Q;exports.convertToBlocks=N;exports.getStylesForBlocks=V;
3
+ @tailwind utilities;`,t)}const w=(e,t,r)=>{const i=JSON.stringify(e).replace(/#styles:([^"]*)/g,(s,o)=>`#styles:${o.replace(/,/g," ")}`.replace(/#styles:/g,""));return k(t,[i],[],"",r)},S=async(e,t=n.defaultThemeOptions,r=!1)=>await w(e,t,r);exports.getChaiThemeCssVariables=n.getChaiThemeCssVariables;exports.getThemeFontsCSSImport=n.getThemeFontsCSSImport;exports.getThemeFontsLinkMarkup=n.getThemeFontsLinkMarkup;exports.RenderChaiBlocks=a.RenderChaiBlocks;exports.convertToBlocks=p;exports.getStylesForBlocks=S;
package/dist/render.d.ts CHANGED
@@ -23,9 +23,33 @@ declare type ChaiBuilderThemeOptions = {
23
23
  };
24
24
 
25
25
  declare type ChaiBuilderThemeValues = {
26
- fontFamily: Record<string, string>;
26
+ fontFamily: {
27
+ heading: string;
28
+ body: string;
29
+ };
27
30
  borderRadius: string;
28
- colors: Record<string, string[]>;
31
+ colors: {
32
+ background: [HexColor, HexColor];
33
+ foreground: [HexColor, HexColor];
34
+ primary: [HexColor, HexColor];
35
+ "primary-foreground": [HexColor, HexColor];
36
+ secondary: [HexColor, HexColor];
37
+ "secondary-foreground": [HexColor, HexColor];
38
+ muted: [HexColor, HexColor];
39
+ "muted-foreground": [HSLColor, HSLColor];
40
+ accent: [HSLColor, HSLColor];
41
+ "accent-foreground": [HSLColor, HSLColor];
42
+ destructive: [HSLColor, HSLColor];
43
+ "destructive-foreground": [HSLColor, HSLColor];
44
+ border: [HSLColor, HSLColor];
45
+ input: [HSLColor, HSLColor];
46
+ ring: [HexColor, HexColor];
47
+ card: [HexColor, HexColor];
48
+ "card-foreground": [HexColor, HexColor];
49
+ popover: [HexColor, HexColor];
50
+ "popover-foreground": [HexColor, HexColor];
51
+ [key: string]: [HexColor, HexColor];
52
+ };
29
53
  };
30
54
 
31
55
  /**
@@ -34,7 +58,7 @@ declare type ChaiBuilderThemeValues = {
34
58
  */
35
59
  export declare const convertToBlocks: (chaiFormatContent: string) => ChaiBlock[];
36
60
 
37
- export declare const getChaiThemeCssVariables: (chaiTheme: Partial<ChaiBuilderThemeValues>) => string;
61
+ export declare const getChaiThemeCssVariables: (chaiTheme: ChaiBuilderThemeValues) => string;
38
62
 
39
63
  /**
40
64
  * Get the tailwind css for the blocks
@@ -49,6 +73,8 @@ export declare const getThemeFontsCSSImport: (fonts: ChaiFontViaUrl[]) => any;
49
73
 
50
74
  export declare const getThemeFontsLinkMarkup: (fonts: ChaiFontViaUrl[]) => any;
51
75
 
76
+ declare type HexColor = string;
77
+
52
78
  declare type HSLColor = string;
53
79
 
54
80
  export declare function RenderChaiBlocks(props: RenderChaiBlocksProps): JSX_2.Element;