@chaibuilder/sdk 2.1.7 → 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;
@@ -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.7",
8
+ "version": "2.1.8",
9
9
  "type": "module",
10
10
  "repository": {
11
11
  "type": "git",