@chaibuilder/sdk 2.0.0-beta.94 → 2.0.0-beta.96

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/dist/core.cjs +25 -12
  2. package/dist/core.js +26 -13
  3. package/package.json +1 -1
package/dist/core.cjs CHANGED
@@ -840,7 +840,7 @@ const StoreContext = React.createContext(
840
840
  );
841
841
  const useStore = (options) => {
842
842
  const store = React.useContext(StoreContext);
843
- return store || getDefaultStore();
843
+ return (options == null ? void 0 : options.store) || store || getDefaultStore();
844
844
  };
845
845
  const isPromiseLike = (x) => typeof (x == null ? void 0 : x.then) === "function";
846
846
  const attachPromiseMeta = (promise) => {
@@ -906,7 +906,7 @@ const createContinuablePromise = (promise) => {
906
906
  return continuablePromise;
907
907
  };
908
908
  function useAtomValue(atom2, options) {
909
- const store = useStore();
909
+ const store = useStore(options);
910
910
  const [[valueFromReducer, storeFromReducer, atomFromReducer], rerender] = React.useReducer(
911
911
  (prev) => {
912
912
  const nextValue = store.get(atom2);
@@ -939,7 +939,7 @@ function useAtomValue(atom2, options) {
939
939
  return value;
940
940
  }
941
941
  function useSetAtom(atom2, options) {
942
- const store = useStore();
942
+ const store = useStore(options);
943
943
  const setAtom = React.useCallback(
944
944
  (...args) => {
945
945
  return store.set(atom2, ...args);
@@ -950,9 +950,9 @@ function useSetAtom(atom2, options) {
950
950
  }
951
951
  function useAtom(atom2, options) {
952
952
  return [
953
- useAtomValue(atom2),
953
+ useAtomValue(atom2, options),
954
954
  // We do wrong type assertion here, which results in throwing an error.
955
- useSetAtom(atom2)
955
+ useSetAtom(atom2, options)
956
956
  ];
957
957
  }
958
958
  function useAtomCallback(callback, options) {
@@ -960,7 +960,7 @@ function useAtomCallback(callback, options) {
960
960
  () => atom(null, (get, set, ...args) => callback(get, set, ...args)),
961
961
  [callback]
962
962
  );
963
- return useSetAtom(anAtom);
963
+ return useSetAtom(anAtom, options);
964
964
  }
965
965
  const readOnlyModeAtom = jotai.atom(false);
966
966
  readOnlyModeAtom.debugLabel = "readOnlyModeAtom";
@@ -1822,6 +1822,7 @@ const useRemoveBlocks = () => {
1822
1822
  [presentBlocks, setSelectedIds, ids2]
1823
1823
  );
1824
1824
  };
1825
+ const builderStore = jotai.getDefaultStore();
1825
1826
  const writeAtomValue = jotai.atom(
1826
1827
  null,
1827
1828
  // it's a convention to pass `null` for the first argument
@@ -1842,6 +1843,9 @@ const useGetBlockAtomValue = (splitAtoms) => {
1842
1843
  React.useCallback(
1843
1844
  (get, _set, idOrAtom) => {
1844
1845
  const blockAsAtoms = get(splitAtoms);
1846
+ if (!blockAsAtoms || !blockAsAtoms.length) {
1847
+ throw new Error("No blocks available");
1848
+ }
1845
1849
  const blockAtom = lodashEs.find(
1846
1850
  blockAsAtoms,
1847
1851
  (b) => get(b)._id === (lodashEs.isString(idOrAtom) ? idOrAtom : get(idOrAtom)._id)
@@ -1852,7 +1856,8 @@ const useGetBlockAtomValue = (splitAtoms) => {
1852
1856
  return get(blockAtom);
1853
1857
  },
1854
1858
  [splitAtoms]
1855
- )
1859
+ ),
1860
+ { store: builderStore }
1856
1861
  );
1857
1862
  };
1858
1863
  const useGetBlockAtom = (splitAtoms) => {
@@ -1860,17 +1865,23 @@ const useGetBlockAtom = (splitAtoms) => {
1860
1865
  React.useCallback(
1861
1866
  (get, _set, idOrAtom) => {
1862
1867
  const blockAsAtoms = get(splitAtoms);
1868
+ if (!blockAsAtoms || !blockAsAtoms.length) {
1869
+ console.warn("No blocks available in splitAtoms");
1870
+ return null;
1871
+ }
1863
1872
  const blockAtom = lodashEs.find(
1864
1873
  blockAsAtoms,
1865
1874
  (b) => get(b)._id === (lodashEs.isString(idOrAtom) ? idOrAtom : get(idOrAtom)._id)
1866
1875
  );
1867
1876
  if (!blockAtom) {
1868
- throw new Error(`Block with id ${idOrAtom} not found`);
1877
+ console.warn(`Block with id ${idOrAtom} not found`);
1878
+ return null;
1869
1879
  }
1870
1880
  return blockAtom;
1871
1881
  },
1872
1882
  [splitAtoms]
1873
- )
1883
+ ),
1884
+ { store: builderStore }
1874
1885
  );
1875
1886
  };
1876
1887
  function insertBlocksAtPosition(allBlocks, newBlocks, parentId, position) {
@@ -5103,18 +5114,21 @@ const BlocksRenderer = ({
5103
5114
  parent = null,
5104
5115
  splitAtoms = void 0
5105
5116
  }) => {
5106
- const getAtomValue = useGetBlockAtom(splitAtoms);
5117
+ const getBlockAtom = useGetBlockAtom(splitAtoms);
5107
5118
  const filteredBlocks = React.useMemo(
5108
5119
  () => lodashEs.filter(blocks, (block) => lodashEs.isString(parent) ? block._parent === parent : !block._parent),
5109
5120
  [blocks, parent]
5110
5121
  );
5111
5122
  const hasChildren = React.useCallback((block) => lodashEs.filter(blocks, (b) => b._parent === block._id).length > 0, [blocks]);
5112
5123
  return lodashEs.map(filteredBlocks, (block) => {
5113
- return /* @__PURE__ */ jsxRuntime.jsx(BlockRenderer, { blockAtom: getAtomValue(block._id), children: block._type === "GlobalBlock" ? /* @__PURE__ */ jsxRuntime.jsx(GlobalBlocksRenderer, { blockAtom: getAtomValue(block._id) }) : hasChildren(block) ? /* @__PURE__ */ jsxRuntime.jsx(BlocksRenderer, { splitAtoms, blocks, parent: block._id }) : null }, block._id);
5124
+ const blockAtom = getBlockAtom(block._id);
5125
+ if (!blockAtom) return null;
5126
+ return /* @__PURE__ */ jsxRuntime.jsx(BlockRenderer, { blockAtom, children: block._type === "GlobalBlock" ? /* @__PURE__ */ jsxRuntime.jsx(GlobalBlocksRenderer, { blockAtom: getBlockAtom(block._id) }) : hasChildren(block) ? /* @__PURE__ */ jsxRuntime.jsx(BlocksRenderer, { splitAtoms, blocks, parent: block._id }) : null }, block._id);
5114
5127
  });
5115
5128
  };
5116
5129
  const PageBlocksRenderer = () => {
5117
5130
  const [blocks] = useBlocksStore();
5131
+ console.log(jotai.useAtomValue(pageBlocksAtomsAtom));
5118
5132
  return /* @__PURE__ */ jsxRuntime.jsx(BlocksRenderer, { splitAtoms: pageBlocksAtomsAtom, blocks });
5119
5133
  };
5120
5134
  const StaticBlocksRenderer = () => {
@@ -11037,7 +11051,6 @@ function getFromQueryParams(key) {
11037
11051
  const FEATURE_TOGGLES = {
11038
11052
  dnd: getFromQueryParams("dnd")
11039
11053
  };
11040
- const builderStore = jotai.getDefaultStore();
11041
11054
  const setDebugLogs = (value) => {
11042
11055
  };
11043
11056
  const getParentNodeIds = (blocks, id) => {
package/dist/core.js CHANGED
@@ -5,7 +5,7 @@ import { jsx, Fragment, jsxs } from "react/jsx-runtime";
5
5
  import * as React from "react";
6
6
  import React__default, { createContext, useReducer, useEffect, useDebugValue, useCallback, useContext, useMemo, Component, Children, useState, useRef, Suspense, createElement, memo, lazy } from "react";
7
7
  import { ag as useToast, S as Skeleton, B as Button, L as Label, D as Dialog, s as DialogTrigger, a as DialogContent, h as Badge, T as Textarea, O as Tooltip, P as TooltipTrigger, Q as TooltipContent, V as Popover, W as PopoverTrigger, X as PopoverContent, I as Input$1, U as TooltipPortal, e as AccordionItem, f as AccordionTrigger, g as AccordionContent, $ as DropdownMenu, a0 as DropdownMenuTrigger, a1 as DropdownMenuContent, G as ScrollArea, a5 as DropdownMenuLabel, a6 as DropdownMenuSeparator, a8 as DropdownMenuGroup, a2 as DropdownMenuItem, a7 as DropdownMenuShortcut, A as Accordion, C as Card, x as CardHeader, E as CardDescription, F as CardContent, y as CardFooter, J as Tabs, K as TabsList, M as TabsTrigger, N as TabsContent, aj as ContextMenu, ak as ContextMenuTrigger, al as ContextMenuContent, am as ContextMenuItem, j as AlertDialog, k as AlertDialogTrigger, l as AlertDialogContent, m as AlertDialogHeader, o as AlertDialogTitle, p as AlertDialogDescription, n as AlertDialogFooter, r as AlertDialogCancel, q as AlertDialogAction, a3 as DropdownMenuCheckboxItem, Y as HoverCard, Z as HoverCardTrigger, _ as HoverCardContent, b as Switch, ae as Separator, R as TooltipProvider, ai as Toaster } from "./context-menu-DHla8ofZ.js";
8
- import { atom as atom$1, useAtomValue as useAtomValue$1, useAtom as useAtom$1, useSetAtom as useSetAtom$1, getDefaultStore as getDefaultStore$1 } from "jotai";
8
+ import { atom as atom$1, useAtomValue as useAtomValue$1, useAtom as useAtom$1, getDefaultStore as getDefaultStore$1, useSetAtom as useSetAtom$1 } from "jotai";
9
9
  import { has, get, find, filter, flatten, map, omit, isString, includes, without, compact, each, set, first, isObject, memoize, isEmpty, noop, keys, range, values, flattenDeep, startsWith, isNull, forEach, unset, chunk, cloneDeep, pick, throttle, isFunction as isFunction$1, reverse, startCase, debounce, capitalize, split, findIndex, take, nth, toLower, isNumber, parseInt as parseInt$1, isNaN as isNaN$1, findLast, intersection, groupBy, uniq, flatMapDeep, some, reject, sortBy, toUpper, round } from "lodash-es";
10
10
  import { Provider } from "react-wrap-balancer";
11
11
  import { g as generateUUID, a as getBreakpointValue, c as cn, G as GenIcon } from "./iconBase-CWgVxu0A.js";
@@ -825,7 +825,7 @@ const StoreContext = createContext(
825
825
  );
826
826
  const useStore = (options) => {
827
827
  const store = useContext(StoreContext);
828
- return store || getDefaultStore();
828
+ return (options == null ? void 0 : options.store) || store || getDefaultStore();
829
829
  };
830
830
  const isPromiseLike = (x) => typeof (x == null ? void 0 : x.then) === "function";
831
831
  const attachPromiseMeta = (promise) => {
@@ -891,7 +891,7 @@ const createContinuablePromise = (promise) => {
891
891
  return continuablePromise;
892
892
  };
893
893
  function useAtomValue(atom2, options) {
894
- const store = useStore();
894
+ const store = useStore(options);
895
895
  const [[valueFromReducer, storeFromReducer, atomFromReducer], rerender] = useReducer(
896
896
  (prev) => {
897
897
  const nextValue = store.get(atom2);
@@ -924,7 +924,7 @@ function useAtomValue(atom2, options) {
924
924
  return value;
925
925
  }
926
926
  function useSetAtom(atom2, options) {
927
- const store = useStore();
927
+ const store = useStore(options);
928
928
  const setAtom = useCallback(
929
929
  (...args) => {
930
930
  return store.set(atom2, ...args);
@@ -935,9 +935,9 @@ function useSetAtom(atom2, options) {
935
935
  }
936
936
  function useAtom(atom2, options) {
937
937
  return [
938
- useAtomValue(atom2),
938
+ useAtomValue(atom2, options),
939
939
  // We do wrong type assertion here, which results in throwing an error.
940
- useSetAtom(atom2)
940
+ useSetAtom(atom2, options)
941
941
  ];
942
942
  }
943
943
  function useAtomCallback(callback, options) {
@@ -945,7 +945,7 @@ function useAtomCallback(callback, options) {
945
945
  () => atom(null, (get2, set2, ...args) => callback(get2, set2, ...args)),
946
946
  [callback]
947
947
  );
948
- return useSetAtom(anAtom);
948
+ return useSetAtom(anAtom, options);
949
949
  }
950
950
  const readOnlyModeAtom = atom$1(false);
951
951
  readOnlyModeAtom.debugLabel = "readOnlyModeAtom";
@@ -1807,6 +1807,7 @@ const useRemoveBlocks = () => {
1807
1807
  [presentBlocks, setSelectedIds, ids2]
1808
1808
  );
1809
1809
  };
1810
+ const builderStore = getDefaultStore$1();
1810
1811
  const writeAtomValue = atom$1(
1811
1812
  null,
1812
1813
  // it's a convention to pass `null` for the first argument
@@ -1827,6 +1828,9 @@ const useGetBlockAtomValue = (splitAtoms) => {
1827
1828
  useCallback(
1828
1829
  (get2, _set, idOrAtom) => {
1829
1830
  const blockAsAtoms = get2(splitAtoms);
1831
+ if (!blockAsAtoms || !blockAsAtoms.length) {
1832
+ throw new Error("No blocks available");
1833
+ }
1830
1834
  const blockAtom = find(
1831
1835
  blockAsAtoms,
1832
1836
  (b) => get2(b)._id === (isString(idOrAtom) ? idOrAtom : get2(idOrAtom)._id)
@@ -1837,7 +1841,8 @@ const useGetBlockAtomValue = (splitAtoms) => {
1837
1841
  return get2(blockAtom);
1838
1842
  },
1839
1843
  [splitAtoms]
1840
- )
1844
+ ),
1845
+ { store: builderStore }
1841
1846
  );
1842
1847
  };
1843
1848
  const useGetBlockAtom = (splitAtoms) => {
@@ -1845,17 +1850,23 @@ const useGetBlockAtom = (splitAtoms) => {
1845
1850
  useCallback(
1846
1851
  (get2, _set, idOrAtom) => {
1847
1852
  const blockAsAtoms = get2(splitAtoms);
1853
+ if (!blockAsAtoms || !blockAsAtoms.length) {
1854
+ console.warn("No blocks available in splitAtoms");
1855
+ return null;
1856
+ }
1848
1857
  const blockAtom = find(
1849
1858
  blockAsAtoms,
1850
1859
  (b) => get2(b)._id === (isString(idOrAtom) ? idOrAtom : get2(idOrAtom)._id)
1851
1860
  );
1852
1861
  if (!blockAtom) {
1853
- throw new Error(`Block with id ${idOrAtom} not found`);
1862
+ console.warn(`Block with id ${idOrAtom} not found`);
1863
+ return null;
1854
1864
  }
1855
1865
  return blockAtom;
1856
1866
  },
1857
1867
  [splitAtoms]
1858
- )
1868
+ ),
1869
+ { store: builderStore }
1859
1870
  );
1860
1871
  };
1861
1872
  function insertBlocksAtPosition(allBlocks, newBlocks, parentId, position) {
@@ -5088,18 +5099,21 @@ const BlocksRenderer = ({
5088
5099
  parent = null,
5089
5100
  splitAtoms = void 0
5090
5101
  }) => {
5091
- const getAtomValue = useGetBlockAtom(splitAtoms);
5102
+ const getBlockAtom = useGetBlockAtom(splitAtoms);
5092
5103
  const filteredBlocks = useMemo(
5093
5104
  () => filter(blocks, (block) => isString(parent) ? block._parent === parent : !block._parent),
5094
5105
  [blocks, parent]
5095
5106
  );
5096
5107
  const hasChildren = useCallback((block) => filter(blocks, (b) => b._parent === block._id).length > 0, [blocks]);
5097
5108
  return map(filteredBlocks, (block) => {
5098
- return /* @__PURE__ */ jsx(BlockRenderer, { blockAtom: getAtomValue(block._id), children: block._type === "GlobalBlock" ? /* @__PURE__ */ jsx(GlobalBlocksRenderer, { blockAtom: getAtomValue(block._id) }) : hasChildren(block) ? /* @__PURE__ */ jsx(BlocksRenderer, { splitAtoms, blocks, parent: block._id }) : null }, block._id);
5109
+ const blockAtom = getBlockAtom(block._id);
5110
+ if (!blockAtom) return null;
5111
+ return /* @__PURE__ */ jsx(BlockRenderer, { blockAtom, children: block._type === "GlobalBlock" ? /* @__PURE__ */ jsx(GlobalBlocksRenderer, { blockAtom: getBlockAtom(block._id) }) : hasChildren(block) ? /* @__PURE__ */ jsx(BlocksRenderer, { splitAtoms, blocks, parent: block._id }) : null }, block._id);
5099
5112
  });
5100
5113
  };
5101
5114
  const PageBlocksRenderer = () => {
5102
5115
  const [blocks] = useBlocksStore();
5116
+ console.log(useAtomValue$1(pageBlocksAtomsAtom));
5103
5117
  return /* @__PURE__ */ jsx(BlocksRenderer, { splitAtoms: pageBlocksAtomsAtom, blocks });
5104
5118
  };
5105
5119
  const StaticBlocksRenderer = () => {
@@ -11022,7 +11036,6 @@ function getFromQueryParams(key) {
11022
11036
  const FEATURE_TOGGLES = {
11023
11037
  dnd: getFromQueryParams("dnd")
11024
11038
  };
11025
- const builderStore = getDefaultStore$1();
11026
11039
  const setDebugLogs = (value) => {
11027
11040
  };
11028
11041
  const getParentNodeIds = (blocks, id) => {
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.0.0-beta.94",
8
+ "version": "2.0.0-beta.96",
9
9
  "type": "module",
10
10
  "repository": {
11
11
  "type": "git",