@chaibuilder/sdk 2.0.2 → 2.0.3
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 +22 -3
- package/dist/core.js +1134 -1133
- package/dist/render.cjs +2 -2
- package/dist/render.js +40 -38
- 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"),f=require("./getSplitClasses-DodqA_KW.cjs"),$=require("@mhsdesign/jit-browser-tailwindcss"),
|
|
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"),F=require("@tailwindcss/aspect-ratio"),b=require("@tailwindcss/container-queries"),M=require("@tailwindcss/forms"),k=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(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(" ")},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:[M,k,F,b,B.chaiBuilderPlugin],corePlugins:{preflight:i},...t?{prefix:`${t}`}:{}}}).generateStylesFromContent(` ${i?"@tailwind base;":""}
|
|
2
2
|
@tailwind components;
|
|
3
|
-
@tailwind utilities;`,r)}const K=(e,r,n)=>{const t=JSON.stringify(e).replace(/#styles:([^"]*)/g,(i,
|
|
3
|
+
@tailwind utilities;`,r)}const K=(e,r,n)=>{const t=JSON.stringify(e).replace(/#styles:([^"]*)/g,(i,a)=>`#styles:${a.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 a=/\{\{(.*?)\}\}/g,l=i.match(a);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]=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),a=>{i.includes(a)&&!s.isEmpty(r)&&(t[a]=s.get(t,`${a}-${r}`,t[a]))}),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,a])=>{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:a.block});return u&&(t[i]=s.get(u,s.get(a,"prop"),null)),t},{}),H=()=>g.jsx("span",{children:"Loading..."});function E({blocks:e,parent:r,classPrefix:n="",externalData:t={},blockModifierCallback:i=null,lang:a="",fallbackLang:l="",metadata:c={},dataProviderMetadataCallback:u=()=>{}}){const h=e,P=o=>D(o,n);return(r?s.filter(e,{_parent:r}):s.filter(e,o=>s.isEmpty(o._parent))).map((o,v)=>{const C={},q=s.filter(h,{_parent:o._id});C.children=q.length>0?g.jsx(E,{externalData:t,classPrefix:n,parent:o._id,blocks:h,lang:a||l,metadata:c},o._id):null;const d=T.getRegisteredChaiBlock(o._type);if(d!==null){let m=o;const y=d.component;m={...d.defaults,...o},i&&(m=i(m));const x=a===l?"":a,O=G(h,o._id,Q(o._type)),_=j(W(o,x,d),t),w=s.omit({blockProps:{},inBuilder:!1,...m,index:v,..._,...P(_),...C,...O,metadata:c,lang:a||l,key:o._id},["_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:a||l,metadata:c,dataProvider:d.dataProvider,block:o,component:y,props:w},o._id)},o._id)}return g.jsx(p.Suspense,{children:p.createElement(y,w)},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=I;exports.getStylesForBlocks=L;
|
package/dist/render.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { d as W } from "./ChaiThemeFn-Cort9tch.js";
|
|
2
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
|
|
4
|
-
import { g as
|
|
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 w, isString as R, isObject as D, find as _, includes as j } from "lodash-es";
|
|
4
|
+
import { g as b, S as y } 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";
|
|
@@ -10,10 +10,10 @@ import H from "@tailwindcss/typography";
|
|
|
10
10
|
import { g as X, c as Z } from "./plugin-kUMxtQR5.js";
|
|
11
11
|
import { jsx as p, jsxs as k } from "react/jsx-runtime";
|
|
12
12
|
import { getRegisteredChaiBlock as F } from "@chaibuilder/runtime";
|
|
13
|
-
import N, { Suspense as
|
|
13
|
+
import N, { Suspense as C, createElement as tt } from "react";
|
|
14
14
|
import { twMerge as et } from "tailwind-merge";
|
|
15
15
|
const nt = (t, s = "") => {
|
|
16
|
-
const { classes: n } =
|
|
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(":");
|
|
@@ -55,25 +55,25 @@ async function rt(t, s, n = [], e = "", r) {
|
|
|
55
55
|
);
|
|
56
56
|
}
|
|
57
57
|
const it = (t, s, n) => {
|
|
58
|
-
const e = JSON.stringify(t).replace(/#styles:([^"]*)/g, (r,
|
|
58
|
+
const e = JSON.stringify(t).replace(/#styles:([^"]*)/g, (r, o) => `#styles:${o.replace(/,/g, " ")}`.replace(/#styles:/g, ""));
|
|
59
59
|
return rt(s, [e], [], "", n);
|
|
60
60
|
}, xt = async (t, s = W, n = !1) => await it(t, s, n);
|
|
61
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(
|
|
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
68
|
const at = $((t, s) => {
|
|
69
|
-
const { baseClasses: n, classes: e } =
|
|
70
|
-
return s === "" ? r.replace(
|
|
69
|
+
const { baseClasses: n, classes: e } = b(t), r = et(n, e);
|
|
70
|
+
return s === "" ? r.replace(y, "").trim() : nt(r, s).replace(y, "").trim();
|
|
71
71
|
}), A = (t, s) => {
|
|
72
72
|
const n = E(t);
|
|
73
|
-
return x(
|
|
74
|
-
if (
|
|
73
|
+
return x(w(n), (e) => {
|
|
74
|
+
if (R(n[e])) {
|
|
75
75
|
let r = n[e];
|
|
76
|
-
const
|
|
76
|
+
const o = /\{\{(.*?)\}\}/g, c = r.match(o);
|
|
77
77
|
c && c.forEach((a) => {
|
|
78
78
|
const l = a.slice(2, -2), m = d(s, l, a);
|
|
79
79
|
r = r.replace(a, m);
|
|
@@ -83,13 +83,13 @@ const at = $((t, s) => {
|
|
|
83
83
|
}), n;
|
|
84
84
|
};
|
|
85
85
|
function ct(t, s) {
|
|
86
|
-
const n = d(t, `${s}_attrs`, {}), e =
|
|
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
89
|
function lt(t, s) {
|
|
90
90
|
const n = {};
|
|
91
91
|
return Object.keys(t).forEach((e) => {
|
|
92
|
-
if (
|
|
92
|
+
if (R(t[e]) && t[e].startsWith(y)) {
|
|
93
93
|
const r = at(t[e], s);
|
|
94
94
|
n[e] = {
|
|
95
95
|
className: r,
|
|
@@ -101,20 +101,20 @@ function lt(t, s) {
|
|
|
101
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(
|
|
105
|
-
r.includes(
|
|
104
|
+
return x(w(e), (o) => {
|
|
105
|
+
r.includes(o) && !g(s) && (e[o] = d(e, `${o}-${s}`, e[o]));
|
|
106
106
|
}), e;
|
|
107
107
|
}
|
|
108
108
|
const ut = $((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
|
-
}), pt = (t, s, n) => g(n) ? {} : Object.entries(n).reduce((e, [r,
|
|
111
|
+
}), pt = (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
|
-
const l = _(c, { _type:
|
|
117
|
-
return l && (e[r] = d(l, d(
|
|
116
|
+
const l = _(c, { _type: o.block });
|
|
117
|
+
return l && (e[r] = d(l, d(o, "prop"), null)), e;
|
|
118
118
|
}, {}), mt = () => /* @__PURE__ */ p("span", { children: "Loading..." });
|
|
119
119
|
function ft({
|
|
120
120
|
blocks: t,
|
|
@@ -122,33 +122,33 @@ function ft({
|
|
|
122
122
|
classPrefix: n = "",
|
|
123
123
|
externalData: e = {},
|
|
124
124
|
blockModifierCallback: r = null,
|
|
125
|
-
lang:
|
|
125
|
+
lang: o = "",
|
|
126
126
|
fallbackLang: c = "",
|
|
127
127
|
metadata: a = {},
|
|
128
128
|
dataProviderMetadataCallback: l = () => {
|
|
129
129
|
}
|
|
130
130
|
}) {
|
|
131
|
-
const m = t, I = (
|
|
132
|
-
return (s ? h(t, { _parent: s }) : h(t, (
|
|
133
|
-
const P = {}, M = h(m, { _parent:
|
|
131
|
+
const m = t, I = (i) => lt(i, n);
|
|
132
|
+
return (s ? h(t, { _parent: s }) : h(t, (i) => g(i._parent))).map((i, J) => {
|
|
133
|
+
const P = {}, M = h(m, { _parent: i._id });
|
|
134
134
|
P.children = M.length > 0 ? /* @__PURE__ */ p(
|
|
135
135
|
ft,
|
|
136
136
|
{
|
|
137
137
|
externalData: e,
|
|
138
138
|
classPrefix: n,
|
|
139
|
-
parent:
|
|
139
|
+
parent: i._id,
|
|
140
140
|
blocks: m,
|
|
141
|
-
lang:
|
|
141
|
+
lang: o || c,
|
|
142
142
|
metadata: a
|
|
143
143
|
},
|
|
144
|
-
|
|
144
|
+
i._id
|
|
145
145
|
) : null;
|
|
146
|
-
const u = F(
|
|
146
|
+
const u = F(i._type);
|
|
147
147
|
if (u !== null) {
|
|
148
|
-
let f =
|
|
148
|
+
let f = i;
|
|
149
149
|
const B = u.component;
|
|
150
|
-
f = { ...u.defaults, ...
|
|
151
|
-
const U =
|
|
150
|
+
f = { ...u.defaults, ...i }, r && (f = r(f));
|
|
151
|
+
const U = o === c ? "" : o, V = pt(m, i._id, ut(i._type)), v = A(dt(i, U, u), e), T = S(
|
|
152
152
|
{
|
|
153
153
|
blockProps: {},
|
|
154
154
|
inBuilder: !1,
|
|
@@ -159,31 +159,33 @@ function ft({
|
|
|
159
159
|
...P,
|
|
160
160
|
...V,
|
|
161
161
|
metadata: a,
|
|
162
|
-
lang:
|
|
162
|
+
lang: o || c,
|
|
163
|
+
key: i._id
|
|
163
164
|
},
|
|
164
165
|
["_parent"]
|
|
165
166
|
);
|
|
166
167
|
if (O(u, "dataProvider")) {
|
|
167
168
|
const K = d(u, "suspenseFallback", mt);
|
|
168
|
-
return /* @__PURE__ */ p(
|
|
169
|
+
return /* @__PURE__ */ p(C, { fallback: tt(K), children: /* @__PURE__ */ p(
|
|
169
170
|
ot,
|
|
170
171
|
{
|
|
171
172
|
dataProviderMetadataCallback: l,
|
|
172
|
-
lang:
|
|
173
|
+
lang: o || c,
|
|
173
174
|
metadata: a,
|
|
174
175
|
dataProvider: u.dataProvider,
|
|
175
|
-
block:
|
|
176
|
+
block: i,
|
|
176
177
|
component: B,
|
|
177
178
|
props: T
|
|
178
|
-
}
|
|
179
|
-
|
|
179
|
+
},
|
|
180
|
+
i._id
|
|
181
|
+
) }, i._id);
|
|
180
182
|
}
|
|
181
|
-
return /* @__PURE__ */ p(
|
|
183
|
+
return /* @__PURE__ */ p(C, { children: N.createElement(B, T) }, i._id);
|
|
182
184
|
}
|
|
183
185
|
return /* @__PURE__ */ k("noscript", { children: [
|
|
184
|
-
|
|
186
|
+
i._type,
|
|
185
187
|
" not found"
|
|
186
|
-
] },
|
|
188
|
+
] }, i._id);
|
|
187
189
|
});
|
|
188
190
|
}
|
|
189
191
|
export {
|