本文整理汇总了TypeScript中draft-js.ContentState.merge方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ContentState.merge方法的具体用法?TypeScript ContentState.merge怎么用?TypeScript ContentState.merge使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类draft-js.ContentState
的用法示例。
在下文中一共展示了ContentState.merge方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: updateStyles
export function updateStyles(editor: EditorState) {
const key = editor.getSelection().getFocusKey()
const content = editor.getCurrentContent()
const block = content.getBlockForKey(key)
const ast = parser.parse(block.getText())
let updatedBlock: ContentBlock
let updatedContent: ContentState
if (ast.firstChild === ast.lastChild && ast.firstChild) {
const node = ast.firstChild
if (node.type === 'Heading') {
const type = headerType[ast.firstChild.level] || 'unstyled'
updatedBlock = maybeSet(block, type)
} else if (node.type === 'BlockQuote') {
updatedBlock = maybeSet(block, 'blockquote')
// } else if (node.type === 'Paragraph' && node.firstChild !== node.lastChild) {
// updatedContent = updateInlineStyles(content, block.getKey(), node)
} else {
updatedBlock = maybeSet(block, 'unstyled')
}
/// goal question metiric, victor basili
/// Program slicing, component based systems
} else {
updatedBlock = maybeSet(block, 'unstyled')
}
if (updatedBlock) {
updatedContent = content.setIn(['blockMap', key], updatedBlock)
}
if (updatedContent) {
const selection = editor.getSelection()
updatedContent = updatedContent.merge({
selectionBefore: selection,
selectionAfter: selection,
})
return EditorState.push(editor, updatedContent, 'change-block-type')
}
return editor
}