@dooboostore/simple-web-component 1.0.33 → 1.0.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -30
- package/dist/cjs/decorators/addEventListener.js.map +1 -1
- package/dist/cjs/decorators/applyAttribute.js +67 -57
- package/dist/cjs/decorators/applyAttribute.js.map +2 -2
- package/dist/cjs/decorators/applyClass.js +80 -70
- package/dist/cjs/decorators/applyClass.js.map +2 -2
- package/dist/cjs/decorators/applyNode.js +5 -8
- package/dist/cjs/decorators/applyNode.js.map +2 -2
- package/dist/cjs/decorators/applyStyle.js +66 -56
- package/dist/cjs/decorators/applyStyle.js.map +2 -2
- package/dist/cjs/decorators/attribute.js +35 -29
- package/dist/cjs/decorators/attribute.js.map +2 -2
- package/dist/cjs/decorators/changedAttributeHost.js +32 -12
- package/dist/cjs/decorators/changedAttributeHost.js.map +2 -2
- package/dist/cjs/decorators/elementDefine.js +238 -180
- package/dist/cjs/decorators/elementDefine.js.map +2 -2
- package/dist/cjs/decorators/emitCustomEvent.js +67 -48
- package/dist/cjs/decorators/emitCustomEvent.js.map +2 -2
- package/dist/cjs/decorators/lifecycles.js +15 -17
- package/dist/cjs/decorators/lifecycles.js.map +2 -2
- package/dist/cjs/decorators/setProperty.js +50 -39
- package/dist/cjs/decorators/setProperty.js.map +2 -2
- package/dist/cjs/decorators/subscribeSwcAppMessageWhileConnected.js.map +1 -1
- package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js +2 -2
- package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
- package/dist/cjs/elements/SwcAppEngine.js +14 -8
- package/dist/cjs/elements/SwcAppEngine.js.map +3 -3
- package/dist/cjs/elements/SwcAppMixin.js +154 -81
- package/dist/cjs/elements/SwcAppMixin.js.map +2 -2
- package/dist/cjs/elements/SwcAsync.js +28 -18
- package/dist/cjs/elements/SwcAsync.js.map +2 -2
- package/dist/cjs/elements/SwcChoose.js +68 -45
- package/dist/cjs/elements/SwcChoose.js.map +2 -2
- package/dist/cjs/elements/SwcIf.js +52 -30
- package/dist/cjs/elements/SwcIf.js.map +2 -2
- package/dist/cjs/elements/SwcLoop.js +109 -35
- package/dist/cjs/elements/SwcLoop.js.map +2 -2
- package/dist/cjs/elements/register.js +263 -131
- package/dist/cjs/elements/register.js.map +2 -2
- package/dist/cjs/router/ElementRouter.js +4 -2
- package/dist/cjs/router/ElementRouter.js.map +1 -1
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/utils/Utils.js +25 -7
- package/dist/cjs/utils/Utils.js.map +2 -2
- package/dist/esm/decorators/addEventListener.js.map +1 -1
- package/dist/esm/decorators/applyAttribute.js +67 -57
- package/dist/esm/decorators/applyAttribute.js.map +2 -2
- package/dist/esm/decorators/applyClass.js +80 -70
- package/dist/esm/decorators/applyClass.js.map +2 -2
- package/dist/esm/decorators/applyNode.js +5 -8
- package/dist/esm/decorators/applyNode.js.map +2 -2
- package/dist/esm/decorators/applyStyle.js +66 -56
- package/dist/esm/decorators/applyStyle.js.map +2 -2
- package/dist/esm/decorators/attribute.js +35 -29
- package/dist/esm/decorators/attribute.js.map +2 -2
- package/dist/esm/decorators/changedAttributeHost.js +32 -12
- package/dist/esm/decorators/changedAttributeHost.js.map +2 -2
- package/dist/esm/decorators/elementDefine.js +240 -182
- package/dist/esm/decorators/elementDefine.js.map +2 -2
- package/dist/esm/decorators/emitCustomEvent.js +67 -48
- package/dist/esm/decorators/emitCustomEvent.js.map +2 -2
- package/dist/esm/decorators/lifecycles.js +15 -17
- package/dist/esm/decorators/lifecycles.js.map +2 -2
- package/dist/esm/decorators/setProperty.js +50 -39
- package/dist/esm/decorators/setProperty.js.map +2 -2
- package/dist/esm/decorators/subscribeSwcAppMessageWhileConnected.js.map +1 -1
- package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js +2 -2
- package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
- package/dist/esm/elements/SwcAppEngine.js +14 -7
- package/dist/esm/elements/SwcAppEngine.js.map +2 -2
- package/dist/esm/elements/SwcAppMixin.js +156 -82
- package/dist/esm/elements/SwcAppMixin.js.map +2 -2
- package/dist/esm/elements/SwcAsync.js +28 -18
- package/dist/esm/elements/SwcAsync.js.map +2 -2
- package/dist/esm/elements/SwcChoose.js +69 -46
- package/dist/esm/elements/SwcChoose.js.map +2 -2
- package/dist/esm/elements/SwcIf.js +53 -31
- package/dist/esm/elements/SwcIf.js.map +2 -2
- package/dist/esm/elements/SwcLoop.js +110 -36
- package/dist/esm/elements/SwcLoop.js.map +2 -2
- package/dist/esm/elements/register.js +264 -132
- package/dist/esm/elements/register.js.map +2 -2
- package/dist/esm/router/ElementRouter.js +5 -2
- package/dist/esm/router/ElementRouter.js.map +1 -1
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils/Utils.js +25 -7
- package/dist/esm/utils/Utils.js.map +2 -2
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +728 -595
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
- package/dist/types/decorators/addEventListener.d.ts +4 -1
- package/dist/types/decorators/addEventListener.d.ts.map +1 -1
- package/dist/types/decorators/applyAttribute.d.ts +5 -1
- package/dist/types/decorators/applyAttribute.d.ts.map +1 -1
- package/dist/types/decorators/applyClass.d.ts +4 -0
- package/dist/types/decorators/applyClass.d.ts.map +1 -1
- package/dist/types/decorators/applyNode.d.ts +5 -1
- package/dist/types/decorators/applyNode.d.ts.map +1 -1
- package/dist/types/decorators/applyStyle.d.ts +5 -1
- package/dist/types/decorators/applyStyle.d.ts.map +1 -1
- package/dist/types/decorators/attribute.d.ts +5 -0
- package/dist/types/decorators/attribute.d.ts.map +1 -1
- package/dist/types/decorators/changedAttributeHost.d.ts +14 -3
- package/dist/types/decorators/changedAttributeHost.d.ts.map +1 -1
- package/dist/types/decorators/elementDefine.d.ts +1 -1
- package/dist/types/decorators/elementDefine.d.ts.map +1 -1
- package/dist/types/decorators/emitCustomEvent.d.ts +15 -7
- package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
- package/dist/types/decorators/lifecycles.d.ts +10 -7
- package/dist/types/decorators/lifecycles.d.ts.map +1 -1
- package/dist/types/decorators/setProperty.d.ts +5 -1
- package/dist/types/decorators/setProperty.d.ts.map +1 -1
- package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts +2 -2
- package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts.map +1 -1
- package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts +5 -6
- package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts.map +1 -1
- package/dist/types/elements/SwcAppEngine.d.ts +9 -3
- package/dist/types/elements/SwcAppEngine.d.ts.map +1 -1
- package/dist/types/elements/SwcAppMixin.d.ts +12 -7
- package/dist/types/elements/SwcAppMixin.d.ts.map +1 -1
- package/dist/types/elements/register.d.ts.map +1 -1
- package/dist/types/types.d.ts +1 -0
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils/Utils.d.ts +4 -1
- package/dist/types/utils/Utils.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +728 -595
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +5 -5
- package/src/decorators/addEventListener.ts +1 -1
- package/src/decorators/applyAttribute.ts +74 -61
- package/src/decorators/applyClass.ts +91 -77
- package/src/decorators/applyNode.ts +16 -13
- package/src/decorators/applyStyle.ts +75 -61
- package/src/decorators/attribute.ts +55 -43
- package/src/decorators/changedAttributeHost.ts +49 -15
- package/src/decorators/elementDefine.ts +401 -340
- package/src/decorators/emitCustomEvent.ts +92 -62
- package/src/decorators/lifecycles.ts +11 -10
- package/src/decorators/setProperty.ts +58 -44
- package/src/decorators/subscribeSwcAppMessageWhileConnected.ts +2 -2
- package/src/decorators/subscribeSwcAppRouteChangeWhileConnected.ts +11 -11
- package/src/elements/SwcAppEngine.ts +19 -13
- package/src/elements/SwcAppMixin.ts +214 -102
- package/src/elements/SwcAsync.ts +28 -17
- package/src/elements/SwcChoose.ts +94 -36
- package/src/elements/SwcIf.ts +59 -22
- package/src/elements/SwcLoop.ts +140 -27
- package/src/elements/register.ts +319 -100
- package/src/types.ts +1 -0
- package/src/utils/Utils.ts +38 -10
- package/tsconfig.json +2 -2
|
@@ -1,24 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import {ReflectUtils} from '@dooboostore/core';
|
|
2
|
+
import {SpecialSelector, SwcQueryOptions, HelperHostSet} from '../types';
|
|
3
|
+
import {ensureInit, getElementConfig} from './elementDefine';
|
|
4
|
+
import {SwcUtils} from '../utils/Utils';
|
|
5
5
|
|
|
6
6
|
export interface EmitCustomEventBaseOptions {
|
|
7
7
|
bubbles?: boolean;
|
|
8
8
|
composed?: boolean;
|
|
9
9
|
cancelable?: boolean;
|
|
10
|
+
filter?: (target: EventTarget, detail: any, meta: { currentThis: any, helper: HelperHostSet }) => boolean;
|
|
10
11
|
}
|
|
11
12
|
|
|
13
|
+
type Options = (EmitCustomEventBaseOptions & SwcQueryOptions) | (EmitCustomEventBaseOptions & SwcQueryOptions & { attributeName?: string });
|
|
14
|
+
|
|
12
15
|
export interface EmitCustomEventMetadata {
|
|
13
16
|
propertyKey: string | symbol;
|
|
14
17
|
selector: string;
|
|
15
18
|
type: string;
|
|
16
|
-
options:
|
|
19
|
+
options: Options;
|
|
17
20
|
}
|
|
18
21
|
|
|
19
22
|
export const EMIT_CUSTOM_EVENT_METADATA_KEY = Symbol.for('simple-web-component:emit-custom-event');
|
|
20
|
-
|
|
21
|
-
export function emitCustomEvent(
|
|
23
|
+
|
|
24
|
+
export function emitCustomEvent(target: SpecialSelector, type: string, options?: Options): MethodDecorator;
|
|
25
|
+
export function emitCustomEvent(selector: string, type: string, options?: Options): MethodDecorator;
|
|
22
26
|
/**
|
|
23
27
|
* @emitCustomEvent decorator to dispatch custom events to a target.
|
|
24
28
|
*/
|
|
@@ -26,7 +30,7 @@ export function emitCustomEvent(selectorOrTarget: string, type: string, options:
|
|
|
26
30
|
return (targetObj: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {
|
|
27
31
|
const constructor = targetObj.constructor;
|
|
28
32
|
|
|
29
|
-
const fullOptions: any = {
|
|
33
|
+
const fullOptions: any = {...options, type};
|
|
30
34
|
|
|
31
35
|
if (fullOptions.bubbles === undefined) fullOptions.bubbles = true;
|
|
32
36
|
if (fullOptions.composed === undefined) fullOptions.composed = true;
|
|
@@ -36,62 +40,77 @@ export function emitCustomEvent(selectorOrTarget: string, type: string, options:
|
|
|
36
40
|
list = [];
|
|
37
41
|
ReflectUtils.defineMetadata(EMIT_CUSTOM_EVENT_METADATA_KEY, list, constructor);
|
|
38
42
|
}
|
|
39
|
-
list.push({
|
|
43
|
+
list.push({propertyKey, selector: selectorOrTarget, type, options: fullOptions});
|
|
40
44
|
|
|
41
45
|
const original = descriptor.value;
|
|
42
|
-
descriptor.value =
|
|
46
|
+
descriptor.value = function (...args: any[]) {
|
|
43
47
|
ensureInit(this);
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (
|
|
62
|
-
|
|
63
|
-
if (
|
|
64
|
-
|
|
65
|
-
if (
|
|
66
|
-
|
|
67
|
-
if (
|
|
68
|
-
|
|
69
|
-
if (
|
|
70
|
-
|
|
71
|
-
if (
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
searchRoots.push(this
|
|
85
|
-
if (
|
|
48
|
+
const res = original.apply(this, args);
|
|
49
|
+
|
|
50
|
+
const handleResult = (detail: any) => {
|
|
51
|
+
const event = new CustomEvent(type, {
|
|
52
|
+
detail,
|
|
53
|
+
bubbles: fullOptions.bubbles,
|
|
54
|
+
composed: fullOptions.composed,
|
|
55
|
+
cancelable: fullOptions.cancelable
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const hostSet = SwcUtils.getHostSet(this as any);
|
|
59
|
+
const conf = getElementConfig(this);
|
|
60
|
+
const currentWin = (this as any)._resolveWindow?.(conf) || ((typeof window !== 'undefined' ? window : undefined) as Window);
|
|
61
|
+
|
|
62
|
+
const eventTargets: EventTarget[] = [];
|
|
63
|
+
if (selectorOrTarget === ':window') eventTargets.push(currentWin);
|
|
64
|
+
else if (selectorOrTarget === ':document') eventTargets.push(currentWin.document);
|
|
65
|
+
else if (selectorOrTarget === ':parentHost') {
|
|
66
|
+
if (hostSet.$parentHost) eventTargets.push(hostSet.$parentHost);
|
|
67
|
+
} else if (selectorOrTarget === ':appHost') {
|
|
68
|
+
if (hostSet.$appHost) eventTargets.push(hostSet.$appHost);
|
|
69
|
+
} else if (selectorOrTarget === ':firstHost') {
|
|
70
|
+
if (hostSet.$firstHost) eventTargets.push(hostSet.$firstHost);
|
|
71
|
+
} else if (selectorOrTarget === ':lastHost') {
|
|
72
|
+
if (hostSet.$lastHost) eventTargets.push(hostSet.$lastHost);
|
|
73
|
+
} else if (selectorOrTarget === ':firstAppHost') {
|
|
74
|
+
if (hostSet.$firstAppHost) eventTargets.push(hostSet.$firstAppHost);
|
|
75
|
+
} else if (selectorOrTarget === ':lastAppHost') {
|
|
76
|
+
if (hostSet.$lastAppHost) eventTargets.push(hostSet.$lastAppHost);
|
|
77
|
+
} else if (selectorOrTarget === ':hosts') {
|
|
78
|
+
hostSet.$hosts.forEach(h => eventTargets.push(h));
|
|
79
|
+
} else if (selectorOrTarget === ':appHosts') {
|
|
80
|
+
hostSet.$appHosts.forEach(h => eventTargets.push(h));
|
|
81
|
+
} else if (selectorOrTarget === ':host' || !selectorOrTarget) {
|
|
82
|
+
eventTargets.push(this as any);
|
|
83
|
+
} else {
|
|
84
|
+
const r = fullOptions.root || 'auto';
|
|
85
|
+
const searchRoots: (HTMLElement | ShadowRoot)[] = [];
|
|
86
|
+
if (r === 'auto') searchRoots.push(this.shadowRoot || (this as any));
|
|
87
|
+
else if (r === 'light') searchRoots.push(this as any);
|
|
88
|
+
else if (r === 'shadow' && this.shadowRoot) searchRoots.push(this.shadowRoot);
|
|
89
|
+
else if (r === 'all') {
|
|
90
|
+
searchRoots.push(this as any);
|
|
91
|
+
if (this.shadowRoot) searchRoots.push(this.shadowRoot);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
searchRoots.forEach(sr => {
|
|
95
|
+
sr.querySelectorAll(selectorOrTarget).forEach(el => eventTargets.push(el));
|
|
96
|
+
});
|
|
86
97
|
}
|
|
87
98
|
|
|
88
|
-
|
|
89
|
-
|
|
99
|
+
eventTargets.forEach(t => {
|
|
100
|
+
if (fullOptions.filter && !fullOptions.filter(t, detail, {currentThis: this, helper: hostSet})) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
t.dispatchEvent(event);
|
|
90
104
|
});
|
|
91
|
-
}
|
|
92
105
|
|
|
93
|
-
|
|
94
|
-
|
|
106
|
+
return detail;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
if (res instanceof Promise) {
|
|
110
|
+
return res.then(handleResult);
|
|
111
|
+
} else {
|
|
112
|
+
return handleResult(res);
|
|
113
|
+
}
|
|
95
114
|
};
|
|
96
115
|
};
|
|
97
116
|
}
|
|
@@ -105,13 +124,24 @@ export const getEmitCustomEventMetadataList = (target: any): EmitCustomEventMeta
|
|
|
105
124
|
* @emitCustomEventHost decorator - simplified version of @emitCustomEvent for :host selector
|
|
106
125
|
* Usage: @emitCustomEventHost('navigate') // default attributeName: 'on-emit-navigate'
|
|
107
126
|
* Usage: @emitCustomEventHost('navigate', { attributeName: 'on-navigate' })
|
|
108
|
-
*
|
|
127
|
+
*
|
|
109
128
|
* The attributeName option is used to automatically observe attributes for this event.
|
|
110
129
|
* For example, { attributeName: 'on-navigate' } will add 'on-navigate' to observedAttributes.
|
|
111
130
|
*/
|
|
112
|
-
export function emitCustomEventHost(type: string, options: EmitCustomEventBaseOptions & SwcQueryOptions & { attributeName?: string }
|
|
113
|
-
|
|
114
|
-
|
|
131
|
+
export function emitCustomEventHost(type: string, options: EmitCustomEventBaseOptions & SwcQueryOptions & { attributeName?: string }): MethodDecorator ;
|
|
132
|
+
export function emitCustomEventHost(type: string, attributeName: string): MethodDecorator ;
|
|
133
|
+
export function emitCustomEventHost(type: string): MethodDecorator;
|
|
134
|
+
export function emitCustomEventHost(type: string, optionsOrAttributeaName?: string | (EmitCustomEventBaseOptions & SwcQueryOptions & { attributeName?: string })): MethodDecorator {
|
|
135
|
+
if (optionsOrAttributeaName && typeof optionsOrAttributeaName === 'string') {
|
|
136
|
+
return emitCustomEventHost(type, {attributeName: optionsOrAttributeaName});
|
|
137
|
+
} else if (optionsOrAttributeaName && typeof optionsOrAttributeaName === 'object') {
|
|
138
|
+
if (!optionsOrAttributeaName.attributeName) {
|
|
139
|
+
optionsOrAttributeaName.attributeName = `on-emit-${type}`;
|
|
140
|
+
}
|
|
141
|
+
return emitCustomEvent(':host', type, optionsOrAttributeaName);
|
|
142
|
+
} else {
|
|
143
|
+
return emitCustomEvent(':host', type, {attributeName: `on-emit-${type}`});
|
|
115
144
|
}
|
|
116
|
-
|
|
145
|
+
|
|
146
|
+
|
|
117
147
|
}
|
|
@@ -14,6 +14,7 @@ export const INNER_HTML_METADATA_KEY = Symbol.for('simple-web-component:inner-ht
|
|
|
14
14
|
export const ATTRIBUTE_CHANGED_WILDCARD = '*';
|
|
15
15
|
|
|
16
16
|
export interface InnerHtmlOptions {
|
|
17
|
+
replaceWrap?:{ start: string, end:string},
|
|
17
18
|
useShadow?: boolean;
|
|
18
19
|
}
|
|
19
20
|
|
|
@@ -35,21 +36,21 @@ function createLifecycleDecorator(metadataKey: symbol): MethodDecorator {
|
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
export const onInitialize = createLifecycleDecorator(ON_INITIALIZE_METADATA_KEY);
|
|
38
|
-
export const
|
|
39
|
-
export const
|
|
40
|
-
export const onConnected =
|
|
39
|
+
export const onConnectedBefore = createLifecycleDecorator(ON_BEFORE_CONNECTED_METADATA_KEY);
|
|
40
|
+
export const onConnectedAfter = createLifecycleDecorator(ON_AFTER_CONNECTED_METADATA_KEY);
|
|
41
|
+
export const onConnected = onConnectedAfter;
|
|
41
42
|
|
|
42
|
-
export const
|
|
43
|
-
export const
|
|
44
|
-
export const onDisconnected =
|
|
43
|
+
export const onDisconnectedBefore = createLifecycleDecorator(ON_BEFORE_DISCONNECTED_METADATA_KEY);
|
|
44
|
+
export const onDisconnectedAfter = createLifecycleDecorator(ON_AFTER_DISCONNECTED_METADATA_KEY);
|
|
45
|
+
export const onDisconnected = onDisconnectedAfter;
|
|
45
46
|
|
|
46
|
-
export const
|
|
47
|
-
export const
|
|
48
|
-
export const onAdopted =
|
|
47
|
+
export const onAdoptedBefore = createLifecycleDecorator(ON_BEFORE_ADOPTED_METADATA_KEY);
|
|
48
|
+
export const onAdoptedAfter = createLifecycleDecorator(ON_AFTER_ADOPTED_METADATA_KEY);
|
|
49
|
+
export const onAdopted = onAdoptedAfter;
|
|
49
50
|
|
|
50
51
|
export const onAddEventListener = createLifecycleDecorator(ON_ADD_EVENT_LISTENER_METADATA_KEY);
|
|
51
52
|
|
|
52
|
-
export const onConnectedSwcApp = createLifecycleDecorator(ON_CONNECTED_SWC_APP_METADATA_KEY);
|
|
53
|
+
// export const onConnectedSwcApp = createLifecycleDecorator(ON_CONNECTED_SWC_APP_METADATA_KEY);
|
|
53
54
|
|
|
54
55
|
/**
|
|
55
56
|
* @onConnectedInnerHtml decorator to define the initial HTML content when connected.
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { ReflectUtils } from '@dooboostore/core';
|
|
2
2
|
import { ensureInit } from './elementDefine';
|
|
3
3
|
import { SwcUtils } from '../utils/Utils';
|
|
4
|
-
import { SwcQueryOptions } from '../types';
|
|
4
|
+
import { HelperHostSet, SwcQueryOptions } from '../types';
|
|
5
5
|
|
|
6
6
|
export interface PropertySetOptions extends SwcQueryOptions {
|
|
7
7
|
name?: string;
|
|
8
|
+
filter?: (target: HTMLElement, value: any, meta: {currentThis: any, helper: HelperHostSet}) => boolean;
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
export interface PropertySetMetadata {
|
|
@@ -38,55 +39,68 @@ export const setProperty = (selector: string, propertyNameOrOptions?: string | P
|
|
|
38
39
|
});
|
|
39
40
|
|
|
40
41
|
const original = descriptor.value;
|
|
41
|
-
descriptor.value =
|
|
42
|
+
descriptor.value = function (...args: any[]) {
|
|
42
43
|
ensureInit(this);
|
|
43
|
-
const res =
|
|
44
|
-
if (res !== undefined) {
|
|
45
|
-
const win = (this as any).ownerDocument?.defaultView || window;
|
|
46
|
-
const host = this as unknown as HTMLElement;
|
|
47
|
-
const hostSet = { ...SwcUtils.getHelperAndHostSet(win, host), $this: this };
|
|
48
|
-
const r = finalOptions.root || 'auto';
|
|
49
|
-
const targetEls: HTMLElement[] = [];
|
|
44
|
+
const res = (original as any).apply(this, args);
|
|
50
45
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
46
|
+
const handleResult = (resolvedValue: any) => {
|
|
47
|
+
if (resolvedValue !== undefined) {
|
|
48
|
+
const win = (this as any).ownerDocument?.defaultView || window;
|
|
49
|
+
const host = this as unknown as HTMLElement;
|
|
50
|
+
const hostSet = { ...SwcUtils.getHelperAndHostSet(win, host), $this: this };
|
|
51
|
+
const r = finalOptions.root || 'auto';
|
|
52
|
+
const targetEls: HTMLElement[] = [];
|
|
55
53
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (
|
|
68
|
-
|
|
69
|
-
|
|
54
|
+
const applyRoot = (t: any) => {
|
|
55
|
+
if (!t || !(t instanceof win.HTMLElement)) return;
|
|
56
|
+
targetEls.push(t);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
if (selector === ':parentHost') applyRoot(hostSet.$parentHost);
|
|
60
|
+
else if (selector === ':appHost') applyRoot(hostSet.$appHost);
|
|
61
|
+
else if (selector === ':firstHost') applyRoot(hostSet.$firstHost);
|
|
62
|
+
else if (selector === ':lastHost') applyRoot(hostSet.$lastHost);
|
|
63
|
+
else if (selector === ':firstAppHost') applyRoot(hostSet.$firstAppHost);
|
|
64
|
+
else if (selector === ':lastAppHost') applyRoot(hostSet.$lastAppHost);
|
|
65
|
+
else if (selector === ':hosts') hostSet.$hosts.forEach(applyRoot);
|
|
66
|
+
else if (selector === ':appHosts') hostSet.$appHosts.forEach(applyRoot);
|
|
67
|
+
else if (selector === ':host' || !selector) applyRoot(host);
|
|
68
|
+
else {
|
|
69
|
+
const targetRoot = r === 'auto' ? (host.shadowRoot || host) : (r === 'shadow' ? host.shadowRoot : host);
|
|
70
|
+
if (targetRoot) {
|
|
71
|
+
const found = targetRoot.querySelectorAll(selector);
|
|
72
|
+
if (found) targetEls.push(...(Array.from(found) as HTMLElement[]));
|
|
73
|
+
}
|
|
70
74
|
}
|
|
71
|
-
}
|
|
72
75
|
|
|
73
|
-
|
|
74
|
-
|
|
76
|
+
targetEls.forEach(targetEl => {
|
|
77
|
+
if (finalOptions.filter && !finalOptions.filter(targetEl, resolvedValue, {currentThis: this, helper: hostSet})) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const resolvedRes = typeof resolvedValue === 'function' ? (resolvedValue as any)(targetEl, hostSet) : resolvedValue;
|
|
75
81
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
82
|
+
if (propertyName) {
|
|
83
|
+
// Case: @setProperty(selector, 'propertyName')
|
|
84
|
+
(targetEl as any)[propertyName] = resolvedRes;
|
|
85
|
+
} else if (typeof resolvedRes === 'object' && resolvedRes !== null && !Array.isArray(resolvedRes)) {
|
|
86
|
+
// Case: @setProperty(selector) with Object return - assign multiple properties
|
|
87
|
+
Object.entries(resolvedRes as any).forEach(([prop, val]) => {
|
|
88
|
+
const finalVal = typeof val === 'function' ? val(targetEl, hostSet) : val;
|
|
89
|
+
(targetEl as any)[prop] = finalVal;
|
|
90
|
+
});
|
|
91
|
+
} else {
|
|
92
|
+
// Simple value - assign to 'value' property by default
|
|
93
|
+
(targetEl as any).value = resolvedRes;
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
return resolvedValue;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
if (res instanceof Promise) {
|
|
101
|
+
return res.then(handleResult);
|
|
102
|
+
} else {
|
|
103
|
+
return handleResult(res);
|
|
90
104
|
}
|
|
91
105
|
};
|
|
92
106
|
};
|
|
@@ -6,11 +6,11 @@ export const SUBSCRIBE_SWC_APP_MESSAGE_WHILE_CONNECTED_METADATA_KEY = Symbol.for
|
|
|
6
6
|
export interface SwcAppMessageSubscriberMetadata {
|
|
7
7
|
propertyKey: string | symbol;
|
|
8
8
|
messageType?: string;
|
|
9
|
-
filter?: (message: SwcAppMessage) => boolean;
|
|
9
|
+
filter?: (message: SwcAppMessage, currentThis: any) => boolean;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export interface SwcAppMessageOptions {
|
|
13
|
-
filter?: (message: SwcAppMessage) => boolean;
|
|
13
|
+
filter?: (message: SwcAppMessage, currentThis: any) => boolean;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
function createSubscribeSwcAppMessageWhileConnected(options?: SwcAppMessageOptions, messageType?: string): MethodDecorator {
|
|
@@ -3,15 +3,16 @@ import { Router } from '@dooboostore/core-web';
|
|
|
3
3
|
|
|
4
4
|
export const SUBSCRIBE_SWC_APP_ROUTE_CHANGE_WHILE_CONNECTED_METADATA_KEY = Symbol.for('simple-web-component:subscribe-swc-app-route-change-while-connected');
|
|
5
5
|
|
|
6
|
+
export type RoutePathType = string | string[] | ((currentThis: any) => string | string[]);
|
|
7
|
+
|
|
6
8
|
export interface SwcAppRouteChangeSubscriberMetadata {
|
|
7
9
|
propertyKey: string | symbol;
|
|
8
|
-
|
|
9
|
-
filter?: (router: Router) => boolean;
|
|
10
|
+
options?: SwcAppRouteChangeOptions;
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
export interface SwcAppRouteChangeOptions {
|
|
13
|
-
path?:
|
|
14
|
-
filter?: (router: Router) => boolean;
|
|
14
|
+
path?: RoutePathType;
|
|
15
|
+
filter?: (router: Router, currentThis: any) => boolean;
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
function createSubscribeSwcAppRouteChangeWhileConnected(options?: SwcAppRouteChangeOptions): MethodDecorator {
|
|
@@ -25,8 +26,8 @@ function createSubscribeSwcAppRouteChangeWhileConnected(options?: SwcAppRouteCha
|
|
|
25
26
|
list = [];
|
|
26
27
|
ReflectUtils.defineMetadata(SUBSCRIBE_SWC_APP_ROUTE_CHANGE_WHILE_CONNECTED_METADATA_KEY, list, constructor);
|
|
27
28
|
}
|
|
28
|
-
list.push({ propertyKey,
|
|
29
|
-
|
|
29
|
+
list.push({ propertyKey, options });
|
|
30
|
+
|
|
30
31
|
return descriptor;
|
|
31
32
|
};
|
|
32
33
|
}
|
|
@@ -35,8 +36,7 @@ function createSubscribeSwcAppRouteChangeWhileConnected(options?: SwcAppRouteCha
|
|
|
35
36
|
export function subscribeSwcAppRouteChangeWhileConnected(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;
|
|
36
37
|
// 오버로드 시그니처 - 함수 호출 (괄호 있음)
|
|
37
38
|
export function subscribeSwcAppRouteChangeWhileConnected(): MethodDecorator;
|
|
38
|
-
export function subscribeSwcAppRouteChangeWhileConnected(pathPattern:
|
|
39
|
-
export function subscribeSwcAppRouteChangeWhileConnected(pathPatterns: string[]): MethodDecorator;
|
|
39
|
+
export function subscribeSwcAppRouteChangeWhileConnected(pathPattern: RoutePathType): MethodDecorator;
|
|
40
40
|
export function subscribeSwcAppRouteChangeWhileConnected(options: SwcAppRouteChangeOptions): MethodDecorator;
|
|
41
41
|
|
|
42
42
|
// 실제 구현 (이중 모드)
|
|
@@ -46,15 +46,15 @@ export function subscribeSwcAppRouteChangeWhileConnected(targetOrOptions?: any,
|
|
|
46
46
|
if (propertyKey && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {
|
|
47
47
|
return createSubscribeSwcAppRouteChangeWhileConnected({})(targetOrOptions, propertyKey, descriptor);
|
|
48
48
|
}
|
|
49
|
-
|
|
49
|
+
|
|
50
50
|
// 함수로 호출된 경우 (괄호 있음): @subscribeSwcAppRouteChangeWhileConnected() / @subscribeSwcAppRouteChangeWhileConnected('/path')
|
|
51
51
|
let options: SwcAppRouteChangeOptions = {};
|
|
52
52
|
|
|
53
53
|
if (Array.isArray(targetOrOptions)) {
|
|
54
54
|
// 배열: @subscribeSwcAppRouteChangeWhileConnected(['/path1', '/path2'])
|
|
55
55
|
options.path = targetOrOptions;
|
|
56
|
-
} else if (typeof targetOrOptions === 'string') {
|
|
57
|
-
//
|
|
56
|
+
} else if (typeof targetOrOptions === 'string' || typeof targetOrOptions === 'function') {
|
|
57
|
+
// 문자열 또는 함수: @subscribeSwcAppRouteChangeWhileConnected('/path')
|
|
58
58
|
options.path = targetOrOptions;
|
|
59
59
|
} else if (targetOrOptions && typeof targetOrOptions === 'object') {
|
|
60
60
|
// 객체: @subscribeSwcAppRouteChangeWhileConnected({ path: '/path', filter: ... })
|
|
@@ -1,26 +1,29 @@
|
|
|
1
1
|
import { SimpleApplication } from '@dooboostore/simple-boot/SimpleApplication';
|
|
2
|
-
import { PathRouter } from '@dooboostore/core-web';
|
|
3
|
-
import { HashRouter } from '@dooboostore/core-web';
|
|
2
|
+
import { HashRouter, PathRouter, Router, RouterEventType } from '@dooboostore/core-web';
|
|
4
3
|
import { ElementRouter } from '../router/ElementRouter';
|
|
5
4
|
import { SimOption } from '@dooboostore/simple-boot/SimOption';
|
|
6
|
-
import {
|
|
7
|
-
import { Subscription } from '@dooboostore/core';
|
|
8
|
-
import { ConstructorType, OptionalType } from '@dooboostore/core';
|
|
9
|
-
import { FunctionUtils } from '@dooboostore/core';
|
|
10
|
-
import { SwcUtils } from '../utils/Utils';
|
|
5
|
+
import { ConstructorType, OptionalType, Subscription } from '@dooboostore/core';
|
|
11
6
|
|
|
12
7
|
import { SwcAppInterface } from '../types';
|
|
13
|
-
import {
|
|
8
|
+
import { SimConfig } from '@dooboostore/simple-boot';
|
|
14
9
|
|
|
15
10
|
export type SwcConfigType = {
|
|
16
11
|
routeType: 'path' | 'hash' | 'element';
|
|
17
|
-
connectMode?: 'direct' | 'swap';
|
|
12
|
+
connectMode?: 'direct' | 'swap' | 'clear-swap';
|
|
18
13
|
container?: symbol;
|
|
14
|
+
otherInstanceSim?: Map<ConstructorType<any> | Function | SimConfig | symbol, any>;
|
|
19
15
|
path?: string;
|
|
20
16
|
window: Window;
|
|
21
17
|
onEngineStarted?: (sp: SimpleApplication, app: SwcAppInterface) => void;
|
|
22
18
|
onConnected?: (app: SwcAppInterface) => void;
|
|
23
19
|
onDisconnected?: (app: SwcAppInterface) => void;
|
|
20
|
+
|
|
21
|
+
onChildrenConnectedDone?: (app: SwcAppInterface) => void;
|
|
22
|
+
// onChildrenSwcAppStartedDone?: (app: SwcAppInterface) => void;
|
|
23
|
+
// childrenSwcAppStartedDoneCheckIntervalTime?: number;
|
|
24
|
+
onChildrenRouteChanged?: (event: RouterEventType, app: SwcAppInterface) => void;
|
|
25
|
+
childrenRouteChangedCheckIntervalTime?: number; // 자식 연결 완료 이벤트 디바운스 타임 (ms)
|
|
26
|
+
childrenConnectedDoneCheckIntervalTime?: number;
|
|
24
27
|
};
|
|
25
28
|
|
|
26
29
|
export type SwcAttributeConfigType = OptionalType<SwcConfigType, 'routeType' | 'window'>;
|
|
@@ -36,6 +39,7 @@ export class SwcAppEngine {
|
|
|
36
39
|
get config() {
|
|
37
40
|
return this._config;
|
|
38
41
|
}
|
|
42
|
+
|
|
39
43
|
async connect(config: SwcConfigType) {
|
|
40
44
|
try {
|
|
41
45
|
this._config = config;
|
|
@@ -52,15 +56,17 @@ export class SwcAppEngine {
|
|
|
52
56
|
// console.log('vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv', this.router)
|
|
53
57
|
|
|
54
58
|
// App start
|
|
55
|
-
const containerSymbol = this._config.container || (this.host as any).getContainerSymbol?.();
|
|
56
59
|
this.simpleApplication = new SimpleApplication(
|
|
57
60
|
new SimOption({
|
|
58
|
-
excludeProxys: [Node],
|
|
59
|
-
container:
|
|
61
|
+
excludeProxys: [(this._config.window as any).Node],
|
|
62
|
+
container: this._config.container
|
|
60
63
|
})
|
|
61
64
|
);
|
|
62
65
|
|
|
63
66
|
const otherInstanceSim = new Map<any, any>();
|
|
67
|
+
this.config?.otherInstanceSim?.forEach((v, k) => {
|
|
68
|
+
otherInstanceSim.set(k, v);
|
|
69
|
+
});
|
|
64
70
|
if (this.router) otherInstanceSim.set(Router, this.router);
|
|
65
71
|
this.simpleApplication.run(otherInstanceSim);
|
|
66
72
|
|
|
@@ -68,7 +74,7 @@ export class SwcAppEngine {
|
|
|
68
74
|
this._config.onEngineStarted(this.simpleApplication, this.host as unknown as SwcAppInterface);
|
|
69
75
|
}
|
|
70
76
|
} catch (e) {
|
|
71
|
-
console.error('[SWC-APP-ENGINE] Init failed:', e);
|
|
77
|
+
console.error('[SWC-APP-ENGINE] Init failed:', e, this._config);
|
|
72
78
|
}
|
|
73
79
|
}
|
|
74
80
|
|