@chaibuilder/sdk 2.2.14 → 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/core.cjs +4 -4
- package/dist/core.js +169 -169
- package/dist/new-blocks-render-helpers-DfAVXxr2.js +126 -0
- package/dist/new-blocks-render-helpers-DvF4dnjH.cjs +1 -0
- package/dist/render.cjs +2 -2
- package/dist/render.d.ts +4 -0
- package/dist/render.js +92 -73
- package/package.json +1 -1
- package/dist/new-blocks-render-helpers-BGcG63he.js +0 -111
- package/dist/new-blocks-render-helpers-DRQ8Buz8.cjs +0 -1
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { getRegisteredChaiBlock as O } from "@chaibuilder/runtime";
|
|
2
|
+
import { memoize as $, get as c, cloneDeep as m, forEach as u, keys as C, isString as _, startsWith as f, isArray as h, isEmpty as d, includes as R } from "lodash-es";
|
|
3
|
+
import { twMerge as x } from "tailwind-merge";
|
|
4
|
+
const E = "#styles:", j = "__ADD_BLOCK_INTERNAL_ROOT", B = (s) => {
|
|
5
|
+
if (s = s.replace(E, ""), !s) return { baseClasses: "", classes: "" };
|
|
6
|
+
const t = s.split(/,(?![^\[]*\])/);
|
|
7
|
+
if (t.length === 1)
|
|
8
|
+
return { baseClasses: "", classes: t[0].trim() };
|
|
9
|
+
const [a, ...e] = t;
|
|
10
|
+
return {
|
|
11
|
+
baseClasses: a.trim(),
|
|
12
|
+
classes: e.join(",").trim().replace(/ +(?= )/g, "")
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
import.meta.vitest && describe("getSplitChaiClasses", () => {
|
|
16
|
+
it("should return the base classes and the classes", () => {
|
|
17
|
+
const s = {
|
|
18
|
+
",styles-2": { baseClasses: "", classes: "styles-2" },
|
|
19
|
+
"styles-1,styles-2": { baseClasses: "styles-1", classes: "styles-2" },
|
|
20
|
+
",bg-[linear-gradient(-10deg,black,transparent_100%)]": {
|
|
21
|
+
baseClasses: "",
|
|
22
|
+
classes: "bg-[linear-gradient(-10deg,black,transparent_100%)]"
|
|
23
|
+
},
|
|
24
|
+
"styles-1,bg-[linear-gradient(-10deg,black,transparent_100%)]": {
|
|
25
|
+
baseClasses: "styles-1",
|
|
26
|
+
classes: "bg-[linear-gradient(-10deg,black,transparent_100%)]"
|
|
27
|
+
},
|
|
28
|
+
someclass: {
|
|
29
|
+
baseClasses: "",
|
|
30
|
+
classes: "someclass"
|
|
31
|
+
},
|
|
32
|
+
",bg-red-500 text-center font-bold": {
|
|
33
|
+
baseClasses: "",
|
|
34
|
+
classes: "bg-red-500 text-center font-bold"
|
|
35
|
+
},
|
|
36
|
+
"bg-[linear-gradient(-10deg,black,transparent_100%)], bg-[linear-gradient(-10deg,black,transparent_100%)]": {
|
|
37
|
+
baseClasses: "bg-[linear-gradient(-10deg,black,transparent_100%)]",
|
|
38
|
+
classes: "bg-[linear-gradient(-10deg,black,transparent_100%)]"
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
for (let t in s) {
|
|
42
|
+
const a = B(`${E}${t}`);
|
|
43
|
+
expect(a).toEqual(s[t]);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
function D(s, t, a) {
|
|
48
|
+
const e = c(a, "i18nProps", []);
|
|
49
|
+
if (d(t) || d(e)) return s;
|
|
50
|
+
const r = m(s);
|
|
51
|
+
return u(C(r), (n) => {
|
|
52
|
+
R(e, n) && !d(t) && (r[n] = c(r, `${n}-${t}`, r[n]));
|
|
53
|
+
}), r;
|
|
54
|
+
}
|
|
55
|
+
const N = (s, t, { index: a, key: e }) => {
|
|
56
|
+
const r = m(s);
|
|
57
|
+
return u(C(r), (n) => {
|
|
58
|
+
if (_(r[n]) && !f(n, "_")) {
|
|
59
|
+
let i = r[n];
|
|
60
|
+
n === "repeaterItems" && (r.repeaterItemsBinding = i);
|
|
61
|
+
const o = /\{\{(.*?)\}\}/g, g = i.match(o);
|
|
62
|
+
g && g.forEach((l) => {
|
|
63
|
+
let p = l.slice(2, -2);
|
|
64
|
+
a !== -1 && e !== "" && f(p, "$index.") && (p = `${e.replace(/\{\{(.*)\}\}/g, "$1")}.${p.replace("$index", `${a}`)}`);
|
|
65
|
+
const b = c(t, p, l);
|
|
66
|
+
i = h(b) ? b : i.replace(l, b);
|
|
67
|
+
}), r[n] = i;
|
|
68
|
+
}
|
|
69
|
+
}), r;
|
|
70
|
+
}, T = $((s) => {
|
|
71
|
+
const { baseClasses: t, classes: a } = B(s);
|
|
72
|
+
return x(t, a);
|
|
73
|
+
});
|
|
74
|
+
function v(s, t) {
|
|
75
|
+
return c(s, `${t}_attrs`, {});
|
|
76
|
+
}
|
|
77
|
+
function P(s, t = !0) {
|
|
78
|
+
const a = {};
|
|
79
|
+
return Object.keys(s).forEach((e) => {
|
|
80
|
+
if (_(s[e]) && s[e].startsWith(E)) {
|
|
81
|
+
const r = T(s[e]), n = v(s, e);
|
|
82
|
+
a[e] = {
|
|
83
|
+
...!d(r) && { className: r },
|
|
84
|
+
...n,
|
|
85
|
+
...t ? {
|
|
86
|
+
"data-style-prop": e,
|
|
87
|
+
"data-block-parent": s._id,
|
|
88
|
+
"data-style-id": `${e}-${s._id}`
|
|
89
|
+
} : {}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
}), a;
|
|
93
|
+
}
|
|
94
|
+
const L = $((s) => {
|
|
95
|
+
const t = O(s), a = c(t, "schema.properties", {});
|
|
96
|
+
return Object.fromEntries(Object.entries(a).filter(([, e]) => c(e, "runtime", !1)));
|
|
97
|
+
}), M = (s, t) => {
|
|
98
|
+
if (!h(s)) return s;
|
|
99
|
+
let a = s, e;
|
|
100
|
+
return typeof t.limit == "number" && t.limit > 0 && (e = t.limit), e !== void 0 && (a = a.slice(0, e)), a;
|
|
101
|
+
}, S = (s, t) => {
|
|
102
|
+
const a = m(s);
|
|
103
|
+
return u(C(a), (e) => {
|
|
104
|
+
if (_(a[e]) && !f(e, "_")) {
|
|
105
|
+
let r = a[e];
|
|
106
|
+
e === "repeaterItems" && (a.repeaterItemsBinding = r);
|
|
107
|
+
const n = /\{\{(.*?)\}\}/g, i = r.match(n);
|
|
108
|
+
i && i.forEach((o) => {
|
|
109
|
+
let g = o.slice(2, -2);
|
|
110
|
+
const l = c(t, g, o);
|
|
111
|
+
r = h(l) ? l : r.replace(o, l);
|
|
112
|
+
}), a[e] = r;
|
|
113
|
+
}
|
|
114
|
+
}), a;
|
|
115
|
+
};
|
|
116
|
+
export {
|
|
117
|
+
j as R,
|
|
118
|
+
E as S,
|
|
119
|
+
N as a,
|
|
120
|
+
D as b,
|
|
121
|
+
L as c,
|
|
122
|
+
M as d,
|
|
123
|
+
S as e,
|
|
124
|
+
B as f,
|
|
125
|
+
P as g
|
|
126
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const f=require("@chaibuilder/runtime"),e=require("lodash-es"),m=require("tailwind-merge"),u="#styles:",C="__ADD_BLOCK_INTERNAL_ROOT",b=s=>{if(s=s.replace(u,""),!s)return{baseClasses:"",classes:""};const i=s.split(/,(?![^\[]*\])/);if(i.length===1)return{baseClasses:"",classes:i[0].trim()};const[a,...t]=i;return{baseClasses:a.trim(),classes:t.join(",").trim().replace(/ +(?= )/g,"")}};function E(s,i,a){const t=e.get(a,"i18nProps",[]);if(e.isEmpty(i)||e.isEmpty(t))return s;const n=e.cloneDeep(s);return e.forEach(e.keys(n),r=>{e.includes(t,r)&&!e.isEmpty(i)&&(n[r]=e.get(n,`${r}-${i}`,n[r]))}),n}const h=(s,i,{index:a,key:t})=>{const n=e.cloneDeep(s);return e.forEach(e.keys(n),r=>{if(e.isString(n[r])&&!e.startsWith(r,"_")){let l=n[r];r==="repeaterItems"&&(n.repeaterItemsBinding=l);const g=/\{\{(.*?)\}\}/g,o=l.match(g);o&&o.forEach(c=>{let p=c.slice(2,-2);a!==-1&&t!==""&&e.startsWith(p,"$index.")&&(p=`${t.replace(/\{\{(.*)\}\}/g,"$1")}.${p.replace("$index",`${a}`)}`);const d=e.get(i,p,c);l=e.isArray(d)?d:l.replace(c,d)}),n[r]=l}}),n},_=e.memoize(s=>{const{baseClasses:i,classes:a}=b(s);return m.twMerge(i,a)});function y(s,i){return e.get(s,`${i}_attrs`,{})}function B(s,i=!0){const a={};return Object.keys(s).forEach(t=>{if(e.isString(s[t])&&s[t].startsWith(u)){const n=_(s[t]),r=y(s,t);a[t]={...!e.isEmpty(n)&&{className:n},...r,...i?{"data-style-prop":t,"data-block-parent":s._id,"data-style-id":`${t}-${s._id}`}:{}}}}),a}const $=e.memoize(s=>{const i=f.getRegisteredChaiBlock(s),a=e.get(i,"schema.properties",{});return Object.fromEntries(Object.entries(a).filter(([,t])=>e.get(t,"runtime",!1)))}),T=(s,i)=>{if(!e.isArray(s))return s;let a=s,t;return typeof i.limit=="number"&&i.limit>0&&(t=i.limit),t!==void 0&&(a=a.slice(0,t)),a},O=(s,i)=>{const a=e.cloneDeep(s);return e.forEach(e.keys(a),t=>{if(e.isString(a[t])&&!e.startsWith(t,"_")){let n=a[t];t==="repeaterItems"&&(a.repeaterItemsBinding=n);const r=/\{\{(.*?)\}\}/g,l=n.match(r);l&&l.forEach(g=>{let o=g.slice(2,-2);const c=e.get(i,o,g);n=e.isArray(c)?c:n.replace(g,c)}),a[t]=n}}),a};exports.ROOT_TEMP_KEY=C;exports.STYLES_KEY=u;exports.applyBinding=h;exports.applyChaiDataBinding=O;exports.applyLanguage=E;exports.applyLimit=T;exports.getBlockRuntimeProps=$;exports.getBlockTagAttributes=B;exports.getSplitChaiClasses=b;
|
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
|
|
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
|
@@ -2,6 +2,8 @@ import { ChaiFontViaUrl } from '@chaibuilder/runtime';
|
|
|
2
2
|
import { ChaiPageProps } from '@chaibuilder/runtime';
|
|
3
3
|
import { JSX as JSX_2 } from 'react/jsx-runtime';
|
|
4
4
|
|
|
5
|
+
export declare const applyChaiDataBinding: (block: Record<string, string>, pageExternalData: Record<string, any>) => any;
|
|
6
|
+
|
|
5
7
|
declare type BorderRadiusValue = false | string;
|
|
6
8
|
|
|
7
9
|
declare type ChaiBlock<T = Record<string, any>> = {
|
|
@@ -60,6 +62,8 @@ export declare const convertToBlocks: (chaiFormatContent: string) => ChaiBlock[]
|
|
|
60
62
|
|
|
61
63
|
export declare const getChaiThemeCssVariables: (chaiTheme: ChaiThemeValues) => string;
|
|
62
64
|
|
|
65
|
+
export declare function getMergedPartialBlocks(blocks: ChaiBlock[], partials: Record<string, ChaiBlock[]>): ChaiBlock[];
|
|
66
|
+
|
|
63
67
|
/**
|
|
64
68
|
* Get the tailwind css for the blocks
|
|
65
69
|
* @param blocks - The blocks to get the tailwind css for
|
package/dist/render.js
CHANGED
|
@@ -1,39 +1,52 @@
|
|
|
1
|
-
import { d as
|
|
2
|
-
import { a as
|
|
3
|
-
import { a as
|
|
4
|
-
import {
|
|
5
|
-
import j from "
|
|
6
|
-
import U from "@tailwindcss/
|
|
7
|
-
import V from "@tailwindcss/
|
|
1
|
+
import { d as F, c as O } from "./plugin-fnBB3TCm.js";
|
|
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";
|
|
8
9
|
import "tailwindcss-animate";
|
|
9
|
-
import { g as
|
|
10
|
-
import { createTailwindcss as
|
|
11
|
-
import
|
|
12
|
-
import { jsx as
|
|
13
|
-
import { Suspense as
|
|
14
|
-
import { getRegisteredChaiBlock as
|
|
15
|
-
|
|
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) => {
|
|
16
29
|
if (!e) return [];
|
|
17
30
|
try {
|
|
18
|
-
return JSON.parse(
|
|
31
|
+
return JSON.parse(X(e)).filter((a) => !a._type.startsWith("@chai"));
|
|
19
32
|
} catch {
|
|
20
33
|
return [{ _type: "Paragraph", _id: "error", content: "Invalid JSON. Please check the JSON string." }];
|
|
21
34
|
}
|
|
22
35
|
};
|
|
23
|
-
function
|
|
36
|
+
function X(e) {
|
|
24
37
|
const t = /(asset:\/\/|https:\/\/asset\.localhost\/)(?:localhost\/)?[^"']+/g;
|
|
25
38
|
return e.replace(t, (a) => {
|
|
26
39
|
const r = decodeURIComponent(a), i = r.indexOf("public");
|
|
27
40
|
return i !== -1 ? r.substring(i + 6) : r;
|
|
28
41
|
});
|
|
29
42
|
}
|
|
30
|
-
async function
|
|
31
|
-
return await
|
|
43
|
+
async function Y(e, t, a = [], r = "", i) {
|
|
44
|
+
return await z({
|
|
32
45
|
tailwindConfig: {
|
|
33
46
|
darkMode: "class",
|
|
34
47
|
safelist: a,
|
|
35
|
-
theme: { extend:
|
|
36
|
-
plugins: [
|
|
48
|
+
theme: { extend: W(e) },
|
|
49
|
+
plugins: [V, G, U, H, O],
|
|
37
50
|
corePlugins: { preflight: i },
|
|
38
51
|
...r ? { prefix: `${r}` } : {}
|
|
39
52
|
}
|
|
@@ -44,11 +57,11 @@ async function Q(e, t, a = [], r = "", i) {
|
|
|
44
57
|
t
|
|
45
58
|
);
|
|
46
59
|
}
|
|
47
|
-
const
|
|
48
|
-
const r = JSON.stringify(e).replace(/#styles:([^"]*)/g, (i,
|
|
49
|
-
return
|
|
50
|
-
},
|
|
51
|
-
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) {
|
|
52
65
|
const t = await e.dataProvider({
|
|
53
66
|
pageProps: e.pageProps,
|
|
54
67
|
block: e.block,
|
|
@@ -56,85 +69,91 @@ async function Y(e) {
|
|
|
56
69
|
draft: e.draft,
|
|
57
70
|
inBuilder: !1
|
|
58
71
|
});
|
|
59
|
-
return k(t, "$metadata") &&
|
|
60
|
-
...
|
|
72
|
+
return k(t, "$metadata") && x(e.dataProviderMetadataCallback) && e.dataProviderMetadataCallback(e.block, t.$metadata), e.children({
|
|
73
|
+
...E(t, "$metadata")
|
|
61
74
|
});
|
|
62
75
|
}
|
|
63
|
-
const
|
|
64
|
-
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, {
|
|
65
78
|
index: b,
|
|
66
|
-
key:
|
|
67
|
-
}), 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 = {
|
|
68
81
|
blockProps: {},
|
|
69
82
|
inBuilder: !1,
|
|
70
83
|
lang: a || r,
|
|
71
|
-
...
|
|
84
|
+
...d,
|
|
72
85
|
...I,
|
|
73
|
-
...
|
|
86
|
+
...L
|
|
74
87
|
};
|
|
75
|
-
if (
|
|
76
|
-
if (
|
|
77
|
-
const
|
|
78
|
-
return /* @__PURE__ */
|
|
79
|
-
|
|
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,
|
|
80
93
|
{
|
|
81
94
|
lang: a,
|
|
82
|
-
pageProps:
|
|
95
|
+
pageProps: g,
|
|
83
96
|
block: t,
|
|
84
|
-
dataProvider:
|
|
85
|
-
...
|
|
86
|
-
draft:
|
|
87
|
-
children: (
|
|
88
|
-
...
|
|
89
|
-
...
|
|
97
|
+
dataProvider: c.dataProvider,
|
|
98
|
+
...u ? { dataProviderMetadataCallback: u } : {},
|
|
99
|
+
draft: o,
|
|
100
|
+
children: (R) => h(f, {
|
|
101
|
+
...P,
|
|
102
|
+
...R,
|
|
90
103
|
children: i({
|
|
91
104
|
_id: t._id,
|
|
92
105
|
_type: t._type,
|
|
93
|
-
...
|
|
94
|
-
repeaterItems:
|
|
95
|
-
repeaterItemsBinding:
|
|
106
|
+
...B(d.repeaterItems) ? {
|
|
107
|
+
repeaterItems: w(d.repeaterItems, t),
|
|
108
|
+
repeaterItemsBinding: d.repeaterItemsBinding
|
|
96
109
|
} : {}
|
|
97
110
|
})
|
|
98
111
|
})
|
|
99
112
|
}
|
|
100
113
|
) });
|
|
101
114
|
}
|
|
102
|
-
return /* @__PURE__ */
|
|
103
|
-
...
|
|
115
|
+
return /* @__PURE__ */ p(v, { children: h(f, {
|
|
116
|
+
...P,
|
|
104
117
|
children: i({
|
|
105
118
|
_id: t._id,
|
|
106
119
|
_type: t._type,
|
|
107
|
-
...
|
|
108
|
-
repeaterItems:
|
|
109
|
-
repeaterItemsBinding:
|
|
120
|
+
...B(d.repeaterItems) ? {
|
|
121
|
+
repeaterItems: w(d.repeaterItems, t),
|
|
122
|
+
repeaterItemsBinding: d.repeaterItemsBinding
|
|
110
123
|
} : {}
|
|
111
124
|
})
|
|
112
125
|
}) });
|
|
113
126
|
}, _ = (e) => {
|
|
114
|
-
const { blocks: t, parent: a, repeaterData: r } = e
|
|
115
|
-
|
|
116
|
-
(n) => k(n, "_id") && (
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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]) => {
|
|
120
135
|
const n = [];
|
|
121
|
-
let
|
|
122
|
-
for (;
|
|
123
|
-
n.push(
|
|
124
|
-
const
|
|
125
|
-
return
|
|
136
|
+
let o = y(e, { _id: t });
|
|
137
|
+
for (; o; )
|
|
138
|
+
n.push(o), o = y(e, { _id: o._parent });
|
|
139
|
+
const g = y(n, { _type: l.block });
|
|
140
|
+
return g && (r[i] = s(g, s(l, "prop"), null)), r;
|
|
126
141
|
}, {});
|
|
127
|
-
function
|
|
128
|
-
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))
|
|
129
144
|
throw new Error("lang prop is required when fallbackLang is provided");
|
|
145
|
+
if (m(e.blocks))
|
|
146
|
+
return null;
|
|
130
147
|
const t = e.lang ?? "en", a = e.fallbackLang ?? t;
|
|
131
|
-
return /* @__PURE__ */
|
|
148
|
+
return /* @__PURE__ */ p(_, { ...e, lang: t, fallbackLang: a });
|
|
132
149
|
}
|
|
133
150
|
export {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
Be as
|
|
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
|
|
140
159
|
};
|
package/package.json
CHANGED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { getRegisteredChaiBlock as B } from "@chaibuilder/runtime";
|
|
2
|
-
import { memoize as f, get as i, isEmpty as o, cloneDeep as u, forEach as C, keys as _, includes as O, isString as h, startsWith as m, isArray as $ } from "lodash-es";
|
|
3
|
-
import { twMerge as R } from "tailwind-merge";
|
|
4
|
-
const d = "#styles:", N = "__ADD_BLOCK_INTERNAL_ROOT", E = (s) => {
|
|
5
|
-
if (s = s.replace(d, ""), !s) return { baseClasses: "", classes: "" };
|
|
6
|
-
const e = s.split(/,(?![^\[]*\])/);
|
|
7
|
-
if (e.length === 1)
|
|
8
|
-
return { baseClasses: "", classes: e[0].trim() };
|
|
9
|
-
const [a, ...t] = e;
|
|
10
|
-
return {
|
|
11
|
-
baseClasses: a.trim(),
|
|
12
|
-
classes: t.join(",").trim().replace(/ +(?= )/g, "")
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
import.meta.vitest && describe("getSplitChaiClasses", () => {
|
|
16
|
-
it("should return the base classes and the classes", () => {
|
|
17
|
-
const s = {
|
|
18
|
-
",styles-2": { baseClasses: "", classes: "styles-2" },
|
|
19
|
-
"styles-1,styles-2": { baseClasses: "styles-1", classes: "styles-2" },
|
|
20
|
-
",bg-[linear-gradient(-10deg,black,transparent_100%)]": {
|
|
21
|
-
baseClasses: "",
|
|
22
|
-
classes: "bg-[linear-gradient(-10deg,black,transparent_100%)]"
|
|
23
|
-
},
|
|
24
|
-
"styles-1,bg-[linear-gradient(-10deg,black,transparent_100%)]": {
|
|
25
|
-
baseClasses: "styles-1",
|
|
26
|
-
classes: "bg-[linear-gradient(-10deg,black,transparent_100%)]"
|
|
27
|
-
},
|
|
28
|
-
someclass: {
|
|
29
|
-
baseClasses: "",
|
|
30
|
-
classes: "someclass"
|
|
31
|
-
},
|
|
32
|
-
",bg-red-500 text-center font-bold": {
|
|
33
|
-
baseClasses: "",
|
|
34
|
-
classes: "bg-red-500 text-center font-bold"
|
|
35
|
-
},
|
|
36
|
-
"bg-[linear-gradient(-10deg,black,transparent_100%)], bg-[linear-gradient(-10deg,black,transparent_100%)]": {
|
|
37
|
-
baseClasses: "bg-[linear-gradient(-10deg,black,transparent_100%)]",
|
|
38
|
-
classes: "bg-[linear-gradient(-10deg,black,transparent_100%)]"
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
for (let e in s) {
|
|
42
|
-
const a = E(`${d}${e}`);
|
|
43
|
-
expect(a).toEqual(s[e]);
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
function P(s, e, a) {
|
|
48
|
-
const t = i(a, "i18nProps", []);
|
|
49
|
-
if (o(e) || o(t)) return s;
|
|
50
|
-
const r = u(s);
|
|
51
|
-
return C(_(r), (n) => {
|
|
52
|
-
O(t, n) && !o(e) && (r[n] = i(r, `${n}-${e}`, r[n]));
|
|
53
|
-
}), r;
|
|
54
|
-
}
|
|
55
|
-
const D = (s, e, { index: a, key: t }) => {
|
|
56
|
-
const r = u(s);
|
|
57
|
-
return C(_(r), (n) => {
|
|
58
|
-
if (h(r[n]) && !m(n, "_")) {
|
|
59
|
-
let l = r[n];
|
|
60
|
-
n === "repeaterItems" && (r.repeaterItemsBinding = l);
|
|
61
|
-
const y = /\{\{(.*?)\}\}/g, b = l.match(y);
|
|
62
|
-
b && b.forEach((g) => {
|
|
63
|
-
let c = g.slice(2, -2);
|
|
64
|
-
a !== -1 && t !== "" && m(c, "$index.") && (c = `${t.replace(/\{\{(.*)\}\}/g, "$1")}.${c.replace("$index", `${a}`)}`);
|
|
65
|
-
const p = i(e, c, g);
|
|
66
|
-
l = $(p) ? p : l.replace(g, p);
|
|
67
|
-
}), r[n] = l;
|
|
68
|
-
}
|
|
69
|
-
}), r;
|
|
70
|
-
}, x = f((s) => {
|
|
71
|
-
const { baseClasses: e, classes: a } = E(s);
|
|
72
|
-
return R(e, a);
|
|
73
|
-
});
|
|
74
|
-
function T(s, e) {
|
|
75
|
-
return i(s, `${e}_attrs`, {});
|
|
76
|
-
}
|
|
77
|
-
function I(s, e = !0) {
|
|
78
|
-
const a = {};
|
|
79
|
-
return Object.keys(s).forEach((t) => {
|
|
80
|
-
if (h(s[t]) && s[t].startsWith(d)) {
|
|
81
|
-
const r = x(s[t]), n = T(s, t);
|
|
82
|
-
a[t] = {
|
|
83
|
-
...!o(r) && { className: r },
|
|
84
|
-
...n,
|
|
85
|
-
...e ? {
|
|
86
|
-
"data-style-prop": t,
|
|
87
|
-
"data-block-parent": s._id,
|
|
88
|
-
"data-style-id": `${t}-${s._id}`
|
|
89
|
-
} : {}
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
}), a;
|
|
93
|
-
}
|
|
94
|
-
const L = f((s) => {
|
|
95
|
-
const e = B(s), a = i(e, "schema.properties", {});
|
|
96
|
-
return Object.fromEntries(Object.entries(a).filter(([, t]) => i(t, "runtime", !1)));
|
|
97
|
-
}), M = (s, e) => {
|
|
98
|
-
if (!$(s)) return s;
|
|
99
|
-
let a = s, t;
|
|
100
|
-
return typeof e.limit == "number" && e.limit > 0 && (t = e.limit), t !== void 0 && (a = a.slice(0, t)), a;
|
|
101
|
-
};
|
|
102
|
-
export {
|
|
103
|
-
N as R,
|
|
104
|
-
d as S,
|
|
105
|
-
D as a,
|
|
106
|
-
P as b,
|
|
107
|
-
L as c,
|
|
108
|
-
M as d,
|
|
109
|
-
E as e,
|
|
110
|
-
I as g
|
|
111
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const m=require("@chaibuilder/runtime"),e=require("lodash-es"),f=require("tailwind-merge"),p="#styles:",C="__ADD_BLOCK_INTERNAL_ROOT",u=s=>{if(s=s.replace(p,""),!s)return{baseClasses:"",classes:""};const t=s.split(/,(?![^\[]*\])/);if(t.length===1)return{baseClasses:"",classes:t[0].trim()};const[r,...a]=t;return{baseClasses:r.trim(),classes:a.join(",").trim().replace(/ +(?= )/g,"")}};function E(s,t,r){const a=e.get(r,"i18nProps",[]);if(e.isEmpty(t)||e.isEmpty(a))return s;const n=e.cloneDeep(s);return e.forEach(e.keys(n),i=>{e.includes(a,i)&&!e.isEmpty(t)&&(n[i]=e.get(n,`${i}-${t}`,n[i]))}),n}const _=(s,t,{index:r,key:a})=>{const n=e.cloneDeep(s);return e.forEach(e.keys(n),i=>{if(e.isString(n[i])&&!e.startsWith(i,"_")){let l=n[i];i==="repeaterItems"&&(n.repeaterItemsBinding=l);const b=/\{\{(.*?)\}\}/g,d=l.match(b);d&&d.forEach(g=>{let c=g.slice(2,-2);r!==-1&&a!==""&&e.startsWith(c,"$index.")&&(c=`${a.replace(/\{\{(.*)\}\}/g,"$1")}.${c.replace("$index",`${r}`)}`);const o=e.get(t,c,g);l=e.isArray(o)?o:l.replace(g,o)}),n[i]=l}}),n},h=e.memoize(s=>{const{baseClasses:t,classes:r}=u(s);return f.twMerge(t,r)});function y(s,t){return e.get(s,`${t}_attrs`,{})}function $(s,t=!0){const r={};return Object.keys(s).forEach(a=>{if(e.isString(s[a])&&s[a].startsWith(p)){const n=h(s[a]),i=y(s,a);r[a]={...!e.isEmpty(n)&&{className:n},...i,...t?{"data-style-prop":a,"data-block-parent":s._id,"data-style-id":`${a}-${s._id}`}:{}}}}),r}const B=e.memoize(s=>{const t=m.getRegisteredChaiBlock(s),r=e.get(t,"schema.properties",{});return Object.fromEntries(Object.entries(r).filter(([,a])=>e.get(a,"runtime",!1)))}),T=(s,t)=>{if(!e.isArray(s))return s;let r=s,a;return typeof t.limit=="number"&&t.limit>0&&(a=t.limit),a!==void 0&&(r=r.slice(0,a)),r};exports.ROOT_TEMP_KEY=C;exports.STYLES_KEY=p;exports.applyBinding=_;exports.applyLanguage=E;exports.applyLimit=T;exports.getBlockRuntimeProps=B;exports.getBlockTagAttributes=$;exports.getSplitChaiClasses=u;
|