@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
@@ -1,19 +1,20 @@
1
- import {ReflectUtils, FunctionUtils, ActionExpression} from '@dooboostore/core';
1
+ import {ActionExpression, FunctionUtils, ReflectUtils} from '@dooboostore/core';
2
2
  import {getAddEventListenerMetadata} from './addEventListener';
3
- import {ON_INITIALIZE_METADATA_KEY, ON_BEFORE_CONNECTED_METADATA_KEY, ON_AFTER_CONNECTED_METADATA_KEY, ON_BEFORE_DISCONNECTED_METADATA_KEY, ON_AFTER_DISCONNECTED_METADATA_KEY, ON_BEFORE_ADOPTED_METADATA_KEY, ON_AFTER_ADOPTED_METADATA_KEY, findAllLifecycleMetadata, getOnConnectedInnerHtmlMetadata, getOnConnectedBeforeMetadata, getOnConnectedAfterMetadata, ON_CONNECTED_COMPLETED_METADATA_KEY} from './lifecycles';
3
+ import {findAllLifecycleMetadata, findAllOnConnectedAfterMetadata, findAllOnConnectedBeforeMetadata, findAllOnConnectedMetadata, ON_AFTER_ADOPTED_METADATA_KEY, ON_AFTER_DISCONNECTED_METADATA_KEY, ON_BEFORE_ADOPTED_METADATA_KEY, ON_BEFORE_DISCONNECTED_METADATA_KEY, ON_CONNECTED_COMPLETED_METADATA_KEY, ON_INITIALIZE_METADATA_KEY} from './lifecycles';
4
4
  import {getEmitCustomEventMetadataList} from './emitCustomEvent';
5
- import {findAllAttributeChangedMetadata, convertAttributeValue} from './changedAttributeThis';
5
+ import {convertAttributeValue, findAllAttributeChangedMetadata} from './changedAttributeThis';
6
6
  import {findAllAttributeApplyMetadata} from './applyAttribute';
7
7
  import {findAllAttributeMetadata, getAttributeValue} from './attribute';
8
8
  import {getQueryMetadata} from './query';
9
9
  import {getQueryAllMetadata} from './queryAll';
10
10
  import {SwcUtils} from '../utils/Utils';
11
- import {HTML_TAG_ENTRIES, DOM_EVENT_NAMES} from '../config/config';
11
+ import {DOM_EVENT_NAMES, HTML_TAG_ENTRIES} from '../config/config';
12
12
  import {SituationTypeContainer, SituationTypeContainers} from '@dooboostore/simple-boot/decorators/inject/Inject';
13
- import {InjectSituationType, HostSet, HelperHostSet, SwcAppInterface} from '../types';
14
- import {ConvertUtils, NodeSlot} from '@dooboostore/core-web';
15
- import {isSSR} from "../elements/SwcApp";
13
+ import {HelperHostSet, HostSet, InjectSituationType} from '../types';
14
+ import {ConvertUtils, ElementApply, NodeSlot} from '@dooboostore/core-web';
15
+ import {isSSR} from "../elements/SwcAppMixin";
16
16
  import {findAllApplySlotMetadata} from "./applySlot";
17
+ import {findAllStateMetadata} from "./state";
17
18
 
18
19
  // --- Core Interfaces & Types ---
19
20
 
@@ -39,11 +40,10 @@ export const getElementConfig = (target: any): ElementMetadata | undefined => {
39
40
 
40
41
  export const ensureInit = (inst: any) => { // HTMLElement
41
42
  if (!inst.__swc_initialized) {
42
- inst._swcId = inst?.getAttribute?.('swc-use-ssr') ?? Math.random().toString(36).substring(2, 11);
43
+ inst._swcId = inst?.getAttribute?.('swc-use-ssr') ?? 's' + Math.random().toString(36).substring(2, 11).toLowerCase();
43
44
  inst._emitHandlers = new Map();
44
45
  inst._boundListeners = [];
45
46
  inst.__swc_initialized = true;
46
-
47
47
  // const attributeList = findAllQ(inst);
48
48
  // attributeList.forEach(meta => {
49
49
  // delete (inst as any)[meta.propertyKey];
@@ -54,7 +54,7 @@ export const ensureInit = (inst: any) => { // HTMLElement
54
54
  // ╔════════════════════════════════════════════════════════════════════════════════╗
55
55
  // ║ decorator 필드의 own property 삭제 ║
56
56
  // ║ ║
57
- // ║ 이유: ║
57
+ // ║ 이유: own property가 있으면 prototype의 getter/setter는 절대 안 탄다 ║
58
58
  // ║ 1. TypeScript는 초기값이 있는 필드를 constructor에서 own property로 생성 ║
59
59
  // ║ @attributeThis('id') myId: string = "default" → this.myId = "default" ║
60
60
  // ║ ║
@@ -73,7 +73,11 @@ export const ensureInit = (inst: any) => { // HTMLElement
73
73
  // @attribute 필드의 own property 삭제 → getter/setter 작동
74
74
  const attributeList = findAllAttributeMetadata(target);
75
75
  attributeList.forEach(meta => {
76
+ const initUserData = (inst as any)[meta.propertyKey];
76
77
  delete (inst as any)[meta.propertyKey];
78
+ // undefined 이면은 외부 attribute string html을 리스팩한다
79
+ if (initUserData !== undefined)
80
+ (inst as any)[meta.propertyKey] = initUserData;
77
81
  });
78
82
 
79
83
  // @query 필드의 own property 삭제 → getter 작동
@@ -93,8 +97,16 @@ export const ensureInit = (inst: any) => { // HTMLElement
93
97
  }
94
98
  const slotAllList = findAllApplySlotMetadata(target);
95
99
  if (slotAllList) {
96
- slotAllList.filter(it=>it.type === 'property').forEach(meta => {
100
+ slotAllList.filter(it => it.type === 'property').forEach(meta => {
101
+ delete (inst as any)[meta.propertyKey];
102
+ });
103
+ }
104
+ const stateAllList = findAllStateMetadata(target);
105
+ if (stateAllList) {
106
+ stateAllList.forEach(meta => {
107
+ const initUserData = (inst as any)[meta.propertyKey];
97
108
  delete (inst as any)[meta.propertyKey];
109
+ (inst as any)[meta.propertyKey] = initUserData;
98
110
  });
99
111
  }
100
112
 
@@ -111,9 +123,11 @@ export const ensureInit = (inst: any) => { // HTMLElement
111
123
  }
112
124
  };
113
125
 
126
+
127
+ // 훔 이게맞나?? global로 관리하는게..훔... 왜이렇게 했을까..
114
128
  // --- Global Event Handling ---
115
129
  const globalDelegatedRoots = new WeakSet<Node>();
116
-
130
+ // 여기에서 중복 호출안되게 잘막아준다 ..
117
131
  const handleGlobalSwcEvent = async (event: Event) => {
118
132
  if ((event as any).__swc_handled) return;
119
133
  const path = event.composedPath();
@@ -155,6 +169,28 @@ const setupPrototype = (proto: any, win: Window) => {
155
169
  if (proto.__swc_proto_setup) return;
156
170
  proto.__swc_proto_setup = true;
157
171
 
172
+
173
+ proto.createSlotString = function (id: string) {
174
+ return NodeSlot.slot(`${this._swcId}-${id}`);
175
+ }
176
+ proto.createEaHtml = function (id: string, script: string) {
177
+ return ElementApply.html(id, script);
178
+ }
179
+ proto.createEaText = function (id: string, script: string) {
180
+ return ElementApply.text(id, script);
181
+ }
182
+ proto.createEaAttribute = function (id: string, name: string, script: string) {
183
+ return ElementApply.attribute(id, name, script);
184
+ }
185
+ proto.createEaEvent = function (id: string, name: string, script: string) {
186
+ return ElementApply.event(id, name, script);
187
+ }
188
+ proto.createEaProperty = function (id: string, name: string, script: string) {
189
+ return ElementApply.property(id, name, script);
190
+ }
191
+
192
+ // swc-id-asdasdasdasd-click=" :value="" {: value fsdfsdafsad :} {html: aaa :} {text: asdas :}
193
+
158
194
  proto._executeSwcScript = function (attrName: string, hostSet: HostSet, extraArgs: Record<string, any> = {}) {
159
195
  ensureInit(this);
160
196
  const script = this.getAttribute(attrName);
@@ -338,7 +374,7 @@ export const elementDefine =
338
374
  const conf = getElementConfig(this);
339
375
  const currentWin = (this as any)._resolveWindow(conf);
340
376
 
341
- const bMethods = getOnConnectedBeforeMetadata(this).filter(it => useSsr ? !it.options.ssrFirst : true);
377
+ const bMethods = findAllOnConnectedBeforeMetadata(this).filter(it => useSsr ? !it.options.ssrFirst : true);
342
378
  // console.log('beforeConnected', bMethods)
343
379
  if (bMethods) {
344
380
  for (const m of bMethods) await (this as any)._invokeLifecycleMethod(m.propertyKey, helperHostSet);
@@ -347,65 +383,68 @@ export const elementDefine =
347
383
 
348
384
  // console.log('vvvvvvvvvvvvvvvu-seSsr-vvvvvvvvvv>', useSsr, this.tagName, this.getAttribute('seq'))
349
385
  // // ssr 처리라서 이미 내려준거그대로 상요하면된다 따라서 호출안한다
350
- const targetConnectedInnerHtmlList = getOnConnectedInnerHtmlMetadata(constructor).filter(it => useSsr ? !it.options.ssrFirst : true);
351
- const shadowMode = conf?.useShadow || targetConnectedInnerHtmlList.find(it => it.options.useShadow)?.options.useShadow;
386
+ const targetConnectedList = findAllOnConnectedMetadata(constructor).filter(it => useSsr ? !it.options.ssrFirst : true);
387
+ const shadowMode = conf?.useShadow || targetConnectedList.find(it => it.options.useShadow)?.options.useShadow;
388
+ // console.log('--------->', this.tagName, shadowMode && !this.shadowRoot)
352
389
  if (shadowMode && !this.shadowRoot) {
353
390
  const mode = shadowMode === true ? 'open' : shadowMode;
354
- this.attachShadow({mode: mode as ShadowRootMode});
391
+ console.log('tagName=', this.tagName, 'mode', mode, this.shadowRoot);
392
+ // if (this.tagName!=='INDEX-ROUTER') {
393
+ this.attachShadow({mode: mode as ShadowRootMode});
394
+ // }
355
395
  }
356
396
 
357
- if (targetConnectedInnerHtmlList.length > 0) {
358
- let sContent = '',
359
- lContent = '';
360
- for (const meta of targetConnectedInnerHtmlList) {
397
+ const stateContext: any = {...helperHostSet};
398
+ findAllStateMetadata(this).forEach(it => {
399
+ stateContext[it.name] = this[it.propertyKey]
400
+ })
401
+
402
+ const shadowChildren: Node[] = [];
403
+ const lightChildren: Node[] = [];
404
+
405
+ console.log('targetConnectList', this.tagName, targetConnectedList.length)
406
+ if (targetConnectedList.length > 0) {
407
+ // let sContent = '',
408
+ // lContent = '';
409
+ for (const meta of targetConnectedList) {
361
410
  // const res = (this as any)[meta.propertyKey]();
362
411
  let res = await (this as any)._invokeLifecycleMethod(meta.propertyKey, helperHostSet);
363
- const actionExpression = new ActionExpression(res, {
364
- expression: {
365
- replace: {
366
- start: meta.options.replaceWrap?.start || '[[',
367
- end: meta.options.replaceWrap?.end || ']]'
368
- },
369
- callReturn: {
370
- start: meta.options.replaceWrap?.start || '[[=',
371
- end: meta.options.replaceWrap?.end || ']]'
372
- },
373
- call: {
374
- start: meta.options.replaceWrap?.start || '[[@',
375
- end: meta.options.replaceWrap?.end || ']]'
376
- }
377
- }
378
- });
379
-
380
- actionExpression.getExpressions().filter(it => it.type === 'replace').forEach(it => {
381
- actionExpression.replace(it, NodeSlot.slot(`${this._swcId}-${it.script}`));
382
- // try {
383
- // const sr = FunctionUtils.executeReturn({script: it.script, context: this, args: helperHostSet});
384
- // actionExpression.replace(it, sr);
385
- // } catch (e) {
386
- // console.error(`[SWC] Failed to execute connectedInnerHTML:`, e);
387
- // }
388
- });
389
- res = actionExpression.getUnprocessedTemplate();
412
+ // res = SwcUtils.projectProcessHtml(this, res);
413
+ if (typeof res === 'string') {
414
+ const htmlTemplateElement = doc.createElement('template');
415
+ htmlTemplateElement.innerHTML = res;//SwcUtils.projectProcessHtml(this._swcId, res, doc);
416
+ res = htmlTemplateElement.content;
417
+ }
390
418
 
391
- if (res !== undefined) {
392
- if (meta.options.useShadow || conf?.useShadow) sContent += res;
393
- else lContent += res;
419
+ if (res) {
420
+ const nodes = Array.isArray(res) ? res : [res];
421
+ if (meta.options.useShadow || conf?.useShadow) {
422
+ shadowChildren.push(...nodes);
423
+ }else {
424
+ lightChildren.push(...nodes);
425
+ }
394
426
  }
395
427
  }
396
428
  try {
397
429
  if (this.shadowRoot) {
398
- this.shadowRoot.innerHTML = sContent;
430
+ const applyShadowChildren = SwcUtils.projectProcessHtml(this._swcId, shadowChildren, doc);
431
+ this.shadowRoot.replaceChildren(...applyShadowChildren)
399
432
  }
400
- if (lContent) {
401
- this.innerHTML = lContent;
433
+ if (lightChildren.length) {
434
+ const applyLightChildren = SwcUtils.projectProcessHtml(this._swcId, lightChildren, doc);
435
+ this.replaceChildren(...applyLightChildren)
402
436
  }
437
+
403
438
  } catch (e) {
404
439
  console.error('[ElementDefine] innerHTML setting error:', e);
405
440
  }
441
+ new ElementApply(this, {id: this._swcId}).apply({context: stateContext, bind: this});
442
+ } else {
443
+ new ElementApply(this, {id: this._swcId}).apply({exclude: {html: true, text: true, attribute: true}, context: stateContext, bind: this});
406
444
  }
407
445
 
408
- const root = this.getRootNode();
446
+ // global delegate event
447
+ const root = this.getRootNode()
409
448
  if (!globalDelegatedRoots.has(root)) {
410
449
  DOM_EVENT_NAMES.forEach(type => {
411
450
  root.addEventListener(type, handleGlobalSwcEvent);
@@ -413,6 +452,7 @@ export const elementDefine =
413
452
  globalDelegatedRoots.add(root);
414
453
  }
415
454
 
455
+
416
456
  // Separate delegate and non-delegate listeners
417
457
  const delegateListeners: typeof addEventListenerList = [];
418
458
  const nonDelegateListeners: typeof addEventListenerList = [];
@@ -542,15 +582,13 @@ export const elementDefine =
542
582
  await (this as any)[meta.propertyKey](event, {currentHostSet, $$matchedElement: event.currentTarget}, args);
543
583
  };
544
584
  t.addEventListener(type, handler, opts);
545
- if (options.removeOnDisconnected === true || t === currentWin || t === currentWin.document) {
546
- (this as any)._boundListeners.push({target: t, type, handler, options: opts});
547
- }
585
+ (this as any)._boundListeners.push({target: t, type, handler, options: opts});
548
586
  });
549
587
  });
550
588
 
551
589
  if (originalConnected) await (originalConnected.apply(this));
552
590
 
553
- const aMethods = getOnConnectedAfterMetadata(this).filter(it => {
591
+ const aMethods = findAllOnConnectedAfterMetadata(this).filter(it => {
554
592
  return useSsr ? !it.options.ssrFirst : true;
555
593
  });
556
594
  // console.log('afterConnected', this.tagName, aMethods, getOnConnectedAfterMetadata(this))
@@ -603,6 +641,20 @@ export const elementDefine =
603
641
  (this as any)._boundListeners = [];
604
642
  }
605
643
 
644
+ new ElementApply(this, {id: this._swcId}).removeAllEventListener();
645
+
646
+ // globalDelegatedRoots remove
647
+ // const roots = [this, this.getRootNode()];
648
+ // if (this.shadowRoot) {
649
+ // roots.push(this.shadowRoot);
650
+ // }
651
+ // roots.forEach(root => {
652
+ // DOM_EVENT_NAMES.forEach(type => {
653
+ // root.removeEventListener(type, handleGlobalSwcEvent);
654
+ // });
655
+ // }
656
+ // )
657
+
606
658
  if (originalDisconnected) originalDisconnected.apply(this);
607
659
 
608
660
  const aMethods = findAllLifecycleMetadata(this, ON_AFTER_DISCONNECTED_METADATA_KEY);
@@ -1,5 +1,5 @@
1
1
  import {ReflectUtils} from '@dooboostore/core';
2
- import {SpecialSelector, SwcQueryOptions, HelperHostSet} from '../types';
2
+ import { SpecialSelector, SwcQueryOptions, HelperHostSet } from '../types';
3
3
  import {ensureInit, getElementConfig} from './elementDefine';
4
4
  import {SwcUtils} from '../utils/Utils';
5
5
 
@@ -15,3 +15,5 @@ export * from './subscribeSwcAppRouteChangeWhileConnected';
15
15
  export * from './subscribeSwcAppMessageWhileConnected';
16
16
  export * from './publishSwcAppMessage';
17
17
  export * from './applySlot';
18
+ export * from './state';
19
+
@@ -8,7 +8,7 @@ export const ON_AFTER_DISCONNECTED_METADATA_KEY = Symbol.for('simple-web-compone
8
8
  export const ON_BEFORE_ADOPTED_METADATA_KEY = Symbol.for('simple-web-component:on-before-adopted');
9
9
  export const ON_AFTER_ADOPTED_METADATA_KEY = Symbol.for('simple-web-component:on-after-adopted');
10
10
  export const ON_ADD_EVENT_LISTENER_METADATA_KEY = Symbol.for('simple-web-component:on-add-event-listener');
11
- export const ON_CONNECTED_INNER_HTML_METADATA_KEY = Symbol.for('simple-web-component:inner-html');
11
+ export const ON_CONNECTED_METADATA_KEY = Symbol.for('simple-web-component');
12
12
  export const ON_CONNECTED_SWC_APP_METADATA_KEY = Symbol.for('simple-web-component:on-connected-swc-app');
13
13
  export const ON_CONNECTED_COMPLETED_METADATA_KEY = Symbol.for('simple-web-component:on-completed');
14
14
 
@@ -16,7 +16,7 @@ export const ATTRIBUTE_CHANGED_WILDCARD = '*';
16
16
 
17
17
  export interface InnerHtmlOptions {
18
18
  ssrFirst?: boolean;
19
- replaceWrap?:{ start: string, end:string},
19
+ // replaceWrap?:{ start: string, end:string},
20
20
  useShadow?: boolean;
21
21
  }
22
22
  export interface InnerHtmlMetadata {
@@ -93,7 +93,7 @@ function createLifecycleDecorator(metadataKey: symbol): MethodDecorator {
93
93
  export const onInitialize = createLifecycleDecorator(ON_INITIALIZE_METADATA_KEY);
94
94
  // export const onConnectedBefore = createLifecycleDecorator(ON_BEFORE_CONNECTED_METADATA_KEY);
95
95
  // export const onConnectedAfter = createLifecycleDecorator(ON_AFTER_CONNECTED_METADATA_KEY);
96
- export const onConnected = onConnectedAfter;
96
+ // export const onConnected = onConnectedAfter;
97
97
 
98
98
  export const onDisconnectedBefore = createLifecycleDecorator(ON_BEFORE_DISCONNECTED_METADATA_KEY);
99
99
  export const onDisconnectedAfter = createLifecycleDecorator(ON_AFTER_DISCONNECTED_METADATA_KEY);
@@ -108,28 +108,52 @@ export const onAddEventListener = createLifecycleDecorator(ON_ADD_EVENT_LISTENER
108
108
  export const onConnectedSwcApp = createLifecycleDecorator(ON_CONNECTED_SWC_APP_METADATA_KEY);
109
109
  export const onConnectedCompleted = createLifecycleDecorator(ON_CONNECTED_COMPLETED_METADATA_KEY);
110
110
 
111
- /**
112
- * @onConnectedInnerHtml decorator to define the initial HTML content when connected.
113
- */
114
- export function onConnectedInnerHtml(options: InnerHtmlOptions): MethodDecorator;
115
- export function onConnectedInnerHtml(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
116
- export function onConnectedInnerHtml(arg1?: InnerHtmlOptions | Object, arg2?: string | symbol, arg3?: PropertyDescriptor): MethodDecorator | void {
117
- const decorator = (options: InnerHtmlOptions, target: Object, propertyKey: string | symbol) => {
118
- const constructor = target.constructor;
119
- let list = ReflectUtils.getMetadata<InnerHtmlMetadata[]>(ON_CONNECTED_INNER_HTML_METADATA_KEY, constructor);
120
- if (!list) {
121
- list = [];
122
- ReflectUtils.defineMetadata(ON_CONNECTED_INNER_HTML_METADATA_KEY, list, constructor);
123
- }
124
- list.push({ propertyKey, options });
125
- };
126
111
 
127
- if (arg2) {
128
- return decorator({}, arg1!, arg2);
112
+
113
+
114
+
115
+ const decorator = (options: InnerHtmlOptions, target: Object, propertyKey: string | symbol) => {
116
+ const constructor = target.constructor;
117
+ let list = ReflectUtils.getMetadata<InnerHtmlMetadata[]>(ON_CONNECTED_METADATA_KEY, constructor);
118
+ if (!list) {
119
+ list = [];
120
+ ReflectUtils.defineMetadata(ON_CONNECTED_METADATA_KEY, list, constructor);
121
+ }
122
+ list.push({ propertyKey, options });
123
+ };
124
+
125
+ export function onConnectedShadowDom(options: Omit<InnerHtmlOptions, 'useShadow'>): MethodDecorator; // 파라미터있음
126
+ export function onConnectedShadowDom(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void; // 파라미터없음
127
+ export function onConnectedShadowDom(optionOrTarget: Omit<InnerHtmlOptions, 'useShadow'> | Object, propertyKey?: string | symbol, arg3?: PropertyDescriptor): MethodDecorator | void {
128
+ if (propertyKey) { // no parameter option @decorator
129
+ return decorator({useShadow: true}, optionOrTarget!, propertyKey);
129
130
  }
131
+ // parameter option @decorator()
132
+ return (target: Object, propertyKey: string | symbol) => {
133
+ decorator({...optionOrTarget??{}, useShadow: true}, target, propertyKey);
134
+ };
135
+ }
130
136
 
137
+ export function onConnectedLightDom(options: Omit<InnerHtmlOptions, 'useShadow'>): MethodDecorator; // 파라미터있음
138
+ export function onConnectedLightDom(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void; // 파라미터없음
139
+ export function onConnectedLightDom(optionOrTarget: Omit<InnerHtmlOptions, 'useShadow'> | Object, propertyKey?: string | symbol, arg3?: PropertyDescriptor): MethodDecorator | void {
140
+ if (propertyKey) { // no parameter option @decorator
141
+ return decorator({useShadow: false}, optionOrTarget!, propertyKey);
142
+ }
143
+ // parameter option @decorator()
144
+ return (target: Object, propertyKey: string | symbol) => {
145
+ decorator({...optionOrTarget??{}, useShadow: false}, target, propertyKey);
146
+ };
147
+ }
148
+ export function onConnected(options: InnerHtmlOptions): MethodDecorator;
149
+ export function onConnected(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
150
+ export function onConnected(optionOrTarget: InnerHtmlOptions | Object, propertyKey?: string | symbol, arg3?: PropertyDescriptor): MethodDecorator | void {
151
+ if (propertyKey) { // no parameter option @decorator
152
+ return decorator({}, optionOrTarget!, propertyKey);
153
+ }
154
+ // parameter option @decorator()
131
155
  return (target: Object, propertyKey: string | symbol) => {
132
- decorator((arg1 as InnerHtmlOptions) || {}, target, propertyKey);
156
+ decorator((optionOrTarget as InnerHtmlOptions) || {}, target, propertyKey);
133
157
  };
134
158
  }
135
159
 
@@ -138,19 +162,19 @@ export function onConnectedInnerHtml(arg1?: InnerHtmlOptions | Object, arg2?: st
138
162
  */
139
163
  // export const findAllLifecycleMetadata = <T = (string | symbol)[]>(target: any, metadataKey: symbol): T | undefined => {
140
164
  export const findAllLifecycleMetadata = (target: any, metadataKey: symbol): (string | symbol)[] => {
141
- const results = ReflectUtils.findAllMetadataFlatten(metadataKey, target);
165
+ const results = ReflectUtils.findAllMetadataFlatten(metadataKey, target)??[];
142
166
  return results;
143
167
  };
144
168
 
145
- export const getOnConnectedInnerHtmlMetadata = (target: any): InnerHtmlMetadata[] => {
169
+ export const findAllOnConnectedMetadata = (target: any): InnerHtmlMetadata[] => {
146
170
  const constructor = target instanceof Function ? target : target.constructor;
147
- return ReflectUtils.getMetadata(ON_CONNECTED_INNER_HTML_METADATA_KEY, constructor) ?? [];
171
+ return ReflectUtils.getMetadata(ON_CONNECTED_METADATA_KEY, constructor) ?? [];
148
172
  };
149
- export const getOnConnectedBeforeMetadata = (target: any): OnConnectedMetadata[] => {
173
+ export const findAllOnConnectedBeforeMetadata = (target: any): OnConnectedMetadata[] => {
150
174
  const constructor = target instanceof Function ? target : target.constructor;
151
175
  return ReflectUtils.getMetadata(ON_BEFORE_CONNECTED_METADATA_KEY, constructor) ?? [];
152
176
  };
153
- export const getOnConnectedAfterMetadata = (target: any): OnConnectedMetadata[] => {
177
+ export const findAllOnConnectedAfterMetadata = (target: any): OnConnectedMetadata[] => {
154
178
  const constructor = target instanceof Function ? target : target.constructor;
155
179
  return ReflectUtils.getMetadata(ON_AFTER_CONNECTED_METADATA_KEY, constructor) ?? [];
156
180
  };
@@ -1,6 +1,5 @@
1
- import { ReflectUtils } from '@dooboostore/core';
2
- import { SwcAppMessage } from '../types';
3
- import { SwcUtils } from '../utils/Utils';
1
+ import {ReflectUtils} from '@dooboostore/core';
2
+ import {SwcUtils} from '../utils/Utils';
4
3
 
5
4
  export const PUBLISH_SWC_APP_MESSAGE_METADATA_KEY = Symbol.for('simple-web-component:publish-swc-app-message');
6
5
 
@@ -1,12 +1,12 @@
1
1
  import { ReflectUtils } from '@dooboostore/core';
2
2
  import { getElementConfig, ensureInit } from './elementDefine';
3
3
  import { SwcUtils } from '../utils/Utils';
4
- import { SpecialSelector, SwcQueryOptions } from '../types';
4
+ import { SpecialSelector, SwcQueryOptions, HelperHostSet } from '../types';
5
5
 
6
6
  export interface QueryMetadata {
7
7
  propertyKey: string | symbol;
8
8
  selector: string;
9
- options: SwcQueryOptions;
9
+ options: SwcQueryOptions ;
10
10
  }
11
11
 
12
12
  export const QUERY_METADATA_KEY = Symbol.for('simple-web-component:query');
@@ -180,7 +180,7 @@ export function queryAppHost(targetOrOptions?: any, propertyKey?: string | symbo
180
180
  }
181
181
  }
182
182
 
183
- export const getQueryMetadata = (target: any): QueryMetadata[] | undefined => {
183
+ export const getQueryMetadata = (target: any): QueryMetadata[] => {
184
184
  const constructor = target instanceof Function ? target : target.constructor;
185
- return ReflectUtils.getMetadata(QUERY_METADATA_KEY, constructor);
185
+ return ReflectUtils.getMetadata(QUERY_METADATA_KEY, constructor) ?? [];
186
186
  };
@@ -1,7 +1,7 @@
1
1
  import { ReflectUtils } from '@dooboostore/core';
2
2
  import { getElementConfig, ensureInit } from './elementDefine';
3
3
  import { SwcUtils } from '../utils/Utils';
4
- import { SpecialSelector, SwcQueryOptions } from '../types';
4
+ import { SpecialSelector, SwcQueryOptions, HelperHostSet } from '../types';
5
5
 
6
6
  export interface QueryAllMetadata {
7
7
  propertyKey: string | symbol;
@@ -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 { HelperHostSet, SwcQueryOptions } from '../types';
4
+ import { SpecialSelector, SwcQueryOptions, HelperHostSet } from '../types';
5
5
 
6
6
  export interface PropertySetOptions extends SwcQueryOptions {
7
7
  name?: string;
@@ -0,0 +1,84 @@
1
+ import {ReflectUtils} from '@dooboostore/core';
2
+ import {ElementApply} from "@dooboostore/core-web";
3
+ import {SwcUtils} from "../utils/Utils";
4
+ import {getElementConfig} from "./elementDefine";
5
+
6
+ export interface StateMetadata {
7
+ propertyKey: string | symbol;
8
+ name: string;
9
+ }
10
+
11
+ export const STATE_METADATA_KEY = Symbol.for('simple-web-component:state');
12
+
13
+ // export function state(target: SpecialSelector): PropertyDecorator;
14
+ // export function state(): PropertyDecorator;
15
+ export function state(target: Object, propertyKey: string | symbol): void;
16
+ export function state(name: string): PropertyDecorator;
17
+ /**
18
+ * Supports both forms:
19
+ * - @state
20
+ * - @state()
21
+ * - @state('selector')
22
+ */
23
+ export function state(nameOrTarget?: string | Object, propertyKey?: string | symbol): any {
24
+
25
+ const stateDefine = (targetObj: any, stateMetadata: StateMetadata) => {
26
+
27
+ let storage = targetObj[stateMetadata.propertyKey];
28
+ // console.log('ssssssssssssssss', storage, stateMetadata.propertyKey)
29
+ Object.defineProperty(targetObj, stateMetadata.propertyKey, {
30
+ set(this: any, nv: string) {
31
+ console.log('setState!!', nv)
32
+ storage = nv;
33
+ const config = getElementConfig(this)
34
+ const ea = new ElementApply(this, {id: this._swcId});
35
+ const helperHostSet = SwcUtils.getHelperAndHostSet(config.window, this);
36
+ const stateContext: any = {...helperHostSet};
37
+ findAllStateMetadata(this).forEach(it => {
38
+ stateContext[it.name] = this[it.propertyKey]
39
+ })
40
+ ea.apply({context:stateContext, targetVariableName: stateMetadata.name, bind: this});
41
+ },
42
+ get(this: any) {
43
+ return storage;
44
+ },
45
+ enumerable: true,
46
+ configurable: true
47
+ });
48
+ }
49
+
50
+ // If used as @state (no parentheses), TypeScript will call this function with (target, propertyKey)
51
+ if (typeof nameOrTarget === 'object' && propertyKey) {
52
+ const targetObj = nameOrTarget as Object;
53
+ const name = String(propertyKey);
54
+ const constructor = (targetObj as any).constructor;
55
+ let states = ReflectUtils.getMetadata<StateMetadata[]>(STATE_METADATA_KEY, constructor);
56
+ if (!states) {
57
+ states = [];
58
+ ReflectUtils.defineMetadata(STATE_METADATA_KEY, states, constructor);
59
+ }
60
+ const stateMetadata = {propertyKey, name};
61
+ states.push(stateMetadata);
62
+ stateDefine(targetObj, stateMetadata);
63
+ return;
64
+ }
65
+
66
+ // Otherwise return a decorator factory
67
+ return (targetObj: Object, propertyKey: string | symbol): void => {
68
+ const name = String(nameOrTarget);
69
+ const constructor = targetObj.constructor;
70
+ let states = ReflectUtils.getMetadata<StateMetadata[]>(STATE_METADATA_KEY, constructor);
71
+ if (!states) {
72
+ states = [];
73
+ ReflectUtils.defineMetadata(STATE_METADATA_KEY, states, constructor);
74
+ }
75
+ const stateMetadata = {propertyKey, name};
76
+ states.push(stateMetadata);
77
+ stateDefine(targetObj, stateMetadata);
78
+ };
79
+ }
80
+
81
+ export const findAllStateMetadata = (target: any): StateMetadata[] => {
82
+ const constructor = target instanceof Function ? target : target.constructor;
83
+ return ReflectUtils.getMetadata(STATE_METADATA_KEY, constructor) ?? [];
84
+ };
@@ -1,5 +1,5 @@
1
1
  import { ReflectUtils } from '@dooboostore/core';
2
- import { SwcAppMessage } from '../types';
2
+ import { SwcAppMessage, SpecialSelector, SwcQueryOptions, HelperHostSet } from '../types';
3
3
 
4
4
  export const SUBSCRIBE_SWC_APP_MESSAGE_WHILE_CONNECTED_METADATA_KEY = Symbol.for('simple-web-component:subscribe-swc-app-message-while-connected');
5
5
 
@@ -1,5 +1,6 @@
1
- import { ReflectUtils } from '@dooboostore/core';
2
- import { Router } from '@dooboostore/core-web';
1
+ import {ReflectUtils} from '@dooboostore/core';
2
+ import {Router} from '@dooboostore/core-web';
3
+ import {HelperHostSet} from '../types';
3
4
 
4
5
  export const SUBSCRIBE_SWC_APP_ROUTE_CHANGE_WHILE_CONNECTED_METADATA_KEY = Symbol.for('simple-web-component:subscribe-swc-app-route-change-while-connected');
5
6
 
@@ -12,7 +13,7 @@ export interface SwcAppRouteChangeSubscriberMetadata {
12
13
 
13
14
  export interface SwcAppRouteChangeOptions {
14
15
  path?: RoutePathType;
15
- filter?: (router: Router, currentThis: any) => boolean;
16
+ filter?: (router: Router, meta: {currentThis: any, helper: HelperHostSet}) => boolean;
16
17
  }
17
18
 
18
19
  function createSubscribeSwcAppRouteChangeWhileConnected(options?: SwcAppRouteChangeOptions): MethodDecorator {