@chaibuilder/sdk 2.0.0-beta.94 → 2.0.0-beta.95
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.cjs +14 -3
- package/dist/core.js +14 -3
- package/package.json +1 -1
package/dist/core.cjs
CHANGED
|
@@ -1842,6 +1842,9 @@ const useGetBlockAtomValue = (splitAtoms) => {
|
|
|
1842
1842
|
React.useCallback(
|
|
1843
1843
|
(get, _set, idOrAtom) => {
|
|
1844
1844
|
const blockAsAtoms = get(splitAtoms);
|
|
1845
|
+
if (!blockAsAtoms || !blockAsAtoms.length) {
|
|
1846
|
+
throw new Error("No blocks available");
|
|
1847
|
+
}
|
|
1845
1848
|
const blockAtom = lodashEs.find(
|
|
1846
1849
|
blockAsAtoms,
|
|
1847
1850
|
(b) => get(b)._id === (lodashEs.isString(idOrAtom) ? idOrAtom : get(idOrAtom)._id)
|
|
@@ -1860,12 +1863,17 @@ const useGetBlockAtom = (splitAtoms) => {
|
|
|
1860
1863
|
React.useCallback(
|
|
1861
1864
|
(get, _set, idOrAtom) => {
|
|
1862
1865
|
const blockAsAtoms = get(splitAtoms);
|
|
1866
|
+
if (!blockAsAtoms || !blockAsAtoms.length) {
|
|
1867
|
+
console.warn("No blocks available in splitAtoms");
|
|
1868
|
+
return null;
|
|
1869
|
+
}
|
|
1863
1870
|
const blockAtom = lodashEs.find(
|
|
1864
1871
|
blockAsAtoms,
|
|
1865
1872
|
(b) => get(b)._id === (lodashEs.isString(idOrAtom) ? idOrAtom : get(idOrAtom)._id)
|
|
1866
1873
|
);
|
|
1867
1874
|
if (!blockAtom) {
|
|
1868
|
-
|
|
1875
|
+
console.warn(`Block with id ${idOrAtom} not found`);
|
|
1876
|
+
return null;
|
|
1869
1877
|
}
|
|
1870
1878
|
return blockAtom;
|
|
1871
1879
|
},
|
|
@@ -5103,18 +5111,21 @@ const BlocksRenderer = ({
|
|
|
5103
5111
|
parent = null,
|
|
5104
5112
|
splitAtoms = void 0
|
|
5105
5113
|
}) => {
|
|
5106
|
-
const
|
|
5114
|
+
const getBlockAtom = useGetBlockAtom(splitAtoms);
|
|
5107
5115
|
const filteredBlocks = React.useMemo(
|
|
5108
5116
|
() => lodashEs.filter(blocks, (block) => lodashEs.isString(parent) ? block._parent === parent : !block._parent),
|
|
5109
5117
|
[blocks, parent]
|
|
5110
5118
|
);
|
|
5111
5119
|
const hasChildren = React.useCallback((block) => lodashEs.filter(blocks, (b) => b._parent === block._id).length > 0, [blocks]);
|
|
5112
5120
|
return lodashEs.map(filteredBlocks, (block) => {
|
|
5113
|
-
|
|
5121
|
+
const blockAtom = getBlockAtom(block._id);
|
|
5122
|
+
if (!blockAtom) return null;
|
|
5123
|
+
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
5124
|
});
|
|
5115
5125
|
};
|
|
5116
5126
|
const PageBlocksRenderer = () => {
|
|
5117
5127
|
const [blocks] = useBlocksStore();
|
|
5128
|
+
console.log(jotai.useAtomValue(pageBlocksAtomsAtom));
|
|
5118
5129
|
return /* @__PURE__ */ jsxRuntime.jsx(BlocksRenderer, { splitAtoms: pageBlocksAtomsAtom, blocks });
|
|
5119
5130
|
};
|
|
5120
5131
|
const StaticBlocksRenderer = () => {
|
package/dist/core.js
CHANGED
|
@@ -1827,6 +1827,9 @@ const useGetBlockAtomValue = (splitAtoms) => {
|
|
|
1827
1827
|
useCallback(
|
|
1828
1828
|
(get2, _set, idOrAtom) => {
|
|
1829
1829
|
const blockAsAtoms = get2(splitAtoms);
|
|
1830
|
+
if (!blockAsAtoms || !blockAsAtoms.length) {
|
|
1831
|
+
throw new Error("No blocks available");
|
|
1832
|
+
}
|
|
1830
1833
|
const blockAtom = find(
|
|
1831
1834
|
blockAsAtoms,
|
|
1832
1835
|
(b) => get2(b)._id === (isString(idOrAtom) ? idOrAtom : get2(idOrAtom)._id)
|
|
@@ -1845,12 +1848,17 @@ const useGetBlockAtom = (splitAtoms) => {
|
|
|
1845
1848
|
useCallback(
|
|
1846
1849
|
(get2, _set, idOrAtom) => {
|
|
1847
1850
|
const blockAsAtoms = get2(splitAtoms);
|
|
1851
|
+
if (!blockAsAtoms || !blockAsAtoms.length) {
|
|
1852
|
+
console.warn("No blocks available in splitAtoms");
|
|
1853
|
+
return null;
|
|
1854
|
+
}
|
|
1848
1855
|
const blockAtom = find(
|
|
1849
1856
|
blockAsAtoms,
|
|
1850
1857
|
(b) => get2(b)._id === (isString(idOrAtom) ? idOrAtom : get2(idOrAtom)._id)
|
|
1851
1858
|
);
|
|
1852
1859
|
if (!blockAtom) {
|
|
1853
|
-
|
|
1860
|
+
console.warn(`Block with id ${idOrAtom} not found`);
|
|
1861
|
+
return null;
|
|
1854
1862
|
}
|
|
1855
1863
|
return blockAtom;
|
|
1856
1864
|
},
|
|
@@ -5088,18 +5096,21 @@ const BlocksRenderer = ({
|
|
|
5088
5096
|
parent = null,
|
|
5089
5097
|
splitAtoms = void 0
|
|
5090
5098
|
}) => {
|
|
5091
|
-
const
|
|
5099
|
+
const getBlockAtom = useGetBlockAtom(splitAtoms);
|
|
5092
5100
|
const filteredBlocks = useMemo(
|
|
5093
5101
|
() => filter(blocks, (block) => isString(parent) ? block._parent === parent : !block._parent),
|
|
5094
5102
|
[blocks, parent]
|
|
5095
5103
|
);
|
|
5096
5104
|
const hasChildren = useCallback((block) => filter(blocks, (b) => b._parent === block._id).length > 0, [blocks]);
|
|
5097
5105
|
return map(filteredBlocks, (block) => {
|
|
5098
|
-
|
|
5106
|
+
const blockAtom = getBlockAtom(block._id);
|
|
5107
|
+
if (!blockAtom) return null;
|
|
5108
|
+
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
5109
|
});
|
|
5100
5110
|
};
|
|
5101
5111
|
const PageBlocksRenderer = () => {
|
|
5102
5112
|
const [blocks] = useBlocksStore();
|
|
5113
|
+
console.log(useAtomValue$1(pageBlocksAtomsAtom));
|
|
5103
5114
|
return /* @__PURE__ */ jsx(BlocksRenderer, { splitAtoms: pageBlocksAtomsAtom, blocks });
|
|
5104
5115
|
};
|
|
5105
5116
|
const StaticBlocksRenderer = () => {
|