@dooboostore/simple-web-component 1.0.34 → 1.0.36
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 +44 -51
- package/dist/cjs/decorators/addEventListener.js +12 -4
- package/dist/cjs/decorators/addEventListener.js.map +2 -2
- package/dist/cjs/decorators/applyAttribute.js +19 -18
- package/dist/cjs/decorators/applyAttribute.js.map +2 -2
- package/dist/cjs/decorators/applyClass.js +23 -22
- package/dist/cjs/decorators/applyClass.js.map +2 -2
- package/dist/cjs/decorators/applyNode.js +22 -17
- package/dist/cjs/decorators/applyNode.js.map +2 -2
- package/dist/cjs/decorators/applyStyle.js +20 -19
- package/dist/cjs/decorators/applyStyle.js.map +2 -2
- package/dist/cjs/decorators/attribute.js +17 -16
- package/dist/cjs/decorators/attribute.js.map +2 -2
- package/dist/cjs/decorators/{changedAttributeHost.js → changedAttributeThis.js} +6 -6
- package/dist/cjs/decorators/changedAttributeThis.js.map +7 -0
- package/dist/cjs/decorators/elementDefine.js +234 -188
- package/dist/cjs/decorators/elementDefine.js.map +2 -2
- package/dist/cjs/decorators/emitCustomEvent.js +24 -16
- package/dist/cjs/decorators/emitCustomEvent.js.map +2 -2
- package/dist/cjs/decorators/index.js +1 -1
- package/dist/cjs/decorators/index.js.map +1 -1
- package/dist/cjs/decorators/lifecycles.js +15 -17
- package/dist/cjs/decorators/lifecycles.js.map +2 -2
- package/dist/cjs/decorators/query.js +38 -60
- package/dist/cjs/decorators/query.js.map +2 -2
- package/dist/cjs/decorators/queryAll.js +31 -63
- package/dist/cjs/decorators/queryAll.js.map +2 -2
- package/dist/cjs/decorators/setProperty.js +13 -12
- package/dist/cjs/decorators/setProperty.js.map +2 -2
- package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js +2 -2
- package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
- package/dist/cjs/elements/SwcAppEngine.js +8 -2
- package/dist/cjs/elements/SwcAppEngine.js.map +2 -2
- package/dist/cjs/elements/SwcAppMixin.js +120 -65
- package/dist/cjs/elements/SwcAppMixin.js.map +2 -2
- package/dist/cjs/elements/SwcAsync.js +31 -21
- package/dist/cjs/elements/SwcAsync.js.map +2 -2
- package/dist/cjs/elements/SwcChoose.js +53 -34
- package/dist/cjs/elements/SwcChoose.js.map +2 -2
- package/dist/cjs/elements/SwcIf.js +54 -32
- package/dist/cjs/elements/SwcIf.js.map +2 -2
- package/dist/cjs/elements/SwcLoop.js +111 -37
- package/dist/cjs/elements/SwcLoop.js.map +2 -2
- package/dist/cjs/elements/register.js +249 -122
- 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 +31 -17
- package/dist/cjs/utils/Utils.js.map +2 -2
- package/dist/esm/decorators/addEventListener.js +12 -4
- package/dist/esm/decorators/addEventListener.js.map +2 -2
- package/dist/esm/decorators/applyAttribute.js +19 -18
- package/dist/esm/decorators/applyAttribute.js.map +2 -2
- package/dist/esm/decorators/applyClass.js +23 -22
- package/dist/esm/decorators/applyClass.js.map +2 -2
- package/dist/esm/decorators/applyNode.js +22 -17
- package/dist/esm/decorators/applyNode.js.map +2 -2
- package/dist/esm/decorators/applyStyle.js +20 -19
- package/dist/esm/decorators/applyStyle.js.map +2 -2
- package/dist/esm/decorators/attribute.js +17 -16
- package/dist/esm/decorators/attribute.js.map +2 -2
- package/dist/esm/decorators/{changedAttributeHost.js → changedAttributeThis.js} +3 -3
- package/dist/esm/decorators/changedAttributeThis.js.map +7 -0
- package/dist/esm/decorators/elementDefine.js +233 -187
- package/dist/esm/decorators/elementDefine.js.map +2 -2
- package/dist/esm/decorators/emitCustomEvent.js +24 -16
- package/dist/esm/decorators/emitCustomEvent.js.map +2 -2
- package/dist/esm/decorators/index.js +1 -1
- package/dist/esm/decorators/index.js.map +1 -1
- package/dist/esm/decorators/lifecycles.js +15 -17
- package/dist/esm/decorators/lifecycles.js.map +2 -2
- package/dist/esm/decorators/query.js +38 -60
- package/dist/esm/decorators/query.js.map +2 -2
- package/dist/esm/decorators/queryAll.js +31 -63
- package/dist/esm/decorators/queryAll.js.map +2 -2
- package/dist/esm/decorators/setProperty.js +13 -12
- package/dist/esm/decorators/setProperty.js.map +2 -2
- package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js +2 -2
- package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
- package/dist/esm/elements/SwcAppEngine.js +9 -2
- package/dist/esm/elements/SwcAppEngine.js.map +2 -2
- package/dist/esm/elements/SwcAppMixin.js +122 -66
- package/dist/esm/elements/SwcAppMixin.js.map +2 -2
- package/dist/esm/elements/SwcAsync.js +32 -22
- package/dist/esm/elements/SwcAsync.js.map +2 -2
- package/dist/esm/elements/SwcChoose.js +54 -35
- package/dist/esm/elements/SwcChoose.js.map +2 -2
- package/dist/esm/elements/SwcIf.js +55 -33
- package/dist/esm/elements/SwcIf.js.map +2 -2
- package/dist/esm/elements/SwcLoop.js +112 -38
- package/dist/esm/elements/SwcLoop.js.map +2 -2
- package/dist/esm/elements/register.js +250 -123
- 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 +31 -17
- package/dist/esm/utils/Utils.js.map +2 -2
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +563 -557
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
- package/dist/types/decorators/addEventListener.d.ts +5 -7
- package/dist/types/decorators/addEventListener.d.ts.map +1 -1
- package/dist/types/decorators/applyAttribute.d.ts +4 -4
- package/dist/types/decorators/applyAttribute.d.ts.map +1 -1
- package/dist/types/decorators/applyClass.d.ts +6 -6
- package/dist/types/decorators/applyClass.d.ts.map +1 -1
- package/dist/types/decorators/applyNode.d.ts +7 -6
- package/dist/types/decorators/applyNode.d.ts.map +1 -1
- package/dist/types/decorators/applyStyle.d.ts +4 -4
- package/dist/types/decorators/applyStyle.d.ts.map +1 -1
- package/dist/types/decorators/attribute.d.ts +5 -5
- package/dist/types/decorators/attribute.d.ts.map +1 -1
- package/dist/types/decorators/changedAttributeThis.d.ts +18 -0
- package/dist/types/decorators/changedAttributeThis.d.ts.map +1 -0
- package/dist/types/decorators/elementDefine.d.ts.map +1 -1
- package/dist/types/decorators/emitCustomEvent.d.ts +11 -12
- package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
- package/dist/types/decorators/index.d.ts +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/query.d.ts +17 -63
- package/dist/types/decorators/query.d.ts.map +1 -1
- package/dist/types/decorators/queryAll.d.ts +6 -63
- 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/subscribeSwcAppRouteChangeWhileConnected.d.ts +4 -5
- package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts.map +1 -1
- package/dist/types/elements/SwcAppEngine.d.ts +4 -1
- package/dist/types/elements/SwcAppEngine.d.ts.map +1 -1
- package/dist/types/elements/SwcAppMixin.d.ts +11 -8
- 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 +3 -2
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils/Utils.d.ts +11 -8
- package/dist/types/utils/Utils.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +563 -557
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +3 -3
- package/src/decorators/addEventListener.ts +11 -9
- package/src/decorators/applyAttribute.ts +16 -15
- package/src/decorators/applyClass.ts +18 -17
- package/src/decorators/applyNode.ts +34 -21
- package/src/decorators/applyStyle.ts +17 -16
- package/src/decorators/attribute.ts +21 -20
- package/src/decorators/{changedAttributeHost.ts → changedAttributeThis.ts} +13 -14
- package/src/decorators/elementDefine.ts +402 -358
- package/src/decorators/emitCustomEvent.ts +40 -31
- package/src/decorators/index.ts +1 -1
- package/src/decorators/lifecycles.ts +11 -10
- package/src/decorators/query.ts +51 -124
- package/src/decorators/queryAll.ts +30 -127
- package/src/decorators/setProperty.ts +12 -11
- package/src/decorators/subscribeSwcAppRouteChangeWhileConnected.ts +10 -10
- package/src/elements/SwcAppEngine.ts +10 -3
- package/src/elements/SwcAppMixin.ts +177 -97
- package/src/elements/SwcAsync.ts +32 -21
- package/src/elements/SwcChoose.ts +74 -37
- package/src/elements/SwcIf.ts +60 -23
- package/src/elements/SwcLoop.ts +141 -28
- package/src/elements/register.ts +300 -102
- package/src/types.ts +6 -5
- package/src/utils/Utils.ts +40 -23
- package/tsconfig.json +2 -2
- package/dist/cjs/decorators/changedAttributeHost.js.map +0 -7
- package/dist/esm/decorators/changedAttributeHost.js.map +0 -7
- package/dist/types/decorators/changedAttributeHost.d.ts +0 -19
- package/dist/types/decorators/changedAttributeHost.d.ts.map +0 -1
package/src/utils/Utils.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { SwcAppInterface, HostSet, HelperSet, HelperHostSet } from '../types';
|
|
2
2
|
import {getElementConfig} from "../decorators";
|
|
3
3
|
import { getExpression, ExpressionResult, GetExpressionConfig, GetExpressionResult } from '@dooboostore/core';
|
|
4
|
+
import {Router} from "@dooboostore/core-web";
|
|
4
5
|
|
|
5
6
|
export const SWC_NOT_FOUND = Symbol.for('simple-web-component:not-found');
|
|
6
7
|
|
|
@@ -151,14 +152,30 @@ export const htmlArticleElement = (options?: { doc?: Document; attrs?: Record<st
|
|
|
151
152
|
export namespace SwcUtils {
|
|
152
153
|
|
|
153
154
|
|
|
155
|
+
export const getParentContainer = (e: Node) => {
|
|
156
|
+
return e.parentElement ?? e.getRootNode() as any;
|
|
157
|
+
}
|
|
158
|
+
|
|
154
159
|
export const parsePathPatternsSetAttributeString = (pathPattern: string[], path: string) => {
|
|
155
160
|
return JSON.stringify(SwcUtils.parsePathPatternsSet(pathPattern, path)).replace(/"/g, "'");
|
|
156
161
|
}
|
|
157
162
|
|
|
158
|
-
export const parsePathPatternsSet = (pathPattern: string[],
|
|
163
|
+
export const parsePathPatternsSet = (pathPattern: string[], urlAndRouter?: string | Router) => {
|
|
164
|
+
// if (!path) {
|
|
165
|
+
// return;
|
|
166
|
+
// }
|
|
167
|
+
urlAndRouter ??= '/'
|
|
168
|
+
const p = typeof urlAndRouter === 'string' ? urlAndRouter : urlAndRouter.value.url;
|
|
169
|
+
const searchParams = new URLSearchParams();
|
|
170
|
+
const qs = p.split('?')[1];
|
|
171
|
+
qs?.split('&').forEach(it => {
|
|
172
|
+
const [k, v] = it.split('=');
|
|
173
|
+
searchParams.set(k,v);
|
|
174
|
+
})
|
|
159
175
|
return {
|
|
160
|
-
path:
|
|
161
|
-
|
|
176
|
+
path: p,
|
|
177
|
+
searchParams,
|
|
178
|
+
pathData: SwcUtils.parsePathPatterns(pathPattern, p)
|
|
162
179
|
};
|
|
163
180
|
};
|
|
164
181
|
export const parsePathPatterns = (pathPattern: string[], path: string) => {
|
|
@@ -208,9 +225,9 @@ export namespace SwcUtils {
|
|
|
208
225
|
* Finds the nearest logical SWC host for an element.
|
|
209
226
|
* Checks __swc_host property first, then climbs the DOM tree.
|
|
210
227
|
*/
|
|
211
|
-
export const
|
|
212
|
-
|
|
213
|
-
|
|
228
|
+
export const findNearestSwcHostIncludingSelf = (el: HTMLElement | Node): HTMLElement | undefined => {
|
|
229
|
+
const el1 = el as any;
|
|
230
|
+
if (el1.__swc_host) return el1.__swc_host;
|
|
214
231
|
|
|
215
232
|
let current: any = el.parentElement || (el.getRootNode?.() as any)?.host;
|
|
216
233
|
const doc = el.ownerDocument;
|
|
@@ -226,32 +243,32 @@ export namespace SwcUtils {
|
|
|
226
243
|
/**
|
|
227
244
|
* Returns all SWC ancestors (excluding self) in [root, ..., parent] order.
|
|
228
245
|
*/
|
|
229
|
-
export const
|
|
246
|
+
export const findAllSwcHostsIncludingSelf = (el: HTMLElement | Node): HTMLElement[] => {
|
|
230
247
|
const hosts: HTMLElement[] = [];
|
|
231
|
-
let current =
|
|
248
|
+
let current = findNearestSwcHostIncludingSelf(el);
|
|
232
249
|
while (current) {
|
|
233
250
|
hosts.push(current);
|
|
234
251
|
// To find the next ancestor, we must start searching from the PARENT of the found host
|
|
235
|
-
current =
|
|
252
|
+
current = findNearestSwcHostIncludingSelf(current);
|
|
236
253
|
}
|
|
237
254
|
return hosts.reverse();
|
|
238
255
|
};
|
|
239
256
|
|
|
240
257
|
export const getHosts = (el: HTMLElement): HTMLElement[] => {
|
|
241
|
-
const ancestors =
|
|
258
|
+
const ancestors = findAllSwcHostsIncludingSelf(el);
|
|
242
259
|
if (getElementConfig(el)) return [...ancestors, el];
|
|
243
260
|
return ancestors;
|
|
244
261
|
};
|
|
245
262
|
|
|
246
263
|
export const getHost = (el: HTMLElement): HTMLElement | undefined => {
|
|
247
264
|
if (getElementConfig(el)) return el;
|
|
248
|
-
return
|
|
265
|
+
return findNearestSwcHostIncludingSelf(el);
|
|
249
266
|
};
|
|
250
267
|
|
|
251
268
|
export const getAppHosts = (el: HTMLElement): SwcAppInterface[] => {
|
|
252
269
|
// const hosts = getHosts(el);
|
|
253
270
|
// return hosts.filter(host => host.tagName.toLowerCase() === 'swc-app' || host.getAttribute('is')?.startsWith('swc-app-')) as SwcAppInterface[];
|
|
254
|
-
const hosts = SwcUtils.
|
|
271
|
+
const hosts = SwcUtils.findAllAppHostsIncludingSelfDirect(el);
|
|
255
272
|
return hosts;
|
|
256
273
|
};
|
|
257
274
|
|
|
@@ -262,22 +279,22 @@ export namespace SwcUtils {
|
|
|
262
279
|
};
|
|
263
280
|
|
|
264
281
|
/**
|
|
265
|
-
* Find
|
|
282
|
+
* Find the closest app host by traversing DOM tree directly, including the element itself.
|
|
266
283
|
* Only checks tagName and is attribute - no SWC host discovery.
|
|
267
284
|
* Useful for Safari polyfill compatibility where is="" elements upgrade in child-first order.
|
|
268
285
|
*/
|
|
269
|
-
export const
|
|
270
|
-
const appHosts =
|
|
286
|
+
export const findAppHostIncludingSelfDirect = (el: HTMLElement): SwcAppInterface | null => {
|
|
287
|
+
const appHosts = findAllAppHostsIncludingSelfDirect(el);
|
|
271
288
|
return appHosts.length > 0 ? appHosts[appHosts.length - 1] : null;
|
|
272
289
|
};
|
|
273
290
|
|
|
274
291
|
/**
|
|
275
|
-
* Find all
|
|
276
|
-
* Returns array of all
|
|
292
|
+
* Find all app hosts by traversing DOM tree directly, including the element itself.
|
|
293
|
+
* Returns array of all app hosts in [root, ..., closest-parent-or-self] order.
|
|
277
294
|
* Only checks tagName and is attribute - no SWC host discovery.
|
|
278
295
|
* Useful for Safari polyfill compatibility where is="" elements upgrade in child-first order.
|
|
279
296
|
*/
|
|
280
|
-
export const
|
|
297
|
+
export const findAllAppHostsIncludingSelfDirect = (el: HTMLElement): SwcAppInterface[] => {
|
|
281
298
|
const appHosts: SwcAppInterface[] = [];
|
|
282
299
|
|
|
283
300
|
const w = el.ownerDocument?.defaultView || ((typeof window !== 'undefined' ? window : undefined) as any);
|
|
@@ -315,11 +332,11 @@ export namespace SwcUtils {
|
|
|
315
332
|
}
|
|
316
333
|
}
|
|
317
334
|
}
|
|
318
|
-
return appHosts.reverse(); // [root, ..., closest-parent]
|
|
335
|
+
return appHosts.reverse(); // [root, ..., closest-parent-or-self]
|
|
319
336
|
};
|
|
320
337
|
|
|
321
338
|
export const getHostSet = (el: HTMLElement): HostSet => {
|
|
322
|
-
const ancestors =
|
|
339
|
+
const ancestors = findAllSwcHostsIncludingSelf(el); // [root, ..., parent]
|
|
323
340
|
|
|
324
341
|
const $host = ancestors.length > 0 ? ancestors[ancestors.length - 1] : null;
|
|
325
342
|
const $parentHost = ancestors.length > 1 ? ancestors[ancestors.length - 2] : null;
|
|
@@ -337,8 +354,7 @@ export namespace SwcUtils {
|
|
|
337
354
|
curr = curr.parentElement || (curr.getRootNode() as any).host;
|
|
338
355
|
}
|
|
339
356
|
|
|
340
|
-
const $appHosts = SwcUtils.
|
|
341
|
-
// console.log('apphosts00000000', $appHosts)
|
|
357
|
+
const $appHosts = SwcUtils.findAllAppHostsIncludingSelfDirect(el);
|
|
342
358
|
const $appHost = $appHosts.length > 0 ? ($appHosts[$appHosts.length - 1] === el ? ($appHosts.length > 1 ? $appHosts[$appHosts.length - 2] : null) : $appHosts[$appHosts.length - 1]) : null;
|
|
343
359
|
const $firstAppHost = $appHosts.length > 0 ? $appHosts[0] : null;
|
|
344
360
|
|
|
@@ -347,7 +363,8 @@ export namespace SwcUtils {
|
|
|
347
363
|
$parentHost,
|
|
348
364
|
$hosts,
|
|
349
365
|
$firstHost,
|
|
350
|
-
$lastHost: $
|
|
366
|
+
$lastHost: $host,
|
|
367
|
+
$templateHost: (el as any).__swc_template_host,
|
|
351
368
|
$appHost,
|
|
352
369
|
$appHosts,
|
|
353
370
|
$firstAppHost,
|
package/tsconfig.json
CHANGED
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
"declaration": true,
|
|
7
7
|
"declarationMap": true,
|
|
8
8
|
"stripInternal": true,
|
|
9
|
-
"target": "
|
|
9
|
+
"target": "es2022",
|
|
10
10
|
"noEmit": true,
|
|
11
|
-
"lib": ["dom", "dom.iterable", "esnext"],
|
|
11
|
+
"lib": ["dom", "dom.iterable", "es2024", "esnext"],
|
|
12
12
|
"experimentalDecorators": true,
|
|
13
13
|
"emitDecoratorMetadata": true,
|
|
14
14
|
"esModuleInterop": true,
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/decorators/changedAttributeHost.ts"],
|
|
4
|
-
"sourcesContent": ["import {ReflectUtils} from '@dooboostore/core';\n\nexport const ON_ATTRIBUTE_CHANGED_METADATA_KEY = Symbol.for('simple-web-component:on-attribute-changed');\n\nexport interface ChangedAttributeHostOptions {\n type?: typeof Number | typeof Boolean | typeof String;\n}\n\nexport interface ChangedAttributeHostMetadata {\n attributeName: string;\n propertyKey: string | symbol;\n options: ChangedAttributeHostOptions;\n}\n\nconst convertValue = (val: any, type: any): any => {\n if (val === null || val === undefined) return val;\n if (type === Number) return Number(val);\n if (type === Boolean) return val === 'false' || val === '0' ? false : true;\n return val;\n};\n\n/**\n * @changedAttributeHost decorator - fires when any attribute on :host changes\n * Usage: @changedAttributeHost('data-product-id')\n * @changedAttributeHost('count', { type: Number })\n */\nexport function changedAttributeHost(attributeName?: string, options: ChangedAttributeHostOptions = {}): MethodDecorator {\n return (target: Object, propertyKey: string | symbol) => {\n const constructor = target.constructor;\n let metaList = ReflectUtils.getOwnMetadata(ON_ATTRIBUTE_CHANGED_METADATA_KEY, constructor) as ChangedAttributeHostMetadata[];\n if (!metaList) {\n metaList = [];\n ReflectUtils.defineMetadata(ON_ATTRIBUTE_CHANGED_METADATA_KEY, metaList, constructor);\n }\n\n const name = attributeName || String(propertyKey);\n metaList.push({\n attributeName: name,\n propertyKey,\n options\n });\n };\n}\n\nexport const getChangedAttributeMetadata = (target: any): ChangedAttributeHostMetadata[] | undefined => {\n const constructor = target instanceof Function ? target : target.constructor;\n return ReflectUtils.getMetadata(ON_ATTRIBUTE_CHANGED_METADATA_KEY, constructor);\n};\n\nexport const findAllAttributeChangedMetadata = (target: any): Map<string, ChangedAttributeHostMetadata[]> => {\n const constructor = target instanceof Function ? target : target.constructor;\n const metaList = ReflectUtils.findAllMetadata<ChangedAttributeHostMetadata[]>(ON_ATTRIBUTE_CHANGED_METADATA_KEY, constructor) || [];\n \n const result = new Map<string, ChangedAttributeHostMetadata[]>();\n metaList.forEach(meta => {\n meta.forEach(item => {\n if (!result.has(item.attributeName)) {\n result.set(item.attributeName, []);\n }\n result.get(item.attributeName)!.push(item);\n });\n });\n return result;\n};\n\nexport const convertAttributeValue = (val: any, type?: typeof Number | typeof Boolean | typeof String): any => {\n return convertValue(val, type);\n};\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA2B;AAEpB,MAAM,oCAAoC,OAAO,IAAI,2CAA2C;AAYvG,MAAM,eAAe,CAAC,KAAU,SAAmB;AACjD,MAAI,QAAQ,QAAQ,QAAQ,OAAW,QAAO;AAC9C,MAAI,SAAS,OAAQ,QAAO,OAAO,GAAG;AACtC,MAAI,SAAS,QAAS,QAAO,QAAQ,WAAW,QAAQ,MAAM,QAAQ;AACtE,SAAO;AACT;AAOO,SAAS,qBAAqB,eAAwB,UAAuC,CAAC,GAAoB;AACvH,SAAO,CAAC,QAAgB,gBAAiC;AACvD,UAAM,cAAc,OAAO;AAC3B,QAAI,WAAW,yBAAa,eAAe,mCAAmC,WAAW;AACzF,QAAI,CAAC,UAAU;AACb,iBAAW,CAAC;AACZ,+BAAa,eAAe,mCAAmC,UAAU,WAAW;AAAA,IACtF;AAEA,UAAM,OAAO,iBAAiB,OAAO,WAAW;AAChD,aAAS,KAAK;AAAA,MACZ,eAAe;AAAA,MACf;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH;AACF;AAEO,MAAM,8BAA8B,CAAC,WAA4D;AACtG,QAAM,cAAc,kBAAkB,WAAW,SAAS,OAAO;AACjE,SAAO,yBAAa,YAAY,mCAAmC,WAAW;AAChF;AAEO,MAAM,kCAAkC,CAAC,WAA6D;AAC3G,QAAM,cAAc,kBAAkB,WAAW,SAAS,OAAO;AACjE,QAAM,WAAW,yBAAa,gBAAgD,mCAAmC,WAAW,KAAK,CAAC;AAElI,QAAM,SAAS,oBAAI,IAA4C;AAC/D,WAAS,QAAQ,UAAQ;AACvB,SAAK,QAAQ,UAAQ;AACnB,UAAI,CAAC,OAAO,IAAI,KAAK,aAAa,GAAG;AACnC,eAAO,IAAI,KAAK,eAAe,CAAC,CAAC;AAAA,MACnC;AACA,aAAO,IAAI,KAAK,aAAa,EAAG,KAAK,IAAI;AAAA,IAC3C,CAAC;AAAA,EACH,CAAC;AACD,SAAO;AACT;AAEO,MAAM,wBAAwB,CAAC,KAAU,SAA+D;AAC7G,SAAO,aAAa,KAAK,IAAI;AAC/B;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/decorators/changedAttributeHost.ts"],
|
|
4
|
-
"sourcesContent": ["import {ReflectUtils} from '@dooboostore/core';\n\nexport const ON_ATTRIBUTE_CHANGED_METADATA_KEY = Symbol.for('simple-web-component:on-attribute-changed');\n\nexport interface ChangedAttributeHostOptions {\n type?: typeof Number | typeof Boolean | typeof String;\n}\n\nexport interface ChangedAttributeHostMetadata {\n attributeName: string;\n propertyKey: string | symbol;\n options: ChangedAttributeHostOptions;\n}\n\nconst convertValue = (val: any, type: any): any => {\n if (val === null || val === undefined) return val;\n if (type === Number) return Number(val);\n if (type === Boolean) return val === 'false' || val === '0' ? false : true;\n return val;\n};\n\n/**\n * @changedAttributeHost decorator - fires when any attribute on :host changes\n * Usage: @changedAttributeHost('data-product-id')\n * @changedAttributeHost('count', { type: Number })\n */\nexport function changedAttributeHost(attributeName?: string, options: ChangedAttributeHostOptions = {}): MethodDecorator {\n return (target: Object, propertyKey: string | symbol) => {\n const constructor = target.constructor;\n let metaList = ReflectUtils.getOwnMetadata(ON_ATTRIBUTE_CHANGED_METADATA_KEY, constructor) as ChangedAttributeHostMetadata[];\n if (!metaList) {\n metaList = [];\n ReflectUtils.defineMetadata(ON_ATTRIBUTE_CHANGED_METADATA_KEY, metaList, constructor);\n }\n\n const name = attributeName || String(propertyKey);\n metaList.push({\n attributeName: name,\n propertyKey,\n options\n });\n };\n}\n\nexport const getChangedAttributeMetadata = (target: any): ChangedAttributeHostMetadata[] | undefined => {\n const constructor = target instanceof Function ? target : target.constructor;\n return ReflectUtils.getMetadata(ON_ATTRIBUTE_CHANGED_METADATA_KEY, constructor);\n};\n\nexport const findAllAttributeChangedMetadata = (target: any): Map<string, ChangedAttributeHostMetadata[]> => {\n const constructor = target instanceof Function ? target : target.constructor;\n const metaList = ReflectUtils.findAllMetadata<ChangedAttributeHostMetadata[]>(ON_ATTRIBUTE_CHANGED_METADATA_KEY, constructor) || [];\n \n const result = new Map<string, ChangedAttributeHostMetadata[]>();\n metaList.forEach(meta => {\n meta.forEach(item => {\n if (!result.has(item.attributeName)) {\n result.set(item.attributeName, []);\n }\n result.get(item.attributeName)!.push(item);\n });\n });\n return result;\n};\n\nexport const convertAttributeValue = (val: any, type?: typeof Number | typeof Boolean | typeof String): any => {\n return convertValue(val, type);\n};\n"],
|
|
5
|
-
"mappings": "AAAA,SAAQ,oBAAmB;AAEpB,MAAM,oCAAoC,OAAO,IAAI,2CAA2C;AAYvG,MAAM,eAAe,CAAC,KAAU,SAAmB;AACjD,MAAI,QAAQ,QAAQ,QAAQ,OAAW,QAAO;AAC9C,MAAI,SAAS,OAAQ,QAAO,OAAO,GAAG;AACtC,MAAI,SAAS,QAAS,QAAO,QAAQ,WAAW,QAAQ,MAAM,QAAQ;AACtE,SAAO;AACT;AAOO,SAAS,qBAAqB,eAAwB,UAAuC,CAAC,GAAoB;AACvH,SAAO,CAAC,QAAgB,gBAAiC;AACvD,UAAM,cAAc,OAAO;AAC3B,QAAI,WAAW,aAAa,eAAe,mCAAmC,WAAW;AACzF,QAAI,CAAC,UAAU;AACb,iBAAW,CAAC;AACZ,mBAAa,eAAe,mCAAmC,UAAU,WAAW;AAAA,IACtF;AAEA,UAAM,OAAO,iBAAiB,OAAO,WAAW;AAChD,aAAS,KAAK;AAAA,MACZ,eAAe;AAAA,MACf;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH;AACF;AAEO,MAAM,8BAA8B,CAAC,WAA4D;AACtG,QAAM,cAAc,kBAAkB,WAAW,SAAS,OAAO;AACjE,SAAO,aAAa,YAAY,mCAAmC,WAAW;AAChF;AAEO,MAAM,kCAAkC,CAAC,WAA6D;AAC3G,QAAM,cAAc,kBAAkB,WAAW,SAAS,OAAO;AACjE,QAAM,WAAW,aAAa,gBAAgD,mCAAmC,WAAW,KAAK,CAAC;AAElI,QAAM,SAAS,oBAAI,IAA4C;AAC/D,WAAS,QAAQ,UAAQ;AACvB,SAAK,QAAQ,UAAQ;AACnB,UAAI,CAAC,OAAO,IAAI,KAAK,aAAa,GAAG;AACnC,eAAO,IAAI,KAAK,eAAe,CAAC,CAAC;AAAA,MACnC;AACA,aAAO,IAAI,KAAK,aAAa,EAAG,KAAK,IAAI;AAAA,IAC3C,CAAC;AAAA,EACH,CAAC;AACD,SAAO;AACT;AAEO,MAAM,wBAAwB,CAAC,KAAU,SAA+D;AAC7G,SAAO,aAAa,KAAK,IAAI;AAC/B;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export declare const ON_ATTRIBUTE_CHANGED_METADATA_KEY: unique symbol;
|
|
2
|
-
export interface ChangedAttributeHostOptions {
|
|
3
|
-
type?: typeof Number | typeof Boolean | typeof String;
|
|
4
|
-
}
|
|
5
|
-
export interface ChangedAttributeHostMetadata {
|
|
6
|
-
attributeName: string;
|
|
7
|
-
propertyKey: string | symbol;
|
|
8
|
-
options: ChangedAttributeHostOptions;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* @changedAttributeHost decorator - fires when any attribute on :host changes
|
|
12
|
-
* Usage: @changedAttributeHost('data-product-id')
|
|
13
|
-
* @changedAttributeHost('count', { type: Number })
|
|
14
|
-
*/
|
|
15
|
-
export declare function changedAttributeHost(attributeName?: string, options?: ChangedAttributeHostOptions): MethodDecorator;
|
|
16
|
-
export declare const getChangedAttributeMetadata: (target: any) => ChangedAttributeHostMetadata[] | undefined;
|
|
17
|
-
export declare const findAllAttributeChangedMetadata: (target: any) => Map<string, ChangedAttributeHostMetadata[]>;
|
|
18
|
-
export declare const convertAttributeValue: (val: any, type?: typeof Number | typeof Boolean | typeof String) => any;
|
|
19
|
-
//# sourceMappingURL=changedAttributeHost.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"changedAttributeHost.d.ts","sourceRoot":"","sources":["../../../src/decorators/changedAttributeHost.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,iCAAiC,eAA0D,CAAC;AAEzG,MAAM,WAAW,2BAA2B;IAC1C,IAAI,CAAC,EAAE,OAAO,MAAM,GAAG,OAAO,OAAO,GAAG,OAAO,MAAM,CAAC;CACvD;AAED,MAAM,WAAW,4BAA4B;IAC3C,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,GAAG,MAAM,CAAC;IAC7B,OAAO,EAAE,2BAA2B,CAAC;CACtC;AASD;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,OAAO,GAAE,2BAAgC,GAAG,eAAe,CAgBvH;AAED,eAAO,MAAM,2BAA2B,GAAI,QAAQ,GAAG,KAAG,4BAA4B,EAAE,GAAG,SAG1F,CAAC;AAEF,eAAO,MAAM,+BAA+B,GAAI,QAAQ,GAAG,KAAG,GAAG,CAAC,MAAM,EAAE,4BAA4B,EAAE,CAcvG,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAAI,KAAK,GAAG,EAAE,OAAO,OAAO,MAAM,GAAG,OAAO,OAAO,GAAG,OAAO,MAAM,KAAG,GAEvG,CAAC"}
|