@dxos/react-ui-calendar 0.8.4-main.e8ec1fe → 0.8.4-main.f466a3d56e

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/LICENSE CHANGED
@@ -1,8 +1,105 @@
1
- MIT License
2
- Copyright (c) 2022 DXOS
1
+ # Functional Source License, Version 1.1, ALv2 Future License
3
2
 
4
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
3
+ ## Abbreviation
5
4
 
6
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
5
+ FSL-1.1-Apache-2.0
7
6
 
8
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
7
+ ## Notice
8
+
9
+ Copyright 2026 DXOS
10
+
11
+ ## Terms and Conditions
12
+
13
+ ### Licensor ("We")
14
+
15
+ The party offering the Software under these Terms and Conditions.
16
+
17
+ ### The Software
18
+
19
+ The "Software" is each version of the software that we make available under
20
+ these Terms and Conditions, as indicated by our inclusion of these Terms and
21
+ Conditions with the Software.
22
+
23
+ ### License Grant
24
+
25
+ Subject to your compliance with this License Grant and the Patents,
26
+ Redistribution and Trademark clauses below, we hereby grant you the right to
27
+ use, copy, modify, create derivative works, publicly perform, publicly display
28
+ and redistribute the Software for any Permitted Purpose identified below.
29
+
30
+ ### Permitted Purpose
31
+
32
+ A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
33
+ means making the Software available to others in a commercial product or
34
+ service that:
35
+
36
+ 1. substitutes for the Software;
37
+
38
+ 2. substitutes for any other product or service we offer using the Software
39
+ that exists as of the date we make the Software available; or
40
+
41
+ 3. offers the same or substantially similar functionality as the Software.
42
+
43
+ Permitted Purposes specifically include using the Software:
44
+
45
+ 1. for your internal use and access;
46
+
47
+ 2. for non-commercial education;
48
+
49
+ 3. for non-commercial research; and
50
+
51
+ 4. in connection with professional services that you provide to a licensee
52
+ using the Software in accordance with these Terms and Conditions.
53
+
54
+ ### Patents
55
+
56
+ To the extent your use for a Permitted Purpose would necessarily infringe our
57
+ patents, the license grant above includes a license under our patents. If you
58
+ make a claim against any party that the Software infringes or contributes to
59
+ the infringement of any patent, then your patent license to the Software ends
60
+ immediately.
61
+
62
+ ### Redistribution
63
+
64
+ The Terms and Conditions apply to all copies, modifications and derivatives of
65
+ the Software.
66
+
67
+ If you redistribute any copies, modifications or derivatives of the Software,
68
+ you must include a copy of or a link to these Terms and Conditions and not
69
+ remove any copyright notices provided in or with the Software.
70
+
71
+ ### Disclaimer
72
+
73
+ THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
74
+ IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
75
+ PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
76
+
77
+ IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
78
+ SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
79
+ EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
80
+
81
+ ### Trademarks
82
+
83
+ Except for displaying the License Details and identifying us as the origin of
84
+ the Software, you have no right under these Terms and Conditions to use our
85
+ trademarks, trade names, service marks or product names.
86
+
87
+ ## Grant of Future License
88
+
89
+ We hereby irrevocably grant you an additional license to use the Software under
90
+ the Apache License, Version 2.0 that is effective on the second anniversary of
91
+ the date we make the Software available. On or after that date, you may use the
92
+ Software under the Apache License, Version 2.0, in which case the following
93
+ will apply:
94
+
95
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
96
+ this file except in compliance with the License.
97
+
98
+ You may obtain a copy of the License at
99
+
100
+ http://www.apache.org/licenses/LICENSE-2.0
101
+
102
+ Unless required by applicable law or agreed to in writing, software distributed
103
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
104
+ CONDITIONS OF ANY KIND, either express or implied. See the License for the
105
+ specific language governing permissions and limitations under the License.
@@ -1,25 +1,13 @@
1
1
  // src/components/Calendar/Calendar.tsx
2
- import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
3
2
  import { createContext } from "@radix-ui/react-context";
4
- import { addDays, differenceInWeeks, format, startOfWeek } from "date-fns";
3
+ import { addDays, differenceInWeeks, format, startOfDay, startOfWeek } from "date-fns";
5
4
  import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from "react";
6
5
  import { useResizeDetector } from "react-resize-detector";
7
6
  import { List } from "react-virtualized";
8
7
  import { Event } from "@dxos/async";
9
- import { Icon, IconButton, useTranslation } from "@dxos/react-ui";
10
- import { mx } from "@dxos/react-ui-theme";
11
-
12
- // src/translations.ts
13
- var translationKey = "react-ui-calendar";
14
- var translations = [
15
- {
16
- "en-US": {
17
- [translationKey]: {
18
- "today button": "Today"
19
- }
20
- }
21
- }
22
- ];
8
+ import { IconButton, useTranslation } from "@dxos/react-ui";
9
+ import { composable, composableProps, mx } from "@dxos/ui-theme";
10
+ import { translationKey } from "#translations";
23
11
 
24
12
  // src/components/Calendar/util.ts
25
13
  var getDate = (start2, weekNumber, dayOfWeek, weekStartsOn) => {
@@ -40,236 +28,203 @@ var size = 48;
40
28
  var defaultWidth = 7 * size;
41
29
  var [CalendarContextProvider, useCalendarContext] = createContext("Calendar");
42
30
  var CalendarRoot = /* @__PURE__ */ forwardRef(({ children, weekStartsOn = 1 }, forwardedRef) => {
43
- var _effect = _useSignals();
44
- try {
45
- const event = useMemo(() => new Event(), []);
46
- const [selected, setSelected] = useState();
47
- const [index, setIndex] = useState();
48
- useImperativeHandle(forwardedRef, () => ({
49
- scrollTo: (date) => {
50
- event.emit({
51
- type: "scroll",
52
- date
53
- });
54
- }
55
- }), [
56
- event
57
- ]);
58
- return /* @__PURE__ */ React.createElement(CalendarContextProvider, {
59
- weekStartsOn,
60
- event,
61
- index,
62
- setIndex,
63
- selected,
64
- setSelected
65
- }, children);
66
- } finally {
67
- _effect.f();
68
- }
69
- });
70
- var CalendarViewport = ({ children, classNames }) => {
71
- var _effect = _useSignals();
72
- try {
73
- return /* @__PURE__ */ React.createElement("div", {
74
- role: "none",
75
- className: mx("flex flex-col items-center overflow-hidden bg-inputSurface", classNames)
76
- }, children);
77
- } finally {
78
- _effect.f();
79
- }
80
- };
81
- CalendarViewport.displayName = "CalendarContent";
82
- var CalendarToolbar = ({ classNames }) => {
83
- var _effect = _useSignals();
84
- try {
85
- const { t } = useTranslation(translationKey);
86
- const { weekStartsOn, event, index, selected } = useCalendarContext(CalendarToolbar.displayName);
87
- const top = useMemo(() => getDate(start, index ?? 0, 6, weekStartsOn), [
88
- index,
89
- weekStartsOn
90
- ]);
91
- const today = useMemo(() => /* @__PURE__ */ new Date(), []);
92
- const handleToday = useCallback(() => {
31
+ const event = useMemo(() => new Event(), []);
32
+ const [selected, setSelected] = useState();
33
+ const [index, setIndex] = useState();
34
+ useImperativeHandle(forwardedRef, () => ({
35
+ scrollTo: (date) => {
93
36
  event.emit({
94
37
  type: "scroll",
95
- date: today
96
- });
97
- }, [
98
- event,
99
- start,
100
- today
101
- ]);
102
- return /* @__PURE__ */ React.createElement("div", {
103
- role: "none",
104
- className: mx("shink-0 is-full grid grid-cols-3 items-center bg-barSurface", classNames),
105
- style: {
106
- width: defaultWidth
107
- }
108
- }, /* @__PURE__ */ React.createElement("div", {
109
- className: "flex justify-start"
110
- }, /* @__PURE__ */ React.createElement(IconButton, {
111
- variant: "ghost",
112
- size: 5,
113
- icon: "ph--calendar--regular",
114
- iconOnly: true,
115
- classNames: "aspect-square",
116
- label: t("today button"),
117
- onClick: handleToday
118
- })), /* @__PURE__ */ React.createElement("div", {
119
- className: "flex justify-center p-2 text-description"
120
- }, format(selected ?? top, "MMMM")), /* @__PURE__ */ React.createElement("div", {
121
- className: "flex justify-end p-2 text-description"
122
- }, (selected ?? top).getFullYear()));
123
- } finally {
124
- _effect.f();
125
- }
126
- };
127
- CalendarToolbar.displayName = "CalendarHeader";
128
- var CalendarGrid = ({ classNames, rows, onSelect }) => {
129
- var _effect = _useSignals();
130
- try {
131
- const { weekStartsOn, event, setIndex, selected, setSelected } = useCalendarContext(CalendarGrid.displayName);
132
- const { ref: containerRef, width = 0, height = 0 } = useResizeDetector();
133
- const maxHeight = rows ? rows * size : void 0;
134
- const listRef = useRef(null);
135
- const today = useMemo(() => /* @__PURE__ */ new Date(), []);
136
- const [initialized, setInitialized] = useState(false);
137
- useEffect(() => {
138
- const index = differenceInWeeks(today, start);
139
- listRef.current?.scrollToRow(index);
140
- }, [
141
- initialized,
142
- start,
143
- today
144
- ]);
145
- useEffect(() => {
146
- return event.on((event2) => {
147
- switch (event2.type) {
148
- case "scroll": {
149
- const index = differenceInWeeks(event2.date, start);
150
- listRef.current?.scrollToRow(index);
151
- break;
152
- }
153
- }
154
- });
155
- }, [
156
- event
157
- ]);
158
- const days = useMemo(() => {
159
- const weekStart = startOfWeek(/* @__PURE__ */ new Date(), {
160
- weekStartsOn
161
- });
162
- return Array.from({
163
- length: 7
164
- }, (_, i) => {
165
- const day = addDays(weekStart, i);
166
- return format(day, "EEE");
167
- });
168
- }, []);
169
- const getNumAppointments = useCallback((_date) => {
170
- return 0;
171
- }, []);
172
- const handleDaySelect = useCallback((date) => {
173
- setSelected((current) => isSameDay(date, current) ? void 0 : date);
174
- onSelect?.({
175
38
  date
176
39
  });
177
- }, [
178
- onSelect
179
- ]);
180
- const handleScroll = useCallback((info) => {
181
- setIndex(Math.round(info.scrollTop / size));
182
- }, []);
183
- const rowRenderer = useCallback(({ key, index, style }) => {
184
- const getBgColor = (date) => date.getMonth() % 2 === 0 && "bg-modalSurface";
185
- return /* @__PURE__ */ React.createElement("div", {
186
- key,
187
- role: "none",
188
- style,
189
- className: "is-full grid grid-cols-[1fr_max-content_1fr] snap-center"
190
- }, /* @__PURE__ */ React.createElement("div", {
191
- role: "none",
192
- className: mx(getBgColor(getDate(start, index, 0, weekStartsOn)))
193
- }), /* @__PURE__ */ React.createElement("div", {
194
- role: "none",
195
- className: "grid grid-cols-7",
196
- style: {
197
- gridTemplateColumns: `repeat(7, ${size}px)`
40
+ }
41
+ }), [
42
+ event
43
+ ]);
44
+ return /* @__PURE__ */ React.createElement(CalendarContextProvider, {
45
+ weekStartsOn,
46
+ event,
47
+ index,
48
+ setIndex,
49
+ selected,
50
+ setSelected
51
+ }, children);
52
+ });
53
+ var CALENDAR_TOOLBAR_NAME = "CalendarHeader";
54
+ var CalendarToolbar = composable(({ classNames, ...props }, forwardedRef) => {
55
+ const { t } = useTranslation(translationKey);
56
+ const { weekStartsOn, event, index, selected } = useCalendarContext(CALENDAR_TOOLBAR_NAME);
57
+ const top = useMemo(() => getDate(start, index ?? 0, 6, weekStartsOn), [
58
+ index,
59
+ weekStartsOn
60
+ ]);
61
+ const today = useMemo(() => /* @__PURE__ */ new Date(), []);
62
+ const handleToday = useCallback(() => {
63
+ event.emit({
64
+ type: "scroll",
65
+ date: today
66
+ });
67
+ }, [
68
+ event,
69
+ start,
70
+ today
71
+ ]);
72
+ return /* @__PURE__ */ React.createElement("div", {
73
+ ...composableProps(props, {
74
+ role: "none",
75
+ classNames: [
76
+ "shrink-0 grid! grid-cols-3 items-center bg-toolbar-surface",
77
+ classNames
78
+ ]
79
+ }),
80
+ ref: forwardedRef,
81
+ style: {
82
+ width: defaultWidth
83
+ }
84
+ }, /* @__PURE__ */ React.createElement("div", {
85
+ className: "flex justify-start"
86
+ }, /* @__PURE__ */ React.createElement(IconButton, {
87
+ variant: "ghost",
88
+ icon: "ph--calendar--regular",
89
+ iconOnly: true,
90
+ classNames: "aspect-square",
91
+ label: t("today.button"),
92
+ onClick: handleToday
93
+ })), /* @__PURE__ */ React.createElement("div", {
94
+ className: "flex justify-center p-2 text-description"
95
+ }, format(selected ?? top, "MMMM")), /* @__PURE__ */ React.createElement("div", {
96
+ className: "flex justify-end p-2 text-description"
97
+ }, (selected ?? top).getFullYear()));
98
+ });
99
+ CalendarToolbar.displayName = CALENDAR_TOOLBAR_NAME;
100
+ var CALENDAR_GRID_NAME = "CalendarGrid";
101
+ var CalendarGrid = composable(({ classNames, rows, dates = [], onSelect, ...props }, forwardedRef) => {
102
+ const { weekStartsOn, event, setIndex, selected, setSelected } = useCalendarContext(CALENDAR_GRID_NAME);
103
+ const { ref: containerRef, width = 0, height = 0 } = useResizeDetector();
104
+ const maxHeight = rows ? rows * size : void 0;
105
+ const listRef = useRef(null);
106
+ const today = useMemo(() => /* @__PURE__ */ new Date(), []);
107
+ const dateSet = useMemo(() => new Set(dates.map((date) => startOfDay(date).toISOString())), [
108
+ dates
109
+ ]);
110
+ const hasDate = useCallback((date) => dateSet.has(startOfDay(date).toISOString()), [
111
+ dateSet
112
+ ]);
113
+ const [initialized, setInitialized] = useState(false);
114
+ useEffect(() => {
115
+ const index = differenceInWeeks(today, start);
116
+ listRef.current?.scrollToRow(index);
117
+ }, [
118
+ initialized,
119
+ start,
120
+ today
121
+ ]);
122
+ useEffect(() => {
123
+ return event.on((event2) => {
124
+ switch (event2.type) {
125
+ case "scroll": {
126
+ const index = differenceInWeeks(event2.date, start);
127
+ listRef.current?.scrollToRow(index);
128
+ break;
198
129
  }
199
- }, Array.from({
200
- length: 7
201
- }).map((_, i) => {
202
- const date = getDate(start, index, i, weekStartsOn);
203
- const num = getNumAppointments(date);
204
- const border = isSameDay(date, selected) ? "border-primary-500" : isSameDay(date, today) ? "border-amber-500" : void 0;
205
- return /* @__PURE__ */ React.createElement("div", {
206
- key: i,
207
- role: "none",
208
- className: mx("relative flex justify-center items-center cursor-pointer", getBgColor(date)),
209
- onClick: () => handleDaySelect(date)
210
- }, /* @__PURE__ */ React.createElement("span", {
211
- className: "text-description"
212
- }, date.getDate()), !border && date.getDate() === 1 && /* @__PURE__ */ React.createElement("span", {
213
- className: "absolute top-0 text-xs text-description"
214
- }, format(date, "MMM")), border && /* @__PURE__ */ React.createElement("div", {
215
- role: "none",
216
- className: mx("absolute top-0 left-0 is-full bs-full border-2 rounded-full", border)
217
- }), num > 0 && /* @__PURE__ */ React.createElement(Icon, {
218
- classNames: "absolute bottom-0",
219
- icon: num > 3 ? "ph--dots-three--regular" : "ph--dot--regular",
220
- size: 5
221
- }));
222
- })), /* @__PURE__ */ React.createElement("div", {
223
- className: mx(getBgColor(getDate(start, index, 6, weekStartsOn)))
224
- }));
225
- }, [
226
- handleDaySelect,
227
- getNumAppointments,
228
- selected,
130
+ }
131
+ });
132
+ }, [
133
+ event
134
+ ]);
135
+ const days = useMemo(() => {
136
+ const weekStart = startOfWeek(/* @__PURE__ */ new Date(), {
229
137
  weekStartsOn
230
- ]);
138
+ });
139
+ return Array.from({
140
+ length: 7
141
+ }, (_, i) => {
142
+ const day = addDays(weekStart, i);
143
+ return format(day, "EEE");
144
+ });
145
+ }, []);
146
+ const handleDaySelect = useCallback((date) => {
147
+ setSelected((current) => isSameDay(date, current) ? void 0 : date);
148
+ onSelect?.({
149
+ date
150
+ });
151
+ }, [
152
+ onSelect
153
+ ]);
154
+ const handleScroll = useCallback((info) => {
155
+ setIndex(Math.round(info.scrollTop / size));
156
+ }, []);
157
+ const rowRenderer = useCallback(({ key, index, style }) => {
158
+ const getBgColor = (date) => date.getMonth() % 2 === 0 && "bg-modal-surface";
231
159
  return /* @__PURE__ */ React.createElement("div", {
232
- role: "none",
233
- className: mx("flex flex-col bs-full is-full justify-center overflow-hidden", classNames)
234
- }, /* @__PURE__ */ React.createElement("div", {
235
- role: "none",
236
- className: "flex justify-center bg-groupSurface"
160
+ key,
161
+ style,
162
+ className: "grid"
237
163
  }, /* @__PURE__ */ React.createElement("div", {
238
- role: "none",
239
- className: "flex is-full grid grid-cols-7",
164
+ className: "grid grid-cols-7 bg-input-surface",
240
165
  style: {
241
- width: defaultWidth
166
+ gridTemplateColumns: `repeat(7, ${size}px)`
242
167
  }
243
- }, days.map((date, i) => /* @__PURE__ */ React.createElement("div", {
244
- key: i,
245
- role: "none",
246
- className: "flex justify-center p-2 text-sm font-thin"
247
- }, date)))), /* @__PURE__ */ React.createElement("div", {
248
- role: "none",
249
- className: "flex flex-col bs-full is-full justify-center overflow-hidden",
250
- ref: containerRef
251
- }, /* @__PURE__ */ React.createElement(List, {
252
- ref: listRef,
253
- role: "none",
254
- // TODO(burdon): Snap isn't working.
255
- className: "[&>div]:snap-y scrollbar-none outline-none",
256
- width,
257
- height: maxHeight ?? height,
258
- rowCount: maxRows,
259
- rowHeight: size,
260
- rowRenderer,
261
- scrollToAlignment: "start",
262
- onScroll: handleScroll,
263
- onRowsRendered: () => setInitialized(true)
168
+ }, Array.from({
169
+ length: 7
170
+ }).map((_, i) => {
171
+ const date = getDate(start, index, i, weekStartsOn);
172
+ const border = isSameDay(date, selected) ? "border-primary-500" : isSameDay(date, today) ? "border-amber-500" : hasDate(date) ? "border-neutral-700 border-dashed" : void 0;
173
+ return /* @__PURE__ */ React.createElement("div", {
174
+ key: i,
175
+ className: mx("relative flex justify-center items-center cursor-pointer", getBgColor(date)),
176
+ onClick: () => handleDaySelect(date)
177
+ }, /* @__PURE__ */ React.createElement("span", {
178
+ className: "text-description"
179
+ }, date.getDate()), !border && date.getDate() === 1 && /* @__PURE__ */ React.createElement("span", {
180
+ className: "absolute top-0 text-xs text-description"
181
+ }, format(date, "MMM")), border && /* @__PURE__ */ React.createElement("div", {
182
+ className: mx("absolute inset-1 border-2 rounded-full", border)
183
+ }));
264
184
  })));
265
- } finally {
266
- _effect.f();
267
- }
268
- };
269
- CalendarGrid.displayName = "CalendarGrid";
185
+ }, [
186
+ handleDaySelect,
187
+ hasDate,
188
+ selected,
189
+ weekStartsOn
190
+ ]);
191
+ return /* @__PURE__ */ React.createElement("div", {
192
+ ...composableProps(props, {
193
+ role: "none",
194
+ classNames: [
195
+ "flex flex-col h-full w-full justify-center overflow-hidden",
196
+ classNames
197
+ ]
198
+ }),
199
+ ref: forwardedRef
200
+ }, /* @__PURE__ */ React.createElement("div", {
201
+ className: "grid w-full grid-cols-7",
202
+ style: {
203
+ width: defaultWidth
204
+ }
205
+ }, days.map((date, i) => /* @__PURE__ */ React.createElement("div", {
206
+ key: i,
207
+ className: "flex justify-center p-2 text-sm font-thin"
208
+ }, date))), /* @__PURE__ */ React.createElement("div", {
209
+ className: "flex flex-col h-full w-full justify-center overflow-hidden",
210
+ ref: containerRef
211
+ }, /* @__PURE__ */ React.createElement(List, {
212
+ ref: listRef,
213
+ role: "none",
214
+ className: "scrollbar-none outline-hidden",
215
+ width,
216
+ height: maxHeight ?? height,
217
+ rowCount: maxRows,
218
+ rowHeight: size,
219
+ rowRenderer,
220
+ scrollToAlignment: "start",
221
+ onScroll: handleScroll,
222
+ onRowsRendered: () => setInitialized(true)
223
+ })));
224
+ });
225
+ CalendarGrid.displayName = CALENDAR_GRID_NAME;
270
226
  var Calendar = {
271
227
  Root: CalendarRoot,
272
- Viewport: CalendarViewport,
273
228
  Toolbar: CalendarToolbar,
274
229
  Grid: CalendarGrid
275
230
  };