@dooboostore/simple-web-component 1.0.38 → 1.0.40
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/LICENSE.md +7 -0
- package/README.md +88 -871
- package/dist/cjs/SwcAppEngine.js.map +2 -2
- package/dist/cjs/decorators/applyAttribute.js +194 -111
- package/dist/cjs/decorators/applyAttribute.js.map +2 -2
- package/dist/cjs/decorators/applyNode.js +82 -80
- package/dist/cjs/decorators/applyNode.js.map +2 -2
- package/dist/cjs/decorators/applyProperty.js +213 -0
- package/dist/cjs/decorators/applyProperty.js.map +7 -0
- package/dist/cjs/decorators/applySlot.js +93 -82
- package/dist/cjs/decorators/applySlot.js.map +3 -3
- package/dist/cjs/decorators/changedAttributeThis.js.map +1 -1
- package/dist/cjs/decorators/elementDefine.js +14 -34
- package/dist/cjs/decorators/elementDefine.js.map +2 -2
- package/dist/cjs/decorators/index.js +2 -2
- package/dist/cjs/decorators/index.js.map +2 -2
- package/dist/cjs/decorators/lifecycles.js +4 -4
- package/dist/cjs/decorators/lifecycles.js.map +2 -2
- package/dist/cjs/decorators/state.js +0 -1
- package/dist/cjs/decorators/state.js.map +2 -2
- package/dist/cjs/elements/SwcApp.js.map +2 -2
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/esm/SwcAppEngine.js.map +2 -2
- package/dist/esm/decorators/applyAttribute.js +196 -113
- package/dist/esm/decorators/applyAttribute.js.map +2 -2
- package/dist/esm/decorators/applyNode.js +82 -80
- package/dist/esm/decorators/applyNode.js.map +2 -2
- package/dist/esm/decorators/applyProperty.js +194 -0
- package/dist/esm/decorators/applyProperty.js.map +7 -0
- package/dist/esm/decorators/applySlot.js +93 -82
- package/dist/esm/decorators/applySlot.js.map +3 -3
- package/dist/esm/decorators/changedAttributeThis.js.map +1 -1
- package/dist/esm/decorators/elementDefine.js +14 -34
- package/dist/esm/decorators/elementDefine.js.map +2 -2
- package/dist/esm/decorators/index.js +2 -2
- package/dist/esm/decorators/index.js.map +1 -1
- package/dist/esm/decorators/lifecycles.js +4 -4
- package/dist/esm/decorators/lifecycles.js.map +2 -2
- package/dist/esm/decorators/state.js +0 -1
- package/dist/esm/decorators/state.js.map +2 -2
- package/dist/esm/elements/SwcApp.js.map +2 -2
- package/dist/esm/types/index.js.map +1 -1
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +525 -513
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
- package/dist/types/SwcAppEngine.d.ts.map +1 -1
- package/dist/types/decorators/applyAttribute.d.ts +56 -15
- package/dist/types/decorators/applyAttribute.d.ts.map +1 -1
- package/dist/types/decorators/applyNode.d.ts +28 -24
- package/dist/types/decorators/applyNode.d.ts.map +1 -1
- package/dist/types/decorators/applyProperty.d.ts +61 -0
- package/dist/types/decorators/applyProperty.d.ts.map +1 -0
- package/dist/types/decorators/applySlot.d.ts +17 -15
- package/dist/types/decorators/applySlot.d.ts.map +1 -1
- package/dist/types/decorators/elementDefine.d.ts.map +1 -1
- package/dist/types/decorators/index.d.ts +2 -2
- package/dist/types/decorators/index.d.ts.map +1 -1
- package/dist/types/decorators/lifecycles.d.ts +4 -4
- package/dist/types/decorators/lifecycles.d.ts.map +1 -1
- package/dist/types/decorators/state.d.ts.map +1 -1
- package/dist/types/elements/SwcApp.d.ts.map +1 -1
- package/dist/types/types/index.d.ts +1 -6
- package/dist/types/types/index.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +525 -513
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +1 -1
- package/src/SwcAppEngine.ts +1 -0
- package/src/decorators/applyAttribute.ts +311 -126
- package/src/decorators/applyNode.ts +108 -105
- package/src/decorators/applyProperty.ts +302 -0
- package/src/decorators/applySlot.ts +112 -94
- package/src/decorators/changedAttributeThis.ts +1 -1
- package/src/decorators/elementDefine.ts +44 -33
- package/src/decorators/index.ts +2 -3
- package/src/decorators/lifecycles.ts +6 -6
- package/src/decorators/state.ts +0 -1
- package/src/elements/SwcApp.ts +0 -1
- package/src/types/index.ts +7 -7
- package/dist/cjs/decorators/attribute.js +0 -187
- package/dist/cjs/decorators/attribute.js.map +0 -7
- package/dist/cjs/decorators/setProperty.js +0 -109
- package/dist/cjs/decorators/setProperty.js.map +0 -7
- package/dist/esm/decorators/attribute.js +0 -168
- package/dist/esm/decorators/attribute.js.map +0 -7
- package/dist/esm/decorators/setProperty.js +0 -90
- package/dist/esm/decorators/setProperty.js.map +0 -7
- package/dist/types/decorators/attribute.d.ts +0 -31
- package/dist/types/decorators/attribute.d.ts.map +0 -1
- package/dist/types/decorators/setProperty.d.ts +0 -17
- package/dist/types/decorators/setProperty.d.ts.map +0 -1
- package/src/decorators/attribute.ts +0 -223
- package/src/decorators/setProperty.ts +0 -112
|
@@ -3,108 +3,119 @@ import { ensureInit, getElementConfig } from "./elementDefine.js";
|
|
|
3
3
|
import { SwcUtils } from "../utils/Utils.js";
|
|
4
4
|
import { NodeSlot } from "@dooboostore/core-web";
|
|
5
5
|
const APPLY_SLOT_METADATA_KEY = Symbol.for("simple-web-component:apply-slot");
|
|
6
|
-
|
|
6
|
+
const applyToDom = (swcId, id, pos, nodes) => {
|
|
7
|
+
const nodeSlot = new NodeSlot(void 0, swcId);
|
|
8
|
+
if (pos === "replaceChildrenText" || pos === "replaceChildren" || pos === "replaceChildrenHtml") {
|
|
9
|
+
nodeSlot.replaceChildren(id, ...nodes);
|
|
10
|
+
} else if (pos === "appendHtml" || pos === "append" || pos === "appendText") {
|
|
11
|
+
nodeSlot.append(id, ...nodes);
|
|
12
|
+
} else if (pos === "prependHtml" || pos === "prepend" || pos === "prependText") {
|
|
13
|
+
nodeSlot.prepend(id, ...nodes);
|
|
14
|
+
} else if (pos === "clear") {
|
|
15
|
+
nodeSlot.clear(id);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
function applySlot(targetId, opt) {
|
|
7
19
|
return (targetObj, propertyKey, descriptor) => {
|
|
8
|
-
const
|
|
9
|
-
if (type === "property") {
|
|
10
|
-
Object.defineProperty(targetObj, propertyKey, {
|
|
11
|
-
get() {
|
|
12
|
-
const nodeSlot = new NodeSlot(this, `${this._swcId}-${id}`);
|
|
13
|
-
return nodeSlot;
|
|
14
|
-
},
|
|
15
|
-
set(nv) {
|
|
16
|
-
if (nv) {
|
|
17
|
-
} else {
|
|
18
|
-
const nodeSlot = new NodeSlot(this, `${this._swcId}-${id}`);
|
|
19
|
-
nodeSlot.clear();
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
configurable: true,
|
|
23
|
-
enumerable: true
|
|
24
|
-
});
|
|
25
|
-
}
|
|
20
|
+
const options = { position: "replaceChildren", ...opt };
|
|
26
21
|
const constructor = targetObj.constructor;
|
|
27
22
|
let metaList = ReflectUtils.getOwnMetadata(APPLY_SLOT_METADATA_KEY, constructor);
|
|
28
23
|
if (!metaList) {
|
|
29
24
|
metaList = [];
|
|
30
25
|
ReflectUtils.defineMetadata(APPLY_SLOT_METADATA_KEY, metaList, constructor);
|
|
31
26
|
}
|
|
32
|
-
metaList.push({ propertyKey,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
} else if (pos === "appendText") {
|
|
53
|
-
nodeSlot.appendText(id, res);
|
|
54
|
-
} else if (pos === "prependHtml") {
|
|
55
|
-
nodeSlot.prependHtml(id, res);
|
|
56
|
-
} else if (pos === "prependText") {
|
|
57
|
-
nodeSlot.prependText(id, res);
|
|
58
|
-
} else if (pos === "clear") {
|
|
59
|
-
nodeSlot.clear(id);
|
|
60
|
-
}
|
|
27
|
+
metaList.push({ propertyKey, targetId, options });
|
|
28
|
+
const original = descriptor.value;
|
|
29
|
+
descriptor.value = function(...args) {
|
|
30
|
+
ensureInit(this);
|
|
31
|
+
const conf = getElementConfig(this);
|
|
32
|
+
const currentWin = conf.window;
|
|
33
|
+
const swcId = this._swcId;
|
|
34
|
+
const currentDoc = currentWin.document;
|
|
35
|
+
const hostSet = SwcUtils.getHelperAndHostSet(currentWin, this);
|
|
36
|
+
const pos = options.position;
|
|
37
|
+
const resToNodes = (res2) => {
|
|
38
|
+
const nodes = [];
|
|
39
|
+
if (typeof res2 === "string" && (pos === "replaceChildrenHtml" || pos === "appendHtml" || pos === "prependHtml")) {
|
|
40
|
+
const t = currentWin.document.createElement("template");
|
|
41
|
+
t.innerHTML = res2;
|
|
42
|
+
nodes.push(...Array.from(t.content.childNodes));
|
|
43
|
+
} else if (typeof res2 === "string" && (pos === "replaceChildrenText" || pos === "prependText" || pos === "appendText")) {
|
|
44
|
+
nodes.push(currentWin.document.createTextNode(res2));
|
|
45
|
+
} else if (typeof res2 === "object") {
|
|
46
|
+
nodes.push(res2);
|
|
61
47
|
}
|
|
62
|
-
|
|
48
|
+
SwcUtils.projectProcessHtml(swcId, nodes, currentDoc);
|
|
49
|
+
return nodes;
|
|
63
50
|
};
|
|
64
|
-
|
|
51
|
+
const fallbackNodes = [];
|
|
52
|
+
if (options.fallback) {
|
|
53
|
+
const res2 = options.fallback.call(this, hostSet);
|
|
54
|
+
const nodes = resToNodes(res2);
|
|
55
|
+
fallbackNodes.push(...nodes);
|
|
56
|
+
applyToDom(swcId, targetId, options.position, nodes);
|
|
57
|
+
}
|
|
58
|
+
let res = original.apply(this, args);
|
|
59
|
+
if (res instanceof Promise) {
|
|
60
|
+
return res.then((asyncRes) => {
|
|
61
|
+
const nodes = resToNodes(asyncRes);
|
|
62
|
+
fallbackNodes.forEach((it) => it.remove());
|
|
63
|
+
applyToDom(swcId, targetId, options.position, nodes);
|
|
64
|
+
});
|
|
65
|
+
} else {
|
|
66
|
+
const nodes = resToNodes(res);
|
|
67
|
+
applyToDom(swcId, targetId, options.position, nodes);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
65
70
|
};
|
|
66
71
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return ReflectUtils.getMetadata(APPLY_SLOT_METADATA_KEY, constructor);
|
|
70
|
-
};
|
|
71
|
-
function applySlotClear(id) {
|
|
72
|
-
return applySlot(id, { position: "clear" });
|
|
72
|
+
function clearSlot(targetId) {
|
|
73
|
+
return applySlot(targetId, { position: "clear" });
|
|
73
74
|
}
|
|
74
|
-
function
|
|
75
|
-
return applySlot(
|
|
75
|
+
function prependHtmlSlot(targetId) {
|
|
76
|
+
return applySlot(targetId, { position: "prependHtml" });
|
|
76
77
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
return applySlot(id, { position: "prependText" });
|
|
78
|
+
function prependSlot(targetId) {
|
|
79
|
+
return applySlot(targetId, { position: "prepend" });
|
|
80
80
|
}
|
|
81
|
-
function
|
|
82
|
-
return applySlot(
|
|
81
|
+
function prependTextSlot(targetId) {
|
|
82
|
+
return applySlot(targetId, { position: "prependText" });
|
|
83
83
|
}
|
|
84
|
-
function
|
|
85
|
-
return applySlot(
|
|
84
|
+
function appendHtmlSlot(targetId) {
|
|
85
|
+
return applySlot(targetId, { position: "appendHtml" });
|
|
86
86
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
return applySlot(id, { position: "replaceChildrenHtml" });
|
|
87
|
+
function appendTextSlot(targetId) {
|
|
88
|
+
return applySlot(targetId, { position: "appendText" });
|
|
90
89
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
return applySlot(id, { position: "replaceChildrenText" });
|
|
90
|
+
function appendSlot(targetId) {
|
|
91
|
+
return applySlot(targetId, { position: "append" });
|
|
94
92
|
}
|
|
93
|
+
function replaceChildrenHtmlSlot(targetId) {
|
|
94
|
+
return applySlot(targetId, { position: "replaceChildrenHtml" });
|
|
95
|
+
}
|
|
96
|
+
function replaceChildrenSlot(targetId) {
|
|
97
|
+
return applySlot(targetId, { position: "replaceChildren" });
|
|
98
|
+
}
|
|
99
|
+
function replaceChildrenTextSlot(targetId) {
|
|
100
|
+
return applySlot(targetId, { position: "replaceChildrenText" });
|
|
101
|
+
}
|
|
102
|
+
const findAllApplySlotMetadata = (target) => {
|
|
103
|
+
const constructor = target instanceof Function ? target : target.constructor;
|
|
104
|
+
return ReflectUtils.getMetadata(APPLY_SLOT_METADATA_KEY, constructor);
|
|
105
|
+
};
|
|
95
106
|
export {
|
|
96
107
|
APPLY_SLOT_METADATA_KEY,
|
|
108
|
+
appendHtmlSlot,
|
|
109
|
+
appendSlot,
|
|
110
|
+
appendTextSlot,
|
|
97
111
|
applySlot,
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
applySlotReplaceChildrenHtml,
|
|
107
|
-
applySlotReplaceChildrenText,
|
|
108
|
-
findAllApplySlotMetadata
|
|
112
|
+
clearSlot,
|
|
113
|
+
findAllApplySlotMetadata,
|
|
114
|
+
prependHtmlSlot,
|
|
115
|
+
prependSlot,
|
|
116
|
+
prependTextSlot,
|
|
117
|
+
replaceChildrenHtmlSlot,
|
|
118
|
+
replaceChildrenSlot,
|
|
119
|
+
replaceChildrenTextSlot
|
|
109
120
|
};
|
|
110
121
|
//# 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,
|
|
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/**\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: 'replaceChildren', ...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\nexport function clearSlot(targetId: string): MethodDecorator {\n return applySlot(targetId, {position: 'clear'});\n}\n\nexport function prependHtmlSlot(targetId: string): MethodDecorator {\n return applySlot(targetId, {position: 'prependHtml'});\n}\n\nexport function prependSlot(targetId: string): MethodDecorator {\n return applySlot(targetId, {position: 'prepend'});\n}\n\nexport function prependTextSlot(targetId: string): MethodDecorator {\n return applySlot(targetId, {position: 'prependText'});\n}\n\nexport function appendHtmlSlot(targetId: string): MethodDecorator {\n return applySlot(targetId, {position: 'appendHtml'});\n}\n\nexport function appendTextSlot(targetId: string): MethodDecorator {\n return applySlot(targetId, {position: 'appendText'});\n}\n\nexport function appendSlot(targetId: string): MethodDecorator {\n return applySlot(targetId, {position: 'append'});\n}\n\nexport function replaceChildrenHtmlSlot(targetId: string): MethodDecorator {\n return applySlot(targetId, {position: 'replaceChildrenHtml'});\n}\n\nexport function replaceChildrenSlot(targetId: string): MethodDecorator {\n return applySlot(targetId, {position: 'replaceChildren'});\n}\n\nexport function replaceChildrenTextSlot(targetId: string): MethodDecorator {\n return applySlot(targetId, {position: 'replaceChildrenText'});\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};"],
|
|
5
|
+
"mappings": "AAAA,SAAsB,oBAAmB;AACzC,SAAQ,YAAY,wBAAuB;AAC3C,SAAQ,gBAAe;AACvB,SAAQ,gBAAe;AAmChB,MAAM,0BAA0B,OAAO,IAAI,iCAAiC;AAyCnF,MAAM,aAAa,CAAC,OAAe,IAAY,KAAwB,UAAkB;AACvF,QAAM,WAAW,IAAI,SAAS,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/B,WAAW,QAAQ,SAAS;AAC1B,aAAS,MAAM,EAAE;AAAA,EACnB;AACF;AAKO,SAAS,UAAU,UAAkB,KAAkE;AAC5G,SAAO,CAAC,WAAmB,aAA8B,eAA6C;AAGpG,UAAM,UAA4B,EAAC,UAAU,m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BAA2B,CAAC,WAAqC;AAC5E,QAAM,cAAc,kBAAkB,WAAW,SAAS,OAAO;AACjE,SAAO,aAAa,YAAY,yBAAyB,WAAW;AACtE;",
|
|
6
|
+
"names": ["res"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/decorators/changedAttributeThis.ts"],
|
|
4
|
-
"sourcesContent": ["import { ReflectUtils } from '@dooboostore/core';\n\nexport const ON_ATTRIBUTE_CHANGED_METADATA_KEY = Symbol.for('simple-web-component:on-attribute-changed');\n\nexport interface ChangedAttributeThisOptions
|
|
4
|
+
"sourcesContent": ["import { ReflectUtils } from '@dooboostore/core';\n\nexport const ON_ATTRIBUTE_CHANGED_METADATA_KEY = Symbol.for('simple-web-component:on-attribute-changed');\n\nexport interface ChangedAttributeThisOptions {\n type?: typeof Number | typeof Boolean | typeof String;\n while?: 'connected';\n}\n\nexport interface ChangedAttributeThisMetadata {\n attributeName: string;\n propertyKey: string | symbol;\n options: ChangedAttributeThisOptions;\n}\n\nconst convertValue = (val: any, type: any): any => {\n if (val === null || val === undefined) return val;\n if (type === Number) return Number(val);\n if (type === Boolean) return val === 'false' || val === '0' ? false : true;\n return val;\n};\n\n/**\n * @changedAttributeThis decorator - fires when any attribute on $this changes\n */\nexport function changedAttributeThis(attributeName?: string, options: ChangedAttributeThisOptions = {}): MethodDecorator {\n return (target: Object, propertyKey: string | symbol) => {\n const constructor = target.constructor;\n let metaList = ReflectUtils.getOwnMetadata(ON_ATTRIBUTE_CHANGED_METADATA_KEY, constructor) as ChangedAttributeThisMetadata[];\n if (!metaList) {\n metaList = [];\n ReflectUtils.defineMetadata(ON_ATTRIBUTE_CHANGED_METADATA_KEY, metaList, constructor);\n }\n\n const name = attributeName || String(propertyKey);\n metaList.push({\n attributeName: name,\n propertyKey,\n options\n });\n };\n}\n\nexport const getChangedAttributeMetadata = (target: any): ChangedAttributeThisMetadata[] | undefined => {\n const constructor = target instanceof Function ? target : target.constructor;\n return ReflectUtils.getMetadata(ON_ATTRIBUTE_CHANGED_METADATA_KEY, constructor);\n};\n\nexport const findAllAttributeChangedMetadata = (target: any): Map<string, ChangedAttributeThisMetadata[]> => {\n const constructor = target instanceof Function ? target : target.constructor;\n const metaList = ReflectUtils.findAllMetadata<ChangedAttributeThisMetadata[]>(ON_ATTRIBUTE_CHANGED_METADATA_KEY, constructor) || [];\n\n const result = new Map<string, ChangedAttributeThisMetadata[]>();\n metaList.forEach(meta => {\n meta.forEach(item => {\n if (!result.has(item.attributeName)) {\n result.set(item.attributeName, []);\n }\n result.get(item.attributeName)!.push(item);\n });\n });\n return result;\n};\n\nexport const convertAttributeValue = (val: any, type?: typeof Number | typeof Boolean | typeof String): any => {\n return convertValue(val, type);\n};\n"],
|
|
5
5
|
"mappings": "AAAA,SAAS,oBAAoB;AAEtB,MAAM,oCAAoC,OAAO,IAAI,2CAA2C;AAavG,MAAM,eAAe,CAAC,KAAU,SAAmB;AACjD,MAAI,QAAQ,QAAQ,QAAQ,OAAW,QAAO;AAC9C,MAAI,SAAS,OAAQ,QAAO,OAAO,GAAG;AACtC,MAAI,SAAS,QAAS,QAAO,QAAQ,WAAW,QAAQ,MAAM,QAAQ;AACtE,SAAO;AACT;AAKO,SAAS,qBAAqB,eAAwB,UAAuC,CAAC,GAAoB;AACvH,SAAO,CAAC,QAAgB,gBAAiC;AACvD,UAAM,cAAc,OAAO;AAC3B,QAAI,WAAW,aAAa,eAAe,mCAAmC,WAAW;AACzF,QAAI,CAAC,UAAU;AACb,iBAAW,CAAC;AACZ,mBAAa,eAAe,mCAAmC,UAAU,WAAW;AAAA,IACtF;AAEA,UAAM,OAAO,iBAAiB,OAAO,WAAW;AAChD,aAAS,KAAK;AAAA,MACZ,eAAe;AAAA,MACf;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH;AACF;AAEO,MAAM,8BAA8B,CAAC,WAA4D;AACtG,QAAM,cAAc,kBAAkB,WAAW,SAAS,OAAO;AACjE,SAAO,aAAa,YAAY,mCAAmC,WAAW;AAChF;AAEO,MAAM,kCAAkC,CAAC,WAA6D;AAC3G,QAAM,cAAc,kBAAkB,WAAW,SAAS,OAAO;AACjE,QAAM,WAAW,aAAa,gBAAgD,mCAAmC,WAAW,KAAK,CAAC;AAElI,QAAM,SAAS,oBAAI,IAA4C;AAC/D,WAAS,QAAQ,UAAQ;AACvB,SAAK,QAAQ,UAAQ;AACnB,UAAI,CAAC,OAAO,IAAI,KAAK,aAAa,GAAG;AACnC,eAAO,IAAI,KAAK,eAAe,CAAC,CAAC;AAAA,MACnC;AACA,aAAO,IAAI,KAAK,aAAa,EAAG,KAAK,IAAI;AAAA,IAC3C,CAAC;AAAA,EACH,CAAC;AACD,SAAO;AACT;AAEO,MAAM,wBAAwB,CAAC,KAAU,SAA+D;AAC7G,SAAO,aAAa,KAAK,IAAI;AAC/B;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -3,18 +3,17 @@ import { getAddEventListenerMetadata } from "./addEventListener.js";
|
|
|
3
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.js";
|
|
4
4
|
import { getEmitCustomEventMetadataList } from "./emitCustomEvent.js";
|
|
5
5
|
import { convertAttributeValue, findAllAttributeChangedMetadata } from "./changedAttributeThis.js";
|
|
6
|
-
import { findAllAttributeApplyMetadata } from "./applyAttribute.js";
|
|
7
|
-
import { findAllAttributeMetadata, getAttributeValue } from "./attribute.js";
|
|
6
|
+
import { findAllAttributeApplyMetadata, findAllAttributeMetadata, getAttributeValue } from "./applyAttribute.js";
|
|
8
7
|
import { getQueryMetadata } from "./query.js";
|
|
9
8
|
import { getQueryAllMetadata } from "./queryAll.js";
|
|
10
9
|
import { SwcUtils } from "../utils/Utils.js";
|
|
11
10
|
import { DOM_EVENT_NAMES, HTML_TAG_ENTRIES } from "../config/config.js";
|
|
12
11
|
import { SituationTypeContainer, SituationTypeContainers } from "@dooboostore/simple-boot/decorators/inject/Inject";
|
|
13
12
|
import { InjectSituationType } from "../types/index.js";
|
|
14
|
-
import { ConvertUtils, ElementApply
|
|
13
|
+
import { ConvertUtils, ElementApply } from "@dooboostore/core-web";
|
|
15
14
|
import { isSSR } from "../elements/SwcAppMixin.js";
|
|
16
|
-
import { findAllApplySlotMetadata } from "./applySlot.js";
|
|
17
15
|
import { findAllStateMetadata } from "./state.js";
|
|
16
|
+
import { findAllPropertyMetadata } from "./applyProperty.js";
|
|
18
17
|
const ELEMENT_CONFIG_KEY = Symbol.for("simple-web-component:element-config");
|
|
19
18
|
const getElementConfig = (target) => {
|
|
20
19
|
const constructor = target instanceof Function ? target : target.constructor;
|
|
@@ -27,13 +26,12 @@ const ensureInit = (inst) => {
|
|
|
27
26
|
inst._boundListeners = [];
|
|
28
27
|
inst.__swc_initialized = true;
|
|
29
28
|
const target = inst instanceof Function ? inst : inst.constructor;
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
});
|
|
29
|
+
const attributeAllList = findAllAttributeMetadata(target).filter((it) => it.type === "property");
|
|
30
|
+
if (attributeAllList) {
|
|
31
|
+
attributeAllList.forEach((meta) => {
|
|
32
|
+
delete inst[meta.propertyKey];
|
|
33
|
+
});
|
|
34
|
+
}
|
|
37
35
|
const queryList = getQueryMetadata(target);
|
|
38
36
|
if (queryList) {
|
|
39
37
|
queryList.forEach((meta) => {
|
|
@@ -46,9 +44,9 @@ const ensureInit = (inst) => {
|
|
|
46
44
|
delete inst[meta.propertyKey];
|
|
47
45
|
});
|
|
48
46
|
}
|
|
49
|
-
const
|
|
50
|
-
if (
|
|
51
|
-
|
|
47
|
+
const propertyAllList = findAllPropertyMetadata(target).filter((it) => it.type === "property");
|
|
48
|
+
if (propertyAllList) {
|
|
49
|
+
propertyAllList.forEach((meta) => {
|
|
52
50
|
delete inst[meta.propertyKey];
|
|
53
51
|
});
|
|
54
52
|
}
|
|
@@ -105,24 +103,6 @@ const getHandlers = (inst) => {
|
|
|
105
103
|
const setupPrototype = (proto, win) => {
|
|
106
104
|
if (proto.__swc_proto_setup) return;
|
|
107
105
|
proto.__swc_proto_setup = true;
|
|
108
|
-
proto.createSlotString = function(id) {
|
|
109
|
-
return NodeSlot.slot(`${this._swcId}-${id}`);
|
|
110
|
-
};
|
|
111
|
-
proto.createEaHtml = function(id, script) {
|
|
112
|
-
return ElementApply.html(id, script);
|
|
113
|
-
};
|
|
114
|
-
proto.createEaText = function(id, script) {
|
|
115
|
-
return ElementApply.text(id, script);
|
|
116
|
-
};
|
|
117
|
-
proto.createEaAttribute = function(id, name, script) {
|
|
118
|
-
return ElementApply.attribute(id, name, script);
|
|
119
|
-
};
|
|
120
|
-
proto.createEaEvent = function(id, name, script) {
|
|
121
|
-
return ElementApply.event(id, name, script);
|
|
122
|
-
};
|
|
123
|
-
proto.createEaProperty = function(id, name, script) {
|
|
124
|
-
return ElementApply.property(id, name, script);
|
|
125
|
-
};
|
|
126
106
|
proto._executeSwcScript = function(attrName, hostSet, extraArgs = {}) {
|
|
127
107
|
ensureInit(this);
|
|
128
108
|
const script = this.getAttribute(attrName);
|
|
@@ -252,8 +232,8 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
252
232
|
const applyAttributeMap = findAllAttributeApplyMetadata(constructor);
|
|
253
233
|
const swcLifecycleAttributes = ["swc-on-constructor", "swc-on-connected", "swc-on-disconnected", "swc-on-before-connected", "swc-on-after-connected", "swc-on-before-disconnected", "swc-on-after-disconnected", "swc-on-before-adopted", "swc-on-after-adopted", "swc-on-attribute-changed"];
|
|
254
234
|
const swcOnEvents = DOM_EVENT_NAMES.map((e) => `swc-on-${e}`);
|
|
255
|
-
const attributeApplyNames = Array.from(applyAttributeMap.values()).map((it) => it.
|
|
256
|
-
const hostAttributes = attributeList.filter((it) => it.selector === "$this").map((it) => it.
|
|
235
|
+
const attributeApplyNames = Array.from(applyAttributeMap.values()).map((it) => it.targetAttributeName).filter(Boolean);
|
|
236
|
+
const hostAttributes = attributeList.filter((it) => it.selector === "$this").map((it) => it.propertyKey || String(it.propertyKey));
|
|
257
237
|
const originalStaticObservedAttributes = constructor.observedAttributes ?? [];
|
|
258
238
|
const mergedObservedAttributes = [.../* @__PURE__ */ new Set([...metadata.observedAttributes ?? [], ...originalStaticObservedAttributes, ...attrChangeMap.keys(), ...attributeApplyNames, ...hostAttributes, ...emitHostCustomEventList.map((it) => it.options.attributeName).filter(Boolean), ...swcLifecycleAttributes, ...swcOnEvents])];
|
|
259
239
|
const proto = constructor.prototype;
|