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


TypeScript prosemirror-model.Node類代碼示例

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


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

示例1: selectAroundMark

  selectAroundMark(markType: MarkType, doc: Node, pos: number, dispatchTransaction): Mark {
    let $pos = doc.resolve(pos),
      parent = $pos.parent;

    let start = parent.childAfter($pos.parentOffset);
    if (!start.node || start.node.marks.length === 0) {
      // happens if the cursor is at the end of the line or the end of the node, use nodeAt pos - 1 to find node marks
      start.node = parent.nodeAt($pos.parentOffset - 1);
      if (!start.node) {
        return null;
      }
    }

    let targetMark = start.node.marks.find(mark => mark.type.name === markType.name);
    if (!targetMark) {
      return null;
    }

    let startIndex = $pos.index(),
      startPos = $pos.start() + start.offset;
    while (startIndex > 0 && targetMark.isInSet(parent.child(startIndex - 1).marks)) {
      startPos -= parent.child(--startIndex).nodeSize;
    }
    let endIndex = $pos.indexAfter(),
      endPos = startPos + start.node.nodeSize;
    while (endPos < parent.childCount && targetMark.isInSet(parent.child(endIndex).marks)) {
      endPos += parent.child(endIndex++).nodeSize;
    }

    let selection = Selection.between(doc.resolve(startPos), doc.resolve(endPos));
    dispatchTransaction(this.view.editor.state.tr.setSelection(selection));

    return targetMark;
  }
開發者ID:PRX,項目名稱:publish.prx.org,代碼行數:34,代碼來源:prosemirror.markdown.editor.ts

示例2: createState

export function createState(schema: Schema, nodeOrJson: Node | any, plugins?: Plugin[]) {
    return EditorState.create({
        schema,
        doc: nodeOrJson instanceof Node ? nodeOrJson : Node.fromJSON(schema, nodeOrJson.doc),
        plugins,
    })
}
開發者ID:zodiac-team,項目名稱:zodiac-ui,代碼行數:7,代碼來源:create-state.ts

示例3: getContent

 const getContent = (node: Node) => {
   if (node.type.name === 'text') {
     if (translatedContent.length > 0 && node.textContent.length > 0
       && !node.textContent.match(/^\s+/)
       && !translatedContent.match(/^.+\s$/)) {
       translatedContent += ' ';
     }
     let linkMark: Mark;
     node.marks.forEach(mark => {
       if (markdownSchema.marks.link.isInSet([mark])) {
         linkMark = mark;
       }
     });
     if (linkMark) {
       translatedContent += `[${node.textContent}](${linkMark.attrs.href}`;
       if (node.marks[0].attrs.title) {
         translatedContent += ` "${linkMark.attrs.title}")`;
       } else {
         translatedContent += ')';
       }
     } else {
       translatedContent += node.textContent;
     }
   }
   // traverse the node tree and pull out the textContent and links via markdown input schema
   node.forEach((child, offset, index) => getContent(child));
 };
開發者ID:PRX,項目名稱:publish.prx.org,代碼行數:27,代碼來源:prosemirror.markdown.editor.ts

示例4: getAttrs

domOutputSpec = ['div', ['div', { class: 'foo' }, 0]];

export const nodeSpec: model.NodeSpec = {
    attrs: {
        name: { default: '' }
    },
    parseDOM: [
        {
            tag: 'span[data-name]',
            getAttrs(dom) {
                if (dom instanceof HTMLElement) {
                    return {
                        name: dom.getAttribute('data-name')!
                    };
                }
            }
        }
    ],
    toDOM(node) {
        const { name } = node.attrs;
        const attrs = {
            'data-emoji-name': name
        };
        return ['span', attrs, 0];
    }
};

const node = new model.Node();
node.nodesBetween(0, 1, () => {});
node.descendants(() => {});
開發者ID:anurse,項目名稱:DefinitelyTyped,代碼行數:30,代碼來源:prosemirror-model-tests.ts

示例5: toDOM

                }
            }
        }
    ],
    toDOM(node) {
        const { name } = node.attrs;
        const attrs = {
            'data-emoji-name': name
        };
        return ['span', attrs, 0];
    }
};

// Verify that non-null assertion operator can be used.

const res1_1 = new model.Node();
res1_1.nodesBetween(0, 1, () => {});
res1_1.nodesBetween(0, 1, () => null);
res1_1.nodesBetween(0, 1, () => undefined);
res1_1.nodesBetween(0, 1, () => true);
res1_1.descendants(() => {});
res1_1.descendants(() => null);
res1_1.descendants(() => undefined);
res1_1.descendants(() => true);
const res1_2: model.Node = res1_1.maybeChild(0)!;
const res1_3: model.Node = res1_1.nodeAt(0)!;

const cm1 = new model.ContentMatch();
const cm2: model.ContentMatch = cm1.matchType({} as any)!;
const cm3: model.ContentMatch = cm1.matchFragment({} as any)!;
const cm4: model.Fragment = cm1.fillBefore({} as any)!;
開發者ID:CNBoland,項目名稱:DefinitelyTyped,代碼行數:31,代碼來源:prosemirror-model-tests.ts


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