@chaibuilder/sdk 2.2.12 → 2.2.13
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.js +24 -24
- 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 k=require("./plugin-C01tjI6V.cjs"),p=require("./new-blocks-render-helpers-DRQ8Buz8.cjs"),r=require("lodash-es"),x=require("@tailwindcss/aspect-ratio"),q=require("@tailwindcss/forms"),I=require("@tailwindcss/typography");require("tailwindcss-animate");const R=require("./get-chai-builder-theme-CeaKvOZ8.cjs"),F=require("@mhsdesign/jit-browser-tailwindcss"),j=require("@tailwindcss/container-queries"),u=require("react/jsx-runtime"),m=require("react"),L=require("@chaibuilder/runtime"),E=e=>{if(!e)return[];try{return JSON.parse(O(e)).filter(a=>!a._type.startsWith("@chai"))}catch{return[{_type:"Paragraph",_id:"error",content:"Invalid JSON. Please check the JSON string."}]}};function O(e){const t=/(asset:\/\/|https:\/\/asset\.localhost\/)(?:localhost\/)?[^"']+/g;return e.replace(t,a=>{const n=decodeURIComponent(a),s=n.indexOf("public");return s!==-1?n.substring(s+6):n})}async function A(e,t,a=[],n="",s){return await F.createTailwindcss({tailwindConfig:{darkMode:"class",safelist:a,theme:{extend:R.getChaiBuilderTheme(e)},plugins:[q,I,x,j,k.chaiBuilderPlugin],corePlugins:{preflight:s},...n?{prefix:`${n}`}:{}}}).generateStylesFromContent(` ${s?"@tailwind base;":""}
|
|
2
2
|
@tailwind components;
|
|
3
|
-
@tailwind utilities;`,t)}const D=(e,t,a)=>{const n=JSON.stringify(e).replace(/#styles:([^"]*)/g,(s,
|
|
3
|
+
@tailwind utilities;`,t)}const D=(e,t,a)=>{const n=JSON.stringify(e).replace(/#styles:([^"]*)/g,(s,c)=>`#styles:${c.replace(/,/g," ")}`.replace(/#styles:/g,""));return A(t,[n],[],"",a)},M=async(e,t=k.defaultThemeOptions,a=!1)=>await D(e,t,a);async function $(e){const t=await e.dataProvider({pageProps:e.pageProps,block:e.block,lang:e.lang,draft:e.draft,inBuilder:!1});return r.has(t,"$metadata")&&r.isFunction(e.dataProviderMetadataCallback)&&e.dataProviderMetadataCallback(e.block,t.$metadata),e.children({...r.omit(t,"$metadata")})}const N=()=>u.jsx("div",{}),J=e=>{const{block:t,lang:a,fallbackLang:n,children:s,externalData:c,blocks:i,draft:l,pageProps:g,dataProviderMetadataCallback:h}=e,o=L.getRegisteredChaiBlock(t._type),f=r.get(o,"component",null),y=r.get(e.repeaterData,"index",-1),B=r.get(e.repeaterData,"dataKey",""),_=a===n?"":a,d=p.applyBinding(p.applyLanguage(t,_,o),c,{index:y,key:B}),w=p.getBlockTagAttributes(t,!1),C=K(i,t._id,p.getBlockRuntimeProps(t._type)),S=r.has(o,"dataProvider")&&r.isFunction(o.dataProvider),P={blockProps:{},inBuilder:!1,lang:a||n,...d,...w,...C};if(r.isNull(f))return null;if(S){const v=r.get(o,"suspenseFallback",N);return u.jsx(m.Suspense,{fallback:m.createElement(v),children:u.jsx($,{lang:a,pageProps:g,block:t,dataProvider:o.dataProvider,...h?{dataProviderMetadataCallback:h}:{},draft:l,children:T=>m.createElement(f,{...P,...T,children:s({_id:t._id,_type:t._type,...r.isArray(d.repeaterItems)?{repeaterItems:p.applyLimit(d.repeaterItems,t),repeaterItemsBinding:d.repeaterItemsBinding}:{}})})})})}return u.jsx(m.Suspense,{children:m.createElement(f,{...P,children:s({_id:t._id,_type:t._type,...r.isArray(d.repeaterItems)?{repeaterItems:p.applyLimit(d.repeaterItems,t),repeaterItemsBinding:d.repeaterItemsBinding}:{}})})})},b=e=>{const{blocks:t,parent:a,repeaterData:n}=e,s=r.filter(t,i=>r.has(i,"_id")&&(r.isEmpty(a)?!i._parent:i._parent===a)),c=i=>r.filter(t,l=>l._parent===i).length>0;return r.map(s,i=>i?m.createElement(J,{...e,key:i._id,block:i},({_id:l,_type:g,repeaterItems:h,repeaterItemsBinding:o})=>g==="Repeater"?r.isArray(h)&&h.map((f,y)=>u.jsx(b,{...e,parent:i._id,repeaterData:{index:y,dataKey:o}})):c(l)?u.jsx(b,{...e,parent:i._id,repeaterData:n}):null):null)},K=(e,t,a)=>r.isEmpty(a)?{}:Object.entries(a).reduce((n,[s,c])=>{const i=[];let l=r.find(e,{_id:t});for(;l;)i.push(l),l=r.find(e,{_id:l._parent});const g=r.find(i,{_type:c.block});return g&&(n[s]=r.get(g,r.get(c,"prop"),null)),n},{});function V(e){if(r.has(e,"metadata")&&console.warn(" metadata is deprecated and will be removed in upcoming version, use pageProps instead"),r.isEmpty(e.lang)&&!r.isEmpty(e.fallbackLang))throw new Error("lang prop is required when fallbackLang is provided");const t=e.lang??"en",a=e.fallbackLang??t;return u.jsx(b,{...e,lang:t,fallbackLang:a})}exports.getChaiThemeCssVariables=k.getChaiThemeCssVariables;exports.getThemeFontsCSSImport=k.getThemeFontsCSSImport;exports.getThemeFontsLinkMarkup=k.getThemeFontsLinkMarkup;exports.RenderChaiBlocks=V;exports.convertToBlocks=E;exports.getStylesForBlocks=M;
|
package/dist/render.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { d as
|
|
2
|
-
import { a as
|
|
3
|
-
import { a as
|
|
4
|
-
import { has as k,
|
|
1
|
+
import { d as D, c as O } from "./plugin-fnBB3TCm.js";
|
|
2
|
+
import { a as _e, b as we, e as Be } from "./plugin-fnBB3TCm.js";
|
|
3
|
+
import { a as $, b as A, g as M, c as N, d as B } from "./new-blocks-render-helpers-BGcG63he.js";
|
|
4
|
+
import { has as k, isFunction as S, omit as J, get as g, isNull as E, isArray as P, filter as v, isEmpty as h, map as K, find as y } from "lodash-es";
|
|
5
5
|
import j from "@tailwindcss/aspect-ratio";
|
|
6
6
|
import U from "@tailwindcss/forms";
|
|
7
7
|
import V from "@tailwindcss/typography";
|
|
@@ -33,7 +33,7 @@ async function Q(e, t, a = [], r = "", i) {
|
|
|
33
33
|
darkMode: "class",
|
|
34
34
|
safelist: a,
|
|
35
35
|
theme: { extend: q(e) },
|
|
36
|
-
plugins: [U, V, j, z,
|
|
36
|
+
plugins: [U, V, j, z, O],
|
|
37
37
|
corePlugins: { preflight: i },
|
|
38
38
|
...r ? { prefix: `${r}` } : {}
|
|
39
39
|
}
|
|
@@ -47,7 +47,7 @@ async function Q(e, t, a = [], r = "", i) {
|
|
|
47
47
|
const X = (e, t, a) => {
|
|
48
48
|
const r = JSON.stringify(e).replace(/#styles:([^"]*)/g, (i, o) => `#styles:${o.replace(/,/g, " ")}`.replace(/#styles:/g, ""));
|
|
49
49
|
return Q(t, [r], [], "", a);
|
|
50
|
-
}, ke = async (e, t =
|
|
50
|
+
}, ke = async (e, t = D, a = !1) => await X(e, t, a);
|
|
51
51
|
async function Y(e) {
|
|
52
52
|
const t = await e.dataProvider({
|
|
53
53
|
pageProps: e.pageProps,
|
|
@@ -56,41 +56,41 @@ async function Y(e) {
|
|
|
56
56
|
draft: e.draft,
|
|
57
57
|
inBuilder: !1
|
|
58
58
|
});
|
|
59
|
-
return k(t, "$metadata") && e.dataProviderMetadataCallback(e.block, t.$metadata), e.children({
|
|
59
|
+
return k(t, "$metadata") && S(e.dataProviderMetadataCallback) && e.dataProviderMetadataCallback(e.block, t.$metadata), e.children({
|
|
60
60
|
...J(t, "$metadata")
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
63
|
const Z = () => /* @__PURE__ */ d("div", {}), ee = (e) => {
|
|
64
|
-
const { block: t, lang: a, fallbackLang: r, children: i, externalData: o, blocks: n, draft: s, pageProps: p, dataProviderMetadataCallback: m } = e, l = G(t._type), u = g(l, "component", null), b = g(e.repeaterData, "index", -1),
|
|
64
|
+
const { block: t, lang: a, fallbackLang: r, children: i, externalData: o, blocks: n, draft: s, pageProps: p, dataProviderMetadataCallback: m } = e, l = G(t._type), u = g(l, "component", null), b = g(e.repeaterData, "index", -1), x = g(e.repeaterData, "dataKey", ""), c = $(A(t, a === r ? "" : a, l), o, {
|
|
65
65
|
index: b,
|
|
66
|
-
key:
|
|
67
|
-
}),
|
|
66
|
+
key: x
|
|
67
|
+
}), I = M(t, !1), T = te(n, t._id, N(t._type)), L = k(l, "dataProvider") && S(l.dataProvider), w = {
|
|
68
68
|
blockProps: {},
|
|
69
69
|
inBuilder: !1,
|
|
70
70
|
lang: a || r,
|
|
71
71
|
...c,
|
|
72
|
-
...
|
|
73
|
-
...
|
|
72
|
+
...I,
|
|
73
|
+
...T
|
|
74
74
|
};
|
|
75
75
|
if (E(u)) return null;
|
|
76
|
-
if (
|
|
77
|
-
const
|
|
78
|
-
return /* @__PURE__ */ d(C, { fallback: f(
|
|
76
|
+
if (L) {
|
|
77
|
+
const R = g(l, "suspenseFallback", Z);
|
|
78
|
+
return /* @__PURE__ */ d(C, { fallback: f(R), children: /* @__PURE__ */ d(
|
|
79
79
|
Y,
|
|
80
80
|
{
|
|
81
81
|
lang: a,
|
|
82
82
|
pageProps: p,
|
|
83
83
|
block: t,
|
|
84
84
|
dataProvider: l.dataProvider,
|
|
85
|
-
dataProviderMetadataCallback: m,
|
|
85
|
+
...m ? { dataProviderMetadataCallback: m } : {},
|
|
86
86
|
draft: s,
|
|
87
|
-
children: (
|
|
87
|
+
children: (F) => f(u, {
|
|
88
88
|
...w,
|
|
89
|
-
...
|
|
89
|
+
...F,
|
|
90
90
|
children: i({
|
|
91
91
|
_id: t._id,
|
|
92
92
|
_type: t._type,
|
|
93
|
-
...
|
|
93
|
+
...P(c.repeaterItems) ? {
|
|
94
94
|
repeaterItems: B(c.repeaterItems, t),
|
|
95
95
|
repeaterItemsBinding: c.repeaterItemsBinding
|
|
96
96
|
} : {}
|
|
@@ -104,18 +104,18 @@ const Z = () => /* @__PURE__ */ d("div", {}), ee = (e) => {
|
|
|
104
104
|
children: i({
|
|
105
105
|
_id: t._id,
|
|
106
106
|
_type: t._type,
|
|
107
|
-
...
|
|
107
|
+
...P(c.repeaterItems) ? {
|
|
108
108
|
repeaterItems: B(c.repeaterItems, t),
|
|
109
109
|
repeaterItemsBinding: c.repeaterItemsBinding
|
|
110
110
|
} : {}
|
|
111
111
|
})
|
|
112
112
|
}) });
|
|
113
|
-
},
|
|
113
|
+
}, _ = (e) => {
|
|
114
114
|
const { blocks: t, parent: a, repeaterData: r } = e, i = v(
|
|
115
115
|
t,
|
|
116
116
|
(n) => k(n, "_id") && (h(a) ? !n._parent : n._parent === a)
|
|
117
117
|
), o = (n) => v(t, (s) => s._parent === n).length > 0;
|
|
118
|
-
return K(i, (n) => n ? /* @__PURE__ */ f(ee, { ...e, key: n._id, block: n }, ({ _id: s, _type: p, repeaterItems: m, repeaterItemsBinding: l }) => p === "Repeater" ?
|
|
118
|
+
return K(i, (n) => n ? /* @__PURE__ */ f(ee, { ...e, key: n._id, block: n }, ({ _id: s, _type: p, repeaterItems: m, repeaterItemsBinding: l }) => p === "Repeater" ? P(m) && m.map((u, b) => /* @__PURE__ */ d(_, { ...e, parent: n._id, repeaterData: { index: b, dataKey: l } })) : o(s) ? /* @__PURE__ */ d(_, { ...e, parent: n._id, repeaterData: r }) : null) : null);
|
|
119
119
|
}, te = (e, t, a) => h(a) ? {} : Object.entries(a).reduce((r, [i, o]) => {
|
|
120
120
|
const n = [];
|
|
121
121
|
let s = y(e, { _id: t });
|
|
@@ -128,12 +128,12 @@ function be(e) {
|
|
|
128
128
|
if (k(e, "metadata") && console.warn(" metadata is deprecated and will be removed in upcoming version, use pageProps instead"), h(e.lang) && !h(e.fallbackLang))
|
|
129
129
|
throw new Error("lang prop is required when fallbackLang is provided");
|
|
130
130
|
const t = e.lang ?? "en", a = e.fallbackLang ?? t;
|
|
131
|
-
return /* @__PURE__ */ d(
|
|
131
|
+
return /* @__PURE__ */ d(_, { ...e, lang: t, fallbackLang: a });
|
|
132
132
|
}
|
|
133
133
|
export {
|
|
134
134
|
be as RenderChaiBlocks,
|
|
135
135
|
he as convertToBlocks,
|
|
136
|
-
|
|
136
|
+
_e as getChaiThemeCssVariables,
|
|
137
137
|
ke as getStylesForBlocks,
|
|
138
138
|
we as getThemeFontsCSSImport,
|
|
139
139
|
Be as getThemeFontsLinkMarkup
|