@nocobase/plugin-map 0.8.1-alpha.3

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 (104) hide show
  1. package/LICENSE +201 -0
  2. package/client.d.ts +4 -0
  3. package/client.js +30 -0
  4. package/lib/client/components/AMap.d.ts +13 -0
  5. package/lib/client/components/AMap.js +502 -0
  6. package/lib/client/components/Configuration.d.ts +2 -0
  7. package/lib/client/components/Configuration.js +167 -0
  8. package/lib/client/components/Designer.d.ts +2 -0
  9. package/lib/client/components/Designer.js +308 -0
  10. package/lib/client/components/Map.d.ts +6 -0
  11. package/lib/client/components/Map.js +65 -0
  12. package/lib/client/components/ReadPretty.d.ts +2 -0
  13. package/lib/client/components/ReadPretty.js +81 -0
  14. package/lib/client/components/Search.d.ts +6 -0
  15. package/lib/client/components/Search.js +155 -0
  16. package/lib/client/constants.d.ts +4 -0
  17. package/lib/client/constants.js +17 -0
  18. package/lib/client/fields/circle.d.ts +2 -0
  19. package/lib/client/fields/circle.js +37 -0
  20. package/lib/client/fields/index.d.ts +2 -0
  21. package/lib/client/fields/index.js +22 -0
  22. package/lib/client/fields/lineString.d.ts +2 -0
  23. package/lib/client/fields/lineString.js +37 -0
  24. package/lib/client/fields/point.d.ts +2 -0
  25. package/lib/client/fields/point.js +37 -0
  26. package/lib/client/fields/polygon.d.ts +2 -0
  27. package/lib/client/fields/polygon.js +37 -0
  28. package/lib/client/fields/schema.d.ts +99 -0
  29. package/lib/client/fields/schema.js +79 -0
  30. package/lib/client/hooks/index.d.ts +1 -0
  31. package/lib/client/hooks/index.js +18 -0
  32. package/lib/client/hooks/useMapConfiguration.d.ts +2 -0
  33. package/lib/client/hooks/useMapConfiguration.js +33 -0
  34. package/lib/client/index.d.ts +3 -0
  35. package/lib/client/index.js +80 -0
  36. package/lib/client/initialize.d.ts +4 -0
  37. package/lib/client/initialize.js +67 -0
  38. package/lib/client/locales/en-US.d.ts +2 -0
  39. package/lib/client/locales/en-US.js +9 -0
  40. package/lib/client/locales/index.d.ts +4 -0
  41. package/lib/client/locales/index.js +56 -0
  42. package/lib/client/locales/zh-CN.d.ts +43 -0
  43. package/lib/client/locales/zh-CN.js +51 -0
  44. package/lib/index.d.ts +1 -0
  45. package/lib/index.js +15 -0
  46. package/lib/server/actions/index.d.ts +3 -0
  47. package/lib/server/actions/index.js +66 -0
  48. package/lib/server/collections/mapConfiguration.d.ts +3 -0
  49. package/lib/server/collections/mapConfiguration.js +30 -0
  50. package/lib/server/constants.d.ts +1 -0
  51. package/lib/server/constants.js +8 -0
  52. package/lib/server/fields/circle.d.ts +13 -0
  53. package/lib/server/fields/circle.js +84 -0
  54. package/lib/server/fields/index.d.ts +4 -0
  55. package/lib/server/fields/index.js +57 -0
  56. package/lib/server/fields/lineString.d.ts +13 -0
  57. package/lib/server/fields/lineString.js +91 -0
  58. package/lib/server/fields/point.d.ts +13 -0
  59. package/lib/server/fields/point.js +95 -0
  60. package/lib/server/fields/polygon.d.ts +13 -0
  61. package/lib/server/fields/polygon.js +89 -0
  62. package/lib/server/helpers/index.d.ts +6 -0
  63. package/lib/server/helpers/index.js +44 -0
  64. package/lib/server/index.d.ts +1 -0
  65. package/lib/server/index.js +15 -0
  66. package/lib/server/plugin.d.ts +11 -0
  67. package/lib/server/plugin.js +88 -0
  68. package/package.json +19 -0
  69. package/server.d.ts +4 -0
  70. package/server.js +30 -0
  71. package/src/client/components/AMap.tsx +369 -0
  72. package/src/client/components/Configuration.tsx +91 -0
  73. package/src/client/components/Designer.tsx +260 -0
  74. package/src/client/components/Map.tsx +29 -0
  75. package/src/client/components/ReadPretty.tsx +34 -0
  76. package/src/client/components/Search.tsx +93 -0
  77. package/src/client/constants.ts +6 -0
  78. package/src/client/fields/circle.ts +23 -0
  79. package/src/client/fields/index.ts +16 -0
  80. package/src/client/fields/lineString.ts +23 -0
  81. package/src/client/fields/point.ts +24 -0
  82. package/src/client/fields/polygon.ts +23 -0
  83. package/src/client/fields/schema.ts +57 -0
  84. package/src/client/hooks/index.ts +1 -0
  85. package/src/client/hooks/useMapConfiguration.ts +15 -0
  86. package/src/client/index.tsx +43 -0
  87. package/src/client/initialize.tsx +33 -0
  88. package/src/client/locales/en-US.ts +5 -0
  89. package/src/client/locales/index.ts +22 -0
  90. package/src/client/locales/zh-CN.ts +45 -0
  91. package/src/index.ts +1 -0
  92. package/src/server/__tests__/fields.test.ts +168 -0
  93. package/src/server/actions/index.ts +46 -0
  94. package/src/server/collections/mapConfiguration.ts +27 -0
  95. package/src/server/constants.ts +1 -0
  96. package/src/server/fields/.gitkeep +0 -0
  97. package/src/server/fields/circle.ts +50 -0
  98. package/src/server/fields/index.ts +4 -0
  99. package/src/server/fields/lineString.ts +56 -0
  100. package/src/server/fields/point.ts +59 -0
  101. package/src/server/fields/polygon.ts +56 -0
  102. package/src/server/helpers/index.ts +25 -0
  103. package/src/server/index.ts +1 -0
  104. package/src/server/plugin.ts +46 -0
@@ -0,0 +1,43 @@
1
+ declare const locale: {
2
+ 'Map-based geometry': string;
3
+ 'Map type': string;
4
+ Point: string;
5
+ Line: string;
6
+ Circle: string;
7
+ Polygon: string;
8
+ 'Access key': string;
9
+ 'securityJsCode or serviceHost': string;
10
+ AMap: string;
11
+ 'Google Maps': string;
12
+ Clear: string;
13
+ 'Click to select the starting point and double-click to end the drawing': string;
14
+ 'Clear the canvas': string;
15
+ 'Are you sure to clear the canvas?': string;
16
+ Confirm: string;
17
+ Cancel: string;
18
+ 'Enter keywords to search': string;
19
+ 'The AccessKey is incorrect, please check it': string;
20
+ 'Please configure the AMap securityCode or serviceHost correctly': string;
21
+ 'Map Manager': string;
22
+ Configuration: string;
23
+ 'Saved successfully': string;
24
+ 'Saved failed': string;
25
+ Edit: string;
26
+ Save: string;
27
+ 'Please configure the AccessKey and SecurityJsCode first': string;
28
+ 'Go to the configuration page': string;
29
+ Zoom: string;
30
+ 'Set default zoom level': string;
31
+ 'The default zoom level of the map': string;
32
+ 'Edit field title': string;
33
+ 'Field title': string;
34
+ 'Edit tooltip': string;
35
+ 'Delete field': string;
36
+ Required: string;
37
+ Pattern: string;
38
+ Editable: string;
39
+ Readonly: string;
40
+ "Easy-reading": string;
41
+ "Edit description": string;
42
+ };
43
+ export default locale;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ const locale = {
8
+ 'Map-based geometry': '基于地图的几何图形',
9
+ 'Map type': '地图类型',
10
+ 'Point': '点',
11
+ 'Line': '线',
12
+ 'Circle': '圆',
13
+ 'Polygon': '多边形',
14
+ 'Access key': '访问密钥',
15
+ 'securityJsCode or serviceHost': 'securityJsCode 或 serviceHost',
16
+ 'AMap': '高德地图',
17
+ 'Google Maps': '谷歌地图',
18
+ 'Clear': '清空',
19
+ 'Click to select the starting point and double-click to end the drawing': '点击选择起点,双击结束绘制',
20
+ 'Clear the canvas': '清空画布',
21
+ 'Are you sure to clear the canvas?': '您确定要清空画布吗?',
22
+ 'Confirm': '确定',
23
+ 'Cancel': '取消',
24
+ 'Enter keywords to search': '输入地方名关键字搜索(必须包含省/市)',
25
+ 'The AccessKey is incorrect, please check it': '访问密钥不正确,请检查',
26
+ 'Please configure the AMap securityCode or serviceHost correctly': '请正确配置高德地图 securityCode 或 serviceHost',
27
+ 'Map Manager': '地图管理',
28
+ 'Configuration': '配置',
29
+ 'Saved successfully': '保存成功',
30
+ 'Saved failed': '保存失败',
31
+ 'Edit': '编辑',
32
+ 'Save': '保存',
33
+ 'Please configure the AccessKey and SecurityJsCode first': '请先配置 AccessKey 和 SecurityJsCode',
34
+ 'Go to the configuration page': '前往配置页面',
35
+ 'Zoom': '缩放',
36
+ 'Set default zoom level': '设置默认缩放级别',
37
+ 'The default zoom level of the map': '地图默认缩放级别',
38
+ // Designer
39
+ 'Edit field title': '编辑字段标题',
40
+ 'Field title': '字段标题',
41
+ 'Edit tooltip': '编辑提示信息',
42
+ 'Delete field': '删除字段',
43
+ "Required": "必填",
44
+ 'Pattern': '模式',
45
+ "Editable": "可编辑",
46
+ "Readonly": "只读(禁止编辑)",
47
+ "Easy-reading": "只读(阅读模式)",
48
+ "Edit description": "编辑描述"
49
+ };
50
+ var _default = locale;
51
+ exports.default = _default;
package/lib/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { default } from './server';
package/lib/index.js ADDED
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "default", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _server.default;
10
+ }
11
+ });
12
+
13
+ var _server = _interopRequireDefault(require("./server"));
14
+
15
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -0,0 +1,3 @@
1
+ import { Context } from '@nocobase/actions';
2
+ export declare const getConfiguration: (ctx: Context, next: any) => Promise<any>;
3
+ export declare const setConfiguration: (ctx: Context, next: any) => Promise<any>;
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.setConfiguration = exports.getConfiguration = void 0;
7
+
8
+ var _constants = require("../constants");
9
+
10
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
11
+
12
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
13
+
14
+ const getConfiguration = /*#__PURE__*/function () {
15
+ var _ref = _asyncToGenerator(function* (ctx, next) {
16
+ const type = ctx.action.params.type;
17
+ const repo = ctx.db.getRepository(_constants.MapConfigurationCollectionName);
18
+ const record = yield repo.findOne({
19
+ filter: {
20
+ type
21
+ }
22
+ });
23
+ ctx.body = record;
24
+ return next();
25
+ });
26
+
27
+ return function getConfiguration(_x, _x2) {
28
+ return _ref.apply(this, arguments);
29
+ };
30
+ }();
31
+
32
+ exports.getConfiguration = getConfiguration;
33
+
34
+ const setConfiguration = /*#__PURE__*/function () {
35
+ var _ref2 = _asyncToGenerator(function* (ctx, next) {
36
+ const values = ctx.action.params;
37
+ const repo = ctx.db.getRepository(_constants.MapConfigurationCollectionName);
38
+ const record = yield repo.findOne({
39
+ filter: {
40
+ type: values.type
41
+ }
42
+ });
43
+
44
+ if (record) {
45
+ yield repo.update({
46
+ values,
47
+ filter: {
48
+ type: values.type
49
+ }
50
+ });
51
+ } else {
52
+ yield repo.create({
53
+ values
54
+ });
55
+ }
56
+
57
+ ctx.body = 'ok';
58
+ return next();
59
+ });
60
+
61
+ return function setConfiguration(_x3, _x4) {
62
+ return _ref2.apply(this, arguments);
63
+ };
64
+ }();
65
+
66
+ exports.setConfiguration = setConfiguration;
@@ -0,0 +1,3 @@
1
+ import { CollectionOptions } from "@nocobase/client";
2
+ declare const _default: CollectionOptions;
3
+ export default _default;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _constants = require("../constants");
9
+
10
+ var _default = {
11
+ name: _constants.MapConfigurationCollectionName,
12
+ title: '{{t("Map Manager")}}',
13
+ fields: [{
14
+ title: 'Access key',
15
+ comment: '访问密钥',
16
+ name: 'accessKey',
17
+ type: 'string'
18
+ }, {
19
+ title: 'securityJsCode',
20
+ comment: 'securityJsCode or serviceHOST',
21
+ name: 'securityJsCode',
22
+ type: 'string'
23
+ }, {
24
+ title: 'Map type',
25
+ comment: '地图类型',
26
+ name: 'type',
27
+ type: 'string'
28
+ }]
29
+ };
30
+ exports.default = _default;
@@ -0,0 +1 @@
1
+ export declare const MapConfigurationCollectionName = "mapConfiguration";
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.MapConfigurationCollectionName = void 0;
7
+ const MapConfigurationCollectionName = 'mapConfiguration';
8
+ exports.MapConfigurationCollectionName = MapConfigurationCollectionName;
@@ -0,0 +1,13 @@
1
+ import { BaseColumnFieldOptions, Field, FieldContext } from '@nocobase/database';
2
+ import { DataTypes } from 'sequelize';
3
+ declare class Circle extends DataTypes.ABSTRACT {
4
+ key: string;
5
+ }
6
+ export declare class CircleField extends Field {
7
+ constructor(options?: any, context?: FieldContext);
8
+ get dataType(): typeof Circle;
9
+ }
10
+ export interface CircleFieldOptions extends BaseColumnFieldOptions {
11
+ type: 'circle';
12
+ }
13
+ export {};
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.CircleField = void 0;
7
+
8
+ function _database() {
9
+ const data = require("@nocobase/database");
10
+
11
+ _database = function _database() {
12
+ return data;
13
+ };
14
+
15
+ return data;
16
+ }
17
+
18
+ function _sequelize() {
19
+ const data = require("sequelize");
20
+
21
+ _sequelize = function _sequelize() {
22
+ return data;
23
+ };
24
+
25
+ return data;
26
+ }
27
+
28
+ var _helpers = require("../helpers");
29
+
30
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
31
+
32
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
33
+
34
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
35
+
36
+ class Circle extends _sequelize().DataTypes.ABSTRACT {
37
+ constructor(...args) {
38
+ super(...args);
39
+ this.key = 'Circle';
40
+ }
41
+
42
+ }
43
+
44
+ class CircleField extends _database().Field {
45
+ constructor(options, context) {
46
+ const name = options.name;
47
+ super(_objectSpread({
48
+ get() {
49
+ const value = this.getDataValue(name);
50
+
51
+ if ((0, _helpers.isPg)(context)) {
52
+ if (typeof value === 'string') {
53
+ return (0, _helpers.toValue)(`(${value})`);
54
+ }
55
+
56
+ return value ? [value.x, value.y, value.radius] : null;
57
+ } else {
58
+ return value;
59
+ }
60
+ },
61
+
62
+ set(value) {
63
+ var _value;
64
+
65
+ if (!((_value = value) === null || _value === void 0 ? void 0 : _value.length)) value = null;else if ((0, _helpers.isPg)(context)) {
66
+ value = value.join(',');
67
+ }
68
+ this.setDataValue(name, value);
69
+ }
70
+
71
+ }, options), context);
72
+ }
73
+
74
+ get dataType() {
75
+ if ((0, _helpers.isPg)(this.context)) {
76
+ return Circle;
77
+ } else {
78
+ return _sequelize().DataTypes.JSON;
79
+ }
80
+ }
81
+
82
+ }
83
+
84
+ exports.CircleField = CircleField;
@@ -0,0 +1,4 @@
1
+ export * from './point';
2
+ export * from './lineString';
3
+ export * from './polygon';
4
+ export * from './circle';
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ var _point = require("./point");
8
+
9
+ Object.keys(_point).forEach(function (key) {
10
+ if (key === "default" || key === "__esModule") return;
11
+ if (key in exports && exports[key] === _point[key]) return;
12
+ Object.defineProperty(exports, key, {
13
+ enumerable: true,
14
+ get: function get() {
15
+ return _point[key];
16
+ }
17
+ });
18
+ });
19
+
20
+ var _lineString = require("./lineString");
21
+
22
+ Object.keys(_lineString).forEach(function (key) {
23
+ if (key === "default" || key === "__esModule") return;
24
+ if (key in exports && exports[key] === _lineString[key]) return;
25
+ Object.defineProperty(exports, key, {
26
+ enumerable: true,
27
+ get: function get() {
28
+ return _lineString[key];
29
+ }
30
+ });
31
+ });
32
+
33
+ var _polygon = require("./polygon");
34
+
35
+ Object.keys(_polygon).forEach(function (key) {
36
+ if (key === "default" || key === "__esModule") return;
37
+ if (key in exports && exports[key] === _polygon[key]) return;
38
+ Object.defineProperty(exports, key, {
39
+ enumerable: true,
40
+ get: function get() {
41
+ return _polygon[key];
42
+ }
43
+ });
44
+ });
45
+
46
+ var _circle = require("./circle");
47
+
48
+ Object.keys(_circle).forEach(function (key) {
49
+ if (key === "default" || key === "__esModule") return;
50
+ if (key in exports && exports[key] === _circle[key]) return;
51
+ Object.defineProperty(exports, key, {
52
+ enumerable: true,
53
+ get: function get() {
54
+ return _circle[key];
55
+ }
56
+ });
57
+ });
@@ -0,0 +1,13 @@
1
+ import { BaseColumnFieldOptions, Field, FieldContext } from '@nocobase/database';
2
+ import { DataTypes } from 'sequelize';
3
+ declare class LineString extends DataTypes.ABSTRACT {
4
+ key: string;
5
+ }
6
+ export declare class LineStringField extends Field {
7
+ constructor(options?: any, context?: FieldContext);
8
+ get dataType(): DataTypes.GeometryDataType | typeof LineString;
9
+ }
10
+ export interface LineStringOptions extends BaseColumnFieldOptions {
11
+ type: 'lineString';
12
+ }
13
+ export {};
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.LineStringField = void 0;
7
+
8
+ function _database() {
9
+ const data = require("@nocobase/database");
10
+
11
+ _database = function _database() {
12
+ return data;
13
+ };
14
+
15
+ return data;
16
+ }
17
+
18
+ function _sequelize() {
19
+ const data = require("sequelize");
20
+
21
+ _sequelize = function _sequelize() {
22
+ return data;
23
+ };
24
+
25
+ return data;
26
+ }
27
+
28
+ var _helpers = require("../helpers");
29
+
30
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
31
+
32
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
33
+
34
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
35
+
36
+ class LineString extends _sequelize().DataTypes.ABSTRACT {
37
+ constructor(...args) {
38
+ super(...args);
39
+ this.key = 'Path';
40
+ }
41
+
42
+ }
43
+
44
+ class LineStringField extends _database().Field {
45
+ constructor(options, context) {
46
+ const name = options.name;
47
+ super(_objectSpread({
48
+ get() {
49
+ const value = this.getDataValue(name);
50
+
51
+ if ((0, _helpers.isPg)(context)) {
52
+ return (0, _helpers.toValue)(value);
53
+ } else if ((0, _helpers.isMysql)(context)) {
54
+ return (value === null || value === void 0 ? void 0 : value.coordinates) || null;
55
+ } else {
56
+ return value;
57
+ }
58
+ },
59
+
60
+ set(value) {
61
+ var _value;
62
+
63
+ if (!((_value = value) === null || _value === void 0 ? void 0 : _value.length)) value = null;else if ((0, _helpers.isPg)(context)) {
64
+ value = (0, _helpers.joinComma)(value.map(_helpers.joinComma));
65
+ } else if ((0, _helpers.isMysql)(context)) {
66
+ value = {
67
+ type: 'LineString',
68
+ coordinates: value
69
+ };
70
+ }
71
+ this.setDataValue(name, value);
72
+ }
73
+
74
+ }, options), context);
75
+ }
76
+
77
+ get dataType() {
78
+ if ((0, _helpers.isPg)(this.context)) {
79
+ return LineString;
80
+ }
81
+
82
+ if ((0, _helpers.isMysql)(this.context)) {
83
+ return _sequelize().DataTypes.GEOMETRY('LINESTRING');
84
+ } else {
85
+ return _sequelize().DataTypes.JSON;
86
+ }
87
+ }
88
+
89
+ }
90
+
91
+ exports.LineStringField = LineStringField;
@@ -0,0 +1,13 @@
1
+ import { BaseColumnFieldOptions, Field, FieldContext } from '@nocobase/database';
2
+ import { DataTypes } from 'sequelize';
3
+ declare class Point extends DataTypes.ABSTRACT {
4
+ key: string;
5
+ }
6
+ export declare class PointField extends Field {
7
+ constructor(options?: any, context?: FieldContext);
8
+ get dataType(): typeof Point | DataTypes.GeometryDataType;
9
+ }
10
+ export interface PointFieldOptions extends BaseColumnFieldOptions {
11
+ type: 'point';
12
+ }
13
+ export {};
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.PointField = void 0;
7
+
8
+ function _database() {
9
+ const data = require("@nocobase/database");
10
+
11
+ _database = function _database() {
12
+ return data;
13
+ };
14
+
15
+ return data;
16
+ }
17
+
18
+ function _sequelize() {
19
+ const data = require("sequelize");
20
+
21
+ _sequelize = function _sequelize() {
22
+ return data;
23
+ };
24
+
25
+ return data;
26
+ }
27
+
28
+ var _helpers = require("../helpers");
29
+
30
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
31
+
32
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
33
+
34
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
35
+
36
+ class Point extends _sequelize().DataTypes.ABSTRACT {
37
+ constructor(...args) {
38
+ super(...args);
39
+ this.key = 'Point';
40
+ }
41
+
42
+ }
43
+
44
+ class PointField extends _database().Field {
45
+ constructor(options, context) {
46
+ const name = options.name;
47
+ super(_objectSpread({
48
+ get() {
49
+ const value = this.getDataValue(name);
50
+
51
+ if ((0, _helpers.isPg)(context)) {
52
+ if (typeof value === 'string') {
53
+ return (0, _helpers.toValue)(value);
54
+ }
55
+
56
+ return value ? [value.x, value.y] : null;
57
+ } else if ((0, _helpers.isMysql)(context)) {
58
+ return (value === null || value === void 0 ? void 0 : value.coordinates) || null;
59
+ } else {
60
+ return value;
61
+ }
62
+ },
63
+
64
+ set(value) {
65
+ var _value;
66
+
67
+ if (!((_value = value) === null || _value === void 0 ? void 0 : _value.length)) value = null;else if ((0, _helpers.isPg)(context)) {
68
+ value = (0, _helpers.joinComma)(value);
69
+ } else if ((0, _helpers.isMysql)(context)) {
70
+ value = {
71
+ type: 'Point',
72
+ coordinates: value
73
+ };
74
+ }
75
+ this.setDataValue(name, value);
76
+ }
77
+
78
+ }, options), context);
79
+ }
80
+
81
+ get dataType() {
82
+ if ((0, _helpers.isPg)(this.context)) {
83
+ return Point;
84
+ }
85
+
86
+ if ((0, _helpers.isMysql)(this.context)) {
87
+ return _sequelize().DataTypes.GEOMETRY('POINT');
88
+ } else {
89
+ return _sequelize().DataTypes.JSON;
90
+ }
91
+ }
92
+
93
+ }
94
+
95
+ exports.PointField = PointField;
@@ -0,0 +1,13 @@
1
+ import { BaseColumnFieldOptions, Field, FieldContext } from '@nocobase/database';
2
+ import { DataTypes } from 'sequelize';
3
+ declare class Polygon extends DataTypes.ABSTRACT {
4
+ key: string;
5
+ }
6
+ export declare class PolygonField extends Field {
7
+ constructor(options?: any, context?: FieldContext);
8
+ get dataType(): DataTypes.GeometryDataType | typeof Polygon;
9
+ }
10
+ export interface PolygonFieldOptions extends BaseColumnFieldOptions {
11
+ type: 'polygon';
12
+ }
13
+ export {};