當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript prosemirror-model.MarkType類代碼示例

本文整理匯總了TypeScript中prosemirror-model.MarkType的典型用法代碼示例。如果您正苦於以下問題:TypeScript MarkType類的具體用法?TypeScript MarkType怎麽用?TypeScript MarkType使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了MarkType類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: allowedBlocks

    state.doc.nodesBetween(from, to, (node, pos, parent) => {
        if (!node.type.isBlock) {
            return false
        }

        if (
            (!allowedBlocks ||
                (Array.isArray(allowedBlocks)
                    ? allowedBlocks.indexOf(node.type) > -1
                    : allowedBlocks(state.schema, node, parent))) &&
            parent.type.allowsMarkType(markType)
        ) {
            const oldMarks = node.marks.filter(mark => mark.type === markType)

            const prevAttrs = oldMarks.length ? (oldMarks[0].attrs as T) : undefined
            const newAttrs = getAttrs(prevAttrs, node)

            if (newAttrs !== undefined) {
                tr.setNodeMarkup(
                    pos,
                    node.type,
                    node.attrs,
                    node.marks
                        .filter(mark => !markType.excludes(mark.type))
                        .concat(newAttrs === false ? [] : markType.create(newAttrs)),
                )
                markApplied = true
            }
        }
    })
開發者ID:zodiac-team,項目名稱:zodiac-ui,代碼行數:30,代碼來源:toggle-block-mark.ts

示例2:

export const isMarkTypeActive = (state: EditorState, markType: MarkType): boolean => {
    const { $from, from, to, empty } = state.selection
    if (empty) {
        return !!markType.isInSet(state.storedMarks || $from.marks())
    }
    return state.doc.rangeHasMark(from, to, markType)
}
開發者ID:zodiac-team,項目名稱:zodiac-ui,代碼行數:7,代碼來源:utils.ts

示例3:

const cm2: model.ContentMatch = cm1.matchType({} as any)!;
const cm3: model.ContentMatch = cm1.matchFragment({} as any)!;
const cm4: model.Fragment = cm1.fillBefore({} as any)!;
const cm5: model.NodeType[] = cm1.findWrapping({} as any)!;

const f1 = new model.Fragment();
f1.nodesBetween(0, 0, () => {});
f1.nodesBetween(0, 0, () => null);
f1.nodesBetween(0, 0, () => undefined);
f1.nodesBetween(0, 0, () => true);

f1.descendants(() => {});
f1.descendants(() => null);
f1.descendants(() => undefined);
f1.descendants(() => true);

const res2_1: model.Node = f1.maybeChild(0)!;
const res2_2: number = f1.findDiffStart(f1)!;
const res2_3: { a: number, b: number } = f1.findDiffEnd({} as any)!;
const res2_4: object = f1.toJSON()!;

const res3_1 = new model.ResolvedPos();
const res3_2: model.Mark[] = res3_1.marksAcross(res3_1)!;
const res3_3: model.NodeRange = res3_1.blockRange(res3_1)!;

const res4_1 = new model.NodeType();
const res4_2: model.Node = res4_1.createAndFill()!;

const res5_1 = new model.MarkType();
const res5_2: model.Mark = res5_1.isInSet([])!;
開發者ID:CNBoland,項目名稱:DefinitelyTyped,代碼行數:30,代碼來源:prosemirror-model-tests.ts

示例4: return

    return (state, match, start, end) => {
        const [, prefix, textWithCombo] = match
        const to = end
        // in case of *string* pattern it matches the text from beginning of the paragraph,
        // because we want ** to work for strong text
        // that's why "start" argument is wrong and we need to calculate it ourselves
        const from = textWithCombo ? start + prefix.length : start
        const nodeBefore = state.doc.resolve(start + prefix.length).nodeBefore

        if (
            prefix &&
            prefix.length > 0 &&
            !validRegex(char, prefix) &&
            !(nodeBefore && nodeBefore.type === state.schema.nodes.hardBreak)
        ) {
            return null
        }
        // fixes the following case: my `*name` is *
        // expected result: should ignore special characters inside "code"
        if (
            state.schema.marks.code &&
            state.schema.marks.code.isInSet(state.doc.resolve(from + 1).marks())
        ) {
            return null
        }

        // Prevent autoformatting across hardbreaks
        let containsHardBreak
        state.doc.nodesBetween(from, to, node => {
            if (node.type === schema.nodes.hardBreak) {
                containsHardBreak = true
                return false
            }
            return !containsHardBreak
        })
        if (containsHardBreak) {
            return null
        }

        // fixes autoformatting in heading nodes: # Heading *bold*
        // expected result: should not autoformat *bold*; <h1>Heading *bold*</h1>
        if (state.doc.resolve(from).sameParent(state.doc.resolve(to))) {
            if (!state.doc.resolve(from).parent.type.allowsMarkType(markType)) {
                return null
            }
        }

        // apply mark to the range (from, to)
        let tr = state.tr.addMark(from, to, markType.create())

        if (charSize > 1) {
            // delete special characters after the text
            // Prosemirror removes the last symbol by itself, so we need to remove "charSize - 1" symbols
            tr = tr.delete(to - (charSize - 1), to)
        }

        return (
            tr
                // delete special characters before the text
                .delete(from, from + charSize)
                .removeStoredMark(markType)
        )
    }
開發者ID:zodiac-team,項目名稱:zodiac-ui,代碼行數:63,代碼來源:text.formatting.inputrule.ts

示例5:

 .filter(mark => !markType.excludes(mark.type))
開發者ID:zodiac-team,項目名稱:zodiac-ui,代碼行數:1,代碼來源:toggle-block-mark.ts


注:本文中的prosemirror-model.MarkType類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。