How to use the @ephox/katamari.Fun.curry function in @ephox/katamari

To help you get started, we’ve selected a few @ephox/katamari examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tinymce / tinymce / modules / tinymce / src / plugins / table / main / ts / ui / Helpers.ts View on Github external
const alignmentData = {};
  Tools.each(alignments.split(' '), (name) => {
    if (editor.formatter.matchNode(elm, formatName + name)) {
      alignmentData[dataName] = name;
    }
  });

  if (!alignmentData[dataName]) {
    // TODO: Note, this isn't a real value. But maybe that is OK?
    alignmentData[dataName] = '';
  }

  return alignmentData;
};

const getHAlignment = Fun.curry(getAlignment, 'left center right');
const getVAlignment = Fun.curry(getAlignment, 'top middle bottom');

export interface TableData {
  height: string;
  width: string;
  cellspacing: string;
  cellpadding: string;
  caption: boolean;
  class?: string;
  align: string;
  border: string;
  cols?: string;
  rows?: string;
  borderstyle?: string;
  bordercolor?: string;
  backgroundcolor?: string;
github tinymce / tinymce / modules / tinymce / src / plugins / table / main / ts / ui / Helpers.ts View on Github external
Tools.each(alignments.split(' '), (name) => {
    if (editor.formatter.matchNode(elm, formatName + name)) {
      alignmentData[dataName] = name;
    }
  });

  if (!alignmentData[dataName]) {
    // TODO: Note, this isn't a real value. But maybe that is OK?
    alignmentData[dataName] = '';
  }

  return alignmentData;
};

const getHAlignment = Fun.curry(getAlignment, 'left center right');
const getVAlignment = Fun.curry(getAlignment, 'top middle bottom');

export interface TableData {
  height: string;
  width: string;
  cellspacing: string;
  cellpadding: string;
  caption: boolean;
  class?: string;
  align: string;
  border: string;
  cols?: string;
  rows?: string;
  borderstyle?: string;
  bordercolor?: string;
  backgroundcolor?: string;
}
github tinymce / tinymce / modules / tinymce / src / core / main / ts / delete / CefBoundaryDelete.ts View on Github external
const deleteCefBoundaryText = function (editor: Editor, forward: boolean) {
  const range = editor.selection.getRng();
  if (!NodeType.isText(range.commonAncestorContainer)) {
    return false;
  }

  const direction = forward ? HDirection.Forwards : HDirection.Backwards;
  const caretWalker = CaretWalker(editor.getBody());
  const getNextVisualCaretPosition = Fun.curry(CaretUtils.getVisualCaretPosition, caretWalker.next);
  const getPrevVisualCaretPosition = Fun.curry(CaretUtils.getVisualCaretPosition, caretWalker.prev);
  const getNextPosFn = forward ? getNextVisualCaretPosition : getPrevVisualCaretPosition;
  const isBeforeContentEditableFalseFn = forward ? isBeforeContentEditableFalse : isAfterContentEditableFalse;

  // Get the next caret position. ie where it'll be after the delete
  const caretPosition = CaretUtils.getNormalizedRangeEndPoint(direction, editor.getBody(), range);
  const nextCaretPosition = InlineUtils.normalizePosition(forward, getNextPosFn(caretPosition));
  if (!nextCaretPosition || !CaretUtils.isMoveInsideSameBlock(caretPosition, nextCaretPosition)) {
    return false;
  } else if (isBeforeContentEditableFalseFn(nextCaretPosition)) {
    return deleteContentAndShowCaret(editor, range, caretPosition.getNode(), direction, forward, nextCaretPosition);
  }

  // Peek ahead and see if the next element is a cef element
  const peekCaretPosition = getNextPosFn(nextCaretPosition);
  if (peekCaretPosition && isBeforeContentEditableFalseFn(peekCaretPosition)) {
    if (CaretUtils.isMoveInsideSameBlock(nextCaretPosition, peekCaretPosition)) {
github tinymce / tinymce / src / core / main / ts / keyboard / ContentEndpointNavigation.ts View on Github external
const getClosestTargetBlock = (pos: CaretPosition, root: Element) => {
  const isRoot = Fun.curry(Compare.eq, root);
  return PredicateFind.closest(Element.fromDom(pos.container()), ElementType.isBlock, isRoot).filter(isTarget);
};
github tinymce / tinymce / modules / tinymce / src / core / main / ts / caret / CaretBr.ts View on Github external
const findBr = (forward: boolean, root: Element, pos: CaretPosition) => {
  const parentBlocks = Arr.filter(Parents.parentsAndSelf(Element.fromDom(pos.container()), root), ElementType.isBlock);
  const scope = Arr.head(parentBlocks).getOr(root);
  return CaretFinder.fromPosition(forward, scope.dom(), pos).filter(isBr);
};

const isBeforeBr = (root: Element, pos: CaretPosition) => {
  return getElementFromPosition(pos).exists(ElementType.isBr) || findBr(true, root, pos).isSome();
};

const isAfterBr = (root: Element, pos: CaretPosition) => {
  return getElementFromPrevPosition(pos).exists(ElementType.isBr) || findBr(false, root, pos).isSome();
};

const findPreviousBr = Fun.curry(findBr, false);
const findNextBr = Fun.curry(findBr, true);

export {
  findPreviousBr,
  findNextBr,
  isBeforeBr,
  isAfterBr
};
github tinymce / tinymce / src / core / main / ts / caret / BlockBoundary.ts View on Github external
};

const isAtBlockBoundary = (forward: boolean, root: Element, pos: CaretPosition) => {
  return getClosestBlock(root, pos).fold(
    () => {
      return navigateIgnoreEmptyTextNodes(forward, root.dom(), pos).forall((newPos) => {
        return isInSameBlock(newPos, pos, root.dom()) === false;
      });
    },
    (parent) => {
      return navigateIgnoreEmptyTextNodes(forward, parent.dom(), pos).isNone();
    }
  );
};

const isAtStartOfBlock = Fun.curry(isAtBlockBoundary, false);
const isAtEndOfBlock = Fun.curry(isAtBlockBoundary, true);
const isBeforeBlock = Fun.curry(isAtBeforeAfterBlockBoundary, false);
const isAfterBlock = Fun.curry(isAtBeforeAfterBlockBoundary, true);

export {
  isAtStartOfBlock,
  isAtEndOfBlock,
  isBeforeBlock,
  isAfterBlock
};
github tinymce / tinymce / modules / tinymce / src / core / main / ts / caret / InsertText.ts View on Github external
} else {
    return getElementFromPosition(pos).map((elm) => {
      const textNode = Element.fromText(text);

      if (pos.isAtEnd()) {
        Insert.after(elm, textNode);
      } else {
        Insert.before(elm, textNode);
      }

      return CaretPosition(textNode.dom(), text.length);
    });
  }
};

const insertNbspAtPosition = Fun.curry(insertTextAtPosition, '\u00a0');
const insertSpaceAtPosition = Fun.curry(insertTextAtPosition, ' ');

export {
  insertTextAtPosition,
  insertNbspAtPosition,
  insertSpaceAtPosition
};
github tinymce / tinymce / modules / tinymce / src / core / main / ts / caret / InsertText.ts View on Github external
return getElementFromPosition(pos).map((elm) => {
      const textNode = Element.fromText(text);

      if (pos.isAtEnd()) {
        Insert.after(elm, textNode);
      } else {
        Insert.before(elm, textNode);
      }

      return CaretPosition(textNode.dom(), text.length);
    });
  }
};

const insertNbspAtPosition = Fun.curry(insertTextAtPosition, '\u00a0');
const insertSpaceAtPosition = Fun.curry(insertTextAtPosition, ' ');

export {
  insertTextAtPosition,
  insertNbspAtPosition,
  insertSpaceAtPosition
};
github tinymce / tinymce / modules / tinymce / src / core / main / ts / caret / TableCells.ts View on Github external
const getClosestCell = (getYAxisValue: GetAxisValue, isTargetCorner: IsTargetCorner, table: HTMLElement, x: number, y: number): Option => {
  type TableThing = HTMLTableDataCellElement | HTMLTableHeaderCellElement | HTMLTableCaptionElement;
  const cells = SelectorFilter.descendants(Element.fromDom(table), 'td,th,caption').map((e) => e.dom() as TableThing);
  const corners = Arr.filter(getCorners(getYAxisValue, cells), (corner) => isTargetCorner(corner, y));

  return findClosestCorner(corners, x, y).map((corner) => {
    return corner.cell;
  });
};

const getBottomValue = (rect: ClientRect) => rect.bottom;
const getTopValue = (rect: ClientRect) => rect.top;
const isAbove = (corner: Corner, y: number) => corner.y < y;
const isBelow = (corner: Corner, y: number) => corner.y > y;

const getClosestCellAbove = Fun.curry(getClosestCell, getBottomValue, isAbove) as (table: HTMLElement, x: number, y: number) => Option;
const getClosestCellBelow = Fun.curry(getClosestCell, getTopValue, isBelow) as (table: HTMLElement, x: number, y: number) => Option;

const findClosestPositionInAboveCell = (table: HTMLElement, pos: CaretPosition): Option => {
  return Arr.head(pos.getClientRects()).bind((rect) => {
    return getClosestCellAbove(table, rect.left, rect.top);
  }).bind((cell) => findClosestHorizontalPosition(getLastLinePositions(cell), pos));
};

const findClosestPositionInBelowCell = (table: HTMLElement, pos: CaretPosition): Option => {
  return Arr.last(pos.getClientRects()).bind((rect) => {
    return getClosestCellBelow(table, rect.left, rect.top);
  }).bind((cell) => findClosestHorizontalPosition(getFirstLinePositions(cell), pos));
};

export {
  getClosestCellAbove,