Example #1
0
  suite.test('getClientRects from array', function () {
    const viewElm = setupHtml('<b>a</b><b>b</b>');
    const clientRects = Dimensions.getClientRects(Arr.from(viewElm.childNodes));

    LegacyUnit.strictEqual(clientRects.length, 2);
    LegacyUnit.equalDom(clientRects[0].node, viewElm.childNodes[0]);
    LegacyUnit.equalDom(clientRects[1].node, viewElm.childNodes[1]);
  });
const removeElementAndReposition = (caretContainer: Node, pos: CaretPosition): CaretPosition => {
  const parentNode = pos.container();
  const newPosition = Arr.indexOf(Arr.from(parentNode.childNodes), caretContainer).map(function (index) {
    return index < pos.offset() ? CaretPosition(parentNode, pos.offset() - 1) : pos;
  }).getOr(pos);
  remove(caretContainer);
  return newPosition;
};
Example #3
0
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;
};
Example #4
0
const getFakeCaretTargets = (root: HTMLElement): HTMLElement[] => {
  return Arr.filter(Arr.from(root.getElementsByTagName('*')), isFakeCaretTarget) as HTMLElement[];
};
Example #5
0
const write = function (fragments: string[], elm: Element): Element {
  const currentFragments = Arr.map(Arr.from(elm.childNodes), getOuterHtml);
  applyDiff(Diff.diff(currentFragments, fragments), elm);
  return elm;
};
Example #6
0
const read = function (elm: Element): string[] {
  return Arr.filter(Arr.map(Arr.from(elm.childNodes), getOuterHtml), function (item) {
    return item.length > 0;
  });
};
Example #7
0
const filterByExtension = function (files: FileList) {
  const re = new RegExp('(' + extensionsAccepted.split(/\s*,\s*/).join('|') + ')$', 'i');
  return Arr.filter(Arr.from(files), (file) => re.test(file.name));
};
Example #8
0
const getImagesFromDataTransfer = (dataTransfer: DataTransfer) => {
  const items = dataTransfer.items ? Arr.map(Arr.from(dataTransfer.items), (item) => item.getAsFile()) : [];
  const files = dataTransfer.files ? Arr.from(dataTransfer.files) : [];
  const images = Arr.filter(items.length > 0 ? items : files, (file) => /^image\/(jpeg|png|gif|bmp)$/.test(file.type));
  return images;
};
Example #9
0
const getAllImages = function (elm: HTMLElement): HTMLImageElement[] {
  return elm ? Arr.from(elm.getElementsByTagName('img')) : [];
};