@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,502 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ function _react() {
9
+ const data = _interopRequireWildcard(require("react"));
10
+
11
+ _react = function _react() {
12
+ return data;
13
+ };
14
+
15
+ return data;
16
+ }
17
+
18
+ function _amapJsapiLoader() {
19
+ const data = _interopRequireDefault(require("@amap/amap-jsapi-loader"));
20
+
21
+ _amapJsapiLoader = function _amapJsapiLoader() {
22
+ return data;
23
+ };
24
+
25
+ return data;
26
+ }
27
+
28
+ require("@amap/amap-jsapi-types");
29
+
30
+ function _react2() {
31
+ const data = require("@formily/react");
32
+
33
+ _react2 = function _react2() {
34
+ return data;
35
+ };
36
+
37
+ return data;
38
+ }
39
+
40
+ function _client() {
41
+ const data = require("@nocobase/client");
42
+
43
+ _client = function _client() {
44
+ return data;
45
+ };
46
+
47
+ return data;
48
+ }
49
+
50
+ function _css() {
51
+ const data = require("@emotion/css");
52
+
53
+ _css = function _css() {
54
+ return data;
55
+ };
56
+
57
+ return data;
58
+ }
59
+
60
+ function _antd() {
61
+ const data = require("antd");
62
+
63
+ _antd = function _antd() {
64
+ return data;
65
+ };
66
+
67
+ return data;
68
+ }
69
+
70
+ var _locales = require("../locales");
71
+
72
+ var _Search = _interopRequireDefault(require("./Search"));
73
+
74
+ function _ahooks() {
75
+ const data = require("ahooks");
76
+
77
+ _ahooks = function _ahooks() {
78
+ return data;
79
+ };
80
+
81
+ return data;
82
+ }
83
+
84
+ var _hooks = require("../hooks");
85
+
86
+ function _reactRouter() {
87
+ const data = require("react-router");
88
+
89
+ _reactRouter = function _reactRouter() {
90
+ return data;
91
+ };
92
+
93
+ return data;
94
+ }
95
+
96
+ function _icons() {
97
+ const data = require("@ant-design/icons");
98
+
99
+ _icons = function _icons() {
100
+ return data;
101
+ };
102
+
103
+ return data;
104
+ }
105
+
106
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
107
+
108
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
109
+
110
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
111
+
112
+ 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; }
113
+
114
+ 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; }
115
+
116
+ 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; }
117
+
118
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
119
+
120
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
121
+
122
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
123
+
124
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
125
+
126
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
127
+
128
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
129
+
130
+ const methodMapping = {
131
+ point: {
132
+ mouseTool: 'marker',
133
+ propertyKey: 'position',
134
+ overlay: 'Marker'
135
+ },
136
+ polygon: {
137
+ mouseTool: 'polygon',
138
+ editor: 'PolygonEditor',
139
+ propertyKey: 'path',
140
+ overlay: 'Polygon'
141
+ },
142
+ lineString: {
143
+ mouseTool: 'polyline',
144
+ editor: 'PolylineEditor',
145
+ propertyKey: 'path',
146
+ overlay: 'Polyline'
147
+ },
148
+ circle: {
149
+ mouseTool: 'circle',
150
+ editor: 'CircleEditor',
151
+
152
+ transformOptions(value) {
153
+ return {
154
+ center: value.slice(0, 2),
155
+ radius: value[2]
156
+ };
157
+ },
158
+
159
+ overlay: 'Circle'
160
+ }
161
+ };
162
+
163
+ const AMapComponent = props => {
164
+ const _ref = (0, _hooks.useMapConfiguration)(props.mapType) || {},
165
+ accessKey = _ref.accessKey,
166
+ securityJsCode = _ref.securityJsCode;
167
+
168
+ const value = props.value,
169
+ onChange = props.onChange,
170
+ disabled = props.disabled,
171
+ _props$zoom = props.zoom,
172
+ zoom = _props$zoom === void 0 ? 13 : _props$zoom;
173
+
174
+ const _useMapTranslation = (0, _locales.useMapTranslation)(),
175
+ t = _useMapTranslation.t;
176
+
177
+ const fieldSchema = (0, _react2().useFieldSchema)();
178
+ const aMap = (0, _react().useRef)();
179
+ const map = (0, _react().useRef)();
180
+ const mouseTool = (0, _react().useRef)();
181
+
182
+ const _useState = (0, _react().useState)([]),
183
+ _useState2 = _slicedToArray(_useState, 2),
184
+ needUpdateFlag = _useState2[0],
185
+ forceUpdate = _useState2[1];
186
+
187
+ const _useState3 = (0, _react().useState)(''),
188
+ _useState4 = _slicedToArray(_useState3, 2),
189
+ errMessage = _useState4[0],
190
+ setErrMessage = _useState4[1];
191
+
192
+ const _useCollection = (0, _client().useCollection)(),
193
+ getField = _useCollection.getField;
194
+
195
+ const collectionField = getField(fieldSchema.name);
196
+ const type = collectionField === null || collectionField === void 0 ? void 0 : collectionField.interface;
197
+ const overlay = (0, _react().useRef)();
198
+ const editor = (0, _react().useRef)(null);
199
+ const history = (0, _reactRouter().useHistory)();
200
+ const id = (0, _react().useRef)(`nocobase-map-${type}-${Date.now().toString(32)}`);
201
+
202
+ const _useState5 = (0, _react().useState)({
203
+ strokeWeight: 5,
204
+ strokeColor: '#4e9bff',
205
+ fillColor: '#4e9bff',
206
+ strokeOpacity: 1
207
+ }),
208
+ _useState6 = _slicedToArray(_useState5, 1),
209
+ commonOptions = _useState6[0];
210
+
211
+ const toRemoveOverlay = (0, _ahooks().useMemoizedFn)(() => {
212
+ if (overlay.current) {
213
+ var _map$current;
214
+
215
+ (_map$current = map.current) === null || _map$current === void 0 ? void 0 : _map$current.remove(overlay.current);
216
+ }
217
+ });
218
+ const setTarget = (0, _ahooks().useMemoizedFn)(() => {
219
+ if (!disabled && type !== 'point' && editor.current) {
220
+ editor.current.setTarget(overlay.current);
221
+ editor.current.open();
222
+ }
223
+ });
224
+ const onMapChange = (0, _ahooks().useMemoizedFn)((target, onlyChange = false) => {
225
+ let nextValue = null;
226
+
227
+ if (type === 'point') {
228
+ const _target$getPosition = target.getPosition(),
229
+ lat = _target$getPosition.lat,
230
+ lng = _target$getPosition.lng;
231
+
232
+ nextValue = [lng, lat];
233
+ } else if (type === 'polygon' || type === 'lineString') {
234
+ nextValue = target.getPath().map(item => [item.lng, item.lat]);
235
+
236
+ if (nextValue.length < 2) {
237
+ return;
238
+ }
239
+ } else if (type === 'circle') {
240
+ const center = target.getCenter();
241
+ const radius = target.getRadius();
242
+ nextValue = [center.lng, center.lat, radius];
243
+ }
244
+
245
+ if (!onlyChange) {
246
+ toRemoveOverlay();
247
+ overlay.current = target;
248
+ setTarget();
249
+ }
250
+
251
+ onChange(nextValue);
252
+ });
253
+ const createEditor = (0, _ahooks().useMemoizedFn)(() => {
254
+ const mapping = methodMapping[type];
255
+
256
+ if (mapping && 'editor' in mapping && !editor.current) {
257
+ editor.current = new aMap.current[mapping.editor](map.current);
258
+ editor.current.on('adjust', function ({
259
+ target
260
+ }) {
261
+ onMapChange(target, true);
262
+ });
263
+ editor.current.on('move', function ({
264
+ target
265
+ }) {
266
+ onMapChange(target, true);
267
+ });
268
+ }
269
+ });
270
+ const executeMouseTool = (0, _ahooks().useMemoizedFn)(() => {
271
+ var _editor$current;
272
+
273
+ if (!mouseTool.current || ((_editor$current = editor.current) === null || _editor$current === void 0 ? void 0 : _editor$current.getTarget())) return;
274
+ const mapping = methodMapping[type];
275
+
276
+ if (!mapping) {
277
+ return;
278
+ }
279
+
280
+ mouseTool.current[mapping.mouseTool](_objectSpread({}, commonOptions));
281
+ });
282
+ const createMouseTool = (0, _ahooks().useMemoizedFn)(() => {
283
+ if (mouseTool.current) return;
284
+ mouseTool.current = new aMap.current.MouseTool(map.current);
285
+ mouseTool.current.on('draw', function ({
286
+ obj
287
+ }) {
288
+ onMapChange(obj);
289
+ });
290
+ executeMouseTool();
291
+ });
292
+
293
+ const toCenter = (position, imm) => {
294
+ if (map.current) {
295
+ map.current.setZoomAndCenter(18, position, imm);
296
+ }
297
+ };
298
+
299
+ const onReset = () => {
300
+ const ok = () => {
301
+ toRemoveOverlay();
302
+
303
+ if (editor.current) {
304
+ editor.current.setTarget();
305
+ editor.current.close();
306
+ }
307
+
308
+ onChange(null);
309
+ };
310
+
311
+ _antd().Modal.confirm({
312
+ title: t('Clear the canvas'),
313
+ content: t('Are you sure to clear the canvas?'),
314
+ okText: t('Confirm'),
315
+ cancelText: t('Cancel'),
316
+
317
+ onOk() {
318
+ ok();
319
+ }
320
+
321
+ });
322
+ };
323
+
324
+ const onFocusOverlay = () => {
325
+ if (overlay.current) {
326
+ map.current.setFitView([overlay.current]);
327
+ }
328
+ }; // 编辑时
329
+
330
+
331
+ (0, _react().useEffect)(() => {
332
+ if (!aMap.current) return;
333
+
334
+ if (!value || overlay.current) {
335
+ return;
336
+ }
337
+
338
+ const mapping = methodMapping[type];
339
+
340
+ if (!mapping) {
341
+ return;
342
+ }
343
+
344
+ const options = _objectSpread({}, commonOptions);
345
+
346
+ if ('transformOptions' in mapping) {
347
+ Object.assign(options, mapping.transformOptions(value));
348
+ } else if ('propertyKey' in mapping) {
349
+ options[mapping.propertyKey] = value;
350
+ }
351
+
352
+ const nextOverlay = new aMap.current[mapping.overlay](options); // 聚焦在编辑的位置
353
+
354
+ map.current.setFitView([nextOverlay]);
355
+ nextOverlay.setMap(map.current);
356
+ overlay.current = nextOverlay;
357
+ createEditor();
358
+ setTarget();
359
+ }, [value, needUpdateFlag, type, commonOptions]); // 当在编辑时,关闭 mouseTool
360
+
361
+ (0, _react().useEffect)(() => {
362
+ if (!mouseTool.current) return;
363
+
364
+ if (disabled) {
365
+ var _mouseTool$current, _editor$current2;
366
+
367
+ (_mouseTool$current = mouseTool.current) === null || _mouseTool$current === void 0 ? void 0 : _mouseTool$current.close();
368
+ (_editor$current2 = editor.current) === null || _editor$current2 === void 0 ? void 0 : _editor$current2.close();
369
+ } else {
370
+ var _editor$current3;
371
+
372
+ executeMouseTool();
373
+ (_editor$current3 = editor.current) === null || _editor$current3 === void 0 ? void 0 : _editor$current3.open();
374
+ }
375
+ }, [disabled]); // AMap.MouseTool & AMap.XXXEditor
376
+
377
+ (0, _react().useEffect)(() => {
378
+ if (!aMap.current || !type || disabled) return;
379
+ createMouseTool();
380
+ createEditor();
381
+ }, [disabled, needUpdateFlag, type]);
382
+ (0, _react().useEffect)(() => {
383
+ if (!mouseTool.current || !editor.current) return;
384
+ const target = editor.current.getTarget();
385
+
386
+ if (target) {
387
+ var _mouseTool$current$cl, _mouseTool$current2;
388
+
389
+ (_mouseTool$current$cl = (_mouseTool$current2 = mouseTool.current).close) === null || _mouseTool$current$cl === void 0 ? void 0 : _mouseTool$current$cl.call(_mouseTool$current2);
390
+ } else {
391
+ executeMouseTool();
392
+ }
393
+ }, [type, value]);
394
+ (0, _react().useEffect)(() => {
395
+ if (!accessKey || map.current) return;
396
+
397
+ if (securityJsCode) {
398
+ window._AMapSecurityConfig = {
399
+ [securityJsCode.endsWith('_AMapService') ? 'serviceHOST' : 'securityJsCode']: securityJsCode
400
+ };
401
+ }
402
+
403
+ _amapJsapiLoader().default.load({
404
+ key: accessKey,
405
+ version: '2.0',
406
+ plugins: ['AMap.MouseTool', 'AMap.PolygonEditor', 'AMap.PolylineEditor', 'AMap.CircleEditor']
407
+ }).then(amap => {
408
+ setTimeout(() => {
409
+ map.current = new amap.Map(id.current, {
410
+ resizeEnable: true,
411
+ zoom
412
+ });
413
+ aMap.current = amap;
414
+ setErrMessage('');
415
+ forceUpdate([]);
416
+ }, Math.random() * 300);
417
+ }).catch(err => {
418
+ if (err.includes('多个不一致的 key')) {
419
+ setErrMessage(t('The AccessKey is incorrect, please check it'));
420
+ } else {
421
+ setErrMessage(err);
422
+ }
423
+ });
424
+
425
+ return () => {
426
+ var _map$current2;
427
+
428
+ (_map$current2 = map.current) === null || _map$current2 === void 0 ? void 0 : _map$current2.destroy();
429
+ aMap.current = null;
430
+ map.current = null;
431
+ mouseTool.current = null;
432
+ editor.current = null;
433
+ };
434
+ }, [accessKey, type, securityJsCode]);
435
+
436
+ if (!accessKey || errMessage) {
437
+ return _react().default.createElement(_antd().Alert, {
438
+ action: _react().default.createElement(_antd().Button, {
439
+ type: "primary",
440
+ onClick: () => history.push('/admin/settings/map-configuration/configuration')
441
+ }, t('Go to the configuration page')),
442
+ message: errMessage || t('Please configure the AccessKey and SecurityJsCode first'),
443
+ type: "error"
444
+ });
445
+ }
446
+
447
+ return _react().default.createElement("div", {
448
+ className: (0, _css().css)`
449
+ position: relative;
450
+ `,
451
+ id: id.current,
452
+ style: {
453
+ height: '500px'
454
+ }
455
+ }, _react().default.createElement("div", {
456
+ className: (0, _css().css)`
457
+ position: absolute;
458
+ bottom: 80px;
459
+ right: 20px;
460
+ z-index: 10;
461
+ `
462
+ }, _react().default.createElement(_antd().Button, {
463
+ onClick: onFocusOverlay,
464
+ disabled: !overlay.current,
465
+ type: "primary",
466
+ shape: "round",
467
+ size: "large",
468
+ icon: _react().default.createElement(_icons().SyncOutlined, null)
469
+ })), !disabled ? _react().default.createElement(_react().default.Fragment, null, _react().default.createElement(_Search.default, {
470
+ toCenter: toCenter,
471
+ aMap: aMap.current
472
+ }), _react().default.createElement("div", {
473
+ className: (0, _css().css)`
474
+ position: absolute;
475
+ bottom: 20px;
476
+ left: 10px;
477
+ z-index: 2;
478
+ pointer-events: none;
479
+ `
480
+ }, _react().default.createElement(_antd().Alert, {
481
+ message: t('Click to select the starting point and double-click to end the drawing'),
482
+ type: "info"
483
+ })), _react().default.createElement("div", {
484
+ className: (0, _css().css)`
485
+ position: absolute;
486
+ bottom: 20px;
487
+ right: 20px;
488
+ z-index: 2;
489
+ `
490
+ }, _react().default.createElement(_antd().Button, {
491
+ disabled: !value,
492
+ style: {
493
+ height: '40px'
494
+ },
495
+ onClick: onReset,
496
+ type: "primary",
497
+ danger: true
498
+ }, t('Clear')))) : null);
499
+ };
500
+
501
+ var _default = AMapComponent;
502
+ exports.default = _default;
@@ -0,0 +1,2 @@
1
+ declare const Configuration: () => JSX.Element;
2
+ export default Configuration;
@@ -0,0 +1,167 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ function _client() {
9
+ const data = require("@nocobase/client");
10
+
11
+ _client = function _client() {
12
+ return data;
13
+ };
14
+
15
+ return data;
16
+ }
17
+
18
+ function _ahooks() {
19
+ const data = require("ahooks");
20
+
21
+ _ahooks = function _ahooks() {
22
+ return data;
23
+ };
24
+
25
+ return data;
26
+ }
27
+
28
+ function _antd() {
29
+ const data = require("antd");
30
+
31
+ _antd = function _antd() {
32
+ return data;
33
+ };
34
+
35
+ return data;
36
+ }
37
+
38
+ function _react() {
39
+ const data = _interopRequireWildcard(require("react"));
40
+
41
+ _react = function _react() {
42
+ return data;
43
+ };
44
+
45
+ return data;
46
+ }
47
+
48
+ var _constants = require("../constants");
49
+
50
+ var _hooks = require("../hooks");
51
+
52
+ var _locales = require("../locales");
53
+
54
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
55
+
56
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
57
+
58
+ 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; }
59
+
60
+ 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; }
61
+
62
+ 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; }
63
+
64
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
65
+
66
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
67
+
68
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
69
+
70
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
71
+
72
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
73
+
74
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
75
+
76
+ const AMapConfiguration = ({
77
+ type
78
+ }) => {
79
+ const _useMapTranslation = (0, _locales.useMapTranslation)(),
80
+ t = _useMapTranslation.t;
81
+
82
+ const _useBoolean = (0, _ahooks().useBoolean)(false),
83
+ _useBoolean2 = _slicedToArray(_useBoolean, 2),
84
+ isDisabled = _useBoolean2[0],
85
+ disableAction = _useBoolean2[1];
86
+
87
+ const apiClient = (0, _client().useAPIClient)();
88
+
89
+ const _Form$useForm = _antd().Form.useForm(),
90
+ _Form$useForm2 = _slicedToArray(_Form$useForm, 1),
91
+ form = _Form$useForm2[0];
92
+
93
+ const data = (0, _hooks.useMapConfiguration)(type);
94
+ (0, _react().useEffect)(() => {
95
+ if (data) {
96
+ form.setFieldsValue(data);
97
+ disableAction.toggle();
98
+ }
99
+ }, [data]);
100
+ const resource = (0, _react().useMemo)(() => {
101
+ return apiClient.resource(_hooks.MapConfigurationResourceKey);
102
+ }, [apiClient]);
103
+
104
+ const onSubmit = values => {
105
+ resource.set(_objectSpread(_objectSpread({}, values), {}, {
106
+ type
107
+ })).then(res => {
108
+ _antd().message.success(t('Saved successfully'));
109
+ }).catch(err => {
110
+ _antd().message.success(t('Saved failed'));
111
+ });
112
+ };
113
+
114
+ return _react().default.createElement(_antd().Form, {
115
+ form: form,
116
+ layout: "vertical",
117
+ onFinish: onSubmit
118
+ }, _react().default.createElement(_antd().Form.Item, {
119
+ required: true,
120
+ name: "accessKey",
121
+ label: t('Access key')
122
+ }, _react().default.createElement(_antd().Input, {
123
+ disabled: isDisabled
124
+ })), _react().default.createElement(_antd().Form.Item, {
125
+ required: true,
126
+ name: "securityJsCode",
127
+ label: t('securityJsCode or serviceHost')
128
+ }, _react().default.createElement(_antd().Input, {
129
+ disabled: isDisabled
130
+ })), isDisabled ? _react().default.createElement(_antd().Button, {
131
+ onClick: disableAction.toggle,
132
+ type: "ghost"
133
+ }, t('Edit')) : _react().default.createElement(_antd().Form.Item, null, _react().default.createElement(_antd().Button, {
134
+ type: "primary",
135
+ htmlType: "submit"
136
+ }, t('Save'))));
137
+ };
138
+
139
+ const components = {
140
+ amap: AMapConfiguration,
141
+ google: () => _react().default.createElement("div", null, "Coming soon")
142
+ };
143
+
144
+ const tabList = _constants.MapTypes.map(item => {
145
+ return _objectSpread(_objectSpread({}, item), {}, {
146
+ component: components[item.value]
147
+ });
148
+ });
149
+
150
+ const Configuration = () => {
151
+ const compile = (0, _client().useCompile)();
152
+ return _react().default.createElement(_antd().Card, {
153
+ bordered: true
154
+ }, _react().default.createElement(_antd().Tabs, {
155
+ type: "card"
156
+ }, tabList.map(tab => {
157
+ return _react().default.createElement(_antd().Tabs.TabPane, {
158
+ key: tab.value,
159
+ tab: compile(tab.label)
160
+ }, _react().default.createElement(tab.component, {
161
+ type: tab.value
162
+ }));
163
+ })));
164
+ };
165
+
166
+ var _default = Configuration;
167
+ exports.default = _default;
@@ -0,0 +1,2 @@
1
+ declare const Designer: () => JSX.Element;
2
+ export default Designer;