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
feat: Add unique ids for each block #1493
Conversation
Please, add a description to the PR. What case you're trying to cover? |
I'm sorry this is my negligence, I have added a description |
Awesome. This is exactly what we need to finally use EditorJs for our system. We also need an ID per block for collaboration features and in some special cases to map (save) each block to a separate database record (which is not possible without an identifier). UUIDv4 perfectly fits. Maybe someone needs another "id generator" but this could be added/opened in a later step. So I can't wait to see this feature in EditorJS. 👍 |
Yes, we'd love to have uids assigned for each block. Really important for our commenting use case! |
src/components/block/api.ts
Outdated
@@ -14,6 +14,14 @@ function BlockAPI( | |||
block: Block | |||
): void { | |||
const blockAPI: BlockAPIInterface = { | |||
/** | |||
* Tool 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.
* Tool id | |
* Block id |
src/components/block/index.ts
Outdated
@@ -27,6 +27,11 @@ import SelectionUtils from '../selection'; | |||
* Interface describes Block class constructor argument | |||
*/ | |||
interface BlockConstructorOptions { | |||
/** | |||
* Tool's 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.
* Tool's id | |
* Block's id |
src/components/block/index.ts
Outdated
@@ -107,6 +112,11 @@ export default class Block { | |||
}; | |||
} | |||
|
|||
/** | |||
* unique identifier |
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.
* unique identifier | |
* Block unique identifier |
types/api/block.d.ts
Outdated
@@ -5,6 +5,11 @@ import {SavedData} from '../data-formats'; | |||
* @interface BlockAPI Describes Block API methods and properties | |||
*/ | |||
export interface BlockAPI { | |||
/** | |||
* Tool name |
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.
* Tool name | |
* Block unique identifier |
src/components/utils.ts
Outdated
* | ||
* @returns {string} | ||
*/ | ||
export function generateUuidv4(): 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.
I think it would be better to name this method just as generateId()
and make UUIDv4
"private". E.g.
export function generateId(): string {
return uuidv4();
}
function uuidv4(): string {
// your code
}
so that we could change the id generator algorithm
src/components/modules/paste.ts
Outdated
@@ -759,7 +759,7 @@ export default class Paste extends Module { | |||
* | |||
* @returns {void} | |||
*/ | |||
private insertEditorJSData(blocks: Array<Pick<SavedData, 'data' | 'tool'>>): void { | |||
private insertEditorJSData(blocks: Array<Pick<SavedData, 'id' | 'data' | 'tool'>>): void { |
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
seems unused.
private insertEditorJSData(blocks: Array<Pick<SavedData, 'id' | 'data' | 'tool'>>): void { | |
private insertEditorJSData(blocks: Array<Pick<SavedData, 'data' | 'tool'>>): void { |
I think it's better to use |
Should we close the ancestor PR #1333 with respects? |
|
The uniqueness of block ids will be scoped by the single entry. So I think that collision of ids of blocks inside one entry will be rare. |
Thanks for your suggestions, you are right, I will modify and submit again, thanks! |
* @returns {string} | ||
*/ | ||
export function generateBlockId(): string { | ||
return uuidv4(); |
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.
Check this comment please #1493 (comment)
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.
Ok i will change to nano(10)
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.
@cobbcheng need any help on this?
// the project's config changing) | ||
|
||
/** | ||
* @type {Cypress.PluginConfig} |
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 supposed to be here?
Why is this considered "not ready"? Something I can help with? We would also like to use Editor.js but we are stuck because we cannot merge edits from different users. |
I'd like to help too. |
Question: |
Closing due more relevant #1667 |
When editing documents collaboratively, we usually need a unique id to save and identify the current block. This PR is modified and resubmitted based on this #1333 , because this PR is no longer maintained
I'm adressing #873 with this PR.
Tested Features:
Important Note:
If you "transform/transition" an existing block to another block it will receive a NEW unique id