263c32002f
Rename the rich-text editor package and all Editor* exports to Writekit*; remove the old vue/editor tree.
14 lines
601 B
TypeScript
14 lines
601 B
TypeScript
/**
|
|
* Stable, collision-resistant identifier for blocks. Block ids survive
|
|
* split/merge/move and are how positions, selections, and the CRDT address a
|
|
* block — so they must be unique and never reused.
|
|
*/
|
|
export function createId(): string {
|
|
if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function')
|
|
return crypto.randomUUID();
|
|
|
|
// Fallback for exotic runtimes without WebCrypto (Node >= 19 and all target
|
|
// browsers provide `crypto.randomUUID`, so this is effectively dead code).
|
|
return `b-${Math.random().toString(36).slice(2)}-${Date.now().toString(36)}`;
|
|
}
|