@dooboostore/simple-web-component 1.0.16 → 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 +109 -48
- package/dist/cjs/decorators/addEventListener.js.map +2 -2
- package/dist/cjs/decorators/appendChild.js +48 -0
- package/dist/cjs/decorators/appendChild.js.map +7 -0
- package/dist/cjs/decorators/elementDefine.js +216 -67
- package/dist/cjs/decorators/elementDefine.js.map +3 -3
- 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 +38 -0
- package/dist/cjs/decorators/query.js.map +2 -2
- package/dist/cjs/decorators/queryAll.js +32 -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/elements/SwcAppEngine.js +2 -1
- package/dist/cjs/elements/SwcAppEngine.js.map +2 -2
- package/dist/cjs/elements/SwcAsync.js +188 -0
- package/dist/cjs/elements/SwcAsync.js.map +7 -0
- package/dist/cjs/elements/SwcChoose.js +155 -0
- package/dist/cjs/elements/SwcChoose.js.map +7 -0
- package/dist/cjs/elements/SwcIf.js +167 -0
- package/dist/cjs/elements/SwcIf.js.map +7 -0
- package/dist/cjs/elements/SwcLoop.js +246 -0
- package/dist/cjs/elements/SwcLoop.js.map +7 -0
- package/dist/cjs/elements/SwcSubTemplates.js +65 -0
- package/dist/cjs/elements/SwcSubTemplates.js.map +7 -0
- package/dist/cjs/elements/index.js +7 -0
- package/dist/cjs/elements/index.js.map +2 -2
- package/dist/cjs/index.js +12 -2
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/utils/Utils.js +74 -37
- package/dist/cjs/utils/Utils.js.map +3 -3
- package/dist/esm/decorators/addEventListener.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 +216 -67
- package/dist/esm/decorators/elementDefine.js.map +3 -3
- 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 +38 -0
- package/dist/esm/decorators/query.js.map +2 -2
- package/dist/esm/decorators/queryAll.js +32 -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/elements/SwcAppEngine.js +2 -1
- package/dist/esm/elements/SwcAppEngine.js.map +2 -2
- package/dist/esm/elements/SwcAsync.js +169 -0
- package/dist/esm/elements/SwcAsync.js.map +7 -0
- package/dist/esm/elements/SwcChoose.js +136 -0
- package/dist/esm/elements/SwcChoose.js.map +7 -0
- package/dist/esm/elements/SwcIf.js +148 -0
- package/dist/esm/elements/SwcIf.js.map +7 -0
- package/dist/esm/elements/SwcLoop.js +227 -0
- package/dist/esm/elements/SwcLoop.js.map +7 -0
- package/dist/esm/elements/SwcSubTemplates.js +46 -0
- package/dist/esm/elements/SwcSubTemplates.js.map +7 -0
- package/dist/esm/elements/index.js +7 -0
- package/dist/esm/elements/index.js.map +2 -2
- package/dist/esm/index.js +8 -2
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils/Utils.js +74 -37
- package/dist/esm/utils/Utils.js.map +3 -3
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +1226 -149
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
- package/dist/types/decorators/addEventListener.d.ts +1 -0
- package/dist/types/decorators/addEventListener.d.ts.map +1 -1
- 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 +0 -2
- package/dist/types/decorators/query.d.ts.map +1 -1
- package/dist/types/decorators/queryAll.d.ts +0 -2
- 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/elements/SwcAppEngine.d.ts.map +1 -1
- package/dist/types/elements/SwcAsync.d.ts +16 -0
- package/dist/types/elements/SwcAsync.d.ts.map +1 -0
- package/dist/types/elements/SwcChoose.d.ts +13 -0
- package/dist/types/elements/SwcChoose.d.ts.map +1 -0
- package/dist/types/elements/SwcIf.d.ts +15 -0
- package/dist/types/elements/SwcIf.d.ts.map +1 -0
- package/dist/types/elements/SwcLoop.d.ts +20 -0
- package/dist/types/elements/SwcLoop.d.ts.map +1 -0
- package/dist/types/elements/SwcSubTemplates.d.ts +13 -0
- package/dist/types/elements/SwcSubTemplates.d.ts.map +1 -0
- package/dist/types/elements/index.d.ts +7 -0
- package/dist/types/elements/index.d.ts.map +1 -1
- package/dist/types/index.d.ts +5 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types.d.ts +8 -0
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils/Utils.d.ts +16 -10
- package/dist/types/utils/Utils.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +1226 -149
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +10 -3
- package/src/decorators/addEventListener.ts +1 -0
- package/src/decorators/appendChild.ts +42 -0
- package/src/decorators/elementDefine.ts +225 -71
- package/src/decorators/index.ts +2 -1
- package/src/decorators/{innerHtml.ts → onConnectedInnerHtml.ts} +7 -6
- package/src/decorators/query.ts +32 -2
- package/src/decorators/queryAll.ts +32 -2
- package/src/decorators/replaceChildren.ts +35 -0
- package/src/elements/SwcAppEngine.ts +2 -1
- package/src/elements/SwcAsync.ts +163 -0
- package/src/elements/SwcChoose.ts +127 -0
- package/src/elements/SwcIf.ts +134 -0
- package/src/elements/SwcLoop.ts +215 -0
- package/src/elements/SwcSubTemplates.ts +19 -0
- package/src/elements/index.ts +8 -3
- package/src/index.ts +5 -2
- package/src/types.ts +9 -1
- package/src/utils/Utils.ts +86 -36
- 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
|
@@ -1119,6 +1119,7 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
1119
1119
|
var bundle_entry_exports = {};
|
|
1120
1120
|
__export(bundle_entry_exports, {
|
|
1121
1121
|
ADD_EVENT_LISTENER_METADATA_KEY: () => ADD_EVENT_LISTENER_METADATA_KEY,
|
|
1122
|
+
APPEND_CHILD_METADATA_KEY: () => APPEND_CHILD_METADATA_KEY,
|
|
1122
1123
|
ATTRIBUTE_CHANGED_WILDCARD: () => ATTRIBUTE_CHANGED_WILDCARD,
|
|
1123
1124
|
ELEMENT_CONFIG_KEY: () => ELEMENT_CONFIG_KEY,
|
|
1124
1125
|
EMIT_CUSTOM_EVENT_METADATA_KEY: () => EMIT_CUSTOM_EVENT_METADATA_KEY,
|
|
@@ -1134,8 +1135,10 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
1134
1135
|
ON_BEFORE_DISCONNECTED_METADATA_KEY: () => ON_BEFORE_DISCONNECTED_METADATA_KEY,
|
|
1135
1136
|
QUERY_ALL_METADATA_KEY: () => QUERY_ALL_METADATA_KEY,
|
|
1136
1137
|
QUERY_METADATA_KEY: () => QUERY_METADATA_KEY,
|
|
1138
|
+
REPLACE_CHILDREN_METADATA_KEY: () => REPLACE_CHILDREN_METADATA_KEY,
|
|
1137
1139
|
SET_ATTRIBUTE_METADATA_KEY: () => SET_ATTRIBUTE_METADATA_KEY,
|
|
1138
1140
|
SWC_NOT_FOUND: () => SWC_NOT_FOUND,
|
|
1141
|
+
SwcApp: () => SwcApp,
|
|
1139
1142
|
SwcAppAnchor: () => SwcAppAnchor,
|
|
1140
1143
|
SwcAppArea: () => SwcAppArea,
|
|
1141
1144
|
SwcAppAudio: () => SwcAppAudio,
|
|
@@ -1150,6 +1153,7 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
1150
1153
|
SwcAppDiv: () => SwcAppDiv,
|
|
1151
1154
|
SwcAppDl: () => SwcAppDl,
|
|
1152
1155
|
SwcAppEmbed: () => SwcAppEmbed,
|
|
1156
|
+
SwcAppEngine: () => SwcAppEngine,
|
|
1153
1157
|
SwcAppFieldSet: () => SwcAppFieldSet,
|
|
1154
1158
|
SwcAppForm: () => SwcAppForm,
|
|
1155
1159
|
SwcAppHeading: () => SwcAppHeading,
|
|
@@ -1193,23 +1197,37 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
1193
1197
|
SwcAppTrack: () => SwcAppTrack,
|
|
1194
1198
|
SwcAppUl: () => SwcAppUl,
|
|
1195
1199
|
SwcAppVideo: () => SwcAppVideo,
|
|
1200
|
+
SwcAsync: () => SwcAsync,
|
|
1201
|
+
SwcChoose: () => SwcChoose,
|
|
1202
|
+
SwcDefault: () => SwcDefault,
|
|
1203
|
+
SwcError: () => SwcError,
|
|
1204
|
+
SwcIf: () => SwcIf,
|
|
1205
|
+
SwcLoading: () => SwcLoading,
|
|
1206
|
+
SwcLoop: () => SwcLoop,
|
|
1207
|
+
SwcOtherwise: () => SwcOtherwise,
|
|
1208
|
+
SwcSuccess: () => SwcSuccess,
|
|
1196
1209
|
SwcUtils: () => SwcUtils,
|
|
1210
|
+
SwcWhen: () => SwcWhen,
|
|
1197
1211
|
addEventListener: () => addEventListener,
|
|
1212
|
+
appendChild: () => appendChild,
|
|
1198
1213
|
changedAttribute: () => changedAttribute,
|
|
1199
1214
|
elementDefine: () => elementDefine,
|
|
1200
1215
|
emitCustomEvent: () => emitCustomEvent,
|
|
1216
|
+
findAllAppendChildMetadata: () => findAllAppendChildMetadata,
|
|
1201
1217
|
findAllAttributeChangedMetadata: () => findAllAttributeChangedMetadata,
|
|
1202
1218
|
findAllLifecycleMetadata: () => findAllLifecycleMetadata,
|
|
1219
|
+
findAllReplaceChildrenMetadata: () => findAllReplaceChildrenMetadata,
|
|
1203
1220
|
findAllSetAttributeMetadata: () => findAllSetAttributeMetadata,
|
|
1204
1221
|
getAddEventListenerMetadata: () => getAddEventListenerMetadata,
|
|
1205
1222
|
getChangedAttributeMetadata: () => getChangedAttributeMetadata,
|
|
1206
1223
|
getElementConfig: () => getElementConfig,
|
|
1207
1224
|
getEmitCustomEventMetadataList: () => getEmitCustomEventMetadataList,
|
|
1208
|
-
|
|
1225
|
+
getOnConnectedInnerHtmlMetadata: () => getOnConnectedInnerHtmlMetadata,
|
|
1209
1226
|
getQueryAllMetadata: () => getQueryAllMetadata,
|
|
1210
1227
|
getQueryMetadata: () => getQueryMetadata,
|
|
1228
|
+
getReplaceChildrenMetadata: () => getReplaceChildrenMetadata,
|
|
1211
1229
|
getSetAttributeMetadata: () => getSetAttributeMetadata,
|
|
1212
|
-
innerHtml: () =>
|
|
1230
|
+
innerHtml: () => onConnectedInnerHtml,
|
|
1213
1231
|
onAddEventListener: () => onAddEventListener,
|
|
1214
1232
|
onAdopted: () => onAdopted,
|
|
1215
1233
|
onAfterAdopted: () => onAfterAdopted,
|
|
@@ -1219,9 +1237,11 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
1219
1237
|
onBeforeConnected: () => onBeforeConnected,
|
|
1220
1238
|
onBeforeDisconnected: () => onBeforeDisconnected,
|
|
1221
1239
|
onConnected: () => onConnected,
|
|
1240
|
+
onConnectedInnerHtml: () => onConnectedInnerHtml,
|
|
1222
1241
|
onDisconnected: () => onDisconnected,
|
|
1223
1242
|
query: () => query,
|
|
1224
1243
|
queryAll: () => queryAll,
|
|
1244
|
+
replaceChildren: () => replaceChildren,
|
|
1225
1245
|
setAttribute: () => setAttribute
|
|
1226
1246
|
});
|
|
1227
1247
|
var import_reflect_metadata2 = __toESM(require_Reflect(), 1);
|
|
@@ -1230,32 +1250,33 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
1230
1250
|
var import_reflect_metadata = __toESM(require_Reflect(), 1);
|
|
1231
1251
|
|
|
1232
1252
|
// ../core/dist/esm/reflect/ReflectUtils.js
|
|
1233
|
-
var ReflectUtils
|
|
1234
|
-
|
|
1253
|
+
var ReflectUtils;
|
|
1254
|
+
((ReflectUtils2) => {
|
|
1255
|
+
ReflectUtils2.getParameterTypes = (target, propertyKey) => {
|
|
1235
1256
|
if (propertyKey) {
|
|
1236
1257
|
return Reflect.getMetadata("design:paramtypes", target, propertyKey) || [];
|
|
1237
1258
|
} else {
|
|
1238
1259
|
return Reflect.getMetadata("design:paramtypes", target) || [];
|
|
1239
1260
|
}
|
|
1240
|
-
}
|
|
1241
|
-
getReturnType
|
|
1261
|
+
};
|
|
1262
|
+
ReflectUtils2.getReturnType = (target, propertyKey) => {
|
|
1242
1263
|
return Reflect.getMetadata("design:returntype", target, propertyKey);
|
|
1243
|
-
}
|
|
1244
|
-
getType
|
|
1264
|
+
};
|
|
1265
|
+
ReflectUtils2.getType = (target, propertyKey) => {
|
|
1245
1266
|
if (propertyKey) {
|
|
1246
1267
|
return Reflect.getMetadata("design:type", target, propertyKey);
|
|
1247
1268
|
} else {
|
|
1248
1269
|
return Reflect.getMetadata("design:type", target);
|
|
1249
1270
|
}
|
|
1250
|
-
}
|
|
1251
|
-
getMetadata
|
|
1271
|
+
};
|
|
1272
|
+
ReflectUtils2.getMetadata = (metadataKey, target, propertyKey) => {
|
|
1252
1273
|
if (propertyKey) {
|
|
1253
1274
|
return Reflect.getMetadata(metadataKey, target, propertyKey);
|
|
1254
1275
|
} else {
|
|
1255
1276
|
return Reflect.getMetadata(metadataKey, target);
|
|
1256
1277
|
}
|
|
1257
|
-
}
|
|
1258
|
-
findMetadata
|
|
1278
|
+
};
|
|
1279
|
+
ReflectUtils2.findMetadata = (metadataKey, target, propertyKey) => {
|
|
1259
1280
|
if (target == null) return void 0;
|
|
1260
1281
|
let searchTarget = typeof target === "object" && typeof target !== "function" ? target.constructor : target;
|
|
1261
1282
|
while (searchTarget && searchTarget !== Object) {
|
|
@@ -1266,11 +1287,8 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
1266
1287
|
if (searchTarget === target) break;
|
|
1267
1288
|
}
|
|
1268
1289
|
return void 0;
|
|
1269
|
-
}
|
|
1270
|
-
|
|
1271
|
-
* 프로토타입 체인의 모든 메타데이터를 수집하여 리스트로 반환합니다. (부모 -> 자식 순)
|
|
1272
|
-
*/
|
|
1273
|
-
findAllMetadata: (metadataKey, target, propertyKey) => {
|
|
1290
|
+
};
|
|
1291
|
+
ReflectUtils2.findAllMetadata = (metadataKey, target, propertyKey) => {
|
|
1274
1292
|
const results = [];
|
|
1275
1293
|
if (target == null) return results;
|
|
1276
1294
|
let searchTarget = typeof target === "object" && typeof target !== "function" ? target.constructor : target;
|
|
@@ -1282,24 +1300,18 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
1282
1300
|
if (searchTarget === target) break;
|
|
1283
1301
|
}
|
|
1284
1302
|
return results;
|
|
1285
|
-
}
|
|
1286
|
-
|
|
1287
|
-
* 모든 메타데이터(배열 형태)를 수집하여 하나의 배열로 합칩니다. (부모 -> 자식 순)
|
|
1288
|
-
*/
|
|
1289
|
-
findAllMetadataFlatten: (metadataKey, target, propertyKey) => {
|
|
1303
|
+
};
|
|
1304
|
+
ReflectUtils2.findAllMetadataFlatten = (metadataKey, target, propertyKey) => {
|
|
1290
1305
|
const results = [];
|
|
1291
|
-
const metaList =
|
|
1306
|
+
const metaList = (0, ReflectUtils2.findAllMetadata)(metadataKey, target, propertyKey);
|
|
1292
1307
|
metaList.forEach((data) => {
|
|
1293
1308
|
if (Array.isArray(data)) results.push(...data);
|
|
1294
1309
|
});
|
|
1295
1310
|
return [...new Set(results)];
|
|
1296
|
-
}
|
|
1297
|
-
|
|
1298
|
-
* 프로토타입 체인의 모든 메타데이터(맵 형태)를 수집하여 합칩니다. (부모 -> 자식 순)
|
|
1299
|
-
*/
|
|
1300
|
-
findAllMapMetadata: (metadataKey, target) => {
|
|
1311
|
+
};
|
|
1312
|
+
ReflectUtils2.findAllMapMetadata = (metadataKey, target) => {
|
|
1301
1313
|
const finalMap = /* @__PURE__ */ new Map();
|
|
1302
|
-
const metaList =
|
|
1314
|
+
const metaList = (0, ReflectUtils2.findAllMetadata)(metadataKey, target);
|
|
1303
1315
|
metaList.forEach((data) => {
|
|
1304
1316
|
if (data instanceof Map) {
|
|
1305
1317
|
data.forEach((values, key) => {
|
|
@@ -1310,35 +1322,73 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
1310
1322
|
}
|
|
1311
1323
|
});
|
|
1312
1324
|
return finalMap;
|
|
1313
|
-
}
|
|
1314
|
-
getMetadataKeys
|
|
1325
|
+
};
|
|
1326
|
+
ReflectUtils2.getMetadataKeys = (target) => {
|
|
1315
1327
|
return Reflect.getMetadataKeys(target);
|
|
1316
|
-
}
|
|
1317
|
-
getOwnMetadata
|
|
1328
|
+
};
|
|
1329
|
+
ReflectUtils2.getOwnMetadata = (metadataKey, target, propertyKey) => {
|
|
1318
1330
|
if (propertyKey) {
|
|
1319
1331
|
return Reflect.getOwnMetadata(metadataKey, target, propertyKey);
|
|
1320
1332
|
} else {
|
|
1321
1333
|
return Reflect.getOwnMetadata(metadataKey, target);
|
|
1322
1334
|
}
|
|
1323
|
-
}
|
|
1324
|
-
getMetadatas
|
|
1325
|
-
return
|
|
1326
|
-
}
|
|
1327
|
-
metadata
|
|
1335
|
+
};
|
|
1336
|
+
ReflectUtils2.getMetadatas = (target) => {
|
|
1337
|
+
return (0, ReflectUtils2.getMetadataKeys)(target).map((it) => (0, ReflectUtils2.getMetadata)(it, target));
|
|
1338
|
+
};
|
|
1339
|
+
ReflectUtils2.metadata = (metadataKey, data) => {
|
|
1328
1340
|
return Reflect.metadata(metadataKey, data);
|
|
1329
|
-
}
|
|
1330
|
-
defineMetadata
|
|
1341
|
+
};
|
|
1342
|
+
ReflectUtils2.defineMetadata = (metadataKey, value, target, propertyKey) => {
|
|
1331
1343
|
if (propertyKey && Reflect.defineMetadata) {
|
|
1332
1344
|
Reflect.defineMetadata(metadataKey, value, target, propertyKey);
|
|
1333
1345
|
} else if (Reflect.defineMetadata) {
|
|
1334
1346
|
Reflect.defineMetadata(metadataKey, value, target);
|
|
1335
1347
|
}
|
|
1336
|
-
}
|
|
1337
|
-
};
|
|
1348
|
+
};
|
|
1349
|
+
})(ReflectUtils || (ReflectUtils = {}));
|
|
1350
|
+
|
|
1351
|
+
// ../core/dist/esm/function/FunctionUtils.js
|
|
1352
|
+
var FunctionUtils;
|
|
1353
|
+
((FunctionUtils2) => {
|
|
1354
|
+
FunctionUtils2.getParameterNames = (func, property) => {
|
|
1355
|
+
if (typeof func === "object" && property) {
|
|
1356
|
+
func = func[property];
|
|
1357
|
+
}
|
|
1358
|
+
return new RegExp("(?:" + func.name + "\\s*|^)\\s*\\((.*?)\\)").exec(func.toString().replace(/\n/g, ""))?.[1].replace(/\/\*.*?\*\//g, "").replace(/ /g, "").split(",") ?? [];
|
|
1359
|
+
};
|
|
1360
|
+
FunctionUtils2.evalScript = (script, obj) => {
|
|
1361
|
+
try {
|
|
1362
|
+
if (script && obj) {
|
|
1363
|
+
return Function(`"use strict";
|
|
1364
|
+
${script}
|
|
1365
|
+
`).bind(obj)();
|
|
1366
|
+
} else if (script) {
|
|
1367
|
+
return new Function("return " + script)();
|
|
1368
|
+
} else {
|
|
1369
|
+
return null;
|
|
1370
|
+
}
|
|
1371
|
+
} catch (e) {
|
|
1372
|
+
return null;
|
|
1373
|
+
}
|
|
1374
|
+
};
|
|
1375
|
+
FunctionUtils2.execute = (params) => {
|
|
1376
|
+
const { script, context, args = {} } = params;
|
|
1377
|
+
const argNames = Object.keys(args);
|
|
1378
|
+
const argValues = Object.values(args);
|
|
1379
|
+
return new Function(...argNames, script).apply(context, argValues);
|
|
1380
|
+
};
|
|
1381
|
+
FunctionUtils2.executeReturn = (params) => {
|
|
1382
|
+
const { script, context, args = {} } = params;
|
|
1383
|
+
const argNames = Object.keys(args);
|
|
1384
|
+
const argValues = Object.values(args);
|
|
1385
|
+
return new Function(...argNames, `return ${script}`).apply(context, argValues);
|
|
1386
|
+
};
|
|
1387
|
+
})(FunctionUtils || (FunctionUtils = {}));
|
|
1338
1388
|
|
|
1339
|
-
// src/decorators/
|
|
1389
|
+
// src/decorators/onConnectedInnerHtml.ts
|
|
1340
1390
|
var INNER_HTML_METADATA_KEY = Symbol("simple-web-component:inner-html");
|
|
1341
|
-
function
|
|
1391
|
+
function onConnectedInnerHtml(arg1, arg2, arg3) {
|
|
1342
1392
|
const decorator = (options, target, propertyKey) => {
|
|
1343
1393
|
const constructor = target.constructor;
|
|
1344
1394
|
let list = ReflectUtils.getMetadata(INNER_HTML_METADATA_KEY, constructor);
|
|
@@ -1355,7 +1405,7 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
1355
1405
|
decorator(arg1 || {}, target, propertyKey);
|
|
1356
1406
|
};
|
|
1357
1407
|
}
|
|
1358
|
-
var
|
|
1408
|
+
var getOnConnectedInnerHtmlMetadata = (target) => {
|
|
1359
1409
|
const constructor = target instanceof Function ? target : target.constructor;
|
|
1360
1410
|
return ReflectUtils.getMetadata(INNER_HTML_METADATA_KEY, constructor);
|
|
1361
1411
|
};
|
|
@@ -1492,10 +1542,81 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
1492
1542
|
return result;
|
|
1493
1543
|
};
|
|
1494
1544
|
|
|
1545
|
+
// src/decorators/replaceChildren.ts
|
|
1546
|
+
var REPLACE_CHILDREN_METADATA_KEY = Symbol("simple-web-component:replace-children");
|
|
1547
|
+
function replaceChildren(selector) {
|
|
1548
|
+
return (target, propertyKey) => {
|
|
1549
|
+
const constructor = target.constructor;
|
|
1550
|
+
let meta = ReflectUtils.getOwnMetadata(REPLACE_CHILDREN_METADATA_KEY, constructor);
|
|
1551
|
+
if (!meta) {
|
|
1552
|
+
meta = /* @__PURE__ */ new Map();
|
|
1553
|
+
ReflectUtils.defineMetadata(REPLACE_CHILDREN_METADATA_KEY, meta, constructor);
|
|
1554
|
+
}
|
|
1555
|
+
meta.set(propertyKey, selector);
|
|
1556
|
+
};
|
|
1557
|
+
}
|
|
1558
|
+
var getReplaceChildrenMetadata = (target) => {
|
|
1559
|
+
const constructor = target instanceof Function ? target : target.constructor;
|
|
1560
|
+
return ReflectUtils.getMetadata(REPLACE_CHILDREN_METADATA_KEY, constructor);
|
|
1561
|
+
};
|
|
1562
|
+
var findAllReplaceChildrenMetadata = (target) => {
|
|
1563
|
+
const result = /* @__PURE__ */ new Map();
|
|
1564
|
+
const maps = ReflectUtils.findAllMetadata(REPLACE_CHILDREN_METADATA_KEY, target);
|
|
1565
|
+
maps.forEach((map) => {
|
|
1566
|
+
if (map instanceof Map) {
|
|
1567
|
+
map.forEach((v, k) => result.set(k, v));
|
|
1568
|
+
}
|
|
1569
|
+
});
|
|
1570
|
+
return result;
|
|
1571
|
+
};
|
|
1572
|
+
|
|
1573
|
+
// src/decorators/appendChild.ts
|
|
1574
|
+
var APPEND_CHILD_METADATA_KEY = Symbol("simple-web-component:append-child");
|
|
1575
|
+
function appendChild(selector, options = { position: "lastChild" }) {
|
|
1576
|
+
return (target, propertyKey) => {
|
|
1577
|
+
const constructor = target.constructor;
|
|
1578
|
+
let meta = ReflectUtils.getOwnMetadata(APPEND_CHILD_METADATA_KEY, constructor);
|
|
1579
|
+
if (!meta) {
|
|
1580
|
+
meta = /* @__PURE__ */ new Map();
|
|
1581
|
+
ReflectUtils.defineMetadata(APPEND_CHILD_METADATA_KEY, meta, constructor);
|
|
1582
|
+
}
|
|
1583
|
+
meta.set(propertyKey, { propertyKey, selector, options });
|
|
1584
|
+
};
|
|
1585
|
+
}
|
|
1586
|
+
var findAllAppendChildMetadata = (target) => {
|
|
1587
|
+
const result = /* @__PURE__ */ new Map();
|
|
1588
|
+
const maps = ReflectUtils.findAllMetadata(APPEND_CHILD_METADATA_KEY, target);
|
|
1589
|
+
maps.forEach((map) => {
|
|
1590
|
+
if (map instanceof Map) {
|
|
1591
|
+
map.forEach((v, k) => result.set(k, v));
|
|
1592
|
+
}
|
|
1593
|
+
});
|
|
1594
|
+
return result;
|
|
1595
|
+
};
|
|
1596
|
+
|
|
1495
1597
|
// src/utils/Utils.ts
|
|
1496
1598
|
var SWC_NOT_FOUND = Symbol("SWC_NOT_FOUND");
|
|
1497
|
-
var SwcUtils
|
|
1498
|
-
|
|
1599
|
+
var SwcUtils;
|
|
1600
|
+
((SwcUtils2) => {
|
|
1601
|
+
SwcUtils2.getHelperSet = (win) => {
|
|
1602
|
+
const doc = win.document;
|
|
1603
|
+
return {
|
|
1604
|
+
$d: doc,
|
|
1605
|
+
$w: win,
|
|
1606
|
+
$q: (sel, root) => (root ?? doc).querySelector(sel),
|
|
1607
|
+
$qa: (sel, root) => Array.from((root ?? doc).querySelectorAll(sel)),
|
|
1608
|
+
$qi: (id, root) => (root ?? doc).getElementById(id)
|
|
1609
|
+
};
|
|
1610
|
+
};
|
|
1611
|
+
SwcUtils2.getHelperAndHostSet = (win, el) => {
|
|
1612
|
+
const helperSet = (0, SwcUtils2.getHelperSet)(win);
|
|
1613
|
+
const hostSet = (0, SwcUtils2.getHostSet)(el);
|
|
1614
|
+
return {
|
|
1615
|
+
...helperSet,
|
|
1616
|
+
...hostSet
|
|
1617
|
+
};
|
|
1618
|
+
};
|
|
1619
|
+
SwcUtils2.getValueByPath = (obj, path, rootName) => {
|
|
1499
1620
|
if (!obj || !path) return SWC_NOT_FOUND;
|
|
1500
1621
|
const parts = path.split(".");
|
|
1501
1622
|
let current = obj;
|
|
@@ -1504,49 +1625,66 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
1504
1625
|
current = current[part];
|
|
1505
1626
|
}
|
|
1506
1627
|
return current;
|
|
1507
|
-
}
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
current =
|
|
1511
|
-
while (current) {
|
|
1628
|
+
};
|
|
1629
|
+
SwcUtils2.findNearestSwcHost = (el) => {
|
|
1630
|
+
if (el.__swc_host) return el.__swc_host;
|
|
1631
|
+
let current = el.parentElement || el.getRootNode?.()?.host;
|
|
1632
|
+
while (current && current !== document && current !== window) {
|
|
1633
|
+
if (current.__swc_host) return current.__swc_host;
|
|
1512
1634
|
if (getElementConfig(current)) return current;
|
|
1513
|
-
current = current.parentElement || current?.
|
|
1635
|
+
current = current.parentElement || current.getRootNode?.()?.host;
|
|
1514
1636
|
}
|
|
1515
1637
|
return void 0;
|
|
1516
|
-
}
|
|
1517
|
-
|
|
1518
|
-
* Returns all SWC ancestors (excluding self) in [root, ..., parent] order.
|
|
1519
|
-
*/
|
|
1520
|
-
static findAllSwcHosts(el) {
|
|
1638
|
+
};
|
|
1639
|
+
SwcUtils2.findAllSwcHosts = (el) => {
|
|
1521
1640
|
const hosts = [];
|
|
1522
|
-
let current =
|
|
1641
|
+
let current = (0, SwcUtils2.findNearestSwcHost)(el);
|
|
1523
1642
|
while (current) {
|
|
1524
1643
|
hosts.push(current);
|
|
1525
|
-
current =
|
|
1644
|
+
current = (0, SwcUtils2.findNearestSwcHost)(current);
|
|
1526
1645
|
}
|
|
1527
1646
|
return hosts.reverse();
|
|
1528
|
-
}
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1647
|
+
};
|
|
1648
|
+
SwcUtils2.getHosts = (el) => {
|
|
1649
|
+
const ancestors = (0, SwcUtils2.findAllSwcHosts)(el);
|
|
1650
|
+
if (getElementConfig(el)) return [...ancestors, el];
|
|
1651
|
+
return ancestors;
|
|
1652
|
+
};
|
|
1653
|
+
SwcUtils2.getHost = (el) => {
|
|
1654
|
+
if (getElementConfig(el)) return el;
|
|
1655
|
+
return (0, SwcUtils2.findNearestSwcHost)(el);
|
|
1656
|
+
};
|
|
1657
|
+
SwcUtils2.getAppHosts = (el) => {
|
|
1658
|
+
const hosts = (0, SwcUtils2.getHosts)(el);
|
|
1537
1659
|
return hosts.filter((host) => host.tagName.toLowerCase() === "swc-app" || host.getAttribute("is")?.startsWith("swc-app-"));
|
|
1538
|
-
}
|
|
1539
|
-
|
|
1540
|
-
const appHosts =
|
|
1660
|
+
};
|
|
1661
|
+
SwcUtils2.getAppHost = (el) => {
|
|
1662
|
+
const appHosts = (0, SwcUtils2.getAppHosts)(el);
|
|
1541
1663
|
const appHostsWithoutSelf = appHosts.filter((h) => h !== el);
|
|
1542
1664
|
return appHostsWithoutSelf.length > 0 ? appHostsWithoutSelf[appHostsWithoutSelf.length - 1] : void 0;
|
|
1543
|
-
}
|
|
1544
|
-
|
|
1545
|
-
const
|
|
1546
|
-
const
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1665
|
+
};
|
|
1666
|
+
SwcUtils2.getHostSet = (el) => {
|
|
1667
|
+
const isSwc = !!getElementConfig(el);
|
|
1668
|
+
const ancestors = (0, SwcUtils2.findAllSwcHosts)(el);
|
|
1669
|
+
let $host;
|
|
1670
|
+
let $parentHost;
|
|
1671
|
+
if (isSwc) {
|
|
1672
|
+
$host = el;
|
|
1673
|
+
$parentHost = ancestors.length > 0 ? ancestors[ancestors.length - 1] : null;
|
|
1674
|
+
} else {
|
|
1675
|
+
$host = ancestors.length > 0 ? ancestors[ancestors.length - 1] : el;
|
|
1676
|
+
$parentHost = ancestors.length > 1 ? ancestors[ancestors.length - 2] : null;
|
|
1677
|
+
}
|
|
1678
|
+
const $hosts = isSwc ? [...ancestors, el] : ancestors;
|
|
1679
|
+
const $firstHost = $hosts.length > 0 ? $hosts[0] : null;
|
|
1680
|
+
const loopContext = {};
|
|
1681
|
+
let curr = el;
|
|
1682
|
+
while (curr && curr !== document.documentElement) {
|
|
1683
|
+
if (curr.__swc_loop_context) {
|
|
1684
|
+
Object.assign(loopContext, curr.__swc_loop_context);
|
|
1685
|
+
}
|
|
1686
|
+
curr = curr.parentElement || curr.getRootNode().host;
|
|
1687
|
+
}
|
|
1550
1688
|
const $appHosts = $hosts.filter((h) => h.tagName.toLowerCase() === "swc-app" || h.getAttribute("is")?.startsWith("swc-app-"));
|
|
1551
1689
|
const $appHost = $appHosts.length > 0 ? $appHosts[$appHosts.length - 1] === el ? $appHosts.length > 1 ? $appHosts[$appHosts.length - 2] : null : $appHosts[$appHosts.length - 1] : null;
|
|
1552
1690
|
const $firstAppHost = $appHosts.length > 0 ? $appHosts[0] : null;
|
|
@@ -1559,10 +1697,11 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
1559
1697
|
$appHost,
|
|
1560
1698
|
$appHosts,
|
|
1561
1699
|
$firstAppHost,
|
|
1562
|
-
$lastAppHost: $appHost
|
|
1700
|
+
$lastAppHost: $appHost,
|
|
1701
|
+
...loopContext
|
|
1563
1702
|
};
|
|
1564
|
-
}
|
|
1565
|
-
};
|
|
1703
|
+
};
|
|
1704
|
+
})(SwcUtils || (SwcUtils = {}));
|
|
1566
1705
|
|
|
1567
1706
|
// src/config/config.ts
|
|
1568
1707
|
var HTML_TAG_ENTRIES = [
|
|
@@ -1685,6 +1824,7 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
1685
1824
|
|
|
1686
1825
|
// src/decorators/elementDefine.ts
|
|
1687
1826
|
var ELEMENT_CONFIG_KEY = Symbol("simple-web-component:element-config");
|
|
1827
|
+
var globalDelegatedRoots = /* @__PURE__ */ new WeakSet();
|
|
1688
1828
|
function buildEnv(configWindow) {
|
|
1689
1829
|
const win = configWindow || (typeof window !== "undefined" ? window : void 0);
|
|
1690
1830
|
const doc = win?.document;
|
|
@@ -1693,13 +1833,7 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
1693
1833
|
if (win?.[cls])
|
|
1694
1834
|
builtInTagMap.set(win[cls], tag);
|
|
1695
1835
|
}
|
|
1696
|
-
const domHelpers =
|
|
1697
|
-
$d: doc,
|
|
1698
|
-
$w: win,
|
|
1699
|
-
$q: (sel, root) => (root ?? doc).querySelector(sel),
|
|
1700
|
-
$qa: (sel, root) => Array.from((root ?? doc).querySelectorAll(sel)),
|
|
1701
|
-
$qi: (id, root) => (root ?? doc).getElementById(id)
|
|
1702
|
-
};
|
|
1836
|
+
const domHelpers = SwcUtils.getHelperSet(win);
|
|
1703
1837
|
return { win, doc, builtInTagMap, domHelpers };
|
|
1704
1838
|
}
|
|
1705
1839
|
var getHandlers = (inst) => {
|
|
@@ -1711,8 +1845,6 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
1711
1845
|
const config = typeof inConfig === "string" ? { name: inConfig } : inConfig;
|
|
1712
1846
|
const { win, doc, builtInTagMap: BUILT_IN_TAG_MAP, domHelpers: SWC_DOM_HELPERS } = buildEnv(config.window);
|
|
1713
1847
|
config.window = win;
|
|
1714
|
-
const SWC_DOM_HELPER_KEYS = Object.keys(SWC_DOM_HELPERS);
|
|
1715
|
-
const SWC_DOM_HELPER_VALS = () => SWC_DOM_HELPER_KEYS.map((k) => SWC_DOM_HELPERS[k]);
|
|
1716
1848
|
let extendsTagName = config.extends;
|
|
1717
1849
|
if (!extendsTagName) {
|
|
1718
1850
|
let proto = constructor;
|
|
@@ -1728,19 +1860,19 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
1728
1860
|
const addEventListenerList = getAddEventListenerMetadata(constructor) || [];
|
|
1729
1861
|
const attrChangeMap = findAllAttributeChangedMetadata(constructor);
|
|
1730
1862
|
const setAttrMap = findAllSetAttributeMetadata(constructor);
|
|
1863
|
+
const replaceChildrenMap = findAllReplaceChildrenMetadata(constructor);
|
|
1864
|
+
const appendChildMap = findAllAppendChildMetadata(constructor);
|
|
1731
1865
|
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"];
|
|
1732
1866
|
const swcOnEvents = DOM_EVENT_NAMES.map((e) => `swc-on-${e}`);
|
|
1733
1867
|
const mergedObservedAttributes = [.../* @__PURE__ */ new Set([...config.observedAttributes ?? [], ...attrChangeMap.keys(), ...setAttrMap.keys(), ...emitCustomEventList.map((it) => it.options.attributeName), ...swcLifecycleAttributes, ...swcOnEvents])];
|
|
1734
|
-
const
|
|
1868
|
+
const connectedInnerHtmlList = getOnConnectedInnerHtmlMetadata(constructor) || [];
|
|
1735
1869
|
const NewClass = class extends constructor {
|
|
1736
1870
|
_executeSwcScript(attrName, hostSet, extraArgs = {}) {
|
|
1737
1871
|
const script = this.getAttribute(attrName);
|
|
1738
1872
|
if (script) {
|
|
1739
1873
|
try {
|
|
1740
1874
|
const args = { ...hostSet, ...SWC_DOM_HELPERS, ...extraArgs };
|
|
1741
|
-
|
|
1742
|
-
const argValues = Object.values(args);
|
|
1743
|
-
new Function(...argNames, script).apply(this, argValues);
|
|
1875
|
+
FunctionUtils.execute({ script, context: this, args });
|
|
1744
1876
|
} catch (e) {
|
|
1745
1877
|
console.error(`[SWC] Failed to execute ${attrName}:`, e);
|
|
1746
1878
|
}
|
|
@@ -1782,9 +1914,13 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
1782
1914
|
el.removeEventListener(eventName, oldHandler);
|
|
1783
1915
|
const handler = (event) => {
|
|
1784
1916
|
const hostSet = SwcUtils.getHostSet(el);
|
|
1785
|
-
const
|
|
1786
|
-
|
|
1787
|
-
|
|
1917
|
+
const args = {
|
|
1918
|
+
event,
|
|
1919
|
+
$data: event.detail,
|
|
1920
|
+
...hostSet,
|
|
1921
|
+
...SWC_DOM_HELPERS
|
|
1922
|
+
};
|
|
1923
|
+
FunctionUtils.execute({ script, context: el, args });
|
|
1788
1924
|
};
|
|
1789
1925
|
el.addEventListener(eventName, handler);
|
|
1790
1926
|
handlers.set(attrName, handler);
|
|
@@ -1793,9 +1929,10 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
1793
1929
|
super(...args);
|
|
1794
1930
|
this._swcId = Math.random().toString(36).substring(2, 11);
|
|
1795
1931
|
this._emitHandlers = /* @__PURE__ */ new Map();
|
|
1932
|
+
this._boundListeners = [];
|
|
1796
1933
|
const hostSet = SwcUtils.getHostSet(this);
|
|
1797
1934
|
this._executeSwcScript("swc-on-constructor", hostSet);
|
|
1798
|
-
if (
|
|
1935
|
+
if (connectedInnerHtmlList.some((it) => it.options.useShadow === true) && !this.shadowRoot) {
|
|
1799
1936
|
this.attachShadow({ mode: "open" });
|
|
1800
1937
|
}
|
|
1801
1938
|
}
|
|
@@ -1803,6 +1940,9 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
1803
1940
|
return mergedObservedAttributes;
|
|
1804
1941
|
}
|
|
1805
1942
|
async connectedCallback() {
|
|
1943
|
+
const conf = getElementConfig(this);
|
|
1944
|
+
const currentWin = conf?.window || window;
|
|
1945
|
+
const currentDoc = currentWin.document;
|
|
1806
1946
|
const hostSet = SwcUtils.getHostSet(this);
|
|
1807
1947
|
this._executeSwcScript("swc-on-before-connected", hostSet);
|
|
1808
1948
|
const bMethods = findAllLifecycleMetadata(this, ON_BEFORE_CONNECTED_METADATA_KEY);
|
|
@@ -1812,9 +1952,9 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
1812
1952
|
}
|
|
1813
1953
|
if (typeof this.initCore === "function")
|
|
1814
1954
|
this.initCore();
|
|
1815
|
-
if (
|
|
1955
|
+
if (connectedInnerHtmlList.length > 0) {
|
|
1816
1956
|
let sContent = "", lContent = "";
|
|
1817
|
-
for (const meta of
|
|
1957
|
+
for (const meta of connectedInnerHtmlList) {
|
|
1818
1958
|
const res = await this[meta.propertyKey]();
|
|
1819
1959
|
if (res !== void 0) {
|
|
1820
1960
|
if (meta.options.useShadow)
|
|
@@ -1828,17 +1968,88 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
1828
1968
|
if (lContent)
|
|
1829
1969
|
this.innerHTML = lContent;
|
|
1830
1970
|
}
|
|
1971
|
+
const createDelegationHandler = (delegateHost) => (event) => {
|
|
1972
|
+
if (event.__swc_handled)
|
|
1973
|
+
return;
|
|
1974
|
+
const path = event.composedPath();
|
|
1975
|
+
const type = event.type;
|
|
1976
|
+
const attrName = `swc-on-${type}`;
|
|
1977
|
+
for (const node of path) {
|
|
1978
|
+
if (node === delegateHost)
|
|
1979
|
+
break;
|
|
1980
|
+
if (!(node instanceof HTMLElement))
|
|
1981
|
+
continue;
|
|
1982
|
+
const script = node.getAttribute?.(attrName);
|
|
1983
|
+
if (script && !getElementConfig(node)) {
|
|
1984
|
+
const host = SwcUtils.findNearestSwcHost(node);
|
|
1985
|
+
if (host) {
|
|
1986
|
+
const childHostSet = SwcUtils.getHostSet(node);
|
|
1987
|
+
const args = {
|
|
1988
|
+
event,
|
|
1989
|
+
$data: event.detail,
|
|
1990
|
+
...childHostSet,
|
|
1991
|
+
...SWC_DOM_HELPERS
|
|
1992
|
+
};
|
|
1993
|
+
FunctionUtils.execute({ script, context: node, args });
|
|
1994
|
+
event.__swc_handled = true;
|
|
1995
|
+
break;
|
|
1996
|
+
}
|
|
1997
|
+
}
|
|
1998
|
+
}
|
|
1999
|
+
};
|
|
2000
|
+
DOM_EVENT_NAMES.forEach((type) => {
|
|
2001
|
+
const handler = createDelegationHandler(this);
|
|
2002
|
+
this.addEventListener(type, handler);
|
|
2003
|
+
this._boundListeners.push({ target: this, type, handler });
|
|
2004
|
+
});
|
|
2005
|
+
const hasParentHost = SwcUtils.findAllSwcHosts(this).length > 0;
|
|
2006
|
+
if (!hasParentHost) {
|
|
2007
|
+
const root = this.getRootNode();
|
|
2008
|
+
if (!globalDelegatedRoots.has(root)) {
|
|
2009
|
+
DOM_EVENT_NAMES.forEach((type) => {
|
|
2010
|
+
const handler = createDelegationHandler(root);
|
|
2011
|
+
root.addEventListener(type, handler);
|
|
2012
|
+
});
|
|
2013
|
+
globalDelegatedRoots.add(root);
|
|
2014
|
+
}
|
|
2015
|
+
}
|
|
1831
2016
|
addEventListenerList.forEach((meta) => {
|
|
1832
2017
|
const { selector, type, options } = meta;
|
|
1833
|
-
const { root, capture, once, passive, stopPropagation, stopImmediatePropagation, preventDefault, delegate } = options;
|
|
1834
|
-
|
|
2018
|
+
const { root, capture, once, passive, stopPropagation, stopImmediatePropagation, preventDefault, delegate, removeOnDisconnected } = options;
|
|
2019
|
+
const opts = { capture, once, passive };
|
|
2020
|
+
const bindTargets = [];
|
|
2021
|
+
if (selector === ":window") {
|
|
2022
|
+
bindTargets.push(currentWin);
|
|
2023
|
+
} else if (selector === ":document") {
|
|
2024
|
+
bindTargets.push(currentDoc);
|
|
2025
|
+
} else if (selector === ":parentHost") {
|
|
2026
|
+
if (hostSet.$parentHost)
|
|
2027
|
+
bindTargets.push(hostSet.$parentHost);
|
|
2028
|
+
} else if (selector === ":appHost") {
|
|
2029
|
+
if (hostSet.$appHost)
|
|
2030
|
+
bindTargets.push(hostSet.$appHost);
|
|
2031
|
+
} else if (selector === ":firstHost") {
|
|
2032
|
+
if (hostSet.$firstHost)
|
|
2033
|
+
bindTargets.push(hostSet.$firstHost);
|
|
2034
|
+
} else if (selector === ":lastHost") {
|
|
2035
|
+
if (hostSet.$lastHost)
|
|
2036
|
+
bindTargets.push(hostSet.$lastHost);
|
|
2037
|
+
} else if (selector === ":firstAppHost") {
|
|
2038
|
+
if (hostSet.$firstAppHost)
|
|
2039
|
+
bindTargets.push(hostSet.$firstAppHost);
|
|
2040
|
+
} else if (selector === ":lastAppHost") {
|
|
2041
|
+
if (hostSet.$lastAppHost)
|
|
2042
|
+
bindTargets.push(hostSet.$lastAppHost);
|
|
2043
|
+
} else if (!selector || selector === ":host") {
|
|
2044
|
+
bindTargets.push(this);
|
|
2045
|
+
} else if (delegate) {
|
|
1835
2046
|
const bindRoots = [];
|
|
1836
2047
|
const r = root || "auto";
|
|
1837
|
-
if (r === "auto")
|
|
2048
|
+
if (r === "auto")
|
|
1838
2049
|
bindRoots.push(this.shadowRoot || this);
|
|
1839
|
-
|
|
2050
|
+
else if (r === "light")
|
|
1840
2051
|
bindRoots.push(this);
|
|
1841
|
-
|
|
2052
|
+
else if (r === "shadow") {
|
|
1842
2053
|
if (this.shadowRoot)
|
|
1843
2054
|
bindRoots.push(this.shadowRoot);
|
|
1844
2055
|
} else if (r === "all") {
|
|
@@ -1846,62 +2057,61 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
1846
2057
|
if (this.shadowRoot)
|
|
1847
2058
|
bindRoots.push(this.shadowRoot);
|
|
1848
2059
|
}
|
|
1849
|
-
bindRoots.forEach((
|
|
2060
|
+
bindRoots.forEach((br) => {
|
|
1850
2061
|
const handler = (event) => {
|
|
1851
|
-
const
|
|
1852
|
-
|
|
1853
|
-
if (matchedEl && bindRoot.contains(matchedEl)) {
|
|
2062
|
+
const matchedEl = event.target.closest(selector);
|
|
2063
|
+
if (matchedEl && br.contains(matchedEl)) {
|
|
1854
2064
|
if (stopPropagation)
|
|
1855
2065
|
event.stopPropagation();
|
|
1856
2066
|
if (stopImmediatePropagation)
|
|
1857
2067
|
event.stopImmediatePropagation();
|
|
1858
2068
|
if (preventDefault)
|
|
1859
2069
|
event.preventDefault();
|
|
1860
|
-
const
|
|
1861
|
-
this._invokeLifecycleMethod(meta.propertyKey,
|
|
2070
|
+
const currentHostSet = SwcUtils.getHostSet(this);
|
|
2071
|
+
this._invokeLifecycleMethod(meta.propertyKey, currentHostSet, [event, currentHostSet, matchedEl]);
|
|
1862
2072
|
}
|
|
1863
2073
|
};
|
|
1864
|
-
|
|
2074
|
+
br.addEventListener(type, handler, opts);
|
|
2075
|
+
const self2 = this;
|
|
2076
|
+
if (removeOnDisconnected === true || br !== self2 && br !== self2.shadowRoot) {
|
|
2077
|
+
this._boundListeners.push({ target: br, type, handler, options: opts });
|
|
2078
|
+
}
|
|
1865
2079
|
});
|
|
1866
2080
|
} else {
|
|
1867
|
-
const
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
} else if (r === "all") {
|
|
1881
|
-
searchRoots.push(this);
|
|
1882
|
-
if (this.shadowRoot)
|
|
1883
|
-
searchRoots.push(this.shadowRoot);
|
|
1884
|
-
}
|
|
1885
|
-
searchRoots.forEach((sr) => {
|
|
1886
|
-
const found = sr.querySelectorAll(selector);
|
|
1887
|
-
found.forEach((el) => targetEls.push(el));
|
|
1888
|
-
});
|
|
2081
|
+
const searchRoots = [];
|
|
2082
|
+
const r = root || "auto";
|
|
2083
|
+
if (r === "auto")
|
|
2084
|
+
searchRoots.push(this.shadowRoot || this);
|
|
2085
|
+
else if (r === "light")
|
|
2086
|
+
searchRoots.push(this);
|
|
2087
|
+
else if (r === "shadow") {
|
|
2088
|
+
if (this.shadowRoot)
|
|
2089
|
+
searchRoots.push(this.shadowRoot);
|
|
2090
|
+
} else if (r === "all") {
|
|
2091
|
+
searchRoots.push(this);
|
|
2092
|
+
if (this.shadowRoot)
|
|
2093
|
+
searchRoots.push(this.shadowRoot);
|
|
1889
2094
|
}
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
if (stopPropagation)
|
|
1893
|
-
event.stopPropagation();
|
|
1894
|
-
if (stopImmediatePropagation)
|
|
1895
|
-
event.stopImmediatePropagation();
|
|
1896
|
-
if (preventDefault)
|
|
1897
|
-
event.preventDefault();
|
|
1898
|
-
const hostSet2 = SwcUtils.getHostSet(this);
|
|
1899
|
-
this._invokeLifecycleMethod(meta.propertyKey, hostSet2, [event, hostSet2]);
|
|
1900
|
-
};
|
|
1901
|
-
const opts = { capture, once, passive };
|
|
1902
|
-
el.addEventListener(type, handler, opts);
|
|
2095
|
+
searchRoots.forEach((sr) => {
|
|
2096
|
+
sr.querySelectorAll(selector).forEach((el) => bindTargets.push(el));
|
|
1903
2097
|
});
|
|
1904
2098
|
}
|
|
2099
|
+
bindTargets.forEach((target) => {
|
|
2100
|
+
const handler = (event) => {
|
|
2101
|
+
if (stopPropagation)
|
|
2102
|
+
event.stopPropagation();
|
|
2103
|
+
if (stopImmediatePropagation)
|
|
2104
|
+
event.stopImmediatePropagation();
|
|
2105
|
+
if (preventDefault)
|
|
2106
|
+
event.preventDefault();
|
|
2107
|
+
const currentHostSet = SwcUtils.getHostSet(this);
|
|
2108
|
+
this._invokeLifecycleMethod(meta.propertyKey, currentHostSet, [event, currentHostSet]);
|
|
2109
|
+
};
|
|
2110
|
+
target.addEventListener(type, handler, opts);
|
|
2111
|
+
if (removeOnDisconnected === true || target === currentWin || target === currentDoc) {
|
|
2112
|
+
this._boundListeners.push({ target, type, handler, options: opts });
|
|
2113
|
+
}
|
|
2114
|
+
});
|
|
1905
2115
|
});
|
|
1906
2116
|
if (super.connectedCallback)
|
|
1907
2117
|
await super.connectedCallback();
|
|
@@ -1919,6 +2129,8 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
1919
2129
|
const bMethods = findAllLifecycleMetadata(this, ON_BEFORE_DISCONNECTED_METADATA_KEY);
|
|
1920
2130
|
if (bMethods)
|
|
1921
2131
|
bMethods.forEach((m) => this._invokeLifecycleMethod(m, hostSet));
|
|
2132
|
+
this._boundListeners.forEach((l) => l.target.removeEventListener(l.type, l.handler, l.options));
|
|
2133
|
+
this._boundListeners = [];
|
|
1922
2134
|
if (super.disconnectedCallback)
|
|
1923
2135
|
super.disconnectedCallback();
|
|
1924
2136
|
const aMethods = findAllLifecycleMetadata(this, ON_AFTER_DISCONNECTED_METADATA_KEY);
|
|
@@ -1990,6 +2202,79 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
1990
2202
|
};
|
|
1991
2203
|
}
|
|
1992
2204
|
});
|
|
2205
|
+
replaceChildrenMap.forEach((selector, methodName) => {
|
|
2206
|
+
const original = NewClass.prototype[methodName];
|
|
2207
|
+
if (typeof original === "function") {
|
|
2208
|
+
NewClass.prototype[methodName] = function(...args) {
|
|
2209
|
+
const res = original.apply(this, args);
|
|
2210
|
+
if (res !== void 0) {
|
|
2211
|
+
const conf = getElementConfig(this);
|
|
2212
|
+
const currentWin = conf?.window || window;
|
|
2213
|
+
const currentDoc = currentWin.document;
|
|
2214
|
+
let targetEl = null;
|
|
2215
|
+
if (selector === ":host" || !selector) {
|
|
2216
|
+
targetEl = this;
|
|
2217
|
+
} else {
|
|
2218
|
+
targetEl = (this.shadowRoot || this).querySelector(selector);
|
|
2219
|
+
}
|
|
2220
|
+
if (targetEl) {
|
|
2221
|
+
const nodes = Array.isArray(res) ? res : [res];
|
|
2222
|
+
const normalizedNodes = nodes.map((n) => {
|
|
2223
|
+
if (typeof n === "string") {
|
|
2224
|
+
const t = currentDoc.createElement("template");
|
|
2225
|
+
t.innerHTML = n;
|
|
2226
|
+
return t.content;
|
|
2227
|
+
}
|
|
2228
|
+
return n;
|
|
2229
|
+
});
|
|
2230
|
+
targetEl.replaceChildren(...normalizedNodes);
|
|
2231
|
+
}
|
|
2232
|
+
}
|
|
2233
|
+
return res;
|
|
2234
|
+
};
|
|
2235
|
+
}
|
|
2236
|
+
});
|
|
2237
|
+
appendChildMap.forEach((meta, methodName) => {
|
|
2238
|
+
const { selector, options } = meta;
|
|
2239
|
+
const original = NewClass.prototype[methodName];
|
|
2240
|
+
if (typeof original === "function") {
|
|
2241
|
+
NewClass.prototype[methodName] = function(...args) {
|
|
2242
|
+
const res = original.apply(this, args);
|
|
2243
|
+
if (res !== void 0) {
|
|
2244
|
+
const conf = getElementConfig(this);
|
|
2245
|
+
const currentWin = conf?.window || window;
|
|
2246
|
+
const currentDoc = currentWin.document;
|
|
2247
|
+
let targetEl = null;
|
|
2248
|
+
if (selector === ":host" || !selector) {
|
|
2249
|
+
targetEl = this;
|
|
2250
|
+
} else {
|
|
2251
|
+
targetEl = (this.shadowRoot || this).querySelector(selector);
|
|
2252
|
+
}
|
|
2253
|
+
if (targetEl) {
|
|
2254
|
+
const nodes = Array.isArray(res) ? res : [res];
|
|
2255
|
+
const normalizedNodes = nodes.map((n) => {
|
|
2256
|
+
if (typeof n === "string") {
|
|
2257
|
+
const t = currentDoc.createElement("template");
|
|
2258
|
+
t.innerHTML = n;
|
|
2259
|
+
return t.content;
|
|
2260
|
+
}
|
|
2261
|
+
return n;
|
|
2262
|
+
});
|
|
2263
|
+
const pos = options.position || "lastChild";
|
|
2264
|
+
if (pos === "lastChild")
|
|
2265
|
+
targetEl.append(...normalizedNodes);
|
|
2266
|
+
else if (pos === "firstChild")
|
|
2267
|
+
targetEl.prepend(...normalizedNodes);
|
|
2268
|
+
else if (pos === "nextSibling")
|
|
2269
|
+
targetEl.after(...normalizedNodes);
|
|
2270
|
+
else if (pos === "previousSibling")
|
|
2271
|
+
targetEl.before(...normalizedNodes);
|
|
2272
|
+
}
|
|
2273
|
+
}
|
|
2274
|
+
return res;
|
|
2275
|
+
};
|
|
2276
|
+
}
|
|
2277
|
+
});
|
|
1993
2278
|
const originalProto = constructor.prototype;
|
|
1994
2279
|
const newProto = NewClass.prototype;
|
|
1995
2280
|
Object.getOwnPropertyNames(originalProto).forEach((name) => {
|
|
@@ -2027,6 +2312,26 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
2027
2312
|
queries.push({ selector, options, propertyKey });
|
|
2028
2313
|
Object.defineProperty(target, propertyKey, {
|
|
2029
2314
|
get() {
|
|
2315
|
+
const hostSet = SwcUtils.getHostSet(this);
|
|
2316
|
+
if (selector === ":parentHost")
|
|
2317
|
+
return hostSet.$parentHost;
|
|
2318
|
+
if (selector === ":appHost")
|
|
2319
|
+
return hostSet.$appHost;
|
|
2320
|
+
if (selector === ":firstHost")
|
|
2321
|
+
return hostSet.$firstHost;
|
|
2322
|
+
if (selector === ":lastHost")
|
|
2323
|
+
return hostSet.$lastHost;
|
|
2324
|
+
if (selector === ":firstAppHost")
|
|
2325
|
+
return hostSet.$firstAppHost;
|
|
2326
|
+
if (selector === ":lastAppHost")
|
|
2327
|
+
return hostSet.$lastAppHost;
|
|
2328
|
+
const config = getElementConfig(this);
|
|
2329
|
+
const win = config?.window || window;
|
|
2330
|
+
const doc = win.document;
|
|
2331
|
+
if (selector === ":window")
|
|
2332
|
+
return win;
|
|
2333
|
+
if (selector === ":document")
|
|
2334
|
+
return doc;
|
|
2030
2335
|
if (!selector || selector === ":host")
|
|
2031
2336
|
return this;
|
|
2032
2337
|
const r = options.root || "auto";
|
|
@@ -2041,6 +2346,22 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
2041
2346
|
}
|
|
2042
2347
|
return (this.shadowRoot || this).querySelector(selector);
|
|
2043
2348
|
},
|
|
2349
|
+
set(nv) {
|
|
2350
|
+
if (nv === null || nv === void 0) {
|
|
2351
|
+
const r = options.root || "auto";
|
|
2352
|
+
let targetEl = null;
|
|
2353
|
+
if (r === "shadow")
|
|
2354
|
+
targetEl = this.shadowRoot ? this.shadowRoot.querySelector(selector) : null;
|
|
2355
|
+
else if (r === "light")
|
|
2356
|
+
targetEl = this.querySelector(selector);
|
|
2357
|
+
else if (r === "all")
|
|
2358
|
+
targetEl = this.shadowRoot?.querySelector(selector) || this.querySelector(selector);
|
|
2359
|
+
else
|
|
2360
|
+
targetEl = (this.shadowRoot || this).querySelector(selector);
|
|
2361
|
+
if (targetEl)
|
|
2362
|
+
targetEl.remove();
|
|
2363
|
+
}
|
|
2364
|
+
},
|
|
2044
2365
|
enumerable: true,
|
|
2045
2366
|
configurable: true
|
|
2046
2367
|
});
|
|
@@ -2067,6 +2388,18 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
2067
2388
|
queries.push({ selector, options, propertyKey });
|
|
2068
2389
|
Object.defineProperty(target, propertyKey, {
|
|
2069
2390
|
get() {
|
|
2391
|
+
const hostSet = SwcUtils.getHostSet(this);
|
|
2392
|
+
if (selector === ":hosts")
|
|
2393
|
+
return hostSet.$hosts;
|
|
2394
|
+
if (selector === ":appHosts")
|
|
2395
|
+
return hostSet.$appHosts;
|
|
2396
|
+
const config = getElementConfig(this);
|
|
2397
|
+
const win = config?.window || window;
|
|
2398
|
+
const doc = win.document;
|
|
2399
|
+
if (selector === ":window")
|
|
2400
|
+
return [win];
|
|
2401
|
+
if (selector === ":document")
|
|
2402
|
+
return [doc];
|
|
2070
2403
|
if (!selector || selector === ":host")
|
|
2071
2404
|
return [this];
|
|
2072
2405
|
const r = options.root || "auto";
|
|
@@ -2084,6 +2417,24 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
2084
2417
|
const root = this.shadowRoot || this;
|
|
2085
2418
|
return root.querySelectorAll(selector);
|
|
2086
2419
|
},
|
|
2420
|
+
set(nv) {
|
|
2421
|
+
if (nv === null || nv === void 0 || Array.isArray(nv) && nv.length === 0) {
|
|
2422
|
+
const r = options.root || "auto";
|
|
2423
|
+
let targets = [];
|
|
2424
|
+
if (r === "shadow")
|
|
2425
|
+
targets = this.shadowRoot ? Array.from(this.shadowRoot.querySelectorAll(selector)) : [];
|
|
2426
|
+
else if (r === "light")
|
|
2427
|
+
targets = Array.from(this.querySelectorAll(selector));
|
|
2428
|
+
else if (r === "all") {
|
|
2429
|
+
const sNodes = this.shadowRoot ? Array.from(this.shadowRoot.querySelectorAll(selector)) : [];
|
|
2430
|
+
const lNodes = Array.from(this.querySelectorAll(selector));
|
|
2431
|
+
targets = [...sNodes, ...lNodes];
|
|
2432
|
+
} else {
|
|
2433
|
+
targets = Array.from((this.shadowRoot || this).querySelectorAll(selector));
|
|
2434
|
+
}
|
|
2435
|
+
targets.forEach((t) => t.remove());
|
|
2436
|
+
}
|
|
2437
|
+
},
|
|
2087
2438
|
enumerable: true,
|
|
2088
2439
|
configurable: true
|
|
2089
2440
|
});
|
|
@@ -7711,7 +8062,7 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
7711
8062
|
const configStr = this.host.getAttribute("swc-get-application-config");
|
|
7712
8063
|
if (!configStr) return;
|
|
7713
8064
|
try {
|
|
7714
|
-
const userConfig =
|
|
8065
|
+
const userConfig = FunctionUtils.executeReturn({ script: configStr, context: this.host });
|
|
7715
8066
|
if (userConfig && userConfig.rootRouter) {
|
|
7716
8067
|
const _config = {
|
|
7717
8068
|
routeType: "element",
|
|
@@ -9575,6 +9926,732 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
9575
9926
|
SwcAppBody = __decorate57([
|
|
9576
9927
|
elementDefine({ name: "swc-app-body", extends: "body" })
|
|
9577
9928
|
], SwcAppBody);
|
|
9929
|
+
|
|
9930
|
+
// src/elements/SwcSubTemplates.ts
|
|
9931
|
+
var __decorate58 = function(decorators, target, key, desc) {
|
|
9932
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
9933
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
9934
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
9935
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
9936
|
+
};
|
|
9937
|
+
var SwcLoading = class SwcLoading2 extends HTMLTemplateElement {
|
|
9938
|
+
};
|
|
9939
|
+
SwcLoading = __decorate58([
|
|
9940
|
+
elementDefine({ name: "swc-loading", extends: "template" })
|
|
9941
|
+
], SwcLoading);
|
|
9942
|
+
var SwcError = class SwcError2 extends HTMLTemplateElement {
|
|
9943
|
+
};
|
|
9944
|
+
SwcError = __decorate58([
|
|
9945
|
+
elementDefine({ name: "swc-error", extends: "template" })
|
|
9946
|
+
], SwcError);
|
|
9947
|
+
var SwcSuccess = class SwcSuccess2 extends HTMLTemplateElement {
|
|
9948
|
+
};
|
|
9949
|
+
SwcSuccess = __decorate58([
|
|
9950
|
+
elementDefine({ name: "swc-success", extends: "template" })
|
|
9951
|
+
], SwcSuccess);
|
|
9952
|
+
var SwcWhen = class SwcWhen2 extends HTMLTemplateElement {
|
|
9953
|
+
};
|
|
9954
|
+
SwcWhen = __decorate58([
|
|
9955
|
+
elementDefine({ name: "swc-when", extends: "template" })
|
|
9956
|
+
], SwcWhen);
|
|
9957
|
+
var SwcOtherwise = class SwcOtherwise2 extends HTMLTemplateElement {
|
|
9958
|
+
};
|
|
9959
|
+
SwcOtherwise = __decorate58([
|
|
9960
|
+
elementDefine({ name: "swc-otherwise", extends: "template" })
|
|
9961
|
+
], SwcOtherwise);
|
|
9962
|
+
var SwcDefault = class SwcDefault2 extends HTMLTemplateElement {
|
|
9963
|
+
};
|
|
9964
|
+
SwcDefault = __decorate58([
|
|
9965
|
+
elementDefine({ name: "swc-default", extends: "template" })
|
|
9966
|
+
], SwcDefault);
|
|
9967
|
+
|
|
9968
|
+
// src/elements/SwcLoop.ts
|
|
9969
|
+
var __decorate59 = function(decorators, target, key, desc) {
|
|
9970
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
9971
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
9972
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
9973
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
9974
|
+
};
|
|
9975
|
+
var __metadata = function(k, v) {
|
|
9976
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9977
|
+
};
|
|
9978
|
+
var SwcLoop = class SwcLoop2 extends HTMLTemplateElement {
|
|
9979
|
+
constructor() {
|
|
9980
|
+
super(...arguments);
|
|
9981
|
+
this._value = [];
|
|
9982
|
+
this._nodes = [];
|
|
9983
|
+
this._defaultNodes = [];
|
|
9984
|
+
}
|
|
9985
|
+
get value() {
|
|
9986
|
+
return this._value;
|
|
9987
|
+
}
|
|
9988
|
+
set value(nv) {
|
|
9989
|
+
this._value = Array.isArray(nv) ? [...nv] : [];
|
|
9990
|
+
this.render();
|
|
9991
|
+
}
|
|
9992
|
+
getNodes(index) {
|
|
9993
|
+
return this._nodes[index] || null;
|
|
9994
|
+
}
|
|
9995
|
+
_getTarget() {
|
|
9996
|
+
const script = this.getAttribute("on-get-portal");
|
|
9997
|
+
if (!script)
|
|
9998
|
+
return null;
|
|
9999
|
+
try {
|
|
10000
|
+
const res = FunctionUtils.executeReturn({
|
|
10001
|
+
script,
|
|
10002
|
+
context: this,
|
|
10003
|
+
args: SwcUtils.getHelperAndHostSet(window, this)
|
|
10004
|
+
});
|
|
10005
|
+
if (typeof res === "string")
|
|
10006
|
+
return document.querySelector(res);
|
|
10007
|
+
if (res instanceof Node)
|
|
10008
|
+
return res;
|
|
10009
|
+
} catch (e) {
|
|
10010
|
+
console.error("[SwcLoop] Portal target error:", e);
|
|
10011
|
+
}
|
|
10012
|
+
return null;
|
|
10013
|
+
}
|
|
10014
|
+
append(...items) {
|
|
10015
|
+
if (!items.length || !this.parentElement)
|
|
10016
|
+
return;
|
|
10017
|
+
if (this._defaultNodes.length > 0)
|
|
10018
|
+
this._cleanupDefault();
|
|
10019
|
+
const fragment = document.createDocumentFragment();
|
|
10020
|
+
const startIndex = this._value.length;
|
|
10021
|
+
items.forEach((item, i) => {
|
|
10022
|
+
const index = startIndex + i;
|
|
10023
|
+
const nodes = this._createItemNodes(item, index);
|
|
10024
|
+
if (nodes) {
|
|
10025
|
+
this._nodes.push(nodes);
|
|
10026
|
+
nodes.forEach((n) => fragment.appendChild(n));
|
|
10027
|
+
this._value.push(item);
|
|
10028
|
+
} else {
|
|
10029
|
+
this._nodes.push(null);
|
|
10030
|
+
this._value.push(null);
|
|
10031
|
+
}
|
|
10032
|
+
});
|
|
10033
|
+
const target = this._getTarget();
|
|
10034
|
+
if (target) {
|
|
10035
|
+
target.appendChild(fragment);
|
|
10036
|
+
} else {
|
|
10037
|
+
const lastValidIdx = this._nodes.length - items.length - 1;
|
|
10038
|
+
let refNode = this;
|
|
10039
|
+
for (let i = lastValidIdx; i >= 0; i--) {
|
|
10040
|
+
const group = this._nodes[i];
|
|
10041
|
+
if (group && group.length > 0) {
|
|
10042
|
+
refNode = group[group.length - 1];
|
|
10043
|
+
break;
|
|
10044
|
+
}
|
|
10045
|
+
}
|
|
10046
|
+
this.parentElement.insertBefore(fragment, refNode.nextSibling);
|
|
10047
|
+
}
|
|
10048
|
+
}
|
|
10049
|
+
remove(index) {
|
|
10050
|
+
const targetIdx = index !== void 0 ? index : this._nodes.length - 1;
|
|
10051
|
+
if (targetIdx < 0 || targetIdx >= this._nodes.length)
|
|
10052
|
+
return;
|
|
10053
|
+
const nodes = this._nodes[targetIdx];
|
|
10054
|
+
if (nodes) {
|
|
10055
|
+
nodes.forEach((n) => {
|
|
10056
|
+
if (n.parentElement)
|
|
10057
|
+
n.parentElement.removeChild(n);
|
|
10058
|
+
});
|
|
10059
|
+
this._nodes[targetIdx] = null;
|
|
10060
|
+
this._value[targetIdx] = null;
|
|
10061
|
+
}
|
|
10062
|
+
const activeRows = this._value.filter((v) => v !== null);
|
|
10063
|
+
if (activeRows.length === 0) {
|
|
10064
|
+
this.render();
|
|
10065
|
+
}
|
|
10066
|
+
}
|
|
10067
|
+
_createItemNodes(item, index) {
|
|
10068
|
+
const clone = this.content.cloneNode(true);
|
|
10069
|
+
Array.from(clone.querySelectorAll('template[is="swc-default"]')).forEach((t) => t.remove());
|
|
10070
|
+
const nodes = Array.from(clone.childNodes);
|
|
10071
|
+
const elements = nodes.filter((n) => n.nodeType === 1);
|
|
10072
|
+
const groupCtx = {
|
|
10073
|
+
$index: index,
|
|
10074
|
+
$item: item,
|
|
10075
|
+
$nodes: nodes,
|
|
10076
|
+
$elements: elements,
|
|
10077
|
+
$firstNode: nodes[0],
|
|
10078
|
+
$lastNode: nodes[nodes.length - 1],
|
|
10079
|
+
$firstElement: elements[0],
|
|
10080
|
+
$lastElement: elements[elements.length - 1],
|
|
10081
|
+
$isFirst: index === 0,
|
|
10082
|
+
$isLast: index === this._value.length - 1,
|
|
10083
|
+
$isEven: index % 2 === 0,
|
|
10084
|
+
$isOdd: index % 2 !== 0,
|
|
10085
|
+
$count: this._value.length
|
|
10086
|
+
};
|
|
10087
|
+
this._executeCallback("on-clone-nodes", groupCtx);
|
|
10088
|
+
nodes.forEach((node, nodeIndex) => {
|
|
10089
|
+
if (node instanceof HTMLElement)
|
|
10090
|
+
node.__swc_host = this;
|
|
10091
|
+
this._executeCallback("on-clone-node", { ...groupCtx, $node: node, $nodeIndex: nodeIndex, $isElement: node.nodeType === 1 });
|
|
10092
|
+
});
|
|
10093
|
+
return nodes;
|
|
10094
|
+
}
|
|
10095
|
+
_executeCallback(attrName, extraArgs) {
|
|
10096
|
+
const script = this.getAttribute(attrName);
|
|
10097
|
+
if (!script)
|
|
10098
|
+
return;
|
|
10099
|
+
const helperHostSet = SwcUtils.getHelperAndHostSet(window, this);
|
|
10100
|
+
try {
|
|
10101
|
+
FunctionUtils.execute({ script, context: this, args: { ...helperHostSet, ...extraArgs } });
|
|
10102
|
+
} catch (e) {
|
|
10103
|
+
console.error(`[SwcLoop] Error in ${attrName}:`, e);
|
|
10104
|
+
}
|
|
10105
|
+
}
|
|
10106
|
+
refreshValue(newValue) {
|
|
10107
|
+
const script = newValue !== void 0 ? newValue : this.getAttribute("on-get-value");
|
|
10108
|
+
if (!script) {
|
|
10109
|
+
this.value = [];
|
|
10110
|
+
return;
|
|
10111
|
+
}
|
|
10112
|
+
const helperHostSet = SwcUtils.getHelperAndHostSet(window, this);
|
|
10113
|
+
try {
|
|
10114
|
+
const res = FunctionUtils.executeReturn({ script, context: this, args: helperHostSet });
|
|
10115
|
+
if (Array.isArray(res)) {
|
|
10116
|
+
this.value = res;
|
|
10117
|
+
}
|
|
10118
|
+
} catch (e) {
|
|
10119
|
+
console.error("[SwcLoop] Failed to get value from on-get-value script:", e);
|
|
10120
|
+
this.value = [];
|
|
10121
|
+
}
|
|
10122
|
+
}
|
|
10123
|
+
render() {
|
|
10124
|
+
this._cleanup();
|
|
10125
|
+
if (!this.parentElement)
|
|
10126
|
+
return;
|
|
10127
|
+
const activeRows = this._value.filter((v) => v !== null);
|
|
10128
|
+
const target = this._getTarget();
|
|
10129
|
+
if (activeRows.length === 0) {
|
|
10130
|
+
const t = this.content.querySelector('template[is="swc-default"]');
|
|
10131
|
+
if (t) {
|
|
10132
|
+
const clone = t.content.cloneNode(true);
|
|
10133
|
+
this._defaultNodes = Array.from(clone.childNodes);
|
|
10134
|
+
this._defaultNodes.forEach((n) => {
|
|
10135
|
+
if (n instanceof HTMLElement)
|
|
10136
|
+
n.__swc_host = this;
|
|
10137
|
+
});
|
|
10138
|
+
if (target)
|
|
10139
|
+
target.appendChild(clone);
|
|
10140
|
+
else
|
|
10141
|
+
this.parentElement.insertBefore(clone, this.nextSibling);
|
|
10142
|
+
}
|
|
10143
|
+
return;
|
|
10144
|
+
}
|
|
10145
|
+
const fragment = document.createDocumentFragment();
|
|
10146
|
+
this._value.forEach((item, index) => {
|
|
10147
|
+
if (item === null) {
|
|
10148
|
+
this._nodes.push(null);
|
|
10149
|
+
return;
|
|
10150
|
+
}
|
|
10151
|
+
const nodes = this._createItemNodes(item, index);
|
|
10152
|
+
this._nodes.push(nodes);
|
|
10153
|
+
nodes.forEach((n) => fragment.appendChild(n));
|
|
10154
|
+
});
|
|
10155
|
+
if (target)
|
|
10156
|
+
target.appendChild(fragment);
|
|
10157
|
+
else
|
|
10158
|
+
this.parentElement.insertBefore(fragment, this.nextSibling);
|
|
10159
|
+
}
|
|
10160
|
+
_cleanup() {
|
|
10161
|
+
this._nodes.forEach((group) => {
|
|
10162
|
+
if (group)
|
|
10163
|
+
group.forEach((node) => node.parentElement?.removeChild(node));
|
|
10164
|
+
});
|
|
10165
|
+
this._nodes = [];
|
|
10166
|
+
this._cleanupDefault();
|
|
10167
|
+
}
|
|
10168
|
+
_cleanupDefault() {
|
|
10169
|
+
this._defaultNodes.forEach((n) => n.parentElement?.removeChild(n));
|
|
10170
|
+
this._defaultNodes = [];
|
|
10171
|
+
}
|
|
10172
|
+
connectedCallback() {
|
|
10173
|
+
this.refreshValue();
|
|
10174
|
+
}
|
|
10175
|
+
disconnectedCallback() {
|
|
10176
|
+
this._cleanup();
|
|
10177
|
+
}
|
|
10178
|
+
};
|
|
10179
|
+
__decorate59([
|
|
10180
|
+
changedAttribute("on-get-value"),
|
|
10181
|
+
__metadata("design:type", Function),
|
|
10182
|
+
__metadata("design:paramtypes", [String]),
|
|
10183
|
+
__metadata("design:returntype", void 0)
|
|
10184
|
+
], SwcLoop.prototype, "refreshValue", null);
|
|
10185
|
+
SwcLoop = __decorate59([
|
|
10186
|
+
elementDefine({ name: "swc-loop", extends: "template" })
|
|
10187
|
+
], SwcLoop);
|
|
10188
|
+
|
|
10189
|
+
// src/elements/SwcIf.ts
|
|
10190
|
+
var __decorate60 = function(decorators, target, key, desc) {
|
|
10191
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
10192
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
10193
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
10194
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10195
|
+
};
|
|
10196
|
+
var __metadata2 = function(k, v) {
|
|
10197
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10198
|
+
};
|
|
10199
|
+
var SwcIf = class SwcIf2 extends HTMLTemplateElement {
|
|
10200
|
+
constructor() {
|
|
10201
|
+
super(...arguments);
|
|
10202
|
+
this._nodes = [];
|
|
10203
|
+
this._value = null;
|
|
10204
|
+
}
|
|
10205
|
+
get value() {
|
|
10206
|
+
return this._value;
|
|
10207
|
+
}
|
|
10208
|
+
set value(nv) {
|
|
10209
|
+
this._value = nv;
|
|
10210
|
+
this.render();
|
|
10211
|
+
}
|
|
10212
|
+
_getTarget() {
|
|
10213
|
+
const script = this.getAttribute("on-get-portal");
|
|
10214
|
+
if (!script)
|
|
10215
|
+
return null;
|
|
10216
|
+
try {
|
|
10217
|
+
const res = FunctionUtils.executeReturn({
|
|
10218
|
+
script,
|
|
10219
|
+
context: this,
|
|
10220
|
+
args: SwcUtils.getHelperAndHostSet(window, this)
|
|
10221
|
+
});
|
|
10222
|
+
if (typeof res === "string")
|
|
10223
|
+
return document.querySelector(res);
|
|
10224
|
+
if (res instanceof Node)
|
|
10225
|
+
return res;
|
|
10226
|
+
} catch (e) {
|
|
10227
|
+
console.error("[SwcIf] Portal target error:", e);
|
|
10228
|
+
}
|
|
10229
|
+
return null;
|
|
10230
|
+
}
|
|
10231
|
+
_executeCallback(attrName, extraArgs) {
|
|
10232
|
+
const script = this.getAttribute(attrName);
|
|
10233
|
+
if (!script)
|
|
10234
|
+
return;
|
|
10235
|
+
const helperHostSet = SwcUtils.getHelperAndHostSet(window, this);
|
|
10236
|
+
try {
|
|
10237
|
+
FunctionUtils.execute({ script, context: this, args: { ...helperHostSet, ...extraArgs } });
|
|
10238
|
+
} catch (e) {
|
|
10239
|
+
console.error(`[SwcIf] Error in ${attrName}:`, e);
|
|
10240
|
+
}
|
|
10241
|
+
}
|
|
10242
|
+
refresh(newValue) {
|
|
10243
|
+
const script = newValue !== void 0 ? newValue : this.getAttribute("on-get-value");
|
|
10244
|
+
if (!script) {
|
|
10245
|
+
this.value = null;
|
|
10246
|
+
return;
|
|
10247
|
+
}
|
|
10248
|
+
if (!this.parentElement)
|
|
10249
|
+
return;
|
|
10250
|
+
const helperHostSet = SwcUtils.getHelperAndHostSet(window, this);
|
|
10251
|
+
try {
|
|
10252
|
+
const result = FunctionUtils.executeReturn({
|
|
10253
|
+
script,
|
|
10254
|
+
context: this,
|
|
10255
|
+
args: helperHostSet
|
|
10256
|
+
});
|
|
10257
|
+
this.value = result;
|
|
10258
|
+
} catch (e) {
|
|
10259
|
+
console.error("[SwcIf] Error in on-get-value:", e);
|
|
10260
|
+
this.value = null;
|
|
10261
|
+
}
|
|
10262
|
+
}
|
|
10263
|
+
render() {
|
|
10264
|
+
this.cleanup();
|
|
10265
|
+
if (!this.parentElement)
|
|
10266
|
+
return;
|
|
10267
|
+
let fragment = null;
|
|
10268
|
+
const ctx = { $value: this._value, $nodes: [], $elements: [] };
|
|
10269
|
+
if (this._value) {
|
|
10270
|
+
const clone = this.content.cloneNode(true);
|
|
10271
|
+
Array.from(clone.querySelectorAll('template[is="swc-default"]')).forEach((t) => t.remove());
|
|
10272
|
+
fragment = clone;
|
|
10273
|
+
} else {
|
|
10274
|
+
const t = this.content.querySelector('template[is="swc-default"]');
|
|
10275
|
+
if (t)
|
|
10276
|
+
fragment = t.content.cloneNode(true);
|
|
10277
|
+
}
|
|
10278
|
+
if (fragment) {
|
|
10279
|
+
this.mount(fragment, ctx);
|
|
10280
|
+
}
|
|
10281
|
+
}
|
|
10282
|
+
mount(fragment, ctx) {
|
|
10283
|
+
const nodes = Array.from(fragment.childNodes);
|
|
10284
|
+
const elements = nodes.filter((n) => n.nodeType === 1);
|
|
10285
|
+
Object.assign(ctx, {
|
|
10286
|
+
$nodes: nodes,
|
|
10287
|
+
$elements: elements,
|
|
10288
|
+
$firstNode: nodes[0],
|
|
10289
|
+
$lastNode: nodes[nodes.length - 1],
|
|
10290
|
+
$firstElement: elements[0],
|
|
10291
|
+
$lastElement: elements[elements.length - 1]
|
|
10292
|
+
});
|
|
10293
|
+
this._executeCallback("on-clone-nodes", ctx);
|
|
10294
|
+
nodes.forEach((node, nodeIndex) => {
|
|
10295
|
+
if (node instanceof HTMLElement)
|
|
10296
|
+
node.__swc_host = this;
|
|
10297
|
+
this._executeCallback("on-clone-node", { ...ctx, $node: node, $nodeIndex: nodeIndex, $isElement: node.nodeType === 1 });
|
|
10298
|
+
});
|
|
10299
|
+
this._nodes = nodes;
|
|
10300
|
+
const target = this._getTarget();
|
|
10301
|
+
if (target) {
|
|
10302
|
+
target.appendChild(fragment);
|
|
10303
|
+
} else {
|
|
10304
|
+
this.parentElement?.insertBefore(fragment, this.nextSibling);
|
|
10305
|
+
}
|
|
10306
|
+
}
|
|
10307
|
+
cleanup() {
|
|
10308
|
+
this._nodes.forEach((n) => {
|
|
10309
|
+
if (n.parentElement)
|
|
10310
|
+
n.parentElement.removeChild(n);
|
|
10311
|
+
});
|
|
10312
|
+
this._nodes = [];
|
|
10313
|
+
}
|
|
10314
|
+
connectedCallback() {
|
|
10315
|
+
this.refresh();
|
|
10316
|
+
}
|
|
10317
|
+
disconnectedCallback() {
|
|
10318
|
+
this.cleanup();
|
|
10319
|
+
}
|
|
10320
|
+
};
|
|
10321
|
+
__decorate60([
|
|
10322
|
+
changedAttribute("on-get-value"),
|
|
10323
|
+
__metadata2("design:type", Function),
|
|
10324
|
+
__metadata2("design:paramtypes", [String]),
|
|
10325
|
+
__metadata2("design:returntype", void 0)
|
|
10326
|
+
], SwcIf.prototype, "refresh", null);
|
|
10327
|
+
SwcIf = __decorate60([
|
|
10328
|
+
elementDefine({ name: "swc-if", extends: "template" })
|
|
10329
|
+
], SwcIf);
|
|
10330
|
+
|
|
10331
|
+
// src/elements/SwcChoose.ts
|
|
10332
|
+
var __decorate61 = function(decorators, target, key, desc) {
|
|
10333
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
10334
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
10335
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
10336
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10337
|
+
};
|
|
10338
|
+
var __metadata3 = function(k, v) {
|
|
10339
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10340
|
+
};
|
|
10341
|
+
var SwcChoose = class SwcChoose2 extends HTMLTemplateElement {
|
|
10342
|
+
constructor() {
|
|
10343
|
+
super(...arguments);
|
|
10344
|
+
this._nodes = [];
|
|
10345
|
+
this._value = null;
|
|
10346
|
+
}
|
|
10347
|
+
get value() {
|
|
10348
|
+
return this._value;
|
|
10349
|
+
}
|
|
10350
|
+
set value(nv) {
|
|
10351
|
+
this._value = nv;
|
|
10352
|
+
this.render();
|
|
10353
|
+
}
|
|
10354
|
+
_executeCallback(attrName, extraArgs) {
|
|
10355
|
+
const script = this.getAttribute(attrName);
|
|
10356
|
+
if (!script)
|
|
10357
|
+
return;
|
|
10358
|
+
const helperHostSet = SwcUtils.getHelperAndHostSet(window, this);
|
|
10359
|
+
try {
|
|
10360
|
+
FunctionUtils.execute({ script, context: this, args: { ...helperHostSet, ...extraArgs } });
|
|
10361
|
+
} catch (e) {
|
|
10362
|
+
console.error(`[SwcChoose] Error in ${attrName}:`, e);
|
|
10363
|
+
}
|
|
10364
|
+
}
|
|
10365
|
+
refresh(newValue) {
|
|
10366
|
+
const script = newValue !== void 0 ? newValue : this.getAttribute("on-get-value");
|
|
10367
|
+
if (!script) {
|
|
10368
|
+
this.value = null;
|
|
10369
|
+
return;
|
|
10370
|
+
}
|
|
10371
|
+
if (!this.parentElement)
|
|
10372
|
+
return;
|
|
10373
|
+
const helperHostSet = SwcUtils.getHelperAndHostSet(window, this);
|
|
10374
|
+
try {
|
|
10375
|
+
const result = FunctionUtils.executeReturn({
|
|
10376
|
+
script,
|
|
10377
|
+
context: this,
|
|
10378
|
+
args: helperHostSet
|
|
10379
|
+
});
|
|
10380
|
+
this.value = result;
|
|
10381
|
+
} catch (e) {
|
|
10382
|
+
console.error("[SwcChoose] Error in on-get-value:", e);
|
|
10383
|
+
}
|
|
10384
|
+
}
|
|
10385
|
+
render() {
|
|
10386
|
+
this.cleanup();
|
|
10387
|
+
if (!this.parentElement)
|
|
10388
|
+
return;
|
|
10389
|
+
const templates = Array.from(this.content.querySelectorAll("template"));
|
|
10390
|
+
let selected = null;
|
|
10391
|
+
let otherwise = null;
|
|
10392
|
+
let defaultTmp = null;
|
|
10393
|
+
for (const t of templates) {
|
|
10394
|
+
const is = t.getAttribute("is");
|
|
10395
|
+
if (is === "swc-when") {
|
|
10396
|
+
const whenVal = t.getAttribute("value");
|
|
10397
|
+
if (String(whenVal) === String(this._value)) {
|
|
10398
|
+
selected = t;
|
|
10399
|
+
break;
|
|
10400
|
+
}
|
|
10401
|
+
} else if (is === "swc-otherwise") {
|
|
10402
|
+
otherwise = t;
|
|
10403
|
+
} else if (is === "swc-default") {
|
|
10404
|
+
defaultTmp = t;
|
|
10405
|
+
}
|
|
10406
|
+
}
|
|
10407
|
+
const targetTemplate = (this._value == null ? defaultTmp : selected) || otherwise || defaultTmp;
|
|
10408
|
+
if (targetTemplate) {
|
|
10409
|
+
const clone = targetTemplate.content.cloneNode(true);
|
|
10410
|
+
const nodes = Array.from(clone.childNodes);
|
|
10411
|
+
const elements = nodes.filter((n) => n.nodeType === 1);
|
|
10412
|
+
const ctx = {
|
|
10413
|
+
$value: this._value,
|
|
10414
|
+
$nodes: nodes,
|
|
10415
|
+
$elements: elements,
|
|
10416
|
+
$firstNode: nodes[0],
|
|
10417
|
+
$lastNode: nodes[nodes.length - 1],
|
|
10418
|
+
$firstElement: elements[0],
|
|
10419
|
+
$lastElement: elements[elements.length - 1]
|
|
10420
|
+
};
|
|
10421
|
+
this._executeCallback("on-clone-nodes", ctx);
|
|
10422
|
+
nodes.forEach((node, nodeIndex) => {
|
|
10423
|
+
if (node instanceof HTMLElement) {
|
|
10424
|
+
node.__swc_host = this;
|
|
10425
|
+
}
|
|
10426
|
+
this._executeCallback("on-clone-node", {
|
|
10427
|
+
...ctx,
|
|
10428
|
+
$node: node,
|
|
10429
|
+
$nodeIndex: nodeIndex,
|
|
10430
|
+
$isElement: node.nodeType === 1
|
|
10431
|
+
});
|
|
10432
|
+
});
|
|
10433
|
+
this._nodes = nodes;
|
|
10434
|
+
this.parentElement.insertBefore(clone, this.nextSibling);
|
|
10435
|
+
}
|
|
10436
|
+
}
|
|
10437
|
+
cleanup() {
|
|
10438
|
+
this._nodes.forEach((n) => {
|
|
10439
|
+
if (n.parentElement)
|
|
10440
|
+
n.parentElement.removeChild(n);
|
|
10441
|
+
});
|
|
10442
|
+
this._nodes = [];
|
|
10443
|
+
}
|
|
10444
|
+
connectedCallback() {
|
|
10445
|
+
this.refresh();
|
|
10446
|
+
}
|
|
10447
|
+
disconnectedCallback() {
|
|
10448
|
+
this.cleanup();
|
|
10449
|
+
}
|
|
10450
|
+
};
|
|
10451
|
+
__decorate61([
|
|
10452
|
+
changedAttribute("on-get-value"),
|
|
10453
|
+
__metadata3("design:type", Function),
|
|
10454
|
+
__metadata3("design:paramtypes", [String]),
|
|
10455
|
+
__metadata3("design:returntype", void 0)
|
|
10456
|
+
], SwcChoose.prototype, "refresh", null);
|
|
10457
|
+
SwcChoose = __decorate61([
|
|
10458
|
+
elementDefine({ name: "swc-choose", extends: "template" })
|
|
10459
|
+
], SwcChoose);
|
|
10460
|
+
|
|
10461
|
+
// src/elements/SwcAsync.ts
|
|
10462
|
+
var __decorate62 = function(decorators, target, key, desc) {
|
|
10463
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
10464
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
10465
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
10466
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10467
|
+
};
|
|
10468
|
+
var __metadata4 = function(k, v) {
|
|
10469
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10470
|
+
};
|
|
10471
|
+
var SwcAsync = class SwcAsync2 extends HTMLTemplateElement {
|
|
10472
|
+
constructor() {
|
|
10473
|
+
super(...arguments);
|
|
10474
|
+
this._nodes = [];
|
|
10475
|
+
this._currentPromise = null;
|
|
10476
|
+
this._value = null;
|
|
10477
|
+
}
|
|
10478
|
+
get value() {
|
|
10479
|
+
return this._value;
|
|
10480
|
+
}
|
|
10481
|
+
set value(nv) {
|
|
10482
|
+
if (nv instanceof Promise) {
|
|
10483
|
+
this.handlePromise(nv);
|
|
10484
|
+
} else {
|
|
10485
|
+
this._value = nv;
|
|
10486
|
+
this.render(nv === null ? "default" : "success", nv);
|
|
10487
|
+
}
|
|
10488
|
+
}
|
|
10489
|
+
refresh(newValue) {
|
|
10490
|
+
const script = newValue !== void 0 ? newValue : this.getAttribute("on-get-value");
|
|
10491
|
+
if (!script) {
|
|
10492
|
+
this.value = null;
|
|
10493
|
+
return;
|
|
10494
|
+
}
|
|
10495
|
+
if (!this.parentElement)
|
|
10496
|
+
return;
|
|
10497
|
+
const helperHostSet = SwcUtils.getHelperAndHostSet(window, this);
|
|
10498
|
+
try {
|
|
10499
|
+
const result = FunctionUtils.executeReturn({
|
|
10500
|
+
script,
|
|
10501
|
+
context: this,
|
|
10502
|
+
args: helperHostSet
|
|
10503
|
+
});
|
|
10504
|
+
if (result instanceof Promise) {
|
|
10505
|
+
this.handlePromise(result);
|
|
10506
|
+
} else {
|
|
10507
|
+
this.value = result;
|
|
10508
|
+
}
|
|
10509
|
+
} catch (e) {
|
|
10510
|
+
this.render("error", e);
|
|
10511
|
+
}
|
|
10512
|
+
}
|
|
10513
|
+
async handlePromise(promise) {
|
|
10514
|
+
this._currentPromise = promise;
|
|
10515
|
+
this.render("loading");
|
|
10516
|
+
try {
|
|
10517
|
+
const result = await promise;
|
|
10518
|
+
if (this._currentPromise !== promise)
|
|
10519
|
+
return;
|
|
10520
|
+
this._value = result;
|
|
10521
|
+
this.render("success", result);
|
|
10522
|
+
} catch (e) {
|
|
10523
|
+
if (this._currentPromise !== promise)
|
|
10524
|
+
return;
|
|
10525
|
+
this.render("error", e);
|
|
10526
|
+
}
|
|
10527
|
+
}
|
|
10528
|
+
render(state, data) {
|
|
10529
|
+
this.cleanup();
|
|
10530
|
+
if (!this.parentElement)
|
|
10531
|
+
return;
|
|
10532
|
+
let fragment;
|
|
10533
|
+
const ctx = {
|
|
10534
|
+
$nodes: [],
|
|
10535
|
+
$elements: [],
|
|
10536
|
+
$state: state,
|
|
10537
|
+
$value: null,
|
|
10538
|
+
$error: null
|
|
10539
|
+
};
|
|
10540
|
+
if (state === "default") {
|
|
10541
|
+
const t = this.content.querySelector('template[is="swc-default"]');
|
|
10542
|
+
fragment = t ? t.content.cloneNode(true) : document.createDocumentFragment();
|
|
10543
|
+
} else if (state === "loading") {
|
|
10544
|
+
const t = this.content.querySelector('template[is="swc-loading"]');
|
|
10545
|
+
fragment = t ? t.content.cloneNode(true) : document.createDocumentFragment();
|
|
10546
|
+
} else if (state === "error") {
|
|
10547
|
+
const t = this.content.querySelector('template[is="swc-error"]');
|
|
10548
|
+
ctx.$error = data;
|
|
10549
|
+
fragment = t ? t.content.cloneNode(true) : document.createDocumentFragment();
|
|
10550
|
+
} else {
|
|
10551
|
+
const t = this.content.querySelector('template[is="swc-success"]');
|
|
10552
|
+
ctx.$value = data;
|
|
10553
|
+
if (t) {
|
|
10554
|
+
fragment = t.content.cloneNode(true);
|
|
10555
|
+
} else {
|
|
10556
|
+
const clone = this.content.cloneNode(true);
|
|
10557
|
+
Array.from(clone.querySelectorAll('template[is="swc-loading"], template[is="swc-error"], template[is="swc-success"], template[is="swc-default"]')).forEach((tmp) => tmp.remove());
|
|
10558
|
+
fragment = clone;
|
|
10559
|
+
}
|
|
10560
|
+
}
|
|
10561
|
+
this.mount(fragment, ctx);
|
|
10562
|
+
}
|
|
10563
|
+
mount(fragment, ctx) {
|
|
10564
|
+
const nodes = Array.from(fragment.childNodes);
|
|
10565
|
+
const elements = nodes.filter((n) => n.nodeType === 1);
|
|
10566
|
+
Object.assign(ctx, {
|
|
10567
|
+
$nodes: nodes,
|
|
10568
|
+
$elements: elements,
|
|
10569
|
+
$firstNode: nodes[0],
|
|
10570
|
+
$lastNode: nodes[nodes.length - 1],
|
|
10571
|
+
$firstElement: elements[0],
|
|
10572
|
+
$lastElement: elements[elements.length - 1]
|
|
10573
|
+
});
|
|
10574
|
+
this._executeCallback("on-clone-nodes", ctx);
|
|
10575
|
+
nodes.forEach((node, nodeIndex) => {
|
|
10576
|
+
if (node instanceof HTMLElement) {
|
|
10577
|
+
node.__swc_host = this;
|
|
10578
|
+
}
|
|
10579
|
+
this._executeCallback("on-clone-node", {
|
|
10580
|
+
...ctx,
|
|
10581
|
+
$node: node,
|
|
10582
|
+
$nodeIndex: nodeIndex,
|
|
10583
|
+
$isElement: node.nodeType === 1
|
|
10584
|
+
});
|
|
10585
|
+
});
|
|
10586
|
+
this._nodes = nodes;
|
|
10587
|
+
this.parentElement?.insertBefore(fragment, this.nextSibling);
|
|
10588
|
+
}
|
|
10589
|
+
_executeCallback(attrName, extraArgs) {
|
|
10590
|
+
const script = this.getAttribute(attrName);
|
|
10591
|
+
if (!script)
|
|
10592
|
+
return;
|
|
10593
|
+
const helperHostSet = SwcUtils.getHelperAndHostSet(window, this);
|
|
10594
|
+
try {
|
|
10595
|
+
FunctionUtils.execute({ script, context: this, args: { ...helperHostSet, ...extraArgs } });
|
|
10596
|
+
} catch (e) {
|
|
10597
|
+
console.error(`[SwcAsync] Error in ${attrName}:`, e);
|
|
10598
|
+
}
|
|
10599
|
+
}
|
|
10600
|
+
cleanup() {
|
|
10601
|
+
this._nodes.forEach((n) => {
|
|
10602
|
+
if (n.parentElement)
|
|
10603
|
+
n.parentElement.removeChild(n);
|
|
10604
|
+
});
|
|
10605
|
+
this._nodes = [];
|
|
10606
|
+
}
|
|
10607
|
+
connectedCallback() {
|
|
10608
|
+
this.refresh();
|
|
10609
|
+
}
|
|
10610
|
+
disconnectedCallback() {
|
|
10611
|
+
this.cleanup();
|
|
10612
|
+
}
|
|
10613
|
+
};
|
|
10614
|
+
__decorate62([
|
|
10615
|
+
changedAttribute("on-get-value"),
|
|
10616
|
+
__metadata4("design:type", Function),
|
|
10617
|
+
__metadata4("design:paramtypes", [String]),
|
|
10618
|
+
__metadata4("design:returntype", void 0)
|
|
10619
|
+
], SwcAsync.prototype, "refresh", null);
|
|
10620
|
+
SwcAsync = __decorate62([
|
|
10621
|
+
elementDefine({ name: "swc-async", extends: "template" })
|
|
10622
|
+
], SwcAsync);
|
|
10623
|
+
|
|
10624
|
+
// src/elements/SwcApp.ts
|
|
10625
|
+
var __decorate63 = function(decorators, target, key, desc) {
|
|
10626
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
10627
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
10628
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
10629
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10630
|
+
};
|
|
10631
|
+
var SwcApp = class SwcApp2 extends HTMLElement {
|
|
10632
|
+
constructor() {
|
|
10633
|
+
super(...arguments);
|
|
10634
|
+
this._engine = new SwcAppEngine(this);
|
|
10635
|
+
}
|
|
10636
|
+
get simpleApplication() {
|
|
10637
|
+
return this._engine.simpleApplication;
|
|
10638
|
+
}
|
|
10639
|
+
get router() {
|
|
10640
|
+
return this._engine.router;
|
|
10641
|
+
}
|
|
10642
|
+
connectedCallback() {
|
|
10643
|
+
this._engine.connect();
|
|
10644
|
+
}
|
|
10645
|
+
disconnectedCallback() {
|
|
10646
|
+
this._engine.disconnect();
|
|
10647
|
+
}
|
|
10648
|
+
async routing(path) {
|
|
10649
|
+
await this._engine.router?.go(path);
|
|
10650
|
+
}
|
|
10651
|
+
};
|
|
10652
|
+
SwcApp = __decorate63([
|
|
10653
|
+
elementDefine({ name: "swc-app", extends: void 0 })
|
|
10654
|
+
], SwcApp);
|
|
9578
10655
|
return __toCommonJS(bundle_entry_exports);
|
|
9579
10656
|
})();
|
|
9580
10657
|
/*! Bundled license information:
|