How to use the automerge.Text function in automerge

To help you get started, we’ve selected a few automerge examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github inkandswitch / pushpin / src / renderer / components / content-types / TextContent.tsx View on Github external
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
      }
    }
  })
}
github inkandswitch / pushpin / src / renderer / components / TextContent.tsx View on Github external
function initializeDocument(doc: TextDoc) {
  doc.text = new Automerge.Text()
  doc.text.insertAt(0, '\n') // Quill prefers an ending newline.
}
github fluid-notion / fluid-outliner / core / models / EmbeddedCRDTFile.ts View on Github external
this.crdt = AutoMerge.change(AutoMerge.init(), (doc: any) => {
                doc.content = new AutoMerge.Text()
            });
        }
github inkandswitch / pushpin / src / components / playground.jsx View on Github external
onChange((doc) => {
      doc.text = new Automerge.Text()
      doc.text.insertAt(0, ...defaultText.split(''))
    })
  }
github inkandswitch / pushpin / src / components / code-mirror-editor.jsx View on Github external
onChange(d => {
      d.text = new Automerge.Text()
      d.text.insertAt(0, ...text.split(''))
    })
  }
github frontarm / demoboard / packages / demoboard-core / src / project / demoboardProjectReducer.ts View on Github external
...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
github aslakhellesoy / automerge-codemirror / stories / components / PadComponent.tsx View on Github external
change(doc, draft => {
        if (draft.sheets == undefined) draft.sheets = []
        draft.sheets.push(new Text())
      })
    )
github cudr / slate-collaborative / packages / bridge / src / utils / toSync.ts View on Github external
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)
    }
github frontarm / demoboard / packages / demoboard-core / src / project / createInitialDemoboardProjectState.ts View on Github external
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)