@dooboostore/simple-web-component 1.0.39 → 1.0.40
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/LICENSE.md +7 -0
- package/README.md +65 -46
- package/dist/cjs/SwcAppEngine.js.map +2 -2
- package/dist/cjs/decorators/applyAttribute.js +194 -111
- package/dist/cjs/decorators/applyAttribute.js.map +2 -2
- package/dist/cjs/decorators/applyNode.js +58 -43
- package/dist/cjs/decorators/applyNode.js.map +2 -2
- package/dist/cjs/decorators/applyProperty.js +213 -0
- package/dist/cjs/decorators/applyProperty.js.map +7 -0
- package/dist/cjs/decorators/applySlot.js +32 -26
- package/dist/cjs/decorators/applySlot.js.map +2 -2
- package/dist/cjs/decorators/changedAttributeThis.js.map +1 -1
- package/dist/cjs/decorators/elementDefine.js +17 -30
- package/dist/cjs/decorators/elementDefine.js.map +2 -2
- package/dist/cjs/decorators/index.js +2 -2
- package/dist/cjs/decorators/index.js.map +2 -2
- package/dist/cjs/decorators/lifecycles.js +4 -4
- package/dist/cjs/decorators/lifecycles.js.map +2 -2
- package/dist/cjs/elements/SwcApp.js.map +2 -2
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/esm/SwcAppEngine.js.map +2 -2
- package/dist/esm/decorators/applyAttribute.js +196 -113
- package/dist/esm/decorators/applyAttribute.js.map +2 -2
- package/dist/esm/decorators/applyNode.js +58 -43
- package/dist/esm/decorators/applyNode.js.map +2 -2
- package/dist/esm/decorators/applyProperty.js +194 -0
- package/dist/esm/decorators/applyProperty.js.map +7 -0
- package/dist/esm/decorators/applySlot.js +32 -26
- package/dist/esm/decorators/applySlot.js.map +2 -2
- package/dist/esm/decorators/changedAttributeThis.js.map +1 -1
- package/dist/esm/decorators/elementDefine.js +17 -30
- package/dist/esm/decorators/elementDefine.js.map +2 -2
- package/dist/esm/decorators/index.js +2 -2
- package/dist/esm/decorators/index.js.map +1 -1
- package/dist/esm/decorators/lifecycles.js +4 -4
- package/dist/esm/decorators/lifecycles.js.map +2 -2
- package/dist/esm/elements/SwcApp.js.map +2 -2
- package/dist/esm/types/index.js.map +1 -1
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +421 -394
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
- package/dist/types/SwcAppEngine.d.ts.map +1 -1
- package/dist/types/decorators/applyAttribute.d.ts +56 -15
- package/dist/types/decorators/applyAttribute.d.ts.map +1 -1
- package/dist/types/decorators/applyNode.d.ts +28 -24
- package/dist/types/decorators/applyNode.d.ts.map +1 -1
- package/dist/types/decorators/applyProperty.d.ts +61 -0
- package/dist/types/decorators/applyProperty.d.ts.map +1 -0
- package/dist/types/decorators/applySlot.d.ts +10 -10
- package/dist/types/decorators/applySlot.d.ts.map +1 -1
- package/dist/types/decorators/elementDefine.d.ts.map +1 -1
- package/dist/types/decorators/index.d.ts +2 -2
- package/dist/types/decorators/index.d.ts.map +1 -1
- package/dist/types/decorators/lifecycles.d.ts +4 -4
- package/dist/types/decorators/lifecycles.d.ts.map +1 -1
- package/dist/types/elements/SwcApp.d.ts.map +1 -1
- package/dist/types/types/index.d.ts +1 -6
- package/dist/types/types/index.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +421 -394
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +3 -3
- package/src/SwcAppEngine.ts +1 -0
- package/src/decorators/applyAttribute.ts +311 -126
- package/src/decorators/applyNode.ts +68 -57
- package/src/decorators/applyProperty.ts +302 -0
- package/src/decorators/applySlot.ts +25 -18
- package/src/decorators/changedAttributeThis.ts +1 -1
- package/src/decorators/elementDefine.ts +41 -30
- package/src/decorators/index.ts +2 -3
- package/src/decorators/lifecycles.ts +6 -6
- package/src/elements/SwcApp.ts +0 -1
- package/src/types/index.ts +7 -7
- package/dist/cjs/decorators/attribute.js +0 -187
- package/dist/cjs/decorators/attribute.js.map +0 -7
- package/dist/cjs/decorators/setProperty.js +0 -109
- package/dist/cjs/decorators/setProperty.js.map +0 -7
- package/dist/esm/decorators/attribute.js +0 -168
- package/dist/esm/decorators/attribute.js.map +0 -7
- package/dist/esm/decorators/setProperty.js +0 -90
- package/dist/esm/decorators/setProperty.js.map +0 -7
- package/dist/types/decorators/attribute.d.ts +0 -31
- package/dist/types/decorators/attribute.d.ts.map +0 -1
- package/dist/types/decorators/setProperty.d.ts +0 -17
- package/dist/types/decorators/setProperty.d.ts.map +0 -1
- package/src/decorators/attribute.ts +0 -223
- package/src/decorators/setProperty.ts +0 -112
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import { ReflectUtils } from '@dooboostore/core';
|
|
2
|
-
import { ensureInit } from './elementDefine';
|
|
3
|
-
import { SwcUtils } from '../utils/Utils';
|
|
4
|
-
import { SpecialSelector, SwcQueryOptions, HelperHostSet } from '../types';
|
|
5
|
-
|
|
6
|
-
export interface PropertySetOptions extends SwcQueryOptions {
|
|
7
|
-
name?: string;
|
|
8
|
-
filter?: (target: HTMLElement, value: any, meta: {currentThis: any, helper: HelperHostSet}) => boolean;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface PropertySetMetadata {
|
|
12
|
-
propertyKey: string | symbol;
|
|
13
|
-
selector: string;
|
|
14
|
-
options: PropertySetOptions;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const PROPERTY_SET_METADATA_KEY = Symbol.for('simple-web-component:property-set');
|
|
18
|
-
|
|
19
|
-
export const setProperty = (selector: string, propertyNameOrOptions?: string | PropertySetOptions, options: PropertySetOptions = {}): MethodDecorator => {
|
|
20
|
-
return (target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {
|
|
21
|
-
const constructor = target.constructor;
|
|
22
|
-
let metaList = ReflectUtils.getOwnMetadata(PROPERTY_SET_METADATA_KEY, constructor) as Map<string | symbol, PropertySetMetadata>;
|
|
23
|
-
if (!metaList) {
|
|
24
|
-
metaList = new Map<string | symbol, PropertySetMetadata>();
|
|
25
|
-
ReflectUtils.defineMetadata(PROPERTY_SET_METADATA_KEY, metaList, constructor);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
let propertyName = typeof propertyNameOrOptions === 'string' ? propertyNameOrOptions : undefined;
|
|
29
|
-
let finalOptions = options;
|
|
30
|
-
|
|
31
|
-
if (typeof propertyNameOrOptions === 'object' && propertyNameOrOptions !== null) {
|
|
32
|
-
finalOptions = propertyNameOrOptions as PropertySetOptions;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
metaList.set(propertyKey, {
|
|
36
|
-
propertyKey,
|
|
37
|
-
selector,
|
|
38
|
-
options: { ...finalOptions, name: propertyName }
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
const original = descriptor.value;
|
|
42
|
-
descriptor.value = function (...args: any[]) {
|
|
43
|
-
ensureInit(this);
|
|
44
|
-
const res = (original as any).apply(this, args);
|
|
45
|
-
|
|
46
|
-
const handleResult = (resolvedValue: any) => {
|
|
47
|
-
if (resolvedValue !== undefined) {
|
|
48
|
-
const win = (this as any).ownerDocument?.defaultView || window;
|
|
49
|
-
const host = this as unknown as HTMLElement;
|
|
50
|
-
const hostSet = { ...SwcUtils.getHelperAndHostSet(win, host), $this: this };
|
|
51
|
-
const r = finalOptions.root || 'auto';
|
|
52
|
-
const targetEls: HTMLElement[] = [];
|
|
53
|
-
|
|
54
|
-
const applyRoot = (t: any) => {
|
|
55
|
-
if (!t || !(t instanceof win.HTMLElement)) return;
|
|
56
|
-
targetEls.push(t);
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
if (selector === '$this' || !selector) applyRoot(host);
|
|
60
|
-
else if (selector === '$host') applyRoot(hostSet.$host);
|
|
61
|
-
else if (selector === '$parentHost') applyRoot(hostSet.$parentHost);
|
|
62
|
-
else if (selector === '$appHost') applyRoot(hostSet.$appHost);
|
|
63
|
-
else if (selector === '$firstHost') applyRoot(hostSet.$firstHost);
|
|
64
|
-
else if (selector === '$lastHost') applyRoot(hostSet.$lastHost);
|
|
65
|
-
else if (selector === '$firstAppHost') applyRoot(hostSet.$firstAppHost);
|
|
66
|
-
else if (selector === '$lastAppHost') applyRoot(hostSet.$lastAppHost);
|
|
67
|
-
else if (selector === '$hosts') hostSet.$hosts.forEach(applyRoot);
|
|
68
|
-
else if (selector === '$appHosts') hostSet.$appHosts.forEach(applyRoot);
|
|
69
|
-
else {
|
|
70
|
-
const targetRoot = r === 'auto' ? (host.shadowRoot || host) : (r === 'shadow' ? host.shadowRoot : host);
|
|
71
|
-
if (targetRoot) {
|
|
72
|
-
const found = targetRoot.querySelectorAll(selector);
|
|
73
|
-
if (found) targetEls.push(...(Array.from(found) as HTMLElement[]));
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
targetEls.forEach(targetEl => {
|
|
78
|
-
if (finalOptions.filter && !finalOptions.filter(targetEl, resolvedValue, {currentThis: this, helper: hostSet})) {
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
const resolvedRes = typeof resolvedValue === 'function' ? (resolvedValue as any)(targetEl, hostSet) : resolvedValue;
|
|
82
|
-
|
|
83
|
-
if (propertyName) {
|
|
84
|
-
// Case: @setProperty(selector, 'propertyName')
|
|
85
|
-
(targetEl as any)[propertyName] = resolvedRes;
|
|
86
|
-
} else if (typeof resolvedRes === 'object' && resolvedRes !== null && !Array.isArray(resolvedRes)) {
|
|
87
|
-
// Case: @setProperty(selector) with Object return - assign multiple properties
|
|
88
|
-
Object.entries(resolvedRes as any).forEach(([prop, val]) => {
|
|
89
|
-
const finalVal = typeof val === 'function' ? val(targetEl, hostSet) : val;
|
|
90
|
-
(targetEl as any)[prop] = finalVal;
|
|
91
|
-
});
|
|
92
|
-
} else {
|
|
93
|
-
// Simple value - assign to 'value' property by default
|
|
94
|
-
(targetEl as any).value = resolvedRes;
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
return resolvedValue;
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
if (res instanceof Promise) {
|
|
102
|
-
return res.then(handleResult);
|
|
103
|
-
} else {
|
|
104
|
-
return handleResult(res);
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
};
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
export const setPropertyThis = (propertyNameOrOptions?: string | PropertySetOptions, options: PropertySetOptions = {}): MethodDecorator => {
|
|
111
|
-
return setProperty('$this', propertyNameOrOptions, options);
|
|
112
|
-
};
|