@chaibuilder/sdk 2.2.6-beta.1 → 2.2.6-beta.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/render.cjs +2 -2
- package/dist/render.js +35 -35
- 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 h=require("./plugin-C01tjI6V.cjs"),p=require("./new-blocks-render-helpers-DxkhHL0n.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"),j=require("@mhsdesign/jit-browser-tailwindcss"),F=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(
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("./plugin-C01tjI6V.cjs"),p=require("./new-blocks-render-helpers-DxkhHL0n.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"),j=require("@mhsdesign/jit-browser-tailwindcss"),F=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 j.createTailwindcss({tailwindConfig:{darkMode:"class",safelist:a,theme:{extend:R.getChaiBuilderTheme(e)},plugins:[q,I,x,F,h.chaiBuilderPlugin],corePlugins:{preflight:s},...n?{prefix:`${n}`}:{}}}).generateStylesFromContent(` ${s?"@tailwind base;":""}
|
|
2
2
|
@tailwind components;
|
|
3
|
-
@tailwind utilities;`,t)}const D=(e,t,
|
|
3
|
+
@tailwind utilities;`,t)}const D=(e,t,a)=>{const n=JSON.stringify(e).replace(/#styles:([^"]*)/g,(s,o)=>`#styles:${o.replace(/,/g," ")}`.replace(/#styles:/g,""));return A(t,[n],[],"",a)},M=async(e,t=h.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")&&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:o,blocks:i,draft:l,pageProps:g,dataProviderMetadataCallback:k}=e,c=L.getRegisteredChaiBlock(t._type),f=r.get(c,"component",null),y=r.get(e.repeaterData,"index",-1),w=r.get(e.repeaterData,"dataKey",""),P=a===n?"":a,d=p.applyBinding(p.applyLanguage(t,P,c),o,{index:y,key:w}),C=p.getBlockTagAttributes(t),S=K(i,t._id,p.getBlockRuntimeProps(t._type)),v=r.has(c,"dataProvider")&&r.isFunction(c.dataProvider),_={blockProps:{},inBuilder:!1,lang:a||n,...d,...C,...S};if(r.isNull(f))return null;if(v){const T=r.get(c,"suspenseFallback",N);return console.log("Has data provider",t),u.jsx(m.Suspense,{fallback:m.createElement(T),children:u.jsx($,{lang:a,pageProps:g,block:t,dataProvider:c.dataProvider,dataProviderMetadataCallback:k,draft:l,children:({dataProviderProps:B})=>(console.log("data provider",t._id,B),m.createElement(f,{..._,...B,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,{..._,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)),o=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:k,repeaterItemsBinding:c})=>g==="Repeater"?r.isArray(k)&&k.map((f,y)=>u.jsx(b,{...e,parent:i._id,repeaterData:{index:y,dataKey:c}})):o(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,o])=>{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:o.block});return g&&(n[s]=r.get(g,r.get(o,"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=h.getChaiThemeCssVariables;exports.getThemeFontsCSSImport=h.getThemeFontsCSSImport;exports.getThemeFontsLinkMarkup=h.getThemeFontsLinkMarkup;exports.RenderChaiBlocks=V;exports.convertToBlocks=E;exports.getStylesForBlocks=M;
|
package/dist/render.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
import { d as F, c as D } from "./plugin-fnBB3TCm.js";
|
|
2
2
|
import { a as Pe, b as we, e as Be } from "./plugin-fnBB3TCm.js";
|
|
3
|
-
import { a as O, b as $, g as A, c as N, d as
|
|
4
|
-
import { has as k, omit as J, get as g, isFunction as M, isNull as E, isArray as _, filter as
|
|
3
|
+
import { a as O, b as $, g as A, c as N, d as v } from "./new-blocks-render-helpers-BrYtxlrw.js";
|
|
4
|
+
import { has as k, omit as J, get as g, isFunction as M, isNull as E, isArray as _, filter as C, 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";
|
|
8
8
|
import "tailwindcss-animate";
|
|
9
9
|
import { g as q } from "./get-chai-builder-theme-ByeXCyGx.js";
|
|
10
|
-
import { createTailwindcss as
|
|
11
|
-
import
|
|
10
|
+
import { createTailwindcss as H } from "@mhsdesign/jit-browser-tailwindcss";
|
|
11
|
+
import W from "@tailwindcss/container-queries";
|
|
12
12
|
import { jsx as d } from "react/jsx-runtime";
|
|
13
|
-
import { Suspense as
|
|
14
|
-
import { getRegisteredChaiBlock as
|
|
13
|
+
import { Suspense as S, createElement as f } from "react";
|
|
14
|
+
import { getRegisteredChaiBlock as z } from "@chaibuilder/runtime";
|
|
15
15
|
const he = (e) => {
|
|
16
16
|
if (!e) return [];
|
|
17
17
|
try {
|
|
18
|
-
return JSON.parse(
|
|
18
|
+
return JSON.parse(G(e)).filter((a) => !a._type.startsWith("@chai"));
|
|
19
19
|
} catch {
|
|
20
20
|
return [{ _type: "Paragraph", _id: "error", content: "Invalid JSON. Please check the JSON string." }];
|
|
21
21
|
}
|
|
22
22
|
};
|
|
23
|
-
function
|
|
23
|
+
function G(e) {
|
|
24
24
|
const t = /(asset:\/\/|https:\/\/asset\.localhost\/)(?:localhost\/)?[^"']+/g;
|
|
25
25
|
return e.replace(t, (a) => {
|
|
26
26
|
const r = decodeURIComponent(a), i = r.indexOf("public");
|
|
@@ -28,12 +28,12 @@ function H(e) {
|
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
30
|
async function Q(e, t, a = [], r = "", i) {
|
|
31
|
-
return await
|
|
31
|
+
return await H({
|
|
32
32
|
tailwindConfig: {
|
|
33
33
|
darkMode: "class",
|
|
34
34
|
safelist: a,
|
|
35
35
|
theme: { extend: q(e) },
|
|
36
|
-
plugins: [U, V, j,
|
|
36
|
+
plugins: [U, V, j, W, D],
|
|
37
37
|
corePlugins: { preflight: i },
|
|
38
38
|
...r ? { prefix: `${r}` } : {}
|
|
39
39
|
}
|
|
@@ -45,7 +45,7 @@ async function Q(e, t, a = [], r = "", i) {
|
|
|
45
45
|
);
|
|
46
46
|
}
|
|
47
47
|
const X = (e, t, a) => {
|
|
48
|
-
const r = JSON.stringify(e).replace(/#styles:([^"]*)/g, (i,
|
|
48
|
+
const r = JSON.stringify(e).replace(/#styles:([^"]*)/g, (i, s) => `#styles:${s.replace(/,/g, " ")}`.replace(/#styles:/g, ""));
|
|
49
49
|
return Q(t, [r], [], "", a);
|
|
50
50
|
}, ke = async (e, t = F, a = !1) => await X(e, t, a);
|
|
51
51
|
async function Y(e) {
|
|
@@ -61,21 +61,21 @@ async function Y(e) {
|
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
63
|
const Z = () => /* @__PURE__ */ d("div", {}), ee = (e) => {
|
|
64
|
-
const { block: t, lang: a, fallbackLang: r, children: i, externalData:
|
|
64
|
+
const { block: t, lang: a, fallbackLang: r, children: i, externalData: s, blocks: n, draft: o, pageProps: p, dataProviderMetadataCallback: m } = e, l = z(t._type), u = g(l, "component", null), b = g(e.repeaterData, "index", -1), x = g(e.repeaterData, "dataKey", ""), c = O($(t, a === r ? "" : a, l), s, {
|
|
65
65
|
index: b,
|
|
66
|
-
key:
|
|
67
|
-
}),
|
|
66
|
+
key: x
|
|
67
|
+
}), I = A(t), T = te(n, t._id, N(t._type)), L = k(l, "dataProvider") && M(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(
|
|
76
|
+
if (L) {
|
|
77
|
+
const R = g(l, "suspenseFallback", Z);
|
|
78
|
+
return console.log("Has data provider", t), /* @__PURE__ */ d(S, { fallback: f(R), children: /* @__PURE__ */ d(
|
|
79
79
|
Y,
|
|
80
80
|
{
|
|
81
81
|
lang: a,
|
|
@@ -83,46 +83,46 @@ const Z = () => /* @__PURE__ */ d("div", {}), ee = (e) => {
|
|
|
83
83
|
block: t,
|
|
84
84
|
dataProvider: l.dataProvider,
|
|
85
85
|
dataProviderMetadataCallback: m,
|
|
86
|
-
draft:
|
|
87
|
-
children: ({ dataProviderProps:
|
|
86
|
+
draft: o,
|
|
87
|
+
children: ({ dataProviderProps: B }) => (console.log("data provider", t._id, B), f(u, {
|
|
88
88
|
...w,
|
|
89
|
-
...
|
|
89
|
+
...B,
|
|
90
90
|
children: i({
|
|
91
91
|
_id: t._id,
|
|
92
92
|
_type: t._type,
|
|
93
93
|
..._(c.repeaterItems) ? {
|
|
94
|
-
repeaterItems:
|
|
94
|
+
repeaterItems: v(c.repeaterItems, t),
|
|
95
95
|
repeaterItemsBinding: c.repeaterItemsBinding
|
|
96
96
|
} : {}
|
|
97
97
|
})
|
|
98
|
-
})
|
|
98
|
+
}))
|
|
99
99
|
}
|
|
100
100
|
) });
|
|
101
101
|
}
|
|
102
|
-
return /* @__PURE__ */ d(
|
|
102
|
+
return /* @__PURE__ */ d(S, { children: f(u, {
|
|
103
103
|
...w,
|
|
104
104
|
children: i({
|
|
105
105
|
_id: t._id,
|
|
106
106
|
_type: t._type,
|
|
107
107
|
..._(c.repeaterItems) ? {
|
|
108
|
-
repeaterItems:
|
|
108
|
+
repeaterItems: v(c.repeaterItems, t),
|
|
109
109
|
repeaterItemsBinding: c.repeaterItemsBinding
|
|
110
110
|
} : {}
|
|
111
111
|
})
|
|
112
112
|
}) });
|
|
113
113
|
}, P = (e) => {
|
|
114
|
-
const { blocks: t, parent: a, repeaterData: r } = e, i =
|
|
114
|
+
const { blocks: t, parent: a, repeaterData: r } = e, i = C(
|
|
115
115
|
t,
|
|
116
116
|
(n) => k(n, "_id") && (h(a) ? !n._parent : n._parent === a)
|
|
117
|
-
),
|
|
118
|
-
return K(i, (n) => n ? /* @__PURE__ */ f(ee, { ...e, key: n._id, block: n }, ({ _id:
|
|
119
|
-
}, te = (e, t, a) => h(a) ? {} : Object.entries(a).reduce((r, [i,
|
|
117
|
+
), s = (n) => C(t, (o) => o._parent === n).length > 0;
|
|
118
|
+
return K(i, (n) => n ? /* @__PURE__ */ f(ee, { ...e, key: n._id, block: n }, ({ _id: o, _type: p, repeaterItems: m, repeaterItemsBinding: l }) => p === "Repeater" ? _(m) && m.map((u, b) => /* @__PURE__ */ d(P, { ...e, parent: n._id, repeaterData: { index: b, dataKey: l } })) : s(o) ? /* @__PURE__ */ d(P, { ...e, parent: n._id, repeaterData: r }) : null) : null);
|
|
119
|
+
}, te = (e, t, a) => h(a) ? {} : Object.entries(a).reduce((r, [i, s]) => {
|
|
120
120
|
const n = [];
|
|
121
|
-
let
|
|
122
|
-
for (;
|
|
123
|
-
n.push(
|
|
124
|
-
const p = y(n, { _type:
|
|
125
|
-
return p && (r[i] = g(p, g(
|
|
121
|
+
let o = y(e, { _id: t });
|
|
122
|
+
for (; o; )
|
|
123
|
+
n.push(o), o = y(e, { _id: o._parent });
|
|
124
|
+
const p = y(n, { _type: s.block });
|
|
125
|
+
return p && (r[i] = g(p, g(s, "prop"), null)), r;
|
|
126
126
|
}, {});
|
|
127
127
|
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))
|