-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustomTimeGrid.js
More file actions
1577 lines (1479 loc) · 81.3 KB
/
customTimeGrid.js
File metadata and controls
1577 lines (1479 loc) · 81.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*!
FullCalendar Time Grid Plugin v6.1.17
Docs & License: https://fullcalendar.io/docs/timegrid-view
(c) 2024 Adam Shaw
*/
FullCalendar.MultiRowTimeGrid = (function (exports, core, internal$1, preact, internal$2) {
'use strict';
//unused classes and funcions for normal work:
// I do not think i use this
class TimeColMoreLink extends internal$1.BaseComponent {
render() {
print("Calling timecolmorelink")
let { props } = this;
return (preact.createElement(internal$1.MoreLinkContainer, { elClasses: ['fc-timegrid-more-link'], elStyle: {
top: props.top,
bottom: props.bottom,
}, allDayDate: null, moreCnt: props.hiddenSegs.length, allSegs: props.hiddenSegs, hiddenSegs: props.hiddenSegs, extraDateSpan: props.extraDateSpan, dateProfile: props.dateProfile, todayRange: props.todayRange, popoverContent: () => renderPlainFgSegs(props.hiddenSegs, props), defaultGenerator: renderMoreLinkInner, forceTimed: true }, (InnerContent) => (preact.createElement(InnerContent, { elTag: "div", elClasses: ['fc-timegrid-more-link-inner', 'fc-sticky'] }))));
}
}
//unused
class TimeBodyAxis extends internal$1.BaseComponent {
render() {
//doesnt seem to be called for now
//console.log("calling Timebodyaaaaaaaaaaaaaaaaaaaaaaaaaaa")
return this.props.slatMetas.map((slatMeta) => (preact.createElement("tr", { key: slatMeta.key },
preact.createElement(TimeColsAxisCell, Object.assign({}, slatMeta)))));
}
}
// this seems to split events that are all day focusing mostly on events?
class AllDaySplitter extends internal$1.Splitter {
// this gets called on every reload or week change
getKeyInfo() {
//console.log("calling getKeyInfo, it ruetruns allDay, and time")
// this seems to just build the arrays to be done
return {
allDay: {},
timed: {},
};
}
getKeysForDateSpan(dateSpan) {
// not called within this
//console.log("calling getKey for datespan allDay", dateSpan.allDay)
if (dateSpan.allDay) {
return ['allDay'];
}
return ['timed'];
}
getKeysForEventDef(eventDef) {
// called within this, gets the number of events stored in the DB
//console.log("calling getKey for eventdef", eventDef)
if (!eventDef.allDay) {
return ['timed'];
}
if (internal$1.hasBgRendering(eventDef)) {
return ['timed', 'allDay'];
}
return ['allDay'];
}
}
function TimeColsAxisCell(props) {
// called 48 times, in a row not dependant on the number of weeks or dates
// this is dependant on the minute interval between times
//console.log("Cakkubg the timeColSaxis")
let classNames = [
'fc-timegrid-slot',
'fc-timegrid-slot-label',
props.isLabeled ? 'fc-scrollgrid-shrink' : 'fc-timegrid-slot-minor',
];
return (preact.createElement(internal$1.ViewContextType.Consumer, null, (context) => {
if (!props.isLabeled) {
return (preact.createElement("td", { className: classNames.join(' '), "data-time": props.isoTimeStr }));
}
let { dateEnv, options, viewApi } = context;
let labelFormat = // TODO: fully pre-parse
options.slotLabelFormat == null ? DEFAULT_SLAT_LABEL_FORMAT :
Array.isArray(options.slotLabelFormat) ? internal$1.createFormatter(options.slotLabelFormat[0]) :
internal$1.createFormatter(options.slotLabelFormat);
let renderProps = {
level: 0,
time: props.time,
date: dateEnv.toDate(props.date),
view: viewApi,
text: dateEnv.format(props.date, labelFormat),
};
return (preact.createElement(internal$1.ContentContainer, { elTag: "td", elClasses: classNames, elAttrs: {
'data-time': props.isoTimeStr,
}, renderProps: renderProps, generatorName: "slotLabelContent", customGenerator: options.slotLabelContent, defaultGenerator: renderInnerContent, classNameGenerator: options.slotLabelClassNames, didMount: options.slotLabelDidMount, willUnmount: options.slotLabelWillUnmount }, (InnerContent) => (preact.createElement("div", { className: "fc-timegrid-slot-label-frame fc-scrollgrid-shrink-frame" },
preact.createElement(InnerContent, { elTag: "div", elClasses: [
'fc-timegrid-slot-label-cushion',
'fc-scrollgrid-shrink-cushion',
] })))));
}));
}
function renderInnerContent(props) {
// this gets the time slots for the 12am to 11pm
//console.log(props.text)
return props.text;
}
function renderAllDayInner(renderProps) {
// Called once
//console.log("calling render with data:",renderProps.text)
return renderProps.text;
}
class TimeColsView extends internal$1.DateComponent {
constructor() {
super(...arguments);
this.allDaySplitter = new AllDaySplitter(); // for use by subclasses
this.headerElRef = preact.createRef();
this.rootElRef = preact.createRef();
this.scrollerElRef = preact.createRef();
this.state = {
slatCoords: null,
};
this.handleScrollTopRequest = (scrollTop) => {
let scrollerEl = this.scrollerElRef.current;
if (scrollerEl) { // TODO: not sure how this could ever be null. weirdness with the reducer
scrollerEl.scrollTop = scrollTop;
}
};
/* Header Render Methods
------------------------------------------------------------------------------------------------------------------*/
this.renderHeadAxis = (rowKey, frameHeight = '') => {
let { options } = this.context;
let { dateProfile } = this.props;
let range = dateProfile.renderRange;
let dayCnt = internal$1.diffDays(range.start, range.end);
// only do in day views (to avoid doing in week views that dont need it)
let navLinkAttrs = (dayCnt === 1)
? internal$1.buildNavLinkAttrs(this.context, range.start, 'week')
: {};
if (options.weekNumbers && rowKey === 'day') {
return (preact.createElement(internal$1.WeekNumberContainer, { elTag: "th", elClasses: [
'fc-timegrid-axis',
'fc-scrollgrid-shrink',
], elAttrs: {
'aria-hidden': true,
}, date: range.start, defaultFormat: DEFAULT_WEEK_NUM_FORMAT }, (InnerContent) => (preact.createElement("div", { className: [
'fc-timegrid-axis-frame',
'fc-scrollgrid-shrink-frame',
'fc-timegrid-axis-frame-liquid',
].join(' '), style: { height: frameHeight } },
preact.createElement(InnerContent, { elTag: "a", elClasses: [
'fc-timegrid-axis-cushion',
'fc-scrollgrid-shrink-cushion',
'fc-scrollgrid-sync-inner',
], elAttrs: navLinkAttrs })))));
}
return (preact.createElement("th", { "aria-hidden": true, className: "fc-timegrid-axis" },
preact.createElement("div", { className: "fc-timegrid-axis-frame", style: { height: frameHeight } })));
};
/* Table Component Render Methods
------------------------------------------------------------------------------------------------------------------*/
// only a one-way height sync. we don't send the axis inner-content height to the DayGrid,
// but DayGrid still needs to have classNames on inner elements in order to measure.
this.renderTableRowAxis = (rowHeight) => {
let { options, viewApi } = this.context;
let renderProps = {
text: options.allDayText,
view: viewApi,
};
return (
// TODO: make reusable hook. used in list view too
preact.createElement(internal$1.ContentContainer, { elTag: "td", elClasses: [
'fc-timegrid-axis',
'fc-scrollgrid-shrink',
], elAttrs: {
'aria-hidden': true,
}, renderProps: renderProps, generatorName: "allDayContent", customGenerator: options.allDayContent, defaultGenerator: renderAllDayInner, classNameGenerator: options.allDayClassNames, didMount: options.allDayDidMount, willUnmount: options.allDayWillUnmount }, (InnerContent) => (preact.createElement("div", { className: [
'fc-timegrid-axis-frame',
'fc-scrollgrid-shrink-frame',
rowHeight == null ? ' fc-timegrid-axis-frame-liquid' : '',
].join(' '), style: { height: rowHeight } },
preact.createElement(InnerContent, { elTag: "span", elClasses: [
'fc-timegrid-axis-cushion',
'fc-scrollgrid-shrink-cushion',
'fc-scrollgrid-sync-inner',
] })))));
};
this.handleSlatCoords = (slatCoords) => {
this.setState({ slatCoords });
};
}
// rendering
// ----------------------------------------------------------------------------------------------------
renderSimpleLayout(headerRowContent, allDayContent, timeContent) {
// this is what I believe builds the skeleton for the table
let { context, props } = this;
//console.log("calling renderSImplelayout")
// console.log("header row content is",headerRowContent)
// console.log("allday content is ",allDayContent)
// console.log("timeContent is ",timeContent)
let sections = [];
let stickyHeaderDates = internal$1.getStickyHeaderDates(context.options);
if (headerRowContent) {
sections.push({
type: 'header',
key: 'header',
isSticky: stickyHeaderDates,
chunk: {
elRef: this.headerElRef,
tableClassName: 'fc-col-header',
rowContent: headerRowContent,
},
});
}
if (allDayContent) {
sections.push({
type: 'body',
key: 'all-day',
chunk: { content: allDayContent },
});
console.log("here")
//this is the sidebar thing
sections.push({
type: 'body',
key: 'all-day-divider',
outerContent: ( // TODO: rename to cellContent so don't need to define <tr>?
preact.createElement("tr", { role: "presentation", className: "fc-scrollgrid-section", id: 'all-day-divider' },
preact.createElement("td", { className: 'fc-timegrid-divider ' + context.theme.getClass('tableCellShaded') }))),
});
}
sections.push({
type: 'body',
key: 'body',
liquid: true,
expandRows: Boolean(context.options.expandRows),
chunk: {
scrollerElRef: this.scrollerElRef,
content: timeContent,
},
}
);
//console.log("SEctoins are now:", sections)
//console.log("returning this:", preact.createElement(internal$1.ViewContainer, { elRef: this.rootElRef, elClasses: ['fc-timegrid'], viewSpec: context.viewSpec },
// preact.createElement(internal$1.SimpleScrollGrid, { liquid: !props.isHeightAuto && !props.forPrint, collapsibleWidth: props.forPrint, cols: [{ width: 'shrink' }], sections: sections })))
return (preact.createElement(internal$1.ViewContainer, { elRef: this.rootElRef, elClasses: ['fc-timegrid'], viewSpec: context.viewSpec },
preact.createElement(internal$1.SimpleScrollGrid, { liquid: !props.isHeightAuto && !props.forPrint, collapsibleWidth: props.forPrint, cols: [{ width: 'shrink' }], sections: sections })));
}
//this is the sidewise one I believe
renderHScrollLayout(headerRowContent, allDayContent, timeContent, colCnt, dayMinWidth, slatMetas, slatCoords) {
let ScrollGrid = this.context.pluginHooks.scrollGridImpl;
if (!ScrollGrid) {
throw new Error('No ScrollGrid implementation');
}
let { context, props } = this;
let stickyHeaderDates = !props.forPrint && internal$1.getStickyHeaderDates(context.options);
let stickyFooterScrollbar = !props.forPrint && internal$1.getStickyFooterScrollbar(context.options);
let sections = [];
if (headerRowContent) {
sections.push({
type: 'header',
key: 'header',
isSticky: stickyHeaderDates,
syncRowHeights: true,
chunks: [
{
key: 'axis',
rowContent: (arg) => (preact.createElement("tr", { role: "presentation" }, this.renderHeadAxis('day', arg.rowSyncHeights[0]))),
},
{
key: 'cols',
elRef: this.headerElRef,
tableClassName: 'fc-col-header',
rowContent: headerRowContent,
},
],
});
}
if (allDayContent) {
sections.push({
type: 'body',
key: 'all-day',
syncRowHeights: true,
chunks: [
{
key: 'axis',
rowContent: (contentArg) => (preact.createElement("tr", { role: "presentation" }, this.renderTableRowAxis(contentArg.rowSyncHeights[0]))),
},
{
key: 'cols',
content: allDayContent,
},
],
});
sections.push({
key: 'all-day-divider',
type: 'body',
outerContent: ( // TODO: rename to cellContent so don't need to define <tr>?
preact.createElement("tr", { role: "presentation", className: "fc-scrollgrid-section" },
preact.createElement("td", { colSpan: 2, className: 'fc-timegrid-divider ' + context.theme.getClass('tableCellShaded') }))),
});
}
let isNowIndicator = context.options.nowIndicator;
sections.push({
type: 'body',
key: 'body',
liquid: true,
expandRows: Boolean(context.options.expandRows),
chunks: [
{
key: 'axis',
content: (arg) => (
// TODO: make this now-indicator arrow more DRY with TimeColsContent
preact.createElement("div", { className: "fc-timegrid-axis-chunk" },
preact.createElement("table", { "aria-hidden": true, style: { height: arg.expandRows ? arg.clientHeight : '' } },
arg.tableColGroupNode,
preact.createElement("tbody", null,
preact.createElement(TimeBodyAxis, { slatMetas: slatMetas }))),
preact.createElement("div", { className: "fc-timegrid-now-indicator-container" },
preact.createElement(internal$1.NowTimer, { unit: isNowIndicator ? 'minute' : 'day' /* hacky */ }, (nowDate) => {
let nowIndicatorTop = isNowIndicator &&
slatCoords &&
slatCoords.safeComputeTop(nowDate); // might return void
if (typeof nowIndicatorTop === 'number') {
return (preact.createElement(internal$1.NowIndicatorContainer, { elClasses: ['fc-timegrid-now-indicator-arrow'], elStyle: { top: nowIndicatorTop }, isAxis: true, date: nowDate }));
}
return null;
})))),
},
{
key: 'cols',
scrollerElRef: this.scrollerElRef,
content: timeContent,
},
],
});
if (stickyFooterScrollbar) {
sections.push({
key: 'footer',
type: 'footer',
isSticky: true,
chunks: [
{
key: 'axis',
content: internal$1.renderScrollShim,
},
{
key: 'cols',
content: internal$1.renderScrollShim,
},
],
});
}
return (preact.createElement(internal$1.ViewContainer, { elRef: this.rootElRef, elClasses: ['fc-timegrid'], viewSpec: context.viewSpec },
preact.createElement(ScrollGrid, { liquid: !props.isHeightAuto && !props.forPrint, forPrint: props.forPrint, collapsibleWidth: false, colGroups: [
{ width: 'shrink', cols: [{ width: 'shrink' }] },
{ cols: [{ span: colCnt, minWidth: dayMinWidth }] },
], sections: sections })));
}
/* Dimensions
------------------------------------------------------------------------------------------------------------------*/
getAllDayMaxEventProps() {
let { dayMaxEvents, dayMaxEventRows } = this.context.options;
if (dayMaxEvents === true || dayMaxEventRows === true) { // is auto?
dayMaxEvents = undefined;
dayMaxEventRows = AUTO_ALL_DAY_MAX_EVENT_ROWS; // make sure "auto" goes to a real number
}
return { dayMaxEvents, dayMaxEventRows };
}
}
class TimeColsSlatsCoords {
constructor(positions, dateProfile, slotDuration) {
this.positions = positions;
this.dateProfile = dateProfile;
this.slotDuration = slotDuration;
}
safeComputeTop(date) {
//console.log("calling safecompute, twice per")
let { dateProfile } = this;
if (internal$1.rangeContainsMarker(dateProfile.currentRange, date)) {
let startOfDayDate = internal$1.startOfDay(date);
let timeMs = date.valueOf() - startOfDayDate.valueOf();
if (timeMs >= internal$1.asRoughMs(dateProfile.slotMinTime) &&
timeMs < internal$1.asRoughMs(dateProfile.slotMaxTime)) {
return this.computeTimeTop(internal$1.createDuration(timeMs));
}
}
return null;
}
// Computes the top coordinate, relative to the bounds of the grid, of the given date.
// A `startOfDayDate` must be given for avoiding ambiguity over how to treat midnight.
computeDateTop(when, startOfDayDate) {
// called once only on page load, is based on number of events:
//console.log("calling datetop, called 16 times")
if (!startOfDayDate) {
startOfDayDate = internal$1.startOfDay(when);
}
return this.computeTimeTop(internal$1.createDuration(when.valueOf() - startOfDayDate.valueOf()));
}
// Computes the top coordinate, relative to the bounds of the grid, of the given time (a Duration).
// This is a makeshify way to compute the time-top. Assumes all slatMetas dates are uniform.
// Eventually allow computation with arbirary slat dates.
computeTimeTop(duration) {
let { positions, dateProfile } = this;
let len = positions.els.length;
// floating-point value of # of slots covered
let slatCoverage = (duration.milliseconds - internal$1.asRoughMs(dateProfile.slotMinTime)) / internal$1.asRoughMs(this.slotDuration);
let slatIndex;
let slatRemainder;
// compute a floating-point number for how many slats should be progressed through.
// from 0 to number of slats (inclusive)
// constrained because slotMinTime/slotMaxTime might be customized.
slatCoverage = Math.max(0, slatCoverage);
slatCoverage = Math.min(len, slatCoverage);
// an integer index of the furthest whole slat
// from 0 to number slats (*exclusive*, so len-1)
slatIndex = Math.floor(slatCoverage);
slatIndex = Math.min(slatIndex, len - 1);
// how much further through the slatIndex slat (from 0.0-1.0) must be covered in addition.
// could be 1.0 if slatCoverage is covering *all* the slots
slatRemainder = slatCoverage - slatIndex;
return positions.tops[slatIndex] +
positions.getHeight(slatIndex) * slatRemainder;
}
}
class TimeColsSlatsBody extends internal$1.BaseComponent {
render() {
let { props, context } = this;
let { options } = context;
let { slatElRefs } = props;
return (preact.createElement("tbody", null, props.slatMetas.map((slatMeta, i) => {
let renderProps = {
time: slatMeta.time,
date: context.dateEnv.toDate(slatMeta.date),
view: context.viewApi,
};
return (preact.createElement("tr", { key: slatMeta.key, ref: slatElRefs.createRef(slatMeta.key) },
props.axis && (preact.createElement(TimeColsAxisCell, Object.assign({}, slatMeta))),
preact.createElement(internal$1.ContentContainer, { elTag: "td", elClasses: [
'fc-timegrid-slot',
'fc-timegrid-slot-lane',
!slatMeta.isLabeled && 'fc-timegrid-slot-minor',
], elAttrs: {
'data-time': slatMeta.isoTimeStr,
}, renderProps: renderProps, generatorName: "slotLaneContent", customGenerator: options.slotLaneContent, classNameGenerator: options.slotLaneClassNames, didMount: options.slotLaneDidMount, willUnmount: options.slotLaneWillUnmount })));
})));
}
}
/*
for the horizontal "slats" that run width-wise. Has a time axis on a side. Depends on RTL.
*/
class TimeColsSlats extends internal$1.BaseComponent {
constructor() {
super(...arguments);
this.rootElRef = preact.createRef();
this.slatElRefs = new internal$1.RefMap();
}
render() {
let { props, context } = this;
return (preact.createElement("div", { ref: this.rootElRef, className: "fc-timegrid-slots" },
preact.createElement("table", { "aria-hidden": true, className: context.theme.getClass('table'), style: {
minWidth: props.tableMinWidth,
width: props.clientWidth,
height: props.minHeight,
} },
props.tableColGroupNode /* relies on there only being a single <col> for the axis */,
preact.createElement(TimeColsSlatsBody, { slatElRefs: this.slatElRefs, axis: props.axis, slatMetas: props.slatMetas }))));
}
componentDidMount() {
this.updateSizing();
}
componentDidUpdate() {
this.updateSizing();
}
componentWillUnmount() {
if (this.props.onCoords) {
this.props.onCoords(null);
}
}
updateSizing() {
let { context, props } = this;
if (props.onCoords &&
props.clientWidth !== null // means sizing has stabilized
) {
let rootEl = this.rootElRef.current;
if (rootEl.offsetHeight) { // not hidden by css
props.onCoords(new TimeColsSlatsCoords(new internal$1.PositionCache(this.rootElRef.current, collectSlatEls(this.slatElRefs.currentMap, props.slatMetas), false, true), this.props.dateProfile, context.options.slotDuration));
}
}
}
}
function collectSlatEls(elMap, slatMetas) {
return slatMetas.map((slatMeta) => elMap[slatMeta.key]);
}
function splitSegsByCol(segs, colCnt) {
let segsByCol = [];
let i;
//console.log("calling splitSegsByCol, with colcnt of: ",colCnt)
for (i = 0; i < colCnt; i += 1) {
segsByCol.push([]);
}
if (segs) {
for (i = 0; i < segs.length; i += 1) {
segsByCol[segs[i].col].push(segs[i]);
}
}
return segsByCol;
}
function splitInteractionByCol(ui, colCnt) {
let byRow = [];
if (!ui) {
for (let i = 0; i < colCnt; i += 1) {
byRow[i] = null;
}
}
else {
for (let i = 0; i < colCnt; i += 1) {
byRow[i] = {
affectedInstances: ui.affectedInstances,
isEvent: ui.isEvent,
segs: [],
};
}
for (let seg of ui.segs) {
byRow[seg.col].segs.push(seg);
}
}
return byRow;
}
function renderMoreLinkInner(props) {
return props.shortText;
}
// segInputs assumed sorted
function buildPositioning(segInputs, strictOrder, maxStackCnt) {
let hierarchy = new internal$1.SegHierarchy();
if (strictOrder != null) {
hierarchy.strictOrder = strictOrder;
}
if (maxStackCnt != null) {
hierarchy.maxStackCnt = maxStackCnt;
}
let hiddenEntries = hierarchy.addSegs(segInputs);
let hiddenGroups = internal$1.groupIntersectingEntries(hiddenEntries);
let web = buildWeb(hierarchy);
web = stretchWeb(web, 1); // all levelCoords/thickness will have 0.0-1.0
let segRects = webToRects(web);
return { segRects, hiddenGroups };
}
function buildWeb(hierarchy) {
const { entriesByLevel } = hierarchy;
const buildNode = cacheable((level, lateral) => level + ':' + lateral, (level, lateral) => {
let siblingRange = findNextLevelSegs(hierarchy, level, lateral);
let nextLevelRes = buildNodes(siblingRange, buildNode);
let entry = entriesByLevel[level][lateral];
return [
Object.assign(Object.assign({}, entry), { nextLevelNodes: nextLevelRes[0] }),
entry.thickness + nextLevelRes[1], // the pressure builds
];
});
return buildNodes(entriesByLevel.length
? { level: 0, lateralStart: 0, lateralEnd: entriesByLevel[0].length }
: null, buildNode)[0];
}
function buildNodes(siblingRange, buildNode) {
if (!siblingRange) {
return [[], 0];
}
let { level, lateralStart, lateralEnd } = siblingRange;
let lateral = lateralStart;
let pairs = [];
while (lateral < lateralEnd) {
pairs.push(buildNode(level, lateral));
lateral += 1;
}
pairs.sort(cmpDescPressures);
return [
pairs.map(extractNode),
pairs[0][1], // first item's pressure
];
}
function cmpDescPressures(a, b) {
return b[1] - a[1];
}
function extractNode(a) {
return a[0];
}
function findNextLevelSegs(hierarchy, subjectLevel, subjectLateral) {
let { levelCoords, entriesByLevel } = hierarchy;
let subjectEntry = entriesByLevel[subjectLevel][subjectLateral];
let afterSubject = levelCoords[subjectLevel] + subjectEntry.thickness;
let levelCnt = levelCoords.length;
let level = subjectLevel;
// skip past levels that are too high up
for (; level < levelCnt && levelCoords[level] < afterSubject; level += 1)
; // do nothing
for (; level < levelCnt; level += 1) {
let entries = entriesByLevel[level];
let entry;
let searchIndex = internal$1.binarySearch(entries, subjectEntry.span.start, internal$1.getEntrySpanEnd);
let lateralStart = searchIndex[0] + searchIndex[1]; // if exact match (which doesn't collide), go to next one
let lateralEnd = lateralStart;
while ( // loop through entries that horizontally intersect
(entry = entries[lateralEnd]) && // but not past the whole seg list
entry.span.start < subjectEntry.span.end) {
lateralEnd += 1;
}
if (lateralStart < lateralEnd) {
return { level, lateralStart, lateralEnd };
}
}
return null;
}
function stretchWeb(topLevelNodes, totalThickness) {
const stretchNode = cacheable((node, startCoord, prevThickness) => internal$1.buildEntryKey(node), (node, startCoord, prevThickness) => {
let { nextLevelNodes, thickness } = node;
let allThickness = thickness + prevThickness;
let thicknessFraction = thickness / allThickness;
let endCoord;
let newChildren = [];
if (!nextLevelNodes.length) {
endCoord = totalThickness;
}
else {
for (let childNode of nextLevelNodes) {
if (endCoord === undefined) {
let res = stretchNode(childNode, startCoord, allThickness);
endCoord = res[0];
newChildren.push(res[1]);
}
else {
let res = stretchNode(childNode, endCoord, 0);
newChildren.push(res[1]);
}
}
}
let newThickness = (endCoord - startCoord) * thicknessFraction;
return [endCoord - newThickness, Object.assign(Object.assign({}, node), { thickness: newThickness, nextLevelNodes: newChildren })];
});
return topLevelNodes.map((node) => stretchNode(node, 0, 0)[1]);
}
// not sorted in any particular order
function webToRects(topLevelNodes) {
let rects = [];
const processNode = cacheable((node, levelCoord, stackDepth) => internal$1.buildEntryKey(node), (node, levelCoord, stackDepth) => {
let rect = Object.assign(Object.assign({}, node), { levelCoord,
stackDepth, stackForward: 0 });
rects.push(rect);
return (rect.stackForward = processNodes(node.nextLevelNodes, levelCoord + node.thickness, stackDepth + 1) + 1);
});
function processNodes(nodes, levelCoord, stackDepth) {
let stackForward = 0;
for (let node of nodes) {
stackForward = Math.max(processNode(node, levelCoord, stackDepth), stackForward);
}
return stackForward;
}
processNodes(topLevelNodes, 0, 0);
return rects; // TODO: sort rects by levelCoord to be consistent with toRects?
}
// TODO: move to general util
function cacheable(keyFunc, workFunc) {
const cache = {};
return (...args) => {
let key = keyFunc(...args);
return (key in cache)
? cache[key]
: (cache[key] = workFunc(...args));
};
}
function computeSegVCoords(segs, colDate, slatCoords = null, eventMinHeight = 0) {
let vcoords = [];
if (slatCoords) {
for (let i = 0; i < segs.length; i += 1) {
let seg = segs[i];
let spanStart = slatCoords.computeDateTop(seg.start, colDate);
let spanEnd = Math.max(spanStart + (eventMinHeight || 0), // :(
slatCoords.computeDateTop(seg.end, colDate));
vcoords.push({
start: Math.round(spanStart),
end: Math.round(spanEnd), //
});
}
}
return vcoords;
}
function computeFgSegPlacements(segs, segVCoords, // might not have for every seg
eventOrderStrict, eventMaxStack) {
let segInputs = [];
let dumbSegs = []; // segs without coords
for (let i = 0; i < segs.length; i += 1) {
let vcoords = segVCoords[i];
if (vcoords) {
segInputs.push({
index: i,
thickness: 1,
span: vcoords,
});
}
else {
dumbSegs.push(segs[i]);
}
}
let { segRects, hiddenGroups } = buildPositioning(segInputs, eventOrderStrict, eventMaxStack);
let segPlacements = [];
for (let segRect of segRects) {
segPlacements.push({
seg: segs[segRect.index],
rect: segRect,
});
}
for (let dumbSeg of dumbSegs) {
segPlacements.push({ seg: dumbSeg, rect: null });
}
return { segPlacements, hiddenGroups };
}
const DEFAULT_TIME_FORMAT = internal$1.createFormatter({
hour: 'numeric',
minute: '2-digit',
meridiem: false,
});
class TimeColEvent extends internal$1.BaseComponent {
render() {
return (preact.createElement(internal$1.StandardEvent, Object.assign({}, this.props, { elClasses: [
'fc-timegrid-event',
'fc-v-event',
this.props.isShort && 'fc-timegrid-event-short',
], defaultTimeFormat: DEFAULT_TIME_FORMAT })));
}
}
class TimeCol extends internal$1.BaseComponent {
constructor() {
super(...arguments);
this.sortEventSegs = internal$1.memoize(internal$1.sortEventSegs);
}
// TODO: memoize event-placement?
render() {
let { props, context } = this;
let { options } = context;
let isSelectMirror = options.selectMirror;
let mirrorSegs = // yuck
(props.eventDrag && props.eventDrag.segs) ||
(props.eventResize && props.eventResize.segs) ||
(isSelectMirror && props.dateSelectionSegs) ||
[];
let interactionAffectedInstances = // TODO: messy way to compute this
(props.eventDrag && props.eventDrag.affectedInstances) ||
(props.eventResize && props.eventResize.affectedInstances) ||
{};
let sortedFgSegs = this.sortEventSegs(props.fgEventSegs, options.eventOrder);
return (preact.createElement(internal$1.DayCellContainer, { elTag: "td", elRef: props.elRef, elClasses: [
'fc-timegrid-col',
...(props.extraClassNames || []),
], elAttrs: Object.assign({ role: 'gridcell' }, props.extraDataAttrs), date: props.date, dateProfile: props.dateProfile, todayRange: props.todayRange, extraRenderProps: props.extraRenderProps }, (InnerContent) => (preact.createElement("div", { className: "fc-timegrid-col-frame" },
preact.createElement("div", { className: "fc-timegrid-col-bg" },
this.renderFillSegs(props.businessHourSegs, 'non-business'),
this.renderFillSegs(props.bgEventSegs, 'bg-event'),
this.renderFillSegs(props.dateSelectionSegs, 'highlight')),
preact.createElement("div", { className: "fc-timegrid-col-events" }, this.renderFgSegs(sortedFgSegs, interactionAffectedInstances, false, false, false)),
preact.createElement("div", { className: "fc-timegrid-col-events" }, this.renderFgSegs(mirrorSegs, {}, Boolean(props.eventDrag), Boolean(props.eventResize), Boolean(isSelectMirror), 'mirror')),
preact.createElement("div", { className: "fc-timegrid-now-indicator-container" }, this.renderNowIndicator(props.nowIndicatorSegs)),
internal$1.hasCustomDayCellContent(options) && (preact.createElement(InnerContent, { elTag: "div", elClasses: ['fc-timegrid-col-misc'] }))))));
}
renderFgSegs(sortedFgSegs, segIsInvisible, isDragging, isResizing, isDateSelecting, forcedKey) {
let { props } = this;
if (props.forPrint) {
return renderPlainFgSegs(sortedFgSegs, props);
}
return this.renderPositionedFgSegs(sortedFgSegs, segIsInvisible, isDragging, isResizing, isDateSelecting, forcedKey);
}
renderPositionedFgSegs(segs, // if not mirror, needs to be sorted
segIsInvisible, isDragging, isResizing, isDateSelecting, forcedKey) {
let { eventMaxStack, eventShortHeight, eventOrderStrict, eventMinHeight } = this.context.options;
let { date, slatCoords, eventSelection, todayRange, nowDate } = this.props;
let isMirror = isDragging || isResizing || isDateSelecting;
let segVCoords = computeSegVCoords(segs, date, slatCoords, eventMinHeight);
let { segPlacements, hiddenGroups } = computeFgSegPlacements(segs, segVCoords, eventOrderStrict, eventMaxStack);
return (preact.createElement(preact.Fragment, null,
this.renderHiddenGroups(hiddenGroups, segs),
segPlacements.map((segPlacement) => {
let { seg, rect } = segPlacement;
let instanceId = seg.eventRange.instance.instanceId;
let isVisible = isMirror || Boolean(!segIsInvisible[instanceId] && rect);
let vStyle = computeSegVStyle(rect && rect.span);
let hStyle = (!isMirror && rect) ? this.computeSegHStyle(rect) : { left: 0, right: 0 };
let isInset = Boolean(rect) && rect.stackForward > 0;
let isShort = Boolean(rect) && (rect.span.end - rect.span.start) < eventShortHeight; // look at other places for this problem
return (preact.createElement("div", { className: 'fc-timegrid-event-harness' +
(isInset ? ' fc-timegrid-event-harness-inset' : ''), key: forcedKey || instanceId, style: Object.assign(Object.assign({ visibility: isVisible ? '' : 'hidden' }, vStyle), hStyle) },
preact.createElement(TimeColEvent, Object.assign({ seg: seg, isDragging: isDragging, isResizing: isResizing, isDateSelecting: isDateSelecting, isSelected: instanceId === eventSelection, isShort: isShort }, internal$1.getSegMeta(seg, todayRange, nowDate)))));
})));
}
// will already have eventMinHeight applied because segInputs already had it
renderHiddenGroups(hiddenGroups, segs) {
let { extraDateSpan, dateProfile, todayRange, nowDate, eventSelection, eventDrag, eventResize } = this.props;
return (preact.createElement(preact.Fragment, null, hiddenGroups.map((hiddenGroup) => {
let positionCss = computeSegVStyle(hiddenGroup.span);
let hiddenSegs = compileSegsFromEntries(hiddenGroup.entries, segs);
return (preact.createElement(TimeColMoreLink, { key: internal$1.buildIsoString(internal$1.computeEarliestSegStart(hiddenSegs)), hiddenSegs: hiddenSegs, top: positionCss.top, bottom: positionCss.bottom, extraDateSpan: extraDateSpan, dateProfile: dateProfile, todayRange: todayRange, nowDate: nowDate, eventSelection: eventSelection, eventDrag: eventDrag, eventResize: eventResize }));
})));
}
renderFillSegs(segs, fillType) {
let { props, context } = this;
let segVCoords = computeSegVCoords(segs, props.date, props.slatCoords, context.options.eventMinHeight); // don't assume all populated
let children = segVCoords.map((vcoords, i) => {
let seg = segs[i];
return (preact.createElement("div", { key: internal$1.buildEventRangeKey(seg.eventRange), className: "fc-timegrid-bg-harness", style: computeSegVStyle(vcoords) }, fillType === 'bg-event' ?
preact.createElement(internal$1.BgEvent, Object.assign({ seg: seg }, internal$1.getSegMeta(seg, props.todayRange, props.nowDate))) :
internal$1.renderFill(fillType)));
});
return preact.createElement(preact.Fragment, null, children);
}
renderNowIndicator(segs) {
let { slatCoords, date } = this.props;
if (!slatCoords) {
return null;
}
return segs.map((seg, i) => (preact.createElement(internal$1.NowIndicatorContainer
// key doesn't matter. will only ever be one
, {
// key doesn't matter. will only ever be one
key: i, elClasses: ['fc-timegrid-now-indicator-line'], elStyle: {
top: slatCoords.computeDateTop(seg.start, date),
}, isAxis: false, date: date })));
}
computeSegHStyle(segHCoords) {
let { isRtl, options } = this.context;
let shouldOverlap = options.slotEventOverlap;
let nearCoord = segHCoords.levelCoord; // the left side if LTR. the right side if RTL. floating-point
let farCoord = segHCoords.levelCoord + segHCoords.thickness; // the right side if LTR. the left side if RTL. floating-point
let left; // amount of space from left edge, a fraction of the total width
let right; // amount of space from right edge, a fraction of the total width
if (shouldOverlap) {
// double the width, but don't go beyond the maximum forward coordinate (1.0)
farCoord = Math.min(1, nearCoord + (farCoord - nearCoord) * 2);
}
if (isRtl) {
left = 1 - farCoord;
right = nearCoord;
}
else {
left = nearCoord;
right = 1 - farCoord;
}
let props = {
zIndex: segHCoords.stackDepth + 1,
left: left * 100 + '%',
right: right * 100 + '%',
};
if (shouldOverlap && !segHCoords.stackForward) {
// add padding to the edge so that forward stacked events don't cover the resizer's icon
props[isRtl ? 'marginLeft' : 'marginRight'] = 10 * 2; // 10 is a guesstimate of the icon's width
}
return props;
}
}
function renderPlainFgSegs(sortedFgSegs, { todayRange, nowDate, eventSelection, eventDrag, eventResize }) {
let hiddenInstances = (eventDrag ? eventDrag.affectedInstances : null) ||
(eventResize ? eventResize.affectedInstances : null) ||
{};
return (preact.createElement(preact.Fragment, null, sortedFgSegs.map((seg) => {
let instanceId = seg.eventRange.instance.instanceId;
return (preact.createElement("div", { key: instanceId, style: { visibility: hiddenInstances[instanceId] ? 'hidden' : '' } },
preact.createElement(TimeColEvent, Object.assign({ seg: seg, isDragging: false, isResizing: false, isDateSelecting: false, isSelected: instanceId === eventSelection, isShort: false }, internal$1.getSegMeta(seg, todayRange, nowDate)))));
})));
}
function computeSegVStyle(segVCoords) {
if (!segVCoords) {
return { top: '', bottom: '' };
}
return {
top: segVCoords.start,
bottom: -segVCoords.end,
};
}
function compileSegsFromEntries(segEntries, allSegs) {
return segEntries.map((segEntry) => allSegs[segEntry.index]);
}
class TimeColsContent extends internal$1.BaseComponent {
constructor() {
super(...arguments);
this.splitFgEventSegs = internal$1.memoize(splitSegsByCol);
this.splitBgEventSegs = internal$1.memoize(splitSegsByCol);
this.splitBusinessHourSegs = internal$1.memoize(splitSegsByCol);
this.splitNowIndicatorSegs = internal$1.memoize(splitSegsByCol);
this.splitDateSelectionSegs = internal$1.memoize(splitSegsByCol);
this.splitEventDrag = internal$1.memoize(splitInteractionByCol);
this.splitEventResize = internal$1.memoize(splitInteractionByCol);
this.rootElRef = preact.createRef();
this.cellElRefs = new internal$1.RefMap();
}
render() {
let { props, context } = this;
let nowIndicatorTop = context.options.nowIndicator &&
props.slatCoords &&
props.slatCoords.safeComputeTop(props.nowDate); // might return void
let colCnt = props.cells.length;
let fgEventSegsByRow = this.splitFgEventSegs(props.fgEventSegs, colCnt);
let bgEventSegsByRow = this.splitBgEventSegs(props.bgEventSegs, colCnt);
let businessHourSegsByRow = this.splitBusinessHourSegs(props.businessHourSegs, colCnt);
let nowIndicatorSegsByRow = this.splitNowIndicatorSegs(props.nowIndicatorSegs, colCnt);
let dateSelectionSegsByRow = this.splitDateSelectionSegs(props.dateSelectionSegs, colCnt);
let eventDragByRow = this.splitEventDrag(props.eventDrag, colCnt);
let eventResizeByRow = this.splitEventResize(props.eventResize, colCnt);
return (preact.createElement("div", { className: "fc-timegrid-cols", ref: this.rootElRef },
preact.createElement("table", { role: "presentation", style: {
minWidth: props.tableMinWidth,
width: props.clientWidth,
} },
props.tableColGroupNode,
preact.createElement("tbody", { role: "presentation" },
preact.createElement("tr", { role: "row" },
props.axis && (preact.createElement("td", { "aria-hidden": true, className: "fc-timegrid-col fc-timegrid-axis" },
preact.createElement("div", { className: "fc-timegrid-col-frame" },
preact.createElement("div", { className: "fc-timegrid-now-indicator-container" }, typeof nowIndicatorTop === 'number' && (preact.createElement(internal$1.NowIndicatorContainer, { elClasses: ['fc-timegrid-now-indicator-arrow'], elStyle: { top: nowIndicatorTop }, isAxis: true, date: props.nowDate })))))),
props.cells.map((cell, i) => (preact.createElement(TimeCol, { key: cell.key, elRef: this.cellElRefs.createRef(cell.key), dateProfile: props.dateProfile, date: cell.date, nowDate: props.nowDate, todayRange: props.todayRange, extraRenderProps: cell.extraRenderProps, extraDataAttrs: cell.extraDataAttrs, extraClassNames: cell.extraClassNames, extraDateSpan: cell.extraDateSpan, fgEventSegs: fgEventSegsByRow[i], bgEventSegs: bgEventSegsByRow[i], businessHourSegs: businessHourSegsByRow[i], nowIndicatorSegs: nowIndicatorSegsByRow[i], dateSelectionSegs: dateSelectionSegsByRow[i], eventDrag: eventDragByRow[i], eventResize: eventResizeByRow[i], slatCoords: props.slatCoords, eventSelection: props.eventSelection, forPrint: props.forPrint }))))))));
}
componentDidMount() {
this.updateCoords();
}
componentDidUpdate() {
this.updateCoords();
}
updateCoords() {
let { props } = this;
if (props.onColCoords &&
props.clientWidth !== null // means sizing has stabilized
) {
props.onColCoords(new internal$1.PositionCache(this.rootElRef.current, collectCellEls(this.cellElRefs.currentMap, props.cells), true, // horizontal
false));
}
}
}
function collectCellEls(elMap, cells) {
return cells.map((cell) => elMap[cell.key]);
}
/* A component that renders one or more columns of vertical time slots
----------------------------------------------------------------------------------------------------------------------*/
class TimeCols extends internal$1.DateComponent {
constructor() {
super(...arguments);
this.processSlotOptions = internal$1.memoize(processSlotOptions);
this.state = {
slatCoords: null,
};
this.handleRootEl = (el) => {
if (el) {
this.context.registerInteractiveComponent(this, {
el,
isHitComboAllowed: this.props.isHitComboAllowed,
});
}
else {
this.context.unregisterInteractiveComponent(this);
}
};
this.handleScrollRequest = (request) => {
let { onScrollTopRequest } = this.props;
let { slatCoords } = this.state;
if (onScrollTopRequest && slatCoords) {
if (request.time) {
let top = slatCoords.computeTimeTop(request.time);
top = Math.ceil(top); // zoom can give weird floating-point values. rather scroll a little bit further
if (top) {
top += 1; // to overcome top border that slots beyond the first have. looks better
}
onScrollTopRequest(top);
}
return true;
}
return false;
};
this.handleColCoords = (colCoords) => {
this.colCoords = colCoords;
};
this.handleSlatCoords = (slatCoords) => {
this.setState({ slatCoords });