tltv-timeline-element 1.0.25 → 1.0.26

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.
@@ -15,6 +15,14 @@ import { DateTimeConstants } from './util/dateTimeUtil.js';
15
15
  import * as ElementUtil from './util/elementUtil.js';
16
16
  import { addDaysInZone, getZonedFields, isoWeekOfYear, parseWallTime, zonedWallTimeToInstant } from './util/zonedTime.js';
17
17
  import { DefaultLocaleDataProvider } from './model/DefaultLocaleDataProvider.js';
18
+ /* Attribute converter: truncates a date-time to hour accuracy ("yyyy-MM-ddTHH"). */
19
+ function toHourAccuracy(value) {
20
+ return (value && value.length > 13) ? value.substring(0, 13) : value;
21
+ }
22
+ /* Attribute converter for default-true flags: only the value "false" turns them off. */
23
+ function visibleUnlessFalse(value) {
24
+ return value !== 'false';
25
+ }
18
26
  /**
19
27
  * Scalable, time zone aware timeline header. Renders a date range as year,
20
28
  * month and day rows above a resolution row of hours, days, weeks, months or
@@ -41,6 +49,10 @@ import { DefaultLocaleDataProvider } from './model/DefaultLocaleDataProvider.js'
41
49
  * @cssprop [--timeline-col-weekend=#ccc] - Background of weekend resolution blocks.
42
50
  * @cssprop [--timeline-col-font-size=10px] - Font size of resolution blocks.
43
51
  * @cssprop [--timeline-col-current=#ffe082] - Background of the current-date highlight.
52
+ * @cssprop --timeline-col-min-width - Minimum width of a day or hour block. Default: width of the text "MM".
53
+ * @cssprop --timeline-col-week-min-width - Minimum width of a week block. Default: 4px per day.
54
+ * @cssprop --timeline-col-month-min-width - Minimum width of a 30 day month block. Default: 4px per day.
55
+ * @cssprop --timeline-col-year-min-width - Minimum width of a 365 day year block. Default: 1px per day.
44
56
  */
45
57
  let TimelineElement = TimelineElement_1 = class TimelineElement extends LitElement {
46
58
  constructor() {
@@ -54,12 +66,17 @@ let TimelineElement = TimelineElement_1 = class TimelineElement extends LitEleme
54
66
  /** Timezone for date and time formatting. Doesn't match with actual start and end Date object's time zone. */
55
67
  this.timeZone = "Europe/London";
56
68
  this.locale = "en-US";
57
- this.firstDayOfWeek = 1; // sunday;
69
+ /** First day of the week, 1 (Sunday) to 7 (Saturday). */
70
+ this.firstDayOfWeek = 1;
58
71
  this.twelveHourClock = false;
72
+ /** Show the month header row. Visible by default; hide with `monthrowvisible="false"`. */
59
73
  this.monthRowVisible = true;
74
+ /** Show the year header row. Visible by default; hide with `yearrowvisible="false"`. */
60
75
  this.yearRowVisible = true;
61
76
  /* When true, the resolution block (and the day row block) covering the current date/time is highlighted with 'current' style. */
62
77
  this.currentDateVisible = false;
78
+ /** Log diagnostic messages to the browser console. */
79
+ this.debug = false;
63
80
  /* Current day formatted as 'yyyy-MM-dd' in the timeline's time zone. Refreshed before each fill. */
64
81
  this.currentDayString = null;
65
82
  this.currentHourString = null;
@@ -130,116 +147,110 @@ let TimelineElement = TimelineElement_1 = class TimelineElement extends LitEleme
130
147
  display: block;
131
148
  overflow: hidden;
132
149
  position: relative;
133
-
134
- --no-user-select: {
135
- -webkit-user-select: none;
136
- -khtml-user-select: none;
137
- -moz-user-select: none;
138
- -ms-user-select: none;
139
- user-select: none;
140
- }
141
150
  }
142
151
  :host([hidden]) {
143
152
  display: none;
144
153
  }
145
-
154
+
146
155
  .year,
147
- .month,
148
- .day {
149
- padding-left: 2px;
150
- text-overflow: ellipsis;
151
- white-space: nowrap;
152
- border-right: 1px solid #A9A9A9;
153
- box-sizing: border-box;
154
- -moz-box-sizing: border-box;
155
- -webkit-box-sizing: border-box;
156
- }
157
- .year.spacer,
158
- .month.spacer,
159
- .day.spacer {
160
- padding-left: 0px;
161
- }
156
+ .month,
157
+ .day {
158
+ padding-left: 2px;
159
+ text-overflow: ellipsis;
160
+ white-space: nowrap;
161
+ border-right: 1px solid #A9A9A9;
162
+ box-sizing: border-box;
163
+ }
164
+ .year.spacer,
165
+ .month.spacer,
166
+ .day.spacer {
167
+ padding-left: 0px;
168
+ }
162
169
 
163
- .month:nth-of-type(even),
164
- .day:nth-of-type(even) {
165
- background-color: var(--timeline-row-even-background, #ddd);
166
- }
167
- .col.even {
168
- background-color: var(--timeline-col-even-background-color, #ccc);
169
- }
170
+ .month:nth-of-type(even),
171
+ .day:nth-of-type(even) {
172
+ background-color: var(--timeline-row-even-background, #ddd);
173
+ }
174
+ .col.even {
175
+ background-color: var(--timeline-col-even-background-color, #ccc);
176
+ }
170
177
 
171
- .col {
178
+ .col {
172
179
  position: var(--timeline-col-position);
173
- left: var(--timeline-col-left);
174
- height: 100%;
175
- float: left;
176
- overflow: hidden;
177
- border-right: 1px solid #A9A9A9;
178
- background-color: var(--timeline-col-background-color, #ddd);
179
- font-size: var(--timeline-col-font-size, 10px);
180
- text-align: center;
181
- box-sizing: border-box;
182
- -moz-box-sizing: border-box;
183
- -webkit-box-sizing: border-box;
184
- -webkit-touch-callout: none;
185
- @apply --no-user-select;
186
- }
180
+ left: var(--timeline-col-left);
181
+ height: 100%;
182
+ float: left;
183
+ overflow: hidden;
184
+ border-right: 1px solid #A9A9A9;
185
+ background-color: var(--timeline-col-background-color, #ddd);
186
+ font-size: var(--timeline-col-font-size, 10px);
187
+ text-align: center;
188
+ box-sizing: border-box;
189
+ -webkit-touch-callout: none;
190
+ -webkit-user-select: none;
191
+ user-select: none;
192
+ }
187
193
 
188
194
  .c-col {
189
- width: var(--timeline-col-center-width);
190
- }
195
+ width: var(--timeline-col-center-width);
196
+ }
191
197
 
192
- .f-col {
193
- width: var(--timeline-col-first-width);
194
- }
198
+ .f-col {
199
+ width: var(--timeline-col-first-width);
200
+ }
201
+
202
+ .l-col {
203
+ width: var(--timeline-col-last-width);
204
+ }
195
205
 
196
- .l-col {
197
- width: var(--timeline-col-last-width);
206
+ .col.w,
207
+ .col.m,
208
+ .col.y {
209
+ text-align: left;
198
210
  }
199
-
200
- .col.w,
201
- .col.m,
202
- .col.y {
203
- text-align: left;
204
- }
205
211
 
206
- .col.weekend {
207
- background-color: var(--timeline-col-weekend, #ccc);
208
- }
212
+ .col.weekend {
213
+ background-color: var(--timeline-col-weekend, #ccc);
214
+ }
209
215
 
210
- .col.current,
211
- .day.current {
212
- background-color: var(--timeline-col-current, #ffe082);
213
- }
216
+ .col.current,
217
+ .day.current {
218
+ background-color: var(--timeline-col-current, #ffe082);
219
+ }
214
220
 
215
- .col.measure {
216
- // Change min-width to adjust grid's cell width with day and hour-resolution.
217
- //min-width: 40px;
218
- }
219
- .col.w.measure {
220
- // Change min-width to adjust grid's cell width with week-resolution.
221
- //min-width: 70px;
222
- }
223
- .col.m.measure {
224
- // Change min-width to adjust grid's cell width with month-resolution (width of a 30 day month).
225
- //min-width: 120px;
226
- }
227
- .col.y.measure {
228
- // Change min-width to adjust grid's cell width with year-resolution (width of a 365 day year).
229
- //min-width: 365px;
230
- }
221
+ /*
222
+ * Minimum block widths are measured from these hidden elements (see
223
+ * calculateResolutionMinWidth()). An unset custom property leaves
224
+ * min-width unset, so the defaults apply.
225
+ */
226
+ .col.measure {
227
+ /* Day and hour block. */
228
+ min-width: var(--timeline-col-min-width);
229
+ }
230
+ .col.w.measure {
231
+ /* One week block. */
232
+ min-width: var(--timeline-col-week-min-width);
233
+ }
234
+ .col.m.measure {
235
+ /* A 30 day month block. */
236
+ min-width: var(--timeline-col-month-min-width);
237
+ }
238
+ .col.y.measure {
239
+ /* A 365 day year block. */
240
+ min-width: var(--timeline-col-year-min-width);
241
+ }
231
242
 
232
- .row {
233
- width: 100%;
234
- float: left;
235
- overflow: hidden;
236
- height: var(--timeline-row-height, 15px);
237
- font-size: var(--timeline-row-font-size, 10px);
238
- background-color: var(--timeline-row-background, #d0d0d0);
239
- -ms-flex-pack: justify;
240
- -webkit-touch-callout: none;
241
- @apply --no-user-select;
242
- }
243
+ .row {
244
+ width: 100%;
245
+ float: left;
246
+ overflow: hidden;
247
+ height: var(--timeline-row-height, 15px);
248
+ font-size: var(--timeline-row-font-size, 10px);
249
+ background-color: var(--timeline-row-background, #d0d0d0);
250
+ -webkit-touch-callout: none;
251
+ -webkit-user-select: none;
252
+ user-select: none;
253
+ }
243
254
  `;
244
255
  }
245
256
  render() {
@@ -262,7 +273,7 @@ let TimelineElement = TimelineElement_1 = class TimelineElement extends LitEleme
262
273
  return nothing;
263
274
  }
264
275
  dayBlocks() {
265
- if (this.isDayRowVisible) {
276
+ if (this.isDayRowVisible()) {
266
277
  return this.timelineBlocks(this.dayRowData, TimelineElement_1.STYLE_DAY);
267
278
  }
268
279
  return nothing;
@@ -304,19 +315,19 @@ let TimelineElement = TimelineElement_1 = class TimelineElement extends LitEleme
304
315
  }
305
316
  this.updateTimeLine(this.resolution, this.internalInclusiveStartDateTime, this.internalInclusiveEndDateTime, new DefaultLocaleDataProvider(this.locale, this.timeZone, this.firstDayOfWeek, this.twelveHourClock));
306
317
  }
307
- updated(changedProps) {
318
+ updated() {
308
319
  if (!(this.resolution) || !this.internalInclusiveStartDateTime || !this.internalInclusiveEndDateTime) {
309
320
  return;
310
321
  }
311
322
  if (this.resolution !== Resolution.Day && this.resolution !== Resolution.Week && this.resolution !== Resolution.Hour
312
323
  && !this.isMonthOrYearResolution()) {
313
- console.log("TimelineElement resolution " + (this.resolution ? Resolution[this.resolution] : "null")
324
+ console.warn("TimelineElement resolution " + (this.resolution ? Resolution[this.resolution] : "null")
314
325
  + " is not supported");
315
326
  return;
316
327
  }
317
- console.log("TimelineElement Constructed content.");
328
+ this.log("TimelineElement Constructed content.");
318
329
  this.updateWidths();
319
- console.log("TimelineElement is updated for resolution " + Resolution[this.resolution] + ".");
330
+ this.log("TimelineElement is updated for resolution " + Resolution[this.resolution] + ".");
320
331
  this.registerScrollHandler();
321
332
  }
322
333
  /**
@@ -342,15 +353,15 @@ let TimelineElement = TimelineElement_1 = class TimelineElement extends LitEleme
342
353
  */
343
354
  updateTimeLine(resolution, startDate, endDate, localeDataProvider) {
344
355
  if (!localeDataProvider) {
345
- console.log("TimelineElement requires ILocaleDataProvider. Can't complete update(...) operation.");
356
+ console.warn("TimelineElement requires ILocaleDataProvider. Can't complete update(...) operation.");
346
357
  return;
347
358
  }
348
359
  this.clear();
349
- console.log("TimelineElement content cleared.");
360
+ this.log("TimelineElement content cleared.");
350
361
  if (!(resolution) || !startDate || !endDate) {
351
362
  return;
352
363
  }
353
- console.log("TimelineElement Updating content.");
364
+ this.log("TimelineElement Updating content.");
354
365
  this.localeDataProvider = localeDataProvider;
355
366
  this.resolution = resolution;
356
367
  this.resetDateRange(startDate, endDate);
@@ -382,19 +393,18 @@ let TimelineElement = TimelineElement_1 = class TimelineElement extends LitEleme
382
393
  if (this.scrollHandler) {
383
394
  return;
384
395
  }
385
- const timeline = this;
386
396
  this.scrollContainer = this.setupScrollContainer();
387
- this.scrollHandler = function (e) {
388
- window.requestAnimationFrame(function () {
389
- const container = timeline.scrollContainer;
390
- const sl = container.scrollLeft || container.scrollX;
391
- const st = container.scrollTop || container.scrollY;
392
- if (sl != timeline.previousContainerScrollLeft) {
393
- timeline.setScrollLeft(sl);
394
- timeline.previousContainerScrollLeft = sl;
397
+ this.scrollHandler = () => {
398
+ window.requestAnimationFrame(() => {
399
+ const container = this.scrollContainer;
400
+ const sl = container instanceof Window ? container.scrollX : container.scrollLeft;
401
+ const st = container instanceof Window ? container.scrollY : container.scrollTop;
402
+ if (sl != this.previousContainerScrollLeft) {
403
+ this.setScrollLeft(sl);
404
+ this.previousContainerScrollLeft = sl;
395
405
  }
396
- if (st != timeline.previousContainerScrollTop) {
397
- timeline.previousContainerScrollTop = st;
406
+ if (st != this.previousContainerScrollTop) {
407
+ this.previousContainerScrollTop = st;
398
408
  }
399
409
  });
400
410
  };
@@ -558,12 +568,18 @@ let TimelineElement = TimelineElement_1 = class TimelineElement extends LitEleme
558
568
  return DateUtil.toNormalDate(zonedDate, this.localeDataProvider.getDaylightAdjustment(zonedDate));
559
569
  }
560
570
  getParentElement(node) {
561
- let parent = node.parentNode;
562
- if (!parent || parent.nodeType != 1) {
563
- parent = null;
571
+ const parent = node.parentNode;
572
+ if (!parent || parent.nodeType != Node.ELEMENT_NODE) {
573
+ return null;
564
574
  }
565
575
  return parent;
566
576
  }
577
+ /* Logs a diagnostic message when the debug property is set. */
578
+ log(message) {
579
+ if (this.debug) {
580
+ console.log(message);
581
+ }
582
+ }
567
583
  getDay(date) {
568
584
  // by adjusting the date to the middle of the day before formatting is a
569
585
  // workaround to avoid DST issues with DateTimeFormatter.
@@ -940,8 +956,10 @@ let TimelineElement = TimelineElement_1 = class TimelineElement extends LitEleme
940
956
  const p = range / width;
941
957
  const offset = p * left;
942
958
  const date = new Date(this.internalInclusiveStartDateTime.getTime() + offset);
943
- console.log("Zoned: " + this.localeDataProvider.formatDate(date, "dd. HH:mm") + " DST: "
944
- + this.localeDataProvider.getDaylightAdjustment(date) / 60000);
959
+ if (this.debug) {
960
+ this.log("Zoned: " + this.localeDataProvider.formatDate(date, "dd. HH:mm") + " DST: "
961
+ + this.localeDataProvider.getDaylightAdjustment(date) / 60000);
962
+ }
945
963
  return date;
946
964
  }
947
965
  /**
@@ -994,10 +1012,10 @@ let TimelineElement = TimelineElement_1 = class TimelineElement extends LitEleme
994
1012
  */
995
1013
  updateWidths() {
996
1014
  if (this.resolutionDiv == null) {
997
- console.log("TimelineElement is not ready for updateWidths() call. Call update(...) instead.");
1015
+ this.log("TimelineElement is not ready for updateWidths() call. Call update(...) instead.");
998
1016
  return;
999
1017
  }
1000
- console.log("TimelineElement Started updating widths.");
1018
+ this.log("TimelineElement Started updating widths.");
1001
1019
  // start by clearing old content in resolution element
1002
1020
  while (this.resolutionDiv.firstChild) {
1003
1021
  this.resolutionDiv.removeChild(this.resolutionDiv.lastChild);
@@ -1053,7 +1071,7 @@ let TimelineElement = TimelineElement_1 = class TimelineElement extends LitEleme
1053
1071
  if (this.isAlwaysCalculatePixelWidths()) {
1054
1072
  this.updateSpacerBlocks(this.dayOrHourWidthPx);
1055
1073
  }
1056
- console.log("TimelineElement Widths are updated.");
1074
+ this.log("TimelineElement Widths are updated.");
1057
1075
  }
1058
1076
  updateBlockWidths(rowData) {
1059
1077
  for (const entry of rowData.getBlockEntries()) {
@@ -1153,7 +1171,7 @@ let TimelineElement = TimelineElement_1 = class TimelineElement extends LitEleme
1153
1171
  }
1154
1172
  this.resolutionDiv.appendChild(element);
1155
1173
  }
1156
- console.log(`TimelineElement Added ${blocks} visible timeline elements for resolution ${Resolution[this.resolution]}`);
1174
+ this.log(`TimelineElement Added ${blocks} visible timeline elements for resolution ${Resolution[this.resolution]}`);
1157
1175
  }
1158
1176
  calculateMinimumResolutionBlockWidth() {
1159
1177
  if (this.resolution === Resolution.Week) {
@@ -1231,7 +1249,7 @@ let TimelineElement = TimelineElement_1 = class TimelineElement extends LitEleme
1231
1249
  this.fillTimelineForResolution(leftDate, new Date(Math.min(this.internalInclusiveEndDateTime.getTime(), this.getDateForLeftPositionNoticeDST(datePos + containerWidth, noticeDst).getTime())), left);
1232
1250
  this.style.setProperty("--timeline-col-position", "relative");
1233
1251
  this.style.setProperty("--timeline-col-left", left + "px");
1234
- console.log(`TimelineElement Updated visible timeline elements for horizontal scroll position ${left} (plus ${datePos - left} to center-of-first-block)`);
1252
+ this.log(`TimelineElement Updated visible timeline elements for horizontal scroll position ${left} (plus ${datePos - left} to center-of-first-block)`);
1235
1253
  }
1236
1254
  showAllResolutionBlocks() {
1237
1255
  this.style.setProperty("--timeline-col-position", "relative");
@@ -1298,11 +1316,11 @@ let TimelineElement = TimelineElement_1 = class TimelineElement extends LitEleme
1298
1316
  this.fillTimelineForHourResolution(startDate, endDate, left);
1299
1317
  }
1300
1318
  else {
1301
- console.log("TimelineElement resolution " + (this.resolution != null ? Resolution[this.resolution] : "null")
1319
+ console.warn("TimelineElement resolution " + (this.resolution != null ? Resolution[this.resolution] : "null")
1302
1320
  + " is not supported");
1303
1321
  return;
1304
1322
  }
1305
- console.log("TimelineElement Filled new data and styles to visible timeline elements");
1323
+ this.log("TimelineElement Filled new data and styles to visible timeline elements");
1306
1324
  }
1307
1325
  isFirstResBlockShort() {
1308
1326
  return this.firstResBlockCount > 0 && ((this.resolution === Resolution.Week && this.firstResBlockCount < DateTimeConstants.DAYS_IN_WEEK));
@@ -1757,8 +1775,8 @@ let TimelineElement = TimelineElement_1 = class TimelineElement extends LitEleme
1757
1775
  const visibleRangeNormalStartDate = timeline.toNormalDate(startDate);
1758
1776
  if (timeline.normalStartDate.getTime() < visibleRangeNormalStartDate.getTime()) {
1759
1777
  let daysHidden = Math.floor(((visibleRangeNormalStartDate.getTime() - timeline.normalStartDate.getTime()) / DateTimeConstants.DAY_INTERVAL));
1760
- console.log("Days hidden: " + daysHidden);
1761
- console.log("firstWeekBlockHidden = " + timeline.firstWeekBlockHidden);
1778
+ timeline.log("Days hidden: " + daysHidden);
1779
+ timeline.log("firstWeekBlockHidden = " + timeline.firstWeekBlockHidden);
1762
1780
  if (daysHidden === 0) {
1763
1781
  return false;
1764
1782
  }
@@ -1783,7 +1801,7 @@ let TimelineElement = TimelineElement_1 = class TimelineElement extends LitEleme
1783
1801
  });
1784
1802
  }
1785
1803
  logIndexOutOfBounds(indexName, index, childCount) {
1786
- console.log(`${indexName} index ${index} out of bounds with childCount ${childCount}. Can't fill content.`);
1804
+ this.log(`${indexName} index ${index} out of bounds with childCount ${childCount}. Can't fill content.`);
1787
1805
  }
1788
1806
  fillTimelineForHour(interval, startDate, endDate, resBlockFiller) {
1789
1807
  const currentYear = null;
@@ -1923,34 +1941,17 @@ __decorate([
1923
1941
  property({
1924
1942
  reflect: true,
1925
1943
  converter: {
1926
- fromAttribute: (value, type) => {
1927
- return Resolution[value];
1928
- },
1929
- toAttribute: (value, type) => {
1930
- return Resolution[value];
1931
- }
1944
+ // Attribute holds the enum name, e.g. "Week".
1945
+ fromAttribute: (value) => Resolution[value],
1946
+ toAttribute: (value) => Resolution[value],
1932
1947
  }
1933
1948
  })
1934
1949
  ], TimelineElement.prototype, "resolution", void 0);
1935
1950
  __decorate([
1936
- property({
1937
- reflect: true,
1938
- converter: {
1939
- fromAttribute: (value, type) => {
1940
- return (value) ? (value.length > 13) ? value.substring(0, 13) : value : value;
1941
- },
1942
- }
1943
- })
1951
+ property({ reflect: true, converter: { fromAttribute: toHourAccuracy } })
1944
1952
  ], TimelineElement.prototype, "startDateTime", void 0);
1945
1953
  __decorate([
1946
- property({
1947
- reflect: true,
1948
- converter: {
1949
- fromAttribute: (value, type) => {
1950
- return (value) ? (value.length > 13) ? value.substring(0, 13) : value : value;
1951
- },
1952
- }
1953
- })
1954
+ property({ reflect: true, converter: { fromAttribute: toHourAccuracy } })
1954
1955
  ], TimelineElement.prototype, "endDateTime", void 0);
1955
1956
  __decorate([
1956
1957
  property({ reflect: true })
@@ -1959,7 +1960,7 @@ __decorate([
1959
1960
  property({ reflect: true })
1960
1961
  ], TimelineElement.prototype, "locale", void 0);
1961
1962
  __decorate([
1962
- property({ reflect: true })
1963
+ property({ reflect: true, type: Number })
1963
1964
  ], TimelineElement.prototype, "firstDayOfWeek", void 0);
1964
1965
  __decorate([
1965
1966
  property({ reflect: true, type: Boolean })
@@ -1986,10 +1987,10 @@ __decorate([
1986
1987
  property({ reflect: true })
1987
1988
  ], TimelineElement.prototype, "scrollContainerId", void 0);
1988
1989
  __decorate([
1989
- property()
1990
+ property({ converter: { fromAttribute: visibleUnlessFalse } })
1990
1991
  ], TimelineElement.prototype, "monthRowVisible", void 0);
1991
1992
  __decorate([
1992
- property()
1993
+ property({ converter: { fromAttribute: visibleUnlessFalse } })
1993
1994
  ], TimelineElement.prototype, "yearRowVisible", void 0);
1994
1995
  __decorate([
1995
1996
  property()
@@ -2000,6 +2001,9 @@ __decorate([
2000
2001
  __decorate([
2001
2002
  property({ reflect: true, type: Boolean })
2002
2003
  ], TimelineElement.prototype, "currentDateVisible", void 0);
2004
+ __decorate([
2005
+ property({ type: Boolean })
2006
+ ], TimelineElement.prototype, "debug", void 0);
2003
2007
  __decorate([
2004
2008
  query('#resolutionDiv')
2005
2009
  ], TimelineElement.prototype, "resolutionDiv", void 0);