@itrocks/table 0.2.7 → 0.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/column-reorder.js +8 -10
  2. package/package.json +1 -1
package/column-reorder.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import { Plugin } from '../plugin/plugin.js';
2
2
  import { PluginOptions } from '../plugin/plugin.js';
3
+ let activeDrag;
3
4
  const clamp = (value) => Math.max(0, Math.min(1, value));
4
5
  const maxScrollSpeed = 800;
5
6
  const penetration = 10;
6
7
  const scrollZone = 50;
7
- let activeDrag;
8
8
  export class TableColumnReorder extends Plugin {
9
9
  drag;
10
10
  frame;
@@ -14,27 +14,24 @@ export class TableColumnReorder extends Plugin {
14
14
  this.frame = undefined;
15
15
  const drag = this.drag;
16
16
  this.updateState(drag);
17
- if (drag.remove) {
18
- drag.time = undefined;
19
- return;
20
- }
21
17
  const pointerDirection = drag.direction;
22
18
  drag.direction = 0;
23
19
  const scrollDirection = this.scroll(drag, time);
20
+ if (scrollDirection)
21
+ this.requestFrame();
24
22
  const direction = pointerDirection || scrollDirection;
25
23
  const target = direction ? this.target(drag, direction) : drag.index;
26
24
  if (target !== drag.index)
27
25
  this.move(drag, target);
28
- if (scrollDirection)
29
- this.requestFrame();
30
26
  }
31
27
  defaultOptions() {
32
28
  return new TableColumnReorderOptions();
33
29
  }
34
30
  finish(commit) {
35
31
  this.press = undefined;
36
- if (this.frame !== undefined)
32
+ if (this.frame !== undefined) {
37
33
  cancelAnimationFrame(this.frame);
34
+ }
38
35
  this.frame = undefined;
39
36
  const drag = this.drag;
40
37
  if (!drag)
@@ -90,8 +87,9 @@ export class TableColumnReorder extends Plugin {
90
87
  }
91
88
  move(drag, targetIndex) {
92
89
  const after = drag.index < targetIndex;
93
- for (const cell of drag.cells) {
94
- const target = cell.parentElement.cells[targetIndex];
90
+ for (const row of this.rows()) {
91
+ const cell = row.cells[drag.index];
92
+ const target = row.cells[targetIndex];
95
93
  after ? target.after(cell) : target.before(cell);
96
94
  }
97
95
  if (drag.col) {
package/package.json CHANGED
@@ -52,5 +52,5 @@
52
52
  "scripts": {
53
53
  "build": "tsc && sass --no-source-map demo:demo && node ../prepare-module/prepare-module.js"
54
54
  },
55
- "version": "0.2.7"
55
+ "version": "0.2.9"
56
56
  }