@nocobase/plugin-map 0.9.0-alpha.2 → 0.9.1-alpha.1

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.
package/README.md ADDED
@@ -0,0 +1,13 @@
1
+ # map
2
+
3
+ English | [中文](./README.zh-CN.md)
4
+
5
+ 地图插件。
6
+
7
+ ## 安装激活
8
+
9
+ ```bash
10
+ yarn pm enable map
11
+ ```
12
+
13
+ ## 使用方法
@@ -0,0 +1,13 @@
1
+ # map
2
+
3
+ [English](./README.md) | 中文
4
+
5
+ 地图插件。
6
+
7
+ ## 安装激活
8
+
9
+ ```bash
10
+ yarn pm enable map
11
+ ```
12
+
13
+ ## 使用方法
@@ -63,15 +63,15 @@ const ReadPretty = props => {
63
63
  const mapType = props.mapType || (collectionField === null || collectionField === void 0 ? void 0 : (_collectionField$uiSc = collectionField.uiSchema['x-component-props']) === null || _collectionField$uiSc === void 0 ? void 0 : _collectionField$uiSc.mapType);
64
64
  const field = (0, _react().useField)();
65
65
  (0, _react2().useEffect)(() => {
66
- if (!field.title) {
66
+ var _collectionField$uiSc2;
67
+
68
+ if (!field.title && (collectionField === null || collectionField === void 0 ? void 0 : (_collectionField$uiSc2 = collectionField.uiSchema) === null || _collectionField$uiSc2 === void 0 ? void 0 : _collectionField$uiSc2.title)) {
67
69
  field.title = collectionField.uiSchema.title;
68
70
  }
69
- }, collectionField.title);
70
- if (!readOnly) return _react2().default.createElement("div", {
71
- style: {
72
- whiteSpace: 'pre-wrap'
73
- }
74
- }, value === null || value === void 0 ? void 0 : value.map(item => Array.isArray(item) ? `(${item.join(',')})` : item).join(','));
71
+ }, collectionField === null || collectionField === void 0 ? void 0 : collectionField.title);
72
+ if (!readOnly) return _react2().default.createElement("div", null, _react2().default.createElement(_client().EllipsisWithTooltip, {
73
+ ellipsis: true
74
+ }, value === null || value === void 0 ? void 0 : value.map(item => Array.isArray(item) ? `(${item.join(',')})` : item).join(',')));
75
75
  return mapType === 'amap' ? _react2().default.createElement(_AMap.default, _objectSpread({
76
76
  mapType: mapType
77
77
  }, props)) : null;
@@ -35,62 +35,6 @@ export declare const commonSchema: {
35
35
  'x-validator': string;
36
36
  description: string;
37
37
  };
38
- type: import("@formily/react").Stringify<{
39
- [key: symbol]: any;
40
- [key: `x-${string}`]: any;
41
- [key: `x-${number}`]: any;
42
- version?: string;
43
- name?: import("@formily/react").SchemaKey;
44
- title?: any;
45
- description?: any;
46
- default?: any;
47
- readOnly?: boolean;
48
- writeOnly?: boolean;
49
- type?: import("@formily/react").SchemaTypes;
50
- enum?: import("@formily/react").SchemaEnum<any>;
51
- const?: any;
52
- multipleOf?: number;
53
- maximum?: number;
54
- exclusiveMaximum?: number;
55
- minimum?: number;
56
- exclusiveMinimum?: number;
57
- maxLength?: number;
58
- minLength?: number;
59
- pattern?: string | RegExp;
60
- maxItems?: number;
61
- minItems?: number;
62
- uniqueItems?: boolean;
63
- maxProperties?: number;
64
- minProperties?: number;
65
- required?: string | boolean | string[];
66
- format?: string;
67
- $ref?: string;
68
- $namespace?: string;
69
- definitions?: import("@formily/react").SchemaProperties<any, any, any, any, any, any, any, any>;
70
- properties?: import("@formily/react").SchemaProperties<any, any, any, any, any, any, any, any>;
71
- items?: import("@formily/react").SchemaItems<any, any, any, any, any, any, any, any>;
72
- additionalItems?: import("@formily/react").Stringify<any>;
73
- patternProperties?: import("@formily/react").SchemaProperties<any, any, any, any, any, any, any, any>;
74
- additionalProperties?: import("@formily/react").Stringify<any>;
75
- "x-value"?: any;
76
- "x-index"?: number;
77
- "x-pattern"?: any;
78
- "x-display"?: any;
79
- "x-validator"?: any;
80
- "x-decorator"?: any;
81
- "x-decorator-props"?: any;
82
- "x-component"?: any;
83
- "x-component-props"?: any;
84
- "x-reactions"?: import("@formily/react").SchemaReactions<any>;
85
- "x-content"?: any;
86
- "x-data"?: any;
87
- "x-visible"?: boolean;
88
- "x-hidden"?: boolean;
89
- "x-disabled"?: boolean;
90
- "x-editable"?: boolean;
91
- "x-read-only"?: boolean;
92
- "x-read-pretty"?: boolean;
93
- }>;
94
38
  };
95
39
  schemaInitialize(schema: ISchema, { readPretty, block }: {
96
40
  readPretty: any;
@@ -27,8 +27,8 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
27
27
 
28
28
  const defaultProps = _client().interfacesProperties.defaultProps;
29
29
 
30
- if (Array.isArray(defaultProps.type.enum)) {
31
- defaultProps.type.enum.push({
30
+ if (Array.isArray(_client().interfacesProperties.type.enum)) {
31
+ _client().interfacesProperties.type.enum.push({
32
32
  label: 'Point',
33
33
  value: 'point'
34
34
  }, {
@@ -8,6 +8,8 @@ exports.default = void 0;
8
8
  var _constants = require("../constants");
9
9
 
10
10
  var _default = {
11
+ namespace: 'map',
12
+ duplicator: 'optional',
11
13
  name: _constants.MapConfigurationCollectionName,
12
14
  title: '{{t("Map Manager")}}',
13
15
  fields: [{
@@ -29,6 +29,8 @@ var _actions = require("./actions");
29
29
 
30
30
  var _fields = require("./fields");
31
31
 
32
+ var _valueParsers = require("./value-parsers");
33
+
32
34
  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); } }
33
35
 
34
36
  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); }); }; }
@@ -44,6 +46,12 @@ class MapPlugin extends _server().Plugin {
44
46
  circle: _fields.CircleField
45
47
  };
46
48
  this.db.registerFieldTypes(fields);
49
+ this.db.registerFieldValueParsers({
50
+ point: _valueParsers.PointValueParser,
51
+ polygon: _valueParsers.PolygonValueParser,
52
+ lineString: _valueParsers.LineStringValueParser,
53
+ circle: _valueParsers.CircleValueParser
54
+ });
47
55
  }
48
56
 
49
57
  load() {
@@ -0,0 +1,13 @@
1
+ import { BaseValueParser } from '@nocobase/database';
2
+ export declare class PointValueParser extends BaseValueParser {
3
+ setValue(value: any): Promise<void>;
4
+ }
5
+ export declare class PolygonValueParser extends BaseValueParser {
6
+ setValue(value: any): Promise<void>;
7
+ }
8
+ export declare class LineStringValueParser extends BaseValueParser {
9
+ setValue(value: any): Promise<void>;
10
+ }
11
+ export declare class CircleValueParser extends BaseValueParser {
12
+ setValue(value: any): Promise<void>;
13
+ }
@@ -0,0 +1,96 @@
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
+
8
+ function _database() {
9
+ const data = require("@nocobase/database");
10
+
11
+ _database = function _database() {
12
+ return data;
13
+ };
14
+
15
+ return data;
16
+ }
17
+
18
+ function 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); } }
19
+
20
+ 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); }); }; }
21
+
22
+ class PointValueParser extends _database().BaseValueParser {
23
+ setValue(value) {
24
+ var _this = this;
25
+
26
+ return _asyncToGenerator(function* () {
27
+ if (Array.isArray(value)) {
28
+ _this.value = value;
29
+ } else if (typeof value === 'string') {
30
+ _this.value = value.split(',');
31
+ } else {
32
+ _this.errors.push('Value invalid');
33
+ }
34
+ })();
35
+ }
36
+
37
+ }
38
+
39
+ exports.PointValueParser = PointValueParser;
40
+
41
+ class PolygonValueParser extends _database().BaseValueParser {
42
+ setValue(value) {
43
+ var _this2 = this;
44
+
45
+ return _asyncToGenerator(function* () {
46
+ if (Array.isArray(value)) {
47
+ _this2.value = value;
48
+ } else if (typeof value === 'string') {
49
+ _this2.value = value.substring(1, value.length - 1).split('),(').map(v => v.split(','));
50
+ } else {
51
+ _this2.errors.push('Value invalid');
52
+ }
53
+ })();
54
+ }
55
+
56
+ }
57
+
58
+ exports.PolygonValueParser = PolygonValueParser;
59
+
60
+ class LineStringValueParser extends _database().BaseValueParser {
61
+ setValue(value) {
62
+ var _this3 = this;
63
+
64
+ return _asyncToGenerator(function* () {
65
+ if (Array.isArray(value)) {
66
+ _this3.value = value;
67
+ } else if (typeof value === 'string') {
68
+ _this3.value = value.substring(1, value.length - 1).split('),(').map(v => v.split(','));
69
+ } else {
70
+ _this3.errors.push('Value invalid');
71
+ }
72
+ })();
73
+ }
74
+
75
+ }
76
+
77
+ exports.LineStringValueParser = LineStringValueParser;
78
+
79
+ class CircleValueParser extends _database().BaseValueParser {
80
+ setValue(value) {
81
+ var _this4 = this;
82
+
83
+ return _asyncToGenerator(function* () {
84
+ if (Array.isArray(value)) {
85
+ _this4.value = value;
86
+ } else if (typeof value === 'string') {
87
+ _this4.value = value.split(',');
88
+ } else {
89
+ _this4.errors.push('Value invalid');
90
+ }
91
+ })();
92
+ }
93
+
94
+ }
95
+
96
+ exports.CircleValueParser = CircleValueParser;
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@nocobase/plugin-map",
3
- "version": "0.9.0-alpha.2",
3
+ "version": "0.9.1-alpha.1",
4
4
  "description": "",
5
5
  "license": "AGPL-3.0",
6
6
  "main": "./lib/index.js",
7
7
  "types": "./lib/index.d.ts",
8
8
  "devDependencies": {
9
- "@nocobase/server": "0.9.0-alpha.2",
10
- "@nocobase/test": "0.9.0-alpha.2"
9
+ "@nocobase/server": "0.9.1-alpha.1",
10
+ "@nocobase/test": "0.9.1-alpha.1"
11
11
  },
12
12
  "dependencies": {
13
13
  "@amap/amap-jsapi-loader": "^1.0.1",
14
14
  "@amap/amap-jsapi-types": "^0.0.10"
15
15
  },
16
- "gitHead": "b8f76ad38e60e677c5bb4aab0a4cdb28d98a0f49"
16
+ "gitHead": "56cb184b00dc383b853015d525bf6e79dea92169"
17
17
  }
@@ -1,5 +1,5 @@
1
1
  import { useField, useFieldSchema } from '@formily/react';
2
- import { useCollection } from '@nocobase/client';
2
+ import { EllipsisWithTooltip, useCollection } from '@nocobase/client';
3
3
  import React, { useEffect } from 'react';
4
4
  import AMapComponent from './AMap';
5
5
 
@@ -12,19 +12,17 @@ const ReadPretty = (props) => {
12
12
  const field = useField();
13
13
 
14
14
  useEffect(() => {
15
- if (!field.title) {
15
+ if (!field.title && collectionField?.uiSchema?.title) {
16
16
  field.title = collectionField.uiSchema.title;
17
17
  }
18
- }, collectionField.title);
18
+ }, collectionField?.title);
19
19
 
20
20
  if (!readOnly)
21
21
  return (
22
- <div
23
- style={{
24
- whiteSpace: 'pre-wrap',
25
- }}
26
- >
27
- {value?.map((item) => (Array.isArray(item) ? `(${item.join(',')})` : item)).join(',')}
22
+ <div>
23
+ <EllipsisWithTooltip ellipsis={true}>
24
+ {value?.map((item) => (Array.isArray(item) ? `(${item.join(',')})` : item)).join(',')}
25
+ </EllipsisWithTooltip>
28
26
  </div>
29
27
  );
30
28
 
@@ -5,8 +5,8 @@ import { generateNTemplate } from '../locale';
5
5
 
6
6
  const { defaultProps } = interfacesProperties;
7
7
 
8
- if (Array.isArray(defaultProps.type.enum)) {
9
- defaultProps.type.enum.push(
8
+ if (Array.isArray(interfacesProperties.type.enum)) {
9
+ interfacesProperties.type.enum.push(
10
10
  {
11
11
  label: 'Point',
12
12
  value: 'point',
@@ -2,6 +2,8 @@ import { CollectionOptions } from "@nocobase/client";
2
2
  import { MapConfigurationCollectionName } from "../constants";
3
3
 
4
4
  export default {
5
+ namespace: 'map',
6
+ duplicator: 'optional',
5
7
  name: MapConfigurationCollectionName,
6
8
  title: '{{t("Map Manager")}}',
7
9
  fields: [
@@ -2,6 +2,7 @@ import { InstallOptions, Plugin } from '@nocobase/server';
2
2
  import { resolve } from 'path';
3
3
  import { getConfiguration, setConfiguration } from './actions';
4
4
  import { CircleField, LineStringField, PointField, PolygonField } from './fields';
5
+ import { CircleValueParser, LineStringValueParser, PointValueParser, PolygonValueParser } from './value-parsers';
5
6
 
6
7
  export class MapPlugin extends Plugin {
7
8
  afterAdd() {}
@@ -13,8 +14,13 @@ export class MapPlugin extends Plugin {
13
14
  lineString: LineStringField,
14
15
  circle: CircleField,
15
16
  };
16
-
17
17
  this.db.registerFieldTypes(fields);
18
+ this.db.registerFieldValueParsers({
19
+ point: PointValueParser,
20
+ polygon: PolygonValueParser,
21
+ lineString: LineStringValueParser,
22
+ circle: CircleValueParser,
23
+ });
18
24
  }
19
25
 
20
26
  async load() {
@@ -0,0 +1,55 @@
1
+ import { BaseValueParser } from '@nocobase/database';
2
+
3
+ export class PointValueParser extends BaseValueParser {
4
+ async setValue(value) {
5
+ if (Array.isArray(value)) {
6
+ this.value = value;
7
+ } else if (typeof value === 'string') {
8
+ this.value = value.split(',');
9
+ } else {
10
+ this.errors.push('Value invalid');
11
+ }
12
+ }
13
+ }
14
+
15
+ export class PolygonValueParser extends BaseValueParser {
16
+ async setValue(value) {
17
+ if (Array.isArray(value)) {
18
+ this.value = value;
19
+ } else if (typeof value === 'string') {
20
+ this.value = value
21
+ .substring(1, value.length - 1)
22
+ .split('),(')
23
+ .map((v) => v.split(','));
24
+ } else {
25
+ this.errors.push('Value invalid');
26
+ }
27
+ }
28
+ }
29
+
30
+ export class LineStringValueParser extends BaseValueParser {
31
+ async setValue(value) {
32
+ if (Array.isArray(value)) {
33
+ this.value = value;
34
+ } else if (typeof value === 'string') {
35
+ this.value = value
36
+ .substring(1, value.length - 1)
37
+ .split('),(')
38
+ .map((v) => v.split(','));
39
+ } else {
40
+ this.errors.push('Value invalid');
41
+ }
42
+ }
43
+ }
44
+
45
+ export class CircleValueParser extends BaseValueParser {
46
+ async setValue(value) {
47
+ if (Array.isArray(value)) {
48
+ this.value = value;
49
+ } else if (typeof value === 'string') {
50
+ this.value = value.split(',');
51
+ } else {
52
+ this.errors.push('Value invalid');
53
+ }
54
+ }
55
+ }