How to use the slate-react.setEventTransfer 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 sanity-io / sanity / packages / @sanity / form-builder / src / inputs / BlockEditor / nodes / InlineObject.tsx View on Github external
handleDragStart = (event: React.DragEvent) => {
    const {node} = this.props
    this.setState({isDragging: true})
    this.addDragHandlers()
    const element = ReactDOM.findDOMNode(this._previewContainer) // eslint-disable-line react/no-find-dom-node
    if (element && element instanceof HTMLElement) {
      const encoded = Base64.serializeNode(node, {preserveKeys: true})
      setEventTransfer(event, 'node', encoded)
      event.dataTransfer.effectAllowed = 'move'
      event.dataTransfer.setDragImage(element, element.clientWidth / 2, -10)
    }
    this.props.editor.moveToEndOfNode(this.props.node).focus()
  }
  // Remove the drop target if we leave the editors nodes
github sanity-io / sanity / packages / @sanity / form-builder / src / inputs / BlockEditor / nodes / BlockObject.tsx View on Github external
handleDragStart = (event: React.DragEvent) => {
    const {node, readOnly} = this.props
    if (readOnly) {
      event.preventDefault()
      return
    }
    this.setState({isDragging: true})
    this.addDragHandlers()
    const encoded = Base64.serializeNode(node, {
      preserveKeys: true,
      preserveData: true
    })
    setEventTransfer(event, 'node', encoded)
    event.dataTransfer.effectAllowed = 'move'
    // Specify dragImage so that single elements in the preview will not be the drag image,
    // but always the whole block thing itself.
    // Also clone it so that it will not be visually clipped by scroll-containers etc.
    const element: HTMLElement = event.currentTarget
    if (element) {
      this._dragGhost = element.cloneNode(true) as HTMLElement
      this._dragGhost.style.width = `${element.clientWidth}px`
      this._dragGhost.style.height = `${element.clientHeight}px`
      this._dragGhost.style.position = 'absolute'
      this._dragGhost.style.top = '-99999px'
      this._dragGhost.style.left = '-99999px'
      if (document.body) {
        document.body.appendChild(this._dragGhost)
        // eslint-disable-next-line max-depth
        if (this._dragGhost) {
github netlify / netlify-cms / packages / netlify-cms-widget-markdown / src / MarkdownControl / plugins / CopyPasteVisual.js View on Github external
const handleCopy = async (event, editor) => {
    event.persist();
    const markdown = slateToMarkdown(editor.value.fragment.toJS());
    const html = await markdownToHtml(markdown, { getAsset, resolveWidget });
    setEventTransfer(event, 'text', markdown);
    setEventTransfer(event, 'html', html);
    setEventTransfer(event, 'fragment', base64.serializeNode(editor.value.fragment));
    event.preventDefault();
  };
github netlify / netlify-cms / packages / netlify-cms-widget-markdown / src / MarkdownControl / plugins / CopyPasteVisual.js View on Github external
const handleCopy = async (event, editor) => {
    event.persist();
    const markdown = slateToMarkdown(editor.value.fragment.toJS());
    const html = await markdownToHtml(markdown, { getAsset, resolveWidget });
    setEventTransfer(event, 'text', markdown);
    setEventTransfer(event, 'html', html);
    setEventTransfer(event, 'fragment', base64.serializeNode(editor.value.fragment));
    event.preventDefault();
  };
github netlify / netlify-cms / packages / netlify-cms-widget-markdown / src / MarkdownControl / RawEditor.js View on Github external
handleCopy = async (event, editor) => {
    event.persist();
    const { getAsset, resolveWidget } = this.props;
    const markdown = Plain.serialize(editor.value);
    const html = await markdownToHtml(markdown, { getAsset, resolveWidget });
    setEventTransfer(event, 'text', markdown);
    setEventTransfer(event, 'html', html);
    event.preventDefault();
  };
github netlify / netlify-cms / packages / netlify-cms-widget-markdown / src / MarkdownControl / plugins / CopyPasteVisual.js View on Github external
const handleCopy = async (event, editor) => {
    event.persist();
    const markdown = slateToMarkdown(editor.value.fragment.toJS());
    const html = await markdownToHtml(markdown, { getAsset, resolveWidget });
    setEventTransfer(event, 'text', markdown);
    setEventTransfer(event, 'html', html);
    setEventTransfer(event, 'fragment', base64.serializeNode(editor.value.fragment));
    event.preventDefault();
  };
github netlify / netlify-cms / packages / netlify-cms-widget-markdown / src / MarkdownControl / RawEditor.js View on Github external
handleCopy = async (event, editor) => {
    event.persist();
    const { getAsset, resolveWidget } = this.props;
    const markdown = Plain.serialize(editor.value);
    const html = await markdownToHtml(markdown, { getAsset, resolveWidget });
    setEventTransfer(event, 'text', markdown);
    setEventTransfer(event, 'html', html);
    event.preventDefault();
  };