本文整理汇总了TypeScript中@typewriter/editor.Delta.insert方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Delta.insert方法的具体用法?TypeScript Delta.insert怎么用?TypeScript Delta.insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@typewriter/editor.Delta
的用法示例。
在下文中一共展示了Delta.insert方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: embed
embed(at: number, attributes: { [name: string]: any }) {
this.updatePosition(at);
this.delta.insert({ decorator: attributes });
this.position += 1;
}
示例2: deltaFromDom
export function deltaFromDom(root: Element, paper: Paper, options: any = {}) {
const inDom = root.ownerDocument.contains(root);
const { blocks, marks, embeds } = paper;
if (!options) options = defaultOptions;
var walker = root.ownerDocument.createTreeWalker(root, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT, {
acceptNode: node => {
if (SKIP_ELEMENTS[node.nodeName]) {
return NodeFilter.FILTER_REJECT;
} else if (node.nodeType === Node.TEXT_NODE && node.nodeValue === '') {
node.nodeType === Node.TEXT_NODE;
} else if (node.nodeType === Node.TEXT_NODE || options.notInDom || inDom) {
return NodeFilter.FILTER_ACCEPT;
} else {
return NodeFilter.FILTER_REJECT;
}
}
});
const delta = new Delta();
let currentBlock: any, firstBlockSeen = false, unknownBlock = false, empty = true, node: Node;
let lastNode = false;
if (options.startNode) {
walker.currentNode = options.startNode;
walker.previousNode();
if (options.offset) delta.retain(options.offset, undefined);
} else {
walker.currentNode = root;
}
while ((node = walker.nextNode())) {
if (node === options.endNode) lastNode = true;
else if (lastNode) break;
if (isBRPlaceholder(paper, node)) {
empty = false;
} else if (node.nodeType === Node.TEXT_NODE) {
let parent = node.parentNode as Element;
// If all newlines, we can ignore
if (node.nodeValue.replace(/\n+/g, '') === '') continue;
// non-breaking spaces ( ) are spaces in a delta
const text = node.nodeValue.replace(/\xA0/g, ' ').replace(/\n+/g, ' ');
// Word gives us end-of-paragraph nodes with a single space. Ignore them.
if (!text || (text === ' ' && parent.classList.contains('EOP'))) continue;
// Gather up all the marks for this text node, walking up to the block level
const attributes = gatherMarks(parent, root, paper);
empty = false;
delta.insert(text, attributes);
} else if (node.className.indexOf('decorator') !== -1) {
continue;
} else if (embeds.matches(node)) {
const embed = embeds.findByNode(node);
if (embed) {
const attributes = gatherMarks(node.parentNode as Element, root, paper);
delta.insert(embed.fromDom ? embed.fromDom(node, paper) : { [embed.name]: true }, attributes);
}
} else if (blocks.matches(node) || (node.nodeType === Node.ELEMENT_NODE && (node as Element).matches(BLOCK_ELEMENTS))) {
unknownBlock = !blocks.matches(node);
if (unknownBlock) {
let parent = node.parentNode;
while (parent && !blocks.matches(parent) && parent !== root) {
parent = parent.parentNode;
}
// If this block element is inside a recognized block, ignore it
if (parent && parent !== root) {
continue;
}
}
const block = blocks.findByNode(node, true);
// Skip paragraphs/divs inside blockquotes and list items etc.
if (block === blocks.getDefault() && blocks.matches(node.parentNode)) {
continue;
}
if (firstBlockSeen) {
if (!currentBlock.unknownBlock || !empty) {
delta.insert('\n', currentBlock.unknownBlock ? {} : currentBlock);
empty = true;
}
} else {
firstBlockSeen = true;
}
if (unknownBlock) {
currentBlock = { unknownBlock };
} else if (block !== blocks.getDefault()) {
currentBlock = block.fromDom ? block.fromDom(node, paper) : { [block.name]: true };
} else {
currentBlock = {};
}
}
}
//.........这里部分代码省略.........