-
-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy patheditor.ts
More file actions
executable file
·2165 lines (1969 loc) · 80.2 KB
/
editor.ts
File metadata and controls
executable file
·2165 lines (1969 loc) · 80.2 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
/* eslint-disable import/order */
/**
* Editor module for Calendar Card Pro
* ------------------------
* Provides the visual configuration editor for Calendar Card Pro.
* Handles config validation, upgrade, and dynamic UI rendering using native Home Assistant elements.
*/
//-----------------------------------------------------------------------------
// IMPORTS & CONSTANTS
//-----------------------------------------------------------------------------
import { LitElement, TemplateResult, html } from 'lit';
import { property } from 'lit/decorators.js';
import styles from './editor.styles';
import * as Types from '../config/types';
import * as Config from '../config/config';
import * as Helpers from '../utils/helpers';
import * as Localize from '../translations/localize';
// Import Material Design icons
import {
mdiCalendar, // For individual calendar entities
mdiCalendarMonth, // For Core Settings
mdiCalendarMultiple, // For Calendar Entities main panel
mdiCalendarToday, // For Date Display
mdiCardText, // For Event Display
mdiGestureTapHold, // For Interactions
mdiPalette, // For Appearance & Layout
mdiWeatherPartlyCloudy, // For Weather Integration
} from '@mdi/js';
// Deprecated parameter mappings for config upgrade
const DEPRECATED_CONFIG_MAP: Record<string, string> = {
max_events_to_show: 'compact_events_to_show',
vertical_line_color: 'accent_color',
horizontal_line_width: 'day_separator_width',
horizontal_line_color: 'day_separator_color',
};
const DEPRECATED_ENTITY_CONFIG_MAP: Record<string, string> = {
max_events_to_show: 'compact_events_to_show',
};
//-----------------------------------------------------------------------------
// COMPONENT DEFINITION & PROPERTIES
//-----------------------------------------------------------------------------
/**
* Calendar Card Pro Editor component
*
* This component handles the visual configuration of the card.
*/
export class CalendarCardProEditor extends LitElement {
static get styles() {
return styles;
}
@property({ attribute: false }) hass?: Types.Hass;
@property({ attribute: false }) _config?: Types.Config;
//-----------------------------------------------------------------------------
// LIFECYCLE METHODS
//-----------------------------------------------------------------------------
/**
* Called when the editor is attached to the DOM.
*/
connectedCallback(): void {
super.connectedCallback();
this._loadCustomElements();
}
/**
* Loads custom Home Assistant elements required by the editor.
*/
private async _loadCustomElements(): Promise<void> {
if (!customElements.get('ha-entity-picker')) {
try {
const huiElement = customElements.get('hui-entities-card');
if (
huiElement &&
typeof (huiElement as unknown as { getConfigElement?: () => Promise<unknown> })
.getConfigElement === 'function'
) {
await (
huiElement as unknown as { getConfigElement: () => Promise<unknown> }
).getConfigElement();
} else {
// Fallback if method doesn't exist
console.warn('Could not load ha-entity-picker: getConfigElement not available');
}
} catch (e) {
console.warn('Could not load ha-entity-picker', e);
}
}
}
//-----------------------------------------------------------------------------
// CONFIG MANAGEMENT & UPGRADE HELPERS
//-----------------------------------------------------------------------------
/**
* Sets the configuration for the editor.
* @param config Partial configuration object
*/
setConfig(config: Partial<Types.Config>): void {
this._config = { ...Config.DEFAULT_CONFIG, ...config };
}
/**
* Gets a configuration value using dot notation.
* @param path Dot notation path
* @param defaultValue Default value if not found
* @returns The config value or default
*/
getConfigValue(path: string, defaultValue?: unknown): unknown {
if (!this._config) {
return defaultValue;
}
// Handle simple top-level properties
if (!path.includes('.')) {
let value = this._config[path] ?? defaultValue;
// Handle special cases for string/boolean conversions in the UI
if (path === 'time_24h') {
// For the dropdown selection in the UI, we need string values
if (value === true) return 'true';
if (value === false) return 'false';
// 'system' stays as a string
}
return value;
}
// Handle nested properties with dot notation
const pathParts = path.split('.');
let current: unknown = this._config;
for (const part of pathParts) {
if (current === undefined || current === null) {
return defaultValue;
}
// Handle array indices
if (/^\d+$/.test(part)) {
const index = parseInt(part, 10);
if (Array.isArray(current) && index >= 0 && index < current.length) {
current = current[index];
continue;
}
return defaultValue;
}
// Handle object properties
if (
typeof current === 'object' &&
current !== null &&
part in (current as Record<string, unknown>)
) {
current = (current as Record<string, unknown>)[part];
} else {
return defaultValue;
}
}
return current ?? defaultValue;
}
/**
* Sets a configuration value using dot notation.
* @param path Dot notation path
* @param value Value to set
*/
setConfigValue(path: string, value: unknown): void {
if (!this._config) {
return;
}
// Handle special cases for string/boolean conversions
if (path === 'time_24h') {
if (value === 'true') {
value = true; // Convert string 'true' to boolean true
} else if (value === 'false') {
value = false; // Convert string 'false' to boolean false
}
// 'system' remains as string
}
// Create a deep copy of the config
const config = JSON.parse(JSON.stringify(this._config)) as Record<string, unknown>;
// Handle simple top-level properties
if (!path.includes('.')) {
if (value === undefined) {
// Only delete if undefined, preserve empty strings
delete config[path];
} else {
// Store all other values, including empty strings
config[path] = value;
}
this._fireConfigChanged(config as unknown as Types.Config);
return;
}
// Handle nested properties with dot notation
const pathParts = path.split('.');
const lastPart = pathParts.pop()!;
let current: Record<string, unknown> | unknown[] = config;
for (const part of pathParts) {
// Handle array indices
if (/^\d+$/.test(part)) {
const index = parseInt(part, 10);
if (!Array.isArray(current)) {
current = [] as unknown[];
}
while ((current as unknown[]).length <= index) {
(current as unknown[]).push({});
}
if (!(current as unknown[])[index] || typeof (current as unknown[])[index] !== 'object') {
(current as unknown[])[index] = {};
}
current = (current as unknown[])[index] as Record<string, unknown>;
continue;
}
// Handle object properties
if (
!Object.prototype.hasOwnProperty.call(current, part) ||
typeof (current as Record<string, unknown>)[part] !== 'object'
) {
(current as Record<string, unknown>)[part] = {};
}
current = (current as Record<string, unknown>)[part] as Record<string, unknown>;
}
// Set or delete the final value
if (value === undefined) {
// Only delete if undefined, preserve empty strings
delete (current as Record<string, unknown>)[lastPart];
} else {
// Store all other values, including empty strings
(current as Record<string, unknown>)[lastPart] = value;
}
this._fireConfigChanged(config as unknown as Types.Config);
}
/**
* Fires the config-changed event to notify Home Assistant of config updates.
* @param config The updated config
*/
private _fireConfigChanged(config: Types.Config): void {
// Filter out default values to minimize YAML bloat
const minimalConfig = Helpers.filterDefaultValues(
config as unknown as Record<string, unknown>,
Config.DEFAULT_CONFIG as unknown as Record<string, unknown>,
);
// Update internal config for UI rendering (keep full config)
this._config = config;
// Send only non-default values to Home Assistant
this.dispatchEvent(new CustomEvent('config-changed', { detail: { config: minimalConfig } }));
}
/**
* Finds deprecated parameters at the root config level.
* @param config The config object
* @returns Array of deprecated parameter keys
*/
private _findDeprecatedParams(config: Record<string, unknown>): string[] {
return Object.keys(DEPRECATED_CONFIG_MAP).filter((deprecated) => deprecated in config);
}
/**
* Finds deprecated parameters in entity configs.
* @param entities The entities array
* @returns Array of objects with index and param
*/
private _findDeprecatedEntityParams(entities: unknown[]): { index: number; param: string }[] {
const found: { index: number; param: string }[] = [];
entities.forEach((entity, idx) => {
if (typeof entity === 'object' && entity !== null) {
Object.keys(DEPRECATED_ENTITY_CONFIG_MAP).forEach((deprecated) => {
if (deprecated in entity) {
found.push({ index: idx, param: deprecated });
}
});
}
});
return found;
}
/**
* Upgrades the config by replacing deprecated parameters with their replacements.
*/
private _upgradeConfig(): void {
const config = { ...this._config } as Record<string, unknown>;
let changed = false;
// Root-level deprecated params
for (const [oldKey, newKey] of Object.entries(DEPRECATED_CONFIG_MAP)) {
if (oldKey in config) {
config[newKey] = config[oldKey];
delete config[oldKey];
changed = true;
}
}
// Entity-level deprecated params
if (Array.isArray(config.entities)) {
config.entities = config.entities.map((entity) => {
if (typeof entity === 'object' && entity !== null) {
const newEntity = { ...entity };
for (const [oldKey, newKey] of Object.entries(DEPRECATED_ENTITY_CONFIG_MAP)) {
if (oldKey in newEntity) {
newEntity[newKey] = newEntity[oldKey];
delete newEntity[oldKey];
changed = true;
}
}
return newEntity;
}
return entity;
});
}
if (changed) {
this._fireConfigChanged(config as unknown as Types.Config);
}
}
//-----------------------------------------------------------------------------
// TRANSLATION & LOCALIZATION HELPERS
//-----------------------------------------------------------------------------
/**
* Helper to get a translated string for the editor UI.
* @param key Translation key
* @returns Translated string
*/
private _getTranslation(key: string): string {
// Get requested language
const requestedLang = this._config?.language || this.hass?.locale?.language || 'en';
// Properly prefix editor keys unless they already have the prefix
const translationKey = key.includes('.') ? key : `editor.${key}`;
const isEditorTranslation = translationKey.startsWith('editor.');
// If this is an editor translation, check if translations exist in the requested language
// If not, fall back to English only for editor translations
const langToUse =
isEditorTranslation && !Localize.hasEditorTranslations(requestedLang) ? 'en' : requestedLang;
// Get translation using appropriate language
return Localize.translate(langToUse, translationKey as string, key) as string;
}
//-----------------------------------------------------------------------------
// INPUT/EVENT HANDLERS
//-----------------------------------------------------------------------------
/**
* Handles value changes from input elements.
* @param event Input event
*/
_valueChanged(event: Event): void {
if (!event.target) return;
event.stopPropagation();
const target = event.target as HTMLInputElement | HTMLSelectElement;
const name = target.getAttribute('name');
let value: string | boolean | number | null = target.value;
if (!name) return;
// Handle special cases for UI controls that require custom processing
if (name === 'language_mode') {
const mode = target.value;
// UI-only field that controls the real 'language' config parameter
if (mode === 'system') {
// Remove language setting when using system default
this.setConfigValue('language', undefined);
} else if (mode === 'custom') {
// Set a default language if none exists
if (!this.getConfigValue('language')) {
this.setConfigValue('language', 'en');
}
}
return; // Don't save the UI mode itself to config
} else if (name === 'height_mode') {
const mode = target.value;
// UI-only selector that manages two real config params: height and max_height
// Save the current height/max_height values before clearing them
const currentHeight = this.getConfigValue('height');
const currentMaxHeight = this.getConfigValue('max_height');
// Clear out both height settings
this.setConfigValue('height', undefined);
this.setConfigValue('max_height', undefined);
if (mode === 'fixed') {
// Use the current height value if it exists, otherwise set default
this.setConfigValue(
'height',
currentHeight && currentHeight !== 'auto' ? currentHeight : '300px',
);
} else if (mode === 'maximum') {
// Use the current max_height value if it exists and isn't "none", otherwise set default
this.setConfigValue(
'max_height',
currentMaxHeight && currentMaxHeight !== 'none' ? currentMaxHeight : '300px',
);
}
return; // Don't save the UI mode itself to config
} else if (name === 'start_date_mode') {
// UI-only field that controls the 'start_date' parameter
this._handleStartDateModeChange(target.value);
return; // Don't save the UI mode itself to config
} else if (name === 'start_date_fixed' || name === 'start_date_offset') {
// These are UI-only fields that map to the single 'start_date' parameter
this.setConfigValue('start_date', target.value);
this.requestUpdate();
return; // Don't save these UI fields to config
} else if (name === 'remove_location_country_selector') {
// UI-only field that controls the 'remove_location_country' parameter
// The actual value is set by the custom change handler in the select field
return; // Don't save this UI-only field to config
} else if (name === 'show_week_numbers' && value === 'null') {
// Special handling for show_week_numbers to convert 'null' string to actual null
// This ensures the default option is properly stored as null rather than a string
value = null;
}
// Handle switch/checkbox values
if (target.tagName === 'HA-SWITCH') {
value = (target as HTMLInputElement).checked;
}
// Handle numeric inputs
if (target.getAttribute('type') === 'number' && value !== '') {
value = parseFloat(value as string);
}
this.setConfigValue(name, value);
}
/**
* Handles changes to service data fields (JSON inputs).
* @param event Input event
*/
_serviceDataChanged(event: Event): void {
if (!event.target) return;
const target = event.target as HTMLInputElement;
const name = target.getAttribute('name');
if (!name) return;
let value = target.value;
try {
// Parse JSON and store as object
value = value ? JSON.parse(value) : {};
this.setConfigValue(name, value);
} catch {
// Invalid JSON - don't update
}
}
/**
* Determines the mode (default/fixed/offset) from a start_date value
* @returns 'default' | 'fixed' | 'offset'
*/
private _getStartDateMode(): 'default' | 'fixed' | 'offset' {
const value = this.getConfigValue('start_date', '');
// Ensure we're working with a string
const strValue = value !== undefined && value !== null ? String(value) : '';
if (!strValue || strValue === '') return 'default';
if (/^\d{4}-\d{2}-\d{2}$/.test(strValue)) return 'fixed';
if (/^[+-]?\d+$/.test(strValue)) return 'offset';
return 'fixed'; // fallback for legacy/unknown
}
/**
* Gets the appropriate value for each start_date input mode
* @param mode The current input mode ('fixed' or 'offset')
* @returns The appropriate value for the selected mode
*/
private _getStartDateValue(mode: 'fixed' | 'offset'): string {
const value = this.getConfigValue('start_date', '');
// Ensure we're working with a string
const strValue = value !== undefined && value !== null ? String(value) : '';
if (mode === 'fixed' && /^\d{4}-\d{2}-\d{2}$/.test(strValue)) return strValue;
if (mode === 'offset' && /^[+-]?\d+$/.test(strValue)) return strValue;
return '';
}
/**
* Handles changes to the start_date mode
* @param mode The selected mode
*/
private _handleStartDateModeChange(mode: string): void {
if (mode === 'default') {
this.setConfigValue('start_date', undefined);
} else if (mode === 'fixed') {
// Set to today as default for fixed date
const today = new Date();
const yyyy = today.getFullYear();
const mm = String(today.getMonth() + 1).padStart(2, '0');
const dd = String(today.getDate()).padStart(2, '0');
this.setConfigValue('start_date', `${yyyy}-${mm}-${dd}`);
} else if (mode === 'offset') {
this.setConfigValue('start_date', '+0');
}
}
//-----------------------------------------------------------------------------
// MAIN RENDER METHOD
//-----------------------------------------------------------------------------
/**
* Renders the editor UI.
* @returns Lit template for the editor
*/
render() {
if (!this.hass || !this._config) {
return html``;
}
// Config upgrade notice
const deprecatedParams = this._findDeprecatedParams(
this._config as unknown as Record<string, unknown>,
);
const deprecatedEntityParams = this._findDeprecatedEntityParams(
(this._config?.entities ?? []) as unknown[],
);
const hasDeprecated = deprecatedParams.length > 0 || deprecatedEntityParams.length > 0;
const upgradeNotice = hasDeprecated
? html`
<div style="border-radius: 8px; overflow: hidden;">
<ha-alert alert-type="warning">
<div style="height: 6px"></div>
<b>${this._getTranslation('editor.deprecated_config_detected')}</b><br />
${this._getTranslation('editor.deprecated_config_explanation')}<br />
<span style="color: var(--warning-color); font-size: 0.95em;">
${this._getTranslation('editor.deprecated_config_update_hint')}
</span>
<div style="text-align:center;">
<ha-button @click="${() => this._upgradeConfig()}">
<ha-icon icon="mdi:autorenew"></ha-icon>
${this._getTranslation('editor.update_config')}
</ha-button>
</div>
</ha-alert>
</div>
`
: null;
return html`
${upgradeNotice}
<div class="card-config">
<!-- CALENDAR ENTITIES -->
${this.addExpansionPanel(
this._getTranslation('calendar_entities'),
mdiCalendarMultiple,
html` ${this._renderCalendarEntities()} `,
true, // expanded by default
)}
<!-- CORE SETTINGS -->
${this.addExpansionPanel(
this._getTranslation('core_settings'),
mdiCalendarMonth,
html`
<!-- Display Range -->
<h3>${this._getTranslation('time_range')}</h3>
<div class="helper-text">${this._getTranslation('time_range_note')}</div>
${this.addTextField('days_to_show', this._getTranslation('days_to_show'), 'number')}
<div class="helper-text">${this._getTranslation('days_to_show_note')}</div>
${this.addSelectField(
'start_date_mode',
this._getTranslation('start_date_mode'),
[
{ value: 'default', label: this._getTranslation('start_date_mode_default') },
{ value: 'fixed', label: this._getTranslation('start_date_mode_fixed') },
{ value: 'offset', label: this._getTranslation('start_date_mode_offset') },
],
false,
String(this._getStartDateMode()),
(value) => {
this._handleStartDateModeChange(value);
this.requestUpdate();
},
)}
${(() => {
const mode = this._getStartDateMode();
if (mode === 'fixed') {
return this.addDateField(
'start_date_fixed',
this._getTranslation('start_date_fixed'),
this._getStartDateValue('fixed'),
);
} else if (mode === 'offset') {
return html`
${this.addTextField(
'start_date_offset',
this._getTranslation('start_date_offset'),
'text',
this._getStartDateValue('offset'),
)}
<div class="helper-text">${this._getTranslation('start_date_offset_note')}</div>
`;
}
return html``;
})()}
<!-- Compact Mode -->
<h3>${this._getTranslation('compact_mode')}</h3>
<div class="helper-text">${this._getTranslation('compact_mode_note')}</div>
${this.addTextField(
'compact_days_to_show',
this._getTranslation('compact_days_to_show'),
'number',
)}
${this.addTextField(
'compact_events_to_show',
this._getTranslation('compact_events_to_show'),
'number',
)}
${this.addBooleanField(
'compact_events_complete_days',
this._getTranslation('compact_events_complete_days'),
)}
<div class="helper-text">
${this._getTranslation('compact_events_complete_days_note')}
</div>
<!-- Event Visibility -->
<h3>${this._getTranslation('event_visibility')}</h3>
${this.addBooleanField('show_past_events', this._getTranslation('show_past_events'))}
${this.addBooleanField('show_empty_days', this._getTranslation('show_empty_days'))}
${this.addBooleanField('filter_duplicates', this._getTranslation('filter_duplicates'))}
<!-- Language & Time Formats -->
<h3>${this._getTranslation('language_time_formats')}</h3>
${this.addSelectField(
'language_mode',
this._getTranslation('language_mode'),
[
{ value: 'system', label: this._getTranslation('system') },
{ value: 'custom', label: this._getTranslation('custom') },
],
false,
this.getConfigValue('language') !== undefined ? 'custom' : 'system',
)}
${(() => {
return this.getConfigValue('language') !== undefined
? html`
${this.addTextField('language', this._getTranslation('language_code'))}
<div class="helper-text">${this._getTranslation('language_code_note')}</div>
`
: html``;
})()}
${this.addSelectField('time_24h', this._getTranslation('time_24h'), [
{ value: 'system', label: this._getTranslation('system') },
{ value: 'true', label: this._getTranslation('24h') },
{ value: 'false', label: this._getTranslation('12h') },
])}
`,
)}
<!-- APPEARANCE & LAYOUT -->
${this.addExpansionPanel(
this._getTranslation('appearance_layout'),
mdiPalette,
html`
<!-- Title Styling -->
<h3>${this._getTranslation('title_styling')}</h3>
${this.addTextField('title', this._getTranslation('title'))}
${this.addTextField('title_font_size', this._getTranslation('title_font_size'))}
${this.addTextField('title_color', this._getTranslation('title_color'))}
<!-- Card Styling -->
<h3>${this._getTranslation('card_styling')}</h3>
${this.addTextField('background_color', this._getTranslation('background_color'))}
${this.addSelectField(
'height_mode',
this._getTranslation('height_mode'),
[
{ value: 'auto', label: this._getTranslation('auto') },
{ value: 'fixed', label: this._getTranslation('fixed') },
{ value: 'maximum', label: this._getTranslation('maximum') },
],
false,
(() => {
if (
this.getConfigValue('height') !== undefined &&
this.getConfigValue('height') !== 'auto'
) {
return 'fixed';
} else if (
this.getConfigValue('max_height') !== undefined &&
this.getConfigValue('max_height') !== 'none'
) {
return 'maximum';
}
return 'auto';
})(),
)}
${(() => {
if (
this.getConfigValue('height') !== undefined &&
this.getConfigValue('height') !== 'auto'
) {
return html`
${this.addTextField('height', this._getTranslation('height_value'))}
<div class="helper-text">${this._getTranslation('fixed_height_note')}</div>
`;
} else if (
this.getConfigValue('max_height') !== undefined &&
this.getConfigValue('max_height') !== 'none'
) {
return html`
${this.addTextField('max_height', this._getTranslation('height_value'))}
<div class="helper-text">${this._getTranslation('max_height_note')}</div>
`;
}
return html``;
})()}
<!-- Event Styling -->
<h3>${this._getTranslation('event_styling')}</h3>
${this.addTextField('accent_color', this._getTranslation('accent_color'))}
${this.addTextField(
'event_background_opacity',
this._getTranslation('event_background_opacity'),
'number',
)}
${this.addTextField('vertical_line_width', this._getTranslation('vertical_line_width'))}
<!-- Spacing & Alignment -->
<h3>${this._getTranslation('spacing_alignment')}</h3>
${this.addTextField('day_spacing', this._getTranslation('day_spacing'))}
${this.addTextField('event_spacing', this._getTranslation('event_spacing'))}
${this.addTextField(
'additional_card_spacing',
this._getTranslation('additional_card_spacing'),
)}
`,
)}
<!-- DATE DISPLAY -->
${this.addExpansionPanel(
this._getTranslation('date_display'),
mdiCalendarToday,
html`
<!-- Date Column Formatting -->
<h3>${this._getTranslation('vertical_alignment')}</h3>
${this.addSelectField(
'date_vertical_alignment',
this._getTranslation('date_vertical_alignment'),
[
{ value: 'top', label: this._getTranslation('top') },
{ value: 'middle', label: this._getTranslation('middle') },
{ value: 'bottom', label: this._getTranslation('bottom') },
],
)}
<!-- Date Column Formatting -->
<h3>${this._getTranslation('date_formatting')}</h3>
<!-- Weekday Formatting -->
<h5>${this._getTranslation('weekday_font')}</h5>
${this.addTextField('weekday_font_size', this._getTranslation('weekday_font_size'))}
${this.addTextField('weekday_color', this._getTranslation('weekday_color'))}
<!-- Day Formatting -->
<h5>${this._getTranslation('day_font')}</h5>
${this.addTextField('day_font_size', this._getTranslation('day_font_size'))}
${this.addTextField('day_color', this._getTranslation('day_color'))}
<!-- Month Formatting -->
<h5>${this._getTranslation('month_font')}</h5>
${this.addBooleanField('show_month', this._getTranslation('show_month'))}
${this.addTextField('month_font_size', this._getTranslation('month_font_size'))}
${this.addTextField('month_color', this._getTranslation('month_color'))}
<!-- Weekend Highlighting -->
<h5>${this._getTranslation('weekend_highlighting')}</h5>
${this.addTextField(
'weekend_weekday_color',
this._getTranslation('weekend_weekday_color'),
)}
${this.addTextField('weekend_day_color', this._getTranslation('weekend_day_color'))}
${this.addTextField('weekend_month_color', this._getTranslation('weekend_month_color'))}
<!-- Today Highlighting -->
<h5>${this._getTranslation('today_highlighting')}</h5>
${this.addTextField('today_weekday_color', this._getTranslation('today_weekday_color'))}
${this.addTextField('today_day_color', this._getTranslation('today_day_color'))}
${this.addTextField('today_month_color', this._getTranslation('today_month_color'))}
<!-- Today Indicator -->
<h3>${this._getTranslation('today_indicator')}</h3>
${this.addTodayIndicatorField(
'today_indicator',
this._getTranslation('today_indicator'),
)}
${(() => {
const indicatorValue = this.getConfigValue('today_indicator');
// Only show additional fields if indicator is enabled (not false, undefined, or "none")
if (indicatorValue && indicatorValue !== 'none') {
return html`
${this.addTextField(
'today_indicator_position',
this._getTranslation('today_indicator_position'),
)}
${this.addTextField(
'today_indicator_color',
this._getTranslation('today_indicator_color'),
)}
${this.addTextField(
'today_indicator_size',
this._getTranslation('today_indicator_size'),
)}
`;
}
return html``;
})()}
<!-- Week Numbers & Separators -->
<h3>${this._getTranslation('week_numbers_separators')}</h3>
<!-- Week Numbers -->
<h5>${this._getTranslation('week_numbers')}</h5>
${this.addSelectField('first_day_of_week', this._getTranslation('first_day_of_week'), [
{ value: 'system', label: this._getTranslation('system') },
{ value: 'sunday', label: this._getTranslation('sunday') },
{ value: 'monday', label: this._getTranslation('monday') },
])}
${this.addSelectField('show_week_numbers', this._getTranslation('show_week_numbers'), [
{ value: 'null', label: this._getTranslation('none') },
{ value: 'iso', label: 'ISO' },
{ value: 'simple', label: this._getTranslation('simple') },
])}
${(() => {
const weekNumbersValue = this.getConfigValue('show_week_numbers');
if (weekNumbersValue === 'iso') {
return html`<div class="helper-text">
${this._getTranslation('week_number_note_iso')}
</div>`;
} else if (weekNumbersValue === 'simple') {
return html`<div class="helper-text">
${this._getTranslation('week_number_note_simple')}
</div>`;
}
return html``;
})()}
${(() => {
const weekNumbersEnabled = this.getConfigValue('show_week_numbers');
if (weekNumbersEnabled && weekNumbersEnabled !== 'null') {
return html`
${this.addBooleanField(
'show_current_week_number',
this._getTranslation('show_current_week_number'),
)}
${this.addTextField(
'week_number_font_size',
this._getTranslation('week_number_font_size'),
)}
${this.addTextField(
'week_number_color',
this._getTranslation('week_number_color'),
)}
${this.addTextField(
'week_number_background_color',
this._getTranslation('week_number_background_color'),
)}
`;
}
return html``;
})()}
<!-- Day Separator -->
<h5>${this._getTranslation('day_separator')}</h5>
${this.addBooleanField(
'day_separator_toggle',
this._getTranslation('show_day_separator'),
this.getConfigValue('day_separator_width') !== '0px' &&
this.getConfigValue('day_separator_width') !== '0',
(e) => {
// Get the toggle state from the event
const checked = (e.target as HTMLInputElement).checked;
// Set width based on toggle state
if (checked) {
// If toggled ON, set default width
this.setConfigValue('day_separator_width', '1px');
} else {
// If toggled OFF, set to 0px to hide
this.setConfigValue('day_separator_width', '0px');
}
},
true, // UI-only
)}
${(() => {
// Only show width and color fields if separator is enabled (width is not 0px)
const separatorEnabled =
this.getConfigValue('day_separator_width') !== '0px' &&
this.getConfigValue('day_separator_width') !== '0';
if (!separatorEnabled) {
return html``;
}
return html`
${this.addTextField(
'day_separator_width',
this._getTranslation('day_separator_width'),
)}
${this.addTextField(
'day_separator_color',
this._getTranslation('day_separator_color'),
)}
`;
})()}
<!-- Week Separator -->
<h5>${this._getTranslation('week_separator')}</h5>
${this.addBooleanField(
'week_separator_toggle',
this._getTranslation('show_week_separator'),
this.getConfigValue('week_separator_width') !== '0px' &&
this.getConfigValue('week_separator_width') !== '0',
(e) => {
// Get the toggle state from the event
const checked = (e.target as HTMLInputElement).checked;
// Set width based on toggle state
if (checked) {
// If toggled ON, set default width
this.setConfigValue('week_separator_width', '1px');
} else {
// If toggled OFF, set to 0px to hide
this.setConfigValue('week_separator_width', '0px');
}
},
true, // UI-only
)}
${(() => {
// Only show width and color fields if separator is enabled (width is not 0px)
const separatorEnabled =
this.getConfigValue('week_separator_width') !== '0px' &&
this.getConfigValue('week_separator_width') !== '0';
if (!separatorEnabled) {
return html``;
}
return html`
${this.addTextField(
'week_separator_width',
this._getTranslation('week_separator_width'),
)}
${this.addTextField(
'week_separator_color',
this._getTranslation('week_separator_color'),
)}
`;
})()}
<!-- Month Separator -->
<h5>${this._getTranslation('month_separator')}</h5>
${this.addBooleanField(
'month_separator_toggle',
this._getTranslation('show_month_separator'),
this.getConfigValue('month_separator_width') !== '0px' &&
this.getConfigValue('month_separator_width') !== '0',
(e) => {
// Get the toggle state from the event
const checked = (e.target as HTMLInputElement).checked;
// Set width based on toggle state
if (checked) {
// If toggled ON, set default width
this.setConfigValue('month_separator_width', '1px');
} else {
// If toggled OFF, set to 0px to hide
this.setConfigValue('month_separator_width', '0px');