@chaibuilder/sdk 1.3.0-beta.7 → 1.3.0-beta.8
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/CodeEditor-1LboGb1I.cjs +91 -0
- package/dist/CodeEditor-BKgZeXwz.js +91 -0
- package/dist/STRINGS-3Sn_NeX1.cjs +9 -0
- package/dist/STRINGS-DdpfVlsV.js +10 -0
- package/dist/Topbar-B8IS6y4H.js +135 -0
- package/dist/Topbar-DXC7DFU1.cjs +135 -0
- package/dist/UnsplashImages-CjJ5szAy.cjs +215 -0
- package/dist/UnsplashImages-Ck9qpKR0.js +215 -0
- package/dist/UploadImages-DW1mj4MB.cjs +117 -0
- package/dist/UploadImages-DgAMZ8GR.js +117 -0
- package/dist/context-menu-BLbuduri.cjs +1073 -0
- package/dist/context-menu-BgtRnByf.js +1042 -0
- package/dist/controls-8EZmm0Ns.js +234 -0
- package/dist/controls-DaW52RjX.cjs +233 -0
- package/dist/core.cjs +82 -1
- package/dist/core.js +74 -74
- package/dist/iconBase-BSrIcOaG.cjs +146 -0
- package/dist/iconBase-CWgVxu0A.js +147 -0
- package/dist/index-Bjw2sUN2.cjs +12139 -0
- package/dist/index-D8_rAW8B.js +12124 -0
- package/dist/jsx-runtime-B6vEU3CM.cjs +925 -0
- package/dist/jsx-runtime-ClFauRgV.js +926 -0
- package/dist/plugin-BYwesM58.cjs +54 -0
- package/dist/plugin-BiDLHDo3.cjs +114 -0
- package/dist/plugin-BukD7GJR.js +115 -0
- package/dist/plugin-tVAEvXiS.js +55 -0
- package/dist/render.cjs +208 -2
- package/dist/render.js +171 -125
- package/dist/runtime.cjs +26 -1
- package/dist/runtime.js +16 -16
- package/dist/style.css +1529 -2
- package/dist/tailwind.cjs +78 -1
- package/dist/tailwind.js +21 -19
- package/dist/ui.cjs +392 -1
- package/dist/ui.js +268 -257
- package/dist/web-blocks.cjs +1241 -3
- package/dist/web-blocks.js +764 -555
- package/package.json +1 -1
- package/dist/CodeEditor-CLJIUsvL.js +0 -77
- package/dist/CodeEditor-DrVE5UwR.cjs +0 -1
- package/dist/STRINGS-eiGM83kj.js +0 -7
- package/dist/STRINGS-ew98weUe.cjs +0 -1
- package/dist/Topbar-BvLH3BD9.cjs +0 -1
- package/dist/Topbar-D3bfoa2h.js +0 -113
- package/dist/UnsplashImages-3SDmSL-g.js +0 -189
- package/dist/UnsplashImages-Cx6vImSl.cjs +0 -1
- package/dist/UploadImages-CkjdUS7T.js +0 -101
- package/dist/UploadImages-aqkH-8LC.cjs +0 -1
- package/dist/context-menu-BbqLeYFX.js +0 -979
- package/dist/context-menu-DfAXjmc8.cjs +0 -1
- package/dist/controls-C4n5ycp4.cjs +0 -1
- package/dist/controls-Com-zYCq.js +0 -234
- package/dist/iconBase-Cn2BsTrq.cjs +0 -1
- package/dist/iconBase-DHfFLkem.js +0 -124
- package/dist/index-BlcnqLh_.js +0 -9236
- package/dist/index-DUJxGeyq.cjs +0 -63
- package/dist/jsx-runtime-BYECrxsp.cjs +0 -30
- package/dist/jsx-runtime-DGlMoOmv.js +0 -630
- package/dist/plugin-BOEoR5jk.js +0 -44
- package/dist/plugin-COMQcYlW.cjs +0 -1
- package/dist/plugin-Dw854zFv.js +0 -107
- package/dist/plugin-I9XxF65G.cjs +0 -1
package/dist/render.js
CHANGED
|
@@ -1,163 +1,209 @@
|
|
|
1
|
-
import { last
|
|
2
|
-
import { S as
|
|
3
|
-
import { j as
|
|
4
|
-
import
|
|
5
|
-
import { twMerge
|
|
6
|
-
import { getBlockComponent
|
|
7
|
-
import { createTailwindcss
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import { g as
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
1
|
+
import { last, flattenDeep, memoize, filter, isEmpty, omit, isString, get, each, cloneDeep, forEach, keys, has, includes, replace } from "lodash-es";
|
|
2
|
+
import { S as STYLES_KEY, a as SLOT_KEY } from "./STRINGS-DdpfVlsV.js";
|
|
3
|
+
import { j as jsxRuntimeExports } from "./jsx-runtime-ClFauRgV.js";
|
|
4
|
+
import React__default from "react";
|
|
5
|
+
import { twMerge } from "tailwind-merge";
|
|
6
|
+
import { getBlockComponent } from "@chaibuilder/runtime";
|
|
7
|
+
import { createTailwindcss } from "@mhsdesign/jit-browser-tailwindcss";
|
|
8
|
+
import forms from "@tailwindcss/forms";
|
|
9
|
+
import typography from "@tailwindcss/typography";
|
|
10
|
+
import aspectRatio from "@tailwindcss/aspect-ratio";
|
|
11
|
+
import { g as getChaiBuilderTheme, c as chaiBuilderPlugin } from "./plugin-tVAEvXiS.js";
|
|
12
|
+
const addPrefixToClasses = (classes, prefix = "") => {
|
|
13
|
+
const classesArray = classes.replace(STYLES_KEY, "").split(",");
|
|
14
|
+
const array = classesArray.map((item) => {
|
|
15
|
+
const classes2 = item.split(" ");
|
|
16
|
+
const newClasses = classes2.map((item2) => {
|
|
17
|
+
if (item2 === "") return "";
|
|
18
|
+
if (item2.includes(":")) {
|
|
19
|
+
const values = item2.split(":");
|
|
20
|
+
values[values.length - 1] = prefix + last(values);
|
|
21
|
+
return values.join(":");
|
|
22
|
+
}
|
|
23
|
+
return `${prefix}${item2}`;
|
|
24
|
+
});
|
|
25
|
+
return newClasses.join(" ");
|
|
26
|
+
});
|
|
27
|
+
return flattenDeep(array).join(" ");
|
|
28
|
+
};
|
|
29
|
+
const convertToBlocks = (chaiFormatContent) => {
|
|
30
|
+
if (!chaiFormatContent) return [];
|
|
24
31
|
try {
|
|
25
|
-
|
|
26
|
-
|
|
32
|
+
const blocks = JSON.parse(removeAssetPrefix(chaiFormatContent));
|
|
33
|
+
return blocks.filter((block) => !block._type.startsWith("@chai"));
|
|
34
|
+
} catch (error) {
|
|
27
35
|
return [{ _type: "Paragraph", _id: "error", content: "Invalid JSON. Please check the JSON string." }];
|
|
28
36
|
}
|
|
29
37
|
};
|
|
30
|
-
function
|
|
31
|
-
const
|
|
32
|
-
return
|
|
33
|
-
const
|
|
34
|
-
|
|
38
|
+
function removeAssetPrefix(input) {
|
|
39
|
+
const regex = /(asset:\/\/|https:\/\/asset\.localhost\/)(?:localhost\/)?[^"']+/g;
|
|
40
|
+
return input.replace(regex, (match) => {
|
|
41
|
+
const decodedUrl = decodeURIComponent(match);
|
|
42
|
+
const publicIndex = decodedUrl.indexOf("public");
|
|
43
|
+
if (publicIndex !== -1) {
|
|
44
|
+
return decodedUrl.substring(publicIndex + 6);
|
|
45
|
+
}
|
|
46
|
+
return decodedUrl;
|
|
35
47
|
});
|
|
36
48
|
}
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return
|
|
49
|
+
const getSlots = (block) => {
|
|
50
|
+
const slots = {};
|
|
51
|
+
Object.keys(block).forEach((key) => {
|
|
52
|
+
if (isString(block[key]) && block[key].startsWith(SLOT_KEY)) {
|
|
53
|
+
slots[key] = block[key].replace(SLOT_KEY, "").split(",");
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
return slots;
|
|
57
|
+
};
|
|
58
|
+
const generateClassNames = memoize((styles, classPrefix) => {
|
|
59
|
+
const stylesArray = styles.replace(STYLES_KEY, "").split(",");
|
|
60
|
+
const classes = twMerge(stylesArray[0], stylesArray[1]);
|
|
61
|
+
if (classPrefix === "") return classes.replace(STYLES_KEY, "").trim();
|
|
62
|
+
return addPrefixToClasses(classes, classPrefix).replace(STYLES_KEY, "").trim();
|
|
45
63
|
});
|
|
46
|
-
function
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
64
|
+
function getElementAttrs(block, key) {
|
|
65
|
+
const attrs = get(block, `${key}_attrs`, {});
|
|
66
|
+
if (has(attrs, "data-ai-key")) {
|
|
67
|
+
delete attrs["data-ai-key"];
|
|
68
|
+
}
|
|
69
|
+
const attrsKeys = keys(attrs).join(" ");
|
|
70
|
+
if (includes(attrsKeys, "x-show") && !includes(attrsKeys, "x-transition")) {
|
|
71
|
+
attrs["x-transition"] = "";
|
|
72
|
+
}
|
|
73
|
+
return attrs;
|
|
51
74
|
}
|
|
52
|
-
function
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
if (
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
className:
|
|
59
|
-
...
|
|
75
|
+
function getStyleAttrs(block, classPrefix) {
|
|
76
|
+
const styles = {};
|
|
77
|
+
Object.keys(block).forEach((key) => {
|
|
78
|
+
if (isString(block[key]) && block[key].startsWith(STYLES_KEY)) {
|
|
79
|
+
const classes = generateClassNames(block[key], classPrefix);
|
|
80
|
+
styles[key] = {
|
|
81
|
+
className: classes,
|
|
82
|
+
...getElementAttrs(block, key)
|
|
60
83
|
};
|
|
61
84
|
}
|
|
62
|
-
})
|
|
85
|
+
});
|
|
86
|
+
return styles;
|
|
63
87
|
}
|
|
64
|
-
function
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
88
|
+
function applyBindings(block, chaiData) {
|
|
89
|
+
const bindings = get(block, "_bindings", {});
|
|
90
|
+
if (isEmpty(bindings)) return { ...block };
|
|
91
|
+
each(bindings, (value, key) => {
|
|
92
|
+
if (isString(value) && get(chaiData, value, null)) {
|
|
93
|
+
block[key] = get(chaiData, value, null);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
return block;
|
|
69
97
|
}
|
|
70
|
-
function
|
|
71
|
-
if (
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
98
|
+
function applyLanguage(_block, lang, blockDefinition) {
|
|
99
|
+
if (isEmpty(lang)) return _block;
|
|
100
|
+
const block = cloneDeep(_block);
|
|
101
|
+
forEach(keys(block), (key) => {
|
|
102
|
+
if (get(blockDefinition, ["props", key, "i18n"]) && !isEmpty(lang)) {
|
|
103
|
+
block[key] = get(block, `${key}-${lang}`, block[key]);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
return block;
|
|
76
107
|
}
|
|
77
|
-
function
|
|
78
|
-
blocks
|
|
79
|
-
parent
|
|
80
|
-
classPrefix
|
|
81
|
-
externalData
|
|
82
|
-
blockModifierCallback
|
|
83
|
-
lang
|
|
108
|
+
function RenderChaiBlocks({
|
|
109
|
+
blocks,
|
|
110
|
+
parent,
|
|
111
|
+
classPrefix = "",
|
|
112
|
+
externalData = {},
|
|
113
|
+
blockModifierCallback,
|
|
114
|
+
lang
|
|
84
115
|
}) {
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
116
|
+
const allBlocks = blocks;
|
|
117
|
+
const getStyles = (block) => getStyleAttrs(block, classPrefix);
|
|
118
|
+
const filteredBlocks = parent ? filter(blocks, { _parent: parent }) : filter(blocks, (block) => isEmpty(block._parent));
|
|
119
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: React__default.Children.toArray(
|
|
120
|
+
filteredBlocks.map((block, index) => {
|
|
121
|
+
const slots = getSlots(block);
|
|
122
|
+
const attrs = {};
|
|
123
|
+
if (!isEmpty(slots)) {
|
|
124
|
+
Object.keys(slots).forEach((key) => {
|
|
125
|
+
attrs[key] = React__default.Children.toArray(
|
|
126
|
+
slots[key].map((slotId) => /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
127
|
+
RenderChaiBlocks,
|
|
128
|
+
{
|
|
129
|
+
externalData,
|
|
130
|
+
classPrefix,
|
|
131
|
+
blocks: allBlocks,
|
|
132
|
+
parent: slotId,
|
|
133
|
+
lang
|
|
134
|
+
}
|
|
135
|
+
))
|
|
136
|
+
);
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
const blocks2 = filter(allBlocks, { _parent: block._id });
|
|
140
|
+
attrs.children = blocks2.length > 0 ? /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
141
|
+
RenderChaiBlocks,
|
|
106
142
|
{
|
|
107
|
-
externalData
|
|
108
|
-
classPrefix
|
|
109
|
-
parent:
|
|
110
|
-
blocks:
|
|
111
|
-
lang
|
|
143
|
+
externalData,
|
|
144
|
+
classPrefix,
|
|
145
|
+
parent: block._id,
|
|
146
|
+
blocks: allBlocks,
|
|
147
|
+
lang
|
|
112
148
|
}
|
|
113
149
|
) : null;
|
|
114
|
-
const
|
|
115
|
-
if (
|
|
116
|
-
let
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
150
|
+
const blockDefinition = getBlockComponent(block._type);
|
|
151
|
+
if (blockDefinition !== null) {
|
|
152
|
+
let syncedBlock = block;
|
|
153
|
+
const Component = blockDefinition.component;
|
|
154
|
+
syncedBlock = { ...blockDefinition.defaults, ...block };
|
|
155
|
+
if (blockModifierCallback) {
|
|
156
|
+
syncedBlock = blockModifierCallback(syncedBlock);
|
|
157
|
+
}
|
|
158
|
+
return React__default.createElement(
|
|
159
|
+
Component,
|
|
160
|
+
omit(
|
|
121
161
|
{
|
|
122
162
|
blockProps: {},
|
|
123
|
-
inBuilder:
|
|
124
|
-
...
|
|
125
|
-
index
|
|
126
|
-
...
|
|
127
|
-
...
|
|
128
|
-
...
|
|
163
|
+
inBuilder: false,
|
|
164
|
+
...syncedBlock,
|
|
165
|
+
index,
|
|
166
|
+
...applyBindings(applyLanguage(block, lang, blockDefinition), externalData),
|
|
167
|
+
...getStyles(syncedBlock),
|
|
168
|
+
...attrs
|
|
129
169
|
},
|
|
130
170
|
["_parent"]
|
|
131
171
|
)
|
|
132
172
|
);
|
|
133
173
|
}
|
|
134
|
-
return /* @__PURE__ */
|
|
135
|
-
|
|
174
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsxs("noscript", { children: [
|
|
175
|
+
block._type,
|
|
136
176
|
" not found"
|
|
137
177
|
] });
|
|
138
178
|
})
|
|
139
179
|
) });
|
|
140
180
|
}
|
|
141
|
-
async function
|
|
142
|
-
|
|
181
|
+
async function getTailwindCSS(theme, markupString, safelist = [], prefix = "", includeBaseStyles = false) {
|
|
182
|
+
const tailwind = createTailwindcss({
|
|
143
183
|
tailwindConfig: {
|
|
144
184
|
darkMode: "class",
|
|
145
|
-
safelist
|
|
146
|
-
theme: { extend:
|
|
147
|
-
plugins: [
|
|
148
|
-
corePlugins: { preflight:
|
|
149
|
-
...
|
|
185
|
+
safelist,
|
|
186
|
+
theme: { extend: getChaiBuilderTheme(theme) },
|
|
187
|
+
plugins: [forms, typography, aspectRatio, chaiBuilderPlugin],
|
|
188
|
+
corePlugins: { preflight: includeBaseStyles },
|
|
189
|
+
...prefix ? { prefix: `${prefix}` } : {}
|
|
150
190
|
}
|
|
151
|
-
})
|
|
152
|
-
|
|
191
|
+
});
|
|
192
|
+
return await tailwind.generateStylesFromContent(
|
|
193
|
+
` ${includeBaseStyles ? "@tailwind base;" : ""}
|
|
153
194
|
@tailwind components;
|
|
154
195
|
@tailwind utilities;`,
|
|
155
|
-
|
|
196
|
+
markupString
|
|
156
197
|
);
|
|
157
198
|
}
|
|
158
|
-
const
|
|
199
|
+
const getBlocksTailwindCSS = (blocks, theme, includeBaseStyles = false) => {
|
|
200
|
+
return getTailwindCSS(theme, [replace(JSON.stringify(blocks), /#styles:,?/g, "")], [], "", includeBaseStyles);
|
|
201
|
+
};
|
|
202
|
+
const getStylesForBlocks = async (blocks, theme = {}, includeBaseStyles = true) => {
|
|
203
|
+
return await getBlocksTailwindCSS(blocks, theme, includeBaseStyles);
|
|
204
|
+
};
|
|
159
205
|
export {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
206
|
+
RenderChaiBlocks,
|
|
207
|
+
convertToBlocks,
|
|
208
|
+
getStylesForBlocks
|
|
163
209
|
};
|
package/dist/runtime.cjs
CHANGED
|
@@ -1 +1,26 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const runtime = require("@chaibuilder/runtime");
|
|
4
|
+
const controls = require("./controls-DaW52RjX.cjs");
|
|
5
|
+
exports.Checkbox = controls.c;
|
|
6
|
+
exports.Code = controls.l;
|
|
7
|
+
exports.Color = controls.h;
|
|
8
|
+
exports.Icon = controls.q;
|
|
9
|
+
exports.Image = controls.x;
|
|
10
|
+
exports.InfoField = controls.u;
|
|
11
|
+
exports.Link = controls.w;
|
|
12
|
+
exports.List = controls.S;
|
|
13
|
+
exports.Model = controls.b;
|
|
14
|
+
exports.MultilineText = controls.f;
|
|
15
|
+
exports.Numeric = controls.s;
|
|
16
|
+
exports.RichText = controls.m;
|
|
17
|
+
exports.SelectOption = controls.y;
|
|
18
|
+
exports.SingleLineText = controls.g;
|
|
19
|
+
exports.Slot = controls.r;
|
|
20
|
+
exports.Styles = controls.T;
|
|
21
|
+
Object.keys(runtime).forEach((k) => {
|
|
22
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
get: () => runtime[k]
|
|
25
|
+
});
|
|
26
|
+
});
|
package/dist/runtime.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
export * from "@chaibuilder/runtime";
|
|
2
|
-
import { c
|
|
2
|
+
import { c, l, h, q, x, u, w, S, b, f, s, m, y, g, r, T } from "./controls-8EZmm0Ns.js";
|
|
3
3
|
export {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
4
|
+
c as Checkbox,
|
|
5
|
+
l as Code,
|
|
6
|
+
h as Color,
|
|
7
|
+
q as Icon,
|
|
8
|
+
x as Image,
|
|
9
|
+
u as InfoField,
|
|
10
|
+
w as Link,
|
|
11
|
+
S as List,
|
|
12
|
+
b as Model,
|
|
13
|
+
f as MultilineText,
|
|
14
|
+
s as Numeric,
|
|
15
|
+
m as RichText,
|
|
16
|
+
y as SelectOption,
|
|
17
17
|
g as SingleLineText,
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
r as Slot,
|
|
19
|
+
T as Styles
|
|
20
20
|
};
|