How to use the @sanity/block-tools.normalizeBlock function in @sanity/block-tools

To help you get started, we’ve selected a few @sanity/block-tools 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 / utils / createEmptyBlock.ts View on Github external
const key = options.key || randomKey(12)
  const raw = {
    _key: key,
    _type: 'block',
    children: [
      {
        _type: 'span',
        _key: `${key}0`,
        text: '',
        marks: []
      }
    ],
    style: options.style || 'normal'
  }
  const allowedDecorators = blockContentFeatures.decorators.map(item => item.value)
  return deserialize([normalizeBlock(raw, {allowedDecorators})], blockContentFeatures.types.block).document.nodes.first()
}
github sanity-io / sanity / packages / @sanity / form-builder / src / inputs / BlockEditor / utils / createBlockActionPatchFn.ts View on Github external
return (givenBlock: Block) => {
    const allowedDecorators = blockContentFeatures.decorators.map(item => item.value)
    switch (type) {
      case 'set':
        return onPatch(
          PatchEvent.from(
            set(
              normalizeBlock(givenBlock, {
                allowedDecorators
              }),
              [{_key: block._key}]
            )
          )
        )
      case 'unset':
        return onPatch(PatchEvent.from(unset([{_key: block._key}])))
      case 'insert':
        toInsert = Array.isArray(givenBlock) ? givenBlock : [givenBlock]
        toInsert = toInsert.map(blk =>
          normalizeBlock(blk, {
            allowedDecorators
          })
        )
        return onPatch(PatchEvent.from(insert(toInsert, 'after', [{_key: block._key}])))
github sanity-io / sanity / packages / @sanity / form-builder / src / inputs / BlockEditor / utils / changeToPatches.js View on Github external
nextOperation &&
      nextOperation.type === 'set_node' &&
      nextOperation.path[0] === operation.path[0] + 1 &&
      (newKey = nextOperation.properties.data.get('_key'))
    ) {
      setKey(newKey, newBlock)
      operations.splice(operationIndex + 1, 1)
    }
    patches.push(insert([newBlock], position, [{_key: afterKey}]))
  }

  if (operation.path.length === 2) {
    const block = appliedBlocks[operation.path[0]]
    if (block._type === 'block') {
      setKey(block._key, block)
      patches.push(set(normalizeBlock(block), [{_key: block._key}]))
    }
  }
  return patches
}
github sanity-io / sanity / packages / @sanity / form-builder / src / inputs / BlockEditor / Editor.tsx View on Github external
          const blocksToInsertNormalized = result.insert.map(block => normalizeBlock(block, {allowedDecorators}))
          const patches = [