@jobber/components 4.1.1 → 4.1.3-pre.14

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.
Files changed (96) hide show
  1. package/dist/Autocomplete/index.js +12 -12
  2. package/dist/Avatar/index.js +2 -2
  3. package/dist/{Avatar-89cfd0a6.js → Avatar-01c5ba8b.js} +3 -3
  4. package/dist/Banner/index.js +8 -8
  5. package/dist/Button/index.js +3 -3
  6. package/dist/Button-186ef2c1.js +57 -0
  7. package/dist/ButtonDismiss/index.js +4 -4
  8. package/dist/{ButtonDismiss-3fb1eaf9.js → ButtonDismiss-d2d16622.js} +1 -1
  9. package/dist/Card/index.js +6 -6
  10. package/dist/Card-c0f88c0f.js +93 -0
  11. package/dist/Checkbox/index.js +4 -4
  12. package/dist/Checkbox-1df46a4a.js +40 -0
  13. package/dist/Chips/InternalChipDismissible/hooks/useInternalChipDismissibleInput.d.ts +1 -1
  14. package/dist/Chips/index.js +11 -11
  15. package/dist/ConfirmationModal/index.js +11 -11
  16. package/dist/{ConfirmationModal-6a7beee2.js → ConfirmationModal-ac668c46.js} +3 -3
  17. package/dist/Content/index.js +2 -2
  18. package/dist/{Content-05df8f7f.js → Content-af82acba.js} +5 -5
  19. package/dist/DataDump/index.js +8 -8
  20. package/dist/DataTable/index.js +17 -17
  21. package/dist/DatePicker/index.js +4 -4
  22. package/dist/DatePicker-e085dff4.js +106 -0
  23. package/dist/DescriptionList/index.js +4 -4
  24. package/dist/Disclosure/index.js +5 -5
  25. package/dist/Divider/index.js +3 -3
  26. package/dist/Drawer/index.js +9 -9
  27. package/dist/Emphasis/index.js +3 -3
  28. package/dist/{Emphasis-23dc2a0a.js → Emphasis-53e963b5.js} +1 -1
  29. package/dist/FeatureSwitch/index.js +11 -11
  30. package/dist/Form/index.js +2 -2
  31. package/dist/FormField/index.js +8 -8
  32. package/dist/{FormField-79a0a375.js → FormField-aff52a1d.js} +21 -13
  33. package/dist/FormatEmail/index.js +3 -3
  34. package/dist/FormatFile/index.js +13 -13
  35. package/dist/FormatFile-42ea7a6a.js +105 -0
  36. package/dist/Gallery/index.js +16 -16
  37. package/dist/Heading/index.js +3 -3
  38. package/dist/{Heading-7b203f7f.js → Heading-8c6e4e0b.js} +1 -1
  39. package/dist/InlineLabel/index.js +4 -4
  40. package/dist/InputAvatar/index.js +10 -10
  41. package/dist/InputDate/index.js +9 -9
  42. package/dist/InputEmail/index.js +8 -8
  43. package/dist/InputFile/index.js +6 -6
  44. package/dist/{InputFile-5e0ed2b5.js → InputFile-e7c15211.js} +7 -7
  45. package/dist/InputGroup/index.js +3 -3
  46. package/dist/InputNumber/index.js +8 -8
  47. package/dist/InputPassword/index.js +8 -8
  48. package/dist/InputText/InputText.d.ts +74 -17
  49. package/dist/InputText/index.js +9 -9
  50. package/dist/{InputText-95ea24f9.js → InputText-90bf6056.js} +1 -1
  51. package/dist/InputTime/index.js +652 -812
  52. package/dist/InputValidation/index.js +4 -4
  53. package/dist/{InputValidation-97dd0dcf.js → InputValidation-e09f5d20.js} +4 -4
  54. package/dist/LightBox/index.js +5 -5
  55. package/dist/{LightBox-dd1afa97.js → LightBox-8472bc9d.js} +5 -5
  56. package/dist/List/index.js +13 -13
  57. package/dist/Markdown/index.js +7 -7
  58. package/dist/{Markdown-be2dcd0c.js → Markdown-5d86d6e7.js} +4 -4
  59. package/dist/Menu/index.js +4 -4
  60. package/dist/{Menu-d6a7d17b.js → Menu-b5e8d8f9.js} +5 -5
  61. package/dist/Modal/index.js +6 -6
  62. package/dist/{Modal-757e83fd.js → Modal-e41f9284.js} +8 -8
  63. package/dist/MultiSelect/index.js +8 -8
  64. package/dist/{Option-4b665afd.js → Option-9aa09e72.js} +1 -1
  65. package/dist/Page/index.js +11 -11
  66. package/dist/Popover/index.js +6 -6
  67. package/dist/ProgressBar/index.js +2 -2
  68. package/dist/ProgressBar-d3178aa9.js +28 -0
  69. package/dist/RadioGroup/index.js +5 -5
  70. package/dist/Select/index.js +9 -9
  71. package/dist/Spinner/index.js +2 -2
  72. package/dist/Spinner-35cee923.js +24 -0
  73. package/dist/StatusLabel/index.js +5 -5
  74. package/dist/Switch/index.js +3 -3
  75. package/dist/Switch-21d7093a.js +56 -0
  76. package/dist/Table/index.js +5 -5
  77. package/dist/Tabs/index.js +4 -4
  78. package/dist/Text/index.js +3 -3
  79. package/dist/{Text-7ce00adb.js → Text-4c04ddc3.js} +1 -1
  80. package/dist/Toast/index.js +5 -5
  81. package/dist/Tooltip/index.js +4 -4
  82. package/dist/{Tooltip-1090a43d.js → Tooltip-27720f96.js} +4 -4
  83. package/dist/Typography/index.js +2 -2
  84. package/dist/Typography-dd9717e7.js +62 -0
  85. package/dist/{tslib.es6-efe27175.js → tslib.es6-5b8768b7.js} +16 -13
  86. package/package.json +7 -7
  87. package/dist/Button-16e043ec.js +0 -57
  88. package/dist/Card-edab9c3c.js +0 -93
  89. package/dist/Checkbox-c1efc2f6.js +0 -40
  90. package/dist/DatePicker-0696b0f0.js +0 -106
  91. package/dist/FormatFile-3512f838.js +0 -105
  92. package/dist/ProgressBar-f028b159.js +0 -28
  93. package/dist/Spinner-ae4c8a85.js +0 -24
  94. package/dist/Switch-7ac32f7b.js +0 -56
  95. package/dist/Typography-9262511f.js +0 -62
  96. /package/dist/{style-inject.es-dcee06b6.js → style-inject.es-9d2f5f4e.js} +0 -0
@@ -2,883 +2,723 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var tslib_es6 = require('../tslib.es6-efe27175.js');
5
+ var tslib_es6 = require('../tslib.es6-5b8768b7.js');
6
6
  var React = require('react');
7
7
  var debounce = require('lodash/debounce');
8
8
  var temporal = require('@std-proposal/temporal');
9
- var FormField = require('../FormField-79a0a375.js');
9
+ var FormField = require('../FormField-aff52a1d.js');
10
10
  require('uuid');
11
11
  require('react-hook-form');
12
- require('../style-inject.es-dcee06b6.js');
12
+ require('../style-inject.es-9d2f5f4e.js');
13
13
  require('classnames');
14
- require('../Button-16e043ec.js');
14
+ require('../Button-186ef2c1.js');
15
15
  require('react-router-dom');
16
16
  require('../Icon-405a216c.js');
17
17
  require('@jobber/design');
18
- require('../Typography-9262511f.js');
19
- require('../Text-7ce00adb.js');
20
- require('../InputValidation-97dd0dcf.js');
18
+ require('../Typography-dd9717e7.js');
19
+ require('../Text-4c04ddc3.js');
20
+ require('../InputValidation-e09f5d20.js');
21
21
  require('framer-motion');
22
- require('../Spinner-ae4c8a85.js');
22
+ require('../Spinner-35cee923.js');
23
23
 
24
24
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
25
25
 
26
26
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
27
27
  var debounce__default = /*#__PURE__*/_interopDefaultLegacy(debounce);
28
28
 
29
- function getDefaultExportFromCjs (x) {
30
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
29
+ // https://stackoverflow.com/a/10199306/1611058
30
+ function get_time_support() {
31
+ var input = document.createElement('input');
32
+ input.setAttribute('type', 'time');
33
+ var notValid = 'not-a-time';
34
+ input.setAttribute('value', notValid);
35
+ return input.value !== notValid;
31
36
  }
32
37
 
33
- var supportsTime$2 = {exports: {}};
38
+ var timeSupport = get_time_support();
39
+ if (window) window.supportsTime = timeSupport;
34
40
 
35
- var supportsTime$1 = {exports: {}};
41
+ var supportsTime = timeSupport;
36
42
 
37
- (function (module) {
38
- // https://stackoverflow.com/a/10199306/1611058
39
- function get_time_support () {
40
- var input = document.createElement('input');
41
- input.setAttribute('type','time');
42
-
43
- var notValid = 'not-a-time';
44
- input.setAttribute('value', notValid);
45
-
46
- return (input.value !== notValid);
47
- }
48
-
49
- var timeSupport = get_time_support();
50
-
51
- if (window) window.supportsTime = timeSupport;
52
- if (module) module.exports = timeSupport;
53
- } (supportsTime$1));
43
+ function leading_zero(number) {
44
+ if (isNaN(number)) return number;
45
+ var purified = parseInt(number);
46
+ return purified < 10 ? '0' + purified : number;
47
+ }
54
48
 
55
- (function (module) {
56
- module.exports = supportsTime$1.exports;
57
- } (supportsTime$2));
49
+ function convert_to_24hr_time(timeString_12hr) {
50
+ if (/-/.test(timeString_12hr)) return '';
51
+ var isPM = timeString_12hr.indexOf('PM') > -1;
52
+ var timeResult = /^([0-9]{2})/.exec(timeString_12hr);
53
+ var hrs = timeResult ? parseInt(timeResult[1]) : '';
54
+ var newHrs;
55
+
56
+ if (hrs === 12) {
57
+ newHrs = isPM ? 12 : 0;
58
+ } else {
59
+ newHrs = isPM ? hrs + 12 : hrs;
60
+ }
61
+
62
+ var finalHrs = newHrs === 24 ? 0 : newHrs;
63
+ var timeRegEx = /^[0-9]{2}:([0-9]{2}) (AM|PM)/;
64
+ return timeString_12hr.replace(timeRegEx, leading_zero(finalHrs) + ':$1');
65
+ }
58
66
 
59
- var supportsTime = /*@__PURE__*/getDefaultExportFromCjs(supportsTime$2.exports);
67
+ function set_data_attribute($input, timeString_12hr) {
68
+ var filteredString = timeString_12hr.indexOf('-') > -1 ? '' : timeString_12hr;
69
+ var time24hr = convert_to_24hr_time(filteredString);
70
+ $input.setAttribute('data-value', time24hr);
71
+ }
60
72
 
61
- var timeInputPolyfill = {exports: {}};
73
+ function create_event(eventName) {
74
+ var event = document.createEvent('Event');
75
+ event.initEvent(eventName, true, true);
76
+ return event;
77
+ }
62
78
 
63
- var leading_zero$4 = function leading_zero (number) {
64
- if (isNaN(number)) return number;
65
- var purified = parseInt(number);
66
- return purified < 10 ? '0' + purified : number;
67
- };
79
+ var inputEvent = create_event('input');
80
+ var changeEvent = create_event('change');
81
+ function trigger_event($input, eventName) {
82
+ var event = {
83
+ input: inputEvent,
84
+ change: changeEvent
85
+ }[eventName];
86
+
87
+ if (can_trigger_change($input)) {
88
+ $input.dispatchEvent(event);
89
+ }
90
+ } // Browsers only send out input and change events if the time element has a full valid value
91
+
92
+ function can_trigger_change($input) {
93
+ return !/--/.test($input.value);
94
+ }
68
95
 
69
- var leading_zero$3 = leading_zero$4;
70
-
71
- var convert_to_24hr_time$1 = function convert_to_24hr_time (timeString_12hr) {
72
- if (/-/.test(timeString_12hr)) return '';
73
- var isPM = timeString_12hr.indexOf('PM') > -1;
74
- var timeResult = /^([0-9]{2})/.exec(timeString_12hr);
75
- var hrs = timeResult ? parseInt(timeResult[1]) : '';
76
- var newHrs;
77
- if (hrs === 12) {
78
- newHrs = isPM ? 12 : 0;
79
- } else {
80
- newHrs = isPM ? hrs + 12 : hrs;
81
- }
82
- var finalHrs = newHrs === 24 ? 0 : newHrs;
83
- var timeRegEx = /^[0-9]{2}:([0-9]{2}) (AM|PM)/;
84
- return timeString_12hr.replace(timeRegEx, leading_zero$3(finalHrs)+':$1');
85
- };
96
+ function trigger_both_events($input) {
97
+ // the event only ever fires if there is a full valid value available
98
+ trigger_event($input, 'input');
99
+ trigger_event($input, 'change');
100
+ }
86
101
 
87
- var convert_to_24hr_time = convert_to_24hr_time$1;
88
-
89
- var set_data_attribute$3 = function set_data_attribute($input, timeString_12hr){
90
- var filteredString = timeString_12hr.indexOf('-') > -1 ? '' : timeString_12hr;
91
- var time24hr = convert_to_24hr_time(filteredString);
92
- $input.setAttribute('data-value', time24hr);
93
- };
102
+ // I need to keep this separate from reset so that
103
+ // I can reset without attracting focus
104
+ function apply_default($input) {
105
+ $input.value = '--:-- --';
106
+ set_data_attribute($input, '');
107
+ trigger_both_events($input);
108
+ }
94
109
 
95
- var create_event$1 = function create_event(eventName){
96
- var event = document.createEvent('Event');
97
- event.initEvent(eventName, true, true);
98
- return event;
99
- };
110
+ function convert_number(number) {
111
+ return isNaN(number) ? number : parseInt(number);
112
+ }
100
113
 
101
- var create_event = create_event$1;
102
-
103
- var inputEvent = create_event('input');
104
- var changeEvent = create_event('change');
105
-
106
- var trigger_event$1 = function trigger_event($input, eventName) {
107
- var event = {
108
- input: inputEvent,
109
- change: changeEvent,
110
- }[eventName];
111
-
112
- if (can_trigger_change($input)) {
113
- $input.dispatchEvent(event);
114
- }
115
- };
116
-
117
- // Browsers only send out input and change events if the time element has a full valid value
118
- function can_trigger_change ($input) {
119
- return !/--/.test($input.value);
120
- }
121
-
122
- var trigger_event = trigger_event$1;
123
-
124
- // It seems that oninput and onchange are treated the same way by browsers :/
125
- var trigger_both_events$2 = function trigger_both_events($input) {
126
- // the event only ever fires if there is a full valid value available
127
- trigger_event($input, 'input');
128
- trigger_event($input,'change');
129
- };
114
+ function convert_hours_to_12hr_time(hours) {
115
+ return hours <= 12 ? hours === 0 ? 12 : hours : hours - 12;
116
+ }
130
117
 
131
- // I need to keep this separate from reset so that
132
- // I can reset without attracting focus
133
-
134
- var set_data_attribute$2 = set_data_attribute$3;
135
- var trigger_both_events$1 = trigger_both_events$2;
136
-
137
- var apply_default$1 = function apply_default ($input) {
138
- $input.value = '--:-- --';
139
- set_data_attribute$2($input, '');
140
- trigger_both_events$1($input);
141
- };
118
+ function convert_to_12hr_time(timeString_24hr) {
119
+ if (timeString_24hr === '') return '--:-- --';
120
+ var twentyFour_regex = /([0-9]{2})\:([0-9]{2})/;
121
+ var result = twentyFour_regex.exec(timeString_24hr);
122
+ var hrs_24 = convert_number(result[1]);
123
+ var min = result[2];
124
+ var hrs_12 = convert_hours_to_12hr_time(hrs_24);
125
+ var isPM = hrs_24 >= 12;
126
+ var mode = isPM ? 'PM' : 'AM';
127
+ return [leading_zero(hrs_12), ':', min, ' ', mode].join('');
128
+ }
142
129
 
143
- var convert_number$2 = function convert_number (number) {
144
- return isNaN(number) ? number : parseInt(number);
145
- };
130
+ function set_time($input, time_string_24hr) {
131
+ var twelveHr = convert_to_12hr_time(time_string_24hr);
132
+ $input.value = twelveHr;
133
+ set_data_attribute($input, time_string_24hr);
134
+ }
146
135
 
147
- var convert_hours_to_12hr_time$2 = function convert_hours_to_12hr_time (hours) {
148
- return hours <= 12 ? hours === 0 ? 12 : hours : hours - 12;
149
- };
136
+ function update_time($input) {
137
+ set_time($input, $input.value);
138
+ return $input;
139
+ }
150
140
 
151
- var convert_number$1 = convert_number$2;
152
- var convert_hours_to_12hr_time$1 = convert_hours_to_12hr_time$2;
153
- var leading_zero$2 = leading_zero$4;
154
-
155
- var convert_to_12hr_time$1 = function convert_to_12hr_time (timeString_24hr) {
156
- if (timeString_24hr === '') return '--:-- --';
157
- var twentyFour_regex = /([0-9]{2})\:([0-9]{2})/;
158
- var result = twentyFour_regex.exec(timeString_24hr);
159
- var hrs_24 = convert_number$1(result[1]);
160
- var min = result[2];
161
- var hrs_12 = convert_hours_to_12hr_time$1(hrs_24);
162
- var isPM = hrs_24 > 12;
163
- var mode = isPM ? 'PM' : 'AM';
164
- return [leading_zero$2(hrs_12), ':', min, ' ', mode].join('');
165
- };
141
+ // IE11 doesn't support Object.values()
142
+ function values(obj) {
143
+ var key_values = [];
166
144
 
167
- var convert_to_12hr_time = convert_to_12hr_time$1;
168
- var set_data_attribute$1 = set_data_attribute$3;
169
-
170
- var set_time$2 = function set_time($input, time_string_24hr) {
171
- var twelveHr = convert_to_12hr_time(time_string_24hr);
172
- $input.value = twelveHr;
173
- set_data_attribute$1($input, time_string_24hr);
174
- };
145
+ for (var key in obj) {
146
+ key_values.push(obj[key]);
147
+ }
175
148
 
176
- var set_time$1 = set_time$2;
177
-
178
- var update_time = function update_time($input) {
179
- set_time$1($input, $input.value);
180
- return $input;
181
- };
149
+ return key_values;
150
+ }
182
151
 
183
- // IE11 doesn't support Object.values()
184
- var values$1 = function values (obj) {
185
- var key_values = [];
186
- for (var key in obj) {
187
- key_values.push(obj[key]);
188
- }
189
- return key_values;
190
- };
152
+ function select_segment($input, segment) {
153
+ set_input_type();
154
+ var actions = {
155
+ hrs: select(0, 2),
156
+ min: select(3, 5),
157
+ mode: select(6, 8)
158
+ };
159
+ actions[segment]($input);
160
+
161
+ function set_input_type() {
162
+ var type = segment === 'mode' ? 'text' : 'tel';
163
+ $input.setAttribute('type', type);
164
+ }
165
+
166
+ function select(start, end) {
167
+ return function () {
168
+ $input.setSelectionRange(start, end);
169
+ };
170
+ }
171
+ }
191
172
 
192
- var select_segment$5 = function select_segment ($input, segment) {
193
-
194
- set_input_type();
195
-
196
- var actions = {
197
- hrs: select(0, 2),
198
- min: select(3, 5),
199
- mode: select(6, 8),
200
- };
201
-
202
- actions[segment]($input);
203
-
204
- function set_input_type() {
205
- var type = segment === 'mode' ? 'text' : 'tel';
206
- $input.setAttribute('type', type);
207
- }
208
-
209
- function select (start, end) {
210
- return function () {
211
- $input.setSelectionRange(start, end);
212
- }
213
- }
214
- };
173
+ var ranges = {
174
+ hrs: {
175
+ start: 0,
176
+ end: 2
177
+ },
178
+ min: {
179
+ start: 3,
180
+ end: 5
181
+ },
182
+ mode: {
183
+ start: 6,
184
+ end: 8
185
+ }
186
+ };
187
+
188
+ function get_selected_range($input) {
189
+ return {
190
+ start: $input.selectionStart,
191
+ end: $input.selectionEnd
192
+ };
193
+ }
215
194
 
216
- var ranges$2 = {
217
- hrs : { start: 0, end: 2 },
218
- min : { start: 3, end: 5 },
219
- mode : { start: 6, end: 8 },
220
- };
221
-
222
- var ranges_1 = ranges$2;
195
+ function get_current_segment($input) {
196
+ var selection = get_selected_range($input);
223
197
 
224
- var get_selected_range$1 = function get_selected_range ($input) {
225
- return { start: $input.selectionStart, end: $input.selectionEnd };
226
- };
198
+ for (var segment in ranges) {
199
+ var range = ranges[segment];
200
+ var aboveMin = range.start <= selection.start;
201
+ var belowMax = range.end >= selection.end;
227
202
 
228
- var ranges$1 = ranges_1;
229
- var get_selected_range = get_selected_range$1;
230
-
231
- var get_current_segment$9 = function get_current_segment ($input) {
232
- var selection = get_selected_range($input);
233
- for (var segment in ranges$1) {
234
- var range = ranges$1[segment];
235
- var aboveMin = range.start <= selection.start;
236
- var belowMax = range.end >= selection.end;
237
- if (aboveMin && belowMax) {
238
- return segment;
239
- }
240
- }
241
- return 'hrs';
242
- };
203
+ if (aboveMin && belowMax) {
204
+ return segment;
205
+ }
206
+ }
243
207
 
244
- var manual_entry_log$2 = [];
245
-
246
- function clear () {
247
- manual_entry_log$2 = [];
248
- }
249
-
250
- function add (entry) {
251
- manual_entry_log$2.push(entry);
252
- }
253
-
254
- function items(){
255
- return manual_entry_log$2;
256
- }
257
-
258
- var manual_entry_log_1 = {
259
- items: items,
260
- clear: clear,
261
- add: add,
262
- };
208
+ return 'hrs';
209
+ }
263
210
 
264
- var ranges = ranges_1;
265
-
266
- var segments$1 = Object.keys(ranges);
267
-
268
- var segments_1 = segments$1;
269
-
270
- var convert_number = convert_number$2;
271
-
272
- var get_values$4 = function get_values ($input, timeString) {
273
- var value = timeString ? timeString : $input.value;
274
- var regEx = /([0-9-]{1,2})\:([0-9-]{1,2})\s?(AM|PM|\-\-)?/;
275
- var result = regEx.exec(value);
276
-
277
- return {
278
- hrs: convert_number(result[1]),
279
- min: convert_number(result[2]),
280
- mode: result[3],
281
- }
282
- };
211
+ var manual_entry_log = [];
283
212
 
284
- var get_current_segment$8 = get_current_segment$9;
285
- var get_values$3 = get_values$4;
286
-
287
- var update_a11y$5 = function update_a11y ($input, announcementArray) {
288
- // Timeout helps ensure that the input has stabilized
289
- setTimeout(function(){
290
- var current_segment = get_current_segment$8($input);
291
- var values = get_values$3($input);
292
- var value = values[current_segment];
293
- var finalValue = value == '--' ? 'blank' : value;
294
-
295
- var segmentName = {
296
- hrs: 'Hours',
297
- min: 'Minutes',
298
- mode: 'AM/PM'
299
- }[current_segment];
300
-
301
- var announcements = {
302
- initial: '$label grouping $fullValue.',
303
- select: '$segmentName spin button $segmentValue.',
304
- update: '$segmentValue.',
305
- };
306
-
307
- var textArray = announcementArray.map(function(providedString){
308
- if (announcements[providedString]) {
309
- return announcements[providedString];
310
- }
311
- return providedString;
312
- });
313
-
314
- var fullValue = $input.value.replace(/--/g,'blank');
315
-
316
- var html = '<p>' + textArray.join('</p><p>') + '</p>';
317
- html = html.replace(/\$label/g, $input.polyfill.label);
318
- html = html.replace(/\$segmentName/g, segmentName);
319
- html = html.replace(/\$segmentValue/g, finalValue);
320
- html = html.replace(/\$fullValue/g, fullValue);
321
-
322
- $input.polyfill.$a11y.innerHTML = html;
323
- }, 1);
324
- };
213
+ function clear() {
214
+ manual_entry_log = [];
215
+ }
325
216
 
326
- var get_current_segment$7 = get_current_segment$9;
327
- var select_segment$4 = select_segment$5;
328
-
329
- var manual_entry_log$1 = manual_entry_log_1;
330
- var segments = segments_1;
331
-
332
- var update_a11y$4 = update_a11y$5;
333
-
334
- var traverse$2 = function traverse ($input, direction) {
335
- var segment = get_current_segment$7($input);
336
-
337
- var modifier = direction === 'next' ? 1 : -1;
338
- var next_segment_index = segments.indexOf(segment) + modifier;
339
-
340
- var next_segment = {
341
- next: segments[next_segment_index] || 'mode',
342
- prev: next_segment_index < 0 ? 'hrs' : segments[next_segment_index],
343
- }[direction];
344
-
345
- select_segment$4($input, next_segment);
346
- manual_entry_log$1.clear();
347
- update_a11y$4($input, ['select']);
348
- };
217
+ function add(entry) {
218
+ manual_entry_log.push(entry);
219
+ }
349
220
 
350
- var traverse$1 = traverse$2;
351
-
352
- var next_segment$3 = function next_segment ($input) {
353
- traverse$1($input, 'next');
354
- };
221
+ function items() {
222
+ return manual_entry_log;
223
+ }
355
224
 
356
- var traverse = traverse$2;
357
-
358
- var prev_segment$2 = function prev_segment ($input) {
359
- traverse($input, 'prev');
225
+ var manual_entry_log$1 = {
226
+ items: items,
227
+ clear: clear,
228
+ add: add
360
229
  };
361
230
 
362
- var get_current_segment$6 = get_current_segment$9;
363
- var select_segment$3 = select_segment$5;
364
-
365
- var select_cursor_segment$1 = function select_cursor_segment ($input) {
366
- var current_segment = get_current_segment$6($input);
367
- select_segment$3($input, current_segment);
368
- };
231
+ var segments = Object.keys(ranges);
369
232
 
370
- var apply_default = apply_default$1;
371
- var select_segment$2 = select_segment$5;
372
-
373
- var reset$1 = function reset ($input) {
374
- apply_default($input);
375
- select_segment$2($input, 'hrs');
376
- };
233
+ function get_values($input, timeString) {
234
+ var value = timeString ? timeString : $input.value;
235
+ var regEx = /([0-9-]{1,2})\:([0-9-]{1,2})\s?(AM|PM|\-\-)?/;
236
+ var result = regEx.exec(value);
237
+ return {
238
+ hrs: convert_number(result[1]),
239
+ min: convert_number(result[2]),
240
+ mode: result[3]
241
+ };
242
+ }
377
243
 
378
- var get_values$2 = get_values$4;
379
- var leading_zero$1 = leading_zero$4;
380
- var select_segment$1 = select_segment$5;
381
- var set_data_attribute = set_data_attribute$3;
382
- var trigger_both_events = trigger_both_events$2;
383
-
384
- var set_segment$5 = function set_segment ($input, segment, value) {
385
- var values = get_values$2($input);
386
- values[segment] = value;
387
- var newInputVal = [
388
- leading_zero$1(values.hrs),':',
389
- leading_zero$1(values.min),' ',
390
- values.mode
391
- ].join('');
392
- $input.value = newInputVal;
393
- select_segment$1($input, segment);
394
- set_data_attribute($input, newInputVal);
395
- trigger_both_events($input);
396
- };
244
+ function update_a11y($input, announcementArray) {
245
+ // Timeout helps ensure that the input has stabilized
246
+ setTimeout(function () {
247
+ var current_segment = get_current_segment($input);
248
+ var values = get_values($input);
249
+ var value = values[current_segment];
250
+ var finalValue = value == '--' ? 'blank' : value;
251
+ var segmentName = {
252
+ hrs: 'Hours',
253
+ min: 'Minutes',
254
+ mode: 'AM/PM'
255
+ }[current_segment];
256
+ var announcements = {
257
+ initial: '$label grouping $fullValue.',
258
+ select: '$segmentName spin button $segmentValue.',
259
+ update: '$segmentValue.'
260
+ };
261
+ var textArray = announcementArray.map(function (providedString) {
262
+ if (announcements[providedString]) {
263
+ return announcements[providedString];
264
+ }
265
+
266
+ return providedString;
267
+ });
268
+ var fullValue = $input.value.replace(/--/g, 'blank');
269
+ var html = '<p>' + textArray.join('</p><p>') + '</p>';
270
+ html = html.replace(/\$label/g, $input.polyfill.label);
271
+ html = html.replace(/\$segmentName/g, segmentName);
272
+ html = html.replace(/\$segmentValue/g, finalValue);
273
+ html = html.replace(/\$fullValue/g, fullValue);
274
+ $input.polyfill.$a11y.innerHTML = html;
275
+ }, 1);
276
+ }
397
277
 
398
- var all_number_keys$2 = [
399
- // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
400
- 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
401
- 96, 97, 98, 99,100,101,102,103,104,105
402
- ];
403
-
404
- var all_number_keys_1 = all_number_keys$2;
405
-
406
- var all_number_keys$1 = all_number_keys_1;
407
-
408
- var sorted_number_keys$1 = {};
409
- // sorted_number_keys = { 48: 0, 49: 1, 96: 0, 97: 1, ... };
410
- all_number_keys$1.forEach(function(key, index) {
411
- var number_val = index > 9 ? index - 10 : index;
412
- sorted_number_keys$1[key] = number_val;
413
- });
414
-
415
- var sorted_number_keys_1 = sorted_number_keys$1;
416
-
417
- var get_current_segment$5 = get_current_segment$9;
418
- var set_segment$4 = set_segment$5;
419
- var next_segment$2 = next_segment$3;
420
-
421
- var manual_entry_log = manual_entry_log_1;
422
- var sorted_number_keys = sorted_number_keys_1;
423
-
424
- var manual_number_entry$1 = function manual_number_entry($input, key) {
425
- var key_value = sorted_number_keys[key];
426
- var segment = get_current_segment$5($input);
427
-
428
- if (segment !== 'mode') {
429
- var entry_count = manual_entry_log.items().length;
430
-
431
- var upper_limits = {
432
- hrs: [1,2],
433
- min: [5,9],
434
- };
435
- var limit = upper_limits[segment][entry_count];
436
-
437
- if (entry_count < 2) {
438
- manual_entry_log.add(key_value);
439
- }
440
-
441
- var full_limit = parseInt(upper_limits[segment].join(''));
442
- var full_entry = parseInt(manual_entry_log.items().join(''));
443
-
444
- if (full_limit >= full_entry) {
445
- set_segment$4($input, segment, full_entry);
446
- }
447
-
448
- var at_limit = key_value > limit || manual_entry_log.items().length === 2;
449
-
450
- if (at_limit) {
451
- next_segment$2($input);
452
- }
453
- }
454
- };
278
+ function traverse($input, direction) {
279
+ var segment = get_current_segment($input);
280
+ var modifier = direction === 'next' ? 1 : -1;
281
+ var next_segment_index = segments.indexOf(segment) + modifier;
282
+ var next_segment = {
283
+ next: segments[next_segment_index] || 'mode',
284
+ prev: next_segment_index < 0 ? 'hrs' : segments[next_segment_index]
285
+ }[direction];
286
+ select_segment($input, next_segment);
287
+ manual_entry_log$1.clear();
288
+ update_a11y($input, ['select']);
289
+ }
455
290
 
456
- var set_segment$3 = set_segment$5;
457
- var update_a11y$3 = update_a11y$5;
458
-
459
- var clear_segment$1 = function clear_segment ($input, segment) {
460
- set_segment$3($input, segment, '--');
461
- update_a11y$3($input, ['update']);
462
- };
291
+ function next_segment($input) {
292
+ traverse($input, 'next');
293
+ }
463
294
 
464
- var get_values$1 = get_values$4;
465
- var set_segment$2 = set_segment$5;
466
-
467
- var switch_mode$2 = function switch_mode ($input, default_mode) {
468
- default_mode = default_mode || 'AM';
469
- var current_mode = get_values$1($input).mode;
470
- var new_mode = {
471
- '--' : default_mode,
472
- 'AM' : 'PM',
473
- 'PM' : 'AM',
474
- }[current_mode];
475
- set_segment$2($input, 'mode', new_mode);
476
- };
295
+ function prev_segment($input) {
296
+ traverse($input, 'prev');
297
+ }
477
298
 
478
- var get_values = get_values$4;
479
- var convert_hours_to_12hr_time = convert_hours_to_12hr_time$2;
480
- var leading_zero = leading_zero$4;
481
- var set_segment$1 = set_segment$5;
482
-
483
- var nudge_time_segment$2 = function nudge_time_segment ($input, segment, direction) {
484
- var current_values = get_values($input);
485
- var time;
486
-
487
- var modifier = direction === 'up' ? 1 : -1;
488
-
489
- if (current_values[segment] === '--') {
490
- var current_time = new Date();
491
- time = {
492
- hrs: convert_hours_to_12hr_time(current_time.getHours()),
493
- min: current_time.getMinutes(),
494
- };
495
- } else {
496
- var minutes = {
497
- up : current_values.min < 59 ? current_values.min + modifier : 0,
498
- down : current_values.min === 0 ? 59 : current_values.min + modifier,
499
- };
500
- time = {
501
- hrs: convert_hours_to_12hr_time(current_values.hrs + modifier),
502
- min: minutes[direction],
503
- };
504
- }
505
-
506
- set_segment$1($input, segment, leading_zero(time[segment]) );
507
- };
299
+ function select_cursor_segment($input) {
300
+ var current_segment = get_current_segment($input);
301
+ select_segment($input, current_segment);
302
+ }
508
303
 
509
- var switch_mode$1 = switch_mode$2;
510
- var nudge_time_segment$1 = nudge_time_segment$2;
511
- var update_a11y$2 = update_a11y$5;
512
-
513
- var increment$1 = function increment ($input, segment) {
514
- if (segment === 'mode') {
515
- switch_mode$1($input, 'AM');
516
- } else {
517
- nudge_time_segment$1($input, segment, 'up');
518
- }
519
- update_a11y$2($input, ['update']);
520
- };
304
+ function reset($input) {
305
+ apply_default($input);
306
+ select_segment($input, 'hrs');
307
+ }
521
308
 
522
- var get_current_segment$4 = get_current_segment$9;
523
- var increment = increment$1;
524
-
525
- var increment_current_segment$1 = function increment_current_segment ($input) {
526
- var current_segment = get_current_segment$4($input);
527
- increment($input, current_segment);
528
- };
309
+ function set_segment($input, segment, value) {
310
+ var values = get_values($input);
311
+ values[segment] = value;
312
+ var newInputVal = [leading_zero(values.hrs), ':', leading_zero(values.min), ' ', values.mode].join('');
313
+ $input.value = newInputVal;
314
+ select_segment($input, segment);
315
+ set_data_attribute($input, newInputVal);
316
+ trigger_both_events($input);
317
+ }
529
318
 
530
- var switch_mode = switch_mode$2;
531
- var nudge_time_segment = nudge_time_segment$2;
532
- var update_a11y$1 = update_a11y$5;
533
-
534
- var decrement$1 = function decrement ($input, segment) {
535
- if (segment === 'mode') {
536
- switch_mode($input, 'PM');
537
- } else {
538
- nudge_time_segment($input, segment, 'down');
539
- }
540
- update_a11y$1($input, ['update']);
541
- };
319
+ /*eslint indent: 0 */
320
+ // prettier-ignore
321
+ var all_number_keys = [// 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
322
+ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105];
542
323
 
543
- var get_current_segment$3 = get_current_segment$9;
544
- var decrement = decrement$1;
545
-
546
- var decrement_current_segment$1 = function decrement_current_segment ($input){
547
- var current_segment = get_current_segment$3($input);
548
- decrement($input, current_segment);
549
- };
324
+ var sorted_number_keys = {}; // sorted_number_keys = { 48: 0, 49: 1, 96: 0, 97: 1, ... };
550
325
 
551
- var get_current_segment$2 = get_current_segment$9;
552
- var set_segment = set_segment$5;
553
-
554
- var set_mode$1 = function set_mode ($input, type) {
555
- var segment = get_current_segment$2($input);
556
- if (segment === 'mode') {
557
- set_segment($input, segment, type);
558
- }
559
- };
326
+ all_number_keys.forEach(function (key, index) {
327
+ var number_val = index > 9 ? index - 10 : index;
328
+ sorted_number_keys[key] = number_val;
329
+ });
560
330
 
561
- var switch_to_data_value$1 = function($input) {
562
- var replacementVal = $input.dataset.value;
563
- $input.value = replacementVal;
564
- };
331
+ function manual_number_entry($input, key) {
332
+ var key_value = sorted_number_keys[key];
333
+ var segment = get_current_segment($input);
565
334
 
566
- var switch_to_data_value = switch_to_data_value$1;
567
- var set_time = set_time$2;
568
-
569
- var switch_times$1 = function switch_times ($input, format) {
570
- var is12hr = /\s/.test($input.value);
571
-
572
- if (format != 12 && format != 24) {
573
- format = is12hr ? 24 : 12;
574
- }
575
-
576
- var actions = {
577
- 12: function(){
578
- if (!is12hr) {
579
- set_time($input, $input.dataset.value);
580
- }
581
- },
582
- 24: function(){
583
- if (is12hr) {
584
- switch_to_data_value($input);
585
- }
586
- }
587
- };
588
- actions[format]();
589
- };
335
+ if (segment !== 'mode') {
336
+ var entry_count = manual_entry_log$1.items().length;
337
+ var upper_limits = {
338
+ hrs: [1, 2],
339
+ min: [5, 9]
340
+ };
341
+ var limit = upper_limits[segment][entry_count];
590
342
 
591
- var get_current_segment$1 = get_current_segment$9;
592
- var prev_segment$1 = prev_segment$2;
593
- var next_segment$1 = next_segment$3;
594
-
595
- var handle_tab$1 = function handle_tab($input, e) {
596
- var current_segment = get_current_segment$1($input);
597
- var backwards_and_first = e.shiftKey && current_segment === 'hrs';
598
- var forwards_and_last = !e.shiftKey && current_segment === 'mode';
599
-
600
- if (!backwards_and_first && !forwards_and_last) {
601
- e.preventDefault();
602
- if (e.shiftKey) {
603
- prev_segment$1($input);
604
- } else {
605
- next_segment$1($input);
606
- }
607
- }
608
- };
343
+ if (entry_count < 2) {
344
+ manual_entry_log$1.add(key_value);
345
+ }
346
+
347
+ var full_limit = parseInt(upper_limits[segment].join(''));
348
+ var full_entry = parseInt(manual_entry_log$1.items().join(''));
349
+
350
+ if (full_limit >= full_entry) {
351
+ set_segment($input, segment, full_entry);
352
+ }
353
+
354
+ var at_limit = key_value > limit || manual_entry_log$1.items().length === 2;
355
+
356
+ if (at_limit) {
357
+ next_segment($input);
358
+ }
359
+ }
360
+ }
361
+
362
+ function clear_segment($input, segment) {
363
+ set_segment($input, segment, '--');
364
+ update_a11y($input, ['update']);
365
+ }
366
+
367
+ function switch_mode($input, default_mode) {
368
+ default_mode = default_mode || 'AM';
369
+ var current_mode = get_values($input).mode;
370
+ var new_mode = {
371
+ '--': default_mode,
372
+ AM: 'PM',
373
+ PM: 'AM'
374
+ }[current_mode];
375
+ set_segment($input, 'mode', new_mode);
376
+ }
377
+
378
+ function nudge_time_segment($input, segment, direction) {
379
+ var current_values = get_values($input);
380
+ var time;
381
+ var modifier = direction === 'up' ? 1 : -1;
609
382
 
610
- var named_keys$1 = {
611
- ArrowDown: 40,
612
- ArrowRight: 39,
613
- ArrowUp: 38,
614
- ArrowLeft: 37,
615
- Backspace: 8,
616
- Delete: 46,
617
- Tab: 9,
618
- Shift: 16,
619
- Escape: 27,
620
- a: 65,
621
- p: 80,
622
- };
623
-
624
- var named_keys_1 = named_keys$1;
625
-
626
- var values = values$1;
627
-
628
- var select_segment = select_segment$5;
629
-
630
- var next_segment = next_segment$3;
631
- var prev_segment = prev_segment$2;
632
- var select_cursor_segment = select_cursor_segment$1;
633
-
634
- var get_current_segment = get_current_segment$9;
635
-
636
- var reset = reset$1;
637
- var manual_number_entry = manual_number_entry$1;
638
- var clear_segment = clear_segment$1;
639
- var increment_current_segment = increment_current_segment$1;
640
- var decrement_current_segment = decrement_current_segment$1;
641
- var set_mode = set_mode$1;
642
- var switch_times = switch_times$1;
643
-
644
- var handle_tab = handle_tab$1;
645
-
646
- var all_number_keys = all_number_keys_1;
647
- var named_keys = named_keys_1;
648
-
649
- var update_a11y = update_a11y$5;
650
-
651
- var bind_events = function bind_events ($input) {
652
-
653
- var shiftKey = false;
654
-
655
- document.addEventListener('keydown', function(e){
656
- shiftKey = e.shiftKey;
657
- });
658
- document.addEventListener('keyup', function(e){
659
- shiftKey = e.shiftKey;
660
- });
661
-
662
- if ($input.form) {
663
- $input.form.addEventListener('submit', function(){
664
- auto_swap($input);
665
- });
666
- }
667
-
668
- var focused_via_click = false;
669
-
670
- $input.addEventListener('mousedown', function(){
671
- focused_via_click = true;
672
- });
673
-
674
- // Turns the IE clear button into a reset button
675
- $input.addEventListener('mouseup', function(){
676
- setTimeout(function(){
677
- if ($input.value === '') reset($input);
678
- }, 1);
679
- });
680
-
681
- $input.addEventListener('click', function(e){
682
- select_cursor_segment($input);
683
- });
684
-
685
- $input.addEventListener('blur', function(){
686
- $input.dataset.value;
687
- focused_via_click = false;
688
- });
689
-
690
- $input.addEventListener('focus', function(e){
691
- if (!focused_via_click) {
692
- e.preventDefault();
693
- var segment = shiftKey ? 'mode' : 'hrs';
694
- select_segment($input, segment);
695
- }
696
- update_a11y($input, [
697
- 'initial',
698
- 'select'
699
- ]);
700
- });
701
-
702
- $input.addEventListener('keydown', function(e) {
703
- var is_enter_key = e.which === 13;
704
- if (is_enter_key) return true;
705
-
706
- var is_number_key = all_number_keys.indexOf(e.which) > -1;
707
- var is_named_key = values(named_keys).indexOf(e.which) > -1;
708
- var is_arrow_key = [named_keys.ArrowDown, named_keys.ArrowRight, named_keys.ArrowUp, named_keys.ArrowLeft].indexOf(e.which) > -1;
709
- var is_mode_key = [named_keys.a, named_keys.p].indexOf(e.which) > -1;
710
- var is_delete_key = [named_keys.Delete, named_keys.Backspace].indexOf(e.which) > -1;
711
-
712
- if (!is_named_key || is_arrow_key || is_number_key || is_mode_key || is_delete_key) { e.preventDefault(); }
713
-
714
- if (is_number_key) {
715
- manual_number_entry($input, e.which);
716
- }
717
-
718
- if (is_delete_key) {
719
- var segment = get_current_segment($input);
720
- clear_segment($input, segment);
721
- }
722
-
723
- switch (e.which) {
724
- case named_keys.ArrowRight: next_segment($input); break;
725
- case named_keys.ArrowLeft: prev_segment($input); break;
726
- case named_keys.ArrowUp: increment_current_segment($input); break;
727
- case named_keys.ArrowDown: decrement_current_segment($input); break;
728
- case named_keys.Escape: reset($input); break;
729
- case named_keys.a: set_mode($input, 'AM'); break;
730
- case named_keys.p: set_mode($input, 'PM'); break;
731
- case named_keys.Tab: handle_tab($input, e); break;
732
- }
733
- });
734
- };
735
-
736
- function auto_swap($input) {
737
- if ($input.polyfill.autoSwap) {
738
- switch_times($input, 24);
739
- setTimeout(function(){
740
- switch_times($input, 12);
741
- }, 1);
742
- }
743
- }
744
-
745
- // selector is optional, it allows for an early exit
746
- var get_ancestors$1 = function ($input, selectorString) {
747
- var $elem = $input;
748
-
749
- // https://stackoverflow.com/a/8729274/1611058
750
- var ancestors = [];
751
- while ($elem) {
752
- ancestors.push($elem);
753
- var matchesSelector = $elem.msMatchesSelector ?
754
- $elem.msMatchesSelector(selectorString) :
755
- $elem.matches(selectorString);
756
- if (matchesSelector) {
757
- return ancestors;
758
- }
759
- $elem = $elem.parentElement;
760
- }
761
-
762
- return ancestors;
383
+ if (current_values[segment] === '--') {
384
+ var current_time = new Date();
385
+ time = {
386
+ hrs: convert_hours_to_12hr_time(current_time.getHours()),
387
+ min: current_time.getMinutes()
388
+ };
389
+ } else {
390
+ var minutes = {
391
+ up: current_values.min < 59 ? current_values.min + modifier : 0,
392
+ down: current_values.min === 0 ? 59 : current_values.min + modifier
393
+ };
394
+ time = {
395
+ hrs: convert_hours_to_12hr_time(current_values.hrs + modifier),
396
+ min: minutes[direction]
397
+ };
398
+ }
399
+
400
+ set_segment($input, segment, leading_zero(time[segment]));
401
+ }
402
+
403
+ function increment($input, segment) {
404
+ if (segment === 'mode') {
405
+ switch_mode($input, 'AM');
406
+ } else {
407
+ nudge_time_segment($input, segment, 'up');
408
+ }
409
+
410
+ update_a11y($input, ['update']);
411
+ }
412
+
413
+ function increment_current_segment($input) {
414
+ var current_segment = get_current_segment($input);
415
+ increment($input, current_segment);
416
+ }
417
+
418
+ function decrement($input, segment) {
419
+ if (segment === 'mode') {
420
+ switch_mode($input, 'PM');
421
+ } else {
422
+ nudge_time_segment($input, segment, 'down');
423
+ }
424
+
425
+ update_a11y($input, ['update']);
426
+ }
427
+
428
+ function decrement_current_segment($input) {
429
+ var current_segment = get_current_segment($input);
430
+ decrement($input, current_segment);
431
+ }
432
+
433
+ function set_mode($input, type) {
434
+ var segment = get_current_segment($input);
435
+
436
+ if (segment === 'mode') {
437
+ set_segment($input, segment, type);
438
+ }
439
+ }
440
+
441
+ var switch_to_data_value = function ($input) {
442
+ var replacementVal = $input.dataset.value;
443
+ $input.value = replacementVal;
763
444
  };
764
445
 
765
- var get_ancestors = get_ancestors$1;
766
-
767
- var get_label = function get_label ($input) {
768
-
769
- var labelText =
770
- aria_labelledby($input) ||
771
- aria_label($input) ||
772
- for_attribute($input) ||
773
- label_wrapper_element($input) ||
774
- title_attribute($input);
775
-
776
- if (labelText) return labelText;
777
-
778
- console.error('Label text for input not found.', $input);
779
- throw new Error('Cannot polyfill time input due to a missing label.');
780
- };
781
-
782
- function aria_labelledby($input){
783
- var ariaLabelByID = $input.getAttribute('aria-labelledby');
784
- if (ariaLabelByID) {
785
- var $ariaLabelBy = document.getElementById(ariaLabelByID);
786
- if ($ariaLabelBy) return $ariaLabelBy.textContent;
787
- }
788
- return false;
789
- }
790
-
791
- function aria_label($input){
792
- var ariaLabel = $input.getAttribute('aria-label');
793
- if (ariaLabel) return ariaLabel;
794
- return false;
795
- }
796
-
797
- function for_attribute($input){
798
- if ($input.id) {
799
- var $forLabel = document.querySelector('label[for="'+$input.id+'"]');
800
- if ($forLabel) return $forLabel.textContent;
801
- }
802
- return false;
803
- }
804
-
805
- function label_wrapper_element($input){
806
- var ancestors = get_ancestors($input, 'label');
807
- var $parentLabel = ancestors[ancestors.length - 1];
808
- if ($parentLabel.nodeName == 'LABEL') return $parentLabel.textContent;
809
- return false
810
- }
811
-
812
- function title_attribute($input){
813
- var titleLabel = $input.getAttribute('title');
814
- if (titleLabel) return titleLabel;
815
- return false
816
- }
817
-
818
- var create_a11y_block = function create_accessibility_block () {
819
- var $block = document.createElement('div');
820
- $block.setAttribute('aria-live', 'assertive');
821
- $block.setAttribute('style', 'position: absolute; opacity: 0; height: 0; width: 0; overflow: hidden; pointer-events: none;');
822
- $block.classList.add('time-input-polyfill-accessibility-block');
823
- document.querySelector('body').appendChild($block);
824
- return $block;
446
+ function switch_times($input, format) {
447
+ var is12hr = /\s/.test($input.value);
448
+
449
+ if (format != 12 && format != 24) {
450
+ format = is12hr ? 24 : 12;
451
+ }
452
+
453
+ var actions = {
454
+ 12: function _() {
455
+ if (!is12hr) {
456
+ set_time($input, $input.dataset.value);
457
+ }
458
+ },
459
+ 24: function _() {
460
+ if (is12hr) {
461
+ switch_to_data_value($input);
462
+ }
463
+ }
464
+ };
465
+ actions[format]();
466
+ }
467
+
468
+ function handle_tab($input, e) {
469
+ var current_segment = get_current_segment($input);
470
+ var backwards_and_first = e.shiftKey && current_segment === 'hrs';
471
+ var forwards_and_last = !e.shiftKey && current_segment === 'mode';
472
+
473
+ if (!backwards_and_first && !forwards_and_last) {
474
+ e.preventDefault();
475
+
476
+ if (e.shiftKey) {
477
+ prev_segment($input);
478
+ } else {
479
+ next_segment($input);
480
+ }
481
+ }
482
+ }
483
+
484
+ var named_keys = {
485
+ ArrowDown: 40,
486
+ ArrowRight: 39,
487
+ ArrowUp: 38,
488
+ ArrowLeft: 37,
489
+ Backspace: 8,
490
+ Delete: 46,
491
+ Tab: 9,
492
+ Shift: 16,
493
+ Escape: 27,
494
+ a: 65,
495
+ p: 80
496
+ };
497
+
498
+ function bind_events($input) {
499
+ var shiftKey = false;
500
+ document.addEventListener('keydown', function (e) {
501
+ shiftKey = e.shiftKey;
502
+ });
503
+ document.addEventListener('keyup', function (e) {
504
+ shiftKey = e.shiftKey;
505
+ });
506
+
507
+ if ($input.form) {
508
+ $input.form.addEventListener('submit', function () {
509
+ auto_swap($input);
510
+ });
511
+ }
512
+
513
+ var focused_via_click = false;
514
+ $input.addEventListener('mousedown', function () {
515
+ focused_via_click = true;
516
+ }); // Turns the IE clear button into a reset button
517
+
518
+ $input.addEventListener('mouseup', function () {
519
+ setTimeout(function () {
520
+ if ($input.value === '') reset($input);
521
+ }, 1);
522
+ });
523
+ $input.addEventListener('click', function (e) {
524
+ select_cursor_segment($input);
525
+ });
526
+ $input.addEventListener('blur', function () {
527
+ focused_via_click = false;
528
+ });
529
+ $input.addEventListener('focus', function (e) {
530
+ if (!focused_via_click) {
531
+ e.preventDefault();
532
+ var segment = shiftKey ? 'mode' : 'hrs';
533
+ select_segment($input, segment);
534
+ }
535
+
536
+ update_a11y($input, ['initial', 'select']);
537
+ });
538
+ $input.addEventListener('keydown', function (e) {
539
+ var is_enter_key = e.which === 13;
540
+ if (is_enter_key) return true;
541
+ var is_number_key = all_number_keys.indexOf(e.which) > -1;
542
+ var is_named_key = values(named_keys).indexOf(e.which) > -1;
543
+ var is_arrow_key = [named_keys.ArrowDown, named_keys.ArrowRight, named_keys.ArrowUp, named_keys.ArrowLeft].indexOf(e.which) > -1;
544
+ var is_mode_key = [named_keys.a, named_keys.p].indexOf(e.which) > -1;
545
+ var is_delete_key = [named_keys.Delete, named_keys.Backspace].indexOf(e.which) > -1;
546
+
547
+ if (!is_named_key || is_arrow_key || is_number_key || is_mode_key || is_delete_key) {
548
+ e.preventDefault();
549
+ }
550
+
551
+ if (is_number_key) {
552
+ manual_number_entry($input, e.which);
553
+ }
554
+
555
+ if (is_delete_key) {
556
+ var segment = get_current_segment($input);
557
+ clear_segment($input, segment);
558
+ }
559
+
560
+ switch (e.which) {
561
+ case named_keys.ArrowRight:
562
+ next_segment($input);
563
+ break;
564
+
565
+ case named_keys.ArrowLeft:
566
+ prev_segment($input);
567
+ break;
568
+
569
+ case named_keys.ArrowUp:
570
+ increment_current_segment($input);
571
+ break;
572
+
573
+ case named_keys.ArrowDown:
574
+ decrement_current_segment($input);
575
+ break;
576
+
577
+ case named_keys.Escape:
578
+ reset($input);
579
+ break;
580
+
581
+ case named_keys.a:
582
+ set_mode($input, 'AM');
583
+ break;
584
+
585
+ case named_keys.p:
586
+ set_mode($input, 'PM');
587
+ break;
588
+
589
+ case named_keys.Tab:
590
+ handle_tab($input, e);
591
+ break;
592
+ }
593
+ });
594
+ }
595
+
596
+ function auto_swap($input) {
597
+ if ($input.polyfill.autoSwap) {
598
+ switch_times($input, 24);
599
+ setTimeout(function () {
600
+ switch_times($input, 12);
601
+ }, 1);
602
+ }
603
+ }
604
+
605
+ // selector is optional, it allows for an early exit
606
+ var get_ancestors = function ($input, selectorString) {
607
+ var $elem = $input; // https://stackoverflow.com/a/8729274/1611058
608
+
609
+ var ancestors = [];
610
+
611
+ while ($elem) {
612
+ ancestors.push($elem);
613
+ var matchesSelector = $elem.msMatchesSelector ? $elem.msMatchesSelector(selectorString) : $elem.matches(selectorString);
614
+
615
+ if (matchesSelector) {
616
+ return ancestors;
617
+ }
618
+
619
+ $elem = $elem.parentElement;
620
+ }
621
+
622
+ return ancestors;
825
623
  };
826
624
 
827
- (function (module) {
828
- var apply_default = apply_default$1;
829
- var update_time$1 = update_time;
830
- var set_data_attribute = set_data_attribute$3;
831
- var bind_events$1 = bind_events;
832
- var switch_times = switch_times$1;
833
- var get_label$1 = get_label;
834
-
835
- var create_a11y_block$1 = create_a11y_block;
836
-
837
- var accessibility_block_created = false;
838
- var $a11y;
839
-
840
- function TimePolyfill($input) {
841
-
842
- $input.setAttribute('autocomplete','off');
843
-
844
- // Prevent screen reader from announcing the default stuff
845
- $input.setAttribute('aria-hidden', true);
846
-
847
- if (!accessibility_block_created) {
848
- $a11y = create_a11y_block$1();
849
- accessibility_block_created = true;
850
- }
851
-
852
- var label = get_label$1($input);
853
-
854
- $input.polyfill = {
855
- $a11y: $a11y,
856
- label: label,
857
- autoSwap: true,
858
- update: function() {
859
- update_time$1($input);
860
- },
861
- swap: function(forcedFormat) {
862
- switch_times($input, forcedFormat);
863
- }
864
- };
865
-
866
- if ($input.value === '' || /--/.test($input.value)) {
867
- apply_default($input);
868
- set_data_attribute($input, '');
869
- } else {
870
- update_time$1($input);
871
- set_data_attribute($input, $input.value);
872
- }
873
-
874
- bind_events$1($input);
875
- }
876
-
877
- if (window) window.TimePolyfill = TimePolyfill;
878
- if (module) module.exports = TimePolyfill;
879
- } (timeInputPolyfill));
880
-
881
- var TimePolyfill = timeInputPolyfill.exports;
625
+ function get_label($input) {
626
+ var labelText = aria_labelledby($input) || aria_label($input) || for_attribute($input) || label_wrapper_element($input) || title_attribute($input);
627
+ if (labelText) return labelText;
628
+ console.error('Label text for input not found.', $input);
629
+ throw new Error('Cannot polyfill time input due to a missing label.');
630
+ }
631
+
632
+ function aria_labelledby($input) {
633
+ var ariaLabelByID = $input.getAttribute('aria-labelledby');
634
+
635
+ if (ariaLabelByID) {
636
+ var $ariaLabelBy = document.getElementById(ariaLabelByID);
637
+ if ($ariaLabelBy) return $ariaLabelBy.textContent;
638
+ }
639
+
640
+ return false;
641
+ }
642
+
643
+ function aria_label($input) {
644
+ var ariaLabel = $input.getAttribute('aria-label');
645
+ if (ariaLabel) return ariaLabel;
646
+ return false;
647
+ }
648
+
649
+ function for_attribute($input) {
650
+ if ($input.id) {
651
+ var $forLabel = document.querySelector('label[for="' + $input.id + '"]');
652
+ if ($forLabel) return $forLabel.textContent;
653
+ }
654
+
655
+ return false;
656
+ }
657
+
658
+ function label_wrapper_element($input) {
659
+ var ancestors = get_ancestors($input, 'label');
660
+ var $parentLabel = ancestors[ancestors.length - 1];
661
+ if ($parentLabel.nodeName == 'LABEL') return $parentLabel.textContent;
662
+ return false;
663
+ }
664
+
665
+ function title_attribute($input) {
666
+ var titleLabel = $input.getAttribute('title');
667
+ if (titleLabel) return titleLabel;
668
+ return false;
669
+ }
670
+
671
+ function create_accessibility_block() {
672
+ var $block = document.createElement('div');
673
+ $block.setAttribute('aria-live', 'assertive');
674
+ $block.setAttribute('style', 'position: absolute; opacity: 0; height: 0; width: 0; overflow: hidden; pointer-events: none;');
675
+ $block.classList.add('time-input-polyfill-accessibility-block');
676
+ document.querySelector('body').appendChild($block);
677
+ return $block;
678
+ }
679
+
680
+ var accessibility_block_created = false;
681
+ var $a11y;
682
+
683
+ function TimePolyfill($input, $label) {
684
+ $input.setAttribute('autocomplete', 'off'); // Prevent screen reader from announcing the default stuff
685
+
686
+ $input.setAttribute('aria-hidden', true);
687
+
688
+ if (!accessibility_block_created) {
689
+ $a11y = create_accessibility_block();
690
+ accessibility_block_created = true;
691
+ }
692
+
693
+ var label = $label ? $label.textContent : get_label($input);
694
+ $input.polyfill = {
695
+ $a11y: $a11y,
696
+ label: label,
697
+ autoSwap: true,
698
+ update: function update() {
699
+ update_time($input);
700
+ },
701
+ swap: function swap(forcedFormat) {
702
+ switch_times($input, forcedFormat);
703
+ }
704
+ };
705
+
706
+ if ($input.value === '' || /--/.test($input.value)) {
707
+ apply_default($input);
708
+ set_data_attribute($input, '');
709
+ } else {
710
+ update_time($input);
711
+ set_data_attribute($input, $input.value);
712
+ }
713
+
714
+ bind_events($input);
715
+ }
716
+
717
+ if (window) {
718
+ window.TimePolyfill = TimePolyfill;
719
+ }
720
+
721
+ var index_cjs = TimePolyfill;
882
722
 
883
723
  function civilTimeToHTMLTime(civilTime) {
884
724
  if (civilTime == undefined) {
@@ -904,7 +744,7 @@ function InputTimeSafari(_a) {
904
744
  const blurHandler = generateEventHandler(handleChange);
905
745
  React.useLayoutEffect(() => {
906
746
  const input = inputTime.current;
907
- new TimePolyfill(input);
747
+ new index_cjs(input);
908
748
  if (value) {
909
749
  input.value = civilTimeToHTMLTime(value);
910
750
  input.polyfill.update();