@dooboostore/simple-web-component 1.0.48 → 1.0.50
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 +189 -19
- package/dist/cjs/config/config.js +1 -1
- package/dist/cjs/config/config.js.map +2 -2
- package/dist/cjs/decorators/addEventListener.js +2373 -30
- package/dist/cjs/decorators/addEventListener.js.map +3 -3
- package/dist/cjs/decorators/applyAttribute.js +31 -0
- package/dist/cjs/decorators/applyAttribute.js.map +2 -2
- package/dist/cjs/decorators/applyClass.js +55 -18
- package/dist/cjs/decorators/applyClass.js.map +3 -3
- package/dist/cjs/decorators/applyNode.js +73 -1
- package/dist/cjs/decorators/applyNode.js.map +3 -3
- package/dist/cjs/decorators/applyProperty.js +107 -3
- package/dist/cjs/decorators/applyProperty.js.map +2 -2
- package/dist/cjs/decorators/applySlot.js +6 -5
- package/dist/cjs/decorators/applySlot.js.map +2 -2
- package/dist/cjs/decorators/applyStyle.js +42 -5
- package/dist/cjs/decorators/applyStyle.js.map +2 -2
- package/dist/cjs/decorators/changedAttribute.js +61 -13
- package/dist/cjs/decorators/changedAttribute.js.map +2 -2
- package/dist/cjs/decorators/elementDefine.js +254 -439
- package/dist/cjs/decorators/elementDefine.js.map +3 -3
- package/dist/cjs/decorators/emitCustomEvent.js +55 -0
- package/dist/cjs/decorators/emitCustomEvent.js.map +2 -2
- package/dist/cjs/decorators/eventMedia.js +84 -0
- package/dist/cjs/decorators/eventMedia.js.map +7 -0
- package/dist/cjs/decorators/index.js +6 -1
- package/dist/cjs/decorators/index.js.map +2 -2
- package/dist/cjs/decorators/intersectionObserver.js +200 -0
- package/dist/cjs/decorators/intersectionObserver.js.map +7 -0
- package/dist/cjs/decorators/mutationObserver.js +186 -55
- package/dist/cjs/decorators/mutationObserver.js.map +3 -3
- package/dist/cjs/decorators/parameter.js +73 -0
- package/dist/cjs/decorators/parameter.js.map +7 -0
- package/dist/cjs/decorators/query.js +117 -102
- package/dist/cjs/decorators/query.js.map +2 -2
- package/dist/cjs/decorators/requestAnimationFrame.js +124 -0
- package/dist/cjs/decorators/requestAnimationFrame.js.map +7 -0
- package/dist/cjs/decorators/resizeObserver.js +133 -55
- package/dist/cjs/decorators/resizeObserver.js.map +2 -2
- package/dist/cjs/decorators/setInterval.js +114 -0
- package/dist/cjs/decorators/setInterval.js.map +7 -0
- package/dist/cjs/decorators/setTimeout.js +117 -0
- package/dist/cjs/decorators/setTimeout.js.map +7 -0
- package/dist/cjs/decorators/subscribeSwcAppMessageWhileConnected.js +9 -0
- package/dist/cjs/decorators/subscribeSwcAppMessageWhileConnected.js.map +2 -2
- package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js +9 -0
- package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
- package/dist/cjs/elements/SwcAppMixin.js +19 -3
- package/dist/cjs/elements/SwcAppMixin.js.map +2 -2
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/cjs/types/window.d.js.map +1 -1
- package/dist/esm/config/config.js +1 -1
- package/dist/esm/config/config.js.map +2 -2
- package/dist/esm/decorators/addEventListener.js +2374 -30
- package/dist/esm/decorators/addEventListener.js.map +3 -3
- package/dist/esm/decorators/applyAttribute.js +31 -0
- package/dist/esm/decorators/applyAttribute.js.map +2 -2
- package/dist/esm/decorators/applyClass.js +55 -18
- package/dist/esm/decorators/applyClass.js.map +3 -3
- package/dist/esm/decorators/applyNode.js +73 -1
- package/dist/esm/decorators/applyNode.js.map +3 -3
- package/dist/esm/decorators/applyProperty.js +107 -3
- package/dist/esm/decorators/applyProperty.js.map +2 -2
- package/dist/esm/decorators/applySlot.js +6 -5
- package/dist/esm/decorators/applySlot.js.map +2 -2
- package/dist/esm/decorators/applyStyle.js +42 -5
- package/dist/esm/decorators/applyStyle.js.map +2 -2
- package/dist/esm/decorators/changedAttribute.js +62 -13
- package/dist/esm/decorators/changedAttribute.js.map +2 -2
- package/dist/esm/decorators/elementDefine.js +261 -446
- package/dist/esm/decorators/elementDefine.js.map +3 -3
- package/dist/esm/decorators/emitCustomEvent.js +55 -0
- package/dist/esm/decorators/emitCustomEvent.js.map +2 -2
- package/dist/esm/decorators/eventMedia.js +66 -0
- package/dist/esm/decorators/eventMedia.js.map +7 -0
- package/dist/esm/decorators/index.js +6 -1
- package/dist/esm/decorators/index.js.map +2 -2
- package/dist/esm/decorators/intersectionObserver.js +182 -0
- package/dist/esm/decorators/intersectionObserver.js.map +7 -0
- package/dist/esm/decorators/mutationObserver.js +187 -55
- package/dist/esm/decorators/mutationObserver.js.map +3 -3
- package/dist/esm/decorators/parameter.js +54 -0
- package/dist/esm/decorators/parameter.js.map +7 -0
- package/dist/esm/decorators/query.js +117 -102
- package/dist/esm/decorators/query.js.map +2 -2
- package/dist/esm/decorators/requestAnimationFrame.js +105 -0
- package/dist/esm/decorators/requestAnimationFrame.js.map +7 -0
- package/dist/esm/decorators/resizeObserver.js +134 -55
- package/dist/esm/decorators/resizeObserver.js.map +2 -2
- package/dist/esm/decorators/setInterval.js +95 -0
- package/dist/esm/decorators/setInterval.js.map +7 -0
- package/dist/esm/decorators/setTimeout.js +98 -0
- package/dist/esm/decorators/setTimeout.js.map +7 -0
- package/dist/esm/decorators/subscribeSwcAppMessageWhileConnected.js +9 -0
- package/dist/esm/decorators/subscribeSwcAppMessageWhileConnected.js.map +2 -2
- package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js +9 -0
- package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
- package/dist/esm/elements/SwcAppMixin.js +20 -4
- package/dist/esm/elements/SwcAppMixin.js.map +2 -2
- package/dist/esm/types/index.js.map +1 -1
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +4961 -1628
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
- package/dist/types/config/config.d.ts.map +1 -1
- package/dist/types/decorators/addEventListener.d.ts +1046 -33
- package/dist/types/decorators/addEventListener.d.ts.map +1 -1
- package/dist/types/decorators/applyAttribute.d.ts +24 -34
- package/dist/types/decorators/applyAttribute.d.ts.map +1 -1
- package/dist/types/decorators/applyClass.d.ts +36 -34
- package/dist/types/decorators/applyClass.d.ts.map +1 -1
- package/dist/types/decorators/applyNode.d.ts +32 -20
- package/dist/types/decorators/applyNode.d.ts.map +1 -1
- package/dist/types/decorators/applyProperty.d.ts +61 -34
- package/dist/types/decorators/applyProperty.d.ts.map +1 -1
- package/dist/types/decorators/applySlot.d.ts.map +1 -1
- package/dist/types/decorators/applyStyle.d.ts +27 -12
- package/dist/types/decorators/applyStyle.d.ts.map +1 -1
- package/dist/types/decorators/changedAttribute.d.ts +12 -3
- package/dist/types/decorators/changedAttribute.d.ts.map +1 -1
- package/dist/types/decorators/elementDefine.d.ts +0 -14
- package/dist/types/decorators/elementDefine.d.ts.map +1 -1
- package/dist/types/decorators/emitCustomEvent.d.ts +28 -4
- package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
- package/dist/types/decorators/eventMedia.d.ts +25 -0
- package/dist/types/decorators/eventMedia.d.ts.map +1 -0
- package/dist/types/decorators/index.d.ts +6 -1
- package/dist/types/decorators/index.d.ts.map +1 -1
- package/dist/types/decorators/intersectionObserver.d.ts +58 -0
- package/dist/types/decorators/intersectionObserver.d.ts.map +1 -0
- package/dist/types/decorators/mutationObserver.d.ts +44 -25
- package/dist/types/decorators/mutationObserver.d.ts.map +1 -1
- package/dist/types/decorators/parameter.d.ts +35 -0
- package/dist/types/decorators/parameter.d.ts.map +1 -0
- package/dist/types/decorators/query.d.ts +57 -14
- package/dist/types/decorators/query.d.ts.map +1 -1
- package/dist/types/decorators/requestAnimationFrame.d.ts +47 -0
- package/dist/types/decorators/requestAnimationFrame.d.ts.map +1 -0
- package/dist/types/decorators/resizeObserver.d.ts +43 -23
- package/dist/types/decorators/resizeObserver.d.ts.map +1 -1
- package/dist/types/decorators/setInterval.d.ts +41 -0
- package/dist/types/decorators/setInterval.d.ts.map +1 -0
- package/dist/types/decorators/setTimeout.d.ts +41 -0
- package/dist/types/decorators/setTimeout.d.ts.map +1 -0
- package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts +7 -1
- package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts.map +1 -1
- package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts +6 -0
- package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts.map +1 -1
- package/dist/types/elements/SwcAppMixin.d.ts.map +1 -1
- package/dist/types/types/index.d.ts +104 -0
- package/dist/types/types/index.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +4961 -1628
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +7 -5
- package/src/config/config.ts +1 -1
- package/src/decorators/addEventListener.ts +1446 -34
- package/src/decorators/applyAttribute.ts +60 -36
- package/src/decorators/applyClass.ts +86 -26
- package/src/decorators/applyNode.ts +124 -36
- package/src/decorators/applyProperty.ts +172 -40
- package/src/decorators/applySlot.ts +6 -5
- package/src/decorators/applyStyle.ts +74 -17
- package/src/decorators/changedAttribute.ts +76 -15
- package/src/decorators/elementDefine.ts +310 -582
- package/src/decorators/emitCustomEvent.ts +73 -5
- package/src/decorators/eventMedia.ts +78 -0
- package/src/decorators/index.ts +6 -1
- package/src/decorators/intersectionObserver.ts +275 -0
- package/src/decorators/mutationObserver.ts +282 -89
- package/src/decorators/parameter.ts +81 -0
- package/src/decorators/query.ts +168 -126
- package/src/decorators/requestAnimationFrame.ts +158 -0
- package/src/decorators/resizeObserver.ts +211 -89
- package/src/decorators/setInterval.ts +136 -0
- package/src/decorators/setTimeout.ts +139 -0
- package/src/decorators/subscribeSwcAppMessageWhileConnected.ts +17 -0
- package/src/decorators/subscribeSwcAppRouteChangeWhileConnected.ts +19 -0
- package/src/elements/SwcAppMixin.ts +20 -5
- package/src/types/index.ts +141 -0
- package/src/types/window.d.ts +2 -18
- package/dist/cjs/decorators/queryAll.js +0 -181
- package/dist/cjs/decorators/queryAll.js.map +0 -7
- package/dist/cjs/examples/RxJSOperatorsExample.js +0 -285
- package/dist/cjs/examples/RxJSOperatorsExample.js.map +0 -7
- package/dist/esm/decorators/queryAll.js +0 -162
- package/dist/esm/decorators/queryAll.js.map +0 -7
- package/dist/esm/examples/RxJSOperatorsExample.js +0 -266
- package/dist/esm/examples/RxJSOperatorsExample.js.map +0 -7
- package/dist/types/decorators/queryAll.d.ts +0 -22
- package/dist/types/decorators/queryAll.d.ts.map +0 -1
- package/dist/types/examples/RxJSOperatorsExample.d.ts +0 -94
- package/dist/types/examples/RxJSOperatorsExample.d.ts.map +0 -1
- package/src/decorators/queryAll.ts +0 -186
- package/src/examples/RxJSOperatorsExample.ts +0 -279
|
@@ -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 /**\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(
|
|
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,0BAA0B,OAAO,IAAI,iCAAiC;AAyCnF,MAAM,aAAa,CAAC,OAAe,IAAY,KAAwB,UAAkB;
|
|
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 = (host: HTMLElement, swcId: string, id: string, pos: ApplySlotPosition, nodes: Node[]) => {\n const nodeSlot = new NodeSlot(host, 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 host = this;\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(host, 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(host, swcId, targetId, options.position, nodes);\n })\n } else {\n const extracted = extractValue(res);\n const nodes: Node[] = resToNodes(extracted);\n applyToDom(host, 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,0BAA0B,OAAO,IAAI,iCAAiC;AAyCnF,MAAM,aAAa,CAAC,MAAmB,OAAe,IAAY,KAAwB,UAAkB;AAC1G,QAAM,WAAW,IAAI,yBAAS,MAAM,KAAK;AACzC,MAAI,QAAQ,yBAAyB,QAAQ,qBAAqB,QAAQ,uBAAuB;AAC/F,aAAS,gBAAgB,IAAI,GAAG,KAAK;AAAA,EACvC,WAAW,QAAQ,gBAAgB,QAAQ,YAAY,QAAQ,cAAc;AAC3E,aAAS,OAAO,IAAI,GAAG,KAAK;AAAA,EAC9B,WAAW,QAAQ,iBAAiB,QAAQ,aAAa,QAAQ,eAAe;AAC9E,aAAS,QAAQ,IAAI,GAAG,KAAK;AAAA,EAC/B,WAAW,QAAQ,SAAS;AAC1B,aAAS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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
|
}
|
|
@@ -22,6 +22,12 @@ __export(applyStyle_exports, {
|
|
|
22
22
|
findAllStyleMetadata: () => findAllStyleMetadata,
|
|
23
23
|
removeStyle: () => removeStyle,
|
|
24
24
|
setStyle: () => setStyle,
|
|
25
|
+
style: () => style,
|
|
26
|
+
styleAll: () => styleAll,
|
|
27
|
+
styleAppHost: () => styleAppHost,
|
|
28
|
+
styleLight: () => styleLight,
|
|
29
|
+
styleShadow: () => styleShadow,
|
|
30
|
+
styleThis: () => styleThis,
|
|
25
31
|
updateStyle: () => updateStyle
|
|
26
32
|
});
|
|
27
33
|
module.exports = __toCommonJS(applyStyle_exports);
|
|
@@ -45,6 +51,9 @@ const resolveSelector = (selector, inst, win) => {
|
|
|
45
51
|
if (result === null) {
|
|
46
52
|
return [];
|
|
47
53
|
}
|
|
54
|
+
if (result instanceof win.Node) {
|
|
55
|
+
return [];
|
|
56
|
+
}
|
|
48
57
|
return result;
|
|
49
58
|
}
|
|
50
59
|
return selector;
|
|
@@ -156,10 +165,10 @@ function createStyleDecorator(action) {
|
|
|
156
165
|
};
|
|
157
166
|
}
|
|
158
167
|
function applyStyle(selectorOrTarget, actionOrPropertyKey, optionsOrDescriptor) {
|
|
159
|
-
if (optionsOrDescriptor !== void 0 && (typeof actionOrPropertyKey === "string" || typeof actionOrPropertyKey === "symbol")) {
|
|
168
|
+
if (optionsOrDescriptor !== void 0 && typeof selectorOrTarget !== "string" && typeof selectorOrTarget !== "function" && (typeof actionOrPropertyKey === "string" || typeof actionOrPropertyKey === "symbol")) {
|
|
160
169
|
return createStyleDecorator("update")("$this", {})(selectorOrTarget, actionOrPropertyKey, optionsOrDescriptor);
|
|
161
170
|
}
|
|
162
|
-
if (typeof selectorOrTarget === "string") {
|
|
171
|
+
if (typeof selectorOrTarget === "string" || typeof selectorOrTarget === "function") {
|
|
163
172
|
const action2 = typeof actionOrPropertyKey === "string" ? actionOrPropertyKey : "update";
|
|
164
173
|
const options2 = typeof actionOrPropertyKey === "object" ? actionOrPropertyKey : optionsOrDescriptor;
|
|
165
174
|
return createStyleDecorator(action2)(selectorOrTarget, options2);
|
|
@@ -172,7 +181,7 @@ function setStyle(selectorOrTarget, optionsOrPropertyKey, descriptor) {
|
|
|
172
181
|
if (descriptor !== void 0 && (typeof optionsOrPropertyKey === "string" || typeof optionsOrPropertyKey === "symbol")) {
|
|
173
182
|
return createStyleDecorator("set")("$this", {})(selectorOrTarget, optionsOrPropertyKey, descriptor);
|
|
174
183
|
}
|
|
175
|
-
if (typeof selectorOrTarget === "string") {
|
|
184
|
+
if (typeof selectorOrTarget === "string" || typeof selectorOrTarget === "function") {
|
|
176
185
|
return createStyleDecorator("set")(selectorOrTarget, optionsOrPropertyKey);
|
|
177
186
|
}
|
|
178
187
|
return createStyleDecorator("set")("$this", selectorOrTarget);
|
|
@@ -181,7 +190,7 @@ function updateStyle(selectorOrTarget, optionsOrPropertyKey, descriptor) {
|
|
|
181
190
|
if (descriptor !== void 0 && (typeof optionsOrPropertyKey === "string" || typeof optionsOrPropertyKey === "symbol")) {
|
|
182
191
|
return createStyleDecorator("update")("$this", {})(selectorOrTarget, optionsOrPropertyKey, descriptor);
|
|
183
192
|
}
|
|
184
|
-
if (typeof selectorOrTarget === "string") {
|
|
193
|
+
if (typeof selectorOrTarget === "string" || typeof selectorOrTarget === "function") {
|
|
185
194
|
return createStyleDecorator("update")(selectorOrTarget, optionsOrPropertyKey);
|
|
186
195
|
}
|
|
187
196
|
return createStyleDecorator("update")("$this", selectorOrTarget);
|
|
@@ -190,11 +199,39 @@ function removeStyle(selectorOrTarget, optionsOrPropertyKey, descriptor) {
|
|
|
190
199
|
if (descriptor !== void 0 && (typeof optionsOrPropertyKey === "string" || typeof optionsOrPropertyKey === "symbol")) {
|
|
191
200
|
return createStyleDecorator("remove")("$this", {})(selectorOrTarget, optionsOrPropertyKey, descriptor);
|
|
192
201
|
}
|
|
193
|
-
if (typeof selectorOrTarget === "string") {
|
|
202
|
+
if (typeof selectorOrTarget === "string" || typeof selectorOrTarget === "function") {
|
|
194
203
|
return createStyleDecorator("remove")(selectorOrTarget, optionsOrPropertyKey);
|
|
195
204
|
}
|
|
196
205
|
return createStyleDecorator("remove")("$this", selectorOrTarget);
|
|
197
206
|
}
|
|
207
|
+
const style = applyStyle;
|
|
208
|
+
function styleThis(actionOrTarget, optionsOrPropertyKey, descriptor) {
|
|
209
|
+
if ((typeof optionsOrPropertyKey === "string" || typeof optionsOrPropertyKey === "symbol") && descriptor !== void 0) {
|
|
210
|
+
return applyStyle("$this", void 0, {})(actionOrTarget, optionsOrPropertyKey, descriptor);
|
|
211
|
+
}
|
|
212
|
+
return applyStyle("$this", actionOrTarget, optionsOrPropertyKey);
|
|
213
|
+
}
|
|
214
|
+
function styleAppHost(actionOrTarget, optionsOrPropertyKey, descriptor) {
|
|
215
|
+
if ((typeof optionsOrPropertyKey === "string" || typeof optionsOrPropertyKey === "symbol") && descriptor !== void 0) {
|
|
216
|
+
return applyStyle("$appHost", void 0, {})(actionOrTarget, optionsOrPropertyKey, descriptor);
|
|
217
|
+
}
|
|
218
|
+
return applyStyle("$appHost", actionOrTarget, optionsOrPropertyKey);
|
|
219
|
+
}
|
|
220
|
+
function styleLight(selector, actionOrOptions, options) {
|
|
221
|
+
const action = typeof actionOrOptions === "string" ? actionOrOptions : void 0;
|
|
222
|
+
const opts = typeof actionOrOptions === "object" ? actionOrOptions : options;
|
|
223
|
+
return applyStyle(selector, action, { ...opts ?? {}, root: "light" });
|
|
224
|
+
}
|
|
225
|
+
function styleShadow(selector, actionOrOptions, options) {
|
|
226
|
+
const action = typeof actionOrOptions === "string" ? actionOrOptions : void 0;
|
|
227
|
+
const opts = typeof actionOrOptions === "object" ? actionOrOptions : options;
|
|
228
|
+
return applyStyle(selector, action, { ...opts ?? {}, root: "shadow" });
|
|
229
|
+
}
|
|
230
|
+
function styleAll(selector, actionOrOptions, options) {
|
|
231
|
+
const action = typeof actionOrOptions === "string" ? actionOrOptions : void 0;
|
|
232
|
+
const opts = typeof actionOrOptions === "object" ? actionOrOptions : options;
|
|
233
|
+
return applyStyle(selector, action, { ...opts ?? {}, root: "all" });
|
|
234
|
+
}
|
|
198
235
|
const findAllStyleMetadata = (target) => {
|
|
199
236
|
const result = /* @__PURE__ */ new Map();
|
|
200
237
|
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 * 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 type StyleSelector = string | ((currentThis: any, helper: HelperHostSet) => NodeList | Element | Element[] | null);\n\nexport interface StyleApplyMetadata {\n propertyKey: string | symbol;\n selector: StyleSelector;\n action: StyleAction;\n options: StyleApplyOptions;\n}\n\nexport const STYLE_METADATA_KEY = Symbol.for('simple-web-component:style');\n\n/**\n * Resolve selector to string or elements\n * Handles function-based selectors and returns elements if applicable\n */\nconst resolveSelector = (selector: StyleSelector, inst: any, win: Window): string | HTMLElement[] => {\n if (typeof selector === 'function') {\n const hostSet = SwcUtils.getHelperAndHostSet(win, inst);\n const result = selector(inst, hostSet);\n \n if (result instanceof win.Element) {\n return [result as HTMLElement];\n }\n if (result instanceof win.NodeList) {\n return Array.from(result) as HTMLElement[];\n }\n if (Array.isArray(result)) {\n return result as HTMLElement[];\n }\n if (result === null) {\n return [];\n }\n return result as string;\n }\n return selector as string;\n};\n\n/**\n * Get target elements from selector\n */\nconst getTargetElements = (selector: StyleSelector, inst: any, win: Window, root: string): HTMLElement[] => {\n const resolved = resolveSelector(selector, inst, win);\n \n if (Array.isArray(resolved)) {\n return resolved;\n }\n\n const stringSelector = resolved as string;\n const targetEls: HTMLElement[] = [];\n const host = inst as unknown as HTMLElement;\n const hostSet = SwcUtils.getHelperAndHostSet(win, inst);\n\n const applyRoot = (t: any) => {\n if (!t || !(t instanceof win.HTMLElement)) return;\n targetEls.push(t);\n };\n\n if (stringSelector === '$this' || !stringSelector) applyRoot(host);\n else if (stringSelector === '$host') applyRoot(hostSet.$host);\n else if (stringSelector === '$parentHost') applyRoot(hostSet.$parentHost);\n else if (stringSelector === '$appHost') applyRoot(hostSet.$appHost);\n else if (stringSelector === '$firstHost') applyRoot(hostSet.$firstHost);\n else if (stringSelector === '$lastHost') applyRoot(hostSet.$lastHost);\n else if (stringSelector === '$firstAppHost') applyRoot(hostSet.$firstAppHost);\n else if (stringSelector === '$lastAppHost') applyRoot(hostSet.$lastAppHost);\n else if (stringSelector === '$hosts') hostSet.$hosts.forEach(applyRoot);\n else if (stringSelector === '$appHosts') hostSet.$appHosts.forEach(applyRoot);\n else {\n const targetRoot = root === 'auto' ? (host.shadowRoot || host) : (root === 'shadow' ? host.shadowRoot : host);\n if (targetRoot) {\n const found = targetRoot.querySelectorAll(stringSelector);\n if (found) targetEls.push(...(Array.from(found) as HTMLElement[]));\n }\n }\n\n return targetEls;\n};\n\nfunction createStyleDecorator(action: StyleAction) {\n return (selector: StyleSelector, 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 = getTargetElements(selector, this, win, r);\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: StyleSelector, 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: StyleSelector, 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: StyleSelector, 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: StyleSelector, 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;
|
|
4
|
+
"sourcesContent": ["import {ReflectUtils} from '@dooboostore/core';\nimport {ensureInit} from './elementDefine';\nimport {SwcUtils} from '../utils/Utils';\nimport { SpecialSelector, SwcQueryOptions, SwcFnSelector, SwcSelector, HelperHostSet } from '../types';\n\nexport type StyleAction = 'set' | 'update' | 'remove';\n\n// \uACF5\uD1B5 \uC635\uC158 \u2014 root \uC5C6\uC74C\nexport interface StyleBaseOptions {\n filter?: (target: HTMLElement, value: any, meta: {currentThis: any, helper: HelperHostSet}) => boolean;\n valueKey?: symbol | string;\n}\n\n// \uBB38\uC790\uC5F4 \uC140\uB809\uD130 \uC804\uC6A9 \u2014 root \uD5C8\uC6A9\nexport type StyleQueryOptions = StyleBaseOptions & SwcQueryOptions;\n// \uD568\uC218 \uC140\uB809\uD130 \uC804\uC6A9 \u2014 root \uAE08\uC9C0\nexport type StyleNonQueryOptions = StyleBaseOptions;\n// \uB0B4\uBD80 \uC800\uC7A5/\uD574\uC11D\uC6A9\nexport type StyleApplyOptions = StyleQueryOptions;\n\nexport type StyleFnSelector = SwcFnSelector;\nexport type StyleSelector = SwcSelector;\n\n// \uC140\uB809\uD130 \uC885\uB958\uC5D0 \uB530\uB77C \uC635\uC158 \uD0C0\uC785 \uBD84\uAE30\nexport type StyleOptionsOf<S extends StyleSelector> = S extends string ? StyleQueryOptions : StyleNonQueryOptions;\n\nexport interface StyleApplyMetadata {\n propertyKey: string | symbol;\n selector: StyleSelector;\n action: StyleAction;\n options: StyleApplyOptions;\n}\n\nexport const STYLE_METADATA_KEY = Symbol.for('simple-web-component:style');\n\n/**\n * Resolve selector to string or elements\n * Handles function-based selectors and returns elements if applicable\n */\nconst resolveSelector = (selector: StyleSelector, inst: any, win: Window): string | HTMLElement[] => {\n if (typeof selector === 'function') {\n const hostSet = SwcUtils.getHelperAndHostSet(win, inst);\n const result = selector(inst, hostSet);\n \n if (result instanceof win.Element) {\n return [result as HTMLElement];\n }\n if (result instanceof win.NodeList) {\n return Array.from(result) as HTMLElement[];\n }\n if (Array.isArray(result)) {\n return result as HTMLElement[];\n }\n if (result === null) {\n return [];\n }\n if (result instanceof win.Node) {\n return [];\n }\n return result as string;\n }\n return selector as string;\n};\n\n/**\n * Get target elements from selector\n */\nconst getTargetElements = (selector: StyleSelector, inst: any, win: Window, root: string): HTMLElement[] => {\n const resolved = resolveSelector(selector, inst, win);\n \n if (Array.isArray(resolved)) {\n return resolved;\n }\n\n const stringSelector = resolved as string;\n const targetEls: HTMLElement[] = [];\n const host = inst as unknown as HTMLElement;\n const hostSet = SwcUtils.getHelperAndHostSet(win, inst);\n\n const applyRoot = (t: any) => {\n if (!t || !(t instanceof win.HTMLElement)) return;\n targetEls.push(t);\n };\n\n if (stringSelector === '$this' || !stringSelector) applyRoot(host);\n else if (stringSelector === '$host') applyRoot(hostSet.$host);\n else if (stringSelector === '$parentHost') applyRoot(hostSet.$parentHost);\n else if (stringSelector === '$appHost') applyRoot(hostSet.$appHost);\n else if (stringSelector === '$firstHost') applyRoot(hostSet.$firstHost);\n else if (stringSelector === '$lastHost') applyRoot(hostSet.$lastHost);\n else if (stringSelector === '$firstAppHost') applyRoot(hostSet.$firstAppHost);\n else if (stringSelector === '$lastAppHost') applyRoot(hostSet.$lastAppHost);\n else if (stringSelector === '$hosts') hostSet.$hosts.forEach(applyRoot);\n else if (stringSelector === '$appHosts') hostSet.$appHosts.forEach(applyRoot);\n else {\n const targetRoot = root === 'auto' ? (host.shadowRoot || host) : (root === 'shadow' ? host.shadowRoot : host);\n if (targetRoot) {\n const found = targetRoot.querySelectorAll(stringSelector);\n if (found) targetEls.push(...(Array.from(found) as HTMLElement[]));\n }\n }\n\n return targetEls;\n};\n\nfunction createStyleDecorator(action: StyleAction) {\n return (selector: StyleSelector, 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 = getTargetElements(selector, this, win, r);\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?: StyleQueryOptions): MethodDecorator;\nexport function applyStyle(selector: StyleFnSelector, action?: StyleAction, options?: StyleNonQueryOptions): MethodDecorator;\nexport function applyStyle(selectorOrTarget?: any, actionOrPropertyKey?: any, optionsOrDescriptor?: any): any {\n // Bare decorator: @applyStyle\n if (optionsOrDescriptor !== undefined && typeof selectorOrTarget !== 'string' && typeof selectorOrTarget !== 'function' && (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' || typeof selectorOrTarget === 'function') {\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?: StyleQueryOptions): MethodDecorator;\nexport function setStyle(selector: StyleFnSelector, options?: StyleNonQueryOptions): 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' || typeof selectorOrTarget === 'function') {\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?: StyleQueryOptions): MethodDecorator;\nexport function updateStyle(selector: StyleFnSelector, options?: StyleNonQueryOptions): 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' || typeof selectorOrTarget === 'function') {\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?: StyleQueryOptions): MethodDecorator;\nexport function removeStyle(selector: StyleFnSelector, options?: StyleNonQueryOptions): 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' || typeof selectorOrTarget === 'function') {\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\n// \u2500\u2500\u2500 Aliases \u2500\u2500\u2500\nexport const style = applyStyle;\n\n// \u2500\u2500\u2500 \uD3B8\uC758 \uD5EC\uD37C (selector/root \uC0DD\uB7B5) \u2500\u2500\u2500\n\nexport function styleThis(action?: StyleAction, options?: StyleQueryOptions): MethodDecorator;\nexport function styleThis(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;\nexport function styleThis(actionOrTarget?: StyleAction | Object, optionsOrPropertyKey?: StyleQueryOptions | string | symbol, descriptor?: PropertyDescriptor): any {\n if ((typeof optionsOrPropertyKey === 'string' || typeof optionsOrPropertyKey === 'symbol') && descriptor !== undefined) {\n return (applyStyle('$this', undefined as any, {}) as any)(actionOrTarget, optionsOrPropertyKey, descriptor);\n }\n return applyStyle('$this', actionOrTarget as any, optionsOrPropertyKey as StyleQueryOptions);\n}\nexport function styleAppHost(action?: StyleAction, options?: StyleQueryOptions): MethodDecorator;\nexport function styleAppHost(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;\nexport function styleAppHost(actionOrTarget?: StyleAction | Object, optionsOrPropertyKey?: StyleQueryOptions | string | symbol, descriptor?: PropertyDescriptor): any {\n if ((typeof optionsOrPropertyKey === 'string' || typeof optionsOrPropertyKey === 'symbol') && descriptor !== undefined) {\n return (applyStyle('$appHost', undefined as any, {}) as any)(actionOrTarget, optionsOrPropertyKey, descriptor);\n }\n return applyStyle('$appHost', actionOrTarget as any, optionsOrPropertyKey as StyleQueryOptions);\n}\nexport function styleLight(selector: string, action?: StyleAction, options?: Omit<StyleQueryOptions, 'root'>): MethodDecorator;\nexport function styleLight(selector: string, options?: Omit<StyleQueryOptions, 'root'>): MethodDecorator;\nexport function styleLight(selector: string, actionOrOptions?: StyleAction | Omit<StyleQueryOptions, 'root'>, options?: Omit<StyleQueryOptions, 'root'>): MethodDecorator {\n const action = (typeof actionOrOptions === 'string' ? actionOrOptions : undefined) as StyleAction | undefined;\n const opts = (typeof actionOrOptions === 'object' ? actionOrOptions : options) as Omit<StyleQueryOptions, 'root'> | undefined;\n return applyStyle(selector, action, {...opts ?? {}, root: 'light'});\n}\nexport function styleShadow(selector: string, action?: StyleAction, options?: Omit<StyleQueryOptions, 'root'>): MethodDecorator;\nexport function styleShadow(selector: string, options?: Omit<StyleQueryOptions, 'root'>): MethodDecorator;\nexport function styleShadow(selector: string, actionOrOptions?: StyleAction | Omit<StyleQueryOptions, 'root'>, options?: Omit<StyleQueryOptions, 'root'>): MethodDecorator {\n const action = (typeof actionOrOptions === 'string' ? actionOrOptions : undefined) as StyleAction | undefined;\n const opts = (typeof actionOrOptions === 'object' ? actionOrOptions : options) as Omit<StyleQueryOptions, 'root'> | undefined;\n return applyStyle(selector, action, {...opts ?? {}, root: 'shadow'});\n}\nexport function styleAll(selector: string, action?: StyleAction, options?: Omit<StyleQueryOptions, 'root'>): MethodDecorator;\nexport function styleAll(selector: string, options?: Omit<StyleQueryOptions, 'root'>): MethodDecorator;\nexport function styleAll(selector: string, actionOrOptions?: StyleAction | Omit<StyleQueryOptions, 'root'>, options?: Omit<StyleQueryOptions, 'root'>): MethodDecorator {\n const action = (typeof actionOrOptions === 'string' ? actionOrOptions : undefined) as StyleAction | undefined;\n const opts = (typeof actionOrOptions === 'object' ? actionOrOptions : options) as Omit<StyleQueryOptions, 'root'> | undefined;\n return applyStyle(selector, action, {...opts ?? {}, root: 'all'});\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": ";;;;;;;;;;;;;;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CAAC;AAAA,IACxC;AAAA,EACF,CAAC;AACD,SAAO;AACT;",
|
|
6
6
|
"names": ["action", "options"]
|
|
7
7
|
}
|
|
@@ -2,6 +2,7 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
5
6
|
var __export = (target, all) => {
|
|
6
7
|
for (var name in all)
|
|
7
8
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -15,8 +16,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
16
|
return to;
|
|
16
17
|
};
|
|
17
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
18
20
|
var changedAttribute_exports = {};
|
|
19
21
|
__export(changedAttribute_exports, {
|
|
22
|
+
ChangedAttributeLifeCycler: () => ChangedAttributeLifeCycler,
|
|
20
23
|
ON_ATTRIBUTE_CHANGED_METADATA_KEY: () => ON_ATTRIBUTE_CHANGED_METADATA_KEY,
|
|
21
24
|
changedAttribute: () => changedAttribute,
|
|
22
25
|
convertAttributeValue: () => convertAttributeValue,
|
|
@@ -25,6 +28,7 @@ __export(changedAttribute_exports, {
|
|
|
25
28
|
});
|
|
26
29
|
module.exports = __toCommonJS(changedAttribute_exports);
|
|
27
30
|
var import_core = require("@dooboostore/core");
|
|
31
|
+
var import_applyAttribute = require("./applyAttribute");
|
|
28
32
|
const ON_ATTRIBUTE_CHANGED_METADATA_KEY = Symbol.for("simple-web-component:on-attribute-changed");
|
|
29
33
|
const convertValue = (val, type) => {
|
|
30
34
|
if (val === null || val === void 0) return val;
|
|
@@ -32,20 +36,29 @@ const convertValue = (val, type) => {
|
|
|
32
36
|
if (type === Boolean) return val === "false" || val === "0" ? false : true;
|
|
33
37
|
return val;
|
|
34
38
|
};
|
|
35
|
-
|
|
39
|
+
const applyChangedAttribute = (attributeName, options, target, propertyKey) => {
|
|
40
|
+
const constructor = target.constructor;
|
|
41
|
+
let metaList = import_core.ReflectUtils.getOwnMetadata(ON_ATTRIBUTE_CHANGED_METADATA_KEY, constructor);
|
|
42
|
+
if (!metaList) {
|
|
43
|
+
metaList = [];
|
|
44
|
+
import_core.ReflectUtils.defineMetadata(ON_ATTRIBUTE_CHANGED_METADATA_KEY, metaList, constructor);
|
|
45
|
+
}
|
|
46
|
+
const name = attributeName || String(propertyKey);
|
|
47
|
+
metaList.push({
|
|
48
|
+
attributeName: name,
|
|
49
|
+
propertyKey,
|
|
50
|
+
options
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
function changedAttribute(attributeNameOrTarget, optionsOrPropertyKey, descriptor) {
|
|
54
|
+
if ((typeof optionsOrPropertyKey === "string" || typeof optionsOrPropertyKey === "symbol") && descriptor !== void 0) {
|
|
55
|
+
applyChangedAttribute(void 0, {}, attributeNameOrTarget, optionsOrPropertyKey);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const attributeName = attributeNameOrTarget;
|
|
59
|
+
const options = optionsOrPropertyKey ?? {};
|
|
36
60
|
return (target, propertyKey) => {
|
|
37
|
-
|
|
38
|
-
let metaList = import_core.ReflectUtils.getOwnMetadata(ON_ATTRIBUTE_CHANGED_METADATA_KEY, constructor);
|
|
39
|
-
if (!metaList) {
|
|
40
|
-
metaList = [];
|
|
41
|
-
import_core.ReflectUtils.defineMetadata(ON_ATTRIBUTE_CHANGED_METADATA_KEY, metaList, constructor);
|
|
42
|
-
}
|
|
43
|
-
const name = attributeName || String(propertyKey);
|
|
44
|
-
metaList.push({
|
|
45
|
-
attributeName: name,
|
|
46
|
-
propertyKey,
|
|
47
|
-
options
|
|
48
|
-
});
|
|
61
|
+
applyChangedAttribute(attributeName, options, target, propertyKey);
|
|
49
62
|
};
|
|
50
63
|
}
|
|
51
64
|
const getChangedAttributeMetadata = (target) => {
|
|
@@ -69,4 +82,39 @@ const findAllAttributeChangedMetadata = (target) => {
|
|
|
69
82
|
const convertAttributeValue = (val, type) => {
|
|
70
83
|
return convertValue(val, type);
|
|
71
84
|
};
|
|
85
|
+
class ChangedAttributeLifeCycler {
|
|
86
|
+
constructor() {
|
|
87
|
+
__publicField(this, "attrChangeMap", null);
|
|
88
|
+
}
|
|
89
|
+
/** 클래스 메타데이터 기반 attrChangeMap 을 lazy 로드한다 (공유 시클러 캐시). */
|
|
90
|
+
getAttrChangeMap(inst) {
|
|
91
|
+
if (!this.attrChangeMap) this.attrChangeMap = findAllAttributeChangedMetadata(inst);
|
|
92
|
+
return this.attrChangeMap;
|
|
93
|
+
}
|
|
94
|
+
/** observedAttributes 에 포함할 attribute 이름 목록 */
|
|
95
|
+
getObservedAttributeNames(inst) {
|
|
96
|
+
return Array.from(this.getAttrChangeMap(inst).keys());
|
|
97
|
+
}
|
|
98
|
+
onConnected(helperHostSet) {
|
|
99
|
+
const inst = helperHostSet.$this;
|
|
100
|
+
for (const [name, metaList] of this.getAttrChangeMap(inst)) {
|
|
101
|
+
for (const meta of metaList) {
|
|
102
|
+
if (meta.options.while === "connected") {
|
|
103
|
+
const val = (0, import_applyAttribute.getAttributeValue)(inst, name, { type: meta.options.type });
|
|
104
|
+
if (val !== null) inst[meta.propertyKey](val, null, name, helperHostSet);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/** attributeChangedCallback 에서 elementDefine 이 직접 호출 */
|
|
110
|
+
onAttributeChanged(helperHostSet, name, old, newVal) {
|
|
111
|
+
const inst = helperHostSet.$this;
|
|
112
|
+
const metaList = this.getAttrChangeMap(inst).get(name);
|
|
113
|
+
if (!metaList) return;
|
|
114
|
+
for (const meta of metaList) {
|
|
115
|
+
if (meta.options.while === "connected" && !inst.__swc_connected) continue;
|
|
116
|
+
inst[meta.propertyKey](convertAttributeValue(newVal, meta.options.type), old, name, helperHostSet);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
72
120
|
//# sourceMappingURL=changedAttribute.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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\
|
|
5
|
-
"mappings": "
|
|
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\nconst applyChangedAttribute = (attributeName: string | undefined, options: ChangedAttributeThisOptions, target: Object, propertyKey: string | symbol): void => {\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\nexport function changedAttribute(attributeName?: string, options?: ChangedAttributeThisOptions): MethodDecorator;\nexport function changedAttribute(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\n/**\n * @changedAttributeThis decorator - fires when any attribute on $this changes.\n * \uC635\uC158 \uC5C6\uC774 `@changedAttribute` \uADF8\uB300\uB85C \uBD99\uC5EC\uB3C4 \uB418\uACE0, `@changedAttribute(...)`\uCC98\uB7FC \uC774\uB984/\uC635\uC158\uC744 \uC904 \uC218\uB3C4 \uC788\uB2E4.\n */\nexport function changedAttribute(attributeNameOrTarget?: string | Object, optionsOrPropertyKey?: ChangedAttributeThisOptions | string | symbol, descriptor?: PropertyDescriptor): MethodDecorator | void {\n if ((typeof optionsOrPropertyKey === 'string' || typeof optionsOrPropertyKey === 'symbol') && descriptor !== undefined) {\n // \uC635\uC158 \uC5C6\uC774: @changedAttribute\n applyChangedAttribute(undefined, {}, attributeNameOrTarget as Object, optionsOrPropertyKey);\n return;\n }\n // \uC635\uC158\uACFC \uD568\uAED8: @changedAttribute() / @changedAttribute('name', options?)\n const attributeName = attributeNameOrTarget as string | undefined;\n const options = (optionsOrPropertyKey as ChangedAttributeThisOptions) ?? {};\n return (target: Object, propertyKey: string | symbol) => {\n applyChangedAttribute(attributeName, options, target, propertyKey);\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\n// \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n// ChangedAttributeLifeCycler\n// \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\nimport { ElementDefineLifeCycler, HelperHostSet } from '../types';\nimport { getAttributeValue } from './applyAttribute';\n\nexport class ChangedAttributeLifeCycler implements ElementDefineLifeCycler {\n private attrChangeMap: Map<string, ChangedAttributeThisMetadata[]> | null = null;\n\n /** \uD074\uB798\uC2A4 \uBA54\uD0C0\uB370\uC774\uD130 \uAE30\uBC18 attrChangeMap \uC744 lazy \uB85C\uB4DC\uD55C\uB2E4 (\uACF5\uC720 \uC2DC\uD074\uB7EC \uCE90\uC2DC). */\n private getAttrChangeMap(inst: any): Map<string, ChangedAttributeThisMetadata[]> {\n if (!this.attrChangeMap) this.attrChangeMap = findAllAttributeChangedMetadata(inst);\n return this.attrChangeMap;\n }\n\n /** observedAttributes \uC5D0 \uD3EC\uD568\uD560 attribute \uC774\uB984 \uBAA9\uB85D */\n getObservedAttributeNames(inst: any): string[] {\n return Array.from(this.getAttrChangeMap(inst).keys());\n }\n\n onConnected(helperHostSet: HelperHostSet): void {\n const inst = helperHostSet.$this;\n\n // while:'connected' \uC635\uC158 \u2014 connected \uC2DC\uC810 \uD604\uC7AC \uAC12\uC73C\uB85C \uCD08\uAE30 \uC2E4\uD589\n for (const [name, metaList] of this.getAttrChangeMap(inst)) {\n for (const meta of metaList) {\n if (meta.options.while === 'connected') {\n const val = getAttributeValue(inst, name, { type: meta.options.type });\n if (val !== null) inst[meta.propertyKey](val, null, name, helperHostSet);\n }\n }\n }\n }\n\n /** attributeChangedCallback \uC5D0\uC11C elementDefine \uC774 \uC9C1\uC811 \uD638\uCD9C */\n onAttributeChanged(helperHostSet: HelperHostSet, name: string, old: string | null, newVal: any): void {\n const inst = helperHostSet.$this;\n const metaList = this.getAttrChangeMap(inst).get(name);\n if (!metaList) return;\n for (const meta of metaList) {\n if (meta.options.while === 'connected' && !inst.__swc_connected) continue;\n inst[meta.propertyKey](convertAttributeValue(newVal, meta.options.type), old, name, helperHostSet);\n }\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA6B;AAuF7B,4BAAkC;AArF3B,MAAM,oCAAoC,OAAO,IAAI,2CAA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