awesome-timeline-react 0.1.15 → 0.3.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/dist/index.js CHANGED
@@ -1,1924 +1,2339 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
- var __getProtoOf = Object.getPrototypeOf;
8
- var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
10
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
- var __spreadValues = (a, b) => {
12
- for (var prop in b || (b = {}))
13
- if (__hasOwnProp.call(b, prop))
14
- __defNormalProp(a, prop, b[prop]);
15
- if (__getOwnPropSymbols)
16
- for (var prop of __getOwnPropSymbols(b)) {
17
- if (__propIsEnum.call(b, prop))
18
- __defNormalProp(a, prop, b[prop]);
19
- }
20
- return a;
21
- };
22
- var __export = (target, all) => {
23
- for (var name in all)
24
- __defProp(target, name, { get: all[name], enumerable: true });
25
- };
26
- var __copyProps = (to, from, except, desc) => {
27
- if (from && typeof from === "object" || typeof from === "function") {
28
- for (let key of __getOwnPropNames(from))
29
- if (!__hasOwnProp.call(to, key) && key !== except)
30
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
31
- }
32
- return to;
33
- };
34
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
35
- // If the importer is in node compatibility mode or this is not an ESM
36
- // file that has been converted to a CommonJS file using a Babel-
37
- // compatible transform (i.e. "__esModule" has not been set), then set
38
- // "default" to the CommonJS "module.exports" for node compatibility.
39
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
40
- mod
41
- ));
42
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
43
-
44
- // src/index.ts
45
- var src_exports = {};
46
- __export(src_exports, {
47
- Timeline: () => Timeline
48
- });
49
- module.exports = __toCommonJS(src_exports);
50
-
51
- // src/timeline.tsx
52
- var import_react23 = __toESM(require("react"));
53
-
54
- // src/components/time-bar.tsx
55
- var import_react4 = __toESM(require("react"));
56
-
57
- // src/hooks/use-generate-blocks.tsx
58
- var import_react = __toESM(require("react"));
59
- var import_react2 = require("react");
60
-
61
- // src/helpers/get-month-name.ts
62
- var getMonthName = (monthIndex) => {
63
- let monthName = null;
64
- switch (monthIndex) {
65
- case 0:
66
- monthName = "Jan";
67
- break;
68
- case 1:
69
- monthName = "Feb";
70
- break;
71
- case 2:
72
- monthName = "Mar";
73
- break;
74
- case 3:
75
- monthName = "Apr";
76
- break;
77
- case 4:
78
- monthName = "May";
79
- break;
80
- case 5:
81
- monthName = "Jun";
82
- break;
83
- case 6:
84
- monthName = "Jul";
85
- break;
86
- case 7:
87
- monthName = "Aug";
88
- break;
89
- case 8:
90
- monthName = "Sep";
91
- break;
92
- case 9:
93
- monthName = "Oct";
94
- break;
95
- case 10:
96
- monthName = "Nov";
97
- break;
98
- case 11:
99
- monthName = "Dec";
100
- break;
101
- default:
102
- monthName = "Jan";
103
- }
104
- return monthName;
105
- };
106
- var get_month_name_default = getMonthName;
107
-
108
- // src/helpers/get-week-day-name.ts
109
- var getWeekDayName = (dayIndex) => {
110
- let dayName = null;
111
- switch (dayIndex) {
112
- case 0:
113
- dayName = "Mon";
114
- break;
115
- case 1:
116
- dayName = "Tue";
117
- break;
118
- case 2:
119
- dayName = "Wed";
120
- break;
121
- case 3:
122
- dayName = "Thu";
123
- break;
124
- case 4:
125
- dayName = "Fri";
126
- break;
127
- case 5:
128
- dayName = "Sat";
129
- break;
130
- case 6:
131
- dayName = "Sun";
132
- break;
133
- default:
134
- dayName = "Mon";
135
- }
136
- return dayName;
137
- };
138
- var get_week_day_name_default = getWeekDayName;
139
-
140
- // src/hooks/use-generate-blocks.tsx
141
- var useGenerateBlocks = ({
142
- windowTime,
143
- tick,
144
- contentWidth,
145
- blockWidth
146
- }) => {
147
- const { dayBlocks, hourBlocks } = (0, import_react2.useMemo)(() => {
148
- let timePoint = windowTime[0];
149
- const dayBlocks2 = [];
150
- const hourBlocks2 = [];
151
- if (tick === null || contentWidth === null) {
152
- return { dayBlocks: [], hourBlocks: [] };
153
- }
154
- let widthLeft = contentWidth;
155
- let prevNumBlocks = 1;
156
- while (1) {
157
- let datePoint = new Date(timePoint * 1e3);
158
- const endDatePoint = new Date(
159
- datePoint.getFullYear(),
160
- datePoint.getMonth(),
161
- datePoint.getDate(),
162
- 23,
163
- 59,
164
- 59
165
- );
166
- const dateDuration = endDatePoint.getTime() - datePoint.getTime();
167
- const dateWidth = dateDuration / 1e3 / tick;
168
- widthLeft -= dateWidth;
169
- if (Math.round(widthLeft) < 0) {
170
- const numBlocks2 = Math.round((dateWidth + widthLeft) / blockWidth);
171
- for (let i = 0; i < numBlocks2; i++) {
172
- hourBlocks2.push(
173
- /* @__PURE__ */ import_react.default.createElement(
174
- "div",
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;
233
- }
234
- timePoint = (endDatePoint.getTime() + 1e3) / 1e3;
235
- }
236
- return { dayBlocks: dayBlocks2, hourBlocks: hourBlocks2 };
237
- }, [tick, windowTime, contentWidth]);
238
- return { dayBlocks, hourBlocks };
239
- };
240
- var use_generate_blocks_default = useGenerateBlocks;
241
-
242
- // src/hooks/use-get-block-properties.ts
243
- var import_react3 = require("react");
244
- var useGetBlockProperties = ({
245
- windowTime,
246
- contentWidth
247
- }) => {
248
- const numberOfHourBlocks = (0, import_react3.useMemo)(
249
- () => (windowTime[1] - windowTime[0]) / 3600,
250
- [windowTime]
251
- );
252
- const blockWidth = contentWidth ? contentWidth / numberOfHourBlocks : 0;
253
- return { numberOfHourBlocks, blockWidth };
254
- };
255
- var use_get_block_properties_default = useGetBlockProperties;
256
-
257
- // src/components/time-bar.tsx
258
- var TimeBar = ({
259
- windowTime,
260
- tick,
261
- contentWidth,
262
- scrollWidth,
263
- additionalClassNames
264
- }) => {
265
- const timeContentRef = (0, import_react4.useRef)(null);
266
- const { blockWidth } = use_get_block_properties_default({
267
- windowTime,
268
- contentWidth
269
- });
270
- const { dayBlocks, hourBlocks } = use_generate_blocks_default({
271
- windowTime,
272
- tick,
273
- contentWidth,
274
- blockWidth
275
- });
276
- const timeBarClassNames = (additionalClassNames == null ? void 0 : additionalClassNames.timeBar) ? "time-bar " + additionalClassNames.timeBar : "time-bar";
277
- const dayRowClassNames = (additionalClassNames == null ? void 0 : additionalClassNames.dayRow) ? "day-row " + additionalClassNames.dayRow : "day-row";
278
- const hourRowClassNames = (additionalClassNames == null ? void 0 : additionalClassNames.hourRow) ? "hour-row " + additionalClassNames.hourRow : "hour-row";
279
- return /* @__PURE__ */ import_react4.default.createElement("div", { className: timeBarClassNames }, /* @__PURE__ */ import_react4.default.createElement("div", { className: "empty-block" }), /* @__PURE__ */ import_react4.default.createElement(
280
- "div",
281
- {
282
- className: "time-content",
283
- ref: timeContentRef,
284
- style: { minWidth: contentWidth ? contentWidth : 0 }
285
- },
286
- /* @__PURE__ */ import_react4.default.createElement(
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(
307
- "div",
308
- {
309
- style: {
310
- width: scrollWidth,
311
- height: "100%",
312
- boxSizing: "border-box",
313
- borderLeft: "1px solid yellow"
314
- }
315
- }
316
- ) : null);
317
- };
318
- var time_bar_default = TimeBar;
319
-
320
- // src/components/rows-header.tsx
321
- var import_react7 = __toESM(require("react"));
322
-
323
- // src/components/row-header.tsx
324
- var import_react6 = __toESM(require("react"));
325
-
326
- // src/contexts/row-height-context.ts
327
- var import_react5 = require("react");
328
- var RowsHeightContext = (0, import_react5.createContext)(
329
- null
330
- );
331
-
332
- // src/components/row-header.tsx
333
- var RowHeader = ({ name, id }) => {
334
- const rowsHeightContext = (0, import_react6.useContext)(RowsHeightContext);
335
- const minHeight = rowsHeightContext && rowsHeightContext.rowsHeight && rowsHeightContext.rowsHeight[id] ? rowsHeightContext.rowsHeight[id].minHeight : 40;
336
- return /* @__PURE__ */ import_react6.default.createElement("div", { className: "row-header", style: { minHeight } }, name);
337
- };
338
- var row_header_default = RowHeader;
339
-
340
- // src/components/rows-header.tsx
341
- var RowsHeader = ({
342
- rows,
343
- className
344
- }) => {
345
- const classNames = className ? "rows-header-wrapper " + className : "rows-header-wrapper";
346
- return /* @__PURE__ */ import_react7.default.createElement("div", { className: classNames }, rows.map((row) => /* @__PURE__ */ import_react7.default.createElement(
347
- row_header_default,
348
- {
349
- key: `row_header_${row.id}`,
350
- id: row.id,
351
- name: row.name
352
- }
353
- )));
354
- };
355
- var rows_header_default = RowsHeader;
356
-
357
- // src/components/content.tsx
358
- var import_react19 = __toESM(require("react"));
359
-
360
- // src/components/lines-canvas.tsx
361
- var import_react8 = __toESM(require("react"));
362
- var import_react9 = require("react");
363
- var LinesCanvas = ({
364
- contentWidth,
365
- cellWidth,
366
- lineClassName
367
- }) => {
368
- const lines = (0, import_react9.useMemo)(() => {
369
- const lines2 = [];
370
- const classNames = lineClassName ? "line " + lineClassName : "line";
371
- if (contentWidth) {
372
- for (let i = cellWidth; i < contentWidth; i = i + cellWidth) {
373
- lines2.push(/* @__PURE__ */ import_react8.default.createElement("div", { key: `line_${i}`, className: classNames }));
374
- }
375
- }
376
- return lines2;
377
- }, [cellWidth, contentWidth]);
378
- const minWidth = (0, import_react9.useMemo)(() => {
379
- return contentWidth ? contentWidth - lines.length * cellWidth : 0;
380
- }, [contentWidth, cellWidth, lines]);
381
- return /* @__PURE__ */ import_react8.default.createElement(
382
- "div",
383
- {
384
- className: minWidth < 1 ? "lines-canvas hide-last-line" : "lines-canvas",
385
- style: minWidth < 1 ? {
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
- );
393
- };
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
-
400
- // src/components/static-event.tsx
401
- var import_react10 = __toESM(require("react"));
402
- var StaticEvent = ({
403
- id,
404
- startPosition,
405
- width,
406
- top,
407
- height
408
- }) => {
409
- return /* @__PURE__ */ import_react10.default.createElement(
410
- "div",
411
- {
412
- id: `static_event_${id}`,
413
- key: `static_event_${id}`,
414
- className: "static-event",
415
- onDrop: (event) => event.stopPropagation(),
416
- style: {
417
- left: startPosition,
418
- width,
419
- top,
420
- minHeight: height
421
- }
422
- }
423
- );
424
- };
425
- var static_event_default = StaticEvent;
426
-
427
- // src/components/row-content.tsx
428
- var import_react13 = __toESM(require("react"));
429
-
430
- // node_modules/immer/dist/immer.mjs
431
- var NOTHING = Symbol.for("immer-nothing");
432
- var DRAFTABLE = Symbol.for("immer-draftable");
433
- var DRAFT_STATE = Symbol.for("immer-state");
434
- var errors = process.env.NODE_ENV !== "production" ? [
435
- // All error codes, starting by 0:
436
- function(plugin) {
437
- return `The plugin for '${plugin}' has not been loaded into Immer. To enable the plugin, import and call \`enable${plugin}()\` when initializing your application.`;
438
- },
439
- function(thing) {
440
- return `produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '${thing}'`;
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;
526
- } else {
527
- return x !== x && y !== y;
528
- }
529
- }
530
- function isMap(target) {
531
- return target instanceof Map;
532
- }
533
- function isSet(target) {
534
- return target instanceof Set;
535
- }
536
- function latest(state) {
537
- return state.copy_ || state.base_;
538
- }
539
- function shallowCopy(base, strict) {
540
- if (isMap(base)) {
541
- return new Map(base);
542
- }
543
- if (isSet(base)) {
544
- return new Set(base);
545
- }
546
- if (Array.isArray(base))
547
- return Array.prototype.slice.call(base);
548
- const isPlain = isPlainObject(base);
549
- if (strict === true || strict === "class_only" && !isPlain) {
550
- const descriptors = Object.getOwnPropertyDescriptors(base);
551
- delete descriptors[DRAFT_STATE];
552
- let keys = Reflect.ownKeys(descriptors);
553
- for (let i = 0; i < keys.length; i++) {
554
- const key = keys[i];
555
- const desc = descriptors[key];
556
- if (desc.writable === false) {
557
- desc.writable = true;
558
- desc.configurable = true;
559
- }
560
- if (desc.get || desc.set)
561
- descriptors[key] = {
562
- configurable: true,
563
- writable: true,
564
- // could live with !!desc.set as well here...
565
- enumerable: desc.enumerable,
566
- value: base[key]
567
- };
568
- }
569
- return Object.create(getPrototypeOf(base), descriptors);
570
- } else {
571
- const proto = getPrototypeOf(base);
572
- if (proto !== null && isPlain) {
573
- return __spreadValues({}, base);
574
- }
575
- const obj = Object.create(proto);
576
- return Object.assign(obj, base);
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_
667
- );
668
- }
669
- } else {
670
- result = finalize(scope, baseDraft, []);
671
- }
672
- revokeScope(scope);
673
- if (scope.patches_) {
674
- scope.patchListener_(scope.patches_, scope.inversePatches_);
675
- }
676
- return result !== NOTHING ? result : void 0;
677
- }
678
- function finalize(rootScope, value, path) {
679
- if (isFrozen(value))
680
- return value;
681
- const state = value[DRAFT_STATE];
682
- if (!state) {
683
- each(
684
- value,
685
- (key, childValue) => finalizeProperty(rootScope, state, value, key, childValue, path)
686
- );
687
- return value;
688
- }
689
- if (state.scope_ !== rootScope)
690
- return value;
691
- if (!state.modified_) {
692
- maybeFreeze(rootScope, state.base_, true);
693
- return state.base_;
694
- }
695
- if (!state.finalized_) {
696
- state.finalized_ = true;
697
- state.scope_.unfinalizedDrafts_--;
698
- const result = state.copy_;
699
- let resultEach = result;
700
- let isSet2 = false;
701
- if (state.type_ === 3) {
702
- resultEach = new Set(result);
703
- result.clear();
704
- isSet2 = true;
705
- }
706
- each(
707
- resultEach,
708
- (key, childValue) => finalizeProperty(rootScope, state, result, key, childValue, path, isSet2)
709
- );
710
- maybeFreeze(rootScope, result, false);
711
- if (path && rootScope.patches_) {
712
- getPlugin("Patches").generatePatches_(
713
- state,
714
- path,
715
- rootScope.patches_,
716
- rootScope.inversePatches_
717
- );
718
- }
719
- }
720
- return state.copy_;
721
- }
722
- function finalizeProperty(rootScope, parentState, targetObject, prop, childValue, rootPath, targetIsSet) {
723
- if (process.env.NODE_ENV !== "production" && childValue === targetObject)
724
- die(5);
725
- if (isDraft(childValue)) {
726
- const path = rootPath && parentState && parentState.type_ !== 3 && // Set objects are atomic since they have no keys.
727
- !has(parentState.assigned_, prop) ? rootPath.concat(prop) : void 0;
728
- const res = finalize(rootScope, childValue, path);
729
- set(targetObject, prop, res);
730
- if (isDraft(res)) {
731
- rootScope.canAutoFreeze_ = false;
732
- } else
733
- return;
734
- } else if (targetIsSet) {
735
- targetObject.add(childValue);
736
- }
737
- if (isDraftable(childValue) && !isFrozen(childValue)) {
738
- if (!rootScope.immer_.autoFreeze_ && rootScope.unfinalizedDrafts_ < 1) {
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;
824
- }
825
- if (is(value, current2) && (value !== void 0 || has(state.base_, prop)))
826
- return true;
827
- prepareCopy(state);
828
- markChanged(state);
829
- }
830
- if (state.copy_[prop] === value && // special case: handle new props with value 'undefined'
831
- (value !== void 0 || prop in state.copy_) || // special case: NaN
832
- Number.isNaN(value) && Number.isNaN(state.copy_[prop]))
833
- return true;
834
- state.copy_[prop] = value;
835
- state.assigned_[prop] = true;
836
- return true;
837
- },
838
- deleteProperty(state, prop) {
839
- if (peek(state.base_, prop) !== void 0 || prop in state.base_) {
840
- state.assigned_[prop] = false;
841
- prepareCopy(state);
842
- markChanged(state);
843
- } else {
844
- delete state.assigned_[prop];
845
- }
846
- if (state.copy_) {
847
- delete state.copy_[prop];
848
- }
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
- }
874
- };
875
- var arrayTraps = {};
876
- each(objectTraps, (key, fn) => {
877
- arrayTraps[key] = function() {
878
- arguments[0] = arguments[0][0];
879
- return fn.apply(this, arguments);
880
- };
881
- });
882
- arrayTraps.deleteProperty = function(state, prop) {
883
- if (process.env.NODE_ENV !== "production" && isNaN(parseInt(prop)))
884
- die(13);
885
- return arrayTraps.set.call(this, state, prop, void 0);
886
- };
887
- arrayTraps.set = function(state, prop, value) {
888
- if (process.env.NODE_ENV !== "production" && prop !== "length" && isNaN(parseInt(prop)))
889
- die(14);
890
- return objectTraps.set.call(this, state[0], prop, value, state[0]);
891
- };
892
- function peek(draft, prop) {
893
- const state = draft[DRAFT_STATE];
894
- const source = state ? latest(state) : draft;
895
- return source[prop];
896
- }
897
- function readPropFromProto(state, source, prop) {
898
- var _a;
899
- const desc = getDescriptorFromProto(source, prop);
900
- return desc ? `value` in desc ? desc.value : (
901
- // This is a very special case, if the prop is a getter defined by the
902
- // prototype, we should invoke it with the draft as context!
903
- (_a = desc.get) == null ? void 0 : _a.call(state.draft_)
904
- ) : void 0;
905
- }
906
- function getDescriptorFromProto(source, prop) {
907
- if (!(prop in source))
908
- return void 0;
909
- let proto = getPrototypeOf(source);
910
- while (proto) {
911
- const desc = Object.getOwnPropertyDescriptor(proto, prop);
912
- if (desc)
913
- return desc;
914
- proto = getPrototypeOf(proto);
915
- }
916
- return void 0;
917
- }
918
- function markChanged(state) {
919
- if (!state.modified_) {
920
- state.modified_ = true;
921
- if (state.parent_) {
922
- markChanged(state.parent_);
923
- }
924
- }
925
- }
926
- function prepareCopy(state) {
927
- if (!state.copy_) {
928
- state.copy_ = shallowCopy(
929
- state.base_,
930
- state.scope_.immer_.useStrictShallowCopy_
931
- );
932
- }
933
- }
934
- var Immer2 = class {
935
- constructor(config) {
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);
1019
- }
1020
- /**
1021
- * Pass true to automatically freeze all copies created by Immer.
1022
- *
1023
- * By default, auto-freezing is enabled.
1024
- */
1025
- setAutoFreeze(value) {
1026
- this.autoFreeze_ = value;
1027
- }
1028
- /**
1029
- * Pass true to enable strict shallow copy.
1030
- *
1031
- * By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.
1032
- */
1033
- setUseStrictShallowCopy(value) {
1034
- this.useStrictShallowCopy_ = value;
1035
- }
1036
- applyPatches(base, patches) {
1037
- let i;
1038
- for (i = patches.length - 1; i >= 0; i--) {
1039
- const patch = patches[i];
1040
- if (patch.path.length === 0 && patch.op === "replace") {
1041
- base = patch.value;
1042
- break;
1043
- }
1044
- }
1045
- if (i > -1) {
1046
- patches = patches.slice(i + 1);
1047
- }
1048
- const applyPatchesImpl = getPlugin("Patches").applyPatches_;
1049
- if (isDraft(base)) {
1050
- return applyPatchesImpl(base, patches);
1051
- }
1052
- return this.produce(
1053
- base,
1054
- (draft) => applyPatchesImpl(draft, patches)
1055
- );
1056
- }
1057
- };
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
-
1101
- // src/contexts/drag-started-context.ts
1102
- var import_react11 = require("react");
1103
- var DragStartedContext = (0, import_react11.createContext)({
1104
- dragStarted: false,
1105
- setDragStarted: () => {
1106
- }
1107
- });
1108
-
1109
- // src/contexts/external-properties-context.ts
1110
- var import_react12 = require("react");
1111
- var ExternalPropertiesContext = (0, import_react12.createContext)(
1112
- {}
1113
- );
1114
-
1115
- // src/helpers/sort-events.ts
1116
- var sortEvents = (eventA, eventB) => {
1117
- if (eventA.startTime - eventB.startTime < 0) return -1;
1118
- if (eventA.startTime === eventB.startTime) {
1119
- if (eventA.endTime < eventB.endTime) {
1120
- return -1;
1121
- } else {
1122
- return 1;
1123
- }
1124
- } else {
1125
- return 1;
1126
- }
1127
- };
1128
- var sort_events_default = sortEvents;
1129
-
1130
- // src/components/row-content.tsx
1131
- var RowContent = (0, import_react13.forwardRef)((props, ref) => {
1132
- const { setEvents, tick, id, windowTime, cellWidth, children } = props;
1133
- const { dragStarted, setDragStarted } = (0, import_react13.useContext)(DragStartedContext);
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]
1169
- );
1170
- const rowsHeightContext = (0, import_react13.useContext)(RowsHeightContext);
1171
- const minHeight = rowsHeightContext && rowsHeightContext.rowsHeight && rowsHeightContext.rowsHeight[id] ? rowsHeightContext.rowsHeight[id].minHeight : 40;
1172
- return /* @__PURE__ */ import_react13.default.createElement(
1173
- "div",
1174
- {
1175
- id: `row_${id}`,
1176
- ref,
1177
- onDragOver: (event) => event.preventDefault(),
1178
- onDrop: handleOnDrop,
1179
- className: dragStarted ? "row-content not-clickable" : "row-content",
1180
- "data-index": id,
1181
- style: {
1182
- minHeight
1183
- }
1184
- },
1185
- children
1186
- );
1187
- });
1188
- var row_content_default = RowContent;
1189
-
1190
- // src/components/event.tsx
1191
- var import_react15 = __toESM(require("react"));
1192
-
1193
- // src/components/resize-icon.tsx
1194
- var import_react14 = __toESM(require("react"));
1195
- var ResizeIcon = () => {
1196
- return /* @__PURE__ */ import_react14.default.createElement("div", { style: { display: "flex", gap: "1px" } }, /* @__PURE__ */ import_react14.default.createElement("div", { className: "resize-bar" }), /* @__PURE__ */ import_react14.default.createElement("div", { className: "resize-bar" }));
1197
- };
1198
- var resize_icon_default = ResizeIcon;
1199
-
1200
- // src/components/event.tsx
1201
- var Event = ({
1202
- eventData,
1203
- startPosition,
1204
- width,
1205
- top,
1206
- setEvents,
1207
- tick
1208
- }) => {
1209
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
1210
- const { setDragStarted } = (0, import_react15.useContext)(DragStartedContext);
1211
- const { onResize, eventsResize, eventPromptRef } = (0, import_react15.useContext)(
1212
- ExternalPropertiesContext
1213
- );
1214
- const initialPositionForResizeRef = (0, import_react15.useRef)(0);
1215
- const handleOnDragStart = (0, import_react15.useCallback)(
1216
- (event) => {
1217
- event.stopPropagation();
1218
- event.dataTransfer.setData("eventId", eventData.id);
1219
- setTimeout(() => setDragStarted(true), 0);
1220
- const target = event.target;
1221
- target.style.opacity = "50%";
1222
- if (eventPromptRef == null ? void 0 : eventPromptRef.current) {
1223
- eventPromptRef.current.setDisplay("none");
1224
- }
1225
- },
1226
- [setDragStarted]
1227
- );
1228
- const handleOnDragEnd = (0, import_react15.useCallback)(
1229
- (event) => {
1230
- event.stopPropagation();
1231
- setDragStarted(false);
1232
- const target = event.target;
1233
- target.style.opacity = "100%";
1234
- },
1235
- [setDragStarted]
1236
- );
1237
- const classNames = ((_a = eventData.props) == null ? void 0 : _a.classNames) ? "event " + eventData.props.classNames.join(" ") : "event";
1238
- const [draggableEvent, setDraggableEvent] = (0, import_react15.useState)(true);
1239
- const [resizeOffset, setResizeOffset] = (0, import_react15.useState)(0);
1240
- const resizeOffsetRef = (0, import_react15.useRef)(0);
1241
- const [resizeStarted, setResizeStarted] = (0, import_react15.useState)(false);
1242
- const resizeDirectionRef = (0, import_react15.useRef)(null);
1243
- const handleDocumentOnMouseMoveResize = (0, import_react15.useCallback)(
1244
- (event) => {
1245
- const offset = event.clientX - initialPositionForResizeRef.current;
1246
- let internalResizeOffset = resizeDirectionRef.current === "left" ? offset * -1 : offset;
1247
- setResizeOffset(internalResizeOffset);
1248
- resizeOffsetRef.current = offset;
1249
- },
1250
- [setResizeOffset]
1251
- );
1252
- const handleDocumentOnMouseUp = (0, import_react15.useCallback)(
1253
- (event, resizeDirection) => {
1254
- initialPositionForResizeRef.current = 0;
1255
- setResizeStarted(false);
1256
- document.removeEventListener(
1257
- "mousemove",
1258
- handleDocumentOnMouseMoveResize
1259
- );
1260
- const lockedStyle = document.getElementById("lock-cursor");
1261
- if (lockedStyle) {
1262
- lockedStyle.remove();
1263
- }
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
- },
1297
- [
1298
- handleDocumentOnMouseMoveResize,
1299
- setEvents,
1300
- tick,
1301
- setResizeOffset,
1302
- sort_events_default
1303
- ]
1304
- );
1305
- const handleOnMouseDownEventResizer = (0, import_react15.useCallback)(
1306
- (event, resizeDirection) => {
1307
- event.stopPropagation();
1308
- resizeDirectionRef.current = resizeDirection;
1309
- setResizeStarted(true);
1310
- const style = document.createElement("style");
1311
- style.id = "lock-cursor";
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();
1328
- }
1329
- },
1330
- [resizeStarted]
1331
- );
1332
- const handleOnMouseOver = (0, import_react15.useCallback)(
1333
- (event) => {
1334
- var _a2, _b2;
1335
- event.stopPropagation();
1336
- if (((_a2 = eventData.props) == null ? void 0 : _a2.showPrompt) || ((_b2 = eventData.props) == null ? void 0 : _b2.showPrompt) === void 0) {
1337
- const target = event.target;
1338
- if (eventPromptRef == null ? void 0 : eventPromptRef.current) {
1339
- eventPromptRef.current.setDisplay("block");
1340
- eventPromptRef.current.setRight(
1341
- `calc(100% - ${target.getBoundingClientRect().left}px + 60px)`
1342
- );
1343
- eventPromptRef.current.setBottom(
1344
- `calc(100% - ${target.getBoundingClientRect().top}px + 60px)`
1345
- );
1346
- eventPromptRef.current.setEvent(eventData);
1347
- }
1348
- }
1349
- },
1350
- [eventData]
1351
- );
1352
- const handleOnMouseOut = (0, import_react15.useCallback)(() => {
1353
- if (eventPromptRef == null ? void 0 : eventPromptRef.current) {
1354
- eventPromptRef.current.setDisplay("none");
1355
- }
1356
- }, []);
1357
- return /* @__PURE__ */ import_react15.default.createElement(
1358
- "div",
1359
- {
1360
- id: `event_${eventData.id}`,
1361
- key: `event_${eventData.id}`,
1362
- className: classNames,
1363
- draggable: ((_b = eventData.props) == null ? void 0 : _b.isLocked) ? false : draggableEvent,
1364
- onDragStart: handleOnDragStart,
1365
- onDragEnd: handleOnDragEnd,
1366
- onMouseDown: (event) => event.stopPropagation(),
1367
- onMouseMove: handleOnMouseMove,
1368
- onMouseOut: handleOnMouseOut,
1369
- onDrop: (event) => event.stopPropagation(),
1370
- style: {
1371
- left: resizeDirectionRef.current === "left" ? startPosition - resizeOffset : startPosition,
1372
- width: width + resizeOffset,
1373
- top,
1374
- cursor: ((_c = eventData.props) == null ? void 0 : _c.isLocked) ? "not-allowed" : "pointer"
1375
- }
1376
- },
1377
- !((_d = eventData.props) == null ? void 0 : _d.isLocked) && (eventsResize && (((_e = eventData.props) == null ? void 0 : _e.isResizable) === true || ((_f = eventData.props) == null ? void 0 : _f.isResizable) === void 0) || !eventsResize && ((_g = eventData.props) == null ? void 0 : _g.isResizable)) && /* @__PURE__ */ import_react15.default.createElement(
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
- )
1404
- );
1405
- };
1406
- var event_default = Event;
1407
-
1408
- // src/hooks/use-intersection-observer.ts
1409
- var import_react16 = require("react");
1410
- var useIntersectionObserver = ({
1411
- bodyRef,
1412
- rowsContentRef
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");
1420
- }
1421
- });
1422
- }, []);
1423
- const observer = new IntersectionObserver(callback, {
1424
- root: bodyRef.current
1425
- });
1426
- (0, import_react16.useEffect)(() => {
1427
- if (rowsContentRef.current) {
1428
- rowsContentRef.current.forEach((row) => {
1429
- observer.observe(row);
1430
- });
1431
- }
1432
- return () => observer.disconnect();
1433
- }, [observer]);
1434
- };
1435
- var use_intersection_observer_default = useIntersectionObserver;
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
- }
1473
- }
1474
- if (assignEventOrder) {
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
- };
1503
- }
1504
- internalAllRowsHeight2 += 40 + highestEventOrder * 22;
1505
- const rowStaticEvents = tick && staticEvents ? staticEvents.filter((event) => event.rowId === row.id).map((event) => {
1506
- if (event.endTime >= windowTime[0] && event.startTime <= windowTime[1]) {
1507
- return /* @__PURE__ */ import_react18.default.createElement(
1508
- static_event_default,
1509
- {
1510
- key: `static_event_${event.id}`,
1511
- id: event.id,
1512
- startPosition: (event.startTime - windowTime[0]) / tick,
1513
- width: (event.endTime - event.startTime) / tick,
1514
- top: 10,
1515
- height: 20 + highestEventOrder * 22
1516
- }
1517
- );
1518
- }
1519
- }) : null;
1520
- return /* @__PURE__ */ import_react18.default.createElement(import_react18.default.Fragment, { key: `row_content_${row.id}` }, /* @__PURE__ */ import_react18.default.createElement(
1521
- row_content_default,
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);
1551
- }
1552
- }, [content, internalAllRowsHeight]);
1553
- return content;
1554
- };
1555
- var use_produce_content_default = useProduceContent;
1556
-
1557
- // src/components/content.tsx
1558
- var Content = (0, import_react19.forwardRef)(
1559
- ({
1560
- rows,
1561
- events,
1562
- staticEvents,
1563
- setEvents,
1564
- tick,
1565
- windowTime,
1566
- cellWidth,
1567
- setWindowTime,
1568
- contentWidth,
1569
- setCellWidth,
1570
- bodyRef,
1571
- lineClassName
1572
- }, ref) => {
1573
- const [mouseDown, setMouseDown] = (0, import_react19.useState)(false);
1574
- const startMovePosition = (0, import_react19.useRef)(null);
1575
- const [changeGrid, setChangeGrid] = (0, import_react19.useState)(false);
1576
- const { blockWidth } = use_get_block_properties_default({ windowTime, contentWidth });
1577
- const rowsHeightContext = (0, import_react19.useContext)(RowsHeightContext);
1578
- const handleOnMouseMove = (0, import_react19.useCallback)(
1579
- (event) => {
1580
- event.preventDefault();
1581
- if (!mouseDown) {
1582
- return;
1583
- }
1584
- const element = event.target;
1585
- const { left } = element.getBoundingClientRect();
1586
- const movePosition = event.clientX - left;
1587
- const moveTimestamp = tick ? Math.floor(tick * blockWidth) : 0;
1588
- if (startMovePosition.current && startMovePosition.current - movePosition >= blockWidth) {
1589
- startMovePosition.current = movePosition;
1590
- setWindowTime((prev) => [
1591
- prev[0] + moveTimestamp,
1592
- prev[1] + moveTimestamp
1593
- ]);
1594
- } else if (startMovePosition.current && movePosition - startMovePosition.current >= blockWidth) {
1595
- startMovePosition.current = movePosition;
1596
- setWindowTime((prev) => [
1597
- prev[0] - moveTimestamp,
1598
- prev[1] - moveTimestamp
1599
- ]);
1600
- }
1601
- },
1602
- [blockWidth, setWindowTime, mouseDown]
1603
- );
1604
- const handleOnMouseDown = (0, import_react19.useCallback)(
1605
- (event) => {
1606
- setMouseDown(true);
1607
- if (event.button === 1) {
1608
- event.preventDefault();
1609
- }
1610
- const element = event.target;
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,
1625
- windowTime,
1626
- tick,
1627
- events,
1628
- staticEvents,
1629
- cellWidth,
1630
- setEvents,
1631
- bodyRef
1632
- });
1633
- const handleAuxClick = (0, import_react19.useCallback)(
1634
- (event) => {
1635
- event.preventDefault();
1636
- if (event.button === 1) {
1637
- setChangeGrid((prev) => !prev);
1638
- }
1639
- },
1640
- []
1641
- );
1642
- const handleOnWheel = (0, import_react19.useCallback)(
1643
- (event) => {
1644
- const pixelsToCalculate = tick ? 900 / tick : 0;
1645
- if (changeGrid) {
1646
- setCellWidth((cellWidth2) => {
1647
- const newCellWidth = event.deltaY > 0 ? cellWidth2 + pixelsToCalculate : cellWidth2 - pixelsToCalculate;
1648
- if (newCellWidth < pixelsToCalculate || newCellWidth > pixelsToCalculate * 12) {
1649
- return cellWidth2;
1650
- }
1651
- return newCellWidth;
1652
- });
1653
- }
1654
- },
1655
- [changeGrid, cellWidth, tick]
1656
- );
1657
- (0, import_react19.useEffect)(() => {
1658
- if (bodyRef.current) {
1659
- bodyRef.current.style.overflow = changeGrid ? "hidden" : "auto";
1660
- }
1661
- }, [changeGrid]);
1662
- return /* @__PURE__ */ import_react19.default.createElement(
1663
- "div",
1664
- {
1665
- key: "content",
1666
- ref,
1667
- className: "content-wrapper",
1668
- onMouseDown: handleOnMouseDown,
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
- );
1689
- }
1690
- );
1691
- var content_default = Content;
1692
-
1693
- // src/hooks/use-resize-observer.ts
1694
- var import_react20 = require("react");
1695
- var useResizeObserver = ({
1696
- windowTime,
1697
- setTick,
1698
- setCellWidth,
1699
- contentRef
1700
- }) => {
1701
- const prevWidthRef = (0, import_react20.useRef)(0);
1702
- const resizeObserver = (0, import_react20.useMemo)(() => {
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" });
1720
- }
1721
- return () => resizeObserver.disconnect();
1722
- }, [resizeObserver]);
1723
- };
1724
- var use_resize_observer_default = useResizeObserver;
1725
-
1726
- // src/components/rt-indicator.tsx
1727
- var import_react21 = __toESM(require("react"));
1728
- var RTIndicator = ({
1729
- tick,
1730
- windowTime
1731
- }) => {
1732
- const [currentTime, setCurrentTime] = (0, import_react21.useState)((/* @__PURE__ */ new Date()).getTime() / 1e3);
1733
- const [leftOffset, setLeftOffset] = (0, import_react21.useState)(0);
1734
- const intervalIdRef = (0, import_react21.useRef)(null);
1735
- (0, import_react21.useEffect)(() => {
1736
- if (tick) {
1737
- const leftOffsetTime = currentTime - windowTime[0];
1738
- setLeftOffset(Math.round(leftOffsetTime / tick));
1739
- if (intervalIdRef.current !== null) {
1740
- clearInterval(intervalIdRef.current);
1741
- }
1742
- const intervalId = setInterval(() => {
1743
- setCurrentTime((/* @__PURE__ */ new Date()).getTime() / 1e3);
1744
- }, tick * 1e3);
1745
- intervalIdRef.current = intervalId;
1746
- }
1747
- }, [tick, windowTime, currentTime]);
1748
- return /* @__PURE__ */ import_react21.default.createElement(import_react21.default.Fragment, null, windowTime[0] <= currentTime && currentTime <= windowTime[1] && /* @__PURE__ */ import_react21.default.createElement(import_react21.default.Fragment, null, /* @__PURE__ */ import_react21.default.createElement("div", { className: "rt-arrow", style: { left: 86 + leftOffset } }), /* @__PURE__ */ import_react21.default.createElement("div", { className: "rt-line", style: { left: 100 + leftOffset } })));
1749
- };
1750
- var rt_indicator_default = RTIndicator;
1751
-
1752
- // src/components/event-prompt.tsx
1753
- var import_react22 = __toESM(require("react"));
1754
- var EventPrompt = (0, import_react22.forwardRef)(
1755
- ({ template }, ref) => {
1756
- const eventRef = (0, import_react22.useRef)(null);
1757
- const [hoveredEvent, setHoveredEvent] = (0, import_react22.useState)();
1758
- (0, import_react22.useImperativeHandle)(ref, () => {
1759
- return {
1760
- setDisplay(value) {
1761
- if (eventRef.current) {
1762
- eventRef.current.style.display = value;
1763
- }
1764
- },
1765
- setRight(value) {
1766
- if (eventRef.current) {
1767
- eventRef.current.style.right = value;
1768
- }
1769
- },
1770
- setBottom(value) {
1771
- if (eventRef.current) {
1772
- eventRef.current.style.bottom = value;
1773
- }
1774
- },
1775
- setEvent(event) {
1776
- setHoveredEvent(event);
1777
- }
1778
- };
1779
- });
1780
- return /* @__PURE__ */ import_react22.default.createElement("div", { className: "event-prompt", ref: eventRef }, template && hoveredEvent && template(hoveredEvent));
1781
- }
1782
- );
1783
- var event_prompt_default = EventPrompt;
1784
-
1785
- // src/timeline.tsx
1786
- var Timeline = ({
1787
- rows,
1788
- events,
1789
- staticEvents,
1790
- onDrop,
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 };
1858
- }
1859
- });
1860
- setRowsHeight(tempRowsHeight);
1861
- }, [rows]);
1862
- use_resize_observer_default({ contentRef, setCellWidth, setTick, windowTime });
1863
- const eventPrompt = (0, import_react23.useMemo)(
1864
- () => /* @__PURE__ */ import_react23.default.createElement(
1865
- event_prompt_default,
1866
- {
1867
- ref: eventPromptRef,
1868
- template: eventPromptTemplate
1869
- }
1870
- ),
1871
- [eventPromptTemplate]
1872
- );
1873
- return /* @__PURE__ */ import_react23.default.createElement("div", { className: "main-wrapper", ref: mainRef }, showRTIndicator && /* @__PURE__ */ import_react23.default.createElement(rt_indicator_default, { tick, windowTime }), /* @__PURE__ */ import_react23.default.createElement(
1874
- time_bar_default,
1875
- {
1876
- windowTime,
1877
- tick,
1878
- contentWidth: contentRef.current ? contentRef.current.getBoundingClientRect().width : null,
1879
- scrollWidth
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
1891
- }
1892
- ),
1893
- /* @__PURE__ */ import_react23.default.createElement(DragStartedContext.Provider, { value: { dragStarted, setDragStarted } }, /* @__PURE__ */ import_react23.default.createElement(
1894
- ExternalPropertiesContext.Provider,
1895
- {
1896
- value: { onDrop, onResize, eventsResize, eventPromptRef }
1897
- },
1898
- /* @__PURE__ */ import_react23.default.createElement(
1899
- content_default,
1900
- {
1901
- events: internalEvents,
1902
- staticEvents,
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
1914
- }
1915
- ),
1916
- showEventPrompt && eventPrompt
1917
- ))
1918
- )));
1919
- };
1920
- // Annotate the CommonJS export names for ESM import in node:
1921
- 0 && (module.exports = {
1922
- Timeline
1923
- });
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __defProps = Object.defineProperties;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
+ var __getProtoOf = Object.getPrototypeOf;
10
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
11
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
12
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
+ var __spreadValues = (a, b) => {
14
+ for (var prop in b || (b = {}))
15
+ if (__hasOwnProp.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ if (__getOwnPropSymbols)
18
+ for (var prop of __getOwnPropSymbols(b)) {
19
+ if (__propIsEnum.call(b, prop))
20
+ __defNormalProp(a, prop, b[prop]);
21
+ }
22
+ return a;
23
+ };
24
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
25
+ var __export = (target, all) => {
26
+ for (var name in all)
27
+ __defProp(target, name, { get: all[name], enumerable: true });
28
+ };
29
+ var __copyProps = (to, from, except, desc) => {
30
+ if (from && typeof from === "object" || typeof from === "function") {
31
+ for (let key of __getOwnPropNames(from))
32
+ if (!__hasOwnProp.call(to, key) && key !== except)
33
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
34
+ }
35
+ return to;
36
+ };
37
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
38
+ // If the importer is in node compatibility mode or this is not an ESM
39
+ // file that has been converted to a CommonJS file using a Babel-
40
+ // compatible transform (i.e. "__esModule" has not been set), then set
41
+ // "default" to the CommonJS "module.exports" for node compatibility.
42
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
43
+ mod
44
+ ));
45
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
46
+
47
+ // src/index.ts
48
+ var index_exports = {};
49
+ __export(index_exports, {
50
+ Timeline: () => Timeline
51
+ });
52
+ module.exports = __toCommonJS(index_exports);
53
+
54
+ // src/timeline.tsx
55
+ var import_react7 = __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;
264
+
265
+ // src/components/canvas-time-bar.tsx
266
+ var import_react4 = __toESM(require("react"));
267
+
268
+ // src/helpers/get-month-name.ts
269
+ var getMonthName = (monthIndex) => {
270
+ let monthName = null;
271
+ switch (monthIndex) {
272
+ case 0:
273
+ monthName = "Jan";
274
+ break;
275
+ case 1:
276
+ monthName = "Feb";
277
+ break;
278
+ case 2:
279
+ monthName = "Mar";
280
+ break;
281
+ case 3:
282
+ monthName = "Apr";
283
+ break;
284
+ case 4:
285
+ monthName = "May";
286
+ break;
287
+ case 5:
288
+ monthName = "Jun";
289
+ break;
290
+ case 6:
291
+ monthName = "Jul";
292
+ break;
293
+ case 7:
294
+ monthName = "Aug";
295
+ break;
296
+ case 8:
297
+ monthName = "Sep";
298
+ break;
299
+ case 9:
300
+ monthName = "Oct";
301
+ break;
302
+ case 10:
303
+ monthName = "Nov";
304
+ break;
305
+ case 11:
306
+ monthName = "Dec";
307
+ break;
308
+ default:
309
+ monthName = "Jan";
310
+ }
311
+ return monthName;
312
+ };
313
+ var get_month_name_default = getMonthName;
314
+
315
+ // src/helpers/get-week-day-name.ts
316
+ var WEEKDAY_NAMES = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
317
+ var getWeekDayName = (dayIndex) => {
318
+ var _a;
319
+ return (_a = WEEKDAY_NAMES[dayIndex]) != null ? _a : "Sun";
320
+ };
321
+ var get_week_day_name_default = getWeekDayName;
322
+
323
+ // src/core/time-blocks.ts
324
+ var pad2 = (n) => n < 10 ? `0${n}` : `${n}`;
325
+ var hourLabel = (hour) => `${pad2(hour)}:00`;
326
+ var dayLabel = (date) => `${get_week_day_name_default(date.getDay())} ${date.getDate()} ${get_month_name_default(
327
+ date.getMonth()
328
+ )}`;
329
+ var defaultFormat = (unit) => {
330
+ if (typeof unit === "object") {
331
+ return (d) => `${pad2(d.getHours())}:${pad2(d.getMinutes())}`;
332
+ }
333
+ switch (unit) {
334
+ case "hour":
335
+ return (d) => hourLabel(d.getHours());
336
+ case "month":
337
+ return (d) => `${get_month_name_default(d.getMonth())} ${d.getFullYear()}`;
338
+ case "day":
339
+ case "week":
340
+ default:
341
+ return (d) => dayLabel(d);
342
+ }
343
+ };
344
+ var floorToUnit = (date, unit, anchorSec) => {
345
+ if (typeof unit === "object") {
346
+ const t = date.getTime() / 1e3;
347
+ const step = unit.stepSeconds;
348
+ return new Date((anchorSec + Math.floor((t - anchorSec) / step) * step) * 1e3);
349
+ }
350
+ const y = date.getFullYear();
351
+ const mo = date.getMonth();
352
+ const d = date.getDate();
353
+ switch (unit) {
354
+ case "hour":
355
+ return new Date(y, mo, d, date.getHours());
356
+ case "day":
357
+ return new Date(y, mo, d);
358
+ case "week": {
359
+ const dow = (date.getDay() + 6) % 7;
360
+ return new Date(y, mo, d - dow);
361
+ }
362
+ case "month":
363
+ return new Date(y, mo, 1);
364
+ }
365
+ };
366
+ var nextBoundary = (blockStart, unit) => {
367
+ if (typeof unit === "object") {
368
+ return new Date(blockStart.getTime() + unit.stepSeconds * 1e3);
369
+ }
370
+ const y = blockStart.getFullYear();
371
+ const mo = blockStart.getMonth();
372
+ const d = blockStart.getDate();
373
+ switch (unit) {
374
+ case "hour":
375
+ return new Date(y, mo, d, blockStart.getHours() + 1);
376
+ case "day":
377
+ return new Date(y, mo, d + 1);
378
+ case "week":
379
+ return new Date(y, mo, d + 7);
380
+ case "month":
381
+ return new Date(y, mo + 1, 1);
382
+ }
383
+ };
384
+ var generateUnitBlocks = ({
385
+ unit,
386
+ format,
387
+ windowStart,
388
+ windowEnd,
389
+ tick
390
+ }) => {
391
+ const blocks = [];
392
+ const resolvedUnit = unit != null ? unit : "hour";
393
+ if (tick === null || tick <= 0 || windowEnd <= windowStart) return blocks;
394
+ const label = format != null ? format : defaultFormat(resolvedUnit);
395
+ const anchorSec = new Date(
396
+ new Date(windowStart * 1e3).getFullYear(),
397
+ new Date(windowStart * 1e3).getMonth(),
398
+ new Date(windowStart * 1e3).getDate()
399
+ ).getTime() / 1e3;
400
+ let cursorSec = windowStart;
401
+ let guard = 0;
402
+ while (cursorSec < windowEnd && guard++ < 1e5) {
403
+ const blockStart = floorToUnit(new Date(cursorSec * 1e3), resolvedUnit, anchorSec);
404
+ const blockEnd = nextBoundary(blockStart, resolvedUnit);
405
+ const startSec = blockStart.getTime() / 1e3;
406
+ const endSec = blockEnd.getTime() / 1e3;
407
+ if (endSec <= startSec) break;
408
+ const visibleStart = Math.max(startSec, windowStart);
409
+ const visibleEnd = Math.min(endSec, windowEnd);
410
+ blocks.push({
411
+ label: label(blockStart, blockEnd),
412
+ x: (visibleStart - windowStart) / tick,
413
+ width: (visibleEnd - visibleStart) / tick
414
+ });
415
+ cursorSec = endSec;
416
+ }
417
+ return blocks;
418
+ };
419
+
420
+ // src/canvas/dpr.ts
421
+ var sizeCanvas = (canvas, cssWidth, cssHeight, dpr) => {
422
+ canvas.width = Math.max(1, Math.round(cssWidth * dpr));
423
+ canvas.height = Math.max(1, Math.round(cssHeight * dpr));
424
+ canvas.style.width = `${cssWidth}px`;
425
+ canvas.style.height = `${cssHeight}px`;
426
+ const ctx = canvas.getContext("2d");
427
+ if (ctx) {
428
+ ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
429
+ }
430
+ return ctx;
431
+ };
432
+ var watchDpr = (onChange) => {
433
+ let disposed = false;
434
+ let cleanup = () => {
435
+ };
436
+ const listen = () => {
437
+ if (disposed) return;
438
+ const media = window.matchMedia(
439
+ `(resolution: ${window.devicePixelRatio}dppx)`
440
+ );
441
+ const handler = () => {
442
+ onChange(window.devicePixelRatio);
443
+ media.removeEventListener("change", handler);
444
+ listen();
445
+ };
446
+ media.addEventListener("change", handler);
447
+ cleanup = () => media.removeEventListener("change", handler);
448
+ };
449
+ listen();
450
+ return () => {
451
+ disposed = true;
452
+ cleanup();
453
+ };
454
+ };
455
+
456
+ // src/canvas/theme.ts
457
+ var DEFAULT_THEME = {
458
+ eventFill: "#ffffff",
459
+ eventStroke: "#000000",
460
+ eventTextColor: "#000000",
461
+ staticEventFill: "#e0e0e0",
462
+ gridColor: "#e4dcdc",
463
+ timeBarBorder: "yellow",
464
+ timeBarTextColor: "white",
465
+ font: void 0,
466
+ barHeight: 20,
467
+ laneGap: 2,
468
+ rowPaddingY: 10,
469
+ barRadius: 5
470
+ };
471
+ var resolveTheme = (theme) => __spreadValues(__spreadValues({}, DEFAULT_THEME), theme);
472
+
473
+ // src/canvas/draw-grid.ts
474
+ var drawGridLines = (ctx, {
475
+ width,
476
+ height,
477
+ cellWidth,
478
+ windowStart,
479
+ tick,
480
+ color = DEFAULT_THEME.gridColor
481
+ }) => {
482
+ if (cellWidth <= 0 || tick <= 0) return;
483
+ const cellTime = cellWidth * tick;
484
+ ctx.strokeStyle = color;
485
+ ctx.lineWidth = 1;
486
+ ctx.beginPath();
487
+ for (let t = Math.floor(windowStart / cellTime) * cellTime + cellTime; ; t += cellTime) {
488
+ const x = (t - windowStart) / tick;
489
+ if (x >= width || width - x < 1) break;
490
+ if (x < 1) continue;
491
+ const crisp = Math.round(x) - 0.5;
492
+ ctx.moveTo(crisp, 0);
493
+ ctx.lineTo(crisp, height);
494
+ }
495
+ ctx.stroke();
496
+ };
497
+ var drawTimeBar = (ctx, {
498
+ width,
499
+ height,
500
+ topBlocks,
501
+ bottomBlocks,
502
+ font,
503
+ borderColor = DEFAULT_THEME.timeBarBorder,
504
+ textColor = DEFAULT_THEME.timeBarTextColor
505
+ }) => {
506
+ const mid = height / 2;
507
+ ctx.strokeStyle = borderColor;
508
+ ctx.lineWidth = 1;
509
+ ctx.beginPath();
510
+ ctx.moveTo(0, Math.round(mid) - 0.5);
511
+ ctx.lineTo(width, Math.round(mid) - 0.5);
512
+ ctx.stroke();
513
+ ctx.beginPath();
514
+ for (let i = 0; i < topBlocks.length - 1; i++) {
515
+ const edge = Math.round(topBlocks[i].x + topBlocks[i].width) - 0.5;
516
+ ctx.moveTo(edge, 0);
517
+ ctx.lineTo(edge, mid);
518
+ }
519
+ for (let i = 0; i < bottomBlocks.length - 1; i++) {
520
+ const edge = Math.round(bottomBlocks[i].x + bottomBlocks[i].width) - 0.5;
521
+ ctx.moveTo(edge, mid);
522
+ ctx.lineTo(edge, height);
523
+ }
524
+ ctx.stroke();
525
+ ctx.fillStyle = textColor;
526
+ ctx.font = font;
527
+ ctx.textBaseline = "middle";
528
+ ctx.textAlign = "center";
529
+ const inset = 4;
530
+ for (const block of topBlocks) {
531
+ ctx.fillText(
532
+ block.label,
533
+ block.x + block.width / 2,
534
+ mid / 2,
535
+ block.width - inset
536
+ );
537
+ }
538
+ for (const block of bottomBlocks) {
539
+ ctx.fillText(
540
+ block.label,
541
+ block.x + block.width / 2,
542
+ mid + mid / 2,
543
+ block.width - inset
544
+ );
545
+ }
546
+ };
547
+
548
+ // src/components/canvas-time-bar.tsx
549
+ var TIME_BAR_INNER_HEIGHT = 48;
550
+ var CanvasTimeBar = ({
551
+ windowTime,
552
+ tick,
553
+ contentWidth,
554
+ scrollWidth,
555
+ theme,
556
+ timeBar
557
+ }) => {
558
+ var _a, _b;
559
+ const canvasRef = (0, import_react4.useRef)(null);
560
+ const topRow = (_a = timeBar == null ? void 0 : timeBar.topRow) != null ? _a : { unit: "day" };
561
+ const bottomRow = (_b = timeBar == null ? void 0 : timeBar.bottomRow) != null ? _b : { unit: "hour" };
562
+ (0, import_react4.useEffect)(() => {
563
+ var _a2;
564
+ const canvas = canvasRef.current;
565
+ if (!canvas || !contentWidth) return;
566
+ const ctx = sizeCanvas(
567
+ canvas,
568
+ contentWidth,
569
+ TIME_BAR_INNER_HEIGHT,
570
+ window.devicePixelRatio
571
+ );
572
+ if (!ctx) return;
573
+ const [windowStart, windowEnd] = windowTime;
574
+ drawTimeBar(ctx, {
575
+ width: contentWidth,
576
+ height: TIME_BAR_INNER_HEIGHT,
577
+ font: (_a2 = theme == null ? void 0 : theme.font) != null ? _a2 : getComputedStyle(canvas).font,
578
+ borderColor: theme == null ? void 0 : theme.timeBarBorder,
579
+ textColor: theme == null ? void 0 : theme.timeBarTextColor,
580
+ topBlocks: generateUnitBlocks(__spreadProps(__spreadValues({}, topRow), { windowStart, windowEnd, tick })),
581
+ bottomBlocks: generateUnitBlocks(__spreadProps(__spreadValues({}, bottomRow), {
582
+ windowStart,
583
+ windowEnd,
584
+ tick
585
+ }))
586
+ });
587
+ }, [windowTime, tick, contentWidth, theme, timeBar]);
588
+ return /* @__PURE__ */ import_react4.default.createElement("div", { className: "time-bar" }, /* @__PURE__ */ import_react4.default.createElement("div", { className: "empty-block" }), /* @__PURE__ */ import_react4.default.createElement(
589
+ "canvas",
590
+ {
591
+ ref: canvasRef,
592
+ className: "canvas-time-bar",
593
+ style: { minWidth: contentWidth ? contentWidth : 0 }
594
+ }
595
+ ), scrollWidth ? /* @__PURE__ */ import_react4.default.createElement(
596
+ "div",
597
+ {
598
+ style: {
599
+ width: scrollWidth,
600
+ height: "100%",
601
+ boxSizing: "border-box",
602
+ borderLeft: "1px solid yellow"
603
+ }
604
+ }
605
+ ) : null);
606
+ };
607
+ var canvas_time_bar_default = CanvasTimeBar;
608
+
609
+ // src/components/canvas-board.tsx
610
+ var import_react6 = __toESM(require("react"));
611
+
612
+ // src/canvas/frame-scheduler.ts
613
+ var FrameScheduler = class {
614
+ constructor(onFrame) {
615
+ this.onFrame = onFrame;
616
+ this.rafId = null;
617
+ this.dirty = { static: false, dynamic: false };
618
+ }
619
+ invalidate(layer) {
620
+ if (layer === "all" || layer === "static") this.dirty.static = true;
621
+ if (layer === "all" || layer === "dynamic") this.dirty.dynamic = true;
622
+ this.schedule();
623
+ }
624
+ /** Runs a pending frame immediately (tests, synchronous reads). */
625
+ flush() {
626
+ if (this.rafId !== null) {
627
+ cancelAnimationFrame(this.rafId);
628
+ this.rafId = null;
629
+ this.run();
630
+ }
631
+ }
632
+ dispose() {
633
+ if (this.rafId !== null) {
634
+ cancelAnimationFrame(this.rafId);
635
+ this.rafId = null;
636
+ }
637
+ this.dirty = { static: false, dynamic: false };
638
+ }
639
+ schedule() {
640
+ if (this.rafId !== null) return;
641
+ this.rafId = requestAnimationFrame(() => {
642
+ this.rafId = null;
643
+ this.run();
644
+ });
645
+ }
646
+ run() {
647
+ const dirty = this.dirty;
648
+ this.dirty = { static: false, dynamic: false };
649
+ if (dirty.static || dirty.dynamic) this.onFrame(dirty);
650
+ }
651
+ };
652
+
653
+ // src/core/culling.ts
654
+ var cullToWindow = (events, windowStart, windowEnd) => {
655
+ let lo = 0;
656
+ let hi = events.length;
657
+ while (lo < hi) {
658
+ const mid = lo + hi >> 1;
659
+ if (events[mid].startTime <= windowEnd) {
660
+ lo = mid + 1;
661
+ } else {
662
+ hi = mid;
663
+ }
664
+ }
665
+ const visible = [];
666
+ for (let i = 0; i < lo; i++) {
667
+ if (events[i].endTime >= windowStart) visible.push(events[i]);
668
+ }
669
+ return visible;
670
+ };
671
+
672
+ // src/core/coords.ts
673
+ var timeToX = (time, windowStart, tick) => (time - windowStart) / tick;
674
+ var timeToWidth = (startTime, endTime, tick) => (endTime - startTime) / tick;
675
+ var intersectsWindow = (event, windowStart, windowEnd) => event.endTime >= windowStart && event.startTime <= windowEnd;
676
+
677
+ // src/core/geometry.ts
678
+ var DEFAULT_GEOMETRY = {
679
+ barHeight: 20,
680
+ laneHeight: 22,
681
+ laneTopOffset: 10,
682
+ rowBaseHeight: 40,
683
+ staticEventBaseHeight: 20,
684
+ barRadius: 5
685
+ };
686
+ var geometryFromTheme = (theme) => {
687
+ const barHeight = theme.barHeight;
688
+ const rowPaddingY = theme.rowPaddingY;
689
+ return {
690
+ barHeight,
691
+ laneHeight: barHeight + theme.laneGap,
692
+ laneTopOffset: rowPaddingY,
693
+ rowBaseHeight: barHeight + 2 * rowPaddingY,
694
+ staticEventBaseHeight: barHeight,
695
+ barRadius: theme.barRadius
696
+ };
697
+ };
698
+
699
+ // src/core/lanes.ts
700
+ var laneTop = (lane, g = DEFAULT_GEOMETRY) => g.laneTopOffset + g.laneHeight * lane;
701
+ var rowMinHeight = (highestLane, g = DEFAULT_GEOMETRY) => g.rowBaseHeight + highestLane * g.laneHeight;
702
+ var staticEventHeight = (highestLane, g = DEFAULT_GEOMETRY) => g.staticEventBaseHeight + highestLane * g.laneHeight;
703
+ var assignLanes = (rowEvents, windowStart, windowEnd) => {
704
+ let eventOrder = 0;
705
+ const prevEvent = [];
706
+ let highestEventOrder = 0;
707
+ const laneOf = /* @__PURE__ */ new Map();
708
+ for (const event of rowEvents) {
709
+ if (!intersectsWindow(event, windowStart, windowEnd)) continue;
710
+ let tempEventOrder = 0;
711
+ let assignEventOrder = true;
712
+ for (let i = 0; i <= eventOrder; i++) {
713
+ if (prevEvent[i] && prevEvent[i].endTime > event.startTime) {
714
+ tempEventOrder += 1;
715
+ } else {
716
+ if (eventOrder > highestEventOrder) {
717
+ highestEventOrder = eventOrder;
718
+ }
719
+ eventOrder = 0;
720
+ assignEventOrder = false;
721
+ break;
722
+ }
723
+ }
724
+ if (assignEventOrder) {
725
+ eventOrder = tempEventOrder;
726
+ }
727
+ prevEvent[tempEventOrder] = event;
728
+ laneOf.set(event.id, tempEventOrder);
729
+ }
730
+ if (eventOrder > highestEventOrder) {
731
+ highestEventOrder = eventOrder;
732
+ }
733
+ return { laneOf, highestLane: highestEventOrder };
734
+ };
735
+
736
+ // src/core/interactions.ts
737
+ var computeDropTimes = ({
738
+ pointerX,
739
+ cellWidth,
740
+ tick,
741
+ windowStart,
742
+ duration
743
+ }) => {
744
+ const cellTime = cellWidth * tick;
745
+ const pointerTime = windowStart + pointerX * tick;
746
+ const startTime = Math.round(pointerTime / cellTime) * cellTime;
747
+ return { startTime, endTime: startTime + duration };
748
+ };
749
+ var computeResizeTimes = (event, deltaPx, tick, direction) => {
750
+ if (direction === "left") {
751
+ const startTime = Math.round(event.startTime + deltaPx * tick);
752
+ if (event.endTime - startTime > 0) {
753
+ return { startTime, endTime: event.endTime };
754
+ }
755
+ return null;
756
+ }
757
+ const endTime = Math.round(event.endTime + deltaPx * tick);
758
+ if (endTime - event.startTime > 0) {
759
+ return { startTime: event.startTime, endTime };
760
+ }
761
+ return null;
762
+ };
763
+ var canResizeEvent = (event, eventsResize) => {
764
+ var _a, _b, _c, _d;
765
+ 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);
766
+ };
767
+ var stepCellWidth = (cellWidth, deltaY, tick) => {
768
+ const pixelsToCalculate = 900 / tick;
769
+ const next = deltaY > 0 ? cellWidth + pixelsToCalculate : cellWidth - pixelsToCalculate;
770
+ if (next < pixelsToCalculate || next > pixelsToCalculate * 12) {
771
+ return cellWidth;
772
+ }
773
+ return next;
774
+ };
775
+ var computeZoom = (windowTime, tick, cellWidth, anchorX, factor, contentWidth, { minWindowSeconds, maxWindowSeconds }) => {
776
+ const [start, end] = windowTime;
777
+ const oldDuration = end - start;
778
+ const newDuration = Math.min(
779
+ Math.max(oldDuration * factor, minWindowSeconds),
780
+ maxWindowSeconds
781
+ );
782
+ const cellTime = cellWidth * tick;
783
+ const tAnchor = start + anchorX * tick;
784
+ const newStart = Math.round(tAnchor - anchorX / contentWidth * newDuration);
785
+ const newEnd = newStart + Math.round(newDuration);
786
+ const newTick = (newEnd - newStart) / contentWidth;
787
+ return {
788
+ windowTime: [newStart, newEnd],
789
+ tick: newTick,
790
+ cellWidth: cellTime / newTick
791
+ };
792
+ };
793
+
794
+ // src/canvas/draw-events.ts
795
+ var EVENT_TEXT_INSET = 13;
796
+ var HANDLE_INSET = 4;
797
+ var HANDLE_BAR_WIDTH = 3;
798
+ var HANDLE_BAR_GAP = 1;
799
+ var HANDLE_BAR_HEIGHT = 10;
800
+ var roundedRect = (ctx, x, y, width, height, radius) => {
801
+ const r = Math.min(radius, width / 2, height / 2);
802
+ ctx.beginPath();
803
+ if (typeof ctx.roundRect === "function") {
804
+ ctx.roundRect(x, y, width, height, r);
805
+ } else {
806
+ ctx.moveTo(x + r, y);
807
+ ctx.arcTo(x + width, y, x + width, y + height, r);
808
+ ctx.arcTo(x + width, y + height, x, y + height, r);
809
+ ctx.arcTo(x, y + height, x, y, r);
810
+ ctx.arcTo(x, y, x + width, y, r);
811
+ ctx.closePath();
812
+ }
813
+ };
814
+ var drawRowDividers = (ctx, view, scene, animator) => {
815
+ const [windowStart, windowEnd] = view.windowTime;
816
+ const rowIds = scene.getRowIds();
817
+ ctx.strokeStyle = view.theme.gridColor;
818
+ ctx.lineWidth = 1;
819
+ ctx.beginPath();
820
+ let y = 0;
821
+ for (let i = 0; i < rowIds.length; i++) {
822
+ y += animator.rowHeight(
823
+ rowIds[i],
824
+ scene.getRowHeight(rowIds[i], windowStart, windowEnd)
825
+ );
826
+ if (i === rowIds.length - 1) break;
827
+ const screenY = y - view.scrollTop;
828
+ if (screenY < 0) continue;
829
+ if (screenY > view.height) break;
830
+ const crisp = Math.round(screenY) - 0.5;
831
+ ctx.moveTo(0, crisp);
832
+ ctx.lineTo(view.width, crisp);
833
+ }
834
+ ctx.stroke();
835
+ };
836
+ var drawResizeHandles = (ctx, rect, alpha, strokeColor) => {
837
+ ctx.save();
838
+ ctx.globalAlpha *= alpha;
839
+ ctx.strokeStyle = strokeColor;
840
+ ctx.lineWidth = 1;
841
+ const barY = rect.y + (rect.height - HANDLE_BAR_HEIGHT) / 2;
842
+ const xs = [
843
+ rect.x + HANDLE_INSET,
844
+ rect.x + HANDLE_INSET + HANDLE_BAR_WIDTH + HANDLE_BAR_GAP,
845
+ rect.x + rect.width - HANDLE_INSET - HANDLE_BAR_WIDTH,
846
+ rect.x + rect.width - HANDLE_INSET - HANDLE_BAR_WIDTH * 2 - HANDLE_BAR_GAP
847
+ ];
848
+ for (const barX of xs) {
849
+ ctx.beginPath();
850
+ if (typeof ctx.roundRect === "function") {
851
+ ctx.roundRect(
852
+ barX + 0.5,
853
+ barY + 0.5,
854
+ HANDLE_BAR_WIDTH - 1,
855
+ HANDLE_BAR_HEIGHT - 1,
856
+ 1.5
857
+ );
858
+ } else {
859
+ ctx.rect(barX + 0.5, barY + 0.5, HANDLE_BAR_WIDTH - 1, HANDLE_BAR_HEIGHT - 1);
860
+ }
861
+ ctx.stroke();
862
+ }
863
+ ctx.restore();
864
+ };
865
+ var defaultDrawEvent = (ctx, event, rect, view, font, barRadius) => {
866
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
867
+ const theme = view.theme;
868
+ const style = (_a = event.props) == null ? void 0 : _a.style;
869
+ if ((style == null ? void 0 : style.opacity) !== void 0) ctx.globalAlpha *= style.opacity;
870
+ ctx.fillStyle = (_b = style == null ? void 0 : style.fill) != null ? _b : theme.eventFill;
871
+ ctx.strokeStyle = (_c = style == null ? void 0 : style.stroke) != null ? _c : theme.eventStroke;
872
+ ctx.lineWidth = (_d = style == null ? void 0 : style.strokeWidth) != null ? _d : 1;
873
+ roundedRect(
874
+ ctx,
875
+ rect.x + 0.5,
876
+ rect.y + 0.5,
877
+ rect.width - 1,
878
+ rect.height - 1,
879
+ (_e = style == null ? void 0 : style.borderRadius) != null ? _e : barRadius
880
+ );
881
+ ctx.fill();
882
+ ctx.stroke();
883
+ const label = (_f = event.props) == null ? void 0 : _f.label;
884
+ if (label && rect.width > EVENT_TEXT_INSET * 2) {
885
+ ctx.fillStyle = (_g = style == null ? void 0 : style.textColor) != null ? _g : theme.eventTextColor;
886
+ ctx.font = (_i = (_h = style == null ? void 0 : style.font) != null ? _h : theme.font) != null ? _i : font;
887
+ ctx.save();
888
+ ctx.beginPath();
889
+ ctx.rect(
890
+ rect.x + EVENT_TEXT_INSET,
891
+ rect.y,
892
+ rect.width - EVENT_TEXT_INSET * 2,
893
+ rect.height
894
+ );
895
+ ctx.clip();
896
+ ctx.fillText(label, rect.x + EVENT_TEXT_INSET, rect.y + rect.height / 2);
897
+ ctx.restore();
898
+ }
899
+ };
900
+ var drawEvents = (ctx, view, scene, font, animator) => {
901
+ var _a, _b, _c, _d, _e, _f;
902
+ if (view.tick === null) return;
903
+ const [windowStart, windowEnd] = view.windowTime;
904
+ const tick = view.tick;
905
+ const geometry = scene.getGeometry();
906
+ ctx.font = (_a = view.theme.font) != null ? _a : font;
907
+ ctx.textBaseline = "middle";
908
+ ctx.textAlign = "left";
909
+ let rowTop = 0;
910
+ for (const rowId of scene.getRowIds()) {
911
+ const rowHeight = animator.rowHeight(
912
+ rowId,
913
+ scene.getRowHeight(rowId, windowStart, windowEnd)
914
+ );
915
+ const rowY = rowTop - view.scrollTop;
916
+ rowTop += rowHeight;
917
+ if (rowY + rowHeight < 0) continue;
918
+ if (rowY > view.height) break;
919
+ const lanes = scene.getLanes(rowId, windowStart, windowEnd);
920
+ for (const event of cullToWindow(
921
+ scene.getRowStaticEvents(rowId),
922
+ windowStart,
923
+ windowEnd
924
+ )) {
925
+ const x = timeToX(event.startTime, windowStart, tick);
926
+ const width = timeToWidth(event.startTime, event.endTime, tick);
927
+ ctx.fillStyle = view.theme.staticEventFill;
928
+ roundedRect(
929
+ ctx,
930
+ x,
931
+ rowY + geometry.laneTopOffset,
932
+ width,
933
+ staticEventHeight(lanes.highestLane, geometry),
934
+ geometry.barRadius
935
+ );
936
+ ctx.fill();
937
+ }
938
+ for (const event of cullToWindow(
939
+ scene.getRowEvents(rowId),
940
+ windowStart,
941
+ windowEnd
942
+ )) {
943
+ let x = timeToX(event.startTime, windowStart, tick);
944
+ let width = timeToWidth(event.startTime, event.endTime, tick);
945
+ const y = rowY + animator.eventTop(
946
+ event.id,
947
+ laneTop(lanes.laneOf.get(event.id), geometry)
948
+ );
949
+ const resize = view.resizePreview;
950
+ const resizing = resize !== null && resize.eventId === event.id;
951
+ if (resizing) {
952
+ if (resize.direction === "left") {
953
+ x += resize.deltaPx;
954
+ width -= resize.deltaPx;
955
+ } else {
956
+ width += resize.deltaPx;
957
+ }
958
+ }
959
+ const rect = { x, y, width, height: geometry.barHeight };
960
+ const state = {
961
+ hovered: view.hoveredEventId === event.id,
962
+ dragging: view.draggedEventId === event.id,
963
+ resizing,
964
+ selected: false
965
+ };
966
+ ctx.save();
967
+ if (state.dragging) ctx.globalAlpha = 0.5;
968
+ const custom = (_c = (_b = event.props) == null ? void 0 : _b.drawEvent) != null ? _c : view.drawEvent;
969
+ const drawn = custom !== void 0 && custom(ctx, event, rect, state, view.theme) !== false;
970
+ if (!drawn) {
971
+ defaultDrawEvent(ctx, event, rect, view, font, geometry.barRadius);
972
+ }
973
+ if (canResizeEvent(event, view.eventsResize)) {
974
+ const alpha = animator.handleAlpha(
975
+ event.id,
976
+ state.hovered || state.resizing ? 1 : 0
977
+ );
978
+ if (alpha > 0.01) {
979
+ drawResizeHandles(
980
+ ctx,
981
+ rect,
982
+ alpha,
983
+ (_f = (_e = (_d = event.props) == null ? void 0 : _d.style) == null ? void 0 : _e.stroke) != null ? _f : view.theme.eventStroke
984
+ );
985
+ }
986
+ }
987
+ ctx.restore();
988
+ }
989
+ }
990
+ };
991
+
992
+ // src/canvas/renderer.ts
993
+ var TimelineRenderer = class {
994
+ constructor(staticCanvas, dynamicCanvas, scene) {
995
+ this.staticCanvas = staticCanvas;
996
+ this.dynamicCanvas = dynamicCanvas;
997
+ this.scene = scene;
998
+ this.view = {
999
+ windowTime: [0, 0],
1000
+ tick: null,
1001
+ cellWidth: 0,
1002
+ scrollTop: 0,
1003
+ width: 0,
1004
+ height: 0,
1005
+ theme: DEFAULT_THEME,
1006
+ drawEvent: void 0,
1007
+ eventsResize: true,
1008
+ hoveredEventId: null,
1009
+ draggedEventId: null,
1010
+ resizePreview: null
1011
+ };
1012
+ this.animator = new LayoutAnimator();
1013
+ this.dpr = typeof window !== "undefined" ? window.devicePixelRatio : 1;
1014
+ this.font = "16px sans-serif";
1015
+ this.scheduler = new FrameScheduler((dirty) => this.drawFrame(dirty));
1016
+ this.unsubscribeScene = scene.subscribe(() => this.invalidate("all"));
1017
+ this.unwatchDpr = watchDpr((dpr) => {
1018
+ this.dpr = dpr;
1019
+ this.resizeCanvases();
1020
+ this.invalidate("all");
1021
+ });
1022
+ }
1023
+ getView() {
1024
+ return this.view;
1025
+ }
1026
+ setView(partial) {
1027
+ const sizeChanged = partial.width !== void 0 && partial.width !== this.view.width || partial.height !== void 0 && partial.height !== this.view.height;
1028
+ this.view = __spreadValues(__spreadValues({}, this.view), partial);
1029
+ if (sizeChanged) {
1030
+ this.resizeCanvases();
1031
+ this.invalidate("all");
1032
+ return;
1033
+ }
1034
+ this.invalidate("all");
1035
+ }
1036
+ invalidate(layer) {
1037
+ this.scheduler.invalidate(layer);
1038
+ }
1039
+ /** Force a synchronous draw of anything pending (tests, screenshots). */
1040
+ flush() {
1041
+ this.scheduler.flush();
1042
+ }
1043
+ dispose() {
1044
+ this.scheduler.dispose();
1045
+ this.unsubscribeScene();
1046
+ this.unwatchDpr();
1047
+ }
1048
+ resizeCanvases() {
1049
+ sizeCanvas(this.staticCanvas, this.view.width, this.view.height, this.dpr);
1050
+ sizeCanvas(this.dynamicCanvas, this.view.width, this.view.height, this.dpr);
1051
+ if (typeof getComputedStyle === "function") {
1052
+ this.font = getComputedStyle(this.dynamicCanvas).font || this.font;
1053
+ }
1054
+ }
1055
+ drawFrame(dirty) {
1056
+ if (this.view.tick === null) return;
1057
+ this.animator.beginFrame(performance.now());
1058
+ if (dirty.static) {
1059
+ const ctx = this.staticCanvas.getContext("2d");
1060
+ if (ctx) {
1061
+ ctx.clearRect(0, 0, this.view.width, this.view.height);
1062
+ drawGridLines(ctx, {
1063
+ width: this.view.width,
1064
+ height: this.view.height,
1065
+ cellWidth: this.view.cellWidth,
1066
+ windowStart: this.view.windowTime[0],
1067
+ tick: this.view.tick,
1068
+ color: this.view.theme.gridColor
1069
+ });
1070
+ drawRowDividers(ctx, this.view, this.scene, this.animator);
1071
+ }
1072
+ }
1073
+ if (dirty.dynamic) {
1074
+ const ctx = this.dynamicCanvas.getContext("2d");
1075
+ if (ctx) {
1076
+ ctx.clearRect(0, 0, this.view.width, this.view.height);
1077
+ drawEvents(ctx, this.view, this.scene, this.font, this.animator);
1078
+ }
1079
+ }
1080
+ if (this.animator.isAnimating()) {
1081
+ this.scheduler.invalidate("all");
1082
+ }
1083
+ }
1084
+ };
1085
+
1086
+ // src/hooks/use-canvas-interactions.ts
1087
+ var import_react5 = require("react");
1088
+
1089
+ // src/core/types.ts
1090
+ var rectContains = (rect, x, y) => x >= rect.x && x <= rect.x + rect.width && y >= rect.y && y <= rect.y + rect.height;
1091
+
1092
+ // src/core/hit-test.ts
1093
+ var hitTest = (scene, view, x, y) => {
1094
+ const { windowStart, windowEnd, tick, scrollTop } = view;
1095
+ const geometry = scene.getGeometry();
1096
+ const yContent = y + scrollTop;
1097
+ let rowTop = 0;
1098
+ let rowId = null;
1099
+ for (const id of scene.getRowIds()) {
1100
+ const height = scene.getRowHeight(id, windowStart, windowEnd);
1101
+ if (yContent >= rowTop && yContent < rowTop + height) {
1102
+ rowId = id;
1103
+ break;
1104
+ }
1105
+ rowTop += height;
1106
+ }
1107
+ if (rowId === null) return null;
1108
+ const lanes = scene.getLanes(rowId, windowStart, windowEnd);
1109
+ const rowY = rowTop - scrollTop;
1110
+ const events = cullToWindow(
1111
+ scene.getRowEvents(rowId),
1112
+ windowStart,
1113
+ windowEnd
1114
+ );
1115
+ for (let i = events.length - 1; i >= 0; i--) {
1116
+ const event = events[i];
1117
+ const rect = {
1118
+ x: timeToX(event.startTime, windowStart, tick),
1119
+ y: rowY + laneTop(lanes.laneOf.get(event.id), geometry),
1120
+ width: timeToWidth(event.startTime, event.endTime, tick),
1121
+ height: geometry.barHeight
1122
+ };
1123
+ if (rectContains(rect, x, y)) {
1124
+ return { kind: "event", event, rowId, rect };
1125
+ }
1126
+ }
1127
+ const statics = cullToWindow(
1128
+ scene.getRowStaticEvents(rowId),
1129
+ windowStart,
1130
+ windowEnd
1131
+ );
1132
+ for (let i = statics.length - 1; i >= 0; i--) {
1133
+ const event = statics[i];
1134
+ const rect = {
1135
+ x: timeToX(event.startTime, windowStart, tick),
1136
+ y: rowY + geometry.laneTopOffset,
1137
+ width: timeToWidth(event.startTime, event.endTime, tick),
1138
+ height: staticEventHeight(lanes.highestLane, geometry)
1139
+ };
1140
+ if (rectContains(rect, x, y)) {
1141
+ return { kind: "static", event, rowId, rect };
1142
+ }
1143
+ }
1144
+ return null;
1145
+ };
1146
+
1147
+ // src/hooks/use-canvas-interactions.ts
1148
+ var DRAG_THRESHOLD_PX = 3;
1149
+ var RESIZE_HOT_ZONE_PX = 8;
1150
+ var DRAG_ZOOM_PX_PER_DOUBLING = 300;
1151
+ var lockCursor = (cursor) => {
1152
+ const style = document.createElement("style");
1153
+ style.id = "lock-cursor";
1154
+ style.innerHTML = `* { cursor: ${cursor} !important; }`;
1155
+ document.head.appendChild(style);
1156
+ };
1157
+ var unlockCursor = () => {
1158
+ var _a;
1159
+ (_a = document.getElementById("lock-cursor")) == null ? void 0 : _a.remove();
1160
+ };
1161
+ var useCanvasInteractions = ({
1162
+ scene,
1163
+ rendererRef,
1164
+ dynamicCanvasRef,
1165
+ bodyRef,
1166
+ ghostRef,
1167
+ eventPromptRef,
1168
+ setWindowTime,
1169
+ setCellWidth,
1170
+ setTick,
1171
+ onDrop,
1172
+ onResize,
1173
+ onEventClick,
1174
+ onEventHover,
1175
+ eventsResize,
1176
+ panZoom
1177
+ }) => {
1178
+ const stateRef = (0, import_react5.useRef)({ mode: "idle" });
1179
+ const changeGridRef = (0, import_react5.useRef)(false);
1180
+ const panFrameRef = (0, import_react5.useRef)(null);
1181
+ const panPendingDxRef = (0, import_react5.useRef)(0);
1182
+ const hoveredRef = (0, import_react5.useRef)(null);
1183
+ const pointersRef = (0, import_react5.useRef)(/* @__PURE__ */ new Map());
1184
+ const zoomFrameRef = (0, import_react5.useRef)(null);
1185
+ const zoomPendingRef = (0, import_react5.useRef)(null);
1186
+ const config = (0, import_react5.useMemo)(
1187
+ () => {
1188
+ var _a, _b, _c, _d, _e, _f, _g;
1189
+ return {
1190
+ panOnDragBackground: (_a = panZoom == null ? void 0 : panZoom.panOnDragBackground) != null ? _a : true,
1191
+ ctrlWheelZoom: (_b = panZoom == null ? void 0 : panZoom.ctrlWheelZoom) != null ? _b : true,
1192
+ pinchZoom: (_c = panZoom == null ? void 0 : panZoom.pinchZoom) != null ? _c : true,
1193
+ dragZoom: (_d = panZoom == null ? void 0 : panZoom.dragZoom) != null ? _d : true,
1194
+ zoomWheelFactor: (_e = panZoom == null ? void 0 : panZoom.zoomWheelFactor) != null ? _e : 1.15,
1195
+ middleClickGranularity: (_f = panZoom == null ? void 0 : panZoom.middleClickGranularity) != null ? _f : true,
1196
+ zoomStepSeconds: (_g = panZoom == null ? void 0 : panZoom.zoomStepSeconds) != null ? _g : 900
1197
+ };
1198
+ },
1199
+ [panZoom]
1200
+ );
1201
+ const limits = (0, import_react5.useMemo)(
1202
+ () => {
1203
+ var _a, _b;
1204
+ return {
1205
+ minWindowSeconds: (_a = panZoom == null ? void 0 : panZoom.minWindowSeconds) != null ? _a : 900,
1206
+ maxWindowSeconds: (_b = panZoom == null ? void 0 : panZoom.maxWindowSeconds) != null ? _b : 30 * 24 * 3600
1207
+ };
1208
+ },
1209
+ [panZoom]
1210
+ );
1211
+ const applyZoom = (0, import_react5.useCallback)(
1212
+ (base, anchorX, factor, contentWidth) => {
1213
+ var _a;
1214
+ if (contentWidth <= 0) return;
1215
+ const next = computeZoom(
1216
+ base.windowTime,
1217
+ base.tick,
1218
+ base.cellWidth,
1219
+ anchorX,
1220
+ factor,
1221
+ contentWidth,
1222
+ limits
1223
+ );
1224
+ (_a = rendererRef.current) == null ? void 0 : _a.setView({
1225
+ windowTime: next.windowTime,
1226
+ tick: next.tick,
1227
+ cellWidth: next.cellWidth
1228
+ });
1229
+ setWindowTime(next.windowTime);
1230
+ setTick(next.tick);
1231
+ setCellWidth(next.cellWidth);
1232
+ },
1233
+ [rendererRef, setWindowTime, setTick, setCellWidth, limits]
1234
+ );
1235
+ const scheduleContinuousZoom = (0, import_react5.useCallback)(() => {
1236
+ if (zoomFrameRef.current !== null) return;
1237
+ zoomFrameRef.current = requestAnimationFrame(() => {
1238
+ zoomFrameRef.current = null;
1239
+ const pending = zoomPendingRef.current;
1240
+ const state = stateRef.current;
1241
+ if (!pending || state.mode !== "pinch" && state.mode !== "zoom") return;
1242
+ applyZoom(state.snapshot, pending.anchorX, pending.factor, state.contentWidth);
1243
+ });
1244
+ }, [applyZoom]);
1245
+ const snapshotView = (0, import_react5.useCallback)(() => {
1246
+ const renderer = rendererRef.current;
1247
+ const canvas = dynamicCanvasRef.current;
1248
+ if (!renderer || !canvas) return null;
1249
+ const view = renderer.getView();
1250
+ if (view.tick === null) return null;
1251
+ return {
1252
+ base: {
1253
+ windowTime: [view.windowTime[0], view.windowTime[1]],
1254
+ tick: view.tick,
1255
+ cellWidth: view.cellWidth
1256
+ },
1257
+ contentWidth: canvas.getBoundingClientRect().width
1258
+ };
1259
+ }, [rendererRef, dynamicCanvasRef]);
1260
+ const hidePrompt = (0, import_react5.useCallback)(() => {
1261
+ var _a;
1262
+ (_a = eventPromptRef.current) == null ? void 0 : _a.hide();
1263
+ }, [eventPromptRef]);
1264
+ const currentHit = (0, import_react5.useCallback)(
1265
+ (clientX, clientY) => {
1266
+ const canvas = dynamicCanvasRef.current;
1267
+ const renderer = rendererRef.current;
1268
+ if (!canvas || !renderer) return null;
1269
+ const view = renderer.getView();
1270
+ if (view.tick === null) return null;
1271
+ const rect = canvas.getBoundingClientRect();
1272
+ return hitTest(
1273
+ scene,
1274
+ {
1275
+ windowStart: view.windowTime[0],
1276
+ windowEnd: view.windowTime[1],
1277
+ tick: view.tick,
1278
+ scrollTop: view.scrollTop
1279
+ },
1280
+ clientX - rect.left,
1281
+ clientY - rect.top
1282
+ );
1283
+ },
1284
+ [scene, dynamicCanvasRef, rendererRef]
1285
+ );
1286
+ const resizeDirectionAt = (0, import_react5.useCallback)(
1287
+ (hit, clientX) => {
1288
+ if (hit.kind !== "event" || !canResizeEvent(hit.event, eventsResize)) {
1289
+ return null;
1290
+ }
1291
+ const canvas = dynamicCanvasRef.current;
1292
+ if (!canvas) return null;
1293
+ const x = clientX - canvas.getBoundingClientRect().left;
1294
+ const zone = Math.min(RESIZE_HOT_ZONE_PX, hit.rect.width / 3);
1295
+ if (x <= hit.rect.x + zone) return "left";
1296
+ if (x >= hit.rect.x + hit.rect.width - zone) return "right";
1297
+ return null;
1298
+ },
1299
+ [dynamicCanvasRef, eventsResize]
1300
+ );
1301
+ const schedulePan = (0, import_react5.useCallback)(() => {
1302
+ if (panFrameRef.current !== null) return;
1303
+ panFrameRef.current = requestAnimationFrame(() => {
1304
+ panFrameRef.current = null;
1305
+ const renderer = rendererRef.current;
1306
+ const dx = panPendingDxRef.current;
1307
+ panPendingDxRef.current = 0;
1308
+ const tick = renderer == null ? void 0 : renderer.getView().tick;
1309
+ if (!tick || dx === 0) return;
1310
+ const dt = Math.round(dx * tick);
1311
+ if (dt === 0) {
1312
+ panPendingDxRef.current = dx;
1313
+ return;
1314
+ }
1315
+ setWindowTime((prev) => [prev[0] - dt, prev[1] - dt]);
1316
+ });
1317
+ }, [rendererRef, setWindowTime]);
1318
+ const updateGhost = (0, import_react5.useCallback)(
1319
+ (state, clientX, clientY) => {
1320
+ const ghost = ghostRef.current;
1321
+ if (!ghost) return;
1322
+ ghost.style.display = "flex";
1323
+ ghost.style.left = `${state.hit.rect.x + (clientX - state.startClientX)}px`;
1324
+ ghost.style.top = `${state.hit.rect.y + (clientY - state.startClientY)}px`;
1325
+ ghost.style.width = `${state.hit.rect.width}px`;
1326
+ },
1327
+ [ghostRef]
1328
+ );
1329
+ const styleGhost = (0, import_react5.useCallback)(
1330
+ (event) => {
1331
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
1332
+ const ghost = ghostRef.current;
1333
+ const theme = (_a = rendererRef.current) == null ? void 0 : _a.getView().theme;
1334
+ if (!ghost || !theme) return;
1335
+ const style = (_b = event.props) == null ? void 0 : _b.style;
1336
+ ghost.style.backgroundColor = (_c = style == null ? void 0 : style.fill) != null ? _c : theme.eventFill;
1337
+ ghost.style.border = `${(_d = style == null ? void 0 : style.strokeWidth) != null ? _d : 1}px solid ${(_e = style == null ? void 0 : style.stroke) != null ? _e : theme.eventStroke}`;
1338
+ ghost.style.borderRadius = `${(_f = style == null ? void 0 : style.borderRadius) != null ? _f : theme.barRadius}px`;
1339
+ ghost.style.color = (_g = style == null ? void 0 : style.textColor) != null ? _g : theme.eventTextColor;
1340
+ ghost.style.font = (_i = (_h = style == null ? void 0 : style.font) != null ? _h : theme.font) != null ? _i : "";
1341
+ ghost.style.justifyContent = "flex-start";
1342
+ ghost.style.alignItems = "center";
1343
+ ghost.style.paddingInline = "13px";
1344
+ ghost.style.overflow = "hidden";
1345
+ ghost.style.whiteSpace = "nowrap";
1346
+ ghost.textContent = (_k = (_j = event.props) == null ? void 0 : _j.label) != null ? _k : "";
1347
+ },
1348
+ [ghostRef, rendererRef]
1349
+ );
1350
+ const handlePointerDown = (0, import_react5.useCallback)(
1351
+ (pointerEvent) => {
1352
+ var _a, _b;
1353
+ const canvas = dynamicCanvasRef.current;
1354
+ if (!canvas) return;
1355
+ const isTouch = pointerEvent.pointerType === "touch";
1356
+ pointersRef.current.set(pointerEvent.pointerId, {
1357
+ x: pointerEvent.clientX,
1358
+ y: pointerEvent.clientY,
1359
+ touch: isTouch
1360
+ });
1361
+ if (config.pinchZoom && isTouch && pointersRef.current.size === 2) {
1362
+ const snap = snapshotView();
1363
+ if (snap) {
1364
+ if (ghostRef.current) ghostRef.current.style.display = "none";
1365
+ (_a = rendererRef.current) == null ? void 0 : _a.setView({ draggedEventId: null });
1366
+ const pts = [...pointersRef.current.values()];
1367
+ const startDist = Math.hypot(pts[0].x - pts[1].x, pts[0].y - pts[1].y) || 1;
1368
+ const rect = canvas.getBoundingClientRect();
1369
+ stateRef.current = {
1370
+ mode: "pinch",
1371
+ startDist,
1372
+ anchorX: (pts[0].x + pts[1].x) / 2 - rect.left,
1373
+ contentWidth: snap.contentWidth,
1374
+ snapshot: snap.base
1375
+ };
1376
+ canvas.setPointerCapture(pointerEvent.pointerId);
1377
+ hidePrompt();
1378
+ }
1379
+ return;
1380
+ }
1381
+ if (pointerEvent.button !== 0) return;
1382
+ const hit = currentHit(pointerEvent.clientX, pointerEvent.clientY);
1383
+ if ((hit == null ? void 0 : hit.kind) === "event" && !((_b = hit.event.props) == null ? void 0 : _b.isLocked)) {
1384
+ const direction = resizeDirectionAt(hit, pointerEvent.clientX);
1385
+ if (direction) {
1386
+ stateRef.current = {
1387
+ mode: "resize",
1388
+ event: hit.event,
1389
+ direction,
1390
+ startClientX: pointerEvent.clientX,
1391
+ deltaPx: 0
1392
+ };
1393
+ lockCursor("e-resize");
1394
+ } else {
1395
+ stateRef.current = {
1396
+ mode: "drag",
1397
+ hit,
1398
+ startClientX: pointerEvent.clientX,
1399
+ startClientY: pointerEvent.clientY,
1400
+ active: false
1401
+ };
1402
+ styleGhost(hit.event);
1403
+ }
1404
+ } else if (config.dragZoom && (pointerEvent.ctrlKey || pointerEvent.metaKey) && !isTouch) {
1405
+ const snap = snapshotView();
1406
+ if (!snap) return;
1407
+ const rect = canvas.getBoundingClientRect();
1408
+ stateRef.current = {
1409
+ mode: "zoom",
1410
+ startClientX: pointerEvent.clientX,
1411
+ anchorX: pointerEvent.clientX - rect.left,
1412
+ contentWidth: snap.contentWidth,
1413
+ snapshot: snap.base
1414
+ };
1415
+ } else if (config.panOnDragBackground) {
1416
+ stateRef.current = {
1417
+ mode: "pan",
1418
+ lastClientX: pointerEvent.clientX,
1419
+ lastClientY: pointerEvent.clientY,
1420
+ touch: isTouch
1421
+ };
1422
+ canvas.style.cursor = "grabbing";
1423
+ } else {
1424
+ return;
1425
+ }
1426
+ hidePrompt();
1427
+ canvas.setPointerCapture(pointerEvent.pointerId);
1428
+ },
1429
+ [
1430
+ currentHit,
1431
+ resizeDirectionAt,
1432
+ dynamicCanvasRef,
1433
+ hidePrompt,
1434
+ config,
1435
+ snapshotView,
1436
+ ghostRef,
1437
+ rendererRef,
1438
+ styleGhost
1439
+ ]
1440
+ );
1441
+ const handleHover = (0, import_react5.useCallback)(
1442
+ (pointerEvent) => {
1443
+ var _a, _b, _c, _d;
1444
+ const canvas = dynamicCanvasRef.current;
1445
+ if (!canvas) return;
1446
+ const hit = currentHit(pointerEvent.clientX, pointerEvent.clientY);
1447
+ const prevHovered = hoveredRef.current;
1448
+ hoveredRef.current = hit;
1449
+ if ((hit == null ? void 0 : hit.kind) === "event") {
1450
+ if ((_a = hit.event.props) == null ? void 0 : _a.isLocked) {
1451
+ canvas.style.cursor = "not-allowed";
1452
+ } else if (resizeDirectionAt(hit, pointerEvent.clientX)) {
1453
+ canvas.style.cursor = "e-resize";
1454
+ } else {
1455
+ canvas.style.cursor = "pointer";
1456
+ }
1457
+ } else {
1458
+ canvas.style.cursor = "grab";
1459
+ }
1460
+ const hoveredId = (hit == null ? void 0 : hit.kind) === "event" ? hit.event.id : null;
1461
+ const prevId = (prevHovered == null ? void 0 : prevHovered.kind) === "event" ? prevHovered.event.id : null;
1462
+ if (hoveredId !== prevId) {
1463
+ (_b = rendererRef.current) == null ? void 0 : _b.setView({ hoveredEventId: hoveredId });
1464
+ if (onEventHover) {
1465
+ onEventHover({
1466
+ eventId: hoveredId,
1467
+ rowId: hoveredId !== null && hit ? hit.rowId : null
1468
+ });
1469
+ }
1470
+ }
1471
+ const prompt = eventPromptRef.current;
1472
+ if (!prompt) return;
1473
+ 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)) {
1474
+ if (prevId !== hit.event.id) {
1475
+ const canvasRect = canvas.getBoundingClientRect();
1476
+ prompt.show(hit.event, {
1477
+ x: canvasRect.left + hit.rect.x,
1478
+ y: canvasRect.top + hit.rect.y,
1479
+ width: hit.rect.width,
1480
+ height: hit.rect.height
1481
+ });
1482
+ }
1483
+ } else {
1484
+ prompt.hide();
1485
+ }
1486
+ },
1487
+ [
1488
+ currentHit,
1489
+ resizeDirectionAt,
1490
+ dynamicCanvasRef,
1491
+ eventPromptRef,
1492
+ rendererRef,
1493
+ onEventHover
1494
+ ]
1495
+ );
1496
+ const handlePointerMove = (0, import_react5.useCallback)(
1497
+ (pointerEvent) => {
1498
+ var _a, _b;
1499
+ const tracked = pointersRef.current.get(pointerEvent.pointerId);
1500
+ if (tracked) {
1501
+ tracked.x = pointerEvent.clientX;
1502
+ tracked.y = pointerEvent.clientY;
1503
+ }
1504
+ const state = stateRef.current;
1505
+ if (state.mode === "idle") {
1506
+ handleHover(pointerEvent);
1507
+ return;
1508
+ }
1509
+ if (state.mode === "pinch") {
1510
+ const pts = [...pointersRef.current.values()];
1511
+ if (pts.length < 2) return;
1512
+ const dist = Math.hypot(pts[0].x - pts[1].x, pts[0].y - pts[1].y) || 1;
1513
+ zoomPendingRef.current = {
1514
+ anchorX: state.anchorX,
1515
+ factor: state.startDist / dist
1516
+ // fingers apart -> factor<1 -> zoom in
1517
+ };
1518
+ scheduleContinuousZoom();
1519
+ return;
1520
+ }
1521
+ if (state.mode === "zoom") {
1522
+ const dx = pointerEvent.clientX - state.startClientX;
1523
+ zoomPendingRef.current = {
1524
+ anchorX: state.anchorX,
1525
+ factor: Math.pow(2, -dx / DRAG_ZOOM_PX_PER_DOUBLING)
1526
+ // right -> zoom in
1527
+ };
1528
+ scheduleContinuousZoom();
1529
+ return;
1530
+ }
1531
+ if (state.mode === "pan") {
1532
+ panPendingDxRef.current += pointerEvent.clientX - state.lastClientX;
1533
+ if (state.touch && bodyRef.current) {
1534
+ bodyRef.current.scrollTop -= pointerEvent.clientY - state.lastClientY;
1535
+ }
1536
+ state.lastClientX = pointerEvent.clientX;
1537
+ state.lastClientY = pointerEvent.clientY;
1538
+ schedulePan();
1539
+ return;
1540
+ }
1541
+ if (state.mode === "drag") {
1542
+ if (!state.active && Math.abs(pointerEvent.clientX - state.startClientX) + Math.abs(pointerEvent.clientY - state.startClientY) > DRAG_THRESHOLD_PX) {
1543
+ state.active = true;
1544
+ (_a = rendererRef.current) == null ? void 0 : _a.setView({ draggedEventId: state.hit.event.id });
1545
+ }
1546
+ if (state.active) {
1547
+ updateGhost(state, pointerEvent.clientX, pointerEvent.clientY);
1548
+ }
1549
+ return;
1550
+ }
1551
+ state.deltaPx = pointerEvent.clientX - state.startClientX;
1552
+ (_b = rendererRef.current) == null ? void 0 : _b.setView({
1553
+ resizePreview: {
1554
+ eventId: state.event.id,
1555
+ deltaPx: state.deltaPx,
1556
+ direction: state.direction
1557
+ }
1558
+ });
1559
+ },
1560
+ [
1561
+ handleHover,
1562
+ schedulePan,
1563
+ updateGhost,
1564
+ rendererRef,
1565
+ scheduleContinuousZoom,
1566
+ bodyRef
1567
+ ]
1568
+ );
1569
+ const commitDrop = (0, import_react5.useCallback)(
1570
+ (state, clientX, clientY) => {
1571
+ const canvas = dynamicCanvasRef.current;
1572
+ const renderer = rendererRef.current;
1573
+ if (!canvas || !renderer) return;
1574
+ const view = renderer.getView();
1575
+ if (view.tick === null || view.cellWidth <= 0) return;
1576
+ const canvasRect = canvas.getBoundingClientRect();
1577
+ const yContent = clientY - canvasRect.top + view.scrollTop;
1578
+ let rowTop = 0;
1579
+ let targetRowId = null;
1580
+ for (const id of scene.getRowIds()) {
1581
+ const height = scene.getRowHeight(
1582
+ id,
1583
+ view.windowTime[0],
1584
+ view.windowTime[1]
1585
+ );
1586
+ if (yContent >= rowTop && yContent < rowTop + height) {
1587
+ targetRowId = id;
1588
+ break;
1589
+ }
1590
+ rowTop += height;
1591
+ }
1592
+ if (targetRowId === null) return;
1593
+ const liveEvent = scene.getEvent(state.hit.event.id);
1594
+ if (!liveEvent) return;
1595
+ const { startTime, endTime } = computeDropTimes({
1596
+ pointerX: clientX - canvasRect.left,
1597
+ cellWidth: view.cellWidth,
1598
+ tick: view.tick,
1599
+ windowStart: view.windowTime[0],
1600
+ duration: liveEvent.endTime - liveEvent.startTime
1601
+ });
1602
+ if (onDrop) {
1603
+ onDrop({
1604
+ eventId: liveEvent.id,
1605
+ oldRowId: liveEvent.rowId,
1606
+ newRowId: targetRowId,
1607
+ startTime,
1608
+ endTime
1609
+ });
1610
+ }
1611
+ renderer.animator.snapEventTop(liveEvent.id);
1612
+ scene.applyPatches([
1613
+ {
1614
+ op: "update",
1615
+ id: liveEvent.id,
1616
+ changes: { startTime, endTime, rowId: targetRowId }
1617
+ }
1618
+ ]);
1619
+ },
1620
+ [scene, dynamicCanvasRef, rendererRef, onDrop]
1621
+ );
1622
+ const commitResize = (0, import_react5.useCallback)(
1623
+ (state) => {
1624
+ const renderer = rendererRef.current;
1625
+ const tick = renderer == null ? void 0 : renderer.getView().tick;
1626
+ renderer == null ? void 0 : renderer.setView({ resizePreview: null });
1627
+ unlockCursor();
1628
+ if (!tick) return;
1629
+ const liveEvent = scene.getEvent(state.event.id);
1630
+ if (!liveEvent) return;
1631
+ const next = computeResizeTimes(
1632
+ liveEvent,
1633
+ state.deltaPx,
1634
+ tick,
1635
+ state.direction
1636
+ );
1637
+ if (next) {
1638
+ scene.applyPatches([
1639
+ { op: "update", id: liveEvent.id, changes: next }
1640
+ ]);
1641
+ }
1642
+ if (onResize) {
1643
+ const committed = next != null ? next : {
1644
+ startTime: liveEvent.startTime,
1645
+ endTime: liveEvent.endTime
1646
+ };
1647
+ onResize(__spreadValues({ eventId: liveEvent.id }, committed));
1648
+ }
1649
+ },
1650
+ [scene, rendererRef, onResize]
1651
+ );
1652
+ const handlePointerUp = (0, import_react5.useCallback)(
1653
+ (pointerEvent) => {
1654
+ var _a;
1655
+ const canvas = dynamicCanvasRef.current;
1656
+ const state = stateRef.current;
1657
+ pointersRef.current.delete(pointerEvent.pointerId);
1658
+ stateRef.current = { mode: "idle" };
1659
+ if (canvas == null ? void 0 : canvas.hasPointerCapture(pointerEvent.pointerId)) {
1660
+ canvas.releasePointerCapture(pointerEvent.pointerId);
1661
+ }
1662
+ if (canvas) canvas.style.cursor = "grab";
1663
+ if (state.mode === "drag" && state.active) {
1664
+ if (ghostRef.current) ghostRef.current.style.display = "none";
1665
+ (_a = rendererRef.current) == null ? void 0 : _a.setView({ draggedEventId: null });
1666
+ commitDrop(state, pointerEvent.clientX, pointerEvent.clientY);
1667
+ } else if (state.mode === "drag" && !state.active) {
1668
+ if (onEventClick) {
1669
+ onEventClick({
1670
+ eventId: state.hit.event.id,
1671
+ rowId: state.hit.rowId,
1672
+ nativeEvent: pointerEvent.nativeEvent,
1673
+ modifiers: {
1674
+ shift: pointerEvent.shiftKey,
1675
+ ctrl: pointerEvent.ctrlKey,
1676
+ meta: pointerEvent.metaKey,
1677
+ alt: pointerEvent.altKey
1678
+ }
1679
+ });
1680
+ }
1681
+ } else if (state.mode === "resize") {
1682
+ commitResize(state);
1683
+ }
1684
+ },
1685
+ [
1686
+ dynamicCanvasRef,
1687
+ ghostRef,
1688
+ rendererRef,
1689
+ commitDrop,
1690
+ commitResize,
1691
+ onEventClick
1692
+ ]
1693
+ );
1694
+ const handlePointerCancel = (0, import_react5.useCallback)(
1695
+ (pointerEvent) => {
1696
+ var _a;
1697
+ pointersRef.current.delete(pointerEvent.pointerId);
1698
+ stateRef.current = { mode: "idle" };
1699
+ const canvas = dynamicCanvasRef.current;
1700
+ if (canvas == null ? void 0 : canvas.hasPointerCapture(pointerEvent.pointerId)) {
1701
+ canvas.releasePointerCapture(pointerEvent.pointerId);
1702
+ }
1703
+ if (ghostRef.current) ghostRef.current.style.display = "none";
1704
+ (_a = rendererRef.current) == null ? void 0 : _a.setView({ draggedEventId: null });
1705
+ },
1706
+ [dynamicCanvasRef, ghostRef, rendererRef]
1707
+ );
1708
+ const handlePointerLeave = (0, import_react5.useCallback)(() => {
1709
+ var _a, _b;
1710
+ if (stateRef.current.mode !== "idle") return;
1711
+ if (((_a = hoveredRef.current) == null ? void 0 : _a.kind) === "event") {
1712
+ (_b = rendererRef.current) == null ? void 0 : _b.setView({ hoveredEventId: null });
1713
+ if (onEventHover) onEventHover({ eventId: null, rowId: null });
1714
+ }
1715
+ hoveredRef.current = null;
1716
+ if (dynamicCanvasRef.current) {
1717
+ dynamicCanvasRef.current.style.cursor = "";
1718
+ }
1719
+ hidePrompt();
1720
+ }, [dynamicCanvasRef, rendererRef, hidePrompt, onEventHover]);
1721
+ const handleAuxClick = (0, import_react5.useCallback)(
1722
+ (pointerEvent) => {
1723
+ pointerEvent.preventDefault();
1724
+ if (pointerEvent.button === 1 && config.middleClickGranularity) {
1725
+ changeGridRef.current = !changeGridRef.current;
1726
+ if (bodyRef.current) {
1727
+ bodyRef.current.style.overflowY = changeGridRef.current ? "hidden" : "auto";
1728
+ }
1729
+ }
1730
+ },
1731
+ [bodyRef, config]
1732
+ );
1733
+ (0, import_react5.useEffect)(() => {
1734
+ const canvas = dynamicCanvasRef.current;
1735
+ if (!canvas) return;
1736
+ const handleWheel = (wheelEvent) => {
1737
+ var _a;
1738
+ const view = (_a = rendererRef.current) == null ? void 0 : _a.getView();
1739
+ if (!view || view.tick === null) return;
1740
+ const tick = view.tick;
1741
+ if (changeGridRef.current) {
1742
+ wheelEvent.preventDefault();
1743
+ setCellWidth(
1744
+ (cellWidth) => stepCellWidth(
1745
+ cellWidth,
1746
+ wheelEvent.deltaY,
1747
+ tick * 900 / config.zoomStepSeconds
1748
+ )
1749
+ );
1750
+ return;
1751
+ }
1752
+ if ((wheelEvent.ctrlKey || wheelEvent.metaKey) && config.ctrlWheelZoom) {
1753
+ wheelEvent.preventDefault();
1754
+ const rect = canvas.getBoundingClientRect();
1755
+ const factor = wheelEvent.deltaY > 0 ? config.zoomWheelFactor : 1 / config.zoomWheelFactor;
1756
+ applyZoom(
1757
+ {
1758
+ windowTime: [view.windowTime[0], view.windowTime[1]],
1759
+ tick,
1760
+ cellWidth: view.cellWidth
1761
+ },
1762
+ wheelEvent.clientX - rect.left,
1763
+ factor,
1764
+ rect.width
1765
+ );
1766
+ return;
1767
+ }
1768
+ };
1769
+ canvas.addEventListener("wheel", handleWheel, { passive: false });
1770
+ return () => canvas.removeEventListener("wheel", handleWheel);
1771
+ }, [dynamicCanvasRef, rendererRef, setCellWidth, applyZoom, config]);
1772
+ (0, import_react5.useEffect)(() => unlockCursor, []);
1773
+ return {
1774
+ handlePointerDown,
1775
+ handlePointerMove,
1776
+ handlePointerUp,
1777
+ handlePointerLeave,
1778
+ handlePointerCancel,
1779
+ handleAuxClick
1780
+ };
1781
+ };
1782
+ var use_canvas_interactions_default = useCanvasInteractions;
1783
+
1784
+ // src/components/canvas-board.tsx
1785
+ var CanvasBoard = (0, import_react6.forwardRef)(
1786
+ ({
1787
+ scene,
1788
+ rows,
1789
+ windowTime,
1790
+ tick,
1791
+ cellWidth,
1792
+ theme,
1793
+ drawEvent,
1794
+ bodyRef,
1795
+ rendererRef,
1796
+ eventPromptRef,
1797
+ rowsHeaderClassName,
1798
+ setWindowTime,
1799
+ setCellWidth,
1800
+ setTick,
1801
+ onDrop,
1802
+ onResize,
1803
+ onEventClick,
1804
+ onEventHover,
1805
+ eventsResize,
1806
+ panZoom,
1807
+ animations
1808
+ }, contentRef) => {
1809
+ const staticCanvasRef = (0, import_react6.useRef)(null);
1810
+ const dynamicCanvasRef = (0, import_react6.useRef)(null);
1811
+ const ghostRef = (0, import_react6.useRef)(null);
1812
+ const [scrollTop, setScrollTop] = (0, import_react6.useState)(0);
1813
+ const [viewportHeight, setViewportHeight] = (0, import_react6.useState)(0);
1814
+ (0, import_react6.useEffect)(() => {
1815
+ if (!staticCanvasRef.current || !dynamicCanvasRef.current) return;
1816
+ const renderer = new TimelineRenderer(
1817
+ staticCanvasRef.current,
1818
+ dynamicCanvasRef.current,
1819
+ scene
1820
+ );
1821
+ rendererRef.current = renderer;
1822
+ return () => {
1823
+ renderer.dispose();
1824
+ rendererRef.current = null;
1825
+ };
1826
+ }, [scene, rendererRef]);
1827
+ (0, import_react6.useEffect)(() => {
1828
+ var _a, _b;
1829
+ (_a = rendererRef.current) == null ? void 0 : _a.animator.setDurations(
1830
+ animations.layoutMs,
1831
+ animations.fadeMs
1832
+ );
1833
+ (_b = rendererRef.current) == null ? void 0 : _b.setView({
1834
+ windowTime: [windowTime[0], windowTime[1]],
1835
+ tick,
1836
+ cellWidth,
1837
+ theme,
1838
+ drawEvent,
1839
+ eventsResize
1840
+ });
1841
+ }, [
1842
+ windowTime,
1843
+ tick,
1844
+ cellWidth,
1845
+ theme,
1846
+ drawEvent,
1847
+ eventsResize,
1848
+ animations,
1849
+ rendererRef
1850
+ ]);
1851
+ (0, import_react6.useEffect)(() => {
1852
+ const column = contentRef && "current" in contentRef ? contentRef.current : null;
1853
+ const body = bodyRef.current;
1854
+ if (!column || !body) return;
1855
+ const measure = () => {
1856
+ var _a;
1857
+ const height = Math.min(body.clientHeight, window.innerHeight);
1858
+ setViewportHeight(height);
1859
+ (_a = rendererRef.current) == null ? void 0 : _a.setView({
1860
+ width: column.getBoundingClientRect().width,
1861
+ height
1862
+ });
1863
+ };
1864
+ measure();
1865
+ const observer = new ResizeObserver(measure);
1866
+ observer.observe(column);
1867
+ observer.observe(body);
1868
+ return () => observer.disconnect();
1869
+ }, [bodyRef, contentRef, rendererRef]);
1870
+ (0, import_react6.useEffect)(() => {
1871
+ const body = bodyRef.current;
1872
+ if (!body) return;
1873
+ const handleScroll = () => {
1874
+ var _a;
1875
+ (_a = rendererRef.current) == null ? void 0 : _a.setView({ scrollTop: body.scrollTop });
1876
+ setScrollTop(body.scrollTop);
1877
+ };
1878
+ body.addEventListener("scroll", handleScroll, { passive: true });
1879
+ return () => body.removeEventListener("scroll", handleScroll);
1880
+ }, [bodyRef, rendererRef]);
1881
+ (0, import_react6.useSyncExternalStore)(
1882
+ (0, import_react6.useCallback)((listener) => scene.subscribe(listener), [scene]),
1883
+ () => scene.version
1884
+ );
1885
+ const {
1886
+ handlePointerDown,
1887
+ handlePointerMove,
1888
+ handlePointerUp,
1889
+ handlePointerLeave,
1890
+ handlePointerCancel,
1891
+ handleAuxClick
1892
+ } = use_canvas_interactions_default({
1893
+ scene,
1894
+ rendererRef,
1895
+ dynamicCanvasRef,
1896
+ bodyRef,
1897
+ ghostRef,
1898
+ eventPromptRef,
1899
+ setWindowTime,
1900
+ setCellWidth,
1901
+ setTick,
1902
+ onDrop,
1903
+ onResize,
1904
+ onEventClick,
1905
+ onEventHover,
1906
+ eventsResize,
1907
+ panZoom
1908
+ });
1909
+ const { offsetOf, totalHeight } = scene.getRowOffsets(
1910
+ windowTime[0],
1911
+ windowTime[1]
1912
+ );
1913
+ const visibleHeaders = [];
1914
+ for (let i = 0; i < rows.length; i++) {
1915
+ const row = rows[i];
1916
+ const top = offsetOf.get(row.id);
1917
+ const height = scene.getRowHeight(row.id, windowTime[0], windowTime[1]);
1918
+ if (top + height < scrollTop) continue;
1919
+ if (top > scrollTop + viewportHeight) break;
1920
+ visibleHeaders.push(
1921
+ /* @__PURE__ */ import_react6.default.createElement(
1922
+ "div",
1923
+ {
1924
+ key: `row_header_${row.id}`,
1925
+ className: "row-header canvas-row-header",
1926
+ style: {
1927
+ top,
1928
+ height,
1929
+ borderBottom: i === rows.length - 1 ? "none" : "1px solid yellow",
1930
+ // keeps the DOM header in step with the canvas layout tween
1931
+ transition: animations.layoutMs > 0 ? `top ${animations.layoutMs}ms ease-in-out, height ${animations.layoutMs}ms ease-in-out` : "none"
1932
+ }
1933
+ },
1934
+ row.name
1935
+ )
1936
+ );
1937
+ }
1938
+ const headerClassNames = rowsHeaderClassName ? `rows-header-wrapper canvas-rows-header ${rowsHeaderClassName}` : "rows-header-wrapper canvas-rows-header";
1939
+ return /* @__PURE__ */ import_react6.default.createElement(import_react6.default.Fragment, null, /* @__PURE__ */ import_react6.default.createElement("div", { className: headerClassNames, style: { height: totalHeight } }, visibleHeaders), /* @__PURE__ */ import_react6.default.createElement("div", { className: "canvas-content-column", ref: contentRef }, /* @__PURE__ */ import_react6.default.createElement("div", { className: "canvas-sticky" }, /* @__PURE__ */ import_react6.default.createElement("canvas", { ref: staticCanvasRef }), /* @__PURE__ */ import_react6.default.createElement(
1940
+ "canvas",
1941
+ {
1942
+ ref: dynamicCanvasRef,
1943
+ onPointerDown: handlePointerDown,
1944
+ onPointerMove: handlePointerMove,
1945
+ onPointerUp: handlePointerUp,
1946
+ onPointerLeave: handlePointerLeave,
1947
+ onPointerCancel: handlePointerCancel,
1948
+ onAuxClick: handleAuxClick
1949
+ }
1950
+ ), /* @__PURE__ */ import_react6.default.createElement(
1951
+ "div",
1952
+ {
1953
+ ref: ghostRef,
1954
+ className: "event canvas-drag-ghost",
1955
+ style: { height: scene.getGeometry().barHeight }
1956
+ }
1957
+ )), /* @__PURE__ */ import_react6.default.createElement(
1958
+ "div",
1959
+ {
1960
+ className: "canvas-scroll-spacer",
1961
+ style: { height: totalHeight }
1962
+ }
1963
+ )));
1964
+ }
1965
+ );
1966
+ var canvas_board_default = CanvasBoard;
1967
+
1968
+ // src/core/scene.ts
1969
+ var binaryInsertIndex = (events, event) => {
1970
+ let lo = 0;
1971
+ let hi = events.length;
1972
+ while (lo < hi) {
1973
+ const mid = lo + hi >> 1;
1974
+ if (sort_events_default(events[mid], event) < 0) {
1975
+ lo = mid + 1;
1976
+ } else {
1977
+ hi = mid;
1978
+ }
1979
+ }
1980
+ return lo;
1981
+ };
1982
+ var SceneStore = class {
1983
+ constructor() {
1984
+ this.rowIndexes = /* @__PURE__ */ new Map();
1985
+ this.rowOrder = [];
1986
+ this.eventRow = /* @__PURE__ */ new Map();
1987
+ this.listeners = /* @__PURE__ */ new Set();
1988
+ // Themeable vertical layout. Lanes are geometry-free (pure time logic), so a
1989
+ // geometry change only affects heights/offsets — the cached lanes stay valid
1990
+ // and we just bump to trigger a redraw.
1991
+ this.geometry = DEFAULT_GEOMETRY;
1992
+ this.version = 0;
1993
+ }
1994
+ setGeometry(geometry) {
1995
+ this.geometry = geometry;
1996
+ this.bump();
1997
+ }
1998
+ getGeometry() {
1999
+ return this.geometry;
2000
+ }
2001
+ setRows(rows) {
2002
+ const next = /* @__PURE__ */ new Map();
2003
+ for (const row of rows) {
2004
+ const existing = this.rowIndexes.get(row.id);
2005
+ next.set(
2006
+ row.id,
2007
+ existing ? __spreadProps(__spreadValues({}, existing), { row }) : {
2008
+ row,
2009
+ events: [],
2010
+ staticEvents: [],
2011
+ lanesDirty: true,
2012
+ lanes: null,
2013
+ laneWindowStart: NaN,
2014
+ laneWindowEnd: NaN
2015
+ }
2016
+ );
2017
+ }
2018
+ for (const [id, rowId] of this.eventRow) {
2019
+ if (!next.has(rowId)) this.eventRow.delete(id);
2020
+ }
2021
+ this.rowIndexes = next;
2022
+ this.rowOrder = rows.map((row) => row.id);
2023
+ this.bump();
2024
+ }
2025
+ setEvents(events) {
2026
+ for (const index of this.rowIndexes.values()) {
2027
+ index.events = [];
2028
+ index.lanesDirty = true;
2029
+ }
2030
+ this.eventRow.clear();
2031
+ for (const event of events) {
2032
+ const index = this.rowIndexes.get(event.rowId);
2033
+ if (!index) continue;
2034
+ index.events.push(event);
2035
+ this.eventRow.set(event.id, event.rowId);
2036
+ }
2037
+ for (const index of this.rowIndexes.values()) {
2038
+ index.events.sort(sort_events_default);
2039
+ }
2040
+ this.bump();
2041
+ }
2042
+ setStaticEvents(events) {
2043
+ for (const index of this.rowIndexes.values()) {
2044
+ index.staticEvents = [];
2045
+ }
2046
+ for (const event of events) {
2047
+ const index = this.rowIndexes.get(event.rowId);
2048
+ if (!index) continue;
2049
+ index.staticEvents.push(event);
2050
+ }
2051
+ for (const index of this.rowIndexes.values()) {
2052
+ index.staticEvents.sort(sort_events_default);
2053
+ }
2054
+ this.bump();
2055
+ }
2056
+ applyPatches(patches) {
2057
+ for (const patch of patches) {
2058
+ if (patch.op === "upsert") {
2059
+ this.remove(patch.event.id);
2060
+ this.insert(patch.event);
2061
+ } else if (patch.op === "update") {
2062
+ const existing = this.getEvent(patch.id);
2063
+ if (!existing) continue;
2064
+ this.remove(patch.id);
2065
+ this.insert(__spreadProps(__spreadValues(__spreadValues({}, existing), patch.changes), { id: patch.id }));
2066
+ } else {
2067
+ this.remove(patch.id);
2068
+ }
2069
+ }
2070
+ this.bump();
2071
+ }
2072
+ getEvent(id) {
2073
+ var _a;
2074
+ const rowId = this.eventRow.get(id);
2075
+ if (rowId === void 0) return void 0;
2076
+ return (_a = this.rowIndexes.get(rowId)) == null ? void 0 : _a.events.find((event) => event.id === id);
2077
+ }
2078
+ getRowIds() {
2079
+ return this.rowOrder;
2080
+ }
2081
+ getRow(rowId) {
2082
+ var _a;
2083
+ return (_a = this.rowIndexes.get(rowId)) == null ? void 0 : _a.row;
2084
+ }
2085
+ getRowEvents(rowId) {
2086
+ var _a, _b;
2087
+ return (_b = (_a = this.rowIndexes.get(rowId)) == null ? void 0 : _a.events) != null ? _b : [];
2088
+ }
2089
+ getRowStaticEvents(rowId) {
2090
+ var _a, _b;
2091
+ return (_b = (_a = this.rowIndexes.get(rowId)) == null ? void 0 : _a.staticEvents) != null ? _b : [];
2092
+ }
2093
+ getLanes(rowId, windowStart, windowEnd) {
2094
+ const index = this.rowIndexes.get(rowId);
2095
+ if (!index) return { laneOf: /* @__PURE__ */ new Map(), highestLane: 0 };
2096
+ if (index.lanesDirty || index.lanes === null || index.laneWindowStart !== windowStart || index.laneWindowEnd !== windowEnd) {
2097
+ index.lanes = assignLanes(index.events, windowStart, windowEnd);
2098
+ index.laneWindowStart = windowStart;
2099
+ index.laneWindowEnd = windowEnd;
2100
+ index.lanesDirty = false;
2101
+ }
2102
+ return index.lanes;
2103
+ }
2104
+ getRowHeight(rowId, windowStart, windowEnd) {
2105
+ return rowMinHeight(
2106
+ this.getLanes(rowId, windowStart, windowEnd).highestLane,
2107
+ this.geometry
2108
+ );
2109
+ }
2110
+ /**
2111
+ * y offset of each row's top edge (content coordinates, before scroll) plus
2112
+ * the total content height — drives both drawing and the scroll spacer.
2113
+ */
2114
+ getRowOffsets(windowStart, windowEnd) {
2115
+ const offsetOf = /* @__PURE__ */ new Map();
2116
+ let y = 0;
2117
+ for (const rowId of this.rowOrder) {
2118
+ offsetOf.set(rowId, y);
2119
+ y += this.getRowHeight(rowId, windowStart, windowEnd);
2120
+ }
2121
+ return { offsetOf, totalHeight: y };
2122
+ }
2123
+ subscribe(listener) {
2124
+ this.listeners.add(listener);
2125
+ return () => this.listeners.delete(listener);
2126
+ }
2127
+ insert(event) {
2128
+ const index = this.rowIndexes.get(event.rowId);
2129
+ if (!index) return;
2130
+ index.events.splice(binaryInsertIndex(index.events, event), 0, event);
2131
+ index.lanesDirty = true;
2132
+ this.eventRow.set(event.id, event.rowId);
2133
+ }
2134
+ remove(id) {
2135
+ const rowId = this.eventRow.get(id);
2136
+ if (rowId === void 0) return;
2137
+ const index = this.rowIndexes.get(rowId);
2138
+ if (index) {
2139
+ const at = index.events.findIndex((event) => event.id === id);
2140
+ if (at !== -1) index.events.splice(at, 1);
2141
+ index.lanesDirty = true;
2142
+ }
2143
+ this.eventRow.delete(id);
2144
+ }
2145
+ bump() {
2146
+ this.version++;
2147
+ for (const listener of this.listeners) listener();
2148
+ }
2149
+ };
2150
+
2151
+ // src/timeline.tsx
2152
+ var Timeline = (0, import_react7.forwardRef)(
2153
+ ({
2154
+ rows,
2155
+ events,
2156
+ staticEvents,
2157
+ onDrop,
2158
+ onResize,
2159
+ onEventClick,
2160
+ onEventHover,
2161
+ startDate,
2162
+ endDate,
2163
+ theme,
2164
+ drawEvent,
2165
+ additionalClassNames,
2166
+ showRTIndicator = true,
2167
+ eventsResize = true,
2168
+ eventPromptTemplate,
2169
+ showEventPrompt = true,
2170
+ panZoom,
2171
+ timeBar,
2172
+ animations = true
2173
+ }, handleRef) => {
2174
+ const [windowTime, setWindowTime] = (0, import_react7.useState)([
2175
+ new Date(
2176
+ startDate.getFullYear(),
2177
+ startDate.getMonth(),
2178
+ startDate.getDate(),
2179
+ startDate.getHours(),
2180
+ 0,
2181
+ 0
2182
+ ).getTime() / 1e3,
2183
+ new Date(
2184
+ endDate.getFullYear(),
2185
+ endDate.getMonth(),
2186
+ endDate.getDate(),
2187
+ endDate.getHours(),
2188
+ 0,
2189
+ 0
2190
+ ).getTime() / 1e3
2191
+ ]);
2192
+ const [cellWidth, setCellWidth] = (0, import_react7.useState)(0);
2193
+ const contentRef = (0, import_react7.useRef)(null);
2194
+ const mainRef = (0, import_react7.useRef)(null);
2195
+ const bodyRef = (0, import_react7.useRef)(null);
2196
+ const [tick, setTick] = (0, import_react7.useState)(null);
2197
+ const [scrollWidth, setScrollWidth] = (0, import_react7.useState)(0);
2198
+ const eventPromptRef = (0, import_react7.useRef)(null);
2199
+ const rendererRef = (0, import_react7.useRef)(null);
2200
+ const sceneRef = (0, import_react7.useRef)(null);
2201
+ if (sceneRef.current === null) {
2202
+ sceneRef.current = new SceneStore();
2203
+ }
2204
+ const scene = sceneRef.current;
2205
+ (0, import_react7.useEffect)(() => {
2206
+ scene.setRows(rows);
2207
+ }, [scene, rows]);
2208
+ (0, import_react7.useEffect)(() => {
2209
+ scene.setEvents([...events].sort(sort_events_default));
2210
+ }, [scene, events]);
2211
+ (0, import_react7.useEffect)(() => {
2212
+ scene.setStaticEvents(staticEvents ? [...staticEvents] : []);
2213
+ }, [scene, staticEvents]);
2214
+ const windowTimeRef = (0, import_react7.useRef)(windowTime);
2215
+ windowTimeRef.current = windowTime;
2216
+ (0, import_react7.useImperativeHandle)(
2217
+ handleRef,
2218
+ () => ({
2219
+ setEvents: (next) => scene.setEvents([...next].sort(sort_events_default)),
2220
+ updateEvents: (patches) => scene.applyPatches(patches),
2221
+ getEvent: (id) => scene.getEvent(id),
2222
+ scrollToRow: (rowId) => {
2223
+ const [windowStart, windowEnd] = windowTimeRef.current;
2224
+ const offset2 = scene.getRowOffsets(windowStart, windowEnd).offsetOf.get(rowId);
2225
+ if (offset2 !== void 0 && bodyRef.current) {
2226
+ bodyRef.current.scrollTop = offset2;
2227
+ }
2228
+ },
2229
+ scrollToTime: (time) => {
2230
+ setWindowTime((prev) => [time, time + (prev[1] - prev[0])]);
2231
+ },
2232
+ setWindow: (startTime, endTime) => setWindowTime([startTime, endTime]),
2233
+ getVisibleRange: () => ({
2234
+ startTime: windowTimeRef.current[0],
2235
+ endTime: windowTimeRef.current[1]
2236
+ }),
2237
+ redraw: () => {
2238
+ var _a;
2239
+ return (_a = rendererRef.current) == null ? void 0 : _a.invalidate("all");
2240
+ }
2241
+ }),
2242
+ [scene]
2243
+ );
2244
+ (0, import_react7.useEffect)(() => {
2245
+ if (contentRef.current) {
2246
+ const windowDuration = windowTime[1] - windowTime[0];
2247
+ const numberOfHourBlocks = windowDuration / 3600;
2248
+ setTick(
2249
+ windowDuration / contentRef.current.getBoundingClientRect().width
2250
+ );
2251
+ setCellWidth(
2252
+ contentRef.current.getBoundingClientRect().width / numberOfHourBlocks
2253
+ );
2254
+ }
2255
+ }, []);
2256
+ (0, import_react7.useEffect)(() => {
2257
+ if (bodyRef.current) {
2258
+ setScrollWidth(
2259
+ bodyRef.current.getBoundingClientRect().width - bodyRef.current.scrollWidth
2260
+ );
2261
+ }
2262
+ }, []);
2263
+ use_resize_observer_default({ contentRef, setCellWidth, setTick, windowTime });
2264
+ const resolvedTheme = (0, import_react7.useMemo)(() => resolveTheme(theme), [theme]);
2265
+ const geometry = (0, import_react7.useMemo)(
2266
+ () => geometryFromTheme(resolvedTheme),
2267
+ [resolvedTheme]
2268
+ );
2269
+ (0, import_react7.useEffect)(() => {
2270
+ scene.setGeometry(geometry);
2271
+ }, [scene, geometry]);
2272
+ const resolvedAnimations = (0, import_react7.useMemo)(() => {
2273
+ var _a, _b;
2274
+ if (animations === false) return { layoutMs: 0, fadeMs: 0 };
2275
+ if (animations === true) {
2276
+ return {
2277
+ layoutMs: DEFAULT_LAYOUT_DURATION_MS,
2278
+ fadeMs: DEFAULT_FADE_DURATION_MS
2279
+ };
2280
+ }
2281
+ return {
2282
+ layoutMs: (_a = animations.layoutMs) != null ? _a : DEFAULT_LAYOUT_DURATION_MS,
2283
+ fadeMs: (_b = animations.fadeMs) != null ? _b : DEFAULT_FADE_DURATION_MS
2284
+ };
2285
+ }, [animations]);
2286
+ const eventPrompt = (0, import_react7.useMemo)(
2287
+ () => /* @__PURE__ */ import_react7.default.createElement(
2288
+ event_prompt_default,
2289
+ {
2290
+ ref: eventPromptRef,
2291
+ template: eventPromptTemplate
2292
+ }
2293
+ ),
2294
+ [eventPromptTemplate]
2295
+ );
2296
+ return /* @__PURE__ */ import_react7.default.createElement("div", { className: "main-wrapper", ref: mainRef }, showRTIndicator && /* @__PURE__ */ import_react7.default.createElement(rt_indicator_default, { tick, windowTime }), /* @__PURE__ */ import_react7.default.createElement(
2297
+ canvas_time_bar_default,
2298
+ {
2299
+ windowTime,
2300
+ tick,
2301
+ contentWidth: contentRef.current ? contentRef.current.getBoundingClientRect().width : null,
2302
+ scrollWidth,
2303
+ theme: resolvedTheme,
2304
+ timeBar
2305
+ }
2306
+ ), /* @__PURE__ */ import_react7.default.createElement("div", { className: "body-wrapper", ref: bodyRef }, /* @__PURE__ */ import_react7.default.createElement(
2307
+ canvas_board_default,
2308
+ {
2309
+ scene,
2310
+ rows,
2311
+ windowTime,
2312
+ tick,
2313
+ cellWidth,
2314
+ theme: resolvedTheme,
2315
+ drawEvent,
2316
+ bodyRef,
2317
+ rendererRef,
2318
+ eventPromptRef,
2319
+ rowsHeaderClassName: additionalClassNames == null ? void 0 : additionalClassNames.rowsHeader,
2320
+ setWindowTime,
2321
+ setCellWidth,
2322
+ setTick,
2323
+ onDrop,
2324
+ onResize,
2325
+ onEventClick,
2326
+ onEventHover,
2327
+ eventsResize,
2328
+ panZoom,
2329
+ animations: resolvedAnimations,
2330
+ ref: contentRef
2331
+ }
2332
+ ), showEventPrompt && eventPrompt));
2333
+ }
2334
+ );
2335
+ // Annotate the CommonJS export names for ESM import in node:
2336
+ 0 && (module.exports = {
2337
+ Timeline
2338
+ });
1924
2339
  //# sourceMappingURL=index.js.map