@chaibuilder/sdk 2.2.13 → 2.2.15
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 +191 -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 +2 -0
- package/dist/render.js +23 -21
- 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 k=require("./plugin-C01tjI6V.cjs"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const k=require("./plugin-C01tjI6V.cjs"),u=require("./new-blocks-render-helpers-DvF4dnjH.cjs"),a=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"),g=require("react/jsx-runtime"),h=require("react"),L=require("@chaibuilder/runtime"),E=e=>{if(!e)return[];try{return JSON.parse(D(e)).filter(r=>!r._type.startsWith("@chai"))}catch{return[{_type:"Paragraph",_id:"error",content:"Invalid JSON. Please check the JSON string."}]}};function D(e){const t=/(asset:\/\/|https:\/\/asset\.localhost\/)(?:localhost\/)?[^"']+/g;return e.replace(t,r=>{const n=decodeURIComponent(r),s=n.indexOf("public");return s!==-1?n.substring(s+6):n})}async function O(e,t,r=[],n="",s){return await F.createTailwindcss({tailwindConfig:{darkMode:"class",safelist:r,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
|
|
3
|
+
@tailwind utilities;`,t)}const A=(e,t,r)=>{const n=JSON.stringify(e).replace(/#styles:([^"]*)/g,(s,c)=>`#styles:${c.replace(/,/g," ")}`.replace(/#styles:/g,""));return O(t,[n],[],"",r)},M=async(e,t=k.defaultThemeOptions,r=!1)=>await A(e,t,r);async function $(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 N=()=>g.jsx("div",{}),J=e=>{const{block:t,lang:r,fallbackLang:n,children:s,externalData:c,blocks:i,draft:l,pageProps:p,dataProviderMetadataCallback:m}=e,o=L.getRegisteredChaiBlock(t._type),f=a.get(o,"component",null),y=a.get(e.repeaterData,"index",-1),P=a.get(e.repeaterData,"dataKey",""),_=r===n?"":r,d=u.applyBinding(u.applyLanguage(t,_,o),c,{index:y,key:P}),w=u.getBlockTagAttributes(t,!1),C=K(i,t._id,u.getBlockRuntimeProps(t._type)),S=a.has(o,"dataProvider")&&a.isFunction(o.dataProvider),B={blockProps:{},inBuilder:!1,lang:r||n,...d,...w,...C};if(a.isNull(f))return null;if(S){const v=a.get(o,"suspenseFallback",N);return g.jsx(h.Suspense,{fallback:h.createElement(v),children:g.jsx($,{lang:r,pageProps:p,block:t,dataProvider:o.dataProvider,...m?{dataProviderMetadataCallback:m}:{},draft:l,children:T=>h.createElement(f,{...B,...T,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(f,{...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:r,repeaterData:n}=e,s=a.filter(t,i=>a.has(i,"_id")&&(a.isEmpty(r)?!i._parent:i._parent===r)),c=i=>a.filter(t,l=>l._parent===i).length>0;return a.map(s,i=>i?h.createElement(J,{...e,key:i._id,block:i},({_id:l,_type:p,repeaterItems:m,repeaterItemsBinding:o})=>p==="Repeater"?a.isArray(m)&&m.map((f,y)=>g.jsx(b,{...e,parent:i._id,repeaterData:{index:y,dataKey:o}})):c(l)?g.jsx(b,{...e,parent:i._id,repeaterData:n}):null):null)},K=(e,t,r)=>a.isEmpty(r)?{}:Object.entries(r).reduce((n,[s,c])=>{const i=[];let l=a.find(e,{_id:t});for(;l;)i.push(l),l=a.find(e,{_id:l._parent});const p=a.find(i,{_type:c.block});return p&&(n[s]=a.get(p,a.get(c,"prop"),null)),n},{});function V(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");const t=e.lang??"en",r=e.fallbackLang??t;return g.jsx(b,{...e,lang:t,fallbackLang:r})}exports.getChaiThemeCssVariables=k.getChaiThemeCssVariables;exports.getThemeFontsCSSImport=k.getThemeFontsCSSImport;exports.getThemeFontsLinkMarkup=k.getThemeFontsLinkMarkup;exports.applyChaiDataBinding=u.applyChaiDataBinding;exports.RenderChaiBlocks=V;exports.convertToBlocks=E;exports.getStylesForBlocks=M;
|
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>> = {
|
package/dist/render.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { d as
|
|
1
|
+
import { d as F, c as O } from "./plugin-fnBB3TCm.js";
|
|
2
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-
|
|
4
|
-
import {
|
|
3
|
+
import { a as $, b as A, g as M, c as N, d as B } from "./new-blocks-render-helpers-DfAVXxr2.js";
|
|
4
|
+
import { e as ve } from "./new-blocks-render-helpers-DfAVXxr2.js";
|
|
5
|
+
import { has as k, isFunction as S, omit as J, get as g, isNull as E, isArray as P, filter as C, isEmpty as h, map as K, find as y } from "lodash-es";
|
|
5
6
|
import j from "@tailwindcss/aspect-ratio";
|
|
6
7
|
import U from "@tailwindcss/forms";
|
|
7
8
|
import V from "@tailwindcss/typography";
|
|
@@ -10,7 +11,7 @@ import { g as q } from "./get-chai-builder-theme-ByeXCyGx.js";
|
|
|
10
11
|
import { createTailwindcss as W } from "@mhsdesign/jit-browser-tailwindcss";
|
|
11
12
|
import z from "@tailwindcss/container-queries";
|
|
12
13
|
import { jsx as d } from "react/jsx-runtime";
|
|
13
|
-
import { Suspense as
|
|
14
|
+
import { Suspense as v, createElement as f } from "react";
|
|
14
15
|
import { getRegisteredChaiBlock as G } from "@chaibuilder/runtime";
|
|
15
16
|
const he = (e) => {
|
|
16
17
|
if (!e) return [];
|
|
@@ -45,9 +46,9 @@ async function Q(e, t, a = [], r = "", i) {
|
|
|
45
46
|
);
|
|
46
47
|
}
|
|
47
48
|
const X = (e, t, a) => {
|
|
48
|
-
const r = JSON.stringify(e).replace(/#styles:([^"]*)/g, (i,
|
|
49
|
+
const r = JSON.stringify(e).replace(/#styles:([^"]*)/g, (i, s) => `#styles:${s.replace(/,/g, " ")}`.replace(/#styles:/g, ""));
|
|
49
50
|
return Q(t, [r], [], "", a);
|
|
50
|
-
}, ke = async (e, t =
|
|
51
|
+
}, ke = async (e, t = F, a = !1) => await X(e, t, a);
|
|
51
52
|
async function Y(e) {
|
|
52
53
|
const t = await e.dataProvider({
|
|
53
54
|
pageProps: e.pageProps,
|
|
@@ -61,7 +62,7 @@ async function Y(e) {
|
|
|
61
62
|
});
|
|
62
63
|
}
|
|
63
64
|
const Z = () => /* @__PURE__ */ d("div", {}), ee = (e) => {
|
|
64
|
-
const { block: t, lang: a, fallbackLang: r, children: i, externalData:
|
|
65
|
+
const { block: t, lang: a, fallbackLang: r, children: i, externalData: s, blocks: n, draft: o, 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), s, {
|
|
65
66
|
index: b,
|
|
66
67
|
key: x
|
|
67
68
|
}), I = M(t, !1), T = te(n, t._id, N(t._type)), L = k(l, "dataProvider") && S(l.dataProvider), w = {
|
|
@@ -75,7 +76,7 @@ const Z = () => /* @__PURE__ */ d("div", {}), ee = (e) => {
|
|
|
75
76
|
if (E(u)) return null;
|
|
76
77
|
if (L) {
|
|
77
78
|
const R = g(l, "suspenseFallback", Z);
|
|
78
|
-
return /* @__PURE__ */ d(
|
|
79
|
+
return /* @__PURE__ */ d(v, { fallback: f(R), children: /* @__PURE__ */ d(
|
|
79
80
|
Y,
|
|
80
81
|
{
|
|
81
82
|
lang: a,
|
|
@@ -83,10 +84,10 @@ const Z = () => /* @__PURE__ */ d("div", {}), ee = (e) => {
|
|
|
83
84
|
block: t,
|
|
84
85
|
dataProvider: l.dataProvider,
|
|
85
86
|
...m ? { dataProviderMetadataCallback: m } : {},
|
|
86
|
-
draft:
|
|
87
|
-
children: (
|
|
87
|
+
draft: o,
|
|
88
|
+
children: (D) => f(u, {
|
|
88
89
|
...w,
|
|
89
|
-
...
|
|
90
|
+
...D,
|
|
90
91
|
children: i({
|
|
91
92
|
_id: t._id,
|
|
92
93
|
_type: t._type,
|
|
@@ -99,7 +100,7 @@ const Z = () => /* @__PURE__ */ d("div", {}), ee = (e) => {
|
|
|
99
100
|
}
|
|
100
101
|
) });
|
|
101
102
|
}
|
|
102
|
-
return /* @__PURE__ */ d(
|
|
103
|
+
return /* @__PURE__ */ d(v, { children: f(u, {
|
|
103
104
|
...w,
|
|
104
105
|
children: i({
|
|
105
106
|
_id: t._id,
|
|
@@ -111,18 +112,18 @@ const Z = () => /* @__PURE__ */ d("div", {}), ee = (e) => {
|
|
|
111
112
|
})
|
|
112
113
|
}) });
|
|
113
114
|
}, _ = (e) => {
|
|
114
|
-
const { blocks: t, parent: a, repeaterData: r } = e, i =
|
|
115
|
+
const { blocks: t, parent: a, repeaterData: r } = e, i = C(
|
|
115
116
|
t,
|
|
116
117
|
(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,
|
|
118
|
+
), s = (n) => C(t, (o) => o._parent === n).length > 0;
|
|
119
|
+
return K(i, (n) => n ? /* @__PURE__ */ f(ee, { ...e, key: n._id, block: n }, ({ _id: o, _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 } })) : s(o) ? /* @__PURE__ */ d(_, { ...e, parent: n._id, repeaterData: r }) : null) : null);
|
|
120
|
+
}, te = (e, t, a) => h(a) ? {} : Object.entries(a).reduce((r, [i, s]) => {
|
|
120
121
|
const n = [];
|
|
121
|
-
let
|
|
122
|
-
for (;
|
|
123
|
-
n.push(
|
|
124
|
-
const p = y(n, { _type:
|
|
125
|
-
return p && (r[i] = g(p, g(
|
|
122
|
+
let o = y(e, { _id: t });
|
|
123
|
+
for (; o; )
|
|
124
|
+
n.push(o), o = y(e, { _id: o._parent });
|
|
125
|
+
const p = y(n, { _type: s.block });
|
|
126
|
+
return p && (r[i] = g(p, g(s, "prop"), null)), r;
|
|
126
127
|
}, {});
|
|
127
128
|
function be(e) {
|
|
128
129
|
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))
|
|
@@ -132,6 +133,7 @@ function be(e) {
|
|
|
132
133
|
}
|
|
133
134
|
export {
|
|
134
135
|
be as RenderChaiBlocks,
|
|
136
|
+
ve as applyChaiDataBinding,
|
|
135
137
|
he as convertToBlocks,
|
|
136
138
|
_e as getChaiThemeCssVariables,
|
|
137
139
|
ke as getStylesForBlocks,
|
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;
|