@nocobase/plugin-data-visualization 0.10.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.
Files changed (108) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +88 -0
  3. package/client.d.ts +3 -0
  4. package/client.js +65 -0
  5. package/lib/client/Settings.d.ts +2 -0
  6. package/lib/client/Settings.js +81 -0
  7. package/lib/client/block/ChartBlock.d.ts +2 -0
  8. package/lib/client/block/ChartBlock.js +73 -0
  9. package/lib/client/block/ChartBlockDesigner.d.ts +2 -0
  10. package/lib/client/block/ChartBlockDesigner.js +35 -0
  11. package/lib/client/block/ChartBlockInitializer.d.ts +6 -0
  12. package/lib/client/block/ChartBlockInitializer.js +114 -0
  13. package/lib/client/block/ChartConfigure.d.ts +33 -0
  14. package/lib/client/block/ChartConfigure.js +501 -0
  15. package/lib/client/block/formatters.d.ts +15 -0
  16. package/lib/client/block/formatters.js +58 -0
  17. package/lib/client/block/index.d.ts +4 -0
  18. package/lib/client/block/index.js +49 -0
  19. package/lib/client/block/schemas/configure.d.ts +4 -0
  20. package/lib/client/block/schemas/configure.js +492 -0
  21. package/lib/client/block/transformers.d.ts +6 -0
  22. package/lib/client/block/transformers.js +69 -0
  23. package/lib/client/hooks.d.ts +312 -0
  24. package/lib/client/hooks.js +275 -0
  25. package/lib/client/index.d.ts +5 -0
  26. package/lib/client/index.js +70 -0
  27. package/lib/client/locale/en-US.d.ts +23 -0
  28. package/lib/client/locale/en-US.js +29 -0
  29. package/lib/client/locale/index.d.ts +3 -0
  30. package/lib/client/locale/index.js +39 -0
  31. package/lib/client/locale/ja-JP.d.ts +2 -0
  32. package/lib/client/locale/ja-JP.js +8 -0
  33. package/lib/client/locale/pt-BR.d.ts +23 -0
  34. package/lib/client/locale/pt-BR.js +29 -0
  35. package/lib/client/locale/ru-RU.d.ts +2 -0
  36. package/lib/client/locale/ru-RU.js +8 -0
  37. package/lib/client/locale/tr-TR.d.ts +2 -0
  38. package/lib/client/locale/tr-TR.js +8 -0
  39. package/lib/client/locale/zh-CN.d.ts +70 -0
  40. package/lib/client/locale/zh-CN.js +76 -0
  41. package/lib/client/renderer/ChartLibrary.d.ts +71 -0
  42. package/lib/client/renderer/ChartLibrary.js +140 -0
  43. package/lib/client/renderer/ChartRenderer.d.ts +7 -0
  44. package/lib/client/renderer/ChartRenderer.js +258 -0
  45. package/lib/client/renderer/ChartRendererProvider.d.ts +43 -0
  46. package/lib/client/renderer/ChartRendererProvider.js +38 -0
  47. package/lib/client/renderer/index.d.ts +4 -0
  48. package/lib/client/renderer/index.js +49 -0
  49. package/lib/client/renderer/library/AntdLibrary.d.ts +2 -0
  50. package/lib/client/renderer/library/AntdLibrary.js +123 -0
  51. package/lib/client/renderer/library/G2PlotLibrary.d.ts +2 -0
  52. package/lib/client/renderer/library/G2PlotLibrary.js +288 -0
  53. package/lib/client/renderer/library/index.d.ts +3 -0
  54. package/lib/client/renderer/library/index.js +15 -0
  55. package/lib/client/utils.d.ts +96 -0
  56. package/lib/client/utils.js +137 -0
  57. package/lib/index.d.ts +1 -0
  58. package/lib/index.js +13 -0
  59. package/lib/server/actions/formatter.d.ts +3 -0
  60. package/lib/server/actions/formatter.js +44 -0
  61. package/lib/server/actions/query.d.ts +86 -0
  62. package/lib/server/actions/query.js +326 -0
  63. package/lib/server/index.d.ts +1 -0
  64. package/lib/server/index.js +13 -0
  65. package/lib/server/plugin.d.ts +13 -0
  66. package/lib/server/plugin.js +64 -0
  67. package/package.json +23 -0
  68. package/server.d.ts +3 -0
  69. package/server.js +65 -0
  70. package/src/client/Settings.tsx +43 -0
  71. package/src/client/__tests__/chart-configure.test.tsx +14 -0
  72. package/src/client/__tests__/chart-library.test.ts +78 -0
  73. package/src/client/__tests__/chart-renderer.test.tsx +30 -0
  74. package/src/client/__tests__/hooks.test.ts +261 -0
  75. package/src/client/block/ChartBlock.tsx +22 -0
  76. package/src/client/block/ChartBlockDesigner.tsx +19 -0
  77. package/src/client/block/ChartBlockInitializer.tsx +83 -0
  78. package/src/client/block/ChartConfigure.tsx +450 -0
  79. package/src/client/block/formatters.ts +70 -0
  80. package/src/client/block/index.ts +4 -0
  81. package/src/client/block/schemas/configure.ts +474 -0
  82. package/src/client/block/transformers.ts +52 -0
  83. package/src/client/hooks.ts +239 -0
  84. package/src/client/index.tsx +41 -0
  85. package/src/client/locale/en-US.ts +23 -0
  86. package/src/client/locale/index.ts +19 -0
  87. package/src/client/locale/ja-JP.ts +1 -0
  88. package/src/client/locale/pt-BR.ts +23 -0
  89. package/src/client/locale/ru-RU.ts +1 -0
  90. package/src/client/locale/tr-TR.ts +1 -0
  91. package/src/client/locale/zh-CN.ts +71 -0
  92. package/src/client/renderer/ChartLibrary.tsx +178 -0
  93. package/src/client/renderer/ChartRenderer.tsx +201 -0
  94. package/src/client/renderer/ChartRendererProvider.tsx +58 -0
  95. package/src/client/renderer/index.ts +4 -0
  96. package/src/client/renderer/library/AntdLibrary.tsx +94 -0
  97. package/src/client/renderer/library/G2PlotLibrary.tsx +236 -0
  98. package/src/client/renderer/library/index.tsx +4 -0
  99. package/src/client/utils.ts +102 -0
  100. package/src/index.ts +1 -0
  101. package/src/server/__tests__/api.test.ts +105 -0
  102. package/src/server/__tests__/formatter.test.ts +49 -0
  103. package/src/server/__tests__/query.test.ts +220 -0
  104. package/src/server/actions/formatter.ts +49 -0
  105. package/src/server/actions/query.ts +285 -0
  106. package/src/server/collections/.gitkeep +0 -0
  107. package/src/server/index.ts +1 -0
  108. package/src/server/plugin.ts +37 -0
@@ -0,0 +1,288 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.G2PlotLibrary = void 0;
7
+ function _plots() {
8
+ const data = require("@ant-design/plots");
9
+ _plots = function _plots() {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ var _locale = require("../../locale");
15
+ var _ChartLibrary = require("../ChartLibrary");
16
+ 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; }
17
+ 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; }
18
+ 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; }
19
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
20
+ 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); }
21
+ const init = _ChartLibrary.commonInit;
22
+ const basicSchema = {
23
+ type: 'object',
24
+ properties: {
25
+ xField: {
26
+ title: (0, _locale.lang)('xField'),
27
+ type: 'string',
28
+ 'x-decorator': 'FormItem',
29
+ 'x-component': 'Select',
30
+ 'x-reactions': '{{ useChartFields }}',
31
+ required: true
32
+ },
33
+ yField: {
34
+ title: (0, _locale.lang)('yField'),
35
+ type: 'string',
36
+ 'x-decorator': 'FormItem',
37
+ 'x-component': 'Select',
38
+ 'x-reactions': '{{ useChartFields }}',
39
+ required: true
40
+ },
41
+ seriesField: {
42
+ title: (0, _locale.lang)('seriesField'),
43
+ type: 'string',
44
+ 'x-decorator': 'FormItem',
45
+ 'x-component': 'Select',
46
+ 'x-reactions': '{{ useChartFields }}'
47
+ }
48
+ }
49
+ };
50
+ const _useProps = ({
51
+ data,
52
+ fieldProps,
53
+ general,
54
+ advanced
55
+ }) => {
56
+ const meta = {};
57
+ Object.entries(fieldProps).forEach(([key, props]) => {
58
+ meta[key] = {
59
+ formatter: props.transformer,
60
+ alias: props.label
61
+ };
62
+ });
63
+ return _objectSpread(_objectSpread({
64
+ data,
65
+ meta
66
+ }, general), advanced);
67
+ };
68
+ const G2PlotLibrary = {
69
+ line: {
70
+ name: (0, _locale.lang)('Line Chart'),
71
+ component: _plots().Line,
72
+ schema: basicSchema,
73
+ init,
74
+ useProps: _useProps,
75
+ reference: {
76
+ title: (0, _locale.lang)('Line Chart'),
77
+ link: 'https://g2plot.antv.antgroup.com/api/plots/bar'
78
+ }
79
+ },
80
+ area: {
81
+ name: (0, _locale.lang)('Area Chart'),
82
+ component: _plots().Area,
83
+ schema: basicSchema,
84
+ init,
85
+ useProps: _useProps,
86
+ reference: {
87
+ title: (0, _locale.lang)('Area Chart'),
88
+ link: 'https://g2plot.antv.antgroup.com/api/plots/area'
89
+ }
90
+ },
91
+ column: {
92
+ name: (0, _locale.lang)('Column Chart'),
93
+ component: _plots().Column,
94
+ schema: basicSchema,
95
+ init,
96
+ useProps: _useProps,
97
+ reference: {
98
+ title: (0, _locale.lang)('Column Chart'),
99
+ link: 'https://g2plot.antv.antgroup.com/api/plots/column'
100
+ }
101
+ },
102
+ bar: {
103
+ name: (0, _locale.lang)('Bar Chart'),
104
+ component: _plots().Bar,
105
+ schema: basicSchema,
106
+ init: (fields, {
107
+ measures,
108
+ dimensions
109
+ }) => {
110
+ const _infer = (0, _ChartLibrary.infer)(fields, {
111
+ measures,
112
+ dimensions
113
+ }),
114
+ xField = _infer.xField,
115
+ yField = _infer.yField,
116
+ seriesField = _infer.seriesField;
117
+ return {
118
+ general: {
119
+ xField: yField === null || yField === void 0 ? void 0 : yField.value,
120
+ yField: xField === null || xField === void 0 ? void 0 : xField.value,
121
+ seriesField: seriesField === null || seriesField === void 0 ? void 0 : seriesField.value
122
+ }
123
+ };
124
+ },
125
+ useProps: _useProps,
126
+ reference: {
127
+ title: (0, _locale.lang)('Bar Chart'),
128
+ link: 'https://g2plot.antv.antgroup.com/api/plots/bar'
129
+ }
130
+ },
131
+ pie: {
132
+ name: (0, _locale.lang)('Pie Chart'),
133
+ component: _plots().Pie,
134
+ schema: {
135
+ type: 'object',
136
+ properties: {
137
+ angleField: {
138
+ title: (0, _locale.lang)('angleField'),
139
+ type: 'string',
140
+ 'x-decorator': 'FormItem',
141
+ 'x-component': 'Select',
142
+ 'x-reactions': '{{ useChartFields }}',
143
+ required: true
144
+ },
145
+ colorField: {
146
+ title: (0, _locale.lang)('colorField'),
147
+ type: 'string',
148
+ 'x-decorator': 'FormItem',
149
+ 'x-component': 'Select',
150
+ 'x-reactions': '{{ useChartFields }}',
151
+ required: true
152
+ }
153
+ }
154
+ },
155
+ init: (fields, {
156
+ measures,
157
+ dimensions
158
+ }) => {
159
+ const _infer2 = (0, _ChartLibrary.infer)(fields, {
160
+ measures,
161
+ dimensions
162
+ }),
163
+ xField = _infer2.xField,
164
+ yField = _infer2.yField;
165
+ return {
166
+ general: {
167
+ colorField: xField === null || xField === void 0 ? void 0 : xField.value,
168
+ angleField: yField === null || yField === void 0 ? void 0 : yField.value
169
+ }
170
+ };
171
+ },
172
+ useProps: _useProps,
173
+ reference: {
174
+ title: (0, _locale.lang)('Pie Chart'),
175
+ link: 'https://g2plot.antv.antgroup.com/api/plots/pie'
176
+ }
177
+ },
178
+ dualAxes: {
179
+ name: (0, _locale.lang)('Dual Axes Chart'),
180
+ component: _plots().DualAxes,
181
+ useProps: ({
182
+ data,
183
+ fieldProps,
184
+ general,
185
+ advanced
186
+ }) => {
187
+ return _objectSpread(_objectSpread({}, _useProps({
188
+ data,
189
+ fieldProps,
190
+ general,
191
+ advanced
192
+ })), {}, {
193
+ data: [data, data]
194
+ });
195
+ },
196
+ schema: {
197
+ type: 'object',
198
+ properties: {
199
+ xField: {
200
+ title: (0, _locale.lang)('xField'),
201
+ type: 'string',
202
+ 'x-decorator': 'FormItem',
203
+ 'x-component': 'Select',
204
+ 'x-reactions': '{{ useChartFields }}',
205
+ required: true
206
+ },
207
+ yField: {
208
+ title: (0, _locale.lang)('yField'),
209
+ type: 'array',
210
+ 'x-decorator': 'FormItem',
211
+ 'x-component': 'ArrayItems',
212
+ items: {
213
+ type: 'void',
214
+ 'x-component': 'Space',
215
+ properties: {
216
+ sort: {
217
+ type: 'void',
218
+ 'x-decorator': 'FormItem',
219
+ 'x-component': 'ArrayItems.SortHandle'
220
+ },
221
+ input: {
222
+ type: 'string',
223
+ 'x-decorator': 'FormItem',
224
+ 'x-component': 'Select',
225
+ 'x-reactions': '{{ useChartFields }}',
226
+ 'x-component-props': {
227
+ style: {
228
+ 'min-width': '200px'
229
+ }
230
+ },
231
+ required: true
232
+ },
233
+ remove: {
234
+ type: 'void',
235
+ 'x-decorator': 'FormItem',
236
+ 'x-component': 'ArrayItems.Remove'
237
+ }
238
+ }
239
+ },
240
+ properties: {
241
+ add: {
242
+ type: 'void',
243
+ title: (0, _locale.lang)('Add'),
244
+ 'x-component': 'ArrayItems.Addition'
245
+ }
246
+ }
247
+ }
248
+ }
249
+ },
250
+ init: (fields, {
251
+ measures,
252
+ dimensions
253
+ }) => {
254
+ const _infer3 = (0, _ChartLibrary.infer)(fields, {
255
+ measures,
256
+ dimensions
257
+ }),
258
+ xField = _infer3.xField,
259
+ yFields = _infer3.yFields;
260
+ return {
261
+ general: {
262
+ xField: xField === null || xField === void 0 ? void 0 : xField.value,
263
+ yField: (yFields === null || yFields === void 0 ? void 0 : yFields.map(f => f.value).slice(0, 2)) || []
264
+ }
265
+ };
266
+ },
267
+ reference: {
268
+ title: (0, _locale.lang)('Dual Axes Chart'),
269
+ link: 'https://g2plot.antv.antgroup.com/api/plots/dual-axes'
270
+ }
271
+ },
272
+ // gauge: {
273
+ // name: lang('Gauge Chart'),
274
+ // component: Gauge,
275
+ // },
276
+ scatter: {
277
+ name: (0, _locale.lang)('Scatter Chart'),
278
+ component: _plots().Scatter,
279
+ schema: basicSchema,
280
+ init,
281
+ useProps: _useProps,
282
+ reference: {
283
+ title: (0, _locale.lang)('Scatter Chart'),
284
+ link: 'https://g2plot.antv.antgroup.com/api/plots/scatter'
285
+ }
286
+ }
287
+ };
288
+ exports.G2PlotLibrary = G2PlotLibrary;
@@ -0,0 +1,3 @@
1
+ export declare const InternalLibrary: {
2
+ [x: string]: import("..").ChartProps;
3
+ };
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.InternalLibrary = void 0;
7
+ var _AntdLibrary = require("./AntdLibrary");
8
+ var _G2PlotLibrary = require("./G2PlotLibrary");
9
+ 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; }
10
+ 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; }
11
+ 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; }
12
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
13
+ 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); }
14
+ const InternalLibrary = _objectSpread(_objectSpread({}, _G2PlotLibrary.G2PlotLibrary), _AntdLibrary.AntdLibrary);
15
+ exports.InternalLibrary = InternalLibrary;
@@ -0,0 +1,96 @@
1
+ import { FieldOption } from './hooks';
2
+ import { QueryProps } from './renderer';
3
+ export declare const createRendererSchema: (decoratorProps: any, componentProps?: {}) => {
4
+ type: string;
5
+ 'x-decorator': string;
6
+ 'x-decorator-props': any;
7
+ 'x-acl-action': string;
8
+ 'x-designer': string;
9
+ 'x-component': string;
10
+ 'x-component-props': {
11
+ size: string;
12
+ };
13
+ 'x-initializer': string;
14
+ properties: {
15
+ [x: string]: {
16
+ type: string;
17
+ 'x-component': string;
18
+ 'x-component-props': {};
19
+ };
20
+ };
21
+ };
22
+ export declare const parseField: (field: string | string[]) => {
23
+ target: string;
24
+ name: string;
25
+ alias: string;
26
+ };
27
+ export declare const getField: (fields: FieldOption[], field: string | string[]) => FieldOption;
28
+ export declare const getSelectedFields: (fields: FieldOption[], query: QueryProps) => {
29
+ key: string;
30
+ label: string;
31
+ value: string;
32
+ alias?: string;
33
+ name?: string;
34
+ type?: string;
35
+ interface?: string;
36
+ uiSchema?: import("@formily/react").Stringify<{
37
+ [key: symbol]: any;
38
+ [key: `x-${string}`]: any;
39
+ [key: `x-${number}`]: any;
40
+ version?: string;
41
+ name?: import("@formily/react").SchemaKey;
42
+ title?: any;
43
+ description?: any;
44
+ default?: any;
45
+ readOnly?: boolean;
46
+ writeOnly?: boolean;
47
+ type?: import("@formily/react").SchemaTypes;
48
+ enum?: import("@formily/react").SchemaEnum<any>;
49
+ const?: any;
50
+ multipleOf?: number;
51
+ maximum?: number;
52
+ exclusiveMaximum?: number;
53
+ minimum?: number;
54
+ exclusiveMinimum?: number;
55
+ maxLength?: number;
56
+ minLength?: number;
57
+ pattern?: string | RegExp;
58
+ maxItems?: number;
59
+ minItems?: number;
60
+ uniqueItems?: boolean;
61
+ maxProperties?: number;
62
+ minProperties?: number;
63
+ required?: string | boolean | string[];
64
+ format?: string;
65
+ $ref?: string;
66
+ $namespace?: string;
67
+ definitions?: import("@formily/react").SchemaProperties<any, any, any, any, any, any, any, any>;
68
+ properties?: import("@formily/react").SchemaProperties<any, any, any, any, any, any, any, any>;
69
+ items?: import("@formily/react").SchemaItems<any, any, any, any, any, any, any, any>;
70
+ additionalItems?: import("@formily/react").Stringify<any>;
71
+ patternProperties?: import("@formily/react").SchemaProperties<any, any, any, any, any, any, any, any>;
72
+ additionalProperties?: import("@formily/react").Stringify<any>;
73
+ "x-value"?: any;
74
+ "x-index"?: number;
75
+ "x-pattern"?: any;
76
+ "x-display"?: any;
77
+ "x-validator"?: any;
78
+ "x-decorator"?: any;
79
+ "x-decorator-props"?: any;
80
+ "x-component"?: any;
81
+ "x-component-props"?: any;
82
+ "x-reactions"?: import("@formily/react").SchemaReactions<any>;
83
+ "x-content"?: any;
84
+ "x-data"?: any;
85
+ "x-visible"?: boolean;
86
+ "x-hidden"?: boolean;
87
+ "x-disabled"?: boolean;
88
+ "x-editable"?: boolean;
89
+ "x-read-only"?: boolean;
90
+ "x-read-pretty"?: boolean;
91
+ "x-compile-omitted"?: string[];
92
+ }>;
93
+ target?: string;
94
+ targetFields?: FieldOption[];
95
+ }[];
96
+ export declare const processData: (fields: FieldOption[], data: any[], scope: any) => {}[];
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.processData = exports.parseField = exports.getSelectedFields = exports.getField = exports.createRendererSchema = void 0;
7
+ function _react() {
8
+ const data = require("@formily/react");
9
+ _react = function _react() {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ function _shared() {
15
+ const data = require("@formily/shared");
16
+ _shared = function _shared() {
17
+ return data;
18
+ };
19
+ return data;
20
+ }
21
+ 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; }
22
+ 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; }
23
+ 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; }
24
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
25
+ 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); }
26
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
27
+ 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."); }
28
+ 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); }
29
+ 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; }
30
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
31
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
32
+ const createRendererSchema = (decoratorProps, componentProps = {}) => {
33
+ const collection = decoratorProps.collection;
34
+ return {
35
+ type: 'void',
36
+ 'x-decorator': 'ChartRendererProvider',
37
+ 'x-decorator-props': decoratorProps,
38
+ 'x-acl-action': `${collection}:list`,
39
+ 'x-designer': 'ChartRenderer.Designer',
40
+ 'x-component': 'CardItem',
41
+ 'x-component-props': {
42
+ size: 'small'
43
+ },
44
+ 'x-initializer': 'ChartInitializers',
45
+ properties: {
46
+ [(0, _shared().uid)()]: {
47
+ type: 'void',
48
+ 'x-component': 'ChartRenderer',
49
+ 'x-component-props': componentProps
50
+ }
51
+ }
52
+ };
53
+ };
54
+ // For AssociationField, the format of field is [targetField, field]
55
+ exports.createRendererSchema = createRendererSchema;
56
+ const parseField = field => {
57
+ let target;
58
+ let name;
59
+ if (!Array.isArray(field)) {
60
+ name = field;
61
+ } else if (field.length === 1) {
62
+ name = field[0];
63
+ } else if (field.length > 1) {
64
+ var _field = _slicedToArray(field, 2);
65
+ target = _field[0];
66
+ name = _field[1];
67
+ }
68
+ return {
69
+ target,
70
+ name,
71
+ alias: target ? `${target}.${name}` : name
72
+ };
73
+ };
74
+ exports.parseField = parseField;
75
+ const getField = (fields, field) => {
76
+ var _fields$find, _fields$find$targetFi;
77
+ const _parseField = parseField(field),
78
+ target = _parseField.target,
79
+ name = _parseField.name;
80
+ if (!target) {
81
+ return fields.find(f => f.name === name);
82
+ }
83
+ const targetField = (_fields$find = fields.find(f => f.name === target)) === null || _fields$find === void 0 ? void 0 : (_fields$find$targetFi = _fields$find.targetFields) === null || _fields$find$targetFi === void 0 ? void 0 : _fields$find$targetFi.find(f => f.name === name);
84
+ return targetField;
85
+ };
86
+ exports.getField = getField;
87
+ const getSelectedFields = (fields, query) => {
88
+ // When field alias is set, appends it to the field list
89
+ const process = selectedFields => {
90
+ return selectedFields.map(selectedField => {
91
+ const fieldProps = getField(fields, selectedField.field);
92
+ return _objectSpread(_objectSpread({}, fieldProps), {}, {
93
+ key: selectedField.alias || (fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.key),
94
+ label: selectedField.alias || (fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.label),
95
+ value: selectedField.alias || (fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.value)
96
+ });
97
+ });
98
+ };
99
+ const measures = query.measures || [];
100
+ const dimensions = query.dimensions || [];
101
+ // unique
102
+ const map = new Map([...process(measures), ...process(dimensions)].map(item => [item.value, item]));
103
+ const selectedFields = [...map.values()];
104
+ return selectedFields;
105
+ };
106
+ exports.getSelectedFields = getSelectedFields;
107
+ const processData = (fields, data, scope) => {
108
+ const parseEnum = (field, value) => {
109
+ var _field$uiSchema;
110
+ const options = (_field$uiSchema = field.uiSchema) === null || _field$uiSchema === void 0 ? void 0 : _field$uiSchema.enum;
111
+ if (!options || !Array.isArray(options)) {
112
+ return value;
113
+ }
114
+ const option = options.find(option => option.value === value);
115
+ return _react().Schema.compile((option === null || option === void 0 ? void 0 : option.label) || value, scope);
116
+ };
117
+ return data.map(record => {
118
+ const processed = {};
119
+ Object.entries(record).forEach(([key, value]) => {
120
+ const field = getField(fields, key.split('.'));
121
+ if (!field) {
122
+ processed[key] = value;
123
+ return;
124
+ }
125
+ switch (field.interface) {
126
+ case 'select':
127
+ case 'radioGroup':
128
+ processed[key] = parseEnum(field, value);
129
+ break;
130
+ default:
131
+ processed[key] = value;
132
+ }
133
+ });
134
+ return processed;
135
+ });
136
+ };
137
+ exports.processData = processData;
package/lib/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { default } from './server';
package/lib/index.js ADDED
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "default", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _server.default;
10
+ }
11
+ });
12
+ var _server = _interopRequireDefault(require("./server"));
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -0,0 +1,3 @@
1
+ export declare const dateFormatFn: (sequelize: any, dialect: string, field: string, format: string) => any;
2
+ export declare const formatFn: (sequelize: any, dialect: string, field: string, format: string) => any;
3
+ export declare const formatter: (sequelize: any, type: string, field: string, format: string) => any;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.formatter = exports.formatFn = exports.dateFormatFn = void 0;
7
+ const dateFormatFn = (sequelize, dialect, field, format) => {
8
+ switch (dialect) {
9
+ case 'sqlite':
10
+ format = format.replace(/YYYY/g, '%Y').replace(/MM/g, '%m').replace(/DD/g, '%d').replace(/hh/g, '%H').replace(/mm/g, '%M').replace(/ss/g, '%S');
11
+ return sequelize.fn('strftime', format, sequelize.col(field));
12
+ case 'mysql':
13
+ format = format.replace(/YYYY/g, '%Y').replace(/MM/g, '%m').replace(/DD/g, '%d').replace(/hh/g, '%H').replace(/mm/g, '%i').replace(/ss/g, '%S');
14
+ return sequelize.fn('date_format', sequelize.col(field), format);
15
+ case 'postgres':
16
+ format = format.replace(/hh/g, 'HH24').replace(/mm/g, 'MI').replace(/ss/g, 'SS');
17
+ return sequelize.fn('to_char', sequelize.col(field), format);
18
+ default:
19
+ return field;
20
+ }
21
+ };
22
+ exports.dateFormatFn = dateFormatFn;
23
+ const formatFn = (sequelize, dialect, field, format) => {
24
+ switch (dialect) {
25
+ case 'sqlite':
26
+ case 'postgres':
27
+ return sequelize.fn('format', format, sequelize.col(field));
28
+ default:
29
+ return field;
30
+ }
31
+ };
32
+ exports.formatFn = formatFn;
33
+ const formatter = (sequelize, type, field, format) => {
34
+ const dialect = sequelize.getDialect();
35
+ switch (type) {
36
+ case 'date':
37
+ case 'datetime':
38
+ case 'time':
39
+ return dateFormatFn(sequelize, dialect, field, format);
40
+ default:
41
+ return formatFn(sequelize, dialect, field, format);
42
+ }
43
+ };
44
+ exports.formatter = formatter;