@spectrum-web-components/number-field 0.3.13 → 0.4.1-devmode.7
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/package.json +26 -13
- package/sp-number-field.dev.js +3 -0
- package/sp-number-field.dev.js.map +7 -0
- package/sp-number-field.js +3 -14
- package/sp-number-field.js.map +7 -1
- package/src/NumberField.dev.js +499 -0
- package/src/NumberField.dev.js.map +7 -0
- package/src/NumberField.js +452 -504
- package/src/NumberField.js.map +7 -1
- package/src/index.dev.js +2 -0
- package/src/index.dev.js.map +7 -0
- package/src/index.js +2 -13
- package/src/index.js.map +7 -1
- package/src/number-field.css.dev.js +147 -0
- package/src/number-field.css.dev.js.map +7 -0
- package/src/number-field.css.js +6 -15
- package/src/number-field.css.js.map +7 -1
- package/src/spectrum-number-field.css.dev.js +143 -0
- package/src/spectrum-number-field.css.dev.js.map +7 -0
- package/src/spectrum-number-field.css.js +3 -14
- package/src/spectrum-number-field.css.js.map +7 -1
- package/stories/number-field.stories.js +215 -229
- package/stories/number-field.stories.js.map +7 -1
- package/test/benchmark/basic-test.js +5 -16
- package/test/benchmark/basic-test.js.map +7 -1
- package/test/helpers.js +44 -55
- package/test/helpers.js.map +7 -1
- package/test/inputs.test.js +340 -350
- package/test/inputs.test.js.map +7 -1
- package/test/number-field.test-vrt.js +4 -15
- package/test/number-field.test-vrt.js.map +7 -1
- package/test/number-field.test.js +1135 -1135
- package/test/number-field.test.js.map +7 -1
package/src/NumberField.js
CHANGED
|
@@ -1,417 +1,380 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import
|
|
22
|
-
import
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
+
if (decorator = decorators[i])
|
|
7
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
+
if (kind && result)
|
|
9
|
+
__defProp(target, key, result);
|
|
10
|
+
return result;
|
|
11
|
+
};
|
|
12
|
+
import {
|
|
13
|
+
html
|
|
14
|
+
} from "@spectrum-web-components/base";
|
|
15
|
+
import {
|
|
16
|
+
property,
|
|
17
|
+
query
|
|
18
|
+
} from "@spectrum-web-components/base/src/decorators.js";
|
|
19
|
+
import { streamingListener } from "@spectrum-web-components/base/src/streaming-listener.js";
|
|
20
|
+
import { NumberFormatter, NumberParser } from "@internationalized/number";
|
|
21
|
+
import "@spectrum-web-components/icons-ui/icons/sp-icon-chevron75.js";
|
|
22
|
+
import "@spectrum-web-components/action-button/sp-action-button.js";
|
|
23
|
+
import {
|
|
24
|
+
isAndroid,
|
|
25
|
+
isIPhone
|
|
26
|
+
} from "@spectrum-web-components/shared/src/platform.js";
|
|
27
|
+
import { TextfieldBase } from "@spectrum-web-components/textfield";
|
|
28
|
+
import chevronStyles from "@spectrum-web-components/icon/src/spectrum-icon-chevron.css.js";
|
|
29
|
+
import styles from "./number-field.css.js";
|
|
23
30
|
export const FRAMES_PER_CHANGE = 5;
|
|
24
|
-
export const indeterminatePlaceholder =
|
|
31
|
+
export const indeterminatePlaceholder = "-";
|
|
25
32
|
export const remapMultiByteCharacters = {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
33
|
+
"\uFF11": "1",
|
|
34
|
+
"\uFF12": "2",
|
|
35
|
+
"\uFF13": "3",
|
|
36
|
+
"\uFF14": "4",
|
|
37
|
+
"\uFF15": "5",
|
|
38
|
+
"\uFF16": "6",
|
|
39
|
+
"\uFF17": "7",
|
|
40
|
+
"\uFF18": "8",
|
|
41
|
+
"\uFF19": "9",
|
|
42
|
+
"\uFF10": "0",
|
|
43
|
+
"\u3001": ",",
|
|
44
|
+
"\uFF0C": ",",
|
|
45
|
+
"\u3002": ".",
|
|
46
|
+
"\uFF0E": ".",
|
|
47
|
+
"\uFF05": "%",
|
|
48
|
+
"\uFF0B": "+",
|
|
49
|
+
\u30FC: "-"
|
|
43
50
|
};
|
|
44
|
-
/**
|
|
45
|
-
* @element sp-number-field
|
|
46
|
-
* @slot help-text - default or non-negative help text to associate to your form element
|
|
47
|
-
* @slot negative-help-text - negative help text to associate to your form element when `invalid`
|
|
48
|
-
*/
|
|
49
51
|
export class NumberField extends TextfieldBase {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
if (this.disabled || this.readonly) {
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
const min = typeof this.min !== 'undefined' ? this.min : 0;
|
|
185
|
-
let value = this.value;
|
|
186
|
-
value += count * this._step;
|
|
187
|
-
if (isNaN(this.value)) {
|
|
188
|
-
this.value = min;
|
|
189
|
-
}
|
|
190
|
-
else {
|
|
191
|
-
this.value = value;
|
|
192
|
-
}
|
|
193
|
-
this.dispatchEvent(new Event('input', { bubbles: true, composed: true }));
|
|
194
|
-
this.indeterminate = false;
|
|
195
|
-
this.focus();
|
|
196
|
-
}
|
|
197
|
-
increment(factor = 1) {
|
|
198
|
-
this.stepBy(1 * factor);
|
|
199
|
-
}
|
|
200
|
-
decrement(factor = 1) {
|
|
201
|
-
this.stepBy(-1 * factor);
|
|
202
|
-
}
|
|
203
|
-
handleKeydown(event) {
|
|
204
|
-
switch (event.code) {
|
|
205
|
-
case 'ArrowUp':
|
|
206
|
-
event.preventDefault();
|
|
207
|
-
this.increment(event.shiftKey ? this.stepModifier : 1);
|
|
208
|
-
this.dispatchEvent(new Event('change', { bubbles: true, composed: true }));
|
|
209
|
-
break;
|
|
210
|
-
case 'ArrowDown':
|
|
211
|
-
event.preventDefault();
|
|
212
|
-
this.decrement(event.shiftKey ? this.stepModifier : 1);
|
|
213
|
-
this.dispatchEvent(new Event('change', { bubbles: true, composed: true }));
|
|
214
|
-
break;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
onScroll(event) {
|
|
52
|
+
constructor() {
|
|
53
|
+
super(...arguments);
|
|
54
|
+
this.focused = false;
|
|
55
|
+
this._forcedUnit = "";
|
|
56
|
+
this.formatOptions = {};
|
|
57
|
+
this.hideStepper = false;
|
|
58
|
+
this.indeterminate = false;
|
|
59
|
+
this.keyboardFocused = false;
|
|
60
|
+
this.resolvedLanguage = document.documentElement.lang || navigator.language;
|
|
61
|
+
this.stepperActive = false;
|
|
62
|
+
this.stepModifier = 10;
|
|
63
|
+
this._value = NaN;
|
|
64
|
+
this._trackingValue = "";
|
|
65
|
+
this.changeCount = 0;
|
|
66
|
+
this.wasIndeterminate = false;
|
|
67
|
+
}
|
|
68
|
+
static get styles() {
|
|
69
|
+
return [...super.styles, styles, chevronStyles];
|
|
70
|
+
}
|
|
71
|
+
set value(rawValue) {
|
|
72
|
+
const value = this.validateInput(rawValue);
|
|
73
|
+
if (value === this.value) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const oldValue = this._value;
|
|
77
|
+
this._value = value;
|
|
78
|
+
this.requestUpdate("value", oldValue);
|
|
79
|
+
}
|
|
80
|
+
get value() {
|
|
81
|
+
return this._value;
|
|
82
|
+
}
|
|
83
|
+
get inputValue() {
|
|
84
|
+
return this.indeterminate ? this.formattedValue : this.inputElement.value;
|
|
85
|
+
}
|
|
86
|
+
get valueAsString() {
|
|
87
|
+
return this._value.toString();
|
|
88
|
+
}
|
|
89
|
+
set valueAsString(value) {
|
|
90
|
+
this.value = this.numberParser.parse(value);
|
|
91
|
+
}
|
|
92
|
+
get formattedValue() {
|
|
93
|
+
if (isNaN(this.value))
|
|
94
|
+
return "";
|
|
95
|
+
return this.numberFormatter.format(this.value) + (this.focused ? "" : this._forcedUnit);
|
|
96
|
+
}
|
|
97
|
+
convertValueToNumber(value) {
|
|
98
|
+
return this.numberParser.parse(value);
|
|
99
|
+
}
|
|
100
|
+
get _step() {
|
|
101
|
+
var _a;
|
|
102
|
+
if (typeof this.step !== "undefined") {
|
|
103
|
+
return this.step;
|
|
104
|
+
}
|
|
105
|
+
if (((_a = this.formatOptions) == null ? void 0 : _a.style) === "percent") {
|
|
106
|
+
return 0.01;
|
|
107
|
+
}
|
|
108
|
+
return 1;
|
|
109
|
+
}
|
|
110
|
+
handlePointerdown(event) {
|
|
111
|
+
if (event.button !== 0) {
|
|
112
|
+
event.preventDefault();
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
this.stepperActive = true;
|
|
116
|
+
this.buttons.setPointerCapture(event.pointerId);
|
|
117
|
+
const stepUpRect = this.buttons.children[0].getBoundingClientRect();
|
|
118
|
+
const stepDownRect = this.buttons.children[1].getBoundingClientRect();
|
|
119
|
+
this.findChange = (event2) => {
|
|
120
|
+
if (event2.clientX >= stepUpRect.x && event2.clientY >= stepUpRect.y && event2.clientX <= stepUpRect.x + stepUpRect.width && event2.clientY <= stepUpRect.y + stepUpRect.height) {
|
|
121
|
+
this.change = (event3) => this.increment(event3.shiftKey ? this.stepModifier : 1);
|
|
122
|
+
} else if (event2.clientX >= stepDownRect.x && event2.clientY >= stepDownRect.y && event2.clientX <= stepDownRect.x + stepDownRect.width && event2.clientY <= stepDownRect.y + stepDownRect.height) {
|
|
123
|
+
this.change = (event3) => this.decrement(event3.shiftKey ? this.stepModifier : 1);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
this.findChange(event);
|
|
127
|
+
this.startChange(event);
|
|
128
|
+
}
|
|
129
|
+
startChange(event) {
|
|
130
|
+
this.changeCount = 0;
|
|
131
|
+
this.doChange(event);
|
|
132
|
+
this.safty = setTimeout(() => {
|
|
133
|
+
this.doNextChange(event);
|
|
134
|
+
}, 400);
|
|
135
|
+
}
|
|
136
|
+
doChange(event) {
|
|
137
|
+
this.change(event);
|
|
138
|
+
}
|
|
139
|
+
handlePointermove(event) {
|
|
140
|
+
this.findChange(event);
|
|
141
|
+
}
|
|
142
|
+
handlePointerup(event) {
|
|
143
|
+
this.buttons.releasePointerCapture(event.pointerId);
|
|
144
|
+
cancelAnimationFrame(this.nextChange);
|
|
145
|
+
clearTimeout(this.safty);
|
|
146
|
+
this.dispatchEvent(new Event("change", { bubbles: true, composed: true }));
|
|
147
|
+
this.stepperActive = false;
|
|
148
|
+
}
|
|
149
|
+
doNextChange(event) {
|
|
150
|
+
this.changeCount += 1;
|
|
151
|
+
if (this.changeCount % FRAMES_PER_CHANGE === 0) {
|
|
152
|
+
this.doChange(event);
|
|
153
|
+
}
|
|
154
|
+
return requestAnimationFrame(() => {
|
|
155
|
+
this.nextChange = this.doNextChange(event);
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
stepBy(count) {
|
|
159
|
+
if (this.disabled || this.readonly) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
const min = typeof this.min !== "undefined" ? this.min : 0;
|
|
163
|
+
let value = this.value;
|
|
164
|
+
value += count * this._step;
|
|
165
|
+
if (isNaN(this.value)) {
|
|
166
|
+
this.value = min;
|
|
167
|
+
} else {
|
|
168
|
+
this.value = value;
|
|
169
|
+
}
|
|
170
|
+
this.dispatchEvent(new Event("input", { bubbles: true, composed: true }));
|
|
171
|
+
this.indeterminate = false;
|
|
172
|
+
this.focus();
|
|
173
|
+
}
|
|
174
|
+
increment(factor = 1) {
|
|
175
|
+
this.stepBy(1 * factor);
|
|
176
|
+
}
|
|
177
|
+
decrement(factor = 1) {
|
|
178
|
+
this.stepBy(-1 * factor);
|
|
179
|
+
}
|
|
180
|
+
handleKeydown(event) {
|
|
181
|
+
switch (event.code) {
|
|
182
|
+
case "ArrowUp":
|
|
218
183
|
event.preventDefault();
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
184
|
+
this.increment(event.shiftKey ? this.stepModifier : 1);
|
|
185
|
+
this.dispatchEvent(new Event("change", { bubbles: true, composed: true }));
|
|
186
|
+
break;
|
|
187
|
+
case "ArrowDown":
|
|
188
|
+
event.preventDefault();
|
|
189
|
+
this.decrement(event.shiftKey ? this.stepModifier : 1);
|
|
190
|
+
this.dispatchEvent(new Event("change", { bubbles: true, composed: true }));
|
|
191
|
+
break;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
onScroll(event) {
|
|
195
|
+
event.preventDefault();
|
|
196
|
+
const direction = event.shiftKey ? event.deltaX / Math.abs(event.deltaX) : event.deltaY / Math.abs(event.deltaY);
|
|
197
|
+
if (direction !== 0 && !isNaN(direction)) {
|
|
198
|
+
this.stepBy(direction * (event.shiftKey ? this.stepModifier : 1));
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
onFocus() {
|
|
202
|
+
super.onFocus();
|
|
203
|
+
this._trackingValue = this.inputValue;
|
|
204
|
+
this.keyboardFocused = !this.readonly && true;
|
|
205
|
+
this.addEventListener("wheel", this.onScroll, { passive: false });
|
|
206
|
+
}
|
|
207
|
+
onBlur() {
|
|
208
|
+
super.onBlur();
|
|
209
|
+
this.keyboardFocused = !this.readonly && false;
|
|
210
|
+
this.removeEventListener("wheel", this.onScroll);
|
|
211
|
+
}
|
|
212
|
+
handleFocusin() {
|
|
213
|
+
this.focused = !this.readonly && true;
|
|
214
|
+
this.keyboardFocused = !this.readonly && true;
|
|
215
|
+
}
|
|
216
|
+
handleFocusout() {
|
|
217
|
+
this.focused = !this.readonly && false;
|
|
218
|
+
this.keyboardFocused = !this.readonly && false;
|
|
219
|
+
}
|
|
220
|
+
handleChange() {
|
|
221
|
+
const value = this.convertValueToNumber(this.inputValue);
|
|
222
|
+
if (this.wasIndeterminate) {
|
|
223
|
+
this.wasIndeterminate = false;
|
|
224
|
+
this.indeterminateValue = void 0;
|
|
225
|
+
if (isNaN(value)) {
|
|
226
|
+
this.indeterminate = true;
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
this.value = value;
|
|
231
|
+
super.handleChange();
|
|
232
|
+
}
|
|
233
|
+
handleInput() {
|
|
234
|
+
if (this.indeterminate) {
|
|
235
|
+
this.wasIndeterminate = true;
|
|
236
|
+
this.indeterminateValue = this.value;
|
|
237
|
+
this.inputElement.value = this.inputElement.value.replace(indeterminatePlaceholder, "");
|
|
238
|
+
}
|
|
239
|
+
const { value: originalValue, selectionStart } = this.inputElement;
|
|
240
|
+
const value = originalValue.split("").map((char) => remapMultiByteCharacters[char] || char).join("");
|
|
241
|
+
if (this.numberParser.isValidPartialNumber(value)) {
|
|
242
|
+
const valueAsNumber = this.convertValueToNumber(value);
|
|
243
|
+
if (!value && this.indeterminateValue) {
|
|
244
|
+
this.indeterminate = true;
|
|
245
|
+
this._value = this.indeterminateValue;
|
|
246
|
+
} else {
|
|
247
|
+
this.indeterminate = false;
|
|
248
|
+
this._value = this.validateInput(valueAsNumber);
|
|
249
|
+
}
|
|
250
|
+
this._trackingValue = value;
|
|
251
|
+
this.inputElement.value = value;
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
const currentLength = value.length;
|
|
255
|
+
const previousLength = this._trackingValue.length;
|
|
256
|
+
const nextSelectStart = (selectionStart || currentLength) - (currentLength - previousLength);
|
|
257
|
+
this.inputElement.value = this.indeterminate ? indeterminatePlaceholder : this._trackingValue;
|
|
258
|
+
this.inputElement.setSelectionRange(nextSelectStart, nextSelectStart);
|
|
259
|
+
}
|
|
260
|
+
validateInput(value) {
|
|
261
|
+
if (typeof this.min !== "undefined") {
|
|
262
|
+
value = Math.max(this.min, value);
|
|
263
|
+
}
|
|
264
|
+
if (typeof this.max !== "undefined") {
|
|
265
|
+
value = Math.min(this.max, value);
|
|
266
|
+
}
|
|
267
|
+
if (this.step) {
|
|
268
|
+
const min = typeof this.min !== "undefined" ? this.min : 0;
|
|
269
|
+
const moduloStep = (value - min) % this.step;
|
|
270
|
+
const fallsOnStep = moduloStep === 0;
|
|
271
|
+
if (!fallsOnStep) {
|
|
272
|
+
const overUnder = Math.round(moduloStep / this.step);
|
|
273
|
+
if (overUnder === 1) {
|
|
274
|
+
value += this.step - moduloStep;
|
|
275
|
+
} else {
|
|
276
|
+
value -= moduloStep;
|
|
298
277
|
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
const fallsOnStep = moduloStep === 0;
|
|
304
|
-
if (!fallsOnStep) {
|
|
305
|
-
const overUnder = Math.round(moduloStep / this.step);
|
|
306
|
-
if (overUnder === 1) {
|
|
307
|
-
value += this.step - moduloStep;
|
|
308
|
-
}
|
|
309
|
-
else {
|
|
310
|
-
value -= moduloStep;
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
if (typeof this.max !== 'undefined') {
|
|
314
|
-
while (value > this.max) {
|
|
315
|
-
value -= this.step;
|
|
316
|
-
}
|
|
317
|
-
}
|
|
278
|
+
}
|
|
279
|
+
if (typeof this.max !== "undefined") {
|
|
280
|
+
while (value > this.max) {
|
|
281
|
+
value -= this.step;
|
|
318
282
|
}
|
|
319
|
-
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
return value;
|
|
286
|
+
}
|
|
287
|
+
get displayValue() {
|
|
288
|
+
const indeterminateValue = this.focused ? "" : indeterminatePlaceholder;
|
|
289
|
+
return this.indeterminate ? indeterminateValue : this.formattedValue;
|
|
290
|
+
}
|
|
291
|
+
clearNumberFormatterCache() {
|
|
292
|
+
this._numberFormatter = void 0;
|
|
293
|
+
this._numberParser = void 0;
|
|
294
|
+
}
|
|
295
|
+
get numberFormatter() {
|
|
296
|
+
if (!this._numberFormatter || !this._numberFormatterFocused) {
|
|
297
|
+
const {
|
|
298
|
+
style,
|
|
299
|
+
unit,
|
|
300
|
+
unitDisplay,
|
|
301
|
+
...formatOptionsNoUnit
|
|
302
|
+
} = this.formatOptions;
|
|
303
|
+
if (style !== "unit") {
|
|
304
|
+
formatOptionsNoUnit.style = style;
|
|
305
|
+
}
|
|
306
|
+
this._numberFormatterFocused = new NumberFormatter(this.resolvedLanguage, formatOptionsNoUnit);
|
|
307
|
+
try {
|
|
308
|
+
this._numberFormatter = new NumberFormatter(this.resolvedLanguage, this.formatOptions);
|
|
309
|
+
this._forcedUnit = "";
|
|
310
|
+
this._numberFormatter.format(1);
|
|
311
|
+
} catch (error) {
|
|
312
|
+
if (style === "unit") {
|
|
313
|
+
this._forcedUnit = unit;
|
|
349
314
|
}
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
315
|
+
this._numberFormatter = this._numberFormatterFocused;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
return this.focused ? this._numberFormatterFocused : this._numberFormatter;
|
|
319
|
+
}
|
|
320
|
+
get numberParser() {
|
|
321
|
+
if (!this._numberParser || !this._numberParserFocused) {
|
|
322
|
+
const {
|
|
323
|
+
style,
|
|
324
|
+
unit,
|
|
325
|
+
unitDisplay,
|
|
326
|
+
...formatOptionsNoUnit
|
|
327
|
+
} = this.formatOptions;
|
|
328
|
+
if (style !== "unit") {
|
|
329
|
+
formatOptionsNoUnit.style = style;
|
|
330
|
+
}
|
|
331
|
+
this._numberParserFocused = new NumberParser(this.resolvedLanguage, formatOptionsNoUnit);
|
|
332
|
+
try {
|
|
333
|
+
this._numberParser = new NumberParser(this.resolvedLanguage, this.formatOptions);
|
|
334
|
+
this._forcedUnit = "";
|
|
335
|
+
this._numberParser.parse("0");
|
|
336
|
+
} catch (error) {
|
|
337
|
+
if (style === "unit") {
|
|
338
|
+
this._forcedUnit = unit;
|
|
374
339
|
}
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
340
|
+
this._numberParser = this._numberParserFocused;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
return this.focused ? this._numberParserFocused : this._numberParser;
|
|
344
|
+
}
|
|
345
|
+
renderField() {
|
|
346
|
+
this.autocomplete = "off";
|
|
347
|
+
return html`
|
|
380
348
|
${super.renderField()}
|
|
381
|
-
${this.hideStepper
|
|
382
|
-
? html ``
|
|
383
|
-
: html `
|
|
349
|
+
${this.hideStepper ? html`` : html`
|
|
384
350
|
<span
|
|
385
351
|
class="buttons"
|
|
386
352
|
@focusin=${this.handleFocusin}
|
|
387
353
|
@focusout=${this.handleFocusout}
|
|
388
354
|
${streamingListener({
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
355
|
+
start: ["pointerdown", this.handlePointerdown],
|
|
356
|
+
streamInside: [
|
|
357
|
+
[
|
|
358
|
+
"pointermove",
|
|
359
|
+
"pointerenter",
|
|
360
|
+
"pointerleave",
|
|
361
|
+
"pointerover",
|
|
362
|
+
"pointerout"
|
|
363
|
+
],
|
|
364
|
+
this.handlePointermove
|
|
365
|
+
],
|
|
366
|
+
end: [
|
|
367
|
+
["pointerup", "pointercancel"],
|
|
368
|
+
this.handlePointerup
|
|
369
|
+
]
|
|
370
|
+
})}
|
|
405
371
|
>
|
|
406
372
|
<sp-action-button
|
|
407
373
|
class="stepUp"
|
|
408
374
|
label="Increment"
|
|
409
375
|
tabindex="-1"
|
|
410
376
|
?focused=${this.focused}
|
|
411
|
-
?disabled=${this.disabled ||
|
|
412
|
-
this.readonly ||
|
|
413
|
-
(typeof this.max !== 'undefined' &&
|
|
414
|
-
this.value === this.max)}
|
|
377
|
+
?disabled=${this.disabled || this.readonly || typeof this.max !== "undefined" && this.value === this.max}
|
|
415
378
|
?quiet=${this.quiet}
|
|
416
379
|
>
|
|
417
380
|
<sp-icon-chevron75
|
|
@@ -424,10 +387,7 @@ export class NumberField extends TextfieldBase {
|
|
|
424
387
|
label="Decrement"
|
|
425
388
|
tabindex="-1"
|
|
426
389
|
?focused=${this.focused}
|
|
427
|
-
?disabled=${this.disabled ||
|
|
428
|
-
this.readonly ||
|
|
429
|
-
(typeof this.min !== 'undefined' &&
|
|
430
|
-
this.value === this.min)}
|
|
390
|
+
?disabled=${this.disabled || this.readonly || typeof this.min !== "undefined" && this.value === this.min}
|
|
431
391
|
?quiet=${this.quiet}
|
|
432
392
|
>
|
|
433
393
|
<sp-icon-chevron75
|
|
@@ -438,114 +398,102 @@ export class NumberField extends TextfieldBase {
|
|
|
438
398
|
</span>
|
|
439
399
|
`}
|
|
440
400
|
`;
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
401
|
+
}
|
|
402
|
+
update(changes) {
|
|
403
|
+
if (changes.has("formatOptions") || changes.has("resolvedLanguage")) {
|
|
404
|
+
this.clearNumberFormatterCache();
|
|
405
|
+
}
|
|
406
|
+
if (changes.has("value") || changes.has("max") || changes.has("min")) {
|
|
407
|
+
const value = this.numberParser.parse(this.formattedValue.replace(this._forcedUnit, ""));
|
|
408
|
+
this.value = value;
|
|
409
|
+
}
|
|
410
|
+
super.update(changes);
|
|
411
|
+
}
|
|
412
|
+
willUpdate() {
|
|
413
|
+
this.multiline = false;
|
|
414
|
+
}
|
|
415
|
+
firstUpdated(changes) {
|
|
416
|
+
super.firstUpdated(changes);
|
|
417
|
+
this.addEventListener("keydown", this.handleKeydown);
|
|
418
|
+
}
|
|
419
|
+
updated(changes) {
|
|
420
|
+
if (changes.has("min") || changes.has("formatOptions")) {
|
|
421
|
+
let inputMode = "numeric";
|
|
422
|
+
const hasNegative = typeof this.min !== "undefined" && this.min < 0;
|
|
423
|
+
const { maximumFractionDigits } = this.formatOptions;
|
|
424
|
+
const hasDecimals = maximumFractionDigits && maximumFractionDigits > 0;
|
|
425
|
+
if (isIPhone()) {
|
|
426
|
+
if (hasNegative) {
|
|
427
|
+
inputMode = "text";
|
|
428
|
+
} else if (hasDecimals) {
|
|
429
|
+
inputMode = "decimal";
|
|
445
430
|
}
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
firstUpdated(changes) {
|
|
452
|
-
super.firstUpdated(changes);
|
|
453
|
-
this.addEventListener('keydown', this.handleKeydown);
|
|
454
|
-
}
|
|
455
|
-
updated(changes) {
|
|
456
|
-
if (changes.has('value') ||
|
|
457
|
-
changes.has('max') ||
|
|
458
|
-
changes.has('min') ||
|
|
459
|
-
changes.has('min')) {
|
|
460
|
-
const value = this.numberParser.parse(this.inputValue.replace(this._forcedUnit, ''));
|
|
461
|
-
this.value = value;
|
|
431
|
+
} else if (isAndroid()) {
|
|
432
|
+
if (hasNegative) {
|
|
433
|
+
inputMode = "numeric";
|
|
434
|
+
} else if (hasDecimals) {
|
|
435
|
+
inputMode = "decimal";
|
|
462
436
|
}
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
// decimal does not have a minus key.
|
|
483
|
-
if (hasNegative) {
|
|
484
|
-
inputMode = 'numeric';
|
|
485
|
-
}
|
|
486
|
-
else if (hasDecimals) {
|
|
487
|
-
inputMode = 'decimal';
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
this.inputElement.inputMode = inputMode;
|
|
437
|
+
}
|
|
438
|
+
this.inputElement.inputMode = inputMode;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
connectedCallback() {
|
|
442
|
+
super.connectedCallback();
|
|
443
|
+
this.resolveLanguage();
|
|
444
|
+
}
|
|
445
|
+
disconnectedCallback() {
|
|
446
|
+
this.resolveLanguage();
|
|
447
|
+
super.disconnectedCallback();
|
|
448
|
+
}
|
|
449
|
+
resolveLanguage() {
|
|
450
|
+
const queryThemeEvent = new CustomEvent("sp-language-context", {
|
|
451
|
+
bubbles: true,
|
|
452
|
+
composed: true,
|
|
453
|
+
detail: {
|
|
454
|
+
callback: (lang) => {
|
|
455
|
+
this.resolvedLanguage = lang;
|
|
491
456
|
}
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
disconnectedCallback() {
|
|
498
|
-
this.resolveLanguage();
|
|
499
|
-
super.disconnectedCallback();
|
|
500
|
-
}
|
|
501
|
-
resolveLanguage() {
|
|
502
|
-
const queryThemeEvent = new CustomEvent('sp-language-context', {
|
|
503
|
-
bubbles: true,
|
|
504
|
-
composed: true,
|
|
505
|
-
detail: {
|
|
506
|
-
callback: (lang) => {
|
|
507
|
-
this.resolvedLanguage = lang;
|
|
508
|
-
},
|
|
509
|
-
},
|
|
510
|
-
cancelable: true,
|
|
511
|
-
});
|
|
512
|
-
this.dispatchEvent(queryThemeEvent);
|
|
513
|
-
}
|
|
457
|
+
},
|
|
458
|
+
cancelable: true
|
|
459
|
+
});
|
|
460
|
+
this.dispatchEvent(queryThemeEvent);
|
|
461
|
+
}
|
|
514
462
|
}
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
], NumberField.prototype, "buttons",
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
], NumberField.prototype, "focused",
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
], NumberField.prototype, "formatOptions",
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
], NumberField.prototype, "hideStepper",
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
], NumberField.prototype, "indeterminate",
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
], NumberField.prototype, "keyboardFocused",
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
], NumberField.prototype, "max",
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
], NumberField.prototype, "min",
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
], NumberField.prototype, "resolvedLanguage",
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
], NumberField.prototype, "step",
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
], NumberField.prototype, "stepModifier",
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
], NumberField.prototype, "value",
|
|
551
|
-
//# sourceMappingURL=NumberField.js.map
|
|
463
|
+
__decorateClass([
|
|
464
|
+
query(".buttons")
|
|
465
|
+
], NumberField.prototype, "buttons", 2);
|
|
466
|
+
__decorateClass([
|
|
467
|
+
property({ type: Boolean, reflect: true })
|
|
468
|
+
], NumberField.prototype, "focused", 2);
|
|
469
|
+
__decorateClass([
|
|
470
|
+
property({ type: Object, attribute: "format-options" })
|
|
471
|
+
], NumberField.prototype, "formatOptions", 2);
|
|
472
|
+
__decorateClass([
|
|
473
|
+
property({ type: Boolean, reflect: true, attribute: "hide-stepper" })
|
|
474
|
+
], NumberField.prototype, "hideStepper", 2);
|
|
475
|
+
__decorateClass([
|
|
476
|
+
property({ type: Boolean, reflect: true })
|
|
477
|
+
], NumberField.prototype, "indeterminate", 2);
|
|
478
|
+
__decorateClass([
|
|
479
|
+
property({ type: Boolean, reflect: true, attribute: "keyboard-focused" })
|
|
480
|
+
], NumberField.prototype, "keyboardFocused", 2);
|
|
481
|
+
__decorateClass([
|
|
482
|
+
property({ type: Number })
|
|
483
|
+
], NumberField.prototype, "max", 2);
|
|
484
|
+
__decorateClass([
|
|
485
|
+
property({ type: Number })
|
|
486
|
+
], NumberField.prototype, "min", 2);
|
|
487
|
+
__decorateClass([
|
|
488
|
+
property({ attribute: false })
|
|
489
|
+
], NumberField.prototype, "resolvedLanguage", 2);
|
|
490
|
+
__decorateClass([
|
|
491
|
+
property({ type: Number })
|
|
492
|
+
], NumberField.prototype, "step", 2);
|
|
493
|
+
__decorateClass([
|
|
494
|
+
property({ type: Number, reflect: true, attribute: "step-modifier" })
|
|
495
|
+
], NumberField.prototype, "stepModifier", 2);
|
|
496
|
+
__decorateClass([
|
|
497
|
+
property({ type: Number })
|
|
498
|
+
], NumberField.prototype, "value", 1);
|
|
499
|
+
//# sourceMappingURL=NumberField.js.map
|