Skip to content

Commit 5943057

Browse files
committed
feat: added DefaultChaiBlocks to sdk export
1 parent 781e242 commit 5943057

File tree

4 files changed

+25
-35
lines changed

4 files changed

+25
-35
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"author": "Suraj Air",
66
"license": "BSD-3-Clause",
77
"homepage": "https://chaibuilder.com",
8-
"version": "1.2.80",
8+
"version": "1.2.81",
99
"type": "module",
1010
"repository": {
1111
"type": "git",

src/core/components/sidepanels/panels/add-blocks/AddBlocks.tsx

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
1-
import React, { useEffect, useState } from "react";
2-
import {
3-
capitalize,
4-
filter,
5-
find,
6-
first,
7-
groupBy,
8-
includes,
9-
isEmpty,
10-
map,
11-
reject,
12-
sortBy,
13-
uniq,
14-
values,
15-
} from "lodash-es";
1+
import React, { useState } from "react";
2+
import { capitalize, filter, find, map, reject, sortBy, values } from "lodash-es";
163
import { useAtom } from "jotai";
174
import { useTranslation } from "react-i18next";
185
import {
@@ -29,13 +16,13 @@ import { CoreBlock } from "./CoreBlock";
2916
import { showPredefinedBlockCategoryAtom } from "../../../../atoms/ui";
3017
import { useBlocksStore, useBuilderProp } from "../../../../hooks";
3118
import ImportHTML from "./ImportHTML";
32-
import { useChaiBlocks } from "@chaibuilder/runtime";
3319
import { mergeClasses, UILibraries } from "../../../../main";
3420
import { canAcceptChildBlock, canBeNestedInside } from "../../../../functions/block-helpers.ts";
21+
import { DefaultChaiBlocks } from "./DefaultBlocks.tsx";
3522

3623
const CORE_GROUPS = ["basic", "typography", "media", "layout", "form", "advanced", "other"];
3724

38-
export const ChaiBuilderBlocks = ({ groups, blocks, parentId }: any) => {
25+
export const ChaiBuilderBlocks = ({ groups, blocks, parentId, gridCols = "grid-cols-4" }: any) => {
3926
const { t } = useTranslation();
4027
const [allBlocks] = useBlocksStore();
4128
const parentType = find(allBlocks, (block) => block._id === parentId)?._type;
@@ -50,7 +37,7 @@ export const ChaiBuilderBlocks = ({ groups, blocks, parentId }: any) => {
5037
{capitalize(t(group.toLowerCase()))}
5138
</AccordionTrigger>
5239
<AccordionContent className="mx-auto max-w-xl p-3">
53-
<div className="grid grid-cols-4 gap-2">
40+
<div className={"grid gap-2 " + gridCols}>
5441
{React.Children.toArray(
5542
reject(filter(values(blocks), { group }), { hidden: true }).map((block) => {
5643
return (
@@ -84,23 +71,8 @@ const AddBlocksPanel = ({
8471
}) => {
8572
const { t } = useTranslation();
8673
const [tab, setTab] = useState<string>("library");
87-
const [active, setActive] = useState<string>("basic");
88-
const allChaiBlocks = useChaiBlocks();
8974
const [, setCategory] = useAtom(showPredefinedBlockCategoryAtom);
9075
const importHTMLSupport = useBuilderProp("importHTMLSupport", true);
91-
const filterChaiBlock = useBuilderProp("filterChaiBlock", () => true);
92-
const chaiBlocks = filter(allChaiBlocks, filterChaiBlock);
93-
94-
const groupedBlocks = groupBy(chaiBlocks, "category") as Record<string, any[]>;
95-
const uniqueTypeGroup = uniq(map(groupedBlocks.core, "group"));
96-
97-
// * setting active tab if not already selected from current unique list
98-
useEffect(() => {
99-
if (!includes(uniqueTypeGroup, active) && !isEmpty(uniqueTypeGroup) && !isEmpty(active)) {
100-
setActive(first(uniqueTypeGroup) as string);
101-
}
102-
}, [uniqueTypeGroup, active]);
103-
10476
return (
10577
<div className={mergeClasses("flex h-full w-full flex-col overflow-hidden", className)}>
10678
{showHeading ? (
@@ -129,7 +101,7 @@ const AddBlocksPanel = ({
129101
{tab === "core" && (
130102
<ScrollArea className="-mx-1.5 h-[calc(100vh-156px)] overflow-y-auto">
131103
<div className="mt-2 w-full">
132-
<ChaiBuilderBlocks parentId={parentId} groups={uniqueTypeGroup} blocks={groupedBlocks.core} />
104+
<DefaultChaiBlocks gridCols={"grid-cols-4"} parentId={parentId} />
133105
</div>
134106
</ScrollArea>
135107
)}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { useChaiBlocks } from "@chaibuilder/runtime";
2+
import { useBuilderProp } from "../../../../hooks";
3+
import { ChaiBuilderBlocks } from "./AddBlocks.tsx";
4+
import { filter, groupBy, map, uniq } from "lodash-es";
5+
6+
export const DefaultChaiBlocks = ({ parentId, gridCols = "grid-cols-2" }: { parentId?: string; gridCols?: string }) => {
7+
const allChaiBlocks = useChaiBlocks();
8+
const filterChaiBlock = useBuilderProp("filterChaiBlock", () => true);
9+
const chaiBlocks = filter(allChaiBlocks, filterChaiBlock);
10+
11+
const groupedBlocks = groupBy(chaiBlocks, "category") as Record<string, any[]>;
12+
const uniqueTypeGroup = uniq(map(groupedBlocks.core, "group"));
13+
14+
return (
15+
<ChaiBuilderBlocks gridCols={gridCols} parentId={parentId} groups={uniqueTypeGroup} blocks={groupedBlocks.core} />
16+
);
17+
};

src/core/main/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export { emitChaiBuilderMsg, useChaiBuilderMsgListener, CHAI_BUILDER_EVENTS } fr
1414
export { AISetContext, AIUserPrompt } from "../components/AskAi.tsx";
1515
export { BlockAttributesEditor } from "../components/settings/new-panel/BlockAttributesEditor.tsx";
1616
export { ChaiBuilderEditor } from "./ChaiBuilderEditor";
17+
export { DefaultChaiBlocks } from "../components/sidepanels/panels/add-blocks/DefaultBlocks.tsx";
1718
export { DarkMode as DarkModeSwitcher } from "../components/canvas/topbar/DarkMode.tsx";
1819
export { Breakpoints as ScreenSizes } from "../components/canvas/topbar/Breakpoints.tsx";
1920
export { UndoRedo } from "../components/canvas/topbar/UndoRedo.tsx";

0 commit comments

Comments
 (0)