@dooboostore/simple-web-component 1.0.23 → 1.0.24
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 +238 -44
- package/dist/cjs/decorators/applyNode.js +129 -34
- package/dist/cjs/decorators/applyNode.js.map +2 -2
- package/dist/cjs/decorators/attribute.js +21 -2
- package/dist/cjs/decorators/attribute.js.map +2 -2
- package/dist/cjs/decorators/changedAttributeHost.js.map +2 -2
- package/dist/cjs/decorators/classList.js +60 -17
- package/dist/cjs/decorators/classList.js.map +2 -2
- package/dist/cjs/decorators/query.js +77 -2
- package/dist/cjs/decorators/query.js.map +2 -2
- package/dist/cjs/decorators/queryAll.js +77 -2
- package/dist/cjs/decorators/queryAll.js.map +2 -2
- package/dist/cjs/decorators/setAttribute.js +4 -4
- package/dist/cjs/decorators/setAttribute.js.map +2 -2
- package/dist/cjs/decorators/style.js +46 -15
- package/dist/cjs/decorators/style.js.map +2 -2
- package/dist/cjs/index.js +4 -4
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/utils/Utils.js +140 -1
- package/dist/cjs/utils/Utils.js.map +2 -2
- package/dist/esm/decorators/applyNode.js +129 -34
- package/dist/esm/decorators/applyNode.js.map +2 -2
- package/dist/esm/decorators/attribute.js +21 -2
- package/dist/esm/decorators/attribute.js.map +2 -2
- package/dist/esm/decorators/changedAttributeHost.js.map +2 -2
- package/dist/esm/decorators/classList.js +60 -17
- package/dist/esm/decorators/classList.js.map +2 -2
- package/dist/esm/decorators/query.js +77 -2
- package/dist/esm/decorators/query.js.map +2 -2
- package/dist/esm/decorators/queryAll.js +77 -2
- package/dist/esm/decorators/queryAll.js.map +2 -2
- package/dist/esm/decorators/setAttribute.js +4 -4
- package/dist/esm/decorators/setAttribute.js.map +2 -2
- package/dist/esm/decorators/style.js +46 -15
- package/dist/esm/decorators/style.js.map +2 -2
- package/dist/esm/index.js +4 -4
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/utils/Utils.js +140 -1
- package/dist/esm/utils/Utils.js.map +2 -2
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +542 -155
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
- package/dist/types/decorators/applyNode.d.ts +49 -27
- package/dist/types/decorators/applyNode.d.ts.map +1 -1
- package/dist/types/decorators/attribute.d.ts +11 -4
- package/dist/types/decorators/attribute.d.ts.map +1 -1
- package/dist/types/decorators/classList.d.ts +15 -5
- package/dist/types/decorators/classList.d.ts.map +1 -1
- package/dist/types/decorators/query.d.ts +68 -4
- package/dist/types/decorators/query.d.ts.map +1 -1
- package/dist/types/decorators/queryAll.d.ts +70 -1
- package/dist/types/decorators/queryAll.d.ts.map +1 -1
- package/dist/types/decorators/setAttribute.d.ts.map +1 -1
- package/dist/types/decorators/style.d.ts +17 -8
- package/dist/types/decorators/style.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/utils/Utils.d.ts +49 -0
- package/dist/types/utils/Utils.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +542 -155
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +3 -3
- package/src/decorators/applyNode.ts +179 -60
- package/src/decorators/attribute.ts +43 -10
- package/src/decorators/changedAttributeHost.ts +1 -1
- package/src/decorators/classList.ts +79 -17
- package/src/decorators/query.ts +147 -5
- package/src/decorators/queryAll.ts +148 -2
- package/src/decorators/setAttribute.ts +6 -5
- package/src/decorators/style.ts +67 -22
- package/src/index.ts +6 -6
- package/src/utils/Utils.ts +144 -0
- package/dist/cjs/utils/TemplateUtils.js +0 -109
- package/dist/cjs/utils/TemplateUtils.js.map +0 -7
- package/dist/esm/utils/TemplateUtils.js +0 -90
- package/dist/esm/utils/TemplateUtils.js.map +0 -7
- package/dist/types/utils/TemplateUtils.d.ts +0 -59
- package/dist/types/utils/TemplateUtils.d.ts.map +0 -1
- package/src/utils/TemplateUtils.ts +0 -92
package/README.md
CHANGED
|
@@ -260,19 +260,26 @@ class StyledCard extends HTMLElement {
|
|
|
260
260
|
|
|
261
261
|
### Attribute & Property Decorators
|
|
262
262
|
|
|
263
|
-
#### 10. `@attributeHost
|
|
264
|
-
Bidirectional attribute binding with automatic type conversion.
|
|
263
|
+
#### 10. `@attributeHost`
|
|
264
|
+
Bidirectional attribute binding with automatic type conversion on `:host` element.
|
|
265
|
+
|
|
266
|
+
All usage patterns support automatic field-name-to-attribute-name conversion:
|
|
267
|
+
- Without parentheses: `@attributeHost` - uses field name as attribute name
|
|
268
|
+
- Empty parentheses: `@attributeHost()` - uses field name as attribute name
|
|
269
|
+
- Options only: `@attributeHost({ connectedInitialize: true })` - uses field name as attribute name
|
|
270
|
+
- Custom name: `@attributeHost('custom-name')` - explicit attribute name
|
|
271
|
+
- Custom name + options: `@attributeHost('custom-name', { type: Boolean })` - both specified
|
|
265
272
|
|
|
266
273
|
```typescript
|
|
267
274
|
@elementDefine('input-field')
|
|
268
275
|
class InputField extends HTMLElement {
|
|
269
|
-
@attributeHost
|
|
276
|
+
@attributeHost
|
|
270
277
|
value: string = '';
|
|
271
278
|
|
|
272
279
|
@attributeHost('disabled')
|
|
273
280
|
disabled: boolean = false;
|
|
274
281
|
|
|
275
|
-
@attributeHost(
|
|
282
|
+
@attributeHost({ type: Number })
|
|
276
283
|
count: number = 0;
|
|
277
284
|
|
|
278
285
|
@onConnectedInnerHtml
|
|
@@ -544,11 +551,54 @@ class TodoList extends HTMLElement {
|
|
|
544
551
|
- Remove temporary overlays
|
|
545
552
|
- Clean up modal dialogs
|
|
546
553
|
|
|
554
|
+
#### 15. `@queryHost` - Query :host Element
|
|
555
|
+
Specialized query for the component element itself. Supports automatic or explicit usage.
|
|
556
|
+
|
|
557
|
+
All usage patterns automatically set the element reference:
|
|
558
|
+
- Without parentheses: `@queryHost` self?: HTMLElement;
|
|
559
|
+
- Empty parentheses: `@queryHost()` self?: HTMLElement;
|
|
560
|
+
- With options: `@queryHost({ root: 'shadow' })` self?: HTMLElement;
|
|
561
|
+
|
|
562
|
+
```typescript
|
|
563
|
+
@elementDefine('custom-card')
|
|
564
|
+
class CustomCard extends HTMLElement {
|
|
565
|
+
@queryHost
|
|
566
|
+
self?: HTMLElement;
|
|
567
|
+
|
|
568
|
+
@queryHost()
|
|
569
|
+
selfExplicit?: HTMLElement;
|
|
570
|
+
|
|
571
|
+
printTag() {
|
|
572
|
+
console.log(this.self?.tagName); // Logs: CUSTOM-CARD
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
```
|
|
576
|
+
|
|
577
|
+
#### 16. `@queryAllHost` - Query All :host Children
|
|
578
|
+
Returns all children of the component element. Useful for accessing direct children.
|
|
579
|
+
|
|
580
|
+
All usage patterns automatically set the children array:
|
|
581
|
+
- Without parentheses: `@queryAllHost` children?: HTMLElement[];
|
|
582
|
+
- Empty parentheses: `@queryAllHost()` children?: HTMLElement[];
|
|
583
|
+
- With options: `@queryAllHost({ root: 'shadow' })` children?: HTMLElement[];
|
|
584
|
+
|
|
585
|
+
```typescript
|
|
586
|
+
@elementDefine('card-container')
|
|
587
|
+
class CardContainer extends HTMLElement {
|
|
588
|
+
@queryAllHost
|
|
589
|
+
allChildren?: HTMLElement[];
|
|
590
|
+
|
|
591
|
+
getChildCount() {
|
|
592
|
+
return this.allChildren?.length ?? 0;
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
```
|
|
596
|
+
|
|
547
597
|
---
|
|
548
598
|
|
|
549
599
|
### Event & Messaging Decorators
|
|
550
600
|
|
|
551
|
-
####
|
|
601
|
+
#### 17. `@addEventListener(selector, event, options?)`
|
|
552
602
|
Declarative event binding with automatic delegation.
|
|
553
603
|
|
|
554
604
|
```typescript
|
|
@@ -605,7 +655,7 @@ class TodoApp extends HTMLElement {
|
|
|
605
655
|
- ✅ Parent communication (`:parentHost`, `:appHost`)
|
|
606
656
|
- ✅ Auto-cleanup on `disconnectedCallback`
|
|
607
657
|
|
|
608
|
-
####
|
|
658
|
+
#### 18. `@emitCustomEvent(target, type, options?)`
|
|
609
659
|
Emit custom events to component hierarchy or global targets.
|
|
610
660
|
|
|
611
661
|
```typescript
|
|
@@ -683,40 +733,42 @@ class UserWidget extends HTMLElement {
|
|
|
683
733
|
|
|
684
734
|
### DOM Manipulation Decorators
|
|
685
735
|
|
|
686
|
-
####
|
|
736
|
+
#### 19. `@applyNode(selector, options?)`
|
|
687
737
|
Surgically add, update, or replace DOM nodes at specific positions.
|
|
688
738
|
|
|
689
739
|
```typescript
|
|
740
|
+
import { htmlDivElement, htmlFragment, htmlSpanElement } from '@dooboostore/simple-web-component';
|
|
741
|
+
|
|
690
742
|
@elementDefine('counter-display')
|
|
691
743
|
class CounterDisplay extends HTMLElement {
|
|
692
744
|
private count = 0;
|
|
693
745
|
private errorMessage = '';
|
|
694
746
|
|
|
695
|
-
// Replace all children with new content
|
|
747
|
+
// Replace all children with new content (return Node)
|
|
696
748
|
@applyNode('#display', { position: 'replaceChildren' })
|
|
697
749
|
updateDisplayCount() {
|
|
698
|
-
return
|
|
750
|
+
return htmlSpanElement(`${this.count}`);
|
|
699
751
|
}
|
|
700
752
|
|
|
701
|
-
// Append to container
|
|
753
|
+
// Append to container (return Node)
|
|
702
754
|
@applyNode('#history', { position: 'beforeEnd' })
|
|
703
755
|
addHistoryEntry() {
|
|
704
|
-
return `<p>Count was: ${this.count}</p
|
|
756
|
+
return htmlFragment(`<p>Count was: ${this.count}</p>`);
|
|
705
757
|
}
|
|
706
758
|
|
|
707
|
-
// Set HTML content
|
|
759
|
+
// Set HTML content (return string)
|
|
708
760
|
@applyNode('#status', { position: 'innerHtml' })
|
|
709
761
|
setStatus() {
|
|
710
762
|
return `<strong>Status: Active</strong>`;
|
|
711
763
|
}
|
|
712
764
|
|
|
713
|
-
// Set text content
|
|
765
|
+
// Set text content (return string)
|
|
714
766
|
@applyNode('#counter', { position: 'innerText' })
|
|
715
767
|
updateCounter() {
|
|
716
768
|
return this.count.toString();
|
|
717
769
|
}
|
|
718
770
|
|
|
719
|
-
// Remove element if condition is truthy
|
|
771
|
+
// Remove element if condition is truthy (return boolean)
|
|
720
772
|
@applyNode('#error-banner', { position: 'remove' })
|
|
721
773
|
dismissError() {
|
|
722
774
|
return this.errorMessage === ''; // Remove if no error
|
|
@@ -759,34 +811,160 @@ Control which DOM tree is searched with the `root` option:
|
|
|
759
811
|
Shorthand decorators for common position-specific operations:
|
|
760
812
|
|
|
761
813
|
**Position-Specific Variants:**
|
|
814
|
+
|
|
815
|
+
Return **DOM Nodes** for position-based insertion. Use DOM creation functions:
|
|
816
|
+
|
|
762
817
|
```typescript
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
@
|
|
767
|
-
|
|
768
|
-
@
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
@
|
|
818
|
+
import {
|
|
819
|
+
htmlFragment, htmlDivElement, htmlSpanElement,
|
|
820
|
+
createElement, textNode
|
|
821
|
+
} from '@dooboostore/simple-web-component';
|
|
822
|
+
|
|
823
|
+
@elementDefine('my-component')
|
|
824
|
+
class MyComponent extends HTMLElement {
|
|
825
|
+
// Method 1: Using htmlFragment (DocumentFragment)
|
|
826
|
+
@applyBeforeBeginNode('#target') prependTarget() {
|
|
827
|
+
return htmlFragment('<div>Before</div>');
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
// Method 2: Using htmlDivElement (single element)
|
|
831
|
+
@applyAfterBeginNode('#target') afterBeginTarget() {
|
|
832
|
+
return htmlDivElement('After Begin');
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
// Method 3: Manual createElement (full control)
|
|
836
|
+
@applyBeforeEndNode('#target') beforeEndTarget() {
|
|
837
|
+
return htmlDivElement('Before End');
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
@applyAfterEndNode('#target') afterEndTarget() {
|
|
841
|
+
const el = htmlDivElement('After');
|
|
842
|
+
el.classList.add('highlight');
|
|
843
|
+
return el;
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
@applyReplaceNode('#target') replaceTarget() {
|
|
847
|
+
return htmlFragment('<div class="replaced">Replaced</div>');
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
// Multiple nodes: return array
|
|
851
|
+
@applyReplaceChildrenNode('#target') replaceChildrenTarget() {
|
|
852
|
+
return [
|
|
853
|
+
htmlDivElement('Item 1'),
|
|
854
|
+
htmlDivElement('Item 2'),
|
|
855
|
+
htmlDivElement('Item 3')
|
|
856
|
+
];
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
// String return for innerHtml
|
|
860
|
+
@applyInnerHtmlNode('#target') setInnerHtml() {
|
|
861
|
+
return `<b>Bold</b> <i>Italic</i>`;
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
// String return for innerText
|
|
865
|
+
@applyInnerTextNode('#target') setInnerText() {
|
|
866
|
+
return 'Plain text';
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
// Boolean return for remove
|
|
870
|
+
@applyRemoveNode('#target') removeTarget() {
|
|
871
|
+
return this.shouldHideTarget;
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
```
|
|
875
|
+
|
|
876
|
+
**SSR Support (with custom Document):**
|
|
877
|
+
|
|
878
|
+
```typescript
|
|
879
|
+
// Browser
|
|
880
|
+
return htmlDivElement('Content'); // Uses global document
|
|
881
|
+
|
|
882
|
+
// SSR (e.g. Node.js with jsdom)
|
|
883
|
+
const ssrDocument = new JSDOM().window.document;
|
|
884
|
+
return htmlDivElement('Content', ssrDocument); // Pass custom doc
|
|
772
885
|
```
|
|
773
886
|
|
|
774
887
|
**Host-Targeted Variants (`:host` selector):**
|
|
888
|
+
|
|
889
|
+
All Host variants support three usage patterns:
|
|
890
|
+
- Without parentheses: `@applyBeforeBeginNodeHost` prependHost() { ... }
|
|
891
|
+
- With empty parentheses: `@applyBeforeBeginNodeHost()` prependHost() { ... }
|
|
892
|
+
- With options: `@applyBeforeBeginNodeHost({ ... })` prependHost() { ... }
|
|
893
|
+
|
|
775
894
|
```typescript
|
|
776
|
-
@
|
|
777
|
-
|
|
778
|
-
@
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
@
|
|
784
|
-
|
|
895
|
+
@elementDefine('my-component')
|
|
896
|
+
class MyComponent extends HTMLElement {
|
|
897
|
+
@applyBeforeBeginNodeHost
|
|
898
|
+
prependHost() {
|
|
899
|
+
return htmlFragment('<div>Before Host</div>');
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
@applyAfterBeginNodeHost() afterBeginHost() {
|
|
903
|
+
return htmlSpanElement('After Begin');
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
@applyBeforeEndNodeHost beforeEndHost() {
|
|
907
|
+
const el = htmlDivElement('Before End');
|
|
908
|
+
return el;
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
@applyAfterEndNodeHost afterEndHost() {
|
|
912
|
+
return htmlFragment('After Host');
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
@applyReplaceNodeHost replaceHost() {
|
|
916
|
+
return htmlFragment('<div>Replaced Host</div>');
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
// Multiple children in shadow DOM
|
|
920
|
+
@applyReplaceChildrenNodeHost() replaceChildrenHost() {
|
|
921
|
+
return [
|
|
922
|
+
htmlDivElement('Shadow Child 1'),
|
|
923
|
+
htmlDivElement('Shadow Child 2')
|
|
924
|
+
];
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
@applyInnerHtmlNodeHost setHostInnerHtml() {
|
|
928
|
+
return `<h1>Host Content</h1>`;
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
@applyInnerTextNodeHost() setHostInnerText() {
|
|
932
|
+
return 'Host text content';
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
@applyRemoveNodeHost removeHost() {
|
|
936
|
+
return this.isRemoved;
|
|
937
|
+
}
|
|
938
|
+
}
|
|
785
939
|
```
|
|
786
940
|
|
|
787
|
-
|
|
941
|
+
**Return Types by Position:**
|
|
942
|
+
- `beforeBegin`, `afterBegin`, `beforeEnd`, `afterEnd`: **Node | Node[]**
|
|
943
|
+
- `replace`: **Node**
|
|
944
|
+
- `replaceChildren`: **Node | Node[]**
|
|
945
|
+
- `innerHtml`: **string**
|
|
946
|
+
- `innerText`: **string**
|
|
947
|
+
- `remove`: **boolean** (truthy = remove)
|
|
948
|
+
|
|
949
|
+
**Available DOM Functions:**
|
|
950
|
+
- `htmlFragment(html, doc?)` - Create DocumentFragment from HTML
|
|
951
|
+
- `textNode(text, doc?)` - Create Text node
|
|
952
|
+
- `commentNode(comment, doc?)` - Create Comment node
|
|
953
|
+
- `createElement(tagName, options?, doc?)` - Create any element with attributes
|
|
954
|
+
- `htmlDivElement(html, doc?)` - Create div element
|
|
955
|
+
- `htmlSpanElement(html, doc?)` - Create span element
|
|
956
|
+
- `htmlButtonElement(html, doc?)` - Create button element
|
|
957
|
+
- `htmlAElement(html, href?, doc?)` - Create anchor element
|
|
958
|
+
- `htmlPElement(html, doc?)` - Create paragraph element
|
|
959
|
+
- `htmlLiElement(html, doc?)` - Create list item element
|
|
960
|
+
- `htmlUlElement(doc?)` - Create unordered list
|
|
961
|
+
- `htmlHeadingElement(level, html, doc?)` - Create h1-h6
|
|
962
|
+
- `htmlSectionElement(doc?)` - Create section
|
|
963
|
+
- `htmlArticleElement(doc?)` - Create article
|
|
788
964
|
|
|
789
|
-
|
|
965
|
+
**All functions accept optional `doc` parameter for SSR support.**
|
|
966
|
+
|
|
967
|
+
#### 20. `@setStyle(selector, options?)` / `@updateStyle(selector, options?)` / `@removeStyle(selector, options?)`
|
|
790
968
|
|
|
791
969
|
Manipulate CSS styles on elements with full Shadow DOM support.
|
|
792
970
|
|
|
@@ -839,18 +1017,26 @@ class StyledComponent extends HTMLElement {
|
|
|
839
1017
|
```
|
|
840
1018
|
|
|
841
1019
|
**Host-Targeted Variants:**
|
|
1020
|
+
|
|
1021
|
+
Note: `:host` selector targets the component itself (boundary), so `root` option is ignored.
|
|
1022
|
+
|
|
1023
|
+
All Host variants support three usage patterns:
|
|
1024
|
+
- Without parentheses: `@setStyleHost` setHostStyle() { ... }
|
|
1025
|
+
- With empty parentheses: `@setStyleHost()` setHostStyle() { ... }
|
|
1026
|
+
- With options: `@setStyleHost({ ... })` setHostStyle() { ... }
|
|
1027
|
+
|
|
842
1028
|
```typescript
|
|
843
|
-
@setStyleHost
|
|
1029
|
+
@setStyleHost
|
|
844
1030
|
setHostStyle() {
|
|
845
1031
|
return { display: 'flex', gap: '10px' };
|
|
846
1032
|
}
|
|
847
1033
|
|
|
848
|
-
@updateStyleHost(
|
|
1034
|
+
@updateStyleHost()
|
|
849
1035
|
updateHostStyle() {
|
|
850
1036
|
return { backgroundColor: '#f0f0f0' };
|
|
851
1037
|
}
|
|
852
1038
|
|
|
853
|
-
@removeStyleHost(
|
|
1039
|
+
@removeStyleHost()
|
|
854
1040
|
clearHostStyle() {
|
|
855
1041
|
return ['backgroundColor'];
|
|
856
1042
|
}
|
|
@@ -858,7 +1044,7 @@ clearHostStyle() {
|
|
|
858
1044
|
|
|
859
1045
|
---
|
|
860
1046
|
|
|
861
|
-
####
|
|
1047
|
+
#### 21. `@setClassList(selector, options?)` / `@addClassList(selector, options?)` / `@removeClassList(selector, options?)` / `@toggleClassList(selector, options?)` / `@updateClassList(selector, options?)`
|
|
862
1048
|
|
|
863
1049
|
Manipulate CSS classes on elements declaratively with Shadow DOM support.
|
|
864
1050
|
|
|
@@ -914,28 +1100,36 @@ class TabComponent extends HTMLElement {
|
|
|
914
1100
|
```
|
|
915
1101
|
|
|
916
1102
|
**Host-Targeted Variants:**
|
|
1103
|
+
|
|
1104
|
+
Note: `:host` selector targets the component itself (boundary), so `root` option is ignored.
|
|
1105
|
+
|
|
1106
|
+
All Host variants support three usage patterns:
|
|
1107
|
+
- Without parentheses: `@setClassListHost` setHostClasses() { ... }
|
|
1108
|
+
- With empty parentheses: `@setClassListHost()` setHostClasses() { ... }
|
|
1109
|
+
- With options: `@setClassListHost({ ... })` setHostClasses() { ... }
|
|
1110
|
+
|
|
917
1111
|
```typescript
|
|
918
|
-
@addClassListHost
|
|
1112
|
+
@addClassListHost
|
|
919
1113
|
addHostClasses() {
|
|
920
1114
|
return ['component', 'interactive'];
|
|
921
1115
|
}
|
|
922
1116
|
|
|
923
|
-
@removeClassListHost(
|
|
1117
|
+
@removeClassListHost()
|
|
924
1118
|
removeHostClasses() {
|
|
925
1119
|
return ['loading'];
|
|
926
1120
|
}
|
|
927
1121
|
|
|
928
|
-
@toggleClassListHost(
|
|
1122
|
+
@toggleClassListHost()
|
|
929
1123
|
toggleHostClass() {
|
|
930
1124
|
return this.isOpen; // Apply 'open' class if true
|
|
931
1125
|
}
|
|
932
1126
|
|
|
933
|
-
@setClassListHost
|
|
1127
|
+
@setClassListHost
|
|
934
1128
|
setHostClasses() {
|
|
935
1129
|
return this.isOpen ? ['open', 'expanded'] : ['closed'];
|
|
936
1130
|
}
|
|
937
1131
|
|
|
938
|
-
@updateClassListHost(
|
|
1132
|
+
@updateClassListHost()
|
|
939
1133
|
updateHostClasses() {
|
|
940
1134
|
return ['visible'];
|
|
941
1135
|
}
|
|
@@ -945,7 +1139,7 @@ updateHostClasses() {
|
|
|
945
1139
|
|
|
946
1140
|
### Dependency Injection & Singleton
|
|
947
1141
|
|
|
948
|
-
####
|
|
1142
|
+
#### 22. `@Sim`
|
|
949
1143
|
Marks a class as a **Singleton** in the `<swc-app>` DI container for **constructor injection**.
|
|
950
1144
|
|
|
951
1145
|
**Two DI Mechanisms:**
|
|
@@ -43,6 +43,7 @@ __export(applyNode_exports, {
|
|
|
43
43
|
module.exports = __toCommonJS(applyNode_exports);
|
|
44
44
|
var import_core = require("@dooboostore/core");
|
|
45
45
|
var import_elementDefine = require("./elementDefine");
|
|
46
|
+
var import_Utils = require("../utils/Utils");
|
|
46
47
|
const APPLY_NODE_METADATA_KEY = Symbol("simple-web-component:apply-node");
|
|
47
48
|
const normalizeNodes = (res, doc) => {
|
|
48
49
|
const items = Array.isArray(res) ? res : [res];
|
|
@@ -71,15 +72,20 @@ function applyNode(selector, options = { position: "beforeEnd" }) {
|
|
|
71
72
|
const currentDoc = currentWin.document;
|
|
72
73
|
const pos = options.position || "beforeEnd";
|
|
73
74
|
const r = options.root || "auto";
|
|
74
|
-
const
|
|
75
|
+
const applyRoot = (t) => {
|
|
76
|
+
if (!t || !(t instanceof HTMLElement))
|
|
77
|
+
return t;
|
|
78
|
+
if (r === "auto")
|
|
79
|
+
return t.shadowRoot || t;
|
|
75
80
|
if (r === "shadow")
|
|
76
|
-
return
|
|
81
|
+
return t.shadowRoot;
|
|
77
82
|
if (r === "light")
|
|
78
|
-
return
|
|
83
|
+
return t;
|
|
79
84
|
if (r === "all")
|
|
80
|
-
return
|
|
81
|
-
return
|
|
85
|
+
return t.shadowRoot || t;
|
|
86
|
+
return t;
|
|
82
87
|
};
|
|
88
|
+
const hostSet = import_Utils.SwcUtils.getHostSet(this);
|
|
83
89
|
if (pos === "remove") {
|
|
84
90
|
if (res) {
|
|
85
91
|
if (selector === ":host" || !selector) {
|
|
@@ -89,7 +95,7 @@ function applyNode(selector, options = { position: "beforeEnd" }) {
|
|
|
89
95
|
this.remove();
|
|
90
96
|
}
|
|
91
97
|
} else {
|
|
92
|
-
const targetRoot =
|
|
98
|
+
const targetRoot = applyRoot(this);
|
|
93
99
|
if (targetRoot) {
|
|
94
100
|
const targets = targetRoot.querySelectorAll(selector);
|
|
95
101
|
targets.forEach((el) => el.remove());
|
|
@@ -98,14 +104,22 @@ function applyNode(selector, options = { position: "beforeEnd" }) {
|
|
|
98
104
|
}
|
|
99
105
|
} else {
|
|
100
106
|
let targetEl = null;
|
|
101
|
-
if (selector === ":host"
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
+
if (selector === ":host") {
|
|
108
|
+
targetEl = applyRoot(this);
|
|
109
|
+
} else if (selector === ":parentHost") {
|
|
110
|
+
targetEl = applyRoot(hostSet.$parentHost);
|
|
111
|
+
} else if (selector === ":appHost") {
|
|
112
|
+
targetEl = applyRoot(hostSet.$appHost);
|
|
113
|
+
} else if (selector === ":firstHost") {
|
|
114
|
+
targetEl = applyRoot(hostSet.$firstHost);
|
|
115
|
+
} else if (selector === ":lastHost") {
|
|
116
|
+
targetEl = applyRoot(hostSet.$lastHost);
|
|
117
|
+
} else if (selector === ":firstAppHost") {
|
|
118
|
+
targetEl = applyRoot(hostSet.$firstHost);
|
|
119
|
+
} else if (selector === ":lastAppHost") {
|
|
120
|
+
targetEl = applyRoot(hostSet.$lastAppHost);
|
|
107
121
|
} else {
|
|
108
|
-
const targetRoot =
|
|
122
|
+
const targetRoot = applyRoot(this);
|
|
109
123
|
targetEl = targetRoot ? targetRoot.querySelector(selector) : null;
|
|
110
124
|
}
|
|
111
125
|
if (targetEl) {
|
|
@@ -150,25 +164,106 @@ const findAllApplyNodeMetadata = (target) => {
|
|
|
150
164
|
});
|
|
151
165
|
return result;
|
|
152
166
|
};
|
|
153
|
-
function applyNodeHost(
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
167
|
+
function applyNodeHost(targetOrOptions, propertyKey, descriptor) {
|
|
168
|
+
console.log("vvvvv");
|
|
169
|
+
if (propertyKey !== void 0 && typeof propertyKey === "string" || typeof propertyKey === "symbol") {
|
|
170
|
+
return applyNode(":host", { position: "beforeEnd" })(targetOrOptions, propertyKey, descriptor);
|
|
171
|
+
}
|
|
172
|
+
if (typeof targetOrOptions === "object" && targetOrOptions !== null) {
|
|
173
|
+
const options = targetOrOptions;
|
|
174
|
+
return applyNode(":host", { ...options, position: options.position || "beforeEnd" });
|
|
175
|
+
} else {
|
|
176
|
+
return applyNode(":host", { position: "beforeEnd" });
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
function applyBeforeBeginNode(selector, options) {
|
|
180
|
+
return applyNode(selector, { ...options, position: "beforeBegin" });
|
|
181
|
+
}
|
|
182
|
+
function applyAfterBeginNode(selector, options) {
|
|
183
|
+
return applyNode(selector, { ...options, position: "afterBegin" });
|
|
184
|
+
}
|
|
185
|
+
function applyBeforeEndNode(selector, options) {
|
|
186
|
+
return applyNode(selector, { ...options, position: "beforeEnd" });
|
|
187
|
+
}
|
|
188
|
+
function applyAfterEndNode(selector, options) {
|
|
189
|
+
return applyNode(selector, { ...options, position: "afterEnd" });
|
|
190
|
+
}
|
|
191
|
+
function applyReplaceNode(selector, options) {
|
|
192
|
+
return applyNode(selector, { ...options, position: "replace" });
|
|
193
|
+
}
|
|
194
|
+
function applyReplaceChildrenNode(selector, options) {
|
|
195
|
+
return applyNode(selector, { ...options, position: "replaceChildren" });
|
|
196
|
+
}
|
|
197
|
+
function applyInnerHtmlNode(selector, options) {
|
|
198
|
+
return applyNode(selector, { ...options, position: "innerHtml" });
|
|
199
|
+
}
|
|
200
|
+
function applyInnerTextNode(selector, options) {
|
|
201
|
+
return applyNode(selector, { ...options, position: "innerText" });
|
|
202
|
+
}
|
|
203
|
+
function applyRemoveNode(selector, options) {
|
|
204
|
+
return applyNode(selector, { ...options, position: "remove" });
|
|
205
|
+
}
|
|
206
|
+
function applyBeforeBeginNodeHost(targetOrOptions, propertyKey, descriptor) {
|
|
207
|
+
if (propertyKey !== void 0) {
|
|
208
|
+
const decorator = applyNode(":host", { position: "beforeBegin" });
|
|
209
|
+
return decorator(targetOrOptions, propertyKey, descriptor);
|
|
210
|
+
}
|
|
211
|
+
return applyNode(":host", { ...targetOrOptions || {}, position: "beforeBegin" });
|
|
212
|
+
}
|
|
213
|
+
function applyAfterBeginNodeHost(optionsOrTarget, propertyKey, descriptor) {
|
|
214
|
+
if (propertyKey !== void 0) {
|
|
215
|
+
const decorator = applyNode(":host", { position: "afterBegin" });
|
|
216
|
+
return decorator(optionsOrTarget, propertyKey, descriptor);
|
|
217
|
+
}
|
|
218
|
+
return applyNode(":host", { ...optionsOrTarget || {}, position: "afterBegin" });
|
|
219
|
+
}
|
|
220
|
+
function applyBeforeEndNodeHost(optionsOrTarget, propertyKey, descriptor) {
|
|
221
|
+
if (propertyKey !== void 0) {
|
|
222
|
+
const decorator = applyNode(":host", { position: "beforeEnd" });
|
|
223
|
+
return decorator(optionsOrTarget, propertyKey, descriptor);
|
|
224
|
+
}
|
|
225
|
+
return applyNode(":host", { ...optionsOrTarget || {}, position: "beforeEnd" });
|
|
226
|
+
}
|
|
227
|
+
function applyAfterEndNodeHost(optionsOrTarget, propertyKey, descriptor) {
|
|
228
|
+
if (propertyKey !== void 0) {
|
|
229
|
+
const decorator = applyNode(":host", { position: "afterEnd" });
|
|
230
|
+
return decorator(optionsOrTarget, propertyKey, descriptor);
|
|
231
|
+
}
|
|
232
|
+
return applyNode(":host", { ...optionsOrTarget || {}, position: "afterEnd" });
|
|
233
|
+
}
|
|
234
|
+
function applyReplaceNodeHost(optionsOrTarget, propertyKey, descriptor) {
|
|
235
|
+
if (propertyKey !== void 0) {
|
|
236
|
+
const decorator = applyNode(":host", { position: "replace" });
|
|
237
|
+
return decorator(optionsOrTarget, propertyKey, descriptor);
|
|
238
|
+
}
|
|
239
|
+
return applyNode(":host", { ...optionsOrTarget || {}, position: "replace" });
|
|
240
|
+
}
|
|
241
|
+
function applyReplaceChildrenNodeHost(optionsOrTarget, propertyKey, descriptor) {
|
|
242
|
+
if (propertyKey !== void 0) {
|
|
243
|
+
const decorator = applyNode(":host", { position: "replaceChildren" });
|
|
244
|
+
return decorator(optionsOrTarget, propertyKey, descriptor);
|
|
245
|
+
}
|
|
246
|
+
return applyNode(":host", { ...optionsOrTarget || {}, position: "replaceChildren" });
|
|
247
|
+
}
|
|
248
|
+
function applyInnerHtmlNodeHost(optionsOrTarget, propertyKey, descriptor) {
|
|
249
|
+
if (propertyKey !== void 0) {
|
|
250
|
+
const decorator = applyNode(":host", { position: "innerHtml" });
|
|
251
|
+
return decorator(optionsOrTarget, propertyKey, descriptor);
|
|
252
|
+
}
|
|
253
|
+
return applyNode(":host", { ...optionsOrTarget || {}, position: "innerHtml" });
|
|
254
|
+
}
|
|
255
|
+
function applyInnerTextNodeHost(optionsOrTarget, propertyKey, descriptor) {
|
|
256
|
+
if (propertyKey !== void 0) {
|
|
257
|
+
const decorator = applyNode(":host", { position: "innerText" });
|
|
258
|
+
return decorator(optionsOrTarget, propertyKey, descriptor);
|
|
259
|
+
}
|
|
260
|
+
return applyNode(":host", { ...optionsOrTarget || {}, position: "innerText" });
|
|
261
|
+
}
|
|
262
|
+
function applyRemoveNodeHost(optionsOrTarget, propertyKey, descriptor) {
|
|
263
|
+
if (propertyKey !== void 0) {
|
|
264
|
+
const decorator = applyNode(":host", { position: "remove" });
|
|
265
|
+
return decorator(optionsOrTarget, propertyKey, descriptor);
|
|
266
|
+
}
|
|
267
|
+
return applyNode(":host", { ...optionsOrTarget || {}, position: "remove" });
|
|
268
|
+
}
|
|
174
269
|
//# sourceMappingURL=applyNode.js.map
|