tltv-timeline-element 1.0.24 → 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.
- package/README.md +148 -10
- package/custom-elements.json +4201 -0
- package/dist/src/model/DefaultLocaleDataProvider.d.ts +35 -27
- package/dist/src/model/DefaultLocaleDataProvider.d.ts.map +1 -0
- package/dist/src/model/DefaultLocaleDataProvider.js +78 -111
- package/dist/src/model/DefaultLocaleDataProvider.js.map +1 -1
- package/dist/src/model/ILocaleDataProvider.d.ts +71 -62
- package/dist/src/model/ILocaleDataProvider.d.ts.map +1 -0
- package/dist/src/model/ILocaleDataProvider.js +1 -1
- package/dist/src/model/IResolutionBlockFiller.d.ts +5 -4
- package/dist/src/model/IResolutionBlockFiller.d.ts.map +1 -0
- package/dist/src/model/IResolutionBlockFiller.js +1 -1
- package/dist/src/model/IResolutionBlockRegisterer.d.ts +4 -3
- package/dist/src/model/IResolutionBlockRegisterer.d.ts.map +1 -0
- package/dist/src/model/IResolutionBlockRegisterer.js +1 -1
- package/dist/src/model/Resolution.d.ts +8 -7
- package/dist/src/model/Resolution.d.ts.map +1 -0
- package/dist/src/model/Resolution.js +8 -8
- package/dist/src/model/Weekday.d.ts +6 -5
- package/dist/src/model/Weekday.d.ts.map +1 -0
- package/dist/src/model/Weekday.js +6 -6
- package/dist/src/model/blockRowData.d.ts +12 -11
- package/dist/src/model/blockRowData.d.ts.map +1 -0
- package/dist/src/model/blockRowData.js +28 -28
- package/dist/src/model/blockRowData.js.map +1 -1
- package/dist/src/timeline-element.d.ts +406 -388
- package/dist/src/timeline-element.d.ts.map +1 -0
- package/dist/src/timeline-element.js +1987 -1987
- package/dist/src/timeline-element.js.map +1 -1
- package/dist/src/util/dateTimeUtil.d.ts +21 -14
- package/dist/src/util/dateTimeUtil.d.ts.map +1 -0
- package/dist/src/util/dateTimeUtil.js +42 -55
- package/dist/src/util/dateTimeUtil.js.map +1 -1
- package/dist/src/util/elementUtil.d.ts +5 -4
- package/dist/src/util/elementUtil.d.ts.map +1 -0
- package/dist/src/util/elementUtil.js +48 -48
- package/dist/src/util/elementUtil.js.map +1 -1
- package/dist/src/util/zonedTime.d.ts +85 -0
- package/dist/src/util/zonedTime.d.ts.map +1 -0
- package/dist/src/util/zonedTime.js +239 -0
- package/dist/src/util/zonedTime.js.map +1 -0
- package/package.json +53 -24
- package/src/model/DefaultLocaleDataProvider.ts +32 -66
- package/src/model/ILocaleDataProvider.ts +10 -2
- package/src/model/IResolutionBlockFiller.ts +1 -1
- package/src/model/IResolutionBlockRegisterer.ts +1 -1
- package/src/model/blockRowData.ts +4 -4
- package/src/timeline-element.ts +380 -372
- package/src/util/dateTimeUtil.ts +16 -29
- package/src/util/elementUtil.ts +4 -4
- package/src/util/zonedTime.ts +280 -0
- package/server.js +0 -18
- package/src/index.html +0 -112
- package/tsconfig.json +0 -15
- package/webpack.config.js +0 -33
package/README.md
CHANGED
|
@@ -1,9 +1,131 @@
|
|
|
1
|
-
|
|
1
|
+
# timeline-element
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`<timeline-element>` is a scalable, time zone aware timeline header web
|
|
4
|
+
component built with [Lit](https://lit.dev). It renders a date range as rows of
|
|
5
|
+
year, month and day blocks above a resolution row of hours, days, weeks, months
|
|
6
|
+
or years, and provides an API for converting between dates and horizontal
|
|
7
|
+
positions. That makes it a foundation for scheduling views such as Gantt charts
|
|
8
|
+
([tltv-gantt-element](https://github.com/tltv/gantt-element) is built on it).
|
|
4
9
|
|
|
5
|
-
|
|
6
|
-
|
|
10
|
+
## Features
|
|
11
|
+
|
|
12
|
+
- **Five resolutions:** `Hour`, `Day`, `Week`, `Month` and `Year`.
|
|
13
|
+
- **Time zone aware:** dates, weekdays, week numbers and the current-date highlight
|
|
14
|
+
are calculated in the configured IANA time zone, independent of the browser's
|
|
15
|
+
own zone. Daylight saving time switches (23 and 25 hour days, repeated or
|
|
16
|
+
skipped hours) are handled correctly.
|
|
17
|
+
- **Scales to fit:** the timeline stretches to fill its container, and switches
|
|
18
|
+
to minimum-width blocks with horizontal scrolling when the range doesn't fit.
|
|
19
|
+
Only the visible blocks are rendered while scrolling.
|
|
20
|
+
- **Positioning API:** convert dates to pixel or percentage positions and widths,
|
|
21
|
+
and pixel positions back to dates, for placing content on the timeline.
|
|
22
|
+
- **Current date highlight**, weekend highlighting, 12/24 hour clock and a
|
|
23
|
+
configurable first day of the week.
|
|
24
|
+
- **Themeable** with CSS custom properties.
|
|
25
|
+
- **No runtime dependencies besides Lit** (2.8+ or 3); date and time zone
|
|
26
|
+
handling uses the native `Intl` API.
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
```sh
|
|
31
|
+
npm install tltv-timeline-element lit
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
[Lit](https://lit.dev) is a peer dependency: Lit 2.8+ and Lit 3 are supported, so
|
|
35
|
+
the timeline shares the Lit version of your application instead of bundling its
|
|
36
|
+
own copy.
|
|
37
|
+
|
|
38
|
+
## Usage
|
|
39
|
+
|
|
40
|
+
```js
|
|
41
|
+
import 'tltv-timeline-element'; // registers <timeline-element>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
```html
|
|
45
|
+
<timeline-element
|
|
46
|
+
resolution="Day"
|
|
47
|
+
startdatetime="2020-04-01"
|
|
48
|
+
enddatetime="2020-06-30"
|
|
49
|
+
timezone="Europe/Helsinki"
|
|
50
|
+
currentdatevisible>
|
|
51
|
+
</timeline-element>
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
The package is published as ES modules with TypeScript declarations. Individual
|
|
55
|
+
modules such as `tltv-timeline-element/dist/src/model/Resolution.js` can also be
|
|
56
|
+
imported directly.
|
|
57
|
+
|
|
58
|
+
### Attributes
|
|
59
|
+
|
|
60
|
+
| Attribute | Property | Description |
|
|
61
|
+
| --- | --- | --- |
|
|
62
|
+
| `resolution` | `resolution` | `Hour`, `Day` (default), `Week`, `Month` or `Year`. |
|
|
63
|
+
| `startdatetime` | `startDateTime` | Inclusive start, e.g. `2020-04-01`, or `2020-04-01T08` for `Hour`. |
|
|
64
|
+
| `enddatetime` | `endDateTime` | Inclusive end, same format as the start. |
|
|
65
|
+
| `timezone` | `timeZone` | IANA time zone. Default `Europe/London`. |
|
|
66
|
+
| `locale` | `locale` | Locale for time formatting. Default `en-US`. |
|
|
67
|
+
| `firstdayofweek` | `firstDayOfWeek` | First day of the week, `1` (Sunday, default) to `7` (Saturday). |
|
|
68
|
+
| `twelvehourclock` | `twelveHourClock` | Show hours in 12 hour format. |
|
|
69
|
+
| `currentdatevisible` | `currentDateVisible` | Highlight the current hour, day, week, month or year. |
|
|
70
|
+
| `scrollcontainerid` | `scrollContainerId` | Id of the element whose horizontal scrolling the timeline follows. Defaults to the parent element. |
|
|
71
|
+
| `yearrowvisible`, `monthrowvisible` | `yearRowVisible`, `monthRowVisible` | Show the year and month header rows (default). Hide with `yearrowvisible="false"` / `monthrowvisible="false"`. |
|
|
72
|
+
| | `monthNames` | Custom month names, January first. |
|
|
73
|
+
| `debug` | `debug` | Log diagnostic messages to the browser console. |
|
|
74
|
+
|
|
75
|
+
### Positioning API
|
|
76
|
+
|
|
77
|
+
| Method | Returns |
|
|
78
|
+
| --- | --- |
|
|
79
|
+
| `getLeftPositionForDate(date)` | Left offset of a date in pixels. |
|
|
80
|
+
| `getLeftPositionPercentageStringForDate(date, contentWidth)` | Left offset as a CSS percentage, relative to a content area of the given width. |
|
|
81
|
+
| `getLeftPositionPercentageStringForDateRange(date, rangeWidth, rangeStart, rangeEnd)` | Left offset as a CSS percentage within a nested date range. |
|
|
82
|
+
| `getWidthPercentageStringForDateInterval(interval)` | Width of a time interval (ms) as a CSS percentage of the timeline. |
|
|
83
|
+
| `getWidthPercentageStringForDateIntervalForRange(interval, range)` | Width of an interval as a CSS percentage of another range (ms). |
|
|
84
|
+
| `getDateForLeftPosition(left)` | Date at a pixel offset, e.g. for click and drag handling. |
|
|
85
|
+
| `getResolutionWidth()`, `isTimelineOverflowingHorizontally()` | Current timeline width and overflow state. |
|
|
86
|
+
| `refreshCurrentDate()` | Moves the current-date highlight without rebuilding the timeline. |
|
|
87
|
+
|
|
88
|
+
## Development
|
|
89
|
+
|
|
90
|
+
```sh
|
|
91
|
+
npm install
|
|
92
|
+
npm start # Vite dev server with the demo page (index.html)
|
|
93
|
+
npm run build # compile to dist/src (ES modules + type declarations) and generate custom-elements.json
|
|
94
|
+
npm run watch # recompile on change
|
|
95
|
+
npm run lint # ESLint (TypeScript, Lit and web component rules)
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
`dist/` and `custom-elements.json` are build output and are not committed;
|
|
99
|
+
`npm pack` and `npm publish` build them automatically (`prepack`).
|
|
100
|
+
|
|
101
|
+
The [Custom Elements Manifest](https://custom-elements-manifest.open-wc.org/)
|
|
102
|
+
(`custom-elements.json`) describes the element's attributes, properties,
|
|
103
|
+
methods and CSS custom properties for IDEs and documentation tools.
|
|
104
|
+
|
|
105
|
+
## Continuous integration
|
|
106
|
+
|
|
107
|
+
The CI workflow (`.github/workflows/ci.yml`) runs lint, build and the tests on
|
|
108
|
+
every pull request.
|
|
109
|
+
|
|
110
|
+
## Testing
|
|
111
|
+
|
|
112
|
+
Tests run with [Vitest](https://vitest.dev) browser mode in real browsers (the
|
|
113
|
+
timeline measures layout, which jsdom can't do).
|
|
114
|
+
|
|
115
|
+
```sh
|
|
116
|
+
npm run test:install-browsers # once: downloads Chromium, Firefox and WebKit
|
|
117
|
+
npm test # full matrix
|
|
118
|
+
npm run test:quick # Chromium in one time zone
|
|
119
|
+
npm run test:watch # watch mode
|
|
120
|
+
npm run test:visual # visible browser, pauses 1s after each render
|
|
121
|
+
npm run test:typecheck # type-check tests
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Every test runs in Chromium under several *browser* time zones (UTC,
|
|
125
|
+
Europe/Helsinki, America/New_York, Australia/Sydney, Asia/Kolkata), and once in
|
|
126
|
+
Firefox and WebKit, because parts of the date logic depend on the browser's
|
|
127
|
+
time zone. See `vitest.config.mts`. Tests marked `test.fails` document known
|
|
128
|
+
bugs; they start failing (and must be flipped) once the bug is fixed.
|
|
7
129
|
|
|
8
130
|
## Resolutions
|
|
9
131
|
|
|
@@ -17,11 +139,13 @@ The `resolution` attribute accepts `Hour`, `Day`, `Week`, `Month` and `Year`.
|
|
|
17
139
|
- With `Month` resolution the month header row is not shown, and with `Year`
|
|
18
140
|
resolution the year header row is not shown, as the resolution row already
|
|
19
141
|
shows the same information.
|
|
20
|
-
- Minimum block widths
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
1px
|
|
142
|
+
- Minimum block widths can be set with the `--timeline-col-min-width` (day and
|
|
143
|
+
hour), `--timeline-col-week-min-width` (one week),
|
|
144
|
+
`--timeline-col-month-min-width` (a 30 day month) and
|
|
145
|
+
`--timeline-col-year-min-width` (a 365 day year) CSS custom properties. The
|
|
146
|
+
width includes the block's 1px border. Defaults: the width of the text "MM"
|
|
147
|
+
for days and hours, 4px per day for weeks and months, and 1px per day for
|
|
148
|
+
years. Minimum widths are measured when the resolution is set.
|
|
25
149
|
|
|
26
150
|
## Styling
|
|
27
151
|
|
|
@@ -37,4 +161,18 @@ customized with the following CSS custom properties (defaults in parentheses):
|
|
|
37
161
|
| `--timeline-col-background-color` (`#ddd`) | Background of resolution blocks. |
|
|
38
162
|
| `--timeline-col-even-background-color` (`#ccc`) | Background of even resolution blocks. |
|
|
39
163
|
| `--timeline-col-weekend` (`#ccc`) | Background of weekend resolution blocks. |
|
|
40
|
-
| `--timeline-col-font-size` (`10px`) | Font size of resolution blocks. |
|
|
164
|
+
| `--timeline-col-font-size` (`10px`) | Font size of resolution blocks. |
|
|
165
|
+
| `--timeline-col-current` (`#ffe082`) | Background of the current-date highlight. |
|
|
166
|
+
| `--timeline-col-min-width` | Minimum width of a day or hour block. |
|
|
167
|
+
| `--timeline-col-week-min-width` | Minimum width of a week block. |
|
|
168
|
+
| `--timeline-col-month-min-width` | Minimum width of a 30 day month block. |
|
|
169
|
+
| `--timeline-col-year-min-width` | Minimum width of a 365 day year block. |
|
|
170
|
+
|
|
171
|
+
## Background
|
|
172
|
+
|
|
173
|
+
The component originates from the timeline widget of the Gantt add-on for
|
|
174
|
+
Vaadin Framework 8 (GWT), rewritten as a standalone web component.
|
|
175
|
+
|
|
176
|
+
## License
|
|
177
|
+
|
|
178
|
+
[MIT](LICENSE)
|