Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
handle.change((doc) => {
doc.text = new Automerge.Text()
if (text) {
doc.text.insertAt!(0, ...text.split(''))
if (!text || !text.endsWith('\n')) {
doc.text.insertAt!(text ? text.length : 0, '\n') // Quill prefers an ending newline
}
}
})
}
function initializeDocument(doc: TextDoc) {
doc.text = new Automerge.Text()
doc.text.insertAt(0, '\n') // Quill prefers an ending newline.
}
this.crdt = AutoMerge.change(AutoMerge.init(), (doc: any) => {
doc.content = new AutoMerge.Text()
});
}
onChange((doc) => {
doc.text = new Automerge.Text()
doc.text.insertAt(0, ...defaultText.split(''))
})
}
onChange(d => {
d.text = new Automerge.Text()
d.text.insertAt(0, ...text.split(''))
})
}
...updateData(state, data => {
for (let [pathname, { source, codeMirrorDoc }] of Object.entries(files)) {
if (codeMirrorDoc) {
unpersistedCodeMirrorDocs[pathname] = codeMirrorDoc
}
if (!merge) {
data.sources = {}
}
if (typeof source !== 'string') {
data.sources[pathname] = source
} else {
let text = new Text()
if (source.length) {
text.insertAt!(0, ...source)
}
data.sources[pathname] = text
}
}
}),
...(merge
change(doc, draft => {
if (draft.sheets == undefined) draft.sheets = []
draft.sheets.push(new Text())
})
)
const toSync = node => {
if (!node) {
return
}
if (node.hasOwnProperty('text')) {
return {
...node,
text: new Automerge.Text(node.text)
}
} else if (node.nodes) {
return {
...node,
nodes: node.nodes.map(toSync)
}
} else if (node.leaves) {
return {
...node,
leaves: node.leaves.map(toSync)
}
} else if (node.document) {
return {
...node,
document: toSync(node.document)
}
metadata[key].insertAt!(0, ...initialMetadata[key])
}
let staticSourcePathnames = new Set()
let secondarySourcePathnames = new Set(Object.keys(DefaultGeneratedSources))
let sources: { [pathname: string]: Text | DemoboardGeneratedFile } = {
...DefaultGeneratedSources,
}
for (let pathname of Object.keys(initialSources)) {
let source = initialSources[pathname]
if (typeof source === 'string') {
let text = new Text()
text.insertAt!(0, ...initialSources[pathname])
sources[pathname] = text
staticSourcePathnames.add(pathname)
} else {
sources[pathname] = source || new Text()
secondarySourcePathnames.add(pathname)
}
}
let templates: {
[templateName: string]: {
[pathname: string]: string | DemoboardGeneratedFile
}
} = {
initial: initialSources,
...initialTemplates,
}
let indexPathname = Array.from(staticSourcePathnames)
.concat(Array.from(secondarySourcePathnames))
.find(x => indexPathnames.indexOf(x) !== -1)