lowcoder-comps 0.0.18 → 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.
- package/README.md +27 -0
- package/index.html +26 -0
- package/index.tsx +19 -0
- package/jest.config.js +6 -0
- package/package.json +3 -4
- package/src/__test__/allComp.test.tsx +61 -0
- package/src/app-env.d.ts +3 -0
- package/src/comps/calendarComp/calendarComp.tsx +443 -0
- package/src/comps/calendarComp/calendarConstants.tsx +898 -0
- package/src/comps/chartComp/chartComp.tsx +356 -0
- package/src/comps/chartComp/chartConfigs/barChartConfig.tsx +51 -0
- package/src/comps/chartComp/chartConfigs/cartesianAxisConfig.tsx +307 -0
- package/src/comps/chartComp/chartConfigs/chartUrls.tsx +9 -0
- package/src/comps/chartComp/chartConfigs/legendConfig.tsx +55 -0
- package/src/comps/chartComp/chartConfigs/lineChartConfig.tsx +96 -0
- package/src/comps/chartComp/chartConfigs/pieChartConfig.tsx +83 -0
- package/src/comps/chartComp/chartConfigs/scatterChartConfig.tsx +62 -0
- package/src/comps/chartComp/chartConstants.tsx +288 -0
- package/src/comps/chartComp/chartPropertyView.tsx +218 -0
- package/src/comps/chartComp/chartUtils.ts +291 -0
- package/src/comps/chartComp/reactEcharts/core.tsx +194 -0
- package/src/comps/chartComp/reactEcharts/index.ts +21 -0
- package/src/comps/chartComp/reactEcharts/types.ts +76 -0
- package/src/comps/chartComp/seriesComp.tsx +119 -0
- package/src/comps/imageEditorComp/imageEditorClass.tsx +52 -0
- package/src/comps/imageEditorComp/imageEditorConstants.tsx +109 -0
- package/src/comps/imageEditorComp/index.tsx +184 -0
- package/src/comps/mermaidComp/index.tsx +44 -0
- package/src/comps/mermaidComp/mermaid.tsx +29 -0
- package/src/global.ts +1 -0
- package/src/i18n/comps/index.tsx +29 -0
- package/src/i18n/comps/locales/en.ts +150 -0
- package/src/i18n/comps/locales/enObj.tsx +198 -0
- package/src/i18n/comps/locales/index.ts +7 -0
- package/src/i18n/comps/locales/types.tsx +10 -0
- package/src/i18n/comps/locales/zh.ts +145 -0
- package/src/i18n/comps/locales/zhObj.tsx +4 -0
- package/src/index.ts +11 -0
- package/tsconfig.json +22 -0
- package/vite.config.js +10 -0
- package/0d763a87.js +0 -798
- package/1813144f.js +0 -940
- package/2039ece8.js +0 -91
- package/256b619e.js +0 -92
- package/2ff2c7a6.js +0 -6
- package/372dc2a7.js +0 -365
- package/3b12eb0e.js +0 -2103
- package/3c0b160f.js +0 -236
- package/401f73a2.js +0 -1602
- package/4137766d.js +0 -86
- package/4728777d.js +0 -447
- package/4881ced8.js +0 -943
- package/50cdd04e.js +0 -823
- package/5a46ac81.js +0 -1118
- package/6737b605.js +0 -985
- package/6a3117df.js +0 -159
- package/6add348f.js +0 -2456
- package/7aa956be.js +0 -326
- package/80fe4e54.js +0 -24
- package/847d7b9d.js +0 -7
- package/8c3bb161.js +0 -18619
- package/8edfc14c.js +0 -1246
- package/a96f93b1.js +0 -1032
- package/b680d6c7.js +0 -70
- package/babb4d5d.js +0 -832
- package/bfa09fb0.js +0 -607
- package/c1008714.js +0 -275
- package/ca536ab8.js +0 -117238
- package/cb157d73.js +0 -849
- package/ce50b2ed.js +0 -2679
- package/d4fa84c2.js +0 -212
- package/d7fee54a.js +0 -451
- package/e1a22e9d.js +0 -34
- package/e1cbc8ec.js +0 -46688
- package/f9637058.js +0 -16
- package/fbeabd79.js +0 -793
- package/fc3693cc.js +0 -2827
- package/index.js +0 -5
package/README.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# lowcoder comp lib
|
|
2
|
+
|
|
3
|
+
## Start
|
|
4
|
+
|
|
5
|
+
Start dev server to develop your comp lib.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
yarn start
|
|
9
|
+
|
|
10
|
+
# or
|
|
11
|
+
|
|
12
|
+
npm start
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Build
|
|
16
|
+
|
|
17
|
+
Build current comp lib into a .tgz file that you can upload it to the Lowcoder Comp Market.
|
|
18
|
+
|
|
19
|
+
Before build you should change the version in package.json file.
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
yarn build
|
|
23
|
+
|
|
24
|
+
# or
|
|
25
|
+
|
|
26
|
+
npm run build
|
|
27
|
+
```
|
package/index.html
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
+
<title>Lowcoder Comp Playground</title>
|
|
8
|
+
<style>
|
|
9
|
+
#root {
|
|
10
|
+
height: 100vh;
|
|
11
|
+
}
|
|
12
|
+
#root-loader {
|
|
13
|
+
height: 100vh;
|
|
14
|
+
display: flex;
|
|
15
|
+
justify-content: center;
|
|
16
|
+
align-items: center;
|
|
17
|
+
}
|
|
18
|
+
</style>
|
|
19
|
+
</head>
|
|
20
|
+
<body>
|
|
21
|
+
<div id="root">
|
|
22
|
+
<div id="root-loader">Loading...</div>
|
|
23
|
+
</div>
|
|
24
|
+
<script src="index.tsx" type="module"></script>
|
|
25
|
+
</body>
|
|
26
|
+
</html>
|
package/index.tsx
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import ReactDOM from "react-dom";
|
|
2
|
+
import { CompIDE } from "lowcoder-sdk";
|
|
3
|
+
import { name, version, lowcoder } from "./package.json";
|
|
4
|
+
import compMap from "./src/index";
|
|
5
|
+
|
|
6
|
+
import "lowcoder-sdk/dist/style.css";
|
|
7
|
+
|
|
8
|
+
function CompDevApp() {
|
|
9
|
+
return (
|
|
10
|
+
<CompIDE
|
|
11
|
+
compMap={compMap}
|
|
12
|
+
packageName={name}
|
|
13
|
+
packageVersion={version}
|
|
14
|
+
compMeta={lowcoder.comps}
|
|
15
|
+
/>
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
ReactDOM.render(<CompDevApp />, document.querySelector("#root"));
|
package/jest.config.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lowcoder-comps",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.19",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"dependencies": {
|
|
@@ -58,8 +58,7 @@
|
|
|
58
58
|
"h": 40
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
-
}
|
|
62
|
-
"entry": "index.js"
|
|
61
|
+
}
|
|
63
62
|
},
|
|
64
63
|
"scripts": {
|
|
65
64
|
"start": "vite",
|
|
@@ -74,4 +73,4 @@
|
|
|
74
73
|
"vite": "^4.3.9",
|
|
75
74
|
"vite-tsconfig-paths": "^3.6.0"
|
|
76
75
|
}
|
|
77
|
-
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import _ from "lodash";
|
|
2
|
+
import { CompConstructor, CustomAction } from "lowcoder-core";
|
|
3
|
+
import { evalAndReduce, isExposingMethodComp } from "lowcoder-sdk";
|
|
4
|
+
import { ChartCompWithDefault } from "comps/chartComp/chartComp";
|
|
5
|
+
import log from "loglevel";
|
|
6
|
+
|
|
7
|
+
const COMPS_MAP = {
|
|
8
|
+
chart: ChartCompWithDefault,
|
|
9
|
+
} as Record<string, CompConstructor>;
|
|
10
|
+
|
|
11
|
+
const compContextActionMap = {} as Record<string, CustomAction>;
|
|
12
|
+
|
|
13
|
+
test("test comp don't change if no value change", () => {
|
|
14
|
+
Object.keys(COMPS_MAP).forEach((name) => {
|
|
15
|
+
const Comp = COMPS_MAP[name];
|
|
16
|
+
let comp = new Comp({});
|
|
17
|
+
if (compContextActionMap[name]) {
|
|
18
|
+
// set context
|
|
19
|
+
comp = comp.reduce(compContextActionMap[name]);
|
|
20
|
+
}
|
|
21
|
+
comp.getView(); // getView() is allowed when unevaluated
|
|
22
|
+
comp = evalAndReduce(comp);
|
|
23
|
+
expect(comp.node() === comp.node()).toBe(true);
|
|
24
|
+
expect(comp.node()?.evaluate() === comp.node()?.evaluate()).toBe(true);
|
|
25
|
+
const comp2 = evalAndReduce(comp);
|
|
26
|
+
if (comp2 !== comp) {
|
|
27
|
+
const comp3 = evalAndReduce(comp2);
|
|
28
|
+
if (comp3 === comp2) {
|
|
29
|
+
// log.debug(`${name} need eval twice to converge`);
|
|
30
|
+
} else {
|
|
31
|
+
const newComp = evalAndReduce(comp);
|
|
32
|
+
Object.keys((comp as any).children).forEach((key) => {
|
|
33
|
+
log.log(
|
|
34
|
+
`${key}, isEqual ${(comp as any).children[key] === (newComp as any).children[key]}`
|
|
35
|
+
);
|
|
36
|
+
});
|
|
37
|
+
throw new Error("bad " + name);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test("comp exposing method duplicate name", () => {
|
|
44
|
+
// one comp can't expose two methods with the same name
|
|
45
|
+
Object.values(COMPS_MAP).forEach((Comp) => {
|
|
46
|
+
const comp = new Comp({});
|
|
47
|
+
const methods = [];
|
|
48
|
+
if (isExposingMethodComp(comp)) {
|
|
49
|
+
methods.push(comp.getMethodConfig());
|
|
50
|
+
}
|
|
51
|
+
const childrenMap = (comp as any).children;
|
|
52
|
+
childrenMap &&
|
|
53
|
+
Object.values(childrenMap).forEach((child) => {
|
|
54
|
+
if (isExposingMethodComp(child as any)) {
|
|
55
|
+
methods.push((child as any).getMethodConfig());
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
const allMethodName = methods.flatMap((m) => m.map((methodConfig) => methodConfig.name));
|
|
59
|
+
expect(allMethodName.length).toEqual(_.uniq(allMethodName).length);
|
|
60
|
+
});
|
|
61
|
+
});
|
package/src/app-env.d.ts
ADDED
|
@@ -0,0 +1,443 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isValidColor,
|
|
3
|
+
NameConfig,
|
|
4
|
+
NameConfigHidden,
|
|
5
|
+
BoolControl,
|
|
6
|
+
UICompBuilder,
|
|
7
|
+
withDefault,
|
|
8
|
+
withExposingConfigs,
|
|
9
|
+
NumberControl,
|
|
10
|
+
StringControl,
|
|
11
|
+
hiddenPropertyView,
|
|
12
|
+
ChangeEventHandlerControl,
|
|
13
|
+
Section,
|
|
14
|
+
sectionNames,
|
|
15
|
+
dropdownControl,
|
|
16
|
+
styleControl,
|
|
17
|
+
ThemeContext,
|
|
18
|
+
CalendarStyle,
|
|
19
|
+
DateParser,
|
|
20
|
+
CustomModal,
|
|
21
|
+
jsonValueExposingStateControl,
|
|
22
|
+
CalendarDeleteIcon,
|
|
23
|
+
Tooltip,
|
|
24
|
+
} from "lowcoder-sdk";
|
|
25
|
+
import { Input, Form } from "antd";
|
|
26
|
+
import { trans, getCalendarLocale } from "../../i18n/comps";
|
|
27
|
+
import { createRef, useContext, useRef, useState } from "react";
|
|
28
|
+
import FullCalendar from "@fullcalendar/react";
|
|
29
|
+
import dayGridPlugin from "@fullcalendar/daygrid";
|
|
30
|
+
import timeGridPlugin from "@fullcalendar/timegrid";
|
|
31
|
+
import interactionPlugin from "@fullcalendar/interaction";
|
|
32
|
+
import listPlugin from "@fullcalendar/list";
|
|
33
|
+
import allLocales from "@fullcalendar/core/locales-all";
|
|
34
|
+
import { EventContentArg, DateSelectArg } from "@fullcalendar/core";
|
|
35
|
+
import momentPlugin from "@fullcalendar/moment";
|
|
36
|
+
import {
|
|
37
|
+
DefaultViewOptions,
|
|
38
|
+
FirstDayOptions,
|
|
39
|
+
Wrapper,
|
|
40
|
+
Event,
|
|
41
|
+
Remove,
|
|
42
|
+
EventType,
|
|
43
|
+
defaultData,
|
|
44
|
+
ViewType,
|
|
45
|
+
buttonText,
|
|
46
|
+
headerToolbar,
|
|
47
|
+
views,
|
|
48
|
+
slotLabelFormat,
|
|
49
|
+
viewClassNames,
|
|
50
|
+
FormWrapper,
|
|
51
|
+
} from "./calendarConstants";
|
|
52
|
+
import dayjs from "dayjs";
|
|
53
|
+
|
|
54
|
+
const childrenMap = {
|
|
55
|
+
events: jsonValueExposingStateControl("events", defaultData),
|
|
56
|
+
onEvent: ChangeEventHandlerControl,
|
|
57
|
+
|
|
58
|
+
editable: withDefault(BoolControl, true),
|
|
59
|
+
defaultDate: withDefault(StringControl, "{{ new Date() }}"),
|
|
60
|
+
defaultView: dropdownControl(DefaultViewOptions, "timeGridWeek"),
|
|
61
|
+
firstDay: dropdownControl(FirstDayOptions, "1"),
|
|
62
|
+
showEventTime: withDefault(BoolControl, true),
|
|
63
|
+
showWeekends: withDefault(BoolControl, true),
|
|
64
|
+
showAllDay: withDefault(BoolControl, true),
|
|
65
|
+
dayMaxEvents: withDefault(NumberControl, 2),
|
|
66
|
+
eventMaxStack: withDefault(NumberControl, 0),
|
|
67
|
+
style: styleControl(CalendarStyle),
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
let CalendarBasicComp = (function () {
|
|
71
|
+
return new UICompBuilder(childrenMap, (props) => {
|
|
72
|
+
const theme = useContext(ThemeContext);
|
|
73
|
+
const ref = createRef<HTMLDivElement>();
|
|
74
|
+
const editEvent = useRef<EventType>();
|
|
75
|
+
const [form] = Form.useForm();
|
|
76
|
+
const [left, setLeft] = useState<number | undefined>(undefined);
|
|
77
|
+
|
|
78
|
+
const events = props.events.value.map((item: EventType) => {
|
|
79
|
+
return {
|
|
80
|
+
title: item.title,
|
|
81
|
+
id: item.id,
|
|
82
|
+
start: dayjs(item.start, DateParser).format(),
|
|
83
|
+
end: dayjs(item.end, DateParser).format(),
|
|
84
|
+
allDay: item.allDay,
|
|
85
|
+
color: isValidColor(item.color || "") ? item.color : theme?.theme?.primary,
|
|
86
|
+
...(item.groupId ? { groupId: item.groupId } : null),
|
|
87
|
+
};
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const {
|
|
91
|
+
defaultDate,
|
|
92
|
+
defaultView,
|
|
93
|
+
showEventTime,
|
|
94
|
+
showWeekends,
|
|
95
|
+
showAllDay,
|
|
96
|
+
dayMaxEvents,
|
|
97
|
+
eventMaxStack,
|
|
98
|
+
style,
|
|
99
|
+
firstDay,
|
|
100
|
+
editable,
|
|
101
|
+
} = props;
|
|
102
|
+
|
|
103
|
+
function renderEventContent(eventInfo: EventContentArg) {
|
|
104
|
+
const isList = eventInfo.view.type === "listWeek";
|
|
105
|
+
let sizeClass = "";
|
|
106
|
+
if ([ViewType.WEEK, ViewType.DAY].includes(eventInfo.view.type as ViewType)) {
|
|
107
|
+
const duration = dayjs(eventInfo.event.end).diff(dayjs(eventInfo.event.start), "minutes");
|
|
108
|
+
if (duration <= 30 || eventInfo.event.allDay) {
|
|
109
|
+
sizeClass = "small";
|
|
110
|
+
} else if (duration <= 60) {
|
|
111
|
+
sizeClass = "middle";
|
|
112
|
+
} else {
|
|
113
|
+
sizeClass = "large";
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const stateClass =
|
|
117
|
+
dayjs().isAfter(dayjs(eventInfo.event.end)) &&
|
|
118
|
+
(eventInfo.view.type as ViewType) !== ViewType.MONTH
|
|
119
|
+
? "past"
|
|
120
|
+
: "";
|
|
121
|
+
|
|
122
|
+
return (
|
|
123
|
+
<Event
|
|
124
|
+
className={`event ${sizeClass} ${stateClass}`}
|
|
125
|
+
isList={isList}
|
|
126
|
+
bg={eventInfo.backgroundColor}
|
|
127
|
+
theme={theme?.theme}
|
|
128
|
+
allDay={showAllDay}
|
|
129
|
+
$style={props.style}
|
|
130
|
+
>
|
|
131
|
+
<div className="event-time">{eventInfo.timeText}</div>
|
|
132
|
+
<div className="event-title">{eventInfo.event.title}</div>
|
|
133
|
+
<Remove
|
|
134
|
+
isList={isList}
|
|
135
|
+
className="event-remove"
|
|
136
|
+
onClick={(e) => {
|
|
137
|
+
e.stopPropagation();
|
|
138
|
+
props.onEvent("change");
|
|
139
|
+
const event = events.filter((item: EventType) => item.id !== eventInfo.event.id);
|
|
140
|
+
props.events.onChange(event);
|
|
141
|
+
}}
|
|
142
|
+
onMouseDown={(e) => {
|
|
143
|
+
e.stopPropagation();
|
|
144
|
+
e.preventDefault();
|
|
145
|
+
}}
|
|
146
|
+
>
|
|
147
|
+
<CalendarDeleteIcon />
|
|
148
|
+
</Remove>
|
|
149
|
+
</Event>
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const handleDbClick = () => {
|
|
154
|
+
const event = props.events.value.find(
|
|
155
|
+
(item: EventType) => item.id === editEvent.current?.id
|
|
156
|
+
) as EventType;
|
|
157
|
+
if (!editable || !editEvent.current) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
if (event) {
|
|
161
|
+
const { title, groupId, color, id } = event;
|
|
162
|
+
const eventInfo = {
|
|
163
|
+
title,
|
|
164
|
+
groupId,
|
|
165
|
+
color,
|
|
166
|
+
id,
|
|
167
|
+
};
|
|
168
|
+
showModal(eventInfo, true);
|
|
169
|
+
} else {
|
|
170
|
+
showModal(editEvent.current, false);
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
const handleCreate = (info: DateSelectArg) => {
|
|
175
|
+
const event = {
|
|
176
|
+
allDay: info.allDay,
|
|
177
|
+
start: info.startStr,
|
|
178
|
+
end: info.endStr,
|
|
179
|
+
};
|
|
180
|
+
const view = info.view.type as ViewType;
|
|
181
|
+
const duration = dayjs(info.end).diff(dayjs(info.start), "minutes");
|
|
182
|
+
const singleClick =
|
|
183
|
+
(view === ViewType.MONTH && duration === 1440) ||
|
|
184
|
+
([ViewType.WEEK, ViewType.DAY].includes(view) && duration === 30) ||
|
|
185
|
+
(info.allDay && duration === 1440);
|
|
186
|
+
if (singleClick) {
|
|
187
|
+
editEvent.current = event;
|
|
188
|
+
setTimeout(() => {
|
|
189
|
+
editEvent.current = undefined;
|
|
190
|
+
}, 500);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
showModal(event, false);
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
const showModal = (event: EventType, ifEdit: boolean) => {
|
|
197
|
+
const modalTitle = ifEdit ? trans("calendar.editEvent") : trans("calendar.creatEvent");
|
|
198
|
+
form && form.setFieldsValue(event);
|
|
199
|
+
const eventId = editEvent.current?.id;
|
|
200
|
+
CustomModal.confirm({
|
|
201
|
+
title: modalTitle,
|
|
202
|
+
content: (
|
|
203
|
+
<FormWrapper form={form}>
|
|
204
|
+
<Form.Item
|
|
205
|
+
label={
|
|
206
|
+
<Tooltip title={trans("calendar.eventIdTooltip")}>
|
|
207
|
+
{trans("calendar.eventId")}
|
|
208
|
+
</Tooltip>
|
|
209
|
+
}
|
|
210
|
+
name="id"
|
|
211
|
+
rules={[{ required: true, message: trans("calendar.eventIdRequire") }]}
|
|
212
|
+
>
|
|
213
|
+
<Input />
|
|
214
|
+
</Form.Item>
|
|
215
|
+
<Form.Item
|
|
216
|
+
label={trans("calendar.eventName")}
|
|
217
|
+
name="title"
|
|
218
|
+
rules={[{ required: true, message: trans("calendar.eventNameRequire") }]}
|
|
219
|
+
>
|
|
220
|
+
<Input />
|
|
221
|
+
</Form.Item>
|
|
222
|
+
<Form.Item label={trans("calendar.eventColor")} name="color">
|
|
223
|
+
<Input />
|
|
224
|
+
</Form.Item>
|
|
225
|
+
<Form.Item
|
|
226
|
+
label={
|
|
227
|
+
<Tooltip title={trans("calendar.groupIdTooltip")}>
|
|
228
|
+
{trans("calendar.eventGroupId")}
|
|
229
|
+
</Tooltip>
|
|
230
|
+
}
|
|
231
|
+
name="groupId"
|
|
232
|
+
>
|
|
233
|
+
<Input />
|
|
234
|
+
</Form.Item>
|
|
235
|
+
</FormWrapper>
|
|
236
|
+
),
|
|
237
|
+
onConfirm: () => {
|
|
238
|
+
form.submit();
|
|
239
|
+
return form.validateFields().then(() => {
|
|
240
|
+
const { id, groupId, color, title = "" } = form.getFieldsValue();
|
|
241
|
+
const idExist = props.events.value.findIndex((item: EventType) => item.id === id);
|
|
242
|
+
if (idExist > -1 && id !== eventId) {
|
|
243
|
+
form.setFields([{ name: "id", errors: [trans("calendar.eventIdExist")] }]);
|
|
244
|
+
throw new Error();
|
|
245
|
+
}
|
|
246
|
+
if (ifEdit) {
|
|
247
|
+
const changeEvents = props.events.value.map((item: EventType) => {
|
|
248
|
+
if (item.id === eventId) {
|
|
249
|
+
return {
|
|
250
|
+
...item,
|
|
251
|
+
title,
|
|
252
|
+
id,
|
|
253
|
+
...(groupId !== undefined ? { groupId } : null),
|
|
254
|
+
...(color !== undefined ? { color } : null),
|
|
255
|
+
};
|
|
256
|
+
} else {
|
|
257
|
+
return item;
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
props.events.onChange(changeEvents);
|
|
261
|
+
} else {
|
|
262
|
+
const createInfo = {
|
|
263
|
+
allDay: event.allDay,
|
|
264
|
+
start: event.start,
|
|
265
|
+
end: event.end,
|
|
266
|
+
id,
|
|
267
|
+
title,
|
|
268
|
+
...(groupId !== undefined ? { groupId } : null),
|
|
269
|
+
...(color !== undefined ? { color } : null),
|
|
270
|
+
};
|
|
271
|
+
props.events.onChange([...props.events.value, createInfo]);
|
|
272
|
+
}
|
|
273
|
+
props.onEvent("change");
|
|
274
|
+
form.resetFields();
|
|
275
|
+
});
|
|
276
|
+
},
|
|
277
|
+
onCancel: () => {
|
|
278
|
+
form.resetFields();
|
|
279
|
+
},
|
|
280
|
+
});
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
let initialDate = defaultDate;
|
|
284
|
+
try {
|
|
285
|
+
initialDate = new Date(defaultDate).toISOString();
|
|
286
|
+
} catch (error) {
|
|
287
|
+
initialDate = undefined;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
return (
|
|
291
|
+
<Wrapper
|
|
292
|
+
ref={ref}
|
|
293
|
+
editable={editable}
|
|
294
|
+
$style={style}
|
|
295
|
+
theme={theme?.theme}
|
|
296
|
+
onDoubleClick={handleDbClick}
|
|
297
|
+
left={left}
|
|
298
|
+
key={initialDate ? defaultView + initialDate : defaultView}
|
|
299
|
+
>
|
|
300
|
+
<FullCalendar
|
|
301
|
+
slotEventOverlap={false}
|
|
302
|
+
events={events}
|
|
303
|
+
expandRows={true}
|
|
304
|
+
height={"100%"}
|
|
305
|
+
locale={getCalendarLocale()}
|
|
306
|
+
locales={allLocales}
|
|
307
|
+
firstDay={Number(firstDay)}
|
|
308
|
+
plugins={[dayGridPlugin, timeGridPlugin, interactionPlugin, listPlugin, momentPlugin]}
|
|
309
|
+
headerToolbar={headerToolbar}
|
|
310
|
+
moreLinkClick={(info) => {
|
|
311
|
+
let left = 0;
|
|
312
|
+
const ele = info.jsEvent.target as HTMLElement;
|
|
313
|
+
if (info.view.type === ViewType.DAY) {
|
|
314
|
+
if (info.allDay) {
|
|
315
|
+
left = ele.offsetParent?.parentElement?.offsetLeft || 0;
|
|
316
|
+
} else {
|
|
317
|
+
left = ele.parentElement?.offsetLeft || 0;
|
|
318
|
+
}
|
|
319
|
+
} else {
|
|
320
|
+
if (info.allDay) {
|
|
321
|
+
left = ele.offsetParent?.parentElement?.parentElement?.offsetLeft || 0;
|
|
322
|
+
} else {
|
|
323
|
+
left =
|
|
324
|
+
ele.offsetParent?.parentElement?.parentElement?.parentElement?.offsetLeft || 0;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
setLeft(left);
|
|
328
|
+
}}
|
|
329
|
+
buttonText={buttonText}
|
|
330
|
+
views={views}
|
|
331
|
+
eventClassNames={() => (!showEventTime ? "no-time" : "")}
|
|
332
|
+
slotLabelFormat={slotLabelFormat}
|
|
333
|
+
viewClassNames={viewClassNames}
|
|
334
|
+
moreLinkText={trans("calendar.more")}
|
|
335
|
+
initialDate={initialDate}
|
|
336
|
+
initialView={defaultView}
|
|
337
|
+
editable={editable}
|
|
338
|
+
selectable={editable}
|
|
339
|
+
selectMirror={false}
|
|
340
|
+
displayEventTime={showEventTime}
|
|
341
|
+
dayMaxEvents={dayMaxEvents}
|
|
342
|
+
eventMaxStack={eventMaxStack || undefined}
|
|
343
|
+
weekends={showWeekends}
|
|
344
|
+
allDaySlot={showAllDay}
|
|
345
|
+
eventContent={renderEventContent}
|
|
346
|
+
select={(info) => handleCreate(info)}
|
|
347
|
+
eventClick={(info) => {
|
|
348
|
+
const event = events.find((item: EventType) => item.id === info.event.id);
|
|
349
|
+
editEvent.current = event;
|
|
350
|
+
setTimeout(() => {
|
|
351
|
+
editEvent.current = undefined;
|
|
352
|
+
}, 500);
|
|
353
|
+
}}
|
|
354
|
+
eventsSet={(info) => {
|
|
355
|
+
let needChange = false;
|
|
356
|
+
let changeEvents: EventType[] = [];
|
|
357
|
+
info.forEach((item) => {
|
|
358
|
+
const event = events.find((i: EventType) => i.id === item.id);
|
|
359
|
+
const start = dayjs(item.start, DateParser).format();
|
|
360
|
+
const end = dayjs(item.end, DateParser).format();
|
|
361
|
+
if (
|
|
362
|
+
start !== event?.start ||
|
|
363
|
+
end !== event?.end ||
|
|
364
|
+
!!item.allDay !== !!event?.allDay
|
|
365
|
+
) {
|
|
366
|
+
needChange = true;
|
|
367
|
+
changeEvents.push({
|
|
368
|
+
...event,
|
|
369
|
+
allDay: item.allDay,
|
|
370
|
+
start: item.startStr,
|
|
371
|
+
end: item.endStr,
|
|
372
|
+
});
|
|
373
|
+
} else {
|
|
374
|
+
changeEvents.push(event);
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
if (needChange) {
|
|
378
|
+
props.events.onChange(changeEvents);
|
|
379
|
+
props.onEvent("change");
|
|
380
|
+
}
|
|
381
|
+
}}
|
|
382
|
+
/>
|
|
383
|
+
</Wrapper>
|
|
384
|
+
);
|
|
385
|
+
})
|
|
386
|
+
.setPropertyViewFn((children) => {
|
|
387
|
+
return (
|
|
388
|
+
<>
|
|
389
|
+
<Section name={sectionNames.basic}>{children.events.propertyView({})}</Section>
|
|
390
|
+
<Section name={sectionNames.interaction}>{children.onEvent.getPropertyView()}</Section>
|
|
391
|
+
<Section name={sectionNames.advanced}>
|
|
392
|
+
{children.editable.propertyView({
|
|
393
|
+
label: trans("calendar.editable"),
|
|
394
|
+
})}
|
|
395
|
+
{children.defaultDate.propertyView({
|
|
396
|
+
label: trans("calendar.defaultDate"),
|
|
397
|
+
tooltip: trans("calendar.defaultDateTooltip"),
|
|
398
|
+
})}
|
|
399
|
+
{children.defaultView.propertyView({
|
|
400
|
+
label: trans("calendar.defaultView"),
|
|
401
|
+
tooltip: trans("calendar.defaultViewTooltip"),
|
|
402
|
+
})}
|
|
403
|
+
{children.firstDay.propertyView({
|
|
404
|
+
label: trans("calendar.startWeek"),
|
|
405
|
+
})}
|
|
406
|
+
{children.showEventTime.propertyView({
|
|
407
|
+
label: trans("calendar.showEventTime"),
|
|
408
|
+
tooltip: trans("calendar.showEventTimeTooltip"),
|
|
409
|
+
})}
|
|
410
|
+
{children.showWeekends.propertyView({
|
|
411
|
+
label: trans("calendar.showWeekends"),
|
|
412
|
+
})}
|
|
413
|
+
{children.showAllDay.propertyView({
|
|
414
|
+
label: trans("calendar.showAllDay"),
|
|
415
|
+
tooltip: trans("calendar.showAllDayTooltip"),
|
|
416
|
+
})}
|
|
417
|
+
{children.dayMaxEvents.propertyView({
|
|
418
|
+
label: trans("calendar.dayMaxEvents"),
|
|
419
|
+
tooltip: trans("calendar.dayMaxEventsTooltip"),
|
|
420
|
+
})}
|
|
421
|
+
{children.eventMaxStack.propertyView({
|
|
422
|
+
label: trans("calendar.eventMaxStack"),
|
|
423
|
+
tooltip: trans("calendar.eventMaxStackTooltip"),
|
|
424
|
+
})}
|
|
425
|
+
</Section>
|
|
426
|
+
<Section name={sectionNames.layout}>{hiddenPropertyView(children)}</Section>
|
|
427
|
+
<Section name={sectionNames.style}>{children.style.getPropertyView()}</Section>
|
|
428
|
+
</>
|
|
429
|
+
);
|
|
430
|
+
})
|
|
431
|
+
.build();
|
|
432
|
+
})();
|
|
433
|
+
|
|
434
|
+
CalendarBasicComp = class extends CalendarBasicComp {
|
|
435
|
+
override autoHeight(): boolean {
|
|
436
|
+
return false;
|
|
437
|
+
}
|
|
438
|
+
};
|
|
439
|
+
|
|
440
|
+
export const CalendarComp = withExposingConfigs(CalendarBasicComp, [
|
|
441
|
+
new NameConfig("events", trans("calendar.events")),
|
|
442
|
+
NameConfigHidden,
|
|
443
|
+
]);
|