@dooboostore/simple-web-component 1.0.17 → 1.0.18
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 +75 -107
- package/dist/cjs/decorators/appendChild.js +48 -0
- package/dist/cjs/decorators/appendChild.js.map +7 -0
- package/dist/cjs/decorators/elementDefine.js +85 -7
- package/dist/cjs/decorators/elementDefine.js.map +2 -2
- package/dist/cjs/decorators/index.js +2 -1
- package/dist/cjs/decorators/index.js.map +2 -2
- package/dist/cjs/decorators/{innerHtml.js → onConnectedInnerHtml.js} +8 -8
- package/dist/cjs/decorators/onConnectedInnerHtml.js.map +7 -0
- package/dist/cjs/decorators/query.js +16 -0
- package/dist/cjs/decorators/query.js.map +2 -2
- package/dist/cjs/decorators/queryAll.js +18 -0
- package/dist/cjs/decorators/queryAll.js.map +2 -2
- package/dist/cjs/decorators/replaceChildren.js +53 -0
- package/dist/cjs/decorators/replaceChildren.js.map +7 -0
- package/dist/cjs/index.js +11 -1
- package/dist/cjs/index.js.map +2 -2
- package/dist/esm/decorators/appendChild.js +29 -0
- package/dist/esm/decorators/appendChild.js.map +7 -0
- package/dist/esm/decorators/elementDefine.js +85 -7
- package/dist/esm/decorators/elementDefine.js.map +2 -2
- package/dist/esm/decorators/index.js +2 -1
- package/dist/esm/decorators/index.js.map +2 -2
- package/dist/esm/decorators/{innerHtml.js → onConnectedInnerHtml.js} +5 -5
- package/dist/esm/decorators/onConnectedInnerHtml.js.map +7 -0
- package/dist/esm/decorators/query.js +16 -0
- package/dist/esm/decorators/query.js.map +2 -2
- package/dist/esm/decorators/queryAll.js +18 -0
- package/dist/esm/decorators/queryAll.js.map +2 -2
- package/dist/esm/decorators/replaceChildren.js +34 -0
- package/dist/esm/decorators/replaceChildren.js.map +7 -0
- package/dist/esm/index.js +7 -1
- package/dist/esm/index.js.map +2 -2
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +181 -11
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +3 -3
- package/dist/types/decorators/appendChild.d.ts +17 -0
- package/dist/types/decorators/appendChild.d.ts.map +1 -0
- package/dist/types/decorators/elementDefine.d.ts.map +1 -1
- package/dist/types/decorators/index.d.ts +2 -1
- package/dist/types/decorators/index.d.ts.map +1 -1
- package/dist/types/decorators/onConnectedInnerHtml.d.ts +15 -0
- package/dist/types/decorators/onConnectedInnerHtml.d.ts.map +1 -0
- package/dist/types/decorators/query.d.ts.map +1 -1
- package/dist/types/decorators/queryAll.d.ts.map +1 -1
- package/dist/types/decorators/replaceChildren.d.ts +9 -0
- package/dist/types/decorators/replaceChildren.d.ts.map +1 -0
- package/dist/types/index.d.ts +4 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +181 -11
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +3 -3
- package/package.json +1 -1
- package/src/decorators/appendChild.ts +42 -0
- package/src/decorators/elementDefine.ts +90 -7
- package/src/decorators/index.ts +2 -1
- package/src/decorators/{innerHtml.ts → onConnectedInnerHtml.ts} +7 -6
- package/src/decorators/query.ts +12 -0
- package/src/decorators/queryAll.ts +16 -0
- package/src/decorators/replaceChildren.ts +35 -0
- package/src/index.ts +4 -1
- package/dist/cjs/decorators/innerHtml.js.map +0 -7
- package/dist/esm/decorators/innerHtml.js.map +0 -7
- package/dist/types/decorators/innerHtml.d.ts +0 -12
- package/dist/types/decorators/innerHtml.d.ts.map +0 -1
|
@@ -1252,9 +1252,9 @@ var FunctionUtils;
|
|
|
1252
1252
|
};
|
|
1253
1253
|
})(FunctionUtils || (FunctionUtils = {}));
|
|
1254
1254
|
|
|
1255
|
-
// src/decorators/
|
|
1255
|
+
// src/decorators/onConnectedInnerHtml.ts
|
|
1256
1256
|
var INNER_HTML_METADATA_KEY = Symbol("simple-web-component:inner-html");
|
|
1257
|
-
function
|
|
1257
|
+
function onConnectedInnerHtml(arg1, arg2, arg3) {
|
|
1258
1258
|
const decorator = (options, target, propertyKey) => {
|
|
1259
1259
|
const constructor = target.constructor;
|
|
1260
1260
|
let list = ReflectUtils.getMetadata(INNER_HTML_METADATA_KEY, constructor);
|
|
@@ -1271,7 +1271,7 @@ function innerHtml(arg1, arg2, arg3) {
|
|
|
1271
1271
|
decorator(arg1 || {}, target, propertyKey);
|
|
1272
1272
|
};
|
|
1273
1273
|
}
|
|
1274
|
-
var
|
|
1274
|
+
var getOnConnectedInnerHtmlMetadata = (target) => {
|
|
1275
1275
|
const constructor = target instanceof Function ? target : target.constructor;
|
|
1276
1276
|
return ReflectUtils.getMetadata(INNER_HTML_METADATA_KEY, constructor);
|
|
1277
1277
|
};
|
|
@@ -1408,6 +1408,58 @@ var findAllSetAttributeMetadata = (target) => {
|
|
|
1408
1408
|
return result;
|
|
1409
1409
|
};
|
|
1410
1410
|
|
|
1411
|
+
// src/decorators/replaceChildren.ts
|
|
1412
|
+
var REPLACE_CHILDREN_METADATA_KEY = Symbol("simple-web-component:replace-children");
|
|
1413
|
+
function replaceChildren(selector) {
|
|
1414
|
+
return (target, propertyKey) => {
|
|
1415
|
+
const constructor = target.constructor;
|
|
1416
|
+
let meta = ReflectUtils.getOwnMetadata(REPLACE_CHILDREN_METADATA_KEY, constructor);
|
|
1417
|
+
if (!meta) {
|
|
1418
|
+
meta = /* @__PURE__ */ new Map();
|
|
1419
|
+
ReflectUtils.defineMetadata(REPLACE_CHILDREN_METADATA_KEY, meta, constructor);
|
|
1420
|
+
}
|
|
1421
|
+
meta.set(propertyKey, selector);
|
|
1422
|
+
};
|
|
1423
|
+
}
|
|
1424
|
+
var getReplaceChildrenMetadata = (target) => {
|
|
1425
|
+
const constructor = target instanceof Function ? target : target.constructor;
|
|
1426
|
+
return ReflectUtils.getMetadata(REPLACE_CHILDREN_METADATA_KEY, constructor);
|
|
1427
|
+
};
|
|
1428
|
+
var findAllReplaceChildrenMetadata = (target) => {
|
|
1429
|
+
const result = /* @__PURE__ */ new Map();
|
|
1430
|
+
const maps = ReflectUtils.findAllMetadata(REPLACE_CHILDREN_METADATA_KEY, target);
|
|
1431
|
+
maps.forEach((map) => {
|
|
1432
|
+
if (map instanceof Map) {
|
|
1433
|
+
map.forEach((v, k) => result.set(k, v));
|
|
1434
|
+
}
|
|
1435
|
+
});
|
|
1436
|
+
return result;
|
|
1437
|
+
};
|
|
1438
|
+
|
|
1439
|
+
// src/decorators/appendChild.ts
|
|
1440
|
+
var APPEND_CHILD_METADATA_KEY = Symbol("simple-web-component:append-child");
|
|
1441
|
+
function appendChild(selector, options = { position: "lastChild" }) {
|
|
1442
|
+
return (target, propertyKey) => {
|
|
1443
|
+
const constructor = target.constructor;
|
|
1444
|
+
let meta = ReflectUtils.getOwnMetadata(APPEND_CHILD_METADATA_KEY, constructor);
|
|
1445
|
+
if (!meta) {
|
|
1446
|
+
meta = /* @__PURE__ */ new Map();
|
|
1447
|
+
ReflectUtils.defineMetadata(APPEND_CHILD_METADATA_KEY, meta, constructor);
|
|
1448
|
+
}
|
|
1449
|
+
meta.set(propertyKey, { propertyKey, selector, options });
|
|
1450
|
+
};
|
|
1451
|
+
}
|
|
1452
|
+
var findAllAppendChildMetadata = (target) => {
|
|
1453
|
+
const result = /* @__PURE__ */ new Map();
|
|
1454
|
+
const maps = ReflectUtils.findAllMetadata(APPEND_CHILD_METADATA_KEY, target);
|
|
1455
|
+
maps.forEach((map) => {
|
|
1456
|
+
if (map instanceof Map) {
|
|
1457
|
+
map.forEach((v, k) => result.set(k, v));
|
|
1458
|
+
}
|
|
1459
|
+
});
|
|
1460
|
+
return result;
|
|
1461
|
+
};
|
|
1462
|
+
|
|
1411
1463
|
// src/utils/Utils.ts
|
|
1412
1464
|
var SWC_NOT_FOUND = Symbol("SWC_NOT_FOUND");
|
|
1413
1465
|
var SwcUtils;
|
|
@@ -1674,10 +1726,12 @@ var elementDefine = (inConfig) => (constructor) => {
|
|
|
1674
1726
|
const addEventListenerList = getAddEventListenerMetadata(constructor) || [];
|
|
1675
1727
|
const attrChangeMap = findAllAttributeChangedMetadata(constructor);
|
|
1676
1728
|
const setAttrMap = findAllSetAttributeMetadata(constructor);
|
|
1729
|
+
const replaceChildrenMap = findAllReplaceChildrenMetadata(constructor);
|
|
1730
|
+
const appendChildMap = findAllAppendChildMetadata(constructor);
|
|
1677
1731
|
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"];
|
|
1678
1732
|
const swcOnEvents = DOM_EVENT_NAMES.map((e) => `swc-on-${e}`);
|
|
1679
1733
|
const mergedObservedAttributes = [.../* @__PURE__ */ new Set([...config.observedAttributes ?? [], ...attrChangeMap.keys(), ...setAttrMap.keys(), ...emitCustomEventList.map((it) => it.options.attributeName), ...swcLifecycleAttributes, ...swcOnEvents])];
|
|
1680
|
-
const
|
|
1734
|
+
const connectedInnerHtmlList = getOnConnectedInnerHtmlMetadata(constructor) || [];
|
|
1681
1735
|
const NewClass = class extends constructor {
|
|
1682
1736
|
_executeSwcScript(attrName, hostSet, extraArgs = {}) {
|
|
1683
1737
|
const script = this.getAttribute(attrName);
|
|
@@ -1744,7 +1798,7 @@ var elementDefine = (inConfig) => (constructor) => {
|
|
|
1744
1798
|
this._boundListeners = [];
|
|
1745
1799
|
const hostSet = SwcUtils.getHostSet(this);
|
|
1746
1800
|
this._executeSwcScript("swc-on-constructor", hostSet);
|
|
1747
|
-
if (
|
|
1801
|
+
if (connectedInnerHtmlList.some((it) => it.options.useShadow === true) && !this.shadowRoot) {
|
|
1748
1802
|
this.attachShadow({ mode: "open" });
|
|
1749
1803
|
}
|
|
1750
1804
|
}
|
|
@@ -1764,9 +1818,9 @@ var elementDefine = (inConfig) => (constructor) => {
|
|
|
1764
1818
|
}
|
|
1765
1819
|
if (typeof this.initCore === "function")
|
|
1766
1820
|
this.initCore();
|
|
1767
|
-
if (
|
|
1821
|
+
if (connectedInnerHtmlList.length > 0) {
|
|
1768
1822
|
let sContent = "", lContent = "";
|
|
1769
|
-
for (const meta of
|
|
1823
|
+
for (const meta of connectedInnerHtmlList) {
|
|
1770
1824
|
const res = await this[meta.propertyKey]();
|
|
1771
1825
|
if (res !== void 0) {
|
|
1772
1826
|
if (meta.options.useShadow)
|
|
@@ -1810,8 +1864,9 @@ var elementDefine = (inConfig) => (constructor) => {
|
|
|
1810
1864
|
}
|
|
1811
1865
|
};
|
|
1812
1866
|
DOM_EVENT_NAMES.forEach((type) => {
|
|
1813
|
-
|
|
1814
|
-
this.
|
|
1867
|
+
const handler = createDelegationHandler(this);
|
|
1868
|
+
this.addEventListener(type, handler);
|
|
1869
|
+
this._boundListeners.push({ target: this, type, handler });
|
|
1815
1870
|
});
|
|
1816
1871
|
const hasParentHost = SwcUtils.findAllSwcHosts(this).length > 0;
|
|
1817
1872
|
if (!hasParentHost) {
|
|
@@ -2013,6 +2068,79 @@ var elementDefine = (inConfig) => (constructor) => {
|
|
|
2013
2068
|
};
|
|
2014
2069
|
}
|
|
2015
2070
|
});
|
|
2071
|
+
replaceChildrenMap.forEach((selector, methodName) => {
|
|
2072
|
+
const original = NewClass.prototype[methodName];
|
|
2073
|
+
if (typeof original === "function") {
|
|
2074
|
+
NewClass.prototype[methodName] = function(...args) {
|
|
2075
|
+
const res = original.apply(this, args);
|
|
2076
|
+
if (res !== void 0) {
|
|
2077
|
+
const conf = getElementConfig(this);
|
|
2078
|
+
const currentWin = conf?.window || window;
|
|
2079
|
+
const currentDoc = currentWin.document;
|
|
2080
|
+
let targetEl = null;
|
|
2081
|
+
if (selector === ":host" || !selector) {
|
|
2082
|
+
targetEl = this;
|
|
2083
|
+
} else {
|
|
2084
|
+
targetEl = (this.shadowRoot || this).querySelector(selector);
|
|
2085
|
+
}
|
|
2086
|
+
if (targetEl) {
|
|
2087
|
+
const nodes = Array.isArray(res) ? res : [res];
|
|
2088
|
+
const normalizedNodes = nodes.map((n) => {
|
|
2089
|
+
if (typeof n === "string") {
|
|
2090
|
+
const t = currentDoc.createElement("template");
|
|
2091
|
+
t.innerHTML = n;
|
|
2092
|
+
return t.content;
|
|
2093
|
+
}
|
|
2094
|
+
return n;
|
|
2095
|
+
});
|
|
2096
|
+
targetEl.replaceChildren(...normalizedNodes);
|
|
2097
|
+
}
|
|
2098
|
+
}
|
|
2099
|
+
return res;
|
|
2100
|
+
};
|
|
2101
|
+
}
|
|
2102
|
+
});
|
|
2103
|
+
appendChildMap.forEach((meta, methodName) => {
|
|
2104
|
+
const { selector, options } = meta;
|
|
2105
|
+
const original = NewClass.prototype[methodName];
|
|
2106
|
+
if (typeof original === "function") {
|
|
2107
|
+
NewClass.prototype[methodName] = function(...args) {
|
|
2108
|
+
const res = original.apply(this, args);
|
|
2109
|
+
if (res !== void 0) {
|
|
2110
|
+
const conf = getElementConfig(this);
|
|
2111
|
+
const currentWin = conf?.window || window;
|
|
2112
|
+
const currentDoc = currentWin.document;
|
|
2113
|
+
let targetEl = null;
|
|
2114
|
+
if (selector === ":host" || !selector) {
|
|
2115
|
+
targetEl = this;
|
|
2116
|
+
} else {
|
|
2117
|
+
targetEl = (this.shadowRoot || this).querySelector(selector);
|
|
2118
|
+
}
|
|
2119
|
+
if (targetEl) {
|
|
2120
|
+
const nodes = Array.isArray(res) ? res : [res];
|
|
2121
|
+
const normalizedNodes = nodes.map((n) => {
|
|
2122
|
+
if (typeof n === "string") {
|
|
2123
|
+
const t = currentDoc.createElement("template");
|
|
2124
|
+
t.innerHTML = n;
|
|
2125
|
+
return t.content;
|
|
2126
|
+
}
|
|
2127
|
+
return n;
|
|
2128
|
+
});
|
|
2129
|
+
const pos = options.position || "lastChild";
|
|
2130
|
+
if (pos === "lastChild")
|
|
2131
|
+
targetEl.append(...normalizedNodes);
|
|
2132
|
+
else if (pos === "firstChild")
|
|
2133
|
+
targetEl.prepend(...normalizedNodes);
|
|
2134
|
+
else if (pos === "nextSibling")
|
|
2135
|
+
targetEl.after(...normalizedNodes);
|
|
2136
|
+
else if (pos === "previousSibling")
|
|
2137
|
+
targetEl.before(...normalizedNodes);
|
|
2138
|
+
}
|
|
2139
|
+
}
|
|
2140
|
+
return res;
|
|
2141
|
+
};
|
|
2142
|
+
}
|
|
2143
|
+
});
|
|
2016
2144
|
const originalProto = constructor.prototype;
|
|
2017
2145
|
const newProto = NewClass.prototype;
|
|
2018
2146
|
Object.getOwnPropertyNames(originalProto).forEach((name) => {
|
|
@@ -2084,6 +2212,22 @@ function query(selector, options = {}) {
|
|
|
2084
2212
|
}
|
|
2085
2213
|
return (this.shadowRoot || this).querySelector(selector);
|
|
2086
2214
|
},
|
|
2215
|
+
set(nv) {
|
|
2216
|
+
if (nv === null || nv === void 0) {
|
|
2217
|
+
const r = options.root || "auto";
|
|
2218
|
+
let targetEl = null;
|
|
2219
|
+
if (r === "shadow")
|
|
2220
|
+
targetEl = this.shadowRoot ? this.shadowRoot.querySelector(selector) : null;
|
|
2221
|
+
else if (r === "light")
|
|
2222
|
+
targetEl = this.querySelector(selector);
|
|
2223
|
+
else if (r === "all")
|
|
2224
|
+
targetEl = this.shadowRoot?.querySelector(selector) || this.querySelector(selector);
|
|
2225
|
+
else
|
|
2226
|
+
targetEl = (this.shadowRoot || this).querySelector(selector);
|
|
2227
|
+
if (targetEl)
|
|
2228
|
+
targetEl.remove();
|
|
2229
|
+
}
|
|
2230
|
+
},
|
|
2087
2231
|
enumerable: true,
|
|
2088
2232
|
configurable: true
|
|
2089
2233
|
});
|
|
@@ -2139,6 +2283,24 @@ function queryAll(selector, options = {}) {
|
|
|
2139
2283
|
const root = this.shadowRoot || this;
|
|
2140
2284
|
return root.querySelectorAll(selector);
|
|
2141
2285
|
},
|
|
2286
|
+
set(nv) {
|
|
2287
|
+
if (nv === null || nv === void 0 || Array.isArray(nv) && nv.length === 0) {
|
|
2288
|
+
const r = options.root || "auto";
|
|
2289
|
+
let targets = [];
|
|
2290
|
+
if (r === "shadow")
|
|
2291
|
+
targets = this.shadowRoot ? Array.from(this.shadowRoot.querySelectorAll(selector)) : [];
|
|
2292
|
+
else if (r === "light")
|
|
2293
|
+
targets = Array.from(this.querySelectorAll(selector));
|
|
2294
|
+
else if (r === "all") {
|
|
2295
|
+
const sNodes = this.shadowRoot ? Array.from(this.shadowRoot.querySelectorAll(selector)) : [];
|
|
2296
|
+
const lNodes = Array.from(this.querySelectorAll(selector));
|
|
2297
|
+
targets = [...sNodes, ...lNodes];
|
|
2298
|
+
} else {
|
|
2299
|
+
targets = Array.from((this.shadowRoot || this).querySelectorAll(selector));
|
|
2300
|
+
}
|
|
2301
|
+
targets.forEach((t) => t.remove());
|
|
2302
|
+
}
|
|
2303
|
+
},
|
|
2142
2304
|
enumerable: true,
|
|
2143
2305
|
configurable: true
|
|
2144
2306
|
});
|
|
@@ -10358,6 +10520,7 @@ SwcApp = __decorate63([
|
|
|
10358
10520
|
], SwcApp);
|
|
10359
10521
|
export {
|
|
10360
10522
|
ADD_EVENT_LISTENER_METADATA_KEY,
|
|
10523
|
+
APPEND_CHILD_METADATA_KEY,
|
|
10361
10524
|
ATTRIBUTE_CHANGED_WILDCARD,
|
|
10362
10525
|
ELEMENT_CONFIG_KEY,
|
|
10363
10526
|
EMIT_CUSTOM_EVENT_METADATA_KEY,
|
|
@@ -10373,6 +10536,7 @@ export {
|
|
|
10373
10536
|
ON_BEFORE_DISCONNECTED_METADATA_KEY,
|
|
10374
10537
|
QUERY_ALL_METADATA_KEY,
|
|
10375
10538
|
QUERY_METADATA_KEY,
|
|
10539
|
+
REPLACE_CHILDREN_METADATA_KEY,
|
|
10376
10540
|
SET_ATTRIBUTE_METADATA_KEY,
|
|
10377
10541
|
SWC_NOT_FOUND,
|
|
10378
10542
|
SwcApp,
|
|
@@ -10446,21 +10610,25 @@ export {
|
|
|
10446
10610
|
SwcUtils,
|
|
10447
10611
|
SwcWhen,
|
|
10448
10612
|
addEventListener,
|
|
10613
|
+
appendChild,
|
|
10449
10614
|
changedAttribute,
|
|
10450
10615
|
elementDefine,
|
|
10451
10616
|
emitCustomEvent,
|
|
10617
|
+
findAllAppendChildMetadata,
|
|
10452
10618
|
findAllAttributeChangedMetadata,
|
|
10453
10619
|
findAllLifecycleMetadata,
|
|
10620
|
+
findAllReplaceChildrenMetadata,
|
|
10454
10621
|
findAllSetAttributeMetadata,
|
|
10455
10622
|
getAddEventListenerMetadata,
|
|
10456
10623
|
getChangedAttributeMetadata,
|
|
10457
10624
|
getElementConfig,
|
|
10458
10625
|
getEmitCustomEventMetadataList,
|
|
10459
|
-
|
|
10626
|
+
getOnConnectedInnerHtmlMetadata,
|
|
10460
10627
|
getQueryAllMetadata,
|
|
10461
10628
|
getQueryMetadata,
|
|
10629
|
+
getReplaceChildrenMetadata,
|
|
10462
10630
|
getSetAttributeMetadata,
|
|
10463
|
-
innerHtml,
|
|
10631
|
+
onConnectedInnerHtml as innerHtml,
|
|
10464
10632
|
onAddEventListener,
|
|
10465
10633
|
onAdopted,
|
|
10466
10634
|
onAfterAdopted,
|
|
@@ -10470,9 +10638,11 @@ export {
|
|
|
10470
10638
|
onBeforeConnected,
|
|
10471
10639
|
onBeforeDisconnected,
|
|
10472
10640
|
onConnected,
|
|
10641
|
+
onConnectedInnerHtml,
|
|
10473
10642
|
onDisconnected,
|
|
10474
10643
|
query,
|
|
10475
10644
|
queryAll,
|
|
10645
|
+
replaceChildren,
|
|
10476
10646
|
setAttribute
|
|
10477
10647
|
};
|
|
10478
10648
|
/*! Bundled license information:
|