@chaibuilder/sdk 2.0.0-beta.81 → 2.0.0-beta.83
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/ChaiThemeFn-DcE5RdLQ.cjs +236 -0
- package/dist/ChaiThemeFn-DzirXKjI.js +237 -0
- package/dist/CodeEditor-C8_JzwHn.cjs +81 -0
- package/dist/CodeEditor-DdIk_PEV.js +81 -0
- package/dist/Topbar-62QmCKWL.cjs +18 -0
- package/dist/Topbar-Cqt0j3Yt.js +18 -0
- package/dist/context-menu-DHla8ofZ.js +893 -0
- package/dist/context-menu-DawHUIXd.cjs +923 -0
- package/dist/core.cjs +11710 -5
- package/dist/core.js +6846 -3957
- package/dist/getSplitClasses-BuALfSLX.js +54 -0
- package/dist/getSplitClasses-mbQmvwI3.cjs +53 -0
- package/dist/iconBase-BSrIcOaG.cjs +146 -0
- package/dist/iconBase-CWgVxu0A.js +147 -0
- package/dist/plugin-BcTnEZwx.cjs +26 -0
- package/dist/plugin-DGEKY3uC.js +27 -0
- package/dist/render.cjs +247 -2
- package/dist/render.js +205 -150
- package/dist/runtime.cjs +9 -1
- package/dist/sdk.css +1336 -1
- package/dist/tailwind.cjs +78 -1
- package/dist/tailwind.js +21 -19
- package/dist/ui.cjs +378 -1
- package/dist/ui.js +254 -244
- package/dist/web-blocks.cjs +1679 -2
- package/dist/web-blocks.js +747 -518
- package/package.json +1 -1
- package/dist/ChaiThemeFn-Cort9tch.js +0 -201
- package/dist/ChaiThemeFn-DQu-2Eh9.cjs +0 -13
- package/dist/CodeEditor-B2x4yruH.cjs +0 -1
- package/dist/CodeEditor-VcQsGvTM.js +0 -65
- package/dist/Topbar-BQsjWb-A.js +0 -16
- package/dist/Topbar-DEw_kBMz.cjs +0 -1
- package/dist/context-menu-C4lLV8gP.cjs +0 -1
- package/dist/context-menu-D5ViOi6K.js +0 -831
- package/dist/getSplitClasses-DodqA_KW.cjs +0 -1
- package/dist/getSplitClasses-DphwgQiE.js +0 -48
- package/dist/iconBase-Cn2BsTrq.cjs +0 -1
- package/dist/iconBase-DHfFLkem.js +0 -124
- package/dist/plugin-2xcljWGM.cjs +0 -1
- package/dist/plugin-kUMxtQR5.js +0 -24
package/dist/render.cjs
CHANGED
|
@@ -1,3 +1,248 @@
|
|
|
1
|
-
"use strict";
|
|
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;`,
|
|
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;
|