Step.sync(function () { const headStuff = editor.getDoc().head.querySelectorAll('link, style'); const linkIndex = Arr.findIndex(headStuff, function (elm) { return Node.name(Element.fromDom(elm)) === 'link'; }).getOrDie('could not find link elemnt'); const styleIndex = Arr.findIndex(headStuff, function (elm) { return elm.innerText === contentStyle; }).getOrDie('could not find content style tag'); Assertions.assertEq('style tag should be after link tag', linkIndex < styleIndex, true); })
const getChildrenUntilBlockBoundary = (block: Element) => { const children = Traverse.children(block); return Arr.findIndex(children, ElementType.isBlock).fold( () => children, (index) => children.slice(0, index) ); };
const getParentInlines = function (rootElm, startElm) { const parents = Parents.parentsAndSelf(startElm, rootElm); return Arr.findIndex(parents, ElementType.isBlock).fold( Fun.constant(parents), function (index) { return parents.slice(0, index); } ); };
const closeNotification = function (notification) { Arr.findIndex(notifications, function (otherNotification) { return otherNotification === notification; }).each(function (index) { // Mutate here since third party might have stored away the window array // TODO: Consider breaking this api notifications.splice(index, 1); }); };
const getChildrenUntilBlockBoundary = function (block) { const children = Traverse.children(block); return Arr.findIndex(children, ElementType.isBlock).fold( function () { return children; }, function (index) { return children.slice(0, index); } ); };
const closeWindow = function (win) { Arr.findIndex(windows, function (otherWindow) { return otherWindow === win; }).each(function (index) { // Mutate here since third party might have stored away the window array, consider breaking this api windows.splice(index, 1); fireCloseEvent(win); // Move focus back to editor when the last window is closed if (windows.length === 0) { editor.focus(); } }); };
const detectSize = (comp: AlloyComponent, margin: number, selectorClass: string): Option<{ numColumns: number, numRows: number}> => { const descendants = SelectorFilter.descendants(comp.element(), '.' + selectorClass); // TODO: This seems to cause performance issues in the emoji dialog if (descendants.length > 0) { const columnLength = Arr.findIndex(descendants, (c) => { const thisTop = c.dom().getBoundingClientRect().top; const cTop = descendants[0].dom().getBoundingClientRect().top; return Math.abs(thisTop - cTop) > margin; }).getOr(descendants.length); return Option.some({ numColumns: columnLength, numRows: Math.ceil(descendants.length / columnLength) }); } else { return Option.none(); } };
const getCellIndex = (cells, cell) => { return Arr.findIndex(cells, (x) => Compare.eq(x, cell)); };
const sizeToIndex = function (size) { return Arr.findIndex(candidates, function (v) { return v === size; }); };
const hasItemName = function (namedMenuItems, name) { return Arr.findIndex(namedMenuItems, function (namedMenuItem) { return namedMenuItem.name === name; }).isSome(); };