@savvycal/calendar 0.2.0 → 0.3.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.
@@ -1 +1 @@
1
- {"version":3,"file":"ResourceGridView.d.ts","sourceRoot":"","sources":["../../../src/components/resource-grid-view/ResourceGridView.tsx"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAIV,qBAAqB,EAGtB,MAAM,kBAAkB,CAAC;AAa1B,wBAAgB,gBAAgB,CAAC,EAC/B,IAAI,EACJ,QAAQ,EACR,SAAS,EACT,MAAM,EACN,YAAY,EACZ,cAAc,EACd,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,mBAAmB,EACnB,aAAa,EACb,QAAQ,EACR,WAAW,EACX,SAAS,EACT,UAAU,EACV,UAAe,EACf,cAAoB,EACpB,YAAY,EACZ,WAAW,EACX,mBAAmB,EACnB,qBAAqB,EACrB,YAAY,EACZ,iBAAqB,EACrB,eAAe,EACf,gBAAgB,EAChB,YAAY,EACZ,QAAQ,EACR,WAAuB,EACvB,WAAe,GAChB,EAAE,qBAAqB,2CA0XvB"}
1
+ {"version":3,"file":"ResourceGridView.d.ts","sourceRoot":"","sources":["../../../src/components/resource-grid-view/ResourceGridView.tsx"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAIV,qBAAqB,EAGtB,MAAM,kBAAkB,CAAC;AAa1B,wBAAgB,gBAAgB,CAAC,EAC/B,IAAI,EACJ,QAAQ,EACR,SAAS,EACT,MAAM,EACN,YAAY,EACZ,cAAc,EACd,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,mBAAmB,EACnB,aAAa,EACb,QAAQ,EACR,WAAW,EACX,SAAS,EACT,UAAU,EACV,UAAe,EACf,cAAoB,EACpB,YAAY,EACZ,WAAW,EACX,mBAAmB,EACnB,qBAAqB,EACrB,YAAY,EACZ,iBAAqB,EACrB,eAAe,EACf,gBAAgB,EAChB,YAAY,EACZ,QAAQ,EACR,WAAuB,EACvB,WAAe,GAChB,EAAE,qBAAqB,2CA+XvB"}
@@ -1,226 +1,223 @@
1
- import { jsxs as W, jsx as n } from "react/jsx-runtime";
2
- import { useCallback as v, useRef as mt, useState as ut, useEffect as L, useMemo as f } from "react";
3
- import { cn as T } from "../../lib/utils.js";
4
- import { generateTimeSlots as pt, formatDateLabel as ft, formatTimeRange as U } from "../../lib/time.js";
5
- import { groupByResource as ht, computePositionedEvents as gt } from "../../lib/overlap.js";
6
- import { computeUnavailableBlocks as yt } from "../../lib/availability.js";
7
- import { resourceGridViewDefaults as wt } from "./defaults.js";
8
- import { GridHeader as Ht } from "./GridHeader.js";
1
+ import { jsxs as L, jsx as n } from "react/jsx-runtime";
2
+ import { useCallback as v, useRef as U, useState as ft, useEffect as V, useMemo as p } from "react";
3
+ import { cn as $ } from "../../lib/utils.js";
4
+ import { generateTimeSlots as pt, formatDateLabel as ht, formatTimeRange as z } from "../../lib/time.js";
5
+ import { groupByResource as gt, computePositionedEvents as yt } from "../../lib/overlap.js";
6
+ import { computeUnavailableBlocks as wt } from "../../lib/availability.js";
7
+ import { resourceGridViewDefaults as Ht } from "./defaults.js";
8
+ import { GridHeader as Rt } from "./GridHeader.js";
9
9
  import { TimeGutter as St } from "./TimeGutter.js";
10
- import { ResourceColumn as Rt } from "./ResourceColumn.js";
11
- import { SlotInteractionLayer as bt } from "./SlotInteractionLayer.js";
12
- import { SelectionOverlay as Ct } from "./SelectionOverlay.js";
13
- import { UnavailabilityOverlay as Dt } from "./UnavailabilityOverlay.js";
10
+ import { ResourceColumn as bt } from "./ResourceColumn.js";
11
+ import { SlotInteractionLayer as Ct } from "./SlotInteractionLayer.js";
12
+ import { SelectionOverlay as Dt } from "./SelectionOverlay.js";
13
+ import { UnavailabilityOverlay as Tt } from "./UnavailabilityOverlay.js";
14
14
  import { NowIndicator as vt } from "./NowIndicator.js";
15
- import { AllDayRow as Tt } from "./AllDayRow.js";
16
- import { useEffectiveHourHeight as $t } from "./useEffectiveHourHeight.js";
17
- import { useAnnouncer as xt } from "./useAnnouncer.js";
18
- function Pt({
15
+ import { AllDayRow as $t } from "./AllDayRow.js";
16
+ import { useEffectiveHourHeight as xt } from "./useEffectiveHourHeight.js";
17
+ import { useAnnouncer as kt } from "./useAnnouncer.js";
18
+ function qt({
19
19
  date: a,
20
20
  timeZone: l,
21
- resources: r,
22
- events: $,
23
- availability: g,
24
- unavailability: y,
25
- timeAxis: H,
26
- onEventClick: x,
27
- snapDuration: k,
28
- placeholderDuration: V,
29
- selectedRange: u,
30
- onSelect: m,
31
- onSlotClick: z,
32
- className: A,
33
- classNames: N,
34
- hourHeight: F = 60,
35
- columnMinWidth: K = 120,
36
- renderHeader: P,
21
+ resources: o,
22
+ events: x,
23
+ availability: y,
24
+ unavailability: w,
25
+ timeAxis: R,
26
+ onEventClick: k,
27
+ snapDuration: N,
28
+ placeholderDuration: A,
29
+ selectedRange: m,
30
+ onSelect: u,
31
+ onSlotClick: F,
32
+ className: K,
33
+ classNames: E,
34
+ hourHeight: P = 60,
35
+ columnMinWidth: q = 120,
36
+ renderHeader: J,
37
37
  renderEvent: S,
38
- selectionAppearance: q,
39
- dragPreviewAppearance: J,
40
- selectionRef: Q,
41
- selectionLingerMs: R = 0,
42
- selectedEventId: E,
43
- selectedEventRef: j,
44
- renderCorner: X,
45
- eventGap: Y,
46
- eventLayout: _ = "columns",
47
- stackOffset: Z = 8
38
+ selectionAppearance: Q,
39
+ dragPreviewAppearance: X,
40
+ selectionRef: Y,
41
+ selectionLingerMs: b = 0,
42
+ selectedEventId: j,
43
+ selectedEventRef: I,
44
+ renderCorner: _,
45
+ eventGap: Z,
46
+ eventLayout: tt = "columns",
47
+ stackOffset: et = 8
48
48
  }) {
49
- const d = H?.startHour ?? 0, c = H?.endHour ?? 24, b = H?.intervalMinutes ?? 60, { effectiveHourHeight: s, rootRef: tt, headerRef: et, allDayRef: ot, headerHeight: I } = $t(F, c - d), i = v(
50
- (t) => T(wt[t], N?.[t]),
51
- [N]
52
- ), w = mt(null), [rt, B] = ut(
49
+ const c = R?.startHour ?? 0, d = R?.endHour ?? 24, C = R?.intervalMinutes ?? 60, { effectiveHourHeight: s, rootRef: rt, headerRef: ot, allDayRef: it, headerHeight: B } = xt(P, d - c), i = v(
50
+ (t) => $(Ht[t], E?.[t]),
51
+ [E]
52
+ ), H = U(null), h = U(null), [lt, M] = ft(
53
53
  null
54
54
  );
55
- L(() => {
56
- if (u)
57
- w.current = u;
58
- else if (w.current && R > 0) {
59
- const t = w.current;
60
- w.current = null, B(t);
61
- const e = setTimeout(
62
- () => B(null),
63
- R
64
- );
65
- return () => clearTimeout(e);
55
+ V(() => {
56
+ if (m)
57
+ h.current !== null && (clearTimeout(h.current), h.current = null), H.current = m;
58
+ else if (H.current && b > 0) {
59
+ const t = H.current;
60
+ H.current = null, M(t), h.current = setTimeout(() => {
61
+ h.current = null, M(null);
62
+ }, b);
66
63
  }
67
- }, [u, R]);
68
- const C = u ?? rt, D = f(
69
- () => pt({ startHour: d, endHour: c, intervalMinutes: b }),
70
- [d, c, b]
71
- ), { allDayEvents: M, timedEvents: G } = f(() => {
64
+ }, [m, b]);
65
+ const D = m ?? lt, T = p(
66
+ () => pt({ startHour: c, endHour: d, intervalMinutes: C }),
67
+ [c, d, C]
68
+ ), { allDayEvents: G, timedEvents: O } = p(() => {
72
69
  const t = [], e = [];
73
- for (const o of $)
74
- o.allDay ? t.push(o) : e.push(o);
70
+ for (const r of x)
71
+ r.allDay ? t.push(r) : e.push(r);
75
72
  return { allDayEvents: t, timedEvents: e };
76
- }, [$]), it = f(
77
- () => ht(M),
78
- [M]
79
- ), lt = f(
80
- () => gt(
81
- G,
73
+ }, [x]), nt = p(
74
+ () => gt(G),
75
+ [G]
76
+ ), at = p(
77
+ () => yt(
78
+ O,
82
79
  l,
83
80
  a,
84
- d,
85
81
  c,
82
+ d,
86
83
  s
87
84
  ),
88
- [G, l, a, d, c, s]
89
- ), nt = f(() => {
90
- if (!g && !y)
85
+ [O, l, a, c, d, s]
86
+ ), ct = p(() => {
87
+ if (!y && !w)
91
88
  return /* @__PURE__ */ new Map();
92
89
  const t = /* @__PURE__ */ new Set([
93
- ...Object.keys(g ?? {}),
94
- ...Object.keys(y ?? {})
90
+ ...Object.keys(y ?? {}),
91
+ ...Object.keys(w ?? {})
95
92
  ]), e = /* @__PURE__ */ new Map();
96
- for (const o of t) {
97
- const p = yt(
98
- g?.[o],
99
- y?.[o],
93
+ for (const r of t) {
94
+ const f = wt(
95
+ y?.[r],
96
+ w?.[r],
100
97
  l,
101
98
  a,
102
- d,
103
99
  c,
100
+ d,
104
101
  s
105
102
  );
106
- p.length > 0 && e.set(o, p);
103
+ f.length > 0 && e.set(r, f);
107
104
  }
108
105
  return e;
109
106
  }, [
110
- g,
111
107
  y,
108
+ w,
112
109
  l,
113
110
  a,
114
- d,
115
111
  c,
112
+ d,
116
113
  s
117
- ]), { message: at, announce: h } = xt(), dt = f(
118
- () => `Schedule for ${ft(a)}`,
114
+ ]), { message: dt, announce: g } = kt(), st = p(
115
+ () => `Schedule for ${ht(a)}`,
119
116
  [a]
120
- ), O = v(
117
+ ), W = v(
121
118
  (t) => {
122
- if (m?.(null), x?.(t), t.allDay) {
119
+ if (u?.(null), k?.(t), t.allDay) {
123
120
  const e = [t.title, "all day"];
124
- t.clientName && e.push(t.clientName), h(`Selected: ${e.join(", ")}`);
121
+ t.clientName && e.push(t.clientName), g(`Selected: ${e.join(", ")}`);
125
122
  } else {
126
123
  const e = [
127
124
  t.title,
128
- U(t.startTime, t.endTime, l)
125
+ z(t.startTime, t.endTime, l)
129
126
  ];
130
127
  t.clientName && e.push(t.clientName);
131
- const o = r.find((p) => p.id === t.resourceId);
132
- o && e.push(o.name), h(`Selected: ${e.join(", ")}`);
128
+ const r = o.find((f) => f.id === t.resourceId);
129
+ r && e.push(r.name), g(`Selected: ${e.join(", ")}`);
133
130
  }
134
131
  },
135
- [m, x, l, r, h]
136
- ), ct = v(
132
+ [u, k, l, o, g]
133
+ ), ut = v(
137
134
  (t) => {
138
- if (m?.(t), t) {
135
+ if (u?.(t), t) {
139
136
  const e = [
140
- U(t.startTime, t.endTime, l)
141
- ], o = r.find((p) => p.id === t.resourceId);
142
- o && e.push(o.name), h(`Selected time: ${e.join(", ")}`);
137
+ z(t.startTime, t.endTime, l)
138
+ ], r = o.find((f) => f.id === t.resourceId);
139
+ r && e.push(r.name), g(`Selected time: ${e.join(", ")}`);
143
140
  }
144
141
  },
145
- [m, l, r, h]
142
+ [u, l, o, g]
146
143
  );
147
- L(() => {
148
- if (!u || !m) return;
144
+ V(() => {
145
+ if (!m || !u) return;
149
146
  const t = (e) => {
150
- e.key === "Escape" && m(null);
147
+ e.key === "Escape" && u(null);
151
148
  };
152
149
  return document.addEventListener("keydown", t), () => document.removeEventListener("keydown", t);
153
- }, [u, m]);
154
- const st = s * b / 60;
155
- return /* @__PURE__ */ W("div", { ref: tt, className: T(i("root"), A), children: [
156
- /* @__PURE__ */ W(
150
+ }, [m, u]);
151
+ const mt = s * C / 60;
152
+ return /* @__PURE__ */ L("div", { ref: rt, className: $(i("root"), K), children: [
153
+ /* @__PURE__ */ L(
157
154
  "div",
158
155
  {
159
156
  className: i("grid"),
160
157
  role: "region",
161
158
  "aria-roledescription": "calendar",
162
- "aria-label": dt,
159
+ "aria-label": st,
163
160
  style: {
164
161
  display: "grid",
165
- gridTemplateColumns: `max-content repeat(${r.length}, minmax(${K}px, 1fr))`,
166
- gridTemplateRows: `auto auto repeat(${D.length}, ${st}px)`
162
+ gridTemplateColumns: `max-content repeat(${o.length}, minmax(${q}px, 1fr))`,
163
+ gridTemplateRows: `auto auto repeat(${T.length}, ${mt}px)`
167
164
  },
168
165
  children: [
169
166
  /* @__PURE__ */ n(
170
167
  "div",
171
168
  {
172
- ref: et,
169
+ ref: ot,
173
170
  className: i("cornerCell"),
174
171
  style: { gridRow: 1, gridColumn: 1 },
175
- children: X?.({ timeZone: l, date: a })
172
+ children: _?.({ timeZone: l, date: a })
176
173
  }
177
174
  ),
178
- r.map((t, e) => /* @__PURE__ */ n(
179
- Ht,
175
+ o.map((t, e) => /* @__PURE__ */ n(
176
+ Rt,
180
177
  {
181
178
  resource: t,
182
179
  column: e + 2,
183
180
  cls: i,
184
- renderHeader: P
181
+ renderHeader: J
185
182
  },
186
183
  t.id
187
184
  )),
188
185
  /* @__PURE__ */ n(
189
186
  "div",
190
187
  {
191
- ref: ot,
192
- className: T(i("allDayCell"), "left-0 z-30"),
188
+ ref: it,
189
+ className: $(i("allDayCell"), "left-0 z-30"),
193
190
  style: {
194
191
  gridRow: 2,
195
192
  gridColumn: 1,
196
- top: I
193
+ top: B
197
194
  }
198
195
  }
199
196
  ),
200
- r.map((t, e) => /* @__PURE__ */ n(
197
+ o.map((t, e) => /* @__PURE__ */ n(
201
198
  "div",
202
199
  {
203
200
  className: i("allDayCell"),
204
201
  style: {
205
202
  gridRow: 2,
206
203
  gridColumn: e + 2,
207
- top: I,
208
- ...e === r.length - 1 ? { borderRightWidth: 0 } : {}
204
+ top: B,
205
+ ...e === o.length - 1 ? { borderRightWidth: 0 } : {}
209
206
  },
210
207
  children: /* @__PURE__ */ n(
211
- Tt,
208
+ $t,
212
209
  {
213
- events: it.get(t.id) ?? [],
210
+ events: nt.get(t.id) ?? [],
214
211
  cls: i,
215
- onEventClick: O,
216
- selectedEventId: E,
217
- selectedEventRef: j
212
+ onEventClick: W,
213
+ selectedEventId: j,
214
+ selectedEventRef: I
218
215
  }
219
216
  )
220
217
  },
221
218
  `allday-${t.id}`
222
219
  )),
223
- D.map((t) => /* @__PURE__ */ n(
220
+ T.map((t) => /* @__PURE__ */ n(
224
221
  St,
225
222
  {
226
223
  label: t.label,
@@ -231,89 +228,89 @@ function Pt({
231
228
  },
232
229
  t.index
233
230
  )),
234
- D.map(
235
- (t) => r.map((e, o) => /* @__PURE__ */ n(
231
+ T.map(
232
+ (t) => o.map((e, r) => /* @__PURE__ */ n(
236
233
  "div",
237
234
  {
238
235
  className: i(t.isHourStart ? "bodyCell" : "bodyCellMinor"),
239
236
  style: {
240
237
  gridRow: t.index + 3,
241
- gridColumn: o + 2,
238
+ gridColumn: r + 2,
242
239
  ...t.isHourStart ? {} : { borderTopStyle: "dotted" },
243
240
  ...t.index === 0 ? { borderTopWidth: 0 } : {},
244
- ...o === r.length - 1 ? { borderRightWidth: 0 } : {}
241
+ ...r === o.length - 1 ? { borderRightWidth: 0 } : {}
245
242
  }
246
243
  },
247
244
  `${t.index}-${e.id}`
248
245
  ))
249
246
  ),
250
- r.map((t, e) => {
251
- const o = nt.get(t.id);
252
- return o ? /* @__PURE__ */ n(
253
- Dt,
247
+ o.map((t, e) => {
248
+ const r = ct.get(t.id);
249
+ return r ? /* @__PURE__ */ n(
250
+ Tt,
254
251
  {
255
- blocks: o,
252
+ blocks: r,
256
253
  column: e + 2,
257
254
  cls: i
258
255
  },
259
256
  `unavail-${t.id}`
260
257
  ) : null;
261
258
  }),
262
- k != null && r.map((t, e) => /* @__PURE__ */ n(
263
- bt,
259
+ N != null && o.map((t, e) => /* @__PURE__ */ n(
260
+ Ct,
264
261
  {
265
262
  resource: t,
266
263
  column: e + 2,
267
264
  date: a,
268
265
  timeZone: l,
269
- startHour: d,
270
- endHour: c,
266
+ startHour: c,
267
+ endHour: d,
271
268
  hourHeight: s,
272
- snapDuration: k,
273
- placeholderDuration: V ?? 15,
269
+ snapDuration: N,
270
+ placeholderDuration: A ?? 15,
274
271
  cls: i,
275
- onSlotClick: z,
276
- onSelect: ct,
277
- dragPreviewAppearance: J,
272
+ onSlotClick: F,
273
+ onSelect: ut,
274
+ dragPreviewAppearance: X,
278
275
  renderEvent: S
279
276
  },
280
277
  `slot-${t.id}`
281
278
  )),
282
- r.map((t, e) => /* @__PURE__ */ n(
283
- Rt,
279
+ o.map((t, e) => /* @__PURE__ */ n(
280
+ bt,
284
281
  {
285
282
  resource: t,
286
- positionedEvents: lt.get(t.id) ?? [],
283
+ positionedEvents: at.get(t.id) ?? [],
287
284
  column: e + 2,
288
285
  timeZone: l,
289
286
  cls: i,
290
- onEventClick: O,
287
+ onEventClick: W,
291
288
  renderEvent: S,
292
- eventGap: Y,
293
- eventLayout: _,
294
- stackOffset: Z,
295
- selectedEventId: E,
296
- selectedEventRef: j
289
+ eventGap: Z,
290
+ eventLayout: tt,
291
+ stackOffset: et,
292
+ selectedEventId: j,
293
+ selectedEventRef: I
297
294
  },
298
295
  t.id
299
296
  )),
300
- C != null && (() => {
301
- const t = r.findIndex(
302
- (e) => e.id === C.resourceId
297
+ D != null && (() => {
298
+ const t = o.findIndex(
299
+ (e) => e.id === D.resourceId
303
300
  );
304
301
  return t === -1 ? null : /* @__PURE__ */ n(
305
- Ct,
302
+ Dt,
306
303
  {
307
- selectedRange: C,
304
+ selectedRange: D,
308
305
  column: t + 2,
309
- resource: r[t],
306
+ resource: o[t],
310
307
  viewDate: a,
311
308
  timeZone: l,
312
- startHour: d,
309
+ startHour: c,
313
310
  hourHeight: s,
314
311
  cls: i,
315
- appearance: q,
316
- selectionRef: Q,
312
+ appearance: Q,
313
+ selectionRef: Y,
317
314
  renderEvent: S
318
315
  }
319
316
  );
@@ -323,8 +320,8 @@ function Pt({
323
320
  {
324
321
  date: a,
325
322
  timeZone: l,
326
- startHour: d,
327
- endHour: c,
323
+ startHour: c,
324
+ endHour: d,
328
325
  hourHeight: s,
329
326
  cls: i
330
327
  }
@@ -349,11 +346,11 @@ function Pt({
349
346
  whiteSpace: "nowrap",
350
347
  borderWidth: 0
351
348
  },
352
- children: at
349
+ children: dt
353
350
  }
354
351
  )
355
352
  ] });
356
353
  }
357
354
  export {
358
- Pt as ResourceGridView
355
+ qt as ResourceGridView
359
356
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@savvycal/calendar",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {