First steps to creating a new node
This commit is contained in:
parent
1ce8e29e37
commit
989542be91
6 changed files with 101 additions and 44 deletions
|
|
@ -342,11 +342,11 @@ export class NodeUINative {
|
|||
this.render()
|
||||
})
|
||||
|
||||
_mbus.subscribe('NODE_MODIFIED', ()=>{
|
||||
_mbus.subscribe('NODE_MODIFIED', () => {
|
||||
document.querySelector('#crumbs .crumbs')?.classList.add('node-modified')
|
||||
})
|
||||
|
||||
_mbus.subscribe('NODE_UNMODIFIED', ()=>{
|
||||
_mbus.subscribe('NODE_UNMODIFIED', () => {
|
||||
document.querySelector('#crumbs .crumbs')?.classList.remove('node-modified')
|
||||
})
|
||||
}// }}}
|
||||
|
|
@ -359,7 +359,7 @@ export class NodeUINative {
|
|||
</div>
|
||||
`
|
||||
|
||||
tmpl.content.querySelector('#node-content').addEventListener('input', event=>this.contentChanged(event))
|
||||
tmpl.content.querySelector('#node-content').addEventListener('input', event => this.contentChanged(event))
|
||||
|
||||
return tmpl.content
|
||||
}// }}}
|
||||
|
|
@ -392,7 +392,20 @@ export class Node {
|
|||
if (a.data.Name > b.data.Name) return 0
|
||||
return 0
|
||||
}//}}}
|
||||
static create(name, parentUUID) {
|
||||
return new Node({
|
||||
UUID: uuidv7(),
|
||||
Created: (new Date()).toISOString(),
|
||||
Content: '',
|
||||
Name: name,
|
||||
ParentUUID: parentUUID,
|
||||
Markdown: false,
|
||||
History: false,
|
||||
})
|
||||
}
|
||||
|
||||
constructor(nodeData, level) {//{{{
|
||||
|
||||
this.Level = level
|
||||
this.data = nodeData
|
||||
this.UUID = nodeData.UUID
|
||||
|
|
@ -525,4 +538,30 @@ export class Node {
|
|||
}//}}}
|
||||
}
|
||||
|
||||
function uuidv7() {
|
||||
// random bytes
|
||||
const value = new Uint8Array(16)
|
||||
crypto.getRandomValues(value)
|
||||
|
||||
// current timestamp in ms
|
||||
const timestamp = BigInt(Date.now())
|
||||
|
||||
// timestamp
|
||||
value[0] = Number((timestamp >> 40n) & 0xffn)
|
||||
value[1] = Number((timestamp >> 32n) & 0xffn)
|
||||
value[2] = Number((timestamp >> 24n) & 0xffn)
|
||||
value[3] = Number((timestamp >> 16n) & 0xffn)
|
||||
value[4] = Number((timestamp >> 8n) & 0xffn)
|
||||
value[5] = Number(timestamp & 0xffn)
|
||||
|
||||
// version and variant
|
||||
value[6] = (value[6] & 0x0f) | 0x70
|
||||
value[8] = (value[8] & 0x3f) | 0x80
|
||||
|
||||
const str = Array.from(value)
|
||||
.map((b) => b.toString(16).padStart(2, "0"))
|
||||
.join("")
|
||||
return `${str.slice(0, 8)}-${str.slice(8, 12)}-${str.slice(12, 16)}-${str.slice(16, 20)}-${str.slice(20)}`
|
||||
}
|
||||
|
||||
// vim: foldmethod=marker
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue