@dooboostore/simple-web-component 1.0.37 → 1.0.39
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 +280 -791
- package/dist/cjs/SwcAppEngine.js +3 -0
- package/dist/cjs/SwcAppEngine.js.map +2 -2
- package/dist/cjs/decorators/addEventListener.js +20 -4
- package/dist/cjs/decorators/addEventListener.js.map +2 -2
- package/dist/cjs/decorators/applyAttribute.js.map +1 -1
- package/dist/cjs/decorators/applyClass.js.map +1 -1
- package/dist/cjs/decorators/applyNode.js +104 -35
- package/dist/cjs/decorators/applyNode.js.map +2 -2
- package/dist/cjs/decorators/applySlot.js +69 -57
- package/dist/cjs/decorators/applySlot.js.map +3 -3
- package/dist/cjs/decorators/applyStyle.js.map +2 -2
- package/dist/cjs/decorators/attribute.js.map +1 -1
- package/dist/cjs/decorators/elementDefine.js +65 -42
- package/dist/cjs/decorators/elementDefine.js.map +2 -2
- package/dist/cjs/decorators/emitCustomEvent.js.map +1 -1
- package/dist/cjs/decorators/index.js +1 -0
- package/dist/cjs/decorators/index.js.map +2 -2
- package/dist/cjs/decorators/lifecycles.js +47 -31
- package/dist/cjs/decorators/lifecycles.js.map +3 -3
- package/dist/cjs/decorators/publishSwcAppMessage.js.map +2 -2
- package/dist/cjs/decorators/query.js +1 -1
- package/dist/cjs/decorators/query.js.map +2 -2
- package/dist/cjs/decorators/queryAll.js.map +1 -1
- package/dist/cjs/decorators/setProperty.js.map +1 -1
- package/dist/cjs/decorators/state.js +83 -0
- package/dist/cjs/decorators/state.js.map +7 -0
- package/dist/cjs/decorators/subscribeSwcAppMessageWhileConnected.js.map +1 -1
- package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
- package/dist/cjs/elements/SwcApp.js +193 -305
- package/dist/cjs/elements/SwcApp.js.map +3 -3
- package/dist/cjs/elements/SwcAppMixin.js +291 -0
- package/dist/cjs/elements/SwcAppMixin.js.map +7 -0
- package/dist/cjs/elements/index.js +3 -21
- package/dist/cjs/elements/index.js.map +3 -3
- package/dist/cjs/index.js +1 -3
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/{types.js → types/index.js} +1 -1
- package/dist/cjs/types/index.js.map +7 -0
- package/dist/cjs/types/window.d.js.map +1 -1
- package/dist/cjs/utils/Utils.js +159 -20
- package/dist/cjs/utils/Utils.js.map +3 -3
- package/dist/esm/SwcAppEngine.js +3 -0
- package/dist/esm/SwcAppEngine.js.map +2 -2
- package/dist/esm/decorators/addEventListener.js +20 -4
- package/dist/esm/decorators/addEventListener.js.map +2 -2
- package/dist/esm/decorators/applyAttribute.js.map +1 -1
- package/dist/esm/decorators/applyClass.js.map +1 -1
- package/dist/esm/decorators/applyNode.js +104 -35
- package/dist/esm/decorators/applyNode.js.map +2 -2
- package/dist/esm/decorators/applySlot.js +69 -57
- package/dist/esm/decorators/applySlot.js.map +3 -3
- package/dist/esm/decorators/applyStyle.js.map +2 -2
- package/dist/esm/decorators/attribute.js.map +1 -1
- package/dist/esm/decorators/elementDefine.js +69 -46
- package/dist/esm/decorators/elementDefine.js.map +2 -2
- package/dist/esm/decorators/emitCustomEvent.js.map +1 -1
- package/dist/esm/decorators/index.js +1 -0
- package/dist/esm/decorators/index.js.map +2 -2
- package/dist/esm/decorators/lifecycles.js +47 -31
- package/dist/esm/decorators/lifecycles.js.map +3 -3
- package/dist/esm/decorators/publishSwcAppMessage.js.map +2 -2
- package/dist/esm/decorators/query.js +1 -1
- package/dist/esm/decorators/query.js.map +2 -2
- package/dist/esm/decorators/queryAll.js.map +1 -1
- package/dist/esm/decorators/setProperty.js.map +1 -1
- package/dist/esm/decorators/state.js +64 -0
- package/dist/esm/decorators/state.js.map +7 -0
- package/dist/esm/decorators/subscribeSwcAppMessageWhileConnected.js.map +1 -1
- package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
- package/dist/esm/elements/SwcApp.js +195 -307
- package/dist/esm/elements/SwcApp.js.map +3 -3
- package/dist/esm/elements/SwcAppMixin.js +273 -0
- package/dist/esm/elements/SwcAppMixin.js.map +7 -0
- package/dist/esm/elements/index.js +2 -7
- package/dist/esm/elements/index.js.map +2 -2
- package/dist/esm/index.js +2 -4
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/{types.js → types/index.js} +1 -1
- package/dist/esm/types/index.js.map +7 -0
- package/dist/esm/utils/Utils.js +159 -20
- package/dist/esm/utils/Utils.js.map +3 -3
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +3448 -2584
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
- package/dist/types/SwcAppEngine.d.ts +1 -1
- package/dist/types/SwcAppEngine.d.ts.map +1 -1
- package/dist/types/decorators/addEventListener.d.ts +5 -2
- package/dist/types/decorators/addEventListener.d.ts.map +1 -1
- package/dist/types/decorators/applyAttribute.d.ts.map +1 -1
- package/dist/types/decorators/applyClass.d.ts.map +1 -1
- package/dist/types/decorators/applyNode.d.ts +23 -7
- package/dist/types/decorators/applyNode.d.ts.map +1 -1
- package/dist/types/decorators/applySlot.d.ts +14 -12
- package/dist/types/decorators/applySlot.d.ts.map +1 -1
- package/dist/types/decorators/applyStyle.d.ts.map +1 -1
- package/dist/types/decorators/attribute.d.ts.map +1 -1
- package/dist/types/decorators/elementDefine.d.ts.map +1 -1
- package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
- package/dist/types/decorators/index.d.ts +1 -0
- package/dist/types/decorators/index.d.ts.map +1 -1
- package/dist/types/decorators/lifecycles.d.ts +10 -14
- package/dist/types/decorators/lifecycles.d.ts.map +1 -1
- package/dist/types/decorators/publishSwcAppMessage.d.ts.map +1 -1
- package/dist/types/decorators/query.d.ts +1 -1
- package/dist/types/decorators/query.d.ts.map +1 -1
- package/dist/types/decorators/queryAll.d.ts.map +1 -1
- package/dist/types/decorators/setProperty.d.ts +1 -1
- package/dist/types/decorators/setProperty.d.ts.map +1 -1
- package/dist/types/decorators/state.d.ts +9 -0
- package/dist/types/decorators/state.d.ts.map +1 -0
- package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts.map +1 -1
- package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts +5 -1
- package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts.map +1 -1
- package/dist/types/elements/SwcApp.d.ts +35 -6
- package/dist/types/elements/SwcApp.d.ts.map +1 -1
- package/dist/types/elements/SwcAppMixin.d.ts +405 -0
- package/dist/types/elements/SwcAppMixin.d.ts.map +1 -0
- package/dist/types/elements/index.d.ts +2 -2
- package/dist/types/elements/index.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/{types.d.ts → types/index.d.ts} +11 -11
- package/dist/types/types/index.d.ts.map +1 -0
- package/dist/types/utils/Utils.d.ts +14 -2
- package/dist/types/utils/Utils.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +3431 -2567
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +4 -4
- package/src/SwcAppEngine.ts +6 -2
- package/src/decorators/addEventListener.ts +21 -5
- package/src/decorators/applyAttribute.ts +1 -1
- package/src/decorators/applyClass.ts +1 -1
- package/src/decorators/applyNode.ts +183 -73
- package/src/decorators/applySlot.ts +99 -128
- package/src/decorators/applyStyle.ts +4 -4
- package/src/decorators/attribute.ts +1 -1
- package/src/decorators/elementDefine.ts +112 -60
- package/src/decorators/emitCustomEvent.ts +1 -1
- package/src/decorators/index.ts +2 -0
- package/src/decorators/lifecycles.ts +50 -26
- package/src/decorators/publishSwcAppMessage.ts +2 -3
- package/src/decorators/query.ts +4 -4
- package/src/decorators/queryAll.ts +1 -1
- package/src/decorators/setProperty.ts +1 -1
- package/src/decorators/state.ts +83 -0
- package/src/decorators/subscribeSwcAppMessageWhileConnected.ts +1 -1
- package/src/decorators/subscribeSwcAppRouteChangeWhileConnected.ts +4 -3
- package/src/elements/SwcApp.ts +239 -441
- package/src/elements/SwcAppMixin.ts +328 -0
- package/src/elements/index.ts +2 -9
- package/src/index.ts +2 -4
- package/src/{types.ts → types/index.ts} +13 -10
- package/src/types/window.d.ts +3 -0
- package/src/utils/Utils.ts +205 -20
- package/dist/cjs/types.js.map +0 -7
- package/dist/esm/types.js.map +0 -7
- package/dist/types/types.d.ts.map +0 -1
|
@@ -8,7 +8,7 @@ export const ON_AFTER_DISCONNECTED_METADATA_KEY = Symbol.for('simple-web-compone
|
|
|
8
8
|
export const ON_BEFORE_ADOPTED_METADATA_KEY = Symbol.for('simple-web-component:on-before-adopted');
|
|
9
9
|
export const ON_AFTER_ADOPTED_METADATA_KEY = Symbol.for('simple-web-component:on-after-adopted');
|
|
10
10
|
export const ON_ADD_EVENT_LISTENER_METADATA_KEY = Symbol.for('simple-web-component:on-add-event-listener');
|
|
11
|
-
export const
|
|
11
|
+
export const ON_CONNECTED_METADATA_KEY = Symbol.for('simple-web-component');
|
|
12
12
|
export const ON_CONNECTED_SWC_APP_METADATA_KEY = Symbol.for('simple-web-component:on-connected-swc-app');
|
|
13
13
|
export const ON_CONNECTED_COMPLETED_METADATA_KEY = Symbol.for('simple-web-component:on-completed');
|
|
14
14
|
|
|
@@ -16,7 +16,7 @@ export const ATTRIBUTE_CHANGED_WILDCARD = '*';
|
|
|
16
16
|
|
|
17
17
|
export interface InnerHtmlOptions {
|
|
18
18
|
ssrFirst?: boolean;
|
|
19
|
-
replaceWrap?:{ start: string, end:string},
|
|
19
|
+
// replaceWrap?:{ start: string, end:string},
|
|
20
20
|
useShadow?: boolean;
|
|
21
21
|
}
|
|
22
22
|
export interface InnerHtmlMetadata {
|
|
@@ -93,7 +93,7 @@ function createLifecycleDecorator(metadataKey: symbol): MethodDecorator {
|
|
|
93
93
|
export const onInitialize = createLifecycleDecorator(ON_INITIALIZE_METADATA_KEY);
|
|
94
94
|
// export const onConnectedBefore = createLifecycleDecorator(ON_BEFORE_CONNECTED_METADATA_KEY);
|
|
95
95
|
// export const onConnectedAfter = createLifecycleDecorator(ON_AFTER_CONNECTED_METADATA_KEY);
|
|
96
|
-
export const onConnected = onConnectedAfter;
|
|
96
|
+
// export const onConnected = onConnectedAfter;
|
|
97
97
|
|
|
98
98
|
export const onDisconnectedBefore = createLifecycleDecorator(ON_BEFORE_DISCONNECTED_METADATA_KEY);
|
|
99
99
|
export const onDisconnectedAfter = createLifecycleDecorator(ON_AFTER_DISCONNECTED_METADATA_KEY);
|
|
@@ -108,28 +108,52 @@ export const onAddEventListener = createLifecycleDecorator(ON_ADD_EVENT_LISTENER
|
|
|
108
108
|
export const onConnectedSwcApp = createLifecycleDecorator(ON_CONNECTED_SWC_APP_METADATA_KEY);
|
|
109
109
|
export const onConnectedCompleted = createLifecycleDecorator(ON_CONNECTED_COMPLETED_METADATA_KEY);
|
|
110
110
|
|
|
111
|
-
/**
|
|
112
|
-
* @onConnectedInnerHtml decorator to define the initial HTML content when connected.
|
|
113
|
-
*/
|
|
114
|
-
export function onConnectedInnerHtml(options: InnerHtmlOptions): MethodDecorator;
|
|
115
|
-
export function onConnectedInnerHtml(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
|
|
116
|
-
export function onConnectedInnerHtml(arg1?: InnerHtmlOptions | Object, arg2?: string | symbol, arg3?: PropertyDescriptor): MethodDecorator | void {
|
|
117
|
-
const decorator = (options: InnerHtmlOptions, target: Object, propertyKey: string | symbol) => {
|
|
118
|
-
const constructor = target.constructor;
|
|
119
|
-
let list = ReflectUtils.getMetadata<InnerHtmlMetadata[]>(ON_CONNECTED_INNER_HTML_METADATA_KEY, constructor);
|
|
120
|
-
if (!list) {
|
|
121
|
-
list = [];
|
|
122
|
-
ReflectUtils.defineMetadata(ON_CONNECTED_INNER_HTML_METADATA_KEY, list, constructor);
|
|
123
|
-
}
|
|
124
|
-
list.push({ propertyKey, options });
|
|
125
|
-
};
|
|
126
111
|
|
|
127
|
-
|
|
128
|
-
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
const decorator = (options: InnerHtmlOptions, target: Object, propertyKey: string | symbol) => {
|
|
116
|
+
const constructor = target.constructor;
|
|
117
|
+
let list = ReflectUtils.getMetadata<InnerHtmlMetadata[]>(ON_CONNECTED_METADATA_KEY, constructor);
|
|
118
|
+
if (!list) {
|
|
119
|
+
list = [];
|
|
120
|
+
ReflectUtils.defineMetadata(ON_CONNECTED_METADATA_KEY, list, constructor);
|
|
121
|
+
}
|
|
122
|
+
list.push({ propertyKey, options });
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
export function onConnectedShadowDom(options: Omit<InnerHtmlOptions, 'useShadow'>): MethodDecorator; // 파라미터있음
|
|
126
|
+
export function onConnectedShadowDom(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void; // 파라미터없음
|
|
127
|
+
export function onConnectedShadowDom(optionOrTarget: Omit<InnerHtmlOptions, 'useShadow'> | Object, propertyKey?: string | symbol, arg3?: PropertyDescriptor): MethodDecorator | void {
|
|
128
|
+
if (propertyKey) { // no parameter option @decorator
|
|
129
|
+
return decorator({useShadow: true}, optionOrTarget!, propertyKey);
|
|
129
130
|
}
|
|
131
|
+
// parameter option @decorator()
|
|
132
|
+
return (target: Object, propertyKey: string | symbol) => {
|
|
133
|
+
decorator({...optionOrTarget??{}, useShadow: true}, target, propertyKey);
|
|
134
|
+
};
|
|
135
|
+
}
|
|
130
136
|
|
|
137
|
+
export function onConnectedLightDom(options: Omit<InnerHtmlOptions, 'useShadow'>): MethodDecorator; // 파라미터있음
|
|
138
|
+
export function onConnectedLightDom(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void; // 파라미터없음
|
|
139
|
+
export function onConnectedLightDom(optionOrTarget: Omit<InnerHtmlOptions, 'useShadow'> | Object, propertyKey?: string | symbol, arg3?: PropertyDescriptor): MethodDecorator | void {
|
|
140
|
+
if (propertyKey) { // no parameter option @decorator
|
|
141
|
+
return decorator({useShadow: false}, optionOrTarget!, propertyKey);
|
|
142
|
+
}
|
|
143
|
+
// parameter option @decorator()
|
|
144
|
+
return (target: Object, propertyKey: string | symbol) => {
|
|
145
|
+
decorator({...optionOrTarget??{}, useShadow: false}, target, propertyKey);
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
export function onConnected(options: InnerHtmlOptions): MethodDecorator;
|
|
149
|
+
export function onConnected(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
|
|
150
|
+
export function onConnected(optionOrTarget: InnerHtmlOptions | Object, propertyKey?: string | symbol, arg3?: PropertyDescriptor): MethodDecorator | void {
|
|
151
|
+
if (propertyKey) { // no parameter option @decorator
|
|
152
|
+
return decorator({}, optionOrTarget!, propertyKey);
|
|
153
|
+
}
|
|
154
|
+
// parameter option @decorator()
|
|
131
155
|
return (target: Object, propertyKey: string | symbol) => {
|
|
132
|
-
decorator((
|
|
156
|
+
decorator((optionOrTarget as InnerHtmlOptions) || {}, target, propertyKey);
|
|
133
157
|
};
|
|
134
158
|
}
|
|
135
159
|
|
|
@@ -138,19 +162,19 @@ export function onConnectedInnerHtml(arg1?: InnerHtmlOptions | Object, arg2?: st
|
|
|
138
162
|
*/
|
|
139
163
|
// export const findAllLifecycleMetadata = <T = (string | symbol)[]>(target: any, metadataKey: symbol): T | undefined => {
|
|
140
164
|
export const findAllLifecycleMetadata = (target: any, metadataKey: symbol): (string | symbol)[] => {
|
|
141
|
-
const results = ReflectUtils.findAllMetadataFlatten(metadataKey, target);
|
|
165
|
+
const results = ReflectUtils.findAllMetadataFlatten(metadataKey, target)??[];
|
|
142
166
|
return results;
|
|
143
167
|
};
|
|
144
168
|
|
|
145
|
-
export const
|
|
169
|
+
export const findAllOnConnectedMetadata = (target: any): InnerHtmlMetadata[] => {
|
|
146
170
|
const constructor = target instanceof Function ? target : target.constructor;
|
|
147
|
-
return ReflectUtils.getMetadata(
|
|
171
|
+
return ReflectUtils.getMetadata(ON_CONNECTED_METADATA_KEY, constructor) ?? [];
|
|
148
172
|
};
|
|
149
|
-
export const
|
|
173
|
+
export const findAllOnConnectedBeforeMetadata = (target: any): OnConnectedMetadata[] => {
|
|
150
174
|
const constructor = target instanceof Function ? target : target.constructor;
|
|
151
175
|
return ReflectUtils.getMetadata(ON_BEFORE_CONNECTED_METADATA_KEY, constructor) ?? [];
|
|
152
176
|
};
|
|
153
|
-
export const
|
|
177
|
+
export const findAllOnConnectedAfterMetadata = (target: any): OnConnectedMetadata[] => {
|
|
154
178
|
const constructor = target instanceof Function ? target : target.constructor;
|
|
155
179
|
return ReflectUtils.getMetadata(ON_AFTER_CONNECTED_METADATA_KEY, constructor) ?? [];
|
|
156
180
|
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { SwcUtils } from '../utils/Utils';
|
|
1
|
+
import {ReflectUtils} from '@dooboostore/core';
|
|
2
|
+
import {SwcUtils} from '../utils/Utils';
|
|
4
3
|
|
|
5
4
|
export const PUBLISH_SWC_APP_MESSAGE_METADATA_KEY = Symbol.for('simple-web-component:publish-swc-app-message');
|
|
6
5
|
|
package/src/decorators/query.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { ReflectUtils } from '@dooboostore/core';
|
|
2
2
|
import { getElementConfig, ensureInit } from './elementDefine';
|
|
3
3
|
import { SwcUtils } from '../utils/Utils';
|
|
4
|
-
import { SpecialSelector, SwcQueryOptions } from '../types';
|
|
4
|
+
import { SpecialSelector, SwcQueryOptions, HelperHostSet } from '../types';
|
|
5
5
|
|
|
6
6
|
export interface QueryMetadata {
|
|
7
7
|
propertyKey: string | symbol;
|
|
8
8
|
selector: string;
|
|
9
|
-
options: SwcQueryOptions;
|
|
9
|
+
options: SwcQueryOptions ;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export const QUERY_METADATA_KEY = Symbol.for('simple-web-component:query');
|
|
@@ -180,7 +180,7 @@ export function queryAppHost(targetOrOptions?: any, propertyKey?: string | symbo
|
|
|
180
180
|
}
|
|
181
181
|
}
|
|
182
182
|
|
|
183
|
-
export const getQueryMetadata = (target: any): QueryMetadata[]
|
|
183
|
+
export const getQueryMetadata = (target: any): QueryMetadata[] => {
|
|
184
184
|
const constructor = target instanceof Function ? target : target.constructor;
|
|
185
|
-
return ReflectUtils.getMetadata(QUERY_METADATA_KEY, constructor);
|
|
185
|
+
return ReflectUtils.getMetadata(QUERY_METADATA_KEY, constructor) ?? [];
|
|
186
186
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ReflectUtils } from '@dooboostore/core';
|
|
2
2
|
import { getElementConfig, ensureInit } from './elementDefine';
|
|
3
3
|
import { SwcUtils } from '../utils/Utils';
|
|
4
|
-
import { SpecialSelector, SwcQueryOptions } from '../types';
|
|
4
|
+
import { SpecialSelector, SwcQueryOptions, HelperHostSet } from '../types';
|
|
5
5
|
|
|
6
6
|
export interface QueryAllMetadata {
|
|
7
7
|
propertyKey: string | symbol;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ReflectUtils } from '@dooboostore/core';
|
|
2
2
|
import { ensureInit } from './elementDefine';
|
|
3
3
|
import { SwcUtils } from '../utils/Utils';
|
|
4
|
-
import {
|
|
4
|
+
import { SpecialSelector, SwcQueryOptions, HelperHostSet } from '../types';
|
|
5
5
|
|
|
6
6
|
export interface PropertySetOptions extends SwcQueryOptions {
|
|
7
7
|
name?: string;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import {ReflectUtils} from '@dooboostore/core';
|
|
2
|
+
import {ElementApply} from "@dooboostore/core-web";
|
|
3
|
+
import {SwcUtils} from "../utils/Utils";
|
|
4
|
+
import {getElementConfig} from "./elementDefine";
|
|
5
|
+
|
|
6
|
+
export interface StateMetadata {
|
|
7
|
+
propertyKey: string | symbol;
|
|
8
|
+
name: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const STATE_METADATA_KEY = Symbol.for('simple-web-component:state');
|
|
12
|
+
|
|
13
|
+
// export function state(target: SpecialSelector): PropertyDecorator;
|
|
14
|
+
// export function state(): PropertyDecorator;
|
|
15
|
+
export function state(target: Object, propertyKey: string | symbol): void;
|
|
16
|
+
export function state(name: string): PropertyDecorator;
|
|
17
|
+
/**
|
|
18
|
+
* Supports both forms:
|
|
19
|
+
* - @state
|
|
20
|
+
* - @state()
|
|
21
|
+
* - @state('selector')
|
|
22
|
+
*/
|
|
23
|
+
export function state(nameOrTarget?: string | Object, propertyKey?: string | symbol): any {
|
|
24
|
+
|
|
25
|
+
const stateDefine = (targetObj: any, stateMetadata: StateMetadata) => {
|
|
26
|
+
|
|
27
|
+
let storage = targetObj[stateMetadata.propertyKey];
|
|
28
|
+
// console.log('ssssssssssssssss', storage, stateMetadata.propertyKey)
|
|
29
|
+
Object.defineProperty(targetObj, stateMetadata.propertyKey, {
|
|
30
|
+
set(this: any, nv: string) {
|
|
31
|
+
storage = nv;
|
|
32
|
+
const config = getElementConfig(this)
|
|
33
|
+
const ea = new ElementApply(this, {id: this._swcId});
|
|
34
|
+
const helperHostSet = SwcUtils.getHelperAndHostSet(config.window, this);
|
|
35
|
+
const stateContext: any = {...helperHostSet};
|
|
36
|
+
findAllStateMetadata(this).forEach(it => {
|
|
37
|
+
stateContext[it.name] = this[it.propertyKey]
|
|
38
|
+
})
|
|
39
|
+
ea.apply({context:stateContext, targetVariableName: stateMetadata.name, bind: this});
|
|
40
|
+
},
|
|
41
|
+
get(this: any) {
|
|
42
|
+
return storage;
|
|
43
|
+
},
|
|
44
|
+
enumerable: true,
|
|
45
|
+
configurable: true
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// If used as @state (no parentheses), TypeScript will call this function with (target, propertyKey)
|
|
50
|
+
if (typeof nameOrTarget === 'object' && propertyKey) {
|
|
51
|
+
const targetObj = nameOrTarget as Object;
|
|
52
|
+
const name = String(propertyKey);
|
|
53
|
+
const constructor = (targetObj as any).constructor;
|
|
54
|
+
let states = ReflectUtils.getMetadata<StateMetadata[]>(STATE_METADATA_KEY, constructor);
|
|
55
|
+
if (!states) {
|
|
56
|
+
states = [];
|
|
57
|
+
ReflectUtils.defineMetadata(STATE_METADATA_KEY, states, constructor);
|
|
58
|
+
}
|
|
59
|
+
const stateMetadata = {propertyKey, name};
|
|
60
|
+
states.push(stateMetadata);
|
|
61
|
+
stateDefine(targetObj, stateMetadata);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Otherwise return a decorator factory
|
|
66
|
+
return (targetObj: Object, propertyKey: string | symbol): void => {
|
|
67
|
+
const name = String(nameOrTarget);
|
|
68
|
+
const constructor = targetObj.constructor;
|
|
69
|
+
let states = ReflectUtils.getMetadata<StateMetadata[]>(STATE_METADATA_KEY, constructor);
|
|
70
|
+
if (!states) {
|
|
71
|
+
states = [];
|
|
72
|
+
ReflectUtils.defineMetadata(STATE_METADATA_KEY, states, constructor);
|
|
73
|
+
}
|
|
74
|
+
const stateMetadata = {propertyKey, name};
|
|
75
|
+
states.push(stateMetadata);
|
|
76
|
+
stateDefine(targetObj, stateMetadata);
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export const findAllStateMetadata = (target: any): StateMetadata[] => {
|
|
81
|
+
const constructor = target instanceof Function ? target : target.constructor;
|
|
82
|
+
return ReflectUtils.getMetadata(STATE_METADATA_KEY, constructor) ?? [];
|
|
83
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ReflectUtils } from '@dooboostore/core';
|
|
2
|
-
import { SwcAppMessage } from '../types';
|
|
2
|
+
import { SwcAppMessage, SpecialSelector, SwcQueryOptions, HelperHostSet } from '../types';
|
|
3
3
|
|
|
4
4
|
export const SUBSCRIBE_SWC_APP_MESSAGE_WHILE_CONNECTED_METADATA_KEY = Symbol.for('simple-web-component:subscribe-swc-app-message-while-connected');
|
|
5
5
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import {ReflectUtils} from '@dooboostore/core';
|
|
2
|
+
import {Router} from '@dooboostore/core-web';
|
|
3
|
+
import {HelperHostSet} from '../types';
|
|
3
4
|
|
|
4
5
|
export const SUBSCRIBE_SWC_APP_ROUTE_CHANGE_WHILE_CONNECTED_METADATA_KEY = Symbol.for('simple-web-component:subscribe-swc-app-route-change-while-connected');
|
|
5
6
|
|
|
@@ -12,7 +13,7 @@ export interface SwcAppRouteChangeSubscriberMetadata {
|
|
|
12
13
|
|
|
13
14
|
export interface SwcAppRouteChangeOptions {
|
|
14
15
|
path?: RoutePathType;
|
|
15
|
-
filter?: (router: Router, currentThis: any) => boolean;
|
|
16
|
+
filter?: (router: Router, meta: {currentThis: any, helper: HelperHostSet}) => boolean;
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
function createSubscribeSwcAppRouteChangeWhileConnected(options?: SwcAppRouteChangeOptions): MethodDecorator {
|