@nocobase/plugin-action-export 1.0.0-alpha.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.
- package/LICENSE +661 -0
- package/README.md +9 -0
- package/README.zh-CN.md +9 -0
- package/client.d.ts +2 -0
- package/client.js +1 -0
- package/dist/client/ExportActionInitializer.d.ts +8 -0
- package/dist/client/ExportDesigner.d.ts +2 -0
- package/dist/client/ExportPluginProvider.d.ts +2 -0
- package/dist/client/index.d.ts +9 -0
- package/dist/client/index.js +14 -0
- package/dist/client/locale/index.d.ts +2 -0
- package/dist/client/schemaSettings.d.ts +2 -0
- package/dist/client/useExportAction.d.ts +3 -0
- package/dist/client/useFields.d.ts +1 -0
- package/dist/client/useShared.d.ts +71 -0
- package/dist/externalVersion.js +14 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +39 -0
- package/dist/locale/en-US.json +4 -0
- package/dist/locale/zh-CN.json +4 -0
- package/dist/node_modules/node-xlsx/lib/helpers.js +142 -0
- package/dist/node_modules/node-xlsx/lib/index.js +6 -0
- package/dist/node_modules/node-xlsx/lib/workbook.js +16 -0
- package/dist/node_modules/node-xlsx/package.json +1 -0
- package/dist/server/actions/export-xlsx.d.ts +2 -0
- package/dist/server/actions/export-xlsx.js +80 -0
- package/dist/server/actions/index.d.ts +1 -0
- package/dist/server/actions/index.js +21 -0
- package/dist/server/index.d.ts +7 -0
- package/dist/server/index.js +49 -0
- package/dist/server/migrations/20240425220631-change-locale-module.d.ts +6 -0
- package/dist/server/migrations/20240425220631-change-locale-module.js +42 -0
- package/dist/server/renders/index.d.ts +8 -0
- package/dist/server/renders/index.js +159 -0
- package/dist/server/renders/renders.d.ts +15 -0
- package/dist/server/renders/renders.js +167 -0
- package/dist/server/utils/columns2Appends.d.ts +1 -0
- package/dist/server/utils/columns2Appends.js +45 -0
- package/dist/server/utils/index.d.ts +1 -0
- package/dist/server/utils/index.js +21 -0
- package/dist/swagger/index.json +21 -0
- package/package.json +34 -0
- package/server.d.ts +2 -0
- package/server.js +1 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
exports.__esModule = true;
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
|
|
10
|
+
var Workbook = function Workbook() {
|
|
11
|
+
(0, _defineProperty2.default)(this, "SheetNames", []);
|
|
12
|
+
(0, _defineProperty2.default)(this, "Sheets", {});
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
exports.default = Workbook;
|
|
16
|
+
//# sourceMappingURL=workbook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"name":"node-xlsx","author":"Olivier Louvignes <olivier@mg-crea.com>","version":"0.16.2","description":"NodeJS Excel files parser & builder","main":"lib/index.js","scripts":{"start":"yarn test:watch","test":"NODE_ENV=test jest --runInBand","test:watch":"yarn test -- --watch","test:coverage":"yarn test -- --coverage","lint":"NODE_ENV=test eslint src/ test/","build":"rimraf lib/*; NODE_ENV=production babel src/ -d lib/ -s","build:watch":"yarn build -- -w","prepublish":"yarn build"},"repository":"github:mgcrea/node-xlsx","license":"Apache-2.0","dependencies":{"@babel/runtime":"^7.14.6","buffer-from":"^1.1.1","xlsx":"^0.17.0"},"devDependencies":{"@babel/cli":"^7.14.5","@babel/core":"^7.14.6","@babel/plugin-proposal-class-properties":"^7.14.5","@babel/plugin-transform-runtime":"^7.14.5","@babel/preset-env":"^7.14.7","babel-eslint":"^10.1.0","codacy-coverage":"^3.4.0","debug-utils":"^0.5.3","eslint":"^7.30.0","eslint-config-airbnb-base":"^14.2.1","eslint-config-prettier":"^8.3.0","eslint-plugin-import":"^2.23.4","expect":"^27.0.6","jest":"^27.0.6","rimraf":"^3.0.2"},"engines":{"node":">=4.0.0"},"keywords":["excel","parser","builder","xlsx","xls"],"jest":{"testEnvironment":"node","setupFiles":["<rootDir>/test/setup.js"]},"_lastModified":"2024-04-28T17:04:42.069Z"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var export_xlsx_exports = {};
|
|
29
|
+
__export(export_xlsx_exports, {
|
|
30
|
+
exportXlsx: () => exportXlsx
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(export_xlsx_exports);
|
|
33
|
+
var import_node_xlsx = __toESM(require("node-xlsx"));
|
|
34
|
+
var import_renders = __toESM(require("../renders"));
|
|
35
|
+
var import_utils = require("../utils");
|
|
36
|
+
async function exportXlsx(ctx, next) {
|
|
37
|
+
var _a, _b;
|
|
38
|
+
const { title, filter, sort, fields, except } = ctx.action.params;
|
|
39
|
+
let columns = ((_a = ctx.action.params.values) == null ? void 0 : _a.columns) || ((_b = ctx.action.params) == null ? void 0 : _b.columns);
|
|
40
|
+
if (typeof columns === "string") {
|
|
41
|
+
columns = JSON.parse(columns);
|
|
42
|
+
}
|
|
43
|
+
const repository = ctx.getCurrentRepository();
|
|
44
|
+
const collection = repository.collection;
|
|
45
|
+
columns = columns == null ? void 0 : columns.filter((col) => {
|
|
46
|
+
var _a2;
|
|
47
|
+
return collection.hasField(col.dataIndex[0]) && ((_a2 = col == null ? void 0 : col.dataIndex) == null ? void 0 : _a2.length) > 0;
|
|
48
|
+
});
|
|
49
|
+
const appends = (0, import_utils.columns2Appends)(columns, ctx);
|
|
50
|
+
const data = await repository.find({
|
|
51
|
+
filter,
|
|
52
|
+
fields,
|
|
53
|
+
appends,
|
|
54
|
+
except,
|
|
55
|
+
sort,
|
|
56
|
+
limit: 200,
|
|
57
|
+
context: ctx
|
|
58
|
+
});
|
|
59
|
+
const collectionFields = columns.map((col) => collection.fields.get(col.dataIndex[0]));
|
|
60
|
+
const { rows, ranges } = await (0, import_renders.default)({ columns, fields: collectionFields, data }, ctx);
|
|
61
|
+
ctx.body = import_node_xlsx.default.build([
|
|
62
|
+
{
|
|
63
|
+
name: "Sheet 1",
|
|
64
|
+
data: rows,
|
|
65
|
+
options: {
|
|
66
|
+
"!merges": ranges
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
]);
|
|
70
|
+
ctx.set({
|
|
71
|
+
"Content-Type": "application/octet-stream",
|
|
72
|
+
// to avoid "invalid character" error in header (RFC)
|
|
73
|
+
"Content-Disposition": `attachment; filename=${encodeURI(title)}.xlsx`
|
|
74
|
+
});
|
|
75
|
+
await next();
|
|
76
|
+
}
|
|
77
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
78
|
+
0 && (module.exports = {
|
|
79
|
+
exportXlsx
|
|
80
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './export-xlsx';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var actions_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(actions_exports);
|
|
17
|
+
__reExport(actions_exports, require("./export-xlsx"), module.exports);
|
|
18
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
19
|
+
0 && (module.exports = {
|
|
20
|
+
...require("./export-xlsx")
|
|
21
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { InstallOptions, Plugin } from '@nocobase/server';
|
|
2
|
+
export declare class PluginActionExportServer extends Plugin {
|
|
3
|
+
beforeLoad(): void;
|
|
4
|
+
load(): Promise<void>;
|
|
5
|
+
install(options: InstallOptions): Promise<void>;
|
|
6
|
+
}
|
|
7
|
+
export default PluginActionExportServer;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var server_exports = {};
|
|
19
|
+
__export(server_exports, {
|
|
20
|
+
PluginActionExportServer: () => PluginActionExportServer,
|
|
21
|
+
default: () => server_default
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(server_exports);
|
|
24
|
+
var import_server = require("@nocobase/server");
|
|
25
|
+
var import_actions = require("./actions");
|
|
26
|
+
class PluginActionExportServer extends import_server.Plugin {
|
|
27
|
+
beforeLoad() {
|
|
28
|
+
}
|
|
29
|
+
async load() {
|
|
30
|
+
this.app.dataSourceManager.afterAddDataSource((dataSource) => {
|
|
31
|
+
var _a;
|
|
32
|
+
if (!((_a = dataSource.collectionManager) == null ? void 0 : _a.db)) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
dataSource.resourceManager.registerActionHandler("export", import_actions.exportXlsx);
|
|
36
|
+
dataSource.acl.setAvailableAction("export", {
|
|
37
|
+
displayName: '{{t("Export")}}',
|
|
38
|
+
allowConfigureFields: true
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
async install(options) {
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
var server_default = PluginActionExportServer;
|
|
46
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
47
|
+
0 && (module.exports = {
|
|
48
|
+
PluginActionExportServer
|
|
49
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var change_locale_module_exports = {};
|
|
19
|
+
__export(change_locale_module_exports, {
|
|
20
|
+
default: () => change_locale_module_default
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(change_locale_module_exports);
|
|
23
|
+
var import_server = require("@nocobase/server");
|
|
24
|
+
class change_locale_module_default extends import_server.Migration {
|
|
25
|
+
on = "afterLoad";
|
|
26
|
+
// 'beforeLoad' or 'afterLoad'
|
|
27
|
+
appVersion = "<1.0.0-alpha.1";
|
|
28
|
+
async up() {
|
|
29
|
+
const repo = this.db.getRepository("localizationTexts");
|
|
30
|
+
if (!repo) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
await repo.update({
|
|
34
|
+
filter: {
|
|
35
|
+
module: "resources.export"
|
|
36
|
+
},
|
|
37
|
+
values: {
|
|
38
|
+
module: "resources.action-export"
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var renders_exports = {};
|
|
29
|
+
__export(renders_exports, {
|
|
30
|
+
default: () => renders_default
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(renders_exports);
|
|
33
|
+
var renders = __toESM(require("./renders"));
|
|
34
|
+
function getInterfaceRender(name) {
|
|
35
|
+
return renders[name] || renders._;
|
|
36
|
+
}
|
|
37
|
+
function renderHeader(params, ctx) {
|
|
38
|
+
const { columns, fields, headers = [], rowIndex = 0 } = params;
|
|
39
|
+
const { colIndex = 0 } = params;
|
|
40
|
+
if (!headers[rowIndex]) {
|
|
41
|
+
headers.push([]);
|
|
42
|
+
}
|
|
43
|
+
const row = headers[rowIndex];
|
|
44
|
+
fields.forEach((field, i) => {
|
|
45
|
+
const nextColIndex = colIndex + i;
|
|
46
|
+
row.push({
|
|
47
|
+
column: columns[i],
|
|
48
|
+
field,
|
|
49
|
+
rowIndex,
|
|
50
|
+
colIndex: nextColIndex
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
Object.assign(params, { headers });
|
|
54
|
+
}
|
|
55
|
+
async function renderRows({ columns, fields, data }, ctx) {
|
|
56
|
+
return await data.reduce(async (preResult, row) => {
|
|
57
|
+
const result = await preResult;
|
|
58
|
+
const thisRow = [];
|
|
59
|
+
const rowIndex = 0;
|
|
60
|
+
let colOffset = 0;
|
|
61
|
+
for (let i = 0, iLen = fields.length; i < iLen; i++) {
|
|
62
|
+
const field = fields[i];
|
|
63
|
+
if (!thisRow[rowIndex]) {
|
|
64
|
+
thisRow.push([]);
|
|
65
|
+
}
|
|
66
|
+
const cells = thisRow[rowIndex];
|
|
67
|
+
if (field.options.interface !== "subTable") {
|
|
68
|
+
const render = getInterfaceRender(field.options.interface);
|
|
69
|
+
const value = await render(field, row, ctx, columns[i]);
|
|
70
|
+
cells.push({
|
|
71
|
+
value,
|
|
72
|
+
rowIndex: result.length + rowIndex,
|
|
73
|
+
colIndex: i + colOffset
|
|
74
|
+
});
|
|
75
|
+
} else {
|
|
76
|
+
const subTable = ctx.db.getTable(field.target);
|
|
77
|
+
const subFields = subTable.getOptions().fields.filter((item) => Boolean(item.__index));
|
|
78
|
+
const subTableColumns = [];
|
|
79
|
+
const subRows = await renderRows(
|
|
80
|
+
{ columns: subTableColumns, fields: subFields, data: row.get(field.name) || [] },
|
|
81
|
+
ctx
|
|
82
|
+
);
|
|
83
|
+
subRows.forEach((cells2, j) => {
|
|
84
|
+
const subRowIndex = rowIndex + j;
|
|
85
|
+
if (!thisRow[subRowIndex]) {
|
|
86
|
+
thisRow.push([]);
|
|
87
|
+
}
|
|
88
|
+
const subCells = thisRow[subRowIndex];
|
|
89
|
+
subCells.push(
|
|
90
|
+
...cells2.map((cell) => ({
|
|
91
|
+
...cell,
|
|
92
|
+
rowIndex: result.length + subRowIndex,
|
|
93
|
+
colIndex: cell.colIndex + i
|
|
94
|
+
}))
|
|
95
|
+
);
|
|
96
|
+
});
|
|
97
|
+
colOffset += subFields.length;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
thisRow.forEach((cells) => {
|
|
101
|
+
cells.forEach((cell) => {
|
|
102
|
+
const relRowIndex = cell.rowIndex - result.length;
|
|
103
|
+
Object.assign(cell, {
|
|
104
|
+
rowSpan: relRowIndex >= thisRow.length - 1 || thisRow[relRowIndex + 1].find((item) => item.colIndex === cell.colIndex) ? 1 : thisRow.length - relRowIndex
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
return result.concat(thisRow);
|
|
109
|
+
}, Promise.resolve([]));
|
|
110
|
+
}
|
|
111
|
+
async function renders_default({ columns, fields, data }, ctx) {
|
|
112
|
+
const headers = [];
|
|
113
|
+
renderHeader({ columns, fields, headers }, ctx);
|
|
114
|
+
const ranges = [];
|
|
115
|
+
const maxColIndex = Math.max(...headers.map((row) => row[row.length - 1].colIndex));
|
|
116
|
+
headers.forEach((row, rowIndex) => {
|
|
117
|
+
row.forEach((cell, cellIndex) => {
|
|
118
|
+
cell.rowSpan = cell.rowIndex >= headers.length - 1 || headers[cell.rowIndex + 1].find((item) => item.colIndex === cell.colIndex) ? 1 : headers.length - cell.rowIndex;
|
|
119
|
+
const nextCell = headers.slice(0, rowIndex + 1).map((r) => r.find((item) => item.colIndex > cell.colIndex)).filter((c) => Boolean(c)).reduce((min, c) => min && Math.min(min.colIndex, c.colIndex) === min.colIndex ? min : c, null);
|
|
120
|
+
cell.colSpan = nextCell ? nextCell.colIndex - cell.colIndex : maxColIndex - cell.colIndex + 1;
|
|
121
|
+
if (cell.rowSpan > 1 || cell.colSpan > 1) {
|
|
122
|
+
ranges.push({
|
|
123
|
+
s: { c: cell.colIndex, r: cell.rowIndex },
|
|
124
|
+
e: { c: cell.colIndex + cell.colSpan - 1, r: cell.rowIndex + cell.rowSpan - 1 }
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
const rows = (await renderRows({ columns, fields, data }, ctx)).map((row) => {
|
|
130
|
+
const cells = Array(maxColIndex).fill(null);
|
|
131
|
+
row.forEach((cell) => {
|
|
132
|
+
cells.splice(cell.colIndex, 1, cell.value);
|
|
133
|
+
if (cell.rowSpan > 1) {
|
|
134
|
+
ranges.push({
|
|
135
|
+
s: { c: cell.colIndex, r: cell.rowIndex + headers.length },
|
|
136
|
+
e: { c: cell.colIndex, r: cell.rowIndex + cell.rowSpan - 1 + headers.length }
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
return cells;
|
|
141
|
+
});
|
|
142
|
+
return {
|
|
143
|
+
rows: [
|
|
144
|
+
...headers.map((row) => {
|
|
145
|
+
const cells = Array(maxColIndex).fill(null);
|
|
146
|
+
row.forEach(
|
|
147
|
+
(cell) => cells.splice(
|
|
148
|
+
cell.colIndex,
|
|
149
|
+
1,
|
|
150
|
+
cell.column.title ?? cell.column.defaultTitle ?? cell.column.dataIndex[cell.column.dataIndex.length - 1]
|
|
151
|
+
)
|
|
152
|
+
);
|
|
153
|
+
return cells;
|
|
154
|
+
}),
|
|
155
|
+
...rows
|
|
156
|
+
],
|
|
157
|
+
ranges
|
|
158
|
+
};
|
|
159
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare function _(field: any, row: any, ctx: any, column?: any): Promise<any>;
|
|
2
|
+
export declare function datetime(field: any, row: any, ctx: any): Promise<any>;
|
|
3
|
+
export declare function percent(field: any, row: any, ctx: any): Promise<string>;
|
|
4
|
+
export declare function boolean(field: any, row: any, ctx: any, column?: any): Promise<any>;
|
|
5
|
+
export declare const checkbox: typeof boolean;
|
|
6
|
+
export declare function select(field: any, row: any, ctx: any, column?: any): Promise<any>;
|
|
7
|
+
export declare function multipleSelect(field: any, row: any, ctx: any, column?: any): Promise<any>;
|
|
8
|
+
export declare const radio: typeof select;
|
|
9
|
+
export declare const radioGroup: typeof select;
|
|
10
|
+
export declare const checkboxes: typeof multipleSelect;
|
|
11
|
+
export declare const checkboxGroup: typeof multipleSelect;
|
|
12
|
+
export declare function subTable(field: any, row: any, ctx: any): Promise<any>;
|
|
13
|
+
export declare function linkTo(field: any, row: any, ctx: any, column?: any): Promise<any>;
|
|
14
|
+
export declare function attachment(field: any, row: any, ctx: any): Promise<any>;
|
|
15
|
+
export declare function chinaRegion(field: any, row: any, ctx: any, column?: any): Promise<string>;
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var renders_exports = {};
|
|
19
|
+
__export(renders_exports, {
|
|
20
|
+
_: () => _,
|
|
21
|
+
attachment: () => attachment,
|
|
22
|
+
boolean: () => boolean,
|
|
23
|
+
checkbox: () => checkbox,
|
|
24
|
+
checkboxGroup: () => checkboxGroup,
|
|
25
|
+
checkboxes: () => checkboxes,
|
|
26
|
+
chinaRegion: () => chinaRegion,
|
|
27
|
+
datetime: () => datetime,
|
|
28
|
+
linkTo: () => linkTo,
|
|
29
|
+
multipleSelect: () => multipleSelect,
|
|
30
|
+
percent: () => percent,
|
|
31
|
+
radio: () => radio,
|
|
32
|
+
radioGroup: () => radioGroup,
|
|
33
|
+
select: () => select,
|
|
34
|
+
subTable: () => subTable
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(renders_exports);
|
|
37
|
+
var import_utils = require("@nocobase/utils");
|
|
38
|
+
async function _(field, row, ctx, column) {
|
|
39
|
+
if ((column == null ? void 0 : column.dataIndex.length) > 1) {
|
|
40
|
+
const result = column.dataIndex.reduce((result2, col) => {
|
|
41
|
+
if (Array.isArray(result2)) {
|
|
42
|
+
const subResults = [];
|
|
43
|
+
for (const r of result2) {
|
|
44
|
+
subResults.push(r == null ? void 0 : r[col]);
|
|
45
|
+
}
|
|
46
|
+
return subResults;
|
|
47
|
+
} else {
|
|
48
|
+
if (Array.isArray(result2 == null ? void 0 : result2[col])) {
|
|
49
|
+
const subResults = [];
|
|
50
|
+
if (!(result2 == null ? void 0 : result2[col])) {
|
|
51
|
+
return subResults;
|
|
52
|
+
}
|
|
53
|
+
for (const r of result2[col]) {
|
|
54
|
+
subResults.push(r);
|
|
55
|
+
}
|
|
56
|
+
return subResults;
|
|
57
|
+
} else {
|
|
58
|
+
return result2 == null ? void 0 : result2[col];
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}, row);
|
|
62
|
+
if (Array.isArray(result)) {
|
|
63
|
+
return result.join(",");
|
|
64
|
+
} else {
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
return row.get(field.name);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
async function datetime(field, row, ctx) {
|
|
72
|
+
var _a, _b;
|
|
73
|
+
const value = row.get(field.name);
|
|
74
|
+
if (!value) {
|
|
75
|
+
return "";
|
|
76
|
+
}
|
|
77
|
+
const utcOffset = ctx.get("X-Timezone");
|
|
78
|
+
const props = ((_b = (_a = field.options) == null ? void 0 : _a.uiSchema) == null ? void 0 : _b["x-component-props"]) ?? {};
|
|
79
|
+
const format = (0, import_utils.getDefaultFormat)(props);
|
|
80
|
+
const m = (0, import_utils.str2moment)(value, { ...props, utcOffset });
|
|
81
|
+
return m ? m.format(format) : "";
|
|
82
|
+
}
|
|
83
|
+
async function percent(field, row, ctx) {
|
|
84
|
+
var _a, _b, _c;
|
|
85
|
+
const value = row.get(field.name);
|
|
86
|
+
const step = ((_c = (_b = (_a = field.options) == null ? void 0 : _a.uiSchema) == null ? void 0 : _b["x-component-props"]) == null ? void 0 : _c["step"]) ?? 0;
|
|
87
|
+
return value && `${(0, import_utils.toFixedByStep)(value * 100, step)}%`;
|
|
88
|
+
}
|
|
89
|
+
async function boolean(field, row, ctx, column) {
|
|
90
|
+
const value = row.get(field.name);
|
|
91
|
+
const { enum: enumData } = column ?? {};
|
|
92
|
+
if ((enumData == null ? void 0 : enumData.length) > 0) {
|
|
93
|
+
const option = enumData.find((item) => item.value === value);
|
|
94
|
+
return option == null ? void 0 : option.label;
|
|
95
|
+
} else {
|
|
96
|
+
return value ? "\u662F" : value === null || value === void 0 ? "" : "\u5426";
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const checkbox = boolean;
|
|
100
|
+
async function select(field, row, ctx, column) {
|
|
101
|
+
const value = row.get(field.name);
|
|
102
|
+
let { enum: enumData } = column ?? {};
|
|
103
|
+
if (!enumData) {
|
|
104
|
+
const repository = ctx.db.getCollection("uiSchemas").repository;
|
|
105
|
+
const model = await repository.findById(field.options.uiSchemaUid);
|
|
106
|
+
enumData = model.get("enum");
|
|
107
|
+
}
|
|
108
|
+
const option = enumData.find((item) => item.value === value);
|
|
109
|
+
return option == null ? void 0 : option.label;
|
|
110
|
+
}
|
|
111
|
+
async function multipleSelect(field, row, ctx, column) {
|
|
112
|
+
var _a;
|
|
113
|
+
const values = row.get(field.name);
|
|
114
|
+
let { enum: enumData } = column ?? {};
|
|
115
|
+
if (!enumData) {
|
|
116
|
+
const repository = ctx.db.getCollection("uiSchemas").repository;
|
|
117
|
+
const model = await repository.findById(field.options.uiSchemaUid);
|
|
118
|
+
enumData = model.get("enum");
|
|
119
|
+
}
|
|
120
|
+
return (_a = values == null ? void 0 : values.map((value) => {
|
|
121
|
+
const option = enumData.find((item) => item.value === value);
|
|
122
|
+
return option == null ? void 0 : option.label;
|
|
123
|
+
})) == null ? void 0 : _a.join();
|
|
124
|
+
}
|
|
125
|
+
const radio = select;
|
|
126
|
+
const radioGroup = select;
|
|
127
|
+
const checkboxes = multipleSelect;
|
|
128
|
+
const checkboxGroup = multipleSelect;
|
|
129
|
+
async function subTable(field, row, ctx) {
|
|
130
|
+
return (row.get(field.name) || []).map((item) => item[field.sourceKey]);
|
|
131
|
+
}
|
|
132
|
+
async function linkTo(field, row, ctx, column) {
|
|
133
|
+
return (row.get(field.name) || []).map((item) => {
|
|
134
|
+
return column.dataIndex.reduce((buf, cur) => {
|
|
135
|
+
buf = item[cur];
|
|
136
|
+
return buf;
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
async function attachment(field, row, ctx) {
|
|
141
|
+
return (row.get(field.name) || []).map((item) => item[field.url]).join(" ");
|
|
142
|
+
}
|
|
143
|
+
async function chinaRegion(field, row, ctx, column) {
|
|
144
|
+
const value = row.get(field.name);
|
|
145
|
+
const values = (Array.isArray(value) ? value : [value]).sort(
|
|
146
|
+
(a, b) => a.level !== b.level ? a.level - b.level : a.sort - b.sort
|
|
147
|
+
);
|
|
148
|
+
return values.map((item) => item.name).join("/");
|
|
149
|
+
}
|
|
150
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
151
|
+
0 && (module.exports = {
|
|
152
|
+
_,
|
|
153
|
+
attachment,
|
|
154
|
+
boolean,
|
|
155
|
+
checkbox,
|
|
156
|
+
checkboxGroup,
|
|
157
|
+
checkboxes,
|
|
158
|
+
chinaRegion,
|
|
159
|
+
datetime,
|
|
160
|
+
linkTo,
|
|
161
|
+
multipleSelect,
|
|
162
|
+
percent,
|
|
163
|
+
radio,
|
|
164
|
+
radioGroup,
|
|
165
|
+
select,
|
|
166
|
+
subTable
|
|
167
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function columns2Appends(columns: any, ctx: any): any[];
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var columns2Appends_exports = {};
|
|
19
|
+
__export(columns2Appends_exports, {
|
|
20
|
+
columns2Appends: () => columns2Appends
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(columns2Appends_exports);
|
|
23
|
+
function columns2Appends(columns, ctx) {
|
|
24
|
+
const { resourceName } = ctx.action;
|
|
25
|
+
const appends = /* @__PURE__ */ new Set([]);
|
|
26
|
+
for (const column of columns) {
|
|
27
|
+
let collection = ctx.dataSource.collectionManager.getCollection(resourceName);
|
|
28
|
+
const appendColumns = [];
|
|
29
|
+
for (let i = 0, iLen = column.dataIndex.length; i < iLen; i++) {
|
|
30
|
+
const field = collection.getField(column.dataIndex[i]);
|
|
31
|
+
if (field == null ? void 0 : field.target) {
|
|
32
|
+
appendColumns.push(column.dataIndex[i]);
|
|
33
|
+
collection = ctx.dataSource.collectionManager.getCollection(field.target);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (appendColumns.length > 0) {
|
|
37
|
+
appends.add(appendColumns.join("."));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return Array.from(appends);
|
|
41
|
+
}
|
|
42
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
43
|
+
0 && (module.exports = {
|
|
44
|
+
columns2Appends
|
|
45
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './columns2Appends';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var utils_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(utils_exports);
|
|
17
|
+
__reExport(utils_exports, require("./columns2Appends"), module.exports);
|
|
18
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
19
|
+
0 && (module.exports = {
|
|
20
|
+
...require("./columns2Appends")
|
|
21
|
+
});
|