awesome-timeline-react 0.1.8 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs ADDED
@@ -0,0 +1,1829 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
4
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __spreadValues = (a, b) => {
7
+ for (var prop in b || (b = {}))
8
+ if (__hasOwnProp.call(b, prop))
9
+ __defNormalProp(a, prop, b[prop]);
10
+ if (__getOwnPropSymbols)
11
+ for (var prop of __getOwnPropSymbols(b)) {
12
+ if (__propIsEnum.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ }
15
+ return a;
16
+ };
17
+
18
+ // src/timeline.tsx
19
+ import React13, { useEffect as useEffect6, useRef as useRef8, useState as useState5 } from "react";
20
+
21
+ // src/components/time-bar.tsx
22
+ import React2, { useRef } from "react";
23
+
24
+ // src/hooks/use-generate-blocks.tsx
25
+ import React from "react";
26
+ import { useMemo } from "react";
27
+
28
+ // src/helpers/get-month-name.ts
29
+ var getMonthName = (monthIndex) => {
30
+ let monthName = null;
31
+ switch (monthIndex) {
32
+ case 0:
33
+ monthName = "Jan";
34
+ break;
35
+ case 1:
36
+ monthName = "Feb";
37
+ break;
38
+ case 2:
39
+ monthName = "Mar";
40
+ break;
41
+ case 3:
42
+ monthName = "Apr";
43
+ break;
44
+ case 4:
45
+ monthName = "May";
46
+ break;
47
+ case 5:
48
+ monthName = "Jun";
49
+ break;
50
+ case 6:
51
+ monthName = "Jul";
52
+ break;
53
+ case 7:
54
+ monthName = "Aug";
55
+ break;
56
+ case 8:
57
+ monthName = "Sep";
58
+ break;
59
+ case 9:
60
+ monthName = "Oct";
61
+ break;
62
+ case 10:
63
+ monthName = "Nov";
64
+ break;
65
+ case 11:
66
+ monthName = "Dec";
67
+ break;
68
+ default:
69
+ monthName = "Jan";
70
+ }
71
+ return monthName;
72
+ };
73
+ var get_month_name_default = getMonthName;
74
+
75
+ // src/helpers/get-week-day-name.ts
76
+ var getWeekDayName = (dayIndex) => {
77
+ let dayName = null;
78
+ switch (dayIndex) {
79
+ case 0:
80
+ dayName = "Mon";
81
+ break;
82
+ case 1:
83
+ dayName = "Tue";
84
+ break;
85
+ case 2:
86
+ dayName = "Wed";
87
+ break;
88
+ case 3:
89
+ dayName = "Thu";
90
+ break;
91
+ case 4:
92
+ dayName = "Fri";
93
+ break;
94
+ case 5:
95
+ dayName = "Sat";
96
+ break;
97
+ case 6:
98
+ dayName = "Sun";
99
+ break;
100
+ default:
101
+ dayName = "Mon";
102
+ }
103
+ return dayName;
104
+ };
105
+ var get_week_day_name_default = getWeekDayName;
106
+
107
+ // src/hooks/use-generate-blocks.tsx
108
+ var useGenerateBlocks = ({
109
+ windowTime,
110
+ tick,
111
+ contentWidth,
112
+ blockWidth
113
+ }) => {
114
+ const { dayBlocks, hourBlocks } = useMemo(() => {
115
+ let timePoint = windowTime[0];
116
+ const dayBlocks2 = [];
117
+ const hourBlocks2 = [];
118
+ if (tick === null || contentWidth === null) {
119
+ return { dayBlocks: [], hourBlocks: [] };
120
+ }
121
+ let widthLeft = contentWidth;
122
+ let prevNumBlocks = 1;
123
+ while (1) {
124
+ let datePoint = new Date(timePoint * 1e3);
125
+ const endDatePoint = new Date(
126
+ datePoint.getFullYear(),
127
+ datePoint.getMonth(),
128
+ datePoint.getDate(),
129
+ 23,
130
+ 59,
131
+ 59
132
+ );
133
+ const dateDuration = endDatePoint.getTime() - datePoint.getTime();
134
+ const dateWidth = dateDuration / 1e3 / tick;
135
+ widthLeft -= dateWidth;
136
+ if (Math.round(widthLeft) < 0) {
137
+ const numBlocks2 = Math.round((dateWidth + widthLeft) / blockWidth);
138
+ for (let i = 0; i < numBlocks2; i++) {
139
+ hourBlocks2.push(
140
+ /* @__PURE__ */ React.createElement(
141
+ "div",
142
+ {
143
+ className: "hour-block",
144
+ key: `${datePoint.getDate()}_hour_${i}`
145
+ },
146
+ i < 10 ? `0${i}:00` : `${i}:00`
147
+ )
148
+ );
149
+ }
150
+ dayBlocks2.push(
151
+ /* @__PURE__ */ React.createElement(
152
+ "div",
153
+ {
154
+ className: "day-block",
155
+ key: `${datePoint.getDate()} ${datePoint.getMonth()}`,
156
+ style: {
157
+ gridColumn: `${prevNumBlocks} / ${prevNumBlocks + numBlocks2}`
158
+ // width: dateWidth + widthLeft,
159
+ // minWidth: dateWidth + widthLeft,
160
+ }
161
+ },
162
+ get_week_day_name_default(datePoint.getDay()),
163
+ " ",
164
+ datePoint.getDate(),
165
+ " ",
166
+ get_month_name_default(datePoint.getMonth())
167
+ )
168
+ );
169
+ prevNumBlocks += numBlocks2;
170
+ break;
171
+ }
172
+ const numBlocks = Math.round(dateWidth / blockWidth);
173
+ for (let i = 24 - numBlocks; i < 24; i++) {
174
+ hourBlocks2.push(
175
+ /* @__PURE__ */ React.createElement("div", { className: "hour-block", key: `${datePoint.getDate()}_hour_${i}` }, i < 10 ? `0${i}:00` : `${i}:00`)
176
+ );
177
+ }
178
+ dayBlocks2.push(
179
+ /* @__PURE__ */ React.createElement(
180
+ "div",
181
+ {
182
+ className: "day-block",
183
+ key: `${datePoint.getDate()} ${datePoint.getMonth()}`,
184
+ style: {
185
+ gridColumn: `${prevNumBlocks} / ${prevNumBlocks + numBlocks}`
186
+ // width: dateWidth,
187
+ // minWidth: dateWidth,
188
+ }
189
+ },
190
+ get_week_day_name_default(datePoint.getDay()),
191
+ " ",
192
+ datePoint.getDate(),
193
+ " ",
194
+ get_month_name_default(datePoint.getMonth())
195
+ )
196
+ );
197
+ prevNumBlocks += numBlocks;
198
+ if (Math.round(widthLeft) === 0) {
199
+ break;
200
+ }
201
+ timePoint = (endDatePoint.getTime() + 1e3) / 1e3;
202
+ }
203
+ return { dayBlocks: dayBlocks2, hourBlocks: hourBlocks2 };
204
+ }, [tick, windowTime, contentWidth]);
205
+ return { dayBlocks, hourBlocks };
206
+ };
207
+ var use_generate_blocks_default = useGenerateBlocks;
208
+
209
+ // src/hooks/use-get-block-properties.ts
210
+ import { useMemo as useMemo2 } from "react";
211
+ var useGetBlockProperties = ({
212
+ windowTime,
213
+ contentWidth
214
+ }) => {
215
+ const numberOfHourBlocks = useMemo2(
216
+ () => (windowTime[1] - windowTime[0]) / 3600,
217
+ [windowTime]
218
+ );
219
+ const blockWidth = contentWidth ? contentWidth / numberOfHourBlocks : 0;
220
+ return { numberOfHourBlocks, blockWidth };
221
+ };
222
+ var use_get_block_properties_default = useGetBlockProperties;
223
+
224
+ // src/components/time-bar.tsx
225
+ var TimeBar = ({
226
+ windowTime,
227
+ tick,
228
+ contentWidth,
229
+ scrollWidth,
230
+ additionalClassNames
231
+ }) => {
232
+ const timeContentRef = useRef(null);
233
+ const { blockWidth } = use_get_block_properties_default({
234
+ windowTime,
235
+ contentWidth
236
+ });
237
+ const { dayBlocks, hourBlocks } = use_generate_blocks_default({
238
+ windowTime,
239
+ tick,
240
+ contentWidth,
241
+ blockWidth
242
+ });
243
+ const timeBarClassNames = (additionalClassNames == null ? void 0 : additionalClassNames.timeBar) ? "time-bar " + additionalClassNames.timeBar : "time-bar";
244
+ const dayRowClassNames = (additionalClassNames == null ? void 0 : additionalClassNames.dayRow) ? "day-row " + additionalClassNames.dayRow : "day-row";
245
+ const hourRowClassNames = (additionalClassNames == null ? void 0 : additionalClassNames.hourRow) ? "hour-row " + additionalClassNames.hourRow : "hour-row";
246
+ return /* @__PURE__ */ React2.createElement("div", { className: timeBarClassNames }, /* @__PURE__ */ React2.createElement("div", { className: "empty-block" }), /* @__PURE__ */ React2.createElement(
247
+ "div",
248
+ {
249
+ className: "time-content",
250
+ ref: timeContentRef,
251
+ style: { minWidth: contentWidth ? contentWidth : 0 }
252
+ },
253
+ /* @__PURE__ */ React2.createElement(
254
+ "div",
255
+ {
256
+ className: dayRowClassNames,
257
+ style: {
258
+ gridTemplateColumns: `repeat(auto-fill, minmax(${blockWidth}px, 1fr))`
259
+ }
260
+ },
261
+ dayBlocks.map((block) => block)
262
+ ),
263
+ /* @__PURE__ */ React2.createElement(
264
+ "div",
265
+ {
266
+ className: hourRowClassNames,
267
+ style: {
268
+ gridTemplateColumns: `repeat(auto-fill, minmax(${blockWidth}px, 1fr))`
269
+ }
270
+ },
271
+ hourBlocks.map((block) => block)
272
+ )
273
+ ), scrollWidth ? /* @__PURE__ */ React2.createElement(
274
+ "div",
275
+ {
276
+ style: {
277
+ width: scrollWidth,
278
+ height: "100%",
279
+ boxSizing: "border-box",
280
+ borderLeft: "1px solid yellow"
281
+ }
282
+ }
283
+ ) : null);
284
+ };
285
+ var time_bar_default = TimeBar;
286
+
287
+ // src/components/rows-header.tsx
288
+ import React4 from "react";
289
+
290
+ // src/components/row-header.tsx
291
+ import React3, { useContext } from "react";
292
+
293
+ // src/contexts/row-height-context.ts
294
+ import { createContext } from "react";
295
+ var RowsHeightContext = createContext(
296
+ null
297
+ );
298
+
299
+ // src/components/row-header.tsx
300
+ var RowHeader = ({ name, id }) => {
301
+ const rowsHeightContext = useContext(RowsHeightContext);
302
+ const minHeight = rowsHeightContext && rowsHeightContext.rowsHeight && rowsHeightContext.rowsHeight[id] ? rowsHeightContext.rowsHeight[id].minHeight : 40;
303
+ return /* @__PURE__ */ React3.createElement("div", { className: "row-header", style: { minHeight } }, name);
304
+ };
305
+ var row_header_default = RowHeader;
306
+
307
+ // src/components/rows-header.tsx
308
+ var RowsHeader = ({
309
+ rows,
310
+ className
311
+ }) => {
312
+ const classNames = className ? "rows-header-wrapper " + className : "rows-header-wrapper";
313
+ return /* @__PURE__ */ React4.createElement("div", { className: classNames }, rows.map((row) => /* @__PURE__ */ React4.createElement(
314
+ row_header_default,
315
+ {
316
+ key: `row_header_${row.id}`,
317
+ id: row.id,
318
+ name: row.name
319
+ }
320
+ )));
321
+ };
322
+ var rows_header_default = RowsHeader;
323
+
324
+ // src/components/content.tsx
325
+ import React11, {
326
+ forwardRef as forwardRef2,
327
+ useCallback as useCallback5,
328
+ useContext as useContext6,
329
+ useEffect as useEffect3,
330
+ useRef as useRef5,
331
+ useState as useState3
332
+ } from "react";
333
+
334
+ // src/components/lines-canvas.tsx
335
+ import React5 from "react";
336
+ import { useMemo as useMemo3 } from "react";
337
+ var LinesCanvas = ({
338
+ contentWidth,
339
+ cellWidth,
340
+ lineClassName
341
+ }) => {
342
+ const lines = useMemo3(() => {
343
+ const lines2 = [];
344
+ const classNames = lineClassName ? "line " + lineClassName : "line";
345
+ if (contentWidth) {
346
+ for (let i = cellWidth; i < contentWidth; i = i + cellWidth) {
347
+ lines2.push(/* @__PURE__ */ React5.createElement("div", { key: `line_${i}`, className: classNames }));
348
+ }
349
+ }
350
+ return lines2;
351
+ }, [cellWidth, contentWidth]);
352
+ const minWidth = useMemo3(() => {
353
+ return contentWidth ? contentWidth - lines.length * cellWidth : 0;
354
+ }, [contentWidth, cellWidth, lines]);
355
+ return /* @__PURE__ */ React5.createElement(
356
+ "div",
357
+ {
358
+ className: minWidth < 1 ? "lines-canvas hide-last-line" : "lines-canvas",
359
+ style: minWidth < 1 ? {
360
+ gridTemplateColumns: `repeat(auto-fill, minmax(${cellWidth}px, 1fr))`
361
+ } : {
362
+ gridTemplateColumns: `repeat(auto-fill, minmax(${minWidth}px, ${cellWidth}px))`
363
+ }
364
+ },
365
+ lines
366
+ );
367
+ };
368
+ var lines_canvas_default = LinesCanvas;
369
+
370
+ // src/hooks/use-produce-content.tsx
371
+ import { useContext as useContext5, useEffect as useEffect2, useMemo as useMemo5, useRef as useRef4 } from "react";
372
+ import React10 from "react";
373
+
374
+ // src/components/static-event.tsx
375
+ import React6 from "react";
376
+ var StaticEvent = ({
377
+ id,
378
+ startPosition,
379
+ width,
380
+ top,
381
+ height
382
+ }) => {
383
+ return /* @__PURE__ */ React6.createElement(
384
+ "div",
385
+ {
386
+ id: `static_event_${id}`,
387
+ key: `static_event_${id}`,
388
+ className: "static-event",
389
+ onDrop: (event) => event.stopPropagation(),
390
+ style: {
391
+ left: startPosition,
392
+ width,
393
+ top,
394
+ minHeight: height
395
+ }
396
+ }
397
+ );
398
+ };
399
+ var static_event_default = StaticEvent;
400
+
401
+ // src/components/row-content.tsx
402
+ import React7, {
403
+ forwardRef,
404
+ useCallback as useCallback2,
405
+ useContext as useContext3
406
+ } from "react";
407
+
408
+ // node_modules/immer/dist/immer.mjs
409
+ var NOTHING = Symbol.for("immer-nothing");
410
+ var DRAFTABLE = Symbol.for("immer-draftable");
411
+ var DRAFT_STATE = Symbol.for("immer-state");
412
+ var errors = process.env.NODE_ENV !== "production" ? [
413
+ // All error codes, starting by 0:
414
+ function(plugin) {
415
+ return `The plugin for '${plugin}' has not been loaded into Immer. To enable the plugin, import and call \`enable${plugin}()\` when initializing your application.`;
416
+ },
417
+ function(thing) {
418
+ 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}'`;
419
+ },
420
+ "This object has been frozen and should not be mutated",
421
+ function(data) {
422
+ return "Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? " + data;
423
+ },
424
+ "An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.",
425
+ "Immer forbids circular references",
426
+ "The first or second argument to `produce` must be a function",
427
+ "The third argument to `produce` must be a function or undefined",
428
+ "First argument to `createDraft` must be a plain object, an array, or an immerable object",
429
+ "First argument to `finishDraft` must be a draft returned by `createDraft`",
430
+ function(thing) {
431
+ return `'current' expects a draft, got: ${thing}`;
432
+ },
433
+ "Object.defineProperty() cannot be used on an Immer draft",
434
+ "Object.setPrototypeOf() cannot be used on an Immer draft",
435
+ "Immer only supports deleting array indices",
436
+ "Immer only supports setting array indices and the 'length' property",
437
+ function(thing) {
438
+ return `'original' expects a draft, got: ${thing}`;
439
+ }
440
+ // Note: if more errors are added, the errorOffset in Patches.ts should be increased
441
+ // See Patches.ts for additional errors
442
+ ] : [];
443
+ function die(error, ...args) {
444
+ if (process.env.NODE_ENV !== "production") {
445
+ const e = errors[error];
446
+ const msg = typeof e === "function" ? e.apply(null, args) : e;
447
+ throw new Error(`[Immer] ${msg}`);
448
+ }
449
+ throw new Error(
450
+ `[Immer] minified error nr: ${error}. Full error at: https://bit.ly/3cXEKWf`
451
+ );
452
+ }
453
+ var getPrototypeOf = Object.getPrototypeOf;
454
+ function isDraft(value) {
455
+ return !!value && !!value[DRAFT_STATE];
456
+ }
457
+ function isDraftable(value) {
458
+ var _a;
459
+ if (!value)
460
+ return false;
461
+ return isPlainObject(value) || Array.isArray(value) || !!value[DRAFTABLE] || !!((_a = value.constructor) == null ? void 0 : _a[DRAFTABLE]) || isMap(value) || isSet(value);
462
+ }
463
+ var objectCtorString = Object.prototype.constructor.toString();
464
+ function isPlainObject(value) {
465
+ if (!value || typeof value !== "object")
466
+ return false;
467
+ const proto = getPrototypeOf(value);
468
+ if (proto === null) {
469
+ return true;
470
+ }
471
+ const Ctor = Object.hasOwnProperty.call(proto, "constructor") && proto.constructor;
472
+ if (Ctor === Object)
473
+ return true;
474
+ return typeof Ctor == "function" && Function.toString.call(Ctor) === objectCtorString;
475
+ }
476
+ function each(obj, iter) {
477
+ if (getArchtype(obj) === 0) {
478
+ Reflect.ownKeys(obj).forEach((key) => {
479
+ iter(key, obj[key], obj);
480
+ });
481
+ } else {
482
+ obj.forEach((entry, index) => iter(index, entry, obj));
483
+ }
484
+ }
485
+ function getArchtype(thing) {
486
+ const state = thing[DRAFT_STATE];
487
+ return state ? state.type_ : Array.isArray(thing) ? 1 : isMap(thing) ? 2 : isSet(thing) ? 3 : 0;
488
+ }
489
+ function has(thing, prop) {
490
+ return getArchtype(thing) === 2 ? thing.has(prop) : Object.prototype.hasOwnProperty.call(thing, prop);
491
+ }
492
+ function set(thing, propOrOldValue, value) {
493
+ const t = getArchtype(thing);
494
+ if (t === 2)
495
+ thing.set(propOrOldValue, value);
496
+ else if (t === 3) {
497
+ thing.add(value);
498
+ } else
499
+ thing[propOrOldValue] = value;
500
+ }
501
+ function is(x, y) {
502
+ if (x === y) {
503
+ return x !== 0 || 1 / x === 1 / y;
504
+ } else {
505
+ return x !== x && y !== y;
506
+ }
507
+ }
508
+ function isMap(target) {
509
+ return target instanceof Map;
510
+ }
511
+ function isSet(target) {
512
+ return target instanceof Set;
513
+ }
514
+ function latest(state) {
515
+ return state.copy_ || state.base_;
516
+ }
517
+ function shallowCopy(base, strict) {
518
+ if (isMap(base)) {
519
+ return new Map(base);
520
+ }
521
+ if (isSet(base)) {
522
+ return new Set(base);
523
+ }
524
+ if (Array.isArray(base))
525
+ return Array.prototype.slice.call(base);
526
+ const isPlain = isPlainObject(base);
527
+ if (strict === true || strict === "class_only" && !isPlain) {
528
+ const descriptors = Object.getOwnPropertyDescriptors(base);
529
+ delete descriptors[DRAFT_STATE];
530
+ let keys = Reflect.ownKeys(descriptors);
531
+ for (let i = 0; i < keys.length; i++) {
532
+ const key = keys[i];
533
+ const desc = descriptors[key];
534
+ if (desc.writable === false) {
535
+ desc.writable = true;
536
+ desc.configurable = true;
537
+ }
538
+ if (desc.get || desc.set)
539
+ descriptors[key] = {
540
+ configurable: true,
541
+ writable: true,
542
+ // could live with !!desc.set as well here...
543
+ enumerable: desc.enumerable,
544
+ value: base[key]
545
+ };
546
+ }
547
+ return Object.create(getPrototypeOf(base), descriptors);
548
+ } else {
549
+ const proto = getPrototypeOf(base);
550
+ if (proto !== null && isPlain) {
551
+ return __spreadValues({}, base);
552
+ }
553
+ const obj = Object.create(proto);
554
+ return Object.assign(obj, base);
555
+ }
556
+ }
557
+ function freeze(obj, deep = false) {
558
+ if (isFrozen(obj) || isDraft(obj) || !isDraftable(obj))
559
+ return obj;
560
+ if (getArchtype(obj) > 1) {
561
+ obj.set = obj.add = obj.clear = obj.delete = dontMutateFrozenCollections;
562
+ }
563
+ Object.freeze(obj);
564
+ if (deep)
565
+ Object.entries(obj).forEach(([key, value]) => freeze(value, true));
566
+ return obj;
567
+ }
568
+ function dontMutateFrozenCollections() {
569
+ die(2);
570
+ }
571
+ function isFrozen(obj) {
572
+ return Object.isFrozen(obj);
573
+ }
574
+ var plugins = {};
575
+ function getPlugin(pluginKey) {
576
+ const plugin = plugins[pluginKey];
577
+ if (!plugin) {
578
+ die(0, pluginKey);
579
+ }
580
+ return plugin;
581
+ }
582
+ var currentScope;
583
+ function getCurrentScope() {
584
+ return currentScope;
585
+ }
586
+ function createScope(parent_, immer_) {
587
+ return {
588
+ drafts_: [],
589
+ parent_,
590
+ immer_,
591
+ // Whenever the modified draft contains a draft from another scope, we
592
+ // need to prevent auto-freezing so the unowned draft can be finalized.
593
+ canAutoFreeze_: true,
594
+ unfinalizedDrafts_: 0
595
+ };
596
+ }
597
+ function usePatchesInScope(scope, patchListener) {
598
+ if (patchListener) {
599
+ getPlugin("Patches");
600
+ scope.patches_ = [];
601
+ scope.inversePatches_ = [];
602
+ scope.patchListener_ = patchListener;
603
+ }
604
+ }
605
+ function revokeScope(scope) {
606
+ leaveScope(scope);
607
+ scope.drafts_.forEach(revokeDraft);
608
+ scope.drafts_ = null;
609
+ }
610
+ function leaveScope(scope) {
611
+ if (scope === currentScope) {
612
+ currentScope = scope.parent_;
613
+ }
614
+ }
615
+ function enterScope(immer2) {
616
+ return currentScope = createScope(currentScope, immer2);
617
+ }
618
+ function revokeDraft(draft) {
619
+ const state = draft[DRAFT_STATE];
620
+ if (state.type_ === 0 || state.type_ === 1)
621
+ state.revoke_();
622
+ else
623
+ state.revoked_ = true;
624
+ }
625
+ function processResult(result, scope) {
626
+ scope.unfinalizedDrafts_ = scope.drafts_.length;
627
+ const baseDraft = scope.drafts_[0];
628
+ const isReplaced = result !== void 0 && result !== baseDraft;
629
+ if (isReplaced) {
630
+ if (baseDraft[DRAFT_STATE].modified_) {
631
+ revokeScope(scope);
632
+ die(4);
633
+ }
634
+ if (isDraftable(result)) {
635
+ result = finalize(scope, result);
636
+ if (!scope.parent_)
637
+ maybeFreeze(scope, result);
638
+ }
639
+ if (scope.patches_) {
640
+ getPlugin("Patches").generateReplacementPatches_(
641
+ baseDraft[DRAFT_STATE].base_,
642
+ result,
643
+ scope.patches_,
644
+ scope.inversePatches_
645
+ );
646
+ }
647
+ } else {
648
+ result = finalize(scope, baseDraft, []);
649
+ }
650
+ revokeScope(scope);
651
+ if (scope.patches_) {
652
+ scope.patchListener_(scope.patches_, scope.inversePatches_);
653
+ }
654
+ return result !== NOTHING ? result : void 0;
655
+ }
656
+ function finalize(rootScope, value, path) {
657
+ if (isFrozen(value))
658
+ return value;
659
+ const state = value[DRAFT_STATE];
660
+ if (!state) {
661
+ each(
662
+ value,
663
+ (key, childValue) => finalizeProperty(rootScope, state, value, key, childValue, path)
664
+ );
665
+ return value;
666
+ }
667
+ if (state.scope_ !== rootScope)
668
+ return value;
669
+ if (!state.modified_) {
670
+ maybeFreeze(rootScope, state.base_, true);
671
+ return state.base_;
672
+ }
673
+ if (!state.finalized_) {
674
+ state.finalized_ = true;
675
+ state.scope_.unfinalizedDrafts_--;
676
+ const result = state.copy_;
677
+ let resultEach = result;
678
+ let isSet2 = false;
679
+ if (state.type_ === 3) {
680
+ resultEach = new Set(result);
681
+ result.clear();
682
+ isSet2 = true;
683
+ }
684
+ each(
685
+ resultEach,
686
+ (key, childValue) => finalizeProperty(rootScope, state, result, key, childValue, path, isSet2)
687
+ );
688
+ maybeFreeze(rootScope, result, false);
689
+ if (path && rootScope.patches_) {
690
+ getPlugin("Patches").generatePatches_(
691
+ state,
692
+ path,
693
+ rootScope.patches_,
694
+ rootScope.inversePatches_
695
+ );
696
+ }
697
+ }
698
+ return state.copy_;
699
+ }
700
+ function finalizeProperty(rootScope, parentState, targetObject, prop, childValue, rootPath, targetIsSet) {
701
+ if (process.env.NODE_ENV !== "production" && childValue === targetObject)
702
+ die(5);
703
+ if (isDraft(childValue)) {
704
+ const path = rootPath && parentState && parentState.type_ !== 3 && // Set objects are atomic since they have no keys.
705
+ !has(parentState.assigned_, prop) ? rootPath.concat(prop) : void 0;
706
+ const res = finalize(rootScope, childValue, path);
707
+ set(targetObject, prop, res);
708
+ if (isDraft(res)) {
709
+ rootScope.canAutoFreeze_ = false;
710
+ } else
711
+ return;
712
+ } else if (targetIsSet) {
713
+ targetObject.add(childValue);
714
+ }
715
+ if (isDraftable(childValue) && !isFrozen(childValue)) {
716
+ if (!rootScope.immer_.autoFreeze_ && rootScope.unfinalizedDrafts_ < 1) {
717
+ return;
718
+ }
719
+ finalize(rootScope, childValue);
720
+ if ((!parentState || !parentState.scope_.parent_) && typeof prop !== "symbol" && Object.prototype.propertyIsEnumerable.call(targetObject, prop))
721
+ maybeFreeze(rootScope, childValue);
722
+ }
723
+ }
724
+ function maybeFreeze(scope, value, deep = false) {
725
+ if (!scope.parent_ && scope.immer_.autoFreeze_ && scope.canAutoFreeze_) {
726
+ freeze(value, deep);
727
+ }
728
+ }
729
+ function createProxyProxy(base, parent) {
730
+ const isArray = Array.isArray(base);
731
+ const state = {
732
+ type_: isArray ? 1 : 0,
733
+ // Track which produce call this is associated with.
734
+ scope_: parent ? parent.scope_ : getCurrentScope(),
735
+ // True for both shallow and deep changes.
736
+ modified_: false,
737
+ // Used during finalization.
738
+ finalized_: false,
739
+ // Track which properties have been assigned (true) or deleted (false).
740
+ assigned_: {},
741
+ // The parent draft state.
742
+ parent_: parent,
743
+ // The base state.
744
+ base_: base,
745
+ // The base proxy.
746
+ draft_: null,
747
+ // set below
748
+ // The base copy with any updated values.
749
+ copy_: null,
750
+ // Called by the `produce` function.
751
+ revoke_: null,
752
+ isManual_: false
753
+ };
754
+ let target = state;
755
+ let traps = objectTraps;
756
+ if (isArray) {
757
+ target = [state];
758
+ traps = arrayTraps;
759
+ }
760
+ const { revoke, proxy } = Proxy.revocable(target, traps);
761
+ state.draft_ = proxy;
762
+ state.revoke_ = revoke;
763
+ return proxy;
764
+ }
765
+ var objectTraps = {
766
+ get(state, prop) {
767
+ if (prop === DRAFT_STATE)
768
+ return state;
769
+ const source = latest(state);
770
+ if (!has(source, prop)) {
771
+ return readPropFromProto(state, source, prop);
772
+ }
773
+ const value = source[prop];
774
+ if (state.finalized_ || !isDraftable(value)) {
775
+ return value;
776
+ }
777
+ if (value === peek(state.base_, prop)) {
778
+ prepareCopy(state);
779
+ return state.copy_[prop] = createProxy(value, state);
780
+ }
781
+ return value;
782
+ },
783
+ has(state, prop) {
784
+ return prop in latest(state);
785
+ },
786
+ ownKeys(state) {
787
+ return Reflect.ownKeys(latest(state));
788
+ },
789
+ set(state, prop, value) {
790
+ const desc = getDescriptorFromProto(latest(state), prop);
791
+ if (desc == null ? void 0 : desc.set) {
792
+ desc.set.call(state.draft_, value);
793
+ return true;
794
+ }
795
+ if (!state.modified_) {
796
+ const current2 = peek(latest(state), prop);
797
+ const currentState = current2 == null ? void 0 : current2[DRAFT_STATE];
798
+ if (currentState && currentState.base_ === value) {
799
+ state.copy_[prop] = value;
800
+ state.assigned_[prop] = false;
801
+ return true;
802
+ }
803
+ if (is(value, current2) && (value !== void 0 || has(state.base_, prop)))
804
+ return true;
805
+ prepareCopy(state);
806
+ markChanged(state);
807
+ }
808
+ if (state.copy_[prop] === value && // special case: handle new props with value 'undefined'
809
+ (value !== void 0 || prop in state.copy_) || // special case: NaN
810
+ Number.isNaN(value) && Number.isNaN(state.copy_[prop]))
811
+ return true;
812
+ state.copy_[prop] = value;
813
+ state.assigned_[prop] = true;
814
+ return true;
815
+ },
816
+ deleteProperty(state, prop) {
817
+ if (peek(state.base_, prop) !== void 0 || prop in state.base_) {
818
+ state.assigned_[prop] = false;
819
+ prepareCopy(state);
820
+ markChanged(state);
821
+ } else {
822
+ delete state.assigned_[prop];
823
+ }
824
+ if (state.copy_) {
825
+ delete state.copy_[prop];
826
+ }
827
+ return true;
828
+ },
829
+ // Note: We never coerce `desc.value` into an Immer draft, because we can't make
830
+ // the same guarantee in ES5 mode.
831
+ getOwnPropertyDescriptor(state, prop) {
832
+ const owner = latest(state);
833
+ const desc = Reflect.getOwnPropertyDescriptor(owner, prop);
834
+ if (!desc)
835
+ return desc;
836
+ return {
837
+ writable: true,
838
+ configurable: state.type_ !== 1 || prop !== "length",
839
+ enumerable: desc.enumerable,
840
+ value: owner[prop]
841
+ };
842
+ },
843
+ defineProperty() {
844
+ die(11);
845
+ },
846
+ getPrototypeOf(state) {
847
+ return getPrototypeOf(state.base_);
848
+ },
849
+ setPrototypeOf() {
850
+ die(12);
851
+ }
852
+ };
853
+ var arrayTraps = {};
854
+ each(objectTraps, (key, fn) => {
855
+ arrayTraps[key] = function() {
856
+ arguments[0] = arguments[0][0];
857
+ return fn.apply(this, arguments);
858
+ };
859
+ });
860
+ arrayTraps.deleteProperty = function(state, prop) {
861
+ if (process.env.NODE_ENV !== "production" && isNaN(parseInt(prop)))
862
+ die(13);
863
+ return arrayTraps.set.call(this, state, prop, void 0);
864
+ };
865
+ arrayTraps.set = function(state, prop, value) {
866
+ if (process.env.NODE_ENV !== "production" && prop !== "length" && isNaN(parseInt(prop)))
867
+ die(14);
868
+ return objectTraps.set.call(this, state[0], prop, value, state[0]);
869
+ };
870
+ function peek(draft, prop) {
871
+ const state = draft[DRAFT_STATE];
872
+ const source = state ? latest(state) : draft;
873
+ return source[prop];
874
+ }
875
+ function readPropFromProto(state, source, prop) {
876
+ var _a;
877
+ const desc = getDescriptorFromProto(source, prop);
878
+ return desc ? `value` in desc ? desc.value : (
879
+ // This is a very special case, if the prop is a getter defined by the
880
+ // prototype, we should invoke it with the draft as context!
881
+ (_a = desc.get) == null ? void 0 : _a.call(state.draft_)
882
+ ) : void 0;
883
+ }
884
+ function getDescriptorFromProto(source, prop) {
885
+ if (!(prop in source))
886
+ return void 0;
887
+ let proto = getPrototypeOf(source);
888
+ while (proto) {
889
+ const desc = Object.getOwnPropertyDescriptor(proto, prop);
890
+ if (desc)
891
+ return desc;
892
+ proto = getPrototypeOf(proto);
893
+ }
894
+ return void 0;
895
+ }
896
+ function markChanged(state) {
897
+ if (!state.modified_) {
898
+ state.modified_ = true;
899
+ if (state.parent_) {
900
+ markChanged(state.parent_);
901
+ }
902
+ }
903
+ }
904
+ function prepareCopy(state) {
905
+ if (!state.copy_) {
906
+ state.copy_ = shallowCopy(
907
+ state.base_,
908
+ state.scope_.immer_.useStrictShallowCopy_
909
+ );
910
+ }
911
+ }
912
+ var Immer2 = class {
913
+ constructor(config) {
914
+ this.autoFreeze_ = true;
915
+ this.useStrictShallowCopy_ = false;
916
+ this.produce = (base, recipe, patchListener) => {
917
+ if (typeof base === "function" && typeof recipe !== "function") {
918
+ const defaultBase = recipe;
919
+ recipe = base;
920
+ const self = this;
921
+ return function curriedProduce(base2 = defaultBase, ...args) {
922
+ return self.produce(base2, (draft) => recipe.call(this, draft, ...args));
923
+ };
924
+ }
925
+ if (typeof recipe !== "function")
926
+ die(6);
927
+ if (patchListener !== void 0 && typeof patchListener !== "function")
928
+ die(7);
929
+ let result;
930
+ if (isDraftable(base)) {
931
+ const scope = enterScope(this);
932
+ const proxy = createProxy(base, void 0);
933
+ let hasError = true;
934
+ try {
935
+ result = recipe(proxy);
936
+ hasError = false;
937
+ } finally {
938
+ if (hasError)
939
+ revokeScope(scope);
940
+ else
941
+ leaveScope(scope);
942
+ }
943
+ usePatchesInScope(scope, patchListener);
944
+ return processResult(result, scope);
945
+ } else if (!base || typeof base !== "object") {
946
+ result = recipe(base);
947
+ if (result === void 0)
948
+ result = base;
949
+ if (result === NOTHING)
950
+ result = void 0;
951
+ if (this.autoFreeze_)
952
+ freeze(result, true);
953
+ if (patchListener) {
954
+ const p = [];
955
+ const ip = [];
956
+ getPlugin("Patches").generateReplacementPatches_(base, result, p, ip);
957
+ patchListener(p, ip);
958
+ }
959
+ return result;
960
+ } else
961
+ die(1, base);
962
+ };
963
+ this.produceWithPatches = (base, recipe) => {
964
+ if (typeof base === "function") {
965
+ return (state, ...args) => this.produceWithPatches(state, (draft) => base(draft, ...args));
966
+ }
967
+ let patches, inversePatches;
968
+ const result = this.produce(base, recipe, (p, ip) => {
969
+ patches = p;
970
+ inversePatches = ip;
971
+ });
972
+ return [result, patches, inversePatches];
973
+ };
974
+ if (typeof (config == null ? void 0 : config.autoFreeze) === "boolean")
975
+ this.setAutoFreeze(config.autoFreeze);
976
+ if (typeof (config == null ? void 0 : config.useStrictShallowCopy) === "boolean")
977
+ this.setUseStrictShallowCopy(config.useStrictShallowCopy);
978
+ }
979
+ createDraft(base) {
980
+ if (!isDraftable(base))
981
+ die(8);
982
+ if (isDraft(base))
983
+ base = current(base);
984
+ const scope = enterScope(this);
985
+ const proxy = createProxy(base, void 0);
986
+ proxy[DRAFT_STATE].isManual_ = true;
987
+ leaveScope(scope);
988
+ return proxy;
989
+ }
990
+ finishDraft(draft, patchListener) {
991
+ const state = draft && draft[DRAFT_STATE];
992
+ if (!state || !state.isManual_)
993
+ die(9);
994
+ const { scope_: scope } = state;
995
+ usePatchesInScope(scope, patchListener);
996
+ return processResult(void 0, scope);
997
+ }
998
+ /**
999
+ * Pass true to automatically freeze all copies created by Immer.
1000
+ *
1001
+ * By default, auto-freezing is enabled.
1002
+ */
1003
+ setAutoFreeze(value) {
1004
+ this.autoFreeze_ = value;
1005
+ }
1006
+ /**
1007
+ * Pass true to enable strict shallow copy.
1008
+ *
1009
+ * By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.
1010
+ */
1011
+ setUseStrictShallowCopy(value) {
1012
+ this.useStrictShallowCopy_ = value;
1013
+ }
1014
+ applyPatches(base, patches) {
1015
+ let i;
1016
+ for (i = patches.length - 1; i >= 0; i--) {
1017
+ const patch = patches[i];
1018
+ if (patch.path.length === 0 && patch.op === "replace") {
1019
+ base = patch.value;
1020
+ break;
1021
+ }
1022
+ }
1023
+ if (i > -1) {
1024
+ patches = patches.slice(i + 1);
1025
+ }
1026
+ const applyPatchesImpl = getPlugin("Patches").applyPatches_;
1027
+ if (isDraft(base)) {
1028
+ return applyPatchesImpl(base, patches);
1029
+ }
1030
+ return this.produce(
1031
+ base,
1032
+ (draft) => applyPatchesImpl(draft, patches)
1033
+ );
1034
+ }
1035
+ };
1036
+ function createProxy(value, parent) {
1037
+ const draft = isMap(value) ? getPlugin("MapSet").proxyMap_(value, parent) : isSet(value) ? getPlugin("MapSet").proxySet_(value, parent) : createProxyProxy(value, parent);
1038
+ const scope = parent ? parent.scope_ : getCurrentScope();
1039
+ scope.drafts_.push(draft);
1040
+ return draft;
1041
+ }
1042
+ function current(value) {
1043
+ if (!isDraft(value))
1044
+ die(10, value);
1045
+ return currentImpl(value);
1046
+ }
1047
+ function currentImpl(value) {
1048
+ if (!isDraftable(value) || isFrozen(value))
1049
+ return value;
1050
+ const state = value[DRAFT_STATE];
1051
+ let copy;
1052
+ if (state) {
1053
+ if (!state.modified_)
1054
+ return state.base_;
1055
+ state.finalized_ = true;
1056
+ copy = shallowCopy(value, state.scope_.immer_.useStrictShallowCopy_);
1057
+ } else {
1058
+ copy = shallowCopy(value, true);
1059
+ }
1060
+ each(copy, (key, childValue) => {
1061
+ set(copy, key, currentImpl(childValue));
1062
+ });
1063
+ if (state) {
1064
+ state.finalized_ = false;
1065
+ }
1066
+ return copy;
1067
+ }
1068
+ var immer = new Immer2();
1069
+ var produce = immer.produce;
1070
+ var produceWithPatches = immer.produceWithPatches.bind(
1071
+ immer
1072
+ );
1073
+ var setAutoFreeze = immer.setAutoFreeze.bind(immer);
1074
+ var setUseStrictShallowCopy = immer.setUseStrictShallowCopy.bind(immer);
1075
+ var applyPatches = immer.applyPatches.bind(immer);
1076
+ var createDraft = immer.createDraft.bind(immer);
1077
+ var finishDraft = immer.finishDraft.bind(immer);
1078
+
1079
+ // src/contexts/drag-started-context.ts
1080
+ import { createContext as createContext2 } from "react";
1081
+ var DragStartedContext = createContext2({
1082
+ dragStarted: false,
1083
+ setDragStarted: () => {
1084
+ }
1085
+ });
1086
+
1087
+ // src/contexts/external-properties-context.ts
1088
+ import { createContext as createContext3 } from "react";
1089
+ var ExternalPropertiesContext = createContext3(
1090
+ {}
1091
+ );
1092
+
1093
+ // src/helpers/sort-events.ts
1094
+ var sortEvents = (eventA, eventB) => {
1095
+ if (eventA.startTime - eventB.startTime < 0) return -1;
1096
+ if (eventA.startTime === eventB.startTime) {
1097
+ if (eventA.endTime < eventB.endTime) {
1098
+ return -1;
1099
+ } else {
1100
+ return 1;
1101
+ }
1102
+ } else {
1103
+ return 1;
1104
+ }
1105
+ };
1106
+ var sort_events_default = sortEvents;
1107
+
1108
+ // src/components/row-content.tsx
1109
+ var RowContent = forwardRef((props, ref) => {
1110
+ const { setEvents, tick, id, windowTime, cellWidth, children } = props;
1111
+ const { dragStarted, setDragStarted } = useContext3(DragStartedContext);
1112
+ const { onDrop } = useContext3(ExternalPropertiesContext);
1113
+ const handleOnDrop = useCallback2(
1114
+ (event) => {
1115
+ event.preventDefault();
1116
+ const element = event.target;
1117
+ const { left } = element.getBoundingClientRect();
1118
+ const draggedEventId = event.dataTransfer.getData("eventId");
1119
+ const closestCell = Math.round((event.clientX - left) / cellWidth);
1120
+ const newPosition = cellWidth * closestCell;
1121
+ setEvents(
1122
+ produce((draft) => {
1123
+ const event2 = draft.find((event3) => event3.id === draggedEventId);
1124
+ if (event2 && tick) {
1125
+ const newStartTime = windowTime[0] + newPosition * tick;
1126
+ const eventDuration = event2.endTime - event2.startTime;
1127
+ const newEndTime = windowTime[0] + eventDuration + newPosition * tick;
1128
+ if (onDrop) {
1129
+ onDrop({
1130
+ eventId: event2.id,
1131
+ oldRowId: event2.rowId,
1132
+ newRowId: props.id,
1133
+ startTime: newStartTime,
1134
+ endTime: newEndTime
1135
+ });
1136
+ }
1137
+ event2.startTime = newStartTime;
1138
+ event2.endTime = newEndTime;
1139
+ event2.rowId = props.id;
1140
+ }
1141
+ draft.sort(sort_events_default);
1142
+ })
1143
+ );
1144
+ setDragStarted(false);
1145
+ },
1146
+ [setEvents, tick, windowTime, cellWidth]
1147
+ );
1148
+ const rowsHeightContext = useContext3(RowsHeightContext);
1149
+ const minHeight = rowsHeightContext && rowsHeightContext.rowsHeight && rowsHeightContext.rowsHeight[id] ? rowsHeightContext.rowsHeight[id].minHeight : 40;
1150
+ return /* @__PURE__ */ React7.createElement(
1151
+ "div",
1152
+ {
1153
+ id: `row_${id}`,
1154
+ ref,
1155
+ onDragOver: (event) => event.preventDefault(),
1156
+ onDrop: handleOnDrop,
1157
+ className: dragStarted ? "row-content not-clickable" : "row-content",
1158
+ "data-index": id,
1159
+ style: {
1160
+ minHeight
1161
+ // background: `linear-gradient(to left, white, white 1px, transparent 0, transparent 100%), repeating-linear-gradient(
1162
+ // to left,
1163
+ // #aaaaaa,
1164
+ // #aaaaaa 1px,
1165
+ // transparent 0px,
1166
+ // transparent ${cellWidth}px
1167
+ // )`,
1168
+ }
1169
+ },
1170
+ children
1171
+ );
1172
+ });
1173
+ var row_content_default = RowContent;
1174
+
1175
+ // src/components/event.tsx
1176
+ import React9, {
1177
+ useCallback as useCallback3,
1178
+ useContext as useContext4,
1179
+ useRef as useRef2,
1180
+ useState
1181
+ } from "react";
1182
+
1183
+ // src/assets/grip-lines-vertical-solid.svg
1184
+ import * as React8 from "react";
1185
+ var SvgGripLinesVerticalSolid = (props) => /* @__PURE__ */ React8.createElement("svg", __spreadValues({ xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 192 512" }, props), /* @__PURE__ */ React8.createElement("path", { d: "M64 64c0-17.7-14.3-32-32-32S0 46.3 0 64L0 448c0 17.7 14.3 32 32 32s32-14.3 32-32L64 64zm128 0c0-17.7-14.3-32-32-32s-32 14.3-32 32l0 384c0 17.7 14.3 32 32 32s32-14.3 32-32l0-384z" }));
1186
+ var grip_lines_vertical_solid_default = SvgGripLinesVerticalSolid;
1187
+
1188
+ // src/components/event.tsx
1189
+ var Event = ({
1190
+ id,
1191
+ startPosition,
1192
+ width,
1193
+ top,
1194
+ props,
1195
+ setEvents,
1196
+ tick
1197
+ }) => {
1198
+ const { setDragStarted } = useContext4(DragStartedContext);
1199
+ const { onResize, eventsResize } = useContext4(ExternalPropertiesContext);
1200
+ const initialPositionForResizeRef = useRef2(0);
1201
+ const handleOnDragStart = useCallback3(
1202
+ (event) => {
1203
+ event.stopPropagation();
1204
+ event.dataTransfer.setData("eventId", id);
1205
+ setTimeout(() => setDragStarted(true), 0);
1206
+ const target = event.target;
1207
+ target.style.opacity = "50%";
1208
+ },
1209
+ [setDragStarted]
1210
+ );
1211
+ const handleOnDragEnd = useCallback3(
1212
+ (event) => {
1213
+ event.stopPropagation();
1214
+ setDragStarted(false);
1215
+ const target = event.target;
1216
+ target.style.opacity = "100%";
1217
+ },
1218
+ [setDragStarted]
1219
+ );
1220
+ const classNames = (props == null ? void 0 : props.classNames) ? "event " + props.classNames.join(" ") : "event";
1221
+ const [draggableEvent, setDraggableEvent] = useState(true);
1222
+ const [resizeOffset, setResizeOffset] = useState(0);
1223
+ const resizeOffsetRef = useRef2(0);
1224
+ const [resizeStarted, setResizeStarted] = useState(false);
1225
+ const resizeDirectionRef = useRef2(null);
1226
+ const handleDocumentOnMouseMoveResize = useCallback3(
1227
+ (event) => {
1228
+ const offset = event.clientX - initialPositionForResizeRef.current;
1229
+ setResizeOffset(
1230
+ resizeDirectionRef.current === "left" ? offset * -1 : offset
1231
+ );
1232
+ resizeOffsetRef.current = offset;
1233
+ },
1234
+ [setResizeOffset]
1235
+ );
1236
+ const handleDocumentOnMouseUp = useCallback3(
1237
+ (event, resizeDirection) => {
1238
+ initialPositionForResizeRef.current = 0;
1239
+ setResizeStarted(false);
1240
+ document.removeEventListener(
1241
+ "mousemove",
1242
+ handleDocumentOnMouseMoveResize
1243
+ );
1244
+ const lockedStyle = document.getElementById("lock-cursor");
1245
+ if (lockedStyle) {
1246
+ lockedStyle.remove();
1247
+ }
1248
+ setEvents(
1249
+ produce((draft) => {
1250
+ const event2 = draft.find((event3) => event3.id === id);
1251
+ if (event2 && tick) {
1252
+ if (resizeDirection === "left") {
1253
+ const newStartTime = Math.round(
1254
+ event2.startTime + resizeOffsetRef.current * tick
1255
+ );
1256
+ event2.startTime = newStartTime;
1257
+ } else {
1258
+ const newEndTime = Math.round(
1259
+ event2.endTime + resizeOffsetRef.current * tick
1260
+ );
1261
+ event2.endTime = newEndTime;
1262
+ }
1263
+ if (onResize) {
1264
+ onResize({
1265
+ eventId: event2.id,
1266
+ startTime: event2.startTime,
1267
+ endTime: event2.endTime
1268
+ });
1269
+ }
1270
+ }
1271
+ draft.sort(sort_events_default);
1272
+ resizeOffsetRef.current = 0;
1273
+ setResizeOffset(0);
1274
+ })
1275
+ );
1276
+ },
1277
+ [
1278
+ handleDocumentOnMouseMoveResize,
1279
+ setEvents,
1280
+ tick,
1281
+ setResizeOffset,
1282
+ sort_events_default
1283
+ ]
1284
+ );
1285
+ const handleOnMouseDownEventResizer = useCallback3(
1286
+ (event, resizeDirection) => {
1287
+ event.stopPropagation();
1288
+ resizeDirectionRef.current = resizeDirection;
1289
+ setResizeStarted(true);
1290
+ const style = document.createElement("style");
1291
+ style.id = "lock-cursor";
1292
+ style.innerHTML = "* { cursor: e-resize !important; }";
1293
+ document.head.appendChild(style);
1294
+ document.addEventListener("mousemove", handleDocumentOnMouseMoveResize);
1295
+ document.addEventListener(
1296
+ "mouseup",
1297
+ (event2) => handleDocumentOnMouseUp(event2, resizeDirection),
1298
+ { once: true }
1299
+ );
1300
+ initialPositionForResizeRef.current = event.clientX;
1301
+ },
1302
+ [handleDocumentOnMouseMoveResize, handleDocumentOnMouseUp]
1303
+ );
1304
+ const handleOnMouseMove = useCallback3(
1305
+ (event) => {
1306
+ if (!resizeStarted) {
1307
+ event.stopPropagation();
1308
+ }
1309
+ },
1310
+ [resizeStarted]
1311
+ );
1312
+ return /* @__PURE__ */ React9.createElement(
1313
+ "div",
1314
+ {
1315
+ id: `event_${id}`,
1316
+ key: `event_${id}`,
1317
+ className: classNames,
1318
+ draggable: (props == null ? void 0 : props.isLocked) ? false : draggableEvent,
1319
+ onDragStart: handleOnDragStart,
1320
+ onDragEnd: handleOnDragEnd,
1321
+ onMouseDown: (event) => event.stopPropagation(),
1322
+ onMouseMove: handleOnMouseMove,
1323
+ onDrop: (event) => event.stopPropagation(),
1324
+ style: {
1325
+ left: resizeDirectionRef.current === "left" ? startPosition - resizeOffset : startPosition,
1326
+ width: width + resizeOffset,
1327
+ top,
1328
+ cursor: (props == null ? void 0 : props.isLocked) ? "not-allowed" : "pointer"
1329
+ }
1330
+ },
1331
+ /* @__PURE__ */ React9.createElement("div", { className: "event-content" }, !(props == null ? void 0 : props.isLocked) && (eventsResize || (props == null ? void 0 : props.isResizable)) && /* @__PURE__ */ React9.createElement(
1332
+ "img",
1333
+ {
1334
+ className: "event-resize",
1335
+ style: resizeStarted ? { opacity: "100%" } : void 0,
1336
+ src: grip_lines_vertical_solid_default,
1337
+ alt: "resize-icon",
1338
+ draggable: false,
1339
+ onMouseEnter: () => setDraggableEvent(false),
1340
+ onMouseLeave: () => setDraggableEvent(true),
1341
+ onMouseDown: (event) => handleOnMouseDownEventResizer(event, "left")
1342
+ }
1343
+ ), (props == null ? void 0 : props.content) ? props.content : null, !(props == null ? void 0 : props.isLocked) && (eventsResize || (props == null ? void 0 : props.isResizable)) && /* @__PURE__ */ React9.createElement(
1344
+ "img",
1345
+ {
1346
+ className: "event-resize",
1347
+ style: resizeStarted ? { opacity: "100%" } : void 0,
1348
+ src: grip_lines_vertical_solid_default,
1349
+ alt: "resize-icon",
1350
+ draggable: false,
1351
+ onMouseEnter: () => setDraggableEvent(false),
1352
+ onMouseLeave: () => setDraggableEvent(true),
1353
+ onMouseDown: (event) => handleOnMouseDownEventResizer(event, "right")
1354
+ }
1355
+ ))
1356
+ );
1357
+ };
1358
+ var event_default = Event;
1359
+
1360
+ // src/hooks/use-intersection-observer.ts
1361
+ import { useCallback as useCallback4, useEffect } from "react";
1362
+ var useIntersectionObserver = ({
1363
+ bodyRef,
1364
+ rowsContentRef
1365
+ }) => {
1366
+ const callback = useCallback4((entries) => {
1367
+ entries.forEach((entry) => {
1368
+ if (entry.isIntersecting) {
1369
+ entry.target.classList.remove("row-hidden");
1370
+ } else {
1371
+ entry.target.classList.add("row-hidden");
1372
+ }
1373
+ });
1374
+ }, []);
1375
+ const observer = new IntersectionObserver(callback, {
1376
+ root: bodyRef.current
1377
+ });
1378
+ useEffect(() => {
1379
+ if (rowsContentRef.current) {
1380
+ rowsContentRef.current.forEach((row) => {
1381
+ observer.observe(row);
1382
+ });
1383
+ }
1384
+ return () => observer.disconnect();
1385
+ }, [observer]);
1386
+ };
1387
+ var use_intersection_observer_default = useIntersectionObserver;
1388
+
1389
+ // src/hooks/use-produce-content.tsx
1390
+ var useProduceContent = ({
1391
+ rows,
1392
+ windowTime,
1393
+ tick,
1394
+ events,
1395
+ staticEvents,
1396
+ cellWidth,
1397
+ setEvents,
1398
+ bodyRef
1399
+ }) => {
1400
+ const rowsHeightContext = useContext5(RowsHeightContext);
1401
+ const tempRowsHeightRef = useRef4(null);
1402
+ const rowsContentRef = useRef4([]);
1403
+ const [content, internalAllRowsHeight] = useMemo5(() => {
1404
+ let internalAllRowsHeight2 = 0;
1405
+ return [
1406
+ rows.map((row, i) => {
1407
+ let eventOrder = 0;
1408
+ let prevEvent = [];
1409
+ let highestEventOrder = 0;
1410
+ const rowEvents = tick ? events.filter((event) => event.rowId === row.id).map((event) => {
1411
+ if (event.endTime >= windowTime[0] && event.startTime <= windowTime[1]) {
1412
+ let tempEventOrder = 0;
1413
+ let assignEventOrder = true;
1414
+ for (let i2 = 0; i2 <= eventOrder; i2++) {
1415
+ if (prevEvent && prevEvent[i2] && prevEvent[i2].endTime > event.startTime) {
1416
+ tempEventOrder += 1;
1417
+ } else {
1418
+ if (eventOrder > highestEventOrder) {
1419
+ highestEventOrder = eventOrder;
1420
+ }
1421
+ eventOrder = 0;
1422
+ assignEventOrder = false;
1423
+ break;
1424
+ }
1425
+ }
1426
+ if (assignEventOrder) {
1427
+ eventOrder = tempEventOrder;
1428
+ }
1429
+ prevEvent[tempEventOrder] = event;
1430
+ return /* @__PURE__ */ React10.createElement(
1431
+ event_default,
1432
+ {
1433
+ key: `event_${event.id}`,
1434
+ id: event.id,
1435
+ startPosition: (event.startTime - windowTime[0]) / tick,
1436
+ width: (event.endTime - event.startTime) / tick,
1437
+ top: 10 + 22 * tempEventOrder,
1438
+ props: event.props,
1439
+ setEvents,
1440
+ tick
1441
+ }
1442
+ );
1443
+ }
1444
+ }) : null;
1445
+ if (eventOrder > highestEventOrder) {
1446
+ highestEventOrder = eventOrder;
1447
+ }
1448
+ if (tempRowsHeightRef.current === null) {
1449
+ tempRowsHeightRef.current = {
1450
+ [row.id]: { minHeight: 40 + highestEventOrder * 22 }
1451
+ };
1452
+ } else {
1453
+ tempRowsHeightRef.current[row.id] = {
1454
+ minHeight: 40 + highestEventOrder * 22
1455
+ };
1456
+ }
1457
+ internalAllRowsHeight2 += 40 + highestEventOrder * 22;
1458
+ const rowStaticEvents = tick && staticEvents ? staticEvents.filter((event) => event.rowId === row.id).map((event) => {
1459
+ if (event.endTime >= windowTime[0] && event.startTime <= windowTime[1]) {
1460
+ return /* @__PURE__ */ React10.createElement(
1461
+ static_event_default,
1462
+ {
1463
+ key: `static_event_${event.id}`,
1464
+ id: event.id,
1465
+ startPosition: (event.startTime - windowTime[0]) / tick,
1466
+ width: (event.endTime - event.startTime) / tick,
1467
+ top: 10,
1468
+ height: 20 + highestEventOrder * 22
1469
+ }
1470
+ );
1471
+ }
1472
+ }) : null;
1473
+ return /* @__PURE__ */ React10.createElement(React10.Fragment, { key: `row_content_${row.id}` }, /* @__PURE__ */ React10.createElement(
1474
+ row_content_default,
1475
+ {
1476
+ id: row.id,
1477
+ ref: (el) => {
1478
+ if (rowsContentRef.current && rowsContentRef.current[i] && el) {
1479
+ rowsContentRef.current[i] = el;
1480
+ } else if (rowsContentRef.current && el) {
1481
+ rowsContentRef.current.push(el);
1482
+ }
1483
+ },
1484
+ setEvents,
1485
+ tick,
1486
+ windowTime,
1487
+ cellWidth
1488
+ },
1489
+ rowEvents,
1490
+ rowStaticEvents
1491
+ ));
1492
+ }),
1493
+ internalAllRowsHeight2
1494
+ ];
1495
+ }, [rows, events, tick, windowTime, cellWidth]);
1496
+ use_intersection_observer_default({
1497
+ rowsContentRef,
1498
+ bodyRef
1499
+ });
1500
+ useEffect2(() => {
1501
+ if (rowsHeightContext) {
1502
+ rowsHeightContext.setRowsHeight(tempRowsHeightRef.current);
1503
+ rowsHeightContext.setAllRowsHeight(internalAllRowsHeight);
1504
+ }
1505
+ }, [content, internalAllRowsHeight]);
1506
+ return content;
1507
+ };
1508
+ var use_produce_content_default = useProduceContent;
1509
+
1510
+ // src/components/content.tsx
1511
+ var Content = forwardRef2(
1512
+ ({
1513
+ rows,
1514
+ events,
1515
+ staticEvents,
1516
+ setEvents,
1517
+ tick,
1518
+ windowTime,
1519
+ cellWidth,
1520
+ setWindowTime,
1521
+ contentWidth,
1522
+ setCellWidth,
1523
+ bodyRef,
1524
+ lineClassName
1525
+ }, ref) => {
1526
+ const [mouseDown, setMouseDown] = useState3(false);
1527
+ const startMovePosition = useRef5(null);
1528
+ const [changeGrid, setChangeGrid] = useState3(false);
1529
+ const { blockWidth } = use_get_block_properties_default({ windowTime, contentWidth });
1530
+ const rowsHeightContext = useContext6(RowsHeightContext);
1531
+ const handleOnMouseMove = useCallback5(
1532
+ (event) => {
1533
+ event.preventDefault();
1534
+ if (!mouseDown) {
1535
+ return;
1536
+ }
1537
+ const element = event.target;
1538
+ const { left } = element.getBoundingClientRect();
1539
+ const movePosition = event.clientX - left;
1540
+ const moveTimestamp = tick ? Math.floor(tick * blockWidth) : 0;
1541
+ if (startMovePosition.current && startMovePosition.current - movePosition >= blockWidth) {
1542
+ startMovePosition.current = movePosition;
1543
+ setWindowTime((prev) => [
1544
+ prev[0] + moveTimestamp,
1545
+ prev[1] + moveTimestamp
1546
+ ]);
1547
+ } else if (startMovePosition.current && movePosition - startMovePosition.current >= blockWidth) {
1548
+ startMovePosition.current = movePosition;
1549
+ setWindowTime((prev) => [
1550
+ prev[0] - moveTimestamp,
1551
+ prev[1] - moveTimestamp
1552
+ ]);
1553
+ }
1554
+ },
1555
+ [blockWidth, setWindowTime, mouseDown]
1556
+ );
1557
+ const handleOnMouseDown = useCallback5(
1558
+ (event) => {
1559
+ setMouseDown(true);
1560
+ if (event.button === 1) {
1561
+ event.preventDefault();
1562
+ }
1563
+ const element = event.target;
1564
+ const { left } = element.getBoundingClientRect();
1565
+ startMovePosition.current = event.clientX - left;
1566
+ },
1567
+ [setMouseDown]
1568
+ );
1569
+ const handleOnMouseUp = useCallback5(() => {
1570
+ setMouseDown(false);
1571
+ }, [setMouseDown]);
1572
+ const handleOnMouseLeave = useCallback5(
1573
+ () => setMouseDown(false),
1574
+ [setMouseDown]
1575
+ );
1576
+ const content = use_produce_content_default({
1577
+ rows,
1578
+ windowTime,
1579
+ tick,
1580
+ events,
1581
+ staticEvents,
1582
+ cellWidth,
1583
+ setEvents,
1584
+ bodyRef
1585
+ });
1586
+ const handleAuxClick = useCallback5(
1587
+ (event) => {
1588
+ event.preventDefault();
1589
+ if (event.button === 1) {
1590
+ setChangeGrid((prev) => !prev);
1591
+ }
1592
+ },
1593
+ []
1594
+ );
1595
+ const handleOnWheel = useCallback5(
1596
+ (event) => {
1597
+ const pixelsToCalculate = tick ? 900 / tick : 0;
1598
+ if (changeGrid) {
1599
+ setCellWidth((cellWidth2) => {
1600
+ const newCellWidth = event.deltaY > 0 ? cellWidth2 + pixelsToCalculate : cellWidth2 - pixelsToCalculate;
1601
+ if (newCellWidth < pixelsToCalculate || newCellWidth > pixelsToCalculate * 12) {
1602
+ return cellWidth2;
1603
+ }
1604
+ return newCellWidth;
1605
+ });
1606
+ }
1607
+ },
1608
+ [changeGrid, cellWidth, tick]
1609
+ );
1610
+ useEffect3(() => {
1611
+ if (bodyRef.current) {
1612
+ bodyRef.current.style.overflow = changeGrid ? "hidden" : "auto";
1613
+ }
1614
+ }, [changeGrid]);
1615
+ return /* @__PURE__ */ React11.createElement(
1616
+ "div",
1617
+ {
1618
+ key: "content",
1619
+ ref,
1620
+ className: "content-wrapper",
1621
+ onMouseDown: handleOnMouseDown,
1622
+ onMouseUp: handleOnMouseUp,
1623
+ onMouseMove: handleOnMouseMove,
1624
+ onMouseLeave: handleOnMouseLeave,
1625
+ onAuxClick: handleAuxClick,
1626
+ onWheel: handleOnWheel,
1627
+ style: {
1628
+ cursor: mouseDown ? "grabbing" : "grab",
1629
+ height: rowsHeightContext == null ? void 0 : rowsHeightContext.allRowsHeight
1630
+ }
1631
+ },
1632
+ /* @__PURE__ */ React11.createElement(
1633
+ lines_canvas_default,
1634
+ {
1635
+ contentWidth,
1636
+ cellWidth,
1637
+ lineClassName
1638
+ }
1639
+ ),
1640
+ content
1641
+ );
1642
+ }
1643
+ );
1644
+ var content_default = Content;
1645
+
1646
+ // src/hooks/use-resize-observer.ts
1647
+ import { useEffect as useEffect4, useMemo as useMemo6, useRef as useRef6 } from "react";
1648
+ var useResizeObserver = ({
1649
+ windowTime,
1650
+ setTick,
1651
+ setCellWidth,
1652
+ contentRef
1653
+ }) => {
1654
+ const prevWidthRef = useRef6(0);
1655
+ const resizeObserver = useMemo6(() => {
1656
+ return new ResizeObserver((entries) => {
1657
+ var _a;
1658
+ for (const entry of entries) {
1659
+ const width = (_a = entry.borderBoxSize) == null ? void 0 : _a[0].inlineSize;
1660
+ if (typeof width === "number" && width !== prevWidthRef.current) {
1661
+ prevWidthRef.current = width;
1662
+ const windowDuration = windowTime[1] - windowTime[0];
1663
+ const numberOfHourBlocks = windowDuration / 3600;
1664
+ setTick(windowDuration / entry.contentRect.width);
1665
+ setCellWidth(entry.contentRect.width / numberOfHourBlocks);
1666
+ }
1667
+ }
1668
+ });
1669
+ }, [windowTime]);
1670
+ useEffect4(() => {
1671
+ if (contentRef.current) {
1672
+ resizeObserver.observe(contentRef.current, { box: "border-box" });
1673
+ }
1674
+ return () => resizeObserver.disconnect();
1675
+ }, [resizeObserver]);
1676
+ };
1677
+ var use_resize_observer_default = useResizeObserver;
1678
+
1679
+ // src/components/rt-indicator.tsx
1680
+ import React12, { useEffect as useEffect5, useRef as useRef7, useState as useState4 } from "react";
1681
+ var RTIndicator = ({
1682
+ tick,
1683
+ windowTime
1684
+ }) => {
1685
+ const [currentTime, setCurrentTime] = useState4((/* @__PURE__ */ new Date()).getTime() / 1e3);
1686
+ const [leftOffset, setLeftOffset] = useState4(0);
1687
+ const intervalIdRef = useRef7(null);
1688
+ useEffect5(() => {
1689
+ if (tick) {
1690
+ const leftOffsetTime = currentTime - windowTime[0];
1691
+ setLeftOffset(Math.round(leftOffsetTime / tick));
1692
+ if (intervalIdRef.current !== null) {
1693
+ clearInterval(intervalIdRef.current);
1694
+ }
1695
+ const intervalId = setInterval(() => {
1696
+ setCurrentTime((/* @__PURE__ */ new Date()).getTime() / 1e3);
1697
+ }, tick * 1e3);
1698
+ intervalIdRef.current = intervalId;
1699
+ }
1700
+ }, [tick, windowTime, currentTime]);
1701
+ return /* @__PURE__ */ React12.createElement(React12.Fragment, null, windowTime[0] <= currentTime && currentTime <= windowTime[1] && /* @__PURE__ */ React12.createElement(React12.Fragment, null, /* @__PURE__ */ React12.createElement("div", { className: "rt-arrow", style: { left: 86 + leftOffset } }), /* @__PURE__ */ React12.createElement("div", { className: "rt-line", style: { left: 100 + leftOffset } })));
1702
+ };
1703
+ var rt_indicator_default = RTIndicator;
1704
+
1705
+ // src/timeline.tsx
1706
+ var Timeline = ({
1707
+ rows,
1708
+ events,
1709
+ staticEvents,
1710
+ onDrop,
1711
+ onResize,
1712
+ startDate,
1713
+ endDate,
1714
+ additionalClassNames,
1715
+ showRTIndicator = true,
1716
+ eventsResize = true
1717
+ }) => {
1718
+ const [windowTime, setWindowTime] = useState5([
1719
+ new Date(
1720
+ startDate.getFullYear(),
1721
+ startDate.getMonth(),
1722
+ startDate.getDate(),
1723
+ startDate.getHours(),
1724
+ 0,
1725
+ 0
1726
+ ).getTime() / 1e3,
1727
+ new Date(
1728
+ endDate.getFullYear(),
1729
+ endDate.getMonth(),
1730
+ endDate.getDate(),
1731
+ endDate.getHours(),
1732
+ 0,
1733
+ 0
1734
+ ).getTime() / 1e3
1735
+ ]);
1736
+ const [cellWidth, setCellWidth] = useState5(0);
1737
+ const [internalEvents, setInternalEvents] = useState5([]);
1738
+ const contentRef = useRef8(null);
1739
+ const mainRef = useRef8(null);
1740
+ const bodyRef = useRef8(null);
1741
+ const [tick, setTick] = useState5(null);
1742
+ const [scrollWidth, setScrollWidth] = useState5(0);
1743
+ const [rowsHeight, setRowsHeight] = useState5(null);
1744
+ const [allRowsHeight, setAllRowsHeight] = useState5(0);
1745
+ useEffect6(() => {
1746
+ if (contentRef.current) {
1747
+ const windowDuration = windowTime[1] - windowTime[0];
1748
+ const numberOfHourBlocks = windowDuration / 3600;
1749
+ setTick(
1750
+ windowDuration / contentRef.current.getBoundingClientRect().width
1751
+ );
1752
+ setCellWidth(
1753
+ contentRef.current.getBoundingClientRect().width / numberOfHourBlocks
1754
+ );
1755
+ }
1756
+ }, []);
1757
+ useEffect6(() => {
1758
+ if (bodyRef.current) {
1759
+ setScrollWidth(
1760
+ bodyRef.current.getBoundingClientRect().width - bodyRef.current.scrollWidth
1761
+ );
1762
+ }
1763
+ }, []);
1764
+ useEffect6(() => {
1765
+ setInternalEvents(events.sort(sort_events_default));
1766
+ }, [events]);
1767
+ const [dragStarted, setDragStarted] = useState5(false);
1768
+ useEffect6(() => {
1769
+ let tempRowsHeight = null;
1770
+ rows.forEach((row) => {
1771
+ if (tempRowsHeight === null) {
1772
+ tempRowsHeight = { [row.id]: { minHeight: 40 } };
1773
+ } else {
1774
+ tempRowsHeight[row.id] = { minHeight: 40 };
1775
+ }
1776
+ });
1777
+ setRowsHeight(tempRowsHeight);
1778
+ }, [rows]);
1779
+ use_resize_observer_default({ contentRef, setCellWidth, setTick, windowTime });
1780
+ return /* @__PURE__ */ React13.createElement("div", { className: "main-wrapper", ref: mainRef }, showRTIndicator && /* @__PURE__ */ React13.createElement(rt_indicator_default, { tick, windowTime }), /* @__PURE__ */ React13.createElement(
1781
+ time_bar_default,
1782
+ {
1783
+ windowTime,
1784
+ tick,
1785
+ contentWidth: contentRef.current ? contentRef.current.getBoundingClientRect().width : null,
1786
+ scrollWidth
1787
+ }
1788
+ ), /* @__PURE__ */ React13.createElement("div", { className: "body-wrapper", ref: bodyRef }, /* @__PURE__ */ React13.createElement(
1789
+ RowsHeightContext.Provider,
1790
+ {
1791
+ value: { rowsHeight, setRowsHeight, allRowsHeight, setAllRowsHeight }
1792
+ },
1793
+ /* @__PURE__ */ React13.createElement(
1794
+ rows_header_default,
1795
+ {
1796
+ rows,
1797
+ className: additionalClassNames == null ? void 0 : additionalClassNames.rowsHeader
1798
+ }
1799
+ ),
1800
+ /* @__PURE__ */ React13.createElement(DragStartedContext.Provider, { value: { dragStarted, setDragStarted } }, /* @__PURE__ */ React13.createElement(
1801
+ ExternalPropertiesContext.Provider,
1802
+ {
1803
+ value: { onDrop, onResize, eventsResize }
1804
+ },
1805
+ /* @__PURE__ */ React13.createElement(
1806
+ content_default,
1807
+ {
1808
+ events: internalEvents,
1809
+ staticEvents,
1810
+ rows,
1811
+ setEvents: setInternalEvents,
1812
+ tick,
1813
+ windowTime,
1814
+ cellWidth,
1815
+ setWindowTime,
1816
+ ref: contentRef,
1817
+ setCellWidth,
1818
+ contentWidth: contentRef.current ? contentRef.current.getBoundingClientRect().width : null,
1819
+ bodyRef,
1820
+ lineClassName: additionalClassNames == null ? void 0 : additionalClassNames.gridLine
1821
+ }
1822
+ )
1823
+ ))
1824
+ )));
1825
+ };
1826
+ export {
1827
+ Timeline
1828
+ };
1829
+ //# sourceMappingURL=index.mjs.map