@nocobase/plugin-map 0.9.4-alpha.2 → 0.10.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.
@@ -1 +1,2 @@
1
- export declare const MapBlock: (props: any) => JSX.Element;
1
+ import React from 'react';
2
+ export declare const MapBlock: (props: any) => React.JSX.Element;
@@ -322,7 +322,7 @@ const MapBlockDrawer = props => {
322
322
  }
323
323
  return buf;
324
324
  }, null), [fieldSchema]);
325
- return schema && _react2().default.createElement(_client().ActionContext.Provider, {
325
+ return schema && _react2().default.createElement(_client().ActionContextProvider, {
326
326
  value: {
327
327
  visible: !!record,
328
328
  setVisible
@@ -1 +1,2 @@
1
- export declare const MapBlockDesigner: () => JSX.Element;
1
+ import React from 'react';
2
+ export declare const MapBlockDesigner: () => React.JSX.Element;
@@ -1 +1,2 @@
1
- export declare const MapBlockInitializer: (props: any) => JSX.Element;
1
+ import React from 'react';
2
+ export declare const MapBlockInitializer: (props: any) => React.JSX.Element;
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
2
  export declare const MapBlockContext: React.Context<any>;
3
- export declare const MapBlockProvider: (props: any) => JSX.Element;
3
+ export declare const MapBlockProvider: (props: any) => React.JSX.Element;
4
4
  export declare const useMapBlockContext: () => any;
5
5
  export declare const useMapBlockProps: () => any;
@@ -53,4 +53,5 @@ export declare const createMapBlockSchema: (options: any) => import("@formily/re
53
53
  "x-editable"?: boolean;
54
54
  "x-read-only"?: boolean;
55
55
  "x-read-pretty"?: boolean;
56
+ "x-compile-omitted"?: string[];
56
57
  }>;
@@ -61,9 +61,9 @@ function _react2() {
61
61
  };
62
62
  return data;
63
63
  }
64
- function _reactRouter() {
65
- const data = require("react-router");
66
- _reactRouter = function _reactRouter() {
64
+ function _reactRouterDom() {
65
+ const data = require("react-router-dom");
66
+ _reactRouterDom = function _reactRouterDom() {
67
67
  return data;
68
68
  };
69
69
  return data;
@@ -152,8 +152,8 @@ const AMapComponent = _react2().default.forwardRef((props, ref) => {
152
152
  }, [props === null || props === void 0 ? void 0 : props.type, fieldSchema === null || fieldSchema === void 0 ? void 0 : fieldSchema.name]);
153
153
  const overlay = (0, _react2().useRef)();
154
154
  const _editor = (0, _react2().useRef)(null);
155
- const history = (0, _reactRouter().useHistory)();
156
- const id = (0, _react2().useRef)(`nocobase-map-${type}-${Date.now().toString(32)}`);
155
+ const navigate = (0, _reactRouterDom().useNavigate)();
156
+ const id = (0, _react2().useRef)(`nocobase-map-${type || ''}-${Date.now().toString(32)}`);
157
157
  const _useState5 = (0, _react2().useState)(_objectSpread({
158
158
  strokeWeight: 5,
159
159
  strokeColor: '#4e9bff',
@@ -348,7 +348,7 @@ const AMapComponent = _react2().default.forwardRef((props, ref) => {
348
348
  version: '2.0',
349
349
  plugins: ['AMap.MouseTool', 'AMap.PolygonEditor', 'AMap.PolylineEditor', 'AMap.CircleEditor']
350
350
  }).then(amap => {
351
- requestIdleCallback(() => {
351
+ return requestIdleCallback(() => {
352
352
  map.current = new amap.Map(id.current, {
353
353
  resizeEnable: true,
354
354
  zoom
@@ -358,10 +358,14 @@ const AMapComponent = _react2().default.forwardRef((props, ref) => {
358
358
  forceUpdate([]);
359
359
  });
360
360
  }).catch(err => {
361
- if (err.includes('多个不一致的 key')) {
362
- setErrMessage(t('The AccessKey is incorrect, please check it'));
363
- } else {
364
- setErrMessage(err);
361
+ if (typeof err === 'string') {
362
+ if (err.includes('多个不一致的 key')) {
363
+ setErrMessage(t('The AccessKey is incorrect, please check it'));
364
+ } else {
365
+ setErrMessage(err);
366
+ }
367
+ } else if ((err === null || err === void 0 ? void 0 : err.type) === 'error') {
368
+ setErrMessage('Something went wrong, please refresh the page and try again');
365
369
  }
366
370
  });
367
371
  return () => {
@@ -389,7 +393,7 @@ const AMapComponent = _react2().default.forwardRef((props, ref) => {
389
393
  return _react2().default.createElement(_antd().Alert, {
390
394
  action: _react2().default.createElement(_antd().Button, {
391
395
  type: "primary",
392
- onClick: () => history.push('/admin/settings/map-configuration/configuration')
396
+ onClick: () => navigate('/admin/settings/map-configuration/configuration')
393
397
  }, t('Go to the configuration page')),
394
398
  message: errMessage || t('Please configure the AccessKey and SecurityJsCode first'),
395
399
  type: "error"
@@ -402,7 +406,15 @@ const AMapComponent = _react2().default.forwardRef((props, ref) => {
402
406
  `,
403
407
  id: id.current,
404
408
  style: props === null || props === void 0 ? void 0 : props.style
405
- }, !disabled ? _react2().default.createElement(_react2().default.Fragment, null, _react2().default.createElement(_Search.default, {
409
+ }, !aMap.current && _react2().default.createElement("div", {
410
+ className: (0, _css().css)`
411
+ position: absolute;
412
+ inset: 0;
413
+ display: flex;
414
+ align-items: center;
415
+ justify-content: center;
416
+ `
417
+ }, _react2().default.createElement(_antd().Spin, null)), !disabled ? _react2().default.createElement(_react2().default.Fragment, null, _react2().default.createElement(_Search.default, {
406
418
  toCenter: toCenter,
407
419
  aMap: aMap.current
408
420
  }), _react2().default.createElement("div", {
@@ -1,2 +1,3 @@
1
- declare const Configuration: () => JSX.Element;
1
+ import React from 'react';
2
+ declare const Configuration: () => React.JSX.Element;
2
3
  export default Configuration;
@@ -1,2 +1,3 @@
1
- declare const Designer: () => JSX.Element;
1
+ import React from 'react';
2
+ declare const Designer: () => React.JSX.Element;
2
3
  export default Designer;
@@ -1,2 +1,3 @@
1
- declare const ReadPretty: (props: any) => JSX.Element;
1
+ import React from 'react';
2
+ declare const ReadPretty: (props: any) => React.JSX.Element;
2
3
  export default ReadPretty;
@@ -1,6 +1,7 @@
1
+ import React from 'react';
1
2
  interface SearchProps {
2
3
  aMap: any;
3
4
  toCenter: (p: any) => void;
4
5
  }
5
- declare const Search: (props: SearchProps) => JSX.Element;
6
+ declare const Search: (props: SearchProps) => React.JSX.Element;
6
7
  export default Search;
@@ -1,4 +1,4 @@
1
1
  import React from 'react';
2
2
  import './locale';
3
- declare const _default: React.NamedExoticComponent<object>;
4
- export default _default;
3
+ declare const MapProvider: React.NamedExoticComponent<object>;
4
+ export default MapProvider;
@@ -32,7 +32,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
32
32
  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; }
33
33
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
34
34
  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); }
35
- var _default = _react().default.memo(props => {
35
+ const MapProvider = _react().default.memo(props => {
36
36
  const ctx = (0, _react().useContext)(_client().CollectionManagerContext);
37
37
  const _useMapTranslation = (0, _locale.useMapTranslation)(),
38
38
  t = _useMapTranslation.t;
@@ -59,4 +59,6 @@ var _default = _react().default.memo(props => {
59
59
  })
60
60
  }, props.children))))));
61
61
  });
62
+ MapProvider.displayName = 'MapProvider';
63
+ var _default = MapProvider;
62
64
  exports.default = _default;
package/package.json CHANGED
@@ -2,19 +2,19 @@
2
2
  "name": "@nocobase/plugin-map",
3
3
  "displayName": "Map",
4
4
  "displayName.zh-CN": "地图",
5
- "version": "0.9.4-alpha.2",
5
+ "version": "0.10.0-alpha.2",
6
6
  "description": "Provide map fields and blocks",
7
7
  "description.zh-CN": "提供地图字段和区块",
8
8
  "license": "AGPL-3.0",
9
9
  "main": "./lib/index.js",
10
10
  "types": "./lib/index.d.ts",
11
11
  "devDependencies": {
12
- "@nocobase/server": "0.9.4-alpha.2",
13
- "@nocobase/test": "0.9.4-alpha.2"
12
+ "@nocobase/server": "0.10.0-alpha.2",
13
+ "@nocobase/test": "0.10.0-alpha.2"
14
14
  },
15
15
  "dependencies": {
16
16
  "@amap/amap-jsapi-loader": "^1.0.1",
17
17
  "@amap/amap-jsapi-types": "^0.0.10"
18
18
  },
19
- "gitHead": "2bc19a85bf9425aa220b6c467315c8087f333a7e"
19
+ "gitHead": "85028ae1733fcbd46ecd5d291dacbdc175f7f073"
20
20
  }
@@ -1,7 +1,14 @@
1
1
  import { CheckOutlined, EnvironmentOutlined, ExpandOutlined } from '@ant-design/icons';
2
2
  import { css } from '@emotion/css';
3
3
  import { RecursionField, Schema, useFieldSchema } from '@formily/react';
4
- import { ActionContext, RecordProvider, useCollection, useCompile, useFilterAPI, useProps } from '@nocobase/client';
4
+ import {
5
+ ActionContextProvider,
6
+ RecordProvider,
7
+ useCollection,
8
+ useCompile,
9
+ useFilterAPI,
10
+ useProps,
11
+ } from '@nocobase/client';
5
12
  import { useMemoizedFn } from 'ahooks';
6
13
  import { Button, Space } from 'antd';
7
14
  import React, { useEffect, useMemo, useRef, useState } from 'react';
@@ -272,11 +279,11 @@ const MapBlockDrawer = (props) => {
272
279
 
273
280
  return (
274
281
  schema && (
275
- <ActionContext.Provider value={{ visible: !!record, setVisible }}>
282
+ <ActionContextProvider value={{ visible: !!record, setVisible }}>
276
283
  <RecordProvider record={record}>
277
284
  <RecursionField schema={schema} name={schema.name} />
278
285
  </RecordProvider>
279
- </ActionContext.Provider>
286
+ </ActionContextProvider>
280
287
  )
281
288
  );
282
289
  };
@@ -8,7 +8,7 @@ import { MapBlockInitializer } from './MapBlockInitializer';
8
8
  import { MapBlockProvider, useMapBlockProps } from './MapBlockProvider';
9
9
 
10
10
  export const MapBlockOptions: React.FC = (props) => {
11
- const items = useContext(SchemaInitializerContext);
11
+ const items = useContext<any>(SchemaInitializerContext);
12
12
  const children = items.BlockInitializers.items[0].children;
13
13
 
14
14
  useEffect(() => {
@@ -5,9 +5,9 @@ import { css } from '@emotion/css';
5
5
  import { useFieldSchema } from '@formily/react';
6
6
  import { useCollection } from '@nocobase/client';
7
7
  import { useMemoizedFn } from 'ahooks';
8
- import { Alert, Button, Modal } from 'antd';
8
+ import { Alert, Button, Modal, Spin } from 'antd';
9
9
  import React, { useEffect, useCallback, useRef, useState, useMemo, useImperativeHandle } from 'react';
10
- import { useHistory } from 'react-router';
10
+ import { useNavigate } from 'react-router-dom';
11
11
  import { useMapConfiguration } from '../hooks';
12
12
  import { useMapTranslation } from '../locale';
13
13
  import Search from './Search';
@@ -101,8 +101,8 @@ const AMapComponent = React.forwardRef<AMapForwardedRefProps, AMapComponentProps
101
101
 
102
102
  const overlay = useRef<AMap.Polygon>();
103
103
  const editor = useRef(null);
104
- const history = useHistory();
105
- const id = useRef(`nocobase-map-${type}-${Date.now().toString(32)}`);
104
+ const navigate = useNavigate();
105
+ const id = useRef(`nocobase-map-${type || ''}-${Date.now().toString(32)}`);
106
106
 
107
107
  const [commonOptions] = useState<AMap.PolylineOptions & AMap.PolygonOptions>({
108
108
  strokeWeight: 5,
@@ -316,7 +316,7 @@ const AMapComponent = React.forwardRef<AMapForwardedRefProps, AMapComponentProps
316
316
  plugins: ['AMap.MouseTool', 'AMap.PolygonEditor', 'AMap.PolylineEditor', 'AMap.CircleEditor'],
317
317
  })
318
318
  .then((amap) => {
319
- requestIdleCallback(() => {
319
+ return requestIdleCallback(() => {
320
320
  map.current = new amap.Map(id.current, {
321
321
  resizeEnable: true,
322
322
  zoom,
@@ -327,10 +327,14 @@ const AMapComponent = React.forwardRef<AMapForwardedRefProps, AMapComponentProps
327
327
  });
328
328
  })
329
329
  .catch((err) => {
330
- if (err.includes('多个不一致的 key')) {
331
- setErrMessage(t('The AccessKey is incorrect, please check it'));
332
- } else {
333
- setErrMessage(err);
330
+ if (typeof err === 'string') {
331
+ if (err.includes('多个不一致的 key')) {
332
+ setErrMessage(t('The AccessKey is incorrect, please check it'));
333
+ } else {
334
+ setErrMessage(err);
335
+ }
336
+ } else if (err?.type === 'error') {
337
+ setErrMessage('Something went wrong, please refresh the page and try again');
334
338
  }
335
339
  });
336
340
 
@@ -360,7 +364,7 @@ const AMapComponent = React.forwardRef<AMapForwardedRefProps, AMapComponentProps
360
364
  return (
361
365
  <Alert
362
366
  action={
363
- <Button type="primary" onClick={() => history.push('/admin/settings/map-configuration/configuration')}>
367
+ <Button type="primary" onClick={() => navigate('/admin/settings/map-configuration/configuration')}>
364
368
  {t('Go to the configuration page')}
365
369
  </Button>
366
370
  }
@@ -379,6 +383,19 @@ const AMapComponent = React.forwardRef<AMapForwardedRefProps, AMapComponentProps
379
383
  id={id.current}
380
384
  style={props?.style}
381
385
  >
386
+ {!aMap.current && (
387
+ <div
388
+ className={css`
389
+ position: absolute;
390
+ inset: 0;
391
+ display: flex;
392
+ align-items: center;
393
+ justify-content: center;
394
+ `}
395
+ >
396
+ <Spin />
397
+ </div>
398
+ )}
382
399
  {!disabled ? (
383
400
  <>
384
401
  <Search toCenter={toCenter} aMap={aMap.current} />
@@ -13,7 +13,7 @@ import { MapInitializer } from './initialize';
13
13
  import { useMapTranslation } from './locale';
14
14
  import './locale';
15
15
 
16
- export default React.memo((props) => {
16
+ const MapProvider = React.memo((props) => {
17
17
  const ctx = useContext(CollectionManagerContext);
18
18
  const { t } = useMapTranslation();
19
19
  return (
@@ -45,3 +45,6 @@ export default React.memo((props) => {
45
45
  </CurrentAppInfoProvider>
46
46
  );
47
47
  });
48
+ MapProvider.displayName = 'MapProvider';
49
+
50
+ export default MapProvider;