@visactor/vtable-plugins 1.19.9-alpha.2 → 1.20.0-alpha.0

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 (268) hide show
  1. package/README.md +7 -4
  2. package/cjs/add-row-column.d.ts +2 -2
  3. package/cjs/add-row-column.js +3 -3
  4. package/cjs/add-row-column.js.map +1 -1
  5. package/cjs/auto-fill/auto-fill-helper.d.ts +23 -0
  6. package/cjs/auto-fill/auto-fill-helper.js +83 -0
  7. package/cjs/auto-fill/auto-fill-helper.js.map +1 -0
  8. package/cjs/auto-fill/auto-fill-manager.d.ts +26 -0
  9. package/cjs/auto-fill/auto-fill-manager.js +244 -0
  10. package/cjs/auto-fill/auto-fill-manager.js.map +1 -0
  11. package/cjs/auto-fill/auto-fill-services.d.ts +12 -0
  12. package/cjs/auto-fill/auto-fill-services.js +27 -0
  13. package/cjs/auto-fill/auto-fill-services.js.map +1 -0
  14. package/cjs/auto-fill/date-tools.d.ts +5 -0
  15. package/cjs/auto-fill/date-tools.js +37 -0
  16. package/cjs/auto-fill/date-tools.js.map +1 -0
  17. package/cjs/auto-fill/index.d.ts +21 -0
  18. package/cjs/auto-fill/index.js +52 -0
  19. package/cjs/auto-fill/index.js.map +1 -0
  20. package/cjs/auto-fill/rules.d.ts +10 -0
  21. package/cjs/auto-fill/rules.js +196 -0
  22. package/cjs/auto-fill/rules.js.map +1 -0
  23. package/cjs/auto-fill/series-converters.d.ts +27 -0
  24. package/cjs/auto-fill/series-converters.js +90 -0
  25. package/cjs/auto-fill/series-converters.js.map +1 -0
  26. package/cjs/auto-fill/types.d.ts +67 -0
  27. package/cjs/auto-fill/types.js +20 -0
  28. package/cjs/auto-fill/types.js.map +1 -0
  29. package/cjs/auto-fill/utils/date.d.ts +5 -0
  30. package/cjs/auto-fill/utils/date.js +76 -0
  31. package/cjs/auto-fill/utils/date.js.map +1 -0
  32. package/cjs/auto-fill/utils/fill.d.ts +82 -0
  33. package/cjs/auto-fill/utils/fill.js +361 -0
  34. package/cjs/auto-fill/utils/fill.js.map +1 -0
  35. package/cjs/carousel-animation.d.ts +1 -1
  36. package/cjs/carousel-animation.js.map +1 -1
  37. package/cjs/column-series.js +1 -1
  38. package/cjs/column-series.js.map +1 -1
  39. package/cjs/context-menu.d.ts +34 -0
  40. package/cjs/context-menu.js +157 -0
  41. package/cjs/context-menu.js.map +1 -0
  42. package/cjs/contextmenu/handle-menu-helper.d.ts +23 -0
  43. package/cjs/contextmenu/handle-menu-helper.js +107 -0
  44. package/cjs/contextmenu/handle-menu-helper.js.map +1 -0
  45. package/cjs/contextmenu/index.d.ts +3 -0
  46. package/cjs/contextmenu/index.js +22 -0
  47. package/cjs/contextmenu/index.js.map +1 -0
  48. package/cjs/contextmenu/menu-manager.d.ts +27 -0
  49. package/cjs/contextmenu/menu-manager.js +139 -0
  50. package/cjs/contextmenu/menu-manager.js.map +1 -0
  51. package/cjs/contextmenu/styles.d.ts +106 -0
  52. package/cjs/contextmenu/styles.js +195 -0
  53. package/cjs/contextmenu/styles.js.map +1 -0
  54. package/cjs/contextmenu/types.d.ts +69 -0
  55. package/cjs/contextmenu/types.js +122 -0
  56. package/cjs/contextmenu/types.js.map +1 -0
  57. package/cjs/excel-edit-cell-keyboard.js +2 -2
  58. package/cjs/excel-edit-cell-keyboard.js.map +1 -1
  59. package/cjs/excel-import.js +8 -8
  60. package/cjs/excel-import.js.map +1 -1
  61. package/cjs/fillHandleUtils/autoFillHandle.js.map +1 -1
  62. package/cjs/fillHandleUtils/translateRowObj.js.map +1 -1
  63. package/cjs/filter/condition-filter.d.ts +30 -0
  64. package/cjs/filter/condition-filter.js +271 -0
  65. package/cjs/filter/condition-filter.js.map +1 -0
  66. package/cjs/filter/filter-engine.d.ts +13 -0
  67. package/cjs/filter/filter-engine.js +102 -0
  68. package/cjs/filter/filter-engine.js.map +1 -0
  69. package/cjs/filter/filter-state-manager.d.ts +21 -0
  70. package/cjs/filter/filter-state-manager.js +102 -0
  71. package/cjs/filter/filter-state-manager.js.map +1 -0
  72. package/cjs/filter/filter-toolbar.d.ts +31 -0
  73. package/cjs/filter/filter-toolbar.js +98 -0
  74. package/cjs/filter/filter-toolbar.js.map +1 -0
  75. package/cjs/filter/filter.d.ts +26 -0
  76. package/cjs/filter/filter.js +150 -0
  77. package/cjs/filter/filter.js.map +1 -0
  78. package/cjs/filter/index.d.ts +7 -0
  79. package/cjs/filter/index.js +66 -0
  80. package/cjs/filter/index.js.map +1 -0
  81. package/cjs/filter/styles.d.ts +126 -0
  82. package/cjs/filter/styles.js +145 -0
  83. package/cjs/filter/styles.js.map +1 -0
  84. package/cjs/filter/types.d.ts +55 -0
  85. package/cjs/filter/types.js +18 -0
  86. package/cjs/filter/types.js.map +1 -0
  87. package/cjs/filter/value-filter.d.ts +31 -0
  88. package/cjs/filter/value-filter.js +280 -0
  89. package/cjs/filter/value-filter.js.map +1 -0
  90. package/cjs/focus-highlight.js +1 -1
  91. package/cjs/focus-highlight.js.map +1 -1
  92. package/cjs/gantt-export-image.js.map +1 -1
  93. package/cjs/header-highlight.js.map +1 -1
  94. package/cjs/highlight-header-when-select-cell.d.ts +1 -2
  95. package/cjs/highlight-header-when-select-cell.js +1 -1
  96. package/cjs/highlight-header-when-select-cell.js.map +1 -1
  97. package/cjs/index.d.ts +4 -0
  98. package/cjs/index.js +3 -1
  99. package/cjs/index.js.map +1 -1
  100. package/cjs/invert-highlight.js.map +1 -1
  101. package/cjs/paste-add-row-column.d.ts +1 -0
  102. package/cjs/paste-add-row-column.js +3 -2
  103. package/cjs/paste-add-row-column.js.map +1 -1
  104. package/cjs/rotate-table.js +1 -1
  105. package/cjs/rotate-table.js.map +1 -1
  106. package/cjs/row-series.js +1 -1
  107. package/cjs/row-series.js.map +1 -1
  108. package/cjs/table-carousel-animation.js +2 -3
  109. package/cjs/table-carousel-animation.js.map +1 -1
  110. package/cjs/table-export/csv/index.js +1 -1
  111. package/cjs/table-export/csv/index.js.map +1 -1
  112. package/cjs/table-export/excel/index.js +0 -1
  113. package/cjs/table-export/excel/index.js.map +1 -1
  114. package/cjs/table-export/excel/style.js.map +1 -1
  115. package/cjs/table-export/index.js.map +1 -1
  116. package/cjs/table-export/util/color.js.map +1 -1
  117. package/cjs/table-export/util/download.js.map +1 -1
  118. package/cjs/table-export/util/encode.js.map +1 -1
  119. package/cjs/table-export/util/indent.js.map +1 -1
  120. package/cjs/table-export/util/pagination.js.map +1 -1
  121. package/cjs/table-export/util/promise.js.map +1 -1
  122. package/cjs/table-export/util/type.js +1 -1
  123. package/cjs/table-export/util/type.js.map +1 -1
  124. package/cjs/table-export.js +1 -2
  125. package/cjs/table-export.js.map +1 -1
  126. package/cjs/table-series-number.d.ts +41 -0
  127. package/cjs/table-series-number.js +261 -0
  128. package/cjs/table-series-number.js.map +1 -0
  129. package/cjs/types.d.ts +1 -0
  130. package/cjs/types.js +17 -1
  131. package/cjs/types.js.map +1 -1
  132. package/cjs/wps-fill-handle.js +1 -1
  133. package/cjs/wps-fill-handle.js.map +1 -1
  134. package/dist/vtable-plugins.js +7594 -1492
  135. package/dist/vtable-plugins.min.js +14 -14
  136. package/es/add-row-column.d.ts +2 -2
  137. package/es/add-row-column.js +3 -3
  138. package/es/add-row-column.js.map +1 -1
  139. package/es/auto-fill/auto-fill-helper.d.ts +23 -0
  140. package/es/auto-fill/auto-fill-helper.js +75 -0
  141. package/es/auto-fill/auto-fill-helper.js.map +1 -0
  142. package/es/auto-fill/auto-fill-manager.d.ts +26 -0
  143. package/es/auto-fill/auto-fill-manager.js +218 -0
  144. package/es/auto-fill/auto-fill-manager.js.map +1 -0
  145. package/es/auto-fill/auto-fill-services.d.ts +12 -0
  146. package/es/auto-fill/auto-fill-services.js +19 -0
  147. package/es/auto-fill/auto-fill-services.js.map +1 -0
  148. package/es/auto-fill/date-tools.d.ts +5 -0
  149. package/es/auto-fill/date-tools.js +29 -0
  150. package/es/auto-fill/date-tools.js.map +1 -0
  151. package/es/auto-fill/index.d.ts +21 -0
  152. package/es/auto-fill/index.js +21 -0
  153. package/es/auto-fill/index.js.map +1 -0
  154. package/es/auto-fill/rules.d.ts +10 -0
  155. package/es/auto-fill/rules.js +203 -0
  156. package/es/auto-fill/rules.js.map +1 -0
  157. package/es/auto-fill/series-converters.d.ts +27 -0
  158. package/es/auto-fill/series-converters.js +83 -0
  159. package/es/auto-fill/series-converters.js.map +1 -0
  160. package/es/auto-fill/types.d.ts +67 -0
  161. package/es/auto-fill/types.js +27 -0
  162. package/es/auto-fill/types.js.map +1 -0
  163. package/es/auto-fill/utils/date.d.ts +5 -0
  164. package/es/auto-fill/utils/date.js +68 -0
  165. package/es/auto-fill/utils/date.js.map +1 -0
  166. package/es/auto-fill/utils/fill.d.ts +82 -0
  167. package/es/auto-fill/utils/fill.js +347 -0
  168. package/es/auto-fill/utils/fill.js.map +1 -0
  169. package/es/carousel-animation.d.ts +1 -1
  170. package/es/carousel-animation.js.map +1 -1
  171. package/es/column-series.js +1 -1
  172. package/es/column-series.js.map +1 -1
  173. package/es/context-menu.d.ts +34 -0
  174. package/es/context-menu.js +129 -0
  175. package/es/context-menu.js.map +1 -0
  176. package/es/contextmenu/handle-menu-helper.d.ts +23 -0
  177. package/es/contextmenu/handle-menu-helper.js +99 -0
  178. package/es/contextmenu/handle-menu-helper.js.map +1 -0
  179. package/es/contextmenu/index.d.ts +3 -0
  180. package/es/contextmenu/index.js +6 -0
  181. package/es/contextmenu/index.js.map +1 -0
  182. package/es/contextmenu/menu-manager.d.ts +27 -0
  183. package/es/contextmenu/menu-manager.js +130 -0
  184. package/es/contextmenu/menu-manager.js.map +1 -0
  185. package/es/contextmenu/styles.d.ts +106 -0
  186. package/es/contextmenu/styles.js +197 -0
  187. package/es/contextmenu/styles.js.map +1 -0
  188. package/es/contextmenu/types.d.ts +69 -0
  189. package/es/contextmenu/types.js +121 -0
  190. package/es/contextmenu/types.js.map +1 -0
  191. package/es/excel-edit-cell-keyboard.js +2 -2
  192. package/es/excel-edit-cell-keyboard.js.map +1 -1
  193. package/es/excel-import.js +8 -8
  194. package/es/excel-import.js.map +1 -1
  195. package/es/fillHandleUtils/autoFillHandle.js.map +1 -1
  196. package/es/fillHandleUtils/translateRowObj.js.map +1 -1
  197. package/es/filter/condition-filter.d.ts +30 -0
  198. package/es/filter/condition-filter.js +262 -0
  199. package/es/filter/condition-filter.js.map +1 -0
  200. package/es/filter/filter-engine.d.ts +13 -0
  201. package/es/filter/filter-engine.js +94 -0
  202. package/es/filter/filter-engine.js.map +1 -0
  203. package/es/filter/filter-state-manager.d.ts +21 -0
  204. package/es/filter/filter-state-manager.js +94 -0
  205. package/es/filter/filter-state-manager.js.map +1 -0
  206. package/es/filter/filter-toolbar.d.ts +31 -0
  207. package/es/filter/filter-toolbar.js +90 -0
  208. package/es/filter/filter-toolbar.js.map +1 -0
  209. package/es/filter/filter.d.ts +26 -0
  210. package/es/filter/filter.js +125 -0
  211. package/es/filter/filter.js.map +1 -0
  212. package/es/filter/index.d.ts +7 -0
  213. package/es/filter/index.js +14 -0
  214. package/es/filter/index.js.map +1 -0
  215. package/es/filter/styles.d.ts +126 -0
  216. package/es/filter/styles.js +140 -0
  217. package/es/filter/styles.js.map +1 -0
  218. package/es/filter/types.d.ts +55 -0
  219. package/es/filter/types.js +17 -0
  220. package/es/filter/types.js.map +1 -0
  221. package/es/filter/value-filter.d.ts +31 -0
  222. package/es/filter/value-filter.js +275 -0
  223. package/es/filter/value-filter.js.map +1 -0
  224. package/es/focus-highlight.js +1 -1
  225. package/es/focus-highlight.js.map +1 -1
  226. package/es/gantt-export-image.js.map +1 -1
  227. package/es/header-highlight.js.map +1 -1
  228. package/es/highlight-header-when-select-cell.d.ts +1 -2
  229. package/es/highlight-header-when-select-cell.js +1 -1
  230. package/es/highlight-header-when-select-cell.js.map +1 -1
  231. package/es/index.d.ts +4 -0
  232. package/es/index.js +8 -0
  233. package/es/index.js.map +1 -1
  234. package/es/invert-highlight.js.map +1 -1
  235. package/es/paste-add-row-column.d.ts +1 -0
  236. package/es/paste-add-row-column.js +3 -2
  237. package/es/paste-add-row-column.js.map +1 -1
  238. package/es/rotate-table.js +1 -1
  239. package/es/rotate-table.js.map +1 -1
  240. package/es/row-series.js +1 -1
  241. package/es/row-series.js.map +1 -1
  242. package/es/table-carousel-animation.js +3 -3
  243. package/es/table-carousel-animation.js.map +1 -1
  244. package/es/table-export/csv/index.js +1 -1
  245. package/es/table-export/csv/index.js.map +1 -1
  246. package/es/table-export/excel/index.js +1 -2
  247. package/es/table-export/excel/index.js.map +1 -1
  248. package/es/table-export/excel/style.js.map +1 -1
  249. package/es/table-export/index.js.map +1 -1
  250. package/es/table-export/util/color.js.map +1 -1
  251. package/es/table-export/util/download.js.map +1 -1
  252. package/es/table-export/util/encode.js.map +1 -1
  253. package/es/table-export/util/indent.js.map +1 -1
  254. package/es/table-export/util/pagination.js.map +1 -1
  255. package/es/table-export/util/promise.js.map +1 -1
  256. package/es/table-export/util/type.js +1 -1
  257. package/es/table-export/util/type.js.map +1 -1
  258. package/es/table-export.js +1 -2
  259. package/es/table-export.js.map +1 -1
  260. package/es/table-series-number.d.ts +41 -0
  261. package/es/table-series-number.js +253 -0
  262. package/es/table-series-number.js.map +1 -0
  263. package/es/types.d.ts +1 -0
  264. package/es/types.js +2 -1
  265. package/es/types.js.map +1 -1
  266. package/es/wps-fill-handle.js +1 -1
  267. package/es/wps-fill-handle.js.map +1 -1
  268. package/package.json +8 -8
@@ -0,0 +1,244 @@
1
+ "use strict";
2
+
3
+ var __createBinding = this && this.__createBinding || (Object.create ? function(o, m, k, k2) {
4
+ void 0 === k2 && (k2 = k);
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ desc && !("get" in desc ? !m.__esModule : desc.writable || desc.configurable) || (desc = {
7
+ enumerable: !0,
8
+ get: function() {
9
+ return m[k];
10
+ }
11
+ }), Object.defineProperty(o, k2, desc);
12
+ } : function(o, m, k, k2) {
13
+ void 0 === k2 && (k2 = k), o[k2] = m[k];
14
+ }), __setModuleDefault = this && this.__setModuleDefault || (Object.create ? function(o, v) {
15
+ Object.defineProperty(o, "default", {
16
+ enumerable: !0,
17
+ value: v
18
+ });
19
+ } : function(o, v) {
20
+ o.default = v;
21
+ }), __importStar = this && this.__importStar || function(mod) {
22
+ if (mod && mod.__esModule) return mod;
23
+ var result = {};
24
+ if (null != mod) for (var k in mod) "default" !== k && Object.prototype.hasOwnProperty.call(mod, k) && __createBinding(result, mod, k);
25
+ return __setModuleDefault(result, mod), result;
26
+ };
27
+
28
+ Object.defineProperty(exports, "__esModule", {
29
+ value: !0
30
+ }), exports.AutoFillManager = void 0;
31
+
32
+ const types_1 = require("./types"), auto_fill_services_1 = require("./auto-fill-services"), rules_1 = require("./rules"), fill_1 = require("./utils/fill"), VTable = __importStar(require("@visactor/vtable")), auto_fill_helper_1 = require("./auto-fill-helper"), ts_types_1 = require("@visactor/vtable/es/ts-types");
33
+
34
+ class AutoFillManager {
35
+ constructor(options) {
36
+ this.sourceData = [], this.options = options, this.autoFillService = new auto_fill_services_1.AutoFillService;
37
+ }
38
+ setTable(table) {
39
+ this.headers = {
40
+ row: new Set,
41
+ col: new Set
42
+ }, this.tableInstance = table, table.on(VTable.TABLE_EVENT_TYPE.DROPDOWN_MENU_CLICK, (args => {
43
+ "复制填充" === args.text ? this.fillData(types_1.APPLY_TYPE.COPY) : "序列填充" === args.text && this.fillData(types_1.APPLY_TYPE.SERIES);
44
+ }));
45
+ const rowHeaderCells = this.tableInstance.getAllRowHeaderCells()[0];
46
+ rowHeaderCells && rowHeaderCells.forEach((cell => {
47
+ this.headers.col.add(cell.col);
48
+ }));
49
+ const colHeaderCells = this.tableInstance.getAllColumnHeaderCells()[0];
50
+ colHeaderCells && colHeaderCells.forEach((cell => {
51
+ this.headers.row.add(cell.row);
52
+ }));
53
+ }
54
+ handleStartDrag(selectedRange) {
55
+ this.sourceRange = (0, auto_fill_helper_1.getSelectedRangeArray)(selectedRange),
56
+ this.sourceRange.cols = this.sourceRange.cols.filter((col => !this.headers.col.has(col))),
57
+ this.sourceRange.rows = this.sourceRange.rows.filter((row => !this.headers.row.has(row)));
58
+ }
59
+ handleEndDrag(endSelectCellRange, direction) {
60
+ var _a;
61
+ this.direction = direction;
62
+ const selectedRange = (0, auto_fill_helper_1.getSelectedRangeArray)(endSelectCellRange);
63
+ this.targetRange = (0, auto_fill_helper_1.getTargetRange)(this.direction, this.sourceRange, selectedRange),
64
+ this.targetRange.cols = this.targetRange.cols.filter((col => !this.headers.col.has(col))),
65
+ this.targetRange.rows = this.targetRange.rows.filter((row => !this.headers.row.has(row))),
66
+ (null === (_a = this.options) || void 0 === _a ? void 0 : _a.fillMode) ? this.fillData(this.options.fillMode) : (0,
67
+ auto_fill_helper_1.openAutoFillMenu)(this.tableInstance, Math.max(...selectedRange.cols), Math.max(...selectedRange.rows));
68
+ }
69
+ handleDbClick() {
70
+ var _a;
71
+ if (!this.sourceRange) return;
72
+ this.direction = types_1.Direction.DOWN;
73
+ const detectFillRange = (0, auto_fill_helper_1.getSelectedRangeArray)(this._detectFillRange());
74
+ if (this.targetRange = (0, auto_fill_helper_1.getTargetRange)(this.direction, this.sourceRange, detectFillRange),
75
+ this.targetRange.cols = this.targetRange.cols.filter((col => !this.headers.col.has(col))),
76
+ this.targetRange.rows = this.targetRange.rows.filter((row => !this.headers.row.has(row))),
77
+ 0 === this.targetRange.cols.length || 0 === this.targetRange.rows.length) return;
78
+ const startCol = this.sourceRange.cols[0], startRow = this.sourceRange.rows[0], endCol = this.targetRange.cols[this.targetRange.cols.length - 1], endRow = this.targetRange.rows[this.targetRange.rows.length - 1], stateManager = this.tableInstance.stateManager;
79
+ stateManager.updateSelectPos(startCol, startRow, !1, !1, !1, !0, !0), stateManager.updateInteractionState(ts_types_1.InteractionState.grabing),
80
+ stateManager.updateSelectPos(endCol, endRow, !1, !1, !1, !0, !0), stateManager.endSelectCells(!1, !1),
81
+ stateManager.updateInteractionState(ts_types_1.InteractionState.default), (null === (_a = this.options) || void 0 === _a ? void 0 : _a.fastFillMode) ? this.fillData(this.options.fastFillMode) : (0,
82
+ auto_fill_helper_1.openAutoFillMenu)(this.tableInstance, endCol, endRow);
83
+ }
84
+ fillData(applyType) {
85
+ this.sourceData = this.getSourceData(this.sourceRange, this.direction);
86
+ const location = {
87
+ source: this.sourceRange,
88
+ target: this.targetRange
89
+ };
90
+ this._fillData(location, this.direction, applyType);
91
+ }
92
+ getSourceData(source, direction) {
93
+ const rules = this.autoFillService.getRules(), sourceData = [], isVertical = direction === types_1.Direction.DOWN || direction === types_1.Direction.UP;
94
+ let aArray, bArray;
95
+ isVertical ? (aArray = source.cols, bArray = source.rows) : (aArray = source.rows,
96
+ bArray = source.cols);
97
+ const matrix = (0, auto_fill_helper_1.getCellMatrix)(this.tableInstance);
98
+ return aArray.forEach((a => {
99
+ const sourceDataPiece = this.getEmptySourceDataPiece(), prevData = {
100
+ type: void 0,
101
+ cellData: void 0
102
+ };
103
+ bArray.forEach((b => {
104
+ let data;
105
+ data = isVertical ? matrix.getValue(b, a) : matrix.getValue(a, b);
106
+ const {type: type, isContinue: isContinue} = rules.find((r => r.match(data, null))) || rules_1.otherRule;
107
+ if (isContinue(prevData, data)) {
108
+ const typeInfo = sourceDataPiece[type], last = typeInfo[typeInfo.length - 1];
109
+ last.data.push(data), last.index.push(b - bArray[0]);
110
+ } else {
111
+ const typeInfo = sourceDataPiece[type];
112
+ typeInfo ? typeInfo.push({
113
+ data: [ data ],
114
+ index: [ b - bArray[0] ]
115
+ }) : sourceDataPiece[type] = [ {
116
+ data: [ data ],
117
+ index: [ b - bArray[0] ]
118
+ } ];
119
+ }
120
+ prevData.type = type, prevData.cellData = data;
121
+ })), sourceData.push(sourceDataPiece);
122
+ })), sourceData;
123
+ }
124
+ getEmptySourceDataPiece() {
125
+ const sourceDataPiece = {};
126
+ return this.autoFillService.getRules().forEach((r => {
127
+ sourceDataPiece[r.type] = [];
128
+ })), sourceDataPiece;
129
+ }
130
+ _detectFillRange() {
131
+ var _a, _b, _c, _d, _e;
132
+ const start = {
133
+ row: Math.min(...this.sourceRange.rows),
134
+ col: Math.min(...this.sourceRange.cols)
135
+ }, end = {
136
+ row: Math.max(...this.sourceRange.rows),
137
+ col: Math.max(...this.sourceRange.cols)
138
+ }, matrix = (0, auto_fill_helper_1.getCellMatrix)(this.tableInstance), maxRow = matrix.getMaxRows(), maxColumn = matrix.getMaxColumns();
139
+ let detectEndRow = end.row;
140
+ if (start.col > 0 && (null === (_a = matrix.getValue(start.row, start.col - 1)) || void 0 === _a ? void 0 : _a.v)) {
141
+ let cur = start.row;
142
+ for (;(null === (_b = matrix.getValue(cur, start.col - 1)) || void 0 === _b ? void 0 : _b.v) && cur <= maxRow; ) cur += 1;
143
+ detectEndRow = cur - 1;
144
+ } else if (end.col < maxColumn && (null === (_c = matrix.getValue(end.row, end.col + 1)) || void 0 === _c ? void 0 : _c.v)) {
145
+ let cur = start.row;
146
+ for (;(null === (_d = matrix.getValue(cur, end.col + 1)) || void 0 === _d ? void 0 : _d.v) && cur <= maxRow; ) cur += 1;
147
+ detectEndRow = cur - 1;
148
+ }
149
+ for (let i = end.row + 1; i <= detectEndRow; i++) for (let j = start.col; j <= end.col; j++) if (null === (_e = matrix.getValue(i, j)) || void 0 === _e ? void 0 : _e.v) {
150
+ detectEndRow = i - 1;
151
+ break;
152
+ }
153
+ return {
154
+ start: {
155
+ row: start.row,
156
+ col: start.col
157
+ },
158
+ end: {
159
+ row: detectEndRow,
160
+ col: end.col
161
+ }
162
+ };
163
+ }
164
+ _fillData(location, direction, applyType) {
165
+ const {source: source, target: target} = location;
166
+ if (!source || !target || null == direction) return;
167
+ const {cols: targetCols, rows: targetRows} = target, {cols: sourceCols, rows: sourceRows} = source, sourceData = this.sourceData;
168
+ let csLen;
169
+ csLen = direction === types_1.Direction.DOWN || direction === types_1.Direction.UP ? sourceRows.length : sourceCols.length;
170
+ const applyDatas = [];
171
+ if (direction === types_1.Direction.DOWN || direction === types_1.Direction.UP) {
172
+ const asLen = targetRows.length, untransformedApplyDatas = [];
173
+ targetCols.forEach(((_, i) => {
174
+ const copyD = sourceData[i], applyData = this.getApplyData(copyD, csLen, asLen, direction, applyType, location);
175
+ untransformedApplyDatas.push(applyData);
176
+ }));
177
+ for (let i = 0; i < untransformedApplyDatas[0].length; i++) {
178
+ const row = [];
179
+ for (let j = 0; j < untransformedApplyDatas.length; j++) row.push(Object.assign({
180
+ s: null
181
+ }, untransformedApplyDatas[j][i]));
182
+ applyDatas.push(row);
183
+ }
184
+ } else {
185
+ const asLen = targetCols.length;
186
+ targetRows.forEach(((_, i) => {
187
+ const copyD = sourceData[i], applyData = this.getApplyData(copyD, csLen, asLen, direction, applyType, location), row = [];
188
+ for (let j = 0; j < applyData.length; j++) row.push(Object.assign({
189
+ s: null
190
+ }, applyData[j]));
191
+ applyDatas.push(row);
192
+ }));
193
+ }
194
+ const values = [];
195
+ targetRows.forEach(((row, rowIndex) => {
196
+ const rowValues = [];
197
+ targetCols.forEach(((col, colIndex) => {
198
+ const range = (0, auto_fill_helper_1.isMergeCell)(this.tableInstance, col, row);
199
+ range && this.tableInstance.unmergeCells(range.start.col, range.start.row, range.end.col, range.end.row),
200
+ applyDatas[rowIndex][colIndex] && rowValues.push(applyDatas[rowIndex][colIndex].v + "");
201
+ })), values.push(rowValues);
202
+ }));
203
+ const minRow = Math.min(...targetRows), minCol = Math.min(...targetCols);
204
+ this.tableInstance.changeCellValues(minCol, minRow, values);
205
+ }
206
+ getApplyData(sourceDataPiece, csLen, asLen, direction, applyType, location) {
207
+ const applyData = [], num = Math.floor(asLen / csLen), rsd = asLen % csLen, rules = this.autoFillService.getRules(), applyDataInTypes = {};
208
+ rules.forEach((r => {
209
+ applyDataInTypes[r.type] = [];
210
+ })), rules.forEach((r => {
211
+ const {type: type, applyFunctions: customApplyFunctions = {}} = r, copyDataInType = sourceDataPiece[type];
212
+ copyDataInType && copyDataInType.forEach((copySquad => {
213
+ const s = (0, fill_1.getLenS)(copySquad.index, rsd), len = copySquad.index.length * num + s, arrData = this.applyFunctions(copySquad, len, direction, applyType, customApplyFunctions, sourceDataPiece, location), arrIndex = (0,
214
+ fill_1.getDataIndex)(csLen, asLen, copySquad.index);
215
+ applyDataInTypes[type].push({
216
+ data: arrData,
217
+ index: arrIndex
218
+ });
219
+ }));
220
+ }));
221
+ for (let x = 0; x < asLen; x++) rules.forEach((r => {
222
+ const {type: type} = r, applyDataInType = applyDataInTypes[type];
223
+ for (let y = 0; y < applyDataInType.length; y++) x in applyDataInType[y].index && applyData.push(applyDataInType[y].data[applyDataInType[y].index[x]]);
224
+ }));
225
+ return applyData;
226
+ }
227
+ applyFunctions(copySquad, len, direction, applyType, customApplyFunctions, sourceDataPiece, location) {
228
+ const {data: data} = copySquad, isReverse = direction === types_1.Direction.UP || direction === types_1.Direction.LEFT;
229
+ if (applyType === types_1.APPLY_TYPE.COPY) {
230
+ const custom = null == customApplyFunctions ? void 0 : customApplyFunctions[types_1.APPLY_TYPE.COPY];
231
+ return custom ? custom(copySquad, len, direction, sourceDataPiece, location) : (isReverse && data.reverse(),
232
+ (0, fill_1.fillCopy)(data, len));
233
+ }
234
+ if (applyType === types_1.APPLY_TYPE.SERIES) {
235
+ const custom = null == customApplyFunctions ? void 0 : customApplyFunctions[types_1.APPLY_TYPE.SERIES];
236
+ return custom ? custom(copySquad, len, direction, sourceDataPiece) : (isReverse && data.reverse(),
237
+ (null == customApplyFunctions ? void 0 : customApplyFunctions[types_1.APPLY_TYPE.COPY]) ? customApplyFunctions[types_1.APPLY_TYPE.COPY](copySquad, len, direction, sourceDataPiece, location) : (0,
238
+ fill_1.fillCopy)(data, len));
239
+ }
240
+ }
241
+ }
242
+
243
+ exports.AutoFillManager = AutoFillManager;
244
+ //# sourceMappingURL=auto-fill-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/auto-fill/auto-fill-manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAeA,mCAA+D;AAS/D,6DAAuD;AACvD,mCAAoC;AACp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,SAAS,EAAE,eAAe,CAAC,CAAC;aAC3D;YACD,SAAS,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YAE5B,IAAI,oBAAoB,aAApB,oBAAoB,uBAApB,oBAAoB,CAAG,kBAAU,CAAC,IAAI,CAAC,EAAE;gBAC3C,OAAO,oBAAoB,CAAC,kBAAU,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,eAAe,EAAE,QAAQ,CAAC,CAAC;aACpG;YACD,OAAO,IAAA,eAAQ,EAAC,IAAI,EAAE,GAAG,CAAC,CAAC;SAC5B;IACH,CAAC;CACF;AA/bD,0CA+bC","file":"auto-fill-manager.js","sourcesContent":["/**\n * Copyright 2023-present DreamNum Co., Ltd.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { Direction, APPLY_TYPE, CellValueType } from './types';\nimport type {\n ISourceDataPiece,\n ICellData,\n Nullable,\n IRuleConfirmedData,\n IDiscreteRange,\n IAutoFillLocation\n} from './types';\nimport { AutoFillService } from './auto-fill-services';\nimport { otherRule } from './rules';\nimport { fillCopy, getDataIndex, getLenS } from './utils/fill';\nimport type { ICopyDataInType } from './utils/fill';\nimport type { APPLY_FUNCTIONS } from './types';\nimport type { CellRange } from '@visactor/vtable/es/ts-types/table-engine';\nimport type { ListTable } from '@visactor/vtable';\nimport * as VTable from '@visactor/vtable';\nimport {\n getSelectedRangeArray,\n getTargetRange,\n openAutoFillMenu,\n getCellMatrix,\n isMergeCell\n} from './auto-fill-helper';\nimport type { IAutoFillPluginOptions } from '.';\nimport { InteractionState } from '@visactor/vtable/es/ts-types';\nexport class AutoFillManager {\n // 源数据\n private sourceData: ISourceDataPiece[] = [];\n // autoFillService 维护规则列表\n private autoFillService: AutoFillService;\n // 表格实例\n private tableInstance: ListTable;\n // 源范围\n private sourceRange: IDiscreteRange;\n // 目标范围\n private targetRange: IDiscreteRange;\n // 填充方向\n private direction: Direction;\n // 行列头\n private headers: {\n row: Set<number>;\n col: Set<number>;\n };\n\n private options?: IAutoFillPluginOptions;\n\n constructor(options?: IAutoFillPluginOptions) {\n this.options = options;\n this.autoFillService = new AutoFillService();\n }\n\n setTable(table: ListTable) {\n this.headers = {\n row: new Set(),\n col: new Set()\n };\n this.tableInstance = table;\n table.on(VTable.TABLE_EVENT_TYPE.DROPDOWN_MENU_CLICK, (args: any) => {\n if (args.text === '复制填充') {\n this.fillData(APPLY_TYPE.COPY);\n } else if (args.text === '序列填充') {\n this.fillData(APPLY_TYPE.SERIES);\n }\n });\n\n //cal headers\n const rowHeaderCells = this.tableInstance.getAllRowHeaderCells()[0];\n if (rowHeaderCells) {\n rowHeaderCells.forEach(cell => {\n this.headers.col.add(cell.col);\n });\n }\n const colHeaderCells = this.tableInstance.getAllColumnHeaderCells()[0];\n if (colHeaderCells) {\n colHeaderCells.forEach(cell => {\n this.headers.row.add(cell.row);\n });\n }\n }\n\n // 开始拖拽\n handleStartDrag(selectedRange: CellRange) {\n this.sourceRange = getSelectedRangeArray(selectedRange);\n this.sourceRange.cols = this.sourceRange.cols.filter(col => !this.headers.col.has(col));\n this.sourceRange.rows = this.sourceRange.rows.filter(row => !this.headers.row.has(row));\n }\n // 结束拖拽\n handleEndDrag(endSelectCellRange: CellRange, direction: string) {\n // set direction\n this.direction = direction as Direction;\n // set target range\n const selectedRange = getSelectedRangeArray(endSelectCellRange);\n this.targetRange = getTargetRange(this.direction, this.sourceRange, selectedRange);\n this.targetRange.cols = this.targetRange.cols.filter(col => !this.headers.col.has(col));\n this.targetRange.rows = this.targetRange.rows.filter(row => !this.headers.row.has(row));\n // open auto fill menu\n if (!this.options?.fillMode) {\n openAutoFillMenu(this.tableInstance, Math.max(...selectedRange.cols), Math.max(...selectedRange.rows));\n } else {\n this.fillData(this.options.fillMode as APPLY_TYPE);\n }\n }\n\n handleDbClick() {\n if (!this.sourceRange) {\n return;\n }\n this.direction = Direction.DOWN;\n // 双击填充时,自动检测填充范围\n const detectFillRange = getSelectedRangeArray(this._detectFillRange());\n this.targetRange = getTargetRange(this.direction, this.sourceRange, detectFillRange);\n this.targetRange.cols = this.targetRange.cols.filter(col => !this.headers.col.has(col));\n this.targetRange.rows = this.targetRange.rows.filter(row => !this.headers.row.has(row));\n if (this.targetRange.cols.length === 0 || this.targetRange.rows.length === 0) {\n return;\n }\n const startCol = this.sourceRange.cols[0];\n const startRow = this.sourceRange.rows[0];\n const endCol = this.targetRange.cols[this.targetRange.cols.length - 1];\n const endRow = this.targetRange.rows[this.targetRange.rows.length - 1];\n // 更新选区\n const stateManager = this.tableInstance.stateManager;\n stateManager.updateSelectPos(startCol, startRow, false, false, false, true, true);\n stateManager.updateInteractionState(InteractionState.grabing);\n stateManager.updateSelectPos(endCol, endRow, false, false, false, true, true);\n stateManager.endSelectCells(false, false);\n stateManager.updateInteractionState(InteractionState.default);\n // 快速填充\n if (!this.options?.fastFillMode) {\n // 打开自动填充菜单\n openAutoFillMenu(this.tableInstance, endCol, endRow);\n } else {\n this.fillData(this.options.fastFillMode as APPLY_TYPE);\n }\n }\n\n /**\n * 填充数据\n * @param applyType - 填充类型\n */\n fillData(applyType: APPLY_TYPE) {\n console.log('fill data applyType', applyType);\n // 获取源数据\n this.sourceData = this.getSourceData(this.sourceRange, this.direction);\n const location = {\n source: this.sourceRange,\n target: this.targetRange\n };\n\n // 填充数据\n this._fillData(location, this.direction, applyType);\n }\n /**\n * 获取源数据\n * @param source - 源范围\n * @param direction - 方向\n * @returns 源数据\n */\n private getSourceData(source: IDiscreteRange, direction: Direction) {\n const rules = this.autoFillService.getRules();\n const sourceData: ISourceDataPiece[] = [];\n const isVertical = direction === Direction.DOWN || direction === Direction.UP;\n let aArray: number[];\n let bArray: number[];\n if (isVertical) {\n aArray = source.cols;\n bArray = source.rows;\n } else {\n aArray = source.rows;\n bArray = source.cols;\n }\n const matrix = getCellMatrix(this.tableInstance);\n // 按照行或列将源数据分成多个片段,获取单元格数据\n aArray.forEach(a => {\n const sourceDataPiece = this.getEmptySourceDataPiece();\n const prevData: IRuleConfirmedData = {\n type: undefined,\n cellData: undefined\n };\n bArray.forEach(b => {\n let data: Nullable<ICellData>;\n if (isVertical) {\n data = matrix.getValue(b, a);\n } else {\n data = matrix.getValue(a, b);\n }\n // find rules to match data\n const { type, isContinue } = rules.find(r => r.match(data, null)) || otherRule;\n if (isContinue(prevData, data)) {\n const typeInfo = sourceDataPiece[type];\n\n const last = typeInfo![typeInfo!.length - 1];\n last.data.push(data);\n last.index.push(b - bArray[0]);\n } else {\n const typeInfo = sourceDataPiece[type];\n if (typeInfo) {\n typeInfo.push({\n data: [data],\n index: [b - bArray[0]]\n });\n } else {\n sourceDataPiece[type] = [\n {\n data: [data],\n index: [b - bArray[0]]\n }\n ];\n }\n }\n prevData.type = type;\n prevData.cellData = data;\n });\n sourceData.push(sourceDataPiece);\n });\n return sourceData;\n }\n /**\n * 获取空的片段数据对象\n * @returns 空的片段数据对象\n */\n private getEmptySourceDataPiece() {\n const sourceDataPiece: ISourceDataPiece = {};\n this.autoFillService.getRules().forEach(r => {\n sourceDataPiece[r.type] = [];\n });\n\n return sourceDataPiece;\n }\n /**\n * 快速填充检测填充范围\n * @returns 填充范围\n */\n private _detectFillRange() {\n // sourceRange\n const start = { row: Math.min(...this.sourceRange.rows), col: Math.min(...this.sourceRange.cols) };\n const end = { row: Math.max(...this.sourceRange.rows), col: Math.max(...this.sourceRange.cols) };\n // matrix\n const matrix = getCellMatrix(this.tableInstance);\n const maxRow = matrix.getMaxRows();\n const maxColumn = matrix.getMaxColumns();\n let detectEndRow = end.row;\n // left column first, or consider right column.\n if (start.col > 0 && matrix.getValue(start.row, start.col - 1)?.v) {\n let cur = start.row;\n while (matrix.getValue(cur, start.col - 1)?.v && cur <= maxRow) {\n cur += 1;\n }\n detectEndRow = cur - 1;\n } else if (end.col < maxColumn && matrix.getValue(end.row, end.col + 1)?.v) {\n let cur = start.row;\n while (matrix.getValue(cur, end.col + 1)?.v && cur <= maxRow) {\n cur += 1;\n }\n detectEndRow = cur - 1;\n }\n for (let i = end.row + 1; i <= detectEndRow; i++) {\n for (let j = start.col; j <= end.col; j++) {\n if (matrix.getValue(i, j)?.v) {\n detectEndRow = i - 1;\n break;\n }\n }\n }\n return {\n start: { row: start.row, col: start.col },\n end: { row: detectEndRow, col: end.col }\n };\n }\n\n /**\n * 填充数据\n * @param location - 位置\n * @param direction - 方向\n * @param applyType - 填充类型\n */\n private _fillData(location: IAutoFillLocation, direction: Direction, applyType: APPLY_TYPE) {\n const { source, target } = location;\n if (!source || !target || direction == null) {\n return;\n }\n\n const { cols: targetCols, rows: targetRows } = target;\n const { cols: sourceCols, rows: sourceRows } = source;\n\n const sourceData = this.sourceData;\n\n let csLen;\n if (direction === Direction.DOWN || direction === Direction.UP) {\n csLen = sourceRows.length;\n } else {\n csLen = sourceCols.length;\n }\n\n const applyDatas: Array<Array<Nullable<ICellData>>> = [];\n\n if (direction === Direction.DOWN || direction === Direction.UP) {\n const asLen = targetRows.length;\n const untransformedApplyDatas: Nullable<ICellData>[][] = [];\n targetCols.forEach((_, i) => {\n const copyD = sourceData[i];\n const applyData = this.getApplyData(copyD, csLen, asLen, direction, applyType, location);\n untransformedApplyDatas.push(applyData);\n });\n for (let i = 0; i < untransformedApplyDatas[0].length; i++) {\n const row: Array<Nullable<ICellData>> = [];\n for (let j = 0; j < untransformedApplyDatas.length; j++) {\n row.push({\n s: null,\n ...untransformedApplyDatas[j][i]\n });\n }\n applyDatas.push(row);\n }\n } else {\n const asLen = targetCols.length;\n targetRows.forEach((_, i) => {\n const copyD = sourceData[i];\n const applyData = this.getApplyData(copyD, csLen, asLen, direction, applyType, location);\n const row: Array<Nullable<ICellData>> = [];\n for (let j = 0; j < applyData.length; j++) {\n row.push({\n s: null,\n ...applyData[j]\n });\n }\n applyDatas.push(row);\n });\n }\n\n // 获取填充的值\n const values: string[][] = [];\n targetRows.forEach((row, rowIndex) => {\n const rowValues: string[] = [];\n targetCols.forEach((col, colIndex) => {\n // 如果当前单元格是合并单元格,则先进行拆开单元格,再进行填充\n const range = isMergeCell(this.tableInstance, col, row);\n if (range) {\n this.tableInstance.unmergeCells(range.start.col, range.start.row, range.end.col, range.end.row);\n }\n // 填充数据存入rowValues,再一次性填充到表格中\n if (applyDatas[rowIndex][colIndex]) {\n rowValues.push(applyDatas[rowIndex][colIndex]!.v + '');\n }\n });\n values.push(rowValues);\n });\n // 获取填充开始的行和列,设置表格值\n const minRow = Math.min(...targetRows);\n const minCol = Math.min(...targetCols);\n this.tableInstance.changeCellValues(minCol, minRow, values);\n }\n\n /**\n * 根据源数据计算填充数据\n * @param sourceDataPiece - 源数据片段\n * @param csLen - 源长度\n * @param asLen - 目标长度\n * @param direction - 方向\n * @param applyType - 填充类型\n * @param location - 位置\n * @returns 填充数据\n */\n private getApplyData(\n sourceDataPiece: ISourceDataPiece,\n csLen: number,\n asLen: number,\n direction: Direction,\n applyType: APPLY_TYPE,\n location: IAutoFillLocation\n ) {\n const applyData: Array<Nullable<ICellData>> = [];\n const num = Math.floor(asLen / csLen);\n const rsd = asLen % csLen;\n const rules = this.autoFillService.getRules();\n\n const applyDataInTypes: { [key: string]: any[] } = {};\n\n rules.forEach(r => {\n applyDataInTypes[r.type] = [];\n });\n\n // calc cell data to apply\n rules.forEach(r => {\n const { type, applyFunctions: customApplyFunctions = {} } = r;\n const copyDataInType = sourceDataPiece[type];\n if (!copyDataInType) {\n return;\n }\n // copyDataInType is an array of copy-squads in same types\n // a copy-squad is an array of continuous cells that has the same type, e.g. [1, 3, 5] is a copy squad, but [1, 3, ab, 5] will be divided into two copy-squads\n copyDataInType.forEach(copySquad => {\n const s = getLenS(copySquad.index, rsd);\n const len = copySquad.index.length * num + s;\n\n // We do not process cell.custom by default. If the user needs to process it, they can do so in the hook extension.\n const arrData = this.applyFunctions(\n copySquad,\n len,\n direction,\n applyType,\n customApplyFunctions,\n sourceDataPiece,\n location\n );\n\n const arrIndex = getDataIndex(csLen, asLen, copySquad.index);\n applyDataInTypes[type].push({ data: arrData, index: arrIndex });\n });\n });\n\n // calc index\n for (let x = 0; x < asLen; x++) {\n rules.forEach(r => {\n const { type } = r;\n const applyDataInType = applyDataInTypes[type];\n for (let y = 0; y < applyDataInType.length; y++) {\n if (x in applyDataInType[y].index) {\n applyData.push(applyDataInType[y].data[applyDataInType[y].index[x]]);\n }\n }\n });\n }\n\n return applyData;\n }\n /**\n * 根据规则计算填充函数\n * @param copySquad - 复制数据\n * @param len - 长度\n * @param direction - 方向\n * @param applyType - 填充类型\n * @param customApplyFunctions - 自定义应用函数\n * @param sourceDataPiece - 源数据片段\n * @param location - 位置\n * @returns 填充数据\n */\n private applyFunctions(\n copySquad: ICopyDataInType,\n len: number,\n direction: Direction,\n applyType: APPLY_TYPE,\n customApplyFunctions: APPLY_FUNCTIONS,\n sourceDataPiece: ISourceDataPiece,\n location: IAutoFillLocation\n ) {\n const { data } = copySquad;\n const isReverse = direction === Direction.UP || direction === Direction.LEFT;\n\n // 复制填充\n if (applyType === APPLY_TYPE.COPY) {\n const custom = customApplyFunctions?.[APPLY_TYPE.COPY];\n if (custom) {\n return custom(copySquad, len, direction, sourceDataPiece, location);\n }\n isReverse && data.reverse();\n return fillCopy(data, len);\n }\n // 序列填充\n if (applyType === APPLY_TYPE.SERIES) {\n const custom = customApplyFunctions?.[APPLY_TYPE.SERIES];\n if (custom) {\n return custom(copySquad, len, direction, sourceDataPiece);\n }\n isReverse && data.reverse();\n // special rules, if not provide custom SERIES apply functions, will be applied as copy\n if (customApplyFunctions?.[APPLY_TYPE.COPY]) {\n return customApplyFunctions[APPLY_TYPE.COPY](copySquad, len, direction, sourceDataPiece, location);\n }\n return fillCopy(data, len);\n }\n }\n}\n"]}
@@ -0,0 +1,12 @@
1
+ import type { IAutoFillRule } from './types';
2
+ export interface IAutoFillService {
3
+ getRules: () => IAutoFillRule[];
4
+ registerRule: (rule: IAutoFillRule) => void;
5
+ }
6
+ export declare class AutoFillService implements IAutoFillService {
7
+ private _rules;
8
+ constructor();
9
+ private _init;
10
+ registerRule(rule: IAutoFillRule): void;
11
+ getRules(): IAutoFillRule[];
12
+ }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: !0
5
+ }), exports.AutoFillService = void 0;
6
+
7
+ const rules_1 = require("./rules");
8
+
9
+ class AutoFillService {
10
+ constructor() {
11
+ this._rules = [], this._init();
12
+ }
13
+ _init() {
14
+ this._rules = [ rules_1.dateRule, rules_1.numberRule, rules_1.extendNumberRule, rules_1.chnNumberRule, rules_1.chnWeek2Rule, rules_1.chnWeek3Rule, rules_1.loopSeriesRule, rules_1.otherRule ].sort(((a, b) => b.priority - a.priority));
15
+ }
16
+ registerRule(rule) {
17
+ if (this._rules.find((r => r.type === rule.type))) throw new Error(`Registry rule failed, type '${rule.type}' already exist!`);
18
+ const index = this._rules.findIndex((r => r.priority < rule.priority));
19
+ this._rules.splice(-1 === index ? this._rules.length : index, 0, rule);
20
+ }
21
+ getRules() {
22
+ return this._rules;
23
+ }
24
+ }
25
+
26
+ exports.AutoFillService = AutoFillService;
27
+ //# sourceMappingURL=auto-fill-services.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/auto-fill/auto-fill-services.ts"],"names":[],"mappings":";;;AAgBA,mCASiB;AAOjB,MAAa,eAAe;IAG1B;QAFQ,WAAM,GAAoB,EAAE,CAAC;QAGnC,IAAI,CAAC,KAAK,EAAE,CAAC;IACf,CAAC;IAEO,KAAK;QACX,IAAI,CAAC,MAAM,GAAG;YACZ,gBAAQ;YACR,kBAAU;YACV,wBAAgB;YAChB,qBAAa;YACb,oBAAY;YACZ,oBAAY;YACZ,sBAAc;YACd,iBAAS;SACV,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC;IAC5C,CAAC;IAED,YAAY,CAAC,IAAmB;QAE9B,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,CAAC,EAAE;YAC/C,MAAM,IAAI,KAAK,CAAC,+BAA+B,IAAI,CAAC,IAAI,kBAAkB,CAAC,CAAC;SAC7E;QAED,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC;QACrE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;IACzE,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF;AAjCD,0CAiCC","file":"auto-fill-services.js","sourcesContent":["/**\n * Copyright 2023-present DreamNum Co., Ltd.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport type { IAutoFillRule } from './types';\nimport {\n dateRule,\n numberRule,\n extendNumberRule,\n chnNumberRule,\n chnWeek2Rule,\n chnWeek3Rule,\n loopSeriesRule,\n otherRule\n} from './rules';\n\nexport interface IAutoFillService {\n getRules: () => IAutoFillRule[];\n registerRule: (rule: IAutoFillRule) => void;\n}\n\nexport class AutoFillService implements IAutoFillService {\n private _rules: IAutoFillRule[] = [];\n\n constructor() {\n this._init();\n }\n\n private _init() {\n this._rules = [\n dateRule,\n numberRule,\n extendNumberRule,\n chnNumberRule,\n chnWeek2Rule,\n chnWeek3Rule,\n loopSeriesRule,\n otherRule\n ].sort((a, b) => b.priority - a.priority);\n }\n\n registerRule(rule: IAutoFillRule) {\n // if rule.type is used, console error\n if (this._rules.find(r => r.type === rule.type)) {\n throw new Error(`Registry rule failed, type '${rule.type}' already exist!`);\n }\n // insert rules according to the rule.priority, the higher priority will be inserted at the beginning of the array\n const index = this._rules.findIndex(r => r.priority < rule.priority);\n this._rules.splice(index === -1 ? this._rules.length : index, 0, rule);\n }\n\n getRules() {\n return this._rules;\n }\n}\n"]}
@@ -0,0 +1,5 @@
1
+ export declare function isValid(date: Date): boolean;
2
+ export declare function differenceInDays(dateLeft: Date, dateRight: Date): number;
3
+ export declare function addDays(date: Date, amount: number): Date;
4
+ export declare function parse(dateString: string, format: string, referenceDate?: Date): Date;
5
+ export declare function format(date: Date, format: string): string;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ function isValid(date) {
4
+ return date instanceof Date && !isNaN(date.getTime());
5
+ }
6
+
7
+ function differenceInDays(dateLeft, dateRight) {
8
+ if (!isValid(dateLeft) || !isValid(dateRight)) throw new Error("Invalid date passed to differenceInDays");
9
+ const leftTime = Date.UTC(dateLeft.getFullYear(), dateLeft.getMonth(), dateLeft.getDate()), rightTime = Date.UTC(dateRight.getFullYear(), dateRight.getMonth(), dateRight.getDate());
10
+ return Math.floor((rightTime - leftTime) / 864e5);
11
+ }
12
+
13
+ function addDays(date, amount) {
14
+ if (!isValid(date)) throw new Error("Invalid date passed to addDays");
15
+ const newDate = new Date(date);
16
+ return newDate.setDate(newDate.getDate() + amount), newDate;
17
+ }
18
+
19
+ function parse(dateString, format, referenceDate = new Date) {
20
+ const yearMatch = format.match(/y+/), monthMatch = format.match(/M+/), dayMatch = format.match(/d+/);
21
+ if (!yearMatch || !monthMatch || !dayMatch) throw new Error("Format string must contain yyyy, MM (or M), and dd (or d)");
22
+ const yearIndex = format.indexOf(yearMatch[0]), monthIndex = format.indexOf(monthMatch[0]), dayIndex = format.indexOf(dayMatch[0]), year = parseInt(dateString.substring(yearIndex, yearIndex + yearMatch[0].length), 10), month = parseInt(dateString.substring(monthIndex, monthIndex + monthMatch[0].length), 10) - 1, day = parseInt(dateString.substring(dayIndex, dayIndex + dayMatch[0].length), 10), fullYear = year < 100 ? 2e3 + year : year, date = new Date(fullYear, month, day);
23
+ return date.getFullYear() !== fullYear || date.getMonth() !== month || date.getDate() !== day ? new Date(NaN) : date;
24
+ }
25
+
26
+ function format(date, format) {
27
+ if (!isValid(date)) throw new Error("Invalid date passed to format");
28
+ const year = date.getFullYear(), month = date.getMonth() + 1, day = date.getDate();
29
+ return format.replace("yyyy", year.toString()).replace("MM", month.toString().padStart(2, "0")).replace("M", month.toString()).replace("dd", day.toString().padStart(2, "0")).replace("d", day.toString());
30
+ }
31
+
32
+ Object.defineProperty(exports, "__esModule", {
33
+ value: !0
34
+ }), exports.format = exports.parse = exports.addDays = exports.differenceInDays = exports.isValid = void 0,
35
+ exports.isValid = isValid, exports.differenceInDays = differenceInDays, exports.addDays = addDays,
36
+ exports.parse = parse, exports.format = format;
37
+ //# sourceMappingURL=date-tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/auto-fill/date-tools.ts"],"names":[],"mappings":";;;AAOA,SAAgB,OAAO,CAAC,IAAU;IAChC,OAAO,IAAI,YAAY,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;AACxD,CAAC;AAFD,0BAEC;AAQD,SAAgB,gBAAgB,CAAC,QAAc,EAAE,SAAe;IAC9D,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC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AE,MAAc;IAC/C,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QAClB,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;KAClD;IAED,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;IAChC,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;IAClC,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;IAG3B,OAAO,MAAM;SACV,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC;SAChC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;SAChD,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC;SAC9B,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;SAC9C,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;AAClC,CAAC;AAhBD,wBAgBC","file":"date-tools.js","sourcesContent":["import { TimeUtil } from '@visactor/vutils';\n\n/**\n * 检查日期是否有效\n * @param date 待检查的日期\n * @returns 是否有效\n */\nexport function isValid(date: Date): boolean {\n return date instanceof Date && !isNaN(date.getTime());\n}\n\n/**\n * 计算两个日期之间的天数差\n * @param dateLeft 较早的日期\n * @param dateRight 较晚的日期\n * @returns 天数差(dateRight - dateLeft)\n */\nexport function differenceInDays(dateLeft: Date, dateRight: Date): number {\n if (!isValid(dateLeft) || !isValid(dateRight)) {\n throw new Error('Invalid date passed to differenceInDays');\n }\n\n // 转换为UTC时间戳(忽略时分秒影响)\n const leftTime = Date.UTC(dateLeft.getFullYear(), dateLeft.getMonth(), dateLeft.getDate());\n\n const rightTime = Date.UTC(dateRight.getFullYear(), dateRight.getMonth(), dateRight.getDate());\n\n // 一天的毫秒数:86400000 = 24 * 60 * 60 * 1000\n return Math.floor((rightTime - leftTime) / 86400000);\n}\n\n/**\n * 给日期增加指定天数\n * @param date 基础日期\n * @param amount 要增加的天数\n * @returns 新的日期对象\n */\nexport function addDays(date: Date, amount: number): Date {\n if (!isValid(date)) {\n throw new Error('Invalid date passed to addDays');\n }\n\n const newDate = new Date(date);\n newDate.setDate(newDate.getDate() + amount);\n return newDate;\n}\n\n/**\n * 解析日期字符串为Date对象\n * @param dateString 日期字符串\n * @param format 格式字符串(支持yyyy、MM、dd、M、d)\n * @param referenceDate 参考日期(用于补全缺失信息)\n * @returns 解析后的Date对象\n */\nexport function parse(dateString: string, format: string, referenceDate: Date = new Date()): Date {\n // 提取格式中的日期部分\n const yearMatch = format.match(/y+/);\n const monthMatch = format.match(/M+/);\n const dayMatch = format.match(/d+/);\n\n if (!yearMatch || !monthMatch || !dayMatch) {\n throw new Error('Format string must contain yyyy, MM (or M), and dd (or d)');\n }\n\n // 提取日期字符串中的对应部分\n const yearIndex = format.indexOf(yearMatch[0]);\n const monthIndex = format.indexOf(monthMatch[0]);\n const dayIndex = format.indexOf(dayMatch[0]);\n\n const year = parseInt(dateString.substring(yearIndex, yearIndex + yearMatch[0].length), 10);\n const month = parseInt(dateString.substring(monthIndex, monthIndex + monthMatch[0].length), 10) - 1; // 月份从0开始\n const day = parseInt(dateString.substring(dayIndex, dayIndex + dayMatch[0].length), 10);\n\n // 处理可能的年份简写(如\"24\"解析为2024)\n const fullYear = year < 100 ? 2000 + year : year;\n\n const date = new Date(fullYear, month, day);\n\n // 验证解析结果是否正确(处理无效日期如2月30日)\n if (date.getFullYear() !== fullYear || date.getMonth() !== month || date.getDate() !== day) {\n return new Date(NaN); // 返回无效日期\n }\n\n return date;\n}\n\n/**\n * 格式化日期为指定字符串\n * @param date 日期对象\n * @param format 格式字符串(支持yyyy、MM、dd、M、d)\n * @returns 格式化后的字符串\n */\nexport function format(date: Date, format: string): string {\n if (!isValid(date)) {\n throw new Error('Invalid date passed to format');\n }\n\n const year = date.getFullYear();\n const month = date.getMonth() + 1; // 月份从1开始\n const day = date.getDate();\n\n // 替换格式中的占位符\n return format\n .replace('yyyy', year.toString())\n .replace('MM', month.toString().padStart(2, '0'))\n .replace('M', month.toString())\n .replace('dd', day.toString().padStart(2, '0'))\n .replace('d', day.toString());\n}\n"]}
@@ -0,0 +1,21 @@
1
+ import * as VTable from '@visactor/vtable';
2
+ import type { TableEvents } from '@visactor/vtable/src/core/TABLE_EVENT_TYPE';
3
+ export interface IAutoFillPluginOptions {
4
+ fillMode?: 'copy' | 'series';
5
+ fastFillMode?: 'copy' | 'series';
6
+ }
7
+ export declare class AutoFillPlugin implements VTable.plugins.IVTablePlugin {
8
+ id: string;
9
+ name: string;
10
+ runTime: ("mousedown_fill_handle" | "drag_fill_handle_end" | "dblclick_fill_handle")[];
11
+ table: VTable.ListTable;
12
+ private autoFillManager;
13
+ constructor(options?: IAutoFillPluginOptions);
14
+ run(...args: [
15
+ {
16
+ direction: string;
17
+ },
18
+ TableEvents[keyof TableEvents] | TableEvents[keyof TableEvents][],
19
+ VTable.BaseTableAPI
20
+ ]): void;
21
+ }
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+
3
+ var __createBinding = this && this.__createBinding || (Object.create ? function(o, m, k, k2) {
4
+ void 0 === k2 && (k2 = k);
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ desc && !("get" in desc ? !m.__esModule : desc.writable || desc.configurable) || (desc = {
7
+ enumerable: !0,
8
+ get: function() {
9
+ return m[k];
10
+ }
11
+ }), Object.defineProperty(o, k2, desc);
12
+ } : function(o, m, k, k2) {
13
+ void 0 === k2 && (k2 = k), o[k2] = m[k];
14
+ }), __setModuleDefault = this && this.__setModuleDefault || (Object.create ? function(o, v) {
15
+ Object.defineProperty(o, "default", {
16
+ enumerable: !0,
17
+ value: v
18
+ });
19
+ } : function(o, v) {
20
+ o.default = v;
21
+ }), __importStar = this && this.__importStar || function(mod) {
22
+ if (mod && mod.__esModule) return mod;
23
+ var result = {};
24
+ if (null != mod) for (var k in mod) "default" !== k && Object.prototype.hasOwnProperty.call(mod, k) && __createBinding(result, mod, k);
25
+ return __setModuleDefault(result, mod), result;
26
+ };
27
+
28
+ Object.defineProperty(exports, "__esModule", {
29
+ value: !0
30
+ }), exports.AutoFillPlugin = void 0;
31
+
32
+ const VTable = __importStar(require("@visactor/vtable")), auto_fill_manager_1 = require("./auto-fill-manager");
33
+
34
+ class AutoFillPlugin {
35
+ constructor(options) {
36
+ this.id = "auto-fill", this.name = "Auto Fill", this.runTime = [ VTable.TABLE_EVENT_TYPE.MOUSEDOWN_FILL_HANDLE, VTable.TABLE_EVENT_TYPE.DRAG_FILL_HANDLE_END, VTable.TABLE_EVENT_TYPE.DBLCLICK_FILL_HANDLE ],
37
+ this.autoFillManager = new auto_fill_manager_1.AutoFillManager(options);
38
+ }
39
+ run(...args) {
40
+ var _a, _b;
41
+ if (args[1] === VTable.TABLE_EVENT_TYPE.MOUSEDOWN_FILL_HANDLE) {
42
+ const [_, __, table] = args;
43
+ this.table = table, this.autoFillManager.setTable(this.table), this.autoFillManager.handleStartDrag(null === (_a = this.table) || void 0 === _a ? void 0 : _a.getSelectedCellRanges()[0]);
44
+ } else if (args[1] === VTable.TABLE_EVENT_TYPE.DRAG_FILL_HANDLE_END) {
45
+ const [{direction: direction}] = args;
46
+ this.autoFillManager.handleEndDrag(null === (_b = this.table) || void 0 === _b ? void 0 : _b.getSelectedCellRanges()[0], direction);
47
+ } else args[1] === VTable.TABLE_EVENT_TYPE.DBLCLICK_FILL_HANDLE && this.autoFillManager.handleDbClick();
48
+ }
49
+ }
50
+
51
+ exports.AutoFillPlugin = AutoFillPlugin;
52
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/auto-fill/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yDAA2C;AAE3C,2DAAsD;AAqB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IACH,CAAC;CACF;AAnCD,wCAmCC","file":"index.js","sourcesContent":["import * as VTable from '@visactor/vtable';\nimport type { TableEvents } from '@visactor/vtable/src/core/TABLE_EVENT_TYPE';\nimport { AutoFillManager } from './auto-fill-manager';\n/**\n * 自动填充插件\n */\nexport interface IAutoFillPluginOptions {\n /**\n * 填充模式\n * 'copy': 复制填充\n * 'series': 序列填充\n * 不填写则开启自动填充菜单\n */\n fillMode?: 'copy' | 'series';\n /**\n * 快速填充模式\n * 'copy': 复制填充\n * 'series': 序列填充\n * 不填写则开启自动填充菜单\n */\n fastFillMode?: 'copy' | 'series';\n}\n\nexport class AutoFillPlugin implements VTable.plugins.IVTablePlugin {\n id = `auto-fill`;\n name = 'Auto Fill';\n runTime = [\n VTable.TABLE_EVENT_TYPE.MOUSEDOWN_FILL_HANDLE,\n VTable.TABLE_EVENT_TYPE.DRAG_FILL_HANDLE_END,\n VTable.TABLE_EVENT_TYPE.DBLCLICK_FILL_HANDLE\n ];\n table: VTable.ListTable;\n private autoFillManager: AutoFillManager;\n constructor(options?: IAutoFillPluginOptions) {\n this.autoFillManager = new AutoFillManager(options);\n }\n run(\n ...args: [\n { direction: string },\n TableEvents[keyof TableEvents] | TableEvents[keyof TableEvents][],\n VTable.BaseTableAPI\n ]\n ) {\n // start drag\n console.log('auto fill plugin run', args);\n if (args[1] === VTable.TABLE_EVENT_TYPE.MOUSEDOWN_FILL_HANDLE) {\n const [_, __, table] = args;\n this.table = table as VTable.ListTable;\n this.autoFillManager.setTable(this.table);\n this.autoFillManager.handleStartDrag(this.table?.getSelectedCellRanges()[0]);\n } else if (args[1] === VTable.TABLE_EVENT_TYPE.DRAG_FILL_HANDLE_END) {\n // end drag\n const [{ direction }] = args;\n this.autoFillManager.handleEndDrag(this.table?.getSelectedCellRanges()[0], direction);\n } else if (args[1] === VTable.TABLE_EVENT_TYPE.DBLCLICK_FILL_HANDLE) {\n this.autoFillManager.handleDbClick();\n }\n }\n}\n"]}
@@ -0,0 +1,10 @@
1
+ import type { IAutoFillRule } from './types';
2
+ export declare const dateRule: IAutoFillRule;
3
+ export declare const numberRule: IAutoFillRule;
4
+ export declare const otherRule: IAutoFillRule;
5
+ export declare const extendNumberRule: IAutoFillRule;
6
+ export declare const chnNumberRule: IAutoFillRule;
7
+ export declare const chnWeek2Rule: IAutoFillRule;
8
+ export declare const chnWeek3Rule: IAutoFillRule;
9
+ export declare const loopSeriesRule: IAutoFillRule;
10
+ export declare function reverseIfNeed<T>(data: T[], reverse: boolean): T[];