@spectrum-web-components/number-field 0.3.12 → 0.4.1-devmode.0

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spectrum-web-components/number-field",
3
- "version": "0.3.12",
3
+ "version": "0.4.1-devmode.0+07474d44f",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -20,11 +20,24 @@
20
20
  "module": "src/index.js",
21
21
  "type": "module",
22
22
  "exports": {
23
- ".": "./src/index.js",
24
- "./src/*": "./src/*.js",
23
+ ".": {
24
+ "development": "./src/index.dev.js",
25
+ "default": "./src/index.js"
26
+ },
25
27
  "./package.json": "./package.json",
26
- "./sp-number-field": "./sp-number-field.js",
27
- "./sp-number-field.js": "./sp-number-field.js"
28
+ "./src/NumberField.js": {
29
+ "development": "./src/NumberField.dev.js",
30
+ "default": "./src/NumberField.js"
31
+ },
32
+ "./src/index.js": {
33
+ "development": "./src/index.dev.js",
34
+ "default": "./src/index.js"
35
+ },
36
+ "./src/number-field.css.js": "./src/number-field.css.js",
37
+ "./sp-number-field.js": {
38
+ "development": "./sp-number-field.dev.js",
39
+ "default": "./sp-number-field.js"
40
+ }
28
41
  },
29
42
  "scripts": {
30
43
  "test": "echo \"Error: run tests from mono-repo root.\" && exit 1"
@@ -45,22 +58,22 @@
45
58
  ],
46
59
  "dependencies": {
47
60
  "@internationalized/number": "^3.1.0",
48
- "@spectrum-web-components/action-button": "^0.8.6",
49
- "@spectrum-web-components/base": "^0.5.7",
50
- "@spectrum-web-components/icon": "^0.11.9",
51
- "@spectrum-web-components/icons-ui": "^0.8.9",
52
- "@spectrum-web-components/shared": "^0.14.2",
53
- "@spectrum-web-components/textfield": "^0.11.8",
61
+ "@spectrum-web-components/action-button": "^0.9.1-devmode.0+07474d44f",
62
+ "@spectrum-web-components/base": "^0.5.9-devmode.24+07474d44f",
63
+ "@spectrum-web-components/icon": "^0.11.12-devmode.0+07474d44f",
64
+ "@spectrum-web-components/icons-ui": "^0.8.12-devmode.0+07474d44f",
65
+ "@spectrum-web-components/shared": "^0.14.5-devmode.0+07474d44f",
66
+ "@spectrum-web-components/textfield": "^0.11.11-devmode.0+07474d44f",
54
67
  "tslib": "^2.0.0"
55
68
  },
56
69
  "devDependencies": {
57
70
  "@formatjs/intl-numberformat": "7.1.4",
58
- "@spectrum-css/stepper": "^3.0.24"
71
+ "@spectrum-css/stepper": "^3.0.26"
59
72
  },
60
73
  "types": "./src/index.d.ts",
61
74
  "customElements": "custom-elements.json",
62
75
  "sideEffects": [
63
76
  "./sp-*.js"
64
77
  ],
65
- "gitHead": "275ee61b152ac3eed0cd1603d8eab2aec90876a0"
78
+ "gitHead": "07474d44f6cee1db241b9ccf3dc812514ffbe7fa"
66
79
  }
@@ -0,0 +1,3 @@
1
+ import { NumberField } from "./src/NumberField.dev.js";
2
+ customElements.define("sp-number-field", NumberField);
3
+ //# sourceMappingURL=sp-number-field.dev.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["sp-number-field.ts"],
4
+ "sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { NumberField } from './src/NumberField.dev.js'\n\ncustomElements.define('sp-number-field', NumberField);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'sp-number-field': NumberField;\n }\n}\n"],
5
+ "mappings": "AAYA;AAEA,eAAe,OAAO,mBAAmB,WAAW;",
6
+ "names": []
7
+ }
@@ -1,14 +1,3 @@
1
- /*
2
- Copyright 2020 Adobe. All rights reserved.
3
- This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License. You may obtain a copy
5
- of the License at http://www.apache.org/licenses/LICENSE-2.0
6
-
7
- Unless required by applicable law or agreed to in writing, software distributed under
8
- the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- OF ANY KIND, either express or implied. See the License for the specific language
10
- governing permissions and limitations under the License.
11
- */
12
- import { NumberField } from './src/NumberField.js';
13
- customElements.define('sp-number-field', NumberField);
14
- //# sourceMappingURL=sp-number-field.js.map
1
+ import { NumberField } from "./src/NumberField.js";
2
+ customElements.define("sp-number-field", NumberField);
3
+ //# sourceMappingURL=sp-number-field.js.map
@@ -1 +1,7 @@
1
- {"version":3,"file":"sp-number-field.js","sourceRoot":"","sources":["sp-number-field.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,cAAc,CAAC,MAAM,CAAC,iBAAiB,EAAE,WAAW,CAAC,CAAC","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { NumberField } from './src/NumberField.js';\n\ncustomElements.define('sp-number-field', NumberField);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'sp-number-field': NumberField;\n }\n}\n"]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["sp-number-field.ts"],
4
+ "sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { NumberField } from './src/NumberField.js';\n\ncustomElements.define('sp-number-field', NumberField);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'sp-number-field': NumberField;\n }\n}\n"],
5
+ "mappings": "AAYA;AAEA,eAAe,OAAO,mBAAmB,WAAW;",
6
+ "names": []
7
+ }
@@ -91,6 +91,7 @@ export declare class NumberField extends TextfieldBase {
91
91
  private _numberParserFocused?;
92
92
  protected renderField(): TemplateResult;
93
93
  protected update(changes: PropertyValues): void;
94
+ willUpdate(): void;
94
95
  protected firstUpdated(changes: PropertyValues): void;
95
96
  protected updated(changes: PropertyValues<this>): void;
96
97
  connectedCallback(): void;
@@ -0,0 +1,499 @@
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";
30
+ export const FRAMES_PER_CHANGE = 5;
31
+ export const indeterminatePlaceholder = "-";
32
+ export const remapMultiByteCharacters = {
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: "-"
50
+ };
51
+ export class NumberField extends TextfieldBase {
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":
183
+ event.preventDefault();
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;
277
+ }
278
+ }
279
+ if (typeof this.max !== "undefined") {
280
+ while (value > this.max) {
281
+ value -= this.step;
282
+ }
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;
314
+ }
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;
339
+ }
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`
348
+ ${super.renderField()}
349
+ ${this.hideStepper ? html`` : html`
350
+ <span
351
+ class="buttons"
352
+ @focusin=${this.handleFocusin}
353
+ @focusout=${this.handleFocusout}
354
+ ${streamingListener({
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
+ })}
371
+ >
372
+ <sp-action-button
373
+ class="stepUp"
374
+ label="Increment"
375
+ tabindex="-1"
376
+ ?focused=${this.focused}
377
+ ?disabled=${this.disabled || this.readonly || typeof this.max !== "undefined" && this.value === this.max}
378
+ ?quiet=${this.quiet}
379
+ >
380
+ <sp-icon-chevron75
381
+ slot="icon"
382
+ class="stepper-icon spectrum-UIIcon-ChevronUp75"
383
+ ></sp-icon-chevron75>
384
+ </sp-action-button>
385
+ <sp-action-button
386
+ class="stepDown"
387
+ label="Decrement"
388
+ tabindex="-1"
389
+ ?focused=${this.focused}
390
+ ?disabled=${this.disabled || this.readonly || typeof this.min !== "undefined" && this.value === this.min}
391
+ ?quiet=${this.quiet}
392
+ >
393
+ <sp-icon-chevron75
394
+ slot="icon"
395
+ class="stepper-icon spectrum-UIIcon-ChevronDown75"
396
+ ></sp-icon-chevron75>
397
+ </sp-action-button>
398
+ </span>
399
+ `}
400
+ `;
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";
430
+ }
431
+ } else if (isAndroid()) {
432
+ if (hasNegative) {
433
+ inputMode = "numeric";
434
+ } else if (hasDecimals) {
435
+ inputMode = "decimal";
436
+ }
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;
456
+ }
457
+ },
458
+ cancelable: true
459
+ });
460
+ this.dispatchEvent(queryThemeEvent);
461
+ }
462
+ }
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.dev.js.map