@schukai/monster 3.112.4 → 3.114.0

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.
@@ -10,21 +10,20 @@
10
10
  * For more information about purchasing a commercial license, please contact schukai GmbH.
11
11
  */
12
12
 
13
- import {instanceSymbol} from "../../constants.mjs";
13
+ import { instanceSymbol } from "../../constants.mjs";
14
+ import { ATTRIBUTE_ROLE } from "../../dom/constants.mjs";
15
+ import { CustomElement } from "../../dom/customelement.mjs";
14
16
  import {
15
- ATTRIBUTE_ROLE,
16
- } from "../../dom/constants.mjs";
17
- import {CustomElement} from "../../dom/customelement.mjs";
18
- import {
19
- assembleMethodSymbol, registerCustomElement,
17
+ assembleMethodSymbol,
18
+ registerCustomElement,
20
19
  } from "../../dom/customelement.mjs";
21
- import {DayStyleSheet} from "./stylesheet/day.mjs";
22
- import {isString} from "../../types/is.mjs"
23
- import {getLocaleOfDocument} from "../../dom/locale.mjs";
24
- import {Observer} from "../../types/observer.mjs";
25
- import {Processing} from "../../util/processing.mjs";
20
+ import { DayStyleSheet } from "./stylesheet/day.mjs";
21
+ import { isString } from "../../types/is.mjs";
22
+ import { getLocaleOfDocument } from "../../dom/locale.mjs";
23
+ import { Observer } from "../../types/observer.mjs";
24
+ import { Processing } from "../../util/processing.mjs";
26
25
 
27
- export {Day};
26
+ export { Day };
28
27
 
29
28
  /**
30
29
  * @private
@@ -66,296 +65,302 @@ const dayLabelElementSymbol = Symbol("dayLabelElement");
66
65
  * @summary A day control that displays the day, month, weekday and a label.
67
66
  */
68
67
  class Day extends CustomElement {
69
-
70
- /**
71
- *
72
- */
73
- constructor() {
74
- super();
75
- initOptionObserver.call(this);
76
- }
77
-
78
- /**
79
- * This method is called by the `instanceof` operator.
80
- * @returns {symbol}
81
- */
82
- static get [instanceSymbol]() {
83
- return Symbol.for("@schukai/monster/components/time/day@@instance");
84
- }
85
-
86
- /**
87
- *
88
- * @return {Components.Time.Day
89
- */
90
- [assembleMethodSymbol]() {
91
- super[assembleMethodSymbol]();
92
- initControlReferences.call(this);
93
- updateDate.call(this);
94
- return this;
95
- }
96
-
97
- /**
98
- * To set the options via the HTML Tag, the attribute `data-monster-options` must be used.
99
- * @see {@link https://monsterjs.org/en/doc/#configurate-a-monster-control}
100
- *
101
- * The individual configuration values can be found in the table.
102
- *
103
- * @property {Object} templates Template definitions
104
- * @property {string} templates.main Main template
105
- * @property {string} date The date of the day
106
- */
107
- get defaults() {
108
- return Object.assign({}, super.defaults, {
109
- templates: {
110
- main: getTemplate(),
111
- },
112
-
113
- date: null,
114
-
115
- day: null, month: null, weekday: null, label: null,
116
-
117
- disabled: false
118
- });
119
- }
120
-
121
- /**
122
- * @return {string}
123
- */
124
- static getTag() {
125
- return "monster-day";
126
- }
127
-
128
- /**
129
- * @return {CSSStyleSheet[]}
130
- */
131
- static getCSSStyleSheet() {
132
- return [DayStyleSheet];
133
- }
134
-
135
- /**
136
- * @return {string[]}
137
- * @since 1.15.0
138
- */
139
- static get observedAttributes() {
140
- return ["data-monster-option-date"];
141
- }
142
-
143
-
68
+ /**
69
+ *
70
+ */
71
+ constructor() {
72
+ super();
73
+ initOptionObserver.call(this);
74
+ }
75
+
76
+ /**
77
+ * This method is called by the `instanceof` operator.
78
+ * @returns {symbol}
79
+ */
80
+ static get [instanceSymbol]() {
81
+ return Symbol.for("@schukai/monster/components/time/day@@instance");
82
+ }
83
+
84
+ /**
85
+ *
86
+ * @return {Components.Time.Day
87
+ */
88
+ [assembleMethodSymbol]() {
89
+ super[assembleMethodSymbol]();
90
+ initControlReferences.call(this);
91
+ updateDate.call(this);
92
+ return this;
93
+ }
94
+
95
+ /**
96
+ * To set the options via the HTML Tag, the attribute `data-monster-options` must be used.
97
+ * @see {@link https://monsterjs.org/en/doc/#configurate-a-monster-control}
98
+ *
99
+ * The individual configuration values can be found in the table.
100
+ *
101
+ * @property {Object} templates Template definitions
102
+ * @property {string} templates.main Main template
103
+ * @property {string} date The date of the day
104
+ */
105
+ get defaults() {
106
+ return Object.assign({}, super.defaults, {
107
+ templates: {
108
+ main: getTemplate(),
109
+ },
110
+
111
+ date: null,
112
+
113
+ day: null,
114
+ month: null,
115
+ weekday: null,
116
+ label: null,
117
+
118
+ disabled: false,
119
+ });
120
+ }
121
+
122
+ /**
123
+ * @return {string}
124
+ */
125
+ static getTag() {
126
+ return "monster-day";
127
+ }
128
+
129
+ /**
130
+ * @return {CSSStyleSheet[]}
131
+ */
132
+ static getCSSStyleSheet() {
133
+ return [DayStyleSheet];
134
+ }
135
+
136
+ /**
137
+ * @return {string[]}
138
+ * @since 1.15.0
139
+ */
140
+ static get observedAttributes() {
141
+ return ["data-monster-option-date"];
142
+ }
144
143
  }
145
144
 
146
145
  /**
147
146
  * @private
148
147
  */
149
148
  function initOptionObserver() {
150
- const self = this;
151
-
152
- let lastDate = this.getOption("date");
153
-
154
- self.attachObserver(
155
- new Observer(function () {
156
- new Processing(() => {
157
-
158
- if (lastDate !== self.getOption("date")) {
159
- lastDate = self.getOption("date");
160
- updateDate.call(self);
161
- }
162
- }).run();
163
- }),
164
- );
149
+ const self = this;
150
+
151
+ let lastDate = this.getOption("date");
152
+
153
+ self.attachObserver(
154
+ new Observer(function () {
155
+ new Processing(() => {
156
+ if (lastDate !== self.getOption("date")) {
157
+ lastDate = self.getOption("date");
158
+ updateDate.call(self);
159
+ }
160
+ }).run();
161
+ }),
162
+ );
165
163
  }
166
164
 
167
165
  /**
168
166
  * @private
169
167
  */
170
168
  function updateDate() {
171
-
172
- const labels = getLabels.call(this)
173
-
174
- let date = this.getOption("date");
175
-
176
- let day = null;
177
- let label = null;
178
-
179
-
180
- if (date === null) {
181
- date = new Date();
182
- } else if (isString(date)) {
183
- date = new Date(date);
184
- }
185
-
186
- if (!(date instanceof Date)) {
187
- return
188
- }
189
-
190
- day = date.getDate();
191
-
192
- const locale = getLocaleOfDocument();
193
-
194
- this.setOption("day", day);
195
- this.setOption("month", new Intl.DateTimeFormat(locale.toString(), {
196
- month: "short"
197
- }).format(date));
198
-
199
-
200
- this.setOption("weekday", new Intl.DateTimeFormat(locale.toString(), {
201
- weekday: "long"
202
- }).format(date));
203
-
204
- if (date.toDateString() === new Date().toDateString()) {
205
- label = labels.today;
206
- } else if (date.toDateString() === new Date(new Date().setDate(new Date().getDate() - 1)).toDateString()) {
207
- label = labels.yesterday;
208
- } else if (date.toDateString() === new Date(new Date().setDate(new Date().getDate() + 1)).toDateString()) {
209
- label = labels.tomorrow;
210
- }
211
-
212
- this.setOption("label", label);
213
-
214
-
169
+ const labels = getLabels.call(this);
170
+
171
+ let date = this.getOption("date");
172
+
173
+ let day = null;
174
+ let label = null;
175
+
176
+ if (date === null) {
177
+ date = new Date();
178
+ } else if (isString(date)) {
179
+ date = new Date(date);
180
+ }
181
+
182
+ if (!(date instanceof Date)) {
183
+ return;
184
+ }
185
+
186
+ day = date.getDate();
187
+
188
+ const locale = getLocaleOfDocument();
189
+
190
+ this.setOption("day", day);
191
+ this.setOption(
192
+ "month",
193
+ new Intl.DateTimeFormat(locale.toString(), {
194
+ month: "short",
195
+ }).format(date),
196
+ );
197
+
198
+ this.setOption(
199
+ "weekday",
200
+ new Intl.DateTimeFormat(locale.toString(), {
201
+ weekday: "long",
202
+ }).format(date),
203
+ );
204
+
205
+ if (date.toDateString() === new Date().toDateString()) {
206
+ label = labels.today;
207
+ } else if (
208
+ date.toDateString() ===
209
+ new Date(new Date().setDate(new Date().getDate() - 1)).toDateString()
210
+ ) {
211
+ label = labels.yesterday;
212
+ } else if (
213
+ date.toDateString() ===
214
+ new Date(new Date().setDate(new Date().getDate() + 1)).toDateString()
215
+ ) {
216
+ label = labels.tomorrow;
217
+ }
218
+
219
+ this.setOption("label", label);
215
220
  }
216
221
 
217
222
  function getLabels() {
218
-
219
- switch (getLocaleOfDocument().language) {
220
- case "de": // German
221
- return {
222
- "today": "Heute",
223
- "tomorrow": "Morgen",
224
- "yesterday": "Gestern"
225
- };
226
-
227
- case "es": // Spanish
228
- return {
229
- "today": "Hoy",
230
- "tomorrow": "Mañana",
231
- "yesterday": "Ayer"
232
- };
233
-
234
- case "zh": // Mandarin
235
- return {
236
- "today": "今天",
237
- "tomorrow": "明天",
238
- "yesterday": "昨天"
239
- };
240
-
241
- case "hi": // Hindi
242
- return {
243
- "today": "आज",
244
- "tomorrow": "कल",
245
- "yesterday": "बीता कल"
246
- };
247
-
248
- case "bn": // Bengali
249
- return {
250
- "today": "আজ",
251
- "tomorrow": "আগামীকাল",
252
- "yesterday": "গতকাল"
253
- };
254
-
255
- case "pt": // Portuguese
256
- return {
257
- "today": "Hoje",
258
- "tomorrow": "Amanhã",
259
- "yesterday": "Ontem"
260
- };
261
-
262
- case "ru": // Russian
263
- return {
264
- "today": "Сегодня",
265
- "tomorrow": "Завтра",
266
- "yesterday": "Вчера"
267
- };
268
-
269
- case "ja": // Japanese
270
- return {
271
- "today": "今日",
272
- "tomorrow": "明日",
273
- "yesterday": "昨日"
274
- };
275
-
276
- case "pa": // Western Punjabi
277
- return {
278
- "today": "ਅਜ",
279
- "tomorrow": "ਕਲ",
280
- "yesterday": "ਬੀਤੇ ਕਲ"
281
- };
282
-
283
- case "mr": // Marathi
284
- return {
285
- "today": "आज",
286
- "tomorrow": "उद्या",
287
- "yesterday": "काल"
288
- };
289
-
290
- case "fr": // French
291
- return {
292
- "today": "Aujourd'hui",
293
- "tomorrow": "Demain",
294
- "yesterday": "Hier"
295
- };
296
-
297
- case "it": // Italian
298
- return {
299
- "today": "Oggi",
300
- "tomorrow": "Domani",
301
- "yesterday": "Ieri"
302
- };
303
-
304
- case "nl": // Dutch
305
- return {
306
- "today": "Vandaag",
307
- "tomorrow": "Morgen",
308
- "yesterday": "Gisteren"
309
- };
310
-
311
- case "sv": // Swedish
312
- return {
313
- "today": "Idag",
314
- "tomorrow": "Imorgon",
315
- "yesterday": "Igår"
316
- };
317
-
318
- case "pl": // Polish
319
- return {
320
- "today": "Dziś",
321
- "tomorrow": "Jutro",
322
- "yesterday": "Wczoraj"
323
- };
324
-
325
- case "da": // Danish
326
- return {
327
- "today": "I dag",
328
- "tomorrow": "I morgen",
329
- "yesterday": "I går"
330
- };
331
-
332
- case "fi": // Finnish
333
- return {
334
- "today": "Tänään",
335
- "tomorrow": "Huomenna",
336
- "yesterday": "Eilen"
337
- };
338
-
339
- case "no": // Norwegian
340
- return {
341
- "today": "I dag",
342
- "tomorrow": "I morgen",
343
- "yesterday": "I går"
344
- };
345
-
346
- case "cs": // Czech
347
- return {
348
- "today": "Dnes",
349
- "tomorrow": "Zítra",
350
- "yesterday": "Včera"
351
- };
352
-
353
- default:
354
- return {
355
- "today": "Today", "tomorrow": "Tomorrow", "yesterday": "Yesterday"
356
- };
357
- }
358
-
223
+ switch (getLocaleOfDocument().language) {
224
+ case "de": // German
225
+ return {
226
+ today: "Heute",
227
+ tomorrow: "Morgen",
228
+ yesterday: "Gestern",
229
+ };
230
+
231
+ case "es": // Spanish
232
+ return {
233
+ today: "Hoy",
234
+ tomorrow: "Mañana",
235
+ yesterday: "Ayer",
236
+ };
237
+
238
+ case "zh": // Mandarin
239
+ return {
240
+ today: "今天",
241
+ tomorrow: "明天",
242
+ yesterday: "昨天",
243
+ };
244
+
245
+ case "hi": // Hindi
246
+ return {
247
+ today: "आज",
248
+ tomorrow: "कल",
249
+ yesterday: "बीता कल",
250
+ };
251
+
252
+ case "bn": // Bengali
253
+ return {
254
+ today: "আজ",
255
+ tomorrow: "আগামীকাল",
256
+ yesterday: "গতকাল",
257
+ };
258
+
259
+ case "pt": // Portuguese
260
+ return {
261
+ today: "Hoje",
262
+ tomorrow: "Amanhã",
263
+ yesterday: "Ontem",
264
+ };
265
+
266
+ case "ru": // Russian
267
+ return {
268
+ today: "Сегодня",
269
+ tomorrow: "Завтра",
270
+ yesterday: "Вчера",
271
+ };
272
+
273
+ case "ja": // Japanese
274
+ return {
275
+ today: "今日",
276
+ tomorrow: "明日",
277
+ yesterday: "昨日",
278
+ };
279
+
280
+ case "pa": // Western Punjabi
281
+ return {
282
+ today: "ਅਜ",
283
+ tomorrow: "ਕਲ",
284
+ yesterday: "ਬੀਤੇ ਕਲ",
285
+ };
286
+
287
+ case "mr": // Marathi
288
+ return {
289
+ today: "आज",
290
+ tomorrow: "उद्या",
291
+ yesterday: "काल",
292
+ };
293
+
294
+ case "fr": // French
295
+ return {
296
+ today: "Aujourd'hui",
297
+ tomorrow: "Demain",
298
+ yesterday: "Hier",
299
+ };
300
+
301
+ case "it": // Italian
302
+ return {
303
+ today: "Oggi",
304
+ tomorrow: "Domani",
305
+ yesterday: "Ieri",
306
+ };
307
+
308
+ case "nl": // Dutch
309
+ return {
310
+ today: "Vandaag",
311
+ tomorrow: "Morgen",
312
+ yesterday: "Gisteren",
313
+ };
314
+
315
+ case "sv": // Swedish
316
+ return {
317
+ today: "Idag",
318
+ tomorrow: "Imorgon",
319
+ yesterday: "Igår",
320
+ };
321
+
322
+ case "pl": // Polish
323
+ return {
324
+ today: "Dziś",
325
+ tomorrow: "Jutro",
326
+ yesterday: "Wczoraj",
327
+ };
328
+
329
+ case "da": // Danish
330
+ return {
331
+ today: "I dag",
332
+ tomorrow: "I morgen",
333
+ yesterday: "I går",
334
+ };
335
+
336
+ case "fi": // Finnish
337
+ return {
338
+ today: "Tänään",
339
+ tomorrow: "Huomenna",
340
+ yesterday: "Eilen",
341
+ };
342
+
343
+ case "no": // Norwegian
344
+ return {
345
+ today: "I dag",
346
+ tomorrow: "I morgen",
347
+ yesterday: "I går",
348
+ };
349
+
350
+ case "cs": // Czech
351
+ return {
352
+ today: "Dnes",
353
+ tomorrow: "Zítra",
354
+ yesterday: "Včera",
355
+ };
356
+
357
+ default:
358
+ return {
359
+ today: "Today",
360
+ tomorrow: "Tomorrow",
361
+ yesterday: "Yesterday",
362
+ };
363
+ }
359
364
  }
360
365
 
361
366
  /**
@@ -364,15 +369,17 @@ function getLabels() {
364
369
  * @returns {*[]}
365
370
  */
366
371
  function getWeekdays(format = "long") {
367
- const locale = getLocaleOfDocument();
372
+ const locale = getLocaleOfDocument();
368
373
 
369
- const weekdays = [];
370
- for (let i = 1; i < 8; i++) {
371
- const date = new Date(1970, 0, 4 + i); // 4. Jan. 1970 = Sonntag
372
- weekdays.push(new Intl.DateTimeFormat(locale, {weekday: format}).format(date),);
373
- }
374
+ const weekdays = [];
375
+ for (let i = 1; i < 8; i++) {
376
+ const date = new Date(1970, 0, 4 + i); // 4. Jan. 1970 = Sonntag
377
+ weekdays.push(
378
+ new Intl.DateTimeFormat(locale, { weekday: format }).format(date),
379
+ );
380
+ }
374
381
 
375
- return weekdays;
382
+ return weekdays;
376
383
  }
377
384
 
378
385
  /**
@@ -380,11 +387,21 @@ function getWeekdays(format = "long") {
380
387
  * @return {void}
381
388
  */
382
389
  function initControlReferences() {
383
- this[dayElementSymbol] = this.shadowRoot.querySelector(`[${ATTRIBUTE_ROLE}="control"]`,);
384
- this[dayMonthElementSymbol] = this.shadowRoot.querySelector(`[${ATTRIBUTE_ROLE}="month"]`,);
385
- this[dayDayElementSymbol] = this.shadowRoot.querySelector(`[${ATTRIBUTE_ROLE}="day"]`,);
386
- this[dayWeekdayElementSymbol] = this.shadowRoot.querySelector(`[${ATTRIBUTE_ROLE}="weekday"]`,);
387
- this[dayLabelElementSymbol] = this.shadowRoot.querySelector(`[${ATTRIBUTE_ROLE}="label"]`,);
390
+ this[dayElementSymbol] = this.shadowRoot.querySelector(
391
+ `[${ATTRIBUTE_ROLE}="control"]`,
392
+ );
393
+ this[dayMonthElementSymbol] = this.shadowRoot.querySelector(
394
+ `[${ATTRIBUTE_ROLE}="month"]`,
395
+ );
396
+ this[dayDayElementSymbol] = this.shadowRoot.querySelector(
397
+ `[${ATTRIBUTE_ROLE}="day"]`,
398
+ );
399
+ this[dayWeekdayElementSymbol] = this.shadowRoot.querySelector(
400
+ `[${ATTRIBUTE_ROLE}="weekday"]`,
401
+ );
402
+ this[dayLabelElementSymbol] = this.shadowRoot.querySelector(
403
+ `[${ATTRIBUTE_ROLE}="label"]`,
404
+ );
388
405
  }
389
406
 
390
407
  /**
@@ -392,8 +409,8 @@ function initControlReferences() {
392
409
  * @return {string}
393
410
  */
394
411
  function getTemplate() {
395
- // language=HTML
396
- return `
412
+ // language=HTML
413
+ return `
397
414
  <div data-monster-role="control" part="control">
398
415
  <div class="month" data-monster-role="month" part="month" data-monster-replace="path:month"></div>
399
416
  <div data-monster-role="day" part="day" data-monster-replace="path:day">12</div>
@@ -403,5 +420,4 @@ function getTemplate() {
403
420
  </div>`;
404
421
  }
405
422
 
406
-
407
423
  registerCustomElement(Day);