@spectrum-web-components/number-field 0.4.2-devmode.0 → 0.5.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.4.2-devmode.0+1a8b29491",
3
+ "version": "0.5.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -58,12 +58,12 @@
58
58
  ],
59
59
  "dependencies": {
60
60
  "@internationalized/number": "^3.1.0",
61
- "@spectrum-web-components/action-button": "^0.9.2-devmode.0+1a8b29491",
62
- "@spectrum-web-components/base": "^0.6.1-devmode.0+1a8b29491",
63
- "@spectrum-web-components/icon": "^0.11.13-devmode.0+1a8b29491",
64
- "@spectrum-web-components/icons-ui": "^0.8.13-devmode.0+1a8b29491",
65
- "@spectrum-web-components/shared": "^0.14.6-devmode.0+1a8b29491",
66
- "@spectrum-web-components/textfield": "^0.12.1-devmode.0+1a8b29491",
61
+ "@spectrum-web-components/action-button": "^0.10.0",
62
+ "@spectrum-web-components/base": "^0.7.0",
63
+ "@spectrum-web-components/icon": "^0.12.0",
64
+ "@spectrum-web-components/icons-ui": "^0.9.0",
65
+ "@spectrum-web-components/shared": "^0.15.0",
66
+ "@spectrum-web-components/textfield": "^0.13.0",
67
67
  "tslib": "^2.0.0"
68
68
  },
69
69
  "devDependencies": {
@@ -76,5 +76,5 @@
76
76
  "./sp-*.js",
77
77
  "./**/*.dev.js"
78
78
  ],
79
- "gitHead": "1a8b294911ab377fa4f07e16eb016f1e3bf7b517"
79
+ "gitHead": "05c81318844160db3f8156144106e643507fef97"
80
80
  }
@@ -1,3 +1,2 @@
1
- import { NumberField } from "./src/NumberField.js";
2
- customElements.define("sp-number-field", NumberField);
1
+ import{NumberField as e}from"./src/NumberField.js";customElements.define("sp-number-field",e);
3
2
  //# sourceMappingURL=sp-number-field.js.map
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["sp-number-field.ts"],
4
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;",
5
+ "mappings": "AAYA,mDAEA,eAAe,OAAO,kBAAmB,CAAW",
6
6
  "names": []
7
7
  }
@@ -1,380 +1,18 @@
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`
1
+ var c=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var n=(h,e,t,i)=>{for(var r=i>1?void 0:i?m(e,t):e,s=h.length-1,o;s>=0;s--)(o=h[s])&&(r=(i?o(e,t,r):o(r))||r);return i&&r&&c(e,t,r),r};import{html as d}from"@spectrum-web-components/base";import{property as a,query as f}from"@spectrum-web-components/base/src/decorators.js";import{streamingListener as v}from"@spectrum-web-components/base/src/streaming-listener.js";import{NumberFormatter as l,NumberParser as p}from"@internationalized/number";import"@spectrum-web-components/icons-ui/icons/sp-icon-chevron75.js";import"@spectrum-web-components/action-button/sp-action-button.js";import{isAndroid as b,isIPhone as g}from"@spectrum-web-components/shared/src/platform.js";import{TextfieldBase as y}from"@spectrum-web-components/textfield";import P from"@spectrum-web-components/icon/src/spectrum-icon-chevron.css.js";import _ from"./number-field.css.js";export const FRAMES_PER_CHANGE=5,indeterminatePlaceholder="-",remapMultiByteCharacters={"\uFF11":"1","\uFF12":"2","\uFF13":"3","\uFF14":"4","\uFF15":"5","\uFF16":"6","\uFF17":"7","\uFF18":"8","\uFF19":"9","\uFF10":"0","\u3001":",","\uFF0C":",","\u3002":".","\uFF0E":".","\uFF05":"%","\uFF0B":"+",\u30FC:"-"};export class NumberField extends y{constructor(){super(...arguments);this.focused=!1;this._forcedUnit="";this.formatOptions={};this.hideStepper=!1;this.indeterminate=!1;this.keyboardFocused=!1;this.resolvedLanguage=document.documentElement.lang||navigator.language;this.stepperActive=!1;this.stepModifier=10;this._value=NaN;this._trackingValue="";this.changeCount=0;this.wasIndeterminate=!1}static get styles(){return[...super.styles,_,P]}set value(e){const t=this.validateInput(e);if(t===this.value)return;const i=this._value;this._value=t,this.requestUpdate("value",i)}get value(){return this._value}get inputValue(){return this.indeterminate?this.formattedValue:this.inputElement.value}get valueAsString(){return this._value.toString()}set valueAsString(e){this.value=this.numberParser.parse(e)}get formattedValue(){return isNaN(this.value)?"":this.numberFormatter.format(this.value)+(this.focused?"":this._forcedUnit)}convertValueToNumber(e){return this.numberParser.parse(e)}get _step(){var e;return typeof this.step!="undefined"?this.step:((e=this.formatOptions)==null?void 0:e.style)==="percent"?.01:1}handlePointerdown(e){if(e.button!==0){e.preventDefault();return}this.stepperActive=!0,this.buttons.setPointerCapture(e.pointerId);const t=this.buttons.children[0].getBoundingClientRect(),i=this.buttons.children[1].getBoundingClientRect();this.findChange=r=>{r.clientX>=t.x&&r.clientY>=t.y&&r.clientX<=t.x+t.width&&r.clientY<=t.y+t.height?this.change=s=>this.increment(s.shiftKey?this.stepModifier:1):r.clientX>=i.x&&r.clientY>=i.y&&r.clientX<=i.x+i.width&&r.clientY<=i.y+i.height&&(this.change=s=>this.decrement(s.shiftKey?this.stepModifier:1))},this.findChange(e),this.startChange(e)}startChange(e){this.changeCount=0,this.doChange(e),this.safty=setTimeout(()=>{this.doNextChange(e)},400)}doChange(e){this.change(e)}handlePointermove(e){this.findChange(e)}handlePointerup(e){this.buttons.releasePointerCapture(e.pointerId),cancelAnimationFrame(this.nextChange),clearTimeout(this.safty),this.dispatchEvent(new Event("change",{bubbles:!0,composed:!0})),this.stepperActive=!1}doNextChange(e){return this.changeCount+=1,this.changeCount%FRAMES_PER_CHANGE===0&&this.doChange(e),requestAnimationFrame(()=>{this.nextChange=this.doNextChange(e)})}stepBy(e){if(this.disabled||this.readonly)return;const t=typeof this.min!="undefined"?this.min:0;let i=this.value;i+=e*this._step,isNaN(this.value)?this.value=t:this.value=i,this.dispatchEvent(new Event("input",{bubbles:!0,composed:!0})),this.indeterminate=!1,this.focus()}increment(e=1){this.stepBy(1*e)}decrement(e=1){this.stepBy(-1*e)}handleKeydown(e){switch(e.code){case"ArrowUp":e.preventDefault(),this.increment(e.shiftKey?this.stepModifier:1),this.dispatchEvent(new Event("change",{bubbles:!0,composed:!0}));break;case"ArrowDown":e.preventDefault(),this.decrement(e.shiftKey?this.stepModifier:1),this.dispatchEvent(new Event("change",{bubbles:!0,composed:!0}));break}}onScroll(e){e.preventDefault();const t=e.shiftKey?e.deltaX/Math.abs(e.deltaX):e.deltaY/Math.abs(e.deltaY);t!==0&&!isNaN(t)&&this.stepBy(t*(e.shiftKey?this.stepModifier:1))}onFocus(){super.onFocus(),this._trackingValue=this.inputValue,this.keyboardFocused=!this.readonly&&!0,this.addEventListener("wheel",this.onScroll,{passive:!1})}onBlur(){super.onBlur(),this.keyboardFocused=!this.readonly&&!1,this.removeEventListener("wheel",this.onScroll)}handleFocusin(){this.focused=!this.readonly&&!0,this.keyboardFocused=!this.readonly&&!0}handleFocusout(){this.focused=!this.readonly&&!1,this.keyboardFocused=!this.readonly&&!1}handleChange(){const e=this.convertValueToNumber(this.inputValue);if(this.wasIndeterminate&&(this.wasIndeterminate=!1,this.indeterminateValue=void 0,isNaN(e))){this.indeterminate=!0;return}this.value=e,super.handleChange()}handleInput(){this.indeterminate&&(this.wasIndeterminate=!0,this.indeterminateValue=this.value,this.inputElement.value=this.inputElement.value.replace(indeterminatePlaceholder,""));const{value:e,selectionStart:t}=this.inputElement,i=e.split("").map(u=>remapMultiByteCharacters[u]||u).join("");if(this.numberParser.isValidPartialNumber(i)){const u=this.convertValueToNumber(i);!i&&this.indeterminateValue?(this.indeterminate=!0,this._value=this.indeterminateValue):(this.indeterminate=!1,this._value=this.validateInput(u)),this._trackingValue=i,this.inputElement.value=i;return}const r=i.length,s=this._trackingValue.length,o=(t||r)-(r-s);this.inputElement.value=this.indeterminate?indeterminatePlaceholder:this._trackingValue,this.inputElement.setSelectionRange(o,o)}validateInput(e){if(typeof this.min!="undefined"&&(e=Math.max(this.min,e)),typeof this.max!="undefined"&&(e=Math.min(this.max,e)),this.step){const t=typeof this.min!="undefined"?this.min:0,i=(e-t)%this.step;if(i===0||(Math.round(i/this.step)===1?e+=this.step-i:e-=i),typeof this.max!="undefined")for(;e>this.max;)e-=this.step}return e}get displayValue(){const e=this.focused?"":indeterminatePlaceholder;return this.indeterminate?e:this.formattedValue}clearNumberFormatterCache(){this._numberFormatter=void 0,this._numberParser=void 0}get numberFormatter(){if(!this._numberFormatter||!this._numberFormatterFocused){const{style:e,unit:t,unitDisplay:i,...r}=this.formatOptions;e!=="unit"&&(r.style=e),this._numberFormatterFocused=new l(this.resolvedLanguage,r);try{this._numberFormatter=new l(this.resolvedLanguage,this.formatOptions),this._forcedUnit="",this._numberFormatter.format(1)}catch(s){e==="unit"&&(this._forcedUnit=t),this._numberFormatter=this._numberFormatterFocused}}return this.focused?this._numberFormatterFocused:this._numberFormatter}get numberParser(){if(!this._numberParser||!this._numberParserFocused){const{style:e,unit:t,unitDisplay:i,...r}=this.formatOptions;e!=="unit"&&(r.style=e),this._numberParserFocused=new p(this.resolvedLanguage,r);try{this._numberParser=new p(this.resolvedLanguage,this.formatOptions),this._forcedUnit="",this._numberParser.parse("0")}catch(s){e==="unit"&&(this._forcedUnit=t),this._numberParser=this._numberParserFocused}}return this.focused?this._numberParserFocused:this._numberParser}renderField(){return this.autocomplete="off",d`
348
2
  ${super.renderField()}
349
- ${this.hideStepper ? html`` : html`
3
+ ${this.hideStepper?d``:d`
350
4
  <span
351
5
  class="buttons"
352
6
  @focusin=${this.handleFocusin}
353
7
  @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
- })}
8
+ ${v({start:["pointerdown",this.handlePointerdown],streamInside:[["pointermove","pointerenter","pointerleave","pointerover","pointerout"],this.handlePointermove],end:[["pointerup","pointercancel"],this.handlePointerup]})}
371
9
  >
372
10
  <sp-action-button
373
11
  class="stepUp"
374
12
  label="Increment"
375
13
  tabindex="-1"
376
14
  ?focused=${this.focused}
377
- ?disabled=${this.disabled || this.readonly || typeof this.max !== "undefined" && this.value === this.max}
15
+ ?disabled=${this.disabled||this.readonly||typeof this.max!="undefined"&&this.value===this.max}
378
16
  ?quiet=${this.quiet}
379
17
  >
380
18
  <sp-icon-chevron75
@@ -387,7 +25,7 @@ export class NumberField extends TextfieldBase {
387
25
  label="Decrement"
388
26
  tabindex="-1"
389
27
  ?focused=${this.focused}
390
- ?disabled=${this.disabled || this.readonly || typeof this.min !== "undefined" && this.value === this.min}
28
+ ?disabled=${this.disabled||this.readonly||typeof this.min!="undefined"&&this.value===this.min}
391
29
  ?quiet=${this.quiet}
392
30
  >
393
31
  <sp-icon-chevron75
@@ -397,103 +35,5 @@ export class NumberField extends TextfieldBase {
397
35
  </sp-action-button>
398
36
  </span>
399
37
  `}
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);
38
+ `}update(e){if((e.has("formatOptions")||e.has("resolvedLanguage"))&&this.clearNumberFormatterCache(),e.has("value")||e.has("max")||e.has("min")){const t=this.numberParser.parse(this.formattedValue.replace(this._forcedUnit,""));this.value=t}super.update(e)}willUpdate(){this.multiline=!1}firstUpdated(e){super.firstUpdated(e),this.addEventListener("keydown",this.handleKeydown)}updated(e){if(e.has("min")||e.has("formatOptions")){let t="numeric";const i=typeof this.min!="undefined"&&this.min<0,{maximumFractionDigits:r}=this.formatOptions,s=r&&r>0;g()?i?t="text":s&&(t="decimal"):b()&&(i?t="numeric":s&&(t="decimal")),this.inputElement.inputMode=t}}connectedCallback(){super.connectedCallback(),this.resolveLanguage()}disconnectedCallback(){this.resolveLanguage(),super.disconnectedCallback()}resolveLanguage(){const e=new CustomEvent("sp-language-context",{bubbles:!0,composed:!0,detail:{callback:t=>{this.resolvedLanguage=t}},cancelable:!0});this.dispatchEvent(e)}}n([f(".buttons")],NumberField.prototype,"buttons",2),n([a({type:Boolean,reflect:!0})],NumberField.prototype,"focused",2),n([a({type:Object,attribute:"format-options"})],NumberField.prototype,"formatOptions",2),n([a({type:Boolean,reflect:!0,attribute:"hide-stepper"})],NumberField.prototype,"hideStepper",2),n([a({type:Boolean,reflect:!0})],NumberField.prototype,"indeterminate",2),n([a({type:Boolean,reflect:!0,attribute:"keyboard-focused"})],NumberField.prototype,"keyboardFocused",2),n([a({type:Number})],NumberField.prototype,"max",2),n([a({type:Number})],NumberField.prototype,"min",2),n([a({attribute:!1})],NumberField.prototype,"resolvedLanguage",2),n([a({type:Number})],NumberField.prototype,"step",2),n([a({type:Number,reflect:!0,attribute:"step-modifier"})],NumberField.prototype,"stepModifier",2),n([a({type:Number})],NumberField.prototype,"value",1);
499
39
  //# sourceMappingURL=NumberField.js.map