@chaibuilder/sdk 2.2.15 → 2.2.16
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 -0
- package/dist/render.js +87 -70
- 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
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("./plugin-C01tjI6V.cjs"),u=require("./new-blocks-render-helpers-DvF4dnjH.cjs"),a=require("lodash-es"),T=require("@tailwindcss/aspect-ratio"),I=require("@tailwindcss/forms"),q=require("@tailwindcss/typography");require("tailwindcss-animate");const R=require("./get-chai-builder-theme-CeaKvOZ8.cjs"),F=require("@mhsdesign/jit-browser-tailwindcss"),L=require("@tailwindcss/container-queries"),g=require("react/jsx-runtime"),h=require("react"),j=require("@chaibuilder/runtime");function E(e,t){const n=e.filter(({_type:r})=>r==="GlobalBlock"||r==="PartialBlock");for(let r=0;r<n.length;r++){const s=n[r],l=a.get(s,"partialBlockId",a.get(s,"globalBlock",""));if(l==="")continue;const i=a.cloneDeep(a.get(t,l,[]));s._parent&&(i==null?void 0:i.length)>0&&(i[0]._parent=s._parent);const o=e.indexOf(s);e.splice(o,1,...i)}return e}const D=e=>{if(!e)return[];try{return JSON.parse(M(e)).filter(n=>!n._type.startsWith("@chai"))}catch{return[{_type:"Paragraph",_id:"error",content:"Invalid JSON. Please check the JSON string."}]}};function M(e){const t=/(asset:\/\/|https:\/\/asset\.localhost\/)(?:localhost\/)?[^"']+/g;return e.replace(t,n=>{const r=decodeURIComponent(n),s=r.indexOf("public");return s!==-1?r.substring(s+6):r})}async function O(e,t,n=[],r="",s){return await F.createTailwindcss({tailwindConfig:{darkMode:"class",safelist:n,theme:{extend:R.getChaiBuilderTheme(e)},plugins:[I,q,T,L,f.chaiBuilderPlugin],corePlugins:{preflight:s},...r?{prefix:`${r}`}:{}}}).generateStylesFromContent(` ${s?"@tailwind base;":""}
|
|
2
2
|
@tailwind components;
|
|
3
|
-
@tailwind utilities;`,t)}const A=(e,t,
|
|
3
|
+
@tailwind utilities;`,t)}const A=(e,t,n)=>{const r=JSON.stringify(e).replace(/#styles:([^"]*)/g,(s,l)=>`#styles:${l.replace(/,/g," ")}`.replace(/#styles:/g,""));return O(t,[r],[],"",n)},$=async(e,t=f.defaultThemeOptions,n=!1)=>await A(e,t,n);async function N(e){const t=await e.dataProvider({pageProps:e.pageProps,block:e.block,lang:e.lang,draft:e.draft,inBuilder:!1});return a.has(t,"$metadata")&&a.isFunction(e.dataProviderMetadataCallback)&&e.dataProviderMetadataCallback(e.block,t.$metadata),e.children({...a.omit(t,"$metadata")})}const J=()=>g.jsx("div",{}),K=e=>{const{block:t,lang:n,fallbackLang:r,children:s,externalData:l,blocks:i,draft:o,pageProps:p,dataProviderMetadataCallback:m}=e,c=j.getRegisteredChaiBlock(t._type),k=a.get(c,"component",null),y=a.get(e.repeaterData,"index",-1),P=a.get(e.repeaterData,"dataKey",""),_=n===r?"":n,d=u.applyBinding(u.applyLanguage(t,_,c),l,{index:y,key:P}),w=u.getBlockTagAttributes(t,!1),C=V(i,t._id,u.getBlockRuntimeProps(t._type)),S=a.has(c,"dataProvider")&&a.isFunction(c.dataProvider),b={blockProps:{},inBuilder:!1,lang:n||r,...d,...w,...C};if(a.isNull(k))return null;if(S){const v=a.get(c,"suspenseFallback",J);return g.jsx(h.Suspense,{fallback:h.createElement(v),children:g.jsx(N,{lang:n,pageProps:p,block:t,dataProvider:c.dataProvider,...m?{dataProviderMetadataCallback:m}:{},draft:o,children:x=>h.createElement(k,{...b,...x,children:s({_id:t._id,_type:t._type,...a.isArray(d.repeaterItems)?{repeaterItems:u.applyLimit(d.repeaterItems,t),repeaterItemsBinding:d.repeaterItemsBinding}:{}})})})})}return g.jsx(h.Suspense,{children:h.createElement(k,{...b,children:s({_id:t._id,_type:t._type,...a.isArray(d.repeaterItems)?{repeaterItems:u.applyLimit(d.repeaterItems,t),repeaterItemsBinding:d.repeaterItemsBinding}:{}})})})},B=e=>{const{blocks:t,parent:n,repeaterData:r}=e;let s=a.uniqBy(a.filter(t,i=>a.has(i,"_id")&&(a.isEmpty(n)?!i._parent:i._parent===n)),"_id");const l=i=>a.filter(t,o=>o._parent===i).length>0;return a.map(s,i=>i?h.createElement(K,{...e,key:i._id,block:i},({_id:o,_type:p,repeaterItems:m,repeaterItemsBinding:c})=>p==="Repeater"?a.isArray(m)&&m.map((k,y)=>g.jsx(B,{...e,parent:i._id,repeaterData:{index:y,dataKey:c}})):l(o)?g.jsx(B,{...e,parent:i._id,repeaterData:r}):null):null)},V=(e,t,n)=>a.isEmpty(n)?{}:Object.entries(n).reduce((r,[s,l])=>{const i=[];let o=a.find(e,{_id:t});for(;o;)i.push(o),o=a.find(e,{_id:o._parent});const p=a.find(i,{_type:l.block});return p&&(r[s]=a.get(p,a.get(l,"prop"),null)),r},{});function U(e){if(a.has(e,"metadata")&&console.warn(" metadata is deprecated and will be removed in upcoming version, use pageProps instead"),a.isEmpty(e.lang)&&!a.isEmpty(e.fallbackLang))throw new Error("lang prop is required when fallbackLang is provided");if(a.isEmpty(e.blocks))return null;const t=e.lang??"en",n=e.fallbackLang??t;return g.jsx(B,{...e,lang:t,fallbackLang:n})}exports.getChaiThemeCssVariables=f.getChaiThemeCssVariables;exports.getThemeFontsCSSImport=f.getThemeFontsCSSImport;exports.getThemeFontsLinkMarkup=f.getThemeFontsLinkMarkup;exports.applyChaiDataBinding=u.applyChaiDataBinding;exports.RenderChaiBlocks=U;exports.convertToBlocks=D;exports.getMergedPartialBlocks=E;exports.getStylesForBlocks=$;
|
package/dist/render.d.ts
CHANGED
|
@@ -62,6 +62,8 @@ export declare const convertToBlocks: (chaiFormatContent: string) => ChaiBlock[]
|
|
|
62
62
|
|
|
63
63
|
export declare const getChaiThemeCssVariables: (chaiTheme: ChaiThemeValues) => string;
|
|
64
64
|
|
|
65
|
+
export declare function getMergedPartialBlocks(blocks: ChaiBlock[], partials: Record<string, ChaiBlock[]>): ChaiBlock[];
|
|
66
|
+
|
|
65
67
|
/**
|
|
66
68
|
* Get the tailwind css for the blocks
|
|
67
69
|
* @param blocks - The blocks to get the tailwind css for
|
package/dist/render.js
CHANGED
|
@@ -1,40 +1,52 @@
|
|
|
1
1
|
import { d as F, c as O } from "./plugin-fnBB3TCm.js";
|
|
2
|
-
import { a as
|
|
3
|
-
import { a as
|
|
4
|
-
import { e as
|
|
5
|
-
import { has as k, isFunction as
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
2
|
+
import { a as Ce, b as ve, e as xe } from "./plugin-fnBB3TCm.js";
|
|
3
|
+
import { a as M, b as $, g as A, c as N, d as w } from "./new-blocks-render-helpers-DfAVXxr2.js";
|
|
4
|
+
import { e as Ie } from "./new-blocks-render-helpers-DfAVXxr2.js";
|
|
5
|
+
import { get as s, cloneDeep as J, has as k, isFunction as x, omit as E, isNull as K, isArray as B, uniqBy as j, filter as C, isEmpty as m, map as q, find as y } from "lodash-es";
|
|
6
|
+
import U from "@tailwindcss/aspect-ratio";
|
|
7
|
+
import V from "@tailwindcss/forms";
|
|
8
|
+
import G from "@tailwindcss/typography";
|
|
9
9
|
import "tailwindcss-animate";
|
|
10
|
-
import { g as
|
|
11
|
-
import { createTailwindcss as
|
|
12
|
-
import
|
|
13
|
-
import { jsx as
|
|
14
|
-
import { Suspense as v, createElement as
|
|
15
|
-
import { getRegisteredChaiBlock as
|
|
16
|
-
|
|
10
|
+
import { g as W } from "./get-chai-builder-theme-ByeXCyGx.js";
|
|
11
|
+
import { createTailwindcss as z } from "@mhsdesign/jit-browser-tailwindcss";
|
|
12
|
+
import H from "@tailwindcss/container-queries";
|
|
13
|
+
import { jsx as p } from "react/jsx-runtime";
|
|
14
|
+
import { Suspense as v, createElement as h } from "react";
|
|
15
|
+
import { getRegisteredChaiBlock as Q } from "@chaibuilder/runtime";
|
|
16
|
+
function be(e, t) {
|
|
17
|
+
const a = e.filter(({ _type: r }) => r === "GlobalBlock" || r === "PartialBlock");
|
|
18
|
+
for (let r = 0; r < a.length; r++) {
|
|
19
|
+
const i = a[r], l = s(i, "partialBlockId", s(i, "globalBlock", ""));
|
|
20
|
+
if (l === "") continue;
|
|
21
|
+
const n = J(s(t, l, []));
|
|
22
|
+
i._parent && (n == null ? void 0 : n.length) > 0 && (n[0]._parent = i._parent);
|
|
23
|
+
const o = e.indexOf(i);
|
|
24
|
+
e.splice(o, 1, ...n);
|
|
25
|
+
}
|
|
26
|
+
return e;
|
|
27
|
+
}
|
|
28
|
+
const ye = (e) => {
|
|
17
29
|
if (!e) return [];
|
|
18
30
|
try {
|
|
19
|
-
return JSON.parse(
|
|
31
|
+
return JSON.parse(X(e)).filter((a) => !a._type.startsWith("@chai"));
|
|
20
32
|
} catch {
|
|
21
33
|
return [{ _type: "Paragraph", _id: "error", content: "Invalid JSON. Please check the JSON string." }];
|
|
22
34
|
}
|
|
23
35
|
};
|
|
24
|
-
function
|
|
36
|
+
function X(e) {
|
|
25
37
|
const t = /(asset:\/\/|https:\/\/asset\.localhost\/)(?:localhost\/)?[^"']+/g;
|
|
26
38
|
return e.replace(t, (a) => {
|
|
27
39
|
const r = decodeURIComponent(a), i = r.indexOf("public");
|
|
28
40
|
return i !== -1 ? r.substring(i + 6) : r;
|
|
29
41
|
});
|
|
30
42
|
}
|
|
31
|
-
async function
|
|
32
|
-
return await
|
|
43
|
+
async function Y(e, t, a = [], r = "", i) {
|
|
44
|
+
return await z({
|
|
33
45
|
tailwindConfig: {
|
|
34
46
|
darkMode: "class",
|
|
35
47
|
safelist: a,
|
|
36
|
-
theme: { extend:
|
|
37
|
-
plugins: [
|
|
48
|
+
theme: { extend: W(e) },
|
|
49
|
+
plugins: [V, G, U, H, O],
|
|
38
50
|
corePlugins: { preflight: i },
|
|
39
51
|
...r ? { prefix: `${r}` } : {}
|
|
40
52
|
}
|
|
@@ -45,11 +57,11 @@ async function Q(e, t, a = [], r = "", i) {
|
|
|
45
57
|
t
|
|
46
58
|
);
|
|
47
59
|
}
|
|
48
|
-
const
|
|
49
|
-
const r = JSON.stringify(e).replace(/#styles:([^"]*)/g, (i,
|
|
50
|
-
return
|
|
51
|
-
},
|
|
52
|
-
async function
|
|
60
|
+
const Z = (e, t, a) => {
|
|
61
|
+
const r = JSON.stringify(e).replace(/#styles:([^"]*)/g, (i, l) => `#styles:${l.replace(/,/g, " ")}`.replace(/#styles:/g, ""));
|
|
62
|
+
return Y(t, [r], [], "", a);
|
|
63
|
+
}, Be = async (e, t = F, a = !1) => await Z(e, t, a);
|
|
64
|
+
async function ee(e) {
|
|
53
65
|
const t = await e.dataProvider({
|
|
54
66
|
pageProps: e.pageProps,
|
|
55
67
|
block: e.block,
|
|
@@ -57,86 +69,91 @@ async function Y(e) {
|
|
|
57
69
|
draft: e.draft,
|
|
58
70
|
inBuilder: !1
|
|
59
71
|
});
|
|
60
|
-
return k(t, "$metadata") &&
|
|
61
|
-
...
|
|
72
|
+
return k(t, "$metadata") && x(e.dataProviderMetadataCallback) && e.dataProviderMetadataCallback(e.block, t.$metadata), e.children({
|
|
73
|
+
...E(t, "$metadata")
|
|
62
74
|
});
|
|
63
75
|
}
|
|
64
|
-
const
|
|
65
|
-
const { block: t, lang: a, fallbackLang: r, children: i, externalData:
|
|
76
|
+
const te = () => /* @__PURE__ */ p("div", {}), ae = (e) => {
|
|
77
|
+
const { block: t, lang: a, fallbackLang: r, children: i, externalData: l, blocks: n, draft: o, pageProps: g, dataProviderMetadataCallback: u } = e, c = Q(t._type), f = s(c, "component", null), b = s(e.repeaterData, "index", -1), S = s(e.repeaterData, "dataKey", ""), d = M($(t, a === r ? "" : a, c), l, {
|
|
66
78
|
index: b,
|
|
67
|
-
key:
|
|
68
|
-
}), I =
|
|
79
|
+
key: S
|
|
80
|
+
}), I = A(t, !1), L = re(n, t._id, N(t._type)), T = k(c, "dataProvider") && x(c.dataProvider), P = {
|
|
69
81
|
blockProps: {},
|
|
70
82
|
inBuilder: !1,
|
|
71
83
|
lang: a || r,
|
|
72
|
-
...
|
|
84
|
+
...d,
|
|
73
85
|
...I,
|
|
74
|
-
...
|
|
86
|
+
...L
|
|
75
87
|
};
|
|
76
|
-
if (
|
|
77
|
-
if (
|
|
78
|
-
const
|
|
79
|
-
return /* @__PURE__ */
|
|
80
|
-
|
|
88
|
+
if (K(f)) return null;
|
|
89
|
+
if (T) {
|
|
90
|
+
const D = s(c, "suspenseFallback", te);
|
|
91
|
+
return /* @__PURE__ */ p(v, { fallback: h(D), children: /* @__PURE__ */ p(
|
|
92
|
+
ee,
|
|
81
93
|
{
|
|
82
94
|
lang: a,
|
|
83
|
-
pageProps:
|
|
95
|
+
pageProps: g,
|
|
84
96
|
block: t,
|
|
85
|
-
dataProvider:
|
|
86
|
-
...
|
|
97
|
+
dataProvider: c.dataProvider,
|
|
98
|
+
...u ? { dataProviderMetadataCallback: u } : {},
|
|
87
99
|
draft: o,
|
|
88
|
-
children: (
|
|
89
|
-
...
|
|
90
|
-
...
|
|
100
|
+
children: (R) => h(f, {
|
|
101
|
+
...P,
|
|
102
|
+
...R,
|
|
91
103
|
children: i({
|
|
92
104
|
_id: t._id,
|
|
93
105
|
_type: t._type,
|
|
94
|
-
...
|
|
95
|
-
repeaterItems:
|
|
96
|
-
repeaterItemsBinding:
|
|
106
|
+
...B(d.repeaterItems) ? {
|
|
107
|
+
repeaterItems: w(d.repeaterItems, t),
|
|
108
|
+
repeaterItemsBinding: d.repeaterItemsBinding
|
|
97
109
|
} : {}
|
|
98
110
|
})
|
|
99
111
|
})
|
|
100
112
|
}
|
|
101
113
|
) });
|
|
102
114
|
}
|
|
103
|
-
return /* @__PURE__ */
|
|
104
|
-
...
|
|
115
|
+
return /* @__PURE__ */ p(v, { children: h(f, {
|
|
116
|
+
...P,
|
|
105
117
|
children: i({
|
|
106
118
|
_id: t._id,
|
|
107
119
|
_type: t._type,
|
|
108
|
-
...
|
|
109
|
-
repeaterItems:
|
|
110
|
-
repeaterItemsBinding:
|
|
120
|
+
...B(d.repeaterItems) ? {
|
|
121
|
+
repeaterItems: w(d.repeaterItems, t),
|
|
122
|
+
repeaterItemsBinding: d.repeaterItemsBinding
|
|
111
123
|
} : {}
|
|
112
124
|
})
|
|
113
125
|
}) });
|
|
114
126
|
}, _ = (e) => {
|
|
115
|
-
const { blocks: t, parent: a, repeaterData: r } = e
|
|
116
|
-
|
|
117
|
-
(n) => k(n, "_id") && (
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
127
|
+
const { blocks: t, parent: a, repeaterData: r } = e;
|
|
128
|
+
let i = j(
|
|
129
|
+
C(t, (n) => k(n, "_id") && (m(a) ? !n._parent : n._parent === a)),
|
|
130
|
+
"_id"
|
|
131
|
+
);
|
|
132
|
+
const l = (n) => C(t, (o) => o._parent === n).length > 0;
|
|
133
|
+
return q(i, (n) => n ? /* @__PURE__ */ h(ae, { ...e, key: n._id, block: n }, ({ _id: o, _type: g, repeaterItems: u, repeaterItemsBinding: c }) => g === "Repeater" ? B(u) && u.map((f, b) => /* @__PURE__ */ p(_, { ...e, parent: n._id, repeaterData: { index: b, dataKey: c } })) : l(o) ? /* @__PURE__ */ p(_, { ...e, parent: n._id, repeaterData: r }) : null) : null);
|
|
134
|
+
}, re = (e, t, a) => m(a) ? {} : Object.entries(a).reduce((r, [i, l]) => {
|
|
121
135
|
const n = [];
|
|
122
136
|
let o = y(e, { _id: t });
|
|
123
137
|
for (; o; )
|
|
124
138
|
n.push(o), o = y(e, { _id: o._parent });
|
|
125
|
-
const
|
|
126
|
-
return
|
|
139
|
+
const g = y(n, { _type: l.block });
|
|
140
|
+
return g && (r[i] = s(g, s(l, "prop"), null)), r;
|
|
127
141
|
}, {});
|
|
128
|
-
function
|
|
129
|
-
if (k(e, "metadata") && console.warn(" metadata is
|
|
142
|
+
function _e(e) {
|
|
143
|
+
if (k(e, "metadata") && console.warn(" metadata is deprecated and will be removed in upcoming version, use pageProps instead"), m(e.lang) && !m(e.fallbackLang))
|
|
130
144
|
throw new Error("lang prop is required when fallbackLang is provided");
|
|
145
|
+
if (m(e.blocks))
|
|
146
|
+
return null;
|
|
131
147
|
const t = e.lang ?? "en", a = e.fallbackLang ?? t;
|
|
132
|
-
return /* @__PURE__ */
|
|
148
|
+
return /* @__PURE__ */ p(_, { ...e, lang: t, fallbackLang: a });
|
|
133
149
|
}
|
|
134
150
|
export {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
151
|
+
_e as RenderChaiBlocks,
|
|
152
|
+
Ie as applyChaiDataBinding,
|
|
153
|
+
ye as convertToBlocks,
|
|
154
|
+
Ce as getChaiThemeCssVariables,
|
|
155
|
+
be as getMergedPartialBlocks,
|
|
156
|
+
Be as getStylesForBlocks,
|
|
157
|
+
ve as getThemeFontsCSSImport,
|
|
158
|
+
xe as getThemeFontsLinkMarkup
|
|
142
159
|
};
|