Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Calculator

0

162
Views
I failed to make blocks ordering with BlockManager

Using grapesjs with custom blocks I need

  1. Collapse all, but extend only 1 block
  2. to order them . I managed to make point 1), but searching for decision of point2) I found this branch : https://github.com/artf/grapesjs/issues/780

and I do it as with timer:

let has_opened_block= false
setTimeout(() => {
    console.log('setTimeout::')
    var closedBlocks = ['Templates', 'Blocks', 'Images', 'Basic', 'Extra', 'forms'];  // I need to collapse these blocks and move them to the bottom


    gjsEditor.Blocks.getCategories().forEach(ct => {

        ct.set('open', false);
        if(!has_opened_block) {  // to open only 1st block which is not in closedBlocks                    
            if (!closedBlocks.includes(ct.id)) {
                has_opened_block = true
                ct.set('open', true);
            }
        }
    });



    const bm = gjsEditor.BlockManager;
    var blocksToRender= [ // I want to see these blocks at top
        bm.get('h2'),
        bm.get('d5'),
        bm.get('f4')
    ]
    for (var i=0; i< closedBlocks.length;i++) { // I want to see all blocks which are not in blocksToRender at bottom
        blocksToRender[blocksToRender.length]= bm.get(closedBlocks[i])
    }
    bm.render( blocksToRender )



}, 8000)

But as result I see 9 blocks, but which looks like empty : https://prnt.sc/86w-dqziZakn

Also I can not drag and drop content of these blocks - nothing is dropped.

What is wrong in my blocks ordering ?

Thanks!

7 months ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2023 PeakU Inc. All Rights Reserved.