-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.js
More file actions
1927 lines (1753 loc) · 72 KB
/
Copy pathplugin.js
File metadata and controls
1927 lines (1753 loc) · 72 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
/**
* Calendar — Hermes desktop plugin. v1.2.0
*
* A full-page calendar with year/month/week/day views, event CRUD and
* to-do checklists. Agents read/write events and todos via the REST
* backend; users interact through the UI.
*
* Python backend: ~/.hermes/plugins/calendar/dashboard/plugin_api.py
* Auto-discovered at /api/plugins/calendar/
*
* STYLING — this plugin ships its own stylesheet (see PLUGIN_CSS) and does not
* use the host's Tailwind utilities. Tailwind v4 generates utilities by
* scanning the app's own source at BUILD time; a plugin loaded at runtime from
* ~/.hermes/desktop-plugins is not in that scan, so a class the app doesn't
* already use for itself has no rule at all. `grid-cols-7` is the case that
* matters here — absent from the shipped CSS, which silently collapsed every
* calendar grid into a single column. Components imported from the SDK
* (Button, Input, Dialog, …) are app-built and keep their own styling; only
* this file's own markup is styled from PLUGIN_CSS.
*/
import {
atom,
Button,
Checkbox,
Codicon,
Dialog,
DialogContent,
DialogFooter,
DialogHeader,
DialogTitle,
host,
Input,
KEYBINDS_AREA,
PALETTE_AREA,
ROUTES_AREA,
SIDEBAR_NAV_AREA,
STATUSBAR_AREAS,
Textarea,
Tip,
useMutation,
useQuery,
useQueryClient,
useValue
} from '@hermes/plugin-sdk'
import { jsx, jsxs } from 'react/jsx-runtime'
import { Fragment, useEffect, useMemo, useState } from 'react'
// ---------------------------------------------------------------------------
// REST binding — bound at register time, consumed by React Query.
// ---------------------------------------------------------------------------
let rest = null
function call(path, opts) {
return rest
? rest(path, opts)
: Promise.reject(new Error('calendar api not ready'))
}
function bindApi(r) {
rest = r
return function () { rest = null }
}
// ---------------------------------------------------------------------------
// Stylesheet
//
// Injected into <head> at register, removed on unload. Colours come from the
// app's own CSS custom properties (those are runtime values, not build-time
// utilities, so they are always available) — the calendar re-themes with the
// rest of Hermes.
// ---------------------------------------------------------------------------
const STYLE_ID = 'hermes-calendar-plugin-styles'
const PLUGIN_CSS = `
.hcal {
--hcal-line: color-mix(in srgb, var(--ui-text-quaternary) 26%, transparent);
--hcal-line-soft: color-mix(in srgb, var(--ui-text-quaternary) 14%, transparent);
--hcal-hover: color-mix(in srgb, var(--ui-text-primary) 8%, transparent);
--hcal-muted: color-mix(in srgb, var(--ui-text-quaternary) 7%, transparent);
display: flex;
flex-direction: column;
height: 100%;
min-height: 0;
padding: 0.75rem;
color: var(--ui-text-primary);
font-size: 0.8125rem;
}
.hcal-overlay {
position: fixed;
inset: 0;
z-index: 120;
background: var(--ui-surface-background, var(--ui-bg-primary));
}
/* header ------------------------------------------------------------------ */
.hcal-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; flex: 0 0 auto; margin-bottom: 0.75rem; }
.hcal-head-l, .hcal-head-r { display: flex; align-items: center; gap: 0.375rem; }
.hcal-title { font-size: 0.95rem; font-weight: 600; white-space: nowrap; }
.hcal-icon { display: inline-flex; align-items: center; justify-content: center; width: 1.5rem; height: 1.5rem; border: 0; border-radius: 4px; background: none; color: var(--ui-text-tertiary); cursor: pointer; }
.hcal-icon:hover { background: var(--hcal-hover); color: var(--ui-text-primary); }
/* segmented view switcher -------------------------------------------------- */
.hcal-seg { display: inline-flex; padding: 2px; border-radius: 6px; background: var(--hcal-muted); }
.hcal-seg button { border: 0; background: none; padding: 0.15rem 0.6rem; font-size: 0.72rem; border-radius: 4px; color: var(--ui-text-tertiary); cursor: pointer; }
.hcal-seg button:hover { color: var(--ui-text-primary); }
.hcal-seg button[data-on='1'] { background: var(--ui-bg-elevated, var(--ui-bg-card)); color: var(--ui-text-primary); font-weight: 500; box-shadow: 0 1px 2px rgb(0 0 0 / 0.18); }
/* the 7-column week grid — the class the host stylesheet never had ---------- */
.hcal-grid7 { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.hcal-dow { text-align: center; font-size: 0.65rem; font-weight: 500; color: var(--ui-text-quaternary); padding: 0.25rem 0; }
/* month -------------------------------------------------------------------- */
.hcal-month { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.hcal-month-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); grid-auto-rows: 1fr; flex: 1; min-height: 0; border-top: 1px solid var(--hcal-line); border-left: 1px solid var(--hcal-line); }
.hcal-cell { border-right: 1px solid var(--hcal-line); border-bottom: 1px solid var(--hcal-line); padding: 2px 3px; overflow: hidden; display: flex; flex-direction: column; gap: 2px; cursor: pointer; }
.hcal-cell:hover { background: var(--hcal-hover); }
.hcal-cell--blank { background: var(--hcal-muted); cursor: default; }
.hcal-cell--blank:hover { background: var(--hcal-muted); }
.hcal-cell--today { box-shadow: inset 0 0 0 1px var(--ui-accent); }
.hcal-daynum { font-size: 0.7rem; font-weight: 500; color: var(--ui-text-secondary); }
.hcal-cell--today .hcal-daynum { color: var(--ui-accent); font-weight: 700; }
.hcal-more { font-size: 0.6rem; color: var(--ui-accent); font-weight: 500; }
/* event chips -------------------------------------------------------------- */
/* flex:none — inside a short month cell a shrinkable chip gets squashed below
its own line-height and the label is sliced in half; let the cell clip. */
.hcal-chip { flex: none; border-radius: 3px; padding: 1px 4px; font-size: 0.62rem; line-height: 1.35; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.hcal-chip:hover { filter: brightness(1.15); }
.hcal-chip--lg { font-size: 0.72rem; padding: 3px 6px; border-radius: 4px; }
.hcal-chip-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.hcal-chip-time { font-size: 0.6rem; opacity: 0.75; }
/* week --------------------------------------------------------------------- */
.hcal-week { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.hcal-week-head { cursor: pointer; text-align: center; padding: 0.2rem 0; border-radius: 5px; }
.hcal-week-head:hover { background: var(--hcal-hover); }
.hcal-week-head[data-today='1'] { background: var(--ui-accent); }
.hcal-week-head[data-today='1'] .hcal-week-dow, .hcal-week-head[data-today='1'] .hcal-week-num { color: #fff; }
.hcal-week-dow { font-size: 0.6rem; color: var(--ui-text-quaternary); }
.hcal-week-num { font-size: 0.85rem; font-weight: 500; }
.hcal-week-body { display: flex; flex: 1; min-height: 0; border-top: 1px solid var(--hcal-line); }
.hcal-week-col { flex: 1; min-width: 0; padding: 3px; overflow-y: auto; display: flex; flex-direction: column; gap: 3px; border-left: 1px solid var(--hcal-line-soft); }
.hcal-week-col:first-child { border-left: 0; }
.hcal-week-col[data-today='1'] { background: color-mix(in srgb, var(--ui-accent) 8%, transparent); }
/* year --------------------------------------------------------------------- */
/* 4 x 3 that fills the pane — explicit 1fr rows, no align-content:start, so
the twelve months share the height instead of leaving a gap underneath. */
.hcal-year { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); grid-template-rows: repeat(3, minmax(0, 1fr)); gap: 0.5rem; flex: 1; min-height: 0; }
.hcal-mini { display: flex; flex-direction: column; min-height: 0; border: 1px solid var(--hcal-line); border-radius: 8px; padding: 0.35rem; overflow: hidden; }
.hcal-mini-name { flex: none; font-size: 0.72rem; font-weight: 600; margin-bottom: 0.15rem; cursor: pointer; }
.hcal-mini-name:hover { color: var(--ui-accent); }
.hcal-mini-dow { font-size: 0.5rem; text-align: center; color: var(--ui-text-quaternary); }
/* Every month renders a fixed 6 rows, so day cells line up across the year. */
.hcal-mini-weeks { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.hcal-mini-week { flex: 1; min-height: 0; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); align-items: center; }
.hcal-mini-day { font-size: 0.56rem; text-align: center; border-radius: 3px; cursor: pointer; }
.hcal-mini-day:hover { background: var(--hcal-hover); }
.hcal-mini-day[data-today='1'] { background: var(--ui-accent); color: #fff; font-weight: 700; }
.hcal-mini-day[data-has='1']:not([data-today='1']) { color: var(--ui-accent); font-weight: 600; }
/* day ---------------------------------------------------------------------- */
.hcal-day { display: flex; height: 100%; min-height: 0; gap: 0.75rem; }
.hcal-day-main { flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 0; }
.hcal-allday { display: flex; flex-direction: column; gap: 3px; margin-bottom: 0.4rem; flex: 0 0 auto; }
/* The whole window fits — rows share the height, nothing scrolls. Hour rows
are the backdrop; events are absolutely placed over them so one can span
several hours and overlapping ones can share the width. */
.hcal-hours { position: relative; flex: 1; min-height: 0; border-top: 1px solid var(--hcal-line); overflow: hidden; }
.hcal-hourgrid { position: absolute; inset: 0; display: flex; flex-direction: column; }
.hcal-hour { flex: 1; min-height: 0; display: flex; border-bottom: 1px solid var(--hcal-line-soft); }
/* An hour pulled in only because an event lives there. */
.hcal-hour[data-extra='1'] { background: var(--hcal-muted); }
.hcal-hour-label { width: 3.5rem; flex: 0 0 auto; text-align: right; padding: 2px 6px 0 0; font-size: 0.62rem; color: var(--ui-text-quaternary); font-variant-numeric: tabular-nums; }
.hcal-hour-rest { flex: 1; min-width: 0; }
.hcal-events { position: absolute; top: 0; bottom: 0; left: 3.5rem; right: 0; }
/* min-height keeps a short event readable: a 15-minute block in a 16-hour
window is only a couple of pixels tall, so its title would be sliced off. */
.hcal-ev { position: absolute; overflow: hidden; min-height: 1.1rem; border-radius: 4px; padding: 1px 5px; font-size: 0.7rem; line-height: 1.25; cursor: pointer; box-shadow: 0 0 0 1px var(--ui-surface-background, transparent); }
.hcal-ev:hover { filter: brightness(1.15); }
.hcal-ev-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hcal-ev-time { font-size: 0.6rem; opacity: 0.8; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hcal-note { flex: none; padding-top: 0.35rem; font-size: 0.66rem; color: var(--ui-text-quaternary); }
/* day-range setting -------------------------------------------------------- */
.hcal-dayset { position: relative; flex: none; align-self: flex-start; margin-bottom: 0.35rem; }
.hcal-dayset-toggle { display: inline-flex; align-items: center; gap: 0.3rem; border: 1px solid var(--hcal-line); border-radius: 5px; background: none; padding: 0.1rem 0.4rem; font: inherit; font-size: 0.66rem; color: var(--ui-text-tertiary); cursor: pointer; }
.hcal-dayset-toggle:hover { background: var(--hcal-hover); color: var(--ui-text-primary); }
.hcal-dayset-panel { position: absolute; top: calc(100% + 4px); left: 0; z-index: 5; width: 15rem; display: flex; flex-direction: column; gap: 0.45rem; padding: 0.6rem; border: 1px solid var(--hcal-line); border-radius: 8px; background: var(--ui-bg-elevated, var(--ui-bg-card)); box-shadow: 0 8px 24px rgb(0 0 0 / 0.35); }
.hcal-dayset-row { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; font-size: 0.72rem; }
/* One dropdown look, shared by the day-range panel and the event form. */
.hcal-select { font: inherit; font-size: 0.72rem; padding: 0.15rem 0.3rem; border-radius: 4px; border: 1px solid var(--hcal-line); background: var(--ui-bg-input, transparent); color: var(--ui-text-primary); cursor: pointer; }
.hcal-select:hover { border-color: color-mix(in srgb, var(--ui-text-quaternary) 50%, transparent); }
.hcal-select:disabled { opacity: 0.45; cursor: default; }
.hcal-field { display: flex; flex-direction: column; gap: 0.2rem; }
.hcal-fieldlabel { font-size: 0.62rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--ui-text-quaternary); }
/* start/end time: hour + minute dropdowns and an AM/PM toggle */
.hcal-times { display: flex; flex-direction: column; gap: 0.5rem; }
.hcal-time { display: flex; align-items: center; gap: 0.25rem; }
.hcal-time-sep { color: var(--ui-text-quaternary); }
.hcal-mer { display: inline-flex; margin-left: 0.3rem; padding: 2px; border-radius: 5px; background: var(--hcal-muted); }
.hcal-mer button { border: 0; background: none; padding: 0.1rem 0.45rem; font: inherit; font-size: 0.68rem; border-radius: 4px; color: var(--ui-text-tertiary); cursor: pointer; }
.hcal-mer button:hover:not(:disabled) { color: var(--ui-text-primary); }
.hcal-mer button[data-on='1'] { background: var(--ui-bg-elevated, var(--ui-bg-card)); color: var(--ui-text-primary); font-weight: 600; box-shadow: 0 1px 2px rgb(0 0 0 / 0.18); }
.hcal-mer button:disabled { opacity: 0.45; cursor: default; }
.hcal-timeerr { font-size: 0.66rem; color: var(--ui-danger, #ef4444); }
.hcal-dayset-actions { display: flex; justify-content: flex-end; gap: 0.3rem; }
.hcal-dayset-note { font-size: 0.62rem; color: var(--ui-text-quaternary); line-height: 1.4; }
/* event detail card -------------------------------------------------------- */
.hcal-card { display: flex; flex-direction: column; gap: 0.7rem; padding: 0.5rem 0 0.25rem; }
.hcal-card-title { display: inline-flex; align-items: center; gap: 0.45rem; }
.hcal-card-dot { width: 0.6rem; height: 0.6rem; border-radius: 50%; flex: none; }
.hcal-card-row { display: flex; align-items: flex-start; gap: 0.5rem; color: var(--ui-text-tertiary); }
.hcal-card-rowtext { min-width: 0; }
.hcal-card-label { font-size: 0.62rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--ui-text-quaternary); }
.hcal-card-value { font-size: 0.8rem; color: var(--ui-text-primary); overflow-wrap: anywhere; }
.hcal-card-desc { padding-top: 0.15rem; white-space: pre-wrap; }
/* Provenance is secondary — quieter type, below a rule. */
.hcal-card-footer { display: flex; flex-direction: column; gap: 0.2rem; margin-top: 0.2rem; padding-top: 0.55rem; border-top: 1px solid var(--hcal-line-soft); }
.hcal-card-meta { display: flex; gap: 0.4rem; font-size: 0.68rem; color: var(--ui-text-quaternary); }
.hcal-card-metalabel { flex: none; }
.hcal-card-metavalue { color: var(--ui-text-tertiary); overflow-wrap: anywhere; }
/* to-do -------------------------------------------------------------------- */
.hcal-todo { width: 15rem; flex: 0 0 auto; display: flex; flex-direction: column; min-height: 0; border: 1px solid var(--hcal-line); border-radius: 8px; padding: 0.6rem; }
.hcal-todo-head { display: flex; align-items: center; gap: 0.4rem; font-size: 0.78rem; font-weight: 600; margin-bottom: 0.5rem; flex: 0 0 auto; }
.hcal-todo-add { display: flex; gap: 0.3rem; margin-bottom: 0.5rem; flex: 0 0 auto; }
.hcal-todo-list { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 1px; }
.hcal-todo-row { display: flex; align-items: center; gap: 0.45rem; padding: 2px 0; }
.hcal-todo-text { flex: 1; min-width: 0; font-size: 0.78rem; overflow: hidden; text-overflow: ellipsis; }
.hcal-todo-row[data-done='1'] .hcal-todo-text { text-decoration: line-through; color: var(--ui-text-quaternary); }
.hcal-todo-del { border: 0; background: none; padding: 0; cursor: pointer; color: var(--ui-text-quaternary); opacity: 0; }
.hcal-todo-row:hover .hcal-todo-del { opacity: 1; }
.hcal-todo-del:hover { color: var(--ui-danger, #ef4444); }
.hcal-empty { font-size: 0.72rem; color: var(--ui-text-quaternary); font-style: italic; }
/* dialog ------------------------------------------------------------------- */
.hcal-form { display: flex; flex-direction: column; gap: 0.6rem; padding: 0.75rem 0; }
.hcal-check { display: flex; align-items: center; gap: 0.45rem; font-size: 0.8rem; }
.hcal-swatches { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.hcal-swatch { width: 1.35rem; height: 1.35rem; border-radius: 50%; border: 2px solid transparent; cursor: pointer; padding: 0; }
.hcal-swatch[data-on='1'] { border-color: var(--ui-text-primary); transform: scale(1.12); }
/* statusbar pill ----------------------------------------------------------- */
.hcal-pill { display: inline-flex; align-items: center; gap: 0.25rem; height: 100%; padding: 0 0.35rem; border: 0; background: none; font-size: 0.6875rem; font-variant-numeric: tabular-nums; color: var(--ui-text-tertiary); cursor: pointer; }
.hcal-pill:hover { background: var(--hcal-hover, rgb(255 255 255 / 0.08)); color: var(--ui-text-primary); }
`
function installStyles() {
if (typeof document === 'undefined') return function () {}
var existing = document.getElementById(STYLE_ID)
if (existing) existing.remove()
var el = document.createElement('style')
el.id = STYLE_ID
el.textContent = PLUGIN_CSS
document.head.appendChild(el)
return function () {
if (el.parentNode) el.parentNode.removeChild(el)
}
}
// ---------------------------------------------------------------------------
// Pop-out to a separate OS window.
//
// A plugin cannot open a calendar-only window: Electron's window-open handler
// denies `window.open` (it hands the URL to the external browser), and the
// route-targeted window kinds live in the main process. What IS reachable is
// the app's own "new window" bridge, which opens a full peer window. So we
// open one and leave a short-lived note in plugin storage — localStorage is
// shared across windows of the same origin, so the NEW window's copy of this
// plugin finds the note as it registers and raises the calendar itself.
// ---------------------------------------------------------------------------
let store = null
const HANDOFF_KEY = 'openOverlayOnBoot'
const HANDOFF_TTL_MS = 20000
function bindStorage(s) {
store = s
return function () { store = null }
}
function canPopOut() {
return typeof window !== 'undefined' &&
Boolean(window.hermesDesktop) &&
typeof window.hermesDesktop.openWindow === 'function'
}
/** True once, in the window that was opened by `openInNewWindow`. */
function consumeHandoff() {
if (!store) return false
var ts = store.get(HANDOFF_KEY, 0)
store.remove(HANDOFF_KEY)
return typeof ts === 'number' && Date.now() - ts < HANDOFF_TTL_MS
}
function openInNewWindow() {
if (!canPopOut()) {
host.notifyError(
new Error('the desktop shell bridge is unavailable'),
'Calendar: cannot open a new window'
)
return
}
if (store) store.set(HANDOFF_KEY, Date.now())
Promise.resolve(window.hermesDesktop.openWindow())
.then(function (result) {
if (!result || !result.ok) {
if (store) store.remove(HANDOFF_KEY)
host.notifyError(
new Error((result && result.error) || 'unknown error'),
'Calendar: could not open a new window'
)
}
})
.catch(function (err) {
if (store) store.remove(HANDOFF_KEY)
host.notifyError(err, 'Calendar: could not open a new window')
})
}
// ---------------------------------------------------------------------------
// Query keys
// ---------------------------------------------------------------------------
function eventsKey(startDate, endDate) {
return ['calendar', 'events', startDate, endDate]
}
function todosKey(date) {
return ['calendar', 'todos', date]
}
function todayKey() {
return ['calendar', 'today']
}
// ---------------------------------------------------------------------------
// State atoms
// ---------------------------------------------------------------------------
const $viewDate = atom(new Date())
const $viewMode = atom('month')
const $dialogOpen = atom(false)
const $editingEvent = atom(null)
const $newTodoText = atom('')
/** Full-window calendar layer, over the session screen. */
const $overlayOpen = atom(false)
/** Event whose detail card is showing (null = none). */
const $viewingEvent = atom(null)
/** Visible hour window in the day view, inclusive start, exclusive end. */
const $dayStartHour = atom(6)
const $dayEndHour = atom(22)
const $daySettingsOpen = atom(false)
const DAY_RANGE_KEY = 'dayHourRange'
function setDayRange(start, end) {
var s = Math.max(0, Math.min(23, start))
var e = Math.max(s + 1, Math.min(24, end))
$dayStartHour.set(s)
$dayEndHour.set(e)
if (store) store.set(DAY_RANGE_KEY, { start: s, end: e })
}
function loadDayRange() {
if (!store) return
var saved = store.get(DAY_RANGE_KEY, null)
if (saved && typeof saved.start === 'number' && typeof saved.end === 'number') {
$dayStartHour.set(Math.max(0, Math.min(23, saved.start)))
$dayEndHour.set(Math.max(1, Math.min(24, saved.end)))
}
}
// ---------------------------------------------------------------------------
// Date utilities
// ---------------------------------------------------------------------------
// Monday-first, so every grid reads Mon…Sun. `dowIndex` converts a JS
// getDay() (Sun=0) into a column in these arrays — index them with that, never
// with getDay() directly.
const DAYS_SHORT = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
const DAYS_MIN = ['Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su']
const MONTHS = [
'January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December'
]
const MONTHS_SHORT = [
'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
]
const EVENT_COLORS = [
'#4f8cff', '#22c55e', '#f59e0b', '#ef4444', '#a855f7',
'#ec4899', '#06b6d4', '#84cc16', '#f97316', '#8b5cf6'
]
function pad(n) {
return String(n).padStart(2, '0')
}
function todayStr() {
var d = new Date()
return d.getFullYear() + '-' + pad(d.getMonth() + 1) + '-' + pad(d.getDate())
}
function isoDate(d) {
return d.getFullYear() + '-' + pad(d.getMonth() + 1) + '-' + pad(d.getDate())
}
function addDays(date, n) {
var d = new Date(date)
d.setDate(d.getDate() + n)
return d
}
function daysInMonth(year, month) {
return new Date(year, month + 1, 0).getDate()
}
/** Column for a date in a Monday-first week: Mon=0 … Sun=6. */
function dowIndex(d) {
return (d.getDay() + 6) % 7
}
function monthGrid(year, month) {
var firstDow = dowIndex(new Date(year, month, 1))
var days = daysInMonth(year, month)
var grid = []
var week = []
for (var i = 0; i < firstDow; i++) week.push(null)
for (var d = 1; d <= days; d++) {
week.push(d)
if (week.length === 7) { grid.push(week); week = [] }
}
if (week.length > 0) {
while (week.length < 7) week.push(null)
grid.push(week)
}
return grid
}
/** Today always lands on today's day view, so it's only inert when you are
* already looking at exactly that. */
function viewShowsToday(viewMode, viewDate) {
return viewMode === 'day' && isoDate(viewDate) === todayStr()
}
/** Pad a month grid out to `rows` week rows, so a 4- or 5-row month occupies
* the same height as a 6-row one (keeps the year view's cells aligned). */
function padWeeks(grid, rows) {
var out = grid.slice()
while (out.length < rows) out.push([null, null, null, null, null, null, null])
return out
}
// Monday-first, matching `monthGrid` and the DAYS_SHORT header row.
function getWeekDays(date) {
var d = new Date(date)
var mon = new Date(d)
mon.setDate(d.getDate() - dowIndex(d))
var days = []
for (var i = 0; i < 7; i++) {
days.push(addDays(mon, i))
}
return days
}
function formatTime(isoTime) {
if (!isoTime) return ''
var parts = String(isoTime).split(':')
var hour = parseInt(parts[0], 10)
if (isNaN(hour)) return ''
var minute = parseInt(parts[1], 10)
if (isNaN(minute)) minute = 0
var suffix = hour < 12 ? 'AM' : 'PM'
var h12 = hour % 12
if (h12 === 0) h12 = 12
return minute === 0
? h12 + ' ' + suffix
: h12 + ':' + pad(minute) + ' ' + suffix
}
/** Minutes past midnight, or null when the time is unusable. */
function minutesOf(isoTime) {
var parts = String(isoTime || '').split(':')
var h = parseInt(parts[0], 10)
var m = parseInt(parts[1], 10)
if (isNaN(h) || h < 0 || h > 23) return null
if (isNaN(m) || m < 0 || m > 59) m = 0
return h * 60 + m
}
/** DEFAULT_EVENT_MINUTES is what an event with no end time occupies — one
* slot, matching how such events used to render. */
const DEFAULT_EVENT_MINUTES = 60
/** An event's [start, end) in minutes past midnight. */
function eventSpan(e) {
var start = minutesOf(e.start_time)
if (start === null) start = 0
var end = minutesOf(e.end_time)
// An end at or before the start is bad data (or a wrap past midnight) —
// fall back to the default block rather than rendering a negative height.
if (end === null || end <= start) end = start + DEFAULT_EVENT_MINUTES
return { start: start, end: Math.min(end, 24 * 60) }
}
/**
* Position overlapping events into columns — any number of them, not just two.
*
* Events are grouped into clusters of transitively-overlapping events; within
* a cluster each event takes the first column already free at its start time,
* and the whole cluster is split into as many columns as that needed. So two
* concurrent events are halves, three are thirds, and a non-overlapping event
* still gets the full width.
*/
function layoutDayEvents(events) {
var items = events.map(function (e) {
var span = eventSpan(e)
return { event: e, start: span.start, end: span.end, col: 0, cols: 1 }
})
items.sort(function (a, b) { return a.start - b.start || a.end - b.end })
var cluster = []
var clusterEnd = -1
function flush() {
if (!cluster.length) return
var colEnds = []
cluster.forEach(function (it) {
var placed = false
for (var c = 0; c < colEnds.length; c++) {
if (it.start >= colEnds[c]) {
it.col = c
colEnds[c] = it.end
placed = true
break
}
}
if (!placed) {
it.col = colEnds.length
colEnds.push(it.end)
}
})
cluster.forEach(function (it) { it.cols = colEnds.length })
cluster = []
clusterEnd = -1
}
items.forEach(function (it) {
if (cluster.length && it.start >= clusterEnd) flush()
cluster.push(it)
clusterEnd = Math.max(clusterEnd, it.end)
})
flush()
return items
}
/** Events are agent-writable over REST, so never trust `color` to be set —
* a null would otherwise render as the string 'null22' in a style. */
function eventColor(e) {
return (e && e.color) || EVENT_COLORS[0]
}
/** Tinted background + solid left edge, the chip look used by every view. */
function chipStyle(e) {
var c = eventColor(e)
return { backgroundColor: c + '2e', borderLeft: '3px solid ' + c }
}
// ---------------------------------------------------------------------------
// Helper: date range for current view
// ---------------------------------------------------------------------------
function useViewRange() {
var viewMode = useValue($viewMode)
var vd = useValue($viewDate)
return useMemo(function () {
switch (viewMode) {
case 'year':
return { start: vd.getFullYear() + '-01-01', end: vd.getFullYear() + '-12-31' }
case 'month':
return {
start: vd.getFullYear() + '-' + pad(vd.getMonth() + 1) + '-01',
end: vd.getFullYear() + '-' + pad(vd.getMonth() + 1) + '-' + pad(daysInMonth(vd.getFullYear(), vd.getMonth()))
}
case 'week': {
var wd = getWeekDays(vd)
return { start: isoDate(wd[0]), end: isoDate(wd[6]) }
}
case 'day':
return { start: isoDate(vd), end: isoDate(vd) }
default:
return { start: todayStr(), end: todayStr() }
}
}, [viewMode, vd])
}
// ---------------------------------------------------------------------------
// Event dialog
// ---------------------------------------------------------------------------
const MINUTE_STEP = 5
// 12, 1, 2 … 11 — chronological within a meridiem rather than plain numeric.
const HOUR12_CHOICES = [12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
/** 'HH:MM' (24h) → { hour12, minute, meridiem }, or null when unset/unusable. */
function splitTime(value) {
var mins = minutesOf(value)
if (mins === null) return null
var h = Math.floor(mins / 60)
var h12 = h % 12
if (h12 === 0) h12 = 12
return { hour12: h12, minute: mins % 60, meridiem: h < 12 ? 'AM' : 'PM' }
}
/** { hour12, minute, meridiem } → 'HH:MM' (24h). */
function joinTime(hour12, minute, meridiem) {
var h = hour12 % 12
if (meridiem === 'PM') h += 12
return pad(h) + ':' + pad(minute)
}
/** With hour/minute/meridiem picked independently, an end at or before the
* start is reachable — the dialog blocks the save rather than storing a
* negative duration. */
function endsBeforeStart(allDay, startTime, endTime) {
if (allDay) return false
var start = minutesOf(startTime)
var end = minutesOf(endTime)
return start !== null && end !== null && end <= start
}
/**
* Hour + minute dropdowns and an AM/PM toggle. The hour list carries a '—'
* entry so a time can still be cleared, which the backend allows (an event
* may have no time without being all-day).
*/
function TimeSelect(props) {
var parts = splitTime(props.value)
function emit(hour12, minute, meridiem) {
props.onChange(joinTime(hour12, minute, meridiem))
}
// Editing a cleared time has to start somewhere: 9:00 AM, then the user
// adjusts. Picking '—' clears it again.
var cur = parts || { hour12: 9, minute: 0, meridiem: 'AM' }
var minuteValues = []
for (var m = 0; m < 60; m += MINUTE_STEP) minuteValues.push(m)
// An off-grid minute already on the event (an agent can write 09:07) stays
// selectable, so editing never silently moves it.
if (parts && minuteValues.indexOf(parts.minute) === -1) {
minuteValues.push(parts.minute)
minuteValues.sort(function (a, b) { return a - b })
}
return jsxs('div', {
className: 'hcal-time',
children: [
jsx('select', {
className: 'hcal-select',
'aria-label': props.label + ' hour',
value: parts ? String(parts.hour12) : '',
onChange: function (e) {
if (e.target.value === '') return props.onChange('')
emit(parseInt(e.target.value, 10), cur.minute, cur.meridiem)
},
children: [jsx('option', { value: '', children: '—' }, 'none')].concat(
HOUR12_CHOICES.map(function (h) {
return jsx('option', { value: String(h), children: String(h) }, h)
})
)
}),
jsx('span', { className: 'hcal-time-sep', children: ':' }),
jsx('select', {
className: 'hcal-select',
'aria-label': props.label + ' minutes',
disabled: !parts,
value: parts ? String(parts.minute) : '',
onChange: function (e) { emit(cur.hour12, parseInt(e.target.value, 10), cur.meridiem) },
children: minuteValues.map(function (v) {
return jsx('option', { value: String(v), children: pad(v) }, v)
})
}),
jsx('div', {
className: 'hcal-mer',
children: ['AM', 'PM'].map(function (mer) {
return jsx('button', {
type: 'button',
'data-on': parts && parts.meridiem === mer ? '1' : '0',
disabled: !parts,
onClick: function () { emit(cur.hour12, cur.minute, mer) },
children: mer
}, mer)
})
})
]
})
}
function EventDialog() {
var open = useValue($dialogOpen)
var editing = useValue($editingEvent)
var qc = useQueryClient()
var vm = useValue($viewMode)
var vd = useValue($viewDate)
var _useState = useState('')
var title = _useState[0]
var setTitle = _useState[1]
var _useState2 = useState(todayStr())
var evDate = _useState2[0]
var setEvDate = _useState2[1]
var _useState3 = useState('09:00')
var startTime = _useState3[0]
var setStartTime = _useState3[1]
var _useState4 = useState('10:00')
var endTime = _useState4[0]
var setEndTime = _useState4[1]
var _useState5 = useState(false)
var allDay = _useState5[0]
var setAllDay = _useState5[1]
var _useState6 = useState(EVENT_COLORS[0])
var color = _useState6[0]
var setColor = _useState6[1]
var _useState7 = useState('')
var desc = _useState7[0]
var setDesc = _useState7[1]
useEffect(function () {
if (editing) {
setTitle(editing.title || '')
setEvDate(editing.date || todayStr())
setStartTime(editing.start_time || '09:00')
setEndTime(editing.end_time || '10:00')
setAllDay(Boolean(editing.all_day))
setColor(editing.color || EVENT_COLORS[0])
setDesc(editing.description || '')
} else if (open) {
var d = vm === 'day' ? isoDate(vd) : todayStr()
setTitle('')
setEvDate(d)
setStartTime('')
setEndTime('')
setAllDay(false)
setColor(EVENT_COLORS[0])
setDesc('')
}
}, [open, editing])
var saveMutation = useMutation({
mutationFn: function () {
// An all-day event carries no times: send explicit nulls so switching an
// existing timed event to all-day actually drops its old start/end.
var body = {
title: title.trim(),
date: evDate,
start_time: allDay ? null : (startTime || null),
end_time: allDay ? null : (endTime || null),
all_day: allDay,
color: color,
description: desc
}
if (editing) {
body.editor = 'user'
return call('/events/' + editing.id, { method: 'PUT', body: body })
}
// Provenance is set once, at creation — an edit must not relabel an
// agent's event as yours.
body.creator = 'user'
return call('/events', { method: 'POST', body: body })
},
onSuccess: function () {
qc.invalidateQueries({ queryKey: ['calendar'] })
$dialogOpen.set(false)
$editingEvent.set(null)
}
})
var deleteMutation = useMutation({
mutationFn: function () { return editing ? call('/events/' + editing.id, { method: 'DELETE' }) : Promise.resolve() },
onSuccess: function () {
qc.invalidateQueries({ queryKey: ['calendar'] })
$dialogOpen.set(false)
$editingEvent.set(null)
}
})
function close() {
$dialogOpen.set(false)
$editingEvent.set(null)
}
var badRange = endsBeforeStart(allDay, startTime, endTime)
if (!open) return null
return jsx(Dialog, {
open: true,
onOpenChange: close,
children: jsxs(DialogContent, {
children: [
jsx(DialogHeader, {
children: jsx(DialogTitle, {
children: editing ? 'Edit Event' : 'New Event'
})
}),
jsxs('div', {
className: 'hcal-form',
children: [
jsx(Input, {
placeholder: 'Event title',
value: title,
onChange: function (e) { setTitle(e.target.value) }
}),
jsx(Input, {
type: 'date',
value: evDate,
onChange: function (e) { setEvDate(e.target.value) }
}),
!allDay && jsxs('div', {
className: 'hcal-times',
children: [
jsxs('div', {
className: 'hcal-field',
children: [
jsx('span', { className: 'hcal-fieldlabel', children: 'Starts' }),
jsx(TimeSelect, {
label: 'Start',
value: startTime,
onChange: setStartTime
})
]
}),
jsxs('div', {
className: 'hcal-field',
children: [
jsx('span', { className: 'hcal-fieldlabel', children: 'Ends' }),
jsx(TimeSelect, {
label: 'End',
value: endTime,
onChange: setEndTime
})
]
}),
badRange && jsx('div', {
className: 'hcal-timeerr',
children: 'The end time is before the start time.'
})
]
}),
jsxs('label', {
className: 'hcal-check',
children: [
jsx('input', { type: 'checkbox', checked: allDay, onChange: function (e) { setAllDay(e.target.checked) } }),
'All day'
]
}),
jsx('div', {
className: 'hcal-swatches',
children: EVENT_COLORS.map(function (c) {
return jsx('button', {
type: 'button',
className: 'hcal-swatch',
'data-on': color === c ? '1' : '0',
style: { backgroundColor: c },
onClick: function () { setColor(c) }
}, c)
})
}),
jsx(Textarea, {
placeholder: 'Description (optional)',
value: desc,
onChange: function (e) { setDesc(e.target.value) },
rows: 3
})
]
}),
jsxs(DialogFooter, {
children: [
editing && jsx(Button, { variant: 'destructive', size: 'sm', onClick: function () { deleteMutation.mutate() }, children: 'Delete' }),
jsx(Button, { variant: 'ghost', size: 'sm', onClick: close, children: 'Cancel' }),
jsx(Button, {
size: 'sm',
onClick: function () { saveMutation.mutate() },
disabled: !title.trim() || badRange,
children: 'Save'
})
]
})
]
})
})
}
// ---------------------------------------------------------------------------
// Event detail card — what a click on an event opens. Editing is one gear away.
// ---------------------------------------------------------------------------
/** Epoch seconds (what the backend stores) → readable local timestamp. */
function formatStamp(epochSeconds) {
if (!epochSeconds && epochSeconds !== 0) return 'unknown'
var d = new Date(Number(epochSeconds) * 1000)
if (isNaN(d.getTime())) return 'unknown'
return DAYS_SHORT[dowIndex(d)] + ', ' + MONTHS_SHORT[d.getMonth()] + ' ' + d.getDate() + ', ' +
d.getFullYear() + ' at ' + formatTime(pad(d.getHours()) + ':' + pad(d.getMinutes()))
}
/** Human date for an event's own day. */
function formatEventDate(ds) {
var parts = String(ds || '').split('-')
if (parts.length !== 3) return ds || ''
var d = new Date(Number(parts[0]), Number(parts[1]) - 1, Number(parts[2]))
if (isNaN(d.getTime())) return ds
return DAYS_SHORT[dowIndex(d)] + ', ' + MONTHS[d.getMonth()] + ' ' + d.getDate() + ', ' + d.getFullYear()
}
function EventCard() {
var event = useValue($viewingEvent)
if (!event) return null
function close() { $viewingEvent.set(null) }
var when = event.all_day
? 'All day'
: event.end_time
? formatTime(event.start_time) + ' – ' + formatTime(event.end_time)
: formatTime(event.start_time) || 'No time set'
// Rows created before provenance existed report as 'user' via the column
// default, which is the right assumption for a hand-made calendar.
function actor(kind, name) {
return kind === 'agent' ? 'Agent · ' + (name || 'unnamed') : 'You'
}
var createdBy = actor(event.creator, event.creator_name)
var edited = event.updated_at && event.updated_at !== event.created_at
var editedBy = actor(event.editor || event.creator, event.editor_name || event.creator_name)
function row(icon, label, value) {
return jsxs('div', {
className: 'hcal-card-row',
children: [
jsx(Codicon, { name: icon, size: '0.85rem' }),
jsxs('div', {
className: 'hcal-card-rowtext',
children: [
jsx('div', { className: 'hcal-card-label', children: label }),
jsx('div', { className: 'hcal-card-value', children: value })
]
})
]
}, label)
}
function meta(label, value) {
return jsxs('div', {
className: 'hcal-card-meta',
children: [
jsx('span', { className: 'hcal-card-metalabel', children: label }),
jsx('span', { className: 'hcal-card-metavalue', children: value })
]
}, label)
}
return jsx(Dialog, {
open: true,
onOpenChange: close,
children: jsxs(DialogContent, {
children: [
jsx(DialogHeader, {
children: jsx(DialogTitle, {
children: jsxs('span', {
className: 'hcal-card-title',
children: [
jsx('span', { className: 'hcal-card-dot', style: { backgroundColor: eventColor(event) } }),
event.title
]
})
})
}),
jsxs('div', {
className: 'hcal-card',
children: [