@dooboostore/simple-web-component 1.0.42 → 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 +689 -85
- package/dist/cjs/SwcAppEngine.js +3 -1
- package/dist/cjs/SwcAppEngine.js.map +2 -2
- package/dist/cjs/decorators/addEventListener.js +10 -0
- package/dist/cjs/decorators/addEventListener.js.map +2 -2
- package/dist/cjs/decorators/applyAttribute.js +41 -30
- package/dist/cjs/decorators/applyAttribute.js.map +2 -2
- package/dist/cjs/decorators/applyClass.js +66 -23
- package/dist/cjs/decorators/applyClass.js.map +3 -3
- package/dist/cjs/decorators/applyNode.js +176 -107
- package/dist/cjs/decorators/applyNode.js.map +2 -2
- package/dist/cjs/decorators/applyProperty.js +21 -30
- package/dist/cjs/decorators/applyProperty.js.map +2 -2
- package/dist/cjs/decorators/applySlot.js +11 -2
- package/dist/cjs/decorators/applySlot.js.map +2 -2
- package/dist/cjs/decorators/applyStyle.js +48 -17
- 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 +58 -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 +37 -23
- 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 +10 -0
- package/dist/esm/decorators/addEventListener.js.map +2 -2
- package/dist/esm/decorators/applyAttribute.js +41 -30
- package/dist/esm/decorators/applyAttribute.js.map +2 -2
- package/dist/esm/decorators/applyClass.js +66 -23
- package/dist/esm/decorators/applyClass.js.map +3 -3
- package/dist/esm/decorators/applyNode.js +176 -107
- package/dist/esm/decorators/applyNode.js.map +2 -2
- package/dist/esm/decorators/applyProperty.js +21 -30
- package/dist/esm/decorators/applyProperty.js.map +2 -2
- package/dist/esm/decorators/applySlot.js +11 -2
- package/dist/esm/decorators/applySlot.js.map +2 -2
- package/dist/esm/decorators/applyStyle.js +48 -17
- 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 +58 -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 +37 -23
- 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 +900 -578
- 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 +22 -14
- package/dist/types/decorators/addEventListener.d.ts.map +1 -1
- package/dist/types/decorators/applyAttribute.d.ts +61 -20
- package/dist/types/decorators/applyAttribute.d.ts.map +1 -1
- package/dist/types/decorators/applyClass.d.ts +22 -36
- package/dist/types/decorators/applyClass.d.ts.map +1 -1
- package/dist/types/decorators/applyNode.d.ts +178 -30
- package/dist/types/decorators/applyNode.d.ts.map +1 -1
- package/dist/types/decorators/applyProperty.d.ts +53 -18
- package/dist/types/decorators/applyProperty.d.ts.map +1 -1
- package/dist/types/decorators/applySlot.d.ts +6 -0
- package/dist/types/decorators/applySlot.d.ts.map +1 -1
- package/dist/types/decorators/applyStyle.d.ts +13 -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 +20 -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 +19 -0
- 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 +900 -578
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +7 -9
- package/src/SwcAppEngine.ts +3 -1
- package/src/decorators/addEventListener.ts +35 -24
- package/src/decorators/applyAttribute.ts +167 -65
- package/src/decorators/applyClass.ts +113 -17
- package/src/decorators/applyNode.ts +383 -102
- package/src/decorators/applyProperty.ts +99 -65
- package/src/decorators/applySlot.ts +24 -10
- package/src/decorators/applyStyle.ts +83 -13
- package/src/decorators/{changedAttributeThis.ts → changedAttribute.ts} +1 -1
- package/src/decorators/elementDefine.ts +47 -4
- package/src/decorators/emitCustomEvent.ts +62 -35
- package/src/decorators/index.ts +1 -1
- package/src/decorators/publishSwcAppMessage.ts +71 -27
- 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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dooboostore/simple-web-component",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.44",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/cjs/index.js",
|
|
@@ -67,11 +67,7 @@
|
|
|
67
67
|
},
|
|
68
68
|
"author": "dooboostore <dooboostore@gmail.com> (https://github.com/dooboostore)",
|
|
69
69
|
"peerDependencies": {
|
|
70
|
-
"reflect-metadata": "^0.2.2"
|
|
71
|
-
"@dooboostore/core": "1.0.32",
|
|
72
|
-
"@dooboostore/simple-boot": "1.0.56",
|
|
73
|
-
"@dooboostore/core-web": "1.0.12",
|
|
74
|
-
"@dooboostore/core-node": "1.0.12"
|
|
70
|
+
"reflect-metadata": "^0.2.2"
|
|
75
71
|
},
|
|
76
72
|
"devDependencies": {
|
|
77
73
|
"@babel/core": "^7.24.0",
|
|
@@ -95,7 +91,11 @@
|
|
|
95
91
|
"typescript": "^5.9.2",
|
|
96
92
|
"webpack": "^5.93.0",
|
|
97
93
|
"webpack-cli": "^5.1.4",
|
|
98
|
-
"webpack-dev-server": "^5.2.0"
|
|
94
|
+
"webpack-dev-server": "^5.2.0",
|
|
95
|
+
"@dooboostore/core": "1.0.32",
|
|
96
|
+
"@dooboostore/core-web": "1.0.12",
|
|
97
|
+
"@dooboostore/simple-boot": "1.0.56",
|
|
98
|
+
"@dooboostore/core-node": "1.0.12"
|
|
99
99
|
},
|
|
100
100
|
"scripts": {
|
|
101
101
|
"clean": "rm -rf dist",
|
|
@@ -112,8 +112,6 @@
|
|
|
112
112
|
"publish:npm": "pnpm run build && cp package.json package.json.back && pnpm pack && TARBALL_NAME=$(ls dooboostore-simple-web-component-*.tgz | head -n 1) && tar -xzf \"$TARBALL_NAME\" -C . --strip-components=1 package/package.json && rm \"$TARBALL_NAME\" && (pnpm publish --no-git-checks || true) && cp package.json.back package.json && rm -rf package.json.back ",
|
|
113
113
|
"ts:clean": "find . -name '*.js' -o -name '*.map' -o -name '*.d.ts' | xargs rm -f",
|
|
114
114
|
"typecheck": "pnpm exec tsc --noEmit",
|
|
115
|
-
"generate:is": "tsx generate-is.ts",
|
|
116
|
-
"generate:is:watch": "node --import tsx --watch --watch-path=./src/elements/SwcIf.ts --watch-path=./src/elements/SwcLoop.ts --watch-path=./src/elements/SwcChoose.ts --watch-path=./src/elements/SwcAsync.ts --watch-path=./src/elements/SwcAppMixin.ts --watch-path=./generate-is.ts generate-is.ts",
|
|
117
115
|
"test": "echo test",
|
|
118
116
|
"test:bundle": "pnpm --filter @dooboostore/simple-web-component-bundle-test dev"
|
|
119
117
|
}
|
package/src/SwcAppEngine.ts
CHANGED
|
@@ -78,7 +78,9 @@ export class SwcAppEngine {
|
|
|
78
78
|
|
|
79
79
|
if (this._config.onStartedLazyDefineComponent) {
|
|
80
80
|
// console.log('-------->', this._config.onStartedLazyDefineComponent)
|
|
81
|
-
await Promise.all(this._config.onStartedLazyDefineComponent.map(it =>
|
|
81
|
+
await Promise.all(this._config.onStartedLazyDefineComponent.map(it => {
|
|
82
|
+
it(this._config.window);
|
|
83
|
+
}))
|
|
82
84
|
}
|
|
83
85
|
if (this._config.onEngineStarted) {
|
|
84
86
|
await this._config.onEngineStarted(this.simpleApplication, this.host as unknown as SwcAppInterface);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ReflectUtils } from '@dooboostore/core';
|
|
2
2
|
import { SpecialSelector, SwcQueryOptions, HelperHostSet } from '../types';
|
|
3
3
|
|
|
4
|
-
export interface AddEventListenerBaseOptions extends EventListenerOptions {
|
|
4
|
+
export interface AddEventListenerBaseOptions<TEvent extends Event = Event> extends EventListenerOptions {
|
|
5
5
|
capture?: boolean;
|
|
6
6
|
once?: boolean;
|
|
7
7
|
passive?: boolean;
|
|
@@ -11,27 +11,31 @@ export interface AddEventListenerBaseOptions extends EventListenerOptions {
|
|
|
11
11
|
// removeOnDisconnected?: boolean;
|
|
12
12
|
delegate?: boolean;
|
|
13
13
|
filter?: (target: Event | CustomEvent, meta:{currentThis: any, helper: HelperHostSet}) => boolean;
|
|
14
|
+
// RxJS operator options
|
|
15
|
+
debounceTime?: number;
|
|
16
|
+
throttleTime?: number;
|
|
17
|
+
distinctUntilChanged?: boolean | ((prev: TEvent, curr: TEvent) => boolean);
|
|
14
18
|
}
|
|
15
19
|
|
|
16
|
-
export interface AddEventListenerMetadata {
|
|
20
|
+
export interface AddEventListenerMetadata<TEvent extends Event = Event> {
|
|
17
21
|
propertyKey: string | symbol;
|
|
18
22
|
selector: string;
|
|
19
23
|
type: string;
|
|
20
|
-
options: AddEventListenerBaseOptions & SwcQueryOptions & { delegate?: boolean };
|
|
24
|
+
options: AddEventListenerBaseOptions<TEvent> & SwcQueryOptions & { delegate?: boolean };
|
|
21
25
|
}
|
|
22
26
|
|
|
23
27
|
export const ADD_EVENT_LISTENER_METADATA_KEY = Symbol.for('simple-web-component:add-event-listener');
|
|
24
28
|
|
|
25
|
-
export function addEventListener(target: SpecialSelector, type: string, options?: AddEventListenerBaseOptions): MethodDecorator;
|
|
26
|
-
export function addEventListener(selector: string, type: string, options?: AddEventListenerBaseOptions & SwcQueryOptions & { delegate?: boolean }): MethodDecorator;
|
|
29
|
+
export function addEventListener<TEvent extends Event = Event>(target: SpecialSelector, type: string, options?: AddEventListenerBaseOptions<TEvent>): MethodDecorator;
|
|
30
|
+
export function addEventListener<TEvent extends Event = Event>(selector: string, type: string, options?: AddEventListenerBaseOptions<TEvent> & SwcQueryOptions & { delegate?: boolean }): MethodDecorator;
|
|
27
31
|
/**
|
|
28
32
|
* @addEventListener decorator to bind events to elements.
|
|
29
33
|
*/
|
|
30
|
-
export function addEventListener(selectorOrTarget: string, type: string, options: any = {}): MethodDecorator {
|
|
34
|
+
export function addEventListener<TEvent extends Event = Event>(selectorOrTarget: string, type: string, options: any = {}): MethodDecorator {
|
|
31
35
|
return (targetObj: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {
|
|
32
36
|
const constructor = targetObj.constructor;
|
|
33
37
|
|
|
34
|
-
let listeners = ReflectUtils.getMetadata<AddEventListenerMetadata[]>(ADD_EVENT_LISTENER_METADATA_KEY, constructor);
|
|
38
|
+
let listeners = ReflectUtils.getMetadata<AddEventListenerMetadata<TEvent>[]>(ADD_EVENT_LISTENER_METADATA_KEY, constructor);
|
|
35
39
|
if (!listeners) {
|
|
36
40
|
listeners = [];
|
|
37
41
|
ReflectUtils.defineMetadata(ADD_EVENT_LISTENER_METADATA_KEY, listeners, constructor);
|
|
@@ -42,42 +46,49 @@ export function addEventListener(selectorOrTarget: string, type: string, options
|
|
|
42
46
|
}
|
|
43
47
|
|
|
44
48
|
|
|
45
|
-
export function addEventListenerDelegateLightDom(selector: string, type: string, options?: Omit<AddEventListenerBaseOptions
|
|
46
|
-
return addEventListener(selector, type, {...options??{}, root:'light', delegate: true});
|
|
49
|
+
export function addEventListenerDelegateLightDom<TEvent extends Event = Event>(selector: string, type: string, options?: Omit<AddEventListenerBaseOptions<TEvent>, 'delegate'>): MethodDecorator {
|
|
50
|
+
return addEventListener<TEvent>(selector, type, {...options??{}, root:'light', delegate: true});
|
|
47
51
|
}
|
|
48
52
|
|
|
49
|
-
export function addEventListenerDelegateShadowDom(selector: string, type: string, options?: Omit<AddEventListenerBaseOptions
|
|
50
|
-
return addEventListener(selector, type, {...options??{}, root:'shadow', delegate: true});
|
|
53
|
+
export function addEventListenerDelegateShadowDom<TEvent extends Event = Event>(selector: string, type: string, options?: Omit<AddEventListenerBaseOptions<TEvent>, 'delegate'>): MethodDecorator {
|
|
54
|
+
return addEventListener<TEvent>(selector, type, {...options??{}, root:'shadow', delegate: true});
|
|
51
55
|
}
|
|
52
|
-
export function addEventListenerDelegateAllDom(selector: string, type: string, options?: Omit<AddEventListenerBaseOptions
|
|
53
|
-
return addEventListener(selector, type, {...options??{}, root:'all', delegate: true});
|
|
56
|
+
export function addEventListenerDelegateAllDom<TEvent extends Event = Event>(selector: string, type: string, options?: Omit<AddEventListenerBaseOptions<TEvent>, 'delegate'>): MethodDecorator {
|
|
57
|
+
return addEventListener<TEvent>(selector, type, {...options??{}, root:'all', delegate: true});
|
|
54
58
|
}
|
|
55
|
-
export function addEventListenerDelegate(selector: string, type: string, options?: Omit<AddEventListenerBaseOptions
|
|
56
|
-
return addEventListener(selector, type, {...options??{}, root:'auto', delegate: true});
|
|
59
|
+
export function addEventListenerDelegate<TEvent extends Event = Event>(selector: string, type: string, options?: Omit<AddEventListenerBaseOptions<TEvent>, 'delegate'>): MethodDecorator {
|
|
60
|
+
return addEventListener<TEvent>(selector, type, {...options??{}, root:'auto', delegate: true});
|
|
57
61
|
}
|
|
58
62
|
|
|
59
63
|
/**
|
|
60
64
|
* @addEventListenerThis decorator - simplified version of @addEventListener for $this selector
|
|
61
65
|
*/
|
|
62
|
-
|
|
63
|
-
|
|
66
|
+
|
|
67
|
+
// --- Aliases: event... ---
|
|
68
|
+
export const event = addEventListener;
|
|
69
|
+
export const eventDelegateLightDom = addEventListenerDelegateLightDom;
|
|
70
|
+
export const eventDelegateShadowDom = addEventListenerDelegateShadowDom;
|
|
71
|
+
export const eventDelegateAllDom = addEventListenerDelegateAllDom;
|
|
72
|
+
export const eventDelegate = addEventListenerDelegate;
|
|
73
|
+
export function addEventListenerThis<TEvent extends Event = Event>(type: string, options?: AddEventListenerBaseOptions<TEvent> & SwcQueryOptions): MethodDecorator {
|
|
74
|
+
return addEventListener<TEvent>('$this', type, options);
|
|
64
75
|
}
|
|
65
76
|
|
|
66
77
|
/**
|
|
67
78
|
* @addEventListenerAppHost decorator - simplified version of @addEventListener for $appHost selector
|
|
68
79
|
*/
|
|
69
|
-
export function addEventListenerAppHost(type: string, options?: AddEventListenerBaseOptions & SwcQueryOptions): MethodDecorator {
|
|
70
|
-
return addEventListener('$appHost', type, options);
|
|
80
|
+
export function addEventListenerAppHost<TEvent extends Event = Event>(type: string, options?: AddEventListenerBaseOptions<TEvent> & SwcQueryOptions): MethodDecorator {
|
|
81
|
+
return addEventListener<TEvent>('$appHost', type, options);
|
|
71
82
|
}
|
|
72
83
|
|
|
73
|
-
export function addEventListenerWindow(type: string, options?: AddEventListenerBaseOptions & SwcQueryOptions): MethodDecorator {
|
|
74
|
-
return addEventListener('$window', type, options);
|
|
84
|
+
export function addEventListenerWindow<TEvent extends Event = Event>(type: string, options?: AddEventListenerBaseOptions<TEvent> & SwcQueryOptions): MethodDecorator {
|
|
85
|
+
return addEventListener<TEvent>('$window', type, options);
|
|
75
86
|
}
|
|
76
|
-
export function addEventListenerDocument(type: string, options?: AddEventListenerBaseOptions & SwcQueryOptions): MethodDecorator {
|
|
77
|
-
return addEventListener('$document', type, options);
|
|
87
|
+
export function addEventListenerDocument<TEvent extends Event = Event>(type: string, options?: AddEventListenerBaseOptions<TEvent> & SwcQueryOptions): MethodDecorator {
|
|
88
|
+
return addEventListener<TEvent>('$document', type, options);
|
|
78
89
|
}
|
|
79
90
|
|
|
80
|
-
export const getAddEventListenerMetadata = (target: any): AddEventListenerMetadata[] | undefined => {
|
|
91
|
+
export const getAddEventListenerMetadata = (target: any): AddEventListenerMetadata<Event>[] | undefined => {
|
|
81
92
|
const constructor = target instanceof Function ? target : target.constructor;
|
|
82
93
|
return ReflectUtils.getMetadata(ADD_EVENT_LISTENER_METADATA_KEY, constructor);
|
|
83
94
|
};
|
|
@@ -12,6 +12,32 @@ export interface AttributeOptions extends SwcQueryOptions {
|
|
|
12
12
|
name?: string;
|
|
13
13
|
type?: typeof Number | typeof Boolean | typeof String;
|
|
14
14
|
filter?: (target: HTMLElement, value: any, meta: { currentThis: any, helper: HelperHostSet }) => boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Custom key to extract value from return object.
|
|
17
|
+
* If not provided, uses ATTRIBUTE_METADATA_KEY by default.
|
|
18
|
+
* Useful when multiple @setAttribute decorators are on the same method.
|
|
19
|
+
*
|
|
20
|
+
* Example:
|
|
21
|
+
* @setAttribute('selector1', { valueKey: 'attr1' })
|
|
22
|
+
* @setAttribute('selector2', { valueKey: 'attr2' })
|
|
23
|
+
* myMethod() {
|
|
24
|
+
* return {
|
|
25
|
+
* attr1: 'value1',
|
|
26
|
+
* attr2: 'value2'
|
|
27
|
+
* };
|
|
28
|
+
* }
|
|
29
|
+
*
|
|
30
|
+
* Or with symbols:
|
|
31
|
+
* @setAttribute('selector1', { valueKey: Symbol.for('attr1') })
|
|
32
|
+
* @setAttribute('selector2', { valueKey: Symbol.for('attr2') })
|
|
33
|
+
* myMethod() {
|
|
34
|
+
* return {
|
|
35
|
+
* [Symbol.for('attr1')]: 'value1',
|
|
36
|
+
* [Symbol.for('attr2')]: 'value2'
|
|
37
|
+
* };
|
|
38
|
+
* }
|
|
39
|
+
*/
|
|
40
|
+
valueKey?: symbol | string;
|
|
15
41
|
}
|
|
16
42
|
|
|
17
43
|
export interface AttributeMetadata {
|
|
@@ -28,6 +54,36 @@ export const ATTRIBUTE_METADATA_KEY = Symbol.for('simple-web-component:attribute
|
|
|
28
54
|
// Utilities
|
|
29
55
|
// ============================================
|
|
30
56
|
|
|
57
|
+
/**
|
|
58
|
+
* Determine if a string is a CSS selector or an attribute name
|
|
59
|
+
*
|
|
60
|
+
* CSS selectors typically:
|
|
61
|
+
* - Start with: #, ., [, :, >, +, ~
|
|
62
|
+
* - Contain special chars: >, +, ~, :, [, ]
|
|
63
|
+
* - Are special keywords: $this, $host, $parentHost, etc.
|
|
64
|
+
*
|
|
65
|
+
* Attribute names are typically:
|
|
66
|
+
* - kebab-case (lowercase with hyphens)
|
|
67
|
+
* - No special selector syntax
|
|
68
|
+
*
|
|
69
|
+
* @param str - String to check
|
|
70
|
+
* @returns true if it's a CSS selector, false if it's an attribute name
|
|
71
|
+
*/
|
|
72
|
+
const isCssSelector = (str: string): boolean => {
|
|
73
|
+
if (!str) return false;
|
|
74
|
+
|
|
75
|
+
// Special keywords
|
|
76
|
+
if (str.startsWith('$')) return true;
|
|
77
|
+
|
|
78
|
+
// CSS selector syntax
|
|
79
|
+
if (/^[#.\[\:>+~]/.test(str)) return true;
|
|
80
|
+
|
|
81
|
+
// Contains CSS combinator or pseudo-selector syntax
|
|
82
|
+
if (/[>+~:\[\]]/.test(str)) return true;
|
|
83
|
+
|
|
84
|
+
return false;
|
|
85
|
+
};
|
|
86
|
+
|
|
31
87
|
const convertValue = (val: string | null, type: any): any => {
|
|
32
88
|
if (val === null || val === undefined) return val;
|
|
33
89
|
if (type === Number) return Number(val);
|
|
@@ -210,13 +266,43 @@ export function applyAttribute(selector: string, targetAttributeNameOrOptions?:
|
|
|
210
266
|
ensureInit(this);
|
|
211
267
|
const res = (original as any).apply(this, args);
|
|
212
268
|
|
|
269
|
+
/**
|
|
270
|
+
* Extract value for this decorator from method return value
|
|
271
|
+
*
|
|
272
|
+
* If return value is an object with this decorator's key,
|
|
273
|
+
* use that value. Otherwise use the entire return value.
|
|
274
|
+
*
|
|
275
|
+
* Uses valueKey from options if provided, otherwise uses ATTRIBUTE_METADATA_KEY.
|
|
276
|
+
*
|
|
277
|
+
* Example:
|
|
278
|
+
* @setAttribute('selector1', { valueKey: 'attr1' })
|
|
279
|
+
* @setAttribute('selector2', { valueKey: 'attr2' })
|
|
280
|
+
* myMethod() {
|
|
281
|
+
* return {
|
|
282
|
+
* attr1: 'attribute-value1',
|
|
283
|
+
* attr2: 'attribute-value2'
|
|
284
|
+
* };
|
|
285
|
+
* }
|
|
286
|
+
*
|
|
287
|
+
* First decorator will use 'attribute-value1', second will use 'attribute-value2'
|
|
288
|
+
*/
|
|
289
|
+
const extractValue = (v: any) => {
|
|
290
|
+
const keyToUse = finalOptions.valueKey ?? ATTRIBUTE_METADATA_KEY;
|
|
291
|
+
if (v && typeof v === 'object' && keyToUse in v) {
|
|
292
|
+
return v[keyToUse];
|
|
293
|
+
}
|
|
294
|
+
return v;
|
|
295
|
+
};
|
|
296
|
+
|
|
213
297
|
if (res instanceof Promise) {
|
|
214
298
|
return res.then((v: any) => {
|
|
215
|
-
|
|
299
|
+
const extracted = extractValue(v);
|
|
300
|
+
applyValueToTargets(this, extracted);
|
|
216
301
|
return v;
|
|
217
302
|
});
|
|
218
303
|
} else {
|
|
219
|
-
|
|
304
|
+
const extracted = extractValue(res);
|
|
305
|
+
applyValueToTargets(this, extracted);
|
|
220
306
|
return res;
|
|
221
307
|
}
|
|
222
308
|
};
|
|
@@ -251,77 +337,93 @@ export function applyAttribute(selector: string, targetAttributeNameOrOptions?:
|
|
|
251
337
|
// ============================================
|
|
252
338
|
|
|
253
339
|
/**
|
|
254
|
-
* @attribute -
|
|
340
|
+
* @attribute - Field decorator for binding element attributes (read/write)
|
|
341
|
+
*
|
|
342
|
+
* Intelligently distinguishes between attribute names and CSS selectors:
|
|
343
|
+
*
|
|
344
|
+
* Usage patterns:
|
|
345
|
+
* - @attribute('product-id') - Attribute name on $this (auto-detected)
|
|
346
|
+
* - @attribute('#user', 'product-id') - Attribute name on selector
|
|
347
|
+
* - @attribute('product-id', options) - Attribute name on $this with options
|
|
348
|
+
* - @attribute('#user', 'product-id', options) - Attribute name on selector with options
|
|
349
|
+
* - @attribute - Bare decorator (uses property name as attribute on $this)
|
|
350
|
+
*
|
|
351
|
+
* Note: This decorator is for FIELDS ONLY. For methods, use @setAttribute.
|
|
255
352
|
*/
|
|
256
|
-
export function attribute(
|
|
257
|
-
export function attribute(
|
|
258
|
-
export function attribute(selector: string,
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
* @attributeThis - Apply attribute on $this element
|
|
264
|
-
* Can be used as: @attributeThis or @attributeThis('attrName') or @attributeThis({ name: 'attrName' })
|
|
265
|
-
*/
|
|
266
|
-
export function attributeThis(target: Object, propertyKey: string | symbol): void;
|
|
267
|
-
export function attributeThis(targetAttributeName: string, options?: AttributeOptions): MethodDecorator & PropertyDecorator;
|
|
268
|
-
export function attributeThis(options?: AttributeOptions): MethodDecorator & PropertyDecorator;
|
|
269
|
-
export function attributeThis(targetOrOptions?: any, propertyKeyOrOptions?: any, descriptor?: PropertyDescriptor): any {
|
|
270
|
-
// Direct decorator usage: @attributeThis
|
|
271
|
-
if (typeof targetOrOptions === 'object' && targetOrOptions !== null && !Array.isArray(targetOrOptions) &&
|
|
272
|
-
typeof propertyKeyOrOptions === 'string' || typeof propertyKeyOrOptions === 'symbol') {
|
|
273
|
-
// Called as @attributeThis (target, propertyKey)
|
|
274
|
-
return applyAttribute('$this', undefined as any, {})(targetOrOptions, propertyKeyOrOptions, descriptor);
|
|
353
|
+
export function attribute(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;
|
|
354
|
+
export function attribute(attributeName: string, options?: AttributeOptions): PropertyDecorator;
|
|
355
|
+
export function attribute(selector: string, attributeName: string, options?: AttributeOptions): PropertyDecorator;
|
|
356
|
+
export function attribute(selectorOrAttributeOrTarget?: string | Object, attributeNameOrOptions?: any, optionsOrDescriptor?: any): any {
|
|
357
|
+
// Bare decorator: @attribute
|
|
358
|
+
if (optionsOrDescriptor !== undefined && (typeof attributeNameOrOptions === 'string' || typeof attributeNameOrOptions === 'symbol')) {
|
|
359
|
+
return applyAttribute('$this', undefined as any, {})(selectorOrAttributeOrTarget as Object, attributeNameOrOptions, optionsOrDescriptor as PropertyDescriptor);
|
|
275
360
|
}
|
|
276
|
-
|
|
277
|
-
//
|
|
278
|
-
if (typeof
|
|
279
|
-
//
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
361
|
+
|
|
362
|
+
// With string as first parameter
|
|
363
|
+
if (typeof selectorOrAttributeOrTarget === 'string') {
|
|
364
|
+
// Check if first parameter is a CSS selector or attribute name
|
|
365
|
+
const isSelector = isCssSelector(selectorOrAttributeOrTarget);
|
|
366
|
+
|
|
367
|
+
if (isSelector) {
|
|
368
|
+
// First param is a selector: @attribute('#user', 'product-id', options?)
|
|
369
|
+
return applyAttribute(selectorOrAttributeOrTarget, attributeNameOrOptions as any, optionsOrDescriptor as AttributeOptions);
|
|
370
|
+
} else {
|
|
371
|
+
// First param is an attribute name: @attribute('product-id', options?)
|
|
372
|
+
// Treat as attribute name on $this
|
|
373
|
+
const options = (typeof attributeNameOrOptions === 'object' && attributeNameOrOptions !== null)
|
|
374
|
+
? attributeNameOrOptions
|
|
375
|
+
: {};
|
|
376
|
+
return applyAttribute('$this', selectorOrAttributeOrTarget, options);
|
|
377
|
+
}
|
|
287
378
|
}
|
|
379
|
+
|
|
380
|
+
// Without selector (defaults to $this with options)
|
|
381
|
+
return applyAttribute('$this', undefined as any, selectorOrAttributeOrTarget as AttributeOptions);
|
|
288
382
|
}
|
|
289
383
|
|
|
290
384
|
/**
|
|
291
|
-
* @setAttribute -
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
* @
|
|
301
|
-
*
|
|
385
|
+
* @setAttribute - Method decorator for setting element attributes from method return value
|
|
386
|
+
*
|
|
387
|
+
* Intelligently distinguishes between attribute names and CSS selectors:
|
|
388
|
+
*
|
|
389
|
+
* Usage patterns:
|
|
390
|
+
* - @setAttribute('data-id') - Attribute name on $this (auto-detected)
|
|
391
|
+
* - @setAttribute('#user', 'data-id') - Attribute name on selector
|
|
392
|
+
* - @setAttribute('data-id', options) - Attribute name on $this with options
|
|
393
|
+
* - @setAttribute('#user', 'data-id', options) - Attribute name on selector with options
|
|
394
|
+
* - @setAttribute - Bare decorator (uses method name as attribute on $this)
|
|
395
|
+
*
|
|
396
|
+
* Note: This decorator is for METHODS ONLY. For fields, use @attribute.
|
|
397
|
+
*
|
|
398
|
+
* Example:
|
|
399
|
+
* @setAttribute('data-status')
|
|
400
|
+
* updateStatus() {
|
|
401
|
+
* return 'active';
|
|
402
|
+
* }
|
|
302
403
|
*/
|
|
303
|
-
export function
|
|
304
|
-
export function
|
|
305
|
-
export function
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
// @setAttributeThis() or @setAttributeThis
|
|
323
|
-
return applyAttribute('$this', undefined as any, {}) as MethodDecorator;
|
|
404
|
+
export function setAttribute(selector: string, attributeName: string, options?: AttributeOptions): MethodDecorator;
|
|
405
|
+
export function setAttribute(attributeName: string, options?: AttributeOptions): MethodDecorator;
|
|
406
|
+
export function setAttribute(selectorOrAttributeOrOptions?: string | AttributeOptions, attributeNameOrOptions?: any, optionsOrUndefined?: AttributeOptions): MethodDecorator {
|
|
407
|
+
// With string as first parameter
|
|
408
|
+
if (typeof selectorOrAttributeOrOptions === 'string') {
|
|
409
|
+
// Check if first parameter is a CSS selector or attribute name
|
|
410
|
+
const isSelector = isCssSelector(selectorOrAttributeOrOptions);
|
|
411
|
+
|
|
412
|
+
if (isSelector) {
|
|
413
|
+
// First param is a selector: @setAttribute('#user', 'data-id', options?)
|
|
414
|
+
return applyAttribute(selectorOrAttributeOrOptions, attributeNameOrOptions as any, optionsOrUndefined as AttributeOptions) as MethodDecorator;
|
|
415
|
+
} else {
|
|
416
|
+
// First param is an attribute name: @setAttribute('data-id', options?)
|
|
417
|
+
// Treat as attribute name on $this
|
|
418
|
+
const options = (typeof attributeNameOrOptions === 'object' && attributeNameOrOptions !== null)
|
|
419
|
+
? attributeNameOrOptions
|
|
420
|
+
: {};
|
|
421
|
+
return applyAttribute('$this', selectorOrAttributeOrOptions, options) as MethodDecorator;
|
|
422
|
+
}
|
|
324
423
|
}
|
|
424
|
+
|
|
425
|
+
// Without selector (defaults to $this with options)
|
|
426
|
+
return applyAttribute('$this', undefined as any, selectorOrAttributeOrOptions as AttributeOptions) as MethodDecorator;
|
|
325
427
|
}
|
|
326
428
|
|
|
327
429
|
// ============================================
|
|
@@ -9,6 +9,12 @@ export type ClassAction = 'set' | 'update' | 'add' | 'remove' | 'toggle';
|
|
|
9
9
|
|
|
10
10
|
export interface ClassApplyOptions extends SwcQueryOptions {
|
|
11
11
|
filter?: (target: HTMLElement, value: any, meta: {currentThis: any, helper: HelperHostSet}) => boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Custom key to extract value from return object.
|
|
14
|
+
* If not provided, uses CLASS_METADATA_KEY by default.
|
|
15
|
+
* Useful when multiple @applyClass decorators are on the same method.
|
|
16
|
+
*/
|
|
17
|
+
valueKey?: symbol | string;
|
|
12
18
|
}
|
|
13
19
|
|
|
14
20
|
export interface ClassApplyMetadata {
|
|
@@ -44,6 +50,22 @@ function createClassDecorator(action: ClassAction) {
|
|
|
44
50
|
ensureInit(this);
|
|
45
51
|
const res = (original as any).apply(this, args);
|
|
46
52
|
|
|
53
|
+
/**
|
|
54
|
+
* Extract value for this decorator from method return value
|
|
55
|
+
*
|
|
56
|
+
* If return value is an object with this decorator's key,
|
|
57
|
+
* use that value. Otherwise use the entire return value.
|
|
58
|
+
*
|
|
59
|
+
* Uses valueKey from options if provided, otherwise uses CLASS_METADATA_KEY.
|
|
60
|
+
*/
|
|
61
|
+
const extractValue = (v: any) => {
|
|
62
|
+
const keyToUse = finalOptions.valueKey ?? CLASS_METADATA_KEY;
|
|
63
|
+
if (v && typeof v === 'object' && keyToUse in v) {
|
|
64
|
+
return v[keyToUse];
|
|
65
|
+
}
|
|
66
|
+
return v;
|
|
67
|
+
};
|
|
68
|
+
|
|
47
69
|
const handleResult = (resolvedValue: any) => {
|
|
48
70
|
if (resolvedValue !== undefined) {
|
|
49
71
|
const win = (this as any).ownerDocument?.defaultView || window;
|
|
@@ -131,9 +153,9 @@ function createClassDecorator(action: ClassAction) {
|
|
|
131
153
|
};
|
|
132
154
|
|
|
133
155
|
if (res instanceof Promise) {
|
|
134
|
-
return res.then(handleResult);
|
|
156
|
+
return res.then((v: any) => handleResult(extractValue(v)));
|
|
135
157
|
} else {
|
|
136
|
-
return handleResult(res);
|
|
158
|
+
return handleResult(extractValue(res));
|
|
137
159
|
}
|
|
138
160
|
};
|
|
139
161
|
return descriptor;
|
|
@@ -141,25 +163,99 @@ function createClassDecorator(action: ClassAction) {
|
|
|
141
163
|
};
|
|
142
164
|
}
|
|
143
165
|
|
|
144
|
-
export function applyClass(
|
|
145
|
-
|
|
166
|
+
export function applyClass(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;
|
|
167
|
+
export function applyClass(selector: string, action?: ClassAction, options?: ClassApplyOptions): MethodDecorator;
|
|
168
|
+
export function applyClass(selectorOrTarget?: any, actionOrPropertyKey?: any, optionsOrDescriptor?: any): any {
|
|
169
|
+
// Bare decorator: @applyClass
|
|
170
|
+
if (optionsOrDescriptor !== undefined && (typeof actionOrPropertyKey === 'string' || typeof actionOrPropertyKey === 'symbol')) {
|
|
171
|
+
return createClassDecorator('update')('$this', {})(selectorOrTarget as Object, actionOrPropertyKey, optionsOrDescriptor as PropertyDescriptor);
|
|
172
|
+
}
|
|
173
|
+
// With selector
|
|
174
|
+
if (typeof selectorOrTarget === 'string') {
|
|
175
|
+
const action = (typeof actionOrPropertyKey === 'string' ? actionOrPropertyKey : 'update') as ClassAction;
|
|
176
|
+
const options = (typeof actionOrPropertyKey === 'object' ? actionOrPropertyKey : optionsOrDescriptor) as ClassApplyOptions | undefined;
|
|
177
|
+
return createClassDecorator(action)(selectorOrTarget, options);
|
|
178
|
+
}
|
|
179
|
+
// Without selector (defaults to $this)
|
|
180
|
+
const action = (typeof selectorOrTarget === 'string' ? selectorOrTarget : 'update') as ClassAction;
|
|
181
|
+
const options = (typeof selectorOrTarget === 'object' ? selectorOrTarget : actionOrPropertyKey) as ClassApplyOptions | undefined;
|
|
182
|
+
return createClassDecorator(action)('$this', options);
|
|
146
183
|
}
|
|
147
184
|
|
|
148
|
-
export
|
|
149
|
-
export
|
|
150
|
-
export
|
|
151
|
-
|
|
152
|
-
|
|
185
|
+
export function setClass(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;
|
|
186
|
+
export function setClass(selector: string, classMapOrOptions?: string | { [className: string]: (el: HTMLElement, value: any, helper: HelperHostSet & { $this: any }) => boolean } | ClassApplyOptions, options?: ClassApplyOptions): MethodDecorator;
|
|
187
|
+
export function setClass(selectorOrTarget?: any, classMapOrOptionsOrPropertyKey?: any, optionsOrDescriptor?: any): any {
|
|
188
|
+
// Bare decorator: @setClass
|
|
189
|
+
if (optionsOrDescriptor !== undefined && (typeof classMapOrOptionsOrPropertyKey === 'string' || typeof classMapOrOptionsOrPropertyKey === 'symbol')) {
|
|
190
|
+
return createClassDecorator('set')('$this', {})(selectorOrTarget as Object, classMapOrOptionsOrPropertyKey, optionsOrDescriptor as PropertyDescriptor);
|
|
191
|
+
}
|
|
192
|
+
// With selector
|
|
193
|
+
if (typeof selectorOrTarget === 'string') {
|
|
194
|
+
return createClassDecorator('set')(selectorOrTarget, classMapOrOptionsOrPropertyKey, optionsOrDescriptor as ClassApplyOptions);
|
|
195
|
+
}
|
|
196
|
+
// Without selector (defaults to $this)
|
|
197
|
+
return createClassDecorator('set')('$this', selectorOrTarget as ClassApplyOptions);
|
|
198
|
+
}
|
|
153
199
|
|
|
154
|
-
|
|
155
|
-
export function
|
|
156
|
-
|
|
200
|
+
export function updateClass(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;
|
|
201
|
+
export function updateClass(selector: string, classMapOrOptions?: string | { [className: string]: (el: HTMLElement, value: any, helper: HelperHostSet & { $this: any }) => boolean } | ClassApplyOptions, options?: ClassApplyOptions): MethodDecorator;
|
|
202
|
+
export function updateClass(selectorOrTarget?: any, classMapOrOptionsOrPropertyKey?: any, optionsOrDescriptor?: any): any {
|
|
203
|
+
// Bare decorator: @updateClass
|
|
204
|
+
if (optionsOrDescriptor !== undefined && (typeof classMapOrOptionsOrPropertyKey === 'string' || typeof classMapOrOptionsOrPropertyKey === 'symbol')) {
|
|
205
|
+
return createClassDecorator('update')('$this', {})(selectorOrTarget as Object, classMapOrOptionsOrPropertyKey, optionsOrDescriptor as PropertyDescriptor);
|
|
206
|
+
}
|
|
207
|
+
// With selector
|
|
208
|
+
if (typeof selectorOrTarget === 'string') {
|
|
209
|
+
return createClassDecorator('update')(selectorOrTarget, classMapOrOptionsOrPropertyKey, optionsOrDescriptor as ClassApplyOptions);
|
|
210
|
+
}
|
|
211
|
+
// Without selector (defaults to $this)
|
|
212
|
+
return createClassDecorator('update')('$this', selectorOrTarget as ClassApplyOptions);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export function addClass(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;
|
|
216
|
+
export function addClass(selector: string, classMapOrOptions?: string | { [className: string]: (el: HTMLElement, value: any, helper: HelperHostSet & { $this: any }) => boolean } | ClassApplyOptions, options?: ClassApplyOptions): MethodDecorator;
|
|
217
|
+
export function addClass(selectorOrTarget?: any, classMapOrOptionsOrPropertyKey?: any, optionsOrDescriptor?: any): any {
|
|
218
|
+
// Bare decorator: @addClass
|
|
219
|
+
if (optionsOrDescriptor !== undefined && (typeof classMapOrOptionsOrPropertyKey === 'string' || typeof classMapOrOptionsOrPropertyKey === 'symbol')) {
|
|
220
|
+
return createClassDecorator('add')('$this', {})(selectorOrTarget as Object, classMapOrOptionsOrPropertyKey, optionsOrDescriptor as PropertyDescriptor);
|
|
221
|
+
}
|
|
222
|
+
// With selector
|
|
223
|
+
if (typeof selectorOrTarget === 'string') {
|
|
224
|
+
return createClassDecorator('add')(selectorOrTarget, classMapOrOptionsOrPropertyKey, optionsOrDescriptor as ClassApplyOptions);
|
|
225
|
+
}
|
|
226
|
+
// Without selector (defaults to $this)
|
|
227
|
+
return createClassDecorator('add')('$this', selectorOrTarget as ClassApplyOptions);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export function removeClass(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;
|
|
231
|
+
export function removeClass(selector: string, classMapOrOptions?: string | { [className: string]: (el: HTMLElement, value: any, helper: HelperHostSet & { $this: any }) => boolean } | ClassApplyOptions, options?: ClassApplyOptions): MethodDecorator;
|
|
232
|
+
export function removeClass(selectorOrTarget?: any, classMapOrOptionsOrPropertyKey?: any, optionsOrDescriptor?: any): any {
|
|
233
|
+
// Bare decorator: @removeClass
|
|
234
|
+
if (optionsOrDescriptor !== undefined && (typeof classMapOrOptionsOrPropertyKey === 'string' || typeof classMapOrOptionsOrPropertyKey === 'symbol')) {
|
|
235
|
+
return createClassDecorator('remove')('$this', {})(selectorOrTarget as Object, classMapOrOptionsOrPropertyKey, optionsOrDescriptor as PropertyDescriptor);
|
|
236
|
+
}
|
|
237
|
+
// With selector
|
|
238
|
+
if (typeof selectorOrTarget === 'string') {
|
|
239
|
+
return createClassDecorator('remove')(selectorOrTarget, classMapOrOptionsOrPropertyKey, optionsOrDescriptor as ClassApplyOptions);
|
|
240
|
+
}
|
|
241
|
+
// Without selector (defaults to $this)
|
|
242
|
+
return createClassDecorator('remove')('$this', selectorOrTarget as ClassApplyOptions);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export function toggleClass(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;
|
|
246
|
+
export function toggleClass(selector: string, classMapOrOptions?: string | { [className: string]: (el: HTMLElement, value: any, helper: HelperHostSet & { $this: any }) => boolean } | ClassApplyOptions, options?: ClassApplyOptions): MethodDecorator;
|
|
247
|
+
export function toggleClass(selectorOrTarget?: any, classMapOrOptionsOrPropertyKey?: any, optionsOrDescriptor?: any): any {
|
|
248
|
+
// Bare decorator: @toggleClass
|
|
249
|
+
if (optionsOrDescriptor !== undefined && (typeof classMapOrOptionsOrPropertyKey === 'string' || typeof classMapOrOptionsOrPropertyKey === 'symbol')) {
|
|
250
|
+
return createClassDecorator('toggle')('$this', {})(selectorOrTarget as Object, classMapOrOptionsOrPropertyKey, optionsOrDescriptor as PropertyDescriptor);
|
|
251
|
+
}
|
|
252
|
+
// With selector
|
|
253
|
+
if (typeof selectorOrTarget === 'string') {
|
|
254
|
+
return createClassDecorator('toggle')(selectorOrTarget, classMapOrOptionsOrPropertyKey, optionsOrDescriptor as ClassApplyOptions);
|
|
255
|
+
}
|
|
256
|
+
// Without selector (defaults to $this)
|
|
257
|
+
return createClassDecorator('toggle')('$this', selectorOrTarget as ClassApplyOptions);
|
|
157
258
|
}
|
|
158
|
-
export const setClassThis = (classMapOrOptions?: string | { [className: string]: (el: HTMLElement, value: any, helper: HelperHostSet & { $this: any }) => boolean } | ClassApplyOptions, options: ClassApplyOptions = {}) => createClassDecorator('set')('$this', classMapOrOptions, options);
|
|
159
|
-
export const updateClassThis = (classMapOrOptions?: string | { [className: string]: (el: HTMLElement, value: any, helper: HelperHostSet & { $this: any }) => boolean } | ClassApplyOptions, options: ClassApplyOptions = {}) => createClassDecorator('update')('$this', classMapOrOptions, options);
|
|
160
|
-
export const addClassThis = (classMapOrOptions?: string | { [className: string]: (el: HTMLElement, value: any, helper: HelperHostSet & { $this: any }) => boolean } | ClassApplyOptions, options: ClassApplyOptions = {}) => createClassDecorator('add')('$this', classMapOrOptions, options);
|
|
161
|
-
export const removeClassThis = (classMapOrOptions?: string | { [className: string]: (el: HTMLElement, value: any, helper: HelperHostSet & { $this: any }) => boolean } | ClassApplyOptions, options: ClassApplyOptions = {}) => createClassDecorator('remove')('$this', classMapOrOptions, options);
|
|
162
|
-
export const toggleClassThis = (classMapOrOptions?: string | { [className: string]: (el: HTMLElement, value: any, helper: HelperHostSet & { $this: any }) => boolean } | ClassApplyOptions, options: ClassApplyOptions = {}) => createClassDecorator('toggle')('$this', classMapOrOptions, options);
|
|
163
259
|
|
|
164
260
|
export const findAllClassMetadata = (target: any): Map<string | symbol, ClassApplyMetadata> => {
|
|
165
261
|
const result = new Map<string | symbol, ClassApplyMetadata>();
|