@dooboostore/simple-web-component 1.0.34 → 1.0.36
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 +44 -51
- package/dist/cjs/decorators/addEventListener.js +12 -4
- package/dist/cjs/decorators/addEventListener.js.map +2 -2
- package/dist/cjs/decorators/applyAttribute.js +19 -18
- package/dist/cjs/decorators/applyAttribute.js.map +2 -2
- package/dist/cjs/decorators/applyClass.js +23 -22
- package/dist/cjs/decorators/applyClass.js.map +2 -2
- package/dist/cjs/decorators/applyNode.js +22 -17
- package/dist/cjs/decorators/applyNode.js.map +2 -2
- package/dist/cjs/decorators/applyStyle.js +20 -19
- package/dist/cjs/decorators/applyStyle.js.map +2 -2
- package/dist/cjs/decorators/attribute.js +17 -16
- package/dist/cjs/decorators/attribute.js.map +2 -2
- package/dist/cjs/decorators/{changedAttributeHost.js → changedAttributeThis.js} +6 -6
- package/dist/cjs/decorators/changedAttributeThis.js.map +7 -0
- package/dist/cjs/decorators/elementDefine.js +234 -188
- package/dist/cjs/decorators/elementDefine.js.map +2 -2
- package/dist/cjs/decorators/emitCustomEvent.js +24 -16
- package/dist/cjs/decorators/emitCustomEvent.js.map +2 -2
- package/dist/cjs/decorators/index.js +1 -1
- package/dist/cjs/decorators/index.js.map +1 -1
- package/dist/cjs/decorators/lifecycles.js +15 -17
- package/dist/cjs/decorators/lifecycles.js.map +2 -2
- package/dist/cjs/decorators/query.js +38 -60
- package/dist/cjs/decorators/query.js.map +2 -2
- package/dist/cjs/decorators/queryAll.js +31 -63
- package/dist/cjs/decorators/queryAll.js.map +2 -2
- package/dist/cjs/decorators/setProperty.js +13 -12
- package/dist/cjs/decorators/setProperty.js.map +2 -2
- package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js +2 -2
- package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
- package/dist/cjs/elements/SwcAppEngine.js +8 -2
- package/dist/cjs/elements/SwcAppEngine.js.map +2 -2
- package/dist/cjs/elements/SwcAppMixin.js +120 -65
- package/dist/cjs/elements/SwcAppMixin.js.map +2 -2
- package/dist/cjs/elements/SwcAsync.js +31 -21
- package/dist/cjs/elements/SwcAsync.js.map +2 -2
- package/dist/cjs/elements/SwcChoose.js +53 -34
- package/dist/cjs/elements/SwcChoose.js.map +2 -2
- package/dist/cjs/elements/SwcIf.js +54 -32
- package/dist/cjs/elements/SwcIf.js.map +2 -2
- package/dist/cjs/elements/SwcLoop.js +111 -37
- package/dist/cjs/elements/SwcLoop.js.map +2 -2
- package/dist/cjs/elements/register.js +249 -122
- package/dist/cjs/elements/register.js.map +2 -2
- package/dist/cjs/router/ElementRouter.js +4 -2
- package/dist/cjs/router/ElementRouter.js.map +1 -1
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/utils/Utils.js +31 -17
- package/dist/cjs/utils/Utils.js.map +2 -2
- package/dist/esm/decorators/addEventListener.js +12 -4
- package/dist/esm/decorators/addEventListener.js.map +2 -2
- package/dist/esm/decorators/applyAttribute.js +19 -18
- package/dist/esm/decorators/applyAttribute.js.map +2 -2
- package/dist/esm/decorators/applyClass.js +23 -22
- package/dist/esm/decorators/applyClass.js.map +2 -2
- package/dist/esm/decorators/applyNode.js +22 -17
- package/dist/esm/decorators/applyNode.js.map +2 -2
- package/dist/esm/decorators/applyStyle.js +20 -19
- package/dist/esm/decorators/applyStyle.js.map +2 -2
- package/dist/esm/decorators/attribute.js +17 -16
- package/dist/esm/decorators/attribute.js.map +2 -2
- package/dist/esm/decorators/{changedAttributeHost.js → changedAttributeThis.js} +3 -3
- package/dist/esm/decorators/changedAttributeThis.js.map +7 -0
- package/dist/esm/decorators/elementDefine.js +233 -187
- package/dist/esm/decorators/elementDefine.js.map +2 -2
- package/dist/esm/decorators/emitCustomEvent.js +24 -16
- package/dist/esm/decorators/emitCustomEvent.js.map +2 -2
- package/dist/esm/decorators/index.js +1 -1
- package/dist/esm/decorators/index.js.map +1 -1
- package/dist/esm/decorators/lifecycles.js +15 -17
- package/dist/esm/decorators/lifecycles.js.map +2 -2
- package/dist/esm/decorators/query.js +38 -60
- package/dist/esm/decorators/query.js.map +2 -2
- package/dist/esm/decorators/queryAll.js +31 -63
- package/dist/esm/decorators/queryAll.js.map +2 -2
- package/dist/esm/decorators/setProperty.js +13 -12
- package/dist/esm/decorators/setProperty.js.map +2 -2
- package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js +2 -2
- package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
- package/dist/esm/elements/SwcAppEngine.js +9 -2
- package/dist/esm/elements/SwcAppEngine.js.map +2 -2
- package/dist/esm/elements/SwcAppMixin.js +122 -66
- package/dist/esm/elements/SwcAppMixin.js.map +2 -2
- package/dist/esm/elements/SwcAsync.js +32 -22
- package/dist/esm/elements/SwcAsync.js.map +2 -2
- package/dist/esm/elements/SwcChoose.js +54 -35
- package/dist/esm/elements/SwcChoose.js.map +2 -2
- package/dist/esm/elements/SwcIf.js +55 -33
- package/dist/esm/elements/SwcIf.js.map +2 -2
- package/dist/esm/elements/SwcLoop.js +112 -38
- package/dist/esm/elements/SwcLoop.js.map +2 -2
- package/dist/esm/elements/register.js +250 -123
- package/dist/esm/elements/register.js.map +2 -2
- package/dist/esm/router/ElementRouter.js +5 -2
- package/dist/esm/router/ElementRouter.js.map +1 -1
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils/Utils.js +31 -17
- package/dist/esm/utils/Utils.js.map +2 -2
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +563 -557
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
- package/dist/types/decorators/addEventListener.d.ts +5 -7
- package/dist/types/decorators/addEventListener.d.ts.map +1 -1
- package/dist/types/decorators/applyAttribute.d.ts +4 -4
- package/dist/types/decorators/applyAttribute.d.ts.map +1 -1
- package/dist/types/decorators/applyClass.d.ts +6 -6
- package/dist/types/decorators/applyClass.d.ts.map +1 -1
- package/dist/types/decorators/applyNode.d.ts +7 -6
- package/dist/types/decorators/applyNode.d.ts.map +1 -1
- package/dist/types/decorators/applyStyle.d.ts +4 -4
- package/dist/types/decorators/applyStyle.d.ts.map +1 -1
- package/dist/types/decorators/attribute.d.ts +5 -5
- package/dist/types/decorators/attribute.d.ts.map +1 -1
- package/dist/types/decorators/changedAttributeThis.d.ts +18 -0
- package/dist/types/decorators/changedAttributeThis.d.ts.map +1 -0
- package/dist/types/decorators/elementDefine.d.ts.map +1 -1
- package/dist/types/decorators/emitCustomEvent.d.ts +11 -12
- package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
- package/dist/types/decorators/index.d.ts +1 -1
- package/dist/types/decorators/lifecycles.d.ts +10 -7
- package/dist/types/decorators/lifecycles.d.ts.map +1 -1
- package/dist/types/decorators/query.d.ts +17 -63
- package/dist/types/decorators/query.d.ts.map +1 -1
- package/dist/types/decorators/queryAll.d.ts +6 -63
- package/dist/types/decorators/queryAll.d.ts.map +1 -1
- package/dist/types/decorators/setProperty.d.ts +1 -1
- package/dist/types/decorators/setProperty.d.ts.map +1 -1
- package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts +4 -5
- package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts.map +1 -1
- package/dist/types/elements/SwcAppEngine.d.ts +4 -1
- package/dist/types/elements/SwcAppEngine.d.ts.map +1 -1
- package/dist/types/elements/SwcAppMixin.d.ts +11 -8
- package/dist/types/elements/SwcAppMixin.d.ts.map +1 -1
- package/dist/types/elements/register.d.ts.map +1 -1
- package/dist/types/types.d.ts +3 -2
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils/Utils.d.ts +11 -8
- package/dist/types/utils/Utils.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +563 -557
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +3 -3
- package/src/decorators/addEventListener.ts +11 -9
- package/src/decorators/applyAttribute.ts +16 -15
- package/src/decorators/applyClass.ts +18 -17
- package/src/decorators/applyNode.ts +34 -21
- package/src/decorators/applyStyle.ts +17 -16
- package/src/decorators/attribute.ts +21 -20
- package/src/decorators/{changedAttributeHost.ts → changedAttributeThis.ts} +13 -14
- package/src/decorators/elementDefine.ts +402 -358
- package/src/decorators/emitCustomEvent.ts +40 -31
- package/src/decorators/index.ts +1 -1
- package/src/decorators/lifecycles.ts +11 -10
- package/src/decorators/query.ts +51 -124
- package/src/decorators/queryAll.ts +30 -127
- package/src/decorators/setProperty.ts +12 -11
- package/src/decorators/subscribeSwcAppRouteChangeWhileConnected.ts +10 -10
- package/src/elements/SwcAppEngine.ts +10 -3
- package/src/elements/SwcAppMixin.ts +177 -97
- package/src/elements/SwcAsync.ts +32 -21
- package/src/elements/SwcChoose.ts +74 -37
- package/src/elements/SwcIf.ts +60 -23
- package/src/elements/SwcLoop.ts +141 -28
- package/src/elements/register.ts +300 -102
- package/src/types.ts +6 -5
- package/src/utils/Utils.ts +40 -23
- package/tsconfig.json +2 -2
- package/dist/cjs/decorators/changedAttributeHost.js.map +0 -7
- package/dist/esm/decorators/changedAttributeHost.js.map +0 -7
- package/dist/types/decorators/changedAttributeHost.d.ts +0 -19
- package/dist/types/decorators/changedAttributeHost.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -49,21 +49,21 @@ render() {
|
|
|
49
49
|
}
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
-
#### @
|
|
52
|
+
#### @applyInnerHtmlNodeThis
|
|
53
53
|
Apply HTML to specific host element.
|
|
54
54
|
|
|
55
55
|
```typescript
|
|
56
|
-
@
|
|
56
|
+
@applyInnerHtmlNodeThis({ root: 'light' })
|
|
57
57
|
updateContent() {
|
|
58
58
|
return `<p>Updated content</p>`;
|
|
59
59
|
}
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
-
#### @
|
|
62
|
+
#### @applyReplaceChildrenNodeThis
|
|
63
63
|
Replace child nodes with new content.
|
|
64
64
|
|
|
65
65
|
```typescript
|
|
66
|
-
@
|
|
66
|
+
@applyReplaceChildrenNodeThis({ root: 'light' })
|
|
67
67
|
replaceChildren(node: Node) {
|
|
68
68
|
return node;
|
|
69
69
|
}
|
|
@@ -95,38 +95,38 @@ onCriticalClick(event: Event) {
|
|
|
95
95
|
Emit custom events with data.
|
|
96
96
|
|
|
97
97
|
```typescript
|
|
98
|
-
@emitCustomEvent('
|
|
98
|
+
@emitCustomEvent('$appHost', 'user-login')
|
|
99
99
|
async onLogin() {
|
|
100
100
|
const user = await this.authService.login();
|
|
101
101
|
return { user }; // Sent as event detail
|
|
102
102
|
}
|
|
103
103
|
```
|
|
104
104
|
|
|
105
|
-
#### @
|
|
105
|
+
#### @emitCustomEventThis
|
|
106
106
|
Emit events from a method with custom event name mapping.
|
|
107
107
|
|
|
108
108
|
```typescript
|
|
109
|
-
@
|
|
109
|
+
@emitCustomEventThis('navigate', { attributeName: 'on-navigate' })
|
|
110
110
|
onNavClick(e: any) {
|
|
111
111
|
return { path: e.target.dataset.path };
|
|
112
112
|
}
|
|
113
113
|
```
|
|
114
114
|
|
|
115
|
-
#### @
|
|
116
|
-
Listen to events on the component element itself (
|
|
115
|
+
#### @addEventListenerThis
|
|
116
|
+
Listen to events on the component element itself (`@host` selector).
|
|
117
117
|
|
|
118
118
|
```typescript
|
|
119
|
-
@
|
|
119
|
+
@addEventListenerThis('click')
|
|
120
120
|
onHostClick(event: Event) {
|
|
121
121
|
console.log('Host element clicked');
|
|
122
122
|
}
|
|
123
123
|
```
|
|
124
124
|
|
|
125
125
|
#### @addEventListenerAppHost
|
|
126
|
-
Listen to events on the app root host element (
|
|
126
|
+
Listen to events on the app root host element (`$appHost` selector). Enables selective event handling with filters.
|
|
127
127
|
|
|
128
128
|
```typescript
|
|
129
|
-
// Listen to all user-action events from
|
|
129
|
+
// Listen to all user-action events from $appHost
|
|
130
130
|
@addEventListenerAppHost('user-action')
|
|
131
131
|
onUserAction(e: CustomEvent) {
|
|
132
132
|
console.log('User action:', e.detail);
|
|
@@ -173,11 +173,11 @@ textInputs?: HTMLInputElement[];
|
|
|
173
173
|
listItems?: HTMLLIElement[];
|
|
174
174
|
```
|
|
175
175
|
|
|
176
|
-
#### @
|
|
176
|
+
#### @queryThis
|
|
177
177
|
Query the component element itself.
|
|
178
178
|
|
|
179
179
|
```typescript
|
|
180
|
-
@
|
|
180
|
+
@queryThis
|
|
181
181
|
self?: HTMLElement;
|
|
182
182
|
|
|
183
183
|
printTag() {
|
|
@@ -185,11 +185,11 @@ printTag() {
|
|
|
185
185
|
}
|
|
186
186
|
```
|
|
187
187
|
|
|
188
|
-
#### @
|
|
188
|
+
#### @queryAllThis
|
|
189
189
|
Query all direct children of the component.
|
|
190
190
|
|
|
191
191
|
```typescript
|
|
192
|
-
@
|
|
192
|
+
@queryAllThis
|
|
193
193
|
children?: HTMLElement[];
|
|
194
194
|
|
|
195
195
|
getChildCount() {
|
|
@@ -210,11 +210,11 @@ width: string = '100px';
|
|
|
210
210
|
resourceId: string = '';
|
|
211
211
|
```
|
|
212
212
|
|
|
213
|
-
#### @
|
|
213
|
+
#### @attributeThis
|
|
214
214
|
Bind attributes on host element itself.
|
|
215
215
|
|
|
216
216
|
```typescript
|
|
217
|
-
@
|
|
217
|
+
@attributeThis('product-id')
|
|
218
218
|
productId: string = '';
|
|
219
219
|
|
|
220
220
|
@onInitialize
|
|
@@ -239,7 +239,7 @@ onDisconnected() {
|
|
|
239
239
|
}
|
|
240
240
|
|
|
241
241
|
|
|
242
|
-
@
|
|
242
|
+
@onConnectedBefore
|
|
243
243
|
onAppReady(router: Router) {
|
|
244
244
|
// Called after SwcApp.connect() completes on all already-connected components
|
|
245
245
|
// Full DI support available through hostSet
|
|
@@ -288,7 +288,7 @@ Switch-case style conditional rendering with `swc-when` and `swc-otherwise` sub-
|
|
|
288
288
|
// Component with conditional rendering logic
|
|
289
289
|
@elementDefine('status-display')
|
|
290
290
|
class StatusDisplay extends HTMLElement {
|
|
291
|
-
@
|
|
291
|
+
@attributeThis('status')
|
|
292
292
|
status: string = 'pending';
|
|
293
293
|
|
|
294
294
|
@setProperty('#status-template', 'value')
|
|
@@ -300,18 +300,15 @@ class StatusDisplay extends HTMLElement {
|
|
|
300
300
|
render() {
|
|
301
301
|
return `
|
|
302
302
|
<template id="status-template" is="swc-choose">
|
|
303
|
-
|
|
304
|
-
<template is="swc-when" value="{{ $value === 'pending' }}">
|
|
303
|
+
<template is="swc-when" test="$value === 'pending'">
|
|
305
304
|
<div style="color: orange;">⏳ Processing...</div>
|
|
306
305
|
</template>
|
|
307
306
|
|
|
308
|
-
|
|
309
|
-
<template is="swc-when" value="{{ $value === 'success' }}">
|
|
307
|
+
<template is="swc-when" test="$value === 'success'">
|
|
310
308
|
<div style="color: green;">✓ Completed</div>
|
|
311
309
|
</template>
|
|
312
310
|
|
|
313
|
-
|
|
314
|
-
<template is="swc-when" value="{{ $value === 'error' }}">
|
|
311
|
+
<template is="swc-when" test="$value === 'error'">
|
|
315
312
|
<div style="color: red;">✗ Failed</div>
|
|
316
313
|
</template>
|
|
317
314
|
|
|
@@ -326,7 +323,6 @@ class StatusDisplay extends HTMLElement {
|
|
|
326
323
|
```
|
|
327
324
|
|
|
328
325
|
**Expression Features:**
|
|
329
|
-
- `{{ }} braces` for dynamic condition evaluation
|
|
330
326
|
- `$value` contains the value passed to `swc-choose`
|
|
331
327
|
- `skip-if-same` attribute prevents re-render when same template selected
|
|
332
328
|
- **Attribute substitution with `{{= }}`**: `attribute-name="{{= expression }}"` automatically evaluated
|
|
@@ -334,7 +330,7 @@ class StatusDisplay extends HTMLElement {
|
|
|
334
330
|
**Attribute Substitution Example ({{= }} usage):**
|
|
335
331
|
```html
|
|
336
332
|
<template is="swc-choose">
|
|
337
|
-
<template is="swc-when"
|
|
333
|
+
<template is="swc-when" test="$value?.type === 'user'">
|
|
338
334
|
<user-card
|
|
339
335
|
data-username="{{= $value?.name }}"
|
|
340
336
|
data-email="{{= $value?.email }}"
|
|
@@ -342,7 +338,7 @@ class StatusDisplay extends HTMLElement {
|
|
|
342
338
|
></user-card>
|
|
343
339
|
</template>
|
|
344
340
|
|
|
345
|
-
<template is="swc-when" value="
|
|
341
|
+
<template is="swc-when" value="$value?.type === 'product'">
|
|
346
342
|
<product-card
|
|
347
343
|
data-product-name="{{= $value?.title }}"
|
|
348
344
|
data-price="{{= $value?.price }}"
|
|
@@ -499,7 +495,7 @@ class ProductList extends HTMLElement {
|
|
|
499
495
|
<div style="margin: 10px; padding: 10px; border: 1px solid #ddd;">
|
|
500
496
|
<!-- Using {{ }} for template content rendering -->
|
|
501
497
|
<h3>{{ $item.name }}</h3>
|
|
502
|
-
<p>Price:
|
|
498
|
+
<p>Price: {{ $item.price }}</p>
|
|
503
499
|
<p>ID: {{ $item.id }} (Index: {{ $index }})</p>
|
|
504
500
|
|
|
505
501
|
<!-- Using {{= }} for dynamic attribute substitution -->
|
|
@@ -512,7 +508,7 @@ class ProductList extends HTMLElement {
|
|
|
512
508
|
|
|
513
509
|
<!-- Computed expressions with {{= }} -->
|
|
514
510
|
<button data-id="{{= $item.id }}" data-price="{{= $item.price }}">
|
|
515
|
-
Add to Cart -
|
|
511
|
+
Add to Cart - {{ $item.price }}
|
|
516
512
|
</button>
|
|
517
513
|
</div>
|
|
518
514
|
|
|
@@ -561,7 +557,7 @@ class ProductList extends HTMLElement {
|
|
|
561
557
|
</template>
|
|
562
558
|
```
|
|
563
559
|
|
|
564
|
-
**Advanced: replace-wrap for Custom Expression Syntax**
|
|
560
|
+
**Advanced: replace-wrap-start replace-wrap-end for Custom Expression Syntax**
|
|
565
561
|
|
|
566
562
|
Override default `{{ }}` and `{{= }}` syntax with custom wrappers:
|
|
567
563
|
|
|
@@ -574,10 +570,10 @@ class CustomLoop extends HTMLElement {
|
|
|
574
570
|
render() {
|
|
575
571
|
return `
|
|
576
572
|
<!-- Using custom wrapper syntax [(= ... )] instead of {{= ... }} -->
|
|
577
|
-
<template id="items" is="swc-loop" replace-wrap="[(=
|
|
573
|
+
<template id="items" is="swc-loop" replace-wrap-start="[(" replace-wrap-end=")]" value="{{= $host.items }}">
|
|
578
574
|
<div>
|
|
579
|
-
<p>Name: [(
|
|
580
|
-
<button data-id="[(
|
|
575
|
+
<p>Name: [( $item.name )]</p>
|
|
576
|
+
<button data-id="[( $item.id )]">Click me</button>
|
|
581
577
|
</div>
|
|
582
578
|
</template>
|
|
583
579
|
`;
|
|
@@ -586,10 +582,8 @@ class CustomLoop extends HTMLElement {
|
|
|
586
582
|
```
|
|
587
583
|
|
|
588
584
|
**replace-wrap attribute options:**
|
|
589
|
-
- Change expression wrapper from default `{{
|
|
590
|
-
- Useful when `{{ }}` conflicts with template engines like EJS or Mustache
|
|
585
|
+
- Change expression wrapper from default `{#{ }#}` to custom pattern
|
|
591
586
|
- Supported on: `SwcLoop`, `SwcChoose`, `SwcIf`, `SwcAsync`, `register()` directives
|
|
592
|
-
- Example patterns: `[(= )]`, `{[= ]}`, `<%= %>` (after escaping)
|
|
593
587
|
|
|
594
588
|
---
|
|
595
589
|
|
|
@@ -621,23 +615,22 @@ class RootRouter extends HTMLElement {
|
|
|
621
615
|
render() {
|
|
622
616
|
return `
|
|
623
617
|
<template id="router" is="swc-choose">
|
|
624
|
-
|
|
625
|
-
<template is="swc-when" value="{{ ['', '/'].includes($value?.path) }}">
|
|
618
|
+
<template is="swc-when" test="['', '/'].includes($value?.path)">
|
|
626
619
|
<home-page/>
|
|
627
620
|
</template>
|
|
628
621
|
|
|
629
622
|
<!-- Users List Page -->
|
|
630
|
-
<template is="swc-when"
|
|
623
|
+
<template is="swc-when" test="$value?.path === '/users'">
|
|
631
624
|
<users-list-page/>
|
|
632
625
|
</template>
|
|
633
626
|
|
|
634
627
|
<!-- User Detail Page: Using {{= }} for dynamic attributes from route params -->
|
|
635
|
-
<template is="swc-when"
|
|
628
|
+
<template is="swc-when" test="$value?.path.startsWith('/users/')">
|
|
636
629
|
<user-detail-page user-id="{{= $value?.pathData?.id }}"></user-detail-page>
|
|
637
630
|
</template>
|
|
638
631
|
|
|
639
632
|
<!-- Product Detail Page: Using {{= }} for dynamic route parameters -->
|
|
640
|
-
<template is="swc-when"
|
|
633
|
+
<template is="swc-when" test="$value?.path.startsWith('/products/')">
|
|
641
634
|
<product-detail-page product-id="{{= $value?.pathData?.id }}"></product-detail-page>
|
|
642
635
|
</template>
|
|
643
636
|
|
|
@@ -900,17 +893,17 @@ const rootRouterFactory = (w: Window) => {
|
|
|
900
893
|
return `
|
|
901
894
|
<template id="router" is="swc-choose">
|
|
902
895
|
<!-- Home Page -->
|
|
903
|
-
<template is="swc-when"
|
|
896
|
+
<template is="swc-when" test="['', '/'].includes($value?.path)">
|
|
904
897
|
<home-page/>
|
|
905
898
|
</template>
|
|
906
899
|
|
|
907
900
|
<!-- Users List -->
|
|
908
|
-
<template is="swc-when"
|
|
901
|
+
<template is="swc-when" test="$value?.path === '/users'">
|
|
909
902
|
<users-list-page/>
|
|
910
903
|
</template>
|
|
911
904
|
|
|
912
905
|
<!-- User Detail -->
|
|
913
|
-
<template is="swc-when"
|
|
906
|
+
<template is="swc-when" test="$value?.path.startsWith('/users/')">
|
|
914
907
|
<user-detail-page user-id="{{$value?.pathData?.id}}"/>
|
|
915
908
|
</template>
|
|
916
909
|
|
|
@@ -965,7 +958,7 @@ export default HomePage;
|
|
|
965
958
|
|
|
966
959
|
```typescript
|
|
967
960
|
// pages/UsersListPage.ts
|
|
968
|
-
import { elementDefine, onConnectedInnerHtml,
|
|
961
|
+
import { elementDefine, onConnectedInnerHtml, onConnectedBefore } from '@dooboostore/simple-web-component';
|
|
969
962
|
import { Inject } from '@dooboostore/simple-boot';
|
|
970
963
|
import { UserService } from '../services/UserService';
|
|
971
964
|
|
|
@@ -978,7 +971,7 @@ const UsersListPage = (w: Window) => {
|
|
|
978
971
|
class UsersListPage extends w.HTMLElement {
|
|
979
972
|
private users: any[] = [];
|
|
980
973
|
|
|
981
|
-
@
|
|
974
|
+
@onConnectedBefore
|
|
982
975
|
onconstructor(@Inject({ symbol: UserService.SYMBOL }) userService: UserService) {
|
|
983
976
|
this.users = userService.getAllUsers();
|
|
984
977
|
}
|
|
@@ -1022,10 +1015,10 @@ const UserCard = (w: Window) => {
|
|
|
1022
1015
|
|
|
1023
1016
|
@elementDefine(tagName, { window: w })
|
|
1024
1017
|
class UserCard extends w.HTMLElement {
|
|
1025
|
-
@
|
|
1018
|
+
@attributeThis('data-username')
|
|
1026
1019
|
username: string;
|
|
1027
1020
|
|
|
1028
|
-
@
|
|
1021
|
+
@attributeThis('data-email')
|
|
1029
1022
|
email: string;
|
|
1030
1023
|
|
|
1031
1024
|
@onConnectedInnerHtml({ useShadow: true })
|
|
@@ -1173,7 +1166,7 @@ src/
|
|
|
1173
1166
|
6. `<root-router>` becomes active with `@subscribeSwcAppRouteChangeWhileConnected` + `swc-choose` template
|
|
1174
1167
|
7. Route changes automatically trigger `swc-choose` re-evaluation and template re-rendering
|
|
1175
1168
|
8. Template attributes like `user-id="{{$value?.pathData?.id}}"` are dynamically populated with route params
|
|
1176
|
-
9. All components have access to injected services via `@onInitialize`
|
|
1169
|
+
9. All components have access to injected services via `@onInitialize`
|
|
1177
1170
|
|
|
1178
1171
|
|
|
1179
1172
|
---
|
|
@@ -20,7 +20,9 @@ __export(addEventListener_exports, {
|
|
|
20
20
|
ADD_EVENT_LISTENER_METADATA_KEY: () => ADD_EVENT_LISTENER_METADATA_KEY,
|
|
21
21
|
addEventListener: () => addEventListener,
|
|
22
22
|
addEventListenerAppHost: () => addEventListenerAppHost,
|
|
23
|
-
|
|
23
|
+
addEventListenerDocument: () => addEventListenerDocument,
|
|
24
|
+
addEventListenerThis: () => addEventListenerThis,
|
|
25
|
+
addEventListenerWindow: () => addEventListenerWindow,
|
|
24
26
|
getAddEventListenerMetadata: () => getAddEventListenerMetadata
|
|
25
27
|
});
|
|
26
28
|
module.exports = __toCommonJS(addEventListener_exports);
|
|
@@ -41,10 +43,16 @@ const getAddEventListenerMetadata = (target) => {
|
|
|
41
43
|
const constructor = target instanceof Function ? target : target.constructor;
|
|
42
44
|
return import_core.ReflectUtils.getMetadata(ADD_EVENT_LISTENER_METADATA_KEY, constructor);
|
|
43
45
|
};
|
|
44
|
-
function
|
|
45
|
-
return addEventListener("
|
|
46
|
+
function addEventListenerThis(type, options) {
|
|
47
|
+
return addEventListener("$this", type, options);
|
|
46
48
|
}
|
|
47
49
|
function addEventListenerAppHost(type, options) {
|
|
48
|
-
return addEventListener("
|
|
50
|
+
return addEventListener("$appHost", type, options);
|
|
51
|
+
}
|
|
52
|
+
function addEventListenerWindow(type, options) {
|
|
53
|
+
return addEventListener("$window", type, options);
|
|
54
|
+
}
|
|
55
|
+
function addEventListenerDocument(type, options) {
|
|
56
|
+
return addEventListener("$document", type, options);
|
|
49
57
|
}
|
|
50
58
|
//# sourceMappingURL=addEventListener.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/decorators/addEventListener.ts"],
|
|
4
|
-
"sourcesContent": ["import { ReflectUtils } from '@dooboostore/core';\nimport { SpecialSelector, SwcQueryOptions, HelperHostSet } from '../types';\n\nexport interface AddEventListenerBaseOptions extends EventListenerOptions {\n capture?: boolean;\n once?: boolean;\n passive?: boolean;\n stopPropagation?: boolean;\n stopImmediatePropagation?: boolean;\n preventDefault?: boolean;\n removeOnDisconnected?: boolean;\n delegate?: boolean;\n filter?: (target: Event | CustomEvent, meta:{currentThis: any, helper: HelperHostSet}) => boolean;\n}\n\nexport interface AddEventListenerMetadata {\n propertyKey: string | symbol;\n selector: string;\n type: string;\n options: AddEventListenerBaseOptions & SwcQueryOptions & { delegate?: boolean };\n}\n\nexport const ADD_EVENT_LISTENER_METADATA_KEY = Symbol.for('simple-web-component:add-event-listener');\n\nexport function addEventListener(target: SpecialSelector, type: string, options?: AddEventListenerBaseOptions): MethodDecorator;\nexport function addEventListener(selector: string, type: string, options?: AddEventListenerBaseOptions & SwcQueryOptions & { delegate?: boolean }): MethodDecorator;\n/**\n * @addEventListener decorator to bind events to elements.\n */\nexport function addEventListener(selectorOrTarget: string, type: string, options: any = {}): MethodDecorator {\n return (targetObj: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n const constructor = targetObj.constructor;\n\n let listeners = ReflectUtils.getMetadata<AddEventListenerMetadata[]>(ADD_EVENT_LISTENER_METADATA_KEY, constructor);\n if (!listeners) {\n listeners = [];\n ReflectUtils.defineMetadata(ADD_EVENT_LISTENER_METADATA_KEY, listeners, constructor);\n }\n\n listeners.push({ propertyKey, selector: selectorOrTarget, type, options });\n };\n}\n\nexport const getAddEventListenerMetadata = (target: any): AddEventListenerMetadata[] | undefined => {\n const constructor = target instanceof Function ? target : target.constructor;\n return ReflectUtils.getMetadata(ADD_EVENT_LISTENER_METADATA_KEY, constructor);\n};\n\n/**\n * @
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA6B;AAsBtB,MAAM,kCAAkC,OAAO,IAAI,yCAAyC;AAO5F,SAAS,iBAAiB,kBAA0B,MAAc,UAAe,CAAC,GAAoB;AAC3G,SAAO,CAAC,WAAmB,aAA8B,eAAmC;AAC1F,UAAM,cAAc,UAAU;AAE9B,QAAI,YAAY,yBAAa,YAAwC,iCAAiC,WAAW;AACjH,QAAI,CAAC,WAAW;AACd,kBAAY,CAAC;AACb,+BAAa,eAAe,iCAAiC,WAAW,WAAW;AAAA,IACrF;AAEA,cAAU,KAAK,EAAE,aAAa,UAAU,kBAAkB,MAAM,QAAQ,CAAC;AAAA,EAC3E;AACF;AAEO,MAAM,8BAA8B,CAAC,WAAwD;AAClG,QAAM,cAAc,kBAAkB,WAAW,SAAS,OAAO;AACjE,SAAO,yBAAa,YAAY,iCAAiC,WAAW;AAC9E;
|
|
4
|
+
"sourcesContent": ["import { ReflectUtils } from '@dooboostore/core';\nimport { SpecialSelector, SwcQueryOptions, HelperHostSet } from '../types';\n\nexport interface AddEventListenerBaseOptions extends EventListenerOptions {\n capture?: boolean;\n once?: boolean;\n passive?: boolean;\n stopPropagation?: boolean;\n stopImmediatePropagation?: boolean;\n preventDefault?: boolean;\n removeOnDisconnected?: boolean;\n delegate?: boolean;\n filter?: (target: Event | CustomEvent, meta:{currentThis: any, helper: HelperHostSet}) => boolean;\n}\n\nexport interface AddEventListenerMetadata {\n propertyKey: string | symbol;\n selector: string;\n type: string;\n options: AddEventListenerBaseOptions & SwcQueryOptions & { delegate?: boolean };\n}\n\nexport const ADD_EVENT_LISTENER_METADATA_KEY = Symbol.for('simple-web-component:add-event-listener');\n\nexport function addEventListener(target: SpecialSelector, type: string, options?: AddEventListenerBaseOptions): MethodDecorator;\nexport function addEventListener(selector: string, type: string, options?: AddEventListenerBaseOptions & SwcQueryOptions & { delegate?: boolean }): MethodDecorator;\n/**\n * @addEventListener decorator to bind events to elements.\n */\nexport function addEventListener(selectorOrTarget: string, type: string, options: any = {}): MethodDecorator {\n return (targetObj: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n const constructor = targetObj.constructor;\n\n let listeners = ReflectUtils.getMetadata<AddEventListenerMetadata[]>(ADD_EVENT_LISTENER_METADATA_KEY, constructor);\n if (!listeners) {\n listeners = [];\n ReflectUtils.defineMetadata(ADD_EVENT_LISTENER_METADATA_KEY, listeners, constructor);\n }\n\n listeners.push({ propertyKey, selector: selectorOrTarget, type, options });\n };\n}\n\nexport const getAddEventListenerMetadata = (target: any): AddEventListenerMetadata[] | undefined => {\n const constructor = target instanceof Function ? target : target.constructor;\n return ReflectUtils.getMetadata(ADD_EVENT_LISTENER_METADATA_KEY, constructor);\n};\n\n/**\n * @addEventListenerThis decorator - simplified version of @addEventListener for $this selector\n */\nexport function addEventListenerThis(type: string, options?: AddEventListenerBaseOptions & SwcQueryOptions): MethodDecorator {\n return addEventListener('$this', type, options);\n}\n\n/**\n * @addEventListenerAppHost decorator - simplified version of @addEventListener for $appHost selector\n */\nexport function addEventListenerAppHost(type: string, options?: AddEventListenerBaseOptions & SwcQueryOptions): MethodDecorator {\n return addEventListener('$appHost', type, options);\n}\nexport function addEventListenerWindow(type: string, options?: AddEventListenerBaseOptions & SwcQueryOptions): MethodDecorator {\n return addEventListener('$window', type, options);\n}\nexport function addEventListenerDocument(type: string, options?: AddEventListenerBaseOptions & SwcQueryOptions): MethodDecorator {\n return addEventListener('$document', type, options);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA6B;AAsBtB,MAAM,kCAAkC,OAAO,IAAI,yCAAyC;AAO5F,SAAS,iBAAiB,kBAA0B,MAAc,UAAe,CAAC,GAAoB;AAC3G,SAAO,CAAC,WAAmB,aAA8B,eAAmC;AAC1F,UAAM,cAAc,UAAU;AAE9B,QAAI,YAAY,yBAAa,YAAwC,iCAAiC,WAAW;AACjH,QAAI,CAAC,WAAW;AACd,kBAAY,CAAC;AACb,+BAAa,eAAe,iCAAiC,WAAW,WAAW;AAAA,IACrF;AAEA,cAAU,KAAK,EAAE,aAAa,UAAU,kBAAkB,MAAM,QAAQ,CAAC;AAAA,EAC3E;AACF;AAEO,MAAM,8BAA8B,CAAC,WAAwD;AAClG,QAAM,cAAc,kBAAkB,WAAW,SAAS,OAAO;AACjE,SAAO,yBAAa,YAAY,iCAAiC,WAAW;AAC9E;AAKO,SAAS,qBAAqB,MAAc,SAA0E;AAC3H,SAAO,iBAAiB,SAAS,MAAM,OAAO;AAChD;AAKO,SAAS,wBAAwB,MAAc,SAA0E;AAC9H,SAAO,iBAAiB,YAAY,MAAM,OAAO;AACnD;AACO,SAAS,uBAAuB,MAAc,SAA0E;AAC7H,SAAO,iBAAiB,WAAW,MAAM,OAAO;AAClD;AACO,SAAS,yBAAyB,MAAc,SAA0E;AAC/H,SAAO,iBAAiB,aAAa,MAAM,OAAO;AACpD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -19,14 +19,14 @@ var applyAttribute_exports = {};
|
|
|
19
19
|
__export(applyAttribute_exports, {
|
|
20
20
|
ATTRIBUTE_APPLY_METADATA_KEY: () => ATTRIBUTE_APPLY_METADATA_KEY,
|
|
21
21
|
applyAttribute: () => applyAttribute,
|
|
22
|
-
|
|
22
|
+
applyAttributeThis: () => applyAttributeThis,
|
|
23
23
|
findAllAttributeApplyMetadata: () => findAllAttributeApplyMetadata,
|
|
24
24
|
removeAttribute: () => removeAttribute,
|
|
25
|
-
|
|
25
|
+
removeAttributeThis: () => removeAttributeThis,
|
|
26
26
|
setAttribute: () => setAttribute,
|
|
27
|
-
|
|
27
|
+
setAttributeThis: () => setAttributeThis,
|
|
28
28
|
updateAttribute: () => updateAttribute,
|
|
29
|
-
|
|
29
|
+
updateAttributeThis: () => updateAttributeThis
|
|
30
30
|
});
|
|
31
31
|
module.exports = __toCommonJS(applyAttribute_exports);
|
|
32
32
|
var import_core = require("@dooboostore/core");
|
|
@@ -68,15 +68,16 @@ function createAttributeDecorator(action) {
|
|
|
68
68
|
if (!t || !(t instanceof win.HTMLElement)) return;
|
|
69
69
|
targetEls.push(t);
|
|
70
70
|
};
|
|
71
|
-
if (selector === "
|
|
72
|
-
else if (selector === "
|
|
73
|
-
else if (selector === "
|
|
74
|
-
else if (selector === "
|
|
75
|
-
else if (selector === "
|
|
76
|
-
else if (selector === "
|
|
77
|
-
else if (selector === "
|
|
78
|
-
else if (selector === "
|
|
79
|
-
else if (selector === "
|
|
71
|
+
if (selector === "$this" || !selector) applyRoot(host);
|
|
72
|
+
else if (selector === "$host") applyRoot(hostSet.$host);
|
|
73
|
+
else if (selector === "$parentHost") applyRoot(hostSet.$parentHost);
|
|
74
|
+
else if (selector === "$appHost") applyRoot(hostSet.$appHost);
|
|
75
|
+
else if (selector === "$firstHost") applyRoot(hostSet.$firstHost);
|
|
76
|
+
else if (selector === "$lastHost") applyRoot(hostSet.$lastHost);
|
|
77
|
+
else if (selector === "$firstAppHost") applyRoot(hostSet.$firstAppHost);
|
|
78
|
+
else if (selector === "$lastAppHost") applyRoot(hostSet.$lastAppHost);
|
|
79
|
+
else if (selector === "$hosts") hostSet.$hosts.forEach(applyRoot);
|
|
80
|
+
else if (selector === "$appHosts") hostSet.$appHosts.forEach(applyRoot);
|
|
80
81
|
else {
|
|
81
82
|
const targetRoot = r === "auto" ? host.shadowRoot || host : r === "shadow" ? host.shadowRoot : host;
|
|
82
83
|
if (targetRoot) {
|
|
@@ -139,12 +140,12 @@ function applyAttribute(selector, action = "update", options = {}) {
|
|
|
139
140
|
const setAttribute = (selector, nameOrOptions, options = {}) => createAttributeDecorator("set")(selector, nameOrOptions, options);
|
|
140
141
|
const updateAttribute = (selector, nameOrOptions, options = {}) => createAttributeDecorator("update")(selector, nameOrOptions, options);
|
|
141
142
|
const removeAttribute = (selector, nameOrOptions, options = {}) => createAttributeDecorator("remove")(selector, nameOrOptions, options);
|
|
142
|
-
function
|
|
143
|
-
return createAttributeDecorator(action)("
|
|
143
|
+
function applyAttributeThis(action = "update", options = {}) {
|
|
144
|
+
return createAttributeDecorator(action)("$this", options);
|
|
144
145
|
}
|
|
145
|
-
const
|
|
146
|
-
const
|
|
147
|
-
const
|
|
146
|
+
const setAttributeThis = (nameOrOptions, options = {}) => createAttributeDecorator("set")("$this", nameOrOptions, options);
|
|
147
|
+
const updateAttributeThis = (nameOrOptions, options = {}) => createAttributeDecorator("update")("$this", nameOrOptions, options);
|
|
148
|
+
const removeAttributeThis = (nameOrOptions, options = {}) => createAttributeDecorator("remove")("$this", nameOrOptions, options);
|
|
148
149
|
const findAllAttributeApplyMetadata = (target) => {
|
|
149
150
|
const result = /* @__PURE__ */ new Map();
|
|
150
151
|
const maps = import_core.ReflectUtils.findAllMetadata(ATTRIBUTE_APPLY_METADATA_KEY, target);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/decorators/applyAttribute.ts"],
|
|
4
|
-
"sourcesContent": ["import { ReflectUtils } from '@dooboostore/core';\nimport { ensureInit } from './elementDefine';\nimport { SwcUtils } from '../utils/Utils';\nimport { SwcQueryOptions, HelperHostSet } from '../types';\n\nexport type AttributeAction = 'set' | 'update' | 'remove';\n\nexport interface AttributeApplyOptions extends SwcQueryOptions {\n name?: string;\n filter?: (target: HTMLElement, value: any, meta: {currentThis: any, helper: HelperHostSet}) => boolean;\n}\n\nexport interface AttributeApplyMetadata {\n propertyKey: string | symbol;\n selector: string;\n action: AttributeAction;\n options: AttributeApplyOptions;\n}\n\nexport const ATTRIBUTE_APPLY_METADATA_KEY = Symbol.for('simple-web-component:attribute-apply');\n\nfunction createAttributeDecorator(action: AttributeAction) {\n return (selector: string, nameOrOptions?: string | AttributeApplyOptions, options: AttributeApplyOptions = {}): MethodDecorator => {\n return (target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n const constructor = target.constructor;\n let metaList = ReflectUtils.getOwnMetadata(ATTRIBUTE_APPLY_METADATA_KEY, constructor) as Map<string | symbol, AttributeApplyMetadata>;\n if (!metaList) {\n metaList = new Map<string | symbol, AttributeApplyMetadata>();\n ReflectUtils.defineMetadata(ATTRIBUTE_APPLY_METADATA_KEY, metaList, constructor);\n }\n\n let attributeName = typeof nameOrOptions === 'string' ? nameOrOptions : undefined;\n let finalOptions = options;\n \n if (typeof nameOrOptions === 'object' && nameOrOptions !== null) {\n finalOptions = nameOrOptions as AttributeApplyOptions;\n }\n\n metaList.set(propertyKey, { \n propertyKey, \n selector, \n action, \n options: { ...finalOptions, name: attributeName } \n });\n\n const original = descriptor.value;\n descriptor.value = function (...args: any[]) {\n ensureInit(this);\n const res = (original as any).apply(this, args);\n\n const handleResult = (resolvedValue: any) => {\n if (resolvedValue !== undefined) {\n const win = (this as any).ownerDocument?.defaultView || window;\n const host = this as unknown as HTMLElement;\n const hostSet = { ...SwcUtils.getHelperAndHostSet(win, host), $this: this };\n const r = finalOptions.root || 'auto';\n const targetEls: HTMLElement[] = [];\n\n const applyRoot = (t: any) => {\n if (!t || !(t instanceof win.HTMLElement)) return;\n targetEls.push(t);\n };\n\n if (selector === '
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA6B;AAC7B,2BAA2B;AAC3B,mBAAyB;AAiBlB,MAAM,+BAA+B,OAAO,IAAI,sCAAsC;AAE7F,SAAS,yBAAyB,QAAyB;AACzD,SAAO,CAAC,UAAkB,eAAgD,UAAiC,CAAC,MAAuB;AACjI,WAAO,CAAC,QAAgB,aAA8B,eAAmC;AACvF,YAAM,cAAc,OAAO;AAC3B,UAAI,WAAW,yBAAa,eAAe,8BAA8B,WAAW;AACpF,UAAI,CAAC,UAAU;AACb,mBAAW,oBAAI,IAA6C;AAC5D,iCAAa,eAAe,8BAA8B,UAAU,WAAW;AAAA,MACjF;AAEA,UAAI,gBAAgB,OAAO,kBAAkB,WAAW,gBAAgB;AACxE,UAAI,eAAe;AAEnB,UAAI,OAAO,kBAAkB,YAAY,kBAAkB,MAAM;AAC7D,uBAAe;AAAA,MACnB;AAEA,eAAS,IAAI,aAAa;AAAA,QACxB;AAAA,QACA;AAAA,QACA;AAAA,QACA,SAAS,EAAE,GAAG,cAAc,MAAM,cAAc;AAAA,MAClD,CAAC;AAED,YAAM,WAAW,WAAW;AAC5B,iBAAW,QAAQ,YAAa,MAAa;AAC3C,6CAAW,IAAI;AACf,cAAM,MAAO,SAAiB,MAAM,MAAM,IAAI;AAE9C,cAAM,eAAe,CAAC,kBAAuB;AAC3C,cAAI,kBAAkB,QAAW;AAC/B,kBAAM,MAAO,KAAa,eAAe,eAAe;AACxD,kBAAM,OAAO;AACb,kBAAM,UAAU,EAAE,GAAG,sBAAS,oBAAoB,KAAK,IAAI,GAAG,OAAO,KAAK;AAC1E,kBAAM,IAAI,aAAa,QAAQ;AAC/B,kBAAM,YAA2B,CAAC;AAElC,kBAAM,YAAY,CAAC,MAAW;AAC5B,kBAAI,CAAC,KAAK,EAAE,aAAa,IAAI,aAAc;AAC3C,wBAAU,KAAK,CAAC;AAAA,YAClB;AAEA,gBAAI,aAAa,cAAe,WAAU,QAAQ,WAAW;AAAA,
|
|
4
|
+
"sourcesContent": ["import { ReflectUtils } from '@dooboostore/core';\nimport { ensureInit } from './elementDefine';\nimport { SwcUtils } from '../utils/Utils';\nimport { SwcQueryOptions, HelperHostSet } from '../types';\n\nexport type AttributeAction = 'set' | 'update' | 'remove';\n\nexport interface AttributeApplyOptions extends SwcQueryOptions {\n name?: string;\n filter?: (target: HTMLElement, value: any, meta: {currentThis: any, helper: HelperHostSet}) => boolean;\n}\n\nexport interface AttributeApplyMetadata {\n propertyKey: string | symbol;\n selector: string;\n action: AttributeAction;\n options: AttributeApplyOptions;\n}\n\nexport const ATTRIBUTE_APPLY_METADATA_KEY = Symbol.for('simple-web-component:attribute-apply');\n\nfunction createAttributeDecorator(action: AttributeAction) {\n return (selector: string, nameOrOptions?: string | AttributeApplyOptions, options: AttributeApplyOptions = {}): MethodDecorator => {\n return (target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n const constructor = target.constructor;\n let metaList = ReflectUtils.getOwnMetadata(ATTRIBUTE_APPLY_METADATA_KEY, constructor) as Map<string | symbol, AttributeApplyMetadata>;\n if (!metaList) {\n metaList = new Map<string | symbol, AttributeApplyMetadata>();\n ReflectUtils.defineMetadata(ATTRIBUTE_APPLY_METADATA_KEY, metaList, constructor);\n }\n\n let attributeName = typeof nameOrOptions === 'string' ? nameOrOptions : undefined;\n let finalOptions = options;\n \n if (typeof nameOrOptions === 'object' && nameOrOptions !== null) {\n finalOptions = nameOrOptions as AttributeApplyOptions;\n }\n\n metaList.set(propertyKey, { \n propertyKey, \n selector, \n action, \n options: { ...finalOptions, name: attributeName } \n });\n\n const original = descriptor.value;\n descriptor.value = function (...args: any[]) {\n ensureInit(this);\n const res = (original as any).apply(this, args);\n\n const handleResult = (resolvedValue: any) => {\n if (resolvedValue !== undefined) {\n const win = (this as any).ownerDocument?.defaultView || window;\n const host = this as unknown as HTMLElement;\n const hostSet = { ...SwcUtils.getHelperAndHostSet(win, host), $this: this };\n const r = finalOptions.root || 'auto';\n const targetEls: HTMLElement[] = [];\n\n const applyRoot = (t: any) => {\n if (!t || !(t instanceof win.HTMLElement)) return;\n targetEls.push(t);\n };\n\n if (selector === '$this' || !selector) applyRoot(host);\n else if (selector === '$host') applyRoot(hostSet.$host);\n else if (selector === '$parentHost') applyRoot(hostSet.$parentHost);\n else if (selector === '$appHost') applyRoot(hostSet.$appHost);\n else if (selector === '$firstHost') applyRoot(hostSet.$firstHost);\n else if (selector === '$lastHost') applyRoot(hostSet.$lastHost);\n else if (selector === '$firstAppHost') applyRoot(hostSet.$firstAppHost);\n else if (selector === '$lastAppHost') applyRoot(hostSet.$lastAppHost);\n else if (selector === '$hosts') hostSet.$hosts.forEach(applyRoot);\n else if (selector === '$appHosts') hostSet.$appHosts.forEach(applyRoot);\n else {\n const targetRoot = r === 'auto' ? (host.shadowRoot || host) : (r === 'shadow' ? host.shadowRoot : host);\n if (targetRoot) {\n const found = targetRoot.querySelectorAll(selector);\n if (found) targetEls.push(...(Array.from(found) as HTMLElement[]));\n }\n }\n\n targetEls.forEach(targetEl => {\n if (finalOptions.filter && !finalOptions.filter(targetEl, resolvedValue, {currentThis: this, helper: hostSet})) {\n return;\n }\n const resolvedRes = typeof resolvedValue === 'function' ? (resolvedValue as any)(targetEl, hostSet) : resolvedValue;\n\n if (action === 'set' || action === 'update') {\n if (attributeName) {\n // Case: @setAttribute(selector, 'name')\n if (resolvedRes === null || resolvedRes === undefined || resolvedRes === false) {\n targetEl.removeAttribute(attributeName);\n } else {\n targetEl.setAttribute(attributeName, resolvedRes === true ? '' : String(resolvedRes));\n }\n } else if (typeof resolvedRes === 'object' && resolvedRes !== null && !Array.isArray(resolvedRes)) {\n // Case: @applyAttribute(selector) with Object return\n Object.entries(resolvedRes as any).forEach(([attr, val]) => {\n const finalVal = typeof val === 'function' ? val(targetEl, hostSet) : val;\n if (finalVal === null || finalVal === undefined || finalVal === false) {\n targetEl.removeAttribute(attr);\n } else {\n targetEl.setAttribute(attr, finalVal === true ? '' : String(finalVal));\n }\n });\n }\n } else if (action === 'remove') {\n if (attributeName) {\n targetEl.removeAttribute(attributeName);\n } else if (typeof resolvedRes === 'object' && resolvedRes !== null && !Array.isArray(resolvedRes)) {\n Object.entries(resolvedRes as any).forEach(([attr, val]) => {\n const shouldRemove = typeof val === 'function' ? val(targetEl, hostSet) : !!val;\n if (shouldRemove) targetEl.removeAttribute(attr);\n });\n } else {\n const attrs = Array.isArray(resolvedRes) ? resolvedRes : [resolvedRes];\n attrs.forEach(a => targetEl.removeAttribute(String(a)));\n }\n }\n });\n }\n return resolvedValue;\n };\n\n if (res instanceof Promise) {\n return res.then(handleResult);\n } else {\n return handleResult(res);\n }\n };\n return descriptor;\n };\n };\n}\n\nexport function applyAttribute(selector: string, action: AttributeAction = 'update', options: AttributeApplyOptions = {}): MethodDecorator {\n return createAttributeDecorator(action)(selector, options);\n}\n\nexport const setAttribute = (selector: string, nameOrOptions?: string | AttributeApplyOptions, options: AttributeApplyOptions = {}) => createAttributeDecorator('set')(selector, nameOrOptions, options);\nexport const updateAttribute = (selector: string, nameOrOptions?: string | AttributeApplyOptions, options: AttributeApplyOptions = {}) => createAttributeDecorator('update')(selector, nameOrOptions, options);\nexport const removeAttribute = (selector: string, nameOrOptions?: string | AttributeApplyOptions, options: AttributeApplyOptions = {}) => createAttributeDecorator('remove')(selector, nameOrOptions, options);\n\n// This versions\nexport function applyAttributeThis(action: AttributeAction = 'update', options: AttributeApplyOptions = {}): MethodDecorator {\n return createAttributeDecorator(action)('$this', options);\n}\nexport const setAttributeThis = (nameOrOptions: string | AttributeApplyOptions, options: AttributeApplyOptions = {}) => createAttributeDecorator('set')('$this', nameOrOptions, options);\nexport const updateAttributeThis = (nameOrOptions: string | AttributeApplyOptions, options: AttributeApplyOptions = {}) => createAttributeDecorator('update')('$this', nameOrOptions, options);\nexport const removeAttributeThis = (nameOrOptions?: string | AttributeApplyOptions, options: AttributeApplyOptions = {}) => createAttributeDecorator('remove')('$this', nameOrOptions, options);\n\nexport const findAllAttributeApplyMetadata = (target: any): Map<string | symbol, AttributeApplyMetadata> => {\n const result = new Map<string | symbol, AttributeApplyMetadata>();\n const maps = ReflectUtils.findAllMetadata<Map<string | symbol, AttributeApplyMetadata>>(ATTRIBUTE_APPLY_METADATA_KEY, target);\n maps.forEach(map => {\n if (map instanceof Map) {\n map.forEach((v, k) => result.set(k, v));\n }\n });\n return result;\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA6B;AAC7B,2BAA2B;AAC3B,mBAAyB;AAiBlB,MAAM,+BAA+B,OAAO,IAAI,sCAAsC;AAE7F,SAAS,yBAAyB,QAAyB;AACzD,SAAO,CAAC,UAAkB,eAAgD,UAAiC,CAAC,MAAuB;AACjI,WAAO,CAAC,QAAgB,aAA8B,eAAmC;AACvF,YAAM,cAAc,OAAO;AAC3B,UAAI,WAAW,yBAAa,eAAe,8BAA8B,WAAW;AACpF,UAAI,CAAC,UAAU;AACb,mBAAW,oBAAI,IAA6C;AAC5D,iCAAa,eAAe,8BAA8B,UAAU,WAAW;AAAA,MACjF;AAEA,UAAI,gBAAgB,OAAO,kBAAkB,WAAW,gBAAgB;AACxE,UAAI,eAAe;AAEnB,UAAI,OAAO,kBAAkB,YAAY,kBAAkB,MAAM;AAC7D,uBAAe;AAAA,MACnB;AAEA,eAAS,IAAI,aAAa;AAAA,QACxB;AAAA,QACA;AAAA,QACA;AAAA,QACA,SAAS,EAAE,GAAG,cAAc,MAAM,cAAc;AAAA,MAClD,CAAC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AM,OAAO,yBAAa,gBAA8D,8BAA8B,MAAM;AAC5H,OAAK,QAAQ,SAAO;AAClB,QAAI,eAAe,KAAK;AACtB,UAAI,QAAQ,CAAC,GAAG,MAAM,OAAO,IAAI,GAAG,CAAC,CAAC;AAAA,IACxC;AAAA,EACF,CAAC;AACD,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -19,18 +19,18 @@ var applyClass_exports = {};
|
|
|
19
19
|
__export(applyClass_exports, {
|
|
20
20
|
CLASS_METADATA_KEY: () => CLASS_METADATA_KEY,
|
|
21
21
|
addClass: () => addClass,
|
|
22
|
-
|
|
22
|
+
addClassThis: () => addClassThis,
|
|
23
23
|
applyClass: () => applyClass,
|
|
24
|
-
|
|
24
|
+
applyClassThis: () => applyClassThis,
|
|
25
25
|
findAllClassMetadata: () => findAllClassMetadata,
|
|
26
26
|
removeClass: () => removeClass,
|
|
27
|
-
|
|
27
|
+
removeClassThis: () => removeClassThis,
|
|
28
28
|
setClass: () => setClass,
|
|
29
|
-
|
|
29
|
+
setClassThis: () => setClassThis,
|
|
30
30
|
toggleClass: () => toggleClass,
|
|
31
|
-
|
|
31
|
+
toggleClassThis: () => toggleClassThis,
|
|
32
32
|
updateClass: () => updateClass,
|
|
33
|
-
|
|
33
|
+
updateClassThis: () => updateClassThis
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(applyClass_exports);
|
|
36
36
|
var import_core = require("@dooboostore/core");
|
|
@@ -69,15 +69,16 @@ function createClassDecorator(action) {
|
|
|
69
69
|
if (!t || !(t instanceof win.HTMLElement)) return;
|
|
70
70
|
targetEls.push(t);
|
|
71
71
|
};
|
|
72
|
-
if (selector === "
|
|
73
|
-
else if (selector === "
|
|
74
|
-
else if (selector === "
|
|
75
|
-
else if (selector === "
|
|
76
|
-
else if (selector === "
|
|
77
|
-
else if (selector === "
|
|
78
|
-
else if (selector === "
|
|
79
|
-
else if (selector === "
|
|
80
|
-
else if (selector === "
|
|
72
|
+
if (selector === "$this" || !selector) applyRoot(host);
|
|
73
|
+
else if (selector === "$host") applyRoot(hostSet.$host);
|
|
74
|
+
else if (selector === "$parentHost") applyRoot(hostSet.$parentHost);
|
|
75
|
+
else if (selector === "$appHost") applyRoot(hostSet.$appHost);
|
|
76
|
+
else if (selector === "$firstHost") applyRoot(hostSet.$firstHost);
|
|
77
|
+
else if (selector === "$lastHost") applyRoot(hostSet.$lastHost);
|
|
78
|
+
else if (selector === "$firstAppHost") applyRoot(hostSet.$firstAppHost);
|
|
79
|
+
else if (selector === "$lastAppHost") applyRoot(hostSet.$lastAppHost);
|
|
80
|
+
else if (selector === "$hosts") hostSet.$hosts.forEach(applyRoot);
|
|
81
|
+
else if (selector === "$appHosts") hostSet.$appHosts.forEach(applyRoot);
|
|
81
82
|
else {
|
|
82
83
|
const targetRoot = r === "auto" ? host.shadowRoot || host : r === "shadow" ? host.shadowRoot : host;
|
|
83
84
|
if (targetRoot) {
|
|
@@ -153,14 +154,14 @@ const updateClass = (selector, classMapOrOptions, options = {}) => createClassDe
|
|
|
153
154
|
const addClass = (selector, classMapOrOptions, options = {}) => createClassDecorator("add")(selector, classMapOrOptions, options);
|
|
154
155
|
const removeClass = (selector, classMapOrOptions, options = {}) => createClassDecorator("remove")(selector, classMapOrOptions, options);
|
|
155
156
|
const toggleClass = (selector, classMapOrOptions, options = {}) => createClassDecorator("toggle")(selector, classMapOrOptions, options);
|
|
156
|
-
function
|
|
157
|
-
return createClassDecorator(action)("
|
|
157
|
+
function applyClassThis(action = "update", options = {}) {
|
|
158
|
+
return createClassDecorator(action)("$this", options);
|
|
158
159
|
}
|
|
159
|
-
const
|
|
160
|
-
const
|
|
161
|
-
const
|
|
162
|
-
const
|
|
163
|
-
const
|
|
160
|
+
const setClassThis = (classMapOrOptions, options = {}) => createClassDecorator("set")("$this", classMapOrOptions, options);
|
|
161
|
+
const updateClassThis = (classMapOrOptions, options = {}) => createClassDecorator("update")("$this", classMapOrOptions, options);
|
|
162
|
+
const addClassThis = (classMapOrOptions, options = {}) => createClassDecorator("add")("$this", classMapOrOptions, options);
|
|
163
|
+
const removeClassThis = (classMapOrOptions, options = {}) => createClassDecorator("remove")("$this", classMapOrOptions, options);
|
|
164
|
+
const toggleClassThis = (classMapOrOptions, options = {}) => createClassDecorator("toggle")("$this", classMapOrOptions, options);
|
|
164
165
|
const findAllClassMetadata = (target) => {
|
|
165
166
|
const result = /* @__PURE__ */ new Map();
|
|
166
167
|
const maps = import_core.ReflectUtils.findAllMetadata(CLASS_METADATA_KEY, target);
|