@chaibuilder/sdk 2.6.2 → 2.6.3

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 CHANGED
@@ -1,3 +1,3 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("./plugin-CSgw-f78.cjs"),p=require("./apply-binding-T3HdSezj.cjs"),t=require("lodash-es"),I=require("@tailwindcss/aspect-ratio"),q=require("@tailwindcss/forms"),$=require("@tailwindcss/typography");require("tailwindcss-animate");const E=require("./get-chai-builder-theme-B1tr_NJB.cjs"),F=require("@mhsdesign/jit-browser-tailwindcss"),L=require("@tailwindcss/container-queries"),m=require("react/jsx-runtime"),u=require("react"),R=require("@chaibuilder/runtime");function D(e,r){const a=e.filter(({_type:i})=>i==="GlobalBlock"||i==="PartialBlock");for(let i=0;i<a.length;i++){const l=a[i],s=t.get(l,"partialBlockId",t.get(l,"globalBlock",""));if(s==="")continue;let n=t.cloneDeep(t.get(r,s,[]));l._parent&&(n==null?void 0:n.length)>0&&(n=n.map(c=>(t.isEmpty(c._parent)&&(c._parent=l._parent),c)));const o=e.indexOf(l);e.splice(o,1,...n)}return e}const j=e=>{if(!e)return[];try{return JSON.parse(M(e)).filter(a=>!a._type.startsWith("@chai"))}catch{return[{_type:"Paragraph",_id:"error",content:"Invalid JSON. Please check the JSON string."}]}};function M(e){const r=/(asset:\/\/|https:\/\/asset\.localhost\/)(?:localhost\/)?[^"']+/g;return e.replace(r,a=>{const i=decodeURIComponent(a),l=i.indexOf("public");return l!==-1?i.substring(l+6):i})}async function O(e,r,a=[],i="",l){return await F.createTailwindcss({tailwindConfig:{darkMode:"class",safelist:a,theme:{extend:E.getChaiBuilderTheme(e)},plugins:[q,$,I,L,y.chaiBuilderPlugin],corePlugins:{preflight:l},...i?{prefix:`${i}`}:{}}}).generateStylesFromContent(` ${l?"@tailwind base;":""}
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const k=require("./plugin-CSgw-f78.cjs"),u=require("./apply-binding-CxkQxWx3.cjs"),t=require("lodash-es"),I=require("@tailwindcss/aspect-ratio"),q=require("@tailwindcss/forms"),$=require("@tailwindcss/typography");require("tailwindcss-animate");const E=require("./get-chai-builder-theme-B1tr_NJB.cjs"),L=require("@mhsdesign/jit-browser-tailwindcss"),F=require("@tailwindcss/container-queries"),m=require("react/jsx-runtime"),g=require("react"),R=require("@chaibuilder/runtime");function M(e,r){const a=e.filter(({_type:i})=>i==="GlobalBlock"||i==="PartialBlock");for(let i=0;i<a.length;i++){const l=a[i],s=t.get(l,"partialBlockId",t.get(l,"globalBlock",""));if(s==="")continue;let n=t.cloneDeep(t.get(r,s,[]));l._parent&&(n==null?void 0:n.length)>0&&(n=n.map(c=>(t.isEmpty(c._parent)&&(c._parent=l._parent),c)));const o=e.indexOf(l);e.splice(o,1,...n)}return e}const D=e=>{if(!e)return[];try{return JSON.parse(j(e)).filter(a=>!a._type.startsWith("@chai"))}catch{return[{_type:"Paragraph",_id:"error",content:"Invalid JSON. Please check the JSON string."}]}};function j(e){const r=/(asset:\/\/|https:\/\/asset\.localhost\/)(?:localhost\/)?[^"']+/g;return e.replace(r,a=>{const i=decodeURIComponent(a),l=i.indexOf("public");return l!==-1?i.substring(l+6):i})}async function O(e,r,a=[],i="",l){return await L.createTailwindcss({tailwindConfig:{darkMode:"class",safelist:a,theme:{extend:E.getChaiBuilderTheme(e)},plugins:[q,$,I,F,k.chaiBuilderPlugin],corePlugins:{preflight:l},...i?{prefix:`${i}`}:{}}}).generateStylesFromContent(` ${l?"@tailwind base;":""}
2
2
  @tailwind components;
3
- @tailwind utilities;`,r)}const A=(e,r,a)=>{const i=JSON.stringify(e).replace(/#styles:([^"]*)/g,(l,s)=>`#styles:${s.replace(/,/g," ")}`.replace(/#styles:/g,""));return O(r,[i],[],"",a)},K=async(e,r=y.defaultThemeOptions,a=!1)=>await A(e,r,a);async function N(e){const r={pageProps:e.pageProps,block:e.block,lang:e.lang,draft:e.draft,inBuilder:!1},a=await e.dataProvider(r);return t.has(a,"$metadata")&&t.isFunction(e.dataProviderMetadataCallback)&&e.dataProviderMetadataCallback(e.block,a.$metadata),e.children({...t.omit(a,"$metadata")})}const J=()=>m.jsx("div",{}),V=e=>{const{block:r,lang:a,fallbackLang:i,children:l,externalData:s,blocks:n,draft:o,pageProps:c,dataProviderMetadataCallback:h}=e,d=R.getRegisteredChaiBlock(r._type),f=t.get(d,"component",null),k=t.get(e.repeaterData,"index",-1),b=t.get(e.repeaterData,"dataKey",""),C=a===i?"":a,g=p.applyBindingToBlockProps(p.applyLanguage(r,C,d),s,{index:k,key:b}),w=p.getBlockTagAttributes(r,!1),S=U(n,r._id,p.getBlockRuntimeProps(r._type)),T=t.has(d,"dataProvider")&&t.isFunction(d.dataProvider),_={...g,...w,...S},P={blockProps:{},inBuilder:!1,lang:a||i,..._};if(t.isNull(f))return null;if(T){const v=t.get(d,"suspenseFallback",J);return m.jsx(u.Suspense,{fallback:u.createElement(v),children:m.jsx(N,{lang:a,pageProps:c,block:_,dataProvider:d.dataProvider,...h?{dataProviderMetadataCallback:h}:{},draft:o,children:x=>u.createElement(f,{...P,...x,children:l({_id:r._id,_type:r._type,...t.isArray(g.repeaterItems)?{repeaterItems:p.applyLimit(g.repeaterItems,r),$repeaterItemsKey:g.$repeaterItemsKey}:{}})})})})}return m.jsx(u.Suspense,{children:u.createElement(f,{...P,children:l({_id:r._id,_type:r._type,...t.isArray(g.repeaterItems)?{repeaterItems:p.applyLimit(g.repeaterItems,r),$repeaterItemsKey:g.$repeaterItemsKey}:{}})})})},B=e=>{const{blocks:r,parent:a,repeaterData:i}=e;let l=t.uniqBy(t.filter(r,n=>t.has(n,"_id")&&(t.isEmpty(a)?!n._parent:n._parent===a)),"_id");const s=n=>t.filter(r,o=>o._parent===n).length>0;return t.map(l,n=>n?u.createElement(V,{...e,key:n._id,block:n},({_id:o,_type:c,repeaterItems:h,$repeaterItemsKey:d})=>c==="Repeater"?t.isArray(h)&&h.map((f,k)=>u.createElement(B,{...e,parent:n._id,key:`${t.get(n,"_parent","root")}-${n._id}-${k}`,repeaterData:{index:k,dataKey:d}})):s(o)?u.createElement(B,{...e,parent:n._id,key:`${t.get(n,"_parent","root")}-${n._id}`,repeaterData:i}):null):null)},U=(e,r,a)=>t.isEmpty(a)?{}:Object.entries(a).reduce((i,[l,s])=>{const n=[];let o=t.find(e,{_id:r});for(;o;)n.push(o),o=t.find(e,{_id:o._parent});const c=t.find(n,{_type:s.block});return c&&(i[l]=t.get(c,t.get(s,"prop"),null)),i},{});function W(e){if(t.isEmpty(e.lang)&&!t.isEmpty(e.fallbackLang))throw new Error("lang prop is required when fallbackLang is provided");if(t.isEmpty(e.blocks))return null;const r=e.lang??"en",a=e.fallbackLang??r;return m.jsx(B,{...e,lang:r,fallbackLang:a})}exports.getChaiThemeCssVariables=y.getChaiThemeCssVariables;exports.getThemeFontsCSSImport=y.getThemeFontsCSSImport;exports.getThemeFontsLinkMarkup=y.getThemeFontsLinkMarkup;exports.applyChaiDataBinding=p.applyChaiDataBinding;exports.RenderChaiBlocks=W;exports.convertToBlocks=j;exports.getMergedPartialBlocks=D;exports.getStylesForBlocks=K;
3
+ @tailwind utilities;`,r)}const A=(e,r,a)=>{const i=JSON.stringify(e).replace(/#styles:([^"]*)/g,(l,s)=>`#styles:${s.replace(/,/g," ")}`.replace(/#styles:/g,""));return O(r,[i],[],"",a)},K=async(e,r=k.defaultThemeOptions,a=!1)=>await A(e,r,a);async function N(e){const r={pageProps:e.pageProps,block:e.block,lang:e.lang,draft:e.draft,inBuilder:!1},a=await e.dataProvider(r);return t.has(a,"$metadata")&&t.isFunction(e.dataProviderMetadataCallback)&&e.dataProviderMetadataCallback(e.block,a.$metadata),e.children({...t.omit(a,"$metadata")})}const J=()=>m.jsx("div",{}),V=e=>{const{block:r,lang:a,fallbackLang:i,children:l,externalData:s,blocks:n,draft:o,pageProps:c,dataProviderMetadataCallback:h}=e,d=R.getRegisteredChaiBlock(r._type),y=t.get(d,"component",null),f=t.get(e.repeaterData,"index",-1),b=t.get(e.repeaterData,"dataKey",""),C=a===i?"":a,p=u.applyBindingToBlockProps(u.applyLanguage(r,C,d),s,{index:f,key:b}),w=u.getBlockTagAttributes(r,!1),T=H(n,r._id,u.getBlockRuntimeProps(r._type)),S=t.has(d,"dataProvider")&&t.isFunction(d.dataProvider),_={...p,...w,...T},P={blockProps:{},inBuilder:!1,lang:a||i,..._};if(t.isNull(y))return null;if(S){const v=t.get(d,"suspenseFallback",J);return m.jsx(g.Suspense,{fallback:g.createElement(v),children:m.jsx(N,{lang:a,pageProps:c,block:_,dataProvider:d.dataProvider,...h?{dataProviderMetadataCallback:h}:{},draft:o,children:x=>g.createElement(y,{...P,...x,children:l({_id:r._id,_type:r._type,...t.isArray(p.repeaterItems)?{repeaterItems:u.applyLimit(p.repeaterItems,r),$repeaterItemsKey:p.$repeaterItemsKey}:{}})})})})}return m.jsx(g.Suspense,{children:g.createElement(y,{...P,children:l({_id:r._id,_type:r._type,...t.isArray(p.repeaterItems)?{repeaterItems:u.applyLimit(p.repeaterItems,r),$repeaterItemsKey:p.$repeaterItemsKey}:{}})})})},B=e=>{const{blocks:r,parent:a,repeaterData:i}=e;let l=t.uniqBy(t.filter(r,n=>t.has(n,"_id")&&(t.isEmpty(a)?!n._parent:n._parent===a)),"_id");const s=n=>t.filter(r,o=>o._parent===n).length>0;return t.map(l,n=>n?g.createElement(V,{...e,key:n._id,block:n},({_id:o,_type:c,repeaterItems:h,$repeaterItemsKey:d})=>c==="Repeater"?t.isArray(h)&&h.map((y,f)=>g.createElement(B,{...e,parent:n._id,key:`${t.get(n,"_parent","root")}-${n._id}-${f}`,repeaterData:{index:f,dataKey:d}})):s(o)?g.createElement(B,{...e,parent:n._id,key:`${t.get(n,"_parent","root")}-${n._id}`,repeaterData:i}):null):null)},H=(e,r,a)=>t.isEmpty(a)?{}:Object.entries(a).reduce((i,[l,s])=>{const n=[];let o=t.find(e,{_id:r});for(;o;)n.push(o),o=t.find(e,{_id:o._parent});const c=t.find(n,{_type:s.block});return c&&(i[l]=t.get(c,t.get(s,"prop"),null)),i},{});function U(e){if(t.isEmpty(e.lang)&&!t.isEmpty(e.fallbackLang))throw new Error("lang prop is required when fallbackLang is provided");if(t.isEmpty(e.blocks))return null;const r=e.lang??"en",a=e.fallbackLang??r;return m.jsx(B,{...e,lang:r,fallbackLang:a})}exports.getChaiThemeCssVariables=k.getChaiThemeCssVariables;exports.getThemeFontsCSSImport=k.getThemeFontsCSSImport;exports.getThemeFontsLinkMarkup=k.getThemeFontsLinkMarkup;exports.applyChaiDataBinding=u.applyChaiDataBinding;exports.convertHTMLToChaiBlocks=u.getBlocksFromHTML;exports.RenderChaiBlocks=U;exports.convertToBlocks=D;exports.getMergedPartialBlocks=M;exports.getStylesForBlocks=K;
package/dist/render.d.ts CHANGED
@@ -54,6 +54,13 @@ declare type ChaiThemeValues = {
54
54
  };
55
55
  };
56
56
 
57
+ /**
58
+ *
59
+ * @param html
60
+ * @returns Blocks JSON
61
+ */
62
+ export declare const convertHTMLToChaiBlocks: (html: string) => ChaiBlock[];
63
+
57
64
  /**
58
65
  * This function converts the chai format content to chai blocks
59
66
  * @param chaiFormatContent
package/dist/render.js CHANGED
@@ -1,14 +1,14 @@
1
1
  import { d as F, c as O } from "./plugin-BOcGV_IY.js";
2
2
  import { a as ve, b as Se, e as xe } from "./plugin-BOcGV_IY.js";
3
- import { a as K, b as A, g as M, c as N, d as C } from "./apply-binding-BL-JPMms.js";
4
- import { e as $e } from "./apply-binding-BL-JPMms.js";
5
- import { get as s, cloneDeep as J, isEmpty as u, has as b, isFunction as x, omit as E, isNull as j, isArray as _, uniqBy as q, filter as v, map as U, find as y } from "lodash-es";
3
+ import { a as K, b as M, g as A, c as N, d as C } from "./apply-binding-OTp8TO_7.js";
4
+ import { e as $e, f as Te } from "./apply-binding-OTp8TO_7.js";
5
+ import { get as s, cloneDeep as J, isEmpty as u, has as P, isFunction as x, omit as E, isNull as j, isArray as _, uniqBy as q, filter as v, map as U, find as y } from "lodash-es";
6
6
  import V from "@tailwindcss/aspect-ratio";
7
7
  import W from "@tailwindcss/forms";
8
8
  import G from "@tailwindcss/typography";
9
9
  import "tailwindcss-animate";
10
- import { g as z } from "./get-chai-builder-theme-BarMkcGH.js";
11
- import { createTailwindcss as H } from "@mhsdesign/jit-browser-tailwindcss";
10
+ import { g as H } from "./get-chai-builder-theme-BarMkcGH.js";
11
+ import { createTailwindcss as z } from "@mhsdesign/jit-browser-tailwindcss";
12
12
  import Q from "@tailwindcss/container-queries";
13
13
  import { jsx as m } from "react/jsx-runtime";
14
14
  import { Suspense as S, createElement as g } from "react";
@@ -16,16 +16,16 @@ import { getRegisteredChaiBlock as X } from "@chaibuilder/runtime";
16
16
  function _e(e, t) {
17
17
  const a = e.filter(({ _type: n }) => n === "GlobalBlock" || n === "PartialBlock");
18
18
  for (let n = 0; n < a.length; n++) {
19
- const i = a[n], l = s(i, "partialBlockId", s(i, "globalBlock", ""));
20
- if (l === "") continue;
21
- let r = J(s(t, l, []));
19
+ const i = a[n], o = s(i, "partialBlockId", s(i, "globalBlock", ""));
20
+ if (o === "") continue;
21
+ let r = J(s(t, o, []));
22
22
  i._parent && (r == null ? void 0 : r.length) > 0 && (r = r.map((c) => (u(c._parent) && (c._parent = i._parent), c)));
23
- const o = e.indexOf(i);
24
- e.splice(o, 1, ...r);
23
+ const l = e.indexOf(i);
24
+ e.splice(l, 1, ...r);
25
25
  }
26
26
  return e;
27
27
  }
28
- const Pe = (e) => {
28
+ const Be = (e) => {
29
29
  if (!e) return [];
30
30
  try {
31
31
  return JSON.parse(Y(e)).filter((a) => !a._type.startsWith("@chai"));
@@ -41,11 +41,11 @@ function Y(e) {
41
41
  });
42
42
  }
43
43
  async function Z(e, t, a = [], n = "", i) {
44
- return await H({
44
+ return await z({
45
45
  tailwindConfig: {
46
46
  darkMode: "class",
47
47
  safelist: a,
48
- theme: { extend: z(e) },
48
+ theme: { extend: H(e) },
49
49
  plugins: [W, G, V, Q, O],
50
50
  corePlugins: { preflight: i },
51
51
  ...n ? { prefix: `${n}` } : {}
@@ -58,9 +58,9 @@ async function Z(e, t, a = [], n = "", i) {
58
58
  );
59
59
  }
60
60
  const ee = (e, t, a) => {
61
- const n = JSON.stringify(e).replace(/#styles:([^"]*)/g, (i, l) => `#styles:${l.replace(/,/g, " ")}`.replace(/#styles:/g, ""));
61
+ const n = JSON.stringify(e).replace(/#styles:([^"]*)/g, (i, o) => `#styles:${o.replace(/,/g, " ")}`.replace(/#styles:/g, ""));
62
62
  return Z(t, [n], [], "", a);
63
- }, be = async (e, t = F, a = !1) => await ee(e, t, a);
63
+ }, Pe = async (e, t = F, a = !1) => await ee(e, t, a);
64
64
  async function te(e) {
65
65
  const t = {
66
66
  pageProps: e.pageProps,
@@ -69,16 +69,16 @@ async function te(e) {
69
69
  draft: e.draft,
70
70
  inBuilder: !1
71
71
  }, a = await e.dataProvider(t);
72
- return b(a, "$metadata") && x(e.dataProviderMetadataCallback) && e.dataProviderMetadataCallback(e.block, a.$metadata), e.children({
72
+ return P(a, "$metadata") && x(e.dataProviderMetadataCallback) && e.dataProviderMetadataCallback(e.block, a.$metadata), e.children({
73
73
  ...E(a, "$metadata")
74
74
  });
75
75
  }
76
76
  const ae = () => /* @__PURE__ */ m("div", {}), re = (e) => {
77
- const { block: t, lang: a, fallbackLang: n, children: i, externalData: l, blocks: r, draft: o, pageProps: c, dataProviderMetadataCallback: f } = e, d = X(t._type), h = s(d, "component", null), k = s(e.repeaterData, "index", -1), I = s(e.repeaterData, "dataKey", ""), p = K(
78
- A(t, a === n ? "" : a, d),
79
- l,
77
+ const { block: t, lang: a, fallbackLang: n, children: i, externalData: o, blocks: r, draft: l, pageProps: c, dataProviderMetadataCallback: f } = e, d = X(t._type), h = s(d, "component", null), k = s(e.repeaterData, "index", -1), I = s(e.repeaterData, "dataKey", ""), p = K(
78
+ M(t, a === n ? "" : a, d),
79
+ o,
80
80
  { index: k, key: I }
81
- ), $ = M(t, !1), T = ne(r, t._id, N(t._type)), L = b(d, "dataProvider") && x(d.dataProvider), B = {
81
+ ), $ = A(t, !1), T = ne(r, t._id, N(t._type)), L = P(d, "dataProvider") && x(d.dataProvider), b = {
82
82
  ...p,
83
83
  ...$,
84
84
  ...T
@@ -86,7 +86,7 @@ const ae = () => /* @__PURE__ */ m("div", {}), re = (e) => {
86
86
  blockProps: {},
87
87
  inBuilder: !1,
88
88
  lang: a || n,
89
- ...B
89
+ ...b
90
90
  };
91
91
  if (j(h)) return null;
92
92
  if (L) {
@@ -96,10 +96,10 @@ const ae = () => /* @__PURE__ */ m("div", {}), re = (e) => {
96
96
  {
97
97
  lang: a,
98
98
  pageProps: c,
99
- block: B,
99
+ block: b,
100
100
  dataProvider: d.dataProvider,
101
101
  ...f ? { dataProviderMetadataCallback: f } : {},
102
- draft: o,
102
+ draft: l,
103
103
  children: (R) => g(h, {
104
104
  ...w,
105
105
  ...R,
@@ -126,23 +126,23 @@ const ae = () => /* @__PURE__ */ m("div", {}), re = (e) => {
126
126
  } : {}
127
127
  })
128
128
  }) });
129
- }, P = (e) => {
129
+ }, B = (e) => {
130
130
  const { blocks: t, parent: a, repeaterData: n } = e;
131
131
  let i = q(
132
- v(t, (r) => b(r, "_id") && (u(a) ? !r._parent : r._parent === a)),
132
+ v(t, (r) => P(r, "_id") && (u(a) ? !r._parent : r._parent === a)),
133
133
  "_id"
134
134
  );
135
- const l = (r) => v(t, (o) => o._parent === r).length > 0;
136
- return U(i, (r) => r ? /* @__PURE__ */ g(re, { ...e, key: r._id, block: r }, ({ _id: o, _type: c, repeaterItems: f, $repeaterItemsKey: d }) => c === "Repeater" ? _(f) && f.map((h, k) => /* @__PURE__ */ g(
137
- P,
135
+ const o = (r) => v(t, (l) => l._parent === r).length > 0;
136
+ return U(i, (r) => r ? /* @__PURE__ */ g(re, { ...e, key: r._id, block: r }, ({ _id: l, _type: c, repeaterItems: f, $repeaterItemsKey: d }) => c === "Repeater" ? _(f) && f.map((h, k) => /* @__PURE__ */ g(
137
+ B,
138
138
  {
139
139
  ...e,
140
140
  parent: r._id,
141
141
  key: `${s(r, "_parent", "root")}-${r._id}-${k}`,
142
142
  repeaterData: { index: k, dataKey: d }
143
143
  }
144
- )) : l(o) ? /* @__PURE__ */ g(
145
- P,
144
+ )) : o(l) ? /* @__PURE__ */ g(
145
+ B,
146
146
  {
147
147
  ...e,
148
148
  parent: r._id,
@@ -150,29 +150,30 @@ const ae = () => /* @__PURE__ */ m("div", {}), re = (e) => {
150
150
  repeaterData: n
151
151
  }
152
152
  ) : null) : null);
153
- }, ne = (e, t, a) => u(a) ? {} : Object.entries(a).reduce((n, [i, l]) => {
153
+ }, ne = (e, t, a) => u(a) ? {} : Object.entries(a).reduce((n, [i, o]) => {
154
154
  const r = [];
155
- let o = y(e, { _id: t });
156
- for (; o; )
157
- r.push(o), o = y(e, { _id: o._parent });
158
- const c = y(r, { _type: l.block });
159
- return c && (n[i] = s(c, s(l, "prop"), null)), n;
155
+ let l = y(e, { _id: t });
156
+ for (; l; )
157
+ r.push(l), l = y(e, { _id: l._parent });
158
+ const c = y(r, { _type: o.block });
159
+ return c && (n[i] = s(c, s(o, "prop"), null)), n;
160
160
  }, {});
161
- function Be(e) {
161
+ function be(e) {
162
162
  if (u(e.lang) && !u(e.fallbackLang))
163
163
  throw new Error("lang prop is required when fallbackLang is provided");
164
164
  if (u(e.blocks))
165
165
  return null;
166
166
  const t = e.lang ?? "en", a = e.fallbackLang ?? t;
167
- return /* @__PURE__ */ m(P, { ...e, lang: t, fallbackLang: a });
167
+ return /* @__PURE__ */ m(B, { ...e, lang: t, fallbackLang: a });
168
168
  }
169
169
  export {
170
- Be as RenderChaiBlocks,
170
+ be as RenderChaiBlocks,
171
171
  $e as applyChaiDataBinding,
172
- Pe as convertToBlocks,
172
+ Te as convertHTMLToChaiBlocks,
173
+ Be as convertToBlocks,
173
174
  ve as getChaiThemeCssVariables,
174
175
  _e as getMergedPartialBlocks,
175
- be as getStylesForBlocks,
176
+ Pe as getStylesForBlocks,
176
177
  Se as getThemeFontsCSSImport,
177
178
  xe as getThemeFontsLinkMarkup
178
179
  };
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "author": "Suraj Air",
6
6
  "license": "BSD-3-Clause",
7
7
  "homepage": "https://chaibuilder.com",
8
- "version": "2.6.2",
8
+ "version": "2.6.3",
9
9
  "type": "module",
10
10
  "repository": {
11
11
  "type": "git",
@@ -1,267 +0,0 @@
1
- import { getRegisteredChaiBlock as $ } from "@chaibuilder/runtime";
2
- import { memoize as k, get as p, cloneDeep as h, forEach as _, keys as f, isString as x, startsWith as m, isArray as g, isEmpty as b, includes as C } from "lodash-es";
3
- import { twMerge as D } from "tailwind-merge";
4
- const E = "#styles:", P = "__ADD_BLOCK_INTERNAL_ROOT", q = "@", B = "#", I = (e) => {
5
- if (e = e.replace(E, ""), !e) return { baseClasses: "", classes: "" };
6
- const s = e.split(/,(?![^\[]*\])/);
7
- if (s.length === 1)
8
- return { baseClasses: "", classes: s[0].trim() };
9
- const [t, ...n] = s;
10
- return {
11
- baseClasses: t.trim(),
12
- classes: n.join(",").trim().replace(/ +(?= )/g, "")
13
- };
14
- };
15
- import.meta.vitest && describe("getSplitChaiClasses", () => {
16
- it("should return the base classes and the classes", () => {
17
- const e = {
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 s in e) {
42
- const t = I(`${E}${s}`);
43
- expect(t).toEqual(e[s]);
44
- }
45
- });
46
- });
47
- function w(e, s, t) {
48
- const n = p(t, "i18nProps", []);
49
- if (b(s) || b(n)) return e;
50
- const a = h(e);
51
- return _(f(a), (r) => {
52
- if (C(n, r) && !b(s)) {
53
- const o = p(a, `${r}-${s}`, ""), l = p(a, r, "");
54
- a[r] = x(o) && o.trim() || l;
55
- }
56
- }), a;
57
- }
58
- const v = k((e) => {
59
- const { baseClasses: s, classes: t } = I(e);
60
- return D(s, t);
61
- });
62
- function T(e, s) {
63
- return p(e, `${s}_attrs`, {});
64
- }
65
- function A(e, s = !0) {
66
- const t = {};
67
- return Object.keys(e).forEach((n) => {
68
- if (x(e[n]) && e[n].startsWith(E)) {
69
- const a = v(e[n]), r = T(e, n);
70
- t[n] = {
71
- ...!b(a) && { className: a },
72
- ...r,
73
- ...s ? {
74
- "data-style-prop": n,
75
- "data-block-parent": e._id,
76
- "data-style-id": `${n}-${e._id}`
77
- } : {}
78
- };
79
- }
80
- }), t;
81
- }
82
- const N = k((e) => {
83
- const s = $(e), t = p(s, "schema.properties", {});
84
- return Object.fromEntries(Object.entries(t).filter(([, n]) => p(n, "runtime", !1)));
85
- }), j = (e, s) => {
86
- if (!g(e)) return e;
87
- let t = e, n;
88
- return typeof s.limit == "number" && s.limit > 0 && (n = s.limit), n !== void 0 && (t = t.slice(0, n)), t;
89
- }, z = (e, s) => {
90
- const t = h(e);
91
- return _(f(t), (n) => {
92
- if (x(t[n]) && !m(n, "_")) {
93
- let a = t[n];
94
- n === "repeaterItems" && (t.repeaterItemsBinding = a);
95
- const r = /\{\{(.*?)\}\}/g, o = a.match(r);
96
- o && o.forEach((l) => {
97
- let c = l.slice(2, -2);
98
- const d = p(s, c, l);
99
- a = g(d) ? d : a.replace(l, d);
100
- }), t[n] = a;
101
- }
102
- }), t;
103
- }, i = (e, s, { index: t, key: n }) => {
104
- if (x(e)) {
105
- let a = e;
106
- const r = /\{\{(.*?)\}\}/g, o = e.match(r);
107
- return o && o.forEach((l) => {
108
- let c = l.slice(2, -2).trim(), d = n.slice(2, -2).trim();
109
- t !== -1 && m(c, "$index.") ? c = `${d}.${t}.${c.slice(7)}` : t !== -1 && m(c, "$index") && (c = `${d}.${t}`);
110
- const y = p(s, c, l);
111
- a = g(y) ? y : a.replace(l, y);
112
- }), a;
113
- }
114
- if (g(e))
115
- return e.map((a) => i(a, s, { index: t, key: n }));
116
- if (e && typeof e == "object") {
117
- const a = {};
118
- return _(f(e), (r) => {
119
- !m(r, "_") && r !== "$repeaterItemsKey" ? a[r] = i(e[r], s, { index: t, key: n }) : a[r] = e[r];
120
- }), a;
121
- }
122
- return e;
123
- }, u = (e, s, { index: t, key: n }) => {
124
- let a = h(e);
125
- return a.repeaterItems && (a.$repeaterItemsKey = a.repeaterItems, m(a.repeaterItems, `{{${B}`) && (a.$repeaterItemsKey = a.repeaterItems = `${a.repeaterItems.replace("}}", `/${a._id}}}`)}`)), i(a, s, { index: t, key: n });
126
- };
127
- import.meta.vitest && (describe("applyBindingToValue", () => {
128
- it("should handle string values with bindings", () => {
129
- const t = i("Hello {{user.name}}", { user: { name: "John" } }, { index: -1, key: "" });
130
- expect(t).toBe("Hello John");
131
- }), it("should handle nested object properties", () => {
132
- const t = i({
133
- name: "John",
134
- address: {
135
- city: "{{user.city}}",
136
- street: "123 Main St"
137
- }
138
- }, { user: { city: "New York" } }, { index: -1, key: "" });
139
- expect(t).toEqual({
140
- name: "John",
141
- address: {
142
- city: "New York",
143
- street: "123 Main St"
144
- }
145
- });
146
- }), it("should handle arrays of values", () => {
147
- const t = i(["Hello {{user.name}}", "Welcome {{user.role}}"], { user: { name: "John", role: "Admin" } }, { index: -1, key: "" });
148
- expect(t).toEqual(["Hello John", "Welcome Admin"]);
149
- }), it("should handle $index binding in repeater context", () => {
150
- const t = i("Item {{$index}}", { items: ["a", "b", "c"] }, { index: 1, key: "{{items}}" });
151
- expect(t).toBe("Item b");
152
- }), it("should handle $index binding with dot notation", () => {
153
- const t = i("Item {{$index.value}}", { items: [{ value: "apple" }, { value: "banana" }, { value: "cherry" }] }, { index: 1, key: "{{items}}" });
154
- expect(t).toBe("Item banana");
155
- }), it("should preserve private properties starting with _", () => {
156
- const s = i({
157
- name: "John",
158
- _private: "secret"
159
- }, {}, { index: -1, key: "" });
160
- expect(s).toEqual({
161
- name: "John",
162
- _private: "secret"
163
- });
164
- });
165
- }), describe("applyBindingToBlockProps", () => {
166
- it("should handle basic block with bindings", () => {
167
- const t = u({
168
- _id: "test-block",
169
- _type: "text",
170
- type: "text",
171
- content: "Hello {{user.name}}",
172
- style: {
173
- color: "{{theme.color}}"
174
- }
175
- }, { user: { name: "John" }, theme: { color: "blue" } }, { index: -1, key: "" });
176
- expect(t).toEqual({
177
- _id: "test-block",
178
- _type: "text",
179
- type: "text",
180
- content: "Hello John",
181
- style: {
182
- color: "blue"
183
- }
184
- });
185
- }), it("should handle repeaterItems and repeaterItemsBinding", () => {
186
- const t = u({
187
- _id: "test-block",
188
- _type: "repeater",
189
- type: "repeater",
190
- repeaterItems: "{{items}}",
191
- items: ["a", "b", "c"]
192
- }, { items: ["x", "y", "z"] }, { index: -1, key: "" });
193
- expect(t).toEqual({
194
- _id: "test-block",
195
- _type: "repeater",
196
- type: "repeater",
197
- $repeaterItemsKey: "{{items}}",
198
- repeaterItems: ["x", "y", "z"],
199
- items: ["a", "b", "c"]
200
- });
201
- }), it("should handle nested blocks with bindings", () => {
202
- const t = u({
203
- _id: "test-block",
204
- _type: "container",
205
- type: "container",
206
- children: [
207
- {
208
- _id: "child-block",
209
- _type: "text",
210
- type: "text",
211
- content: "Item {{$index}}",
212
- style: {
213
- color: "{{theme.color}}"
214
- }
215
- }
216
- ]
217
- }, { theme: { color: "red" }, items: ["x", "y", "z"] }, { index: 2, key: "{{items}}" });
218
- expect(t).toEqual({
219
- _id: "test-block",
220
- _type: "container",
221
- type: "container",
222
- children: [
223
- {
224
- _id: "child-block",
225
- _type: "text",
226
- type: "text",
227
- content: "Item z",
228
- style: {
229
- color: "red"
230
- }
231
- }
232
- ]
233
- });
234
- }), it("should handle arrays of blocks", () => {
235
- const t = u({
236
- _id: "test-block",
237
- _type: "list",
238
- type: "list",
239
- items: [
240
- { _id: "item1", content: "Item {{$index}}" },
241
- { _id: "item2", content: "Item {{$index}}" }
242
- ]
243
- }, { items: ["x", "y", "z"] }, { index: 0, key: "{{items}}" });
244
- expect(t).toEqual({
245
- _id: "test-block",
246
- _type: "list",
247
- type: "list",
248
- items: [
249
- { _id: "item1", content: "Item x" },
250
- { _id: "item2", content: "Item x" }
251
- ]
252
- });
253
- });
254
- }));
255
- export {
256
- B as C,
257
- q as R,
258
- E as S,
259
- u as a,
260
- w as b,
261
- N as c,
262
- j as d,
263
- z as e,
264
- I as f,
265
- A as g,
266
- P as h
267
- };
@@ -1 +0,0 @@
1
- "use strict";const b=require("@chaibuilder/runtime"),t=require("lodash-es"),h=require("tailwind-merge"),g="#styles:",x="__ADD_BLOCK_INTERNAL_ROOT",E="@",m="#",y=e=>{if(e=e.replace(g,""),!e)return{baseClasses:"",classes:""};const i=e.split(/,(?![^\[]*\])/);if(i.length===1)return{baseClasses:"",classes:i[0].trim()};const[a,...n]=i;return{baseClasses:a.trim(),classes:n.join(",").trim().replace(/ +(?= )/g,"")}};function _(e,i,a){const n=t.get(a,"i18nProps",[]);if(t.isEmpty(i)||t.isEmpty(n))return e;const s=t.cloneDeep(e);return t.forEach(t.keys(s),l=>{if(t.includes(n,l)&&!t.isEmpty(i)){const o=t.get(s,`${l}-${i}`,""),r=t.get(s,l,"");s[l]=t.isString(o)&&o.trim()||r}}),s}const f=t.memoize(e=>{const{baseClasses:i,classes:a}=y(e);return h.twMerge(i,a)});function k(e,i){return t.get(e,`${i}_attrs`,{})}function B(e,i=!0){const a={};return Object.keys(e).forEach(n=>{if(t.isString(e[n])&&e[n].startsWith(g)){const s=f(e[n]),l=k(e,n);a[n]={...!t.isEmpty(s)&&{className:s},...l,...i?{"data-style-prop":n,"data-block-parent":e._id,"data-style-id":`${n}-${e._id}`}:{}}}}),a}const I=t.memoize(e=>{const i=b.getRegisteredChaiBlock(e),a=t.get(i,"schema.properties",{});return Object.fromEntries(Object.entries(a).filter(([,n])=>t.get(n,"runtime",!1)))}),T=(e,i)=>{if(!t.isArray(e))return e;let a=e,n;return typeof i.limit=="number"&&i.limit>0&&(n=i.limit),n!==void 0&&(a=a.slice(0,n)),a},C=(e,i)=>{const a=t.cloneDeep(e);return t.forEach(t.keys(a),n=>{if(t.isString(a[n])&&!t.startsWith(n,"_")){let s=a[n];n==="repeaterItems"&&(a.repeaterItemsBinding=s);const l=/\{\{(.*?)\}\}/g,o=s.match(l);o&&o.forEach(r=>{let c=r.slice(2,-2);const p=t.get(i,c,r);s=t.isArray(p)?p:s.replace(r,p)}),a[n]=s}}),a},u=(e,i,{index:a,key:n})=>{if(t.isString(e)){let s=e;const l=/\{\{(.*?)\}\}/g,o=e.match(l);return o&&o.forEach(r=>{let c=r.slice(2,-2).trim(),p=n.slice(2,-2).trim();a!==-1&&t.startsWith(c,"$index.")?c=`${p}.${a}.${c.slice(7)}`:a!==-1&&t.startsWith(c,"$index")&&(c=`${p}.${a}`);const d=t.get(i,c,r);s=t.isArray(d)?d:s.replace(r,d)}),s}if(t.isArray(e))return e.map(s=>u(s,i,{index:a,key:n}));if(e&&typeof e=="object"){const s={};return t.forEach(t.keys(e),l=>{!t.startsWith(l,"_")&&l!=="$repeaterItemsKey"?s[l]=u(e[l],i,{index:a,key:n}):s[l]=e[l]}),s}return e},$=(e,i,{index:a,key:n})=>{let s=t.cloneDeep(e);return s.repeaterItems&&(s.$repeaterItemsKey=s.repeaterItems,t.startsWith(s.repeaterItems,`{{${m}`)&&(s.$repeaterItemsKey=s.repeaterItems=`${s.repeaterItems.replace("}}",`/${s._id}}}`)}`)),u(s,i,{index:a,key:n})};exports.COLLECTION_PREFIX=m;exports.REPEATER_PREFIX=E;exports.ROOT_TEMP_KEY=x;exports.STYLES_KEY=g;exports.applyBindingToBlockProps=$;exports.applyChaiDataBinding=C;exports.applyLanguage=_;exports.applyLimit=T;exports.getBlockRuntimeProps=I;exports.getBlockTagAttributes=B;exports.getSplitChaiClasses=y;