@dooboostore/simple-web-component 1.0.37 → 1.0.38

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 (156) hide show
  1. package/README.md +384 -93
  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 +97 -15
  9. package/dist/cjs/decorators/applyNode.js.map +2 -2
  10. package/dist/cjs/decorators/applySlot.js +16 -9
  11. package/dist/cjs/decorators/applySlot.js.map +2 -2
  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 +68 -38
  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 +84 -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 +97 -15
  50. package/dist/esm/decorators/applyNode.js.map +2 -2
  51. package/dist/esm/decorators/applySlot.js +16 -9
  52. package/dist/esm/decorators/applySlot.js.map +2 -2
  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 +72 -42
  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 +65 -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 +3356 -2477
  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 +22 -6
  92. package/dist/types/decorators/applyNode.d.ts.map +1 -1
  93. package/dist/types/decorators/applySlot.d.ts.map +1 -1
  94. package/dist/types/decorators/applyStyle.d.ts.map +1 -1
  95. package/dist/types/decorators/attribute.d.ts.map +1 -1
  96. package/dist/types/decorators/elementDefine.d.ts.map +1 -1
  97. package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
  98. package/dist/types/decorators/index.d.ts +1 -0
  99. package/dist/types/decorators/index.d.ts.map +1 -1
  100. package/dist/types/decorators/lifecycles.d.ts +10 -14
  101. package/dist/types/decorators/lifecycles.d.ts.map +1 -1
  102. package/dist/types/decorators/publishSwcAppMessage.d.ts.map +1 -1
  103. package/dist/types/decorators/query.d.ts +1 -1
  104. package/dist/types/decorators/query.d.ts.map +1 -1
  105. package/dist/types/decorators/queryAll.d.ts.map +1 -1
  106. package/dist/types/decorators/setProperty.d.ts +1 -1
  107. package/dist/types/decorators/setProperty.d.ts.map +1 -1
  108. package/dist/types/decorators/state.d.ts +9 -0
  109. package/dist/types/decorators/state.d.ts.map +1 -0
  110. package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts.map +1 -1
  111. package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts +5 -1
  112. package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts.map +1 -1
  113. package/dist/types/elements/SwcApp.d.ts +35 -6
  114. package/dist/types/elements/SwcApp.d.ts.map +1 -1
  115. package/dist/types/elements/SwcAppMixin.d.ts +405 -0
  116. package/dist/types/elements/SwcAppMixin.d.ts.map +1 -0
  117. package/dist/types/elements/index.d.ts +2 -2
  118. package/dist/types/elements/index.d.ts.map +1 -1
  119. package/dist/types/index.d.ts +1 -1
  120. package/dist/types/index.d.ts.map +1 -1
  121. package/dist/types/{types.d.ts → types/index.d.ts} +11 -11
  122. package/dist/types/types/index.d.ts.map +1 -0
  123. package/dist/types/utils/Utils.d.ts +14 -2
  124. package/dist/types/utils/Utils.d.ts.map +1 -1
  125. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +3358 -2479
  126. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
  127. package/package.json +4 -4
  128. package/src/SwcAppEngine.ts +6 -2
  129. package/src/decorators/addEventListener.ts +21 -5
  130. package/src/decorators/applyAttribute.ts +1 -1
  131. package/src/decorators/applyClass.ts +1 -1
  132. package/src/decorators/applyNode.ts +180 -62
  133. package/src/decorators/applySlot.ts +27 -67
  134. package/src/decorators/applyStyle.ts +4 -4
  135. package/src/decorators/attribute.ts +1 -1
  136. package/src/decorators/elementDefine.ts +110 -58
  137. package/src/decorators/emitCustomEvent.ts +1 -1
  138. package/src/decorators/index.ts +2 -0
  139. package/src/decorators/lifecycles.ts +50 -26
  140. package/src/decorators/publishSwcAppMessage.ts +2 -3
  141. package/src/decorators/query.ts +4 -4
  142. package/src/decorators/queryAll.ts +1 -1
  143. package/src/decorators/setProperty.ts +1 -1
  144. package/src/decorators/state.ts +84 -0
  145. package/src/decorators/subscribeSwcAppMessageWhileConnected.ts +1 -1
  146. package/src/decorators/subscribeSwcAppRouteChangeWhileConnected.ts +4 -3
  147. package/src/elements/SwcApp.ts +239 -441
  148. package/src/elements/SwcAppMixin.ts +328 -0
  149. package/src/elements/index.ts +2 -9
  150. package/src/index.ts +2 -4
  151. package/src/{types.ts → types/index.ts} +13 -10
  152. package/src/types/window.d.ts +3 -0
  153. package/src/utils/Utils.ts +205 -20
  154. package/dist/cjs/types.js.map +0 -7
  155. package/dist/esm/types.js.map +0 -7
  156. 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.38",
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",
95
+ "@dooboostore/core": "1.0.32",
96
96
  "@dooboostore/core-node": "1.0.12",
97
- "@dooboostore/core-web": "1.0.11",
98
- "@dooboostore/simple-boot": "1.0.55"
97
+ "@dooboostore/core-web": "1.0.12",
98
+ "@dooboostore/simple-boot": "1.0.56"
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 {
@@ -43,41 +45,67 @@ const normalizeNodes = (res: any, doc: Document): Node[] => {
43
45
  });
44
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: any, pos: ApplyNodePosition, win: Window, host?: any) => {
49
+ if (!targetEl) return;
48
50
 
49
- const doc = win.document;
50
-
51
- if (pos === 'innerHtml') {
52
- targetEl.innerHTML = res !== undefined && res !== null ? String(res) : '';
53
- return;
51
+ // console.log('------------',currentThis.tagName, res)
52
+ const doc = win.document;
53
+ const hostSet = SwcUtils.getHelperAndHostSet(win, currentThis);
54
+ const id = currentThis._swcId;
55
+ // Allow processHtml to run here so all DOM insertions go through a single
56
+ // processing point. processHtml may mutate Node[] in-place or return a
57
+ // transformed string result for text processing.
58
+ try {
59
+ if (typeof res === 'string') {
60
+ const processed = SwcUtils.projectProcessHtml(id, res as string, doc);
61
+ if (processed !== undefined) res = processed;
62
+ } else if (res) {
63
+ SwcUtils.projectProcessHtml(id, res, doc);
54
64
  }
55
-
56
- if (pos === 'innerText') {
57
- if (targetEl.innerText !== undefined) {
58
- targetEl.innerText = res !== undefined && res !== null ? String(res) : '';
59
- }
60
- return;
65
+ } catch (e) {
66
+ // swallow and proceed with original res
67
+ }
68
+
69
+ if (pos === 'innerHtml') {
70
+ targetEl.innerHTML = res !== undefined && res !== null ? String(res) : '';
71
+ return;
72
+ }
73
+
74
+ if (pos === 'innerText') {
75
+ if (targetEl.innerText !== undefined) {
76
+ targetEl.innerText = res !== undefined && res !== null ? String(res) : '';
61
77
  }
78
+ return;
79
+ }
80
+
81
+ const stateContext: any = {...hostSet};
82
+ findAllStateMetadata(currentThis).forEach(it => {
83
+ stateContext[it.name] = currentThis[it.propertyKey]
84
+ })
85
+ new ElementApply(currentThis, {id: currentThis._swcId}).apply({target: 'noInitialized', context: stateContext, bind: currentThis});
86
+
62
87
 
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);
88
+ const isShadowRoot = targetEl instanceof win.ShadowRoot;
89
+ const nodes = normalizeNodes(res, doc);
90
+ if (pos === 'replace') {
91
+ if (!isShadowRoot) targetEl.replaceWith(...nodes);
92
+ } else if (pos === 'replaceChildren') {
93
+ targetEl.replaceChildren(...nodes);
94
+ } else {
95
+ if (pos === 'beforeEnd') {
96
+ console.log('tarbbbbbbbbbbbbbb')
97
+ targetEl.append(...nodes)
74
98
  }
99
+ else if (pos === 'afterBegin') targetEl.prepend(...nodes);
100
+ else if (pos === 'beforeBegin' && !isShadowRoot) targetEl.before(...nodes);
101
+ else if (pos === 'afterEnd' && !isShadowRoot) targetEl.after(...nodes);
102
+ }
75
103
  };
76
104
 
77
105
  /**
78
106
  * @applyNode decorator to surgically add/replace nodes to a target element.
79
107
  */
80
- export function applyNode(selector: string, options: ApplyNodeOptions = { position: 'beforeEnd' }): MethodDecorator {
108
+ export function applyNode(selector: string, options: ApplyNodeOptions = {position: 'replaceChildren'}): MethodDecorator {
81
109
  return (targetObj: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {
82
110
  const constructor = targetObj.constructor;
83
111
  let metaList = ReflectUtils.getOwnMetadata(APPLY_NODE_METADATA_KEY, constructor) as Map<string | symbol, ApplyNodeMetadata>;
@@ -85,17 +113,17 @@ export function applyNode(selector: string, options: ApplyNodeOptions = { positi
85
113
  metaList = new Map<string | symbol, ApplyNodeMetadata>();
86
114
  ReflectUtils.defineMetadata(APPLY_NODE_METADATA_KEY, metaList, constructor);
87
115
  }
88
- metaList.set(propertyKey, { propertyKey, selector, options });
116
+ metaList.set(propertyKey, {propertyKey, selector, options});
89
117
 
90
118
  const original = descriptor.value;
91
119
  descriptor.value = function (...args: any[]) {
92
120
  ensureInit(this);
93
-
121
+
94
122
  const conf = getElementConfig(this);
95
123
  const currentWin = (this as any)._resolveWindow?.(conf) || ((typeof window !== 'undefined' ? window : undefined) as Window);
96
124
  const currentDoc = currentWin.document;
97
125
  const hostSet = SwcUtils.getHelperAndHostSet(currentWin, this);
98
-
126
+
99
127
  const getTarget = () => {
100
128
  const r = options.root || 'auto';
101
129
  const applyRoot = (t: any) => {
@@ -113,37 +141,45 @@ export function applyNode(selector: string, options: ApplyNodeOptions = { positi
113
141
  if (selector === '$appHost') return applyRoot(hostSet.$appHost);
114
142
  if (selector === '$firstHost') return applyRoot(hostSet.$firstHost);
115
143
  if (selector === '$lastHost') return applyRoot(hostSet.$lastHost);
116
-
144
+
117
145
  const targetRoot = applyRoot(this);
118
146
  return targetRoot ? targetRoot.querySelector(selector) : null;
119
147
  };
120
148
 
149
+
150
+ console.log('fffffffffff')
121
151
  const targetEl = getTarget();
122
152
  const res = original.apply(this, args);
123
153
 
124
154
  const runApply = (target: any, val: any) => {
125
155
  const pos = options.position || 'beforeEnd';
126
-
156
+ // Delegate HTML/node processing to applyToDom which centralizes
157
+ // processing. runApply should not call processHtml itself to avoid
158
+ // duplicate processing.
159
+ const processedVal = val;
160
+
127
161
  // 사용자가 filter를 명시하면 그 조건으로, 아니면 항상 적용
128
- if (!options.filter || options.filter(target, val, {currentThis: this, helper: hostSet})) {
129
- applyToDom(target, val, pos, currentWin);
162
+ if (!options.filter || options.filter(target, processedVal, {currentThis: this, helper: hostSet})) {
163
+ applyToDom(this, target, processedVal, pos, currentWin);
130
164
  }
131
165
  };
132
166
 
133
167
  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
- });
168
+ // 비동기일 때만 로딩 표시
169
+ if (targetEl && options.fallback) {
170
+ const loadingRes = options.fallback.call(this, hostSet);
171
+ // applyToDom expects a Window as the 4th argument
172
+ applyToDom(this, targetEl, loadingRes, options.position || 'beforeEnd', currentWin);
173
+ }
174
+
175
+ return res.then(finalRes => {
176
+ console.log('amnkj')
177
+ if (finalRes !== undefined && targetEl) runApply(targetEl, finalRes);
178
+ return finalRes;
179
+ });
144
180
  } else {
145
- if (res !== undefined && targetEl) runApply(targetEl, res);
146
- return res;
181
+ if (res !== undefined && targetEl) runApply(targetEl, res);
182
+ return res;
147
183
  }
148
184
  };
149
185
  };
@@ -163,35 +199,117 @@ export const findAllApplyNodeMetadata = (target: any): Map<string | symbol, Appl
163
199
  export function applyNodeThis(options: ApplyNodeOptions): MethodDecorator;
164
200
  export function applyNodeThis(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
165
201
  export function applyNodeThis(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
166
- if (propertyKey !== undefined) return applyNode('$this', { position: 'beforeEnd' })(targetOrOptions, propertyKey, descriptor);
202
+ const option: ApplyNodeOptions = {position: 'replaceChildren'};
203
+ if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);
167
204
  const opt = targetOrOptions || {};
168
- return applyNode('$this', { position: 'beforeEnd', ...opt });
205
+ return applyNode('$this', {...option, ...opt});
169
206
  }
170
207
 
171
- export function applyNodeThisReplaceChildren(options: ApplyNodeOptions): MethodDecorator;
208
+ export function applyNodeThisReplaceChildren(options: Omit<ApplyNodeOptions, 'position'>): MethodDecorator;
172
209
  export function applyNodeThisReplaceChildren(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
173
210
  export function applyNodeThisReplaceChildren(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
174
- if (propertyKey !== undefined) return applyNode('$this', { position: 'replaceChildren' })(targetOrOptions, propertyKey, descriptor);
211
+ const option: ApplyNodeOptions = {position: 'replaceChildren'};
212
+ if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);
213
+ const opt = targetOrOptions || {};
214
+ return applyNode('$this', {...opt, ...option});
215
+ }
216
+
217
+ export function applyNodeThisReplaceChildrenLightDom(options: Omit<ApplyNodeOptions, 'position' | 'root'>): MethodDecorator;
218
+ export function applyNodeThisReplaceChildrenLightDom(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
219
+ export function applyNodeThisReplaceChildrenLightDom(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
220
+ const options: ApplyNodeOptions = {position: 'replaceChildren', root: 'light'};
221
+ if (propertyKey !== undefined) return applyNode('$this', options)(targetOrOptions, propertyKey, descriptor);
175
222
  const opt = targetOrOptions || {};
176
- return applyNode('$this', { position: 'replaceChildren', ...opt });
223
+ return applyNode('$this', {...opt, ...options});
177
224
  }
178
225
 
179
- export function applyThisInnerHtmlNode(options: ApplyNodeOptions): MethodDecorator;
226
+ export function applyNodeThisBeforeEnd(options: Omit<ApplyNodeOptions, 'position'>): MethodDecorator;
227
+ export function applyNodeThisBeforeEnd(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
228
+ export function applyNodeThisBeforeEnd(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
229
+ const options: ApplyNodeOptions = {position: 'beforeEnd'};
230
+ if (propertyKey !== undefined) return applyNode('$this', options)(targetOrOptions, propertyKey, descriptor);
231
+ const opt = targetOrOptions || {};
232
+ return applyNode('$this', {...opt, ...options});
233
+ }
234
+
235
+ export function applyNodeThisBeforeEndLightDom(options: Omit<ApplyNodeOptions, 'position' | 'root'>): MethodDecorator;
236
+ export function applyNodeThisBeforeEndLightDom(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
237
+ export function applyNodeThisBeforeEndLightDom(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
238
+ const option: ApplyNodeOptions = {position: 'beforeEnd', root: 'light'}
239
+ if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);
240
+ const opt = targetOrOptions || {};
241
+ return applyNode('$this', {...opt, ...option});
242
+ }
243
+ export function applyNodeThisBeforeEndShadow(options: Omit<ApplyNodeOptions, 'position' | 'root'>): MethodDecorator;
244
+ export function applyNodeThisBeforeEndShadow(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
245
+ export function applyNodeThisBeforeEndShadow(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
246
+ const option: ApplyNodeOptions = {position: 'beforeEnd', root: 'shadow'}
247
+ if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);
248
+ const opt = targetOrOptions || {};
249
+ return applyNode('$this', {...opt, ...option});
250
+ }
251
+
252
+ export function applyNodeThisAfterBegin(options: Omit<ApplyNodeOptions, 'position'>): MethodDecorator;
253
+ export function applyNodeThisAfterBegin(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
254
+ export function applyNodeThisAfterBegin(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
255
+ const option: ApplyNodeOptions = {position: 'afterBegin'};
256
+ if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);
257
+ const opt = targetOrOptions || {};
258
+ return applyNode('$this', {...opt, ...option});
259
+ }
260
+
261
+ export function applyNodeThisAfterBeginLightDom(options: Omit<ApplyNodeOptions, 'position' | 'root'>): MethodDecorator;
262
+ export function applyNodeThisAfterBeginLightDom(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
263
+ export function applyNodeThisAfterBeginLightDom(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
264
+ const option: ApplyNodeOptions = {position: 'afterBegin', root: 'light'}
265
+ if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);
266
+ const opt = targetOrOptions || {};
267
+ return applyNode('$this', {...opt, ...option});
268
+ }
269
+
270
+ export function applyThisInnerHtmlNode(options: Omit<ApplyNodeOptions, 'position'>): MethodDecorator;
180
271
  export function applyThisInnerHtmlNode(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
181
272
  export function applyThisInnerHtmlNode(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
182
- if (propertyKey !== undefined) return applyNode('$this', { position: 'innerHtml' })(targetOrOptions, propertyKey, descriptor);
273
+ const option: ApplyNodeOptions = {position: 'innerHtml'}
274
+ if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);
183
275
  const opt = targetOrOptions || {};
184
- return applyNode('$this', { position: 'innerHtml', ...opt });
276
+ return applyNode('$this', {...opt, ...option});
185
277
  }
186
278
 
187
- export function applyNodeReplaceChildren(selector: string, options: ApplyNodeOptions = {}): MethodDecorator {
188
- return applyNode(selector, { ...options, position: 'replaceChildren' });
279
+ export function applyThisInnerHtmlNodeLightDom(options: Omit<ApplyNodeOptions, 'position' | 'root'>): MethodDecorator;
280
+ export function applyThisInnerHtmlNodeLightDom(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
281
+ export function applyThisInnerHtmlNodeLightDom(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
282
+ const option: ApplyNodeOptions = {position: 'innerHtml', root: 'light'};
283
+ if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);
284
+ const opt = targetOrOptions || {};
285
+ return applyNode('$this', {...opt, ...option});
286
+ }
287
+
288
+ export function applyThisReplaceChildrenNodeLightDom(options: Omit<ApplyNodeOptions, 'position' | 'root'>): MethodDecorator;
289
+ export function applyThisReplaceChildrenNodeLightDom(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
290
+ export function applyThisReplaceChildrenNodeLightDom(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
291
+ const option: ApplyNodeOptions = {position: 'replaceChildren', root: 'light'};
292
+ if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);
293
+ const opt = targetOrOptions || {};
294
+ return applyNode('$this', {...opt, ...option});
189
295
  }
190
296
 
191
- export function applyNodeInnerHtml(selector: string, options: ApplyNodeOptions = {}): MethodDecorator {
192
- return applyNode(selector, { ...options, position: 'innerHtml' });
297
+ export function applyNodeReplaceChildren(selector: string, options: Omit<ApplyNodeOptions, 'position'> = {}): MethodDecorator {
298
+ return applyNode(selector, {...options, position: 'replaceChildren'});
193
299
  }
194
300
 
195
- export function applyNodeInnerText(selector: string, options: ApplyNodeOptions = {}): MethodDecorator {
196
- return applyNode(selector, { ...options, position: 'innerText' });
301
+ export function applyNodeInnerHtml(selector: string, options: Omit<ApplyNodeOptions, 'position'> = {}): MethodDecorator {
302
+ return applyNode(selector, {...options, position: 'innerHtml'});
197
303
  }
304
+
305
+ // export function applyNodeInnerHtmlLightDom(selector: string, options: Omit<ApplyNodeOptions, 'position' | 'root'> = {}): MethodDecorator {
306
+ // return applyNode(selector, {...options, position: 'innerHtml', root: 'light'});
307
+ // }
308
+
309
+ export function applyNodeInnerText(selector: string, options: Omit<ApplyNodeOptions, 'position'> = {}): MethodDecorator {
310
+ return applyNode(selector, {...options, position: 'innerText'});
311
+ }
312
+
313
+ // export function applyNodeInnerTextLightDom(selector: string, options: Omit<ApplyNodeOptions, 'position' | 'root'> = {}): MethodDecorator {
314
+ // return applyNode(selector, {...options, position: 'innerText', root: 'light'});
315
+ // }
@@ -1,7 +1,6 @@
1
- import { ReflectUtils } from '@dooboostore/core';
2
- import { ensureInit, getElementConfig } from './elementDefine';
3
- import { HelperHostSet, SwcRootType } from '../types';
4
- import { SwcUtils } from "../utils/Utils";
1
+ import {ReflectUtils} from '@dooboostore/core';
2
+ import {ensureInit, getElementConfig} from './elementDefine';
3
+ import {SwcUtils} from "../utils/Utils";
5
4
  import {NodeSlot} from "@dooboostore/core-web";
6
5
  /*
7
6
  <!-- beforebegin -->
@@ -89,6 +88,14 @@ export function applySlot(id: string, options: ApplySlotOptions = { position: 'r
89
88
  const nodeSlot = new NodeSlot(this, `${this._swcId}-${id}`);
90
89
  return nodeSlot;
91
90
  },
91
+ set(this: any, nv: any) {
92
+ if(nv) {
93
+ // 있을때 아무일도안함
94
+ } else {
95
+ const nodeSlot = new NodeSlot(this, `${this._swcId}-${id}`);
96
+ nodeSlot.clear();
97
+ }
98
+ },
92
99
  configurable: true,
93
100
  enumerable: true,
94
101
  })
@@ -115,80 +122,33 @@ export function applySlot(id: string, options: ApplySlotOptions = { position: 'r
115
122
  const currentWin = (this as any)._resolveWindow?.(conf) || ((typeof window !== 'undefined' ? window : undefined) as Window);
116
123
  const currentDoc = currentWin.document;
117
124
  const hostSet = SwcUtils.getHelperAndHostSet(currentWin, this);
118
-
119
-
120
- // const getTarget = () => {
121
- // const r = options.root || 'auto';
122
- // const applyRoot = (t: any) => {
123
- // if (!t) return t;
124
- // if (r === 'auto') return t.shadowRoot || t;
125
- // if (r === 'shadow') return t.shadowRoot;
126
- // if (r === 'light') return t;
127
- // if (r === 'all') return t.shadowRoot || t;
128
- // return t;
129
- // };
130
- //
131
- // if (selector === '$this') return applyRoot(this);
132
- // if (selector === '$host') return applyRoot(hostSet.$host);
133
- // if (selector === '$parentHost') return applyRoot(hostSet.$parentHost);
134
- // if (selector === '$appHost') return applyRoot(hostSet.$appHost);
135
- // if (selector === '$firstHost') return applyRoot(hostSet.$firstHost);
136
- // if (selector === '$lastHost') return applyRoot(hostSet.$lastHost);
137
- //
138
- // const targetRoot = applyRoot(this);
139
- // return targetRoot ? targetRoot.querySelector(selector) : null;
140
- // };
141
-
142
- // const targetEl = getTarget();
143
- const res = original.apply(this, args);
144
-
145
- // const runApply = (target: any, val: any) => {
146
- // const pos = options.position || 'beforeEnd';
147
- //
148
- // // 사용자가 filter를 명시하면 그 조건으로, 아니면 항상 적용
149
- // if (!options.filter || options.filter(target, val, {currentThis: this, helper: hostSet})) {
150
- // applyToDom(target, val, pos, currentWin);
151
- // }
152
- // };
153
-
154
- // if (res instanceof Promise) {
155
- // // 비동기일 때만 로딩 표시
156
- // if (targetEl && options.loading) {
157
- // const loadingRes = options.loading.call(this, hostSet);
158
- // applyToDom(targetEl, loadingRes, options.position || 'beforeEnd', currentDoc);
159
- // }
160
- //
161
- // return res.then(finalRes => {
162
- // if (finalRes !== undefined && targetEl) runApply(targetEl, finalRes);
163
- // return finalRes;
164
- // });
165
- // } else {
166
- // if (res !== undefined && targetEl) runApply(targetEl, res);
167
- // return res;
168
- // }
125
+ let res = original.apply(this, args);
169
126
  if (res) {
170
- const nodeSlot = new NodeSlot(this, `${this._swcId}-${id}`);
127
+ // res = SwcUtils.projectProcessHtml(this, res)
128
+ const nodeSlot = new NodeSlot(this, this._swcId);
171
129
  const pos = options.position || 'replaceChildrenHtml';
172
130
  const doc = currentWin.document;
173
-
174
-
175
- // const isShadowRoot = targetEl instanceof win.ShadowRoot;
176
- // const nodes = normalizeNodes(res, doc);
177
131
  if (pos === 'replaceChildrenHtml') {
178
- nodeSlot.replaceChildrenHtml(res);
132
+ nodeSlot.replaceChildrenHtml(id, res);
179
133
  } else if (pos === 'replaceChildrenText') {
180
- nodeSlot.replaceChildrenText(res);
134
+ nodeSlot.replaceChildrenText(id, res);
181
135
  } else if (pos === 'appendHtml') {
182
- nodeSlot.appendHtml(res);
136
+ nodeSlot.appendHtml(id, res);
183
137
  } else if (pos === 'appendText') {
184
- nodeSlot.appendText(res);
138
+ nodeSlot.appendText(id, res);
185
139
  } else if (pos === 'prependHtml') {
186
- nodeSlot.prependHtml(res);
140
+ nodeSlot.prependHtml(id, res);
187
141
  } else if (pos === 'prependText') {
188
- nodeSlot.prependText(res);
142
+ nodeSlot.prependText(id, res);
189
143
  } else if (pos === 'clear') {
190
- nodeSlot.clear();
144
+ nodeSlot.clear(id);
191
145
  }
146
+
147
+ // const stateContext: any = {...hostSet};
148
+ // getStateMetadata(this).forEach(it => {
149
+ // stateContext[it.name] = this[it.propertyKey]
150
+ // })
151
+ // new ElementApply(this, {id: this._swcId}).apply({target:'noInitialized', context: stateContext, bind: this});
192
152
  }
193
153
  return res;
194
154
  };
@@ -1,7 +1,7 @@
1
- import { ReflectUtils } from '@dooboostore/core';
2
- import { ensureInit } from './elementDefine';
3
- import { SwcUtils } from '../utils/Utils';
4
- import { SwcQueryOptions, HelperHostSet } from '../types';
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
5
 
6
6
  export type StyleAction = 'set' | 'update' | 'remove';
7
7
 
@@ -1,7 +1,7 @@
1
1
  import { ReflectUtils, FunctionUtils, ActionExpression } from '@dooboostore/core';
2
2
  import { ensureInit, getElementConfig } from './elementDefine';
3
3
  import { SwcUtils } from '../utils/Utils';
4
- import { SpecialSelector, SwcQueryOptions } from '../types';
4
+ import { SpecialSelector, SwcQueryOptions, HelperHostSet } from '../types';
5
5
  import { ConvertUtils } from '@dooboostore/core-web';
6
6
  export interface AttributeFieldOptions extends SwcQueryOptions {
7
7
  name?: string;