@carbon/utilities 0.25.0-rc.0 → 0.25.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.
- package/es/date-picker/index.d.ts +12 -49
- package/es/date-picker/index.js +2 -59
- package/lib/date-picker/index.js +28 -59
- package/package.json +7 -4
|
@@ -147,7 +147,14 @@ declare global {
|
|
|
147
147
|
}): PlainYearMonth;
|
|
148
148
|
compare(one: PlainYearMonth, two: PlainYearMonth): number;
|
|
149
149
|
}
|
|
150
|
-
|
|
150
|
+
/**
|
|
151
|
+
* Usages of `var` and `namespace`, instead of const, are intentional. TS 6
|
|
152
|
+
* ships built-in types for the Temporal API in `lib.esnext.temporal.d.ts`
|
|
153
|
+
* using these forms. Declaration merging only works when the shapes match.
|
|
154
|
+
* Matching them prevents collisions and tsc errors for TS 6 consumers,
|
|
155
|
+
* and for TS 5 consumers nothing changes, they still get these types
|
|
156
|
+
*/
|
|
157
|
+
var PlainYearMonth: PlainYearMonthConstructor;
|
|
151
158
|
interface PlainDateConstructor {
|
|
152
159
|
from(item: string | {
|
|
153
160
|
year: number;
|
|
@@ -156,11 +163,10 @@ declare global {
|
|
|
156
163
|
}): PlainDate;
|
|
157
164
|
compare(one: PlainDate, two: PlainDate): number;
|
|
158
165
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
plainDateISO(): PlainDate;
|
|
166
|
+
var PlainDate: PlainDateConstructor;
|
|
167
|
+
namespace Now {
|
|
168
|
+
function plainDateISO(): PlainDate;
|
|
162
169
|
}
|
|
163
|
-
const Now: Now;
|
|
164
170
|
}
|
|
165
171
|
}
|
|
166
172
|
/**
|
|
@@ -946,48 +952,5 @@ declare function parseDateString(dateString: string, format: string): Temporal.P
|
|
|
946
952
|
* @returns True if Temporal API is available
|
|
947
953
|
*/
|
|
948
954
|
declare function isTemporalAvailable(): boolean;
|
|
949
|
-
/**
|
|
950
|
-
* Get a fallback date handler if Temporal is not available
|
|
951
|
-
* This provides a migration path for browsers without Temporal support
|
|
952
|
-
*/
|
|
953
|
-
declare function getDateHandler(): {
|
|
954
|
-
type: "temporal";
|
|
955
|
-
toISOString: typeof plainDateToISOString;
|
|
956
|
-
fromISOString: typeof parseISOToPlainDate;
|
|
957
|
-
compare: typeof comparePlainDates;
|
|
958
|
-
format: typeof formatPlainDate;
|
|
959
|
-
isInRange: typeof isDateInRange;
|
|
960
|
-
} | {
|
|
961
|
-
type: "date";
|
|
962
|
-
/**
|
|
963
|
-
*
|
|
964
|
-
* @param {Temporal.PlainDate} date - The date to convert
|
|
965
|
-
*/
|
|
966
|
-
toISOString: (date: Date) => string;
|
|
967
|
-
/**
|
|
968
|
-
*
|
|
969
|
-
* @param {string} str - The ISO string to parse
|
|
970
|
-
*/
|
|
971
|
-
fromISOString: (str: string) => Date | null;
|
|
972
|
-
/**
|
|
973
|
-
*
|
|
974
|
-
* @param {Temporal.PlainDate} d1 - First date
|
|
975
|
-
* @param {Temporal.PlainDate} d2 - Second date
|
|
976
|
-
*/
|
|
977
|
-
compare: (d1: Date, d2: Date) => number;
|
|
978
|
-
/**
|
|
979
|
-
*
|
|
980
|
-
* @param {Temporal.PlainDate} date - The date to format
|
|
981
|
-
* @param {string} format - The format string
|
|
982
|
-
*/
|
|
983
|
-
format: (date: Date, format: string) => string;
|
|
984
|
-
/**
|
|
985
|
-
*
|
|
986
|
-
* @param {Temporal.PlainDate} date - The date to check
|
|
987
|
-
* @param {Temporal.PlainDate | null} min - Minimum date
|
|
988
|
-
* @param {Temporal.PlainDate | null} max - Maximum date
|
|
989
|
-
*/
|
|
990
|
-
isInRange: (date: Date, min: Date | null, max: Date | null) => boolean;
|
|
991
|
-
};
|
|
992
955
|
//#endregion
|
|
993
|
-
export { type CalendarDay, type ClickOutsideConfig, ClickOutsideHandler, type DatePickerContext, DatePickerEvent, type DatePickerEvent$1 as DatePickerEventType, type DatePickerMode, DatePickerState, DatePickerStateMachine, type DateSelectPayload, type FocusRestoreTarget, type InputFocusPayload, type InputType, type KeyboardEventInfo, type KeyboardEventResult, type KeyboardPayload, type SideEffect, type StateAction, type StateConfig, type StateGuard, type StateTransition, type TransitionListener, type TransitionMap, type ValidationErrorPayload, type ValueChangePayload, actions, addDays, addMonths, areDatesEqual, checkGuard, comparePlainDates, dateToPlainDate, daysBetween, effects, executeAction, executeEffect, formatPlainDate, generateCalendarGrid, getAction,
|
|
956
|
+
export { type CalendarDay, type ClickOutsideConfig, ClickOutsideHandler, type DatePickerContext, DatePickerEvent, type DatePickerEvent$1 as DatePickerEventType, type DatePickerMode, DatePickerState, DatePickerStateMachine, type DateSelectPayload, type FocusRestoreTarget, type InputFocusPayload, type InputType, type KeyboardEventInfo, type KeyboardEventResult, type KeyboardPayload, type SideEffect, type StateAction, type StateConfig, type StateGuard, type StateTransition, type TransitionListener, type TransitionMap, type ValidationErrorPayload, type ValueChangePayload, actions, addDays, addMonths, areDatesEqual, checkGuard, comparePlainDates, dateToPlainDate, daysBetween, effects, executeAction, executeEffect, formatPlainDate, generateCalendarGrid, getAction, getEffect, getFullDateLabel, getGuard, getMonthEnd, getMonthStart, getMonthYearLabel, getToday, getWeekdayLabels, guards, isDateInRange, isFuture, isPast, isSingleMode, isTemporalAvailable, isToday, mapKeyboardToStateMachineEvent, parseDateString, parseDateToPlainDate, parseISOToPlainDate, plainDateToDate, plainDateToISOString };
|
package/es/date-picker/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import "temporal-polyfill/global";
|
|
1
2
|
//#region src/date-picker/primitives/states.ts
|
|
2
3
|
/**
|
|
3
4
|
* Copyright IBM Corp. 2026
|
|
@@ -357,64 +358,6 @@ function parseDateString(dateString, format) {
|
|
|
357
358
|
function isTemporalAvailable() {
|
|
358
359
|
return typeof Temporal !== "undefined" && typeof Temporal.PlainDate !== "undefined";
|
|
359
360
|
}
|
|
360
|
-
/**
|
|
361
|
-
* Get a fallback date handler if Temporal is not available
|
|
362
|
-
* This provides a migration path for browsers without Temporal support
|
|
363
|
-
*/
|
|
364
|
-
function getDateHandler() {
|
|
365
|
-
if (isTemporalAvailable()) return {
|
|
366
|
-
type: "temporal",
|
|
367
|
-
toISOString: plainDateToISOString,
|
|
368
|
-
fromISOString: parseISOToPlainDate,
|
|
369
|
-
compare: comparePlainDates,
|
|
370
|
-
format: formatPlainDate,
|
|
371
|
-
isInRange: isDateInRange
|
|
372
|
-
};
|
|
373
|
-
return {
|
|
374
|
-
type: "date",
|
|
375
|
-
/**
|
|
376
|
-
*
|
|
377
|
-
* @param {Temporal.PlainDate} date - The date to convert
|
|
378
|
-
*/
|
|
379
|
-
toISOString: (date) => date.toISOString().split("T")[0],
|
|
380
|
-
/**
|
|
381
|
-
*
|
|
382
|
-
* @param {string} str - The ISO string to parse
|
|
383
|
-
*/
|
|
384
|
-
fromISOString: (str) => {
|
|
385
|
-
const date = new Date(str);
|
|
386
|
-
return isNaN(date.getTime()) ? null : date;
|
|
387
|
-
},
|
|
388
|
-
/**
|
|
389
|
-
*
|
|
390
|
-
* @param {Temporal.PlainDate} d1 - First date
|
|
391
|
-
* @param {Temporal.PlainDate} d2 - Second date
|
|
392
|
-
*/
|
|
393
|
-
compare: (d1, d2) => d1.getTime() - d2.getTime(),
|
|
394
|
-
/**
|
|
395
|
-
*
|
|
396
|
-
* @param {Temporal.PlainDate} date - The date to format
|
|
397
|
-
* @param {string} format - The format string
|
|
398
|
-
*/
|
|
399
|
-
format: (date, format) => {
|
|
400
|
-
const year = date.getFullYear().toString();
|
|
401
|
-
const month = (date.getMonth() + 1).toString().padStart(2, "0");
|
|
402
|
-
const day = date.getDate().toString().padStart(2, "0");
|
|
403
|
-
return format.replace("Y", year).replace("m", month).replace("d", day);
|
|
404
|
-
},
|
|
405
|
-
/**
|
|
406
|
-
*
|
|
407
|
-
* @param {Temporal.PlainDate} date - The date to check
|
|
408
|
-
* @param {Temporal.PlainDate | null} min - Minimum date
|
|
409
|
-
* @param {Temporal.PlainDate | null} max - Maximum date
|
|
410
|
-
*/
|
|
411
|
-
isInRange: (date, min, max) => {
|
|
412
|
-
if (min && date < min) return false;
|
|
413
|
-
if (max && date > max) return false;
|
|
414
|
-
return true;
|
|
415
|
-
}
|
|
416
|
-
};
|
|
417
|
-
}
|
|
418
361
|
//#endregion
|
|
419
362
|
//#region src/date-picker/primitives/guards.ts
|
|
420
363
|
/**
|
|
@@ -2012,4 +1955,4 @@ function getWeekdayLabels(locale = "en", weekStartsOn = 0) {
|
|
|
2012
1955
|
return labels;
|
|
2013
1956
|
}
|
|
2014
1957
|
//#endregion
|
|
2015
|
-
export { ClickOutsideHandler, DatePickerEvent, DatePickerState, DatePickerStateMachine, actions, addDays, addMonths, areDatesEqual, checkGuard, comparePlainDates, dateToPlainDate, daysBetween, effects, executeAction, executeEffect, formatPlainDate, generateCalendarGrid, getAction,
|
|
1958
|
+
export { ClickOutsideHandler, DatePickerEvent, DatePickerState, DatePickerStateMachine, actions, addDays, addMonths, areDatesEqual, checkGuard, comparePlainDates, dateToPlainDate, daysBetween, effects, executeAction, executeEffect, formatPlainDate, generateCalendarGrid, getAction, getEffect, getFullDateLabel, getGuard, getMonthEnd, getMonthStart, getMonthYearLabel, getToday, getWeekdayLabels, guards, isDateInRange, isFuture, isPast, isSingleMode, isTemporalAvailable, isToday, mapKeyboardToStateMachineEvent, parseDateString, parseDateToPlainDate, parseISOToPlainDate, plainDateToDate, plainDateToISOString };
|
package/lib/date-picker/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
require("temporal-polyfill/global");
|
|
2
3
|
//#region src/date-picker/primitives/states.ts
|
|
3
4
|
/**
|
|
4
5
|
* Copyright IBM Corp. 2026
|
|
@@ -358,64 +359,6 @@ function parseDateString(dateString, format) {
|
|
|
358
359
|
function isTemporalAvailable() {
|
|
359
360
|
return typeof Temporal !== "undefined" && typeof Temporal.PlainDate !== "undefined";
|
|
360
361
|
}
|
|
361
|
-
/**
|
|
362
|
-
* Get a fallback date handler if Temporal is not available
|
|
363
|
-
* This provides a migration path for browsers without Temporal support
|
|
364
|
-
*/
|
|
365
|
-
function getDateHandler() {
|
|
366
|
-
if (isTemporalAvailable()) return {
|
|
367
|
-
type: "temporal",
|
|
368
|
-
toISOString: plainDateToISOString,
|
|
369
|
-
fromISOString: parseISOToPlainDate,
|
|
370
|
-
compare: comparePlainDates,
|
|
371
|
-
format: formatPlainDate,
|
|
372
|
-
isInRange: isDateInRange
|
|
373
|
-
};
|
|
374
|
-
return {
|
|
375
|
-
type: "date",
|
|
376
|
-
/**
|
|
377
|
-
*
|
|
378
|
-
* @param {Temporal.PlainDate} date - The date to convert
|
|
379
|
-
*/
|
|
380
|
-
toISOString: (date) => date.toISOString().split("T")[0],
|
|
381
|
-
/**
|
|
382
|
-
*
|
|
383
|
-
* @param {string} str - The ISO string to parse
|
|
384
|
-
*/
|
|
385
|
-
fromISOString: (str) => {
|
|
386
|
-
const date = new Date(str);
|
|
387
|
-
return isNaN(date.getTime()) ? null : date;
|
|
388
|
-
},
|
|
389
|
-
/**
|
|
390
|
-
*
|
|
391
|
-
* @param {Temporal.PlainDate} d1 - First date
|
|
392
|
-
* @param {Temporal.PlainDate} d2 - Second date
|
|
393
|
-
*/
|
|
394
|
-
compare: (d1, d2) => d1.getTime() - d2.getTime(),
|
|
395
|
-
/**
|
|
396
|
-
*
|
|
397
|
-
* @param {Temporal.PlainDate} date - The date to format
|
|
398
|
-
* @param {string} format - The format string
|
|
399
|
-
*/
|
|
400
|
-
format: (date, format) => {
|
|
401
|
-
const year = date.getFullYear().toString();
|
|
402
|
-
const month = (date.getMonth() + 1).toString().padStart(2, "0");
|
|
403
|
-
const day = date.getDate().toString().padStart(2, "0");
|
|
404
|
-
return format.replace("Y", year).replace("m", month).replace("d", day);
|
|
405
|
-
},
|
|
406
|
-
/**
|
|
407
|
-
*
|
|
408
|
-
* @param {Temporal.PlainDate} date - The date to check
|
|
409
|
-
* @param {Temporal.PlainDate | null} min - Minimum date
|
|
410
|
-
* @param {Temporal.PlainDate | null} max - Maximum date
|
|
411
|
-
*/
|
|
412
|
-
isInRange: (date, min, max) => {
|
|
413
|
-
if (min && date < min) return false;
|
|
414
|
-
if (max && date > max) return false;
|
|
415
|
-
return true;
|
|
416
|
-
}
|
|
417
|
-
};
|
|
418
|
-
}
|
|
419
362
|
//#endregion
|
|
420
363
|
//#region src/date-picker/primitives/guards.ts
|
|
421
364
|
/**
|
|
@@ -2013,6 +1956,33 @@ function getWeekdayLabels(locale = "en", weekStartsOn = 0) {
|
|
|
2013
1956
|
return labels;
|
|
2014
1957
|
}
|
|
2015
1958
|
//#endregion
|
|
1959
|
+
//#region src/date-picker/index.ts
|
|
1960
|
+
/**
|
|
1961
|
+
* Copyright IBM Corp. 2026
|
|
1962
|
+
*
|
|
1963
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
1964
|
+
* LICENSE file in the root directory of this source tree.
|
|
1965
|
+
*/
|
|
1966
|
+
/**
|
|
1967
|
+
* @internal
|
|
1968
|
+
* This module is for internal use by @carbon/react and @carbon/web-components only.
|
|
1969
|
+
* It is not part of the public @carbon/utilities API.
|
|
1970
|
+
*
|
|
1971
|
+
* Import from source path:
|
|
1972
|
+
* import { ... } from '@carbon/utilities/src/date-picker';
|
|
1973
|
+
*/
|
|
1974
|
+
/**
|
|
1975
|
+
* The primitives below are built on Temporal, which is still unevenly shipped:
|
|
1976
|
+
* no version of Safari implements it, and Chrome/Edge only gained it in 144.
|
|
1977
|
+
* Every `Temporal.*` reference in this module tree is a bare global, so on those engines
|
|
1978
|
+
* the first access — `Temporal.Now.plainDateISO()` on the calendar-open transition
|
|
1979
|
+
* throws a ReferenceError and the calendar never opens.
|
|
1980
|
+
|
|
1981
|
+
* `temporal-polyfill/global` installs `globalThis.Temporal` only when the engine
|
|
1982
|
+
* does not already provide it, so a native implementation always wins. It is
|
|
1983
|
+
* imported first so the global exists before any primitive can reach for it.
|
|
1984
|
+
*/
|
|
1985
|
+
//#endregion
|
|
2016
1986
|
exports.ClickOutsideHandler = ClickOutsideHandler;
|
|
2017
1987
|
exports.DatePickerEvent = DatePickerEvent;
|
|
2018
1988
|
exports.DatePickerState = DatePickerState;
|
|
@@ -2031,7 +2001,6 @@ exports.executeEffect = executeEffect;
|
|
|
2031
2001
|
exports.formatPlainDate = formatPlainDate;
|
|
2032
2002
|
exports.generateCalendarGrid = generateCalendarGrid;
|
|
2033
2003
|
exports.getAction = getAction;
|
|
2034
|
-
exports.getDateHandler = getDateHandler;
|
|
2035
2004
|
exports.getEffect = getEffect;
|
|
2036
2005
|
exports.getFullDateLabel = getFullDateLabel;
|
|
2037
2006
|
exports.getGuard = getGuard;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@carbon/utilities",
|
|
3
3
|
"description": "Utilities and helpers to drive consistency across software products using the Carbon Design System",
|
|
4
|
-
"version": "0.25.0
|
|
4
|
+
"version": "0.25.0",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"module": "es/index.js",
|
|
@@ -22,7 +22,9 @@
|
|
|
22
22
|
"sideEffects": [
|
|
23
23
|
"*.scss",
|
|
24
24
|
"./index.scss",
|
|
25
|
-
"./scss/**"
|
|
25
|
+
"./scss/**",
|
|
26
|
+
"./es/date-picker/index.js",
|
|
27
|
+
"./lib/date-picker/index.js"
|
|
26
28
|
],
|
|
27
29
|
"exports": {
|
|
28
30
|
".": {
|
|
@@ -64,7 +66,8 @@
|
|
|
64
66
|
},
|
|
65
67
|
"dependencies": {
|
|
66
68
|
"@ibm/telemetry-js": "^1.6.1",
|
|
67
|
-
"@internationalized/number": "^3.6.1"
|
|
69
|
+
"@internationalized/number": "^3.6.1",
|
|
70
|
+
"temporal-polyfill": "^1.0.4"
|
|
68
71
|
},
|
|
69
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "7518c84ffd00f22434fe19d83119692c12fccb2f"
|
|
70
73
|
}
|