@chaibuilder/sdk 2.0.4 → 2.0.6
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/core.cjs +3 -3
- package/dist/core.d.ts +30 -28
- package/dist/core.js +490 -508
- package/dist/render.cjs +2 -2
- package/dist/render.js +60 -60
- package/package.json +3 -3
package/dist/render.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("./ChaiThemeFn-DQu-2Eh9.cjs"),s=require("lodash-es"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("./ChaiThemeFn-DQu-2Eh9.cjs"),s=require("lodash-es"),m=require("./getSplitClasses-DodqA_KW.cjs"),F=require("@mhsdesign/jit-browser-tailwindcss"),b=require("@tailwindcss/aspect-ratio"),k=require("@tailwindcss/container-queries"),M=require("@tailwindcss/forms"),N=require("@tailwindcss/typography"),w=require("./plugin-2xcljWGM.cjs"),g=require("react/jsx-runtime"),T=require("@chaibuilder/runtime"),p=require("react"),Y=require("tailwind-merge"),I=(e,r="")=>{const{classes:n}=m.getSplitChaiClasses(e),t=n.split(" ").map(i=>i.split(" ").map(a=>{if(a==="")return"";if(a.includes(":")){const u=a.split(":");return u[u.length-1]=r+s.last(u),u.join(":")}return`${r}${a}`}).join(" "));return s.flattenDeep(t).join(" ")},A=e=>{if(!e)return[];try{return JSON.parse(J(e)).filter(n=>!n._type.startsWith("@chai"))}catch{return[{_type:"Paragraph",_id:"error",content:"Invalid JSON. Please check the JSON string."}]}};function J(e){const r=/(asset:\/\/|https:\/\/asset\.localhost\/)(?:localhost\/)?[^"']+/g;return e.replace(r,n=>{const t=decodeURIComponent(n),i=t.indexOf("public");return i!==-1?t.substring(i+6):t})}async function K(e,r,n=[],t="",i){return await F.createTailwindcss({tailwindConfig:{darkMode:"class",safelist:n,theme:{extend:w.getChaiBuilderTheme(e)},plugins:[M,N,b,k,w.chaiBuilderPlugin],corePlugins:{preflight:i},...t?{prefix:`${t}`}:{}}}).generateStylesFromContent(` ${i?"@tailwind base;":""}
|
|
2
2
|
@tailwind components;
|
|
3
|
-
@tailwind utilities;`,r)}const
|
|
3
|
+
@tailwind utilities;`,r)}const L=(e,r,n)=>{const t=JSON.stringify(e).replace(/#styles:([^"]*)/g,(i,c)=>`#styles:${c.replace(/,/g," ")}`.replace(/#styles:/g,""));return K(r,[t],[],"",n)},V=async(e,r=S.defaultThemeOptions,n=!1)=>await L(e,r,n);async function U(e){const r=await(e==null?void 0:e.dataProvider(e.block,e.lang,e.metadata));return s.has(r,"$metadata")&&e.dataProviderMetadataCallback(e.block,r.$metadata),g.jsx(p.Suspense,{children:p.createElement(e.component,{...s.omit(e.props,["dataProvider","dataProviderMetadataCallback"]),...s.omit(r,"$metadata")})})}const z=s.memoize((e,r)=>{const{baseClasses:n,classes:t}=m.getSplitChaiClasses(e),i=Y.twMerge(n,t);return r===""?i.replace(m.STYLES_KEY,"").trim():I(i,r).replace(m.STYLES_KEY,"").trim()}),j=(e,r)=>{const n=s.cloneDeep(e);return s.forEach(s.keys(n),t=>{if(s.isString(n[t])){let i=n[t];const c=/\{\{(.*?)\}\}/g,l=i.match(c);l&&l.forEach(a=>{const u=a.slice(2,-2),h=s.get(r,u,a);i=i.replace(a,h)}),n[t]=i}s.isObject(n[t])&&(n[t]=j(n[t],r))}),n};function D(e,r){const n=s.get(e,`${r}_attrs`,{}),t=s.keys(n).join(" ");return s.includes(t,"x-show")&&!s.includes(t,"x-transition")&&(n["x-transition"]=""),n}function W(e,r){const n={};return Object.keys(e).forEach(t=>{if(s.isString(e[t])&&e[t].startsWith(m.STYLES_KEY)){const i=z(e[t],r);n[t]={className:i,...D(e,t)}}}),n}function Q(e,r,n){if(s.isEmpty(r))return e;const t=s.cloneDeep(e),i=s.get(n,"i18nProps",[]);return s.forEach(s.keys(t),c=>{i.includes(c)&&!s.isEmpty(r)&&(t[c]=s.get(t,`${c}-${r}`,t[c]))}),t}const G=s.memoize(e=>{const r=T.getRegisteredChaiBlock(e),n=s.get(r,"schema.properties",{});return Object.fromEntries(Object.entries(n).filter(([,t])=>s.get(t,"runtime",!1)))}),H=(e,r,n)=>s.isEmpty(n)?{}:Object.entries(n).reduce((t,[i,c])=>{const l=[];let a=s.find(e,{_id:r});for(;a;)l.push(a),a=s.find(e,{_id:a._parent});const u=s.find(l,{_type:c.block});return u&&(t[i]=s.get(u,s.get(c,"prop"),null)),t},{}),X=()=>g.jsx("span",{children:"Loading..."});function E({blocks:e,parent:r,classPrefix:n="",externalData:t={},blockModifierCallback:i=null,lang:c="",fallbackLang:l="",metadata:a={},dataProviderMetadataCallback:u=()=>{}}){const h=e,P=o=>W(o,n),q=r?s.filter(e,{_parent:r}):s.filter(e,o=>s.isEmpty(o._parent));return s.uniqBy(q,"_id").map((o,v)=>{const y={},x=s.filter(h,{_parent:o._id});y.children=x.length>0?g.jsx(E,{externalData:t,classPrefix:n,parent:o._id,blocks:h,lang:c||l,metadata:a},o._id):null;const d=T.getRegisteredChaiBlock(o._type);if(d!==null){let f=o;const C=d.component;f={...d.defaults,...o},i&&(f=i(f));const O=c===l?"":c,R=H(h,o._id,G(o._type)),_=j(Q(o,O,d),t),B=s.omit({blockProps:{},inBuilder:!1,...f,index:v,..._,...P(_),...y,...R,metadata:a,lang:c||l,key:o._id},["_parent"]);if(s.has(d,"dataProvider")){const $=s.get(d,"suspenseFallback",X);return g.jsx(p.Suspense,{fallback:p.createElement($),children:g.jsx(U,{dataProviderMetadataCallback:u,lang:c||l,metadata:a,dataProvider:d.dataProvider,block:o,component:C,props:B},o._id)},o._id)}return g.jsx(p.Suspense,{children:p.createElement(C,B)},o._id)}return g.jsxs("noscript",{children:[o._type," not found"]},o._id)})}exports.getChaiThemeCssVariables=S.getChaiThemeCssVariables;exports.getThemeFontsCSSImport=S.getThemeFontsCSSImport;exports.getThemeFontsLinkMarkup=S.getThemeFontsLinkMarkup;exports.RenderChaiBlocks=E;exports.convertToBlocks=A;exports.getStylesForBlocks=V;
|
package/dist/render.js
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
import { d as
|
|
2
|
-
import { a as
|
|
3
|
-
import { last as
|
|
1
|
+
import { d as Y } from "./ChaiThemeFn-Cort9tch.js";
|
|
2
|
+
import { a as At, b as It, c as Jt } from "./ChaiThemeFn-Cort9tch.js";
|
|
3
|
+
import { last as q, flattenDeep as z, has as O, omit as S, memoize as $, get as d, filter as h, isEmpty as g, uniqBy as D, cloneDeep as E, forEach as x, keys as w, isString as R, isObject as L, find as _, includes as j } from "lodash-es";
|
|
4
4
|
import { g as b, S as y } from "./getSplitClasses-DphwgQiE.js";
|
|
5
|
-
import { createTailwindcss as
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import { g as
|
|
11
|
-
import { jsx as p, jsxs as
|
|
5
|
+
import { createTailwindcss as Q } from "@mhsdesign/jit-browser-tailwindcss";
|
|
6
|
+
import G from "@tailwindcss/aspect-ratio";
|
|
7
|
+
import H from "@tailwindcss/container-queries";
|
|
8
|
+
import X from "@tailwindcss/forms";
|
|
9
|
+
import Z from "@tailwindcss/typography";
|
|
10
|
+
import { g as k, c as tt } from "./plugin-kUMxtQR5.js";
|
|
11
|
+
import { jsx as p, jsxs as et } from "react/jsx-runtime";
|
|
12
12
|
import { getRegisteredChaiBlock as F } from "@chaibuilder/runtime";
|
|
13
|
-
import N, { Suspense as C, createElement as
|
|
14
|
-
import { twMerge as
|
|
15
|
-
const
|
|
13
|
+
import N, { Suspense as C, createElement as nt } from "react";
|
|
14
|
+
import { twMerge as st } from "tailwind-merge";
|
|
15
|
+
const rt = (t, s = "") => {
|
|
16
16
|
const { classes: n } = b(t), e = n.split(" ").map((r) => r.split(" ").map((a) => {
|
|
17
17
|
if (a === "") return "";
|
|
18
18
|
if (a.includes(":")) {
|
|
19
19
|
const l = a.split(":");
|
|
20
|
-
return l[l.length - 1] = s +
|
|
20
|
+
return l[l.length - 1] = s + q(l), l.join(":");
|
|
21
21
|
}
|
|
22
22
|
return `${s}${a}`;
|
|
23
23
|
}).join(" "));
|
|
24
24
|
return z(e).join(" ");
|
|
25
|
-
},
|
|
25
|
+
}, Rt = (t) => {
|
|
26
26
|
if (!t) return [];
|
|
27
27
|
try {
|
|
28
|
-
return JSON.parse(
|
|
28
|
+
return JSON.parse(it(t)).filter((n) => !n._type.startsWith("@chai"));
|
|
29
29
|
} catch {
|
|
30
30
|
return [{ _type: "Paragraph", _id: "error", content: "Invalid JSON. Please check the JSON string." }];
|
|
31
31
|
}
|
|
32
32
|
};
|
|
33
|
-
function
|
|
33
|
+
function it(t) {
|
|
34
34
|
const s = /(asset:\/\/|https:\/\/asset\.localhost\/)(?:localhost\/)?[^"']+/g;
|
|
35
35
|
return t.replace(s, (n) => {
|
|
36
36
|
const e = decodeURIComponent(n), r = e.indexOf("public");
|
|
37
37
|
return r !== -1 ? e.substring(r + 6) : e;
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
|
-
async function
|
|
41
|
-
return await
|
|
40
|
+
async function ot(t, s, n = [], e = "", r) {
|
|
41
|
+
return await Q({
|
|
42
42
|
tailwindConfig: {
|
|
43
43
|
darkMode: "class",
|
|
44
44
|
safelist: n,
|
|
45
|
-
theme: { extend:
|
|
46
|
-
plugins: [
|
|
45
|
+
theme: { extend: k(t) },
|
|
46
|
+
plugins: [X, Z, G, H, tt],
|
|
47
47
|
corePlugins: { preflight: r },
|
|
48
48
|
...e ? { prefix: `${e}` } : {}
|
|
49
49
|
}
|
|
@@ -54,20 +54,20 @@ async function rt(t, s, n = [], e = "", r) {
|
|
|
54
54
|
s
|
|
55
55
|
);
|
|
56
56
|
}
|
|
57
|
-
const
|
|
57
|
+
const at = (t, s, n) => {
|
|
58
58
|
const e = JSON.stringify(t).replace(/#styles:([^"]*)/g, (r, o) => `#styles:${o.replace(/,/g, " ")}`.replace(/#styles:/g, ""));
|
|
59
|
-
return
|
|
60
|
-
},
|
|
61
|
-
async function
|
|
59
|
+
return ot(s, [e], [], "", n);
|
|
60
|
+
}, bt = async (t, s = Y, n = !1) => await at(t, s, n);
|
|
61
|
+
async function ct(t) {
|
|
62
62
|
const s = await (t == null ? void 0 : t.dataProvider(t.block, t.lang, t.metadata));
|
|
63
63
|
return O(s, "$metadata") && t.dataProviderMetadataCallback(t.block, s.$metadata), /* @__PURE__ */ p(C, { children: N.createElement(t.component, {
|
|
64
64
|
...S(t.props, ["dataProvider", "dataProviderMetadataCallback"]),
|
|
65
65
|
...S(s, "$metadata")
|
|
66
66
|
}) });
|
|
67
67
|
}
|
|
68
|
-
const
|
|
69
|
-
const { baseClasses: n, classes: e } = b(t), r =
|
|
70
|
-
return s === "" ? r.replace(y, "").trim() :
|
|
68
|
+
const lt = $((t, s) => {
|
|
69
|
+
const { baseClasses: n, classes: e } = b(t), r = st(n, e);
|
|
70
|
+
return s === "" ? r.replace(y, "").trim() : rt(r, s).replace(y, "").trim();
|
|
71
71
|
}), A = (t, s) => {
|
|
72
72
|
const n = E(t);
|
|
73
73
|
return x(w(n), (e) => {
|
|
@@ -79,44 +79,44 @@ const at = $((t, s) => {
|
|
|
79
79
|
r = r.replace(a, m);
|
|
80
80
|
}), n[e] = r;
|
|
81
81
|
}
|
|
82
|
-
|
|
82
|
+
L(n[e]) && (n[e] = A(n[e], s));
|
|
83
83
|
}), n;
|
|
84
84
|
};
|
|
85
|
-
function
|
|
85
|
+
function dt(t, s) {
|
|
86
86
|
const n = d(t, `${s}_attrs`, {}), e = w(n).join(" ");
|
|
87
87
|
return j(e, "x-show") && !j(e, "x-transition") && (n["x-transition"] = ""), n;
|
|
88
88
|
}
|
|
89
|
-
function
|
|
89
|
+
function ut(t, s) {
|
|
90
90
|
const n = {};
|
|
91
91
|
return Object.keys(t).forEach((e) => {
|
|
92
92
|
if (R(t[e]) && t[e].startsWith(y)) {
|
|
93
|
-
const r =
|
|
93
|
+
const r = lt(t[e], s);
|
|
94
94
|
n[e] = {
|
|
95
95
|
className: r,
|
|
96
|
-
...
|
|
96
|
+
...dt(t, e)
|
|
97
97
|
};
|
|
98
98
|
}
|
|
99
99
|
}), n;
|
|
100
100
|
}
|
|
101
|
-
function
|
|
101
|
+
function pt(t, s, n) {
|
|
102
102
|
if (g(s)) return t;
|
|
103
103
|
const e = E(t), r = d(n, "i18nProps", []);
|
|
104
104
|
return x(w(e), (o) => {
|
|
105
105
|
r.includes(o) && !g(s) && (e[o] = d(e, `${o}-${s}`, e[o]));
|
|
106
106
|
}), e;
|
|
107
107
|
}
|
|
108
|
-
const
|
|
108
|
+
const mt = $((t) => {
|
|
109
109
|
const s = F(t), n = d(s, "schema.properties", {});
|
|
110
110
|
return Object.fromEntries(Object.entries(n).filter(([, e]) => d(e, "runtime", !1)));
|
|
111
|
-
}),
|
|
111
|
+
}), ft = (t, s, n) => g(n) ? {} : Object.entries(n).reduce((e, [r, o]) => {
|
|
112
112
|
const c = [];
|
|
113
113
|
let a = _(t, { _id: s });
|
|
114
114
|
for (; a; )
|
|
115
115
|
c.push(a), a = _(t, { _id: a._parent });
|
|
116
116
|
const l = _(c, { _type: o.block });
|
|
117
117
|
return l && (e[r] = d(l, d(o, "prop"), null)), e;
|
|
118
|
-
}, {}),
|
|
119
|
-
function
|
|
118
|
+
}, {}), gt = () => /* @__PURE__ */ p("span", { children: "Loading..." });
|
|
119
|
+
function ht({
|
|
120
120
|
blocks: t,
|
|
121
121
|
parent: s,
|
|
122
122
|
classPrefix: n = "",
|
|
@@ -128,11 +128,11 @@ function ft({
|
|
|
128
128
|
dataProviderMetadataCallback: l = () => {
|
|
129
129
|
}
|
|
130
130
|
}) {
|
|
131
|
-
const m = t, I = (i) =>
|
|
132
|
-
return (
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
|
|
131
|
+
const m = t, I = (i) => ut(i, n), J = s ? h(t, { _parent: s }) : h(t, (i) => g(i._parent));
|
|
132
|
+
return D(J, "_id").map((i, M) => {
|
|
133
|
+
const B = {}, U = h(m, { _parent: i._id });
|
|
134
|
+
B.children = U.length > 0 ? /* @__PURE__ */ p(
|
|
135
|
+
ht,
|
|
136
136
|
{
|
|
137
137
|
externalData: e,
|
|
138
138
|
classPrefix: n,
|
|
@@ -146,18 +146,18 @@ function ft({
|
|
|
146
146
|
const u = F(i._type);
|
|
147
147
|
if (u !== null) {
|
|
148
148
|
let f = i;
|
|
149
|
-
const
|
|
149
|
+
const P = u.component;
|
|
150
150
|
f = { ...u.defaults, ...i }, r && (f = r(f));
|
|
151
|
-
const
|
|
151
|
+
const V = o === c ? "" : o, K = ft(m, i._id, mt(i._type)), v = A(pt(i, V, u), e), T = S(
|
|
152
152
|
{
|
|
153
153
|
blockProps: {},
|
|
154
154
|
inBuilder: !1,
|
|
155
155
|
...f,
|
|
156
|
-
index:
|
|
156
|
+
index: M,
|
|
157
157
|
...v,
|
|
158
158
|
...I(v),
|
|
159
|
-
...
|
|
160
|
-
...
|
|
159
|
+
...B,
|
|
160
|
+
...K,
|
|
161
161
|
metadata: a,
|
|
162
162
|
lang: o || c,
|
|
163
163
|
key: i._id
|
|
@@ -165,34 +165,34 @@ function ft({
|
|
|
165
165
|
["_parent"]
|
|
166
166
|
);
|
|
167
167
|
if (O(u, "dataProvider")) {
|
|
168
|
-
const
|
|
169
|
-
return /* @__PURE__ */ p(C, { fallback:
|
|
170
|
-
|
|
168
|
+
const W = d(u, "suspenseFallback", gt);
|
|
169
|
+
return /* @__PURE__ */ p(C, { fallback: nt(W), children: /* @__PURE__ */ p(
|
|
170
|
+
ct,
|
|
171
171
|
{
|
|
172
172
|
dataProviderMetadataCallback: l,
|
|
173
173
|
lang: o || c,
|
|
174
174
|
metadata: a,
|
|
175
175
|
dataProvider: u.dataProvider,
|
|
176
176
|
block: i,
|
|
177
|
-
component:
|
|
177
|
+
component: P,
|
|
178
178
|
props: T
|
|
179
179
|
},
|
|
180
180
|
i._id
|
|
181
181
|
) }, i._id);
|
|
182
182
|
}
|
|
183
|
-
return /* @__PURE__ */ p(C, { children: N.createElement(
|
|
183
|
+
return /* @__PURE__ */ p(C, { children: N.createElement(P, T) }, i._id);
|
|
184
184
|
}
|
|
185
|
-
return /* @__PURE__ */
|
|
185
|
+
return /* @__PURE__ */ et("noscript", { children: [
|
|
186
186
|
i._type,
|
|
187
187
|
" not found"
|
|
188
188
|
] }, i._id);
|
|
189
189
|
});
|
|
190
190
|
}
|
|
191
191
|
export {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
192
|
+
ht as RenderChaiBlocks,
|
|
193
|
+
Rt as convertToBlocks,
|
|
194
|
+
At as getChaiThemeCssVariables,
|
|
195
|
+
bt as getStylesForBlocks,
|
|
196
|
+
It as getThemeFontsCSSImport,
|
|
197
|
+
Jt as getThemeFontsLinkMarkup
|
|
198
198
|
};
|
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.0.
|
|
8
|
+
"version": "2.0.6",
|
|
9
9
|
"type": "module",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
}
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@chaibuilder/runtime": "2.0.
|
|
56
|
+
"@chaibuilder/runtime": "2.0.1",
|
|
57
57
|
"@types/react": "*",
|
|
58
58
|
"@types/react-dom": "*",
|
|
59
59
|
"jotai": "2.12.1",
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
}
|
|
70
70
|
},
|
|
71
71
|
"dependencies": {
|
|
72
|
-
"@chaibuilder/runtime": "2.0.
|
|
72
|
+
"@chaibuilder/runtime": "2.0.1",
|
|
73
73
|
"@floating-ui/dom": "1.6.13",
|
|
74
74
|
"@floating-ui/react-dom": "2.1.2",
|
|
75
75
|
"@mhsdesign/jit-browser-tailwindcss": "0.4.2",
|