zcatalyst-cli 1.13.3 → 1.14.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.
- package/docs/client-utils.toml +6 -1
- package/docs/commands/ds/import.toml +5 -0
- package/docs/fn-utils/lib/python.toml +4 -0
- package/docs/init/dependencies/python/ensure-python.toml +12 -0
- package/docs/init/dependencies/python/pip-install.toml +4 -0
- package/docs/serve/index.toml +5 -0
- package/lib/authentication/login.js +2 -1
- package/lib/cli_table/index.js +26 -2
- package/lib/cli_table/src/cell.js +359 -267
- package/lib/cli_table/src/layout-manager.js +231 -209
- package/lib/cli_table/src/table.js +76 -60
- package/lib/cli_table/src/utils.js +259 -224
- package/lib/client-utils.js +18 -4
- package/lib/command_needs/rc.js +57 -8
- package/lib/commands/config/delete.js +23 -0
- package/lib/commands/config/get.js +23 -0
- package/lib/commands/config/list.js +23 -0
- package/lib/commands/config/set.js +29 -0
- package/lib/commands/console/cache.js +31 -1
- package/lib/commands/console/queue.js +31 -1
- package/lib/commands/console/zcql.js +27 -1
- package/lib/commands/ds/export.js +2 -2
- package/lib/commands/ds/import.js +25 -5
- package/lib/commands/ds/status.js +2 -2
- package/lib/commands/iac/export.js +1 -1
- package/lib/commands/iac/import.js +1 -1
- package/lib/commands/iac/pack.js +16 -5
- package/lib/commands/iac/status.js +1 -1
- package/lib/commands/index.js +4 -0
- package/lib/commands/project/list.js +1 -1
- package/lib/commands/project/use.js +1 -1
- package/lib/deploy/features/client.js +2 -2
- package/lib/deploy/features/functions/index.js +13 -3
- package/lib/deploy/features/functions/languages/index.js +19 -2
- package/lib/endpoints/index.js +12 -5
- package/lib/endpoints/lib/env.js +5 -2
- package/lib/endpoints/lib/functions.js +30 -0
- package/lib/endpoints/lib/org.js +35 -0
- package/lib/endpoints/lib/project.js +7 -3
- package/lib/express_middlewares/unknownReqProxy.js +4 -1
- package/lib/fn-utils/index.js +2 -0
- package/lib/fn-utils/lib/common.js +68 -7
- package/lib/fn-utils/lib/integ.js +15 -11
- package/lib/fn-utils/lib/java.js +7 -3
- package/lib/fn-utils/lib/python.js +121 -0
- package/lib/fn-watcher.js +10 -2
- package/lib/index.js +2 -1
- package/lib/init/dependencies/python/ensure-python.js +151 -0
- package/lib/init/dependencies/python/pip-install.js +175 -0
- package/lib/init/features/functions/index.js +50 -29
- package/lib/init/features/functions/languages/index.js +3 -1
- package/lib/init/features/functions/languages/python.js +115 -0
- package/lib/init/features/index.js +2 -2
- package/lib/init/features/project.js +26 -6
- package/lib/init/util/project.js +2 -2
- package/lib/internal/api.js +2 -0
- package/lib/internal/command.js +1 -1
- package/lib/internal/rc.js +2 -0
- package/lib/port-resolver.js +4 -3
- package/lib/prompt/types/file-path.js +1 -1
- package/lib/pull/features/functions/index.js +35 -2
- package/lib/pull/features/functions/languages.js +8 -1
- package/lib/readLineUtils.js +37 -1
- package/lib/readline/features/cache.js +175 -1
- package/lib/readline/features/index.js +7 -1
- package/lib/readline/features/queue.js +209 -1
- package/lib/readline/features/zcql.js +237 -1
- package/lib/readline/index.js +30 -1
- package/lib/serve/index.js +48 -7
- package/lib/serve/server/index.js +118 -44
- package/lib/serve/server/lib/master.js +18 -5
- package/lib/serve/server/lib/node.mjs +41 -0
- package/lib/serve/server/lib/web_client/index.js +7 -3
- package/lib/serve/server/lib/web_client/server.js +31 -15
- package/lib/shell/dependencies/http-functions.js +57 -21
- package/lib/shell/dependencies/invoker/bio/java/JavabioInvoker.java +1 -2
- package/lib/shell/dependencies/invoker/bio/node.mjs +127 -0
- package/lib/shell/dependencies/invoker/cron/java/JavacronInvoker.java +1 -1
- package/lib/shell/dependencies/invoker/cron/node.mjs +87 -0
- package/lib/shell/dependencies/invoker/event/java/JavaeventInvoker.java +3 -3
- package/lib/shell/dependencies/invoker/event/node.mjs +84 -0
- package/lib/shell/dependencies/invoker/integ/java/JavaintegInvoker.java +1 -1
- package/lib/shell/dependencies/invoker/integ/node.mjs +88 -0
- package/lib/shell/dependencies/local-function.js +74 -22
- package/lib/shell/index.js +11 -2
- package/lib/shell/prepare/index.js +21 -0
- package/lib/shell/prepare/languages/index.js +8 -2
- package/lib/shell/prepare/languages/java.js +39 -2
- package/lib/shell/prepare/languages/node.js +21 -2
- package/lib/shell/prepare/languages/python.js +65 -0
- package/lib/throbber/index.js +3 -1
- package/lib/userConfig.js +48 -0
- package/lib/util_modules/constants/index.js +3 -1
- package/lib/util_modules/constants/lib/apig-rules.js +8 -0
- package/lib/util_modules/constants/lib/cliq-handlers.js +17 -1
- package/lib/util_modules/constants/lib/dc-type.js +8 -0
- package/lib/util_modules/constants/lib/default.js +2 -2
- package/lib/util_modules/constants/lib/env-path.js +12 -0
- package/lib/util_modules/constants/lib/file-names.js +4 -1
- package/lib/util_modules/constants/lib/folder-names.js +3 -1
- package/lib/util_modules/constants/lib/placeholders.js +6 -1
- package/lib/util_modules/constants/lib/runtime.js +2 -1
- package/lib/util_modules/constants/lib/scopes.js +1 -0
- package/lib/util_modules/constants/lib/template.js +9 -0
- package/lib/util_modules/constants/lib/urls.js +2 -6
- package/lib/util_modules/context-help.js +2 -0
- package/lib/util_modules/fs/lib/async.js +35 -11
- package/lib/util_modules/project.js +20 -1
- package/package.json +2 -1
- package/templates/init/functions/java/aio/catalyst-config.json +3 -2
- package/templates/init/functions/java/bio/catalyst-config.json +3 -2
- package/templates/init/functions/java/cron/catalyst-config.json +3 -2
- package/templates/init/functions/java/event/catalyst-config.json +3 -2
- package/templates/init/functions/java/integ/cliq/catalyst-config.json +1 -0
- package/templates/init/functions/node/aio/catalyst-config.json +3 -2
- package/templates/init/functions/node/bio/catalyst-config.json +3 -2
- package/templates/init/functions/node/cron/catalyst-config.json +3 -2
- package/templates/init/functions/node/event/catalyst-config.json +3 -2
- package/templates/init/functions/node/integ/cliq/catalyst-config.json +1 -0
- package/templates/init/functions/node/integ/cliq/handlers/bot-handler.js +2 -2
- package/templates/init/functions/node/integ/cliq/handlers/command-handler.js +1 -2
- package/templates/init/functions/node/integ/cliq/handlers/function-handler.js +1 -1
- package/templates/init/functions/node/integ/cliq/handlers/installation-handler.js +1 -1
- package/templates/init/functions/node/integ/cliq/handlers/installation-validator.js +1 -1
- package/templates/init/functions/node/integ/cliq/handlers/message-action-handler.js +1 -1
- package/templates/init/functions/node/integ/cliq/handlers/widget-handler.js +1 -1
- package/templates/init/functions/node/integ/cliq/sample.js +4 -4
- package/templates/init/functions/python/aio/catalyst-config.json +11 -0
- package/templates/init/functions/python/aio/requirements.txt +1 -0
- package/templates/init/functions/python/aio/sample.py +26 -0
- package/templates/init/functions/python/bio/catalyst-config.json +11 -0
- package/templates/init/functions/python/bio/requirements.txt +1 -0
- package/templates/init/functions/python/bio/sample.py +6 -0
- package/templates/init/functions/python/cron/catalyst-config.json +11 -0
- package/templates/init/functions/python/cron/requirements.txt +1 -0
- package/templates/init/functions/python/cron/sample.py +18 -0
- package/templates/init/functions/python/event/catalyst-config.json +11 -0
- package/templates/init/functions/python/event/requirements.txt +1 -0
- package/templates/init/functions/python/event/sample.py +21 -0
- package/templates/init/functions/python/integ/cliq/catalyst-config.json +11 -0
- package/templates/init/functions/python/integ/cliq/handlers/bot_handler.py +174 -0
- package/templates/init/functions/python/integ/cliq/handlers/command_handler.py +102 -0
- package/templates/init/functions/python/integ/cliq/handlers/function_handler.py +409 -0
- package/templates/init/functions/python/integ/cliq/handlers/installation_handler.py +12 -0
- package/templates/init/functions/python/integ/cliq/handlers/installation_validator.py +16 -0
- package/templates/init/functions/python/integ/cliq/handlers/message_action_handler.py +18 -0
- package/templates/init/functions/python/integ/cliq/handlers/widget_handler.py +269 -0
- package/templates/init/functions/python/integ/cliq/requirements.txt +1 -0
- package/templates/init/functions/python/integ/cliq/sample.py +21 -0
- package/lib/serve/server/lib/node.js +0 -62
- package/lib/shell/dependencies/invoker/bio/node.js +0 -80
- package/lib/shell/dependencies/invoker/cron/node.js +0 -54
- package/lib/shell/dependencies/invoker/event/node.js +0 -56
- package/lib/shell/dependencies/invoker/integ/node.js +0 -79
- package/templates/.DS_Store +0 -0
- package/templates/init/.DS_Store +0 -0
- package/templates/init/client/.DS_Store +0 -0
- package/templates/init/client/react/.DS_Store +0 -0
- 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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
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
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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;
|