@chaibuilder/sdk 2.0.0 → 2.0.2
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.d.ts +8 -0
- package/dist/core.js +902 -784
- package/dist/render.cjs +2 -2
- package/dist/render.d.ts +1 -3
- package/dist/render.js +107 -112
- 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"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("./ChaiThemeFn-DQu-2Eh9.cjs"),s=require("lodash-es"),f=require("./getSplitClasses-DodqA_KW.cjs"),$=require("@mhsdesign/jit-browser-tailwindcss"),b=require("@tailwindcss/aspect-ratio"),F=require("@tailwindcss/container-queries"),k=require("@tailwindcss/forms"),M=require("@tailwindcss/typography"),B=require("./plugin-2xcljWGM.cjs"),g=require("react/jsx-runtime"),T=require("@chaibuilder/runtime"),p=require("react"),N=require("tailwind-merge"),Y=(e,r="")=>{const{classes:n}=f.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(" ")},I=e=>{if(!e)return[];try{return JSON.parse(A(e)).filter(n=>!n._type.startsWith("@chai"))}catch{return[{_type:"Paragraph",_id:"error",content:"Invalid JSON. Please check the JSON string."}]}};function A(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 J(e,r,n=[],t="",i){return await $.createTailwindcss({tailwindConfig:{darkMode:"class",safelist:n,theme:{extend:B.getChaiBuilderTheme(e)},plugins:[k,M,b,F,B.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 K=(e,r,n)=>{const t=JSON.stringify(e).replace(/#styles:([^"]*)/g,(i,o)=>`#styles:${o.replace(/,/g," ")}`.replace(/#styles:/g,""));return J(r,[t],[],"",n)},L=async(e,r=S.defaultThemeOptions,n=!1)=>await K(e,r,n);async function V(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 U=s.memoize((e,r)=>{const{baseClasses:n,classes:t}=f.getSplitChaiClasses(e),i=N.twMerge(n,t);return r===""?i.replace(f.STYLES_KEY,"").trim():Y(i,r).replace(f.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 o=/\{\{(.*?)\}\}/g,l=i.match(o);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 z(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 D(e,r){const n={};return Object.keys(e).forEach(t=>{if(s.isString(e[t])&&e[t].startsWith(f.STYLES_KEY)){const i=U(e[t],r);n[t]={className:i,...z(e,t)}}}),n}function W(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 Q=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)))}),G=(e,r,n)=>s.isEmpty(n)?{}:Object.entries(n).reduce((t,[i,o])=>{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:o.block});return u&&(t[i]=s.get(u,s.get(o,"prop"),null)),t},{}),H=()=>g.jsx("span",{children:"Loading..."});function E({blocks:e,parent:r,classPrefix:n="",externalData:t={},blockModifierCallback:i=null,lang:o="",fallbackLang:l="",metadata:a={},dataProviderMetadataCallback:u=()=>{}}){const h=e,P=c=>D(c,n);return(r?s.filter(e,{_parent:r}):s.filter(e,c=>s.isEmpty(c._parent))).map((c,v)=>{const C={},q=s.filter(h,{_parent:c._id});C.children=q.length>0?g.jsx(E,{externalData:t,classPrefix:n,parent:c._id,blocks:h,lang:o||l,metadata:a},c._id):null;const d=T.getRegisteredChaiBlock(c._type);if(d!==null){let m=c;const y=d.component;m={...d.defaults,...c},i&&(m=i(m));const x=o===l?"":o,O=G(h,c._id,Q(c._type)),_=j(W(c,x,d),t),w=s.omit({blockProps:{},inBuilder:!1,...m,index:v,..._,...P(_),...C,...O,metadata:a,lang:o||l},["_parent"]);if(s.has(d,"dataProvider")){const R=s.get(d,"suspenseFallback",H);return g.jsx(p.Suspense,{fallback:p.createElement(R),children:g.jsx(V,{dataProviderMetadataCallback:u,lang:o||l,metadata:a,dataProvider:d.dataProvider,block:c,component:y,props:w})},c._id)}return g.jsx(p.Suspense,{children:p.createElement(y,w)},c._id)}return g.jsxs("noscript",{children:[c._type," not found"]},c._id)})}exports.getChaiThemeCssVariables=S.getChaiThemeCssVariables;exports.getThemeFontsCSSImport=S.getThemeFontsCSSImport;exports.getThemeFontsLinkMarkup=S.getThemeFontsLinkMarkup;exports.RenderChaiBlocks=E;exports.convertToBlocks=I;exports.getStylesForBlocks=L;
|
package/dist/render.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { JSX as JSX_2 } from 'react/jsx-runtime';
|
|
2
|
-
|
|
3
1
|
declare type BorderRadiusValue = false | string;
|
|
4
2
|
|
|
5
3
|
declare type ChaiBlock<T = Record<string, any>> = {
|
|
@@ -43,7 +41,7 @@ export declare const getThemeFontsLinkMarkup: (chaiTheme: Pick<Partial<ChaiBuild
|
|
|
43
41
|
|
|
44
42
|
declare type HSLColor = string;
|
|
45
43
|
|
|
46
|
-
export declare function RenderChaiBlocks({ blocks, parent, classPrefix, externalData, blockModifierCallback, lang, fallbackLang, metadata, dataProviderMetadataCallback, }: RenderChaiBlocksProps):
|
|
44
|
+
export declare function RenderChaiBlocks({ blocks, parent, classPrefix, externalData, blockModifierCallback, lang, fallbackLang, metadata, dataProviderMetadataCallback, }: RenderChaiBlocksProps): any;
|
|
47
45
|
|
|
48
46
|
declare type RenderChaiBlocksProps = {
|
|
49
47
|
blocks: ChaiBlock[];
|
package/dist/render.js
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
1
|
import { d as W } from "./ChaiThemeFn-Cort9tch.js";
|
|
2
|
-
import { a as
|
|
3
|
-
import { last as Y, flattenDeep as z, has as O, omit as
|
|
4
|
-
import { g as
|
|
2
|
+
import { a as Ft, b as Nt, c as At } from "./ChaiThemeFn-Cort9tch.js";
|
|
3
|
+
import { last as Y, flattenDeep as z, 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 D, find as _, includes as j } from "lodash-es";
|
|
4
|
+
import { g as R, S as C } from "./getSplitClasses-DphwgQiE.js";
|
|
5
5
|
import { createTailwindcss as L } from "@mhsdesign/jit-browser-tailwindcss";
|
|
6
6
|
import Q from "@tailwindcss/aspect-ratio";
|
|
7
7
|
import q from "@tailwindcss/container-queries";
|
|
8
8
|
import G from "@tailwindcss/forms";
|
|
9
9
|
import H from "@tailwindcss/typography";
|
|
10
10
|
import { g as X, c as Z } from "./plugin-kUMxtQR5.js";
|
|
11
|
-
import { jsx as p,
|
|
12
|
-
import { getRegisteredChaiBlock as
|
|
13
|
-
import
|
|
14
|
-
import { twMerge as
|
|
15
|
-
const
|
|
16
|
-
const { classes: n } =
|
|
17
|
-
if (
|
|
18
|
-
if (
|
|
19
|
-
const l =
|
|
11
|
+
import { jsx as p, jsxs as k } from "react/jsx-runtime";
|
|
12
|
+
import { getRegisteredChaiBlock as F } from "@chaibuilder/runtime";
|
|
13
|
+
import N, { Suspense as w, createElement as tt } from "react";
|
|
14
|
+
import { twMerge as et } from "tailwind-merge";
|
|
15
|
+
const nt = (t, 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
20
|
return l[l.length - 1] = s + Y(l), l.join(":");
|
|
21
21
|
}
|
|
22
|
-
return `${s}${
|
|
22
|
+
return `${s}${a}`;
|
|
23
23
|
}).join(" "));
|
|
24
24
|
return z(e).join(" ");
|
|
25
25
|
}, Et = (t) => {
|
|
26
26
|
if (!t) return [];
|
|
27
27
|
try {
|
|
28
|
-
return JSON.parse(
|
|
28
|
+
return JSON.parse(st(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 st(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
|
|
40
|
+
async function rt(t, s, n = [], e = "", r) {
|
|
41
41
|
return await L({
|
|
42
42
|
tailwindConfig: {
|
|
43
43
|
darkMode: "class",
|
|
@@ -54,69 +54,69 @@ async function ot(t, s, n = [], e = "", r) {
|
|
|
54
54
|
s
|
|
55
55
|
);
|
|
56
56
|
}
|
|
57
|
-
const
|
|
57
|
+
const it = (t, s, n) => {
|
|
58
58
|
const e = JSON.stringify(t).replace(/#styles:([^"]*)/g, (r, i) => `#styles:${i.replace(/,/g, " ")}`.replace(/#styles:/g, ""));
|
|
59
|
-
return
|
|
60
|
-
}, xt = async (t, s = W, n = !1) => await
|
|
61
|
-
async function
|
|
59
|
+
return rt(s, [e], [], "", n);
|
|
60
|
+
}, xt = async (t, s = W, n = !1) => await it(t, s, n);
|
|
61
|
+
async function ot(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
|
-
const
|
|
69
|
-
const { baseClasses: n, classes: e } =
|
|
70
|
-
return s === "" ? r.replace(C, "").trim() :
|
|
68
|
+
const at = $((t, s) => {
|
|
69
|
+
const { baseClasses: n, classes: e } = R(t), r = et(n, e);
|
|
70
|
+
return s === "" ? r.replace(C, "").trim() : nt(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
|
D(n[e]) && (n[e] = A(n[e], s));
|
|
83
83
|
}), n;
|
|
84
84
|
};
|
|
85
|
-
function
|
|
86
|
-
const n = d(t, `${s}_attrs`, {}), e =
|
|
85
|
+
function ct(t, s) {
|
|
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
|
-
function
|
|
89
|
+
function lt(t, s) {
|
|
90
90
|
const n = {};
|
|
91
91
|
return Object.keys(t).forEach((e) => {
|
|
92
|
-
if (
|
|
93
|
-
const r =
|
|
92
|
+
if (b(t[e]) && t[e].startsWith(C)) {
|
|
93
|
+
const r = at(t[e], s);
|
|
94
94
|
n[e] = {
|
|
95
95
|
className: r,
|
|
96
|
-
...
|
|
96
|
+
...ct(t, e)
|
|
97
97
|
};
|
|
98
98
|
}
|
|
99
99
|
}), n;
|
|
100
100
|
}
|
|
101
|
-
function
|
|
101
|
+
function dt(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
|
-
const
|
|
109
|
-
const s =
|
|
108
|
+
const ut = $((t) => {
|
|
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
|
+
}), pt = (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
|
-
}, {}),
|
|
119
|
-
function
|
|
118
|
+
}, {}), mt = () => /* @__PURE__ */ p("span", { children: "Loading..." });
|
|
119
|
+
function ft({
|
|
120
120
|
blocks: t,
|
|
121
121
|
parent: s,
|
|
122
122
|
classPrefix: n = "",
|
|
@@ -124,78 +124,73 @@ 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
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
131
|
+
const m = t, I = (o) => lt(o, n);
|
|
132
|
+
return (s ? h(t, { _parent: s }) : h(t, (o) => g(o._parent))).map((o, J) => {
|
|
133
|
+
const P = {}, M = h(m, { _parent: o._id });
|
|
134
|
+
P.children = M.length > 0 ? /* @__PURE__ */ p(
|
|
135
|
+
ft,
|
|
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 U = i === c ? "" : i, V = pt(m, o._id, ut(o._type)), v = A(dt(o, U, u), e), T = S(
|
|
137
152
|
{
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
153
|
+
blockProps: {},
|
|
154
|
+
inBuilder: !1,
|
|
155
|
+
...f,
|
|
156
|
+
index: J,
|
|
157
|
+
...v,
|
|
158
|
+
...I(v),
|
|
159
|
+
...P,
|
|
160
|
+
...V,
|
|
161
|
+
metadata: a,
|
|
162
|
+
lang: i || c
|
|
163
|
+
},
|
|
164
|
+
["_parent"]
|
|
165
|
+
);
|
|
166
|
+
if (O(u, "dataProvider")) {
|
|
167
|
+
const K = d(u, "suspenseFallback", mt);
|
|
168
|
+
return /* @__PURE__ */ p(w, { fallback: tt(K), children: /* @__PURE__ */ p(
|
|
169
|
+
ot,
|
|
152
170
|
{
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
lang: i || c
|
|
163
|
-
},
|
|
164
|
-
["_parent"]
|
|
165
|
-
);
|
|
166
|
-
if (O(u, "dataProvider")) {
|
|
167
|
-
const K = d(
|
|
168
|
-
u,
|
|
169
|
-
"suspenseFallback",
|
|
170
|
-
gt
|
|
171
|
-
);
|
|
172
|
-
return /* @__PURE__ */ p(w, { fallback: nt(K), children: /* @__PURE__ */ p(
|
|
173
|
-
ct,
|
|
174
|
-
{
|
|
175
|
-
dataProviderMetadataCallback: l,
|
|
176
|
-
lang: i || c,
|
|
177
|
-
metadata: o,
|
|
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) });
|
|
171
|
+
dataProviderMetadataCallback: l,
|
|
172
|
+
lang: i || c,
|
|
173
|
+
metadata: a,
|
|
174
|
+
dataProvider: u.dataProvider,
|
|
175
|
+
block: o,
|
|
176
|
+
component: B,
|
|
177
|
+
props: T
|
|
178
|
+
}
|
|
179
|
+
) }, o._id);
|
|
186
180
|
}
|
|
187
|
-
return /* @__PURE__ */
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
181
|
+
return /* @__PURE__ */ p(w, { children: N.createElement(B, T) }, o._id);
|
|
182
|
+
}
|
|
183
|
+
return /* @__PURE__ */ k("noscript", { children: [
|
|
184
|
+
o._type,
|
|
185
|
+
" not found"
|
|
186
|
+
] }, o._id);
|
|
187
|
+
});
|
|
193
188
|
}
|
|
194
189
|
export {
|
|
195
|
-
|
|
190
|
+
ft as RenderChaiBlocks,
|
|
196
191
|
Et as convertToBlocks,
|
|
197
|
-
|
|
192
|
+
Ft as getChaiThemeCssVariables,
|
|
198
193
|
xt as getStylesForBlocks,
|
|
199
|
-
|
|
200
|
-
|
|
194
|
+
Nt as getThemeFontsCSSImport,
|
|
195
|
+
At as getThemeFontsLinkMarkup
|
|
201
196
|
};
|