Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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 update some blocks, not all. #1074

Closed
hughfenghen opened this issue Mar 21, 2020 · 10 comments
Closed

How to update some blocks, not all. #1074

hughfenghen opened this issue Mar 21, 2020 · 10 comments

Comments

@hughfenghen
Copy link

hughfenghen commented Mar 21, 2020

Hi, i know editor.render() can update all blocks, Is there any way to update only a certain block?

I see from the source that BlockMananger may be able to do it, but it is not a public API.

If editor.js can get or update specific blocks, it may be beneficial for collaborative editing and performance.

@gohabereg
Copy link
Member

Hi @hughfenghen
We gonna export some Block API soon

@hughfenghen
Copy link
Author

@gohabereg Good, thanks~

@gohabereg
Copy link
Member

Hi @hughfenghen

I've opened a #1075 PR with Block API.

However, at the moment we can't provide a method to update a certain block, as data passed to the Tool constructor. So to update it, we need to construct the new Block with updated data and replace the old one. I don't think this approach is the best one, so we need to design a block update flow and describe it with APIs and docs.

@taurenshaman
Copy link

I tried to refactor some code from render method. But when I click Edit from settings part, the edit UI show and hide immediately and show the rendered result. Maybe I should wait for the new feature?
ezgif-6-f6df70aabf40

scenario: a textarea to edit KaTeX.

here is the js file: https://gist.github.com/taurenshaman/3cd1dc489defe2999c27fdcc1140ceea

demo: https://taurenshaman.github.io/demo/editor@codexteam+katex.html?v=3

@romanKrds
Copy link

Hi @hughfenghen

I've opened a #1075 PR with Block API.

However, at the moment we can't provide a method to update a certain block, as data passed to the Tool constructor. So to update it, we need to construct the new Block with updated data and replace the old one. I don't think this approach is the best one, so we need to design a block update flow and describe it with APIs and docs.

Hi @gohabereg. Thanks a lot for the PR! That's exactly what I need. Only one question, how can I use it? I tried to call updated insert method with new arguments, but get an error: "Cannot read property 'config' of undefined". Could you take a look at the stackblits example? Thanks in advance!

https://stackblitz.com/edit/angular-editorjs-insert?file=src%2Fapp%2Fapp.component.ts

@gaona233
Copy link

Hi @hughfenghen

I've opened a #1075 PR with Block API.

However, at the moment we can't provide a method to update a certain block, as data passed to the Tool constructor. So to update it, we need to construct the new Block with updated data and replace the old one. I don't think this approach is the best one, so we need to design a block update flow and describe it with APIs and docs.

is there any way to solve this problem

@milu2003
Copy link

i need it too

@hata6502
Copy link
Contributor

👀

@milu2003
Copy link

milu2003 commented Mar 20, 2021

2021-03-20.11.49.39.mov

If you update all the blocks, the page will jump, so the user experience is very bad

let block_data = await this.editor.save();
block_data = _.cloneDeep(block_data);
let find_index = _.findIndex(block_data.blocks, x => {
  return x.data.meta_data._id == a.data.meta_data._id;
});
let old_info = block_data.blocks[find_index];
let new_data = _.cloneDeep(old_info);
new_data.data = _.cloneDeep(a.data);
block_data.blocks[find_index] = new_data;
this.editor.blocks.render(block_data);

Is there any way to execute a plug-in function from the outside? For example, a function of the plug-in is responsible for local updates, rather than re rendering the entire component

@gohabereg

@hata6502
Copy link
Contributor

I think this is a good feature request!
It also related to editorjs-undo: #518

I approach to use the diff library: https://github.com/kpdecker/jsdiff

@codex-team codex-team locked and limited conversation to collaborators Jan 17, 2022
@talyguryn talyguryn converted this issue into discussion #1877 Jan 17, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants