@nocobase/plugin-charts 0.10.1-alpha.1 → 0.11.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/client.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- // @ts-nocheck
2
- export * from './lib/client';
3
- export { default } from './lib/client';
1
+ export * from './src/client';
2
+ export { default } from './src/client';
4
3
 
package/client.js CHANGED
@@ -1,30 +1 @@
1
- "use strict";
2
-
3
- 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); }
4
-
5
- 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; }
6
-
7
- var _index = _interopRequireWildcard(require("./lib/client"));
8
-
9
- Object.defineProperty(exports, "__esModule", {
10
- value: true
11
- });
12
- var _exportNames = {};
13
- Object.defineProperty(exports, "default", {
14
- enumerable: true,
15
- get: function get() {
16
- return _index.default;
17
- }
18
- });
19
-
20
- Object.keys(_index).forEach(function (key) {
21
- if (key === "default" || key === "__esModule") return;
22
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
23
- if (key in exports && exports[key] === _index[key]) return;
24
- Object.defineProperty(exports, key, {
25
- enumerable: true,
26
- get: function get() {
27
- return _index[key];
28
- }
29
- });
30
- });
1
+ module.exports = require('./lib/client/index.js');
@@ -15,9 +15,9 @@ export interface ChartBlockEngineMetaData {
15
15
  chart: IChartConfig;
16
16
  }
17
17
  export declare const useGetDataSet: (chartQueryId: number) => {
18
- loading: any;
18
+ loading: boolean;
19
19
  dataSet: any;
20
- error: any;
20
+ error: Error;
21
21
  };
22
22
  declare const ChartBlockEngine: {
23
23
  ({ chartBlockEngineMetaData }: {
@@ -63,11 +63,6 @@ const ChartRenderComponent = ({
63
63
  loading = _useGetDataSet.loading,
64
64
  dataSet = _useGetDataSet.dataSet,
65
65
  error = _useGetDataSet.error;
66
- if (error) {
67
- return _react().default.createElement(_react().default.Fragment, null, _react().default.createElement(_antd().Empty, {
68
- description: _react().default.createElement("span", null, "May be this chart block's query data has been deleted,please check!")
69
- }));
70
- }
71
66
  const _useState = (0, _react().useState)({}),
72
67
  _useState2 = _slicedToArray(_useState, 2),
73
68
  currentConfig = _useState2[0],
@@ -75,6 +70,11 @@ const ChartRenderComponent = ({
75
70
  (0, _react().useEffect)(() => {
76
71
  setCurrentConfig(chartConfig);
77
72
  }, [JSON.stringify(chartConfig)]);
73
+ if (error) {
74
+ return _react().default.createElement(_react().default.Fragment, null, _react().default.createElement(_antd().Empty, {
75
+ description: _react().default.createElement("span", null, `May be this chart block's query data has been deleted,please check!`)
76
+ }));
77
+ }
78
78
  if (currentConfig.type !== chartConfig.type) {
79
79
  return _react().default.createElement(_react().default.Fragment, null);
80
80
  }
@@ -82,8 +82,7 @@ const ChartRenderComponent = ({
82
82
  case 'G2Plot':
83
83
  {
84
84
  var _templates$get2, _chartConfig$category;
85
- let finalChartOptions;
86
- finalChartOptions = (_templates$get2 = _templates.templates.get(chartType)) === null || _templates$get2 === void 0 ? void 0 : _templates$get2.defaultChartOptions;
85
+ const finalChartOptions = (_templates$get2 = _templates.templates.get(chartType)) === null || _templates$get2 === void 0 ? void 0 : _templates$get2.defaultChartOptions;
87
86
  let template;
88
87
  try {
89
88
  template = _json().default.parse(chartConfig === null || chartConfig === void 0 ? void 0 : chartConfig.template);
@@ -4,16 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.jsonConfigDesc = exports.ChartBlockEngineDesignerInitializer = exports.ChartBlockEngineDesigner = void 0;
7
- function _css() {
8
- const data = require("@emotion/css");
9
- _css = function _css() {
10
- return data;
11
- };
12
- return data;
13
- }
14
- function _antd() {
15
- const data = require("@formily/antd");
16
- _antd = function _antd() {
7
+ function _antdV() {
8
+ const data = require("@formily/antd-v5");
9
+ _antdV = function _antdV() {
17
10
  return data;
18
11
  };
19
12
  return data;
@@ -32,9 +25,16 @@ function _client() {
32
25
  };
33
26
  return data;
34
27
  }
35
- function _antd2() {
28
+ function _client2() {
29
+ const data = require("@nocobase/utils/client");
30
+ _client2 = function _client2() {
31
+ return data;
32
+ };
33
+ return data;
34
+ }
35
+ function _antd() {
36
36
  const data = require("antd");
37
- _antd2 = function _antd2() {
37
+ _antd = function _antd() {
38
38
  return data;
39
39
  };
40
40
  return data;
@@ -136,6 +136,8 @@ const ChartBlockEngineDesignerInitializer = props => {
136
136
  query = chartBlockEngineMetaData.query;
137
137
  const _useFieldsById = (0, _hooks.useFieldsById)(query.id),
138
138
  fields = _useFieldsById.fields;
139
+ const _useGlobalTheme = (0, _client().useGlobalTheme)(),
140
+ theme = _useGlobalTheme.theme;
139
141
  const dataSource = fields.map(field => {
140
142
  return {
141
143
  label: field.name,
@@ -145,16 +147,16 @@ const ChartBlockEngineDesignerInitializer = props => {
145
147
  return _react2().default.createElement(_client().SchemaSettings.Item, {
146
148
  onClick: function () {
147
149
  var _onClick = _asyncToGenerator(function* () {
148
- (0, _antd().FormDialog)({
150
+ (0, _client().FormDialog)({
149
151
  okText: compile('{{t("Submit")}}'),
150
152
  title: (0, _locale.lang)('Edit chart block'),
151
153
  width: 1200,
152
154
  bodyStyle: {
153
- background: '#f0f2f5',
155
+ background: 'var(--nb-box-bg)',
154
156
  maxHeight: '65vh',
155
157
  overflow: 'auto'
156
158
  }
157
- }, form => {
159
+ }, function Com(form) {
158
160
  var _chartBlockEngineMeta, _chartBlockEngineMeta2;
159
161
  const _useState = (0, _react2().useState)(null),
160
162
  _useState2 = _slicedToArray(_useState, 2),
@@ -176,18 +178,18 @@ const ChartBlockEngineDesignerInitializer = props => {
176
178
  scope: options.scope,
177
179
  components: _objectSpread({}, options.components)
178
180
  }, _react2().default.createElement("section", {
179
- className: (0, _css().css)`
181
+ className: (0, _client().css)`
180
182
  display: flex;
181
183
  gap: 24px;
182
184
  `
183
- }, _react2().default.createElement(_antd2().Card, {
185
+ }, _react2().default.createElement(_antd().Card, {
184
186
  bordered: false,
185
187
  title: _client().i18n.t('Chart config'),
186
188
  size: 'default',
187
- className: (0, _css().css)`
189
+ className: (0, _client().css)`
188
190
  flex: 1;
189
191
  `
190
- }, _react2().default.createElement(_antd().FormLayout, {
192
+ }, _react2().default.createElement(_antdV().FormLayout, {
191
193
  layout: 'vertical'
192
194
  }, _react2().default.createElement(_client().SchemaComponent, {
193
195
  scope: {
@@ -227,11 +229,11 @@ const ChartBlockEngineDesignerInitializer = props => {
227
229
  }
228
230
  }
229
231
  }))), _react2().default.createElement("div", {
230
- className: (0, _css().css)`
232
+ className: (0, _client().css)`
231
233
  flex: 1;
232
234
  min-width: 600px;
233
235
  `
234
- }, _react2().default.createElement(_antd2().Card, {
236
+ }, _react2().default.createElement(_antd().Card, {
235
237
  size: 'default',
236
238
  title: (0, _locale.lang)('Chart preview')
237
239
  }, chartBlockEngineMetaData && _react2().default.createElement(_react2().default.Fragment, null, _react2().default.createElement(_client().SchemaComponent, {
@@ -247,10 +249,10 @@ const ChartBlockEngineDesignerInitializer = props => {
247
249
  }
248
250
  }
249
251
  }
250
- }))), _react2().default.createElement(_antd2().Card, {
252
+ }))), _react2().default.createElement(_antd().Card, {
251
253
  size: 'default',
252
254
  title: (0, _locale.lang)('Data preview'),
253
- className: (0, _css().css)`
255
+ className: (0, _client().css)`
254
256
  margin-top: 24px;
255
257
  overflow: scroll;
256
258
  `
@@ -258,7 +260,7 @@ const ChartBlockEngineDesignerInitializer = props => {
258
260
  queryId: chartBlockEngineMetaData === null || chartBlockEngineMetaData === void 0 ? void 0 : (_chartBlockEngineMeta2 = chartBlockEngineMetaData.query) === null || _chartBlockEngineMeta2 === void 0 ? void 0 : _chartBlockEngineMeta2.id,
259
261
  fields: fields
260
262
  }))))));
261
- }).open({
263
+ }, theme).open({
262
264
  initialValues: _objectSpread({}, chart) //reset before chartBlockMetaData
263
265
  }).then(values => {
264
266
  //patch updates
@@ -277,6 +279,8 @@ const ChartBlockEngineDesignerInitializer = props => {
277
279
  }
278
280
  });
279
281
  dn.refresh();
282
+ }).catch(err => {
283
+ (0, _client2().error)(err);
280
284
  });
281
285
  });
282
286
  function onClick() {
@@ -4,16 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.Options = exports.ChartBlockInitializer = void 0;
7
- function _css() {
8
- const data = require("@emotion/css");
9
- _css = function _css() {
10
- return data;
11
- };
12
- return data;
13
- }
14
- function _antd() {
15
- const data = require("@formily/antd");
16
- _antd = function _antd() {
7
+ function _antdV() {
8
+ const data = require("@formily/antd-v5");
9
+ _antdV = function _antdV() {
17
10
  return data;
18
11
  };
19
12
  return data;
@@ -32,9 +25,9 @@ function _client() {
32
25
  };
33
26
  return data;
34
27
  }
35
- function _antd2() {
28
+ function _antd() {
36
29
  const data = require("antd");
37
- _antd2 = function _antd2() {
30
+ _antd = function _antd() {
38
31
  return data;
39
32
  };
40
33
  return data;
@@ -109,8 +102,8 @@ const ChartBlockInitializer = props => {
109
102
  const options = (0, _react2().useContext)(_react().SchemaOptionsContext);
110
103
  const api = (0, _client().useAPIClient)();
111
104
  const compile = (0, _client().useCompile)();
112
- const _useChartsTranslation = (0, _locale.useChartsTranslation)(),
113
- t = _useChartsTranslation.t;
105
+ const _useGlobalTheme = (0, _client().useGlobalTheme)(),
106
+ theme = _useGlobalTheme.theme;
114
107
  return _react2().default.createElement(_ChartQueryBlockInitializer.ChartQueryBlockInitializer, _objectSpread(_objectSpread({}, props), {}, {
115
108
  componentType: 'Charts',
116
109
  onCreateBlockSchema: function () {
@@ -123,16 +116,16 @@ const ChartBlockInitializer = props => {
123
116
  value: field.name
124
117
  };
125
118
  });
126
- const values = yield (0, _antd().FormDialog)({
119
+ const values = yield (0, _client().FormDialog)({
127
120
  okText: compile('{{t("Submit")}}'),
128
121
  title: (0, _locale.lang)('Create chart block'),
129
122
  width: 1200,
130
123
  bodyStyle: {
131
- background: '#f0f2f5',
124
+ background: 'var(--nb-box-bg)',
132
125
  maxHeight: '65vh',
133
126
  overflow: 'auto'
134
127
  }
135
- }, () => {
128
+ }, function Com() {
136
129
  var _chartBlockEngineMeta, _chartBlockEngineMeta2;
137
130
  const form = (0, _react().useForm)();
138
131
  const _useState5 = (0, _react2().useState)(null),
@@ -155,19 +148,19 @@ const ChartBlockInitializer = props => {
155
148
  scope: options.scope,
156
149
  components: _objectSpread({}, options.components)
157
150
  }, _react2().default.createElement("section", {
158
- className: (0, _css().css)`
151
+ className: (0, _client().css)`
159
152
  display: flex;
160
153
  gap: 24px;
161
154
  `
162
- }, _react2().default.createElement(_antd2().Card, {
155
+ }, _react2().default.createElement(_antd().Card, {
163
156
  title: (0, _locale.lang)('Chart config'),
164
157
  size: 'default',
165
- className: (0, _css().css)`
158
+ className: (0, _client().css)`
166
159
  flex: 1;
167
160
  `
168
161
  }, _react2().default.createElement(_client().FormProvider, {
169
162
  form: form
170
- }, _react2().default.createElement(_antd().FormLayout, {
163
+ }, _react2().default.createElement(_antdV().FormLayout, {
171
164
  layout: 'vertical'
172
165
  }, _react2().default.createElement(_client().SchemaComponent, {
173
166
  scope: {
@@ -207,11 +200,11 @@ const ChartBlockInitializer = props => {
207
200
  }
208
201
  }
209
202
  })))), _react2().default.createElement("div", {
210
- className: (0, _css().css)`
203
+ className: (0, _client().css)`
211
204
  flex: 1;
212
205
  min-width: 600px;
213
206
  `
214
- }, _react2().default.createElement(_antd2().Card, {
207
+ }, _react2().default.createElement(_antd().Card, {
215
208
  size: 'default',
216
209
  title: (0, _locale.lang)('Chart preview')
217
210
  }, chartBlockEngineMetaData && _react2().default.createElement(_react2().default.Fragment, null, _react2().default.createElement(_client().SchemaComponent, {
@@ -227,10 +220,10 @@ const ChartBlockInitializer = props => {
227
220
  }
228
221
  }
229
222
  }
230
- }))), _react2().default.createElement(_antd2().Card, {
223
+ }))), _react2().default.createElement(_antd().Card, {
231
224
  size: 'default',
232
225
  title: (0, _locale.lang)('Data preview'),
233
- className: (0, _css().css)`
226
+ className: (0, _client().css)`
234
227
  margin-top: 24px;
235
228
  overflow: scroll;
236
229
  `
@@ -238,7 +231,7 @@ const ChartBlockInitializer = props => {
238
231
  queryId: chartBlockEngineMetaData === null || chartBlockEngineMetaData === void 0 ? void 0 : (_chartBlockEngineMeta2 = chartBlockEngineMetaData.query) === null || _chartBlockEngineMeta2 === void 0 ? void 0 : _chartBlockEngineMeta2.id,
239
232
  fields: chartQueryMetadata === null || chartQueryMetadata === void 0 ? void 0 : chartQueryMetadata.fields
240
233
  }))))));
241
- }).open({
234
+ }, theme).open({
242
235
  initialValues: {}
243
236
  });
244
237
  if (values) {
@@ -11,9 +11,9 @@ function _icons() {
11
11
  };
12
12
  return data;
13
13
  }
14
- function _antd() {
15
- const data = require("@formily/antd");
16
- _antd = function _antd() {
14
+ function _antdV() {
15
+ const data = require("@formily/antd-v5");
16
+ _antdV = function _antdV() {
17
17
  return data;
18
18
  };
19
19
  return data;
@@ -73,15 +73,17 @@ const ChartQueryBlockInitializer = props => {
73
73
  const apiClient = (0, _client().useAPIClient)();
74
74
  const ctx = (0, _ChartQueryMetadataProvider.useChartQueryMetadataContext)();
75
75
  const options = (0, _react2().useContext)(_react().SchemaOptionsContext);
76
+ const _useGlobalTheme = (0, _client().useGlobalTheme)(),
77
+ theme = _useGlobalTheme.theme;
76
78
  const onAddQuery = (0, _react2().useCallback)(info => {
77
- (0, _antd().FormDialog)({
79
+ (0, _client().FormDialog)({
78
80
  sql: (0, _locale.lang)('Add SQL query'),
79
81
  json: (0, _locale.lang)('Add JSON query')
80
82
  }[info.key], () => {
81
83
  return _react2().default.createElement("div", null, _react2().default.createElement(_client().SchemaComponentOptions, {
82
84
  scope: options.scope,
83
85
  components: _objectSpread({}, options.components)
84
- }, _react2().default.createElement(_antd().FormLayout, {
86
+ }, _react2().default.createElement(_antdV().FormLayout, {
85
87
  layout: 'vertical'
86
88
  }, _react2().default.createElement(_client().SchemaComponent, {
87
89
  schema: {
@@ -97,7 +99,7 @@ const ChartQueryBlockInitializer = props => {
97
99
  }
98
100
  }
99
101
  }))));
100
- }).open({
102
+ }, theme).open({
101
103
  initialValues: {
102
104
  type: info.key
103
105
  }
@@ -105,7 +107,7 @@ const ChartQueryBlockInitializer = props => {
105
107
  var _ref = _asyncToGenerator(function* (values) {
106
108
  try {
107
109
  var _apiClient$resource;
108
- if ((_apiClient$resource = apiClient.resource('chartsQueries')) === null || _apiClient$resource === void 0 ? void 0 : _apiClient$resource.create) {
110
+ if ((_apiClient$resource = apiClient.resource('chartsQueries')) !== null && _apiClient$resource !== void 0 && _apiClient$resource.create) {
109
111
  const _yield$apiClient$reso = yield apiClient.resource('chartsQueries').create({
110
112
  values
111
113
  }),
@@ -106,8 +106,8 @@ var _default = ({
106
106
  Input: _client().Input,
107
107
  FormItem: _client().FormItem
108
108
  }
109
- }, _react().default.createElement(_client().BlockSchemaComponentProvider, null, _react().default.createElement(_client().SchemaComponent, {
109
+ }, _react().default.createElement(_client().SchemaComponent, {
110
110
  schema: schema
111
- })));
111
+ }));
112
112
  };
113
113
  exports.default = _default;
@@ -1,4 +1,6 @@
1
- import React from 'react';
1
+ import { Plugin } from '@nocobase/client';
2
2
  import './Icons';
3
- declare const Charts: React.NamedExoticComponent<object>;
4
- export default Charts;
3
+ export declare class ChartsPlugin extends Plugin {
4
+ load(): Promise<void>;
5
+ }
6
+ export default ChartsPlugin;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = void 0;
6
+ exports.default = exports.ChartsPlugin = void 0;
7
7
  function _core() {
8
8
  const data = require("@formily/core");
9
9
  _core = function _core() {
@@ -42,6 +42,8 @@ var _QueriesTable = require("./settings/QueriesTable");
42
42
  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); }
43
43
  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; }
44
44
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
45
+ 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); } }
46
+ 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); }); }; }
45
47
  (0, _core().registerValidateRules)({
46
48
  json5: (value, rule) => {
47
49
  if (!value) {
@@ -65,7 +67,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
65
67
  }
66
68
  }
67
69
  });
68
- const Charts = _react().default.memo(props => {
70
+ const ChartsProvider = _react().default.memo(props => {
69
71
  const api = (0, _client().useAPIClient)();
70
72
  const items = (0, _react().useContext)(_client().SchemaInitializerContext);
71
73
  const children = items.BlockInitializers.items[0].children;
@@ -125,6 +127,17 @@ const Charts = _react().default.memo(props => {
125
127
  value: items
126
128
  }, props.children))));
127
129
  });
128
- Charts.displayName = 'Charts';
129
- var _default = Charts;
130
+ ChartsProvider.displayName = 'ChartsProvider';
131
+ class ChartsPlugin extends _client().Plugin {
132
+ load() {
133
+ var _this = this;
134
+ return _asyncToGenerator(function* () {
135
+ _this.app.use(ChartsProvider);
136
+ // TODO: 主应用应该会有这个插件,按道理不需要再注册
137
+ _this.app.pm.add(_client().BlockSchemaComponentPlugin);
138
+ })();
139
+ }
140
+ }
141
+ exports.ChartsPlugin = ChartsPlugin;
142
+ var _default = ChartsPlugin;
130
143
  exports.default = _default;
@@ -11,13 +11,6 @@ function _icons() {
11
11
  };
12
12
  return data;
13
13
  }
14
- function _css() {
15
- const data = require("@emotion/css");
16
- _css = function _css() {
17
- return data;
18
- };
19
- return data;
20
- }
21
14
  function _react() {
22
15
  const data = require("@formily/react");
23
16
  _react = function _react() {
@@ -105,7 +98,7 @@ const InternalSelect = (0, _react().connect)(props => {
105
98
  },
106
99
  trigger: "hover"
107
100
  }, _react2().default.createElement("div", {
108
- className: (0, _css().css)`
101
+ className: (0, _client().css)`
109
102
  display: flex;
110
103
  gap: 4px;
111
104
  align-items: center;
@@ -129,7 +122,7 @@ const InternalSelect = (0, _react().connect)(props => {
129
122
  },
130
123
  trigger: "hover"
131
124
  }, _react2().default.createElement("div", {
132
- className: (0, _css().css)`
125
+ className: (0, _client().css)`
133
126
  display: flex;
134
127
  gap: 4px;
135
128
  align-items: center;
@@ -145,7 +138,7 @@ const InternalSelect = (0, _react().connect)(props => {
145
138
  loading: true
146
139
  }, (props, field) => {
147
140
  return _objectSpread(_objectSpread({}, props), {}, {
148
- suffixIcon: (field === null || field === void 0 ? void 0 : field['loading']) || (field === null || field === void 0 ? void 0 : field['validating']) ? _react2().default.createElement(_icons().LoadingOutlined, null) : props === null || props === void 0 ? void 0 : props.suffixIcon
141
+ suffixIcon: field !== null && field !== void 0 && field['loading'] || field !== null && field !== void 0 && field['validating'] ? _react2().default.createElement(_icons().LoadingOutlined, null) : props === null || props === void 0 ? void 0 : props.suffixIcon
149
142
  });
150
143
  }), (0, _react().mapReadPretty)(_ReadPretty.ReadPretty));
151
144
  const CustomSelect = InternalSelect;
@@ -1,2 +1,2 @@
1
1
  import React from 'react';
2
- export declare const ReadPretty: React.MemoExoticComponent<import("@formily/react").ReactFC<Pick<any, string | number | symbol>>>;
2
+ export declare const ReadPretty: React.MemoExoticComponent<import("@formily/react").ReactFC<Omit<any, "ref">>>;
@@ -4,9 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getCurrentOptions = exports.defaultFieldNames = void 0;
7
- function _lodash() {
8
- const data = require("lodash");
9
- _lodash = function _lodash() {
7
+ function _client() {
8
+ const data = require("@nocobase/utils/client");
9
+ _client = function _client() {
10
10
  return data;
11
11
  };
12
12
  return data;
@@ -39,7 +39,7 @@ const getCurrentOptions = (values, dataSource, fieldNames) => {
39
39
  return newArr;
40
40
  }
41
41
  const result = flatData(dataSource);
42
- values = (0, _lodash().castArray)(values).filter(item => item != null).map(val => typeof val === 'object' ? val[fieldNames.value] : val);
42
+ values = _client().lodash.castArray(values).filter(item => item != null).map(val => typeof val === 'object' ? val[fieldNames.value] : val);
43
43
  const findOptions = options => {
44
44
  if (!options) return [];
45
45
  const current = [];
@@ -4,14 +4,13 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.sql = exports.json = exports.getQueryTypeSchema = exports.api = void 0;
7
- function _cloneDeep() {
8
- const data = _interopRequireDefault(require("lodash/cloneDeep"));
9
- _cloneDeep = function _cloneDeep() {
7
+ function _client() {
8
+ const data = require("@nocobase/utils/client");
9
+ _client = function _client() {
10
10
  return data;
11
11
  };
12
12
  return data;
13
13
  }
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
14
  const json = {
16
15
  type: 'object',
17
16
  properties: {
@@ -73,6 +72,6 @@ const types = {
73
72
  api
74
73
  };
75
74
  const getQueryTypeSchema = type => {
76
- return (0, _cloneDeep().default)(types[type]);
75
+ return _client().lodash.cloneDeep(types[type]);
77
76
  };
78
77
  exports.getQueryTypeSchema = getQueryTypeSchema;
@@ -39,7 +39,7 @@ const parseDataSetString = str => {
39
39
  if (dataSetDataArray.every(item => {
40
40
  return typeof item === 'object' && Object.keys(item).length > 1;
41
41
  })) dataSetDataArray.map(item => {
42
- if (!(item === null || item === void 0 ? void 0 : item.id)) {
42
+ if (!(item !== null && item !== void 0 && item.id)) {
43
43
  item.id = (0, _shared().uid)();
44
44
  }
45
45
  return item;
@@ -1 +0,0 @@
1
-
package/package.json CHANGED
@@ -4,15 +4,37 @@
4
4
  "displayName.zh-CN": "图表",
5
5
  "description": "Out-of-the-box, feature-rich chart plugins.",
6
6
  "description.zh-CN": "开箱即用、丰富的报表。",
7
- "version": "0.10.1-alpha.1",
8
- "main": "lib/server/index.js",
9
- "devDependencies": {
10
- "@nocobase/client": "0.10.1-alpha.1",
11
- "@nocobase/server": "0.10.1-alpha.1",
12
- "@nocobase/test": "0.10.1-alpha.1"
13
- },
7
+ "version": "0.11.1-alpha.1",
8
+ "main": "./lib/server/index.js",
9
+ "files": [
10
+ "lib",
11
+ "src",
12
+ "README.md",
13
+ "README.zh-CN.md",
14
+ "CHANGELOG.md",
15
+ "server.js",
16
+ "server.d.ts",
17
+ "client.js",
18
+ "client.d.ts"
19
+ ],
14
20
  "dependencies": {
15
21
  "json5": "^2.2.3"
16
22
  },
17
- "gitHead": "8f415f5e0ee2e72d681f9ab16af5911b52c374a9"
23
+ "devDependencies": {
24
+ "@ant-design/icons": "^5.1.4",
25
+ "@formily/antd-v5": "1.1.0-beta.4",
26
+ "@formily/core": "2.2.26",
27
+ "@formily/react": "2.2.26",
28
+ "@formily/shared": "2.2.26",
29
+ "@nocobase/client": "0.11.1-alpha.1",
30
+ "@nocobase/database": "0.11.1-alpha.1",
31
+ "@nocobase/server": "0.11.1-alpha.1",
32
+ "@nocobase/test": "0.11.1-alpha.1",
33
+ "@nocobase/utils": "0.11.1-alpha.1",
34
+ "antd": "^5.6.4",
35
+ "react": "^18.2.0",
36
+ "react-i18next": "^11.15.1",
37
+ "react-router-dom": "^6.11.2"
38
+ },
39
+ "gitHead": "9ed1dba520bc5f3a7cb1255ea8d92ccbefc11bc8"
18
40
  }
package/server.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- // @ts-nocheck
2
- export * from './lib/server';
3
- export { default } from './lib/server';
1
+ export * from './src/server';
2
+ export { default } from './src/server';
4
3
 
package/server.js CHANGED
@@ -1,30 +1 @@
1
- "use strict";
2
-
3
- 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); }
4
-
5
- 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; }
6
-
7
- var _index = _interopRequireWildcard(require("./lib/server"));
8
-
9
- Object.defineProperty(exports, "__esModule", {
10
- value: true
11
- });
12
- var _exportNames = {};
13
- Object.defineProperty(exports, "default", {
14
- enumerable: true,
15
- get: function get() {
16
- return _index.default;
17
- }
18
- });
19
-
20
- Object.keys(_index).forEach(function (key) {
21
- if (key === "default" || key === "__esModule") return;
22
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
23
- if (key in exports && exports[key] === _index[key]) return;
24
- Object.defineProperty(exports, key, {
25
- enumerable: true,
26
- get: function get() {
27
- return _index[key];
28
- }
29
- });
30
- });
1
+ module.exports = require('./lib/server/index.js');
@@ -36,28 +36,27 @@ const ChartRenderComponent = ({
36
36
  const chartConfig = chartBlockEngineMetaData.chart;
37
37
  const { loading, dataSet, error } = useGetDataSet(chartBlockEngineMetaData.query.id);
38
38
 
39
+ const [currentConfig, setCurrentConfig] = useState<IChartConfig>({} as any);
40
+
41
+ useEffect(() => {
42
+ setCurrentConfig(chartConfig);
43
+ }, [JSON.stringify(chartConfig)]);
44
+
39
45
  if (error) {
40
46
  return (
41
47
  <>
42
- <Empty description={<span>May be this chart block's query data has been deleted,please check!</span>} />
48
+ <Empty description={<span>{`May be this chart block's query data has been deleted,please check!`}</span>} />
43
49
  </>
44
50
  );
45
51
  }
46
52
 
47
- const [currentConfig, setCurrentConfig] = useState<IChartConfig>({} as any);
48
-
49
- useEffect(() => {
50
- setCurrentConfig(chartConfig);
51
- }, [JSON.stringify(chartConfig)]);
52
-
53
53
  if (currentConfig.type !== chartConfig.type) {
54
54
  return <></>;
55
55
  }
56
56
 
57
57
  switch (renderComponent) {
58
58
  case 'G2Plot': {
59
- let finalChartOptions;
60
- finalChartOptions = templates.get(chartType)?.defaultChartOptions;
59
+ const finalChartOptions = templates.get(chartType)?.defaultChartOptions;
61
60
  let template;
62
61
  try {
63
62
  template = JSON5.parse(chartConfig?.template);
@@ -85,7 +84,9 @@ const ChartRenderComponent = ({
85
84
  };
86
85
 
87
86
  export const useGetDataSet = (chartQueryId: number) => {
88
- const { data, loading, error } = useRequest({
87
+ const { data, loading, error } = useRequest<{
88
+ data: any;
89
+ }>({
89
90
  url: `/chartsQueries:getData/${chartQueryId}`,
90
91
  });
91
92
  const dataSet = data?.data;
@@ -1,17 +1,20 @@
1
- import { css } from '@emotion/css';
2
- import { FormDialog, FormLayout } from '@formily/antd';
1
+ import { FormLayout } from '@formily/antd-v5';
3
2
  import { SchemaOptionsContext, useField, useFieldSchema } from '@formily/react';
4
3
  import {
5
4
  APIClientProvider,
5
+ FormDialog,
6
6
  GeneralSchemaDesigner,
7
- i18n,
8
7
  SchemaComponent,
9
8
  SchemaComponentOptions,
10
9
  SchemaSettings,
10
+ css,
11
+ i18n,
11
12
  useAPIClient,
12
13
  useCompile,
13
14
  useDesignable,
15
+ useGlobalTheme,
14
16
  } from '@nocobase/client';
17
+ import { error } from '@nocobase/utils/client';
15
18
  import { Card } from 'antd';
16
19
  import JSON5 from 'json5';
17
20
  import React, { useContext, useEffect, useState } from 'react';
@@ -81,12 +84,15 @@ export const ChartBlockEngineDesignerInitializer = (props) => {
81
84
  const compile = useCompile();
82
85
  const { chart, query } = chartBlockEngineMetaData;
83
86
  const { fields } = useFieldsById(query.id);
87
+ const { theme } = useGlobalTheme();
88
+
84
89
  const dataSource = fields.map((field) => {
85
90
  return {
86
91
  label: field.name,
87
92
  value: field.name,
88
93
  };
89
94
  });
95
+
90
96
  return (
91
97
  <SchemaSettings.Item
92
98
  onClick={async () => {
@@ -95,9 +101,9 @@ export const ChartBlockEngineDesignerInitializer = (props) => {
95
101
  okText: compile('{{t("Submit")}}'),
96
102
  title: lang('Edit chart block'),
97
103
  width: 1200,
98
- bodyStyle: { background: '#f0f2f5', maxHeight: '65vh', overflow: 'auto' },
104
+ bodyStyle: { background: 'var(--nb-box-bg)', maxHeight: '65vh', overflow: 'auto' },
99
105
  },
100
- (form) => {
106
+ function Com(form) {
101
107
  const [chartBlockEngineMetaData, setChartBlockEngineMetaData] = useState<ChartBlockEngineMetaData>(null);
102
108
  useEffect(() => {
103
109
  const chartBlockEngineMetaData = {
@@ -208,6 +214,7 @@ export const ChartBlockEngineDesignerInitializer = (props) => {
208
214
  </APIClientProvider>
209
215
  );
210
216
  },
217
+ theme,
211
218
  )
212
219
  .open({
213
220
  initialValues: { ...chart }, //reset before chartBlockMetaData
@@ -229,6 +236,9 @@ export const ChartBlockEngineDesignerInitializer = (props) => {
229
236
  },
230
237
  });
231
238
  dn.refresh();
239
+ })
240
+ .catch((err) => {
241
+ error(err);
232
242
  });
233
243
  }}
234
244
  >
@@ -1,14 +1,16 @@
1
- import { css } from '@emotion/css';
2
- import { FormDialog, FormLayout } from '@formily/antd';
1
+ import { FormLayout } from '@formily/antd-v5';
3
2
  import { Field } from '@formily/core';
4
- import { observer, RecursionField, Schema, SchemaOptionsContext, useField, useForm } from '@formily/react';
3
+ import { RecursionField, Schema, SchemaOptionsContext, observer, useField, useForm } from '@formily/react';
5
4
  import {
6
5
  APIClientProvider,
6
+ FormDialog,
7
7
  FormProvider,
8
8
  SchemaComponent,
9
9
  SchemaComponentOptions,
10
+ css,
10
11
  useAPIClient,
11
12
  useCompile,
13
+ useGlobalTheme,
12
14
  } from '@nocobase/client';
13
15
  import { Card } from 'antd';
14
16
  import JSON5 from 'json5';
@@ -17,7 +19,7 @@ import { ChartBlockEngineMetaData } from './ChartBlockEngine';
17
19
  import { jsonConfigDesc } from './ChartBlockEngineDesigner';
18
20
  import { ChartQueryBlockInitializer, ChartQueryMetadata } from './ChartQueryBlockInitializer';
19
21
  import DataSetPreviewTable from './DataSetPreviewTable';
20
- import { lang, useChartsTranslation } from './locale';
22
+ import { lang } from './locale';
21
23
  import { templates } from './templates';
22
24
 
23
25
  export const Options = observer(
@@ -57,7 +59,8 @@ export const ChartBlockInitializer = (props) => {
57
59
  const options = useContext(SchemaOptionsContext);
58
60
  const api = useAPIClient();
59
61
  const compile = useCompile();
60
- const { t } = useChartsTranslation();
62
+ const { theme } = useGlobalTheme();
63
+
61
64
  return (
62
65
  <ChartQueryBlockInitializer
63
66
  {...props}
@@ -74,9 +77,9 @@ export const ChartBlockInitializer = (props) => {
74
77
  okText: compile('{{t("Submit")}}'),
75
78
  title: lang('Create chart block'),
76
79
  width: 1200,
77
- bodyStyle: { background: '#f0f2f5', maxHeight: '65vh', overflow: 'auto' },
80
+ bodyStyle: { background: 'var(--nb-box-bg)', maxHeight: '65vh', overflow: 'auto' },
78
81
  },
79
- () => {
82
+ function Com() {
80
83
  const form = useForm<ChartFormInterface>();
81
84
  const [chartBlockEngineMetaData, setChartBlockEngineMetaData] = useState<ChartBlockEngineMetaData>(null);
82
85
  useEffect(() => {
@@ -192,6 +195,7 @@ export const ChartBlockInitializer = (props) => {
192
195
  </APIClientProvider>
193
196
  );
194
197
  },
198
+ theme,
195
199
  ).open({
196
200
  initialValues: {},
197
201
  });
@@ -1,12 +1,14 @@
1
1
  import { TableOutlined } from '@ant-design/icons';
2
- import { FormDialog, FormLayout } from '@formily/antd';
2
+ import { FormLayout } from '@formily/antd-v5';
3
3
  import { SchemaOptionsContext } from '@formily/react';
4
4
  import {
5
+ FormDialog,
5
6
  SchemaComponent,
6
7
  SchemaComponentOptions,
7
8
  SchemaInitializer,
8
9
  SchemaInitializerButtonContext,
9
10
  useAPIClient,
11
+ useGlobalTheme,
10
12
  } from '@nocobase/client';
11
13
  import { error } from '@nocobase/utils/client';
12
14
  import React, { useCallback, useContext, useMemo } from 'react';
@@ -27,6 +29,8 @@ export const ChartQueryBlockInitializer = (props) => {
27
29
  const apiClient = useAPIClient();
28
30
  const ctx = useChartQueryMetadataContext();
29
31
  const options = useContext(SchemaOptionsContext);
32
+ const { theme } = useGlobalTheme();
33
+
30
34
  const onAddQuery = useCallback(
31
35
  (info) => {
32
36
  FormDialog(
@@ -58,6 +62,7 @@ export const ChartQueryBlockInitializer = (props) => {
58
62
  </div>
59
63
  );
60
64
  },
65
+ theme,
61
66
  )
62
67
  .open({
63
68
  initialValues: {
@@ -22,7 +22,9 @@ export const ChartQueryMetadataProvider: React.FC = (props) => {
22
22
 
23
23
  const location = useLocation();
24
24
 
25
- const service = useRequest(options, {
25
+ const service = useRequest<{
26
+ data: any;
27
+ }>(options, {
26
28
  manual: true,
27
29
  });
28
30
 
@@ -1,12 +1,5 @@
1
1
  import { ISchema } from '@formily/react';
2
- import {
3
- BlockSchemaComponentProvider,
4
- FormItem,
5
- Input,
6
- SchemaComponent,
7
- SchemaComponentProvider,
8
- TableV2,
9
- } from '@nocobase/client';
2
+ import { FormItem, Input, SchemaComponent, SchemaComponentProvider, TableV2 } from '@nocobase/client';
10
3
  import { Empty, Spin } from 'antd';
11
4
  import React from 'react';
12
5
  import { useGetDataSet } from './ChartBlockEngine';
@@ -72,9 +65,7 @@ export default ({ queryId, fields }: { queryId: number; fields }) => {
72
65
  });
73
66
  return (
74
67
  <SchemaComponentProvider scope={{ dataSet }} components={{ TableV2, Input, FormItem }}>
75
- <BlockSchemaComponentProvider>
76
- <SchemaComponent schema={schema} />
77
- </BlockSchemaComponentProvider>
68
+ <SchemaComponent schema={schema} />
78
69
  </SchemaComponentProvider>
79
70
  );
80
71
  };
@@ -1,5 +1,7 @@
1
1
  import { registerValidateRules } from '@formily/core';
2
2
  import {
3
+ BlockSchemaComponentPlugin,
4
+ Plugin,
3
5
  SchemaComponentOptions,
4
6
  SchemaInitializerContext,
5
7
  SettingsCenterProvider,
@@ -39,7 +41,7 @@ registerValidateRules({
39
41
  },
40
42
  });
41
43
 
42
- const Charts = React.memo((props) => {
44
+ const ChartsProvider = React.memo((props) => {
43
45
  const api = useAPIClient();
44
46
  const items = useContext<any>(SchemaInitializerContext);
45
47
  const children = items.BlockInitializers.items[0].children;
@@ -99,6 +101,15 @@ const Charts = React.memo((props) => {
99
101
  </ChartQueryMetadataProvider>
100
102
  );
101
103
  });
102
- Charts.displayName = 'Charts';
104
+ ChartsProvider.displayName = 'ChartsProvider';
103
105
 
104
- export default Charts;
106
+ export class ChartsPlugin extends Plugin {
107
+ async load() {
108
+ this.app.use(ChartsProvider);
109
+
110
+ // TODO: 主应用应该会有这个插件,按道理不需要再注册
111
+ this.app.pm.add(BlockSchemaComponentPlugin);
112
+ }
113
+ }
114
+
115
+ export default ChartsPlugin;
@@ -1,8 +1,7 @@
1
1
  import { LoadingOutlined } from '@ant-design/icons';
2
- import { css } from '@emotion/css';
3
2
  import { connect, mapProps, mapReadPretty } from '@formily/react';
4
3
  import { isValid } from '@formily/shared';
5
- import { Icon } from '@nocobase/client';
4
+ import { css, Icon } from '@nocobase/client';
6
5
  import type { SelectProps } from 'antd';
7
6
  import { Popover, Select as AntdSelect } from 'antd';
8
7
  import React from 'react';
@@ -1,4 +1,4 @@
1
- import { castArray } from 'lodash';
1
+ import { lodash } from '@nocobase/utils/client';
2
2
 
3
3
  export const defaultFieldNames = {
4
4
  label: 'label',
@@ -20,7 +20,8 @@ export const getCurrentOptions = (values, dataSource, fieldNames) => {
20
20
  return newArr;
21
21
  }
22
22
  const result = flatData(dataSource);
23
- values = castArray(values)
23
+ values = lodash
24
+ .castArray(values)
24
25
  .filter((item) => item != null)
25
26
  .map((val) => (typeof val === 'object' ? val[fieldNames.value] : val));
26
27
  const findOptions = (options: any[]) => {
@@ -1,5 +1,6 @@
1
1
  import { ISchema } from '@formily/react';
2
- import cloneDeep from 'lodash/cloneDeep';
2
+ import { lodash } from '@nocobase/utils/client';
3
+
3
4
  export const json: ISchema = {
4
5
  type: 'object',
5
6
  properties: {
@@ -60,5 +61,5 @@ const types = {
60
61
  };
61
62
 
62
63
  export const getQueryTypeSchema = (type) => {
63
- return cloneDeep(types[type]);
64
+ return lodash.cloneDeep(types[type]);
64
65
  };