lowcoder-comps 0.0.17 → 0.0.19

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 (78) hide show
  1. package/README.md +27 -0
  2. package/index.html +26 -0
  3. package/index.tsx +19 -0
  4. package/jest.config.js +6 -0
  5. package/package.json +4 -5
  6. package/src/__test__/allComp.test.tsx +61 -0
  7. package/src/app-env.d.ts +3 -0
  8. package/src/comps/calendarComp/calendarComp.tsx +443 -0
  9. package/src/comps/calendarComp/calendarConstants.tsx +898 -0
  10. package/src/comps/chartComp/chartComp.tsx +356 -0
  11. package/src/comps/chartComp/chartConfigs/barChartConfig.tsx +51 -0
  12. package/src/comps/chartComp/chartConfigs/cartesianAxisConfig.tsx +307 -0
  13. package/src/comps/chartComp/chartConfigs/chartUrls.tsx +9 -0
  14. package/src/comps/chartComp/chartConfigs/legendConfig.tsx +55 -0
  15. package/src/comps/chartComp/chartConfigs/lineChartConfig.tsx +96 -0
  16. package/src/comps/chartComp/chartConfigs/pieChartConfig.tsx +83 -0
  17. package/src/comps/chartComp/chartConfigs/scatterChartConfig.tsx +62 -0
  18. package/src/comps/chartComp/chartConstants.tsx +288 -0
  19. package/src/comps/chartComp/chartPropertyView.tsx +218 -0
  20. package/src/comps/chartComp/chartUtils.ts +291 -0
  21. package/src/comps/chartComp/reactEcharts/core.tsx +194 -0
  22. package/src/comps/chartComp/reactEcharts/index.ts +21 -0
  23. package/src/comps/chartComp/reactEcharts/types.ts +76 -0
  24. package/src/comps/chartComp/seriesComp.tsx +119 -0
  25. package/src/comps/imageEditorComp/imageEditorClass.tsx +52 -0
  26. package/src/comps/imageEditorComp/imageEditorConstants.tsx +109 -0
  27. package/src/comps/imageEditorComp/index.tsx +184 -0
  28. package/src/comps/mermaidComp/index.tsx +44 -0
  29. package/src/comps/mermaidComp/mermaid.tsx +29 -0
  30. package/src/global.ts +1 -0
  31. package/src/i18n/comps/index.tsx +29 -0
  32. package/src/i18n/comps/locales/en.ts +150 -0
  33. package/src/i18n/comps/locales/enObj.tsx +198 -0
  34. package/src/i18n/comps/locales/index.ts +7 -0
  35. package/src/i18n/comps/locales/types.tsx +10 -0
  36. package/src/i18n/comps/locales/zh.ts +145 -0
  37. package/src/i18n/comps/locales/zhObj.tsx +4 -0
  38. package/src/index.ts +11 -0
  39. package/tsconfig.json +22 -0
  40. package/vite.config.js +10 -0
  41. package/001f8b13.js +0 -326
  42. package/085bf0c2.js +0 -46688
  43. package/256b619e.js +0 -92
  44. package/29cba276.js +0 -91
  45. package/2e18581a.js +0 -451
  46. package/2ff2c7a6.js +0 -6
  47. package/340c33ea.js +0 -1602
  48. package/3ad55ad7.js +0 -607
  49. package/47b0b0ff.js +0 -70
  50. package/4a5b6fbe.js +0 -798
  51. package/4abe140e.js +0 -943
  52. package/4cf5b178.js +0 -34
  53. package/5cab7b96.js +0 -18619
  54. package/626b9013.js +0 -7
  55. package/6798500f.js +0 -793
  56. package/68b021d0.js +0 -2456
  57. package/6ab1612a.js +0 -24
  58. package/6e903063.js +0 -940
  59. package/72a7048f.js +0 -849
  60. package/7902f186.js +0 -823
  61. package/82c1c410.js +0 -86
  62. package/8517f7c1.js +0 -365
  63. package/9495ef3b.js +0 -1118
  64. package/9ea1ddd6.js +0 -447
  65. package/a01c9944.js +0 -212
  66. package/a4ce7e8a.js +0 -2827
  67. package/ad68bdd0.js +0 -236
  68. package/b499e5a9.js +0 -2103
  69. package/bdc7b18a.js +0 -1032
  70. package/be5b66cd.js +0 -832
  71. package/c4378831.js +0 -117175
  72. package/ca8f4e3f.js +0 -275
  73. package/de61c633.js +0 -2679
  74. package/e04788e2.js +0 -159
  75. package/f9637058.js +0 -16
  76. package/f9a47b7c.js +0 -985
  77. package/ff16c2ec.js +0 -1246
  78. package/index.js +0 -5
@@ -0,0 +1,9 @@
1
+ import { language } from "i18n/comps";
2
+
3
+ const echartsUrlLocale = language === "zh" ? "zh" : "en";
4
+ export const optionUrl = `https://echarts.apache.org/${echartsUrlLocale}/option.html`;
5
+ export const examplesUrl = `https://echarts.apache.org/examples/${echartsUrlLocale}/index.html`;
6
+ export const xAxisTypeUrl = `${optionUrl}#xAxis.type`;
7
+ export const googleMapsApiUrl = `https://maps.googleapis.com/maps/api/js?v=3.exp`;
8
+ export const mapOptionUrl = `https://github.com/plainheart/echarts-extension-gmap`;
9
+ export const mapExamplesUrl = `https://codepen.io/plainheart/pen/VweLGbR`;
@@ -0,0 +1,55 @@
1
+ import {
2
+ AlignBottom,
3
+ AlignClose,
4
+ AlignRight,
5
+ dropdownControl,
6
+ MultiCompBuilder,
7
+ } from "lowcoder-sdk";
8
+ import { LegendComponentOption } from "echarts";
9
+ import { trans } from "i18n/comps";
10
+
11
+ const LegendPositionOptions = [
12
+ {
13
+ label: <AlignBottom />,
14
+ value: "bottom",
15
+ },
16
+ {
17
+ label: <AlignRight />,
18
+ value: "right",
19
+ },
20
+ {
21
+ label: <AlignClose />,
22
+ value: "close",
23
+ },
24
+ ] as const;
25
+
26
+ export const LegendConfig = (function () {
27
+ return new MultiCompBuilder(
28
+ {
29
+ position: dropdownControl(LegendPositionOptions, "bottom"),
30
+ },
31
+ (props): LegendComponentOption => {
32
+ const config: LegendComponentOption = {
33
+ top: "bottom",
34
+ type: "scroll",
35
+ };
36
+ if (props.position === "right") {
37
+ config.top = "center";
38
+ config.left = "right";
39
+ config.orient = "vertical";
40
+ } else if (props.position === "close") {
41
+ config.show = false;
42
+ }
43
+ return config;
44
+ }
45
+ )
46
+ .setPropertyViewFn((children) => (
47
+ <>
48
+ {children.position.propertyView({
49
+ label: trans("chart.legendPosition"),
50
+ radioButton: true,
51
+ })}
52
+ </>
53
+ ))
54
+ .build();
55
+ })();
@@ -0,0 +1,96 @@
1
+ import { LineSeriesOption } from "echarts";
2
+ import {
3
+ MultiCompBuilder,
4
+ BoolControl,
5
+ dropdownControl,
6
+ showLabelPropertyView,
7
+ withContext,
8
+ StringControl,
9
+ ColorOrBoolCodeControl,
10
+ } from "lowcoder-sdk";
11
+ import { trans } from "i18n/comps";
12
+
13
+ const BarTypeOptions = [
14
+ {
15
+ label: trans("chart.basicLine"),
16
+ value: "basicLine",
17
+ },
18
+ {
19
+ label: trans("chart.stackedLine"),
20
+ value: "stackedLine",
21
+ },
22
+ {
23
+ label: trans("chart.areaLine"),
24
+ value: "areaLine",
25
+ },
26
+ ] as const;
27
+
28
+ export const ItemColorComp = withContext(
29
+ new MultiCompBuilder({ value: ColorOrBoolCodeControl }, (props) => props.value)
30
+ .setPropertyViewFn((children) =>
31
+ children.value.propertyView({
32
+ label: trans("chart.pointColorLabel"),
33
+ placeholder: "{{value < 25000}}",
34
+ tooltip: trans("chart.pointColorTooltip"),
35
+ })
36
+ )
37
+ .build(),
38
+ ["seriesName", "value"] as const
39
+ );
40
+
41
+ export const LineChartConfig = (function () {
42
+ return new MultiCompBuilder(
43
+ {
44
+ showLabel: BoolControl,
45
+ type: dropdownControl(BarTypeOptions, "basicLine"),
46
+ smooth: BoolControl,
47
+ itemColor: ItemColorComp,
48
+ },
49
+ (props): LineSeriesOption => {
50
+ const config: LineSeriesOption = {
51
+ type: "line",
52
+ label: {
53
+ show: props.showLabel,
54
+ },
55
+ itemStyle: {
56
+ color: (params) => {
57
+ if (!params.encode || !params.dimensionNames) {
58
+ return params.color;
59
+ }
60
+ const dataKey = params.dimensionNames[params.encode["y"][0]];
61
+ const color = (props.itemColor as any)({
62
+ seriesName: params.seriesName,
63
+ value: (params.data as any)[dataKey],
64
+ });
65
+ if (color === "true") {
66
+ return "red";
67
+ } else if (color === "false" || !color) {
68
+ return params.color;
69
+ }
70
+ return color;
71
+ },
72
+ },
73
+ };
74
+ if (props.type === "stackedLine") {
75
+ config.stack = "stackValue";
76
+ } else if (props.type === "areaLine") {
77
+ config.areaStyle = {};
78
+ }
79
+ if (props.smooth) {
80
+ config.smooth = true;
81
+ }
82
+ return config;
83
+ }
84
+ )
85
+ .setPropertyViewFn((children) => (
86
+ <>
87
+ {children.type.propertyView({
88
+ label: trans("chart.lineType"),
89
+ })}
90
+ {showLabelPropertyView(children)}
91
+ {children.smooth.propertyView({ label: trans("chart.smooth") })}
92
+ {children.itemColor.getPropertyView()}
93
+ </>
94
+ ))
95
+ .build();
96
+ })();
@@ -0,0 +1,83 @@
1
+ import { MultiCompBuilder } from "lowcoder-sdk";
2
+ import { PieSeriesOption } from "echarts";
3
+ import { dropdownControl } from "lowcoder-sdk";
4
+ import { ConstructorToView } from "lowcoder-core";
5
+ import { trans } from "i18n/comps";
6
+
7
+ const BarTypeOptions = [
8
+ {
9
+ label: trans("chart.basicPie"),
10
+ value: "basicPie",
11
+ },
12
+ {
13
+ label: trans("chart.doughnutPie"),
14
+ value: "doughnutPie",
15
+ },
16
+ {
17
+ label: trans("chart.rosePie"),
18
+ value: "rosePie",
19
+ },
20
+ ] as const;
21
+
22
+ // radius percent for each pie chart when one line has [1, 2, 3] pie charts
23
+ const pieRadiusConfig = [65, 35, 20];
24
+
25
+ type PieConfigViewType = ConstructorToView<typeof PieChartConfig>;
26
+
27
+ export const PieChartConfig = (function () {
28
+ return new MultiCompBuilder(
29
+ {
30
+ type: dropdownControl(BarTypeOptions, "basicPie"),
31
+ },
32
+ (props): PieSeriesOption => {
33
+ const config: PieSeriesOption = {
34
+ type: "pie",
35
+ label: {
36
+ show: true,
37
+ formatter: "{d}%",
38
+ },
39
+ };
40
+ if (props.type === "rosePie") {
41
+ config.roseType = "area";
42
+ } else if (props.type === "doughnutPie") {
43
+ config.radius = ["40%", "60%"];
44
+ }
45
+ return config;
46
+ }
47
+ )
48
+ .setPropertyViewFn((children) => (
49
+ <>
50
+ {children.type.propertyView({
51
+ label: trans("chart.pieType"),
52
+ })}
53
+ </>
54
+ ))
55
+ .build();
56
+ })();
57
+
58
+ export function getPieRadiusAndCenter(
59
+ seriesLength: number,
60
+ pieIndex: number,
61
+ pieConfig: PieConfigViewType
62
+ ) {
63
+ const columnPieNum = Math.min(seriesLength, pieRadiusConfig.length);
64
+ const radiusNumber = pieRadiusConfig[columnPieNum - 1];
65
+ const isDoughnutPie = Array.isArray(pieConfig.radius);
66
+ const radius = isDoughnutPie
67
+ ? [(radiusNumber / 1.6).toFixed(2) + "%", radiusNumber + "%"]
68
+ : radiusNumber + "%";
69
+
70
+ /*** calculate center coordinates ***/
71
+ const pieDiameter = 100 / columnPieNum;
72
+ const xPosition = (pieDiameter * (pieIndex % columnPieNum) + pieDiameter / 2).toFixed(2) + "%";
73
+ const rowIndex = Math.floor(pieIndex / columnPieNum) + 1;
74
+ const yPosition =
75
+ ((100 / Math.floor((columnPieNum * 2 + seriesLength - 1) / columnPieNum)) * rowIndex).toFixed(
76
+ 2
77
+ ) + "%";
78
+ // log.log("Echarts height: index:", pieConfig, radius, pieIndex, xPosition, yPosition);
79
+ return {
80
+ radius: radius,
81
+ center: [xPosition, yPosition],
82
+ } as const;
83
+ }
@@ -0,0 +1,62 @@
1
+ import {
2
+ MultiCompBuilder,
3
+ dropdownControl,
4
+ BoolControl,
5
+ showLabelPropertyView,
6
+ } from "lowcoder-sdk";
7
+ import { ScatterSeriesOption } from "echarts";
8
+ import { trans } from "i18n/comps";
9
+
10
+ const ScatterShapeOptions = [
11
+ {
12
+ label: trans("chart.circle"),
13
+ value: "circle",
14
+ },
15
+ {
16
+ label: trans("chart.rect"),
17
+ value: "rect",
18
+ },
19
+ {
20
+ label: trans("chart.triangle"),
21
+ value: "triangle",
22
+ },
23
+ {
24
+ label: trans("chart.diamond"),
25
+ value: "diamond",
26
+ },
27
+ {
28
+ label: trans("chart.pin"),
29
+ value: "pin",
30
+ },
31
+ {
32
+ label: trans("chart.arrow"),
33
+ value: "arrow",
34
+ },
35
+ ] as const;
36
+
37
+ export const ScatterChartConfig = (function () {
38
+ return new MultiCompBuilder(
39
+ {
40
+ showLabel: BoolControl,
41
+ shape: dropdownControl(ScatterShapeOptions, "circle"),
42
+ },
43
+ (props): ScatterSeriesOption => {
44
+ return {
45
+ type: "scatter",
46
+ symbol: props.shape,
47
+ label: {
48
+ show: props.showLabel,
49
+ },
50
+ };
51
+ }
52
+ )
53
+ .setPropertyViewFn((children) => (
54
+ <>
55
+ {showLabelPropertyView(children)}
56
+ {children.shape.propertyView({
57
+ label: trans("chart.scatterShape"),
58
+ })}
59
+ </>
60
+ ))
61
+ .build();
62
+ })();
@@ -0,0 +1,288 @@
1
+ import {
2
+ jsonControl,
3
+ JSONObject,
4
+ stateComp,
5
+ toJSONObjectArray,
6
+ toObject,
7
+ BoolControl,
8
+ withDefault,
9
+ StringControl,
10
+ NumberControl,
11
+ FunctionControl,
12
+ dropdownControl,
13
+ eventHandlerControl,
14
+ valueComp,
15
+ withType,
16
+ ValueFromOption,
17
+ uiChildren,
18
+ } from "lowcoder-sdk";
19
+ import { RecordConstructorToComp, RecordConstructorToView } from "lowcoder-core";
20
+ import { BarChartConfig } from "./chartConfigs/barChartConfig";
21
+ import { XAxisConfig, YAxisConfig } from "./chartConfigs/cartesianAxisConfig";
22
+ import { LegendConfig } from "./chartConfigs/legendConfig";
23
+ import { LineChartConfig } from "./chartConfigs/lineChartConfig";
24
+ import { PieChartConfig } from "./chartConfigs/pieChartConfig";
25
+ import { ScatterChartConfig } from "./chartConfigs/scatterChartConfig";
26
+ import { SeriesListComp } from "./seriesComp";
27
+ import { EChartsOption } from "echarts";
28
+ import { i18nObjs, trans } from "i18n/comps";
29
+
30
+ export const ChartTypeOptions = [
31
+ {
32
+ label: trans("chart.bar"),
33
+ value: "bar",
34
+ },
35
+ {
36
+ label: trans("chart.line"),
37
+ value: "line",
38
+ },
39
+ {
40
+ label: trans("chart.scatter"),
41
+ value: "scatter",
42
+ },
43
+ {
44
+ label: trans("chart.pie"),
45
+ value: "pie",
46
+ },
47
+ ] as const;
48
+
49
+ const chartModeOptions = [
50
+ {
51
+ label: trans("chart.UIMode"),
52
+ value: "ui",
53
+ },
54
+ {
55
+ label: "ECharts JSON",
56
+ value: "json",
57
+ },
58
+ {
59
+ label: "Map",
60
+ value: "map",
61
+ },
62
+ ] as const;
63
+
64
+ export const UIEventOptions = [
65
+ {
66
+ label: trans("chart.select"),
67
+ value: "select",
68
+ description: trans("chart.selectDesc"),
69
+ },
70
+
71
+ {
72
+ label: trans("chart.unSelect"),
73
+ value: "unselect",
74
+ description: trans("chart.unselectDesc"),
75
+ },
76
+ ] as const;
77
+
78
+ export const MapEventOptions = [
79
+ {
80
+ label: trans("chart.mapReady"),
81
+ value: "mapReady",
82
+ description: trans("chart.mapReadyDesc"),
83
+ },
84
+ {
85
+ label: trans("chart.zoomLevelChange"),
86
+ value: "zoomLevelChange",
87
+ description: trans("chart.zoomLevelChangeDesc"),
88
+ },
89
+ {
90
+ label: trans("chart.centerPositionChange"),
91
+ value: "centerPositionChange",
92
+ description: trans("chart.centerPositionChangeDesc"),
93
+ },
94
+ ] as const;
95
+
96
+ export const XAxisDirectionOptions = [
97
+ {
98
+ label: trans("chart.horizontal"),
99
+ value: "horizontal",
100
+ },
101
+ {
102
+ label: trans("chart.vertical"),
103
+ value: "vertical",
104
+ },
105
+ ] as const;
106
+
107
+ export type XAxisDirectionType = ValueFromOption<typeof XAxisDirectionOptions>;
108
+
109
+ export const noDataAxisConfig = {
110
+ animation: false,
111
+ xAxis: {
112
+ type: "category",
113
+ name: trans("chart.noData"),
114
+ nameLocation: "middle",
115
+ data: [],
116
+ axisLine: {
117
+ lineStyle: {
118
+ color: "#8B8FA3",
119
+ },
120
+ },
121
+ },
122
+ yAxis: {
123
+ type: "value",
124
+ axisLabel: {
125
+ color: "#8B8FA3",
126
+ },
127
+ splitLine: {
128
+ lineStyle: {
129
+ color: "#F0F0F0",
130
+ },
131
+ },
132
+ },
133
+ tooltip: {
134
+ show: false,
135
+ },
136
+ series: [
137
+ {
138
+ data: [700],
139
+ type: "line",
140
+ itemStyle: {
141
+ opacity: 0,
142
+ },
143
+ },
144
+ ],
145
+ } as EChartsOption;
146
+
147
+ export const noDataPieChartConfig = {
148
+ animation: false,
149
+ tooltip: {
150
+ show: false,
151
+ },
152
+ legend: {
153
+ formatter: trans("chart.unknown"),
154
+ top: "bottom",
155
+ selectedMode: false,
156
+ },
157
+ color: ["#B8BBCC", "#CED0D9", "#DCDEE6", "#E6E6EB"],
158
+ series: [
159
+ {
160
+ type: "pie",
161
+ radius: "35%",
162
+ center: ["25%", "50%"],
163
+ silent: true,
164
+ label: {
165
+ show: false,
166
+ },
167
+ data: [
168
+ {
169
+ name: "1",
170
+ value: 70,
171
+ },
172
+ {
173
+ name: "2",
174
+ value: 68,
175
+ },
176
+ {
177
+ name: "3",
178
+ value: 48,
179
+ },
180
+ {
181
+ name: "4",
182
+ value: 40,
183
+ },
184
+ ],
185
+ },
186
+ {
187
+ type: "pie",
188
+ radius: "35%",
189
+ center: ["75%", "50%"],
190
+ silent: true,
191
+ label: {
192
+ show: false,
193
+ },
194
+ data: [
195
+ {
196
+ name: "1",
197
+ value: 70,
198
+ },
199
+ {
200
+ name: "2",
201
+ value: 68,
202
+ },
203
+ {
204
+ name: "3",
205
+ value: 48,
206
+ },
207
+ {
208
+ name: "4",
209
+ value: 40,
210
+ },
211
+ ],
212
+ },
213
+ ],
214
+ } as EChartsOption;
215
+
216
+ export type ChartSize = { w: number; h: number };
217
+
218
+ export const getDataKeys = (data: Array<JSONObject>) => {
219
+ if (!data) {
220
+ return [];
221
+ }
222
+ const dataKeys: Array<string> = [];
223
+ data.slice(0, 50).forEach((d) => {
224
+ Object.keys(d).forEach((key) => {
225
+ if (!dataKeys.includes(key)) {
226
+ dataKeys.push(key);
227
+ }
228
+ });
229
+ });
230
+ return dataKeys;
231
+ };
232
+
233
+ const ChartOptionMap = {
234
+ bar: BarChartConfig,
235
+ line: LineChartConfig,
236
+ pie: PieChartConfig,
237
+ scatter: ScatterChartConfig,
238
+ };
239
+
240
+ const ChartOptionComp = withType(ChartOptionMap, "bar");
241
+ export type CharOptionCompType = keyof typeof ChartOptionMap;
242
+
243
+ export const chartUiModeChildren = {
244
+ title: StringControl,
245
+ data: jsonControl(toJSONObjectArray, i18nObjs.defaultDataSource),
246
+ xAxisKey: valueComp<string>(""), // x-axis, key from data
247
+ xAxisDirection: dropdownControl(XAxisDirectionOptions, "horizontal"),
248
+ series: SeriesListComp,
249
+ xConfig: XAxisConfig,
250
+ yConfig: YAxisConfig,
251
+ legendConfig: LegendConfig,
252
+ chartConfig: ChartOptionComp,
253
+ onUIEvent: eventHandlerControl(UIEventOptions),
254
+ };
255
+
256
+ const chartMapModeChildren = {
257
+ mapInstance: stateComp(),
258
+ getMapInstance: FunctionControl,
259
+ mapApiKey: withDefault(StringControl, ''),
260
+ mapZoomLevel: withDefault(NumberControl, 3),
261
+ mapCenterLng: withDefault(NumberControl, 15.932644),
262
+ mapCenterLat: withDefault(NumberControl, 50.942063),
263
+ mapOptions: jsonControl(toObject, i18nObjs.defaultMapJsonOption),
264
+ onMapEvent: eventHandlerControl(MapEventOptions),
265
+ showCharts: withDefault(BoolControl, true),
266
+ }
267
+
268
+ export const chartChildrenMap = {
269
+ mode: dropdownControl(chartModeOptions, "ui"),
270
+ echartsOption: jsonControl(toObject, i18nObjs.defaultEchartsJsonOption),
271
+ selectedPoints: stateComp<
272
+ Array<{
273
+ seriesName: string;
274
+ // coordinate chart
275
+ x?: any;
276
+ y?: any;
277
+ // pie or funnel
278
+ itemName?: any;
279
+ value?: any;
280
+ }>
281
+ >([]),
282
+ ...chartUiModeChildren,
283
+ ...chartMapModeChildren,
284
+ };
285
+
286
+ const chartUiChildrenMap = uiChildren(chartChildrenMap);
287
+ export type ChartCompPropsType = RecordConstructorToView<typeof chartUiChildrenMap>;
288
+ export type ChartCompChildrenType = RecordConstructorToComp<typeof chartUiChildrenMap>;