@dooboostore/simple-web-component 1.0.39 → 1.0.41

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 (98) hide show
  1. package/LICENSE.md +7 -0
  2. package/README.md +235 -47
  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/decorators/subscribeSwcAppRouteChangeWhileConnected.js +9 -3
  20. package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
  21. package/dist/cjs/elements/SwcApp.js.map +2 -2
  22. package/dist/cjs/elements/SwcAppMixin.js +11 -4
  23. package/dist/cjs/elements/SwcAppMixin.js.map +2 -2
  24. package/dist/cjs/types/index.js.map +1 -1
  25. package/dist/esm/SwcAppEngine.js.map +2 -2
  26. package/dist/esm/decorators/applyAttribute.js +196 -113
  27. package/dist/esm/decorators/applyAttribute.js.map +2 -2
  28. package/dist/esm/decorators/applyNode.js +58 -43
  29. package/dist/esm/decorators/applyNode.js.map +2 -2
  30. package/dist/esm/decorators/applyProperty.js +194 -0
  31. package/dist/esm/decorators/applyProperty.js.map +7 -0
  32. package/dist/esm/decorators/applySlot.js +32 -26
  33. package/dist/esm/decorators/applySlot.js.map +2 -2
  34. package/dist/esm/decorators/changedAttributeThis.js.map +1 -1
  35. package/dist/esm/decorators/elementDefine.js +17 -30
  36. package/dist/esm/decorators/elementDefine.js.map +2 -2
  37. package/dist/esm/decorators/index.js +2 -2
  38. package/dist/esm/decorators/index.js.map +1 -1
  39. package/dist/esm/decorators/lifecycles.js +4 -4
  40. package/dist/esm/decorators/lifecycles.js.map +2 -2
  41. package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js +9 -3
  42. package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
  43. package/dist/esm/elements/SwcApp.js.map +2 -2
  44. package/dist/esm/elements/SwcAppMixin.js +11 -4
  45. package/dist/esm/elements/SwcAppMixin.js.map +2 -2
  46. package/dist/esm/types/index.js.map +1 -1
  47. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +441 -401
  48. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
  49. package/dist/types/SwcAppEngine.d.ts.map +1 -1
  50. package/dist/types/decorators/applyAttribute.d.ts +56 -15
  51. package/dist/types/decorators/applyAttribute.d.ts.map +1 -1
  52. package/dist/types/decorators/applyNode.d.ts +28 -24
  53. package/dist/types/decorators/applyNode.d.ts.map +1 -1
  54. package/dist/types/decorators/applyProperty.d.ts +61 -0
  55. package/dist/types/decorators/applyProperty.d.ts.map +1 -0
  56. package/dist/types/decorators/applySlot.d.ts +10 -10
  57. package/dist/types/decorators/applySlot.d.ts.map +1 -1
  58. package/dist/types/decorators/elementDefine.d.ts.map +1 -1
  59. package/dist/types/decorators/index.d.ts +2 -2
  60. package/dist/types/decorators/index.d.ts.map +1 -1
  61. package/dist/types/decorators/lifecycles.d.ts +4 -4
  62. package/dist/types/decorators/lifecycles.d.ts.map +1 -1
  63. package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts +2 -0
  64. package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts.map +1 -1
  65. package/dist/types/elements/SwcApp.d.ts.map +1 -1
  66. package/dist/types/elements/SwcAppMixin.d.ts.map +1 -1
  67. package/dist/types/types/index.d.ts +1 -6
  68. package/dist/types/types/index.d.ts.map +1 -1
  69. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +441 -401
  70. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
  71. package/package.json +3 -3
  72. package/src/SwcAppEngine.ts +1 -0
  73. package/src/decorators/applyAttribute.ts +311 -126
  74. package/src/decorators/applyNode.ts +68 -57
  75. package/src/decorators/applyProperty.ts +302 -0
  76. package/src/decorators/applySlot.ts +25 -18
  77. package/src/decorators/changedAttributeThis.ts +1 -1
  78. package/src/decorators/elementDefine.ts +41 -30
  79. package/src/decorators/index.ts +2 -3
  80. package/src/decorators/lifecycles.ts +6 -6
  81. package/src/decorators/subscribeSwcAppRouteChangeWhileConnected.ts +14 -4
  82. package/src/elements/SwcApp.ts +0 -1
  83. package/src/elements/SwcAppMixin.ts +16 -4
  84. package/src/types/index.ts +7 -7
  85. package/dist/cjs/decorators/attribute.js +0 -187
  86. package/dist/cjs/decorators/attribute.js.map +0 -7
  87. package/dist/cjs/decorators/setProperty.js +0 -109
  88. package/dist/cjs/decorators/setProperty.js.map +0 -7
  89. package/dist/esm/decorators/attribute.js +0 -168
  90. package/dist/esm/decorators/attribute.js.map +0 -7
  91. package/dist/esm/decorators/setProperty.js +0 -90
  92. package/dist/esm/decorators/setProperty.js.map +0 -7
  93. package/dist/types/decorators/attribute.d.ts +0 -31
  94. package/dist/types/decorators/attribute.d.ts.map +0 -1
  95. package/dist/types/decorators/setProperty.d.ts +0 -17
  96. package/dist/types/decorators/setProperty.d.ts.map +0 -1
  97. package/src/decorators/attribute.ts +0 -223
  98. 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
- };