@dooboostore/simple-web-component 1.0.25 → 1.0.27
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 +284 -68
- package/dist/cjs/decorators/attribute.js +32 -43
- package/dist/cjs/decorators/attribute.js.map +3 -3
- package/dist/cjs/decorators/elementDefine.js +33 -19
- package/dist/cjs/decorators/elementDefine.js.map +2 -2
- package/dist/cjs/decorators/index.js +1 -0
- package/dist/cjs/decorators/index.js.map +2 -2
- package/dist/cjs/decorators/lifecycles.js +5 -5
- package/dist/cjs/decorators/lifecycles.js.map +2 -2
- package/dist/cjs/decorators/query.js +4 -4
- package/dist/cjs/decorators/query.js.map +2 -2
- package/dist/cjs/decorators/queryAll.js +4 -4
- package/dist/cjs/decorators/queryAll.js.map +2 -2
- package/dist/cjs/decorators/subscribeSwcAppRouteChange.js +59 -0
- package/dist/cjs/decorators/subscribeSwcAppRouteChange.js.map +7 -0
- package/dist/cjs/elements/SwcAppEngine.js +18 -63
- package/dist/cjs/elements/SwcAppEngine.js.map +3 -3
- package/dist/cjs/elements/SwcAppMixin.js +103 -24
- package/dist/cjs/elements/SwcAppMixin.js.map +2 -2
- package/dist/cjs/elements/register.js +0 -1
- package/dist/cjs/elements/register.js.map +2 -2
- package/dist/cjs/utils/Utils.js +18 -0
- package/dist/cjs/utils/Utils.js.map +3 -3
- package/dist/esm/decorators/attribute.js +32 -43
- package/dist/esm/decorators/attribute.js.map +3 -3
- package/dist/esm/decorators/elementDefine.js +34 -20
- package/dist/esm/decorators/elementDefine.js.map +2 -2
- package/dist/esm/decorators/index.js +1 -0
- package/dist/esm/decorators/index.js.map +2 -2
- package/dist/esm/decorators/lifecycles.js +5 -5
- package/dist/esm/decorators/lifecycles.js.map +2 -2
- package/dist/esm/decorators/query.js +4 -4
- package/dist/esm/decorators/query.js.map +2 -2
- package/dist/esm/decorators/queryAll.js +4 -4
- package/dist/esm/decorators/queryAll.js.map +2 -2
- package/dist/esm/decorators/subscribeSwcAppRouteChange.js +40 -0
- package/dist/esm/decorators/subscribeSwcAppRouteChange.js.map +7 -0
- package/dist/esm/elements/SwcAppEngine.js +18 -63
- package/dist/esm/elements/SwcAppEngine.js.map +2 -2
- package/dist/esm/elements/SwcAppMixin.js +103 -24
- package/dist/esm/elements/SwcAppMixin.js.map +2 -2
- package/dist/esm/elements/register.js +0 -1
- package/dist/esm/elements/register.js.map +2 -2
- package/dist/esm/utils/Utils.js +18 -0
- package/dist/esm/utils/Utils.js.map +3 -3
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +135 -2470
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
- package/dist/types/decorators/attribute.d.ts +0 -1
- package/dist/types/decorators/attribute.d.ts.map +1 -1
- package/dist/types/decorators/elementDefine.d.ts.map +1 -1
- package/dist/types/decorators/index.d.ts +1 -0
- package/dist/types/decorators/index.d.ts.map +1 -1
- package/dist/types/decorators/lifecycles.d.ts +2 -2
- package/dist/types/decorators/lifecycles.d.ts.map +1 -1
- package/dist/types/decorators/query.d.ts +1 -1
- package/dist/types/decorators/query.d.ts.map +1 -1
- package/dist/types/decorators/queryAll.d.ts +1 -1
- package/dist/types/decorators/queryAll.d.ts.map +1 -1
- package/dist/types/decorators/subscribeSwcAppRouteChange.d.ts +18 -0
- package/dist/types/decorators/subscribeSwcAppRouteChange.d.ts.map +1 -0
- package/dist/types/elements/SwcAppEngine.d.ts +3 -5
- package/dist/types/elements/SwcAppEngine.d.ts.map +1 -1
- package/dist/types/elements/SwcAppMixin.d.ts +9 -0
- package/dist/types/elements/SwcAppMixin.d.ts.map +1 -1
- package/dist/types/elements/register.d.ts +1 -1
- package/dist/types/elements/register.d.ts.map +1 -1
- package/dist/types/utils/Utils.d.ts +3 -0
- package/dist/types/utils/Utils.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +135 -2470
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +3 -3
- package/src/decorators/attribute.ts +62 -53
- package/src/decorators/elementDefine.ts +79 -30
- package/src/decorators/index.ts +1 -0
- package/src/decorators/lifecycles.ts +2 -2
- package/src/decorators/query.ts +5 -5
- package/src/decorators/queryAll.ts +8 -7
- package/src/decorators/subscribeSwcAppRouteChange.ts +71 -0
- package/src/elements/SwcAppEngine.ts +25 -81
- package/src/elements/SwcAppMixin.ts +143 -28
- package/src/elements/register.ts +0 -2
- package/src/utils/Utils.ts +33 -0
package/README.md
CHANGED
|
@@ -3,112 +3,328 @@
|
|
|
3
3
|
[](https://github.com/dooboostore-develop/packages/actions/workflows/main.yaml)
|
|
4
4
|
[](https://opensource.org/licenses/MIT)
|
|
5
5
|
|
|
6
|
-
> **"Pure, Standards-Compliant, and Blazing Fast Web Components Framework."**
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
**SWC** is a lightweight, production-ready Web Components framework for building fast, modular, and maintainable SPAs without Virtual DOM overhead.
|
|
9
8
|
|
|
10
9
|
---
|
|
11
10
|
|
|
12
|
-
##
|
|
11
|
+
## 🎯 Core Features
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
- **Extreme Performance**: Optimized for high-load UIs with minimal memory footprint.
|
|
17
|
-
- **Micro-Frontend Ready**: Independent routing and DI containers for every component scope.
|
|
18
|
-
- **Modern CSS**: First-class support for Container Queries and Shadow DOM.
|
|
13
|
+
### 1. **@elementDefine** - Component Registration
|
|
14
|
+
Register Web Components with automatic lifecycle management and DI support.
|
|
19
15
|
|
|
20
|
-
|
|
16
|
+
```typescript
|
|
17
|
+
@elementDefine('my-component')
|
|
18
|
+
class MyComponent extends HTMLElement {
|
|
19
|
+
@onInitialize
|
|
20
|
+
constructor(private service: MyService) {
|
|
21
|
+
super();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
```
|
|
21
25
|
|
|
22
|
-
|
|
26
|
+
### 2. **Dependency Injection (@onInitialize)**
|
|
27
|
+
Inject services into Web Components using the `@onInitialize` decorator.
|
|
23
28
|
|
|
24
|
-
|
|
29
|
+
```typescript
|
|
30
|
+
@elementDefine('dashboard')
|
|
31
|
+
class Dashboard extends HTMLElement {
|
|
32
|
+
@onInitialize
|
|
33
|
+
constructor(
|
|
34
|
+
@Inject({ symbol: UserService.SYMBOL }) userService: UserService
|
|
35
|
+
) {
|
|
36
|
+
super();
|
|
37
|
+
this.userService = userService;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
```
|
|
25
41
|
|
|
26
|
-
|
|
42
|
+
### 3. **Declarative DOM Updates**
|
|
27
43
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
- **Method Decorators**:
|
|
31
|
-
- `@applyAttribute(selector, action?)`: Universal attribute controller.
|
|
32
|
-
- `@setAttribute(selector, name?)`: Sets a specific attribute based on return value.
|
|
33
|
-
- `@updateAttribute(selector)`: Merges/updates multiple attributes.
|
|
34
|
-
- `@removeAttribute(selector)`: Removes attributes.
|
|
44
|
+
#### @onConnectedInnerHtml
|
|
45
|
+
Render HTML automatically when component connects to DOM.
|
|
35
46
|
|
|
36
47
|
```typescript
|
|
37
|
-
|
|
38
|
-
|
|
48
|
+
@onConnectedInnerHtml({ useShadow: true })
|
|
49
|
+
render() {
|
|
50
|
+
return `<div>Hello, <span>${this.name}</span>!</div>`;
|
|
51
|
+
}
|
|
52
|
+
```
|
|
39
53
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
54
|
+
#### @applyInnerHtmlNodeHost
|
|
55
|
+
Apply HTML to specific host element.
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
@applyInnerHtmlNodeHost({ root: 'light' })
|
|
59
|
+
updateContent() {
|
|
60
|
+
return `<p>Updated content</p>`;
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
#### @applyReplaceChildrenNodeHost
|
|
65
|
+
Replace child nodes with new content.
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
@applyReplaceChildrenNodeHost({ root: 'light' })
|
|
69
|
+
replaceChildren(node: Node) {
|
|
70
|
+
return node;
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### 4. **Event Handling**
|
|
75
|
+
|
|
76
|
+
#### @addEventListener
|
|
77
|
+
Attach event listeners to elements.
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
@addEventListener('#submit-btn', 'click')
|
|
81
|
+
onSubmit(event: Event) {
|
|
82
|
+
console.log('Submitted');
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
#### @emitCustomEvent
|
|
87
|
+
Emit custom events with data.
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
@emitCustomEvent(':appHost', 'user-login')
|
|
91
|
+
async onLogin() {
|
|
92
|
+
const user = await this.authService.login();
|
|
93
|
+
return { user }; // Sent as event detail
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
#### @emitCustomEventHost
|
|
98
|
+
Emit events from a method with custom event name mapping.
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
@emitCustomEventHost('navigate', { attributeName: 'on-navigate' })
|
|
102
|
+
onNavClick(e: any) {
|
|
103
|
+
return { path: e.target.dataset.path };
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### 5. **DOM Querying**
|
|
108
|
+
|
|
109
|
+
#### @query
|
|
110
|
+
Query single element (Light DOM by default).
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
@query('#form-input')
|
|
114
|
+
formInput?: HTMLInputElement;
|
|
115
|
+
|
|
116
|
+
@query('.card', { root: 'shadow' })
|
|
117
|
+
shadowCard?: HTMLElement;
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
#### @queryAll
|
|
121
|
+
Query multiple elements.
|
|
122
|
+
|
|
123
|
+
```typescript
|
|
124
|
+
@queryAll('input[type="text"]')
|
|
125
|
+
textInputs?: HTMLInputElement[];
|
|
126
|
+
|
|
127
|
+
@queryAll('li', { root: 'shadow' })
|
|
128
|
+
listItems?: HTMLLIElement[];
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
#### @queryHost
|
|
132
|
+
Query the component element itself.
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
@queryHost
|
|
136
|
+
self?: HTMLElement;
|
|
137
|
+
|
|
138
|
+
printTag() {
|
|
139
|
+
console.log(this.self?.tagName); // CUSTOM-CARD
|
|
47
140
|
}
|
|
48
141
|
```
|
|
49
142
|
|
|
50
|
-
|
|
143
|
+
#### @queryAllHost
|
|
144
|
+
Query all direct children of the component.
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
@queryAllHost
|
|
148
|
+
children?: HTMLElement[];
|
|
149
|
+
|
|
150
|
+
getChildCount() {
|
|
151
|
+
return this.children?.length ?? 0;
|
|
152
|
+
}
|
|
153
|
+
```
|
|
51
154
|
|
|
52
|
-
|
|
155
|
+
### 6. **Attribute Binding**
|
|
53
156
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
- `@updateClass(selector)`: Updates specific classes (Merge Strategy).
|
|
57
|
-
- `@toggleClass(selector)`: Toggles classes.
|
|
157
|
+
#### @attribute
|
|
158
|
+
Bind HTML attributes to properties (automatic sync).
|
|
58
159
|
|
|
59
160
|
```typescript
|
|
60
|
-
@
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
161
|
+
@attribute
|
|
162
|
+
width: string = '100px';
|
|
163
|
+
|
|
164
|
+
@attribute('data-id')
|
|
165
|
+
resourceId: string = '';
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
#### @attributeHost
|
|
169
|
+
Bind attributes on host element itself.
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
@attributeHost('product-id')
|
|
173
|
+
productId: string = '';
|
|
174
|
+
|
|
175
|
+
@onInitialize
|
|
176
|
+
constructor() {
|
|
177
|
+
super();
|
|
178
|
+
if (this.productId) {
|
|
179
|
+
this.loadProduct(this.productId);
|
|
180
|
+
}
|
|
66
181
|
}
|
|
67
182
|
```
|
|
68
183
|
|
|
69
|
-
###
|
|
184
|
+
### 7. **Lifecycle Hooks**
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
@onConnected
|
|
188
|
+
onConnected() {
|
|
189
|
+
// Called when element enters DOM
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
@onDisconnected
|
|
193
|
+
onDisconnected() {
|
|
194
|
+
// Called when element leaves DOM
|
|
195
|
+
}
|
|
70
196
|
|
|
71
|
-
|
|
197
|
+
@onAttributeChanged
|
|
198
|
+
onAttributeChanged(name: string, oldValue: string, newValue: string) {
|
|
199
|
+
// Called when attribute changes
|
|
200
|
+
}
|
|
201
|
+
```
|
|
72
202
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
- `@updateStyle(selector)`: Merges with existing styles.
|
|
76
|
-
- `@removeStyle(selector)`: Removes specific properties.
|
|
203
|
+
### 8. **Routing with @subscribeSwcAppRouteChange**
|
|
204
|
+
Declarative route pattern matching with path parameters.
|
|
77
205
|
|
|
78
206
|
```typescript
|
|
79
|
-
@
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
207
|
+
@elementDefine('root-router')
|
|
208
|
+
class RootRouter extends HTMLElement {
|
|
209
|
+
@subscribeSwcAppRouteChange('/')
|
|
210
|
+
@applyInnerHtmlNodeHost({ root: 'light' })
|
|
211
|
+
homeRoute(router: RouterEventType) {
|
|
212
|
+
return `<home-page/>`;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
@subscribeSwcAppRouteChange('/product/{id}')
|
|
216
|
+
@applyInnerHtmlNodeHost({ root: 'light' })
|
|
217
|
+
productRoute(router: RouterEventType, pathData: any) {
|
|
218
|
+
return `<product-page product-id="${pathData.id}"/>`;
|
|
219
|
+
}
|
|
85
220
|
}
|
|
86
221
|
```
|
|
87
222
|
|
|
88
|
-
###
|
|
223
|
+
### 9. **Accommodation Pattern**
|
|
224
|
+
Factory-based component registration with explicit DI.
|
|
89
225
|
|
|
90
|
-
|
|
226
|
+
```typescript
|
|
227
|
+
// Component factory
|
|
228
|
+
export default (w: Window) => {
|
|
229
|
+
const tagName = 'my-component';
|
|
230
|
+
const existing = w.customElements.get(tagName);
|
|
231
|
+
if (existing) return tagName;
|
|
91
232
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
233
|
+
@elementDefine(tagName, { window: w })
|
|
234
|
+
class MyComponent extends w.HTMLElement {
|
|
235
|
+
@onInitialize
|
|
236
|
+
constructor(service: MyService) {
|
|
237
|
+
super();
|
|
238
|
+
this.service = service;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return tagName;
|
|
243
|
+
};
|
|
96
244
|
|
|
97
|
-
|
|
245
|
+
// Boot factory
|
|
246
|
+
export default (w: Window, container: symbol) => {
|
|
247
|
+
serviceFactories.forEach(s => s(container));
|
|
248
|
+
register(w, [...pageFactories, ...componentFactories]);
|
|
249
|
+
};
|
|
98
250
|
|
|
99
|
-
|
|
100
|
-
|
|
251
|
+
// Entry point
|
|
252
|
+
const container = Symbol('app');
|
|
253
|
+
bootFactory(w, container);
|
|
254
|
+
appElement.connect({
|
|
255
|
+
container,
|
|
256
|
+
window: w,
|
|
257
|
+
onEngineStarted: () => {
|
|
258
|
+
appElement.innerHTML = '<root-router></root-router>';
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
```
|
|
101
262
|
|
|
102
263
|
---
|
|
103
264
|
|
|
104
|
-
##
|
|
265
|
+
## ⚠️ Critical Rules
|
|
266
|
+
|
|
267
|
+
### DO NOT Use @Sim on Web Components
|
|
268
|
+
`@Sim` is for **Services only**. Web Components should use `@elementDefine`.
|
|
269
|
+
|
|
270
|
+
```typescript
|
|
271
|
+
// ✅ CORRECT
|
|
272
|
+
@Sim()
|
|
273
|
+
export class UserService { }
|
|
274
|
+
|
|
275
|
+
@elementDefine(tagName, { window: w })
|
|
276
|
+
class UserWidget extends w.HTMLElement { }
|
|
105
277
|
|
|
106
|
-
|
|
107
|
-
|
|
278
|
+
// ❌ WRONG
|
|
279
|
+
@Sim()
|
|
280
|
+
@elementDefine(tagName, { window: w })
|
|
281
|
+
class UserWidget extends w.HTMLElement { }
|
|
108
282
|
```
|
|
109
283
|
|
|
110
|
-
###
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
284
|
+
### Factory Always Returns tagName (String)
|
|
285
|
+
```typescript
|
|
286
|
+
export default (w: Window) => {
|
|
287
|
+
const tagName = 'my-element';
|
|
288
|
+
const existing = w.customElements.get(tagName);
|
|
289
|
+
if (existing) return tagName; // ← Return string!
|
|
290
|
+
|
|
291
|
+
@elementDefine(tagName, { window: w })
|
|
292
|
+
class MyElement extends w.HTMLElement { }
|
|
293
|
+
|
|
294
|
+
return tagName; // ← Always return tagName, never class
|
|
295
|
+
};
|
|
114
296
|
```
|
|
297
|
+
|
|
298
|
+
### @onInitialize for DI (Not Constructor Parameters)
|
|
299
|
+
```typescript
|
|
300
|
+
// ✅ CORRECT
|
|
301
|
+
@onInitialize
|
|
302
|
+
constructor(@Inject({ symbol: Service.SYMBOL }) service: Service) {
|
|
303
|
+
super();
|
|
304
|
+
this.service = service;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// ❌ WRONG
|
|
308
|
+
constructor(private service: Service) { super(); } // Web Components can't have constructor parameters!
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
---
|
|
312
|
+
|
|
313
|
+
## 📚 Examples
|
|
314
|
+
|
|
315
|
+
- **[Commerce (E-Commerce SPA)](./examples/commerce)** - Full shopping cart example
|
|
316
|
+
- **[Stock (Market Dashboard)](./examples/stock)** - Real-time data with routing
|
|
317
|
+
- **[Accommodation (Reference Pattern)](./examples/accommodation)** - Standard setup pattern
|
|
318
|
+
|
|
319
|
+
---
|
|
320
|
+
|
|
321
|
+
## 🔗 Related Packages
|
|
322
|
+
|
|
323
|
+
- **[@dooboostore/simple-boot](../simple-boot)** - DI & AOP Container
|
|
324
|
+
- **[@dooboostore/core-web](../core-web)** - Web Utilities & Router
|
|
325
|
+
- **[@dooboostore/dom-parser](../dom-parser)** - HTML Parsing & AST
|
|
326
|
+
|
|
327
|
+
---
|
|
328
|
+
|
|
329
|
+
## 📄 License
|
|
330
|
+
MIT © 2024 dooboostore-develop
|
|
@@ -104,49 +104,37 @@ function attribute(selector, options = {}) {
|
|
|
104
104
|
}
|
|
105
105
|
});
|
|
106
106
|
};
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
return
|
|
122
|
-
}
|
|
123
|
-
return null;
|
|
124
|
-
}
|
|
125
|
-
return convertValue(this[privateKey], targetType);
|
|
126
|
-
},
|
|
127
|
-
set(nv) {
|
|
128
|
-
const attrName = options.name || String(propertyKey);
|
|
129
|
-
const conf = (0, import_elementDefine.getElementConfig)(this);
|
|
130
|
-
const currentWin = this._resolveWindow?.(conf) || (typeof window !== "undefined" ? window : void 0);
|
|
131
|
-
if (this.__swc_syncing_init) {
|
|
132
|
-
if (options.connectedInitialize === true) {
|
|
133
|
-
const targets2 = resolveTargetEls(this, selector, options, currentWin);
|
|
134
|
-
applySetAttribute(this, targets2, attrName, nv);
|
|
135
|
-
} else {
|
|
136
|
-
this[privateKey] = nv;
|
|
107
|
+
try {
|
|
108
|
+
Object.defineProperty(target, propertyKey, {
|
|
109
|
+
get() {
|
|
110
|
+
const attrName = options.name || String(propertyKey);
|
|
111
|
+
const conf = (0, import_elementDefine.getElementConfig)(this);
|
|
112
|
+
const currentWin = this._resolveWindow?.(conf) || (typeof window !== "undefined" ? window : void 0);
|
|
113
|
+
const targetType = options.type || designType;
|
|
114
|
+
const targets = resolveTargetEls(this, selector, options, currentWin);
|
|
115
|
+
const primaryTarget = targets[0];
|
|
116
|
+
if (primaryTarget && typeof primaryTarget.hasAttribute === "function") {
|
|
117
|
+
if (primaryTarget.hasAttribute(attrName)) {
|
|
118
|
+
const domVal = primaryTarget.getAttribute(attrName);
|
|
119
|
+
return convertValue(domVal, targetType);
|
|
120
|
+
}
|
|
121
|
+
return null;
|
|
137
122
|
}
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
123
|
+
return convertValue(this[privateKey], targetType);
|
|
124
|
+
},
|
|
125
|
+
set(nv) {
|
|
126
|
+
const attrName = options.name || String(propertyKey);
|
|
127
|
+
const conf = (0, import_elementDefine.getElementConfig)(this);
|
|
128
|
+
const currentWin = this._resolveWindow?.(conf) || (typeof window !== "undefined" ? window : void 0);
|
|
129
|
+
const targets = resolveTargetEls(this, selector, options, currentWin);
|
|
130
|
+
applySetAttribute(this, targets, attrName, nv);
|
|
131
|
+
},
|
|
132
|
+
enumerable: true,
|
|
133
|
+
configurable: true
|
|
134
|
+
});
|
|
135
|
+
} catch (err) {
|
|
136
|
+
console.error("[SWC] defineProperty error:", err);
|
|
137
|
+
}
|
|
150
138
|
};
|
|
151
139
|
}
|
|
152
140
|
function attributeHost(targetOrAttrOrOptions, propertyKeyOrOptions) {
|
|
@@ -169,6 +157,7 @@ function attributeHost(targetOrAttrOrOptions, propertyKeyOrOptions) {
|
|
|
169
157
|
}
|
|
170
158
|
}
|
|
171
159
|
const findAllAttributeMetadata = (target) => {
|
|
172
|
-
|
|
160
|
+
const actualTarget = target instanceof Function ? target : target.constructor;
|
|
161
|
+
return import_core.ReflectUtils.findAllMetadata(ATTRIBUTE_FIELD_METADATA_KEY, actualTarget).flat();
|
|
173
162
|
};
|
|
174
163
|
//# sourceMappingURL=attribute.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/decorators/attribute.ts"],
|
|
4
|
-
"sourcesContent": ["import {ReflectUtils} from '@dooboostore/core';\nimport {ensureInit, getElementConfig} from './elementDefine';\nimport {SwcUtils} from '../utils/Utils';\nimport {SpecialSelector, SwcQueryOptions} from '../types';\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA2B;AAC3B,2BAA2C;AAC3C,mBAAuB;
|
|
6
|
-
"names": [
|
|
4
|
+
"sourcesContent": ["import {ReflectUtils} from '@dooboostore/core';\nimport {ensureInit, getElementConfig} from './elementDefine';\nimport {SwcUtils} from '../utils/Utils';\nimport {SpecialSelector, SwcQueryOptions} from '../types';\nexport interface AttributeFieldOptions extends SwcQueryOptions {\n name?: string;\n // connectedInitialize?: boolean;\n type?: typeof Number | typeof Boolean | typeof String;\n}\n\nexport interface AttributeFieldMetadata {\n propertyKey: string | symbol;\n selector: string;\n options: AttributeFieldOptions;\n privateKey: symbol;\n}\n\nexport const ATTRIBUTE_FIELD_METADATA_KEY = Symbol.for('simple-web-component:attribute-field');\n\nconst convertValue = (val: string | null, type: any): any => {\n if (val === null || val === undefined) return val;\n if (type === Number) return Number(val);\n if (type === Boolean) return val === 'false' || val === '0' ? false : true;\n return val;\n};\n\nexport const resolveTargetEls = (inst: any, selector: string, options: AttributeFieldOptions, currentWin: any): HTMLElement[] => {\n const r = options.root || 'auto';\n const results: HTMLElement[] = [];\n\n const applyRoot = (target: any) => {\n if (!target) return;\n if (r === 'auto') {\n results.push(target);\n } else {\n if (r === 'light' || r === 'all') results.push(target);\n if ((r === 'shadow' || r === 'all') && target.shadowRoot) results.push(target.shadowRoot);\n }\n };\n\n if (selector === ':host' || !selector) {\n applyRoot(inst);\n } else if (selector === ':window') {\n results.push(currentWin);\n } else if (selector === ':document') {\n results.push(currentWin.document);\n } else {\n const hostSet = SwcUtils.getHostSet(inst);\n if (selector === ':parentHost') applyRoot(hostSet.$parentHost);\n else if (selector === ':appHost') applyRoot(hostSet.$appHost as any);\n else if (selector === ':firstHost') applyRoot(hostSet.$firstHost);\n else if (selector === ':lastHost') applyRoot(hostSet.$lastHost);\n else if (selector === ':firstAppHost') applyRoot(hostSet.$firstAppHost as any);\n else if (selector === ':lastAppHost') applyRoot(hostSet.$lastAppHost as any);\n else {\n if (r === 'shadow') {\n const found = inst.shadowRoot?.querySelectorAll(selector);\n if (found) results.push(...found);\n } else if (r === 'light') {\n const found = inst.querySelectorAll(selector);\n if (found) results.push(...found);\n } else if (r === 'all') {\n const sMatch = inst.shadowRoot?.querySelectorAll(selector);\n const lMatch = inst.querySelectorAll(selector);\n if (sMatch) results.push(...sMatch);\n if (lMatch) results.push(...lMatch);\n } else {\n const found = (inst.shadowRoot || inst).querySelectorAll(selector);\n if (found) results.push(...found);\n }\n }\n }\n return results;\n};\n\n/**\n * @attribute decorator to sync a field value with an element's attribute.\n */\nexport function attribute(selector: string, options: AttributeFieldOptions = {}): PropertyDecorator {\n return (target: Object, propertyKey: string | symbol) => {\n const constructor = target.constructor;\n const privateKey = Symbol(String(propertyKey));\n //\n const designType = (Reflect as any).getMetadata('design:type', target, propertyKey);\n //\n let metaList = ReflectUtils.getOwnMetadata(ATTRIBUTE_FIELD_METADATA_KEY, constructor) as AttributeFieldMetadata[];\n if (!metaList) {\n metaList = [];\n ReflectUtils.defineMetadata(ATTRIBUTE_FIELD_METADATA_KEY, metaList, constructor);\n }\n metaList.push({propertyKey, selector, options, privateKey});\n\n const applySetAttribute = (inst: any, targets: HTMLElement[], attrName: string, nv: any) => {\n targets.forEach(it => {\n if (it && typeof (it as any).setAttribute === 'function') {\n if (nv === null) {\n (it as any).removeAttribute(attrName);\n } else {\n (it as any).setAttribute(attrName, String(nv));\n }\n } else {\n inst[privateKey] = nv;\n }\n });\n };\n\n try {\n // Own property\uB97C \uC0AD\uC81C\uD558\uC5EC getter\uAC00 \uC791\uB3D9\uD558\uB3C4\uB85D \uD568\n // delete target[propertyKey];\n\n // const defineTarget = target instanceof Function ? target : (target as any).constructor;\n \n Object.defineProperty(target, propertyKey, {\n get(this: any) {\n // try {\n const attrName = options.name || String(propertyKey);\n const conf = getElementConfig(this);\n const currentWin = this._resolveWindow?.(conf) || ((typeof window !== 'undefined' ? window : undefined) as any);\n const targetType = options.type || designType;\n //\n // connectedInitialize: true\uC774\uBA74 privateKey \uAC12\uB9CC \uBC18\uD658 (DOM \uBB34\uC2DC)\n // if (options.connectedInitialize === true && (this as any).__swc_syncing_init) {\n // console.log('cccccccc2');\n // return this[privateKey];\n // // return convertValue(this[privateKey], targetType);\n // }\n\n const targets = resolveTargetEls(this, selector, options, currentWin);\n const primaryTarget = targets[0];\n\n if (primaryTarget && typeof (primaryTarget as any).hasAttribute === 'function') {\n if ((primaryTarget as any).hasAttribute(attrName)) {\n const domVal = (primaryTarget as any).getAttribute(attrName);\n return convertValue(domVal, targetType);\n }\n return null;\n }\n\n return convertValue(this[privateKey], targetType);\n // } catch (err) {\n // console.error('Error in getter:', err);\n // throw err;\n // }\n },\n set(this: any, nv: any) {\n // this[propertyKey] = nv;\n const attrName = options.name || String(propertyKey);\n const conf = getElementConfig(this);\n const currentWin = this._resolveWindow?.(conf) || ((typeof window !== 'undefined' ? window : undefined) as any);\n\n\n // if (!this.__swc_connected) {\n // this[privateKey] = nv;\n // return;\n // }\n\n const targets = resolveTargetEls(this, selector, options, currentWin);\n applySetAttribute(this, targets, attrName, nv);\n },\n enumerable: true,\n configurable: true\n });\n } catch (err) {\n console.error('[SWC] defineProperty error:', err);\n }\n };\n}\n\n/**\n * @attributeHost decorator to sync a field value with the :host element's attribute.\n */\nexport function attributeHost(target: Object, propertyKey: string | symbol): void;\nexport function attributeHost(options: AttributeFieldOptions): PropertyDecorator;\nexport function attributeHost(attrName: string): PropertyDecorator;\nexport function attributeHost(attrName: string, options: AttributeFieldOptions): PropertyDecorator;\nexport function attributeHost(targetOrAttrOrOptions?: any, propertyKeyOrOptions?: any): any {\n if (propertyKeyOrOptions !== undefined && (typeof propertyKeyOrOptions === 'string' || typeof propertyKeyOrOptions === 'symbol')) {\n return attribute(':host', { name: String(propertyKeyOrOptions) })(targetOrAttrOrOptions, propertyKeyOrOptions);\n }\n\n if (typeof targetOrAttrOrOptions === 'string') {\n const attrName = targetOrAttrOrOptions;\n const options = (typeof propertyKeyOrOptions === 'object' ? propertyKeyOrOptions : {}) as AttributeFieldOptions;\n return attribute(':host', { ...options, name: attrName });\n } else if (typeof targetOrAttrOrOptions === 'object') {\n const options = targetOrAttrOrOptions as AttributeFieldOptions;\n return (target: Object, propertyKey: string | symbol) => {\n return attribute(':host', { ...options, name: String(propertyKey) })(target, propertyKey);\n };\n } else {\n return (target: Object, propertyKey: string | symbol) => {\n return attribute(':host', { name: String(propertyKey) })(target, propertyKey);\n };\n }\n}\n\nexport const findAllAttributeMetadata = (target: any): AttributeFieldMetadata[] => {\n const actualTarget = target instanceof Function ? target : target.constructor;\n return ReflectUtils.findAllMetadata<AttributeFieldMetadata[]>(ATTRIBUTE_FIELD_METADATA_KEY, actualTarget).flat();\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA2B;AAC3B,2BAA2C;AAC3C,mBAAuB;AAehB,MAAM,+BAA+B,OAAO,IAAI,sCAAsC;AAE7F,MAAM,eAAe,CAAC,KAAoB,SAAmB;AAC3D,MAAI,QAAQ,QAAQ,QAAQ,OAAW,QAAO;AAC9C,MAAI,SAAS,OAAQ,QAAO,OAAO,GAAG;AACtC,MAAI,SAAS,QAAS,QAAO,QAAQ,WAAW,QAAQ,MAAM,QAAQ;AACtE,SAAO;AACT;AAEO,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U,SAAS,EAAE,GAAG,SAAS,MAAM,OAAO,WAAW,EAAE,CAAC,EAAE,QAAQ,WAAW;AAAA,IAC1F;AAAA,EACF,OAAO;AACL,WAAO,CAAC,QAAgB,gBAAiC;AACvD,aAAO,UAAU,SAAS,EAAE,MAAM,OAAO,WAAW,EAAE,CAAC,EAAE,QAAQ,WAAW;AAAA,IAC9E;AAAA,EACF;AACF;AAEO,MAAM,2BAA2B,CAAC,WAA0C;AACjF,QAAM,eAAe,kBAAkB,WAAW,SAAS,OAAO;AAClE,SAAO,yBAAa,gBAA0C,8BAA8B,YAAY,EAAE,KAAK;AACjH;",
|
|
6
|
+
"names": []
|
|
7
7
|
}
|
|
@@ -31,6 +31,8 @@ var import_emitCustomEvent = require("./emitCustomEvent");
|
|
|
31
31
|
var import_changedAttributeHost = require("./changedAttributeHost");
|
|
32
32
|
var import_applyAttribute = require("./applyAttribute");
|
|
33
33
|
var import_attribute = require("./attribute");
|
|
34
|
+
var import_query = require("./query");
|
|
35
|
+
var import_queryAll = require("./queryAll");
|
|
34
36
|
var import_Utils = require("../utils/Utils");
|
|
35
37
|
var import_config = require("../config/config");
|
|
36
38
|
var import_Inject = require("@dooboostore/simple-boot/decorators/inject/Inject");
|
|
@@ -46,9 +48,26 @@ const ensureInit = (inst) => {
|
|
|
46
48
|
inst._emitHandlers = /* @__PURE__ */ new Map();
|
|
47
49
|
inst._boundListeners = [];
|
|
48
50
|
inst.__swc_initialized = true;
|
|
51
|
+
const target = inst instanceof Function ? inst : inst.constructor;
|
|
52
|
+
const attributeList = (0, import_attribute.findAllAttributeMetadata)(target);
|
|
53
|
+
attributeList.forEach((meta) => {
|
|
54
|
+
delete inst[meta.propertyKey];
|
|
55
|
+
});
|
|
56
|
+
const queryList = (0, import_query.getQueryMetadata)(target);
|
|
57
|
+
if (queryList) {
|
|
58
|
+
queryList.forEach((meta) => {
|
|
59
|
+
delete inst[meta.propertyKey];
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
const queryAllList = (0, import_queryAll.getQueryAllMetadata)(target);
|
|
63
|
+
if (queryAllList) {
|
|
64
|
+
queryAllList.forEach((meta) => {
|
|
65
|
+
delete inst[meta.propertyKey];
|
|
66
|
+
});
|
|
67
|
+
}
|
|
49
68
|
const hostSet = import_Utils.SwcUtils.getHostSet(inst);
|
|
50
69
|
inst._executeSwcScript?.("swc-on-constructor", hostSet);
|
|
51
|
-
const cMethods = (0, import_lifecycles.findAllLifecycleMetadata)(inst, import_lifecycles.
|
|
70
|
+
const cMethods = (0, import_lifecycles.findAllLifecycleMetadata)(inst, import_lifecycles.ON_INITIALIZE_METADATA_KEY);
|
|
52
71
|
if (cMethods) {
|
|
53
72
|
for (const m of cMethods) inst._invokeLifecycleMethod(m, hostSet);
|
|
54
73
|
}
|
|
@@ -215,12 +234,12 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
215
234
|
const swcLifecycleAttributes = ["swc-on-constructor", "swc-on-connected", "swc-on-disconnected", "swc-on-before-connected", "swc-on-after-connected", "swc-on-before-disconnected", "swc-on-after-disconnected", "swc-on-before-adopted", "swc-on-after-adopted", "swc-on-attribute-changed"];
|
|
216
235
|
const swcOnEvents = import_config.DOM_EVENT_NAMES.map((e) => `swc-on-${e}`);
|
|
217
236
|
const attributeApplyNames = Array.from(applyAttributeMap.values()).map((it) => it.options.name).filter(Boolean);
|
|
218
|
-
const
|
|
237
|
+
const hostAttributes = attributeList.filter((it) => it.selector === ":host").map((it) => it.options.name || String(it.propertyKey));
|
|
219
238
|
const mergedObservedAttributes = [.../* @__PURE__ */ new Set([
|
|
220
239
|
...metadata.observedAttributes ?? [],
|
|
221
240
|
...attrChangeMap.keys(),
|
|
222
241
|
...attributeApplyNames,
|
|
223
|
-
...
|
|
242
|
+
...hostAttributes,
|
|
224
243
|
...emitHostCustomEventList.map((it) => it.options.attributeName).filter(Boolean),
|
|
225
244
|
...swcLifecycleAttributes,
|
|
226
245
|
...swcOnEvents
|
|
@@ -231,30 +250,18 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
231
250
|
const originalConnected = proto.connectedCallback;
|
|
232
251
|
proto.connectedCallback = function() {
|
|
233
252
|
ensureInit(this);
|
|
253
|
+
const hostSet = import_Utils.SwcUtils.getHostSet(this);
|
|
254
|
+
const appHost = hostSet.$appHost;
|
|
255
|
+
const conf = getElementConfig(this);
|
|
256
|
+
const currentWin = this._resolveWindow(conf);
|
|
234
257
|
if (connectedInnerHtmlList.some((it) => it.options.useShadow === true) && !this.shadowRoot) {
|
|
235
258
|
this.attachShadow({ mode: "open" });
|
|
236
259
|
}
|
|
237
|
-
const conf = getElementConfig(this);
|
|
238
|
-
const currentWin = this._resolveWindow(conf);
|
|
239
|
-
const hostSet = import_Utils.SwcUtils.getHostSet(this);
|
|
240
260
|
this._executeSwcScript("swc-on-before-connected", hostSet);
|
|
241
261
|
const bMethods = (0, import_lifecycles.findAllLifecycleMetadata)(this, import_lifecycles.ON_BEFORE_CONNECTED_METADATA_KEY);
|
|
242
262
|
if (bMethods) {
|
|
243
263
|
for (const m of bMethods) this._invokeLifecycleMethod(m, hostSet);
|
|
244
264
|
}
|
|
245
|
-
attributeList.forEach((meta) => {
|
|
246
|
-
if (meta.options.connectedInitialize === true) {
|
|
247
|
-
this.__swc_syncing_init = true;
|
|
248
|
-
try {
|
|
249
|
-
const memoryVal = this[meta.privateKey];
|
|
250
|
-
if (memoryVal !== void 0) {
|
|
251
|
-
this[meta.propertyKey] = memoryVal;
|
|
252
|
-
}
|
|
253
|
-
} finally {
|
|
254
|
-
this.__swc_syncing_init = false;
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
});
|
|
258
265
|
if (connectedInnerHtmlList.length > 0) {
|
|
259
266
|
let sContent = "", lContent = "";
|
|
260
267
|
for (const meta of connectedInnerHtmlList) {
|
|
@@ -390,6 +397,9 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
390
397
|
this._executeSwcScript("swc-on-connected", hostSet);
|
|
391
398
|
this._executeSwcScript("swc-on-after-connected", hostSet);
|
|
392
399
|
this.__swc_connected = true;
|
|
400
|
+
if (appHost && typeof appHost._connected === "function") {
|
|
401
|
+
appHost._connected(this);
|
|
402
|
+
}
|
|
393
403
|
};
|
|
394
404
|
const originalDisconnected = proto.disconnectedCallback;
|
|
395
405
|
proto.disconnectedCallback = function() {
|
|
@@ -411,6 +421,10 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
411
421
|
this._executeSwcScript("swc-on-disconnected", hostSet);
|
|
412
422
|
this._executeSwcScript("swc-on-after-disconnected", hostSet);
|
|
413
423
|
this.__swc_connected = false;
|
|
424
|
+
const appHost = hostSet.$appHost;
|
|
425
|
+
if (appHost && typeof appHost._disconnected === "function") {
|
|
426
|
+
appHost._disconnected(this);
|
|
427
|
+
}
|
|
414
428
|
};
|
|
415
429
|
const originalAdopted = proto.adoptedCallback;
|
|
416
430
|
proto.adoptedCallback = function() {
|