@chaibuilder/sdk 2.0.0 → 2.0.1
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 +5 -5
- package/dist/core.js +649 -585
- package/dist/render.cjs +2 -2
- package/dist/render.js +102 -103
- package/package.json +1 -1
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"),m=require("./getSplitClasses-DodqA_KW.cjs")
|
|
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"),$=require("@mhsdesign/jit-browser-tailwindcss"),b=require("@tailwindcss/aspect-ratio"),M=require("@tailwindcss/container-queries"),k=require("@tailwindcss/forms"),N=require("@tailwindcss/typography"),T=require("./plugin-2xcljWGM.cjs"),d=require("react/jsx-runtime"),j=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(c=>{if(c==="")return"";if(c.includes(":")){const u=c.split(":");return u[u.length-1]=r+s.last(u),u.join(":")}return`${r}${c}`}).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 $.createTailwindcss({tailwindConfig:{darkMode:"class",safelist:n,theme:{extend:T.getChaiBuilderTheme(e)},plugins:[k,N,b,M,T.chaiBuilderPlugin],corePlugins:{preflight:i},...t?{prefix:`${t}`}:{}}}).generateStylesFromContent(` ${i?"@tailwind base;":""}
|
|
2
2
|
@tailwind components;
|
|
3
|
-
@tailwind utilities;`,r)}const L=(e,r,n)=>{const t=JSON.stringify(e).replace(/#styles:([^"]*)/g,(i,o)=>`#styles:${o.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),d.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():
|
|
3
|
+
@tailwind utilities;`,r)}const L=(e,r,n)=>{const t=JSON.stringify(e).replace(/#styles:([^"]*)/g,(i,o)=>`#styles:${o.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),d.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()}),B=(e,r)=>{const n=s.cloneDeep(e);return s.forEach(s.keys(n),t=>{if(s.isString(n[t])){let i=n[t];const o=/\{\{(.*?)\}\}/g,l=i.match(o);l&&l.forEach(c=>{const u=c.slice(2,-2),h=s.get(r,u,c);i=i.replace(c,h)}),n[t]=i}s.isObject(n[t])&&(n[t]=B(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),o=>{i.includes(o)&&!s.isEmpty(r)&&(t[o]=s.get(t,`${o}-${r}`,t[o]))}),t}const G=s.memoize(e=>{const r=j.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,o])=>{const l=[];let c=s.find(e,{_id:r});for(;c;)l.push(c),c=s.find(e,{_id:c._parent});const u=s.find(l,{_type:o.block});return u&&(t[i]=s.get(u,s.get(o,"prop"),null)),t},{}),X=()=>d.jsx("span",{children:"Loading..."});function E({blocks:e,parent:r,classPrefix:n="",externalData:t={},blockModifierCallback:i=null,lang:o="",fallbackLang:l="",metadata:c={},dataProviderMetadataCallback:u=()=>{}}){const h=e,P=a=>W(a,n),v=r?s.filter(e,{_parent:r}):s.filter(e,a=>s.isEmpty(a._parent));return d.jsx(d.Fragment,{children:v.map((a,x)=>{const C={},q=s.filter(h,{_parent:a._id});C.children=q.length>0?d.jsx(E,{externalData:t,classPrefix:n,parent:a._id,blocks:h,lang:o||l,metadata:c},a._id):null;const g=j.getRegisteredChaiBlock(a._type);if(g!==null){let f=a;const y=g.component;f={...g.defaults,...a},i&&(f=i(f));const O=o===l?"":o,F=H(h,a._id,G(a._type)),_=B(Q(a,O,g),t),w=s.omit({blockProps:{},inBuilder:!1,...f,index:x,..._,...P(_),...C,...F,metadata:c,lang:o||l},["_parent"]);if(s.has(g,"dataProvider")){const R=s.get(g,"suspenseFallback",X);return d.jsx(p.Suspense,{fallback:p.createElement(R),children:d.jsx(U,{dataProviderMetadataCallback:u,lang:o||l,metadata:c,dataProvider:g.dataProvider,block:a,component:y,props:w})},a._id)}return d.jsx(p.Suspense,{children:p.createElement(y,w)},a._id)}return d.jsxs("noscript",{children:[a._type," not found"]},a._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,28 +1,28 @@
|
|
|
1
|
-
import { d as
|
|
1
|
+
import { d as Y } from "./ChaiThemeFn-Cort9tch.js";
|
|
2
2
|
import { a as Nt, b as At, c as It } from "./ChaiThemeFn-Cort9tch.js";
|
|
3
|
-
import { last as
|
|
4
|
-
import { g as
|
|
5
|
-
import { createTailwindcss as
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import { g as
|
|
3
|
+
import { last as z, flattenDeep as D, has as O, omit as S, memoize as $, get as d, filter as h, isEmpty as g, cloneDeep as E, forEach as x, keys as y, isString as b, isObject as L, find as _, includes as j } from "lodash-es";
|
|
4
|
+
import { g as R, S as C } from "./getSplitClasses-DphwgQiE.js";
|
|
5
|
+
import { createTailwindcss as Q } from "@mhsdesign/jit-browser-tailwindcss";
|
|
6
|
+
import q from "@tailwindcss/aspect-ratio";
|
|
7
|
+
import G from "@tailwindcss/container-queries";
|
|
8
|
+
import H from "@tailwindcss/forms";
|
|
9
|
+
import X from "@tailwindcss/typography";
|
|
10
|
+
import { g as Z, c as k } from "./plugin-kUMxtQR5.js";
|
|
11
11
|
import { jsx as p, Fragment as tt, jsxs as et } from "react/jsx-runtime";
|
|
12
|
-
import { getRegisteredChaiBlock as
|
|
13
|
-
import
|
|
12
|
+
import { getRegisteredChaiBlock as F } from "@chaibuilder/runtime";
|
|
13
|
+
import N, { Suspense as w, createElement as nt } from "react";
|
|
14
14
|
import { twMerge as st } from "tailwind-merge";
|
|
15
15
|
const rt = (t, s = "") => {
|
|
16
|
-
const { classes: n } =
|
|
17
|
-
if (
|
|
18
|
-
if (
|
|
19
|
-
const l =
|
|
20
|
-
return l[l.length - 1] = s +
|
|
16
|
+
const { classes: n } = R(t), e = n.split(" ").map((r) => r.split(" ").map((a) => {
|
|
17
|
+
if (a === "") return "";
|
|
18
|
+
if (a.includes(":")) {
|
|
19
|
+
const l = a.split(":");
|
|
20
|
+
return l[l.length - 1] = s + z(l), l.join(":");
|
|
21
21
|
}
|
|
22
|
-
return `${s}${
|
|
22
|
+
return `${s}${a}`;
|
|
23
23
|
}).join(" "));
|
|
24
|
-
return
|
|
25
|
-
},
|
|
24
|
+
return D(e).join(" ");
|
|
25
|
+
}, xt = (t) => {
|
|
26
26
|
if (!t) return [];
|
|
27
27
|
try {
|
|
28
28
|
return JSON.parse(it(t)).filter((n) => !n._type.startsWith("@chai"));
|
|
@@ -38,12 +38,12 @@ function it(t) {
|
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
40
|
async function ot(t, s, n = [], e = "", r) {
|
|
41
|
-
return await
|
|
41
|
+
return await Q({
|
|
42
42
|
tailwindConfig: {
|
|
43
43
|
darkMode: "class",
|
|
44
44
|
safelist: n,
|
|
45
|
-
theme: { extend:
|
|
46
|
-
plugins: [
|
|
45
|
+
theme: { extend: Z(t) },
|
|
46
|
+
plugins: [H, X, q, G, k],
|
|
47
47
|
corePlugins: { preflight: r },
|
|
48
48
|
...e ? { prefix: `${e}` } : {}
|
|
49
49
|
}
|
|
@@ -57,39 +57,39 @@ async function ot(t, s, n = [], e = "", r) {
|
|
|
57
57
|
const at = (t, s, n) => {
|
|
58
58
|
const e = JSON.stringify(t).replace(/#styles:([^"]*)/g, (r, i) => `#styles:${i.replace(/,/g, " ")}`.replace(/#styles:/g, ""));
|
|
59
59
|
return ot(s, [e], [], "", n);
|
|
60
|
-
},
|
|
60
|
+
}, bt = async (t, s = Y, n = !1) => await at(t, s, n);
|
|
61
61
|
async function ct(t) {
|
|
62
62
|
const s = await (t == null ? void 0 : t.dataProvider(t.block, t.lang, t.metadata));
|
|
63
|
-
return O(s, "$metadata") && t.dataProviderMetadataCallback(t.block, s.$metadata), /* @__PURE__ */ p(w, { children:
|
|
64
|
-
...
|
|
65
|
-
...
|
|
63
|
+
return O(s, "$metadata") && t.dataProviderMetadataCallback(t.block, s.$metadata), /* @__PURE__ */ p(w, { children: N.createElement(t.component, {
|
|
64
|
+
...S(t.props, ["dataProvider", "dataProviderMetadataCallback"]),
|
|
65
|
+
...S(s, "$metadata")
|
|
66
66
|
}) });
|
|
67
67
|
}
|
|
68
68
|
const lt = $((t, s) => {
|
|
69
|
-
const { baseClasses: n, classes: e } =
|
|
69
|
+
const { baseClasses: n, classes: e } = R(t), r = st(n, e);
|
|
70
70
|
return s === "" ? r.replace(C, "").trim() : rt(r, s).replace(C, "").trim();
|
|
71
71
|
}), A = (t, s) => {
|
|
72
72
|
const n = E(t);
|
|
73
|
-
return x(
|
|
74
|
-
if (
|
|
73
|
+
return x(y(n), (e) => {
|
|
74
|
+
if (b(n[e])) {
|
|
75
75
|
let r = n[e];
|
|
76
76
|
const i = /\{\{(.*?)\}\}/g, c = r.match(i);
|
|
77
|
-
c && c.forEach((
|
|
78
|
-
const l =
|
|
79
|
-
r = r.replace(
|
|
77
|
+
c && c.forEach((a) => {
|
|
78
|
+
const l = a.slice(2, -2), m = d(s, l, a);
|
|
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
85
|
function dt(t, s) {
|
|
86
|
-
const n = d(t, `${s}_attrs`, {}), e =
|
|
86
|
+
const n = d(t, `${s}_attrs`, {}), e = y(n).join(" ");
|
|
87
87
|
return j(e, "x-show") && !j(e, "x-transition") && (n["x-transition"] = ""), n;
|
|
88
88
|
}
|
|
89
89
|
function ut(t, s) {
|
|
90
90
|
const n = {};
|
|
91
91
|
return Object.keys(t).forEach((e) => {
|
|
92
|
-
if (
|
|
92
|
+
if (b(t[e]) && t[e].startsWith(C)) {
|
|
93
93
|
const r = lt(t[e], s);
|
|
94
94
|
n[e] = {
|
|
95
95
|
className: r,
|
|
@@ -101,19 +101,19 @@ function ut(t, s) {
|
|
|
101
101
|
function pt(t, s, n) {
|
|
102
102
|
if (g(s)) return t;
|
|
103
103
|
const e = E(t), r = d(n, "i18nProps", []);
|
|
104
|
-
return x(
|
|
104
|
+
return x(y(e), (i) => {
|
|
105
105
|
r.includes(i) && !g(s) && (e[i] = d(e, `${i}-${s}`, e[i]));
|
|
106
106
|
}), e;
|
|
107
107
|
}
|
|
108
108
|
const mt = $((t) => {
|
|
109
|
-
const s =
|
|
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, i]) => {
|
|
112
112
|
const c = [];
|
|
113
|
-
let
|
|
114
|
-
for (;
|
|
115
|
-
c.push(
|
|
116
|
-
const l =
|
|
113
|
+
let a = _(t, { _id: s });
|
|
114
|
+
for (; a; )
|
|
115
|
+
c.push(a), a = _(t, { _id: a._parent });
|
|
116
|
+
const l = _(c, { _type: i.block });
|
|
117
117
|
return l && (e[r] = d(l, d(i, "prop"), null)), e;
|
|
118
118
|
}, {}), gt = () => /* @__PURE__ */ p("span", { children: "Loading..." });
|
|
119
119
|
function ht({
|
|
@@ -124,78 +124,77 @@ function ht({
|
|
|
124
124
|
blockModifierCallback: r = null,
|
|
125
125
|
lang: i = "",
|
|
126
126
|
fallbackLang: c = "",
|
|
127
|
-
metadata:
|
|
127
|
+
metadata: a = {},
|
|
128
128
|
dataProviderMetadataCallback: l = () => {
|
|
129
129
|
}
|
|
130
130
|
}) {
|
|
131
|
-
const m = t, I = (
|
|
132
|
-
return /* @__PURE__ */ p(tt, { children:
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
131
|
+
const m = t, I = (o) => ut(o, n), J = s ? h(t, { _parent: s }) : h(t, (o) => g(o._parent));
|
|
132
|
+
return /* @__PURE__ */ p(tt, { children: J.map((o, M) => {
|
|
133
|
+
const P = {}, U = h(m, { _parent: o._id });
|
|
134
|
+
P.children = U.length > 0 ? /* @__PURE__ */ p(
|
|
135
|
+
ht,
|
|
136
|
+
{
|
|
137
|
+
externalData: e,
|
|
138
|
+
classPrefix: n,
|
|
139
|
+
parent: o._id,
|
|
140
|
+
blocks: m,
|
|
141
|
+
lang: i || c,
|
|
142
|
+
metadata: a
|
|
143
|
+
},
|
|
144
|
+
o._id
|
|
145
|
+
) : null;
|
|
146
|
+
const u = F(o._type);
|
|
147
|
+
if (u !== null) {
|
|
148
|
+
let f = o;
|
|
149
|
+
const B = u.component;
|
|
150
|
+
f = { ...u.defaults, ...o }, r && (f = r(f));
|
|
151
|
+
const V = i === c ? "" : i, K = ft(m, o._id, mt(o._type)), v = A(pt(o, V, u), e), T = S(
|
|
137
152
|
{
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
index: M,
|
|
157
|
-
...v,
|
|
158
|
-
...I(v),
|
|
159
|
-
...B,
|
|
160
|
-
...k,
|
|
161
|
-
metadata: o,
|
|
162
|
-
lang: i || c
|
|
163
|
-
},
|
|
164
|
-
["_parent"]
|
|
153
|
+
blockProps: {},
|
|
154
|
+
inBuilder: !1,
|
|
155
|
+
...f,
|
|
156
|
+
index: M,
|
|
157
|
+
...v,
|
|
158
|
+
...I(v),
|
|
159
|
+
...P,
|
|
160
|
+
...K,
|
|
161
|
+
metadata: a,
|
|
162
|
+
lang: i || c
|
|
163
|
+
},
|
|
164
|
+
["_parent"]
|
|
165
|
+
);
|
|
166
|
+
if (O(u, "dataProvider")) {
|
|
167
|
+
const W = d(
|
|
168
|
+
u,
|
|
169
|
+
"suspenseFallback",
|
|
170
|
+
gt
|
|
165
171
|
);
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
dataProvider: u.dataProvider,
|
|
179
|
-
block: a,
|
|
180
|
-
component: b,
|
|
181
|
-
props: T
|
|
182
|
-
}
|
|
183
|
-
) });
|
|
184
|
-
}
|
|
185
|
-
return /* @__PURE__ */ p(w, { children: y.createElement(b, T) });
|
|
172
|
+
return /* @__PURE__ */ p(w, { fallback: nt(W), children: /* @__PURE__ */ p(
|
|
173
|
+
ct,
|
|
174
|
+
{
|
|
175
|
+
dataProviderMetadataCallback: l,
|
|
176
|
+
lang: i || c,
|
|
177
|
+
metadata: a,
|
|
178
|
+
dataProvider: u.dataProvider,
|
|
179
|
+
block: o,
|
|
180
|
+
component: B,
|
|
181
|
+
props: T
|
|
182
|
+
}
|
|
183
|
+
) }, o._id);
|
|
186
184
|
}
|
|
187
|
-
return /* @__PURE__ */
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
185
|
+
return /* @__PURE__ */ p(w, { children: N.createElement(B, T) }, o._id);
|
|
186
|
+
}
|
|
187
|
+
return /* @__PURE__ */ et("noscript", { children: [
|
|
188
|
+
o._type,
|
|
189
|
+
" not found"
|
|
190
|
+
] }, o._id);
|
|
191
|
+
}) });
|
|
193
192
|
}
|
|
194
193
|
export {
|
|
195
194
|
ht as RenderChaiBlocks,
|
|
196
|
-
|
|
195
|
+
xt as convertToBlocks,
|
|
197
196
|
Nt as getChaiThemeCssVariables,
|
|
198
|
-
|
|
197
|
+
bt as getStylesForBlocks,
|
|
199
198
|
At as getThemeFontsCSSImport,
|
|
200
199
|
It as getThemeFontsLinkMarkup
|
|
201
200
|
};
|