How to use the slate.Document.create 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 howtocards / frontend / src / lib / rich-text / extensions / hot-keys / code-block / on-paste-code-block.js View on Github external
// Convert to text if needed
  let text

  if (data.type === "fragment") {
    text = data.fragment
      .getTexts()
      .map((t) => t.text)
      .join("\n")
  } else {
    // eslint-disable-next-line prefer-destructuring
    text = data.text
  }
  // Convert the text to code lines
  const lines = deserializeCode(opts, text).nodes
  const fragment = Document.create({ nodes: lines })

  return change.insertFragment(fragment)
}
github grafana / grafana / public / app / plugins / datasource / grafana-azure-monitor-datasource / editor / query_field.tsx View on Github external
export const makeFragment = text => {
  const lines = text.split('\n').map(line =>
    Block.create({
      type: 'paragraph',
      nodes: [Text.create(line)],
    } as any)
  );

  const fragment = Document.create({
    nodes: lines,
  });
  return fragment;
};
github grafana / influxdb-flux-datasource / src / editor / QueryField.tsx View on Github external
export const makeFragment = text => {
  const lines = text.split('\n').map(line =>
    Block.create({
      type: 'paragraph',
      nodes: [Text.create(line)],
    })
  );

  const fragment = Document.create({
    nodes: lines,
  });
  return fragment;
};
github GridProtectionAlliance / openHistorian / Source / Applications / openHistorian / openHistorian / Grafana / public / app / plugins / datasource / grafana-azure-monitor-datasource / editor / query_field.tsx View on Github external
export const makeFragment = (text: string) => {
  const lines = text.split('\n').map((line: any) =>
    Block.create({
      type: 'paragraph',
      nodes: [Text.create(line)],
    } as any)
  );

  const fragment = Document.create({
    nodes: lines,
  });
  return fragment;
};
github grafana / grafana / public / app / features / explore / Value.ts View on Github external
const lines = text.split('\n').map(line =>
    Block.create({
      type: 'code_line',
      nodes: [Text.create(line)],
    })
  );

  const block = Block.create({
    data: {
      syntax,
    },
    type: 'code_block',
    nodes: lines,
  });

  return Document.create({
    nodes: [block],
  });
};
github react-page / react-page / packages / plugins / content / slate / src / hooks.js View on Github external
export const merge = (states: Object[]): Object => {
  const nodes = map(path(['editorState', 'document', 'nodes']), states)
  const mergedNodes = reduce(
    (a: List, b: List) => a.concat(b),
    head(nodes),
    tail(nodes)
  )
  const mergedDocument = Document.create({ nodes: mergedNodes })
  const mergedEditorState = Value.create({ document: mergedDocument })

  return { editorState: mergedEditorState }
}
github MorpheoOrg / morpheo-analytics / src / client / js / business / notebook / reducers / slate.js View on Github external
* same conditions as regards security.
 *
 * The fact that you are presently reading this means that you have had
 * knowledge of the CeCILL license and that you accept its terms.
 */

import {State, Document} from 'slate';

import {actionTypes} from '../actions';
import {actionTypes as kernelActionTypes} from '../../kernel/actions';
import languages from '../components/Editor/languages';
import {getContent} from './cells';

const initialState = {
    state: State.create({
        document: Document.create({
            nodes: [
                {
                    kind: 'block',
                    type: 'code_block',
                    data: {syntax: languages[0]},
                    nodes: [
                        {
                            type: 'code_line',
                            nodes: [{
                                type: 'text',
                                text: '',
                            }],
                        },
                    ],
                },
            ],
github haiwen / seahub / frontend / src / draft-review.js View on Github external
const block = document.getClosestBlock(anchor.key);
      const nextText = block.getNextText(anchor.key);
      if (nextText) {
        range = range.moveAnchorTo(nextText.key, 0);
      }
    }
    if (focusInline && focus.offset == focusText.text.length) {
      const block = document.getClosestBlock(focus.key);
      const nextText = block.getNextText(focus.key);
      if (nextText) {
        range = range.moveFocusTo(nextText.key, 0); 
      }
    }
    let fragment = document.getFragmentAtRange(range);
    let nodes = this.removeNullNode(fragment.nodes);
    let newFragment = Document.create({
      nodes: nodes
    });
    let newValue = Value.create({
      document: newFragment
    });
    this.quote = serialize(newValue.toJSON());
    let blockPath = document.createSelection(range).anchor.path.slice(0, 1);
    let node = document.getNode(blockPath);
    this.newIndex = node.data.get('new_index');
    this.oldIndex = node.data.get('old_index');
  }
github sanity-io / sanity / packages / @sanity / form-builder / src / inputs / BlockEditor-slate / conversion / toSlate.js View on Github external
export default function toSlate(array, context) {
  if (array.length === 0) {
    return State.create({
      document: Document.create({
        nodes: Block.createList([
          Raw.deserializeNode({
            kind: 'block',
            type: SLATE_DEFAULT_NODE,
            nodes: [
              {kind: 'text', text: '', ranges: []}
            ]
          })
        ])
      })
    })
  }
  return State.create({
    document: Document.create({
      nodes: Block.createList(array.map(node => DESERIALIZE.node(node, context)))
    })