@zag-js/date-utils 0.0.0-dev-20230107115230
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 +21 -0
- package/README.md +19 -0
- package/dist/align.d.ts +7 -0
- package/dist/align.js +105 -0
- package/dist/align.mjs +9 -0
- package/dist/assertion.d.ts +13 -0
- package/dist/assertion.js +77 -0
- package/dist/assertion.mjs +20 -0
- package/dist/chunk-2DZ3KIVJ.mjs +73 -0
- package/dist/chunk-6NI2PIAA.mjs +27 -0
- package/dist/chunk-6XKXGQP6.mjs +32 -0
- package/dist/chunk-7JERMWT3.mjs +46 -0
- package/dist/chunk-C4U2N3JC.mjs +65 -0
- package/dist/chunk-DI2YG6VG.mjs +24 -0
- package/dist/chunk-ECAENYV6.mjs +19 -0
- package/dist/chunk-EXWX3KZT.mjs +64 -0
- package/dist/chunk-FJMTHABG.mjs +8 -0
- package/dist/chunk-HP2COJGP.mjs +76 -0
- package/dist/chunk-M4F23P2U.mjs +35 -0
- package/dist/chunk-TCPXGBJP.mjs +33 -0
- package/dist/chunk-TTJVXKJY.mjs +12 -0
- package/dist/chunk-VWVBJ5CB.mjs +110 -0
- package/dist/chunk-XHAL6X5Z.mjs +27 -0
- package/dist/chunk-ZSLC7OI2.mjs +22 -0
- package/dist/constrain.d.ts +10 -0
- package/dist/constrain.js +97 -0
- package/dist/constrain.mjs +14 -0
- package/dist/duration.d.ts +11 -0
- package/dist/duration.js +47 -0
- package/dist/duration.mjs +8 -0
- package/dist/format-range.d.ts +6 -0
- package/dist/format-range.js +51 -0
- package/dist/format-range.mjs +6 -0
- package/dist/format-selected-date.d.ts +6 -0
- package/dist/format-selected-date.js +86 -0
- package/dist/format-selected-date.mjs +9 -0
- package/dist/format-visible-range.d.ts +6 -0
- package/dist/format-visible-range.js +102 -0
- package/dist/format-visible-range.mjs +30 -0
- package/dist/get-era-format.d.ts +5 -0
- package/dist/get-era-format.js +32 -0
- package/dist/get-era-format.mjs +6 -0
- package/dist/get-formatter.d.ts +7 -0
- package/dist/get-formatter.js +61 -0
- package/dist/get-formatter.mjs +9 -0
- package/dist/get-month-dates.d.ts +5 -0
- package/dist/get-month-dates.js +65 -0
- package/dist/get-month-dates.mjs +7 -0
- package/dist/get-week-dates.d.ts +7 -0
- package/dist/get-week-dates.js +60 -0
- package/dist/get-week-dates.mjs +8 -0
- package/dist/get-year-range.d.ts +7 -0
- package/dist/get-year-range.js +36 -0
- package/dist/get-year-range.mjs +6 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +656 -0
- package/dist/index.mjs +120 -0
- package/dist/mutation.d.ts +13 -0
- package/dist/mutation.js +120 -0
- package/dist/mutation.mjs +22 -0
- package/dist/pagination.d.ts +25 -0
- package/dist/pagination.js +193 -0
- package/dist/pagination.mjs +22 -0
- package/dist/placeholder.d.ts +7 -0
- package/dist/placeholder.js +47 -0
- package/dist/placeholder.mjs +21 -0
- package/dist/segment-constants.d.ts +2 -0
- package/dist/segment-constants.js +52 -0
- package/dist/segment-constants.mjs +8 -0
- package/dist/segment-limit.d.ts +14 -0
- package/dist/segment-limit.js +97 -0
- package/dist/segment-limit.mjs +6 -0
- package/dist/segment-mutation.d.ts +8 -0
- package/dist/segment-mutation.js +89 -0
- package/dist/segment-mutation.mjs +8 -0
- package/dist/segment-parts.d.ts +25 -0
- package/dist/segment-parts.js +143 -0
- package/dist/segment-parts.mjs +37 -0
- package/dist/types-9f60d2f1.d.ts +61 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.js +18 -0
- package/dist/types.mjs +0 -0
- package/package.json +53 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/segment-limit.ts
|
|
21
|
+
var segment_limit_exports = {};
|
|
22
|
+
__export(segment_limit_exports, {
|
|
23
|
+
getSegmentLimits: () => getSegmentLimits
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(segment_limit_exports);
|
|
26
|
+
var import_date = require("@internationalized/date");
|
|
27
|
+
function getSegmentLimits(date, type, options) {
|
|
28
|
+
switch (type) {
|
|
29
|
+
case "era": {
|
|
30
|
+
let eras = date.calendar.getEras();
|
|
31
|
+
return {
|
|
32
|
+
value: eras.indexOf(date.era),
|
|
33
|
+
min: 0,
|
|
34
|
+
max: eras.length - 1
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
case "year":
|
|
38
|
+
return {
|
|
39
|
+
value: date.year,
|
|
40
|
+
min: 1,
|
|
41
|
+
max: date.calendar.getYearsInEra(date)
|
|
42
|
+
};
|
|
43
|
+
case "month":
|
|
44
|
+
return {
|
|
45
|
+
value: date.month,
|
|
46
|
+
min: (0, import_date.getMinimumMonthInYear)(date),
|
|
47
|
+
max: date.calendar.getMonthsInYear(date)
|
|
48
|
+
};
|
|
49
|
+
case "day":
|
|
50
|
+
return {
|
|
51
|
+
value: date.day,
|
|
52
|
+
min: (0, import_date.getMinimumDayInMonth)(date),
|
|
53
|
+
max: date.calendar.getDaysInMonth(date)
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
if ("hour" in date) {
|
|
57
|
+
switch (type) {
|
|
58
|
+
case "dayPeriod":
|
|
59
|
+
return {
|
|
60
|
+
value: date.hour >= 12 ? 12 : 0,
|
|
61
|
+
min: 0,
|
|
62
|
+
max: 12
|
|
63
|
+
};
|
|
64
|
+
case "hour":
|
|
65
|
+
if (options.hour12) {
|
|
66
|
+
let isPM = date.hour >= 12;
|
|
67
|
+
return {
|
|
68
|
+
value: date.hour,
|
|
69
|
+
min: isPM ? 12 : 0,
|
|
70
|
+
max: isPM ? 23 : 11
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
value: date.hour,
|
|
75
|
+
min: 0,
|
|
76
|
+
max: 23
|
|
77
|
+
};
|
|
78
|
+
case "minute":
|
|
79
|
+
return {
|
|
80
|
+
value: date.minute,
|
|
81
|
+
min: 0,
|
|
82
|
+
max: 59
|
|
83
|
+
};
|
|
84
|
+
case "second":
|
|
85
|
+
return {
|
|
86
|
+
value: date.second,
|
|
87
|
+
min: 0,
|
|
88
|
+
max: 59
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return {};
|
|
93
|
+
}
|
|
94
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
95
|
+
0 && (module.exports = {
|
|
96
|
+
getSegmentLimits
|
|
97
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as _internationalized_date from '@internationalized/date';
|
|
2
|
+
import { DateValue } from '@internationalized/date';
|
|
3
|
+
import { e as DateSegmentPart, f as DateFormatOptions } from './types-9f60d2f1.js';
|
|
4
|
+
|
|
5
|
+
declare function addSegment(date: DateValue, part: DateSegmentPart, amount: number, options: DateFormatOptions): _internationalized_date.CalendarDate | _internationalized_date.CalendarDateTime | _internationalized_date.ZonedDateTime | undefined;
|
|
6
|
+
declare function setSegment(date: DateValue, part: DateSegmentPart, value: number, options: DateFormatOptions): _internationalized_date.CalendarDate | _internationalized_date.CalendarDateTime | _internationalized_date.ZonedDateTime | undefined;
|
|
7
|
+
|
|
8
|
+
export { addSegment, setSegment };
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/segment-mutation.ts
|
|
21
|
+
var segment_mutation_exports = {};
|
|
22
|
+
__export(segment_mutation_exports, {
|
|
23
|
+
addSegment: () => addSegment,
|
|
24
|
+
setSegment: () => setSegment
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(segment_mutation_exports);
|
|
27
|
+
function addSegment(date, part, amount, options) {
|
|
28
|
+
switch (part) {
|
|
29
|
+
case "era":
|
|
30
|
+
case "year":
|
|
31
|
+
case "month":
|
|
32
|
+
case "day":
|
|
33
|
+
return date.cycle(part, amount, { round: part === "year" });
|
|
34
|
+
}
|
|
35
|
+
if ("hour" in date) {
|
|
36
|
+
switch (part) {
|
|
37
|
+
case "dayPeriod": {
|
|
38
|
+
let hours = date.hour;
|
|
39
|
+
let isPM = hours >= 12;
|
|
40
|
+
return date.set({ hour: isPM ? hours - 12 : hours + 12 });
|
|
41
|
+
}
|
|
42
|
+
case "hour":
|
|
43
|
+
case "minute":
|
|
44
|
+
case "second":
|
|
45
|
+
return date.cycle(part, amount, {
|
|
46
|
+
round: part !== "hour",
|
|
47
|
+
hourCycle: options.hour12 ? 12 : 24
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function setSegment(date, part, value, options) {
|
|
53
|
+
switch (part) {
|
|
54
|
+
case "day":
|
|
55
|
+
case "month":
|
|
56
|
+
case "year":
|
|
57
|
+
case "era":
|
|
58
|
+
return date.set({ [part]: value });
|
|
59
|
+
}
|
|
60
|
+
if ("hour" in date) {
|
|
61
|
+
switch (part) {
|
|
62
|
+
case "dayPeriod": {
|
|
63
|
+
let hours = date.hour;
|
|
64
|
+
let wasPM = hours >= 12;
|
|
65
|
+
let isPM = value >= 12;
|
|
66
|
+
return isPM === wasPM ? date : date.set({ hour: wasPM ? hours - 12 : hours + 12 });
|
|
67
|
+
}
|
|
68
|
+
case "hour":
|
|
69
|
+
if (options.hour12) {
|
|
70
|
+
let hours = date.hour;
|
|
71
|
+
let wasPM = hours >= 12;
|
|
72
|
+
if (!wasPM && value === 12) {
|
|
73
|
+
value = 0;
|
|
74
|
+
}
|
|
75
|
+
if (wasPM && value < 12) {
|
|
76
|
+
value += 12;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
case "minute":
|
|
80
|
+
case "second":
|
|
81
|
+
return date.set({ [part]: value });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
86
|
+
0 && (module.exports = {
|
|
87
|
+
addSegment,
|
|
88
|
+
setSegment
|
|
89
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { DateValue, DateFormatter } from '@internationalized/date';
|
|
2
|
+
import { g as DateSegmentContext } from './types-9f60d2f1.js';
|
|
3
|
+
|
|
4
|
+
declare function getAllSegments(segments: Intl.DateTimeFormatPart[]): {};
|
|
5
|
+
declare function getSegments(ctx: DateSegmentContext, date: DateValue, formatter: DateFormatter): ({
|
|
6
|
+
isPlaceholder: boolean;
|
|
7
|
+
placeholder: any;
|
|
8
|
+
isEditable: boolean;
|
|
9
|
+
value: number;
|
|
10
|
+
min: number;
|
|
11
|
+
max: number;
|
|
12
|
+
type: keyof Intl.DateTimeFormatPartTypesRegistry;
|
|
13
|
+
text: any;
|
|
14
|
+
} | {
|
|
15
|
+
isPlaceholder: boolean;
|
|
16
|
+
placeholder: any;
|
|
17
|
+
isEditable: boolean;
|
|
18
|
+
value?: undefined;
|
|
19
|
+
min?: undefined;
|
|
20
|
+
max?: undefined;
|
|
21
|
+
type: keyof Intl.DateTimeFormatPartTypesRegistry;
|
|
22
|
+
text: any;
|
|
23
|
+
})[];
|
|
24
|
+
|
|
25
|
+
export { getAllSegments, getSegments };
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/segment-parts.ts
|
|
21
|
+
var segment_parts_exports = {};
|
|
22
|
+
__export(segment_parts_exports, {
|
|
23
|
+
getAllSegments: () => getAllSegments,
|
|
24
|
+
getSegments: () => getSegments
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(segment_parts_exports);
|
|
27
|
+
|
|
28
|
+
// src/segment-constants.ts
|
|
29
|
+
var EDITABLE_SEGMENTS = {
|
|
30
|
+
year: true,
|
|
31
|
+
month: true,
|
|
32
|
+
day: true,
|
|
33
|
+
hour: true,
|
|
34
|
+
minute: true,
|
|
35
|
+
second: true,
|
|
36
|
+
dayPeriod: true,
|
|
37
|
+
era: true
|
|
38
|
+
};
|
|
39
|
+
function isSegmentEditable(segment) {
|
|
40
|
+
return EDITABLE_SEGMENTS[segment];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// src/segment-limit.ts
|
|
44
|
+
var import_date = require("@internationalized/date");
|
|
45
|
+
function getSegmentLimits(date, type, options) {
|
|
46
|
+
switch (type) {
|
|
47
|
+
case "era": {
|
|
48
|
+
let eras = date.calendar.getEras();
|
|
49
|
+
return {
|
|
50
|
+
value: eras.indexOf(date.era),
|
|
51
|
+
min: 0,
|
|
52
|
+
max: eras.length - 1
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
case "year":
|
|
56
|
+
return {
|
|
57
|
+
value: date.year,
|
|
58
|
+
min: 1,
|
|
59
|
+
max: date.calendar.getYearsInEra(date)
|
|
60
|
+
};
|
|
61
|
+
case "month":
|
|
62
|
+
return {
|
|
63
|
+
value: date.month,
|
|
64
|
+
min: (0, import_date.getMinimumMonthInYear)(date),
|
|
65
|
+
max: date.calendar.getMonthsInYear(date)
|
|
66
|
+
};
|
|
67
|
+
case "day":
|
|
68
|
+
return {
|
|
69
|
+
value: date.day,
|
|
70
|
+
min: (0, import_date.getMinimumDayInMonth)(date),
|
|
71
|
+
max: date.calendar.getDaysInMonth(date)
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
if ("hour" in date) {
|
|
75
|
+
switch (type) {
|
|
76
|
+
case "dayPeriod":
|
|
77
|
+
return {
|
|
78
|
+
value: date.hour >= 12 ? 12 : 0,
|
|
79
|
+
min: 0,
|
|
80
|
+
max: 12
|
|
81
|
+
};
|
|
82
|
+
case "hour":
|
|
83
|
+
if (options.hour12) {
|
|
84
|
+
let isPM = date.hour >= 12;
|
|
85
|
+
return {
|
|
86
|
+
value: date.hour,
|
|
87
|
+
min: isPM ? 12 : 0,
|
|
88
|
+
max: isPM ? 23 : 11
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
value: date.hour,
|
|
93
|
+
min: 0,
|
|
94
|
+
max: 23
|
|
95
|
+
};
|
|
96
|
+
case "minute":
|
|
97
|
+
return {
|
|
98
|
+
value: date.minute,
|
|
99
|
+
min: 0,
|
|
100
|
+
max: 59
|
|
101
|
+
};
|
|
102
|
+
case "second":
|
|
103
|
+
return {
|
|
104
|
+
value: date.second,
|
|
105
|
+
min: 0,
|
|
106
|
+
max: 59
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return {};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// src/segment-parts.ts
|
|
114
|
+
function getAllSegments(segments) {
|
|
115
|
+
return segments.filter((segment) => isSegmentEditable(segment.type)).reduce((acc, segment) => (acc[segment.type] = true, acc), {});
|
|
116
|
+
}
|
|
117
|
+
function getPlaceholder(params) {
|
|
118
|
+
const placeholder = { day: "dd", month: "mm", year: "yyyy" };
|
|
119
|
+
return placeholder[params.field];
|
|
120
|
+
}
|
|
121
|
+
function getSegments(ctx, date, formatter) {
|
|
122
|
+
const segments = formatter.formatToParts(date.toDate(ctx.timeZone));
|
|
123
|
+
return segments.map((segment) => {
|
|
124
|
+
let isEditable = isSegmentEditable(segment.type);
|
|
125
|
+
if (segment.type === "era")
|
|
126
|
+
isEditable = false;
|
|
127
|
+
let isPlaceholder = isSegmentEditable(segment.type) && !ctx.validSegments[segment.type];
|
|
128
|
+
let placeholder = isSegmentEditable(segment.type) ? getPlaceholder({ field: segment.type }) : null;
|
|
129
|
+
return {
|
|
130
|
+
type: segment.type,
|
|
131
|
+
text: isPlaceholder ? placeholder : segment.value,
|
|
132
|
+
...getSegmentLimits(date, segment.type, formatter.resolvedOptions()),
|
|
133
|
+
isPlaceholder: !!isPlaceholder,
|
|
134
|
+
placeholder,
|
|
135
|
+
isEditable: !!isEditable
|
|
136
|
+
};
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
140
|
+
0 && (module.exports = {
|
|
141
|
+
getAllSegments,
|
|
142
|
+
getSegments
|
|
143
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isSegmentEditable
|
|
3
|
+
} from "./chunk-6NI2PIAA.mjs";
|
|
4
|
+
import {
|
|
5
|
+
getSegmentLimits
|
|
6
|
+
} from "./chunk-2DZ3KIVJ.mjs";
|
|
7
|
+
|
|
8
|
+
// src/segment-parts.ts
|
|
9
|
+
function getAllSegments(segments) {
|
|
10
|
+
return segments.filter((segment) => isSegmentEditable(segment.type)).reduce((acc, segment) => (acc[segment.type] = true, acc), {});
|
|
11
|
+
}
|
|
12
|
+
function getPlaceholder(params) {
|
|
13
|
+
const placeholder = { day: "dd", month: "mm", year: "yyyy" };
|
|
14
|
+
return placeholder[params.field];
|
|
15
|
+
}
|
|
16
|
+
function getSegments(ctx, date, formatter) {
|
|
17
|
+
const segments = formatter.formatToParts(date.toDate(ctx.timeZone));
|
|
18
|
+
return segments.map((segment) => {
|
|
19
|
+
let isEditable = isSegmentEditable(segment.type);
|
|
20
|
+
if (segment.type === "era")
|
|
21
|
+
isEditable = false;
|
|
22
|
+
let isPlaceholder = isSegmentEditable(segment.type) && !ctx.validSegments[segment.type];
|
|
23
|
+
let placeholder = isSegmentEditable(segment.type) ? getPlaceholder({ field: segment.type }) : null;
|
|
24
|
+
return {
|
|
25
|
+
type: segment.type,
|
|
26
|
+
text: isPlaceholder ? placeholder : segment.value,
|
|
27
|
+
...getSegmentLimits(date, segment.type, formatter.resolvedOptions()),
|
|
28
|
+
isPlaceholder: !!isPlaceholder,
|
|
29
|
+
placeholder,
|
|
30
|
+
isEditable: !!isEditable
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
export {
|
|
35
|
+
getAllSegments,
|
|
36
|
+
getSegments
|
|
37
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { DateDuration, DateValue, DateFormatter, CalendarDate } from '@internationalized/date';
|
|
2
|
+
|
|
3
|
+
declare const EDITABLE_SEGMENTS: {
|
|
4
|
+
year: boolean;
|
|
5
|
+
month: boolean;
|
|
6
|
+
day: boolean;
|
|
7
|
+
hour: boolean;
|
|
8
|
+
minute: boolean;
|
|
9
|
+
second: boolean;
|
|
10
|
+
dayPeriod: boolean;
|
|
11
|
+
era: boolean;
|
|
12
|
+
};
|
|
13
|
+
type DateSegments = Partial<typeof EDITABLE_SEGMENTS>;
|
|
14
|
+
declare const SEGMENT_PAGE_STEP: {
|
|
15
|
+
year: number;
|
|
16
|
+
month: number;
|
|
17
|
+
day: number;
|
|
18
|
+
hour: number;
|
|
19
|
+
minute: number;
|
|
20
|
+
second: number;
|
|
21
|
+
};
|
|
22
|
+
declare function isSegmentEditable(segment: DateSegmentPart): any;
|
|
23
|
+
|
|
24
|
+
type DateGranularity = "day" | "hour" | "minute" | "second" | "year" | "month";
|
|
25
|
+
type DateAlignment = "start" | "end" | "center";
|
|
26
|
+
type DateContext = DateValueRange & {
|
|
27
|
+
locale: string;
|
|
28
|
+
timeZone: string;
|
|
29
|
+
duration: DateDuration;
|
|
30
|
+
isUnavailable?: (date: DateValue) => boolean;
|
|
31
|
+
};
|
|
32
|
+
type DateValueRange = {
|
|
33
|
+
min?: DateValue;
|
|
34
|
+
max?: DateValue;
|
|
35
|
+
};
|
|
36
|
+
type DateSegmentContext = {
|
|
37
|
+
timeZone: string;
|
|
38
|
+
locale: string;
|
|
39
|
+
granularity: DateGranularity;
|
|
40
|
+
allSegments: DateSegments;
|
|
41
|
+
displayValue: DateValue;
|
|
42
|
+
validSegments: DateSegments;
|
|
43
|
+
getDateFormatter: (options: Intl.DateTimeFormatOptions) => DateFormatter;
|
|
44
|
+
getPlaceholder: (options: {
|
|
45
|
+
field: string;
|
|
46
|
+
locale: string;
|
|
47
|
+
}) => string;
|
|
48
|
+
};
|
|
49
|
+
type DateDescriptionContext = {
|
|
50
|
+
start?: CalendarDate;
|
|
51
|
+
end?: CalendarDate;
|
|
52
|
+
isSelectingRange?: boolean;
|
|
53
|
+
timeZone: string;
|
|
54
|
+
locale: string;
|
|
55
|
+
getDateFormatter: (options: Intl.DateTimeFormatOptions) => DateFormatter;
|
|
56
|
+
toString: (start: string, end: string) => string;
|
|
57
|
+
};
|
|
58
|
+
type DateSegmentPart = Intl.DateTimeFormatPartTypes;
|
|
59
|
+
type DateFormatOptions = Intl.ResolvedDateTimeFormatOptions;
|
|
60
|
+
|
|
61
|
+
export { DateContext as D, SEGMENT_PAGE_STEP as S, DateAlignment as a, DateDescriptionContext as b, DateGranularity as c, DateSegments as d, DateSegmentPart as e, DateFormatOptions as f, DateSegmentContext as g, DateValueRange as h, isSegmentEditable as i };
|
package/dist/types.d.ts
ADDED
package/dist/types.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/types.ts
|
|
17
|
+
var types_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(types_exports);
|
package/dist/types.mjs
ADDED
|
File without changes
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zag-js/date-utils",
|
|
3
|
+
"version": "0.0.0-dev-20230107115230",
|
|
4
|
+
"description": "Date utilities for zag.js",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"js",
|
|
7
|
+
"utils",
|
|
8
|
+
"date-utils"
|
|
9
|
+
],
|
|
10
|
+
"author": "Segun Adebayo <sage@adebayosegun.com>",
|
|
11
|
+
"homepage": "https://github.com/chakra-ui/zag#readme",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"main": "dist/index.js",
|
|
14
|
+
"repository": "https://github.com/chakra-ui/zag/tree/main/packages/utilities/date-utils",
|
|
15
|
+
"sideEffects": false,
|
|
16
|
+
"files": [
|
|
17
|
+
"dist/**/*"
|
|
18
|
+
],
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public"
|
|
21
|
+
},
|
|
22
|
+
"bugs": {
|
|
23
|
+
"url": "https://github.com/chakra-ui/zag/issues"
|
|
24
|
+
},
|
|
25
|
+
"clean-package": "../../../clean-package.config.json",
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"@internationalized/date": ">=3.0.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"clean-package": "2.2.0",
|
|
31
|
+
"@internationalized/date": "^3.0.2"
|
|
32
|
+
},
|
|
33
|
+
"module": "dist/index.mjs",
|
|
34
|
+
"types": "dist/index.d.ts",
|
|
35
|
+
"exports": {
|
|
36
|
+
".": {
|
|
37
|
+
"types": "./dist/index.d.ts",
|
|
38
|
+
"import": "./dist/index.mjs",
|
|
39
|
+
"require": "./dist/index.js"
|
|
40
|
+
},
|
|
41
|
+
"./package.json": "./package.json"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build-fast": "tsup src",
|
|
45
|
+
"start": "pnpm build --watch",
|
|
46
|
+
"build": "tsup src --dts",
|
|
47
|
+
"test": "jest --config ../../../jest.config.js --rootDir . --passWithNoTests",
|
|
48
|
+
"lint": "eslint src --ext .ts,.tsx",
|
|
49
|
+
"test-ci": "pnpm test --ci --runInBand",
|
|
50
|
+
"test-watch": "pnpm test --watch -u",
|
|
51
|
+
"typecheck": "tsc --noEmit"
|
|
52
|
+
}
|
|
53
|
+
}
|