@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.
- package/dist/Autocomplete/index.js +12 -12
- package/dist/Avatar/index.js +2 -2
- package/dist/{Avatar-89cfd0a6.js → Avatar-01c5ba8b.js} +3 -3
- package/dist/Banner/index.js +8 -8
- package/dist/Button/index.js +3 -3
- package/dist/Button-186ef2c1.js +57 -0
- package/dist/ButtonDismiss/index.js +4 -4
- package/dist/{ButtonDismiss-3fb1eaf9.js → ButtonDismiss-d2d16622.js} +1 -1
- package/dist/Card/index.js +6 -6
- package/dist/Card-c0f88c0f.js +93 -0
- package/dist/Checkbox/index.js +4 -4
- package/dist/Checkbox-1df46a4a.js +40 -0
- package/dist/Chips/InternalChipDismissible/hooks/useInternalChipDismissibleInput.d.ts +1 -1
- package/dist/Chips/index.js +11 -11
- package/dist/ConfirmationModal/index.js +11 -11
- package/dist/{ConfirmationModal-6a7beee2.js → ConfirmationModal-ac668c46.js} +3 -3
- package/dist/Content/index.js +2 -2
- package/dist/{Content-05df8f7f.js → Content-af82acba.js} +5 -5
- package/dist/DataDump/index.js +8 -8
- package/dist/DataTable/index.js +17 -17
- package/dist/DatePicker/index.js +4 -4
- package/dist/DatePicker-e085dff4.js +106 -0
- package/dist/DescriptionList/index.js +4 -4
- package/dist/Disclosure/index.js +5 -5
- package/dist/Divider/index.js +3 -3
- package/dist/Drawer/index.js +9 -9
- package/dist/Emphasis/index.js +3 -3
- package/dist/{Emphasis-23dc2a0a.js → Emphasis-53e963b5.js} +1 -1
- package/dist/FeatureSwitch/index.js +11 -11
- package/dist/Form/index.js +2 -2
- package/dist/FormField/index.js +8 -8
- package/dist/{FormField-79a0a375.js → FormField-aff52a1d.js} +21 -13
- package/dist/FormatEmail/index.js +3 -3
- package/dist/FormatFile/index.js +13 -13
- package/dist/FormatFile-42ea7a6a.js +105 -0
- package/dist/Gallery/index.js +16 -16
- package/dist/Heading/index.js +3 -3
- package/dist/{Heading-7b203f7f.js → Heading-8c6e4e0b.js} +1 -1
- package/dist/InlineLabel/index.js +4 -4
- package/dist/InputAvatar/index.js +10 -10
- package/dist/InputDate/index.js +9 -9
- package/dist/InputEmail/index.js +8 -8
- package/dist/InputFile/index.js +6 -6
- package/dist/{InputFile-5e0ed2b5.js → InputFile-e7c15211.js} +7 -7
- package/dist/InputGroup/index.js +3 -3
- package/dist/InputNumber/index.js +8 -8
- package/dist/InputPassword/index.js +8 -8
- package/dist/InputText/InputText.d.ts +74 -17
- package/dist/InputText/index.js +9 -9
- package/dist/{InputText-95ea24f9.js → InputText-90bf6056.js} +1 -1
- package/dist/InputTime/index.js +652 -812
- package/dist/InputValidation/index.js +4 -4
- package/dist/{InputValidation-97dd0dcf.js → InputValidation-e09f5d20.js} +4 -4
- package/dist/LightBox/index.js +5 -5
- package/dist/{LightBox-dd1afa97.js → LightBox-8472bc9d.js} +5 -5
- package/dist/List/index.js +13 -13
- package/dist/Markdown/index.js +7 -7
- package/dist/{Markdown-be2dcd0c.js → Markdown-5d86d6e7.js} +4 -4
- package/dist/Menu/index.js +4 -4
- package/dist/{Menu-d6a7d17b.js → Menu-b5e8d8f9.js} +5 -5
- package/dist/Modal/index.js +6 -6
- package/dist/{Modal-757e83fd.js → Modal-e41f9284.js} +8 -8
- package/dist/MultiSelect/index.js +8 -8
- package/dist/{Option-4b665afd.js → Option-9aa09e72.js} +1 -1
- package/dist/Page/index.js +11 -11
- package/dist/Popover/index.js +6 -6
- package/dist/ProgressBar/index.js +2 -2
- package/dist/ProgressBar-d3178aa9.js +28 -0
- package/dist/RadioGroup/index.js +5 -5
- package/dist/Select/index.js +9 -9
- package/dist/Spinner/index.js +2 -2
- package/dist/Spinner-35cee923.js +24 -0
- package/dist/StatusLabel/index.js +5 -5
- package/dist/Switch/index.js +3 -3
- package/dist/Switch-21d7093a.js +56 -0
- package/dist/Table/index.js +5 -5
- package/dist/Tabs/index.js +4 -4
- package/dist/Text/index.js +3 -3
- package/dist/{Text-7ce00adb.js → Text-4c04ddc3.js} +1 -1
- package/dist/Toast/index.js +5 -5
- package/dist/Tooltip/index.js +4 -4
- package/dist/{Tooltip-1090a43d.js → Tooltip-27720f96.js} +4 -4
- package/dist/Typography/index.js +2 -2
- package/dist/Typography-dd9717e7.js +62 -0
- package/dist/{tslib.es6-efe27175.js → tslib.es6-5b8768b7.js} +16 -13
- package/package.json +7 -7
- package/dist/Button-16e043ec.js +0 -57
- package/dist/Card-edab9c3c.js +0 -93
- package/dist/Checkbox-c1efc2f6.js +0 -40
- package/dist/DatePicker-0696b0f0.js +0 -106
- package/dist/FormatFile-3512f838.js +0 -105
- package/dist/ProgressBar-f028b159.js +0 -28
- package/dist/Spinner-ae4c8a85.js +0 -24
- package/dist/Switch-7ac32f7b.js +0 -56
- package/dist/Typography-9262511f.js +0 -62
- /package/dist/{style-inject.es-dcee06b6.js → style-inject.es-9d2f5f4e.js} +0 -0
package/dist/InputTime/index.js
CHANGED
|
@@ -2,883 +2,723 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var tslib_es6 = require('../tslib.es6-
|
|
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-
|
|
9
|
+
var FormField = require('../FormField-aff52a1d.js');
|
|
10
10
|
require('uuid');
|
|
11
11
|
require('react-hook-form');
|
|
12
|
-
require('../style-inject.es-
|
|
12
|
+
require('../style-inject.es-9d2f5f4e.js');
|
|
13
13
|
require('classnames');
|
|
14
|
-
require('../Button-
|
|
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-
|
|
19
|
-
require('../Text-
|
|
20
|
-
require('../InputValidation-
|
|
18
|
+
require('../Typography-dd9717e7.js');
|
|
19
|
+
require('../Text-4c04ddc3.js');
|
|
20
|
+
require('../InputValidation-e09f5d20.js');
|
|
21
21
|
require('framer-motion');
|
|
22
|
-
require('../Spinner-
|
|
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
|
-
|
|
30
|
-
|
|
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
|
|
38
|
+
var timeSupport = get_time_support();
|
|
39
|
+
if (window) window.supportsTime = timeSupport;
|
|
34
40
|
|
|
35
|
-
var supportsTime
|
|
41
|
+
var supportsTime = timeSupport;
|
|
36
42
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
return event;
|
|
99
|
-
};
|
|
110
|
+
function convert_number(number) {
|
|
111
|
+
return isNaN(number) ? number : parseInt(number);
|
|
112
|
+
}
|
|
100
113
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
var
|
|
135
|
-
var
|
|
136
|
-
|
|
137
|
-
var
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
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
|
-
|
|
144
|
-
|
|
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
|
-
|
|
148
|
-
|
|
149
|
-
|
|
136
|
+
function update_time($input) {
|
|
137
|
+
set_time($input, $input.value);
|
|
138
|
+
return $input;
|
|
139
|
+
}
|
|
150
140
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
var
|
|
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
|
|
168
|
-
|
|
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
|
-
|
|
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
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
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
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
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
|
-
|
|
217
|
-
|
|
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
|
|
225
|
-
|
|
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
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
285
|
-
|
|
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
|
-
|
|
327
|
-
|
|
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
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
traverse$1($input, 'next');
|
|
354
|
-
};
|
|
221
|
+
function items() {
|
|
222
|
+
return manual_entry_log;
|
|
223
|
+
}
|
|
355
224
|
|
|
356
|
-
var
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
225
|
+
var manual_entry_log$1 = {
|
|
226
|
+
items: items,
|
|
227
|
+
clear: clear,
|
|
228
|
+
add: add
|
|
360
229
|
};
|
|
361
230
|
|
|
362
|
-
var
|
|
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
|
-
|
|
371
|
-
var
|
|
372
|
-
|
|
373
|
-
var
|
|
374
|
-
|
|
375
|
-
|
|
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
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
var
|
|
382
|
-
var
|
|
383
|
-
|
|
384
|
-
var
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
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
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
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
|
-
|
|
457
|
-
|
|
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
|
-
|
|
465
|
-
|
|
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
|
-
|
|
479
|
-
var
|
|
480
|
-
|
|
481
|
-
|
|
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
|
-
|
|
510
|
-
|
|
511
|
-
|
|
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
|
-
|
|
523
|
-
var
|
|
524
|
-
|
|
525
|
-
var
|
|
526
|
-
|
|
527
|
-
|
|
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
|
-
|
|
531
|
-
|
|
532
|
-
var
|
|
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
|
|
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
|
-
|
|
552
|
-
var
|
|
553
|
-
|
|
554
|
-
|
|
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
|
-
|
|
562
|
-
|
|
563
|
-
|
|
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
|
-
|
|
567
|
-
var
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
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
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
var
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
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
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
var
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
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
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
var
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
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
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
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
|
|
747
|
+
new index_cjs(input);
|
|
908
748
|
if (value) {
|
|
909
749
|
input.value = civilTimeToHTMLTime(value);
|
|
910
750
|
input.polyfill.update();
|