@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
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ReflectUtils
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { SwcUtils } from "../utils/Utils";
|
|
1
|
+
import {OptionalType, ReflectUtils} from '@dooboostore/core';
|
|
2
|
+
import {ensureInit, getElementConfig} from './elementDefine';
|
|
3
|
+
import {SwcUtils} from "../utils/Utils";
|
|
5
4
|
import {NodeSlot} from "@dooboostore/core-web";
|
|
5
|
+
import {HelperHostSet} from "../types";
|
|
6
6
|
/*
|
|
7
7
|
<!-- beforebegin -->
|
|
8
8
|
<p> <-- it's me
|
|
@@ -12,10 +12,11 @@ import {NodeSlot} from "@dooboostore/core-web";
|
|
|
12
12
|
</p>
|
|
13
13
|
<!-- afterend -->
|
|
14
14
|
*/
|
|
15
|
-
export type ApplySlotPosition = 'prependHtml' | 'prependText' | 'appendHtml' | 'appendText' | 'replaceChildrenHtml' | 'replaceChildrenText' | 'clear';
|
|
15
|
+
export type ApplySlotPosition = 'prepend' | 'prependHtml' | 'prependText' | 'append' | 'appendHtml' | 'appendText' | 'replaceChildren' | 'replaceChildrenHtml' | 'replaceChildrenText' | 'clear';
|
|
16
16
|
|
|
17
17
|
export interface ApplySlotOptions {
|
|
18
|
-
position
|
|
18
|
+
position: ApplySlotPosition;
|
|
19
|
+
fallback?: (helper: HelperHostSet) => string | Node;
|
|
19
20
|
// root?: SwcRootType;
|
|
20
21
|
/**
|
|
21
22
|
* Filter function to determine whether to perform DOM operation.
|
|
@@ -30,8 +31,8 @@ export interface ApplySlotOptions {
|
|
|
30
31
|
|
|
31
32
|
export interface ApplySlotMetadata {
|
|
32
33
|
propertyKey: string | symbol;
|
|
33
|
-
|
|
34
|
-
type: 'method' | 'property';
|
|
34
|
+
targetId: string;
|
|
35
|
+
// type: 'method' | 'property';
|
|
35
36
|
options: ApplySlotOptions;
|
|
36
37
|
}
|
|
37
38
|
|
|
@@ -76,25 +77,27 @@ export const APPLY_SLOT_METADATA_KEY = Symbol.for('simple-web-component:apply-sl
|
|
|
76
77
|
// }
|
|
77
78
|
// };
|
|
78
79
|
|
|
80
|
+
const applyToDom = (swcId: string, id: string, pos: ApplySlotPosition, nodes: Node[]) => {
|
|
81
|
+
const nodeSlot = new NodeSlot(this, swcId);
|
|
82
|
+
if (pos === 'replaceChildrenText' || pos === 'replaceChildren' || pos === 'replaceChildrenHtml') {
|
|
83
|
+
nodeSlot.replaceChildren(id, ...nodes);
|
|
84
|
+
} else if (pos === 'appendHtml' || pos === 'append' || pos === 'appendText') {
|
|
85
|
+
nodeSlot.append(id, ...nodes);
|
|
86
|
+
} else if (pos === 'prependHtml' || pos === 'prepend' || pos === 'prependText') {
|
|
87
|
+
nodeSlot.prepend(id, ...nodes);
|
|
88
|
+
} else if (pos === 'clear') {
|
|
89
|
+
nodeSlot.clear(id);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
79
92
|
/**
|
|
80
93
|
* @applyNode decorator to surgically add/replace nodes to a target element.
|
|
81
94
|
*/
|
|
82
|
-
export function applySlot(
|
|
83
|
-
return (targetObj: Object, propertyKey: string | symbol, descriptor
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
get(this: any) {
|
|
89
|
-
const nodeSlot = new NodeSlot(this, `${this._swcId}-${id}`);
|
|
90
|
-
return nodeSlot;
|
|
91
|
-
},
|
|
92
|
-
configurable: true,
|
|
93
|
-
enumerable: true,
|
|
94
|
-
})
|
|
95
|
-
// return nodeSlot;
|
|
96
|
-
// return;
|
|
97
|
-
}
|
|
95
|
+
export function applySlot(targetId: string, opt: OptionalType<ApplySlotOptions, 'position'>): MethodDecorator {
|
|
96
|
+
return (targetObj: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<any>) => {
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
const options: ApplySlotOptions = {position: 'replaceChildrenHtml', ...opt};
|
|
100
|
+
|
|
98
101
|
|
|
99
102
|
const constructor = targetObj.constructor;
|
|
100
103
|
let metaList = ReflectUtils.getOwnMetadata(APPLY_SLOT_METADATA_KEY, constructor) as ApplySlotMetadata[];
|
|
@@ -102,97 +105,56 @@ export function applySlot(id: string, options: ApplySlotOptions = { position: 'r
|
|
|
102
105
|
metaList = []
|
|
103
106
|
ReflectUtils.defineMetadata(APPLY_SLOT_METADATA_KEY, metaList, constructor);
|
|
104
107
|
}
|
|
105
|
-
metaList.push({
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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
|
-
// }
|
|
169
|
-
if (res) {
|
|
170
|
-
const nodeSlot = new NodeSlot(this, `${this._swcId}-${id}`);
|
|
171
|
-
const pos = options.position || 'replaceChildrenHtml';
|
|
172
|
-
const doc = currentWin.document;
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
// const isShadowRoot = targetEl instanceof win.ShadowRoot;
|
|
176
|
-
// const nodes = normalizeNodes(res, doc);
|
|
177
|
-
if (pos === 'replaceChildrenHtml') {
|
|
178
|
-
nodeSlot.replaceChildrenHtml(res);
|
|
179
|
-
} else if (pos === 'replaceChildrenText') {
|
|
180
|
-
nodeSlot.replaceChildrenText(res);
|
|
181
|
-
} else if (pos === 'appendHtml') {
|
|
182
|
-
nodeSlot.appendHtml(res);
|
|
183
|
-
} else if (pos === 'appendText') {
|
|
184
|
-
nodeSlot.appendText(res);
|
|
185
|
-
} else if (pos === 'prependHtml') {
|
|
186
|
-
nodeSlot.prependHtml(res);
|
|
187
|
-
} else if (pos === 'prependText') {
|
|
188
|
-
nodeSlot.prependText(res);
|
|
189
|
-
} else if (pos === 'clear') {
|
|
190
|
-
nodeSlot.clear();
|
|
191
|
-
}
|
|
108
|
+
metaList.push({propertyKey, targetId, options});
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
const original = descriptor.value;
|
|
112
|
+
descriptor.value = function (...args: any[]) {
|
|
113
|
+
ensureInit(this);
|
|
114
|
+
|
|
115
|
+
const conf = getElementConfig(this);
|
|
116
|
+
const currentWin = conf.window;
|
|
117
|
+
const swcId = this._swcId;
|
|
118
|
+
const currentDoc = currentWin.document;
|
|
119
|
+
const hostSet = SwcUtils.getHelperAndHostSet(currentWin, this);
|
|
120
|
+
const pos = options.position;
|
|
121
|
+
|
|
122
|
+
const resToNodes = (res: string | Node) => {
|
|
123
|
+
const nodes: Node[] = [];
|
|
124
|
+
|
|
125
|
+
if (typeof res === 'string' && (pos === 'replaceChildrenHtml' || pos === 'appendHtml' || pos === 'prependHtml')) {
|
|
126
|
+
const t = currentWin.document.createElement('template');
|
|
127
|
+
t.innerHTML = res;
|
|
128
|
+
nodes.push(...Array.from(t.content.childNodes));
|
|
129
|
+
} else if (typeof res === 'string' && (pos === 'replaceChildrenText' || pos === 'prependText' || pos === 'appendText')) {
|
|
130
|
+
nodes.push(currentWin.document.createTextNode(res));
|
|
131
|
+
} else if (typeof res === 'object') {
|
|
132
|
+
nodes.push(res);
|
|
192
133
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
134
|
+
SwcUtils.projectProcessHtml(swcId, nodes, currentDoc);
|
|
135
|
+
return nodes;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const fallbackNodes: Node[] = [];
|
|
139
|
+
if (options.fallback) {
|
|
140
|
+
const res: string | Node = options.fallback.call(this, hostSet);
|
|
141
|
+
const nodes: Node[] = resToNodes(res);
|
|
142
|
+
fallbackNodes.push(...nodes);
|
|
143
|
+
applyToDom(swcId, targetId, options.position, nodes);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
let res = original.apply(this, args);
|
|
147
|
+
if (res instanceof Promise) {
|
|
148
|
+
return res.then(asyncRes => {
|
|
149
|
+
const nodes = resToNodes(asyncRes)
|
|
150
|
+
fallbackNodes.forEach((it: any)=>it.remove());
|
|
151
|
+
applyToDom(swcId, targetId, options.position, nodes);
|
|
152
|
+
})
|
|
153
|
+
} else {
|
|
154
|
+
const nodes: Node[] = resToNodes(res);
|
|
155
|
+
applyToDom(swcId, targetId, options.position, nodes);
|
|
156
|
+
}
|
|
157
|
+
};
|
|
196
158
|
};
|
|
197
159
|
}
|
|
198
160
|
|
|
@@ -202,27 +164,36 @@ export const findAllApplySlotMetadata = (target: any): ApplySlotMetadata[] => {
|
|
|
202
164
|
return ReflectUtils.getMetadata(APPLY_SLOT_METADATA_KEY, constructor);
|
|
203
165
|
};
|
|
204
166
|
|
|
205
|
-
export function applySlotClear(
|
|
206
|
-
return applySlot(
|
|
167
|
+
export function applySlotClear(targetId: string): MethodDecorator {
|
|
168
|
+
return applySlot(targetId, {position: 'clear'});
|
|
207
169
|
}
|
|
208
|
-
|
|
209
|
-
|
|
170
|
+
|
|
171
|
+
export function applySlotPrependHtml(targetId: string): MethodDecorator {
|
|
172
|
+
return applySlot(targetId, {position: 'prependHtml'});
|
|
210
173
|
}
|
|
174
|
+
|
|
211
175
|
export const applySlotPrepend = applySlotPrependHtml;
|
|
212
|
-
|
|
213
|
-
|
|
176
|
+
|
|
177
|
+
export function applySlotPrependText(targetId: string): MethodDecorator {
|
|
178
|
+
return applySlot(targetId, {position: 'prependText'});
|
|
214
179
|
}
|
|
215
|
-
|
|
216
|
-
|
|
180
|
+
|
|
181
|
+
export function applySlotAppendHtml(targetId: string): MethodDecorator {
|
|
182
|
+
return applySlot(targetId, {position: 'appendHtml'});
|
|
217
183
|
}
|
|
218
|
-
|
|
219
|
-
|
|
184
|
+
|
|
185
|
+
export function applySlotAppendText(targetId: string): MethodDecorator {
|
|
186
|
+
return applySlot(targetId, {position: 'appendText'});
|
|
220
187
|
}
|
|
188
|
+
|
|
221
189
|
export const applySlotAppend = applySlotAppendHtml;
|
|
222
|
-
|
|
223
|
-
|
|
190
|
+
|
|
191
|
+
export function applySlotReplaceChildrenHtml(targetId: string): MethodDecorator {
|
|
192
|
+
return applySlot(targetId, {position: 'replaceChildrenHtml'});
|
|
224
193
|
}
|
|
194
|
+
|
|
225
195
|
export const applySlotReplaceChildren = applySlotReplaceChildrenHtml;
|
|
226
|
-
|
|
227
|
-
|
|
196
|
+
|
|
197
|
+
export function applySlotReplaceChildrenText(targetId: string): MethodDecorator {
|
|
198
|
+
return applySlot(targetId, {position: 'replaceChildrenText'});
|
|
228
199
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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;
|
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {ActionExpression, FunctionUtils, ReflectUtils} from '@dooboostore/core';
|
|
2
2
|
import {getAddEventListenerMetadata} from './addEventListener';
|
|
3
|
-
import {
|
|
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 {
|
|
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 {
|
|
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 {
|
|
14
|
-
import {ConvertUtils, NodeSlot} from '@dooboostore/core-web';
|
|
15
|
-
import {isSSR} from "../elements/
|
|
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 작동
|
|
@@ -91,10 +95,18 @@ export const ensureInit = (inst: any) => { // HTMLElement
|
|
|
91
95
|
delete (inst as any)[meta.propertyKey];
|
|
92
96
|
});
|
|
93
97
|
}
|
|
94
|
-
const slotAllList = findAllApplySlotMetadata(target);
|
|
95
|
-
if (slotAllList) {
|
|
96
|
-
|
|
98
|
+
// const slotAllList = findAllApplySlotMetadata(target);
|
|
99
|
+
// if (slotAllList) {
|
|
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 =
|
|
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
|
|
351
|
-
const shadowMode = conf?.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.
|
|
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
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
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
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
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
|
|
392
|
-
|
|
393
|
-
|
|
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.
|
|
430
|
+
const applyShadowChildren = SwcUtils.projectProcessHtml(this._swcId, shadowChildren, doc);
|
|
431
|
+
this.shadowRoot.replaceChildren(...applyShadowChildren)
|
|
399
432
|
}
|
|
400
|
-
if (
|
|
401
|
-
this.
|
|
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
|
-
|
|
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
|
-
|
|
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 =
|
|
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
|
|