handsontable 0.0.0-next-a34a8db-20241121 → 0.0.0-next-a148bc1-20241121
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of handsontable might be problematic. Click here for more details.
- package/3rdparty/walkontable/src/index.js +2 -0
- package/3rdparty/walkontable/src/index.mjs +2 -1
- package/3rdparty/walkontable/src/renderer/_base.js +3 -4
- package/3rdparty/walkontable/src/renderer/_base.mjs +2 -2
- package/3rdparty/walkontable/src/renderer/cells.js +11 -10
- package/3rdparty/walkontable/src/renderer/cells.mjs +10 -8
- package/3rdparty/walkontable/src/renderer/colGroup.js +6 -7
- package/3rdparty/walkontable/src/renderer/colGroup.mjs +5 -5
- package/3rdparty/walkontable/src/renderer/columnHeaders.js +4 -5
- package/3rdparty/walkontable/src/renderer/columnHeaders.mjs +3 -3
- package/3rdparty/walkontable/src/renderer/index.js +18 -19
- package/3rdparty/walkontable/src/renderer/index.mjs +6 -6
- package/3rdparty/walkontable/src/renderer/rowHeaders.js +5 -6
- package/3rdparty/walkontable/src/renderer/rowHeaders.mjs +4 -4
- package/3rdparty/walkontable/src/renderer/rows.js +23 -11
- package/3rdparty/walkontable/src/renderer/rows.mjs +23 -10
- package/3rdparty/walkontable/src/renderer/table.js +1 -1
- package/3rdparty/walkontable/src/renderer/table.mjs +1 -1
- package/3rdparty/walkontable/src/utils/nodesPool.js +22 -5
- package/3rdparty/walkontable/src/utils/nodesPool.mjs +22 -5
- package/3rdparty/walkontable/src/utils/orderView/index.js +4 -5
- package/3rdparty/walkontable/src/utils/orderView/index.mjs +2 -2
- package/3rdparty/walkontable/src/utils/orderView/sharedView.js +3 -4
- package/3rdparty/walkontable/src/utils/orderView/sharedView.mjs +2 -2
- package/3rdparty/walkontable/src/utils/orderView/view.js +79 -76
- package/3rdparty/walkontable/src/utils/orderView/view.mjs +78 -74
- package/3rdparty/walkontable/src/utils/orderView/viewDiffer/index.js +138 -0
- package/3rdparty/walkontable/src/utils/orderView/viewDiffer/index.mjs +135 -0
- package/3rdparty/walkontable/src/utils/orderView/viewDiffer/viewOrder.js +72 -0
- package/3rdparty/walkontable/src/utils/orderView/viewDiffer/viewOrder.mjs +68 -0
- package/3rdparty/walkontable/src/utils/orderView/viewSize.js +1 -1
- package/3rdparty/walkontable/src/utils/orderView/viewSize.mjs +1 -1
- package/3rdparty/walkontable/src/utils/orderView/viewSizeSet.js +4 -5
- package/3rdparty/walkontable/src/utils/orderView/viewSizeSet.mjs +3 -3
- package/base.js +2 -2
- package/base.mjs +2 -2
- package/dist/handsontable.css +2 -2
- package/dist/handsontable.full.css +2 -2
- package/dist/handsontable.full.js +1963 -1710
- package/dist/handsontable.full.min.css +2 -2
- package/dist/handsontable.full.min.js +6 -6
- package/dist/handsontable.js +1965 -1712
- package/dist/handsontable.min.css +2 -2
- package/dist/handsontable.min.js +6 -6
- package/helpers/mixed.js +1 -1
- package/helpers/mixed.mjs +1 -1
- package/package.json +1 -1
@@ -7,21 +7,27 @@ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e =
|
|
7
7
|
*
|
8
8
|
* @class {NodesPool}
|
9
9
|
*/
|
10
|
-
export
|
10
|
+
export class NodesPool {
|
11
11
|
constructor(nodeType) {
|
12
12
|
/**
|
13
|
-
* Node type to generate (
|
13
|
+
* Node type to generate (e.g. 'TH', 'TD').
|
14
14
|
*
|
15
15
|
* @type {string}
|
16
16
|
*/
|
17
17
|
_defineProperty(this, "nodeType", void 0);
|
18
|
+
/**
|
19
|
+
* The holder for all created DOM nodes (THs, TDs).
|
20
|
+
*
|
21
|
+
* @type {Map<string, HTMLElement>}
|
22
|
+
*/
|
23
|
+
_defineProperty(this, "pool", new Map());
|
18
24
|
this.nodeType = nodeType.toUpperCase();
|
19
25
|
}
|
20
26
|
|
21
27
|
/**
|
22
28
|
* Set document owner for this instance.
|
23
29
|
*
|
24
|
-
* @param {
|
30
|
+
* @param {Document} rootDocument The document window owner.
|
25
31
|
*/
|
26
32
|
setRootDocument(rootDocument) {
|
27
33
|
this.rootDocument = rootDocument;
|
@@ -30,9 +36,20 @@ export default class NodesPool {
|
|
30
36
|
/**
|
31
37
|
* Obtains an element. The returned elements in the feature can be cached.
|
32
38
|
*
|
39
|
+
* @param {number} rowIndex The row index.
|
40
|
+
* @param {number} [columnIndex] The column index.
|
33
41
|
* @returns {HTMLElement}
|
34
42
|
*/
|
35
|
-
obtain() {
|
36
|
-
|
43
|
+
obtain(rowIndex, columnIndex) {
|
44
|
+
const hasColumnIndex = typeof columnIndex === 'number';
|
45
|
+
const key = hasColumnIndex ? `${rowIndex}x${columnIndex}` : rowIndex.toString();
|
46
|
+
if (this.pool.has(key)) {
|
47
|
+
return this.pool.get(key);
|
48
|
+
}
|
49
|
+
const node = this.rootDocument.createElement(this.nodeType);
|
50
|
+
|
51
|
+
// node.dataset.id = key; // Uncomment for debug purposes
|
52
|
+
this.pool.set(key, node);
|
53
|
+
return node;
|
37
54
|
}
|
38
55
|
}
|
@@ -1,8 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
3
|
exports.__esModule = true;
|
4
|
-
var _view =
|
5
|
-
exports.OrderView = _view.
|
6
|
-
var _sharedView =
|
7
|
-
exports.SharedOrderView = _sharedView.
|
8
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
4
|
+
var _view = require("./view");
|
5
|
+
exports.OrderView = _view.OrderView;
|
6
|
+
var _sharedView = require("./sharedView");
|
7
|
+
exports.SharedOrderView = _sharedView.SharedOrderView;
|
@@ -1,3 +1,3 @@
|
|
1
|
-
import OrderView from "./view.mjs";
|
2
|
-
import SharedOrderView from "./sharedView.mjs";
|
1
|
+
import { OrderView } from "./view.mjs";
|
2
|
+
import { SharedOrderView } from "./sharedView.mjs";
|
3
3
|
export { OrderView, SharedOrderView };
|
@@ -1,14 +1,13 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
3
|
exports.__esModule = true;
|
4
|
-
var _view =
|
5
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
4
|
+
var _view = require("./view");
|
6
5
|
/**
|
7
6
|
* Executive model for TR root nodes.
|
8
7
|
*
|
9
8
|
* @class {SharedOrderView}
|
10
9
|
*/
|
11
|
-
class SharedOrderView extends _view.
|
10
|
+
class SharedOrderView extends _view.OrderView {
|
12
11
|
/**
|
13
12
|
* The method results in merging external order view into the current order. This happens only for order views which
|
14
13
|
* operate on the same root node.
|
@@ -43,4 +42,4 @@ class SharedOrderView extends _view.default {
|
|
43
42
|
return this;
|
44
43
|
}
|
45
44
|
}
|
46
|
-
exports.
|
45
|
+
exports.SharedOrderView = SharedOrderView;
|
@@ -1,10 +1,10 @@
|
|
1
|
-
import OrderView from "./view.mjs";
|
1
|
+
import { OrderView } from "./view.mjs";
|
2
2
|
/**
|
3
3
|
* Executive model for TR root nodes.
|
4
4
|
*
|
5
5
|
* @class {SharedOrderView}
|
6
6
|
*/
|
7
|
-
export
|
7
|
+
export class SharedOrderView extends OrderView {
|
8
8
|
/**
|
9
9
|
* The method results in merging external order view into the current order. This happens only for order views which
|
10
10
|
* operate on the same root node.
|
@@ -3,9 +3,8 @@
|
|
3
3
|
exports.__esModule = true;
|
4
4
|
require("core-js/modules/es.error.cause.js");
|
5
5
|
require("core-js/modules/es.array.push.js");
|
6
|
-
var
|
7
|
-
var
|
8
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
6
|
+
var _viewSizeSet = require("./viewSizeSet");
|
7
|
+
var _viewDiffer = require("./viewDiffer");
|
9
8
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
10
9
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
11
10
|
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
@@ -18,7 +17,7 @@ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e =
|
|
18
17
|
* @class {OrderView}
|
19
18
|
*/
|
20
19
|
class OrderView {
|
21
|
-
constructor(rootNode, nodesPool
|
20
|
+
constructor(rootNode, nodesPool) {
|
22
21
|
/**
|
23
22
|
* The root node to manage with.
|
24
23
|
*
|
@@ -28,7 +27,7 @@ class OrderView {
|
|
28
27
|
/**
|
29
28
|
* Factory for newly created DOM elements.
|
30
29
|
*
|
31
|
-
* @type {
|
30
|
+
* @type {function(number): HTMLElement}
|
32
31
|
*/
|
33
32
|
_defineProperty(this, "nodesPool", void 0);
|
34
33
|
/**
|
@@ -36,28 +35,41 @@ class OrderView {
|
|
36
35
|
*
|
37
36
|
* @type {ViewSizeSet}
|
38
37
|
*/
|
39
|
-
_defineProperty(this, "sizeSet", new _viewSizeSet.
|
38
|
+
_defineProperty(this, "sizeSet", new _viewSizeSet.ViewSizeSet());
|
40
39
|
/**
|
41
|
-
*
|
40
|
+
* The list of DOM elements which are rendered for this render cycle.
|
42
41
|
*
|
43
|
-
* @type {
|
42
|
+
* @type {HTMLElement[]}
|
44
43
|
*/
|
45
|
-
_defineProperty(this, "
|
44
|
+
_defineProperty(this, "collectedNodes", []);
|
46
45
|
/**
|
47
|
-
* The
|
46
|
+
* The differ which calculates the differences between current and next view. It generates
|
47
|
+
* commands that are processed by the OrderView (see `applyCommand` method).
|
48
48
|
*
|
49
|
-
* @type {
|
49
|
+
* @type {ViewDiffer}
|
50
50
|
*/
|
51
|
-
_defineProperty(this, "
|
51
|
+
_defineProperty(this, "viewDiffer", new _viewDiffer.ViewDiffer(this.sizeSet));
|
52
52
|
/**
|
53
|
-
*
|
53
|
+
* @type {number[]}
|
54
|
+
*/
|
55
|
+
_defineProperty(this, "staleNodeIndexes", []);
|
56
|
+
/**
|
57
|
+
* The list of render commands to execute. The command is an array with the following
|
58
|
+
* structure: [
|
59
|
+
* [
|
60
|
+
* 'prepend' | 'append' | 'insert_before' | 'replace' | 'remove', // command name
|
61
|
+
* 10, // processed node index
|
62
|
+
* 9, // previous node index (only for 'insert_before' and 'replace' commands)
|
63
|
+
* 8 // node index to remove (only for 'insert_before' command)
|
64
|
+
* ],
|
65
|
+
* ...
|
66
|
+
* ].
|
54
67
|
*
|
55
|
-
* @type {
|
68
|
+
* @type {Array[]}
|
56
69
|
*/
|
57
|
-
_defineProperty(this, "
|
70
|
+
_defineProperty(this, "leads", []);
|
58
71
|
this.rootNode = rootNode;
|
59
72
|
this.nodesPool = nodesPool;
|
60
|
-
this.childNodeType = childNodeType.toUpperCase();
|
61
73
|
}
|
62
74
|
|
63
75
|
/**
|
@@ -84,6 +96,14 @@ class OrderView {
|
|
84
96
|
return this;
|
85
97
|
}
|
86
98
|
|
99
|
+
/**
|
100
|
+
* @param {number} sourceIndex The source index.
|
101
|
+
* @returns {boolean}
|
102
|
+
*/
|
103
|
+
hasStaleContent(sourceIndex) {
|
104
|
+
return this.staleNodeIndexes.includes(sourceIndex);
|
105
|
+
}
|
106
|
+
|
87
107
|
/**
|
88
108
|
* Checks if this instance of the view shares the root node with another instance. This happens only once when
|
89
109
|
* a row (TR) as a root node is managed by two OrderView instances. If this happens another DOM injection
|
@@ -116,30 +136,44 @@ class OrderView {
|
|
116
136
|
}
|
117
137
|
|
118
138
|
/**
|
119
|
-
*
|
139
|
+
* Applies the commands generated by the differ into the specific DOM operations.
|
120
140
|
*
|
121
|
-
* @
|
141
|
+
* @param {Array} command The command to apply.
|
122
142
|
*/
|
123
|
-
|
143
|
+
applyCommand(command) {
|
124
144
|
const {
|
125
|
-
rootNode
|
126
|
-
sizeSet
|
145
|
+
rootNode
|
127
146
|
} = this;
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
147
|
+
const [name, nodeIndex, nodePrevIndex, nodeIndexToRemove] = command;
|
148
|
+
const node = this.nodesPool(nodeIndex);
|
149
|
+
this.collectedNodes.push(node);
|
150
|
+
|
151
|
+
// @TODO(perf-tip): Only nodes which are first time rendered (hasn't any inner content) can be marked as stale
|
152
|
+
// e.q `name !== 'none' && !node.firstChild`.
|
153
|
+
if (name !== 'none') {
|
154
|
+
this.staleNodeIndexes.push(nodeIndex);
|
155
|
+
}
|
156
|
+
switch (name) {
|
157
|
+
case 'prepend':
|
158
|
+
rootNode.insertBefore(node, rootNode.firstChild);
|
159
|
+
break;
|
160
|
+
case 'append':
|
161
|
+
rootNode.appendChild(node);
|
162
|
+
break;
|
163
|
+
case 'insert_before':
|
164
|
+
rootNode.insertBefore(node, this.nodesPool(nodePrevIndex));
|
165
|
+
// To keep the constant length of child nodes (after inserting a node) remove the last child.
|
166
|
+
rootNode.removeChild(this.nodesPool(nodeIndexToRemove));
|
167
|
+
break;
|
168
|
+
case 'replace':
|
169
|
+
rootNode.replaceChild(node, this.nodesPool(nodePrevIndex));
|
170
|
+
break;
|
171
|
+
case 'remove':
|
172
|
+
rootNode.removeChild(node);
|
173
|
+
break;
|
174
|
+
default:
|
175
|
+
break;
|
141
176
|
}
|
142
|
-
return childElementCount;
|
143
177
|
}
|
144
178
|
|
145
179
|
/**
|
@@ -148,30 +182,8 @@ class OrderView {
|
|
148
182
|
*/
|
149
183
|
start() {
|
150
184
|
this.collectedNodes.length = 0;
|
151
|
-
this.
|
152
|
-
|
153
|
-
rootNode,
|
154
|
-
sizeSet
|
155
|
-
} = this;
|
156
|
-
const isShared = this.isSharedViewSet();
|
157
|
-
const {
|
158
|
-
nextSize
|
159
|
-
} = sizeSet.getViewSize();
|
160
|
-
let childElementCount = this.getRenderedChildCount();
|
161
|
-
while (childElementCount < nextSize) {
|
162
|
-
const newNode = this.nodesPool();
|
163
|
-
if (!isShared || isShared && sizeSet.isPlaceOn(_constants.WORKING_SPACE_BOTTOM)) {
|
164
|
-
rootNode.appendChild(newNode);
|
165
|
-
} else {
|
166
|
-
rootNode.insertBefore(newNode, rootNode.firstChild);
|
167
|
-
}
|
168
|
-
childElementCount += 1;
|
169
|
-
}
|
170
|
-
const isSharedPlacedOnTop = isShared && sizeSet.isPlaceOn(_constants.WORKING_SPACE_TOP);
|
171
|
-
while (childElementCount > nextSize) {
|
172
|
-
rootNode.removeChild(isSharedPlacedOnTop ? rootNode.firstChild : rootNode.lastChild);
|
173
|
-
childElementCount -= 1;
|
174
|
-
}
|
185
|
+
this.staleNodeIndexes.length = 0;
|
186
|
+
this.leads = this.viewDiffer.diff();
|
175
187
|
}
|
176
188
|
|
177
189
|
/**
|
@@ -179,28 +191,19 @@ class OrderView {
|
|
179
191
|
* This method has to be called as many times as the size count is met (to cover all previously rendered DOM elements).
|
180
192
|
*/
|
181
193
|
render() {
|
182
|
-
|
183
|
-
|
184
|
-
sizeSet
|
185
|
-
} = this;
|
186
|
-
let visualIndex = this.visualIndex;
|
187
|
-
if (this.isSharedViewSet() && sizeSet.isPlaceOn(_constants.WORKING_SPACE_BOTTOM)) {
|
188
|
-
visualIndex += sizeSet.sharedSize.nextSize;
|
189
|
-
}
|
190
|
-
let node = rootNode.childNodes[visualIndex];
|
191
|
-
if (node.tagName !== this.childNodeType) {
|
192
|
-
const newNode = this.nodesPool();
|
193
|
-
rootNode.replaceChild(newNode, node);
|
194
|
-
node = newNode;
|
194
|
+
if (this.leads.length > 0) {
|
195
|
+
this.applyCommand(this.leads.shift());
|
195
196
|
}
|
196
|
-
this.collectedNodes.push(node);
|
197
|
-
this.visualIndex += 1;
|
198
197
|
}
|
199
198
|
|
200
199
|
/**
|
201
200
|
* Ends the render process.
|
202
201
|
* This method has to be called only once (at the end) for the render cycle.
|
203
202
|
*/
|
204
|
-
end() {
|
203
|
+
end() {
|
204
|
+
while (this.leads.length > 0) {
|
205
|
+
this.applyCommand(this.leads.shift());
|
206
|
+
}
|
207
|
+
}
|
205
208
|
}
|
206
|
-
exports.
|
209
|
+
exports.OrderView = OrderView;
|
@@ -3,8 +3,8 @@ import "core-js/modules/es.array.push.js";
|
|
3
3
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
4
4
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
5
5
|
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
6
|
-
import {
|
7
|
-
import
|
6
|
+
import { ViewSizeSet } from "./viewSizeSet.mjs";
|
7
|
+
import { ViewDiffer } from "./viewDiffer/index.mjs";
|
8
8
|
/**
|
9
9
|
* Executive model for each table renderer. It's responsible for injecting DOM nodes in a
|
10
10
|
* specified order and adjusting the number of elements in the root node.
|
@@ -13,8 +13,8 @@ import ViewSizeSet from "./viewSizeSet.mjs";
|
|
13
13
|
*
|
14
14
|
* @class {OrderView}
|
15
15
|
*/
|
16
|
-
export
|
17
|
-
constructor(rootNode, nodesPool
|
16
|
+
export class OrderView {
|
17
|
+
constructor(rootNode, nodesPool) {
|
18
18
|
/**
|
19
19
|
* The root node to manage with.
|
20
20
|
*
|
@@ -24,7 +24,7 @@ export default class OrderView {
|
|
24
24
|
/**
|
25
25
|
* Factory for newly created DOM elements.
|
26
26
|
*
|
27
|
-
* @type {
|
27
|
+
* @type {function(number): HTMLElement}
|
28
28
|
*/
|
29
29
|
_defineProperty(this, "nodesPool", void 0);
|
30
30
|
/**
|
@@ -34,26 +34,39 @@ export default class OrderView {
|
|
34
34
|
*/
|
35
35
|
_defineProperty(this, "sizeSet", new ViewSizeSet());
|
36
36
|
/**
|
37
|
-
*
|
37
|
+
* The list of DOM elements which are rendered for this render cycle.
|
38
38
|
*
|
39
|
-
* @type {
|
39
|
+
* @type {HTMLElement[]}
|
40
40
|
*/
|
41
|
-
_defineProperty(this, "
|
41
|
+
_defineProperty(this, "collectedNodes", []);
|
42
42
|
/**
|
43
|
-
* The
|
43
|
+
* The differ which calculates the differences between current and next view. It generates
|
44
|
+
* commands that are processed by the OrderView (see `applyCommand` method).
|
44
45
|
*
|
45
|
-
* @type {
|
46
|
+
* @type {ViewDiffer}
|
46
47
|
*/
|
47
|
-
_defineProperty(this, "
|
48
|
+
_defineProperty(this, "viewDiffer", new ViewDiffer(this.sizeSet));
|
48
49
|
/**
|
49
|
-
*
|
50
|
+
* @type {number[]}
|
51
|
+
*/
|
52
|
+
_defineProperty(this, "staleNodeIndexes", []);
|
53
|
+
/**
|
54
|
+
* The list of render commands to execute. The command is an array with the following
|
55
|
+
* structure: [
|
56
|
+
* [
|
57
|
+
* 'prepend' | 'append' | 'insert_before' | 'replace' | 'remove', // command name
|
58
|
+
* 10, // processed node index
|
59
|
+
* 9, // previous node index (only for 'insert_before' and 'replace' commands)
|
60
|
+
* 8 // node index to remove (only for 'insert_before' command)
|
61
|
+
* ],
|
62
|
+
* ...
|
63
|
+
* ].
|
50
64
|
*
|
51
|
-
* @type {
|
65
|
+
* @type {Array[]}
|
52
66
|
*/
|
53
|
-
_defineProperty(this, "
|
67
|
+
_defineProperty(this, "leads", []);
|
54
68
|
this.rootNode = rootNode;
|
55
69
|
this.nodesPool = nodesPool;
|
56
|
-
this.childNodeType = childNodeType.toUpperCase();
|
57
70
|
}
|
58
71
|
|
59
72
|
/**
|
@@ -80,6 +93,14 @@ export default class OrderView {
|
|
80
93
|
return this;
|
81
94
|
}
|
82
95
|
|
96
|
+
/**
|
97
|
+
* @param {number} sourceIndex The source index.
|
98
|
+
* @returns {boolean}
|
99
|
+
*/
|
100
|
+
hasStaleContent(sourceIndex) {
|
101
|
+
return this.staleNodeIndexes.includes(sourceIndex);
|
102
|
+
}
|
103
|
+
|
83
104
|
/**
|
84
105
|
* Checks if this instance of the view shares the root node with another instance. This happens only once when
|
85
106
|
* a row (TR) as a root node is managed by two OrderView instances. If this happens another DOM injection
|
@@ -112,30 +133,44 @@ export default class OrderView {
|
|
112
133
|
}
|
113
134
|
|
114
135
|
/**
|
115
|
-
*
|
136
|
+
* Applies the commands generated by the differ into the specific DOM operations.
|
116
137
|
*
|
117
|
-
* @
|
138
|
+
* @param {Array} command The command to apply.
|
118
139
|
*/
|
119
|
-
|
140
|
+
applyCommand(command) {
|
120
141
|
const {
|
121
|
-
rootNode
|
122
|
-
sizeSet
|
142
|
+
rootNode
|
123
143
|
} = this;
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
144
|
+
const [name, nodeIndex, nodePrevIndex, nodeIndexToRemove] = command;
|
145
|
+
const node = this.nodesPool(nodeIndex);
|
146
|
+
this.collectedNodes.push(node);
|
147
|
+
|
148
|
+
// @TODO(perf-tip): Only nodes which are first time rendered (hasn't any inner content) can be marked as stale
|
149
|
+
// e.q `name !== 'none' && !node.firstChild`.
|
150
|
+
if (name !== 'none') {
|
151
|
+
this.staleNodeIndexes.push(nodeIndex);
|
152
|
+
}
|
153
|
+
switch (name) {
|
154
|
+
case 'prepend':
|
155
|
+
rootNode.insertBefore(node, rootNode.firstChild);
|
156
|
+
break;
|
157
|
+
case 'append':
|
158
|
+
rootNode.appendChild(node);
|
159
|
+
break;
|
160
|
+
case 'insert_before':
|
161
|
+
rootNode.insertBefore(node, this.nodesPool(nodePrevIndex));
|
162
|
+
// To keep the constant length of child nodes (after inserting a node) remove the last child.
|
163
|
+
rootNode.removeChild(this.nodesPool(nodeIndexToRemove));
|
164
|
+
break;
|
165
|
+
case 'replace':
|
166
|
+
rootNode.replaceChild(node, this.nodesPool(nodePrevIndex));
|
167
|
+
break;
|
168
|
+
case 'remove':
|
169
|
+
rootNode.removeChild(node);
|
170
|
+
break;
|
171
|
+
default:
|
172
|
+
break;
|
137
173
|
}
|
138
|
-
return childElementCount;
|
139
174
|
}
|
140
175
|
|
141
176
|
/**
|
@@ -144,30 +179,8 @@ export default class OrderView {
|
|
144
179
|
*/
|
145
180
|
start() {
|
146
181
|
this.collectedNodes.length = 0;
|
147
|
-
this.
|
148
|
-
|
149
|
-
rootNode,
|
150
|
-
sizeSet
|
151
|
-
} = this;
|
152
|
-
const isShared = this.isSharedViewSet();
|
153
|
-
const {
|
154
|
-
nextSize
|
155
|
-
} = sizeSet.getViewSize();
|
156
|
-
let childElementCount = this.getRenderedChildCount();
|
157
|
-
while (childElementCount < nextSize) {
|
158
|
-
const newNode = this.nodesPool();
|
159
|
-
if (!isShared || isShared && sizeSet.isPlaceOn(WORKING_SPACE_BOTTOM)) {
|
160
|
-
rootNode.appendChild(newNode);
|
161
|
-
} else {
|
162
|
-
rootNode.insertBefore(newNode, rootNode.firstChild);
|
163
|
-
}
|
164
|
-
childElementCount += 1;
|
165
|
-
}
|
166
|
-
const isSharedPlacedOnTop = isShared && sizeSet.isPlaceOn(WORKING_SPACE_TOP);
|
167
|
-
while (childElementCount > nextSize) {
|
168
|
-
rootNode.removeChild(isSharedPlacedOnTop ? rootNode.firstChild : rootNode.lastChild);
|
169
|
-
childElementCount -= 1;
|
170
|
-
}
|
182
|
+
this.staleNodeIndexes.length = 0;
|
183
|
+
this.leads = this.viewDiffer.diff();
|
171
184
|
}
|
172
185
|
|
173
186
|
/**
|
@@ -175,27 +188,18 @@ export default class OrderView {
|
|
175
188
|
* This method has to be called as many times as the size count is met (to cover all previously rendered DOM elements).
|
176
189
|
*/
|
177
190
|
render() {
|
178
|
-
|
179
|
-
|
180
|
-
sizeSet
|
181
|
-
} = this;
|
182
|
-
let visualIndex = this.visualIndex;
|
183
|
-
if (this.isSharedViewSet() && sizeSet.isPlaceOn(WORKING_SPACE_BOTTOM)) {
|
184
|
-
visualIndex += sizeSet.sharedSize.nextSize;
|
185
|
-
}
|
186
|
-
let node = rootNode.childNodes[visualIndex];
|
187
|
-
if (node.tagName !== this.childNodeType) {
|
188
|
-
const newNode = this.nodesPool();
|
189
|
-
rootNode.replaceChild(newNode, node);
|
190
|
-
node = newNode;
|
191
|
+
if (this.leads.length > 0) {
|
192
|
+
this.applyCommand(this.leads.shift());
|
191
193
|
}
|
192
|
-
this.collectedNodes.push(node);
|
193
|
-
this.visualIndex += 1;
|
194
194
|
}
|
195
195
|
|
196
196
|
/**
|
197
197
|
* Ends the render process.
|
198
198
|
* This method has to be called only once (at the end) for the render cycle.
|
199
199
|
*/
|
200
|
-
end() {
|
200
|
+
end() {
|
201
|
+
while (this.leads.length > 0) {
|
202
|
+
this.applyCommand(this.leads.shift());
|
203
|
+
}
|
204
|
+
}
|
201
205
|
}
|