@chaibuilder/sdk 2.0.0-beta.93 → 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 +20 -10
- package/dist/core.js +20 -10
- package/package.json +1 -1
package/dist/core.cjs
CHANGED
|
@@ -1841,14 +1841,16 @@ const useGetBlockAtomValue = (splitAtoms) => {
|
|
|
1841
1841
|
return useAtomCallback(
|
|
1842
1842
|
React.useCallback(
|
|
1843
1843
|
(get, _set, idOrAtom) => {
|
|
1844
|
-
const blockAsAtoms = get(
|
|
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)
|
|
1848
1851
|
);
|
|
1849
1852
|
if (!blockAtom) {
|
|
1850
|
-
|
|
1851
|
-
return;
|
|
1853
|
+
throw new Error(`Block with id ${idOrAtom} not found`);
|
|
1852
1854
|
}
|
|
1853
1855
|
return get(blockAtom);
|
|
1854
1856
|
},
|
|
@@ -1860,14 +1862,18 @@ const useGetBlockAtom = (splitAtoms) => {
|
|
|
1860
1862
|
return useAtomCallback(
|
|
1861
1863
|
React.useCallback(
|
|
1862
1864
|
(get, _set, idOrAtom) => {
|
|
1863
|
-
const blockAsAtoms = get(splitAtoms
|
|
1865
|
+
const blockAsAtoms = get(splitAtoms);
|
|
1866
|
+
if (!blockAsAtoms || !blockAsAtoms.length) {
|
|
1867
|
+
console.warn("No blocks available in splitAtoms");
|
|
1868
|
+
return null;
|
|
1869
|
+
}
|
|
1864
1870
|
const blockAtom = lodashEs.find(
|
|
1865
1871
|
blockAsAtoms,
|
|
1866
1872
|
(b) => get(b)._id === (lodashEs.isString(idOrAtom) ? idOrAtom : get(idOrAtom)._id)
|
|
1867
1873
|
);
|
|
1868
1874
|
if (!blockAtom) {
|
|
1869
1875
|
console.warn(`Block with id ${idOrAtom} not found`);
|
|
1870
|
-
return;
|
|
1876
|
+
return null;
|
|
1871
1877
|
}
|
|
1872
1878
|
return blockAtom;
|
|
1873
1879
|
},
|
|
@@ -4715,7 +4721,7 @@ const useHandleCanvasDblClick = () => {
|
|
|
4715
4721
|
const updateContent = useUpdateBlocksProps();
|
|
4716
4722
|
const [editingBlockId, setEditingBlockId] = jotai.useAtom(inlineEditingActiveAtom);
|
|
4717
4723
|
const { clearHighlight } = useBlockHighlight();
|
|
4718
|
-
const getBlockAtomValue = useGetBlockAtomValue();
|
|
4724
|
+
const getBlockAtomValue = useGetBlockAtomValue(pageBlocksAtomsAtom);
|
|
4719
4725
|
return React.useCallback(
|
|
4720
4726
|
(e2) => {
|
|
4721
4727
|
var _a;
|
|
@@ -5105,19 +5111,22 @@ const BlocksRenderer = ({
|
|
|
5105
5111
|
parent = null,
|
|
5106
5112
|
splitAtoms = void 0
|
|
5107
5113
|
}) => {
|
|
5108
|
-
const
|
|
5114
|
+
const getBlockAtom = useGetBlockAtom(splitAtoms);
|
|
5109
5115
|
const filteredBlocks = React.useMemo(
|
|
5110
5116
|
() => lodashEs.filter(blocks, (block) => lodashEs.isString(parent) ? block._parent === parent : !block._parent),
|
|
5111
5117
|
[blocks, parent]
|
|
5112
5118
|
);
|
|
5113
5119
|
const hasChildren = React.useCallback((block) => lodashEs.filter(blocks, (b) => b._parent === block._id).length > 0, [blocks]);
|
|
5114
5120
|
return lodashEs.map(filteredBlocks, (block) => {
|
|
5115
|
-
|
|
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);
|
|
5116
5124
|
});
|
|
5117
5125
|
};
|
|
5118
5126
|
const PageBlocksRenderer = () => {
|
|
5119
5127
|
const [blocks] = useBlocksStore();
|
|
5120
|
-
|
|
5128
|
+
console.log(jotai.useAtomValue(pageBlocksAtomsAtom));
|
|
5129
|
+
return /* @__PURE__ */ jsxRuntime.jsx(BlocksRenderer, { splitAtoms: pageBlocksAtomsAtom, blocks });
|
|
5121
5130
|
};
|
|
5122
5131
|
const StaticBlocksRenderer = () => {
|
|
5123
5132
|
const [blocks] = useBlocksStore();
|
|
@@ -9102,7 +9111,8 @@ const ChaiBuilderBlocks = ({ groups, blocks, parentId, position, gridCols = "gri
|
|
|
9102
9111
|
position,
|
|
9103
9112
|
block,
|
|
9104
9113
|
disabled: !canAcceptChildBlock(parentType, block.type) || !canBeNestedInside(parentType, block.type)
|
|
9105
|
-
}
|
|
9114
|
+
},
|
|
9115
|
+
block.type
|
|
9106
9116
|
))
|
|
9107
9117
|
) })
|
|
9108
9118
|
] }, group)) }) })
|
package/dist/core.js
CHANGED
|
@@ -1826,14 +1826,16 @@ const useGetBlockAtomValue = (splitAtoms) => {
|
|
|
1826
1826
|
return useAtomCallback(
|
|
1827
1827
|
useCallback(
|
|
1828
1828
|
(get2, _set, idOrAtom) => {
|
|
1829
|
-
const blockAsAtoms = get2(
|
|
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)
|
|
1833
1836
|
);
|
|
1834
1837
|
if (!blockAtom) {
|
|
1835
|
-
|
|
1836
|
-
return;
|
|
1838
|
+
throw new Error(`Block with id ${idOrAtom} not found`);
|
|
1837
1839
|
}
|
|
1838
1840
|
return get2(blockAtom);
|
|
1839
1841
|
},
|
|
@@ -1845,14 +1847,18 @@ const useGetBlockAtom = (splitAtoms) => {
|
|
|
1845
1847
|
return useAtomCallback(
|
|
1846
1848
|
useCallback(
|
|
1847
1849
|
(get2, _set, idOrAtom) => {
|
|
1848
|
-
const blockAsAtoms = get2(splitAtoms
|
|
1850
|
+
const blockAsAtoms = get2(splitAtoms);
|
|
1851
|
+
if (!blockAsAtoms || !blockAsAtoms.length) {
|
|
1852
|
+
console.warn("No blocks available in splitAtoms");
|
|
1853
|
+
return null;
|
|
1854
|
+
}
|
|
1849
1855
|
const blockAtom = find(
|
|
1850
1856
|
blockAsAtoms,
|
|
1851
1857
|
(b) => get2(b)._id === (isString(idOrAtom) ? idOrAtom : get2(idOrAtom)._id)
|
|
1852
1858
|
);
|
|
1853
1859
|
if (!blockAtom) {
|
|
1854
1860
|
console.warn(`Block with id ${idOrAtom} not found`);
|
|
1855
|
-
return;
|
|
1861
|
+
return null;
|
|
1856
1862
|
}
|
|
1857
1863
|
return blockAtom;
|
|
1858
1864
|
},
|
|
@@ -4700,7 +4706,7 @@ const useHandleCanvasDblClick = () => {
|
|
|
4700
4706
|
const updateContent = useUpdateBlocksProps();
|
|
4701
4707
|
const [editingBlockId, setEditingBlockId] = useAtom$1(inlineEditingActiveAtom);
|
|
4702
4708
|
const { clearHighlight } = useBlockHighlight();
|
|
4703
|
-
const getBlockAtomValue = useGetBlockAtomValue();
|
|
4709
|
+
const getBlockAtomValue = useGetBlockAtomValue(pageBlocksAtomsAtom);
|
|
4704
4710
|
return useCallback(
|
|
4705
4711
|
(e2) => {
|
|
4706
4712
|
var _a;
|
|
@@ -5090,19 +5096,22 @@ const BlocksRenderer = ({
|
|
|
5090
5096
|
parent = null,
|
|
5091
5097
|
splitAtoms = void 0
|
|
5092
5098
|
}) => {
|
|
5093
|
-
const
|
|
5099
|
+
const getBlockAtom = useGetBlockAtom(splitAtoms);
|
|
5094
5100
|
const filteredBlocks = useMemo(
|
|
5095
5101
|
() => filter(blocks, (block) => isString(parent) ? block._parent === parent : !block._parent),
|
|
5096
5102
|
[blocks, parent]
|
|
5097
5103
|
);
|
|
5098
5104
|
const hasChildren = useCallback((block) => filter(blocks, (b) => b._parent === block._id).length > 0, [blocks]);
|
|
5099
5105
|
return map(filteredBlocks, (block) => {
|
|
5100
|
-
|
|
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);
|
|
5101
5109
|
});
|
|
5102
5110
|
};
|
|
5103
5111
|
const PageBlocksRenderer = () => {
|
|
5104
5112
|
const [blocks] = useBlocksStore();
|
|
5105
|
-
|
|
5113
|
+
console.log(useAtomValue$1(pageBlocksAtomsAtom));
|
|
5114
|
+
return /* @__PURE__ */ jsx(BlocksRenderer, { splitAtoms: pageBlocksAtomsAtom, blocks });
|
|
5106
5115
|
};
|
|
5107
5116
|
const StaticBlocksRenderer = () => {
|
|
5108
5117
|
const [blocks] = useBlocksStore();
|
|
@@ -9087,7 +9096,8 @@ const ChaiBuilderBlocks = ({ groups, blocks, parentId, position, gridCols = "gri
|
|
|
9087
9096
|
position,
|
|
9088
9097
|
block,
|
|
9089
9098
|
disabled: !canAcceptChildBlock(parentType, block.type) || !canBeNestedInside(parentType, block.type)
|
|
9090
|
-
}
|
|
9099
|
+
},
|
|
9100
|
+
block.type
|
|
9091
9101
|
))
|
|
9092
9102
|
) })
|
|
9093
9103
|
] }, group)) }) })
|