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" ;
16
3
import { useAtom } from "jotai" ;
17
4
import { useTranslation } from "react-i18next" ;
18
5
import {
@@ -29,13 +16,13 @@ import { CoreBlock } from "./CoreBlock";
29
16
import { showPredefinedBlockCategoryAtom } from "../../../../atoms/ui" ;
30
17
import { useBlocksStore , useBuilderProp } from "../../../../hooks" ;
31
18
import ImportHTML from "./ImportHTML" ;
32
- import { useChaiBlocks } from "@chaibuilder/runtime" ;
33
19
import { mergeClasses , UILibraries } from "../../../../main" ;
34
20
import { canAcceptChildBlock , canBeNestedInside } from "../../../../functions/block-helpers.ts" ;
21
+ import { DefaultChaiBlocks } from "./DefaultBlocks.tsx" ;
35
22
36
23
const CORE_GROUPS = [ "basic" , "typography" , "media" , "layout" , "form" , "advanced" , "other" ] ;
37
24
38
- export const ChaiBuilderBlocks = ( { groups, blocks, parentId } : any ) => {
25
+ export const ChaiBuilderBlocks = ( { groups, blocks, parentId, gridCols = "grid-cols-4" } : any ) => {
39
26
const { t } = useTranslation ( ) ;
40
27
const [ allBlocks ] = useBlocksStore ( ) ;
41
28
const parentType = find ( allBlocks , ( block ) => block . _id === parentId ) ?. _type ;
@@ -50,7 +37,7 @@ export const ChaiBuilderBlocks = ({ groups, blocks, parentId }: any) => {
50
37
{ capitalize ( t ( group . toLowerCase ( ) ) ) }
51
38
</ AccordionTrigger >
52
39
< 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 } >
54
41
{ React . Children . toArray (
55
42
reject ( filter ( values ( blocks ) , { group } ) , { hidden : true } ) . map ( ( block ) => {
56
43
return (
@@ -84,23 +71,8 @@ const AddBlocksPanel = ({
84
71
} ) => {
85
72
const { t } = useTranslation ( ) ;
86
73
const [ tab , setTab ] = useState < string > ( "library" ) ;
87
- const [ active , setActive ] = useState < string > ( "basic" ) ;
88
- const allChaiBlocks = useChaiBlocks ( ) ;
89
74
const [ , setCategory ] = useAtom ( showPredefinedBlockCategoryAtom ) ;
90
75
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
-
104
76
return (
105
77
< div className = { mergeClasses ( "flex h-full w-full flex-col overflow-hidden" , className ) } >
106
78
{ showHeading ? (
@@ -129,7 +101,7 @@ const AddBlocksPanel = ({
129
101
{ tab === "core" && (
130
102
< ScrollArea className = "-mx-1.5 h-[calc(100vh-156px)] overflow-y-auto" >
131
103
< div className = "mt-2 w-full" >
132
- < ChaiBuilderBlocks parentId = { parentId } groups = { uniqueTypeGroup } blocks = { groupedBlocks . core } />
104
+ < DefaultChaiBlocks gridCols = { "grid-cols-4" } parentId = { parentId } />
133
105
</ div >
134
106
</ ScrollArea >
135
107
) }
0 commit comments