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