@operato/event-view 1.2.21 → 1.2.23
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/CHANGELOG.md +21 -0
- package/dist/src/calendar-monthly-styles.js +6 -1
- package/dist/src/calendar-monthly-styles.js.map +1 -1
- package/dist/src/calendar-monthly.d.ts +5 -12
- package/dist/src/calendar-monthly.js +27 -29
- package/dist/src/calendar-monthly.js.map +1 -1
- package/dist/src/calendar-weekly-styles.js +2 -2
- package/dist/src/calendar-weekly-styles.js.map +1 -1
- package/dist/src/calendar-weekly.d.ts +5 -12
- package/dist/src/calendar-weekly.js +22 -30
- package/dist/src/calendar-weekly.js.map +1 -1
- package/dist/src/common.d.ts +15 -0
- package/dist/src/common.js +13 -0
- package/dist/src/common.js.map +1 -0
- package/dist/src/event-provider.d.ts +2 -3
- package/dist/src/event-provider.js.map +1 -1
- package/dist/src/index.d.ts +2 -1
- package/dist/src/index.js +2 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/ox-event-view.d.ts +2 -0
- package/dist/src/ox-event-view.js +5 -3
- package/dist/src/ox-event-view.js.map +1 -1
- package/dist/src/sample-event-provider.d.ts +3 -2
- package/dist/src/sample-event-provider.js +100 -4
- package/dist/src/sample-event-provider.js.map +1 -1
- package/dist/src/types.d.ts +20 -0
- package/dist/src/types.js +13 -0
- package/dist/src/types.js.map +1 -0
- package/dist/stories/index.stories.js +54 -1
- package/dist/stories/index.stories.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -2
- package/src/calendar-monthly-styles.ts +6 -1
- package/src/calendar-monthly.ts +24 -44
- package/src/calendar-weekly-styles.ts +2 -2
- package/src/calendar-weekly.ts +18 -45
- package/src/index.ts +2 -1
- package/src/ox-event-view.ts +4 -3
- package/src/types.ts +38 -0
- package/stories/index.stories.ts +60 -2
- package/themes/calendar-theme.css +1 -2
- package/src/biz-event.ts +0 -6
- package/src/event-provider.ts +0 -6
- package/src/sample-event-provider.ts +0 -116
package/src/calendar-weekly.ts
CHANGED
|
@@ -1,46 +1,23 @@
|
|
|
1
1
|
import dayjs, { Dayjs } from 'dayjs/esm/index'
|
|
2
|
-
import weekday from 'dayjs/esm/plugin/weekday'
|
|
3
|
-
import weekOfYear from 'dayjs/esm/plugin/weekOfYear'
|
|
4
2
|
import { html, LitElement, PropertyValues } from 'lit'
|
|
5
|
-
import { customElement, property } from 'lit/decorators.js'
|
|
3
|
+
import { customElement, property, state } from 'lit/decorators.js'
|
|
6
4
|
|
|
7
|
-
import { BizEvent } from './biz-event'
|
|
8
5
|
import { CalendarWeeklyStyles } from './calendar-weekly-styles'
|
|
9
|
-
import { EventProvider } from './
|
|
10
|
-
|
|
11
|
-
dayjs.extend(weekday)
|
|
12
|
-
dayjs.extend(weekOfYear)
|
|
13
|
-
|
|
14
|
-
const WEEKDAYS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
|
|
15
|
-
|
|
16
|
-
function isToday(date: Date) {
|
|
17
|
-
const today = new Date()
|
|
18
|
-
return (
|
|
19
|
-
date.getDate() == today.getDate() &&
|
|
20
|
-
date.getMonth() == today.getMonth() &&
|
|
21
|
-
date.getFullYear() == today.getFullYear()
|
|
22
|
-
)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
type CALENDAR = {
|
|
26
|
-
label: string
|
|
27
|
-
date: Date
|
|
28
|
-
thisWeek: boolean
|
|
29
|
-
today?: boolean
|
|
30
|
-
}[]
|
|
6
|
+
import { BizEvent, CALENDAR, WEEKDAYS, EventProvider, isToday } from './types'
|
|
31
7
|
|
|
32
8
|
@customElement('calendar-weekly')
|
|
33
9
|
export class CalendarWeekly extends LitElement {
|
|
34
10
|
static styles = [CalendarWeeklyStyles]
|
|
35
11
|
|
|
36
|
-
@property({ type: Number }) year: number = dayjs().year()
|
|
37
|
-
@property({ type: Number }) month: number = dayjs().month()
|
|
38
|
-
@property({ type: Number }) week: number = dayjs().week()
|
|
39
12
|
@property({ type: Array }) eventProvider?: EventProvider
|
|
40
13
|
|
|
41
|
-
|
|
42
|
-
|
|
14
|
+
@state() year: number = dayjs().year()
|
|
15
|
+
@state() month: number = dayjs().month()
|
|
16
|
+
@state() week: number = dayjs().week()
|
|
17
|
+
@state() calendar?: CALENDAR
|
|
18
|
+
@state() eventMap?: Map<Date, BizEvent[]>
|
|
43
19
|
|
|
20
|
+
render() {
|
|
44
21
|
return html`
|
|
45
22
|
<div head>
|
|
46
23
|
<div this-week>
|
|
@@ -49,7 +26,6 @@ export class CalendarWeekly extends LitElement {
|
|
|
49
26
|
|
|
50
27
|
<div nav>
|
|
51
28
|
<mwc-button
|
|
52
|
-
outlined
|
|
53
29
|
@click=${() => {
|
|
54
30
|
const dayJs = this.getLastDateOfWeek(this.year, this.week)
|
|
55
31
|
const prevWeek = dayJs.subtract(1, 'week')
|
|
@@ -77,22 +53,16 @@ export class CalendarWeekly extends LitElement {
|
|
|
77
53
|
</div>
|
|
78
54
|
|
|
79
55
|
<ol>
|
|
80
|
-
${calendar
|
|
56
|
+
${this.calendar?.map((date, index) => {
|
|
81
57
|
return html`
|
|
82
58
|
<li ?today=${date.today} day-of-week><span date-label>${date.label}(${WEEKDAYS[index]})</span></li>
|
|
83
59
|
`
|
|
84
60
|
})}
|
|
85
|
-
${calendar
|
|
61
|
+
${this.calendar?.map(date => {
|
|
86
62
|
return html`<li day-task>
|
|
87
63
|
<div>
|
|
88
|
-
${this.
|
|
89
|
-
event
|
|
90
|
-
html`<span
|
|
91
|
-
@click=${() => event.clickEvent(event.title, event.due)}
|
|
92
|
-
event
|
|
93
|
-
.style="border-color: ${event.color};"
|
|
94
|
-
>${event.title}</span
|
|
95
|
-
>`
|
|
64
|
+
${(this.eventMap?.get(date?.date) || []).map(({ title, color, template }) =>
|
|
65
|
+
template ? template : html`<span event .style="border-color: ${color};">${title}</span>`
|
|
96
66
|
)}
|
|
97
67
|
</div>
|
|
98
68
|
</li>`
|
|
@@ -101,10 +71,13 @@ export class CalendarWeekly extends LitElement {
|
|
|
101
71
|
`
|
|
102
72
|
}
|
|
103
73
|
|
|
104
|
-
updated(changes: PropertyValues<this>) {
|
|
74
|
+
async updated(changes: PropertyValues<this>) {
|
|
75
|
+
if (changes.has('year') || changes.has('month') || changes.has('week')) {
|
|
76
|
+
const calendar = this.createDaysForCurrentWeek(this.year, this.week)
|
|
105
77
|
|
|
106
|
-
|
|
107
|
-
|
|
78
|
+
this.eventMap = await this.eventProvider?.fetchEventsForCalendar(calendar)
|
|
79
|
+
this.calendar = calendar
|
|
80
|
+
}
|
|
108
81
|
}
|
|
109
82
|
|
|
110
83
|
moveTo(year: number, month: number, week: number) {
|
package/src/index.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from './types.js'
|
|
2
|
+
export * from './ox-event-view.js'
|
package/src/ox-event-view.ts
CHANGED
|
@@ -6,7 +6,7 @@ import './calendar-weekly'
|
|
|
6
6
|
import { css, html, LitElement } from 'lit'
|
|
7
7
|
import { customElement, property } from 'lit/decorators.js'
|
|
8
8
|
|
|
9
|
-
import {
|
|
9
|
+
import { EventProvider } from './types'
|
|
10
10
|
|
|
11
11
|
@customElement('ox-event-view')
|
|
12
12
|
export class OxEventView extends LitElement {
|
|
@@ -25,16 +25,17 @@ export class OxEventView extends LitElement {
|
|
|
25
25
|
`
|
|
26
26
|
|
|
27
27
|
@property({ type: String }) mode: 'monthly' | 'weekly' = 'monthly'
|
|
28
|
+
@property({ type: Array }) eventProvider?: EventProvider
|
|
28
29
|
|
|
29
30
|
render() {
|
|
30
31
|
return this.mode == 'weekly'
|
|
31
32
|
? html`
|
|
32
|
-
<calendar-weekly .eventProvider=${
|
|
33
|
+
<calendar-weekly .eventProvider=${this.eventProvider}>
|
|
33
34
|
<mwc-icon @click=${(e: Event) => (this.mode = 'monthly')}>calendar_month</mwc-icon>
|
|
34
35
|
</calendar-weekly>
|
|
35
36
|
`
|
|
36
37
|
: html`
|
|
37
|
-
<calendar-monthly .eventProvider=${
|
|
38
|
+
<calendar-monthly .eventProvider=${this.eventProvider}>
|
|
38
39
|
<mwc-icon @click=${(e: Event) => (this.mode = 'weekly')}>calendar_view_week</mwc-icon>
|
|
39
40
|
</calendar-monthly>
|
|
40
41
|
`
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { TemplateResult } from 'lit'
|
|
2
|
+
import dayjs from 'dayjs/esm/index'
|
|
3
|
+
import weekday from 'dayjs/esm/plugin/weekday'
|
|
4
|
+
import weekOfYear from 'dayjs/esm/plugin/weekOfYear'
|
|
5
|
+
|
|
6
|
+
dayjs.extend(weekday)
|
|
7
|
+
dayjs.extend(weekOfYear)
|
|
8
|
+
|
|
9
|
+
export type BizEvent = {
|
|
10
|
+
due?: string
|
|
11
|
+
title: string
|
|
12
|
+
color: string
|
|
13
|
+
clickEvent?: any
|
|
14
|
+
template?: TemplateResult
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type CALENDAR = {
|
|
18
|
+
label: string
|
|
19
|
+
date: Date
|
|
20
|
+
thisMonth?: boolean
|
|
21
|
+
thisWeek?: boolean
|
|
22
|
+
today?: boolean
|
|
23
|
+
}[]
|
|
24
|
+
|
|
25
|
+
export interface EventProvider {
|
|
26
|
+
fetchEventsForCalendar(calendar: CALENDAR): Map<Date, BizEvent[]>
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const WEEKDAYS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
|
|
30
|
+
|
|
31
|
+
export function isToday(date: Date) {
|
|
32
|
+
const today = new Date()
|
|
33
|
+
return (
|
|
34
|
+
date.getDate() == today.getDate() &&
|
|
35
|
+
date.getMonth() == today.getMonth() &&
|
|
36
|
+
date.getFullYear() == today.getFullYear()
|
|
37
|
+
)
|
|
38
|
+
}
|
package/stories/index.stories.ts
CHANGED
|
@@ -1,6 +1,64 @@
|
|
|
1
1
|
import '../src/ox-event-view.js'
|
|
2
|
-
|
|
3
2
|
import { html, TemplateResult } from 'lit'
|
|
3
|
+
import { BizEvent, CALENDAR, EventProvider } from '../src/types.js'
|
|
4
|
+
|
|
5
|
+
class SampleEventProvider implements EventProvider {
|
|
6
|
+
fetchEventsForCalendar(calendar: CALENDAR) {
|
|
7
|
+
const map = new Map<Date, BizEvent[]>()
|
|
8
|
+
|
|
9
|
+
calendar.forEach(({ date }) =>
|
|
10
|
+
map.set(date, [
|
|
11
|
+
{
|
|
12
|
+
due: '2021-08-21',
|
|
13
|
+
title: 'HAHAHA',
|
|
14
|
+
color: 'yellow'
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
due: '2021-08-21',
|
|
18
|
+
title: 'HOHOHO',
|
|
19
|
+
color: 'lime'
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
due: '2021-08-21',
|
|
23
|
+
title: 'HIHIHI',
|
|
24
|
+
color: 'yellow'
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
due: '2021-08-21',
|
|
28
|
+
title: 'HEHEHE',
|
|
29
|
+
color: 'white'
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
due: '2021-08-21',
|
|
33
|
+
title: 'KEKEKE',
|
|
34
|
+
color: 'yellow'
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
due: '2021-08-21',
|
|
38
|
+
title: 'MEMEME',
|
|
39
|
+
color: 'orange'
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
due: '2021-08-21',
|
|
43
|
+
title: 'MOMOMO',
|
|
44
|
+
color: 'lime'
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
due: '2021-08-21',
|
|
48
|
+
title: 'QUOQUO',
|
|
49
|
+
color: 'navy'
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
due: '2021-08-21',
|
|
53
|
+
title: 'ZZXXCC',
|
|
54
|
+
color: 'gray'
|
|
55
|
+
}
|
|
56
|
+
])
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
return map
|
|
60
|
+
}
|
|
61
|
+
}
|
|
4
62
|
|
|
5
63
|
export default {
|
|
6
64
|
title: 'EventView',
|
|
@@ -26,7 +84,7 @@ const Template: Story<ArgTypes> = ({ mode = 'monthly' }: ArgTypes) =>
|
|
|
26
84
|
<link rel="stylesheet" href="/themes/calendar-theme.css" />
|
|
27
85
|
<link href="https://fonts.googleapis.com/css?family=Material+Icons&display=block" rel="stylesheet" />
|
|
28
86
|
|
|
29
|
-
<ox-event-view mode=${mode}> </ox-event-view>
|
|
87
|
+
<ox-event-view mode=${mode} .eventProvider=${new SampleEventProvider()}> </ox-event-view>
|
|
30
88
|
`
|
|
31
89
|
|
|
32
90
|
export const Regular = Template.bind({})
|
|
@@ -36,7 +36,7 @@ body {
|
|
|
36
36
|
--calendar-weekly-opacity: 0.5;
|
|
37
37
|
--calendar-weekly-date-label-background-color: var(--status-danger-color);
|
|
38
38
|
--calendar-weekly-date-label-margin: var(--margin-narrow);
|
|
39
|
-
--calendar-weekly-date-label-padding:
|
|
39
|
+
--calendar-weekly-date-label-padding: 3px var(--padding-narrow);
|
|
40
40
|
--calendar-weekly-date-label-color: var(--theme-white-color);
|
|
41
41
|
|
|
42
42
|
--calendar-weekly-background-color: #f4f4f4;
|
|
@@ -45,7 +45,6 @@ body {
|
|
|
45
45
|
--calendar-weekly-event-padding: 2px var(--padding-default);
|
|
46
46
|
--calendar-weekly-event-border: 3px solid #ccc;
|
|
47
47
|
--calendar-weekly-event-border-width: 0 0 0 3px;
|
|
48
|
-
|
|
49
48
|
}
|
|
50
49
|
|
|
51
50
|
@media only screen and (max-width: 460px) {
|
package/src/biz-event.ts
DELETED
package/src/event-provider.ts
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { EventProvider } from './event-provider'
|
|
2
|
-
|
|
3
|
-
export class SampleMonthlyEventProvider implements EventProvider {
|
|
4
|
-
fetchEventsForDate(date: Date, options: any) {
|
|
5
|
-
return [
|
|
6
|
-
{
|
|
7
|
-
due: '2021-08-21',
|
|
8
|
-
title: 'HAHAHA',
|
|
9
|
-
color: 'yellow'
|
|
10
|
-
},
|
|
11
|
-
{
|
|
12
|
-
due: '2021-08-21',
|
|
13
|
-
title: 'HOHOHO',
|
|
14
|
-
color: 'lime'
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
due: '2021-08-21',
|
|
18
|
-
title: 'HIHIHI',
|
|
19
|
-
color: 'yellow'
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
due: '2021-08-21',
|
|
23
|
-
title: 'HEHEHE',
|
|
24
|
-
color: 'white'
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
due: '2021-08-21',
|
|
28
|
-
title: 'KEKEKE',
|
|
29
|
-
color: 'yellow'
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
due: '2021-08-21',
|
|
33
|
-
title: 'MEMEME',
|
|
34
|
-
color: 'orange'
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
due: '2021-08-21',
|
|
38
|
-
title: 'MOMOMO',
|
|
39
|
-
color: 'lime'
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
due: '2021-08-21',
|
|
43
|
-
title: 'QUOQUO',
|
|
44
|
-
color: 'navy'
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
due: '2021-08-21',
|
|
48
|
-
title: 'ZZXXCC',
|
|
49
|
-
color: 'gray'
|
|
50
|
-
}
|
|
51
|
-
]
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
fetchEventsForDuration(from: Date, to: Date, options: any) {
|
|
55
|
-
return []
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export class SampleWeeklyEventProvider implements EventProvider {
|
|
60
|
-
fetchEventsForDate(date: Date, options: any) {
|
|
61
|
-
return [
|
|
62
|
-
{
|
|
63
|
-
due: '2021-08-21',
|
|
64
|
-
title: 'HAHAHA',
|
|
65
|
-
color: 'yellow',
|
|
66
|
-
clickEvent: function (title: string, due: string) {
|
|
67
|
-
console.log('clicked...', title, due)
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
due: '2021-08-21',
|
|
72
|
-
title: 'HOHOHO',
|
|
73
|
-
color: 'lime'
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
due: '2021-08-21',
|
|
77
|
-
title: 'HIHIHI',
|
|
78
|
-
color: 'yellow'
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
due: '2021-08-21',
|
|
82
|
-
title: 'HEHEHE',
|
|
83
|
-
color: 'white'
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
due: '2021-08-21',
|
|
87
|
-
title: 'KEKEKE',
|
|
88
|
-
color: 'yellow'
|
|
89
|
-
},
|
|
90
|
-
{
|
|
91
|
-
due: '2021-08-21',
|
|
92
|
-
title: 'MEMEME',
|
|
93
|
-
color: 'orange'
|
|
94
|
-
},
|
|
95
|
-
{
|
|
96
|
-
due: '2021-08-21',
|
|
97
|
-
title: 'MOMOMO',
|
|
98
|
-
color: 'lime'
|
|
99
|
-
},
|
|
100
|
-
{
|
|
101
|
-
due: '2021-08-21',
|
|
102
|
-
title: 'QUOQUO',
|
|
103
|
-
color: 'navy'
|
|
104
|
-
},
|
|
105
|
-
{
|
|
106
|
-
due: '2021-08-21',
|
|
107
|
-
title: 'ZZXXCC',
|
|
108
|
-
color: 'gray'
|
|
109
|
-
}
|
|
110
|
-
]
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
fetchEventsForDuration(from: Date, to: Date, options: any) {
|
|
114
|
-
return []
|
|
115
|
-
}
|
|
116
|
-
}
|