@dooboostore/simple-web-component 1.0.0
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 +102 -0
- package/dist/cjs/bundle-entry.js +18 -0
- package/dist/cjs/bundle-entry.js.map +7 -0
- package/dist/cjs/decorators/attributeChanged.js +42 -0
- package/dist/cjs/decorators/attributeChanged.js.map +7 -0
- package/dist/cjs/decorators/element.js +183 -0
- package/dist/cjs/decorators/element.js.map +7 -0
- package/dist/cjs/decorators/style.js +34 -0
- package/dist/cjs/decorators/style.js.map +7 -0
- package/dist/cjs/decorators/template.js +34 -0
- package/dist/cjs/decorators/template.js.map +7 -0
- package/dist/cjs/index.js +21 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/package.json +5 -0
- package/dist/esm/bundle-entry.js +2 -0
- package/dist/esm/bundle-entry.js.map +7 -0
- package/dist/esm/decorators/attributeChanged.js +23 -0
- package/dist/esm/decorators/attributeChanged.js.map +7 -0
- package/dist/esm/decorators/element.js +164 -0
- package/dist/esm/decorators/element.js.map +7 -0
- package/dist/esm/decorators/style.js +15 -0
- package/dist/esm/decorators/style.js.map +7 -0
- package/dist/esm/decorators/template.js +15 -0
- package/dist/esm/decorators/template.js.map +7 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/index.js.map +7 -0
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +260 -0
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +7 -0
- package/dist/types/bundle-entry.d.ts +2 -0
- package/dist/types/bundle-entry.d.ts.map +1 -0
- package/dist/types/decorators/attributeChanged.d.ts +4 -0
- package/dist/types/decorators/attributeChanged.d.ts.map +1 -0
- package/dist/types/decorators/element.d.ts +11 -0
- package/dist/types/decorators/element.d.ts.map +1 -0
- package/dist/types/decorators/style.d.ts +4 -0
- package/dist/types/decorators/style.d.ts.map +1 -0
- package/dist/types/decorators/template.d.ts +4 -0
- package/dist/types/decorators/template.d.ts.map +1 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +284 -0
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +7 -0
- package/package.json +93 -0
- package/src/bundle-entry.ts +1 -0
- package/src/decorators/attributeChanged.ts +20 -0
- package/src/decorators/element.ts +201 -0
- package/src/decorators/style.ts +12 -0
- package/src/decorators/template.ts +14 -0
- package/src/index.ts +4 -0
- package/tsconfig.json +23 -0
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
var dooboostoreSimpleWebComponent = (() => {
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/bundle-entry.ts
|
|
21
|
+
var bundle_entry_exports = {};
|
|
22
|
+
__export(bundle_entry_exports, {
|
|
23
|
+
ATTRIBUTE_CHANGED_METADATA_KEY: () => ATTRIBUTE_CHANGED_METADATA_KEY,
|
|
24
|
+
ELEMENT_CONFIG_KEY: () => ELEMENT_CONFIG_KEY,
|
|
25
|
+
STYLE_METHOD_KEY: () => STYLE_METHOD_KEY,
|
|
26
|
+
TEMPLATE_METHOD_KEY: () => TEMPLATE_METHOD_KEY,
|
|
27
|
+
attributeChanged: () => attributeChanged,
|
|
28
|
+
element: () => element,
|
|
29
|
+
getAttributeChangedMap: () => getAttributeChangedMap,
|
|
30
|
+
getElementConfig: () => getElementConfig,
|
|
31
|
+
getStyleMethod: () => getStyleMethod,
|
|
32
|
+
getTemplateMethod: () => getTemplateMethod,
|
|
33
|
+
style: () => style,
|
|
34
|
+
template: () => template
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// ../core/dist/esm/reflect/ReflectUtils.js
|
|
38
|
+
var ReflectUtils;
|
|
39
|
+
((ReflectUtils2) => {
|
|
40
|
+
ReflectUtils2.getParameterTypes = (target, propertyKey) => {
|
|
41
|
+
if (propertyKey) {
|
|
42
|
+
return Reflect.getMetadata("design:paramtypes", target, propertyKey) || [];
|
|
43
|
+
} else {
|
|
44
|
+
return Reflect.getMetadata("design:paramtypes", target) || [];
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
ReflectUtils2.getReturnType = (target, propertyKey) => {
|
|
48
|
+
return Reflect.getMetadata("design:returntype", target, propertyKey);
|
|
49
|
+
};
|
|
50
|
+
ReflectUtils2.getType = (target, propertyKey) => {
|
|
51
|
+
if (propertyKey) {
|
|
52
|
+
return Reflect.getMetadata("design:type", target, propertyKey);
|
|
53
|
+
} else {
|
|
54
|
+
return Reflect.getMetadata("design:type", target);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
ReflectUtils2.getMetadata = (metadataKey, target, propertyKey) => {
|
|
58
|
+
if (propertyKey) {
|
|
59
|
+
return Reflect.getMetadata(metadataKey, target, propertyKey);
|
|
60
|
+
} else {
|
|
61
|
+
return Reflect.getMetadata(metadataKey, target);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
ReflectUtils2.getMetadataKeys = (target) => {
|
|
65
|
+
return Reflect.getMetadataKeys(target);
|
|
66
|
+
};
|
|
67
|
+
ReflectUtils2.getOwnMetadata = (metadataKey, target, propertyKey) => {
|
|
68
|
+
if (propertyKey) {
|
|
69
|
+
return Reflect.getOwnMetadata(metadataKey, target, propertyKey);
|
|
70
|
+
} else {
|
|
71
|
+
return Reflect.getOwnMetadata(metadataKey, target);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
ReflectUtils2.getMetadatas = (target) => {
|
|
75
|
+
return ReflectUtils2.getMetadataKeys(target).map((it) => ReflectUtils2.getMetadata(it, target));
|
|
76
|
+
};
|
|
77
|
+
ReflectUtils2.metadata = (metadataKey, data) => {
|
|
78
|
+
return Reflect.metadata(metadataKey, data);
|
|
79
|
+
};
|
|
80
|
+
ReflectUtils2.defineMetadata = (metadataKey, value, target, propertyKey) => {
|
|
81
|
+
if (propertyKey && Reflect.defineMetadata) {
|
|
82
|
+
Reflect.defineMetadata(metadataKey, value, target, propertyKey);
|
|
83
|
+
} else if (Reflect.defineMetadata) {
|
|
84
|
+
Reflect.defineMetadata(metadataKey, value, target);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
})(ReflectUtils || (ReflectUtils = {}));
|
|
88
|
+
|
|
89
|
+
// src/decorators/attributeChanged.ts
|
|
90
|
+
var ATTRIBUTE_CHANGED_METADATA_KEY = Symbol("simple-web-component:attribute-changed");
|
|
91
|
+
var attributeChanged = (attributeName) => {
|
|
92
|
+
return (target, propertyKey, descriptor) => {
|
|
93
|
+
const constructor = target.constructor;
|
|
94
|
+
let meta = ReflectUtils.getMetadata(ATTRIBUTE_CHANGED_METADATA_KEY, constructor);
|
|
95
|
+
if (!meta) {
|
|
96
|
+
meta = /* @__PURE__ */ new Map();
|
|
97
|
+
ReflectUtils.defineMetadata(ATTRIBUTE_CHANGED_METADATA_KEY, meta, constructor);
|
|
98
|
+
}
|
|
99
|
+
meta.set(attributeName, propertyKey);
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
var getAttributeChangedMap = (target) => {
|
|
103
|
+
const constructor = target instanceof Function ? target : target.constructor;
|
|
104
|
+
return ReflectUtils.getMetadata(ATTRIBUTE_CHANGED_METADATA_KEY, constructor);
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
// src/decorators/template.ts
|
|
108
|
+
var TEMPLATE_METHOD_KEY = Symbol("simple-web-component:template-method");
|
|
109
|
+
var template = (target, propertyKey, descriptor) => {
|
|
110
|
+
ReflectUtils.defineMetadata(TEMPLATE_METHOD_KEY, propertyKey, target.constructor);
|
|
111
|
+
};
|
|
112
|
+
var getTemplateMethod = (target) => {
|
|
113
|
+
const constructor = target instanceof Function ? target : target.constructor;
|
|
114
|
+
return ReflectUtils.getMetadata(TEMPLATE_METHOD_KEY, constructor);
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
// src/decorators/style.ts
|
|
118
|
+
var STYLE_METHOD_KEY = Symbol("simple-web-component:style-method");
|
|
119
|
+
var style = (target, propertyKey, descriptor) => {
|
|
120
|
+
ReflectUtils.defineMetadata(STYLE_METHOD_KEY, propertyKey, target.constructor);
|
|
121
|
+
};
|
|
122
|
+
var getStyleMethod = (target) => {
|
|
123
|
+
const constructor = target instanceof Function ? target : target.constructor;
|
|
124
|
+
return ReflectUtils.getMetadata(STYLE_METHOD_KEY, constructor);
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
// src/decorators/element.ts
|
|
128
|
+
var ELEMENT_CONFIG_KEY = Symbol("simple-web-component:element-config");
|
|
129
|
+
var BUILT_IN_TAG_MAP = /* @__PURE__ */ new Map();
|
|
130
|
+
var registerTag = (className, tagName) => {
|
|
131
|
+
if (typeof globalThis !== "undefined" && globalThis[className]) {
|
|
132
|
+
BUILT_IN_TAG_MAP.set(globalThis[className], tagName);
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
[
|
|
136
|
+
["HTMLAnchorElement", "a"],
|
|
137
|
+
["HTMLAreaElement", "area"],
|
|
138
|
+
["HTMLAudioElement", "audio"],
|
|
139
|
+
["HTMLBaseElement", "base"],
|
|
140
|
+
["HTMLButtonElement", "button"],
|
|
141
|
+
["HTMLCanvasElement", "canvas"],
|
|
142
|
+
["HTMLDataElement", "data"],
|
|
143
|
+
["HTMLDataListElement", "datalist"],
|
|
144
|
+
["HTMLDetailsElement", "details"],
|
|
145
|
+
["HTMLDialogElement", "dialog"],
|
|
146
|
+
["HTMLDivElement", "div"],
|
|
147
|
+
["HTMLDListElement", "dl"],
|
|
148
|
+
["HTMLEmbedElement", "embed"],
|
|
149
|
+
["HTMLFieldSetElement", "fieldset"],
|
|
150
|
+
["HTMLFormElement", "form"],
|
|
151
|
+
["HTMLHRElement", "hr"],
|
|
152
|
+
["HTMLIFrameElement", "iframe"],
|
|
153
|
+
["HTMLImageElement", "img"],
|
|
154
|
+
["HTMLInputElement", "input"],
|
|
155
|
+
["HTMLLabelElement", "label"],
|
|
156
|
+
["HTMLLegendElement", "legend"],
|
|
157
|
+
["HTMLLIElement", "li"],
|
|
158
|
+
["HTMLLinkElement", "link"],
|
|
159
|
+
["HTMLMapElement", "map"],
|
|
160
|
+
["HTMLMetaElement", "meta"],
|
|
161
|
+
["HTMLMeterElement", "meter"],
|
|
162
|
+
["HTMLModElement", "del"],
|
|
163
|
+
["HTMLObjectElement", "object"],
|
|
164
|
+
["HTMLOListElement", "ol"],
|
|
165
|
+
["HTMLOptGroupElement", "optgroup"],
|
|
166
|
+
["HTMLOptionElement", "option"],
|
|
167
|
+
["HTMLOutputElement", "output"],
|
|
168
|
+
["HTMLParagraphElement", "p"],
|
|
169
|
+
["HTMLParamElement", "param"],
|
|
170
|
+
["HTMLPictureElement", "picture"],
|
|
171
|
+
["HTMLPreElement", "pre"],
|
|
172
|
+
["HTMLProgressElement", "progress"],
|
|
173
|
+
["HTMLQuoteElement", "blockquote"],
|
|
174
|
+
["HTMLScriptElement", "script"],
|
|
175
|
+
["HTMLSelectElement", "select"],
|
|
176
|
+
["HTMLSlotElement", "slot"],
|
|
177
|
+
["HTMLSourceElement", "source"],
|
|
178
|
+
["HTMLSpanElement", "span"],
|
|
179
|
+
["HTMLStyleElement", "style"],
|
|
180
|
+
["HTMLTableElement", "table"],
|
|
181
|
+
["HTMLTableSectionElement", "tbody"],
|
|
182
|
+
["HTMLTableCellElement", "td"],
|
|
183
|
+
["HTMLTemplateElement", "template"],
|
|
184
|
+
["HTMLTextAreaElement", "textarea"],
|
|
185
|
+
["HTMLTimeElement", "time"],
|
|
186
|
+
["HTMLTitleElement", "title"],
|
|
187
|
+
["HTMLTableRowElement", "tr"],
|
|
188
|
+
["HTMLTrackElement", "track"],
|
|
189
|
+
["HTMLUListElement", "ul"],
|
|
190
|
+
["HTMLVideoElement", "video"],
|
|
191
|
+
["HTMLHeadingElement", "h1"]
|
|
192
|
+
].forEach(([cls, tag]) => registerTag(cls, tag));
|
|
193
|
+
var element = (inConfig) => (constructor) => {
|
|
194
|
+
const config = typeof inConfig === "string" ? { tagName: inConfig } : inConfig;
|
|
195
|
+
let extendsTagName = config.extends;
|
|
196
|
+
if (!extendsTagName) {
|
|
197
|
+
let proto = Object.getPrototypeOf(constructor);
|
|
198
|
+
while (proto && proto !== HTMLElement && proto !== Function.prototype) {
|
|
199
|
+
extendsTagName = BUILT_IN_TAG_MAP.get(proto);
|
|
200
|
+
if (extendsTagName)
|
|
201
|
+
break;
|
|
202
|
+
proto = Object.getPrototypeOf(proto);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
const attributeChangedMap = getAttributeChangedMap(constructor);
|
|
206
|
+
const observedFromDecorators = attributeChangedMap ? Array.from(attributeChangedMap.keys()) : [];
|
|
207
|
+
const mergedObservedAttributes = [.../* @__PURE__ */ new Set([...config.observedAttributes ?? [], ...observedFromDecorators])];
|
|
208
|
+
const NewClass = class extends constructor {
|
|
209
|
+
static get observedAttributes() {
|
|
210
|
+
return mergedObservedAttributes;
|
|
211
|
+
}
|
|
212
|
+
constructor(...args) {
|
|
213
|
+
super(...args);
|
|
214
|
+
if (config.useShadow === true && !this.shadowRoot) {
|
|
215
|
+
this.attachShadow({ mode: "open" });
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
disconnectedCallback() {
|
|
219
|
+
if (super.disconnectedCallback) {
|
|
220
|
+
super.disconnectedCallback();
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
connectedMoveCallback() {
|
|
224
|
+
if (super.connectedMoveCallback) {
|
|
225
|
+
super.connectedMoveCallback();
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
adoptedCallback() {
|
|
229
|
+
if (super.adoptedCallback) {
|
|
230
|
+
super.adoptedCallback();
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
async connectedCallback() {
|
|
234
|
+
if (super.connectedCallback) {
|
|
235
|
+
await super.connectedCallback();
|
|
236
|
+
}
|
|
237
|
+
const templateMethod = getTemplateMethod(this);
|
|
238
|
+
const styleMethod = getStyleMethod(this);
|
|
239
|
+
const template2 = templateMethod ? await this[templateMethod]() : void 0;
|
|
240
|
+
const style2 = styleMethod ? await this[styleMethod]() : void 0;
|
|
241
|
+
if (!this.shadowRoot && template2 === void 0 && style2 === void 0) {
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
let content = "";
|
|
245
|
+
if (style2 !== void 0 && style2.trim().length > 0) {
|
|
246
|
+
content += `<style>${style2}</style>`;
|
|
247
|
+
}
|
|
248
|
+
if (template2 !== void 0) {
|
|
249
|
+
content += template2;
|
|
250
|
+
} else if (!this.shadowRoot) {
|
|
251
|
+
content += this.innerHTML;
|
|
252
|
+
}
|
|
253
|
+
if (this.shadowRoot) {
|
|
254
|
+
this.shadowRoot.innerHTML = content;
|
|
255
|
+
} else {
|
|
256
|
+
this.innerHTML = content;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
// 4. Handle attribute changes and route to decorated methods
|
|
260
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
261
|
+
if (super.attributeChangedCallback) {
|
|
262
|
+
super.attributeChangedCallback(name, oldValue, newValue);
|
|
263
|
+
}
|
|
264
|
+
const methodKey = attributeChangedMap?.get(name);
|
|
265
|
+
if (methodKey && typeof this[methodKey] === "function") {
|
|
266
|
+
this[methodKey](newValue, oldValue);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
const registry = config.customElementRegistry || (typeof customElements !== "undefined" ? customElements : void 0);
|
|
271
|
+
if (registry && !registry.get(config.tagName)) {
|
|
272
|
+
const options = extendsTagName ? { extends: extendsTagName } : void 0;
|
|
273
|
+
registry.define(config.tagName, NewClass, options);
|
|
274
|
+
}
|
|
275
|
+
ReflectUtils.defineMetadata(ELEMENT_CONFIG_KEY, config, NewClass);
|
|
276
|
+
return NewClass;
|
|
277
|
+
};
|
|
278
|
+
var getElementConfig = (target) => {
|
|
279
|
+
const constructor = target instanceof Function ? target : target.constructor;
|
|
280
|
+
return ReflectUtils.getMetadata(ELEMENT_CONFIG_KEY, constructor);
|
|
281
|
+
};
|
|
282
|
+
return __toCommonJS(bundle_entry_exports);
|
|
283
|
+
})();
|
|
284
|
+
//# sourceMappingURL=dooboostore-simple-web-component.umd.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/bundle-entry.ts", "../../../core/src/reflect/ReflectUtils.ts", "../../src/decorators/attributeChanged.ts", "../../src/decorators/template.ts", "../../src/decorators/style.ts", "../../src/decorators/element.ts"],
|
|
4
|
+
"sourcesContent": ["export * from './index';\n", "import { ConstructorType } from '../types';\nexport namespace ReflectUtils {\n export const getParameterTypes = (target: any, propertyKey?: string | symbol): ConstructorType<any>[] => {\n // console.log('---------param')\n if (propertyKey) {\n return Reflect.getMetadata('design:paramtypes', target, propertyKey) || [];\n } else {\n return Reflect.getMetadata('design:paramtypes', target) || [];\n }\n }\n\n\n export const getReturnType = (target: any, propertyKey: string | symbol): any => {\n return Reflect.getMetadata('design:returntype', target, propertyKey);\n }\n\n // @Reflect.metadata(\"design:type\", Point)\n export const getType = (target: any, propertyKey?: string | symbol): any => {\n if (propertyKey) {\n return Reflect.getMetadata('design:type', target, propertyKey);\n } else {\n return Reflect.getMetadata('design:type', target);\n }\n }\n\n export const getMetadata = <T = any>(metadataKey: any, target: any, propertyKey?: string | symbol): T | undefined => {\n if (propertyKey) {\n return Reflect.getMetadata(metadataKey, target, propertyKey);\n } else {\n return Reflect.getMetadata(metadataKey, target);\n }\n\n\n //\n // let tt = target;\n // // proxy \uAC78\uB9B0\uAC70\uB294 \uC624\uB9AC\uC9C0\uB110 constructor\uC5D0 \uB4E4\uC5B4\uAC00\uC788\uC744\uACBD\uC6B0\uB3C4\uC788\uC5B4\uC11C reflect\uAC00 proxy\uC758 constructor\uC5D0\uC11C \uCC3E\uB294\uACBD\uC6B0\uB3C4\uC788\uB2E4,\n // // \uC11C\uBC84\uB791 \uD504\uB860\uD2B8\uB791 \uB2E4\uB978\uB4EF.. \uADF8\uB798\uC11C \uC704\uB85C \uCC3E\uC544\uAC00\uBA74\uC11C\n // while (tt) {\n // let meta: any = undefined;\n // if (propertyKey) {\n // meta = Reflect.getMetadata(metadataKey, tt, propertyKey);\n // } else {\n // meta = Reflect.getMetadata(metadataKey, tt);\n // }\n // if (meta) {\n // return meta;\n // }\n // tt = Reflect.getPrototypeOf(tt);\n // }\n }\n\n export const getMetadataKeys = (target: any) => {\n return Reflect.getMetadataKeys(target);\n }\n\n export const getOwnMetadata = (metadataKey: any, target: any, propertyKey?: string): number[] | any => {\n if (propertyKey) {\n return Reflect.getOwnMetadata(metadataKey, target, propertyKey);\n } else {\n return Reflect.getOwnMetadata(metadataKey, target);\n }\n }\n\n export const getMetadatas = (target: any) => {\n return ReflectUtils.getMetadataKeys(target).map(it => ReflectUtils.getMetadata(it, target));\n }\n\n export const metadata = (metadataKey: any, data: any) => {\n return Reflect.metadata(metadataKey, data);\n }\n\n export const defineMetadata = (metadataKey: any, value: any, target: any, propertyKey?: string | symbol) => {\n // console.log(\"Reflect:\",Reflect)\n if (propertyKey && Reflect.defineMetadata) {\n Reflect.defineMetadata(metadataKey, value, target, propertyKey);\n } else if (Reflect.defineMetadata) {\n Reflect.defineMetadata(metadataKey, value, target);\n // Reflect.defineMetadata(\"design:paramtypes\", value, target);\n }\n // console.log(\"Reflect:\",Reflect.getMetadata(metadataKey, target))\n // console.log(\"Reflect:\",Reflect.getMetadata('design:paramtypes', target))\n }\n}\n", "import { ReflectUtils } from '@dooboostore/core/reflect/ReflectUtils';\n\nexport const ATTRIBUTE_CHANGED_METADATA_KEY = Symbol('simple-web-component:attribute-changed');\n\nexport const attributeChanged = (attributeName: string): MethodDecorator => {\n return (target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n const constructor = target.constructor;\n let meta = ReflectUtils.getMetadata<Map<string, string | symbol>>(ATTRIBUTE_CHANGED_METADATA_KEY, constructor);\n if (!meta) {\n meta = new Map<string, string | symbol>();\n ReflectUtils.defineMetadata(ATTRIBUTE_CHANGED_METADATA_KEY, meta, constructor);\n }\n meta.set(attributeName, propertyKey);\n };\n};\n\nexport const getAttributeChangedMap = (target: any): Map<string, string | symbol> | undefined => {\n const constructor = target instanceof Function ? target : target.constructor;\n return ReflectUtils.getMetadata(ATTRIBUTE_CHANGED_METADATA_KEY, constructor);\n};\n", "import { ReflectUtils } from '@dooboostore/core/reflect/ReflectUtils';\n\nexport const TEMPLATE_METHOD_KEY = Symbol('simple-web-component:template-method');\n\nexport const template: MethodDecorator = (target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n // console.log('setTemplateMethod target.constructor', target.constructor)\n ReflectUtils.defineMetadata(TEMPLATE_METHOD_KEY, propertyKey, target.constructor);\n};\n\nexport const getTemplateMethod = (target: any): string | symbol | undefined => {\n const constructor = target instanceof Function ? target : target.constructor;\n // console.log('getTemplateMethod constructor', constructor)\n return ReflectUtils.getMetadata(TEMPLATE_METHOD_KEY, constructor);\n};\n", "import { ReflectUtils } from '@dooboostore/core/reflect/ReflectUtils';\n\nexport const STYLE_METHOD_KEY = Symbol('simple-web-component:style-method');\n\nexport const style: MethodDecorator = (target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n ReflectUtils.defineMetadata(STYLE_METHOD_KEY, propertyKey, target.constructor);\n};\n\nexport const getStyleMethod = (target: any): string | symbol | undefined => {\n const constructor = target instanceof Function ? target : target.constructor;\n return ReflectUtils.getMetadata(STYLE_METHOD_KEY, constructor);\n};\n", "import { ReflectUtils } from '@dooboostore/core/reflect/ReflectUtils';\nimport { getAttributeChangedMap } from './attributeChanged';\nimport { getTemplateMethod } from './template';\nimport { getStyleMethod } from './style';\n\nexport interface ElementConfig {\n tagName: string;\n useShadow?: boolean;\n extends?: string;\n observedAttributes?: string[];\n customElementRegistry?: CustomElementRegistry;\n}\n\nexport const ELEMENT_CONFIG_KEY = Symbol('simple-web-component:element-config');\n\nconst BUILT_IN_TAG_MAP = new Map<any, string>();\n\nconst registerTag = (className: string, tagName: string) => {\n if (typeof globalThis !== 'undefined' && (globalThis as any)[className]) {\n BUILT_IN_TAG_MAP.set((globalThis as any)[className], tagName);\n }\n};\n\n// Register comprehensive list of supported tags for automatic extends inference\n[\n ['HTMLAnchorElement', 'a'],\n ['HTMLAreaElement', 'area'],\n ['HTMLAudioElement', 'audio'],\n ['HTMLBaseElement', 'base'],\n ['HTMLButtonElement', 'button'],\n ['HTMLCanvasElement', 'canvas'],\n ['HTMLDataElement', 'data'],\n ['HTMLDataListElement', 'datalist'],\n ['HTMLDetailsElement', 'details'],\n ['HTMLDialogElement', 'dialog'],\n ['HTMLDivElement', 'div'],\n ['HTMLDListElement', 'dl'],\n ['HTMLEmbedElement', 'embed'],\n ['HTMLFieldSetElement', 'fieldset'],\n ['HTMLFormElement', 'form'],\n ['HTMLHRElement', 'hr'],\n ['HTMLIFrameElement', 'iframe'],\n ['HTMLImageElement', 'img'],\n ['HTMLInputElement', 'input'],\n ['HTMLLabelElement', 'label'],\n ['HTMLLegendElement', 'legend'],\n ['HTMLLIElement', 'li'],\n ['HTMLLinkElement', 'link'],\n ['HTMLMapElement', 'map'],\n ['HTMLMetaElement', 'meta'],\n ['HTMLMeterElement', 'meter'],\n ['HTMLModElement', 'del'],\n ['HTMLObjectElement', 'object'],\n ['HTMLOListElement', 'ol'],\n ['HTMLOptGroupElement', 'optgroup'],\n ['HTMLOptionElement', 'option'],\n ['HTMLOutputElement', 'output'],\n ['HTMLParagraphElement', 'p'],\n ['HTMLParamElement', 'param'],\n ['HTMLPictureElement', 'picture'],\n ['HTMLPreElement', 'pre'],\n ['HTMLProgressElement', 'progress'],\n ['HTMLQuoteElement', 'blockquote'],\n ['HTMLScriptElement', 'script'],\n ['HTMLSelectElement', 'select'],\n ['HTMLSlotElement', 'slot'],\n ['HTMLSourceElement', 'source'],\n ['HTMLSpanElement', 'span'],\n ['HTMLStyleElement', 'style'],\n ['HTMLTableElement', 'table'],\n ['HTMLTableSectionElement', 'tbody'],\n ['HTMLTableCellElement', 'td'],\n ['HTMLTemplateElement', 'template'],\n ['HTMLTextAreaElement', 'textarea'],\n ['HTMLTimeElement', 'time'],\n ['HTMLTitleElement', 'title'],\n ['HTMLTableRowElement', 'tr'],\n ['HTMLTrackElement', 'track'],\n ['HTMLUListElement', 'ul'],\n ['HTMLVideoElement', 'video'],\n ['HTMLHeadingElement', 'h1']\n].forEach(([cls, tag]) => registerTag(cls, tag));\n\nexport const element =\n (inConfig: ElementConfig | string): ClassDecorator =>\n (constructor: any) => {\n const config: ElementConfig = typeof inConfig === 'string' ? { tagName: inConfig } : inConfig;\n\n // 1. Automatically derive extendsTagName from prototype chain if not provided\n let extendsTagName = config.extends;\n if (!extendsTagName) {\n let proto = Object.getPrototypeOf(constructor);\n while (proto && proto !== HTMLElement && proto !== Function.prototype) {\n extendsTagName = BUILT_IN_TAG_MAP.get(proto);\n if (extendsTagName) break;\n proto = Object.getPrototypeOf(proto);\n }\n }\n\n // 2. Automatically collect observed attributes from @attributeChanged decorators\n const attributeChangedMap = getAttributeChangedMap(constructor);\n const observedFromDecorators = attributeChangedMap ? Array.from(attributeChangedMap.keys()) : [];\n const mergedObservedAttributes = [...new Set([...(config.observedAttributes ?? []), ...observedFromDecorators])];\n\n // 3. Create a new anonymous class that extends the original constructor\n const NewClass = class extends (constructor as any) {\n static get observedAttributes() {\n return mergedObservedAttributes;\n }\n\n constructor(...args: any[]) {\n super(...args);\n if (config.useShadow === true && !this.shadowRoot) {\n this.attachShadow({ mode: 'open' });\n }\n }\n\n disconnectedCallback() {\n if (super.disconnectedCallback) {\n super.disconnectedCallback();\n }\n }\n\n connectedMoveCallback() {\n if (super.connectedMoveCallback) {\n super.connectedMoveCallback();\n }\n }\n\n adoptedCallback() {\n if (super.adoptedCallback) {\n super.adoptedCallback();\n }\n }\n\n async connectedCallback() {\n if (super.connectedCallback) {\n await super.connectedCallback();\n }\n\n const templateMethod = getTemplateMethod(this);\n const styleMethod = getStyleMethod(this);\n\n const template = templateMethod ? await (this as any)[templateMethod]() : undefined;\n const style = styleMethod ? await (this as any)[styleMethod]() : undefined;\n\n // If not using shadow DOM and no decorators are present, do nothing\n if (!this.shadowRoot && template === undefined && style === undefined) {\n return;\n }\n\n let content = '';\n if (style !== undefined && style.trim().length > 0) {\n content += `<style>${style}</style>`;\n }\n\n if (template !== undefined) {\n content += template;\n } else if (!this.shadowRoot) {\n content += this.innerHTML;\n }\n\n if (this.shadowRoot) {\n this.shadowRoot.innerHTML = content;\n } else {\n this.innerHTML = content;\n }\n }\n\n // 4. Handle attribute changes and route to decorated methods\n attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null) {\n // Call the original callback if it exists\n if (super.attributeChangedCallback) {\n super.attributeChangedCallback(name, oldValue, newValue);\n }\n\n // Call the method associated with @attributeChanged\n const methodKey = attributeChangedMap?.get(name);\n if (methodKey && typeof (this as any)[methodKey] === 'function') {\n (this as any)[methodKey](newValue, oldValue);\n }\n }\n };\n\n // 5. Register Custom Element using specified or default registry\n const registry = config.customElementRegistry || (typeof customElements !== 'undefined' ? customElements : undefined);\n if (registry && !registry.get(config.tagName)) {\n const options = extendsTagName ? { extends: extendsTagName } : undefined;\n registry.define(config.tagName, NewClass as any, options);\n }\n\n // 6. Save metadata\n ReflectUtils.defineMetadata(ELEMENT_CONFIG_KEY, config, NewClass);\n\n return NewClass as any;\n };\n\nexport const getElementConfig = (target: any): ElementConfig | undefined => {\n const constructor = target instanceof Function ? target : target.constructor;\n return ReflectUtils.getMetadata(ELEMENT_CONFIG_KEY, constructor);\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCO,MAAW;AAAA,GAAX,CAAWA,kBAAX;AACUA,kBAAA,oBAAoB,CAAC,QAAa,gBAA0D;AAErG,UAAI,aAAa;AACb,eAAO,QAAQ,YAAY,qBAAqB,QAAQ,WAAW,KAAK,CAAC;MAC7E,OAAO;AACH,eAAO,QAAQ,YAAY,qBAAqB,MAAM,KAAK,CAAC;MAChE;IACJ;AAGaA,kBAAA,gBAAgB,CAAC,QAAa,gBAAuC;AAC9E,aAAO,QAAQ,YAAY,qBAAqB,QAAQ,WAAW;IACvE;AAGaA,kBAAA,UAAU,CAAC,QAAa,gBAAuC;AACxE,UAAI,aAAa;AACb,eAAO,QAAQ,YAAY,eAAe,QAAQ,WAAW;MACjE,OAAO;AACH,eAAO,QAAQ,YAAY,eAAe,MAAM;MACpD;IACJ;AAEaA,kBAAA,cAAc,CAAU,aAAkB,QAAa,gBAAiD;AACjH,UAAI,aAAa;AACb,eAAO,QAAQ,YAAY,aAAa,QAAQ,WAAW;MAC/D,OAAO;AACH,eAAO,QAAQ,YAAY,aAAa,MAAM;MAClD;IAmBJ;AAEaA,kBAAA,kBAAkB,CAAC,WAAgB;AAC5C,aAAO,QAAQ,gBAAgB,MAAM;IACzC;AAEaA,kBAAA,iBAAiB,CAAC,aAAkB,QAAa,gBA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AAWA;QACb,WAAW,CAAC,KAAK,YAAY;AAC3B,qBAAW,KAAK;QAClB;AAEA,YAAI,KAAK,YAAY;AACnB,eAAK,WAAW,YAAY;QAC9B,OAAO;AACL,eAAK,YAAY;QACnB;MACF;;MAGA,yBAAyB,MAAc,UAAyB,UAAuB;AAErF,YAAI,MAAM,0BAA0B;AAClC,gBAAM,yBAAyB,MAAM,UAAU,QAAQ;QACzD;AAGA,cAAM,YAAY,qBAAqB,IAAI,IAAI;AAC/C,YAAI,aAAa,OAAQ,KAAa,SAAS,MAAM,YAAY;AAC9D,eAAa,SAAS,EAAE,UAAU,QAAQ;QAC7C;MACF;;AAIF,UAAM,WAAW,OAAO,0BAA0B,OAAO,mBAAmB,cAAc,iBAAiB;AAC3G,QAAI,YAAY,CAAC,SAAS,IAAI,OAAO,OAAO,GAAG;AAC7C,YAAM,UAAU,iBAAiB,EAAE,SAAS,eAAc,IAAK;AAC/D,eAAS,OAAO,OAAO,SAAS,UAAiB,OAAO;IAC1D;AAGA,iBAAa,eAAe,oBAAoB,QAAQ,QAAQ;AAEhE,WAAO;EACT;AAEK,MAAM,mBAAmB,CAAC,WAA0C;AACzE,UAAM,cAAc,kBAAkB,WAAW,SAAS,OAAO;AACjE,WAAO,aAAa,YAAY,oBAAoB,WAAW;EACjE;",
|
|
6
|
+
"names": ["ReflectUtils", "template", "style"]
|
|
7
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dooboostore/simple-web-component",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/cjs/index.js",
|
|
7
|
+
"module": "./dist/esm/index.js",
|
|
8
|
+
"types": "./dist/types/index.d.ts",
|
|
9
|
+
"typesVersions": {
|
|
10
|
+
"*": {
|
|
11
|
+
"*": [
|
|
12
|
+
"dist/types/*"
|
|
13
|
+
]
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"description": "Simple Web Component library based on dom-render philosophy",
|
|
17
|
+
"keywords": [
|
|
18
|
+
"front",
|
|
19
|
+
"web-components",
|
|
20
|
+
"view",
|
|
21
|
+
"template",
|
|
22
|
+
"simple-web-component",
|
|
23
|
+
"front-end"
|
|
24
|
+
],
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"src",
|
|
28
|
+
"types.d.ts",
|
|
29
|
+
"LICENSE.md",
|
|
30
|
+
"tsconfig.json"
|
|
31
|
+
],
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
},
|
|
35
|
+
"exports": {
|
|
36
|
+
".": {
|
|
37
|
+
"types": "./dist/types/index.d.ts",
|
|
38
|
+
"import": "./dist/esm/index.js",
|
|
39
|
+
"require": "./dist/cjs/index.js"
|
|
40
|
+
},
|
|
41
|
+
"./*": {
|
|
42
|
+
"types": "./dist/types/*.d.ts",
|
|
43
|
+
"import": "./dist/esm/*.js",
|
|
44
|
+
"require": "./dist/cjs/*.js"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"author": "dooboostore <dooboostore@gmail.com> (https://github.com/dooboostore)",
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"reflect-metadata": "^0.2.2"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@babel/core": "^7.24.0",
|
|
53
|
+
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
54
|
+
"@babel/plugin-proposal-decorators": "^7.24.0",
|
|
55
|
+
"@babel/plugin-transform-private-property-in-object": "^7.25.9",
|
|
56
|
+
"@babel/preset-env": "^7.24.0",
|
|
57
|
+
"@babel/preset-typescript": "^7.24.0",
|
|
58
|
+
"@types/jest": "^26.0.22",
|
|
59
|
+
"raw-loader": "^4.0.2",
|
|
60
|
+
"@typescript-eslint/eslint-plugin": "^4.16.1",
|
|
61
|
+
"@typescript-eslint/parser": "^4.16.1",
|
|
62
|
+
"webpack": "^5.93.0",
|
|
63
|
+
"webpack-cli": "^5.1.4",
|
|
64
|
+
"webpack-dev-server": "^5.2.0",
|
|
65
|
+
"html-webpack-plugin": "^5.6.3",
|
|
66
|
+
"ts-loader": "^9.5.1",
|
|
67
|
+
"tslib": "^2.8.1",
|
|
68
|
+
"@types/node": "^20",
|
|
69
|
+
"typescript": "^5.9.2",
|
|
70
|
+
"esbuild-plugin-tsc": "^0.5.0",
|
|
71
|
+
"esbuild": "^0.23.0",
|
|
72
|
+
"@dooboostore/core": "1.0.28",
|
|
73
|
+
"@dooboostore/core-web": "1.0.9",
|
|
74
|
+
"@dooboostore/core-node": "1.0.10"
|
|
75
|
+
},
|
|
76
|
+
"scripts": {
|
|
77
|
+
"clean": "rm -rf dist",
|
|
78
|
+
"build:esm": "node build.mjs esm",
|
|
79
|
+
"watch:esm": "pnpm run build:esm && node build.mjs esm --watch",
|
|
80
|
+
"build:cjs": "node build.mjs cjs",
|
|
81
|
+
"watch:cjs": "pnpm run build:cjs && node build.mjs cjs --watch",
|
|
82
|
+
"build": "pnpm run clean && node build.mjs all",
|
|
83
|
+
"build:umd-bundle": "node build.mjs umd-bundle",
|
|
84
|
+
"watch:umd-bundle": "pnpm run build:umd-bundle && node build.mjs umd-bundle --watch",
|
|
85
|
+
"build:esm-bundle": "node build.mjs esm-bundle",
|
|
86
|
+
"watch:esm-bundle": "pnpm run build:esm-bundle && node build.mjs esm-bundle --watch",
|
|
87
|
+
"watch": "node build.mjs all --watch",
|
|
88
|
+
"publish:npm": "pnpm run build && cp package.json package.json.back && pnpm pack && TARBALL_NAME=$(ls dooboostore-simple-web-component-*.tgz | head -n 1) && tar -xzf \"$TARBALL_NAME\" -C . --strip-components=1 package/package.json && rm \"$TARBALL_NAME\" && (pnpm publish --no-git-checks || true) && cp package.json.back package.json && rm -rf package.json.back ",
|
|
89
|
+
"ts:clean": "find . -name '*.js' -o -name '*.map' -o -name '*.d.ts' | xargs rm -f",
|
|
90
|
+
"typecheck": "pnpm exec tsc --noEmit",
|
|
91
|
+
"test": "echo test"
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './index';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ReflectUtils } from '@dooboostore/core/reflect/ReflectUtils';
|
|
2
|
+
|
|
3
|
+
export const ATTRIBUTE_CHANGED_METADATA_KEY = Symbol('simple-web-component:attribute-changed');
|
|
4
|
+
|
|
5
|
+
export const attributeChanged = (attributeName: string): MethodDecorator => {
|
|
6
|
+
return (target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {
|
|
7
|
+
const constructor = target.constructor;
|
|
8
|
+
let meta = ReflectUtils.getMetadata<Map<string, string | symbol>>(ATTRIBUTE_CHANGED_METADATA_KEY, constructor);
|
|
9
|
+
if (!meta) {
|
|
10
|
+
meta = new Map<string, string | symbol>();
|
|
11
|
+
ReflectUtils.defineMetadata(ATTRIBUTE_CHANGED_METADATA_KEY, meta, constructor);
|
|
12
|
+
}
|
|
13
|
+
meta.set(attributeName, propertyKey);
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const getAttributeChangedMap = (target: any): Map<string, string | symbol> | undefined => {
|
|
18
|
+
const constructor = target instanceof Function ? target : target.constructor;
|
|
19
|
+
return ReflectUtils.getMetadata(ATTRIBUTE_CHANGED_METADATA_KEY, constructor);
|
|
20
|
+
};
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { ReflectUtils } from '@dooboostore/core/reflect/ReflectUtils';
|
|
2
|
+
import { getAttributeChangedMap } from './attributeChanged';
|
|
3
|
+
import { getTemplateMethod } from './template';
|
|
4
|
+
import { getStyleMethod } from './style';
|
|
5
|
+
|
|
6
|
+
export interface ElementConfig {
|
|
7
|
+
tagName: string;
|
|
8
|
+
useShadow?: boolean;
|
|
9
|
+
extends?: string;
|
|
10
|
+
observedAttributes?: string[];
|
|
11
|
+
customElementRegistry?: CustomElementRegistry;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const ELEMENT_CONFIG_KEY = Symbol('simple-web-component:element-config');
|
|
15
|
+
|
|
16
|
+
const BUILT_IN_TAG_MAP = new Map<any, string>();
|
|
17
|
+
|
|
18
|
+
const registerTag = (className: string, tagName: string) => {
|
|
19
|
+
if (typeof globalThis !== 'undefined' && (globalThis as any)[className]) {
|
|
20
|
+
BUILT_IN_TAG_MAP.set((globalThis as any)[className], tagName);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// Register comprehensive list of supported tags for automatic extends inference
|
|
25
|
+
[
|
|
26
|
+
['HTMLAnchorElement', 'a'],
|
|
27
|
+
['HTMLAreaElement', 'area'],
|
|
28
|
+
['HTMLAudioElement', 'audio'],
|
|
29
|
+
['HTMLBaseElement', 'base'],
|
|
30
|
+
['HTMLButtonElement', 'button'],
|
|
31
|
+
['HTMLCanvasElement', 'canvas'],
|
|
32
|
+
['HTMLDataElement', 'data'],
|
|
33
|
+
['HTMLDataListElement', 'datalist'],
|
|
34
|
+
['HTMLDetailsElement', 'details'],
|
|
35
|
+
['HTMLDialogElement', 'dialog'],
|
|
36
|
+
['HTMLDivElement', 'div'],
|
|
37
|
+
['HTMLDListElement', 'dl'],
|
|
38
|
+
['HTMLEmbedElement', 'embed'],
|
|
39
|
+
['HTMLFieldSetElement', 'fieldset'],
|
|
40
|
+
['HTMLFormElement', 'form'],
|
|
41
|
+
['HTMLHRElement', 'hr'],
|
|
42
|
+
['HTMLIFrameElement', 'iframe'],
|
|
43
|
+
['HTMLImageElement', 'img'],
|
|
44
|
+
['HTMLInputElement', 'input'],
|
|
45
|
+
['HTMLLabelElement', 'label'],
|
|
46
|
+
['HTMLLegendElement', 'legend'],
|
|
47
|
+
['HTMLLIElement', 'li'],
|
|
48
|
+
['HTMLLinkElement', 'link'],
|
|
49
|
+
['HTMLMapElement', 'map'],
|
|
50
|
+
['HTMLMetaElement', 'meta'],
|
|
51
|
+
['HTMLMeterElement', 'meter'],
|
|
52
|
+
['HTMLModElement', 'del'],
|
|
53
|
+
['HTMLObjectElement', 'object'],
|
|
54
|
+
['HTMLOListElement', 'ol'],
|
|
55
|
+
['HTMLOptGroupElement', 'optgroup'],
|
|
56
|
+
['HTMLOptionElement', 'option'],
|
|
57
|
+
['HTMLOutputElement', 'output'],
|
|
58
|
+
['HTMLParagraphElement', 'p'],
|
|
59
|
+
['HTMLParamElement', 'param'],
|
|
60
|
+
['HTMLPictureElement', 'picture'],
|
|
61
|
+
['HTMLPreElement', 'pre'],
|
|
62
|
+
['HTMLProgressElement', 'progress'],
|
|
63
|
+
['HTMLQuoteElement', 'blockquote'],
|
|
64
|
+
['HTMLScriptElement', 'script'],
|
|
65
|
+
['HTMLSelectElement', 'select'],
|
|
66
|
+
['HTMLSlotElement', 'slot'],
|
|
67
|
+
['HTMLSourceElement', 'source'],
|
|
68
|
+
['HTMLSpanElement', 'span'],
|
|
69
|
+
['HTMLStyleElement', 'style'],
|
|
70
|
+
['HTMLTableElement', 'table'],
|
|
71
|
+
['HTMLTableSectionElement', 'tbody'],
|
|
72
|
+
['HTMLTableCellElement', 'td'],
|
|
73
|
+
['HTMLTemplateElement', 'template'],
|
|
74
|
+
['HTMLTextAreaElement', 'textarea'],
|
|
75
|
+
['HTMLTimeElement', 'time'],
|
|
76
|
+
['HTMLTitleElement', 'title'],
|
|
77
|
+
['HTMLTableRowElement', 'tr'],
|
|
78
|
+
['HTMLTrackElement', 'track'],
|
|
79
|
+
['HTMLUListElement', 'ul'],
|
|
80
|
+
['HTMLVideoElement', 'video'],
|
|
81
|
+
['HTMLHeadingElement', 'h1']
|
|
82
|
+
].forEach(([cls, tag]) => registerTag(cls, tag));
|
|
83
|
+
|
|
84
|
+
export const element =
|
|
85
|
+
(inConfig: ElementConfig | string): ClassDecorator =>
|
|
86
|
+
(constructor: any) => {
|
|
87
|
+
const config: ElementConfig = typeof inConfig === 'string' ? { tagName: inConfig } : inConfig;
|
|
88
|
+
|
|
89
|
+
// 1. Automatically derive extendsTagName from prototype chain if not provided
|
|
90
|
+
let extendsTagName = config.extends;
|
|
91
|
+
if (!extendsTagName) {
|
|
92
|
+
let proto = Object.getPrototypeOf(constructor);
|
|
93
|
+
while (proto && proto !== HTMLElement && proto !== Function.prototype) {
|
|
94
|
+
extendsTagName = BUILT_IN_TAG_MAP.get(proto);
|
|
95
|
+
if (extendsTagName) break;
|
|
96
|
+
proto = Object.getPrototypeOf(proto);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// 2. Automatically collect observed attributes from @attributeChanged decorators
|
|
101
|
+
const attributeChangedMap = getAttributeChangedMap(constructor);
|
|
102
|
+
const observedFromDecorators = attributeChangedMap ? Array.from(attributeChangedMap.keys()) : [];
|
|
103
|
+
const mergedObservedAttributes = [...new Set([...(config.observedAttributes ?? []), ...observedFromDecorators])];
|
|
104
|
+
|
|
105
|
+
// 3. Create a new anonymous class that extends the original constructor
|
|
106
|
+
const NewClass = class extends (constructor as any) {
|
|
107
|
+
static get observedAttributes() {
|
|
108
|
+
return mergedObservedAttributes;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
constructor(...args: any[]) {
|
|
112
|
+
super(...args);
|
|
113
|
+
if (config.useShadow === true && !this.shadowRoot) {
|
|
114
|
+
this.attachShadow({ mode: 'open' });
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
disconnectedCallback() {
|
|
119
|
+
if (super.disconnectedCallback) {
|
|
120
|
+
super.disconnectedCallback();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
connectedMoveCallback() {
|
|
125
|
+
if (super.connectedMoveCallback) {
|
|
126
|
+
super.connectedMoveCallback();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
adoptedCallback() {
|
|
131
|
+
if (super.adoptedCallback) {
|
|
132
|
+
super.adoptedCallback();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
async connectedCallback() {
|
|
137
|
+
if (super.connectedCallback) {
|
|
138
|
+
await super.connectedCallback();
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const templateMethod = getTemplateMethod(this);
|
|
142
|
+
const styleMethod = getStyleMethod(this);
|
|
143
|
+
|
|
144
|
+
const template = templateMethod ? await (this as any)[templateMethod]() : undefined;
|
|
145
|
+
const style = styleMethod ? await (this as any)[styleMethod]() : undefined;
|
|
146
|
+
|
|
147
|
+
// If not using shadow DOM and no decorators are present, do nothing
|
|
148
|
+
if (!this.shadowRoot && template === undefined && style === undefined) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
let content = '';
|
|
153
|
+
if (style !== undefined && style.trim().length > 0) {
|
|
154
|
+
content += `<style>${style}</style>`;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (template !== undefined) {
|
|
158
|
+
content += template;
|
|
159
|
+
} else if (!this.shadowRoot) {
|
|
160
|
+
content += this.innerHTML;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (this.shadowRoot) {
|
|
164
|
+
this.shadowRoot.innerHTML = content;
|
|
165
|
+
} else {
|
|
166
|
+
this.innerHTML = content;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// 4. Handle attribute changes and route to decorated methods
|
|
171
|
+
attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null) {
|
|
172
|
+
// Call the original callback if it exists
|
|
173
|
+
if (super.attributeChangedCallback) {
|
|
174
|
+
super.attributeChangedCallback(name, oldValue, newValue);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// Call the method associated with @attributeChanged
|
|
178
|
+
const methodKey = attributeChangedMap?.get(name);
|
|
179
|
+
if (methodKey && typeof (this as any)[methodKey] === 'function') {
|
|
180
|
+
(this as any)[methodKey](newValue, oldValue);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
// 5. Register Custom Element using specified or default registry
|
|
186
|
+
const registry = config.customElementRegistry || (typeof customElements !== 'undefined' ? customElements : undefined);
|
|
187
|
+
if (registry && !registry.get(config.tagName)) {
|
|
188
|
+
const options = extendsTagName ? { extends: extendsTagName } : undefined;
|
|
189
|
+
registry.define(config.tagName, NewClass as any, options);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// 6. Save metadata
|
|
193
|
+
ReflectUtils.defineMetadata(ELEMENT_CONFIG_KEY, config, NewClass);
|
|
194
|
+
|
|
195
|
+
return NewClass as any;
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
export const getElementConfig = (target: any): ElementConfig | undefined => {
|
|
199
|
+
const constructor = target instanceof Function ? target : target.constructor;
|
|
200
|
+
return ReflectUtils.getMetadata(ELEMENT_CONFIG_KEY, constructor);
|
|
201
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ReflectUtils } from '@dooboostore/core/reflect/ReflectUtils';
|
|
2
|
+
|
|
3
|
+
export const STYLE_METHOD_KEY = Symbol('simple-web-component:style-method');
|
|
4
|
+
|
|
5
|
+
export const style: MethodDecorator = (target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {
|
|
6
|
+
ReflectUtils.defineMetadata(STYLE_METHOD_KEY, propertyKey, target.constructor);
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const getStyleMethod = (target: any): string | symbol | undefined => {
|
|
10
|
+
const constructor = target instanceof Function ? target : target.constructor;
|
|
11
|
+
return ReflectUtils.getMetadata(STYLE_METHOD_KEY, constructor);
|
|
12
|
+
};
|