@dooboostore/simple-web-component 1.0.37 → 1.0.39

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 (157) hide show
  1. package/README.md +280 -791
  2. package/dist/cjs/SwcAppEngine.js +3 -0
  3. package/dist/cjs/SwcAppEngine.js.map +2 -2
  4. package/dist/cjs/decorators/addEventListener.js +20 -4
  5. package/dist/cjs/decorators/addEventListener.js.map +2 -2
  6. package/dist/cjs/decorators/applyAttribute.js.map +1 -1
  7. package/dist/cjs/decorators/applyClass.js.map +1 -1
  8. package/dist/cjs/decorators/applyNode.js +104 -35
  9. package/dist/cjs/decorators/applyNode.js.map +2 -2
  10. package/dist/cjs/decorators/applySlot.js +69 -57
  11. package/dist/cjs/decorators/applySlot.js.map +3 -3
  12. package/dist/cjs/decorators/applyStyle.js.map +2 -2
  13. package/dist/cjs/decorators/attribute.js.map +1 -1
  14. package/dist/cjs/decorators/elementDefine.js +65 -42
  15. package/dist/cjs/decorators/elementDefine.js.map +2 -2
  16. package/dist/cjs/decorators/emitCustomEvent.js.map +1 -1
  17. package/dist/cjs/decorators/index.js +1 -0
  18. package/dist/cjs/decorators/index.js.map +2 -2
  19. package/dist/cjs/decorators/lifecycles.js +47 -31
  20. package/dist/cjs/decorators/lifecycles.js.map +3 -3
  21. package/dist/cjs/decorators/publishSwcAppMessage.js.map +2 -2
  22. package/dist/cjs/decorators/query.js +1 -1
  23. package/dist/cjs/decorators/query.js.map +2 -2
  24. package/dist/cjs/decorators/queryAll.js.map +1 -1
  25. package/dist/cjs/decorators/setProperty.js.map +1 -1
  26. package/dist/cjs/decorators/state.js +83 -0
  27. package/dist/cjs/decorators/state.js.map +7 -0
  28. package/dist/cjs/decorators/subscribeSwcAppMessageWhileConnected.js.map +1 -1
  29. package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
  30. package/dist/cjs/elements/SwcApp.js +193 -305
  31. package/dist/cjs/elements/SwcApp.js.map +3 -3
  32. package/dist/cjs/elements/SwcAppMixin.js +291 -0
  33. package/dist/cjs/elements/SwcAppMixin.js.map +7 -0
  34. package/dist/cjs/elements/index.js +3 -21
  35. package/dist/cjs/elements/index.js.map +3 -3
  36. package/dist/cjs/index.js +1 -3
  37. package/dist/cjs/index.js.map +2 -2
  38. package/dist/cjs/{types.js → types/index.js} +1 -1
  39. package/dist/cjs/types/index.js.map +7 -0
  40. package/dist/cjs/types/window.d.js.map +1 -1
  41. package/dist/cjs/utils/Utils.js +159 -20
  42. package/dist/cjs/utils/Utils.js.map +3 -3
  43. package/dist/esm/SwcAppEngine.js +3 -0
  44. package/dist/esm/SwcAppEngine.js.map +2 -2
  45. package/dist/esm/decorators/addEventListener.js +20 -4
  46. package/dist/esm/decorators/addEventListener.js.map +2 -2
  47. package/dist/esm/decorators/applyAttribute.js.map +1 -1
  48. package/dist/esm/decorators/applyClass.js.map +1 -1
  49. package/dist/esm/decorators/applyNode.js +104 -35
  50. package/dist/esm/decorators/applyNode.js.map +2 -2
  51. package/dist/esm/decorators/applySlot.js +69 -57
  52. package/dist/esm/decorators/applySlot.js.map +3 -3
  53. package/dist/esm/decorators/applyStyle.js.map +2 -2
  54. package/dist/esm/decorators/attribute.js.map +1 -1
  55. package/dist/esm/decorators/elementDefine.js +69 -46
  56. package/dist/esm/decorators/elementDefine.js.map +2 -2
  57. package/dist/esm/decorators/emitCustomEvent.js.map +1 -1
  58. package/dist/esm/decorators/index.js +1 -0
  59. package/dist/esm/decorators/index.js.map +2 -2
  60. package/dist/esm/decorators/lifecycles.js +47 -31
  61. package/dist/esm/decorators/lifecycles.js.map +3 -3
  62. package/dist/esm/decorators/publishSwcAppMessage.js.map +2 -2
  63. package/dist/esm/decorators/query.js +1 -1
  64. package/dist/esm/decorators/query.js.map +2 -2
  65. package/dist/esm/decorators/queryAll.js.map +1 -1
  66. package/dist/esm/decorators/setProperty.js.map +1 -1
  67. package/dist/esm/decorators/state.js +64 -0
  68. package/dist/esm/decorators/state.js.map +7 -0
  69. package/dist/esm/decorators/subscribeSwcAppMessageWhileConnected.js.map +1 -1
  70. package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
  71. package/dist/esm/elements/SwcApp.js +195 -307
  72. package/dist/esm/elements/SwcApp.js.map +3 -3
  73. package/dist/esm/elements/SwcAppMixin.js +273 -0
  74. package/dist/esm/elements/SwcAppMixin.js.map +7 -0
  75. package/dist/esm/elements/index.js +2 -7
  76. package/dist/esm/elements/index.js.map +2 -2
  77. package/dist/esm/index.js +2 -4
  78. package/dist/esm/index.js.map +2 -2
  79. package/dist/esm/{types.js → types/index.js} +1 -1
  80. package/dist/esm/types/index.js.map +7 -0
  81. package/dist/esm/utils/Utils.js +159 -20
  82. package/dist/esm/utils/Utils.js.map +3 -3
  83. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +3448 -2584
  84. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
  85. package/dist/types/SwcAppEngine.d.ts +1 -1
  86. package/dist/types/SwcAppEngine.d.ts.map +1 -1
  87. package/dist/types/decorators/addEventListener.d.ts +5 -2
  88. package/dist/types/decorators/addEventListener.d.ts.map +1 -1
  89. package/dist/types/decorators/applyAttribute.d.ts.map +1 -1
  90. package/dist/types/decorators/applyClass.d.ts.map +1 -1
  91. package/dist/types/decorators/applyNode.d.ts +23 -7
  92. package/dist/types/decorators/applyNode.d.ts.map +1 -1
  93. package/dist/types/decorators/applySlot.d.ts +14 -12
  94. package/dist/types/decorators/applySlot.d.ts.map +1 -1
  95. package/dist/types/decorators/applyStyle.d.ts.map +1 -1
  96. package/dist/types/decorators/attribute.d.ts.map +1 -1
  97. package/dist/types/decorators/elementDefine.d.ts.map +1 -1
  98. package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
  99. package/dist/types/decorators/index.d.ts +1 -0
  100. package/dist/types/decorators/index.d.ts.map +1 -1
  101. package/dist/types/decorators/lifecycles.d.ts +10 -14
  102. package/dist/types/decorators/lifecycles.d.ts.map +1 -1
  103. package/dist/types/decorators/publishSwcAppMessage.d.ts.map +1 -1
  104. package/dist/types/decorators/query.d.ts +1 -1
  105. package/dist/types/decorators/query.d.ts.map +1 -1
  106. package/dist/types/decorators/queryAll.d.ts.map +1 -1
  107. package/dist/types/decorators/setProperty.d.ts +1 -1
  108. package/dist/types/decorators/setProperty.d.ts.map +1 -1
  109. package/dist/types/decorators/state.d.ts +9 -0
  110. package/dist/types/decorators/state.d.ts.map +1 -0
  111. package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts.map +1 -1
  112. package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts +5 -1
  113. package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts.map +1 -1
  114. package/dist/types/elements/SwcApp.d.ts +35 -6
  115. package/dist/types/elements/SwcApp.d.ts.map +1 -1
  116. package/dist/types/elements/SwcAppMixin.d.ts +405 -0
  117. package/dist/types/elements/SwcAppMixin.d.ts.map +1 -0
  118. package/dist/types/elements/index.d.ts +2 -2
  119. package/dist/types/elements/index.d.ts.map +1 -1
  120. package/dist/types/index.d.ts +1 -1
  121. package/dist/types/index.d.ts.map +1 -1
  122. package/dist/types/{types.d.ts → types/index.d.ts} +11 -11
  123. package/dist/types/types/index.d.ts.map +1 -0
  124. package/dist/types/utils/Utils.d.ts +14 -2
  125. package/dist/types/utils/Utils.d.ts.map +1 -1
  126. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +3431 -2567
  127. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
  128. package/package.json +4 -4
  129. package/src/SwcAppEngine.ts +6 -2
  130. package/src/decorators/addEventListener.ts +21 -5
  131. package/src/decorators/applyAttribute.ts +1 -1
  132. package/src/decorators/applyClass.ts +1 -1
  133. package/src/decorators/applyNode.ts +183 -73
  134. package/src/decorators/applySlot.ts +99 -128
  135. package/src/decorators/applyStyle.ts +4 -4
  136. package/src/decorators/attribute.ts +1 -1
  137. package/src/decorators/elementDefine.ts +112 -60
  138. package/src/decorators/emitCustomEvent.ts +1 -1
  139. package/src/decorators/index.ts +2 -0
  140. package/src/decorators/lifecycles.ts +50 -26
  141. package/src/decorators/publishSwcAppMessage.ts +2 -3
  142. package/src/decorators/query.ts +4 -4
  143. package/src/decorators/queryAll.ts +1 -1
  144. package/src/decorators/setProperty.ts +1 -1
  145. package/src/decorators/state.ts +83 -0
  146. package/src/decorators/subscribeSwcAppMessageWhileConnected.ts +1 -1
  147. package/src/decorators/subscribeSwcAppRouteChangeWhileConnected.ts +4 -3
  148. package/src/elements/SwcApp.ts +239 -441
  149. package/src/elements/SwcAppMixin.ts +328 -0
  150. package/src/elements/index.ts +2 -9
  151. package/src/index.ts +2 -4
  152. package/src/{types.ts → types/index.ts} +13 -10
  153. package/src/types/window.d.ts +3 -0
  154. package/src/utils/Utils.ts +205 -20
  155. package/dist/cjs/types.js.map +0 -7
  156. package/dist/esm/types.js.map +0 -7
  157. package/dist/types/types.d.ts.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dooboostore/simple-web-component",
3
- "version": "1.0.37",
3
+ "version": "1.0.39",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.js",
@@ -92,10 +92,10 @@
92
92
  "webpack": "^5.93.0",
93
93
  "webpack-cli": "^5.1.4",
94
94
  "webpack-dev-server": "^5.2.0",
95
- "@dooboostore/core": "1.0.31",
96
95
  "@dooboostore/core-node": "1.0.12",
97
- "@dooboostore/core-web": "1.0.11",
98
- "@dooboostore/simple-boot": "1.0.55"
96
+ "@dooboostore/core-web": "1.0.12",
97
+ "@dooboostore/simple-boot": "1.0.56",
98
+ "@dooboostore/core": "1.0.32"
99
99
  },
100
100
  "scripts": {
101
101
  "clean": "rm -rf dist",
@@ -3,13 +3,12 @@ import { HashRouter, PathRouter, Router, RouterEventType } from '@dooboostore/co
3
3
  import { ElementRouter } from './router/ElementRouter';
4
4
  import { SimOption } from '@dooboostore/simple-boot';
5
5
  import { ConstructorType, OptionalType, Subscription } from '@dooboostore/core';
6
-
7
6
  import { SwcAppInterface } from './types';
8
7
  import { SimConfig } from '@dooboostore/simple-boot';
9
8
 
10
9
  export type SwcConfigType = {
11
10
  routeType: 'path' | 'hash' | 'element';
12
- connectMode?: 'direct' | 'swap' | 'clear-swap' | 'hydrate'; // hydrate 아직 개발중
11
+ // connectMode?: 'direct' | 'swap' | 'clear-swap'; // hydrate 아직 개발중
13
12
  container?: symbol;
14
13
  otherInstanceSim?: Map<ConstructorType<any> | Function | SimConfig | symbol, any>;
15
14
  path?: string;
@@ -22,6 +21,7 @@ export type SwcConfigType = {
22
21
  onConnected?: (app: SwcAppInterface) => void;
23
22
  onDisconnected?: (app: SwcAppInterface) => void;
24
23
  ssr?: boolean;
24
+ onStartedLazyDefineComponent?: ((w: Window)=> Promise<CustomElementConstructor> | void | string | any | CustomElementConstructor)[];
25
25
 
26
26
  onChildrenConnectedDone?: (app: SwcAppInterface) => void;
27
27
  // onChildrenSwcAppStartedDone?: (app: SwcAppInterface) => void;
@@ -75,6 +75,10 @@ export class SwcAppEngine {
75
75
  if (this.router) otherInstanceSim.set(Router, this.router);
76
76
  this.simpleApplication.run(otherInstanceSim);
77
77
 
78
+
79
+ if (this._config.onStartedLazyDefineComponent) {
80
+ await Promise.all(this._config.onStartedLazyDefineComponent.map(it => it(this._config.window)))
81
+ }
78
82
  if (this._config.onEngineStarted) {
79
83
  await this._config.onEngineStarted(this.simpleApplication, this.host as unknown as SwcAppInterface);
80
84
  }
@@ -8,7 +8,7 @@ export interface AddEventListenerBaseOptions extends EventListenerOptions {
8
8
  stopPropagation?: boolean;
9
9
  stopImmediatePropagation?: boolean;
10
10
  preventDefault?: boolean;
11
- removeOnDisconnected?: boolean;
11
+ // removeOnDisconnected?: boolean;
12
12
  delegate?: boolean;
13
13
  filter?: (target: Event | CustomEvent, meta:{currentThis: any, helper: HelperHostSet}) => boolean;
14
14
  }
@@ -41,10 +41,20 @@ export function addEventListener(selectorOrTarget: string, type: string, options
41
41
  };
42
42
  }
43
43
 
44
- export const getAddEventListenerMetadata = (target: any): AddEventListenerMetadata[] | undefined => {
45
- const constructor = target instanceof Function ? target : target.constructor;
46
- return ReflectUtils.getMetadata(ADD_EVENT_LISTENER_METADATA_KEY, constructor);
47
- };
44
+
45
+ export function addEventListenerDelegateLightDom(selector: string, type: string, options?: Omit<AddEventListenerBaseOptions, 'delegate'>): MethodDecorator {
46
+ return addEventListener(selector, type, {...options??{}, root:'light', delegate: true});
47
+ }
48
+
49
+ export function addEventListenerDelegateShadowDom(selector: string, type: string, options?: Omit<AddEventListenerBaseOptions, 'delegate'>): MethodDecorator {
50
+ return addEventListener(selector, type, {...options??{}, root:'shadow', delegate: true});
51
+ }
52
+ export function addEventListenerDelegateAllDom(selector: string, type: string, options?: Omit<AddEventListenerBaseOptions, 'delegate'>): MethodDecorator {
53
+ return addEventListener(selector, type, {...options??{}, root:'all', delegate: true});
54
+ }
55
+ export function addEventListenerDelegate(selector: string, type: string, options?: Omit<AddEventListenerBaseOptions, 'delegate'>): MethodDecorator {
56
+ return addEventListener(selector, type, {...options??{}, root:'auto', delegate: true});
57
+ }
48
58
 
49
59
  /**
50
60
  * @addEventListenerThis decorator - simplified version of @addEventListener for $this selector
@@ -59,9 +69,15 @@ export function addEventListenerThis(type: string, options?: AddEventListenerBas
59
69
  export function addEventListenerAppHost(type: string, options?: AddEventListenerBaseOptions & SwcQueryOptions): MethodDecorator {
60
70
  return addEventListener('$appHost', type, options);
61
71
  }
72
+
62
73
  export function addEventListenerWindow(type: string, options?: AddEventListenerBaseOptions & SwcQueryOptions): MethodDecorator {
63
74
  return addEventListener('$window', type, options);
64
75
  }
65
76
  export function addEventListenerDocument(type: string, options?: AddEventListenerBaseOptions & SwcQueryOptions): MethodDecorator {
66
77
  return addEventListener('$document', type, options);
67
78
  }
79
+
80
+ export const getAddEventListenerMetadata = (target: any): AddEventListenerMetadata[] | undefined => {
81
+ const constructor = target instanceof Function ? target : target.constructor;
82
+ return ReflectUtils.getMetadata(ADD_EVENT_LISTENER_METADATA_KEY, constructor);
83
+ };
@@ -1,7 +1,7 @@
1
1
  import { ReflectUtils } from '@dooboostore/core';
2
2
  import { ensureInit } from './elementDefine';
3
3
  import { SwcUtils } from '../utils/Utils';
4
- import { SwcQueryOptions, HelperHostSet } from '../types';
4
+ import { SpecialSelector, SwcQueryOptions, HelperHostSet } from '../types';
5
5
 
6
6
  export type AttributeAction = 'set' | 'update' | 'remove';
7
7
 
@@ -1,7 +1,7 @@
1
1
  import { ReflectUtils } from '@dooboostore/core';
2
2
  import { ensureInit } from './elementDefine';
3
3
  import { SwcUtils } from '../utils/Utils';
4
- import { SwcQueryOptions, HelperHostSet } from '../types';
4
+ import { SpecialSelector, SwcQueryOptions, HelperHostSet } from '../types';
5
5
 
6
6
  export const CLASS_METADATA_KEY = Symbol.for('simple-web-component:class');
7
7
 
@@ -1,7 +1,9 @@
1
1
  import { ReflectUtils } from '@dooboostore/core';
2
2
  import { ensureInit, getElementConfig } from './elementDefine';
3
- import { HelperHostSet, SwcRootType } from '../types';
4
- import { SwcUtils } from "../utils/Utils";
3
+ import {SpecialSelector, SwcQueryOptions, HelperHostSet, SwcRootType} from '../types';
4
+ import { SwcUtils} from "../utils/Utils";
5
+ import {findAllStateMetadata} from "./state";
6
+ import {ElementApply} from "@dooboostore/core-web";
5
7
  /*
6
8
  <!-- beforebegin -->
7
9
  <p> <-- it's me
@@ -20,11 +22,11 @@ export interface ApplyNodeOptions {
20
22
  * Filter function to determine whether to perform DOM operation.
21
23
  * If it returns false, the operation is skipped.
22
24
  */
23
- filter?: (target: HTMLElement | ShadowRoot, newValue: any, meta:{currentThis: any,helper: HelperHostSet}) => boolean;
25
+ filter?: (target: HTMLElement | ShadowRoot, newValue: any, meta: { currentThis: any, helper: HelperHostSet }) => boolean;
24
26
  /**
25
27
  * Optional loading content to display while an async method is executing.
26
28
  */
27
- loading?: (helper: HelperHostSet) => any;
29
+ fallback?: (helper: HelperHostSet) => any;
28
30
  }
29
31
 
30
32
  export interface ApplyNodeMetadata {
@@ -35,49 +37,66 @@ export interface ApplyNodeMetadata {
35
37
 
36
38
  export const APPLY_NODE_METADATA_KEY = Symbol.for('simple-web-component:apply-node');
37
39
 
38
- const normalizeNodes = (res: any, doc: Document): Node[] => {
39
- const items = Array.isArray(res) ? res : [res];
40
- return items.map(it => {
41
- if (it instanceof Node) return it;
42
- return doc.createTextNode(it !== undefined && it !== null ? String(it) : '');
43
- });
44
- };
40
+ // const normalizeNodes = (res: any, doc: Document): Node[] => {
41
+ // const items = Array.isArray(res) ? res : [res];
42
+ // return items.map(it => {
43
+ // if (it instanceof Node) return it;
44
+ // return doc.createTextNode(it !== undefined && it !== null ? String(it) : '');
45
+ // });
46
+ // };
45
47
 
46
- const applyToDom = (targetEl: any, res: any, pos: ApplyNodePosition, win: Window) => {
47
- if (!targetEl) return;
48
+ const applyToDom = (currentThis: any, targetEl: HTMLElement, res: Node | string, pos: ApplyNodePosition, win: Window, host?: any) => {
49
+ if (!targetEl) return;
50
+ const doc = win.document;
51
+ const hostSet = SwcUtils.getHelperAndHostSet(win, currentThis);
52
+ const id = currentThis._swcId;
48
53
 
49
- const doc = win.document;
50
-
51
- if (pos === 'innerHtml') {
52
- targetEl.innerHTML = res !== undefined && res !== null ? String(res) : '';
53
- return;
54
- }
55
-
56
- if (pos === 'innerText') {
57
- if (targetEl.innerText !== undefined) {
58
- targetEl.innerText = res !== undefined && res !== null ? String(res) : '';
59
- }
60
- return;
61
- }
62
54
 
63
- const isShadowRoot = targetEl instanceof win.ShadowRoot;
64
- const nodes = normalizeNodes(res, doc);
65
- if (pos === 'replace') {
66
- if (!isShadowRoot) targetEl.replaceWith(...nodes);
67
- } else if (pos === 'replaceChildren') {
68
- targetEl.replaceChildren(...nodes);
69
- } else {
70
- if (pos === 'beforeEnd') targetEl.append(...nodes);
71
- else if (pos === 'afterBegin') targetEl.prepend(...nodes);
72
- else if (pos === 'beforeBegin' && !isShadowRoot) targetEl.before(...nodes);
73
- else if (pos === 'afterEnd' && !isShadowRoot) targetEl.after(...nodes);
55
+ const nodes: Node[] = [];
56
+
57
+ if (typeof res === 'string' && pos === 'innerHtml') {
58
+ const t = win.document.createElement('template');
59
+ t.innerHTML = res;
60
+ nodes.push(...Array.from(t.content.childNodes));
61
+ } else if (typeof res === 'string' && pos === 'innerText') {
62
+ nodes.push(win.document.createTextNode(res));
63
+ }
64
+
65
+ SwcUtils.projectProcessHtml(id, nodes, doc);
66
+
67
+
68
+
69
+ const isShadowRoot = targetEl instanceof win.ShadowRoot;
70
+ // const nodes = normalizeNodes(res, doc);
71
+ if (pos === 'replace') {
72
+ if (!isShadowRoot) targetEl.replaceWith(...nodes);
73
+ } else if (pos === 'innerHtml') {
74
+ targetEl.replaceChildren(...nodes);
75
+ } else if (pos === 'innerText') {
76
+ targetEl.replaceChildren(...nodes);
77
+ } else if (pos === 'replaceChildren') {
78
+ targetEl.replaceChildren(...nodes);
79
+ } else {
80
+ if (pos === 'beforeEnd') {
81
+ targetEl.append(...nodes)
74
82
  }
83
+ else if (pos === 'afterBegin') targetEl.prepend(...nodes);
84
+ else if (pos === 'beforeBegin' && !isShadowRoot) targetEl.before(...nodes);
85
+ else if (pos === 'afterEnd' && !isShadowRoot) targetEl.after(...nodes);
86
+ }
87
+
88
+ const stateContext: any = {...hostSet};
89
+ findAllStateMetadata(currentThis).forEach(it => {
90
+ stateContext[it.name] = currentThis[it.propertyKey]
91
+ })
92
+ new ElementApply(targetEl, {id: id}).apply({target: 'noInitialized', context: stateContext, bind: currentThis});
93
+ return nodes;
75
94
  };
76
95
 
77
96
  /**
78
97
  * @applyNode decorator to surgically add/replace nodes to a target element.
79
98
  */
80
- export function applyNode(selector: string, options: ApplyNodeOptions = { position: 'beforeEnd' }): MethodDecorator {
99
+ export function applyNode(selector: string, options: ApplyNodeOptions = {position: 'replaceChildren'}): MethodDecorator {
81
100
  return (targetObj: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {
82
101
  const constructor = targetObj.constructor;
83
102
  let metaList = ReflectUtils.getOwnMetadata(APPLY_NODE_METADATA_KEY, constructor) as Map<string | symbol, ApplyNodeMetadata>;
@@ -85,17 +104,17 @@ export function applyNode(selector: string, options: ApplyNodeOptions = { positi
85
104
  metaList = new Map<string | symbol, ApplyNodeMetadata>();
86
105
  ReflectUtils.defineMetadata(APPLY_NODE_METADATA_KEY, metaList, constructor);
87
106
  }
88
- metaList.set(propertyKey, { propertyKey, selector, options });
107
+ metaList.set(propertyKey, {propertyKey, selector, options});
89
108
 
90
109
  const original = descriptor.value;
91
110
  descriptor.value = function (...args: any[]) {
92
111
  ensureInit(this);
93
-
112
+
94
113
  const conf = getElementConfig(this);
95
114
  const currentWin = (this as any)._resolveWindow?.(conf) || ((typeof window !== 'undefined' ? window : undefined) as Window);
96
115
  const currentDoc = currentWin.document;
97
116
  const hostSet = SwcUtils.getHelperAndHostSet(currentWin, this);
98
-
117
+
99
118
  const getTarget = () => {
100
119
  const r = options.root || 'auto';
101
120
  const applyRoot = (t: any) => {
@@ -113,37 +132,46 @@ export function applyNode(selector: string, options: ApplyNodeOptions = { positi
113
132
  if (selector === '$appHost') return applyRoot(hostSet.$appHost);
114
133
  if (selector === '$firstHost') return applyRoot(hostSet.$firstHost);
115
134
  if (selector === '$lastHost') return applyRoot(hostSet.$lastHost);
116
-
135
+
117
136
  const targetRoot = applyRoot(this);
118
137
  return targetRoot ? targetRoot.querySelector(selector) : null;
119
138
  };
120
139
 
140
+
141
+ console.log('fffffffffff')
121
142
  const targetEl = getTarget();
122
143
  const res = original.apply(this, args);
123
144
 
124
145
  const runApply = (target: any, val: any) => {
125
146
  const pos = options.position || 'beforeEnd';
126
-
147
+ // Delegate HTML/node processing to applyToDom which centralizes
148
+ // processing. runApply should not call processHtml itself to avoid
149
+ // duplicate processing.
150
+ const processedVal = val;
151
+
127
152
  // 사용자가 filter를 명시하면 그 조건으로, 아니면 항상 적용
128
- if (!options.filter || options.filter(target, val, {currentThis: this, helper: hostSet})) {
129
- applyToDom(target, val, pos, currentWin);
153
+ if (!options.filter || options.filter(target, processedVal, {currentThis: this, helper: hostSet})) {
154
+ applyToDom(this, target, processedVal, pos, currentWin);
130
155
  }
131
156
  };
132
157
 
158
+
159
+ const fallbackNodes: Node[] = [];
160
+ if (targetEl && options.fallback) {
161
+ const loadingRes = options.fallback.call(this, hostSet);
162
+ // applyToDom expects a Window as the 4th argument
163
+ fallbackNodes.push(...applyToDom(this, targetEl, loadingRes, options.position || 'beforeEnd', currentWin));
164
+ }
165
+
133
166
  if (res instanceof Promise) {
134
- // 비동기일 때만 로딩 표시
135
- if (targetEl && options.loading) {
136
- const loadingRes = options.loading.call(this, hostSet);
137
- applyToDom(targetEl, loadingRes, options.position || 'beforeEnd', currentDoc);
138
- }
139
-
140
- return res.then(finalRes => {
141
- if (finalRes !== undefined && targetEl) runApply(targetEl, finalRes);
142
- return finalRes;
143
- });
167
+ return res.then(finalRes => {
168
+ fallbackNodes.forEach((it: any)=>it.remove());
169
+ if (finalRes !== undefined && targetEl) runApply(targetEl, finalRes);
170
+ return finalRes;
171
+ });
144
172
  } else {
145
- if (res !== undefined && targetEl) runApply(targetEl, res);
146
- return res;
173
+ if (res !== undefined && targetEl) runApply(targetEl, res);
174
+ return res;
147
175
  }
148
176
  };
149
177
  };
@@ -163,35 +191,117 @@ export const findAllApplyNodeMetadata = (target: any): Map<string | symbol, Appl
163
191
  export function applyNodeThis(options: ApplyNodeOptions): MethodDecorator;
164
192
  export function applyNodeThis(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
165
193
  export function applyNodeThis(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
166
- if (propertyKey !== undefined) return applyNode('$this', { position: 'beforeEnd' })(targetOrOptions, propertyKey, descriptor);
194
+ const option: ApplyNodeOptions = {position: 'replaceChildren'};
195
+ if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);
167
196
  const opt = targetOrOptions || {};
168
- return applyNode('$this', { position: 'beforeEnd', ...opt });
197
+ return applyNode('$this', {...option, ...opt});
169
198
  }
170
199
 
171
- export function applyNodeThisReplaceChildren(options: ApplyNodeOptions): MethodDecorator;
200
+ export function applyNodeThisReplaceChildren(options: Omit<ApplyNodeOptions, 'position'>): MethodDecorator;
172
201
  export function applyNodeThisReplaceChildren(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
173
202
  export function applyNodeThisReplaceChildren(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
174
- if (propertyKey !== undefined) return applyNode('$this', { position: 'replaceChildren' })(targetOrOptions, propertyKey, descriptor);
203
+ const option: ApplyNodeOptions = {position: 'replaceChildren'};
204
+ if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);
205
+ const opt = targetOrOptions || {};
206
+ return applyNode('$this', {...opt, ...option});
207
+ }
208
+
209
+ export function applyNodeThisReplaceChildrenLightDom(options: Omit<ApplyNodeOptions, 'position' | 'root'>): MethodDecorator;
210
+ export function applyNodeThisReplaceChildrenLightDom(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
211
+ export function applyNodeThisReplaceChildrenLightDom(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
212
+ const options: ApplyNodeOptions = {position: 'replaceChildren', root: 'light'};
213
+ if (propertyKey !== undefined) return applyNode('$this', options)(targetOrOptions, propertyKey, descriptor);
175
214
  const opt = targetOrOptions || {};
176
- return applyNode('$this', { position: 'replaceChildren', ...opt });
215
+ return applyNode('$this', {...opt, ...options});
177
216
  }
178
217
 
179
- export function applyThisInnerHtmlNode(options: ApplyNodeOptions): MethodDecorator;
180
- export function applyThisInnerHtmlNode(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
181
- export function applyThisInnerHtmlNode(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
182
- if (propertyKey !== undefined) return applyNode('$this', { position: 'innerHtml' })(targetOrOptions, propertyKey, descriptor);
218
+ export function applyNodeThisBeforeEnd(options: Omit<ApplyNodeOptions, 'position'>): MethodDecorator;
219
+ export function applyNodeThisBeforeEnd(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
220
+ export function applyNodeThisBeforeEnd(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
221
+ const options: ApplyNodeOptions = {position: 'beforeEnd'};
222
+ if (propertyKey !== undefined) return applyNode('$this', options)(targetOrOptions, propertyKey, descriptor);
183
223
  const opt = targetOrOptions || {};
184
- return applyNode('$this', { position: 'innerHtml', ...opt });
224
+ return applyNode('$this', {...opt, ...options});
185
225
  }
186
226
 
187
- export function applyNodeReplaceChildren(selector: string, options: ApplyNodeOptions = {}): MethodDecorator {
188
- return applyNode(selector, { ...options, position: 'replaceChildren' });
227
+ export function applyNodeThisBeforeEndLightDom(options: Omit<ApplyNodeOptions, 'position' | 'root'>): MethodDecorator;
228
+ export function applyNodeThisBeforeEndLightDom(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
229
+ export function applyNodeThisBeforeEndLightDom(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
230
+ const option: ApplyNodeOptions = {position: 'beforeEnd', root: 'light'}
231
+ if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);
232
+ const opt = targetOrOptions || {};
233
+ return applyNode('$this', {...opt, ...option});
234
+ }
235
+ export function applyNodeThisBeforeEndShadow(options: Omit<ApplyNodeOptions, 'position' | 'root'>): MethodDecorator;
236
+ export function applyNodeThisBeforeEndShadow(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
237
+ export function applyNodeThisBeforeEndShadow(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
238
+ const option: ApplyNodeOptions = {position: 'beforeEnd', root: 'shadow'}
239
+ if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);
240
+ const opt = targetOrOptions || {};
241
+ return applyNode('$this', {...opt, ...option});
242
+ }
243
+
244
+ export function applyNodeThisAfterBegin(options: Omit<ApplyNodeOptions, 'position'>): MethodDecorator;
245
+ export function applyNodeThisAfterBegin(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
246
+ export function applyNodeThisAfterBegin(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
247
+ const option: ApplyNodeOptions = {position: 'afterBegin'};
248
+ if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);
249
+ const opt = targetOrOptions || {};
250
+ return applyNode('$this', {...opt, ...option});
251
+ }
252
+
253
+ export function applyNodeThisAfterBeginLightDom(options: Omit<ApplyNodeOptions, 'position' | 'root'>): MethodDecorator;
254
+ export function applyNodeThisAfterBeginLightDom(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
255
+ export function applyNodeThisAfterBeginLightDom(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
256
+ const option: ApplyNodeOptions = {position: 'afterBegin', root: 'light'}
257
+ if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);
258
+ const opt = targetOrOptions || {};
259
+ return applyNode('$this', {...opt, ...option});
260
+ }
261
+
262
+ export function applyNodeThisInnerHtml(options: Omit<ApplyNodeOptions, 'position'>): MethodDecorator;
263
+ export function applyNodeThisInnerHtml(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
264
+ export function applyNodeThisInnerHtml(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
265
+ const option: ApplyNodeOptions = {position: 'innerHtml'}
266
+ if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);
267
+ const opt = targetOrOptions || {};
268
+ return applyNode('$this', {...opt, ...option});
269
+ }
270
+
271
+ export function applyThisInnerHtmlNodeLightDom(options: Omit<ApplyNodeOptions, 'position' | 'root'>): MethodDecorator;
272
+ export function applyThisInnerHtmlNodeLightDom(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
273
+ export function applyThisInnerHtmlNodeLightDom(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
274
+ const option: ApplyNodeOptions = {position: 'innerHtml', root: 'light'};
275
+ if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);
276
+ const opt = targetOrOptions || {};
277
+ return applyNode('$this', {...opt, ...option});
189
278
  }
190
279
 
191
- export function applyNodeInnerHtml(selector: string, options: ApplyNodeOptions = {}): MethodDecorator {
192
- return applyNode(selector, { ...options, position: 'innerHtml' });
280
+ export function applyThisReplaceChildrenNodeLightDom(options: Omit<ApplyNodeOptions, 'position' | 'root'>): MethodDecorator;
281
+ export function applyThisReplaceChildrenNodeLightDom(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
282
+ export function applyThisReplaceChildrenNodeLightDom(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
283
+ const option: ApplyNodeOptions = {position: 'replaceChildren', root: 'light'};
284
+ if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);
285
+ const opt = targetOrOptions || {};
286
+ return applyNode('$this', {...opt, ...option});
193
287
  }
194
288
 
195
- export function applyNodeInnerText(selector: string, options: ApplyNodeOptions = {}): MethodDecorator {
196
- return applyNode(selector, { ...options, position: 'innerText' });
289
+ export function applyNodeReplaceChildren(selector: string, options: Omit<ApplyNodeOptions, 'position'> = {}): MethodDecorator {
290
+ return applyNode(selector, {...options, position: 'replaceChildren'});
197
291
  }
292
+
293
+ export function applyNodeInnerHtml(selector: string, options: Omit<ApplyNodeOptions, 'position'> = {}): MethodDecorator {
294
+ return applyNode(selector, {...options, position: 'innerHtml'});
295
+ }
296
+
297
+ // export function applyNodeInnerHtmlLightDom(selector: string, options: Omit<ApplyNodeOptions, 'position' | 'root'> = {}): MethodDecorator {
298
+ // return applyNode(selector, {...options, position: 'innerHtml', root: 'light'});
299
+ // }
300
+
301
+ export function applyNodeInnerText(selector: string, options: Omit<ApplyNodeOptions, 'position'> = {}): MethodDecorator {
302
+ return applyNode(selector, {...options, position: 'innerText'});
303
+ }
304
+
305
+ // export function applyNodeInnerTextLightDom(selector: string, options: Omit<ApplyNodeOptions, 'position' | 'root'> = {}): MethodDecorator {
306
+ // return applyNode(selector, {...options, position: 'innerText', root: 'light'});
307
+ // }