How to use the slate-react.findNode 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 edtr-io / edtr-io / packages / plugin-text / src / factory / editor.tsx View on Github external
onClick={(e, editor, next): CoreEditor | void => {
          if (e.target) {
            // @ts-ignore
            const node = findNode(e.target as Element, editor)
            if (!node) {
              return editor
            }
          }
          next()
        }}
        onChange={change => {
github sanity-io / sanity / packages / @sanity / form-builder / src / inputs / BlockEditor / nodes / BlockObject.tsx View on Github external
// eslint-disable-next-line max-depth
        if (!targetDOMNode && closestBlock) {
          targetDOMNode = findDOMNode(closestBlock)
        }
      }
    }
    // As the event is registered on the editor parent node
    // ignore the event if it is coming from from the editor node itself
    if (!targetDOMNode || targetDOMNode === this._editorNode) {
      this.resetDropTarget()
      return
    }
    if (event.dataTransfer) {
      event.dataTransfer.dropEffect = 'move'
    }
    const targetNode = findNode(targetDOMNode, editor)
    if (!targetNode) {
      this.resetDropTarget()
      return
    }
    const block =
      targetNode.object === 'block'
        ? targetNode
        : editor.value.document.getClosestBlock(targetNode.key)
    // If no or same block reset and return
    if (!block || block.key === node.key) {
      this.resetDropTarget()
      return
    }
    const blockDOMNode = findDOMNode(block)
    const rect = blockDOMNode.getBoundingClientRect()
    const position = event.clientY < rect.top + blockDOMNode.scrollHeight / 2 ? 'before' : 'after'
github keystonejs / keystone / packages / fields / src / types / CloudinaryImage / views / blocks / single-image.js View on Github external
onDragStart(event, editor, next) {
      const { value } = editor;
      const { document } = value;
      const node = findNode(event.target, editor);
      if (node.type === blocks.image.type) {
        const ancestors = document.getAncestors(node.key);
        let imgContainer = ancestors.get(ancestors.size - 1);
        if (imgContainer.type === type) {
          editor.moveToRangeOfNode(imgContainer);
        }
      }

      next();
    },
  },
github sanity-io / sanity / packages / @sanity / form-builder / src / inputs / BlockEditor / plugins / OnDropPlugin.ts View on Github external
onDrop(event: React.MouseEvent, editor: SlateEditor, next: (arg0: void) => void) {
      const {target} = event
      const node = findNode(target, editor)
      if (editor.query('isVoid', node)) {
        return editor
      }
      return next()
    }
  }
github keystonejs / keystone / packages / field-content / src / views / editor / blocks / image-container.js View on Github external
onDragStart(event, editor, next) {
      const { value } = editor;
      const { document } = value;
      const node = findNode(event.target, editor);
      if (node.type === blocks.image.type) {
        const ancestors = document.getAncestors(node.key);
        let imgContainer = ancestors.get(ancestors.size - 1);
        if (imgContainer.type === type) {
          editor.moveToRangeOfNode(imgContainer);
        }
      }

      next();
    },
  },