Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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()
}
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}])))
toInsert = toInsert.map(blk =>
normalizeBlock(blk, {
allowedDecorators
})
)
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
}
const blocksToInsertNormalized = result.insert.map(block => normalizeBlock(block, {allowedDecorators}))
const patches = [