Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to retrieve block data? #2629

Open
mustson opened this issue Feb 21, 2024 · 1 comment
Open

How to retrieve block data? #2629

mustson opened this issue Feb 21, 2024 · 1 comment

Comments

@mustson
Copy link

mustson commented Feb 21, 2024

// Retrieve block details once and use throughout
const block = this.api.blocks.getBlockByIndex(blockIndex);

        console.log('Block data:', block.data, 'Block index:', blockIndex);
        if (!block || !block.id) {
            throw new Error('No valid ID for the current block.');
        }

        const originalText = block.data?.text; // Using optional chaining for safety
        console.log(block);
        
        Block data is undefined, how do I retrieve the contents of a block, such as the text of a paragraph of heading? Or a list content?
@mustson
Copy link
Author

mustson commented Feb 21, 2024

Data is undefined at constructor,

export default class MyBlockTune { static get isTune() { return true; } constructor({ api, data, config, block }) { this.api = api; this.data = data; this.config = config; this.block = block; console.log('Constructor called'); console.log('Constructor data:', data); console.log('Constructor block:', block); // Set up a listener for when the block data might change }

why?!

here is the initiation:

`const editor = new EditorJS({
                holder: 'editorjs',
                data: {
                    blocks: articleBlocks,
                },
                tools: {
                    myBlockTune: {
                        class: MyBlockTune,
                        config: {
                            // Important: Does your tune need specific data to work?
                            // Example
                        },
                    },
                    header: {
                        class: Header,
                    },
                    paragraph: {
                        class: Paragraph,
                        tunes: ['myBlockTune'], // Add the tune to the header tool
                    },
                    list: List,
                    image: Image,

                    // Add more tools as needed
                },
            });`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant