@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.
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 +11710 -5
  10. package/dist/core.js +6846 -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.js CHANGED
@@ -1,194 +1,249 @@
1
- import { d as U } from "./ChaiThemeFn-Cort9tch.js";
2
- import { a as Rt, b as $t, c as Ft } from "./ChaiThemeFn-Cort9tch.js";
3
- import { last as V, flattenDeep as k, memoize as j, get as u, filter as h, isEmpty as f, omit as D, has as K, cloneDeep as x, forEach as O, keys as w, isString as v, find as S, includes as E } from "lodash-es";
4
- import { g as b, S as y } from "./getSplitClasses-DphwgQiE.js";
5
- import { createTailwindcss as M } from "@mhsdesign/jit-browser-tailwindcss";
6
- import W from "@tailwindcss/aspect-ratio";
7
- import Y from "@tailwindcss/container-queries";
8
- import z from "@tailwindcss/forms";
9
- import L from "@tailwindcss/typography";
10
- import { g as Q, c as q } from "./plugin-kUMxtQR5.js";
11
- import { jsx as d, Fragment as G, jsxs as H } from "react/jsx-runtime";
12
- import { getRegisteredChaiBlock as R } from "@chaibuilder/runtime";
13
- import _, { Suspense as C, createElement as X } from "react";
14
- import { twMerge as Z } from "tailwind-merge";
15
- const tt = (t, s = "") => {
16
- const { classes: n } = b(t), e = n.split(" ").map((r) => r.split(" ").map((o) => {
17
- if (o === "") return "";
18
- if (o.includes(":")) {
19
- const a = o.split(":");
20
- return a[a.length - 1] = s + V(a), a.join(":");
21
- }
22
- return `${s}${o}`;
23
- }).join(" "));
24
- return k(e).join(" ");
25
- }, xt = (t) => {
26
- if (!t) return [];
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
- return JSON.parse(et(t)).filter((n) => !n._type.startsWith("@chai"));
29
- } catch {
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 et(t) {
34
- const s = /(asset:\/\/|https:\/\/asset\.localhost\/)(?:localhost\/)?[^"']+/g;
35
- return t.replace(s, (n) => {
36
- const e = decodeURIComponent(n), r = e.indexOf("public");
37
- return r !== -1 ? e.substring(r + 6) : e;
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 nt(t, s, n = [], e = "", r) {
41
- return await M({
52
+ async function getTailwindCSS(themeOptions, markupString, safelist = [], prefix = "", includeBaseStyles) {
53
+ const tailwind = createTailwindcss({
42
54
  tailwindConfig: {
43
55
  darkMode: "class",
44
- safelist: n,
45
- theme: { extend: Q(t) },
46
- plugins: [z, L, W, Y, q],
47
- corePlugins: { preflight: r },
48
- ...e ? { prefix: `${e}` } : {}
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
- }).generateStylesFromContent(
51
- ` ${r ? "@tailwind base;" : ""}
62
+ });
63
+ return await tailwind.generateStylesFromContent(
64
+ ` ${includeBaseStyles ? "@tailwind base;" : ""}
52
65
  @tailwind components;
53
66
  @tailwind utilities;`,
54
- s
67
+ markupString
55
68
  );
56
69
  }
57
- const st = (t, s, n) => {
58
- const e = JSON.stringify(t).replace(/#styles:([^"]*)/g, (r, i) => `#styles:${i.replace(/,/g, " ")}`.replace(/#styles:/g, ""));
59
- return nt(s, [e], [], "", n);
60
- }, Ot = async (t, s = U, n = !1) => await st(t, s, n);
61
- async function rt(t) {
62
- const s = await (t == null ? void 0 : t.dataProvider(t.block, t.lang, t.metadata));
63
- return /* @__PURE__ */ d(C, { children: _.createElement(t.component, { ...t.props, ...s }) });
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 it = j((t, s) => {
66
- const { baseClasses: n, classes: e } = b(t), r = Z(n, e);
67
- return s === "" ? r.replace(y, "").trim() : tt(r, s).replace(y, "").trim();
68
- }), ot = (t, s) => {
69
- const n = x(t);
70
- return O(w(n), (e) => {
71
- if (v(n[e])) {
72
- let r = n[e];
73
- const i = /\{\{(.*?)\}\}/g, l = r.match(i);
74
- l && l.forEach((o) => {
75
- const a = o.slice(2, -2), g = u(s, a, o);
76
- r = r.replace(o, g);
77
- }), n[e] = r;
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
- }), n;
105
+ });
106
+ return clonedBlock;
80
107
  };
81
- function ct(t, s) {
82
- const n = u(t, `${s}_attrs`, {}), e = w(n).join(" ");
83
- return E(e, "x-show") && !E(e, "x-transition") && (n["x-transition"] = ""), n;
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 at(t, s) {
86
- const n = {};
87
- return Object.keys(t).forEach((e) => {
88
- if (v(t[e]) && t[e].startsWith(y)) {
89
- const r = it(t[e], s);
90
- n[e] = {
91
- className: r,
92
- ...ct(t, e)
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
- }), n;
126
+ });
127
+ return styles;
96
128
  }
97
- function lt(t, s, n) {
98
- if (f(s)) return t;
99
- const e = x(t), r = u(n, "i18nProps", []);
100
- return O(w(e), (i) => {
101
- r.includes(i) && !f(s) && (e[i] = u(e, `${i}-${s}`, e[i]));
102
- }), e;
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 ut = j((t) => {
105
- const s = R(t), n = u(s, "schema.properties", {});
106
- return Object.fromEntries(Object.entries(n).filter(([, e]) => u(e, "runtime", !1)));
107
- }), pt = (t, s, n) => f(n) ? {} : Object.entries(n).reduce((e, [r, i]) => {
108
- const l = [];
109
- let o = S(t, { _id: s });
110
- for (; o; )
111
- l.push(o), o = S(t, { _id: o._parent });
112
- const a = S(l, { _type: i.block });
113
- return a && (e[r] = u(a, u(i, "prop"), null)), e;
114
- }, {}), dt = () => /* @__PURE__ */ d("span", { children: "Loading..." });
115
- function mt({
116
- blocks: t,
117
- parent: s,
118
- classPrefix: n = "",
119
- externalData: e = {},
120
- blockModifierCallback: r = null,
121
- lang: i = "",
122
- fallbackLang: l = "",
123
- metadata: o = {}
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 a = t, g = (c) => at(c, n), $ = s ? h(t, { _parent: s }) : h(t, (c) => f(c._parent));
126
- return /* @__PURE__ */ d(G, { children: _.Children.toArray(
127
- $.map((c, F) => {
128
- const P = {}, N = h(a, { _parent: c._id });
129
- P.children = N.length > 0 ? /* @__PURE__ */ d(
130
- mt,
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: e,
133
- classPrefix: n,
134
- parent: c._id,
135
- blocks: a,
136
- lang: i || l,
137
- metadata: o
182
+ externalData,
183
+ classPrefix,
184
+ parent: block._id,
185
+ blocks: allBlocks,
186
+ lang: lang || fallbackLang,
187
+ metadata
138
188
  }
139
189
  ) : null;
140
- const p = R(c._type);
141
- if (p !== null) {
142
- let m = c;
143
- const B = p.component;
144
- m = { ...p.defaults, ...c }, r && (m = r(m));
145
- const A = i === l ? "" : i, I = pt(a, c._id, ut(c._type)), T = D(
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: !1,
149
- ...m,
150
- index: F,
151
- ...ot(lt(c, A, p), e),
152
- ...g(m),
153
- ...P,
154
- ...I,
155
- metadata: o,
156
- lang: i || l
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 (K(p, "dataProvider")) {
161
- const J = u(
162
- p,
215
+ if (has(blockDefinition, "dataProvider")) {
216
+ const suspenseFallback = get(
217
+ blockDefinition,
163
218
  "suspenseFallback",
164
- dt
219
+ SuspenseFallback
165
220
  );
166
- return /* @__PURE__ */ d(C, { fallback: X(J), children: /* @__PURE__ */ d(
167
- rt,
221
+ return /* @__PURE__ */ jsx(Suspense, { fallback: createElement(suspenseFallback), children: /* @__PURE__ */ jsx(
222
+ AsyncPropsBlock,
168
223
  {
169
- lang: i || l,
170
- metadata: o,
171
- dataProvider: p.dataProvider,
172
- block: c,
173
- component: B,
174
- props: T
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__ */ d(C, { children: _.createElement(B, T) });
233
+ return /* @__PURE__ */ jsx(Suspense, { children: React__default.createElement(Component, props) });
179
234
  }
180
- return /* @__PURE__ */ H("noscript", { children: [
181
- c._type,
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
- mt as RenderChaiBlocks,
189
- xt as convertToBlocks,
190
- Rt as getChaiThemeCssVariables,
191
- Ot as getStylesForBlocks,
192
- $t as getThemeFontsCSSImport,
193
- Ft as getThemeFontsLinkMarkup
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";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("@chaibuilder/runtime");Object.keys(t).forEach(e=>{e!=="default"&&!Object.prototype.hasOwnProperty.call(exports,e)&&Object.defineProperty(exports,e,{enumerable:!0,get:()=>t[e]})});
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
+ });