本文整理汇总了TypeScript中tinymce/core/api/dom/DOMUtils.getRoot函数的典型用法代码示例。如果您正苦于以下问题:TypeScript getRoot函数的具体用法?TypeScript getRoot怎么用?TypeScript getRoot使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getRoot函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: resolvePathRange
}, (areas) => {
const outermostRange = resolvePathRange(dom.getRoot(), areas[areas.length - 1].range).getOrDie('Internal constraint violation');
const start = findInlinePatternStart(dom, pattern, outermostRange.startNode, outermostRange.startOffset, block);
return start.map(({node: startNode, offset: startOffset}) => {
const range = generatePathRange(dom.getRoot(), startNode, startOffset, endNode, endOffset).getOrDie('Internal constraint violation');
return areas.concat([{ pattern, range }]);
});
});
示例2:
return Options.lift(start, end, (start, end) => {
const range = dom.createRng();
range.setStartAfter(start);
if (!isCollapsed(start, end, dom.getRoot())) {
range.setEndBefore(end);
} else {
range.collapse(true);
}
return range;
});
示例3: generatePathRange
return start.map(({node: startNode, offset: startOffset}) => {
const range = generatePathRange(dom.getRoot(), startNode, startOffset, endNode, endOffset).getOrDie('Internal constraint violation');
return areas.concat([{ pattern, range }]);
});
示例4: resolvePath
const applyInlinePatterns = (editor: Editor, areas: InlinePatternMatch[]) => {
const dom: DOMUtils = editor.dom;
const newMarker = (id: string) => dom.create('span', {'data-mce-type': 'bookmark', 'id': id});
const markerRange = (ids: {start: string, end?: string}) => {
const start = Option.from(dom.select('#' + ids.start)[0]);
const end = Option.from(dom.select('#' + ids.end)[0]);
return Options.lift(start, end, (start, end) => {
const range = dom.createRng();
range.setStartAfter(start);
if (!isCollapsed(start, end, dom.getRoot())) {
range.setEndBefore(end);
} else {
range.collapse(true);
}
return range;
});
};
const markerPrefix = Id.generate('mce_');
const markerIds = Arr.map(areas, (_area, i) => {
return {
start: markerPrefix + '_' + i + '_start',
end: markerPrefix + '_' + i + '_end',
};
});
// store the cursor position
const cursor = editor.selection.getBookmark();
// add marks for the left and right sides of the ranges and delete the pattern start/end
for (let i = areas.length - 1; i >= 0; i--) {
// insert right side marker
const { pattern, range } = areas[i];
const { node: endNode, offset: endOffset } = resolvePath(dom.getRoot(), range.end).getOrDie('Failed to resolve range[' + i + '].end');
const textOutsideRange = endOffset === 0 ? endNode : endNode.splitText(endOffset);
textOutsideRange.parentNode.insertBefore(newMarker(markerIds[i].end), textOutsideRange);
if (pattern.start.length > 0) {
endNode.deleteData(endOffset - pattern.end.length, pattern.end.length);
}
}
for (let i = 0; i < areas.length; i++) {
// insert left side marker
const { pattern, range } = areas[i];
const { node: startNode, offset: startOffset } = resolvePath(dom.getRoot(), range.start).getOrDie('Failed to resolve range.start');
const textInsideRange = startOffset === 0 ? startNode : startNode.splitText(startOffset);
textInsideRange.parentNode.insertBefore(newMarker(markerIds[i].start), textInsideRange);
// delete the start pattern
if (pattern.start.length > 0) {
textInsideRange.deleteData(0, pattern.start.length);
} else {
textInsideRange.deleteData(0, pattern.end.length);
}
}
// apply the patterns
for (let i = 0; i < areas.length; i++) {
const { pattern } = areas[i];
const optRange = markerRange(markerIds[i]);
optRange.each((range) => {
editor.selection.setRng(range);
if (pattern.type === 'inline-format') {
pattern.format.forEach((format) => {
editor.formatter.apply(format);
});
} else {
editor.execCommand(pattern.cmd, false, pattern.value);
}
});
// remove the markers
dom.remove(markerIds[i].start);
dom.remove(markerIds[i].end);
}
// return the selection
editor.selection.moveToBookmark(cursor);
};