Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const isActive = hasBlock(value, type);
const isList =
hasBlock(value, 'bulleted-list-item') ||
hasBlock(value, 'numbered-list-item');
if (isList) {
transform = transform
.setBlock(isActive ? defaultNode : type)
.unwrapBlock('bulleted-list')
.unwrapBlock('numbered-list');
} else if (isAtomic) {
transform = transform.insertBlock({
type,
isVoid,
data: {},
nodes: defaultNodes || Block.createList([createP()]),
});
} else {
transform = transform.setBlock(isActive ? defaultNode : type);
}
} else {
// Handle the extra wrapping required for list buttons.
const isList =
hasBlock(value, 'bulleted-list-item') ||
hasBlock(value, 'numbered-list-item');
const isType = blocks.some(
block => !!document.getClosest(block, parent => parent.type === type)
);
if (isList && isType) {
transform = transform
.setBlock(defaultNode)
const {fragment, html, text} = transfer
const {type} = transfer
if (type === 'fragment') {
onProgress({status: 'fragment'})
// Check if we have all block types in the schema,
// otherwise, use html version
const allSchemaBlockTypes = blockContentType.of
.map(ofType => ofType.name)
.concat('contentBlock')
const allBlocksHasSchemaDef = fragment.nodes
.map(node => node.type)
.every(nodeType => allSchemaBlockTypes.includes(nodeType))
if (allBlocksHasSchemaDef) {
ensureNoPlaceholder(editor)
const {focusBlock} = editor.value
const newNodesList = Block.createList(fragment.nodes.map(node => processNode(node, editor)))
const newDoc = new Document({
key: fragment.key,
nodes: newNodesList
})
newDoc.nodes.forEach((block, index) => {
if (
index === 0 &&
focusBlock &&
!editor.query('isVoid', focusBlock) &&
focusBlock.nodes.size === 1 &&
focusBlock.text === ''
) {
editor
.insertBlock(block)
.moveToEndOfBlock()
.removeNodeByKey(focusBlock.key)
function onPaste(event, data, change) {
if (typeof data.fragment === 'undefined' || data.fragment === null) {
return null
}
const newNodesList = Block.createList(data.fragment.nodes.toArray().map(processNode))
const newDoc = new Document({
key: data.fragment.key,
nodes: newNodesList
})
return change.insertFragment(newDoc)
}
export default function toSlate(array, context) {
if (array.length === 0) {
return State.create({
document: Document.create({
nodes: Block.createList([
Raw.deserializeNode({
kind: 'block',
type: SLATE_DEFAULT_NODE,
nodes: [
{kind: 'text', text: '', ranges: []}
]
})
])
})
})
}
return State.create({
document: Document.create({
nodes: Block.createList(array.map(node => DESERIALIZE.node(node, context)))
})
})
export default items =>
Block.createList(
items
.map((item) => {
if (!item) {
return empty();
} else if (item.component && item.key) {
const block = { type: item.key, kind: 'block' };
if (!item.editable) {
block.isVoid = true;
} else {
block.nodes = Block.createList([empty()]);
}
return block;
}
})
.filter(x => x)
);
nodes: Block.createList(para.children.map(child => {
return Block.create({
type: 'listItem',
nodes: Block.createList(child.children.map((childChild) => {
return DESERIALIZE.node(childChild, context)
}))
})
}))
})
export default items =>
Block.createList(
items
.map((item) => {
if (!item) {
return empty();
} else if (item.component && item.key) {
const block = { type: item.key, kind: 'block' };
if (!item.editable) {
block.isVoid = true;
} else {
block.nodes = Block.createList([empty()]);
}
return block;
}
})
.filter(x => x),
);
.map((item) => {
if (!item) {
return empty();
} else if (item.component && item.key) {
const block = { type: item.key, kind: 'block' };
if (!item.editable) {
block.isVoid = true;
} else {
block.nodes = Block.createList([empty()]);
}
return block;
}
})
.filter(x => x)
export default items =>
Block.createList(
items
.map((item) => {
if (!item) {
return empty();
} else if (item.component && item.key) {
const block = { type: item.key, kind: 'block' };
if (!item.editable) {
block.isVoid = true;
} else {
block.nodes = Block.createList([empty()]);
}
return block;
}
})
.filter(x => x)
);
document: Document.create({
nodes: Block.createList([
Raw.deserializeNode({
kind: 'block',
type: SLATE_DEFAULT_NODE,
nodes: [
{kind: 'text', text: '', ranges: []}
]
})
])
})
})
}
return State.create({
document: Document.create({
nodes: Block.createList(array.map(node => DESERIALIZE.node(node, context)))
})
})
}