handsontable 15.0.0 → 15.1.0-next-dfdf994-20250206

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 (168) hide show
  1. package/3rdparty/walkontable/src/index.js +2 -0
  2. package/3rdparty/walkontable/src/index.mjs +2 -1
  3. package/3rdparty/walkontable/src/overlays.js +2 -39
  4. package/3rdparty/walkontable/src/overlays.mjs +2 -39
  5. package/3rdparty/walkontable/src/renderer/_base.js +3 -4
  6. package/3rdparty/walkontable/src/renderer/_base.mjs +2 -2
  7. package/3rdparty/walkontable/src/renderer/cells.js +7 -11
  8. package/3rdparty/walkontable/src/renderer/cells.mjs +6 -9
  9. package/3rdparty/walkontable/src/renderer/colGroup.js +6 -7
  10. package/3rdparty/walkontable/src/renderer/colGroup.mjs +5 -5
  11. package/3rdparty/walkontable/src/renderer/columnHeaders.js +4 -5
  12. package/3rdparty/walkontable/src/renderer/columnHeaders.mjs +3 -3
  13. package/3rdparty/walkontable/src/renderer/index.js +18 -19
  14. package/3rdparty/walkontable/src/renderer/index.mjs +6 -6
  15. package/3rdparty/walkontable/src/renderer/rowHeaders.js +6 -7
  16. package/3rdparty/walkontable/src/renderer/rowHeaders.mjs +5 -5
  17. package/3rdparty/walkontable/src/renderer/rows.js +23 -11
  18. package/3rdparty/walkontable/src/renderer/rows.mjs +23 -10
  19. package/3rdparty/walkontable/src/renderer/table.js +1 -1
  20. package/3rdparty/walkontable/src/renderer/table.mjs +1 -1
  21. package/3rdparty/walkontable/src/selection/border/border.js +10 -2
  22. package/3rdparty/walkontable/src/selection/border/border.mjs +10 -2
  23. package/3rdparty/walkontable/src/utils/nodesPool.js +21 -6
  24. package/3rdparty/walkontable/src/utils/nodesPool.mjs +21 -6
  25. package/3rdparty/walkontable/src/utils/orderView/index.js +4 -5
  26. package/3rdparty/walkontable/src/utils/orderView/index.mjs +2 -2
  27. package/3rdparty/walkontable/src/utils/orderView/sharedView.js +3 -4
  28. package/3rdparty/walkontable/src/utils/orderView/sharedView.mjs +2 -2
  29. package/3rdparty/walkontable/src/utils/orderView/view.js +60 -76
  30. package/3rdparty/walkontable/src/utils/orderView/view.mjs +59 -74
  31. package/3rdparty/walkontable/src/utils/orderView/viewDiffer/index.js +138 -0
  32. package/3rdparty/walkontable/src/utils/orderView/viewDiffer/index.mjs +135 -0
  33. package/3rdparty/walkontable/src/utils/orderView/viewDiffer/viewOrder.js +72 -0
  34. package/3rdparty/walkontable/src/utils/orderView/viewDiffer/viewOrder.mjs +68 -0
  35. package/3rdparty/walkontable/src/utils/orderView/viewSize.js +1 -1
  36. package/3rdparty/walkontable/src/utils/orderView/viewSize.mjs +1 -1
  37. package/3rdparty/walkontable/src/utils/orderView/viewSizeSet.js +4 -5
  38. package/3rdparty/walkontable/src/utils/orderView/viewSizeSet.mjs +3 -3
  39. package/CHANGELOG.md +54 -0
  40. package/README.md +3 -3
  41. package/base.js +2 -2
  42. package/base.mjs +2 -2
  43. package/cellTypes/dropdownType/dropdownType.js +4 -2
  44. package/cellTypes/dropdownType/dropdownType.mjs +4 -2
  45. package/core.js +39 -38
  46. package/core.mjs +36 -35
  47. package/dataMap/dataMap.js +8 -0
  48. package/dataMap/dataMap.mjs +8 -0
  49. package/dataMap/dataSource.js +4 -0
  50. package/dataMap/dataSource.mjs +4 -0
  51. package/dataMap/metaManager/lazyFactoryMap.js +8 -5
  52. package/dataMap/metaManager/lazyFactoryMap.mjs +8 -5
  53. package/dataMap/metaManager/metaSchema.js +24 -9
  54. package/dataMap/metaManager/metaSchema.mjs +24 -9
  55. package/dist/handsontable.css +6 -2
  56. package/dist/handsontable.full.css +6 -2
  57. package/dist/handsontable.full.js +8020 -6915
  58. package/dist/handsontable.full.min.css +3 -3
  59. package/dist/handsontable.full.min.js +530 -528
  60. package/dist/handsontable.js +3827 -2902
  61. package/dist/handsontable.min.css +3 -3
  62. package/dist/handsontable.min.js +35 -33
  63. package/editors/autocompleteEditor/autocompleteEditor.js +1 -3
  64. package/editors/autocompleteEditor/autocompleteEditor.mjs +1 -3
  65. package/editors/dateEditor/dateEditor.js +4 -0
  66. package/editors/dateEditor/dateEditor.mjs +4 -0
  67. package/editors/dropdownEditor/dropdownEditor.js +3 -16
  68. package/editors/dropdownEditor/dropdownEditor.mjs +3 -16
  69. package/editors/handsontableEditor/handsontableEditor.js +4 -4
  70. package/editors/handsontableEditor/handsontableEditor.mjs +4 -4
  71. package/focusManager.js +1 -1
  72. package/focusManager.mjs +1 -1
  73. package/helpers/dom/element.d.ts +0 -1
  74. package/helpers/mixed.js +2 -2
  75. package/helpers/mixed.mjs +2 -2
  76. package/helpers/object.js +4 -0
  77. package/helpers/object.mjs +4 -0
  78. package/package.json +2 -2
  79. package/plugins/base/base.js +0 -7
  80. package/plugins/base/base.mjs +0 -7
  81. package/plugins/comments/comments.js +12 -3
  82. package/plugins/comments/comments.mjs +12 -3
  83. package/plugins/contextMenu/contextMenu.js +2 -7
  84. package/plugins/contextMenu/contextMenu.mjs +2 -7
  85. package/plugins/contextMenu/menu/menu.js +2 -2
  86. package/plugins/contextMenu/menu/menu.mjs +2 -2
  87. package/plugins/contextMenu/predefinedItems/clearColumn.js +15 -4
  88. package/plugins/contextMenu/predefinedItems/clearColumn.mjs +15 -4
  89. package/plugins/filters/conditionCollection.js +8 -7
  90. package/plugins/filters/conditionCollection.mjs +8 -7
  91. package/plugins/filters/filters.js +26 -16
  92. package/plugins/filters/filters.mjs +26 -16
  93. package/plugins/filters/utils.js +7 -24
  94. package/plugins/filters/utils.mjs +7 -24
  95. package/plugins/hiddenColumns/hiddenColumns.js +1 -3
  96. package/plugins/hiddenColumns/hiddenColumns.mjs +1 -3
  97. package/plugins/hiddenRows/hiddenRows.js +1 -3
  98. package/plugins/hiddenRows/hiddenRows.mjs +1 -3
  99. package/plugins/manualRowMove/manualRowMove.js +1 -1
  100. package/plugins/manualRowMove/manualRowMove.mjs +1 -1
  101. package/plugins/mergeCells/calculations/autofill.js +60 -44
  102. package/plugins/mergeCells/calculations/autofill.mjs +60 -44
  103. package/plugins/mergeCells/cellsCollection.js +25 -8
  104. package/plugins/mergeCells/cellsCollection.mjs +25 -8
  105. package/plugins/mergeCells/mergeCells.js +15 -16
  106. package/plugins/mergeCells/mergeCells.mjs +15 -16
  107. package/plugins/nestedHeaders/nestedHeaders.js +6 -1
  108. package/plugins/nestedHeaders/nestedHeaders.mjs +6 -1
  109. package/plugins/nestedHeaders/stateManager/index.js +1 -2
  110. package/plugins/nestedHeaders/stateManager/index.mjs +1 -2
  111. package/plugins/nestedHeaders/utils/ghostTable.js +4 -0
  112. package/plugins/nestedHeaders/utils/ghostTable.mjs +4 -0
  113. package/plugins/nestedRows/utils/rowMoveController.js +1 -6
  114. package/plugins/nestedRows/utils/rowMoveController.mjs +1 -6
  115. package/plugins/undoRedo/actions/_base.js +19 -0
  116. package/plugins/undoRedo/actions/_base.mjs +15 -0
  117. package/plugins/undoRedo/actions/cellAlignment.js +85 -0
  118. package/plugins/undoRedo/actions/cellAlignment.mjs +81 -0
  119. package/plugins/undoRedo/actions/columnMove.js +84 -0
  120. package/plugins/undoRedo/actions/columnMove.mjs +80 -0
  121. package/plugins/undoRedo/actions/columnSort.js +73 -0
  122. package/plugins/undoRedo/actions/columnSort.mjs +69 -0
  123. package/plugins/undoRedo/actions/createColumn.js +60 -0
  124. package/plugins/undoRedo/actions/createColumn.mjs +56 -0
  125. package/plugins/undoRedo/actions/createRow.js +65 -0
  126. package/plugins/undoRedo/actions/createRow.mjs +61 -0
  127. package/plugins/undoRedo/actions/dataChange.js +123 -0
  128. package/plugins/undoRedo/actions/dataChange.mjs +119 -0
  129. package/plugins/undoRedo/actions/filters.js +66 -0
  130. package/plugins/undoRedo/actions/filters.mjs +62 -0
  131. package/plugins/undoRedo/actions/index.js +27 -0
  132. package/plugins/undoRedo/actions/index.mjs +23 -0
  133. package/plugins/undoRedo/actions/mergeCells.js +63 -0
  134. package/plugins/undoRedo/actions/mergeCells.mjs +59 -0
  135. package/plugins/undoRedo/actions/removeColumn.js +176 -0
  136. package/plugins/undoRedo/actions/removeColumn.mjs +172 -0
  137. package/plugins/undoRedo/actions/removeRow.js +119 -0
  138. package/plugins/undoRedo/actions/removeRow.mjs +115 -0
  139. package/plugins/undoRedo/actions/rowMove.js +84 -0
  140. package/plugins/undoRedo/actions/rowMove.mjs +80 -0
  141. package/plugins/undoRedo/actions/unmergeCells.js +56 -0
  142. package/plugins/undoRedo/actions/unmergeCells.mjs +52 -0
  143. package/plugins/undoRedo/index.js +3 -4
  144. package/plugins/undoRedo/index.mjs +1 -2
  145. package/plugins/undoRedo/undoRedo.js +277 -879
  146. package/plugins/undoRedo/undoRedo.mjs +277 -880
  147. package/plugins/undoRedo/utils.js +37 -0
  148. package/plugins/undoRedo/utils.mjs +33 -0
  149. package/renderers/checkboxRenderer/checkboxRenderer.js +8 -1
  150. package/renderers/checkboxRenderer/checkboxRenderer.mjs +8 -1
  151. package/shortcutContexts/commands/moveCellSelection/downByViewportHeight.js +1 -0
  152. package/shortcutContexts/commands/moveCellSelection/downByViewportHeight.mjs +1 -0
  153. package/shortcutContexts/commands/moveCellSelection/upByViewportHeight.js +2 -1
  154. package/shortcutContexts/commands/moveCellSelection/upByViewportHeight.mjs +2 -1
  155. package/styles/handsontable.css +75 -103
  156. package/styles/handsontable.min.css +3 -3
  157. package/styles/ht-theme-horizon.css +2 -2
  158. package/styles/ht-theme-horizon.min.css +2 -2
  159. package/styles/ht-theme-main.css +2 -2
  160. package/styles/ht-theme-main.min.css +2 -2
  161. package/tableView.js +17 -1
  162. package/tableView.mjs +17 -1
  163. package/utils/autoResize.js +1 -1
  164. package/utils/autoResize.mjs +1 -1
  165. package/utils/parseTable.js +1 -1
  166. package/utils/parseTable.mjs +1 -1
  167. package/validators/dateValidator/dateValidator.js +1 -1
  168. package/validators/dateValidator/dateValidator.mjs +1 -1
@@ -2,11 +2,11 @@ import "core-js/modules/es.error.cause.js";
2
2
  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; }
3
3
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
4
4
  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); }
5
- import BaseRenderer from "./_base.mjs";
6
- import { warn } from "./../../../../helpers/console.mjs";
7
- import { toSingleLine } from "./../../../../helpers/templateLiteralTag.mjs";
8
- import { OrderView } from "./../utils/orderView/index.mjs";
9
- import { addClass, removeClass, setAttribute } from "../../../../helpers/dom/element.mjs";
5
+ import { BaseRenderer } from "./_base.mjs";
6
+ import { warn } from "../../../../helpers/console.mjs";
7
+ import { toSingleLine } from "../../../../helpers/templateLiteralTag.mjs";
8
+ import { OrderView } from "../utils/orderView/index.mjs";
9
+ import { addClass, hasClass, removeClass, setAttribute } from "../../../../helpers/dom/element.mjs";
10
10
  import { A11Y_ROW, A11Y_ROWGROUP, A11Y_ROWINDEX } from "../../../../helpers/a11y.mjs";
11
11
  const ROW_CLASSNAMES = {
12
12
  rowEven: 'ht__row_even',
@@ -26,7 +26,7 @@ let performanceWarningAppeared = false;
26
26
  *
27
27
  * @class {RowsRenderer}
28
28
  */
29
- export default class RowsRenderer extends BaseRenderer {
29
+ export class RowsRenderer extends BaseRenderer {
30
30
  constructor(rootNode) {
31
31
  super('TR', rootNode);
32
32
  /**
@@ -35,7 +35,7 @@ export default class RowsRenderer extends BaseRenderer {
35
35
  * @type {WeakMap}
36
36
  */
37
37
  _defineProperty(this, "orderView", void 0);
38
- this.orderView = new OrderView(rootNode, sourceRowIndex => this.nodesPool.obtain(sourceRowIndex), this.nodeType);
38
+ this.orderView = new OrderView(rootNode, sourceRowIndex => this.nodesPool.obtain(sourceRowIndex));
39
39
  }
40
40
 
41
41
  /**
@@ -48,6 +48,16 @@ export default class RowsRenderer extends BaseRenderer {
48
48
  return this.orderView.getNode(visualIndex);
49
49
  }
50
50
 
51
+ /**
52
+ * Checks if the the row is marked as "stale" and has to be rerendered.
53
+ *
54
+ * @param {number} visualIndex Visual index of the rendered node (it always goeas from 0 to N).
55
+ * @returns {boolean}
56
+ */
57
+ hasStaleContent(visualIndex) {
58
+ return this.orderView.hasStaleContent(visualIndex);
59
+ }
60
+
51
61
  /**
52
62
  * Renders the cells.
53
63
  */
@@ -75,10 +85,13 @@ export default class RowsRenderer extends BaseRenderer {
75
85
  // `aria-rowindex` is incremented by both tbody and thead rows.
76
86
  A11Y_ROWINDEX(sourceRowIndex + ((_this$table$rowUtils$ = (_this$table$rowUtils = this.table.rowUtils) === null || _this$table$rowUtils === void 0 || (_this$table$rowUtils = _this$table$rowUtils.dataAccessObject) === null || _this$table$rowUtils === void 0 ? void 0 : _this$table$rowUtils.columnHeaders.length) !== null && _this$table$rowUtils$ !== void 0 ? _this$table$rowUtils$ : 0) + 1)]);
77
87
  }
78
- removeClass(TR, [ROW_CLASSNAMES.rowEven, ROW_CLASSNAMES.rowOdd]);
79
88
  if ((sourceRowIndex + 1) % 2 === 0) {
80
- addClass(TR, ROW_CLASSNAMES.rowEven);
81
- } else {
89
+ if (!hasClass(TR, ROW_CLASSNAMES.rowEven)) {
90
+ removeClass(TR, ROW_CLASSNAMES.rowOdd);
91
+ addClass(TR, ROW_CLASSNAMES.rowEven);
92
+ }
93
+ } else if (!hasClass(TR, ROW_CLASSNAMES.rowOdd)) {
94
+ removeClass(TR, ROW_CLASSNAMES.rowEven);
82
95
  addClass(TR, ROW_CLASSNAMES.rowOdd);
83
96
  }
84
97
  }
@@ -335,4 +335,4 @@ class TableRenderer {
335
335
  }
336
336
  }
337
337
  }
338
- exports.default = TableRenderer;
338
+ exports.TableRenderer = TableRenderer;
@@ -46,7 +46,7 @@ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e =
46
46
  *
47
47
  * @class {RowsRenderer}
48
48
  */
49
- export default class TableRenderer {
49
+ export class TableRenderer {
50
50
  constructor(rootNode) {
51
51
  let {
52
52
  cellRenderer,
@@ -477,9 +477,17 @@ class Border {
477
477
  const toTdOffsetTop = trimToWindow ? toTD.getBoundingClientRect().top : toTD.offsetTop;
478
478
  const cornerBottomEdge = toTdOffsetTop + (0, _element.outerHeight)(toTD) + parseInt(this.cornerDefaultStyle.height, 10) / 2;
479
479
  const cornerOverlappingContainer = cornerBottomEdge >= (0, _element.innerHeight)(trimmingContainer);
480
+ const isClassicTheme = this.wot.stylesHandler.isClassicTheme();
480
481
  if (cornerOverlappingContainer) {
481
- this.cornerStyle.top = `${Math.floor(top + height + this.cornerCenterPointOffset - cornerHalfHeight - cornerBorderCompensation)}px`;
482
- this.cornerStyle.borderBottomWidth = 0;
482
+ const cornerTopPosition = Math.floor(top + height + this.cornerCenterPointOffset - cornerHalfHeight - cornerBorderCompensation);
483
+ if (isClassicTheme) {
484
+ // styles for classic theme
485
+ this.cornerStyle.top = `${cornerTopPosition}px`;
486
+ this.cornerStyle.borderBottomWidth = 0;
487
+ } else {
488
+ // styles for ht-theme
489
+ this.cornerStyle.top = `${cornerTopPosition - 1}px`;
490
+ }
483
491
  }
484
492
  }
485
493
  this.cornerStyle.display = 'block';
@@ -474,9 +474,17 @@ class Border {
474
474
  const toTdOffsetTop = trimToWindow ? toTD.getBoundingClientRect().top : toTD.offsetTop;
475
475
  const cornerBottomEdge = toTdOffsetTop + outerHeight(toTD) + parseInt(this.cornerDefaultStyle.height, 10) / 2;
476
476
  const cornerOverlappingContainer = cornerBottomEdge >= innerHeight(trimmingContainer);
477
+ const isClassicTheme = this.wot.stylesHandler.isClassicTheme();
477
478
  if (cornerOverlappingContainer) {
478
- this.cornerStyle.top = `${Math.floor(top + height + this.cornerCenterPointOffset - cornerHalfHeight - cornerBorderCompensation)}px`;
479
- this.cornerStyle.borderBottomWidth = 0;
479
+ const cornerTopPosition = Math.floor(top + height + this.cornerCenterPointOffset - cornerHalfHeight - cornerBorderCompensation);
480
+ if (isClassicTheme) {
481
+ // styles for classic theme
482
+ this.cornerStyle.top = `${cornerTopPosition}px`;
483
+ this.cornerStyle.borderBottomWidth = 0;
484
+ } else {
485
+ // styles for ht-theme
486
+ this.cornerStyle.top = `${cornerTopPosition - 1}px`;
487
+ }
480
488
  }
481
489
  }
482
490
  this.cornerStyle.display = 'block';
@@ -13,30 +13,45 @@ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e =
13
13
  class NodesPool {
14
14
  constructor(nodeType) {
15
15
  /**
16
- * Node type to generate (ew 'th', 'td').
16
+ * Node type to generate (e.g. 'TH', 'TD').
17
17
  *
18
18
  * @type {string}
19
19
  */
20
20
  _defineProperty(this, "nodeType", void 0);
21
+ /**
22
+ * The holder for all created DOM nodes (THs, TDs).
23
+ *
24
+ * @type {Map<string, HTMLElement>}
25
+ */
26
+ _defineProperty(this, "pool", new Map());
21
27
  this.nodeType = nodeType.toUpperCase();
22
28
  }
23
29
 
24
30
  /**
25
31
  * Set document owner for this instance.
26
32
  *
27
- * @param {HTMLDocument} rootDocument The document window owner.
33
+ * @param {Document} rootDocument The document window owner.
28
34
  */
29
35
  setRootDocument(rootDocument) {
30
36
  this.rootDocument = rootDocument;
31
37
  }
32
38
 
33
39
  /**
34
- * Obtains an element. The returned elements in the feature can be cached.
40
+ * Obtains an element.
35
41
  *
42
+ * @param {number} rowIndex The row index.
43
+ * @param {number} [columnIndex] The column index.
36
44
  * @returns {HTMLElement}
37
45
  */
38
- obtain() {
39
- return this.rootDocument.createElement(this.nodeType);
46
+ obtain(rowIndex, columnIndex) {
47
+ const hasColumnIndex = typeof columnIndex === 'number';
48
+ const key = hasColumnIndex ? `${rowIndex}x${columnIndex}` : rowIndex.toString();
49
+ if (this.pool.has(key)) {
50
+ return this.pool.get(key);
51
+ }
52
+ const node = this.rootDocument.createElement(this.nodeType);
53
+ this.pool.set(key, node);
54
+ return node;
40
55
  }
41
56
  }
42
- exports.default = NodesPool;
57
+ exports.NodesPool = NodesPool;
@@ -7,32 +7,47 @@ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e =
7
7
  *
8
8
  * @class {NodesPool}
9
9
  */
10
- export default class NodesPool {
10
+ export class NodesPool {
11
11
  constructor(nodeType) {
12
12
  /**
13
- * Node type to generate (ew 'th', 'td').
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 {HTMLDocument} rootDocument The document window owner.
30
+ * @param {Document} rootDocument The document window owner.
25
31
  */
26
32
  setRootDocument(rootDocument) {
27
33
  this.rootDocument = rootDocument;
28
34
  }
29
35
 
30
36
  /**
31
- * Obtains an element. The returned elements in the feature can be cached.
37
+ * Obtains an element.
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
- return this.rootDocument.createElement(this.nodeType);
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
+ this.pool.set(key, node);
51
+ return node;
37
52
  }
38
53
  }
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  exports.__esModule = true;
4
- var _view = _interopRequireDefault(require("./view"));
5
- exports.OrderView = _view.default;
6
- var _sharedView = _interopRequireDefault(require("./sharedView"));
7
- exports.SharedOrderView = _sharedView.default;
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 = _interopRequireDefault(require("./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.default {
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.default = SharedOrderView;
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 default class SharedOrderView extends OrderView {
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 _constants = require("./constants");
7
- var _viewSizeSet = _interopRequireDefault(require("./viewSizeSet"));
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, childNodeType) {
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 {Function}
30
+ * @type {function(number): HTMLElement}
32
31
  */
33
32
  _defineProperty(this, "nodesPool", void 0);
34
33
  /**
@@ -36,28 +35,37 @@ class OrderView {
36
35
  *
37
36
  * @type {ViewSizeSet}
38
37
  */
39
- _defineProperty(this, "sizeSet", new _viewSizeSet.default());
38
+ _defineProperty(this, "sizeSet", new _viewSizeSet.ViewSizeSet());
40
39
  /**
41
- * Node type which the order view will manage while rendering the DOM elements.
40
+ * The list of DOM elements which are rendered for this render cycle.
42
41
  *
43
- * @type {string}
42
+ * @type {HTMLElement[]}
44
43
  */
45
- _defineProperty(this, "childNodeType", void 0);
44
+ _defineProperty(this, "collectedNodes", []);
46
45
  /**
47
- * The visual index of currently processed row.
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 {number}
49
+ * @type {ViewDiffer}
50
50
  */
51
- _defineProperty(this, "visualIndex", 0);
51
+ _defineProperty(this, "viewDiffer", new _viewDiffer.ViewDiffer(this.sizeSet));
52
52
  /**
53
- * The list of DOM elements which are rendered for this render cycle.
53
+ * The list of render commands to execute. The command is an array with the following
54
+ * structure: [
55
+ * [
56
+ * 'prepend' | 'append' | 'insert_before' | 'replace' | 'remove', // command name
57
+ * 10, // processed node index
58
+ * 9, // previous node index (only for 'insert_before' and 'replace' commands)
59
+ * 8 // node index to remove (only for 'insert_before' command)
60
+ * ],
61
+ * ...
62
+ * ].
54
63
  *
55
- * @type {HTMLElement[]}
64
+ * @type {Array[]}
56
65
  */
57
- _defineProperty(this, "collectedNodes", []);
66
+ _defineProperty(this, "leads", []);
58
67
  this.rootNode = rootNode;
59
68
  this.nodesPool = nodesPool;
60
- this.childNodeType = childNodeType.toUpperCase();
61
69
  }
62
70
 
63
71
  /**
@@ -116,30 +124,38 @@ class OrderView {
116
124
  }
117
125
 
118
126
  /**
119
- * Returns rendered child count for this instance.
127
+ * Applies the commands generated by the differ into the specific DOM operations.
120
128
  *
121
- * @returns {number}
129
+ * @param {Array} command The command to apply.
122
130
  */
123
- getRenderedChildCount() {
131
+ applyCommand(command) {
124
132
  const {
125
- rootNode,
126
- sizeSet
133
+ rootNode
127
134
  } = this;
128
- let childElementCount = 0;
129
- if (this.isSharedViewSet()) {
130
- let element = rootNode.firstElementChild;
131
- while (element) {
132
- if (element.tagName === this.childNodeType) {
133
- childElementCount += 1;
134
- } else if (sizeSet.isPlaceOn(_constants.WORKING_SPACE_TOP)) {
135
- break;
136
- }
137
- element = element.nextElementSibling;
138
- }
139
- } else {
140
- childElementCount = rootNode.childElementCount;
135
+ const [name, nodeIndex, nodePrevIndex, nodeIndexToRemove] = command;
136
+ const node = this.nodesPool(nodeIndex);
137
+ this.collectedNodes.push(node);
138
+ switch (name) {
139
+ case 'prepend':
140
+ rootNode.insertBefore(node, rootNode.firstChild);
141
+ break;
142
+ case 'append':
143
+ rootNode.appendChild(node);
144
+ break;
145
+ case 'insert_before':
146
+ rootNode.insertBefore(node, this.nodesPool(nodePrevIndex));
147
+ // To keep the constant length of child nodes (after inserting a node) remove the last child.
148
+ rootNode.removeChild(this.nodesPool(nodeIndexToRemove));
149
+ break;
150
+ case 'replace':
151
+ rootNode.replaceChild(node, this.nodesPool(nodePrevIndex));
152
+ break;
153
+ case 'remove':
154
+ rootNode.removeChild(node);
155
+ break;
156
+ default:
157
+ break;
141
158
  }
142
- return childElementCount;
143
159
  }
144
160
 
145
161
  /**
@@ -148,30 +164,7 @@ class OrderView {
148
164
  */
149
165
  start() {
150
166
  this.collectedNodes.length = 0;
151
- this.visualIndex = 0;
152
- const {
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
- }
167
+ this.leads = this.viewDiffer.diff();
175
168
  }
176
169
 
177
170
  /**
@@ -179,28 +172,19 @@ class OrderView {
179
172
  * This method has to be called as many times as the size count is met (to cover all previously rendered DOM elements).
180
173
  */
181
174
  render() {
182
- const {
183
- rootNode,
184
- sizeSet
185
- } = this;
186
- let visualIndex = this.visualIndex;
187
- if (this.isSharedViewSet() && sizeSet.isPlaceOn(_constants.WORKING_SPACE_BOTTOM)) {
188
- visualIndex += sizeSet.sharedSize.nextSize;
175
+ if (this.leads.length > 0) {
176
+ this.applyCommand(this.leads.shift());
189
177
  }
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;
195
- }
196
- this.collectedNodes.push(node);
197
- this.visualIndex += 1;
198
178
  }
199
179
 
200
180
  /**
201
181
  * Ends the render process.
202
182
  * This method has to be called only once (at the end) for the render cycle.
203
183
  */
204
- end() {}
184
+ end() {
185
+ while (this.leads.length > 0) {
186
+ this.applyCommand(this.leads.shift());
187
+ }
188
+ }
205
189
  }
206
- exports.default = OrderView;
190
+ exports.OrderView = OrderView;