How to use the slate-react.getEventTransfer function in slate-react

To help you get started, we’ve selected a few slate-react 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 haiwen / seahub / frontend / src / lib / seafile-slate-plugin.js View on Github external
onDrop(event, change, editor) {
      const transfer = getEventTransfer(event);
      const range = getEventRange(event, change.value);
      switch (transfer.type) {
        case 'text': {
          const { text } = transfer;
          if (!isUrl(text))
            return;
          if (text.endsWith("png?raw=1") || text.endsWith("png?raw=1")
            || text.endsWith("jpg?raw=1") || text.endsWith("JPG?raw=1") ) {
            // a special URL from seafile server
            var node = Inline.create({
              type: 'image',
              isVoid: true,
              data: {
                src: text
              }
            });
github sanity-io / sanity / packages / @sanity / form-builder / src / inputs / BlockEditor / plugins / PastePlugin.ts View on Github external
function onPaste(event, editor, next: (arg0: void) => void) {
    event.preventDefault()
    onProgress({status: 'start'})
    const transfer = getEventTransfer(event)
    const {fragment, html, text} = transfer
    const {type} = transfer
    if (type === 'fragment') {
      onProgress({status: 'fragment'})
      // Check if we have all block types in the schema,
      // otherwise, use html version
      const allSchemaBlockTypes = blockContentType.of
        .map(ofType => ofType.name)
        .concat('contentBlock')
      const allBlocksHasSchemaDef = fragment.nodes
        .map(node => node.type)
        .every(nodeType => allSchemaBlockTypes.includes(nodeType))
      if (allBlocksHasSchemaDef) {
        ensureNoPlaceholder(editor)
        const {focusBlock} = editor.value
        const newNodesList = Block.createList(fragment.nodes.map(node => processNode(node, editor)))
github KohheePeace / slate-tuto / src / app / App.jsx View on Github external
onPaste = (e, change) => {
    const transfer = getEventTransfer(e);
    const { type } = transfer;
    switch (type) {
      // case 'files': return this.handleOnDrop(files);
      case 'text': return onPasteText(e, change);
      case 'html': return onPasteHtml(e, change);
      default: break;
    }
  }
github blocks / blocks / packages / mdx / editor / src / plugins / link / onPaste.js View on Github external
export default (event, editor, next) => {
  const { value } = editor
  if (value.selection.isCollapsed) return next()
  const transfer = getEventTransfer(event)
  const { type, text } = transfer
  if (type !== 'text' && type !== 'html') return next()
  if (!isURL(text)) return next()

  if (editor.hasLinks()) {
    editor.unwrapLink()
  }

  editor.wrapLink({ href: text })
}
github oughtinc / mosaic / client / src / lib / slate-plugins / linkifyPlugin.tsx View on Github external
onPaste: (event, change) => {
      const transfer = getEventTransfer(event);
      const { type, text } = transfer;
      if (type !== "text" && type !== "html") {
        return;
      }

      if (!isUrl(text)) {
        return;
      }

      change
        .insertText(text)
        .extend(-text.length)
        .call(wrapLink, text);

      return false;
    },
github Graphite-Docs / graphite / client / src / components / docs / views / editors / SlateEditor.js View on Github external
onPaste = (event, editor, next) => {
    const transfer = getEventTransfer(event);
    if (transfer.type !== "html") return next();
    const { document } = html.deserialize(transfer.html);
    editor.insertFragment(document);
  };
github wowlusitong / re-editor / packages / core / src / scripts / components / ReEditor.js View on Github external
handlePaste = (event, editor, next) => {
    const { onImageUpload } = this.props;
    const transfer = getEventTransfer(event);
    const type = getPasteType(transfer);
    const paste = paster[type];
    if (paste) {
      return paste({ editor, transfer, onImageUpload });
    }
    next();
  };
github pradel / sigle / src / modules / editor / components / SlateEditor.tsx View on Github external
const handleDrop = (
    event: React.DragEvent<element>,
    editor: Editor,
    next: () =&gt; any
  ) =&gt; {
    const target = editor.findEventRange(event);
    if (!target &amp;&amp; event.type === 'drop') return next();

    const transfer: any = getEventTransfer(event);
    const { type, files } = transfer;

    if (type === 'files') {
      addImageToEditor(editor, files);
      return;
    }

    next();
  };
</element>
github letterpad / letterpad / admin / features / article / editor / index.js View on Github external
onPaste = (event, change) => {
    scrollToCursor();
    const transfer = getEventTransfer(event);
    if (transfer.type != "html") return;
    const { document } = html.deserialize(transfer.html);
    change.insertFragment(document);
    return true;
  };
github roast-cms / french-press-editor / src / plugins / paste-html.js View on Github external
onPaste(event, change) {
      const transfer = getEventTransfer(event);
      if (transfer.type !== "html") return;
      if (transfer.isShift) return;
      const { document } = html.deserialize(transfer.html);
      change.insertFragment(document);
      return true;
    }
  };