@nocobase/plugin-field-china-region 1.0.0-alpha.9 → 1.0.1-alpha.2
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/dist/externalVersion.js
CHANGED
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
module.exports = {
|
|
11
11
|
"@formily/core": "2.3.0",
|
|
12
12
|
"@formily/react": "2.3.0",
|
|
13
|
-
"@nocobase/client": "1.0.
|
|
14
|
-
"@nocobase/server": "1.0.
|
|
13
|
+
"@nocobase/client": "1.0.1-alpha.2",
|
|
14
|
+
"@nocobase/server": "1.0.1-alpha.2",
|
|
15
15
|
"china-division": "2.7.0",
|
|
16
|
-
"@nocobase/database": "1.0.
|
|
16
|
+
"@nocobase/database": "1.0.1-alpha.2"
|
|
17
17
|
};
|
package/dist/server/index.js
CHANGED
|
@@ -32,6 +32,7 @@ __export(server_exports, {
|
|
|
32
32
|
module.exports = __toCommonJS(server_exports);
|
|
33
33
|
var import_server = require("@nocobase/server");
|
|
34
34
|
var import_path = require("path");
|
|
35
|
+
var import_china_region_interface = require("./interfaces/china-region-interface");
|
|
35
36
|
function getChinaDivisionData(key) {
|
|
36
37
|
try {
|
|
37
38
|
require.resolve(`../china-division/${key}.json`);
|
|
@@ -55,6 +56,7 @@ class PluginFieldChinaRegionServer extends import_server.Plugin {
|
|
|
55
56
|
await next();
|
|
56
57
|
}
|
|
57
58
|
});
|
|
59
|
+
this.app.db.interfaceManager.registerInterfaceType("chinaRegion", import_china_region_interface.ChinaRegionInterface);
|
|
58
60
|
}
|
|
59
61
|
async importData() {
|
|
60
62
|
const areas = getChinaDivisionData("areas");
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
import { BaseInterface } from '@nocobase/database';
|
|
10
|
+
export declare class ChinaRegionInterface extends BaseInterface {
|
|
11
|
+
toValue(str: string, ctx?: any): Promise<any>;
|
|
12
|
+
toString(value: any, ctx?: any): string;
|
|
13
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
+
var china_region_interface_exports = {};
|
|
28
|
+
__export(china_region_interface_exports, {
|
|
29
|
+
ChinaRegionInterface: () => ChinaRegionInterface
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(china_region_interface_exports);
|
|
32
|
+
var import_database = require("@nocobase/database");
|
|
33
|
+
class ChinaRegionInterface extends import_database.BaseInterface {
|
|
34
|
+
async toValue(str, ctx) {
|
|
35
|
+
const { field } = ctx;
|
|
36
|
+
const items = str.split("/");
|
|
37
|
+
const repository = field.database.getRepository(field.target);
|
|
38
|
+
const instances = await repository.find({
|
|
39
|
+
filter: {
|
|
40
|
+
name: items
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
for (let i = 0; i < items.length; i++) {
|
|
44
|
+
const instance = instances.find((item) => item.name === items[i]);
|
|
45
|
+
if (!instance) {
|
|
46
|
+
throw new Error(`china region "${items[i]}" does not exist`);
|
|
47
|
+
}
|
|
48
|
+
items[i] = instance.get("code");
|
|
49
|
+
}
|
|
50
|
+
return items;
|
|
51
|
+
}
|
|
52
|
+
toString(value, ctx) {
|
|
53
|
+
const values = (Array.isArray(value) ? value : [value]).sort(
|
|
54
|
+
(a, b) => a.level !== b.level ? a.level - b.level : a.sort - b.sort
|
|
55
|
+
);
|
|
56
|
+
return values.map((item) => item.name).join("/");
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
60
|
+
0 && (module.exports = {
|
|
61
|
+
ChinaRegionInterface
|
|
62
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/plugin-field-china-region",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1-alpha.2",
|
|
4
4
|
"displayName": "Administrative divisions of China",
|
|
5
5
|
"displayName.zh-CN": "中国行政区划",
|
|
6
6
|
"description": "Provides data and field type for administrative divisions of China.",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"@nocobase/server": "1.x",
|
|
23
23
|
"@nocobase/test": "1.x"
|
|
24
24
|
},
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "fc5a8e3c812516f787cb22d3d198f058f45b1963",
|
|
26
26
|
"keywords": [
|
|
27
27
|
"Fields"
|
|
28
28
|
]
|