@operato/event-view 8.0.0-alpha.4 → 8.0.0-beta.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.
- package/CHANGELOG.md +80 -0
- package/dist/src/calendar-monthly-styles.js +17 -5
- package/dist/src/calendar-monthly-styles.js.map +1 -1
- package/dist/src/calendar-monthly.d.ts +5 -0
- package/dist/src/calendar-monthly.js +68 -5
- package/dist/src/calendar-monthly.js.map +1 -1
- package/dist/src/calendar-weekly-styles.js +14 -3
- package/dist/src/calendar-weekly-styles.js.map +1 -1
- package/dist/src/calendar-weekly.d.ts +12 -0
- package/dist/src/calendar-weekly.js +83 -4
- package/dist/src/calendar-weekly.js.map +1 -1
- package/dist/src/ox-event-view.js +2 -1
- package/dist/src/ox-event-view.js.map +1 -1
- package/dist/src/types.d.ts +1 -1
- package/dist/src/types.js.map +1 -1
- package/dist/stories/index.stories.d.ts +1 -1
- package/dist/stories/index.stories.js +9 -2
- package/dist/stories/index.stories.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +10 -10
- package/src/calendar-monthly-styles.ts +17 -5
- package/src/calendar-monthly.ts +88 -6
- package/src/calendar-weekly-styles.ts +14 -3
- package/src/calendar-weekly.ts +108 -4
- package/src/ox-event-view.ts +2 -1
- package/src/types.ts +1 -1
- package/stories/index.stories.ts +10 -3
- package/themes/calendar-theme.css +4 -1
package/src/calendar-weekly.ts
CHANGED
|
@@ -18,6 +18,9 @@ export class CalendarWeekly extends LitElement {
|
|
|
18
18
|
@state() week: number = dayjs().week()
|
|
19
19
|
@state() calendar?: CALENDAR
|
|
20
20
|
@state() eventMap?: Map<Date, BizEvent[]>
|
|
21
|
+
@state() selections?: [Date, Date]
|
|
22
|
+
|
|
23
|
+
@state() pointerDownDate?: Date | null
|
|
21
24
|
|
|
22
25
|
render() {
|
|
23
26
|
return html`
|
|
@@ -54,14 +57,28 @@ export class CalendarWeekly extends LitElement {
|
|
|
54
57
|
<slot></slot>
|
|
55
58
|
</div>
|
|
56
59
|
|
|
57
|
-
<ol
|
|
60
|
+
<ol
|
|
61
|
+
@pointerdown=${this.handlePointerDown}
|
|
62
|
+
@pointermove=${this.handlePointerMove}
|
|
63
|
+
@pointerup=${this.handlePointerUp}
|
|
64
|
+
>
|
|
58
65
|
${this.calendar?.map((date, index) => {
|
|
66
|
+
const [from, to] = this.selections || ([] as any)
|
|
67
|
+
const { date: thisDate } = date
|
|
68
|
+
const selected = from && to && thisDate >= from && thisDate <= to
|
|
69
|
+
|
|
59
70
|
return html`
|
|
60
|
-
<li ?today=${date.today} day-of-week
|
|
71
|
+
<li ?today=${date.today} day-of-week date .date=${thisDate} ?selected=${selected}>
|
|
72
|
+
<span date-label>${date.label}(${WEEKDAYS[index]})</span>
|
|
73
|
+
</li>
|
|
61
74
|
`
|
|
62
75
|
})}
|
|
63
76
|
${this.calendar?.map(date => {
|
|
64
|
-
|
|
77
|
+
const [from, to] = this.selections || ([] as any)
|
|
78
|
+
const { date: thisDate } = date
|
|
79
|
+
const selected = from && to && thisDate >= from && thisDate <= to
|
|
80
|
+
|
|
81
|
+
return html`<li date .date=${thisDate} ?selected=${selected}>
|
|
65
82
|
<div>
|
|
66
83
|
${(this.eventMap?.get(date?.date) || []).map(({ title, color, template }) =>
|
|
67
84
|
template ? template : html`<span event .style="border-color: ${color};">${title}</span>`
|
|
@@ -74,7 +91,7 @@ export class CalendarWeekly extends LitElement {
|
|
|
74
91
|
}
|
|
75
92
|
|
|
76
93
|
async updated(changes: PropertyValues<this>) {
|
|
77
|
-
if (changes.has('year') || changes.has('month') || changes.has('week')) {
|
|
94
|
+
if (changes.has('year') || changes.has('month') || changes.has('week') || changes.has('eventProvider')) {
|
|
78
95
|
const calendar = this.createDaysForCurrentWeek(this.year, this.week)
|
|
79
96
|
|
|
80
97
|
this.eventMap = await this.eventProvider?.fetchEventsForCalendar(calendar)
|
|
@@ -88,6 +105,93 @@ export class CalendarWeekly extends LitElement {
|
|
|
88
105
|
this.week = week
|
|
89
106
|
}
|
|
90
107
|
|
|
108
|
+
handlePointerDown(event: PointerEvent) {
|
|
109
|
+
const target = event.target as HTMLElement
|
|
110
|
+
|
|
111
|
+
if (!target.hasAttribute('date') && !target.hasAttribute('date-label')) {
|
|
112
|
+
return
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const dateElement = target.closest('[date]') as HTMLElement
|
|
116
|
+
const from = (dateElement as any).date
|
|
117
|
+
|
|
118
|
+
this.pointerDownDate = from
|
|
119
|
+
|
|
120
|
+
// 캡처를 설정하지 않음(Touch 디바이스에서 중요)
|
|
121
|
+
target.releasePointerCapture(event.pointerId)
|
|
122
|
+
|
|
123
|
+
event.preventDefault()
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
handlePointerMove(event: PointerEvent) {
|
|
127
|
+
const from = this.pointerDownDate
|
|
128
|
+
|
|
129
|
+
if (!from) {
|
|
130
|
+
return
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const target = event.target as HTMLElement
|
|
134
|
+
const dateElement = target.closest('[date]') as HTMLElement
|
|
135
|
+
|
|
136
|
+
if (!dateElement) {
|
|
137
|
+
return
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const date = (dateElement as any).date
|
|
141
|
+
this.selections = from > date ? [date, from] : [from, date]
|
|
142
|
+
|
|
143
|
+
// 캡처를 설정하지 않음(Touch 디바이스에서 중요)
|
|
144
|
+
target.releasePointerCapture(event.pointerId)
|
|
145
|
+
|
|
146
|
+
event.preventDefault()
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
handlePointerUp(event: PointerEvent) {
|
|
150
|
+
const from = this.pointerDownDate
|
|
151
|
+
|
|
152
|
+
this.pointerDownDate = null
|
|
153
|
+
|
|
154
|
+
if (!from) {
|
|
155
|
+
return
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const target = event.target as HTMLElement
|
|
159
|
+
const dateElement = target.closest('[date]') as HTMLElement
|
|
160
|
+
|
|
161
|
+
if (!dateElement) {
|
|
162
|
+
return
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const date = (dateElement as any).date
|
|
166
|
+
this.selections = from > date ? [date, from] : [from, date]
|
|
167
|
+
|
|
168
|
+
this.dispatchEvent(
|
|
169
|
+
new CustomEvent('select-date', {
|
|
170
|
+
detail: this.selections,
|
|
171
|
+
bubbles: true,
|
|
172
|
+
composed: true
|
|
173
|
+
})
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
event.preventDefault()
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
selectDate(date: { label: string; date: Date; thisMonth?: boolean; thisWeek?: boolean; today?: boolean }) {
|
|
180
|
+
if (date) {
|
|
181
|
+
this.selections = [date.date, date.date]
|
|
182
|
+
} else {
|
|
183
|
+
this.selections = undefined
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
this.dispatchEvent(
|
|
187
|
+
new CustomEvent('select-date', {
|
|
188
|
+
detail: date,
|
|
189
|
+
bubbles: true,
|
|
190
|
+
composed: true
|
|
191
|
+
})
|
|
192
|
+
)
|
|
193
|
+
}
|
|
194
|
+
|
|
91
195
|
getLastDateOfWeek(year: number, week: number): Dayjs {
|
|
92
196
|
const firstWeekLastDay = dayjs(new Date(year, 0, 1)).endOf('w')
|
|
93
197
|
week -= 1 // one-based week, so need the minus-one
|
package/src/ox-event-view.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -23,7 +23,7 @@ export type CALENDAR = {
|
|
|
23
23
|
}[]
|
|
24
24
|
|
|
25
25
|
export interface EventProvider {
|
|
26
|
-
fetchEventsForCalendar(calendar: CALENDAR): Map<Date, BizEvent[]
|
|
26
|
+
fetchEventsForCalendar(calendar: CALENDAR): Promise<Map<Date, BizEvent[]>>
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
export const WEEKDAYS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
|
package/stories/index.stories.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { html, TemplateResult } from 'lit'
|
|
|
3
3
|
import { BizEvent, CALENDAR, EventProvider } from '../src/types.js'
|
|
4
4
|
|
|
5
5
|
class SampleEventProvider implements EventProvider {
|
|
6
|
-
fetchEventsForCalendar(calendar: CALENDAR) {
|
|
6
|
+
async fetchEventsForCalendar(calendar: CALENDAR) {
|
|
7
7
|
const map = new Map<Date, BizEvent[]>()
|
|
8
8
|
|
|
9
9
|
calendar.forEach(({ date }) =>
|
|
@@ -75,7 +75,7 @@ interface Story<T> {
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
interface ArgTypes {
|
|
78
|
-
mode?:
|
|
78
|
+
mode?: 'monthly' | 'weekly'
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
const Template: Story<ArgTypes> = ({ mode = 'monthly' }: ArgTypes) => html`
|
|
@@ -102,7 +102,14 @@ const Template: Story<ArgTypes> = ({ mode = 'monthly' }: ArgTypes) => html`
|
|
|
102
102
|
rel="stylesheet"
|
|
103
103
|
/>
|
|
104
104
|
|
|
105
|
-
<ox-event-view
|
|
105
|
+
<ox-event-view
|
|
106
|
+
mode="${mode}"
|
|
107
|
+
.eventProvider=${new SampleEventProvider()}
|
|
108
|
+
@select-date=${(e: CustomEvent) => {
|
|
109
|
+
console.log(e.detail)
|
|
110
|
+
}}
|
|
111
|
+
>
|
|
112
|
+
</ox-event-view>
|
|
106
113
|
`
|
|
107
114
|
|
|
108
115
|
export const Regular = Template.bind({})
|
|
@@ -9,7 +9,8 @@ body {
|
|
|
9
9
|
/* monthly layout */
|
|
10
10
|
--calendar-monthly-ol-margin: var(--margin-default) 0;
|
|
11
11
|
--calendar-monthly-ol-top-border: 2px solid var(--md-sys-color-secondary);
|
|
12
|
-
--calendar-current-
|
|
12
|
+
--calendar-current-month-background-color: var(--md-sys-color-surface-variant);
|
|
13
|
+
--calendar-current-month-color: var(--md-sys-color-on-surface);
|
|
13
14
|
--calendar-monthly-label-align: left;
|
|
14
15
|
--calendar-monthly-label-padding: var(--padding-narrow) 0;
|
|
15
16
|
--calendar-monthly-label-color: var(--md-sys-color-secondary);
|
|
@@ -18,6 +19,7 @@ body {
|
|
|
18
19
|
--calendar-monthly-date-label-margin: var(--margin-narrow);
|
|
19
20
|
--calendar-monthly-date-label-padding: 0px 6px;
|
|
20
21
|
--calendar-monthly-date-label-color: var(--md-sys-color-on-primary);
|
|
22
|
+
--calendar-monthly-date-min-height: 120px;
|
|
21
23
|
|
|
22
24
|
--calendar-monthly-background-color: #f4f4f4;
|
|
23
25
|
--calendar-monthly-event-border-radius: var(--border-radius);
|
|
@@ -35,6 +37,7 @@ body {
|
|
|
35
37
|
--calendar-weekly-ol-margin: var(--margin-default) 0;
|
|
36
38
|
--calendar-weekly-ol-top-border: 2px solid var(--md-sys-color-secondary);
|
|
37
39
|
--calendar-current-week-background-color: var(--md-sys-color-surface-variant);
|
|
40
|
+
--calendar-current-week-color: var(--md-sys-color-on-surface);
|
|
38
41
|
--calendar-weekly-label-align: center;
|
|
39
42
|
--calendar-weekly-label-padding: var(--padding-narrow) 0;
|
|
40
43
|
--calendar-weekly-label-color: var(--md-sys-color-secondary);
|