@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2025 Sanity.io
3
+ Copyright (c) 2026 Sanity.io
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,10 +1,8 @@
1
- > For the v2 version, please refer to the [studio-v2 branch](https://github.com/sanity-io/rich-date-input/tree/studio-v2).
1
+ # @sanity/rich-date-input
2
2
 
3
- # V3 Rich Date Input
3
+ A timezone-aware datetime type and input component for Sanity Studio.
4
4
 
5
- Provides a timezone-aware date input for Sanity Studio.
6
-
7
- ![This is an image](assets/plugin.gif)
5
+ ![Rich Date Input demo](https://raw.githubusercontent.com/sanity-io/rich-date-input/main/assets/plugin.gif)
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 {DatetimeDefinition} from 'sanity'
2
- import {ObjectDefinition} from 'sanity'
3
- import {ObjectSchemaType} from 'sanity'
4
- import {Plugin as Plugin_2} from 'sanity'
5
-
6
- export declare interface RichDate {
7
- local: string
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
- export declare const richDate: Plugin_2<void>
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
- export declare interface RichDateDefinition extends Omit<
19
- ObjectDefinition,
20
- 'type' | 'fields' | 'options'
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
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', {
4
- value: true
5
- });
6
- var sanity = require('sanity');
7
- var jsxRuntime = require('react/jsx-runtime');
8
- var ui = require('@sanity/ui');
9
- var react = require('react');
10
- var dateFnsTz = require('date-fns-tz');
11
- var tzdb = require('@vvo/tzdb');
12
- var icons = require('@sanity/icons');
13
- const unlocalizeDateTime = (datetime, timezone) => {
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: tz.currentTimeFormat.split(" ")[0],
22
+ offset: offset ?? "",
33
23
  // all searchable text - this is transformed before being rendered in `<AutoComplete>`
34
- value: "".concat(tz.currentTimeFormat, " ").concat(tz.abbreviation, " ").concat(tz.name),
24
+ value: `${tz.currentTimeFormat} ${tz.abbreviation} ${tz.name}`,
35
25
  currentTimeOffsetInMinutes: tz.currentTimeOffsetInMinutes,
36
26
  group: tz.group
37
27
  };
38
- });
39
- var __defProp$1 = Object.defineProperty;
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
- onChange
65
- }
66
- } = props;
67
- const handleDateChange = react.useCallback(patch => {
68
- var _a2;
69
- const timezone = (_a2 = value == null ? void 0 : value.timezone) != null ? _a2 : Intl.DateTimeFormat().resolvedOptions().timeZone;
70
- const newDatetime = patch == null ? void 0 : patch.value;
71
- if (!newDatetime || !("type" in patch) || patch.type !== "set") {
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, Intl.DateTimeFormat().resolvedOptions().timeZone);
76
- const newUtcDateObject = dateFnsTz.zonedTimeToUtc(desiredDateTime, timezone);
77
- const newOffset = dateFnsTz.getTimezoneOffset(timezone, newUtcDateObject) / 60 / 1e3;
78
- const localDate = dateFnsTz.formatInTimeZone(newUtcDateObject, timezone, "yyyy-MM-dd'T'HH:mm:ssXXX");
79
- const patches = [];
80
- patches.push(sanity.set(newUtcDateObject.toISOString(), ["utc"]));
81
- patches.push(sanity.set(localDate, ["local"]));
82
- if (!(value == null ? void 0 : value.timezone)) {
83
- patches.push(sanity.set(timezone, ["timezone"]));
84
- }
85
- if ((value == null ? void 0 : value.offset) !== newOffset) {
86
- patches.push(sanity.set(newOffset, ["offset"]));
87
- }
88
- onChange(patches);
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
- const currentTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
104
- const label = (_g = (_e = (_c = (_a = allTimezones.find(tz => tz.name === timezone)) == null ? void 0 : _a.abbreviation) != null ? _c : (_b = allTimezones.find(tz => tz.group.includes(timezone))) == null ? void 0 : _b.abbreviation) != null ? _e : (_d = allTimezones.find(tz => tz.name === currentTimezone)) == null ? void 0 : _d.abbreviation) != null ? _g : (_f = allTimezones.find(tz => tz.group.includes(currentTimezone))) == null ? void 0 : _f.abbreviation;
105
- return /* @__PURE__ */jsxRuntime.jsx(ui.Button, {
106
- fontSize: 1,
107
- style: {
108
- width: "100%"
109
- },
110
- justify: "flex-start",
111
- icon: icons.EarthAmericasIcon,
112
- mode: "ghost",
113
- onClick,
114
- text: "".concat(label),
115
- "aria-label": "Select a timezone"
116
- });
117
- };
118
- const TimezoneSelector = props => {
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
- const currentTz = allTimezones.find(tz => tz.name === (value == null ? void 0 : value.timezone));
125
- const userTzName = Intl.DateTimeFormat().resolvedOptions().timeZone;
126
- const userTz = (_a = allTimezones.find(tz => tz.name === userTzName)) != null ? _a : allTimezones.find(tz => tz.group.includes(userTzName));
127
- const handleTimezoneChange = react.useCallback(selectedTz => {
128
- var _a2;
129
- const newTimezone = (_a2 = allTimezones.find(tz => tz.value === selectedTz)) != null ? _a2 : userTz;
130
- const timezonePatch = sanity.set(newTimezone.name, ["timezone"]);
131
- const patches = [timezonePatch];
132
- if (value == null ? void 0 : value.utc) {
133
- const desiredDateTime = unlocalizeDateTime(value.utc, value.timezone);
134
- const newUtcDateObject = dateFnsTz.zonedTimeToUtc(desiredDateTime, newTimezone.name);
135
- const newOffset = dateFnsTz.getTimezoneOffset(newTimezone.name, newUtcDateObject) / 60 / 1e3;
136
- const newLocalDate = dateFnsTz.formatInTimeZone(newUtcDateObject.toISOString(), newTimezone.name, "yyyy-MM-dd'T'HH:mm:ssXXX");
137
- patches.push(sanity.set(newUtcDateObject.toISOString(), ["utc"]));
138
- patches.push(sanity.set(newLocalDate, ["local"]));
139
- patches.push(sanity.set(newOffset, ["offset"]));
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, userTz, value]);
143
- return (
144
- // taken from Scheduled Publishing, again!
145
- // https://github.com/sanity-io/sanity-plugin-scheduled-publishing/blob/bb282e3df9a8a73df37fab8ee1fdd0e2430745be/src/components/dialogs/DialogTimeZone.tsx#L100
146
- /* @__PURE__ */
147
- jsxRuntime.jsx(ui.Box, {
148
- padding: 4,
149
- children: /* @__PURE__ */jsxRuntime.jsx(ui.Autocomplete, {
150
- fontSize: 2,
151
- icon: icons.SearchIcon,
152
- id: "timezone",
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
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
217
- const RichDateInput = props => {
218
- const {
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
- const localMember = members.find(member => member.kind === "field" && member.name === "local");
228
- const timezoneMember = members.find(member => member.kind === "field" && member.name === "timezone");
229
- const [timezoneSelectorOpen, setTimezoneSelectorOpen] = react.useState(false);
230
- const onClose = react.useCallback(() => setTimezoneSelectorOpen(false), []);
231
- const onOpen = react.useCallback(() => setTimezoneSelectorOpen(true), []);
232
- return /* @__PURE__ */jsxRuntime.jsxs(jsxRuntime.Fragment, {
233
- children: [/* @__PURE__ */jsxRuntime.jsxs(ui.Flex, {
234
- children: [/* @__PURE__ */jsxRuntime.jsx(ui.Box, {
235
- flex: [1, 2, 4],
236
- children: localMember && /* @__PURE__ */jsxRuntime.jsx(sanity.ObjectInputMember, __spreadProps(__spreadValues({}, props), {
237
- member: localMember,
238
- renderField: renderFieldProps => /* @__PURE__ */jsxRuntime.jsx(RelativeDateTimePicker, __spreadProps(__spreadValues({}, renderFieldProps), {
239
- dateValue: value,
240
- schemaType: __spreadProps(__spreadValues({}, renderFieldProps.schemaType), {
241
- options
242
- }),
243
- inputProps: __spreadProps(__spreadValues({}, renderFieldProps.inputProps), {
244
- onChange
245
- })
246
- }))
247
- }))
248
- }), /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
249
- flex: [1],
250
- marginLeft: [2, 2, 3, 4],
251
- marginTop: 2,
252
- children: timezoneMember && /* @__PURE__ */jsxRuntime.jsx(sanity.ObjectInputMember, __spreadProps(__spreadValues({}, props), {
253
- member: timezoneMember,
254
- renderInput: () => {
255
- var _a;
256
- return /* @__PURE__ */jsxRuntime.jsx(TimezoneButton, {
257
- onClick: onOpen,
258
- timezone: (_a = value == null ? void 0 : value.timezone) != null ? _a : ""
259
- });
260
- }
261
- }))
262
- })]
263
- }), timezoneSelectorOpen && /* @__PURE__ */jsxRuntime.jsx(ui.Dialog, {
264
- onClose,
265
- header: "Select a timezone",
266
- id: "timezone-select",
267
- width: 1,
268
- children: /* @__PURE__ */jsxRuntime.jsx(TimezoneSelector, {
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
- const richDateTypeName = "richDate";
276
- const richDateSchema = sanity.defineType({
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: [sanity.defineField({
191
+ fields: [defineField({
281
192
  name: "local",
282
193
  title: "Local",
283
194
  type: "string"
284
- }), sanity.defineField({
195
+ }), defineField({
285
196
  name: "utc",
286
197
  title: "UTC",
287
198
  type: "string"
288
- }), sanity.defineField({
199
+ }), defineField({
289
200
  name: "timezone",
290
201
  title: "Timezone",
291
202
  type: "string"
292
- }), sanity.defineField({
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
- exports.richDate = richDate;
217
+ export {
218
+ richDate
219
+ };
308
220
  //# sourceMappingURL=index.js.map