当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Arr.foldl方法代码示例

本文整理汇总了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();
  };
开发者ID:danielpunkass,项目名称:tinymce,代码行数:7,代码来源:NewLineAction.ts

示例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;
};
开发者ID:tinymce,项目名称:tinymce,代码行数:26,代码来源:SilverContextMenu.ts

示例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;
};
开发者ID:tinymce,项目名称:tinymce,代码行数:28,代码来源:MenuConversion.ts

示例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);
};
开发者ID:danielpunkass,项目名称:tinymce,代码行数:7,代码来源:ComposeList.ts

示例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;
};
开发者ID:howardjing,项目名称:tinymce,代码行数:7,代码来源:FragmentReader.ts

示例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);
};
开发者ID:abstask,项目名称:tinymce,代码行数:9,代码来源:RangePoint.ts

示例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;
};
开发者ID:danielpunkass,项目名称:tinymce,代码行数:9,代码来源:CaretCandidate.ts

示例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
  });
};
开发者ID:tinymce,项目名称:tinymce,代码行数:11,代码来源:Utils.ts

示例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());
};
开发者ID:abstask,项目名称:tinymce,代码行数:12,代码来源:TableCells.ts

示例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();
  });
};
开发者ID:tinymce,项目名称:tinymce,代码行数:12,代码来源:PathRange.ts


注:本文中的@ephox/katamari.Arr.foldl方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。