@jsb188/schedule 1.1.11 → 1.1.12
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/package.json +6 -5
- package/src/modules/Gantt.helpers.ts +11 -30
- package/src/modules/Gantt.tsx +46 -181
- package/src/ui/ProjectFormUI.tsx +8 -31
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsb188/schedule",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.12",
|
|
4
4
|
"description": "Scheduling engines and contracts shared by the server and clients: working-time calendars, critical path scheduling, recurrence, and coverage rules.",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "jsb188",
|
|
@@ -48,11 +48,12 @@
|
|
|
48
48
|
"luxon": "^3.7.2"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"@jsb188/app": "1.1.
|
|
52
|
-
"@jsb188/react-web": "1.1.
|
|
53
|
-
"react": "^19.
|
|
51
|
+
"@jsb188/app": "1.1.12",
|
|
52
|
+
"@jsb188/react-web": "1.1.12",
|
|
53
|
+
"react": "^19.3.0",
|
|
54
54
|
"jotai": "^2.13.1",
|
|
55
|
-
"@jsb188/sheet": "1.1.
|
|
55
|
+
"@jsb188/sheet": "1.1.12",
|
|
56
|
+
"@jsb188/form": "1.1.12"
|
|
56
57
|
},
|
|
57
58
|
"scripts": {
|
|
58
59
|
"test": "vitest run --config ./vitest.config.ts --passWithNoTests",
|
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import { createGridEdgeAutoScroller } from '@jsb188/sheet/libs/grid-touch';
|
|
2
|
-
import {
|
|
3
|
-
getGanttDate,
|
|
4
|
-
GANTT_ROW_HEIGHT,
|
|
5
|
-
type GanttBarObj,
|
|
6
|
-
type GanttRowObj,
|
|
7
|
-
type GanttScaleObj,
|
|
8
|
-
} from '../libs/gantt-geometry.ts';
|
|
2
|
+
import { getGanttDate, GANTT_ROW_HEIGHT, type GanttBarObj, type GanttRowObj, type GanttScaleObj } from '../libs/gantt-geometry.ts';
|
|
9
3
|
import type { ScheduleRelationshipTypeEnum } from '../types/schedule.d.ts';
|
|
10
4
|
|
|
11
5
|
export interface GanttMoveIntent {
|
|
@@ -16,6 +10,7 @@ export interface GanttMoveIntent {
|
|
|
16
10
|
|
|
17
11
|
/* Track one pointer gesture with edge scrolling; commit only an intentional completed move or link. */
|
|
18
12
|
export function startGanttPointerInteraction(p: {
|
|
13
|
+
isKeyboardLayerActive: (event: KeyboardEvent) => boolean;
|
|
19
14
|
event: React.PointerEvent<HTMLDivElement>;
|
|
20
15
|
row: GanttRowObj;
|
|
21
16
|
bar: GanttBarObj;
|
|
@@ -24,16 +19,10 @@ export function startGanttPointerInteraction(p: {
|
|
|
24
19
|
scale: GanttScaleObj;
|
|
25
20
|
tableWidth: number;
|
|
26
21
|
onMove?: (row: GanttRowObj, intent: GanttMoveIntent) => void;
|
|
27
|
-
onLink?: (
|
|
28
|
-
predecessorId: string,
|
|
29
|
-
successorId: string,
|
|
30
|
-
type: ScheduleRelationshipTypeEnum,
|
|
31
|
-
) => void;
|
|
22
|
+
onLink?: (predecessorId: string, successorId: string, type: ScheduleRelationshipTypeEnum) => void;
|
|
32
23
|
}): () => void {
|
|
33
24
|
p.event.preventDefault();
|
|
34
|
-
const element =
|
|
35
|
-
p.event.currentTarget.closest<HTMLElement>('[data-gantt-activity]') ||
|
|
36
|
-
p.event.currentTarget;
|
|
25
|
+
const element = p.event.currentTarget.closest<HTMLElement>('[data-gantt-activity]') || p.event.currentTarget;
|
|
37
26
|
const initialX = p.event.clientX;
|
|
38
27
|
const initialScroll = p.body.scrollLeft;
|
|
39
28
|
let clientX = initialX;
|
|
@@ -47,10 +36,7 @@ export function startGanttPointerInteraction(p: {
|
|
|
47
36
|
};
|
|
48
37
|
const link = p.kind.startsWith('LINK');
|
|
49
38
|
const svg = p.body.querySelector('svg');
|
|
50
|
-
const preview =
|
|
51
|
-
link && svg
|
|
52
|
-
? document.createElementNS('http://www.w3.org/2000/svg', 'path')
|
|
53
|
-
: null;
|
|
39
|
+
const preview = link && svg ? document.createElementNS('http://www.w3.org/2000/svg', 'path') : null;
|
|
54
40
|
if (preview) {
|
|
55
41
|
preview.setAttribute('stroke', 'currentColor');
|
|
56
42
|
preview.setAttribute('fill', 'none');
|
|
@@ -69,13 +55,11 @@ export function startGanttPointerInteraction(p: {
|
|
|
69
55
|
const x2 = x - bounds.left + p.body.scrollLeft - p.tableWidth;
|
|
70
56
|
const y2 = y - bounds.top + p.body.scrollTop;
|
|
71
57
|
preview.setAttribute('d', `M ${x1} ${y1} L ${x2} ${y2}`);
|
|
72
|
-
} else if (p.kind === 'MOVE')
|
|
73
|
-
element.style.transform = `${original.transform} translateX(${distance}px)`;
|
|
58
|
+
} else if (p.kind === 'MOVE') element.style.transform = `${original.transform} translateX(${distance}px)`;
|
|
74
59
|
else if (p.kind === 'RESIZE_START') {
|
|
75
60
|
element.style.left = `${p.bar.x + Math.min(distance, p.bar.width - 2)}px`;
|
|
76
61
|
element.style.width = `${Math.max(2, p.bar.width - distance)}px`;
|
|
77
|
-
} else if (p.kind === 'RESIZE_FINISH')
|
|
78
|
-
element.style.width = `${Math.max(2, p.bar.width + distance)}px`;
|
|
62
|
+
} else if (p.kind === 'RESIZE_FINISH') element.style.width = `${Math.max(2, p.bar.width + distance)}px`;
|
|
79
63
|
};
|
|
80
64
|
const scroller = createGridEdgeAutoScroller({
|
|
81
65
|
getScrollNode: () => p.body,
|
|
@@ -102,20 +86,16 @@ export function startGanttPointerInteraction(p: {
|
|
|
102
86
|
const up = (event: PointerEvent) => {
|
|
103
87
|
const deltaDays = Math.round(distance / p.scale.dayWidth);
|
|
104
88
|
const target = link
|
|
105
|
-
? document
|
|
106
|
-
.elementFromPoint(event.clientX, event.clientY)
|
|
107
|
-
?.closest<HTMLElement>('[data-gantt-activity]')
|
|
89
|
+
? document.elementFromPoint(event.clientX, event.clientY)?.closest<HTMLElement>('[data-gantt-activity]')
|
|
108
90
|
: null;
|
|
109
91
|
cleanup();
|
|
110
92
|
if (link && target && target.dataset.ganttActivity !== p.row.id) {
|
|
111
93
|
const bounds = target.getBoundingClientRect();
|
|
112
94
|
const toFinish = event.clientX >= bounds.left + bounds.width / 2;
|
|
113
|
-
const type =
|
|
114
|
-
`${p.kind === 'LINK_START' ? 'S' : 'F'}${toFinish ? 'F' : 'S'}` as ScheduleRelationshipTypeEnum;
|
|
95
|
+
const type = `${p.kind === 'LINK_START' ? 'S' : 'F'}${toFinish ? 'F' : 'S'}` as ScheduleRelationshipTypeEnum;
|
|
115
96
|
p.onLink?.(p.row.id, target.dataset.ganttActivity!, type);
|
|
116
97
|
} else if (!link && Math.abs(distance) >= 3 && deltaDays) {
|
|
117
|
-
const endpoint =
|
|
118
|
-
p.kind === 'RESIZE_FINISH' ? p.bar.x + p.bar.width : p.bar.x;
|
|
98
|
+
const endpoint = p.kind === 'RESIZE_FINISH' ? p.bar.x + p.bar.width : p.bar.x;
|
|
119
99
|
p.onMove?.(p.row, {
|
|
120
100
|
kind: p.kind as GanttMoveIntent['kind'],
|
|
121
101
|
date: getGanttDate(p.scale, endpoint + deltaDays * p.scale.dayWidth),
|
|
@@ -127,6 +107,7 @@ export function startGanttPointerInteraction(p: {
|
|
|
127
107
|
const cancel = () => cleanup();
|
|
128
108
|
/* Escape always cancels the current gesture. */
|
|
129
109
|
const key = (event: KeyboardEvent) => {
|
|
110
|
+
if (!p.isKeyboardLayerActive(event)) return;
|
|
130
111
|
if (event.key === 'Escape') cleanup();
|
|
131
112
|
};
|
|
132
113
|
window.addEventListener('pointermove', move);
|
package/src/modules/Gantt.tsx
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
|
+
import { useIsKeyboardLayerActive } from '@jsb188/react/states/keyboardLayer';
|
|
1
2
|
import { cn } from '@jsb188/app/utils/string.ts';
|
|
2
3
|
import { useStore } from 'jotai';
|
|
3
4
|
import { DateTime } from 'luxon';
|
|
4
|
-
import {
|
|
5
|
-
memo,
|
|
6
|
-
useCallback,
|
|
7
|
-
useEffect,
|
|
8
|
-
useMemo,
|
|
9
|
-
useRef,
|
|
10
|
-
useState,
|
|
11
|
-
type ReactNode,
|
|
12
|
-
} from 'react';
|
|
5
|
+
import { memo, useCallback, useEffect, useMemo, useRef, useState, type ReactNode } from 'react';
|
|
13
6
|
import {
|
|
14
7
|
getGanttNonWorkingColumns,
|
|
15
8
|
buildGanttBars,
|
|
@@ -29,10 +22,7 @@ import {
|
|
|
29
22
|
type GanttZoomEnum,
|
|
30
23
|
type GanttScaleObj,
|
|
31
24
|
} from '../libs/gantt-geometry.ts';
|
|
32
|
-
import {
|
|
33
|
-
createGanttSelectionAtom,
|
|
34
|
-
getGanttSelection,
|
|
35
|
-
} from '../libs/gantt-state.ts';
|
|
25
|
+
import { createGanttSelectionAtom, getGanttSelection } from '../libs/gantt-state.ts';
|
|
36
26
|
import {
|
|
37
27
|
GanttHeaderUI,
|
|
38
28
|
GanttTableHeaderUI,
|
|
@@ -42,16 +32,10 @@ import {
|
|
|
42
32
|
type GanttTableUIProps,
|
|
43
33
|
type GanttTimelineUIProps,
|
|
44
34
|
} from '../ui/GanttUI.tsx';
|
|
45
|
-
import {
|
|
46
|
-
startGanttPointerInteraction,
|
|
47
|
-
type GanttMoveIntent,
|
|
48
|
-
} from './Gantt.helpers.ts';
|
|
35
|
+
import { startGanttPointerInteraction, type GanttMoveIntent } from './Gantt.helpers.ts';
|
|
49
36
|
import { getWorkCalendarTable } from '../utils/workTime.ts';
|
|
50
37
|
import { handleGanttKeyboardEvent } from '../libs/gantt-keyboard.ts';
|
|
51
|
-
import type {
|
|
52
|
-
ScheduleWorkCalendarDef,
|
|
53
|
-
ScheduleRelationshipTypeEnum,
|
|
54
|
-
} from '../types/schedule.d.ts';
|
|
38
|
+
import type { ScheduleWorkCalendarDef, ScheduleRelationshipTypeEnum } from '../types/schedule.d.ts';
|
|
55
39
|
|
|
56
40
|
export interface GanttProps {
|
|
57
41
|
workCalendar?: ScheduleWorkCalendarDef;
|
|
@@ -62,12 +46,7 @@ export interface GanttProps {
|
|
|
62
46
|
onZoomChange?: (zoom: GanttZoomEnum) => void;
|
|
63
47
|
onFocusSearch?: () => void;
|
|
64
48
|
scrollLeft?: number;
|
|
65
|
-
onViewportChange?: (viewport: {
|
|
66
|
-
scale: GanttScaleObj;
|
|
67
|
-
scrollLeft: number;
|
|
68
|
-
width: number;
|
|
69
|
-
tableWidth: number;
|
|
70
|
-
}) => void;
|
|
49
|
+
onViewportChange?: (viewport: { scale: GanttScaleObj; scrollLeft: number; width: number; tableWidth: number }) => void;
|
|
71
50
|
className?: string;
|
|
72
51
|
wbsNodes: GanttWbsInput[];
|
|
73
52
|
activities: GanttActivityInput[];
|
|
@@ -96,11 +75,7 @@ export interface GanttProps {
|
|
|
96
75
|
renderCell?: GanttTableUIProps['renderCell'];
|
|
97
76
|
onMoveRows?: GanttTableUIProps['onMoveRows'];
|
|
98
77
|
onMoveActivity?: (row: GanttRowObj, intent: GanttMoveIntent) => void;
|
|
99
|
-
onCreateRelationship?: (
|
|
100
|
-
predecessorId: string,
|
|
101
|
-
successorId: string,
|
|
102
|
-
type: ScheduleRelationshipTypeEnum,
|
|
103
|
-
) => void;
|
|
78
|
+
onCreateRelationship?: (predecessorId: string, successorId: string, type: ScheduleRelationshipTypeEnum) => void;
|
|
104
79
|
}
|
|
105
80
|
|
|
106
81
|
const FILE_CONSTANTS = {
|
|
@@ -117,13 +92,12 @@ const FILE_CONSTANTS = {
|
|
|
117
92
|
|
|
118
93
|
/* Coordinate geometry, virtualized panes and user intent while the page owns all server mutations. */
|
|
119
94
|
export const Gantt = memo((p: GanttProps) => {
|
|
95
|
+
const isKeyboardLayerActive = useIsKeyboardLayerActive();
|
|
120
96
|
const store = useStore();
|
|
121
97
|
const selection = useMemo(createGanttSelectionAtom, []);
|
|
122
98
|
const [columnWidths, setColumnWidths] = useState<Record<string, number>>({});
|
|
123
99
|
const activeCell = useRef({ rowIndex: 0, columnIndex: 1 });
|
|
124
|
-
const pendingFocus = useRef<{ rowId: string; columnKey: string } | null>(
|
|
125
|
-
null,
|
|
126
|
-
);
|
|
100
|
+
const pendingFocus = useRef<{ rowId: string; columnKey: string } | null>(null);
|
|
127
101
|
const initialSelection = useRef<string | null>(null);
|
|
128
102
|
const cleanupResize = useRef<(() => void) | null>(null);
|
|
129
103
|
const [collapsed, setCollapsed] = useState(() => new Set<string>());
|
|
@@ -156,22 +130,10 @@ export const Gantt = memo((p: GanttProps) => {
|
|
|
156
130
|
})),
|
|
157
131
|
[p.columns, p.columnLabels, columnWidths],
|
|
158
132
|
);
|
|
159
|
-
const columnsWidth = useMemo(
|
|
160
|
-
|
|
161
|
-
[columns],
|
|
162
|
-
);
|
|
163
|
-
const tableWidth = Math.min(
|
|
164
|
-
columnsWidth,
|
|
165
|
-
Math.max(240, Math.floor(viewport.width * 0.6)),
|
|
166
|
-
);
|
|
133
|
+
const columnsWidth = useMemo(() => columns.reduce((sum, column) => sum + column.width, 0), [columns]);
|
|
134
|
+
const tableWidth = Math.min(columnsWidth, Math.max(240, Math.floor(viewport.width * 0.6)));
|
|
167
135
|
const rows = useMemo(
|
|
168
|
-
() =>
|
|
169
|
-
buildGanttRows(
|
|
170
|
-
p.wbsNodes,
|
|
171
|
-
p.activities,
|
|
172
|
-
p.baselineActivities || [],
|
|
173
|
-
collapsed,
|
|
174
|
-
),
|
|
136
|
+
() => buildGanttRows(p.wbsNodes, p.activities, p.baselineActivities || [], collapsed),
|
|
175
137
|
[p.wbsNodes, p.activities, p.baselineActivities, collapsed],
|
|
176
138
|
);
|
|
177
139
|
const scale = useMemo(
|
|
@@ -179,47 +141,19 @@ export const Gantt = memo((p: GanttProps) => {
|
|
|
179
141
|
[rows, p.now, p.timeZone, p.zoom, p.formatters],
|
|
180
142
|
);
|
|
181
143
|
const nonWorkingColumns = useMemo(
|
|
182
|
-
() =>
|
|
183
|
-
p.workCalendar
|
|
184
|
-
? getGanttNonWorkingColumns(
|
|
185
|
-
scale,
|
|
186
|
-
getWorkCalendarTable(p.workCalendar, scale.startAt, scale.endAt),
|
|
187
|
-
)
|
|
188
|
-
: [],
|
|
144
|
+
() => (p.workCalendar ? getGanttNonWorkingColumns(scale, getWorkCalendarTable(p.workCalendar, scale.startAt, scale.endAt)) : []),
|
|
189
145
|
[scale, p.workCalendar],
|
|
190
146
|
);
|
|
191
147
|
const bars = useMemo(() => buildGanttBars(rows, scale), [rows, scale]);
|
|
192
|
-
const links = useMemo(
|
|
193
|
-
|
|
194
|
-
[rows, bars, p.relationships],
|
|
195
|
-
);
|
|
196
|
-
const range = getGanttVisibleRange(
|
|
197
|
-
viewport.top,
|
|
198
|
-
viewport.height,
|
|
199
|
-
rows.length,
|
|
200
|
-
);
|
|
148
|
+
const links = useMemo(() => buildGanttLinks(rows, bars, p.relationships), [rows, bars, p.relationships]);
|
|
149
|
+
const range = getGanttVisibleRange(viewport.top, viewport.height, rows.length);
|
|
201
150
|
const visibleRowTexts = useMemo(
|
|
202
151
|
() =>
|
|
203
152
|
rows.slice(range.start, range.end).map((row) => ({
|
|
204
|
-
duration:
|
|
205
|
-
row.kind === 'WBS'
|
|
206
|
-
? ''
|
|
207
|
-
: (p.formatters?.duration || formatGanttDays)(
|
|
208
|
-
row.durationMinutes,
|
|
209
|
-
p.minutesPerDay,
|
|
210
|
-
),
|
|
153
|
+
duration: row.kind === 'WBS' ? '' : (p.formatters?.duration || formatGanttDays)(row.durationMinutes, p.minutesPerDay),
|
|
211
154
|
start: (p.formatters?.date || formatGanttDate)(row.startAt, p.timeZone),
|
|
212
|
-
finish: (p.formatters?.date || formatGanttDate)(
|
|
213
|
-
|
|
214
|
-
p.timeZone,
|
|
215
|
-
),
|
|
216
|
-
float:
|
|
217
|
-
row.kind === 'WBS'
|
|
218
|
-
? ''
|
|
219
|
-
: (p.formatters?.duration || formatGanttDays)(
|
|
220
|
-
row.totalFloatMinutes,
|
|
221
|
-
p.minutesPerDay,
|
|
222
|
-
),
|
|
155
|
+
finish: (p.formatters?.date || formatGanttDate)(row.finishAt, p.timeZone),
|
|
156
|
+
float: row.kind === 'WBS' ? '' : (p.formatters?.duration || formatGanttDays)(row.totalFloatMinutes, p.minutesPerDay),
|
|
223
157
|
values: {
|
|
224
158
|
duration: String(row.durationMinutes / p.minutesPerDay),
|
|
225
159
|
start: row.startAt
|
|
@@ -239,9 +173,7 @@ export const Gantt = memo((p: GanttProps) => {
|
|
|
239
173
|
const todayX = useMemo(() => getGanttX(scale, p.now), [scale, p.now]);
|
|
240
174
|
const dataDateX = useMemo(() => {
|
|
241
175
|
const value = p.dataDateAt ? new Date(p.dataDateAt) : null;
|
|
242
|
-
return value && Number.isFinite(value.getTime())
|
|
243
|
-
? getGanttX(scale, value)
|
|
244
|
-
: null;
|
|
176
|
+
return value && Number.isFinite(value.getTime()) ? getGanttX(scale, value) : null;
|
|
245
177
|
}, [scale, p.dataDateAt]);
|
|
246
178
|
|
|
247
179
|
/* Measure the scroll window at most once per animation frame. */
|
|
@@ -259,20 +191,14 @@ export const Gantt = memo((p: GanttProps) => {
|
|
|
259
191
|
height: body.clientHeight,
|
|
260
192
|
width: body.clientWidth,
|
|
261
193
|
};
|
|
262
|
-
return current.top === next.top &&
|
|
263
|
-
current.left === next.left &&
|
|
264
|
-
current.height === next.height &&
|
|
265
|
-
current.width === next.width
|
|
194
|
+
return current.top === next.top && current.left === next.left && current.height === next.height && current.width === next.width
|
|
266
195
|
? current
|
|
267
196
|
: next;
|
|
268
197
|
});
|
|
269
198
|
});
|
|
270
199
|
}, []);
|
|
271
200
|
useEffect(() => {
|
|
272
|
-
const observer =
|
|
273
|
-
typeof ResizeObserver === 'undefined'
|
|
274
|
-
? null
|
|
275
|
-
: new ResizeObserver(measure);
|
|
201
|
+
const observer = typeof ResizeObserver === 'undefined' ? null : new ResizeObserver(measure);
|
|
276
202
|
if (bodyRef.current) observer?.observe(bodyRef.current);
|
|
277
203
|
measure();
|
|
278
204
|
return () => {
|
|
@@ -283,24 +209,19 @@ export const Gantt = memo((p: GanttProps) => {
|
|
|
283
209
|
};
|
|
284
210
|
}, [measure, rows.length === 0]);
|
|
285
211
|
useEffect(() => {
|
|
286
|
-
if (p.selectedRowId && !store.get(selection).has(p.selectedRowId))
|
|
287
|
-
store.set(selection, new Set([p.selectedRowId]));
|
|
212
|
+
if (p.selectedRowId && !store.get(selection).has(p.selectedRowId)) store.set(selection, new Set([p.selectedRowId]));
|
|
288
213
|
}, [p.selectedRowId, selection, store]);
|
|
289
214
|
useEffect(() => {
|
|
290
215
|
const body = bodyRef.current;
|
|
291
216
|
if (body) {
|
|
292
|
-
body.scrollLeft = Math.max(
|
|
293
|
-
0,
|
|
294
|
-
(dataDateX ?? todayX) - FILE_CONSTANTS.scrollLeadPx,
|
|
295
|
-
);
|
|
217
|
+
body.scrollLeft = Math.max(0, (dataDateX ?? todayX) - FILE_CONSTANTS.scrollLeadPx);
|
|
296
218
|
measure();
|
|
297
219
|
}
|
|
298
220
|
}, [p.zoom]);
|
|
299
221
|
|
|
300
222
|
/* Keep wide table columns scrollable without consuming the timeline's viewport. */
|
|
301
223
|
const syncTableScroll = useCallback(() => {
|
|
302
|
-
if (tableBodyRef.current && tableHeaderRef.current)
|
|
303
|
-
tableBodyRef.current.scrollLeft = tableHeaderRef.current.scrollLeft;
|
|
224
|
+
if (tableBodyRef.current && tableHeaderRef.current) tableBodyRef.current.scrollLeft = tableHeaderRef.current.scrollLeft;
|
|
304
225
|
}, []);
|
|
305
226
|
useEffect(() => {
|
|
306
227
|
const table = tableBodyRef.current;
|
|
@@ -314,9 +235,7 @@ export const Gantt = memo((p: GanttProps) => {
|
|
|
314
235
|
return;
|
|
315
236
|
event.preventDefault();
|
|
316
237
|
event.stopPropagation();
|
|
317
|
-
tableHeaderRef.current.scrollLeft += event.shiftKey
|
|
318
|
-
? event.deltaY || event.deltaX
|
|
319
|
-
: event.deltaX;
|
|
238
|
+
tableHeaderRef.current.scrollLeft += event.shiftKey ? event.deltaY || event.deltaX : event.deltaX;
|
|
320
239
|
syncTableScroll();
|
|
321
240
|
};
|
|
322
241
|
table?.addEventListener('wheel', wheel, { passive: false });
|
|
@@ -331,15 +250,9 @@ export const Gantt = memo((p: GanttProps) => {
|
|
|
331
250
|
const body = bodyRef.current;
|
|
332
251
|
if (!row || !column || !body) return;
|
|
333
252
|
if (tableHeaderRef.current) {
|
|
334
|
-
const left = columns
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
if (left < tableHeaderRef.current.scrollLeft)
|
|
338
|
-
tableHeaderRef.current.scrollLeft = left;
|
|
339
|
-
else if (
|
|
340
|
-
left + column.width >
|
|
341
|
-
tableHeaderRef.current.scrollLeft + tableWidth
|
|
342
|
-
)
|
|
253
|
+
const left = columns.slice(0, columnIndex).reduce((sum, item) => sum + item.width, 0);
|
|
254
|
+
if (left < tableHeaderRef.current.scrollLeft) tableHeaderRef.current.scrollLeft = left;
|
|
255
|
+
else if (left + column.width > tableHeaderRef.current.scrollLeft + tableWidth)
|
|
343
256
|
tableHeaderRef.current.scrollLeft = left + column.width - tableWidth;
|
|
344
257
|
syncTableScroll();
|
|
345
258
|
}
|
|
@@ -348,10 +261,7 @@ export const Gantt = memo((p: GanttProps) => {
|
|
|
348
261
|
const top = rowIndex * GANTT_ROW_HEIGHT;
|
|
349
262
|
if (top < body.scrollTop) body.scrollTop = top;
|
|
350
263
|
else if (top + GANTT_ROW_HEIGHT > body.scrollTop + body.clientHeight)
|
|
351
|
-
body.scrollTop = Math.max(
|
|
352
|
-
0,
|
|
353
|
-
top + GANTT_ROW_HEIGHT - body.clientHeight,
|
|
354
|
-
);
|
|
264
|
+
body.scrollTop = Math.max(0, top + GANTT_ROW_HEIGHT - body.clientHeight);
|
|
355
265
|
const mounted = body.querySelector<HTMLElement>(
|
|
356
266
|
`[data-gantt-row="${CSS.escape(row.id)}"] [data-gantt-column="${CSS.escape(column.key)}"]`,
|
|
357
267
|
);
|
|
@@ -375,8 +285,7 @@ export const Gantt = memo((p: GanttProps) => {
|
|
|
375
285
|
}
|
|
376
286
|
}, [range.start, range.end, rows, columns]);
|
|
377
287
|
useEffect(() => {
|
|
378
|
-
if (!p.selectedRowId || initialSelection.current === p.selectedRowId)
|
|
379
|
-
return;
|
|
288
|
+
if (!p.selectedRowId || initialSelection.current === p.selectedRowId) return;
|
|
380
289
|
const index = rows.findIndex((row) => row.id === p.selectedRowId);
|
|
381
290
|
if (index >= 0) {
|
|
382
291
|
initialSelection.current = p.selectedRowId;
|
|
@@ -385,12 +294,7 @@ export const Gantt = memo((p: GanttProps) => {
|
|
|
385
294
|
}, [p.selectedRowId, rows]);
|
|
386
295
|
/* Continue a committed editor move across rows that may not yet be mounted. */
|
|
387
296
|
const navigateCell = useCallback(
|
|
388
|
-
(
|
|
389
|
-
rowId: string,
|
|
390
|
-
columnKey: string,
|
|
391
|
-
direction: number,
|
|
392
|
-
vertical: boolean,
|
|
393
|
-
) => {
|
|
297
|
+
(rowId: string, columnKey: string, direction: number, vertical: boolean) => {
|
|
394
298
|
let rowIndex = rows.findIndex((row) => row.id === rowId);
|
|
395
299
|
let columnIndex = columns.findIndex((column) => column.key === columnKey);
|
|
396
300
|
if (vertical) rowIndex += direction;
|
|
@@ -410,10 +314,7 @@ export const Gantt = memo((p: GanttProps) => {
|
|
|
410
314
|
[rows, columns, focusCell],
|
|
411
315
|
);
|
|
412
316
|
/* Resize only the chosen column and remove global pointer listeners after the gesture. */
|
|
413
|
-
const resizeColumn = (
|
|
414
|
-
event: React.PointerEvent<HTMLDivElement>,
|
|
415
|
-
column: GanttColumnObj,
|
|
416
|
-
) => {
|
|
317
|
+
const resizeColumn = (event: React.PointerEvent<HTMLDivElement>, column: GanttColumnObj) => {
|
|
417
318
|
event.preventDefault();
|
|
418
319
|
cleanupResize.current?.();
|
|
419
320
|
const initialX = event.clientX;
|
|
@@ -421,10 +322,7 @@ export const Gantt = memo((p: GanttProps) => {
|
|
|
421
322
|
const move = (next: PointerEvent) =>
|
|
422
323
|
setColumnWidths((current) => ({
|
|
423
324
|
...current,
|
|
424
|
-
[column.key]: Math.max(
|
|
425
|
-
40,
|
|
426
|
-
Math.min(800, column.width + next.clientX - initialX),
|
|
427
|
-
),
|
|
325
|
+
[column.key]: Math.max(40, Math.min(800, column.width + next.clientX - initialX)),
|
|
428
326
|
}));
|
|
429
327
|
/* Finish or cancel a header resize without leaving window listeners active. */
|
|
430
328
|
const finish = () => {
|
|
@@ -466,20 +364,14 @@ export const Gantt = memo((p: GanttProps) => {
|
|
|
466
364
|
});
|
|
467
365
|
}, []);
|
|
468
366
|
/* Interpret all bar and connector gestures through one cancellable pointer lifecycle. */
|
|
469
|
-
const barPointerDown = useCallback<
|
|
470
|
-
NonNullable<GanttTimelineUIProps['onBarPointerDown']>
|
|
471
|
-
>(
|
|
367
|
+
const barPointerDown = useCallback<NonNullable<GanttTimelineUIProps['onBarPointerDown']>>(
|
|
472
368
|
(event, row, bar, kind) => {
|
|
473
369
|
const body = bodyRef.current;
|
|
474
370
|
if (!body) return;
|
|
475
|
-
if (
|
|
476
|
-
kind.startsWith('LINK')
|
|
477
|
-
? !latest.current.onCreateRelationship
|
|
478
|
-
: !latest.current.onMoveActivity
|
|
479
|
-
)
|
|
480
|
-
return;
|
|
371
|
+
if (kind.startsWith('LINK') ? !latest.current.onCreateRelationship : !latest.current.onMoveActivity) return;
|
|
481
372
|
cleanupDrag.current?.();
|
|
482
373
|
cleanupDrag.current = startGanttPointerInteraction({
|
|
374
|
+
isKeyboardLayerActive,
|
|
483
375
|
event,
|
|
484
376
|
row,
|
|
485
377
|
bar,
|
|
@@ -497,29 +389,18 @@ export const Gantt = memo((p: GanttProps) => {
|
|
|
497
389
|
const moveRows = useCallback<NonNullable<GanttTableUIProps['onMoveRows']>>(
|
|
498
390
|
(ids, wbsId, afterActivityId) => {
|
|
499
391
|
const selected = store.get(selection);
|
|
500
|
-
latest.current.onMoveRows?.(
|
|
501
|
-
ids.some((id) => selected.has(id)) ? [...selected] : ids,
|
|
502
|
-
wbsId,
|
|
503
|
-
afterActivityId,
|
|
504
|
-
);
|
|
392
|
+
latest.current.onMoveRows?.(ids.some((id) => selected.has(id)) ? [...selected] : ids, wbsId, afterActivityId);
|
|
505
393
|
},
|
|
506
394
|
[store, selection],
|
|
507
395
|
);
|
|
508
396
|
/* Dispatch navigation and command keys centrally so virtualized rows share one keyboard contract. */
|
|
509
397
|
const keyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {
|
|
510
398
|
const target = event.target as HTMLElement;
|
|
511
|
-
if (target.closest('input,textarea,select,button,[contenteditable="true"]'))
|
|
512
|
-
|
|
513
|
-
const
|
|
514
|
-
|
|
515
|
-
const
|
|
516
|
-
?.dataset.ganttColumn;
|
|
517
|
-
const rowIndex = rowId
|
|
518
|
-
? rows.findIndex((row) => row.id === rowId)
|
|
519
|
-
: Math.min(activeCell.current.rowIndex, rows.length - 1);
|
|
520
|
-
const columnIndex = columnKey
|
|
521
|
-
? columns.findIndex((column) => column.key === columnKey)
|
|
522
|
-
: activeCell.current.columnIndex;
|
|
399
|
+
if (target.closest('input,textarea,select,button,[contenteditable="true"]')) return;
|
|
400
|
+
const rowId = target.closest<HTMLElement>('[data-gantt-row]')?.dataset.ganttRow;
|
|
401
|
+
const columnKey = target.closest<HTMLElement>('[data-gantt-column]')?.dataset.ganttColumn;
|
|
402
|
+
const rowIndex = rowId ? rows.findIndex((row) => row.id === rowId) : Math.min(activeCell.current.rowIndex, rows.length - 1);
|
|
403
|
+
const columnIndex = columnKey ? columns.findIndex((column) => column.key === columnKey) : activeCell.current.columnIndex;
|
|
523
404
|
const row = rows[rowIndex];
|
|
524
405
|
const action = handleGanttKeyboardEvent(event, {
|
|
525
406
|
rowIndex,
|
|
@@ -536,9 +417,7 @@ export const Gantt = memo((p: GanttProps) => {
|
|
|
536
417
|
if (event.target === bodyRef.current && row) {
|
|
537
418
|
event.preventDefault();
|
|
538
419
|
focusCell(rowIndex, columnIndex);
|
|
539
|
-
document.activeElement?.dispatchEvent(
|
|
540
|
-
new MouseEvent('dblclick', { bubbles: true }),
|
|
541
|
-
);
|
|
420
|
+
document.activeElement?.dispatchEvent(new MouseEvent('dblclick', { bubbles: true }));
|
|
542
421
|
}
|
|
543
422
|
return;
|
|
544
423
|
}
|
|
@@ -549,14 +428,7 @@ export const Gantt = memo((p: GanttProps) => {
|
|
|
549
428
|
const next = rows[action.rowIndex];
|
|
550
429
|
focusCell(action.rowIndex, action.columnIndex);
|
|
551
430
|
if (next) {
|
|
552
|
-
const selected = getGanttSelection(
|
|
553
|
-
store.get(selection),
|
|
554
|
-
rows,
|
|
555
|
-
next.id,
|
|
556
|
-
anchorRef.current,
|
|
557
|
-
false,
|
|
558
|
-
action.extend,
|
|
559
|
-
);
|
|
431
|
+
const selected = getGanttSelection(store.get(selection), rows, next.id, anchorRef.current, false, action.extend);
|
|
560
432
|
store.set(selection, selected);
|
|
561
433
|
if (!action.extend) anchorRef.current = next.id;
|
|
562
434
|
latest.current.onSelectionChange?.([...selected]);
|
|
@@ -582,10 +454,7 @@ export const Gantt = memo((p: GanttProps) => {
|
|
|
582
454
|
else latest.current.onInsertActivity?.();
|
|
583
455
|
break;
|
|
584
456
|
case 'INDENT':
|
|
585
|
-
latest.current.onIndentRows?.(
|
|
586
|
-
ids.length ? ids : row ? [row.id] : [],
|
|
587
|
-
action.outdent,
|
|
588
|
-
);
|
|
457
|
+
latest.current.onIndentRows?.(ids.length ? ids : row ? [row.id] : [], action.outdent);
|
|
589
458
|
break;
|
|
590
459
|
case 'ZOOM':
|
|
591
460
|
latest.current.onZoomChange?.(action.zoom);
|
|
@@ -605,11 +474,7 @@ export const Gantt = memo((p: GanttProps) => {
|
|
|
605
474
|
});
|
|
606
475
|
}, [scale, viewport.left, timelineWidth, tableWidth]);
|
|
607
476
|
useEffect(() => {
|
|
608
|
-
if (
|
|
609
|
-
bodyRef.current &&
|
|
610
|
-
p.scrollLeft !== undefined &&
|
|
611
|
-
Math.abs(bodyRef.current.scrollLeft - p.scrollLeft) > 1
|
|
612
|
-
) {
|
|
477
|
+
if (bodyRef.current && p.scrollLeft !== undefined && Math.abs(bodyRef.current.scrollLeft - p.scrollLeft) > 1) {
|
|
613
478
|
bodyRef.current.scrollLeft = p.scrollLeft;
|
|
614
479
|
measure();
|
|
615
480
|
}
|
package/src/ui/ProjectFormUI.tsx
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import { cn } from '@jsb188/app/utils/string.ts';
|
|
2
|
-
import {
|
|
3
|
-
Input,
|
|
4
|
-
Select,
|
|
5
|
-
type SelectOptionType,
|
|
6
|
-
Textarea,
|
|
7
|
-
} from '@jsb188/react-web/modules/Form';
|
|
2
|
+
import { Input, Select, type SelectOptionType, Textarea } from '@jsb188/form/modules/Form';
|
|
8
3
|
import { Button } from '@jsb188/react-web/ui/Button';
|
|
9
4
|
import { memo } from 'react';
|
|
10
5
|
|
|
@@ -85,11 +80,7 @@ export const ProjectFormUI = memo((p: ProjectFormUIProps) => {
|
|
|
85
80
|
onDelete,
|
|
86
81
|
} = p;
|
|
87
82
|
|
|
88
|
-
const saveDisabled =
|
|
89
|
-
!!saving ||
|
|
90
|
-
!values.name.trim() ||
|
|
91
|
-
!values.plannedStartDate ||
|
|
92
|
-
!values.timeZone;
|
|
83
|
+
const saveDisabled = !!saving || !values.name.trim() || !values.plannedStartDate || !values.timeZone;
|
|
93
84
|
|
|
94
85
|
return (
|
|
95
86
|
<div className={cn('v_stretch h_f of', className)}>
|
|
@@ -148,15 +139,9 @@ export const ProjectFormUI = memo((p: ProjectFormUIProps) => {
|
|
|
148
139
|
name="timeZone"
|
|
149
140
|
label={timeZoneLabel}
|
|
150
141
|
disabled={saving}
|
|
151
|
-
options={
|
|
152
|
-
p.timeZoneOptions || [
|
|
153
|
-
{ value: values.timeZone, text: values.timeZone },
|
|
154
|
-
]
|
|
155
|
-
}
|
|
142
|
+
options={p.timeZoneOptions || [{ value: values.timeZone, text: values.timeZone }]}
|
|
156
143
|
value={values.timeZone}
|
|
157
|
-
onChange={(value) =>
|
|
158
|
-
onChangeValue('timeZone', String(value || 'UTC'))
|
|
159
|
-
}
|
|
144
|
+
onChange={(value) => onChangeValue('timeZone', String(value || 'UTC'))}
|
|
160
145
|
/>
|
|
161
146
|
{p.workCalendarOptions ? (
|
|
162
147
|
<Select
|
|
@@ -167,9 +152,7 @@ export const ProjectFormUI = memo((p: ProjectFormUIProps) => {
|
|
|
167
152
|
disabled={saving}
|
|
168
153
|
options={p.workCalendarOptions}
|
|
169
154
|
value={values.workCalendarId}
|
|
170
|
-
onChange={(value) =>
|
|
171
|
-
onChangeValue('workCalendarId', String(value || ''))
|
|
172
|
-
}
|
|
155
|
+
onChange={(value) => onChangeValue('workCalendarId', String(value || ''))}
|
|
173
156
|
/>
|
|
174
157
|
) : null}
|
|
175
158
|
|
|
@@ -183,9 +166,7 @@ export const ProjectFormUI = memo((p: ProjectFormUIProps) => {
|
|
|
183
166
|
label={plannedStartLabel}
|
|
184
167
|
disabled={saving}
|
|
185
168
|
value={values.plannedStartDate}
|
|
186
|
-
onChange={(e) =>
|
|
187
|
-
onChangeValue('plannedStartDate', e.currentTarget.value)
|
|
188
|
-
}
|
|
169
|
+
onChange={(e) => onChangeValue('plannedStartDate', e.currentTarget.value)}
|
|
189
170
|
/>
|
|
190
171
|
<Input
|
|
191
172
|
fullWidth
|
|
@@ -196,9 +177,7 @@ export const ProjectFormUI = memo((p: ProjectFormUIProps) => {
|
|
|
196
177
|
label={mustFinishByLabel}
|
|
197
178
|
disabled={saving}
|
|
198
179
|
value={values.mustFinishByDate}
|
|
199
|
-
onChange={(e) =>
|
|
200
|
-
onChangeValue('mustFinishByDate', e.currentTarget.value)
|
|
201
|
-
}
|
|
180
|
+
onChange={(e) => onChangeValue('mustFinishByDate', e.currentTarget.value)}
|
|
202
181
|
/>
|
|
203
182
|
</div>
|
|
204
183
|
|
|
@@ -226,9 +205,7 @@ export const ProjectFormUI = memo((p: ProjectFormUIProps) => {
|
|
|
226
205
|
onChange={(e) => onChangeValue('description', e.currentTarget.value)}
|
|
227
206
|
/>
|
|
228
207
|
|
|
229
|
-
{errorText ?
|
|
230
|
-
<div className="ft_xs cl_err mt_xs">{errorText}</div>
|
|
231
|
-
) : null}
|
|
208
|
+
{errorText ? <div className="ft_xs cl_err mt_xs">{errorText}</div> : null}
|
|
232
209
|
</div>
|
|
233
210
|
|
|
234
211
|
<div
|