zcatalyst-cli 1.13.3 → 1.14.1

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 (162) hide show
  1. package/docs/client-utils.toml +6 -1
  2. package/docs/commands/ds/import.toml +5 -0
  3. package/docs/fn-utils/lib/python.toml +4 -0
  4. package/docs/init/dependencies/python/ensure-python.toml +12 -0
  5. package/docs/init/dependencies/python/pip-install.toml +4 -0
  6. package/docs/serve/index.toml +5 -0
  7. package/lib/authentication/login.js +2 -1
  8. package/lib/cli_table/index.js +26 -2
  9. package/lib/cli_table/src/cell.js +359 -267
  10. package/lib/cli_table/src/layout-manager.js +231 -209
  11. package/lib/cli_table/src/table.js +76 -60
  12. package/lib/cli_table/src/utils.js +259 -224
  13. package/lib/client-utils.js +18 -4
  14. package/lib/command_needs/rc.js +57 -8
  15. package/lib/commands/config/delete.js +23 -0
  16. package/lib/commands/config/get.js +23 -0
  17. package/lib/commands/config/list.js +23 -0
  18. package/lib/commands/config/set.js +29 -0
  19. package/lib/commands/console/cache.js +31 -1
  20. package/lib/commands/console/queue.js +31 -1
  21. package/lib/commands/console/zcql.js +27 -1
  22. package/lib/commands/ds/export.js +2 -2
  23. package/lib/commands/ds/import.js +25 -5
  24. package/lib/commands/ds/status.js +2 -2
  25. package/lib/commands/iac/export.js +1 -1
  26. package/lib/commands/iac/import.js +1 -1
  27. package/lib/commands/iac/pack.js +16 -5
  28. package/lib/commands/iac/status.js +1 -1
  29. package/lib/commands/index.js +4 -0
  30. package/lib/commands/project/list.js +1 -1
  31. package/lib/commands/project/use.js +1 -1
  32. package/lib/deploy/features/client.js +2 -2
  33. package/lib/deploy/features/functions/index.js +13 -3
  34. package/lib/deploy/features/functions/languages/index.js +19 -2
  35. package/lib/endpoints/index.js +12 -5
  36. package/lib/endpoints/lib/env.js +5 -2
  37. package/lib/endpoints/lib/functions.js +30 -0
  38. package/lib/endpoints/lib/org.js +35 -0
  39. package/lib/endpoints/lib/project.js +7 -3
  40. package/lib/express_middlewares/unknownReqProxy.js +4 -1
  41. package/lib/fn-utils/index.js +2 -0
  42. package/lib/fn-utils/lib/common.js +68 -7
  43. package/lib/fn-utils/lib/integ.js +15 -11
  44. package/lib/fn-utils/lib/java.js +7 -3
  45. package/lib/fn-utils/lib/python.js +121 -0
  46. package/lib/fn-watcher.js +10 -2
  47. package/lib/index.js +2 -1
  48. package/lib/init/dependencies/python/ensure-python.js +151 -0
  49. package/lib/init/dependencies/python/pip-install.js +189 -0
  50. package/lib/init/features/functions/index.js +50 -29
  51. package/lib/init/features/functions/languages/index.js +3 -1
  52. package/lib/init/features/functions/languages/python.js +115 -0
  53. package/lib/init/features/index.js +2 -2
  54. package/lib/init/features/project.js +26 -6
  55. package/lib/init/util/project.js +2 -2
  56. package/lib/internal/api.js +2 -0
  57. package/lib/internal/command.js +1 -1
  58. package/lib/internal/rc.js +2 -0
  59. package/lib/port-resolver.js +4 -3
  60. package/lib/prompt/types/file-path.js +1 -1
  61. package/lib/pull/features/functions/index.js +35 -2
  62. package/lib/pull/features/functions/languages.js +8 -1
  63. package/lib/readLineUtils.js +37 -1
  64. package/lib/readline/features/cache.js +175 -1
  65. package/lib/readline/features/index.js +7 -1
  66. package/lib/readline/features/queue.js +209 -1
  67. package/lib/readline/features/zcql.js +237 -1
  68. package/lib/readline/index.js +30 -1
  69. package/lib/serve/index.js +48 -7
  70. package/lib/serve/server/index.js +118 -44
  71. package/lib/serve/server/lib/java/lib/catalyst-cli-java-runtime-1.0.0.jar +0 -0
  72. package/lib/serve/server/lib/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
  73. package/lib/serve/server/lib/java/lib/catalyst-java-runtime-1.0.0.jar +0 -0
  74. package/lib/serve/server/lib/master.js +18 -5
  75. package/lib/serve/server/lib/node.mjs +41 -0
  76. package/lib/serve/server/lib/web_client/index.js +7 -3
  77. package/lib/serve/server/lib/web_client/server.js +31 -15
  78. package/lib/shell/dependencies/http-functions.js +57 -21
  79. package/lib/shell/dependencies/invoker/bio/java/JavabioInvoker.java +1 -2
  80. package/lib/shell/dependencies/invoker/bio/node.mjs +127 -0
  81. package/lib/shell/dependencies/invoker/cron/java/JavacronInvoker.java +1 -1
  82. package/lib/shell/dependencies/invoker/cron/node.mjs +87 -0
  83. package/lib/shell/dependencies/invoker/event/java/JavaeventInvoker.java +3 -3
  84. package/lib/shell/dependencies/invoker/event/node.mjs +84 -0
  85. package/lib/shell/dependencies/invoker/integ/java/JavaintegInvoker.java +1 -1
  86. package/lib/shell/dependencies/invoker/integ/node.mjs +88 -0
  87. package/lib/shell/dependencies/local-function.js +74 -22
  88. package/lib/shell/index.js +11 -2
  89. package/lib/shell/prepare/index.js +21 -0
  90. package/lib/shell/prepare/languages/index.js +8 -2
  91. package/lib/shell/prepare/languages/java.js +39 -2
  92. package/lib/shell/prepare/languages/node.js +21 -2
  93. package/lib/shell/prepare/languages/python.js +65 -0
  94. package/lib/throbber/index.js +3 -1
  95. package/lib/userConfig.js +48 -0
  96. package/lib/util_modules/constants/index.js +3 -1
  97. package/lib/util_modules/constants/lib/apig-rules.js +8 -0
  98. package/lib/util_modules/constants/lib/cliq-handlers.js +17 -1
  99. package/lib/util_modules/constants/lib/dc-type.js +8 -0
  100. package/lib/util_modules/constants/lib/default.js +2 -2
  101. package/lib/util_modules/constants/lib/env-path.js +12 -0
  102. package/lib/util_modules/constants/lib/file-names.js +4 -1
  103. package/lib/util_modules/constants/lib/folder-names.js +3 -1
  104. package/lib/util_modules/constants/lib/placeholders.js +6 -1
  105. package/lib/util_modules/constants/lib/runtime.js +2 -1
  106. package/lib/util_modules/constants/lib/scopes.js +1 -0
  107. package/lib/util_modules/constants/lib/template.js +9 -0
  108. package/lib/util_modules/constants/lib/urls.js +2 -6
  109. package/lib/util_modules/context-help.js +2 -0
  110. package/lib/util_modules/fs/lib/async.js +35 -11
  111. package/lib/util_modules/project.js +20 -1
  112. package/package.json +2 -1
  113. package/templates/init/functions/java/aio/catalyst-config.json +3 -2
  114. package/templates/init/functions/java/bio/catalyst-config.json +3 -2
  115. package/templates/init/functions/java/cron/catalyst-config.json +3 -2
  116. package/templates/init/functions/java/event/catalyst-config.json +3 -2
  117. package/templates/init/functions/java/integ/cliq/catalyst-config.json +1 -0
  118. package/templates/init/functions/node/aio/catalyst-config.json +3 -2
  119. package/templates/init/functions/node/bio/catalyst-config.json +3 -2
  120. package/templates/init/functions/node/cron/catalyst-config.json +3 -2
  121. package/templates/init/functions/node/event/catalyst-config.json +3 -2
  122. package/templates/init/functions/node/integ/cliq/catalyst-config.json +1 -0
  123. package/templates/init/functions/node/integ/cliq/handlers/bot-handler.js +2 -2
  124. package/templates/init/functions/node/integ/cliq/handlers/command-handler.js +1 -2
  125. package/templates/init/functions/node/integ/cliq/handlers/function-handler.js +1 -1
  126. package/templates/init/functions/node/integ/cliq/handlers/installation-handler.js +1 -1
  127. package/templates/init/functions/node/integ/cliq/handlers/installation-validator.js +1 -1
  128. package/templates/init/functions/node/integ/cliq/handlers/message-action-handler.js +1 -1
  129. package/templates/init/functions/node/integ/cliq/handlers/widget-handler.js +1 -1
  130. package/templates/init/functions/node/integ/cliq/sample.js +4 -4
  131. package/templates/init/functions/python/aio/catalyst-config.json +11 -0
  132. package/templates/init/functions/python/aio/requirements.txt +1 -0
  133. package/templates/init/functions/python/aio/sample.py +26 -0
  134. package/templates/init/functions/python/bio/catalyst-config.json +11 -0
  135. package/templates/init/functions/python/bio/requirements.txt +1 -0
  136. package/templates/init/functions/python/bio/sample.py +6 -0
  137. package/templates/init/functions/python/cron/catalyst-config.json +11 -0
  138. package/templates/init/functions/python/cron/requirements.txt +1 -0
  139. package/templates/init/functions/python/cron/sample.py +18 -0
  140. package/templates/init/functions/python/event/catalyst-config.json +11 -0
  141. package/templates/init/functions/python/event/requirements.txt +1 -0
  142. package/templates/init/functions/python/event/sample.py +21 -0
  143. package/templates/init/functions/python/integ/cliq/catalyst-config.json +11 -0
  144. package/templates/init/functions/python/integ/cliq/handlers/bot_handler.py +174 -0
  145. package/templates/init/functions/python/integ/cliq/handlers/command_handler.py +102 -0
  146. package/templates/init/functions/python/integ/cliq/handlers/function_handler.py +409 -0
  147. package/templates/init/functions/python/integ/cliq/handlers/installation_handler.py +12 -0
  148. package/templates/init/functions/python/integ/cliq/handlers/installation_validator.py +16 -0
  149. package/templates/init/functions/python/integ/cliq/handlers/message_action_handler.py +18 -0
  150. package/templates/init/functions/python/integ/cliq/handlers/widget_handler.py +269 -0
  151. package/templates/init/functions/python/integ/cliq/requirements.txt +1 -0
  152. package/templates/init/functions/python/integ/cliq/sample.py +21 -0
  153. package/lib/serve/server/lib/node.js +0 -62
  154. package/lib/shell/dependencies/invoker/bio/node.js +0 -80
  155. package/lib/shell/dependencies/invoker/cron/node.js +0 -54
  156. package/lib/shell/dependencies/invoker/event/node.js +0 -56
  157. package/lib/shell/dependencies/invoker/integ/node.js +0 -79
  158. package/templates/.DS_Store +0 -0
  159. package/templates/init/.DS_Store +0 -0
  160. package/templates/init/client/.DS_Store +0 -0
  161. package/templates/init/client/react/.DS_Store +0 -0
  162. package/templates/init/functions/node/integ/cliq/.DS_Store +0 -0
@@ -1,215 +1,237 @@
1
- "use strict";
2
1
  const Cell = require('./cell');
3
2
  const { ColSpanCell, RowSpanCell } = Cell;
3
+
4
4
  (function () {
5
- function layoutTable(table) {
6
- table.forEach((row, rowIndex) => {
7
- let prevCell = null;
8
- row.forEach((cell, columnIndex) => {
9
- cell.y = rowIndex;
10
- cell.x = prevCell ? prevCell.x + 1 : columnIndex;
11
- for (let y = rowIndex; y >= 0; y--) {
12
- const row2 = table[y];
13
- const xMax = y === rowIndex ? columnIndex : row2.length;
14
- for (let x = 0; x < xMax; x++) {
15
- const cell2 = row2[x];
16
- while (cellsConflict(cell, cell2)) {
17
- cell.x++;
18
- }
19
- }
20
- prevCell = cell;
21
- }
22
- });
23
- });
24
- }
25
- function maxWidth(table) {
26
- let mw = 0;
27
- table.forEach((row) => {
28
- row.forEach((cell) => {
29
- mw = Math.max(mw, cell.x + (cell.colSpan || 1));
30
- });
31
- });
32
- return mw;
33
- }
34
- function maxHeight(table) {
35
- return table.length;
36
- }
37
- function cellsConflict(cell1, cell2) {
38
- const yMin1 = cell1.y;
39
- const yMax1 = cell1.y - 1 + (cell1.rowSpan || 1);
40
- const yMin2 = cell2.y;
41
- const yMax2 = cell2.y - 1 + (cell2.rowSpan || 1);
42
- const yConflict = !(yMin1 > yMax2 || yMin2 > yMax1);
43
- const xMin1 = cell1.x;
44
- const xMax1 = cell1.x - 1 + (cell1.colSpan || 1);
45
- const xMin2 = cell2.x;
46
- const xMax2 = cell2.x - 1 + (cell2.colSpan || 1);
47
- const xConflict = !(xMin1 > xMax2 || xMin2 > xMax1);
48
- return yConflict && xConflict;
49
- }
50
- function conflictExists(rows, x, y) {
51
- const i_max = Math.min(rows.length - 1, y);
52
- const cell = { x: x, y: y };
53
- for (let i = 0; i <= i_max; i++) {
54
- const row = rows[i];
55
- for (let j = 0; j < row.length; j++) {
56
- if (cellsConflict(cell, row[j])) {
57
- return true;
58
- }
59
- }
60
- }
61
- return false;
62
- }
63
- function allBlank(rows, y, xMin, xMax) {
64
- for (let x = xMin; x < xMax; x++) {
65
- if (conflictExists(rows, x, y)) {
66
- return false;
67
- }
68
- }
69
- return true;
70
- }
71
- function addRowSpanCells(table) {
72
- table.forEach((row, rowIndex) => {
73
- row.forEach((cell) => {
74
- for (let i = 1; i < cell.rowSpan; i++) {
75
- const rowSpanCell = new RowSpanCell(cell);
76
- rowSpanCell.x = cell.x;
77
- rowSpanCell.y = cell.y + i;
78
- rowSpanCell.colSpan = cell.colSpan;
79
- insertCell(rowSpanCell, table[rowIndex + i]);
80
- }
81
- });
82
- });
83
- }
84
- function addColSpanCells(cellRows) {
85
- for (let rowIndex = cellRows.length - 1; rowIndex >= 0; rowIndex--) {
86
- const cellColumns = cellRows[rowIndex];
87
- for (let columnIndex = 0; columnIndex < cellColumns.length; columnIndex++) {
88
- const cell = cellColumns[columnIndex];
89
- for (let k = 1; k < cell.colSpan; k++) {
90
- const colSpanCell = new ColSpanCell();
91
- colSpanCell.x = cell.x + k;
92
- colSpanCell.y = cell.y;
93
- cellColumns.splice(columnIndex + 1, 0, colSpanCell);
94
- }
95
- }
96
- }
97
- }
98
- function insertCell(cell, row) {
99
- let x = 0;
100
- while (x < row.length && row[x].x < cell.x) {
101
- x++;
102
- }
103
- row.splice(x, 0, cell);
104
- }
105
- function fillInTable(table) {
106
- const h_max = maxHeight(table);
107
- const w_max = maxWidth(table);
108
- for (let y = 0; y < h_max; y++) {
109
- for (let x = 0; x < w_max; x++) {
110
- if (!conflictExists(table, x, y)) {
111
- const opts = { x: x, y: y, colSpan: 1, rowSpan: 1 };
112
- x++;
113
- while (x < w_max && !conflictExists(table, x, y)) {
114
- opts.colSpan++;
115
- x++;
116
- }
117
- let y2 = y + 1;
118
- while (y2 < h_max && allBlank(table, y2, opts.x, opts.x + opts.colSpan)) {
119
- opts.rowSpan++;
120
- y2++;
121
- }
122
- const cell = new Cell(opts);
123
- cell.x = opts.x;
124
- cell.y = opts.y;
125
- insertCell(cell, table[y]);
126
- }
127
- }
128
- }
129
- }
130
- function generateCells(rows) {
131
- return rows.map((row) => {
132
- if (!Array.isArray(row)) {
133
- const key = Object.keys(row)[0];
134
- row = row[key];
135
- if (Array.isArray(row)) {
136
- row = row.slice();
137
- row.unshift(key);
138
- }
139
- else {
140
- row = [key, row];
141
- }
142
- }
143
- return row.map((cell) => {
144
- return new Cell(cell);
145
- });
146
- });
147
- }
148
- function makeTableLayout(rows) {
149
- const cellRows = generateCells(rows);
150
- layoutTable(cellRows);
151
- fillInTable(cellRows);
152
- addRowSpanCells(cellRows);
153
- addColSpanCells(cellRows);
154
- return cellRows;
155
- }
156
- module.exports = {
157
- makeTableLayout: makeTableLayout,
158
- layoutTable: layoutTable,
159
- addRowSpanCells: addRowSpanCells,
160
- maxWidth: maxWidth,
161
- fillInTable: fillInTable,
162
- computeWidths: makeComputeWidths('colSpan', 'desiredWidth', 'x', 1),
163
- computeHeights: makeComputeWidths('rowSpan', 'desiredHeight', 'y', 1)
164
- };
5
+ function layoutTable(table) {
6
+ table.forEach((row, rowIndex) => {
7
+ let prevCell = null;
8
+ row.forEach((cell, columnIndex) => {
9
+ cell.y = rowIndex;
10
+ cell.x = prevCell ? prevCell.x + 1 : columnIndex;
11
+ for (let y = rowIndex; y >= 0; y--) {
12
+ const row2 = table[y];
13
+ const xMax = y === rowIndex ? columnIndex : row2.length;
14
+ for (let x = 0; x < xMax; x++) {
15
+ const cell2 = row2[x];
16
+ while (cellsConflict(cell, cell2)) {
17
+ cell.x++;
18
+ }
19
+ }
20
+ prevCell = cell;
21
+ }
22
+ });
23
+ });
24
+ }
25
+
26
+ function maxWidth(table) {
27
+ let mw = 0;
28
+ table.forEach((row) => {
29
+ row.forEach((cell) => {
30
+ mw = Math.max(mw, cell.x + (cell.colSpan || 1));
31
+ });
32
+ });
33
+ return mw;
34
+ }
35
+
36
+ function maxHeight(table) {
37
+ return table.length;
38
+ }
39
+
40
+ function cellsConflict(cell1, cell2) {
41
+ const yMin1 = cell1.y;
42
+ const yMax1 = cell1.y - 1 + (cell1.rowSpan || 1);
43
+ const yMin2 = cell2.y;
44
+ const yMax2 = cell2.y - 1 + (cell2.rowSpan || 1);
45
+ const yConflict = !(yMin1 > yMax2 || yMin2 > yMax1);
46
+
47
+ const xMin1 = cell1.x;
48
+ const xMax1 = cell1.x - 1 + (cell1.colSpan || 1);
49
+ const xMin2 = cell2.x;
50
+ const xMax2 = cell2.x - 1 + (cell2.colSpan || 1);
51
+ const xConflict = !(xMin1 > xMax2 || xMin2 > xMax1);
52
+
53
+ return yConflict && xConflict;
54
+ }
55
+
56
+ function conflictExists(rows, x, y) {
57
+ const i_max = Math.min(rows.length - 1, y);
58
+ const cell = { x: x, y: y };
59
+ for (let i = 0; i <= i_max; i++) {
60
+ const row = rows[i];
61
+ for (let j = 0; j < row.length; j++) {
62
+ if (cellsConflict(cell, row[j])) {
63
+ return true;
64
+ }
65
+ }
66
+ }
67
+ return false;
68
+ }
69
+
70
+ function allBlank(rows, y, xMin, xMax) {
71
+ for (let x = xMin; x < xMax; x++) {
72
+ if (conflictExists(rows, x, y)) {
73
+ return false;
74
+ }
75
+ }
76
+ return true;
77
+ }
78
+
79
+ function addRowSpanCells(table) {
80
+ table.forEach((row, rowIndex) => {
81
+ row.forEach((cell) => {
82
+ for (let i = 1; i < cell.rowSpan; i++) {
83
+ const rowSpanCell = new RowSpanCell(cell);
84
+ rowSpanCell.x = cell.x;
85
+ rowSpanCell.y = cell.y + i;
86
+ rowSpanCell.colSpan = cell.colSpan;
87
+ insertCell(rowSpanCell, table[rowIndex + i]);
88
+ }
89
+ });
90
+ });
91
+ }
92
+
93
+ function addColSpanCells(cellRows) {
94
+ for (let rowIndex = cellRows.length - 1; rowIndex >= 0; rowIndex--) {
95
+ const cellColumns = cellRows[rowIndex];
96
+ for (let columnIndex = 0; columnIndex < cellColumns.length; columnIndex++) {
97
+ const cell = cellColumns[columnIndex];
98
+ for (let k = 1; k < cell.colSpan; k++) {
99
+ const colSpanCell = new ColSpanCell();
100
+ colSpanCell.x = cell.x + k;
101
+ colSpanCell.y = cell.y;
102
+ cellColumns.splice(columnIndex + 1, 0, colSpanCell);
103
+ }
104
+ }
105
+ }
106
+ }
107
+
108
+ function insertCell(cell, row) {
109
+ let x = 0;
110
+ while (x < row.length && row[x].x < cell.x) {
111
+ x++;
112
+ }
113
+ row.splice(x, 0, cell);
114
+ }
115
+
116
+ function fillInTable(table) {
117
+ const h_max = maxHeight(table);
118
+ const w_max = maxWidth(table);
119
+ for (let y = 0; y < h_max; y++) {
120
+ for (let x = 0; x < w_max; x++) {
121
+ if (!conflictExists(table, x, y)) {
122
+ const opts = { x: x, y: y, colSpan: 1, rowSpan: 1 };
123
+ x++;
124
+ while (x < w_max && !conflictExists(table, x, y)) {
125
+ opts.colSpan++;
126
+ x++;
127
+ }
128
+ let y2 = y + 1;
129
+ while (y2 < h_max && allBlank(table, y2, opts.x, opts.x + opts.colSpan)) {
130
+ opts.rowSpan++;
131
+ y2++;
132
+ }
133
+
134
+ const cell = new Cell(opts);
135
+ cell.x = opts.x;
136
+ cell.y = opts.y;
137
+ insertCell(cell, table[y]);
138
+ }
139
+ }
140
+ }
141
+ }
142
+
143
+ function generateCells(rows) {
144
+ return rows.map((row) => {
145
+ if (!Array.isArray(row)) {
146
+ const key = Object.keys(row)[0];
147
+ row = row[key];
148
+ if (Array.isArray(row)) {
149
+ row = row.slice();
150
+ row.unshift(key);
151
+ } else {
152
+ row = [key, row];
153
+ }
154
+ }
155
+ return row.map((cell) => {
156
+ return new Cell(cell);
157
+ });
158
+ });
159
+ }
160
+
161
+ function makeTableLayout(rows) {
162
+ const cellRows = generateCells(rows);
163
+ layoutTable(cellRows);
164
+ fillInTable(cellRows);
165
+ addRowSpanCells(cellRows);
166
+ addColSpanCells(cellRows);
167
+ return cellRows;
168
+ }
169
+
170
+ module.exports = {
171
+ makeTableLayout: makeTableLayout,
172
+ layoutTable: layoutTable,
173
+ addRowSpanCells: addRowSpanCells,
174
+ maxWidth: maxWidth,
175
+ fillInTable: fillInTable,
176
+ computeWidths: makeComputeWidths('colSpan', 'desiredWidth', 'x', 1),
177
+ computeHeights: makeComputeWidths('rowSpan', 'desiredHeight', 'y', 1)
178
+ };
165
179
  })();
180
+
166
181
  function makeComputeWidths(colSpan, desiredWidth, x, forcedMin) {
167
- return function (vals, table) {
168
- const result = [];
169
- const spanners = [];
170
- table.forEach((row) => {
171
- row.forEach((cell) => {
172
- if ((cell[colSpan] || 1) > 1) {
173
- spanners.push(cell);
174
- }
175
- else {
176
- result[cell[x]] = Math.max(result[cell[x]] || 0, cell[desiredWidth] || 0, forcedMin);
177
- }
178
- });
179
- });
180
- vals.forEach((val, index) => {
181
- if (typeof val === 'number') {
182
- result[index] = val;
183
- }
184
- });
185
- for (let k = spanners.length - 1; k >= 0; k--) {
186
- const cell = spanners[k];
187
- const span = cell[colSpan];
188
- const col = cell[x];
189
- let existingWidth = result[col];
190
- let editableCols = typeof vals[col] === 'number' ? 0 : 1;
191
- for (let i = 1; i < span; i++) {
192
- existingWidth += 1 + result[col + i];
193
- if (typeof vals[col + i] !== 'number') {
194
- editableCols++;
195
- }
196
- }
197
- if (cell[desiredWidth] > existingWidth) {
198
- let i = 0;
199
- while (editableCols > 0 && cell[desiredWidth] > existingWidth) {
200
- if (typeof vals[col + i] !== 'number') {
201
- const dif = Math.round((cell[desiredWidth] - existingWidth) / editableCols);
202
- existingWidth += dif;
203
- result[col + i] += dif;
204
- editableCols--;
205
- }
206
- i++;
207
- }
208
- }
209
- }
210
- Object.assign(vals, result);
211
- for (let j = 0; j < vals.length; j++) {
212
- vals[j] = Math.max(forcedMin, vals[j] || 0);
213
- }
214
- };
182
+ return function (vals, table) {
183
+ const result = [];
184
+ const spanners = [];
185
+ table.forEach((row) => {
186
+ row.forEach((cell) => {
187
+ if ((cell[colSpan] || 1) > 1) {
188
+ spanners.push(cell);
189
+ } else {
190
+ result[cell[x]] = Math.max(
191
+ result[cell[x]] || 0,
192
+ cell[desiredWidth] || 0,
193
+ forcedMin
194
+ );
195
+ }
196
+ });
197
+ });
198
+
199
+ vals.forEach((val, index) => {
200
+ if (typeof val === 'number') {
201
+ result[index] = val;
202
+ }
203
+ });
204
+
205
+ // spanners.forEach(function(cell){
206
+ for (let k = spanners.length - 1; k >= 0; k--) {
207
+ const cell = spanners[k];
208
+ const span = cell[colSpan];
209
+ const col = cell[x];
210
+ let existingWidth = result[col];
211
+ let editableCols = typeof vals[col] === 'number' ? 0 : 1;
212
+ for (let i = 1; i < span; i++) {
213
+ existingWidth += 1 + result[col + i];
214
+ if (typeof vals[col + i] !== 'number') {
215
+ editableCols++;
216
+ }
217
+ }
218
+ if (cell[desiredWidth] > existingWidth) {
219
+ let i = 0;
220
+ while (editableCols > 0 && cell[desiredWidth] > existingWidth) {
221
+ if (typeof vals[col + i] !== 'number') {
222
+ const dif = Math.round((cell[desiredWidth] - existingWidth) / editableCols);
223
+ existingWidth += dif;
224
+ result[col + i] += dif;
225
+ editableCols--;
226
+ }
227
+ i++;
228
+ }
229
+ }
230
+ }
231
+
232
+ Object.assign(vals, result);
233
+ for (let j = 0; j < vals.length; j++) {
234
+ vals[j] = Math.max(forcedMin, vals[j] || 0);
235
+ }
236
+ };
215
237
  }
@@ -1,67 +1,83 @@
1
- "use strict";
2
1
  const utils = require('./utils');
3
2
  const tableLayout = require('./layout-manager');
3
+
4
4
  class Table extends Array {
5
- constructor(options) {
6
- super();
7
- this.options = utils.mergeOptions(options);
8
- }
9
- toString() {
10
- let array = this;
11
- const headersPresent = this.options.head && this.options.head.length;
12
- if (headersPresent) {
13
- array = [this.options.head];
14
- if (this.length) {
15
- array.push.apply(array, this);
16
- }
17
- }
18
- else {
19
- this.options.style.head = [];
20
- }
21
- const cells = tableLayout.makeTableLayout(array);
22
- cells.forEach(function (row) {
23
- row.forEach(function (cell) {
24
- cell.mergeTableOptions(this.options, cells);
25
- }, this);
26
- }, this);
27
- tableLayout.computeWidths(this.options.colWidths, cells);
28
- tableLayout.computeHeights(this.options.rowHeights, cells);
29
- cells.forEach(function (row) {
30
- row.forEach(function (cell) {
31
- cell.init(this.options);
32
- }, this);
33
- }, this);
34
- const result = [];
35
- for (let rowIndex = 0; rowIndex < cells.length; rowIndex++) {
36
- const row = cells[rowIndex];
37
- const heightOfRow = this.options.rowHeights[rowIndex];
38
- if (rowIndex === 0 ||
39
- !this.options.style.compact ||
40
- (rowIndex == 1 && headersPresent)) {
41
- doDraw(row, 'top', result);
42
- }
43
- for (let lineNum = 0; lineNum < heightOfRow; lineNum++) {
44
- doDraw(row, lineNum, result);
45
- }
46
- if (rowIndex + 1 == cells.length) {
47
- doDraw(row, 'bottom', result);
48
- }
49
- }
50
- return result.join('\n');
51
- }
52
- get width() {
53
- const str = this.toString().split('\n');
54
- return str[0].length;
55
- }
5
+ constructor(options) {
6
+ super();
7
+
8
+ this.options = utils.mergeOptions(options);
9
+ }
10
+
11
+ toString() {
12
+ let array = this;
13
+ const headersPresent = this.options.head && this.options.head.length;
14
+ if (headersPresent) {
15
+ array = [this.options.head];
16
+ if (this.length) {
17
+ array.push.apply(array, this);
18
+ }
19
+ } else {
20
+ this.options.style.head = [];
21
+ }
22
+
23
+ const cells = tableLayout.makeTableLayout(array);
24
+
25
+ cells.forEach(function (row) {
26
+ row.forEach(function (cell) {
27
+ cell.mergeTableOptions(this.options, cells);
28
+ }, this);
29
+ }, this);
30
+
31
+ tableLayout.computeWidths(this.options.colWidths, cells);
32
+ tableLayout.computeHeights(this.options.rowHeights, cells);
33
+
34
+ cells.forEach(function (row) {
35
+ row.forEach(function (cell) {
36
+ cell.init(this.options);
37
+ }, this);
38
+ }, this);
39
+
40
+ const result = [];
41
+
42
+ for (let rowIndex = 0; rowIndex < cells.length; rowIndex++) {
43
+ const row = cells[rowIndex];
44
+ const heightOfRow = this.options.rowHeights[rowIndex];
45
+
46
+ if (
47
+ rowIndex === 0 ||
48
+ !this.options.style.compact ||
49
+ (rowIndex == 1 && headersPresent)
50
+ ) {
51
+ doDraw(row, 'top', result);
52
+ }
53
+
54
+ for (let lineNum = 0; lineNum < heightOfRow; lineNum++) {
55
+ doDraw(row, lineNum, result);
56
+ }
57
+
58
+ if (rowIndex + 1 == cells.length) {
59
+ doDraw(row, 'bottom', result);
60
+ }
61
+ }
62
+
63
+ return result.join('\n');
64
+ }
65
+
66
+ get width() {
67
+ const str = this.toString().split('\n');
68
+ return str[0].length;
69
+ }
56
70
  }
71
+
57
72
  function doDraw(row, lineNum, result) {
58
- const line = [];
59
- row.forEach((cell) => {
60
- line.push(cell.draw(lineNum));
61
- });
62
- const str = line.join('');
63
- if (str.length) {
64
- result.push(str);
65
- }
73
+ const line = [];
74
+ row.forEach((cell) => {
75
+ line.push(cell.draw(lineNum));
76
+ });
77
+ const str = line.join('');
78
+ if (str.length) {
79
+ result.push(str);
80
+ }
66
81
  }
82
+
67
83
  module.exports = Table;