OXIESEC PANEL
- Current Dir:
/
/
var
/
www
/
reader
/
_backup
/
tinymce
/
tinymce
/
src
/
core
/
main
/
ts
/
caret
Server IP: 139.59.38.164
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
02/20/2020 05:44:43 AM
rwxr-xr-x
📄
BlockBoundary.ts
1.53 KB
02/20/2020 05:42:20 AM
rw-r--r--
📄
CaretBr.ts
1.47 KB
02/20/2020 05:42:20 AM
rw-r--r--
📄
CaretCandidate.ts
2.68 KB
02/20/2020 05:42:21 AM
rw-r--r--
📄
CaretContainer.ts
5.4 KB
02/20/2020 05:42:21 AM
rw-r--r--
📄
CaretContainerInline.ts
2.23 KB
02/20/2020 05:42:22 AM
rw-r--r--
📄
CaretContainerInput.ts
1.87 KB
02/20/2020 05:42:22 AM
rw-r--r--
📄
CaretContainerRemove.ts
3.3 KB
02/20/2020 05:42:23 AM
rw-r--r--
📄
CaretFinder.ts
4.09 KB
02/20/2020 05:42:25 AM
rw-r--r--
📄
CaretPosition.ts
13.27 KB
02/20/2020 05:42:26 AM
rw-r--r--
📄
CaretPositionPredicates.ts
2.24 KB
02/20/2020 05:42:27 AM
rw-r--r--
📄
CaretUtils.ts
8.54 KB
02/20/2020 05:42:27 AM
rw-r--r--
📄
CaretWalker.ts
7.67 KB
02/20/2020 05:42:28 AM
rw-r--r--
📄
FakeCaret.ts
6.26 KB
02/20/2020 05:42:28 AM
rw-r--r--
📄
InsertText.ts
1.32 KB
02/20/2020 05:42:29 AM
rw-r--r--
📄
LineReader.ts
5.88 KB
02/20/2020 05:42:29 AM
rw-r--r--
📄
LineUtils.ts
4.11 KB
02/20/2020 05:42:30 AM
rw-r--r--
📄
LineWalker.ts
4.56 KB
02/20/2020 05:42:30 AM
rw-r--r--
📄
TableCells.ts
3.58 KB
02/20/2020 05:42:31 AM
rw-r--r--
Editing: TableCells.ts
Close
/** * Copyright (c) Tiny Technologies, Inc. All rights reserved. * Licensed under the LGPL or a commercial license. * For LGPL see License.txt in the project root for license information. * For commercial licenses see https://www.tiny.cloud/ */ import { ClientRect, HTMLElement } from '@ephox/dom-globals'; import { Arr, Fun, Option } from '@ephox/katamari'; import { Element, SelectorFilter } from '@ephox/sugar'; import { findClosestHorizontalPosition, getLastLinePositions, getFirstLinePositions } from './LineReader'; import { CaretPosition } from './CaretPosition'; import { clone as roundRect } from '../geom/ClientRect'; type GetAxisValue = (rect: ClientRect) => number; type IsTargetCorner = (corner: Corner, y: number) => boolean; interface Corner { x: number; y: number; cell: HTMLElement; } const deflate = (rect: ClientRect, delta: number): ClientRect => { return { left: rect.left - delta, top: rect.top - delta, right: rect.right + delta * 2, bottom: rect.bottom + delta * 2, width: rect.width + delta, height: rect.height + delta }; }; const getCorners = (getYAxisValue, tds: HTMLElement[]): Corner[] => { return Arr.bind(tds, (td) => { const rect = deflate(roundRect(td.getBoundingClientRect()), -1); return [ { x: rect.left, y: getYAxisValue(rect), cell: td }, { x: rect.right, y: getYAxisValue(rect), cell: td } ]; }); }; 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()); }; const getClosestCell = (getYAxisValue: GetAxisValue, isTargetCorner: IsTargetCorner, table: HTMLElement, x: number, y: number): Option<HTMLElement> => { const cells = SelectorFilter.descendants(Element.fromDom(table), 'td,th,caption').map((e) => e.dom()); 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<HTMLElement>; const getClosestCellBelow = Fun.curry(getClosestCell, getTopValue, isBelow) as (table: HTMLElement, x: number, y: number) => Option<HTMLElement>; const findClosestPositionInAboveCell = (table: HTMLElement, pos: CaretPosition): Option<CaretPosition> => { 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<CaretPosition> => { return Arr.last(pos.getClientRects()).bind((rect) => { return getClosestCellBelow(table, rect.left, rect.top); }).bind((cell) => findClosestHorizontalPosition(getFirstLinePositions(cell), pos)); }; export { getClosestCellAbove, getClosestCellBelow, findClosestPositionInAboveCell, findClosestPositionInBelowCell };