@spectrum-web-components/textfield 0.11.8 → 0.11.11-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 +26 -13
- package/sp-textfield.dev.js +3 -0
- package/sp-textfield.dev.js.map +7 -0
- package/sp-textfield.js +3 -14
- package/sp-textfield.js.map +7 -1
- package/src/Textfield.d.ts +1 -1
- package/src/Textfield.dev.js +291 -0
- package/src/Textfield.dev.js.map +7 -0
- package/src/Textfield.js +230 -246
- package/src/Textfield.js.map +7 -1
- package/src/index.dev.js +2 -0
- package/src/index.dev.js.map +7 -0
- package/src/index.js +2 -13
- package/src/index.js.map +7 -1
- package/src/spectrum-textfield.css.dev.js +252 -0
- package/src/spectrum-textfield.css.dev.js.map +7 -0
- package/src/spectrum-textfield.css.js +3 -14
- package/src/spectrum-textfield.css.js.map +7 -1
- package/src/textfield.css.dev.js +259 -0
- package/src/textfield.css.dev.js.map +7 -0
- package/src/textfield.css.js +4 -15
- package/src/textfield.css.js.map +7 -1
- package/stories/textarea.stories.js +15 -26
- package/stories/textarea.stories.js.map +7 -1
- package/stories/textfield.stories.js +15 -26
- package/stories/textfield.stories.js.map +7 -1
- package/test/benchmark/test-basic.js +5 -16
- package/test/benchmark/test-basic.js.map +7 -1
- package/test/textarea.test-vrt.js +4 -15
- package/test/textarea.test-vrt.js.map +7 -1
- package/test/textfield.test-vrt.js +4 -15
- package/test/textfield.test-vrt.js.map +7 -1
- package/test/textfield.test.js +460 -516
- package/test/textfield.test.js.map +7 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spectrum-web-components/textfield",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.11-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
|
-
".":
|
|
24
|
-
|
|
23
|
+
".": {
|
|
24
|
+
"development": "./src/index.dev.js",
|
|
25
|
+
"default": "./src/index.js"
|
|
26
|
+
},
|
|
25
27
|
"./package.json": "./package.json",
|
|
26
|
-
"./
|
|
27
|
-
|
|
28
|
+
"./src/Textfield.js": {
|
|
29
|
+
"development": "./src/Textfield.dev.js",
|
|
30
|
+
"default": "./src/Textfield.js"
|
|
31
|
+
},
|
|
32
|
+
"./src/index.js": {
|
|
33
|
+
"development": "./src/index.dev.js",
|
|
34
|
+
"default": "./src/index.js"
|
|
35
|
+
},
|
|
36
|
+
"./src/textfield.css.js": "./src/textfield.css.js",
|
|
37
|
+
"./sp-textfield.js": {
|
|
38
|
+
"development": "./sp-textfield.dev.js",
|
|
39
|
+
"default": "./sp-textfield.js"
|
|
40
|
+
}
|
|
28
41
|
},
|
|
29
42
|
"scripts": {
|
|
30
43
|
"test": "echo \"Error: run tests from mono-repo root.\" && exit 1"
|
|
@@ -44,21 +57,21 @@
|
|
|
44
57
|
"lit-html"
|
|
45
58
|
],
|
|
46
59
|
"dependencies": {
|
|
47
|
-
"@spectrum-web-components/base": "^0.5.
|
|
48
|
-
"@spectrum-web-components/help-text": "^0.1.
|
|
49
|
-
"@spectrum-web-components/icon": "^0.11.
|
|
50
|
-
"@spectrum-web-components/icons-ui": "^0.8.
|
|
51
|
-
"@spectrum-web-components/icons-workflow": "^0.8.
|
|
52
|
-
"@spectrum-web-components/shared": "^0.14.
|
|
60
|
+
"@spectrum-web-components/base": "^0.5.9-devmode.24+07474d44f",
|
|
61
|
+
"@spectrum-web-components/help-text": "^0.1.11-devmode.0+07474d44f",
|
|
62
|
+
"@spectrum-web-components/icon": "^0.11.12-devmode.0+07474d44f",
|
|
63
|
+
"@spectrum-web-components/icons-ui": "^0.8.12-devmode.0+07474d44f",
|
|
64
|
+
"@spectrum-web-components/icons-workflow": "^0.8.12-devmode.0+07474d44f",
|
|
65
|
+
"@spectrum-web-components/shared": "^0.14.5-devmode.0+07474d44f",
|
|
53
66
|
"tslib": "^2.0.0"
|
|
54
67
|
},
|
|
55
68
|
"devDependencies": {
|
|
56
|
-
"@spectrum-css/textfield": "^3.2.
|
|
69
|
+
"@spectrum-css/textfield": "^3.2.4"
|
|
57
70
|
},
|
|
58
71
|
"types": "./src/index.d.ts",
|
|
59
72
|
"customElements": "custom-elements.json",
|
|
60
73
|
"sideEffects": [
|
|
61
74
|
"./sp-*.js"
|
|
62
75
|
],
|
|
63
|
-
"gitHead": "
|
|
76
|
+
"gitHead": "07474d44f6cee1db241b9ccf3dc812514ffbe7fa"
|
|
64
77
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["sp-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 { Textfield } from './src/Textfield.dev.js'\n\ncustomElements.define('sp-textfield', Textfield);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'sp-textfield': Textfield;\n }\n}\n"],
|
|
5
|
+
"mappings": "AAYA;AAEA,eAAe,OAAO,gBAAgB,SAAS;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/sp-textfield.js
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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 { Textfield } from './src/Textfield.js';
|
|
13
|
-
customElements.define('sp-textfield', Textfield);
|
|
14
|
-
//# sourceMappingURL=sp-textfield.js.map
|
|
1
|
+
import { Textfield } from "./src/Textfield.js";
|
|
2
|
+
customElements.define("sp-textfield", Textfield);
|
|
3
|
+
//# sourceMappingURL=sp-textfield.js.map
|
package/sp-textfield.js.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["sp-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 { Textfield } from './src/Textfield.js';\n\ncustomElements.define('sp-textfield', Textfield);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'sp-textfield': Textfield;\n }\n}\n"],
|
|
5
|
+
"mappings": "AAYA;AAEA,eAAe,OAAO,gBAAgB,SAAS;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/src/Textfield.d.ts
CHANGED
|
@@ -62,7 +62,7 @@ export declare class TextfieldBase extends TextfieldBase_base {
|
|
|
62
62
|
private get renderInput();
|
|
63
63
|
protected renderField(): TemplateResult;
|
|
64
64
|
protected render(): TemplateResult;
|
|
65
|
-
protected
|
|
65
|
+
protected update(changedProperties: PropertyValues): void;
|
|
66
66
|
checkValidity(): boolean;
|
|
67
67
|
}
|
|
68
68
|
/**
|
|
@@ -0,0 +1,291 @@
|
|
|
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"];
|
|
32
|
+
export class TextfieldBase extends ManageHelpText(Focusable) {
|
|
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;
|
|
66
|
+
}
|
|
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
|
+
}
|
|
93
|
+
}
|
|
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`
|
|
111
|
+
<sp-icon-alert id="invalid" class="icon"></sp-icon-alert>
|
|
112
|
+
`;
|
|
113
|
+
} else if (this.valid) {
|
|
114
|
+
return html`
|
|
115
|
+
<sp-icon-checkmark100
|
|
116
|
+
id="valid"
|
|
117
|
+
class="icon spectrum-UIIcon-Checkmark100"
|
|
118
|
+
></sp-icon-checkmark100>
|
|
119
|
+
`;
|
|
120
|
+
}
|
|
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`
|
|
129
|
+
<div id="sizer">${this.value}​</div>
|
|
130
|
+
` : nothing}
|
|
131
|
+
<!-- @ts-ignore -->
|
|
132
|
+
<textarea
|
|
133
|
+
aria-describedby=${this.helpTextId}
|
|
134
|
+
aria-label=${this.label || this.placeholder}
|
|
135
|
+
aria-invalid=${ifDefined(this.invalid || void 0)}
|
|
136
|
+
class="input"
|
|
137
|
+
maxlength=${ifDefined(this.maxlength > -1 ? this.maxlength : void 0)}
|
|
138
|
+
minlength=${ifDefined(this.minlength > -1 ? this.minlength : void 0)}
|
|
139
|
+
pattern=${ifDefined(this.pattern)}
|
|
140
|
+
placeholder=${this.placeholder}
|
|
141
|
+
.value=${this.displayValue}
|
|
142
|
+
@change=${this.handleChange}
|
|
143
|
+
@input=${this.handleInput}
|
|
144
|
+
@focus=${this.onFocus}
|
|
145
|
+
@blur=${this.onBlur}
|
|
146
|
+
?disabled=${this.disabled}
|
|
147
|
+
?required=${this.required}
|
|
148
|
+
?readonly=${this.readonly}
|
|
149
|
+
autocomplete=${ifDefined(this.autocomplete)}
|
|
150
|
+
></textarea>
|
|
151
|
+
`;
|
|
152
|
+
}
|
|
153
|
+
get renderInput() {
|
|
154
|
+
return html`
|
|
155
|
+
<!-- @ts-ignore -->
|
|
156
|
+
<input
|
|
157
|
+
type=${this.type}
|
|
158
|
+
aria-describedby=${this.helpTextId}
|
|
159
|
+
aria-label=${this.label || this.placeholder}
|
|
160
|
+
aria-invalid=${ifDefined(this.invalid || void 0)}
|
|
161
|
+
class="input"
|
|
162
|
+
maxlength=${ifDefined(this.maxlength > -1 ? this.maxlength : void 0)}
|
|
163
|
+
minlength=${ifDefined(this.minlength > -1 ? this.minlength : void 0)}
|
|
164
|
+
pattern=${ifDefined(this.pattern)}
|
|
165
|
+
placeholder=${this.placeholder}
|
|
166
|
+
.value=${live(this.displayValue)}
|
|
167
|
+
@change=${this.handleChange}
|
|
168
|
+
@input=${this.handleInput}
|
|
169
|
+
@focus=${this.onFocus}
|
|
170
|
+
@blur=${this.onBlur}
|
|
171
|
+
?disabled=${this.disabled}
|
|
172
|
+
?required=${this.required}
|
|
173
|
+
?readonly=${this.readonly}
|
|
174
|
+
autocomplete=${ifDefined(this.autocomplete)}
|
|
175
|
+
/>
|
|
176
|
+
`;
|
|
177
|
+
}
|
|
178
|
+
renderField() {
|
|
179
|
+
return html`
|
|
180
|
+
${this.renderStateIcons()}
|
|
181
|
+
${this.multiline ? this.renderMultiline : this.renderInput}
|
|
182
|
+
`;
|
|
183
|
+
}
|
|
184
|
+
render() {
|
|
185
|
+
return html`
|
|
186
|
+
<div id="textfield">${this.renderField()}</div>
|
|
187
|
+
${this.renderHelpText(this.invalid)}
|
|
188
|
+
`;
|
|
189
|
+
}
|
|
190
|
+
update(changedProperties) {
|
|
191
|
+
if (changedProperties.has("value") || changedProperties.has("required") && this.required) {
|
|
192
|
+
this.updateComplete.then(() => {
|
|
193
|
+
this.checkValidity();
|
|
194
|
+
});
|
|
195
|
+
}
|
|
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;
|
|
210
|
+
}
|
|
211
|
+
return validity;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
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);
|
|
271
|
+
export class Textfield extends TextfieldBase {
|
|
272
|
+
constructor() {
|
|
273
|
+
super(...arguments);
|
|
274
|
+
this._value = "";
|
|
275
|
+
}
|
|
276
|
+
set value(value) {
|
|
277
|
+
if (value === this.value) {
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
const oldValue = this._value;
|
|
281
|
+
this._value = value;
|
|
282
|
+
this.requestUpdate("value", oldValue);
|
|
283
|
+
}
|
|
284
|
+
get value() {
|
|
285
|
+
return this._value;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
__decorateClass([
|
|
289
|
+
property({ type: String })
|
|
290
|
+
], Textfield.prototype, "value", 1);
|
|
291
|
+
//# sourceMappingURL=Textfield.dev.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
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}​</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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