@g9tm/lynxcontrols-calendar 0.0.0-stage → 2.2.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"calendar.d.ts","sourceRoot":"","sources":["../src/calendar.tsx"],"names":[],"mappings":"AAGA,OAAO,gBAAgB,CAAC;AAOxB,OAAO,EAKL,KAAK,WAAW,EAOjB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,KAAK,SAAS,EAA6B,MAAM,gBAAgB,CAAC;AAC3E,OAAO,EAAU,KAAK,YAAY,EAAmE,MAAM,SAAS,CAAC;AAqBrH,oCAAoC;AACpC,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;IAC5B,QAAQ,CAAC,KAAK,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;IACpC,8CAA8C;IAC9C,QAAQ,CAAC,KAAK,CAAC,EAAE;QAAE,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;QAAC,QAAQ,CAAC,GAAG,EAAE,WAAW,CAAA;KAAE,GAAG,IAAI,CAAC;IACnF,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,IAAI,CAAC;IAChD,4DAA4D;IAC5D,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,OAAO,CAAC;IACjD,QAAQ,CAAC,GAAG,CAAC,EAAE,WAAW,CAAC;IAC3B,QAAQ,CAAC,GAAG,CAAC,EAAE,WAAW,CAAC;IAC3B,iEAAiE;IACjE,QAAQ,CAAC,YAAY,CAAC,EAAE,WAAW,CAAC;CACrC;AAED,uHAAuH;AACvH,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,GAAG,SAAS,CAiF9D;AAED,oCAAoC;AACpC,MAAM,WAAW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AC;IAC3B,QAAQ,CAAC,GAAG,CAAC,EAAE,WAAW,CAAC;IAC3B,yCAAyC;IACzC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,GAAG,SAAS,CAkD9D;AAED,uCAAuC;AACvC,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,CAAC;IACpC,QAAQ,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI,KAAK,IAAI,CAAC;IACvD,QAAQ,CAAC,MAAM,EAAE;QACf,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;QACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;QACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;KACzB,CAAC;CACH;AAED,sEAAsE;AACtE,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,GAAG,SAAS,CAsCpE"}
@@ -0,0 +1,404 @@
1
+ import "./calendar.css";
2
+ import { g9IdProps } from "@g9tm/lynxcontrols/base";
3
+ import { G9IconButton } from "@g9tm/lynxcontrols/button";
4
+ import { G9TextEntry } from "@g9tm/lynxcontrols/fields";
5
+ import { G9VirtualList } from "@g9tm/lynxcontrols/list";
6
+ import { useG9Culture, useG9Direction } from "@g9tm/lynxcontrols/provider";
7
+ import { G9Chip, G9Segmented } from "@g9tm/lynxcontrols/toggle";
8
+ import { addDays, compareLocal, formatLocalDateTime, formatNumber, g9Haptic, getMonthName, getWeekdayNames, parseNaturalDate, toCalendarDate, toEpochDays } from "@g9tm/lynxcontrols-foundation";
9
+ import { useMemo, useRef, useState } from "@lynx-js/react";
10
+ import { agenda, layoutDay, monthGrid, sameDay, shiftMonth, slotAt, weekStartFor } from "./model.jsx";
11
+ const rowDir = (rtl)=>({
12
+ flexDirection: rtl ? 'row-reverse' : 'row',
13
+ direction: 'ltr'
14
+ });
15
+ function useCal() {
16
+ const culture = useG9Culture();
17
+ const rtl = 'rtl' === useG9Direction();
18
+ const calendar = culture.calendar;
19
+ const weekStart = weekStartFor(calendar, culture.language);
20
+ const num = (n)=>formatNumber(n, {
21
+ numberingSystem: culture.numberingSystem,
22
+ useGrouping: false
23
+ });
24
+ const weekdays = getWeekdayNames(culture, 'abbreviated');
25
+ const initial = (wd)=>{
26
+ var _weekdays_wd;
27
+ const name = null != (_weekdays_wd = weekdays[wd]) ? _weekdays_wd : '';
28
+ return 'fa' === culture.language ? name.charAt(0) : name.slice(0, 2);
29
+ };
30
+ return {
31
+ culture,
32
+ rtl,
33
+ calendar,
34
+ weekStart,
35
+ num,
36
+ initial
37
+ };
38
+ }
39
+ function G9MiniMonth(props) {
40
+ var _ref, _props_initialMonth;
41
+ const { culture, rtl, calendar, weekStart, num, initial } = useCal();
42
+ const start = toCalendarDate(null != (_ref = null != (_props_initialMonth = props.initialMonth) ? _props_initialMonth : props.value) ? _ref : props.today, calendar);
43
+ const [ym, setYm] = useState({
44
+ year: start.year,
45
+ month: start.month
46
+ });
47
+ const weeks = useMemo(()=>monthGrid(calendar, ym.year, ym.month, weekStart, true), [
48
+ calendar,
49
+ ym.year,
50
+ ym.month,
51
+ weekStart
52
+ ]);
53
+ const off = (d)=>props.min && compareLocal(d, props.min) < 0 || props.max && compareLocal(d, props.max) > 0;
54
+ const inRange = (d)=>!!props.range && compareLocal(d, props.range.start) >= 0 && compareLocal(d, props.range.end) <= 0;
55
+ const go = (delta)=>setYm((m)=>shiftMonth(m.year, m.month, delta));
56
+ return <view className="g9-mini-month" {...g9IdProps(props.id)}>
57
+ <view className="g9-mini-month__head" style={rowDir(rtl)}>
58
+ <text className="g9-mini-month__title">{`${getMonthName(calendar, ym.month, culture)} ${num(ym.year)}`}</text>
59
+ <view className="g9-mini-month__arrows" style={rowDir(rtl)}>
60
+ <G9IconButton {...props.id ? {
61
+ id: `${props.id}.Prev`
62
+ } : {}} icon={rtl ? 'chevronRight' : 'chevronLeft'} isGhost buttonSize={32} accessibilityText="‹" onPress={()=>go(-1)}/>
63
+ <G9IconButton {...props.id ? {
64
+ id: `${props.id}.Next`
65
+ } : {}} icon={rtl ? 'chevronLeft' : 'chevronRight'} isGhost buttonSize={32} accessibilityText="›" onPress={()=>go(1)}/>
66
+ </view>
67
+ </view>
68
+ <view className="g9-mini-month__week" style={rowDir(rtl)}>
69
+ {Array.from({
70
+ length: 7
71
+ }, (_, i)=><text key={i} className="g9-mini-month__wd">
72
+ {initial((weekStart + i) % 7)}
73
+ </text>)}
74
+ </view>
75
+ {weeks.map((week, r)=><view key={r} className="g9-mini-month__week" style={rowDir(rtl)}>
76
+ {week.map((c)=>{
77
+ var _props_marked;
78
+ const selected = !!props.value && sameDay(c.date, props.value);
79
+ const today = sameDay(c.date, props.today);
80
+ const disabled = !!off(c.date);
81
+ return <view key={c.key} className={`g9-mini-month__cell${inRange(c.date) ? ' g9-mini-month__cell--range' : ''}`} {...!disabled && props.onSelect ? {
82
+ bindtap: ()=>{
83
+ var _props_onSelect;
84
+ return g9Haptic('select'), null == (_props_onSelect = props.onSelect) ? void 0 : _props_onSelect.call(props, c.date);
85
+ }
86
+ } : {}} accessibility-element={true} accessibility-traits="button" accessibility-label={formatLocalDateTime(c.date, 'dddd d MMMM', culture)}>
87
+ <view className={`g9-mini-month__day${selected ? ' g9-mini-month__day--on' : today ? ' g9-mini-month__day--today' : ''}`}>
88
+ <text className={`g9-mini-month__num${selected ? ' g9-mini-month__num--on' : !c.inMonth || disabled ? ' g9-mini-month__num--out' : ''}`}>
89
+ {num(c.day)}
90
+ </text>
91
+ </view>
92
+ {(null == (_props_marked = props.marked) ? void 0 : _props_marked.call(props, c.date)) ? <view className="g9-mini-month__dot"/> : <view className="g9-mini-month__dot g9-mini-month__dot--none"/>}
93
+ </view>;
94
+ })}
95
+ </view>)}
96
+ </view>;
97
+ }
98
+ function G9MonthView(props) {
99
+ var _props_perDay;
100
+ const { rtl, calendar, weekStart, num, initial } = useCal();
101
+ const m = toCalendarDate(props.month, calendar);
102
+ const weeks = useMemo(()=>monthGrid(calendar, m.year, m.month, weekStart), [
103
+ calendar,
104
+ m.year,
105
+ m.month,
106
+ weekStart
107
+ ]);
108
+ const byDay = useMemo(()=>{
109
+ const map = new Map();
110
+ for (const e of props.events){
111
+ const k = toEpochDays(e.date);
112
+ const list = map.get(k);
113
+ if (list) list.push(e);
114
+ else map.set(k, [
115
+ e
116
+ ]);
117
+ }
118
+ return map;
119
+ }, [
120
+ props.events
121
+ ]);
122
+ const per = null != (_props_perDay = props.perDay) ? _props_perDay : 2;
123
+ return <view className="g9-month" {...g9IdProps(props.id)}>
124
+ <view className="g9-month__week g9-month__week--head" style={rowDir(rtl)}>
125
+ {Array.from({
126
+ length: 7
127
+ }, (_, i)=><text key={i} className="g9-month__wd">
128
+ {initial((weekStart + i) % 7)}
129
+ </text>)}
130
+ </view>
131
+ {weeks.map((week, r)=><view key={r} className="g9-month__week" style={rowDir(rtl)}>
132
+ {week.map((c)=>{
133
+ var _byDay_get;
134
+ const list = null != (_byDay_get = byDay.get(toEpochDays(c.date))) ? _byDay_get : [];
135
+ return <view key={c.key} className={`g9-month__cell${c.inMonth ? '' : ' g9-month__cell--out'}`} {...props.onSelectDay ? {
136
+ bindtap: ()=>{
137
+ var _props_onSelectDay;
138
+ return null == (_props_onSelectDay = props.onSelectDay) ? void 0 : _props_onSelectDay.call(props, c.date);
139
+ }
140
+ } : {}}>
141
+ <text className={`g9-month__num${sameDay(c.date, props.today) ? ' g9-month__num--today' : ''}`}>
142
+ {num(c.day)}
143
+ </text>
144
+ {list.slice(0, per).map((e)=><view key={e.id} className="g9-month__event" style={e.color ? {
145
+ backgroundColor: e.color
146
+ } : {}} {...props.onSelectEvent ? {
147
+ catchtap: ()=>{
148
+ var _props_onSelectEvent;
149
+ return null == (_props_onSelectEvent = props.onSelectEvent) ? void 0 : _props_onSelectEvent.call(props, e);
150
+ }
151
+ } : {}}>
152
+ <text className="g9-month__event-text" text-maxline="1">
153
+ {e.title}
154
+ </text>
155
+ </view>)}
156
+ {list.length > per ? <text className="g9-month__more">{`+${num(list.length - per)}`}</text> : null}
157
+ </view>;
158
+ })}
159
+ </view>)}
160
+ </view>;
161
+ }
162
+ function G9TimeGrid(props) {
163
+ var _props_days, _props_hourHeight, _props_fromHour, _props_toHour;
164
+ const { culture, rtl, num } = useCal();
165
+ const n = null != (_props_days = props.days) ? _props_days : 1;
166
+ const hh = null != (_props_hourHeight = props.hourHeight) ? _props_hourHeight : 52;
167
+ const from = null != (_props_fromHour = props.fromHour) ? _props_fromHour : 0;
168
+ const to = null != (_props_toHour = props.toHour) ? _props_toHour : 24;
169
+ const days = Array.from({
170
+ length: n
171
+ }, (_, i)=>addDays(props.start, i));
172
+ const y = (minutes)=>(minutes - 60 * from) / 60 * hh;
173
+ const body = useRef(null);
174
+ const pickSlot = (d, windowY)=>{
175
+ try {
176
+ var _body_current;
177
+ null == (_body_current = body.current) || _body_current.invoke({
178
+ method: 'boundingClientRect',
179
+ success: (r)=>{
180
+ var _props_onSelectSlot;
181
+ 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));
182
+ },
183
+ fail: ()=>{}
184
+ }).exec();
185
+ } catch {}
186
+ };
187
+ return <view className="g9-time-grid" {...g9IdProps(props.id)}>
188
+ {}
189
+ {n > 1 ? <view className="g9-time-grid__heads" style={rowDir(rtl)}>
190
+ <view className="g9-time-grid__gutter"/>
191
+ {days.map((d)=><text key={toEpochDays(d)} className={`g9-time-grid__head${sameDay(d, props.today) ? ' g9-time-grid__head--today' : ''}`}>
192
+ {formatLocalDateTime(d, 'ddd d', culture)}
193
+ </text>)}
194
+ </view> : null}
195
+ <scroll-view className="g9-time-grid__scroll" scroll-orientation="vertical">
196
+ <view className="g9-time-grid__body" ref={(r)=>{
197
+ body.current = r;
198
+ }} style={{
199
+ ...rowDir(rtl),
200
+ height: `${(to - from) * hh}px`
201
+ }}>
202
+ <view className="g9-time-grid__gutter">
203
+ {Array.from({
204
+ length: to - from
205
+ }, (_, i)=><text key={i} className="g9-time-grid__hour" style={{
206
+ top: `${i * hh - 7}px`
207
+ }}>
208
+ {0 === i ? '' : `${num(from + i)}:${num(0)}${num(0)}`}
209
+ </text>)}
210
+ </view>
211
+ {days.map((d)=>{
212
+ const today = sameDay(d, props.today);
213
+ const timed = props.events.filter((e)=>sameDay(e.date, d) && void 0 !== e.start);
214
+ const placed = layoutDay(timed.map((e)=>{
215
+ var _e_end;
216
+ return {
217
+ id: e.id,
218
+ start: e.start,
219
+ end: null != (_e_end = e.end) ? _e_end : e.start + 60
220
+ };
221
+ }));
222
+ return <view key={toEpochDays(d)} className="g9-time-grid__col" {...props.onSelectSlot ? {
223
+ bindtap: (e)=>{
224
+ var _ref;
225
+ var _e_detail;
226
+ return pickSlot(d, null != (_ref = null == (_e_detail = e.detail) ? void 0 : _e_detail.y) ? _ref : 0);
227
+ }
228
+ } : {}}>
229
+ {Array.from({
230
+ length: to - from
231
+ }, (_, i)=><view key={i} className="g9-time-grid__line" style={{
232
+ top: `${i * hh}px`
233
+ }}/>)}
234
+ {placed.map((p)=>{
235
+ const e = timed.find((x)=>x.id === p.id);
236
+ const w = 100 / p.lanes;
237
+ return <view key={p.id} className="g9-time-grid__event" style={{
238
+ top: `${y(p.start)}px`,
239
+ height: `${Math.max(18, y(p.end) - y(p.start) - 2)}px`,
240
+ [rtl ? 'right' : 'left']: `${p.lane * w}%`,
241
+ width: `${w}%`,
242
+ ...e.color ? {
243
+ backgroundColor: e.color
244
+ } : {}
245
+ }} {...props.onSelectEvent ? {
246
+ catchtap: ()=>{
247
+ var _props_onSelectEvent;
248
+ return null == (_props_onSelectEvent = props.onSelectEvent) ? void 0 : _props_onSelectEvent.call(props, e);
249
+ }
250
+ } : {}}>
251
+ <text className="g9-time-grid__event-text" text-maxline="2">
252
+ {e.title}
253
+ </text>
254
+ </view>;
255
+ })}
256
+ {today && void 0 !== props.now && props.now >= 60 * from && props.now <= 60 * to ? <view className="g9-time-grid__now" style={{
257
+ top: `${y(props.now)}px`
258
+ }}/> : null}
259
+ </view>;
260
+ })}
261
+ </view>
262
+ </scroll-view>
263
+ </view>;
264
+ }
265
+ function G9AgendaView(props) {
266
+ const { culture, rtl, num } = useCal();
267
+ const groups = useMemo(()=>agenda([
268
+ ...props.events
269
+ ].sort((a, b)=>{
270
+ var _a_start, _b_start;
271
+ return compareLocal(a.date, b.date) || (null != (_a_start = a.start) ? _a_start : -1) - (null != (_b_start = b.start) ? _b_start : -1);
272
+ })), [
273
+ props.events
274
+ ]);
275
+ const rows = [];
276
+ for (const g of groups){
277
+ rows.push({
278
+ kind: 'day',
279
+ key: `d${toEpochDays(g.date)}`,
280
+ date: g.date
281
+ });
282
+ for (const e of g.items)rows.push({
283
+ kind: 'event',
284
+ key: e.id,
285
+ event: e
286
+ });
287
+ }
288
+ const hm = (m)=>`${num(Math.floor(m / 60))}:${num(m % 60).padStart(2, num(0))}`;
289
+ return <G9VirtualList {...props.id ? {
290
+ id: props.id
291
+ } : {}} className="g9-agenda" items={rows} getKey={(r)=>r.key} reuseKey={(r)=>r.kind} isSticky={(r)=>'day' === r.kind} estimatedSize={(r)=>'day' === r.kind ? 40 : 56} {...props.empty ? {
292
+ empty: props.empty
293
+ } : {}} renderItem={(r)=>{
294
+ var _props_allDayText;
295
+ return 'day' === r.kind ? <view className="g9-agenda__day" style={rowDir(rtl)}>
296
+ <text className={`g9-agenda__day-text${sameDay(r.date, props.today) ? ' g9-agenda__day-text--today' : ''}`}>
297
+ {formatLocalDateTime(r.date, 'dddd d MMMM', culture)}
298
+ </text>
299
+ </view> : <view className="g9-agenda__event" style={rowDir(rtl)} {...props.onSelectEvent ? {
300
+ bindtap: ()=>{
301
+ var _props_onSelectEvent;
302
+ return null == (_props_onSelectEvent = props.onSelectEvent) ? void 0 : _props_onSelectEvent.call(props, r.event);
303
+ }
304
+ } : {}}>
305
+ <view className="g9-agenda__bar" style={r.event.color ? {
306
+ backgroundColor: r.event.color
307
+ } : {}}/>
308
+ <text className="g9-agenda__time">
309
+ {void 0 === r.event.start ? null != (_props_allDayText = props.allDayText) ? _props_allDayText : '—' : `${hm(r.event.start)}${void 0 !== r.event.end ? ` – ${hm(r.event.end)}` : ''}`}
310
+ </text>
311
+ <text className="g9-agenda__title" text-maxline="2" style={{
312
+ textAlign: rtl ? 'right' : 'left'
313
+ }}>
314
+ {r.event.title}
315
+ </text>
316
+ </view>;
317
+ }}/>;
318
+ }
319
+ function G9DateInput(props) {
320
+ const culture = useG9Culture();
321
+ const [open, setOpen] = useState(false);
322
+ const [bad, setBad] = useState(false);
323
+ const shown = props.value ? formatLocalDateTime(props.value, 'dddd d MMMM yyyy', culture) : '';
324
+ const [text1, setText] = useState(shown);
325
+ const commit = (t)=>{
326
+ if (!t.trim()) {
327
+ setBad(false);
328
+ props.onChange(null);
329
+ return;
330
+ }
331
+ const d = parseNaturalDate(t, props.today, {
332
+ persian: 'fa' === culture.language
333
+ });
334
+ setBad(!d);
335
+ if (d) {
336
+ props.onChange(d);
337
+ setText(formatLocalDateTime(d, 'dddd d MMMM yyyy', culture));
338
+ }
339
+ };
340
+ return <view className="g9-date-input" {...g9IdProps(props.id)}>
341
+ <G9TextEntry {...props.id ? {
342
+ id: `${props.id}.Text`
343
+ } : {}} label={props.label} value={text1} onValueChange={(t)=>setText(t)} onBlur={()=>commit(text1)} onConfirm={commit} trailingIcon="calendar" hasError={bad} {...bad && props.invalidText ? {
344
+ errorText: props.invalidText
345
+ } : {}} onFocus={()=>setOpen(true)}/>
346
+ {open ? <G9MiniMonth {...props.id ? {
347
+ id: `${props.id}.Month`
348
+ } : {}} today={props.today} value={props.value} {...props.min ? {
349
+ min: props.min
350
+ } : {}} {...props.max ? {
351
+ max: props.max
352
+ } : {}} onSelect={(d)=>{
353
+ props.onChange(d);
354
+ setText(formatLocalDateTime(d, 'dddd d MMMM yyyy', culture));
355
+ setBad(false);
356
+ setOpen(false);
357
+ }}/> : null}
358
+ </view>;
359
+ }
360
+ function G9RepeatPicker(props) {
361
+ var _ref, _ref1;
362
+ var _props_value, _props_value1;
363
+ const { rtl, weekStart, initial } = useCal();
364
+ const freq = null != (_ref = null == (_props_value = props.value) ? void 0 : _props_value.freq) ? _ref : 'never';
365
+ const days = null != (_ref1 = null == (_props_value1 = props.value) ? void 0 : _props_value1.weekdays) ? _ref1 : [];
366
+ return <view className="g9-repeat" {...g9IdProps(props.id)}>
367
+ <G9Segmented {...props.id ? {
368
+ id: `${props.id}.Freq`
369
+ } : {}} size="sm" fit="content" value={freq} onChange={(f)=>{
370
+ var _props_value;
371
+ return props.onChange('never' === f ? null : {
372
+ ...null != (_props_value = props.value) ? _props_value : {},
373
+ freq: f
374
+ });
375
+ }} items={[
376
+ 'never',
377
+ 'daily',
378
+ 'weekly',
379
+ 'monthly',
380
+ 'yearly'
381
+ ].map((k)=>({
382
+ key: k,
383
+ label: props.labels[k]
384
+ }))}/>
385
+ {'weekly' === freq ? <view className="g9-repeat__days" style={rowDir(rtl)}>
386
+ {Array.from({
387
+ length: 7
388
+ }, (_, i)=>(weekStart + i) % 7).map((wd)=><G9Chip key={wd} text={initial(wd)} size="sm" selected={days.includes(wd)} onPress={()=>{
389
+ var _props_value;
390
+ return props.onChange({
391
+ ...null != (_props_value = props.value) ? _props_value : {
392
+ freq: 'weekly'
393
+ },
394
+ freq: 'weekly',
395
+ weekdays: days.includes(wd) ? days.filter((x)=>x !== wd) : [
396
+ ...days,
397
+ wd
398
+ ].sort((a, b)=>a - b)
399
+ });
400
+ }}/>)}
401
+ </view> : null}
402
+ </view>;
403
+ }
404
+ export { G9AgendaView, G9DateInput, G9MiniMonth, G9MonthView, G9RepeatPicker, G9TimeGrid };
@@ -0,0 +1,5 @@
1
+ export { G9AgendaView, type G9AgendaViewProps, type G9CalendarEvent, G9DateInput, type G9DateInputProps, G9MiniMonth, type G9MiniMonthProps, G9MonthView, type G9MonthViewProps, G9RepeatPicker, type G9RepeatPickerProps, G9TimeGrid, type G9TimeGridProps, } from './calendar.js';
2
+ export * from './model.js';
3
+ export { type G9MonthDay, G9MonthDayPicker, type G9MonthDayPickerProps, monthDayLength } from './month-day.js';
4
+ export { G9ZonePicker, type G9ZonePickerProps, zoneLabel, zoneOffsetLabel } from './zone-picker.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,WAAW,EACX,KAAK,gBAAgB,EACrB,WAAW,EACX,KAAK,gBAAgB,EACrB,WAAW,EACX,KAAK,gBAAgB,EACrB,cAAc,EACd,KAAK,mBAAmB,EACxB,UAAU,EACV,KAAK,eAAe,GACrB,MAAM,YAAY,CAAC;AACpB,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,KAAK,UAAU,EAAE,gBAAgB,EAAE,KAAK,qBAAqB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC5G,OAAO,EAAE,YAAY,EAAE,KAAK,iBAAiB,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC"}
package/dist/index.jsx ADDED
@@ -0,0 +1,4 @@
1
+ export * from "./model.jsx";
2
+ export { G9AgendaView, G9DateInput, G9MiniMonth, G9MonthView, G9RepeatPicker, G9TimeGrid } from "./calendar.jsx";
3
+ export { G9MonthDayPicker, monthDayLength } from "./month-day.jsx";
4
+ export { G9ZonePicker, zoneLabel, zoneOffsetLabel } from "./zone-picker.jsx";
@@ -0,0 +1,62 @@
1
+ import { type G9CalendarSystem, type G9LocalDate } from '@g9tm/lynxcontrols-foundation';
2
+ /** First day of the week: Saturday (6) for Persian, Sunday (0) or Monday (1) elsewhere. */
3
+ export declare const weekStartFor: (calendar: G9CalendarSystem, language: string) => number;
4
+ /** One cell of a month grid. */
5
+ export interface G9DayCell {
6
+ readonly date: G9LocalDate;
7
+ /** Day of the month in the grid's calendar. */
8
+ readonly day: number;
9
+ readonly inMonth: boolean;
10
+ readonly weekday: number;
11
+ readonly key: string;
12
+ }
13
+ /** A month in `calendar` as weeks of 7 cells (6 rows when `fixedRows`, else just enough). */
14
+ export declare function monthGrid(calendar: G9CalendarSystem, year: number, month: number, weekStart: number, fixedRows?: boolean): G9DayCell[][];
15
+ /** The month after (or before, `delta` < 0) a calendar month. */
16
+ export declare function shiftMonth(year: number, month: number, delta: number): {
17
+ readonly year: number;
18
+ readonly month: number;
19
+ };
20
+ /** Whether two local dates are the same day (calendar-independent: compares the ISO date). */
21
+ export declare const sameDay: (a: G9LocalDate, b: G9LocalDate) => boolean;
22
+ /** How an event repeats. */
23
+ export interface G9Recurrence {
24
+ readonly freq: 'daily' | 'weekly' | 'monthly' | 'yearly';
25
+ /** Every n periods. Default 1. */
26
+ readonly interval?: number;
27
+ /** Weekly: the weekdays (0 = Sunday … 6 = Saturday). Default the start's weekday. */
28
+ readonly weekdays?: readonly number[];
29
+ readonly until?: G9LocalDate;
30
+ readonly count?: number;
31
+ }
32
+ /**
33
+ * The occurrences of a recurrence that start on or after `from` and on or before `to`, in the event's calendar
34
+ * (a monthly event on the 31st skips shorter months, as calendars do). At most 1000 are produced.
35
+ */
36
+ export declare function occurrences(start: G9LocalDate, rule: G9Recurrence, from: G9LocalDate, to: G9LocalDate, calendar?: G9CalendarSystem): G9LocalDate[];
37
+ /** An event in a day, minutes from midnight. */
38
+ export interface G9TimedEvent {
39
+ readonly id: string;
40
+ readonly start: number;
41
+ readonly end: number;
42
+ }
43
+ /** Where an event is drawn in a day column: its lane and how many lanes its cluster has. */
44
+ export interface G9EventPlacement {
45
+ readonly id: string;
46
+ readonly start: number;
47
+ readonly end: number;
48
+ readonly lane: number;
49
+ readonly lanes: number;
50
+ }
51
+ /** Packs overlapping events into lanes; every event of a cluster gets the cluster's lane count. */
52
+ export declare function layoutDay(events: readonly G9TimedEvent[]): G9EventPlacement[];
53
+ /** Agenda: events grouped by day (days without events left out), in order. */
54
+ export declare function agenda<T extends {
55
+ readonly date: G9LocalDate;
56
+ }>(items: readonly T[]): {
57
+ readonly date: G9LocalDate;
58
+ readonly items: readonly T[];
59
+ }[];
60
+ /** The quarter hour at `offsetY` px down a time grid's hours (minutes from midnight, inside `[fromHour, toHour)`). */
61
+ export declare function slotAt(offsetY: number, hourHeight: number, fromHour: number, toHour: number): number;
62
+ //# sourceMappingURL=model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAGA,OAAO,EAML,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAGjB,MAAM,+BAA+B,CAAC;AAEvC,2FAA2F;AAC3F,eAAO,MAAM,YAAY,GAAI,UAAU,gBAAgB,EAAE,UAAU,MAAM,KAAG,MACC,CAAC;AAE9E,gCAAgC;AAChC,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAC3B,+CAA+C;IAC/C,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAED,6FAA6F;AAC7F,wBAAgB,SAAS,CACvB,QAAQ,EAAE,gBAAgB,EAC1B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,EACjB,SAAS,UAAQ,GAChB,SAAS,EAAE,EAAE,CAuBf;AAED,iEAAiE;AACjE,wBAAgB,UAAU,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C,KAAK,EAAE,MAAM,CAAC;CACxB;AAED,mGAAmG;AACnG,wBAAgB,SAAS,CAAC,MAAM,EAAE,SAAS,YAAY,EAAE,GAAG,gBAAgB,EAAE,CAuB7E;AAED,8EAA8E;AAC9E,wBAAgB,MAAM,CAAC,CAAC,SAAS;IAAE,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAA;CAAE,EAC7D,KAAK,EAAE,SAAS,CAAC,EAAE,GAClB;IAAE,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC,EAAE,CAAA;CAAE,EAAE,CAShE;AAED,sHAAsH;AACtH,wBAAgB,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAGpG"}
package/dist/model.jsx ADDED
@@ -0,0 +1,137 @@
1
+ import { addDays, compareLocal, dayOfWeek, daysInMonth, fromCalendarDate, toCalendarDate, toEpochDays } from "@g9tm/lynxcontrols-foundation";
2
+ const weekStartFor = (calendar, language)=>'persian' === calendar || 'fa' === language ? 6 : 'en' === language ? 0 : 1;
3
+ function monthGrid(calendar, year, month, weekStart, fixedRows = false) {
4
+ const first = fromCalendarDate({
5
+ calendar,
6
+ year,
7
+ month,
8
+ day: 1
9
+ });
10
+ const lead = (dayOfWeek(first) - weekStart + 7) % 7;
11
+ const total = daysInMonth(calendar, year, month);
12
+ const rows = fixedRows ? 6 : Math.ceil((lead + total) / 7);
13
+ const start = addDays(first, -lead);
14
+ const out = [];
15
+ for(let r = 0; r < rows; r++){
16
+ const week = [];
17
+ for(let c = 0; c < 7; c++){
18
+ const date = addDays(start, 7 * r + c);
19
+ const cd = toCalendarDate(date, calendar);
20
+ week.push({
21
+ date,
22
+ day: cd.day,
23
+ inMonth: cd.year === year && cd.month === month,
24
+ weekday: dayOfWeek(date),
25
+ key: `${toEpochDays(date)}`
26
+ });
27
+ }
28
+ out.push(week);
29
+ }
30
+ return out;
31
+ }
32
+ function shiftMonth(year, month, delta) {
33
+ const i = 12 * year + (month - 1) + delta;
34
+ return {
35
+ year: Math.floor(i / 12),
36
+ month: (i % 12 + 12) % 12 + 1
37
+ };
38
+ }
39
+ const sameDay = (a, b)=>0 === compareLocal(a, b);
40
+ function occurrences(start, rule, from, to, calendar = 'gregorian') {
41
+ var _rule_interval;
42
+ const interval = Math.max(1, null != (_rule_interval = rule.interval) ? _rule_interval : 1);
43
+ const out = [];
44
+ let made = 0;
45
+ const take = (d)=>{
46
+ if (compareLocal(d, start) < 0) return true;
47
+ if (rule.until && compareLocal(d, rule.until) > 0) return false;
48
+ if (void 0 !== rule.count && made >= rule.count) return false;
49
+ made++;
50
+ if (compareLocal(d, from) >= 0 && compareLocal(d, to) <= 0) out.push(d);
51
+ return compareLocal(d, to) <= 0 && out.length < 1000;
52
+ };
53
+ if ('daily' === rule.freq) for(let d = start; take(d); d = addDays(d, interval));
54
+ else if ('weekly' === rule.freq) {
55
+ var _rule_weekdays;
56
+ const days = [
57
+ ...(null == (_rule_weekdays = rule.weekdays) ? void 0 : _rule_weekdays.length) ? rule.weekdays : [
58
+ dayOfWeek(start)
59
+ ]
60
+ ].sort((a, b)=>a - b);
61
+ const weekOf = addDays(start, -dayOfWeek(start));
62
+ outer: for(let w = 0; w < 5200; w += interval)for (const wd of days)if (!take(addDays(weekOf, 7 * w + wd))) break outer;
63
+ } else {
64
+ const c0 = toCalendarDate(start, calendar);
65
+ for(let k = 0; k < 12000; k += interval){
66
+ const m = 'monthly' === rule.freq ? shiftMonth(c0.year, c0.month, k) : {
67
+ year: c0.year + k,
68
+ month: c0.month
69
+ };
70
+ if (!(c0.day > daysInMonth(calendar, m.year, m.month))) {
71
+ if (!take(fromCalendarDate({
72
+ calendar,
73
+ year: m.year,
74
+ month: m.month,
75
+ day: c0.day
76
+ }))) break;
77
+ }
78
+ }
79
+ }
80
+ return out;
81
+ }
82
+ function layoutDay(events) {
83
+ const sorted = [
84
+ ...events
85
+ ].sort((a, b)=>a.start - b.start || b.end - a.end);
86
+ const out = [];
87
+ let cluster = [];
88
+ let clusterEnd = -1;
89
+ const flush = ()=>{
90
+ const lanes = cluster.reduce((m, e)=>Math.max(m, e.lane + 1), 0);
91
+ for (const e of cluster)out.push({
92
+ ...e,
93
+ lanes
94
+ });
95
+ cluster = [];
96
+ };
97
+ for (const e of sorted){
98
+ if (cluster.length && e.start >= clusterEnd) {
99
+ flush();
100
+ clusterEnd = -1;
101
+ }
102
+ const used = new Set(cluster.filter((c)=>c.end > e.start).map((c)=>c.lane));
103
+ let lane = 0;
104
+ while(used.has(lane))lane++;
105
+ cluster.push({
106
+ id: e.id,
107
+ start: e.start,
108
+ end: Math.max(e.end, e.start + 15),
109
+ lane
110
+ });
111
+ clusterEnd = Math.max(clusterEnd, e.end);
112
+ }
113
+ if (cluster.length) flush();
114
+ return out;
115
+ }
116
+ function agenda(items) {
117
+ const map = new Map();
118
+ for (const it of items){
119
+ const k = toEpochDays(it.date);
120
+ const list = map.get(k);
121
+ if (list) list.push(it);
122
+ else map.set(k, [
123
+ it
124
+ ]);
125
+ }
126
+ return [
127
+ ...map.entries()
128
+ ].sort((a, b)=>a[0] - b[0]).map(([, list])=>({
129
+ date: list[0].date,
130
+ items: list
131
+ }));
132
+ }
133
+ function slotAt(offsetY, hourHeight, fromHour, toHour) {
134
+ const quarters = Math.floor(offsetY / hourHeight * 4);
135
+ return Math.min(60 * toHour - 15, Math.max(60 * fromHour, 60 * fromHour + 15 * quarters));
136
+ }
137
+ export { agenda, layoutDay, monthGrid, occurrences, sameDay, shiftMonth, slotAt, weekStartFor };
@@ -0,0 +1,22 @@
1
+ import './calendar.css';
2
+ import type { ReactNode } from '@lynx-js/react';
3
+ /** A day of a month in no particular year. */
4
+ export interface G9MonthDay {
5
+ readonly month: number;
6
+ readonly day: number;
7
+ }
8
+ /** The most days `month` (1–12) can have in the calendar, whatever the year. */
9
+ export declare function monthDayLength(calendar: 'persian' | 'gregorian', month: number): number;
10
+ /** Props of {@link G9MonthDayPicker}. */
11
+ export interface G9MonthDayPickerProps {
12
+ readonly id?: string;
13
+ readonly value: G9MonthDay | null;
14
+ /** `null` when the chosen month is tapped again (cleared). */
15
+ readonly onChange: (value: G9MonthDay | null) => void;
16
+ }
17
+ /**
18
+ * Two rows of chips: the twelve months of the culture's calendar, then the chosen month's days. Choosing another month
19
+ * keeps the day where that month has it (31 → 30 on a shorter one).
20
+ */
21
+ export declare function G9MonthDayPicker(props: G9MonthDayPickerProps): ReactNode;
22
+ //# sourceMappingURL=month-day.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"month-day.d.ts","sourceRoot":"","sources":["../src/month-day.tsx"],"names":[],"mappings":"AAGA,OAAO,gBAAgB,CAAC;AAMxB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,8CAA8C;AAC9C,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAKD,gFAAgF;AAChF,wBAAgB,cAAc,CAAC,QAAQ,EAAE,SAAS,GAAG,WAAW,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAEvF;AAED,yCAAyC;AACzC,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,CAAC;IAClC,8DAA8D;IAC9D,QAAQ,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,KAAK,IAAI,CAAC;CACvD;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,GAAG,SAAS,CAiDxE"}