@chaibuilder/sdk 3.0.3 → 3.0.4

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/core.js CHANGED
@@ -1,6 +1,6 @@
1
- var H = Object.defineProperty;
2
- var V = (o, n, r) => n in o ? H(o, n, { enumerable: !0, configurable: !0, writable: !0, value: r }) : o[n] = r;
3
- var F = (o, n, r) => V(o, typeof n != "symbol" ? n + "" : n, r);
1
+ var V = Object.defineProperty;
2
+ var U = (o, n, r) => n in o ? V(o, n, { enumerable: !0, configurable: !0, writable: !0, value: r }) : o[n] = r;
3
+ var F = (o, n, r) => U(o, typeof n != "symbol" ? n + "" : n, r);
4
4
  import { jsx, jsxs, Fragment } from "react/jsx-runtime";
5
5
  import { useRegisteredChaiBlocks, getRegisteredChaiBlock, getDefaultBlockProps, useRegisteredFonts, getBlockFormSchemas, syncBlocksWithDefaults } from "@chaibuilder/runtime";
6
6
  import { get, find, filter, flatten, has, map, includes, without, compact, reverse, findIndex, isEmpty, isString, each, omit, values, pick, startsWith, isFunction, isObject as isObject$1, memoize, noop, first, keys, range, flattenDeep, set, forEach, unset, chunk, cloneDeep, isNull, isArray, split, reject, take, debounce, startCase, isNumber, parseInt as parseInt$1, isNaN as isNaN$1, toLower, nth, findLast, intersection, toUpper, capitalize, groupBy, uniq, sortBy, round } from "lodash-es";
@@ -14,13 +14,13 @@ import { v as Button, ab as DropdownMenu, ap as DropdownMenuTrigger, ad as Dropd
14
14
  import clsx$1, { clsx } from "clsx";
15
15
  import { twMerge } from "tailwind-merge";
16
16
  import TreeModel from "tree-model";
17
- import { C as COLLECTION_PREFIX, S as STYLES_KEY, h as getSplitChaiClasses, a as applyBindingToBlockProps, b as applyLanguage, g as getBlockTagAttributes, c as getBlockRuntimeProps, d as applyLimit, R as REPEATER_PREFIX, f as getBlocksFromHTML, i as ROOT_TEMP_KEY } from "./apply-binding-OTp8TO_7.js";
17
+ import { C as COLLECTION_PREFIX, S as STYLES_KEY, h as getSplitChaiClasses, a as applyBindingToBlockProps, b as applyLanguage, g as getBlockTagAttributes, c as getBlockRuntimeProps, d as applyLimit, R as REPEATER_PREFIX, f as getBlocksFromHTML, i as ROOT_TEMP_KEY } from "./apply-binding-tfi-KyyV.js";
18
18
  import { d as defaultThemeOptions, f as defaultThemeValues, a as getChaiThemeCssVariables, g as getChaiThemeOptions, p as plugin, h as getThemeFontsUrls, i as getThemeCustomFontFace } from "./plugin-BOcGV_IY.js";
19
19
  import { isObject } from "@rjsf/utils";
20
20
  import { useDebouncedCallback, useThrottledCallback, useResizeObserver, useIntervalEffect } from "@react-hookz/web";
21
21
  import { toast, Toaster } from "sonner";
22
22
  import { useTranslation, initReactI18next } from "react-i18next";
23
- import { useTranslation as $e } from "react-i18next";
23
+ import { useTranslation as Fe } from "react-i18next";
24
24
  import Fuse from "fuse.js";
25
25
  import UndoManager from "undo-manager";
26
26
  import Link from "@tiptap/extension-link";
@@ -35,7 +35,7 @@ import Autosuggest from "react-autosuggest";
35
35
  import { useFeature } from "flagged";
36
36
  import { Tree } from "react-arborist";
37
37
  import i18n from "i18next";
38
- import { default as He } from "i18next";
38
+ import { default as Ve } from "i18next";
39
39
  import "himalaya";
40
40
  import tailwindAspectRatio from "@tailwindcss/aspect-ratio";
41
41
  import tailwindForms from "@tailwindcss/forms";
@@ -6475,17 +6475,17 @@ function ManualClasses() {
6475
6475
  const T = f.trim().toLowerCase().replace(/ +(?= )/g, "").split(" ");
6476
6476
  u(m, T, !0), x("");
6477
6477
  }, [j, _] = useState([]), w = ({ value: T }) => {
6478
- const P = T.trim().toLowerCase(), N = P.match(/.+:/g);
6479
- let R = [];
6480
- if (N && N.length > 0) {
6481
- const [O] = N, M = P.replace(O, "");
6482
- R = i.search(M).map((D) => ({
6483
- ...D,
6484
- item: { ...D.item, name: O + D.item.name }
6478
+ const P = T.trim().toLowerCase(), R = P.match(/.+:/g);
6479
+ let N = [];
6480
+ if (R && R.length > 0) {
6481
+ const [D] = R, $ = P.replace(D, "");
6482
+ N = i.search($).map((M) => ({
6483
+ ...M,
6484
+ item: { ...M.item, name: D + M.item.name }
6485
6485
  }));
6486
6486
  } else
6487
- R = i.search(P);
6488
- return _(map(R, "item"));
6487
+ N = i.search(P);
6488
+ return _(map(N, "item"));
6489
6489
  }, k = () => {
6490
6490
  _([]);
6491
6491
  }, A = (T) => T.name, E = (T) => /* @__PURE__ */ jsx("div", { className: "rounded-md p-1", children: T.name }), S = useMemo(
@@ -6575,16 +6575,16 @@ function ManualClasses() {
6575
6575
  {
6576
6576
  ref: o,
6577
6577
  value: n,
6578
- onChange: (N) => r(N.target.value),
6578
+ onChange: (R) => r(R.target.value),
6579
6579
  onBlur: () => {
6580
6580
  v(T);
6581
6581
  },
6582
- onKeyDown: (N) => {
6583
- N.key === "Enter" && v(T);
6582
+ onKeyDown: (R) => {
6583
+ R.key === "Enter" && v(T);
6584
6584
  },
6585
- onFocus: (N) => {
6585
+ onFocus: (R) => {
6586
6586
  setTimeout(() => {
6587
- N.target.select();
6587
+ R.target.select();
6588
6588
  }, 0);
6589
6589
  },
6590
6590
  className: "group relative flex max-w-[260px] cursor-default items-center gap-x-1 truncate break-words rounded border border-border bg-gray-200 p-px px-1.5 pr-2 text-[11px] text-gray-600 hover:border-gray-300 dark:border-gray-700 dark:bg-gray-800 dark:text-gray-300"
@@ -7647,7 +7647,7 @@ const Input = ({ node: o }) => {
7647
7647
  var n;
7648
7648
  return o != null && o._name ? o._name : (o == null ? void 0 : o._type) === "Box" && (o != null && o.tag) && (o == null ? void 0 : o.tag) !== "div" ? startCase(o.tag) : ((n = o == null ? void 0 : o._type) == null ? void 0 : n.split("/").pop()) || "";
7649
7649
  }, Node = memo(({ node: o, style: n, dragHandle: r }) => {
7650
- var P;
7650
+ var R;
7651
7651
  const { t: a } = useTranslation(), [l, , i] = useHiddenBlockIds(), [c] = useAtom$1(canvasIframeAtom), { hasPermission: d } = usePermissions();
7652
7652
  let p = null;
7653
7653
  const u = o.children.length > 0, { highlightBlock: g, clearHighlight: m } = useBlockHighlight(), { id: h, data: f, isSelected: x, willReceiveDrop: y, isDragging: b, isEditing: C, handleClick: B } = o, j = (N) => {
@@ -7670,15 +7670,15 @@ const Input = ({ node: o }) => {
7670
7670
  }, 500);
7671
7671
  return () => clearTimeout(N);
7672
7672
  }, [y, o, b]);
7673
- const I = (N, R) => {
7674
- const O = c.contentDocument || c.contentWindow.document, M = O.querySelector(`[data-block-id=${N}]`);
7675
- M && M.setAttribute("data-drop", R);
7676
- const $ = M.getBoundingClientRect(), D = c.getBoundingClientRect();
7677
- $.top >= D.top && $.left >= D.left && $.bottom <= D.bottom && $.right <= D.right || (O.documentElement.scrollTop = M.offsetTop - D.top);
7673
+ const I = (N, D) => {
7674
+ const $ = c.contentDocument || c.contentWindow.document, O = $.querySelector(`[data-block-id=${N}]`);
7675
+ O && O.setAttribute("data-drop", D);
7676
+ const M = O.getBoundingClientRect(), H = c.getBoundingClientRect();
7677
+ M.top >= H.top && M.left >= H.left && M.bottom <= H.bottom && M.right <= H.right || ($.documentElement.scrollTop = O.offsetTop - H.top);
7678
7678
  }, L = (N) => {
7679
7679
  S();
7680
- const R = get(o, "parent.id");
7681
- R !== "__REACT_ARBORIST_INTERNAL_ROOT__" ? pubsub.publish(CHAI_BUILDER_EVENTS.OPEN_ADD_BLOCK, { _id: R, position: N }) : pubsub.publish(CHAI_BUILDER_EVENTS.OPEN_ADD_BLOCK, { position: N });
7680
+ const D = get(o, "parent.id");
7681
+ D !== "__REACT_ARBORIST_INTERNAL_ROOT__" ? pubsub.publish(CHAI_BUILDER_EVENTS.OPEN_ADD_BLOCK, { _id: D, position: N }) : pubsub.publish(CHAI_BUILDER_EVENTS.OPEN_ADD_BLOCK, { position: N });
7682
7682
  };
7683
7683
  if (h === ROOT_TEMP_KEY)
7684
7684
  return /* @__PURE__ */ jsxs("div", { className: "group relative w-full cursor-pointer", children: [
@@ -7698,7 +7698,7 @@ const Input = ({ node: o }) => {
7698
7698
  ),
7699
7699
  /* @__PURE__ */ jsx("br", {})
7700
7700
  ] });
7701
- const T = useMemo(() => has(f, "_libBlockId") && !isEmpty(f._libBlockId) && (d(PERMISSIONS.CREATE_LIBRARY_BLOCK) || d(PERMISSIONS.EDIT_LIBRARY_BLOCK)), [f, d]);
7701
+ const T = useMemo(() => has(f, "_libBlockId") && !isEmpty(f._libBlockId) && (d(PERMISSIONS.CREATE_LIBRARY_BLOCK) || d(PERMISSIONS.EDIT_LIBRARY_BLOCK)), [f, d]), P = useMemo(() => (f == null ? void 0 : f._type) === "PartialBlock" || (f == null ? void 0 : f._type) === "GlobalBlock", [f]);
7702
7702
  return /* @__PURE__ */ jsx("div", { className: "w-full", children: /* @__PURE__ */ jsxs(
7703
7703
  "div",
7704
7704
  {
@@ -7720,7 +7720,7 @@ const Input = ({ node: o }) => {
7720
7720
  N.preventDefault(), I(h, "no");
7721
7721
  },
7722
7722
  children: [
7723
- d(PERMISSIONS.ADD_BLOCK) && (o == null ? void 0 : o.rowIndex) > 0 && (o.parent.isOpen && canAddChildBlock(get(o, "parent.data._type")) || ((P = o == null ? void 0 : o.parent) == null ? void 0 : P.id) === "__REACT_ARBORIST_INTERNAL_ROOT__") && /* @__PURE__ */ jsx("div", { className: "group relative ml-5 h-full w-full cursor-pointer", children: /* @__PURE__ */ jsx(
7723
+ d(PERMISSIONS.ADD_BLOCK) && (o == null ? void 0 : o.rowIndex) > 0 && (o.parent.isOpen && canAddChildBlock(get(o, "parent.data._type")) || ((R = o == null ? void 0 : o.parent) == null ? void 0 : R.id) === "__REACT_ARBORIST_INTERNAL_ROOT__") && /* @__PURE__ */ jsx("div", { className: "group relative ml-5 h-full w-full cursor-pointer", children: /* @__PURE__ */ jsx(
7724
7724
  "div",
7725
7725
  {
7726
7726
  onClick: (N) => {
@@ -7758,8 +7758,10 @@ const Input = ({ node: o }) => {
7758
7758
  {
7759
7759
  className: cn(
7760
7760
  "leading-1 flex items-center",
7761
- T && "text-primary/60",
7762
- T && x && "text-primary/80"
7761
+ T && "text-orange-600/90",
7762
+ T && x && "text-orange-600",
7763
+ P && "text-purple-600/90",
7764
+ P && x && "text-purple-100"
7763
7765
  ),
7764
7766
  children: [
7765
7767
  /* @__PURE__ */ jsx(TypeIcon, { type: f == null ? void 0 : f._type }),
@@ -7777,18 +7779,18 @@ const Input = ({ node: o }) => {
7777
7779
  }
7778
7780
  )
7779
7781
  ] }),
7780
- /* @__PURE__ */ jsxs("div", { className: "invisible flex items-center space-x-1.5 pr-2 group-hover:visible", children: [
7782
+ /* @__PURE__ */ jsxs("div", { className: "invisible flex items-center space-x-1.5 pr-px group-hover:visible", children: [
7781
7783
  canAddChildBlock(f == null ? void 0 : f._type) && !l.includes(h) && d(PERMISSIONS.ADD_BLOCK) ? /* @__PURE__ */ jsxs(Tooltip, { children: [
7782
7784
  /* @__PURE__ */ jsx(
7783
7785
  TooltipTrigger,
7784
7786
  {
7785
7787
  onClick: () => pubsub.publish(CHAI_BUILDER_EVENTS.OPEN_ADD_BLOCK, { _id: h }),
7786
- className: "cursor-pointer rounded bg-transparent",
7788
+ className: "cursor-pointer rounded bg-transparent p-px hover:bg-primary/10",
7787
7789
  asChild: !0,
7788
- children: /* @__PURE__ */ jsx(PlusIcon, { className: "h-3 w-3" })
7790
+ children: /* @__PURE__ */ jsx(PlusIcon, { className: "h-4 w-4" })
7789
7791
  }
7790
7792
  ),
7791
- /* @__PURE__ */ jsx(TooltipContent, { className: "isolate z-[9999]", side: "bottom", children: a("Add block") })
7793
+ /* @__PURE__ */ jsx(TooltipContent, { className: "isolate z-[9999]", side: "bottom", children: a("Add block inside") })
7792
7794
  ] }) : null,
7793
7795
  /* @__PURE__ */ jsxs(Tooltip, { children: [
7794
7796
  /* @__PURE__ */ jsx(
@@ -7797,14 +7799,14 @@ const Input = ({ node: o }) => {
7797
7799
  onClick: (N) => {
7798
7800
  N.stopPropagation(), i(h), o.isOpen && o.toggle();
7799
7801
  },
7800
- className: "cursor-pointer rounded bg-transparent",
7802
+ className: "cursor-pointer rounded bg-transparent p-0.5 hover:bg-primary/10",
7801
7803
  asChild: !0,
7802
7804
  children: /* @__PURE__ */ jsx(EyeNoneIcon, { className: "h-4 w-4" })
7803
7805
  }
7804
7806
  ),
7805
7807
  /* @__PURE__ */ jsx(TooltipContent, { className: "isolate z-[9999]", side: "bottom", children: a("Hide block") })
7806
7808
  ] }),
7807
- /* @__PURE__ */ jsx(BlockMoreOptions, { node: o, id: h, children: /* @__PURE__ */ jsx(DotsVerticalIcon, { className: "h-4 w-4" }) })
7809
+ /* @__PURE__ */ jsx(BlockMoreOptions, { node: o, id: h, children: /* @__PURE__ */ jsx("div", { className: "cursor-pointer rounded bg-transparent p-px hover:bg-primary/10", children: /* @__PURE__ */ jsx(DotsVerticalIcon, { className: "h-3 w-3" }) }) })
7808
7810
  ] })
7809
7811
  ]
7810
7812
  }
@@ -7946,16 +7948,16 @@ const Input = ({ node: o }) => {
7946
7948
  treeRef.current.isEditing || handleKeyDown(o);
7947
7949
  },
7948
7950
  children: [
7949
- /* @__PURE__ */ jsxs("div", { className: "mb-2 flex items-center justify-end gap-x-2 pb-2 text-sm text-muted-foreground", children: [
7951
+ /* @__PURE__ */ jsxs("div", { className: "mb-2 flex items-center justify-end gap-x-1 pb-2 text-sm text-muted-foreground", children: [
7950
7952
  /* @__PURE__ */ jsxs(Tooltip, { children: [
7951
7953
  /* @__PURE__ */ jsx(TooltipTrigger, { asChild: !0, children: /* @__PURE__ */ jsx(
7952
7954
  Button,
7953
7955
  {
7954
7956
  onClick: () => setHiddenBlocks([]),
7955
- variant: "outline",
7957
+ variant: "ghost",
7956
7958
  className: "h-fit p-1 disabled:cursor-not-allowed disabled:opacity-50",
7957
7959
  size: "sm",
7958
- children: /* @__PURE__ */ jsx(EyeOpenIcon, { className: "h-4 w-4" })
7960
+ children: /* @__PURE__ */ jsx(EyeOpenIcon, { className: "h-2 w-2" })
7959
7961
  }
7960
7962
  ) }),
7961
7963
  /* @__PURE__ */ jsx(TooltipContent, { className: "isolate z-[9999]", children: t("Show hidden blocks") })
@@ -7964,14 +7966,14 @@ const Input = ({ node: o }) => {
7964
7966
  /* @__PURE__ */ jsx(TooltipTrigger, { asChild: !0, children: /* @__PURE__ */ jsx(Button, { className: "h-fit p-1", onClick: () => {
7965
7967
  var o;
7966
7968
  return (o = treeRef == null ? void 0 : treeRef.current) == null ? void 0 : o.openAll();
7967
- }, variant: "outline", size: "sm", children: /* @__PURE__ */ jsx(DoubleArrowDownIcon, { className: "h-3.5 w-3.5" }) }) }),
7969
+ }, variant: "ghost", size: "sm", children: /* @__PURE__ */ jsx(DoubleArrowDownIcon, { className: "h-2 w-2" }) }) }),
7968
7970
  /* @__PURE__ */ jsx(TooltipContent, { className: "isolate z-[9999]", children: t("Expand all") })
7969
7971
  ] }),
7970
7972
  /* @__PURE__ */ jsxs(Tooltip, { children: [
7971
7973
  /* @__PURE__ */ jsx(TooltipTrigger, { asChild: !0, children: /* @__PURE__ */ jsx(Button, { className: "h-fit p-1", onClick: () => {
7972
7974
  var o;
7973
7975
  return (o = treeRef == null ? void 0 : treeRef.current) == null ? void 0 : o.closeAll();
7974
- }, variant: "outline", size: "sm", children: /* @__PURE__ */ jsx(DoubleArrowUpIcon, { className: "h-3.5 w-3.5" }) }) }),
7976
+ }, variant: "ghost", size: "sm", children: /* @__PURE__ */ jsx(DoubleArrowUpIcon, { className: "h-2 w-2" }) }) }),
7975
7977
  /* @__PURE__ */ jsx(TooltipContent, { className: "isolate z-[9999]", children: t("Collapse all") })
7976
7978
  ] })
7977
7979
  ] }),
@@ -9251,8 +9253,8 @@ const AiAssistant = () => {
9251
9253
  }, w = useCallback((k) => {
9252
9254
  const A = (v) => /[.,!?;:]/.test(v), E = (v, I, L) => {
9253
9255
  let T = "", P = "";
9254
- const N = I > 0 ? v[I - 1] : "", R = I < v.length ? v[I] : "";
9255
- return I > 0 && (N === "." || !A(N) && N !== " ") && (T = " "), I < v.length && !A(R) && R !== " " && (P = " "), {
9256
+ const R = I > 0 ? v[I - 1] : "", N = I < v.length ? v[I] : "";
9257
+ return I > 0 && (R === "." || !A(R) && R !== " ") && (T = " "), I < v.length && !A(N) && N !== " " && (P = " "), {
9256
9258
  text: T + L + P,
9257
9259
  prefixLength: T.length,
9258
9260
  suffixLength: P.length
@@ -9261,12 +9263,12 @@ const AiAssistant = () => {
9261
9263
  if (S) {
9262
9264
  const v = S.selectionStart || 0, I = S.value || "", L = S.selectionEnd || v;
9263
9265
  if (L > v) {
9264
- const O = `{{${k}}}`, { text: M } = E(I, v, O), $ = I.slice(0, v) + M + I.slice(L);
9265
- p($);
9266
+ const D = `{{${k}}}`, { text: $ } = E(I, v, D), O = I.slice(0, v) + $ + I.slice(L);
9267
+ p(O);
9266
9268
  return;
9267
9269
  }
9268
- const P = `{{${k}}}`, { text: N } = E(I, v, P), R = I.slice(0, v) + N + I.slice(v);
9269
- p(R);
9270
+ const P = `{{${k}}}`, { text: R } = E(I, v, P), N = I.slice(0, v) + R + I.slice(v);
9271
+ p(N);
9270
9272
  }
9271
9273
  }, []);
9272
9274
  return /* @__PURE__ */ jsxs("div", { className: "flex max-h-full flex-1 flex-col", children: [
@@ -10379,7 +10381,7 @@ export {
10379
10381
  getBlocksFromHTML as convertHTMLToChaiBlocks,
10380
10382
  generateUUID as generateBlockId,
10381
10383
  getBlocksFromHTML,
10382
- He as i18n,
10384
+ Ve as i18n,
10383
10385
  cn$2 as mergeClasses,
10384
10386
  registerBlockSettingField,
10385
10387
  registerBlockSettingTemplate,
@@ -10445,7 +10447,7 @@ export {
10445
10447
  useTheme,
10446
10448
  useThemeOptions,
10447
10449
  useToggleChaiFeatureFlag,
10448
- $e as useTranslation,
10450
+ Fe as useTranslation,
10449
10451
  useUndoManager,
10450
10452
  useUpdateBlocksProps,
10451
10453
  useUpdateBlocksPropsRealtime,
package/dist/render.cjs CHANGED
@@ -1,3 +1,3 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const k=require("./plugin-CSgw-f78.cjs"),u=require("./apply-binding-CxkQxWx3.cjs"),t=require("lodash-es"),I=require("@tailwindcss/aspect-ratio"),q=require("@tailwindcss/forms"),$=require("@tailwindcss/typography");require("tailwindcss-animate");const E=require("./get-chai-builder-theme-B1tr_NJB.cjs"),L=require("@mhsdesign/jit-browser-tailwindcss"),F=require("@tailwindcss/container-queries"),m=require("react/jsx-runtime"),g=require("react"),R=require("@chaibuilder/runtime");function M(e,r){const a=e.filter(({_type:i})=>i==="GlobalBlock"||i==="PartialBlock");for(let i=0;i<a.length;i++){const l=a[i],s=t.get(l,"partialBlockId",t.get(l,"globalBlock",""));if(s==="")continue;let n=t.cloneDeep(t.get(r,s,[]));l._parent&&(n==null?void 0:n.length)>0&&(n=n.map(c=>(t.isEmpty(c._parent)&&(c._parent=l._parent),c)));const o=e.indexOf(l);e.splice(o,1,...n)}return e}const D=e=>{if(!e)return[];try{return JSON.parse(j(e)).filter(a=>!a._type.startsWith("@chai"))}catch{return[{_type:"Paragraph",_id:"error",content:"Invalid JSON. Please check the JSON string."}]}};function j(e){const r=/(asset:\/\/|https:\/\/asset\.localhost\/)(?:localhost\/)?[^"']+/g;return e.replace(r,a=>{const i=decodeURIComponent(a),l=i.indexOf("public");return l!==-1?i.substring(l+6):i})}async function O(e,r,a=[],i="",l){return await L.createTailwindcss({tailwindConfig:{darkMode:"class",safelist:a,theme:{extend:E.getChaiBuilderTheme(e)},plugins:[q,$,I,F,k.chaiBuilderPlugin],corePlugins:{preflight:l},...i?{prefix:`${i}`}:{}}}).generateStylesFromContent(` ${l?"@tailwind base;":""}
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const k=require("./plugin-CSgw-f78.cjs"),u=require("./apply-binding-HQ9gBNJP.cjs"),t=require("lodash-es"),I=require("@tailwindcss/aspect-ratio"),q=require("@tailwindcss/forms"),$=require("@tailwindcss/typography");require("tailwindcss-animate");const E=require("./get-chai-builder-theme-B1tr_NJB.cjs"),L=require("@mhsdesign/jit-browser-tailwindcss"),F=require("@tailwindcss/container-queries"),m=require("react/jsx-runtime"),g=require("react"),R=require("@chaibuilder/runtime");function M(e,r){const a=e.filter(({_type:i})=>i==="GlobalBlock"||i==="PartialBlock");for(let i=0;i<a.length;i++){const l=a[i],s=t.get(l,"partialBlockId",t.get(l,"globalBlock",""));if(s==="")continue;let n=t.cloneDeep(t.get(r,s,[]));l._parent&&(n==null?void 0:n.length)>0&&(n=n.map(c=>(t.isEmpty(c._parent)&&(c._parent=l._parent),c)));const o=e.indexOf(l);e.splice(o,1,...n)}return e}const D=e=>{if(!e)return[];try{return JSON.parse(j(e)).filter(a=>!a._type.startsWith("@chai"))}catch{return[{_type:"Paragraph",_id:"error",content:"Invalid JSON. Please check the JSON string."}]}};function j(e){const r=/(asset:\/\/|https:\/\/asset\.localhost\/)(?:localhost\/)?[^"']+/g;return e.replace(r,a=>{const i=decodeURIComponent(a),l=i.indexOf("public");return l!==-1?i.substring(l+6):i})}async function O(e,r,a=[],i="",l){return await L.createTailwindcss({tailwindConfig:{darkMode:"class",safelist:a,theme:{extend:E.getChaiBuilderTheme(e)},plugins:[q,$,I,F,k.chaiBuilderPlugin],corePlugins:{preflight:l},...i?{prefix:`${i}`}:{}}}).generateStylesFromContent(` ${l?"@tailwind base;":""}
2
2
  @tailwind components;
3
3
  @tailwind utilities;`,r)}const A=(e,r,a)=>{const i=JSON.stringify(e).replace(/#styles:([^"]*)/g,(l,s)=>`#styles:${s.replace(/,/g," ")}`.replace(/#styles:/g,""));return O(r,[i],[],"",a)},K=async(e,r=k.defaultThemeOptions,a=!1)=>await A(e,r,a);async function N(e){const r={pageProps:e.pageProps,block:e.block,lang:e.lang,draft:e.draft,inBuilder:!1},a=await e.dataProvider(r);return t.has(a,"$metadata")&&t.isFunction(e.dataProviderMetadataCallback)&&e.dataProviderMetadataCallback(e.block,a.$metadata),e.children({...t.omit(a,"$metadata")})}const J=()=>m.jsx("div",{}),V=e=>{const{block:r,lang:a,fallbackLang:i,children:l,externalData:s,blocks:n,draft:o,pageProps:c,dataProviderMetadataCallback:h}=e,d=R.getRegisteredChaiBlock(r._type),y=t.get(d,"component",null),f=t.get(e.repeaterData,"index",-1),b=t.get(e.repeaterData,"dataKey",""),C=a===i?"":a,p=u.applyBindingToBlockProps(u.applyLanguage(r,C,d),s,{index:f,key:b}),w=u.getBlockTagAttributes(r,!1),T=H(n,r._id,u.getBlockRuntimeProps(r._type)),S=t.has(d,"dataProvider")&&t.isFunction(d.dataProvider),_={...p,...w,...T},P={blockProps:{},inBuilder:!1,lang:a||i,..._};if(t.isNull(y))return null;if(S){const v=t.get(d,"suspenseFallback",J);return m.jsx(g.Suspense,{fallback:g.createElement(v),children:m.jsx(N,{lang:a,pageProps:c,block:_,dataProvider:d.dataProvider,...h?{dataProviderMetadataCallback:h}:{},draft:o,children:x=>g.createElement(y,{...P,...x,children:l({_id:r._id,_type:r._type,...t.isArray(p.repeaterItems)?{repeaterItems:u.applyLimit(p.repeaterItems,r),$repeaterItemsKey:p.$repeaterItemsKey}:{}})})})})}return m.jsx(g.Suspense,{children:g.createElement(y,{...P,children:l({_id:r._id,_type:r._type,...t.isArray(p.repeaterItems)?{repeaterItems:u.applyLimit(p.repeaterItems,r),$repeaterItemsKey:p.$repeaterItemsKey}:{}})})})},B=e=>{const{blocks:r,parent:a,repeaterData:i}=e;let l=t.uniqBy(t.filter(r,n=>t.has(n,"_id")&&(t.isEmpty(a)?!n._parent:n._parent===a)),"_id");const s=n=>t.filter(r,o=>o._parent===n).length>0;return t.map(l,n=>n?g.createElement(V,{...e,key:n._id,block:n},({_id:o,_type:c,repeaterItems:h,$repeaterItemsKey:d})=>c==="Repeater"?t.isArray(h)&&h.map((y,f)=>g.createElement(B,{...e,parent:n._id,key:`${t.get(n,"_parent","root")}-${n._id}-${f}`,repeaterData:{index:f,dataKey:d}})):s(o)?g.createElement(B,{...e,parent:n._id,key:`${t.get(n,"_parent","root")}-${n._id}`,repeaterData:i}):null):null)},H=(e,r,a)=>t.isEmpty(a)?{}:Object.entries(a).reduce((i,[l,s])=>{const n=[];let o=t.find(e,{_id:r});for(;o;)n.push(o),o=t.find(e,{_id:o._parent});const c=t.find(n,{_type:s.block});return c&&(i[l]=t.get(c,t.get(s,"prop"),null)),i},{});function U(e){if(t.isEmpty(e.lang)&&!t.isEmpty(e.fallbackLang))throw new Error("lang prop is required when fallbackLang is provided");if(t.isEmpty(e.blocks))return null;const r=e.lang??"en",a=e.fallbackLang??r;return m.jsx(B,{...e,lang:r,fallbackLang:a})}exports.getChaiThemeCssVariables=k.getChaiThemeCssVariables;exports.getThemeFontsCSSImport=k.getThemeFontsCSSImport;exports.getThemeFontsLinkMarkup=k.getThemeFontsLinkMarkup;exports.applyChaiDataBinding=u.applyChaiDataBinding;exports.convertHTMLToChaiBlocks=u.getBlocksFromHTML;exports.RenderChaiBlocks=U;exports.convertToBlocks=D;exports.getMergedPartialBlocks=M;exports.getStylesForBlocks=K;
package/dist/render.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { d as F, c as O } from "./plugin-BOcGV_IY.js";
2
2
  import { a as ve, b as Se, e as xe } from "./plugin-BOcGV_IY.js";
3
- import { a as K, b as M, g as A, c as N, d as C } from "./apply-binding-OTp8TO_7.js";
4
- import { e as $e, f as Te } from "./apply-binding-OTp8TO_7.js";
3
+ import { a as K, b as M, g as A, c as N, d as C } from "./apply-binding-tfi-KyyV.js";
4
+ import { e as $e, f as Te } from "./apply-binding-tfi-KyyV.js";
5
5
  import { get as s, cloneDeep as J, isEmpty as u, has as P, isFunction as x, omit as E, isNull as j, isArray as _, uniqBy as q, filter as v, map as U, find as y } from "lodash-es";
6
6
  import V from "@tailwindcss/aspect-ratio";
7
7
  import W from "@tailwindcss/forms";
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "author": "Suraj Air",
6
6
  "license": "BSD-3-Clause",
7
7
  "homepage": "https://chaibuilder.com",
8
- "version": "3.0.3",
8
+ "version": "3.0.4",
9
9
  "type": "module",
10
10
  "repository": {
11
11
  "type": "git",