@nocobase/plugin-map 0.11.0-alpha.1 → 0.11.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.
@@ -53,11 +53,12 @@ function _toPrimitive(input, hint) { if (typeof input !== "object" || input ===
53
53
  const MapBlockInitializer = props => {
54
54
  const insert = props.insert;
55
55
  const options = (0, _react2().useContext)(_react().SchemaOptionsContext);
56
- console.log('🚀 ~ file: MapBlockInitializer.tsx:12 ~ MapBlockInitializer ~ options:', options);
57
56
  const _useCollectionManager = (0, _client().useCollectionManager)(),
58
57
  getCollectionFieldsOptions = _useCollectionManager.getCollectionFieldsOptions;
59
58
  const _useMapTranslation = (0, _locale.useMapTranslation)(),
60
59
  t = _useMapTranslation.t;
60
+ const _useGlobalTheme = (0, _client().useGlobalTheme)(),
61
+ theme = _useGlobalTheme.theme;
61
62
  return _react2().default.createElement(_client().DataBlockInitializer, _objectSpread(_objectSpread({}, props), {}, {
62
63
  componentType: 'Map',
63
64
  icon: _react2().default.createElement(_icons().TableOutlined, null),
@@ -67,7 +68,7 @@ const MapBlockInitializer = props => {
67
68
  }) {
68
69
  const mapFieldOptions = getCollectionFieldsOptions(item.name, ['point', 'lineString', 'polygon']);
69
70
  const markerFieldOptions = getCollectionFieldsOptions(item.name, 'string');
70
- const values = yield (0, _antdV().FormDialog)(t('Create map block'), () => {
71
+ const values = yield (0, _client().FormDialog)(t('Create map block'), () => {
71
72
  var _mapFieldOptions$;
72
73
  return _react2().default.createElement(_client().SchemaComponentOptions, {
73
74
  scope: options.scope,
@@ -104,7 +105,7 @@ const MapBlockInitializer = props => {
104
105
  }
105
106
  }
106
107
  })));
107
- }).open({
108
+ }, theme).open({
108
109
  initialValues: {}
109
110
  });
110
111
  insert((0, _utils.createMapBlockSchema)({
@@ -147,6 +147,8 @@ const AMapComponent = _react2().default.forwardRef((props, ref) => {
147
147
  const _editor = (0, _react2().useRef)(null);
148
148
  const navigate = (0, _reactRouterDom().useNavigate)();
149
149
  const id = (0, _react2().useRef)(`nocobase-map-${type || ''}-${Date.now().toString(32)}`);
150
+ const _App$useApp = _antd().App.useApp(),
151
+ modal = _App$useApp.modal;
150
152
  const _useState5 = (0, _react2().useState)(_objectSpread({
151
153
  strokeWeight: 5,
152
154
  strokeColor: '#4e9bff',
@@ -250,7 +252,7 @@ const AMapComponent = _react2().default.forwardRef((props, ref) => {
250
252
  }
251
253
  onChange === null || onChange === void 0 ? void 0 : onChange(null);
252
254
  };
253
- _antd().Modal.confirm({
255
+ modal.confirm({
254
256
  title: t('Clear the canvas'),
255
257
  content: t('Are you sure to clear the canvas?'),
256
258
  okText: t('Confirm'),
@@ -142,6 +142,8 @@ const GoogleMapsComponent = _react2().default.forwardRef((props, ref) => {
142
142
  errMessage = _useState4[0],
143
143
  setErrMessage = _useState4[1];
144
144
  const api = (0, _client().useAPIClient)();
145
+ const _App$useApp = _antd().App.useApp(),
146
+ modal = _App$useApp.modal;
145
147
  const type = (0, _react2().useMemo)(() => {
146
148
  if (props.type) return props.type;
147
149
  const collectionField = getField(fieldSchema === null || fieldSchema === void 0 ? void 0 : fieldSchema.name);
@@ -376,7 +378,7 @@ const GoogleMapsComponent = _react2().default.forwardRef((props, ref) => {
376
378
  drawingManagerRef.current.setDrawingMode(drawingMode.current);
377
379
  onChange === null || onChange === void 0 ? void 0 : onChange(null);
378
380
  };
379
- _antd().Modal.confirm({
381
+ modal.confirm({
380
382
  title: t('Clear the canvas'),
381
383
  content: t('Are you sure to clear the canvas?'),
382
384
  okText: t('Confirm'),
@@ -25,7 +25,6 @@ const getSSKey = type => {
25
25
  };
26
26
  exports.getSSKey = getSSKey;
27
27
  const useMapConfiguration = type => {
28
- var _useRequest$data;
29
28
  // cache
30
29
  const config = (0, _react().useMemo)(() => {
31
30
  const d = sessionStorage.getItem(getSSKey(type));
@@ -34,20 +33,22 @@ const useMapConfiguration = type => {
34
33
  }
35
34
  return d;
36
35
  }, [type]);
36
+ const _useRequest = (0, _client().useRequest)({
37
+ resource: MapConfigurationResourceKey,
38
+ action: 'get',
39
+ params: {
40
+ type
41
+ }
42
+ }, {
43
+ onSuccess(data) {
44
+ sessionStorage.setItem(getSSKey(type), JSON.stringify(data === null || data === void 0 ? void 0 : data.data));
45
+ },
46
+ refreshOnWindowFocus: false,
47
+ refreshDeps: [],
48
+ manual: config ? true : false
49
+ }),
50
+ data = _useRequest.data;
37
51
  if (config) return config;
38
- return (_useRequest$data = (0, _client().useRequest)({
39
- resource: MapConfigurationResourceKey,
40
- action: 'get',
41
- params: {
42
- type
43
- }
44
- }, {
45
- onSuccess(data) {
46
- sessionStorage.setItem(getSSKey(type), JSON.stringify(data === null || data === void 0 ? void 0 : data.data));
47
- },
48
- refreshOnWindowFocus: false,
49
- refreshDeps: [],
50
- manual: config ? true : false
51
- }).data) === null || _useRequest$data === void 0 ? void 0 : _useRequest$data.data;
52
+ return data === null || data === void 0 ? void 0 : data.data;
52
53
  };
53
54
  exports.useMapConfiguration = useMapConfiguration;
@@ -1,5 +1,4 @@
1
1
  import { Plugin } from '@nocobase/client';
2
- import './locale';
3
2
  export declare class MapPlugin extends Plugin {
4
3
  load(): Promise<void>;
5
4
  }
@@ -21,13 +21,10 @@ function _reactI18next() {
21
21
  };
22
22
  return data;
23
23
  }
24
- var _enUS = _interopRequireDefault(require("./en-US"));
25
- var _zhCN = _interopRequireDefault(require("./zh-CN"));
26
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
27
24
  const NAMESPACE = 'map';
25
+ // i18n.addResources('zh-CN', NAMESPACE, zhCN);
26
+ // i18n.addResources('en-US', NAMESPACE, enUS);
28
27
  exports.NAMESPACE = NAMESPACE;
29
- _client().i18n.addResources('zh-CN', NAMESPACE, _zhCN.default);
30
- _client().i18n.addResources('en-US', NAMESPACE, _enUS.default);
31
28
  function lang(key) {
32
29
  return _client().i18n.t(key, {
33
30
  ns: NAMESPACE
@@ -1,4 +1,5 @@
1
1
  declare const locale: {
2
+ Map: string;
2
3
  'Map-based geometry': string;
3
4
  'Map type': string;
4
5
  Point: string;
@@ -43,5 +44,6 @@ declare const locale: {
43
44
  'Map field': string;
44
45
  'Marker field': string;
45
46
  'Load google maps failed, Please check the Api key and refresh the page': string;
47
+ 'Create map block': string;
46
48
  };
47
49
  export default locale;
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  const locale = {
8
+ Map: '地图',
8
9
  'Map-based geometry': '基于地图的几何图形',
9
10
  'Map type': '地图类型',
10
11
  Point: '点',
@@ -49,7 +50,8 @@ const locale = {
49
50
  'Edit description': '编辑描述',
50
51
  'Map field': '地图字段',
51
52
  'Marker field': '标记字段',
52
- 'Load google maps failed, Please check the Api key and refresh the page': '加载谷歌地图失败,请检查 Api key 并刷新页面'
53
+ 'Load google maps failed, Please check the Api key and refresh the page': '加载谷歌地图失败,请检查 Api key 并刷新页面',
54
+ 'Create map block': '创建地图区块'
53
55
  };
54
56
  var _default = locale;
55
57
  exports.default = _default;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@nocobase/plugin-map",
3
3
  "displayName": "Map",
4
4
  "displayName.zh-CN": "地图",
5
- "version": "0.11.0-alpha.1",
5
+ "version": "0.11.1-alpha.2",
6
6
  "description": "Provide map fields and blocks",
7
7
  "description.zh-CN": "提供地图字段和区块",
8
8
  "license": "AGPL-3.0",
@@ -31,12 +31,12 @@
31
31
  "@formily/core": "2.2.26",
32
32
  "@formily/react": "2.2.26",
33
33
  "@formily/shared": "2.2.26",
34
- "@nocobase/actions": "0.11.0-alpha.1",
35
- "@nocobase/client": "0.11.0-alpha.1",
36
- "@nocobase/database": "0.11.0-alpha.1",
37
- "@nocobase/server": "0.11.0-alpha.1",
38
- "@nocobase/test": "0.11.0-alpha.1",
39
- "@nocobase/utils": "0.11.0-alpha.1",
34
+ "@nocobase/actions": "0.11.1-alpha.2",
35
+ "@nocobase/client": "0.11.1-alpha.2",
36
+ "@nocobase/database": "0.11.1-alpha.2",
37
+ "@nocobase/server": "0.11.1-alpha.2",
38
+ "@nocobase/test": "0.11.1-alpha.2",
39
+ "@nocobase/utils": "0.11.1-alpha.2",
40
40
  "@types/react": "^17.0.0",
41
41
  "@types/react-dom": "^17.0.0",
42
42
  "antd": "^5.6.4",
@@ -45,5 +45,5 @@
45
45
  "react-i18next": "^11.15.1",
46
46
  "react-router-dom": "^6.11.2"
47
47
  },
48
- "gitHead": "7581b6d3a3a54f09f06a9effb7e3e65328281b2b"
48
+ "gitHead": "8482aa720ea1c3abbbb9fe1208e73778bd63f1cf"
49
49
  }
@@ -1,7 +1,14 @@
1
1
  import { TableOutlined } from '@ant-design/icons';
2
- import { FormDialog, FormLayout } from '@formily/antd-v5';
2
+ import { FormLayout } from '@formily/antd-v5';
3
3
  import { SchemaOptionsContext } from '@formily/react';
4
- import { DataBlockInitializer, SchemaComponent, SchemaComponentOptions, useCollectionManager } from '@nocobase/client';
4
+ import {
5
+ DataBlockInitializer,
6
+ FormDialog,
7
+ SchemaComponent,
8
+ SchemaComponentOptions,
9
+ useCollectionManager,
10
+ useGlobalTheme,
11
+ } from '@nocobase/client';
5
12
  import React, { useContext } from 'react';
6
13
  import { useMapTranslation } from '../locale';
7
14
  import { createMapBlockSchema } from './utils';
@@ -9,9 +16,9 @@ import { createMapBlockSchema } from './utils';
9
16
  export const MapBlockInitializer = (props) => {
10
17
  const { insert } = props;
11
18
  const options = useContext(SchemaOptionsContext);
12
- console.log('🚀 ~ file: MapBlockInitializer.tsx:12 ~ MapBlockInitializer ~ options:', options);
13
19
  const { getCollectionFieldsOptions } = useCollectionManager();
14
20
  const { t } = useMapTranslation();
21
+ const { theme } = useGlobalTheme();
15
22
 
16
23
  return (
17
24
  <DataBlockInitializer
@@ -21,48 +28,52 @@ export const MapBlockInitializer = (props) => {
21
28
  onCreateBlockSchema={async ({ item }) => {
22
29
  const mapFieldOptions = getCollectionFieldsOptions(item.name, ['point', 'lineString', 'polygon']);
23
30
  const markerFieldOptions = getCollectionFieldsOptions(item.name, 'string');
24
- const values = await FormDialog(t('Create map block'), () => {
25
- return (
26
- <SchemaComponentOptions scope={options.scope} components={{ ...options.components }}>
27
- <FormLayout layout={'vertical'}>
28
- <SchemaComponent
29
- schema={{
30
- properties: {
31
- field: {
32
- title: t('Map field'),
33
- enum: mapFieldOptions,
34
- required: true,
35
- 'x-component': 'Select',
36
- 'x-decorator': 'FormItem',
37
- default: mapFieldOptions[0]?.value,
38
- },
39
- marker: {
40
- title: t('Marker field'),
41
- enum: markerFieldOptions,
42
- 'x-component': 'Select',
43
- 'x-decorator': 'FormItem',
44
- 'x-reactions': (field) => {
45
- const value = field.form.values.field;
46
- console.log('🚀 ~ file: MapBlockInitializer.tsx:45 ~ values ~ value:', value);
47
- console.log(
48
- '🚀 ~ file: MapBlockInitializer.tsx:50 ~ values ~ mapFieldOptions:',
49
- mapFieldOptions,
50
- );
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
+ );
51
60
 
52
- if (!value) {
53
- return;
54
- }
55
- const item = mapFieldOptions.find((item) => item.value === value).type;
56
- field.hidden = item !== 'point';
61
+ if (!value) {
62
+ return;
63
+ }
64
+ const item = mapFieldOptions.find((item) => item.value === value).type;
65
+ field.hidden = item !== 'point';
66
+ },
57
67
  },
58
68
  },
59
- },
60
- }}
61
- />
62
- </FormLayout>
63
- </SchemaComponentOptions>
64
- );
65
- }).open({
69
+ }}
70
+ />
71
+ </FormLayout>
72
+ </SchemaComponentOptions>
73
+ );
74
+ },
75
+ theme,
76
+ ).open({
66
77
  initialValues: {},
67
78
  });
68
79
  insert(
@@ -4,7 +4,7 @@ import { SyncOutlined } from '@ant-design/icons';
4
4
  import { useFieldSchema } from '@formily/react';
5
5
  import { css, useCollection } from '@nocobase/client';
6
6
  import { useMemoizedFn } from 'ahooks';
7
- import { Alert, Button, Modal, Spin } from 'antd';
7
+ import { Alert, App, Button, Spin } from 'antd';
8
8
  import React, { useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
9
9
  import { useNavigate } from 'react-router-dom';
10
10
  import { useMapConfiguration } from '../../hooks';
@@ -102,6 +102,7 @@ export const AMapComponent = React.forwardRef<AMapForwardedRefProps, AMapCompone
102
102
  const editor = useRef(null);
103
103
  const navigate = useNavigate();
104
104
  const id = useRef(`nocobase-map-${type || ''}-${Date.now().toString(32)}`);
105
+ const { modal } = App.useApp();
105
106
 
106
107
  const [commonOptions] = useState<AMap.PolylineOptions & AMap.PolygonOptions>({
107
108
  strokeWeight: 5,
@@ -210,7 +211,7 @@ export const AMapComponent = React.forwardRef<AMapForwardedRefProps, AMapCompone
210
211
  }
211
212
  onChange?.(null);
212
213
  };
213
- Modal.confirm({
214
+ modal.confirm({
214
215
  title: t('Clear the canvas'),
215
216
  content: t('Are you sure to clear the canvas?'),
216
217
  okText: t('Confirm'),
@@ -3,7 +3,7 @@ import { useFieldSchema } from '@formily/react';
3
3
  import { Loader } from '@googlemaps/js-api-loader';
4
4
  import { css, useAPIClient, useCollection } from '@nocobase/client';
5
5
  import { useMemoizedFn } from 'ahooks';
6
- import { Alert, Button, Modal, Spin } from 'antd';
6
+ import { Alert, App, Button, Spin } from 'antd';
7
7
  import React, { useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
8
8
  import { useNavigate } from 'react-router-dom';
9
9
  import { defaultImage } from '../../constants';
@@ -88,6 +88,7 @@ export const GoogleMapsComponent = React.forwardRef<GoogleMapForwardedRefProps,
88
88
  const [needUpdateFlag, forceUpdate] = useState([]);
89
89
  const [errMessage, setErrMessage] = useState('');
90
90
  const api = useAPIClient();
91
+ const { modal } = App.useApp();
91
92
 
92
93
  const type = useMemo<MapEditorType>(() => {
93
94
  if (props.type) return props.type;
@@ -352,7 +353,7 @@ export const GoogleMapsComponent = React.forwardRef<GoogleMapForwardedRefProps,
352
353
  drawingManagerRef.current.setDrawingMode(drawingMode.current);
353
354
  onChange?.(null);
354
355
  };
355
- Modal.confirm({
356
+ modal.confirm({
356
357
  title: t('Clear the canvas'),
357
358
  content: t('Are you sure to clear the canvas?'),
358
359
  okText: t('Confirm'),
@@ -16,9 +16,9 @@ export const useMapConfiguration = (type: string) => {
16
16
  return d;
17
17
  }, [type]);
18
18
 
19
- if (config) return config;
20
-
21
- return useRequest(
19
+ const { data } = useRequest<{
20
+ data: any;
21
+ }>(
22
22
  {
23
23
  resource: MapConfigurationResourceKey,
24
24
  action: 'get',
@@ -34,5 +34,9 @@ export const useMapConfiguration = (type: string) => {
34
34
  refreshDeps: [],
35
35
  manual: config ? true : false,
36
36
  },
37
- ).data?.data;
37
+ );
38
+
39
+ if (config) return config;
40
+
41
+ return data?.data;
38
42
  };
@@ -10,7 +10,6 @@ import { MapBlockOptions } from './block';
10
10
  import { Configuration, Map } from './components';
11
11
  import { interfaces } from './fields';
12
12
  import { MapInitializer } from './initialize';
13
- import './locale';
14
13
  import { useMapTranslation } from './locale';
15
14
 
16
15
  const MapProvider = React.memo((props) => {
@@ -1,12 +1,10 @@
1
1
  import { i18n } from '@nocobase/client';
2
2
  import { useTranslation } from 'react-i18next';
3
- import enUS from './en-US';
4
- import zhCN from './zh-CN';
5
3
 
6
4
  export const NAMESPACE = 'map';
7
5
 
8
- i18n.addResources('zh-CN', NAMESPACE, zhCN);
9
- i18n.addResources('en-US', NAMESPACE, enUS);
6
+ // i18n.addResources('zh-CN', NAMESPACE, zhCN);
7
+ // i18n.addResources('en-US', NAMESPACE, enUS);
10
8
 
11
9
  export function lang(key: string) {
12
10
  return i18n.t(key, { ns: NAMESPACE });
@@ -1,4 +1,5 @@
1
1
  const locale = {
2
+ Map: '地图',
2
3
  'Map-based geometry': '基于地图的几何图形',
3
4
  'Map type': '地图类型',
4
5
  Point: '点',
@@ -45,6 +46,7 @@ const locale = {
45
46
  'Marker field': '标记字段',
46
47
  'Load google maps failed, Please check the Api key and refresh the page':
47
48
  '加载谷歌地图失败,请检查 Api key 并刷新页面',
49
+ 'Create map block': '创建地图区块',
48
50
  };
49
51
 
50
52
  export default locale;