Example #1
0
const getNewRowCursorPosition = function (editor, table) {
  const rows = SelectorFilter.descendants(table, 'tr');
  return Arr.last(rows).bind(function (last) {
    return SelectorFind.descendant(last, 'td,th').map(function (first) {
      return getCellFirstCursorPosition(editor, first);
    });
  });
};
Example #2
0
const createJoinedSections = (scope: Document, length: number, listType: ListType): Section[] => {
  const sections: Section[] = [];
  for (let i = 0; i < length; i++) {
    const newSection = createSection(scope, listType);
    Arr.last(sections).each((lastSection) => joinSections(lastSection, newSection));
    sections.push(newSection);
  }
  return sections;
};
Example #3
0
const populateSegments = (segments: Segment[], entry: Entry): void => {
  for (let i = 0; i < segments.length - 1; i++) {
    Css.set(segments[i].item, 'list-style-type', 'none');
  }
  Arr.last(segments).each((segment) => {
    Attr.setAll(segment.list, entry.listAttributes);
    Attr.setAll(segment.item, entry.itemAttributes);
    InsertAll.append(segment.item, entry.content);
  });
};
Example #4
0
const writeDeep = (scope: Document, outline: Section[], entry: Entry): Section[] => {
  const newSections = createJoinedSections(scope, entry.depth - outline.length, entry.listType);
  populateSections(newSections, entry);

  Options.liftN([
    Arr.last(outline),
    Arr.head(newSections)
  ], joinSections);
  return outline.concat(newSections);
};
Example #5
0
const writeShallow = (scope: Document, outline: Section[], entry: Entry): Section[] => {
  const newOutline = outline.slice(0, entry.depth);

  Arr.last(newOutline).each((section) => {
    setItem(section, createItem(scope, entry.itemAttributes, entry.content));
    normalizeSection(section, entry);
  });

  return newOutline;
};
Example #6
0
const writeShallow = (scope: Document, cast: Segment[], entry: Entry): Segment[] => {
  const newCast = cast.slice(0, entry.depth);

  Arr.last(newCast).each((segment) => {
    const item = createItem(scope, entry.itemAttributes, entry.content);
    appendItem(segment, item);
    normalizeSegment(segment, entry);
  });

  return newCast;
};
Example #7
0
 AlloyEvents.run<BackwardSlideEvent>(backSlideEvent, (comp, se) => {
   Arr.last(stack.get()).each((last) => {
     stack.set(stack.get().slice(0, stack.get().length - 1));
     AlloyTriggers.emitWith(comp, changeSlideEvent, {
       // Because we are using premade, we should have access to the same element
       // to give focus (although it isn't working)
       contents: GuiFactory.premade(last.bar),
       focus: last.focus
     });
   });
 }),
Example #8
0
 return () => {
   const from = forward ? CaretPosition.fromRangeEnd(editor.selection.getRng()) : CaretPosition.fromRangeStart(editor.selection.getRng());
   const result = forward ? getPositionsUntilNextLine(editor.getBody(), from) : getPositionsUntilPreviousLine(editor.getBody(), from);
   const to = forward ? Arr.last(result.positions) : Arr.head(result.positions);
   return to.filter(isCefPosition(forward)).fold(
     Fun.constant(false),
     (pos) => {
       editor.selection.setRng(pos.toRange());
       return true;
     }
   );
 };
Example #9
0
        onEscape: (comp) => {

          return Arr.last(stack.get()).fold(
            () => {
              // Escape just focuses the content. It no longer closes the toolbar.
              return spec.onEscape();
            },
            (_) => {
              AlloyTriggers.emit(comp, backSlideEvent);
              return Option.some(true);
            }
          );
        }
Example #10
0
const addContextMenuGroup = (xs: Array<MenuItem>, groupItems: Array<MenuItem>) => {
  // Skip if there are no items
  if (groupItems.length === 0) {
    return xs;
  }

  // Only add a separator at the beginning if the last item isn't a separator
  const lastMenuItem = Arr.last(xs).filter((item) => !isSeparator(item));
  const before = lastMenuItem.fold(
    () => [],
    (_) => [ separator ]
  );
  return xs.concat(before).concat(groupItems).concat([ separator ]);
};
Example #11
0
const deleteCaret = function (editor, forward) {
  const rootElm = Element.fromDom(editor.getBody());
  const startElm = Element.fromDom(editor.selection.getStart());
  const parentInlines = Arr.filter(getParentInlines(rootElm, startElm), hasOnlyOneChild);

  return Arr.last(parentInlines).map(function (target) {
    const fromPos = CaretPosition.fromRangeStart(editor.selection.getRng());
    if (DeleteUtils.willDeleteLastPositionInElement(forward, fromPos, target.dom())) {
      deleteLastPosition(forward, editor, target, parentInlines);
      return true;
    } else {
      return false;
    }
  }).getOr(false);
};
Example #12
0
const findLastParentListNode = (editor: Editor, elm: Node): Option<Node> => {
  const parentLists = editor.dom.getParents(elm, 'ol,ul', getClosestListRootElm(editor, elm));
  return Arr.last(parentLists);
};
Example #13
0
const isAbove = (pos1: CaretPosition, pos2: CaretPosition): boolean => {
  return Options.liftN([Arr.head(pos2.getClientRects()), Arr.last(pos1.getClientRects())], ClientRect.isAbove).getOr(false);
};
Example #14
0
 export const isBelow = (pos1: CaretPosition, pos2: CaretPosition): boolean => {
   return Options.liftN([Arr.last(pos2.getClientRects()), Arr.head(pos1.getClientRects())], GeomClientRect.isBelow).getOr(false);
 };
Example #15
0
const findClosestPositionInBelowCell = (table: HTMLElement, pos: CaretPosition): Option<CaretPosition> => {
  return Arr.last(pos.getClientRects()).bind((rect) => {
    return getClosestCellBelow(table, rect.left, rect.top);
  }).bind((cell) => findClosestHorizontalPosition(getFirstLinePositions(cell), pos));
};
 (startCell) => getClosestTable(startCell, isRoot).bind((table) => {
   return Arr.last(getTableCells(table)).map((endCell) => tableCellRng(startCell, endCell));
 })
const getCellRangeFromStartTable = (cellRng: any, isRoot) => getClosestTable(cellRng.start(), isRoot).bind((table) => {
  return Arr.last(getTableCells(table)).map((endCell) => tableCellRng(cellRng.start(), endCell));
});
Example #18
0
const appendSegments = (head: Segment[], tail: Segment[]): void => {
  Options.liftN([ Arr.last(head), Arr.head(tail)], joinSegment);
};