Files
tools/vue/writekit/src/model/id.ts
T
robonen 263c32002f feat(writekit): rename @robonen/editor to @robonen/writekit
Rename the rich-text editor package and all Editor* exports to Writekit*;
remove the old vue/editor tree.
2026-06-15 16:54:06 +07:00

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)}`;
}