OXIESEC PANEL
- Current Dir:
/
/
var
/
www
/
reader
/
_backup
/
tinymce
/
tinymce
/
src
/
core
/
main
/
ts
/
delete
Server IP: 139.59.38.164
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
02/20/2020 05:44:43 AM
rwxr-xr-x
📄
BlockBoundaryDelete.ts
950 bytes
02/20/2020 05:42:46 AM
rw-r--r--
📄
BlockMergeBoundary.ts
3.03 KB
02/20/2020 05:42:46 AM
rw-r--r--
📄
BlockRangeDelete.ts
2.51 KB
02/20/2020 05:42:47 AM
rw-r--r--
📄
CefBoundaryDelete.ts
3.77 KB
02/20/2020 05:42:47 AM
rw-r--r--
📄
CefDelete.ts
3.16 KB
02/20/2020 05:42:48 AM
rw-r--r--
📄
CefDeleteAction.ts
5.63 KB
02/20/2020 05:42:49 AM
rw-r--r--
📄
DeleteCommands.ts
2.09 KB
02/20/2020 05:42:49 AM
rw-r--r--
📄
DeleteElement.ts
6.5 KB
02/20/2020 05:42:50 AM
rw-r--r--
📄
DeleteUtils.ts
2.39 KB
02/20/2020 05:42:50 AM
rw-r--r--
📄
ImageBlockDelete.ts
1.23 KB
02/20/2020 05:42:51 AM
rw-r--r--
📄
InlineBoundaryDelete.ts
4.91 KB
02/20/2020 05:42:52 AM
rw-r--r--
📄
InlineFormatDelete.ts
2.38 KB
02/20/2020 05:42:52 AM
rw-r--r--
📄
MergeBlocks.ts
3.69 KB
02/20/2020 05:42:53 AM
rw-r--r--
📄
MergeText.ts
2.9 KB
02/20/2020 05:42:53 AM
rw-r--r--
📄
TableDelete.ts
5.81 KB
02/20/2020 05:42:54 AM
rw-r--r--
📄
TableDeleteAction.ts
4.26 KB
02/20/2020 05:42:54 AM
rw-r--r--
Editing: TableDeleteAction.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 { Adt, Arr, Fun, Option, Options, Struct } from '@ephox/katamari'; import { Compare, Element, SelectorFilter, SelectorFind } from '@ephox/sugar'; import { Range } from '@ephox/dom-globals'; const tableCellRng = Struct.immutable('start', 'end'); const tableSelection = Struct.immutable('rng', 'table', 'cells'); const deleteAction = Adt.generate([ { removeTable: [ 'element' ] }, { emptyCells: [ 'cells' ] } ]); const isRootFromElement = (root) => Fun.curry(Compare.eq, root); const getClosestCell = (container, isRoot) => { return SelectorFind.closest(Element.fromDom(container), 'td,th', isRoot); }; const getClosestTable = (cell, isRoot) => { return SelectorFind.ancestor(cell, 'table', isRoot); }; const isExpandedCellRng = (cellRng) => { return Compare.eq(cellRng.start(), cellRng.end()) === false; }; const getTableFromCellRng = (cellRng, isRoot) => { return getClosestTable(cellRng.start(), isRoot) .bind((startParentTable) => { return getClosestTable(cellRng.end(), isRoot) .bind((endParentTable) => { return Compare.eq(startParentTable, endParentTable) ? Option.some(startParentTable) : Option.none(); }); }); }; const getTableCells = (table) => SelectorFilter.descendants(table, 'td,th'); const getCellRangeFromStartTable = (cellRng: any, isRoot) => getClosestTable(cellRng.start(), isRoot).bind((table) => { return Arr.last(getTableCells(table)).map((endCell) => tableCellRng(cellRng.start(), endCell)); }); const partialSelection = (isRoot, rng) => { const startCell = getClosestCell(rng.startContainer, isRoot); const endCell = getClosestCell(rng.endContainer, isRoot); return rng.collapsed ? Option.none() : Options.liftN([startCell, endCell], tableCellRng).fold( () => startCell.fold( () => endCell.bind((endCell) => getClosestTable(endCell, isRoot).bind((table) => { return Arr.head(getTableCells(table)).map((startCell) => tableCellRng(startCell, endCell)); })), (startCell) => getClosestTable(startCell, isRoot).bind((table) => { return Arr.last(getTableCells(table)).map((endCell) => tableCellRng(startCell, endCell)); }) ), (cellRng: any) => isWithinSameTable(isRoot, cellRng) ? Option.none() : getCellRangeFromStartTable(cellRng, isRoot) ); }; const isWithinSameTable = (isRoot, cellRng) => getTableFromCellRng(cellRng, isRoot).isSome(); const getCellRng = (rng: Range, isRoot) => { const startCell = getClosestCell(rng.startContainer, isRoot); const endCell = getClosestCell(rng.endContainer, isRoot); return Options.liftN([startCell, endCell], tableCellRng) .filter(isExpandedCellRng) .filter((cellRng) => isWithinSameTable(isRoot, cellRng)) .orThunk(() => partialSelection(isRoot, rng)); }; const getTableSelectionFromCellRng = (cellRng, isRoot) => { return getTableFromCellRng(cellRng, isRoot).map((table) => tableSelection(cellRng, table, getTableCells(table))); }; const getTableSelectionFromRng = (root, rng: Range) => { const isRoot = isRootFromElement(root); return getCellRng(rng, isRoot).bind((cellRng) => getTableSelectionFromCellRng(cellRng, isRoot)); }; const getCellIndex = (cells, cell) => { return Arr.findIndex(cells, (x) => Compare.eq(x, cell)); }; const getSelectedCells = (tableSelection) => { return Options.liftN([ getCellIndex(tableSelection.cells(), tableSelection.rng().start()), getCellIndex(tableSelection.cells(), tableSelection.rng().end()) ], (startIndex, endIndex) => { return tableSelection.cells().slice(startIndex, endIndex + 1); }); }; const getAction = (tableSelection) => { return getSelectedCells(tableSelection) .map((selected) => { const cells = tableSelection.cells(); return selected.length === cells.length ? deleteAction.removeTable(tableSelection.table()) : deleteAction.emptyCells(selected); }); }; const getActionFromCells = (cells) => deleteAction.emptyCells(cells); const getActionFromRange = (root, rng: Range) => getTableSelectionFromRng(root, rng).bind(getAction); export default { getActionFromRange, getActionFromCells };