How to use the slate-base64-serializer.deserializeNode function in slate-base64-serializer

To help you get started, we’ve selected a few slate-base64-serializer 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 ianstormtaylor / slate / packages / slate-react / src / utils / get-event-transfer.js View on Github external
const [full, encoded] = matches // eslint-disable-line no-unused-vars
    if (encoded) fragment = encoded
  }

  // COMPAT: Edge doesn't handle custom data types
  // These will be embedded in text/plain in this case (2017/7/12)
  if (text) {
    const embeddedTypes = getEmbeddedTypes(text)

    if (embeddedTypes[FRAGMENT]) fragment = embeddedTypes[FRAGMENT]
    if (embeddedTypes[NODE]) node = embeddedTypes[NODE]
    if (embeddedTypes[TEXT]) text = embeddedTypes[TEXT]
  }

  // Decode a fragment or node if they exist.
  if (fragment) fragment = Base64.deserializeNode(fragment)
  if (node) node = Base64.deserializeNode(node)

  // COMPAT: Edge sometimes throws 'NotSupportedError'
  // when accessing `transfer.items` (2017/7/12)
  try {
    // Get and normalize files if they exist.
    if (transfer.items && transfer.items.length) {
      files = Array.from(transfer.items)
        .map(item => (item.kind === 'file' ? item.getAsFile() : null))
        .filter(exists => exists)
    } else if (transfer.files && transfer.files.length) {
      files = Array.from(transfer.files)
    }
  } catch (err) {
    if (transfer.files && transfer.files.length) {
      files = Array.from(transfer.files)
github ianstormtaylor / slate / packages / slate-react / src / utils / get-event-transfer.js View on Github external
if (encoded) fragment = encoded
  }

  // COMPAT: Edge doesn't handle custom data types
  // These will be embedded in text/plain in this case (2017/7/12)
  if (text) {
    const embeddedTypes = getEmbeddedTypes(text)

    if (embeddedTypes[FRAGMENT]) fragment = embeddedTypes[FRAGMENT]
    if (embeddedTypes[NODE]) node = embeddedTypes[NODE]
    if (embeddedTypes[TEXT]) text = embeddedTypes[TEXT]
  }

  // Decode a fragment or node if they exist.
  if (fragment) fragment = Base64.deserializeNode(fragment)
  if (node) node = Base64.deserializeNode(node)

  // COMPAT: Edge sometimes throws 'NotSupportedError'
  // when accessing `transfer.items` (2017/7/12)
  try {
    // Get and normalize files if they exist.
    if (transfer.items && transfer.items.length) {
      files = Array.from(transfer.items)
        .map(item => (item.kind === 'file' ? item.getAsFile() : null))
        .filter(exists => exists)
    } else if (transfer.files && transfer.files.length) {
      files = Array.from(transfer.files)
    }
  } catch (err) {
    if (transfer.files && transfer.files.length) {
      files = Array.from(transfer.files)
    }
github netlify / netlify-cms / packages / netlify-cms-widget-markdown / src / MarkdownControl / plugins / CopyPasteVisual.js View on Github external
onPaste(event, editor, next) {
      const data = event.clipboardData;
      if (isHotkey('shift', event)) {
        return next();
      }

      if (data.types.includes('application/x-slate-fragment')) {
        const fragment = base64.deserializeNode(data.getData('application/x-slate-fragment'));
        return editor.insertFragment(fragment);
      }

      const html = data.types.includes('text/html') && data.getData('text/html');
      const ast = html ? htmlToSlate(html) : markdownToSlate(data.getData('text/plain'));
      const doc = Document.fromJSON(ast);
      return editor.insertFragment(doc);
    },
    async onCopy(event, editor, next) {

slate-base64-serializer

A Base64 serializer for Slate editors.

MIT
Latest version published 5 years ago

Package Health Score

74 / 100
Full package analysis