OXIESEC PANEL
- Current Dir:
/
/
var
/
www
/
reader
/
_backup
/
tinymce
/
tinymce
/
src
/
core
/
main
/
ts
/
selection
Server IP: 139.59.38.164
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
02/20/2020 05:44:43 AM
rwxr-xr-x
📄
CaretRangeFromPoint.ts
2.6 KB
02/20/2020 05:44:11 AM
rw-r--r--
📄
DetailsElement.ts
1.19 KB
02/20/2020 05:44:11 AM
rw-r--r--
📄
ElementSelection.ts
4.83 KB
02/20/2020 05:44:12 AM
rw-r--r--
📄
EventProcessRanges.ts
593 bytes
02/20/2020 05:44:12 AM
rw-r--r--
📄
FragmentReader.ts
3.82 KB
02/20/2020 05:44:13 AM
rw-r--r--
📄
GetSelectionContent.ts
2.12 KB
02/20/2020 05:44:15 AM
rw-r--r--
📄
MultiClickSelection.ts
1.64 KB
02/20/2020 05:44:16 AM
rw-r--r--
📄
MultiRange.ts
955 bytes
02/20/2020 05:44:17 AM
rw-r--r--
📄
NormalizeRange.ts
10.02 KB
02/20/2020 05:44:17 AM
rw-r--r--
📄
RangeCompare.ts
580 bytes
02/20/2020 05:44:18 AM
rw-r--r--
📄
RangeInsertNode.ts
1.52 KB
02/20/2020 05:44:18 AM
rw-r--r--
📄
RangeNodes.ts
946 bytes
02/20/2020 05:44:19 AM
rw-r--r--
📄
RangeNormalizer.ts
1.69 KB
02/20/2020 05:44:19 AM
rw-r--r--
📄
RangeWalk.ts
4.38 KB
02/20/2020 05:44:20 AM
rw-r--r--
📄
SelectionBookmark.ts
3.36 KB
02/20/2020 05:44:20 AM
rw-r--r--
📄
SelectionRestore.ts
1.98 KB
02/20/2020 05:44:21 AM
rw-r--r--
📄
SelectionUtils.ts
3.65 KB
02/20/2020 05:44:21 AM
rw-r--r--
📄
SetSelectionContent.ts
2.44 KB
02/20/2020 05:44:22 AM
rw-r--r--
📄
SimpleTableModel.ts
4.08 KB
02/20/2020 05:44:22 AM
rw-r--r--
📄
SplitRange.ts
1.94 KB
02/20/2020 05:44:23 AM
rw-r--r--
📄
TableCellSelection.ts
1.25 KB
02/20/2020 05:44:24 AM
rw-r--r--
📄
WordSelection.ts
1.47 KB
02/20/2020 05:44:24 AM
rw-r--r--
Editing: SimpleTableModel.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 { Arr, Option, Struct } from '@ephox/katamari'; import { Compare, Insert, InsertAll, Replication, Element, Attr, SelectorFilter } from '@ephox/sugar'; const tableModel = Struct.immutable('element', 'width', 'rows'); const tableRow = Struct.immutable('element', 'cells'); const cellPosition = Struct.immutable('x', 'y'); const getSpan = function (td, key) { const value = parseInt(Attr.get(td, key), 10); return isNaN(value) ? 1 : value; }; const fillout = function (table, x, y, tr, td) { const rowspan = getSpan(td, 'rowspan'); const colspan = getSpan(td, 'colspan'); const rows = table.rows(); for (let y2 = y; y2 < y + rowspan; y2++) { if (!rows[y2]) { rows[y2] = tableRow(Replication.deep(tr), []); } for (let x2 = x; x2 < x + colspan; x2++) { const cells = rows[y2].cells(); // not filler td:s are purposely not cloned so that we can // find cells in the model by element object references cells[x2] = y2 === y && x2 === x ? td : Replication.shallow(td); } } }; const cellExists = function (table, x, y) { const rows = table.rows(); const cells = rows[y] ? rows[y].cells() : []; return !!cells[x]; }; const skipCellsX = function (table, x, y) { while (cellExists(table, x, y)) { x++; } return x; }; const getWidth = function (rows) { return Arr.foldl(rows, function (acc, row) { return row.cells().length > acc ? row.cells().length : acc; }, 0); }; const findElementPos = function (table, element) { const rows = table.rows(); for (let y = 0; y < rows.length; y++) { const cells = rows[y].cells(); for (let x = 0; x < cells.length; x++) { if (Compare.eq(cells[x], element)) { return Option.some(cellPosition(x, y)); } } } return Option.none(); }; const extractRows = function (table, sx, sy, ex, ey) { const newRows = []; const rows = table.rows(); for (let y = sy; y <= ey; y++) { const cells = rows[y].cells(); const slice = sx < ex ? cells.slice(sx, ex + 1) : cells.slice(ex, sx + 1); newRows.push(tableRow(rows[y].element(), slice)); } return newRows; }; const subTable = function (table, startPos, endPos) { const sx = startPos.x(), sy = startPos.y(); const ex = endPos.x(), ey = endPos.y(); const newRows = sy < ey ? extractRows(table, sx, sy, ex, ey) : extractRows(table, sx, ey, ex, sy); return tableModel(table.element(), getWidth(newRows), newRows); }; const createDomTable = function (table, rows) { const tableElement = Replication.shallow(table.element()); const tableBody = Element.fromTag('tbody'); InsertAll.append(tableBody, rows); Insert.append(tableElement, tableBody); return tableElement; }; const modelRowsToDomRows = function (table) { return Arr.map(table.rows(), function (row) { const cells = Arr.map(row.cells(), function (cell) { const td = Replication.deep(cell); Attr.remove(td, 'colspan'); Attr.remove(td, 'rowspan'); return td; }); const tr = Replication.shallow(row.element()); InsertAll.append(tr, cells); return tr; }); }; const fromDom = function (tableElm) { const table = tableModel(Replication.shallow(tableElm), 0, []); Arr.each(SelectorFilter.descendants(tableElm, 'tr'), function (tr, y) { Arr.each(SelectorFilter.descendants(tr, 'td,th'), function (td, x) { fillout(table, skipCellsX(table, x, y), y, tr, td); }); }); return tableModel(table.element(), getWidth(table.rows()), table.rows()); }; const toDom = function (table) { return createDomTable(table, modelRowsToDomRows(table)); }; const subsection = function (table, startElement, endElement) { return findElementPos(table, startElement).bind(function (startPos) { return findElementPos(table, endElement).map(function (endPos) { return subTable(table, startPos, endPos); }); }); }; export default { fromDom, toDom, subsection };