@chaibuilder/sdk 2.5.5 → 2.5.7

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
@@ -736,6 +736,9 @@ const useLanguages = () => {
736
736
  selectedLang: n,
737
737
  setSelectedLang: l
738
738
  };
739
+ }, isPageLoadedAtom = atom(!1), useIsPageLoaded = () => {
740
+ const [o] = useAtom$1(isPageLoadedAtom);
741
+ return o;
739
742
  }, builderSaveStateAtom = atom("SAVED");
740
743
  builderSaveStateAtom.debugLabel = "builderSaveStateAtom";
741
744
  const checkMissingTranslations = (o, r) => r ? o.some((n) => {
@@ -751,43 +754,43 @@ const checkMissingTranslations = (o, r) => r ? o.some((n) => {
751
754
  return console.warn(`Failed to get block definition for type: ${n._type}`, a), !1;
752
755
  }
753
756
  }) : !1, useSavePage = () => {
754
- const [o, r] = useAtom$1(builderSaveStateAtom), n = useBuilderProp("onSave", async (m) => {
755
- }), a = useBuilderProp("onSaveStateChange", noop), l = useGetPageData(), [i] = useTheme(), { hasPermission: c } = usePermissions(), { selectedLang: d, fallbackLang: p } = useLanguages(), u = () => {
756
- const m = l();
757
- return !d || d === p ? !1 : checkMissingTranslations(m.blocks || [], d);
757
+ const [o, r] = useAtom$1(builderSaveStateAtom), n = useBuilderProp("onSave", async (f) => {
758
+ }), a = useBuilderProp("onSaveStateChange", noop), l = useGetPageData(), [i] = useTheme(), { hasPermission: c } = usePermissions(), { selectedLang: d, fallbackLang: p } = useLanguages(), u = useIsPageLoaded(), g = () => {
759
+ const f = l();
760
+ return !d || d === p ? !1 : checkMissingTranslations(f.blocks || [], d);
758
761
  };
759
762
  return { savePage: useThrottledCallback(
760
- async (m = !1) => {
761
- if (!c("save_page"))
763
+ async (f = !1) => {
764
+ if (!c("save_page") || !u)
762
765
  return;
763
766
  r("SAVING"), a("SAVING");
764
- const f = l();
767
+ const x = l();
765
768
  return await n({
766
- autoSave: m,
767
- blocks: f.blocks,
769
+ autoSave: f,
770
+ blocks: x.blocks,
768
771
  theme: i,
769
- needTranslations: u()
772
+ needTranslations: g()
770
773
  }), setTimeout(() => {
771
774
  r("SAVED"), a("SAVED");
772
775
  }, 100), !0;
773
776
  },
774
- [l, r, i, n, a],
777
+ [l, r, i, n, a, u],
775
778
  3e3
776
779
  // save only every 5 seconds
777
780
  ), savePageAsync: async () => {
778
- if (!c("save_page"))
781
+ if (!c("save_page") || !u)
779
782
  return;
780
783
  r("SAVING"), a("SAVING");
781
- const m = l();
784
+ const f = l();
782
785
  return await n({
783
786
  autoSave: !0,
784
- blocks: m.blocks,
787
+ blocks: f.blocks,
785
788
  theme: i,
786
- needTranslations: u()
789
+ needTranslations: g()
787
790
  }), setTimeout(() => {
788
791
  r("SAVED"), a("SAVED");
789
792
  }, 100), !0;
790
- }, saveState: o, setSaveState: r, needTranslations: u };
793
+ }, saveState: o, setSaveState: r, needTranslations: g };
791
794
  }, undoManager = new UndoManager();
792
795
  undoManager.setLimit(50);
793
796
  const undoRedoStateAtom = atom({
@@ -840,13 +843,13 @@ const undoRedoStateAtom = atom({
840
843
  } = useBlocksStoreManager();
841
844
  return {
842
845
  moveBlocks: (x, y, b) => {
843
- const A = map(x, (B) => {
844
- const w = r.find((E) => E._id === B)._parent || null, v = r.filter((E) => w ? E._parent === w : !E._parent).map((E) => E._id).indexOf(B);
845
- return { _id: B, oldParent: w, oldPosition: v };
846
- }), _ = A.find(({ _id: B }) => B === x[0]);
847
- _ && _.oldParent === y && _.oldPosition === b || (i(x, y, b), o({
848
- undo: () => each(A, ({ _id: B, oldParent: N, oldPosition: w }) => {
849
- i([B], N, w);
846
+ const A = map(x, (_) => {
847
+ const w = r.find((B) => B._id === _)._parent || null, v = r.filter((B) => w ? B._parent === w : !B._parent).map((B) => B._id).indexOf(_);
848
+ return { _id: _, oldParent: w, oldPosition: v };
849
+ }), E = A.find(({ _id: _ }) => _ === x[0]);
850
+ E && E.oldParent === y && E.oldPosition === b || (i(x, y, b), o({
851
+ undo: () => each(A, ({ _id: _, oldParent: N, oldPosition: w }) => {
852
+ i([_], N, w);
850
853
  }),
851
854
  redo: () => i(x, y, b)
852
855
  }));
@@ -858,8 +861,8 @@ const undoRedoStateAtom = atom({
858
861
  });
859
862
  },
860
863
  removeBlocks: (x) => {
861
- var _;
862
- const y = (_ = first(x)) == null ? void 0 : _._parent, A = r.filter((B) => y ? B._parent === y : !B._parent).indexOf(first(x));
864
+ var E;
865
+ const y = (E = first(x)) == null ? void 0 : E._parent, A = r.filter((_) => y ? _._parent === y : !_._parent).indexOf(first(x));
863
866
  l(map(x, "_id")), o({
864
867
  undo: () => a(x, y, A),
865
868
  redo: () => l(map(x, "_id"))
@@ -868,17 +871,17 @@ const undoRedoStateAtom = atom({
868
871
  updateBlocks: (x, y, b) => {
869
872
  let A = [];
870
873
  if (b)
871
- A = map(x, (_) => ({ _id: _, ...b }));
874
+ A = map(x, (E) => ({ _id: E, ...b }));
872
875
  else {
873
- const _ = keys(y);
874
- A = map(x, (B) => {
875
- const N = r.find((k) => k._id === B), w = { _id: B };
876
- return each(_, (k) => w[k] = N[k]), w;
876
+ const E = keys(y);
877
+ A = map(x, (_) => {
878
+ const N = r.find((k) => k._id === _), w = { _id: _ };
879
+ return each(E, (k) => w[k] = N[k]), w;
877
880
  });
878
881
  }
879
- c(map(x, (_) => ({ _id: _, ...y }))), o({
882
+ c(map(x, (E) => ({ _id: E, ...y }))), o({
880
883
  undo: () => c(A),
881
- redo: () => c(map(x, (_) => ({ _id: _, ...y })))
884
+ redo: () => c(map(x, (E) => ({ _id: E, ...y })))
882
885
  });
883
886
  },
884
887
  updateBlocksRuntime: (x, y) => {
@@ -893,8 +896,8 @@ const undoRedoStateAtom = atom({
893
896
  updateMultipleBlocksProps: (x) => {
894
897
  let y = [];
895
898
  y = map(x, (b) => {
896
- const A = keys(b), _ = r.find((N) => N._id === b._id), B = {};
897
- return each(A, (N) => B[N] = _[N]), B;
899
+ const A = keys(b), E = r.find((N) => N._id === b._id), _ = {};
900
+ return each(A, (N) => _[N] = E[N]), _;
898
901
  }), c(x), o({
899
902
  undo: () => c(y),
900
903
  redo: () => c(x)
@@ -2352,12 +2355,15 @@ function getChildBlocks(o, r, n) {
2352
2355
  const getBlockWithChildren = (o, r) => {
2353
2356
  let n = [];
2354
2357
  return n = flattenDeep([...n, ...getChildBlocks(r, o, n)]), n;
2355
- }, pickOnlyAIProps = (o, r) => compact(
2356
- o.map((n) => {
2357
- const a = ["_id", "_type", "_parent"], l = pick(n, a), i = getRegisteredChaiBlock(n._type), c = {}, d = get(i, "aiProps", []);
2358
- for (const p in n)
2359
- a.includes(p) || d.includes(p) && (c[p] = get(n, `${p}-${r}`, n[p]));
2360
- return isEmpty(c) ? !1 : (has(l, "_parent") && isEmpty(l._parent) && delete l._parent, { ...l, ...c });
2358
+ }, pickOnlyAIProps = (o, r, n) => compact(
2359
+ o.map((a) => {
2360
+ const l = ["_id", "_type", "_parent"], i = pick(a, l), c = getRegisteredChaiBlock(a._type), d = {}, p = get(c, "aiProps", []);
2361
+ for (const u in a)
2362
+ if (!l.includes(u) && p.includes(u)) {
2363
+ const g = get(a, `${u}-${r}`, ""), h = get(a, u, "");
2364
+ d[u] = isString(g) && g.trim() || h, n && (d[u] = h);
2365
+ }
2366
+ return isEmpty(d) ? !1 : (has(i, "_parent") && isEmpty(i._parent) && delete i._parent, { ...i, ...d });
2361
2367
  })
2362
2368
  ), addLangToPrompt = (o, r, n) => !r || n !== "content" ? o : `${o}. Generate content in ${get(LANGUAGES, r, r)} language.`, askAiProcessingAtom = atom(!1), useAskAi = () => {
2363
2369
  const [o, r] = useAtom$1(askAiProcessingAtom), [n, a] = useState(null), l = useBuilderProp("askAiCallBack", null), i = useStreamMultipleBlocksProps(), c = useUpdateMultipleBlocksProps(), [d] = useBlocksStore(), { selectedLang: p, fallbackLang: u } = useLanguages(), g = p.length ? p : u, h = (m, f) => {
@@ -2365,8 +2371,8 @@ const getBlockWithChildren = (o, r) => {
2365
2371
  for (const y in x) {
2366
2372
  const b = x[y];
2367
2373
  if (typeof b == "string" && startsWith(b, STYLES_KEY)) {
2368
- const { baseClasses: A, classes: _ } = getSplitChaiClasses(b);
2369
- x[y] = compact(flattenDeep([A, _])).join(" ");
2374
+ const { baseClasses: A, classes: E } = getSplitChaiClasses(b);
2375
+ x[y] = compact(flattenDeep([A, E])).join(" ");
2370
2376
  } else
2371
2377
  y !== "_id" && delete x[y];
2372
2378
  }
@@ -2378,20 +2384,22 @@ const getBlockWithChildren = (o, r) => {
2378
2384
  if (l) {
2379
2385
  r(!0), a(null);
2380
2386
  try {
2381
- const b = p === u ? "" : p, A = m === "content" ? pickOnlyAIProps(cloneDeep(getBlockWithChildren(f, d)), p) : [h(f, d)], _ = await l(m, addLangToPrompt(x, g, m), A, b), { blocks: B, error: N } = _;
2382
- if (N) {
2383
- a(N);
2387
+ const b = p === u ? "" : p;
2388
+ console.log("prompt", x);
2389
+ const A = x.toLowerCase().includes("translate the content"), E = m === "content" ? pickOnlyAIProps(cloneDeep(getBlockWithChildren(f, d)), p, A) : [h(f, d)], _ = await l(m, addLangToPrompt(x, g, m), E, b), { blocks: N, error: w } = _;
2390
+ if (w) {
2391
+ a(w);
2384
2392
  return;
2385
2393
  }
2386
2394
  if (m === "styles") {
2387
- const w = B.map((k) => {
2388
- for (const v in k)
2389
- v !== "_id" && (k[v] = `${STYLES_KEY},${k[v]}`);
2390
- return k;
2395
+ const k = N.map((v) => {
2396
+ for (const B in v)
2397
+ B !== "_id" && (v[B] = `${STYLES_KEY},${v[B]}`);
2398
+ return v;
2391
2399
  });
2392
- c(w);
2400
+ c(k);
2393
2401
  } else
2394
- i(B);
2402
+ i(N);
2395
2403
  y && y(_);
2396
2404
  } catch (b) {
2397
2405
  a(b);
@@ -3596,17 +3604,17 @@ const ChaiFrame = React__default.forwardRef((o, r) => /* @__PURE__ */ jsx(Frame,
3596
3604
  }
3597
3605
  ), WithBlockTextEditor = memo(
3598
3606
  ({ block: o, children: r }) => {
3599
- const n = "content", { document: a } = useFrame(), { editingBlockId: l, editingItemIndex: i, setEditingBlockId: c, setEditingItemIndex: d } = useInlineEditing(), [p, u] = useState(null), g = useRef(null), { clearHighlight: h } = useBlockHighlight(), m = useUpdateBlocksProps(), { selectedLang: f } = useLanguages(), [, x] = useSelectedBlockIds(), y = useRef(null), b = l, { blockContent: A, blockType: _ } = useMemo(() => {
3607
+ const n = "content", { document: a } = useFrame(), { editingBlockId: l, editingItemIndex: i, setEditingBlockId: c, setEditingItemIndex: d } = useInlineEditing(), [p, u] = useState(null), g = useRef(null), { clearHighlight: h } = useBlockHighlight(), m = useUpdateBlocksProps(), { selectedLang: f } = useLanguages(), [, x] = useSelectedBlockIds(), y = useRef(null), b = l, { blockContent: A, blockType: E } = useMemo(() => {
3600
3608
  var j;
3601
3609
  const v = o._type;
3602
- let E = o[n];
3610
+ let B = o[n];
3603
3611
  const S = getRegisteredChaiBlock(o._type);
3604
- return f && ((j = S == null ? void 0 : S.i18nProps) == null ? void 0 : j.includes(n)) && has(o, `${n}-${f}`) && (E = get(o, `${n}-${f}`)), { blockContent: E, blockType: v };
3605
- }, [o, f]), B = useCallback(
3612
+ return f && ((j = S == null ? void 0 : S.i18nProps) == null ? void 0 : j.includes(n)) && has(o, `${n}-${f}`) && (B = get(o, `${n}-${f}`)), { blockContent: B, blockType: v };
3613
+ }, [o, f]), _ = useCallback(
3606
3614
  (v) => {
3607
3615
  var S;
3608
- const E = v || ((S = g.current) == null ? void 0 : S.innerText);
3609
- m([b], { [n]: E }), u(null), c(null), d(-1), x(b ? [b] : []);
3616
+ const B = v || ((S = g.current) == null ? void 0 : S.innerText);
3617
+ m([b], { [n]: B }), u(null), c(null), d(-1), x(b ? [b] : []);
3610
3618
  },
3611
3619
  [b, m, c, x, f]
3612
3620
  ), N = useDebouncedCallback(
@@ -3617,9 +3625,9 @@ const ChaiFrame = React__default.forwardRef((o, r) => /* @__PURE__ */ jsx(Frame,
3617
3625
  1e3
3618
3626
  ), w = useCallback(
3619
3627
  (v) => {
3620
- v.preventDefault(), b && (y.current = b), B(), setTimeout(() => {
3621
- const E = y.current;
3622
- y.current = null, x([E]);
3628
+ v.preventDefault(), b && (y.current = b), _(), setTimeout(() => {
3629
+ const B = y.current;
3630
+ y.current = null, x([B]);
3623
3631
  }, 100);
3624
3632
  },
3625
3633
  [x, b, f]
@@ -3627,16 +3635,16 @@ const ChaiFrame = React__default.forwardRef((o, r) => /* @__PURE__ */ jsx(Frame,
3627
3635
  useEffect(() => {
3628
3636
  var C;
3629
3637
  if (!b) return;
3630
- const v = `[data-block-id="${b}"]`, E = i >= 0 ? `[data-block-index="${i}"]` : "", S = a.querySelector(`${v}${E}`);
3638
+ const v = `[data-block-id="${b}"]`, B = i >= 0 ? `[data-block-index="${i}"]` : "", S = a.querySelector(`${v}${B}`);
3631
3639
  S && ((C = S == null ? void 0 : S.classList) == null || C.add("sr-only"), u(S));
3632
- }, [b, _, a, i]);
3633
- const k = useMemo(() => p ? (h(), _ === "RichText" ? /* @__PURE__ */ jsx(
3640
+ }, [b, E, a, i]);
3641
+ const k = useMemo(() => p ? (h(), E === "RichText" ? /* @__PURE__ */ jsx(
3634
3642
  RichTextEditor,
3635
3643
  {
3636
3644
  blockContent: A,
3637
3645
  editingElement: p,
3638
3646
  onChange: N,
3639
- onClose: B,
3647
+ onClose: _,
3640
3648
  onEscape: w
3641
3649
  }
3642
3650
  ) : /* @__PURE__ */ jsx(
@@ -3645,11 +3653,11 @@ const ChaiFrame = React__default.forwardRef((o, r) => /* @__PURE__ */ jsx(Frame,
3645
3653
  editorRef: g,
3646
3654
  blockContent: A,
3647
3655
  editingElement: p,
3648
- onClose: B,
3656
+ onClose: _,
3649
3657
  onChange: N,
3650
3658
  onEscape: w
3651
3659
  }
3652
- )) : null, [p, b, _, A, B, f]);
3660
+ )) : null, [p, b, E, A, _, f]);
3653
3661
  return /* @__PURE__ */ jsxs(Fragment, { children: [
3654
3662
  k,
3655
3663
  r
@@ -3690,17 +3698,17 @@ const ChaiFrame = React__default.forwardRef((o, r) => /* @__PURE__ */ jsx(Frame,
3690
3698
  key: y
3691
3699
  }) : applyLanguage(i, d, c),
3692
3700
  [i, d, c, g, m, x, y]
3693
- ), A = useMemo(() => getBlockTagAttributes(i), [i, getBlockTagAttributes]), _ = useMemo(
3701
+ ), A = useMemo(() => getBlockTagAttributes(i), [i, getBlockTagAttributes]), E = useMemo(
3694
3702
  () => u(i._id, getBlockRuntimeProps(i._type)),
3695
3703
  [i._id, i._type, u, getBlockRuntimeProps]
3696
- ), B = useMemo(
3704
+ ), _ = useMemo(
3697
3705
  () => ({
3698
3706
  blockProps: { "data-block-id": i._id, "data-block-type": i._type, "data-block-index": x },
3699
3707
  inBuilder: !0,
3700
3708
  lang: d || p,
3701
3709
  ...b,
3702
3710
  ...A,
3703
- ..._,
3711
+ ...E,
3704
3712
  ...o
3705
3713
  }),
3706
3714
  [
@@ -3710,13 +3718,13 @@ const ChaiFrame = React__default.forwardRef((o, r) => /* @__PURE__ */ jsx(Frame,
3710
3718
  p,
3711
3719
  b,
3712
3720
  A,
3713
- _,
3721
+ E,
3714
3722
  o
3715
3723
  ]
3716
3724
  ), N = useMemo(() => !CORE_BLOCKS.includes(i._type), [i._type]);
3717
3725
  if (isNull(f) || h.includes(i._id)) return null;
3718
3726
  let w = /* @__PURE__ */ jsx(Suspense, { children: createElement(f, {
3719
- ...B,
3727
+ ..._,
3720
3728
  children: n({
3721
3729
  _id: i._id,
3722
3730
  _type: i._type,
@@ -4028,15 +4036,15 @@ const PLACEHOLDER_IMAGE = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTAwIiBoZWl
4028
4036
  const b = isArray(y) ? first(y) : y;
4029
4037
  if (b) {
4030
4038
  r(b == null ? void 0 : b.url);
4031
- const A = b == null ? void 0 : b.width, _ = b == null ? void 0 : b.height;
4039
+ const A = b == null ? void 0 : b.width, E = b == null ? void 0 : b.height;
4032
4040
  if (c != null && c._id) {
4033
- const B = {
4041
+ const _ = {
4034
4042
  ...A && { width: A },
4035
- ..._ && { height: _ },
4043
+ ...E && { height: E },
4036
4044
  ...b.description && { alt: b.description }
4037
4045
  };
4038
- if (set(B, u, b.id), isEmpty(B)) return;
4039
- d([c._id], B);
4046
+ if (set(_, u, b.id), isEmpty(_)) return;
4047
+ d([c._id], _);
4040
4048
  }
4041
4049
  }
4042
4050
  }, x = useCallback(() => {
@@ -4203,12 +4211,12 @@ const DataBindingSelector = ({
4203
4211
  r(`{{${g}}}`, {}, n);
4204
4212
  return;
4205
4213
  }
4206
- const m = (b) => /[.,!?;:]/.test(b), f = (b, A, _) => {
4207
- let B = "", N = "";
4214
+ const m = (b) => /[.,!?;:]/.test(b), f = (b, A, E) => {
4215
+ let _ = "", N = "";
4208
4216
  const w = A > 0 ? b[A - 1] : "", k = A < b.length ? b[A] : "";
4209
- return A > 0 && (w === "." || !m(w) && w !== " ") && (B = " "), A < b.length && !m(k) && k !== " " && (N = " "), {
4210
- text: B + _ + N,
4211
- prefixLength: B.length,
4217
+ return A > 0 && (w === "." || !m(w) && w !== " ") && (_ = " "), A < b.length && !m(k) && k !== " " && (N = " "), {
4218
+ text: _ + E + N,
4219
+ prefixLength: _.length,
4212
4220
  suffixLength: N.length
4213
4221
  };
4214
4222
  }, x = document.getElementById(n);
@@ -4219,27 +4227,27 @@ const DataBindingSelector = ({
4219
4227
  if (b) {
4220
4228
  const A = `{{${g}}}`;
4221
4229
  b.commands.focus();
4222
- const { from: _, to: B } = b.state.selection;
4223
- if (_ !== B)
4230
+ const { from: E, to: _ } = b.state.selection;
4231
+ if (E !== _)
4224
4232
  b.chain().deleteSelection().insertContent(A).run();
4225
4233
  else {
4226
- const { state: w } = b, k = w.selection.from, v = w.doc.textBetween(Math.max(0, k - 1), k), E = w.doc.textBetween(k, Math.min(k + 1, w.doc.content.size));
4234
+ const { state: w } = b, k = w.selection.from, v = w.doc.textBetween(Math.max(0, k - 1), k), B = w.doc.textBetween(k, Math.min(k + 1, w.doc.content.size));
4227
4235
  let S = "";
4228
4236
  k > 0 && v !== " " && !m(v) && (S = " ");
4229
4237
  let C = "";
4230
- E && E !== " " && !m(E) && (C = " "), b.chain().insertContent(S + A + C).run();
4238
+ B && B !== " " && !m(B) && (C = " "), b.chain().insertContent(S + A + C).run();
4231
4239
  }
4232
4240
  setTimeout(() => r(b.getHTML(), {}, n), 100);
4233
4241
  return;
4234
4242
  }
4235
4243
  } else {
4236
- const b = x, A = b.selectionStart || 0, _ = b.value || "", B = b.selectionEnd || A;
4237
- if (B > A) {
4238
- const E = `{{${g}}}`, { text: S } = f(_, A, E), C = _.slice(0, A) + S + _.slice(B);
4244
+ const b = x, A = b.selectionStart || 0, E = b.value || "", _ = b.selectionEnd || A;
4245
+ if (_ > A) {
4246
+ const B = `{{${g}}}`, { text: S } = f(E, A, B), C = E.slice(0, A) + S + E.slice(_);
4239
4247
  r(C, {}, n);
4240
4248
  return;
4241
4249
  }
4242
- const w = `{{${g}}}`, { text: k } = f(_, A, w), v = _.slice(0, A) + k + _.slice(A);
4250
+ const w = `{{${g}}}`, { text: k } = f(E, A, w), v = E.slice(0, A) + k + E.slice(A);
4243
4251
  r(v, {}, n);
4244
4252
  }
4245
4253
  },
@@ -4261,8 +4269,8 @@ const DataBindingSelector = ({
4261
4269
  pageTypes: r,
4262
4270
  onChange: n
4263
4271
  }) => {
4264
- var E;
4265
- const { t: a } = useTranslation(), l = useBuilderProp("searchPageTypeItems", (S, C) => []), [i, c] = useState(!1), [d, p] = useState(!1), [u, g] = useState("page"), [h, m] = useState(""), [f, x] = useState([]), [y, b] = useState(-1), A = useRef(null), _ = (E = r == null ? void 0 : r.find((S) => S.key === u)) == null ? void 0 : E.name;
4272
+ var B;
4273
+ const { t: a } = useTranslation(), l = useBuilderProp("searchPageTypeItems", (S, C) => []), [i, c] = useState(!1), [d, p] = useState(!1), [u, g] = useState("page"), [h, m] = useState(""), [f, x] = useState([]), [y, b] = useState(-1), A = useRef(null), E = (B = r == null ? void 0 : r.find((S) => S.key === u)) == null ? void 0 : B.name;
4266
4274
  useEffect(() => {
4267
4275
  if (m(""), x([]), b(-1), p(!1), !o || i || !startsWith(o, "pageType:")) return;
4268
4276
  const S = split(o, ":"), C = get(S, 1, "page") || "page";
@@ -4271,7 +4279,7 @@ const DataBindingSelector = ({
4271
4279
  j && Array.isArray(j) && m(get(j, [0, "name"], ""));
4272
4280
  })();
4273
4281
  }, [o]);
4274
- const B = useDebouncedCallback(
4282
+ const _ = useDebouncedCallback(
4275
4283
  async (S) => {
4276
4284
  if (isEmpty(S))
4277
4285
  x([]);
@@ -4312,7 +4320,7 @@ const DataBindingSelector = ({
4312
4320
  const k = () => {
4313
4321
  m(""), x([]), b(-1), p(!1), n("");
4314
4322
  }, v = (S) => {
4315
- m(S), p(!isEmpty(S)), c(!0), B(S);
4323
+ m(S), p(!isEmpty(S)), c(!0), _(S);
4316
4324
  };
4317
4325
  return /* @__PURE__ */ jsxs("div", { children: [
4318
4326
  /* @__PURE__ */ jsx("select", { name: "pageType", value: u, onChange: (S) => g(S.target.value), children: map(r, (S) => /* @__PURE__ */ jsx("option", { value: S.key, children: S.name }, S.key)) }),
@@ -4324,7 +4332,7 @@ const DataBindingSelector = ({
4324
4332
  value: h,
4325
4333
  onChange: (S) => v(S.target.value),
4326
4334
  onKeyDown: w,
4327
- placeholder: a(`Search ${_ ?? ""}`),
4335
+ placeholder: a(`Search ${E ?? ""}`),
4328
4336
  className: "w-full rounded-md border border-gray-300 p-2 pr-16"
4329
4337
  }
4330
4338
  ),
@@ -4657,11 +4665,11 @@ const MenuBar = ({ editor: o, onExpand: r }) => {
4657
4665
  if (f !== x)
4658
4666
  u.chain().deleteSelection().insertContent(m).run();
4659
4667
  else {
4660
- const { state: b } = u, A = b.selection.from, _ = b.doc.textBetween(Math.max(0, A - 1), A), B = b.doc.textBetween(A, Math.min(A + 1, b.doc.content.size));
4668
+ const { state: b } = u, A = b.selection.from, E = b.doc.textBetween(Math.max(0, A - 1), A), _ = b.doc.textBetween(A, Math.min(A + 1, b.doc.content.size));
4661
4669
  let N = "";
4662
- A > 0 && _ !== " " && !/[.,!?;:]/.test(_) && (N = " ");
4670
+ A > 0 && E !== " " && !/[.,!?;:]/.test(E) && (N = " ");
4663
4671
  let w = "";
4664
- B && B !== " " && !/[.,!?;:]/.test(B) && (w = " "), u.chain().insertContent(N + m + w).run();
4672
+ _ && _ !== " " && !/[.,!?;:]/.test(_) && (w = " "), u.chain().insertContent(N + m + w).run();
4665
4673
  }
4666
4674
  };
4667
4675
  return /* @__PURE__ */ jsx(Dialog, { open: o, onOpenChange: (h) => !h && r(), children: /* @__PURE__ */ jsxs(DialogContent, { className: "max-h-[90vh] overflow-y-auto sm:max-w-[800px]", children: [
@@ -4961,25 +4969,25 @@ const MenuBar = ({ editor: o, onExpand: r }) => {
4961
4969
  const { selectedLang: h, fallbackLang: m, languages: f } = useLanguages(), x = useMemo(
4962
4970
  () => isEmpty(f) ? "" : isEmpty(h) ? m : h,
4963
4971
  [f, h, m]
4964
- ), y = useMemo(() => get(LANGUAGES, x, x), [x]), b = usePageExternalData(), A = useSelectedBlock(), _ = useRegisteredChaiBlocks(), B = useMemo(
4965
- () => get(_, [A == null ? void 0 : A._type, "i18nProps"], []),
4966
- [_, A == null ? void 0 : A._type]
4972
+ ), y = useMemo(() => get(LANGUAGES, x, x), [x]), b = usePageExternalData(), A = useSelectedBlock(), E = useRegisteredChaiBlocks(), _ = useMemo(
4973
+ () => get(E, [A == null ? void 0 : A._type, "i18nProps"], []),
4974
+ [E, A == null ? void 0 : A._type]
4967
4975
  ), [N, w] = useState(null);
4968
4976
  if (c)
4969
4977
  return null;
4970
4978
  if (p.type === "boolean") return /* @__PURE__ */ jsx("div", { className: r, children: a });
4971
- const v = B == null ? void 0 : B.includes(o.replace("root.", ""));
4979
+ const v = _ == null ? void 0 : _.includes(o.replace("root.", ""));
4972
4980
  if (p.type === "array") {
4973
- const E = N === o;
4981
+ const B = N === o;
4974
4982
  return /* @__PURE__ */ jsxs("div", { className: `${r} relative`, children: [
4975
4983
  p.title && /* @__PURE__ */ jsx("div", { className: "flex items-center justify-between gap-1", children: /* @__PURE__ */ jsxs(
4976
4984
  "label",
4977
4985
  {
4978
4986
  htmlFor: o,
4979
- onClick: () => w(E ? null : o),
4987
+ onClick: () => w(B ? null : o),
4980
4988
  className: "flex cursor-pointer items-center gap-x-1 py-1 leading-tight duration-200 hover:bg-slate-100",
4981
4989
  children: [
4982
- E ? /* @__PURE__ */ jsx(ChevronDown, { className: "h-3 w-3" }) : /* @__PURE__ */ jsx(ChevronRight, { className: "h-3 w-3" }),
4990
+ B ? /* @__PURE__ */ jsx(ChevronDown, { className: "h-3 w-3" }) : /* @__PURE__ */ jsx(ChevronRight, { className: "h-3 w-3" }),
4983
4991
  /* @__PURE__ */ jsx(List, { className: "h-3 w-3" }),
4984
4992
  /* @__PURE__ */ jsx("span", { className: "leading-tight", children: n }),
4985
4993
  " ",
@@ -4998,7 +5006,7 @@ const MenuBar = ({ editor: o, onExpand: r }) => {
4998
5006
  ]
4999
5007
  }
5000
5008
  ) }),
5001
- (u == null ? void 0 : u.length) === 0 ? /* @__PURE__ */ jsx("div", { className: "h-0 overflow-hidden", children: a }) : /* @__PURE__ */ jsxs("div", { className: `${E ? "pt-0.5" : "h-0 overflow-hidden"}`, children: [
5009
+ (u == null ? void 0 : u.length) === 0 ? /* @__PURE__ */ jsx("div", { className: "h-0 overflow-hidden", children: a }) : /* @__PURE__ */ jsxs("div", { className: `${B ? "pt-0.5" : "h-0 overflow-hidden"}`, children: [
5002
5010
  a,
5003
5011
  l,
5004
5012
  i
@@ -5026,8 +5034,8 @@ const MenuBar = ({ editor: o, onExpand: r }) => {
5026
5034
  DataBindingSelector,
5027
5035
  {
5028
5036
  schema: p,
5029
- onChange: (E) => {
5030
- g(E, u, o);
5037
+ onChange: (B) => {
5038
+ g(B, u, o);
5031
5039
  },
5032
5040
  id: o,
5033
5041
  formData: u
@@ -5144,21 +5152,21 @@ function BlockSettings() {
5144
5152
  k && (n([r._id], { [k]: get(w, k) }), x({ formData: w }, k, { [k]: get(c, k) }));
5145
5153
  }, b = ({ formData: w }, k) => {
5146
5154
  k && (n([g._id], { [k]: get(w, k) }), x({ formData: w }, k, { [k]: get(c, k) }));
5147
- }, { schema: A, uiSchema: _ } = useMemo(() => {
5155
+ }, { schema: A, uiSchema: E } = useMemo(() => {
5148
5156
  const w = r == null ? void 0 : r._type;
5149
5157
  if (!w)
5150
5158
  return { schema: {}, uiSchema: {} };
5151
5159
  try {
5152
5160
  const { schema: k, uiSchema: v } = getBlockFormSchemas(w);
5153
5161
  if (w === "Repeater") {
5154
- const E = get(r, "repeaterItems", "");
5155
- startsWith(E, `{{${COLLECTION_PREFIX}`) ? (set(v, "filter", { "ui:widget": "collectionSelect" }), set(v, "sort", { "ui:widget": "collectionSelect" })) : (set(v, "filter", { "ui:widget": "hidden" }), set(v, "sort", { "ui:widget": "hidden" }));
5162
+ const B = get(r, "repeaterItems", "");
5163
+ startsWith(B, `{{${COLLECTION_PREFIX}`) ? (set(v, "filter", { "ui:widget": "collectionSelect" }), set(v, "sort", { "ui:widget": "collectionSelect" })) : (set(v, "filter", { "ui:widget": "hidden" }), set(v, "sort", { "ui:widget": "hidden" }));
5156
5164
  }
5157
5165
  return { schema: k, uiSchema: v };
5158
5166
  } catch {
5159
5167
  return { schema: {}, uiSchema: {} };
5160
5168
  }
5161
- }, [r]), { wrapperSchema: B, wrapperUiSchema: N } = useMemo(() => {
5169
+ }, [r]), { wrapperSchema: _, wrapperUiSchema: N } = useMemo(() => {
5162
5170
  if (!g || !(g != null && g._type))
5163
5171
  return { wrapperSchema: {}, wrapperUiSchema: {} };
5164
5172
  const w = g == null ? void 0 : g._type, { schema: k = {}, uiSchema: v = {} } = getBlockFormSchemas(w);
@@ -5190,7 +5198,7 @@ function BlockSettings() {
5190
5198
  blockId: g == null ? void 0 : g._id,
5191
5199
  onChange: b,
5192
5200
  formData: m,
5193
- schema: B,
5201
+ schema: _,
5194
5202
  uiSchema: N
5195
5203
  }
5196
5204
  ) })
@@ -5202,7 +5210,7 @@ function BlockSettings() {
5202
5210
  onChange: y,
5203
5211
  formData: i,
5204
5212
  schema: A,
5205
- uiSchema: _
5213
+ uiSchema: E
5206
5214
  }
5207
5215
  )
5208
5216
  ] });
@@ -5413,7 +5421,7 @@ const BlockStylingProps = () => {
5413
5421
  },
5414
5422
  a
5415
5423
  )) }), THROTTLE_TIME = 50, AdvanceChoices = (o) => {
5416
- const [r, n] = useState(!1), [a, l] = useState(""), { currentClass: i, onChange: c, classPrefix: d, cssProperty: p, units: u, negative: g } = o, [h, m] = useState(p != null && p.toLowerCase().includes("width") ? "%" : u[0]), [f, x] = useState(!1), [y, b] = useState(""), [A, _] = useState(!1), [B, N] = useState(!1);
5424
+ const [r, n] = useState(!1), [a, l] = useState(""), { currentClass: i, onChange: c, classPrefix: d, cssProperty: p, units: u, negative: g } = o, [h, m] = useState(p != null && p.toLowerCase().includes("width") ? "%" : u[0]), [f, x] = useState(!1), [y, b] = useState(""), [A, E] = useState(!1), [_, N] = useState(!1);
5417
5425
  useEffect(() => {
5418
5426
  const { value: S, unit: C } = getClassValueAndUnit(i);
5419
5427
  if (C === "") {
@@ -5440,7 +5448,7 @@ const BlockStylingProps = () => {
5440
5448
  S ? k(T) : w(T);
5441
5449
  },
5442
5450
  [w, k, a, h, d, u]
5443
- ), E = useCallback(
5451
+ ), B = useCallback(
5444
5452
  (S) => {
5445
5453
  const C = getUserInputValues(`${a}`, u);
5446
5454
  if (get(C, "error", !1)) {
@@ -5487,11 +5495,11 @@ const BlockStylingProps = () => {
5487
5495
  const C = parseInt$1(S.target.value);
5488
5496
  let j = isNaN$1(C) ? 0 : C;
5489
5497
  S.keyCode === 38 && (j += 1), S.keyCode === 40 && (j -= 1);
5490
- const I = `${j}`, R = `${I.startsWith("-") ? "-" : ""}${d}[${I.replace("-", "")}${h === "-" ? "" : h}]`;
5491
- k(R);
5498
+ const I = `${j}`, P = `${I.startsWith("-") ? "-" : ""}${d}[${I.replace("-", "")}${h === "-" ? "" : h}]`;
5499
+ k(P);
5492
5500
  },
5493
5501
  onKeyUp: (S) => {
5494
- B && (S.preventDefault(), N(!1));
5502
+ _ && (S.preventDefault(), N(!1));
5495
5503
  },
5496
5504
  onBlur: () => v(),
5497
5505
  onChange: (S) => {
@@ -5527,7 +5535,7 @@ const BlockStylingProps = () => {
5527
5535
  units: u,
5528
5536
  current: h,
5529
5537
  onSelect: (S) => {
5530
- n(!1), m(S), E(S);
5538
+ n(!1), m(S), B(S);
5531
5539
  }
5532
5540
  }
5533
5541
  ) })
@@ -5536,9 +5544,9 @@ const BlockStylingProps = () => {
5536
5544
  ["none", "auto"].indexOf(h) !== -1 || A ? null : /* @__PURE__ */ jsx(
5537
5545
  DragStyleButton,
5538
5546
  {
5539
- onDragStart: () => _(!0),
5547
+ onDragStart: () => E(!0),
5540
5548
  onDragEnd: (S) => {
5541
- if (b(() => ""), _(!1), isEmpty(S))
5549
+ if (b(() => ""), E(!1), isEmpty(S))
5542
5550
  return;
5543
5551
  const C = `${S}`, I = `${C.startsWith("-") ? "-" : ""}${d}[${C.replace("-", "")}${h === "-" ? "" : h}]`;
5544
5552
  w(I);
@@ -6013,21 +6021,21 @@ const COLOR_PROP = {
6013
6021
  const { t: r } = useTranslation(), { type: n = "icons", label: a, property: l, onEmitChange: i = () => {
6014
6022
  }, units: c, negative: d = !1 } = o, [p] = useDarkMode(), [u] = useStylingState(), [, g] = useScreenSizeWidth(), h = useCurrentClassByProperty(l), m = useAddClassesToBlocks(), f = useRemoveClassesFromBlocks(), [x] = useSelectedBlockIds(), y = useMemo(() => get(h, "fullCls", ""), [h]), b = useCallback(
6015
6023
  (k, v = !0) => {
6016
- const E = { dark: p, mq: g, mod: u, cls: k, property: l, fullCls: "" };
6017
- (p || u !== "") && (E.mq = "xs");
6018
- const S = generateFullClsName(E);
6024
+ const B = { dark: p, mq: g, mod: u, cls: k, property: l, fullCls: "" };
6025
+ (p || u !== "") && (B.mq = "xs");
6026
+ const S = generateFullClsName(B);
6019
6027
  m(x, [S], v);
6020
6028
  },
6021
6029
  [x, p, g, u, l, m]
6022
6030
  ), A = useCallback(() => {
6023
6031
  f(x, [y], !0);
6024
- }, [x, y, f]), _ = useMemo(() => canChangeClass(h, g), [h, g]);
6032
+ }, [x, y, f]), E = useMemo(() => canChangeClass(h, g), [h, g]);
6025
6033
  useEffect(() => {
6026
- i(_, h);
6027
- }, [_, i, h]);
6028
- const [, , B] = useScreenSizeWidth(), N = useCallback(
6034
+ i(E, h);
6035
+ }, [E, i, h]);
6036
+ const [, , _] = useScreenSizeWidth(), N = useCallback(
6029
6037
  (k) => {
6030
- B({
6038
+ _({
6031
6039
  xs: 400,
6032
6040
  sm: 640,
6033
6041
  md: 800,
@@ -6036,9 +6044,9 @@ const COLOR_PROP = {
6036
6044
  "2xl": 1920
6037
6045
  }[k]);
6038
6046
  },
6039
- [B]
6047
+ [_]
6040
6048
  ), w = get(h, "dark", null) === p && get(h, "mod", null) === u && get(h, "mq", null) === g;
6041
- return /* @__PURE__ */ jsx(BlockStyleProvider, { canChange: _, canReset: h && w, children: /* @__PURE__ */ jsxs("div", { className: "group flex flex-row items-center py-2 first:pt-0 last:pb-0", children: [
6049
+ return /* @__PURE__ */ jsx(BlockStyleProvider, { canChange: E, canReset: h && w, children: /* @__PURE__ */ jsxs("div", { className: "group flex flex-row items-center py-2 first:pt-0 last:pb-0", children: [
6042
6050
  /* @__PURE__ */ jsx("div", { className: "relative w-[70px] truncate text-xs text-foreground", children: /* @__PURE__ */ jsx("span", { className: `text-[11px] ${h && !w ? "text-foreground" : ""}`, children: r(a) }) }),
6043
6051
  /* @__PURE__ */ jsxs("div", { className: "flex flex-row items-center", children: [
6044
6052
  /* @__PURE__ */ jsxs("div", { className: "w-[150px]", children: [
@@ -6058,7 +6066,7 @@ const COLOR_PROP = {
6058
6066
  n === "color" && /* @__PURE__ */ jsx(ColorChoice, { property: l, onChange: b }),
6059
6067
  n === "dropdown" && /* @__PURE__ */ jsx(DropDownChoices, { label: a, property: l, onChange: b })
6060
6068
  ] }),
6061
- /* @__PURE__ */ jsx("div", { className: `w-[30px] cursor-pointer ${y ? "visible" : "invisible"}`, children: w ? /* @__PURE__ */ jsx("button", { type: "button", onClick: () => A(), title: "Reset", className: "flex px-1.5 text-xs", children: /* @__PURE__ */ jsx(CrossCircledIcon, { className: "h-5 w-5 text-blue-500 hover:opacity-80" }) }) : _ && h ? /* @__PURE__ */ jsxs(Tooltip, { delayDuration: 100, children: [
6069
+ /* @__PURE__ */ jsx("div", { className: `w-[30px] cursor-pointer ${y ? "visible" : "invisible"}`, children: w ? /* @__PURE__ */ jsx("button", { type: "button", onClick: () => A(), title: "Reset", className: "flex px-1.5 text-xs", children: /* @__PURE__ */ jsx(CrossCircledIcon, { className: "h-5 w-5 text-blue-500 hover:opacity-80" }) }) : E && h ? /* @__PURE__ */ jsxs(Tooltip, { delayDuration: 100, children: [
6062
6070
  /* @__PURE__ */ jsx(TooltipTrigger, { asChild: !0, children: /* @__PURE__ */ jsx(
6063
6071
  "button",
6064
6072
  {
@@ -6459,24 +6467,24 @@ const AskAIStyles = ({ blockId: o }) => {
6459
6467
  };
6460
6468
  function ManualClasses() {
6461
6469
  var I;
6462
- const o = useRef(null), [r, n] = useState(""), [a, l] = useState(-1), i = useFuseSearch(), { t: c } = useTranslation(), [d] = useSelectedStylingBlocks(), p = useSelectedBlock(), u = useAddClassesToBlocks(), g = useRemoveClassesFromBlocks(), [h] = useSelectedBlockIds(), m = useBuilderProp("askAiCallBack", null), [f, x] = useState(""), y = (I = first(d)) == null ? void 0 : I.prop, { classes: b } = getSplitChaiClasses(get(p, y, "")), A = b.split(" ").filter((T) => !isEmpty(T)), _ = () => {
6470
+ const o = useRef(null), [r, n] = useState(""), [a, l] = useState(-1), i = useFuseSearch(), { t: c } = useTranslation(), [d] = useSelectedStylingBlocks(), p = useSelectedBlock(), u = useAddClassesToBlocks(), g = useRemoveClassesFromBlocks(), [h] = useSelectedBlockIds(), m = useBuilderProp("askAiCallBack", null), [f, x] = useState(""), y = (I = first(d)) == null ? void 0 : I.prop, { classes: b } = getSplitChaiClasses(get(p, y, "")), A = b.split(" ").filter((T) => !isEmpty(T)), E = () => {
6463
6471
  const T = f.trim().toLowerCase().replace(/ +(?= )/g, "").split(" ");
6464
6472
  u(h, T, !0), x("");
6465
- }, [B, N] = useState([]), w = ({ value: T }) => {
6466
- const R = T.trim().toLowerCase(), L = R.match(/.+:/g);
6473
+ }, [_, N] = useState([]), w = ({ value: T }) => {
6474
+ const P = T.trim().toLowerCase(), L = P.match(/.+:/g);
6467
6475
  let D = [];
6468
6476
  if (L && L.length > 0) {
6469
- const [P] = L, M = R.replace(P, "");
6477
+ const [R] = L, M = P.replace(R, "");
6470
6478
  D = i.search(M).map((O) => ({
6471
6479
  ...O,
6472
- item: { ...O.item, name: P + O.item.name }
6480
+ item: { ...O.item, name: R + O.item.name }
6473
6481
  }));
6474
6482
  } else
6475
- D = i.search(R);
6483
+ D = i.search(P);
6476
6484
  return N(map(D, "item"));
6477
6485
  }, k = () => {
6478
6486
  N([]);
6479
- }, v = (T) => T.name, E = (T) => /* @__PURE__ */ jsx("div", { className: "rounded-md p-1", children: T.name }), S = useMemo(
6487
+ }, v = (T) => T.name, B = (T) => /* @__PURE__ */ jsx("div", { className: "rounded-md p-1", children: T.name }), S = useMemo(
6480
6488
  () => ({
6481
6489
  ref: o,
6482
6490
  autoComplete: "off",
@@ -6491,16 +6499,16 @@ function ManualClasses() {
6491
6499
  }, 0);
6492
6500
  },
6493
6501
  onKeyDown: (T) => {
6494
- T.key === "Enter" && f.trim() !== "" && _();
6502
+ T.key === "Enter" && f.trim() !== "" && E();
6495
6503
  },
6496
- onChange: (T, { newValue: R }) => x(R),
6504
+ onChange: (T, { newValue: P }) => x(P),
6497
6505
  className: "w-full rounded-md text-xs px-2 hover:outline-0 bg-background border-border py-1"
6498
6506
  }),
6499
6507
  [f, c, o]
6500
6508
  ), C = (T) => {
6501
6509
  debugger;
6502
- const R = r.trim().toLowerCase().replace(/ +(?= )/g, "").split(" ");
6503
- g(h, [T]), u(h, R, !0), n(""), l(-1);
6510
+ const P = r.trim().toLowerCase().replace(/ +(?= )/g, "").split(" ");
6511
+ g(h, [T]), u(h, P, !0), n(""), l(-1);
6504
6512
  }, j = () => {
6505
6513
  if (navigator.clipboard === void 0) {
6506
6514
  toast.error(c("Clipboard not supported"));
@@ -6529,11 +6537,11 @@ function ManualClasses() {
6529
6537
  /* @__PURE__ */ jsx("div", { className: "relative flex w-full items-center gap-x-3", children: /* @__PURE__ */ jsx(
6530
6538
  Autosuggest,
6531
6539
  {
6532
- suggestions: B,
6540
+ suggestions: _,
6533
6541
  onSuggestionsFetchRequested: w,
6534
6542
  onSuggestionsClearRequested: k,
6535
6543
  getSuggestionValue: v,
6536
- renderSuggestion: E,
6544
+ renderSuggestion: B,
6537
6545
  inputProps: S,
6538
6546
  containerProps: {
6539
6547
  className: "relative h-8 w-full gap-y-1 py-1 border-border text-xs"
@@ -6550,7 +6558,7 @@ function ManualClasses() {
6550
6558
  {
6551
6559
  variant: "outline",
6552
6560
  className: "h-6 border-border",
6553
- onClick: _,
6561
+ onClick: E,
6554
6562
  disabled: f.trim() === "",
6555
6563
  size: "sm",
6556
6564
  children: /* @__PURE__ */ jsx(PlusIcon, {})
@@ -6558,7 +6566,7 @@ function ManualClasses() {
6558
6566
  )
6559
6567
  ] }),
6560
6568
  /* @__PURE__ */ jsx("div", { className: "flex w-full flex-wrap gap-2 overflow-x-hidden", children: A.map(
6561
- (T, R) => a === R ? /* @__PURE__ */ jsx(
6569
+ (T, P) => a === P ? /* @__PURE__ */ jsx(
6562
6570
  "input",
6563
6571
  {
6564
6572
  ref: o,
@@ -7013,7 +7021,7 @@ const CoreBlock = ({
7013
7021
  }
7014
7022
  }
7015
7023
  }, traverseNodes = (o, r = null) => flatMapDeep(o, (n) => {
7016
- var h, m, f, x, y, b, A, _, B, N;
7024
+ var h, m, f, x, y, b, A, E, _, N;
7017
7025
  if (n.type === "comment") return [];
7018
7026
  let a = { _id: generateUUID() };
7019
7027
  if (r && (a._parent = r.block._id), n.type === "text")
@@ -7069,14 +7077,14 @@ const CoreBlock = ({
7069
7077
  a.content = getTextContent(w);
7070
7078
  const k = find(
7071
7079
  n.children || [],
7072
- (v) => (v == null ? void 0 : v.tagName) === "span" && some(v.children || [], (E) => (E == null ? void 0 : E.tagName) === "svg")
7080
+ (v) => (v == null ? void 0 : v.tagName) === "span" && some(v.children || [], (B) => (B == null ? void 0 : B.tagName) === "svg")
7073
7081
  );
7074
7082
  if (k) {
7075
- const v = find(k.children || [], (E) => (E == null ? void 0 : E.tagName) === "svg");
7083
+ const v = find(k.children || [], (B) => (B == null ? void 0 : B.tagName) === "svg");
7076
7084
  if (v) {
7077
7085
  a.icon = stringify([v]);
7078
- const { height: E, width: S } = getSvgDimensions(v, "16px", "16px");
7079
- a.iconHeight = E, a.iconWidth = S;
7086
+ const { height: B, width: S } = getSvgDimensions(v, "16px", "16px");
7087
+ a.iconHeight = B, a.iconWidth = S;
7080
7088
  }
7081
7089
  }
7082
7090
  return [a];
@@ -7092,10 +7100,10 @@ const CoreBlock = ({
7092
7100
  if (k && v)
7093
7101
  a.styles = `${STYLES_KEY}, ${cn$2(`w-${v} h-${k}`, w)}`.trim(), a.height = k == null ? void 0 : k.replace("px", ""), a.width = v == null ? void 0 : v.replace("px", "");
7094
7102
  else {
7095
- const E = (_ = find(n.attributes, { key: "height" })) == null ? void 0 : _.value, S = (B = find(n.attributes, { key: "width" })) == null ? void 0 : B.value;
7096
- E && S ? (a.styles = `${STYLES_KEY}, ${cn$2(`w-[${S}px] h-[${E}px]`, w)}`.trim(), a.height = E, a.width = S) : a.styles = `${STYLES_KEY}, ${cn$2("w-full h-full", w)}`.trim();
7103
+ const B = (E = find(n.attributes, { key: "height" })) == null ? void 0 : E.value, S = (_ = find(n.attributes, { key: "width" })) == null ? void 0 : _.value;
7104
+ B && S ? (a.styles = `${STYLES_KEY}, ${cn$2(`w-[${S}px] h-[${B}px]`, w)}`.trim(), a.height = B, a.width = S) : a.styles = `${STYLES_KEY}, ${cn$2("w-full h-full", w)}`.trim();
7097
7105
  }
7098
- return n.attributes = filter(n.attributes, (E) => !includes(["style", "width", "height", "class"], E.key)), a.icon = stringify([n]), [a];
7106
+ return n.attributes = filter(n.attributes, (B) => !includes(["style", "width", "height", "class"], B.key)), a.icon = stringify([n]), [a];
7099
7107
  } else if (n.tagName == "option" && r && ((N = r.block) == null ? void 0 : N._type) === "Select")
7100
7108
  return r.block.options.push({
7101
7109
  label: getTextContent(n.children),
@@ -7212,18 +7220,18 @@ const registerChaiLibrary = (o, r) => {
7212
7220
  parentId: n = void 0,
7213
7221
  position: a = -1
7214
7222
  }) => {
7215
- const [l, i] = useState(!1), c = useMemo(() => (r == null ? void 0 : r.getBlock) || (() => []), [r]), { addCoreBlock: d, addPredefinedBlock: p } = useAddBlock(), [, u] = useSelectedBlockIds(), { clearHighlight: g } = useBlockHighlight(), h = get(o, "name", get(o, "label")), m = get(o, "description", ""), f = useFeature("dnd"), [, x] = useAtom$1(draggedBlockAtom), y = (_) => {
7216
- const B = has(_, "styles_attrs.data-page-section");
7217
- return _._type === "Box" && B;
7223
+ const [l, i] = useState(!1), c = useMemo(() => (r == null ? void 0 : r.getBlock) || (() => []), [r]), { addCoreBlock: d, addPredefinedBlock: p } = useAddBlock(), [, u] = useSelectedBlockIds(), { clearHighlight: g } = useBlockHighlight(), h = get(o, "name", get(o, "label")), m = get(o, "description", ""), f = useFeature("dnd"), [, x] = useAtom$1(draggedBlockAtom), y = (E) => {
7224
+ const _ = has(E, "styles_attrs.data-page-section");
7225
+ return E._type === "Box" && _;
7218
7226
  }, b = useCallback(
7219
- async (_) => {
7220
- if (_.stopPropagation(), has(o, "component")) {
7227
+ async (E) => {
7228
+ if (E.stopPropagation(), has(o, "component")) {
7221
7229
  d(o, n, a), pubsub.publish(CHAI_BUILDER_EVENTS.CLOSE_ADD_BLOCK);
7222
7230
  return;
7223
7231
  }
7224
7232
  i(!0);
7225
- let B = await c({ library: r, block: o });
7226
- typeof B == "string" && (B = getBlocksFromHTML(B)), isEmpty(B) || p(syncBlocksWithDefaults(B), n, a), pubsub.publish(CHAI_BUILDER_EVENTS.CLOSE_ADD_BLOCK);
7233
+ let _ = await c({ library: r, block: o });
7234
+ typeof _ == "string" && (_ = getBlocksFromHTML(_)), isEmpty(_) || p(syncBlocksWithDefaults(_), n, a), pubsub.publish(CHAI_BUILDER_EVENTS.CLOSE_ADD_BLOCK);
7227
7235
  },
7228
7236
  [d, p, o, c, r, n, a]
7229
7237
  );
@@ -7234,18 +7242,18 @@ const registerChaiLibrary = (o, r) => {
7234
7242
  onClick: l ? () => {
7235
7243
  } : b,
7236
7244
  draggable: f ? "true" : "false",
7237
- onDragStart: async (_) => {
7238
- const B = await c({ library: r, block: o });
7245
+ onDragStart: async (E) => {
7246
+ const _ = await c({ library: r, block: o });
7239
7247
  let N = n;
7240
- if (y(first(B)) && (N = null), !isEmpty(B)) {
7241
- const w = { blocks: B, uiLibrary: !0, parent: N };
7242
- if (_.dataTransfer.setData("text/plain", JSON.stringify(w)), o.preview) {
7248
+ if (y(first(_)) && (N = null), !isEmpty(_)) {
7249
+ const w = { blocks: _, uiLibrary: !0, parent: N };
7250
+ if (E.dataTransfer.setData("text/plain", JSON.stringify(w)), o.preview) {
7243
7251
  const k = new Image();
7244
7252
  k.src = o.preview, k.onload = () => {
7245
- _.dataTransfer.setDragImage(k, 0, 0);
7253
+ E.dataTransfer.setDragImage(k, 0, 0);
7246
7254
  };
7247
7255
  } else
7248
- _.dataTransfer.setDragImage(new Image(), 0, 0);
7256
+ E.dataTransfer.setDragImage(new Image(), 0, 0);
7249
7257
  x(w), setTimeout(() => {
7250
7258
  u([]), g(), pubsub.publish(CHAI_BUILDER_EVENTS.CLOSE_ADD_BLOCK);
7251
7259
  }, 200);
@@ -7298,9 +7306,9 @@ const registerChaiLibrary = (o, r) => {
7298
7306
  return;
7299
7307
  }
7300
7308
  }, [y, b]);
7301
- const _ = get(y, b, []), B = useRef(null), { t: N } = useTranslation(), w = (C) => {
7302
- B.current && (clearTimeout(B.current), B.current = null), B.current = setTimeout(() => {
7303
- B.current && A(C);
7309
+ const E = get(y, b, []), _ = useRef(null), { t: N } = useTranslation(), w = (C) => {
7310
+ _.current && (clearTimeout(_.current), _.current = null), _.current = setTimeout(() => {
7311
+ _.current && A(C);
7304
7312
  }, 400);
7305
7313
  }, k = () => {
7306
7314
  i != null && i.id && p(i.id);
@@ -7312,7 +7320,7 @@ const registerChaiLibrary = (o, r) => {
7312
7320
  /* @__PURE__ */ jsx(Skeleton, { className: "col-span-3 h-full" }),
7313
7321
  /* @__PURE__ */ jsx(Skeleton, { className: "col-span-9 h-full" })
7314
7322
  ] });
7315
- const E = filter(_, (C, j) => j % 2 === 0), S = filter(_, (C, j) => j % 2 === 1);
7323
+ const B = filter(E, (C, j) => j % 2 === 0), S = filter(E, (C, j) => j % 2 === 1);
7316
7324
  return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs("div", { className: "flex h-full max-h-full flex-col", children: [
7317
7325
  /* @__PURE__ */ jsx("div", { className: "flex items-center gap-2 border-border py-2", children: /* @__PURE__ */ jsxs("div", { className: "relative w-full", children: [
7318
7326
  /* @__PURE__ */ jsx(Search, { className: "absolute left-2 top-2.5 h-4 w-4 text-muted-foreground" }),
@@ -7350,7 +7358,7 @@ const registerChaiLibrary = (o, r) => {
7350
7358
  "div",
7351
7359
  {
7352
7360
  onMouseEnter: () => w(j),
7353
- onMouseLeave: () => clearTimeout(B.current),
7361
+ onMouseLeave: () => clearTimeout(_.current),
7354
7362
  role: "button",
7355
7363
  onClick: () => A(j),
7356
7364
  className: cn$2(
@@ -7369,11 +7377,11 @@ const registerChaiLibrary = (o, r) => {
7369
7377
  /* @__PURE__ */ jsx("div", { className: "flex h-full max-h-full w-full flex-col border-l border-border", children: /* @__PURE__ */ jsxs(
7370
7378
  ScrollArea,
7371
7379
  {
7372
- onMouseEnter: () => B.current ? clearTimeout(B.current) : null,
7380
+ onMouseEnter: () => _.current ? clearTimeout(_.current) : null,
7373
7381
  className: "z-10 flex h-full max-h-full w-full flex-col gap-2 transition-all ease-linear",
7374
7382
  children: [
7375
- isEmpty(_) && !isEmpty(y) ? /* @__PURE__ */ jsx("div", { className: "flex h-full flex-col items-center justify-center p-6 text-center", children: /* @__PURE__ */ jsx("p", { className: "text-sm", children: N("No blocks found in this group") }) }) : /* @__PURE__ */ jsxs("div", { className: "grid w-full grid-cols-2 gap-2 px-2", children: [
7376
- /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-1", children: E.map((C, j) => /* @__PURE__ */ jsx(
7383
+ isEmpty(E) && !isEmpty(y) ? /* @__PURE__ */ jsx("div", { className: "flex h-full flex-col items-center justify-center p-6 text-center", children: /* @__PURE__ */ jsx("p", { className: "text-sm", children: N("No blocks found in this group") }) }) : /* @__PURE__ */ jsxs("div", { className: "grid w-full grid-cols-2 gap-2 px-2", children: [
7384
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-1", children: B.map((C, j) => /* @__PURE__ */ jsx(
7377
7385
  BlockCard,
7378
7386
  {
7379
7387
  parentId: o,
@@ -7428,14 +7436,14 @@ const registerChaiLibrary = (o, r) => {
7428
7436
  }), g(!0);
7429
7437
  else if (!l && Object.keys(a || {}).length > 0) {
7430
7438
  const m = Object.entries(a).map(([x, y]) => {
7431
- const b = y, A = b.type || "partial", _ = formatReadableName(A);
7439
+ const b = y, A = b.type || "partial", E = formatReadableName(A);
7432
7440
  return {
7433
7441
  type: "PartialBlock",
7434
7442
  // Set the type to PartialBlock
7435
7443
  label: formatReadableName(b.name || x),
7436
7444
  description: b.description || "",
7437
7445
  icon: Globe,
7438
- group: _,
7446
+ group: E,
7439
7447
  // Use formatted type as group
7440
7448
  category: "partial",
7441
7449
  partialBlockId: x,
@@ -7507,9 +7515,9 @@ const registerChaiLibrary = (o, r) => {
7507
7515
  }), []);
7508
7516
  const A = useCallback((C) => {
7509
7517
  y(C), b.current && b.current(C);
7510
- }, []), _ = useCallback(() => {
7518
+ }, []), E = useCallback(() => {
7511
7519
  y(null), b.current && b.current.cancel();
7512
- }, []), B = useCallback((C) => {
7520
+ }, []), _ = useCallback((C) => {
7513
7521
  b.current && b.current.cancel(), f(C), y(null);
7514
7522
  }, []), N = useMemo(
7515
7523
  () => d ? values(r).filter(
@@ -7527,7 +7535,7 @@ const registerChaiLibrary = (o, r) => {
7527
7535
  ), k = useMemo(
7528
7536
  () => sortBy(w, (C) => CORE_GROUPS.indexOf(C) === -1 ? 99 : CORE_GROUPS.indexOf(C)),
7529
7537
  [w]
7530
- ), v = useMemo(() => m === "all" ? N : filter(values(N), { group: m }), [N, m]), E = useMemo(() => m === "all" ? k : [m], [k, m]);
7538
+ ), v = useMemo(() => m === "all" ? N : filter(values(N), { group: m }), [N, m]), B = useMemo(() => m === "all" ? k : [m], [k, m]);
7531
7539
  return /* @__PURE__ */ jsxs("div", { className: "mx-auto flex h-full w-full max-w-3xl flex-col", children: [
7532
7540
  /* @__PURE__ */ jsx("div", { className: "sticky top-0 z-10 bg-background/80 px-4 py-2 backdrop-blur-sm", children: /* @__PURE__ */ jsx(
7533
7541
  Input$1,
@@ -7545,9 +7553,9 @@ const registerChaiLibrary = (o, r) => {
7545
7553
  /* @__PURE__ */ jsx(
7546
7554
  "button",
7547
7555
  {
7548
- onClick: () => B("all"),
7556
+ onClick: () => _("all"),
7549
7557
  onMouseEnter: () => A("all"),
7550
- onMouseLeave: _,
7558
+ onMouseLeave: E,
7551
7559
  className: `w-full rounded-md px-2 py-1.5 text-left text-sm font-medium ${m === "all" || x === "all" ? "bg-primary text-primary-foreground" : "hover:bg-primary/50 hover:text-primary-foreground"}`,
7552
7560
  children: i("All")
7553
7561
  },
@@ -7556,9 +7564,9 @@ const registerChaiLibrary = (o, r) => {
7556
7564
  k.map((C) => /* @__PURE__ */ jsx(
7557
7565
  "button",
7558
7566
  {
7559
- onClick: () => B(C),
7567
+ onClick: () => _(C),
7560
7568
  onMouseEnter: () => A(C),
7561
- onMouseLeave: _,
7569
+ onMouseLeave: E,
7562
7570
  className: `w-full rounded-md px-2 py-1.5 text-left text-sm ${m === C || x === C ? "bg-primary text-primary-foreground" : "hover:bg-primary/50 hover:text-primary-foreground"}`,
7563
7571
  children: capitalize(i(C.toLowerCase()))
7564
7572
  },
@@ -7570,7 +7578,7 @@ const registerChaiLibrary = (o, r) => {
7570
7578
  ' "',
7571
7579
  d,
7572
7580
  '"'
7573
- ] }) }) : /* @__PURE__ */ jsx("div", { className: "space-y-6 p-4", children: E.map((C) => /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
7581
+ ] }) }) : /* @__PURE__ */ jsx("div", { className: "space-y-6 p-4", children: B.map((C) => /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
7574
7582
  /* @__PURE__ */ jsx("h3", { className: "px-1 text-sm font-medium", children: capitalize(i(C.toLowerCase())) }),
7575
7583
  /* @__PURE__ */ jsx("div", { className: "grid gap-2 " + l, children: reject(
7576
7584
  m === "all" ? filter(values(v), { group: C }) : values(v),
@@ -7935,22 +7943,22 @@ const Input = ({ node: o }) => {
7935
7943
  var r;
7936
7944
  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) : ((r = o == null ? void 0 : o._type) == null ? void 0 : r.split("/").pop()) || "";
7937
7945
  }, Node = memo(({ node: o, style: r, dragHandle: n }) => {
7938
- var R;
7946
+ var P;
7939
7947
  const { t: a } = useTranslation(), [l, , i] = useHiddenBlockIds(), [c] = useAtom$1(canvasIframeAtom), { hasPermission: d } = usePermissions();
7940
7948
  let p = null;
7941
- const u = o.children.length > 0, { highlightBlock: g, clearHighlight: h } = useBlockHighlight(), { id: m, data: f, isSelected: x, willReceiveDrop: y, isDragging: b, isEditing: A, handleClick: _ } = o, B = (L) => {
7949
+ const u = o.children.length > 0, { highlightBlock: g, clearHighlight: h } = useBlockHighlight(), { id: m, data: f, isSelected: x, willReceiveDrop: y, isDragging: b, isEditing: A, handleClick: E } = o, _ = (L) => {
7942
7950
  L.stopPropagation(), !l.includes(m) && o.toggle();
7943
7951
  }, N = (L) => {
7944
7952
  L.isInternal && (p = L.isOpen, L.isOpen && L.close());
7945
7953
  }, w = (L) => {
7946
7954
  L.isInternal && p !== null && (p ? L.open() : L.close(), p = null);
7947
- }, [k, v] = useAtom$1(currentAddSelection), E = () => {
7955
+ }, [k, v] = useAtom$1(currentAddSelection), B = () => {
7948
7956
  var L;
7949
7957
  S(), o.parent.isSelected || v((L = o == null ? void 0 : o.parent) == null ? void 0 : L.id);
7950
7958
  }, S = () => {
7951
7959
  v(null);
7952
7960
  }, C = (L) => {
7953
- S(), L.stopPropagation(), !o.isOpen && !l.includes(m) && o.toggle(), _(L);
7961
+ S(), L.stopPropagation(), !o.isOpen && !l.includes(m) && o.toggle(), E(L);
7954
7962
  };
7955
7963
  useEffect(() => {
7956
7964
  const L = setTimeout(() => {
@@ -7959,10 +7967,10 @@ const Input = ({ node: o }) => {
7959
7967
  return () => clearTimeout(L);
7960
7968
  }, [y, o, b]);
7961
7969
  const j = (L, D) => {
7962
- const P = c.contentDocument || c.contentWindow.document, M = P.querySelector(`[data-block-id=${L}]`);
7970
+ const R = c.contentDocument || c.contentWindow.document, M = R.querySelector(`[data-block-id=${L}]`);
7963
7971
  M && M.setAttribute("data-drop", D);
7964
7972
  const $ = M.getBoundingClientRect(), O = c.getBoundingClientRect();
7965
- $.top >= O.top && $.left >= O.left && $.bottom <= O.bottom && $.right <= O.right || (P.documentElement.scrollTop = M.offsetTop - O.top);
7973
+ $.top >= O.top && $.left >= O.left && $.bottom <= O.bottom && $.right <= O.right || (R.documentElement.scrollTop = M.offsetTop - O.top);
7966
7974
  }, I = (L) => {
7967
7975
  S();
7968
7976
  const D = get(o, "parent.id");
@@ -8008,13 +8016,13 @@ const Input = ({ node: o }) => {
8008
8016
  L.preventDefault(), j(m, "no");
8009
8017
  },
8010
8018
  children: [
8011
- 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(
8019
+ 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(
8012
8020
  "div",
8013
8021
  {
8014
8022
  onClick: (L) => {
8015
8023
  L.stopPropagation(), I(o.childIndex);
8016
8024
  },
8017
- onMouseEnter: E,
8025
+ onMouseEnter: B,
8018
8026
  onMouseLeave: S,
8019
8027
  className: "absolute -top-0.5 h-1 w-[90%] rounded bg-primary opacity-0 delay-200 duration-200 group-hover:opacity-100",
8020
8028
  children: /* @__PURE__ */ jsx("div", { className: "absolute left-1/2 top-1/2 flex h-4 w-4 -translate-x-1/2 -translate-y-1/2 transform items-center justify-center rounded-full bg-primary p-1 outline outline-2 outline-white hover:bg-primary", children: /* @__PURE__ */ jsx(PlusIcon, { className: "h-3 w-3 stroke-[4] text-white" }) })
@@ -8038,7 +8046,7 @@ const Input = ({ node: o }) => {
8038
8046
  "div",
8039
8047
  {
8040
8048
  className: `flex h-4 w-4 rotate-0 transform cursor-pointer items-center justify-center transition-transform duration-100 ${o.isOpen ? "rotate-90" : ""}`,
8041
- children: u && /* @__PURE__ */ jsx("button", { onClick: B, type: "button", children: /* @__PURE__ */ jsx(ChevronRight, { className: `h-3 w-3 stroke-[3] ${x ? "text-white" : "text-slate-400"}` }) })
8049
+ children: u && /* @__PURE__ */ jsx("button", { onClick: _, type: "button", children: /* @__PURE__ */ jsx(ChevronRight, { className: `h-3 w-3 stroke-[3] ${x ? "text-white" : "text-slate-400"}` }) })
8042
8050
  }
8043
8051
  ),
8044
8052
  /* @__PURE__ */ jsxs(
@@ -8354,9 +8362,36 @@ const Input = ({ node: o }) => {
8354
8362
  /* @__PURE__ */ jsx(SelectContent, { children: a.map((l) => /* @__PURE__ */ jsx(SelectItem, { value: l.family, children: l.family }, l.family)) })
8355
8363
  ] })
8356
8364
  ] });
8365
+ }, defaultShadcnPreset = {
8366
+ fontFamily: {
8367
+ heading: "Inter",
8368
+ body: "Inter"
8369
+ },
8370
+ borderRadius: "6px",
8371
+ colors: {
8372
+ background: ["#ffffff", "#0a0a0a"],
8373
+ foreground: ["#0a0a0a", "#fafafa"],
8374
+ primary: ["#171717", "#e5e5e5"],
8375
+ "primary-foreground": ["#fafafa", "#171717"],
8376
+ secondary: ["#f5f5f5", "#262626"],
8377
+ "secondary-foreground": ["#171717", "#fafafa"],
8378
+ muted: ["#f5f5f5", "#262626"],
8379
+ "muted-foreground": ["#737373", "#a1a1a1"],
8380
+ accent: ["#f5f5f5", "#404040"],
8381
+ "accent-foreground": ["#171717", "#fafafa"],
8382
+ destructive: ["#e7000b", "#ff6467"],
8383
+ "destructive-foreground": ["#ffffff", "#fafafa"],
8384
+ border: ["#e5e5e5", "#282828"],
8385
+ input: ["#e5e5e5", "#343434"],
8386
+ ring: ["#a1a1a1", "#737373"],
8387
+ card: ["#ffffff", "#171717"],
8388
+ "card-foreground": ["#0a0a0a", "#fafafa"],
8389
+ popover: ["#ffffff", "#262626"],
8390
+ "popover-foreground": ["#0a0a0a", "#fafafa"]
8391
+ }
8357
8392
  }, LazyCssImportModal = lazy(
8358
8393
  () => import("./css-import-modal-CcUf6F6T.js").then((o) => ({ default: o.CssImportModal }))
8359
- ), PREV_THEME_KEY = "chai-builder-previous-theme", setPreviousTheme = (o) => {
8394
+ ), PREV_THEME_KEY = "chai-builder-previous-theme", DEFAULT_THEME_PRESET = [{ shadcn_default: defaultShadcnPreset }], setPreviousTheme = (o) => {
8360
8395
  if (!(typeof window > "u"))
8361
8396
  try {
8362
8397
  localStorage.setItem(PREV_THEME_KEY, JSON.stringify(o));
@@ -8371,7 +8406,9 @@ const Input = ({ node: o }) => {
8371
8406
  console.warn("Failed to clear previous theme from localStorage:", o);
8372
8407
  }
8373
8408
  }, ThemeConfigPanel = React.memo(({ className: o = "" }) => {
8374
- const [r, n] = useDarkMode(), [a, l] = React.useState(""), [i, c] = React.useState(!1), d = useBuilderProp("themePresets", []), p = useBuilderProp("themePanelComponent", null), { hasPermission: u } = usePermissions(), [g, h] = useTheme(), m = useThemeOptions(), { t: f } = useTranslation(), x = React.useCallback(
8409
+ const [r, n] = useDarkMode(), [a, l] = React.useState(""), [i, c] = React.useState(!1), d = useBuilderProp("themePresets", []), p = useBuilderProp("themePanelComponent", null), { hasPermission: u } = usePermissions();
8410
+ d && !d.some((w) => Object.keys(w)[0] === "shadcn_default") && d.push(...DEFAULT_THEME_PRESET);
8411
+ const [g, h] = useTheme(), m = useThemeOptions(), { t: f } = useTranslation(), x = React.useCallback(
8375
8412
  (w) => {
8376
8413
  const k = { ...g };
8377
8414
  setPreviousTheme(k), h(w), toast.success("Theme updated", {
@@ -8410,7 +8447,7 @@ const Input = ({ node: o }) => {
8410
8447
  },
8411
8448
  [g],
8412
8449
  200
8413
- ), _ = React.useCallback(
8450
+ ), E = React.useCallback(
8414
8451
  (w) => {
8415
8452
  h(() => ({
8416
8453
  ...g,
@@ -8418,7 +8455,7 @@ const Input = ({ node: o }) => {
8418
8455
  }));
8419
8456
  },
8420
8457
  [g]
8421
- ), B = useDebouncedCallback(
8458
+ ), _ = useDebouncedCallback(
8422
8459
  (w, k) => {
8423
8460
  h(() => {
8424
8461
  const v = get(g, `colors.${w}`);
@@ -8440,10 +8477,10 @@ const Input = ({ node: o }) => {
8440
8477
  ColorPickerInput,
8441
8478
  {
8442
8479
  value: v,
8443
- onChange: (E) => B(k, E)
8480
+ onChange: (B) => _(k, B)
8444
8481
  }
8445
8482
  ),
8446
- /* @__PURE__ */ jsx(Label, { className: "text-xs font-normal leading-tight", children: k.split(/(?=[A-Z])/).join(" ").replace(/-/g, " ").split(" ").map((E) => E.charAt(0).toUpperCase() + E.slice(1)).join(" ") + (!k.toLowerCase().includes("foreground") && !k.toLowerCase().includes("border") && !k.toLowerCase().includes("input") && !k.toLowerCase().includes("ring") && !k.toLowerCase().includes("background") ? " Background" : "") })
8483
+ /* @__PURE__ */ jsx(Label, { className: "text-xs font-normal leading-tight", children: k.split(/(?=[A-Z])/).join(" ").replace(/-/g, " ").split(" ").map((B) => B.charAt(0).toUpperCase() + B.slice(1)).join(" ") + (!k.toLowerCase().includes("foreground") && !k.toLowerCase().includes("border") && !k.toLowerCase().includes("input") && !k.toLowerCase().includes("ring") && !k.toLowerCase().includes("background") ? " Background" : "") })
8447
8484
  ] }, k) : null;
8448
8485
  }) });
8449
8486
  return u("edit_theme") ? /* @__PURE__ */ jsxs("div", { className: "relative w-full", children: [
@@ -8491,7 +8528,7 @@ const Input = ({ node: o }) => {
8491
8528
  ] }),
8492
8529
  /* @__PURE__ */ jsx(Badge, { variant: "secondary", className: "text-xs", children: g.borderRadius })
8493
8530
  ] }),
8494
- /* @__PURE__ */ jsx("div", { className: "flex items-center gap-4 py-2", children: /* @__PURE__ */ jsx(BorderRadiusInput, { value: g.borderRadius, onChange: _ }) })
8531
+ /* @__PURE__ */ jsx("div", { className: "flex items-center gap-4 py-2", children: /* @__PURE__ */ jsx(BorderRadiusInput, { value: g.borderRadius, onChange: E }) })
8495
8532
  ] }),
8496
8533
  /* @__PURE__ */ jsx(Separator, {}),
8497
8534
  (m == null ? void 0 : m.colors) && /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
@@ -9250,19 +9287,19 @@ function AIChatPanel() {
9250
9287
  content: "This is a sample response from the AI assistant. In a real implementation, this would be replaced with an actual response from the AI model.",
9251
9288
  timestamp: /* @__PURE__ */ new Date()
9252
9289
  };
9253
- r((_) => [..._, A]), i(!1), d(null);
9290
+ r((E) => [...E, A]), i(!1), d(null);
9254
9291
  }, 1500);
9255
9292
  }, m = (b) => {
9256
9293
  b.key === "Enter" && !b.shiftKey && (b.preventDefault(), h());
9257
9294
  }, f = (b) => {
9258
- var _;
9259
- const A = (_ = b.target.files) == null ? void 0 : _[0];
9295
+ var E;
9296
+ const A = (E = b.target.files) == null ? void 0 : E[0];
9260
9297
  if (A) {
9261
- const B = new FileReader();
9262
- B.onload = (N) => {
9298
+ const _ = new FileReader();
9299
+ _.onload = (N) => {
9263
9300
  var w;
9264
9301
  d((w = N.target) == null ? void 0 : w.result);
9265
- }, B.readAsDataURL(A);
9302
+ }, _.readAsDataURL(A);
9266
9303
  }
9267
9304
  }, x = () => {
9268
9305
  var b;
@@ -9470,11 +9507,11 @@ const AiAssistant = () => {
9470
9507
  n(k), l(a), c(""), p(""), m("");
9471
9508
  }
9472
9509
  }, A = (k) => {
9473
- const v = a.filter((E, S) => S !== k);
9510
+ const v = a.filter((B, S) => S !== k);
9474
9511
  n(v), l(v);
9475
- }, _ = (k) => {
9512
+ }, E = (k) => {
9476
9513
  g(k), c(a[k].key), p(a[k].value);
9477
- }, B = () => {
9514
+ }, _ = () => {
9478
9515
  if (i.startsWith("@")) {
9479
9516
  m("Attribute keys cannot start with '@'");
9480
9517
  return;
@@ -9484,25 +9521,25 @@ const AiAssistant = () => {
9484
9521
  k[u] = { key: i, value: d }, n(k), l(k), g(null), c(""), p(""), m("");
9485
9522
  }
9486
9523
  }, N = (k) => {
9487
- k.key === "Enter" && !k.shiftKey && (k.preventDefault(), u !== null ? B() : b());
9524
+ k.key === "Enter" && !k.shiftKey && (k.preventDefault(), u !== null ? _() : b());
9488
9525
  }, w = useCallback((k) => {
9489
- const v = (C) => /[.,!?;:]/.test(C), E = (C, j, I) => {
9490
- let T = "", R = "";
9526
+ const v = (C) => /[.,!?;:]/.test(C), B = (C, j, I) => {
9527
+ let T = "", P = "";
9491
9528
  const L = j > 0 ? C[j - 1] : "", D = j < C.length ? C[j] : "";
9492
- return j > 0 && (L === "." || !v(L) && L !== " ") && (T = " "), j < C.length && !v(D) && D !== " " && (R = " "), {
9493
- text: T + I + R,
9529
+ return j > 0 && (L === "." || !v(L) && L !== " ") && (T = " "), j < C.length && !v(D) && D !== " " && (P = " "), {
9530
+ text: T + I + P,
9494
9531
  prefixLength: T.length,
9495
- suffixLength: R.length
9532
+ suffixLength: P.length
9496
9533
  };
9497
9534
  }, S = x.current;
9498
9535
  if (S) {
9499
9536
  const C = S.selectionStart || 0, j = S.value || "", I = S.selectionEnd || C;
9500
9537
  if (I > C) {
9501
- const P = `{{${k}}}`, { text: M } = E(j, C, P), $ = j.slice(0, C) + M + j.slice(I);
9538
+ const R = `{{${k}}}`, { text: M } = B(j, C, R), $ = j.slice(0, C) + M + j.slice(I);
9502
9539
  p($);
9503
9540
  return;
9504
9541
  }
9505
- const R = `{{${k}}}`, { text: L } = E(j, C, R), D = j.slice(0, C) + L + j.slice(C);
9542
+ const P = `{{${k}}}`, { text: L } = B(j, C, P), D = j.slice(0, C) + L + j.slice(C);
9506
9543
  p(D);
9507
9544
  }
9508
9545
  }, []);
@@ -9511,7 +9548,7 @@ const AiAssistant = () => {
9511
9548
  "form",
9512
9549
  {
9513
9550
  onSubmit: (k) => {
9514
- k.preventDefault(), u !== null ? B() : b();
9551
+ k.preventDefault(), u !== null ? _() : b();
9515
9552
  },
9516
9553
  className: "space-y-3",
9517
9554
  children: [
@@ -9567,7 +9604,7 @@ const AiAssistant = () => {
9567
9604
  /* @__PURE__ */ jsx("span", { className: "max-w-[200px] text-wrap font-normal", children: k.value.toString() })
9568
9605
  ] }),
9569
9606
  /* @__PURE__ */ jsxs("div", { className: "flex-shrink-0 text-slate-400", children: [
9570
- /* @__PURE__ */ jsx(Button, { variant: "ghost", size: "icon", className: "h-6 w-6", onClick: () => _(v), children: /* @__PURE__ */ jsx(Edit2, { className: "h-3 w-3" }) }),
9607
+ /* @__PURE__ */ jsx(Button, { variant: "ghost", size: "icon", className: "h-6 w-6", onClick: () => E(v), children: /* @__PURE__ */ jsx(Edit2, { className: "h-3 w-3" }) }),
9571
9608
  /* @__PURE__ */ jsx(Button, { variant: "ghost", size: "icon", className: "h-6 w-6", onClick: () => A(v), children: /* @__PURE__ */ jsx(X, { className: "h-3 w-3" }) })
9572
9609
  ] })
9573
9610
  ] }, v)) })
@@ -9749,11 +9786,11 @@ const RootLayout = () => {
9749
9786
  k && get(k, "view", "standard") === "standard" && (a.current = r, i(get(k, "width", DEFAULT_PANEL_WIDTH)));
9750
9787
  }
9751
9788
  }, [r, x]);
9752
- const _ = useMemo(() => {
9789
+ const E = useMemo(() => {
9753
9790
  if (r === null) return 0;
9754
9791
  const k = find(x, { id: r });
9755
9792
  return get(k, "view", "standard") === "standard" ? A : l;
9756
- }, [r, A, l, x]), B = useCallback(() => {
9793
+ }, [r, A, l, x]), _ = useCallback(() => {
9757
9794
  n(a.current);
9758
9795
  }, [n]), N = useCallback(() => {
9759
9796
  n("outline");
@@ -9802,8 +9839,8 @@ const RootLayout = () => {
9802
9839
  {
9803
9840
  id: "left-panel",
9804
9841
  className: "h-full max-h-full border-r border-border",
9805
- initial: { width: _ },
9806
- animate: { width: _ },
9842
+ initial: { width: E },
9843
+ animate: { width: E },
9807
9844
  transition: { duration: 0.3, ease: "easeInOut" },
9808
9845
  children: r !== null && get(b, "view", "standard") === "standard" && /* @__PURE__ */ jsxs("div", { className: "no-scrollbar flex h-full flex-col overflow-hidden px-3 py-2", children: [
9809
9846
  /* @__PURE__ */ jsx(
@@ -9859,7 +9896,7 @@ const RootLayout = () => {
9859
9896
  }
9860
9897
  ),
9861
9898
  /* @__PURE__ */ jsx(AddBlocksDialog, {}),
9862
- r !== null && get(b, "view") === "drawer" && /* @__PURE__ */ jsx(Sheet, { open: !0, onOpenChange: () => B(), children: /* @__PURE__ */ jsxs(
9899
+ r !== null && get(b, "view") === "drawer" && /* @__PURE__ */ jsx(Sheet, { open: !0, onOpenChange: () => _(), children: /* @__PURE__ */ jsxs(
9863
9900
  SheetContent,
9864
9901
  {
9865
9902
  side: "left",
@@ -9877,7 +9914,7 @@ const RootLayout = () => {
9877
9914
  }
9878
9915
  ) }),
9879
9916
  " ",
9880
- r !== null && get(b, "view") === "modal" && /* @__PURE__ */ jsx(Dialog, { open: !0, onOpenChange: () => B(), children: /* @__PURE__ */ jsxs(DialogContent, { className: "gap-0 p-0", style: { maxWidth: `${A}px` }, children: [
9917
+ r !== null && get(b, "view") === "modal" && /* @__PURE__ */ jsx(Dialog, { open: !0, onOpenChange: () => _(), children: /* @__PURE__ */ jsxs(DialogContent, { className: "gap-0 p-0", style: { maxWidth: `${A}px` }, children: [
9881
9918
  /* @__PURE__ */ jsx(DialogHeader, { className: "border-b border-border px-2 py-3.5", children: /* @__PURE__ */ jsxs(DialogTitle, { className: "flex items-center gap-2", children: [
9882
9919
  /* @__PURE__ */ jsx("span", { className: "inline-block", children: get(b, "icon", null) }),
9883
9920
  /* @__PURE__ */ jsx("span", { children: f(get(b, "label", "")) })
@@ -9908,7 +9945,7 @@ const RootLayout = () => {
9908
9945
  /* @__PURE__ */ jsx("span", { className: "rtl:ml-2 rtl:inline-block", children: get(b, "icon", null) }),
9909
9946
  /* @__PURE__ */ jsx("span", { children: f(get(b, "label", "")) })
9910
9947
  ] }),
9911
- /* @__PURE__ */ jsx(Button, { onClick: () => B(), variant: "ghost", size: "icon", className: "", children: /* @__PURE__ */ jsx(X, { className: "h-5 w-5" }) })
9948
+ /* @__PURE__ */ jsx(Button, { onClick: () => _(), variant: "ghost", size: "icon", className: "", children: /* @__PURE__ */ jsx(X, { className: "h-5 w-5" }) })
9912
9949
  ] }),
9913
9950
  /* @__PURE__ */ jsx("div", { className: "flex-1 overflow-y-auto p-4", children: /* @__PURE__ */ jsx(Suspense, { fallback: /* @__PURE__ */ jsx("div", { children: "Loading..." }), children: React__default.createElement(get(b, "panel", NoopComponent), {
9914
9951
  close: N
@@ -9964,7 +10001,7 @@ const RootLayout = () => {
9964
10001
  });
9965
10002
  }, m = (x) => {
9966
10003
  if (!c) return;
9967
- const y = x.clientX - p.x, b = x.clientY - p.y, A = x.currentTarget, _ = A.offsetWidth, B = A.offsetHeight, N = window.innerWidth - _, w = window.innerHeight - B, k = Math.max(0, Math.min(y, N)), v = Math.max(0, Math.min(b, w));
10004
+ const y = x.clientX - p.x, b = x.clientY - p.y, A = x.currentTarget, E = A.offsetWidth, _ = A.offsetHeight, N = window.innerWidth - E, w = window.innerHeight - _, k = Math.max(0, Math.min(y, N)), v = Math.max(0, Math.min(b, w));
9968
10005
  n(k, v);
9969
10006
  }, f = () => {
9970
10007
  d(!1);
@@ -10143,10 +10180,10 @@ const RootLayout = () => {
10143
10180
  return (x = m.onMount) == null ? void 0 : x.call(m, f);
10144
10181
  }, ...h) => {
10145
10182
  const m = h[0] || ((v) => {
10146
- let E = o.get(v);
10147
- return E || (E = { d: /* @__PURE__ */ new Map(), p: /* @__PURE__ */ new Set(), n: 0 }, o.set(v, E), u == null || u(v, k)), E;
10183
+ let B = o.get(v);
10184
+ return B || (B = { d: /* @__PURE__ */ new Map(), p: /* @__PURE__ */ new Set(), n: 0 }, o.set(v, B), u == null || u(v, k)), B;
10148
10185
  }), f = h[1] || (() => {
10149
- const v = [], E = (S) => {
10186
+ const v = [], B = (S) => {
10150
10187
  try {
10151
10188
  S();
10152
10189
  } catch (C) {
@@ -10154,121 +10191,121 @@ const RootLayout = () => {
10154
10191
  }
10155
10192
  };
10156
10193
  do {
10157
- c.f && E(c.f);
10194
+ c.f && B(c.f);
10158
10195
  const S = /* @__PURE__ */ new Set(), C = S.add.bind(S);
10159
10196
  a.forEach((j) => {
10160
10197
  var I;
10161
10198
  return (I = r.get(j)) == null ? void 0 : I.l.forEach(C);
10162
- }), a.clear(), i.forEach(C), i.clear(), l.forEach(C), l.clear(), S.forEach(E), a.size && x();
10199
+ }), a.clear(), i.forEach(C), i.clear(), l.forEach(C), l.clear(), S.forEach(B), a.size && x();
10163
10200
  } while (a.size || i.size || l.size);
10164
10201
  if (v.length)
10165
10202
  throw new AggregateError(v);
10166
10203
  }), x = h[2] || (() => {
10167
- const v = [], E = /* @__PURE__ */ new WeakSet(), S = /* @__PURE__ */ new WeakSet(), C = Array.from(a);
10204
+ const v = [], B = /* @__PURE__ */ new WeakSet(), S = /* @__PURE__ */ new WeakSet(), C = Array.from(a);
10168
10205
  for (; C.length; ) {
10169
10206
  const j = C[C.length - 1], I = m(j);
10170
10207
  if (S.has(j)) {
10171
10208
  C.pop();
10172
10209
  continue;
10173
10210
  }
10174
- if (E.has(j)) {
10211
+ if (B.has(j)) {
10175
10212
  n.get(j) === I.n && v.push([j, I]), S.add(j), C.pop();
10176
10213
  continue;
10177
10214
  }
10178
- E.add(j);
10215
+ B.add(j);
10179
10216
  for (const T of getMountedOrPendingDependents(j, I, r))
10180
- E.has(T) || C.push(T);
10217
+ B.has(T) || C.push(T);
10181
10218
  }
10182
10219
  for (let j = v.length - 1; j >= 0; --j) {
10183
10220
  const [I, T] = v[j];
10184
- let R = !1;
10221
+ let P = !1;
10185
10222
  for (const L of T.d.keys())
10186
10223
  if (L !== I && a.has(L)) {
10187
- R = !0;
10224
+ P = !0;
10188
10225
  break;
10189
10226
  }
10190
- R && (y(I), _(I)), n.delete(I);
10227
+ P && (y(I), E(I)), n.delete(I);
10191
10228
  }
10192
10229
  }), y = h[3] || ((v) => {
10193
- var E;
10230
+ var B;
10194
10231
  const S = m(v);
10195
10232
  if (isAtomStateInitialized(S) && (r.has(v) && n.get(v) !== S.n || Array.from(S.d).every(
10196
- ([P, M]) => (
10233
+ ([R, M]) => (
10197
10234
  // Recursively, read the atom state of the dependency, and
10198
10235
  // check if the atom epoch number is unchanged
10199
- y(P).n === M
10236
+ y(R).n === M
10200
10237
  )
10201
10238
  )))
10202
10239
  return S;
10203
10240
  S.d.clear();
10204
10241
  let C = !0;
10205
10242
  const j = () => {
10206
- r.has(v) && (_(v), x(), f());
10207
- }, I = (P) => {
10243
+ r.has(v) && (E(v), x(), f());
10244
+ }, I = (R) => {
10208
10245
  var M;
10209
- if (isSelfAtom(v, P)) {
10210
- const O = m(P);
10246
+ if (isSelfAtom(v, R)) {
10247
+ const O = m(R);
10211
10248
  if (!isAtomStateInitialized(O))
10212
- if (hasInitialValue(P))
10213
- setAtomStateValueOrPromise(P, P.init, m);
10249
+ if (hasInitialValue(R))
10250
+ setAtomStateValueOrPromise(R, R.init, m);
10214
10251
  else
10215
10252
  throw new Error("no atom init");
10216
10253
  return returnAtomValue(O);
10217
10254
  }
10218
- const $ = y(P);
10255
+ const $ = y(R);
10219
10256
  try {
10220
10257
  return returnAtomValue($);
10221
10258
  } finally {
10222
- S.d.set(P, $.n), isPendingPromise(S.v) && addPendingPromiseToDependency(v, S.v, $), (M = r.get(P)) == null || M.t.add(v), C || j();
10259
+ S.d.set(R, $.n), isPendingPromise(S.v) && addPendingPromiseToDependency(v, S.v, $), (M = r.get(R)) == null || M.t.add(v), C || j();
10223
10260
  }
10224
10261
  };
10225
- let T, R;
10262
+ let T, P;
10226
10263
  const L = {
10227
10264
  get signal() {
10228
10265
  return T || (T = new AbortController()), T.signal;
10229
10266
  },
10230
10267
  get setSelf() {
10231
- return !R && isActuallyWritableAtom(v) && (R = (...P) => {
10268
+ return !P && isActuallyWritableAtom(v) && (P = (...R) => {
10232
10269
  if (!C)
10233
10270
  try {
10234
- return A(v, ...P);
10271
+ return A(v, ...R);
10235
10272
  } finally {
10236
10273
  x(), f();
10237
10274
  }
10238
- }), R;
10275
+ }), P;
10239
10276
  }
10240
10277
  }, D = S.n;
10241
10278
  try {
10242
- const P = d(v, I, L);
10243
- return setAtomStateValueOrPromise(v, P, m), isPromiseLike$1(P) && (registerAbortHandler(P, () => T == null ? void 0 : T.abort()), P.then(
10279
+ const R = d(v, I, L);
10280
+ return setAtomStateValueOrPromise(v, R, m), isPromiseLike$1(R) && (registerAbortHandler(R, () => T == null ? void 0 : T.abort()), R.then(
10244
10281
  j,
10245
10282
  j
10246
10283
  )), S;
10247
- } catch (P) {
10248
- return delete S.v, S.e = P, ++S.n, S;
10284
+ } catch (R) {
10285
+ return delete S.v, S.e = R, ++S.n, S;
10249
10286
  } finally {
10250
- C = !1, D !== S.n && n.get(v) === D && (n.set(v, S.n), a.add(v), (E = c.c) == null || E.call(c, v));
10287
+ C = !1, D !== S.n && n.get(v) === D && (n.set(v, S.n), a.add(v), (B = c.c) == null || B.call(c, v));
10251
10288
  }
10252
10289
  }), b = h[4] || ((v) => {
10253
- const E = [v];
10254
- for (; E.length; ) {
10255
- const S = E.pop(), C = m(S);
10290
+ const B = [v];
10291
+ for (; B.length; ) {
10292
+ const S = B.pop(), C = m(S);
10256
10293
  for (const j of getMountedOrPendingDependents(S, C, r)) {
10257
10294
  const I = m(j);
10258
- n.set(j, I.n), E.push(j);
10295
+ n.set(j, I.n), B.push(j);
10259
10296
  }
10260
10297
  }
10261
- }), A = h[5] || ((v, ...E) => {
10298
+ }), A = h[5] || ((v, ...B) => {
10262
10299
  let S = !0;
10263
10300
  const C = (I) => returnAtomValue(y(I)), j = (I, ...T) => {
10264
- var R;
10301
+ var P;
10265
10302
  const L = m(I);
10266
10303
  try {
10267
10304
  if (isSelfAtom(v, I)) {
10268
10305
  if (!hasInitialValue(I))
10269
10306
  throw new Error("atom not writable");
10270
- const D = L.n, P = T[0];
10271
- setAtomStateValueOrPromise(I, P, m), _(I), D !== L.n && (a.add(I), (R = c.c) == null || R.call(c, I), b(I));
10307
+ const D = L.n, R = T[0];
10308
+ setAtomStateValueOrPromise(I, R, m), E(I), D !== L.n && (a.add(I), (P = c.c) == null || P.call(c, I), b(I));
10272
10309
  return;
10273
10310
  } else
10274
10311
  return A(I, ...T);
@@ -10277,18 +10314,18 @@ const RootLayout = () => {
10277
10314
  }
10278
10315
  };
10279
10316
  try {
10280
- return p(v, C, j, ...E);
10317
+ return p(v, C, j, ...B);
10281
10318
  } finally {
10282
10319
  S = !1;
10283
10320
  }
10284
- }), _ = h[6] || ((v) => {
10285
- var E;
10321
+ }), E = h[6] || ((v) => {
10322
+ var B;
10286
10323
  const S = m(v), C = r.get(v);
10287
10324
  if (C && !isPendingPromise(S.v)) {
10288
10325
  for (const [j, I] of S.d)
10289
10326
  if (!C.d.has(j)) {
10290
10327
  const T = m(j);
10291
- B(j).t.add(v), C.d.add(j), I !== T.n && (a.add(j), (E = c.c) == null || E.call(c, j), b(j));
10328
+ _(j).t.add(v), C.d.add(j), I !== T.n && (a.add(j), (B = c.c) == null || B.call(c, j), b(j));
10292
10329
  }
10293
10330
  for (const j of C.d || [])
10294
10331
  if (!S.d.has(j)) {
@@ -10297,34 +10334,34 @@ const RootLayout = () => {
10297
10334
  I == null || I.t.delete(v);
10298
10335
  }
10299
10336
  }
10300
- }), B = h[7] || ((v) => {
10301
- var E;
10337
+ }), _ = h[7] || ((v) => {
10338
+ var B;
10302
10339
  const S = m(v);
10303
10340
  let C = r.get(v);
10304
10341
  if (!C) {
10305
10342
  y(v);
10306
10343
  for (const j of S.d.keys())
10307
- B(j).t.add(v);
10344
+ _(j).t.add(v);
10308
10345
  if (C = {
10309
10346
  l: /* @__PURE__ */ new Set(),
10310
10347
  d: new Set(S.d.keys()),
10311
10348
  t: /* @__PURE__ */ new Set()
10312
- }, r.set(v, C), (E = c.m) == null || E.call(c, v), isActuallyWritableAtom(v)) {
10349
+ }, r.set(v, C), (B = c.m) == null || B.call(c, v), isActuallyWritableAtom(v)) {
10313
10350
  const j = () => {
10314
10351
  let I = !0;
10315
- const T = (...R) => {
10352
+ const T = (...P) => {
10316
10353
  try {
10317
- return A(v, ...R);
10354
+ return A(v, ...P);
10318
10355
  } finally {
10319
10356
  I || (x(), f());
10320
10357
  }
10321
10358
  };
10322
10359
  try {
10323
- const R = g(v, T);
10324
- R && (C.u = () => {
10360
+ const P = g(v, T);
10361
+ P && (C.u = () => {
10325
10362
  I = !0;
10326
10363
  try {
10327
- R();
10364
+ P();
10328
10365
  } finally {
10329
10366
  I = !1;
10330
10367
  }
@@ -10338,14 +10375,14 @@ const RootLayout = () => {
10338
10375
  }
10339
10376
  return C;
10340
10377
  }), N = h[8] || ((v) => {
10341
- var E;
10378
+ var B;
10342
10379
  const S = m(v);
10343
10380
  let C = r.get(v);
10344
10381
  if (C && !C.l.size && !Array.from(C.t).some((j) => {
10345
10382
  var I;
10346
10383
  return (I = r.get(j)) == null ? void 0 : I.d.has(v);
10347
10384
  })) {
10348
- C.u && i.add(C.u), C = void 0, r.delete(v), (E = c.u) == null || E.call(c, v);
10385
+ C.u && i.add(C.u), C = void 0, r.delete(v), (B = c.u) == null || B.call(c, v);
10349
10386
  for (const j of S.d.keys()) {
10350
10387
  const I = N(j);
10351
10388
  I == null || I.t.delete(v);
@@ -10374,22 +10411,22 @@ const RootLayout = () => {
10374
10411
  y,
10375
10412
  b,
10376
10413
  A,
10414
+ E,
10377
10415
  _,
10378
- B,
10379
10416
  N
10380
10417
  ], k = {
10381
10418
  get: (v) => returnAtomValue(y(v)),
10382
- set: (v, ...E) => {
10419
+ set: (v, ...B) => {
10383
10420
  try {
10384
- return A(v, ...E);
10421
+ return A(v, ...B);
10385
10422
  } finally {
10386
10423
  x(), f();
10387
10424
  }
10388
10425
  },
10389
- sub: (v, E) => {
10390
- const C = B(v).l;
10391
- return C.add(E), f(), () => {
10392
- C.delete(E), N(v), f();
10426
+ sub: (v, B) => {
10427
+ const C = _(v).l;
10428
+ return C.add(B), f(), () => {
10429
+ C.delete(B), N(v), f();
10393
10430
  };
10394
10431
  }
10395
10432
  };
@@ -10498,7 +10535,7 @@ const useAutoSave = () => {
10498
10535
  }, ChaiWatchers = (o) => {
10499
10536
  const [, r] = useBlocksStore(), n = useBuilderReset(), [a] = useAtom(builderSaveStateAtom);
10500
10537
  useAtom(selectedLibraryAtom), useKeyEventWatcher(), useExpandTree(), useAutoSave(), useWatchPartailBlocks(), useUnmountBroadcastChannel();
10501
- const { postMessage: l } = useBroadcastChannel();
10538
+ const { postMessage: l } = useBroadcastChannel(), [, i] = useAtom(isPageLoadedAtom);
10502
10539
  return useEffect(() => {
10503
10540
  builderStore.set(
10504
10541
  // @ts-ignore
@@ -10508,17 +10545,17 @@ const useAutoSave = () => {
10508
10545
  }, [o]), useEffect(() => {
10509
10546
  builderStore.set(chaiPageExternalDataAtom, o.pageExternalData || {});
10510
10547
  }, [o.pageExternalData]), useEffect(() => {
10511
- setTimeout(() => {
10512
- const i = syncBlocksWithDefaults(o.blocks || []);
10513
- r(i), i && i.length > 0 && l({ type: "blocks-updated", blocks: i }), n();
10548
+ i(!1), setTimeout(() => {
10549
+ const c = syncBlocksWithDefaults(o.blocks || []);
10550
+ r(c), c && c.length > 0 && l({ type: "blocks-updated", blocks: c }), n(), i(!0);
10514
10551
  }, 400);
10515
10552
  }, [o.blocks]), useEffect(() => {
10516
10553
  i18n.changeLanguage(o.locale || "en");
10517
10554
  }, [o.locale]), useEffect(() => {
10518
10555
  setDebugLogs(o.debugLogs);
10519
10556
  }, [o.debugLogs]), useEffect(() => {
10520
- o.translations && each(o.translations, (i, c) => {
10521
- i18n.addResourceBundle(c, "translation", i, !0, !0);
10557
+ o.translations && each(o.translations, (c, d) => {
10558
+ i18n.addResourceBundle(d, "translation", c, !0, !0);
10522
10559
  });
10523
10560
  }, [o.translations]), useEffect(() => (a !== "SAVED" ? window.onbeforeunload = () => "" : window.onbeforeunload = null, () => {
10524
10561
  window.onbeforeunload = null;
@@ -10602,6 +10639,7 @@ export {
10602
10639
  useHiddenBlockIds,
10603
10640
  useHighlightBlockId,
10604
10641
  useInlineEditing,
10642
+ useIsPageLoaded,
10605
10643
  useLanguages,
10606
10644
  useLibraryBlocks,
10607
10645
  useMediaManagerComponent,