@chaibuilder/sdk 2.0.0-beta.58 → 2.0.0-beta.60
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/render.cjs +2 -2
- package/dist/render.d.ts +2 -1
- package/dist/render.js +101 -100
- 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 f=require("./ChaiThemeFn-DQu-2Eh9.cjs"),r=require("lodash-es"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("./ChaiThemeFn-DQu-2Eh9.cjs"),r=require("lodash-es"),h=require("./STRINGS-n7COZtKr.cjs"),P=require("@mhsdesign/jit-browser-tailwindcss"),q=require("@tailwindcss/aspect-ratio"),F=require("@tailwindcss/container-queries"),Y=require("@tailwindcss/forms"),v=require("@tailwindcss/typography"),E=require("./plugin-2xcljWGM.cjs"),a=require("./jsx-runtime-qcKc-DpB.cjs"),A=require("@chaibuilder/runtime"),p=require("react"),O=require("tailwind-merge"),$=(e,s="")=>{const t=e.replace(h.STYLES_KEY,"").split(",").map(i=>i.split(" ").map(l=>{if(l==="")return"";if(l.includes(":")){const u=l.split(":");return u[u.length-1]=s+r.last(u),u.join(":")}return`${s}${l}`}).join(" "));return r.flattenDeep(t).join(" ")},N=e=>{if(!e)return[];try{return JSON.parse(I(e)).filter(n=>!n._type.startsWith("@chai"))}catch{return[{_type:"Paragraph",_id:"error",content:"Invalid JSON. Please check the JSON string."}]}};function I(e){const s=/(asset:\/\/|https:\/\/asset\.localhost\/)(?:localhost\/)?[^"']+/g;return e.replace(s,n=>{const t=decodeURIComponent(n),i=t.indexOf("public");return i!==-1?t.substring(i+6):t})}async function K(e,s,n=[],t="",i){return await P.createTailwindcss({tailwindConfig:{darkMode:"class",safelist:n,theme:{extend:E.getChaiBuilderTheme(e)},plugins:[Y,v,q,F,E.chaiBuilderPlugin],corePlugins:{preflight:i},...t?{prefix:`${t}`}:{}}}).generateStylesFromContent(` ${i?"@tailwind base;":""}
|
|
2
2
|
@tailwind components;
|
|
3
|
-
@tailwind utilities;`,s)}const
|
|
3
|
+
@tailwind utilities;`,s)}const L=(e,s,n)=>{const t=JSON.stringify(e).replace(/#styles:([^"]*)/g,(i,o)=>`#styles:${o.replace(/,/g," ")}`.replace(/#styles:/g,""));return K(s,[t],[],"",n)},k=async(e,s=f.defaultThemeOptions,n=!1)=>await L(e,s,n);async function M(e){const s=await(e==null?void 0:e.dataProvider(e.block,e.lang,e.metadata));return a.jsxRuntimeExports.jsx(p.Suspense,{children:p.createElement(e.component,{...e.props,...s})})}const J=r.memoize((e,s)=>{const n=e.replace(h.STYLES_KEY,"").split(","),t=O.twMerge(n[0],n[1]);return s===""?t.replace(h.STYLES_KEY,"").trim():$(t,s).replace(h.STYLES_KEY,"").trim()});function U(e,s){const n=r.get(e,`${s}_attrs`,{}),t=r.keys(n).join(" ");return r.includes(t,"x-show")&&!r.includes(t,"x-transition")&&(n["x-transition"]=""),n}function b(e,s){const n={};return Object.keys(e).forEach(t=>{if(r.isString(e[t])&&e[t].startsWith(h.STYLES_KEY)){const i=J(e[t],s);n[t]={className:i,...U(e,t)}}}),n}function V(e,s){const n=r.get(e,"_bindings",{});return r.isEmpty(n)?{...e}:(r.each(n,(t,i)=>{r.isString(t)&&r.get(s,t,null)&&(e[i]=r.get(s,t,null))}),e)}function W(e,s,n){if(r.isEmpty(s))return e;const t=r.cloneDeep(e),i=r.get(n,"i18nProps",[]);return r.forEach(r.keys(t),o=>{i.includes(o)&&!r.isEmpty(s)&&(t[o]=r.get(t,`${o}-${s}`,t[o]))}),t}const z=()=>a.jsxRuntimeExports.jsx("span",{children:"Loading..."});function j({blocks:e,parent:s,classPrefix:n="",externalData:t={},blockModifierCallback:i=null,lang:o="",fallbackLang:g="",metadata:l={}}){const u=e,T=c=>b(c,n),C=s?r.filter(e,{_parent:s}):r.filter(e,c=>r.isEmpty(c._parent));return a.jsxRuntimeExports.jsx(a.jsxRuntimeExports.Fragment,{children:p.Children.toArray(C.map((c,w)=>{const S={},_=r.filter(u,{_parent:c._id});S.children=_.length>0?a.jsxRuntimeExports.jsx(j,{externalData:t,classPrefix:n,parent:c._id,blocks:u,lang:o||g,metadata:l}):null;const d=A.getRegisteredChaiBlock(c._type);if(d!==null){let m=c;const x=d.component;m={...d.defaults,...c},i&&(m=i(m));const R=o===g?"":o,y=r.omit({blockProps:{},inBuilder:!1,...m,index:w,...V(W(c,R,d),t),...T(m),...S,metadata:l,lang:o||g},["_parent"]);if(r.has(d,"dataProvider")){const B=r.get(d,"suspenseFallback",z);return a.jsxRuntimeExports.jsx(p.Suspense,{fallback:p.createElement(B),children:a.jsxRuntimeExports.jsx(M,{lang:o||g,metadata:l,dataProvider:d.dataProvider,block:c,component:x,props:y})})}return a.jsxRuntimeExports.jsx(p.Suspense,{children:p.createElement(x,y)})}return a.jsxRuntimeExports.jsxs("noscript",{children:[c._type," not found"]})}))})}exports.getChaiThemeCssVariables=f.getChaiThemeCssVariables;exports.getThemeFontsCSSImport=f.getThemeFontsCSSImport;exports.getThemeFontsLinkMarkup=f.getThemeFontsLinkMarkup;exports.RenderChaiBlocks=j;exports.convertToBlocks=N;exports.getStylesForBlocks=k;
|
package/dist/render.d.ts
CHANGED
|
@@ -43,13 +43,14 @@ export declare const getThemeFontsLinkMarkup: (chaiTheme: Pick<Partial<ChaiBuild
|
|
|
43
43
|
|
|
44
44
|
declare type HSLColor = string;
|
|
45
45
|
|
|
46
|
-
export declare function RenderChaiBlocks({ blocks, parent, classPrefix, externalData, blockModifierCallback, lang, metadata, }: {
|
|
46
|
+
export declare function RenderChaiBlocks({ blocks, parent, classPrefix, externalData, blockModifierCallback, lang, fallbackLang, metadata, }: {
|
|
47
47
|
blocks: ChaiBlock[];
|
|
48
48
|
parent?: string;
|
|
49
49
|
classPrefix?: string;
|
|
50
50
|
externalData?: Record<string, any>;
|
|
51
51
|
blockModifierCallback?: (block: ChaiBlock) => ChaiBlock;
|
|
52
52
|
lang?: string;
|
|
53
|
+
fallbackLang?: string;
|
|
53
54
|
metadata?: Record<string, any>;
|
|
54
55
|
}): JSX_2.Element;
|
|
55
56
|
|
package/dist/render.js
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
import { d as
|
|
2
|
-
import { a as
|
|
3
|
-
import { last as
|
|
4
|
-
import { S as
|
|
5
|
-
import { createTailwindcss as
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import { g as
|
|
1
|
+
import { d as F } from "./ChaiThemeFn-Cort9tch.js";
|
|
2
|
+
import { a as Tt, b as Bt, c as Et } from "./ChaiThemeFn-Cort9tch.js";
|
|
3
|
+
import { last as O, flattenDeep as v, memoize as N, filter as h, isEmpty as g, omit as R, has as I, get as p, each as J, isString as C, cloneDeep as U, forEach as K, keys as P, includes as j } from "lodash-es";
|
|
4
|
+
import { S as f } from "./STRINGS-DtEft2kY.js";
|
|
5
|
+
import { createTailwindcss as M } from "@mhsdesign/jit-browser-tailwindcss";
|
|
6
|
+
import W from "@tailwindcss/aspect-ratio";
|
|
7
|
+
import Y from "@tailwindcss/container-queries";
|
|
8
|
+
import z from "@tailwindcss/forms";
|
|
9
|
+
import D from "@tailwindcss/typography";
|
|
10
|
+
import { g as L, c as Q } from "./plugin-kUMxtQR5.js";
|
|
11
11
|
import { j as a } from "./jsx-runtime-Drh4NO5G.js";
|
|
12
|
-
import { getRegisteredChaiBlock as
|
|
13
|
-
import y, { Suspense as S, createElement as
|
|
14
|
-
import { twMerge as
|
|
15
|
-
const
|
|
16
|
-
const e = t.replace(
|
|
12
|
+
import { getRegisteredChaiBlock as V } from "@chaibuilder/runtime";
|
|
13
|
+
import y, { Suspense as S, createElement as b } from "react";
|
|
14
|
+
import { twMerge as q } from "tailwind-merge";
|
|
15
|
+
const G = (t, s = "") => {
|
|
16
|
+
const e = t.replace(f, "").split(",").map((r) => r.split(" ").map((c) => {
|
|
17
17
|
if (c === "") return "";
|
|
18
18
|
if (c.includes(":")) {
|
|
19
|
-
const
|
|
20
|
-
return
|
|
19
|
+
const l = c.split(":");
|
|
20
|
+
return l[l.length - 1] = s + O(l), l.join(":");
|
|
21
21
|
}
|
|
22
|
-
return `${
|
|
22
|
+
return `${s}${c}`;
|
|
23
23
|
}).join(" "));
|
|
24
|
-
return
|
|
25
|
-
},
|
|
24
|
+
return v(e).join(" ");
|
|
25
|
+
}, _t = (t) => {
|
|
26
26
|
if (!t) return [];
|
|
27
27
|
try {
|
|
28
|
-
return JSON.parse(
|
|
28
|
+
return JSON.parse(H(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
|
|
34
|
-
const
|
|
35
|
-
return t.replace(
|
|
36
|
-
const e = decodeURIComponent(
|
|
33
|
+
function H(t) {
|
|
34
|
+
const s = /(asset:\/\/|https:\/\/asset\.localhost\/)(?:localhost\/)?[^"']+/g;
|
|
35
|
+
return t.replace(s, (n) => {
|
|
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 X(t, s, n = [], e = "", r) {
|
|
41
|
+
return await M({
|
|
42
42
|
tailwindConfig: {
|
|
43
43
|
darkMode: "class",
|
|
44
|
-
safelist:
|
|
45
|
-
theme: { extend:
|
|
46
|
-
plugins: [
|
|
44
|
+
safelist: n,
|
|
45
|
+
theme: { extend: L(t) },
|
|
46
|
+
plugins: [z, D, W, Y, Q],
|
|
47
47
|
corePlugins: { preflight: r },
|
|
48
48
|
...e ? { prefix: `${e}` } : {}
|
|
49
49
|
}
|
|
@@ -51,106 +51,107 @@ async function G(t, n, s = [], e = "", r) {
|
|
|
51
51
|
` ${r ? "@tailwind base;" : ""}
|
|
52
52
|
@tailwind components;
|
|
53
53
|
@tailwind utilities;`,
|
|
54
|
-
|
|
54
|
+
s
|
|
55
55
|
);
|
|
56
56
|
}
|
|
57
|
-
const
|
|
57
|
+
const Z = (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
|
-
},
|
|
61
|
-
async function
|
|
62
|
-
const
|
|
63
|
-
return /* @__PURE__ */ a.jsx(S, { children: y.createElement(t.component, { ...t.props, ...
|
|
59
|
+
return X(s, [e], [], "", n);
|
|
60
|
+
}, jt = async (t, s = F, n = !1) => await Z(t, s, n);
|
|
61
|
+
async function k(t) {
|
|
62
|
+
const s = await (t == null ? void 0 : t.dataProvider(t.block, t.lang, t.metadata));
|
|
63
|
+
return /* @__PURE__ */ a.jsx(S, { children: y.createElement(t.component, { ...t.props, ...s }) });
|
|
64
64
|
}
|
|
65
|
-
const
|
|
66
|
-
const
|
|
67
|
-
return
|
|
65
|
+
const tt = N((t, s) => {
|
|
66
|
+
const n = t.replace(f, "").split(","), e = q(n[0], n[1]);
|
|
67
|
+
return s === "" ? e.replace(f, "").trim() : G(e, s).replace(f, "").trim();
|
|
68
68
|
});
|
|
69
|
-
function
|
|
70
|
-
const
|
|
71
|
-
return j(e, "x-show") && !j(e, "x-transition") && (
|
|
69
|
+
function et(t, s) {
|
|
70
|
+
const n = p(t, `${s}_attrs`, {}), e = P(n).join(" ");
|
|
71
|
+
return j(e, "x-show") && !j(e, "x-transition") && (n["x-transition"] = ""), n;
|
|
72
72
|
}
|
|
73
|
-
function
|
|
74
|
-
const
|
|
73
|
+
function st(t, s) {
|
|
74
|
+
const n = {};
|
|
75
75
|
return Object.keys(t).forEach((e) => {
|
|
76
|
-
if (C(t[e]) && t[e].startsWith(
|
|
77
|
-
const r =
|
|
78
|
-
|
|
76
|
+
if (C(t[e]) && t[e].startsWith(f)) {
|
|
77
|
+
const r = tt(t[e], s);
|
|
78
|
+
n[e] = {
|
|
79
79
|
className: r,
|
|
80
|
-
...
|
|
80
|
+
...et(t, e)
|
|
81
81
|
};
|
|
82
82
|
}
|
|
83
|
-
}),
|
|
83
|
+
}), n;
|
|
84
84
|
}
|
|
85
|
-
function nt(t,
|
|
86
|
-
const
|
|
87
|
-
return g(
|
|
88
|
-
C(e) &&
|
|
85
|
+
function nt(t, s) {
|
|
86
|
+
const n = p(t, "_bindings", {});
|
|
87
|
+
return g(n) ? { ...t } : (J(n, (e, r) => {
|
|
88
|
+
C(e) && p(s, e, null) && (t[r] = p(s, e, null));
|
|
89
89
|
}), t);
|
|
90
90
|
}
|
|
91
|
-
function
|
|
92
|
-
if (g(
|
|
93
|
-
const e =
|
|
94
|
-
return
|
|
95
|
-
r.includes(i) && !g(
|
|
91
|
+
function rt(t, s, n) {
|
|
92
|
+
if (g(s)) return t;
|
|
93
|
+
const e = U(t), r = p(n, "i18nProps", []);
|
|
94
|
+
return K(P(e), (i) => {
|
|
95
|
+
r.includes(i) && !g(s) && (e[i] = p(e, `${i}-${s}`, e[i]));
|
|
96
96
|
}), e;
|
|
97
97
|
}
|
|
98
|
-
const
|
|
99
|
-
function
|
|
98
|
+
const it = () => /* @__PURE__ */ a.jsx("span", { children: "Loading..." });
|
|
99
|
+
function ot({
|
|
100
100
|
blocks: t,
|
|
101
|
-
parent:
|
|
102
|
-
classPrefix:
|
|
101
|
+
parent: s,
|
|
102
|
+
classPrefix: n = "",
|
|
103
103
|
externalData: e = {},
|
|
104
104
|
blockModifierCallback: r = null,
|
|
105
105
|
lang: i = "",
|
|
106
|
-
|
|
106
|
+
fallbackLang: d = "",
|
|
107
|
+
metadata: c = {}
|
|
107
108
|
}) {
|
|
108
|
-
const
|
|
109
|
+
const l = t, T = (o) => st(o, n), B = s ? h(t, { _parent: s }) : h(t, (o) => g(o._parent));
|
|
109
110
|
return /* @__PURE__ */ a.jsx(a.Fragment, { children: y.Children.toArray(
|
|
110
|
-
B.map((o,
|
|
111
|
-
const x = {},
|
|
112
|
-
x.children =
|
|
113
|
-
|
|
111
|
+
B.map((o, E) => {
|
|
112
|
+
const x = {}, A = h(l, { _parent: o._id });
|
|
113
|
+
x.children = A.length > 0 ? /* @__PURE__ */ a.jsx(
|
|
114
|
+
ot,
|
|
114
115
|
{
|
|
115
116
|
externalData: e,
|
|
116
|
-
classPrefix:
|
|
117
|
+
classPrefix: n,
|
|
117
118
|
parent: o._id,
|
|
118
|
-
blocks:
|
|
119
|
-
lang: i
|
|
120
|
-
metadata:
|
|
119
|
+
blocks: l,
|
|
120
|
+
lang: i || d,
|
|
121
|
+
metadata: c
|
|
121
122
|
}
|
|
122
123
|
) : null;
|
|
123
|
-
const
|
|
124
|
-
if (
|
|
125
|
-
let
|
|
126
|
-
const w =
|
|
127
|
-
|
|
128
|
-
const _ =
|
|
124
|
+
const u = V(o._type);
|
|
125
|
+
if (u !== null) {
|
|
126
|
+
let m = o;
|
|
127
|
+
const w = u.component;
|
|
128
|
+
m = { ...u.defaults, ...o }, r && (m = r(m));
|
|
129
|
+
const _ = R(
|
|
129
130
|
{
|
|
130
131
|
blockProps: {},
|
|
131
132
|
inBuilder: !1,
|
|
132
|
-
...
|
|
133
|
-
index:
|
|
134
|
-
...nt(
|
|
135
|
-
...
|
|
133
|
+
...m,
|
|
134
|
+
index: E,
|
|
135
|
+
...nt(rt(o, i === d ? "" : i, u), e),
|
|
136
|
+
...T(m),
|
|
136
137
|
...x,
|
|
137
|
-
metadata:
|
|
138
|
-
lang: i
|
|
138
|
+
metadata: c,
|
|
139
|
+
lang: i || d
|
|
139
140
|
},
|
|
140
141
|
["_parent"]
|
|
141
142
|
);
|
|
142
|
-
if (
|
|
143
|
-
const
|
|
144
|
-
|
|
143
|
+
if (I(u, "dataProvider")) {
|
|
144
|
+
const $ = p(
|
|
145
|
+
u,
|
|
145
146
|
"suspenseFallback",
|
|
146
|
-
|
|
147
|
+
it
|
|
147
148
|
);
|
|
148
|
-
return /* @__PURE__ */ a.jsx(S, { fallback:
|
|
149
|
-
|
|
149
|
+
return /* @__PURE__ */ a.jsx(S, { fallback: b($), children: /* @__PURE__ */ a.jsx(
|
|
150
|
+
k,
|
|
150
151
|
{
|
|
151
|
-
lang: i
|
|
152
|
-
metadata:
|
|
153
|
-
dataProvider:
|
|
152
|
+
lang: i || d,
|
|
153
|
+
metadata: c,
|
|
154
|
+
dataProvider: u.dataProvider,
|
|
154
155
|
block: o,
|
|
155
156
|
component: w,
|
|
156
157
|
props: _
|
|
@@ -167,10 +168,10 @@ function it({
|
|
|
167
168
|
) });
|
|
168
169
|
}
|
|
169
170
|
export {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
171
|
+
ot as RenderChaiBlocks,
|
|
172
|
+
_t as convertToBlocks,
|
|
173
|
+
Tt as getChaiThemeCssVariables,
|
|
174
|
+
jt as getStylesForBlocks,
|
|
175
|
+
Bt as getThemeFontsCSSImport,
|
|
176
|
+
Et as getThemeFontsLinkMarkup
|
|
176
177
|
};
|