本文整理匯總了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
};
};