@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.
- package/README.md +280 -791
- package/dist/cjs/SwcAppEngine.js +3 -0
- package/dist/cjs/SwcAppEngine.js.map +2 -2
- package/dist/cjs/decorators/addEventListener.js +20 -4
- package/dist/cjs/decorators/addEventListener.js.map +2 -2
- package/dist/cjs/decorators/applyAttribute.js.map +1 -1
- package/dist/cjs/decorators/applyClass.js.map +1 -1
- package/dist/cjs/decorators/applyNode.js +104 -35
- package/dist/cjs/decorators/applyNode.js.map +2 -2
- package/dist/cjs/decorators/applySlot.js +69 -57
- package/dist/cjs/decorators/applySlot.js.map +3 -3
- package/dist/cjs/decorators/applyStyle.js.map +2 -2
- package/dist/cjs/decorators/attribute.js.map +1 -1
- package/dist/cjs/decorators/elementDefine.js +65 -42
- package/dist/cjs/decorators/elementDefine.js.map +2 -2
- package/dist/cjs/decorators/emitCustomEvent.js.map +1 -1
- package/dist/cjs/decorators/index.js +1 -0
- package/dist/cjs/decorators/index.js.map +2 -2
- package/dist/cjs/decorators/lifecycles.js +47 -31
- package/dist/cjs/decorators/lifecycles.js.map +3 -3
- package/dist/cjs/decorators/publishSwcAppMessage.js.map +2 -2
- package/dist/cjs/decorators/query.js +1 -1
- package/dist/cjs/decorators/query.js.map +2 -2
- package/dist/cjs/decorators/queryAll.js.map +1 -1
- package/dist/cjs/decorators/setProperty.js.map +1 -1
- package/dist/cjs/decorators/state.js +83 -0
- package/dist/cjs/decorators/state.js.map +7 -0
- package/dist/cjs/decorators/subscribeSwcAppMessageWhileConnected.js.map +1 -1
- package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
- package/dist/cjs/elements/SwcApp.js +193 -305
- package/dist/cjs/elements/SwcApp.js.map +3 -3
- package/dist/cjs/elements/SwcAppMixin.js +291 -0
- package/dist/cjs/elements/SwcAppMixin.js.map +7 -0
- package/dist/cjs/elements/index.js +3 -21
- package/dist/cjs/elements/index.js.map +3 -3
- package/dist/cjs/index.js +1 -3
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/{types.js → types/index.js} +1 -1
- package/dist/cjs/types/index.js.map +7 -0
- package/dist/cjs/types/window.d.js.map +1 -1
- package/dist/cjs/utils/Utils.js +159 -20
- package/dist/cjs/utils/Utils.js.map +3 -3
- package/dist/esm/SwcAppEngine.js +3 -0
- package/dist/esm/SwcAppEngine.js.map +2 -2
- package/dist/esm/decorators/addEventListener.js +20 -4
- package/dist/esm/decorators/addEventListener.js.map +2 -2
- package/dist/esm/decorators/applyAttribute.js.map +1 -1
- package/dist/esm/decorators/applyClass.js.map +1 -1
- package/dist/esm/decorators/applyNode.js +104 -35
- package/dist/esm/decorators/applyNode.js.map +2 -2
- package/dist/esm/decorators/applySlot.js +69 -57
- package/dist/esm/decorators/applySlot.js.map +3 -3
- package/dist/esm/decorators/applyStyle.js.map +2 -2
- package/dist/esm/decorators/attribute.js.map +1 -1
- package/dist/esm/decorators/elementDefine.js +69 -46
- package/dist/esm/decorators/elementDefine.js.map +2 -2
- package/dist/esm/decorators/emitCustomEvent.js.map +1 -1
- package/dist/esm/decorators/index.js +1 -0
- package/dist/esm/decorators/index.js.map +2 -2
- package/dist/esm/decorators/lifecycles.js +47 -31
- package/dist/esm/decorators/lifecycles.js.map +3 -3
- package/dist/esm/decorators/publishSwcAppMessage.js.map +2 -2
- package/dist/esm/decorators/query.js +1 -1
- package/dist/esm/decorators/query.js.map +2 -2
- package/dist/esm/decorators/queryAll.js.map +1 -1
- package/dist/esm/decorators/setProperty.js.map +1 -1
- package/dist/esm/decorators/state.js +64 -0
- package/dist/esm/decorators/state.js.map +7 -0
- package/dist/esm/decorators/subscribeSwcAppMessageWhileConnected.js.map +1 -1
- package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
- package/dist/esm/elements/SwcApp.js +195 -307
- package/dist/esm/elements/SwcApp.js.map +3 -3
- package/dist/esm/elements/SwcAppMixin.js +273 -0
- package/dist/esm/elements/SwcAppMixin.js.map +7 -0
- package/dist/esm/elements/index.js +2 -7
- package/dist/esm/elements/index.js.map +2 -2
- package/dist/esm/index.js +2 -4
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/{types.js → types/index.js} +1 -1
- package/dist/esm/types/index.js.map +7 -0
- package/dist/esm/utils/Utils.js +159 -20
- package/dist/esm/utils/Utils.js.map +3 -3
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +3448 -2584
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
- package/dist/types/SwcAppEngine.d.ts +1 -1
- package/dist/types/SwcAppEngine.d.ts.map +1 -1
- package/dist/types/decorators/addEventListener.d.ts +5 -2
- package/dist/types/decorators/addEventListener.d.ts.map +1 -1
- package/dist/types/decorators/applyAttribute.d.ts.map +1 -1
- package/dist/types/decorators/applyClass.d.ts.map +1 -1
- package/dist/types/decorators/applyNode.d.ts +23 -7
- package/dist/types/decorators/applyNode.d.ts.map +1 -1
- package/dist/types/decorators/applySlot.d.ts +14 -12
- package/dist/types/decorators/applySlot.d.ts.map +1 -1
- package/dist/types/decorators/applyStyle.d.ts.map +1 -1
- package/dist/types/decorators/attribute.d.ts.map +1 -1
- package/dist/types/decorators/elementDefine.d.ts.map +1 -1
- package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
- package/dist/types/decorators/index.d.ts +1 -0
- package/dist/types/decorators/index.d.ts.map +1 -1
- package/dist/types/decorators/lifecycles.d.ts +10 -14
- package/dist/types/decorators/lifecycles.d.ts.map +1 -1
- package/dist/types/decorators/publishSwcAppMessage.d.ts.map +1 -1
- package/dist/types/decorators/query.d.ts +1 -1
- package/dist/types/decorators/query.d.ts.map +1 -1
- package/dist/types/decorators/queryAll.d.ts.map +1 -1
- package/dist/types/decorators/setProperty.d.ts +1 -1
- package/dist/types/decorators/setProperty.d.ts.map +1 -1
- package/dist/types/decorators/state.d.ts +9 -0
- package/dist/types/decorators/state.d.ts.map +1 -0
- package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts.map +1 -1
- package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts +5 -1
- package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts.map +1 -1
- package/dist/types/elements/SwcApp.d.ts +35 -6
- package/dist/types/elements/SwcApp.d.ts.map +1 -1
- package/dist/types/elements/SwcAppMixin.d.ts +405 -0
- package/dist/types/elements/SwcAppMixin.d.ts.map +1 -0
- package/dist/types/elements/index.d.ts +2 -2
- package/dist/types/elements/index.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/{types.d.ts → types/index.d.ts} +11 -11
- package/dist/types/types/index.d.ts.map +1 -0
- package/dist/types/utils/Utils.d.ts +14 -2
- package/dist/types/utils/Utils.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +3431 -2567
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +4 -4
- package/src/SwcAppEngine.ts +6 -2
- package/src/decorators/addEventListener.ts +21 -5
- package/src/decorators/applyAttribute.ts +1 -1
- package/src/decorators/applyClass.ts +1 -1
- package/src/decorators/applyNode.ts +183 -73
- package/src/decorators/applySlot.ts +99 -128
- package/src/decorators/applyStyle.ts +4 -4
- package/src/decorators/attribute.ts +1 -1
- package/src/decorators/elementDefine.ts +112 -60
- package/src/decorators/emitCustomEvent.ts +1 -1
- package/src/decorators/index.ts +2 -0
- package/src/decorators/lifecycles.ts +50 -26
- package/src/decorators/publishSwcAppMessage.ts +2 -3
- package/src/decorators/query.ts +4 -4
- package/src/decorators/queryAll.ts +1 -1
- package/src/decorators/setProperty.ts +1 -1
- package/src/decorators/state.ts +83 -0
- package/src/decorators/subscribeSwcAppMessageWhileConnected.ts +1 -1
- package/src/decorators/subscribeSwcAppRouteChangeWhileConnected.ts +4 -3
- package/src/elements/SwcApp.ts +239 -441
- package/src/elements/SwcAppMixin.ts +328 -0
- package/src/elements/index.ts +2 -9
- package/src/index.ts +2 -4
- package/src/{types.ts → types/index.ts} +13 -10
- package/src/types/window.d.ts +3 -0
- package/src/utils/Utils.ts +205 -20
- package/dist/cjs/types.js.map +0 -7
- package/dist/esm/types.js.map +0 -7
- 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.
|
|
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.
|
|
98
|
-
"@dooboostore/simple-boot": "1.0.
|
|
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",
|
package/src/SwcAppEngine.ts
CHANGED
|
@@ -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'
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
return
|
|
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
|
|
4
|
-
import { SwcUtils
|
|
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
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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 = (
|
|
47
|
-
|
|
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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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 = {
|
|
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, {
|
|
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,
|
|
129
|
-
|
|
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
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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
|
-
|
|
146
|
-
|
|
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
|
-
|
|
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', {
|
|
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
|
-
|
|
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', {
|
|
215
|
+
return applyNode('$this', {...opt, ...options});
|
|
177
216
|
}
|
|
178
217
|
|
|
179
|
-
export function
|
|
180
|
-
export function
|
|
181
|
-
export function
|
|
182
|
-
|
|
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', {
|
|
224
|
+
return applyNode('$this', {...opt, ...options});
|
|
185
225
|
}
|
|
186
226
|
|
|
187
|
-
export function
|
|
188
|
-
|
|
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
|
|
192
|
-
|
|
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
|
|
196
|
-
|
|
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
|
+
// }
|