@nocobase/plugin-charts 0.9.1-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/client.d.ts +4 -0
  2. package/client.js +30 -0
  3. package/lib/client/ChartBlockEngine.d.ts +27 -0
  4. package/lib/client/ChartBlockEngine.js +201 -0
  5. package/lib/client/ChartBlockEngineDesigner.d.ts +3 -0
  6. package/lib/client/ChartBlockEngineDesigner.js +348 -0
  7. package/lib/client/ChartBlockInitializer.d.ts +3 -0
  8. package/lib/client/ChartBlockInitializer.js +324 -0
  9. package/lib/client/ChartQueryBlockInitializer.d.ts +9 -0
  10. package/lib/client/ChartQueryBlockInitializer.js +230 -0
  11. package/lib/client/ChartQueryMetadataProvider.d.ts +10 -0
  12. package/lib/client/ChartQueryMetadataProvider.js +118 -0
  13. package/lib/client/DataSetPreviewTable.d.ts +5 -0
  14. package/lib/client/DataSetPreviewTable.js +127 -0
  15. package/lib/client/Icons.d.ts +1 -0
  16. package/lib/client/Icons.js +226 -0
  17. package/lib/client/chartRenderComponents/index.d.ts +2 -0
  18. package/lib/client/chartRenderComponents/index.js +26 -0
  19. package/lib/client/hooks/index.d.ts +4 -0
  20. package/lib/client/hooks/index.js +52 -0
  21. package/lib/client/index.d.ts +4 -0
  22. package/lib/client/index.js +161 -0
  23. package/lib/client/locale/en-US.d.ts +23 -0
  24. package/lib/client/locale/en-US.js +29 -0
  25. package/lib/client/locale/index.d.ts +3 -0
  26. package/lib/client/locale/index.js +46 -0
  27. package/lib/client/locale/ja-JP.d.ts +2 -0
  28. package/lib/client/locale/ja-JP.js +8 -0
  29. package/lib/client/locale/ru-RU.d.ts +2 -0
  30. package/lib/client/locale/ru-RU.js +8 -0
  31. package/lib/client/locale/tr-TR.d.ts +2 -0
  32. package/lib/client/locale/tr-TR.js +8 -0
  33. package/lib/client/locale/zh-CN.d.ts +61 -0
  34. package/lib/client/locale/zh-CN.js +67 -0
  35. package/lib/client/select/CustomSelect.d.ts +11 -0
  36. package/lib/client/select/CustomSelect.js +193 -0
  37. package/lib/client/select/ReadPretty.d.ts +2 -0
  38. package/lib/client/select/ReadPretty.js +102 -0
  39. package/lib/client/select/index.d.ts +2 -0
  40. package/lib/client/select/index.js +31 -0
  41. package/lib/client/select/shared.d.ts +7 -0
  42. package/lib/client/select/shared.js +86 -0
  43. package/lib/client/settings/AddNewQuery.d.ts +2 -0
  44. package/lib/client/settings/AddNewQuery.js +321 -0
  45. package/lib/client/settings/ConfigureFields.d.ts +1 -0
  46. package/lib/client/settings/ConfigureFields.js +51 -0
  47. package/lib/client/settings/QueriesTable.d.ts +1 -0
  48. package/lib/client/settings/QueriesTable.js +108 -0
  49. package/lib/client/settings/queryTypes.d.ts +5 -0
  50. package/lib/client/settings/queryTypes.js +85 -0
  51. package/lib/client/settings/schemas/chartsQueries.d.ts +8 -0
  52. package/lib/client/settings/schemas/chartsQueries.js +378 -0
  53. package/lib/client/templates/AreaTemplate.d.ts +65 -0
  54. package/lib/client/templates/AreaTemplate.js +86 -0
  55. package/lib/client/templates/BarTemplate.d.ts +80 -0
  56. package/lib/client/templates/BarTemplate.js +103 -0
  57. package/lib/client/templates/ColumnTemplate.d.ts +80 -0
  58. package/lib/client/templates/ColumnTemplate.js +103 -0
  59. package/lib/client/templates/FunnelTemplate.d.ts +66 -0
  60. package/lib/client/templates/FunnelTemplate.js +87 -0
  61. package/lib/client/templates/LineTemplate.d.ts +67 -0
  62. package/lib/client/templates/LineTemplate.js +92 -0
  63. package/lib/client/templates/PieTemplate.d.ts +71 -0
  64. package/lib/client/templates/PieTemplate.js +92 -0
  65. package/lib/client/templates/RadarTemplate.d.ts +71 -0
  66. package/lib/client/templates/RadarTemplate.js +93 -0
  67. package/lib/client/templates/ScatterTemplate.d.ts +91 -0
  68. package/lib/client/templates/ScatterTemplate.js +112 -0
  69. package/lib/client/templates/TableTemplate.d.ts +28 -0
  70. package/lib/client/templates/TableTemplate.js +54 -0
  71. package/lib/client/templates/index.d.ts +1 -0
  72. package/lib/client/templates/index.js +33 -0
  73. package/lib/client/utils.d.ts +3 -0
  74. package/lib/client/utils.js +66 -0
  75. package/lib/index.d.ts +1 -0
  76. package/lib/index.js +15 -0
  77. package/lib/server/actions/chartsQueries.d.ts +3 -0
  78. package/lib/server/actions/chartsQueries.js +104 -0
  79. package/lib/server/actions/index.d.ts +1 -0
  80. package/lib/server/actions/index.js +1 -0
  81. package/lib/server/collections/chartsQueries.d.ts +2 -0
  82. package/lib/server/collections/chartsQueries.js +36 -0
  83. package/lib/server/index.d.ts +1 -0
  84. package/lib/server/index.js +15 -0
  85. package/lib/server/plugin.d.ts +14 -0
  86. package/lib/server/plugin.js +142 -0
  87. package/lib/server/query.d.ts +12 -0
  88. package/lib/server/query.js +91 -0
  89. package/lib/server/shared/index.d.ts +2 -0
  90. package/lib/server/shared/index.js +8 -0
  91. package/package.json +14 -0
  92. package/server.d.ts +4 -0
  93. package/server.js +30 -0
  94. package/src/client/ChartBlockEngine.tsx +120 -0
  95. package/src/client/ChartBlockEngineDesigner.tsx +238 -0
  96. package/src/client/ChartBlockInitializer.tsx +216 -0
  97. package/src/client/ChartQueryBlockInitializer.tsx +136 -0
  98. package/src/client/ChartQueryMetadataProvider.tsx +62 -0
  99. package/src/client/DataSetPreviewTable.tsx +73 -0
  100. package/src/client/Icons.tsx +99 -0
  101. package/src/client/chartRenderComponents/index.ts +7 -0
  102. package/src/client/hooks/index.ts +19 -0
  103. package/src/client/index.tsx +101 -0
  104. package/src/client/locale/en-US.ts +23 -0
  105. package/src/client/locale/index.ts +18 -0
  106. package/src/client/locale/ja-JP.ts +1 -0
  107. package/src/client/locale/ru-RU.ts +1 -0
  108. package/src/client/locale/tr-TR.ts +1 -0
  109. package/src/client/locale/zh-CN.ts +63 -0
  110. package/src/client/select/CustomSelect.tsx +127 -0
  111. package/src/client/select/ReadPretty.tsx +36 -0
  112. package/src/client/select/index.md +38 -0
  113. package/src/client/select/index.ts +2 -0
  114. package/src/client/select/shared.ts +36 -0
  115. package/src/client/settings/AddNewQuery.tsx +161 -0
  116. package/src/client/settings/ConfigureFields.tsx +18 -0
  117. package/src/client/settings/QueriesTable.tsx +26 -0
  118. package/src/client/settings/queryTypes.ts +64 -0
  119. package/src/client/settings/schemas/chartsQueries.ts +319 -0
  120. package/src/client/templates/AreaTemplate.tsx +64 -0
  121. package/src/client/templates/BarTemplate.tsx +80 -0
  122. package/src/client/templates/ColumnTemplate.tsx +81 -0
  123. package/src/client/templates/FunnelTemplate.tsx +65 -0
  124. package/src/client/templates/LineTemplate.tsx +72 -0
  125. package/src/client/templates/PieTemplate.tsx +68 -0
  126. package/src/client/templates/RadarTemplate.tsx +71 -0
  127. package/src/client/templates/ScatterTemplate.tsx +90 -0
  128. package/src/client/templates/TableTemplate.tsx +48 -0
  129. package/src/client/templates/index.ts +21 -0
  130. package/src/client/utils.ts +39 -0
  131. package/src/index.ts +1 -0
  132. package/src/server/actions/chartsQueries.ts +44 -0
  133. package/src/server/actions/index.ts +0 -0
  134. package/src/server/collections/.gitkeep +0 -0
  135. package/src/server/collections/chartsQueries.ts +24 -0
  136. package/src/server/index.ts +1 -0
  137. package/src/server/plugin.ts +61 -0
  138. package/src/server/query.ts +39 -0
  139. package/src/server/shared/index.ts +2 -0
@@ -0,0 +1,324 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Options = exports.ChartBlockInitializer = void 0;
7
+
8
+ function _css() {
9
+ const data = require("@emotion/css");
10
+
11
+ _css = function _css() {
12
+ return data;
13
+ };
14
+
15
+ return data;
16
+ }
17
+
18
+ function _antd() {
19
+ const data = require("@formily/antd");
20
+
21
+ _antd = function _antd() {
22
+ return data;
23
+ };
24
+
25
+ return data;
26
+ }
27
+
28
+ function _react() {
29
+ const data = require("@formily/react");
30
+
31
+ _react = function _react() {
32
+ return data;
33
+ };
34
+
35
+ return data;
36
+ }
37
+
38
+ function _client() {
39
+ const data = require("@nocobase/client");
40
+
41
+ _client = function _client() {
42
+ return data;
43
+ };
44
+
45
+ return data;
46
+ }
47
+
48
+ function _antd2() {
49
+ const data = require("antd");
50
+
51
+ _antd2 = function _antd2() {
52
+ return data;
53
+ };
54
+
55
+ return data;
56
+ }
57
+
58
+ function _json() {
59
+ const data = _interopRequireDefault(require("json5"));
60
+
61
+ _json = function _json() {
62
+ return data;
63
+ };
64
+
65
+ return data;
66
+ }
67
+
68
+ function _react2() {
69
+ const data = _interopRequireWildcard(require("react"));
70
+
71
+ _react2 = function _react2() {
72
+ return data;
73
+ };
74
+
75
+ return data;
76
+ }
77
+
78
+ var _ChartBlockEngineDesigner = require("./ChartBlockEngineDesigner");
79
+
80
+ var _ChartQueryBlockInitializer = require("./ChartQueryBlockInitializer");
81
+
82
+ var _DataSetPreviewTable = _interopRequireDefault(require("./DataSetPreviewTable"));
83
+
84
+ var _locale = require("./locale");
85
+
86
+ var _templates = require("./templates");
87
+
88
+ 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); }
89
+
90
+ 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; }
91
+
92
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
93
+
94
+ 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); } }
95
+
96
+ 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); }); }; }
97
+
98
+ 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; }
99
+
100
+ 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; }
101
+
102
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
103
+
104
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
105
+
106
+ 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."); }
107
+
108
+ 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); }
109
+
110
+ 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; }
111
+
112
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
113
+
114
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
115
+
116
+ const Options = (0, _react().observer)(props => {
117
+ const form = (0, _react().useForm)();
118
+ const field = (0, _react().useField)();
119
+
120
+ const _useState = (0, _react2().useState)(new (_react().Schema)({})),
121
+ _useState2 = _slicedToArray(_useState, 2),
122
+ s = _useState2[0],
123
+ setSchema = _useState2[1];
124
+
125
+ const _useState3 = (0, _react2().useState)(form.values.type),
126
+ _useState4 = _slicedToArray(_useState3, 2),
127
+ chartType = _useState4[0],
128
+ setChartType = _useState4[1];
129
+
130
+ (0, _react2().useEffect)(() => {
131
+ var _form$values, _form$values2;
132
+
133
+ // form.clearFormGraph('options.*');
134
+ setChartType(form === null || form === void 0 ? void 0 : (_form$values = form.values) === null || _form$values === void 0 ? void 0 : _form$values.type);
135
+
136
+ if (chartType !== (form === null || form === void 0 ? void 0 : (_form$values2 = form.values) === null || _form$values2 === void 0 ? void 0 : _form$values2.type)) {
137
+ form.clearFormGraph('options.*');
138
+ }
139
+
140
+ if (form.values.type) {
141
+ const template = _templates.templates.get(form.values.type);
142
+
143
+ setSchema(new (_react().Schema)(template.configurableProperties || {}));
144
+ }
145
+ }, [form.values.type]);
146
+ return _react2().default.createElement(_react().RecursionField, {
147
+ schema: s
148
+ });
149
+ });
150
+ exports.Options = Options;
151
+
152
+ const ChartBlockInitializer = props => {
153
+ const insert = props.insert;
154
+ const options = (0, _react2().useContext)(_react().SchemaOptionsContext);
155
+ const api = (0, _client().useAPIClient)();
156
+ const compile = (0, _client().useCompile)();
157
+
158
+ const _useChartsTranslation = (0, _locale.useChartsTranslation)(),
159
+ t = _useChartsTranslation.t;
160
+
161
+ return _react2().default.createElement(_ChartQueryBlockInitializer.ChartQueryBlockInitializer, _objectSpread(_objectSpread({}, props), {}, {
162
+ componentType: 'Charts',
163
+ onCreateBlockSchema: function () {
164
+ var _onCreateBlockSchema = _asyncToGenerator(function* ({
165
+ item: chartQueryMetadata
166
+ }) {
167
+ const dataSource = chartQueryMetadata === null || chartQueryMetadata === void 0 ? void 0 : chartQueryMetadata.fields.map(field => {
168
+ return {
169
+ label: field.name,
170
+ value: field.name
171
+ };
172
+ });
173
+ let values = yield (0, _antd().FormDialog)({
174
+ okText: compile('{{t("Submit")}}'),
175
+ title: (0, _locale.lang)('Create chart block'),
176
+ width: 1200,
177
+ bodyStyle: {
178
+ background: '#f0f2f5',
179
+ maxHeight: '65vh',
180
+ overflow: 'auto'
181
+ }
182
+ }, () => {
183
+ var _chartBlockEngineMeta, _chartBlockEngineMeta2;
184
+
185
+ const form = (0, _react().useForm)();
186
+
187
+ const _useState5 = (0, _react2().useState)(null),
188
+ _useState6 = _slicedToArray(_useState5, 2),
189
+ chartBlockEngineMetaData = _useState6[0],
190
+ setChartBlockEngineMetaData = _useState6[1];
191
+
192
+ (0, _react2().useEffect)(() => {
193
+ const chartBlockEngineMetaData = {
194
+ query: {
195
+ id: chartQueryMetadata === null || chartQueryMetadata === void 0 ? void 0 : chartQueryMetadata.id
196
+ },
197
+ chart: form.values //TODO
198
+
199
+ };
200
+ setChartBlockEngineMetaData(chartBlockEngineMetaData);
201
+ }, [form.values.type]);
202
+ return _react2().default.createElement(_client().APIClientProvider, {
203
+ apiClient: api
204
+ }, _react2().default.createElement(_client().SchemaComponentOptions, {
205
+ scope: options.scope,
206
+ components: _objectSpread({}, options.components)
207
+ }, _react2().default.createElement("section", {
208
+ className: (0, _css().css)`
209
+ display: flex;
210
+ gap: 24px;
211
+ `
212
+ }, _react2().default.createElement(_antd2().Card, {
213
+ title: (0, _locale.lang)('Chart config'),
214
+ size: 'default',
215
+ className: (0, _css().css)`
216
+ flex: 1;
217
+ `
218
+ }, _react2().default.createElement(_client().FormProvider, {
219
+ form: form
220
+ }, _react2().default.createElement(_antd().FormLayout, {
221
+ layout: 'vertical'
222
+ }, _react2().default.createElement(_client().SchemaComponent, {
223
+ scope: {
224
+ dataSource,
225
+ JSON5: _json().default,
226
+ jsonConfigDesc: _ChartBlockEngineDesigner.jsonConfigDesc
227
+ },
228
+ components: {
229
+ Options
230
+ },
231
+ schema: {
232
+ properties: {
233
+ // title: {
234
+ // title: lang('Chart title'),
235
+ // 'x-component': 'Input',
236
+ // 'x-decorator': 'FormItem',
237
+ // },
238
+ type: {
239
+ title: (0, _locale.lang)('Chart type'),
240
+ required: true,
241
+ 'x-component': 'CustomSelect',
242
+ 'x-decorator': 'FormItem',
243
+ enum: [..._templates.templates.values()].map(template => {
244
+ return {
245
+ title: template.title,
246
+ key: template.type,
247
+ description: template.description,
248
+ group: template.group,
249
+ iconId: template.iconId
250
+ };
251
+ })
252
+ },
253
+ options: {
254
+ type: 'void',
255
+ 'x-component': 'Options'
256
+ }
257
+ }
258
+ }
259
+ })))), _react2().default.createElement("div", {
260
+ className: (0, _css().css)`
261
+ flex: 1;
262
+ min-width: 600px;
263
+ `
264
+ }, _react2().default.createElement(_antd2().Card, {
265
+ size: 'default',
266
+ title: (0, _locale.lang)('Chart preview')
267
+ }, chartBlockEngineMetaData && _react2().default.createElement(_react2().default.Fragment, null, _react2().default.createElement(_client().SchemaComponent, {
268
+ schema: {
269
+ properties: {
270
+ chartPreview: {
271
+ type: 'void',
272
+ 'x-decorator': 'CardItem',
273
+ 'x-component': 'ChartBlockEngine',
274
+ 'x-component-props': {
275
+ chartBlockEngineMetaData
276
+ }
277
+ }
278
+ }
279
+ }
280
+ }))), _react2().default.createElement(_antd2().Card, {
281
+ size: 'default',
282
+ title: (0, _locale.lang)('Data preview'),
283
+ className: (0, _css().css)`
284
+ margin-top: 24px;
285
+ overflow: scroll;
286
+ `
287
+ }, (chartBlockEngineMetaData === null || chartBlockEngineMetaData === void 0 ? void 0 : (_chartBlockEngineMeta = chartBlockEngineMetaData.query) === null || _chartBlockEngineMeta === void 0 ? void 0 : _chartBlockEngineMeta.id) && _react2().default.createElement(_DataSetPreviewTable.default, {
288
+ queryId: chartBlockEngineMetaData === null || chartBlockEngineMetaData === void 0 ? void 0 : (_chartBlockEngineMeta2 = chartBlockEngineMetaData.query) === null || _chartBlockEngineMeta2 === void 0 ? void 0 : _chartBlockEngineMeta2.id,
289
+ fields: chartQueryMetadata === null || chartQueryMetadata === void 0 ? void 0 : chartQueryMetadata.fields
290
+ }))))));
291
+ }).open({
292
+ initialValues: {}
293
+ });
294
+
295
+ if (values) {
296
+ const chartBlockEngineMetaData = {
297
+ query: {
298
+ id: chartQueryMetadata.id
299
+ },
300
+ chart: values
301
+ };
302
+ insert({
303
+ type: 'void',
304
+ title: values === null || values === void 0 ? void 0 : values.title,
305
+ 'x-designer': 'ChartBlockEngine.Designer',
306
+ 'x-decorator': 'CardItem',
307
+ 'x-component': 'ChartBlockEngine',
308
+ 'x-component-props': {
309
+ chartBlockEngineMetaData
310
+ }
311
+ });
312
+ }
313
+ });
314
+
315
+ function onCreateBlockSchema(_x) {
316
+ return _onCreateBlockSchema.apply(this, arguments);
317
+ }
318
+
319
+ return onCreateBlockSchema;
320
+ }()
321
+ }));
322
+ };
323
+
324
+ exports.ChartBlockInitializer = ChartBlockInitializer;
@@ -0,0 +1,9 @@
1
+ export interface ChartQueryMetadata {
2
+ id: number;
3
+ title: string;
4
+ type: string;
5
+ fields: {
6
+ name: string;
7
+ }[];
8
+ }
9
+ export declare const ChartQueryBlockInitializer: (props: any) => JSX.Element;
@@ -0,0 +1,230 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ChartQueryBlockInitializer = void 0;
7
+
8
+ function _icons() {
9
+ const data = require("@ant-design/icons");
10
+
11
+ _icons = function _icons() {
12
+ return data;
13
+ };
14
+
15
+ return data;
16
+ }
17
+
18
+ function _antd() {
19
+ const data = require("@formily/antd");
20
+
21
+ _antd = function _antd() {
22
+ return data;
23
+ };
24
+
25
+ return data;
26
+ }
27
+
28
+ function _react() {
29
+ const data = require("@formily/react");
30
+
31
+ _react = function _react() {
32
+ return data;
33
+ };
34
+
35
+ return data;
36
+ }
37
+
38
+ function _client() {
39
+ const data = require("@nocobase/client");
40
+
41
+ _client = function _client() {
42
+ return data;
43
+ };
44
+
45
+ return data;
46
+ }
47
+
48
+ function _react2() {
49
+ const data = _interopRequireWildcard(require("react"));
50
+
51
+ _react2 = function _react2() {
52
+ return data;
53
+ };
54
+
55
+ return data;
56
+ }
57
+
58
+ var _ChartQueryMetadataProvider = require("./ChartQueryMetadataProvider");
59
+
60
+ var _locale = require("./locale");
61
+
62
+ var _queryTypes = require("./settings/queryTypes");
63
+
64
+ const _excluded = ["templateWrap", "onCreateBlockSchema", "componentType", "createBlockSchema", "insert"];
65
+
66
+ 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); }
67
+
68
+ 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; }
69
+
70
+ 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); } }
71
+
72
+ 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); }); }; }
73
+
74
+ 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; }
75
+
76
+ 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; }
77
+
78
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
79
+
80
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
81
+
82
+ 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."); }
83
+
84
+ 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); }
85
+
86
+ 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; }
87
+
88
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
89
+
90
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
91
+
92
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
93
+
94
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
95
+
96
+ const ChartQueryBlockInitializer = props => {
97
+ const defaultItems = [{
98
+ type: 'itemGroup',
99
+ title: (0, _locale.lang)('Select query data'),
100
+ children: []
101
+ }];
102
+
103
+ const templateWrap = props.templateWrap,
104
+ onCreateBlockSchema = props.onCreateBlockSchema,
105
+ componentType = props.componentType,
106
+ createBlockSchema = props.createBlockSchema,
107
+ insert = props.insert,
108
+ others = _objectWithoutProperties(props, _excluded);
109
+
110
+ const _useContext = (0, _react2().useContext)(_client().SchemaInitializerButtonContext),
111
+ setVisible = _useContext.setVisible;
112
+
113
+ const _useState = (0, _react2().useState)(defaultItems),
114
+ _useState2 = _slicedToArray(_useState, 2),
115
+ items = _useState2[0],
116
+ setItems = _useState2[1];
117
+
118
+ const apiClient = (0, _client().useAPIClient)();
119
+ const ctx = (0, _ChartQueryMetadataProvider.useChartQueryMetadataContext)();
120
+ const options = (0, _react2().useContext)(_react().SchemaOptionsContext);
121
+
122
+ const onAddQuery = info => {
123
+ (0, _antd().FormDialog)({
124
+ sql: (0, _locale.lang)('Add SQL query'),
125
+ json: (0, _locale.lang)('Add JSON query')
126
+ }[info.key], () => {
127
+ return _react2().default.createElement("div", null, _react2().default.createElement(_client().SchemaComponentOptions, {
128
+ scope: options.scope,
129
+ components: _objectSpread({}, options.components)
130
+ }, _react2().default.createElement(_antd().FormLayout, {
131
+ layout: 'vertical'
132
+ }, _react2().default.createElement(_client().SchemaComponent, {
133
+ schema: {
134
+ type: 'object',
135
+ properties: {
136
+ title: {
137
+ title: (0, _locale.lang)('Title'),
138
+ required: true,
139
+ 'x-component': 'Input',
140
+ 'x-decorator': 'FormItem'
141
+ },
142
+ options: (0, _queryTypes.getQueryTypeSchema)(info.key)
143
+ }
144
+ }
145
+ }))));
146
+ }).open({
147
+ initialValues: {
148
+ type: info.key
149
+ }
150
+ }).then( /*#__PURE__*/function () {
151
+ var _ref = _asyncToGenerator(function* (values) {
152
+ try {
153
+ var _apiClient$resource, _apiClient$resource$c;
154
+
155
+ const _yield$apiClient$reso = yield (_apiClient$resource = apiClient.resource('chartsQueries')) === null || _apiClient$resource === void 0 ? void 0 : (_apiClient$resource$c = _apiClient$resource.create) === null || _apiClient$resource$c === void 0 ? void 0 : _apiClient$resource$c.call(_apiClient$resource, {
156
+ values
157
+ }),
158
+ data = _yield$apiClient$reso.data;
159
+
160
+ const items = yield ctx.refresh();
161
+ const item = items.find(item => {
162
+ var _data$data;
163
+
164
+ return item.id === (data === null || data === void 0 ? void 0 : (_data$data = data.data) === null || _data$data === void 0 ? void 0 : _data$data.id);
165
+ });
166
+ onCreateBlockSchema({
167
+ item
168
+ });
169
+ setVisible(false);
170
+ } catch (error) {}
171
+ });
172
+
173
+ return function (_x) {
174
+ return _ref.apply(this, arguments);
175
+ };
176
+ }()).catch(() => {});
177
+ };
178
+
179
+ (0, _react2().useEffect)(() => {
180
+ const chartQueryMetadata = ctx.data;
181
+
182
+ if (chartQueryMetadata && Array.isArray(chartQueryMetadata)) {
183
+ setItems([chartQueryMetadata.length > 0 ? {
184
+ type: 'itemGroup',
185
+ title: '{{t("Select chart query", {ns: "charts"})}}',
186
+ children: chartQueryMetadata
187
+ } : null, chartQueryMetadata.length > 0 ? {
188
+ type: 'divider'
189
+ } : null,, {
190
+ type: 'subMenu',
191
+ title: (0, _locale.lang)('Add chart query'),
192
+ // component: AddChartQuery,
193
+ children: [{
194
+ key: 'sql',
195
+ type: 'item',
196
+ title: 'SQL',
197
+ onClick: onAddQuery
198
+ }, {
199
+ key: 'json',
200
+ type: 'item',
201
+ title: 'JSON',
202
+ onClick: onAddQuery
203
+ }]
204
+ }].filter(Boolean));
205
+ }
206
+ }, []);
207
+ return _react2().default.createElement(_client().SchemaInitializer.Item, _objectSpread(_objectSpread({
208
+ icon: _react2().default.createElement(_icons().TableOutlined, null)
209
+ }, others), {}, {
210
+ onClick: function () {
211
+ var _onClick = _asyncToGenerator(function* ({
212
+ item
213
+ }) {
214
+ onCreateBlockSchema({
215
+ item
216
+ });
217
+ setVisible(false);
218
+ });
219
+
220
+ function onClick(_x2) {
221
+ return _onClick.apply(this, arguments);
222
+ }
223
+
224
+ return onClick;
225
+ }(),
226
+ items: items
227
+ }));
228
+ };
229
+
230
+ exports.ChartQueryBlockInitializer = ChartQueryBlockInitializer;
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ export declare const ChartQueryMetadataContext: React.Context<{
3
+ refresh: () => void;
4
+ data: any[];
5
+ }>;
6
+ export declare const ChartQueryMetadataProvider: React.FC;
7
+ export declare const useChartQueryMetadataContext: () => {
8
+ refresh: () => void;
9
+ data: any[];
10
+ };