How to use the slate.Value.fromJSON 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 este / este / components / editor / Editor.js View on Github external
const [value, setValue] = useState(() => {
    const model = elementsToSlateValue(
      page.element.id,
      elements,
      componentsById,
    );
    // For SSR.
    KeyUtils.resetGenerator();
    return Value.fromJSON(model);
  });
  const stylesById = useMemo(() => arrayOfItemsWithIdToObject(styles), [
github accordproject / template-studio-v2 / src / sagas / contractSaga.js View on Github external
marks: []
        }
      ]
    };

    const valueAsSlate = slateTransformer.fromMarkdown(clauseMd);
    const clauseNodeJSON = valueAsSlate.toJSON().document.nodes[0];
    const newSlateValueAsJSON = JSON.parse(JSON.stringify(slateValue.toJSON()));

    const { nodes } = newSlateValueAsJSON.document;

    // add the clause node to the Slate dom at current position
    // Temporary fix to separate clauses, adding the new paragraph at
    // end of splice. Convert this all back to markdown
    nodes.splice((currentPosition + 1), 0, clauseNodeJSON, paragraphSpaceNodeJSON);
    const realNewMd = slateTransformer.toMarkdown(Value.fromJSON(newSlateValueAsJSON));

    // update contract on store with new slate and md values
    yield put(actions.documentEdited(Value.fromJSON(newSlateValueAsJSON), realNewMd));
    const grammar = templateObj.parserManager.getTemplatizedGrammar();


    // Temporary roundtrip and rebuild grammar
    const grammarRound = roundTrip(grammar);
    templateObj.parserManager.buildGrammar(grammarRound);

    const sampleText = templateObj.getMetadata().getSamples().default;
    const model = templateObj.getModelManager().getModels();
    const logic = templateObj.getScriptManager().getLogic();
    const clauseTemplateId = uuidv4(); // unique identifier for a clause template

    // add a new clause template to the store so user can edit template
github Canner / canner-slate-editor / packages / slate-selectors / line-height / src / __tests__ / index.js View on Github external
test("create a LineHeight icon", () => {
  const initialValue = Value.fromJSON({
    document: {
      nodes: [
        {
          object: "block",
          type: "paragraph",
          nodes: [
            {
              object: "text",
              leaves: [
                {
                  text: "A line of text in a paragraph."
                }
              ]
            }
          ]
        }
github ianstormtaylor / slate / examples / versions / index.js View on Github external
/**
 * The versions example.
 *
 * @type {Component}
 */

class Versions extends React.Component {
  /**
   * Deserialize the initial editor value.
   *
   * @type {Object}
   */

  state = {
    value: Value.fromJSON(initialValue),
    versions: [],
    v: '',
  }

  /**
   * On mounting, save an initial version.
   */

  componentDidMount() {
    this.saveVersion()
  }

  /**
   * Store a reference to the `editor`.
   *
   * @param {Editor} editor
github YurkaninRyan / slate-sticky-inlines / example / index.js View on Github external
import React from 'react'
import ReactDOM from 'react-dom'
import initialValue from './value'
import { Value } from 'slate'
import { Editor } from 'slate-react'

class Example extends React.Component {
  plugins = [
    StickyInlines({ bannedTypes: ["banned", "no-sticky-boundary-link", "cant-be-empty-link", "doesnt-stick-on-delete-link"] }),
    StickyInlines({ allowedTypes: ["no-sticky-boundary-link"], hasStickyBoundaries: false }),
    StickyInlines({ allowedTypes: ["cant-be-empty-link"], canBeEmpty: false }),
    StickyInlines({ allowedTypes: ["doesnt-stick-on-delete-link"], stickOnDelete: false })
  ];

  state = {
    value: Value.fromJSON(initialValue)
  };

  onChange = ({ value }) => {
    this.setState({ value })
  }

  renderNode = (props) => {
    switch (props.node.type) {
      case "link": {
        const className = props.isSelected ? "focused" : ""
        return <a href="/">{props.children}</a>
      }
      case "no-sticky-boundary-link": {
        const className = props.isSelected ? "focused" : ""
        return <a href="/">{props.children}</a>
      }
github webiny / webiny-js / packages / webiny-app-i18n / src / components / I18NValue.js View on Github external
value = getValue(defaultObject);
    }

    if (typeof value === "string") {
        return value;
    }

    let editorPlugins = getPlugins("i18n-value-rich-text-editor")
        .map(item =&gt; item.plugin.editor)
        .filter(Boolean);

    if (Array.isArray(props.editorPlugins)) {
        editorPlugins = [...editorPlugins, ...props.editorPlugins];
    }

    return ;
}
github Graphite-Docs / graphite / web / src / components / helpers / singleRTC.js View on Github external
//Now we need to determine if the response was from indexedDB or an API call:
    if (fetchFile.loadLocal || storageProvider === 'google' || storageProvider === 'ipfs') {
      let decryptedContent;
      if(storageProvider === 'google') {
        decryptedContent = await JSON.parse(decryptContent(fetchFile, { privateKey: thisKey }))
      } else {
        decryptedContent = await JSON.parse(
          decryptContent(JSON.parse(fetchFile.data.content), {
            privateKey: thisKey
          })
        );
      }
      
      setGlobal(
        {
          content: Value.fromJSON(decryptedContent.content),
          title: decryptedContent.title,
          tags: decryptedContent.tags,
          idToLoad: decryptedContent.id,
          singleDocIsPublic: decryptedContent.singleDocIsPublic, //adding this...
          docLoaded: true,
          readOnly: decryptedContent.readOnly, //NOTE: adding this, to setState of readOnly from getFile...
          rtc: decryptedContent.rtc || false,
          sharedWith: decryptedContent.sharedWith,
          teamDoc: decryptedContent.teamDoc,
          compressed: decryptedContent.compressed || false,
          spacing: decryptedContent.spacing,
          lastUpdate: decryptedContent.lastUpdate,
          jsonContent: true,
          versions: decryptedContent.versions || [],
          loading: false
        })
github RodionChachura / simple-blog-front / src / reducers / editor.js View on Github external
const getDefaultState = () => ({
  title: '',
  content: Value.fromJSON({
    document: {
      nodes: [
        {
          object: 'block',
          type: 'paragraph', 
        },
      ],
    },
  }),
  storyId: undefined,
  lastSave: Date.now(),
  lastEdit: undefined,
  changesSaved: true,
  linkPrompt: undefined,
  link: '',
  tags: [],
github react-page / react-page / packages / plugins / content / slate / src / hooks.js View on Github external
export const createInitialState = () => ({
  editorState: Value.fromJSON(
    {
      document: {
        nodes: [
          {
            object: 'block',
            type: P,
            nodes: [
              {
                object: 'text',
                leaves: [
                  {
                    text: ''
                  }
                ]
              }
            ]
github oughtinc / mosaic / client / src / components / MetadataEditor.tsx View on Github external
import { compose } from "recompose";
import { Value } from "slate";
import { Editor } from "slate-react";
import { Auth } from "../auth";
import { LinkifyPlugin } from "../lib/slate-plugins/linkifyPlugin";

const linkifyPlugin = LinkifyPlugin();

const plugins = [linkifyPlugin];

export class MetaDataEditorPresentational extends React.Component {
  public state = {
    isSavePending: false,
    didSaveJustSuccesfullyOccur: false,
    value: this.props.valueAsJSON
      ? Value.fromJSON(this.props.valueAsJSON)
      : Value.fromJSON({
          document: {
            nodes: [
              {
                object: "block",
                type: "paragraph",
                nodes: [
                  {
                    object: "text",
                    leaves: [
                      {
                        text: "",
                      },
                    ],
                  },
                ],