@g9tm/lynxcontrols-calendar 2.5.7 → 2.5.9
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/catalog/cards/G9AgendaView.md +4 -1
- package/catalog/cards/G9BirthdayField.md +14 -0
- package/catalog/cards/G9DateInput.md +3 -2
- package/catalog/cards/G9EventCard.md +17 -0
- package/catalog/cards/G9FindTime.md +16 -0
- package/catalog/cards/G9MiniMonth.md +2 -2
- package/catalog/cards/G9MonthView.md +6 -4
- package/catalog/cards/G9RepeatPicker.md +5 -1
- package/catalog/cards/G9TimeGrid.md +6 -6
- package/catalog/cards/G9TimeListPicker.md +17 -0
- package/catalog/cards/G9TodayWidget.md +16 -0
- package/catalog/cards/G9WorkingHoursEditor.md +16 -0
- package/catalog/catalog.json +3495 -564
- package/catalog/index.md +11 -5
- package/dist/.tsbuildinfo +1 -1
- package/dist/calendar.css +798 -2
- package/dist/calendar.css.map +1 -1
- package/dist/calendar.d.ts +83 -48
- package/dist/calendar.d.ts.map +1 -1
- package/dist/calendar.jsx +144 -254
- package/dist/cards.d.ts +131 -0
- package/dist/cards.d.ts.map +1 -0
- package/dist/cards.jsx +252 -0
- package/dist/events.d.ts +45 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.jsx +83 -0
- package/dist/gesture.d.ts +79 -0
- package/dist/gesture.d.ts.map +1 -0
- package/dist/gesture.jsx +160 -0
- package/dist/index.d.ts +10 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.jsx +10 -1
- package/dist/model.d.ts +9 -0
- package/dist/model.d.ts.map +1 -1
- package/dist/model.jsx +33 -4
- package/dist/month-view.d.ts +50 -0
- package/dist/month-view.d.ts.map +1 -0
- package/dist/month-view.jsx +362 -0
- package/dist/people.d.ts +67 -0
- package/dist/people.d.ts.map +1 -0
- package/dist/people.jsx +211 -0
- package/dist/recurrence.d.ts +51 -0
- package/dist/recurrence.d.ts.map +1 -0
- package/dist/recurrence.jsx +280 -0
- package/dist/repeat-picker.d.ts +47 -0
- package/dist/repeat-picker.d.ts.map +1 -0
- package/dist/repeat-picker.jsx +289 -0
- package/dist/time-grid.d.ts +50 -0
- package/dist/time-grid.d.ts.map +1 -0
- package/dist/time-grid.jsx +639 -0
- package/dist/time-list.d.ts +25 -0
- package/dist/time-list.d.ts.map +1 -0
- package/dist/time-list.jsx +85 -0
- package/package.json +3 -3
|
@@ -0,0 +1,639 @@
|
|
|
1
|
+
import { g9IdProps } from "@g9tm/lynxcontrols/base";
|
|
2
|
+
import { useG9Keys } from "@g9tm/lynxcontrols/commands";
|
|
3
|
+
import { useG9Back } from "@g9tm/lynxcontrols/host";
|
|
4
|
+
import { useG9Culture, useG9Direction } from "@g9tm/lynxcontrols/provider";
|
|
5
|
+
import { addDays, dayOfWeek, formatLocalDateTime, formatNumber, g9Haptic, toEpochDays } from "@g9tm/lynxcontrols-foundation";
|
|
6
|
+
import { runOnBackground, runOnMainThread, useEffect, useMainThreadRef, useRef, useState } from "@lynx-js/react";
|
|
7
|
+
import { eventLastDay, eventTouches, isBarEvent, layoutLanes, secondDateLabel } from "./events.jsx";
|
|
8
|
+
import { dragPreview, grabOffset, previewBar, previewBoxes, samePreview, tapDraft } from "./gesture.jsx";
|
|
9
|
+
import { layoutDay, sameDay, slotAt } from "./model.jsx";
|
|
10
|
+
const LANE = 24;
|
|
11
|
+
const MAX_LANES = 3;
|
|
12
|
+
const LONG_PRESS_MS = 420;
|
|
13
|
+
const IDLE = {
|
|
14
|
+
phase: 'idle',
|
|
15
|
+
source: 'touch',
|
|
16
|
+
x0: 0,
|
|
17
|
+
y0: 0,
|
|
18
|
+
t0: 0,
|
|
19
|
+
stamp: -1,
|
|
20
|
+
token: 0,
|
|
21
|
+
last: '',
|
|
22
|
+
begin: null,
|
|
23
|
+
grid: null,
|
|
24
|
+
allDay: null
|
|
25
|
+
};
|
|
26
|
+
const minutesOf = (e)=>{
|
|
27
|
+
var _e_end, _e_start, _e_start1;
|
|
28
|
+
return (null != (_e_end = e.end) ? _e_end : (null != (_e_start = e.start) ? _e_start : 0) + 60) - (null != (_e_start1 = e.start) ? _e_start1 : 0);
|
|
29
|
+
};
|
|
30
|
+
function DragCancel(props) {
|
|
31
|
+
useG9Back(()=>{
|
|
32
|
+
props.onCancel();
|
|
33
|
+
return true;
|
|
34
|
+
});
|
|
35
|
+
useG9Keys((e)=>'Escape' === e.key ? (props.onCancel(), true) : false);
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
function G9TimeGrid(props) {
|
|
39
|
+
var _props_days, _props_hourHeight, _props_fromHour, _props_toHour, _props_weekend, _props_secondCalendar, _props_moreText, _props_allDayText;
|
|
40
|
+
const culture = useG9Culture();
|
|
41
|
+
const rtl = 'rtl' === useG9Direction();
|
|
42
|
+
const calendar = culture.calendar;
|
|
43
|
+
const num = (n)=>formatNumber(n, {
|
|
44
|
+
numberingSystem: culture.numberingSystem,
|
|
45
|
+
useGrouping: false
|
|
46
|
+
});
|
|
47
|
+
const n = null != (_props_days = props.days) ? _props_days : 1;
|
|
48
|
+
const hh = null != (_props_hourHeight = props.hourHeight) ? _props_hourHeight : 52;
|
|
49
|
+
const from = null != (_props_fromHour = props.fromHour) ? _props_fromHour : 0;
|
|
50
|
+
const to = null != (_props_toHour = props.toHour) ? _props_toHour : 24;
|
|
51
|
+
const days = Array.from({
|
|
52
|
+
length: n
|
|
53
|
+
}, (_, i)=>addDays(props.start, i));
|
|
54
|
+
const y = (minutes)=>(minutes - 60 * from) / 60 * hh;
|
|
55
|
+
const side = rtl ? 'right' : 'left';
|
|
56
|
+
const weekend = null != (_props_weekend = props.weekend) ? _props_weekend : 'fa' === culture.language ? [
|
|
57
|
+
5
|
|
58
|
+
] : [
|
|
59
|
+
0,
|
|
60
|
+
6
|
|
61
|
+
];
|
|
62
|
+
const second = 'auto' === props.secondCalendar ? 'persian' === calendar ? 'gregorian' : 'persian' : null != (_props_secondCalendar = props.secondCalendar) ? _props_secondCalendar : 'none';
|
|
63
|
+
const editing = void 0 !== props.onCreate || void 0 !== props.onMove;
|
|
64
|
+
const [expanded, setExpanded] = useState(false);
|
|
65
|
+
const first = toEpochDays(props.start);
|
|
66
|
+
const bars = props.events.filter((e)=>isBarEvent(e) && toEpochDays(eventLastDay(e)) >= first && toEpochDays(e.date) <= first + n - 1).map((e)=>({
|
|
67
|
+
event: e,
|
|
68
|
+
start: Math.max(0, toEpochDays(e.date) - first),
|
|
69
|
+
end: Math.min(n - 1, toEpochDays(eventLastDay(e)) - first)
|
|
70
|
+
}));
|
|
71
|
+
const lanes = layoutLanes(bars.map((b)=>({
|
|
72
|
+
id: b.event.id,
|
|
73
|
+
start: b.start,
|
|
74
|
+
end: b.end
|
|
75
|
+
})));
|
|
76
|
+
const laneCount = Math.max(0, ...[
|
|
77
|
+
...lanes.values()
|
|
78
|
+
].map((l)=>l + 1));
|
|
79
|
+
const shownLanes = expanded ? laneCount : Math.min(laneCount, MAX_LANES);
|
|
80
|
+
const hiddenPerDay = days.map((_, i)=>bars.filter((b)=>{
|
|
81
|
+
var _lanes_get;
|
|
82
|
+
return (null != (_lanes_get = lanes.get(b.event.id)) ? _lanes_get : 0) >= shownLanes && b.start <= i && b.end >= i;
|
|
83
|
+
}).length);
|
|
84
|
+
const moreRow = expanded || hiddenPerDay.some((h)=>h > 0);
|
|
85
|
+
const allDayHeight = Math.max(1, shownLanes) * LANE + (moreRow ? 20 : 0);
|
|
86
|
+
const more = null != (_props_moreText = props.moreText) ? _props_moreText : (k)=>`+${num(k)}`;
|
|
87
|
+
const [preview, setPreview] = useState(null);
|
|
88
|
+
const [dragging, setDragging] = useState(false);
|
|
89
|
+
const gesture = useRef({
|
|
90
|
+
mode: 'create',
|
|
91
|
+
id: null,
|
|
92
|
+
entry: null,
|
|
93
|
+
from: null,
|
|
94
|
+
grab: 0,
|
|
95
|
+
dragging: false
|
|
96
|
+
});
|
|
97
|
+
const latest = useRef(props);
|
|
98
|
+
latest.current = props;
|
|
99
|
+
const toDraft = (p)=>{
|
|
100
|
+
const s = latest.current.start;
|
|
101
|
+
return {
|
|
102
|
+
allDay: p.allDay,
|
|
103
|
+
date: addDays(s, p.start),
|
|
104
|
+
start: p.startMinute,
|
|
105
|
+
endDate: addDays(s, p.end),
|
|
106
|
+
end: p.endMinute
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
const entryOf = (e)=>{
|
|
110
|
+
var _e_start;
|
|
111
|
+
return {
|
|
112
|
+
startOffset: toEpochDays(e.date) - toEpochDays(latest.current.start),
|
|
113
|
+
lastOffset: toEpochDays(eventLastDay(e)) - toEpochDays(latest.current.start),
|
|
114
|
+
startMinute: null != (_e_start = e.start) ? _e_start : 0,
|
|
115
|
+
duration: minutesOf(e),
|
|
116
|
+
allDay: void 0 === e.start,
|
|
117
|
+
bar: isBarEvent(e)
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
const begun = (mode, id, at)=>{
|
|
121
|
+
const e = id ? latest.current.events.find((x)=>x.id === id) : void 0;
|
|
122
|
+
const entry = e ? entryOf(e) : null;
|
|
123
|
+
gesture.current = {
|
|
124
|
+
mode,
|
|
125
|
+
id,
|
|
126
|
+
entry,
|
|
127
|
+
from: at,
|
|
128
|
+
grab: grabOffset(entry, at),
|
|
129
|
+
dragging: false
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
const moved = (at)=>{
|
|
133
|
+
const g = gesture.current;
|
|
134
|
+
if (!g.from) return;
|
|
135
|
+
if (!g.dragging) {
|
|
136
|
+
g.dragging = true;
|
|
137
|
+
setDragging(true);
|
|
138
|
+
g9Haptic('select');
|
|
139
|
+
}
|
|
140
|
+
const next = dragPreview(g.mode, g.entry, g.from, at, g.grab, n);
|
|
141
|
+
setPreview((p)=>samePreview(p, next) ? p : next);
|
|
142
|
+
};
|
|
143
|
+
const ended = (commit)=>{
|
|
144
|
+
const g = gesture.current;
|
|
145
|
+
gesture.current = {
|
|
146
|
+
mode: 'create',
|
|
147
|
+
id: null,
|
|
148
|
+
entry: null,
|
|
149
|
+
from: null,
|
|
150
|
+
grab: 0,
|
|
151
|
+
dragging: false
|
|
152
|
+
};
|
|
153
|
+
setDragging(false);
|
|
154
|
+
setPreview((p)=>{
|
|
155
|
+
if (commit && p && g.dragging) {
|
|
156
|
+
var _latest_current_onCreate, _latest_current;
|
|
157
|
+
const draft = toDraft(p);
|
|
158
|
+
if ('create' === g.mode) null == (_latest_current_onCreate = (_latest_current = latest.current).onCreate) || _latest_current_onCreate.call(_latest_current, draft);
|
|
159
|
+
else {
|
|
160
|
+
var _latest_current_onMove, _latest_current1;
|
|
161
|
+
const e = latest.current.events.find((x)=>x.id === g.id);
|
|
162
|
+
if (e) null == (_latest_current_onMove = (_latest_current1 = latest.current).onMove) || _latest_current_onMove.call(_latest_current1, e, draft);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return null;
|
|
166
|
+
});
|
|
167
|
+
};
|
|
168
|
+
const tapped = ()=>{
|
|
169
|
+
var _latest_current_onCreate, _latest_current;
|
|
170
|
+
const g = gesture.current;
|
|
171
|
+
gesture.current = {
|
|
172
|
+
mode: 'create',
|
|
173
|
+
id: null,
|
|
174
|
+
entry: null,
|
|
175
|
+
from: null,
|
|
176
|
+
grab: 0,
|
|
177
|
+
dragging: false
|
|
178
|
+
};
|
|
179
|
+
if (g.id) {
|
|
180
|
+
var _latest_current_onSelectEvent, _latest_current1;
|
|
181
|
+
const e = latest.current.events.find((x)=>x.id === g.id);
|
|
182
|
+
if (e) null == (_latest_current_onSelectEvent = (_latest_current1 = latest.current).onSelectEvent) || _latest_current_onSelectEvent.call(_latest_current1, e);
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
if (!g.from) return;
|
|
186
|
+
const draft = toDraft(tapDraft(g.from, n));
|
|
187
|
+
if (latest.current.onSelectSlot && 'grid' === g.from.region) latest.current.onSelectSlot(draft.date, g.from.minute);
|
|
188
|
+
else null == (_latest_current_onCreate = (_latest_current = latest.current).onCreate) || _latest_current_onCreate.call(_latest_current, draft);
|
|
189
|
+
};
|
|
190
|
+
const pointer = useMainThreadRef({
|
|
191
|
+
...IDLE
|
|
192
|
+
});
|
|
193
|
+
const gridRef = useMainThreadRef(null);
|
|
194
|
+
const allDayRef = useMainThreadRef(null);
|
|
195
|
+
const scrollerRef = useMainThreadRef(null);
|
|
196
|
+
const hoursFrom = from;
|
|
197
|
+
function locateMT(x, yy) {
|
|
198
|
+
'main thread';
|
|
199
|
+
const p = pointer.current;
|
|
200
|
+
const grid = p.grid;
|
|
201
|
+
const all = p.allDay;
|
|
202
|
+
if (!grid) return null;
|
|
203
|
+
const col = (r)=>{
|
|
204
|
+
if (r.width <= 0) return 0;
|
|
205
|
+
let f = rtl ? (r.left + r.width - x) / r.width : (x - r.left) / r.width;
|
|
206
|
+
f = Math.min(0.9999, Math.max(0, f));
|
|
207
|
+
return Math.floor(f * n);
|
|
208
|
+
};
|
|
209
|
+
if (all && yy < all.top + all.height) return {
|
|
210
|
+
region: 'allday',
|
|
211
|
+
index: col(all),
|
|
212
|
+
minute: 0
|
|
213
|
+
};
|
|
214
|
+
const raw = (yy - grid.top) / hh * 60 + 60 * hoursFrom;
|
|
215
|
+
const minute = Math.min(1440, Math.max(0, 15 * Math.round(raw / 15)));
|
|
216
|
+
return {
|
|
217
|
+
region: 'grid',
|
|
218
|
+
index: col(grid),
|
|
219
|
+
minute
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
function sendMT(x, yy, startOnly) {
|
|
223
|
+
'main thread';
|
|
224
|
+
const at = locateMT(x, yy);
|
|
225
|
+
if (!at) return;
|
|
226
|
+
const key = `${at.region}:${at.index}:${at.minute}`;
|
|
227
|
+
const p = pointer.current;
|
|
228
|
+
if (startOnly) {
|
|
229
|
+
p.last = key;
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
if (key === p.last && 'drag' === p.phase) return;
|
|
233
|
+
p.last = key;
|
|
234
|
+
runOnBackground(moved)(at);
|
|
235
|
+
}
|
|
236
|
+
function startDragMT() {
|
|
237
|
+
'main thread';
|
|
238
|
+
var _scrollerRef_current;
|
|
239
|
+
const p = pointer.current;
|
|
240
|
+
if ('pending' !== p.phase) return;
|
|
241
|
+
p.phase = 'drag';
|
|
242
|
+
if ('touch' === p.source) null == (_scrollerRef_current = scrollerRef.current) || _scrollerRef_current.setAttribute('enable-scroll', false);
|
|
243
|
+
}
|
|
244
|
+
function finishMT(commit) {
|
|
245
|
+
'main thread';
|
|
246
|
+
var _scrollerRef_current;
|
|
247
|
+
const p = pointer.current;
|
|
248
|
+
const wasDrag = 'drag' === p.phase;
|
|
249
|
+
if ('touch' === p.source) null == (_scrollerRef_current = scrollerRef.current) || _scrollerRef_current.setAttribute('enable-scroll', true);
|
|
250
|
+
pointer.current = {
|
|
251
|
+
...IDLE,
|
|
252
|
+
stamp: p.stamp,
|
|
253
|
+
token: p.token
|
|
254
|
+
};
|
|
255
|
+
if (wasDrag) runOnBackground(ended)(commit);
|
|
256
|
+
}
|
|
257
|
+
function beginMT(stamp, x, yy, source, mode, id, editable) {
|
|
258
|
+
'main thread';
|
|
259
|
+
var _ref;
|
|
260
|
+
var _gridRef_current, _allDayRef_current;
|
|
261
|
+
const p = pointer.current;
|
|
262
|
+
if (p.stamp === stamp && 'idle' !== p.phase) return;
|
|
263
|
+
if ('drag' === p.phase) return;
|
|
264
|
+
const token = p.token + 1;
|
|
265
|
+
pointer.current = {
|
|
266
|
+
...IDLE,
|
|
267
|
+
phase: 'pending',
|
|
268
|
+
source,
|
|
269
|
+
x0: x,
|
|
270
|
+
y0: yy,
|
|
271
|
+
t0: Date.now(),
|
|
272
|
+
stamp,
|
|
273
|
+
token
|
|
274
|
+
};
|
|
275
|
+
const opts = {};
|
|
276
|
+
const g = null == (_gridRef_current = gridRef.current) ? void 0 : _gridRef_current.invoke('boundingClientRect', opts);
|
|
277
|
+
if (!g) return;
|
|
278
|
+
const a = null != (_ref = null == (_allDayRef_current = allDayRef.current) ? void 0 : _allDayRef_current.invoke('boundingClientRect', opts)) ? _ref : Promise.resolve(null);
|
|
279
|
+
Promise.all([
|
|
280
|
+
g,
|
|
281
|
+
a
|
|
282
|
+
]).then((rects)=>{
|
|
283
|
+
const now = pointer.current;
|
|
284
|
+
if (now.token !== token) return;
|
|
285
|
+
const r0 = rects[0];
|
|
286
|
+
const r1 = rects[1];
|
|
287
|
+
now.grid = {
|
|
288
|
+
left: r0.left,
|
|
289
|
+
top: r0.top,
|
|
290
|
+
width: r0.width,
|
|
291
|
+
height: r0.height
|
|
292
|
+
};
|
|
293
|
+
now.allDay = r1 ? {
|
|
294
|
+
left: r1.left,
|
|
295
|
+
top: r1.top,
|
|
296
|
+
width: r1.width,
|
|
297
|
+
height: r1.height
|
|
298
|
+
} : null;
|
|
299
|
+
const at = locateMT(now.x0, now.y0);
|
|
300
|
+
if (!at) return;
|
|
301
|
+
const movable = 'create' === mode ? editing : editable;
|
|
302
|
+
now.begin = {
|
|
303
|
+
mode: movable ? mode : 'create',
|
|
304
|
+
id,
|
|
305
|
+
at
|
|
306
|
+
};
|
|
307
|
+
if (movable || 'create' === mode) sendMT(now.x0, now.y0, true);
|
|
308
|
+
else now.last = 'locked';
|
|
309
|
+
}, ()=>void 0);
|
|
310
|
+
}
|
|
311
|
+
function flushBeginMT() {
|
|
312
|
+
'main thread';
|
|
313
|
+
const p = pointer.current;
|
|
314
|
+
if (!p.begin) return;
|
|
315
|
+
const b = p.begin;
|
|
316
|
+
p.begin = null;
|
|
317
|
+
runOnBackground(begun)(b.mode, b.id, b.at);
|
|
318
|
+
}
|
|
319
|
+
function releaseMT() {
|
|
320
|
+
'main thread';
|
|
321
|
+
flushBeginMT();
|
|
322
|
+
const p = pointer.current;
|
|
323
|
+
if ('drag' === p.phase) return void finishMT(true);
|
|
324
|
+
if ('pending' === p.phase) {
|
|
325
|
+
pointer.current = {
|
|
326
|
+
...IDLE,
|
|
327
|
+
stamp: p.stamp,
|
|
328
|
+
token: p.token
|
|
329
|
+
};
|
|
330
|
+
runOnBackground(tapped)();
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
function abortMT() {
|
|
334
|
+
'main thread';
|
|
335
|
+
if ('idle' !== pointer.current.phase) finishMT(false);
|
|
336
|
+
}
|
|
337
|
+
function moveMT(x, yy, source) {
|
|
338
|
+
'main thread';
|
|
339
|
+
const p = pointer.current;
|
|
340
|
+
if (p.source !== source || 'idle' === p.phase) return;
|
|
341
|
+
flushBeginMT();
|
|
342
|
+
if ('pending' === p.phase) {
|
|
343
|
+
const d = Math.hypot(x - p.x0, yy - p.y0);
|
|
344
|
+
if ('locked' === p.last) {
|
|
345
|
+
if (d > 8) pointer.current = {
|
|
346
|
+
...IDLE,
|
|
347
|
+
stamp: p.stamp,
|
|
348
|
+
token: p.token
|
|
349
|
+
};
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
if ('mouse' === source ? d >= 4 : Date.now() - p.t0 >= LONG_PRESS_MS && d < 12) startDragMT();
|
|
353
|
+
else {
|
|
354
|
+
if ('touch' !== source || !(d > 8)) return;
|
|
355
|
+
pointer.current = {
|
|
356
|
+
...IDLE,
|
|
357
|
+
stamp: p.stamp,
|
|
358
|
+
token: p.token
|
|
359
|
+
};
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
sendMT(x, yy, false);
|
|
364
|
+
}
|
|
365
|
+
function rowTouchStart(e) {
|
|
366
|
+
'main thread';
|
|
367
|
+
var _e_timestamp, _t_pageX, _t_pageY;
|
|
368
|
+
var _e_touches;
|
|
369
|
+
const t = null == (_e_touches = e.touches) ? void 0 : _e_touches[0];
|
|
370
|
+
if (t) beginMT(null != (_e_timestamp = e.timestamp) ? _e_timestamp : 0, null != (_t_pageX = t.pageX) ? _t_pageX : 0, null != (_t_pageY = t.pageY) ? _t_pageY : 0, 'touch', 'create', null, true);
|
|
371
|
+
}
|
|
372
|
+
function rowTouchMove(e) {
|
|
373
|
+
'main thread';
|
|
374
|
+
var _t_pageX, _t_pageY;
|
|
375
|
+
var _e_touches;
|
|
376
|
+
const t = null == (_e_touches = e.touches) ? void 0 : _e_touches[0];
|
|
377
|
+
if (t) moveMT(null != (_t_pageX = t.pageX) ? _t_pageX : 0, null != (_t_pageY = t.pageY) ? _t_pageY : 0, 'touch');
|
|
378
|
+
}
|
|
379
|
+
function rowTouchEnd() {
|
|
380
|
+
'main thread';
|
|
381
|
+
if ('touch' === pointer.current.source) releaseMT();
|
|
382
|
+
}
|
|
383
|
+
function rowLongPress() {
|
|
384
|
+
'main thread';
|
|
385
|
+
const p = pointer.current;
|
|
386
|
+
flushBeginMT();
|
|
387
|
+
if ('touch' === p.source && 'pending' === p.phase && 'locked' !== p.last) startDragMT();
|
|
388
|
+
}
|
|
389
|
+
function rowMouseDown(e) {
|
|
390
|
+
'main thread';
|
|
391
|
+
if (0 !== e.button) return;
|
|
392
|
+
beginMT(e.timestamp, e.pageX, e.pageY, 'mouse', 'create', null, true);
|
|
393
|
+
}
|
|
394
|
+
function rowMouseMove(e) {
|
|
395
|
+
'main thread';
|
|
396
|
+
moveMT(e.pageX, e.pageY, 'mouse');
|
|
397
|
+
}
|
|
398
|
+
function rowMouseUp() {
|
|
399
|
+
'main thread';
|
|
400
|
+
if ('mouse' === pointer.current.source) releaseMT();
|
|
401
|
+
}
|
|
402
|
+
const cancel = ()=>void runOnMainThread(abortMT)();
|
|
403
|
+
const scrollNode = useRef(null);
|
|
404
|
+
const placed = useRef('');
|
|
405
|
+
const startKey = `${first}:${n}`;
|
|
406
|
+
useEffect(()=>{
|
|
407
|
+
if (false === props.initialScroll || placed.current === startKey) return;
|
|
408
|
+
placed.current = startKey;
|
|
409
|
+
const today = days.some((d)=>sameDay(d, props.today));
|
|
410
|
+
const minute = 'number' == typeof props.initialScroll ? props.initialScroll : 'morning' !== props.initialScroll && today && void 0 !== props.now ? Math.max(0, props.now - 90) : 450;
|
|
411
|
+
const offset = Math.max(0, Math.round(y(minute)));
|
|
412
|
+
const go = ()=>{
|
|
413
|
+
try {
|
|
414
|
+
var _scrollNode_current;
|
|
415
|
+
null == (_scrollNode_current = scrollNode.current) || _scrollNode_current.invoke({
|
|
416
|
+
method: 'scrollTo',
|
|
417
|
+
params: {
|
|
418
|
+
offset,
|
|
419
|
+
smooth: false
|
|
420
|
+
}
|
|
421
|
+
}).exec();
|
|
422
|
+
} catch {}
|
|
423
|
+
};
|
|
424
|
+
go();
|
|
425
|
+
const t = setTimeout(go, 250);
|
|
426
|
+
return ()=>clearTimeout(t);
|
|
427
|
+
}, [
|
|
428
|
+
startKey
|
|
429
|
+
]);
|
|
430
|
+
const body = useRef(null);
|
|
431
|
+
const pickSlot = (d, windowY)=>{
|
|
432
|
+
try {
|
|
433
|
+
var _body_current;
|
|
434
|
+
null == (_body_current = body.current) || _body_current.invoke({
|
|
435
|
+
method: 'boundingClientRect',
|
|
436
|
+
success: (r)=>{
|
|
437
|
+
var _props_onSelectSlot;
|
|
438
|
+
if ('number' == typeof (null == r ? void 0 : r.top) && Number.isFinite(r.top)) null == (_props_onSelectSlot = props.onSelectSlot) || _props_onSelectSlot.call(props, d, slotAt(windowY - r.top, hh, from, to));
|
|
439
|
+
},
|
|
440
|
+
fail: ()=>{}
|
|
441
|
+
}).exec();
|
|
442
|
+
} catch {}
|
|
443
|
+
};
|
|
444
|
+
const hm = (m)=>`${num(Math.floor(m / 60))}:${num(m % 60).padStart(2, num(0))}`;
|
|
445
|
+
const boxes = preview ? previewBoxes(preview, n, hh) : [];
|
|
446
|
+
const barPreview = preview ? previewBar(preview, n) : null;
|
|
447
|
+
const rowDir = {
|
|
448
|
+
flexDirection: rtl ? 'row-reverse' : 'row',
|
|
449
|
+
direction: 'ltr'
|
|
450
|
+
};
|
|
451
|
+
const colStyle = (index, span = 1)=>({
|
|
452
|
+
[side]: `${index / n * 100}%`,
|
|
453
|
+
width: `${span / n * 100}%`
|
|
454
|
+
});
|
|
455
|
+
const grabbing = editing ? {
|
|
456
|
+
'main-thread:bindtouchstart': rowTouchStart,
|
|
457
|
+
'main-thread:bindtouchmove': rowTouchMove,
|
|
458
|
+
'main-thread:bindtouchend': rowTouchEnd,
|
|
459
|
+
'main-thread:bindtouchcancel': rowTouchEnd,
|
|
460
|
+
'main-thread:bindlongpress': rowLongPress,
|
|
461
|
+
'main-thread:bindmousedown': rowMouseDown,
|
|
462
|
+
'main-thread:bindmousemove': rowMouseMove,
|
|
463
|
+
'main-thread:bindmouseup': rowMouseUp
|
|
464
|
+
} : {};
|
|
465
|
+
const eventStart = (e, mode)=>{
|
|
466
|
+
const editable = true === e.canEdit && void 0 !== props.onMove;
|
|
467
|
+
return editing ? {
|
|
468
|
+
'main-thread:bindtouchstart': (ev)=>{
|
|
469
|
+
'main thread';
|
|
470
|
+
var _ev_timestamp, _t_pageX, _t_pageY;
|
|
471
|
+
var _ev_touches;
|
|
472
|
+
const t = null == (_ev_touches = ev.touches) ? void 0 : _ev_touches[0];
|
|
473
|
+
if (t) beginMT(null != (_ev_timestamp = ev.timestamp) ? _ev_timestamp : 0, null != (_t_pageX = t.pageX) ? _t_pageX : 0, null != (_t_pageY = t.pageY) ? _t_pageY : 0, 'touch', mode, e.id, editable);
|
|
474
|
+
},
|
|
475
|
+
'main-thread:bindmousedown': (ev)=>{
|
|
476
|
+
'main thread';
|
|
477
|
+
if (0 === ev.button) beginMT(ev.timestamp, ev.pageX, ev.pageY, 'mouse', mode, e.id, editable);
|
|
478
|
+
}
|
|
479
|
+
} : {};
|
|
480
|
+
};
|
|
481
|
+
return <view className="g9-time-grid" {...g9IdProps(props.id)}>
|
|
482
|
+
{dragging ? <DragCancel onCancel={cancel}/> : null}
|
|
483
|
+
{}
|
|
484
|
+
{n > 1 ? <view className="g9-time-grid__heads" style={rowDir}>
|
|
485
|
+
<view className="g9-time-grid__gutter"/>
|
|
486
|
+
{days.map((d)=>{
|
|
487
|
+
var _props_dayOff;
|
|
488
|
+
const today = sameDay(d, props.today);
|
|
489
|
+
const off = (null == (_props_dayOff = props.dayOff) ? void 0 : _props_dayOff.call(props, d)) === true || weekend.includes(dayOfWeek(d));
|
|
490
|
+
const other = secondDateLabel(d, calendar, second, culture);
|
|
491
|
+
return <view key={toEpochDays(d)} className="g9-time-grid__head-cell" {...props.onOpenDay ? {
|
|
492
|
+
bindtap: ()=>{
|
|
493
|
+
var _props_onOpenDay;
|
|
494
|
+
return null == (_props_onOpenDay = props.onOpenDay) ? void 0 : _props_onOpenDay.call(props, d);
|
|
495
|
+
}
|
|
496
|
+
} : {}} accessibility-element={true} accessibility-label={formatLocalDateTime(d, 'dddd d MMMM', culture)}>
|
|
497
|
+
<text className={`g9-time-grid__head${today ? ' g9-time-grid__head--today' : off ? ' g9-time-grid__head--off' : ''}`}>
|
|
498
|
+
{formatLocalDateTime(d, 'ddd d', culture)}
|
|
499
|
+
</text>
|
|
500
|
+
{other ? <text className="g9-time-grid__head-second">{other}</text> : null}
|
|
501
|
+
</view>;
|
|
502
|
+
})}
|
|
503
|
+
</view> : null}
|
|
504
|
+
{bars.length > 0 || editing ? <view className="g9-time-grid__allday" style={rowDir}>
|
|
505
|
+
<view className="g9-time-grid__gutter">
|
|
506
|
+
<text className="g9-time-grid__allday-label" text-maxline="2">
|
|
507
|
+
{null != (_props_allDayText = props.allDayText) ? _props_allDayText : ''}
|
|
508
|
+
</text>
|
|
509
|
+
</view>
|
|
510
|
+
<view className="g9-time-grid__allday-cols" main-thread:ref={allDayRef} style={{
|
|
511
|
+
height: `${allDayHeight}px`
|
|
512
|
+
}} {...grabbing}>
|
|
513
|
+
{bars.filter((b)=>{
|
|
514
|
+
var _lanes_get;
|
|
515
|
+
return (null != (_lanes_get = lanes.get(b.event.id)) ? _lanes_get : 0) < shownLanes;
|
|
516
|
+
}).map((b)=>{
|
|
517
|
+
var _lanes_get;
|
|
518
|
+
return <view key={b.event.id} className={`g9-time-grid__bar${b.event.rsvp ? ` g9-time-grid__bar--${b.event.rsvp}` : ''}`} style={{
|
|
519
|
+
...colStyle(b.start, b.end - b.start + 1),
|
|
520
|
+
top: `${(null != (_lanes_get = lanes.get(b.event.id)) ? _lanes_get : 0) * LANE}px`,
|
|
521
|
+
height: `${LANE - 2}px`,
|
|
522
|
+
...b.event.color ? {
|
|
523
|
+
backgroundColor: b.event.color
|
|
524
|
+
} : {}
|
|
525
|
+
}} {...eventStart(b.event, 'move')} catchtap={()=>{
|
|
526
|
+
var _props_onSelectEvent;
|
|
527
|
+
if (!editing) null == (_props_onSelectEvent = props.onSelectEvent) || _props_onSelectEvent.call(props, b.event);
|
|
528
|
+
}} accessibility-element={true} accessibility-traits="button" accessibility-label={b.event.title}>
|
|
529
|
+
<text className="g9-time-grid__bar-text" text-maxline="1">
|
|
530
|
+
{b.event.title}
|
|
531
|
+
</text>
|
|
532
|
+
</view>;
|
|
533
|
+
})}
|
|
534
|
+
{barPreview ? <view className="g9-time-grid__bar g9-time-grid__bar--preview" style={{
|
|
535
|
+
...colStyle(barPreview.start, barPreview.end - barPreview.start + 1),
|
|
536
|
+
top: '0px',
|
|
537
|
+
height: `${LANE - 2}px`
|
|
538
|
+
}}/> : null}
|
|
539
|
+
{moreRow ? <view className="g9-time-grid__more-row" style={{
|
|
540
|
+
top: `${shownLanes * LANE}px`
|
|
541
|
+
}}>
|
|
542
|
+
{days.map((d, i)=>{
|
|
543
|
+
var _hiddenPerDay_i;
|
|
544
|
+
return hiddenPerDay[i] || expanded ? <view key={toEpochDays(d)} className="g9-time-grid__more" style={colStyle(i)} catchtap={()=>setExpanded(!expanded)} accessibility-element={true} accessibility-traits="button">
|
|
545
|
+
<text className="g9-time-grid__more-text">{expanded ? '−' : more(null != (_hiddenPerDay_i = hiddenPerDay[i]) ? _hiddenPerDay_i : 0)}</text>
|
|
546
|
+
</view> : null;
|
|
547
|
+
})}
|
|
548
|
+
</view> : null}
|
|
549
|
+
</view>
|
|
550
|
+
</view> : null}
|
|
551
|
+
<scroll-view className="g9-time-grid__scroll" scroll-orientation="vertical" main-thread:ref={scrollerRef} ref={(r)=>{
|
|
552
|
+
scrollNode.current = r;
|
|
553
|
+
}}>
|
|
554
|
+
<view className="g9-time-grid__body" ref={(r)=>{
|
|
555
|
+
body.current = r;
|
|
556
|
+
}} main-thread:ref={gridRef} style={{
|
|
557
|
+
...rowDir,
|
|
558
|
+
height: `${(to - from) * hh}px`
|
|
559
|
+
}} {...grabbing}>
|
|
560
|
+
<view className="g9-time-grid__gutter">
|
|
561
|
+
{Array.from({
|
|
562
|
+
length: to - from
|
|
563
|
+
}, (_, i)=><text key={i} className="g9-time-grid__hour" style={{
|
|
564
|
+
top: `${i * hh - 7}px`
|
|
565
|
+
}}>
|
|
566
|
+
{0 === i ? '' : `${num(from + i)}:${num(0)}${num(0)}`}
|
|
567
|
+
</text>)}
|
|
568
|
+
</view>
|
|
569
|
+
{days.map((d, index)=>{
|
|
570
|
+
const today = sameDay(d, props.today);
|
|
571
|
+
const timed = props.events.filter((e)=>!isBarEvent(e) && eventTouches(e, d) && void 0 !== e.start);
|
|
572
|
+
const spans = timed.map((e)=>{
|
|
573
|
+
var _e_end;
|
|
574
|
+
const s = sameDay(e.date, d) ? e.start : 0;
|
|
575
|
+
const last = sameDay(eventLastDay(e), d);
|
|
576
|
+
const end = last ? null != (_e_end = e.end) ? _e_end : e.start + 60 : 1440;
|
|
577
|
+
return {
|
|
578
|
+
id: e.id,
|
|
579
|
+
start: s,
|
|
580
|
+
end: Math.max(end, s + 15)
|
|
581
|
+
};
|
|
582
|
+
});
|
|
583
|
+
const placed = layoutDay(spans);
|
|
584
|
+
const dayBoxes = boxes.filter((b)=>b.index === index);
|
|
585
|
+
return <view key={toEpochDays(d)} className="g9-time-grid__col" {...props.onSelectSlot && !editing ? {
|
|
586
|
+
bindtap: (ev)=>{
|
|
587
|
+
var _ref;
|
|
588
|
+
var _ev_detail;
|
|
589
|
+
return pickSlot(d, null != (_ref = null == (_ev_detail = ev.detail) ? void 0 : _ev_detail.y) ? _ref : 0);
|
|
590
|
+
}
|
|
591
|
+
} : {}}>
|
|
592
|
+
{Array.from({
|
|
593
|
+
length: to - from
|
|
594
|
+
}, (_, i)=><view key={i} className="g9-time-grid__line" style={{
|
|
595
|
+
top: `${i * hh}px`
|
|
596
|
+
}}/>)}
|
|
597
|
+
{placed.map((p)=>{
|
|
598
|
+
const e = timed.find((x)=>x.id === p.id);
|
|
599
|
+
const w = 100 / p.lanes;
|
|
600
|
+
const editable = true === e.canEdit && void 0 !== props.onMove;
|
|
601
|
+
return <view key={p.id} className={`g9-time-grid__event${e.rsvp ? ` g9-time-grid__event--${e.rsvp}` : ''}${gesture.current.id === e.id && dragging ? ' g9-time-grid__event--lifted' : ''}`} style={{
|
|
602
|
+
top: `${y(p.start)}px`,
|
|
603
|
+
height: `${Math.max(18, y(p.end) - y(p.start) - 2)}px`,
|
|
604
|
+
[side]: `${p.lane * w}%`,
|
|
605
|
+
width: `${w}%`,
|
|
606
|
+
...e.color ? {
|
|
607
|
+
backgroundColor: e.color
|
|
608
|
+
} : {}
|
|
609
|
+
}} {...eventStart(e, 'move')} catchtap={()=>{
|
|
610
|
+
var _props_onSelectEvent;
|
|
611
|
+
if (!editing) null == (_props_onSelectEvent = props.onSelectEvent) || _props_onSelectEvent.call(props, e);
|
|
612
|
+
}} accessibility-element={true} accessibility-traits="button" accessibility-label={`${e.title}, ${hm(e.start)}`}>
|
|
613
|
+
<text className="g9-time-grid__event-text" text-maxline="2">
|
|
614
|
+
{e.title}
|
|
615
|
+
</text>
|
|
616
|
+
{editable && sameDay(eventLastDay(e), d) ? <view className="g9-time-grid__resize" {...eventStart(e, 'resize')}/> : null}
|
|
617
|
+
</view>;
|
|
618
|
+
})}
|
|
619
|
+
{dayBoxes.map((b)=><view key={`p${b.index}`} className="g9-time-grid__event g9-time-grid__event--preview" style={{
|
|
620
|
+
top: `${b.top - from * hh}px`,
|
|
621
|
+
height: `${b.height}px`,
|
|
622
|
+
[side]: '0%',
|
|
623
|
+
width: '100%'
|
|
624
|
+
}}>
|
|
625
|
+
{preview && !preview.allDay ? <text className="g9-time-grid__event-text">{`${hm(preview.startMinute)} – ${hm(preview.endMinute)}`}</text> : null}
|
|
626
|
+
</view>)}
|
|
627
|
+
{today && void 0 !== props.now && props.now >= 60 * from && props.now <= 60 * to ? <view className="g9-time-grid__now" style={{
|
|
628
|
+
top: `${y(props.now)}px`
|
|
629
|
+
}}/> : null}
|
|
630
|
+
</view>;
|
|
631
|
+
})}
|
|
632
|
+
</view>
|
|
633
|
+
{props.paddingEnd ? <view style={{
|
|
634
|
+
height: `${props.paddingEnd}px`
|
|
635
|
+
}}/> : null}
|
|
636
|
+
</scroll-view>
|
|
637
|
+
</view>;
|
|
638
|
+
}
|
|
639
|
+
export { G9TimeGrid };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type G9NumberingSystem } from '@g9tm/lynxcontrols-foundation';
|
|
2
|
+
import { type ReactNode } from '@lynx-js/react';
|
|
3
|
+
/** The steps of a day (every `step` minutes) plus `value` when it is off the grid, in order. */
|
|
4
|
+
export declare function timeSteps(value: number | null, step?: number): number[];
|
|
5
|
+
/** `minutes` after midnight as `HH:mm` in the given digits. */
|
|
6
|
+
export declare function timeLabel(minutes: number, numberingSystem?: G9NumberingSystem): string;
|
|
7
|
+
/** Props of {@link G9TimeListPicker}. */
|
|
8
|
+
export interface G9TimeListPickerProps {
|
|
9
|
+
readonly id?: string;
|
|
10
|
+
readonly label: string;
|
|
11
|
+
/** Minutes after midnight; `null`: none chosen. */
|
|
12
|
+
readonly value: number | null;
|
|
13
|
+
readonly onChange: (minutes: number) => void;
|
|
14
|
+
/** Minutes between the listed times. Default 15. */
|
|
15
|
+
readonly step?: number;
|
|
16
|
+
readonly placeholder?: string;
|
|
17
|
+
readonly disabled?: boolean;
|
|
18
|
+
readonly hint?: string;
|
|
19
|
+
readonly error?: string | null;
|
|
20
|
+
/** The phone list's title. Default the label. */
|
|
21
|
+
readonly title?: string;
|
|
22
|
+
}
|
|
23
|
+
/** A time picked from a list of steps: a popover on a wide window, a sheet on a phone; it opens at the value. */
|
|
24
|
+
export declare function G9TimeListPicker(props: G9TimeListPickerProps): ReactNode;
|
|
25
|
+
//# sourceMappingURL=time-list.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"time-list.d.ts","sourceRoot":"","sources":["../src/time-list.tsx"],"names":[],"mappings":"AAQA,OAAO,EAAgB,KAAK,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AACrF,OAAO,EAAE,KAAK,SAAS,EAAoB,MAAM,gBAAgB,CAAC;AAGlE,gGAAgG;AAChG,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,EAAE,IAAI,SAAK,GAAG,MAAM,EAAE,CAKnE;AAED,+DAA+D;AAC/D,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,eAAe,GAAE,iBAA2B,GAAG,MAAM,CAI/F;AAED,yCAAyC;AACzC,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,mDAAmD;IACnD,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,QAAQ,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7C,oDAAoD;IACpD,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,iDAAiD;IACjD,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,iHAAiH;AACjH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,GAAG,SAAS,CA4FxE"}
|