@dooboostore/simple-web-component 1.0.23 → 1.0.24
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 +238 -44
- package/dist/cjs/decorators/applyNode.js +129 -34
- package/dist/cjs/decorators/applyNode.js.map +2 -2
- package/dist/cjs/decorators/attribute.js +21 -2
- package/dist/cjs/decorators/attribute.js.map +2 -2
- package/dist/cjs/decorators/changedAttributeHost.js.map +2 -2
- package/dist/cjs/decorators/classList.js +60 -17
- package/dist/cjs/decorators/classList.js.map +2 -2
- package/dist/cjs/decorators/query.js +77 -2
- package/dist/cjs/decorators/query.js.map +2 -2
- package/dist/cjs/decorators/queryAll.js +77 -2
- package/dist/cjs/decorators/queryAll.js.map +2 -2
- package/dist/cjs/decorators/setAttribute.js +4 -4
- package/dist/cjs/decorators/setAttribute.js.map +2 -2
- package/dist/cjs/decorators/style.js +46 -15
- package/dist/cjs/decorators/style.js.map +2 -2
- package/dist/cjs/index.js +4 -4
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/utils/Utils.js +140 -1
- package/dist/cjs/utils/Utils.js.map +2 -2
- package/dist/esm/decorators/applyNode.js +129 -34
- package/dist/esm/decorators/applyNode.js.map +2 -2
- package/dist/esm/decorators/attribute.js +21 -2
- package/dist/esm/decorators/attribute.js.map +2 -2
- package/dist/esm/decorators/changedAttributeHost.js.map +2 -2
- package/dist/esm/decorators/classList.js +60 -17
- package/dist/esm/decorators/classList.js.map +2 -2
- package/dist/esm/decorators/query.js +77 -2
- package/dist/esm/decorators/query.js.map +2 -2
- package/dist/esm/decorators/queryAll.js +77 -2
- package/dist/esm/decorators/queryAll.js.map +2 -2
- package/dist/esm/decorators/setAttribute.js +4 -4
- package/dist/esm/decorators/setAttribute.js.map +2 -2
- package/dist/esm/decorators/style.js +46 -15
- package/dist/esm/decorators/style.js.map +2 -2
- package/dist/esm/index.js +4 -4
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/utils/Utils.js +140 -1
- package/dist/esm/utils/Utils.js.map +2 -2
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +542 -155
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
- package/dist/types/decorators/applyNode.d.ts +49 -27
- package/dist/types/decorators/applyNode.d.ts.map +1 -1
- package/dist/types/decorators/attribute.d.ts +11 -4
- package/dist/types/decorators/attribute.d.ts.map +1 -1
- package/dist/types/decorators/classList.d.ts +15 -5
- package/dist/types/decorators/classList.d.ts.map +1 -1
- package/dist/types/decorators/query.d.ts +68 -4
- package/dist/types/decorators/query.d.ts.map +1 -1
- package/dist/types/decorators/queryAll.d.ts +70 -1
- package/dist/types/decorators/queryAll.d.ts.map +1 -1
- package/dist/types/decorators/setAttribute.d.ts.map +1 -1
- package/dist/types/decorators/style.d.ts +17 -8
- package/dist/types/decorators/style.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/utils/Utils.d.ts +49 -0
- package/dist/types/utils/Utils.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +542 -155
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +3 -3
- package/src/decorators/applyNode.ts +179 -60
- package/src/decorators/attribute.ts +43 -10
- package/src/decorators/changedAttributeHost.ts +1 -1
- package/src/decorators/classList.ts +79 -17
- package/src/decorators/query.ts +147 -5
- package/src/decorators/queryAll.ts +148 -2
- package/src/decorators/setAttribute.ts +6 -5
- package/src/decorators/style.ts +67 -22
- package/src/index.ts +6 -6
- package/src/utils/Utils.ts +144 -0
- package/dist/cjs/utils/TemplateUtils.js +0 -109
- package/dist/cjs/utils/TemplateUtils.js.map +0 -7
- package/dist/esm/utils/TemplateUtils.js +0 -90
- package/dist/esm/utils/TemplateUtils.js.map +0 -7
- package/dist/types/utils/TemplateUtils.d.ts +0 -59
- package/dist/types/utils/TemplateUtils.d.ts.map +0 -1
- package/src/utils/TemplateUtils.ts +0 -92
|
@@ -20,27 +20,40 @@ function createClassListDecorator(action) {
|
|
|
20
20
|
const r = options.root || "auto";
|
|
21
21
|
const hostSet = SwcUtils.getHostSet(this);
|
|
22
22
|
const targetEls = [];
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
const applyRoot = (t) => {
|
|
24
|
+
if (!t || !(t instanceof HTMLElement)) return;
|
|
25
|
+
if (r === "auto") {
|
|
26
|
+
targetEls.push(t);
|
|
27
|
+
} else {
|
|
28
|
+
if (r === "light" || r === "all") targetEls.push(t);
|
|
29
|
+
if ((r === "shadow" || r === "all") && t.shadowRoot) {
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
if (selector === ":parentHost") applyRoot(hostSet.$parentHost);
|
|
34
|
+
else if (selector === ":appHost") applyRoot(hostSet.$appHost);
|
|
35
|
+
else if (selector === ":firstHost") applyRoot(hostSet.$firstHost);
|
|
36
|
+
else if (selector === ":lastHost") applyRoot(hostSet.$lastHost);
|
|
37
|
+
else if (selector === ":firstAppHost") applyRoot(hostSet.$firstAppHost);
|
|
38
|
+
else if (selector === ":lastAppHost") applyRoot(hostSet.$lastAppHost);
|
|
39
|
+
else if (selector === ":hosts") hostSet.$hosts.forEach(applyRoot);
|
|
40
|
+
else if (selector === ":appHosts") hostSet.$appHosts.forEach(applyRoot);
|
|
41
|
+
else if (selector === ":host" || !selector) applyRoot(this);
|
|
42
|
+
else {
|
|
30
43
|
if (r === "shadow") {
|
|
31
44
|
const found = this.shadowRoot?.querySelectorAll(selector);
|
|
32
|
-
if (found) targetEls.push(...found);
|
|
45
|
+
if (found) targetEls.push(...Array.from(found));
|
|
33
46
|
} else if (r === "light") {
|
|
34
47
|
const found = this.querySelectorAll(selector);
|
|
35
|
-
if (found) targetEls.push(...found);
|
|
48
|
+
if (found) targetEls.push(...Array.from(found));
|
|
36
49
|
} else if (r === "all") {
|
|
37
50
|
const sFound = this.shadowRoot?.querySelectorAll(selector);
|
|
38
51
|
const lFound = this.querySelectorAll(selector);
|
|
39
|
-
if (sFound) targetEls.push(...sFound);
|
|
40
|
-
if (lFound) targetEls.push(...lFound);
|
|
52
|
+
if (sFound) targetEls.push(...Array.from(sFound));
|
|
53
|
+
if (lFound) targetEls.push(...Array.from(lFound));
|
|
41
54
|
} else {
|
|
42
55
|
const found = (this.shadowRoot || this).querySelectorAll(selector);
|
|
43
|
-
if (found) targetEls.push(...found);
|
|
56
|
+
if (found) targetEls.push(...Array.from(found));
|
|
44
57
|
}
|
|
45
58
|
}
|
|
46
59
|
targetEls.forEach((targetEl) => {
|
|
@@ -83,11 +96,41 @@ const updateClassList = (selector, options = {}) => createClassListDecorator("up
|
|
|
83
96
|
const addClassList = (selector, options = {}) => createClassListDecorator("add")(selector, options);
|
|
84
97
|
const removeClassList = (selector, options = {}) => createClassListDecorator("remove")(selector, options);
|
|
85
98
|
const toggleClassList = (selector, options = {}) => createClassListDecorator("toggle")(selector, options);
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
99
|
+
function setClassListHost(targetOrOptions, propertyKey, descriptor) {
|
|
100
|
+
if (propertyKey !== void 0) {
|
|
101
|
+
const decorator = createClassListDecorator("set")(":host", {});
|
|
102
|
+
return decorator(targetOrOptions, propertyKey, descriptor);
|
|
103
|
+
}
|
|
104
|
+
return createClassListDecorator("set")(":host", targetOrOptions || {});
|
|
105
|
+
}
|
|
106
|
+
function updateClassListHost(targetOrOptions, propertyKey, descriptor) {
|
|
107
|
+
if (propertyKey !== void 0) {
|
|
108
|
+
const decorator = createClassListDecorator("update")(":host", {});
|
|
109
|
+
return decorator(targetOrOptions, propertyKey, descriptor);
|
|
110
|
+
}
|
|
111
|
+
return createClassListDecorator("update")(":host", targetOrOptions || {});
|
|
112
|
+
}
|
|
113
|
+
function addClassListHost(targetOrOptions, propertyKey, descriptor) {
|
|
114
|
+
if (propertyKey !== void 0) {
|
|
115
|
+
const decorator = createClassListDecorator("add")(":host", {});
|
|
116
|
+
return decorator(targetOrOptions, propertyKey, descriptor);
|
|
117
|
+
}
|
|
118
|
+
return createClassListDecorator("add")(":host", targetOrOptions || {});
|
|
119
|
+
}
|
|
120
|
+
function removeClassListHost(targetOrOptions, propertyKey, descriptor) {
|
|
121
|
+
if (propertyKey !== void 0) {
|
|
122
|
+
const decorator = createClassListDecorator("remove")(":host", {});
|
|
123
|
+
return decorator(targetOrOptions, propertyKey, descriptor);
|
|
124
|
+
}
|
|
125
|
+
return createClassListDecorator("remove")(":host", targetOrOptions || {});
|
|
126
|
+
}
|
|
127
|
+
function toggleClassListHost(targetOrOptions, propertyKey, descriptor) {
|
|
128
|
+
if (propertyKey !== void 0) {
|
|
129
|
+
const decorator = createClassListDecorator("toggle")(":host", {});
|
|
130
|
+
return decorator(targetOrOptions, propertyKey, descriptor);
|
|
131
|
+
}
|
|
132
|
+
return createClassListDecorator("toggle")(":host", targetOrOptions || {});
|
|
133
|
+
}
|
|
91
134
|
const findAllClassListMetadata = (target) => {
|
|
92
135
|
const result = /* @__PURE__ */ new Map();
|
|
93
136
|
const maps = ReflectUtils.findAllMetadata(CLASS_LIST_METADATA_KEY, target);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/decorators/classList.ts"],
|
|
4
|
-
"sourcesContent": ["import { ReflectUtils } from '@dooboostore/core';\nimport { ensureInit } from './elementDefine';\nimport { SwcUtils } from '../utils/Utils';\nimport { SwcQueryOptions } from '../types';\n\nexport const CLASS_LIST_METADATA_KEY = Symbol('simple-web-component:class-list');\n\nexport type ClassListAction = 'set' | 'update' | 'add' | 'remove' | 'toggle';\n\nexport interface ClassListMetadata {\n propertyKey: string | symbol;\n selector: string;\n action: ClassListAction;\n options: SwcQueryOptions;\n}\n\nfunction createClassListDecorator(action: ClassListAction) {\n return (selector: string, options: SwcQueryOptions = {}): MethodDecorator => {\n return (target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n const constructor = target.constructor;\n let metaList = ReflectUtils.getOwnMetadata(CLASS_LIST_METADATA_KEY, constructor) as Map<string | symbol, ClassListMetadata>;\n if (!metaList) {\n metaList = new Map<string | symbol, ClassListMetadata>();\n ReflectUtils.defineMetadata(CLASS_LIST_METADATA_KEY, metaList, constructor);\n }\n metaList.set(propertyKey, { propertyKey, selector, action, options });\n\n const original = descriptor.value;\n descriptor.value = async function (...args: any[]) {\n ensureInit(this);\n const res = await original.apply(this, args);\n if (res !== undefined) {\n const r = options.root || 'auto';\n const hostSet = SwcUtils.getHostSet(this as any);\n const targetEls: HTMLElement[] = [];\n\n if (selector === ':host' || !selector) {\n targetEls.push(this as any);\n } else if (selector === ':parentHost') {\n if (hostSet.$parentHost) targetEls.push(hostSet.$parentHost);\n } else if (selector === ':appHost') {\n if (hostSet.$appHost) targetEls.push(hostSet.$appHost);\n } else {\n if (r === 'shadow') {\n const found = this.shadowRoot?.querySelectorAll(selector);\n if (found) targetEls.push(...found);\n } else if (r === 'light') {\n const found = (this as any).querySelectorAll(selector);\n if (found) targetEls.push(...found);\n } else if (r === 'all') {\n const sFound = this.shadowRoot?.querySelectorAll(selector);\n const lFound = (this as any).querySelectorAll(selector);\n if (sFound) targetEls.push(...sFound);\n if (lFound) targetEls.push(...lFound);\n } else {\n // auto\n const found = (this.shadowRoot || (this as any)).querySelectorAll(selector);\n if (found) targetEls.push(...found);\n }\n }\n\n targetEls.forEach(targetEl => {\n if (action === 'set') {\n let classes = '';\n if (typeof res === 'object' && res !== null && !Array.isArray(res)) {\n classes = Object.entries(res)\n .filter(([_, force]) => !!force)\n .map(([cls]) => cls)\n .join(' ');\n } else {\n classes = Array.isArray(res) ? res.join(' ') : String(res);\n }\n targetEl.className = classes;\n } else if (action === 'update') {\n if (typeof res === 'object' && res !== null && !Array.isArray(res)) {\n Object.entries(res).forEach(([cls, force]) => {\n targetEl.classList.toggle(cls, !!force);\n });\n } else if (res !== undefined && res !== null) {\n const classes = Array.isArray(res) ? res.map(String) : [String(res)];\n targetEl.classList.add(...classes);\n }\n } else if (action === 'add') {\n const classes = Array.isArray(res) ? res.map(String) : [String(res)];\n targetEl.classList.add(...classes);\n } else if (action === 'remove') {\n const classes = Array.isArray(res) ? res.map(String) : [String(res)];\n targetEl.classList.remove(...classes);\n } else if (action === 'toggle') {\n const classes = Array.isArray(res) ? res.map(String) : [String(res)];\n classes.forEach(c => targetEl.classList.toggle(c));\n }\n });\n }\n return res;\n };\n };\n };\n}\n\n/**\n * @setClassList decorator to surgically replace all classes on a target element.\n * Returns: string | string[]\n */\nexport const setClassList = (selector: string, options: SwcQueryOptions = {}) => createClassListDecorator('set')(selector, options);\n\n/**\n * @updateClassList decorator to surgically update specific classes.\n * Returns: Record<string, boolean> (toggle with force) | string | string[] (add)\n */\nexport const updateClassList = (selector: string, options: SwcQueryOptions = {}) => createClassListDecorator('update')(selector, options);\n\n/**\n * @addClassList decorator to surgically add classes to a target element.\n * Returns: string | string[]\n */\nexport const addClassList = (selector: string, options: SwcQueryOptions = {}) => createClassListDecorator('add')(selector, options);\n\n/**\n * @removeClassList decorator to surgically remove classes from a target element.\n * Returns: string | string[]\n */\nexport const removeClassList = (selector: string, options: SwcQueryOptions = {}) => createClassListDecorator('remove')(selector, options);\n\n/**\n * @toggleClassList decorator to surgically toggle classes on a target element.\n * Returns: string | string[]\n */\nexport const toggleClassList = (selector: string, options: SwcQueryOptions = {}) => createClassListDecorator('toggle')(selector, options);\n\n// Host-specific versions (for :host selector)\n\n/**\n * @setClassListHost decorator to set classes on :host element.\n * Returns: string | string[]\n */\nexport const setClassListHost = (options: SwcQueryOptions = {}) => createClassListDecorator('set')(':host', options);\n\n/**\n * @updateClassListHost decorator to update specific classes on :host.\n * Returns: Record<string, boolean> (toggle with force) | string | string[] (add)\n */\nexport const updateClassListHost = (options: SwcQueryOptions = {}) => createClassListDecorator('update')(':host', options);\n\n/**\n * @addClassListHost decorator to add classes to :host element.\n * Returns: string | string[]\n */\nexport const addClassListHost = (options: SwcQueryOptions = {}) => createClassListDecorator('add')(':host', options);\n\n/**\n * @removeClassListHost decorator to remove classes from :host element.\n * Returns: string | string[]\n */\nexport const removeClassListHost = (options: SwcQueryOptions = {}) => createClassListDecorator('remove')(':host', options);\n\n/**\n * @toggleClassListHost decorator to toggle classes on :host element.\n * Returns: string | string[]\n */\nexport const toggleClassListHost = (options: SwcQueryOptions = {}) => createClassListDecorator('toggle')(':host', options);\n\nexport const findAllClassListMetadata = (target: any): Map<string | symbol, ClassListMetadata> => {\n const result = new Map<string | symbol, ClassListMetadata>();\n const maps = ReflectUtils.findAllMetadata<Map<string | symbol, ClassListMetadata>>(CLASS_LIST_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,SAAS,oBAAoB;AAC7B,SAAS,kBAAkB;AAC3B,SAAS,gBAAgB;AAGlB,MAAM,0BAA0B,OAAO,iCAAiC;AAW/E,SAAS,yBAAyB,QAAyB;AACzD,SAAO,CAAC,UAAkB,UAA2B,CAAC,MAAuB;AAC3E,WAAO,CAAC,QAAgB,aAA8B,eAAmC;AACvF,YAAM,cAAc,OAAO;AAC3B,UAAI,WAAW,aAAa,eAAe,yBAAyB,WAAW;AAC/E,UAAI,CAAC,UAAU;AACb,mBAAW,oBAAI,IAAwC;AACvD,qBAAa,eAAe,yBAAyB,UAAU,WAAW;AAAA,MAC5E;AACA,eAAS,IAAI,aAAa,EAAE,aAAa,UAAU,QAAQ,QAAQ,CAAC;AAEpE,YAAM,WAAW,WAAW;AAC5B,iBAAW,QAAQ,kBAAmB,MAAa;AACjD,mBAAW,IAAI;AACf,cAAM,MAAM,MAAM,SAAS,MAAM,MAAM,IAAI;AAC3C,YAAI,QAAQ,QAAW;AACrB,gBAAM,IAAI,QAAQ,QAAQ;AAC1B,gBAAM,UAAU,SAAS,WAAW,IAAW;AAC/C,gBAAM,YAA2B,CAAC;AAElC,
|
|
4
|
+
"sourcesContent": ["import { ReflectUtils } from '@dooboostore/core';\nimport { ensureInit } from './elementDefine';\nimport { SwcUtils } from '../utils/Utils';\nimport { SwcQueryOptions } from '../types';\n\nexport const CLASS_LIST_METADATA_KEY = Symbol('simple-web-component:class-list');\n\nexport type ClassListAction = 'set' | 'update' | 'add' | 'remove' | 'toggle';\n\nexport interface ClassListMetadata {\n propertyKey: string | symbol;\n selector: string;\n action: ClassListAction;\n options: SwcQueryOptions;\n}\n\nfunction createClassListDecorator(action: ClassListAction) {\n return (selector: string, options: SwcQueryOptions = {}): MethodDecorator => {\n return (target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n const constructor = target.constructor;\n let metaList = ReflectUtils.getOwnMetadata(CLASS_LIST_METADATA_KEY, constructor) as Map<string | symbol, ClassListMetadata>;\n if (!metaList) {\n metaList = new Map<string | symbol, ClassListMetadata>();\n ReflectUtils.defineMetadata(CLASS_LIST_METADATA_KEY, metaList, constructor);\n }\n metaList.set(propertyKey, { propertyKey, selector, action, options });\n\n const original = descriptor.value;\n descriptor.value = async function (...args: any[]) {\n ensureInit(this);\n const res = await original.apply(this, args);\n if (res !== undefined) {\n const r = options.root || 'auto';\n const hostSet = SwcUtils.getHostSet(this as any);\n const targetEls: HTMLElement[] = [];\n\n const applyRoot = (t: any) => {\n if (!t || !(t instanceof HTMLElement)) return;\n if (r === 'auto') {\n // Classes belong to the ELEMENT, not the ShadowRoot.\n targetEls.push(t);\n } else {\n if (r === 'light' || r === 'all') targetEls.push(t);\n if ((r === 'shadow' || r === 'all') && t.shadowRoot) {\n // Technically ShadowRoot doesn't have classList, but user might have specified it.\n // We'll skip adding shadowRoot to targetEls for class operations.\n }\n }\n };\n\n 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 if (selector === ':host' || !selector) applyRoot(this);\n else {\n if (r === 'shadow') {\n const found = this.shadowRoot?.querySelectorAll(selector);\n if (found) targetEls.push(...(Array.from(found) as HTMLElement[]));\n } else if (r === 'light') {\n const found = (this as any).querySelectorAll(selector);\n if (found) targetEls.push(...(Array.from(found) as HTMLElement[]));\n } else if (r === 'all') {\n const sFound = this.shadowRoot?.querySelectorAll(selector);\n const lFound = (this as any).querySelectorAll(selector);\n if (sFound) targetEls.push(...(Array.from(sFound) as HTMLElement[]));\n if (lFound) targetEls.push(...(Array.from(lFound) as HTMLElement[]));\n } else {\n // auto\n const found = (this.shadowRoot || (this as any)).querySelectorAll(selector);\n if (found) targetEls.push(...(Array.from(found) as HTMLElement[]));\n }\n }\n\n targetEls.forEach(targetEl => {\n if (action === 'set') {\n let classes = '';\n if (typeof res === 'object' && res !== null && !Array.isArray(res)) {\n classes = Object.entries(res)\n .filter(([_, force]) => !!force)\n .map(([cls]) => cls)\n .join(' ');\n } else {\n classes = Array.isArray(res) ? res.join(' ') : String(res);\n }\n targetEl.className = classes;\n } else if (action === 'update') {\n if (typeof res === 'object' && res !== null && !Array.isArray(res)) {\n Object.entries(res).forEach(([cls, force]) => {\n targetEl.classList.toggle(cls, !!force);\n });\n } else if (res !== undefined && res !== null) {\n const classes = Array.isArray(res) ? res.map(String) : [String(res)];\n targetEl.classList.add(...classes);\n }\n } else if (action === 'add') {\n const classes = Array.isArray(res) ? res.map(String) : [String(res)];\n targetEl.classList.add(...classes);\n } else if (action === 'remove') {\n const classes = Array.isArray(res) ? res.map(String) : [String(res)];\n targetEl.classList.remove(...classes);\n } else if (action === 'toggle') {\n const classes = Array.isArray(res) ? res.map(String) : [String(res)];\n classes.forEach(c => targetEl.classList.toggle(c));\n }\n });\n }\n return res;\n };\n };\n };\n}\n\n/**\n * @setClassList decorator to surgically replace all classes on a target element.\n * Returns: string | string[]\n */\nexport const setClassList = (selector: string, options: SwcQueryOptions = {}) => createClassListDecorator('set')(selector, options);\n\n/**\n * @updateClassList decorator to surgically update specific classes.\n * Returns: Record<string, boolean> (toggle with force) | string | string[] (add)\n */\nexport const updateClassList = (selector: string, options: SwcQueryOptions = {}) => createClassListDecorator('update')(selector, options);\n\n/**\n * @addClassList decorator to surgically add classes to a target element.\n * Returns: string | string[]\n */\nexport const addClassList = (selector: string, options: SwcQueryOptions = {}) => createClassListDecorator('add')(selector, options);\n\n/**\n * @removeClassList decorator to surgically remove classes from a target element.\n * Returns: string | string[]\n */\nexport const removeClassList = (selector: string, options: SwcQueryOptions = {}) => createClassListDecorator('remove')(selector, options);\n\n/**\n * @toggleClassList decorator to surgically toggle classes on a target element.\n * Returns: string | string[]\n */\nexport const toggleClassList = (selector: string, options: SwcQueryOptions = {}) => createClassListDecorator('toggle')(selector, options);\n\n// Host-specific versions (for :host selector)\n\n/**\n * @setClassListHost decorator to set classes on :host element.\n * Returns: string | string[]\n */\nexport function setClassListHost(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): any;\nexport function setClassListHost(): MethodDecorator;\nexport function setClassListHost(options: SwcQueryOptions): MethodDecorator;\nexport function setClassListHost(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {\n if (propertyKey !== undefined) {\n const decorator = createClassListDecorator('set')(':host', {});\n return decorator(targetOrOptions, propertyKey, descriptor);\n }\n return createClassListDecorator('set')(':host', (targetOrOptions as SwcQueryOptions) || {});\n}\n\n/**\n * @updateClassListHost decorator to update specific classes on :host.\n * Returns: Record<string, boolean> (toggle with force) | string | string[] (add)\n */\nexport function updateClassListHost(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): any;\nexport function updateClassListHost(): MethodDecorator;\nexport function updateClassListHost(options: SwcQueryOptions): MethodDecorator;\nexport function updateClassListHost(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {\n if (propertyKey !== undefined) {\n const decorator = createClassListDecorator('update')(':host', {});\n return decorator(targetOrOptions, propertyKey, descriptor);\n }\n return createClassListDecorator('update')(':host', (targetOrOptions as SwcQueryOptions) || {});\n}\n\n/**\n * @addClassListHost decorator to add classes to :host element.\n * Returns: string | string[]\n */\nexport function addClassListHost(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): any;\nexport function addClassListHost(): MethodDecorator;\nexport function addClassListHost(options: SwcQueryOptions): MethodDecorator;\nexport function addClassListHost(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {\n if (propertyKey !== undefined) {\n const decorator = createClassListDecorator('add')(':host', {});\n return decorator(targetOrOptions, propertyKey, descriptor);\n }\n return createClassListDecorator('add')(':host', (targetOrOptions as SwcQueryOptions) || {});\n}\n\n/**\n * @removeClassListHost decorator to remove classes from :host element.\n * Returns: string | string[]\n */\nexport function removeClassListHost(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): any;\nexport function removeClassListHost(): MethodDecorator;\nexport function removeClassListHost(options: SwcQueryOptions): MethodDecorator;\nexport function removeClassListHost(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {\n if (propertyKey !== undefined) {\n const decorator = createClassListDecorator('remove')(':host', {});\n return decorator(targetOrOptions, propertyKey, descriptor);\n }\n return createClassListDecorator('remove')(':host', (targetOrOptions as SwcQueryOptions) || {});\n}\n\n/**\n * @toggleClassListHost decorator to toggle classes on :host element.\n * Returns: string | string[]\n */\nexport function toggleClassListHost(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): any;\nexport function toggleClassListHost(): MethodDecorator;\nexport function toggleClassListHost(options: SwcQueryOptions): MethodDecorator;\nexport function toggleClassListHost(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {\n if (propertyKey !== undefined) {\n const decorator = createClassListDecorator('toggle')(':host', {});\n return decorator(targetOrOptions, propertyKey, descriptor);\n }\n return createClassListDecorator('toggle')(':host', (targetOrOptions as SwcQueryOptions) || {});\n}\n\nexport const findAllClassListMetadata = (target: any): Map<string | symbol, ClassListMetadata> => {\n const result = new Map<string | symbol, ClassListMetadata>();\n const maps = ReflectUtils.findAllMetadata<Map<string | symbol, ClassListMetadata>>(CLASS_LIST_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,SAAS,oBAAoB;AAC7B,SAAS,kBAAkB;AAC3B,SAAS,gBAAgB;AAGlB,MAAM,0BAA0B,OAAO,iCAAiC;AAW/E,SAAS,yBAAyB,QAAyB;AACzD,SAAO,CAAC,UAAkB,UAA2B,CAAC,MAAuB;AAC3E,WAAO,CAAC,QAAgB,aAA8B,eAAmC;AACvF,YAAM,cAAc,OAAO;AAC3B,UAAI,WAAW,aAAa,eAAe,yBAAyB,WAAW;AAC/E,UAAI,CAAC,UAAU;AACb,mBAAW,oBAAI,IAAwC;AACvD,qBAAa,eAAe,yBAAyB,UAAU,WAAW;AAAA,MAC5E;AACA,eAAS,IAAI,aAAa,EAAE,aAAa,UAAU,QAAQ,QAAQ,CAAC;AAEpE,YAAM,WAAW,WAAW;AAC5B,iBAAW,QAAQ,kBAAmB,MAAa;AACjD,mBAAW,IAAI;AACf,cAAM,MAAM,MAAM,SAAS,MAAM,MAAM,IAAI;AAC3C,YAAI,QAAQ,QAAW;AACrB,gBAAM,IAAI,QAAQ,QAAQ;AAC1B,gBAAM,UAAU,SAAS,WAAW,IAAW;AAC/C,gBAAM,YAA2B,CAAC;AAElC,gBAAM,YAAY,CAAC,MAAW;AAC5B,gBAAI,CAAC,KAAK,EAAE,aAAa,aAAc;AACvC,gBAAI,MA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iB,iBAAuB,aAA+B,YAAsC;AAC3H,MAAI,gBAAgB,QAAW;AAC7B,UAAM,YAAY,yBAAyB,KAAK,EAAE,SAAS,CAAC,CAAC;AAC7D,WAAO,UAAU,iBAAiB,aAAa,UAAU;AAAA,EAC3D;AACA,SAAO,yBAAyB,KAAK,EAAE,SAAU,mBAAuC,CAAC,CAAC;AAC5F;AASO,SAAS,oBAAoB,iBAAuB,aAA+B,YAAsC;AAC9H,MAAI,gBAAgB,QAAW;AAC7B,UAAM,YAAY,yBAAyB,QAAQ,EAAE,SAAS,CAAC,CAAC;AAChE,WAAO,UAAU,iBAAiB,aAAa,UAAU;AAAA,EAC3D;AACA,SAAO,yBAAyB,QAAQ,EAAE,SAAU,mBAAuC,CAAC,CAAC;AAC/F;AASO,SAAS,oBAAoB,iBAAuB,aAA+B,YAAsC;AAC9H,MAAI,gBAAgB,QAAW;AAC7B,UAAM,YAAY,yBAAyB,QAAQ,EAAE,SAAS,CAAC,CAAC;AAChE,WAAO,UAAU,iBAAiB,aAAa,UAAU;AAAA,EAC3D;AACA,SAAO,yBAAyB,QAAQ,EAAE,SAAU,mBAAuC,CAAC,CAAC;AAC/F;AAEO,MAAM,2BAA2B,CAAC,WAAyD;AAChG,QAAM,SAAS,oBAAI,IAAwC;AAC3D,QAAM,OAAO,aAAa,gBAAyD,yBAAyB,MAAM;AAClH,OAAK,QAAQ,SAAO;AAClB,QAAI,eAAe,KAAK;AACtB,UAAI,QAAQ,CAAC,GAAG,MAAM,OAAO,IAAI,GAAG,CAAC,CAAC;AAAA,IACxC;AAAA,EACF,CAAC;AACD,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -99,12 +99,87 @@ const getQueryMetadata = (target) => {
|
|
|
99
99
|
const constructor = target instanceof Function ? target : target.constructor;
|
|
100
100
|
return ReflectUtils.getMetadata(QUERY_METADATA_KEY, constructor);
|
|
101
101
|
};
|
|
102
|
-
function queryHost(
|
|
103
|
-
|
|
102
|
+
function queryHost(targetOrOptions, propertyKey) {
|
|
103
|
+
if (propertyKey !== void 0 && (typeof propertyKey === "string" || typeof propertyKey === "symbol")) {
|
|
104
|
+
return query(":host", {})(targetOrOptions, propertyKey);
|
|
105
|
+
}
|
|
106
|
+
if (typeof targetOrOptions === "object" && targetOrOptions !== null) {
|
|
107
|
+
return query(":host", targetOrOptions);
|
|
108
|
+
} else {
|
|
109
|
+
return query(":host", {});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
const host = queryHost;
|
|
113
|
+
function parentHost(targetOrOptions, propertyKey) {
|
|
114
|
+
if (propertyKey !== void 0 && (typeof propertyKey === "string" || typeof propertyKey === "symbol")) {
|
|
115
|
+
return query(":parentHost", {})(targetOrOptions, propertyKey);
|
|
116
|
+
}
|
|
117
|
+
if (typeof targetOrOptions === "object" && targetOrOptions !== null) {
|
|
118
|
+
return query(":parentHost", targetOrOptions);
|
|
119
|
+
} else {
|
|
120
|
+
return query(":parentHost", {});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function appHost(targetOrOptions, propertyKey) {
|
|
124
|
+
if (propertyKey !== void 0 && (typeof propertyKey === "string" || typeof propertyKey === "symbol")) {
|
|
125
|
+
return query(":appHost", {})(targetOrOptions, propertyKey);
|
|
126
|
+
}
|
|
127
|
+
if (typeof targetOrOptions === "object" && targetOrOptions !== null) {
|
|
128
|
+
return query(":appHost", targetOrOptions);
|
|
129
|
+
} else {
|
|
130
|
+
return query(":appHost", {});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function firstHost(targetOrOptions, propertyKey) {
|
|
134
|
+
if (propertyKey !== void 0 && (typeof propertyKey === "string" || typeof propertyKey === "symbol")) {
|
|
135
|
+
return query(":firstHost", {})(targetOrOptions, propertyKey);
|
|
136
|
+
}
|
|
137
|
+
if (typeof targetOrOptions === "object" && targetOrOptions !== null) {
|
|
138
|
+
return query(":firstHost", targetOrOptions);
|
|
139
|
+
} else {
|
|
140
|
+
return query(":firstHost", {});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
function lastHost(targetOrOptions, propertyKey) {
|
|
144
|
+
if (propertyKey !== void 0 && (typeof propertyKey === "string" || typeof propertyKey === "symbol")) {
|
|
145
|
+
return query(":lastHost", {})(targetOrOptions, propertyKey);
|
|
146
|
+
}
|
|
147
|
+
if (typeof targetOrOptions === "object" && targetOrOptions !== null) {
|
|
148
|
+
return query(":lastHost", targetOrOptions);
|
|
149
|
+
} else {
|
|
150
|
+
return query(":lastHost", {});
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function firstAppHost(targetOrOptions, propertyKey) {
|
|
154
|
+
if (propertyKey !== void 0 && (typeof propertyKey === "string" || typeof propertyKey === "symbol")) {
|
|
155
|
+
return query(":firstAppHost", {})(targetOrOptions, propertyKey);
|
|
156
|
+
}
|
|
157
|
+
if (typeof targetOrOptions === "object" && targetOrOptions !== null) {
|
|
158
|
+
return query(":firstAppHost", targetOrOptions);
|
|
159
|
+
} else {
|
|
160
|
+
return query(":firstAppHost", {});
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
function lastAppHost(targetOrOptions, propertyKey) {
|
|
164
|
+
if (propertyKey !== void 0 && (typeof propertyKey === "string" || typeof propertyKey === "symbol")) {
|
|
165
|
+
return query(":lastAppHost", {})(targetOrOptions, propertyKey);
|
|
166
|
+
}
|
|
167
|
+
if (typeof targetOrOptions === "object" && targetOrOptions !== null) {
|
|
168
|
+
return query(":lastAppHost", targetOrOptions);
|
|
169
|
+
} else {
|
|
170
|
+
return query(":lastAppHost", {});
|
|
171
|
+
}
|
|
104
172
|
}
|
|
105
173
|
export {
|
|
106
174
|
QUERY_METADATA_KEY,
|
|
175
|
+
appHost,
|
|
176
|
+
firstAppHost,
|
|
177
|
+
firstHost,
|
|
107
178
|
getQueryMetadata,
|
|
179
|
+
host,
|
|
180
|
+
lastAppHost,
|
|
181
|
+
lastHost,
|
|
182
|
+
parentHost,
|
|
108
183
|
query,
|
|
109
184
|
queryHost
|
|
110
185
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/decorators/query.ts"],
|
|
4
|
-
"sourcesContent": ["import { ReflectUtils } from '@dooboostore/core';\nimport { getElementConfig, ensureInit } from './elementDefine';\nimport { SwcUtils } from '../utils/Utils';\nimport { SpecialSelector, SwcQueryOptions } from '../types';\n\nexport interface QueryMetadata {\n propertyKey: string | symbol;\n selector: string;\n options: SwcQueryOptions;\n}\n\nexport const QUERY_METADATA_KEY = Symbol('simple-web-component:query');\n\nexport function query(target: SpecialSelector): PropertyDecorator;\nexport function query(selector: string, options?: SwcQueryOptions): PropertyDecorator;\n/**\n * @query decorator to inject a single element into a class property.\n */\nexport function query(selectorOrTarget: string, options: any = {}): PropertyDecorator {\n return (targetObj: Object, propertyKey: string | symbol, descriptor?: never): void => {\n if (descriptor !== undefined) {\n throw new Error(`@query decorator cannot be used on methods. (Method: ${String(propertyKey)})`);\n }\n\n const constructor = targetObj.constructor;\n let queries = ReflectUtils.getMetadata<QueryMetadata[]>(QUERY_METADATA_KEY, constructor);\n if (!queries) {\n queries = [];\n ReflectUtils.defineMetadata(QUERY_METADATA_KEY, queries, constructor);\n }\n queries.push({ propertyKey, selector: selectorOrTarget, options });\n\n // const propertyType = Reflect.getMetadata(\"design:type\", targetObj, propertyKey);\n // console.log(`Property ${String(propertyKey)} type is:`, propertyType.name);\n Object.defineProperty(targetObj, propertyKey, {\n get(this: HTMLElement) {\n ensureInit(this);\n const selector = selectorOrTarget;\n\n const r = options.root || 'auto';\n const applyRoot = (t: any) => {\n if (!t || !(t instanceof HTMLElement)) return t;\n if (r === 'auto') return t.shadowRoot || t;\n if (r === 'shadow') return t.shadowRoot;\n if (r === 'light') return t;\n if (r === 'all') return t.shadowRoot || t; // query only returns one, so shadow preferred\n return t;\n };\n\n // --- Special Selectors: HostSet ---\n const hostSet = SwcUtils.getHostSet(this);\n if (selector === ':parentHost') return applyRoot(hostSet.$parentHost);\n if (selector === ':appHost') return applyRoot(hostSet.$appHost);\n if (selector === ':firstHost') return applyRoot(hostSet.$firstHost);\n if (selector === ':lastHost') return applyRoot(hostSet.$lastHost);\n if (selector === ':firstAppHost') return applyRoot(hostSet.$firstAppHost);\n if (selector === ':lastAppHost') return applyRoot(hostSet.$lastAppHost);\n\n // --- Special Selectors: Env ---\n const config = getElementConfig(this);\n const win = config?.window || window;\n if (selector === ':window') return win;\n if (selector === ':document') return win.document;\n if (selector === ':host') return applyRoot(this);\n\n // --- Standard Selectors ---\n if (r === 'shadow') return this.shadowRoot ? this.shadowRoot.querySelector(selector) : null;\n if (r === 'light') return this.querySelector(selector);\n if (r === 'all') {\n const shadowMatch = this.shadowRoot ? this.shadowRoot.querySelector(selector) : null;\n return shadowMatch || this.querySelector(selector);\n }\n return (this.shadowRoot || this).querySelector(selector);\n },\n set(this: HTMLElement, nv: any) {\n ensureInit(this);\n if (nv === null || nv === undefined) {\n const selector = selectorOrTarget;\n if (selector.startsWith(':') && selector !== ':host') return;\n\n const r = options.root || 'auto';\n const targets: Element[] = [];\n\n if (r === 'shadow') {\n if (this.shadowRoot?.querySelector(selector)) targets.push(this.shadowRoot.querySelector(selector)!);\n } else if (r === 'light') {\n if (this.querySelector(selector)) targets.push(this.querySelector(selector)!);\n } else if (r === 'all') {\n if (this.shadowRoot?.querySelector(selector)) targets.push(this.shadowRoot.querySelector(selector)!);\n if (this.querySelector(selector)) targets.push(this.querySelector(selector)!);\n } else {\n const el = (this.shadowRoot || this).querySelector(selector);\n if (el) targets.push(el);\n }\n\n targets.forEach(t => t.remove());\n }\n },\n enumerable: true,\n configurable: true\n });\n };\n}\n\nexport const getQueryMetadata = (target: any): QueryMetadata[] | undefined => {\n const constructor = target instanceof Function ? target : target.constructor;\n return ReflectUtils.getMetadata(QUERY_METADATA_KEY, constructor);\n};\n\n/**\n * @hostQuery decorator - simplified version of @query for :host selector\n * Usage: @hostQuery()\n * Usage: @host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cAAc,QAAQ;AAC3D,gBAAI;AAAI,sBAAQ,KAAK,EAAE;UACzB;AAEA,kBAAQ,QAAQ,OAAK,EAAE,OAAM,CAAE;QACjC;MACF;MACA,YAAY;MACZ,cAAc;KACf;EACH;AACF;AAEO,MAAM,mBAAmB,CAAC,WAA4C;AAC3E,QAAM,cAAc,kBAAkB,WAAW,SAAS,OAAO;AACjE,SAAO,aAAa,YAAY,oBAAoB,WAAW;AACjE;
|
|
4
|
+
"sourcesContent": ["import { ReflectUtils } from '@dooboostore/core';\nimport { getElementConfig, ensureInit } from './elementDefine';\nimport { SwcUtils } from '../utils/Utils';\nimport { SpecialSelector, SwcQueryOptions } from '../types';\n\nexport interface QueryMetadata {\n propertyKey: string | symbol;\n selector: string;\n options: SwcQueryOptions;\n}\n\nexport const QUERY_METADATA_KEY = Symbol('simple-web-component:query');\n\nexport function query(target: SpecialSelector): PropertyDecorator;\nexport function query(selector: string, options?: SwcQueryOptions): PropertyDecorator;\n/**\n * @query decorator to inject a single element into a class property.\n */\nexport function query(selectorOrTarget: string, options: any = {}): PropertyDecorator {\n return (targetObj: Object, propertyKey: string | symbol, descriptor?: never): void => {\n if (descriptor !== undefined) {\n throw new Error(`@query decorator cannot be used on methods. (Method: ${String(propertyKey)})`);\n }\n\n const constructor = targetObj.constructor;\n let queries = ReflectUtils.getMetadata<QueryMetadata[]>(QUERY_METADATA_KEY, constructor);\n if (!queries) {\n queries = [];\n ReflectUtils.defineMetadata(QUERY_METADATA_KEY, queries, constructor);\n }\n queries.push({ propertyKey, selector: selectorOrTarget, options });\n\n // const propertyType = Reflect.getMetadata(\"design:type\", targetObj, propertyKey);\n // console.log(`Property ${String(propertyKey)} type is:`, propertyType.name);\n Object.defineProperty(targetObj, propertyKey, {\n get(this: HTMLElement) {\n ensureInit(this);\n const selector = selectorOrTarget;\n\n const r = options.root || 'auto';\n const applyRoot = (t: any) => {\n if (!t || !(t instanceof HTMLElement)) return t;\n if (r === 'auto') return t.shadowRoot || t;\n if (r === 'shadow') return t.shadowRoot;\n if (r === 'light') return t;\n if (r === 'all') return t.shadowRoot || t; // query only returns one, so shadow preferred\n return t;\n };\n\n // --- Special Selectors: HostSet ---\n const hostSet = SwcUtils.getHostSet(this);\n if (selector === ':parentHost') return applyRoot(hostSet.$parentHost);\n if (selector === ':appHost') return applyRoot(hostSet.$appHost);\n if (selector === ':firstHost') return applyRoot(hostSet.$firstHost);\n if (selector === ':lastHost') return applyRoot(hostSet.$lastHost);\n if (selector === ':firstAppHost') return applyRoot(hostSet.$firstAppHost);\n if (selector === ':lastAppHost') return applyRoot(hostSet.$lastAppHost);\n\n // --- Special Selectors: Env ---\n const config = getElementConfig(this);\n const win = config?.window || window;\n if (selector === ':window') return win;\n if (selector === ':document') return win.document;\n if (selector === ':host') return applyRoot(this);\n\n // --- Standard Selectors ---\n if (r === 'shadow') return this.shadowRoot ? this.shadowRoot.querySelector(selector) : null;\n if (r === 'light') return this.querySelector(selector);\n if (r === 'all') {\n const shadowMatch = this.shadowRoot ? this.shadowRoot.querySelector(selector) : null;\n return shadowMatch || this.querySelector(selector);\n }\n return (this.shadowRoot || this).querySelector(selector);\n },\n set(this: HTMLElement, nv: any) {\n ensureInit(this);\n if (nv === null || nv === undefined) {\n const selector = selectorOrTarget;\n if (selector.startsWith(':') && selector !== ':host') return;\n\n const r = options.root || 'auto';\n const targets: Element[] = [];\n\n if (r === 'shadow') {\n if (this.shadowRoot?.querySelector(selector)) targets.push(this.shadowRoot.querySelector(selector)!);\n } else if (r === 'light') {\n if (this.querySelector(selector)) targets.push(this.querySelector(selector)!);\n } else if (r === 'all') {\n if (this.shadowRoot?.querySelector(selector)) targets.push(this.shadowRoot.querySelector(selector)!);\n if (this.querySelector(selector)) targets.push(this.querySelector(selector)!);\n } else {\n const el = (this.shadowRoot || this).querySelector(selector);\n if (el) targets.push(el);\n }\n\n targets.forEach(t => t.remove());\n }\n },\n enumerable: true,\n configurable: true\n });\n };\n}\n\nexport const getQueryMetadata = (target: any): QueryMetadata[] | undefined => {\n const constructor = target instanceof Function ? target : target.constructor;\n return ReflectUtils.getMetadata(QUERY_METADATA_KEY, constructor);\n};\n\n/**\n * @queryHost decorator - simplified version of @query for :host selector\n * Usage: @queryHost testzzs: HTMLElement | undefined;\n * Usage: @queryHost() testzzs: HTMLElement | undefined;\n * Usage: @queryHost({ root: 'shadow' }) testzzs: HTMLElement | undefined;\n */\nexport function queryHost(target: Object, propertyKey: string | symbol): void;\nexport function queryHost(): PropertyDecorator;\nexport function queryHost(options: SwcQueryOptions): PropertyDecorator;\nexport function queryHost(targetOrOptions?: any, propertyKey?: string | symbol): any {\n // Direct decorator usage: @queryHost (no parentheses)\n if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {\n return query(':host', {})(targetOrOptions, propertyKey);\n }\n\n // @queryHost() or @queryHost(options)\n if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {\n return query(':host', targetOrOptions as SwcQueryOptions);\n } else {\n return query(':host', {});\n }\n}\n\n/**\n * @host - Alias for @queryHost decorator\n * Usage: @host element: HTMLElement | undefined;\n * Usage: @host() element: HTMLElement | undefined;\n * Usage: @host({ root: 'shadow' }) element: HTMLElement | undefined;\n */\nexport const host = queryHost;\n\n/**\n * @parentHost - Query :parentHost (Direct parent SWC component)\n * Usage: @parentHost parent: HTMLElement | undefined;\n * Usage: @parentHost() parent: HTMLElement | undefined;\n * Usage: @parentHost({ root: 'shadow' }) parent: HTMLElement | undefined;\n */\nexport function parentHost(target: Object, propertyKey: string | symbol): void;\nexport function parentHost(): PropertyDecorator;\nexport function parentHost(options: SwcQueryOptions): PropertyDecorator;\nexport function parentHost(targetOrOptions?: any, propertyKey?: string | symbol): any {\n if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {\n return query(':parentHost', {})(targetOrOptions, propertyKey);\n }\n if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {\n return query(':parentHost', targetOrOptions as SwcQueryOptions);\n } else {\n return query(':parentHost', {});\n }\n}\n\n/**\n * @appHost - Query :appHost (Nearest <swc-app>)\n * Usage: @appHost app: SwcAppInterface | undefined;\n * Usage: @appHost() app: SwcAppInterface | undefined;\n * Usage: @appHost({ root: 'shadow' }) app: SwcAppInterface | undefined;\n */\nexport function appHost(target: Object, propertyKey: string | symbol): void;\nexport function appHost(): PropertyDecorator;\nexport function appHost(options: SwcQueryOptions): PropertyDecorator;\nexport function appHost(targetOrOptions?: any, propertyKey?: string | symbol): any {\n if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {\n return query(':appHost', {})(targetOrOptions, propertyKey);\n }\n if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {\n return query(':appHost', targetOrOptions as SwcQueryOptions);\n } else {\n return query(':appHost', {});\n }\n}\n\n/**\n * @firstHost - Query :firstHost (First component in hierarchy)\n * Usage: @firstHost first: HTMLElement | undefined;\n * Usage: @firstHost() first: HTMLElement | undefined;\n * Usage: @firstHost({ root: 'shadow' }) first: HTMLElement | undefined;\n */\nexport function firstHost(target: Object, propertyKey: string | symbol): void;\nexport function firstHost(): PropertyDecorator;\nexport function firstHost(options: SwcQueryOptions): PropertyDecorator;\nexport function firstHost(targetOrOptions?: any, propertyKey?: string | symbol): any {\n if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {\n return query(':firstHost', {})(targetOrOptions, propertyKey);\n }\n if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {\n return query(':firstHost', targetOrOptions as SwcQueryOptions);\n } else {\n return query(':firstHost', {});\n }\n}\n\n/**\n * @lastHost - Query :lastHost (Last component in hierarchy)\n * Usage: @lastHost last: HTMLElement | undefined;\n * Usage: @lastHost() last: HTMLElement | undefined;\n * Usage: @lastHost({ root: 'shadow' }) last: HTMLElement | undefined;\n */\nexport function lastHost(target: Object, propertyKey: string | symbol): void;\nexport function lastHost(): PropertyDecorator;\nexport function lastHost(options: SwcQueryOptions): PropertyDecorator;\nexport function lastHost(targetOrOptions?: any, propertyKey?: string | symbol): any {\n if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {\n return query(':lastHost', {})(targetOrOptions, propertyKey);\n }\n if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {\n return query(':lastHost', targetOrOptions as SwcQueryOptions);\n } else {\n return query(':lastHost', {});\n }\n}\n\n/**\n * @firstAppHost - Query :firstAppHost (First <swc-app> in hierarchy)\n * Usage: @firstAppHost app: SwcAppInterface | undefined;\n * Usage: @firstAppHost() app: SwcAppInterface | undefined;\n * Usage: @firstAppHost({ root: 'shadow' }) app: SwcAppInterface | undefined;\n */\nexport function firstAppHost(target: Object, propertyKey: string | symbol): void;\nexport function firstAppHost(): PropertyDecorator;\nexport function firstAppHost(options: SwcQueryOptions): PropertyDecorator;\nexport function firstAppHost(targetOrOptions?: any, propertyKey?: string | symbol): any {\n if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {\n return query(':firstAppHost', {})(targetOrOptions, propertyKey);\n }\n if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {\n return query(':firstAppHost', targetOrOptions as SwcQueryOptions);\n } else {\n return query(':firstAppHost', {});\n }\n}\n\n/**\n * @lastAppHost - Query :lastAppHost (Last <swc-app> in hierarchy)\n * Usage: @lastAppHost app: SwcAppInterface | undefined;\n * Usage: @lastAppHost() app: SwcAppInterface | undefined;\n * Usage: @lastAppHost({ root: 'shadow' }) app: SwcAppInterface | undefined;\n */\nexport function lastAppHost(target: Object, propertyKey: string | symbol): void;\nexport function lastAppHost(): PropertyDecorator;\nexport function lastAppHost(options: SwcQueryOptions): PropertyDecorator;\nexport function lastAppHost(targetOrOptions?: any, propertyKey?: string | symbol): any {\n if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {\n return query(':lastAppHost', {})(targetOrOptions, propertyKey);\n }\n if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {\n return query(':lastApp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@ const getQueryAllMetadata = (target) => {
|
|
|
96
96
|
const constructor = target instanceof Function ? target : target.constructor;
|
|
97
97
|
return ReflectUtils.getMetadata(QUERY_ALL_METADATA_KEY, constructor);
|
|
98
98
|
};
|
|
99
|
-
function queryAllHost(
|
|
100
|
-
|
|
99
|
+
function queryAllHost(targetOrOptions, propertyKey) {
|
|
100
|
+
if (propertyKey !== void 0 && (typeof propertyKey === "string" || typeof propertyKey === "symbol")) {
|
|
101
|
+
return queryAll(":host", {})(targetOrOptions, propertyKey);
|
|
102
|
+
}
|
|
103
|
+
if (typeof targetOrOptions === "object" && targetOrOptions !== null) {
|
|
104
|
+
return queryAll(":host", targetOrOptions);
|
|
105
|
+
} else {
|
|
106
|
+
return queryAll(":host", {});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
const allHost = queryAllHost;
|
|
110
|
+
function allParentHost(targetOrOptions, propertyKey) {
|
|
111
|
+
if (propertyKey !== void 0 && (typeof propertyKey === "string" || typeof propertyKey === "symbol")) {
|
|
112
|
+
return queryAll(":parentHost", {})(targetOrOptions, propertyKey);
|
|
113
|
+
}
|
|
114
|
+
if (typeof targetOrOptions === "object" && targetOrOptions !== null) {
|
|
115
|
+
return queryAll(":parentHost", targetOrOptions);
|
|
116
|
+
} else {
|
|
117
|
+
return queryAll(":parentHost", {});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function allAppHost(targetOrOptions, propertyKey) {
|
|
121
|
+
if (propertyKey !== void 0 && (typeof propertyKey === "string" || typeof propertyKey === "symbol")) {
|
|
122
|
+
return queryAll(":appHost", {})(targetOrOptions, propertyKey);
|
|
123
|
+
}
|
|
124
|
+
if (typeof targetOrOptions === "object" && targetOrOptions !== null) {
|
|
125
|
+
return queryAll(":appHost", targetOrOptions);
|
|
126
|
+
} else {
|
|
127
|
+
return queryAll(":appHost", {});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function allFirstHost(targetOrOptions, propertyKey) {
|
|
131
|
+
if (propertyKey !== void 0 && (typeof propertyKey === "string" || typeof propertyKey === "symbol")) {
|
|
132
|
+
return queryAll(":firstHost", {})(targetOrOptions, propertyKey);
|
|
133
|
+
}
|
|
134
|
+
if (typeof targetOrOptions === "object" && targetOrOptions !== null) {
|
|
135
|
+
return queryAll(":firstHost", targetOrOptions);
|
|
136
|
+
} else {
|
|
137
|
+
return queryAll(":firstHost", {});
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
function allLastHost(targetOrOptions, propertyKey) {
|
|
141
|
+
if (propertyKey !== void 0 && (typeof propertyKey === "string" || typeof propertyKey === "symbol")) {
|
|
142
|
+
return queryAll(":lastHost", {})(targetOrOptions, propertyKey);
|
|
143
|
+
}
|
|
144
|
+
if (typeof targetOrOptions === "object" && targetOrOptions !== null) {
|
|
145
|
+
return queryAll(":lastHost", targetOrOptions);
|
|
146
|
+
} else {
|
|
147
|
+
return queryAll(":lastHost", {});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function allFirstAppHost(targetOrOptions, propertyKey) {
|
|
151
|
+
if (propertyKey !== void 0 && (typeof propertyKey === "string" || typeof propertyKey === "symbol")) {
|
|
152
|
+
return queryAll(":firstAppHost", {})(targetOrOptions, propertyKey);
|
|
153
|
+
}
|
|
154
|
+
if (typeof targetOrOptions === "object" && targetOrOptions !== null) {
|
|
155
|
+
return queryAll(":firstAppHost", targetOrOptions);
|
|
156
|
+
} else {
|
|
157
|
+
return queryAll(":firstAppHost", {});
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
function allLastAppHost(targetOrOptions, propertyKey) {
|
|
161
|
+
if (propertyKey !== void 0 && (typeof propertyKey === "string" || typeof propertyKey === "symbol")) {
|
|
162
|
+
return queryAll(":lastAppHost", {})(targetOrOptions, propertyKey);
|
|
163
|
+
}
|
|
164
|
+
if (typeof targetOrOptions === "object" && targetOrOptions !== null) {
|
|
165
|
+
return queryAll(":lastAppHost", targetOrOptions);
|
|
166
|
+
} else {
|
|
167
|
+
return queryAll(":lastAppHost", {});
|
|
168
|
+
}
|
|
101
169
|
}
|
|
102
170
|
export {
|
|
103
171
|
QUERY_ALL_METADATA_KEY,
|
|
172
|
+
allAppHost,
|
|
173
|
+
allFirstAppHost,
|
|
174
|
+
allFirstHost,
|
|
175
|
+
allHost,
|
|
176
|
+
allLastAppHost,
|
|
177
|
+
allLastHost,
|
|
178
|
+
allParentHost,
|
|
104
179
|
getQueryAllMetadata,
|
|
105
180
|
queryAll,
|
|
106
181
|
queryAllHost
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/decorators/queryAll.ts"],
|
|
4
|
-
"sourcesContent": ["import { ReflectUtils } from '@dooboostore/core';\nimport { getElementConfig, ensureInit } from './elementDefine';\nimport { SwcUtils } from '../utils/Utils';\nimport { SpecialSelector, SwcQueryOptions } from '../types';\n\nexport interface QueryAllMetadata {\n propertyKey: string | symbol;\n selector: string;\n options: SwcQueryOptions;\n}\n\nexport const QUERY_ALL_METADATA_KEY = Symbol('simple-web-component:query-all');\n\nexport function queryAll(target: SpecialSelector): PropertyDecorator;\nexport function queryAll(selector: string, options?: SwcQueryOptions): PropertyDecorator;\n/**\n * @queryAll decorator to inject a list of elements into a class property.\n */\nexport function queryAll(selectorOrTarget: string, options: any = {}): PropertyDecorator {\n return (targetObj: Object, propertyKey: string | symbol, descriptor?: never): void => {\n if (descriptor !== undefined) {\n throw new Error(`@queryAll decorator cannot be used on methods. (Method: ${String(propertyKey)})`);\n }\n\n const constructor = targetObj.constructor;\n let queries = ReflectUtils.getMetadata<QueryAllMetadata[]>(QUERY_ALL_METADATA_KEY, constructor);\n if (!queries) {\n queries = [];\n ReflectUtils.defineMetadata(QUERY_ALL_METADATA_KEY, queries, constructor);\n }\n queries.push({ propertyKey, selector: selectorOrTarget, options });\n\n Object.defineProperty(targetObj, propertyKey, {\n get(this: HTMLElement) {\n ensureInit(this);\n const selector = selectorOrTarget;\n\n const r = options.root || 'auto';\n const applyRoot = (t: any): any[] => {\n if (!t) return [];\n const items = Array.isArray(t) ? t : [t];\n const results: any[] = [];\n items.forEach(it => {\n if (!(it instanceof HTMLElement)) {\n results.push(it);\n return;\n }\n if (r === 'auto') results.push(it.shadowRoot || it);\n else {\n if (r === 'light' || r === 'all') results.push(it);\n if ((r === 'shadow' || r === 'all') && it.shadowRoot) results.push(it.shadowRoot);\n }\n });\n return results;\n };\n\n // --- Special Selectors: HostSet ---\n const hostSet = SwcUtils.getHostSet(this);\n if (selector === ':hosts') return applyRoot(hostSet.$hosts);\n if (selector === ':appHosts') return applyRoot(hostSet.$appHosts);\n\n // --- Special Selectors: Env ---\n const config = getElementConfig(this);\n const win = config?.window || window;\n if (selector === ':window') return [win];\n if (selector === ':document') return [win.document];\n if (selector === ':host') return applyRoot(this);\n\n // --- Standard Selectors ---\n if (r === 'shadow') return this.shadowRoot ? Array.from(this.shadowRoot.querySelectorAll(selector)) : [];\n if (r === 'light') return Array.from(this.querySelectorAll(selector));\n if (r === 'all') {\n const sNodes = this.shadowRoot ? Array.from(this.shadowRoot.querySelectorAll(selector)) : [];\n const lNodes = Array.from(this.querySelectorAll(selector));\n return [...sNodes, ...lNodes];\n }\n const root = this.shadowRoot || this;\n return Array.from(root.querySelectorAll(selector));\n },\n set(this: HTMLElement, nv: any) {\n ensureInit(this);\n if (nv === null || nv === undefined || (Array.isArray(nv) && nv.length === 0)) {\n const selector = selectorOrTarget;\n if (selector.startsWith(':') && selector !== ':host') return;\n\n const r = options.root || 'auto';\n let targets: (Element | Node)[] = [];\n if (r === 'shadow') targets = this.shadowRoot ? Array.from(this.shadowRoot.querySelectorAll(selector)) : [];\n else if (r === 'light') targets = Array.from(this.querySelectorAll(selector));\n else if (r === 'all') {\n const sNodes = this.shadowRoot ? Array.from(this.shadowRoot.querySelectorAll(selector)) : [];\n const lNodes = Array.from(this.querySelectorAll(selector));\n targets = [...sNodes, ...lNodes];\n } else {\n targets = Array.from((this.shadowRoot || this).querySelectorAll(selector));\n }\n targets.forEach(t => (t as Element).remove());\n }\n },\n enumerable: true,\n configurable: true\n });\n };\n}\n\nexport const getQueryAllMetadata = (target: any): QueryAllMetadata[] | undefined => {\n const constructor = target instanceof Function ? target : target.constructor;\n return ReflectUtils.getMetadata(QUERY_ALL_METADATA_KEY, constructor);\n};\n\n/**\n * @hostQueryAll decorator - simplified version of @queryAll for :host selector\n * Usage: @hostQueryAll()\n * Usage: @hostQueryAll({ root: 'shadow' })\n */\nexport function queryAllHost(options?: SwcQueryOptions): PropertyDecorator {\n return queryAll(':host', options);\n}\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,oBAAoB;AAC7B,SAAS,kBAAkB,kBAAkB;AAC7C,SAAS,gBAAgB;AASlB,MAAM,yBAAyB,OAAO,gCAAgC;AAOvE,SAAU,SAAS,kBAA0B,UAAe,CAAA,GAAE;AAClE,SAAO,CAAC,WAAmB,aAA8B,eAA4B;AACnF,QAAI,eAAe,QAAW;AAC5B,YAAM,IAAI,MAAM,2DAA2D,OAAO,WAAW,CAAC,GAAG;IACnG;AAEA,UAAM,cAAc,UAAU;AAC9B,QAAI,UAAU,aAAa,YAAgC,wBAAwB,WAAW;AAC9F,QAAI,CAAC,SAAS;AACZ,gBAAU,CAAA;AACV,mBAAa,eAAe,wBAAwB,SAAS,WAAW;IAC1E;AACA,YAAQ,KAAK,EAAE,aAAa,UAAU,kBAAkB,QAAO,CAAE;AAEjE,WAAO,eAAe,WAAW,aAAa;MAC5C,MAAG;AACD,mBAAW,IAAI;AACf,cAAM,WAAW;AAEjB,cAAM,IAAI,QAAQ,QAAQ;AAC1B,cAAM,YAAY,CAAC,MAAiB;AAClC,cAAI,CAAC;AAAG,mBAAO,CAAA;AACf,gBAAM,QAAQ,MAAM,QAAQ,CAAC,IAAI,IAAI,CAAC,CAAC;AACvC,gBAAM,UAAiB,CAAA;AACvB,gBAAM,QAAQ,QAAK;AACjB,gBAAI,EAAE,cAAc,cAAc;AAChC,sB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AI,SAAS,WAAW,GAAG,KAAK,aAAa;AAAS;AAEtD,gBAAM,IAAI,QAAQ,QAAQ;AAC1B,cAAI,UAA8B,CAAA;AAClC,cAAI,MAAM;AAAU,sBAAU,KAAK,aAAa,MAAM,KAAK,KAAK,WAAW,iBAAiB,QAAQ,CAAC,IAAI,CAAA;mBAChG,MAAM;AAAS,sBAAU,MAAM,KAAK,KAAK,iBAAiB,QAAQ,CAAC;mBACnE,MAAM,OAAO;AACpB,kBAAM,SAAS,KAAK,aAAa,MAAM,KAAK,KAAK,WAAW,iBAAiB,QAAQ,CAAC,IAAI,CAAA;AAC1F,kBAAM,SAAS,MAAM,KAAK,KAAK,iBAAiB,QAAQ,CAAC;AACzD,sBAAU,CAAC,GAAG,QAAQ,GAAG,MAAM;UACjC,OAAO;AACL,sBAAU,MAAM,MAAM,KAAK,cAAc,MAAM,iBAAiB,QAAQ,CAAC;UAC3E;AACA,kBAAQ,QAAQ,OAAM,EAAc,OAAM,CAAE;QAC9C;MACF;MACA,YAAY;MACZ,cAAc;KACf;EACH;AACF;AAEO,MAAM,sBAAsB,CAAC,WAA+C;AACjF,QAAM,cAAc,kBAAkB,WAAW,SAAS,OAAO;AACjE,SAAO,aAAa,YAAY,wBAAwB,WAAW;AACrE;
|
|
4
|
+
"sourcesContent": ["import { ReflectUtils } from '@dooboostore/core';\nimport { getElementConfig, ensureInit } from './elementDefine';\nimport { SwcUtils } from '../utils/Utils';\nimport { SpecialSelector, SwcQueryOptions } from '../types';\n\nexport interface QueryAllMetadata {\n propertyKey: string | symbol;\n selector: string;\n options: SwcQueryOptions;\n}\n\nexport const QUERY_ALL_METADATA_KEY = Symbol('simple-web-component:query-all');\n\nexport function queryAll(target: SpecialSelector): PropertyDecorator;\nexport function queryAll(selector: string, options?: SwcQueryOptions): PropertyDecorator;\n/**\n * @queryAll decorator to inject a list of elements into a class property.\n */\nexport function queryAll(selectorOrTarget: string, options: any = {}): PropertyDecorator {\n return (targetObj: Object, propertyKey: string | symbol, descriptor?: never): void => {\n if (descriptor !== undefined) {\n throw new Error(`@queryAll decorator cannot be used on methods. (Method: ${String(propertyKey)})`);\n }\n\n const constructor = targetObj.constructor;\n let queries = ReflectUtils.getMetadata<QueryAllMetadata[]>(QUERY_ALL_METADATA_KEY, constructor);\n if (!queries) {\n queries = [];\n ReflectUtils.defineMetadata(QUERY_ALL_METADATA_KEY, queries, constructor);\n }\n queries.push({ propertyKey, selector: selectorOrTarget, options });\n\n Object.defineProperty(targetObj, propertyKey, {\n get(this: HTMLElement) {\n ensureInit(this);\n const selector = selectorOrTarget;\n\n const r = options.root || 'auto';\n const applyRoot = (t: any): any[] => {\n if (!t) return [];\n const items = Array.isArray(t) ? t : [t];\n const results: any[] = [];\n items.forEach(it => {\n if (!(it instanceof HTMLElement)) {\n results.push(it);\n return;\n }\n if (r === 'auto') results.push(it.shadowRoot || it);\n else {\n if (r === 'light' || r === 'all') results.push(it);\n if ((r === 'shadow' || r === 'all') && it.shadowRoot) results.push(it.shadowRoot);\n }\n });\n return results;\n };\n\n // --- Special Selectors: HostSet ---\n const hostSet = SwcUtils.getHostSet(this);\n if (selector === ':hosts') return applyRoot(hostSet.$hosts);\n if (selector === ':appHosts') return applyRoot(hostSet.$appHosts);\n\n // --- Special Selectors: Env ---\n const config = getElementConfig(this);\n const win = config?.window || window;\n if (selector === ':window') return [win];\n if (selector === ':document') return [win.document];\n if (selector === ':host') return applyRoot(this);\n\n // --- Standard Selectors ---\n if (r === 'shadow') return this.shadowRoot ? Array.from(this.shadowRoot.querySelectorAll(selector)) : [];\n if (r === 'light') return Array.from(this.querySelectorAll(selector));\n if (r === 'all') {\n const sNodes = this.shadowRoot ? Array.from(this.shadowRoot.querySelectorAll(selector)) : [];\n const lNodes = Array.from(this.querySelectorAll(selector));\n return [...sNodes, ...lNodes];\n }\n const root = this.shadowRoot || this;\n return Array.from(root.querySelectorAll(selector));\n },\n set(this: HTMLElement, nv: any) {\n ensureInit(this);\n if (nv === null || nv === undefined || (Array.isArray(nv) && nv.length === 0)) {\n const selector = selectorOrTarget;\n if (selector.startsWith(':') && selector !== ':host') return;\n\n const r = options.root || 'auto';\n let targets: (Element | Node)[] = [];\n if (r === 'shadow') targets = this.shadowRoot ? Array.from(this.shadowRoot.querySelectorAll(selector)) : [];\n else if (r === 'light') targets = Array.from(this.querySelectorAll(selector));\n else if (r === 'all') {\n const sNodes = this.shadowRoot ? Array.from(this.shadowRoot.querySelectorAll(selector)) : [];\n const lNodes = Array.from(this.querySelectorAll(selector));\n targets = [...sNodes, ...lNodes];\n } else {\n targets = Array.from((this.shadowRoot || this).querySelectorAll(selector));\n }\n targets.forEach(t => (t as Element).remove());\n }\n },\n enumerable: true,\n configurable: true\n });\n };\n}\n\nexport const getQueryAllMetadata = (target: any): QueryAllMetadata[] | undefined => {\n const constructor = target instanceof Function ? target : target.constructor;\n return ReflectUtils.getMetadata(QUERY_ALL_METADATA_KEY, constructor);\n};\n\n/**\n * @hostQueryAll decorator - simplified version of @queryAll for :host selector\n * Usage: @hostQueryAll()\n * Usage: @hostQueryAll({ root: 'shadow' })\n */\n/**\n * @queryAllHost decorator - simplified version of @queryAll for :host selector\n * Usage: @queryAllHost items: HTMLElement[];\n * Usage: @queryAllHost() items: HTMLElement[];\n * Usage: @queryAllHost({ root: 'shadow' }) items: HTMLElement[];\n */\nexport function queryAllHost(target: Object, propertyKey: string | symbol): void;\nexport function queryAllHost(): PropertyDecorator;\nexport function queryAllHost(options: SwcQueryOptions): PropertyDecorator;\nexport function queryAllHost(targetOrOptions?: any, propertyKey?: string | symbol): any {\n // Direct decorator usage: @queryAllHost (no parentheses)\n if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {\n return queryAll(':host', {})(targetOrOptions, propertyKey);\n }\n\n // @queryAllHost() or @queryAllHost(options)\n if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {\n return queryAll(':host', targetOrOptions as SwcQueryOptions);\n } else {\n return queryAll(':host', {});\n }\n}\n\n/**\n * @allHost - Alias for @queryAllHost decorator\n * Usage: @allHost items: HTMLElement[];\n * Usage: @allHost() items: HTMLElement[];\n * Usage: @allHost({ root: 'shadow' }) items: HTMLElement[];\n */\nexport const allHost = queryAllHost;\n/**\n * @allParentHost - Query all :parentHost (All parent SWC components)\n * Usage: @allParentHost parents: HTMLElement[];\n * Usage: @allParentHost() parents: HTMLElement[];\n * Usage: @allParentHost({ root: 'shadow' }) parents: HTMLElement[];\n */\nexport function allParentHost(target: Object, propertyKey: string | symbol): void;\nexport function allParentHost(): PropertyDecorator;\nexport function allParentHost(options: SwcQueryOptions): PropertyDecorator;\nexport function allParentHost(targetOrOptions?: any, propertyKey?: string | symbol): any {\n if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {\n return queryAll(':parentHost', {})(targetOrOptions, propertyKey);\n }\n if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {\n return queryAll(':parentHost', targetOrOptions as SwcQueryOptions);\n } else {\n return queryAll(':parentHost', {});\n }\n}\n\n/**\n * @allAppHost - Query all :appHost (All <swc-app> instances)\n * Usage: @allAppHost apps: SwcAppInterface[];\n * Usage: @allAppHost() apps: SwcAppInterface[];\n * Usage: @allAppHost({ root: 'shadow' }) apps: SwcAppInterface[];\n */\nexport function allAppHost(target: Object, propertyKey: string | symbol): void;\nexport function allAppHost(): PropertyDecorator;\nexport function allAppHost(options: SwcQueryOptions): PropertyDecorator;\nexport function allAppHost(targetOrOptions?: any, propertyKey?: string | symbol): any {\n if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {\n return queryAll(':appHost', {})(targetOrOptions, propertyKey);\n }\n if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {\n return queryAll(':appHost', targetOrOptions as SwcQueryOptions);\n } else {\n return queryAll(':appHost', {});\n }\n}\n\n/**\n * @allFirstHost - Query all :firstHost (All first components in hierarchy)\n * Usage: @allFirstHost firsts: HTMLElement[];\n * Usage: @allFirstHost() firsts: HTMLElement[];\n * Usage: @allFirstHost({ root: 'shadow' }) firsts: HTMLElement[];\n */\nexport function allFirstHost(target: Object, propertyKey: string | symbol): void;\nexport function allFirstHost(): PropertyDecorator;\nexport function allFirstHost(options: SwcQueryOptions): PropertyDecorator;\nexport function allFirstHost(targetOrOptions?: any, propertyKey?: string | symbol): any {\n if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {\n return queryAll(':firstHost', {})(targetOrOptions, propertyKey);\n }\n if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {\n return queryAll(':firstHost', targetOrOptions as SwcQueryOptions);\n } else {\n return queryAll(':firstHost', {});\n }\n}\n\n/**\n * @allLastHost - Query all :lastHost (All last components in hierarchy)\n * Usage: @allLastHost lasts: HTMLElement[];\n * Usage: @allLastHost() lasts: HTMLElement[];\n * Usage: @allLastHost({ root: 'shadow' }) lasts: HTMLElement[];\n */\nexport function allLastHost(target: Object, propertyKey: string | symbol): void;\nexport function allLastHost(): PropertyDecorator;\nexport function allLastHost(options: SwcQueryOptions): PropertyDecorator;\nexport function allLastHost(targetOrOptions?: any, propertyKey?: string | symbol): any {\n if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {\n return queryAll(':lastHost', {})(targetOrOptions, propertyKey);\n }\n if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {\n return queryAll(':lastHost', targetOrOptions as SwcQueryOptions);\n } else {\n return queryAll(':lastHost', {});\n }\n}\n\n/**\n * @allFirstAppHost - Query all :firstAppHost (All first <swc-app> in hierarchy)\n * Usage: @allFirstAppHost apps: SwcAppInterface[];\n * Usage: @allFirstAppHost() apps: SwcAppInterface[];\n * Usage: @allFirstAppHost({ root: 'shadow' }) apps: SwcAppInterface[];\n */\nexport function allFirstAppHost(target: Object, propertyKey: string | symbol): void;\nexport function allFirstAppHost(): PropertyDecorator;\nexport function allFirstAppHost(options: SwcQueryOptions): PropertyDecorator;\nexport function allFirstAppHost(targetOrOptions?: any, propertyKey?: string | symbol): any {\n if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {\n return queryAll(':firstAppHost', {})(targetOrOptions, propertyKey);\n }\n if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {\n return queryAll(':firstAppHost', targetOrOptions as SwcQueryOptions);\n } else {\n return queryAll(':firstAppHost', {});\n }\n}\n\n/**\n * @allLastAppHost - Query all :lastAppHost (All last <swc-app> in hierarchy)\n * Usage: @allLastAppHost apps: SwcAppInterface[];\n * Usage: @allLastAppHost() apps: SwcAppInterface[];\n * Usage: @allLastAppHost({ root: 'shadow' }) apps: SwcAppInterface[];\n */\nexport function allLastAppHost(target: Object, propertyKey: string | symbol): void;\nexport function allLastAppHost(): PropertyDecorator;\nexport function allLastAppHost(options: SwcQueryOptions): PropertyDecorator;\nexport function allLastAppHost(targetOrOptions?: any, propertyKey?: string | symbol): any {\n if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {\n return queryAll(':lastAppHost', {})(targetOrOptions, propertyKey);\n }\n if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {\n return queryAll(':lastAppHost', targetOrOptions as SwcQueryOptions);\n } else {\n return queryAll(':lastAppHost', {});\n }\n}"],
|
|
5
|
+
"mappings": "AAAA,SAAS,oBAAoB;AAC7B,SAAS,kBAAkB,kBAAkB;AAC7C,SAAS,gBAAgB;AASlB,MAAM,yBAAyB,OAAO,gCAAgC;AAOvE,SAAU,SAAS,kBAA0B,UAAe,CAAA,GAAE;AAClE,SAAO,CAAC,WAAmB,aAA8B,eAA4B;AACnF,QAAI,eAAe,QAAW;AAC5B,YAAM,IAAI,MAAM,2DAA2D,OAAO,WAAW,CAAC,GAAG;IACnG;AAEA,UAAM,cAAc,UAAU;AAC9B,QAAI,UAAU,aAAa,YAAgC,wBAAwB,WAAW;AAC9F,QAAI,CAAC,SAAS;AACZ,gBAAU,CAAA;AACV,mBAAa,eAAe,wBAAwB,SAAS,WA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,WAAc,OAAO,gBAAgB,YAAY,OAAO,gBAAgB,WAAW;AACrG,WAAO,SAAS,aAAa,CAAA,CAAE,EAAE,iBAAiB,WAAW;EAC/D;AACA,MAAI,OAAO,oBAAoB,YAAY,oBAAoB,MAAM;AACnE,WAAO,SAAS,aAAa,eAAkC;EACjE,OAAO;AACL,WAAO,SAAS,aAAa,CAAA,CAAE;EACjC;AACF;AAWM,SAAU,gBAAgB,iBAAuB,aAA6B;AAClF,MAAI,gBAAgB,WAAc,OAAO,gBAAgB,YAAY,OAAO,gBAAgB,WAAW;AACrG,WAAO,SAAS,iBAAiB,CAAA,CAAE,EAAE,iBAAiB,WAAW;EACnE;AACA,MAAI,OAAO,oBAAoB,YAAY,oBAAoB,MAAM;AACnE,WAAO,SAAS,iBAAiB,eAAkC;EACrE,OAAO;AACL,WAAO,SAAS,iBAAiB,CAAA,CAAE;EACrC;AACF;AAWM,SAAU,eAAe,iBAAuB,aAA6B;AACjF,MAAI,gBAAgB,WAAc,OAAO,gBAAgB,YAAY,OAAO,gBAAgB,WAAW;AACrG,WAAO,SAAS,gBAAgB,CAAA,CAAE,EAAE,iBAAiB,WAAW;EAClE;AACA,MAAI,OAAO,oBAAoB,YAAY,oBAAoB,MAAM;AACnE,WAAO,SAAS,gBAAgB,eAAkC;EACpE,OAAO;AACL,WAAO,SAAS,gBAAgB,CAAA,CAAE;EACpC;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -24,11 +24,11 @@ function setAttribute(selector, name, options = {}) {
|
|
|
24
24
|
const applyRoot = (t) => {
|
|
25
25
|
if (!t) return;
|
|
26
26
|
if (r === "auto") {
|
|
27
|
-
targetEls.push(t
|
|
28
|
-
|
|
27
|
+
targetEls.push(t);
|
|
28
|
+
} else {
|
|
29
|
+
if (r === "light" || r === "all") targetEls.push(t);
|
|
30
|
+
if ((r === "shadow" || r === "all") && t.shadowRoot) targetEls.push(t.shadowRoot);
|
|
29
31
|
}
|
|
30
|
-
if (r === "light" || r === "all") targetEls.push(t);
|
|
31
|
-
if ((r === "shadow" || r === "all") && t.shadowRoot) targetEls.push(t.shadowRoot);
|
|
32
32
|
};
|
|
33
33
|
if (selector === ":window") targetEls.push(currentWin);
|
|
34
34
|
else if (selector === ":document") targetEls.push(currentWin.document);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/decorators/setAttribute.ts"],
|
|
4
|
-
"sourcesContent": ["import { ReflectUtils } from '@dooboostore/core';\nimport { ensureInit, getElementConfig } from './elementDefine';\nimport { SwcUtils } from '../utils/Utils';\nimport { SwcQueryOptions } from '../types';\n\nexport interface SetAttributeMetadata {\n propertyKey: string | symbol;\n selector: string;\n name: string;\n options: SwcQueryOptions;\n}\n\nexport const SET_ATTRIBUTE_METADATA_KEY = Symbol('simple-web-component:set-attribute');\n\n/**\n * @setAttribute decorator to surgically update an attribute of a target element.\n * Usage: @setAttribute(':host', 'count')\n * Usage: @setAttribute('#child', 'disabled')\n */\nexport function setAttribute(selector: string, name: string): MethodDecorator;\nexport function setAttribute(selector: string, name: string, options?: SwcQueryOptions): MethodDecorator;\nexport function setAttribute(selector: string, name: string, options: SwcQueryOptions = {}): MethodDecorator {\n return (target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n const constructor = target.constructor;\n let metaList = ReflectUtils.getOwnMetadata(SET_ATTRIBUTE_METADATA_KEY, constructor) as Map<string | symbol, SetAttributeMetadata>;\n if (!metaList) {\n metaList = new Map<string | symbol, SetAttributeMetadata>();\n ReflectUtils.defineMetadata(SET_ATTRIBUTE_METADATA_KEY, metaList, constructor);\n }\n metaList.set(propertyKey, { propertyKey, selector, name, options });\n\n const original = descriptor.value;\n descriptor.value = async function (...args: any[]) {\n ensureInit(this);\n const res = await original.apply(this, args);\n if (res !== undefined) {\n const hostSet = SwcUtils.getHostSet(this as any);\n const conf = getElementConfig(this);\n const currentWin = (this as any)._resolveWindow?.(conf) || ((typeof window !== 'undefined' ? window : undefined) as Window);\n\n const targetEls: any[] = [];\n const r = options.root || 'auto';\n\n const applyRoot = (t: any) => {\n if (!t) return;\n if (r === 'auto') {\n targetEls.push(
|
|
5
|
-
"mappings": "AAAA,SAAS,oBAAoB;AAC7B,SAAS,YAAY,wBAAwB;AAC7C,SAAS,gBAAgB;AAUlB,MAAM,6BAA6B,OAAO,oCAAoC;AAS9E,SAAS,aAAa,UAAkB,MAAc,UAA2B,CAAC,GAAoB;AAC3G,SAAO,CAAC,QAAgB,aAA8B,eAAmC;AACvF,UAAM,cAAc,OAAO;AAC3B,QAAI,WAAW,aAAa,eAAe,4BAA4B,WAAW;AAClF,QAAI,CAAC,UAAU;AACb,iBAAW,oBAAI,IAA2C;AAC1D,mBAAa,eAAe,4BAA4B,UAAU,WAAW;AAAA,IAC/E;AACA,aAAS,IAAI,aAAa,EAAE,aAAa,UAAU,MAAM,QAAQ,CAAC;AAElE,UAAM,WAAW,WAAW;AAC5B,eAAW,QAAQ,kBAAmB,MAAa;AACjD,iBAAW,IAAI;AACf,YAAM,MAAM,MAAM,SAAS,MAAM,MAAM,IAAI;AAC3C,UAAI,QAAQ,QAAW;AACrB,cAAM,UAAU,SAAS,WAAW,IAAW;AAC/C,cAAM,OAAO,iBAAiB,IAAI;AAClC,cAAM,aAAc,KAAa,iBAAiB,IAAI,MAAO,OAAO,WAAW,cAAc,SAAS;AAEtG,cAAM,YAAmB,CAAC;AAC1B,cAAM,IAAI,QAAQ,QAAQ;AAE1B,cAAM,YAAY,CAAC,MAAW;AAC5B,cAAI,CAAC,EAAG;AACR,cAAI,MAAM,QAAQ;
|
|
4
|
+
"sourcesContent": ["import { ReflectUtils } from '@dooboostore/core';\nimport { ensureInit, getElementConfig } from './elementDefine';\nimport { SwcUtils } from '../utils/Utils';\nimport { SwcQueryOptions } from '../types';\n\nexport interface SetAttributeMetadata {\n propertyKey: string | symbol;\n selector: string;\n name: string;\n options: SwcQueryOptions;\n}\n\nexport const SET_ATTRIBUTE_METADATA_KEY = Symbol('simple-web-component:set-attribute');\n\n/**\n * @setAttribute decorator to surgically update an attribute of a target element.\n * Usage: @setAttribute(':host', 'count')\n * Usage: @setAttribute('#child', 'disabled')\n */\nexport function setAttribute(selector: string, name: string): MethodDecorator;\nexport function setAttribute(selector: string, name: string, options?: SwcQueryOptions): MethodDecorator;\nexport function setAttribute(selector: string, name: string, options: SwcQueryOptions = {}): MethodDecorator {\n return (target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n const constructor = target.constructor;\n let metaList = ReflectUtils.getOwnMetadata(SET_ATTRIBUTE_METADATA_KEY, constructor) as Map<string | symbol, SetAttributeMetadata>;\n if (!metaList) {\n metaList = new Map<string | symbol, SetAttributeMetadata>();\n ReflectUtils.defineMetadata(SET_ATTRIBUTE_METADATA_KEY, metaList, constructor);\n }\n metaList.set(propertyKey, { propertyKey, selector, name, options });\n\n const original = descriptor.value;\n descriptor.value = async function (...args: any[]) {\n ensureInit(this);\n const res = await original.apply(this, args);\n if (res !== undefined) {\n const hostSet = SwcUtils.getHostSet(this as any);\n const conf = getElementConfig(this);\n const currentWin = (this as any)._resolveWindow?.(conf) || ((typeof window !== 'undefined' ? window : undefined) as Window);\n\n const targetEls: any[] = [];\n const r = options.root || 'auto';\n\n const applyRoot = (t: any) => {\n if (!t) return;\n if (r === 'auto') {\n // Attributes belong to the ELEMENT, not the ShadowRoot.\n targetEls.push(t);\n } else {\n if (r === 'light' || r === 'all') targetEls.push(t);\n if ((r === 'shadow' || r === 'all') && (t as any).shadowRoot) targetEls.push((t as any).shadowRoot);\n }\n };\n\n if (selector === ':window') targetEls.push(currentWin);\n else if (selector === ':document') targetEls.push(currentWin.document as any);\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 if (selector === ':host' || !selector) applyRoot(this);\n else {\n const roots: any[] = [];\n if (r === 'shadow') {\n if ((this as any).shadowRoot) roots.push((this as any).shadowRoot);\n } else if (r === 'light') {\n roots.push(this as any);\n } else if (r === 'all') {\n roots.push(this as any);\n if ((this as any).shadowRoot) roots.push((this as any).shadowRoot);\n } else {\n roots.push((this as any).shadowRoot || (this as any));\n }\n roots.forEach(root => targetEls.push(...root.querySelectorAll(selector)));\n }\n\n targetEls.forEach(targetEl => {\n if (!targetEl || typeof (targetEl as any).setAttribute !== 'function') return;\n if (res === null) (targetEl as any).removeAttribute(name);\n else (targetEl as any).setAttribute(name, String(res));\n });\n }\n return res;\n };\n };\n}\n\nexport const getSetAttributeMetadata = (target: any): Map<string | symbol, SetAttributeMetadata> | undefined => {\n const constructor = target instanceof Function ? target : target.constructor;\n return ReflectUtils.getMetadata(SET_ATTRIBUTE_METADATA_KEY, constructor);\n};\n\nexport const findAllSetAttributeMetadata = (target: any): Map<string | symbol, SetAttributeMetadata> => {\n const result = new Map<string | symbol, SetAttributeMetadata>();\n const maps = ReflectUtils.findAllMetadata<Map<string | symbol, SetAttributeMetadata>>(SET_ATTRIBUTE_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\n/**\n * @setAttributeHost decorator - simplified version of @setAttribute for :host selector\n * Usage: @setAttributeHost('aria-disabled')\n */\nexport function setAttributeHost(name: string, options?: SwcQueryOptions): MethodDecorator {\n return setAttribute(':host', name, options);\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,oBAAoB;AAC7B,SAAS,YAAY,wBAAwB;AAC7C,SAAS,gBAAgB;AAUlB,MAAM,6BAA6B,OAAO,oCAA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