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


TypeScript editor.getEditorDOM函數代碼示例

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


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

示例1: removeReferences

export function* removeReferences(itemIds: string[]) {
    const doc = getEditorDOM();
    const toDelete = [
        ...doc.querySelectorAll<HTMLSpanElement>(CitationElement.selector),
    ].reduce(
        (idsToDelete, citation) => {
            const existingIds = CitationElement.getItems(citation);
            const filteredItemIds = existingIds.filter(
                id => !itemIds.includes(id),
            );
            if (filteredItemIds.length === 0 && citation.parentNode) {
                citation.parentNode.removeChild(citation);
            } else {
                citation.dataset.items = JSON.stringify(filteredItemIds);
            }
            return idsToDelete.filter(id => !existingIds.includes(id));
        },
        [...itemIds],
    );

    yield dispatch('core/block-editor').resetBlocks(parse(doc.innerHTML));
    if (toDelete.length > 0) {
        yield {
            type: Actions.REMOVE_REFERENCES,
            itemIds: toDelete,
        };
        yield save();
    }
}
開發者ID:dsifford,項目名稱:academic-bloggers-toolkit,代碼行數:29,代碼來源:actions.ts

示例2: updateEditorCitations

function* updateEditorCitations(citations: Processor.CitationMeta[]) {
    const doc = getEditorDOM();
    for (const { html, id, sortedItems } of citations) {
        const node = doc.querySelector<HTMLElement>(
            createSelector(
                ...CitationElement.legacyClassNames.map(cls => ({
                    classNames: [cls],
                    attributes: { id },
                })),
            ),
        );
        if (node) {
            node.innerHTML = html;
            node.dataset.items = sortedItems;
            if (node.firstElementChild) {
                node.dataset.hasChildren = 'true';
                node.firstElementChild.innerHTML =
                    ZERO_WIDTH_SPACE +
                    node.firstElementChild.innerHTML +
                    ZERO_WIDTH_SPACE;
            } else {
                delete node.dataset.hasChildren;
                node.innerHTML = ZERO_WIDTH_SPACE + html + ZERO_WIDTH_SPACE;
            }
        }
    }
    yield dispatch('core/block-editor').resetBlocks(parse(doc.innerHTML));
}
開發者ID:dsifford,項目名稱:academic-bloggers-toolkit,代碼行數:28,代碼來源:actions.ts

示例3: parseFootnotes

export function* parseFootnotes() {
    const doc = getEditorDOM();
    doc.querySelectorAll(FootnoteElement.selector).forEach((footnote, i) => {
        footnote.innerHTML = FootnoteElement.createMarker(i);
    });
    yield dispatch('core/block-editor').resetBlocks(parse(doc.innerHTML));
    yield setFootnotes();
}
開發者ID:dsifford,項目名稱:academic-bloggers-toolkit,代碼行數:8,代碼來源:actions.ts

示例4: removeAllCitations

export function* removeAllCitations() {
    const doc = getEditorDOM();
    for (const el of doc.querySelectorAll(CitationElement.selector)) {
        if (el.parentNode) {
            el.parentNode.removeChild(el);
        }
    }
    yield dispatch('core/block-editor').resetBlocks(parse(doc.innerHTML));
}
開發者ID:dsifford,項目名稱:academic-bloggers-toolkit,代碼行數:9,代碼來源:actions.ts

示例5: removeFootnotes

export function* removeFootnotes(itemIds: string[]) {
    const doc = getEditorDOM();
    let removedItems = 0;
    for (const footnote of doc.querySelectorAll(FootnoteElement.selector)) {
        if (itemIds.includes(`${footnote.id}-ref`) && footnote.parentNode) {
            footnote.parentNode.removeChild(footnote);
            removedItems++;
        }
    }
    if (removedItems > 0) {
        yield save();
    }
}
開發者ID:dsifford,項目名稱:academic-bloggers-toolkit,代碼行數:13,代碼來源:actions.ts


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