@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.
Files changed (62) hide show
  1. package/dist/CodeEditor-1LboGb1I.cjs +91 -0
  2. package/dist/CodeEditor-BKgZeXwz.js +91 -0
  3. package/dist/STRINGS-3Sn_NeX1.cjs +9 -0
  4. package/dist/STRINGS-DdpfVlsV.js +10 -0
  5. package/dist/Topbar-B8IS6y4H.js +135 -0
  6. package/dist/Topbar-DXC7DFU1.cjs +135 -0
  7. package/dist/UnsplashImages-CjJ5szAy.cjs +215 -0
  8. package/dist/UnsplashImages-Ck9qpKR0.js +215 -0
  9. package/dist/UploadImages-DW1mj4MB.cjs +117 -0
  10. package/dist/UploadImages-DgAMZ8GR.js +117 -0
  11. package/dist/context-menu-BLbuduri.cjs +1073 -0
  12. package/dist/context-menu-BgtRnByf.js +1042 -0
  13. package/dist/controls-8EZmm0Ns.js +234 -0
  14. package/dist/controls-DaW52RjX.cjs +233 -0
  15. package/dist/core.cjs +82 -1
  16. package/dist/core.js +74 -74
  17. package/dist/iconBase-BSrIcOaG.cjs +146 -0
  18. package/dist/iconBase-CWgVxu0A.js +147 -0
  19. package/dist/index-Bjw2sUN2.cjs +12139 -0
  20. package/dist/index-D8_rAW8B.js +12124 -0
  21. package/dist/jsx-runtime-B6vEU3CM.cjs +925 -0
  22. package/dist/jsx-runtime-ClFauRgV.js +926 -0
  23. package/dist/plugin-BYwesM58.cjs +54 -0
  24. package/dist/plugin-BiDLHDo3.cjs +114 -0
  25. package/dist/plugin-BukD7GJR.js +115 -0
  26. package/dist/plugin-tVAEvXiS.js +55 -0
  27. package/dist/render.cjs +208 -2
  28. package/dist/render.js +171 -125
  29. package/dist/runtime.cjs +26 -1
  30. package/dist/runtime.js +16 -16
  31. package/dist/style.css +1529 -2
  32. package/dist/tailwind.cjs +78 -1
  33. package/dist/tailwind.js +21 -19
  34. package/dist/ui.cjs +392 -1
  35. package/dist/ui.js +268 -257
  36. package/dist/web-blocks.cjs +1241 -3
  37. package/dist/web-blocks.js +764 -555
  38. package/package.json +1 -1
  39. package/dist/CodeEditor-CLJIUsvL.js +0 -77
  40. package/dist/CodeEditor-DrVE5UwR.cjs +0 -1
  41. package/dist/STRINGS-eiGM83kj.js +0 -7
  42. package/dist/STRINGS-ew98weUe.cjs +0 -1
  43. package/dist/Topbar-BvLH3BD9.cjs +0 -1
  44. package/dist/Topbar-D3bfoa2h.js +0 -113
  45. package/dist/UnsplashImages-3SDmSL-g.js +0 -189
  46. package/dist/UnsplashImages-Cx6vImSl.cjs +0 -1
  47. package/dist/UploadImages-CkjdUS7T.js +0 -101
  48. package/dist/UploadImages-aqkH-8LC.cjs +0 -1
  49. package/dist/context-menu-BbqLeYFX.js +0 -979
  50. package/dist/context-menu-DfAXjmc8.cjs +0 -1
  51. package/dist/controls-C4n5ycp4.cjs +0 -1
  52. package/dist/controls-Com-zYCq.js +0 -234
  53. package/dist/iconBase-Cn2BsTrq.cjs +0 -1
  54. package/dist/iconBase-DHfFLkem.js +0 -124
  55. package/dist/index-BlcnqLh_.js +0 -9236
  56. package/dist/index-DUJxGeyq.cjs +0 -63
  57. package/dist/jsx-runtime-BYECrxsp.cjs +0 -30
  58. package/dist/jsx-runtime-DGlMoOmv.js +0 -630
  59. package/dist/plugin-BOEoR5jk.js +0 -44
  60. package/dist/plugin-COMQcYlW.cjs +0 -1
  61. package/dist/plugin-Dw854zFv.js +0 -107
  62. package/dist/plugin-I9XxF65G.cjs +0 -1
package/dist/render.js CHANGED
@@ -1,163 +1,209 @@
1
- import { last as T, flattenDeep as $, memoize as N, filter as _, isEmpty as d, omit as R, isString as j, get as l, each as J, cloneDeep as P, forEach as I, keys as x, has as K, includes as C, replace as L } from "lodash-es";
2
- import { S as f, a as B } from "./STRINGS-eiGM83kj.js";
3
- import { j as u } from "./jsx-runtime-DGlMoOmv.js";
4
- import w from "react";
5
- import { twMerge as W } from "tailwind-merge";
6
- import { getBlockComponent as Y } from "@chaibuilder/runtime";
7
- import { createTailwindcss as v } from "@mhsdesign/jit-browser-tailwindcss";
8
- import F from "@tailwindcss/forms";
9
- import U from "@tailwindcss/typography";
10
- import z from "@tailwindcss/aspect-ratio";
11
- import { g as M, c as q } from "./plugin-BOEoR5jk.js";
12
- const D = (t, r = "") => {
13
- const s = t.replace(f, "").split(",").map((n) => n.split(" ").map((a) => {
14
- if (a === "") return "";
15
- if (a.includes(":")) {
16
- const c = a.split(":");
17
- return c[c.length - 1] = r + T(c), c.join(":");
18
- }
19
- return `${r}${a}`;
20
- }).join(" "));
21
- return $(s).join(" ");
22
- }, ft = (t) => {
23
- if (!t) return [];
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
- return JSON.parse(G(t)).filter((e) => !e._type.startsWith("@chai"));
26
- } catch {
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 G(t) {
31
- const r = /(asset:\/\/|https:\/\/asset\.localhost\/)(?:localhost\/)?[^"']+/g;
32
- return t.replace(r, (e) => {
33
- const s = decodeURIComponent(e), n = s.indexOf("public");
34
- return n !== -1 ? s.substring(n + 6) : s;
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 H = (t) => {
38
- const r = {};
39
- return Object.keys(t).forEach((e) => {
40
- j(t[e]) && t[e].startsWith(B) && (r[e] = t[e].replace(B, "").split(","));
41
- }), r;
42
- }, Q = N((t, r) => {
43
- const e = t.replace(f, "").split(","), s = W(e[0], e[1]);
44
- return r === "" ? s.replace(f, "").trim() : D(s, r).replace(f, "").trim();
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 V(t, r) {
47
- const e = l(t, `${r}_attrs`, {});
48
- K(e, "data-ai-key") && delete e["data-ai-key"];
49
- const s = x(e).join(" ");
50
- return C(s, "x-show") && !C(s, "x-transition") && (e["x-transition"] = ""), e;
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 X(t, r) {
53
- const e = {};
54
- return Object.keys(t).forEach((s) => {
55
- if (j(t[s]) && t[s].startsWith(f)) {
56
- const n = Q(t[s], r);
57
- e[s] = {
58
- className: n,
59
- ...V(t, s)
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
- }), e;
85
+ });
86
+ return styles;
63
87
  }
64
- function Z(t, r) {
65
- const e = l(t, "_bindings", {});
66
- return d(e) ? { ...t } : (J(e, (s, n) => {
67
- j(s) && l(r, s, null) && (t[n] = l(r, s, null));
68
- }), t);
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 b(t, r, e) {
71
- if (d(r)) return t;
72
- const s = P(t);
73
- return I(x(s), (n) => {
74
- l(e, ["props", n, "i18n"]) && !d(r) && (s[n] = l(s, `${n}-${r}`, s[n]));
75
- }), s;
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 E({
78
- blocks: t,
79
- parent: r,
80
- classPrefix: e = "",
81
- externalData: s = {},
82
- blockModifierCallback: n,
83
- lang: p
108
+ function RenderChaiBlocks({
109
+ blocks,
110
+ parent,
111
+ classPrefix = "",
112
+ externalData = {},
113
+ blockModifierCallback,
114
+ lang
84
115
  }) {
85
- const m = t, a = (i) => X(i, e), c = r ? _(t, { _parent: r }) : _(t, (i) => d(i._parent));
86
- return /* @__PURE__ */ u.jsx(u.Fragment, { children: w.Children.toArray(
87
- c.map((i, O) => {
88
- const h = H(i), y = {};
89
- d(h) || Object.keys(h).forEach((o) => {
90
- y[o] = w.Children.toArray(
91
- h[o].map((S) => /* @__PURE__ */ u.jsx(
92
- E,
93
- {
94
- externalData: s,
95
- classPrefix: e,
96
- blocks: m,
97
- parent: S,
98
- lang: p
99
- }
100
- ))
101
- );
102
- });
103
- const A = _(m, { _parent: i._id });
104
- y.children = A.length > 0 ? /* @__PURE__ */ u.jsx(
105
- E,
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: s,
108
- classPrefix: e,
109
- parent: i._id,
110
- blocks: m,
111
- lang: p
143
+ externalData,
144
+ classPrefix,
145
+ parent: block._id,
146
+ blocks: allBlocks,
147
+ lang
112
148
  }
113
149
  ) : null;
114
- const g = Y(i._type);
115
- if (g !== null) {
116
- let o = i;
117
- const S = g.component;
118
- return o = { ...g.defaults, ...i }, n && (o = n(o)), w.createElement(
119
- S,
120
- R(
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: !1,
124
- ...o,
125
- index: O,
126
- ...Z(b(i, p, g), s),
127
- ...a(o),
128
- ...y
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__ */ u.jsxs("noscript", { children: [
135
- i._type,
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 k(t, r, e = [], s = "", n = !1) {
142
- return await v({
181
+ async function getTailwindCSS(theme, markupString, safelist = [], prefix = "", includeBaseStyles = false) {
182
+ const tailwind = createTailwindcss({
143
183
  tailwindConfig: {
144
184
  darkMode: "class",
145
- safelist: e,
146
- theme: { extend: M(t) },
147
- plugins: [F, U, z, q],
148
- corePlugins: { preflight: n },
149
- ...s ? { prefix: `${s}` } : {}
185
+ safelist,
186
+ theme: { extend: getChaiBuilderTheme(theme) },
187
+ plugins: [forms, typography, aspectRatio, chaiBuilderPlugin],
188
+ corePlugins: { preflight: includeBaseStyles },
189
+ ...prefix ? { prefix: `${prefix}` } : {}
150
190
  }
151
- }).generateStylesFromContent(
152
- ` ${n ? "@tailwind base;" : ""}
191
+ });
192
+ return await tailwind.generateStylesFromContent(
193
+ ` ${includeBaseStyles ? "@tailwind base;" : ""}
153
194
  @tailwind components;
154
195
  @tailwind utilities;`,
155
- r
196
+ markupString
156
197
  );
157
198
  }
158
- const tt = (t, r, e = !1) => k(r, [L(JSON.stringify(t), /#styles:,?/g, "")], [], "", e), dt = async (t, r = {}, e = !0) => await tt(t, r, e);
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
- E as RenderChaiBlocks,
161
- ft as convertToBlocks,
162
- dt as getStylesForBlocks
206
+ RenderChaiBlocks,
207
+ convertToBlocks,
208
+ getStylesForBlocks
163
209
  };
package/dist/runtime.cjs CHANGED
@@ -1 +1,26 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@chaibuilder/runtime"),e=require("./controls-C4n5ycp4.cjs");exports.Checkbox=e.c;exports.Code=e.l;exports.Color=e.h;exports.Icon=e.q;exports.Image=e.x;exports.InfoField=e.u;exports.Link=e.w;exports.List=e.S;exports.Model=e.b;exports.MultilineText=e.f;exports.Numeric=e.s;exports.RichText=e.m;exports.SelectOption=e.y;exports.SingleLineText=e.g;exports.Slot=e.r;exports.Styles=e.T;Object.keys(o).forEach(t=>{t!=="default"&&!Object.prototype.hasOwnProperty.call(exports,t)&&Object.defineProperty(exports,t,{enumerable:!0,get:()=>o[t]})});
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 as o, l as t, h as i, q as l, x as n, u as r, w as x, S as c, b as m, f as S, s as f, m as T, y as d, g, r as h, T as p } from "./controls-Com-zYCq.js";
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
- o as Checkbox,
5
- t as Code,
6
- i as Color,
7
- l as Icon,
8
- n as Image,
9
- r as InfoField,
10
- x as Link,
11
- c as List,
12
- m as Model,
13
- S as MultilineText,
14
- f as Numeric,
15
- T as RichText,
16
- d as SelectOption,
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
- h as Slot,
19
- p as Styles
18
+ r as Slot,
19
+ T as Styles
20
20
  };