How to use the slate.Data.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 blocks / blocks / packages / mdx / serializer / src / index.js View on Github external
if (node.children) {
      data = {
        type: getComponentName(node.children[0].value),
        props: {}
      }

      // Remove open and closing jsx blocks
      node.children = node.children.slice(1, node.children.length - 1)

      return {
        object: 'block',
        type: 'jsx',
        nodes: visitChildren(node),
        data: {
          type: data.type,
          props: Data.create(data.props)
        }
      }
    } else {
      data = parseJSXBlock(node.value)
      return {
        object: 'block',
        type: 'jsx-void',
        data: {
          type: data.type,
          props: Data.create(data.props)
        }
      }
    }
  },
  toMdast: (object, index, parent, { visitChildren }) => {
github withspectrum / slate-markdown / src / decorator.js View on Github external
function addMarks(characters, tokens, offset = 0) {
  for (const token of tokens) {
    if (typeof token == 'string') {
      offset += token.length;
      continue;
    }

    const { content, length, type } = token;
    let level;
    if (type === 'title') {
      const hashes = content.find(
        innerToken => innerToken.type === 'punctuation'
      );
      level = hashes.length;
    }
    const mark = Mark.create({ type, data: Data.create({ level }) });

    for (let i = offset; i < offset + length; i++) {
      let char = characters.get(i);
      let { marks } = char;
      marks = marks.add(mark);
      char = char.set('marks', marks);
      characters.set(i, char);
    }

    if (Array.isArray(content)) {
      addMarks(characters, content, offset);
    }

    offset += length;
  }
}
github react-page / react-page / packages / plugins / content / slate / src / plugins / link / index.js View on Github external
deserialize = (el, next) => {
    switch (el.tagName.toLowerCase()) {
      case 'a':
        return {
          object: 'inline',
          type: A,
          nodes: next(el.childNodes),
          data: Data.create({
            href: (el.attrs.find(({ name }) => name === 'href') || {
              value: ''
            }).value
          })
        }
    }
  }
github blocks / blocks / packages / mdx / editor / src / plugins / jsx-blocks / index.js View on Github external
const setJSXProps = (editor, dataObject) => {
  const {
    value: { startBlock, document }
  } = editor
  const data = Data.create(dataObject)

  if (startBlock.data.get('type') !== dataObject.type) {
    const parent = document.getParent(startBlock.key)
    if (parent) {
      editor.setNodeByKey(parent.key, { type: 'jsx', data })
    }
  } else {
    editor.setBlocks({ data })
  }
}
github react-page / react-page / packages / plugins / content / slate / src / plugins / code / index.tsx View on Github external
deserialize = (el, next) => {
    switch (el.tagName.toLowerCase()) {
      case 'code':
        return {
          object: 'mark',
          type: CODE,
          data: Data.create({}),
          nodes: next(el.childNodes),
        };
      case 'pre':
        return {
          object: 'block',
          type: CODE,
          nodes: next(el.childNodes),
        };
      default:
        return;
    }
  }
github sanity-io / sanity / packages / @sanity / form-builder / src / inputs / BlockEditor / plugins / PastePlugin.ts View on Github external
const newKey = blockTools.randomKey(12)

  const SlateType = node.constructor
  const newData = node.get('data') ? node.get('data').toObject() : {}
  newData._key = newKey
  if (newData.value && newData.value._key) {
    newData.value._key = newKey
  }
  if (newData.annotations) {
    Object.keys(newData.annotations).forEach(key => {
      newData.annotations[key]._key = blockTools.randomKey(12)
    })
  }
  return new SlateType({
    data: Data.create(newData),
    isVoid: editor.query('isVoid', node),
    key: newKey,
    nodes: node.get('nodes').map(childNode => processNode(childNode, editor)),
    type: node.get('type')
  })
}
const NOOP = () => {}
github blocks / blocks / packages / mdx / serializer / src / index.js View on Github external
object: 'block',
        type: 'jsx',
        nodes: visitChildren(node),
        data: {
          type: data.type,
          props: Data.create(data.props)
        }
      }
    } else {
      data = parseJSXBlock(node.value)
      return {
        object: 'block',
        type: 'jsx-void',
        data: {
          type: data.type,
          props: Data.create(data.props)
        }
      }
    }
  },
  toMdast: (object, index, parent, { visitChildren }) => {
github sanity-io / sanity / packages / @sanity / form-builder / src / inputs / BlockEditor-slate / BlockEditor.js View on Github external
const items = this.textStyles.map((style, index) => {
      return {
        key: `blockFormat-${index}`,
        style: style,
        preview: this.slateSchema.nodes.contentBlock({
          children: [
            
              {style.title}
            
          ]
        }),
        title: ` ${style.title}`,
        active: this.hasStyle(style.value)
      }
    })
    let value = items.filter(item => item.active)
github blocks / blocks / packages / mdx / editor / src / plugins / jsx-blocks / index.js View on Github external
const insertJSXBlock = (editor, type, props, component) => {
  const { isVoid } = component.propertyControls

  if (isVoid) {
    editor.insertBlock({
      type: 'jsx-void',
      data: {
        type,
        props: Data.create(props)
      }
    })
  } else {
    editor.wrapBlock({
      type: 'jsx',
      data: {
        type,
        props: Data.create(props)
      }
    })
  }
}
github edtr-io / edtr-io / packages / plugins / text / src / model / rules.tsx View on Github external
deserialize(el, next) {
      if (el.tagName.toLowerCase() === 'a') {
        const href = el.getAttribute('href')

        return {
          object: 'inline',
          type: linkNode,
          nodes: next(el.childNodes),
          data: Data.create({
            href: href ? href : ''
          })
        }
      }
    }
  },