-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Add unique ids for each block #1333
Add unique ids for each block #1333
Conversation
I need this feature pls merge |
d38c047
to
31f120d
Compare
Updated this PR and fixed conflicts. Is there any update about unique block ids? How do you want to proceed with this issue/feature? |
Does this handle creating a new id when copying a block and pasting it as a new block? Initialise empty editor, type a para block, CMD+A (selects all the blocks. In our case the para block), CMD+V. Would the newly pasted block have a new id? |
@sis-dk thanks for spotting the copy & paste issue. I have adressed this in my latest commit |
Why don't use shortid for id generation? Just want to keep consistent. |
I have used this feature on a custom build since 2.15.2 with UUIDs. Now I wanted to update for latest >2.18+ version and simply ported this feature with UUIDs. I think we could also add some custom configuration/callback to generate the IDs in a different way. Since One editor will not have quadrillions of entries I could imageine that shortids are pretty valid too 👍 Maybe the maintainers (@neSpecc, @khaydarov, @gohabereg) could give a statement about this. I'm fine to add some custom configuration/callback to support custom-ids instead of hardcoded uuids. |
const savedData = await Promise.all( | ||
this.selectedBlocks.map((block) => { | ||
block.id = _.generateUuidv4(); | ||
block.save(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
block.save(); | |
return block.save(); |
const savedData
is void[]
currently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So copy paste functions via this.Editor.Paste.MIME_TYPE
is not worked.
const savedData = await Promise.all(this.selectedBlocks.map((block) => block.save())); | ||
const savedData = await Promise.all( | ||
this.selectedBlocks.map((block) => { | ||
block.id = _.generateUuidv4(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
block.id = _.generateUuidv4(); | |
const savedData = await Promise.all(this.selectedBlocks.map(async (block) => ({ | |
...await block.save(), | |
id: _.generateUuidv4() | |
}))); |
block.id = _.generateUuidv4();
may be unsafe because of object mutation.
block.id = _.generateUuidv4(); | ||
block.save(); | ||
}) | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file changes may be not needed because IDs should be regenerated in paste function.
@@ -772,6 +772,7 @@ export default class Paste extends Module { | |||
} | |||
|
|||
BlockManager.insert({ | |||
id, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
id, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The IDs of pasted data via this.Editor.Paste.MIME_TYPE
should be regenerated in paste function.
When copy as this.Editor.Paste.MIME_TYPE
one time and pasted multiple times, The IDs are duplicated.
/** | ||
* Unique Id of the block | ||
*/ | ||
id: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
id: string; | |
id?: string; |
By allowing undefined value, This PR become UNBREAKING Change.
@@ -63,12 +65,14 @@ export default class Renderer extends Module { | |||
*/ | |||
public async insertBlock(item: OutputBlockData): Promise<void> { | |||
const { Tools, BlockManager } = this.Editor; | |||
const id = item.id || _.generateUuidv4(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const id = item.id || _.generateUuidv4(); | |
const id = item.id; |
When const id
is undefined, a new ID is generated in BlockManager.insert()
.
I need this feature pls merge @christoph-kluge 🙏 |
Resolved by #1667 |
I'm adressing #873 with this PR.
Tested Features:
Important Note: