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


TypeScript prosemirror-inputrules.inputRules函數代碼示例

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


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

示例1: horizontalRuleInputRulePlugin

export function horizontalRuleInputRulePlugin(schema: Schema): Plugin | undefined {
    const rules: Array<InputRule> = []

    if (schema.nodes.rule) {
        // '---' and '***' for hr
        rules.push(
            // -1, so that it also replaces the container paragraph
            createInputRule(
                /^(\-\-\-|\*\*\*)$/,
                (state, match, start, end) => createHorizontalRuleAutoformat(state, start - 1, end),
                true,
            ),
        )

        // '---' and '***' after shift+enter for hr
        rules.push(
            createInputRule(
                new RegExp(`${leafNodeReplacementCharacter}(\\-\\-\\-|\\*\\*\\*)`),
                (state, match, start, end) => {
                    const { hardBreak } = state.schema.nodes
                    if (state.doc.resolve(start).nodeAfter.type !== hardBreak) {
                        return null
                    }
                    return createHorizontalRuleAutoformat(state, start, end)
                },
                true,
            ),
        )
    }

    if (rules.length !== 0) {
        return inputRules({ rules })
    }
}
開發者ID:zodiac-team,項目名稱:zodiac-ui,代碼行數:34,代碼來源:input-rule.ts

示例2: createInputRulePlugin

export function createInputRulePlugin(schema: Schema): Plugin | undefined {
    if (!schema.marks.link) {
        return
    }

    const urlWithASpaceRule = createLinkInputRule((new LinkMatcher() as unknown) as RegExp, match =>
        match[3] ? match[1] : `https?://${match[1]}`,
    )

    // [something](link) should convert to a hyperlink
    const markdownLinkRule = createInputRule(
        /(^|[^])\[(.*?)\]\((\S+)\)$/,
        (state, match, start, end) => {
            // tslint:disable-next-line:no-shadowed-variable
            const { schema } = state
            const [, prefix, linkText, linkUrl] = match
            const url = normalizeUrl(linkUrl)
            const markType = schema.mark("link", { href: url })

            console.log("match?")

            return state.tr.replaceWith(
                start + prefix.length,
                end,
                schema.text(linkText, [markType]),
            )
        },
    )

    return inputRules({
        rules: [urlWithASpaceRule, markdownLinkRule],
    })
}
開發者ID:zodiac-team,項目名稱:zodiac-ui,代碼行數:33,代碼來源:input-rule.ts

示例3: inputRulePlugin

export function inputRulePlugin(schema: Schema): Plugin | undefined {
    const rules: Array<InputRuleWithHandler> = []

    if (schema.nodes.heading) {
        rules.push(...getHeadingRules(schema))
    }

    if (schema.nodes.blockquote) {
        rules.push(...getBlockQuoteRules(schema))
    }

    if (schema.nodes.codeBlock) {
        rules.push(...getCodeBlockRules(schema))
    }

    if (rules.length !== 0) {
        return inputRules({ rules })
    }
}
開發者ID:zodiac-team,項目名稱:zodiac-ui,代碼行數:19,代碼來源:block-type.inputrule.ts

示例4: inputRulePlugin

export function inputRulePlugin(schema: Schema): Plugin | undefined {
    const rules: Array<InputRule> = []

    if (schema.marks.strong) {
        rules.push(...getStrongInputRules(schema))
    }

    if (schema.marks.em) {
        rules.push(...getItalicInputRules(schema))
    }

    if (schema.marks.strike) {
        rules.push(...getStrikeInputRules(schema))
    }

    if (schema.marks.code) {
        rules.push(...getCodeInputRules(schema))
    }

    if (rules.length !== 0) {
        return inputRules({ rules })
    }
}
開發者ID:zodiac-team,項目名稱:zodiac-ui,代碼行數:23,代碼來源:text.formatting.inputrule.ts

示例5: buildMenuItemsPlugin

  buildMenuItemsPlugin() {
    let r = {}, deps;

    if (this.outputFormat === ProseMirrorFormatTypes.MARKDOWN) {
      if (this.outputSchema.marks.strong) {
        r['toggleStrong'] = this.markItem(this.outputSchema.marks.strong, {
          title: 'Toggle strong style',
          icon: icons.strong
        });
      }
      if (this.outputSchema.marks.em) {
        r['toggleEm'] = this.markItem(this.outputSchema.marks.em, {title: 'Toggle emphasis', icon: icons.em});
      }
      if (this.outputSchema.marks.code) { // this one is bonus
        r['toggleCode'] = this.markItem(this.outputSchema.marks.code, {title: 'Toggle code font', icon: icons.code});
      }
      if (this.outputSchema.marks.link) {
        r['toggleLink'] = this.linkItem(this.outputSchema.marks.link);
      }
      if (this.outputSchema.nodes.image && this.images && this.images.length > 0) {
        if (this.images.length === 1) {
          r['insertImage'] = this.insertImageItem(this.images[0], 'Image: ' + this.images[0].name);
        } else {
          for (let i = 0; i < this.images.length; i++) {
            r['insertImage' + i] = this.insertImageItem(this.images[i], this.images[i].name);
          }
        }
      }
      if (this.outputSchema.nodes.bullet_list) { // lists are bonus
        r['wrapBulletList'] = this.wrapListItem(this.outputSchema.nodes.bullet_list, {
          title: 'Wrap in bullet list',
          icon: icons.bulletList
        });
      }
      if (this.outputSchema.nodes.ordered_list) { // bonus
        r['wrapOrderedList'] = this.wrapListItem(this.outputSchema.nodes.ordered_list, {
          title: 'Wrap in ordered list',
          icon: icons.orderedList
        });
      }
      if (this.outputSchema.nodes.blockquote) { // bonus
        r['wrapBlockQuote'] = wrapItem(this.outputSchema.nodes.blockquote, {
          title: 'Wrap in block quote',
          icon: icons.blockquote
        });
      }
      if (this.outputSchema.nodes.paragraph) {
        r['makeParagraph'] = blockTypeItem(this.outputSchema.nodes.paragraph, {
          title: 'Change to paragraph',
          label: 'Plain'
        });
      }
      if (this.outputSchema.nodes.code_block) {// bonus
        r['makeCodeBlock'] = blockTypeItem(this.outputSchema.nodes.code_block, {
          title: 'Change to code block',
          label: 'Code'
        });
      }
      if (this.outputSchema.nodes.heading) {
        for (let i = 1; i <= 6; i++) {
          r['makeHead' + i] = blockTypeItem(this.outputSchema.nodes.heading, {
            title: 'Change to heading ' + i,
            label: 'Level ' + i,
            attrs: {level: i}
          });
        }
      }
      if (this.outputSchema.nodes.horizontal_rule) {// bonus
        r['insertHorizontalRule'] = new MenuItem({
          title: 'Insert horizontal rule',
          label: 'Horizontal rule',
          select: (state) => {
            return this.canInsert(state, this.outputSchema.nodes.horizontal_rule);
          },
          run: (state, dispatchTransaction) => {
            dispatchTransaction(state.tr.replaceSelectionWith(this.outputSchema.nodes.horizontal_rule.create()));
          }
        });
      }

      let cut = arr => arr.filter(x => x);

      if (this.images && this.images.length > 1) {
        let imageSubs = Object.keys(r).filter(key => key.match(/insertImage+/)).map(key => r[key]);
        let imageSubMenu = new DropdownSubmenu(imageSubs, {label: 'Image'});
        r['insertMenu'] = new Dropdown(cut([imageSubMenu, r['insertHorizontalRule']]), {label: 'Insert'});
      } else {
        r['insertMenu'] = new Dropdown(cut([r['insertImage'], r['insertHorizontalRule']]), {label: 'Insert'});
      }
      r['typeMenu'] = new Dropdown(cut([r['makeParagraph'], r['makeCodeBlock'], r['makeHead1'] && new DropdownSubmenu(cut([
        r['makeHead1'], r['makeHead2'], r['makeHead3'], r['makeHead4'], r['makeHead5'], r['makeHead6']
      ]), {label: 'Heading'})]), {label: 'Type...'});

      r['inlineMenu'] = [cut([r['toggleStrong'], r['toggleEm'], r['toggleCode'], r['toggleLink']]), [r['insertMenu']]];
      r['blockMenu'] = [cut([r['typeMenu'], r['wrapBulletList'], r['wrapOrderedList'], r['wrapBlockQuote'], joinUpItem,
        liftItem])];
      r['fullMenu'] = r['inlineMenu'].concat(r['blockMenu']);

      deps = [
        inputRules({rules: allInputRules.concat(this.buildInputRules())}),
//.........這裏部分代碼省略.........
開發者ID:PRX,項目名稱:publish.prx.org,代碼行數:101,代碼來源:prosemirror.markdown.editor.ts


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