本文整理汇总了TypeScript中@ephox/sugar.Traverse类的典型用法代码示例。如果您正苦于以下问题:TypeScript Traverse类的具体用法?TypeScript Traverse怎么用?TypeScript Traverse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Traverse类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
const parentsUntil = function (startNode, rootElm, predicate) {
if (Compare.contains(rootElm, startNode)) {
return dropLast(Traverse.parents(startNode, function (elm) {
return predicate(elm) || Compare.eq(elm, rootElm);
}));
} else {
return [];
}
};
示例2: function
const trimBlockTrailingBr = function (elm) {
Traverse.lastChild(elm).each(function (lastChild) {
Traverse.prevSibling(lastChild).each(function (lastChildPrevSibling) {
if (ElementType.isBlock(elm) && ElementType.isBr(lastChild) && ElementType.isBlock(lastChildPrevSibling)) {
Remove.remove(lastChild);
}
});
});
};
示例3:
Logger.t('Editor element properties', Step.sync(function () {
const body = Element.fromDom(document.body);
const targetElement = SelectorFind.descendant(body, '#' + editor.id).getOrDie('No elm');
const editorElement = Traverse.nextSibling(targetElement).getOrDie('No elm');
Assertions.assertDomEq('Should be expected element', editorElement, Element.fromDom(editor.editorContainer));
Assertions.assertDomEq('Should be expected element', editorElement, Element.fromDom(editor.contentAreaContainer));
Assertions.assertDomEq('Should be expected element', targetElement, Element.fromDom(editor.getElement()));
}))
示例4:
return Chain.op(function () {
const sc = Hierarchy.follow(Element.fromDom(viewBlock.get()), startPath).getOrDie('invalid startPath');
const fc = Hierarchy.follow(Element.fromDom(viewBlock.get()), finishPath).getOrDie('invalid finishPath');
const win = Traverse.defaultView(sc);
WindowSelection.setExact(
win.dom(), sc, soffset, fc, foffset
);
});
示例5: function
const moveWindowScroll = function (toolbar, viewport, destY) {
const outerWindow = Traverse.owner(toolbar).dom().defaultView;
return Future.nu(function (callback) {
updateTop(toolbar, destY);
updateTop(viewport, destY);
outerWindow.scrollTo(0, destY);
callback(destY);
});
};
示例6:
bookmark.each(function (b) {
const root = Element.fromDom(viewBlock.get());
const win = Traverse.defaultView(root);
SelectionBookmark.validate(root, b)
.each(function (rng) {
WindowSelection.setExact(win.dom(), rng.start(), rng.soffset(), rng.finish(), rng.foffset());
});
});
示例7:
const isChild = (first: boolean, elm: Element): boolean => {
const start = Element.fromDom(elm);
const pointOp = first ? Arr.head : Arr.last;
return Traverse.parent(start)
.map((parent) => PredicateFilter.children(parent, (elm) => NodeType.isBogus(elm.dom()) === false))
.bind(pointOp)
.map((node) => Compare.eq(node, start))
.getOr(false);
};
示例8: function
function (child) {
if (Node.name(child) === 'br') {
return Traverse.prevSibling(child).map(function (sibling) {
return [node].concat(getLastChildren(sibling));
}).getOr([]);
} else {
return [node].concat(getLastChildren(child));
}
}
示例9: function
const getInsertionPoint = function (fromBlock, toBlock) {
if (Compare.contains(toBlock, fromBlock)) {
return Traverse.parent(fromBlock).bind(function (parent) {
return Compare.eq(parent, toBlock) ? Option.some(fromBlock) : findParentInsertPoint(toBlock, fromBlock);
});
} else {
return Option.none();
}
};
示例10: function
const takeover = function (viewport, contentBody, toolbar, dropup) {
const outerWindow = Traverse.owner(viewport).dom().defaultView;
const toolbarSetup = takeoverToolbar(toolbar);
const toolbarHeight = Height.get(toolbar);
const dropupHeight = Height.get(dropup);
const viewportHeight = deriveViewportHeight(viewport, toolbarHeight, dropupHeight);
const viewportSetup = takeoverViewport(toolbarHeight, viewportHeight, viewport);
const dropupSetup = takeoverDropup(dropup, toolbarHeight, viewportHeight);
let isActive = true;
const restore = function () {
isActive = false;
toolbarSetup.restore();
viewportSetup.restore();
dropupSetup.restore();
};
const isExpanding = function () {
const currentWinHeight = outerWindow.innerHeight;
const lastWinHeight = getLastWindowSize(viewport);
return currentWinHeight > lastWinHeight;
};
const refresh = function () {
if (isActive) {
const newToolbarHeight = Height.get(toolbar);
const dropupHeight = Height.get(dropup);
const newHeight = deriveViewportHeight(viewport, newToolbarHeight, dropupHeight);
Attr.set(viewport, yFixedData, newToolbarHeight + 'px');
Css.set(viewport, 'height', newHeight + 'px');
Css.set(dropup, 'bottom', -(newToolbarHeight + newHeight + dropupHeight) + 'px');
DeviceZones.updatePadding(contentBody, viewport, dropup);
}
};
const setViewportOffset = function (newYOffset) {
const offsetPx = newYOffset + 'px';
Attr.set(viewport, yFixedData, offsetPx);
// The toolbar height has probably changed, so recalculate the viewport height.
refresh();
};
DeviceZones.updatePadding(contentBody, viewport, dropup);
return {
setViewportOffset,
isExpanding,
isShrinking: Fun.not(isExpanding),
refresh,
restore
};
};