@nocobase/plugin-map 0.11.1-alpha.5 → 0.12.0-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.
Files changed (197) hide show
  1. package/client.d.ts +2 -3
  2. package/client.js +1 -1
  3. package/dist/client/index.js +3092 -0
  4. package/{lib → dist}/index.d.ts +1 -0
  5. package/dist/index.js +18 -0
  6. package/dist/locale/en-US.js +6 -0
  7. package/dist/locale/fr-FR.js +6 -0
  8. package/dist/locale/pt-BR.js +51 -0
  9. package/dist/locale/zh-CN.js +54 -0
  10. package/dist/server/actions/index.js +43 -0
  11. package/dist/server/collections/mapConfiguration.js +32 -0
  12. package/dist/server/constants.js +5 -0
  13. package/dist/server/fields/circle.js +47 -0
  14. package/dist/server/fields/index.js +33 -0
  15. package/dist/server/fields/lineString.js +54 -0
  16. package/dist/server/fields/point.js +57 -0
  17. package/dist/server/fields/polygon.js +53 -0
  18. package/dist/server/helpers/index.js +31 -0
  19. package/dist/server/index.js +11 -0
  20. package/dist/server/plugin.js +59 -0
  21. package/dist/server/value-parsers/index.js +53 -0
  22. package/docs/en-US/changelog.md +1 -0
  23. package/docs/en-US/index.md +1 -0
  24. package/docs/en-US/installation.md +1 -0
  25. package/docs/en-US/tabs.json +18 -0
  26. package/docs/en-US/usage.md +1 -0
  27. package/docs/zh-CN/changelog.md +1 -0
  28. package/docs/zh-CN/index.md +1 -0
  29. package/docs/zh-CN/installation.md +1 -0
  30. package/docs/zh-CN/tabs.json +18 -0
  31. package/docs/zh-CN/usage.md +1 -0
  32. package/package.json +19 -30
  33. package/server.d.ts +2 -3
  34. package/server.js +1 -1
  35. package/lib/client/block/MapActionInitializers.js +0 -93
  36. package/lib/client/block/MapBlock.js +0 -38
  37. package/lib/client/block/MapBlockDesigner.js +0 -196
  38. package/lib/client/block/MapBlockInitializer.js +0 -124
  39. package/lib/client/block/MapBlockProvider.js +0 -91
  40. package/lib/client/block/index.js +0 -58
  41. package/lib/client/block/utils.js +0 -102
  42. package/lib/client/components/AMap/Block.js +0 -350
  43. package/lib/client/components/AMap/Map.js +0 -458
  44. package/lib/client/components/AMap/Search.js +0 -121
  45. package/lib/client/components/AMap/index.js +0 -27
  46. package/lib/client/components/Configuration.js +0 -160
  47. package/lib/client/components/Designer.js +0 -167
  48. package/lib/client/components/GoogleMaps/Block.js +0 -370
  49. package/lib/client/components/GoogleMaps/Map.js +0 -466
  50. package/lib/client/components/GoogleMaps/Search.js +0 -128
  51. package/lib/client/components/GoogleMaps/index.js +0 -27
  52. package/lib/client/components/GoogleMaps/utils.js +0 -44
  53. package/lib/client/components/Map.js +0 -50
  54. package/lib/client/components/MapBlock.js +0 -40
  55. package/lib/client/components/MapComponent.js +0 -42
  56. package/lib/client/components/ReadPretty.js +0 -56
  57. package/lib/client/components/index.js +0 -71
  58. package/lib/client/constants.js +0 -19
  59. package/lib/client/fields/circle.js +0 -32
  60. package/lib/client/fields/index.js +0 -17
  61. package/lib/client/fields/lineString.js +0 -32
  62. package/lib/client/fields/point.js +0 -32
  63. package/lib/client/fields/polygon.js +0 -32
  64. package/lib/client/fields/schema.js +0 -64
  65. package/lib/client/hooks/index.js +0 -16
  66. package/lib/client/hooks/useMapConfiguration.js +0 -54
  67. package/lib/client/index.js +0 -73
  68. package/lib/client/initialize.js +0 -50
  69. package/lib/client/locale/index.js +0 -38
  70. package/lib/client/types.js +0 -5
  71. package/lib/client/utils.js +0 -1
  72. package/lib/index.js +0 -13
  73. package/lib/locale/en-US.js +0 -9
  74. package/lib/locale/fr-FR.js +0 -9
  75. package/lib/locale/pt-BR.js +0 -54
  76. package/lib/locale/zh-CN.js +0 -57
  77. package/lib/server/actions/index.js +0 -55
  78. package/lib/server/collections/mapConfiguration.js +0 -30
  79. package/lib/server/constants.js +0 -8
  80. package/lib/server/fields/circle.js +0 -58
  81. package/lib/server/fields/index.js +0 -49
  82. package/lib/server/fields/lineString.js +0 -65
  83. package/lib/server/fields/point.js +0 -68
  84. package/lib/server/fields/polygon.js +0 -64
  85. package/lib/server/helpers/index.js +0 -32
  86. package/lib/server/index.js +0 -13
  87. package/lib/server/plugin.js +0 -79
  88. package/lib/server/value-parsers/index.js +0 -75
  89. package/src/client/block/MapActionInitializers.tsx +0 -97
  90. package/src/client/block/MapBlock.tsx +0 -11
  91. package/src/client/block/MapBlockDesigner.tsx +0 -161
  92. package/src/client/block/MapBlockInitializer.tsx +0 -91
  93. package/src/client/block/MapBlockProvider.tsx +0 -55
  94. package/src/client/block/index.tsx +0 -35
  95. package/src/client/block/utils.ts +0 -81
  96. package/src/client/components/AMap/Block.tsx +0 -314
  97. package/src/client/components/AMap/Map.tsx +0 -461
  98. package/src/client/components/AMap/Search.tsx +0 -92
  99. package/src/client/components/AMap/index.ts +0 -2
  100. package/src/client/components/Configuration.tsx +0 -117
  101. package/src/client/components/Designer.tsx +0 -147
  102. package/src/client/components/GoogleMaps/Block.tsx +0 -341
  103. package/src/client/components/GoogleMaps/Map.tsx +0 -470
  104. package/src/client/components/GoogleMaps/Search.tsx +0 -107
  105. package/src/client/components/GoogleMaps/index.ts +0 -2
  106. package/src/client/components/GoogleMaps/utils.ts +0 -33
  107. package/src/client/components/Map.tsx +0 -33
  108. package/src/client/components/MapBlock.tsx +0 -24
  109. package/src/client/components/MapComponent.tsx +0 -23
  110. package/src/client/components/ReadPretty.tsx +0 -28
  111. package/src/client/components/index.ts +0 -6
  112. package/src/client/constants.ts +0 -11
  113. package/src/client/fields/circle.ts +0 -23
  114. package/src/client/fields/index.ts +0 -11
  115. package/src/client/fields/lineString.ts +0 -23
  116. package/src/client/fields/point.ts +0 -23
  117. package/src/client/fields/polygon.ts +0 -23
  118. package/src/client/fields/schema.ts +0 -54
  119. package/src/client/hooks/index.ts +0 -1
  120. package/src/client/hooks/useMapConfiguration.ts +0 -42
  121. package/src/client/index.tsx +0 -55
  122. package/src/client/initialize.tsx +0 -32
  123. package/src/client/locale/index.ts +0 -19
  124. package/src/client/types.ts +0 -1
  125. package/src/client/utils.ts +0 -0
  126. package/src/index.ts +0 -1
  127. package/src/locale/en-US.ts +0 -3
  128. package/src/locale/fr-FR.ts +0 -3
  129. package/src/locale/pt-BR.ts +0 -51
  130. package/src/locale/zh-CN.ts +0 -52
  131. package/src/server/__tests__/fields.test.ts +0 -157
  132. package/src/server/actions/index.ts +0 -44
  133. package/src/server/collections/mapConfiguration.ts +0 -29
  134. package/src/server/constants.ts +0 -1
  135. package/src/server/fields/.gitkeep +0 -0
  136. package/src/server/fields/circle.ts +0 -48
  137. package/src/server/fields/index.ts +0 -4
  138. package/src/server/fields/lineString.ts +0 -55
  139. package/src/server/fields/point.ts +0 -58
  140. package/src/server/fields/polygon.ts +0 -54
  141. package/src/server/helpers/index.ts +0 -25
  142. package/src/server/index.ts +0 -1
  143. package/src/server/plugin.ts +0 -57
  144. package/src/server/value-parsers/index.ts +0 -55
  145. /package/{lib → dist}/client/block/MapActionInitializers.d.ts +0 -0
  146. /package/{lib → dist}/client/block/MapBlock.d.ts +0 -0
  147. /package/{lib → dist}/client/block/MapBlockDesigner.d.ts +0 -0
  148. /package/{lib → dist}/client/block/MapBlockInitializer.d.ts +0 -0
  149. /package/{lib → dist}/client/block/MapBlockProvider.d.ts +0 -0
  150. /package/{lib → dist}/client/block/index.d.ts +0 -0
  151. /package/{lib → dist}/client/block/utils.d.ts +0 -0
  152. /package/{lib → dist}/client/components/AMap/Block.d.ts +0 -0
  153. /package/{lib → dist}/client/components/AMap/Map.d.ts +0 -0
  154. /package/{lib → dist}/client/components/AMap/Search.d.ts +0 -0
  155. /package/{lib → dist}/client/components/AMap/index.d.ts +0 -0
  156. /package/{lib → dist}/client/components/Configuration.d.ts +0 -0
  157. /package/{lib → dist}/client/components/Designer.d.ts +0 -0
  158. /package/{lib → dist}/client/components/GoogleMaps/Block.d.ts +0 -0
  159. /package/{lib → dist}/client/components/GoogleMaps/Map.d.ts +0 -0
  160. /package/{lib → dist}/client/components/GoogleMaps/Search.d.ts +0 -0
  161. /package/{lib → dist}/client/components/GoogleMaps/index.d.ts +0 -0
  162. /package/{lib → dist}/client/components/GoogleMaps/utils.d.ts +0 -0
  163. /package/{lib → dist}/client/components/Map.d.ts +0 -0
  164. /package/{lib → dist}/client/components/MapBlock.d.ts +0 -0
  165. /package/{lib → dist}/client/components/MapComponent.d.ts +0 -0
  166. /package/{lib → dist}/client/components/ReadPretty.d.ts +0 -0
  167. /package/{lib → dist}/client/components/index.d.ts +0 -0
  168. /package/{lib → dist}/client/constants.d.ts +0 -0
  169. /package/{lib → dist}/client/fields/circle.d.ts +0 -0
  170. /package/{lib → dist}/client/fields/index.d.ts +0 -0
  171. /package/{lib → dist}/client/fields/lineString.d.ts +0 -0
  172. /package/{lib → dist}/client/fields/point.d.ts +0 -0
  173. /package/{lib → dist}/client/fields/polygon.d.ts +0 -0
  174. /package/{lib → dist}/client/fields/schema.d.ts +0 -0
  175. /package/{lib → dist}/client/hooks/index.d.ts +0 -0
  176. /package/{lib → dist}/client/hooks/useMapConfiguration.d.ts +0 -0
  177. /package/{lib → dist}/client/index.d.ts +0 -0
  178. /package/{lib → dist}/client/initialize.d.ts +0 -0
  179. /package/{lib → dist}/client/locale/index.d.ts +0 -0
  180. /package/{lib → dist}/client/types.d.ts +0 -0
  181. /package/{lib → dist}/client/utils.d.ts +0 -0
  182. /package/{lib → dist}/locale/en-US.d.ts +0 -0
  183. /package/{lib → dist}/locale/fr-FR.d.ts +0 -0
  184. /package/{lib → dist}/locale/pt-BR.d.ts +0 -0
  185. /package/{lib → dist}/locale/zh-CN.d.ts +0 -0
  186. /package/{lib → dist}/server/actions/index.d.ts +0 -0
  187. /package/{lib → dist}/server/collections/mapConfiguration.d.ts +0 -0
  188. /package/{lib → dist}/server/constants.d.ts +0 -0
  189. /package/{lib → dist}/server/fields/circle.d.ts +0 -0
  190. /package/{lib → dist}/server/fields/index.d.ts +0 -0
  191. /package/{lib → dist}/server/fields/lineString.d.ts +0 -0
  192. /package/{lib → dist}/server/fields/point.d.ts +0 -0
  193. /package/{lib → dist}/server/fields/polygon.d.ts +0 -0
  194. /package/{lib → dist}/server/helpers/index.d.ts +0 -0
  195. /package/{lib → dist}/server/index.d.ts +0 -0
  196. /package/{lib → dist}/server/plugin.d.ts +0 -0
  197. /package/{lib → dist}/server/value-parsers/index.d.ts +0 -0
@@ -1,64 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.PolygonField = void 0;
7
- function _database() {
8
- const data = require("@nocobase/database");
9
- _database = function _database() {
10
- return data;
11
- };
12
- return data;
13
- }
14
- var _helpers = require("../helpers");
15
- 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; }
16
- 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; }
17
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
18
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
19
- function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
20
- class Polygon extends _database().DataTypes.ABSTRACT {
21
- constructor(...args) {
22
- super(...args);
23
- this.key = 'Polygon';
24
- }
25
- }
26
- class PolygonField extends _database().Field {
27
- constructor(options, context) {
28
- const name = options.name;
29
- super(_objectSpread({
30
- get() {
31
- const value = this.getDataValue(name);
32
- if ((0, _helpers.isPg)(context)) {
33
- return (0, _helpers.toValue)(value);
34
- } else if ((0, _helpers.isMysql)(context)) {
35
- return (value === null || value === void 0 ? void 0 : value.coordinates[0].slice(0, -1)) || null;
36
- } else {
37
- return value;
38
- }
39
- },
40
- set(value) {
41
- var _value;
42
- if (!((_value = value) !== null && _value !== void 0 && _value.length)) value = null;else if ((0, _helpers.isPg)(context)) {
43
- value = (0, _helpers.joinComma)(value.map(item => (0, _helpers.joinComma)(item)));
44
- } else if ((0, _helpers.isMysql)(context)) {
45
- value = {
46
- type: 'Polygon',
47
- coordinates: [value.concat([value[0]])]
48
- };
49
- }
50
- this.setDataValue(name, value);
51
- }
52
- }, options), context);
53
- }
54
- get dataType() {
55
- if ((0, _helpers.isPg)(this.context)) {
56
- return Polygon;
57
- } else if ((0, _helpers.isMysql)(this.context)) {
58
- return _database().DataTypes.GEOMETRY('POLYGON');
59
- } else {
60
- return _database().DataTypes.JSON;
61
- }
62
- }
63
- }
64
- exports.PolygonField = PolygonField;
@@ -1,32 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.toValue = exports.joinComma = exports.isSqlite = exports.isPg = exports.isMysql = exports.getDialect = void 0;
7
- const joinComma = value => {
8
- if (!value) return null;
9
- return `(${value.join(',')})`;
10
- };
11
- exports.joinComma = joinComma;
12
- const toValue = value => {
13
- if (!value) return null;
14
- return JSON.parse(value.replace(/\(/g, '[').replace(/\)/g, ']'));
15
- };
16
- exports.toValue = toValue;
17
- const getDialect = ctx => {
18
- return (ctx.db || ctx.database).sequelize.getDialect();
19
- };
20
- exports.getDialect = getDialect;
21
- const isPg = ctx => {
22
- return getDialect(ctx) === 'postgres';
23
- };
24
- exports.isPg = isPg;
25
- const isSqlite = ctx => {
26
- return getDialect(ctx) === 'sqlite';
27
- };
28
- exports.isSqlite = isSqlite;
29
- const isMysql = ctx => {
30
- return getDialect(ctx) === 'mysql';
31
- };
32
- exports.isMysql = isMysql;
@@ -1,13 +0,0 @@
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 _plugin.default;
10
- }
11
- });
12
- var _plugin = _interopRequireDefault(require("./plugin"));
13
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -1,79 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = exports.MapPlugin = void 0;
7
- function _server() {
8
- const data = require("@nocobase/server");
9
- _server = function _server() {
10
- return data;
11
- };
12
- return data;
13
- }
14
- function _path() {
15
- const data = require("path");
16
- _path = function _path() {
17
- return data;
18
- };
19
- return data;
20
- }
21
- var _actions = require("./actions");
22
- var _fields = require("./fields");
23
- var _valueParsers = require("./value-parsers");
24
- 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); } }
25
- 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); }); }; }
26
- class MapPlugin extends _server().Plugin {
27
- afterAdd() {}
28
- beforeLoad() {
29
- const fields = {
30
- point: _fields.PointField,
31
- polygon: _fields.PolygonField,
32
- lineString: _fields.LineStringField,
33
- circle: _fields.CircleField
34
- };
35
- this.db.registerFieldTypes(fields);
36
- this.db.registerFieldValueParsers({
37
- point: _valueParsers.PointValueParser,
38
- polygon: _valueParsers.PolygonValueParser,
39
- lineString: _valueParsers.LineStringValueParser,
40
- circle: _valueParsers.CircleValueParser
41
- });
42
- }
43
- load() {
44
- var _this = this;
45
- return _asyncToGenerator(function* () {
46
- yield _this.db.import({
47
- directory: (0, _path().resolve)(__dirname, 'collections')
48
- });
49
- _this.app.resource({
50
- name: 'map-configuration',
51
- actions: {
52
- get: _actions.getConfiguration,
53
- set: _actions.setConfiguration
54
- },
55
- only: ['get', 'set']
56
- });
57
- _this.app.acl.registerSnippet({
58
- name: `pm.${_this.name}.configuration`,
59
- actions: ['map-configuration:set']
60
- });
61
- _this.app.acl.allow('map-configuration', 'get', 'loggedIn');
62
- })();
63
- }
64
- install(options) {
65
- return _asyncToGenerator(function* () {})();
66
- }
67
- afterEnable() {
68
- return _asyncToGenerator(function* () {})();
69
- }
70
- afterDisable() {
71
- return _asyncToGenerator(function* () {})();
72
- }
73
- remove() {
74
- return _asyncToGenerator(function* () {})();
75
- }
76
- }
77
- exports.MapPlugin = MapPlugin;
78
- var _default = MapPlugin;
79
- exports.default = _default;
@@ -1,75 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.PolygonValueParser = exports.PointValueParser = exports.LineStringValueParser = exports.CircleValueParser = void 0;
7
- function _database() {
8
- const data = require("@nocobase/database");
9
- _database = function _database() {
10
- return data;
11
- };
12
- return data;
13
- }
14
- 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); } }
15
- 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); }); }; }
16
- class PointValueParser extends _database().BaseValueParser {
17
- setValue(value) {
18
- var _this = this;
19
- return _asyncToGenerator(function* () {
20
- if (Array.isArray(value)) {
21
- _this.value = value;
22
- } else if (typeof value === 'string') {
23
- _this.value = value.split(',');
24
- } else {
25
- _this.errors.push('Value invalid');
26
- }
27
- })();
28
- }
29
- }
30
- exports.PointValueParser = PointValueParser;
31
- class PolygonValueParser extends _database().BaseValueParser {
32
- setValue(value) {
33
- var _this2 = this;
34
- return _asyncToGenerator(function* () {
35
- if (Array.isArray(value)) {
36
- _this2.value = value;
37
- } else if (typeof value === 'string') {
38
- _this2.value = value.substring(1, value.length - 1).split('),(').map(v => v.split(','));
39
- } else {
40
- _this2.errors.push('Value invalid');
41
- }
42
- })();
43
- }
44
- }
45
- exports.PolygonValueParser = PolygonValueParser;
46
- class LineStringValueParser extends _database().BaseValueParser {
47
- setValue(value) {
48
- var _this3 = this;
49
- return _asyncToGenerator(function* () {
50
- if (Array.isArray(value)) {
51
- _this3.value = value;
52
- } else if (typeof value === 'string') {
53
- _this3.value = value.substring(1, value.length - 1).split('),(').map(v => v.split(','));
54
- } else {
55
- _this3.errors.push('Value invalid');
56
- }
57
- })();
58
- }
59
- }
60
- exports.LineStringValueParser = LineStringValueParser;
61
- class CircleValueParser extends _database().BaseValueParser {
62
- setValue(value) {
63
- var _this4 = this;
64
- return _asyncToGenerator(function* () {
65
- if (Array.isArray(value)) {
66
- _this4.value = value;
67
- } else if (typeof value === 'string') {
68
- _this4.value = value.split(',');
69
- } else {
70
- _this4.errors.push('Value invalid');
71
- }
72
- })();
73
- }
74
- }
75
- exports.CircleValueParser = CircleValueParser;
@@ -1,97 +0,0 @@
1
- // 表格操作配置
2
- export const MapActionInitializers = {
3
- title: "{{t('Configure actions')}}",
4
- icon: 'SettingOutlined',
5
- style: {
6
- marginLeft: 8,
7
- },
8
- items: [
9
- {
10
- type: 'itemGroup',
11
- title: "{{t('Enable actions')}}",
12
- children: [
13
- {
14
- type: 'item',
15
- title: "{{t('Filter')}}",
16
- component: 'FilterActionInitializer',
17
- schema: {
18
- 'x-align': 'left',
19
- },
20
- },
21
- {
22
- type: 'item',
23
- title: "{{t('Add new')}}",
24
- component: 'CreateActionInitializer',
25
- schema: {
26
- 'x-align': 'right',
27
- 'x-decorator': 'ACLActionProvider',
28
- 'x-acl-action-props': {
29
- skipScopeCheck: true,
30
- },
31
- },
32
- },
33
- {
34
- type: 'item',
35
- title: "{{t('Refresh')}}",
36
- component: 'RefreshActionInitializer',
37
- schema: {
38
- 'x-align': 'right',
39
- },
40
- },
41
- ],
42
- },
43
- {
44
- type: 'divider',
45
- },
46
- {
47
- type: 'subMenu',
48
- title: '{{t("Customize")}}',
49
- children: [
50
- {
51
- type: 'item',
52
- title: '{{t("Bulk update")}}',
53
- component: 'CustomizeActionInitializer',
54
- schema: {
55
- type: 'void',
56
- title: '{{ t("Bulk update") }}',
57
- 'x-component': 'Action',
58
- 'x-align': 'right',
59
- 'x-acl-action': 'update',
60
- 'x-decorator': 'ACLActionProvider',
61
- 'x-acl-action-props': {
62
- skipScopeCheck: true,
63
- },
64
- 'x-action': 'customize:bulkUpdate',
65
- 'x-designer': 'Action.Designer',
66
- 'x-action-settings': {
67
- assignedValues: {},
68
- updateMode: 'selected',
69
- onSuccess: {
70
- manualClose: true,
71
- redirecting: false,
72
- successMessage: '{{t("Updated successfully")}}',
73
- },
74
- },
75
- 'x-component-props': {
76
- icon: 'EditOutlined',
77
- useProps: '{{ useCustomizeBulkUpdateActionProps }}',
78
- },
79
- },
80
- },
81
- {
82
- type: 'item',
83
- title: '{{t("Bulk edit")}}',
84
- component: 'CustomizeBulkEditActionInitializer',
85
- schema: {
86
- 'x-align': 'right',
87
- 'x-decorator': 'ACLActionProvider',
88
- 'x-acl-action': 'update',
89
- 'x-acl-action-props': {
90
- skipScopeCheck: true,
91
- },
92
- },
93
- },
94
- ],
95
- },
96
- ],
97
- };
@@ -1,11 +0,0 @@
1
- import React, { useState } from 'react';
2
- import { MapBlockComponent } from '../components';
3
- import { useCollection, useProps } from '@nocobase/client';
4
-
5
- export const MapBlock = (props) => {
6
- const { fieldNames } = useProps(props);
7
- const { getField } = useCollection();
8
- const field = getField(fieldNames?.field);
9
- const fieldComponentProps = field?.uiSchema?.['x-component-props'];
10
- return <MapBlockComponent {...fieldComponentProps} {...props} />;
11
- };
@@ -1,161 +0,0 @@
1
- import { ISchema, useField, useFieldSchema } from '@formily/react';
2
- import {
3
- FilterBlockType,
4
- FixedBlockDesignerItem,
5
- GeneralSchemaDesigner,
6
- SchemaSettings,
7
- mergeFilter,
8
- useCollection,
9
- useCollectionFilterOptions,
10
- useCollectionManager,
11
- useDesignable,
12
- useSchemaTemplate,
13
- } from '@nocobase/client';
14
- import { lodash } from '@nocobase/utils/client';
15
- import React from 'react';
16
- import { useTranslation } from 'react-i18next';
17
- import { useMapTranslation } from '../locale';
18
- import { useMapBlockContext } from './MapBlockProvider';
19
-
20
- export const MapBlockDesigner = () => {
21
- const { name, title } = useCollection();
22
- const field = useField();
23
- const fieldSchema = useFieldSchema();
24
- const dataSource = useCollectionFilterOptions(name);
25
- const { service } = useMapBlockContext();
26
- const { t: mapT } = useMapTranslation();
27
- const { t } = useTranslation();
28
- const { dn } = useDesignable();
29
- const { getCollectionFieldsOptions } = useCollectionManager();
30
- const collection = useCollection();
31
- const defaultFilter = fieldSchema?.['x-decorator-props']?.params?.filter || {};
32
- const defaultResource = fieldSchema?.['x-decorator-props']?.resource;
33
- const fieldNames = fieldSchema?.['x-decorator-props']?.['fieldNames'] || {};
34
- const defaultZoom = fieldSchema?.['x-component-props']?.['zoom'] || 13;
35
-
36
- const template = useSchemaTemplate();
37
-
38
- const mapFieldOptions = getCollectionFieldsOptions(collection?.name, ['point', 'lineString', 'polygon']);
39
- const markerFieldOptions = getCollectionFieldsOptions(collection?.name, 'string');
40
-
41
- return (
42
- <GeneralSchemaDesigner template={template} title={title || name}>
43
- <SchemaSettings.BlockTitleItem />
44
- <FixedBlockDesignerItem />
45
- <SchemaSettings.SelectItem
46
- title={mapT('Map field')}
47
- value={fieldNames.field}
48
- options={mapFieldOptions}
49
- onChange={(v) => {
50
- const fieldNames = field.decoratorProps.fieldNames || {};
51
- fieldNames['field'] = v;
52
- field.decoratorProps.fieldNames = fieldNames;
53
- fieldSchema['x-decorator-props']['fieldNames'] = fieldNames;
54
- service.refresh();
55
- dn.emit('patch', {
56
- schema: {
57
- ['x-uid']: fieldSchema['x-uid'],
58
- 'x-decorator-props': field.decoratorProps,
59
- },
60
- });
61
- dn.refresh();
62
- }}
63
- />
64
- <SchemaSettings.SelectItem
65
- title={mapT('Marker field')}
66
- value={fieldNames.marker}
67
- options={markerFieldOptions}
68
- onChange={(v) => {
69
- const fieldNames = field.decoratorProps.fieldNames || {};
70
- fieldNames['marker'] = v;
71
- field.decoratorProps.fieldNames = fieldNames;
72
- fieldSchema['x-decorator-props']['fieldNames'] = fieldNames;
73
- service.refresh();
74
- dn.emit('patch', {
75
- schema: {
76
- ['x-uid']: fieldSchema['x-uid'],
77
- 'x-decorator-props': field.decoratorProps,
78
- },
79
- });
80
- dn.refresh();
81
- }}
82
- />
83
- <SchemaSettings.ModalItem
84
- title={mapT('The default zoom level of the map')}
85
- schema={
86
- {
87
- type: 'object',
88
- title: mapT('Set default zoom level'),
89
- properties: {
90
- zoom: {
91
- title: mapT('Zoom'),
92
- default: defaultZoom,
93
- 'x-component': 'InputNumber',
94
- 'x-decorator': 'FormItem',
95
- 'x-component-props': {
96
- precision: 0,
97
- },
98
- },
99
- },
100
- } as ISchema
101
- }
102
- onSubmit={({ zoom }) => {
103
- lodash.set(fieldSchema, 'x-component-props.zoom', zoom);
104
- Object.assign(field.componentProps, fieldSchema['x-component-props']);
105
- dn.emit('patch', {
106
- schema: {
107
- 'x-uid': fieldSchema['x-uid'],
108
- 'x-component-props': field.componentProps,
109
- },
110
- });
111
- dn.refresh();
112
- }}
113
- ></SchemaSettings.ModalItem>
114
- <SchemaSettings.ModalItem
115
- title={t('Set the data scope')}
116
- schema={
117
- {
118
- type: 'object',
119
- title: t('Set the data scope'),
120
- properties: {
121
- filter: {
122
- default: defaultFilter,
123
- // title: '数据范围',
124
- enum: dataSource,
125
- 'x-component': 'Filter',
126
- 'x-component-props': {},
127
- },
128
- },
129
- } as ISchema
130
- }
131
- onSubmit={({ filter }) => {
132
- const params = field.decoratorProps.params || {};
133
- params.filter = filter;
134
- field.decoratorProps.params = params;
135
- fieldSchema['x-decorator-props']['params'] = params;
136
- const filters = service.params?.[1]?.filters || {};
137
- service.run(
138
- { ...service.params?.[0], filter: mergeFilter([...Object.values(filters), filter]), page: 1 },
139
- { filters },
140
- );
141
- dn.emit('patch', {
142
- schema: {
143
- ['x-uid']: fieldSchema['x-uid'],
144
- 'x-decorator-props': fieldSchema['x-decorator-props'],
145
- },
146
- });
147
- }}
148
- />
149
- <SchemaSettings.ConnectDataBlocks type={FilterBlockType.TABLE} emptyDescription={t('No blocks to connect')} />
150
- <SchemaSettings.Divider />
151
- <SchemaSettings.Template componentName={'Map'} collectionName={name} resourceName={defaultResource} />
152
- <SchemaSettings.Divider />
153
- <SchemaSettings.Remove
154
- removeParentsIfNoChildren
155
- breakRemoveOn={{
156
- 'x-component': 'Grid',
157
- }}
158
- />
159
- </GeneralSchemaDesigner>
160
- );
161
- };
@@ -1,91 +0,0 @@
1
- import { TableOutlined } from '@ant-design/icons';
2
- import { FormLayout } from '@formily/antd-v5';
3
- import { SchemaOptionsContext } from '@formily/react';
4
- import {
5
- DataBlockInitializer,
6
- FormDialog,
7
- SchemaComponent,
8
- SchemaComponentOptions,
9
- useCollectionManager,
10
- useGlobalTheme,
11
- } from '@nocobase/client';
12
- import React, { useContext } from 'react';
13
- import { useMapTranslation } from '../locale';
14
- import { createMapBlockSchema } from './utils';
15
-
16
- export const MapBlockInitializer = (props) => {
17
- const { insert } = props;
18
- const options = useContext(SchemaOptionsContext);
19
- const { getCollectionFieldsOptions } = useCollectionManager();
20
- const { t } = useMapTranslation();
21
- const { theme } = useGlobalTheme();
22
-
23
- return (
24
- <DataBlockInitializer
25
- {...props}
26
- componentType={'Map'}
27
- icon={<TableOutlined />}
28
- onCreateBlockSchema={async ({ item }) => {
29
- const mapFieldOptions = getCollectionFieldsOptions(item.name, ['point', 'lineString', 'polygon']);
30
- const markerFieldOptions = getCollectionFieldsOptions(item.name, 'string');
31
- const values = await FormDialog(
32
- t('Create map block'),
33
- () => {
34
- return (
35
- <SchemaComponentOptions scope={options.scope} components={{ ...options.components }}>
36
- <FormLayout layout={'vertical'}>
37
- <SchemaComponent
38
- schema={{
39
- properties: {
40
- field: {
41
- title: t('Map field'),
42
- enum: mapFieldOptions,
43
- required: true,
44
- 'x-component': 'Select',
45
- 'x-decorator': 'FormItem',
46
- default: mapFieldOptions[0]?.value,
47
- },
48
- marker: {
49
- title: t('Marker field'),
50
- enum: markerFieldOptions,
51
- 'x-component': 'Select',
52
- 'x-decorator': 'FormItem',
53
- 'x-reactions': (field) => {
54
- const value = field.form.values.field;
55
- console.log('🚀 ~ file: MapBlockInitializer.tsx:45 ~ values ~ value:', value);
56
- console.log(
57
- '🚀 ~ file: MapBlockInitializer.tsx:50 ~ values ~ mapFieldOptions:',
58
- mapFieldOptions,
59
- );
60
-
61
- if (!value) {
62
- return;
63
- }
64
- const item = mapFieldOptions.find((item) => item.value === value).type;
65
- field.hidden = item !== 'point';
66
- },
67
- },
68
- },
69
- }}
70
- />
71
- </FormLayout>
72
- </SchemaComponentOptions>
73
- );
74
- },
75
- theme,
76
- ).open({
77
- initialValues: {},
78
- });
79
- insert(
80
- createMapBlockSchema({
81
- collection: item.name,
82
- fieldNames: {
83
- ...values,
84
- },
85
- }),
86
- );
87
- }}
88
- title={t('Map block')}
89
- />
90
- );
91
- };
@@ -1,55 +0,0 @@
1
- import { useField, useFieldSchema } from '@formily/react';
2
- import { BlockProvider, FixedBlockWrapper, SchemaComponentOptions, useBlockRequestContext } from '@nocobase/client';
3
- import React, { createContext, useContext, useState } from 'react';
4
-
5
- export const MapBlockContext = createContext<any>({});
6
-
7
- const InternalMapBlockProvider = (props) => {
8
- const { fieldNames } = props;
9
- const fieldSchema = useFieldSchema();
10
- const field = useField();
11
- const { resource, service } = useBlockRequestContext();
12
- const [selectedRecordKeys, setSelectedRecordKeys] = useState([]);
13
-
14
- return (
15
- <FixedBlockWrapper>
16
- <SchemaComponentOptions scope={{ selectedRecordKeys }}>
17
- <MapBlockContext.Provider
18
- value={{
19
- field,
20
- service,
21
- resource,
22
- fieldNames,
23
- fixedBlock: fieldSchema?.['x-decorator-props']?.fixedBlock,
24
- selectedRecordKeys,
25
- setSelectedRecordKeys,
26
- }}
27
- >
28
- {props.children}
29
- </MapBlockContext.Provider>
30
- </SchemaComponentOptions>
31
- </FixedBlockWrapper>
32
- );
33
- };
34
-
35
- export const MapBlockProvider = (props) => {
36
- return (
37
- <BlockProvider {...props} params={{ ...props.params, paginate: false }}>
38
- <InternalMapBlockProvider {...props} />
39
- </BlockProvider>
40
- );
41
- };
42
-
43
- export const useMapBlockContext = () => {
44
- return useContext(MapBlockContext);
45
- };
46
-
47
- export const useMapBlockProps = () => {
48
- const ctx = useMapBlockContext();
49
-
50
- return {
51
- ...ctx,
52
- dataSource: ctx?.service?.data?.data,
53
- zoom: ctx?.field?.componentProps?.zoom || 13,
54
- };
55
- };