@chaibuilder/sdk 3.1.17 → 3.1.19

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 k=require("./plugin-CSgw-f78.cjs"),u=require("./apply-binding-DvHNFLQD.cjs"),t=require("lodash-es"),q=require("@tailwindcss/aspect-ratio"),L=require("@tailwindcss/forms"),E=require("@tailwindcss/typography");require("tailwindcss-animate");const $=require("./get-chai-builder-theme-B1tr_NJB.cjs"),F=require("@mhsdesign/jit-browser-tailwindcss"),R=require("@tailwindcss/container-queries"),m=require("react/jsx-runtime"),p=require("react"),M=require("@chaibuilder/runtime");function j(e,a){const r=e.filter(({_type:i})=>i==="GlobalBlock"||i==="PartialBlock");for(let i=0;i<r.length;i++){const o=r[i],c=t.get(o,"partialBlockId",t.get(o,"globalBlock",""));if(c==="")continue;let s=t.cloneDeep(t.get(a,c,[]));o._parent&&(s==null?void 0:s.length)>0&&(s=s.map(l=>(t.isEmpty(l._parent)&&(l._parent=o._parent),l)));const n=e.indexOf(o);e.splice(n,1,...s)}return e}const D=e=>{if(!e)return[];try{return JSON.parse(A(e)).filter(r=>!r._type.startsWith("@chai"))}catch{return[{_type:"Paragraph",_id:"error",content:"Invalid JSON. Please check the JSON string."}]}};function A(e){const a=/(asset:\/\/|https:\/\/asset\.localhost\/)(?:localhost\/)?[^"']+/g;return e.replace(a,r=>{const i=decodeURIComponent(r),o=i.indexOf("public");return o!==-1?i.substring(o+6):i})}async function O(e,a=[],r=!1){return await F.createTailwindcss({tailwindConfig:{darkMode:"class",safelist:a,theme:{extend:{...$.getChaiBuilderTheme(),keyframes:{"accordion-down":{from:{height:"0"},to:{height:"var(--radix-accordion-content-height)"}},"accordion-up":{from:{height:"var(--radix-accordion-content-height)"},to:{height:"0"}}},animation:{"accordion-down":"accordion-down 0.2s ease-out","accordion-up":"accordion-up 0.2s ease-out"}}},plugins:[L,E,q,R,k.chaiBuilderPlugin],corePlugins:{preflight:r}}}).generateStylesFromContent(` ${r?"@tailwind base;":""}
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const C=require("./plugin-CSgw-f78.cjs"),d=require("./apply-binding-DvHNFLQD.cjs"),y=require("react/jsx-runtime"),v=require("@chaibuilder/runtime"),L=require("lodash"),t=require("lodash-es"),g=require("react"),q=require("@tailwindcss/aspect-ratio"),D=require("@tailwindcss/forms"),j=require("@tailwindcss/typography");require("tailwindcss-animate");const K=require("./get-chai-builder-theme-B1tr_NJB.cjs"),M=require("@mhsdesign/jit-browser-tailwindcss"),O=require("@tailwindcss/container-queries");async function N(e){const a={pageProps:e.pageProps,block:e.block,lang:e.lang,draft:e.draft,inBuilder:!1},n=await e.dataProvider(a);return t.has(n,"$metadata")&&t.isFunction(e.dataProviderMetadataCallback)&&e.dataProviderMetadataCallback(e.block,n.$metadata),e.children({...t.omit(n,"$metadata")})}const H=()=>y.jsx("div",{}),J=e=>{const{block:a,lang:n,fallbackLang:s,children:i,externalData:o,blocks:l,draft:r,pageProps:c,dataProviderMetadataCallback:k}=e,u=v.getRegisteredChaiBlock(a._type),p=t.get(u,"component",null),_=t.get(e.repeaterData,"index",-1),f=t.get(e.repeaterData,"dataKey",""),w=n===s?"":n,h=d.applyBindingToBlockProps(d.applyLanguage(a,w,u),o,{index:_,key:f}),m=d.getBlockTagAttributes(a,!1),I=R(l,a._id,d.getBlockRuntimeProps(a._type)),T=t.has(u,"dataProvider")&&t.isFunction(u.dataProvider),B={...h,...m,...I},P={blockProps:{},inBuilder:!1,lang:n||s,...B},b=t.get(B,"_show",!0);if(t.isNull(p)||!b)return null;if(T){const S=t.get(u,"suspenseFallback",H);return y.jsx(g.Suspense,{fallback:g.createElement(S),children:y.jsx(N,{lang:n,pageProps:c,block:B,dataProvider:u.dataProvider,...k?{dataProviderMetadataCallback:k}:{},draft:r,children:$=>g.createElement(p,{...P,...$,children:i({_id:a._id,_type:a._type,...t.isArray(h.repeaterItems)?{repeaterItems:d.applyLimit(h.repeaterItems,a),$repeaterItemsKey:h.$repeaterItemsKey,repeaterTotalItems:h.repeaterTotalItems??-1}:{}})})})})}return y.jsx(g.Suspense,{children:g.createElement(p,{...P,children:i({_id:a._id,_type:a._type,...t.isArray(h.repeaterItems)?{repeaterItems:d.applyLimit(h.repeaterItems,a),$repeaterItemsKey:h.$repeaterItemsKey,repeaterTotalItems:h.repeaterTotalItems??-1}:{}})})})},x=e=>{const{blocks:a,parent:n,repeaterData:s,type:i}=e;let o=t.uniqBy(t.filter(a,r=>t.has(r,"_id")&&(t.isEmpty(n)?!r._parent:r._parent===n)),"_id");const l=r=>t.filter(a,c=>c._parent===r).length>0;return(i==="Heading"||i==="Paragraph"||i==="Link")&&(o=d.adjustSpacingInContentBlocks(o)),t.map(o,r=>r?g.createElement(J,{...e,key:r._id,block:r},({_id:c,_type:k,repeaterItems:u,$repeaterItemsKey:p})=>k==="Repeater"?t.isArray(u)&&u.map((_,f)=>g.createElement(x,{...e,parent:r._id,key:`${t.get(r,"_parent","root")}-${r._id}-${f}`,repeaterData:{index:f,dataKey:p}})):l(c)?g.createElement(x,{...e,parent:r._id,key:`${t.get(r,"_parent","root")}-${r._id}`,repeaterData:s,type:r._type}):null):null)},R=(e,a,n)=>t.isEmpty(n)?{}:Object.entries(n).reduce((s,[i,o])=>{const l=[];let r=t.find(e,{_id:a});for(;r;)l.push(r),r=t.find(e,{_id:r._parent});const c=t.find(l,{_type:o.block});return c&&(s[i]=t.get(c,t.get(o,"prop"),null)),s},{});function V(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 a=e.lang??"en",n=e.fallbackLang??a;return y.jsx(x,{...e,lang:a,fallbackLang:n})}async function W(e){const a=await e.dataProvider;return t.has(a,"$metadata")&&t.isFunction(e.dataProviderMetadataCallback)&&e.dataProviderMetadataCallback(e.block,a.$metadata),e.children({...t.omit(a,"$metadata")})}const U=()=>y.jsx("div",{}),G=async e=>{const{block:a,lang:n,fallbackLang:s,children:i,externalData:o,blocks:l,draft:r,pageProps:c,dataProviderMetadataCallback:k,dataProviders:u}=e,p=v.getRegisteredChaiBlock(a._type),_=t.get(p,"component",null),f=t.get(e.repeaterData,"index",-1),w=t.get(e.repeaterData,"dataKey",""),h=n===s?"":n,m=d.applyBindingToBlockProps(d.applyLanguage(a,h,p),o,{index:f,key:w}),I=d.getBlockTagAttributes(a,!1),T=R(l,a._id,d.getBlockRuntimeProps(a._type)),B=t.has(p,"dataProvider")&&t.isFunction(p.dataProvider),P={...m,...I,...T},b={blockProps:{},inBuilder:!1,lang:n||s,...P},S=t.get(P,"_show",!0);if(t.isNull(_)||!S)return null;if(B){const $=t.get(u,a._id,Promise.resolve({})),A=t.get(p,"suspenseFallback",U);return y.jsx(g.Suspense,{fallback:g.createElement(A),children:y.jsx(W,{lang:n,pageProps:c,block:P,dataProvider:$,...k?{dataProviderMetadataCallback:k}:{},draft:r,children:F=>g.createElement(_,{...b,...F,children:i({_id:a._id,_type:a._type,...t.isArray(m.repeaterItems)?{repeaterItems:d.applyLimit(m.repeaterItems,a),$repeaterItemsKey:m.$repeaterItemsKey,repeaterTotalItems:m.repeaterTotalItems??-1}:{}})})})})}return y.jsx(g.Suspense,{children:g.createElement(_,{...b,children:i({_id:a._id,_type:a._type,...t.isArray(m.repeaterItems)?{repeaterItems:d.applyLimit(m.repeaterItems,a),$repeaterItemsKey:m.$repeaterItemsKey,repeaterTotalItems:m.repeaterTotalItems??-1}:{}})})})},E=async e=>{const{blocks:a,parent:n,repeaterData:s,type:i}=e;let o=t.uniqBy(t.filter(a,r=>t.has(r,"_id")&&(t.isEmpty(n)?!r._parent:r._parent===n)),"_id");const l=r=>t.filter(a,c=>c._parent===r).length>0;return(i==="Heading"||i==="Paragraph"||i==="Link")&&(o=d.adjustSpacingInContentBlocks(o)),t.map(o,r=>r?g.createElement(G,{dataProviders:e.dataProviders,...e,key:r._id,block:r},({_id:c,_type:k,repeaterItems:u,$repeaterItemsKey:p})=>k==="Repeater"?t.isArray(u)&&u.map((_,f)=>g.createElement(E,{...e,parent:r._id,key:`${t.get(r,"_parent","root")}-${r._id}-${f}`,repeaterData:{index:f,dataKey:p}})):l(c)?g.createElement(E,{...e,parent:r._id,key:`${t.get(r,"_parent","root")}-${r._id}`,repeaterData:s,type:r._type}):null):null)};async function z(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 a=e.lang??"en",n=e.fallbackLang??a,i=e.blocks.filter(o=>{const l=v.getRegisteredChaiBlock(o._type);return!!(L.has(l,"dataProvider")&&L.isFunction(l.dataProvider))}).reduce((o,l)=>{const r=v.getRegisteredChaiBlock(l._type),c={pageProps:e.pageProps,block:l,lang:e.lang,draft:e.draft,inBuilder:!1};return o[l._id]=r.dataProvider(c),o},{});return y.jsx(E,{...e,lang:a,fallbackLang:n,dataProviders:i})}function Q(e,a){const n=e.filter(({_type:s})=>s==="GlobalBlock"||s==="PartialBlock");for(let s=0;s<n.length;s++){const i=n[s],o=t.get(i,"partialBlockId",t.get(i,"globalBlock",""));if(o==="")continue;let l=t.cloneDeep(t.get(a,o,[]));i._parent&&(l==null?void 0:l.length)>0&&(l=l.map(c=>(t.isEmpty(c._parent)&&(c._parent=i._parent),c)));const r=e.indexOf(i);e.splice(r,1,...l)}return e}const X=e=>{if(!e)return[];try{return JSON.parse(Y(e)).filter(n=>!n._type.startsWith("@chai"))}catch{return[{_type:"Paragraph",_id:"error",content:"Invalid JSON. Please check the JSON string."}]}};function Y(e){const a=/(asset:\/\/|https:\/\/asset\.localhost\/)(?:localhost\/)?[^"']+/g;return e.replace(a,n=>{const s=decodeURIComponent(n),i=s.indexOf("public");return i!==-1?s.substring(i+6):s})}async function Z(e,a=[],n=!1){return await M.createTailwindcss({tailwindConfig:{darkMode:"class",safelist:a,theme:{extend:{...K.getChaiBuilderTheme(),keyframes:{"accordion-down":{from:{height:"0"},to:{height:"var(--radix-accordion-content-height)"}},"accordion-up":{from:{height:"var(--radix-accordion-content-height)"},to:{height:"0"}}},animation:{"accordion-down":"accordion-down 0.2s ease-out","accordion-up":"accordion-up 0.2s ease-out"}}},plugins:[D,j,q,O,C.chaiBuilderPlugin],corePlugins:{preflight:n}}}).generateStylesFromContent(` ${n?"@tailwind base;":""}
2
2
  @tailwind components;
3
- @tailwind utilities;`,e)}const K=(e,a)=>{const r=JSON.stringify(e).replace(/#styles:([^"]*)/g,(i,o)=>`#styles:${o.replace(/,/g," ")}`.replace(/#styles:/g,""));return O([r],[],a)},N=async(e,a=!1)=>await K(e,a);async function J(e){const a={pageProps:e.pageProps,block:e.block,lang:e.lang,draft:e.draft,inBuilder:!1},r=await e.dataProvider(a);return t.has(r,"$metadata")&&t.isFunction(e.dataProviderMetadataCallback)&&e.dataProviderMetadataCallback(e.block,r.$metadata),e.children({...t.omit(r,"$metadata")})}const H=()=>m.jsx("div",{}),V=e=>{const{block:a,lang:r,fallbackLang:i,children:o,externalData:c,blocks:s,draft:n,pageProps:l,dataProviderMetadataCallback:y}=e,d=M.getRegisteredChaiBlock(a._type),h=t.get(d,"component",null),P=t.get(e.repeaterData,"index",-1),f=t.get(e.repeaterData,"dataKey",""),b=r===i?"":r,g=u.applyBindingToBlockProps(u.applyLanguage(a,b,d),c,{index:P,key:f}),C=u.getBlockTagAttributes(a,!1),T=U(s,a._id,u.getBlockRuntimeProps(a._type)),S=t.has(d,"dataProvider")&&t.isFunction(d.dataProvider),B={...g,...C,...T},w={blockProps:{},inBuilder:!1,lang:r||i,...B},v=t.get(B,"_show",!0);if(t.isNull(h)||!v)return null;if(S){const I=t.get(d,"suspenseFallback",H);return m.jsx(p.Suspense,{fallback:p.createElement(I),children:m.jsx(J,{lang:r,pageProps:l,block:B,dataProvider:d.dataProvider,...y?{dataProviderMetadataCallback:y}:{},draft:n,children:x=>p.createElement(h,{...w,...x,children:o({_id:a._id,_type:a._type,...t.isArray(g.repeaterItems)?{repeaterItems:u.applyLimit(g.repeaterItems,a),$repeaterItemsKey:g.$repeaterItemsKey,repeaterTotalItems:g.repeaterTotalItems??-1}:{}})})})})}return m.jsx(p.Suspense,{children:p.createElement(h,{...w,children:o({_id:a._id,_type:a._type,...t.isArray(g.repeaterItems)?{repeaterItems:u.applyLimit(g.repeaterItems,a),$repeaterItemsKey:g.$repeaterItemsKey,repeaterTotalItems:g.repeaterTotalItems??-1}:{}})})})},_=e=>{const{blocks:a,parent:r,repeaterData:i,type:o}=e;let c=t.uniqBy(t.filter(a,n=>t.has(n,"_id")&&(t.isEmpty(r)?!n._parent:n._parent===r)),"_id");const s=n=>t.filter(a,l=>l._parent===n).length>0;return(o==="Heading"||o==="Paragraph"||o==="Link")&&(c=u.adjustSpacingInContentBlocks(c)),t.map(c,n=>n?p.createElement(V,{...e,key:n._id,block:n},({_id:l,_type:y,repeaterItems:d,$repeaterItemsKey:h})=>y==="Repeater"?t.isArray(d)&&d.map((P,f)=>p.createElement(_,{...e,parent:n._id,key:`${t.get(n,"_parent","root")}-${n._id}-${f}`,repeaterData:{index:f,dataKey:h}})):s(l)?p.createElement(_,{...e,parent:n._id,key:`${t.get(n,"_parent","root")}-${n._id}`,repeaterData:i,type:n._type}):null):null)},U=(e,a,r)=>t.isEmpty(r)?{}:Object.entries(r).reduce((i,[o,c])=>{const s=[];let n=t.find(e,{_id:a});for(;n;)s.push(n),n=t.find(e,{_id:n._parent});const l=t.find(s,{_type:c.block});return l&&(i[o]=t.get(l,t.get(c,"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 a=e.lang??"en",r=e.fallbackLang??a;return m.jsx(_,{...e,lang:a,fallbackLang:r})}exports.getChaiThemeCssVariables=k.getChaiThemeCssVariables;exports.getThemeFontsCSSImport=k.getThemeFontsCSSImport;exports.getThemeFontsLinkMarkup=k.getThemeFontsLinkMarkup;exports.applyChaiDataBinding=u.applyChaiDataBinding;exports.convertHTMLToChaiBlocks=u.getBlocksFromHTML;exports.RenderChaiBlocks=W;exports.convertToBlocks=D;exports.getMergedPartialBlocks=j;exports.getStylesForBlocks=N;
3
+ @tailwind utilities;`,e)}const ee=(e,a)=>{const n=JSON.stringify(e).replace(/#styles:([^"]*)/g,(s,i)=>`#styles:${i.replace(/,/g," ")}`.replace(/#styles:/g,""));return Z([n],[],a)},te=async(e,a=!1)=>await ee(e,a);exports.getChaiThemeCssVariables=C.getChaiThemeCssVariables;exports.getThemeFontsCSSImport=C.getThemeFontsCSSImport;exports.getThemeFontsLinkMarkup=C.getThemeFontsLinkMarkup;exports.applyChaiDataBinding=d.applyChaiDataBinding;exports.convertHTMLToChaiBlocks=d.getBlocksFromHTML;exports.AsyncRenderChaiBlocks=z;exports.RenderChaiBlocks=V;exports.convertToBlocks=X;exports.getMergedPartialBlocks=Q;exports.getStylesForBlocks=te;
package/dist/render.d.ts CHANGED
@@ -4,6 +4,8 @@ import { JSX } from 'react/jsx-runtime';
4
4
 
5
5
  export declare const applyChaiDataBinding: (block: Record<string, string>, pageExternalData: Record<string, any>) => any;
6
6
 
7
+ export declare function AsyncRenderChaiBlocks(props: RenderChaiBlocksProps): Promise<JSX.Element>;
8
+
7
9
  declare type ChaiBlock<T = Record<string, any>> = {
8
10
  _id: string;
9
11
  _name?: string;
@@ -76,7 +78,7 @@ declare type HexColor = string;
76
78
 
77
79
  declare type HSLColor = string;
78
80
 
79
- export declare function RenderChaiBlocks(props: RenderChaiBlocksProps): JSX.Element;
81
+ export declare function RenderChaiBlocks(props: RenderChaiBlocksProps_2): JSX.Element;
80
82
 
81
83
  declare type RenderChaiBlocksProps = {
82
84
  blocks: ChaiBlock[];
@@ -89,6 +91,17 @@ declare type RenderChaiBlocksProps = {
89
91
  dataProviderMetadataCallback?: (block: ChaiBlock, meta: Record<string, any>) => void;
90
92
  };
91
93
 
94
+ declare type RenderChaiBlocksProps_2 = {
95
+ blocks: ChaiBlock[];
96
+ parent?: string;
97
+ externalData?: Record<string, any>;
98
+ lang?: string;
99
+ fallbackLang?: string;
100
+ pageProps?: ChaiPageProps;
101
+ draft?: boolean;
102
+ dataProviderMetadataCallback?: (block: ChaiBlock, meta: Record<string, any>) => void;
103
+ };
104
+
92
105
  export { }
93
106
 
94
107
  declare global {
package/dist/render.js CHANGED
@@ -1,53 +1,283 @@
1
- import { c as K } from "./plugin-BOcGV_IY.js";
2
- import { a as ve, b as Se, e as xe } from "./plugin-BOcGV_IY.js";
3
- import { a as M, b as O, g as A, c as N, d as I, e as J } from "./apply-binding-DCno1xQL.js";
4
- import { f as $e, h as Le } from "./apply-binding-DCno1xQL.js";
5
- import { get as s, cloneDeep as j, isEmpty as g, has as b, isFunction as x, omit as E, isNull as q, isArray as B, uniqBy as H, filter as v, map as U, find as _ } from "lodash-es";
6
- import V from "@tailwindcss/aspect-ratio";
7
- import W from "@tailwindcss/forms";
8
- import G from "@tailwindcss/typography";
9
- import "tailwindcss-animate";
10
- import { g as z } from "./get-chai-builder-theme-BarMkcGH.js";
11
- import { createTailwindcss as Q } from "@mhsdesign/jit-browser-tailwindcss";
12
- import X from "@tailwindcss/container-queries";
13
- import { jsx as f } from "react/jsx-runtime";
1
+ import { c as Q } from "./plugin-BOcGV_IY.js";
2
+ import { a as Ae, b as Me, e as Oe } from "./plugin-BOcGV_IY.js";
3
+ import { a as O, b as N, g as E, c as J, d as I, e as j } from "./apply-binding-DCno1xQL.js";
4
+ import { f as Ee, h as Je } from "./apply-binding-DCno1xQL.js";
5
+ import { jsx as m } from "react/jsx-runtime";
6
+ import { getRegisteredChaiBlock as C } from "@chaibuilder/runtime";
7
+ import { has as X, isFunction as Y } from "lodash";
8
+ import { has as B, isFunction as x, omit as q, get as c, isNull as H, isArray as b, uniqBy as W, filter as $, isEmpty as h, map as U, find as F, cloneDeep as Z } from "lodash-es";
14
9
  import { Suspense as S, createElement as u } from "react";
15
- import { getRegisteredChaiBlock as Y } from "@chaibuilder/runtime";
16
- function Be(e, t) {
17
- const a = e.filter(({ _type: n }) => n === "GlobalBlock" || n === "PartialBlock");
18
- for (let n = 0; n < a.length; n++) {
19
- const i = a[n], c = s(i, "partialBlockId", s(i, "globalBlock", ""));
20
- if (c === "") continue;
21
- let o = j(s(t, c, []));
22
- i._parent && (o == null ? void 0 : o.length) > 0 && (o = o.map((l) => (g(l._parent) && (l._parent = i._parent), l)));
23
- const r = e.indexOf(i);
24
- e.splice(r, 1, ...o);
10
+ import ee from "@tailwindcss/aspect-ratio";
11
+ import te from "@tailwindcss/forms";
12
+ import ae from "@tailwindcss/typography";
13
+ import "tailwindcss-animate";
14
+ import { g as re } from "./get-chai-builder-theme-BarMkcGH.js";
15
+ import { createTailwindcss as ne } from "@mhsdesign/jit-browser-tailwindcss";
16
+ import ie from "@tailwindcss/container-queries";
17
+ async function oe(e) {
18
+ const t = {
19
+ pageProps: e.pageProps,
20
+ block: e.block,
21
+ lang: e.lang,
22
+ draft: e.draft,
23
+ inBuilder: !1
24
+ }, r = await e.dataProvider(t);
25
+ return B(r, "$metadata") && x(e.dataProviderMetadataCallback) && e.dataProviderMetadataCallback(e.block, r.$metadata), e.children({
26
+ ...q(r, "$metadata")
27
+ });
28
+ }
29
+ const se = () => /* @__PURE__ */ m("div", {}), le = (e) => {
30
+ const { block: t, lang: r, fallbackLang: i, children: n, externalData: s, blocks: o, draft: a, pageProps: l, dataProviderMetadataCallback: k } = e, d = C(t._type), p = c(d, "component", null), _ = c(e.repeaterData, "index", -1), y = c(e.repeaterData, "dataKey", ""), f = O(
31
+ N(t, r === i ? "" : r, d),
32
+ s,
33
+ { index: _, key: y }
34
+ ), g = E(t, !1), L = V(o, t._id, J(t._type)), T = B(d, "dataProvider") && x(d.dataProvider), v = {
35
+ ...f,
36
+ ...g,
37
+ ...L
38
+ }, P = {
39
+ blockProps: {},
40
+ inBuilder: !1,
41
+ lang: r || i,
42
+ ...v
43
+ }, w = c(v, "_show", !0);
44
+ if (H(p) || !w) return null;
45
+ if (T) {
46
+ const D = c(d, "suspenseFallback", se);
47
+ return /* @__PURE__ */ m(S, { fallback: u(D), children: /* @__PURE__ */ m(
48
+ oe,
49
+ {
50
+ lang: r,
51
+ pageProps: l,
52
+ block: v,
53
+ dataProvider: d.dataProvider,
54
+ ...k ? { dataProviderMetadataCallback: k } : {},
55
+ draft: a,
56
+ children: (K) => u(p, {
57
+ ...P,
58
+ ...K,
59
+ children: n({
60
+ _id: t._id,
61
+ _type: t._type,
62
+ ...b(f.repeaterItems) ? {
63
+ repeaterItems: I(f.repeaterItems, t),
64
+ $repeaterItemsKey: f.$repeaterItemsKey,
65
+ repeaterTotalItems: f.repeaterTotalItems ?? -1
66
+ } : {}
67
+ })
68
+ })
69
+ }
70
+ ) });
71
+ }
72
+ return /* @__PURE__ */ m(S, { children: u(p, {
73
+ ...P,
74
+ children: n({
75
+ _id: t._id,
76
+ _type: t._type,
77
+ ...b(f.repeaterItems) ? {
78
+ repeaterItems: I(f.repeaterItems, t),
79
+ $repeaterItemsKey: f.$repeaterItemsKey,
80
+ repeaterTotalItems: f.repeaterTotalItems ?? -1
81
+ } : {}
82
+ })
83
+ }) });
84
+ }, R = (e) => {
85
+ const { blocks: t, parent: r, repeaterData: i, type: n } = e;
86
+ let s = W(
87
+ $(t, (a) => B(a, "_id") && (h(r) ? !a._parent : a._parent === r)),
88
+ "_id"
89
+ );
90
+ const o = (a) => $(t, (l) => l._parent === a).length > 0;
91
+ return (n === "Heading" || n === "Paragraph" || n === "Link") && (s = j(s)), U(s, (a) => a ? /* @__PURE__ */ u(le, { ...e, key: a._id, block: a }, ({ _id: l, _type: k, repeaterItems: d, $repeaterItemsKey: p }) => k === "Repeater" ? b(d) && d.map((_, y) => /* @__PURE__ */ u(
92
+ R,
93
+ {
94
+ ...e,
95
+ parent: a._id,
96
+ key: `${c(a, "_parent", "root")}-${a._id}-${y}`,
97
+ repeaterData: { index: y, dataKey: p }
98
+ }
99
+ )) : o(l) ? /* @__PURE__ */ u(
100
+ R,
101
+ {
102
+ ...e,
103
+ parent: a._id,
104
+ key: `${c(a, "_parent", "root")}-${a._id}`,
105
+ repeaterData: i,
106
+ type: a._type
107
+ }
108
+ ) : null) : null);
109
+ }, V = (e, t, r) => h(r) ? {} : Object.entries(r).reduce((i, [n, s]) => {
110
+ const o = [];
111
+ let a = F(e, { _id: t });
112
+ for (; a; )
113
+ o.push(a), a = F(e, { _id: a._parent });
114
+ const l = F(o, { _type: s.block });
115
+ return l && (i[n] = c(l, c(s, "prop"), null)), i;
116
+ }, {});
117
+ function xe(e) {
118
+ if (h(e.lang) && !h(e.fallbackLang))
119
+ throw new Error("lang prop is required when fallbackLang is provided");
120
+ if (h(e.blocks))
121
+ return null;
122
+ const t = e.lang ?? "en", r = e.fallbackLang ?? t;
123
+ return /* @__PURE__ */ m(R, { ...e, lang: t, fallbackLang: r });
124
+ }
125
+ async function ce(e) {
126
+ const t = await e.dataProvider;
127
+ return B(t, "$metadata") && x(e.dataProviderMetadataCallback) && e.dataProviderMetadataCallback(e.block, t.$metadata), e.children({
128
+ ...q(t, "$metadata")
129
+ });
130
+ }
131
+ const de = () => /* @__PURE__ */ m("div", {}), pe = async (e) => {
132
+ const {
133
+ block: t,
134
+ lang: r,
135
+ fallbackLang: i,
136
+ children: n,
137
+ externalData: s,
138
+ blocks: o,
139
+ draft: a,
140
+ pageProps: l,
141
+ dataProviderMetadataCallback: k,
142
+ dataProviders: d
143
+ } = e, p = C(t._type), _ = c(p, "component", null), y = c(e.repeaterData, "index", -1), M = c(e.repeaterData, "dataKey", ""), g = O(
144
+ N(t, r === i ? "" : r, p),
145
+ s,
146
+ { index: y, key: M }
147
+ ), L = E(t, !1), T = V(o, t._id, J(t._type)), v = B(p, "dataProvider") && x(p.dataProvider), P = {
148
+ ...g,
149
+ ...L,
150
+ ...T
151
+ }, w = {
152
+ blockProps: {},
153
+ inBuilder: !1,
154
+ lang: r || i,
155
+ ...P
156
+ }, D = c(P, "_show", !0);
157
+ if (H(_) || !D) return null;
158
+ if (v) {
159
+ const K = c(d, t._id, Promise.resolve({})), G = c(p, "suspenseFallback", de);
160
+ return /* @__PURE__ */ m(S, { fallback: u(G), children: /* @__PURE__ */ m(
161
+ ce,
162
+ {
163
+ lang: r,
164
+ pageProps: l,
165
+ block: P,
166
+ dataProvider: K,
167
+ ...k ? { dataProviderMetadataCallback: k } : {},
168
+ draft: a,
169
+ children: (z) => u(_, {
170
+ ...w,
171
+ ...z,
172
+ children: n({
173
+ _id: t._id,
174
+ _type: t._type,
175
+ ...b(g.repeaterItems) ? {
176
+ repeaterItems: I(g.repeaterItems, t),
177
+ $repeaterItemsKey: g.$repeaterItemsKey,
178
+ repeaterTotalItems: g.repeaterTotalItems ?? -1
179
+ } : {}
180
+ })
181
+ })
182
+ }
183
+ ) });
184
+ }
185
+ return /* @__PURE__ */ m(S, { children: u(_, {
186
+ ...w,
187
+ children: n({
188
+ _id: t._id,
189
+ _type: t._type,
190
+ ...b(g.repeaterItems) ? {
191
+ repeaterItems: I(g.repeaterItems, t),
192
+ $repeaterItemsKey: g.$repeaterItemsKey,
193
+ repeaterTotalItems: g.repeaterTotalItems ?? -1
194
+ } : {}
195
+ })
196
+ }) });
197
+ }, A = async (e) => {
198
+ const { blocks: t, parent: r, repeaterData: i, type: n } = e;
199
+ let s = W(
200
+ $(t, (a) => B(a, "_id") && (h(r) ? !a._parent : a._parent === r)),
201
+ "_id"
202
+ );
203
+ const o = (a) => $(t, (l) => l._parent === a).length > 0;
204
+ return (n === "Heading" || n === "Paragraph" || n === "Link") && (s = j(s)), U(s, (a) => a ? /* @__PURE__ */ u(pe, { dataProviders: e.dataProviders, ...e, key: a._id, block: a }, ({ _id: l, _type: k, repeaterItems: d, $repeaterItemsKey: p }) => k === "Repeater" ? b(d) && d.map((_, y) => /* @__PURE__ */ u(
205
+ A,
206
+ {
207
+ ...e,
208
+ parent: a._id,
209
+ key: `${c(a, "_parent", "root")}-${a._id}-${y}`,
210
+ repeaterData: { index: y, dataKey: p }
211
+ }
212
+ )) : o(l) ? /* @__PURE__ */ u(
213
+ A,
214
+ {
215
+ ...e,
216
+ parent: a._id,
217
+ key: `${c(a, "_parent", "root")}-${a._id}`,
218
+ repeaterData: i,
219
+ type: a._type
220
+ }
221
+ ) : null) : null);
222
+ };
223
+ async function Le(e) {
224
+ if (h(e.lang) && !h(e.fallbackLang))
225
+ throw new Error("lang prop is required when fallbackLang is provided");
226
+ if (h(e.blocks))
227
+ return null;
228
+ const t = e.lang ?? "en", r = e.fallbackLang ?? t, n = e.blocks.filter((s) => {
229
+ const o = C(s._type);
230
+ return !!(X(o, "dataProvider") && Y(o.dataProvider));
231
+ }).reduce(
232
+ (s, o) => {
233
+ const a = C(o._type), l = {
234
+ pageProps: e.pageProps,
235
+ block: o,
236
+ lang: e.lang,
237
+ draft: e.draft,
238
+ inBuilder: !1
239
+ };
240
+ return s[o._id] = a.dataProvider(l), s;
241
+ },
242
+ {}
243
+ );
244
+ return /* @__PURE__ */ m(A, { ...e, lang: t, fallbackLang: r, dataProviders: n });
245
+ }
246
+ function Te(e, t) {
247
+ const r = e.filter(({ _type: i }) => i === "GlobalBlock" || i === "PartialBlock");
248
+ for (let i = 0; i < r.length; i++) {
249
+ const n = r[i], s = c(n, "partialBlockId", c(n, "globalBlock", ""));
250
+ if (s === "") continue;
251
+ let o = Z(c(t, s, []));
252
+ n._parent && (o == null ? void 0 : o.length) > 0 && (o = o.map((l) => (h(l._parent) && (l._parent = n._parent), l)));
253
+ const a = e.indexOf(n);
254
+ e.splice(a, 1, ...o);
25
255
  }
26
256
  return e;
27
257
  }
28
- const Pe = (e) => {
258
+ const De = (e) => {
29
259
  if (!e) return [];
30
260
  try {
31
- return JSON.parse(Z(e)).filter((a) => !a._type.startsWith("@chai"));
261
+ return JSON.parse(ue(e)).filter((r) => !r._type.startsWith("@chai"));
32
262
  } catch {
33
263
  return [{ _type: "Paragraph", _id: "error", content: "Invalid JSON. Please check the JSON string." }];
34
264
  }
35
265
  };
36
- function Z(e) {
266
+ function ue(e) {
37
267
  const t = /(asset:\/\/|https:\/\/asset\.localhost\/)(?:localhost\/)?[^"']+/g;
38
- return e.replace(t, (a) => {
39
- const n = decodeURIComponent(a), i = n.indexOf("public");
40
- return i !== -1 ? n.substring(i + 6) : n;
268
+ return e.replace(t, (r) => {
269
+ const i = decodeURIComponent(r), n = i.indexOf("public");
270
+ return n !== -1 ? i.substring(n + 6) : i;
41
271
  });
42
272
  }
43
- async function ee(e, t = [], a = !1) {
44
- return await Q({
273
+ async function ge(e, t = [], r = !1) {
274
+ return await ne({
45
275
  tailwindConfig: {
46
276
  darkMode: "class",
47
277
  safelist: t,
48
278
  theme: {
49
279
  extend: {
50
- ...z(),
280
+ ...re(),
51
281
  keyframes: {
52
282
  "accordion-down": {
53
283
  from: {
@@ -72,136 +302,29 @@ async function ee(e, t = [], a = !1) {
72
302
  }
73
303
  }
74
304
  },
75
- plugins: [W, G, V, X, K],
76
- corePlugins: { preflight: a }
305
+ plugins: [te, ae, ee, ie, Q],
306
+ corePlugins: { preflight: r }
77
307
  }
78
308
  }).generateStylesFromContent(
79
- ` ${a ? "@tailwind base;" : ""}
309
+ ` ${r ? "@tailwind base;" : ""}
80
310
  @tailwind components;
81
311
  @tailwind utilities;`,
82
312
  e
83
313
  );
84
314
  }
85
- const te = (e, t) => {
86
- const a = JSON.stringify(e).replace(/#styles:([^"]*)/g, (n, i) => `#styles:${i.replace(/,/g, " ")}`.replace(/#styles:/g, ""));
87
- return ee([a], [], t);
88
- }, be = async (e, t = !1) => await te(e, t);
89
- async function ae(e) {
90
- const t = {
91
- pageProps: e.pageProps,
92
- block: e.block,
93
- lang: e.lang,
94
- draft: e.draft,
95
- inBuilder: !1
96
- }, a = await e.dataProvider(t);
97
- return b(a, "$metadata") && x(e.dataProviderMetadataCallback) && e.dataProviderMetadataCallback(e.block, a.$metadata), e.children({
98
- ...E(a, "$metadata")
99
- });
100
- }
101
- const re = () => /* @__PURE__ */ f("div", {}), ne = (e) => {
102
- const { block: t, lang: a, fallbackLang: n, children: i, externalData: c, blocks: o, draft: r, pageProps: l, dataProviderMetadataCallback: h } = e, d = Y(t._type), m = s(d, "component", null), w = s(e.repeaterData, "index", -1), k = s(e.repeaterData, "dataKey", ""), p = M(
103
- O(t, a === n ? "" : a, d),
104
- c,
105
- { index: w, key: k }
106
- ), T = A(t, !1), $ = ie(o, t._id, N(t._type)), L = b(d, "dataProvider") && x(d.dataProvider), y = {
107
- ...p,
108
- ...T,
109
- ...$
110
- }, C = {
111
- blockProps: {},
112
- inBuilder: !1,
113
- lang: a || n,
114
- ...y
115
- }, D = s(y, "_show", !0);
116
- if (q(m) || !D) return null;
117
- if (L) {
118
- const R = s(d, "suspenseFallback", re);
119
- return /* @__PURE__ */ f(S, { fallback: u(R), children: /* @__PURE__ */ f(
120
- ae,
121
- {
122
- lang: a,
123
- pageProps: l,
124
- block: y,
125
- dataProvider: d.dataProvider,
126
- ...h ? { dataProviderMetadataCallback: h } : {},
127
- draft: r,
128
- children: (F) => u(m, {
129
- ...C,
130
- ...F,
131
- children: i({
132
- _id: t._id,
133
- _type: t._type,
134
- ...B(p.repeaterItems) ? {
135
- repeaterItems: I(p.repeaterItems, t),
136
- $repeaterItemsKey: p.$repeaterItemsKey,
137
- repeaterTotalItems: p.repeaterTotalItems ?? -1
138
- } : {}
139
- })
140
- })
141
- }
142
- ) });
143
- }
144
- return /* @__PURE__ */ f(S, { children: u(m, {
145
- ...C,
146
- children: i({
147
- _id: t._id,
148
- _type: t._type,
149
- ...B(p.repeaterItems) ? {
150
- repeaterItems: I(p.repeaterItems, t),
151
- $repeaterItemsKey: p.$repeaterItemsKey,
152
- repeaterTotalItems: p.repeaterTotalItems ?? -1
153
- } : {}
154
- })
155
- }) });
156
- }, P = (e) => {
157
- const { blocks: t, parent: a, repeaterData: n, type: i } = e;
158
- let c = H(
159
- v(t, (r) => b(r, "_id") && (g(a) ? !r._parent : r._parent === a)),
160
- "_id"
161
- );
162
- const o = (r) => v(t, (l) => l._parent === r).length > 0;
163
- return (i === "Heading" || i === "Paragraph" || i === "Link") && (c = J(c)), U(c, (r) => r ? /* @__PURE__ */ u(ne, { ...e, key: r._id, block: r }, ({ _id: l, _type: h, repeaterItems: d, $repeaterItemsKey: m }) => h === "Repeater" ? B(d) && d.map((w, k) => /* @__PURE__ */ u(
164
- P,
165
- {
166
- ...e,
167
- parent: r._id,
168
- key: `${s(r, "_parent", "root")}-${r._id}-${k}`,
169
- repeaterData: { index: k, dataKey: m }
170
- }
171
- )) : o(l) ? /* @__PURE__ */ u(
172
- P,
173
- {
174
- ...e,
175
- parent: r._id,
176
- key: `${s(r, "_parent", "root")}-${r._id}`,
177
- repeaterData: n,
178
- type: r._type
179
- }
180
- ) : null) : null);
181
- }, ie = (e, t, a) => g(a) ? {} : Object.entries(a).reduce((n, [i, c]) => {
182
- const o = [];
183
- let r = _(e, { _id: t });
184
- for (; r; )
185
- o.push(r), r = _(e, { _id: r._parent });
186
- const l = _(o, { _type: c.block });
187
- return l && (n[i] = s(l, s(c, "prop"), null)), n;
188
- }, {});
189
- function we(e) {
190
- if (g(e.lang) && !g(e.fallbackLang))
191
- throw new Error("lang prop is required when fallbackLang is provided");
192
- if (g(e.blocks))
193
- return null;
194
- const t = e.lang ?? "en", a = e.fallbackLang ?? t;
195
- return /* @__PURE__ */ f(P, { ...e, lang: t, fallbackLang: a });
196
- }
315
+ const fe = (e, t) => {
316
+ const r = JSON.stringify(e).replace(/#styles:([^"]*)/g, (i, n) => `#styles:${n.replace(/,/g, " ")}`.replace(/#styles:/g, ""));
317
+ return ge([r], [], t);
318
+ }, Ke = async (e, t = !1) => await fe(e, t);
197
319
  export {
198
- we as RenderChaiBlocks,
199
- $e as applyChaiDataBinding,
200
- Le as convertHTMLToChaiBlocks,
201
- Pe as convertToBlocks,
202
- ve as getChaiThemeCssVariables,
203
- Be as getMergedPartialBlocks,
204
- be as getStylesForBlocks,
205
- Se as getThemeFontsCSSImport,
206
- xe as getThemeFontsLinkMarkup
320
+ Le as AsyncRenderChaiBlocks,
321
+ xe as RenderChaiBlocks,
322
+ Ee as applyChaiDataBinding,
323
+ Je as convertHTMLToChaiBlocks,
324
+ De as convertToBlocks,
325
+ Ae as getChaiThemeCssVariables,
326
+ Te as getMergedPartialBlocks,
327
+ Ke as getStylesForBlocks,
328
+ Me as getThemeFontsCSSImport,
329
+ Oe as getThemeFontsLinkMarkup
207
330
  };
@@ -1,5 +1,5 @@
1
1
  import { jsx as e, jsxs as c } from "react/jsx-runtime";
2
- import { d as N, N as D } from "./index-seEzvADJ.js";
2
+ import { d as N, N as D } from "./index-BjbJYOzg.js";
3
3
  import { a1 as v, a3 as S, a6 as j, a9 as w, v as y } from "./tooltip-Bz2MxMHf.js";
4
4
  import "clsx";
5
5
  import "tailwind-merge";
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),u=require("./index-ByCJl7aR.cjs"),n=require("./tooltip-CzZ7Fvt7.cjs");require("clsx");require("tailwind-merge");const S=({isOpen:m,onClose:l,editor:t,rteElement:f})=>{const r=u.usePageExternalData(),j=o=>{if(!t)return;const i=`{{${o}}}`;t.commands.focus();const{from:p,to:g}=t.state.selection;if(p!==g)t.chain().deleteSelection().insertContent(i).run();else{const{state:c}=t,s=c.selection.from,x=c.doc.textBetween(Math.max(0,s-1),s),a=c.doc.textBetween(s,Math.min(s+1,c.doc.content.size));let d="";s>0&&x!==" "&&!/[.,!?;:]/.test(x)&&(d=" ");let h="";a&&a!==" "&&!/[.,!?;:]/.test(a)&&(h=" "),t.chain().insertContent(d+i+h).run()}};return e.jsx(n.Dialog,{open:m,onOpenChange:o=>!o&&l(),children:e.jsxs(n.DialogContent,{className:"max-h-[90vh] overflow-y-auto sm:max-w-[800px]",children:[e.jsx(n.DialogHeader,{children:e.jsxs(n.DialogTitle,{className:"flex items-center justify-between pr-8",children:[e.jsx("span",{children:"Rich Text Editor"}),Object.keys(r).length>0&&e.jsxs("div",{className:"flex items-center",children:[e.jsx("span",{className:"mr-2 text-sm text-muted-foreground",children:"Add field:"}),e.jsx("div",{className:"rte-path-selector",children:e.jsx(u.NestedPathSelector,{data:r,onSelect:j})})]})]})}),f,e.jsx("div",{className:"mt-4 flex justify-end",children:e.jsx(n.Button,{onClick:l,children:"Done"})})]})})};exports.default=S;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),u=require("./index-DV1NenGF.cjs"),n=require("./tooltip-CzZ7Fvt7.cjs");require("clsx");require("tailwind-merge");const S=({isOpen:m,onClose:l,editor:t,rteElement:f})=>{const r=u.usePageExternalData(),j=o=>{if(!t)return;const i=`{{${o}}}`;t.commands.focus();const{from:p,to:g}=t.state.selection;if(p!==g)t.chain().deleteSelection().insertContent(i).run();else{const{state:c}=t,s=c.selection.from,x=c.doc.textBetween(Math.max(0,s-1),s),a=c.doc.textBetween(s,Math.min(s+1,c.doc.content.size));let d="";s>0&&x!==" "&&!/[.,!?;:]/.test(x)&&(d=" ");let h="";a&&a!==" "&&!/[.,!?;:]/.test(a)&&(h=" "),t.chain().insertContent(d+i+h).run()}};return e.jsx(n.Dialog,{open:m,onOpenChange:o=>!o&&l(),children:e.jsxs(n.DialogContent,{className:"max-h-[90vh] overflow-y-auto sm:max-w-[800px]",children:[e.jsx(n.DialogHeader,{children:e.jsxs(n.DialogTitle,{className:"flex items-center justify-between pr-8",children:[e.jsx("span",{children:"Rich Text Editor"}),Object.keys(r).length>0&&e.jsxs("div",{className:"flex items-center",children:[e.jsx("span",{className:"mr-2 text-sm text-muted-foreground",children:"Add field:"}),e.jsx("div",{className:"rte-path-selector",children:e.jsx(u.NestedPathSelector,{data:r,onSelect:j})})]})]})}),f,e.jsx("div",{className:"mt-4 flex justify-end",children:e.jsx(n.Button,{onClick:l,children:"Done"})})]})})};exports.default=S;
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": "3.1.17",
8
+ "version": "3.1.19",
9
9
  "type": "module",
10
10
  "repository": {
11
11
  "type": "git",
@@ -172,6 +172,7 @@
172
172
  "jsdoc": "^4.0.4",
173
173
  "msw": "^2.7.0",
174
174
  "postcss": "^8.5.1",
175
+ "prettier": "^3.6.2",
175
176
  "prettier-plugin-tailwindcss": "^0.6.11",
176
177
  "prop-types": "^15.8.1",
177
178
  "react": "19.2.0",