@spectrum-web-components/textfield 0.11.9 → 0.11.11-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/src/Textfield.js CHANGED
@@ -1,153 +1,141 @@
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 { __decorate } from "tslib";
13
- import { html, nothing, } from '@spectrum-web-components/base';
14
- import { ifDefined, live, } from '@spectrum-web-components/base/src/directives.js';
15
- import { property, query, state, } from '@spectrum-web-components/base/src/decorators.js';
16
- import { ManageHelpText } from '@spectrum-web-components/help-text/src/manage-help-text.js';
17
- import { Focusable } from '@spectrum-web-components/shared/src/focusable.js';
18
- import '@spectrum-web-components/icons-ui/icons/sp-icon-checkmark100.js';
19
- import '@spectrum-web-components/icons-workflow/icons/sp-icon-alert.js';
20
- import textfieldStyles from './textfield.css.js';
21
- import checkmarkStyles from '@spectrum-web-components/icon/src/spectrum-icon-checkmark.css.js';
22
- const textfieldTypes = ['text', 'url', 'tel', 'email', 'password'];
23
- /**
24
- * @fires input - The value of the element has changed.
25
- * @fires change - An alteration to the value of the element has been committed by the user.
26
- */
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
+ nothing
15
+ } from "@spectrum-web-components/base";
16
+ import {
17
+ ifDefined,
18
+ live
19
+ } from "@spectrum-web-components/base/src/directives.js";
20
+ import {
21
+ property,
22
+ query,
23
+ state
24
+ } from "@spectrum-web-components/base/src/decorators.js";
25
+ import { ManageHelpText } from "@spectrum-web-components/help-text/src/manage-help-text.js";
26
+ import { Focusable } from "@spectrum-web-components/shared/src/focusable.js";
27
+ import "@spectrum-web-components/icons-ui/icons/sp-icon-checkmark100.js";
28
+ import "@spectrum-web-components/icons-workflow/icons/sp-icon-alert.js";
29
+ import textfieldStyles from "./textfield.css.js";
30
+ import checkmarkStyles from "@spectrum-web-components/icon/src/spectrum-icon-checkmark.css.js";
31
+ const textfieldTypes = ["text", "url", "tel", "email", "password"];
27
32
  export class TextfieldBase extends ManageHelpText(Focusable) {
28
- constructor() {
29
- super(...arguments);
30
- this.allowedKeys = '';
31
- this.focused = false;
32
- this.invalid = false;
33
- this.label = '';
34
- this.placeholder = '';
35
- this._type = 'text';
36
- this.grows = false;
37
- this.maxlength = -1;
38
- this.minlength = -1;
39
- this.multiline = false;
40
- this.readonly = false;
41
- this.valid = false;
42
- this._value = '';
43
- this.quiet = false;
44
- this.required = false;
33
+ constructor() {
34
+ super(...arguments);
35
+ this.allowedKeys = "";
36
+ this.focused = false;
37
+ this.invalid = false;
38
+ this.label = "";
39
+ this.placeholder = "";
40
+ this._type = "text";
41
+ this.grows = false;
42
+ this.maxlength = -1;
43
+ this.minlength = -1;
44
+ this.multiline = false;
45
+ this.readonly = false;
46
+ this.valid = false;
47
+ this._value = "";
48
+ this.quiet = false;
49
+ this.required = false;
50
+ }
51
+ static get styles() {
52
+ return [textfieldStyles, checkmarkStyles];
53
+ }
54
+ get type() {
55
+ var _a;
56
+ return (_a = textfieldTypes.find((t) => t === this._type)) != null ? _a : "text";
57
+ }
58
+ set type(val) {
59
+ const prev = this._type;
60
+ this._type = val;
61
+ this.requestUpdate("type", prev);
62
+ }
63
+ set value(value) {
64
+ if (value === this.value) {
65
+ return;
45
66
  }
46
- static get styles() {
47
- return [textfieldStyles, checkmarkStyles];
67
+ const oldValue = this._value;
68
+ this._value = value;
69
+ this.requestUpdate("value", oldValue);
70
+ }
71
+ get value() {
72
+ return this._value;
73
+ }
74
+ get focusElement() {
75
+ return this.inputElement;
76
+ }
77
+ setSelectionRange(selectionStart, selectionEnd, selectionDirection = "none") {
78
+ this.inputElement.setSelectionRange(selectionStart, selectionEnd, selectionDirection);
79
+ }
80
+ select() {
81
+ this.inputElement.select();
82
+ }
83
+ handleInput() {
84
+ if (this.allowedKeys && this.inputElement.value) {
85
+ const regExp = new RegExp(`^[${this.allowedKeys}]*$`, "u");
86
+ if (!regExp.test(this.inputElement.value)) {
87
+ const selectionStart = this.inputElement.selectionStart;
88
+ const nextSelectStart = selectionStart - 1;
89
+ this.inputElement.value = this.value.toString();
90
+ this.inputElement.setSelectionRange(nextSelectStart, nextSelectStart);
91
+ return;
92
+ }
48
93
  }
49
- get type() {
50
- var _a;
51
- return (_a = textfieldTypes.find((t) => t === this._type)) !== null && _a !== void 0 ? _a : 'text';
52
- }
53
- set type(val) {
54
- const prev = this._type;
55
- this._type = val;
56
- this.requestUpdate('type', prev);
57
- }
58
- set value(value) {
59
- if (value === this.value) {
60
- return;
61
- }
62
- const oldValue = this._value;
63
- this._value = value;
64
- this.requestUpdate('value', oldValue);
65
- }
66
- get value() {
67
- return this._value;
68
- }
69
- get focusElement() {
70
- return this.inputElement;
71
- }
72
- /**
73
- * Sets the start and end positions of the current selection.
74
- *
75
- * @param selectionStart The 0-based index of the first selected character. An index greater than the length of the
76
- * element's value is treated as pointing to the end of the value.
77
- * @param selectionEnd The 0-based index of the character after the last selected character. An index greater than
78
- * the length of the element's value is treated as pointing to the end of the value.
79
- * @param [selectionDirection="none"] A string indicating the direction in which the selection is considered to
80
- * have been performed.
81
- */
82
- setSelectionRange(selectionStart, selectionEnd, selectionDirection = 'none') {
83
- this.inputElement.setSelectionRange(selectionStart, selectionEnd, selectionDirection);
84
- }
85
- /**
86
- * Selects all the text.
87
- */
88
- select() {
89
- this.inputElement.select();
90
- }
91
- handleInput() {
92
- if (this.allowedKeys && this.inputElement.value) {
93
- const regExp = new RegExp(`^[${this.allowedKeys}]*$`, 'u');
94
- if (!regExp.test(this.inputElement.value)) {
95
- const selectionStart = this.inputElement
96
- .selectionStart;
97
- const nextSelectStart = selectionStart - 1;
98
- this.inputElement.value = this.value.toString();
99
- this.inputElement.setSelectionRange(nextSelectStart, nextSelectStart);
100
- return;
101
- }
102
- }
103
- this.value = this.inputElement.value;
104
- }
105
- handleChange() {
106
- this.dispatchEvent(new Event('change', {
107
- bubbles: true,
108
- composed: true,
109
- }));
110
- }
111
- onFocus() {
112
- this.focused = !this.readonly && true;
113
- }
114
- onBlur() {
115
- this.focused = !this.readonly && false;
116
- }
117
- renderStateIcons() {
118
- if (this.invalid) {
119
- return html `
94
+ this.value = this.inputElement.value;
95
+ }
96
+ handleChange() {
97
+ this.dispatchEvent(new Event("change", {
98
+ bubbles: true,
99
+ composed: true
100
+ }));
101
+ }
102
+ onFocus() {
103
+ this.focused = !this.readonly && true;
104
+ }
105
+ onBlur() {
106
+ this.focused = !this.readonly && false;
107
+ }
108
+ renderStateIcons() {
109
+ if (this.invalid) {
110
+ return html`
120
111
  <sp-icon-alert id="invalid" class="icon"></sp-icon-alert>
121
112
  `;
122
- }
123
- else if (this.valid) {
124
- return html `
113
+ } else if (this.valid) {
114
+ return html`
125
115
  <sp-icon-checkmark100
126
116
  id="valid"
127
117
  class="icon spectrum-UIIcon-Checkmark100"
128
118
  ></sp-icon-checkmark100>
129
119
  `;
130
- }
131
- return nothing;
132
- }
133
- get displayValue() {
134
- return this.value.toString();
135
120
  }
136
- get renderMultiline() {
137
- return html `
138
- ${this.grows && !this.quiet
139
- ? html `
121
+ return nothing;
122
+ }
123
+ get displayValue() {
124
+ return this.value.toString();
125
+ }
126
+ get renderMultiline() {
127
+ return html`
128
+ ${this.grows && !this.quiet ? html`
140
129
  <div id="sizer">${this.value}&#8203;</div>
141
- `
142
- : nothing}
130
+ ` : nothing}
143
131
  <!-- @ts-ignore -->
144
132
  <textarea
145
133
  aria-describedby=${this.helpTextId}
146
134
  aria-label=${this.label || this.placeholder}
147
- aria-invalid=${ifDefined(this.invalid || undefined)}
135
+ aria-invalid=${ifDefined(this.invalid || void 0)}
148
136
  class="input"
149
- maxlength=${ifDefined(this.maxlength > -1 ? this.maxlength : undefined)}
150
- minlength=${ifDefined(this.minlength > -1 ? this.minlength : undefined)}
137
+ maxlength=${ifDefined(this.maxlength > -1 ? this.maxlength : void 0)}
138
+ minlength=${ifDefined(this.minlength > -1 ? this.minlength : void 0)}
151
139
  pattern=${ifDefined(this.pattern)}
152
140
  placeholder=${this.placeholder}
153
141
  .value=${this.displayValue}
@@ -161,18 +149,18 @@ export class TextfieldBase extends ManageHelpText(Focusable) {
161
149
  autocomplete=${ifDefined(this.autocomplete)}
162
150
  ></textarea>
163
151
  `;
164
- }
165
- get renderInput() {
166
- return html `
152
+ }
153
+ get renderInput() {
154
+ return html`
167
155
  <!-- @ts-ignore -->
168
156
  <input
169
157
  type=${this.type}
170
158
  aria-describedby=${this.helpTextId}
171
159
  aria-label=${this.label || this.placeholder}
172
- aria-invalid=${ifDefined(this.invalid || undefined)}
160
+ aria-invalid=${ifDefined(this.invalid || void 0)}
173
161
  class="input"
174
- maxlength=${ifDefined(this.maxlength > -1 ? this.maxlength : undefined)}
175
- minlength=${ifDefined(this.minlength > -1 ? this.minlength : undefined)}
162
+ maxlength=${ifDefined(this.maxlength > -1 ? this.maxlength : void 0)}
163
+ minlength=${ifDefined(this.minlength > -1 ? this.minlength : void 0)}
176
164
  pattern=${ifDefined(this.pattern)}
177
165
  placeholder=${this.placeholder}
178
166
  .value=${live(this.displayValue)}
@@ -186,125 +174,118 @@ export class TextfieldBase extends ManageHelpText(Focusable) {
186
174
  autocomplete=${ifDefined(this.autocomplete)}
187
175
  />
188
176
  `;
189
- }
190
- renderField() {
191
- return html `
177
+ }
178
+ renderField() {
179
+ return html`
192
180
  ${this.renderStateIcons()}
193
181
  ${this.multiline ? this.renderMultiline : this.renderInput}
194
182
  `;
195
- }
196
- render() {
197
- return html `
183
+ }
184
+ render() {
185
+ return html`
198
186
  <div id="textfield">${this.renderField()}</div>
199
187
  ${this.renderHelpText(this.invalid)}
200
188
  `;
189
+ }
190
+ update(changedProperties) {
191
+ if (changedProperties.has("value") || changedProperties.has("required") && this.required) {
192
+ this.updateComplete.then(() => {
193
+ this.checkValidity();
194
+ });
201
195
  }
202
- update(changedProperties) {
203
- if (changedProperties.has('value') ||
204
- (changedProperties.has('required') && this.required)) {
205
- this.updateComplete.then(() => {
206
- this.checkValidity();
207
- });
208
- }
209
- super.update(changedProperties);
210
- }
211
- checkValidity() {
212
- let validity = this.inputElement.checkValidity();
213
- if (this.required || (this.value && this.pattern)) {
214
- if ((this.disabled || this.multiline) && this.pattern) {
215
- const regex = new RegExp(`^${this.pattern}$`, 'u');
216
- validity = regex.test(this.value.toString());
217
- }
218
- if (typeof this.minlength !== 'undefined') {
219
- validity =
220
- validity && this.value.toString().length > this.minlength;
221
- }
222
- this.valid = validity;
223
- this.invalid = !validity;
224
- }
225
- return validity;
196
+ super.update(changedProperties);
197
+ }
198
+ checkValidity() {
199
+ let validity = this.inputElement.checkValidity();
200
+ if (this.required || this.value && this.pattern) {
201
+ if ((this.disabled || this.multiline) && this.pattern) {
202
+ const regex = new RegExp(`^${this.pattern}$`, "u");
203
+ validity = regex.test(this.value.toString());
204
+ }
205
+ if (typeof this.minlength !== "undefined") {
206
+ validity = validity && this.value.toString().length > this.minlength;
207
+ }
208
+ this.valid = validity;
209
+ this.invalid = !validity;
226
210
  }
211
+ return validity;
212
+ }
227
213
  }
228
- __decorate([
229
- property({ attribute: 'allowed-keys' })
230
- ], TextfieldBase.prototype, "allowedKeys", void 0);
231
- __decorate([
232
- property({ type: Boolean, reflect: true })
233
- ], TextfieldBase.prototype, "focused", void 0);
234
- __decorate([
235
- query('.input')
236
- ], TextfieldBase.prototype, "inputElement", void 0);
237
- __decorate([
238
- property({ type: Boolean, reflect: true })
239
- ], TextfieldBase.prototype, "invalid", void 0);
240
- __decorate([
241
- property()
242
- ], TextfieldBase.prototype, "label", void 0);
243
- __decorate([
244
- property()
245
- ], TextfieldBase.prototype, "placeholder", void 0);
246
- __decorate([
247
- property({ attribute: 'type', reflect: true })
248
- ], TextfieldBase.prototype, "_type", void 0);
249
- __decorate([
250
- state()
251
- ], TextfieldBase.prototype, "type", null);
252
- __decorate([
253
- property()
254
- ], TextfieldBase.prototype, "pattern", void 0);
255
- __decorate([
256
- property({ type: Boolean, reflect: true })
257
- ], TextfieldBase.prototype, "grows", void 0);
258
- __decorate([
259
- property({ type: Number })
260
- ], TextfieldBase.prototype, "maxlength", void 0);
261
- __decorate([
262
- property({ type: Number })
263
- ], TextfieldBase.prototype, "minlength", void 0);
264
- __decorate([
265
- property({ type: Boolean, reflect: true })
266
- ], TextfieldBase.prototype, "multiline", void 0);
267
- __decorate([
268
- property({ type: Boolean, reflect: true })
269
- ], TextfieldBase.prototype, "readonly", void 0);
270
- __decorate([
271
- property({ type: Boolean, reflect: true })
272
- ], TextfieldBase.prototype, "valid", void 0);
273
- __decorate([
274
- property({ type: String })
275
- ], TextfieldBase.prototype, "value", null);
276
- __decorate([
277
- property({ type: Boolean, reflect: true })
278
- ], TextfieldBase.prototype, "quiet", void 0);
279
- __decorate([
280
- property({ type: Boolean, reflect: true })
281
- ], TextfieldBase.prototype, "required", void 0);
282
- __decorate([
283
- property({ type: String, reflect: true })
284
- ], TextfieldBase.prototype, "autocomplete", void 0);
285
- /**
286
- * @element sp-textfield
287
- * @slot help-text - default or non-negative help text to associate to your form element
288
- * @slot negative-help-text - negative help text to associate to your form element when `invalid`
289
- */
214
+ __decorateClass([
215
+ property({ attribute: "allowed-keys" })
216
+ ], TextfieldBase.prototype, "allowedKeys", 2);
217
+ __decorateClass([
218
+ property({ type: Boolean, reflect: true })
219
+ ], TextfieldBase.prototype, "focused", 2);
220
+ __decorateClass([
221
+ query(".input")
222
+ ], TextfieldBase.prototype, "inputElement", 2);
223
+ __decorateClass([
224
+ property({ type: Boolean, reflect: true })
225
+ ], TextfieldBase.prototype, "invalid", 2);
226
+ __decorateClass([
227
+ property()
228
+ ], TextfieldBase.prototype, "label", 2);
229
+ __decorateClass([
230
+ property()
231
+ ], TextfieldBase.prototype, "placeholder", 2);
232
+ __decorateClass([
233
+ property({ attribute: "type", reflect: true })
234
+ ], TextfieldBase.prototype, "_type", 2);
235
+ __decorateClass([
236
+ state()
237
+ ], TextfieldBase.prototype, "type", 1);
238
+ __decorateClass([
239
+ property()
240
+ ], TextfieldBase.prototype, "pattern", 2);
241
+ __decorateClass([
242
+ property({ type: Boolean, reflect: true })
243
+ ], TextfieldBase.prototype, "grows", 2);
244
+ __decorateClass([
245
+ property({ type: Number })
246
+ ], TextfieldBase.prototype, "maxlength", 2);
247
+ __decorateClass([
248
+ property({ type: Number })
249
+ ], TextfieldBase.prototype, "minlength", 2);
250
+ __decorateClass([
251
+ property({ type: Boolean, reflect: true })
252
+ ], TextfieldBase.prototype, "multiline", 2);
253
+ __decorateClass([
254
+ property({ type: Boolean, reflect: true })
255
+ ], TextfieldBase.prototype, "readonly", 2);
256
+ __decorateClass([
257
+ property({ type: Boolean, reflect: true })
258
+ ], TextfieldBase.prototype, "valid", 2);
259
+ __decorateClass([
260
+ property({ type: String })
261
+ ], TextfieldBase.prototype, "value", 1);
262
+ __decorateClass([
263
+ property({ type: Boolean, reflect: true })
264
+ ], TextfieldBase.prototype, "quiet", 2);
265
+ __decorateClass([
266
+ property({ type: Boolean, reflect: true })
267
+ ], TextfieldBase.prototype, "required", 2);
268
+ __decorateClass([
269
+ property({ type: String, reflect: true })
270
+ ], TextfieldBase.prototype, "autocomplete", 2);
290
271
  export class Textfield extends TextfieldBase {
291
- constructor() {
292
- super(...arguments);
293
- this._value = '';
294
- }
295
- set value(value) {
296
- if (value === this.value) {
297
- return;
298
- }
299
- const oldValue = this._value;
300
- this._value = value;
301
- this.requestUpdate('value', oldValue);
302
- }
303
- get value() {
304
- return this._value;
272
+ constructor() {
273
+ super(...arguments);
274
+ this._value = "";
275
+ }
276
+ set value(value) {
277
+ if (value === this.value) {
278
+ return;
305
279
  }
280
+ const oldValue = this._value;
281
+ this._value = value;
282
+ this.requestUpdate("value", oldValue);
283
+ }
284
+ get value() {
285
+ return this._value;
286
+ }
306
287
  }
307
- __decorate([
308
- property({ type: String })
309
- ], Textfield.prototype, "value", null);
310
- //# sourceMappingURL=Textfield.js.map
288
+ __decorateClass([
289
+ property({ type: String })
290
+ ], Textfield.prototype, "value", 1);
291
+ //# sourceMappingURL=Textfield.js.map
@@ -1 +1,7 @@
1
- {"version":3,"file":"Textfield.js","sourceRoot":"","sources":["Textfield.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;;AAEF,OAAO,EAEH,IAAI,EACJ,OAAO,GAGV,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACH,SAAS,EACT,IAAI,GACP,MAAM,iDAAiD,CAAC;AACzD,OAAO,EACH,QAAQ,EACR,KAAK,EACL,KAAK,GACR,MAAM,iDAAiD,CAAC;AAEzD,OAAO,EAAE,cAAc,EAAE,MAAM,4DAA4D,CAAC;AAC5F,OAAO,EAAE,SAAS,EAAE,MAAM,kDAAkD,CAAC;AAC7E,OAAO,iEAAiE,CAAC;AACzE,OAAO,gEAAgE,CAAC;AAExE,OAAO,eAAe,MAAM,oBAAoB,CAAC;AACjD,OAAO,eAAe,MAAM,kEAAkE,CAAC;AAE/F,MAAM,cAAc,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU,CAAU,CAAC;AAG5E;;;GAGG;AACH,MAAM,OAAO,aAAc,SAAQ,cAAc,CAAC,SAAS,CAAC;IAA5D;;QAMI,gBAAW,GAAG,EAAE,CAA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AAM,OAAO,SAAU,SAAQ,aAAa;IAA5C;;QAeuB,WAAM,GAAG,EAAE,CAAC;IACnC,CAAC;IAdG,IAAoB,KAAK,CAAC,KAAa;QACnC,IAAI,KAAK,KAAK,IAAI,CAAC,KAAK,EAAE;YACtB,OAAO;SACV;QACD,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAC1C,CAAC;IAED,IAAoB,KAAK;QACrB,OAAO,IAAI,CAAC,MAAM,CAAC;IACvB,CAAC;CAGJ;AAdG;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;sCAQ1B","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 {\n CSSResultArray,\n html,\n nothing,\n PropertyValues,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport {\n ifDefined,\n live,\n} from '@spectrum-web-components/base/src/directives.js';\nimport {\n property,\n query,\n state,\n} from '@spectrum-web-components/base/src/decorators.js';\n\nimport { ManageHelpText } from '@spectrum-web-components/help-text/src/manage-help-text.js';\nimport { Focusable } from '@spectrum-web-components/shared/src/focusable.js';\nimport '@spectrum-web-components/icons-ui/icons/sp-icon-checkmark100.js';\nimport '@spectrum-web-components/icons-workflow/icons/sp-icon-alert.js';\n\nimport textfieldStyles from './textfield.css.js';\nimport checkmarkStyles from '@spectrum-web-components/icon/src/spectrum-icon-checkmark.css.js';\n\nconst textfieldTypes = ['text', 'url', 'tel', 'email', 'password'] as const;\nexport type TextfieldType = typeof textfieldTypes[number];\n\n/**\n * @fires input - The value of the element has changed.\n * @fires change - An alteration to the value of the element has been committed by the user.\n */\nexport class TextfieldBase extends ManageHelpText(Focusable) {\n public static override get styles(): CSSResultArray {\n return [textfieldStyles, checkmarkStyles];\n }\n\n @property({ attribute: 'allowed-keys' })\n allowedKeys = '';\n\n @property({ type: Boolean, reflect: true })\n public focused = false;\n\n @query('.input')\n protected inputElement!: HTMLInputElement | HTMLTextAreaElement;\n\n @property({ type: Boolean, reflect: true })\n public invalid = false;\n\n @property()\n public label = '';\n\n @property()\n public placeholder = '';\n\n @property({ attribute: 'type', reflect: true })\n private _type: TextfieldType = 'text';\n\n @state()\n get type(): TextfieldType {\n return textfieldTypes.find((t) => t === this._type) ?? 'text';\n }\n\n set type(val: TextfieldType) {\n const prev = this._type;\n this._type = val;\n this.requestUpdate('type', prev);\n }\n\n @property()\n public pattern?: string;\n\n @property({ type: Boolean, reflect: true })\n public grows = false;\n\n @property({ type: Number })\n public maxlength = -1;\n\n @property({ type: Number })\n public minlength = -1;\n\n @property({ type: Boolean, reflect: true })\n public multiline = false;\n\n @property({ type: Boolean, reflect: true })\n public readonly = false;\n\n @property({ type: Boolean, reflect: true })\n public valid = false;\n\n @property({ type: String })\n public set value(value: string | number) {\n if (value === this.value) {\n return;\n }\n const oldValue = this._value;\n this._value = value;\n this.requestUpdate('value', oldValue);\n }\n\n public get value(): string | number {\n return this._value;\n }\n\n protected _value: string | number = '';\n\n @property({ type: Boolean, reflect: true })\n public quiet = false;\n\n @property({ type: Boolean, reflect: true })\n public required = false;\n\n @property({ type: String, reflect: true })\n public autocomplete?:\n | HTMLInputElement['autocomplete']\n | HTMLTextAreaElement['autocomplete'];\n\n public override get focusElement(): HTMLInputElement | HTMLTextAreaElement {\n return this.inputElement;\n }\n\n /**\n * Sets the start and end positions of the current selection.\n *\n * @param selectionStart The 0-based index of the first selected character. An index greater than the length of the\n * element's value is treated as pointing to the end of the value.\n * @param selectionEnd The 0-based index of the character after the last selected character. An index greater than\n * the length of the element's value is treated as pointing to the end of the value.\n * @param [selectionDirection=\"none\"] A string indicating the direction in which the selection is considered to\n * have been performed.\n */\n public setSelectionRange(\n selectionStart: number,\n selectionEnd: number,\n selectionDirection: 'forward' | 'backward' | 'none' = 'none'\n ): void {\n this.inputElement.setSelectionRange(\n selectionStart,\n selectionEnd,\n selectionDirection\n );\n }\n\n /**\n * Selects all the text.\n */\n public select(): void {\n this.inputElement.select();\n }\n\n protected handleInput(): void {\n if (this.allowedKeys && this.inputElement.value) {\n const regExp = new RegExp(`^[${this.allowedKeys}]*$`, 'u');\n if (!regExp.test(this.inputElement.value)) {\n const selectionStart = this.inputElement\n .selectionStart as number;\n const nextSelectStart = selectionStart - 1;\n this.inputElement.value = this.value.toString();\n this.inputElement.setSelectionRange(\n nextSelectStart,\n nextSelectStart\n );\n return;\n }\n }\n this.value = this.inputElement.value;\n }\n\n protected handleChange(): void {\n this.dispatchEvent(\n new Event('change', {\n bubbles: true,\n composed: true,\n })\n );\n }\n\n protected onFocus(): void {\n this.focused = !this.readonly && true;\n }\n\n protected onBlur(): void {\n this.focused = !this.readonly && false;\n }\n\n protected renderStateIcons(): TemplateResult | typeof nothing {\n if (this.invalid) {\n return html`\n <sp-icon-alert id=\"invalid\" class=\"icon\"></sp-icon-alert>\n `;\n } else if (this.valid) {\n return html`\n <sp-icon-checkmark100\n id=\"valid\"\n class=\"icon spectrum-UIIcon-Checkmark100\"\n ></sp-icon-checkmark100>\n `;\n }\n return nothing;\n }\n\n protected get displayValue(): string {\n return this.value.toString();\n }\n\n private get renderMultiline(): TemplateResult {\n return html`\n ${this.grows && !this.quiet\n ? html`\n <div id=\"sizer\">${this.value}&#8203;</div>\n `\n : nothing}\n <!-- @ts-ignore -->\n <textarea\n aria-describedby=${this.helpTextId}\n aria-label=${this.label || this.placeholder}\n aria-invalid=${ifDefined(this.invalid || undefined)}\n class=\"input\"\n maxlength=${ifDefined(\n this.maxlength > -1 ? this.maxlength : undefined\n )}\n minlength=${ifDefined(\n this.minlength > -1 ? this.minlength : undefined\n )}\n pattern=${ifDefined(this.pattern)}\n placeholder=${this.placeholder}\n .value=${this.displayValue}\n @change=${this.handleChange}\n @input=${this.handleInput}\n @focus=${this.onFocus}\n @blur=${this.onBlur}\n ?disabled=${this.disabled}\n ?required=${this.required}\n ?readonly=${this.readonly}\n autocomplete=${ifDefined(this.autocomplete)}\n ></textarea>\n `;\n }\n\n private get renderInput(): TemplateResult {\n return html`\n <!-- @ts-ignore -->\n <input\n type=${this.type}\n aria-describedby=${this.helpTextId}\n aria-label=${this.label || this.placeholder}\n aria-invalid=${ifDefined(this.invalid || undefined)}\n class=\"input\"\n maxlength=${ifDefined(\n this.maxlength > -1 ? this.maxlength : undefined\n )}\n minlength=${ifDefined(\n this.minlength > -1 ? this.minlength : undefined\n )}\n pattern=${ifDefined(this.pattern)}\n placeholder=${this.placeholder}\n .value=${live(this.displayValue)}\n @change=${this.handleChange}\n @input=${this.handleInput}\n @focus=${this.onFocus}\n @blur=${this.onBlur}\n ?disabled=${this.disabled}\n ?required=${this.required}\n ?readonly=${this.readonly}\n autocomplete=${ifDefined(this.autocomplete)}\n />\n `;\n }\n\n protected renderField(): TemplateResult {\n return html`\n ${this.renderStateIcons()}\n ${this.multiline ? this.renderMultiline : this.renderInput}\n `;\n }\n\n protected override render(): TemplateResult {\n return html`\n <div id=\"textfield\">${this.renderField()}</div>\n ${this.renderHelpText(this.invalid)}\n `;\n }\n\n protected override update(changedProperties: PropertyValues): void {\n if (\n changedProperties.has('value') ||\n (changedProperties.has('required') && this.required)\n ) {\n this.updateComplete.then(() => {\n this.checkValidity();\n });\n }\n super.update(changedProperties);\n }\n\n public checkValidity(): boolean {\n let validity = this.inputElement.checkValidity();\n if (this.required || (this.value && this.pattern)) {\n if ((this.disabled || this.multiline) && this.pattern) {\n const regex = new RegExp(`^${this.pattern}$`, 'u');\n validity = regex.test(this.value.toString());\n }\n if (typeof this.minlength !== 'undefined') {\n validity =\n validity && this.value.toString().length > this.minlength;\n }\n this.valid = validity;\n this.invalid = !validity;\n }\n return validity;\n }\n}\n\n/**\n * @element sp-textfield\n * @slot help-text - default or non-negative help text to associate to your form element\n * @slot negative-help-text - negative help text to associate to your form element when `invalid`\n */\nexport class Textfield extends TextfieldBase {\n @property({ type: String })\n public override set value(value: string) {\n if (value === this.value) {\n return;\n }\n const oldValue = this._value;\n this._value = value;\n this.requestUpdate('value', oldValue);\n }\n\n public override get value(): string {\n return this._value;\n }\n\n protected override _value = '';\n}\n"]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["Textfield.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 {\n CSSResultArray,\n html,\n nothing,\n PropertyValues,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport {\n ifDefined,\n live,\n} from '@spectrum-web-components/base/src/directives.js';\nimport {\n property,\n query,\n state,\n} from '@spectrum-web-components/base/src/decorators.js';\n\nimport { ManageHelpText } from '@spectrum-web-components/help-text/src/manage-help-text.js';\nimport { Focusable } from '@spectrum-web-components/shared/src/focusable.js';\nimport '@spectrum-web-components/icons-ui/icons/sp-icon-checkmark100.js';\nimport '@spectrum-web-components/icons-workflow/icons/sp-icon-alert.js';\n\nimport textfieldStyles from './textfield.css.js';\nimport checkmarkStyles from '@spectrum-web-components/icon/src/spectrum-icon-checkmark.css.js';\n\nconst textfieldTypes = ['text', 'url', 'tel', 'email', 'password'] as const;\nexport type TextfieldType = typeof textfieldTypes[number];\n\n/**\n * @fires input - The value of the element has changed.\n * @fires change - An alteration to the value of the element has been committed by the user.\n */\nexport class TextfieldBase extends ManageHelpText(Focusable) {\n public static override get styles(): CSSResultArray {\n return [textfieldStyles, checkmarkStyles];\n }\n\n @property({ attribute: 'allowed-keys' })\n allowedKeys = '';\n\n @property({ type: Boolean, reflect: true })\n public focused = false;\n\n @query('.input')\n protected inputElement!: HTMLInputElement | HTMLTextAreaElement;\n\n @property({ type: Boolean, reflect: true })\n public invalid = false;\n\n @property()\n public label = '';\n\n @property()\n public placeholder = '';\n\n @property({ attribute: 'type', reflect: true })\n private _type: TextfieldType = 'text';\n\n @state()\n get type(): TextfieldType {\n return textfieldTypes.find((t) => t === this._type) ?? 'text';\n }\n\n set type(val: TextfieldType) {\n const prev = this._type;\n this._type = val;\n this.requestUpdate('type', prev);\n }\n\n @property()\n public pattern?: string;\n\n @property({ type: Boolean, reflect: true })\n public grows = false;\n\n @property({ type: Number })\n public maxlength = -1;\n\n @property({ type: Number })\n public minlength = -1;\n\n @property({ type: Boolean, reflect: true })\n public multiline = false;\n\n @property({ type: Boolean, reflect: true })\n public readonly = false;\n\n @property({ type: Boolean, reflect: true })\n public valid = false;\n\n @property({ type: String })\n public set value(value: string | number) {\n if (value === this.value) {\n return;\n }\n const oldValue = this._value;\n this._value = value;\n this.requestUpdate('value', oldValue);\n }\n\n public get value(): string | number {\n return this._value;\n }\n\n protected _value: string | number = '';\n\n @property({ type: Boolean, reflect: true })\n public quiet = false;\n\n @property({ type: Boolean, reflect: true })\n public required = false;\n\n @property({ type: String, reflect: true })\n public autocomplete?:\n | HTMLInputElement['autocomplete']\n | HTMLTextAreaElement['autocomplete'];\n\n public override get focusElement(): HTMLInputElement | HTMLTextAreaElement {\n return this.inputElement;\n }\n\n /**\n * Sets the start and end positions of the current selection.\n *\n * @param selectionStart The 0-based index of the first selected character. An index greater than the length of the\n * element's value is treated as pointing to the end of the value.\n * @param selectionEnd The 0-based index of the character after the last selected character. An index greater than\n * the length of the element's value is treated as pointing to the end of the value.\n * @param [selectionDirection=\"none\"] A string indicating the direction in which the selection is considered to\n * have been performed.\n */\n public setSelectionRange(\n selectionStart: number,\n selectionEnd: number,\n selectionDirection: 'forward' | 'backward' | 'none' = 'none'\n ): void {\n this.inputElement.setSelectionRange(\n selectionStart,\n selectionEnd,\n selectionDirection\n );\n }\n\n /**\n * Selects all the text.\n */\n public select(): void {\n this.inputElement.select();\n }\n\n protected handleInput(): void {\n if (this.allowedKeys && this.inputElement.value) {\n const regExp = new RegExp(`^[${this.allowedKeys}]*$`, 'u');\n if (!regExp.test(this.inputElement.value)) {\n const selectionStart = this.inputElement\n .selectionStart as number;\n const nextSelectStart = selectionStart - 1;\n this.inputElement.value = this.value.toString();\n this.inputElement.setSelectionRange(\n nextSelectStart,\n nextSelectStart\n );\n return;\n }\n }\n this.value = this.inputElement.value;\n }\n\n protected handleChange(): void {\n this.dispatchEvent(\n new Event('change', {\n bubbles: true,\n composed: true,\n })\n );\n }\n\n protected onFocus(): void {\n this.focused = !this.readonly && true;\n }\n\n protected onBlur(): void {\n this.focused = !this.readonly && false;\n }\n\n protected renderStateIcons(): TemplateResult | typeof nothing {\n if (this.invalid) {\n return html`\n <sp-icon-alert id=\"invalid\" class=\"icon\"></sp-icon-alert>\n `;\n } else if (this.valid) {\n return html`\n <sp-icon-checkmark100\n id=\"valid\"\n class=\"icon spectrum-UIIcon-Checkmark100\"\n ></sp-icon-checkmark100>\n `;\n }\n return nothing;\n }\n\n protected get displayValue(): string {\n return this.value.toString();\n }\n\n private get renderMultiline(): TemplateResult {\n return html`\n ${this.grows && !this.quiet\n ? html`\n <div id=\"sizer\">${this.value}&#8203;</div>\n `\n : nothing}\n <!-- @ts-ignore -->\n <textarea\n aria-describedby=${this.helpTextId}\n aria-label=${this.label || this.placeholder}\n aria-invalid=${ifDefined(this.invalid || undefined)}\n class=\"input\"\n maxlength=${ifDefined(\n this.maxlength > -1 ? this.maxlength : undefined\n )}\n minlength=${ifDefined(\n this.minlength > -1 ? this.minlength : undefined\n )}\n pattern=${ifDefined(this.pattern)}\n placeholder=${this.placeholder}\n .value=${this.displayValue}\n @change=${this.handleChange}\n @input=${this.handleInput}\n @focus=${this.onFocus}\n @blur=${this.onBlur}\n ?disabled=${this.disabled}\n ?required=${this.required}\n ?readonly=${this.readonly}\n autocomplete=${ifDefined(this.autocomplete)}\n ></textarea>\n `;\n }\n\n private get renderInput(): TemplateResult {\n return html`\n <!-- @ts-ignore -->\n <input\n type=${this.type}\n aria-describedby=${this.helpTextId}\n aria-label=${this.label || this.placeholder}\n aria-invalid=${ifDefined(this.invalid || undefined)}\n class=\"input\"\n maxlength=${ifDefined(\n this.maxlength > -1 ? this.maxlength : undefined\n )}\n minlength=${ifDefined(\n this.minlength > -1 ? this.minlength : undefined\n )}\n pattern=${ifDefined(this.pattern)}\n placeholder=${this.placeholder}\n .value=${live(this.displayValue)}\n @change=${this.handleChange}\n @input=${this.handleInput}\n @focus=${this.onFocus}\n @blur=${this.onBlur}\n ?disabled=${this.disabled}\n ?required=${this.required}\n ?readonly=${this.readonly}\n autocomplete=${ifDefined(this.autocomplete)}\n />\n `;\n }\n\n protected renderField(): TemplateResult {\n return html`\n ${this.renderStateIcons()}\n ${this.multiline ? this.renderMultiline : this.renderInput}\n `;\n }\n\n protected override render(): TemplateResult {\n return html`\n <div id=\"textfield\">${this.renderField()}</div>\n ${this.renderHelpText(this.invalid)}\n `;\n }\n\n protected override update(changedProperties: PropertyValues): void {\n if (\n changedProperties.has('value') ||\n (changedProperties.has('required') && this.required)\n ) {\n this.updateComplete.then(() => {\n this.checkValidity();\n });\n }\n super.update(changedProperties);\n }\n\n public checkValidity(): boolean {\n let validity = this.inputElement.checkValidity();\n if (this.required || (this.value && this.pattern)) {\n if ((this.disabled || this.multiline) && this.pattern) {\n const regex = new RegExp(`^${this.pattern}$`, 'u');\n validity = regex.test(this.value.toString());\n }\n if (typeof this.minlength !== 'undefined') {\n validity =\n validity && this.value.toString().length > this.minlength;\n }\n this.valid = validity;\n this.invalid = !validity;\n }\n return validity;\n }\n}\n\n/**\n * @element sp-textfield\n * @slot help-text - default or non-negative help text to associate to your form element\n * @slot negative-help-text - negative help text to associate to your form element when `invalid`\n */\nexport class Textfield extends TextfieldBase {\n @property({ type: String })\n public override set value(value: string) {\n if (value === this.value) {\n return;\n }\n const oldValue = this._value;\n this._value = value;\n this.requestUpdate('value', oldValue);\n }\n\n public override get value(): string {\n return this._value;\n }\n\n protected override _value = '';\n}\n"],
5
+ "mappings": ";;;;;;;;;;;AAYA;AAAA;AAAA;AAAA;AAOA;AAAA;AAAA;AAAA;AAIA;AAAA;AAAA;AAAA;AAAA;AAMA;AACA;AACA;AACA;AAEA;AACA;AAEA,MAAM,iBAAiB,CAAC,QAAQ,OAAO,OAAO,SAAS,UAAU;AAO1D,aAAM,sBAAsB,eAAe,SAAS,EAAE;AAAA,EAAtD;AAAA;AAMH,uBAAc;AAGP,mBAAU;AAMV,mBAAU;AAGV,iBAAQ;AAGR,uBAAc;AAGb,iBAAuB;AAiBxB,iBAAQ;AAGR,qBAAY;AAGZ,qBAAY;AAGZ,qBAAY;AAGZ,oBAAW;AAGX,iBAAQ;AAgBL,kBAA0B;AAG7B,iBAAQ;AAGR,oBAAW;AAAA;AAAA,aA7ES,SAAyB;AAChD,WAAO,CAAC,iBAAiB,eAAe;AAAA,EAC5C;AAAA,MAwBI,OAAsB;AAvE9B;AAwEQ,WAAO,qBAAe,KAAK,CAAC,MAAM,MAAM,KAAK,KAAK,MAA3C,YAAgD;AAAA,EAC3D;AAAA,MAEI,KAAK,KAAoB;AACzB,UAAM,OAAO,KAAK;AAClB,SAAK,QAAQ;AACb,SAAK,cAAc,QAAQ,IAAI;AAAA,EACnC;AAAA,MAwBW,MAAM,OAAwB;AACrC,QAAI,UAAU,KAAK,OAAO;AACtB;AAAA,IACJ;AACA,UAAM,WAAW,KAAK;AACtB,SAAK,SAAS;AACd,SAAK,cAAc,SAAS,QAAQ;AAAA,EACxC;AAAA,MAEW,QA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GJ;AAdwB;AAAA,EADpB,AAAC,SAAS,EAAE,MAAM,OAAO,CAAC;AAAA,GACN,AAFjB,UAEiB;",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./Textfield.dev.js";
2
+ //# sourceMappingURL=index.dev.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["index.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*/\nexport * from './Textfield.dev.js'\n"],
5
+ "mappings": "AAWA;",
6
+ "names": []
7
+ }
package/src/index.js CHANGED
@@ -1,13 +1,2 @@
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
- export * from './Textfield.js';
13
- //# sourceMappingURL=index.js.map
1
+ export * from "./Textfield.js";
2
+ //# sourceMappingURL=index.js.map