@chaibuilder/sdk 2.5.4 → 2.5.6

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-DpBwzIf9.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 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;":""}
2
2
  @tailwind components;
3
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;
package/dist/render.js CHANGED
@@ -1,7 +1,7 @@
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-CkrtJykq.js";
4
- import { e as $e } from "./apply-binding-CkrtJykq.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
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";
6
6
  import V from "@tailwindcss/aspect-ratio";
7
7
  import W from "@tailwindcss/forms";
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.5.4",
8
+ "version": "2.5.6",
9
9
  "type": "module",
10
10
  "repository": {
11
11
  "type": "git",
@@ -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=>{t.includes(n,l)&&!t.isEmpty(i)&&(s[l]=t.get(s,`${l}-${i}`,s[l]))}),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,p=s.match(l);p&&p.forEach(o=>{let r=o.slice(2,-2);const c=t.get(i,r,o);s=t.isArray(c)?c:s.replace(o,c)}),a[n]=s}}),a},u=(e,i,{index:a,key:n})=>{if(t.isString(e)){let s=e;const l=/\{\{(.*?)\}\}/g,p=e.match(l);return p&&p.forEach(o=>{let r=o.slice(2,-2).trim(),c=n.slice(2,-2).trim();a!==-1&&t.startsWith(r,"$index.")?r=`${c}.${a}.${r.slice(7)}`:a!==-1&&t.startsWith(r,"$index")&&(r=`${c}.${a}`);const d=t.get(i,r,o);s=t.isArray(d)?d:s.replace(o,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;