@dooboostore/simple-web-component 1.0.43 → 1.0.44
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 +298 -49
- package/dist/cjs/SwcAppEngine.js +3 -1
- package/dist/cjs/SwcAppEngine.js.map +2 -2
- package/dist/cjs/decorators/addEventListener.js.map +2 -2
- package/dist/cjs/decorators/applyAttribute.js +30 -28
- package/dist/cjs/decorators/applyAttribute.js.map +2 -2
- package/dist/cjs/decorators/applyClass.js +57 -21
- package/dist/cjs/decorators/applyClass.js.map +3 -3
- package/dist/cjs/decorators/applyNode.js +165 -105
- package/dist/cjs/decorators/applyNode.js.map +2 -2
- package/dist/cjs/decorators/applyProperty.js +11 -28
- package/dist/cjs/decorators/applyProperty.js.map +2 -2
- package/dist/cjs/decorators/applyStyle.js +39 -15
- package/dist/cjs/decorators/applyStyle.js.map +3 -3
- package/dist/cjs/decorators/{changedAttributeThis.js → changedAttribute.js} +6 -6
- package/dist/cjs/decorators/changedAttribute.js.map +7 -0
- package/dist/cjs/decorators/elementDefine.js +37 -6
- package/dist/cjs/decorators/elementDefine.js.map +3 -3
- package/dist/cjs/decorators/emitCustomEvent.js +56 -42
- package/dist/cjs/decorators/emitCustomEvent.js.map +2 -2
- package/dist/cjs/decorators/index.js +1 -1
- package/dist/cjs/decorators/index.js.map +2 -2
- package/dist/cjs/decorators/publishSwcAppMessage.js +5 -5
- package/dist/cjs/decorators/publishSwcAppMessage.js.map +3 -3
- package/dist/cjs/decorators/query.js +96 -145
- package/dist/cjs/decorators/query.js.map +3 -3
- package/dist/cjs/decorators/queryAll.js +104 -131
- package/dist/cjs/decorators/queryAll.js.map +3 -3
- package/dist/cjs/decorators/subscribeSwcAppMessageWhileConnected.js +2 -0
- package/dist/cjs/decorators/subscribeSwcAppMessageWhileConnected.js.map +2 -2
- package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js +2 -0
- package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
- package/dist/cjs/elements/SwcAppMixin.js +17 -2
- package/dist/cjs/elements/SwcAppMixin.js.map +2 -2
- package/dist/cjs/examples/RxJSOperatorsExample.js +285 -0
- package/dist/cjs/examples/RxJSOperatorsExample.js.map +7 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/router/ElementRouter.js +4 -0
- package/dist/cjs/router/ElementRouter.js.map +2 -2
- package/dist/esm/SwcAppEngine.js +3 -1
- package/dist/esm/SwcAppEngine.js.map +2 -2
- package/dist/esm/decorators/addEventListener.js.map +2 -2
- package/dist/esm/decorators/applyAttribute.js +30 -28
- package/dist/esm/decorators/applyAttribute.js.map +2 -2
- package/dist/esm/decorators/applyClass.js +57 -21
- package/dist/esm/decorators/applyClass.js.map +3 -3
- package/dist/esm/decorators/applyNode.js +165 -105
- package/dist/esm/decorators/applyNode.js.map +2 -2
- package/dist/esm/decorators/applyProperty.js +11 -28
- package/dist/esm/decorators/applyProperty.js.map +2 -2
- package/dist/esm/decorators/applyStyle.js +39 -15
- package/dist/esm/decorators/applyStyle.js.map +3 -3
- package/dist/esm/decorators/{changedAttributeThis.js → changedAttribute.js} +3 -3
- package/dist/esm/decorators/changedAttribute.js.map +7 -0
- package/dist/esm/decorators/elementDefine.js +35 -4
- package/dist/esm/decorators/elementDefine.js.map +2 -2
- package/dist/esm/decorators/emitCustomEvent.js +56 -42
- 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/publishSwcAppMessage.js +5 -5
- package/dist/esm/decorators/publishSwcAppMessage.js.map +3 -3
- package/dist/esm/decorators/query.js +96 -145
- package/dist/esm/decorators/query.js.map +3 -3
- package/dist/esm/decorators/queryAll.js +104 -131
- package/dist/esm/decorators/queryAll.js.map +3 -3
- package/dist/esm/decorators/subscribeSwcAppMessageWhileConnected.js +2 -0
- package/dist/esm/decorators/subscribeSwcAppMessageWhileConnected.js.map +2 -2
- package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js +2 -0
- package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
- package/dist/esm/elements/SwcAppMixin.js +18 -3
- package/dist/esm/elements/SwcAppMixin.js.map +2 -2
- package/dist/esm/examples/RxJSOperatorsExample.js +266 -0
- package/dist/esm/examples/RxJSOperatorsExample.js.map +7 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/router/ElementRouter.js +4 -0
- package/dist/esm/router/ElementRouter.js.map +2 -2
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +759 -512
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
- package/dist/types/SwcAppEngine.d.ts.map +1 -1
- package/dist/types/decorators/addEventListener.d.ts +17 -14
- package/dist/types/decorators/addEventListener.d.ts.map +1 -1
- package/dist/types/decorators/applyAttribute.d.ts +35 -20
- package/dist/types/decorators/applyAttribute.d.ts.map +1 -1
- package/dist/types/decorators/applyClass.d.ts +16 -36
- package/dist/types/decorators/applyClass.d.ts.map +1 -1
- package/dist/types/decorators/applyNode.d.ts +172 -30
- package/dist/types/decorators/applyNode.d.ts.map +1 -1
- package/dist/types/decorators/applyProperty.d.ts +27 -18
- package/dist/types/decorators/applyProperty.d.ts.map +1 -1
- package/dist/types/decorators/applyStyle.d.ts +7 -7
- package/dist/types/decorators/applyStyle.d.ts.map +1 -1
- package/dist/types/decorators/{changedAttributeThis.d.ts → changedAttribute.d.ts} +2 -2
- package/dist/types/decorators/changedAttribute.d.ts.map +1 -0
- package/dist/types/decorators/elementDefine.d.ts.map +1 -1
- package/dist/types/decorators/emitCustomEvent.d.ts +3 -10
- package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
- package/dist/types/decorators/index.d.ts +1 -1
- package/dist/types/decorators/index.d.ts.map +1 -1
- package/dist/types/decorators/publishSwcAppMessage.d.ts +1 -1
- package/dist/types/decorators/publishSwcAppMessage.d.ts.map +1 -1
- package/dist/types/decorators/query.d.ts +3 -26
- package/dist/types/decorators/query.d.ts.map +1 -1
- package/dist/types/decorators/queryAll.d.ts +3 -20
- package/dist/types/decorators/queryAll.d.ts.map +1 -1
- package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts +1 -0
- package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts.map +1 -1
- package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts +2 -0
- package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts.map +1 -1
- package/dist/types/elements/SwcAppMixin.d.ts +4 -4
- package/dist/types/elements/SwcAppMixin.d.ts.map +1 -1
- package/dist/types/examples/RxJSOperatorsExample.d.ts +94 -0
- package/dist/types/examples/RxJSOperatorsExample.d.ts.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/router/ElementRouter.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +759 -512
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +3 -3
- package/src/SwcAppEngine.ts +3 -1
- package/src/decorators/addEventListener.ts +28 -24
- package/src/decorators/applyAttribute.ts +109 -63
- package/src/decorators/applyClass.ts +89 -15
- package/src/decorators/applyNode.ts +357 -100
- package/src/decorators/applyProperty.ts +42 -63
- package/src/decorators/applyStyle.ts +59 -11
- package/src/decorators/{changedAttributeThis.ts → changedAttribute.ts} +1 -1
- package/src/decorators/elementDefine.ts +47 -4
- package/src/decorators/emitCustomEvent.ts +44 -36
- package/src/decorators/index.ts +1 -1
- package/src/decorators/publishSwcAppMessage.ts +1 -1
- package/src/decorators/query.ts +90 -159
- package/src/decorators/queryAll.ts +92 -134
- package/src/decorators/subscribeSwcAppMessageWhileConnected.ts +1 -0
- package/src/decorators/subscribeSwcAppRouteChangeWhileConnected.ts +3 -1
- package/src/elements/SwcAppMixin.ts +43 -24
- package/src/examples/RxJSOperatorsExample.ts +279 -0
- package/src/index.ts +2 -0
- package/src/router/ElementRouter.ts +4 -0
- package/dist/cjs/decorators/changedAttributeThis.js.map +0 -7
- package/dist/esm/decorators/changedAttributeThis.js.map +0 -7
- package/dist/types/decorators/changedAttributeThis.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -452,33 +452,168 @@ printTag() {
|
|
|
452
452
|
|
|
453
453
|
### 6. **Attribute Binding**
|
|
454
454
|
|
|
455
|
-
#### @attribute
|
|
456
|
-
Bind HTML attributes to properties
|
|
455
|
+
#### @attribute (Field Decorator)
|
|
456
|
+
Bind HTML attributes to properties with automatic read/write synchronization.
|
|
457
|
+
|
|
458
|
+
Intelligently distinguishes between attribute names and CSS selectors:
|
|
457
459
|
|
|
458
460
|
```typescript
|
|
459
|
-
@
|
|
460
|
-
|
|
461
|
+
@elementDefine('product-card')
|
|
462
|
+
class ProductCard extends HTMLElement {
|
|
463
|
+
// Attribute name on $this (auto-detected)
|
|
464
|
+
@attribute('product-id')
|
|
465
|
+
productId: string;
|
|
466
|
+
|
|
467
|
+
// Attribute name on selector
|
|
468
|
+
@attribute('#user', 'data-id')
|
|
469
|
+
userId: string;
|
|
470
|
+
|
|
471
|
+
// Bare decorator (uses field name as attribute)
|
|
472
|
+
@attribute
|
|
473
|
+
title: string;
|
|
461
474
|
|
|
462
|
-
@
|
|
463
|
-
|
|
475
|
+
@onInitialize
|
|
476
|
+
onconstructor() {
|
|
477
|
+
if (this.productId) {
|
|
478
|
+
this.loadProduct(this.productId);
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
464
482
|
```
|
|
465
483
|
|
|
466
|
-
#### @
|
|
467
|
-
|
|
484
|
+
#### @setAttribute (Method Decorator)
|
|
485
|
+
Set element attributes from method return values.
|
|
468
486
|
|
|
469
487
|
```typescript
|
|
470
|
-
@
|
|
471
|
-
|
|
488
|
+
@elementDefine('status-updater')
|
|
489
|
+
class StatusUpdater extends HTMLElement {
|
|
490
|
+
// Set attribute on $this
|
|
491
|
+
@setAttribute('data-status')
|
|
492
|
+
updateStatus() {
|
|
493
|
+
return this.isActive ? 'active' : 'inactive';
|
|
494
|
+
}
|
|
472
495
|
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
this.
|
|
496
|
+
// Set attribute on selector
|
|
497
|
+
@setAttribute('#user', 'data-name')
|
|
498
|
+
setUserName() {
|
|
499
|
+
return this.userName;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
// Bare decorator (uses method name as attribute)
|
|
503
|
+
@setAttribute
|
|
504
|
+
setValue() {
|
|
505
|
+
return this.computedValue;
|
|
477
506
|
}
|
|
478
507
|
}
|
|
479
508
|
```
|
|
480
509
|
|
|
481
|
-
|
|
510
|
+
**Usage Patterns:**
|
|
511
|
+
- `@attribute('attr-name')` - Attribute name on $this (auto-detected)
|
|
512
|
+
- `@attribute('#selector', 'attr-name')` - Attribute name on selector
|
|
513
|
+
- `@attribute('attr-name', options)` - Attribute name on $this with options
|
|
514
|
+
- `@attribute('#selector', 'attr-name', options)` - Attribute name on selector with options
|
|
515
|
+
- `@attribute` - Bare decorator (uses field name as attribute on $this)
|
|
516
|
+
|
|
517
|
+
**@setAttribute Patterns:**
|
|
518
|
+
- `@setAttribute('attr-name')` - Set attribute on $this
|
|
519
|
+
- `@setAttribute('#selector', 'attr-name')` - Set attribute on selector
|
|
520
|
+
- `@setAttribute('attr-name', options)` - Set attribute on $this with options
|
|
521
|
+
- `@setAttribute('#selector', 'attr-name', options)` - Set attribute on selector with options
|
|
522
|
+
- `@setAttribute` - Bare decorator (uses method name as attribute on $this)
|
|
523
|
+
|
|
524
|
+
#### @changedAttribute (Method Decorator)
|
|
525
|
+
Listen for attribute changes on the component this element.
|
|
526
|
+
|
|
527
|
+
```typescript
|
|
528
|
+
@elementDefine('reactive-component')
|
|
529
|
+
class ReactiveComponent extends HTMLElement {
|
|
530
|
+
@changedAttribute('product-id')
|
|
531
|
+
onProductIdChanged(newValue: string, oldValue: string) {
|
|
532
|
+
console.log(`Product changed from ${oldValue} to ${newValue}`);
|
|
533
|
+
this.loadProduct(newValue);
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
@changedAttribute('data-status', { type: Boolean })
|
|
537
|
+
onStatusChanged(newValue: boolean) {
|
|
538
|
+
console.log(`Status is now: ${newValue}`);
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
// Listen to any attribute change
|
|
542
|
+
@changedAttribute()
|
|
543
|
+
onAnyAttributeChanged(newValue: any, oldValue: any) {
|
|
544
|
+
console.log('An attribute changed');
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
```
|
|
548
|
+
|
|
549
|
+
**@changedAttribute Options:**
|
|
550
|
+
- `attributeName` - Attribute name to listen for (optional, defaults to method name)
|
|
551
|
+
- `type` - Type converter: `Number`, `Boolean`, or `String`
|
|
552
|
+
- `while` - Execution condition: `'connected'` (only while connected to DOM)
|
|
553
|
+
|
|
554
|
+
### 6.5 **Property Binding**
|
|
555
|
+
|
|
556
|
+
#### @property (Field Decorator)
|
|
557
|
+
Bind element properties to component fields with automatic read/write synchronization.
|
|
558
|
+
|
|
559
|
+
```typescript
|
|
560
|
+
@elementDefine('input-wrapper')
|
|
561
|
+
class InputWrapper extends HTMLElement {
|
|
562
|
+
// Property on $this (auto-detected)
|
|
563
|
+
@property('value')
|
|
564
|
+
inputValue: string;
|
|
565
|
+
|
|
566
|
+
// Property on selector
|
|
567
|
+
@property('#submit-btn', 'disabled')
|
|
568
|
+
isSubmitDisabled: boolean;
|
|
569
|
+
|
|
570
|
+
// Bare decorator (uses field name as property)
|
|
571
|
+
@property
|
|
572
|
+
checked: boolean;
|
|
573
|
+
}
|
|
574
|
+
```
|
|
575
|
+
|
|
576
|
+
#### @setProperty (Method Decorator)
|
|
577
|
+
Set element properties from method return values.
|
|
578
|
+
|
|
579
|
+
```typescript
|
|
580
|
+
@elementDefine('form-handler')
|
|
581
|
+
class FormHandler extends HTMLElement {
|
|
582
|
+
// Set property on $this
|
|
583
|
+
@setProperty('disabled')
|
|
584
|
+
disableForm() {
|
|
585
|
+
return !this.isValid();
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
// Set property on selector
|
|
589
|
+
@setProperty('#submit-btn', 'disabled')
|
|
590
|
+
updateSubmitState() {
|
|
591
|
+
return this.hasErrors;
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
// Bare decorator (uses method name as property)
|
|
595
|
+
@setProperty
|
|
596
|
+
setValue() {
|
|
597
|
+
return this.computedValue;
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
```
|
|
601
|
+
|
|
602
|
+
**Usage Patterns:**
|
|
603
|
+
- `@property('propertyName')` - Property on $this
|
|
604
|
+
- `@property('#selector', 'propertyName')` - Property on selector
|
|
605
|
+
- `@property('propertyName', options)` - Property on $this with options
|
|
606
|
+
- `@property('#selector', 'propertyName', options)` - Property on selector with options
|
|
607
|
+
- `@property` - Bare decorator (uses field name as property on $this)
|
|
608
|
+
|
|
609
|
+
**@setProperty Patterns:**
|
|
610
|
+
- `@setProperty('propertyName')` - Set property on $this
|
|
611
|
+
- `@setProperty('#selector', 'propertyName')` - Set property on selector
|
|
612
|
+
- `@setProperty('propertyName', options)` - Set property on $this with options
|
|
613
|
+
- `@setProperty('#selector', 'propertyName', options)` - Set property on selector with options
|
|
614
|
+
- `@setProperty` - Bare decorator (uses method name as property on $this)
|
|
615
|
+
|
|
616
|
+
### 7. **DOM Manipulation with applyNode**
|
|
482
617
|
|
|
483
618
|
Surgically add, replace, or remove nodes in the DOM with fine-grained control.
|
|
484
619
|
|
|
@@ -486,19 +621,19 @@ Surgically add, replace, or remove nodes in the DOM with fine-grained control.
|
|
|
486
621
|
@elementDefine('content-updater')
|
|
487
622
|
class ContentUpdater extends HTMLElement {
|
|
488
623
|
@addEventListener('button', 'click')
|
|
489
|
-
@
|
|
624
|
+
@replaceChildrenNode()
|
|
490
625
|
updateContent() {
|
|
491
626
|
return `<div>New content</div>`;
|
|
492
627
|
}
|
|
493
628
|
|
|
494
629
|
@addEventListener('.append-btn', 'click')
|
|
495
|
-
@
|
|
630
|
+
@beforeEndNode()
|
|
496
631
|
appendContent() {
|
|
497
632
|
return `<p>Appended content</p>`;
|
|
498
633
|
}
|
|
499
634
|
|
|
500
635
|
@addEventListener('.prepend-btn', 'click')
|
|
501
|
-
@
|
|
636
|
+
@afterBeginNode()
|
|
502
637
|
prependContent() {
|
|
503
638
|
return `<p>Prepended content</p>`;
|
|
504
639
|
}
|
|
@@ -517,15 +652,15 @@ class ContentUpdater extends HTMLElement {
|
|
|
517
652
|
```
|
|
518
653
|
|
|
519
654
|
**@applyNode Decorator Variants:**
|
|
520
|
-
- `
|
|
521
|
-
- `
|
|
522
|
-
- `
|
|
523
|
-
- `
|
|
524
|
-
- `
|
|
525
|
-
- `
|
|
526
|
-
- `
|
|
527
|
-
- `
|
|
528
|
-
- `
|
|
655
|
+
- `replaceChildrenNode()` - Replace all children
|
|
656
|
+
- `replaceChildrenLightNode()` - Replace children in light DOM
|
|
657
|
+
- `beforeEndNode()` - Append to end
|
|
658
|
+
- `beforeEndLightNode()` - Append to light DOM end
|
|
659
|
+
- `afterBeginNode()` - Prepend to beginning
|
|
660
|
+
- `afterBeginLightNode()` - Prepend to light DOM beginning
|
|
661
|
+
- `innerHtmlNode()` - Set innerHTML
|
|
662
|
+
- `innerHtmlLightNode()` - Set innerHTML in light DOM
|
|
663
|
+
- `innerTextNode()` - Set innerText
|
|
529
664
|
|
|
530
665
|
**Position Options:**
|
|
531
666
|
```typescript
|
|
@@ -541,7 +676,7 @@ export type ApplyNodePosition =
|
|
|
541
676
|
| 'remove'; // Remove element
|
|
542
677
|
```
|
|
543
678
|
|
|
544
|
-
###
|
|
679
|
+
### 8. **Style & Class Management**
|
|
545
680
|
|
|
546
681
|
Apply styles and classes dynamically with `@applyStyle` and `@applyClass`.
|
|
547
682
|
|
|
@@ -552,7 +687,7 @@ class StyledComponent extends HTMLElement {
|
|
|
552
687
|
isActive = false;
|
|
553
688
|
|
|
554
689
|
@addEventListener('button', 'click')
|
|
555
|
-
@
|
|
690
|
+
@updateStyle()
|
|
556
691
|
toggleStyle() {
|
|
557
692
|
return {
|
|
558
693
|
color: this.isActive ? 'green' : 'red',
|
|
@@ -561,7 +696,7 @@ class StyledComponent extends HTMLElement {
|
|
|
561
696
|
}
|
|
562
697
|
|
|
563
698
|
@addEventListener('.toggle-btn', 'click')
|
|
564
|
-
@
|
|
699
|
+
@updateClass()
|
|
565
700
|
toggleClass() {
|
|
566
701
|
return {
|
|
567
702
|
'active': this.isActive,
|
|
@@ -593,7 +728,7 @@ class StyledComponent extends HTMLElement {
|
|
|
593
728
|
- `removeClassThis()` - Remove classes
|
|
594
729
|
- `toggleClassThis()` - Toggle classes
|
|
595
730
|
|
|
596
|
-
###
|
|
731
|
+
### 8.5 **Lifecycle Hooks**
|
|
597
732
|
|
|
598
733
|
Lifecycle hooks allow you to execute code at specific points in a component's lifecycle. All lifecycle decorators support optional `order` parameter for execution ordering.
|
|
599
734
|
|
|
@@ -676,7 +811,7 @@ onFirst() { }
|
|
|
676
811
|
onSecond() { }
|
|
677
812
|
```
|
|
678
813
|
|
|
679
|
-
###
|
|
814
|
+
### 9. **Structural Directives**
|
|
680
815
|
|
|
681
816
|
Structural Directives allow declarative conditional rendering, list iteration, async handling, and routing with automatic attribute substitution and dynamic expressions.
|
|
682
817
|
|
|
@@ -766,9 +901,9 @@ class LoginForm extends HTMLElement {
|
|
|
766
901
|
- `publishSwcAppMessage(messageType)` - Publish with specific message type
|
|
767
902
|
- `publishSwcAppMessage(messageType, { valueKey: 'customKey' })` - Publish with custom value extraction
|
|
768
903
|
- `publishSwcAppMessage({ messageType: 'type', valueKey: 'customKey' })` - Publish with options object
|
|
769
|
-
- `
|
|
770
|
-
- `
|
|
771
|
-
- `
|
|
904
|
+
- `publishMessage()` - Short alias
|
|
905
|
+
- `publishMessage(messageType)` - Short alias with message type
|
|
906
|
+
- `publishMessage(messageType, options)` - Short alias with options
|
|
772
907
|
|
|
773
908
|
**Using valueKey for Multiple Decorators:**
|
|
774
909
|
|
|
@@ -825,7 +960,7 @@ class ProductDetail extends HTMLElement {
|
|
|
825
960
|
|
|
826
961
|
---
|
|
827
962
|
|
|
828
|
-
###
|
|
963
|
+
### 11. **SwcApp - Multiple Element Types with Mixin Pattern**
|
|
829
964
|
|
|
830
965
|
SWC provides a flexible Mixin-based architecture for creating SwcApp elements that extend different HTMLElement types. This enables building SPAs with any semantic HTML element as the root.
|
|
831
966
|
|
|
@@ -937,7 +1072,7 @@ appElement.connect({
|
|
|
937
1072
|
});
|
|
938
1073
|
```
|
|
939
1074
|
|
|
940
|
-
####
|
|
1075
|
+
#### 12. **Routing with @subscribeSwcAppRouteChangeWhileConnected**
|
|
941
1076
|
|
|
942
1077
|
SWC provides declarative routing with automatic path matching, order-based execution, and optional propagation control.
|
|
943
1078
|
|
|
@@ -1129,8 +1264,8 @@ import {
|
|
|
1129
1264
|
class MultiDecoratorExample extends HTMLElement {
|
|
1130
1265
|
@setAttribute('selector')
|
|
1131
1266
|
@setProperty('selector')
|
|
1132
|
-
@
|
|
1133
|
-
@
|
|
1267
|
+
@updateStyle()
|
|
1268
|
+
@updateClass()
|
|
1134
1269
|
handleUpdate() {
|
|
1135
1270
|
return {
|
|
1136
1271
|
[ATTRIBUTE_METADATA_KEY]: 'attribute-value',
|
|
@@ -1151,8 +1286,8 @@ For more readable code, use the `valueKey` option to specify custom keys:
|
|
|
1151
1286
|
class CustomKeyExample extends HTMLElement {
|
|
1152
1287
|
@setAttribute('selector', { valueKey: 'attrValue' })
|
|
1153
1288
|
@setProperty('selector', { valueKey: 'propValue' })
|
|
1154
|
-
@
|
|
1155
|
-
@
|
|
1289
|
+
@updateStyle({ valueKey: 'styleValue' })
|
|
1290
|
+
@updateClass({ valueKey: 'classValue' })
|
|
1156
1291
|
handleUpdate() {
|
|
1157
1292
|
return {
|
|
1158
1293
|
attrValue: 'attribute-value',
|
|
@@ -1173,7 +1308,7 @@ You can mix both approaches in the same method:
|
|
|
1173
1308
|
class MixedKeysExample extends HTMLElement {
|
|
1174
1309
|
@setAttribute('selector') // Uses default ATTRIBUTE_METADATA_KEY
|
|
1175
1310
|
@setProperty('selector', { valueKey: 'customProp' }) // Uses custom key
|
|
1176
|
-
@
|
|
1311
|
+
@updateStyle({ valueKey: 'styles' }) // Uses custom key
|
|
1177
1312
|
handleUpdate() {
|
|
1178
1313
|
return {
|
|
1179
1314
|
[ATTRIBUTE_METADATA_KEY]: 'attr-value',
|
|
@@ -1185,20 +1320,20 @@ class MixedKeysExample extends HTMLElement {
|
|
|
1185
1320
|
```
|
|
1186
1321
|
|
|
1187
1322
|
**Supported Decorators with valueKey:**
|
|
1188
|
-
- `@applyAttribute` / `@setAttribute`
|
|
1189
|
-
- `@applyProperty` / `@setProperty`
|
|
1323
|
+
- `@applyAttribute` / `@setAttribute`
|
|
1324
|
+
- `@applyProperty` / `@setProperty`
|
|
1190
1325
|
- `@applySlot` / `@clearSlot` / `@appendHtmlSlot` / etc.
|
|
1191
|
-
- `@applyNode` / `@
|
|
1192
|
-
- `@applyStyle` / `@
|
|
1193
|
-
- `@applyClass` / `@
|
|
1194
|
-
- `@emitCustomEvent` / `@emit`
|
|
1326
|
+
- `@applyNode` / `@replaceChildrenNode` / etc.
|
|
1327
|
+
- `@applyStyle` / `@updateStyle` / etc.
|
|
1328
|
+
- `@applyClass` / `@updateClass` / etc.
|
|
1329
|
+
- `@emitCustomEvent` / `@emit`
|
|
1195
1330
|
- `@publishSwcAppMessage` / `@publish`
|
|
1196
1331
|
|
|
1197
1332
|
Each decorator will use only its corresponding value from the return object, preventing conflicts and allowing clean separation of concerns.
|
|
1198
1333
|
|
|
1199
1334
|
---
|
|
1200
1335
|
|
|
1201
|
-
###
|
|
1336
|
+
### 13. **Accommodation Pattern**
|
|
1202
1337
|
Factory-based component registration with explicit DI.
|
|
1203
1338
|
|
|
1204
1339
|
```typescript
|
|
@@ -1239,6 +1374,120 @@ appElement.connect({
|
|
|
1239
1374
|
```
|
|
1240
1375
|
---
|
|
1241
1376
|
|
|
1377
|
+
## 🔄 Decorator API - Consolidated Pattern (v1.0.43+)
|
|
1378
|
+
|
|
1379
|
+
### Simplified Decorator API
|
|
1380
|
+
|
|
1381
|
+
The decorator API uses a consolidated pattern where all decorators support **optional selector parameter** that defaults to `$this` when omitted. This eliminates redundant `*This` functions.
|
|
1382
|
+
|
|
1383
|
+
#### Current Usage Pattern
|
|
1384
|
+
```typescript
|
|
1385
|
+
// Single function with optional selector
|
|
1386
|
+
@applyClass('selector', 'update')
|
|
1387
|
+
method() { ... }
|
|
1388
|
+
|
|
1389
|
+
@applyClass('update') // Selector defaults to $this
|
|
1390
|
+
method() { ... }
|
|
1391
|
+
|
|
1392
|
+
@applyClass // Bare decorator - selector defaults to $this
|
|
1393
|
+
method() { ... }
|
|
1394
|
+
```
|
|
1395
|
+
|
|
1396
|
+
#### Decorator Functions (Current API)
|
|
1397
|
+
|
|
1398
|
+
**applyClass.ts:**
|
|
1399
|
+
- `applyClass(selector?, options?)` - Set/update/add/remove/toggle classes
|
|
1400
|
+
- `setClass(selector?, options?)` - Replace all classes
|
|
1401
|
+
- `updateClass(selector?, options?)` - Toggle classes
|
|
1402
|
+
- `addClass(selector?, options?)` - Add classes
|
|
1403
|
+
- `removeClass(selector?, options?)` - Remove classes
|
|
1404
|
+
- `toggleClass(selector?, options?)` - Toggle classes
|
|
1405
|
+
|
|
1406
|
+
**applyStyle.ts:**
|
|
1407
|
+
- `applyStyle(selector?, options?)` - Set/update/remove styles
|
|
1408
|
+
- `setStyle(selector?, options?)` - Clear and set styles
|
|
1409
|
+
- `updateStyle(selector?, options?)` - Update/merge styles
|
|
1410
|
+
- `removeStyle(selector?, options?)` - Remove specific styles
|
|
1411
|
+
|
|
1412
|
+
**applyProperty.ts:**
|
|
1413
|
+
- `property(selector?, options?)` - Get/set element properties
|
|
1414
|
+
- `setProperty(selector?, options?)` - Set element properties
|
|
1415
|
+
|
|
1416
|
+
**applyAttribute.ts:**
|
|
1417
|
+
- `attribute(selector?, options?)` - Get/set element attributes
|
|
1418
|
+
- `setAttribute(selector?, options?)` - Set element attributes
|
|
1419
|
+
|
|
1420
|
+
**query.ts:**
|
|
1421
|
+
- `query(selector?, options?)` - Query single element (supports $this, $host, $appHost, etc.)
|
|
1422
|
+
|
|
1423
|
+
**queryAll.ts:**
|
|
1424
|
+
- `queryAll(selector?, options?)` - Query multiple elements
|
|
1425
|
+
|
|
1426
|
+
**emitCustomEvent.ts:**
|
|
1427
|
+
- `emitCustomEvent(target, type, options?)` - Emit custom events
|
|
1428
|
+
- `emit(target, type, options?)` - Short alias
|
|
1429
|
+
|
|
1430
|
+
#### Usage Examples
|
|
1431
|
+
|
|
1432
|
+
```typescript
|
|
1433
|
+
@elementDefine('my-component')
|
|
1434
|
+
class MyComponent extends HTMLElement {
|
|
1435
|
+
// Class management - all default to $this
|
|
1436
|
+
@updateClass()
|
|
1437
|
+
toggleActive() {
|
|
1438
|
+
return { 'active': this.isActive };
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1441
|
+
// Style management - all default to $this
|
|
1442
|
+
@updateStyle()
|
|
1443
|
+
applyTheme() {
|
|
1444
|
+
return { color: this.theme.color, fontSize: '16px' };
|
|
1445
|
+
}
|
|
1446
|
+
|
|
1447
|
+
// Property binding - all default to $this
|
|
1448
|
+
@setProperty()
|
|
1449
|
+
updateValue() {
|
|
1450
|
+
return this.computedValue;
|
|
1451
|
+
}
|
|
1452
|
+
|
|
1453
|
+
// Attribute binding - all default to $this
|
|
1454
|
+
@setAttribute()
|
|
1455
|
+
updateId() {
|
|
1456
|
+
return this.elementId;
|
|
1457
|
+
}
|
|
1458
|
+
|
|
1459
|
+
// Query elements
|
|
1460
|
+
@query('#input')
|
|
1461
|
+
inputElement?: HTMLInputElement;
|
|
1462
|
+
|
|
1463
|
+
@queryAll('li')
|
|
1464
|
+
listItems?: HTMLLIElement[];
|
|
1465
|
+
|
|
1466
|
+
// Emit custom events
|
|
1467
|
+
@addEventListener('button', 'click')
|
|
1468
|
+
@emitCustomEvent('$this', 'item-selected')
|
|
1469
|
+
onItemSelect() {
|
|
1470
|
+
return { itemId: this.selectedId };
|
|
1471
|
+
}
|
|
1472
|
+
|
|
1473
|
+
// With selector
|
|
1474
|
+
@updateClass('.card', 'update')
|
|
1475
|
+
updateCardClass() {
|
|
1476
|
+
return { 'highlighted': true };
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
```
|
|
1480
|
+
|
|
1481
|
+
#### Key Features
|
|
1482
|
+
|
|
1483
|
+
1. **Reduced API Surface** - Consolidated decorators eliminate redundant `*This` functions
|
|
1484
|
+
2. **Cleaner Code** - Single function name with multiple overloads
|
|
1485
|
+
3. **Better Discoverability** - Intuitive parameter patterns
|
|
1486
|
+
4. **Flexible Usage** - Supports bare decorators, with options, and with selectors
|
|
1487
|
+
5. **Type Safe** - Full TypeScript support with proper type inference
|
|
1488
|
+
|
|
1489
|
+
---
|
|
1490
|
+
|
|
1242
1491
|
## ⚠️ Critical Rules
|
|
1243
1492
|
|
|
1244
1493
|
### DO NOT Use @Sim on Web Components
|
package/dist/cjs/SwcAppEngine.js
CHANGED
|
@@ -60,7 +60,9 @@ class SwcAppEngine {
|
|
|
60
60
|
if (this.router) otherInstanceSim.set(import_core_web.Router, this.router);
|
|
61
61
|
this.simpleApplication.run(otherInstanceSim);
|
|
62
62
|
if (this._config.onStartedLazyDefineComponent) {
|
|
63
|
-
await Promise.all(this._config.onStartedLazyDefineComponent.map((it) =>
|
|
63
|
+
await Promise.all(this._config.onStartedLazyDefineComponent.map((it) => {
|
|
64
|
+
it(this._config.window);
|
|
65
|
+
}));
|
|
64
66
|
}
|
|
65
67
|
if (this._config.onEngineStarted) {
|
|
66
68
|
await this._config.onEngineStarted(this.simpleApplication, this.host);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/SwcAppEngine.ts"],
|
|
4
|
-
"sourcesContent": ["import { SimpleApplication } from '@dooboostore/simple-boot';\nimport { HashRouter, PathRouter, Router, RouterEventType } from '@dooboostore/core-web';\nimport { ElementRouter } from './router/ElementRouter';\nimport { SimOption } from '@dooboostore/simple-boot';\nimport { ConstructorType, OptionalType, Subscription } from '@dooboostore/core';\nimport { SwcAppInterface } from './types';\nimport { SimConfig } from '@dooboostore/simple-boot';\n\nexport type SwcConfigType = {\n routeType: 'path' | 'hash' | 'element';\n // connectMode?: 'direct' | 'swap' | 'clear-swap'; // hydrate \uC544\uC9C1 \uAC1C\uBC1C\uC911\n container?: symbol;\n otherInstanceSim?: Map<ConstructorType<any> | Function | SimConfig | symbol, any>;\n path?: string;\n window: Window;\n onEngineStarted?: (sp: SimpleApplication, app: SwcAppInterface) => Promise<void> | void;\n onConnectedChildAfter?: (swcEl: HTMLElement) => void;\n onConnectedChildBefore?: (swcEl: HTMLElement) => void;\n onDisconnectedChildAfter?: (swcEl: HTMLElement) => void;\n onDisconnectedChildBefore?: (swcEl: HTMLElement) => void;\n onConnected?: (app: SwcAppInterface) => void;\n onDisconnected?: (app: SwcAppInterface) => void;\n ssr?: boolean;\n onStartedLazyDefineComponent?: ((w: Window)=> Promise<CustomElementConstructor> | void | string | any | CustomElementConstructor)[];\n\n onChildrenConnectedDone?: (app: SwcAppInterface) => void;\n // onChildrenSwcAppStartedDone?: (app: SwcAppInterface) => void;\n // childrenSwcAppStartedDoneCheckIntervalTime?: number;\n onChildrenRouteChanged?: (event: RouterEventType, app: SwcAppInterface) => void;\n childrenRouteChangedCheckIntervalTime?: number; // \uC790\uC2DD \uC5F0\uACB0 \uC644\uB8CC \uC774\uBCA4\uD2B8 \uB514\uBC14\uC6B4\uC2A4 \uD0C0\uC784 (ms)\n childrenConnectedDoneCheckIntervalTime?: number;\n};\n\nexport type SwcAttributeConfigType = OptionalType<SwcConfigType, 'routeType' | 'window'>;\n\nexport class SwcAppEngine {\n public simpleApplication?: SimpleApplication;\n public router?: Router;\n private routerSubscription?: Subscription;\n private _config?: SwcConfigType;\n\n constructor(private host: HTMLElement) {}\n\n get config() {\n return this._config;\n }\n\n async connect(config: SwcConfigType) {\n try {\n this._config = config;\n\n // Router Selection\n if (this._config.routeType === 'path') {\n this.router = new PathRouter({ window: this._config.window, firstUrl: this._config.path });\n } else if (this._config.routeType === 'hash') {\n this.router = new HashRouter({ window: this._config.window, firstUrl: this._config.path });\n } else if (this._config.routeType === 'element') {\n this.router = new ElementRouter({ window: this._config.window, firstUrl: this._config.path });\n }\n\n // console.log('vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv', this.router)\n\n // App start\n this.simpleApplication = new SimpleApplication(\n new SimOption({\n excludeProxys: [(this._config.window as any).Node],\n container: this._config.container\n })\n );\n\n const otherInstanceSim = new Map<any, any>();\n this.config?.otherInstanceSim?.forEach((v, k) => {\n otherInstanceSim.set(k, v);\n });\n if (this.router) otherInstanceSim.set(Router, this.router);\n this.simpleApplication.run(otherInstanceSim);\n\n\n if (this._config.onStartedLazyDefineComponent) {\n // console.log('-------->', this._config.onStartedLazyDefineComponent)\n await Promise.all(this._config.onStartedLazyDefineComponent.map(it => it(this._config.window)))\n }\n if (this._config.onEngineStarted) {\n await this._config.onEngineStarted(this.simpleApplication, this.host as unknown as SwcAppInterface);\n }\n } catch (e) {\n console.error('[SWC-APP-ENGINE] Init failed:', e, this._config);\n }\n }\n\n disconnect() {\n this.routerSubscription?.unsubscribe();\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAkC;AAClC,sBAAgE;AAChE,2BAA8B;AAC9B,IAAAA,sBAA0B;AAgCnB,MAAM,aAAa;AAAA,EAMxB,YAAoB,MAAmB;AAAnB;AALpB,wBAAO;AACP,wBAAO;AACP,wBAAQ;AACR,wBAAQ;AAAA,EAEgC;AAAA,EAExC,IAAI,SAAS;AACX,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAM,QAAQ,QAAuB;AACnC,QAAI;AACF,WAAK,UAAU;AAGf,UAAI,KAAK,QAAQ,cAAc,QAAQ;AACrC,aAAK,SAAS,IAAI,2BAAW,EAAE,QAAQ,KAAK,QAAQ,QAAQ,UAAU,KAAK,QAAQ,KAAK,CAAC;AAAA,MAC3F,WAAW,KAAK,QAAQ,cAAc,QAAQ;AAC5C,aAAK,SAAS,IAAI,2BAAW,EAAE,QAAQ,KAAK,QAAQ,QAAQ,UAAU,KAAK,QAAQ,KAAK,CAAC;AAAA,MAC3F,WAAW,KAAK,QAAQ,cAAc,WAAW;AAC/C,aAAK,SAAS,IAAI,mCAAc,EAAE,QAAQ,KAAK,QAAQ,QAAQ,UAAU,KAAK,QAAQ,KAAK,CAAC;AAAA,MAC9F;AAKA,WAAK,oBAAoB,IAAI;AAAA,QAC3B,IAAI,8BAAU;AAAA,UACZ,eAAe,CAAE,KAAK,QAAQ,OAAe,IAAI;AAAA,UACjD,WAAW,KAAK,QAAQ;AAAA,QAC1B,CAAC;AAAA,MACH;AAEA,YAAM,mBAAmB,oBAAI,IAAc;AAC3C,WAAK,QAAQ,kBAAkB,QAAQ,CAAC,GAAG,MAAM;AAC/C,yBAAiB,IAAI,GAAG,CAAC;AAAA,MAC3B,CAAC;AACD,UAAI,KAAK,OAAQ,kBAAiB,IAAI,wBAAQ,KAAK,MAAM;AACzD,WAAK,kBAAkB,IAAI,gBAAgB;AAG3C,UAAI,KAAK,QAAQ,8BAA8B;AAE7C,cAAM,QAAQ,IAAI,KAAK,QAAQ,6BAA6B,IAAI,QAAM,
|
|
4
|
+
"sourcesContent": ["import { SimpleApplication } from '@dooboostore/simple-boot';\nimport { HashRouter, PathRouter, Router, RouterEventType } from '@dooboostore/core-web';\nimport { ElementRouter } from './router/ElementRouter';\nimport { SimOption } from '@dooboostore/simple-boot';\nimport { ConstructorType, OptionalType, Subscription } from '@dooboostore/core';\nimport { SwcAppInterface } from './types';\nimport { SimConfig } from '@dooboostore/simple-boot';\n\nexport type SwcConfigType = {\n routeType: 'path' | 'hash' | 'element';\n // connectMode?: 'direct' | 'swap' | 'clear-swap'; // hydrate \uC544\uC9C1 \uAC1C\uBC1C\uC911\n container?: symbol;\n otherInstanceSim?: Map<ConstructorType<any> | Function | SimConfig | symbol, any>;\n path?: string;\n window: Window;\n onEngineStarted?: (sp: SimpleApplication, app: SwcAppInterface) => Promise<void> | void;\n onConnectedChildAfter?: (swcEl: HTMLElement) => void;\n onConnectedChildBefore?: (swcEl: HTMLElement) => void;\n onDisconnectedChildAfter?: (swcEl: HTMLElement) => void;\n onDisconnectedChildBefore?: (swcEl: HTMLElement) => void;\n onConnected?: (app: SwcAppInterface) => void;\n onDisconnected?: (app: SwcAppInterface) => void;\n ssr?: boolean;\n onStartedLazyDefineComponent?: ((w: Window)=> Promise<CustomElementConstructor> | void | string | any | CustomElementConstructor)[];\n\n onChildrenConnectedDone?: (app: SwcAppInterface) => void;\n // onChildrenSwcAppStartedDone?: (app: SwcAppInterface) => void;\n // childrenSwcAppStartedDoneCheckIntervalTime?: number;\n onChildrenRouteChanged?: (event: RouterEventType, app: SwcAppInterface) => void;\n childrenRouteChangedCheckIntervalTime?: number; // \uC790\uC2DD \uC5F0\uACB0 \uC644\uB8CC \uC774\uBCA4\uD2B8 \uB514\uBC14\uC6B4\uC2A4 \uD0C0\uC784 (ms)\n childrenConnectedDoneCheckIntervalTime?: number;\n};\n\nexport type SwcAttributeConfigType = OptionalType<SwcConfigType, 'routeType' | 'window'>;\n\nexport class SwcAppEngine {\n public simpleApplication?: SimpleApplication;\n public router?: Router;\n private routerSubscription?: Subscription;\n private _config?: SwcConfigType;\n\n constructor(private host: HTMLElement) {}\n\n get config() {\n return this._config;\n }\n\n async connect(config: SwcConfigType) {\n try {\n this._config = config;\n\n // Router Selection\n if (this._config.routeType === 'path') {\n this.router = new PathRouter({ window: this._config.window, firstUrl: this._config.path });\n } else if (this._config.routeType === 'hash') {\n this.router = new HashRouter({ window: this._config.window, firstUrl: this._config.path });\n } else if (this._config.routeType === 'element') {\n this.router = new ElementRouter({ window: this._config.window, firstUrl: this._config.path });\n }\n\n // console.log('vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv', this.router)\n\n // App start\n this.simpleApplication = new SimpleApplication(\n new SimOption({\n excludeProxys: [(this._config.window as any).Node],\n container: this._config.container\n })\n );\n\n const otherInstanceSim = new Map<any, any>();\n this.config?.otherInstanceSim?.forEach((v, k) => {\n otherInstanceSim.set(k, v);\n });\n if (this.router) otherInstanceSim.set(Router, this.router);\n this.simpleApplication.run(otherInstanceSim);\n\n\n if (this._config.onStartedLazyDefineComponent) {\n // console.log('-------->', this._config.onStartedLazyDefineComponent)\n await Promise.all(this._config.onStartedLazyDefineComponent.map(it => {\n it(this._config.window);\n }))\n }\n if (this._config.onEngineStarted) {\n await this._config.onEngineStarted(this.simpleApplication, this.host as unknown as SwcAppInterface);\n }\n } catch (e) {\n console.error('[SWC-APP-ENGINE] Init failed:', e, this._config);\n }\n }\n\n disconnect() {\n this.routerSubscription?.unsubscribe();\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAkC;AAClC,sBAAgE;AAChE,2BAA8B;AAC9B,IAAAA,sBAA0B;AAgCnB,MAAM,aAAa;AAAA,EAMxB,YAAoB,MAAmB;AAAnB;AALpB,wBAAO;AACP,wBAAO;AACP,wBAAQ;AACR,wBAAQ;AAAA,EAEgC;AAAA,EAExC,IAAI,SAAS;AACX,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAM,QAAQ,QAAuB;AACnC,QAAI;AACF,WAAK,UAAU;AAGf,UAAI,KAAK,QAAQ,cAAc,QAAQ;AACrC,aAAK,SAAS,IAAI,2BAAW,EAAE,QAAQ,KAAK,QAAQ,QAAQ,UAAU,KAAK,QAAQ,KAAK,CAAC;AAAA,MAC3F,WAAW,KAAK,QAAQ,cAAc,QAAQ;AAC5C,aAAK,SAAS,IAAI,2BAAW,EAAE,QAAQ,KAAK,QAAQ,QAAQ,UAAU,KAAK,QAAQ,KAAK,CAAC;AAAA,MAC3F,WAAW,KAAK,QAAQ,cAAc,WAAW;AAC/C,aAAK,SAAS,IAAI,mCAAc,EAAE,QAAQ,KAAK,QAAQ,QAAQ,UAAU,KAAK,QAAQ,KAAK,CAAC;AAAA,MAC9F;AAKA,WAAK,oBAAoB,IAAI;AAAA,QAC3B,IAAI,8BAAU;AAAA,UACZ,eAAe,CAAE,KAAK,QAAQ,OAAe,IAAI;AAAA,UACjD,WAAW,KAAK,QAAQ;AAAA,QAC1B,CAAC;AAAA,MACH;AAEA,YAAM,mBAAmB,oBAAI,IAAc;AAC3C,WAAK,QAAQ,kBAAkB,QAAQ,CAAC,GAAG,MAAM;AAC/C,yBAAiB,IAAI,GAAG,CAAC;AAAA,MAC3B,CAAC;AACD,UAAI,KAAK,OAAQ,kBAAiB,IAAI,wBAAQ,KAAK,MAAM;AACzD,WAAK,kBAAkB,IAAI,gBAAgB;AAG3C,UAAI,KAAK,QAAQ,8BAA8B;AAE7C,cAAM,QAAQ,IAAI,KAAK,QAAQ,6BAA6B,IAAI,QAAM;AACpE,aAAG,KAAK,QAAQ,MAAM;AAAA,QACxB,CAAC,CAAC;AAAA,MACJ;AACA,UAAI,KAAK,QAAQ,iBAAiB;AAChC,cAAM,KAAK,QAAQ,gBAAgB,KAAK,mBAAmB,KAAK,IAAkC;AAAA,MACpG;AAAA,IACF,SAAS,GAAG;AACV,cAAQ,MAAM,iCAAiC,GAAG,KAAK,OAAO;AAAA,IAChE;AAAA,EACF;AAAA,EAEA,aAAa;AACX,SAAK,oBAAoB,YAAY;AAAA,EACvC;AACF;",
|
|
6
6
|
"names": ["import_simple_boot"]
|
|
7
7
|
}
|
|
@@ -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\n\nexport function addEventListenerDelegateLightDom(selector: string, type: string, options?: Omit<AddEventListenerBaseOptions
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA6B;
|
|
4
|
+
"sourcesContent": ["import { ReflectUtils } from '@dooboostore/core';\nimport { SpecialSelector, SwcQueryOptions, HelperHostSet } from '../types';\n\nexport interface AddEventListenerBaseOptions<TEvent extends Event = Event> 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 // RxJS operator options\n debounceTime?: number;\n throttleTime?: number;\n distinctUntilChanged?: boolean | ((prev: TEvent, curr: TEvent) => boolean);\n}\n\nexport interface AddEventListenerMetadata<TEvent extends Event = Event> {\n propertyKey: string | symbol;\n selector: string;\n type: string;\n options: AddEventListenerBaseOptions<TEvent> & SwcQueryOptions & { delegate?: boolean };\n}\n\nexport const ADD_EVENT_LISTENER_METADATA_KEY = Symbol.for('simple-web-component:add-event-listener');\n\nexport function addEventListener<TEvent extends Event = Event>(target: SpecialSelector, type: string, options?: AddEventListenerBaseOptions<TEvent>): MethodDecorator;\nexport function addEventListener<TEvent extends Event = Event>(selector: string, type: string, options?: AddEventListenerBaseOptions<TEvent> & SwcQueryOptions & { delegate?: boolean }): MethodDecorator;\n/**\n * @addEventListener decorator to bind events to elements.\n */\nexport function addEventListener<TEvent extends Event = Event>(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<TEvent>[]>(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\n\nexport function addEventListenerDelegateLightDom<TEvent extends Event = Event>(selector: string, type: string, options?: Omit<AddEventListenerBaseOptions<TEvent>, 'delegate'>): MethodDecorator {\n return addEventListener<TEvent>(selector, type, {...options??{}, root:'light', delegate: true});\n}\n\nexport function addEventListenerDelegateShadowDom<TEvent extends Event = Event>(selector: string, type: string, options?: Omit<AddEventListenerBaseOptions<TEvent>, 'delegate'>): MethodDecorator {\n return addEventListener<TEvent>(selector, type, {...options??{}, root:'shadow', delegate: true});\n}\nexport function addEventListenerDelegateAllDom<TEvent extends Event = Event>(selector: string, type: string, options?: Omit<AddEventListenerBaseOptions<TEvent>, 'delegate'>): MethodDecorator {\n return addEventListener<TEvent>(selector, type, {...options??{}, root:'all', delegate: true});\n}\nexport function addEventListenerDelegate<TEvent extends Event = Event>(selector: string, type: string, options?: Omit<AddEventListenerBaseOptions<TEvent>, 'delegate'>): MethodDecorator {\n return addEventListener<TEvent>(selector, type, {...options??{}, root:'auto', delegate: true});\n}\n\n/**\n * @addEventListenerThis decorator - simplified version of @addEventListener for $this selector\n */\n\n// --- Aliases: event... ---\nexport const event = addEventListener;\nexport const eventDelegateLightDom = addEventListenerDelegateLightDom;\nexport const eventDelegateShadowDom = addEventListenerDelegateShadowDom;\nexport const eventDelegateAllDom = addEventListenerDelegateAllDom;\nexport const eventDelegate = addEventListenerDelegate;\nexport function addEventListenerThis<TEvent extends Event = Event>(type: string, options?: AddEventListenerBaseOptions<TEvent> & SwcQueryOptions): MethodDecorator {\n return addEventListener<TEvent>('$this', type, options);\n}\n\n/**\n * @addEventListenerAppHost decorator - simplified version of @addEventListener for $appHost selector\n */\nexport function addEventListenerAppHost<TEvent extends Event = Event>(type: string, options?: AddEventListenerBaseOptions<TEvent> & SwcQueryOptions): MethodDecorator {\n return addEventListener<TEvent>('$appHost', type, options);\n}\n\nexport function addEventListenerWindow<TEvent extends Event = Event>(type: string, options?: AddEventListenerBaseOptions<TEvent> & SwcQueryOptions): MethodDecorator {\n return addEventListener<TEvent>('$window', type, options);\n}\nexport function addEventListenerDocument<TEvent extends Event = Event>(type: string, options?: AddEventListenerBaseOptions<TEvent> & SwcQueryOptions): MethodDecorator {\n return addEventListener<TEvent>('$document', type, options);\n}\n\nexport const getAddEventListenerMetadata = (target: any): AddEventListenerMetadata<Event>[] | undefined => {\n const constructor = target instanceof Function ? target : target.constructor;\n return ReflectUtils.getMetadata(ADD_EVENT_LISTENER_METADATA_KEY, constructor);\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA6B;AA0BtB,MAAM,kCAAkC,OAAO,IAAI,yCAAyC;AAO5F,SAAS,iBAA+C,kBAA0B,MAAc,UAAe,CAAC,GAAoB;AACzI,SAAO,CAAC,WAAmB,aAA8B,eAAmC;AAC1F,UAAM,cAAc,UAAU;AAE9B,QAAI,YAAY,yBAAa,YAAgD,iCAAiC,WAAW;AACzH,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;AAGO,SAAS,iCAA+D,UAAkB,MAAc,SAAkF;AAC/L,SAAO,iBAAyB,UAAU,MAAM,EAAC,GAAG,WAAS,CAAC,GAAG,MAAK,SAAS,UAAU,KAAI,CAAC;AAChG;AAEO,SAAS,kCAAgE,UAAkB,MAAc,SAAkF;AAChM,SAAO,iBAAyB,UAAU,MAAM,EAAC,GAAG,WAAS,CAAC,GAAG,MAAK,UAAU,UAAU,KAAI,CAAC;AACjG;AACO,SAAS,+BAA6D,UAAkB,MAAc,SAAkF;AAC7L,SAAO,iBAAyB,UAAU,MAAM,EAAC,GAAG,WAAS,CAAC,GAAG,MAAK,OAAO,UAAU,KAAI,CAAC;AAC9F;AACO,SAAS,yBAAuD,UAAkB,MAAc,SAAkF;AACvL,SAAO,iBAAyB,UAAU,MAAM,EAAC,GAAG,WAAS,CAAC,GAAG,MAAK,QAAQ,UAAU,KAAI,CAAC;AAC/F;AAOO,MAAM,QAAQ;AACd,MAAM,wBAAwB;AAC9B,MAAM,yBAAyB;AAC/B,MAAM,sBAAsB;AAC5B,MAAM,gBAAgB;AACtB,SAAS,qBAAmD,MAAc,SAAkF;AACjK,SAAO,iBAAyB,SAAS,MAAM,OAAO;AACxD;AAKO,SAAS,wBAAsD,MAAc,SAAkF;AACpK,SAAO,iBAAyB,YAAY,MAAM,OAAO;AAC3D;AAEO,SAAS,uBAAqD,MAAc,SAAkF;AACnK,SAAO,iBAAyB,WAAW,MAAM,OAAO;AAC1D;AACO,SAAS,yBAAuD,MAAc,SAAkF;AACrK,SAAO,iBAAyB,aAAa,MAAM,OAAO;AAC5D;AAEO,MAAM,8BAA8B,CAAC,WAA+D;AACzG,QAAM,cAAc,kBAAkB,WAAW,SAAS,OAAO;AACjE,SAAO,yBAAa,YAAY,iCAAiC,WAAW;AAC9E;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -20,15 +20,13 @@ __export(applyAttribute_exports, {
|
|
|
20
20
|
ATTRIBUTE_METADATA_KEY: () => ATTRIBUTE_METADATA_KEY,
|
|
21
21
|
applyAttribute: () => applyAttribute,
|
|
22
22
|
attribute: () => attribute,
|
|
23
|
-
attributeThis: () => attributeThis,
|
|
24
23
|
convertValue: () => convertValue,
|
|
25
24
|
default: () => applyAttribute_default,
|
|
26
25
|
findAllAttributeApplyMetadata: () => findAllAttributeApplyMetadata,
|
|
27
26
|
findAllAttributeMetadata: () => findAllAttributeMetadata,
|
|
28
27
|
getAttributeValue: () => getAttributeValue,
|
|
29
28
|
resolveAttributeTargets: () => resolveAttributeTargets,
|
|
30
|
-
setAttribute: () => setAttribute
|
|
31
|
-
setAttributeThis: () => setAttributeThis
|
|
29
|
+
setAttribute: () => setAttribute
|
|
32
30
|
});
|
|
33
31
|
module.exports = __toCommonJS(applyAttribute_exports);
|
|
34
32
|
var import_core = require("@dooboostore/core");
|
|
@@ -36,6 +34,13 @@ var import_elementDefine = require("./elementDefine");
|
|
|
36
34
|
var import_Utils = require("../utils/Utils");
|
|
37
35
|
var import_core_web = require("@dooboostore/core-web");
|
|
38
36
|
const ATTRIBUTE_METADATA_KEY = Symbol.for("simple-web-component:attribute");
|
|
37
|
+
const isCssSelector = (str) => {
|
|
38
|
+
if (!str) return false;
|
|
39
|
+
if (str.startsWith("$")) return true;
|
|
40
|
+
if (/^[#.\[\:>+~]/.test(str)) return true;
|
|
41
|
+
if (/[>+~:\[\]]/.test(str)) return true;
|
|
42
|
+
return false;
|
|
43
|
+
};
|
|
39
44
|
const convertValue = (val, type) => {
|
|
40
45
|
if (val === null || val === void 0) return val;
|
|
41
46
|
if (type === Number) return Number(val);
|
|
@@ -206,35 +211,32 @@ function applyAttribute(selector, targetAttributeNameOrOptions, options) {
|
|
|
206
211
|
});
|
|
207
212
|
};
|
|
208
213
|
}
|
|
209
|
-
function attribute(
|
|
210
|
-
|
|
211
|
-
}
|
|
212
|
-
function attributeThis(targetOrOptions, propertyKeyOrOptions, descriptor) {
|
|
213
|
-
if (typeof targetOrOptions === "object" && targetOrOptions !== null && !Array.isArray(targetOrOptions) && typeof propertyKeyOrOptions === "string" || typeof propertyKeyOrOptions === "symbol") {
|
|
214
|
-
return applyAttribute("$this", void 0, {})(targetOrOptions, propertyKeyOrOptions, descriptor);
|
|
214
|
+
function attribute(selectorOrAttributeOrTarget, attributeNameOrOptions, optionsOrDescriptor) {
|
|
215
|
+
if (optionsOrDescriptor !== void 0 && (typeof attributeNameOrOptions === "string" || typeof attributeNameOrOptions === "symbol")) {
|
|
216
|
+
return applyAttribute("$this", void 0, {})(selectorOrAttributeOrTarget, attributeNameOrOptions, optionsOrDescriptor);
|
|
215
217
|
}
|
|
216
|
-
if (typeof
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
218
|
+
if (typeof selectorOrAttributeOrTarget === "string") {
|
|
219
|
+
const isSelector = isCssSelector(selectorOrAttributeOrTarget);
|
|
220
|
+
if (isSelector) {
|
|
221
|
+
return applyAttribute(selectorOrAttributeOrTarget, attributeNameOrOptions, optionsOrDescriptor);
|
|
222
|
+
} else {
|
|
223
|
+
const options = typeof attributeNameOrOptions === "object" && attributeNameOrOptions !== null ? attributeNameOrOptions : {};
|
|
224
|
+
return applyAttribute("$this", selectorOrAttributeOrTarget, options);
|
|
225
|
+
}
|
|
222
226
|
}
|
|
227
|
+
return applyAttribute("$this", void 0, selectorOrAttributeOrTarget);
|
|
223
228
|
}
|
|
224
|
-
function setAttribute(
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
} else if (targetOrOptions && typeof targetOrOptions === "object") {
|
|
234
|
-
return applyAttribute("$this", void 0, targetOrOptions);
|
|
235
|
-
} else {
|
|
236
|
-
return applyAttribute("$this", void 0, {});
|
|
229
|
+
function setAttribute(selectorOrAttributeOrOptions, attributeNameOrOptions, optionsOrUndefined) {
|
|
230
|
+
if (typeof selectorOrAttributeOrOptions === "string") {
|
|
231
|
+
const isSelector = isCssSelector(selectorOrAttributeOrOptions);
|
|
232
|
+
if (isSelector) {
|
|
233
|
+
return applyAttribute(selectorOrAttributeOrOptions, attributeNameOrOptions, optionsOrUndefined);
|
|
234
|
+
} else {
|
|
235
|
+
const options = typeof attributeNameOrOptions === "object" && attributeNameOrOptions !== null ? attributeNameOrOptions : {};
|
|
236
|
+
return applyAttribute("$this", selectorOrAttributeOrOptions, options);
|
|
237
|
+
}
|
|
237
238
|
}
|
|
239
|
+
return applyAttribute("$this", void 0, selectorOrAttributeOrOptions);
|
|
238
240
|
}
|
|
239
241
|
const findAllAttributeMetadata = (target) => {
|
|
240
242
|
const actualTarget = target instanceof Function ? target : target.constructor;
|