1 var _typeof = typeof Symbol ===
"function" && typeof Symbol.iterator ===
"symbol" ?
function (obj) {
return typeof obj; } :
function (obj) {
return obj && typeof Symbol ===
"function" && obj.constructor === Symbol && obj !== Symbol.prototype ?
"symbol" : typeof obj; };
5 var MoveRows =
function MoveRows(table) {
8 this.placeholderElement = this.createPlaceholderElement();
9 this.hoverElement =
false;
10 this.checkTimeout =
false;
11 this.checkPeriod = 150;
14 this.toRowAfter =
false;
15 this.hasHandle =
false;
19 this.moveHover = this.moveHover.bind(
this);
20 this.endMove = this.endMove.bind(
this);
21 this.tableRowDropEvent =
false;
23 this.touchMove =
false;
25 this.connection =
false;
26 this.connections = [];
28 this.connectedTable =
false;
29 this.connectedRow =
false;
32 MoveRows.prototype.createPlaceholderElement =
function () {
33 var el = document.createElement(
"div");
35 el.classList.add(
"tabulator-row");
36 el.classList.add(
"tabulator-row-placeholder");
41 MoveRows.prototype.initialize =
function (handle) {
42 this.connection = this.table.options.movableRowsConnectedTables;
45 MoveRows.prototype.setHandle =
function (handle) {
46 this.hasHandle = handle;
49 MoveRows.prototype.initializeGroupHeader =
function (group) {
55 config.mouseup =
function (e) {
56 self.tableRowDrop(e, row);
60 config.mousemove =
function (e) {
61 if (e.pageY - Tabulator.prototype.helpers.elOffset(group.element).top +
self.table.rowManager.element.scrollTop > group.getHeight() / 2) {
62 if (
self.toRow !== group || !
self.toRowAfter) {
63 var rowEl = group.getElement();
64 rowEl.parentNode.insertBefore(
self.placeholderElement, rowEl.nextSibling);
65 self.moveRow(group,
true);
68 if (
self.toRow !== group ||
self.toRowAfter) {
69 var rowEl = group.getElement();
70 if (rowEl.previousSibling) {
71 rowEl.parentNode.insertBefore(
self.placeholderElement, rowEl);
72 self.moveRow(group,
false);
78 group.modules.moveRow = config;
81 MoveRows.prototype.initializeRow =
function (row) {
87 config.mouseup =
function (e) {
88 self.tableRowDrop(e, row);
92 config.mousemove =
function (e) {
93 if (e.pageY - Tabulator.prototype.helpers.elOffset(row.element).top +
self.table.rowManager.element.scrollTop > row.getHeight() / 2) {
94 if (
self.toRow !== row || !
self.toRowAfter) {
95 var rowEl = row.getElement();
96 rowEl.parentNode.insertBefore(
self.placeholderElement, rowEl.nextSibling);
97 self.moveRow(row,
true);
100 if (
self.toRow !== row ||
self.toRowAfter) {
101 var rowEl = row.getElement();
102 rowEl.parentNode.insertBefore(
self.placeholderElement, rowEl);
103 self.moveRow(row,
false);
108 if (!this.hasHandle) {
110 rowEl = row.getElement();
112 rowEl.addEventListener(
"mousedown",
function (e) {
114 self.checkTimeout = setTimeout(
function () {
115 self.startMove(e, row);
116 },
self.checkPeriod);
120 rowEl.addEventListener(
"mouseup",
function (e) {
122 if (
self.checkTimeout) {
123 clearTimeout(
self.checkTimeout);
128 this.bindTouchEvents(row, row.getElement());
131 row.modules.moveRow = config;
134 MoveRows.prototype.initializeCell =
function (cell) {
136 cellEl = cell.getElement();
138 cellEl.addEventListener(
"mousedown",
function (e) {
140 self.checkTimeout = setTimeout(
function () {
141 self.startMove(e, cell.row);
142 },
self.checkPeriod);
146 cellEl.addEventListener(
"mouseup",
function (e) {
148 if (
self.checkTimeout) {
149 clearTimeout(
self.checkTimeout);
154 this.bindTouchEvents(cell.row, cell.getElement());
157 MoveRows.prototype.bindTouchEvents =
function (row, element) {
170 element.addEventListener(
"touchstart",
function (e) {
171 self.checkTimeout = setTimeout(
function () {
172 self.touchMove =
true;
174 nextRow = row.nextRow();
175 nextRowHeight = nextRow ? nextRow.getHeight() / 2 : 0;
176 prevRow = row.prevRow();
177 prevRowHeight = prevRow ? prevRow.getHeight() / 2 : 0;
178 nextRowHeightLast = 0;
179 prevRowHeightLast = 0;
182 self.startMove(e, row);
183 },
self.checkPeriod);
184 }, { passive:
true });
185 this.moving, this.toRow, this.toRowAfter;
186 element.addEventListener(
"touchmove",
function (e) {
188 var halfCol, diff, moveToRow;
196 startYMove = e.touches[0].pageY;
199 diff = e.touches[0].pageY - startYMove;
202 if (nextRow && diff - nextRowHeightLast > nextRowHeight) {
205 if (moveToRow !== row) {
206 startYMove = e.touches[0].pageY;
207 moveToRow.getElement().parentNode.insertBefore(
self.placeholderElement, moveToRow.getElement().nextSibling);
208 self.moveRow(moveToRow,
true);
212 if (prevRow && -diff - prevRowHeightLast > prevRowHeight) {
215 if (moveToRow !== row) {
216 startYMove = e.touches[0].pageY;
217 moveToRow.getElement().parentNode.insertBefore(
self.placeholderElement, moveToRow.getElement());
218 self.moveRow(moveToRow,
false);
224 currentRow = moveToRow;
225 nextRow = moveToRow.nextRow();
226 nextRowHeightLast = nextRowHeight;
227 nextRowHeight = nextRow ? nextRow.getHeight() / 2 : 0;
228 prevRow = moveToRow.prevRow();
229 prevRowHeightLast = prevRowHeight;
230 prevRowHeight = prevRow ? prevRow.getHeight() / 2 : 0;
235 element.addEventListener(
"touchend",
function (e) {
236 if (
self.checkTimeout) {
237 clearTimeout(
self.checkTimeout);
241 self.touchMove =
false;
246 MoveRows.prototype._bindMouseMove =
function () {
249 self.table.rowManager.getDisplayRows().forEach(
function (row) {
250 if ((row.type ===
"row" || row.type ===
"group") && row.modules.moveRow.mousemove) {
251 row.getElement().addEventListener(
"mousemove", row.modules.moveRow.mousemove);
256 MoveRows.prototype._unbindMouseMove =
function () {
259 self.table.rowManager.getDisplayRows().forEach(
function (row) {
260 if ((row.type ===
"row" || row.type ===
"group") && row.modules.moveRow.mousemove) {
261 row.getElement().removeEventListener(
"mousemove", row.modules.moveRow.mousemove);
266 MoveRows.prototype.startMove =
function (e, row) {
267 var element = row.getElement();
269 this.setStartPosition(e, row);
273 this.table.element.classList.add(
"tabulator-block-select");
276 this.placeholderElement.style.width = row.getWidth() +
"px";
277 this.placeholderElement.style.height = row.getHeight() +
"px";
279 if (!this.connection) {
280 element.parentNode.insertBefore(this.placeholderElement, element);
281 element.parentNode.removeChild(element);
283 this.table.element.classList.add(
"tabulator-movingrow-sending");
284 this.connectToTables(row);
288 this.hoverElement = element.cloneNode(
true);
289 this.hoverElement.classList.add(
"tabulator-moving");
291 if (this.connection) {
292 document.body.appendChild(this.hoverElement);
293 this.hoverElement.style.left =
"0";
294 this.hoverElement.style.top =
"0";
295 this.hoverElement.style.width = this.table.element.clientWidth +
"px";
296 this.hoverElement.style.whiteSpace =
"nowrap";
297 this.hoverElement.style.overflow =
"hidden";
298 this.hoverElement.style.pointerEvents =
"none";
300 this.table.rowManager.getTableElement().appendChild(this.hoverElement);
302 this.hoverElement.style.left =
"0";
303 this.hoverElement.style.top =
"0";
305 this._bindMouseMove();
308 document.body.addEventListener(
"mousemove", this.moveHover);
309 document.body.addEventListener(
"mouseup", this.endMove);
314 MoveRows.prototype.setStartPosition =
function (e, row) {
315 var pageX = this.touchMove ? e.touches[0].pageX : e.pageX,
316 pageY = this.touchMove ? e.touches[0].pageY : e.pageY,
320 element = row.getElement();
321 if (this.connection) {
322 position = element.getBoundingClientRect();
324 this.startX = position.left - pageX + window.pageXOffset;
325 this.startY = position.top - pageY + window.pageYOffset;
327 this.startY = pageY - element.getBoundingClientRect().top;
331 MoveRows.prototype.endMove =
function (e) {
332 if (!e || e.which === 1 ||
this.touchMove) {
333 this._unbindMouseMove();
335 if (!this.connection) {
336 this.placeholderElement.parentNode.insertBefore(this.moving.getElement(), this.placeholderElement.nextSibling);
337 this.placeholderElement.parentNode.removeChild(this.placeholderElement);
340 this.hoverElement.parentNode.removeChild(this.hoverElement);
342 this.table.element.classList.remove(
"tabulator-block-select");
345 this.table.rowManager.moveRow(this.moving, this.toRow, this.toRowAfter);
350 this.toRowAfter =
false;
352 document.body.removeEventListener(
"mousemove", this.moveHover);
353 document.body.removeEventListener(
"mouseup", this.endMove);
355 if (this.connection) {
356 this.table.element.classList.remove(
"tabulator-movingrow-sending");
357 this.disconnectFromTables();
362 MoveRows.prototype.moveRow =
function (row, after) {
364 this.toRowAfter = after;
367 MoveRows.prototype.moveHover =
function (e) {
368 if (this.connection) {
369 this.moveHoverConnections.call(
this, e);
371 this.moveHoverTable.call(
this, e);
375 MoveRows.prototype.moveHoverTable =
function (e) {
376 var rowHolder = this.table.rowManager.getElement(),
377 scrollTop = rowHolder.scrollTop,
378 yPos = (this.touchMove ? e.touches[0].pageY : e.pageY) - rowHolder.getBoundingClientRect().top + scrollTop,
381 this.hoverElement.style.top = yPos - this.startY +
"px";
384 MoveRows.prototype.moveHoverConnections =
function (e) {
385 this.hoverElement.style.left = this.startX + (this.touchMove ? e.touches[0].pageX : e.pageX) +
"px";
386 this.hoverElement.style.top = this.startY + (this.touchMove ? e.touches[0].pageY : e.pageY) +
"px";
390 MoveRows.prototype.connectToTables =
function (row) {
392 connections = this.table.modules.comms.getConnections(this.connection);
394 this.table.options.movableRowsSendingStart.call(this.table, connections);
396 this.table.modules.comms.send(this.connection,
"moveRow",
"connect", {
402 MoveRows.prototype.disconnectFromTables =
function () {
404 connections = this.table.modules.comms.getConnections(this.connection);
406 this.table.options.movableRowsSendingStop.call(this.table, connections);
408 this.table.modules.comms.send(this.connection,
"moveRow",
"disconnect");
412 MoveRows.prototype.connect =
function (table, row) {
414 if (!this.connectedTable) {
415 this.connectedTable = table;
416 this.connectedRow = row;
418 this.table.element.classList.add(
"tabulator-movingrow-receiving");
420 self.table.rowManager.getDisplayRows().forEach(
function (row) {
421 if (row.type ===
"row" && row.modules.moveRow && row.modules.moveRow.mouseup) {
422 row.getElement().addEventListener(
"mouseup", row.modules.moveRow.mouseup);
426 self.tableRowDropEvent =
self.tableRowDrop.bind(
self);
428 self.table.element.addEventListener(
"mouseup",
self.tableRowDropEvent);
430 this.table.options.movableRowsReceivingStart.call(this.table, row, table);
434 console.warn(
"Move Row Error - Table cannot accept connection, already connected to table:", this.connectedTable);
440 MoveRows.prototype.disconnect =
function (table) {
442 if (table === this.connectedTable) {
443 this.connectedTable =
false;
444 this.connectedRow =
false;
446 this.table.element.classList.remove(
"tabulator-movingrow-receiving");
448 self.table.rowManager.getDisplayRows().forEach(
function (row) {
449 if (row.type ===
"row" && row.modules.moveRow && row.modules.moveRow.mouseup) {
450 row.getElement().removeEventListener(
"mouseup", row.modules.moveRow.mouseup);
454 self.table.element.removeEventListener(
"mouseup",
self.tableRowDropEvent);
456 this.table.options.movableRowsReceivingStop.call(this.table, table);
458 console.warn(
"Move Row Error - trying to disconnect from non connected table");
462 MoveRows.prototype.dropComplete =
function (table, row, success) {
467 switch (_typeof(this.table.options.movableRowsSender)) {
469 sender = this.senders[this.table.options.movableRowsSender];
473 sender = this.table.options.movableRowsSender;
478 sender.call(
this, this.moving.getComponent(), row ? row.getComponent() : undefined, table);
480 if (this.table.options.movableRowsSender) {
481 console.warn(
"Mover Row Error - no matching sender found:", this.table.options.movableRowsSender);
485 this.table.options.movableRowsSent.call(this.table, this.moving.getComponent(), row ? row.getComponent() : undefined, table);
487 this.table.options.movableRowsSentFailed.call(this.table, this.moving.getComponent(), row ? row.getComponent() : undefined, table);
493 MoveRows.prototype.tableRowDrop =
function (e, row) {
494 var receiver =
false,
497 e.stopImmediatePropagation();
499 switch (_typeof(this.table.options.movableRowsReceiver)) {
501 receiver = this.receivers[this.table.options.movableRowsReceiver];
505 receiver = this.table.options.movableRowsReceiver;
510 success = receiver.call(
this, this.connectedRow.getComponent(), row ? row.getComponent() : undefined, this.connectedTable);
512 console.warn(
"Mover Row Error - no matching receiver found:", this.table.options.movableRowsReceiver);
516 this.table.options.movableRowsReceived.call(this.table, this.connectedRow.getComponent(), row ? row.getComponent() : undefined, this.connectedTable);
518 this.table.options.movableRowsReceivedFailed.call(this.table, this.connectedRow.getComponent(), row ? row.getComponent() : undefined, this.connectedTable);
521 this.table.modules.comms.send(this.connectedTable,
"moveRow",
"dropcomplete", {
527 MoveRows.prototype.receivers = {
528 insert:
function insert(fromRow, toRow, fromTable) {
529 this.table.addRow(fromRow.getData(), undefined, toRow);
533 add:
function add(fromRow, toRow, fromTable) {
534 this.table.addRow(fromRow.getData());
538 update:
function update(fromRow, toRow, fromTable) {
540 toRow.update(fromRow.getData());
547 replace:
function replace(fromRow, toRow, fromTable) {
549 this.table.addRow(fromRow.getData(), undefined, toRow);
558 MoveRows.prototype.senders = {
559 delete:
function _delete(fromRow, toRow, toTable) {
564 MoveRows.prototype.commsReceived =
function (table, action, data) {
567 return this.connect(table, data.row);
571 return this.disconnect(table);
575 return this.dropComplete(table, data.row, data.success);
580 Tabulator.prototype.registerModule(
"moveRow", MoveRows);