react-timezone-select 1.2.3-experimental.1 → 1.2.3-experimental.10

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/dist/index.js ADDED
@@ -0,0 +1,186 @@
1
+ // src/index.tsx
2
+ import * as React from "react";
3
+ import Select from "react-select";
4
+ import spacetime from "spacetime";
5
+ import soft from "timezone-soft";
6
+
7
+ // src/timezone-list.ts
8
+ var allTimezones = {
9
+ "Pacific/Midway": "Midway Island, Samoa",
10
+ "Pacific/Honolulu": "Hawaii",
11
+ "America/Juneau": "Alaska",
12
+ "America/Boise": "Mountain Time",
13
+ "America/Dawson": "Dawson, Yukon",
14
+ "America/Chihuahua": "Chihuahua, La Paz, Mazatlan",
15
+ "America/Phoenix": "Arizona",
16
+ "America/Chicago": "Central Time",
17
+ "America/Regina": "Saskatchewan",
18
+ "America/Mexico_City": "Guadalajara, Mexico City, Monterrey",
19
+ "America/Belize": "Central America",
20
+ "America/Detroit": "Eastern Time",
21
+ "America/Bogota": "Bogota, Lima, Quito",
22
+ "America/Caracas": "Caracas, La Paz",
23
+ "America/Santiago": "Santiago",
24
+ "America/St_Johns": "Newfoundland and Labrador",
25
+ "America/Sao_Paulo": "Brasilia",
26
+ "America/Tijuana": "Tijuana",
27
+ "America/Montevideo": "Montevideo",
28
+ "America/Argentina/Buenos_Aires": "Buenos Aires, Georgetown",
29
+ "America/Godthab": "Greenland",
30
+ "America/Los_Angeles": "Pacific Time",
31
+ "Atlantic/Azores": "Azores",
32
+ "Atlantic/Cape_Verde": "Cape Verde Islands",
33
+ GMT: "UTC",
34
+ "Europe/London": "Edinburgh, London",
35
+ "Europe/Dublin": "Dublin",
36
+ "Europe/Lisbon": "Lisbon",
37
+ "Africa/Casablanca": "Casablanca, Monrovia",
38
+ "Atlantic/Canary": "Canary Islands",
39
+ "Europe/Belgrade": "Belgrade, Bratislava, Budapest, Ljubljana, Prague",
40
+ "Europe/Sarajevo": "Sarajevo, Skopje, Warsaw, Zagreb",
41
+ "Europe/Brussels": "Brussels, Copenhagen, Madrid, Paris",
42
+ "Europe/Amsterdam": "Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna",
43
+ "Africa/Algiers": "West Central Africa",
44
+ "Europe/Bucharest": "Bucharest",
45
+ "Africa/Cairo": "Cairo",
46
+ "Europe/Helsinki": "Helsinki, Kiev, Riga, Sofia, Tallinn, Vilnius",
47
+ "Europe/Athens": "Athens, Minsk",
48
+ "Asia/Jerusalem": "Jerusalem",
49
+ "Africa/Harare": "Harare, Pretoria",
50
+ "Europe/Moscow": "Istanbul, Moscow, St. Petersburg, Volgograd",
51
+ "Asia/Kuwait": "Kuwait, Riyadh",
52
+ "Africa/Nairobi": "Nairobi",
53
+ "Asia/Baghdad": "Baghdad",
54
+ "Asia/Tehran": "Tehran",
55
+ "Asia/Dubai": "Abu Dhabi, Muscat",
56
+ "Asia/Baku": "Baku, Tbilisi, Yerevan",
57
+ "Asia/Kabul": "Kabul",
58
+ "Asia/Yekaterinburg": "Ekaterinburg",
59
+ "Asia/Karachi": "Islamabad, Karachi, Tashkent",
60
+ "Asia/Kolkata": "Chennai, Kolkata, Mumbai, New Delhi",
61
+ "Asia/Kathmandu": "Kathmandu",
62
+ "Asia/Dhaka": "Astana, Dhaka",
63
+ "Asia/Colombo": "Sri Jayawardenepura",
64
+ "Asia/Almaty": "Almaty, Novosibirsk",
65
+ "Asia/Rangoon": "Yangon Rangoon",
66
+ "Asia/Bangkok": "Bangkok, Hanoi, Jakarta",
67
+ "Asia/Krasnoyarsk": "Krasnoyarsk",
68
+ "Asia/Shanghai": "Beijing, Chongqing, Hong Kong SAR, Urumqi",
69
+ "Asia/Kuala_Lumpur": "Kuala Lumpur, Singapore",
70
+ "Asia/Taipei": "Taipei",
71
+ "Australia/Perth": "Perth",
72
+ "Asia/Irkutsk": "Irkutsk, Ulaanbaatar",
73
+ "Asia/Seoul": "Seoul",
74
+ "Asia/Tokyo": "Osaka, Sapporo, Tokyo",
75
+ "Asia/Yakutsk": "Yakutsk",
76
+ "Australia/Darwin": "Darwin",
77
+ "Australia/Adelaide": "Adelaide",
78
+ "Australia/Sydney": "Canberra, Melbourne, Sydney",
79
+ "Australia/Brisbane": "Brisbane",
80
+ "Australia/Hobart": "Hobart",
81
+ "Asia/Vladivostok": "Vladivostok",
82
+ "Pacific/Guam": "Guam, Port Moresby",
83
+ "Asia/Magadan": "Magadan, Solomon Islands, New Caledonia",
84
+ "Asia/Kamchatka": "Kamchatka, Marshall Islands",
85
+ "Pacific/Fiji": "Fiji Islands",
86
+ "Pacific/Auckland": "Auckland, Wellington",
87
+ "Pacific/Tongatapu": "Nuku'alofa"
88
+ };
89
+ var timezone_list_default = allTimezones;
90
+
91
+ // src/index.tsx
92
+ var TimezoneSelect = ({
93
+ value,
94
+ onBlur,
95
+ onChange,
96
+ labelStyle = "original",
97
+ timezones,
98
+ ...props
99
+ }) => {
100
+ if (!timezones)
101
+ timezones = timezone_list_default;
102
+ const getOptions = React.useMemo(() => {
103
+ return Object.entries(timezones).reduce((selectOptions, zone) => {
104
+ const now = spacetime.now(zone[0]);
105
+ const tz = now.timezone();
106
+ const tzStrings = soft(zone[0]);
107
+ let label = "";
108
+ let abbr = now.isDST() ? tzStrings[0].daylight?.abbr : tzStrings[0].standard?.abbr;
109
+ let altName = now.isDST() ? tzStrings[0].daylight?.name : tzStrings[0].standard?.name;
110
+ const min = tz.current.offset * 60;
111
+ const hr = `${min / 60 ^ 0}:` + (min % 60 === 0 ? "00" : Math.abs(min % 60));
112
+ const prefix = `(GMT${hr.includes("-") ? hr : `+${hr}`}) ${zone[1]}`;
113
+ switch (labelStyle) {
114
+ case "original":
115
+ label = prefix;
116
+ break;
117
+ case "altName":
118
+ label = `${prefix} ${altName?.length ? `(${altName})` : ""}`;
119
+ break;
120
+ case "abbrev":
121
+ label = `${prefix} ${abbr?.length < 5 ? `(${abbr})` : ""}`;
122
+ break;
123
+ default:
124
+ label = `${prefix}`;
125
+ }
126
+ selectOptions.push({
127
+ value: tz.name,
128
+ label,
129
+ offset: tz.current.offset,
130
+ abbrev: abbr,
131
+ altName
132
+ });
133
+ return selectOptions;
134
+ }, []).sort((a, b) => a.offset - b.offset);
135
+ }, [labelStyle, timezones]);
136
+ const handleChange = (tz) => {
137
+ onChange && onChange(tz);
138
+ };
139
+ const findFuzzyTz = (zone) => {
140
+ let currentTime = spacetime.now("GMT");
141
+ try {
142
+ currentTime = spacetime.now(zone);
143
+ } catch (err) {
144
+ return;
145
+ }
146
+ return getOptions.filter((tz) => tz.offset === currentTime.timezone().current.offset).map((tz) => {
147
+ let score = 0;
148
+ if (currentTime.timezones[tz.value.toLowerCase()] && !!currentTime.timezones[tz.value.toLowerCase()].dst === currentTime.timezone().hasDst) {
149
+ if (tz.value.toLowerCase().indexOf(currentTime.tz.substring(currentTime.tz.indexOf("/") + 1)) !== -1) {
150
+ score += 8;
151
+ }
152
+ if (tz.label.toLowerCase().indexOf(currentTime.tz.substring(currentTime.tz.indexOf("/") + 1)) !== -1) {
153
+ score += 4;
154
+ }
155
+ if (tz.value.toLowerCase().indexOf(currentTime.tz.substring(0, currentTime.tz.indexOf("/")))) {
156
+ score += 2;
157
+ }
158
+ score += 1;
159
+ } else if (tz.value === "GMT") {
160
+ score += 1;
161
+ }
162
+ return { tz, score };
163
+ }).sort((a, b) => b.score - a.score).map(({ tz }) => tz)[0];
164
+ };
165
+ const parseTimezone = (zone) => {
166
+ if (typeof zone === "object" && zone.value && zone.label)
167
+ return zone;
168
+ if (typeof zone === "string") {
169
+ return getOptions.find((tz) => tz.value === zone) || zone.indexOf("/") !== -1 && findFuzzyTz(zone);
170
+ } else if (zone.value && !zone.label) {
171
+ return getOptions.find((tz) => tz.value === zone.value);
172
+ }
173
+ };
174
+ return /* @__PURE__ */ React.createElement(Select, {
175
+ value: parseTimezone(value),
176
+ onChange: handleChange,
177
+ options: getOptions,
178
+ onBlur,
179
+ ...props
180
+ });
181
+ };
182
+ var src_default = TimezoneSelect;
183
+ export {
184
+ timezone_list_default as allTimezones,
185
+ src_default as default
186
+ };
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "react-timezone-select",
3
- "version": "1.2.3-experimental.1",
3
+ "version": "1.2.3-experimental.10",
4
4
  "description": "Usable, dynamic React Timezone Select",
5
5
  "scripts": {
6
6
  "start": "concurrently npm:start:example npm:build",
7
7
  "start:example": "cd example && npm start",
8
8
  "prepublish": "npm run build",
9
9
  "postpublish": "npm run build:example && npm run deploy",
10
+ "build2": "tsc",
10
11
  "build": "node build.cjs",
11
12
  "build:example": "cd example && npm run build",
12
13
  "deploy": "gh-pages -d example/build",
@@ -26,25 +27,12 @@
26
27
  "url": "https://github.com/ndom91/react-timezone-select/issues"
27
28
  },
28
29
  "license": "MIT",
29
- "keywords": [
30
- "react",
31
- "timezone",
32
- "select",
33
- "react-select"
34
- ],
35
- "files": [
36
- "dist/**/*",
37
- "package.json"
38
- ],
30
+ "keywords": ["react", "timezone", "select", "react-select"],
31
+ "files": ["dist/**/*", "package.json"],
39
32
  "type": "module",
40
- "main": "./dist/index.cjs",
33
+ "main": "./dist/index.js",
34
+ "module": "./dist/index.js",
41
35
  "types": "./dist/index.d.ts",
42
- "exports": {
43
- ".": {
44
- "import": "./dist/index.mjs",
45
- "require": "./dist/index.cjs"
46
- }
47
- },
48
36
  "peerDependencies": {
49
37
  "react": "^17.0.1 || ^16",
50
38
  "react-dom": "^17.0.1 || ^16"