awesome-timeline-react 0.1.14 → 0.2.0
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/LICENSE +21 -21
- package/README.md +184 -96
- package/dist/_tsup-dts-rollup.d.mts +738 -329
- package/dist/_tsup-dts-rollup.d.ts +738 -329
- package/dist/index.css +44 -125
- package/dist/index.css.map +1 -1
- package/dist/index.d.mts +19 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +1775 -1643
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1792 -1662
- package/dist/index.mjs.map +1 -1
- package/package.json +66 -62
- package/dist/src/index.d.mts +0 -1
- package/dist/src/index.d.ts +0 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __create = Object.create;
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
|
+
var __defProps = Object.defineProperties;
|
|
4
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
5
7
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
8
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
7
9
|
var __getProtoOf = Object.getPrototypeOf;
|
|
@@ -19,6 +21,7 @@ var __spreadValues = (a, b) => {
|
|
|
19
21
|
}
|
|
20
22
|
return a;
|
|
21
23
|
};
|
|
24
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
22
25
|
var __export = (target, all) => {
|
|
23
26
|
for (var name in all)
|
|
24
27
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -42,21 +45,240 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
42
45
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
43
46
|
|
|
44
47
|
// src/index.ts
|
|
45
|
-
var
|
|
46
|
-
__export(
|
|
48
|
+
var index_exports = {};
|
|
49
|
+
__export(index_exports, {
|
|
47
50
|
Timeline: () => Timeline
|
|
48
51
|
});
|
|
49
|
-
module.exports = __toCommonJS(
|
|
52
|
+
module.exports = __toCommonJS(index_exports);
|
|
50
53
|
|
|
51
54
|
// src/timeline.tsx
|
|
52
|
-
var
|
|
55
|
+
var import_react8 = __toESM(require("react"));
|
|
56
|
+
|
|
57
|
+
// src/canvas/animator.ts
|
|
58
|
+
var DEFAULT_LAYOUT_DURATION_MS = 200;
|
|
59
|
+
var DEFAULT_FADE_DURATION_MS = 120;
|
|
60
|
+
var ease = (t) => t * t * (3 - 2 * t);
|
|
61
|
+
var LayoutAnimator = class {
|
|
62
|
+
constructor() {
|
|
63
|
+
this.rowHeights = /* @__PURE__ */ new Map();
|
|
64
|
+
this.eventTops = /* @__PURE__ */ new Map();
|
|
65
|
+
this.handleAlphas = /* @__PURE__ */ new Map();
|
|
66
|
+
this.now = 0;
|
|
67
|
+
this.activeUntil = 0;
|
|
68
|
+
this.layoutDuration = DEFAULT_LAYOUT_DURATION_MS;
|
|
69
|
+
this.fadeDuration = DEFAULT_FADE_DURATION_MS;
|
|
70
|
+
}
|
|
71
|
+
setDurations(layoutMs, fadeMs) {
|
|
72
|
+
this.layoutDuration = layoutMs;
|
|
73
|
+
this.fadeDuration = fadeMs;
|
|
74
|
+
}
|
|
75
|
+
beginFrame(now) {
|
|
76
|
+
this.now = now;
|
|
77
|
+
}
|
|
78
|
+
rowHeight(rowId, target) {
|
|
79
|
+
return this.value(this.rowHeights, rowId, target, this.layoutDuration);
|
|
80
|
+
}
|
|
81
|
+
eventTop(eventId, target) {
|
|
82
|
+
return this.value(this.eventTops, eventId, target, this.layoutDuration);
|
|
83
|
+
}
|
|
84
|
+
/** 0..1 opacity of an event's resize handles; target 1 = hovered. */
|
|
85
|
+
handleAlpha(eventId, target) {
|
|
86
|
+
return this.value(this.handleAlphas, eventId, target, this.fadeDuration);
|
|
87
|
+
}
|
|
88
|
+
isAnimating() {
|
|
89
|
+
return this.now < this.activeUntil;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Drop an event's top tween so its next draw renders at the target
|
|
93
|
+
* instantly — used on drag-drop commit, where the ghost already previewed
|
|
94
|
+
* the final position and a tween would feel like a rubber-band.
|
|
95
|
+
*/
|
|
96
|
+
snapEventTop(eventId) {
|
|
97
|
+
this.eventTops.delete(eventId);
|
|
98
|
+
}
|
|
99
|
+
/** Drop all state, e.g. when the scene is reset wholesale. */
|
|
100
|
+
reset() {
|
|
101
|
+
this.rowHeights.clear();
|
|
102
|
+
this.eventTops.clear();
|
|
103
|
+
this.handleAlphas.clear();
|
|
104
|
+
this.activeUntil = 0;
|
|
105
|
+
}
|
|
106
|
+
value(map, key, target, duration) {
|
|
107
|
+
let tween = map.get(key);
|
|
108
|
+
if (!tween) {
|
|
109
|
+
tween = { from: target, to: target, start: 0, duration };
|
|
110
|
+
map.set(key, tween);
|
|
111
|
+
return target;
|
|
112
|
+
}
|
|
113
|
+
if (tween.to !== target) {
|
|
114
|
+
if (duration <= 0) {
|
|
115
|
+
tween.from = target;
|
|
116
|
+
tween.to = target;
|
|
117
|
+
return target;
|
|
118
|
+
}
|
|
119
|
+
const current = this.current(tween);
|
|
120
|
+
tween.from = current;
|
|
121
|
+
tween.to = target;
|
|
122
|
+
tween.start = this.now;
|
|
123
|
+
tween.duration = duration;
|
|
124
|
+
this.activeUntil = Math.max(this.activeUntil, this.now + duration);
|
|
125
|
+
}
|
|
126
|
+
return this.current(tween);
|
|
127
|
+
}
|
|
128
|
+
current(tween) {
|
|
129
|
+
if (tween.from === tween.to || tween.duration <= 0) return tween.to;
|
|
130
|
+
const t = Math.min(1, (this.now - tween.start) / tween.duration);
|
|
131
|
+
return tween.from + (tween.to - tween.from) * ease(t);
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
// src/hooks/use-resize-observer.ts
|
|
136
|
+
var import_react = require("react");
|
|
137
|
+
var useResizeObserver = ({
|
|
138
|
+
windowTime,
|
|
139
|
+
setTick,
|
|
140
|
+
setCellWidth,
|
|
141
|
+
contentRef
|
|
142
|
+
}) => {
|
|
143
|
+
const prevWidthRef = (0, import_react.useRef)(0);
|
|
144
|
+
const resizeObserver = (0, import_react.useMemo)(() => {
|
|
145
|
+
return new ResizeObserver((entries) => {
|
|
146
|
+
var _a;
|
|
147
|
+
for (const entry of entries) {
|
|
148
|
+
const width = (_a = entry.borderBoxSize) == null ? void 0 : _a[0].inlineSize;
|
|
149
|
+
if (typeof width === "number" && width !== prevWidthRef.current) {
|
|
150
|
+
prevWidthRef.current = width;
|
|
151
|
+
const windowDuration = windowTime[1] - windowTime[0];
|
|
152
|
+
const numberOfHourBlocks = windowDuration / 3600;
|
|
153
|
+
setTick(windowDuration / entry.contentRect.width);
|
|
154
|
+
setCellWidth(entry.contentRect.width / numberOfHourBlocks);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
}, [windowTime]);
|
|
159
|
+
(0, import_react.useEffect)(() => {
|
|
160
|
+
if (contentRef.current) {
|
|
161
|
+
resizeObserver.observe(contentRef.current, { box: "border-box" });
|
|
162
|
+
}
|
|
163
|
+
return () => resizeObserver.disconnect();
|
|
164
|
+
}, [resizeObserver]);
|
|
165
|
+
};
|
|
166
|
+
var use_resize_observer_default = useResizeObserver;
|
|
167
|
+
|
|
168
|
+
// src/helpers/sort-events.ts
|
|
169
|
+
var sortEvents = (eventA, eventB) => {
|
|
170
|
+
if (eventA.startTime - eventB.startTime < 0) return -1;
|
|
171
|
+
if (eventA.startTime === eventB.startTime) {
|
|
172
|
+
if (eventA.endTime < eventB.endTime) {
|
|
173
|
+
return -1;
|
|
174
|
+
} else {
|
|
175
|
+
return 1;
|
|
176
|
+
}
|
|
177
|
+
} else {
|
|
178
|
+
return 1;
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
var sort_events_default = sortEvents;
|
|
182
|
+
|
|
183
|
+
// src/components/rt-indicator.tsx
|
|
184
|
+
var import_react2 = __toESM(require("react"));
|
|
185
|
+
var RTIndicator = ({
|
|
186
|
+
tick,
|
|
187
|
+
windowTime
|
|
188
|
+
}) => {
|
|
189
|
+
const [currentTime, setCurrentTime] = (0, import_react2.useState)((/* @__PURE__ */ new Date()).getTime() / 1e3);
|
|
190
|
+
const [leftOffset, setLeftOffset] = (0, import_react2.useState)(0);
|
|
191
|
+
const intervalIdRef = (0, import_react2.useRef)(null);
|
|
192
|
+
(0, import_react2.useEffect)(() => {
|
|
193
|
+
if (tick) {
|
|
194
|
+
const leftOffsetTime = currentTime - windowTime[0];
|
|
195
|
+
setLeftOffset(Math.round(leftOffsetTime / tick));
|
|
196
|
+
if (intervalIdRef.current !== null) {
|
|
197
|
+
clearInterval(intervalIdRef.current);
|
|
198
|
+
}
|
|
199
|
+
const intervalId = setInterval(() => {
|
|
200
|
+
setCurrentTime((/* @__PURE__ */ new Date()).getTime() / 1e3);
|
|
201
|
+
}, tick * 1e3);
|
|
202
|
+
intervalIdRef.current = intervalId;
|
|
203
|
+
}
|
|
204
|
+
}, [tick, windowTime, currentTime]);
|
|
205
|
+
return /* @__PURE__ */ import_react2.default.createElement(import_react2.default.Fragment, null, windowTime[0] <= currentTime && currentTime <= windowTime[1] && /* @__PURE__ */ import_react2.default.createElement(import_react2.default.Fragment, null, /* @__PURE__ */ import_react2.default.createElement("div", { className: "rt-arrow", style: { left: 86 + leftOffset } }), /* @__PURE__ */ import_react2.default.createElement("div", { className: "rt-line", style: { left: 100 + leftOffset } })));
|
|
206
|
+
};
|
|
207
|
+
var rt_indicator_default = RTIndicator;
|
|
208
|
+
|
|
209
|
+
// src/components/event-prompt.tsx
|
|
210
|
+
var import_react3 = __toESM(require("react"));
|
|
211
|
+
var import_dom = require("@floating-ui/dom");
|
|
212
|
+
var EventPrompt = (0, import_react3.forwardRef)(
|
|
213
|
+
({ template }, ref) => {
|
|
214
|
+
const promptRef = (0, import_react3.useRef)(null);
|
|
215
|
+
const [hoveredEvent, setHoveredEvent] = (0, import_react3.useState)();
|
|
216
|
+
const showSeqRef = (0, import_react3.useRef)(0);
|
|
217
|
+
(0, import_react3.useImperativeHandle)(ref, () => {
|
|
218
|
+
return {
|
|
219
|
+
show(event, anchorRect) {
|
|
220
|
+
const prompt = promptRef.current;
|
|
221
|
+
if (!prompt) return;
|
|
222
|
+
setHoveredEvent(event);
|
|
223
|
+
const seq = ++showSeqRef.current;
|
|
224
|
+
const virtualAnchor = {
|
|
225
|
+
getBoundingClientRect: () => ({
|
|
226
|
+
x: anchorRect.x,
|
|
227
|
+
y: anchorRect.y,
|
|
228
|
+
width: anchorRect.width,
|
|
229
|
+
height: anchorRect.height,
|
|
230
|
+
top: anchorRect.y,
|
|
231
|
+
left: anchorRect.x,
|
|
232
|
+
right: anchorRect.x + anchorRect.width,
|
|
233
|
+
bottom: anchorRect.y + anchorRect.height
|
|
234
|
+
})
|
|
235
|
+
};
|
|
236
|
+
prompt.style.display = "block";
|
|
237
|
+
prompt.style.visibility = "hidden";
|
|
238
|
+
(0, import_dom.computePosition)(virtualAnchor, prompt, {
|
|
239
|
+
placement: "top",
|
|
240
|
+
middleware: [
|
|
241
|
+
(0, import_dom.offset)(8),
|
|
242
|
+
(0, import_dom.flip)({ padding: 8 }),
|
|
243
|
+
(0, import_dom.shift)({ padding: 8 })
|
|
244
|
+
]
|
|
245
|
+
}).then(({ x, y }) => {
|
|
246
|
+
if (seq !== showSeqRef.current || !promptRef.current) return;
|
|
247
|
+
promptRef.current.style.left = `${x}px`;
|
|
248
|
+
promptRef.current.style.top = `${y}px`;
|
|
249
|
+
promptRef.current.style.visibility = "visible";
|
|
250
|
+
});
|
|
251
|
+
},
|
|
252
|
+
hide() {
|
|
253
|
+
showSeqRef.current++;
|
|
254
|
+
if (promptRef.current) {
|
|
255
|
+
promptRef.current.style.display = "none";
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
});
|
|
260
|
+
return /* @__PURE__ */ import_react3.default.createElement("div", { className: "event-prompt", ref: promptRef }, template && hoveredEvent && template(hoveredEvent));
|
|
261
|
+
}
|
|
262
|
+
);
|
|
263
|
+
var event_prompt_default = EventPrompt;
|
|
53
264
|
|
|
54
|
-
// src/components/time-bar.tsx
|
|
55
|
-
var
|
|
265
|
+
// src/components/canvas-time-bar.tsx
|
|
266
|
+
var import_react5 = __toESM(require("react"));
|
|
56
267
|
|
|
57
|
-
// src/hooks/use-
|
|
58
|
-
var
|
|
59
|
-
var
|
|
268
|
+
// src/hooks/use-get-block-properties.ts
|
|
269
|
+
var import_react4 = require("react");
|
|
270
|
+
var useGetBlockProperties = ({
|
|
271
|
+
windowTime,
|
|
272
|
+
contentWidth
|
|
273
|
+
}) => {
|
|
274
|
+
const numberOfHourBlocks = (0, import_react4.useMemo)(
|
|
275
|
+
() => (windowTime[1] - windowTime[0]) / 3600,
|
|
276
|
+
[windowTime]
|
|
277
|
+
);
|
|
278
|
+
const blockWidth = contentWidth ? contentWidth / numberOfHourBlocks : 0;
|
|
279
|
+
return { numberOfHourBlocks, blockWidth };
|
|
280
|
+
};
|
|
281
|
+
var use_get_block_properties_default = useGetBlockProperties;
|
|
60
282
|
|
|
61
283
|
// src/helpers/get-month-name.ts
|
|
62
284
|
var getMonthName = (monthIndex) => {
|
|
@@ -137,173 +359,243 @@ var getWeekDayName = (dayIndex) => {
|
|
|
137
359
|
};
|
|
138
360
|
var get_week_day_name_default = getWeekDayName;
|
|
139
361
|
|
|
140
|
-
// src/
|
|
141
|
-
var
|
|
142
|
-
|
|
362
|
+
// src/core/time-blocks.ts
|
|
363
|
+
var hourLabel = (hour) => hour < 10 ? `0${hour}:00` : `${hour}:00`;
|
|
364
|
+
var dayLabel = (date) => `${get_week_day_name_default(date.getDay())} ${date.getDate()} ${get_month_name_default(
|
|
365
|
+
date.getMonth()
|
|
366
|
+
)}`;
|
|
367
|
+
var generateTimeBlocks = ({
|
|
368
|
+
windowStart,
|
|
143
369
|
tick,
|
|
144
370
|
contentWidth,
|
|
145
371
|
blockWidth
|
|
146
372
|
}) => {
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
className: "hour-block",
|
|
177
|
-
key: `${datePoint.getDate()}_hour_${i}`
|
|
178
|
-
},
|
|
179
|
-
i < 10 ? `0${i}:00` : `${i}:00`
|
|
180
|
-
)
|
|
181
|
-
);
|
|
182
|
-
}
|
|
183
|
-
dayBlocks2.push(
|
|
184
|
-
/* @__PURE__ */ import_react.default.createElement(
|
|
185
|
-
"div",
|
|
186
|
-
{
|
|
187
|
-
className: "day-block",
|
|
188
|
-
key: `${datePoint.getDate()} ${datePoint.getMonth()}`,
|
|
189
|
-
style: {
|
|
190
|
-
gridColumn: `${prevNumBlocks} / ${prevNumBlocks + numBlocks2}`
|
|
191
|
-
// width: dateWidth + widthLeft,
|
|
192
|
-
// minWidth: dateWidth + widthLeft,
|
|
193
|
-
}
|
|
194
|
-
},
|
|
195
|
-
get_week_day_name_default(datePoint.getDay()),
|
|
196
|
-
" ",
|
|
197
|
-
datePoint.getDate(),
|
|
198
|
-
" ",
|
|
199
|
-
get_month_name_default(datePoint.getMonth())
|
|
200
|
-
)
|
|
201
|
-
);
|
|
202
|
-
prevNumBlocks += numBlocks2;
|
|
203
|
-
break;
|
|
204
|
-
}
|
|
205
|
-
const numBlocks = Math.round(dateWidth / blockWidth);
|
|
206
|
-
for (let i = 24 - numBlocks; i < 24; i++) {
|
|
207
|
-
hourBlocks2.push(
|
|
208
|
-
/* @__PURE__ */ import_react.default.createElement("div", { className: "hour-block", key: `${datePoint.getDate()}_hour_${i}` }, i < 10 ? `0${i}:00` : `${i}:00`)
|
|
209
|
-
);
|
|
210
|
-
}
|
|
211
|
-
dayBlocks2.push(
|
|
212
|
-
/* @__PURE__ */ import_react.default.createElement(
|
|
213
|
-
"div",
|
|
214
|
-
{
|
|
215
|
-
className: "day-block",
|
|
216
|
-
key: `${datePoint.getDate()} ${datePoint.getMonth()}`,
|
|
217
|
-
style: {
|
|
218
|
-
gridColumn: `${prevNumBlocks} / ${prevNumBlocks + numBlocks}`
|
|
219
|
-
// width: dateWidth,
|
|
220
|
-
// minWidth: dateWidth,
|
|
221
|
-
}
|
|
222
|
-
},
|
|
223
|
-
get_week_day_name_default(datePoint.getDay()),
|
|
224
|
-
" ",
|
|
225
|
-
datePoint.getDate(),
|
|
226
|
-
" ",
|
|
227
|
-
get_month_name_default(datePoint.getMonth())
|
|
228
|
-
)
|
|
229
|
-
);
|
|
230
|
-
prevNumBlocks += numBlocks;
|
|
231
|
-
if (Math.round(widthLeft) === 0) {
|
|
232
|
-
break;
|
|
373
|
+
const dayBlocks = [];
|
|
374
|
+
const hourBlocks = [];
|
|
375
|
+
if (tick === null || contentWidth === null || blockWidth <= 0) {
|
|
376
|
+
return { dayBlocks, hourBlocks };
|
|
377
|
+
}
|
|
378
|
+
let timePoint = windowStart;
|
|
379
|
+
let widthLeft = contentWidth;
|
|
380
|
+
let prevNumBlocks = 1;
|
|
381
|
+
while (1) {
|
|
382
|
+
const datePoint = new Date(timePoint * 1e3);
|
|
383
|
+
const endDatePoint = new Date(
|
|
384
|
+
datePoint.getFullYear(),
|
|
385
|
+
datePoint.getMonth(),
|
|
386
|
+
datePoint.getDate(),
|
|
387
|
+
23,
|
|
388
|
+
59,
|
|
389
|
+
59
|
|
390
|
+
);
|
|
391
|
+
const dateDuration = endDatePoint.getTime() - datePoint.getTime();
|
|
392
|
+
const dateWidth = dateDuration / 1e3 / tick;
|
|
393
|
+
widthLeft -= dateWidth;
|
|
394
|
+
if (Math.round(widthLeft) < 0) {
|
|
395
|
+
const numBlocks2 = Math.round((dateWidth + widthLeft) / blockWidth);
|
|
396
|
+
for (let i = 0; i < numBlocks2; i++) {
|
|
397
|
+
hourBlocks.push({
|
|
398
|
+
label: hourLabel(i),
|
|
399
|
+
x: hourBlocks.length * blockWidth,
|
|
400
|
+
width: blockWidth
|
|
401
|
+
});
|
|
233
402
|
}
|
|
234
|
-
|
|
403
|
+
dayBlocks.push({
|
|
404
|
+
label: dayLabel(datePoint),
|
|
405
|
+
x: (prevNumBlocks - 1) * blockWidth,
|
|
406
|
+
width: numBlocks2 * blockWidth
|
|
407
|
+
});
|
|
408
|
+
prevNumBlocks += numBlocks2;
|
|
409
|
+
break;
|
|
410
|
+
}
|
|
411
|
+
const numBlocks = Math.round(dateWidth / blockWidth);
|
|
412
|
+
for (let i = 24 - numBlocks; i < 24; i++) {
|
|
413
|
+
hourBlocks.push({
|
|
414
|
+
label: hourLabel(i),
|
|
415
|
+
x: hourBlocks.length * blockWidth,
|
|
416
|
+
width: blockWidth
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
dayBlocks.push({
|
|
420
|
+
label: dayLabel(datePoint),
|
|
421
|
+
x: (prevNumBlocks - 1) * blockWidth,
|
|
422
|
+
width: numBlocks * blockWidth
|
|
423
|
+
});
|
|
424
|
+
prevNumBlocks += numBlocks;
|
|
425
|
+
if (Math.round(widthLeft) === 0) {
|
|
426
|
+
break;
|
|
235
427
|
}
|
|
236
|
-
|
|
237
|
-
}
|
|
428
|
+
timePoint = (endDatePoint.getTime() + 1e3) / 1e3;
|
|
429
|
+
}
|
|
238
430
|
return { dayBlocks, hourBlocks };
|
|
239
431
|
};
|
|
240
|
-
var use_generate_blocks_default = useGenerateBlocks;
|
|
241
432
|
|
|
242
|
-
// src/
|
|
243
|
-
var
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
433
|
+
// src/canvas/dpr.ts
|
|
434
|
+
var sizeCanvas = (canvas, cssWidth, cssHeight, dpr) => {
|
|
435
|
+
canvas.width = Math.max(1, Math.round(cssWidth * dpr));
|
|
436
|
+
canvas.height = Math.max(1, Math.round(cssHeight * dpr));
|
|
437
|
+
canvas.style.width = `${cssWidth}px`;
|
|
438
|
+
canvas.style.height = `${cssHeight}px`;
|
|
439
|
+
const ctx = canvas.getContext("2d");
|
|
440
|
+
if (ctx) {
|
|
441
|
+
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
442
|
+
}
|
|
443
|
+
return ctx;
|
|
444
|
+
};
|
|
445
|
+
var watchDpr = (onChange) => {
|
|
446
|
+
let disposed = false;
|
|
447
|
+
let cleanup = () => {
|
|
448
|
+
};
|
|
449
|
+
const listen = () => {
|
|
450
|
+
if (disposed) return;
|
|
451
|
+
const media = window.matchMedia(
|
|
452
|
+
`(resolution: ${window.devicePixelRatio}dppx)`
|
|
453
|
+
);
|
|
454
|
+
const handler = () => {
|
|
455
|
+
onChange(window.devicePixelRatio);
|
|
456
|
+
media.removeEventListener("change", handler);
|
|
457
|
+
listen();
|
|
458
|
+
};
|
|
459
|
+
media.addEventListener("change", handler);
|
|
460
|
+
cleanup = () => media.removeEventListener("change", handler);
|
|
461
|
+
};
|
|
462
|
+
listen();
|
|
463
|
+
return () => {
|
|
464
|
+
disposed = true;
|
|
465
|
+
cleanup();
|
|
466
|
+
};
|
|
467
|
+
};
|
|
468
|
+
|
|
469
|
+
// src/canvas/theme.ts
|
|
470
|
+
var DEFAULT_THEME = {
|
|
471
|
+
eventFill: "#ffffff",
|
|
472
|
+
eventStroke: "#000000",
|
|
473
|
+
eventTextColor: "#000000",
|
|
474
|
+
staticEventFill: "#e0e0e0",
|
|
475
|
+
gridColor: "#e4dcdc",
|
|
476
|
+
timeBarBorder: "yellow",
|
|
477
|
+
timeBarTextColor: "white",
|
|
478
|
+
font: void 0
|
|
479
|
+
};
|
|
480
|
+
var resolveTheme = (theme) => __spreadValues(__spreadValues({}, DEFAULT_THEME), theme);
|
|
481
|
+
|
|
482
|
+
// src/canvas/draw-grid.ts
|
|
483
|
+
var drawGridLines = (ctx, {
|
|
484
|
+
width,
|
|
485
|
+
height,
|
|
486
|
+
cellWidth,
|
|
487
|
+
color = DEFAULT_THEME.gridColor
|
|
247
488
|
}) => {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
);
|
|
252
|
-
|
|
253
|
-
|
|
489
|
+
if (cellWidth <= 0) return;
|
|
490
|
+
ctx.strokeStyle = color;
|
|
491
|
+
ctx.lineWidth = 1;
|
|
492
|
+
ctx.beginPath();
|
|
493
|
+
for (let x = cellWidth; x < width; x += cellWidth) {
|
|
494
|
+
if (width - x < 1) break;
|
|
495
|
+
const crisp = Math.round(x) - 0.5;
|
|
496
|
+
ctx.moveTo(crisp, 0);
|
|
497
|
+
ctx.lineTo(crisp, height);
|
|
498
|
+
}
|
|
499
|
+
ctx.stroke();
|
|
500
|
+
};
|
|
501
|
+
var drawTimeBar = (ctx, {
|
|
502
|
+
width,
|
|
503
|
+
height,
|
|
504
|
+
dayBlocks,
|
|
505
|
+
hourBlocks,
|
|
506
|
+
font,
|
|
507
|
+
borderColor = DEFAULT_THEME.timeBarBorder,
|
|
508
|
+
textColor = DEFAULT_THEME.timeBarTextColor
|
|
509
|
+
}) => {
|
|
510
|
+
const mid = height / 2;
|
|
511
|
+
ctx.strokeStyle = borderColor;
|
|
512
|
+
ctx.lineWidth = 1;
|
|
513
|
+
ctx.beginPath();
|
|
514
|
+
ctx.moveTo(0, Math.round(mid) - 0.5);
|
|
515
|
+
ctx.lineTo(width, Math.round(mid) - 0.5);
|
|
516
|
+
ctx.stroke();
|
|
517
|
+
ctx.beginPath();
|
|
518
|
+
for (let i = 0; i < dayBlocks.length - 1; i++) {
|
|
519
|
+
const edge = Math.round(dayBlocks[i].x + dayBlocks[i].width) - 0.5;
|
|
520
|
+
ctx.moveTo(edge, 0);
|
|
521
|
+
ctx.lineTo(edge, mid);
|
|
522
|
+
}
|
|
523
|
+
for (let i = 0; i < hourBlocks.length - 1; i++) {
|
|
524
|
+
const edge = Math.round(hourBlocks[i].x + hourBlocks[i].width) - 0.5;
|
|
525
|
+
ctx.moveTo(edge, mid);
|
|
526
|
+
ctx.lineTo(edge, height);
|
|
527
|
+
}
|
|
528
|
+
ctx.stroke();
|
|
529
|
+
ctx.fillStyle = textColor;
|
|
530
|
+
ctx.font = font;
|
|
531
|
+
ctx.textBaseline = "middle";
|
|
532
|
+
ctx.textAlign = "center";
|
|
533
|
+
const inset = 4;
|
|
534
|
+
for (const block of dayBlocks) {
|
|
535
|
+
ctx.fillText(
|
|
536
|
+
block.label,
|
|
537
|
+
block.x + block.width / 2,
|
|
538
|
+
mid / 2,
|
|
539
|
+
block.width - inset
|
|
540
|
+
);
|
|
541
|
+
}
|
|
542
|
+
for (const block of hourBlocks) {
|
|
543
|
+
ctx.fillText(
|
|
544
|
+
block.label,
|
|
545
|
+
block.x + block.width / 2,
|
|
546
|
+
mid + mid / 2,
|
|
547
|
+
block.width - inset
|
|
548
|
+
);
|
|
549
|
+
}
|
|
254
550
|
};
|
|
255
|
-
var use_get_block_properties_default = useGetBlockProperties;
|
|
256
551
|
|
|
257
|
-
// src/components/time-bar.tsx
|
|
258
|
-
var
|
|
552
|
+
// src/components/canvas-time-bar.tsx
|
|
553
|
+
var TIME_BAR_INNER_HEIGHT = 48;
|
|
554
|
+
var CanvasTimeBar = ({
|
|
259
555
|
windowTime,
|
|
260
556
|
tick,
|
|
261
557
|
contentWidth,
|
|
262
558
|
scrollWidth,
|
|
263
|
-
|
|
559
|
+
theme
|
|
264
560
|
}) => {
|
|
265
|
-
const
|
|
561
|
+
const canvasRef = (0, import_react5.useRef)(null);
|
|
266
562
|
const { blockWidth } = use_get_block_properties_default({
|
|
267
563
|
windowTime,
|
|
268
564
|
contentWidth
|
|
269
565
|
});
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
contentWidth
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
566
|
+
(0, import_react5.useEffect)(() => {
|
|
567
|
+
var _a;
|
|
568
|
+
const canvas = canvasRef.current;
|
|
569
|
+
if (!canvas || !contentWidth) return;
|
|
570
|
+
const ctx = sizeCanvas(
|
|
571
|
+
canvas,
|
|
572
|
+
contentWidth,
|
|
573
|
+
TIME_BAR_INNER_HEIGHT,
|
|
574
|
+
window.devicePixelRatio
|
|
575
|
+
);
|
|
576
|
+
if (ctx) {
|
|
577
|
+
drawTimeBar(ctx, __spreadValues({
|
|
578
|
+
width: contentWidth,
|
|
579
|
+
height: TIME_BAR_INNER_HEIGHT,
|
|
580
|
+
font: (_a = theme == null ? void 0 : theme.font) != null ? _a : getComputedStyle(canvas).font,
|
|
581
|
+
borderColor: theme == null ? void 0 : theme.timeBarBorder,
|
|
582
|
+
textColor: theme == null ? void 0 : theme.timeBarTextColor
|
|
583
|
+
}, generateTimeBlocks({
|
|
584
|
+
windowStart: windowTime[0],
|
|
585
|
+
tick,
|
|
586
|
+
contentWidth,
|
|
587
|
+
blockWidth
|
|
588
|
+
})));
|
|
589
|
+
}
|
|
590
|
+
}, [windowTime, tick, contentWidth, blockWidth, theme]);
|
|
591
|
+
return /* @__PURE__ */ import_react5.default.createElement("div", { className: "time-bar" }, /* @__PURE__ */ import_react5.default.createElement("div", { className: "empty-block" }), /* @__PURE__ */ import_react5.default.createElement(
|
|
592
|
+
"canvas",
|
|
281
593
|
{
|
|
282
|
-
|
|
283
|
-
|
|
594
|
+
ref: canvasRef,
|
|
595
|
+
className: "canvas-time-bar",
|
|
284
596
|
style: { minWidth: contentWidth ? contentWidth : 0 }
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
"div",
|
|
288
|
-
{
|
|
289
|
-
className: dayRowClassNames,
|
|
290
|
-
style: {
|
|
291
|
-
gridTemplateColumns: `repeat(auto-fill, minmax(${blockWidth}px, 1fr))`
|
|
292
|
-
}
|
|
293
|
-
},
|
|
294
|
-
dayBlocks.map((block) => block)
|
|
295
|
-
),
|
|
296
|
-
/* @__PURE__ */ import_react4.default.createElement(
|
|
297
|
-
"div",
|
|
298
|
-
{
|
|
299
|
-
className: hourRowClassNames,
|
|
300
|
-
style: {
|
|
301
|
-
gridTemplateColumns: `repeat(auto-fill, minmax(${blockWidth}px, 1fr))`
|
|
302
|
-
}
|
|
303
|
-
},
|
|
304
|
-
hourBlocks.map((block) => block)
|
|
305
|
-
)
|
|
306
|
-
), scrollWidth ? /* @__PURE__ */ import_react4.default.createElement(
|
|
597
|
+
}
|
|
598
|
+
), scrollWidth ? /* @__PURE__ */ import_react5.default.createElement(
|
|
307
599
|
"div",
|
|
308
600
|
{
|
|
309
601
|
style: {
|
|
@@ -315,1608 +607,1448 @@ var TimeBar = ({
|
|
|
315
607
|
}
|
|
316
608
|
) : null);
|
|
317
609
|
};
|
|
318
|
-
var
|
|
610
|
+
var canvas_time_bar_default = CanvasTimeBar;
|
|
319
611
|
|
|
320
|
-
// src/components/
|
|
612
|
+
// src/components/canvas-board.tsx
|
|
321
613
|
var import_react7 = __toESM(require("react"));
|
|
322
614
|
|
|
323
|
-
// src/
|
|
324
|
-
var
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
)
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
615
|
+
// src/canvas/frame-scheduler.ts
|
|
616
|
+
var FrameScheduler = class {
|
|
617
|
+
constructor(onFrame) {
|
|
618
|
+
this.onFrame = onFrame;
|
|
619
|
+
this.rafId = null;
|
|
620
|
+
this.dirty = { static: false, dynamic: false };
|
|
621
|
+
}
|
|
622
|
+
invalidate(layer) {
|
|
623
|
+
if (layer === "all" || layer === "static") this.dirty.static = true;
|
|
624
|
+
if (layer === "all" || layer === "dynamic") this.dirty.dynamic = true;
|
|
625
|
+
this.schedule();
|
|
626
|
+
}
|
|
627
|
+
/** Runs a pending frame immediately (tests, synchronous reads). */
|
|
628
|
+
flush() {
|
|
629
|
+
if (this.rafId !== null) {
|
|
630
|
+
cancelAnimationFrame(this.rafId);
|
|
631
|
+
this.rafId = null;
|
|
632
|
+
this.run();
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
dispose() {
|
|
636
|
+
if (this.rafId !== null) {
|
|
637
|
+
cancelAnimationFrame(this.rafId);
|
|
638
|
+
this.rafId = null;
|
|
639
|
+
}
|
|
640
|
+
this.dirty = { static: false, dynamic: false };
|
|
641
|
+
}
|
|
642
|
+
schedule() {
|
|
643
|
+
if (this.rafId !== null) return;
|
|
644
|
+
this.rafId = requestAnimationFrame(() => {
|
|
645
|
+
this.rafId = null;
|
|
646
|
+
this.run();
|
|
647
|
+
});
|
|
648
|
+
}
|
|
649
|
+
run() {
|
|
650
|
+
const dirty = this.dirty;
|
|
651
|
+
this.dirty = { static: false, dynamic: false };
|
|
652
|
+
if (dirty.static || dirty.dynamic) this.onFrame(dirty);
|
|
653
|
+
}
|
|
337
654
|
};
|
|
338
|
-
var row_header_default = RowHeader;
|
|
339
655
|
|
|
340
|
-
// src/
|
|
341
|
-
var
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
{
|
|
349
|
-
|
|
350
|
-
id: row.id,
|
|
351
|
-
name: row.name
|
|
656
|
+
// src/core/culling.ts
|
|
657
|
+
var cullToWindow = (events, windowStart, windowEnd) => {
|
|
658
|
+
let lo = 0;
|
|
659
|
+
let hi = events.length;
|
|
660
|
+
while (lo < hi) {
|
|
661
|
+
const mid = lo + hi >> 1;
|
|
662
|
+
if (events[mid].startTime <= windowEnd) {
|
|
663
|
+
lo = mid + 1;
|
|
664
|
+
} else {
|
|
665
|
+
hi = mid;
|
|
352
666
|
}
|
|
353
|
-
|
|
667
|
+
}
|
|
668
|
+
const visible = [];
|
|
669
|
+
for (let i = 0; i < lo; i++) {
|
|
670
|
+
if (events[i].endTime >= windowStart) visible.push(events[i]);
|
|
671
|
+
}
|
|
672
|
+
return visible;
|
|
354
673
|
};
|
|
355
|
-
var rows_header_default = RowsHeader;
|
|
356
674
|
|
|
357
|
-
// src/
|
|
358
|
-
var
|
|
675
|
+
// src/core/coords.ts
|
|
676
|
+
var timeToX = (time, windowStart, tick) => (time - windowStart) / tick;
|
|
677
|
+
var timeToWidth = (startTime, endTime, tick) => (endTime - startTime) / tick;
|
|
678
|
+
var intersectsWindow = (event, windowStart, windowEnd) => event.endTime >= windowStart && event.startTime <= windowEnd;
|
|
359
679
|
|
|
360
|
-
// src/
|
|
361
|
-
var
|
|
362
|
-
var
|
|
363
|
-
var
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
680
|
+
// src/core/lanes.ts
|
|
681
|
+
var LANE_HEIGHT = 22;
|
|
682
|
+
var LANE_TOP_OFFSET = 10;
|
|
683
|
+
var ROW_BASE_HEIGHT = 40;
|
|
684
|
+
var STATIC_EVENT_BASE_HEIGHT = 20;
|
|
685
|
+
var EVENT_BAR_HEIGHT = 20;
|
|
686
|
+
var laneTop = (lane) => LANE_TOP_OFFSET + LANE_HEIGHT * lane;
|
|
687
|
+
var rowMinHeight = (highestLane) => ROW_BASE_HEIGHT + highestLane * LANE_HEIGHT;
|
|
688
|
+
var staticEventHeight = (highestLane) => STATIC_EVENT_BASE_HEIGHT + highestLane * LANE_HEIGHT;
|
|
689
|
+
var assignLanes = (rowEvents, windowStart, windowEnd) => {
|
|
690
|
+
let eventOrder = 0;
|
|
691
|
+
const prevEvent = [];
|
|
692
|
+
let highestEventOrder = 0;
|
|
693
|
+
const laneOf = /* @__PURE__ */ new Map();
|
|
694
|
+
for (const event of rowEvents) {
|
|
695
|
+
if (!intersectsWindow(event, windowStart, windowEnd)) continue;
|
|
696
|
+
let tempEventOrder = 0;
|
|
697
|
+
let assignEventOrder = true;
|
|
698
|
+
for (let i = 0; i <= eventOrder; i++) {
|
|
699
|
+
if (prevEvent[i] && prevEvent[i].endTime > event.startTime) {
|
|
700
|
+
tempEventOrder += 1;
|
|
701
|
+
} else {
|
|
702
|
+
if (eventOrder > highestEventOrder) {
|
|
703
|
+
highestEventOrder = eventOrder;
|
|
704
|
+
}
|
|
705
|
+
eventOrder = 0;
|
|
706
|
+
assignEventOrder = false;
|
|
707
|
+
break;
|
|
374
708
|
}
|
|
375
709
|
}
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
gridTemplateColumns: `repeat(auto-fill, minmax(${cellWidth}px, 1fr))`
|
|
387
|
-
} : {
|
|
388
|
-
gridTemplateColumns: `repeat(auto-fill, minmax(${minWidth}px, ${cellWidth}px))`
|
|
389
|
-
}
|
|
390
|
-
},
|
|
391
|
-
lines
|
|
392
|
-
);
|
|
710
|
+
if (assignEventOrder) {
|
|
711
|
+
eventOrder = tempEventOrder;
|
|
712
|
+
}
|
|
713
|
+
prevEvent[tempEventOrder] = event;
|
|
714
|
+
laneOf.set(event.id, tempEventOrder);
|
|
715
|
+
}
|
|
716
|
+
if (eventOrder > highestEventOrder) {
|
|
717
|
+
highestEventOrder = eventOrder;
|
|
718
|
+
}
|
|
719
|
+
return { laneOf, highestLane: highestEventOrder };
|
|
393
720
|
};
|
|
394
|
-
var lines_canvas_default = LinesCanvas;
|
|
395
|
-
|
|
396
|
-
// src/hooks/use-produce-content.tsx
|
|
397
|
-
var import_react17 = require("react");
|
|
398
|
-
var import_react18 = __toESM(require("react"));
|
|
399
721
|
|
|
400
|
-
// src/
|
|
401
|
-
var
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
height
|
|
722
|
+
// src/core/interactions.ts
|
|
723
|
+
var computeDropTimes = ({
|
|
724
|
+
pointerX,
|
|
725
|
+
cellWidth,
|
|
726
|
+
tick,
|
|
727
|
+
windowStart,
|
|
728
|
+
duration
|
|
408
729
|
}) => {
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
top,
|
|
420
|
-
minHeight: height
|
|
421
|
-
}
|
|
730
|
+
const closestCell = Math.round(pointerX / cellWidth);
|
|
731
|
+
const newPosition = cellWidth * closestCell;
|
|
732
|
+
const startTime = windowStart + newPosition * tick;
|
|
733
|
+
return { startTime, endTime: startTime + duration };
|
|
734
|
+
};
|
|
735
|
+
var computeResizeTimes = (event, deltaPx, tick, direction) => {
|
|
736
|
+
if (direction === "left") {
|
|
737
|
+
const startTime = Math.round(event.startTime + deltaPx * tick);
|
|
738
|
+
if (event.endTime - startTime > 0) {
|
|
739
|
+
return { startTime, endTime: event.endTime };
|
|
422
740
|
}
|
|
423
|
-
|
|
741
|
+
return null;
|
|
742
|
+
}
|
|
743
|
+
const endTime = Math.round(event.endTime + deltaPx * tick);
|
|
744
|
+
if (endTime - event.startTime > 0) {
|
|
745
|
+
return { startTime: event.startTime, endTime };
|
|
746
|
+
}
|
|
747
|
+
return null;
|
|
748
|
+
};
|
|
749
|
+
var canResizeEvent = (event, eventsResize) => {
|
|
750
|
+
var _a, _b, _c, _d;
|
|
751
|
+
return !((_a = event.props) == null ? void 0 : _a.isLocked) && (eventsResize && (((_b = event.props) == null ? void 0 : _b.isResizable) === true || ((_c = event.props) == null ? void 0 : _c.isResizable) === void 0) || !eventsResize && ((_d = event.props) == null ? void 0 : _d.isResizable) === true);
|
|
752
|
+
};
|
|
753
|
+
var stepCellWidth = (cellWidth, deltaY, tick) => {
|
|
754
|
+
const pixelsToCalculate = 900 / tick;
|
|
755
|
+
const next = deltaY > 0 ? cellWidth + pixelsToCalculate : cellWidth - pixelsToCalculate;
|
|
756
|
+
if (next < pixelsToCalculate || next > pixelsToCalculate * 12) {
|
|
757
|
+
return cellWidth;
|
|
758
|
+
}
|
|
759
|
+
return next;
|
|
424
760
|
};
|
|
425
|
-
var static_event_default = StaticEvent;
|
|
426
|
-
|
|
427
|
-
// src/components/row-content.tsx
|
|
428
|
-
var import_react13 = __toESM(require("react"));
|
|
429
761
|
|
|
430
|
-
//
|
|
431
|
-
var
|
|
432
|
-
var
|
|
433
|
-
var
|
|
434
|
-
var
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
"This object has been frozen and should not be mutated",
|
|
443
|
-
function(data) {
|
|
444
|
-
return "Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? " + data;
|
|
445
|
-
},
|
|
446
|
-
"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.",
|
|
447
|
-
"Immer forbids circular references",
|
|
448
|
-
"The first or second argument to `produce` must be a function",
|
|
449
|
-
"The third argument to `produce` must be a function or undefined",
|
|
450
|
-
"First argument to `createDraft` must be a plain object, an array, or an immerable object",
|
|
451
|
-
"First argument to `finishDraft` must be a draft returned by `createDraft`",
|
|
452
|
-
function(thing) {
|
|
453
|
-
return `'current' expects a draft, got: ${thing}`;
|
|
454
|
-
},
|
|
455
|
-
"Object.defineProperty() cannot be used on an Immer draft",
|
|
456
|
-
"Object.setPrototypeOf() cannot be used on an Immer draft",
|
|
457
|
-
"Immer only supports deleting array indices",
|
|
458
|
-
"Immer only supports setting array indices and the 'length' property",
|
|
459
|
-
function(thing) {
|
|
460
|
-
return `'original' expects a draft, got: ${thing}`;
|
|
461
|
-
}
|
|
462
|
-
// Note: if more errors are added, the errorOffset in Patches.ts should be increased
|
|
463
|
-
// See Patches.ts for additional errors
|
|
464
|
-
] : [];
|
|
465
|
-
function die(error, ...args) {
|
|
466
|
-
if (process.env.NODE_ENV !== "production") {
|
|
467
|
-
const e = errors[error];
|
|
468
|
-
const msg = typeof e === "function" ? e.apply(null, args) : e;
|
|
469
|
-
throw new Error(`[Immer] ${msg}`);
|
|
470
|
-
}
|
|
471
|
-
throw new Error(
|
|
472
|
-
`[Immer] minified error nr: ${error}. Full error at: https://bit.ly/3cXEKWf`
|
|
473
|
-
);
|
|
474
|
-
}
|
|
475
|
-
var getPrototypeOf = Object.getPrototypeOf;
|
|
476
|
-
function isDraft(value) {
|
|
477
|
-
return !!value && !!value[DRAFT_STATE];
|
|
478
|
-
}
|
|
479
|
-
function isDraftable(value) {
|
|
480
|
-
var _a;
|
|
481
|
-
if (!value)
|
|
482
|
-
return false;
|
|
483
|
-
return isPlainObject(value) || Array.isArray(value) || !!value[DRAFTABLE] || !!((_a = value.constructor) == null ? void 0 : _a[DRAFTABLE]) || isMap(value) || isSet(value);
|
|
484
|
-
}
|
|
485
|
-
var objectCtorString = Object.prototype.constructor.toString();
|
|
486
|
-
function isPlainObject(value) {
|
|
487
|
-
if (!value || typeof value !== "object")
|
|
488
|
-
return false;
|
|
489
|
-
const proto = getPrototypeOf(value);
|
|
490
|
-
if (proto === null) {
|
|
491
|
-
return true;
|
|
492
|
-
}
|
|
493
|
-
const Ctor = Object.hasOwnProperty.call(proto, "constructor") && proto.constructor;
|
|
494
|
-
if (Ctor === Object)
|
|
495
|
-
return true;
|
|
496
|
-
return typeof Ctor == "function" && Function.toString.call(Ctor) === objectCtorString;
|
|
497
|
-
}
|
|
498
|
-
function each(obj, iter) {
|
|
499
|
-
if (getArchtype(obj) === 0) {
|
|
500
|
-
Reflect.ownKeys(obj).forEach((key) => {
|
|
501
|
-
iter(key, obj[key], obj);
|
|
502
|
-
});
|
|
503
|
-
} else {
|
|
504
|
-
obj.forEach((entry, index) => iter(index, entry, obj));
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
function getArchtype(thing) {
|
|
508
|
-
const state = thing[DRAFT_STATE];
|
|
509
|
-
return state ? state.type_ : Array.isArray(thing) ? 1 : isMap(thing) ? 2 : isSet(thing) ? 3 : 0;
|
|
510
|
-
}
|
|
511
|
-
function has(thing, prop) {
|
|
512
|
-
return getArchtype(thing) === 2 ? thing.has(prop) : Object.prototype.hasOwnProperty.call(thing, prop);
|
|
513
|
-
}
|
|
514
|
-
function set(thing, propOrOldValue, value) {
|
|
515
|
-
const t = getArchtype(thing);
|
|
516
|
-
if (t === 2)
|
|
517
|
-
thing.set(propOrOldValue, value);
|
|
518
|
-
else if (t === 3) {
|
|
519
|
-
thing.add(value);
|
|
520
|
-
} else
|
|
521
|
-
thing[propOrOldValue] = value;
|
|
522
|
-
}
|
|
523
|
-
function is(x, y) {
|
|
524
|
-
if (x === y) {
|
|
525
|
-
return x !== 0 || 1 / x === 1 / y;
|
|
762
|
+
// src/canvas/draw-events.ts
|
|
763
|
+
var EVENT_RADIUS = 5;
|
|
764
|
+
var EVENT_TEXT_INSET = 13;
|
|
765
|
+
var HANDLE_INSET = 4;
|
|
766
|
+
var HANDLE_BAR_WIDTH = 3;
|
|
767
|
+
var HANDLE_BAR_GAP = 1;
|
|
768
|
+
var HANDLE_BAR_HEIGHT = 10;
|
|
769
|
+
var roundedRect = (ctx, x, y, width, height, radius) => {
|
|
770
|
+
const r = Math.min(radius, width / 2, height / 2);
|
|
771
|
+
ctx.beginPath();
|
|
772
|
+
if (typeof ctx.roundRect === "function") {
|
|
773
|
+
ctx.roundRect(x, y, width, height, r);
|
|
526
774
|
} else {
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
}
|
|
579
|
-
function freeze(obj, deep = false) {
|
|
580
|
-
if (isFrozen(obj) || isDraft(obj) || !isDraftable(obj))
|
|
581
|
-
return obj;
|
|
582
|
-
if (getArchtype(obj) > 1) {
|
|
583
|
-
obj.set = obj.add = obj.clear = obj.delete = dontMutateFrozenCollections;
|
|
584
|
-
}
|
|
585
|
-
Object.freeze(obj);
|
|
586
|
-
if (deep)
|
|
587
|
-
Object.entries(obj).forEach(([key, value]) => freeze(value, true));
|
|
588
|
-
return obj;
|
|
589
|
-
}
|
|
590
|
-
function dontMutateFrozenCollections() {
|
|
591
|
-
die(2);
|
|
592
|
-
}
|
|
593
|
-
function isFrozen(obj) {
|
|
594
|
-
return Object.isFrozen(obj);
|
|
595
|
-
}
|
|
596
|
-
var plugins = {};
|
|
597
|
-
function getPlugin(pluginKey) {
|
|
598
|
-
const plugin = plugins[pluginKey];
|
|
599
|
-
if (!plugin) {
|
|
600
|
-
die(0, pluginKey);
|
|
601
|
-
}
|
|
602
|
-
return plugin;
|
|
603
|
-
}
|
|
604
|
-
var currentScope;
|
|
605
|
-
function getCurrentScope() {
|
|
606
|
-
return currentScope;
|
|
607
|
-
}
|
|
608
|
-
function createScope(parent_, immer_) {
|
|
609
|
-
return {
|
|
610
|
-
drafts_: [],
|
|
611
|
-
parent_,
|
|
612
|
-
immer_,
|
|
613
|
-
// Whenever the modified draft contains a draft from another scope, we
|
|
614
|
-
// need to prevent auto-freezing so the unowned draft can be finalized.
|
|
615
|
-
canAutoFreeze_: true,
|
|
616
|
-
unfinalizedDrafts_: 0
|
|
617
|
-
};
|
|
618
|
-
}
|
|
619
|
-
function usePatchesInScope(scope, patchListener) {
|
|
620
|
-
if (patchListener) {
|
|
621
|
-
getPlugin("Patches");
|
|
622
|
-
scope.patches_ = [];
|
|
623
|
-
scope.inversePatches_ = [];
|
|
624
|
-
scope.patchListener_ = patchListener;
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
function revokeScope(scope) {
|
|
628
|
-
leaveScope(scope);
|
|
629
|
-
scope.drafts_.forEach(revokeDraft);
|
|
630
|
-
scope.drafts_ = null;
|
|
631
|
-
}
|
|
632
|
-
function leaveScope(scope) {
|
|
633
|
-
if (scope === currentScope) {
|
|
634
|
-
currentScope = scope.parent_;
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
function enterScope(immer2) {
|
|
638
|
-
return currentScope = createScope(currentScope, immer2);
|
|
639
|
-
}
|
|
640
|
-
function revokeDraft(draft) {
|
|
641
|
-
const state = draft[DRAFT_STATE];
|
|
642
|
-
if (state.type_ === 0 || state.type_ === 1)
|
|
643
|
-
state.revoke_();
|
|
644
|
-
else
|
|
645
|
-
state.revoked_ = true;
|
|
646
|
-
}
|
|
647
|
-
function processResult(result, scope) {
|
|
648
|
-
scope.unfinalizedDrafts_ = scope.drafts_.length;
|
|
649
|
-
const baseDraft = scope.drafts_[0];
|
|
650
|
-
const isReplaced = result !== void 0 && result !== baseDraft;
|
|
651
|
-
if (isReplaced) {
|
|
652
|
-
if (baseDraft[DRAFT_STATE].modified_) {
|
|
653
|
-
revokeScope(scope);
|
|
654
|
-
die(4);
|
|
655
|
-
}
|
|
656
|
-
if (isDraftable(result)) {
|
|
657
|
-
result = finalize(scope, result);
|
|
658
|
-
if (!scope.parent_)
|
|
659
|
-
maybeFreeze(scope, result);
|
|
660
|
-
}
|
|
661
|
-
if (scope.patches_) {
|
|
662
|
-
getPlugin("Patches").generateReplacementPatches_(
|
|
663
|
-
baseDraft[DRAFT_STATE].base_,
|
|
664
|
-
result,
|
|
665
|
-
scope.patches_,
|
|
666
|
-
scope.inversePatches_
|
|
775
|
+
ctx.moveTo(x + r, y);
|
|
776
|
+
ctx.arcTo(x + width, y, x + width, y + height, r);
|
|
777
|
+
ctx.arcTo(x + width, y + height, x, y + height, r);
|
|
778
|
+
ctx.arcTo(x, y + height, x, y, r);
|
|
779
|
+
ctx.arcTo(x, y, x + width, y, r);
|
|
780
|
+
ctx.closePath();
|
|
781
|
+
}
|
|
782
|
+
};
|
|
783
|
+
var drawRowDividers = (ctx, view, scene, animator) => {
|
|
784
|
+
const [windowStart, windowEnd] = view.windowTime;
|
|
785
|
+
const rowIds = scene.getRowIds();
|
|
786
|
+
ctx.strokeStyle = view.theme.gridColor;
|
|
787
|
+
ctx.lineWidth = 1;
|
|
788
|
+
ctx.beginPath();
|
|
789
|
+
let y = 0;
|
|
790
|
+
for (let i = 0; i < rowIds.length; i++) {
|
|
791
|
+
y += animator.rowHeight(
|
|
792
|
+
rowIds[i],
|
|
793
|
+
scene.getRowHeight(rowIds[i], windowStart, windowEnd)
|
|
794
|
+
);
|
|
795
|
+
if (i === rowIds.length - 1) break;
|
|
796
|
+
const screenY = y - view.scrollTop;
|
|
797
|
+
if (screenY < 0) continue;
|
|
798
|
+
if (screenY > view.height) break;
|
|
799
|
+
const crisp = Math.round(screenY) - 0.5;
|
|
800
|
+
ctx.moveTo(0, crisp);
|
|
801
|
+
ctx.lineTo(view.width, crisp);
|
|
802
|
+
}
|
|
803
|
+
ctx.stroke();
|
|
804
|
+
};
|
|
805
|
+
var drawResizeHandles = (ctx, rect, alpha, strokeColor) => {
|
|
806
|
+
ctx.save();
|
|
807
|
+
ctx.globalAlpha *= alpha;
|
|
808
|
+
ctx.strokeStyle = strokeColor;
|
|
809
|
+
ctx.lineWidth = 1;
|
|
810
|
+
const barY = rect.y + (rect.height - HANDLE_BAR_HEIGHT) / 2;
|
|
811
|
+
const xs = [
|
|
812
|
+
rect.x + HANDLE_INSET,
|
|
813
|
+
rect.x + HANDLE_INSET + HANDLE_BAR_WIDTH + HANDLE_BAR_GAP,
|
|
814
|
+
rect.x + rect.width - HANDLE_INSET - HANDLE_BAR_WIDTH,
|
|
815
|
+
rect.x + rect.width - HANDLE_INSET - HANDLE_BAR_WIDTH * 2 - HANDLE_BAR_GAP
|
|
816
|
+
];
|
|
817
|
+
for (const barX of xs) {
|
|
818
|
+
ctx.beginPath();
|
|
819
|
+
if (typeof ctx.roundRect === "function") {
|
|
820
|
+
ctx.roundRect(
|
|
821
|
+
barX + 0.5,
|
|
822
|
+
barY + 0.5,
|
|
823
|
+
HANDLE_BAR_WIDTH - 1,
|
|
824
|
+
HANDLE_BAR_HEIGHT - 1,
|
|
825
|
+
1.5
|
|
667
826
|
);
|
|
827
|
+
} else {
|
|
828
|
+
ctx.rect(barX + 0.5, barY + 0.5, HANDLE_BAR_WIDTH - 1, HANDLE_BAR_HEIGHT - 1);
|
|
668
829
|
}
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
830
|
+
ctx.stroke();
|
|
831
|
+
}
|
|
832
|
+
ctx.restore();
|
|
833
|
+
};
|
|
834
|
+
var defaultDrawEvent = (ctx, event, rect, view, font) => {
|
|
835
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
836
|
+
const theme = view.theme;
|
|
837
|
+
const style = (_a = event.props) == null ? void 0 : _a.style;
|
|
838
|
+
if ((style == null ? void 0 : style.opacity) !== void 0) ctx.globalAlpha *= style.opacity;
|
|
839
|
+
ctx.fillStyle = (_b = style == null ? void 0 : style.fill) != null ? _b : theme.eventFill;
|
|
840
|
+
ctx.strokeStyle = (_c = style == null ? void 0 : style.stroke) != null ? _c : theme.eventStroke;
|
|
841
|
+
ctx.lineWidth = (_d = style == null ? void 0 : style.strokeWidth) != null ? _d : 1;
|
|
842
|
+
roundedRect(
|
|
843
|
+
ctx,
|
|
844
|
+
rect.x + 0.5,
|
|
845
|
+
rect.y + 0.5,
|
|
846
|
+
rect.width - 1,
|
|
847
|
+
rect.height - 1,
|
|
848
|
+
(_e = style == null ? void 0 : style.borderRadius) != null ? _e : EVENT_RADIUS
|
|
849
|
+
);
|
|
850
|
+
ctx.fill();
|
|
851
|
+
ctx.stroke();
|
|
852
|
+
const label = (_f = event.props) == null ? void 0 : _f.label;
|
|
853
|
+
if (label && rect.width > EVENT_TEXT_INSET * 2) {
|
|
854
|
+
ctx.fillStyle = (_g = style == null ? void 0 : style.textColor) != null ? _g : theme.eventTextColor;
|
|
855
|
+
ctx.font = (_i = (_h = style == null ? void 0 : style.font) != null ? _h : theme.font) != null ? _i : font;
|
|
856
|
+
ctx.save();
|
|
857
|
+
ctx.beginPath();
|
|
858
|
+
ctx.rect(
|
|
859
|
+
rect.x + EVENT_TEXT_INSET,
|
|
860
|
+
rect.y,
|
|
861
|
+
rect.width - EVENT_TEXT_INSET * 2,
|
|
862
|
+
rect.height
|
|
686
863
|
);
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
}
|
|
706
|
-
each(
|
|
707
|
-
resultEach,
|
|
708
|
-
(key, childValue) => finalizeProperty(rootScope, state, result, key, childValue, path, isSet2)
|
|
864
|
+
ctx.clip();
|
|
865
|
+
ctx.fillText(label, rect.x + EVENT_TEXT_INSET, rect.y + rect.height / 2);
|
|
866
|
+
ctx.restore();
|
|
867
|
+
}
|
|
868
|
+
};
|
|
869
|
+
var drawEvents = (ctx, view, scene, font, animator) => {
|
|
870
|
+
var _a, _b, _c, _d, _e, _f;
|
|
871
|
+
if (view.tick === null) return;
|
|
872
|
+
const [windowStart, windowEnd] = view.windowTime;
|
|
873
|
+
const tick = view.tick;
|
|
874
|
+
ctx.font = (_a = view.theme.font) != null ? _a : font;
|
|
875
|
+
ctx.textBaseline = "middle";
|
|
876
|
+
ctx.textAlign = "left";
|
|
877
|
+
let rowTop = 0;
|
|
878
|
+
for (const rowId of scene.getRowIds()) {
|
|
879
|
+
const rowHeight = animator.rowHeight(
|
|
880
|
+
rowId,
|
|
881
|
+
scene.getRowHeight(rowId, windowStart, windowEnd)
|
|
709
882
|
);
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
883
|
+
const rowY = rowTop - view.scrollTop;
|
|
884
|
+
rowTop += rowHeight;
|
|
885
|
+
if (rowY + rowHeight < 0) continue;
|
|
886
|
+
if (rowY > view.height) break;
|
|
887
|
+
const lanes = scene.getLanes(rowId, windowStart, windowEnd);
|
|
888
|
+
for (const event of cullToWindow(
|
|
889
|
+
scene.getRowStaticEvents(rowId),
|
|
890
|
+
windowStart,
|
|
891
|
+
windowEnd
|
|
892
|
+
)) {
|
|
893
|
+
const x = timeToX(event.startTime, windowStart, tick);
|
|
894
|
+
const width = timeToWidth(event.startTime, event.endTime, tick);
|
|
895
|
+
ctx.fillStyle = view.theme.staticEventFill;
|
|
896
|
+
roundedRect(
|
|
897
|
+
ctx,
|
|
898
|
+
x,
|
|
899
|
+
rowY + LANE_TOP_OFFSET,
|
|
900
|
+
width,
|
|
901
|
+
staticEventHeight(lanes.highestLane),
|
|
902
|
+
EVENT_RADIUS
|
|
717
903
|
);
|
|
904
|
+
ctx.fill();
|
|
718
905
|
}
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
return;
|
|
740
|
-
}
|
|
741
|
-
finalize(rootScope, childValue);
|
|
742
|
-
if ((!parentState || !parentState.scope_.parent_) && typeof prop !== "symbol" && Object.prototype.propertyIsEnumerable.call(targetObject, prop))
|
|
743
|
-
maybeFreeze(rootScope, childValue);
|
|
744
|
-
}
|
|
745
|
-
}
|
|
746
|
-
function maybeFreeze(scope, value, deep = false) {
|
|
747
|
-
if (!scope.parent_ && scope.immer_.autoFreeze_ && scope.canAutoFreeze_) {
|
|
748
|
-
freeze(value, deep);
|
|
749
|
-
}
|
|
750
|
-
}
|
|
751
|
-
function createProxyProxy(base, parent) {
|
|
752
|
-
const isArray = Array.isArray(base);
|
|
753
|
-
const state = {
|
|
754
|
-
type_: isArray ? 1 : 0,
|
|
755
|
-
// Track which produce call this is associated with.
|
|
756
|
-
scope_: parent ? parent.scope_ : getCurrentScope(),
|
|
757
|
-
// True for both shallow and deep changes.
|
|
758
|
-
modified_: false,
|
|
759
|
-
// Used during finalization.
|
|
760
|
-
finalized_: false,
|
|
761
|
-
// Track which properties have been assigned (true) or deleted (false).
|
|
762
|
-
assigned_: {},
|
|
763
|
-
// The parent draft state.
|
|
764
|
-
parent_: parent,
|
|
765
|
-
// The base state.
|
|
766
|
-
base_: base,
|
|
767
|
-
// The base proxy.
|
|
768
|
-
draft_: null,
|
|
769
|
-
// set below
|
|
770
|
-
// The base copy with any updated values.
|
|
771
|
-
copy_: null,
|
|
772
|
-
// Called by the `produce` function.
|
|
773
|
-
revoke_: null,
|
|
774
|
-
isManual_: false
|
|
775
|
-
};
|
|
776
|
-
let target = state;
|
|
777
|
-
let traps = objectTraps;
|
|
778
|
-
if (isArray) {
|
|
779
|
-
target = [state];
|
|
780
|
-
traps = arrayTraps;
|
|
781
|
-
}
|
|
782
|
-
const { revoke, proxy } = Proxy.revocable(target, traps);
|
|
783
|
-
state.draft_ = proxy;
|
|
784
|
-
state.revoke_ = revoke;
|
|
785
|
-
return proxy;
|
|
786
|
-
}
|
|
787
|
-
var objectTraps = {
|
|
788
|
-
get(state, prop) {
|
|
789
|
-
if (prop === DRAFT_STATE)
|
|
790
|
-
return state;
|
|
791
|
-
const source = latest(state);
|
|
792
|
-
if (!has(source, prop)) {
|
|
793
|
-
return readPropFromProto(state, source, prop);
|
|
794
|
-
}
|
|
795
|
-
const value = source[prop];
|
|
796
|
-
if (state.finalized_ || !isDraftable(value)) {
|
|
797
|
-
return value;
|
|
798
|
-
}
|
|
799
|
-
if (value === peek(state.base_, prop)) {
|
|
800
|
-
prepareCopy(state);
|
|
801
|
-
return state.copy_[prop] = createProxy(value, state);
|
|
802
|
-
}
|
|
803
|
-
return value;
|
|
804
|
-
},
|
|
805
|
-
has(state, prop) {
|
|
806
|
-
return prop in latest(state);
|
|
807
|
-
},
|
|
808
|
-
ownKeys(state) {
|
|
809
|
-
return Reflect.ownKeys(latest(state));
|
|
810
|
-
},
|
|
811
|
-
set(state, prop, value) {
|
|
812
|
-
const desc = getDescriptorFromProto(latest(state), prop);
|
|
813
|
-
if (desc == null ? void 0 : desc.set) {
|
|
814
|
-
desc.set.call(state.draft_, value);
|
|
815
|
-
return true;
|
|
816
|
-
}
|
|
817
|
-
if (!state.modified_) {
|
|
818
|
-
const current2 = peek(latest(state), prop);
|
|
819
|
-
const currentState = current2 == null ? void 0 : current2[DRAFT_STATE];
|
|
820
|
-
if (currentState && currentState.base_ === value) {
|
|
821
|
-
state.copy_[prop] = value;
|
|
822
|
-
state.assigned_[prop] = false;
|
|
823
|
-
return true;
|
|
906
|
+
for (const event of cullToWindow(
|
|
907
|
+
scene.getRowEvents(rowId),
|
|
908
|
+
windowStart,
|
|
909
|
+
windowEnd
|
|
910
|
+
)) {
|
|
911
|
+
let x = timeToX(event.startTime, windowStart, tick);
|
|
912
|
+
let width = timeToWidth(event.startTime, event.endTime, tick);
|
|
913
|
+
const y = rowY + animator.eventTop(
|
|
914
|
+
event.id,
|
|
915
|
+
laneTop(lanes.laneOf.get(event.id))
|
|
916
|
+
);
|
|
917
|
+
const resize = view.resizePreview;
|
|
918
|
+
const resizing = resize !== null && resize.eventId === event.id;
|
|
919
|
+
if (resizing) {
|
|
920
|
+
if (resize.direction === "left") {
|
|
921
|
+
x += resize.deltaPx;
|
|
922
|
+
width -= resize.deltaPx;
|
|
923
|
+
} else {
|
|
924
|
+
width += resize.deltaPx;
|
|
925
|
+
}
|
|
824
926
|
}
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
927
|
+
const rect = { x, y, width, height: EVENT_BAR_HEIGHT };
|
|
928
|
+
const state = {
|
|
929
|
+
hovered: view.hoveredEventId === event.id,
|
|
930
|
+
dragging: view.draggedEventId === event.id,
|
|
931
|
+
resizing,
|
|
932
|
+
selected: false
|
|
933
|
+
};
|
|
934
|
+
ctx.save();
|
|
935
|
+
if (state.dragging) ctx.globalAlpha = 0.5;
|
|
936
|
+
const custom = (_c = (_b = event.props) == null ? void 0 : _b.drawEvent) != null ? _c : view.drawEvent;
|
|
937
|
+
const drawn = custom !== void 0 && custom(ctx, event, rect, state, view.theme) !== false;
|
|
938
|
+
if (!drawn) {
|
|
939
|
+
defaultDrawEvent(ctx, event, rect, view, font);
|
|
940
|
+
}
|
|
941
|
+
if (canResizeEvent(event, view.eventsResize)) {
|
|
942
|
+
const alpha = animator.handleAlpha(
|
|
943
|
+
event.id,
|
|
944
|
+
state.hovered || state.resizing ? 1 : 0
|
|
945
|
+
);
|
|
946
|
+
if (alpha > 0.01) {
|
|
947
|
+
drawResizeHandles(
|
|
948
|
+
ctx,
|
|
949
|
+
rect,
|
|
950
|
+
alpha,
|
|
951
|
+
(_f = (_e = (_d = event.props) == null ? void 0 : _d.style) == null ? void 0 : _e.stroke) != null ? _f : view.theme.eventStroke
|
|
952
|
+
);
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
ctx.restore();
|
|
848
956
|
}
|
|
849
|
-
return true;
|
|
850
|
-
},
|
|
851
|
-
// Note: We never coerce `desc.value` into an Immer draft, because we can't make
|
|
852
|
-
// the same guarantee in ES5 mode.
|
|
853
|
-
getOwnPropertyDescriptor(state, prop) {
|
|
854
|
-
const owner = latest(state);
|
|
855
|
-
const desc = Reflect.getOwnPropertyDescriptor(owner, prop);
|
|
856
|
-
if (!desc)
|
|
857
|
-
return desc;
|
|
858
|
-
return {
|
|
859
|
-
writable: true,
|
|
860
|
-
configurable: state.type_ !== 1 || prop !== "length",
|
|
861
|
-
enumerable: desc.enumerable,
|
|
862
|
-
value: owner[prop]
|
|
863
|
-
};
|
|
864
|
-
},
|
|
865
|
-
defineProperty() {
|
|
866
|
-
die(11);
|
|
867
|
-
},
|
|
868
|
-
getPrototypeOf(state) {
|
|
869
|
-
return getPrototypeOf(state.base_);
|
|
870
|
-
},
|
|
871
|
-
setPrototypeOf() {
|
|
872
|
-
die(12);
|
|
873
957
|
}
|
|
874
958
|
};
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
}
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
return
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
const
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
}
|
|
918
|
-
function markChanged(state) {
|
|
919
|
-
if (!state.modified_) {
|
|
920
|
-
state.modified_ = true;
|
|
921
|
-
if (state.parent_) {
|
|
922
|
-
markChanged(state.parent_);
|
|
959
|
+
|
|
960
|
+
// src/canvas/renderer.ts
|
|
961
|
+
var TimelineRenderer = class {
|
|
962
|
+
constructor(staticCanvas, dynamicCanvas, scene) {
|
|
963
|
+
this.staticCanvas = staticCanvas;
|
|
964
|
+
this.dynamicCanvas = dynamicCanvas;
|
|
965
|
+
this.scene = scene;
|
|
966
|
+
this.view = {
|
|
967
|
+
windowTime: [0, 0],
|
|
968
|
+
tick: null,
|
|
969
|
+
cellWidth: 0,
|
|
970
|
+
scrollTop: 0,
|
|
971
|
+
width: 0,
|
|
972
|
+
height: 0,
|
|
973
|
+
theme: DEFAULT_THEME,
|
|
974
|
+
drawEvent: void 0,
|
|
975
|
+
eventsResize: true,
|
|
976
|
+
hoveredEventId: null,
|
|
977
|
+
draggedEventId: null,
|
|
978
|
+
resizePreview: null
|
|
979
|
+
};
|
|
980
|
+
this.animator = new LayoutAnimator();
|
|
981
|
+
this.dpr = typeof window !== "undefined" ? window.devicePixelRatio : 1;
|
|
982
|
+
this.font = "16px sans-serif";
|
|
983
|
+
this.scheduler = new FrameScheduler((dirty) => this.drawFrame(dirty));
|
|
984
|
+
this.unsubscribeScene = scene.subscribe(() => this.invalidate("all"));
|
|
985
|
+
this.unwatchDpr = watchDpr((dpr) => {
|
|
986
|
+
this.dpr = dpr;
|
|
987
|
+
this.resizeCanvases();
|
|
988
|
+
this.invalidate("all");
|
|
989
|
+
});
|
|
990
|
+
}
|
|
991
|
+
getView() {
|
|
992
|
+
return this.view;
|
|
993
|
+
}
|
|
994
|
+
setView(partial) {
|
|
995
|
+
const sizeChanged = partial.width !== void 0 && partial.width !== this.view.width || partial.height !== void 0 && partial.height !== this.view.height;
|
|
996
|
+
this.view = __spreadValues(__spreadValues({}, this.view), partial);
|
|
997
|
+
if (sizeChanged) {
|
|
998
|
+
this.resizeCanvases();
|
|
999
|
+
this.invalidate("all");
|
|
1000
|
+
return;
|
|
923
1001
|
}
|
|
1002
|
+
this.invalidate("all");
|
|
924
1003
|
}
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
if (!state.copy_) {
|
|
928
|
-
state.copy_ = shallowCopy(
|
|
929
|
-
state.base_,
|
|
930
|
-
state.scope_.immer_.useStrictShallowCopy_
|
|
931
|
-
);
|
|
1004
|
+
invalidate(layer) {
|
|
1005
|
+
this.scheduler.invalidate(layer);
|
|
932
1006
|
}
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
this.autoFreeze_ = true;
|
|
937
|
-
this.useStrictShallowCopy_ = false;
|
|
938
|
-
this.produce = (base, recipe, patchListener) => {
|
|
939
|
-
if (typeof base === "function" && typeof recipe !== "function") {
|
|
940
|
-
const defaultBase = recipe;
|
|
941
|
-
recipe = base;
|
|
942
|
-
const self = this;
|
|
943
|
-
return function curriedProduce(base2 = defaultBase, ...args) {
|
|
944
|
-
return self.produce(base2, (draft) => recipe.call(this, draft, ...args));
|
|
945
|
-
};
|
|
946
|
-
}
|
|
947
|
-
if (typeof recipe !== "function")
|
|
948
|
-
die(6);
|
|
949
|
-
if (patchListener !== void 0 && typeof patchListener !== "function")
|
|
950
|
-
die(7);
|
|
951
|
-
let result;
|
|
952
|
-
if (isDraftable(base)) {
|
|
953
|
-
const scope = enterScope(this);
|
|
954
|
-
const proxy = createProxy(base, void 0);
|
|
955
|
-
let hasError = true;
|
|
956
|
-
try {
|
|
957
|
-
result = recipe(proxy);
|
|
958
|
-
hasError = false;
|
|
959
|
-
} finally {
|
|
960
|
-
if (hasError)
|
|
961
|
-
revokeScope(scope);
|
|
962
|
-
else
|
|
963
|
-
leaveScope(scope);
|
|
964
|
-
}
|
|
965
|
-
usePatchesInScope(scope, patchListener);
|
|
966
|
-
return processResult(result, scope);
|
|
967
|
-
} else if (!base || typeof base !== "object") {
|
|
968
|
-
result = recipe(base);
|
|
969
|
-
if (result === void 0)
|
|
970
|
-
result = base;
|
|
971
|
-
if (result === NOTHING)
|
|
972
|
-
result = void 0;
|
|
973
|
-
if (this.autoFreeze_)
|
|
974
|
-
freeze(result, true);
|
|
975
|
-
if (patchListener) {
|
|
976
|
-
const p = [];
|
|
977
|
-
const ip = [];
|
|
978
|
-
getPlugin("Patches").generateReplacementPatches_(base, result, p, ip);
|
|
979
|
-
patchListener(p, ip);
|
|
980
|
-
}
|
|
981
|
-
return result;
|
|
982
|
-
} else
|
|
983
|
-
die(1, base);
|
|
984
|
-
};
|
|
985
|
-
this.produceWithPatches = (base, recipe) => {
|
|
986
|
-
if (typeof base === "function") {
|
|
987
|
-
return (state, ...args) => this.produceWithPatches(state, (draft) => base(draft, ...args));
|
|
988
|
-
}
|
|
989
|
-
let patches, inversePatches;
|
|
990
|
-
const result = this.produce(base, recipe, (p, ip) => {
|
|
991
|
-
patches = p;
|
|
992
|
-
inversePatches = ip;
|
|
993
|
-
});
|
|
994
|
-
return [result, patches, inversePatches];
|
|
995
|
-
};
|
|
996
|
-
if (typeof (config == null ? void 0 : config.autoFreeze) === "boolean")
|
|
997
|
-
this.setAutoFreeze(config.autoFreeze);
|
|
998
|
-
if (typeof (config == null ? void 0 : config.useStrictShallowCopy) === "boolean")
|
|
999
|
-
this.setUseStrictShallowCopy(config.useStrictShallowCopy);
|
|
1000
|
-
}
|
|
1001
|
-
createDraft(base) {
|
|
1002
|
-
if (!isDraftable(base))
|
|
1003
|
-
die(8);
|
|
1004
|
-
if (isDraft(base))
|
|
1005
|
-
base = current(base);
|
|
1006
|
-
const scope = enterScope(this);
|
|
1007
|
-
const proxy = createProxy(base, void 0);
|
|
1008
|
-
proxy[DRAFT_STATE].isManual_ = true;
|
|
1009
|
-
leaveScope(scope);
|
|
1010
|
-
return proxy;
|
|
1011
|
-
}
|
|
1012
|
-
finishDraft(draft, patchListener) {
|
|
1013
|
-
const state = draft && draft[DRAFT_STATE];
|
|
1014
|
-
if (!state || !state.isManual_)
|
|
1015
|
-
die(9);
|
|
1016
|
-
const { scope_: scope } = state;
|
|
1017
|
-
usePatchesInScope(scope, patchListener);
|
|
1018
|
-
return processResult(void 0, scope);
|
|
1007
|
+
/** Force a synchronous draw of anything pending (tests, screenshots). */
|
|
1008
|
+
flush() {
|
|
1009
|
+
this.scheduler.flush();
|
|
1019
1010
|
}
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
*/
|
|
1025
|
-
setAutoFreeze(value) {
|
|
1026
|
-
this.autoFreeze_ = value;
|
|
1011
|
+
dispose() {
|
|
1012
|
+
this.scheduler.dispose();
|
|
1013
|
+
this.unsubscribeScene();
|
|
1014
|
+
this.unwatchDpr();
|
|
1027
1015
|
}
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
const
|
|
1040
|
-
if (
|
|
1041
|
-
|
|
1042
|
-
|
|
1016
|
+
resizeCanvases() {
|
|
1017
|
+
sizeCanvas(this.staticCanvas, this.view.width, this.view.height, this.dpr);
|
|
1018
|
+
sizeCanvas(this.dynamicCanvas, this.view.width, this.view.height, this.dpr);
|
|
1019
|
+
if (typeof getComputedStyle === "function") {
|
|
1020
|
+
this.font = getComputedStyle(this.dynamicCanvas).font || this.font;
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
drawFrame(dirty) {
|
|
1024
|
+
if (this.view.tick === null) return;
|
|
1025
|
+
this.animator.beginFrame(performance.now());
|
|
1026
|
+
if (dirty.static) {
|
|
1027
|
+
const ctx = this.staticCanvas.getContext("2d");
|
|
1028
|
+
if (ctx) {
|
|
1029
|
+
ctx.clearRect(0, 0, this.view.width, this.view.height);
|
|
1030
|
+
drawGridLines(ctx, {
|
|
1031
|
+
width: this.view.width,
|
|
1032
|
+
height: this.view.height,
|
|
1033
|
+
cellWidth: this.view.cellWidth,
|
|
1034
|
+
color: this.view.theme.gridColor
|
|
1035
|
+
});
|
|
1036
|
+
drawRowDividers(ctx, this.view, this.scene, this.animator);
|
|
1043
1037
|
}
|
|
1044
1038
|
}
|
|
1045
|
-
if (
|
|
1046
|
-
|
|
1039
|
+
if (dirty.dynamic) {
|
|
1040
|
+
const ctx = this.dynamicCanvas.getContext("2d");
|
|
1041
|
+
if (ctx) {
|
|
1042
|
+
ctx.clearRect(0, 0, this.view.width, this.view.height);
|
|
1043
|
+
drawEvents(ctx, this.view, this.scene, this.font, this.animator);
|
|
1044
|
+
}
|
|
1047
1045
|
}
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
return applyPatchesImpl(base, patches);
|
|
1046
|
+
if (this.animator.isAnimating()) {
|
|
1047
|
+
this.scheduler.invalidate("all");
|
|
1051
1048
|
}
|
|
1052
|
-
return this.produce(
|
|
1053
|
-
base,
|
|
1054
|
-
(draft) => applyPatchesImpl(draft, patches)
|
|
1055
|
-
);
|
|
1056
1049
|
}
|
|
1057
1050
|
};
|
|
1058
|
-
function createProxy(value, parent) {
|
|
1059
|
-
const draft = isMap(value) ? getPlugin("MapSet").proxyMap_(value, parent) : isSet(value) ? getPlugin("MapSet").proxySet_(value, parent) : createProxyProxy(value, parent);
|
|
1060
|
-
const scope = parent ? parent.scope_ : getCurrentScope();
|
|
1061
|
-
scope.drafts_.push(draft);
|
|
1062
|
-
return draft;
|
|
1063
|
-
}
|
|
1064
|
-
function current(value) {
|
|
1065
|
-
if (!isDraft(value))
|
|
1066
|
-
die(10, value);
|
|
1067
|
-
return currentImpl(value);
|
|
1068
|
-
}
|
|
1069
|
-
function currentImpl(value) {
|
|
1070
|
-
if (!isDraftable(value) || isFrozen(value))
|
|
1071
|
-
return value;
|
|
1072
|
-
const state = value[DRAFT_STATE];
|
|
1073
|
-
let copy;
|
|
1074
|
-
if (state) {
|
|
1075
|
-
if (!state.modified_)
|
|
1076
|
-
return state.base_;
|
|
1077
|
-
state.finalized_ = true;
|
|
1078
|
-
copy = shallowCopy(value, state.scope_.immer_.useStrictShallowCopy_);
|
|
1079
|
-
} else {
|
|
1080
|
-
copy = shallowCopy(value, true);
|
|
1081
|
-
}
|
|
1082
|
-
each(copy, (key, childValue) => {
|
|
1083
|
-
set(copy, key, currentImpl(childValue));
|
|
1084
|
-
});
|
|
1085
|
-
if (state) {
|
|
1086
|
-
state.finalized_ = false;
|
|
1087
|
-
}
|
|
1088
|
-
return copy;
|
|
1089
|
-
}
|
|
1090
|
-
var immer = new Immer2();
|
|
1091
|
-
var produce = immer.produce;
|
|
1092
|
-
var produceWithPatches = immer.produceWithPatches.bind(
|
|
1093
|
-
immer
|
|
1094
|
-
);
|
|
1095
|
-
var setAutoFreeze = immer.setAutoFreeze.bind(immer);
|
|
1096
|
-
var setUseStrictShallowCopy = immer.setUseStrictShallowCopy.bind(immer);
|
|
1097
|
-
var applyPatches = immer.applyPatches.bind(immer);
|
|
1098
|
-
var createDraft = immer.createDraft.bind(immer);
|
|
1099
|
-
var finishDraft = immer.finishDraft.bind(immer);
|
|
1100
1051
|
|
|
1101
|
-
// src/
|
|
1102
|
-
var
|
|
1103
|
-
var DragStartedContext = (0, import_react11.createContext)({
|
|
1104
|
-
dragStarted: false,
|
|
1105
|
-
setDragStarted: () => {
|
|
1106
|
-
}
|
|
1107
|
-
});
|
|
1052
|
+
// src/hooks/use-canvas-interactions.ts
|
|
1053
|
+
var import_react6 = require("react");
|
|
1108
1054
|
|
|
1109
|
-
// src/
|
|
1110
|
-
var
|
|
1111
|
-
var ExternalPropertiesContext = (0, import_react12.createContext)(
|
|
1112
|
-
{}
|
|
1113
|
-
);
|
|
1055
|
+
// src/core/types.ts
|
|
1056
|
+
var rectContains = (rect, x, y) => x >= rect.x && x <= rect.x + rect.width && y >= rect.y && y <= rect.y + rect.height;
|
|
1114
1057
|
|
|
1115
|
-
// src/
|
|
1116
|
-
var
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1058
|
+
// src/core/hit-test.ts
|
|
1059
|
+
var hitTest = (scene, view, x, y) => {
|
|
1060
|
+
const { windowStart, windowEnd, tick, scrollTop } = view;
|
|
1061
|
+
const yContent = y + scrollTop;
|
|
1062
|
+
let rowTop = 0;
|
|
1063
|
+
let rowId = null;
|
|
1064
|
+
for (const id of scene.getRowIds()) {
|
|
1065
|
+
const height = scene.getRowHeight(id, windowStart, windowEnd);
|
|
1066
|
+
if (yContent >= rowTop && yContent < rowTop + height) {
|
|
1067
|
+
rowId = id;
|
|
1068
|
+
break;
|
|
1123
1069
|
}
|
|
1124
|
-
|
|
1125
|
-
return 1;
|
|
1070
|
+
rowTop += height;
|
|
1126
1071
|
}
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
const { onDrop } = (0, import_react13.useContext)(ExternalPropertiesContext);
|
|
1135
|
-
const handleOnDrop = (0, import_react13.useCallback)(
|
|
1136
|
-
(event) => {
|
|
1137
|
-
event.preventDefault();
|
|
1138
|
-
const element = event.target;
|
|
1139
|
-
const { left } = element.getBoundingClientRect();
|
|
1140
|
-
const draggedEventId = event.dataTransfer.getData("eventId");
|
|
1141
|
-
const closestCell = Math.round((event.clientX - left) / cellWidth);
|
|
1142
|
-
const newPosition = cellWidth * closestCell;
|
|
1143
|
-
setEvents(
|
|
1144
|
-
produce((draft) => {
|
|
1145
|
-
const event2 = draft.find((event3) => event3.id === draggedEventId);
|
|
1146
|
-
if (event2 && tick) {
|
|
1147
|
-
const newStartTime = windowTime[0] + newPosition * tick;
|
|
1148
|
-
const eventDuration = event2.endTime - event2.startTime;
|
|
1149
|
-
const newEndTime = windowTime[0] + eventDuration + newPosition * tick;
|
|
1150
|
-
if (onDrop) {
|
|
1151
|
-
onDrop({
|
|
1152
|
-
eventId: event2.id,
|
|
1153
|
-
oldRowId: event2.rowId,
|
|
1154
|
-
newRowId: props.id,
|
|
1155
|
-
startTime: newStartTime,
|
|
1156
|
-
endTime: newEndTime
|
|
1157
|
-
});
|
|
1158
|
-
}
|
|
1159
|
-
event2.startTime = newStartTime;
|
|
1160
|
-
event2.endTime = newEndTime;
|
|
1161
|
-
event2.rowId = props.id;
|
|
1162
|
-
}
|
|
1163
|
-
draft.sort(sort_events_default);
|
|
1164
|
-
})
|
|
1165
|
-
);
|
|
1166
|
-
setDragStarted(false);
|
|
1167
|
-
},
|
|
1168
|
-
[setEvents, tick, windowTime, cellWidth]
|
|
1072
|
+
if (rowId === null) return null;
|
|
1073
|
+
const lanes = scene.getLanes(rowId, windowStart, windowEnd);
|
|
1074
|
+
const rowY = rowTop - scrollTop;
|
|
1075
|
+
const events = cullToWindow(
|
|
1076
|
+
scene.getRowEvents(rowId),
|
|
1077
|
+
windowStart,
|
|
1078
|
+
windowEnd
|
|
1169
1079
|
);
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1080
|
+
for (let i = events.length - 1; i >= 0; i--) {
|
|
1081
|
+
const event = events[i];
|
|
1082
|
+
const rect = {
|
|
1083
|
+
x: timeToX(event.startTime, windowStart, tick),
|
|
1084
|
+
y: rowY + laneTop(lanes.laneOf.get(event.id)),
|
|
1085
|
+
width: timeToWidth(event.startTime, event.endTime, tick),
|
|
1086
|
+
height: EVENT_BAR_HEIGHT
|
|
1087
|
+
};
|
|
1088
|
+
if (rectContains(rect, x, y)) {
|
|
1089
|
+
return { kind: "event", event, rowId, rect };
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
const statics = cullToWindow(
|
|
1093
|
+
scene.getRowStaticEvents(rowId),
|
|
1094
|
+
windowStart,
|
|
1095
|
+
windowEnd
|
|
1186
1096
|
);
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1097
|
+
for (let i = statics.length - 1; i >= 0; i--) {
|
|
1098
|
+
const event = statics[i];
|
|
1099
|
+
const rect = {
|
|
1100
|
+
x: timeToX(event.startTime, windowStart, tick),
|
|
1101
|
+
y: rowY + LANE_TOP_OFFSET,
|
|
1102
|
+
width: timeToWidth(event.startTime, event.endTime, tick),
|
|
1103
|
+
height: staticEventHeight(lanes.highestLane)
|
|
1104
|
+
};
|
|
1105
|
+
if (rectContains(rect, x, y)) {
|
|
1106
|
+
return { kind: "static", event, rowId, rect };
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
return null;
|
|
1197
1110
|
};
|
|
1198
|
-
var resize_icon_default = ResizeIcon;
|
|
1199
1111
|
|
|
1200
|
-
// src/
|
|
1201
|
-
var
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1112
|
+
// src/hooks/use-canvas-interactions.ts
|
|
1113
|
+
var DRAG_THRESHOLD_PX = 3;
|
|
1114
|
+
var RESIZE_HOT_ZONE_PX = 8;
|
|
1115
|
+
var lockCursor = (cursor) => {
|
|
1116
|
+
const style = document.createElement("style");
|
|
1117
|
+
style.id = "lock-cursor";
|
|
1118
|
+
style.innerHTML = `* { cursor: ${cursor} !important; }`;
|
|
1119
|
+
document.head.appendChild(style);
|
|
1120
|
+
};
|
|
1121
|
+
var unlockCursor = () => {
|
|
1122
|
+
var _a;
|
|
1123
|
+
(_a = document.getElementById("lock-cursor")) == null ? void 0 : _a.remove();
|
|
1124
|
+
};
|
|
1125
|
+
var useCanvasInteractions = ({
|
|
1126
|
+
scene,
|
|
1127
|
+
rendererRef,
|
|
1128
|
+
dynamicCanvasRef,
|
|
1129
|
+
bodyRef,
|
|
1130
|
+
ghostRef,
|
|
1131
|
+
eventPromptRef,
|
|
1132
|
+
setWindowTime,
|
|
1133
|
+
setCellWidth,
|
|
1134
|
+
onDrop,
|
|
1135
|
+
onResize,
|
|
1136
|
+
onEventClick,
|
|
1137
|
+
onEventHover,
|
|
1138
|
+
eventsResize,
|
|
1139
|
+
panZoom
|
|
1208
1140
|
}) => {
|
|
1209
|
-
|
|
1210
|
-
const
|
|
1211
|
-
const
|
|
1212
|
-
|
|
1141
|
+
const stateRef = (0, import_react6.useRef)({ mode: "idle" });
|
|
1142
|
+
const changeGridRef = (0, import_react6.useRef)(false);
|
|
1143
|
+
const panFrameRef = (0, import_react6.useRef)(null);
|
|
1144
|
+
const panPendingDxRef = (0, import_react6.useRef)(0);
|
|
1145
|
+
const hoveredRef = (0, import_react6.useRef)(null);
|
|
1146
|
+
const config = (0, import_react6.useMemo)(
|
|
1147
|
+
() => {
|
|
1148
|
+
var _a, _b, _c, _d;
|
|
1149
|
+
return {
|
|
1150
|
+
panOnDragBackground: (_a = panZoom == null ? void 0 : panZoom.panOnDragBackground) != null ? _a : true,
|
|
1151
|
+
ctrlWheelZoom: (_b = panZoom == null ? void 0 : panZoom.ctrlWheelZoom) != null ? _b : true,
|
|
1152
|
+
middleClickGranularity: (_c = panZoom == null ? void 0 : panZoom.middleClickGranularity) != null ? _c : true,
|
|
1153
|
+
zoomStepSeconds: (_d = panZoom == null ? void 0 : panZoom.zoomStepSeconds) != null ? _d : 900
|
|
1154
|
+
};
|
|
1155
|
+
},
|
|
1156
|
+
[panZoom]
|
|
1213
1157
|
);
|
|
1214
|
-
const
|
|
1215
|
-
|
|
1216
|
-
(
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
const
|
|
1221
|
-
|
|
1222
|
-
if (
|
|
1223
|
-
|
|
1158
|
+
const hidePrompt = (0, import_react6.useCallback)(() => {
|
|
1159
|
+
var _a;
|
|
1160
|
+
(_a = eventPromptRef.current) == null ? void 0 : _a.hide();
|
|
1161
|
+
}, [eventPromptRef]);
|
|
1162
|
+
const currentHit = (0, import_react6.useCallback)(
|
|
1163
|
+
(clientX, clientY) => {
|
|
1164
|
+
const canvas = dynamicCanvasRef.current;
|
|
1165
|
+
const renderer = rendererRef.current;
|
|
1166
|
+
if (!canvas || !renderer) return null;
|
|
1167
|
+
const view = renderer.getView();
|
|
1168
|
+
if (view.tick === null) return null;
|
|
1169
|
+
const rect = canvas.getBoundingClientRect();
|
|
1170
|
+
return hitTest(
|
|
1171
|
+
scene,
|
|
1172
|
+
{
|
|
1173
|
+
windowStart: view.windowTime[0],
|
|
1174
|
+
windowEnd: view.windowTime[1],
|
|
1175
|
+
tick: view.tick,
|
|
1176
|
+
scrollTop: view.scrollTop
|
|
1177
|
+
},
|
|
1178
|
+
clientX - rect.left,
|
|
1179
|
+
clientY - rect.top
|
|
1180
|
+
);
|
|
1181
|
+
},
|
|
1182
|
+
[scene, dynamicCanvasRef, rendererRef]
|
|
1183
|
+
);
|
|
1184
|
+
const resizeDirectionAt = (0, import_react6.useCallback)(
|
|
1185
|
+
(hit, clientX) => {
|
|
1186
|
+
if (hit.kind !== "event" || !canResizeEvent(hit.event, eventsResize)) {
|
|
1187
|
+
return null;
|
|
1224
1188
|
}
|
|
1189
|
+
const canvas = dynamicCanvasRef.current;
|
|
1190
|
+
if (!canvas) return null;
|
|
1191
|
+
const x = clientX - canvas.getBoundingClientRect().left;
|
|
1192
|
+
const zone = Math.min(RESIZE_HOT_ZONE_PX, hit.rect.width / 3);
|
|
1193
|
+
if (x <= hit.rect.x + zone) return "left";
|
|
1194
|
+
if (x >= hit.rect.x + hit.rect.width - zone) return "right";
|
|
1195
|
+
return null;
|
|
1225
1196
|
},
|
|
1226
|
-
[
|
|
1197
|
+
[dynamicCanvasRef, eventsResize]
|
|
1227
1198
|
);
|
|
1228
|
-
const
|
|
1229
|
-
(
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
const
|
|
1233
|
-
|
|
1199
|
+
const schedulePan = (0, import_react6.useCallback)(() => {
|
|
1200
|
+
if (panFrameRef.current !== null) return;
|
|
1201
|
+
panFrameRef.current = requestAnimationFrame(() => {
|
|
1202
|
+
panFrameRef.current = null;
|
|
1203
|
+
const renderer = rendererRef.current;
|
|
1204
|
+
const dx = panPendingDxRef.current;
|
|
1205
|
+
panPendingDxRef.current = 0;
|
|
1206
|
+
const tick = renderer == null ? void 0 : renderer.getView().tick;
|
|
1207
|
+
if (!tick || dx === 0) return;
|
|
1208
|
+
const dt = Math.round(dx * tick);
|
|
1209
|
+
if (dt === 0) {
|
|
1210
|
+
panPendingDxRef.current = dx;
|
|
1211
|
+
return;
|
|
1212
|
+
}
|
|
1213
|
+
setWindowTime((prev) => [prev[0] - dt, prev[1] - dt]);
|
|
1214
|
+
});
|
|
1215
|
+
}, [rendererRef, setWindowTime]);
|
|
1216
|
+
const updateGhost = (0, import_react6.useCallback)(
|
|
1217
|
+
(state, clientX, clientY) => {
|
|
1218
|
+
const ghost = ghostRef.current;
|
|
1219
|
+
if (!ghost) return;
|
|
1220
|
+
ghost.style.display = "flex";
|
|
1221
|
+
ghost.style.left = `${state.hit.rect.x + (clientX - state.startClientX)}px`;
|
|
1222
|
+
ghost.style.top = `${state.hit.rect.y + (clientY - state.startClientY)}px`;
|
|
1223
|
+
ghost.style.width = `${state.hit.rect.width}px`;
|
|
1234
1224
|
},
|
|
1235
|
-
[
|
|
1225
|
+
[ghostRef]
|
|
1236
1226
|
);
|
|
1237
|
-
const
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1227
|
+
const handlePointerDown = (0, import_react6.useCallback)(
|
|
1228
|
+
(pointerEvent) => {
|
|
1229
|
+
var _a;
|
|
1230
|
+
if (pointerEvent.button !== 0) return;
|
|
1231
|
+
const canvas = dynamicCanvasRef.current;
|
|
1232
|
+
if (!canvas) return;
|
|
1233
|
+
const hit = currentHit(pointerEvent.clientX, pointerEvent.clientY);
|
|
1234
|
+
if ((hit == null ? void 0 : hit.kind) === "event" && !((_a = hit.event.props) == null ? void 0 : _a.isLocked)) {
|
|
1235
|
+
const direction = resizeDirectionAt(hit, pointerEvent.clientX);
|
|
1236
|
+
if (direction) {
|
|
1237
|
+
stateRef.current = {
|
|
1238
|
+
mode: "resize",
|
|
1239
|
+
event: hit.event,
|
|
1240
|
+
direction,
|
|
1241
|
+
startClientX: pointerEvent.clientX,
|
|
1242
|
+
deltaPx: 0
|
|
1243
|
+
};
|
|
1244
|
+
lockCursor("e-resize");
|
|
1245
|
+
} else {
|
|
1246
|
+
stateRef.current = {
|
|
1247
|
+
mode: "drag",
|
|
1248
|
+
hit,
|
|
1249
|
+
startClientX: pointerEvent.clientX,
|
|
1250
|
+
startClientY: pointerEvent.clientY,
|
|
1251
|
+
active: false
|
|
1252
|
+
};
|
|
1253
|
+
}
|
|
1254
|
+
} else if (config.panOnDragBackground) {
|
|
1255
|
+
stateRef.current = { mode: "pan", lastClientX: pointerEvent.clientX };
|
|
1256
|
+
canvas.style.cursor = "grabbing";
|
|
1257
|
+
} else {
|
|
1258
|
+
return;
|
|
1259
|
+
}
|
|
1260
|
+
hidePrompt();
|
|
1261
|
+
canvas.setPointerCapture(pointerEvent.pointerId);
|
|
1249
1262
|
},
|
|
1250
|
-
[
|
|
1263
|
+
[currentHit, resizeDirectionAt, dynamicCanvasRef, hidePrompt, config]
|
|
1251
1264
|
);
|
|
1252
|
-
const
|
|
1253
|
-
(
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1265
|
+
const handleHover = (0, import_react6.useCallback)(
|
|
1266
|
+
(pointerEvent) => {
|
|
1267
|
+
var _a, _b, _c, _d;
|
|
1268
|
+
const canvas = dynamicCanvasRef.current;
|
|
1269
|
+
if (!canvas) return;
|
|
1270
|
+
const hit = currentHit(pointerEvent.clientX, pointerEvent.clientY);
|
|
1271
|
+
const prevHovered = hoveredRef.current;
|
|
1272
|
+
hoveredRef.current = hit;
|
|
1273
|
+
if ((hit == null ? void 0 : hit.kind) === "event") {
|
|
1274
|
+
if ((_a = hit.event.props) == null ? void 0 : _a.isLocked) {
|
|
1275
|
+
canvas.style.cursor = "not-allowed";
|
|
1276
|
+
} else if (resizeDirectionAt(hit, pointerEvent.clientX)) {
|
|
1277
|
+
canvas.style.cursor = "e-resize";
|
|
1278
|
+
} else {
|
|
1279
|
+
canvas.style.cursor = "pointer";
|
|
1280
|
+
}
|
|
1281
|
+
} else {
|
|
1282
|
+
canvas.style.cursor = "grab";
|
|
1283
|
+
}
|
|
1284
|
+
const hoveredId = (hit == null ? void 0 : hit.kind) === "event" ? hit.event.id : null;
|
|
1285
|
+
const prevId = (prevHovered == null ? void 0 : prevHovered.kind) === "event" ? prevHovered.event.id : null;
|
|
1286
|
+
if (hoveredId !== prevId) {
|
|
1287
|
+
(_b = rendererRef.current) == null ? void 0 : _b.setView({ hoveredEventId: hoveredId });
|
|
1288
|
+
if (onEventHover) {
|
|
1289
|
+
onEventHover({
|
|
1290
|
+
eventId: hoveredId,
|
|
1291
|
+
rowId: hoveredId !== null && hit ? hit.rowId : null
|
|
1292
|
+
});
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
const prompt = eventPromptRef.current;
|
|
1296
|
+
if (!prompt) return;
|
|
1297
|
+
if ((hit == null ? void 0 : hit.kind) === "event" && (((_c = hit.event.props) == null ? void 0 : _c.showPrompt) || ((_d = hit.event.props) == null ? void 0 : _d.showPrompt) === void 0)) {
|
|
1298
|
+
if (prevId !== hit.event.id) {
|
|
1299
|
+
const canvasRect = canvas.getBoundingClientRect();
|
|
1300
|
+
prompt.show(hit.event, {
|
|
1301
|
+
x: canvasRect.left + hit.rect.x,
|
|
1302
|
+
y: canvasRect.top + hit.rect.y,
|
|
1303
|
+
width: hit.rect.width,
|
|
1304
|
+
height: hit.rect.height
|
|
1305
|
+
});
|
|
1306
|
+
}
|
|
1307
|
+
} else {
|
|
1308
|
+
prompt.hide();
|
|
1263
1309
|
}
|
|
1264
|
-
setEvents(
|
|
1265
|
-
produce((draft) => {
|
|
1266
|
-
const event2 = draft.find((event3) => event3.id === eventData.id);
|
|
1267
|
-
if (event2 && tick) {
|
|
1268
|
-
if (resizeDirection === "left") {
|
|
1269
|
-
const newStartTime = Math.round(
|
|
1270
|
-
event2.startTime + resizeOffsetRef.current * tick
|
|
1271
|
-
);
|
|
1272
|
-
if (event2.endTime - newStartTime > 0) {
|
|
1273
|
-
event2.startTime = newStartTime;
|
|
1274
|
-
}
|
|
1275
|
-
} else {
|
|
1276
|
-
const newEndTime = Math.round(
|
|
1277
|
-
event2.endTime + resizeOffsetRef.current * tick
|
|
1278
|
-
);
|
|
1279
|
-
if (newEndTime - event2.startTime > 0) {
|
|
1280
|
-
event2.endTime = newEndTime;
|
|
1281
|
-
}
|
|
1282
|
-
}
|
|
1283
|
-
if (onResize) {
|
|
1284
|
-
onResize({
|
|
1285
|
-
eventId: event2.id,
|
|
1286
|
-
startTime: event2.startTime,
|
|
1287
|
-
endTime: event2.endTime
|
|
1288
|
-
});
|
|
1289
|
-
}
|
|
1290
|
-
}
|
|
1291
|
-
draft.sort(sort_events_default);
|
|
1292
|
-
resizeOffsetRef.current = 0;
|
|
1293
|
-
setResizeOffset(0);
|
|
1294
|
-
})
|
|
1295
|
-
);
|
|
1296
1310
|
},
|
|
1297
1311
|
[
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1312
|
+
currentHit,
|
|
1313
|
+
resizeDirectionAt,
|
|
1314
|
+
dynamicCanvasRef,
|
|
1315
|
+
eventPromptRef,
|
|
1316
|
+
rendererRef,
|
|
1317
|
+
onEventHover
|
|
1303
1318
|
]
|
|
1304
1319
|
);
|
|
1305
|
-
const
|
|
1306
|
-
(
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
style.innerHTML = "* { cursor: e-resize !important; }";
|
|
1313
|
-
document.head.appendChild(style);
|
|
1314
|
-
document.addEventListener("mousemove", handleDocumentOnMouseMoveResize);
|
|
1315
|
-
document.addEventListener(
|
|
1316
|
-
"mouseup",
|
|
1317
|
-
(event2) => handleDocumentOnMouseUp(event2, resizeDirection),
|
|
1318
|
-
{ once: true }
|
|
1319
|
-
);
|
|
1320
|
-
initialPositionForResizeRef.current = event.clientX;
|
|
1321
|
-
},
|
|
1322
|
-
[handleDocumentOnMouseMoveResize, handleDocumentOnMouseUp]
|
|
1323
|
-
);
|
|
1324
|
-
const handleOnMouseMove = (0, import_react15.useCallback)(
|
|
1325
|
-
(event) => {
|
|
1326
|
-
if (!resizeStarted) {
|
|
1327
|
-
event.stopPropagation();
|
|
1320
|
+
const handlePointerMove = (0, import_react6.useCallback)(
|
|
1321
|
+
(pointerEvent) => {
|
|
1322
|
+
var _a, _b;
|
|
1323
|
+
const state = stateRef.current;
|
|
1324
|
+
if (state.mode === "idle") {
|
|
1325
|
+
handleHover(pointerEvent);
|
|
1326
|
+
return;
|
|
1328
1327
|
}
|
|
1328
|
+
if (state.mode === "pan") {
|
|
1329
|
+
panPendingDxRef.current += pointerEvent.clientX - state.lastClientX;
|
|
1330
|
+
state.lastClientX = pointerEvent.clientX;
|
|
1331
|
+
schedulePan();
|
|
1332
|
+
return;
|
|
1333
|
+
}
|
|
1334
|
+
if (state.mode === "drag") {
|
|
1335
|
+
if (!state.active && Math.abs(pointerEvent.clientX - state.startClientX) + Math.abs(pointerEvent.clientY - state.startClientY) > DRAG_THRESHOLD_PX) {
|
|
1336
|
+
state.active = true;
|
|
1337
|
+
(_a = rendererRef.current) == null ? void 0 : _a.setView({ draggedEventId: state.hit.event.id });
|
|
1338
|
+
}
|
|
1339
|
+
if (state.active) {
|
|
1340
|
+
updateGhost(state, pointerEvent.clientX, pointerEvent.clientY);
|
|
1341
|
+
}
|
|
1342
|
+
return;
|
|
1343
|
+
}
|
|
1344
|
+
state.deltaPx = pointerEvent.clientX - state.startClientX;
|
|
1345
|
+
(_b = rendererRef.current) == null ? void 0 : _b.setView({
|
|
1346
|
+
resizePreview: {
|
|
1347
|
+
eventId: state.event.id,
|
|
1348
|
+
deltaPx: state.deltaPx,
|
|
1349
|
+
direction: state.direction
|
|
1350
|
+
}
|
|
1351
|
+
});
|
|
1329
1352
|
},
|
|
1330
|
-
[
|
|
1353
|
+
[handleHover, schedulePan, updateGhost, rendererRef]
|
|
1331
1354
|
);
|
|
1332
|
-
const
|
|
1333
|
-
(
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
if (
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1355
|
+
const commitDrop = (0, import_react6.useCallback)(
|
|
1356
|
+
(state, clientX, clientY) => {
|
|
1357
|
+
const canvas = dynamicCanvasRef.current;
|
|
1358
|
+
const renderer = rendererRef.current;
|
|
1359
|
+
if (!canvas || !renderer) return;
|
|
1360
|
+
const view = renderer.getView();
|
|
1361
|
+
if (view.tick === null || view.cellWidth <= 0) return;
|
|
1362
|
+
const canvasRect = canvas.getBoundingClientRect();
|
|
1363
|
+
const yContent = clientY - canvasRect.top + view.scrollTop;
|
|
1364
|
+
let rowTop = 0;
|
|
1365
|
+
let targetRowId = null;
|
|
1366
|
+
for (const id of scene.getRowIds()) {
|
|
1367
|
+
const height = scene.getRowHeight(
|
|
1368
|
+
id,
|
|
1369
|
+
view.windowTime[0],
|
|
1370
|
+
view.windowTime[1]
|
|
1371
|
+
);
|
|
1372
|
+
if (yContent >= rowTop && yContent < rowTop + height) {
|
|
1373
|
+
targetRowId = id;
|
|
1374
|
+
break;
|
|
1347
1375
|
}
|
|
1376
|
+
rowTop += height;
|
|
1348
1377
|
}
|
|
1378
|
+
if (targetRowId === null) return;
|
|
1379
|
+
const liveEvent = scene.getEvent(state.hit.event.id);
|
|
1380
|
+
if (!liveEvent) return;
|
|
1381
|
+
const { startTime, endTime } = computeDropTimes({
|
|
1382
|
+
pointerX: clientX - canvasRect.left,
|
|
1383
|
+
cellWidth: view.cellWidth,
|
|
1384
|
+
tick: view.tick,
|
|
1385
|
+
windowStart: view.windowTime[0],
|
|
1386
|
+
duration: liveEvent.endTime - liveEvent.startTime
|
|
1387
|
+
});
|
|
1388
|
+
if (onDrop) {
|
|
1389
|
+
onDrop({
|
|
1390
|
+
eventId: liveEvent.id,
|
|
1391
|
+
oldRowId: liveEvent.rowId,
|
|
1392
|
+
newRowId: targetRowId,
|
|
1393
|
+
startTime,
|
|
1394
|
+
endTime
|
|
1395
|
+
});
|
|
1396
|
+
}
|
|
1397
|
+
renderer.animator.snapEventTop(liveEvent.id);
|
|
1398
|
+
scene.applyPatches([
|
|
1399
|
+
{
|
|
1400
|
+
op: "update",
|
|
1401
|
+
id: liveEvent.id,
|
|
1402
|
+
changes: { startTime, endTime, rowId: targetRowId }
|
|
1403
|
+
}
|
|
1404
|
+
]);
|
|
1349
1405
|
},
|
|
1350
|
-
[
|
|
1406
|
+
[scene, dynamicCanvasRef, rendererRef, onDrop]
|
|
1351
1407
|
);
|
|
1352
|
-
const
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1408
|
+
const commitResize = (0, import_react6.useCallback)(
|
|
1409
|
+
(state) => {
|
|
1410
|
+
const renderer = rendererRef.current;
|
|
1411
|
+
const tick = renderer == null ? void 0 : renderer.getView().tick;
|
|
1412
|
+
renderer == null ? void 0 : renderer.setView({ resizePreview: null });
|
|
1413
|
+
unlockCursor();
|
|
1414
|
+
if (!tick) return;
|
|
1415
|
+
const liveEvent = scene.getEvent(state.event.id);
|
|
1416
|
+
if (!liveEvent) return;
|
|
1417
|
+
const next = computeResizeTimes(
|
|
1418
|
+
liveEvent,
|
|
1419
|
+
state.deltaPx,
|
|
1420
|
+
tick,
|
|
1421
|
+
state.direction
|
|
1422
|
+
);
|
|
1423
|
+
if (next) {
|
|
1424
|
+
scene.applyPatches([
|
|
1425
|
+
{ op: "update", id: liveEvent.id, changes: next }
|
|
1426
|
+
]);
|
|
1427
|
+
}
|
|
1428
|
+
if (onResize) {
|
|
1429
|
+
const committed = next != null ? next : {
|
|
1430
|
+
startTime: liveEvent.startTime,
|
|
1431
|
+
endTime: liveEvent.endTime
|
|
1432
|
+
};
|
|
1433
|
+
onResize(__spreadValues({ eventId: liveEvent.id }, committed));
|
|
1375
1434
|
}
|
|
1376
1435
|
},
|
|
1377
|
-
|
|
1378
|
-
"div",
|
|
1379
|
-
{
|
|
1380
|
-
className: "event-resize",
|
|
1381
|
-
style: resizeStarted ? { opacity: "100%" } : void 0,
|
|
1382
|
-
draggable: false,
|
|
1383
|
-
onMouseEnter: () => setDraggableEvent(false),
|
|
1384
|
-
onMouseLeave: () => setDraggableEvent(true),
|
|
1385
|
-
onMouseDown: (event) => handleOnMouseDownEventResizer(event, "left"),
|
|
1386
|
-
onMouseOver: (event) => event.stopPropagation()
|
|
1387
|
-
},
|
|
1388
|
-
/* @__PURE__ */ import_react15.default.createElement(resize_icon_default, null)
|
|
1389
|
-
),
|
|
1390
|
-
/* @__PURE__ */ import_react15.default.createElement("div", { className: "event-content", onMouseOver: handleOnMouseOver }, ((_h = eventData.props) == null ? void 0 : _h.content) ? eventData.props.content : null),
|
|
1391
|
-
!((_i = eventData.props) == null ? void 0 : _i.isLocked) && (eventsResize && (((_j = eventData.props) == null ? void 0 : _j.isResizable) === true || ((_k = eventData.props) == null ? void 0 : _k.isResizable) === void 0) || !eventsResize && ((_l = eventData.props) == null ? void 0 : _l.isResizable)) && /* @__PURE__ */ import_react15.default.createElement(
|
|
1392
|
-
"div",
|
|
1393
|
-
{
|
|
1394
|
-
className: "event-resize",
|
|
1395
|
-
style: resizeStarted ? { opacity: "100%" } : void 0,
|
|
1396
|
-
draggable: false,
|
|
1397
|
-
onMouseEnter: () => setDraggableEvent(false),
|
|
1398
|
-
onMouseLeave: () => setDraggableEvent(true),
|
|
1399
|
-
onMouseDown: (event) => handleOnMouseDownEventResizer(event, "right"),
|
|
1400
|
-
onMouseOver: (event) => event.stopPropagation()
|
|
1401
|
-
},
|
|
1402
|
-
/* @__PURE__ */ import_react15.default.createElement(resize_icon_default, null)
|
|
1403
|
-
)
|
|
1436
|
+
[scene, rendererRef, onResize]
|
|
1404
1437
|
);
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
}) => {
|
|
1414
|
-
const callback = (0, import_react16.useCallback)((entries) => {
|
|
1415
|
-
entries.forEach((entry) => {
|
|
1416
|
-
if (entry.isIntersecting) {
|
|
1417
|
-
entry.target.classList.remove("row-hidden");
|
|
1418
|
-
} else {
|
|
1419
|
-
entry.target.classList.add("row-hidden");
|
|
1438
|
+
const handlePointerUp = (0, import_react6.useCallback)(
|
|
1439
|
+
(pointerEvent) => {
|
|
1440
|
+
var _a;
|
|
1441
|
+
const canvas = dynamicCanvasRef.current;
|
|
1442
|
+
const state = stateRef.current;
|
|
1443
|
+
stateRef.current = { mode: "idle" };
|
|
1444
|
+
if (canvas == null ? void 0 : canvas.hasPointerCapture(pointerEvent.pointerId)) {
|
|
1445
|
+
canvas.releasePointerCapture(pointerEvent.pointerId);
|
|
1420
1446
|
}
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
// src/hooks/use-produce-content.tsx
|
|
1438
|
-
var useProduceContent = ({
|
|
1439
|
-
rows,
|
|
1440
|
-
windowTime,
|
|
1441
|
-
tick,
|
|
1442
|
-
events,
|
|
1443
|
-
staticEvents,
|
|
1444
|
-
cellWidth,
|
|
1445
|
-
setEvents,
|
|
1446
|
-
bodyRef
|
|
1447
|
-
}) => {
|
|
1448
|
-
const rowsHeightContext = (0, import_react17.useContext)(RowsHeightContext);
|
|
1449
|
-
const tempRowsHeightRef = (0, import_react17.useRef)(null);
|
|
1450
|
-
const rowsContentRef = (0, import_react17.useRef)([]);
|
|
1451
|
-
const [content, internalAllRowsHeight] = (0, import_react17.useMemo)(() => {
|
|
1452
|
-
let internalAllRowsHeight2 = 0;
|
|
1453
|
-
return [
|
|
1454
|
-
rows.map((row, i) => {
|
|
1455
|
-
let eventOrder = 0;
|
|
1456
|
-
let prevEvent = [];
|
|
1457
|
-
let highestEventOrder = 0;
|
|
1458
|
-
const rowEvents = tick ? events.filter((event) => event.rowId === row.id).map((event) => {
|
|
1459
|
-
if (event.endTime >= windowTime[0] && event.startTime <= windowTime[1]) {
|
|
1460
|
-
let tempEventOrder = 0;
|
|
1461
|
-
let assignEventOrder = true;
|
|
1462
|
-
for (let i2 = 0; i2 <= eventOrder; i2++) {
|
|
1463
|
-
if (prevEvent && prevEvent[i2] && prevEvent[i2].endTime > event.startTime) {
|
|
1464
|
-
tempEventOrder += 1;
|
|
1465
|
-
} else {
|
|
1466
|
-
if (eventOrder > highestEventOrder) {
|
|
1467
|
-
highestEventOrder = eventOrder;
|
|
1468
|
-
}
|
|
1469
|
-
eventOrder = 0;
|
|
1470
|
-
assignEventOrder = false;
|
|
1471
|
-
break;
|
|
1472
|
-
}
|
|
1447
|
+
if (canvas) canvas.style.cursor = "grab";
|
|
1448
|
+
if (state.mode === "drag" && state.active) {
|
|
1449
|
+
if (ghostRef.current) ghostRef.current.style.display = "none";
|
|
1450
|
+
(_a = rendererRef.current) == null ? void 0 : _a.setView({ draggedEventId: null });
|
|
1451
|
+
commitDrop(state, pointerEvent.clientX, pointerEvent.clientY);
|
|
1452
|
+
} else if (state.mode === "drag" && !state.active) {
|
|
1453
|
+
if (onEventClick) {
|
|
1454
|
+
onEventClick({
|
|
1455
|
+
eventId: state.hit.event.id,
|
|
1456
|
+
rowId: state.hit.rowId,
|
|
1457
|
+
nativeEvent: pointerEvent.nativeEvent,
|
|
1458
|
+
modifiers: {
|
|
1459
|
+
shift: pointerEvent.shiftKey,
|
|
1460
|
+
ctrl: pointerEvent.ctrlKey,
|
|
1461
|
+
meta: pointerEvent.metaKey,
|
|
1462
|
+
alt: pointerEvent.altKey
|
|
1473
1463
|
}
|
|
1474
|
-
|
|
1475
|
-
eventOrder = tempEventOrder;
|
|
1476
|
-
}
|
|
1477
|
-
prevEvent[tempEventOrder] = event;
|
|
1478
|
-
return /* @__PURE__ */ import_react18.default.createElement(
|
|
1479
|
-
event_default,
|
|
1480
|
-
{
|
|
1481
|
-
key: `event_${event.id}`,
|
|
1482
|
-
eventData: event,
|
|
1483
|
-
startPosition: (event.startTime - windowTime[0]) / tick,
|
|
1484
|
-
width: (event.endTime - event.startTime) / tick,
|
|
1485
|
-
top: 10 + 22 * tempEventOrder,
|
|
1486
|
-
setEvents,
|
|
1487
|
-
tick
|
|
1488
|
-
}
|
|
1489
|
-
);
|
|
1490
|
-
}
|
|
1491
|
-
}) : null;
|
|
1492
|
-
if (eventOrder > highestEventOrder) {
|
|
1493
|
-
highestEventOrder = eventOrder;
|
|
1494
|
-
}
|
|
1495
|
-
if (tempRowsHeightRef.current === null) {
|
|
1496
|
-
tempRowsHeightRef.current = {
|
|
1497
|
-
[row.id]: { minHeight: 40 + highestEventOrder * 22 }
|
|
1498
|
-
};
|
|
1499
|
-
} else {
|
|
1500
|
-
tempRowsHeightRef.current[row.id] = {
|
|
1501
|
-
minHeight: 40 + highestEventOrder * 22
|
|
1502
|
-
};
|
|
1464
|
+
});
|
|
1503
1465
|
}
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
id: row.id,
|
|
1524
|
-
ref: (el) => {
|
|
1525
|
-
if (rowsContentRef.current && rowsContentRef.current[i] && el) {
|
|
1526
|
-
rowsContentRef.current[i] = el;
|
|
1527
|
-
} else if (rowsContentRef.current && el) {
|
|
1528
|
-
rowsContentRef.current.push(el);
|
|
1529
|
-
}
|
|
1530
|
-
},
|
|
1531
|
-
setEvents,
|
|
1532
|
-
tick,
|
|
1533
|
-
windowTime,
|
|
1534
|
-
cellWidth
|
|
1535
|
-
},
|
|
1536
|
-
rowEvents,
|
|
1537
|
-
rowStaticEvents
|
|
1538
|
-
));
|
|
1539
|
-
}),
|
|
1540
|
-
internalAllRowsHeight2
|
|
1541
|
-
];
|
|
1542
|
-
}, [rows, events, tick, windowTime, cellWidth]);
|
|
1543
|
-
use_intersection_observer_default({
|
|
1544
|
-
rowsContentRef,
|
|
1545
|
-
bodyRef
|
|
1546
|
-
});
|
|
1547
|
-
(0, import_react17.useEffect)(() => {
|
|
1548
|
-
if (rowsHeightContext) {
|
|
1549
|
-
rowsHeightContext.setRowsHeight(tempRowsHeightRef.current);
|
|
1550
|
-
rowsHeightContext.setAllRowsHeight(internalAllRowsHeight);
|
|
1466
|
+
} else if (state.mode === "resize") {
|
|
1467
|
+
commitResize(state);
|
|
1468
|
+
}
|
|
1469
|
+
},
|
|
1470
|
+
[
|
|
1471
|
+
dynamicCanvasRef,
|
|
1472
|
+
ghostRef,
|
|
1473
|
+
rendererRef,
|
|
1474
|
+
commitDrop,
|
|
1475
|
+
commitResize,
|
|
1476
|
+
onEventClick
|
|
1477
|
+
]
|
|
1478
|
+
);
|
|
1479
|
+
const handlePointerLeave = (0, import_react6.useCallback)(() => {
|
|
1480
|
+
var _a, _b;
|
|
1481
|
+
if (stateRef.current.mode !== "idle") return;
|
|
1482
|
+
if (((_a = hoveredRef.current) == null ? void 0 : _a.kind) === "event") {
|
|
1483
|
+
(_b = rendererRef.current) == null ? void 0 : _b.setView({ hoveredEventId: null });
|
|
1484
|
+
if (onEventHover) onEventHover({ eventId: null, rowId: null });
|
|
1551
1485
|
}
|
|
1552
|
-
|
|
1553
|
-
|
|
1486
|
+
hoveredRef.current = null;
|
|
1487
|
+
if (dynamicCanvasRef.current) {
|
|
1488
|
+
dynamicCanvasRef.current.style.cursor = "";
|
|
1489
|
+
}
|
|
1490
|
+
hidePrompt();
|
|
1491
|
+
}, [dynamicCanvasRef, rendererRef, hidePrompt, onEventHover]);
|
|
1492
|
+
const handleAuxClick = (0, import_react6.useCallback)(
|
|
1493
|
+
(pointerEvent) => {
|
|
1494
|
+
pointerEvent.preventDefault();
|
|
1495
|
+
if (pointerEvent.button === 1 && config.middleClickGranularity) {
|
|
1496
|
+
changeGridRef.current = !changeGridRef.current;
|
|
1497
|
+
if (bodyRef.current) {
|
|
1498
|
+
bodyRef.current.style.overflowY = changeGridRef.current ? "hidden" : "auto";
|
|
1499
|
+
}
|
|
1500
|
+
}
|
|
1501
|
+
},
|
|
1502
|
+
[bodyRef, config]
|
|
1503
|
+
);
|
|
1504
|
+
(0, import_react6.useEffect)(() => {
|
|
1505
|
+
const canvas = dynamicCanvasRef.current;
|
|
1506
|
+
if (!canvas) return;
|
|
1507
|
+
const handleWheel = (wheelEvent) => {
|
|
1508
|
+
var _a;
|
|
1509
|
+
const viaCtrl = (wheelEvent.ctrlKey || wheelEvent.metaKey) && config.ctrlWheelZoom;
|
|
1510
|
+
if (!changeGridRef.current && !viaCtrl) return;
|
|
1511
|
+
wheelEvent.preventDefault();
|
|
1512
|
+
const tick = (_a = rendererRef.current) == null ? void 0 : _a.getView().tick;
|
|
1513
|
+
if (!tick) return;
|
|
1514
|
+
setCellWidth(
|
|
1515
|
+
(cellWidth) => stepCellWidth(
|
|
1516
|
+
cellWidth,
|
|
1517
|
+
wheelEvent.deltaY,
|
|
1518
|
+
tick * 900 / config.zoomStepSeconds
|
|
1519
|
+
)
|
|
1520
|
+
);
|
|
1521
|
+
};
|
|
1522
|
+
canvas.addEventListener("wheel", handleWheel, { passive: false });
|
|
1523
|
+
return () => canvas.removeEventListener("wheel", handleWheel);
|
|
1524
|
+
}, [dynamicCanvasRef, rendererRef, setCellWidth, config]);
|
|
1525
|
+
(0, import_react6.useEffect)(() => unlockCursor, []);
|
|
1526
|
+
return {
|
|
1527
|
+
handlePointerDown,
|
|
1528
|
+
handlePointerMove,
|
|
1529
|
+
handlePointerUp,
|
|
1530
|
+
handlePointerLeave,
|
|
1531
|
+
handleAuxClick
|
|
1532
|
+
};
|
|
1554
1533
|
};
|
|
1555
|
-
var
|
|
1534
|
+
var use_canvas_interactions_default = useCanvasInteractions;
|
|
1556
1535
|
|
|
1557
|
-
// src/components/
|
|
1558
|
-
var
|
|
1536
|
+
// src/components/canvas-board.tsx
|
|
1537
|
+
var CanvasBoard = (0, import_react7.forwardRef)(
|
|
1559
1538
|
({
|
|
1539
|
+
scene,
|
|
1560
1540
|
rows,
|
|
1561
|
-
events,
|
|
1562
|
-
staticEvents,
|
|
1563
|
-
setEvents,
|
|
1564
|
-
tick,
|
|
1565
1541
|
windowTime,
|
|
1542
|
+
tick,
|
|
1566
1543
|
cellWidth,
|
|
1544
|
+
theme,
|
|
1545
|
+
drawEvent,
|
|
1546
|
+
bodyRef,
|
|
1547
|
+
rendererRef,
|
|
1548
|
+
eventPromptRef,
|
|
1549
|
+
rowsHeaderClassName,
|
|
1567
1550
|
setWindowTime,
|
|
1568
|
-
contentWidth,
|
|
1569
1551
|
setCellWidth,
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
const
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
const { left } = element.getBoundingClientRect();
|
|
1612
|
-
startMovePosition.current = event.clientX - left;
|
|
1613
|
-
},
|
|
1614
|
-
[setMouseDown]
|
|
1615
|
-
);
|
|
1616
|
-
const handleOnMouseUp = (0, import_react19.useCallback)(() => {
|
|
1617
|
-
setMouseDown(false);
|
|
1618
|
-
}, [setMouseDown]);
|
|
1619
|
-
const handleOnMouseLeave = (0, import_react19.useCallback)(
|
|
1620
|
-
() => setMouseDown(false),
|
|
1621
|
-
[setMouseDown]
|
|
1622
|
-
);
|
|
1623
|
-
const content = use_produce_content_default({
|
|
1624
|
-
rows,
|
|
1552
|
+
onDrop,
|
|
1553
|
+
onResize,
|
|
1554
|
+
onEventClick,
|
|
1555
|
+
onEventHover,
|
|
1556
|
+
eventsResize,
|
|
1557
|
+
panZoom,
|
|
1558
|
+
animations
|
|
1559
|
+
}, contentRef) => {
|
|
1560
|
+
const staticCanvasRef = (0, import_react7.useRef)(null);
|
|
1561
|
+
const dynamicCanvasRef = (0, import_react7.useRef)(null);
|
|
1562
|
+
const ghostRef = (0, import_react7.useRef)(null);
|
|
1563
|
+
const [scrollTop, setScrollTop] = (0, import_react7.useState)(0);
|
|
1564
|
+
const [viewportHeight, setViewportHeight] = (0, import_react7.useState)(0);
|
|
1565
|
+
(0, import_react7.useEffect)(() => {
|
|
1566
|
+
if (!staticCanvasRef.current || !dynamicCanvasRef.current) return;
|
|
1567
|
+
const renderer = new TimelineRenderer(
|
|
1568
|
+
staticCanvasRef.current,
|
|
1569
|
+
dynamicCanvasRef.current,
|
|
1570
|
+
scene
|
|
1571
|
+
);
|
|
1572
|
+
rendererRef.current = renderer;
|
|
1573
|
+
return () => {
|
|
1574
|
+
renderer.dispose();
|
|
1575
|
+
rendererRef.current = null;
|
|
1576
|
+
};
|
|
1577
|
+
}, [scene, rendererRef]);
|
|
1578
|
+
(0, import_react7.useEffect)(() => {
|
|
1579
|
+
var _a, _b;
|
|
1580
|
+
(_a = rendererRef.current) == null ? void 0 : _a.animator.setDurations(
|
|
1581
|
+
animations.layoutMs,
|
|
1582
|
+
animations.fadeMs
|
|
1583
|
+
);
|
|
1584
|
+
(_b = rendererRef.current) == null ? void 0 : _b.setView({
|
|
1585
|
+
windowTime: [windowTime[0], windowTime[1]],
|
|
1586
|
+
tick,
|
|
1587
|
+
cellWidth,
|
|
1588
|
+
theme,
|
|
1589
|
+
drawEvent,
|
|
1590
|
+
eventsResize
|
|
1591
|
+
});
|
|
1592
|
+
}, [
|
|
1625
1593
|
windowTime,
|
|
1626
1594
|
tick,
|
|
1627
|
-
events,
|
|
1628
|
-
staticEvents,
|
|
1629
1595
|
cellWidth,
|
|
1630
|
-
|
|
1631
|
-
|
|
1596
|
+
theme,
|
|
1597
|
+
drawEvent,
|
|
1598
|
+
eventsResize,
|
|
1599
|
+
animations,
|
|
1600
|
+
rendererRef
|
|
1601
|
+
]);
|
|
1602
|
+
(0, import_react7.useEffect)(() => {
|
|
1603
|
+
const column = contentRef && "current" in contentRef ? contentRef.current : null;
|
|
1604
|
+
const body = bodyRef.current;
|
|
1605
|
+
if (!column || !body) return;
|
|
1606
|
+
const measure = () => {
|
|
1607
|
+
var _a;
|
|
1608
|
+
const height = Math.min(body.clientHeight, window.innerHeight);
|
|
1609
|
+
setViewportHeight(height);
|
|
1610
|
+
(_a = rendererRef.current) == null ? void 0 : _a.setView({
|
|
1611
|
+
width: column.getBoundingClientRect().width,
|
|
1612
|
+
height
|
|
1613
|
+
});
|
|
1614
|
+
};
|
|
1615
|
+
measure();
|
|
1616
|
+
const observer = new ResizeObserver(measure);
|
|
1617
|
+
observer.observe(column);
|
|
1618
|
+
observer.observe(body);
|
|
1619
|
+
return () => observer.disconnect();
|
|
1620
|
+
}, [bodyRef, contentRef, rendererRef]);
|
|
1621
|
+
(0, import_react7.useEffect)(() => {
|
|
1622
|
+
const body = bodyRef.current;
|
|
1623
|
+
if (!body) return;
|
|
1624
|
+
const handleScroll = () => {
|
|
1625
|
+
var _a;
|
|
1626
|
+
(_a = rendererRef.current) == null ? void 0 : _a.setView({ scrollTop: body.scrollTop });
|
|
1627
|
+
setScrollTop(body.scrollTop);
|
|
1628
|
+
};
|
|
1629
|
+
body.addEventListener("scroll", handleScroll, { passive: true });
|
|
1630
|
+
return () => body.removeEventListener("scroll", handleScroll);
|
|
1631
|
+
}, [bodyRef, rendererRef]);
|
|
1632
|
+
(0, import_react7.useSyncExternalStore)(
|
|
1633
|
+
(0, import_react7.useCallback)((listener) => scene.subscribe(listener), [scene]),
|
|
1634
|
+
() => scene.version
|
|
1635
|
+
);
|
|
1636
|
+
const {
|
|
1637
|
+
handlePointerDown,
|
|
1638
|
+
handlePointerMove,
|
|
1639
|
+
handlePointerUp,
|
|
1640
|
+
handlePointerLeave,
|
|
1641
|
+
handleAuxClick
|
|
1642
|
+
} = use_canvas_interactions_default({
|
|
1643
|
+
scene,
|
|
1644
|
+
rendererRef,
|
|
1645
|
+
dynamicCanvasRef,
|
|
1646
|
+
bodyRef,
|
|
1647
|
+
ghostRef,
|
|
1648
|
+
eventPromptRef,
|
|
1649
|
+
setWindowTime,
|
|
1650
|
+
setCellWidth,
|
|
1651
|
+
onDrop,
|
|
1652
|
+
onResize,
|
|
1653
|
+
onEventClick,
|
|
1654
|
+
onEventHover,
|
|
1655
|
+
eventsResize,
|
|
1656
|
+
panZoom
|
|
1632
1657
|
});
|
|
1633
|
-
const
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
if (event.button === 1) {
|
|
1637
|
-
setChangeGrid((prev) => !prev);
|
|
1638
|
-
}
|
|
1639
|
-
},
|
|
1640
|
-
[]
|
|
1658
|
+
const { offsetOf, totalHeight } = scene.getRowOffsets(
|
|
1659
|
+
windowTime[0],
|
|
1660
|
+
windowTime[1]
|
|
1641
1661
|
);
|
|
1642
|
-
const
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1662
|
+
const visibleHeaders = [];
|
|
1663
|
+
for (let i = 0; i < rows.length; i++) {
|
|
1664
|
+
const row = rows[i];
|
|
1665
|
+
const top = offsetOf.get(row.id);
|
|
1666
|
+
const height = scene.getRowHeight(row.id, windowTime[0], windowTime[1]);
|
|
1667
|
+
if (top + height < scrollTop) continue;
|
|
1668
|
+
if (top > scrollTop + viewportHeight) break;
|
|
1669
|
+
visibleHeaders.push(
|
|
1670
|
+
/* @__PURE__ */ import_react7.default.createElement(
|
|
1671
|
+
"div",
|
|
1672
|
+
{
|
|
1673
|
+
key: `row_header_${row.id}`,
|
|
1674
|
+
className: "row-header canvas-row-header",
|
|
1675
|
+
style: {
|
|
1676
|
+
top,
|
|
1677
|
+
height,
|
|
1678
|
+
borderBottom: i === rows.length - 1 ? "none" : "1px solid yellow",
|
|
1679
|
+
// keeps the DOM header in step with the canvas layout tween
|
|
1680
|
+
transition: animations.layoutMs > 0 ? `top ${animations.layoutMs}ms ease-in-out, height ${animations.layoutMs}ms ease-in-out` : "none"
|
|
1650
1681
|
}
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
(
|
|
1658
|
-
|
|
1659
|
-
|
|
1682
|
+
},
|
|
1683
|
+
row.name
|
|
1684
|
+
)
|
|
1685
|
+
);
|
|
1686
|
+
}
|
|
1687
|
+
const headerClassNames = rowsHeaderClassName ? `rows-header-wrapper canvas-rows-header ${rowsHeaderClassName}` : "rows-header-wrapper canvas-rows-header";
|
|
1688
|
+
return /* @__PURE__ */ import_react7.default.createElement(import_react7.default.Fragment, null, /* @__PURE__ */ import_react7.default.createElement("div", { className: headerClassNames, style: { height: totalHeight } }, visibleHeaders), /* @__PURE__ */ import_react7.default.createElement("div", { className: "canvas-content-column", ref: contentRef }, /* @__PURE__ */ import_react7.default.createElement("div", { className: "canvas-sticky" }, /* @__PURE__ */ import_react7.default.createElement("canvas", { ref: staticCanvasRef }), /* @__PURE__ */ import_react7.default.createElement(
|
|
1689
|
+
"canvas",
|
|
1690
|
+
{
|
|
1691
|
+
ref: dynamicCanvasRef,
|
|
1692
|
+
onPointerDown: handlePointerDown,
|
|
1693
|
+
onPointerMove: handlePointerMove,
|
|
1694
|
+
onPointerUp: handlePointerUp,
|
|
1695
|
+
onPointerLeave: handlePointerLeave,
|
|
1696
|
+
onAuxClick: handleAuxClick
|
|
1660
1697
|
}
|
|
1661
|
-
},
|
|
1662
|
-
return /* @__PURE__ */ import_react19.default.createElement(
|
|
1698
|
+
), /* @__PURE__ */ import_react7.default.createElement("div", { ref: ghostRef, className: "event canvas-drag-ghost" })), /* @__PURE__ */ import_react7.default.createElement(
|
|
1663
1699
|
"div",
|
|
1664
1700
|
{
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
onMouseUp: handleOnMouseUp,
|
|
1670
|
-
onMouseMove: handleOnMouseMove,
|
|
1671
|
-
onMouseLeave: handleOnMouseLeave,
|
|
1672
|
-
onAuxClick: handleAuxClick,
|
|
1673
|
-
onWheel: handleOnWheel,
|
|
1674
|
-
style: {
|
|
1675
|
-
cursor: mouseDown ? "grabbing" : "grab",
|
|
1676
|
-
height: rowsHeightContext == null ? void 0 : rowsHeightContext.allRowsHeight
|
|
1677
|
-
}
|
|
1678
|
-
},
|
|
1679
|
-
/* @__PURE__ */ import_react19.default.createElement(
|
|
1680
|
-
lines_canvas_default,
|
|
1681
|
-
{
|
|
1682
|
-
contentWidth,
|
|
1683
|
-
cellWidth,
|
|
1684
|
-
lineClassName
|
|
1685
|
-
}
|
|
1686
|
-
),
|
|
1687
|
-
content
|
|
1688
|
-
);
|
|
1701
|
+
className: "canvas-scroll-spacer",
|
|
1702
|
+
style: { height: totalHeight }
|
|
1703
|
+
}
|
|
1704
|
+
)));
|
|
1689
1705
|
}
|
|
1690
1706
|
);
|
|
1691
|
-
var
|
|
1707
|
+
var canvas_board_default = CanvasBoard;
|
|
1692
1708
|
|
|
1693
|
-
// src/
|
|
1694
|
-
var
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
return new ResizeObserver((entries) => {
|
|
1704
|
-
var _a;
|
|
1705
|
-
for (const entry of entries) {
|
|
1706
|
-
const width = (_a = entry.borderBoxSize) == null ? void 0 : _a[0].inlineSize;
|
|
1707
|
-
if (typeof width === "number" && width !== prevWidthRef.current) {
|
|
1708
|
-
prevWidthRef.current = width;
|
|
1709
|
-
const windowDuration = windowTime[1] - windowTime[0];
|
|
1710
|
-
const numberOfHourBlocks = windowDuration / 3600;
|
|
1711
|
-
setTick(windowDuration / entry.contentRect.width);
|
|
1712
|
-
setCellWidth(entry.contentRect.width / numberOfHourBlocks);
|
|
1713
|
-
}
|
|
1714
|
-
}
|
|
1715
|
-
});
|
|
1716
|
-
}, [windowTime]);
|
|
1717
|
-
(0, import_react20.useEffect)(() => {
|
|
1718
|
-
if (contentRef.current) {
|
|
1719
|
-
resizeObserver.observe(contentRef.current, { box: "border-box" });
|
|
1709
|
+
// src/core/scene.ts
|
|
1710
|
+
var binaryInsertIndex = (events, event) => {
|
|
1711
|
+
let lo = 0;
|
|
1712
|
+
let hi = events.length;
|
|
1713
|
+
while (lo < hi) {
|
|
1714
|
+
const mid = lo + hi >> 1;
|
|
1715
|
+
if (sort_events_default(events[mid], event) < 0) {
|
|
1716
|
+
lo = mid + 1;
|
|
1717
|
+
} else {
|
|
1718
|
+
hi = mid;
|
|
1720
1719
|
}
|
|
1721
|
-
|
|
1722
|
-
|
|
1720
|
+
}
|
|
1721
|
+
return lo;
|
|
1723
1722
|
};
|
|
1724
|
-
var
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
}
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1723
|
+
var SceneStore = class {
|
|
1724
|
+
constructor() {
|
|
1725
|
+
this.rowIndexes = /* @__PURE__ */ new Map();
|
|
1726
|
+
this.rowOrder = [];
|
|
1727
|
+
this.eventRow = /* @__PURE__ */ new Map();
|
|
1728
|
+
this.listeners = /* @__PURE__ */ new Set();
|
|
1729
|
+
this.version = 0;
|
|
1730
|
+
}
|
|
1731
|
+
setRows(rows) {
|
|
1732
|
+
const next = /* @__PURE__ */ new Map();
|
|
1733
|
+
for (const row of rows) {
|
|
1734
|
+
const existing = this.rowIndexes.get(row.id);
|
|
1735
|
+
next.set(
|
|
1736
|
+
row.id,
|
|
1737
|
+
existing ? __spreadProps(__spreadValues({}, existing), { row }) : {
|
|
1738
|
+
row,
|
|
1739
|
+
events: [],
|
|
1740
|
+
staticEvents: [],
|
|
1741
|
+
lanesDirty: true,
|
|
1742
|
+
lanes: null,
|
|
1743
|
+
laneWindowStart: NaN,
|
|
1744
|
+
laneWindowEnd: NaN
|
|
1745
|
+
}
|
|
1746
|
+
);
|
|
1747
|
+
}
|
|
1748
|
+
for (const [id, rowId] of this.eventRow) {
|
|
1749
|
+
if (!next.has(rowId)) this.eventRow.delete(id);
|
|
1750
|
+
}
|
|
1751
|
+
this.rowIndexes = next;
|
|
1752
|
+
this.rowOrder = rows.map((row) => row.id);
|
|
1753
|
+
this.bump();
|
|
1754
|
+
}
|
|
1755
|
+
setEvents(events) {
|
|
1756
|
+
for (const index of this.rowIndexes.values()) {
|
|
1757
|
+
index.events = [];
|
|
1758
|
+
index.lanesDirty = true;
|
|
1759
|
+
}
|
|
1760
|
+
this.eventRow.clear();
|
|
1761
|
+
for (const event of events) {
|
|
1762
|
+
const index = this.rowIndexes.get(event.rowId);
|
|
1763
|
+
if (!index) continue;
|
|
1764
|
+
index.events.push(event);
|
|
1765
|
+
this.eventRow.set(event.id, event.rowId);
|
|
1766
|
+
}
|
|
1767
|
+
for (const index of this.rowIndexes.values()) {
|
|
1768
|
+
index.events.sort(sort_events_default);
|
|
1769
|
+
}
|
|
1770
|
+
this.bump();
|
|
1771
|
+
}
|
|
1772
|
+
setStaticEvents(events) {
|
|
1773
|
+
for (const index of this.rowIndexes.values()) {
|
|
1774
|
+
index.staticEvents = [];
|
|
1775
|
+
}
|
|
1776
|
+
for (const event of events) {
|
|
1777
|
+
const index = this.rowIndexes.get(event.rowId);
|
|
1778
|
+
if (!index) continue;
|
|
1779
|
+
index.staticEvents.push(event);
|
|
1780
|
+
}
|
|
1781
|
+
for (const index of this.rowIndexes.values()) {
|
|
1782
|
+
index.staticEvents.sort(sort_events_default);
|
|
1783
|
+
}
|
|
1784
|
+
this.bump();
|
|
1785
|
+
}
|
|
1786
|
+
applyPatches(patches) {
|
|
1787
|
+
for (const patch of patches) {
|
|
1788
|
+
if (patch.op === "upsert") {
|
|
1789
|
+
this.remove(patch.event.id);
|
|
1790
|
+
this.insert(patch.event);
|
|
1791
|
+
} else if (patch.op === "update") {
|
|
1792
|
+
const existing = this.getEvent(patch.id);
|
|
1793
|
+
if (!existing) continue;
|
|
1794
|
+
this.remove(patch.id);
|
|
1795
|
+
this.insert(__spreadProps(__spreadValues(__spreadValues({}, existing), patch.changes), { id: patch.id }));
|
|
1796
|
+
} else {
|
|
1797
|
+
this.remove(patch.id);
|
|
1741
1798
|
}
|
|
1742
|
-
const intervalId = setInterval(() => {
|
|
1743
|
-
setCurrentTime((/* @__PURE__ */ new Date()).getTime() / 1e3);
|
|
1744
|
-
}, tick * 1e3);
|
|
1745
|
-
intervalIdRef.current = intervalId;
|
|
1746
1799
|
}
|
|
1747
|
-
|
|
1748
|
-
|
|
1800
|
+
this.bump();
|
|
1801
|
+
}
|
|
1802
|
+
getEvent(id) {
|
|
1803
|
+
var _a;
|
|
1804
|
+
const rowId = this.eventRow.get(id);
|
|
1805
|
+
if (rowId === void 0) return void 0;
|
|
1806
|
+
return (_a = this.rowIndexes.get(rowId)) == null ? void 0 : _a.events.find((event) => event.id === id);
|
|
1807
|
+
}
|
|
1808
|
+
getRowIds() {
|
|
1809
|
+
return this.rowOrder;
|
|
1810
|
+
}
|
|
1811
|
+
getRow(rowId) {
|
|
1812
|
+
var _a;
|
|
1813
|
+
return (_a = this.rowIndexes.get(rowId)) == null ? void 0 : _a.row;
|
|
1814
|
+
}
|
|
1815
|
+
getRowEvents(rowId) {
|
|
1816
|
+
var _a, _b;
|
|
1817
|
+
return (_b = (_a = this.rowIndexes.get(rowId)) == null ? void 0 : _a.events) != null ? _b : [];
|
|
1818
|
+
}
|
|
1819
|
+
getRowStaticEvents(rowId) {
|
|
1820
|
+
var _a, _b;
|
|
1821
|
+
return (_b = (_a = this.rowIndexes.get(rowId)) == null ? void 0 : _a.staticEvents) != null ? _b : [];
|
|
1822
|
+
}
|
|
1823
|
+
getLanes(rowId, windowStart, windowEnd) {
|
|
1824
|
+
const index = this.rowIndexes.get(rowId);
|
|
1825
|
+
if (!index) return { laneOf: /* @__PURE__ */ new Map(), highestLane: 0 };
|
|
1826
|
+
if (index.lanesDirty || index.lanes === null || index.laneWindowStart !== windowStart || index.laneWindowEnd !== windowEnd) {
|
|
1827
|
+
index.lanes = assignLanes(index.events, windowStart, windowEnd);
|
|
1828
|
+
index.laneWindowStart = windowStart;
|
|
1829
|
+
index.laneWindowEnd = windowEnd;
|
|
1830
|
+
index.lanesDirty = false;
|
|
1831
|
+
}
|
|
1832
|
+
return index.lanes;
|
|
1833
|
+
}
|
|
1834
|
+
getRowHeight(rowId, windowStart, windowEnd) {
|
|
1835
|
+
return rowMinHeight(this.getLanes(rowId, windowStart, windowEnd).highestLane);
|
|
1836
|
+
}
|
|
1837
|
+
/**
|
|
1838
|
+
* y offset of each row's top edge (content coordinates, before scroll) plus
|
|
1839
|
+
* the total content height — drives both drawing and the scroll spacer.
|
|
1840
|
+
*/
|
|
1841
|
+
getRowOffsets(windowStart, windowEnd) {
|
|
1842
|
+
const offsetOf = /* @__PURE__ */ new Map();
|
|
1843
|
+
let y = 0;
|
|
1844
|
+
for (const rowId of this.rowOrder) {
|
|
1845
|
+
offsetOf.set(rowId, y);
|
|
1846
|
+
y += this.getRowHeight(rowId, windowStart, windowEnd);
|
|
1847
|
+
}
|
|
1848
|
+
return { offsetOf, totalHeight: y };
|
|
1849
|
+
}
|
|
1850
|
+
subscribe(listener) {
|
|
1851
|
+
this.listeners.add(listener);
|
|
1852
|
+
return () => this.listeners.delete(listener);
|
|
1853
|
+
}
|
|
1854
|
+
insert(event) {
|
|
1855
|
+
const index = this.rowIndexes.get(event.rowId);
|
|
1856
|
+
if (!index) return;
|
|
1857
|
+
index.events.splice(binaryInsertIndex(index.events, event), 0, event);
|
|
1858
|
+
index.lanesDirty = true;
|
|
1859
|
+
this.eventRow.set(event.id, event.rowId);
|
|
1860
|
+
}
|
|
1861
|
+
remove(id) {
|
|
1862
|
+
const rowId = this.eventRow.get(id);
|
|
1863
|
+
if (rowId === void 0) return;
|
|
1864
|
+
const index = this.rowIndexes.get(rowId);
|
|
1865
|
+
if (index) {
|
|
1866
|
+
const at = index.events.findIndex((event) => event.id === id);
|
|
1867
|
+
if (at !== -1) index.events.splice(at, 1);
|
|
1868
|
+
index.lanesDirty = true;
|
|
1869
|
+
}
|
|
1870
|
+
this.eventRow.delete(id);
|
|
1871
|
+
}
|
|
1872
|
+
bump() {
|
|
1873
|
+
this.version++;
|
|
1874
|
+
for (const listener of this.listeners) listener();
|
|
1875
|
+
}
|
|
1749
1876
|
};
|
|
1750
|
-
var rt_indicator_default = RTIndicator;
|
|
1751
1877
|
|
|
1752
|
-
// src/
|
|
1753
|
-
var
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1878
|
+
// src/timeline.tsx
|
|
1879
|
+
var Timeline = (0, import_react8.forwardRef)(
|
|
1880
|
+
({
|
|
1881
|
+
rows,
|
|
1882
|
+
events,
|
|
1883
|
+
staticEvents,
|
|
1884
|
+
onDrop,
|
|
1885
|
+
onResize,
|
|
1886
|
+
onEventClick,
|
|
1887
|
+
onEventHover,
|
|
1888
|
+
startDate,
|
|
1889
|
+
endDate,
|
|
1890
|
+
theme,
|
|
1891
|
+
drawEvent,
|
|
1892
|
+
additionalClassNames,
|
|
1893
|
+
showRTIndicator = true,
|
|
1894
|
+
eventsResize = true,
|
|
1895
|
+
eventPromptTemplate,
|
|
1896
|
+
showEventPrompt = true,
|
|
1897
|
+
panZoom,
|
|
1898
|
+
animations = true
|
|
1899
|
+
}, handleRef) => {
|
|
1900
|
+
const [windowTime, setWindowTime] = (0, import_react8.useState)([
|
|
1901
|
+
new Date(
|
|
1902
|
+
startDate.getFullYear(),
|
|
1903
|
+
startDate.getMonth(),
|
|
1904
|
+
startDate.getDate(),
|
|
1905
|
+
startDate.getHours(),
|
|
1906
|
+
0,
|
|
1907
|
+
0
|
|
1908
|
+
).getTime() / 1e3,
|
|
1909
|
+
new Date(
|
|
1910
|
+
endDate.getFullYear(),
|
|
1911
|
+
endDate.getMonth(),
|
|
1912
|
+
endDate.getDate(),
|
|
1913
|
+
endDate.getHours(),
|
|
1914
|
+
0,
|
|
1915
|
+
0
|
|
1916
|
+
).getTime() / 1e3
|
|
1917
|
+
]);
|
|
1918
|
+
const [cellWidth, setCellWidth] = (0, import_react8.useState)(0);
|
|
1919
|
+
const contentRef = (0, import_react8.useRef)(null);
|
|
1920
|
+
const mainRef = (0, import_react8.useRef)(null);
|
|
1921
|
+
const bodyRef = (0, import_react8.useRef)(null);
|
|
1922
|
+
const [tick, setTick] = (0, import_react8.useState)(null);
|
|
1923
|
+
const [scrollWidth, setScrollWidth] = (0, import_react8.useState)(0);
|
|
1924
|
+
const eventPromptRef = (0, import_react8.useRef)(null);
|
|
1925
|
+
const rendererRef = (0, import_react8.useRef)(null);
|
|
1926
|
+
const sceneRef = (0, import_react8.useRef)(null);
|
|
1927
|
+
if (sceneRef.current === null) {
|
|
1928
|
+
sceneRef.current = new SceneStore();
|
|
1929
|
+
}
|
|
1930
|
+
const scene = sceneRef.current;
|
|
1931
|
+
(0, import_react8.useEffect)(() => {
|
|
1932
|
+
scene.setRows(rows);
|
|
1933
|
+
}, [scene, rows]);
|
|
1934
|
+
(0, import_react8.useEffect)(() => {
|
|
1935
|
+
scene.setEvents([...events].sort(sort_events_default));
|
|
1936
|
+
}, [scene, events]);
|
|
1937
|
+
(0, import_react8.useEffect)(() => {
|
|
1938
|
+
scene.setStaticEvents(staticEvents ? [...staticEvents] : []);
|
|
1939
|
+
}, [scene, staticEvents]);
|
|
1940
|
+
const windowTimeRef = (0, import_react8.useRef)(windowTime);
|
|
1941
|
+
windowTimeRef.current = windowTime;
|
|
1942
|
+
(0, import_react8.useImperativeHandle)(
|
|
1943
|
+
handleRef,
|
|
1944
|
+
() => ({
|
|
1945
|
+
setEvents: (next) => scene.setEvents([...next].sort(sort_events_default)),
|
|
1946
|
+
updateEvents: (patches) => scene.applyPatches(patches),
|
|
1947
|
+
getEvent: (id) => scene.getEvent(id),
|
|
1948
|
+
scrollToRow: (rowId) => {
|
|
1949
|
+
const [windowStart, windowEnd] = windowTimeRef.current;
|
|
1950
|
+
const offset2 = scene.getRowOffsets(windowStart, windowEnd).offsetOf.get(rowId);
|
|
1951
|
+
if (offset2 !== void 0 && bodyRef.current) {
|
|
1952
|
+
bodyRef.current.scrollTop = offset2;
|
|
1768
1953
|
}
|
|
1769
1954
|
},
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
eventRef.current.style.bottom = value;
|
|
1773
|
-
}
|
|
1955
|
+
scrollToTime: (time) => {
|
|
1956
|
+
setWindowTime((prev) => [time, time + (prev[1] - prev[0])]);
|
|
1774
1957
|
},
|
|
1775
|
-
|
|
1776
|
-
|
|
1958
|
+
setWindow: (startTime, endTime) => setWindowTime([startTime, endTime]),
|
|
1959
|
+
getVisibleRange: () => ({
|
|
1960
|
+
startTime: windowTimeRef.current[0],
|
|
1961
|
+
endTime: windowTimeRef.current[1]
|
|
1962
|
+
}),
|
|
1963
|
+
redraw: () => {
|
|
1964
|
+
var _a;
|
|
1965
|
+
return (_a = rendererRef.current) == null ? void 0 : _a.invalidate("all");
|
|
1777
1966
|
}
|
|
1778
|
-
}
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
)
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
onResize,
|
|
1792
|
-
startDate,
|
|
1793
|
-
endDate,
|
|
1794
|
-
additionalClassNames,
|
|
1795
|
-
showRTIndicator = true,
|
|
1796
|
-
eventsResize = true,
|
|
1797
|
-
eventPromptTemplate,
|
|
1798
|
-
showEventPrompt = true
|
|
1799
|
-
}) => {
|
|
1800
|
-
const [windowTime, setWindowTime] = (0, import_react23.useState)([
|
|
1801
|
-
new Date(
|
|
1802
|
-
startDate.getFullYear(),
|
|
1803
|
-
startDate.getMonth(),
|
|
1804
|
-
startDate.getDate(),
|
|
1805
|
-
startDate.getHours(),
|
|
1806
|
-
0,
|
|
1807
|
-
0
|
|
1808
|
-
).getTime() / 1e3,
|
|
1809
|
-
new Date(
|
|
1810
|
-
endDate.getFullYear(),
|
|
1811
|
-
endDate.getMonth(),
|
|
1812
|
-
endDate.getDate(),
|
|
1813
|
-
endDate.getHours(),
|
|
1814
|
-
0,
|
|
1815
|
-
0
|
|
1816
|
-
).getTime() / 1e3
|
|
1817
|
-
]);
|
|
1818
|
-
const [cellWidth, setCellWidth] = (0, import_react23.useState)(0);
|
|
1819
|
-
const [internalEvents, setInternalEvents] = (0, import_react23.useState)([]);
|
|
1820
|
-
const contentRef = (0, import_react23.useRef)(null);
|
|
1821
|
-
const mainRef = (0, import_react23.useRef)(null);
|
|
1822
|
-
const bodyRef = (0, import_react23.useRef)(null);
|
|
1823
|
-
const [tick, setTick] = (0, import_react23.useState)(null);
|
|
1824
|
-
const [scrollWidth, setScrollWidth] = (0, import_react23.useState)(0);
|
|
1825
|
-
const [rowsHeight, setRowsHeight] = (0, import_react23.useState)(null);
|
|
1826
|
-
const [allRowsHeight, setAllRowsHeight] = (0, import_react23.useState)(0);
|
|
1827
|
-
const eventPromptRef = (0, import_react23.useRef)(null);
|
|
1828
|
-
(0, import_react23.useEffect)(() => {
|
|
1829
|
-
if (contentRef.current) {
|
|
1830
|
-
const windowDuration = windowTime[1] - windowTime[0];
|
|
1831
|
-
const numberOfHourBlocks = windowDuration / 3600;
|
|
1832
|
-
setTick(
|
|
1833
|
-
windowDuration / contentRef.current.getBoundingClientRect().width
|
|
1834
|
-
);
|
|
1835
|
-
setCellWidth(
|
|
1836
|
-
contentRef.current.getBoundingClientRect().width / numberOfHourBlocks
|
|
1837
|
-
);
|
|
1838
|
-
}
|
|
1839
|
-
}, []);
|
|
1840
|
-
(0, import_react23.useEffect)(() => {
|
|
1841
|
-
if (bodyRef.current) {
|
|
1842
|
-
setScrollWidth(
|
|
1843
|
-
bodyRef.current.getBoundingClientRect().width - bodyRef.current.scrollWidth
|
|
1844
|
-
);
|
|
1845
|
-
}
|
|
1846
|
-
}, []);
|
|
1847
|
-
(0, import_react23.useEffect)(() => {
|
|
1848
|
-
setInternalEvents(events.sort(sort_events_default));
|
|
1849
|
-
}, [events]);
|
|
1850
|
-
const [dragStarted, setDragStarted] = (0, import_react23.useState)(false);
|
|
1851
|
-
(0, import_react23.useEffect)(() => {
|
|
1852
|
-
let tempRowsHeight = null;
|
|
1853
|
-
rows.forEach((row) => {
|
|
1854
|
-
if (tempRowsHeight === null) {
|
|
1855
|
-
tempRowsHeight = { [row.id]: { minHeight: 40 } };
|
|
1856
|
-
} else {
|
|
1857
|
-
tempRowsHeight[row.id] = { minHeight: 40 };
|
|
1967
|
+
}),
|
|
1968
|
+
[scene]
|
|
1969
|
+
);
|
|
1970
|
+
(0, import_react8.useEffect)(() => {
|
|
1971
|
+
if (contentRef.current) {
|
|
1972
|
+
const windowDuration = windowTime[1] - windowTime[0];
|
|
1973
|
+
const numberOfHourBlocks = windowDuration / 3600;
|
|
1974
|
+
setTick(
|
|
1975
|
+
windowDuration / contentRef.current.getBoundingClientRect().width
|
|
1976
|
+
);
|
|
1977
|
+
setCellWidth(
|
|
1978
|
+
contentRef.current.getBoundingClientRect().width / numberOfHourBlocks
|
|
1979
|
+
);
|
|
1858
1980
|
}
|
|
1859
|
-
});
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
event_prompt_default,
|
|
1866
|
-
{
|
|
1867
|
-
ref: eventPromptRef,
|
|
1868
|
-
template: eventPromptTemplate
|
|
1981
|
+
}, []);
|
|
1982
|
+
(0, import_react8.useEffect)(() => {
|
|
1983
|
+
if (bodyRef.current) {
|
|
1984
|
+
setScrollWidth(
|
|
1985
|
+
bodyRef.current.getBoundingClientRect().width - bodyRef.current.scrollWidth
|
|
1986
|
+
);
|
|
1869
1987
|
}
|
|
1870
|
-
)
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
), /* @__PURE__ */ import_react23.default.createElement("div", { className: "body-wrapper", ref: bodyRef }, /* @__PURE__ */ import_react23.default.createElement(
|
|
1882
|
-
RowsHeightContext.Provider,
|
|
1883
|
-
{
|
|
1884
|
-
value: { rowsHeight, setRowsHeight, allRowsHeight, setAllRowsHeight }
|
|
1885
|
-
},
|
|
1886
|
-
/* @__PURE__ */ import_react23.default.createElement(
|
|
1887
|
-
rows_header_default,
|
|
1888
|
-
{
|
|
1889
|
-
rows,
|
|
1890
|
-
className: additionalClassNames == null ? void 0 : additionalClassNames.rowsHeader
|
|
1988
|
+
}, []);
|
|
1989
|
+
use_resize_observer_default({ contentRef, setCellWidth, setTick, windowTime });
|
|
1990
|
+
const resolvedTheme = (0, import_react8.useMemo)(() => resolveTheme(theme), [theme]);
|
|
1991
|
+
const resolvedAnimations = (0, import_react8.useMemo)(() => {
|
|
1992
|
+
var _a, _b;
|
|
1993
|
+
if (animations === false) return { layoutMs: 0, fadeMs: 0 };
|
|
1994
|
+
if (animations === true) {
|
|
1995
|
+
return {
|
|
1996
|
+
layoutMs: DEFAULT_LAYOUT_DURATION_MS,
|
|
1997
|
+
fadeMs: DEFAULT_FADE_DURATION_MS
|
|
1998
|
+
};
|
|
1891
1999
|
}
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
/* @__PURE__ */
|
|
1899
|
-
|
|
2000
|
+
return {
|
|
2001
|
+
layoutMs: (_a = animations.layoutMs) != null ? _a : DEFAULT_LAYOUT_DURATION_MS,
|
|
2002
|
+
fadeMs: (_b = animations.fadeMs) != null ? _b : DEFAULT_FADE_DURATION_MS
|
|
2003
|
+
};
|
|
2004
|
+
}, [animations]);
|
|
2005
|
+
const eventPrompt = (0, import_react8.useMemo)(
|
|
2006
|
+
() => /* @__PURE__ */ import_react8.default.createElement(
|
|
2007
|
+
event_prompt_default,
|
|
1900
2008
|
{
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
rows,
|
|
1904
|
-
setEvents: setInternalEvents,
|
|
1905
|
-
tick,
|
|
1906
|
-
windowTime,
|
|
1907
|
-
cellWidth,
|
|
1908
|
-
setWindowTime,
|
|
1909
|
-
ref: contentRef,
|
|
1910
|
-
setCellWidth,
|
|
1911
|
-
contentWidth: contentRef.current ? contentRef.current.getBoundingClientRect().width : null,
|
|
1912
|
-
bodyRef,
|
|
1913
|
-
lineClassName: additionalClassNames == null ? void 0 : additionalClassNames.gridLine
|
|
2009
|
+
ref: eventPromptRef,
|
|
2010
|
+
template: eventPromptTemplate
|
|
1914
2011
|
}
|
|
1915
2012
|
),
|
|
1916
|
-
|
|
1917
|
-
)
|
|
1918
|
-
|
|
1919
|
-
|
|
2013
|
+
[eventPromptTemplate]
|
|
2014
|
+
);
|
|
2015
|
+
return /* @__PURE__ */ import_react8.default.createElement("div", { className: "main-wrapper", ref: mainRef }, showRTIndicator && /* @__PURE__ */ import_react8.default.createElement(rt_indicator_default, { tick, windowTime }), /* @__PURE__ */ import_react8.default.createElement(
|
|
2016
|
+
canvas_time_bar_default,
|
|
2017
|
+
{
|
|
2018
|
+
windowTime,
|
|
2019
|
+
tick,
|
|
2020
|
+
contentWidth: contentRef.current ? contentRef.current.getBoundingClientRect().width : null,
|
|
2021
|
+
scrollWidth,
|
|
2022
|
+
theme: resolvedTheme
|
|
2023
|
+
}
|
|
2024
|
+
), /* @__PURE__ */ import_react8.default.createElement("div", { className: "body-wrapper", ref: bodyRef }, /* @__PURE__ */ import_react8.default.createElement(
|
|
2025
|
+
canvas_board_default,
|
|
2026
|
+
{
|
|
2027
|
+
scene,
|
|
2028
|
+
rows,
|
|
2029
|
+
windowTime,
|
|
2030
|
+
tick,
|
|
2031
|
+
cellWidth,
|
|
2032
|
+
theme: resolvedTheme,
|
|
2033
|
+
drawEvent,
|
|
2034
|
+
bodyRef,
|
|
2035
|
+
rendererRef,
|
|
2036
|
+
eventPromptRef,
|
|
2037
|
+
rowsHeaderClassName: additionalClassNames == null ? void 0 : additionalClassNames.rowsHeader,
|
|
2038
|
+
setWindowTime,
|
|
2039
|
+
setCellWidth,
|
|
2040
|
+
onDrop,
|
|
2041
|
+
onResize,
|
|
2042
|
+
onEventClick,
|
|
2043
|
+
onEventHover,
|
|
2044
|
+
eventsResize,
|
|
2045
|
+
panZoom,
|
|
2046
|
+
animations: resolvedAnimations,
|
|
2047
|
+
ref: contentRef
|
|
2048
|
+
}
|
|
2049
|
+
), showEventPrompt && eventPrompt));
|
|
2050
|
+
}
|
|
2051
|
+
);
|
|
1920
2052
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1921
2053
|
0 && (module.exports = {
|
|
1922
2054
|
Timeline
|