@dooboostore/simple-web-component 1.0.42 → 1.0.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +689 -85
- package/dist/cjs/SwcAppEngine.js +3 -1
- package/dist/cjs/SwcAppEngine.js.map +2 -2
- package/dist/cjs/decorators/addEventListener.js +10 -0
- package/dist/cjs/decorators/addEventListener.js.map +2 -2
- package/dist/cjs/decorators/applyAttribute.js +41 -30
- package/dist/cjs/decorators/applyAttribute.js.map +2 -2
- package/dist/cjs/decorators/applyClass.js +66 -23
- package/dist/cjs/decorators/applyClass.js.map +3 -3
- package/dist/cjs/decorators/applyNode.js +176 -107
- package/dist/cjs/decorators/applyNode.js.map +2 -2
- package/dist/cjs/decorators/applyProperty.js +21 -30
- package/dist/cjs/decorators/applyProperty.js.map +2 -2
- package/dist/cjs/decorators/applySlot.js +11 -2
- package/dist/cjs/decorators/applySlot.js.map +2 -2
- package/dist/cjs/decorators/applyStyle.js +48 -17
- package/dist/cjs/decorators/applyStyle.js.map +3 -3
- package/dist/cjs/decorators/{changedAttributeThis.js → changedAttribute.js} +6 -6
- package/dist/cjs/decorators/changedAttribute.js.map +7 -0
- package/dist/cjs/decorators/elementDefine.js +37 -6
- package/dist/cjs/decorators/elementDefine.js.map +3 -3
- package/dist/cjs/decorators/emitCustomEvent.js +58 -42
- package/dist/cjs/decorators/emitCustomEvent.js.map +2 -2
- package/dist/cjs/decorators/index.js +1 -1
- package/dist/cjs/decorators/index.js.map +2 -2
- package/dist/cjs/decorators/publishSwcAppMessage.js +37 -23
- package/dist/cjs/decorators/publishSwcAppMessage.js.map +3 -3
- package/dist/cjs/decorators/query.js +96 -145
- package/dist/cjs/decorators/query.js.map +3 -3
- package/dist/cjs/decorators/queryAll.js +104 -131
- package/dist/cjs/decorators/queryAll.js.map +3 -3
- package/dist/cjs/decorators/subscribeSwcAppMessageWhileConnected.js +2 -0
- package/dist/cjs/decorators/subscribeSwcAppMessageWhileConnected.js.map +2 -2
- package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js +2 -0
- package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
- package/dist/cjs/elements/SwcAppMixin.js +17 -2
- package/dist/cjs/elements/SwcAppMixin.js.map +2 -2
- package/dist/cjs/examples/RxJSOperatorsExample.js +285 -0
- package/dist/cjs/examples/RxJSOperatorsExample.js.map +7 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/router/ElementRouter.js +4 -0
- package/dist/cjs/router/ElementRouter.js.map +2 -2
- package/dist/esm/SwcAppEngine.js +3 -1
- package/dist/esm/SwcAppEngine.js.map +2 -2
- package/dist/esm/decorators/addEventListener.js +10 -0
- package/dist/esm/decorators/addEventListener.js.map +2 -2
- package/dist/esm/decorators/applyAttribute.js +41 -30
- package/dist/esm/decorators/applyAttribute.js.map +2 -2
- package/dist/esm/decorators/applyClass.js +66 -23
- package/dist/esm/decorators/applyClass.js.map +3 -3
- package/dist/esm/decorators/applyNode.js +176 -107
- package/dist/esm/decorators/applyNode.js.map +2 -2
- package/dist/esm/decorators/applyProperty.js +21 -30
- package/dist/esm/decorators/applyProperty.js.map +2 -2
- package/dist/esm/decorators/applySlot.js +11 -2
- package/dist/esm/decorators/applySlot.js.map +2 -2
- package/dist/esm/decorators/applyStyle.js +48 -17
- package/dist/esm/decorators/applyStyle.js.map +3 -3
- package/dist/esm/decorators/{changedAttributeThis.js → changedAttribute.js} +3 -3
- package/dist/esm/decorators/changedAttribute.js.map +7 -0
- package/dist/esm/decorators/elementDefine.js +35 -4
- package/dist/esm/decorators/elementDefine.js.map +2 -2
- package/dist/esm/decorators/emitCustomEvent.js +58 -42
- package/dist/esm/decorators/emitCustomEvent.js.map +2 -2
- package/dist/esm/decorators/index.js +1 -1
- package/dist/esm/decorators/index.js.map +1 -1
- package/dist/esm/decorators/publishSwcAppMessage.js +37 -23
- package/dist/esm/decorators/publishSwcAppMessage.js.map +3 -3
- package/dist/esm/decorators/query.js +96 -145
- package/dist/esm/decorators/query.js.map +3 -3
- package/dist/esm/decorators/queryAll.js +104 -131
- package/dist/esm/decorators/queryAll.js.map +3 -3
- package/dist/esm/decorators/subscribeSwcAppMessageWhileConnected.js +2 -0
- package/dist/esm/decorators/subscribeSwcAppMessageWhileConnected.js.map +2 -2
- package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js +2 -0
- package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
- package/dist/esm/elements/SwcAppMixin.js +18 -3
- package/dist/esm/elements/SwcAppMixin.js.map +2 -2
- package/dist/esm/examples/RxJSOperatorsExample.js +266 -0
- package/dist/esm/examples/RxJSOperatorsExample.js.map +7 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/router/ElementRouter.js +4 -0
- package/dist/esm/router/ElementRouter.js.map +2 -2
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +900 -578
- 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/addEventListener.d.ts +22 -14
- package/dist/types/decorators/addEventListener.d.ts.map +1 -1
- package/dist/types/decorators/applyAttribute.d.ts +61 -20
- package/dist/types/decorators/applyAttribute.d.ts.map +1 -1
- package/dist/types/decorators/applyClass.d.ts +22 -36
- package/dist/types/decorators/applyClass.d.ts.map +1 -1
- package/dist/types/decorators/applyNode.d.ts +178 -30
- package/dist/types/decorators/applyNode.d.ts.map +1 -1
- package/dist/types/decorators/applyProperty.d.ts +53 -18
- package/dist/types/decorators/applyProperty.d.ts.map +1 -1
- package/dist/types/decorators/applySlot.d.ts +6 -0
- package/dist/types/decorators/applySlot.d.ts.map +1 -1
- package/dist/types/decorators/applyStyle.d.ts +13 -7
- package/dist/types/decorators/applyStyle.d.ts.map +1 -1
- package/dist/types/decorators/{changedAttributeThis.d.ts → changedAttribute.d.ts} +2 -2
- package/dist/types/decorators/changedAttribute.d.ts.map +1 -0
- package/dist/types/decorators/elementDefine.d.ts.map +1 -1
- package/dist/types/decorators/emitCustomEvent.d.ts +20 -10
- package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
- package/dist/types/decorators/index.d.ts +1 -1
- package/dist/types/decorators/index.d.ts.map +1 -1
- package/dist/types/decorators/publishSwcAppMessage.d.ts +19 -0
- package/dist/types/decorators/publishSwcAppMessage.d.ts.map +1 -1
- package/dist/types/decorators/query.d.ts +3 -26
- package/dist/types/decorators/query.d.ts.map +1 -1
- package/dist/types/decorators/queryAll.d.ts +3 -20
- package/dist/types/decorators/queryAll.d.ts.map +1 -1
- package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts +1 -0
- package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts.map +1 -1
- package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts +2 -0
- package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts.map +1 -1
- package/dist/types/elements/SwcAppMixin.d.ts +4 -4
- package/dist/types/elements/SwcAppMixin.d.ts.map +1 -1
- package/dist/types/examples/RxJSOperatorsExample.d.ts +94 -0
- package/dist/types/examples/RxJSOperatorsExample.d.ts.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/router/ElementRouter.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +900 -578
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +7 -9
- package/src/SwcAppEngine.ts +3 -1
- package/src/decorators/addEventListener.ts +35 -24
- package/src/decorators/applyAttribute.ts +167 -65
- package/src/decorators/applyClass.ts +113 -17
- package/src/decorators/applyNode.ts +383 -102
- package/src/decorators/applyProperty.ts +99 -65
- package/src/decorators/applySlot.ts +24 -10
- package/src/decorators/applyStyle.ts +83 -13
- package/src/decorators/{changedAttributeThis.ts → changedAttribute.ts} +1 -1
- package/src/decorators/elementDefine.ts +47 -4
- package/src/decorators/emitCustomEvent.ts +62 -35
- package/src/decorators/index.ts +1 -1
- package/src/decorators/publishSwcAppMessage.ts +71 -27
- package/src/decorators/query.ts +90 -159
- package/src/decorators/queryAll.ts +92 -134
- package/src/decorators/subscribeSwcAppMessageWhileConnected.ts +1 -0
- package/src/decorators/subscribeSwcAppRouteChangeWhileConnected.ts +3 -1
- package/src/elements/SwcAppMixin.ts +43 -24
- package/src/examples/RxJSOperatorsExample.ts +279 -0
- package/src/index.ts +2 -0
- package/src/router/ElementRouter.ts +4 -0
- package/dist/cjs/decorators/changedAttributeThis.js.map +0 -7
- package/dist/esm/decorators/changedAttributeThis.js.map +0 -7
- package/dist/types/decorators/changedAttributeThis.d.ts.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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
|
|
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 * Custom key to extract value from return object.\n * If not provided, uses PROPERTY_METADATA_KEY by default.\n * Useful when multiple @setProperty decorators are on the same method.\n * \n * Example:\n * @setProperty('selector1', { valueKey: 'prop1' })\n * @setProperty('selector2', { valueKey: 'prop2' })\n * myMethod() {\n * return {\n * prop1: 'value1',\n * prop2: 'value2'\n * };\n * }\n * \n * Or with symbols:\n * @setProperty('selector1', { valueKey: Symbol.for('prop1') })\n * @setProperty('selector2', { valueKey: Symbol.for('prop2') })\n * myMethod() {\n * return {\n * [Symbol.for('prop1')]: 'value1',\n * [Symbol.for('prop2')]: 'value2'\n * };\n * }\n */\n valueKey?: symbol | string;\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 /**\n * Extract value for this decorator from method return value\n * \n * If return value is an object with this decorator's symbol key,\n * use that value. Otherwise use the entire return value.\n * \n * Example:\n * @setProperty('selector')\n * myMethod() {\n * return {\n * [PROPERTY_METADATA_KEY]: 'property-value',\n * [OTHER_DECORATOR_KEY]: 'other-value'\n * };\n * }\n * \n * This decorator will use 'property-value'\n */\n const extractValue = (v: any) => {\n if (v && typeof v === 'object' && PROPERTY_METADATA_KEY in v) {\n return v[PROPERTY_METADATA_KEY];\n }\n return v;\n };\n\n if (res instanceof Promise) {\n return res.then((v: any) => { \n const extracted = extractValue(v);\n applyValueToTargets(this, extracted); \n return v; \n });\n } else {\n const extracted = extractValue(res);\n applyValueToTargets(this, extracted);\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 - Field decorator for binding element properties (read/write)\n * \n * Usage:\n * - @property('selector', 'propertyName') - Bind to specific property\n * - @property('selector') - Use field name as property name\n * - @property('selector', options) - Bind with options\n * - @property - Bare decorator (binds to $this with field name)\n * \n * Note: This decorator is for FIELDS ONLY. For methods, use @setProperty.\n */\nexport function property(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;\nexport function property(selector: string, targetPropertyKey: string | symbol, options?: PropertyOptions): PropertyDecorator;\nexport function property(selector: string, options?: PropertyOptions): PropertyDecorator;\nexport function property(selectorOrTarget?: string | Object, targetPropertyKeyOrOptions?: any, optionsOrDescriptor?: any): any {\n // Bare decorator: @property\n if (optionsOrDescriptor !== undefined && (typeof targetPropertyKeyOrOptions === 'string' || typeof targetPropertyKeyOrOptions === 'symbol')) {\n return applyProperty('$this', undefined as any, {})(selectorOrTarget as Object, targetPropertyKeyOrOptions, optionsOrDescriptor as PropertyDescriptor);\n }\n // With selector\n if (typeof selectorOrTarget === 'string') {\n return applyProperty(selectorOrTarget, targetPropertyKeyOrOptions as any, optionsOrDescriptor as PropertyOptions);\n }\n // Without selector (defaults to $this)\n return applyProperty('$this', undefined as any, selectorOrTarget as PropertyOptions);\n}\n\n/**\n * @setProperty - Method decorator for setting element properties from method return value\n * \n * Usage:\n * - @setProperty('selector', 'propertyName') - Set specific property\n * - @setProperty('selector') - Use method name as property name\n * - @setProperty('selector', options) - Set with options\n * - @setProperty - Bare decorator (sets on $this with method name)\n * \n * Note: This decorator is for METHODS ONLY. For fields, use @property.\n * \n * Example:\n * @setProperty('selector', 'disabled')\n * disableElement() {\n * return true;\n * }\n */\nexport function setProperty(selector: string, targetPropertyKey: string | symbol, options?: PropertyOptions): MethodDecorator;\nexport function setProperty(selector: string, options?: PropertyOptions): MethodDecorator;\nexport function setProperty(selectorOrOptions?: string | PropertyOptions, targetPropertyKeyOrOptions?: any, optionsOrUndefined?: PropertyOptions): MethodDecorator {\n // With selector\n if (typeof selectorOrOptions === 'string') {\n return applyProperty(selectorOrOptions, targetPropertyKeyOrOptions as any, optionsOrUndefined as PropertyOptions) as MethodDecorator;\n }\n // Without selector (defaults to $this)\n return applyProperty('$this', undefined as any, selectorOrOptions as PropertyOptions) as MethodDecorator;\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;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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
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -89,15 +89,24 @@ function applySlot(targetId, opt) {
|
|
|
89
89
|
fallbackNodes.push(...nodes);
|
|
90
90
|
applyToDom(swcId, targetId, options.position, nodes);
|
|
91
91
|
}
|
|
92
|
+
const extractValue = (v) => {
|
|
93
|
+
const keyToUse = options.valueKey ?? APPLY_SLOT_METADATA_KEY;
|
|
94
|
+
if (v && typeof v === "object" && keyToUse in v) {
|
|
95
|
+
return v[keyToUse];
|
|
96
|
+
}
|
|
97
|
+
return v;
|
|
98
|
+
};
|
|
92
99
|
let res = original.apply(this, args);
|
|
93
100
|
if (res instanceof Promise) {
|
|
94
101
|
return res.then((asyncRes) => {
|
|
95
|
-
const
|
|
102
|
+
const extracted = extractValue(asyncRes);
|
|
103
|
+
const nodes = resToNodes(extracted);
|
|
96
104
|
fallbackNodes.forEach((it) => it.remove());
|
|
97
105
|
applyToDom(swcId, targetId, options.position, nodes);
|
|
98
106
|
});
|
|
99
107
|
} else {
|
|
100
|
-
const
|
|
108
|
+
const extracted = extractValue(res);
|
|
109
|
+
const nodes = resToNodes(extracted);
|
|
101
110
|
applyToDom(swcId, targetId, options.position, nodes);
|
|
102
111
|
}
|
|
103
112
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/decorators/applySlot.ts"],
|
|
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
|
|
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;
|
|
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 /**\n * Custom key to extract value from return object.\n * If not provided, uses APPLY_SLOT_METADATA_KEY by default.\n * Useful when multiple @applySlot decorators are on the same method.\n */\n valueKey?: symbol | string;\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 /**\n * Extract value for this decorator from method return value\n * \n * If return value is an object with this decorator's key,\n * use that value. Otherwise use the entire return value.\n * \n * Uses valueKey from options if provided, otherwise uses APPLY_SLOT_METADATA_KEY.\n */\n const extractValue = (v: any) => {\n const keyToUse = options.valueKey ?? APPLY_SLOT_METADATA_KEY;\n if (v && typeof v === 'object' && keyToUse in v) {\n return v[keyToUse];\n }\n return v;\n };\n\n let res = original.apply(this, args);\n if (res instanceof Promise) {\n return res.then(asyncRes => {\n const extracted = extractValue(asyncRes);\n const nodes = resToNodes(extracted)\n fallbackNodes.forEach((it: any) => it.remove());\n applyToDom(swcId, targetId, options.position, nodes);\n })\n } else {\n const extracted = extractValue(res);\n const nodes: Node[] = resToNodes(extracted);\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;AA+BhB,MAAM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;AACF;AAEO,SAAS,UAAU,UAAmC;AAC3D,SAAO,UAAU,UAAU,EAAC,UAAU,QAAO,CAAC;AAChD;AAEO,SAAS,gBAAgB,UAAmC;AACjE,SAAO,UAAU,UAAU,EAAC,UAAU,cAAa,CAAC;AACtD;AAEO,SAAS,YAAY,UAAmC;AAC7D,SAAO,UAAU,UAAU,EAAC,UAAU,UAAS,CAAC;AAClD;AAEO,SAAS,gBAAgB,UAAmC;AACjE,SAAO,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
6
|
"names": ["res"]
|
|
7
7
|
}
|
|
@@ -19,14 +19,10 @@ var applyStyle_exports = {};
|
|
|
19
19
|
__export(applyStyle_exports, {
|
|
20
20
|
STYLE_METADATA_KEY: () => STYLE_METADATA_KEY,
|
|
21
21
|
applyStyle: () => applyStyle,
|
|
22
|
-
applyStyleThis: () => applyStyleThis,
|
|
23
22
|
findAllStyleMetadata: () => findAllStyleMetadata,
|
|
24
23
|
removeStyle: () => removeStyle,
|
|
25
|
-
removeStyleThis: () => removeStyleThis,
|
|
26
24
|
setStyle: () => setStyle,
|
|
27
|
-
|
|
28
|
-
updateStyle: () => updateStyle,
|
|
29
|
-
updateStyleThis: () => updateStyleThis
|
|
25
|
+
updateStyle: () => updateStyle
|
|
30
26
|
});
|
|
31
27
|
module.exports = __toCommonJS(applyStyle_exports);
|
|
32
28
|
var import_core = require("@dooboostore/core");
|
|
@@ -47,6 +43,13 @@ function createStyleDecorator(action) {
|
|
|
47
43
|
descriptor.value = function(...args) {
|
|
48
44
|
(0, import_elementDefine.ensureInit)(this);
|
|
49
45
|
const res = original.apply(this, args);
|
|
46
|
+
const extractValue = (v) => {
|
|
47
|
+
const keyToUse = options.valueKey ?? STYLE_METADATA_KEY;
|
|
48
|
+
if (v && typeof v === "object" && keyToUse in v) {
|
|
49
|
+
return v[keyToUse];
|
|
50
|
+
}
|
|
51
|
+
return v;
|
|
52
|
+
};
|
|
50
53
|
const handleResult = (resolvedValue) => {
|
|
51
54
|
if (resolvedValue !== void 0) {
|
|
52
55
|
const win = this.ownerDocument?.defaultView || window;
|
|
@@ -112,27 +115,55 @@ function createStyleDecorator(action) {
|
|
|
112
115
|
return resolvedValue;
|
|
113
116
|
};
|
|
114
117
|
if (res instanceof Promise) {
|
|
115
|
-
return res.then(handleResult);
|
|
118
|
+
return res.then((v) => handleResult(extractValue(v)));
|
|
116
119
|
} else {
|
|
117
|
-
return handleResult(res);
|
|
120
|
+
return handleResult(extractValue(res));
|
|
118
121
|
}
|
|
119
122
|
};
|
|
120
123
|
return descriptor;
|
|
121
124
|
};
|
|
122
125
|
};
|
|
123
126
|
}
|
|
124
|
-
function applyStyle(
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const
|
|
130
|
-
|
|
127
|
+
function applyStyle(selectorOrTarget, actionOrPropertyKey, optionsOrDescriptor) {
|
|
128
|
+
if (optionsOrDescriptor !== void 0 && (typeof actionOrPropertyKey === "string" || typeof actionOrPropertyKey === "symbol")) {
|
|
129
|
+
return createStyleDecorator("update")("$this", {})(selectorOrTarget, actionOrPropertyKey, optionsOrDescriptor);
|
|
130
|
+
}
|
|
131
|
+
if (typeof selectorOrTarget === "string") {
|
|
132
|
+
const action2 = typeof actionOrPropertyKey === "string" ? actionOrPropertyKey : "update";
|
|
133
|
+
const options2 = typeof actionOrPropertyKey === "object" ? actionOrPropertyKey : optionsOrDescriptor;
|
|
134
|
+
return createStyleDecorator(action2)(selectorOrTarget, options2);
|
|
135
|
+
}
|
|
136
|
+
const action = typeof selectorOrTarget === "string" ? selectorOrTarget : "update";
|
|
137
|
+
const options = typeof selectorOrTarget === "object" ? selectorOrTarget : actionOrPropertyKey;
|
|
131
138
|
return createStyleDecorator(action)("$this", options);
|
|
132
139
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
140
|
+
function setStyle(selectorOrTarget, optionsOrPropertyKey, descriptor) {
|
|
141
|
+
if (descriptor !== void 0 && (typeof optionsOrPropertyKey === "string" || typeof optionsOrPropertyKey === "symbol")) {
|
|
142
|
+
return createStyleDecorator("set")("$this", {})(selectorOrTarget, optionsOrPropertyKey, descriptor);
|
|
143
|
+
}
|
|
144
|
+
if (typeof selectorOrTarget === "string") {
|
|
145
|
+
return createStyleDecorator("set")(selectorOrTarget, optionsOrPropertyKey);
|
|
146
|
+
}
|
|
147
|
+
return createStyleDecorator("set")("$this", selectorOrTarget);
|
|
148
|
+
}
|
|
149
|
+
function updateStyle(selectorOrTarget, optionsOrPropertyKey, descriptor) {
|
|
150
|
+
if (descriptor !== void 0 && (typeof optionsOrPropertyKey === "string" || typeof optionsOrPropertyKey === "symbol")) {
|
|
151
|
+
return createStyleDecorator("update")("$this", {})(selectorOrTarget, optionsOrPropertyKey, descriptor);
|
|
152
|
+
}
|
|
153
|
+
if (typeof selectorOrTarget === "string") {
|
|
154
|
+
return createStyleDecorator("update")(selectorOrTarget, optionsOrPropertyKey);
|
|
155
|
+
}
|
|
156
|
+
return createStyleDecorator("update")("$this", selectorOrTarget);
|
|
157
|
+
}
|
|
158
|
+
function removeStyle(selectorOrTarget, optionsOrPropertyKey, descriptor) {
|
|
159
|
+
if (descriptor !== void 0 && (typeof optionsOrPropertyKey === "string" || typeof optionsOrPropertyKey === "symbol")) {
|
|
160
|
+
return createStyleDecorator("remove")("$this", {})(selectorOrTarget, optionsOrPropertyKey, descriptor);
|
|
161
|
+
}
|
|
162
|
+
if (typeof selectorOrTarget === "string") {
|
|
163
|
+
return createStyleDecorator("remove")(selectorOrTarget, optionsOrPropertyKey);
|
|
164
|
+
}
|
|
165
|
+
return createStyleDecorator("remove")("$this", selectorOrTarget);
|
|
166
|
+
}
|
|
136
167
|
const findAllStyleMetadata = (target) => {
|
|
137
168
|
const result = /* @__PURE__ */ new Map();
|
|
138
169
|
const maps = import_core.ReflectUtils.findAllMetadata(STYLE_METADATA_KEY, target);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/decorators/applyStyle.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 type StyleAction = 'set' | 'update' | 'remove';\n\nexport interface StyleApplyOptions extends SwcQueryOptions {\n filter?: (target: HTMLElement, value: any, meta: {currentThis: any, helper: HelperHostSet}) => boolean;\n}\n\nexport interface StyleApplyMetadata {\n propertyKey: string | symbol;\n selector: string;\n action: StyleAction;\n options: StyleApplyOptions;\n}\n\nexport const STYLE_METADATA_KEY = Symbol.for('simple-web-component:style');\n\nfunction createStyleDecorator(action: StyleAction) {\n return (selector: string, options: StyleApplyOptions = {}): MethodDecorator => {\n return (target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n const constructor = target.constructor;\n let metaList = ReflectUtils.getOwnMetadata(STYLE_METADATA_KEY, constructor) as Map<string | symbol, StyleApplyMetadata>;\n if (!metaList) {\n metaList = new Map<string | symbol, StyleApplyMetadata>();\n ReflectUtils.defineMetadata(STYLE_METADATA_KEY, metaList, constructor);\n }\n metaList.set(propertyKey, { propertyKey, selector, action, options });\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 = options.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 (options.filter && !options.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 (action === 'set' || action === 'update') {\n if (action === 'set') targetEl.style.cssText = '';\n \n if (typeof resolvedRes === 'object' && resolvedRes !== null && !Array.isArray(resolvedRes)) {\n Object.entries(resolvedRes as any).forEach(([prop, val]) => {\n const finalVal = typeof val === 'function' ? val(targetEl, hostSet) : val;\n if (finalVal === null || finalVal === undefined) {\n targetEl.style.removeProperty(prop);\n } else {\n targetEl.style[prop as any] = String(finalVal);\n }\n });\n } else if (typeof resolvedRes === 'string') {\n targetEl.style.cssText = resolvedRes;\n }\n } else if (action === 'remove') {\n if (typeof resolvedRes === 'object' && resolvedRes !== null && !Array.isArray(resolvedRes)) {\n Object.entries(resolvedRes as any).forEach(([prop, val]) => {\n const shouldRemove = typeof val === 'function' ? val(targetEl, hostSet) : !!val;\n if (shouldRemove) {\n targetEl.style.removeProperty(prop);\n }\n });\n } else {\n const props = Array.isArray(resolvedRes) ? resolvedRes : [resolvedRes];\n props.forEach(p => targetEl.style.removeProperty(String(p)));\n }\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 return descriptor;\n };\n };\n}\n\nexport function applyStyle(selector: string, action: StyleAction = 'update', options: StyleApplyOptions = {}): MethodDecorator {\n return createStyleDecorator(action)(selector, options);\n}\n\nexport const setStyle = (selector: string, options: StyleApplyOptions = {}) => createStyleDecorator('set')(selector, options);\nexport const updateStyle = (selector: string, options: StyleApplyOptions = {}) => createStyleDecorator('update')(selector, options);\nexport const removeStyle = (selector: string, options: StyleApplyOptions = {}) => createStyleDecorator('remove')(selector, options);\n\n// This versions\nexport function applyStyleThis(action: StyleAction = 'update', options: StyleApplyOptions = {}): MethodDecorator {\n return createStyleDecorator(action)('$this', options);\n}\nexport const setStyleThis = (options: StyleApplyOptions = {}) => createStyleDecorator('set')('$this', options);\nexport const updateStyleThis = (options: StyleApplyOptions = {}) => createStyleDecorator('update')('$this', options);\nexport const removeStyleThis = (options: StyleApplyOptions = {}) => createStyleDecorator('remove')('$this', options);\n\nexport const findAllStyleMetadata = (target: any): Map<string | symbol, StyleApplyMetadata> => {\n const result = new Map<string | symbol, StyleApplyMetadata>();\n const maps = ReflectUtils.findAllMetadata<Map<string | symbol, StyleApplyMetadata>>(STYLE_METADATA_KEY, target);\n maps.forEach(map => {\n if (map instanceof Map) {\n map.forEach((v, k) => result.set(k, v));\n }\n });\n return result;\n};\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA
|
|
6
|
-
"names": []
|
|
4
|
+
"sourcesContent": ["import {ReflectUtils} from '@dooboostore/core';\nimport {ensureInit} from './elementDefine';\nimport {SwcUtils} from '../utils/Utils';\nimport { SpecialSelector, SwcQueryOptions, HelperHostSet } from '../types';\n\nexport type StyleAction = 'set' | 'update' | 'remove';\n\nexport interface StyleApplyOptions extends SwcQueryOptions {\n filter?: (target: HTMLElement, value: any, meta: {currentThis: any, helper: HelperHostSet}) => boolean;\n /**\n * Custom key to extract value from return object.\n * If not provided, uses STYLE_METADATA_KEY by default.\n * Useful when multiple @applyStyle decorators are on the same method.\n */\n valueKey?: symbol | string;\n}\n\nexport interface StyleApplyMetadata {\n propertyKey: string | symbol;\n selector: string;\n action: StyleAction;\n options: StyleApplyOptions;\n}\n\nexport const STYLE_METADATA_KEY = Symbol.for('simple-web-component:style');\n\nfunction createStyleDecorator(action: StyleAction) {\n return (selector: string, options: StyleApplyOptions = {}): MethodDecorator => {\n return (target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n const constructor = target.constructor;\n let metaList = ReflectUtils.getOwnMetadata(STYLE_METADATA_KEY, constructor) as Map<string | symbol, StyleApplyMetadata>;\n if (!metaList) {\n metaList = new Map<string | symbol, StyleApplyMetadata>();\n ReflectUtils.defineMetadata(STYLE_METADATA_KEY, metaList, constructor);\n }\n metaList.set(propertyKey, { propertyKey, selector, action, options });\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 /**\n * Extract value for this decorator from method return value\n * \n * If return value is an object with this decorator's key,\n * use that value. Otherwise use the entire return value.\n * \n * Uses valueKey from options if provided, otherwise uses STYLE_METADATA_KEY.\n */\n const extractValue = (v: any) => {\n const keyToUse = options.valueKey ?? STYLE_METADATA_KEY;\n if (v && typeof v === 'object' && keyToUse in v) {\n return v[keyToUse];\n }\n return v;\n };\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 = options.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 (options.filter && !options.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 (action === 'set' || action === 'update') {\n if (action === 'set') targetEl.style.cssText = '';\n \n if (typeof resolvedRes === 'object' && resolvedRes !== null && !Array.isArray(resolvedRes)) {\n Object.entries(resolvedRes as any).forEach(([prop, val]) => {\n const finalVal = typeof val === 'function' ? val(targetEl, hostSet) : val;\n if (finalVal === null || finalVal === undefined) {\n targetEl.style.removeProperty(prop);\n } else {\n targetEl.style[prop as any] = String(finalVal);\n }\n });\n } else if (typeof resolvedRes === 'string') {\n targetEl.style.cssText = resolvedRes;\n }\n } else if (action === 'remove') {\n if (typeof resolvedRes === 'object' && resolvedRes !== null && !Array.isArray(resolvedRes)) {\n Object.entries(resolvedRes as any).forEach(([prop, val]) => {\n const shouldRemove = typeof val === 'function' ? val(targetEl, hostSet) : !!val;\n if (shouldRemove) {\n targetEl.style.removeProperty(prop);\n }\n });\n } else {\n const props = Array.isArray(resolvedRes) ? resolvedRes : [resolvedRes];\n props.forEach(p => targetEl.style.removeProperty(String(p)));\n }\n }\n });\n }\n return resolvedValue;\n };\n\n if (res instanceof Promise) {\n return res.then((v: any) => handleResult(extractValue(v)));\n } else {\n return handleResult(extractValue(res));\n }\n };\n return descriptor;\n };\n };\n}\n\nexport function applyStyle(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;\nexport function applyStyle(selector: string, action?: StyleAction, options?: StyleApplyOptions): MethodDecorator;\nexport function applyStyle(selectorOrTarget?: any, actionOrPropertyKey?: any, optionsOrDescriptor?: any): any {\n // Bare decorator: @applyStyle\n if (optionsOrDescriptor !== undefined && (typeof actionOrPropertyKey === 'string' || typeof actionOrPropertyKey === 'symbol')) {\n return createStyleDecorator('update')('$this', {})(selectorOrTarget as Object, actionOrPropertyKey, optionsOrDescriptor as PropertyDescriptor);\n }\n // With selector\n if (typeof selectorOrTarget === 'string') {\n const action = (typeof actionOrPropertyKey === 'string' ? actionOrPropertyKey : 'update') as StyleAction;\n const options = (typeof actionOrPropertyKey === 'object' ? actionOrPropertyKey : optionsOrDescriptor) as StyleApplyOptions | undefined;\n return createStyleDecorator(action)(selectorOrTarget, options);\n }\n // Without selector (defaults to $this)\n const action = (typeof selectorOrTarget === 'string' ? selectorOrTarget : 'update') as StyleAction;\n const options = (typeof selectorOrTarget === 'object' ? selectorOrTarget : actionOrPropertyKey) as StyleApplyOptions | undefined;\n return createStyleDecorator(action)('$this', options);\n}\n\nexport function setStyle(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;\nexport function setStyle(selector: string, options?: StyleApplyOptions): MethodDecorator;\nexport function setStyle(selectorOrTarget?: any, optionsOrPropertyKey?: any, descriptor?: any): any {\n // Bare decorator: @setStyle\n if (descriptor !== undefined && (typeof optionsOrPropertyKey === 'string' || typeof optionsOrPropertyKey === 'symbol')) {\n return createStyleDecorator('set')('$this', {})(selectorOrTarget as Object, optionsOrPropertyKey, descriptor as PropertyDescriptor);\n }\n // With selector\n if (typeof selectorOrTarget === 'string') {\n return createStyleDecorator('set')(selectorOrTarget, optionsOrPropertyKey as StyleApplyOptions);\n }\n // Without selector (defaults to $this)\n return createStyleDecorator('set')('$this', selectorOrTarget as StyleApplyOptions);\n}\n\nexport function updateStyle(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;\nexport function updateStyle(selector: string, options?: StyleApplyOptions): MethodDecorator;\nexport function updateStyle(selectorOrTarget?: any, optionsOrPropertyKey?: any, descriptor?: any): any {\n // Bare decorator: @updateStyle\n if (descriptor !== undefined && (typeof optionsOrPropertyKey === 'string' || typeof optionsOrPropertyKey === 'symbol')) {\n return createStyleDecorator('update')('$this', {})(selectorOrTarget as Object, optionsOrPropertyKey, descriptor as PropertyDescriptor);\n }\n // With selector\n if (typeof selectorOrTarget === 'string') {\n return createStyleDecorator('update')(selectorOrTarget, optionsOrPropertyKey as StyleApplyOptions);\n }\n // Without selector (defaults to $this)\n return createStyleDecorator('update')('$this', selectorOrTarget as StyleApplyOptions);\n}\n\nexport function removeStyle(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;\nexport function removeStyle(selector: string, options?: StyleApplyOptions): MethodDecorator;\nexport function removeStyle(selectorOrTarget?: any, optionsOrPropertyKey?: any, descriptor?: any): any {\n // Bare decorator: @removeStyle\n if (descriptor !== undefined && (typeof optionsOrPropertyKey === 'string' || typeof optionsOrPropertyKey === 'symbol')) {\n return createStyleDecorator('remove')('$this', {})(selectorOrTarget as Object, optionsOrPropertyKey, descriptor as PropertyDescriptor);\n }\n // With selector\n if (typeof selectorOrTarget === 'string') {\n return createStyleDecorator('remove')(selectorOrTarget, optionsOrPropertyKey as StyleApplyOptions);\n }\n // Without selector (defaults to $this)\n return createStyleDecorator('remove')('$this', selectorOrTarget as StyleApplyOptions);\n}\n\nexport const findAllStyleMetadata = (target: any): Map<string | symbol, StyleApplyMetadata> => {\n const result = new Map<string | symbol, StyleApplyMetadata>();\n const maps = ReflectUtils.findAllMetadata<Map<string | symbol, StyleApplyMetadata>>(STYLE_METADATA_KEY, target);\n maps.forEach(map => {\n if (map instanceof Map) {\n map.forEach((v, k) => result.set(k, v));\n }\n });\n return result;\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA2B;AAC3B,2BAAyB;AACzB,mBAAuB;AAsBhB,MAAM,qBAAqB,OAAO,IAAI,4BAA4B;AAEzE,SAAS,qBAAqB,QAAqB;AACjD,SAAO,CAAC,UAAkB,UAA6B,CAAC,MAAuB;AAC7E,WAAO,CAAC,QAAgB,aAA8B,eAAmC;AACvF,YAAM,cAAc,OAAO;AAC3B,UAAI,WAAW,yBAAa,eAAe,oBAAoB,WAAW;AAC1E,UAAI,CAAC,UAAU;AACb,mBAAW,oBAAI,IAAyC;AACxD,iCAAa,eAAe,oBAAoB,UAAU,WAAW;AAAA,MACvE;AACA,eAAS,IAAI,aAAa,EAAE,aAAa,UAAU,QAAQ,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
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var
|
|
19
|
-
__export(
|
|
18
|
+
var changedAttribute_exports = {};
|
|
19
|
+
__export(changedAttribute_exports, {
|
|
20
20
|
ON_ATTRIBUTE_CHANGED_METADATA_KEY: () => ON_ATTRIBUTE_CHANGED_METADATA_KEY,
|
|
21
|
-
|
|
21
|
+
changedAttribute: () => changedAttribute,
|
|
22
22
|
convertAttributeValue: () => convertAttributeValue,
|
|
23
23
|
findAllAttributeChangedMetadata: () => findAllAttributeChangedMetadata,
|
|
24
24
|
getChangedAttributeMetadata: () => getChangedAttributeMetadata
|
|
25
25
|
});
|
|
26
|
-
module.exports = __toCommonJS(
|
|
26
|
+
module.exports = __toCommonJS(changedAttribute_exports);
|
|
27
27
|
var import_core = require("@dooboostore/core");
|
|
28
28
|
const ON_ATTRIBUTE_CHANGED_METADATA_KEY = Symbol.for("simple-web-component:on-attribute-changed");
|
|
29
29
|
const convertValue = (val, type) => {
|
|
@@ -32,7 +32,7 @@ const convertValue = (val, type) => {
|
|
|
32
32
|
if (type === Boolean) return val === "false" || val === "0" ? false : true;
|
|
33
33
|
return val;
|
|
34
34
|
};
|
|
35
|
-
function
|
|
35
|
+
function changedAttribute(attributeName, options = {}) {
|
|
36
36
|
return (target, propertyKey) => {
|
|
37
37
|
const constructor = target.constructor;
|
|
38
38
|
let metaList = import_core.ReflectUtils.getOwnMetadata(ON_ATTRIBUTE_CHANGED_METADATA_KEY, constructor);
|
|
@@ -69,4 +69,4 @@ const findAllAttributeChangedMetadata = (target) => {
|
|
|
69
69
|
const convertAttributeValue = (val, type) => {
|
|
70
70
|
return convertValue(val, type);
|
|
71
71
|
};
|
|
72
|
-
//# sourceMappingURL=
|
|
72
|
+
//# sourceMappingURL=changedAttribute.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/decorators/changedAttribute.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 {\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 changedAttribute(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
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA6B;AAEtB,MAAM,oCAAoC,OAAO,IAAI,2CAA2C;AAavG,MAAM,eAAe,CAAC,KAAU,SAAmB;AACjD,MAAI,QAAQ,QAAQ,QAAQ,OAAW,QAAO;AAC9C,MAAI,SAAS,OAAQ,QAAO,OAAO,GAAG;AACtC,MAAI,SAAS,QAAS,QAAO,QAAQ,WAAW,QAAQ,MAAM,QAAQ;AACtE,SAAO;AACT;AAKO,SAAS,iBAAiB,eAAwB,UAAuC,CAAC,GAAoB;AACnH,SAAO,CAAC,QAAgB,gBAAiC;AACvD,UAAM,cAAc,OAAO;AAC3B,QAAI,WAAW,yBAAa,eAAe,mCAAmC,WAAW;AACzF,QAAI,CAAC,UAAU;AACb,iBAAW,CAAC;AACZ,+BAAa,eAAe,mCAAmC,UAAU,WAAW;AAAA,IACtF;AAEA,UAAM,OAAO,iBAAiB,OAAO,WAAW;AAChD,aAAS,KAAK;AAAA,MACZ,eAAe;AAAA,MACf;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH;AACF;AAEO,MAAM,8BAA8B,CAAC,WAA4D;AACtG,QAAM,cAAc,kBAAkB,WAAW,SAAS,OAAO;AACjE,SAAO,yBAAa,YAAY,mCAAmC,WAAW;AAChF;AAEO,MAAM,kCAAkC,CAAC,WAA6D;AAC3G,QAAM,cAAc,kBAAkB,WAAW,SAAS,OAAO;AACjE,QAAM,WAAW,yBAAa,gBAAgD,mCAAmC,WAAW,KAAK,CAAC;AAElI,QAAM,SAAS,oBAAI,IAA4C;AAC/D,WAAS,QAAQ,UAAQ;AACvB,SAAK,QAAQ,UAAQ;AACnB,UAAI,CAAC,OAAO,IAAI,KAAK,aAAa,GAAG;AACnC,eAAO,IAAI,KAAK,eAAe,CAAC,CAAC;AAAA,MACnC;AACA,aAAO,IAAI,KAAK,aAAa,EAAG,KAAK,IAAI;AAAA,IAC3C,CAAC;AAAA,EACH,CAAC;AACD,SAAO;AACT;AAEO,MAAM,wBAAwB,CAAC,KAAU,SAA+D;AAC7G,SAAO,aAAa,KAAK,IAAI;AAC/B;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -24,10 +24,12 @@ __export(elementDefine_exports, {
|
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(elementDefine_exports);
|
|
26
26
|
var import_core = require("@dooboostore/core");
|
|
27
|
+
var import_core2 = require("@dooboostore/core");
|
|
28
|
+
var import_operators = require("@dooboostore/core/message/operators");
|
|
27
29
|
var import_addEventListener = require("./addEventListener");
|
|
28
30
|
var import_lifecycles = require("./lifecycles");
|
|
29
31
|
var import_emitCustomEvent = require("./emitCustomEvent");
|
|
30
|
-
var
|
|
32
|
+
var import_changedAttribute = require("./changedAttribute");
|
|
31
33
|
var import_applyAttribute = require("./applyAttribute");
|
|
32
34
|
var import_query = require("./query");
|
|
33
35
|
var import_queryAll = require("./queryAll");
|
|
@@ -250,7 +252,7 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
250
252
|
const emitCustomEventList = (0, import_emitCustomEvent.getEmitCustomEventMetadataList)(constructor) || [];
|
|
251
253
|
const emitHostCustomEventList = emitCustomEventList.filter((meta) => meta.selector === "$this" || meta.selector === "");
|
|
252
254
|
const addEventListenerList = (0, import_addEventListener.getAddEventListenerMetadata)(constructor) || [];
|
|
253
|
-
const attrChangeMap = (0,
|
|
255
|
+
const attrChangeMap = (0, import_changedAttribute.findAllAttributeChangedMetadata)(constructor);
|
|
254
256
|
const attributeList = (0, import_applyAttribute.findAllAttributeMetadata)(constructor);
|
|
255
257
|
const applyAttributeMap = (0, import_applyAttribute.findAllAttributeApplyMetadata)(constructor);
|
|
256
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"];
|
|
@@ -449,8 +451,32 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
449
451
|
const args = { event, ...currentHostSet, $el: t, $root: t };
|
|
450
452
|
await this[meta.propertyKey](event, { currentHostSet, $$matchedElement: event.currentTarget }, args);
|
|
451
453
|
};
|
|
452
|
-
|
|
453
|
-
|
|
454
|
+
const eventSubject = new import_core2.Subject();
|
|
455
|
+
let eventStream = eventSubject;
|
|
456
|
+
if (options.debounceTime !== void 0 && options.debounceTime > 0) {
|
|
457
|
+
eventStream = eventStream.pipe((0, import_operators.debounceTime)(options.debounceTime));
|
|
458
|
+
}
|
|
459
|
+
if (options.throttleTime !== void 0 && options.throttleTime > 0) {
|
|
460
|
+
eventStream = eventStream.pipe((0, import_operators.throttleTime)(options.throttleTime));
|
|
461
|
+
}
|
|
462
|
+
if (options.distinctUntilChanged !== void 0 && options.distinctUntilChanged !== false) {
|
|
463
|
+
if (typeof options.distinctUntilChanged === "function") {
|
|
464
|
+
eventStream = eventStream.pipe((0, import_operators.distinctUntilChanged)(options.distinctUntilChanged));
|
|
465
|
+
} else {
|
|
466
|
+
eventStream = eventStream.pipe((0, import_operators.distinctUntilChanged)());
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
const subscription = eventStream.subscribe({
|
|
470
|
+
next: (event) => {
|
|
471
|
+
handler(event).catch((err) => console.error("Event handler error:", err));
|
|
472
|
+
},
|
|
473
|
+
error: (err) => console.error("Event stream error:", err)
|
|
474
|
+
});
|
|
475
|
+
const wrappedHandler = (event) => {
|
|
476
|
+
eventSubject.next(event);
|
|
477
|
+
};
|
|
478
|
+
t.addEventListener(type, wrappedHandler, opts);
|
|
479
|
+
this._boundListeners.push({ target: t, type, handler: wrappedHandler, options: opts, subscription });
|
|
454
480
|
});
|
|
455
481
|
});
|
|
456
482
|
if (originalConnected) await originalConnected.apply(this);
|
|
@@ -490,7 +516,12 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
490
516
|
const bMethods = (0, import_lifecycles.findAllLifecycleMetadata)(this, import_lifecycles.ON_BEFORE_DISCONNECTED_METADATA_KEY);
|
|
491
517
|
for (const m of bMethods) this._invokeLifecycleMethod(m.propertyKey, helperHostSet);
|
|
492
518
|
if (this._boundListeners) {
|
|
493
|
-
this._boundListeners.forEach((l) =>
|
|
519
|
+
this._boundListeners.forEach((l) => {
|
|
520
|
+
l.target.removeEventListener(l.type, l.handler, l.options);
|
|
521
|
+
if (l.subscription && typeof l.subscription.unsubscribe === "function") {
|
|
522
|
+
l.subscription.unsubscribe();
|
|
523
|
+
}
|
|
524
|
+
});
|
|
494
525
|
this._boundListeners = [];
|
|
495
526
|
}
|
|
496
527
|
new import_core_web.ElementApply(this, { id: this._swcId }).removeAllEventListener();
|
|
@@ -554,7 +585,7 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
554
585
|
if (meta.options.while === "connected" && !this.__swc_connected) {
|
|
555
586
|
continue;
|
|
556
587
|
}
|
|
557
|
-
const convertedVal = (0,
|
|
588
|
+
const convertedVal = (0, import_changedAttribute.convertAttributeValue)(processedVal, meta.options.type);
|
|
558
589
|
this[meta.propertyKey](convertedVal, old, name2, hSet);
|
|
559
590
|
}
|
|
560
591
|
}
|