lowcoder-comps 0.0.7 → 0.0.9
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/icons/icon-chart.svg +15 -0
- package/icons/icon-comp-calendar.svg +22 -0
- package/index.html +26 -0
- package/index.tsx +19 -0
- package/jest.config.js +5 -0
- package/package.json +1 -4
- package/src/__test__/allComp.test.tsx +61 -0
- package/src/app-env.d.ts +3 -0
- package/src/comps/calendarComp/calendarComp.tsx +442 -0
- package/src/comps/calendarComp/calendarConstants.tsx +897 -0
- package/src/comps/chartComp/chartComp.tsx +249 -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 +6 -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 +243 -0
- package/src/comps/chartComp/chartPropertyView.tsx +161 -0
- package/src/comps/chartComp/chartUtils.ts +240 -0
- package/src/comps/chartComp/reactEcharts/core.tsx +187 -0
- package/src/comps/chartComp/reactEcharts/index.ts +20 -0
- package/src/comps/chartComp/reactEcharts/types.ts +70 -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 +142 -0
- package/src/i18n/comps/locales/enObj.tsx +120 -0
- package/src/i18n/comps/locales/index.ts +7 -0
- package/src/i18n/comps/locales/types.tsx +9 -0
- package/src/i18n/comps/locales/zh.ts +4 -0
- package/src/i18n/comps/locales/zhObj.tsx +4 -0
- package/src/index.ts +11 -0
- package/vite.config.js +10 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="48px" height="48px" viewBox="0 0 48 48" version="1.1">
|
|
2
|
+
<g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
|
3
|
+
<g transform="translate(6.000000, 11.500000)" stroke="#D7D9E0" stroke-linecap="round" stroke-width="2">
|
|
4
|
+
<line x1="-2.00715996e-17" y1="0.5" x2="36" y2="0.5"/>
|
|
5
|
+
<line x1="-2.00715996e-17" y1="8.5" x2="36" y2="8.5"/>
|
|
6
|
+
<line x1="2.70913881e-14" y1="16.5" x2="36" y2="16.5"/>
|
|
7
|
+
<line x1="2.70913881e-14" y1="24.5" x2="36" y2="24.5"/>
|
|
8
|
+
</g>
|
|
9
|
+
<g transform="translate(11.000000, 10.000000)" fill="#3377FF">
|
|
10
|
+
<path d="M11,0 L15,0 C15.5522847,-1.01453063e-16 16,0.44771525 16,1 L16,25 L16,25 L10,25 L10,1 C10,0.44771525 10.4477153,7.67586877e-16 11,0 Z"/>
|
|
11
|
+
<path d="M1,13 L5,13 C5.55228475,13 6,13.4477153 6,14 L6,25 L6,25 L0,25 L0,14 C-6.76353751e-17,13.4477153 0.44771525,13 1,13 Z"/>
|
|
12
|
+
<path d="M21,6 L25,6 C25.5522847,6 26,6.44771525 26,7 L26,25 L26,25 L20,25 L20,7 C20,6.44771525 20.4477153,6 21,6 Z"/>
|
|
13
|
+
</g>
|
|
14
|
+
</g>
|
|
15
|
+
</svg>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<svg width="48px" height="48px" viewBox="0 0 48 48" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
3
|
+
<g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
|
4
|
+
<g transform="translate(6.000000, 5.000000)">
|
|
5
|
+
<rect stroke="#D7D9E0" stroke-width="2" fill="#FFFFFF" x="1" y="4" width="34" height="30" rx="3"></rect>
|
|
6
|
+
<g transform="translate(5.000000, 14.000000)">
|
|
7
|
+
<rect fill="#3377FF" x="14" y="0" width="5" height="5" rx="1.5"></rect>
|
|
8
|
+
<rect fill="#8B8FA3" x="7" y="0" width="5" height="5" rx="1.5"></rect>
|
|
9
|
+
<rect fill="#3377FF" x="14" y="6" width="5" height="5" rx="1.5"></rect>
|
|
10
|
+
<rect fill="#8B8FA3" x="7" y="6" width="5" height="5" rx="1.5"></rect>
|
|
11
|
+
<rect fill="#8B8FA3" x="0" y="6" width="5" height="5" rx="1.5"></rect>
|
|
12
|
+
<rect fill="#8B8FA3" x="7" y="12" width="5" height="5" rx="1.5"></rect>
|
|
13
|
+
<rect fill="#8B8FA3" x="0" y="12" width="5" height="5" rx="1.5"></rect>
|
|
14
|
+
<rect fill="#8B8FA3" x="21" y="0" width="5" height="5" rx="1.5"></rect>
|
|
15
|
+
<rect fill="#8B8FA3" x="21" y="6" width="5" height="5" rx="1.5"></rect>
|
|
16
|
+
</g>
|
|
17
|
+
<path d="M3,3 L33,3 C34.6568542,3 36,4.34314575 36,6 L36,12 L36,12 L0,12 L0,6 C-2.02906125e-16,4.34314575 1.34314575,3 3,3 Z" fill="#D7D9E0"></path>
|
|
18
|
+
<rect fill="#D7D9E0" x="7" y="0" width="4" height="8" rx="1"></rect>
|
|
19
|
+
<rect fill="#D7D9E0" x="25" y="0" width="4" height="8" rx="1"></rect>
|
|
20
|
+
</g>
|
|
21
|
+
</g>
|
|
22
|
+
</svg>
|
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
|
@@ -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,442 @@
|
|
|
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 moment from "moment";
|
|
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: moment(item.start, DateParser).format(),
|
|
83
|
+
end: moment(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 = moment(eventInfo.event.end).diff(moment(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
|
+
moment().isAfter(moment(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
|
+
$style={props.style}
|
|
129
|
+
>
|
|
130
|
+
<div className="event-time">{eventInfo.timeText}</div>
|
|
131
|
+
<div className="event-title">{eventInfo.event.title}</div>
|
|
132
|
+
<Remove
|
|
133
|
+
isList={isList}
|
|
134
|
+
className="event-remove"
|
|
135
|
+
onClick={(e) => {
|
|
136
|
+
e.stopPropagation();
|
|
137
|
+
props.onEvent("change");
|
|
138
|
+
const event = events.filter((item: EventType) => item.id !== eventInfo.event.id);
|
|
139
|
+
props.events.onChange(event);
|
|
140
|
+
}}
|
|
141
|
+
onMouseDown={(e) => {
|
|
142
|
+
e.stopPropagation();
|
|
143
|
+
e.preventDefault();
|
|
144
|
+
}}
|
|
145
|
+
>
|
|
146
|
+
<CalendarDeleteIcon />
|
|
147
|
+
</Remove>
|
|
148
|
+
</Event>
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const handleDbClick = () => {
|
|
153
|
+
const event = props.events.value.find(
|
|
154
|
+
(item: EventType) => item.id === editEvent.current?.id
|
|
155
|
+
) as EventType;
|
|
156
|
+
if (!editable || !editEvent.current) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
if (event) {
|
|
160
|
+
const { title, groupId, color, id } = event;
|
|
161
|
+
const eventInfo = {
|
|
162
|
+
title,
|
|
163
|
+
groupId,
|
|
164
|
+
color,
|
|
165
|
+
id,
|
|
166
|
+
};
|
|
167
|
+
showModal(eventInfo, true);
|
|
168
|
+
} else {
|
|
169
|
+
showModal(editEvent.current, false);
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
const handleCreate = (info: DateSelectArg) => {
|
|
174
|
+
const event = {
|
|
175
|
+
allDay: info.allDay,
|
|
176
|
+
start: info.startStr,
|
|
177
|
+
end: info.endStr,
|
|
178
|
+
};
|
|
179
|
+
const view = info.view.type as ViewType;
|
|
180
|
+
const duration = moment(info.end).diff(moment(info.start), "minutes");
|
|
181
|
+
const singleClick =
|
|
182
|
+
(view === ViewType.MONTH && duration === 1440) ||
|
|
183
|
+
([ViewType.WEEK, ViewType.DAY].includes(view) && duration === 30) ||
|
|
184
|
+
(info.allDay && duration === 1440);
|
|
185
|
+
if (singleClick) {
|
|
186
|
+
editEvent.current = event;
|
|
187
|
+
setTimeout(() => {
|
|
188
|
+
editEvent.current = undefined;
|
|
189
|
+
}, 500);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
showModal(event, false);
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
const showModal = (event: EventType, ifEdit: boolean) => {
|
|
196
|
+
const modalTitle = ifEdit ? trans("calendar.editEvent") : trans("calendar.creatEvent");
|
|
197
|
+
form && form.setFieldsValue(event);
|
|
198
|
+
const eventId = editEvent.current?.id;
|
|
199
|
+
CustomModal.confirm({
|
|
200
|
+
title: modalTitle,
|
|
201
|
+
content: (
|
|
202
|
+
<FormWrapper form={form}>
|
|
203
|
+
<Form.Item
|
|
204
|
+
label={
|
|
205
|
+
<Tooltip title={trans("calendar.eventIdTooltip")}>
|
|
206
|
+
{trans("calendar.eventId")}
|
|
207
|
+
</Tooltip>
|
|
208
|
+
}
|
|
209
|
+
name="id"
|
|
210
|
+
rules={[{ required: true, message: trans("calendar.eventIdRequire") }]}
|
|
211
|
+
>
|
|
212
|
+
<Input />
|
|
213
|
+
</Form.Item>
|
|
214
|
+
<Form.Item
|
|
215
|
+
label={trans("calendar.eventName")}
|
|
216
|
+
name="title"
|
|
217
|
+
rules={[{ required: true, message: trans("calendar.eventNameRequire") }]}
|
|
218
|
+
>
|
|
219
|
+
<Input />
|
|
220
|
+
</Form.Item>
|
|
221
|
+
<Form.Item label={trans("calendar.eventColor")} name="color">
|
|
222
|
+
<Input />
|
|
223
|
+
</Form.Item>
|
|
224
|
+
<Form.Item
|
|
225
|
+
label={
|
|
226
|
+
<Tooltip title={trans("calendar.groupIdTooltip")}>
|
|
227
|
+
{trans("calendar.eventGroupId")}
|
|
228
|
+
</Tooltip>
|
|
229
|
+
}
|
|
230
|
+
name="groupId"
|
|
231
|
+
>
|
|
232
|
+
<Input />
|
|
233
|
+
</Form.Item>
|
|
234
|
+
</FormWrapper>
|
|
235
|
+
),
|
|
236
|
+
onConfirm: () => {
|
|
237
|
+
form.submit();
|
|
238
|
+
return form.validateFields().then(() => {
|
|
239
|
+
const { id, groupId, color, title = "" } = form.getFieldsValue();
|
|
240
|
+
const idExist = props.events.value.findIndex((item: EventType) => item.id === id);
|
|
241
|
+
if (idExist > -1 && id !== eventId) {
|
|
242
|
+
form.setFields([{ name: "id", errors: [trans("calendar.eventIdExist")] }]);
|
|
243
|
+
throw new Error();
|
|
244
|
+
}
|
|
245
|
+
if (ifEdit) {
|
|
246
|
+
const changeEvents = props.events.value.map((item: EventType) => {
|
|
247
|
+
if (item.id === eventId) {
|
|
248
|
+
return {
|
|
249
|
+
...item,
|
|
250
|
+
title,
|
|
251
|
+
id,
|
|
252
|
+
...(groupId !== undefined ? { groupId } : null),
|
|
253
|
+
...(color !== undefined ? { color } : null),
|
|
254
|
+
};
|
|
255
|
+
} else {
|
|
256
|
+
return item;
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
props.events.onChange(changeEvents);
|
|
260
|
+
} else {
|
|
261
|
+
const createInfo = {
|
|
262
|
+
allDay: event.allDay,
|
|
263
|
+
start: event.start,
|
|
264
|
+
end: event.end,
|
|
265
|
+
id,
|
|
266
|
+
title,
|
|
267
|
+
...(groupId !== undefined ? { groupId } : null),
|
|
268
|
+
...(color !== undefined ? { color } : null),
|
|
269
|
+
};
|
|
270
|
+
props.events.onChange([...props.events.value, createInfo]);
|
|
271
|
+
}
|
|
272
|
+
props.onEvent("change");
|
|
273
|
+
form.resetFields();
|
|
274
|
+
});
|
|
275
|
+
},
|
|
276
|
+
onCancel: () => {
|
|
277
|
+
form.resetFields();
|
|
278
|
+
},
|
|
279
|
+
});
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
let initialDate = defaultDate;
|
|
283
|
+
try {
|
|
284
|
+
initialDate = new Date(defaultDate).toISOString();
|
|
285
|
+
} catch (error) {
|
|
286
|
+
initialDate = undefined;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
return (
|
|
290
|
+
<Wrapper
|
|
291
|
+
ref={ref}
|
|
292
|
+
editable={editable}
|
|
293
|
+
$style={style}
|
|
294
|
+
theme={theme?.theme}
|
|
295
|
+
onDoubleClick={handleDbClick}
|
|
296
|
+
left={left}
|
|
297
|
+
key={initialDate ? defaultView + initialDate : defaultView}
|
|
298
|
+
>
|
|
299
|
+
<FullCalendar
|
|
300
|
+
slotEventOverlap={false}
|
|
301
|
+
events={events}
|
|
302
|
+
expandRows={true}
|
|
303
|
+
height={"100%"}
|
|
304
|
+
locale={getCalendarLocale()}
|
|
305
|
+
locales={allLocales}
|
|
306
|
+
firstDay={Number(firstDay)}
|
|
307
|
+
plugins={[dayGridPlugin, timeGridPlugin, interactionPlugin, listPlugin, momentPlugin]}
|
|
308
|
+
headerToolbar={headerToolbar}
|
|
309
|
+
moreLinkClick={(info) => {
|
|
310
|
+
let left = 0;
|
|
311
|
+
const ele = info.jsEvent.target as HTMLElement;
|
|
312
|
+
if (info.view.type === ViewType.DAY) {
|
|
313
|
+
if (info.allDay) {
|
|
314
|
+
left = ele.offsetParent?.parentElement?.offsetLeft || 0;
|
|
315
|
+
} else {
|
|
316
|
+
left = ele.parentElement?.offsetLeft || 0;
|
|
317
|
+
}
|
|
318
|
+
} else {
|
|
319
|
+
if (info.allDay) {
|
|
320
|
+
left = ele.offsetParent?.parentElement?.parentElement?.offsetLeft || 0;
|
|
321
|
+
} else {
|
|
322
|
+
left =
|
|
323
|
+
ele.offsetParent?.parentElement?.parentElement?.parentElement?.offsetLeft || 0;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
setLeft(left);
|
|
327
|
+
}}
|
|
328
|
+
buttonText={buttonText}
|
|
329
|
+
views={views}
|
|
330
|
+
eventClassNames={() => (!showEventTime ? "no-time" : "")}
|
|
331
|
+
slotLabelFormat={slotLabelFormat}
|
|
332
|
+
viewClassNames={viewClassNames}
|
|
333
|
+
moreLinkText={trans("calendar.more")}
|
|
334
|
+
initialDate={initialDate}
|
|
335
|
+
initialView={defaultView}
|
|
336
|
+
editable={editable}
|
|
337
|
+
selectable={editable}
|
|
338
|
+
selectMirror={false}
|
|
339
|
+
displayEventTime={showEventTime}
|
|
340
|
+
dayMaxEvents={dayMaxEvents}
|
|
341
|
+
eventMaxStack={eventMaxStack || undefined}
|
|
342
|
+
weekends={showWeekends}
|
|
343
|
+
allDaySlot={showAllDay}
|
|
344
|
+
eventContent={renderEventContent}
|
|
345
|
+
select={(info) => handleCreate(info)}
|
|
346
|
+
eventClick={(info) => {
|
|
347
|
+
const event = events.find((item: EventType) => item.id === info.event.id);
|
|
348
|
+
editEvent.current = event;
|
|
349
|
+
setTimeout(() => {
|
|
350
|
+
editEvent.current = undefined;
|
|
351
|
+
}, 500);
|
|
352
|
+
}}
|
|
353
|
+
eventsSet={(info) => {
|
|
354
|
+
let needChange = false;
|
|
355
|
+
let changeEvents: EventType[] = [];
|
|
356
|
+
info.forEach((item) => {
|
|
357
|
+
const event = events.find((i: EventType) => i.id === item.id);
|
|
358
|
+
const start = moment(item.start, DateParser).format();
|
|
359
|
+
const end = moment(item.end, DateParser).format();
|
|
360
|
+
if (
|
|
361
|
+
start !== event?.start ||
|
|
362
|
+
end !== event?.end ||
|
|
363
|
+
!!item.allDay !== !!event?.allDay
|
|
364
|
+
) {
|
|
365
|
+
needChange = true;
|
|
366
|
+
changeEvents.push({
|
|
367
|
+
...event,
|
|
368
|
+
allDay: item.allDay,
|
|
369
|
+
start: item.startStr,
|
|
370
|
+
end: item.endStr,
|
|
371
|
+
});
|
|
372
|
+
} else {
|
|
373
|
+
changeEvents.push(event);
|
|
374
|
+
}
|
|
375
|
+
});
|
|
376
|
+
if (needChange) {
|
|
377
|
+
props.events.onChange(changeEvents);
|
|
378
|
+
props.onEvent("change");
|
|
379
|
+
}
|
|
380
|
+
}}
|
|
381
|
+
/>
|
|
382
|
+
</Wrapper>
|
|
383
|
+
);
|
|
384
|
+
})
|
|
385
|
+
.setPropertyViewFn((children) => {
|
|
386
|
+
return (
|
|
387
|
+
<>
|
|
388
|
+
<Section name={sectionNames.basic}>{children.events.propertyView({})}</Section>
|
|
389
|
+
<Section name={sectionNames.interaction}>{children.onEvent.getPropertyView()}</Section>
|
|
390
|
+
<Section name={sectionNames.advanced}>
|
|
391
|
+
{children.editable.propertyView({
|
|
392
|
+
label: trans("calendar.editable"),
|
|
393
|
+
})}
|
|
394
|
+
{children.defaultDate.propertyView({
|
|
395
|
+
label: trans("calendar.defaultDate"),
|
|
396
|
+
tooltip: trans("calendar.defaultDateTooltip"),
|
|
397
|
+
})}
|
|
398
|
+
{children.defaultView.propertyView({
|
|
399
|
+
label: trans("calendar.defaultView"),
|
|
400
|
+
tooltip: trans("calendar.defaultViewTooltip"),
|
|
401
|
+
})}
|
|
402
|
+
{children.firstDay.propertyView({
|
|
403
|
+
label: trans("calendar.startWeek"),
|
|
404
|
+
})}
|
|
405
|
+
{children.showEventTime.propertyView({
|
|
406
|
+
label: trans("calendar.showEventTime"),
|
|
407
|
+
tooltip: trans("calendar.showEventTimeTooltip"),
|
|
408
|
+
})}
|
|
409
|
+
{children.showWeekends.propertyView({
|
|
410
|
+
label: trans("calendar.showWeekends"),
|
|
411
|
+
})}
|
|
412
|
+
{children.showAllDay.propertyView({
|
|
413
|
+
label: trans("calendar.showAllDay"),
|
|
414
|
+
tooltip: trans("calendar.showAllDayTooltip"),
|
|
415
|
+
})}
|
|
416
|
+
{children.dayMaxEvents.propertyView({
|
|
417
|
+
label: trans("calendar.dayMaxEvents"),
|
|
418
|
+
tooltip: trans("calendar.dayMaxEventsTooltip"),
|
|
419
|
+
})}
|
|
420
|
+
{children.eventMaxStack.propertyView({
|
|
421
|
+
label: trans("calendar.eventMaxStack"),
|
|
422
|
+
tooltip: trans("calendar.eventMaxStackTooltip"),
|
|
423
|
+
})}
|
|
424
|
+
</Section>
|
|
425
|
+
<Section name={sectionNames.layout}>{hiddenPropertyView(children)}</Section>
|
|
426
|
+
<Section name={sectionNames.style}>{children.style.getPropertyView()}</Section>
|
|
427
|
+
</>
|
|
428
|
+
);
|
|
429
|
+
})
|
|
430
|
+
.build();
|
|
431
|
+
})();
|
|
432
|
+
|
|
433
|
+
CalendarBasicComp = class extends CalendarBasicComp {
|
|
434
|
+
override autoHeight(): boolean {
|
|
435
|
+
return false;
|
|
436
|
+
}
|
|
437
|
+
};
|
|
438
|
+
|
|
439
|
+
export const CalendarComp = withExposingConfigs(CalendarBasicComp, [
|
|
440
|
+
new NameConfig("events", trans("calendar.events")),
|
|
441
|
+
NameConfigHidden,
|
|
442
|
+
]);
|