@zealakit/chrono-react 1.0.0-beta.1 → 1.0.0-beta.2
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/README.md +1 -0
- package/dist/calendar/components.d.ts +2 -2
- package/dist/calendar/components.js +10 -12
- package/dist/calendar/mini-calendar.js +6 -5
- package/dist/calendar/use-calendar.js +1 -3
- package/dist/calendar/use-mini-calendar.js +1 -1
- package/dist/date/bind-panel.js +1 -1
- package/dist/date/components.js +20 -29
- package/dist/date/utilities.d.ts +1 -1
- package/dist/date/utilities.js +1 -1
- package/dist/datetime/components.js +16 -21
- package/dist/datetime/use-datetime-panel.js +1 -1
- package/dist/shared/defined-options.d.ts +18 -0
- package/dist/shared/defined-options.js +9 -0
- package/dist/shared/merge-props.js +1 -3
- package/dist/shared/part.d.ts +1 -1
- package/dist/shared/slot.js +1 -4
- package/dist/shared/style-properties.js +1 -1
- package/dist/time/bind-panel.js +2 -2
- package/dist/time/components.d.ts +2 -2
- package/dist/time/components.js +16 -21
- package/dist/time/utilities.d.ts +1 -1
- package/dist/time/utilities.js +1 -1
- package/dist/vendor/core/calendar/availability.d.ts +2 -2
- package/dist/vendor/core/calendar/availability.js +4 -5
- package/dist/vendor/core/calendar/controllers/calendar-controller.js +93 -145
- package/dist/vendor/core/calendar/controllers/drag-engine.js +15 -34
- package/dist/vendor/core/calendar/controllers/mini-calendar-controller.js +3 -2
- package/dist/vendor/core/calendar/controllers/shared.d.ts +9 -5
- package/dist/vendor/core/calendar/controllers/shared.js +8 -8
- package/dist/vendor/core/calendar/events/agenda-layout.js +4 -3
- package/dist/vendor/core/calendar/events/all-day-row.d.ts +1 -1
- package/dist/vendor/core/calendar/events/all-day-row.js +5 -5
- package/dist/vendor/core/calendar/events/background-layout.d.ts +1 -1
- package/dist/vendor/core/calendar/events/background-layout.js +6 -7
- package/dist/vendor/core/calendar/events/month-layout.js +6 -5
- package/dist/vendor/core/calendar/events/normalize.d.ts +2 -2
- package/dist/vendor/core/calendar/events/normalize.js +6 -9
- package/dist/vendor/core/calendar/events/now-indicator.d.ts +2 -2
- package/dist/vendor/core/calendar/events/time-grid-layout.d.ts +4 -4
- package/dist/vendor/core/calendar/events/time-grid-layout.js +8 -15
- package/dist/vendor/core/calendar/events/types.d.ts +2 -2
- package/dist/vendor/core/calendar/index.d.ts +11 -11
- package/dist/vendor/core/calendar/index.js +5 -5
- package/dist/vendor/core/calendar/interaction/auto-scroll.d.ts +1 -9
- package/dist/vendor/core/calendar/interaction/auto-scroll.js +12 -39
- package/dist/vendor/core/calendar/interaction/drag-geometry.js +2 -5
- package/dist/vendor/core/calendar/interaction/drag-keyboard.js +1 -4
- package/dist/vendor/core/calendar/interaction/drag-pointer.d.ts +5 -4
- package/dist/vendor/core/calendar/interaction/drag-pointer.js +33 -193
- package/dist/vendor/core/calendar/interaction/gesture-handle.d.ts +17 -0
- package/dist/vendor/core/calendar/interaction/gesture-handle.js +26 -0
- package/dist/vendor/core/calendar/interaction/pointer.d.ts +1 -1
- package/dist/vendor/core/calendar/interaction/pointer.js +65 -15
- package/dist/vendor/core/calendar/interaction/selection.d.ts +1 -1
- package/dist/vendor/core/calendar/navigation/navigate.d.ts +3 -3
- package/dist/vendor/core/calendar/navigation/navigate.js +1 -3
- package/dist/vendor/core/calendar/navigation/range.js +1 -1
- package/dist/vendor/core/calendar/navigation/view-definition.d.ts +1 -1
- package/dist/vendor/core/calendar/navigation/view-definition.js +2 -1
- package/dist/vendor/core/calendar/recurrence/apply.js +7 -8
- package/dist/vendor/core/calendar/recurrence/expand.d.ts +1 -1
- package/dist/vendor/core/calendar/recurrence/expand.js +14 -18
- package/dist/vendor/core/calendar/recurrence/pack.js +4 -7
- package/dist/vendor/core/calendar/recurrence/rrule.js +6 -16
- package/dist/vendor/core/calendar/recurrence/series.js +1 -3
- package/dist/vendor/core/calendar/recurrence/types.d.ts +1 -1
- package/dist/vendor/core/calendar/resources/resource-time-grid.js +1 -2
- package/dist/vendor/core/calendar/resources/timeline-layout.js +4 -6
- package/dist/vendor/core/calendar/resources/types.d.ts +7 -7
- package/dist/vendor/core/calendar/views/day.d.ts +5 -5
- package/dist/vendor/core/calendar/views/day.js +2 -5
- package/dist/vendor/core/calendar/views/mini-calendar.d.ts +8 -8
- package/dist/vendor/core/calendar/views/mini-calendar.js +1 -1
- package/dist/vendor/core/calendar/views/month-layout.d.ts +1 -1
- package/dist/vendor/core/calendar/views/month-layout.js +1 -1
- package/dist/vendor/core/calendar/views/time-grid-layout.js +1 -4
- package/dist/vendor/core/date/input/date-input-controller.d.ts +15 -15
- package/dist/vendor/core/date/input/date-input-controller.js +9 -21
- package/dist/vendor/core/date/input/date-range-input-controller.js +2 -5
- package/dist/vendor/core/date/input/parse.d.ts +2 -2
- package/dist/vendor/core/date/input/parse.js +3 -9
- package/dist/vendor/core/date/input/validity.js +1 -1
- package/dist/vendor/core/date/panel/panel-controller.d.ts +11 -11
- package/dist/vendor/core/date/panel/panel-controller.js +18 -40
- package/dist/vendor/core/date/presets.js +1 -2
- package/dist/vendor/core/date/selection/multiple.js +2 -5
- package/dist/vendor/core/date/selection/range.d.ts +2 -2
- package/dist/vendor/core/date/selection/range.js +2 -6
- package/dist/vendor/core/datetime/compose.d.ts +3 -3
- package/dist/vendor/core/datetime/constraints.d.ts +9 -9
- package/dist/vendor/core/datetime/input/datetime-input-controller.d.ts +2 -2
- package/dist/vendor/core/datetime/input/datetime-input-controller.js +12 -27
- package/dist/vendor/core/datetime/input/datetime-range-input-controller.js +5 -16
- package/dist/vendor/core/datetime/input/parse.d.ts +2 -2
- package/dist/vendor/core/datetime/input/parse.js +2 -5
- package/dist/vendor/core/datetime/panel/controller.js +4 -10
- package/dist/vendor/core/datetime/panel/range-controller.js +4 -16
- package/dist/vendor/core/datetime/zone/day-instants.js +1 -3
- package/dist/vendor/core/datetime/zone/resolve.js +2 -4
- package/dist/vendor/core/dom/auto-scroll.d.ts +37 -0
- package/dist/vendor/core/dom/auto-scroll.js +57 -0
- package/dist/vendor/core/dom/drag-session.d.ts +25 -0
- package/dist/vendor/core/dom/drag-session.js +257 -0
- package/dist/vendor/core/foundation/a11y/announcer.d.ts +9 -4
- package/dist/vendor/core/foundation/a11y/announcer.js +15 -27
- package/dist/vendor/core/foundation/a11y/grid-navigation.d.ts +2 -2
- package/dist/vendor/core/foundation/a11y/grid-navigation.js +2 -12
- package/dist/vendor/core/foundation/a11y/roving-focus.js +23 -2
- package/dist/vendor/core/foundation/constraints/availability-rules.js +2 -4
- package/dist/vendor/core/foundation/constraints/availability.d.ts +6 -6
- package/dist/vendor/core/foundation/constraints/availability.js +6 -16
- package/dist/vendor/core/foundation/constraints/date.d.ts +3 -3
- package/dist/vendor/core/foundation/constraints/index.d.ts +1 -1
- package/dist/vendor/core/foundation/constraints/range.d.ts +4 -4
- package/dist/vendor/core/foundation/constraints/range.js +1 -1
- package/dist/vendor/core/foundation/constraints/time.d.ts +5 -5
- package/dist/vendor/core/foundation/constraints/time.js +1 -1
- package/dist/vendor/core/foundation/grid/index.d.ts +2 -2
- package/dist/vendor/core/foundation/grid/month-grid.d.ts +2 -2
- package/dist/vendor/core/foundation/grid/time-axis.d.ts +3 -3
- package/dist/vendor/core/foundation/grid/time-axis.js +1 -1
- package/dist/vendor/core/foundation/input/index.d.ts +1 -1
- package/dist/vendor/core/foundation/input/index.js +1 -1
- package/dist/vendor/core/foundation/input/segment-engine.js +2 -6
- package/dist/vendor/core/foundation/locale/direction.js +1 -13
- package/dist/vendor/core/foundation/locale/format.js +1 -3
- package/dist/vendor/core/foundation/locale/hour-cycle.js +2 -6
- package/dist/vendor/core/foundation/locale/index.d.ts +1 -1
- package/dist/vendor/core/foundation/locale/index.js +1 -1
- package/dist/vendor/core/foundation/locale/resolve.js +12 -2
- package/dist/vendor/core/foundation/locale/week-info.js +1 -2
- package/dist/vendor/core/foundation/ranges/index.d.ts +1 -1
- package/dist/vendor/core/foundation/ranges/index.js +1 -1
- package/dist/vendor/core/foundation/ranges/interval.js +1 -3
- package/dist/vendor/core/foundation/store/controllable.d.ts +1 -1
- package/dist/vendor/core/foundation/store/ids.d.ts +8 -1
- package/dist/vendor/core/foundation/store/ids.js +10 -5
- package/dist/vendor/core/foundation/store/index.d.ts +2 -2
- package/dist/vendor/core/foundation/store/index.js +2 -2
- package/dist/vendor/core/foundation/store/with-optional.d.ts +15 -0
- package/dist/vendor/core/foundation/store/with-optional.js +3 -0
- package/dist/vendor/core/foundation/values/convert.js +3 -7
- package/dist/vendor/core/foundation/values/epoch-day.js +1 -5
- package/dist/vendor/core/foundation/values/index.d.ts +1 -1
- package/dist/vendor/core/foundation/values/index.js +1 -1
- package/dist/vendor/core/foundation/values/iso.js +2 -4
- package/dist/vendor/core/foundation/values/plain-time.js +1 -3
- package/dist/vendor/core/foundation/values/zoned.js +2 -5
- package/dist/vendor/core/time/input/parse.d.ts +1 -1
- package/dist/vendor/core/time/input/parse.js +1 -3
- package/dist/vendor/core/time/input/time-input-controller.d.ts +18 -18
- package/dist/vendor/core/time/input/time-input-controller.js +12 -27
- package/dist/vendor/core/time/input/time-range-input-controller.js +3 -10
- package/dist/vendor/core/time/input/validity.js +1 -1
- package/dist/vendor/core/time/panel/time-panel-controller.d.ts +12 -12
- package/dist/vendor/core/time/panel/time-panel-controller.js +19 -49
- package/dist/vendor/core/time/selection/range.d.ts +3 -3
- package/dist/vendor/core/time/selection/slots.d.ts +9 -9
- package/dist/vendor/core/time/selection/slots.js +1 -3
- package/package.json +21 -28
- package/dist/vendor/core/foundation/store/global-state.d.ts +0 -1
- package/dist/vendor/core/foundation/store/global-state.js +0 -21
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { backspace, compileAvailability, createControllable, createId, defaultMessages, emptySegment, filterDailyRules, fold, formatTime, getDayPeriodNames, getHiddenInputs, getHourCycle, getTextDirection, isSameTime, mergeMessages, nowZoned, plainTime, today as readTodayDate, resolveLocale, segmentOf, snapTime, stepSegment, toLatinDigits, toLocaleDigits, toPlainTime, typeDigit, } from "../../foundation/index.js";
|
|
2
|
-
import { parseTime
|
|
3
|
-
import { getTimeValidity, isTimeInvalid
|
|
2
|
+
import { parseTime } from "./parse.js";
|
|
3
|
+
import { getTimeValidity, isTimeInvalid } from "./validity.js";
|
|
4
|
+
import { withOptional } from "../../foundation/store/with-optional.js";
|
|
4
5
|
const sameNullable = (a, b) => a === b || (a !== null && b !== null && isSameTime(a, b));
|
|
5
6
|
/** Part order and separators from `Intl`, e.g. `hour : minute " " dayPeriod`. */
|
|
6
7
|
function layoutOf(locale, hourCycle, granularity) {
|
|
@@ -23,8 +24,7 @@ function layoutOf(locale, hourCycle, granularity) {
|
|
|
23
24
|
result.push({ type: "literal", text: part.value });
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
|
-
if (hourCycle === "h12" &&
|
|
27
|
-
!result.some((item) => item.type === "dayPeriod")) {
|
|
27
|
+
if (hourCycle === "h12" && !result.some((item) => item.type === "dayPeriod")) {
|
|
28
28
|
result.push({ type: "literal", text: " " }, { type: "dayPeriod", text: "" });
|
|
29
29
|
}
|
|
30
30
|
return result;
|
|
@@ -243,7 +243,7 @@ export function createTimeInputController(initial = {}) {
|
|
|
243
243
|
const pattern = segments
|
|
244
244
|
.map((item) => (item.type === "literal" ? item.text : item.placeholder))
|
|
245
245
|
.join("");
|
|
246
|
-
return {
|
|
246
|
+
return withOptional({
|
|
247
247
|
id,
|
|
248
248
|
mode: options.mode ?? "segmented",
|
|
249
249
|
segments,
|
|
@@ -268,7 +268,7 @@ export function createTimeInputController(initial = {}) {
|
|
|
268
268
|
: null,
|
|
269
269
|
],
|
|
270
270
|
]),
|
|
271
|
-
};
|
|
271
|
+
});
|
|
272
272
|
};
|
|
273
273
|
const refresh = () => {
|
|
274
274
|
const next = compute();
|
|
@@ -304,7 +304,7 @@ export function createTimeInputController(initial = {}) {
|
|
|
304
304
|
const names = getDayPeriodNames(localeOf());
|
|
305
305
|
const clean = (value) => fold(value).replace(/[.\s]/g, "");
|
|
306
306
|
const labels = [clean(names.am), clean(names.pm)];
|
|
307
|
-
const match = (buffer) => labels.flatMap((label, index) => label.startsWith(buffer) ? [index] : []);
|
|
307
|
+
const match = (buffer) => labels.flatMap((label, index) => (label.startsWith(buffer) ? [index] : []));
|
|
308
308
|
letters += clean(key);
|
|
309
309
|
let found = match(letters);
|
|
310
310
|
if (found.length === 0) {
|
|
@@ -378,16 +378,9 @@ export function createTimeInputController(initial = {}) {
|
|
|
378
378
|
return true;
|
|
379
379
|
}
|
|
380
380
|
const bounds = def(part);
|
|
381
|
-
if (key === "ArrowUp" ||
|
|
382
|
-
key === "ArrowDown" ||
|
|
383
|
-
key === "PageUp" ||
|
|
384
|
-
key === "PageDown") {
|
|
381
|
+
if (key === "ArrowUp" || key === "ArrowDown" || key === "PageUp" || key === "PageDown") {
|
|
385
382
|
const direction = key === "ArrowUp" || key === "PageUp" ? 1 : -1;
|
|
386
|
-
const amount = part === "dayPeriod"
|
|
387
|
-
? 1
|
|
388
|
-
: key.startsWith("Page")
|
|
389
|
-
? bounds.pageStep
|
|
390
|
-
: stepOf(part);
|
|
383
|
+
const amount = part === "dayPeriod" ? 1 : key.startsWith("Page") ? bounds.pageStep : stepOf(part);
|
|
391
384
|
const p = placeholder();
|
|
392
385
|
const start = part === "hour"
|
|
393
386
|
? hourCycle() === "h12"
|
|
@@ -410,9 +403,7 @@ export function createTimeInputController(initial = {}) {
|
|
|
410
403
|
return true;
|
|
411
404
|
}
|
|
412
405
|
if (key === "Backspace" || key === "Delete") {
|
|
413
|
-
setSegment(part, key === "Backspace" && part !== "dayPeriod"
|
|
414
|
-
? backspace(parts[part])
|
|
415
|
-
: emptySegment);
|
|
406
|
+
setSegment(part, key === "Backspace" && part !== "dayPeriod" ? backspace(parts[part]) : emptySegment);
|
|
416
407
|
afterEdit();
|
|
417
408
|
return true;
|
|
418
409
|
}
|
|
@@ -478,9 +469,7 @@ export function createTimeInputController(initial = {}) {
|
|
|
478
469
|
if (options.mode === "text")
|
|
479
470
|
controller.commitText();
|
|
480
471
|
const value = control.get();
|
|
481
|
-
if (value &&
|
|
482
|
-
state.validity === "valid" &&
|
|
483
|
-
!sameNullable(value, lastCommitted)) {
|
|
472
|
+
if (value && state.validity === "valid" && !sameNullable(value, lastCommitted)) {
|
|
484
473
|
lastCommitted = value;
|
|
485
474
|
options.onValueCommit?.(value);
|
|
486
475
|
}
|
|
@@ -527,11 +516,7 @@ export function createTimeInputController(initial = {}) {
|
|
|
527
516
|
"aria-disabled": state.disabled ? "true" : undefined,
|
|
528
517
|
"aria-required": state.required ? "true" : undefined,
|
|
529
518
|
"aria-invalid": isTimeInvalid(state.validity) ? "true" : undefined,
|
|
530
|
-
tabindex: state.disabled
|
|
531
|
-
? undefined
|
|
532
|
-
: segment.type === state.focusedPart
|
|
533
|
-
? 0
|
|
534
|
-
: -1,
|
|
519
|
+
tabindex: state.disabled ? undefined : segment.type === state.focusedPart ? 0 : -1,
|
|
535
520
|
inputmode: segment.type === "dayPeriod" ? "text" : "numeric",
|
|
536
521
|
"data-placeholder": segment.value === null,
|
|
537
522
|
"data-invalid": isTimeInvalid(state.validity),
|
|
@@ -3,8 +3,7 @@ import { checkTimeRangeValue, } from "../selection/range.js";
|
|
|
3
3
|
import { createTimeInputController, } from "./time-input-controller.js";
|
|
4
4
|
import { isTimeInvalid } from "./validity.js";
|
|
5
5
|
const same = (a, b) => a === b || (a !== null && b !== null && isSameTime(a, b));
|
|
6
|
-
const sameRange = (a, b) => a === b ||
|
|
7
|
-
(a !== null && b !== null && same(a.start, b.start) && same(a.end, b.end));
|
|
6
|
+
const sameRange = (a, b) => a === b || (a !== null && b !== null && same(a.start, b.start) && same(a.end, b.end));
|
|
8
7
|
const iso = (time, seconds) => time
|
|
9
8
|
? `${String(time.hour).padStart(2, "0")}:${String(time.minute).padStart(2, "0")}${seconds ? `:${String(time.second).padStart(2, "0")}` : ""}`
|
|
10
9
|
: null;
|
|
@@ -94,14 +93,8 @@ export function createTimeRangeInputController(initial = {}) {
|
|
|
94
93
|
disabled: start.disabled,
|
|
95
94
|
readOnly: start.readOnly,
|
|
96
95
|
hidden: getHiddenInputs([
|
|
97
|
-
[
|
|
98
|
-
|
|
99
|
-
iso(value?.start, seconds),
|
|
100
|
-
],
|
|
101
|
-
[
|
|
102
|
-
options.endName ?? (name ? `${name}-end` : undefined),
|
|
103
|
-
iso(value?.end, seconds),
|
|
104
|
-
],
|
|
96
|
+
[options.startName ?? (name ? `${name}-start` : undefined), iso(value?.start, seconds)],
|
|
97
|
+
[options.endName ?? (name ? `${name}-end` : undefined), iso(value?.end, seconds)],
|
|
105
98
|
]),
|
|
106
99
|
messages: start.messages,
|
|
107
100
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getTimeStatus
|
|
1
|
+
import { getTimeStatus } from "../../foundation/index.js";
|
|
2
2
|
/** `filled` is how many of the `required` parts hold a value. */
|
|
3
3
|
export function getTimeValidity(filled, required, time, constraints) {
|
|
4
4
|
if (filled === 0)
|
|
@@ -27,14 +27,14 @@ export type TimePanelBaseOptions = {
|
|
|
27
27
|
key: string;
|
|
28
28
|
label: string;
|
|
29
29
|
});
|
|
30
|
-
min?: TimeInput;
|
|
31
|
-
max?: TimeInput;
|
|
30
|
+
min?: TimeInput | undefined;
|
|
31
|
+
max?: TimeInput | undefined;
|
|
32
32
|
disabledRanges?: readonly {
|
|
33
33
|
start: TimeInput;
|
|
34
34
|
end: TimeInput;
|
|
35
35
|
}[];
|
|
36
|
-
isTimeDisabled?: (time: PlainTime) => boolean;
|
|
37
|
-
isTimeUnavailable?: (time: PlainTime) => boolean;
|
|
36
|
+
isTimeDisabled?: ((time: PlainTime) => boolean) | undefined;
|
|
37
|
+
isTimeUnavailable?: ((time: PlainTime) => boolean) | undefined;
|
|
38
38
|
/**
|
|
39
39
|
* Availability model (plan 11 V6, V8). Time-only components use `daily`
|
|
40
40
|
* rules only; other rule types are ignored with a development warning.
|
|
@@ -42,12 +42,12 @@ export type TimePanelBaseOptions = {
|
|
|
42
42
|
availability?: AvailabilitySpec | Availability;
|
|
43
43
|
scrollToSelected?: boolean;
|
|
44
44
|
autoFocus?: boolean;
|
|
45
|
-
readOnly?: boolean;
|
|
46
|
-
disabled?: boolean;
|
|
47
|
-
locale?: string;
|
|
48
|
-
timeZone?: string;
|
|
49
|
-
now?: number;
|
|
50
|
-
messages?: Partial<Messages
|
|
45
|
+
readOnly?: boolean | undefined;
|
|
46
|
+
disabled?: boolean | undefined;
|
|
47
|
+
locale?: string | undefined;
|
|
48
|
+
timeZone?: string | undefined;
|
|
49
|
+
now?: number | undefined;
|
|
50
|
+
messages?: Partial<Messages> | undefined;
|
|
51
51
|
/** Clock for type-ahead (milliseconds). Default `Date.now`. */
|
|
52
52
|
timer?: () => number;
|
|
53
53
|
};
|
|
@@ -58,9 +58,9 @@ export type TimePanelOptions = TimePanelBaseOptions & {
|
|
|
58
58
|
onValueChange?: (value: TimeValue, info: {
|
|
59
59
|
slot?: BookingSlot;
|
|
60
60
|
}) => void;
|
|
61
|
-
onValueCommit?: (value: PlainTime, info: {
|
|
61
|
+
onValueCommit?: ((value: PlainTime, info: {
|
|
62
62
|
slot?: BookingSlot;
|
|
63
|
-
}) => void;
|
|
63
|
+
}) => void) | undefined;
|
|
64
64
|
};
|
|
65
65
|
export type TimeRangePanelOptions = TimePanelBaseOptions & {
|
|
66
66
|
layout?: "list" | "columns";
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { compileAvailability, createControllable, createId, defaultMessages, filterDailyRules, formatTime, fromSecondOfDay, getDayPeriodLabel, getDayPeriodNames, getHourCycle, getTextDirection, getTimeStatus, isSameTime, mergeMessages, nowZoned, plainTime, today as readTodayDate, resolveLocale, toLatinDigits, toPlainTime, toSecondOfDay, } from "../../foundation/index.js";
|
|
2
2
|
import { checkTimeRangeValue, } from "../selection/range.js";
|
|
3
3
|
import { getBookingSlots, timeKey, } from "../selection/slots.js";
|
|
4
|
+
import { withOptional } from "../../foundation/store/with-optional.js";
|
|
4
5
|
const DAY = 86400;
|
|
5
6
|
const EMPTY = { hour: null, minute: null, second: null, period: null };
|
|
6
7
|
const sameT = (a, b) => a === b || (a !== null && b !== null && isSameTime(a, b));
|
|
7
|
-
const sameR = (a, b) => a === b ||
|
|
8
|
-
(a !== null && b !== null && sameT(a.start, b.start) && sameT(a.end, b.end));
|
|
8
|
+
const sameR = (a, b) => a === b || (a !== null && b !== null && sameT(a.start, b.start) && sameT(a.end, b.end));
|
|
9
9
|
function createPanel(kind, initial) {
|
|
10
10
|
let options = initial;
|
|
11
11
|
const id = options.id ?? createId("chrono-time-panel");
|
|
@@ -40,9 +40,7 @@ function createPanel(kind, initial) {
|
|
|
40
40
|
const unavailableAt = (time) => {
|
|
41
41
|
const availability = availabilityOf();
|
|
42
42
|
return ((options.isTimeUnavailable?.(time) ?? false) ||
|
|
43
|
-
(availability
|
|
44
|
-
? !availability.isTimeAvailable(referenceDate(), time)
|
|
45
|
-
: false));
|
|
43
|
+
(availability ? !availability.isTimeAvailable(referenceDate(), time) : false));
|
|
46
44
|
};
|
|
47
45
|
const selectable = (time) => getTimeStatus(time, constraints()).selectable && !unavailableAt(time);
|
|
48
46
|
const limits = () => ({
|
|
@@ -112,12 +110,8 @@ function createPanel(kind, initial) {
|
|
|
112
110
|
}));
|
|
113
111
|
}
|
|
114
112
|
else {
|
|
115
|
-
const first = options.start === undefined
|
|
116
|
-
|
|
117
|
-
: toSecondOfDay(toPlainTime(options.start));
|
|
118
|
-
const last = options.end === undefined
|
|
119
|
-
? DAY
|
|
120
|
-
: toSecondOfDay(toPlainTime(options.end)) || DAY;
|
|
113
|
+
const first = options.start === undefined ? 0 : toSecondOfDay(toPlainTime(options.start));
|
|
114
|
+
const last = options.end === undefined ? DAY : toSecondOfDay(toPlainTime(options.end)) || DAY;
|
|
121
115
|
list = [];
|
|
122
116
|
for (let at = first; at < last; at += stepSeconds) {
|
|
123
117
|
const time = fromSecondOfDay(at);
|
|
@@ -161,9 +155,7 @@ function createPanel(kind, initial) {
|
|
|
161
155
|
: EMPTY;
|
|
162
156
|
const toTime = (p) => {
|
|
163
157
|
const need = requiredParts();
|
|
164
|
-
const has = (part) => part === "dayPeriod"
|
|
165
|
-
? p.period !== null
|
|
166
|
-
: p[part] !== null;
|
|
158
|
+
const has = (part) => part === "dayPeriod" ? p.period !== null : p[part] !== null;
|
|
167
159
|
if (!need.every(has))
|
|
168
160
|
return null;
|
|
169
161
|
return plainTime(to24(p.hour, p.period), gran() === "hour" ? 0 : p.minute, gran() === "second" ? p.second : 0);
|
|
@@ -239,9 +231,7 @@ function createPanel(kind, initial) {
|
|
|
239
231
|
};
|
|
240
232
|
const mark = (hours, minutes, seconds) => {
|
|
241
233
|
const free = anyOk(hours, minutes, seconds, ok);
|
|
242
|
-
const blocked = isEnd && start
|
|
243
|
-
? !anyOk(hours, minutes, seconds, (t) => rangeOk(t))
|
|
244
|
-
: false;
|
|
234
|
+
const blocked = isEnd && start ? !anyOk(hours, minutes, seconds, (t) => rangeOk(t)) : false;
|
|
245
235
|
return { disabled: !free && !isEnd, blocked };
|
|
246
236
|
};
|
|
247
237
|
const columns = [];
|
|
@@ -304,9 +294,7 @@ function createPanel(kind, initial) {
|
|
|
304
294
|
const locale = localeOf();
|
|
305
295
|
const messages = mergeMessages(defaultMessages, options.messages);
|
|
306
296
|
const value = control.get();
|
|
307
|
-
const draft = range &&
|
|
308
|
-
value?.start != null &&
|
|
309
|
-
value?.end == null;
|
|
297
|
+
const draft = range && value?.start != null && value?.end == null;
|
|
310
298
|
const rv = range ? value : null;
|
|
311
299
|
const lay = layout();
|
|
312
300
|
let sets = [];
|
|
@@ -324,11 +312,7 @@ function createPanel(kind, initial) {
|
|
|
324
312
|
if (lay === "columns") {
|
|
325
313
|
sets = (range ? ["start", "end"] : ["value"]).map((key) => ({
|
|
326
314
|
key,
|
|
327
|
-
label: key === "start"
|
|
328
|
-
? messages.startTime
|
|
329
|
-
: key === "end"
|
|
330
|
-
? messages.endTime
|
|
331
|
-
: messages.time,
|
|
315
|
+
label: key === "start" ? messages.startTime : key === "end" ? messages.endTime : messages.time,
|
|
332
316
|
columns: buildColumns(key, messages),
|
|
333
317
|
}));
|
|
334
318
|
if (!focusKey ||
|
|
@@ -355,9 +339,7 @@ function createPanel(kind, initial) {
|
|
|
355
339
|
})();
|
|
356
340
|
const target = hover ?? focusKey;
|
|
357
341
|
const startEntry = draft
|
|
358
|
-
? (draftStart ??
|
|
359
|
-
list.find((e) => e.key === timeKey(rv?.start)) ??
|
|
360
|
-
null)
|
|
342
|
+
? (draftStart ?? list.find((e) => e.key === timeKey(rv?.start)) ?? null)
|
|
361
343
|
: null;
|
|
362
344
|
const rangeFor = (a, b) => {
|
|
363
345
|
let from = a;
|
|
@@ -449,9 +431,7 @@ function createPanel(kind, initial) {
|
|
|
449
431
|
}
|
|
450
432
|
if (!focusKey || !flat.some((o) => o.key === focusKey)) {
|
|
451
433
|
focusKey =
|
|
452
|
-
(flat.find((o) => o.selected) ??
|
|
453
|
-
flat.find((o) => !o.unavailable) ??
|
|
454
|
-
flat[0])?.key ?? "";
|
|
434
|
+
(flat.find((o) => o.selected) ?? flat.find((o) => !o.unavailable) ?? flat[0])?.key ?? "";
|
|
455
435
|
for (const o of flat)
|
|
456
436
|
o.focused = o.key === focusKey;
|
|
457
437
|
}
|
|
@@ -460,11 +440,9 @@ function createPanel(kind, initial) {
|
|
|
460
440
|
if (!end)
|
|
461
441
|
return false;
|
|
462
442
|
const endSecond = toSecondOfDay(end);
|
|
463
|
-
return e.slot
|
|
464
|
-
? e.endSecond % DAY === endSecond
|
|
465
|
-
: e.startSecond === endSecond;
|
|
443
|
+
return e.slot ? e.endSecond % DAY === endSecond : e.startSecond === endSecond;
|
|
466
444
|
}
|
|
467
|
-
return {
|
|
445
|
+
return withOptional({
|
|
468
446
|
id,
|
|
469
447
|
kind,
|
|
470
448
|
layout: lay,
|
|
@@ -483,7 +461,7 @@ function createPanel(kind, initial) {
|
|
|
483
461
|
direction: getTextDirection(locale),
|
|
484
462
|
locale,
|
|
485
463
|
messages,
|
|
486
|
-
};
|
|
464
|
+
});
|
|
487
465
|
};
|
|
488
466
|
const refresh = () => {
|
|
489
467
|
const next = compute();
|
|
@@ -491,9 +469,7 @@ function createPanel(kind, initial) {
|
|
|
491
469
|
return;
|
|
492
470
|
state = next;
|
|
493
471
|
if (range) {
|
|
494
|
-
const key = next.preview
|
|
495
|
-
? `${timeKey(next.preview.start)}|${timeKey(next.preview.end)}`
|
|
496
|
-
: "";
|
|
472
|
+
const key = next.preview ? `${timeKey(next.preview.start)}|${timeKey(next.preview.end)}` : "";
|
|
497
473
|
if (key !== lastPreview) {
|
|
498
474
|
lastPreview = key;
|
|
499
475
|
options.onRangePreviewChange?.(next.preview);
|
|
@@ -598,9 +574,7 @@ function createPanel(kind, initial) {
|
|
|
598
574
|
setValue({ start: entry.time, end: null });
|
|
599
575
|
return;
|
|
600
576
|
}
|
|
601
|
-
const first = draftStart ??
|
|
602
|
-
list.find((e) => e.key === timeKey(current.start)) ??
|
|
603
|
-
entry;
|
|
577
|
+
const first = draftStart ?? list.find((e) => e.key === timeKey(current.start)) ?? entry;
|
|
604
578
|
let from = first;
|
|
605
579
|
let to = entry;
|
|
606
580
|
if (to.startSecond < from.startSecond && !options.allowOvernight)
|
|
@@ -721,16 +695,14 @@ function createPanel(kind, initial) {
|
|
|
721
695
|
const scope = state.layout === "columns"
|
|
722
696
|
? (state.sets
|
|
723
697
|
.flatMap((s) => s.columns)
|
|
724
|
-
.find((c) => c.options.some((o) => o.key === focusKey))
|
|
725
|
-
?.options ?? all)
|
|
698
|
+
.find((c) => c.options.some((o) => o.key === focusKey))?.options ?? all)
|
|
726
699
|
: all;
|
|
727
700
|
const found = scope.find((o) => norm(o.text).startsWith(norm(typeBuffer)));
|
|
728
701
|
return move(found?.key);
|
|
729
702
|
}
|
|
730
703
|
if (state.layout === "list") {
|
|
731
704
|
const perHour = Math.max(1, Math.round(3600 /
|
|
732
|
-
((options.step?.minutes ?? 0) * 60 +
|
|
733
|
-
(options.step?.seconds ?? 0) ||
|
|
705
|
+
((options.step?.minutes ?? 0) * 60 + (options.step?.seconds ?? 0) ||
|
|
734
706
|
(options.slotDuration
|
|
735
707
|
? (options.step?.minutes ?? options.slotDuration) * 60
|
|
736
708
|
: 1800))));
|
|
@@ -812,9 +784,7 @@ function createPanel(kind, initial) {
|
|
|
812
784
|
: option.disabled || option.unavailable
|
|
813
785
|
? undefined
|
|
814
786
|
: "false",
|
|
815
|
-
"aria-disabled": option.disabled || option.unavailable || option.blocked
|
|
816
|
-
? "true"
|
|
817
|
-
: undefined,
|
|
787
|
+
"aria-disabled": option.disabled || option.unavailable || option.blocked ? "true" : undefined,
|
|
818
788
|
"aria-label": option.label,
|
|
819
789
|
tabindex: option.focused ? 0 : -1,
|
|
820
790
|
"data-chrono-key": option.key,
|
|
@@ -2,10 +2,10 @@ import { type PlainTime, type TimeConstraints } from "../../foundation/index.js"
|
|
|
2
2
|
export type TimeRangeLimits = TimeConstraints & {
|
|
3
3
|
isTimeUnavailable?: (time: PlainTime) => boolean;
|
|
4
4
|
/** `end <= start` means the next day (a range of 24 h or more cannot be represented). */
|
|
5
|
-
allowOvernight?: boolean;
|
|
5
|
+
allowOvernight?: boolean | undefined;
|
|
6
6
|
/** Minutes. */
|
|
7
|
-
minDuration?: number;
|
|
8
|
-
maxDuration?: number;
|
|
7
|
+
minDuration?: number | undefined;
|
|
8
|
+
maxDuration?: number | undefined;
|
|
9
9
|
};
|
|
10
10
|
export type TimeRangeInvalidReason = "start-invalid" | "end-before-start" | "too-short" | "too-long";
|
|
11
11
|
export type TimeRangeValueCheck = {
|
|
@@ -19,21 +19,21 @@ export type BookingSlot = {
|
|
|
19
19
|
data?: unknown;
|
|
20
20
|
};
|
|
21
21
|
export type SlotOptions = {
|
|
22
|
-
start?: TimeInput;
|
|
22
|
+
start?: TimeInput | undefined;
|
|
23
23
|
/** Exclusive; omit for the end of the day. */
|
|
24
|
-
end?: TimeInput;
|
|
24
|
+
end?: TimeInput | undefined;
|
|
25
25
|
/** Minutes. */
|
|
26
|
-
slotDuration?: number;
|
|
26
|
+
slotDuration?: number | undefined;
|
|
27
27
|
/** Minutes between slot starts (default `slotDuration`). */
|
|
28
|
-
step?: number;
|
|
29
|
-
slots?: readonly BookingSlotInput[];
|
|
30
|
-
min?: TimeInput;
|
|
31
|
-
max?: TimeInput;
|
|
28
|
+
step?: number | undefined;
|
|
29
|
+
slots?: readonly BookingSlotInput[] | undefined;
|
|
30
|
+
min?: TimeInput | undefined;
|
|
31
|
+
max?: TimeInput | undefined;
|
|
32
32
|
disabledRanges?: readonly {
|
|
33
33
|
start: TimeInput;
|
|
34
34
|
end: TimeInput;
|
|
35
|
-
}[];
|
|
36
|
-
isTimeDisabled?: (time: PlainTime) => boolean;
|
|
35
|
+
}[] | undefined;
|
|
36
|
+
isTimeDisabled?: ((time: PlainTime) => boolean) | undefined;
|
|
37
37
|
isTimeUnavailable?: (time: PlainTime) => boolean;
|
|
38
38
|
};
|
|
39
39
|
export declare function timeKey(time: PlainTime): string;
|
|
@@ -66,9 +66,7 @@ export function getBookingSlots(options = {}) {
|
|
|
66
66
|
if (duration <= 0)
|
|
67
67
|
return [];
|
|
68
68
|
const first = options.start === undefined ? 0 : toSecondOfDay(toPlainTime(options.start));
|
|
69
|
-
const last = options.end === undefined
|
|
70
|
-
? DAY
|
|
71
|
-
: toSecondOfDay(toPlainTime(options.end)) || DAY;
|
|
69
|
+
const last = options.end === undefined ? DAY : toSecondOfDay(toPlainTime(options.end)) || DAY;
|
|
72
70
|
const stride = (options.step ?? options.slotDuration ?? 0) * 60 || duration;
|
|
73
71
|
const slots = [];
|
|
74
72
|
for (let at = first; at + duration <= last; at += stride) {
|
package/package.json
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zealakit/chrono-react",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.2",
|
|
4
4
|
"description": "Headless Calendar, Date, Time and DateTime components for React.",
|
|
5
5
|
"keywords": [
|
|
6
|
+
"calendar",
|
|
6
7
|
"chrono",
|
|
7
8
|
"date",
|
|
8
|
-
"time",
|
|
9
9
|
"datetime",
|
|
10
|
-
"calendar",
|
|
11
10
|
"headless",
|
|
12
|
-
"zealakit",
|
|
13
11
|
"react",
|
|
12
|
+
"react-component",
|
|
14
13
|
"react-hook",
|
|
15
|
-
"
|
|
14
|
+
"time",
|
|
15
|
+
"zealakit"
|
|
16
16
|
],
|
|
17
|
-
"
|
|
17
|
+
"homepage": "https://github.com/zealakit/chrono#readme",
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/zealakit/chrono/issues"
|
|
20
|
+
},
|
|
18
21
|
"license": "MIT",
|
|
22
|
+
"author": "nqhed - Huy Ed. Nguyen",
|
|
19
23
|
"repository": {
|
|
20
24
|
"type": "git",
|
|
21
25
|
"url": "git+https://github.com/zealakit/chrono.git",
|
|
22
26
|
"directory": "packages/react"
|
|
23
27
|
},
|
|
24
|
-
"homepage": "https://github.com/zealakit/chrono#readme",
|
|
25
|
-
"bugs": {
|
|
26
|
-
"url": "https://github.com/zealakit/chrono/issues"
|
|
27
|
-
},
|
|
28
|
-
"type": "module",
|
|
29
|
-
"engines": {
|
|
30
|
-
"node": ">=20"
|
|
31
|
-
},
|
|
32
|
-
"sideEffects": false,
|
|
33
28
|
"files": [
|
|
34
29
|
"dist",
|
|
35
30
|
"README.md",
|
|
36
31
|
"LICENSE"
|
|
37
32
|
],
|
|
33
|
+
"type": "module",
|
|
34
|
+
"sideEffects": false,
|
|
35
|
+
"main": "./dist/index.js",
|
|
36
|
+
"module": "./dist/index.js",
|
|
37
|
+
"types": "./dist/index.d.ts",
|
|
38
38
|
"exports": {
|
|
39
39
|
".": {
|
|
40
40
|
"types": "./dist/index.d.ts",
|
|
@@ -63,23 +63,16 @@
|
|
|
63
63
|
},
|
|
64
64
|
"./package.json": "./package.json"
|
|
65
65
|
},
|
|
66
|
+
"publishConfig": {
|
|
67
|
+
"access": "public"
|
|
68
|
+
},
|
|
66
69
|
"peerDependencies": {
|
|
70
|
+
"@zealakit/ui-engine": "1.0.0-beta.1",
|
|
67
71
|
"react": "^18.0.0 || ^19.0.0",
|
|
68
72
|
"react-dom": "^18.0.0 || ^19.0.0"
|
|
69
73
|
},
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
"@types/react": "^19.3.0",
|
|
73
|
-
"@types/react-dom": "^19.3.0",
|
|
74
|
-
"happy-dom": "^21.0.4",
|
|
75
|
-
"react": "^19.3.1",
|
|
76
|
-
"react-dom": "^19.3.1"
|
|
77
|
-
},
|
|
78
|
-
"main": "./dist/index.js",
|
|
79
|
-
"module": "./dist/index.js",
|
|
80
|
-
"types": "./dist/index.d.ts",
|
|
81
|
-
"publishConfig": {
|
|
82
|
-
"access": "public"
|
|
74
|
+
"engines": {
|
|
75
|
+
"node": ">=20"
|
|
83
76
|
},
|
|
84
77
|
"scripts": {
|
|
85
78
|
"build": "rm -rf dist && tsc -p tsconfig.json",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function getGlobalState<T>(name: string, create: () => T): T;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* State shared by every copy of Core loaded on a page.
|
|
3
|
-
*
|
|
4
|
-
* Each adapter ships its own bundled copy of Core, so module-level variables
|
|
5
|
-
* would split per adapter. State that must stay page-global lives on
|
|
6
|
-
* `globalThis` under a versioned `Symbol.for` key. Bump the version when a
|
|
7
|
-
* stored shape changes so incompatible copies never read each other's state.
|
|
8
|
-
*
|
|
9
|
-
* SSR-safe: only `globalThis` is touched, and state is created lazily.
|
|
10
|
-
*/
|
|
11
|
-
const STATE_VERSION = 1;
|
|
12
|
-
export function getGlobalState(name, create) {
|
|
13
|
-
const key = Symbol.for(`@zealakit/chrono-core/v${STATE_VERSION}/${name}`);
|
|
14
|
-
const store = globalThis;
|
|
15
|
-
let value = store[key];
|
|
16
|
-
if (value === undefined) {
|
|
17
|
-
value = create();
|
|
18
|
-
store[key] = value;
|
|
19
|
-
}
|
|
20
|
-
return value;
|
|
21
|
-
}
|