@dooboostore/simple-web-component 1.0.53 → 1.0.54

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dooboostore/simple-web-component",
3
- "version": "1.0.53",
3
+ "version": "1.0.54",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.js",
@@ -95,9 +95,9 @@
95
95
  "webpack-dev-server": "^5.2.0"
96
96
  },
97
97
  "dependencies": {
98
- "@dooboostore/core": "1.0.33",
99
98
  "@dooboostore/core-web": "1.0.14",
100
- "@dooboostore/simple-boot": "1.0.59"
99
+ "@dooboostore/simple-boot": "1.0.59",
100
+ "@dooboostore/core": "1.0.33"
101
101
  },
102
102
  "scripts": {
103
103
  "clean": "rm -rf dist",
@@ -86,6 +86,12 @@ const applyToDom = (currentThis: any, targetEl: HTMLElement, res: Node | string
86
86
  targetEl.replaceChildren();
87
87
  return [];
88
88
  }
89
+
90
+ // remove: 대상 자체를 DOM에서 뗀다. $this 처럼 shadow root 로 잡혔으면 그 주인 엘리먼트를 뗀다.
91
+ if (pos === 'remove') {
92
+ (targetEl instanceof win.ShadowRoot ? (targetEl as any).host : targetEl).remove();
93
+ return [];
94
+ }
89
95
 
90
96
  const doc = win.document;
91
97
  const hostSet = SwcUtils.getHelperAndHostSet(currentThis);
@@ -232,6 +238,8 @@ export function applyNode(selectorOrOptions: ApplyNodeSelector | ApplyNodeOption
232
238
 
233
239
  const runApply = (target: any, val: any) => {
234
240
  const pos = options.position || 'beforeEnd';
241
+ // remove 는 값이 '지울지 말지' 다: truthy 일 때만 지운다 (undefined 는 위에서 이미 걸러짐)
242
+ if (pos === 'remove' && !val) return;
235
243
  // Delegate HTML/node processing to applyToDom which centralizes
236
244
  // processing. runApply should not call processHtml itself to avoid
237
245
  // duplicate processing.
@@ -323,6 +331,28 @@ export function clearChildrenNode(selectorOrOptions?: ApplyNodeSelector | Omit<A
323
331
  // Alias for clearChildrenNode
324
332
  export const clearNode = clearChildrenNode;
325
333
 
334
+ /**
335
+ * @removeNode - 메서드 반환값이 truthy 면 대상 엘리먼트를 DOM에서 제거한다.
336
+ * 반환값(valueKey 가 있으면 그 값)이 falsy(undefined / null / false / 0 / '')면 제거하지 않는다. 반환값은 그대로 통과.
337
+ * 선택자에 맞는 첫 번째 엘리먼트를 지운다. 선택자가 없거나 '$this' 면 자기 자신을 지운다.
338
+ *
339
+ * - @removeNode('.toast') / @removeNode('.toast', { valueKey: 'close' })
340
+ * - @removeNode({ valueKey: 'done' }) ($this)
341
+ * - @removeNode ($this, bare)
342
+ */
343
+ export function removeNode(selector: ApplyNodeSelector, options?: Omit<ApplyNodeOptions, 'position'>): MethodDecorator;
344
+ export function removeNode(options: Omit<ApplyNodeOptions, 'position'>): MethodDecorator;
345
+ export function removeNode(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;
346
+ export function removeNode(selectorOrOptions?: ApplyNodeSelector | Omit<ApplyNodeOptions, 'position'> | Object, maybeOptions?: Omit<ApplyNodeOptions, 'position'> | string | symbol, descriptor?: PropertyDescriptor): MethodDecorator | PropertyDescriptor | void {
347
+ if (descriptor !== undefined && (typeof maybeOptions === 'symbol' || typeof maybeOptions === 'string')) {
348
+ return applyNode({position: 'remove'})(selectorOrOptions as Object, maybeOptions, descriptor);
349
+ }
350
+ if (typeof selectorOrOptions === 'string' || typeof selectorOrOptions === 'function') {
351
+ return applyNode(selectorOrOptions as any, {...maybeOptions as Omit<ApplyNodeOptions, 'position'>, position: 'remove'});
352
+ }
353
+ return applyNode({...selectorOrOptions as Omit<ApplyNodeOptions, 'position'>, position: 'remove'});
354
+ }
355
+
326
356
  /**
327
357
  * @innerHtmlNode decorator - sets innerHTML of target element
328
358
  *