@dooboostore/simple-web-component 1.0.38 → 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 +31 -833
- package/dist/cjs/decorators/applyNode.js +26 -39
- package/dist/cjs/decorators/applyNode.js.map +2 -2
- package/dist/cjs/decorators/applySlot.js +69 -64
- package/dist/cjs/decorators/applySlot.js.map +3 -3
- package/dist/cjs/decorators/elementDefine.js +0 -7
- package/dist/cjs/decorators/elementDefine.js.map +2 -2
- package/dist/cjs/decorators/state.js +0 -1
- package/dist/cjs/decorators/state.js.map +2 -2
- package/dist/esm/decorators/applyNode.js +26 -39
- package/dist/esm/decorators/applyNode.js.map +2 -2
- package/dist/esm/decorators/applySlot.js +69 -64
- package/dist/esm/decorators/applySlot.js.map +3 -3
- package/dist/esm/decorators/elementDefine.js +0 -7
- package/dist/esm/decorators/elementDefine.js.map +2 -2
- package/dist/esm/decorators/state.js +0 -1
- package/dist/esm/decorators/state.js.map +2 -2
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +124 -139
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
- package/dist/types/decorators/applyNode.d.ts +2 -2
- 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/state.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +124 -139
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +3 -3
- package/src/decorators/applyNode.ts +43 -51
- package/src/decorators/applySlot.ts +97 -86
- package/src/decorators/elementDefine.ts +6 -6
- package/src/decorators/state.ts +0 -1
|
@@ -28,9 +28,9 @@ __export(applyNode_exports, {
|
|
|
28
28
|
applyNodeThisBeforeEnd: () => applyNodeThisBeforeEnd,
|
|
29
29
|
applyNodeThisBeforeEndLightDom: () => applyNodeThisBeforeEndLightDom,
|
|
30
30
|
applyNodeThisBeforeEndShadow: () => applyNodeThisBeforeEndShadow,
|
|
31
|
+
applyNodeThisInnerHtml: () => applyNodeThisInnerHtml,
|
|
31
32
|
applyNodeThisReplaceChildren: () => applyNodeThisReplaceChildren,
|
|
32
33
|
applyNodeThisReplaceChildrenLightDom: () => applyNodeThisReplaceChildrenLightDom,
|
|
33
|
-
applyThisInnerHtmlNode: () => applyThisInnerHtmlNode,
|
|
34
34
|
applyThisInnerHtmlNodeLightDom: () => applyThisInnerHtmlNodeLightDom,
|
|
35
35
|
applyThisReplaceChildrenNodeLightDom: () => applyThisReplaceChildrenNodeLightDom,
|
|
36
36
|
findAllApplyNodeMetadata: () => findAllApplyNodeMetadata
|
|
@@ -42,56 +42,42 @@ var import_Utils = require("../utils/Utils");
|
|
|
42
42
|
var import_state = require("./state");
|
|
43
43
|
var import_core_web = require("@dooboostore/core-web");
|
|
44
44
|
const APPLY_NODE_METADATA_KEY = Symbol.for("simple-web-component:apply-node");
|
|
45
|
-
const normalizeNodes = (res, doc) => {
|
|
46
|
-
const items = Array.isArray(res) ? res : [res];
|
|
47
|
-
return items.map((it) => {
|
|
48
|
-
if (it instanceof Node) return it;
|
|
49
|
-
return doc.createTextNode(it !== void 0 && it !== null ? String(it) : "");
|
|
50
|
-
});
|
|
51
|
-
};
|
|
52
45
|
const applyToDom = (currentThis, targetEl, res, pos, win, host) => {
|
|
53
46
|
if (!targetEl) return;
|
|
54
47
|
const doc = win.document;
|
|
55
48
|
const hostSet = import_Utils.SwcUtils.getHelperAndHostSet(win, currentThis);
|
|
56
49
|
const id = currentThis._swcId;
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
} catch (e) {
|
|
50
|
+
const nodes = [];
|
|
51
|
+
if (typeof res === "string" && pos === "innerHtml") {
|
|
52
|
+
const t = win.document.createElement("template");
|
|
53
|
+
t.innerHTML = res;
|
|
54
|
+
nodes.push(...Array.from(t.content.childNodes));
|
|
55
|
+
} else if (typeof res === "string" && pos === "innerText") {
|
|
56
|
+
nodes.push(win.document.createTextNode(res));
|
|
65
57
|
}
|
|
66
|
-
|
|
67
|
-
targetEl.innerHTML = res !== void 0 && res !== null ? String(res) : "";
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
if (pos === "innerText") {
|
|
71
|
-
if (targetEl.innerText !== void 0) {
|
|
72
|
-
targetEl.innerText = res !== void 0 && res !== null ? String(res) : "";
|
|
73
|
-
}
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
const stateContext = { ...hostSet };
|
|
77
|
-
(0, import_state.findAllStateMetadata)(currentThis).forEach((it) => {
|
|
78
|
-
stateContext[it.name] = currentThis[it.propertyKey];
|
|
79
|
-
});
|
|
80
|
-
new import_core_web.ElementApply(currentThis, { id: currentThis._swcId }).apply({ target: "noInitialized", context: stateContext, bind: currentThis });
|
|
58
|
+
import_Utils.SwcUtils.projectProcessHtml(id, nodes, doc);
|
|
81
59
|
const isShadowRoot = targetEl instanceof win.ShadowRoot;
|
|
82
|
-
const nodes = normalizeNodes(res, doc);
|
|
83
60
|
if (pos === "replace") {
|
|
84
61
|
if (!isShadowRoot) targetEl.replaceWith(...nodes);
|
|
62
|
+
} else if (pos === "innerHtml") {
|
|
63
|
+
targetEl.replaceChildren(...nodes);
|
|
64
|
+
} else if (pos === "innerText") {
|
|
65
|
+
targetEl.replaceChildren(...nodes);
|
|
85
66
|
} else if (pos === "replaceChildren") {
|
|
86
67
|
targetEl.replaceChildren(...nodes);
|
|
87
68
|
} else {
|
|
88
69
|
if (pos === "beforeEnd") {
|
|
89
|
-
console.log("tarbbbbbbbbbbbbbb");
|
|
90
70
|
targetEl.append(...nodes);
|
|
91
71
|
} else if (pos === "afterBegin") targetEl.prepend(...nodes);
|
|
92
72
|
else if (pos === "beforeBegin" && !isShadowRoot) targetEl.before(...nodes);
|
|
93
73
|
else if (pos === "afterEnd" && !isShadowRoot) targetEl.after(...nodes);
|
|
94
74
|
}
|
|
75
|
+
const stateContext = { ...hostSet };
|
|
76
|
+
(0, import_state.findAllStateMetadata)(currentThis).forEach((it) => {
|
|
77
|
+
stateContext[it.name] = currentThis[it.propertyKey];
|
|
78
|
+
});
|
|
79
|
+
new import_core_web.ElementApply(targetEl, { id }).apply({ target: "noInitialized", context: stateContext, bind: currentThis });
|
|
80
|
+
return nodes;
|
|
95
81
|
};
|
|
96
82
|
function applyNode(selector, options = { position: "replaceChildren" }) {
|
|
97
83
|
return (targetObj, propertyKey, descriptor) => {
|
|
@@ -138,13 +124,14 @@ function applyNode(selector, options = { position: "replaceChildren" }) {
|
|
|
138
124
|
applyToDom(this, target, processedVal, pos, currentWin);
|
|
139
125
|
}
|
|
140
126
|
};
|
|
127
|
+
const fallbackNodes = [];
|
|
128
|
+
if (targetEl && options.fallback) {
|
|
129
|
+
const loadingRes = options.fallback.call(this, hostSet);
|
|
130
|
+
fallbackNodes.push(...applyToDom(this, targetEl, loadingRes, options.position || "beforeEnd", currentWin));
|
|
131
|
+
}
|
|
141
132
|
if (res instanceof Promise) {
|
|
142
|
-
if (targetEl && options.fallback) {
|
|
143
|
-
const loadingRes = options.fallback.call(this, hostSet);
|
|
144
|
-
applyToDom(this, targetEl, loadingRes, options.position || "beforeEnd", currentWin);
|
|
145
|
-
}
|
|
146
133
|
return res.then((finalRes) => {
|
|
147
|
-
|
|
134
|
+
fallbackNodes.forEach((it) => it.remove());
|
|
148
135
|
if (finalRes !== void 0 && targetEl) runApply(targetEl, finalRes);
|
|
149
136
|
return finalRes;
|
|
150
137
|
});
|
|
@@ -213,7 +200,7 @@ function applyNodeThisAfterBeginLightDom(targetOrOptions, propertyKey, descripto
|
|
|
213
200
|
const opt = targetOrOptions || {};
|
|
214
201
|
return applyNode("$this", { ...opt, ...option });
|
|
215
202
|
}
|
|
216
|
-
function
|
|
203
|
+
function applyNodeThisInnerHtml(targetOrOptions, propertyKey, descriptor) {
|
|
217
204
|
const option = { position: "innerHtml" };
|
|
218
205
|
if (propertyKey !== void 0) return applyNode("$this", option)(targetOrOptions, propertyKey, descriptor);
|
|
219
206
|
const opt = targetOrOptions || {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/decorators/applyNode.ts"],
|
|
4
|
-
"sourcesContent": ["import { ReflectUtils } from '@dooboostore/core';\nimport { ensureInit, getElementConfig } from './elementDefine';\nimport {SpecialSelector, SwcQueryOptions, HelperHostSet, SwcRootType} from '../types';\nimport { SwcUtils} from \"../utils/Utils\";\nimport {findAllStateMetadata} from \"./state\";\nimport {ElementApply} from \"@dooboostore/core-web\";\n/*\n<!-- beforebegin -->\n<p> <-- it's me\n <!-- afterbegin -->\n foo\n <!-- beforeend -->\n</p>\n<!-- afterend -->\n */\nexport type ApplyNodePosition = 'beforeBegin' | 'afterBegin' | 'beforeEnd' | 'afterEnd' | 'replace' | 'replaceChildren' | 'innerHtml' | 'innerText' | 'remove';\n\nexport interface ApplyNodeOptions {\n position?: ApplyNodePosition;\n root?: SwcRootType;\n /**\n * Filter function to determine whether to perform DOM operation.\n * If it returns false, the operation is skipped.\n */\n filter?: (target: HTMLElement | ShadowRoot, newValue: any, meta: { currentThis: any, helper: HelperHostSet }) => boolean;\n /**\n * Optional loading content to display while an async method is executing.\n */\n fallback?: (helper: HelperHostSet) => any;\n}\n\nexport interface ApplyNodeMetadata {\n propertyKey: string | symbol;\n selector: string;\n options: ApplyNodeOptions;\n}\n\nexport const APPLY_NODE_METADATA_KEY = Symbol.for('simple-web-component:apply-node');\n\nconst normalizeNodes = (res: any, doc: Document): Node[] => {\n const items = Array.isArray(res) ? res : [res];\n return items.map(it => {\n if (it instanceof Node) return it;\n return doc.createTextNode(it !== undefined && it !== null ? String(it) : '');\n });\n};\n\nconst applyToDom = (currentThis: any, targetEl: HTMLElement, res: any, pos: ApplyNodePosition, win: Window, host?: any) => {\n if (!targetEl) return;\n\n // console.log('------------',currentThis.tagName, res)\n const doc = win.document;\n const hostSet = SwcUtils.getHelperAndHostSet(win, currentThis);\n const id = currentThis._swcId;\n // Allow processHtml to run here so all DOM insertions go through a single\n // processing point. processHtml may mutate Node[] in-place or return a\n // transformed string result for text processing.\n try {\n if (typeof res === 'string') {\n const processed = SwcUtils.projectProcessHtml(id, res as string, doc);\n if (processed !== undefined) res = processed;\n } else if (res) {\n SwcUtils.projectProcessHtml(id, res, doc);\n }\n } catch (e) {\n // swallow and proceed with original res\n }\n\n if (pos === 'innerHtml') {\n targetEl.innerHTML = res !== undefined && res !== null ? String(res) : '';\n return;\n }\n\n if (pos === 'innerText') {\n if (targetEl.innerText !== undefined) {\n targetEl.innerText = res !== undefined && res !== null ? String(res) : '';\n }\n return;\n }\n\n const stateContext: any = {...hostSet};\n findAllStateMetadata(currentThis).forEach(it => {\n stateContext[it.name] = currentThis[it.propertyKey]\n })\n new ElementApply(currentThis, {id: currentThis._swcId}).apply({target: 'noInitialized', context: stateContext, bind: currentThis});\n\n\n const isShadowRoot = targetEl instanceof win.ShadowRoot;\n const nodes = normalizeNodes(res, doc);\n if (pos === 'replace') {\n if (!isShadowRoot) targetEl.replaceWith(...nodes);\n } else if (pos === 'replaceChildren') {\n targetEl.replaceChildren(...nodes);\n } else {\n if (pos === 'beforeEnd') {\n console.log('tarbbbbbbbbbbbbbb')\n targetEl.append(...nodes)\n }\n else if (pos === 'afterBegin') targetEl.prepend(...nodes);\n else if (pos === 'beforeBegin' && !isShadowRoot) targetEl.before(...nodes);\n else if (pos === 'afterEnd' && !isShadowRoot) targetEl.after(...nodes);\n }\n};\n\n/**\n * @applyNode decorator to surgically add/replace nodes to a target element.\n */\nexport function applyNode(selector: string, options: ApplyNodeOptions = {position: 'replaceChildren'}): MethodDecorator {\n return (targetObj: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n const constructor = targetObj.constructor;\n let metaList = ReflectUtils.getOwnMetadata(APPLY_NODE_METADATA_KEY, constructor) as Map<string | symbol, ApplyNodeMetadata>;\n if (!metaList) {\n metaList = new Map<string | symbol, ApplyNodeMetadata>();\n ReflectUtils.defineMetadata(APPLY_NODE_METADATA_KEY, metaList, constructor);\n }\n metaList.set(propertyKey, {propertyKey, selector, options});\n\n const original = descriptor.value;\n descriptor.value = function (...args: any[]) {\n ensureInit(this);\n\n const conf = getElementConfig(this);\n const currentWin = (this as any)._resolveWindow?.(conf) || ((typeof window !== 'undefined' ? window : undefined) as Window);\n const currentDoc = currentWin.document;\n const hostSet = SwcUtils.getHelperAndHostSet(currentWin, this);\n\n const getTarget = () => {\n const r = options.root || 'auto';\n const applyRoot = (t: any) => {\n if (!t) return t;\n if (r === 'auto') return t.shadowRoot || t;\n if (r === 'shadow') return t.shadowRoot;\n if (r === 'light') return t;\n if (r === 'all') return t.shadowRoot || t;\n return t;\n };\n\n if (selector === '$this') return applyRoot(this);\n if (selector === '$host') return applyRoot(hostSet.$host);\n if (selector === '$parentHost') return applyRoot(hostSet.$parentHost);\n if (selector === '$appHost') return applyRoot(hostSet.$appHost);\n if (selector === '$firstHost') return applyRoot(hostSet.$firstHost);\n if (selector === '$lastHost') return applyRoot(hostSet.$lastHost);\n\n const targetRoot = applyRoot(this);\n return targetRoot ? targetRoot.querySelector(selector) : null;\n };\n\n\n console.log('fffffffffff')\n const targetEl = getTarget();\n const res = original.apply(this, args);\n\n const runApply = (target: any, val: any) => {\n const pos = options.position || 'beforeEnd';\n // Delegate HTML/node processing to applyToDom which centralizes\n // processing. runApply should not call processHtml itself to avoid\n // duplicate processing.\n const processedVal = val;\n\n // \uC0AC\uC6A9\uC790\uAC00 filter\uB97C \uBA85\uC2DC\uD558\uBA74 \uADF8 \uC870\uAC74\uC73C\uB85C, \uC544\uB2C8\uBA74 \uD56D\uC0C1 \uC801\uC6A9\n if (!options.filter || options.filter(target, processedVal, {currentThis: this, helper: hostSet})) {\n applyToDom(this, target, processedVal, pos, currentWin);\n }\n };\n\n if (res instanceof Promise) {\n // \uBE44\uB3D9\uAE30\uC77C \uB54C\uB9CC \uB85C\uB529 \uD45C\uC2DC\n if (targetEl && options.fallback) {\n const loadingRes = options.fallback.call(this, hostSet);\n // applyToDom expects a Window as the 4th argument\n applyToDom(this, targetEl, loadingRes, options.position || 'beforeEnd', currentWin);\n }\n\n return res.then(finalRes => {\n console.log('amnkj')\n if (finalRes !== undefined && targetEl) runApply(targetEl, finalRes);\n return finalRes;\n });\n } else {\n if (res !== undefined && targetEl) runApply(targetEl, res);\n return res;\n }\n };\n };\n}\n\nexport const findAllApplyNodeMetadata = (target: any): Map<string | symbol, ApplyNodeMetadata> => {\n const result = new Map<string | symbol, ApplyNodeMetadata>();\n const maps = ReflectUtils.findAllMetadata<Map<string | symbol, ApplyNodeMetadata>>(APPLY_NODE_METADATA_KEY, target);\n maps.forEach(map => {\n if (map instanceof Map) {\n map.forEach((v, k) => result.set(k, v));\n }\n });\n return result;\n};\n\nexport function applyNodeThis(options: ApplyNodeOptions): MethodDecorator;\nexport function applyNodeThis(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function applyNodeThis(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {\n const option: ApplyNodeOptions = {position: 'replaceChildren'};\n if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);\n const opt = targetOrOptions || {};\n return applyNode('$this', {...option, ...opt});\n}\n\nexport function applyNodeThisReplaceChildren(options: Omit<ApplyNodeOptions, 'position'>): MethodDecorator;\nexport function applyNodeThisReplaceChildren(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function applyNodeThisReplaceChildren(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {\n const option: ApplyNodeOptions = {position: 'replaceChildren'};\n if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);\n const opt = targetOrOptions || {};\n return applyNode('$this', {...opt, ...option});\n}\n\nexport function applyNodeThisReplaceChildrenLightDom(options: Omit<ApplyNodeOptions, 'position' | 'root'>): MethodDecorator;\nexport function applyNodeThisReplaceChildrenLightDom(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function applyNodeThisReplaceChildrenLightDom(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {\n const options: ApplyNodeOptions = {position: 'replaceChildren', root: 'light'};\n if (propertyKey !== undefined) return applyNode('$this', options)(targetOrOptions, propertyKey, descriptor);\n const opt = targetOrOptions || {};\n return applyNode('$this', {...opt, ...options});\n}\n\nexport function applyNodeThisBeforeEnd(options: Omit<ApplyNodeOptions, 'position'>): MethodDecorator;\nexport function applyNodeThisBeforeEnd(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function applyNodeThisBeforeEnd(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {\n const options: ApplyNodeOptions = {position: 'beforeEnd'};\n if (propertyKey !== undefined) return applyNode('$this', options)(targetOrOptions, propertyKey, descriptor);\n const opt = targetOrOptions || {};\n return applyNode('$this', {...opt, ...options});\n}\n\nexport function applyNodeThisBeforeEndLightDom(options: Omit<ApplyNodeOptions, 'position' | 'root'>): MethodDecorator;\nexport function applyNodeThisBeforeEndLightDom(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function applyNodeThisBeforeEndLightDom(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {\n const option: ApplyNodeOptions = {position: 'beforeEnd', root: 'light'}\n if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);\n const opt = targetOrOptions || {};\n return applyNode('$this', {...opt, ...option});\n}\nexport function applyNodeThisBeforeEndShadow(options: Omit<ApplyNodeOptions, 'position' | 'root'>): MethodDecorator;\nexport function applyNodeThisBeforeEndShadow(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function applyNodeThisBeforeEndShadow(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {\n const option: ApplyNodeOptions = {position: 'beforeEnd', root: 'shadow'}\n if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);\n const opt = targetOrOptions || {};\n return applyNode('$this', {...opt, ...option});\n}\n\nexport function applyNodeThisAfterBegin(options: Omit<ApplyNodeOptions, 'position'>): MethodDecorator;\nexport function applyNodeThisAfterBegin(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function applyNodeThisAfterBegin(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {\n const option: ApplyNodeOptions = {position: 'afterBegin'};\n if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);\n const opt = targetOrOptions || {};\n return applyNode('$this', {...opt, ...option});\n}\n\nexport function applyNodeThisAfterBeginLightDom(options: Omit<ApplyNodeOptions, 'position' | 'root'>): MethodDecorator;\nexport function applyNodeThisAfterBeginLightDom(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function applyNodeThisAfterBeginLightDom(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {\n const option: ApplyNodeOptions = {position: 'afterBegin', root: 'light'}\n if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);\n const opt = targetOrOptions || {};\n return applyNode('$this', {...opt, ...option});\n}\n\nexport function applyThisInnerHtmlNode(options: Omit<ApplyNodeOptions, 'position'>): MethodDecorator;\nexport function applyThisInnerHtmlNode(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function applyThisInnerHtmlNode(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {\n const option: ApplyNodeOptions = {position: 'innerHtml'}\n if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);\n const opt = targetOrOptions || {};\n return applyNode('$this', {...opt, ...option});\n}\n\nexport function applyThisInnerHtmlNodeLightDom(options: Omit<ApplyNodeOptions, 'position' | 'root'>): MethodDecorator;\nexport function applyThisInnerHtmlNodeLightDom(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function applyThisInnerHtmlNodeLightDom(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {\n const option: ApplyNodeOptions = {position: 'innerHtml', root: 'light'};\n if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);\n const opt = targetOrOptions || {};\n return applyNode('$this', {...opt, ...option});\n}\n\nexport function applyThisReplaceChildrenNodeLightDom(options: Omit<ApplyNodeOptions, 'position' | 'root'>): MethodDecorator;\nexport function applyThisReplaceChildrenNodeLightDom(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function applyThisReplaceChildrenNodeLightDom(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {\n const option: ApplyNodeOptions = {position: 'replaceChildren', root: 'light'};\n if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);\n const opt = targetOrOptions || {};\n return applyNode('$this', {...opt, ...option});\n}\n\nexport function applyNodeReplaceChildren(selector: string, options: Omit<ApplyNodeOptions, 'position'> = {}): MethodDecorator {\n return applyNode(selector, {...options, position: 'replaceChildren'});\n}\n\nexport function applyNodeInnerHtml(selector: string, options: Omit<ApplyNodeOptions, 'position'> = {}): MethodDecorator {\n return applyNode(selector, {...options, position: 'innerHtml'});\n}\n\n// export function applyNodeInnerHtmlLightDom(selector: string, options: Omit<ApplyNodeOptions, 'position' | 'root'> = {}): MethodDecorator {\n// return applyNode(selector, {...options, position: 'innerHtml', root: 'light'});\n// }\n\nexport function applyNodeInnerText(selector: string, options: Omit<ApplyNodeOptions, 'position'> = {}): MethodDecorator {\n return applyNode(selector, {...options, position: 'innerText'});\n}\n\n// export function applyNodeInnerTextLightDom(selector: string, options: Omit<ApplyNodeOptions, 'position' | 'root'> = {}): MethodDecorator {\n// return applyNode(selector, {...options, position: 'innerText', root: 'light'});\n// }\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA6B;AAC7B,2BAA6C;AAE7C,mBAAwB;AACxB,mBAAmC;AACnC,sBAA2B;AAgCpB,MAAM,0BAA0B,OAAO,IAAI,iCAAiC;
|
|
4
|
+
"sourcesContent": ["import { ReflectUtils } from '@dooboostore/core';\nimport { ensureInit, getElementConfig } from './elementDefine';\nimport {SpecialSelector, SwcQueryOptions, HelperHostSet, SwcRootType} from '../types';\nimport { SwcUtils} from \"../utils/Utils\";\nimport {findAllStateMetadata} from \"./state\";\nimport {ElementApply} from \"@dooboostore/core-web\";\n/*\n<!-- beforebegin -->\n<p> <-- it's me\n <!-- afterbegin -->\n foo\n <!-- beforeend -->\n</p>\n<!-- afterend -->\n */\nexport type ApplyNodePosition = 'beforeBegin' | 'afterBegin' | 'beforeEnd' | 'afterEnd' | 'replace' | 'replaceChildren' | 'innerHtml' | 'innerText' | 'remove';\n\nexport interface ApplyNodeOptions {\n position?: ApplyNodePosition;\n root?: SwcRootType;\n /**\n * Filter function to determine whether to perform DOM operation.\n * If it returns false, the operation is skipped.\n */\n filter?: (target: HTMLElement | ShadowRoot, newValue: any, meta: { currentThis: any, helper: HelperHostSet }) => boolean;\n /**\n * Optional loading content to display while an async method is executing.\n */\n fallback?: (helper: HelperHostSet) => any;\n}\n\nexport interface ApplyNodeMetadata {\n propertyKey: string | symbol;\n selector: string;\n options: ApplyNodeOptions;\n}\n\nexport const APPLY_NODE_METADATA_KEY = Symbol.for('simple-web-component:apply-node');\n\n// const normalizeNodes = (res: any, doc: Document): Node[] => {\n// const items = Array.isArray(res) ? res : [res];\n// return items.map(it => {\n// if (it instanceof Node) return it;\n// return doc.createTextNode(it !== undefined && it !== null ? String(it) : '');\n// });\n// };\n\nconst applyToDom = (currentThis: any, targetEl: HTMLElement, res: Node | string, pos: ApplyNodePosition, win: Window, host?: any) => {\n if (!targetEl) return;\n const doc = win.document;\n const hostSet = SwcUtils.getHelperAndHostSet(win, currentThis);\n const id = currentThis._swcId;\n\n\n const nodes: Node[] = [];\n\n if (typeof res === 'string' && pos === 'innerHtml') {\n const t = win.document.createElement('template');\n t.innerHTML = res;\n nodes.push(...Array.from(t.content.childNodes));\n } else if (typeof res === 'string' && pos === 'innerText') {\n nodes.push(win.document.createTextNode(res));\n }\n\n SwcUtils.projectProcessHtml(id, nodes, doc);\n\n\n\n const isShadowRoot = targetEl instanceof win.ShadowRoot;\n // const nodes = normalizeNodes(res, doc);\n if (pos === 'replace') {\n if (!isShadowRoot) targetEl.replaceWith(...nodes);\n } else if (pos === 'innerHtml') {\n targetEl.replaceChildren(...nodes);\n } else if (pos === 'innerText') {\n targetEl.replaceChildren(...nodes);\n } else if (pos === 'replaceChildren') {\n targetEl.replaceChildren(...nodes);\n } else {\n if (pos === 'beforeEnd') {\n targetEl.append(...nodes)\n }\n else if (pos === 'afterBegin') targetEl.prepend(...nodes);\n else if (pos === 'beforeBegin' && !isShadowRoot) targetEl.before(...nodes);\n else if (pos === 'afterEnd' && !isShadowRoot) targetEl.after(...nodes);\n }\n\n const stateContext: any = {...hostSet};\n findAllStateMetadata(currentThis).forEach(it => {\n stateContext[it.name] = currentThis[it.propertyKey]\n })\n new ElementApply(targetEl, {id: id}).apply({target: 'noInitialized', context: stateContext, bind: currentThis});\n return nodes;\n};\n\n/**\n * @applyNode decorator to surgically add/replace nodes to a target element.\n */\nexport function applyNode(selector: string, options: ApplyNodeOptions = {position: 'replaceChildren'}): MethodDecorator {\n return (targetObj: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n const constructor = targetObj.constructor;\n let metaList = ReflectUtils.getOwnMetadata(APPLY_NODE_METADATA_KEY, constructor) as Map<string | symbol, ApplyNodeMetadata>;\n if (!metaList) {\n metaList = new Map<string | symbol, ApplyNodeMetadata>();\n ReflectUtils.defineMetadata(APPLY_NODE_METADATA_KEY, metaList, constructor);\n }\n metaList.set(propertyKey, {propertyKey, selector, options});\n\n const original = descriptor.value;\n descriptor.value = function (...args: any[]) {\n ensureInit(this);\n\n const conf = getElementConfig(this);\n const currentWin = (this as any)._resolveWindow?.(conf) || ((typeof window !== 'undefined' ? window : undefined) as Window);\n const currentDoc = currentWin.document;\n const hostSet = SwcUtils.getHelperAndHostSet(currentWin, this);\n\n const getTarget = () => {\n const r = options.root || 'auto';\n const applyRoot = (t: any) => {\n if (!t) return t;\n if (r === 'auto') return t.shadowRoot || t;\n if (r === 'shadow') return t.shadowRoot;\n if (r === 'light') return t;\n if (r === 'all') return t.shadowRoot || t;\n return t;\n };\n\n if (selector === '$this') return applyRoot(this);\n if (selector === '$host') return applyRoot(hostSet.$host);\n if (selector === '$parentHost') return applyRoot(hostSet.$parentHost);\n if (selector === '$appHost') return applyRoot(hostSet.$appHost);\n if (selector === '$firstHost') return applyRoot(hostSet.$firstHost);\n if (selector === '$lastHost') return applyRoot(hostSet.$lastHost);\n\n const targetRoot = applyRoot(this);\n return targetRoot ? targetRoot.querySelector(selector) : null;\n };\n\n\n console.log('fffffffffff')\n const targetEl = getTarget();\n const res = original.apply(this, args);\n\n const runApply = (target: any, val: any) => {\n const pos = options.position || 'beforeEnd';\n // Delegate HTML/node processing to applyToDom which centralizes\n // processing. runApply should not call processHtml itself to avoid\n // duplicate processing.\n const processedVal = val;\n\n // \uC0AC\uC6A9\uC790\uAC00 filter\uB97C \uBA85\uC2DC\uD558\uBA74 \uADF8 \uC870\uAC74\uC73C\uB85C, \uC544\uB2C8\uBA74 \uD56D\uC0C1 \uC801\uC6A9\n if (!options.filter || options.filter(target, processedVal, {currentThis: this, helper: hostSet})) {\n applyToDom(this, target, processedVal, pos, currentWin);\n }\n };\n\n\n const fallbackNodes: Node[] = [];\n if (targetEl && options.fallback) {\n const loadingRes = options.fallback.call(this, hostSet);\n // applyToDom expects a Window as the 4th argument\n fallbackNodes.push(...applyToDom(this, targetEl, loadingRes, options.position || 'beforeEnd', currentWin));\n }\n\n if (res instanceof Promise) {\n return res.then(finalRes => {\n fallbackNodes.forEach((it: any)=>it.remove());\n if (finalRes !== undefined && targetEl) runApply(targetEl, finalRes);\n return finalRes;\n });\n } else {\n if (res !== undefined && targetEl) runApply(targetEl, res);\n return res;\n }\n };\n };\n}\n\nexport const findAllApplyNodeMetadata = (target: any): Map<string | symbol, ApplyNodeMetadata> => {\n const result = new Map<string | symbol, ApplyNodeMetadata>();\n const maps = ReflectUtils.findAllMetadata<Map<string | symbol, ApplyNodeMetadata>>(APPLY_NODE_METADATA_KEY, target);\n maps.forEach(map => {\n if (map instanceof Map) {\n map.forEach((v, k) => result.set(k, v));\n }\n });\n return result;\n};\n\nexport function applyNodeThis(options: ApplyNodeOptions): MethodDecorator;\nexport function applyNodeThis(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function applyNodeThis(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {\n const option: ApplyNodeOptions = {position: 'replaceChildren'};\n if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);\n const opt = targetOrOptions || {};\n return applyNode('$this', {...option, ...opt});\n}\n\nexport function applyNodeThisReplaceChildren(options: Omit<ApplyNodeOptions, 'position'>): MethodDecorator;\nexport function applyNodeThisReplaceChildren(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function applyNodeThisReplaceChildren(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {\n const option: ApplyNodeOptions = {position: 'replaceChildren'};\n if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);\n const opt = targetOrOptions || {};\n return applyNode('$this', {...opt, ...option});\n}\n\nexport function applyNodeThisReplaceChildrenLightDom(options: Omit<ApplyNodeOptions, 'position' | 'root'>): MethodDecorator;\nexport function applyNodeThisReplaceChildrenLightDom(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function applyNodeThisReplaceChildrenLightDom(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {\n const options: ApplyNodeOptions = {position: 'replaceChildren', root: 'light'};\n if (propertyKey !== undefined) return applyNode('$this', options)(targetOrOptions, propertyKey, descriptor);\n const opt = targetOrOptions || {};\n return applyNode('$this', {...opt, ...options});\n}\n\nexport function applyNodeThisBeforeEnd(options: Omit<ApplyNodeOptions, 'position'>): MethodDecorator;\nexport function applyNodeThisBeforeEnd(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function applyNodeThisBeforeEnd(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {\n const options: ApplyNodeOptions = {position: 'beforeEnd'};\n if (propertyKey !== undefined) return applyNode('$this', options)(targetOrOptions, propertyKey, descriptor);\n const opt = targetOrOptions || {};\n return applyNode('$this', {...opt, ...options});\n}\n\nexport function applyNodeThisBeforeEndLightDom(options: Omit<ApplyNodeOptions, 'position' | 'root'>): MethodDecorator;\nexport function applyNodeThisBeforeEndLightDom(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function applyNodeThisBeforeEndLightDom(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {\n const option: ApplyNodeOptions = {position: 'beforeEnd', root: 'light'}\n if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);\n const opt = targetOrOptions || {};\n return applyNode('$this', {...opt, ...option});\n}\nexport function applyNodeThisBeforeEndShadow(options: Omit<ApplyNodeOptions, 'position' | 'root'>): MethodDecorator;\nexport function applyNodeThisBeforeEndShadow(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function applyNodeThisBeforeEndShadow(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {\n const option: ApplyNodeOptions = {position: 'beforeEnd', root: 'shadow'}\n if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);\n const opt = targetOrOptions || {};\n return applyNode('$this', {...opt, ...option});\n}\n\nexport function applyNodeThisAfterBegin(options: Omit<ApplyNodeOptions, 'position'>): MethodDecorator;\nexport function applyNodeThisAfterBegin(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function applyNodeThisAfterBegin(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {\n const option: ApplyNodeOptions = {position: 'afterBegin'};\n if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);\n const opt = targetOrOptions || {};\n return applyNode('$this', {...opt, ...option});\n}\n\nexport function applyNodeThisAfterBeginLightDom(options: Omit<ApplyNodeOptions, 'position' | 'root'>): MethodDecorator;\nexport function applyNodeThisAfterBeginLightDom(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function applyNodeThisAfterBeginLightDom(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {\n const option: ApplyNodeOptions = {position: 'afterBegin', root: 'light'}\n if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);\n const opt = targetOrOptions || {};\n return applyNode('$this', {...opt, ...option});\n}\n\nexport function applyNodeThisInnerHtml(options: Omit<ApplyNodeOptions, 'position'>): MethodDecorator;\nexport function applyNodeThisInnerHtml(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function applyNodeThisInnerHtml(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {\n const option: ApplyNodeOptions = {position: 'innerHtml'}\n if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);\n const opt = targetOrOptions || {};\n return applyNode('$this', {...opt, ...option});\n}\n\nexport function applyThisInnerHtmlNodeLightDom(options: Omit<ApplyNodeOptions, 'position' | 'root'>): MethodDecorator;\nexport function applyThisInnerHtmlNodeLightDom(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function applyThisInnerHtmlNodeLightDom(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {\n const option: ApplyNodeOptions = {position: 'innerHtml', root: 'light'};\n if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);\n const opt = targetOrOptions || {};\n return applyNode('$this', {...opt, ...option});\n}\n\nexport function applyThisReplaceChildrenNodeLightDom(options: Omit<ApplyNodeOptions, 'position' | 'root'>): MethodDecorator;\nexport function applyThisReplaceChildrenNodeLightDom(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function applyThisReplaceChildrenNodeLightDom(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {\n const option: ApplyNodeOptions = {position: 'replaceChildren', root: 'light'};\n if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);\n const opt = targetOrOptions || {};\n return applyNode('$this', {...opt, ...option});\n}\n\nexport function applyNodeReplaceChildren(selector: string, options: Omit<ApplyNodeOptions, 'position'> = {}): MethodDecorator {\n return applyNode(selector, {...options, position: 'replaceChildren'});\n}\n\nexport function applyNodeInnerHtml(selector: string, options: Omit<ApplyNodeOptions, 'position'> = {}): MethodDecorator {\n return applyNode(selector, {...options, position: 'innerHtml'});\n}\n\n// export function applyNodeInnerHtmlLightDom(selector: string, options: Omit<ApplyNodeOptions, 'position' | 'root'> = {}): MethodDecorator {\n// return applyNode(selector, {...options, position: 'innerHtml', root: 'light'});\n// }\n\nexport function applyNodeInnerText(selector: string, options: Omit<ApplyNodeOptions, 'position'> = {}): MethodDecorator {\n return applyNode(selector, {...options, position: 'innerText'});\n}\n\n// export function applyNodeInnerTextLightDom(selector: string, options: Omit<ApplyNodeOptions, 'position' | 'root'> = {}): MethodDecorator {\n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|
|
@@ -37,93 +37,98 @@ var import_elementDefine = require("./elementDefine");
|
|
|
37
37
|
var import_Utils = require("../utils/Utils");
|
|
38
38
|
var import_core_web = require("@dooboostore/core-web");
|
|
39
39
|
const APPLY_SLOT_METADATA_KEY = Symbol.for("simple-web-component:apply-slot");
|
|
40
|
-
|
|
40
|
+
const applyToDom = (swcId, id, pos, nodes) => {
|
|
41
|
+
const nodeSlot = new import_core_web.NodeSlot(void 0, swcId);
|
|
42
|
+
if (pos === "replaceChildrenText" || pos === "replaceChildren" || pos === "replaceChildrenHtml") {
|
|
43
|
+
nodeSlot.replaceChildren(id, ...nodes);
|
|
44
|
+
} else if (pos === "appendHtml" || pos === "append" || pos === "appendText") {
|
|
45
|
+
nodeSlot.append(id, ...nodes);
|
|
46
|
+
} else if (pos === "prependHtml" || pos === "prepend" || pos === "prependText") {
|
|
47
|
+
nodeSlot.prepend(id, ...nodes);
|
|
48
|
+
} else if (pos === "clear") {
|
|
49
|
+
nodeSlot.clear(id);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
function applySlot(targetId, opt) {
|
|
41
53
|
return (targetObj, propertyKey, descriptor) => {
|
|
42
|
-
const
|
|
43
|
-
if (type === "property") {
|
|
44
|
-
Object.defineProperty(targetObj, propertyKey, {
|
|
45
|
-
get() {
|
|
46
|
-
const nodeSlot = new import_core_web.NodeSlot(this, `${this._swcId}-${id}`);
|
|
47
|
-
return nodeSlot;
|
|
48
|
-
},
|
|
49
|
-
set(nv) {
|
|
50
|
-
if (nv) {
|
|
51
|
-
} else {
|
|
52
|
-
const nodeSlot = new import_core_web.NodeSlot(this, `${this._swcId}-${id}`);
|
|
53
|
-
nodeSlot.clear();
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
configurable: true,
|
|
57
|
-
enumerable: true
|
|
58
|
-
});
|
|
59
|
-
}
|
|
54
|
+
const options = { position: "replaceChildrenHtml", ...opt };
|
|
60
55
|
const constructor = targetObj.constructor;
|
|
61
56
|
let metaList = import_core.ReflectUtils.getOwnMetadata(APPLY_SLOT_METADATA_KEY, constructor);
|
|
62
57
|
if (!metaList) {
|
|
63
58
|
metaList = [];
|
|
64
59
|
import_core.ReflectUtils.defineMetadata(APPLY_SLOT_METADATA_KEY, metaList, constructor);
|
|
65
60
|
}
|
|
66
|
-
metaList.push({ propertyKey,
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
} else if (pos === "appendText") {
|
|
87
|
-
nodeSlot.appendText(id, res);
|
|
88
|
-
} else if (pos === "prependHtml") {
|
|
89
|
-
nodeSlot.prependHtml(id, res);
|
|
90
|
-
} else if (pos === "prependText") {
|
|
91
|
-
nodeSlot.prependText(id, res);
|
|
92
|
-
} else if (pos === "clear") {
|
|
93
|
-
nodeSlot.clear(id);
|
|
94
|
-
}
|
|
61
|
+
metaList.push({ propertyKey, targetId, options });
|
|
62
|
+
const original = descriptor.value;
|
|
63
|
+
descriptor.value = function(...args) {
|
|
64
|
+
(0, import_elementDefine.ensureInit)(this);
|
|
65
|
+
const conf = (0, import_elementDefine.getElementConfig)(this);
|
|
66
|
+
const currentWin = conf.window;
|
|
67
|
+
const swcId = this._swcId;
|
|
68
|
+
const currentDoc = currentWin.document;
|
|
69
|
+
const hostSet = import_Utils.SwcUtils.getHelperAndHostSet(currentWin, this);
|
|
70
|
+
const pos = options.position;
|
|
71
|
+
const resToNodes = (res2) => {
|
|
72
|
+
const nodes = [];
|
|
73
|
+
if (typeof res2 === "string" && (pos === "replaceChildrenHtml" || pos === "appendHtml" || pos === "prependHtml")) {
|
|
74
|
+
const t = currentWin.document.createElement("template");
|
|
75
|
+
t.innerHTML = res2;
|
|
76
|
+
nodes.push(...Array.from(t.content.childNodes));
|
|
77
|
+
} else if (typeof res2 === "string" && (pos === "replaceChildrenText" || pos === "prependText" || pos === "appendText")) {
|
|
78
|
+
nodes.push(currentWin.document.createTextNode(res2));
|
|
79
|
+
} else if (typeof res2 === "object") {
|
|
80
|
+
nodes.push(res2);
|
|
95
81
|
}
|
|
96
|
-
|
|
82
|
+
import_Utils.SwcUtils.projectProcessHtml(swcId, nodes, currentDoc);
|
|
83
|
+
return nodes;
|
|
97
84
|
};
|
|
98
|
-
|
|
85
|
+
const fallbackNodes = [];
|
|
86
|
+
if (options.fallback) {
|
|
87
|
+
const res2 = options.fallback.call(this, hostSet);
|
|
88
|
+
const nodes = resToNodes(res2);
|
|
89
|
+
fallbackNodes.push(...nodes);
|
|
90
|
+
applyToDom(swcId, targetId, options.position, nodes);
|
|
91
|
+
}
|
|
92
|
+
let res = original.apply(this, args);
|
|
93
|
+
if (res instanceof Promise) {
|
|
94
|
+
return res.then((asyncRes) => {
|
|
95
|
+
const nodes = resToNodes(asyncRes);
|
|
96
|
+
fallbackNodes.forEach((it) => it.remove());
|
|
97
|
+
applyToDom(swcId, targetId, options.position, nodes);
|
|
98
|
+
});
|
|
99
|
+
} else {
|
|
100
|
+
const nodes = resToNodes(res);
|
|
101
|
+
applyToDom(swcId, targetId, options.position, nodes);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
99
104
|
};
|
|
100
105
|
}
|
|
101
106
|
const findAllApplySlotMetadata = (target) => {
|
|
102
107
|
const constructor = target instanceof Function ? target : target.constructor;
|
|
103
108
|
return import_core.ReflectUtils.getMetadata(APPLY_SLOT_METADATA_KEY, constructor);
|
|
104
109
|
};
|
|
105
|
-
function applySlotClear(
|
|
106
|
-
return applySlot(
|
|
110
|
+
function applySlotClear(targetId) {
|
|
111
|
+
return applySlot(targetId, { position: "clear" });
|
|
107
112
|
}
|
|
108
|
-
function applySlotPrependHtml(
|
|
109
|
-
return applySlot(
|
|
113
|
+
function applySlotPrependHtml(targetId) {
|
|
114
|
+
return applySlot(targetId, { position: "prependHtml" });
|
|
110
115
|
}
|
|
111
116
|
const applySlotPrepend = applySlotPrependHtml;
|
|
112
|
-
function applySlotPrependText(
|
|
113
|
-
return applySlot(
|
|
117
|
+
function applySlotPrependText(targetId) {
|
|
118
|
+
return applySlot(targetId, { position: "prependText" });
|
|
114
119
|
}
|
|
115
|
-
function applySlotAppendHtml(
|
|
116
|
-
return applySlot(
|
|
120
|
+
function applySlotAppendHtml(targetId) {
|
|
121
|
+
return applySlot(targetId, { position: "appendHtml" });
|
|
117
122
|
}
|
|
118
|
-
function applySlotAppendText(
|
|
119
|
-
return applySlot(
|
|
123
|
+
function applySlotAppendText(targetId) {
|
|
124
|
+
return applySlot(targetId, { position: "appendText" });
|
|
120
125
|
}
|
|
121
126
|
const applySlotAppend = applySlotAppendHtml;
|
|
122
|
-
function applySlotReplaceChildrenHtml(
|
|
123
|
-
return applySlot(
|
|
127
|
+
function applySlotReplaceChildrenHtml(targetId) {
|
|
128
|
+
return applySlot(targetId, { position: "replaceChildrenHtml" });
|
|
124
129
|
}
|
|
125
130
|
const applySlotReplaceChildren = applySlotReplaceChildrenHtml;
|
|
126
|
-
function applySlotReplaceChildrenText(
|
|
127
|
-
return applySlot(
|
|
131
|
+
function applySlotReplaceChildrenText(targetId) {
|
|
132
|
+
return applySlot(targetId, { position: "replaceChildrenText" });
|
|
128
133
|
}
|
|
129
134
|
//# sourceMappingURL=applySlot.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/decorators/applySlot.ts"],
|
|
4
|
-
"sourcesContent": ["import {ReflectUtils} from '@dooboostore/core';\nimport {ensureInit, getElementConfig} from './elementDefine';\nimport {SwcUtils} from \"../utils/Utils\";\nimport {NodeSlot} from \"@dooboostore/core-web\";\n/*\n<!-- beforebegin -->\n<p> <-- it's me\n <!-- afterbegin -->\n foo\n <!-- beforeend -->\n</p>\n<!-- afterend -->\n */\nexport type ApplySlotPosition = 'prependHtml' | 'prependText' | 'appendHtml' | 'appendText' | 'replaceChildrenHtml' | 'replaceChildrenText' | 'clear';\n\nexport interface ApplySlotOptions {\n position
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,
|
|
6
|
-
"names": []
|
|
4
|
+
"sourcesContent": ["import {OptionalType, ReflectUtils} from '@dooboostore/core';\nimport {ensureInit, getElementConfig} from './elementDefine';\nimport {SwcUtils} from \"../utils/Utils\";\nimport {NodeSlot} from \"@dooboostore/core-web\";\nimport {HelperHostSet} from \"../types\";\n/*\n<!-- beforebegin -->\n<p> <-- it's me\n <!-- afterbegin -->\n foo\n <!-- beforeend -->\n</p>\n<!-- afterend -->\n */\nexport type ApplySlotPosition = 'prepend' | 'prependHtml' | 'prependText' | 'append' | 'appendHtml' | 'appendText' | 'replaceChildren' | 'replaceChildrenHtml' | 'replaceChildrenText' | 'clear';\n\nexport interface ApplySlotOptions {\n position: ApplySlotPosition;\n fallback?: (helper: HelperHostSet) => string | Node;\n // root?: SwcRootType;\n /**\n * Filter function to determine whether to perform DOM operation.\n * If it returns false, the operation is skipped.\n */\n // filter?: (target: HTMLElement | ShadowRoot, newValue: any, meta:{currentThis: any,helper: HelperHostSet}) => boolean;\n /**\n * Optional loading content to display while an async method is executing.\n */\n // loading?: (helper: HelperHostSet) => any;\n}\n\nexport interface ApplySlotMetadata {\n propertyKey: string | symbol;\n targetId: string;\n // type: 'method' | 'property';\n options: ApplySlotOptions;\n}\n\nexport const APPLY_SLOT_METADATA_KEY = Symbol.for('simple-web-component:apply-slot');\n\n// const normalizeNodes = (res: any, doc: Document): Node[] => {\n// const items = Array.isArray(res) ? res : [res];\n// return items.map(it => {\n// if (it instanceof Node) return it;\n// return doc.createTextNode(it !== undefined && it !== null ? String(it) : '');\n// });\n// };\n\n// const applyToDom = (targetEl: any, res: any, pos: ApplyNodePosition, win: Window) => {\n// if (!targetEl) return;\n//\n// const doc = win.document;\n//\n// if (pos === 'innerHtml') {\n// targetEl.innerHTML = res !== undefined && res !== null ? String(res) : '';\n// return;\n// }\n//\n// if (pos === 'innerText') {\n// if (targetEl.innerText !== undefined) {\n// targetEl.innerText = res !== undefined && res !== null ? String(res) : '';\n// }\n// return;\n// }\n//\n// const isShadowRoot = targetEl instanceof win.ShadowRoot;\n// const nodes = normalizeNodes(res, doc);\n// if (pos === 'replace') {\n// if (!isShadowRoot) targetEl.replaceWith(...nodes);\n// } else if (pos === 'replaceChildren') {\n// targetEl.replaceChildren(...nodes);\n// } else {\n// if (pos === 'beforeEnd') targetEl.append(...nodes);\n// else if (pos === 'afterBegin') targetEl.prepend(...nodes);\n// else if (pos === 'beforeBegin' && !isShadowRoot) targetEl.before(...nodes);\n// else if (pos === 'afterEnd' && !isShadowRoot) targetEl.after(...nodes);\n// }\n// };\n\nconst applyToDom = (swcId: string, id: string, pos: ApplySlotPosition, nodes: Node[]) => {\n const nodeSlot = new NodeSlot(this, swcId);\n if (pos === 'replaceChildrenText' || pos === 'replaceChildren' || pos === 'replaceChildrenHtml') {\n nodeSlot.replaceChildren(id, ...nodes);\n } else if (pos === 'appendHtml' || pos === 'append' || pos === 'appendText') {\n nodeSlot.append(id, ...nodes);\n } else if (pos === 'prependHtml' || pos === 'prepend' || pos === 'prependText') {\n nodeSlot.prepend(id, ...nodes);\n } else if (pos === 'clear') {\n nodeSlot.clear(id);\n }\n}\n/**\n * @applyNode decorator to surgically add/replace nodes to a target element.\n */\nexport function applySlot(targetId: string, opt: OptionalType<ApplySlotOptions, 'position'>): MethodDecorator {\n return (targetObj: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<any>) => {\n\n\n const options: ApplySlotOptions = {position: 'replaceChildrenHtml', ...opt};\n\n\n const constructor = targetObj.constructor;\n let metaList = ReflectUtils.getOwnMetadata(APPLY_SLOT_METADATA_KEY, constructor) as ApplySlotMetadata[];\n if (!metaList) {\n metaList = []\n ReflectUtils.defineMetadata(APPLY_SLOT_METADATA_KEY, metaList, constructor);\n }\n metaList.push({propertyKey, targetId, options});\n\n\n const original = descriptor.value;\n descriptor.value = function (...args: any[]) {\n ensureInit(this);\n\n const conf = getElementConfig(this);\n const currentWin = conf.window;\n const swcId = this._swcId;\n const currentDoc = currentWin.document;\n const hostSet = SwcUtils.getHelperAndHostSet(currentWin, this);\n const pos = options.position;\n\n const resToNodes = (res: string | Node) => {\n const nodes: Node[] = [];\n\n if (typeof res === 'string' && (pos === 'replaceChildrenHtml' || pos === 'appendHtml' || pos === 'prependHtml')) {\n const t = currentWin.document.createElement('template');\n t.innerHTML = res;\n nodes.push(...Array.from(t.content.childNodes));\n } else if (typeof res === 'string' && (pos === 'replaceChildrenText' || pos === 'prependText' || pos === 'appendText')) {\n nodes.push(currentWin.document.createTextNode(res));\n } else if (typeof res === 'object') {\n nodes.push(res);\n }\n SwcUtils.projectProcessHtml(swcId, nodes, currentDoc);\n return nodes;\n }\n\n const fallbackNodes: Node[] = [];\n if (options.fallback) {\n const res: string | Node = options.fallback.call(this, hostSet);\n const nodes: Node[] = resToNodes(res);\n fallbackNodes.push(...nodes);\n applyToDom(swcId, targetId, options.position, nodes);\n }\n\n let res = original.apply(this, args);\n if (res instanceof Promise) {\n return res.then(asyncRes => {\n const nodes = resToNodes(asyncRes)\n fallbackNodes.forEach((it: any)=>it.remove());\n applyToDom(swcId, targetId, options.position, nodes);\n })\n } else {\n const nodes: Node[] = resToNodes(res);\n applyToDom(swcId, targetId, options.position, nodes);\n }\n };\n };\n}\n\n// export const findAllApplySlotMetadata = (target: any): Map<string | symbol, ApplySlotMetadata> => {\nexport const findAllApplySlotMetadata = (target: any): ApplySlotMetadata[] => {\n const constructor = target instanceof Function ? target : target.constructor;\n return ReflectUtils.getMetadata(APPLY_SLOT_METADATA_KEY, constructor);\n};\n\nexport function applySlotClear(targetId: string): MethodDecorator {\n return applySlot(targetId, {position: 'clear'});\n}\n\nexport function applySlotPrependHtml(targetId: string): MethodDecorator {\n return applySlot(targetId, {position: 'prependHtml'});\n}\n\nexport const applySlotPrepend = applySlotPrependHtml;\n\nexport function applySlotPrependText(targetId: string): MethodDecorator {\n return applySlot(targetId, {position: 'prependText'});\n}\n\nexport function applySlotAppendHtml(targetId: string): MethodDecorator {\n return applySlot(targetId, {position: 'appendHtml'});\n}\n\nexport function applySlotAppendText(targetId: string): MethodDecorator {\n return applySlot(targetId, {position: 'appendText'});\n}\n\nexport const applySlotAppend = applySlotAppendHtml;\n\nexport function applySlotReplaceChildrenHtml(targetId: string): MethodDecorator {\n return applySlot(targetId, {position: 'replaceChildrenHtml'});\n}\n\nexport const applySlotReplaceChildren = applySlotReplaceChildrenHtml;\n\nexport function applySlotReplaceChildrenText(targetId: string): MethodDecorator {\n return applySlot(targetId, {position: 'replaceChildrenText'});\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAyC;AACzC,2BAA2C;AAC3C,mBAAuB;AACvB,sBAAuB;AAmChB,MAAM,0BAA0B,OAAO,IAAI,iCAAiC;AAyCnF,MAAM,aAAa,CAAC,OAAe,IAAY,KAAwB,UAAkB;AACvF,QAAM,WAAW,IAAI,yBAAS,QAAM,KAAK;AACzC,MAAI,QAAQ,yBAAyB,QAAQ,qBAAqB,QAAQ,uBAAuB;AAC/F,aAAS,gBAAgB,IAAI,GAAG,KAAK;AAAA,EACvC,WAAW,QAAQ,gBAAgB,QAAQ,YAAY,QAAQ,cAAc;AAC3E,aAAS,OAAO,IAAI,GAAG,KAAK;AAAA,EAC9B,WAAW,QAAQ,iBAAiB,QAAQ,aAAa,QAAQ,eAAe;AAC9E,aAAS,QAAQ,IAAI,GAAG,KAAK;AAAA,EAC/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AEO,MAAM,2BAA2B;AAEjC,SAAS,6BAA6B,UAAmC;AAC9E,SAAO,UAAU,UAAU,EAAC,UAAU,sBAAqB,CAAC;AAC9D;",
|
|
6
|
+
"names": ["res"]
|
|
7
7
|
}
|
|
@@ -38,7 +38,6 @@ var import_Inject = require("@dooboostore/simple-boot/decorators/inject/Inject")
|
|
|
38
38
|
var import_types = require("../types");
|
|
39
39
|
var import_core_web = require("@dooboostore/core-web");
|
|
40
40
|
var import_SwcAppMixin = require("../elements/SwcAppMixin");
|
|
41
|
-
var import_applySlot = require("./applySlot");
|
|
42
41
|
var import_state = require("./state");
|
|
43
42
|
const ELEMENT_CONFIG_KEY = Symbol.for("simple-web-component:element-config");
|
|
44
43
|
const getElementConfig = (target) => {
|
|
@@ -71,12 +70,6 @@ const ensureInit = (inst) => {
|
|
|
71
70
|
delete inst[meta.propertyKey];
|
|
72
71
|
});
|
|
73
72
|
}
|
|
74
|
-
const slotAllList = (0, import_applySlot.findAllApplySlotMetadata)(target);
|
|
75
|
-
if (slotAllList) {
|
|
76
|
-
slotAllList.filter((it) => it.type === "property").forEach((meta) => {
|
|
77
|
-
delete inst[meta.propertyKey];
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
73
|
const stateAllList = (0, import_state.findAllStateMetadata)(target);
|
|
81
74
|
if (stateAllList) {
|
|
82
75
|
stateAllList.forEach((meta) => {
|