@dooboostore/simple-web-component 1.0.33 → 1.0.35
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 +23 -30
- package/dist/cjs/decorators/addEventListener.js.map +1 -1
- package/dist/cjs/decorators/applyAttribute.js +67 -57
- package/dist/cjs/decorators/applyAttribute.js.map +2 -2
- package/dist/cjs/decorators/applyClass.js +80 -70
- package/dist/cjs/decorators/applyClass.js.map +2 -2
- package/dist/cjs/decorators/applyNode.js +5 -8
- package/dist/cjs/decorators/applyNode.js.map +2 -2
- package/dist/cjs/decorators/applyStyle.js +66 -56
- package/dist/cjs/decorators/applyStyle.js.map +2 -2
- package/dist/cjs/decorators/attribute.js +35 -29
- package/dist/cjs/decorators/attribute.js.map +2 -2
- package/dist/cjs/decorators/changedAttributeHost.js +32 -12
- package/dist/cjs/decorators/changedAttributeHost.js.map +2 -2
- package/dist/cjs/decorators/elementDefine.js +238 -180
- package/dist/cjs/decorators/elementDefine.js.map +2 -2
- package/dist/cjs/decorators/emitCustomEvent.js +67 -48
- package/dist/cjs/decorators/emitCustomEvent.js.map +2 -2
- package/dist/cjs/decorators/lifecycles.js +15 -17
- package/dist/cjs/decorators/lifecycles.js.map +2 -2
- package/dist/cjs/decorators/setProperty.js +50 -39
- package/dist/cjs/decorators/setProperty.js.map +2 -2
- package/dist/cjs/decorators/subscribeSwcAppMessageWhileConnected.js.map +1 -1
- package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js +2 -2
- package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
- package/dist/cjs/elements/SwcAppEngine.js +14 -8
- package/dist/cjs/elements/SwcAppEngine.js.map +3 -3
- package/dist/cjs/elements/SwcAppMixin.js +154 -81
- package/dist/cjs/elements/SwcAppMixin.js.map +2 -2
- package/dist/cjs/elements/SwcAsync.js +28 -18
- package/dist/cjs/elements/SwcAsync.js.map +2 -2
- package/dist/cjs/elements/SwcChoose.js +68 -45
- package/dist/cjs/elements/SwcChoose.js.map +2 -2
- package/dist/cjs/elements/SwcIf.js +52 -30
- package/dist/cjs/elements/SwcIf.js.map +2 -2
- package/dist/cjs/elements/SwcLoop.js +109 -35
- package/dist/cjs/elements/SwcLoop.js.map +2 -2
- package/dist/cjs/elements/register.js +263 -131
- 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 +25 -7
- package/dist/cjs/utils/Utils.js.map +2 -2
- package/dist/esm/decorators/addEventListener.js.map +1 -1
- package/dist/esm/decorators/applyAttribute.js +67 -57
- package/dist/esm/decorators/applyAttribute.js.map +2 -2
- package/dist/esm/decorators/applyClass.js +80 -70
- package/dist/esm/decorators/applyClass.js.map +2 -2
- package/dist/esm/decorators/applyNode.js +5 -8
- package/dist/esm/decorators/applyNode.js.map +2 -2
- package/dist/esm/decorators/applyStyle.js +66 -56
- package/dist/esm/decorators/applyStyle.js.map +2 -2
- package/dist/esm/decorators/attribute.js +35 -29
- package/dist/esm/decorators/attribute.js.map +2 -2
- package/dist/esm/decorators/changedAttributeHost.js +32 -12
- package/dist/esm/decorators/changedAttributeHost.js.map +2 -2
- package/dist/esm/decorators/elementDefine.js +240 -182
- package/dist/esm/decorators/elementDefine.js.map +2 -2
- package/dist/esm/decorators/emitCustomEvent.js +67 -48
- package/dist/esm/decorators/emitCustomEvent.js.map +2 -2
- package/dist/esm/decorators/lifecycles.js +15 -17
- package/dist/esm/decorators/lifecycles.js.map +2 -2
- package/dist/esm/decorators/setProperty.js +50 -39
- package/dist/esm/decorators/setProperty.js.map +2 -2
- package/dist/esm/decorators/subscribeSwcAppMessageWhileConnected.js.map +1 -1
- package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js +2 -2
- package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
- package/dist/esm/elements/SwcAppEngine.js +14 -7
- package/dist/esm/elements/SwcAppEngine.js.map +2 -2
- package/dist/esm/elements/SwcAppMixin.js +156 -82
- package/dist/esm/elements/SwcAppMixin.js.map +2 -2
- package/dist/esm/elements/SwcAsync.js +28 -18
- package/dist/esm/elements/SwcAsync.js.map +2 -2
- package/dist/esm/elements/SwcChoose.js +69 -46
- package/dist/esm/elements/SwcChoose.js.map +2 -2
- package/dist/esm/elements/SwcIf.js +53 -31
- package/dist/esm/elements/SwcIf.js.map +2 -2
- package/dist/esm/elements/SwcLoop.js +110 -36
- package/dist/esm/elements/SwcLoop.js.map +2 -2
- package/dist/esm/elements/register.js +264 -132
- 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 +25 -7
- package/dist/esm/utils/Utils.js.map +2 -2
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +728 -595
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
- package/dist/types/decorators/addEventListener.d.ts +4 -1
- package/dist/types/decorators/addEventListener.d.ts.map +1 -1
- package/dist/types/decorators/applyAttribute.d.ts +5 -1
- package/dist/types/decorators/applyAttribute.d.ts.map +1 -1
- package/dist/types/decorators/applyClass.d.ts +4 -0
- package/dist/types/decorators/applyClass.d.ts.map +1 -1
- package/dist/types/decorators/applyNode.d.ts +5 -1
- package/dist/types/decorators/applyNode.d.ts.map +1 -1
- package/dist/types/decorators/applyStyle.d.ts +5 -1
- package/dist/types/decorators/applyStyle.d.ts.map +1 -1
- package/dist/types/decorators/attribute.d.ts +5 -0
- package/dist/types/decorators/attribute.d.ts.map +1 -1
- package/dist/types/decorators/changedAttributeHost.d.ts +14 -3
- package/dist/types/decorators/changedAttributeHost.d.ts.map +1 -1
- package/dist/types/decorators/elementDefine.d.ts +1 -1
- package/dist/types/decorators/elementDefine.d.ts.map +1 -1
- package/dist/types/decorators/emitCustomEvent.d.ts +15 -7
- package/dist/types/decorators/emitCustomEvent.d.ts.map +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/setProperty.d.ts +5 -1
- package/dist/types/decorators/setProperty.d.ts.map +1 -1
- package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts +2 -2
- package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts.map +1 -1
- package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts +5 -6
- package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts.map +1 -1
- package/dist/types/elements/SwcAppEngine.d.ts +9 -3
- package/dist/types/elements/SwcAppEngine.d.ts.map +1 -1
- package/dist/types/elements/SwcAppMixin.d.ts +12 -7
- 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 +1 -0
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils/Utils.d.ts +4 -1
- package/dist/types/utils/Utils.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +728 -595
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +5 -5
- package/src/decorators/addEventListener.ts +1 -1
- package/src/decorators/applyAttribute.ts +74 -61
- package/src/decorators/applyClass.ts +91 -77
- package/src/decorators/applyNode.ts +16 -13
- package/src/decorators/applyStyle.ts +75 -61
- package/src/decorators/attribute.ts +55 -43
- package/src/decorators/changedAttributeHost.ts +49 -15
- package/src/decorators/elementDefine.ts +401 -340
- package/src/decorators/emitCustomEvent.ts +92 -62
- package/src/decorators/lifecycles.ts +11 -10
- package/src/decorators/setProperty.ts +58 -44
- package/src/decorators/subscribeSwcAppMessageWhileConnected.ts +2 -2
- package/src/decorators/subscribeSwcAppRouteChangeWhileConnected.ts +11 -11
- package/src/elements/SwcAppEngine.ts +19 -13
- package/src/elements/SwcAppMixin.ts +214 -102
- package/src/elements/SwcAsync.ts +28 -17
- package/src/elements/SwcChoose.ts +94 -36
- package/src/elements/SwcIf.ts +59 -22
- package/src/elements/SwcLoop.ts +140 -27
- package/src/elements/register.ts +319 -100
- package/src/types.ts +1 -0
- package/src/utils/Utils.ts +38 -10
- package/tsconfig.json +2 -2
package/README.md
CHANGED
|
@@ -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
|
|
@@ -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
|
}
|
|
@@ -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
|
---
|
|
@@ -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, 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 * @addEventListenerHost decorator - simplified version of @addEventListener for :host selector\n * Usage: @addEventListenerHost('click')\n * Usage: @addEventListenerHost('click', { stopPropagation: true })\n */\nexport function addEventListenerHost(type: string, options?: AddEventListenerBaseOptions & SwcQueryOptions): MethodDecorator {\n return addEventListener(':host', type, options);\n}\n\n/**\n * @addEventListenerAppHost decorator - simplified version of @addEventListener for :appHost selector\n * Usage: @addEventListenerAppHost('click')\n * Usage: @addEventListenerAppHost('click', { stopPropagation: true })\n */\nexport function addEventListenerAppHost(type: string, options?: AddEventListenerBaseOptions & SwcQueryOptions): MethodDecorator {\n return addEventListener(':appHost', type, options);\n}\n"],
|
|
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 * @addEventListenerHost decorator - simplified version of @addEventListener for :host selector\n * Usage: @addEventListenerHost('click')\n * Usage: @addEventListenerHost('click', { stopPropagation: true })\n */\nexport function addEventListenerHost(type: string, options?: AddEventListenerBaseOptions & SwcQueryOptions): MethodDecorator {\n return addEventListener(':host', type, options);\n}\n\n/**\n * @addEventListenerAppHost decorator - simplified version of @addEventListener for :appHost selector\n * Usage: @addEventListenerAppHost('click')\n * Usage: @addEventListenerAppHost('click', { stopPropagation: true })\n */\nexport function addEventListenerAppHost(type: string, options?: AddEventListenerBaseOptions & SwcQueryOptions): MethodDecorator {\n return addEventListener(':appHost', type, options);\n}\n"],
|
|
5
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;AAOO,SAAS,qBAAqB,MAAc,SAA0E;AAC3H,SAAO,iBAAiB,SAAS,MAAM,OAAO;AAChD;AAOO,SAAS,wBAAwB,MAAc,SAA0E;AAC9H,SAAO,iBAAiB,YAAY,MAAM,OAAO;AACnD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -54,70 +54,80 @@ function createAttributeDecorator(action) {
|
|
|
54
54
|
options: { ...finalOptions, name: attributeName }
|
|
55
55
|
});
|
|
56
56
|
const original = descriptor.value;
|
|
57
|
-
descriptor.value =
|
|
57
|
+
descriptor.value = function(...args) {
|
|
58
58
|
(0, import_elementDefine.ensureInit)(this);
|
|
59
|
-
const res =
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
59
|
+
const res = original.apply(this, args);
|
|
60
|
+
const handleResult = (resolvedValue) => {
|
|
61
|
+
if (resolvedValue !== void 0) {
|
|
62
|
+
const win = this.ownerDocument?.defaultView || window;
|
|
63
|
+
const host = this;
|
|
64
|
+
const hostSet = { ...import_Utils.SwcUtils.getHelperAndHostSet(win, host), $this: this };
|
|
65
|
+
const r = finalOptions.root || "auto";
|
|
66
|
+
const targetEls = [];
|
|
67
|
+
const applyRoot = (t) => {
|
|
68
|
+
if (!t || !(t instanceof win.HTMLElement)) return;
|
|
69
|
+
targetEls.push(t);
|
|
70
|
+
};
|
|
71
|
+
if (selector === ":parentHost") applyRoot(hostSet.$parentHost);
|
|
72
|
+
else if (selector === ":appHost") applyRoot(hostSet.$appHost);
|
|
73
|
+
else if (selector === ":firstHost") applyRoot(hostSet.$firstHost);
|
|
74
|
+
else if (selector === ":lastHost") applyRoot(hostSet.$lastHost);
|
|
75
|
+
else if (selector === ":firstAppHost") applyRoot(hostSet.$firstAppHost);
|
|
76
|
+
else if (selector === ":lastAppHost") applyRoot(hostSet.$lastAppHost);
|
|
77
|
+
else if (selector === ":hosts") hostSet.$hosts.forEach(applyRoot);
|
|
78
|
+
else if (selector === ":appHosts") hostSet.$appHosts.forEach(applyRoot);
|
|
79
|
+
else if (selector === ":host" || !selector) applyRoot(host);
|
|
80
|
+
else {
|
|
81
|
+
const targetRoot = r === "auto" ? host.shadowRoot || host : r === "shadow" ? host.shadowRoot : host;
|
|
82
|
+
if (targetRoot) {
|
|
83
|
+
const found = targetRoot.querySelectorAll(selector);
|
|
84
|
+
if (found) targetEls.push(...Array.from(found));
|
|
85
|
+
}
|
|
84
86
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
87
|
+
targetEls.forEach((targetEl) => {
|
|
88
|
+
if (finalOptions.filter && !finalOptions.filter(targetEl, resolvedValue, { currentThis: this, helper: hostSet })) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const resolvedRes = typeof resolvedValue === "function" ? resolvedValue(targetEl, hostSet) : resolvedValue;
|
|
92
|
+
if (action === "set" || action === "update") {
|
|
93
|
+
if (attributeName) {
|
|
94
|
+
if (resolvedRes === null || resolvedRes === void 0 || resolvedRes === false) {
|
|
95
|
+
targetEl.removeAttribute(attributeName);
|
|
96
|
+
} else {
|
|
97
|
+
targetEl.setAttribute(attributeName, resolvedRes === true ? "" : String(resolvedRes));
|
|
98
|
+
}
|
|
99
|
+
} else if (typeof resolvedRes === "object" && resolvedRes !== null && !Array.isArray(resolvedRes)) {
|
|
100
|
+
Object.entries(resolvedRes).forEach(([attr, val]) => {
|
|
101
|
+
const finalVal = typeof val === "function" ? val(targetEl, hostSet) : val;
|
|
102
|
+
if (finalVal === null || finalVal === void 0 || finalVal === false) {
|
|
103
|
+
targetEl.removeAttribute(attr);
|
|
104
|
+
} else {
|
|
105
|
+
targetEl.setAttribute(attr, finalVal === true ? "" : String(finalVal));
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
} else if (action === "remove") {
|
|
110
|
+
if (attributeName) {
|
|
91
111
|
targetEl.removeAttribute(attributeName);
|
|
112
|
+
} else if (typeof resolvedRes === "object" && resolvedRes !== null && !Array.isArray(resolvedRes)) {
|
|
113
|
+
Object.entries(resolvedRes).forEach(([attr, val]) => {
|
|
114
|
+
const shouldRemove = typeof val === "function" ? val(targetEl, hostSet) : !!val;
|
|
115
|
+
if (shouldRemove) targetEl.removeAttribute(attr);
|
|
116
|
+
});
|
|
92
117
|
} else {
|
|
93
|
-
|
|
118
|
+
const attrs = Array.isArray(resolvedRes) ? resolvedRes : [resolvedRes];
|
|
119
|
+
attrs.forEach((a) => targetEl.removeAttribute(String(a)));
|
|
94
120
|
}
|
|
95
|
-
} else if (typeof resolvedRes === "object" && resolvedRes !== null && !Array.isArray(resolvedRes)) {
|
|
96
|
-
Object.entries(resolvedRes).forEach(([attr, val]) => {
|
|
97
|
-
const finalVal = typeof val === "function" ? val(targetEl, hostSet) : val;
|
|
98
|
-
if (finalVal === null || finalVal === void 0 || finalVal === false) {
|
|
99
|
-
targetEl.removeAttribute(attr);
|
|
100
|
-
} else {
|
|
101
|
-
targetEl.setAttribute(attr, finalVal === true ? "" : String(finalVal));
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
} else if (action === "remove") {
|
|
106
|
-
if (attributeName) {
|
|
107
|
-
targetEl.removeAttribute(attributeName);
|
|
108
|
-
} else if (typeof resolvedRes === "object" && resolvedRes !== null && !Array.isArray(resolvedRes)) {
|
|
109
|
-
Object.entries(resolvedRes).forEach(([attr, val]) => {
|
|
110
|
-
const shouldRemove = typeof val === "function" ? val(targetEl, hostSet) : !!val;
|
|
111
|
-
if (shouldRemove) targetEl.removeAttribute(attr);
|
|
112
|
-
});
|
|
113
|
-
} else {
|
|
114
|
-
const attrs = Array.isArray(resolvedRes) ? resolvedRes : [resolvedRes];
|
|
115
|
-
attrs.forEach((a) => targetEl.removeAttribute(String(a)));
|
|
116
121
|
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
return resolvedValue;
|
|
125
|
+
};
|
|
126
|
+
if (res instanceof Promise) {
|
|
127
|
+
return res.then(handleResult);
|
|
128
|
+
} else {
|
|
129
|
+
return handleResult(res);
|
|
119
130
|
}
|
|
120
|
-
return res;
|
|
121
131
|
};
|
|
122
132
|
return descriptor;
|
|
123
133
|
};
|
|
@@ -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}\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 =
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA6B;AAC7B,2BAA2B;AAC3B,mBAAyB;
|
|
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 === ':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 if (selector === ':host' || !selector) applyRoot(host);\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// Host versions\nexport function applyAttributeHost(action: AttributeAction = 'update', options: AttributeApplyOptions = {}): MethodDecorator {\n return createAttributeDecorator(action)(':host', options);\n}\nexport const setAttributeHost = (nameOrOptions: string | AttributeApplyOptions, options: AttributeApplyOptions = {}) => createAttributeDecorator('set')(':host', nameOrOptions, options);\nexport const updateAttributeHost = (nameOrOptions: string | AttributeApplyOptions, options: AttributeApplyOptions = {}) => createAttributeDecorator('update')(':host', nameOrOptions, options);\nexport const removeAttributeHost = (nameOrOptions?: string | AttributeApplyOptions, options: AttributeApplyOptions = {}) => createAttributeDecorator('remove')(':host', 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;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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
7
7
|
}
|
|
@@ -55,81 +55,91 @@ function createClassDecorator(action) {
|
|
|
55
55
|
}
|
|
56
56
|
metaList.set(propertyKey, { propertyKey, selector, action, options: finalOptions });
|
|
57
57
|
const original = descriptor.value;
|
|
58
|
-
descriptor.value =
|
|
58
|
+
descriptor.value = function(...args) {
|
|
59
59
|
(0, import_elementDefine.ensureInit)(this);
|
|
60
|
-
const res =
|
|
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
|
-
targetEls.forEach((targetEl) => {
|
|
88
|
-
const resolvedRes = typeof res === "function" ? res(targetEl, hostSet) : res;
|
|
89
|
-
if (action === "set") {
|
|
90
|
-
let classes = "";
|
|
91
|
-
if (classMap && typeof classMap === "string") {
|
|
92
|
-
classes = resolvedRes ? classMap : "";
|
|
93
|
-
} else if (typeof resolvedRes === "object" && resolvedRes !== null && !Array.isArray(resolvedRes)) {
|
|
94
|
-
classes = Object.entries(resolvedRes).filter(([_, force]) => typeof force === "function" ? force(targetEl, hostSet) : !!force).map(([cls]) => cls).join(" ");
|
|
95
|
-
} else {
|
|
96
|
-
classes = Array.isArray(resolvedRes) ? resolvedRes.join(" ") : String(resolvedRes);
|
|
60
|
+
const res = original.apply(this, args);
|
|
61
|
+
const handleResult = (resolvedValue) => {
|
|
62
|
+
if (resolvedValue !== void 0) {
|
|
63
|
+
const win = this.ownerDocument?.defaultView || window;
|
|
64
|
+
const host = this;
|
|
65
|
+
const hostSet = { ...import_Utils.SwcUtils.getHelperAndHostSet(win, host), $this: this };
|
|
66
|
+
const r = finalOptions.root || "auto";
|
|
67
|
+
const targetEls = [];
|
|
68
|
+
const applyRoot = (t) => {
|
|
69
|
+
if (!t || !(t instanceof win.HTMLElement)) return;
|
|
70
|
+
targetEls.push(t);
|
|
71
|
+
};
|
|
72
|
+
if (selector === ":parentHost") applyRoot(hostSet.$parentHost);
|
|
73
|
+
else if (selector === ":appHost") applyRoot(hostSet.$appHost);
|
|
74
|
+
else if (selector === ":firstHost") applyRoot(hostSet.$firstHost);
|
|
75
|
+
else if (selector === ":lastHost") applyRoot(hostSet.$lastHost);
|
|
76
|
+
else if (selector === ":firstAppHost") applyRoot(hostSet.$firstAppHost);
|
|
77
|
+
else if (selector === ":lastAppHost") applyRoot(hostSet.$lastAppHost);
|
|
78
|
+
else if (selector === ":hosts") hostSet.$hosts.forEach(applyRoot);
|
|
79
|
+
else if (selector === ":appHosts") hostSet.$appHosts.forEach(applyRoot);
|
|
80
|
+
else if (selector === ":host" || !selector) applyRoot(host);
|
|
81
|
+
else {
|
|
82
|
+
const targetRoot = r === "auto" ? host.shadowRoot || host : r === "shadow" ? host.shadowRoot : host;
|
|
83
|
+
if (targetRoot) {
|
|
84
|
+
const found = targetRoot.querySelectorAll(selector);
|
|
85
|
+
if (found) targetEls.push(...Array.from(found));
|
|
97
86
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
if (
|
|
101
|
-
|
|
102
|
-
} else if (typeof resolvedRes === "object" && resolvedRes !== null && !Array.isArray(resolvedRes)) {
|
|
103
|
-
Object.entries(resolvedRes).forEach(([cls, force]) => {
|
|
104
|
-
const isActive = typeof force === "function" ? force(targetEl, hostSet) : !!force;
|
|
105
|
-
targetEl.classList.toggle(cls, isActive);
|
|
106
|
-
});
|
|
107
|
-
} else {
|
|
108
|
-
const classes = Array.isArray(resolvedRes) ? resolvedRes.map(String) : [String(resolvedRes)];
|
|
109
|
-
if (action === "update") targetEl.classList.add(...classes);
|
|
110
|
-
else classes.forEach((c) => targetEl.classList.toggle(c));
|
|
87
|
+
}
|
|
88
|
+
targetEls.forEach((targetEl) => {
|
|
89
|
+
if (finalOptions.filter && !finalOptions.filter(targetEl, resolvedValue, { currentThis: this, helper: hostSet })) {
|
|
90
|
+
return;
|
|
111
91
|
}
|
|
112
|
-
|
|
113
|
-
if (
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
if (
|
|
127
|
-
|
|
92
|
+
const resolvedRes = typeof resolvedValue === "function" ? resolvedValue(targetEl, hostSet) : resolvedValue;
|
|
93
|
+
if (action === "set") {
|
|
94
|
+
let classes = "";
|
|
95
|
+
if (classMap && typeof classMap === "string") {
|
|
96
|
+
classes = resolvedRes ? classMap : "";
|
|
97
|
+
} else if (typeof resolvedRes === "object" && resolvedRes !== null && !Array.isArray(resolvedRes)) {
|
|
98
|
+
classes = Object.entries(resolvedRes).filter(([_, force]) => typeof force === "function" ? force(targetEl, hostSet) : !!force).map(([cls]) => cls).join(" ");
|
|
99
|
+
} else {
|
|
100
|
+
classes = Array.isArray(resolvedRes) ? resolvedRes.join(" ") : String(resolvedRes);
|
|
101
|
+
}
|
|
102
|
+
targetEl.className = classes;
|
|
103
|
+
} else if (action === "update" || action === "toggle") {
|
|
104
|
+
if (classMap && typeof classMap === "string") {
|
|
105
|
+
targetEl.classList.toggle(classMap, !!resolvedRes);
|
|
106
|
+
} else if (typeof resolvedRes === "object" && resolvedRes !== null && !Array.isArray(resolvedRes)) {
|
|
107
|
+
Object.entries(resolvedRes).forEach(([cls, force]) => {
|
|
108
|
+
const isActive = typeof force === "function" ? force(targetEl, hostSet) : !!force;
|
|
109
|
+
targetEl.classList.toggle(cls, isActive);
|
|
110
|
+
});
|
|
111
|
+
} else {
|
|
112
|
+
const classes = Array.isArray(resolvedRes) ? resolvedRes.map(String) : [String(resolvedRes)];
|
|
113
|
+
if (action === "update") targetEl.classList.add(...classes);
|
|
114
|
+
else classes.forEach((c) => targetEl.classList.toggle(c));
|
|
115
|
+
}
|
|
116
|
+
} else if (action === "add" || action === "remove") {
|
|
117
|
+
if (classMap && typeof classMap === "string" && !!resolvedRes) {
|
|
118
|
+
if (action === "add") targetEl.classList.add(classMap);
|
|
119
|
+
else targetEl.classList.remove(classMap);
|
|
120
|
+
} else if (typeof resolvedRes === "object" && resolvedRes !== null && !Array.isArray(resolvedRes)) {
|
|
121
|
+
Object.entries(resolvedRes).forEach(([cls, force]) => {
|
|
122
|
+
const shouldExecute = typeof force === "function" ? force(targetEl, hostSet) : !!force;
|
|
123
|
+
if (shouldExecute) {
|
|
124
|
+
if (action === "add") targetEl.classList.add(cls);
|
|
125
|
+
else targetEl.classList.remove(cls);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
} else {
|
|
129
|
+
const classes = Array.isArray(resolvedRes) ? resolvedRes.map(String) : [String(resolvedRes)];
|
|
130
|
+
if (action === "add") targetEl.classList.add(...classes);
|
|
131
|
+
else targetEl.classList.remove(...classes);
|
|
132
|
+
}
|
|
128
133
|
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
return resolvedValue;
|
|
137
|
+
};
|
|
138
|
+
if (res instanceof Promise) {
|
|
139
|
+
return res.then(handleResult);
|
|
140
|
+
} else {
|
|
141
|
+
return handleResult(res);
|
|
131
142
|
}
|
|
132
|
-
return res;
|
|
133
143
|
};
|
|
134
144
|
return descriptor;
|
|
135
145
|
};
|