How to use the slate.Raw.serialize function in slate

To help you get started, we’ve selected a few slate 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 orbiting / publikator-frontend / lib / github / components / Editor / index.js View on Github external
documentChangeHandler (_, newEditorState) {
    const { data: { repository }, path, uncommittedChangesMutation } = this.props
    const { committedEditorState, uncommittedChanges } = this.state

    const serializedNewEditorState = Raw.serialize(newEditorState, {terse: true})
    const serializedCommittedEditorState = Raw.serialize(committedEditorState, {terse: true})
    if (JSON.stringify(serializedNewEditorState) !== JSON.stringify(serializedCommittedEditorState)) {
      this.store.set('editorState', serializedNewEditorState)
      this.store.set('commit', repository.commit)

      if (!uncommittedChanges) {
        this.setState({
          uncommittedChanges: true
        })
        uncommittedChangesMutation({
          login: repository.owner.login,
          repository: repository.name,
          path: path.split('/').slice(1).join('/'), // omit branch
          action: 'create'
        }).catch((error) => {
          console.log('uncommittedChangesMutation error')
github olymp / olymp / packages / slate / editor-decorators / state.tsx View on Github external
changeValue = (value) => {
        const { onChangeHeadings } = this.props;
        this.value = value;
        this.forceUpdate();
        if (changeValue) {
          const rawValue = Raw.serialize(value, { terse });
          if (JSON.stringify(this.rawValue) !== JSON.stringify(rawValue)) {
            this.rawValue = rawValue;
            this.batch(() => {
              // Flatten & filter
              const flattenNodes = (nodes, level = 0) =>
                nodes.reduce((arr, node) => {
                  const { type, kind, text } = node;
                  let newArr = [...arr];
                  const newNode = { ...node };
                  if (newNode.nodes) {
                    newArr = arr.concat(flattenNodes(newNode.nodes, level + 1));
                    delete newNode.nodes;
                  }

                  // Filter empty Blocks
                  if (
github orbiting / publikator-frontend / lib / editor / components / Editor.js View on Github external
onChange (state) {
    console.log(Raw.serialize(state, { terse: true }))
    this.setState(() => ({
      state
    }))
  }
github aranja / tux / packages / tux / src / components / fields / RichTextField.tsx View on Github external
onChange = async () => {
    const { onEditorChange, editorState, onChange, id } = this.props
    onEditorChange(editorState)
    onChange(Raw.serialize(editorState), id)
  }
github bkniffler / slate-mate / src / editor-decorators / state.js View on Github external
changeValue = value => {
      this.value = value;
      this.forceUpdate();
      if (changeValue) {
        const rawValue = Raw.serialize(value, { terse });
        if (JSON.stringify(this.rawValue) !== JSON.stringify(rawValue)) {
          this.rawValue = rawValue;
          this.batch(() => changeValue(this.props, rawValue));
        }
      }
    }
github aranja / tux / addons / admin / src / slate / serializers / serialize.ts View on Github external
function serialize(state: State, format: Format = 'raw'): any {
  switch (format) {
    case 'raw':
      return Raw.serialize(state, { terse: true })
    case 'html':
      return Html.serialize(state)
    case 'plain':
      return Plain.serialize(state)
    default:
      throw new Error(`Don't know how to deserialize ${format}`)
  }
}