@substrate-system/input 0.0.19 → 0.0.20
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/LICENSE +94 -25
- package/README.md +58 -27
- package/dist/index.cjs +128 -144
- package/dist/index.cjs.map +3 -3
- package/dist/index.css +29 -3
- package/dist/index.d.ts +31 -41
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +128 -144
- package/dist/index.js.map +2 -2
- package/dist/index.min.css +1 -2
- package/dist/index.min.js +18 -1
- package/dist/index.min.js.map +4 -4
- package/dist/meta.json +32 -21
- package/dist/util.cjs +112 -0
- package/dist/util.cjs.map +7 -0
- package/dist/util.d.ts +3 -0
- package/dist/util.d.ts.map +1 -0
- package/dist/util.js +92 -0
- package/dist/util.js.map +7 -0
- package/dist/util.min.js +2 -0
- package/dist/util.min.js.map +7 -0
- package/package.json +24 -48
- package/dist/html.cjs +0 -30
- package/dist/html.cjs.map +0 -7
- package/dist/html.d.ts +0 -18
- package/dist/html.d.ts.map +0 -1
- package/dist/html.js +0 -11
- package/dist/html.js.map +0 -7
- package/dist/html.min.js +0 -2
- package/dist/html.min.js.map +0 -7
package/LICENSE
CHANGED
|
@@ -6,11 +6,15 @@ Version 2.0.2
|
|
|
6
6
|
|
|
7
7
|
## Purpose
|
|
8
8
|
|
|
9
|
-
These terms let you use and share this software for noncommercial purposes
|
|
9
|
+
These terms let you use and share this software for noncommercial purposes
|
|
10
|
+
and in small business for free, while also guaranteeing that paid licenses
|
|
11
|
+
for big businesses will be available on fair, reasonable, and
|
|
12
|
+
nondiscriminatory terms.
|
|
10
13
|
|
|
11
14
|
## Acceptance
|
|
12
15
|
|
|
13
|
-
In order to get any license under these terms, you must agree to them as
|
|
16
|
+
In order to get any license under these terms, you must agree to them as
|
|
17
|
+
both strict obligations and conditions to all your licenses.
|
|
14
18
|
|
|
15
19
|
## Noncommercial Purposes
|
|
16
20
|
|
|
@@ -18,82 +22,147 @@ You may use the software for any noncommercial purpose.
|
|
|
18
22
|
|
|
19
23
|
## Personal Uses
|
|
20
24
|
|
|
21
|
-
Personal use for research, experiment, and testing for the benefit of
|
|
25
|
+
Personal use for research, experiment, and testing for the benefit of
|
|
26
|
+
public knowledge, personal study, private entertainment, hobby projects,
|
|
27
|
+
amateur pursuits, or religious observance, without any anticipated
|
|
28
|
+
commercial application, count as use for noncommercial purposes.
|
|
22
29
|
|
|
23
30
|
## Noncommercial Organizations
|
|
24
31
|
|
|
25
|
-
Use by any charitable organization, educational institution, public
|
|
32
|
+
Use by any charitable organization, educational institution, public
|
|
33
|
+
research organization, public safety or health organization, environmental
|
|
34
|
+
protection organization, or government institution counts as use for
|
|
35
|
+
noncommercial purposes, regardless of the source of funding or obligations
|
|
36
|
+
resulting from the funding.
|
|
26
37
|
|
|
27
38
|
## Small Business
|
|
28
39
|
|
|
29
|
-
You may use the software for the benefit of your company if it meets all
|
|
40
|
+
You may use the software for the benefit of your company if it meets all
|
|
41
|
+
these criteria:
|
|
30
42
|
|
|
31
|
-
1. had fewer than 20 total individuals working as employees and
|
|
43
|
+
1. had fewer than 20 total individuals working as employees and
|
|
44
|
+
independent contractors at all times during the last tax year
|
|
32
45
|
|
|
33
46
|
2. earned less than $1,000,000 total revenue in the last tax year
|
|
34
47
|
|
|
35
|
-
3. received less than $1,000,000 total debt, equity, and other investment
|
|
48
|
+
3. received less than $1,000,000 total debt, equity, and other investment
|
|
49
|
+
in the last five tax years, counting investment in predecessor
|
|
50
|
+
companies that reorganized into, merged with, or spun out your company
|
|
36
51
|
|
|
37
|
-
All dollar figures are United States dollars as of 2019. Adjust for them
|
|
52
|
+
All dollar figures are United States dollars as of 2019. Adjust for them
|
|
53
|
+
inflation according to the United States Bureau of Labor Statistics'
|
|
54
|
+
consumer price index for all urban consumers, United States city average,
|
|
55
|
+
for all items, not seasonally adjusted, with 1982–1984=100 reference base.
|
|
38
56
|
|
|
39
57
|
## Big Business
|
|
40
58
|
|
|
41
59
|
You may use the software for the benefit of your company:
|
|
42
60
|
|
|
43
|
-
1. for 128 days after your company stops qualifying under
|
|
61
|
+
1. for 128 days after your company stops qualifying under
|
|
62
|
+
[Small Business](#small-business)
|
|
44
63
|
|
|
45
|
-
2. indefinitely, if the licensor or their legal successor does not offer
|
|
64
|
+
2. indefinitely, if the licensor or their legal successor does not offer
|
|
65
|
+
fair, reasonable, and nondiscriminatory terms for a commercial license for
|
|
66
|
+
the software within 32 days of [written request](#how-to-request) and
|
|
67
|
+
negotiate in good faith to conclude a deal
|
|
46
68
|
|
|
47
69
|
## How to Request
|
|
48
70
|
|
|
49
|
-
If this software includes an address for the licensor or an agent of the
|
|
71
|
+
If this software includes an address for the licensor or an agent of the
|
|
72
|
+
licensor in a standard place, such as in documentation, software package
|
|
73
|
+
metadata, or an "about" page or screen, try to request a fair commercial
|
|
74
|
+
license at that address. If this package includes both online and offline
|
|
75
|
+
addresses, try online before offline. If you can't deliver a request that
|
|
76
|
+
way, or this software doesn't include any addressees, spend one hour online
|
|
77
|
+
researching an address, recording all your searches and inquiries as you
|
|
78
|
+
go, and try any addresses that you find. If you can't find any addresses,
|
|
79
|
+
or if those addresses also fail, that counts as failure to offer a fair
|
|
80
|
+
commercial license by the licensor under [Big Business](#big-business).
|
|
50
81
|
|
|
51
82
|
## Fair, Reasonable, and Nondiscriminatory Terms
|
|
52
83
|
|
|
53
|
-
Fair, reasonable, and nondiscriminatory terms may license the software
|
|
84
|
+
Fair, reasonable, and nondiscriminatory terms may license the software
|
|
85
|
+
perpetually or for a term, and may or may not cover new versions of the
|
|
86
|
+
software. If the licensor advertises license terms and a pricing structure
|
|
87
|
+
for generally available commercial licenses, the licensor proposes license
|
|
88
|
+
terms and a price as advertised, and a customer not affiliated with the
|
|
89
|
+
licensor has bought a commercial license for the software on substantially
|
|
90
|
+
equivalent terms in the past year, the proposal is fair, reasonable, and
|
|
91
|
+
nondiscriminatory.
|
|
54
92
|
|
|
55
93
|
## Copyright License
|
|
56
94
|
|
|
57
|
-
The licensor grants you a copyright license to do everything with the
|
|
95
|
+
The licensor grants you a copyright license to do everything with the
|
|
96
|
+
software that would otherwise infringe the licensor's copyright in it for
|
|
97
|
+
any purpose allowed by these terms.
|
|
58
98
|
|
|
59
99
|
## Notices
|
|
60
100
|
|
|
61
|
-
You must ensure that anyone who gets a copy of any part of the software
|
|
101
|
+
You must ensure that anyone who gets a copy of any part of the software
|
|
102
|
+
from you also gets a copy of these terms or the URL for them above, as well
|
|
103
|
+
as copies of any plain-text lines beginning with `Required Notice:` that
|
|
104
|
+
the licensor provided with the software. For example:
|
|
62
105
|
|
|
63
|
-
> Required Notice: Nick Thomas (https://nichoth.com)
|
|
106
|
+
> Required Notice: Copyright Nick Thomas (https://nichoth.com)
|
|
64
107
|
|
|
65
108
|
## Patent License
|
|
66
109
|
|
|
67
|
-
The licensor grants you a patent license for the software that covers
|
|
110
|
+
The licensor grants you a patent license for the software that covers
|
|
111
|
+
patent claims the licensor can license, or becomes able to license, that
|
|
112
|
+
you would infringe by using the software.
|
|
68
113
|
|
|
69
114
|
## Fair Use
|
|
70
115
|
|
|
71
|
-
You may have "fair use" rights for the software under the law. These terms
|
|
116
|
+
You may have "fair use" rights for the software under the law. These terms
|
|
117
|
+
do not limit them.
|
|
72
118
|
|
|
73
119
|
## No Other Rights
|
|
74
120
|
|
|
75
|
-
These terms do not allow you to sublicense or transfer any of your licenses
|
|
121
|
+
These terms do not allow you to sublicense or transfer any of your licenses
|
|
122
|
+
to anyone else, or prevent the licensor from granting licenses to anyone
|
|
123
|
+
else. These terms do not imply any other licenses.
|
|
76
124
|
|
|
77
125
|
## Patent Defense
|
|
78
126
|
|
|
79
|
-
If you make any written claim that the software infringes or contributes to
|
|
127
|
+
If you make any written claim that the software infringes or contributes to
|
|
128
|
+
infringement of any patent, your patent license for the software granted
|
|
129
|
+
under these terms ends immediately. If your company makes such a claim,
|
|
130
|
+
your patent license ends immediately for work on behalf of your company.
|
|
80
131
|
|
|
81
132
|
## Violations
|
|
82
133
|
|
|
83
|
-
The first time you are notified in writing that you have violated any of
|
|
134
|
+
The first time you are notified in writing that you have violated any of
|
|
135
|
+
these terms, or done anything with the software not covered by your
|
|
136
|
+
licenses, your licenses can nonetheless continue if you come into full
|
|
137
|
+
compliance with these terms, and take practical steps to correct past
|
|
138
|
+
violations, within 32 days of receiving notice. Otherwise, all your
|
|
139
|
+
licenses end immediately.
|
|
84
140
|
|
|
85
141
|
## No Liability
|
|
86
142
|
|
|
87
|
-
***As far as the law allows, the software comes as is, without any warranty
|
|
143
|
+
***As far as the law allows, the software comes as is, without any warranty
|
|
144
|
+
or condition, and the licensor will not be liable to you for any damages
|
|
145
|
+
arising out of these terms or the use or nature of the software, under any
|
|
146
|
+
kind of legal claim.***
|
|
88
147
|
|
|
89
148
|
## Definitions
|
|
90
149
|
|
|
91
|
-
The **licensor** is the individual or entity offering these terms, and
|
|
150
|
+
The **licensor** is the individual or entity offering these terms, and
|
|
151
|
+
the **software** is the software the licensor makes available under these
|
|
152
|
+
terms.
|
|
92
153
|
|
|
93
154
|
**You** refers to the individual or entity agreeing to these terms.
|
|
94
155
|
|
|
95
|
-
**Your company** is any legal entity, sole proprietorship, or other kind of
|
|
156
|
+
**Your company** is any legal entity, sole proprietorship, or other kind of
|
|
157
|
+
organization that you work for, plus all organizations that have control
|
|
158
|
+
over, are under the control of, or are under common control with that
|
|
159
|
+
organization. **Control** means ownership of substantially all the assets
|
|
160
|
+
of an entity, or the power to direct its management and policies by vote,
|
|
161
|
+
contract, or otherwise. Control can be direct or indirect.
|
|
96
162
|
|
|
97
|
-
**Your licenses** are all the licenses granted to you for the software
|
|
163
|
+
**Your licenses** are all the licenses granted to you for the software
|
|
164
|
+
under these terms.
|
|
165
|
+
|
|
166
|
+
**Use** means anything you do with the software requiring one of your
|
|
167
|
+
licenses.
|
|
98
168
|
|
|
99
|
-
**Use** means anything you do with the software requiring one of your licenses.
|
package/README.md
CHANGED
|
@@ -1,67 +1,98 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
1
|
+
# Input
|
|
2
|
+

|
|
3
3
|
[](README.md)
|
|
4
4
|
[](README.md)
|
|
5
|
-
[](https://packagephobia.com/result?p=@bicycle-codes/keys)
|
|
6
|
+
[](https://esm.sh/@substrate-system/input/es2022/input.mjs)
|
|
7
7
|
[](package.json)
|
|
8
8
|
[](https://semver.org/)
|
|
9
9
|
[](./CHANGELOG.md)
|
|
10
10
|
[](LICENSE)
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
Inputs with style.
|
|
14
14
|
|
|
15
15
|
[See a live demo](https://substrate-system.github.io/input/)
|
|
16
16
|
|
|
17
|
+
<details><summary><h2>Contents</h2></summary>
|
|
18
|
+
|
|
17
19
|
<!-- toc -->
|
|
18
20
|
|
|
19
21
|
- [Install](#install)
|
|
20
|
-
- [
|
|
21
|
-
* [
|
|
22
|
-
* [
|
|
23
|
-
- [
|
|
22
|
+
- [CSS](#css)
|
|
23
|
+
* [Import CSS](#import-css)
|
|
24
|
+
* [Customize CSS via some variables](#customize-css-via-some-variables)
|
|
25
|
+
- [use](#use)
|
|
24
26
|
* [JS](#js)
|
|
27
|
+
* [HTML](#html)
|
|
28
|
+
* [pre-built](#pre-built)
|
|
25
29
|
|
|
26
30
|
<!-- tocstop -->
|
|
27
31
|
|
|
32
|
+
</details>
|
|
33
|
+
|
|
28
34
|
## Install
|
|
29
35
|
|
|
36
|
+
Installation instructions
|
|
37
|
+
|
|
30
38
|
```sh
|
|
31
39
|
npm i -S @substrate-system/input
|
|
32
40
|
```
|
|
33
41
|
|
|
34
|
-
##
|
|
42
|
+
## CSS
|
|
35
43
|
|
|
36
|
-
|
|
44
|
+
### Import CSS
|
|
37
45
|
|
|
38
|
-
### ESM
|
|
39
46
|
```js
|
|
40
|
-
import
|
|
47
|
+
import '@substrate-system/input/css'
|
|
41
48
|
```
|
|
42
49
|
|
|
43
|
-
|
|
50
|
+
Or minified:
|
|
44
51
|
```js
|
|
45
|
-
|
|
52
|
+
import '@substrate-system/input/min/css'
|
|
46
53
|
```
|
|
47
54
|
|
|
48
|
-
|
|
55
|
+
### Customize CSS via some variables
|
|
56
|
+
|
|
57
|
+
```css
|
|
58
|
+
substrate-input {
|
|
59
|
+
--example: pink;
|
|
60
|
+
}
|
|
61
|
+
```
|
|
49
62
|
|
|
50
|
-
##
|
|
51
|
-
|
|
63
|
+
## use
|
|
64
|
+
This calls the global function `customElements.define`. Just import, then use
|
|
65
|
+
the tag in your HTML.
|
|
52
66
|
|
|
53
67
|
### JS
|
|
54
68
|
```js
|
|
55
|
-
import
|
|
69
|
+
import '@substrate-system/input'
|
|
70
|
+
```
|
|
56
71
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
72
|
+
### HTML
|
|
73
|
+
```html
|
|
74
|
+
<div>
|
|
75
|
+
<substrate-input></substrate-input>
|
|
76
|
+
</div>
|
|
77
|
+
```
|
|
60
78
|
|
|
61
|
-
|
|
62
|
-
|
|
79
|
+
### pre-built
|
|
80
|
+
This package exposes minified JS and CSS files too. Copy them to a location that is
|
|
81
|
+
accessible to your web server, then link to them in HTML.
|
|
82
|
+
|
|
83
|
+
#### copy
|
|
84
|
+
```sh
|
|
85
|
+
cp ./node_modules/@substrate-system/input/dist/index.min.js ./public/substrate-input.min.js
|
|
86
|
+
cp ./node_modules/@substrate-system/input/dist/style.min.css ./public/substrate-input.css
|
|
87
|
+
```
|
|
63
88
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
89
|
+
#### HTML
|
|
90
|
+
```html
|
|
91
|
+
<head>
|
|
92
|
+
<link rel="stylesheet" href="./substrate-input.css">
|
|
93
|
+
</head>
|
|
94
|
+
<body>
|
|
95
|
+
<!-- ... -->
|
|
96
|
+
<script type="module" src="./substrate-input.min.js"></script>
|
|
97
|
+
</body>
|
|
67
98
|
```
|
package/dist/index.cjs
CHANGED
|
@@ -19,169 +19,153 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
19
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
20
|
var index_exports = {};
|
|
21
21
|
__export(index_exports, {
|
|
22
|
-
|
|
22
|
+
SubstrateInput: () => SubstrateInput
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(index_exports);
|
|
25
|
-
|
|
25
|
+
var import_web_component = require("@substrate-system/web-component");
|
|
26
|
+
var import_util = require("@substrate-system/web-component/util");
|
|
27
|
+
var import_util2 = require("./util");
|
|
28
|
+
class SubstrateInput extends import_web_component.WebComponent.create("substrate-input") {
|
|
26
29
|
static {
|
|
27
|
-
__name(this, "
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
static
|
|
31
|
-
static
|
|
32
|
-
static
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (disabled !== null) {
|
|
41
|
-
setTimeout(() => {
|
|
42
|
-
this.disabled = true;
|
|
43
|
-
}, 0);
|
|
44
|
-
}
|
|
45
|
-
setTimeout(() => {
|
|
46
|
-
const attr = this.getAttribute("value");
|
|
47
|
-
if (attr) this.value = attr;
|
|
48
|
-
const type = this.getAttribute("type");
|
|
49
|
-
if (type) this.type = type;
|
|
50
|
-
}, 0);
|
|
51
|
-
}
|
|
52
|
-
get input() {
|
|
53
|
-
return this.querySelector("input");
|
|
54
|
-
}
|
|
55
|
-
get tabindex() {
|
|
56
|
-
const i = this.input?.getAttribute("tabindex");
|
|
57
|
-
if (!i) return 0;
|
|
58
|
-
return parseInt(i);
|
|
59
|
-
}
|
|
60
|
-
get name() {
|
|
61
|
-
return this.getAttribute("name");
|
|
62
|
-
}
|
|
63
|
-
get placeholder() {
|
|
64
|
-
return this.getAttribute("placeholder");
|
|
65
|
-
}
|
|
66
|
-
get autocomplete() {
|
|
67
|
-
return this.getAttribute("autocomplete");
|
|
68
|
-
}
|
|
69
|
-
set name(newName) {
|
|
70
|
-
this.setAttribute("name", newName);
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Remove from `this` element and also child.
|
|
74
|
-
*/
|
|
75
|
-
_removeAttribute(name) {
|
|
76
|
-
this.removeAttribute(name);
|
|
77
|
-
this.input?.removeAttribute(name);
|
|
30
|
+
__name(this, "SubstrateInput");
|
|
31
|
+
}
|
|
32
|
+
static TAG = "substrate-input";
|
|
33
|
+
static INPUT_ATTRIBUTES = import_util2.INPUT_ATTRIBUTES;
|
|
34
|
+
static ARIA_ATTRIBUTES = import_util2.ARIA_ATTRIBUTES;
|
|
35
|
+
static observedAttributes = ["label", "id"].concat(SubstrateInput.INPUT_ATTRIBUTES).concat(SubstrateInput.ARIA_ATTRIBUTES);
|
|
36
|
+
inputId = null;
|
|
37
|
+
inputAriaAttributes = {};
|
|
38
|
+
ignoredAriaCallbackNames = /* @__PURE__ */ new Set();
|
|
39
|
+
ignoredIdCallback = false;
|
|
40
|
+
generatedInputId = `substrate-input-${Math.random().toString(36).slice(2, 10)}`;
|
|
41
|
+
handleChange_label(_oldValue, _newValue) {
|
|
42
|
+
this.render();
|
|
78
43
|
}
|
|
79
|
-
|
|
80
|
-
|
|
44
|
+
handleChange_aria(name, _oldValue, newValue) {
|
|
45
|
+
if (this.ignoredAriaCallbackNames.has(name)) {
|
|
46
|
+
this.ignoredAriaCallbackNames.delete(name);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (newValue === null) {
|
|
50
|
+
delete this.inputAriaAttributes[name];
|
|
51
|
+
this.querySelector("input")?.removeAttribute(name);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
this.inputAriaAttributes[name] = newValue;
|
|
55
|
+
this.querySelector("input")?.setAttribute(name, newValue);
|
|
56
|
+
if (this.hasAttribute(name)) {
|
|
57
|
+
this.ignoredAriaCallbackNames.add(name);
|
|
58
|
+
this.removeAttribute(name);
|
|
59
|
+
}
|
|
81
60
|
}
|
|
82
|
-
|
|
83
|
-
if (
|
|
84
|
-
this.
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
this.
|
|
61
|
+
handleChange_id(_oldValue, newValue) {
|
|
62
|
+
if (this.ignoredIdCallback) {
|
|
63
|
+
this.ignoredIdCallback = false;
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (newValue === null) {
|
|
67
|
+
this.inputId = null;
|
|
68
|
+
this.querySelector("input")?.removeAttribute("id");
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
this.inputId = newValue;
|
|
72
|
+
this.querySelector("input")?.setAttribute("id", newValue);
|
|
73
|
+
if (this.hasAttribute("id")) {
|
|
74
|
+
this.ignoredIdCallback = true;
|
|
75
|
+
this.removeAttribute("id");
|
|
89
76
|
}
|
|
90
77
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
*/
|
|
98
|
-
handleChange_disabled(_oldValue, newValue) {
|
|
99
|
-
if (!this.input) {
|
|
100
|
-
setTimeout(() => {
|
|
101
|
-
if (newValue === null || newValue === "null") {
|
|
102
|
-
this.disabled = false;
|
|
103
|
-
} else {
|
|
104
|
-
this.disabled = true;
|
|
105
|
-
}
|
|
106
|
-
}, 0);
|
|
107
|
-
} else {
|
|
108
|
-
if (newValue === null || newValue === "null") {
|
|
109
|
-
this.disabled = false;
|
|
110
|
-
} else {
|
|
111
|
-
this.disabled = true;
|
|
112
|
-
}
|
|
78
|
+
handleChange_inputAttribute(name, newValue) {
|
|
79
|
+
const input = this.querySelector("input");
|
|
80
|
+
if (!input) return;
|
|
81
|
+
if (newValue === null) {
|
|
82
|
+
input.removeAttribute(name);
|
|
83
|
+
return;
|
|
113
84
|
}
|
|
85
|
+
input.setAttribute(name, newValue);
|
|
114
86
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
87
|
+
async attributeChangedCallback(name, oldValue, newValue) {
|
|
88
|
+
if (name === "id") {
|
|
89
|
+
this.handleChange_id(oldValue, newValue);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (name.startsWith("aria-")) {
|
|
93
|
+
this.handleChange_aria(name, oldValue, newValue);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (SubstrateInput.INPUT_ATTRIBUTES.includes(name)) {
|
|
97
|
+
this.handleChange_inputAttribute(name, newValue);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (this[`handleChange_${name}`]) {
|
|
101
|
+
this[`handleChange_${name}`](oldValue, newValue);
|
|
102
|
+
}
|
|
126
103
|
}
|
|
127
104
|
connectedCallback() {
|
|
128
105
|
this.render();
|
|
129
106
|
}
|
|
130
|
-
|
|
131
|
-
return this.
|
|
107
|
+
getInputIdForRender() {
|
|
108
|
+
return this.inputId || this.generatedInputId;
|
|
132
109
|
}
|
|
133
|
-
set
|
|
134
|
-
|
|
110
|
+
set label(value) {
|
|
111
|
+
if (value === null) {
|
|
112
|
+
this.removeAttribute("label");
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
this.setAttribute("label", value);
|
|
135
116
|
}
|
|
136
|
-
get
|
|
137
|
-
return this.
|
|
117
|
+
get label() {
|
|
118
|
+
return this.getAttribute("label");
|
|
138
119
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
120
|
+
render() {
|
|
121
|
+
const label = this.getAttribute("label");
|
|
122
|
+
const hostId = this.getAttribute("id");
|
|
123
|
+
const hostAriaAttributes = Array.from(this.attributes).filter((attr) => attr.name.startsWith("aria-"));
|
|
124
|
+
if (hostId !== null) {
|
|
125
|
+
this.inputId = hostId;
|
|
143
126
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
* Set attributes on the internal input element.
|
|
147
|
-
*/
|
|
148
|
-
_setAttribute(name, value) {
|
|
149
|
-
if (!value) {
|
|
150
|
-
return this._removeAttribute(name);
|
|
127
|
+
for (const attr of hostAriaAttributes) {
|
|
128
|
+
this.inputAriaAttributes[attr.name] = attr.value;
|
|
151
129
|
}
|
|
152
|
-
|
|
153
|
-
|
|
130
|
+
const name = this.getAttribute("name");
|
|
131
|
+
const attrs = Array.from(this.attributes).filter(
|
|
132
|
+
(attr) => attr.name !== "label" && attr.name !== "id" && !attr.name.startsWith("aria-")
|
|
133
|
+
).map(
|
|
134
|
+
(attr) => attr.name + (attr.value === "" ? "" : `="${attr.value}"`)
|
|
135
|
+
).join(" ");
|
|
136
|
+
const classes = (this.getAttribute("class") ?? "").split(" ").concat(["substrate", "input", name || ""]).filter(Boolean).join(" ");
|
|
137
|
+
const inputId = this.getInputIdForRender();
|
|
138
|
+
const renderedIdAttribute = `id="${inputId}"`;
|
|
139
|
+
const ariaAttributes = Object.entries(this.inputAriaAttributes).map(([attrName, attrValue]) => {
|
|
140
|
+
return attrName + (attrValue === "" ? "" : `="${attrValue}"`);
|
|
141
|
+
}).join(" ");
|
|
142
|
+
this.innerHTML = label ? `
|
|
143
|
+
<div class="${classes}">
|
|
144
|
+
<label class="label-content" for="${inputId}">${label}</label>
|
|
145
|
+
<input
|
|
146
|
+
${renderedIdAttribute}
|
|
147
|
+
${ariaAttributes}
|
|
148
|
+
${attrs}
|
|
149
|
+
/>
|
|
150
|
+
</div>
|
|
151
|
+
` : `
|
|
152
|
+
<div class="${classes}">
|
|
153
|
+
<input
|
|
154
|
+
${renderedIdAttribute}
|
|
155
|
+
${ariaAttributes}
|
|
156
|
+
${attrs}
|
|
157
|
+
/>
|
|
158
|
+
</div>
|
|
159
|
+
`;
|
|
160
|
+
if (this.hasAttribute("id")) {
|
|
161
|
+
this.ignoredIdCallback = true;
|
|
162
|
+
this.removeAttribute("id");
|
|
163
|
+
}
|
|
164
|
+
for (const attr of hostAriaAttributes) {
|
|
165
|
+
this.ignoredAriaCallbackNames.add(attr.name);
|
|
166
|
+
this.removeAttribute(attr.name);
|
|
154
167
|
}
|
|
155
|
-
this.input?.setAttribute(name, value);
|
|
156
|
-
}
|
|
157
|
-
render() {
|
|
158
|
-
const {
|
|
159
|
-
type,
|
|
160
|
-
autofocus,
|
|
161
|
-
tabindex,
|
|
162
|
-
disabled,
|
|
163
|
-
value,
|
|
164
|
-
name,
|
|
165
|
-
placeholder,
|
|
166
|
-
autocomplete
|
|
167
|
-
} = this;
|
|
168
|
-
if (!name) throw new Error("not name");
|
|
169
|
-
const classes = ["substrate-input"];
|
|
170
|
-
const btn = !!(this.type === "submit" || this.type === "button");
|
|
171
|
-
const props = [
|
|
172
|
-
`class="${classes.filter(Boolean).join(" ")}"`,
|
|
173
|
-
disabled ? "disabled" : "",
|
|
174
|
-
disabled ? 'aria-disabled="true"' : 'aria-disabled="false"',
|
|
175
|
-
autofocus ? "autofocus" : "",
|
|
176
|
-
type ? `type="${this.type}"` : "",
|
|
177
|
-
tabindex ? `tabindex="${tabindex}"` : 'tabindex="0"',
|
|
178
|
-
btn ? 'role="button"' : "",
|
|
179
|
-
value ? `value="${value}"` : "",
|
|
180
|
-
name ? `name="${name}"` : "",
|
|
181
|
-
autocomplete ? `autocomplete="${autocomplete}"` : "",
|
|
182
|
-
placeholder ? `placeholder="${placeholder}"` : ""
|
|
183
|
-
].filter(Boolean).join(" ");
|
|
184
|
-
return `<input ${props} />`;
|
|
185
168
|
}
|
|
186
169
|
}
|
|
170
|
+
(0, import_util.define)(SubstrateInput.TAG, SubstrateInput);
|
|
187
171
|
//# sourceMappingURL=index.cjs.map
|