@jobber/components 4.76.0 → 4.76.2
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/Combobox/index.js
CHANGED
|
@@ -26,7 +26,7 @@ var classnames__default = /*#__PURE__*/_interopDefaultLegacy(classnames);
|
|
|
26
26
|
var ReactDOM__default = /*#__PURE__*/_interopDefaultLegacy(ReactDOM);
|
|
27
27
|
var debounce__default = /*#__PURE__*/_interopDefaultLegacy(debounce);
|
|
28
28
|
|
|
29
|
-
var css_248z$6 = ".m1w5vdUZ6rQ- {\n z-index: 1002;\n z-index: var(--elevation-tooltip);\n
|
|
29
|
+
var css_248z$6 = ".m1w5vdUZ6rQ- {\n z-index: 1002;\n z-index: var(--elevation-tooltip);\n width: calc((16px * 4) * 3.75);\n width: calc(calc(16px * 4) * 3.75);\n width: calc(var(--space-extravagant) * 3.75);\n box-shadow: 0px calc(16px / 16) calc(16px / 4) 0px\n rgba(0, 0, 0, 0.1),\n 0px calc(16px / 4) 12px 0px rgba(0, 0, 0, 0.05);\n box-shadow: var(--shadow-base);\n margin-top: calc(16px / 2);\n margin-top: var(--space-small);\n border: calc(16px / 16) solid rgb(217, 223, 225);\n border: var(--border-base) solid var(--color-border);\n border-radius: calc(16px / 2);\n border-radius: var(--radius-larger);\n overflow: auto;\n background: rgba(255, 255, 255, 1);\n background: var(--color-surface);\n}\n\n.jobber-retheme .m1w5vdUZ6rQ- {\n border-radius: calc(16px / 8);\n border-radius: var(--radius-base);\n}\n\n/* CAUTION: Tests for content visibility assume this class' presence hides the content\n* so please be careful if you change this class name, or the css rules within.\n*/\n\n.m1w5vdUZ6rQ-.Zlkv2HA096A- {\n display: none;\n visibility: hidden;\n}\n\n.m1w5vdUZ6rQ-:focus,\n.m1w5vdUZ6rQ-:focus-visible {\n outline: none;\n}\n\n.m1w5vdUZ6rQ-:focus-visible {\n box-shadow: 0px 0px 0px calc(16px / 8) rgba(255, 255, 255, 1),\n 0px 0px 0px calc(16px / 4) rgb(147, 161, 169);\n box-shadow: var(--shadow-focus);\n}\n\n.YQry-Rd6zfQ- {\n display: -ms-flexbox;\n display: flex;\n -ms-flex-direction: column;\n flex-direction: column;\n position: sticky;\n gap: calc(16px / 4);\n gap: var(--space-smaller);\n bottom: 0;\n width: 100%;\n background-color: rgba(255, 255, 255, 1);\n background-color: var(--color-surface);\n}\n\n.TcpqL34s4lI- {\n padding-bottom: calc(16px / 2);\n padding-bottom: var(--space-small);\n}\n";
|
|
30
30
|
var styles$6 = {"content":"m1w5vdUZ6rQ-","hidden":"Zlkv2HA096A-","actions":"YQry-Rd6zfQ-","actionPadding":"TcpqL34s4lI-"};
|
|
31
31
|
styleInject_es.styleInject(css_248z$6);
|
|
32
32
|
|
package/dist/DataList/index.js
CHANGED
|
@@ -26,7 +26,7 @@ var ReactDOM = require('react-dom');
|
|
|
26
26
|
var Checkbox = require('../Checkbox-1cdd5cf6.js');
|
|
27
27
|
var reactRouterDom = require('react-router-dom');
|
|
28
28
|
var AnimatedSwitcher = require('../AnimatedSwitcher-d1e1ddcf.js');
|
|
29
|
-
var Combobox = require('../Combobox-
|
|
29
|
+
var Combobox = require('../Combobox-6e7dbc9c.js');
|
|
30
30
|
var Chip = require('../Chip-c91fd6c8.js');
|
|
31
31
|
var debounce = require('lodash/debounce');
|
|
32
32
|
var InputText = require('../InputText-9e61365c.js');
|
package/dist/InputTime/index.js
CHANGED
|
@@ -4,8 +4,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var tslib_es6 = require('../tslib.es6-5b8768b7.js');
|
|
6
6
|
var React = require('react');
|
|
7
|
-
var debounce = require('lodash/debounce');
|
|
8
7
|
var temporal = require('@std-proposal/temporal');
|
|
8
|
+
var debounce = require('lodash/debounce');
|
|
9
9
|
var FormField = require('../FormField-b0e74d32.js');
|
|
10
10
|
require('uuid');
|
|
11
11
|
require('react-hook-form');
|
|
@@ -27,700 +27,6 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
27
27
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
28
28
|
var debounce__default = /*#__PURE__*/_interopDefaultLegacy(debounce);
|
|
29
29
|
|
|
30
|
-
// https://stackoverflow.com/a/10199306/1611058
|
|
31
|
-
function get_time_support() {
|
|
32
|
-
var input = document.createElement('input');
|
|
33
|
-
input.setAttribute('type', 'time');
|
|
34
|
-
var notValid = 'not-a-time';
|
|
35
|
-
input.setAttribute('value', notValid);
|
|
36
|
-
return input.value !== notValid;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
var timeSupport = get_time_support();
|
|
40
|
-
if (window) window.supportsTime = timeSupport;
|
|
41
|
-
|
|
42
|
-
var supportsTime = timeSupport;
|
|
43
|
-
|
|
44
|
-
function leading_zero(number) {
|
|
45
|
-
if (isNaN(number)) return number;
|
|
46
|
-
var purified = parseInt(number);
|
|
47
|
-
return purified < 10 ? '0' + purified : number;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function convert_to_24hr_time(timeString_12hr) {
|
|
51
|
-
if (/-/.test(timeString_12hr)) return '';
|
|
52
|
-
var isPM = timeString_12hr.indexOf('PM') > -1;
|
|
53
|
-
var timeResult = /^([0-9]{2})/.exec(timeString_12hr);
|
|
54
|
-
var hrs = timeResult ? parseInt(timeResult[1]) : '';
|
|
55
|
-
var newHrs;
|
|
56
|
-
|
|
57
|
-
if (hrs === 12) {
|
|
58
|
-
newHrs = isPM ? 12 : 0;
|
|
59
|
-
} else {
|
|
60
|
-
newHrs = isPM ? hrs + 12 : hrs;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
var finalHrs = newHrs === 24 ? 0 : newHrs;
|
|
64
|
-
var timeRegEx = /^[0-9]{2}:([0-9]{2}) (AM|PM)/;
|
|
65
|
-
return timeString_12hr.replace(timeRegEx, leading_zero(finalHrs) + ':$1');
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function set_data_attribute($input, timeString_12hr) {
|
|
69
|
-
var filteredString = timeString_12hr.indexOf('-') > -1 ? '' : timeString_12hr;
|
|
70
|
-
var time24hr = convert_to_24hr_time(filteredString);
|
|
71
|
-
$input.setAttribute('data-value', time24hr);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function create_event(eventName) {
|
|
75
|
-
var event = document.createEvent('Event');
|
|
76
|
-
event.initEvent(eventName, true, true);
|
|
77
|
-
return event;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
var inputEvent = create_event('input');
|
|
81
|
-
var changeEvent = create_event('change');
|
|
82
|
-
function trigger_event($input, eventName) {
|
|
83
|
-
var event = {
|
|
84
|
-
input: inputEvent,
|
|
85
|
-
change: changeEvent
|
|
86
|
-
}[eventName];
|
|
87
|
-
|
|
88
|
-
if (can_trigger_change($input)) {
|
|
89
|
-
$input.dispatchEvent(event);
|
|
90
|
-
}
|
|
91
|
-
} // Browsers only send out input and change events if the time element has a full valid value
|
|
92
|
-
|
|
93
|
-
function can_trigger_change($input) {
|
|
94
|
-
return !/--/.test($input.value);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function trigger_both_events($input) {
|
|
98
|
-
// the event only ever fires if there is a full valid value available
|
|
99
|
-
trigger_event($input, 'input');
|
|
100
|
-
trigger_event($input, 'change');
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// I need to keep this separate from reset so that
|
|
104
|
-
// I can reset without attracting focus
|
|
105
|
-
function apply_default($input) {
|
|
106
|
-
$input.value = '--:-- --';
|
|
107
|
-
set_data_attribute($input, '');
|
|
108
|
-
trigger_both_events($input);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function convert_number(number) {
|
|
112
|
-
return isNaN(number) ? number : parseInt(number);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function convert_hours_to_12hr_time(hours) {
|
|
116
|
-
return hours <= 12 ? hours === 0 ? 12 : hours : hours - 12;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
function convert_to_12hr_time(timeString_24hr) {
|
|
120
|
-
if (timeString_24hr === '') return '--:-- --';
|
|
121
|
-
var twentyFour_regex = /([0-9]{2})\:([0-9]{2})/;
|
|
122
|
-
var result = twentyFour_regex.exec(timeString_24hr);
|
|
123
|
-
var hrs_24 = convert_number(result[1]);
|
|
124
|
-
var min = result[2];
|
|
125
|
-
var hrs_12 = convert_hours_to_12hr_time(hrs_24);
|
|
126
|
-
var isPM = hrs_24 >= 12;
|
|
127
|
-
var mode = isPM ? 'PM' : 'AM';
|
|
128
|
-
return [leading_zero(hrs_12), ':', min, ' ', mode].join('');
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function set_time($input, time_string_24hr) {
|
|
132
|
-
var twelveHr = convert_to_12hr_time(time_string_24hr);
|
|
133
|
-
$input.value = twelveHr;
|
|
134
|
-
set_data_attribute($input, time_string_24hr);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
function update_time($input) {
|
|
138
|
-
set_time($input, $input.value);
|
|
139
|
-
return $input;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// IE11 doesn't support Object.values()
|
|
143
|
-
function values(obj) {
|
|
144
|
-
var key_values = [];
|
|
145
|
-
|
|
146
|
-
for (var key in obj) {
|
|
147
|
-
key_values.push(obj[key]);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
return key_values;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
function select_segment($input, segment) {
|
|
154
|
-
set_input_type();
|
|
155
|
-
var actions = {
|
|
156
|
-
hrs: select(0, 2),
|
|
157
|
-
min: select(3, 5),
|
|
158
|
-
mode: select(6, 8)
|
|
159
|
-
};
|
|
160
|
-
actions[segment]($input);
|
|
161
|
-
|
|
162
|
-
function set_input_type() {
|
|
163
|
-
var type = segment === 'mode' ? 'text' : 'tel';
|
|
164
|
-
$input.setAttribute('type', type);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
function select(start, end) {
|
|
168
|
-
return function () {
|
|
169
|
-
$input.setSelectionRange(start, end);
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
var ranges = {
|
|
175
|
-
hrs: {
|
|
176
|
-
start: 0,
|
|
177
|
-
end: 2
|
|
178
|
-
},
|
|
179
|
-
min: {
|
|
180
|
-
start: 3,
|
|
181
|
-
end: 5
|
|
182
|
-
},
|
|
183
|
-
mode: {
|
|
184
|
-
start: 6,
|
|
185
|
-
end: 8
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
function get_selected_range($input) {
|
|
190
|
-
return {
|
|
191
|
-
start: $input.selectionStart,
|
|
192
|
-
end: $input.selectionEnd
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
function get_current_segment($input) {
|
|
197
|
-
var selection = get_selected_range($input);
|
|
198
|
-
|
|
199
|
-
for (var segment in ranges) {
|
|
200
|
-
var range = ranges[segment];
|
|
201
|
-
var aboveMin = range.start <= selection.start;
|
|
202
|
-
var belowMax = range.end >= selection.end;
|
|
203
|
-
|
|
204
|
-
if (aboveMin && belowMax) {
|
|
205
|
-
return segment;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
return 'hrs';
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
var manual_entry_log = [];
|
|
213
|
-
|
|
214
|
-
function clear() {
|
|
215
|
-
manual_entry_log = [];
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
function add(entry) {
|
|
219
|
-
manual_entry_log.push(entry);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
function items() {
|
|
223
|
-
return manual_entry_log;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
var manual_entry_log$1 = {
|
|
227
|
-
items: items,
|
|
228
|
-
clear: clear,
|
|
229
|
-
add: add
|
|
230
|
-
};
|
|
231
|
-
|
|
232
|
-
var segments = Object.keys(ranges);
|
|
233
|
-
|
|
234
|
-
function get_values($input, timeString) {
|
|
235
|
-
var value = timeString ? timeString : $input.value;
|
|
236
|
-
var regEx = /([0-9-]{1,2})\:([0-9-]{1,2})\s?(AM|PM|\-\-)?/;
|
|
237
|
-
var result = regEx.exec(value);
|
|
238
|
-
return {
|
|
239
|
-
hrs: convert_number(result[1]),
|
|
240
|
-
min: convert_number(result[2]),
|
|
241
|
-
mode: result[3]
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
function update_a11y($input, announcementArray) {
|
|
246
|
-
// Timeout helps ensure that the input has stabilized
|
|
247
|
-
setTimeout(function () {
|
|
248
|
-
var current_segment = get_current_segment($input);
|
|
249
|
-
var values = get_values($input);
|
|
250
|
-
var value = values[current_segment];
|
|
251
|
-
var finalValue = value == '--' ? 'blank' : value;
|
|
252
|
-
var segmentName = {
|
|
253
|
-
hrs: 'Hours',
|
|
254
|
-
min: 'Minutes',
|
|
255
|
-
mode: 'AM/PM'
|
|
256
|
-
}[current_segment];
|
|
257
|
-
var announcements = {
|
|
258
|
-
initial: '$label grouping $fullValue.',
|
|
259
|
-
select: '$segmentName spin button $segmentValue.',
|
|
260
|
-
update: '$segmentValue.'
|
|
261
|
-
};
|
|
262
|
-
var textArray = announcementArray.map(function (providedString) {
|
|
263
|
-
if (announcements[providedString]) {
|
|
264
|
-
return announcements[providedString];
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
return providedString;
|
|
268
|
-
});
|
|
269
|
-
var fullValue = $input.value.replace(/--/g, 'blank');
|
|
270
|
-
var html = '<p>' + textArray.join('</p><p>') + '</p>';
|
|
271
|
-
html = html.replace(/\$label/g, $input.polyfill.label);
|
|
272
|
-
html = html.replace(/\$segmentName/g, segmentName);
|
|
273
|
-
html = html.replace(/\$segmentValue/g, finalValue);
|
|
274
|
-
html = html.replace(/\$fullValue/g, fullValue);
|
|
275
|
-
$input.polyfill.$a11y.innerHTML = html;
|
|
276
|
-
}, 1);
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
function traverse($input, direction) {
|
|
280
|
-
var segment = get_current_segment($input);
|
|
281
|
-
var modifier = direction === 'next' ? 1 : -1;
|
|
282
|
-
var next_segment_index = segments.indexOf(segment) + modifier;
|
|
283
|
-
var next_segment = {
|
|
284
|
-
next: segments[next_segment_index] || 'mode',
|
|
285
|
-
prev: next_segment_index < 0 ? 'hrs' : segments[next_segment_index]
|
|
286
|
-
}[direction];
|
|
287
|
-
select_segment($input, next_segment);
|
|
288
|
-
manual_entry_log$1.clear();
|
|
289
|
-
update_a11y($input, ['select']);
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
function next_segment($input) {
|
|
293
|
-
traverse($input, 'next');
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
function prev_segment($input) {
|
|
297
|
-
traverse($input, 'prev');
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
function select_cursor_segment($input) {
|
|
301
|
-
var current_segment = get_current_segment($input);
|
|
302
|
-
select_segment($input, current_segment);
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
function reset($input) {
|
|
306
|
-
apply_default($input);
|
|
307
|
-
select_segment($input, 'hrs');
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
function set_segment($input, segment, value) {
|
|
311
|
-
var values = get_values($input);
|
|
312
|
-
values[segment] = value;
|
|
313
|
-
var newInputVal = [leading_zero(values.hrs), ':', leading_zero(values.min), ' ', values.mode].join('');
|
|
314
|
-
$input.value = newInputVal;
|
|
315
|
-
select_segment($input, segment);
|
|
316
|
-
set_data_attribute($input, newInputVal);
|
|
317
|
-
trigger_both_events($input);
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
/*eslint indent: 0 */
|
|
321
|
-
// prettier-ignore
|
|
322
|
-
var all_number_keys = [// 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
|
|
323
|
-
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105];
|
|
324
|
-
|
|
325
|
-
var sorted_number_keys = {}; // sorted_number_keys = { 48: 0, 49: 1, 96: 0, 97: 1, ... };
|
|
326
|
-
|
|
327
|
-
all_number_keys.forEach(function (key, index) {
|
|
328
|
-
var number_val = index > 9 ? index - 10 : index;
|
|
329
|
-
sorted_number_keys[key] = number_val;
|
|
330
|
-
});
|
|
331
|
-
|
|
332
|
-
function manual_number_entry($input, key) {
|
|
333
|
-
var key_value = sorted_number_keys[key];
|
|
334
|
-
var segment = get_current_segment($input);
|
|
335
|
-
|
|
336
|
-
if (segment !== 'mode') {
|
|
337
|
-
var entry_count = manual_entry_log$1.items().length;
|
|
338
|
-
var upper_limits = {
|
|
339
|
-
hrs: [1, 2],
|
|
340
|
-
min: [5, 9]
|
|
341
|
-
};
|
|
342
|
-
var limit = upper_limits[segment][entry_count];
|
|
343
|
-
|
|
344
|
-
if (entry_count < 2) {
|
|
345
|
-
manual_entry_log$1.add(key_value);
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
var full_limit = parseInt(upper_limits[segment].join(''));
|
|
349
|
-
var full_entry = parseInt(manual_entry_log$1.items().join(''));
|
|
350
|
-
|
|
351
|
-
if (full_limit >= full_entry) {
|
|
352
|
-
set_segment($input, segment, full_entry);
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
var at_limit = key_value > limit || manual_entry_log$1.items().length === 2;
|
|
356
|
-
|
|
357
|
-
if (at_limit) {
|
|
358
|
-
next_segment($input);
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
function clear_segment($input, segment) {
|
|
364
|
-
set_segment($input, segment, '--');
|
|
365
|
-
update_a11y($input, ['update']);
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
function switch_mode($input, default_mode) {
|
|
369
|
-
default_mode = default_mode || 'AM';
|
|
370
|
-
var current_mode = get_values($input).mode;
|
|
371
|
-
var new_mode = {
|
|
372
|
-
'--': default_mode,
|
|
373
|
-
AM: 'PM',
|
|
374
|
-
PM: 'AM'
|
|
375
|
-
}[current_mode];
|
|
376
|
-
set_segment($input, 'mode', new_mode);
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
function nudge_time_segment($input, segment, direction) {
|
|
380
|
-
var current_values = get_values($input);
|
|
381
|
-
var time;
|
|
382
|
-
var modifier = direction === 'up' ? 1 : -1;
|
|
383
|
-
|
|
384
|
-
if (current_values[segment] === '--') {
|
|
385
|
-
var current_time = new Date();
|
|
386
|
-
time = {
|
|
387
|
-
hrs: convert_hours_to_12hr_time(current_time.getHours()),
|
|
388
|
-
min: current_time.getMinutes()
|
|
389
|
-
};
|
|
390
|
-
} else {
|
|
391
|
-
var minutes = {
|
|
392
|
-
up: current_values.min < 59 ? current_values.min + modifier : 0,
|
|
393
|
-
down: current_values.min === 0 ? 59 : current_values.min + modifier
|
|
394
|
-
};
|
|
395
|
-
time = {
|
|
396
|
-
hrs: convert_hours_to_12hr_time(current_values.hrs + modifier),
|
|
397
|
-
min: minutes[direction]
|
|
398
|
-
};
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
set_segment($input, segment, leading_zero(time[segment]));
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
function increment($input, segment) {
|
|
405
|
-
if (segment === 'mode') {
|
|
406
|
-
switch_mode($input, 'AM');
|
|
407
|
-
} else {
|
|
408
|
-
nudge_time_segment($input, segment, 'up');
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
update_a11y($input, ['update']);
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
function increment_current_segment($input) {
|
|
415
|
-
var current_segment = get_current_segment($input);
|
|
416
|
-
increment($input, current_segment);
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
function decrement($input, segment) {
|
|
420
|
-
if (segment === 'mode') {
|
|
421
|
-
switch_mode($input, 'PM');
|
|
422
|
-
} else {
|
|
423
|
-
nudge_time_segment($input, segment, 'down');
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
update_a11y($input, ['update']);
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
function decrement_current_segment($input) {
|
|
430
|
-
var current_segment = get_current_segment($input);
|
|
431
|
-
decrement($input, current_segment);
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
function set_mode($input, type) {
|
|
435
|
-
var segment = get_current_segment($input);
|
|
436
|
-
|
|
437
|
-
if (segment === 'mode') {
|
|
438
|
-
set_segment($input, segment, type);
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
var switch_to_data_value = function ($input) {
|
|
443
|
-
var replacementVal = $input.dataset.value;
|
|
444
|
-
$input.value = replacementVal;
|
|
445
|
-
};
|
|
446
|
-
|
|
447
|
-
function switch_times($input, format) {
|
|
448
|
-
var is12hr = /\s/.test($input.value);
|
|
449
|
-
|
|
450
|
-
if (format != 12 && format != 24) {
|
|
451
|
-
format = is12hr ? 24 : 12;
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
var actions = {
|
|
455
|
-
12: function _() {
|
|
456
|
-
if (!is12hr) {
|
|
457
|
-
set_time($input, $input.dataset.value);
|
|
458
|
-
}
|
|
459
|
-
},
|
|
460
|
-
24: function _() {
|
|
461
|
-
if (is12hr) {
|
|
462
|
-
switch_to_data_value($input);
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
};
|
|
466
|
-
actions[format]();
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
function handle_tab($input, e) {
|
|
470
|
-
var current_segment = get_current_segment($input);
|
|
471
|
-
var backwards_and_first = e.shiftKey && current_segment === 'hrs';
|
|
472
|
-
var forwards_and_last = !e.shiftKey && current_segment === 'mode';
|
|
473
|
-
|
|
474
|
-
if (!backwards_and_first && !forwards_and_last) {
|
|
475
|
-
e.preventDefault();
|
|
476
|
-
|
|
477
|
-
if (e.shiftKey) {
|
|
478
|
-
prev_segment($input);
|
|
479
|
-
} else {
|
|
480
|
-
next_segment($input);
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
var named_keys = {
|
|
486
|
-
ArrowDown: 40,
|
|
487
|
-
ArrowRight: 39,
|
|
488
|
-
ArrowUp: 38,
|
|
489
|
-
ArrowLeft: 37,
|
|
490
|
-
Backspace: 8,
|
|
491
|
-
Delete: 46,
|
|
492
|
-
Tab: 9,
|
|
493
|
-
Shift: 16,
|
|
494
|
-
Escape: 27,
|
|
495
|
-
a: 65,
|
|
496
|
-
p: 80
|
|
497
|
-
};
|
|
498
|
-
|
|
499
|
-
function bind_events($input) {
|
|
500
|
-
var shiftKey = false;
|
|
501
|
-
document.addEventListener('keydown', function (e) {
|
|
502
|
-
shiftKey = e.shiftKey;
|
|
503
|
-
});
|
|
504
|
-
document.addEventListener('keyup', function (e) {
|
|
505
|
-
shiftKey = e.shiftKey;
|
|
506
|
-
});
|
|
507
|
-
|
|
508
|
-
if ($input.form) {
|
|
509
|
-
$input.form.addEventListener('submit', function () {
|
|
510
|
-
auto_swap($input);
|
|
511
|
-
});
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
var focused_via_click = false;
|
|
515
|
-
$input.addEventListener('mousedown', function () {
|
|
516
|
-
focused_via_click = true;
|
|
517
|
-
}); // Turns the IE clear button into a reset button
|
|
518
|
-
|
|
519
|
-
$input.addEventListener('mouseup', function () {
|
|
520
|
-
setTimeout(function () {
|
|
521
|
-
if ($input.value === '') reset($input);
|
|
522
|
-
}, 1);
|
|
523
|
-
});
|
|
524
|
-
$input.addEventListener('click', function (e) {
|
|
525
|
-
select_cursor_segment($input);
|
|
526
|
-
});
|
|
527
|
-
$input.addEventListener('blur', function () {
|
|
528
|
-
focused_via_click = false;
|
|
529
|
-
});
|
|
530
|
-
$input.addEventListener('focus', function (e) {
|
|
531
|
-
if (!focused_via_click) {
|
|
532
|
-
e.preventDefault();
|
|
533
|
-
var segment = shiftKey ? 'mode' : 'hrs';
|
|
534
|
-
select_segment($input, segment);
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
update_a11y($input, ['initial', 'select']);
|
|
538
|
-
});
|
|
539
|
-
$input.addEventListener('keydown', function (e) {
|
|
540
|
-
var is_enter_key = e.which === 13;
|
|
541
|
-
if (is_enter_key) return true;
|
|
542
|
-
var is_number_key = all_number_keys.indexOf(e.which) > -1;
|
|
543
|
-
var is_named_key = values(named_keys).indexOf(e.which) > -1;
|
|
544
|
-
var is_arrow_key = [named_keys.ArrowDown, named_keys.ArrowRight, named_keys.ArrowUp, named_keys.ArrowLeft].indexOf(e.which) > -1;
|
|
545
|
-
var is_mode_key = [named_keys.a, named_keys.p].indexOf(e.which) > -1;
|
|
546
|
-
var is_delete_key = [named_keys.Delete, named_keys.Backspace].indexOf(e.which) > -1;
|
|
547
|
-
|
|
548
|
-
if (!is_named_key || is_arrow_key || is_number_key || is_mode_key || is_delete_key) {
|
|
549
|
-
e.preventDefault();
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
if (is_number_key) {
|
|
553
|
-
manual_number_entry($input, e.which);
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
if (is_delete_key) {
|
|
557
|
-
var segment = get_current_segment($input);
|
|
558
|
-
clear_segment($input, segment);
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
switch (e.which) {
|
|
562
|
-
case named_keys.ArrowRight:
|
|
563
|
-
next_segment($input);
|
|
564
|
-
break;
|
|
565
|
-
|
|
566
|
-
case named_keys.ArrowLeft:
|
|
567
|
-
prev_segment($input);
|
|
568
|
-
break;
|
|
569
|
-
|
|
570
|
-
case named_keys.ArrowUp:
|
|
571
|
-
increment_current_segment($input);
|
|
572
|
-
break;
|
|
573
|
-
|
|
574
|
-
case named_keys.ArrowDown:
|
|
575
|
-
decrement_current_segment($input);
|
|
576
|
-
break;
|
|
577
|
-
|
|
578
|
-
case named_keys.Escape:
|
|
579
|
-
reset($input);
|
|
580
|
-
break;
|
|
581
|
-
|
|
582
|
-
case named_keys.a:
|
|
583
|
-
set_mode($input, 'AM');
|
|
584
|
-
break;
|
|
585
|
-
|
|
586
|
-
case named_keys.p:
|
|
587
|
-
set_mode($input, 'PM');
|
|
588
|
-
break;
|
|
589
|
-
|
|
590
|
-
case named_keys.Tab:
|
|
591
|
-
handle_tab($input, e);
|
|
592
|
-
break;
|
|
593
|
-
}
|
|
594
|
-
});
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
function auto_swap($input) {
|
|
598
|
-
if ($input.polyfill.autoSwap) {
|
|
599
|
-
switch_times($input, 24);
|
|
600
|
-
setTimeout(function () {
|
|
601
|
-
switch_times($input, 12);
|
|
602
|
-
}, 1);
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
// selector is optional, it allows for an early exit
|
|
607
|
-
var get_ancestors = function ($input, selectorString) {
|
|
608
|
-
var $elem = $input; // https://stackoverflow.com/a/8729274/1611058
|
|
609
|
-
|
|
610
|
-
var ancestors = [];
|
|
611
|
-
|
|
612
|
-
while ($elem) {
|
|
613
|
-
ancestors.push($elem);
|
|
614
|
-
var matchesSelector = $elem.msMatchesSelector ? $elem.msMatchesSelector(selectorString) : $elem.matches(selectorString);
|
|
615
|
-
|
|
616
|
-
if (matchesSelector) {
|
|
617
|
-
return ancestors;
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
$elem = $elem.parentElement;
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
return ancestors;
|
|
624
|
-
};
|
|
625
|
-
|
|
626
|
-
function get_label($input) {
|
|
627
|
-
var labelText = aria_labelledby($input) || aria_label($input) || for_attribute($input) || label_wrapper_element($input) || title_attribute($input);
|
|
628
|
-
if (labelText) return labelText;
|
|
629
|
-
console.error('Label text for input not found.', $input);
|
|
630
|
-
throw new Error('Cannot polyfill time input due to a missing label.');
|
|
631
|
-
}
|
|
632
|
-
|
|
633
|
-
function aria_labelledby($input) {
|
|
634
|
-
var ariaLabelByID = $input.getAttribute('aria-labelledby');
|
|
635
|
-
|
|
636
|
-
if (ariaLabelByID) {
|
|
637
|
-
var $ariaLabelBy = document.getElementById(ariaLabelByID);
|
|
638
|
-
if ($ariaLabelBy) return $ariaLabelBy.textContent;
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
return false;
|
|
642
|
-
}
|
|
643
|
-
|
|
644
|
-
function aria_label($input) {
|
|
645
|
-
var ariaLabel = $input.getAttribute('aria-label');
|
|
646
|
-
if (ariaLabel) return ariaLabel;
|
|
647
|
-
return false;
|
|
648
|
-
}
|
|
649
|
-
|
|
650
|
-
function for_attribute($input) {
|
|
651
|
-
if ($input.id) {
|
|
652
|
-
var $forLabel = document.querySelector('label[for="' + $input.id + '"]');
|
|
653
|
-
if ($forLabel) return $forLabel.textContent;
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
return false;
|
|
657
|
-
}
|
|
658
|
-
|
|
659
|
-
function label_wrapper_element($input) {
|
|
660
|
-
var ancestors = get_ancestors($input, 'label');
|
|
661
|
-
var $parentLabel = ancestors[ancestors.length - 1];
|
|
662
|
-
if ($parentLabel.nodeName == 'LABEL') return $parentLabel.textContent;
|
|
663
|
-
return false;
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
function title_attribute($input) {
|
|
667
|
-
var titleLabel = $input.getAttribute('title');
|
|
668
|
-
if (titleLabel) return titleLabel;
|
|
669
|
-
return false;
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
function create_accessibility_block() {
|
|
673
|
-
var $block = document.createElement('div');
|
|
674
|
-
$block.setAttribute('aria-live', 'assertive');
|
|
675
|
-
$block.setAttribute('style', 'position: absolute; opacity: 0; height: 0; width: 0; overflow: hidden; pointer-events: none;');
|
|
676
|
-
$block.classList.add('time-input-polyfill-accessibility-block');
|
|
677
|
-
document.querySelector('body').appendChild($block);
|
|
678
|
-
return $block;
|
|
679
|
-
}
|
|
680
|
-
|
|
681
|
-
var accessibility_block_created = false;
|
|
682
|
-
var $a11y;
|
|
683
|
-
|
|
684
|
-
function TimePolyfill($input, $label) {
|
|
685
|
-
$input.setAttribute('autocomplete', 'off'); // Prevent screen reader from announcing the default stuff
|
|
686
|
-
|
|
687
|
-
$input.setAttribute('aria-hidden', true);
|
|
688
|
-
|
|
689
|
-
if (!accessibility_block_created) {
|
|
690
|
-
$a11y = create_accessibility_block();
|
|
691
|
-
accessibility_block_created = true;
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
var label = $label ? $label.textContent : get_label($input);
|
|
695
|
-
$input.polyfill = {
|
|
696
|
-
$a11y: $a11y,
|
|
697
|
-
label: label,
|
|
698
|
-
autoSwap: true,
|
|
699
|
-
update: function update() {
|
|
700
|
-
update_time($input);
|
|
701
|
-
},
|
|
702
|
-
swap: function swap(forcedFormat) {
|
|
703
|
-
switch_times($input, forcedFormat);
|
|
704
|
-
}
|
|
705
|
-
};
|
|
706
|
-
|
|
707
|
-
if ($input.value === '' || /--/.test($input.value)) {
|
|
708
|
-
apply_default($input);
|
|
709
|
-
set_data_attribute($input, '');
|
|
710
|
-
} else {
|
|
711
|
-
update_time($input);
|
|
712
|
-
set_data_attribute($input, $input.value);
|
|
713
|
-
}
|
|
714
|
-
|
|
715
|
-
bind_events($input);
|
|
716
|
-
}
|
|
717
|
-
|
|
718
|
-
if (window) {
|
|
719
|
-
window.TimePolyfill = TimePolyfill;
|
|
720
|
-
}
|
|
721
|
-
|
|
722
|
-
var index_cjs = TimePolyfill;
|
|
723
|
-
|
|
724
30
|
function civilTimeToHTMLTime(civilTime) {
|
|
725
31
|
if (civilTime == undefined) {
|
|
726
32
|
return "";
|
|
@@ -737,55 +43,6 @@ function htmlTimeToCivilTime(timeString) {
|
|
|
737
43
|
}
|
|
738
44
|
}
|
|
739
45
|
|
|
740
|
-
function InputTimeSafari(_a) {
|
|
741
|
-
var { defaultValue, value, onChange } = _a, params = tslib_es6.__rest(_a, ["defaultValue", "value", "onChange"]);
|
|
742
|
-
const inputTime = React__default["default"].createRef();
|
|
743
|
-
const debouncedHandleChange = debounce__default["default"](handleChange, 1000);
|
|
744
|
-
const changeHandler = generateEventHandler(debouncedHandleChange);
|
|
745
|
-
const blurHandler = generateEventHandler(handleChange);
|
|
746
|
-
React.useLayoutEffect(() => {
|
|
747
|
-
const input = inputTime.current;
|
|
748
|
-
new index_cjs(input);
|
|
749
|
-
if (value) {
|
|
750
|
-
input.value = civilTimeToHTMLTime(value);
|
|
751
|
-
input.polyfill.update();
|
|
752
|
-
}
|
|
753
|
-
if (defaultValue) {
|
|
754
|
-
input.value = civilTimeToHTMLTime(defaultValue);
|
|
755
|
-
input.polyfill.update();
|
|
756
|
-
}
|
|
757
|
-
input.addEventListener("change", changeHandler);
|
|
758
|
-
input.addEventListener("blur", blurHandler);
|
|
759
|
-
return () => {
|
|
760
|
-
window.removeEventListener("change", changeHandler);
|
|
761
|
-
window.removeEventListener("blur", blurHandler);
|
|
762
|
-
};
|
|
763
|
-
}, []);
|
|
764
|
-
React.useLayoutEffect(() => {
|
|
765
|
-
const input = inputTime.current;
|
|
766
|
-
if (value) {
|
|
767
|
-
input.value = civilTimeToHTMLTime(value);
|
|
768
|
-
input.polyfill.update();
|
|
769
|
-
}
|
|
770
|
-
if (defaultValue) {
|
|
771
|
-
input.value = civilTimeToHTMLTime(defaultValue);
|
|
772
|
-
input.polyfill.update();
|
|
773
|
-
}
|
|
774
|
-
}, [value, defaultValue]);
|
|
775
|
-
return React__default["default"].createElement(FormField.FormField, Object.assign({ inputRef: inputTime, type: "time" }, params));
|
|
776
|
-
function handleChange(newValue) {
|
|
777
|
-
onChange && onChange(htmlTimeToCivilTime(newValue));
|
|
778
|
-
}
|
|
779
|
-
function generateEventHandler(handler) {
|
|
780
|
-
return (event) => {
|
|
781
|
-
const newValue = event.currentTarget.dataset.value;
|
|
782
|
-
if (newValue != undefined) {
|
|
783
|
-
handler(newValue);
|
|
784
|
-
}
|
|
785
|
-
};
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
|
-
|
|
789
46
|
const DEBOUNCE_TIME = 300;
|
|
790
47
|
function useTimePredict({ value, handleChange }) {
|
|
791
48
|
const IS_12_HOUR_FORMAT = React.useRef(Intl.DateTimeFormat(navigator.language, {
|
|
@@ -928,17 +185,12 @@ function InputTime(_a) {
|
|
|
928
185
|
var { defaultValue, value, onChange } = _a, params = tslib_es6.__rest(_a, ["defaultValue", "value", "onChange"]);
|
|
929
186
|
const ref = React.useRef(null);
|
|
930
187
|
const { setTypedTime } = useTimePredict({ value, handleChange });
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
} })));
|
|
938
|
-
}
|
|
939
|
-
else {
|
|
940
|
-
return (React__default["default"].createElement(InputTimeSafari, Object.assign({ defaultValue: defaultValue, value: value, onChange: onChange }, params)));
|
|
941
|
-
}
|
|
188
|
+
const fieldProps = Object.assign(Object.assign(Object.assign({ onChange: handleChange }, (defaultValue && { defaultValue: civilTimeToHTMLTime(defaultValue) })), (!defaultValue && { value: civilTimeToHTMLTime(value) })), params);
|
|
189
|
+
return (React__default["default"].createElement(FormField.FormField, Object.assign({ inputRef: ref, type: "time" }, fieldProps, { onBlur: handleBlur, onKeyUp: e => {
|
|
190
|
+
var _a;
|
|
191
|
+
(_a = fieldProps.onKeyUp) === null || _a === void 0 ? void 0 : _a.call(fieldProps, e);
|
|
192
|
+
!isNaN(parseInt(e.key, 10)) && setTypedTime(prev => prev + e.key);
|
|
193
|
+
} })));
|
|
942
194
|
function handleChange(newValue) {
|
|
943
195
|
onChange === null || onChange === void 0 ? void 0 : onChange(htmlTimeToCivilTime(newValue));
|
|
944
196
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jobber/components",
|
|
3
|
-
"version": "4.76.
|
|
3
|
+
"version": "4.76.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -84,5 +84,5 @@
|
|
|
84
84
|
"> 1%",
|
|
85
85
|
"IE 10"
|
|
86
86
|
],
|
|
87
|
-
"gitHead": "
|
|
87
|
+
"gitHead": "5ab4d688b0e7a05baf67fa6838bca3da2352b9e8"
|
|
88
88
|
}
|