scb-wc-test 0.1.128 → 0.1.129
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/blazor/ScbBlazorInteropBase.cs +137 -0
- package/blazor/scb-blazor-bridge.js +193 -0
- package/mvc/components/scb-calendar/scb-calendar.js +20 -20
- package/mvc/scb-blazor-bridge.js +193 -0
- package/package.json +2 -2
- package/scb-calendar/scb-calendar.d.ts +6 -0
- package/scb-calendar/scb-calendar.js +183 -134
- package/scb-wc-test.bundle.js +171 -171
|
@@ -70,6 +70,12 @@ namespace ScbBlazorDemo
|
|
|
70
70
|
// Alla kalenderkort på sidan
|
|
71
71
|
protected CalendarState[] Calendars { get; private set; } = Array.Empty<CalendarState>();
|
|
72
72
|
|
|
73
|
+
// Enskild kalender (scb-calendar) för scenarion där man bara bryr sig om en
|
|
74
|
+
protected CalendarViewState CalendarView { get; private set; } = new();
|
|
75
|
+
|
|
76
|
+
// Alla kalendrar (scb-calendar) på sidan
|
|
77
|
+
protected CalendarViewState[] CalendarViews { get; private set; } = Array.Empty<CalendarViewState>();
|
|
78
|
+
|
|
73
79
|
// Dialog (scb-dialog)
|
|
74
80
|
protected DialogState Dialog { get; private set; } = new();
|
|
75
81
|
|
|
@@ -426,6 +432,61 @@ namespace ScbBlazorDemo
|
|
|
426
432
|
Calendars = Array.Empty<CalendarState>();
|
|
427
433
|
}
|
|
428
434
|
|
|
435
|
+
// Enskild kalender-vy: baseras på första kalendern om en lista finns, annars på state.CalendarView
|
|
436
|
+
if (state.CalendarViews is not null && state.CalendarViews.Length > 0)
|
|
437
|
+
{
|
|
438
|
+
var dto = state.CalendarViews[0];
|
|
439
|
+
CalendarView.DisplayYear = dto.DisplayYear;
|
|
440
|
+
CalendarView.DisplayMonth = dto.DisplayMonth;
|
|
441
|
+
CalendarView.SelectedDate = dto.SelectedDate ?? string.Empty;
|
|
442
|
+
CalendarView.Lang = dto.Lang ?? string.Empty;
|
|
443
|
+
CalendarView.DisableWeekend = dto.DisableWeekend;
|
|
444
|
+
CalendarView.PublicHolidays = dto.PublicHolidays;
|
|
445
|
+
}
|
|
446
|
+
else if (state.CalendarView is not null)
|
|
447
|
+
{
|
|
448
|
+
CalendarView.DisplayYear = state.CalendarView.DisplayYear;
|
|
449
|
+
CalendarView.DisplayMonth = state.CalendarView.DisplayMonth;
|
|
450
|
+
CalendarView.SelectedDate = state.CalendarView.SelectedDate ?? string.Empty;
|
|
451
|
+
CalendarView.Lang = state.CalendarView.Lang ?? string.Empty;
|
|
452
|
+
CalendarView.DisableWeekend = state.CalendarView.DisableWeekend;
|
|
453
|
+
CalendarView.PublicHolidays = state.CalendarView.PublicHolidays;
|
|
454
|
+
}
|
|
455
|
+
else
|
|
456
|
+
{
|
|
457
|
+
CalendarView.DisplayYear = 0;
|
|
458
|
+
CalendarView.DisplayMonth = 0;
|
|
459
|
+
CalendarView.SelectedDate = string.Empty;
|
|
460
|
+
CalendarView.Lang = string.Empty;
|
|
461
|
+
CalendarView.DisableWeekend = false;
|
|
462
|
+
CalendarView.PublicHolidays = false;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
// Lista med alla calendar views
|
|
466
|
+
if (state.CalendarViews is not null && state.CalendarViews.Length > 0)
|
|
467
|
+
{
|
|
468
|
+
var views = new CalendarViewState[state.CalendarViews.Length];
|
|
469
|
+
for (var i = 0; i < state.CalendarViews.Length; i++)
|
|
470
|
+
{
|
|
471
|
+
var dto = state.CalendarViews[i];
|
|
472
|
+
views[i] = new CalendarViewState
|
|
473
|
+
{
|
|
474
|
+
DisplayYear = dto.DisplayYear,
|
|
475
|
+
DisplayMonth = dto.DisplayMonth,
|
|
476
|
+
SelectedDate = dto.SelectedDate ?? string.Empty,
|
|
477
|
+
Lang = dto.Lang ?? string.Empty,
|
|
478
|
+
DisableWeekend = dto.DisableWeekend,
|
|
479
|
+
PublicHolidays = dto.PublicHolidays
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
CalendarViews = views;
|
|
484
|
+
}
|
|
485
|
+
else
|
|
486
|
+
{
|
|
487
|
+
CalendarViews = Array.Empty<CalendarViewState>();
|
|
488
|
+
}
|
|
489
|
+
|
|
429
490
|
// Dialog
|
|
430
491
|
if (state.Dialog is not null)
|
|
431
492
|
{
|
|
@@ -961,6 +1022,57 @@ namespace ScbBlazorDemo
|
|
|
961
1022
|
return JS.InvokeVoidAsync("SCBBlazor.setStepperActiveIndexById", id ?? string.Empty, activeIndex).AsTask();
|
|
962
1023
|
}
|
|
963
1024
|
|
|
1025
|
+
// Calendar (scb-calendar): global och id-baserad variant
|
|
1026
|
+
protected Task SetCalendarDisplayMonthYearAsync(int year, int month)
|
|
1027
|
+
{
|
|
1028
|
+
return JS.InvokeVoidAsync("SCBBlazor.setCalendarDisplayMonthYear", year, month).AsTask();
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
protected Task SetCalendarSelectedDateAsync(string date)
|
|
1032
|
+
{
|
|
1033
|
+
return JS.InvokeVoidAsync("SCBBlazor.setCalendarSelectedDate", date ?? string.Empty).AsTask();
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
protected Task SetCalendarDisableWeekendAsync(bool disableWeekend)
|
|
1037
|
+
{
|
|
1038
|
+
return JS.InvokeVoidAsync("SCBBlazor.setCalendarDisableWeekend", disableWeekend).AsTask();
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
protected Task SetCalendarPublicHolidaysAsync(bool publicHolidays)
|
|
1042
|
+
{
|
|
1043
|
+
return JS.InvokeVoidAsync("SCBBlazor.setCalendarPublicHolidays", publicHolidays).AsTask();
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
protected Task SetCalendarLangAsync(string lang)
|
|
1047
|
+
{
|
|
1048
|
+
return JS.InvokeVoidAsync("SCBBlazor.setCalendarLang", lang ?? string.Empty).AsTask();
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
protected Task SetCalendarDisplayMonthYearByIdAsync(string id, int year, int month)
|
|
1052
|
+
{
|
|
1053
|
+
return JS.InvokeVoidAsync("SCBBlazor.setCalendarDisplayMonthYearById", id ?? string.Empty, year, month).AsTask();
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
protected Task SetCalendarSelectedDateByIdAsync(string id, string date)
|
|
1057
|
+
{
|
|
1058
|
+
return JS.InvokeVoidAsync("SCBBlazor.setCalendarSelectedDateById", id ?? string.Empty, date ?? string.Empty).AsTask();
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
protected Task SetCalendarDisableWeekendByIdAsync(string id, bool disableWeekend)
|
|
1062
|
+
{
|
|
1063
|
+
return JS.InvokeVoidAsync("SCBBlazor.setCalendarDisableWeekendById", id ?? string.Empty, disableWeekend).AsTask();
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
protected Task SetCalendarPublicHolidaysByIdAsync(string id, bool publicHolidays)
|
|
1067
|
+
{
|
|
1068
|
+
return JS.InvokeVoidAsync("SCBBlazor.setCalendarPublicHolidaysById", id ?? string.Empty, publicHolidays).AsTask();
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
protected Task SetCalendarLangByIdAsync(string id, string lang)
|
|
1072
|
+
{
|
|
1073
|
+
return JS.InvokeVoidAsync("SCBBlazor.setCalendarLangById", id ?? string.Empty, lang ?? string.Empty).AsTask();
|
|
1074
|
+
}
|
|
1075
|
+
|
|
964
1076
|
// Pagination: index-baserad och id-baserad variant
|
|
965
1077
|
protected Task SetPaginationPageAsync(int paginationIndex, int page)
|
|
966
1078
|
{
|
|
@@ -1174,6 +1286,16 @@ namespace ScbBlazorDemo
|
|
|
1174
1286
|
public bool ShowMedia { get; set; }
|
|
1175
1287
|
}
|
|
1176
1288
|
|
|
1289
|
+
protected sealed class CalendarViewState
|
|
1290
|
+
{
|
|
1291
|
+
public int DisplayYear { get; set; }
|
|
1292
|
+
public int DisplayMonth { get; set; }
|
|
1293
|
+
public string SelectedDate { get; set; } = string.Empty;
|
|
1294
|
+
public string Lang { get; set; } = string.Empty;
|
|
1295
|
+
public bool DisableWeekend { get; set; }
|
|
1296
|
+
public bool PublicHolidays { get; set; }
|
|
1297
|
+
}
|
|
1298
|
+
|
|
1177
1299
|
protected sealed class DialogState
|
|
1178
1300
|
{
|
|
1179
1301
|
public bool Open { get; set; }
|
|
@@ -1365,6 +1487,10 @@ namespace ScbBlazorDemo
|
|
|
1365
1487
|
|
|
1366
1488
|
public CalendarDto[] Calendars { get; set; } = Array.Empty<CalendarDto>();
|
|
1367
1489
|
|
|
1490
|
+
public CalendarViewDto CalendarView { get; set; } = new();
|
|
1491
|
+
|
|
1492
|
+
public CalendarViewDto[] CalendarViews { get; set; } = Array.Empty<CalendarViewDto>();
|
|
1493
|
+
|
|
1368
1494
|
public DialogDto Dialog { get; set; } = new();
|
|
1369
1495
|
|
|
1370
1496
|
public NotificationDto[] Notifications { get; set; } = Array.Empty<NotificationDto>();
|
|
@@ -1515,6 +1641,17 @@ namespace ScbBlazorDemo
|
|
|
1515
1641
|
public bool ShowMedia { get; set; }
|
|
1516
1642
|
}
|
|
1517
1643
|
|
|
1644
|
+
|
|
1645
|
+
private sealed class CalendarViewDto
|
|
1646
|
+
{
|
|
1647
|
+
public int DisplayYear { get; set; }
|
|
1648
|
+
public int DisplayMonth { get; set; }
|
|
1649
|
+
public string? SelectedDate { get; set; }
|
|
1650
|
+
public string? Lang { get; set; }
|
|
1651
|
+
public bool DisableWeekend { get; set; }
|
|
1652
|
+
public bool PublicHolidays { get; set; }
|
|
1653
|
+
}
|
|
1654
|
+
|
|
1518
1655
|
private sealed class DialogDto
|
|
1519
1656
|
{
|
|
1520
1657
|
public bool Open { get; set; }
|
|
@@ -238,6 +238,23 @@
|
|
|
238
238
|
prop: 'mediaHeight',
|
|
239
239
|
},
|
|
240
240
|
|
|
241
|
+
// scb-calendar
|
|
242
|
+
{
|
|
243
|
+
sel: 'scb-calendar',
|
|
244
|
+
from: 'scb-calendar-month-change',
|
|
245
|
+
to: 'calendarmonthchange',
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
sel: 'scb-calendar',
|
|
249
|
+
from: 'scb-calendar-select',
|
|
250
|
+
to: 'calendarselect',
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
sel: 'scb-calendar',
|
|
254
|
+
from: 'change',
|
|
255
|
+
to: 'calendareventschange',
|
|
256
|
+
},
|
|
257
|
+
|
|
241
258
|
// scb-card
|
|
242
259
|
{
|
|
243
260
|
sel: 'scb-card',
|
|
@@ -724,6 +741,14 @@
|
|
|
724
741
|
{ sel: 'scb-calendar-card', attr: 'variant', to: 'variantchange' },
|
|
725
742
|
{ sel: 'scb-calendar-card', attr: 'show-media', to: 'showmediachange' },
|
|
726
743
|
|
|
744
|
+
// scb-calendar attribut som ska trigga state-refresh
|
|
745
|
+
{ sel: 'scb-calendar', attr: 'display-year', to: 'calendarmonthchange' },
|
|
746
|
+
{ sel: 'scb-calendar', attr: 'display-month', to: 'calendarmonthchange' },
|
|
747
|
+
{ sel: 'scb-calendar', attr: 'selected-date', to: 'calendarselect' },
|
|
748
|
+
{ sel: 'scb-calendar', attr: 'disable-weekend', to: 'calendardisplaychange' },
|
|
749
|
+
{ sel: 'scb-calendar', attr: 'public-holidays', to: 'calendardisplaychange' },
|
|
750
|
+
{ sel: 'scb-calendar', attr: 'lang', to: 'calendardisplaychange' },
|
|
751
|
+
|
|
727
752
|
// scb-keyfigure-card attribut som ska trigga state-refresh
|
|
728
753
|
{ sel: 'scb-keyfigure-card', attr: 'keyfigure', to: 'keyfigurechange' },
|
|
729
754
|
{ sel: 'scb-keyfigure-card', attr: 'subtitle', to: 'subtitlechange' },
|
|
@@ -1027,6 +1052,7 @@ window.SCBBlazor.getState = function () {
|
|
|
1027
1052
|
const segmented = document.querySelector('scb-segmented-button');
|
|
1028
1053
|
const tabs = document.querySelectorAll('scb-tabs');
|
|
1029
1054
|
const calendars = document.querySelectorAll('scb-calendar-card');
|
|
1055
|
+
const calendarViews = document.querySelectorAll('scb-calendar');
|
|
1030
1056
|
const cards = document.querySelectorAll('scb-card');
|
|
1031
1057
|
const keyfigures = document.querySelectorAll('scb-keyfigure-card');
|
|
1032
1058
|
const menu = document.querySelector('scb-menu');
|
|
@@ -1221,6 +1247,67 @@ window.SCBBlazor.getState = function () {
|
|
|
1221
1247
|
showMedia: false,
|
|
1222
1248
|
};
|
|
1223
1249
|
|
|
1250
|
+
// Alla scb-calendar på sidan
|
|
1251
|
+
const calendarViewsState = Array.from(calendarViews).map((c) => {
|
|
1252
|
+
const anyC = c;
|
|
1253
|
+
const now = new Date();
|
|
1254
|
+
let displayYear = now.getFullYear();
|
|
1255
|
+
let displayMonth = now.getMonth() + 1;
|
|
1256
|
+
|
|
1257
|
+
if (typeof anyC.displayYear === 'number') {
|
|
1258
|
+
displayYear = anyC.displayYear;
|
|
1259
|
+
} else {
|
|
1260
|
+
const yAttr = c.getAttribute('display-year');
|
|
1261
|
+
if (yAttr != null) {
|
|
1262
|
+
const parsed = parseInt(yAttr, 10);
|
|
1263
|
+
if (!Number.isNaN(parsed)) displayYear = parsed;
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
|
|
1267
|
+
if (typeof anyC.displayMonth === 'number') {
|
|
1268
|
+
displayMonth = anyC.displayMonth;
|
|
1269
|
+
} else {
|
|
1270
|
+
const mAttr = c.getAttribute('display-month');
|
|
1271
|
+
if (mAttr != null) {
|
|
1272
|
+
const parsed = parseInt(mAttr, 10);
|
|
1273
|
+
if (!Number.isNaN(parsed)) displayMonth = parsed;
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
const selectedDate =
|
|
1278
|
+
(anyC.selectedDate ?? c.getAttribute('selected-date') ?? '') + '';
|
|
1279
|
+
const lang = (anyC.lang ?? c.getAttribute('lang') ?? '') + '';
|
|
1280
|
+
const disableWeekend =
|
|
1281
|
+
typeof anyC.disableWeekend === 'boolean'
|
|
1282
|
+
? anyC.disableWeekend
|
|
1283
|
+
: c.hasAttribute('disable-weekend');
|
|
1284
|
+
const publicHolidays =
|
|
1285
|
+
typeof anyC.publicHolidays === 'boolean'
|
|
1286
|
+
? anyC.publicHolidays
|
|
1287
|
+
: c.hasAttribute('public-holidays');
|
|
1288
|
+
|
|
1289
|
+
return {
|
|
1290
|
+
displayYear,
|
|
1291
|
+
displayMonth,
|
|
1292
|
+
selectedDate,
|
|
1293
|
+
lang,
|
|
1294
|
+
disableWeekend,
|
|
1295
|
+
publicHolidays,
|
|
1296
|
+
};
|
|
1297
|
+
});
|
|
1298
|
+
|
|
1299
|
+
const calendarViewState =
|
|
1300
|
+
calendarViewsState.length > 0
|
|
1301
|
+
? calendarViewsState[0]
|
|
1302
|
+
: {
|
|
1303
|
+
displayYear: new Date().getFullYear(),
|
|
1304
|
+
displayMonth: new Date().getMonth() + 1,
|
|
1305
|
+
selectedDate: '',
|
|
1306
|
+
lang: 'sv',
|
|
1307
|
+
disableWeekend: false,
|
|
1308
|
+
publicHolidays: true,
|
|
1309
|
+
};
|
|
1310
|
+
|
|
1224
1311
|
// Alla scb-card på sidan
|
|
1225
1312
|
const cardsState = Array.from(cards).map((card) => ({
|
|
1226
1313
|
type: card.getAttribute('type') || '',
|
|
@@ -1886,6 +1973,8 @@ const subMenusState = Array.from(subMenus).map((sm) => {
|
|
|
1886
1973
|
tabs: tabsState,
|
|
1887
1974
|
calendar: calendarState,
|
|
1888
1975
|
calendars: calendarsState,
|
|
1976
|
+
calendarView: calendarViewState,
|
|
1977
|
+
calendarViews: calendarViewsState,
|
|
1889
1978
|
cards: cardsState,
|
|
1890
1979
|
keyfigures: keyfiguresState,
|
|
1891
1980
|
menu: menuState,
|
|
@@ -1932,6 +2021,11 @@ window.SCBBlazor.registerScbEventHandlers = function (dotNetRef) {
|
|
|
1932
2021
|
'supportingtextchange',
|
|
1933
2022
|
'variantchange',
|
|
1934
2023
|
'showmediachange',
|
|
2024
|
+
// calendar
|
|
2025
|
+
'calendarmonthchange',
|
|
2026
|
+
'calendarselect',
|
|
2027
|
+
'calendareventschange',
|
|
2028
|
+
'calendardisplaychange',
|
|
1935
2029
|
// keyfigure-card
|
|
1936
2030
|
'keyfigurechange',
|
|
1937
2031
|
'cardhrefchange',
|
|
@@ -2390,6 +2484,105 @@ window.SCBBlazor.registerScbEventHandlers = function (dotNetRef) {
|
|
|
2390
2484
|
dispatchChange(tabs, 'tabschange', { activeIndex: i });
|
|
2391
2485
|
};
|
|
2392
2486
|
|
|
2487
|
+
// Calendar
|
|
2488
|
+
|
|
2489
|
+
api.setCalendarDisplayMonthYear = function (calendarIndex, displayYear, displayMonth) {
|
|
2490
|
+
const cal = getByIndex('scb-calendar', calendarIndex);
|
|
2491
|
+
if (!cal) return;
|
|
2492
|
+
const y = typeof displayYear === 'number' ? displayYear : parseInt(displayYear, 10);
|
|
2493
|
+
const m = typeof displayMonth === 'number' ? displayMonth : parseInt(displayMonth, 10);
|
|
2494
|
+
if (Number.isNaN(y) || Number.isNaN(m) || m < 1 || m > 12) return;
|
|
2495
|
+
const anyCal = cal;
|
|
2496
|
+
try {
|
|
2497
|
+
anyCal.displayYear = y;
|
|
2498
|
+
anyCal.displayMonth = m;
|
|
2499
|
+
} catch (_) {}
|
|
2500
|
+
cal.setAttribute('display-year', String(y));
|
|
2501
|
+
cal.setAttribute('display-month', String(m));
|
|
2502
|
+
dispatchChange(cal, 'calendarmonthchange', { displayYear: y, displayMonth: m });
|
|
2503
|
+
};
|
|
2504
|
+
|
|
2505
|
+
api.setCalendarDisplayMonthYearById = function (id, displayYear, displayMonth) {
|
|
2506
|
+
const cal = getById(id, 'scb-calendar');
|
|
2507
|
+
if (!cal) return;
|
|
2508
|
+
const y = typeof displayYear === 'number' ? displayYear : parseInt(displayYear, 10);
|
|
2509
|
+
const m = typeof displayMonth === 'number' ? displayMonth : parseInt(displayMonth, 10);
|
|
2510
|
+
if (Number.isNaN(y) || Number.isNaN(m) || m < 1 || m > 12) return;
|
|
2511
|
+
const anyCal = cal;
|
|
2512
|
+
try {
|
|
2513
|
+
anyCal.displayYear = y;
|
|
2514
|
+
anyCal.displayMonth = m;
|
|
2515
|
+
} catch (_) {}
|
|
2516
|
+
cal.setAttribute('display-year', String(y));
|
|
2517
|
+
cal.setAttribute('display-month', String(m));
|
|
2518
|
+
dispatchChange(cal, 'calendarmonthchange', { displayYear: y, displayMonth: m });
|
|
2519
|
+
};
|
|
2520
|
+
|
|
2521
|
+
api.setCalendarSelectedDate = function (calendarIndex, selectedDate) {
|
|
2522
|
+
const cal = getByIndex('scb-calendar', calendarIndex);
|
|
2523
|
+
if (!cal) return;
|
|
2524
|
+
const d = String(selectedDate ?? '');
|
|
2525
|
+
const anyCal = cal;
|
|
2526
|
+
try {
|
|
2527
|
+
anyCal.selectedDate = d;
|
|
2528
|
+
} catch (_) {}
|
|
2529
|
+
if (d) cal.setAttribute('selected-date', d);
|
|
2530
|
+
else cal.removeAttribute('selected-date');
|
|
2531
|
+
dispatchChange(cal, 'calendarselect', { selectedDate: d });
|
|
2532
|
+
};
|
|
2533
|
+
|
|
2534
|
+
api.setCalendarSelectedDateById = function (id, selectedDate) {
|
|
2535
|
+
const cal = getById(id, 'scb-calendar');
|
|
2536
|
+
if (!cal) return;
|
|
2537
|
+
const d = String(selectedDate ?? '');
|
|
2538
|
+
const anyCal = cal;
|
|
2539
|
+
try {
|
|
2540
|
+
anyCal.selectedDate = d;
|
|
2541
|
+
} catch (_) {}
|
|
2542
|
+
if (d) cal.setAttribute('selected-date', d);
|
|
2543
|
+
else cal.removeAttribute('selected-date');
|
|
2544
|
+
dispatchChange(cal, 'calendarselect', { selectedDate: d });
|
|
2545
|
+
};
|
|
2546
|
+
|
|
2547
|
+
api.setCalendarDisableWeekend = function (calendarIndex, disableWeekend) {
|
|
2548
|
+
const cal = getByIndex('scb-calendar', calendarIndex);
|
|
2549
|
+
if (!cal) return;
|
|
2550
|
+
const v = toBool(disableWeekend);
|
|
2551
|
+
const anyCal = cal;
|
|
2552
|
+
try {
|
|
2553
|
+
anyCal.disableWeekend = v;
|
|
2554
|
+
} catch (_) {}
|
|
2555
|
+
if (v) cal.setAttribute('disable-weekend', '');
|
|
2556
|
+
else cal.removeAttribute('disable-weekend');
|
|
2557
|
+
dispatchChange(cal, 'calendardisplaychange', { disableWeekend: v });
|
|
2558
|
+
};
|
|
2559
|
+
|
|
2560
|
+
api.setCalendarPublicHolidays = function (calendarIndex, publicHolidays) {
|
|
2561
|
+
const cal = getByIndex('scb-calendar', calendarIndex);
|
|
2562
|
+
if (!cal) return;
|
|
2563
|
+
const v = toBool(publicHolidays);
|
|
2564
|
+
const anyCal = cal;
|
|
2565
|
+
try {
|
|
2566
|
+
anyCal.publicHolidays = v;
|
|
2567
|
+
} catch (_) {}
|
|
2568
|
+
if (v) cal.setAttribute('public-holidays', '');
|
|
2569
|
+
else cal.removeAttribute('public-holidays');
|
|
2570
|
+
dispatchChange(cal, 'calendardisplaychange', { publicHolidays: v });
|
|
2571
|
+
};
|
|
2572
|
+
|
|
2573
|
+
api.setCalendarLang = function (calendarIndex, lang) {
|
|
2574
|
+
const cal = getByIndex('scb-calendar', calendarIndex);
|
|
2575
|
+
if (!cal) return;
|
|
2576
|
+
const v = String(lang ?? '');
|
|
2577
|
+
const anyCal = cal;
|
|
2578
|
+
try {
|
|
2579
|
+
anyCal.lang = v;
|
|
2580
|
+
} catch (_) {}
|
|
2581
|
+
if (v) cal.setAttribute('lang', v);
|
|
2582
|
+
else cal.removeAttribute('lang');
|
|
2583
|
+
dispatchChange(cal, 'calendardisplaychange', { lang: v });
|
|
2584
|
+
};
|
|
2585
|
+
|
|
2393
2586
|
// Dialog, notification och snackbar
|
|
2394
2587
|
|
|
2395
2588
|
api.setDialogOpen = function (open) {
|
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
import{a as
|
|
1
|
+
import{a as j,n as $,i as P,x as v,t as H}from"../../vendor/vendor.js";import"./scb-calendar-event.js";import"../scb-icon-button/scb-icon-button.js";import"../scb-dialog/scb-dialog.js";import"../scb-list/scb-list.js";import"../../vendor/vendor-material.js";import"../../vendor/preload-helper.js";import"../scb-button/scb-button.js";import"../scb-textfield/scb-textfield.js";import"../scb-datepicker/scb-datepicker.js";import"../scb-divider/scb-divider.js";import"../scb-checkbox/scb-checkbox.js";import"../scb-checkbox/scb-checkbox-group.js";import"../scb-radio-button/scb-radio-button.js";import"../scb-radio-button/scb-radio-group.js";import"../scb-switch/scb-switch.js";import"../scb-chip/scb-chip.js";import"../scb-list/scb-list-item.js";(function(){try{var t=typeof globalThis<"u"?globalThis:window;if(!t.__scb_ce_guard_installed__){t.__scb_ce_guard_installed__=!0;var e=customElements.define.bind(customElements);customElements.define=function(s,r,d){try{customElements.get(s)||e(s,r,d)}catch(c){var a=String(c||"");if(a.indexOf("already been used")===-1&&a.indexOf("NotSupportedError")===-1)throw c}}}}catch{}})();var q=Object.defineProperty,L=Object.getOwnPropertyDescriptor,k=(t,e,s,r)=>{for(var d=r>1?void 0:r?L(e,s):e,a=t.length-1,c;a>=0;a--)(c=t[a])&&(d=(r?c(e,s,d):c(d))||d);return r&&d&&q(e,s,d),d};let D=class extends P{constructor(){super(...arguments),this._lastActiveDay=null,this.lang="sv",this.disableWeekend=!1,this.publicHolidays=!0,this.displayYear=new Date().getFullYear(),this.displayMonth=new Date().getMonth()+1,this.selectedDate="",this._mutationObserver=null,this._syncingDisplay=!1,this._onCalendarKeyDown=t=>{const s=Array.from(this.shadowRoot?.querySelectorAll(".calendar-day.has-event")??[]),r=this.shadowRoot?.activeElement,d=r&&s.includes(r)?r:document.activeElement,a=s.indexOf(d);if(a===-1)return;let c=a;const p=this.disableWeekend?5:7;switch(t.key){case"ArrowRight":c=a+1<s.length?a+1:a;break;case"ArrowLeft":c=a-1>=0?a-1:a;break;case"ArrowDown":c=a+p<s.length?a+p:a;break;case"ArrowUp":c=a-p>=0?a-p:a;break;default:return}c!==a&&(t.preventDefault(),s[c].focus())},this._onEventChanged=()=>{this.requestUpdate()},this._today=new Date,this._current=new Date,this._popupEvent=null,this._restoreDayFocus=()=>{this._lastActiveDay&&setTimeout(()=>{this._lastActiveDay?.focus(),this._lastActiveDay=null},0)},this._easterDateCalculated={}}connectedCallback(){super.connectedCallback();const t=Number(this.displayYear),e=Number(this.displayMonth);!Number.isNaN(t)&&!Number.isNaN(e)&&e>=1&&e<=12&&(this._current=new Date(t,e-1,1)),this._syncDisplayFromCurrent(!1),this.addEventListener("change",this._onEventChanged),this._mutationObserver=new MutationObserver(()=>{this.requestUpdate()}),this._mutationObserver.observe(this,{childList:!0}),this.addEventListener("keydown",this._onCalendarKeyDown)}disconnectedCallback(){this.removeEventListener("change",this._onEventChanged),super.disconnectedCallback(),this._mutationObserver&&(this._mutationObserver.disconnect(),this._mutationObserver=null),this.removeEventListener("keydown",this._onCalendarKeyDown)}updated(t){if(super.updated?.(t),!this._syncingDisplay&&(t.has("displayYear")||t.has("displayMonth"))){const e=Number(this.displayYear),s=Number(this.displayMonth);if(!Number.isNaN(e)&&!Number.isNaN(s)&&s>=1&&s<=12){const r=this._current.getFullYear(),d=this._current.getMonth()+1;(r!==e||d!==s)&&(this._current=new Date(e,s-1,1),this.dispatchEvent(new CustomEvent("scb-calendar-month-change",{bubbles:!0,composed:!0,detail:{displayYear:e,displayMonth:s}})),this.requestUpdate())}}}_syncDisplayFromCurrent(t=!0){const e=this._current.getFullYear(),s=this._current.getMonth()+1;this._syncingDisplay=!0;try{this.displayYear=e,this.displayMonth=s}finally{this._syncingDisplay=!1}t&&this.dispatchEvent(new CustomEvent("scb-calendar-month-change",{bubbles:!0,composed:!0,detail:{displayYear:e,displayMonth:s}}))}_daysInMonth(t,e){return new Date(t,e+1,0).getDate()}_firstDayOfWeek(t,e){const s=new Date(t,e,1).getDay();return s===0?6:s-1}_prevMonth(){this._current=new Date(this._current.getFullYear(),this._current.getMonth()-1,1),this.selectedDate="",this._popupEvent=null,this._syncDisplayFromCurrent(),this.requestUpdate()}_nextMonth(){this._current=new Date(this._current.getFullYear(),this._current.getMonth()+1,1),this.selectedDate="",this._popupEvent=null,this._syncDisplayFromCurrent(),this.requestUpdate()}_showEventPopup(t){this._popupEvent=t,this.selectedDate=t.date,this.dispatchEvent(new CustomEvent("scb-calendar-select",{bubbles:!0,composed:!0,detail:{selectedDate:t.date}})),this._lastActiveDay=this.shadowRoot?.activeElement||document.activeElement,this.requestUpdate(),setTimeout(()=>{const e=this.shadowRoot?.querySelector("scb-dialog");e&&(document.activeElement&&(e.__lastTriggerEl=document.activeElement),e.open=!0,e.addEventListener("close",this._restoreDayFocus,{once:!0}));const s=r=>{r.target?.closest(".event-popup")||this._closePopup()};window.addEventListener("mousedown",s,{once:!0})},0)}_closePopup(){const t=this.shadowRoot?.querySelector("scb-dialog");t&&t.removeAttribute("open"),this._popupEvent=null,this.requestUpdate()}_addDays(t,e){const s=new Date(t.valueOf());return s.setDate(s.getDate()+e),s}_easterDay(t){if(typeof this._easterDateCalculated["Ar"+t]<"u")return new Date(this._easterDateCalculated["Ar"+t]);let e=t;e<100&&(e=e+1900),e<1950&&(e=e+100);const s=e%19,r=e%4,d=e%7,a=(19*s+24)%30,c=(2*r+4*d+6*a+5)%7;let p=22+a+c,T=0;p==57&&(p-=7),p==56&&a==28&&c==6&&s>10&&(p-=7),p>31?(p-=31,T=4):T=3;const _=new Date(e,T-1,p);return this._easterDateCalculated["Ar"+t]=_,new Date(this._easterDateCalculated["Ar"+t])}_swedishHolidayName(t){const e=t.getMonth();if(e===1||e===6||e===7||e===8)return null;const s=t.getMonth()+1,r=t.getDate(),d=t.getFullYear(),a=this._easterDay(d),c=this.lang==="en",p=[["Nyårsdagen","New Year's Day",s===1&&r===1],["Trettondedag jul","Epiphany",s===1&&r===6],["Långfredag","Good Friday",+t==+this._addDays(a,-2)],["Påskdagen","Easter Sunday",+t==+a],["Annandag påsk","Easter Monday",+t==+this._addDays(a,1)],["Kristi himmelsfärdsdag","Ascension Day",+t==+this._addDays(a,39)],["Pingstdagen","Pentecost",+t==+this._addDays(a,50)&&d<2005],["Första maj","May Day",s===5&&r===1],["Nationaldagen","National Day",s===6&&r===6&&d>=2005],["Midsommarafton","Midsummer's Eve",s===6&&r>=19&&r<=25&&t.getDay()===5],["Midsommardagen","Midsummer's Day",s===6&&r>=20&&r<=26&&t.getDay()===6],["Julafton","Christmas Eve",s===12&&r===24],["Juldagen","Christmas Day",s===12&&r===25],["Annandag jul","Boxing Day",s===12&&r===26],["Alla helgons dag","All Saints' Day",s===10&&r>=31&&t.getDay()===6||s===11&&r<=6&&t.getDay()===6]];for(const T of p){const[_,N,A]=T;if(A)return c?N:_}return null}render(){const t=this._current.getFullYear(),e=this._current.getMonth(),s=this._daysInMonth(t,e),r=this._firstDayOfWeek(t,e),d=this._today,a=this.lang==="en",c=a?["January","February","March","April","May","June","July","August","September","October","November","December"]:["Januari","Februari","Mars","April","Maj","Juni","Juli","Augusti","September","Oktober","November","December"];let p=a?["Mon","Tue","Wed","Thu","Fri","Sat","Sun"]:["Mån","Tis","Ons","Tor","Fre","Lör","Sön"];this.disableWeekend&&(p=p.slice(0,5));const T=Array.from(this.querySelectorAll("scb-calendar-event")),_=new Map;for(const n of T){const l=n.getAttribute("start-date")||"",y=n.getAttribute("end-date")||"";if(l&&y){const o=new Date(l),m=new Date(y);for(let u=new Date(o);u<=m;u.setDate(u.getDate()+1)){const b=u.toISOString().split("T")[0],x=_.get(b)||[];x.push({title:n.title,description:n.description,start:l,end:y}),_.set(b,x)}}else if(l&&n.title){const o=l.split("T")[0],m=_.get(o)||[];m.push({title:n.title,description:n.description,start:l}),_.set(o,m)}}const N=[];let A=1;for(let n=0;n<6;n++){const l=[],y=this.disableWeekend?[0,1,2,3,4]:[0,1,2,3,4,5,6];let o=A;for(let m=0;m<y.length;m++){const u=y[m];if(n===0&&u<r){if(!this.disableWeekend||u<5){const b=e===0?11:e-1,x=e===0?t-1:t,S=this._daysInMonth(x,b)-(r-u-1);l.push(v`
|
|
2
2
|
<div class="calendar-day calendar-day--other">
|
|
3
|
-
<span class="calendar-day-number">${
|
|
3
|
+
<span class="calendar-day-number">${S}</span>
|
|
4
4
|
</div>
|
|
5
|
-
`)}}else if(
|
|
5
|
+
`)}}else if(o>s)l.push(v`<div></div>`);else{let b=new Date(t,e,o);if(this.disableWeekend)for(;b.getDay()===0||b.getDay()===6;)o++,b=new Date(t,e,o);if(o>s){l.push(v`<div></div>`);continue}const x=d.getFullYear()===t&&d.getMonth()===e&&d.getDate()===o,f=`${t}-${String(e+1).padStart(2,"0")}-${String(o).padStart(2,"0")}`,S=new Date(t,e,o);let F=!1,w=null;this.publicHolidays&&(w=this._swedishHolidayName(S),F=!!w);let h=_.get(f)||[];h=[...h].sort((i,g)=>{const E=i.start&&f===i.start.split("T")[0]?i.start:i.end&&f===i.end.split("T")[0]?i.end:"",M=g.start&&f===g.start.split("T")[0]?g.start:g.end&&g.end.split("T")[0]?g.end:"",C=E&&E.includes("T"),O=M&&M.includes("T");return C&&O?E.localeCompare(M):C?-1:O?1:i.title.localeCompare(g.title)});const Y=[...h].map(i=>{let g="",E="";if(i.start&&i.end){const M=i.start.split("T")[0],C=i.end.split("T")[0];f===M&&f===C&&i.start.includes("T")&&i.end.includes("T")?g=i.start.split("T")[1].substring(0,5)+"–"+i.end.split("T")[1].substring(0,5):f===M&&i.start.includes("T")?g=i.start.split("T")[1].substring(0,5):f===C&&i.end.includes("T")?(g=i.end.split("T")[1].substring(0,5),E=a?"cont. ":"fort. "):f!==M&&(g="",E=a?"cont. ":"fort. ")}else i.start&&i.start.includes("T")&&(g=i.start.split("T")[1].substring(0,5));return{...i,time:g,prefix:E}});l.push(v`
|
|
6
6
|
<div
|
|
7
|
-
class="calendar-day${
|
|
7
|
+
class="calendar-day${x?" today":""}${h.length?" has-event":""}${F?" calendar-day--holiday":""}"
|
|
8
8
|
tabindex=${h.length?"0":void 0}
|
|
9
|
-
@click=${h.length?()=>this._showEventPopup({date:
|
|
10
|
-
@keydown=${h.length?i=>{(i.key==="Enter"||i.key===" ")&&(i.preventDefault(),this._showEventPopup({date:
|
|
11
|
-
title=${
|
|
9
|
+
@click=${h.length?()=>this._showEventPopup({date:f,events:h}):null}
|
|
10
|
+
@keydown=${h.length?i=>{(i.key==="Enter"||i.key===" ")&&(i.preventDefault(),this._showEventPopup({date:f,events:h}))}:null}
|
|
11
|
+
title=${w||(h.length===1?h[0].title:h.length>1?h.map(i=>i.title).join(", "):"")}
|
|
12
12
|
role=${h.length?"button":void 0}
|
|
13
|
-
aria-label=${
|
|
13
|
+
aria-label=${w||(h.length?h.length===1?h[0].title:h.map(i=>i.title).join(", "):void 0)}
|
|
14
14
|
>
|
|
15
15
|
<md-focus-ring inward></md-focus-ring>
|
|
16
|
-
<span class="calendar-day-number">${
|
|
16
|
+
<span class="calendar-day-number">${o} ${w?v`<span class="calendar-day-holiday-name">${w}</span>`:""}</span>
|
|
17
17
|
<div class="calendar-titles-wrapper">
|
|
18
|
-
${
|
|
18
|
+
${Y.map(i=>v`<span class="calendar-day-event-title">${i.prefix||""}${i.title}</span>`)}
|
|
19
19
|
</div>
|
|
20
20
|
</div>
|
|
21
|
-
`),
|
|
21
|
+
`),o++}}if(A=o,N.push(v`<div class="calendar-grid">${l}</div>`),A>s)break}return v`
|
|
22
22
|
<div class="calendar-header">
|
|
23
|
-
<scb-icon-button @click=${this._prevMonth} icon="chevron_left" aria-label="${
|
|
24
|
-
<span>${c[
|
|
25
|
-
<scb-icon-button @click=${this._nextMonth} icon="chevron_right" aria-label="${
|
|
23
|
+
<scb-icon-button @click=${this._prevMonth} icon="chevron_left" aria-label="${a?"Previous month":"Föregående månad"}"></scb-icon-button>
|
|
24
|
+
<span>${c[e]} ${t}</span>
|
|
25
|
+
<scb-icon-button @click=${this._nextMonth} icon="chevron_right" aria-label="${a?"Next month":"Nästa månad"}"></scb-icon-button>
|
|
26
26
|
</div>
|
|
27
27
|
<div class="calendar-grid calendar-grid-days">
|
|
28
28
|
${p.map(n=>v`<div>${n}</div>`)}
|
|
29
29
|
</div>
|
|
30
30
|
<div class="calendar-weeks">
|
|
31
|
-
${
|
|
31
|
+
${N}
|
|
32
32
|
</div>
|
|
33
33
|
${this._popupEvent&&Array.isArray(this._popupEvent.events)?v`
|
|
34
|
-
<scb-dialog variant="floating" open label="${
|
|
34
|
+
<scb-dialog variant="floating" open label="${a?"Events":"Händelser"} ${this._popupEvent.date}">
|
|
35
35
|
<scb-list>
|
|
36
|
-
${[...this._popupEvent.events].sort((n,
|
|
37
|
-
<scb-list-item label="${
|
|
36
|
+
${[...this._popupEvent.events].sort((n,l)=>{const y=n.start&&n.start.includes("T")?n.start:n.end&&n.end.includes("T")?n.end:"",o=l.start&&l.start.includes("T")?l.start:l.end&&l.end.includes("T")?l.end:"",m=y&&y.includes("T"),u=o&&o.includes("T");return m&&u?y.localeCompare(o):m?-1:u?1:n.title.localeCompare(l.title)}).map(n=>{const l=this._popupEvent?.date??"";let y="",o="",m="";if(n.start&&n.end){const u=n.start.split("T")[0],b=n.end.split("T")[0];u===b&&n.start.includes("T")&&n.end.includes("T")?y=n.start.split("T")[1].substring(0,5)+" – "+n.end.split("T")[1].substring(0,5):l===u&&n.start.includes("T")&&(y="Start: "+n.start.split("T")[1].substring(0,5)+(a?" (Extended event) ":" (Flerdagsevenemang) ")),l===b&&n.end.includes("T")&&u!==b&&(m=(a?"End: ":"Slut: ")+n.end.split("T")[1].substring(0,5)),l!==u&&(o=a?"cont. ":"fort. ")}else n.start&&n.start.includes("T")&&(y=n.start.split("T")[1].substring(0,5));return v`
|
|
37
|
+
<scb-list-item label="${o}${n.title}" supporting-text="${n.description?n.description:""}" overline="${y||""}${m||""}">
|
|
38
38
|
</scb-list-item>`})}
|
|
39
39
|
</scb-list>
|
|
40
40
|
</scb-dialog>
|
|
41
41
|
`:""}
|
|
42
|
-
`}};
|
|
42
|
+
`}};D.styles=j`
|
|
43
43
|
:host {
|
|
44
44
|
display: block;
|
|
45
45
|
border: 1px solid var(--md-sys-color-outline-variant);
|
|
@@ -142,4 +142,4 @@ import{a as N,n as O,i as H,x as v,t as q}from"../../vendor/vendor.js";import"./
|
|
|
142
142
|
gap: var(--spacing-4);
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
-
`;
|
|
145
|
+
`;k([$({type:String})],D.prototype,"lang",2);k([$({type:Boolean,attribute:"disable-weekend"})],D.prototype,"disableWeekend",2);k([$({type:Boolean,attribute:"public-holidays"})],D.prototype,"publicHolidays",2);k([$({type:Number,attribute:"display-year",reflect:!0})],D.prototype,"displayYear",2);k([$({type:Number,attribute:"display-month",reflect:!0})],D.prototype,"displayMonth",2);k([$({type:String,attribute:"selected-date",reflect:!0})],D.prototype,"selectedDate",2);D=k([H("scb-calendar")],D);
|