@dooboostore/simple-web-component 1.0.23 → 1.0.25
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 +64 -3212
- package/dist/cjs/decorators/addEventListener.js +1 -1
- package/dist/cjs/decorators/addEventListener.js.map +2 -2
- package/dist/cjs/decorators/applyAttribute.js +148 -0
- package/dist/cjs/decorators/applyAttribute.js.map +7 -0
- package/dist/cjs/decorators/applyClass.js +164 -0
- package/dist/cjs/decorators/applyClass.js.map +7 -0
- package/dist/cjs/decorators/applyNode.js +97 -109
- package/dist/cjs/decorators/applyNode.js.map +2 -2
- package/dist/cjs/decorators/applyStyle.js +135 -0
- package/dist/cjs/decorators/applyStyle.js.map +7 -0
- package/dist/cjs/decorators/attribute.js +24 -11
- package/dist/cjs/decorators/attribute.js.map +2 -2
- package/dist/cjs/decorators/changedAttributeHost.js +1 -1
- package/dist/cjs/decorators/changedAttributeHost.js.map +2 -2
- package/dist/cjs/decorators/elementDefine.js +14 -23
- package/dist/cjs/decorators/elementDefine.js.map +2 -2
- package/dist/cjs/decorators/emitCustomEvent.js +5 -2
- package/dist/cjs/decorators/emitCustomEvent.js.map +2 -2
- package/dist/cjs/decorators/index.js +3 -3
- package/dist/cjs/decorators/index.js.map +2 -2
- package/dist/cjs/decorators/lifecycles.js +9 -9
- package/dist/cjs/decorators/lifecycles.js.map +2 -2
- package/dist/cjs/decorators/query.js +78 -3
- package/dist/cjs/decorators/query.js.map +2 -2
- package/dist/cjs/decorators/queryAll.js +78 -3
- package/dist/cjs/decorators/queryAll.js.map +2 -2
- package/dist/cjs/elements/SwcAppEngine.js +19 -4
- package/dist/cjs/elements/SwcAppEngine.js.map +2 -2
- package/dist/cjs/elements/SwcAppMixin.js +2 -0
- package/dist/cjs/elements/SwcAppMixin.js.map +2 -2
- package/dist/cjs/index.js +4 -4
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/utils/Utils.js +141 -2
- package/dist/cjs/utils/Utils.js.map +2 -2
- package/dist/esm/decorators/addEventListener.js +1 -1
- package/dist/esm/decorators/addEventListener.js.map +2 -2
- package/dist/esm/decorators/applyAttribute.js +129 -0
- package/dist/esm/decorators/applyAttribute.js.map +7 -0
- package/dist/esm/decorators/applyClass.js +145 -0
- package/dist/esm/decorators/applyClass.js.map +7 -0
- package/dist/esm/decorators/applyNode.js +97 -109
- package/dist/esm/decorators/applyNode.js.map +2 -2
- package/dist/esm/decorators/applyStyle.js +116 -0
- package/dist/esm/decorators/applyStyle.js.map +7 -0
- package/dist/esm/decorators/attribute.js +24 -11
- package/dist/esm/decorators/attribute.js.map +2 -2
- package/dist/esm/decorators/changedAttributeHost.js +1 -1
- package/dist/esm/decorators/changedAttributeHost.js.map +2 -2
- package/dist/esm/decorators/elementDefine.js +14 -23
- package/dist/esm/decorators/elementDefine.js.map +2 -2
- package/dist/esm/decorators/emitCustomEvent.js +5 -2
- package/dist/esm/decorators/emitCustomEvent.js.map +2 -2
- package/dist/esm/decorators/index.js +3 -3
- package/dist/esm/decorators/index.js.map +1 -1
- package/dist/esm/decorators/lifecycles.js +9 -9
- package/dist/esm/decorators/lifecycles.js.map +2 -2
- package/dist/esm/decorators/query.js +78 -3
- package/dist/esm/decorators/query.js.map +2 -2
- package/dist/esm/decorators/queryAll.js +78 -3
- package/dist/esm/decorators/queryAll.js.map +2 -2
- package/dist/esm/elements/SwcAppEngine.js +19 -4
- package/dist/esm/elements/SwcAppEngine.js.map +2 -2
- package/dist/esm/elements/SwcAppMixin.js +2 -0
- package/dist/esm/elements/SwcAppMixin.js.map +2 -2
- package/dist/esm/index.js +4 -4
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/utils/Utils.js +141 -2
- package/dist/esm/utils/Utils.js.map +2 -2
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +3191 -506
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
- package/dist/types/decorators/addEventListener.d.ts.map +1 -1
- package/dist/types/decorators/applyAttribute.d.ts +22 -0
- package/dist/types/decorators/applyAttribute.d.ts.map +1 -0
- package/dist/types/decorators/applyClass.d.ts +65 -0
- package/dist/types/decorators/applyClass.d.ts.map +1 -0
- package/dist/types/decorators/applyNode.d.ts +18 -104
- package/dist/types/decorators/applyNode.d.ts.map +1 -1
- package/dist/types/decorators/applyStyle.d.ts +21 -0
- package/dist/types/decorators/applyStyle.d.ts.map +1 -0
- package/dist/types/decorators/attribute.d.ts +12 -14
- package/dist/types/decorators/attribute.d.ts.map +1 -1
- package/dist/types/decorators/changedAttributeHost.d.ts.map +1 -1
- package/dist/types/decorators/elementDefine.d.ts.map +1 -1
- package/dist/types/decorators/emitCustomEvent.d.ts +1 -1
- package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
- package/dist/types/decorators/index.d.ts +3 -3
- package/dist/types/decorators/index.d.ts.map +1 -1
- package/dist/types/decorators/lifecycles.d.ts.map +1 -1
- package/dist/types/decorators/query.d.ts +68 -4
- package/dist/types/decorators/query.d.ts.map +1 -1
- package/dist/types/decorators/queryAll.d.ts +70 -1
- package/dist/types/decorators/queryAll.d.ts.map +1 -1
- package/dist/types/elements/SwcAppEngine.d.ts +7 -0
- package/dist/types/elements/SwcAppEngine.d.ts.map +1 -1
- package/dist/types/elements/SwcAppMixin.d.ts +1 -1
- package/dist/types/elements/SwcAppMixin.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/utils/Utils.d.ts +49 -0
- package/dist/types/utils/Utils.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +3191 -506
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +3 -3
- package/src/decorators/addEventListener.ts +1 -1
- package/src/decorators/applyAttribute.ts +147 -0
- package/src/decorators/applyClass.ts +158 -0
- package/src/decorators/applyNode.ts +126 -225
- package/src/decorators/applyStyle.ts +128 -0
- package/src/decorators/attribute.ts +42 -43
- package/src/decorators/changedAttributeHost.ts +2 -2
- package/src/decorators/elementDefine.ts +18 -39
- package/src/decorators/emitCustomEvent.ts +6 -3
- package/src/decorators/index.ts +3 -3
- package/src/decorators/lifecycles.ts +9 -11
- package/src/decorators/query.ts +148 -6
- package/src/decorators/queryAll.ts +149 -3
- package/src/elements/SwcAppEngine.ts +32 -4
- package/src/elements/SwcAppMixin.ts +2 -0
- package/src/index.ts +6 -6
- package/src/utils/Utils.ts +146 -1
- package/dist/cjs/decorators/classList.js +0 -134
- package/dist/cjs/decorators/classList.js.map +0 -7
- package/dist/cjs/decorators/setAttribute.js +0 -111
- package/dist/cjs/decorators/setAttribute.js.map +0 -7
- package/dist/cjs/decorators/style.js +0 -114
- package/dist/cjs/decorators/style.js.map +0 -7
- package/dist/cjs/utils/TemplateUtils.js +0 -109
- package/dist/cjs/utils/TemplateUtils.js.map +0 -7
- package/dist/esm/decorators/classList.js +0 -115
- package/dist/esm/decorators/classList.js.map +0 -7
- package/dist/esm/decorators/setAttribute.js +0 -92
- package/dist/esm/decorators/setAttribute.js.map +0 -7
- package/dist/esm/decorators/style.js +0 -95
- package/dist/esm/decorators/style.js.map +0 -7
- package/dist/esm/utils/TemplateUtils.js +0 -90
- package/dist/esm/utils/TemplateUtils.js.map +0 -7
- package/dist/types/decorators/classList.d.ts +0 -61
- package/dist/types/decorators/classList.d.ts.map +0 -1
- package/dist/types/decorators/setAttribute.d.ts +0 -23
- package/dist/types/decorators/setAttribute.d.ts.map +0 -1
- package/dist/types/decorators/style.d.ts +0 -49
- package/dist/types/decorators/style.d.ts.map +0 -1
- package/dist/types/utils/TemplateUtils.d.ts +0 -59
- package/dist/types/utils/TemplateUtils.d.ts.map +0 -1
- package/src/decorators/classList.ts +0 -172
- package/src/decorators/setAttribute.ts +0 -113
- package/src/decorators/style.ts +0 -140
- package/src/utils/TemplateUtils.ts +0 -92
|
@@ -9,7 +9,7 @@ export interface QueryAllMetadata {
|
|
|
9
9
|
options: SwcQueryOptions;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export const QUERY_ALL_METADATA_KEY = Symbol('simple-web-component:query-all');
|
|
12
|
+
export const QUERY_ALL_METADATA_KEY = Symbol.for('simple-web-component:query-all');
|
|
13
13
|
|
|
14
14
|
export function queryAll(target: SpecialSelector): PropertyDecorator;
|
|
15
15
|
export function queryAll(selector: string, options?: SwcQueryOptions): PropertyDecorator;
|
|
@@ -113,6 +113,152 @@ export const getQueryAllMetadata = (target: any): QueryAllMetadata[] | undefined
|
|
|
113
113
|
* Usage: @hostQueryAll()
|
|
114
114
|
* Usage: @hostQueryAll({ root: 'shadow' })
|
|
115
115
|
*/
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
/**
|
|
117
|
+
* @queryAllHost decorator - simplified version of @queryAll for :host selector
|
|
118
|
+
* Usage: @queryAllHost items: HTMLElement[];
|
|
119
|
+
* Usage: @queryAllHost() items: HTMLElement[];
|
|
120
|
+
* Usage: @queryAllHost({ root: 'shadow' }) items: HTMLElement[];
|
|
121
|
+
*/
|
|
122
|
+
export function queryAllHost(target: Object, propertyKey: string | symbol): void;
|
|
123
|
+
export function queryAllHost(): PropertyDecorator;
|
|
124
|
+
export function queryAllHost(options: SwcQueryOptions): PropertyDecorator;
|
|
125
|
+
export function queryAllHost(targetOrOptions?: any, propertyKey?: string | symbol): any {
|
|
126
|
+
// Direct decorator usage: @queryAllHost (no parentheses)
|
|
127
|
+
if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {
|
|
128
|
+
return queryAll(':host', {})(targetOrOptions, propertyKey);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// @queryAllHost() or @queryAllHost(options)
|
|
132
|
+
if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {
|
|
133
|
+
return queryAll(':host', targetOrOptions as SwcQueryOptions);
|
|
134
|
+
} else {
|
|
135
|
+
return queryAll(':host', {});
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* @allHost - Alias for @queryAllHost decorator
|
|
141
|
+
* Usage: @allHost items: HTMLElement[];
|
|
142
|
+
* Usage: @allHost() items: HTMLElement[];
|
|
143
|
+
* Usage: @allHost({ root: 'shadow' }) items: HTMLElement[];
|
|
144
|
+
*/
|
|
145
|
+
export const allHost = queryAllHost;
|
|
146
|
+
/**
|
|
147
|
+
* @allParentHost - Query all :parentHost (All parent SWC components)
|
|
148
|
+
* Usage: @allParentHost parents: HTMLElement[];
|
|
149
|
+
* Usage: @allParentHost() parents: HTMLElement[];
|
|
150
|
+
* Usage: @allParentHost({ root: 'shadow' }) parents: HTMLElement[];
|
|
151
|
+
*/
|
|
152
|
+
export function allParentHost(target: Object, propertyKey: string | symbol): void;
|
|
153
|
+
export function allParentHost(): PropertyDecorator;
|
|
154
|
+
export function allParentHost(options: SwcQueryOptions): PropertyDecorator;
|
|
155
|
+
export function allParentHost(targetOrOptions?: any, propertyKey?: string | symbol): any {
|
|
156
|
+
if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {
|
|
157
|
+
return queryAll(':parentHost', {})(targetOrOptions, propertyKey);
|
|
158
|
+
}
|
|
159
|
+
if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {
|
|
160
|
+
return queryAll(':parentHost', targetOrOptions as SwcQueryOptions);
|
|
161
|
+
} else {
|
|
162
|
+
return queryAll(':parentHost', {});
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* @allAppHost - Query all :appHost (All <swc-app> instances)
|
|
168
|
+
* Usage: @allAppHost apps: SwcAppInterface[];
|
|
169
|
+
* Usage: @allAppHost() apps: SwcAppInterface[];
|
|
170
|
+
* Usage: @allAppHost({ root: 'shadow' }) apps: SwcAppInterface[];
|
|
171
|
+
*/
|
|
172
|
+
export function allAppHost(target: Object, propertyKey: string | symbol): void;
|
|
173
|
+
export function allAppHost(): PropertyDecorator;
|
|
174
|
+
export function allAppHost(options: SwcQueryOptions): PropertyDecorator;
|
|
175
|
+
export function allAppHost(targetOrOptions?: any, propertyKey?: string | symbol): any {
|
|
176
|
+
if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {
|
|
177
|
+
return queryAll(':appHost', {})(targetOrOptions, propertyKey);
|
|
178
|
+
}
|
|
179
|
+
if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {
|
|
180
|
+
return queryAll(':appHost', targetOrOptions as SwcQueryOptions);
|
|
181
|
+
} else {
|
|
182
|
+
return queryAll(':appHost', {});
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* @allFirstHost - Query all :firstHost (All first components in hierarchy)
|
|
188
|
+
* Usage: @allFirstHost firsts: HTMLElement[];
|
|
189
|
+
* Usage: @allFirstHost() firsts: HTMLElement[];
|
|
190
|
+
* Usage: @allFirstHost({ root: 'shadow' }) firsts: HTMLElement[];
|
|
191
|
+
*/
|
|
192
|
+
export function allFirstHost(target: Object, propertyKey: string | symbol): void;
|
|
193
|
+
export function allFirstHost(): PropertyDecorator;
|
|
194
|
+
export function allFirstHost(options: SwcQueryOptions): PropertyDecorator;
|
|
195
|
+
export function allFirstHost(targetOrOptions?: any, propertyKey?: string | symbol): any {
|
|
196
|
+
if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {
|
|
197
|
+
return queryAll(':firstHost', {})(targetOrOptions, propertyKey);
|
|
198
|
+
}
|
|
199
|
+
if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {
|
|
200
|
+
return queryAll(':firstHost', targetOrOptions as SwcQueryOptions);
|
|
201
|
+
} else {
|
|
202
|
+
return queryAll(':firstHost', {});
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* @allLastHost - Query all :lastHost (All last components in hierarchy)
|
|
208
|
+
* Usage: @allLastHost lasts: HTMLElement[];
|
|
209
|
+
* Usage: @allLastHost() lasts: HTMLElement[];
|
|
210
|
+
* Usage: @allLastHost({ root: 'shadow' }) lasts: HTMLElement[];
|
|
211
|
+
*/
|
|
212
|
+
export function allLastHost(target: Object, propertyKey: string | symbol): void;
|
|
213
|
+
export function allLastHost(): PropertyDecorator;
|
|
214
|
+
export function allLastHost(options: SwcQueryOptions): PropertyDecorator;
|
|
215
|
+
export function allLastHost(targetOrOptions?: any, propertyKey?: string | symbol): any {
|
|
216
|
+
if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {
|
|
217
|
+
return queryAll(':lastHost', {})(targetOrOptions, propertyKey);
|
|
218
|
+
}
|
|
219
|
+
if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {
|
|
220
|
+
return queryAll(':lastHost', targetOrOptions as SwcQueryOptions);
|
|
221
|
+
} else {
|
|
222
|
+
return queryAll(':lastHost', {});
|
|
223
|
+
}
|
|
118
224
|
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* @allFirstAppHost - Query all :firstAppHost (All first <swc-app> in hierarchy)
|
|
228
|
+
* Usage: @allFirstAppHost apps: SwcAppInterface[];
|
|
229
|
+
* Usage: @allFirstAppHost() apps: SwcAppInterface[];
|
|
230
|
+
* Usage: @allFirstAppHost({ root: 'shadow' }) apps: SwcAppInterface[];
|
|
231
|
+
*/
|
|
232
|
+
export function allFirstAppHost(target: Object, propertyKey: string | symbol): void;
|
|
233
|
+
export function allFirstAppHost(): PropertyDecorator;
|
|
234
|
+
export function allFirstAppHost(options: SwcQueryOptions): PropertyDecorator;
|
|
235
|
+
export function allFirstAppHost(targetOrOptions?: any, propertyKey?: string | symbol): any {
|
|
236
|
+
if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {
|
|
237
|
+
return queryAll(':firstAppHost', {})(targetOrOptions, propertyKey);
|
|
238
|
+
}
|
|
239
|
+
if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {
|
|
240
|
+
return queryAll(':firstAppHost', targetOrOptions as SwcQueryOptions);
|
|
241
|
+
} else {
|
|
242
|
+
return queryAll(':firstAppHost', {});
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* @allLastAppHost - Query all :lastAppHost (All last <swc-app> in hierarchy)
|
|
248
|
+
* Usage: @allLastAppHost apps: SwcAppInterface[];
|
|
249
|
+
* Usage: @allLastAppHost() apps: SwcAppInterface[];
|
|
250
|
+
* Usage: @allLastAppHost({ root: 'shadow' }) apps: SwcAppInterface[];
|
|
251
|
+
*/
|
|
252
|
+
export function allLastAppHost(target: Object, propertyKey: string | symbol): void;
|
|
253
|
+
export function allLastAppHost(): PropertyDecorator;
|
|
254
|
+
export function allLastAppHost(options: SwcQueryOptions): PropertyDecorator;
|
|
255
|
+
export function allLastAppHost(targetOrOptions?: any, propertyKey?: string | symbol): any {
|
|
256
|
+
if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {
|
|
257
|
+
return queryAll(':lastAppHost', {})(targetOrOptions, propertyKey);
|
|
258
|
+
}
|
|
259
|
+
if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {
|
|
260
|
+
return queryAll(':lastAppHost', targetOrOptions as SwcQueryOptions);
|
|
261
|
+
} else {
|
|
262
|
+
return queryAll(':lastAppHost', {});
|
|
263
|
+
}
|
|
264
|
+
}
|
|
@@ -9,12 +9,19 @@ import { ConstructorType, OptionalType } from '@dooboostore/core';
|
|
|
9
9
|
import { FunctionUtils } from '@dooboostore/core';
|
|
10
10
|
import { SwcUtils } from '../utils/Utils';
|
|
11
11
|
|
|
12
|
+
import { SwcAppInterface } from '../types';
|
|
13
|
+
import {Intent} from "@dooboostore/simple-boot";
|
|
14
|
+
|
|
12
15
|
export type SwcConfigType = {
|
|
13
16
|
rootRouter: ConstructorType<any> | symbol;
|
|
14
17
|
routeType: 'path' | 'hash' | 'element';
|
|
15
18
|
connectMode?: 'direct' | 'swap';
|
|
19
|
+
container?: symbol;
|
|
16
20
|
path?: string;
|
|
17
21
|
window: Window;
|
|
22
|
+
onStarted?: (app: SwcAppInterface) => void;
|
|
23
|
+
onConnected?: (app: SwcAppInterface) => void;
|
|
24
|
+
onDisconnected?: (app: SwcAppInterface) => void;
|
|
18
25
|
};
|
|
19
26
|
|
|
20
27
|
export type SwcAttributeConfigType = OptionalType<SwcConfigType, 'routeType' | 'window'>;
|
|
@@ -24,9 +31,13 @@ export class SwcAppEngine {
|
|
|
24
31
|
public router?: Router;
|
|
25
32
|
private routerSubscription?: Subscription;
|
|
26
33
|
private _isInitialized = false;
|
|
34
|
+
private _config?: SwcConfigType;
|
|
27
35
|
|
|
28
36
|
constructor(private host: HTMLElement) {}
|
|
29
37
|
|
|
38
|
+
get config() {
|
|
39
|
+
return this._config;
|
|
40
|
+
}
|
|
30
41
|
async connect(config?: SwcAttributeConfigType) {
|
|
31
42
|
if (this._isInitialized) return;
|
|
32
43
|
|
|
@@ -37,10 +48,11 @@ export class SwcAppEngine {
|
|
|
37
48
|
const configStr = this.host.getAttribute('swc-get-application-config');
|
|
38
49
|
if (configStr) {
|
|
39
50
|
try {
|
|
51
|
+
// console.log('vvvvvvvvvvvvvvvv->>>>', SwcUtils.findNearestSwcHost(this.host), SwcUtils.getHostSet(this.host))
|
|
40
52
|
userConfig = FunctionUtils.executeReturn({
|
|
41
53
|
script: configStr,
|
|
42
54
|
context: this.host,
|
|
43
|
-
args: SwcUtils.getHelperAndHostSet(win, this.host)
|
|
55
|
+
args: SwcUtils.getHelperAndHostSet(win, SwcUtils.findNearestSwcHost(this.host))
|
|
44
56
|
});
|
|
45
57
|
} catch (e) {
|
|
46
58
|
console.error('[SWC-APP-ENGINE] Script execution failed:', e);
|
|
@@ -53,11 +65,12 @@ export class SwcAppEngine {
|
|
|
53
65
|
|
|
54
66
|
try {
|
|
55
67
|
if (userConfig.rootRouter) {
|
|
56
|
-
|
|
68
|
+
this._config = {
|
|
57
69
|
routeType: 'element',
|
|
58
70
|
window: win,
|
|
59
71
|
...userConfig
|
|
60
72
|
} as SwcConfigType;
|
|
73
|
+
const _config = this._config;
|
|
61
74
|
|
|
62
75
|
// Router Selection
|
|
63
76
|
if (_config.routeType === 'path') {
|
|
@@ -68,23 +81,34 @@ export class SwcAppEngine {
|
|
|
68
81
|
this.router = new ElementRouter({ window: _config.window, firstUrl: _config.path });
|
|
69
82
|
}
|
|
70
83
|
|
|
84
|
+
// console.log('vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv', this.router)
|
|
85
|
+
|
|
71
86
|
// Routing sync
|
|
72
87
|
if (this.router) {
|
|
73
88
|
this.routerSubscription = this.router.observable.subscribe((route: RouterEventType) => {
|
|
74
89
|
if (route.triggerPoint === 'end') {
|
|
75
|
-
|
|
90
|
+
const targetPath = (route.path || '/') + route.search;
|
|
91
|
+
const intent = new Intent(targetPath);
|
|
92
|
+
this.simpleApplication?.routing(intent);
|
|
76
93
|
}
|
|
77
94
|
});
|
|
78
95
|
}
|
|
79
96
|
|
|
80
97
|
|
|
81
98
|
// App start
|
|
82
|
-
|
|
99
|
+
const containerSymbol = _config.container || (this.host as any).getContainerSymbol?.();
|
|
100
|
+
this.simpleApplication = new SimpleApplication(new SimOption({
|
|
101
|
+
excludeProxys: [Node],
|
|
102
|
+
rootRouter: _config.rootRouter,
|
|
103
|
+
container: containerSymbol
|
|
104
|
+
}));
|
|
83
105
|
|
|
84
106
|
const otherInstanceSim = new Map<any, any>();
|
|
85
107
|
if (this.router) otherInstanceSim.set(Router, this.router);
|
|
86
108
|
this.simpleApplication.run(otherInstanceSim);
|
|
87
109
|
|
|
110
|
+
|
|
111
|
+
|
|
88
112
|
// Rendering
|
|
89
113
|
const data = this.simpleApplication.sim(_config.rootRouter);
|
|
90
114
|
if (data instanceof Node) {
|
|
@@ -94,12 +118,16 @@ export class SwcAppEngine {
|
|
|
94
118
|
}
|
|
95
119
|
|
|
96
120
|
if (_config.path) this.router?.go(_config.path);
|
|
121
|
+
if (_config.onStarted) {
|
|
122
|
+
_config.onStarted(this.host as unknown as SwcAppInterface);
|
|
123
|
+
}
|
|
97
124
|
}
|
|
98
125
|
} catch (e) {
|
|
99
126
|
console.error('[SWC-APP-ENGINE] Init failed:', e);
|
|
100
127
|
}
|
|
101
128
|
}
|
|
102
129
|
|
|
130
|
+
|
|
103
131
|
disconnect() {
|
|
104
132
|
this.routerSubscription?.unsubscribe();
|
|
105
133
|
}
|
|
@@ -51,12 +51,14 @@ export function SwcAppMixin<T extends { new (...args: any[]): HTMLElement }>(Bas
|
|
|
51
51
|
// @ts-ignore
|
|
52
52
|
if (super.connectedCallback) super.connectedCallback();
|
|
53
53
|
this.connect();
|
|
54
|
+
this.__swc_engine?.config?.onConnected?.(this);
|
|
54
55
|
}
|
|
55
56
|
|
|
56
57
|
disconnectedCallback() {
|
|
57
58
|
// @ts-ignore
|
|
58
59
|
if (super.disconnectedCallback) super.disconnectedCallback();
|
|
59
60
|
this.__swc_engine.disconnect();
|
|
61
|
+
this.__swc_engine?.config?.onDisconnected?.(this);
|
|
60
62
|
}
|
|
61
63
|
|
|
62
64
|
async routing(path: string) {
|
package/src/index.ts
CHANGED
|
@@ -10,18 +10,18 @@ export * from './types';
|
|
|
10
10
|
|
|
11
11
|
// Utilities
|
|
12
12
|
export * from './utils/Utils';
|
|
13
|
-
export * from './utils/TemplateUtils';
|
|
14
13
|
|
|
15
14
|
// Config
|
|
16
15
|
export * from './config/config';
|
|
17
16
|
|
|
18
17
|
// Registration Factory
|
|
19
|
-
export default (w: Window, other?: ((w: Window) => ConstructorType<any>)
|
|
18
|
+
export default (w: Window, other?: (((w: Window) => ConstructorType<any>) | any) []) => {
|
|
20
19
|
registerAllElements(w);
|
|
21
20
|
const r = other?.map(fn => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
if (typeof fn === 'function') {
|
|
22
|
+
const a = fn(w);
|
|
23
|
+
} else {
|
|
24
|
+
}
|
|
25
25
|
});
|
|
26
|
-
return r??[];
|
|
26
|
+
// return r??[];
|
|
27
27
|
};
|
package/src/utils/Utils.ts
CHANGED
|
@@ -1,7 +1,151 @@
|
|
|
1
1
|
import { SwcAppInterface, HostSet, HelperSet, HelperHostSet } from '../types';
|
|
2
2
|
import {getElementConfig} from "../decorators";
|
|
3
3
|
|
|
4
|
-
export const SWC_NOT_FOUND = Symbol('
|
|
4
|
+
export const SWC_NOT_FOUND = Symbol.for('simple-web-component:not-found');
|
|
5
|
+
|
|
6
|
+
// DOM Creation Utilities
|
|
7
|
+
export const htmlFragment = (html: string, doc?: Document): DocumentFragment => {
|
|
8
|
+
const d = doc || (typeof document !== 'undefined' ? document : undefined);
|
|
9
|
+
if (!d) throw new Error('Document is not available');
|
|
10
|
+
const template = d.createElement('template');
|
|
11
|
+
template.innerHTML = html.trim();
|
|
12
|
+
return template.content;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const textNode = (text: string | any, doc?: Document): Text => {
|
|
16
|
+
const d = doc || (typeof document !== 'undefined' ? document : undefined);
|
|
17
|
+
if (!d) throw new Error('Document is not available');
|
|
18
|
+
return d.createTextNode(text !== undefined && text !== null ? String(text) : '');
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const commentNode = (comment: string | any, doc?: Document): Comment => {
|
|
22
|
+
const d = doc || (typeof document !== 'undefined' ? document : undefined);
|
|
23
|
+
if (!d) throw new Error('Document is not available');
|
|
24
|
+
return d.createComment(comment !== undefined && comment !== null ? String(comment) : '');
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const createElement = <T extends HTMLElement>(
|
|
28
|
+
tagName: string,
|
|
29
|
+
options?: { html?: string; attrs?: Record<string, any>; doc?: Document }
|
|
30
|
+
): T => {
|
|
31
|
+
const d = options?.doc || (typeof document !== 'undefined' ? document : undefined);
|
|
32
|
+
if (!d) throw new Error('Document is not available');
|
|
33
|
+
const el = d.createElement(tagName) as T;
|
|
34
|
+
if (options?.html) el.innerHTML = options.html;
|
|
35
|
+
if (options?.attrs) {
|
|
36
|
+
Object.entries(options.attrs).forEach(([k, v]) => el.setAttribute(k, String(v)));
|
|
37
|
+
}
|
|
38
|
+
return el;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// Element factory functions
|
|
42
|
+
export const htmlDivElement = (html: string, options?: { doc?: Document; attrs?: Record<string, any> }): HTMLDivElement => {
|
|
43
|
+
const d = options?.doc || (typeof document !== 'undefined' ? document : undefined);
|
|
44
|
+
if (!d) throw new Error('Document is not available');
|
|
45
|
+
const el = d.createElement('div') as HTMLDivElement;
|
|
46
|
+
el.innerHTML = html.trim();
|
|
47
|
+
if (options?.attrs) {
|
|
48
|
+
Object.entries(options.attrs).forEach(([k, v]) => el.setAttribute(k, String(v)));
|
|
49
|
+
}
|
|
50
|
+
return el;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export const htmlSpanElement = (html: string, options?: { doc?: Document; attrs?: Record<string, any> }): HTMLSpanElement => {
|
|
54
|
+
const d = options?.doc || (typeof document !== 'undefined' ? document : undefined);
|
|
55
|
+
if (!d) throw new Error('Document is not available');
|
|
56
|
+
const el = d.createElement('span') as HTMLSpanElement;
|
|
57
|
+
el.innerHTML = html.trim();
|
|
58
|
+
if (options?.attrs) {
|
|
59
|
+
Object.entries(options.attrs).forEach(([k, v]) => el.setAttribute(k, String(v)));
|
|
60
|
+
}
|
|
61
|
+
return el;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export const htmlButtonElement = (html: string, options?: { doc?: Document; attrs?: Record<string, any> }): HTMLButtonElement => {
|
|
65
|
+
const d = options?.doc || (typeof document !== 'undefined' ? document : undefined);
|
|
66
|
+
if (!d) throw new Error('Document is not available');
|
|
67
|
+
const el = d.createElement('button') as HTMLButtonElement;
|
|
68
|
+
el.innerHTML = html.trim();
|
|
69
|
+
if (options?.attrs) {
|
|
70
|
+
Object.entries(options.attrs).forEach(([k, v]) => el.setAttribute(k, String(v)));
|
|
71
|
+
}
|
|
72
|
+
return el;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export const htmlUlElement = (options?: { doc?: Document; attrs?: Record<string, any> }): HTMLUListElement => {
|
|
76
|
+
const d = options?.doc || (typeof document !== 'undefined' ? document : undefined);
|
|
77
|
+
if (!d) throw new Error('Document is not available');
|
|
78
|
+
const el = d.createElement('ul') as HTMLUListElement;
|
|
79
|
+
if (options?.attrs) {
|
|
80
|
+
Object.entries(options.attrs).forEach(([k, v]) => el.setAttribute(k, String(v)));
|
|
81
|
+
}
|
|
82
|
+
return el;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export const htmlLiElement = (html: string, options?: { doc?: Document; attrs?: Record<string, any> }): HTMLLIElement => {
|
|
86
|
+
const d = options?.doc || (typeof document !== 'undefined' ? document : undefined);
|
|
87
|
+
if (!d) throw new Error('Document is not available');
|
|
88
|
+
const el = d.createElement('li') as HTMLLIElement;
|
|
89
|
+
el.innerHTML = html.trim();
|
|
90
|
+
if (options?.attrs) {
|
|
91
|
+
Object.entries(options.attrs).forEach(([k, v]) => el.setAttribute(k, String(v)));
|
|
92
|
+
}
|
|
93
|
+
return el;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export const htmlAElement = (html: string, options?: { href?: string; doc?: Document; attrs?: Record<string, any> }): HTMLAnchorElement => {
|
|
97
|
+
const d = options?.doc || (typeof document !== 'undefined' ? document : undefined);
|
|
98
|
+
if (!d) throw new Error('Document is not available');
|
|
99
|
+
const el = d.createElement('a') as HTMLAnchorElement;
|
|
100
|
+
el.innerHTML = html.trim();
|
|
101
|
+
if (options?.href) el.href = options.href;
|
|
102
|
+
if (options?.attrs) {
|
|
103
|
+
Object.entries(options.attrs).forEach(([k, v]) => el.setAttribute(k, String(v)));
|
|
104
|
+
}
|
|
105
|
+
return el;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export const htmlPElement = (html: string, options?: { doc?: Document; attrs?: Record<string, any> }): HTMLParagraphElement => {
|
|
109
|
+
const d = options?.doc || (typeof document !== 'undefined' ? document : undefined);
|
|
110
|
+
if (!d) throw new Error('Document is not available');
|
|
111
|
+
const el = d.createElement('p') as HTMLParagraphElement;
|
|
112
|
+
el.innerHTML = html.trim();
|
|
113
|
+
if (options?.attrs) {
|
|
114
|
+
Object.entries(options.attrs).forEach(([k, v]) => el.setAttribute(k, String(v)));
|
|
115
|
+
}
|
|
116
|
+
return el;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
export const htmlHeadingElement = (level: 1 | 2 | 3 | 4 | 5 | 6, html: string, options?: { doc?: Document; attrs?: Record<string, any> }): HTMLHeadingElement => {
|
|
120
|
+
const d = options?.doc || (typeof document !== 'undefined' ? document : undefined);
|
|
121
|
+
if (!d) throw new Error('Document is not available');
|
|
122
|
+
const el = d.createElement(`h${level}`) as HTMLHeadingElement;
|
|
123
|
+
el.innerHTML = html.trim();
|
|
124
|
+
if (options?.attrs) {
|
|
125
|
+
Object.entries(options.attrs).forEach(([k, v]) => el.setAttribute(k, String(v)));
|
|
126
|
+
}
|
|
127
|
+
return el;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
export const htmlSectionElement = (options?: { doc?: Document; attrs?: Record<string, any> }): HTMLElement => {
|
|
131
|
+
const d = options?.doc || (typeof document !== 'undefined' ? document : undefined);
|
|
132
|
+
if (!d) throw new Error('Document is not available');
|
|
133
|
+
const el = d.createElement('section');
|
|
134
|
+
if (options?.attrs) {
|
|
135
|
+
Object.entries(options.attrs).forEach(([k, v]) => el.setAttribute(k, String(v)));
|
|
136
|
+
}
|
|
137
|
+
return el;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
export const htmlArticleElement = (options?: { doc?: Document; attrs?: Record<string, any> }): HTMLElement => {
|
|
141
|
+
const d = options?.doc || (typeof document !== 'undefined' ? document : undefined);
|
|
142
|
+
if (!d) throw new Error('Document is not available');
|
|
143
|
+
const el = d.createElement('article');
|
|
144
|
+
if (options?.attrs) {
|
|
145
|
+
Object.entries(options.attrs).forEach(([k, v]) => el.setAttribute(k, String(v)));
|
|
146
|
+
}
|
|
147
|
+
return el;
|
|
148
|
+
};
|
|
5
149
|
|
|
6
150
|
export namespace SwcUtils {
|
|
7
151
|
export const getHelperSet = (win: Window): HelperSet => {
|
|
@@ -43,6 +187,7 @@ export namespace SwcUtils {
|
|
|
43
187
|
*/
|
|
44
188
|
export const findNearestSwcHost = (el: HTMLElement | Node): HTMLElement | undefined => {
|
|
45
189
|
if ((el as any).__swc_host) return (el as any).__swc_host;
|
|
190
|
+
// if ((el as any).__swc_proto_setup) return (el as any).__swc_proto_setup;
|
|
46
191
|
|
|
47
192
|
let current: any = el.parentElement || (el.getRootNode?.() as any)?.host;
|
|
48
193
|
const doc = el.ownerDocument;
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var classList_exports = {};
|
|
19
|
-
__export(classList_exports, {
|
|
20
|
-
CLASS_LIST_METADATA_KEY: () => CLASS_LIST_METADATA_KEY,
|
|
21
|
-
addClassList: () => addClassList,
|
|
22
|
-
addClassListHost: () => addClassListHost,
|
|
23
|
-
findAllClassListMetadata: () => findAllClassListMetadata,
|
|
24
|
-
removeClassList: () => removeClassList,
|
|
25
|
-
removeClassListHost: () => removeClassListHost,
|
|
26
|
-
setClassList: () => setClassList,
|
|
27
|
-
setClassListHost: () => setClassListHost,
|
|
28
|
-
toggleClassList: () => toggleClassList,
|
|
29
|
-
toggleClassListHost: () => toggleClassListHost,
|
|
30
|
-
updateClassList: () => updateClassList,
|
|
31
|
-
updateClassListHost: () => updateClassListHost
|
|
32
|
-
});
|
|
33
|
-
module.exports = __toCommonJS(classList_exports);
|
|
34
|
-
var import_core = require("@dooboostore/core");
|
|
35
|
-
var import_elementDefine = require("./elementDefine");
|
|
36
|
-
var import_Utils = require("../utils/Utils");
|
|
37
|
-
const CLASS_LIST_METADATA_KEY = Symbol("simple-web-component:class-list");
|
|
38
|
-
function createClassListDecorator(action) {
|
|
39
|
-
return (selector, options = {}) => {
|
|
40
|
-
return (target, propertyKey, descriptor) => {
|
|
41
|
-
const constructor = target.constructor;
|
|
42
|
-
let metaList = import_core.ReflectUtils.getOwnMetadata(CLASS_LIST_METADATA_KEY, constructor);
|
|
43
|
-
if (!metaList) {
|
|
44
|
-
metaList = /* @__PURE__ */ new Map();
|
|
45
|
-
import_core.ReflectUtils.defineMetadata(CLASS_LIST_METADATA_KEY, metaList, constructor);
|
|
46
|
-
}
|
|
47
|
-
metaList.set(propertyKey, { propertyKey, selector, action, options });
|
|
48
|
-
const original = descriptor.value;
|
|
49
|
-
descriptor.value = async function(...args) {
|
|
50
|
-
(0, import_elementDefine.ensureInit)(this);
|
|
51
|
-
const res = await original.apply(this, args);
|
|
52
|
-
if (res !== void 0) {
|
|
53
|
-
const r = options.root || "auto";
|
|
54
|
-
const hostSet = import_Utils.SwcUtils.getHostSet(this);
|
|
55
|
-
const targetEls = [];
|
|
56
|
-
if (selector === ":host" || !selector) {
|
|
57
|
-
targetEls.push(this);
|
|
58
|
-
} else if (selector === ":parentHost") {
|
|
59
|
-
if (hostSet.$parentHost) targetEls.push(hostSet.$parentHost);
|
|
60
|
-
} else if (selector === ":appHost") {
|
|
61
|
-
if (hostSet.$appHost) targetEls.push(hostSet.$appHost);
|
|
62
|
-
} else {
|
|
63
|
-
if (r === "shadow") {
|
|
64
|
-
const found = this.shadowRoot?.querySelectorAll(selector);
|
|
65
|
-
if (found) targetEls.push(...found);
|
|
66
|
-
} else if (r === "light") {
|
|
67
|
-
const found = this.querySelectorAll(selector);
|
|
68
|
-
if (found) targetEls.push(...found);
|
|
69
|
-
} else if (r === "all") {
|
|
70
|
-
const sFound = this.shadowRoot?.querySelectorAll(selector);
|
|
71
|
-
const lFound = this.querySelectorAll(selector);
|
|
72
|
-
if (sFound) targetEls.push(...sFound);
|
|
73
|
-
if (lFound) targetEls.push(...lFound);
|
|
74
|
-
} else {
|
|
75
|
-
const found = (this.shadowRoot || this).querySelectorAll(selector);
|
|
76
|
-
if (found) targetEls.push(...found);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
targetEls.forEach((targetEl) => {
|
|
80
|
-
if (action === "set") {
|
|
81
|
-
let classes = "";
|
|
82
|
-
if (typeof res === "object" && res !== null && !Array.isArray(res)) {
|
|
83
|
-
classes = Object.entries(res).filter(([_, force]) => !!force).map(([cls]) => cls).join(" ");
|
|
84
|
-
} else {
|
|
85
|
-
classes = Array.isArray(res) ? res.join(" ") : String(res);
|
|
86
|
-
}
|
|
87
|
-
targetEl.className = classes;
|
|
88
|
-
} else if (action === "update") {
|
|
89
|
-
if (typeof res === "object" && res !== null && !Array.isArray(res)) {
|
|
90
|
-
Object.entries(res).forEach(([cls, force]) => {
|
|
91
|
-
targetEl.classList.toggle(cls, !!force);
|
|
92
|
-
});
|
|
93
|
-
} else if (res !== void 0 && res !== null) {
|
|
94
|
-
const classes = Array.isArray(res) ? res.map(String) : [String(res)];
|
|
95
|
-
targetEl.classList.add(...classes);
|
|
96
|
-
}
|
|
97
|
-
} else if (action === "add") {
|
|
98
|
-
const classes = Array.isArray(res) ? res.map(String) : [String(res)];
|
|
99
|
-
targetEl.classList.add(...classes);
|
|
100
|
-
} else if (action === "remove") {
|
|
101
|
-
const classes = Array.isArray(res) ? res.map(String) : [String(res)];
|
|
102
|
-
targetEl.classList.remove(...classes);
|
|
103
|
-
} else if (action === "toggle") {
|
|
104
|
-
const classes = Array.isArray(res) ? res.map(String) : [String(res)];
|
|
105
|
-
classes.forEach((c) => targetEl.classList.toggle(c));
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
return res;
|
|
110
|
-
};
|
|
111
|
-
};
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
const setClassList = (selector, options = {}) => createClassListDecorator("set")(selector, options);
|
|
115
|
-
const updateClassList = (selector, options = {}) => createClassListDecorator("update")(selector, options);
|
|
116
|
-
const addClassList = (selector, options = {}) => createClassListDecorator("add")(selector, options);
|
|
117
|
-
const removeClassList = (selector, options = {}) => createClassListDecorator("remove")(selector, options);
|
|
118
|
-
const toggleClassList = (selector, options = {}) => createClassListDecorator("toggle")(selector, options);
|
|
119
|
-
const setClassListHost = (options = {}) => createClassListDecorator("set")(":host", options);
|
|
120
|
-
const updateClassListHost = (options = {}) => createClassListDecorator("update")(":host", options);
|
|
121
|
-
const addClassListHost = (options = {}) => createClassListDecorator("add")(":host", options);
|
|
122
|
-
const removeClassListHost = (options = {}) => createClassListDecorator("remove")(":host", options);
|
|
123
|
-
const toggleClassListHost = (options = {}) => createClassListDecorator("toggle")(":host", options);
|
|
124
|
-
const findAllClassListMetadata = (target) => {
|
|
125
|
-
const result = /* @__PURE__ */ new Map();
|
|
126
|
-
const maps = import_core.ReflectUtils.findAllMetadata(CLASS_LIST_METADATA_KEY, target);
|
|
127
|
-
maps.forEach((map) => {
|
|
128
|
-
if (map instanceof Map) {
|
|
129
|
-
map.forEach((v, k) => result.set(k, v));
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
return result;
|
|
133
|
-
};
|
|
134
|
-
//# sourceMappingURL=classList.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/decorators/classList.ts"],
|
|
4
|
-
"sourcesContent": ["import { ReflectUtils } from '@dooboostore/core';\nimport { ensureInit } from './elementDefine';\nimport { SwcUtils } from '../utils/Utils';\nimport { SwcQueryOptions } from '../types';\n\nexport const CLASS_LIST_METADATA_KEY = Symbol('simple-web-component:class-list');\n\nexport type ClassListAction = 'set' | 'update' | 'add' | 'remove' | 'toggle';\n\nexport interface ClassListMetadata {\n propertyKey: string | symbol;\n selector: string;\n action: ClassListAction;\n options: SwcQueryOptions;\n}\n\nfunction createClassListDecorator(action: ClassListAction) {\n return (selector: string, options: SwcQueryOptions = {}): MethodDecorator => {\n return (target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n const constructor = target.constructor;\n let metaList = ReflectUtils.getOwnMetadata(CLASS_LIST_METADATA_KEY, constructor) as Map<string | symbol, ClassListMetadata>;\n if (!metaList) {\n metaList = new Map<string | symbol, ClassListMetadata>();\n ReflectUtils.defineMetadata(CLASS_LIST_METADATA_KEY, metaList, constructor);\n }\n metaList.set(propertyKey, { propertyKey, selector, action, options });\n\n const original = descriptor.value;\n descriptor.value = async function (...args: any[]) {\n ensureInit(this);\n const res = await original.apply(this, args);\n if (res !== undefined) {\n const r = options.root || 'auto';\n const hostSet = SwcUtils.getHostSet(this as any);\n const targetEls: HTMLElement[] = [];\n\n if (selector === ':host' || !selector) {\n targetEls.push(this as any);\n } else if (selector === ':parentHost') {\n if (hostSet.$parentHost) targetEls.push(hostSet.$parentHost);\n } else if (selector === ':appHost') {\n if (hostSet.$appHost) targetEls.push(hostSet.$appHost);\n } else {\n if (r === 'shadow') {\n const found = this.shadowRoot?.querySelectorAll(selector);\n if (found) targetEls.push(...found);\n } else if (r === 'light') {\n const found = (this as any).querySelectorAll(selector);\n if (found) targetEls.push(...found);\n } else if (r === 'all') {\n const sFound = this.shadowRoot?.querySelectorAll(selector);\n const lFound = (this as any).querySelectorAll(selector);\n if (sFound) targetEls.push(...sFound);\n if (lFound) targetEls.push(...lFound);\n } else {\n // auto\n const found = (this.shadowRoot || (this as any)).querySelectorAll(selector);\n if (found) targetEls.push(...found);\n }\n }\n\n targetEls.forEach(targetEl => {\n if (action === 'set') {\n let classes = '';\n if (typeof res === 'object' && res !== null && !Array.isArray(res)) {\n classes = Object.entries(res)\n .filter(([_, force]) => !!force)\n .map(([cls]) => cls)\n .join(' ');\n } else {\n classes = Array.isArray(res) ? res.join(' ') : String(res);\n }\n targetEl.className = classes;\n } else if (action === 'update') {\n if (typeof res === 'object' && res !== null && !Array.isArray(res)) {\n Object.entries(res).forEach(([cls, force]) => {\n targetEl.classList.toggle(cls, !!force);\n });\n } else if (res !== undefined && res !== null) {\n const classes = Array.isArray(res) ? res.map(String) : [String(res)];\n targetEl.classList.add(...classes);\n }\n } else if (action === 'add') {\n const classes = Array.isArray(res) ? res.map(String) : [String(res)];\n targetEl.classList.add(...classes);\n } else if (action === 'remove') {\n const classes = Array.isArray(res) ? res.map(String) : [String(res)];\n targetEl.classList.remove(...classes);\n } else if (action === 'toggle') {\n const classes = Array.isArray(res) ? res.map(String) : [String(res)];\n classes.forEach(c => targetEl.classList.toggle(c));\n }\n });\n }\n return res;\n };\n };\n };\n}\n\n/**\n * @setClassList decorator to surgically replace all classes on a target element.\n * Returns: string | string[]\n */\nexport const setClassList = (selector: string, options: SwcQueryOptions = {}) => createClassListDecorator('set')(selector, options);\n\n/**\n * @updateClassList decorator to surgically update specific classes.\n * Returns: Record<string, boolean> (toggle with force) | string | string[] (add)\n */\nexport const updateClassList = (selector: string, options: SwcQueryOptions = {}) => createClassListDecorator('update')(selector, options);\n\n/**\n * @addClassList decorator to surgically add classes to a target element.\n * Returns: string | string[]\n */\nexport const addClassList = (selector: string, options: SwcQueryOptions = {}) => createClassListDecorator('add')(selector, options);\n\n/**\n * @removeClassList decorator to surgically remove classes from a target element.\n * Returns: string | string[]\n */\nexport const removeClassList = (selector: string, options: SwcQueryOptions = {}) => createClassListDecorator('remove')(selector, options);\n\n/**\n * @toggleClassList decorator to surgically toggle classes on a target element.\n * Returns: string | string[]\n */\nexport const toggleClassList = (selector: string, options: SwcQueryOptions = {}) => createClassListDecorator('toggle')(selector, options);\n\n// Host-specific versions (for :host selector)\n\n/**\n * @setClassListHost decorator to set classes on :host element.\n * Returns: string | string[]\n */\nexport const setClassListHost = (options: SwcQueryOptions = {}) => createClassListDecorator('set')(':host', options);\n\n/**\n * @updateClassListHost decorator to update specific classes on :host.\n * Returns: Record<string, boolean> (toggle with force) | string | string[] (add)\n */\nexport const updateClassListHost = (options: SwcQueryOptions = {}) => createClassListDecorator('update')(':host', options);\n\n/**\n * @addClassListHost decorator to add classes to :host element.\n * Returns: string | string[]\n */\nexport const addClassListHost = (options: SwcQueryOptions = {}) => createClassListDecorator('add')(':host', options);\n\n/**\n * @removeClassListHost decorator to remove classes from :host element.\n * Returns: string | string[]\n */\nexport const removeClassListHost = (options: SwcQueryOptions = {}) => createClassListDecorator('remove')(':host', options);\n\n/**\n * @toggleClassListHost decorator to toggle classes on :host element.\n * Returns: string | string[]\n */\nexport const toggleClassListHost = (options: SwcQueryOptions = {}) => createClassListDecorator('toggle')(':host', options);\n\nexport const findAllClassListMetadata = (target: any): Map<string | symbol, ClassListMetadata> => {\n const result = new Map<string | symbol, ClassListMetadata>();\n const maps = ReflectUtils.findAllMetadata<Map<string | symbol, ClassListMetadata>>(CLASS_LIST_METADATA_KEY, target);\n maps.forEach(map => {\n if (map instanceof Map) {\n map.forEach((v, k) => result.set(k, v));\n }\n });\n return result;\n};\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA6B;AAC7B,2BAA2B;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