本文整理汇总了TypeScript中@ephox/katamari.Arr.foldl方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Arr.foldl方法的具体用法?TypeScript Arr.foldl怎么用?TypeScript Arr.foldl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@ephox/katamari.Arr
的用法示例。
在下文中一共展示了Arr.foldl方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
return function (editor, shiftKey) {
const isMatch = Arr.foldl(predicates, function (res, p) {
return res && p(editor, shiftKey);
}, true);
return isMatch ? Option.some(action) : Option.none();
};
示例2: addContextMenuGroup
const generateContextMenu = (contextMenus: Record<string, Menu.ContextMenuApi>, menuConfig: string[], selectedElement: Element) => {
const items = Arr.foldl(menuConfig, (acc, name) => {
// Either read and convert the list of items out of the plugin, or assume it's a standard menu item reference
if (Obj.has(contextMenus, name)) {
const items = contextMenus[name].update(selectedElement);
if (Type.isString(items)) {
return addContextMenuGroup(acc, items.split(' '));
} else if (items.length > 0) {
// TODO: Should we add a ValueSchema check here?
const allItems = Arr.map(items, makeContextItem);
return addContextMenuGroup(acc, allItems);
} else {
return acc;
}
} else {
return acc.concat([name]);
}
}, []);
// Strip off any trailing separator
if (items.length > 0 && isSeparator(items[items.length - 1])) {
items.pop();
}
return items;
};
示例3: if
const unwrapReferences = (items: Array<string | SingleMenuItemApi>, menuItems: MenuItemRegistry): SingleMenuItemApi[] => {
// Unwrap any string based menu item references
const realItems = Arr.foldl(items, (acc, item) => {
if (isMenuItemReference(item)) {
if (item === '') {
return acc;
} else if (item === '|') {
// Ignore the separator if it's at the start or a duplicate
return acc.length > 0 && !isSeparator(acc[acc.length - 1]) ? acc.concat([separator]) : acc;
} else if (Obj.has(menuItems, item.toLowerCase())) {
return acc.concat([ menuItems[item.toLowerCase()] ]);
} else {
// TODO: Add back after TINY-3232 is implemented
// console.error('No representation for menuItem: ' + item);
return acc;
}
} else {
return acc.concat([ item ]);
}
}, []);
// Remove any trailing separators
if (realItems.length > 0 && isSeparator(realItems[realItems.length - 1])) {
realItems.pop();
}
return realItems;
};
示例4: writeDeep
const composeList = (scope: Document, entries: Entry[]): Option<Element> => {
const cast: Segment[] = Arr.foldl(entries, (cast, entry) => {
return entry.depth > cast.length ? writeDeep(scope, cast, entry) : writeShallow(scope, cast, entry);
}, []);
return Arr.head(cast).map((segment) => segment.list);
};
示例5: function
const wrap = function (innerElm, elms) {
const wrapped = Arr.foldl(elms, function (acc, elm) {
Insert.append(elm, acc);
return elm;
}, innerElm);
return elms.length > 0 ? Fragment.fromElements([wrapped]) : wrapped;
};
示例6: function
const isXYWithinRange = function (clientX, clientY, range) {
if (range.collapsed) {
return false;
}
return Arr.foldl(range.getClientRects(), function (state, rect) {
return state || containsXY(rect, clientX, clientY);
}, false);
};
示例7: function
const isAtomicContentEditableFalse = (node: Node): boolean => {
if (!isNonUiContentEditableFalse(node)) {
return false;
}
return Arr.foldl(Arr.from(node.getElementsByTagName('*')), function (result, elm) {
return result || isContentEditableTrue(elm);
}, false) !== true;
};
示例8:
const getLinkAttrs = (data: LinkDialogOutput): Record<string, string> => {
return Arr.foldl([ 'title', 'rel', 'class', 'target' ], (acc, key) => {
data[key].each((value) => {
// If dealing with an empty string, then treat that as being null so the attribute is removed
acc[key] = value.length > 0 ? value : null;
});
return acc;
}, {
href: data.href
});
};
示例9:
const findClosestCorner = (corners: Corner[], x: number, y: number): Option<Corner> => {
return Arr.foldl(corners, (acc, newCorner) => {
return acc.fold(
() => Option.some(newCorner),
(oldCorner) => {
const oldDist = Math.sqrt(Math.abs(oldCorner.x - x) + Math.abs(oldCorner.y - y));
const newDist = Math.sqrt(Math.abs(newCorner.x - x) + Math.abs(newCorner.y - y));
return Option.some(newDist < oldDist ? newCorner : oldCorner);
}
);
}, Option.none());
};
示例10:
const resolvePath = (root: Node, path: number[]): Option<{node: Text, offset: number}> => {
const nodePath = path.slice();
const offset = nodePath.pop();
return Arr.foldl(nodePath, (optNode: Option<Node>, index: number) => {
return optNode.bind((node) => Option.from(node.childNodes[index]));
}, Option.some(root)).bind((node) => {
if (isText(node) && offset >= 0 && offset <= node.data.length) {
return Option.some({node, offset});
}
return Option.none();
});
};