@joist/element 4.0.0-next.4 → 4.0.0-next.41
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/README.md +102 -15
- package/package.json +7 -9
- package/src/lib/attr-changed.test.ts +34 -0
- package/src/lib/attr-changed.ts +15 -0
- package/src/lib/attr.test.ts +159 -97
- package/src/lib/attr.ts +26 -33
- package/src/lib/element.test.ts +95 -71
- package/src/lib/element.ts +107 -51
- package/src/lib/lifecycle.test.ts +31 -0
- package/src/lib/lifecycle.ts +9 -0
- package/src/lib/listen.test.ts +104 -0
- package/src/lib/listen.ts +27 -7
- package/src/lib/metadata.ts +21 -8
- package/src/lib/query.test.ts +21 -47
- package/src/lib/query.ts +2 -8
- package/src/lib/result.ts +1 -21
- package/src/lib/tags.ts +27 -12
- package/src/lib/template.test.ts +123 -0
- package/src/lib/template.ts +118 -0
- package/src/lib.ts +3 -2
- package/target/lib/attr-changed.d.ts +1 -0
- package/target/lib/attr-changed.js +10 -0
- package/target/lib/attr-changed.js.map +1 -0
- package/target/lib/attr-changed.test.d.ts +1 -0
- package/target/lib/attr-changed.test.js +54 -0
- package/target/lib/attr-changed.test.js.map +1 -0
- package/target/lib/attr.d.ts +3 -1
- package/target/lib/attr.js +23 -25
- package/target/lib/attr.js.map +1 -1
- package/target/lib/attr.test.js +373 -251
- package/target/lib/attr.test.js.map +1 -1
- package/target/lib/element.d.ts +8 -339
- package/target/lib/element.js +81 -39
- package/target/lib/element.js.map +1 -1
- package/target/lib/element.test.js +154 -178
- package/target/lib/element.test.js.map +1 -1
- package/target/lib/lifecycle.d.ts +1 -0
- package/target/lib/lifecycle.js +8 -0
- package/target/lib/lifecycle.js.map +1 -0
- package/target/lib/lifecycle.test.d.ts +1 -0
- package/target/lib/lifecycle.test.js +48 -0
- package/target/lib/lifecycle.test.js.map +1 -0
- package/target/lib/listen.d.ts +2 -2
- package/target/lib/listen.js +18 -3
- package/target/lib/listen.js.map +1 -1
- package/target/lib/listen.test.d.ts +1 -0
- package/target/lib/listen.test.js +167 -0
- package/target/lib/listen.test.js.map +1 -0
- package/target/lib/metadata.d.ts +20 -10
- package/target/lib/metadata.js +8 -2
- package/target/lib/metadata.js.map +1 -1
- package/target/lib/query.d.ts +1 -1
- package/target/lib/query.js +1 -6
- package/target/lib/query.js.map +1 -1
- package/target/lib/query.test.js +35 -74
- package/target/lib/query.test.js.map +1 -1
- package/target/lib/result.d.ts +1 -8
- package/target/lib/result.js +1 -14
- package/target/lib/result.js.map +1 -1
- package/target/lib/tags.d.ts +10 -6
- package/target/lib/tags.js +20 -11
- package/target/lib/tags.js.map +1 -1
- package/target/lib/template.d.ts +11 -0
- package/target/lib/template.js +87 -0
- package/target/lib/template.js.map +1 -0
- package/target/lib/template.test.d.ts +1 -0
- package/target/lib/template.test.js +91 -0
- package/target/lib/template.test.js.map +1 -0
- package/target/lib.d.ts +3 -2
- package/target/lib.js +3 -2
- package/target/lib.js.map +1 -1
package/target/lib/attr.test.js
CHANGED
|
@@ -1,194 +1,257 @@
|
|
|
1
1
|
import { __esDecorate, __propKey, __runInitializers } from "tslib";
|
|
2
|
-
import { expect
|
|
2
|
+
import { expect } from 'chai';
|
|
3
3
|
import { attr } from './attr.js';
|
|
4
4
|
import { element } from './element.js';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
let
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
5
|
+
it('should read and parse the correct values', () => {
|
|
6
|
+
let MyElement = (() => {
|
|
7
|
+
let _classDecorators = [element({
|
|
8
|
+
tagName: 'attr-test-1'
|
|
9
|
+
})];
|
|
10
|
+
let _classDescriptor;
|
|
11
|
+
let _classExtraInitializers = [];
|
|
12
|
+
let _classThis;
|
|
13
|
+
let _classSuper = HTMLElement;
|
|
14
|
+
let _value1_decorators;
|
|
15
|
+
let _value1_initializers = [];
|
|
16
|
+
let _value1_extraInitializers = [];
|
|
17
|
+
let _value2_decorators;
|
|
18
|
+
let _value2_initializers = [];
|
|
19
|
+
let _value2_extraInitializers = [];
|
|
20
|
+
let _value3_decorators;
|
|
21
|
+
let _value3_initializers = [];
|
|
22
|
+
let _value3_extraInitializers = [];
|
|
23
|
+
let _value4_decorators;
|
|
24
|
+
let _value4_initializers = [];
|
|
25
|
+
let _value4_extraInitializers = [];
|
|
26
|
+
var MyElement = class extends _classSuper {
|
|
27
|
+
static { _classThis = this; }
|
|
28
|
+
static {
|
|
29
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
30
|
+
_value1_decorators = [attr()];
|
|
31
|
+
_value2_decorators = [attr()];
|
|
32
|
+
_value3_decorators = [attr()];
|
|
33
|
+
_value4_decorators = [attr()];
|
|
34
|
+
__esDecorate(this, null, _value1_decorators, { kind: "accessor", name: "value1", static: false, private: false, access: { has: obj => "value1" in obj, get: obj => obj.value1, set: (obj, value) => { obj.value1 = value; } }, metadata: _metadata }, _value1_initializers, _value1_extraInitializers);
|
|
35
|
+
__esDecorate(this, null, _value2_decorators, { kind: "accessor", name: "value2", static: false, private: false, access: { has: obj => "value2" in obj, get: obj => obj.value2, set: (obj, value) => { obj.value2 = value; } }, metadata: _metadata }, _value2_initializers, _value2_extraInitializers);
|
|
36
|
+
__esDecorate(this, null, _value3_decorators, { kind: "accessor", name: "value3", static: false, private: false, access: { has: obj => "value3" in obj, get: obj => obj.value3, set: (obj, value) => { obj.value3 = value; } }, metadata: _metadata }, _value3_initializers, _value3_extraInitializers);
|
|
37
|
+
__esDecorate(this, null, _value4_decorators, { kind: "accessor", name: "value4", static: false, private: false, access: { has: obj => "value4" in obj, get: obj => obj.value4, set: (obj, value) => { obj.value4 = value; } }, metadata: _metadata }, _value4_initializers, _value4_extraInitializers);
|
|
38
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
39
|
+
MyElement = _classThis = _classDescriptor.value;
|
|
40
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
41
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
42
|
+
}
|
|
43
|
+
#value1_accessor_storage = __runInitializers(this, _value1_initializers, 100);
|
|
44
|
+
get value1() { return this.#value1_accessor_storage; }
|
|
45
|
+
set value1(value) { this.#value1_accessor_storage = value; }
|
|
46
|
+
#value2_accessor_storage = (__runInitializers(this, _value1_extraInitializers), __runInitializers(this, _value2_initializers, 0));
|
|
47
|
+
get value2() { return this.#value2_accessor_storage; }
|
|
48
|
+
set value2(value) { this.#value2_accessor_storage = value; }
|
|
49
|
+
#value3_accessor_storage = (__runInitializers(this, _value2_extraInitializers), __runInitializers(this, _value3_initializers, false));
|
|
50
|
+
get value3() { return this.#value3_accessor_storage; }
|
|
51
|
+
set value3(value) { this.#value3_accessor_storage = value; }
|
|
52
|
+
#value4_accessor_storage = (__runInitializers(this, _value3_extraInitializers), __runInitializers(this, _value4_initializers, 'hello'));
|
|
53
|
+
get value4() { return this.#value4_accessor_storage; }
|
|
54
|
+
set value4(value) { this.#value4_accessor_storage = value; }
|
|
55
|
+
constructor() {
|
|
56
|
+
super(...arguments);
|
|
57
|
+
__runInitializers(this, _value4_extraInitializers);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
return MyElement = _classThis;
|
|
61
|
+
})();
|
|
62
|
+
const container = document.createElement('div');
|
|
63
|
+
container.innerHTML = `
|
|
64
|
+
<attr-test-1 value2="2" value3 value4="world"></attr-test-1>
|
|
65
|
+
`;
|
|
66
|
+
document.body.append(container);
|
|
67
|
+
const el = document.querySelector('attr-test-1');
|
|
68
|
+
expect(el.value1).to.equal(100);
|
|
69
|
+
expect(el.value2).to.equal(2);
|
|
70
|
+
expect(el.value3).to.equal(true);
|
|
71
|
+
expect(el.value4).to.equal('world');
|
|
72
|
+
container.remove();
|
|
73
|
+
});
|
|
74
|
+
it('should not write falsy props to attributes', async () => {
|
|
75
|
+
let MyElement = (() => {
|
|
76
|
+
let _classDecorators = [element({
|
|
77
|
+
tagName: 'attr-test-2'
|
|
78
|
+
})];
|
|
79
|
+
let _classDescriptor;
|
|
80
|
+
let _classExtraInitializers = [];
|
|
81
|
+
let _classThis;
|
|
82
|
+
let _classSuper = HTMLElement;
|
|
83
|
+
let _value1_decorators;
|
|
84
|
+
let _value1_initializers = [];
|
|
85
|
+
let _value1_extraInitializers = [];
|
|
86
|
+
let _value2_decorators;
|
|
87
|
+
let _value2_initializers = [];
|
|
88
|
+
let _value2_extraInitializers = [];
|
|
89
|
+
let _value3_decorators;
|
|
90
|
+
let _value3_initializers = [];
|
|
91
|
+
let _value3_extraInitializers = [];
|
|
92
|
+
var MyElement = class extends _classSuper {
|
|
93
|
+
static { _classThis = this; }
|
|
94
|
+
static {
|
|
95
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
96
|
+
_value1_decorators = [attr()];
|
|
97
|
+
_value2_decorators = [attr()];
|
|
98
|
+
_value3_decorators = [attr()];
|
|
99
|
+
__esDecorate(this, null, _value1_decorators, { kind: "accessor", name: "value1", static: false, private: false, access: { has: obj => "value1" in obj, get: obj => obj.value1, set: (obj, value) => { obj.value1 = value; } }, metadata: _metadata }, _value1_initializers, _value1_extraInitializers);
|
|
100
|
+
__esDecorate(this, null, _value2_decorators, { kind: "accessor", name: "value2", static: false, private: false, access: { has: obj => "value2" in obj, get: obj => obj.value2, set: (obj, value) => { obj.value2 = value; } }, metadata: _metadata }, _value2_initializers, _value2_extraInitializers);
|
|
101
|
+
__esDecorate(this, null, _value3_decorators, { kind: "accessor", name: "value3", static: false, private: false, access: { has: obj => "value3" in obj, get: obj => obj.value3, set: (obj, value) => { obj.value3 = value; } }, metadata: _metadata }, _value3_initializers, _value3_extraInitializers);
|
|
102
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
103
|
+
MyElement = _classThis = _classDescriptor.value;
|
|
104
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
105
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
106
|
+
}
|
|
107
|
+
#value1_accessor_storage = __runInitializers(this, _value1_initializers, undefined);
|
|
108
|
+
get value1() { return this.#value1_accessor_storage; }
|
|
109
|
+
set value1(value) { this.#value1_accessor_storage = value; }
|
|
110
|
+
#value2_accessor_storage = (__runInitializers(this, _value1_extraInitializers), __runInitializers(this, _value2_initializers, null));
|
|
111
|
+
get value2() { return this.#value2_accessor_storage; }
|
|
112
|
+
set value2(value) { this.#value2_accessor_storage = value; }
|
|
113
|
+
#value3_accessor_storage = (__runInitializers(this, _value2_extraInitializers), __runInitializers(this, _value3_initializers, ''));
|
|
114
|
+
get value3() { return this.#value3_accessor_storage; }
|
|
115
|
+
set value3(value) { this.#value3_accessor_storage = value; }
|
|
116
|
+
constructor() {
|
|
117
|
+
super(...arguments);
|
|
118
|
+
__runInitializers(this, _value3_extraInitializers);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
return MyElement = _classThis;
|
|
122
|
+
})();
|
|
123
|
+
const el = new MyElement();
|
|
124
|
+
expect(el.hasAttribute('value1')).to.be.false;
|
|
125
|
+
expect(el.hasAttribute('value2')).to.be.false;
|
|
126
|
+
expect(el.hasAttribute('value3')).to.be.false;
|
|
127
|
+
});
|
|
128
|
+
it('should update attributes when props are changed', async () => {
|
|
129
|
+
let MyElement = (() => {
|
|
130
|
+
let _classDecorators = [element({
|
|
131
|
+
tagName: 'attr-test-3'
|
|
132
|
+
})];
|
|
133
|
+
let _classDescriptor;
|
|
134
|
+
let _classExtraInitializers = [];
|
|
135
|
+
let _classThis;
|
|
136
|
+
let _classSuper = HTMLElement;
|
|
137
|
+
let _value1_decorators;
|
|
138
|
+
let _value1_initializers = [];
|
|
139
|
+
let _value1_extraInitializers = [];
|
|
140
|
+
let _value2_decorators;
|
|
141
|
+
let _value2_initializers = [];
|
|
142
|
+
let _value2_extraInitializers = [];
|
|
143
|
+
let _value3_decorators;
|
|
144
|
+
let _value3_initializers = [];
|
|
145
|
+
let _value3_extraInitializers = [];
|
|
146
|
+
let _value4_decorators;
|
|
147
|
+
let _value4_initializers = [];
|
|
148
|
+
let _value4_extraInitializers = [];
|
|
149
|
+
var MyElement = class extends _classSuper {
|
|
150
|
+
static { _classThis = this; }
|
|
151
|
+
static {
|
|
152
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
153
|
+
_value1_decorators = [attr()];
|
|
154
|
+
_value2_decorators = [attr()];
|
|
155
|
+
_value3_decorators = [attr()];
|
|
156
|
+
_value4_decorators = [attr()];
|
|
157
|
+
__esDecorate(this, null, _value1_decorators, { kind: "accessor", name: "value1", static: false, private: false, access: { has: obj => "value1" in obj, get: obj => obj.value1, set: (obj, value) => { obj.value1 = value; } }, metadata: _metadata }, _value1_initializers, _value1_extraInitializers);
|
|
158
|
+
__esDecorate(this, null, _value2_decorators, { kind: "accessor", name: "value2", static: false, private: false, access: { has: obj => "value2" in obj, get: obj => obj.value2, set: (obj, value) => { obj.value2 = value; } }, metadata: _metadata }, _value2_initializers, _value2_extraInitializers);
|
|
159
|
+
__esDecorate(this, null, _value3_decorators, { kind: "accessor", name: "value3", static: false, private: false, access: { has: obj => "value3" in obj, get: obj => obj.value3, set: (obj, value) => { obj.value3 = value; } }, metadata: _metadata }, _value3_initializers, _value3_extraInitializers);
|
|
160
|
+
__esDecorate(this, null, _value4_decorators, { kind: "accessor", name: "value4", static: false, private: false, access: { has: obj => "value4" in obj, get: obj => obj.value4, set: (obj, value) => { obj.value4 = value; } }, metadata: _metadata }, _value4_initializers, _value4_extraInitializers);
|
|
161
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
162
|
+
MyElement = _classThis = _classDescriptor.value;
|
|
163
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
164
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
165
|
+
}
|
|
166
|
+
#value1_accessor_storage = __runInitializers(this, _value1_initializers, 'hello');
|
|
167
|
+
get value1() { return this.#value1_accessor_storage; }
|
|
168
|
+
set value1(value) { this.#value1_accessor_storage = value; }
|
|
169
|
+
#value2_accessor_storage = (__runInitializers(this, _value1_extraInitializers), __runInitializers(this, _value2_initializers, 0));
|
|
170
|
+
get value2() { return this.#value2_accessor_storage; }
|
|
171
|
+
set value2(value) { this.#value2_accessor_storage = value; }
|
|
172
|
+
#value3_accessor_storage = (__runInitializers(this, _value2_extraInitializers), __runInitializers(this, _value3_initializers, true));
|
|
173
|
+
get value3() { return this.#value3_accessor_storage; }
|
|
174
|
+
set value3(value) { this.#value3_accessor_storage = value; }
|
|
175
|
+
#value4_accessor_storage = (__runInitializers(this, _value3_extraInitializers), __runInitializers(this, _value4_initializers, false));
|
|
176
|
+
get value4() { return this.#value4_accessor_storage; }
|
|
177
|
+
set value4(value) { this.#value4_accessor_storage = value; }
|
|
178
|
+
constructor() {
|
|
179
|
+
super(...arguments);
|
|
180
|
+
__runInitializers(this, _value4_extraInitializers);
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
return MyElement = _classThis;
|
|
184
|
+
})();
|
|
185
|
+
const el = new MyElement();
|
|
186
|
+
el.value1 = 'world';
|
|
187
|
+
el.value2 = 100;
|
|
188
|
+
el.value3 = false;
|
|
189
|
+
el.value4 = true;
|
|
190
|
+
expect(el.getAttribute('value1')).to.equal('world');
|
|
191
|
+
expect(el.getAttribute('value2')).to.equal('100');
|
|
192
|
+
expect(el.hasAttribute('value3')).to.be.false;
|
|
193
|
+
expect(el.hasAttribute('value4')).to.be.true;
|
|
194
|
+
});
|
|
195
|
+
it('should normalize attribute names', async () => {
|
|
196
|
+
const value3 = Symbol('Value from SYMBOL');
|
|
197
|
+
let MyElement = (() => {
|
|
198
|
+
var _a;
|
|
199
|
+
let _classDecorators = [element({
|
|
200
|
+
tagName: 'attr-test-4'
|
|
201
|
+
})];
|
|
202
|
+
let _classDescriptor;
|
|
203
|
+
let _classExtraInitializers = [];
|
|
204
|
+
let _classThis;
|
|
205
|
+
let _classSuper = HTMLElement;
|
|
206
|
+
let _Value1_decorators;
|
|
207
|
+
let _Value1_initializers = [];
|
|
208
|
+
let _Value1_extraInitializers = [];
|
|
209
|
+
let _member_decorators;
|
|
210
|
+
let _member_initializers = [];
|
|
211
|
+
let _member_extraInitializers = [];
|
|
212
|
+
let _member_decorators_1;
|
|
213
|
+
let _member_initializers_1 = [];
|
|
214
|
+
let _member_extraInitializers_1 = [];
|
|
215
|
+
var MyElement = class extends _classSuper {
|
|
216
|
+
static { _classThis = this; }
|
|
217
|
+
static {
|
|
218
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
219
|
+
__esDecorate(this, null, _Value1_decorators, { kind: "accessor", name: "Value1", static: false, private: false, access: { has: obj => "Value1" in obj, get: obj => obj.Value1, set: (obj, value) => { obj.Value1 = value; } }, metadata: _metadata }, _Value1_initializers, _Value1_extraInitializers);
|
|
220
|
+
__esDecorate(this, null, _member_decorators, { kind: "accessor", name: 'Value 2', static: false, private: false, access: { has: obj => 'Value 2' in obj, get: obj => obj['Value 2'], set: (obj, value) => { obj['Value 2'] = value; } }, metadata: _metadata }, _member_initializers, _member_extraInitializers);
|
|
221
|
+
__esDecorate(this, null, _member_decorators_1, { kind: "accessor", name: _a, static: false, private: false, access: { has: obj => _a in obj, get: obj => obj[_a], set: (obj, value) => { obj[_a] = value; } }, metadata: _metadata }, _member_initializers_1, _member_extraInitializers_1);
|
|
222
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
223
|
+
MyElement = _classThis = _classDescriptor.value;
|
|
224
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
225
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
226
|
+
}
|
|
227
|
+
#Value1_accessor_storage = __runInitializers(this, _Value1_initializers, 'hello');
|
|
228
|
+
get Value1() { return this.#Value1_accessor_storage; }
|
|
229
|
+
set Value1(value) { this.#Value1_accessor_storage = value; }
|
|
230
|
+
#_a_accessor_storage = (__runInitializers(this, _Value1_extraInitializers), __runInitializers(this, _member_initializers, 0));
|
|
231
|
+
get ['Value 2']() { return this.#_a_accessor_storage; }
|
|
232
|
+
set ['Value 2'](value) { this.#_a_accessor_storage = value; }
|
|
233
|
+
#_b_accessor_storage = (__runInitializers(this, _member_extraInitializers), __runInitializers(this, _member_initializers_1, true));
|
|
234
|
+
get [(_Value1_decorators = [attr()], _member_decorators = [attr()], _member_decorators_1 = [attr()], _a = __propKey(value3))]() { return this.#_b_accessor_storage; }
|
|
235
|
+
set [_a](value) { this.#_b_accessor_storage = value; }
|
|
236
|
+
constructor() {
|
|
237
|
+
super(...arguments);
|
|
238
|
+
__runInitializers(this, _member_extraInitializers_1);
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
return MyElement = _classThis;
|
|
242
|
+
})();
|
|
243
|
+
const el = new MyElement();
|
|
244
|
+
document.body.append(el);
|
|
245
|
+
expect([...el.attributes].map((attr) => attr.name)).to.deep.equal([
|
|
246
|
+
'value1',
|
|
247
|
+
'value-2',
|
|
248
|
+
'value-from-symbol'
|
|
249
|
+
]);
|
|
250
|
+
el.remove();
|
|
251
|
+
});
|
|
252
|
+
it('should throw an error for symbols with no description', async () => {
|
|
253
|
+
expect(() => {
|
|
254
|
+
const value = Symbol();
|
|
192
255
|
let MyElement = (() => {
|
|
193
256
|
var _a;
|
|
194
257
|
let _classDecorators = [element({
|
|
@@ -198,87 +261,146 @@ describe('@attr()', () => {
|
|
|
198
261
|
let _classExtraInitializers = [];
|
|
199
262
|
let _classThis;
|
|
200
263
|
let _classSuper = HTMLElement;
|
|
201
|
-
let _Value1_decorators;
|
|
202
|
-
let _Value1_initializers = [];
|
|
203
|
-
let _Value1_extraInitializers = [];
|
|
204
264
|
let _member_decorators;
|
|
205
265
|
let _member_initializers = [];
|
|
206
266
|
let _member_extraInitializers = [];
|
|
207
|
-
let _member_decorators_1;
|
|
208
|
-
let _member_initializers_1 = [];
|
|
209
|
-
let _member_extraInitializers_1 = [];
|
|
210
267
|
var MyElement = class extends _classSuper {
|
|
211
268
|
static { _classThis = this; }
|
|
212
269
|
static {
|
|
213
270
|
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
214
|
-
__esDecorate(this, null,
|
|
215
|
-
__esDecorate(this, null, _member_decorators, { kind: "accessor", name: 'Value 2', static: false, private: false, access: { has: obj => 'Value 2' in obj, get: obj => obj['Value 2'], set: (obj, value) => { obj['Value 2'] = value; } }, metadata: _metadata }, _member_initializers, _member_extraInitializers);
|
|
216
|
-
__esDecorate(this, null, _member_decorators_1, { kind: "accessor", name: _a, static: false, private: false, access: { has: obj => _a in obj, get: obj => obj[_a], set: (obj, value) => { obj[_a] = value; } }, metadata: _metadata }, _member_initializers_1, _member_extraInitializers_1);
|
|
271
|
+
__esDecorate(this, null, _member_decorators, { kind: "accessor", name: _a, static: false, private: false, access: { has: obj => _a in obj, get: obj => obj[_a], set: (obj, value) => { obj[_a] = value; } }, metadata: _metadata }, _member_initializers, _member_extraInitializers);
|
|
217
272
|
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
218
273
|
MyElement = _classThis = _classDescriptor.value;
|
|
219
274
|
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
220
275
|
__runInitializers(_classThis, _classExtraInitializers);
|
|
221
276
|
}
|
|
222
|
-
#
|
|
223
|
-
get
|
|
224
|
-
set
|
|
225
|
-
#_a_accessor_storage = (__runInitializers(this, _Value1_extraInitializers), __runInitializers(this, _member_initializers, 0));
|
|
226
|
-
get ['Value 2']() { return this.#_a_accessor_storage; }
|
|
227
|
-
set ['Value 2'](value) { this.#_a_accessor_storage = value; }
|
|
228
|
-
#_b_accessor_storage = (__runInitializers(this, _member_extraInitializers), __runInitializers(this, _member_initializers_1, true));
|
|
229
|
-
get [(_Value1_decorators = [attr()], _member_decorators = [attr()], _member_decorators_1 = [attr()], _a = __propKey(value3))]() { return this.#_b_accessor_storage; }
|
|
230
|
-
set [_a](value) { this.#_b_accessor_storage = value; }
|
|
277
|
+
#_a_accessor_storage = __runInitializers(this, _member_initializers, true);
|
|
278
|
+
get [(_member_decorators = [attr()], _a = __propKey(value))]() { return this.#_a_accessor_storage; }
|
|
279
|
+
set [_a](value) { this.#_a_accessor_storage = value; }
|
|
231
280
|
constructor() {
|
|
232
281
|
super(...arguments);
|
|
233
|
-
__runInitializers(this,
|
|
282
|
+
__runInitializers(this, _member_extraInitializers);
|
|
234
283
|
}
|
|
235
284
|
};
|
|
236
285
|
return MyElement = _classThis;
|
|
237
286
|
})();
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
287
|
+
new MyElement();
|
|
288
|
+
}).to.throw('Cannot handle Symbol property without description');
|
|
289
|
+
});
|
|
290
|
+
it('should not reflect property to attribute', async () => {
|
|
291
|
+
let MyElement = (() => {
|
|
292
|
+
let _classDecorators = [element({
|
|
293
|
+
tagName: 'attr-test-5'
|
|
294
|
+
})];
|
|
295
|
+
let _classDescriptor;
|
|
296
|
+
let _classExtraInitializers = [];
|
|
297
|
+
let _classThis;
|
|
298
|
+
let _classSuper = HTMLElement;
|
|
299
|
+
let _value_decorators;
|
|
300
|
+
let _value_initializers = [];
|
|
301
|
+
let _value_extraInitializers = [];
|
|
302
|
+
var MyElement = class extends _classSuper {
|
|
303
|
+
static { _classThis = this; }
|
|
304
|
+
static {
|
|
305
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
306
|
+
_value_decorators = [attr({ reflect: false })];
|
|
307
|
+
__esDecorate(this, null, _value_decorators, { kind: "accessor", name: "value", static: false, private: false, access: { has: obj => "value" in obj, get: obj => obj.value, set: (obj, value) => { obj.value = value; } }, metadata: _metadata }, _value_initializers, _value_extraInitializers);
|
|
308
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
309
|
+
MyElement = _classThis = _classDescriptor.value;
|
|
310
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
311
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
312
|
+
}
|
|
313
|
+
#value_accessor_storage = __runInitializers(this, _value_initializers, 'foo');
|
|
314
|
+
get value() { return this.#value_accessor_storage; }
|
|
315
|
+
set value(value) { this.#value_accessor_storage = value; }
|
|
316
|
+
constructor() {
|
|
317
|
+
super(...arguments);
|
|
318
|
+
__runInitializers(this, _value_extraInitializers);
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
return MyElement = _classThis;
|
|
322
|
+
})();
|
|
323
|
+
const el = new MyElement();
|
|
324
|
+
el.value = 'bar';
|
|
325
|
+
expect(el.value).to.equal('bar');
|
|
326
|
+
expect(el.hasAttribute('value')).to.be.false;
|
|
327
|
+
});
|
|
328
|
+
it('non reflective attributes should still read new attribute values', async () => {
|
|
329
|
+
let MyElement = (() => {
|
|
330
|
+
let _classDecorators = [element({
|
|
331
|
+
tagName: 'attr-test-6'
|
|
332
|
+
})];
|
|
333
|
+
let _classDescriptor;
|
|
334
|
+
let _classExtraInitializers = [];
|
|
335
|
+
let _classThis;
|
|
336
|
+
let _classSuper = HTMLElement;
|
|
337
|
+
let _value_decorators;
|
|
338
|
+
let _value_initializers = [];
|
|
339
|
+
let _value_extraInitializers = [];
|
|
340
|
+
var MyElement = class extends _classSuper {
|
|
341
|
+
static { _classThis = this; }
|
|
342
|
+
static {
|
|
343
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
344
|
+
_value_decorators = [attr({ reflect: false })];
|
|
345
|
+
__esDecorate(this, null, _value_decorators, { kind: "accessor", name: "value", static: false, private: false, access: { has: obj => "value" in obj, get: obj => obj.value, set: (obj, value) => { obj.value = value; } }, metadata: _metadata }, _value_initializers, _value_extraInitializers);
|
|
346
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
347
|
+
MyElement = _classThis = _classDescriptor.value;
|
|
348
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
349
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
350
|
+
}
|
|
351
|
+
#value_accessor_storage = __runInitializers(this, _value_initializers, 'foo');
|
|
352
|
+
get value() { return this.#value_accessor_storage; }
|
|
353
|
+
set value(value) { this.#value_accessor_storage = value; }
|
|
354
|
+
constructor() {
|
|
355
|
+
super(...arguments);
|
|
356
|
+
__runInitializers(this, _value_extraInitializers);
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
return MyElement = _classThis;
|
|
360
|
+
})();
|
|
361
|
+
const el = new MyElement();
|
|
362
|
+
el.setAttribute('value', 'bar');
|
|
363
|
+
expect(el.value).to.equal('bar');
|
|
364
|
+
});
|
|
365
|
+
it('should allow a manually defined attribute name', async () => {
|
|
366
|
+
let MyElement = (() => {
|
|
367
|
+
let _classDecorators = [element({
|
|
368
|
+
tagName: 'attr-test-7'
|
|
369
|
+
})];
|
|
370
|
+
let _classDescriptor;
|
|
371
|
+
let _classExtraInitializers = [];
|
|
372
|
+
let _classThis;
|
|
373
|
+
let _classSuper = HTMLElement;
|
|
374
|
+
let _value_decorators;
|
|
375
|
+
let _value_initializers = [];
|
|
376
|
+
let _value_extraInitializers = [];
|
|
377
|
+
var MyElement = class extends _classSuper {
|
|
378
|
+
static { _classThis = this; }
|
|
379
|
+
static {
|
|
380
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
381
|
+
_value_decorators = [attr({
|
|
382
|
+
name: 'aria-label'
|
|
252
383
|
})];
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
super(...arguments);
|
|
275
|
-
__runInitializers(this, _member_extraInitializers);
|
|
276
|
-
}
|
|
277
|
-
};
|
|
278
|
-
return MyElement = _classThis;
|
|
279
|
-
})();
|
|
280
|
-
new MyElement();
|
|
281
|
-
}).to.throw('Cannot handle Symbol property without description');
|
|
282
|
-
});
|
|
384
|
+
__esDecorate(this, null, _value_decorators, { kind: "accessor", name: "value", static: false, private: false, access: { has: obj => "value" in obj, get: obj => obj.value, set: (obj, value) => { obj.value = value; } }, metadata: _metadata }, _value_initializers, _value_extraInitializers);
|
|
385
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
386
|
+
MyElement = _classThis = _classDescriptor.value;
|
|
387
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
388
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
389
|
+
}
|
|
390
|
+
#value_accessor_storage = __runInitializers(this, _value_initializers, '');
|
|
391
|
+
get value() { return this.#value_accessor_storage; }
|
|
392
|
+
set value(value) { this.#value_accessor_storage = value; }
|
|
393
|
+
constructor() {
|
|
394
|
+
super(...arguments);
|
|
395
|
+
__runInitializers(this, _value_extraInitializers);
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
return MyElement = _classThis;
|
|
399
|
+
})();
|
|
400
|
+
const el = new MyElement();
|
|
401
|
+
el.setAttribute('aria-label', 'TEST');
|
|
402
|
+
document.body.append(el);
|
|
403
|
+
expect(el.value).to.equal('TEST');
|
|
404
|
+
el.remove();
|
|
283
405
|
});
|
|
284
406
|
//# sourceMappingURL=attr.test.js.map
|