@sanity/rich-date-input 3.0.8 → 4.0.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/LICENSE +1 -1
- package/README.md +3 -20
- package/dist/index.d.ts +18 -29
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +164 -252
- package/dist/index.js.map +1 -1
- package/package.json +36 -68
- package/dist/index.esm.js +0 -303
- package/dist/index.esm.js.map +0 -1
- package/sanity.json +0 -8
- package/src/components/RelativeDateTimePicker.tsx +0 -68
- package/src/components/RichDateInput.tsx +0 -61
- package/src/components/TimezoneButton.tsx +0 -34
- package/src/components/TimezoneSelector.tsx +0 -89
- package/src/index.ts +0 -13
- package/src/schema.ts +0 -62
- package/src/types/index.ts +0 -18
- package/src/utils/index.ts +0 -41
- package/v2-incompatible.js +0 -11
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
# @sanity/rich-date-input
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A timezone-aware datetime type and input component for Sanity Studio.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-

|
|
5
|
+

|
|
8
6
|
|
|
9
7
|
## Installation
|
|
10
8
|
|
|
@@ -66,18 +64,3 @@ The typical data output should be:
|
|
|
66
64
|
## License
|
|
67
65
|
|
|
68
66
|
[MIT](LICENSE) © Sanity.io
|
|
69
|
-
|
|
70
|
-
## Develop & test
|
|
71
|
-
|
|
72
|
-
This plugin uses [@sanity/plugin-kit](https://github.com/sanity-io/plugin-kit)
|
|
73
|
-
with default configuration for build & watch scripts.
|
|
74
|
-
|
|
75
|
-
See [Testing a plugin in Sanity Studio](https://github.com/sanity-io/plugin-kit#testing-a-plugin-in-sanity-studio)
|
|
76
|
-
on how to run this plugin with hotreload in the studio.
|
|
77
|
-
|
|
78
|
-
### Release new version
|
|
79
|
-
|
|
80
|
-
Run ["CI & Release" workflow](https://github.com/sanity-io/v3-rich-date-input/actions/workflows/main.yml).
|
|
81
|
-
Make sure to select the main branch and check "Release new version".
|
|
82
|
-
|
|
83
|
-
Semantic release will only release on configured branches, so it is safe to run release on any branch.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,38 +1,27 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {ObjectDefinition} from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
utc: string
|
|
9
|
-
timezone: string
|
|
10
|
-
offset: number
|
|
1
|
+
import * as sanity1 from "sanity";
|
|
2
|
+
import { DatetimeDefinition, ObjectDefinition, ObjectSchemaType } from "sanity";
|
|
3
|
+
interface RichDate {
|
|
4
|
+
local: string;
|
|
5
|
+
utc: string;
|
|
6
|
+
timezone: string;
|
|
7
|
+
offset: number;
|
|
11
8
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
declare const richDateTypeName: "richDate";
|
|
10
|
+
type RichDateSchemaType = Omit<ObjectSchemaType, 'options'> & {
|
|
11
|
+
options?: DatetimeDefinition['options'];
|
|
12
|
+
};
|
|
15
13
|
/**
|
|
16
14
|
* @public
|
|
17
15
|
*/
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
> {
|
|
22
|
-
type: typeof richDateTypeName
|
|
23
|
-
options?: DatetimeDefinition['options']
|
|
16
|
+
interface RichDateDefinition extends Omit<ObjectDefinition, 'type' | 'fields' | 'options'> {
|
|
17
|
+
type: typeof richDateTypeName;
|
|
18
|
+
options?: DatetimeDefinition['options'];
|
|
24
19
|
}
|
|
25
|
-
|
|
26
|
-
export declare type RichDateSchemaType = Omit<ObjectSchemaType, 'options'> & {
|
|
27
|
-
options?: DatetimeDefinition['options']
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
declare const richDateTypeName: 'richDate'
|
|
31
|
-
|
|
32
|
-
export {}
|
|
33
|
-
|
|
34
20
|
declare module 'sanity' {
|
|
35
21
|
interface IntrinsicDefinitions {
|
|
36
|
-
richDate: RichDateDefinition
|
|
22
|
+
richDate: RichDateDefinition;
|
|
37
23
|
}
|
|
38
24
|
}
|
|
25
|
+
declare const richDate: sanity1.Plugin<void>;
|
|
26
|
+
export { type RichDate, type RichDateDefinition, type RichDateSchemaType, richDate };
|
|
27
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/types/index.ts","../src/schema.ts","../src/index.ts"],"sourcesContent":[],"mappings":";;UAAiB,QAAA;;;EAAA,QAAA,EAAA,MAAQ;;ACMV;cAIT;KAEM,kBAAA,GAAqB,KAAK;EDZrB,OAAA,CAAA,ECaL,kBDba,CAAA,SAAA,CAAA;;ACMV;AAMf;;AAAiC,UAOhB,kBAAA,SAA2B,IAPX,CAOgB,gBAPhB,EAAA,MAAA,GAAA,QAAA,GAAA,SAAA,CAAA,CAAA;EACrB,IAAA,EAAA,OAOG,gBAPH;EAAkB,OAAA,CAAA,EAQlB,kBARkB,CAAA,SAAA,CAAA;AAM9B;eAAiD,QAAA,CAAA;EAClC,UAAA,oBAAA,CAAA;IACH,QAAA,EAME,kBANF;EAFgC;;cCb/B,UAKX,OAAA,CALmB"}
|
package/dist/index.js
CHANGED
|
@@ -1,26 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
return dateFnsTz.formatInTimeZone(datetime, timezone, "yyyy-MM-dd HH:mm:ss");
|
|
15
|
-
};
|
|
16
|
-
const getConstructedUTCDate = (utc, offset) => {
|
|
17
|
-
const date = new Date(utc);
|
|
18
|
-
const currentOffset = date.getTimezoneOffset() * -1;
|
|
19
|
-
const diff = currentOffset - offset;
|
|
20
|
-
const fakeUTCDate = new Date(date.getTime() - diff * 60 * 1e3);
|
|
21
|
-
return fakeUTCDate.toISOString();
|
|
22
|
-
};
|
|
23
|
-
const allTimezones = tzdb.getTimeZones().map(tz => {
|
|
1
|
+
import { DateTimeInput, unset, set, ObjectInputMember, defineType, defineField, definePlugin } from "sanity";
|
|
2
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { c } from "react/compiler-runtime";
|
|
4
|
+
import { Button, Box, Autocomplete, Card, Text, Flex, Dialog } from "@sanity/ui";
|
|
5
|
+
import { useState } from "react";
|
|
6
|
+
import { formatInTimeZone, getTimezoneOffset, zonedTimeToUtc } from "date-fns-tz";
|
|
7
|
+
import { getTimeZones } from "@vvo/tzdb";
|
|
8
|
+
import { EarthAmericasIcon, SearchIcon } from "@sanity/icons";
|
|
9
|
+
const unlocalizeDateTime = (datetime, timezone) => formatInTimeZone(datetime, timezone, "yyyy-MM-dd HH:mm:ss"), getConstructedUTCDate = (utc, offset) => {
|
|
10
|
+
const date = new Date(utc), diff = date.getTimezoneOffset() * -1 - offset;
|
|
11
|
+
return new Date(date.getTime() - diff * 60 * 1e3).toISOString();
|
|
12
|
+
}, allTimezones = getTimeZones().map((tz) => {
|
|
13
|
+
const offset = tz.currentTimeFormat.split(" ")[0];
|
|
24
14
|
return {
|
|
25
15
|
abbreviation: tz.abbreviation,
|
|
26
16
|
alternativeName: tz.alternativeName,
|
|
@@ -29,267 +19,188 @@ const allTimezones = tzdb.getTimeZones().map(tz => {
|
|
|
29
19
|
name: tz.name,
|
|
30
20
|
// Time zone name with underscores removed
|
|
31
21
|
namePretty: tz.name.replaceAll("_", " "),
|
|
32
|
-
offset:
|
|
22
|
+
offset: offset ?? "",
|
|
33
23
|
// all searchable text - this is transformed before being rendered in `<AutoComplete>`
|
|
34
|
-
value:
|
|
24
|
+
value: `${tz.currentTimeFormat} ${tz.abbreviation} ${tz.name}`,
|
|
35
25
|
currentTimeOffsetInMinutes: tz.currentTimeOffsetInMinutes,
|
|
36
26
|
group: tz.group
|
|
37
27
|
};
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
var __defProps$1 = Object.defineProperties;
|
|
41
|
-
var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
|
|
42
|
-
var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
|
|
43
|
-
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
|
|
44
|
-
var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
|
|
45
|
-
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, {
|
|
46
|
-
enumerable: true,
|
|
47
|
-
configurable: true,
|
|
48
|
-
writable: true,
|
|
49
|
-
value
|
|
50
|
-
}) : obj[key] = value;
|
|
51
|
-
var __spreadValues$1 = (a, b) => {
|
|
52
|
-
for (var prop in b || (b = {})) if (__hasOwnProp$1.call(b, prop)) __defNormalProp$1(a, prop, b[prop]);
|
|
53
|
-
if (__getOwnPropSymbols$1) for (var prop of __getOwnPropSymbols$1(b)) {
|
|
54
|
-
if (__propIsEnum$1.call(b, prop)) __defNormalProp$1(a, prop, b[prop]);
|
|
55
|
-
}
|
|
56
|
-
return a;
|
|
57
|
-
};
|
|
58
|
-
var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
|
|
59
|
-
const RelativeDateTimePicker = props => {
|
|
60
|
-
var _a;
|
|
61
|
-
const {
|
|
28
|
+
}), RelativeDateTimePicker = (props) => {
|
|
29
|
+
const $ = c(13), {
|
|
62
30
|
dateValue: value,
|
|
63
|
-
inputProps:
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
} =
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
onChange(sanity.unset());
|
|
31
|
+
inputProps: t0
|
|
32
|
+
} = props, {
|
|
33
|
+
onChange
|
|
34
|
+
} = t0;
|
|
35
|
+
let t1;
|
|
36
|
+
$[0] !== onChange || $[1] !== value?.offset || $[2] !== value?.timezone ? (t1 = (patch) => {
|
|
37
|
+
const formatter = new Intl.DateTimeFormat(), timezone = value?.timezone ?? formatter.resolvedOptions().timeZone;
|
|
38
|
+
if (!patch || Array.isArray(patch) || !("type" in patch) || patch.type !== "set" || !("value" in patch) || typeof patch.value != "string") {
|
|
39
|
+
onChange(unset());
|
|
73
40
|
return;
|
|
74
41
|
}
|
|
75
|
-
const desiredDateTime = unlocalizeDateTime(newDatetime,
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}, [onChange, value]);
|
|
90
|
-
const displayOffset = (value == null ? void 0 : value.utc) && (value == null ? void 0 : value.timezone) ? dateFnsTz.getTimezoneOffset(value.timezone, new Date(value.utc)) / 60 / 1e3 : (_a = value == null ? void 0 : value.offset) != null ? _a : 0;
|
|
91
|
-
const dateToDisplay = (value == null ? void 0 : value.utc) ? getConstructedUTCDate(value.utc, displayOffset) : "";
|
|
92
|
-
return /* @__PURE__ */jsxRuntime.jsx(sanity.DateTimeInput, __spreadProps$1(__spreadValues$1({}, props), {
|
|
93
|
-
onChange: handleDateChange,
|
|
94
|
-
value: dateToDisplay
|
|
95
|
-
}));
|
|
96
|
-
};
|
|
97
|
-
const TimezoneButton = props => {
|
|
98
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
99
|
-
const {
|
|
42
|
+
const newDatetime = patch.value, desiredDateTime = unlocalizeDateTime(newDatetime, formatter.resolvedOptions().timeZone), newUtcDateObject = zonedTimeToUtc(desiredDateTime, timezone), newOffset = getTimezoneOffset(timezone, newUtcDateObject) / 60 / 1e3, localDate = formatInTimeZone(newUtcDateObject, timezone, "yyyy-MM-dd'T'HH:mm:ssXXX"), patches = [];
|
|
43
|
+
patches.push(set(newUtcDateObject.toISOString(), ["utc"])), patches.push(set(localDate, ["local"])), value?.timezone || patches.push(set(timezone, ["timezone"])), value?.offset !== newOffset && patches.push(set(newOffset, ["offset"])), onChange(patches);
|
|
44
|
+
}, $[0] = onChange, $[1] = value?.offset, $[2] = value?.timezone, $[3] = t1) : t1 = $[3];
|
|
45
|
+
const handleDateChange = t1;
|
|
46
|
+
let t2;
|
|
47
|
+
$[4] !== value ? (t2 = value?.utc && value?.timezone ? getTimezoneOffset(value.timezone, new Date(value.utc)) / 60 / 1e3 : value?.offset ?? 0, $[4] = value, $[5] = t2) : t2 = $[5];
|
|
48
|
+
const displayOffset = t2;
|
|
49
|
+
let t3;
|
|
50
|
+
$[6] !== displayOffset || $[7] !== value ? (t3 = value?.utc ? getConstructedUTCDate(value.utc, displayOffset) : "", $[6] = displayOffset, $[7] = value, $[8] = t3) : t3 = $[8];
|
|
51
|
+
const dateToDisplay = t3;
|
|
52
|
+
let t4;
|
|
53
|
+
return $[9] !== dateToDisplay || $[10] !== handleDateChange || $[11] !== props ? (t4 = /* @__PURE__ */ jsx(DateTimeInput, { ...props, onChange: handleDateChange, value: dateToDisplay }), $[9] = dateToDisplay, $[10] = handleDateChange, $[11] = props, $[12] = t4) : t4 = $[12], t4;
|
|
54
|
+
}, TimezoneButton = (props) => {
|
|
55
|
+
const $ = c(6), {
|
|
100
56
|
onClick,
|
|
101
57
|
timezone
|
|
102
58
|
} = props;
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
const
|
|
119
|
-
var _a, _b;
|
|
120
|
-
const {
|
|
59
|
+
let t0;
|
|
60
|
+
if ($[0] !== timezone) {
|
|
61
|
+
const currentTimezone = new Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
62
|
+
t0 = allTimezones.find((tz_2) => tz_2.name === timezone)?.abbreviation ?? allTimezones.find((tz_1) => tz_1.group.includes(timezone))?.abbreviation ?? allTimezones.find((tz_0) => tz_0.name === currentTimezone)?.abbreviation ?? allTimezones.find((tz) => tz.group.includes(currentTimezone))?.abbreviation, $[0] = timezone, $[1] = t0;
|
|
63
|
+
} else
|
|
64
|
+
t0 = $[1];
|
|
65
|
+
const label = t0;
|
|
66
|
+
let t1;
|
|
67
|
+
$[2] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t1 = {
|
|
68
|
+
width: "100%"
|
|
69
|
+
}, $[2] = t1) : t1 = $[2];
|
|
70
|
+
const t2 = `${label}`;
|
|
71
|
+
let t3;
|
|
72
|
+
return $[3] !== onClick || $[4] !== t2 ? (t3 = /* @__PURE__ */ jsx(Button, { fontSize: 1, style: t1, justify: "flex-start", icon: EarthAmericasIcon, mode: "ghost", onClick, text: t2, "aria-label": "Select a timezone" }), $[3] = onClick, $[4] = t2, $[5] = t3) : t3 = $[5], t3;
|
|
73
|
+
}, TimezoneSelector = (props) => {
|
|
74
|
+
const $ = c(10), {
|
|
121
75
|
onChange,
|
|
122
76
|
value
|
|
123
77
|
} = props;
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
patches.push(
|
|
78
|
+
let t0;
|
|
79
|
+
$[0] !== value?.timezone ? (t0 = allTimezones.find((tz) => tz.name === value?.timezone), $[0] = value?.timezone, $[1] = t0) : t0 = $[1];
|
|
80
|
+
const currentTz = t0;
|
|
81
|
+
let t1;
|
|
82
|
+
if ($[2] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
|
|
83
|
+
const userTzName = new Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
84
|
+
t1 = allTimezones.find((tz_1) => tz_1.name === userTzName) ?? allTimezones.find((tz_0) => tz_0.group.includes(userTzName)), $[2] = t1;
|
|
85
|
+
} else
|
|
86
|
+
t1 = $[2];
|
|
87
|
+
const userTz = t1;
|
|
88
|
+
let t2;
|
|
89
|
+
$[3] !== onChange || $[4] !== value ? (t2 = (selectedTz) => {
|
|
90
|
+
const newTimezone = allTimezones.find((tz_2) => tz_2.value === selectedTz) ?? userTz, patches = [set(newTimezone.name, ["timezone"])];
|
|
91
|
+
if (value?.utc) {
|
|
92
|
+
const desiredDateTime = unlocalizeDateTime(value.utc, value.timezone), newUtcDateObject = zonedTimeToUtc(desiredDateTime, newTimezone.name), newOffset = getTimezoneOffset(newTimezone.name, newUtcDateObject) / 60 / 1e3, newLocalDate = formatInTimeZone(newUtcDateObject.toISOString(), newTimezone.name, "yyyy-MM-dd'T'HH:mm:ssXXX");
|
|
93
|
+
patches.push(set(newUtcDateObject.toISOString(), ["utc"])), patches.push(set(newLocalDate, ["local"])), patches.push(set(newOffset, ["offset"]));
|
|
140
94
|
}
|
|
141
95
|
onChange(patches);
|
|
142
|
-
}, [onChange,
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
onChange: handleTimezoneChange,
|
|
154
|
-
openButton: true,
|
|
155
|
-
options: allTimezones,
|
|
156
|
-
padding: 4,
|
|
157
|
-
placeholder: "Search for a city or time zone",
|
|
158
|
-
popover: {
|
|
159
|
-
boundaryElement: document.querySelector("body"),
|
|
160
|
-
constrainSize: true,
|
|
161
|
-
placement: "bottom-start"
|
|
162
|
-
},
|
|
163
|
-
renderOption: option => {
|
|
164
|
-
return /* @__PURE__ */jsxRuntime.jsx(ui.Card, {
|
|
165
|
-
as: "button",
|
|
166
|
-
padding: 3,
|
|
167
|
-
children: /* @__PURE__ */jsxRuntime.jsxs(ui.Text, {
|
|
168
|
-
size: 1,
|
|
169
|
-
textOverflow: "ellipsis",
|
|
170
|
-
children: [/* @__PURE__ */jsxRuntime.jsxs("span", {
|
|
171
|
-
children: ["GMT", option.offset]
|
|
172
|
-
}), /* @__PURE__ */jsxRuntime.jsx("span", {
|
|
173
|
-
style: {
|
|
174
|
-
fontWeight: 500,
|
|
175
|
-
marginLeft: "1em"
|
|
176
|
-
},
|
|
177
|
-
children: option.alternativeName
|
|
178
|
-
}), /* @__PURE__ */jsxRuntime.jsx("span", {
|
|
179
|
-
style: {
|
|
180
|
-
marginLeft: "1em"
|
|
181
|
-
},
|
|
182
|
-
children: option.mainCities
|
|
183
|
-
})]
|
|
184
|
-
})
|
|
185
|
-
});
|
|
186
|
-
},
|
|
187
|
-
renderValue: (_, option) => {
|
|
188
|
-
if (!option) return "";
|
|
189
|
-
return "".concat(option.alternativeName, " (").concat(option.namePretty, ")");
|
|
190
|
-
},
|
|
191
|
-
tabIndex: -1,
|
|
192
|
-
value: (_b = currentTz == null ? void 0 : currentTz.value) != null ? _b : userTz.value
|
|
193
|
-
})
|
|
194
|
-
})
|
|
195
|
-
);
|
|
196
|
-
};
|
|
197
|
-
var __defProp = Object.defineProperty;
|
|
198
|
-
var __defProps = Object.defineProperties;
|
|
199
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
200
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
201
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
202
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
203
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
|
|
204
|
-
enumerable: true,
|
|
205
|
-
configurable: true,
|
|
206
|
-
writable: true,
|
|
207
|
-
value
|
|
208
|
-
}) : obj[key] = value;
|
|
209
|
-
var __spreadValues = (a, b) => {
|
|
210
|
-
for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
|
|
211
|
-
if (__getOwnPropSymbols) for (var prop of __getOwnPropSymbols(b)) {
|
|
212
|
-
if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
|
|
213
|
-
}
|
|
214
|
-
return a;
|
|
96
|
+
}, $[3] = onChange, $[4] = value, $[5] = t2) : t2 = $[5];
|
|
97
|
+
const handleTimezoneChange = t2;
|
|
98
|
+
let t3;
|
|
99
|
+
$[6] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t3 = {
|
|
100
|
+
boundaryElement: document.querySelector("body"),
|
|
101
|
+
constrainSize: !0,
|
|
102
|
+
placement: "bottom-start"
|
|
103
|
+
}, $[6] = t3) : t3 = $[6];
|
|
104
|
+
const t4 = currentTz?.value ?? userTz.value;
|
|
105
|
+
let t5;
|
|
106
|
+
return $[7] !== handleTimezoneChange || $[8] !== t4 ? (t5 = /* @__PURE__ */ jsx(Box, { padding: 4, children: /* @__PURE__ */ jsx(Autocomplete, { fontSize: 2, icon: SearchIcon, id: "timezone", onChange: handleTimezoneChange, openButton: !0, options: allTimezones, padding: 4, placeholder: "Search for a city or time zone", popover: t3, renderOption: _temp$1, renderValue: _temp2$1, tabIndex: -1, value: t4 }) }), $[7] = handleTimezoneChange, $[8] = t4, $[9] = t5) : t5 = $[9], t5;
|
|
215
107
|
};
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
108
|
+
function _temp$1(option) {
|
|
109
|
+
return /* @__PURE__ */ jsx(Card, { as: "button", padding: 3, children: /* @__PURE__ */ jsxs(Text, { size: 1, textOverflow: "ellipsis", children: [
|
|
110
|
+
/* @__PURE__ */ jsxs("span", { children: [
|
|
111
|
+
"GMT",
|
|
112
|
+
option.offset
|
|
113
|
+
] }),
|
|
114
|
+
/* @__PURE__ */ jsx("span", { style: {
|
|
115
|
+
fontWeight: 500,
|
|
116
|
+
marginLeft: "1em"
|
|
117
|
+
}, children: option.alternativeName }),
|
|
118
|
+
/* @__PURE__ */ jsx("span", { style: {
|
|
119
|
+
marginLeft: "1em"
|
|
120
|
+
}, children: option.mainCities })
|
|
121
|
+
] }) });
|
|
122
|
+
}
|
|
123
|
+
function _temp2$1(_, option_0) {
|
|
124
|
+
return option_0 ? `${option_0.alternativeName} (${option_0.namePretty})` : "";
|
|
125
|
+
}
|
|
126
|
+
function isRichDate(value) {
|
|
127
|
+
return typeof value == "object" && value !== null && "_type" in value && value._type === "richDate";
|
|
128
|
+
}
|
|
129
|
+
const RichDateInput = (props) => {
|
|
130
|
+
const $ = c(33), {
|
|
219
131
|
onChange,
|
|
220
132
|
value,
|
|
221
133
|
members,
|
|
222
134
|
schemaType
|
|
223
|
-
} = props
|
|
224
|
-
const {
|
|
135
|
+
} = props, {
|
|
225
136
|
options
|
|
226
137
|
} = schemaType;
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
const
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
onChange,
|
|
270
|
-
value
|
|
271
|
-
})
|
|
272
|
-
})]
|
|
273
|
-
});
|
|
138
|
+
let t0;
|
|
139
|
+
$[0] !== members ? (t0 = members.find(_temp), $[0] = members, $[1] = t0) : t0 = $[1];
|
|
140
|
+
const localMember = t0;
|
|
141
|
+
let t1;
|
|
142
|
+
$[2] !== members ? (t1 = members.find(_temp2), $[2] = members, $[3] = t1) : t1 = $[3];
|
|
143
|
+
const timezoneMember = t1, [timezoneSelectorOpen, setTimezoneSelectorOpen] = useState(!1);
|
|
144
|
+
let t2;
|
|
145
|
+
$[4] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t2 = () => setTimezoneSelectorOpen(!1), $[4] = t2) : t2 = $[4];
|
|
146
|
+
const onClose = t2;
|
|
147
|
+
let t3;
|
|
148
|
+
$[5] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t3 = () => setTimezoneSelectorOpen(!0), $[5] = t3) : t3 = $[5];
|
|
149
|
+
const onOpen = t3, richDateValue = isRichDate(value) ? value : void 0;
|
|
150
|
+
let t4;
|
|
151
|
+
$[6] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t4 = [1, 2, 4], $[6] = t4) : t4 = $[6];
|
|
152
|
+
let t5;
|
|
153
|
+
$[7] !== localMember || $[8] !== onChange || $[9] !== options || $[10] !== props || $[11] !== richDateValue ? (t5 = localMember && /* @__PURE__ */ jsx(ObjectInputMember, { ...props, member: localMember, renderField: (renderFieldProps) => /* @__PURE__ */ jsx(RelativeDateTimePicker, { ...renderFieldProps, dateValue: richDateValue, schemaType: {
|
|
154
|
+
...renderFieldProps.schemaType,
|
|
155
|
+
options
|
|
156
|
+
}, inputProps: {
|
|
157
|
+
...renderFieldProps.inputProps,
|
|
158
|
+
onChange
|
|
159
|
+
} }) }), $[7] = localMember, $[8] = onChange, $[9] = options, $[10] = props, $[11] = richDateValue, $[12] = t5) : t5 = $[12];
|
|
160
|
+
let t6;
|
|
161
|
+
$[13] !== t5 ? (t6 = /* @__PURE__ */ jsx(Box, { flex: t4, children: t5 }), $[13] = t5, $[14] = t6) : t6 = $[14];
|
|
162
|
+
let t7, t8;
|
|
163
|
+
$[15] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t7 = [1], t8 = [2, 2, 3, 4], $[15] = t7, $[16] = t8) : (t7 = $[15], t8 = $[16]);
|
|
164
|
+
let t9;
|
|
165
|
+
$[17] !== props || $[18] !== richDateValue?.timezone || $[19] !== timezoneMember ? (t9 = timezoneMember && /* @__PURE__ */ jsx(ObjectInputMember, { ...props, member: timezoneMember, renderInput: () => /* @__PURE__ */ jsx(TimezoneButton, { onClick: onOpen, timezone: richDateValue?.timezone ?? "" }) }), $[17] = props, $[18] = richDateValue?.timezone, $[19] = timezoneMember, $[20] = t9) : t9 = $[20];
|
|
166
|
+
let t10;
|
|
167
|
+
$[21] !== t9 ? (t10 = /* @__PURE__ */ jsx(Box, { flex: t7, marginLeft: t8, marginTop: 2, children: t9 }), $[21] = t9, $[22] = t10) : t10 = $[22];
|
|
168
|
+
let t11;
|
|
169
|
+
$[23] !== t10 || $[24] !== t6 ? (t11 = /* @__PURE__ */ jsxs(Flex, { children: [
|
|
170
|
+
t6,
|
|
171
|
+
t10
|
|
172
|
+
] }), $[23] = t10, $[24] = t6, $[25] = t11) : t11 = $[25];
|
|
173
|
+
let t12;
|
|
174
|
+
$[26] !== onChange || $[27] !== richDateValue || $[28] !== timezoneSelectorOpen ? (t12 = timezoneSelectorOpen && /* @__PURE__ */ jsx(Dialog, { onClose, header: "Select a timezone", id: "timezone-select", width: 1, children: /* @__PURE__ */ jsx(TimezoneSelector, { onChange, value: richDateValue }) }), $[26] = onChange, $[27] = richDateValue, $[28] = timezoneSelectorOpen, $[29] = t12) : t12 = $[29];
|
|
175
|
+
let t13;
|
|
176
|
+
return $[30] !== t11 || $[31] !== t12 ? (t13 = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
177
|
+
t11,
|
|
178
|
+
t12
|
|
179
|
+
] }), $[30] = t11, $[31] = t12, $[32] = t13) : t13 = $[32], t13;
|
|
274
180
|
};
|
|
275
|
-
|
|
276
|
-
|
|
181
|
+
function _temp(member) {
|
|
182
|
+
return member.kind === "field" && member.name === "local";
|
|
183
|
+
}
|
|
184
|
+
function _temp2(member_0) {
|
|
185
|
+
return member_0.kind === "field" && member_0.name === "timezone";
|
|
186
|
+
}
|
|
187
|
+
const richDateTypeName = "richDate", richDateSchema = defineType({
|
|
277
188
|
name: richDateTypeName,
|
|
278
189
|
title: "Rich Date",
|
|
279
190
|
type: "object",
|
|
280
|
-
fields: [
|
|
191
|
+
fields: [defineField({
|
|
281
192
|
name: "local",
|
|
282
193
|
title: "Local",
|
|
283
194
|
type: "string"
|
|
284
|
-
}),
|
|
195
|
+
}), defineField({
|
|
285
196
|
name: "utc",
|
|
286
197
|
title: "UTC",
|
|
287
198
|
type: "string"
|
|
288
|
-
}),
|
|
199
|
+
}), defineField({
|
|
289
200
|
name: "timezone",
|
|
290
201
|
title: "Timezone",
|
|
291
202
|
type: "string"
|
|
292
|
-
}),
|
|
203
|
+
}), defineField({
|
|
293
204
|
name: "offset",
|
|
294
205
|
title: "Offset",
|
|
295
206
|
type: "number"
|
|
@@ -297,12 +208,13 @@ const richDateSchema = sanity.defineType({
|
|
|
297
208
|
components: {
|
|
298
209
|
input: RichDateInput
|
|
299
210
|
}
|
|
300
|
-
})
|
|
301
|
-
const richDate = sanity.definePlugin({
|
|
211
|
+
}), richDate = definePlugin({
|
|
302
212
|
name: "v3-rich-date-input",
|
|
303
213
|
schema: {
|
|
304
214
|
types: [richDateSchema]
|
|
305
215
|
}
|
|
306
216
|
});
|
|
307
|
-
|
|
217
|
+
export {
|
|
218
|
+
richDate
|
|
219
|
+
};
|
|
308
220
|
//# sourceMappingURL=index.js.map
|