@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
|
@@ -3,8 +3,7 @@ import {getAddEventListenerMetadata} from './addEventListener';
|
|
|
3
3
|
import {findAllLifecycleMetadata, findAllOnConnectedAfterMetadata, findAllOnConnectedBeforeMetadata, findAllOnConnectedMetadata, ON_AFTER_ADOPTED_METADATA_KEY, ON_AFTER_DISCONNECTED_METADATA_KEY, ON_BEFORE_ADOPTED_METADATA_KEY, ON_BEFORE_DISCONNECTED_METADATA_KEY, ON_CONNECTED_COMPLETED_METADATA_KEY, ON_INITIALIZE_METADATA_KEY} from './lifecycles';
|
|
4
4
|
import {getEmitCustomEventMetadataList} from './emitCustomEvent';
|
|
5
5
|
import {convertAttributeValue, findAllAttributeChangedMetadata} from './changedAttributeThis';
|
|
6
|
-
import {findAllAttributeApplyMetadata} from './applyAttribute';
|
|
7
|
-
import {findAllAttributeMetadata, getAttributeValue} from './attribute';
|
|
6
|
+
import {findAllAttributeApplyMetadata, findAllAttributeMetadata, getAttributeValue} from './applyAttribute';
|
|
8
7
|
import {getQueryMetadata} from './query';
|
|
9
8
|
import {getQueryAllMetadata} from './queryAll';
|
|
10
9
|
import {SwcUtils} from '../utils/Utils';
|
|
@@ -15,6 +14,7 @@ import {ConvertUtils, ElementApply, NodeSlot} from '@dooboostore/core-web';
|
|
|
15
14
|
import {isSSR} from "../elements/SwcAppMixin";
|
|
16
15
|
import {findAllApplySlotMetadata} from "./applySlot";
|
|
17
16
|
import {findAllStateMetadata} from "./state";
|
|
17
|
+
import {findAllPropertyMetadata} from "./applyProperty";
|
|
18
18
|
|
|
19
19
|
// --- Core Interfaces & Types ---
|
|
20
20
|
|
|
@@ -69,16 +69,18 @@ export const ensureInit = (inst: any) => { // HTMLElement
|
|
|
69
69
|
// ║ 4. own property를 삭제하면 JavaScript가 prototype의 getter를 찾게 됨 ║
|
|
70
70
|
// ║ → getter 호출됨 → DOM 속성 값 동기화됨 ║
|
|
71
71
|
// ╚════════════════════════════════════════════════════════════════════════════════╝
|
|
72
|
+
// 함수는 decorator에서 값자체를 descriptor.value = function (...args: any[]) {...
|
|
72
73
|
|
|
73
74
|
// @attribute 필드의 own property 삭제 → getter/setter 작동
|
|
74
|
-
const attributeList = findAllAttributeMetadata(target);
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
75
|
+
// const attributeList = findAllAttributeMetadata(target);
|
|
76
|
+
const attributeAllList = findAllAttributeMetadata(target).filter(it => it.type === 'property');
|
|
77
|
+
if (attributeAllList) {
|
|
78
|
+
attributeAllList.forEach(meta => {
|
|
79
|
+
// const initUserData = (inst as any)[meta.propertyKey];
|
|
80
|
+
delete (inst as any)[meta.propertyKey];
|
|
81
|
+
// (inst as any)[meta.propertyKey] = initUserData;
|
|
82
|
+
});
|
|
83
|
+
}
|
|
82
84
|
|
|
83
85
|
// @query 필드의 own property 삭제 → getter 작동
|
|
84
86
|
const queryList = getQueryMetadata(target);
|
|
@@ -101,6 +103,15 @@ export const ensureInit = (inst: any) => { // HTMLElement
|
|
|
101
103
|
// delete (inst as any)[meta.propertyKey];
|
|
102
104
|
// });
|
|
103
105
|
// }
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
const propertyAllList = findAllPropertyMetadata(target).filter(it => it.type === 'property');
|
|
109
|
+
if (propertyAllList) {
|
|
110
|
+
propertyAllList.forEach(meta => {
|
|
111
|
+
delete (inst as any)[meta.propertyKey];
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
104
115
|
const stateAllList = findAllStateMetadata(target);
|
|
105
116
|
if (stateAllList) {
|
|
106
117
|
stateAllList.forEach(meta => {
|
|
@@ -170,24 +181,24 @@ const setupPrototype = (proto: any, win: Window) => {
|
|
|
170
181
|
proto.__swc_proto_setup = true;
|
|
171
182
|
|
|
172
183
|
|
|
173
|
-
proto.createSlotString = function (id: string) {
|
|
174
|
-
|
|
175
|
-
}
|
|
176
|
-
proto.createEaHtml = function (id: string, script: string) {
|
|
177
|
-
|
|
178
|
-
}
|
|
179
|
-
proto.createEaText = function (id: string, script: string) {
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
proto.createEaAttribute = function (id: string, name: string, script: string) {
|
|
183
|
-
|
|
184
|
-
}
|
|
185
|
-
proto.createEaEvent = function (id: string, name: string, script: string) {
|
|
186
|
-
|
|
187
|
-
}
|
|
188
|
-
proto.createEaProperty = function (id: string, name: string, script: string) {
|
|
189
|
-
|
|
190
|
-
}
|
|
184
|
+
// proto.createSlotString = function (id: string) {
|
|
185
|
+
// return NodeSlot.slot(`${this._swcId}-${id}`);
|
|
186
|
+
// }
|
|
187
|
+
// proto.createEaHtml = function (id: string, script: string) {
|
|
188
|
+
// return ElementApply.html(id, script);
|
|
189
|
+
// }
|
|
190
|
+
// proto.createEaText = function (id: string, script: string) {
|
|
191
|
+
// return ElementApply.text(id, script);
|
|
192
|
+
// }
|
|
193
|
+
// proto.createEaAttribute = function (id: string, name: string, script: string) {
|
|
194
|
+
// return ElementApply.attribute(id, name, script);
|
|
195
|
+
// }
|
|
196
|
+
// proto.createEaEvent = function (id: string, name: string, script: string) {
|
|
197
|
+
// return ElementApply.event(id, name, script);
|
|
198
|
+
// }
|
|
199
|
+
// proto.createEaProperty = function (id: string, name: string, script: string) {
|
|
200
|
+
// return ElementApply.property(id, name, script);
|
|
201
|
+
// }
|
|
191
202
|
|
|
192
203
|
// swc-id-asdasdasdasd-click=" :value="" {: value fsdfsdafsad :} {html: aaa :} {text: asdas :}
|
|
193
204
|
|
|
@@ -339,9 +350,9 @@ export const elementDefine =
|
|
|
339
350
|
const swcOnEvents = DOM_EVENT_NAMES.map(e => `swc-on-${e}`);
|
|
340
351
|
|
|
341
352
|
const attributeApplyNames = Array.from(applyAttributeMap.values())
|
|
342
|
-
.map(it => it.
|
|
353
|
+
.map(it => it.targetAttributeName)
|
|
343
354
|
.filter(Boolean) as string[];
|
|
344
|
-
const hostAttributes = attributeList.filter(it => it.selector === '$this').map(it => it.
|
|
355
|
+
const hostAttributes = attributeList.filter(it => it.selector === '$this').map(it => it.propertyKey || String(it.propertyKey));
|
|
345
356
|
// Get original static observedAttributes before they're overwritten by Object.defineProperty
|
|
346
357
|
const originalStaticObservedAttributes = (constructor.observedAttributes ?? []) as string[];
|
|
347
358
|
const mergedObservedAttributes = [...new Set([...(metadata.observedAttributes ?? []), ...originalStaticObservedAttributes, ...attrChangeMap.keys(), ...attributeApplyNames, ...hostAttributes, ...emitHostCustomEventList.map(it => (it.options as any).attributeName).filter(Boolean), ...swcLifecycleAttributes, ...swcOnEvents])];
|
package/src/decorators/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from './addEventListener';
|
|
2
|
-
export * from './
|
|
2
|
+
export * from './applyAttribute';
|
|
3
3
|
export * from './elementDefine';
|
|
4
4
|
export * from './changedAttributeThis';
|
|
5
5
|
export * from './emitCustomEvent';
|
|
@@ -10,10 +10,9 @@ export * from './queryAll';
|
|
|
10
10
|
export * from './applyClass';
|
|
11
11
|
export * from './applyStyle';
|
|
12
12
|
export * from './applyAttribute';
|
|
13
|
-
export * from './
|
|
13
|
+
export * from './applyProperty';
|
|
14
14
|
export * from './subscribeSwcAppRouteChangeWhileConnected';
|
|
15
15
|
export * from './subscribeSwcAppMessageWhileConnected';
|
|
16
16
|
export * from './publishSwcAppMessage';
|
|
17
17
|
export * from './applySlot';
|
|
18
18
|
export * from './state';
|
|
19
|
-
|
|
@@ -122,9 +122,9 @@ const decorator = (options: InnerHtmlOptions, target: Object, propertyKey: strin
|
|
|
122
122
|
list.push({ propertyKey, options });
|
|
123
123
|
};
|
|
124
124
|
|
|
125
|
-
export function
|
|
126
|
-
export function
|
|
127
|
-
export function
|
|
125
|
+
export function onConnectedShadow(options: Omit<InnerHtmlOptions, 'useShadow'>): MethodDecorator; // 파라미터있음
|
|
126
|
+
export function onConnectedShadow(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void; // 파라미터없음
|
|
127
|
+
export function onConnectedShadow(optionOrTarget: Omit<InnerHtmlOptions, 'useShadow'> | Object, propertyKey?: string | symbol, arg3?: PropertyDescriptor): MethodDecorator | void {
|
|
128
128
|
if (propertyKey) { // no parameter option @decorator
|
|
129
129
|
return decorator({useShadow: true}, optionOrTarget!, propertyKey);
|
|
130
130
|
}
|
|
@@ -134,9 +134,9 @@ export function onConnectedShadowDom(optionOrTarget: Omit<InnerHtmlOptions, 'use
|
|
|
134
134
|
};
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
-
export function
|
|
138
|
-
export function
|
|
139
|
-
export function
|
|
137
|
+
export function onConnectedLight(options: Omit<InnerHtmlOptions, 'useShadow'>): MethodDecorator; // 파라미터있음
|
|
138
|
+
export function onConnectedLight(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void; // 파라미터없음
|
|
139
|
+
export function onConnectedLight(optionOrTarget: Omit<InnerHtmlOptions, 'useShadow'> | Object, propertyKey?: string | symbol, arg3?: PropertyDescriptor): MethodDecorator | void {
|
|
140
140
|
if (propertyKey) { // no parameter option @decorator
|
|
141
141
|
return decorator({useShadow: false}, optionOrTarget!, propertyKey);
|
|
142
142
|
}
|
package/src/elements/SwcApp.ts
CHANGED
package/src/types/index.ts
CHANGED
|
@@ -64,11 +64,11 @@ export interface SwcAppInterface extends HTMLElement {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
export interface SwcElement {
|
|
67
|
-
|
|
68
|
-
createSlotString(id: string): string
|
|
69
|
-
createEaHtml(id: string, script: string): string
|
|
70
|
-
createEaText(id: string, script: string): string
|
|
71
|
-
createEaAttribute(id: string, attributeName: string): string
|
|
72
|
-
createEaEvent(id: string, eventName: string): string
|
|
73
|
-
createEaProperty(id: string, propertyName: string): string
|
|
67
|
+
_swcId: string;
|
|
68
|
+
// createSlotString(id: string): string
|
|
69
|
+
// createEaHtml(id: string, script: string): string
|
|
70
|
+
// createEaText(id: string, script: string): string
|
|
71
|
+
// createEaAttribute(id: string, attributeName: string): string
|
|
72
|
+
// createEaEvent(id: string, eventName: string): string
|
|
73
|
+
// createEaProperty(id: string, propertyName: string): string
|
|
74
74
|
}
|
|
@@ -1,187 +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 attribute_exports = {};
|
|
19
|
-
__export(attribute_exports, {
|
|
20
|
-
ATTRIBUTE_FIELD_METADATA_KEY: () => ATTRIBUTE_FIELD_METADATA_KEY,
|
|
21
|
-
attribute: () => attribute,
|
|
22
|
-
attributeThis: () => attributeThis,
|
|
23
|
-
convertValue: () => convertValue,
|
|
24
|
-
findAllAttributeMetadata: () => findAllAttributeMetadata,
|
|
25
|
-
getAttributeValue: () => getAttributeValue,
|
|
26
|
-
resolveTargetEls: () => resolveTargetEls
|
|
27
|
-
});
|
|
28
|
-
module.exports = __toCommonJS(attribute_exports);
|
|
29
|
-
var import_core = require("@dooboostore/core");
|
|
30
|
-
var import_elementDefine = require("./elementDefine");
|
|
31
|
-
var import_Utils = require("../utils/Utils");
|
|
32
|
-
var import_core_web = require("@dooboostore/core-web");
|
|
33
|
-
const ATTRIBUTE_FIELD_METADATA_KEY = Symbol.for("simple-web-component:attribute-field");
|
|
34
|
-
const convertValue = (val, type) => {
|
|
35
|
-
if (val === null || val === void 0) return val;
|
|
36
|
-
if (type === Number) return Number(val);
|
|
37
|
-
if (type === Boolean) return val === "false" || val === "0" ? false : true;
|
|
38
|
-
return val;
|
|
39
|
-
};
|
|
40
|
-
const getAttributeValue = (inst, attrName, options) => {
|
|
41
|
-
const conf = (0, import_elementDefine.getElementConfig)(inst);
|
|
42
|
-
const currentWin = inst._resolveWindow?.(conf) || (typeof window !== "undefined" ? window : void 0);
|
|
43
|
-
const targets = options?.selector ? resolveTargetEls(inst, options.selector, options, currentWin) : [inst];
|
|
44
|
-
const primaryTarget = targets[0];
|
|
45
|
-
if (primaryTarget && typeof primaryTarget.hasAttribute === "function" && primaryTarget.hasAttribute(attrName)) {
|
|
46
|
-
let domVal = primaryTarget.getAttribute(attrName);
|
|
47
|
-
const ae = new import_core.ActionExpression(domVal);
|
|
48
|
-
const expr = ae.getFirstExpression("callReturn");
|
|
49
|
-
if (expr) {
|
|
50
|
-
try {
|
|
51
|
-
const result = import_core.FunctionUtils.executeReturn({
|
|
52
|
-
script: import_core_web.ConvertUtils.decodeHtmlEntity(expr.script, currentWin.document),
|
|
53
|
-
context: inst,
|
|
54
|
-
args: import_Utils.SwcUtils.getHelperAndHostSet(currentWin, inst)
|
|
55
|
-
});
|
|
56
|
-
return convertValue(result, options?.type);
|
|
57
|
-
} catch (e) {
|
|
58
|
-
console.error(`[SWC] Failed to execute directive {{= ${expr.script} }}:`, e);
|
|
59
|
-
return convertValue(domVal, options?.type);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return convertValue(domVal, options?.type);
|
|
63
|
-
}
|
|
64
|
-
return null;
|
|
65
|
-
};
|
|
66
|
-
const resolveTargetEls = (inst, selector, options, currentWin) => {
|
|
67
|
-
const r = options.root || "auto";
|
|
68
|
-
const results = [];
|
|
69
|
-
const applyRoot = (target) => {
|
|
70
|
-
if (!target) return;
|
|
71
|
-
if (r === "auto") {
|
|
72
|
-
results.push(target);
|
|
73
|
-
} else {
|
|
74
|
-
if (r === "light" || r === "all") results.push(target);
|
|
75
|
-
if ((r === "shadow" || r === "all") && target.shadowRoot) results.push(target.shadowRoot);
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
if (selector === "$this" || !selector) {
|
|
79
|
-
applyRoot(inst);
|
|
80
|
-
} else if (selector === "$window") {
|
|
81
|
-
results.push(currentWin);
|
|
82
|
-
} else if (selector === "$document") {
|
|
83
|
-
results.push(currentWin.document);
|
|
84
|
-
} else {
|
|
85
|
-
const hostSet = import_Utils.SwcUtils.getHostSet(inst);
|
|
86
|
-
if (selector === "$host") applyRoot(hostSet.$host);
|
|
87
|
-
else if (selector === "$parentHost") applyRoot(hostSet.$parentHost);
|
|
88
|
-
else if (selector === "$appHost") applyRoot(hostSet.$appHost);
|
|
89
|
-
else if (selector === "$firstHost") applyRoot(hostSet.$firstHost);
|
|
90
|
-
else if (selector === "$lastHost") applyRoot(hostSet.$lastHost);
|
|
91
|
-
else if (selector === "$firstAppHost") applyRoot(hostSet.$firstAppHost);
|
|
92
|
-
else if (selector === "$lastAppHost") applyRoot(hostSet.$lastAppHost);
|
|
93
|
-
else {
|
|
94
|
-
if (r === "shadow") {
|
|
95
|
-
const found = inst.shadowRoot?.querySelectorAll(selector);
|
|
96
|
-
if (found) results.push(...found);
|
|
97
|
-
} else if (r === "light") {
|
|
98
|
-
const found = inst.querySelectorAll(selector);
|
|
99
|
-
if (found) results.push(...found);
|
|
100
|
-
} else if (r === "all") {
|
|
101
|
-
const sMatch = inst.shadowRoot?.querySelectorAll(selector);
|
|
102
|
-
const lMatch = inst.querySelectorAll(selector);
|
|
103
|
-
if (sMatch) results.push(...sMatch);
|
|
104
|
-
if (lMatch) results.push(...lMatch);
|
|
105
|
-
} else {
|
|
106
|
-
const found = (inst.shadowRoot || inst).querySelectorAll(selector);
|
|
107
|
-
if (found) results.push(...found);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
return results;
|
|
112
|
-
};
|
|
113
|
-
function attribute(selector, options = {}) {
|
|
114
|
-
return (target, propertyKey) => {
|
|
115
|
-
const constructor = target.constructor;
|
|
116
|
-
const privateKey = Symbol(String(propertyKey));
|
|
117
|
-
const designType = Reflect.getMetadata("design:type", target, propertyKey);
|
|
118
|
-
let metaList = import_core.ReflectUtils.getOwnMetadata(ATTRIBUTE_FIELD_METADATA_KEY, constructor);
|
|
119
|
-
if (!metaList) {
|
|
120
|
-
metaList = [];
|
|
121
|
-
import_core.ReflectUtils.defineMetadata(ATTRIBUTE_FIELD_METADATA_KEY, metaList, constructor);
|
|
122
|
-
}
|
|
123
|
-
metaList.push({ propertyKey, selector, options, privateKey });
|
|
124
|
-
const applySetAttribute = (inst, targets, attrName, nv) => {
|
|
125
|
-
targets.forEach((it) => {
|
|
126
|
-
if (it && typeof it.setAttribute === "function") {
|
|
127
|
-
if (nv === null) {
|
|
128
|
-
it.removeAttribute(attrName);
|
|
129
|
-
} else {
|
|
130
|
-
it.setAttribute(attrName, String(nv));
|
|
131
|
-
}
|
|
132
|
-
} else {
|
|
133
|
-
inst[privateKey] = nv;
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
};
|
|
137
|
-
try {
|
|
138
|
-
Object.defineProperty(target, propertyKey, {
|
|
139
|
-
get() {
|
|
140
|
-
const attrName = options.name || String(propertyKey);
|
|
141
|
-
const mergedOptions = {
|
|
142
|
-
...options,
|
|
143
|
-
selector,
|
|
144
|
-
type: options.type || designType
|
|
145
|
-
};
|
|
146
|
-
const result = getAttributeValue(this, attrName, mergedOptions);
|
|
147
|
-
return result !== null ? result : this[privateKey];
|
|
148
|
-
},
|
|
149
|
-
set(nv) {
|
|
150
|
-
const attrName = options.name || String(propertyKey);
|
|
151
|
-
const conf = (0, import_elementDefine.getElementConfig)(this);
|
|
152
|
-
const currentWin = this._resolveWindow?.(conf) || (typeof window !== "undefined" ? window : void 0);
|
|
153
|
-
const targets = resolveTargetEls(this, selector, options, currentWin);
|
|
154
|
-
applySetAttribute(this, targets, attrName, nv);
|
|
155
|
-
},
|
|
156
|
-
enumerable: true,
|
|
157
|
-
configurable: true
|
|
158
|
-
});
|
|
159
|
-
} catch (err) {
|
|
160
|
-
console.error("[SWC] defineProperty error:", err);
|
|
161
|
-
}
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
function attributeThis(targetOrAttrOrOptions, propertyKeyOrOptions) {
|
|
165
|
-
if (propertyKeyOrOptions !== void 0 && (typeof propertyKeyOrOptions === "string" || typeof propertyKeyOrOptions === "symbol")) {
|
|
166
|
-
return attribute("$this", { name: String(propertyKeyOrOptions) })(targetOrAttrOrOptions, propertyKeyOrOptions);
|
|
167
|
-
}
|
|
168
|
-
if (typeof targetOrAttrOrOptions === "string") {
|
|
169
|
-
const attrName = targetOrAttrOrOptions;
|
|
170
|
-
const options = typeof propertyKeyOrOptions === "object" ? propertyKeyOrOptions : {};
|
|
171
|
-
return attribute("$this", { ...options, name: attrName });
|
|
172
|
-
} else if (typeof targetOrAttrOrOptions === "object") {
|
|
173
|
-
const options = targetOrAttrOrOptions;
|
|
174
|
-
return (target, propertyKey) => {
|
|
175
|
-
return attribute("$this", { ...options, name: String(propertyKey) })(target, propertyKey);
|
|
176
|
-
};
|
|
177
|
-
} else {
|
|
178
|
-
return (target, propertyKey) => {
|
|
179
|
-
return attribute("$this", { name: String(propertyKey) })(target, propertyKey);
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
const findAllAttributeMetadata = (target) => {
|
|
184
|
-
const actualTarget = target instanceof Function ? target : target.constructor;
|
|
185
|
-
return import_core.ReflectUtils.findAllMetadata(ATTRIBUTE_FIELD_METADATA_KEY, actualTarget).flat();
|
|
186
|
-
};
|
|
187
|
-
//# sourceMappingURL=attribute.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/decorators/attribute.ts"],
|
|
4
|
-
"sourcesContent": ["import { ReflectUtils, FunctionUtils, ActionExpression } from '@dooboostore/core';\nimport { ensureInit, getElementConfig } from './elementDefine';\nimport { SwcUtils } from '../utils/Utils';\nimport { SpecialSelector, SwcQueryOptions, HelperHostSet } from '../types';\nimport { ConvertUtils } from '@dooboostore/core-web';\nexport interface AttributeFieldOptions extends SwcQueryOptions {\n name?: string;\n // connectedInitialize?: boolean;\n type?: typeof Number | typeof Boolean | typeof String;\n}\n\nexport interface AttributeFieldMetadata {\n propertyKey: string | symbol;\n selector: string;\n options: AttributeFieldOptions;\n privateKey: symbol;\n}\n\nexport const ATTRIBUTE_FIELD_METADATA_KEY = Symbol.for('simple-web-component:attribute-field');\n\nconst convertValue = (val: string | null, 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\nexport { convertValue };\n\nexport const getAttributeValue = (inst: any, attrName: string, options?: AttributeFieldOptions & { selector?: string }): any => {\n const conf = getElementConfig(inst);\n const currentWin = inst._resolveWindow?.(conf) || ((typeof window !== 'undefined' ? window : undefined) as any);\n\n // If selector is not provided, use inst itself\n const targets = options?.selector ? resolveTargetEls(inst, options.selector, options, currentWin) : [inst];\n\n const primaryTarget = targets[0];\n\n if (primaryTarget && typeof (primaryTarget as any).hasAttribute === 'function' && (primaryTarget as any).hasAttribute(attrName)) {\n let domVal = (primaryTarget as any).getAttribute(attrName);\n\n // \uD45C\uD604\uC2DD \uCCB4\uD06C\n const ae = new ActionExpression(domVal);\n const expr = ae.getFirstExpression('callReturn');\n if (expr) {\n try {\n const result = FunctionUtils.executeReturn({\n script: ConvertUtils.decodeHtmlEntity(expr.script, currentWin.document),\n context: inst,\n args: SwcUtils.getHelperAndHostSet(currentWin, inst)\n });\n return convertValue(result, options?.type);\n } catch (e) {\n console.error(`[SWC] Failed to execute directive {{= ${expr.script} }}:`, e);\n return convertValue(domVal, options?.type);\n }\n }\n\n return convertValue(domVal, options?.type);\n }\n\n // If no target found, return null\n return null;\n};\n\nexport const resolveTargetEls = (inst: any, selector: string, options: AttributeFieldOptions, currentWin: any): HTMLElement[] => {\n const r = options.root || 'auto';\n const results: HTMLElement[] = [];\n\n const applyRoot = (target: any) => {\n if (!target) return;\n if (r === 'auto') {\n results.push(target);\n } else {\n if (r === 'light' || r === 'all') results.push(target);\n if ((r === 'shadow' || r === 'all') && target.shadowRoot) results.push(target.shadowRoot);\n }\n };\n\n if (selector === '$this' || !selector) {\n applyRoot(inst);\n } else if (selector === '$window') {\n results.push(currentWin);\n } else if (selector === '$document') {\n results.push(currentWin.document);\n } else {\n const hostSet = SwcUtils.getHostSet(inst);\n if (selector === '$host') applyRoot(hostSet.$host);\n else if (selector === '$parentHost') applyRoot(hostSet.$parentHost);\n else if (selector === '$appHost') applyRoot(hostSet.$appHost as any);\n else if (selector === '$firstHost') applyRoot(hostSet.$firstHost);\n else if (selector === '$lastHost') applyRoot(hostSet.$lastHost);\n else if (selector === '$firstAppHost') applyRoot(hostSet.$firstAppHost as any);\n else if (selector === '$lastAppHost') applyRoot(hostSet.$lastAppHost as any);\n else {\n if (r === 'shadow') {\n const found = inst.shadowRoot?.querySelectorAll(selector);\n if (found) results.push(...found);\n } else if (r === 'light') {\n const found = inst.querySelectorAll(selector);\n if (found) results.push(...found);\n } else if (r === 'all') {\n const sMatch = inst.shadowRoot?.querySelectorAll(selector);\n const lMatch = inst.querySelectorAll(selector);\n if (sMatch) results.push(...sMatch);\n if (lMatch) results.push(...lMatch);\n } else {\n const found = (inst.shadowRoot || inst).querySelectorAll(selector);\n if (found) results.push(...found);\n }\n }\n }\n return results;\n};\n\n/**\n * @attribute decorator to sync a field value with an element's attribute.\n */\nexport function attribute(selector: string, options: AttributeFieldOptions = {}): PropertyDecorator {\n return (target: Object, propertyKey: string | symbol) => {\n const constructor = target.constructor;\n const privateKey = Symbol(String(propertyKey));\n //\n const designType = (Reflect as any).getMetadata('design:type', target, propertyKey);\n //\n let metaList = ReflectUtils.getOwnMetadata(ATTRIBUTE_FIELD_METADATA_KEY, constructor) as AttributeFieldMetadata[];\n if (!metaList) {\n metaList = [];\n ReflectUtils.defineMetadata(ATTRIBUTE_FIELD_METADATA_KEY, metaList, constructor);\n }\n metaList.push({ propertyKey, selector, options, privateKey });\n\n const applySetAttribute = (inst: any, targets: HTMLElement[], attrName: string, nv: any) => {\n targets.forEach(it => {\n // console.log('sssssssssssss', it, attrName, nv);\n if (it && typeof (it as any).setAttribute === 'function') {\n if (nv === null) {\n (it as any).removeAttribute(attrName);\n } else {\n (it as any).setAttribute(attrName, String(nv));\n }\n } else {\n inst[privateKey] = nv;\n }\n });\n };\n\n try {\n // Own property\uB97C \uC0AD\uC81C\uD558\uC5EC getter\uAC00 \uC791\uB3D9\uD558\uB3C4\uB85D \uD568\n // delete target[propertyKey];\n\n // const defineTarget = target instanceof Function ? target : (target as any).constructor;\n\n Object.defineProperty(target, propertyKey, {\n get(this: any) {\n const attrName = options.name || String(propertyKey);\n\n // Merge designType fallback into options once\n const mergedOptions = {\n ...options,\n selector,\n type: options.type || designType\n };\n\n const result = getAttributeValue(this, attrName, mergedOptions);\n return result !== null ? result : this[privateKey];\n },\n set(this: any, nv: any) {\n // this[propertyKey] = nv;\n // console.log('------>??settttt', this, nv, propertyKey);\n const attrName = options.name || String(propertyKey);\n const conf = getElementConfig(this);\n const currentWin = this._resolveWindow?.(conf) || ((typeof window !== 'undefined' ? window : undefined) as any);\n\n // if (!this.__swc_connected) {\n // this[privateKey] = nv;\n // return;\n // }\n\n const targets = resolveTargetEls(this, selector, options, currentWin);\n applySetAttribute(this, targets, attrName, nv);\n },\n enumerable: true,\n configurable: true\n });\n } catch (err) {\n console.error('[SWC] defineProperty error:', err);\n }\n };\n}\n\n/**\n * @attributeThis decorator to sync a field value with the $this element's attribute.\n */\nexport function attributeThis(target: Object, propertyKey: string | symbol): void;\nexport function attributeThis(options: AttributeFieldOptions): PropertyDecorator;\nexport function attributeThis(attrName: string): PropertyDecorator;\nexport function attributeThis(attrName: string, options: AttributeFieldOptions): PropertyDecorator;\nexport function attributeThis(targetOrAttrOrOptions?: any, propertyKeyOrOptions?: any): any {\n if (propertyKeyOrOptions !== undefined && (typeof propertyKeyOrOptions === 'string' || typeof propertyKeyOrOptions === 'symbol')) {\n return attribute('$this', { name: String(propertyKeyOrOptions) })(targetOrAttrOrOptions, propertyKeyOrOptions);\n }\n\n if (typeof targetOrAttrOrOptions === 'string') {\n const attrName = targetOrAttrOrOptions;\n const options = (typeof propertyKeyOrOptions === 'object' ? propertyKeyOrOptions : {}) as AttributeFieldOptions;\n return attribute('$this', { ...options, name: attrName });\n } else if (typeof targetOrAttrOrOptions === 'object') {\n const options = targetOrAttrOrOptions as AttributeFieldOptions;\n return (target: Object, propertyKey: string | symbol) => {\n return attribute('$this', { ...options, name: String(propertyKey) })(target, propertyKey);\n };\n } else {\n return (target: Object, propertyKey: string | symbol) => {\n return attribute('$this', { name: String(propertyKey) })(target, propertyKey);\n };\n }\n}\n\nexport const findAllAttributeMetadata = (target: any): AttributeFieldMetadata[] => {\n const actualTarget = target instanceof Function ? target : target.constructor;\n return ReflectUtils.findAllMetadata<AttributeFieldMetadata[]>(ATTRIBUTE_FIELD_METADATA_KEY, actualTarget).flat();\n};\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAA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E,CAAC,EAAE,QAAQ,WAAW;AAAA,IAC9E;AAAA,EACF;AACF;AAEO,MAAM,2BAA2B,CAAC,WAA0C;AACjF,QAAM,eAAe,kBAAkB,WAAW,SAAS,OAAO;AAClE,SAAO,yBAAa,gBAA0C,8BAA8B,YAAY,EAAE,KAAK;AACjH;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,109 +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 setProperty_exports = {};
|
|
19
|
-
__export(setProperty_exports, {
|
|
20
|
-
PROPERTY_SET_METADATA_KEY: () => PROPERTY_SET_METADATA_KEY,
|
|
21
|
-
setProperty: () => setProperty,
|
|
22
|
-
setPropertyThis: () => setPropertyThis
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(setProperty_exports);
|
|
25
|
-
var import_core = require("@dooboostore/core");
|
|
26
|
-
var import_elementDefine = require("./elementDefine");
|
|
27
|
-
var import_Utils = require("../utils/Utils");
|
|
28
|
-
const PROPERTY_SET_METADATA_KEY = Symbol.for("simple-web-component:property-set");
|
|
29
|
-
const setProperty = (selector, propertyNameOrOptions, options = {}) => {
|
|
30
|
-
return (target, propertyKey, descriptor) => {
|
|
31
|
-
const constructor = target.constructor;
|
|
32
|
-
let metaList = import_core.ReflectUtils.getOwnMetadata(PROPERTY_SET_METADATA_KEY, constructor);
|
|
33
|
-
if (!metaList) {
|
|
34
|
-
metaList = /* @__PURE__ */ new Map();
|
|
35
|
-
import_core.ReflectUtils.defineMetadata(PROPERTY_SET_METADATA_KEY, metaList, constructor);
|
|
36
|
-
}
|
|
37
|
-
let propertyName = typeof propertyNameOrOptions === "string" ? propertyNameOrOptions : void 0;
|
|
38
|
-
let finalOptions = options;
|
|
39
|
-
if (typeof propertyNameOrOptions === "object" && propertyNameOrOptions !== null) {
|
|
40
|
-
finalOptions = propertyNameOrOptions;
|
|
41
|
-
}
|
|
42
|
-
metaList.set(propertyKey, {
|
|
43
|
-
propertyKey,
|
|
44
|
-
selector,
|
|
45
|
-
options: { ...finalOptions, name: propertyName }
|
|
46
|
-
});
|
|
47
|
-
const original = descriptor.value;
|
|
48
|
-
descriptor.value = function(...args) {
|
|
49
|
-
(0, import_elementDefine.ensureInit)(this);
|
|
50
|
-
const res = original.apply(this, args);
|
|
51
|
-
const handleResult = (resolvedValue) => {
|
|
52
|
-
if (resolvedValue !== void 0) {
|
|
53
|
-
const win = this.ownerDocument?.defaultView || window;
|
|
54
|
-
const host = this;
|
|
55
|
-
const hostSet = { ...import_Utils.SwcUtils.getHelperAndHostSet(win, host), $this: this };
|
|
56
|
-
const r = finalOptions.root || "auto";
|
|
57
|
-
const targetEls = [];
|
|
58
|
-
const applyRoot = (t) => {
|
|
59
|
-
if (!t || !(t instanceof win.HTMLElement)) return;
|
|
60
|
-
targetEls.push(t);
|
|
61
|
-
};
|
|
62
|
-
if (selector === "$this" || !selector) applyRoot(host);
|
|
63
|
-
else if (selector === "$host") applyRoot(hostSet.$host);
|
|
64
|
-
else if (selector === "$parentHost") applyRoot(hostSet.$parentHost);
|
|
65
|
-
else if (selector === "$appHost") applyRoot(hostSet.$appHost);
|
|
66
|
-
else if (selector === "$firstHost") applyRoot(hostSet.$firstHost);
|
|
67
|
-
else if (selector === "$lastHost") applyRoot(hostSet.$lastHost);
|
|
68
|
-
else if (selector === "$firstAppHost") applyRoot(hostSet.$firstAppHost);
|
|
69
|
-
else if (selector === "$lastAppHost") applyRoot(hostSet.$lastAppHost);
|
|
70
|
-
else if (selector === "$hosts") hostSet.$hosts.forEach(applyRoot);
|
|
71
|
-
else if (selector === "$appHosts") hostSet.$appHosts.forEach(applyRoot);
|
|
72
|
-
else {
|
|
73
|
-
const targetRoot = r === "auto" ? host.shadowRoot || host : r === "shadow" ? host.shadowRoot : host;
|
|
74
|
-
if (targetRoot) {
|
|
75
|
-
const found = targetRoot.querySelectorAll(selector);
|
|
76
|
-
if (found) targetEls.push(...Array.from(found));
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
targetEls.forEach((targetEl) => {
|
|
80
|
-
if (finalOptions.filter && !finalOptions.filter(targetEl, resolvedValue, { currentThis: this, helper: hostSet })) {
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
const resolvedRes = typeof resolvedValue === "function" ? resolvedValue(targetEl, hostSet) : resolvedValue;
|
|
84
|
-
if (propertyName) {
|
|
85
|
-
targetEl[propertyName] = resolvedRes;
|
|
86
|
-
} else if (typeof resolvedRes === "object" && resolvedRes !== null && !Array.isArray(resolvedRes)) {
|
|
87
|
-
Object.entries(resolvedRes).forEach(([prop, val]) => {
|
|
88
|
-
const finalVal = typeof val === "function" ? val(targetEl, hostSet) : val;
|
|
89
|
-
targetEl[prop] = finalVal;
|
|
90
|
-
});
|
|
91
|
-
} else {
|
|
92
|
-
targetEl.value = resolvedRes;
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
return resolvedValue;
|
|
97
|
-
};
|
|
98
|
-
if (res instanceof Promise) {
|
|
99
|
-
return res.then(handleResult);
|
|
100
|
-
} else {
|
|
101
|
-
return handleResult(res);
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
};
|
|
105
|
-
};
|
|
106
|
-
const setPropertyThis = (propertyNameOrOptions, options = {}) => {
|
|
107
|
-
return setProperty("$this", propertyNameOrOptions, options);
|
|
108
|
-
};
|
|
109
|
-
//# sourceMappingURL=setProperty.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/decorators/setProperty.ts"],
|
|
4
|
-
"sourcesContent": ["import { ReflectUtils } from '@dooboostore/core';\nimport { ensureInit } from './elementDefine';\nimport { SwcUtils } from '../utils/Utils';\nimport { SpecialSelector, SwcQueryOptions, HelperHostSet } from '../types';\n\nexport interface PropertySetOptions extends SwcQueryOptions {\n name?: string;\n filter?: (target: HTMLElement, value: any, meta: {currentThis: any, helper: HelperHostSet}) => boolean;\n}\n\nexport interface PropertySetMetadata {\n propertyKey: string | symbol;\n selector: string;\n options: PropertySetOptions;\n}\n\nexport const PROPERTY_SET_METADATA_KEY = Symbol.for('simple-web-component:property-set');\n\nexport const setProperty = (selector: string, propertyNameOrOptions?: string | PropertySetOptions, options: PropertySetOptions = {}): MethodDecorator => {\n return (target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n const constructor = target.constructor;\n let metaList = ReflectUtils.getOwnMetadata(PROPERTY_SET_METADATA_KEY, constructor) as Map<string | symbol, PropertySetMetadata>;\n if (!metaList) {\n metaList = new Map<string | symbol, PropertySetMetadata>();\n ReflectUtils.defineMetadata(PROPERTY_SET_METADATA_KEY, metaList, constructor);\n }\n\n let propertyName = typeof propertyNameOrOptions === 'string' ? propertyNameOrOptions : undefined;\n let finalOptions = options;\n \n if (typeof propertyNameOrOptions === 'object' && propertyNameOrOptions !== null) {\n finalOptions = propertyNameOrOptions as PropertySetOptions;\n }\n\n metaList.set(propertyKey, { \n propertyKey, \n selector, \n options: { ...finalOptions, name: propertyName } \n });\n\n const original = descriptor.value;\n descriptor.value = function (...args: any[]) {\n ensureInit(this);\n const res = (original as any).apply(this, args);\n\n const handleResult = (resolvedValue: any) => {\n if (resolvedValue !== undefined) {\n const win = (this as any).ownerDocument?.defaultView || window;\n const host = this as unknown as HTMLElement;\n const hostSet = { ...SwcUtils.getHelperAndHostSet(win, host), $this: this };\n const r = finalOptions.root || 'auto';\n const targetEls: HTMLElement[] = [];\n\n const applyRoot = (t: any) => {\n if (!t || !(t instanceof win.HTMLElement)) return;\n targetEls.push(t);\n };\n\n if (selector === '$this' || !selector) applyRoot(host);\n else if (selector === '$host') applyRoot(hostSet.$host);\n else if (selector === '$parentHost') applyRoot(hostSet.$parentHost);\n else if (selector === '$appHost') applyRoot(hostSet.$appHost);\n else if (selector === '$firstHost') applyRoot(hostSet.$firstHost);\n else if (selector === '$lastHost') applyRoot(hostSet.$lastHost);\n else if (selector === '$firstAppHost') applyRoot(hostSet.$firstAppHost);\n else if (selector === '$lastAppHost') applyRoot(hostSet.$lastAppHost);\n else if (selector === '$hosts') hostSet.$hosts.forEach(applyRoot);\n else if (selector === '$appHosts') hostSet.$appHosts.forEach(applyRoot);\n else {\n const targetRoot = r === 'auto' ? (host.shadowRoot || host) : (r === 'shadow' ? host.shadowRoot : host);\n if (targetRoot) {\n const found = targetRoot.querySelectorAll(selector);\n if (found) targetEls.push(...(Array.from(found) as HTMLElement[]));\n }\n }\n\n targetEls.forEach(targetEl => {\n if (finalOptions.filter && !finalOptions.filter(targetEl, resolvedValue, {currentThis: this, helper: hostSet})) {\n return;\n }\n const resolvedRes = typeof resolvedValue === 'function' ? (resolvedValue as any)(targetEl, hostSet) : resolvedValue;\n\n if (propertyName) {\n // Case: @setProperty(selector, 'propertyName')\n (targetEl as any)[propertyName] = resolvedRes;\n } else if (typeof resolvedRes === 'object' && resolvedRes !== null && !Array.isArray(resolvedRes)) {\n // Case: @setProperty(selector) with Object return - assign multiple properties\n Object.entries(resolvedRes as any).forEach(([prop, val]) => {\n const finalVal = typeof val === 'function' ? val(targetEl, hostSet) : val;\n (targetEl as any)[prop] = finalVal;\n });\n } else {\n // Simple value - assign to 'value' property by default\n (targetEl as any).value = resolvedRes;\n }\n });\n }\n return resolvedValue;\n };\n\n if (res instanceof Promise) {\n return res.then(handleResult);\n } else {\n return handleResult(res);\n }\n };\n };\n};\n\nexport const setPropertyThis = (propertyNameOrOptions?: string | PropertySetOptions, options: PropertySetOptions = {}): MethodDecorator => {\n return setProperty('$this', propertyNameOrOptions, options);\n};\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA6B;AAC7B,2BAA2B;AAC3B,mBAAyB;AAclB,MAAM,4BAA4B,OAAO,IAAI,mCAAmC;AAEhF,MAAM,cAAc,CAAC,UAAkB,uBAAqD,UAA8B,CAAC,MAAuB;AACvJ,SAAO,CAAC,QAAgB,aAA8B,eAAmC;AACvF,UAAM,cAAc,OAAO;AAC3B,QAAI,WAAW,yBAAa,eAAe,2BAA2B,WAAW;AACjF,QAAI,CAAC,UAAU;AACb,iBAAW,oBAAI,IAA0C;AACzD,+BAAa,eAAe,2BAA2B,UAAU,WAAW;AAAA,IAC9E;AAEA,QAAI,eAAe,OAAO,0BAA0B,WAAW,wBAAwB;AACvF,QAAI,eAAe;AAEnB,QAAI,OAAO,0BAA0B,YAAY,0BAA0B,MAAM;AAC/E,qBAAe;AAAA,IACjB;AAEA,aAAS,IAAI,aAAa;AAAA,MACxB;AAAA,MACA;AAAA,MACA,SAAS,EAAE,GAAG,cAAc,MAAM,aAAa;AAAA,IACjD,CAAC;AAED,UAAM,WAAW,WAAW;AAC5B,eAAW,QAAQ,YAAa,MAAa;AAC3C,2CAAW,IAAI;AACf,YAAM,MAAO,SAAiB,MAAM,MAAM,IAAI;AAE9C,YAAM,eAAe,CAAC,kBAAuB;AAC3C,YAAI,kBAAkB,QAAW;AAC/B,gBAAM,MAAO,KA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