@chaibuilder/sdk 2.0.2 → 2.0.4

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 S=require("./ChaiThemeFn-DQu-2Eh9.cjs"),s=require("lodash-es"),f=require("./getSplitClasses-DodqA_KW.cjs"),$=require("@mhsdesign/jit-browser-tailwindcss"),b=require("@tailwindcss/aspect-ratio"),F=require("@tailwindcss/container-queries"),k=require("@tailwindcss/forms"),M=require("@tailwindcss/typography"),B=require("./plugin-2xcljWGM.cjs"),g=require("react/jsx-runtime"),T=require("@chaibuilder/runtime"),p=require("react"),N=require("tailwind-merge"),Y=(e,r="")=>{const{classes:n}=f.getSplitChaiClasses(e),t=n.split(" ").map(i=>i.split(" ").map(a=>{if(a==="")return"";if(a.includes(":")){const u=a.split(":");return u[u.length-1]=r+s.last(u),u.join(":")}return`${r}${a}`}).join(" "));return s.flattenDeep(t).join(" ")},I=e=>{if(!e)return[];try{return JSON.parse(A(e)).filter(n=>!n._type.startsWith("@chai"))}catch{return[{_type:"Paragraph",_id:"error",content:"Invalid JSON. Please check the JSON string."}]}};function A(e){const r=/(asset:\/\/|https:\/\/asset\.localhost\/)(?:localhost\/)?[^"']+/g;return e.replace(r,n=>{const t=decodeURIComponent(n),i=t.indexOf("public");return i!==-1?t.substring(i+6):t})}async function J(e,r,n=[],t="",i){return await $.createTailwindcss({tailwindConfig:{darkMode:"class",safelist:n,theme:{extend:B.getChaiBuilderTheme(e)},plugins:[k,M,b,F,B.chaiBuilderPlugin],corePlugins:{preflight:i},...t?{prefix:`${t}`}:{}}}).generateStylesFromContent(` ${i?"@tailwind base;":""}
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("./ChaiThemeFn-DQu-2Eh9.cjs"),s=require("lodash-es"),f=require("./getSplitClasses-DodqA_KW.cjs"),$=require("@mhsdesign/jit-browser-tailwindcss"),F=require("@tailwindcss/aspect-ratio"),b=require("@tailwindcss/container-queries"),M=require("@tailwindcss/forms"),k=require("@tailwindcss/typography"),B=require("./plugin-2xcljWGM.cjs"),g=require("react/jsx-runtime"),T=require("@chaibuilder/runtime"),p=require("react"),N=require("tailwind-merge"),Y=(e,r="")=>{const{classes:n}=f.getSplitChaiClasses(e),t=n.split(" ").map(i=>i.split(" ").map(c=>{if(c==="")return"";if(c.includes(":")){const u=c.split(":");return u[u.length-1]=r+s.last(u),u.join(":")}return`${r}${c}`}).join(" "));return s.flattenDeep(t).join(" ")},I=e=>{if(!e)return[];try{return JSON.parse(A(e)).filter(n=>!n._type.startsWith("@chai"))}catch{return[{_type:"Paragraph",_id:"error",content:"Invalid JSON. Please check the JSON string."}]}};function A(e){const r=/(asset:\/\/|https:\/\/asset\.localhost\/)(?:localhost\/)?[^"']+/g;return e.replace(r,n=>{const t=decodeURIComponent(n),i=t.indexOf("public");return i!==-1?t.substring(i+6):t})}async function J(e,r,n=[],t="",i){return await $.createTailwindcss({tailwindConfig:{darkMode:"class",safelist:n,theme:{extend:B.getChaiBuilderTheme(e)},plugins:[M,k,F,b,B.chaiBuilderPlugin],corePlugins:{preflight:i},...t?{prefix:`${t}`}:{}}}).generateStylesFromContent(` ${i?"@tailwind base;":""}
2
2
  @tailwind components;
3
- @tailwind utilities;`,r)}const K=(e,r,n)=>{const t=JSON.stringify(e).replace(/#styles:([^"]*)/g,(i,o)=>`#styles:${o.replace(/,/g," ")}`.replace(/#styles:/g,""));return J(r,[t],[],"",n)},L=async(e,r=S.defaultThemeOptions,n=!1)=>await K(e,r,n);async function V(e){const r=await(e==null?void 0:e.dataProvider(e.block,e.lang,e.metadata));return s.has(r,"$metadata")&&e.dataProviderMetadataCallback(e.block,r.$metadata),g.jsx(p.Suspense,{children:p.createElement(e.component,{...s.omit(e.props,["dataProvider","dataProviderMetadataCallback"]),...s.omit(r,"$metadata")})})}const U=s.memoize((e,r)=>{const{baseClasses:n,classes:t}=f.getSplitChaiClasses(e),i=N.twMerge(n,t);return r===""?i.replace(f.STYLES_KEY,"").trim():Y(i,r).replace(f.STYLES_KEY,"").trim()}),j=(e,r)=>{const n=s.cloneDeep(e);return s.forEach(s.keys(n),t=>{if(s.isString(n[t])){let i=n[t];const o=/\{\{(.*?)\}\}/g,l=i.match(o);l&&l.forEach(a=>{const u=a.slice(2,-2),h=s.get(r,u,a);i=i.replace(a,h)}),n[t]=i}s.isObject(n[t])&&(n[t]=j(n[t],r))}),n};function z(e,r){const n=s.get(e,`${r}_attrs`,{}),t=s.keys(n).join(" ");return s.includes(t,"x-show")&&!s.includes(t,"x-transition")&&(n["x-transition"]=""),n}function D(e,r){const n={};return Object.keys(e).forEach(t=>{if(s.isString(e[t])&&e[t].startsWith(f.STYLES_KEY)){const i=U(e[t],r);n[t]={className:i,...z(e,t)}}}),n}function W(e,r,n){if(s.isEmpty(r))return e;const t=s.cloneDeep(e),i=s.get(n,"i18nProps",[]);return s.forEach(s.keys(t),o=>{i.includes(o)&&!s.isEmpty(r)&&(t[o]=s.get(t,`${o}-${r}`,t[o]))}),t}const Q=s.memoize(e=>{const r=T.getRegisteredChaiBlock(e),n=s.get(r,"schema.properties",{});return Object.fromEntries(Object.entries(n).filter(([,t])=>s.get(t,"runtime",!1)))}),G=(e,r,n)=>s.isEmpty(n)?{}:Object.entries(n).reduce((t,[i,o])=>{const l=[];let a=s.find(e,{_id:r});for(;a;)l.push(a),a=s.find(e,{_id:a._parent});const u=s.find(l,{_type:o.block});return u&&(t[i]=s.get(u,s.get(o,"prop"),null)),t},{}),H=()=>g.jsx("span",{children:"Loading..."});function E({blocks:e,parent:r,classPrefix:n="",externalData:t={},blockModifierCallback:i=null,lang:o="",fallbackLang:l="",metadata:a={},dataProviderMetadataCallback:u=()=>{}}){const h=e,P=c=>D(c,n);return(r?s.filter(e,{_parent:r}):s.filter(e,c=>s.isEmpty(c._parent))).map((c,v)=>{const C={},q=s.filter(h,{_parent:c._id});C.children=q.length>0?g.jsx(E,{externalData:t,classPrefix:n,parent:c._id,blocks:h,lang:o||l,metadata:a},c._id):null;const d=T.getRegisteredChaiBlock(c._type);if(d!==null){let m=c;const y=d.component;m={...d.defaults,...c},i&&(m=i(m));const x=o===l?"":o,O=G(h,c._id,Q(c._type)),_=j(W(c,x,d),t),w=s.omit({blockProps:{},inBuilder:!1,...m,index:v,..._,...P(_),...C,...O,metadata:a,lang:o||l},["_parent"]);if(s.has(d,"dataProvider")){const R=s.get(d,"suspenseFallback",H);return g.jsx(p.Suspense,{fallback:p.createElement(R),children:g.jsx(V,{dataProviderMetadataCallback:u,lang:o||l,metadata:a,dataProvider:d.dataProvider,block:c,component:y,props:w})},c._id)}return g.jsx(p.Suspense,{children:p.createElement(y,w)},c._id)}return g.jsxs("noscript",{children:[c._type," not found"]},c._id)})}exports.getChaiThemeCssVariables=S.getChaiThemeCssVariables;exports.getThemeFontsCSSImport=S.getThemeFontsCSSImport;exports.getThemeFontsLinkMarkup=S.getThemeFontsLinkMarkup;exports.RenderChaiBlocks=E;exports.convertToBlocks=I;exports.getStylesForBlocks=L;
3
+ @tailwind utilities;`,r)}const K=(e,r,n)=>{const t=JSON.stringify(e).replace(/#styles:([^"]*)/g,(i,a)=>`#styles:${a.replace(/,/g," ")}`.replace(/#styles:/g,""));return J(r,[t],[],"",n)},L=async(e,r=S.defaultThemeOptions,n=!1)=>await K(e,r,n);async function V(e){const r=await(e==null?void 0:e.dataProvider(e.block,e.lang,e.metadata));return s.has(r,"$metadata")&&e.dataProviderMetadataCallback(e.block,r.$metadata),g.jsx(p.Suspense,{children:p.createElement(e.component,{...s.omit(e.props,["dataProvider","dataProviderMetadataCallback"]),...s.omit(r,"$metadata")})})}const U=s.memoize((e,r)=>{const{baseClasses:n,classes:t}=f.getSplitChaiClasses(e),i=N.twMerge(n,t);return r===""?i.replace(f.STYLES_KEY,"").trim():Y(i,r).replace(f.STYLES_KEY,"").trim()}),j=(e,r)=>{const n=s.cloneDeep(e);return s.forEach(s.keys(n),t=>{if(s.isString(n[t])){let i=n[t];const a=/\{\{(.*?)\}\}/g,l=i.match(a);l&&l.forEach(c=>{const u=c.slice(2,-2),h=s.get(r,u,c);i=i.replace(c,h)}),n[t]=i}s.isObject(n[t])&&(n[t]=j(n[t],r))}),n};function z(e,r){const n=s.get(e,`${r}_attrs`,{}),t=s.keys(n).join(" ");return s.includes(t,"x-show")&&!s.includes(t,"x-transition")&&(n["x-transition"]=""),n}function D(e,r){const n={};return Object.keys(e).forEach(t=>{if(s.isString(e[t])&&e[t].startsWith(f.STYLES_KEY)){const i=U(e[t],r);n[t]={className:i,...z(e,t)}}}),n}function W(e,r,n){if(s.isEmpty(r))return e;const t=s.cloneDeep(e),i=s.get(n,"i18nProps",[]);return s.forEach(s.keys(t),a=>{i.includes(a)&&!s.isEmpty(r)&&(t[a]=s.get(t,`${a}-${r}`,t[a]))}),t}const Q=s.memoize(e=>{const r=T.getRegisteredChaiBlock(e),n=s.get(r,"schema.properties",{});return Object.fromEntries(Object.entries(n).filter(([,t])=>s.get(t,"runtime",!1)))}),G=(e,r,n)=>s.isEmpty(n)?{}:Object.entries(n).reduce((t,[i,a])=>{const l=[];let c=s.find(e,{_id:r});for(;c;)l.push(c),c=s.find(e,{_id:c._parent});const u=s.find(l,{_type:a.block});return u&&(t[i]=s.get(u,s.get(a,"prop"),null)),t},{}),H=()=>g.jsx("span",{children:"Loading..."});function E({blocks:e,parent:r,classPrefix:n="",externalData:t={},blockModifierCallback:i=null,lang:a="",fallbackLang:l="",metadata:c={},dataProviderMetadataCallback:u=()=>{}}){const h=e,P=o=>D(o,n);return(r?s.filter(e,{_parent:r}):s.filter(e,o=>s.isEmpty(o._parent))).map((o,v)=>{const C={},q=s.filter(h,{_parent:o._id});C.children=q.length>0?g.jsx(E,{externalData:t,classPrefix:n,parent:o._id,blocks:h,lang:a||l,metadata:c},o._id):null;const d=T.getRegisteredChaiBlock(o._type);if(d!==null){let m=o;const y=d.component;m={...d.defaults,...o},i&&(m=i(m));const x=a===l?"":a,O=G(h,o._id,Q(o._type)),_=j(W(o,x,d),t),w=s.omit({blockProps:{},inBuilder:!1,...m,index:v,..._,...P(_),...C,...O,metadata:c,lang:a||l,key:o._id},["_parent"]);if(s.has(d,"dataProvider")){const R=s.get(d,"suspenseFallback",H);return g.jsx(p.Suspense,{fallback:p.createElement(R),children:g.jsx(V,{dataProviderMetadataCallback:u,lang:a||l,metadata:c,dataProvider:d.dataProvider,block:o,component:y,props:w},o._id)},o._id)}return g.jsx(p.Suspense,{children:p.createElement(y,w)},o._id)}return g.jsxs("noscript",{children:[o._type," not found"]},o._id)})}exports.getChaiThemeCssVariables=S.getChaiThemeCssVariables;exports.getThemeFontsCSSImport=S.getThemeFontsCSSImport;exports.getThemeFontsLinkMarkup=S.getThemeFontsLinkMarkup;exports.RenderChaiBlocks=E;exports.convertToBlocks=I;exports.getStylesForBlocks=L;
package/dist/render.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { d as W } from "./ChaiThemeFn-Cort9tch.js";
2
2
  import { a as Ft, b as Nt, c as At } from "./ChaiThemeFn-Cort9tch.js";
3
- import { last as Y, flattenDeep as z, has as O, omit as S, memoize as $, get as d, filter as h, isEmpty as g, cloneDeep as E, forEach as x, keys as y, isString as b, isObject as D, find as _, includes as j } from "lodash-es";
4
- import { g as R, S as C } from "./getSplitClasses-DphwgQiE.js";
3
+ import { last as Y, flattenDeep as z, has as O, omit as S, memoize as $, get as d, filter as h, isEmpty as g, cloneDeep as E, forEach as x, keys as w, isString as R, isObject as D, find as _, includes as j } from "lodash-es";
4
+ import { g as b, S as y } from "./getSplitClasses-DphwgQiE.js";
5
5
  import { createTailwindcss as L } from "@mhsdesign/jit-browser-tailwindcss";
6
6
  import Q from "@tailwindcss/aspect-ratio";
7
7
  import q from "@tailwindcss/container-queries";
@@ -10,10 +10,10 @@ import H from "@tailwindcss/typography";
10
10
  import { g as X, c as Z } from "./plugin-kUMxtQR5.js";
11
11
  import { jsx as p, jsxs as k } from "react/jsx-runtime";
12
12
  import { getRegisteredChaiBlock as F } from "@chaibuilder/runtime";
13
- import N, { Suspense as w, createElement as tt } from "react";
13
+ import N, { Suspense as C, createElement as tt } from "react";
14
14
  import { twMerge as et } from "tailwind-merge";
15
15
  const nt = (t, s = "") => {
16
- const { classes: n } = R(t), e = n.split(" ").map((r) => r.split(" ").map((a) => {
16
+ const { classes: n } = b(t), e = n.split(" ").map((r) => r.split(" ").map((a) => {
17
17
  if (a === "") return "";
18
18
  if (a.includes(":")) {
19
19
  const l = a.split(":");
@@ -55,25 +55,25 @@ async function rt(t, s, n = [], e = "", r) {
55
55
  );
56
56
  }
57
57
  const it = (t, s, n) => {
58
- const e = JSON.stringify(t).replace(/#styles:([^"]*)/g, (r, i) => `#styles:${i.replace(/,/g, " ")}`.replace(/#styles:/g, ""));
58
+ const e = JSON.stringify(t).replace(/#styles:([^"]*)/g, (r, o) => `#styles:${o.replace(/,/g, " ")}`.replace(/#styles:/g, ""));
59
59
  return rt(s, [e], [], "", n);
60
60
  }, xt = async (t, s = W, n = !1) => await it(t, s, n);
61
61
  async function ot(t) {
62
62
  const s = await (t == null ? void 0 : t.dataProvider(t.block, t.lang, t.metadata));
63
- return O(s, "$metadata") && t.dataProviderMetadataCallback(t.block, s.$metadata), /* @__PURE__ */ p(w, { children: N.createElement(t.component, {
63
+ return O(s, "$metadata") && t.dataProviderMetadataCallback(t.block, s.$metadata), /* @__PURE__ */ p(C, { children: N.createElement(t.component, {
64
64
  ...S(t.props, ["dataProvider", "dataProviderMetadataCallback"]),
65
65
  ...S(s, "$metadata")
66
66
  }) });
67
67
  }
68
68
  const at = $((t, s) => {
69
- const { baseClasses: n, classes: e } = R(t), r = et(n, e);
70
- return s === "" ? r.replace(C, "").trim() : nt(r, s).replace(C, "").trim();
69
+ const { baseClasses: n, classes: e } = b(t), r = et(n, e);
70
+ return s === "" ? r.replace(y, "").trim() : nt(r, s).replace(y, "").trim();
71
71
  }), A = (t, s) => {
72
72
  const n = E(t);
73
- return x(y(n), (e) => {
74
- if (b(n[e])) {
73
+ return x(w(n), (e) => {
74
+ if (R(n[e])) {
75
75
  let r = n[e];
76
- const i = /\{\{(.*?)\}\}/g, c = r.match(i);
76
+ const o = /\{\{(.*?)\}\}/g, c = r.match(o);
77
77
  c && c.forEach((a) => {
78
78
  const l = a.slice(2, -2), m = d(s, l, a);
79
79
  r = r.replace(a, m);
@@ -83,13 +83,13 @@ const at = $((t, s) => {
83
83
  }), n;
84
84
  };
85
85
  function ct(t, s) {
86
- const n = d(t, `${s}_attrs`, {}), e = y(n).join(" ");
86
+ const n = d(t, `${s}_attrs`, {}), e = w(n).join(" ");
87
87
  return j(e, "x-show") && !j(e, "x-transition") && (n["x-transition"] = ""), n;
88
88
  }
89
89
  function lt(t, s) {
90
90
  const n = {};
91
91
  return Object.keys(t).forEach((e) => {
92
- if (b(t[e]) && t[e].startsWith(C)) {
92
+ if (R(t[e]) && t[e].startsWith(y)) {
93
93
  const r = at(t[e], s);
94
94
  n[e] = {
95
95
  className: r,
@@ -101,20 +101,20 @@ function lt(t, s) {
101
101
  function dt(t, s, n) {
102
102
  if (g(s)) return t;
103
103
  const e = E(t), r = d(n, "i18nProps", []);
104
- return x(y(e), (i) => {
105
- r.includes(i) && !g(s) && (e[i] = d(e, `${i}-${s}`, e[i]));
104
+ return x(w(e), (o) => {
105
+ r.includes(o) && !g(s) && (e[o] = d(e, `${o}-${s}`, e[o]));
106
106
  }), e;
107
107
  }
108
108
  const ut = $((t) => {
109
109
  const s = F(t), n = d(s, "schema.properties", {});
110
110
  return Object.fromEntries(Object.entries(n).filter(([, e]) => d(e, "runtime", !1)));
111
- }), pt = (t, s, n) => g(n) ? {} : Object.entries(n).reduce((e, [r, i]) => {
111
+ }), pt = (t, s, n) => g(n) ? {} : Object.entries(n).reduce((e, [r, o]) => {
112
112
  const c = [];
113
113
  let a = _(t, { _id: s });
114
114
  for (; a; )
115
115
  c.push(a), a = _(t, { _id: a._parent });
116
- const l = _(c, { _type: i.block });
117
- return l && (e[r] = d(l, d(i, "prop"), null)), e;
116
+ const l = _(c, { _type: o.block });
117
+ return l && (e[r] = d(l, d(o, "prop"), null)), e;
118
118
  }, {}), mt = () => /* @__PURE__ */ p("span", { children: "Loading..." });
119
119
  function ft({
120
120
  blocks: t,
@@ -122,33 +122,33 @@ function ft({
122
122
  classPrefix: n = "",
123
123
  externalData: e = {},
124
124
  blockModifierCallback: r = null,
125
- lang: i = "",
125
+ lang: o = "",
126
126
  fallbackLang: c = "",
127
127
  metadata: a = {},
128
128
  dataProviderMetadataCallback: l = () => {
129
129
  }
130
130
  }) {
131
- const m = t, I = (o) => lt(o, n);
132
- return (s ? h(t, { _parent: s }) : h(t, (o) => g(o._parent))).map((o, J) => {
133
- const P = {}, M = h(m, { _parent: o._id });
131
+ const m = t, I = (i) => lt(i, n);
132
+ return (s ? h(t, { _parent: s }) : h(t, (i) => g(i._parent))).map((i, J) => {
133
+ const P = {}, M = h(m, { _parent: i._id });
134
134
  P.children = M.length > 0 ? /* @__PURE__ */ p(
135
135
  ft,
136
136
  {
137
137
  externalData: e,
138
138
  classPrefix: n,
139
- parent: o._id,
139
+ parent: i._id,
140
140
  blocks: m,
141
- lang: i || c,
141
+ lang: o || c,
142
142
  metadata: a
143
143
  },
144
- o._id
144
+ i._id
145
145
  ) : null;
146
- const u = F(o._type);
146
+ const u = F(i._type);
147
147
  if (u !== null) {
148
- let f = o;
148
+ let f = i;
149
149
  const B = u.component;
150
- f = { ...u.defaults, ...o }, r && (f = r(f));
151
- const U = i === c ? "" : i, V = pt(m, o._id, ut(o._type)), v = A(dt(o, U, u), e), T = S(
150
+ f = { ...u.defaults, ...i }, r && (f = r(f));
151
+ const U = o === c ? "" : o, V = pt(m, i._id, ut(i._type)), v = A(dt(i, U, u), e), T = S(
152
152
  {
153
153
  blockProps: {},
154
154
  inBuilder: !1,
@@ -159,31 +159,33 @@ function ft({
159
159
  ...P,
160
160
  ...V,
161
161
  metadata: a,
162
- lang: i || c
162
+ lang: o || c,
163
+ key: i._id
163
164
  },
164
165
  ["_parent"]
165
166
  );
166
167
  if (O(u, "dataProvider")) {
167
168
  const K = d(u, "suspenseFallback", mt);
168
- return /* @__PURE__ */ p(w, { fallback: tt(K), children: /* @__PURE__ */ p(
169
+ return /* @__PURE__ */ p(C, { fallback: tt(K), children: /* @__PURE__ */ p(
169
170
  ot,
170
171
  {
171
172
  dataProviderMetadataCallback: l,
172
- lang: i || c,
173
+ lang: o || c,
173
174
  metadata: a,
174
175
  dataProvider: u.dataProvider,
175
- block: o,
176
+ block: i,
176
177
  component: B,
177
178
  props: T
178
- }
179
- ) }, o._id);
179
+ },
180
+ i._id
181
+ ) }, i._id);
180
182
  }
181
- return /* @__PURE__ */ p(w, { children: N.createElement(B, T) }, o._id);
183
+ return /* @__PURE__ */ p(C, { children: N.createElement(B, T) }, i._id);
182
184
  }
183
185
  return /* @__PURE__ */ k("noscript", { children: [
184
- o._type,
186
+ i._type,
185
187
  " not found"
186
- ] }, o._id);
188
+ ] }, i._id);
187
189
  });
188
190
  }
189
191
  export {
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.0.2",
8
+ "version": "2.0.4",
9
9
  "type": "module",
10
10
  "repository": {
11
11
  "type": "git",