How to use the slate.Plain.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 olymp / olymp / src / slate / editor.js View on Github external
render = () => {
    const { children, showUndo, onChange, readOnly, marks, nodes, plugins, className, spellcheck, style, blockTypes, ...rest } = this.props;
    const value = this.props.value || Plain.deserialize('');

    const undo = !!value && !!value.history && !!value.history.undos && !!value.history.undos['_head'] && value.history.undos['_head'].value;
    // console.log(undo);

    return (
      <div style="{{">
        
          {false &amp;&amp; undo &amp;&amp; undo.length ? (
            <button size="large" shape="circle"> onChange(value.transform().undo().apply())}&gt;
              <i aria-hidden="true">
            </i></button><i aria-hidden="true">
          ) : null}
        </i><i aria-hidden="true">
        {children}
        {readOnly !== true &amp;&amp; }
        {readOnly !== true &amp;&amp; }</i></div>
github withspectrum / slate-markdown / example / src / App.js View on Github external
constructor(props) {
    super(props);
    // Create markdown plugin
    const markdown = MarkdownPlugin();

    this.state = {
      state: Plain.deserialize(
        '# slate-markdown\nAdd **live markdown preview** to your Slate editor.\n## Usage\n### Installation\n`npm install slate-markdown`\n### Demo\nThis is a [Slate editor](https://slatejs.org) with the plugin enabled, try typing some markdown in here!\n## Links\n- Contribute on [GitHub](https://github.com/withspectrum/slate-markdown)\n- Made by the folks at [Spectrum](https://spectrum.chat)'
      ),
      plugins: [markdown],
    };
  }
github aranja / tux / addons / admin / src / slate / serializers / deserialize.ts View on Github external
return null
  }

  // Always handle raw values.
  // Make it easier to migrate between raw and html.
  if (typeof value === 'object' && value.nodes) {
    return Raw.deserialize(value, { terse: true })
  }

  if (typeof value !== 'string') {
    return null
  }

  switch (format) {
    case 'plain':
      return Plain.deserialize(value)
    // If value is string and format raw,
    case 'raw':
    case 'html':
      return Html.deserialize(value)
    default:
      throw new Error(`Don't know how to deserialize ${format}`)
  }
}
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 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('');
        }
    }
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 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 sanity-io / sanity / packages / @sanity / block-editor / src / Syncer.js View on Github external
constructor(props, ...rest) {
    super(props, ...rest)
    const empty = Plain.deserialize('')
    this.state = {
      slateState: empty.set('document', props.value.document)
    }
  }