@dooboostore/simple-web-component 1.0.39 → 1.0.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/LICENSE.md +7 -0
  2. package/README.md +65 -46
  3. package/dist/cjs/SwcAppEngine.js.map +2 -2
  4. package/dist/cjs/decorators/applyAttribute.js +194 -111
  5. package/dist/cjs/decorators/applyAttribute.js.map +2 -2
  6. package/dist/cjs/decorators/applyNode.js +58 -43
  7. package/dist/cjs/decorators/applyNode.js.map +2 -2
  8. package/dist/cjs/decorators/applyProperty.js +213 -0
  9. package/dist/cjs/decorators/applyProperty.js.map +7 -0
  10. package/dist/cjs/decorators/applySlot.js +32 -26
  11. package/dist/cjs/decorators/applySlot.js.map +2 -2
  12. package/dist/cjs/decorators/changedAttributeThis.js.map +1 -1
  13. package/dist/cjs/decorators/elementDefine.js +17 -30
  14. package/dist/cjs/decorators/elementDefine.js.map +2 -2
  15. package/dist/cjs/decorators/index.js +2 -2
  16. package/dist/cjs/decorators/index.js.map +2 -2
  17. package/dist/cjs/decorators/lifecycles.js +4 -4
  18. package/dist/cjs/decorators/lifecycles.js.map +2 -2
  19. package/dist/cjs/elements/SwcApp.js.map +2 -2
  20. package/dist/cjs/types/index.js.map +1 -1
  21. package/dist/esm/SwcAppEngine.js.map +2 -2
  22. package/dist/esm/decorators/applyAttribute.js +196 -113
  23. package/dist/esm/decorators/applyAttribute.js.map +2 -2
  24. package/dist/esm/decorators/applyNode.js +58 -43
  25. package/dist/esm/decorators/applyNode.js.map +2 -2
  26. package/dist/esm/decorators/applyProperty.js +194 -0
  27. package/dist/esm/decorators/applyProperty.js.map +7 -0
  28. package/dist/esm/decorators/applySlot.js +32 -26
  29. package/dist/esm/decorators/applySlot.js.map +2 -2
  30. package/dist/esm/decorators/changedAttributeThis.js.map +1 -1
  31. package/dist/esm/decorators/elementDefine.js +17 -30
  32. package/dist/esm/decorators/elementDefine.js.map +2 -2
  33. package/dist/esm/decorators/index.js +2 -2
  34. package/dist/esm/decorators/index.js.map +1 -1
  35. package/dist/esm/decorators/lifecycles.js +4 -4
  36. package/dist/esm/decorators/lifecycles.js.map +2 -2
  37. package/dist/esm/elements/SwcApp.js.map +2 -2
  38. package/dist/esm/types/index.js.map +1 -1
  39. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +421 -394
  40. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
  41. package/dist/types/SwcAppEngine.d.ts.map +1 -1
  42. package/dist/types/decorators/applyAttribute.d.ts +56 -15
  43. package/dist/types/decorators/applyAttribute.d.ts.map +1 -1
  44. package/dist/types/decorators/applyNode.d.ts +28 -24
  45. package/dist/types/decorators/applyNode.d.ts.map +1 -1
  46. package/dist/types/decorators/applyProperty.d.ts +61 -0
  47. package/dist/types/decorators/applyProperty.d.ts.map +1 -0
  48. package/dist/types/decorators/applySlot.d.ts +10 -10
  49. package/dist/types/decorators/applySlot.d.ts.map +1 -1
  50. package/dist/types/decorators/elementDefine.d.ts.map +1 -1
  51. package/dist/types/decorators/index.d.ts +2 -2
  52. package/dist/types/decorators/index.d.ts.map +1 -1
  53. package/dist/types/decorators/lifecycles.d.ts +4 -4
  54. package/dist/types/decorators/lifecycles.d.ts.map +1 -1
  55. package/dist/types/elements/SwcApp.d.ts.map +1 -1
  56. package/dist/types/types/index.d.ts +1 -6
  57. package/dist/types/types/index.d.ts.map +1 -1
  58. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +421 -394
  59. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
  60. package/package.json +3 -3
  61. package/src/SwcAppEngine.ts +1 -0
  62. package/src/decorators/applyAttribute.ts +311 -126
  63. package/src/decorators/applyNode.ts +68 -57
  64. package/src/decorators/applyProperty.ts +302 -0
  65. package/src/decorators/applySlot.ts +25 -18
  66. package/src/decorators/changedAttributeThis.ts +1 -1
  67. package/src/decorators/elementDefine.ts +41 -30
  68. package/src/decorators/index.ts +2 -3
  69. package/src/decorators/lifecycles.ts +6 -6
  70. package/src/elements/SwcApp.ts +0 -1
  71. package/src/types/index.ts +7 -7
  72. package/dist/cjs/decorators/attribute.js +0 -187
  73. package/dist/cjs/decorators/attribute.js.map +0 -7
  74. package/dist/cjs/decorators/setProperty.js +0 -109
  75. package/dist/cjs/decorators/setProperty.js.map +0 -7
  76. package/dist/esm/decorators/attribute.js +0 -168
  77. package/dist/esm/decorators/attribute.js.map +0 -7
  78. package/dist/esm/decorators/setProperty.js +0 -90
  79. package/dist/esm/decorators/setProperty.js.map +0 -7
  80. package/dist/types/decorators/attribute.d.ts +0 -31
  81. package/dist/types/decorators/attribute.d.ts.map +0 -1
  82. package/dist/types/decorators/setProperty.d.ts +0 -17
  83. package/dist/types/decorators/setProperty.d.ts.map +0 -1
  84. package/src/decorators/attribute.ts +0 -223
  85. package/src/decorators/setProperty.ts +0 -112
@@ -1,112 +0,0 @@
1
- import { ReflectUtils } from '@dooboostore/core';
2
- import { ensureInit } from './elementDefine';
3
- import { SwcUtils } from '../utils/Utils';
4
- import { SpecialSelector, SwcQueryOptions, HelperHostSet } from '../types';
5
-
6
- export interface PropertySetOptions extends SwcQueryOptions {
7
- name?: string;
8
- filter?: (target: HTMLElement, value: any, meta: {currentThis: any, helper: HelperHostSet}) => boolean;
9
- }
10
-
11
- export interface PropertySetMetadata {
12
- propertyKey: string | symbol;
13
- selector: string;
14
- options: PropertySetOptions;
15
- }
16
-
17
- export const PROPERTY_SET_METADATA_KEY = Symbol.for('simple-web-component:property-set');
18
-
19
- export const setProperty = (selector: string, propertyNameOrOptions?: string | PropertySetOptions, options: PropertySetOptions = {}): MethodDecorator => {
20
- return (target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {
21
- const constructor = target.constructor;
22
- let metaList = ReflectUtils.getOwnMetadata(PROPERTY_SET_METADATA_KEY, constructor) as Map<string | symbol, PropertySetMetadata>;
23
- if (!metaList) {
24
- metaList = new Map<string | symbol, PropertySetMetadata>();
25
- ReflectUtils.defineMetadata(PROPERTY_SET_METADATA_KEY, metaList, constructor);
26
- }
27
-
28
- let propertyName = typeof propertyNameOrOptions === 'string' ? propertyNameOrOptions : undefined;
29
- let finalOptions = options;
30
-
31
- if (typeof propertyNameOrOptions === 'object' && propertyNameOrOptions !== null) {
32
- finalOptions = propertyNameOrOptions as PropertySetOptions;
33
- }
34
-
35
- metaList.set(propertyKey, {
36
- propertyKey,
37
- selector,
38
- options: { ...finalOptions, name: propertyName }
39
- });
40
-
41
- const original = descriptor.value;
42
- descriptor.value = function (...args: any[]) {
43
- ensureInit(this);
44
- const res = (original as any).apply(this, args);
45
-
46
- const handleResult = (resolvedValue: any) => {
47
- if (resolvedValue !== undefined) {
48
- const win = (this as any).ownerDocument?.defaultView || window;
49
- const host = this as unknown as HTMLElement;
50
- const hostSet = { ...SwcUtils.getHelperAndHostSet(win, host), $this: this };
51
- const r = finalOptions.root || 'auto';
52
- const targetEls: HTMLElement[] = [];
53
-
54
- const applyRoot = (t: any) => {
55
- if (!t || !(t instanceof win.HTMLElement)) return;
56
- targetEls.push(t);
57
- };
58
-
59
- if (selector === '$this' || !selector) applyRoot(host);
60
- else if (selector === '$host') applyRoot(hostSet.$host);
61
- else if (selector === '$parentHost') applyRoot(hostSet.$parentHost);
62
- else if (selector === '$appHost') applyRoot(hostSet.$appHost);
63
- else if (selector === '$firstHost') applyRoot(hostSet.$firstHost);
64
- else if (selector === '$lastHost') applyRoot(hostSet.$lastHost);
65
- else if (selector === '$firstAppHost') applyRoot(hostSet.$firstAppHost);
66
- else if (selector === '$lastAppHost') applyRoot(hostSet.$lastAppHost);
67
- else if (selector === '$hosts') hostSet.$hosts.forEach(applyRoot);
68
- else if (selector === '$appHosts') hostSet.$appHosts.forEach(applyRoot);
69
- else {
70
- const targetRoot = r === 'auto' ? (host.shadowRoot || host) : (r === 'shadow' ? host.shadowRoot : host);
71
- if (targetRoot) {
72
- const found = targetRoot.querySelectorAll(selector);
73
- if (found) targetEls.push(...(Array.from(found) as HTMLElement[]));
74
- }
75
- }
76
-
77
- targetEls.forEach(targetEl => {
78
- if (finalOptions.filter && !finalOptions.filter(targetEl, resolvedValue, {currentThis: this, helper: hostSet})) {
79
- return;
80
- }
81
- const resolvedRes = typeof resolvedValue === 'function' ? (resolvedValue as any)(targetEl, hostSet) : resolvedValue;
82
-
83
- if (propertyName) {
84
- // Case: @setProperty(selector, 'propertyName')
85
- (targetEl as any)[propertyName] = resolvedRes;
86
- } else if (typeof resolvedRes === 'object' && resolvedRes !== null && !Array.isArray(resolvedRes)) {
87
- // Case: @setProperty(selector) with Object return - assign multiple properties
88
- Object.entries(resolvedRes as any).forEach(([prop, val]) => {
89
- const finalVal = typeof val === 'function' ? val(targetEl, hostSet) : val;
90
- (targetEl as any)[prop] = finalVal;
91
- });
92
- } else {
93
- // Simple value - assign to 'value' property by default
94
- (targetEl as any).value = resolvedRes;
95
- }
96
- });
97
- }
98
- return resolvedValue;
99
- };
100
-
101
- if (res instanceof Promise) {
102
- return res.then(handleResult);
103
- } else {
104
- return handleResult(res);
105
- }
106
- };
107
- };
108
- };
109
-
110
- export const setPropertyThis = (propertyNameOrOptions?: string | PropertySetOptions, options: PropertySetOptions = {}): MethodDecorator => {
111
- return setProperty('$this', propertyNameOrOptions, options);
112
- };