@chaibuilder/sdk 2.1.6 → 2.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/core.d.ts CHANGED
@@ -396,7 +396,6 @@ export declare const PERMISSIONS: {
396
396
  EDIT_LIBRARY_BLOCK: string;
397
397
  EDIT_LIBRARY_GROUP: string;
398
398
  DELETE_LIBRARY_BLOCK: string;
399
- DELETE_LIBRARY_GROUP: string;
400
399
  };
401
400
 
402
401
  declare type ReactComponentType = default_2.ComponentType<any>;
@@ -533,7 +532,7 @@ export declare const useLibraryBlocks: (library?: Partial<ChaiUILibrary> & {
533
532
  }) => {
534
533
  data: any;
535
534
  isLoading: boolean;
536
- resetLibrary: () => void;
535
+ resetLibrary: (libraryId: string) => void;
537
536
  };
538
537
 
539
538
  export declare const useMediaManagerComponent: () => ComponentType<MediaManagerProps>;
@@ -605,6 +604,12 @@ export declare const useSelectedBlocksDisplayChild: () => {
605
604
 
606
605
  export declare const useSelectedBreakpoints: () => [string[], Function];
607
606
 
607
+ /**
608
+ * Hook to get and set the selected UI library
609
+ * @returns {[string, (library: string) => void]} A tuple containing the selected library ID and a function to set the selected library
610
+ */
611
+ export declare const useSelectedLibrary: () => [string, (args_0: string | RESET | ((prev: string) => string | RESET)) => void];
612
+
608
613
  /**
609
614
  * @group Hooks
610
615
  * @returns {TStyleBlock[]} selected styling blocks
package/dist/core.js CHANGED
@@ -770,15 +770,23 @@ const useUndoManager = () => {
770
770
  const [r, n] = useAtom$1(libraryBlocksAtom), a = useBuilderProp("getUILibraryBlocks", noop), l = get(r, `${o == null ? void 0 : o.id}.blocks`, null), i = get(r, `${o == null ? void 0 : o.id}.loading`, "idle"), c = useRef("idle");
771
771
  useEffect(() => {
772
772
  (async () => {
773
- if (i === "complete" || c.current === "loading") return;
774
- c.current = "loading", n((u) => ({ ...u, [o == null ? void 0 : o.id]: { loading: "loading", blocks: [] } }));
775
- const p = await a(o);
776
- c.current = "idle", n((u) => ({ ...u, [o == null ? void 0 : o.id]: { loading: "complete", blocks: p || [] } }));
773
+ if (!(i === "complete" || c.current === "loading")) {
774
+ c.current = "loading", n((p) => ({ ...p, [o == null ? void 0 : o.id]: { loading: "loading", blocks: [] } }));
775
+ try {
776
+ const p = await a(o);
777
+ c.current = "idle", n((u) => ({ ...u, [o == null ? void 0 : o.id]: { loading: "complete", blocks: p || [] } }));
778
+ } catch {
779
+ c.current = "idle", n((u) => ({ ...u, [o == null ? void 0 : o.id]: { loading: "complete", blocks: [] } }));
780
+ }
781
+ }
777
782
  })();
778
783
  }, [o, l, i, c, n, a]);
779
- const d = useCallback(() => {
780
- n((p) => ({ ...p, [o == null ? void 0 : o.id]: { loading: "idle", blocks: [] } }));
781
- }, [o, n]);
784
+ const d = useCallback(
785
+ (p) => {
786
+ n((u) => ({ ...u, [p]: { loading: "idle", blocks: [] } }));
787
+ },
788
+ [n]
789
+ );
782
790
  return { data: l || [], isLoading: i === "loading", resetLibrary: d };
783
791
  }, canAcceptChildBlock = (o, r) => {
784
792
  if (!o) return !0;
@@ -2648,7 +2656,7 @@ const useBlockHighlight = () => {
2648
2656
  return null;
2649
2657
  });
2650
2658
  wrapperBlockAtom.debugLabel = "wrapperBlockAtom";
2651
- const useWrapperBlock = () => useAtomValue$1(wrapperBlockAtom), sidebarActivePanelAtom = atom("outline");
2659
+ const useWrapperBlock = () => useAtomValue$1(wrapperBlockAtom), useSelectedLibrary = () => useAtom$1(selectedLibraryAtom), sidebarActivePanelAtom = atom("outline");
2652
2660
  sidebarActivePanelAtom.debugLabel = "sidebarActivePanelAtom";
2653
2661
  const useSidebarActivePanel = () => useAtom$1(sidebarActivePanelAtom);
2654
2662
  function getOrientation(o, r = null) {
@@ -6598,7 +6606,7 @@ const BlockCard = ({
6598
6606
  /* @__PURE__ */ jsx(TooltipContent, { children: /* @__PURE__ */ jsx("p", { children: f }) })
6599
6607
  ] });
6600
6608
  }, UILibrarySection = ({ parentId: o, position: r }) => {
6601
- const [n, a] = useAtom$1(selectedLibraryAtom), l = useBuilderProp("uiLibraries", []), i = l.find((v) => v.id === n) || first(l), { data: c, isLoading: d } = useLibraryBlocks(i), p = groupBy([...c], "group"), [u, g] = useState(null);
6609
+ const [n, a] = useSelectedLibrary(), l = useBuilderProp("uiLibraries", []), i = l.find((v) => v.id === n) || first(l), { data: c, isLoading: d } = useLibraryBlocks(i), p = groupBy([...c], "group"), [u, g] = useState(null);
6602
6610
  useEffect(() => {
6603
6611
  u || g(first(keys(p)));
6604
6612
  }, [p, u]);
@@ -6614,7 +6622,7 @@ const BlockCard = ({
6614
6622
  ] });
6615
6623
  const y = filter(f, (v, S) => S % 2 === 0), b = filter(f, (v, S) => S % 2 === 1);
6616
6624
  return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx("div", { className: "relative mt-2 flex h-full max-h-full overflow-hidden bg-background", children: /* @__PURE__ */ jsxs("div", { className: "flex h-full pt-2", children: [
6617
- /* @__PURE__ */ jsxs("div", { className: "flex h-full max-h-full w-60 flex-col gap-1 px-1 pr-2", children: [
6625
+ /* @__PURE__ */ jsxs("div", { className: "flex h-full max-h-full w-72 flex-col gap-1 px-1 pr-2", children: [
6618
6626
  /* @__PURE__ */ jsx(UILibrariesSelect, { library: i == null ? void 0 : i.id, setLibrary: a, uiLibraries: l }),
6619
6627
  /* @__PURE__ */ jsxs("div", { className: "mt-2 flex h-full max-h-full w-full flex-1 flex-col", children: [
6620
6628
  /* @__PURE__ */ jsx("span", { className: "text-xs font-bold text-gray-500", children: h("Groups") }),
@@ -6832,8 +6840,7 @@ const BlockCard = ({
6832
6840
  CREATE_LIBRARY_GROUP: "create_library_group",
6833
6841
  EDIT_LIBRARY_BLOCK: "edit_library_block",
6834
6842
  EDIT_LIBRARY_GROUP: "edit_library_group",
6835
- DELETE_LIBRARY_BLOCK: "delete_library_block",
6836
- DELETE_LIBRARY_GROUP: "delete_library_group"
6843
+ DELETE_LIBRARY_BLOCK: "delete_library_block"
6837
6844
  };
6838
6845
  Object.values(PERMISSIONS);
6839
6846
  let SAVE_TO_LIB_COMPONENT = null;
@@ -7161,7 +7168,7 @@ const selectParent = (o, r) => {
7161
7168
  ),
7162
7169
  /* @__PURE__ */ jsx("br", {})
7163
7170
  ] });
7164
- const L = useMemo(() => has(h, "_libBlockId"), [h]);
7171
+ const L = useMemo(() => has(h, "_libBlockId") && !isEmpty(h._libBlockId), [h]);
7165
7172
  return /* @__PURE__ */ jsx("div", { className: "w-full", children: /* @__PURE__ */ jsxs(
7166
7173
  "div",
7167
7174
  {
@@ -7199,13 +7206,13 @@ const selectParent = (o, r) => {
7199
7206
  "div",
7200
7207
  {
7201
7208
  className: cn(
7202
- "group flex w-full cursor-pointer items-center justify-between space-x-px !rounded p-1 text-foreground/80 outline-none",
7209
+ "group flex w-full cursor-pointer items-center justify-between space-x-px !rounded p-1 outline-none",
7203
7210
  x ? "bg-primary text-primary-foreground" : "hover:bg-primary/10 dark:hover:bg-gray-800",
7204
7211
  y && canAcceptChildBlock(h._type, "Icon") ? "bg-green-200" : "",
7205
7212
  (o == null ? void 0 : o.id) === A ? "bg-primary/10" : "",
7206
7213
  b && "opacity-20",
7207
7214
  l.includes(m) ? "opacity-50" : "",
7208
- L && x && "bg-primary/20"
7215
+ L && x && "bg-primary/20 text-primary"
7209
7216
  ),
7210
7217
  children: [
7211
7218
  /* @__PURE__ */ jsxs("div", { className: "flex items-center", children: [
@@ -7213,7 +7220,7 @@ const selectParent = (o, r) => {
7213
7220
  "div",
7214
7221
  {
7215
7222
  className: `flex h-4 w-4 rotate-0 transform cursor-pointer items-center justify-center transition-transform duration-100 ${o.isOpen ? "rotate-90" : ""}`,
7216
- children: u && /* @__PURE__ */ jsx("button", { onClick: j, type: "button", children: /* @__PURE__ */ jsx(ChevronRight, { className: `h-3 w-3 stroke-[3] ${x ? "text-slate-200" : "text-slate-400"}` }) })
7223
+ children: u && /* @__PURE__ */ jsx("button", { onClick: j, type: "button", children: /* @__PURE__ */ jsx(ChevronRight, { className: `h-3 w-3 stroke-[3] ${x ? "text-primary" : "text-slate-400"}` }) })
7217
7224
  }
7218
7225
  ),
7219
7226
  /* @__PURE__ */ jsxs(
@@ -7246,7 +7253,7 @@ const selectParent = (o, r) => {
7246
7253
  TooltipTrigger,
7247
7254
  {
7248
7255
  onClick: () => pubsub.publish(CHAI_BUILDER_EVENTS.OPEN_ADD_BLOCK, { _id: m }),
7249
- className: "cursor-pointer rounded bg-transparent hover:text-black",
7256
+ className: "cursor-pointer rounded bg-transparent",
7250
7257
  asChild: !0,
7251
7258
  children: /* @__PURE__ */ jsx(PlusIcon, { className: "h-3 w-3" })
7252
7259
  }
@@ -7260,7 +7267,7 @@ const selectParent = (o, r) => {
7260
7267
  onClick: (N) => {
7261
7268
  N.stopPropagation(), i(m), o.isOpen && o.toggle();
7262
7269
  },
7263
- className: "cursor-pointer rounded bg-transparent hover:text-black",
7270
+ className: "cursor-pointer rounded bg-transparent",
7264
7271
  asChild: !0,
7265
7272
  children: /* @__PURE__ */ jsx(EyeOffIcon, { size: "15" })
7266
7273
  }
@@ -9458,6 +9465,7 @@ export {
9458
9465
  useSelectedBlockIds,
9459
9466
  useSelectedBlocksDisplayChild,
9460
9467
  useSelectedBreakpoints,
9468
+ useSelectedLibrary,
9461
9469
  useSelectedStylingBlocks,
9462
9470
  useSidebarActivePanel,
9463
9471
  useStylingBreakpoint,
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": "2.1.6",
8
+ "version": "2.1.8",
9
9
  "type": "module",
10
10
  "repository": {
11
11
  "type": "git",