本文整理汇总了TypeScript中prosemirror-model.Fragment.from方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Fragment.from方法的具体用法?TypeScript Fragment.from怎么用?TypeScript Fragment.from使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类prosemirror-model.Fragment
的用法示例。
在下文中一共展示了Fragment.from方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
return function(state, dispatch) {
const { $from } = state.selection
const parent = $from.parent
const { hardBreak } = state.schema.nodes
if (hardBreak) {
const hardBreakNode = hardBreak.create()
if (parent && parent.type.validContent(Fragment.from(hardBreakNode))) {
if (dispatch) {
dispatch(state.tr.replaceSelectionWith(hardBreakNode))
}
return true
}
}
if (state.selection instanceof TextSelection) {
if (dispatch) {
dispatch(state.tr.insertText("\n"))
}
return true
}
return false
}
示例2:
export const createHorizontalRule = (
state: EditorState,
start,
end,
inputMethod:
| INPUT_METHOD.QUICK_INSERT
| INPUT_METHOD.TOOLBAR
| INPUT_METHOD.INSERT_MENU
| INPUT_METHOD.FORMATTING
| INPUT_METHOD.SHORTCUT,
) => {
if (!state.selection.empty) {
return null
}
const { $from } = state.selection
const $afterRule = state.doc.resolve($from.after())
const { paragraph } = state.schema.nodes
if ($afterRule.nodeAfter && $afterRule.nodeAfter.type === paragraph) {
// if there's already a paragraph after, just insert the rule into
// the current paragraph
end = end + 1
}
const tr = state.tr.replaceWith(
start,
end,
Fragment.from(state.schema.nodes.rule.createChecked()),
)
return tr
}
示例3:
getContent: (domNode, schema) => {
const dom = domNode as HTMLElement
const code = Array.from(dom.children)
.map(child => child.textContent)
// tslint:disable-next-line:triple-equals
.filter(x => (x = undefined))
.join("\n")
return code ? Fragment.from(schema.text(code)) : Fragment.empty
},