@dooboostore/simple-web-component 1.0.38 → 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 +88 -871
- 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 +82 -80
- 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 +93 -82
- package/dist/cjs/decorators/applySlot.js.map +3 -3
- package/dist/cjs/decorators/changedAttributeThis.js.map +1 -1
- package/dist/cjs/decorators/elementDefine.js +14 -34
- 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/decorators/state.js +0 -1
- package/dist/cjs/decorators/state.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 +82 -80
- 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 +93 -82
- package/dist/esm/decorators/applySlot.js.map +3 -3
- package/dist/esm/decorators/changedAttributeThis.js.map +1 -1
- package/dist/esm/decorators/elementDefine.js +14 -34
- 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/decorators/state.js +0 -1
- package/dist/esm/decorators/state.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 +525 -513
- 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 +17 -15
- 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/decorators/state.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 +525 -513
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +1 -1
- package/src/SwcAppEngine.ts +1 -0
- package/src/decorators/applyAttribute.ts +311 -126
- package/src/decorators/applyNode.ts +108 -105
- package/src/decorators/applyProperty.ts +302 -0
- package/src/decorators/applySlot.ts +112 -94
- package/src/decorators/changedAttributeThis.ts +1 -1
- package/src/decorators/elementDefine.ts +44 -33
- package/src/decorators/index.ts +2 -3
- package/src/decorators/lifecycles.ts +6 -6
- package/src/decorators/state.ts +0 -1
- 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
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/decorators/applyProperty.ts"],
|
|
4
|
+
"sourcesContent": ["import { ReflectUtils } from '@dooboostore/core';\nimport { ensureInit, getElementConfig } from './elementDefine';\nimport { SwcUtils } from '../utils/Utils';\nimport { SwcQueryOptions, HelperHostSet } from '../types';\n\nexport interface PropertyOptions extends SwcQueryOptions {\n name?: string | symbol;\n filter?: (target: HTMLElement, value: any, meta: {currentThis: any, helper: HelperHostSet}) => boolean;\n}\n\nexport interface PropertyMetadata {\n propertyKey: string | symbol;\n selector: string;\n targetPropertyKey: string | symbol;\n options: PropertyOptions;\n type: 'property' | 'method';\n}\n\nexport const PROPERTY_METADATA_KEY = Symbol.for('simple-web-component:property');\n\n// ============================================\n// Utilities\n// ============================================\n\n/**\n * Resolve target elements based on selector and options\n * Handles special selectors ($this, $host, etc.) and CSS selectors\n * Returns HTMLElement[] but can include Window and Document for property access\n */\nexport const resolvePropertyTargets = (inst: any, selector: string, options: PropertyOptions): any[] => {\n const conf = getElementConfig(inst);\n const currentWin = conf.window;\n const r = options.root || 'auto';\n const results: any[] = [];\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 if (selector === '$hosts') hostSet.$hosts.forEach(applyRoot);\n else if (selector === '$appHosts') hostSet.$appHosts.forEach(applyRoot);\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 * @applyProperty decorator - set/get element properties\n * \n * Usage:\n * - @applyProperty('selector', 'propertyName') - Set property with explicit name\n * - @applyProperty('selector') - Use property name as target property name\n * - @applyProperty('selector', { name: 'propertyName' }) - Set property via options\n * - Return null/undefined to skip setting\n */\nexport function applyProperty(selector: string, targetPropertyKey: string | symbol, options?: PropertyOptions): MethodDecorator & PropertyDecorator;\nexport function applyProperty(selector: string, options?: PropertyOptions): MethodDecorator & PropertyDecorator;\nexport function applyProperty(selector: string, targetPropertyKeyOrOptions?: string | symbol | PropertyOptions, options?: PropertyOptions): MethodDecorator & PropertyDecorator {\n return (target: Object, propertyKey: string | symbol, descriptor?: PropertyDescriptor) => {\n // ensureInit(target as any);\n \n const constructor = target.constructor;\n const metaType: 'property' | 'method' = descriptor && typeof descriptor.value === 'function' ? 'method' : 'property';\n \n // Parse arguments\n let finalOptions: PropertyOptions = {};\n let targetPropertyKey: string | symbol;\n \n if (typeof targetPropertyKeyOrOptions === 'string' || typeof targetPropertyKeyOrOptions === 'symbol') {\n // applyProperty('selector', 'propertyName', options?)\n targetPropertyKey = targetPropertyKeyOrOptions;\n finalOptions = options || {};\n } else if (targetPropertyKeyOrOptions) {\n // applyProperty('selector', options)\n finalOptions = targetPropertyKeyOrOptions;\n targetPropertyKey = finalOptions.name || propertyKey;\n } else {\n // applyProperty('selector')\n targetPropertyKey = propertyKey;\n }\n\n // Store metadata\n let metaList = ReflectUtils.getOwnMetadata(PROPERTY_METADATA_KEY, constructor) as PropertyMetadata[];\n if (!metaList) {\n metaList = [];\n ReflectUtils.defineMetadata(PROPERTY_METADATA_KEY, metaList, constructor);\n }\n metaList.push({\n propertyKey,\n selector,\n targetPropertyKey,\n options: finalOptions,\n type: metaType\n });\n\n // Helper: apply resolved value to targets\n const applyValueToTargets = (inst: any, resolvedValue: any) => {\n if (resolvedValue === undefined) return resolvedValue;\n\n const targetEls = resolvePropertyTargets(inst, selector, finalOptions);\n const conf = getElementConfig(inst);\n const currentWin = conf.window;\n const hostSet = SwcUtils.getHelperAndHostSet(currentWin, inst);\n\n targetEls.forEach(targetEl => {\n // Apply filter if provided\n if (finalOptions.filter && !finalOptions.filter(targetEl, resolvedValue, { currentThis: inst, helper: hostSet })) {\n return;\n }\n\n const resolvedRes = typeof resolvedValue === 'function' ? (resolvedValue as any)(targetEl, hostSet) : resolvedValue;\n (targetEl as any)[targetPropertyKey] = resolvedRes;\n });\n\n return resolvedValue;\n };\n\n // Method decorator: wrap method to apply its return value to properties\n if (descriptor && typeof descriptor.value === 'function') {\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 if (res instanceof Promise) {\n return res.then((v: any) => { applyValueToTargets(this, v); return v; });\n } else {\n applyValueToTargets(this, res);\n return res;\n }\n };\n return;\n }\n\n // Property decorator: define getter/setter to proxy to element properties\n Object.defineProperty(target, propertyKey, {\n configurable: true,\n enumerable: true,\n get(this: any) {\n ensureInit(this);\n // Read from matched elements\n const targetEls = resolvePropertyTargets(this, selector, finalOptions);\n const conf = getElementConfig(this);\n const currentWin = conf.window;\n const hostSet = SwcUtils.getHelperAndHostSet(currentWin, this);\n\n // Apply filter\n const filtered = targetEls.filter(el => {\n if (finalOptions.filter && !finalOptions.filter(el, (el as any)[targetPropertyKey], { currentThis: this, helper: hostSet })) {\n return false;\n }\n return true;\n });\n\n const values = filtered.map(el => (el as any)[targetPropertyKey]);\n return values.length === 1 ? values[0] : values;\n },\n set(this: any, value: any) {\n ensureInit(this);\n applyValueToTargets(this, value);\n }\n });\n };\n}\n\n// ============================================\n// Convenience Aliases\n// ============================================\n\n/**\n * @property - Alias for @applyProperty\n */\nexport function property(selector: string, targetPropertyKey: string | symbol, options?: PropertyOptions): MethodDecorator & PropertyDecorator;\nexport function property(selector: string, options?: PropertyOptions): MethodDecorator & PropertyDecorator;\nexport function property(selector: string, targetPropertyKeyOrOptions?: string | symbol | PropertyOptions, options?: PropertyOptions): MethodDecorator & PropertyDecorator {\n return applyProperty(selector, targetPropertyKeyOrOptions as any, options);\n}\n\n/**\n * @propertyThis - Apply property on $this element\n * Can be used as: @propertyThis or @propertyThis('propertyName') or @propertyThis({ name: 'propertyName' })\n */\nexport function propertyThis(target: Object, propertyKey: string | symbol): void;\nexport function propertyThis(targetPropertyKey: string | symbol, options?: PropertyOptions): MethodDecorator & PropertyDecorator;\nexport function propertyThis(options?: PropertyOptions): MethodDecorator & PropertyDecorator;\nexport function propertyThis(targetOrOptions?: any, propertyKeyOrOptions?: any, descriptor?: PropertyDescriptor): any {\n // Direct decorator usage: @propertyThis\n if (typeof targetOrOptions === 'object' && targetOrOptions !== null && !Array.isArray(targetOrOptions) && \n (typeof propertyKeyOrOptions === 'string' || typeof propertyKeyOrOptions === 'symbol')) {\n // Called as @propertyThis (target, propertyKey)\n return applyProperty('$this', undefined as any, {})(targetOrOptions, propertyKeyOrOptions, descriptor);\n }\n \n // Called with parameters\n if (typeof targetOrOptions === 'string' || typeof targetOrOptions === 'symbol') {\n // @propertyThis('propertyName', options?)\n return applyProperty('$this', targetOrOptions, propertyKeyOrOptions);\n } else if (targetOrOptions && typeof targetOrOptions === 'object') {\n // @propertyThis({ name: 'propertyName' })\n return applyProperty('$this', undefined as any, targetOrOptions);\n } else {\n // @propertyThis() or @propertyThis\n return applyProperty('$this', undefined as any, {});\n }\n}\n\n/**\n * @setProperty - Alias for @applyProperty (method-decorator semantics)\n */\nexport function setProperty(selector: string, targetPropertyKey: string | symbol, options?: PropertyOptions): MethodDecorator;\nexport function setProperty(selector: string, options?: PropertyOptions): MethodDecorator;\nexport function setProperty(selector: string, targetPropertyKeyOrOptions?: string | symbol | PropertyOptions, options?: PropertyOptions): MethodDecorator {\n return applyProperty(selector, targetPropertyKeyOrOptions as any, options) as MethodDecorator;\n}\n\n/**\n * @setPropertyThis - Set property on $this element\n * Can be used as: @setPropertyThis or @setPropertyThis('propertyName') or @setPropertyThis({ name: 'propertyName' })\n */\nexport function setPropertyThis(target: Object, propertyKey: string | symbol): void;\nexport function setPropertyThis(targetPropertyKey: string | symbol, options?: PropertyOptions): MethodDecorator;\nexport function setPropertyThis(options?: PropertyOptions): MethodDecorator;\nexport function setPropertyThis(targetOrOptions?: any, propertyKeyOrOptions?: any, descriptor?: PropertyDescriptor): any {\n // Direct decorator usage: @setPropertyThis\n if (typeof targetOrOptions === 'object' && targetOrOptions !== null && !Array.isArray(targetOrOptions) && \n (typeof propertyKeyOrOptions === 'string' || typeof propertyKeyOrOptions === 'symbol')) {\n // Called as @setPropertyThis (target, propertyKey)\n return applyProperty('$this', undefined as any, {})(targetOrOptions, propertyKeyOrOptions, descriptor);\n }\n \n // Called with parameters\n if (typeof targetOrOptions === 'string' || typeof targetOrOptions === 'symbol') {\n // @setPropertyThis('propertyName', options?)\n return applyProperty('$this', targetOrOptions, propertyKeyOrOptions) as MethodDecorator;\n } else if (targetOrOptions && typeof targetOrOptions === 'object') {\n // @setPropertyThis({ name: 'propertyName' })\n return applyProperty('$this', undefined as any, targetOrOptions) as MethodDecorator;\n } else {\n // @setPropertyThis() or @setPropertyThis\n return applyProperty('$this', undefined as any, {}) as MethodDecorator;\n }\n}\n\n\n\n// ============================================\n// Metadata Helpers\n// ============================================\n\nexport const findAllPropertyMetadata = (target: any): PropertyMetadata[] => {\n const actualTarget = target instanceof Function ? target : target.constructor;\n return ReflectUtils.findAllMetadata<PropertyMetadata[]>(PROPERTY_METADATA_KEY, actualTarget).flat();\n};\n\n// Backward compatibility alias\nexport const findAllPropertyApplyMetadata = (target: any): Map<string | symbol, PropertyMetadata> => {\n const result = new Map<string | symbol, PropertyMetadata>();\n findAllPropertyMetadata(target).forEach(meta => {\n result.set(meta.propertyKey, meta);\n });\n return result;\n};\n\n\nexport default applyProperty;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA6B;AAC7B,2BAA6C;AAC7C,mBAAyB;AAgBlB,MAAM,wBAAwB,OAAO,IAAI,+BAA+B;AAWxE,MAAM,yBAAyB,CAAC,MAAW,UAAkB,YAAoC;AACtG,QAAM,WAAO,uCAAiB,IAAI;AAClC,QAAM,aAAa,KAAK;AACxB,QAAM,IAAI,QAAQ,QAAQ;AAC1B,QAAM,UAAiB,CAAC;AAExB,QAAM,YAAY,CAAC,WAAgB;A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;AAC1E,QAAM,eAAe,kBAAkB,WAAW,SAAS,OAAO;AAClE,SAAO,yBAAa,gBAAoC,uBAAuB,YAAY,EAAE,KAAK;AACpG;AAGO,MAAM,+BAA+B,CAAC,WAAwD;AACnG,QAAM,SAAS,oBAAI,IAAuC;AAC1D,0BAAwB,MAAM,EAAE,QAAQ,UAAQ;AAC9C,WAAO,IAAI,KAAK,aAAa,IAAI;AAAA,EACnC,CAAC;AACD,SAAO;AACT;AAGA,IAAO,wBAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -18,18 +18,18 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
18
18
|
var applySlot_exports = {};
|
|
19
19
|
__export(applySlot_exports, {
|
|
20
20
|
APPLY_SLOT_METADATA_KEY: () => APPLY_SLOT_METADATA_KEY,
|
|
21
|
+
appendHtmlSlot: () => appendHtmlSlot,
|
|
22
|
+
appendSlot: () => appendSlot,
|
|
23
|
+
appendTextSlot: () => appendTextSlot,
|
|
21
24
|
applySlot: () => applySlot,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
applySlotReplaceChildrenHtml: () => applySlotReplaceChildrenHtml,
|
|
31
|
-
applySlotReplaceChildrenText: () => applySlotReplaceChildrenText,
|
|
32
|
-
findAllApplySlotMetadata: () => findAllApplySlotMetadata
|
|
25
|
+
clearSlot: () => clearSlot,
|
|
26
|
+
findAllApplySlotMetadata: () => findAllApplySlotMetadata,
|
|
27
|
+
prependHtmlSlot: () => prependHtmlSlot,
|
|
28
|
+
prependSlot: () => prependSlot,
|
|
29
|
+
prependTextSlot: () => prependTextSlot,
|
|
30
|
+
replaceChildrenHtmlSlot: () => replaceChildrenHtmlSlot,
|
|
31
|
+
replaceChildrenSlot: () => replaceChildrenSlot,
|
|
32
|
+
replaceChildrenTextSlot: () => replaceChildrenTextSlot
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(applySlot_exports);
|
|
35
35
|
var import_core = require("@dooboostore/core");
|
|
@@ -37,93 +37,104 @@ var import_elementDefine = require("./elementDefine");
|
|
|
37
37
|
var import_Utils = require("../utils/Utils");
|
|
38
38
|
var import_core_web = require("@dooboostore/core-web");
|
|
39
39
|
const APPLY_SLOT_METADATA_KEY = Symbol.for("simple-web-component:apply-slot");
|
|
40
|
-
|
|
40
|
+
const applyToDom = (swcId, id, pos, nodes) => {
|
|
41
|
+
const nodeSlot = new import_core_web.NodeSlot(void 0, swcId);
|
|
42
|
+
if (pos === "replaceChildrenText" || pos === "replaceChildren" || pos === "replaceChildrenHtml") {
|
|
43
|
+
nodeSlot.replaceChildren(id, ...nodes);
|
|
44
|
+
} else if (pos === "appendHtml" || pos === "append" || pos === "appendText") {
|
|
45
|
+
nodeSlot.append(id, ...nodes);
|
|
46
|
+
} else if (pos === "prependHtml" || pos === "prepend" || pos === "prependText") {
|
|
47
|
+
nodeSlot.prepend(id, ...nodes);
|
|
48
|
+
} else if (pos === "clear") {
|
|
49
|
+
nodeSlot.clear(id);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
function applySlot(targetId, opt) {
|
|
41
53
|
return (targetObj, propertyKey, descriptor) => {
|
|
42
|
-
const
|
|
43
|
-
if (type === "property") {
|
|
44
|
-
Object.defineProperty(targetObj, propertyKey, {
|
|
45
|
-
get() {
|
|
46
|
-
const nodeSlot = new import_core_web.NodeSlot(this, `${this._swcId}-${id}`);
|
|
47
|
-
return nodeSlot;
|
|
48
|
-
},
|
|
49
|
-
set(nv) {
|
|
50
|
-
if (nv) {
|
|
51
|
-
} else {
|
|
52
|
-
const nodeSlot = new import_core_web.NodeSlot(this, `${this._swcId}-${id}`);
|
|
53
|
-
nodeSlot.clear();
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
configurable: true,
|
|
57
|
-
enumerable: true
|
|
58
|
-
});
|
|
59
|
-
}
|
|
54
|
+
const options = { position: "replaceChildren", ...opt };
|
|
60
55
|
const constructor = targetObj.constructor;
|
|
61
56
|
let metaList = import_core.ReflectUtils.getOwnMetadata(APPLY_SLOT_METADATA_KEY, constructor);
|
|
62
57
|
if (!metaList) {
|
|
63
58
|
metaList = [];
|
|
64
59
|
import_core.ReflectUtils.defineMetadata(APPLY_SLOT_METADATA_KEY, metaList, constructor);
|
|
65
60
|
}
|
|
66
|
-
metaList.push({ propertyKey,
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
} else if (pos === "appendText") {
|
|
87
|
-
nodeSlot.appendText(id, res);
|
|
88
|
-
} else if (pos === "prependHtml") {
|
|
89
|
-
nodeSlot.prependHtml(id, res);
|
|
90
|
-
} else if (pos === "prependText") {
|
|
91
|
-
nodeSlot.prependText(id, res);
|
|
92
|
-
} else if (pos === "clear") {
|
|
93
|
-
nodeSlot.clear(id);
|
|
94
|
-
}
|
|
61
|
+
metaList.push({ propertyKey, targetId, options });
|
|
62
|
+
const original = descriptor.value;
|
|
63
|
+
descriptor.value = function(...args) {
|
|
64
|
+
(0, import_elementDefine.ensureInit)(this);
|
|
65
|
+
const conf = (0, import_elementDefine.getElementConfig)(this);
|
|
66
|
+
const currentWin = conf.window;
|
|
67
|
+
const swcId = this._swcId;
|
|
68
|
+
const currentDoc = currentWin.document;
|
|
69
|
+
const hostSet = import_Utils.SwcUtils.getHelperAndHostSet(currentWin, this);
|
|
70
|
+
const pos = options.position;
|
|
71
|
+
const resToNodes = (res2) => {
|
|
72
|
+
const nodes = [];
|
|
73
|
+
if (typeof res2 === "string" && (pos === "replaceChildrenHtml" || pos === "appendHtml" || pos === "prependHtml")) {
|
|
74
|
+
const t = currentWin.document.createElement("template");
|
|
75
|
+
t.innerHTML = res2;
|
|
76
|
+
nodes.push(...Array.from(t.content.childNodes));
|
|
77
|
+
} else if (typeof res2 === "string" && (pos === "replaceChildrenText" || pos === "prependText" || pos === "appendText")) {
|
|
78
|
+
nodes.push(currentWin.document.createTextNode(res2));
|
|
79
|
+
} else if (typeof res2 === "object") {
|
|
80
|
+
nodes.push(res2);
|
|
95
81
|
}
|
|
96
|
-
|
|
82
|
+
import_Utils.SwcUtils.projectProcessHtml(swcId, nodes, currentDoc);
|
|
83
|
+
return nodes;
|
|
97
84
|
};
|
|
98
|
-
|
|
85
|
+
const fallbackNodes = [];
|
|
86
|
+
if (options.fallback) {
|
|
87
|
+
const res2 = options.fallback.call(this, hostSet);
|
|
88
|
+
const nodes = resToNodes(res2);
|
|
89
|
+
fallbackNodes.push(...nodes);
|
|
90
|
+
applyToDom(swcId, targetId, options.position, nodes);
|
|
91
|
+
}
|
|
92
|
+
let res = original.apply(this, args);
|
|
93
|
+
if (res instanceof Promise) {
|
|
94
|
+
return res.then((asyncRes) => {
|
|
95
|
+
const nodes = resToNodes(asyncRes);
|
|
96
|
+
fallbackNodes.forEach((it) => it.remove());
|
|
97
|
+
applyToDom(swcId, targetId, options.position, nodes);
|
|
98
|
+
});
|
|
99
|
+
} else {
|
|
100
|
+
const nodes = resToNodes(res);
|
|
101
|
+
applyToDom(swcId, targetId, options.position, nodes);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
99
104
|
};
|
|
100
105
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
return import_core.ReflectUtils.getMetadata(APPLY_SLOT_METADATA_KEY, constructor);
|
|
104
|
-
};
|
|
105
|
-
function applySlotClear(id) {
|
|
106
|
-
return applySlot(id, { position: "clear" });
|
|
106
|
+
function clearSlot(targetId) {
|
|
107
|
+
return applySlot(targetId, { position: "clear" });
|
|
107
108
|
}
|
|
108
|
-
function
|
|
109
|
-
return applySlot(
|
|
109
|
+
function prependHtmlSlot(targetId) {
|
|
110
|
+
return applySlot(targetId, { position: "prependHtml" });
|
|
110
111
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
return applySlot(id, { position: "prependText" });
|
|
112
|
+
function prependSlot(targetId) {
|
|
113
|
+
return applySlot(targetId, { position: "prepend" });
|
|
114
114
|
}
|
|
115
|
-
function
|
|
116
|
-
return applySlot(
|
|
115
|
+
function prependTextSlot(targetId) {
|
|
116
|
+
return applySlot(targetId, { position: "prependText" });
|
|
117
117
|
}
|
|
118
|
-
function
|
|
119
|
-
return applySlot(
|
|
118
|
+
function appendHtmlSlot(targetId) {
|
|
119
|
+
return applySlot(targetId, { position: "appendHtml" });
|
|
120
120
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
return applySlot(id, { position: "replaceChildrenHtml" });
|
|
121
|
+
function appendTextSlot(targetId) {
|
|
122
|
+
return applySlot(targetId, { position: "appendText" });
|
|
124
123
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
return applySlot(id, { position: "replaceChildrenText" });
|
|
124
|
+
function appendSlot(targetId) {
|
|
125
|
+
return applySlot(targetId, { position: "append" });
|
|
128
126
|
}
|
|
127
|
+
function replaceChildrenHtmlSlot(targetId) {
|
|
128
|
+
return applySlot(targetId, { position: "replaceChildrenHtml" });
|
|
129
|
+
}
|
|
130
|
+
function replaceChildrenSlot(targetId) {
|
|
131
|
+
return applySlot(targetId, { position: "replaceChildren" });
|
|
132
|
+
}
|
|
133
|
+
function replaceChildrenTextSlot(targetId) {
|
|
134
|
+
return applySlot(targetId, { position: "replaceChildrenText" });
|
|
135
|
+
}
|
|
136
|
+
const findAllApplySlotMetadata = (target) => {
|
|
137
|
+
const constructor = target instanceof Function ? target : target.constructor;
|
|
138
|
+
return import_core.ReflectUtils.getMetadata(APPLY_SLOT_METADATA_KEY, constructor);
|
|
139
|
+
};
|
|
129
140
|
//# sourceMappingURL=applySlot.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/decorators/applySlot.ts"],
|
|
4
|
-
"sourcesContent": ["import {ReflectUtils} from '@dooboostore/core';\nimport {ensureInit, getElementConfig} from './elementDefine';\nimport {SwcUtils} from \"../utils/Utils\";\nimport {NodeSlot} from \"@dooboostore/core-web\";\n/*\n<!-- beforebegin -->\n<p> <-- it's me\n <!-- afterbegin -->\n foo\n <!-- beforeend -->\n</p>\n<!-- afterend -->\n */\nexport type ApplySlotPosition = 'prependHtml' | 'prependText' | 'appendHtml' | 'appendText' | 'replaceChildrenHtml' | 'replaceChildrenText' | 'clear';\n\nexport interface ApplySlotOptions {\n position
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,
|
|
6
|
-
"names": []
|
|
4
|
+
"sourcesContent": ["import {OptionalType, ReflectUtils} from '@dooboostore/core';\nimport {ensureInit, getElementConfig} from './elementDefine';\nimport {SwcUtils} from \"../utils/Utils\";\nimport {NodeSlot} from \"@dooboostore/core-web\";\nimport {HelperHostSet} from \"../types\";\n/*\n<!-- beforebegin -->\n<p> <-- it's me\n <!-- afterbegin -->\n foo\n <!-- beforeend -->\n</p>\n<!-- afterend -->\n */\nexport type ApplySlotPosition = 'prepend' | 'prependHtml' | 'prependText' | 'append' | 'appendHtml' | 'appendText' | 'replaceChildren' | 'replaceChildrenHtml' | 'replaceChildrenText' | 'clear';\n\nexport interface ApplySlotOptions {\n position: ApplySlotPosition;\n fallback?: (helper: HelperHostSet) => string | Node;\n // root?: SwcRootType;\n /**\n * Filter function to determine whether to perform DOM operation.\n * If it returns false, the operation is skipped.\n */\n // filter?: (target: HTMLElement | ShadowRoot, newValue: any, meta:{currentThis: any,helper: HelperHostSet}) => boolean;\n /**\n * Optional loading content to display while an async method is executing.\n */\n // loading?: (helper: HelperHostSet) => any;\n}\n\nexport interface ApplySlotMetadata {\n propertyKey: string | symbol;\n targetId: string;\n // type: 'method' | 'property';\n options: ApplySlotOptions;\n}\n\nexport const APPLY_SLOT_METADATA_KEY = Symbol.for('simple-web-component:apply-slot');\n\n// const normalizeNodes = (res: any, doc: Document): Node[] => {\n// const items = Array.isArray(res) ? res : [res];\n// return items.map(it => {\n// if (it instanceof Node) return it;\n// return doc.createTextNode(it !== undefined && it !== null ? String(it) : '');\n// });\n// };\n\n// const applyToDom = (targetEl: any, res: any, pos: ApplyNodePosition, win: Window) => {\n// if (!targetEl) return;\n//\n// const doc = win.document;\n//\n// if (pos === 'innerHtml') {\n// targetEl.innerHTML = res !== undefined && res !== null ? String(res) : '';\n// return;\n// }\n//\n// if (pos === 'innerText') {\n// if (targetEl.innerText !== undefined) {\n// targetEl.innerText = res !== undefined && res !== null ? String(res) : '';\n// }\n// return;\n// }\n//\n// const isShadowRoot = targetEl instanceof win.ShadowRoot;\n// const nodes = normalizeNodes(res, doc);\n// if (pos === 'replace') {\n// if (!isShadowRoot) targetEl.replaceWith(...nodes);\n// } else if (pos === 'replaceChildren') {\n// targetEl.replaceChildren(...nodes);\n// } else {\n// if (pos === 'beforeEnd') targetEl.append(...nodes);\n// else if (pos === 'afterBegin') targetEl.prepend(...nodes);\n// else if (pos === 'beforeBegin' && !isShadowRoot) targetEl.before(...nodes);\n// else if (pos === 'afterEnd' && !isShadowRoot) targetEl.after(...nodes);\n// }\n// };\n\nconst applyToDom = (swcId: string, id: string, pos: ApplySlotPosition, nodes: Node[]) => {\n const nodeSlot = new NodeSlot(this, swcId);\n if (pos === 'replaceChildrenText' || pos === 'replaceChildren' || pos === 'replaceChildrenHtml') {\n nodeSlot.replaceChildren(id, ...nodes);\n } else if (pos === 'appendHtml' || pos === 'append' || pos === 'appendText') {\n nodeSlot.append(id, ...nodes);\n } else if (pos === 'prependHtml' || pos === 'prepend' || pos === 'prependText') {\n nodeSlot.prepend(id, ...nodes);\n } else if (pos === 'clear') {\n nodeSlot.clear(id);\n }\n}\n\n/**\n * @applyNode decorator to surgically add/replace nodes to a target element.\n */\nexport function applySlot(targetId: string, opt: OptionalType<ApplySlotOptions, 'position'>): MethodDecorator {\n return (targetObj: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<any>) => {\n\n\n const options: ApplySlotOptions = {position: 'replaceChildren', ...opt};\n\n\n const constructor = targetObj.constructor;\n let metaList = ReflectUtils.getOwnMetadata(APPLY_SLOT_METADATA_KEY, constructor) as ApplySlotMetadata[];\n if (!metaList) {\n metaList = []\n ReflectUtils.defineMetadata(APPLY_SLOT_METADATA_KEY, metaList, constructor);\n }\n metaList.push({propertyKey, targetId, options});\n\n\n const original = descriptor.value;\n descriptor.value = function (...args: any[]) {\n ensureInit(this);\n\n const conf = getElementConfig(this);\n const currentWin = conf.window;\n const swcId = this._swcId;\n const currentDoc = currentWin.document;\n const hostSet = SwcUtils.getHelperAndHostSet(currentWin, this);\n const pos = options.position;\n\n const resToNodes = (res: string | Node) => {\n const nodes: Node[] = [];\n\n if (typeof res === 'string' && (pos === 'replaceChildrenHtml' || pos === 'appendHtml' || pos === 'prependHtml')) {\n const t = currentWin.document.createElement('template');\n t.innerHTML = res;\n nodes.push(...Array.from(t.content.childNodes));\n } else if (typeof res === 'string' && (pos === 'replaceChildrenText' || pos === 'prependText' || pos === 'appendText')) {\n nodes.push(currentWin.document.createTextNode(res));\n } else if (typeof res === 'object') {\n nodes.push(res);\n }\n SwcUtils.projectProcessHtml(swcId, nodes, currentDoc);\n return nodes;\n }\n\n const fallbackNodes: Node[] = [];\n if (options.fallback) {\n const res: string | Node = options.fallback.call(this, hostSet);\n const nodes: Node[] = resToNodes(res);\n fallbackNodes.push(...nodes);\n applyToDom(swcId, targetId, options.position, nodes);\n }\n\n let res = original.apply(this, args);\n if (res instanceof Promise) {\n return res.then(asyncRes => {\n const nodes = resToNodes(asyncRes)\n fallbackNodes.forEach((it: any) => it.remove());\n applyToDom(swcId, targetId, options.position, nodes);\n })\n } else {\n const nodes: Node[] = resToNodes(res);\n applyToDom(swcId, targetId, options.position, nodes);\n }\n };\n };\n}\n\nexport function clearSlot(targetId: string): MethodDecorator {\n return applySlot(targetId, {position: 'clear'});\n}\n\nexport function prependHtmlSlot(targetId: string): MethodDecorator {\n return applySlot(targetId, {position: 'prependHtml'});\n}\n\nexport function prependSlot(targetId: string): MethodDecorator {\n return applySlot(targetId, {position: 'prepend'});\n}\n\nexport function prependTextSlot(targetId: string): MethodDecorator {\n return applySlot(targetId, {position: 'prependText'});\n}\n\nexport function appendHtmlSlot(targetId: string): MethodDecorator {\n return applySlot(targetId, {position: 'appendHtml'});\n}\n\nexport function appendTextSlot(targetId: string): MethodDecorator {\n return applySlot(targetId, {position: 'appendText'});\n}\n\nexport function appendSlot(targetId: string): MethodDecorator {\n return applySlot(targetId, {position: 'append'});\n}\n\nexport function replaceChildrenHtmlSlot(targetId: string): MethodDecorator {\n return applySlot(targetId, {position: 'replaceChildrenHtml'});\n}\n\nexport function replaceChildrenSlot(targetId: string): MethodDecorator {\n return applySlot(targetId, {position: 'replaceChildren'});\n}\n\nexport function replaceChildrenTextSlot(targetId: string): MethodDecorator {\n return applySlot(targetId, {position: 'replaceChildrenText'});\n}\n\n// export const findAllApplySlotMetadata = (target: any): Map<string | symbol, ApplySlotMetadata> => {\nexport const findAllApplySlotMetadata = (target: any): ApplySlotMetadata[] => {\n const constructor = target instanceof Function ? target : target.constructor;\n return ReflectUtils.getMetadata(APPLY_SLOT_METADATA_KEY, constructor);\n};"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAyC;AACzC,2BAA2C;AAC3C,mBAAuB;AACvB,sBAAuB;AAmChB,MAAM,0BAA0B,OAAO,IAAI,iCAAiC;AAyCnF,MAAM,aAAa,CAA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UAAU,UAAU,EAAC,UAAU,cAAa,CAAC;AACtD;AAEO,SAAS,eAAe,UAAmC;AAChE,SAAO,UAAU,UAAU,EAAC,UAAU,aAAY,CAAC;AACrD;AAEO,SAAS,eAAe,UAAmC;AAChE,SAAO,UAAU,UAAU,EAAC,UAAU,aAAY,CAAC;AACrD;AAEO,SAAS,WAAW,UAAmC;AAC5D,SAAO,UAAU,UAAU,EAAC,UAAU,SAAQ,CAAC;AACjD;AAEO,SAAS,wBAAwB,UAAmC;AACzE,SAAO,UAAU,UAAU,EAAC,UAAU,sBAAqB,CAAC;AAC9D;AAEO,SAAS,oBAAoB,UAAmC;AACrE,SAAO,UAAU,UAAU,EAAC,UAAU,kBAAiB,CAAC;AAC1D;AAEO,SAAS,wBAAwB,UAAmC;AACzE,SAAO,UAAU,UAAU,EAAC,UAAU,sBAAqB,CAAC;AAC9D;AAGO,MAAM,2BAA2B,CAAC,WAAqC;AAC5E,QAAM,cAAc,kBAAkB,WAAW,SAAS,OAAO;AACjE,SAAO,yBAAa,YAAY,yBAAyB,WAAW;AACtE;",
|
|
6
|
+
"names": ["res"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/decorators/changedAttributeThis.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 ChangedAttributeThisOptions
|
|
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 ChangedAttributeThisOptions {\n type?: typeof Number | typeof Boolean | typeof String;\n while?: 'connected';\n}\n\nexport interface ChangedAttributeThisMetadata {\n attributeName: string;\n propertyKey: string | symbol;\n options: ChangedAttributeThisOptions;\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 * @changedAttributeThis decorator - fires when any attribute on $this changes\n */\nexport function changedAttributeThis(attributeName?: string, options: ChangedAttributeThisOptions = {}): 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 ChangedAttributeThisMetadata[];\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): ChangedAttributeThisMetadata[] | 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, ChangedAttributeThisMetadata[]> => {\n const constructor = target instanceof Function ? target : target.constructor;\n const metaList = ReflectUtils.findAllMetadata<ChangedAttributeThisMetadata[]>(ON_ATTRIBUTE_CHANGED_METADATA_KEY, constructor) || [];\n\n const result = new Map<string, ChangedAttributeThisMetadata[]>();\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
5
|
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA6B;AAEtB,MAAM,oCAAoC,OAAO,IAAI,2CAA2C;AAavG,MAAM,eAAe,CA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@@ -29,7 +29,6 @@ var import_lifecycles = require("./lifecycles");
|
|
|
29
29
|
var import_emitCustomEvent = require("./emitCustomEvent");
|
|
30
30
|
var import_changedAttributeThis = require("./changedAttributeThis");
|
|
31
31
|
var import_applyAttribute = require("./applyAttribute");
|
|
32
|
-
var import_attribute = require("./attribute");
|
|
33
32
|
var import_query = require("./query");
|
|
34
33
|
var import_queryAll = require("./queryAll");
|
|
35
34
|
var import_Utils = require("../utils/Utils");
|
|
@@ -38,8 +37,8 @@ var import_Inject = require("@dooboostore/simple-boot/decorators/inject/Inject")
|
|
|
38
37
|
var import_types = require("../types");
|
|
39
38
|
var import_core_web = require("@dooboostore/core-web");
|
|
40
39
|
var import_SwcAppMixin = require("../elements/SwcAppMixin");
|
|
41
|
-
var import_applySlot = require("./applySlot");
|
|
42
40
|
var import_state = require("./state");
|
|
41
|
+
var import_applyProperty = require("./applyProperty");
|
|
43
42
|
const ELEMENT_CONFIG_KEY = Symbol.for("simple-web-component:element-config");
|
|
44
43
|
const getElementConfig = (target) => {
|
|
45
44
|
const constructor = target instanceof Function ? target : target.constructor;
|
|
@@ -52,13 +51,12 @@ const ensureInit = (inst) => {
|
|
|
52
51
|
inst._boundListeners = [];
|
|
53
52
|
inst.__swc_initialized = true;
|
|
54
53
|
const target = inst instanceof Function ? inst : inst.constructor;
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
});
|
|
54
|
+
const attributeAllList = (0, import_applyAttribute.findAllAttributeMetadata)(target).filter((it) => it.type === "property");
|
|
55
|
+
if (attributeAllList) {
|
|
56
|
+
attributeAllList.forEach((meta) => {
|
|
57
|
+
delete inst[meta.propertyKey];
|
|
58
|
+
});
|
|
59
|
+
}
|
|
62
60
|
const queryList = (0, import_query.getQueryMetadata)(target);
|
|
63
61
|
if (queryList) {
|
|
64
62
|
queryList.forEach((meta) => {
|
|
@@ -71,9 +69,9 @@ const ensureInit = (inst) => {
|
|
|
71
69
|
delete inst[meta.propertyKey];
|
|
72
70
|
});
|
|
73
71
|
}
|
|
74
|
-
const
|
|
75
|
-
if (
|
|
76
|
-
|
|
72
|
+
const propertyAllList = (0, import_applyProperty.findAllPropertyMetadata)(target).filter((it) => it.type === "property");
|
|
73
|
+
if (propertyAllList) {
|
|
74
|
+
propertyAllList.forEach((meta) => {
|
|
77
75
|
delete inst[meta.propertyKey];
|
|
78
76
|
});
|
|
79
77
|
}
|
|
@@ -130,24 +128,6 @@ const getHandlers = (inst) => {
|
|
|
130
128
|
const setupPrototype = (proto, win) => {
|
|
131
129
|
if (proto.__swc_proto_setup) return;
|
|
132
130
|
proto.__swc_proto_setup = true;
|
|
133
|
-
proto.createSlotString = function(id) {
|
|
134
|
-
return import_core_web.NodeSlot.slot(`${this._swcId}-${id}`);
|
|
135
|
-
};
|
|
136
|
-
proto.createEaHtml = function(id, script) {
|
|
137
|
-
return import_core_web.ElementApply.html(id, script);
|
|
138
|
-
};
|
|
139
|
-
proto.createEaText = function(id, script) {
|
|
140
|
-
return import_core_web.ElementApply.text(id, script);
|
|
141
|
-
};
|
|
142
|
-
proto.createEaAttribute = function(id, name, script) {
|
|
143
|
-
return import_core_web.ElementApply.attribute(id, name, script);
|
|
144
|
-
};
|
|
145
|
-
proto.createEaEvent = function(id, name, script) {
|
|
146
|
-
return import_core_web.ElementApply.event(id, name, script);
|
|
147
|
-
};
|
|
148
|
-
proto.createEaProperty = function(id, name, script) {
|
|
149
|
-
return import_core_web.ElementApply.property(id, name, script);
|
|
150
|
-
};
|
|
151
131
|
proto._executeSwcScript = function(attrName, hostSet, extraArgs = {}) {
|
|
152
132
|
ensureInit(this);
|
|
153
133
|
const script = this.getAttribute(attrName);
|
|
@@ -273,12 +253,12 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
273
253
|
const emitHostCustomEventList = emitCustomEventList.filter((meta) => meta.selector === "$this" || meta.selector === "");
|
|
274
254
|
const addEventListenerList = (0, import_addEventListener.getAddEventListenerMetadata)(constructor) || [];
|
|
275
255
|
const attrChangeMap = (0, import_changedAttributeThis.findAllAttributeChangedMetadata)(constructor);
|
|
276
|
-
const attributeList = (0,
|
|
256
|
+
const attributeList = (0, import_applyAttribute.findAllAttributeMetadata)(constructor);
|
|
277
257
|
const applyAttributeMap = (0, import_applyAttribute.findAllAttributeApplyMetadata)(constructor);
|
|
278
258
|
const swcLifecycleAttributes = ["swc-on-constructor", "swc-on-connected", "swc-on-disconnected", "swc-on-before-connected", "swc-on-after-connected", "swc-on-before-disconnected", "swc-on-after-disconnected", "swc-on-before-adopted", "swc-on-after-adopted", "swc-on-attribute-changed"];
|
|
279
259
|
const swcOnEvents = import_config.DOM_EVENT_NAMES.map((e) => `swc-on-${e}`);
|
|
280
|
-
const attributeApplyNames = Array.from(applyAttributeMap.values()).map((it) => it.
|
|
281
|
-
const hostAttributes = attributeList.filter((it) => it.selector === "$this").map((it) => it.
|
|
260
|
+
const attributeApplyNames = Array.from(applyAttributeMap.values()).map((it) => it.targetAttributeName).filter(Boolean);
|
|
261
|
+
const hostAttributes = attributeList.filter((it) => it.selector === "$this").map((it) => it.propertyKey || String(it.propertyKey));
|
|
282
262
|
const originalStaticObservedAttributes = constructor.observedAttributes ?? [];
|
|
283
263
|
const mergedObservedAttributes = [.../* @__PURE__ */ new Set([...metadata.observedAttributes ?? [], ...originalStaticObservedAttributes, ...attrChangeMap.keys(), ...attributeApplyNames, ...hostAttributes, ...emitHostCustomEventList.map((it) => it.options.attributeName).filter(Boolean), ...swcLifecycleAttributes, ...swcOnEvents])];
|
|
284
264
|
const proto = constructor.prototype;
|
|
@@ -490,7 +470,7 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
490
470
|
for (let [name2, metaList] of Array.from(attrChangeMap)) {
|
|
491
471
|
for (const meta of metaList) {
|
|
492
472
|
if (meta.options.while === "connected") {
|
|
493
|
-
const val = (0,
|
|
473
|
+
const val = (0, import_applyAttribute.getAttributeValue)(this, name2, { type: meta.options.type });
|
|
494
474
|
if (val !== null) {
|
|
495
475
|
await this[meta.propertyKey](val, null, name2, helperHostSet);
|
|
496
476
|
}
|