本文整理匯總了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
},