@chaibuilder/sdk 2.0.0-beta.81 → 2.0.0-beta.82

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.
Files changed (41) hide show
  1. package/dist/ChaiThemeFn-DcE5RdLQ.cjs +236 -0
  2. package/dist/ChaiThemeFn-DzirXKjI.js +237 -0
  3. package/dist/CodeEditor-C8_JzwHn.cjs +81 -0
  4. package/dist/CodeEditor-DdIk_PEV.js +81 -0
  5. package/dist/Topbar-62QmCKWL.cjs +18 -0
  6. package/dist/Topbar-Cqt0j3Yt.js +18 -0
  7. package/dist/context-menu-DHla8ofZ.js +893 -0
  8. package/dist/context-menu-DawHUIXd.cjs +923 -0
  9. package/dist/core.cjs +11709 -5
  10. package/dist/core.js +6845 -3957
  11. package/dist/getSplitClasses-BuALfSLX.js +54 -0
  12. package/dist/getSplitClasses-mbQmvwI3.cjs +53 -0
  13. package/dist/iconBase-BSrIcOaG.cjs +146 -0
  14. package/dist/iconBase-CWgVxu0A.js +147 -0
  15. package/dist/plugin-BcTnEZwx.cjs +26 -0
  16. package/dist/plugin-DGEKY3uC.js +27 -0
  17. package/dist/render.cjs +247 -2
  18. package/dist/render.js +205 -150
  19. package/dist/runtime.cjs +9 -1
  20. package/dist/sdk.css +1336 -1
  21. package/dist/tailwind.cjs +78 -1
  22. package/dist/tailwind.js +21 -19
  23. package/dist/ui.cjs +378 -1
  24. package/dist/ui.js +254 -244
  25. package/dist/web-blocks.cjs +1679 -2
  26. package/dist/web-blocks.js +747 -518
  27. package/package.json +1 -1
  28. package/dist/ChaiThemeFn-Cort9tch.js +0 -201
  29. package/dist/ChaiThemeFn-DQu-2Eh9.cjs +0 -13
  30. package/dist/CodeEditor-B2x4yruH.cjs +0 -1
  31. package/dist/CodeEditor-VcQsGvTM.js +0 -65
  32. package/dist/Topbar-BQsjWb-A.js +0 -16
  33. package/dist/Topbar-DEw_kBMz.cjs +0 -1
  34. package/dist/context-menu-C4lLV8gP.cjs +0 -1
  35. package/dist/context-menu-D5ViOi6K.js +0 -831
  36. package/dist/getSplitClasses-DodqA_KW.cjs +0 -1
  37. package/dist/getSplitClasses-DphwgQiE.js +0 -48
  38. package/dist/iconBase-Cn2BsTrq.cjs +0 -1
  39. package/dist/iconBase-DHfFLkem.js +0 -124
  40. package/dist/plugin-2xcljWGM.cjs +0 -1
  41. package/dist/plugin-kUMxtQR5.js +0 -24
package/dist/render.cjs CHANGED
@@ -1,3 +1,248 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("./ChaiThemeFn-DQu-2Eh9.cjs"),n=require("lodash-es"),f=require("./getSplitClasses-DodqA_KW.cjs"),F=require("@mhsdesign/jit-browser-tailwindcss"),O=require("@tailwindcss/aspect-ratio"),R=require("@tailwindcss/container-queries"),b=require("@tailwindcss/forms"),k=require("@tailwindcss/typography"),_=require("./plugin-2xcljWGM.cjs"),d=require("react/jsx-runtime"),w=require("@chaibuilder/runtime"),p=require("react"),$=require("tailwind-merge"),N=(e,r="")=>{const{classes:s}=f.getSplitChaiClasses(e),t=s.split(" ").map(i=>i.split(" ").map(c=>{if(c==="")return"";if(c.includes(":")){const l=c.split(":");return l[l.length-1]=r+n.last(l),l.join(":")}return`${r}${c}`}).join(" "));return n.flattenDeep(t).join(" ")},Y=e=>{if(!e)return[];try{return JSON.parse(A(e)).filter(s=>!s._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,s=>{const t=decodeURIComponent(s),i=t.indexOf("public");return i!==-1?t.substring(i+6):t})}async function I(e,r,s=[],t="",i){return await F.createTailwindcss({tailwindConfig:{darkMode:"class",safelist:s,theme:{extend:_.getChaiBuilderTheme(e)},plugins:[b,k,O,R,_.chaiBuilderPlugin],corePlugins:{preflight:i},...t?{prefix:`${t}`}:{}}}).generateStylesFromContent(` ${i?"@tailwind base;":""}
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const ChaiThemeFn = require("./ChaiThemeFn-DcE5RdLQ.cjs");
4
+ const lodashEs = require("lodash-es");
5
+ const getSplitClasses = require("./getSplitClasses-mbQmvwI3.cjs");
6
+ const jitBrowserTailwindcss = require("@mhsdesign/jit-browser-tailwindcss");
7
+ const aspectRatio = require("@tailwindcss/aspect-ratio");
8
+ const containerQueries = require("@tailwindcss/container-queries");
9
+ const forms = require("@tailwindcss/forms");
10
+ const typography = require("@tailwindcss/typography");
11
+ const plugin = require("./plugin-BcTnEZwx.cjs");
12
+ const jsxRuntime = require("react/jsx-runtime");
13
+ const runtime = require("@chaibuilder/runtime");
14
+ const React = require("react");
15
+ const tailwindMerge = require("tailwind-merge");
16
+ const addPrefixToClasses = (classes, prefix = "") => {
17
+ const { classes: classesString } = getSplitClasses.getSplitChaiClasses(classes);
18
+ const array = classesString.split(" ").map((item) => {
19
+ const classes2 = item.split(" ");
20
+ const newClasses = classes2.map((item2) => {
21
+ if (item2 === "") return "";
22
+ if (item2.includes(":")) {
23
+ const values = item2.split(":");
24
+ values[values.length - 1] = prefix + lodashEs.last(values);
25
+ return values.join(":");
26
+ }
27
+ return `${prefix}${item2}`;
28
+ });
29
+ return newClasses.join(" ");
30
+ });
31
+ return lodashEs.flattenDeep(array).join(" ");
32
+ };
33
+ const convertToBlocks = (chaiFormatContent) => {
34
+ if (!chaiFormatContent) return [];
35
+ try {
36
+ const blocks = JSON.parse(removeAssetPrefix(chaiFormatContent));
37
+ return blocks.filter((block) => !block._type.startsWith("@chai"));
38
+ } catch (error) {
39
+ return [{ _type: "Paragraph", _id: "error", content: "Invalid JSON. Please check the JSON string." }];
40
+ }
41
+ };
42
+ function removeAssetPrefix(input) {
43
+ const regex = /(asset:\/\/|https:\/\/asset\.localhost\/)(?:localhost\/)?[^"']+/g;
44
+ return input.replace(regex, (match) => {
45
+ const decodedUrl = decodeURIComponent(match);
46
+ const publicIndex = decodedUrl.indexOf("public");
47
+ if (publicIndex !== -1) {
48
+ return decodedUrl.substring(publicIndex + 6);
49
+ }
50
+ return decodedUrl;
51
+ });
52
+ }
53
+ async function getTailwindCSS(themeOptions, markupString, safelist = [], prefix = "", includeBaseStyles) {
54
+ const tailwind = jitBrowserTailwindcss.createTailwindcss({
55
+ tailwindConfig: {
56
+ darkMode: "class",
57
+ safelist,
58
+ theme: { extend: plugin.getChaiBuilderTheme(themeOptions) },
59
+ plugins: [forms, typography, aspectRatio, containerQueries, plugin.chaiBuilderPlugin],
60
+ corePlugins: { preflight: includeBaseStyles },
61
+ ...prefix ? { prefix: `${prefix}` } : {}
62
+ }
63
+ });
64
+ return await tailwind.generateStylesFromContent(
65
+ ` ${includeBaseStyles ? "@tailwind base;" : ""}
2
66
  @tailwind components;
3
- @tailwind utilities;`,r)}const M=(e,r,s)=>{const t=JSON.stringify(e).replace(/#styles:([^"]*)/g,(i,o)=>`#styles:${o.replace(/,/g," ")}`.replace(/#styles:/g,""));return I(r,[t],[],"",s)},J=async(e,r=m.defaultThemeOptions,s=!1)=>await M(e,r,s);async function K(e){const r=await(e==null?void 0:e.dataProvider(e.block,e.lang,e.metadata));return d.jsx(p.Suspense,{children:p.createElement(e.component,{...e.props,...r})})}const L=n.memoize((e,r)=>{const{baseClasses:s,classes:t}=f.getSplitChaiClasses(e),i=$.twMerge(s,t);return r===""?i.replace(f.STYLES_KEY,"").trim():N(i,r).replace(f.STYLES_KEY,"").trim()}),V=(e,r)=>{const s=n.cloneDeep(e);return n.forEach(n.keys(s),t=>{if(n.isString(s[t])){let i=s[t];const o=/\{\{(.*?)\}\}/g,u=i.match(o);u&&u.forEach(c=>{const l=c.slice(2,-2),S=n.get(r,l,c);i=i.replace(c,S)}),s[t]=i}}),s};function D(e,r){const s=n.get(e,`${r}_attrs`,{}),t=n.keys(s).join(" ");return n.includes(t,"x-show")&&!n.includes(t,"x-transition")&&(s["x-transition"]=""),s}function U(e,r){const s={};return Object.keys(e).forEach(t=>{if(n.isString(e[t])&&e[t].startsWith(f.STYLES_KEY)){const i=L(e[t],r);s[t]={className:i,...D(e,t)}}}),s}function z(e,r,s){if(n.isEmpty(r))return e;const t=n.cloneDeep(e),i=n.get(s,"i18nProps",[]);return n.forEach(n.keys(t),o=>{i.includes(o)&&!n.isEmpty(r)&&(t[o]=n.get(t,`${o}-${r}`,t[o]))}),t}const W=n.memoize(e=>{const r=w.getRegisteredChaiBlock(e),s=n.get(r,"schema.properties",{});return Object.fromEntries(Object.entries(s).filter(([,t])=>n.get(t,"runtime",!1)))}),Q=(e,r,s)=>n.isEmpty(s)?{}:Object.entries(s).reduce((t,[i,o])=>{const u=[];let c=n.find(e,{_id:r});for(;c;)u.push(c),c=n.find(e,{_id:c._parent});const l=n.find(u,{_type:o.block});return l&&(t[i]=n.get(l,n.get(o,"prop"),null)),t},{}),G=()=>d.jsx("span",{children:"Loading..."});function E({blocks:e,parent:r,classPrefix:s="",externalData:t={},blockModifierCallback:i=null,lang:o="",fallbackLang:u="",metadata:c={}}){const l=e,S=a=>U(a,s),j=r?n.filter(e,{_parent:r}):n.filter(e,a=>n.isEmpty(a._parent));return d.jsx(d.Fragment,{children:p.Children.toArray(j.map((a,B)=>{const y={},P=n.filter(l,{_parent:a._id});y.children=P.length>0?d.jsx(E,{externalData:t,classPrefix:s,parent:a._id,blocks:l,lang:o||u,metadata:c}):null;const g=w.getRegisteredChaiBlock(a._type);if(g!==null){let h=a;const C=g.component;h={...g.defaults,...a},i&&(h=i(h));const x=o===u?"":o,q=Q(l,a._id,W(a._type)),T=n.omit({blockProps:{},inBuilder:!1,...h,index:B,...V(z(a,x,g),t),...S(h),...y,...q,metadata:c,lang:o||u},["_parent"]);if(n.has(g,"dataProvider")){const v=n.get(g,"suspenseFallback",G);return d.jsx(p.Suspense,{fallback:p.createElement(v),children:d.jsx(K,{lang:o||u,metadata:c,dataProvider:g.dataProvider,block:a,component:C,props:T})})}return d.jsx(p.Suspense,{children:p.createElement(C,T)})}return d.jsxs("noscript",{children:[a._type," not found"]})}))})}exports.getChaiThemeCssVariables=m.getChaiThemeCssVariables;exports.getThemeFontsCSSImport=m.getThemeFontsCSSImport;exports.getThemeFontsLinkMarkup=m.getThemeFontsLinkMarkup;exports.RenderChaiBlocks=E;exports.convertToBlocks=Y;exports.getStylesForBlocks=J;
67
+ @tailwind utilities;`,
68
+ markupString
69
+ );
70
+ }
71
+ const getBlocksTailwindCSS = (blocks, themeOptions, includeBaseStyles) => {
72
+ const blocksString = JSON.stringify(blocks).replace(/#styles:([^"]*)/g, (_match, content) => {
73
+ return `#styles:${content.replace(/,/g, " ")}`.replace(/#styles:/g, "");
74
+ });
75
+ return getTailwindCSS(themeOptions, [blocksString], [], "", includeBaseStyles);
76
+ };
77
+ const getStylesForBlocks = async (blocks, themeOptions = ChaiThemeFn.defaultThemeOptions, includeBaseStyles = false) => {
78
+ return await getBlocksTailwindCSS(blocks, themeOptions, includeBaseStyles);
79
+ };
80
+ async function AsyncPropsBlock(props) {
81
+ const dataProps = await (props == null ? void 0 : props.dataProvider(props.block, props.lang, props.metadata));
82
+ return /* @__PURE__ */ jsxRuntime.jsx(React.Suspense, { children: React.createElement(props.component, { ...props.props, ...dataProps }) });
83
+ }
84
+ const generateClassNames = lodashEs.memoize((styles, classPrefix) => {
85
+ const { baseClasses, classes: classesString } = getSplitClasses.getSplitChaiClasses(styles);
86
+ const classes = tailwindMerge.twMerge(baseClasses, classesString);
87
+ if (classPrefix === "") return classes.replace(getSplitClasses.STYLES_KEY, "").trim();
88
+ return addPrefixToClasses(classes, classPrefix).replace(getSplitClasses.STYLES_KEY, "").trim();
89
+ });
90
+ const applyBinding = (block, pageExternalData) => {
91
+ const clonedBlock = lodashEs.cloneDeep(block);
92
+ lodashEs.forEach(lodashEs.keys(clonedBlock), (key) => {
93
+ if (lodashEs.isString(clonedBlock[key])) {
94
+ let value = clonedBlock[key];
95
+ const bindingRegex = /\{\{(.*?)\}\}/g;
96
+ const matches = value.match(bindingRegex);
97
+ if (matches) {
98
+ matches.forEach((match) => {
99
+ const binding = match.slice(2, -2);
100
+ const bindingValue = lodashEs.get(pageExternalData, binding, match);
101
+ value = value.replace(match, bindingValue);
102
+ });
103
+ }
104
+ clonedBlock[key] = value;
105
+ }
106
+ });
107
+ return clonedBlock;
108
+ };
109
+ function getElementAttrs(block, key) {
110
+ const attrs = lodashEs.get(block, `${key}_attrs`, {});
111
+ const attrsKeys = lodashEs.keys(attrs).join(" ");
112
+ if (lodashEs.includes(attrsKeys, "x-show") && !lodashEs.includes(attrsKeys, "x-transition")) {
113
+ attrs["x-transition"] = "";
114
+ }
115
+ return attrs;
116
+ }
117
+ function getStyleAttrs(block, classPrefix) {
118
+ const styles = {};
119
+ Object.keys(block).forEach((key) => {
120
+ if (lodashEs.isString(block[key]) && block[key].startsWith(getSplitClasses.STYLES_KEY)) {
121
+ const classes = generateClassNames(block[key], classPrefix);
122
+ styles[key] = {
123
+ className: classes,
124
+ ...getElementAttrs(block, key)
125
+ };
126
+ }
127
+ });
128
+ return styles;
129
+ }
130
+ function applyLanguage(_block, lang, blockDefinition) {
131
+ if (lodashEs.isEmpty(lang)) return _block;
132
+ const block = lodashEs.cloneDeep(_block);
133
+ const i18nProps = lodashEs.get(blockDefinition, "i18nProps", []);
134
+ lodashEs.forEach(lodashEs.keys(block), (key) => {
135
+ if (i18nProps.includes(key) && !lodashEs.isEmpty(lang)) {
136
+ block[key] = lodashEs.get(block, `${key}-${lang}`, block[key]);
137
+ }
138
+ });
139
+ return block;
140
+ }
141
+ const getRuntimeProps = lodashEs.memoize((blockType) => {
142
+ const chaiBlock = runtime.getRegisteredChaiBlock(blockType);
143
+ const props = lodashEs.get(chaiBlock, "schema.properties", {});
144
+ return Object.fromEntries(Object.entries(props).filter(([, value]) => lodashEs.get(value, "runtime", false)));
145
+ });
146
+ const getRuntimePropValues = (allBlocks, blockId, runtimeProps) => {
147
+ if (lodashEs.isEmpty(runtimeProps)) return {};
148
+ return Object.entries(runtimeProps).reduce((acc, [key, schema]) => {
149
+ const hierarchy = [];
150
+ let block = lodashEs.find(allBlocks, { _id: blockId });
151
+ while (block) {
152
+ hierarchy.push(block);
153
+ block = lodashEs.find(allBlocks, { _id: block._parent });
154
+ }
155
+ const matchingBlock = lodashEs.find(hierarchy, { _type: schema.block });
156
+ if (matchingBlock) {
157
+ acc[key] = lodashEs.get(matchingBlock, lodashEs.get(schema, "prop"), null);
158
+ }
159
+ return acc;
160
+ }, {});
161
+ };
162
+ const SuspenseFallback = () => /* @__PURE__ */ jsxRuntime.jsx("span", { children: "Loading..." });
163
+ function RenderChaiBlocks({
164
+ blocks,
165
+ parent,
166
+ classPrefix = "",
167
+ externalData = {},
168
+ blockModifierCallback = null,
169
+ lang = "",
170
+ fallbackLang = "",
171
+ metadata = {}
172
+ }) {
173
+ const allBlocks = blocks;
174
+ const getStyles = (block) => getStyleAttrs(block, classPrefix);
175
+ const filteredBlocks = parent ? lodashEs.filter(blocks, { _parent: parent }) : lodashEs.filter(blocks, (block) => lodashEs.isEmpty(block._parent));
176
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: React.Children.toArray(
177
+ filteredBlocks.map((block, index) => {
178
+ const attrs = {};
179
+ const blocks2 = lodashEs.filter(allBlocks, { _parent: block._id });
180
+ attrs.children = blocks2.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx(
181
+ RenderChaiBlocks,
182
+ {
183
+ externalData,
184
+ classPrefix,
185
+ parent: block._id,
186
+ blocks: allBlocks,
187
+ lang: lang || fallbackLang,
188
+ metadata
189
+ }
190
+ ) : null;
191
+ const blockDefinition = runtime.getRegisteredChaiBlock(block._type);
192
+ if (blockDefinition !== null) {
193
+ let syncedBlock = block;
194
+ const Component = blockDefinition.component;
195
+ syncedBlock = { ...blockDefinition.defaults, ...block };
196
+ if (blockModifierCallback) {
197
+ syncedBlock = blockModifierCallback(syncedBlock);
198
+ }
199
+ const langToUse = lang === fallbackLang ? "" : lang;
200
+ const runtimeProps = getRuntimePropValues(allBlocks, block._id, getRuntimeProps(block._type));
201
+ const props = lodashEs.omit(
202
+ {
203
+ blockProps: {},
204
+ inBuilder: false,
205
+ ...syncedBlock,
206
+ index,
207
+ ...applyBinding(applyLanguage(block, langToUse, blockDefinition), externalData),
208
+ ...getStyles(syncedBlock),
209
+ ...attrs,
210
+ ...runtimeProps,
211
+ metadata,
212
+ lang: lang || fallbackLang
213
+ },
214
+ ["_parent"]
215
+ );
216
+ if (lodashEs.has(blockDefinition, "dataProvider")) {
217
+ const suspenseFallback = lodashEs.get(
218
+ blockDefinition,
219
+ "suspenseFallback",
220
+ SuspenseFallback
221
+ );
222
+ return /* @__PURE__ */ jsxRuntime.jsx(React.Suspense, { fallback: React.createElement(suspenseFallback), children: /* @__PURE__ */ jsxRuntime.jsx(
223
+ AsyncPropsBlock,
224
+ {
225
+ lang: lang || fallbackLang,
226
+ metadata,
227
+ dataProvider: blockDefinition.dataProvider,
228
+ block,
229
+ component: Component,
230
+ props
231
+ }
232
+ ) });
233
+ }
234
+ return /* @__PURE__ */ jsxRuntime.jsx(React.Suspense, { children: React.createElement(Component, props) });
235
+ }
236
+ return /* @__PURE__ */ jsxRuntime.jsxs("noscript", { children: [
237
+ block._type,
238
+ " not found"
239
+ ] });
240
+ })
241
+ ) });
242
+ }
243
+ exports.getChaiThemeCssVariables = ChaiThemeFn.getChaiThemeCssVariables;
244
+ exports.getThemeFontsCSSImport = ChaiThemeFn.getThemeFontsCSSImport;
245
+ exports.getThemeFontsLinkMarkup = ChaiThemeFn.getThemeFontsLinkMarkup;
246
+ exports.RenderChaiBlocks = RenderChaiBlocks;
247
+ exports.convertToBlocks = convertToBlocks;
248
+ exports.getStylesForBlocks = getStylesForBlocks;