How to use the slate.Raw.deserialize 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
if (!this.store) {
      this.store = initLocalStore(getLocalStorageKey(repository, view, path))
      if (!this.store.supported) {
        this.setState({
          localStorageNotSupported: true
        })
      }
    }

    let committedEditorState
    if (view === 'new') {
      committedEditorState = Raw.deserialize(blank, {terse: true})
    } else {
      try {
        const json = JSON.parse(repository.blob.text)
        committedEditorState = Raw.deserialize(json, {terse: true})
      } catch (e) {
        console.log('parsing error', e)
      }
    }

    let localState = this.store.getAll()
    let localEditorState
    if (localState && localState.editorState && localState.commit) {
      try {
        localEditorState = Raw.deserialize(localState.editorState, {terse: true})
      } catch (e) {
        console.log('parsing error', e)
      }
    }

    if (localEditorState) {
github olymp / olymp / packages / slate / editor-decorators / state.tsx View on Github external
const parseValue = (v, initialState, terse) => {
  resetKeyGenerator();
  if (!v) {
    return Plain.deserialize('');
  }
  const value = JSON.parse(JSON.stringify(v));
  try {
    return Raw.deserialize(value, { terse });
  } catch (err1) {
    try {
      return Raw.deserialize(value, { terse: !terse });
    } catch (err2) {
      console.error('Couldnt parse value in slate', err1, err2);
      return initialState
        ? parseValue(initialState, undefined, { terse })
        : Plain.deserialize('');
    }
  }
};
github olymp / olymp / packages / slate / editor-decorators / state.js View on Github external
var parseValue = function (v, initialState, terse) {
    resetKeyGenerator();
    if (!v) {
        return Plain.deserialize('');
    }
    var value = JSON.parse(JSON.stringify(v));
    try {
        return Raw.deserialize(value, { terse: terse });
    }
    catch (err1) {
        try {
            return Raw.deserialize(value, { terse: !terse });
        }
        catch (err2) {
            console.error('Couldnt parse value in slate', err1, err2);
            return initialState
                ? parseValue(initialState, undefined, { terse: terse })
                : Plain.deserialize('');
        }
    }
};
var defaultGetValue = function (_a) {
github olymp / olymp / src / slate / editor-decorators / state.js View on Github external
const parseValue = (v, initialState, terse) => {
  resetKeyGenerator();
  if (!v) return Plain.deserialize('');
  const value = JSON.parse(JSON.stringify(v));
  try { return Raw.deserialize(value, { terse }); }
  catch (err1) {
    try { return Raw.deserialize(value, { terse: !terse }); }
    catch (err2) {
      console.error('Couldnt parse value in slate', err1, err2);
      return initialState ? parseValue(initialState, undefined, { terse }) : Plain.deserialize('');
    }
  }
};
github freedomexio / rocketx-condenser / src / app / components / elements / SlateEditor.jsx View on Github external
export const getDemoState = () => Raw.deserialize(demoState, { terse: true });
github olymp / olymp / src / cms / slate / editor-decorators / state.js View on Github external
const parseValue = (value, initialState, terse) => {
  resetKeyGenerator();
  try { return Raw.deserialize(value, { terse }); }
  catch(err) {
    try { return Raw.deserialize(value, { terse: !terse }); }
    catch(err) {
      return initialState ? parseValue(initialState, undefined, { terse }) : Plain.deserialize('');
    }
  }
};
const defaultGetValue = ({ value }) => value;
github bkniffler / slate-mate / src / editor-decorators / state.js View on Github external
const parseValue = (value, initialState, terse) => {
  try { return Raw.deserialize(value, { terse }); }
  catch (err) {
    try { return Raw.deserialize(value, { terse: !terse }); }
    catch(err){
      return initialState ? Raw.deserialize(initialState, { terse }) : Plain.deserialize('');
    }
  }
};
const defaultGetValue = ({ value }) => value;
github bkniffler / slate-mate / src / editor-decorators / state.js View on Github external
const parseValue = (value, initialState, terse) => {
  try { return Raw.deserialize(value, { terse }); }
  catch (err) {
    try { return Raw.deserialize(value, { terse: !terse }); }
    catch(err){
      return initialState ? Raw.deserialize(initialState, { terse }) : Plain.deserialize('');
    }
  }
};
const defaultGetValue = ({ value }) => value;
github iamtekeste / type-hero / src / components / TextEditor.js View on Github external
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { Editor, Raw } from 'slate';

const initialState = Raw.deserialize({
  nodes: [
    {
      kind: 'block',
      type: 'paragraph',
      nodes: [
        {
          kind: 'text',
          text: '',
        },
      ],
    },
  ],
}, { terse: true });

export default class TextEditor extends Component {
  constructor(props) {
github jakoblo / ufo / src / js / view-folder / view-folder-editor / folder-editor-actions.js View on Github external
.then(fileContent => {
          let editorState = Raw.deserialize(JSON.parse(fileContent), {
            terse: true
          });
          editorState = mapFilesToEditorState(fileList, editorState);

          dispatch({
            type: t.FOLDER_EDITOR_INIT,
            payload: {
              path: path,
              editorState: editorState
            }
          });
        });
    } else {