@dooboostore/simple-web-component 1.0.15 → 1.0.17
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 +275 -91
- package/dist/cjs/decorators/addEventListener.js +2 -3
- package/dist/cjs/decorators/addEventListener.js.map +2 -2
- package/dist/cjs/decorators/elementDefine.js +161 -34
- package/dist/cjs/decorators/elementDefine.js.map +3 -3
- package/dist/cjs/decorators/emitCustomEvent.js +2 -14
- package/dist/cjs/decorators/emitCustomEvent.js.map +2 -2
- package/dist/cjs/decorators/query.js +47 -36
- package/dist/cjs/decorators/query.js.map +2 -2
- package/dist/cjs/decorators/queryAll.js +42 -36
- package/dist/cjs/decorators/queryAll.js.map +2 -2
- 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 +1 -1
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/types.js +1 -0
- package/dist/cjs/types.js.map +2 -2
- package/dist/cjs/utils/Utils.js +92 -162
- package/dist/cjs/utils/Utils.js.map +3 -3
- package/dist/esm/decorators/addEventListener.js +2 -3
- package/dist/esm/decorators/addEventListener.js.map +2 -2
- package/dist/esm/decorators/elementDefine.js +161 -34
- package/dist/esm/decorators/elementDefine.js.map +3 -3
- package/dist/esm/decorators/emitCustomEvent.js +2 -14
- package/dist/esm/decorators/emitCustomEvent.js.map +2 -2
- package/dist/esm/decorators/query.js +47 -36
- package/dist/esm/decorators/query.js.map +2 -2
- package/dist/esm/decorators/queryAll.js +42 -36
- package/dist/esm/decorators/queryAll.js.map +2 -2
- 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 +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types.js +1 -0
- package/dist/esm/types.js.map +2 -2
- package/dist/esm/utils/Utils.js +92 -162
- package/dist/esm/utils/Utils.js.map +3 -3
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +1150 -326
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
- package/dist/types/decorators/addEventListener.d.ts +10 -4
- package/dist/types/decorators/addEventListener.d.ts.map +1 -1
- package/dist/types/decorators/elementDefine.d.ts.map +1 -1
- package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
- package/dist/types/decorators/query.d.ts +4 -5
- package/dist/types/decorators/query.d.ts.map +1 -1
- package/dist/types/decorators/queryAll.d.ts +4 -5
- package/dist/types/decorators/queryAll.d.ts.map +1 -1
- 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 +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types.d.ts +11 -1
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils/Utils.d.ts +19 -21
- package/dist/types/utils/Utils.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +1150 -326
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +10 -3
- package/src/decorators/addEventListener.ts +11 -7
- package/src/decorators/elementDefine.ts +165 -39
- package/src/decorators/emitCustomEvent.ts +5 -21
- package/src/decorators/query.ts +46 -41
- package/src/decorators/queryAll.ts +45 -41
- 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 +1 -1
- package/src/types.ts +15 -5
- package/src/utils/Utils.ts +111 -197
|
@@ -1136,6 +1136,7 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
1136
1136
|
QUERY_METADATA_KEY: () => QUERY_METADATA_KEY,
|
|
1137
1137
|
SET_ATTRIBUTE_METADATA_KEY: () => SET_ATTRIBUTE_METADATA_KEY,
|
|
1138
1138
|
SWC_NOT_FOUND: () => SWC_NOT_FOUND,
|
|
1139
|
+
SwcApp: () => SwcApp,
|
|
1139
1140
|
SwcAppAnchor: () => SwcAppAnchor,
|
|
1140
1141
|
SwcAppArea: () => SwcAppArea,
|
|
1141
1142
|
SwcAppAudio: () => SwcAppAudio,
|
|
@@ -1150,6 +1151,7 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
1150
1151
|
SwcAppDiv: () => SwcAppDiv,
|
|
1151
1152
|
SwcAppDl: () => SwcAppDl,
|
|
1152
1153
|
SwcAppEmbed: () => SwcAppEmbed,
|
|
1154
|
+
SwcAppEngine: () => SwcAppEngine,
|
|
1153
1155
|
SwcAppFieldSet: () => SwcAppFieldSet,
|
|
1154
1156
|
SwcAppForm: () => SwcAppForm,
|
|
1155
1157
|
SwcAppHeading: () => SwcAppHeading,
|
|
@@ -1193,7 +1195,17 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
1193
1195
|
SwcAppTrack: () => SwcAppTrack,
|
|
1194
1196
|
SwcAppUl: () => SwcAppUl,
|
|
1195
1197
|
SwcAppVideo: () => SwcAppVideo,
|
|
1198
|
+
SwcAsync: () => SwcAsync,
|
|
1199
|
+
SwcChoose: () => SwcChoose,
|
|
1200
|
+
SwcDefault: () => SwcDefault,
|
|
1201
|
+
SwcError: () => SwcError,
|
|
1202
|
+
SwcIf: () => SwcIf,
|
|
1203
|
+
SwcLoading: () => SwcLoading,
|
|
1204
|
+
SwcLoop: () => SwcLoop,
|
|
1205
|
+
SwcOtherwise: () => SwcOtherwise,
|
|
1206
|
+
SwcSuccess: () => SwcSuccess,
|
|
1196
1207
|
SwcUtils: () => SwcUtils,
|
|
1208
|
+
SwcWhen: () => SwcWhen,
|
|
1197
1209
|
addEventListener: () => addEventListener,
|
|
1198
1210
|
changedAttribute: () => changedAttribute,
|
|
1199
1211
|
elementDefine: () => elementDefine,
|
|
@@ -1230,32 +1242,33 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
1230
1242
|
var import_reflect_metadata = __toESM(require_Reflect(), 1);
|
|
1231
1243
|
|
|
1232
1244
|
// ../core/dist/esm/reflect/ReflectUtils.js
|
|
1233
|
-
var ReflectUtils
|
|
1234
|
-
|
|
1245
|
+
var ReflectUtils;
|
|
1246
|
+
((ReflectUtils2) => {
|
|
1247
|
+
ReflectUtils2.getParameterTypes = (target, propertyKey) => {
|
|
1235
1248
|
if (propertyKey) {
|
|
1236
1249
|
return Reflect.getMetadata("design:paramtypes", target, propertyKey) || [];
|
|
1237
1250
|
} else {
|
|
1238
1251
|
return Reflect.getMetadata("design:paramtypes", target) || [];
|
|
1239
1252
|
}
|
|
1240
|
-
}
|
|
1241
|
-
getReturnType
|
|
1253
|
+
};
|
|
1254
|
+
ReflectUtils2.getReturnType = (target, propertyKey) => {
|
|
1242
1255
|
return Reflect.getMetadata("design:returntype", target, propertyKey);
|
|
1243
|
-
}
|
|
1244
|
-
getType
|
|
1256
|
+
};
|
|
1257
|
+
ReflectUtils2.getType = (target, propertyKey) => {
|
|
1245
1258
|
if (propertyKey) {
|
|
1246
1259
|
return Reflect.getMetadata("design:type", target, propertyKey);
|
|
1247
1260
|
} else {
|
|
1248
1261
|
return Reflect.getMetadata("design:type", target);
|
|
1249
1262
|
}
|
|
1250
|
-
}
|
|
1251
|
-
getMetadata
|
|
1263
|
+
};
|
|
1264
|
+
ReflectUtils2.getMetadata = (metadataKey, target, propertyKey) => {
|
|
1252
1265
|
if (propertyKey) {
|
|
1253
1266
|
return Reflect.getMetadata(metadataKey, target, propertyKey);
|
|
1254
1267
|
} else {
|
|
1255
1268
|
return Reflect.getMetadata(metadataKey, target);
|
|
1256
1269
|
}
|
|
1257
|
-
}
|
|
1258
|
-
findMetadata
|
|
1270
|
+
};
|
|
1271
|
+
ReflectUtils2.findMetadata = (metadataKey, target, propertyKey) => {
|
|
1259
1272
|
if (target == null) return void 0;
|
|
1260
1273
|
let searchTarget = typeof target === "object" && typeof target !== "function" ? target.constructor : target;
|
|
1261
1274
|
while (searchTarget && searchTarget !== Object) {
|
|
@@ -1266,11 +1279,8 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
1266
1279
|
if (searchTarget === target) break;
|
|
1267
1280
|
}
|
|
1268
1281
|
return void 0;
|
|
1269
|
-
}
|
|
1270
|
-
|
|
1271
|
-
* 프로토타입 체인의 모든 메타데이터를 수집하여 리스트로 반환합니다. (부모 -> 자식 순)
|
|
1272
|
-
*/
|
|
1273
|
-
findAllMetadata: (metadataKey, target, propertyKey) => {
|
|
1282
|
+
};
|
|
1283
|
+
ReflectUtils2.findAllMetadata = (metadataKey, target, propertyKey) => {
|
|
1274
1284
|
const results = [];
|
|
1275
1285
|
if (target == null) return results;
|
|
1276
1286
|
let searchTarget = typeof target === "object" && typeof target !== "function" ? target.constructor : target;
|
|
@@ -1282,24 +1292,18 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
1282
1292
|
if (searchTarget === target) break;
|
|
1283
1293
|
}
|
|
1284
1294
|
return results;
|
|
1285
|
-
}
|
|
1286
|
-
|
|
1287
|
-
* 모든 메타데이터(배열 형태)를 수집하여 하나의 배열로 합칩니다. (부모 -> 자식 순)
|
|
1288
|
-
*/
|
|
1289
|
-
findAllMetadataFlatten: (metadataKey, target, propertyKey) => {
|
|
1295
|
+
};
|
|
1296
|
+
ReflectUtils2.findAllMetadataFlatten = (metadataKey, target, propertyKey) => {
|
|
1290
1297
|
const results = [];
|
|
1291
|
-
const metaList =
|
|
1298
|
+
const metaList = (0, ReflectUtils2.findAllMetadata)(metadataKey, target, propertyKey);
|
|
1292
1299
|
metaList.forEach((data) => {
|
|
1293
1300
|
if (Array.isArray(data)) results.push(...data);
|
|
1294
1301
|
});
|
|
1295
1302
|
return [...new Set(results)];
|
|
1296
|
-
}
|
|
1297
|
-
|
|
1298
|
-
* 프로토타입 체인의 모든 메타데이터(맵 형태)를 수집하여 합칩니다. (부모 -> 자식 순)
|
|
1299
|
-
*/
|
|
1300
|
-
findAllMapMetadata: (metadataKey, target) => {
|
|
1303
|
+
};
|
|
1304
|
+
ReflectUtils2.findAllMapMetadata = (metadataKey, target) => {
|
|
1301
1305
|
const finalMap = /* @__PURE__ */ new Map();
|
|
1302
|
-
const metaList =
|
|
1306
|
+
const metaList = (0, ReflectUtils2.findAllMetadata)(metadataKey, target);
|
|
1303
1307
|
metaList.forEach((data) => {
|
|
1304
1308
|
if (data instanceof Map) {
|
|
1305
1309
|
data.forEach((values, key) => {
|
|
@@ -1310,31 +1314,69 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
1310
1314
|
}
|
|
1311
1315
|
});
|
|
1312
1316
|
return finalMap;
|
|
1313
|
-
}
|
|
1314
|
-
getMetadataKeys
|
|
1317
|
+
};
|
|
1318
|
+
ReflectUtils2.getMetadataKeys = (target) => {
|
|
1315
1319
|
return Reflect.getMetadataKeys(target);
|
|
1316
|
-
}
|
|
1317
|
-
getOwnMetadata
|
|
1320
|
+
};
|
|
1321
|
+
ReflectUtils2.getOwnMetadata = (metadataKey, target, propertyKey) => {
|
|
1318
1322
|
if (propertyKey) {
|
|
1319
1323
|
return Reflect.getOwnMetadata(metadataKey, target, propertyKey);
|
|
1320
1324
|
} else {
|
|
1321
1325
|
return Reflect.getOwnMetadata(metadataKey, target);
|
|
1322
1326
|
}
|
|
1323
|
-
}
|
|
1324
|
-
getMetadatas
|
|
1325
|
-
return
|
|
1326
|
-
}
|
|
1327
|
-
metadata
|
|
1327
|
+
};
|
|
1328
|
+
ReflectUtils2.getMetadatas = (target) => {
|
|
1329
|
+
return (0, ReflectUtils2.getMetadataKeys)(target).map((it) => (0, ReflectUtils2.getMetadata)(it, target));
|
|
1330
|
+
};
|
|
1331
|
+
ReflectUtils2.metadata = (metadataKey, data) => {
|
|
1328
1332
|
return Reflect.metadata(metadataKey, data);
|
|
1329
|
-
}
|
|
1330
|
-
defineMetadata
|
|
1333
|
+
};
|
|
1334
|
+
ReflectUtils2.defineMetadata = (metadataKey, value, target, propertyKey) => {
|
|
1331
1335
|
if (propertyKey && Reflect.defineMetadata) {
|
|
1332
1336
|
Reflect.defineMetadata(metadataKey, value, target, propertyKey);
|
|
1333
1337
|
} else if (Reflect.defineMetadata) {
|
|
1334
1338
|
Reflect.defineMetadata(metadataKey, value, target);
|
|
1335
1339
|
}
|
|
1336
|
-
}
|
|
1337
|
-
};
|
|
1340
|
+
};
|
|
1341
|
+
})(ReflectUtils || (ReflectUtils = {}));
|
|
1342
|
+
|
|
1343
|
+
// ../core/dist/esm/function/FunctionUtils.js
|
|
1344
|
+
var FunctionUtils;
|
|
1345
|
+
((FunctionUtils2) => {
|
|
1346
|
+
FunctionUtils2.getParameterNames = (func, property) => {
|
|
1347
|
+
if (typeof func === "object" && property) {
|
|
1348
|
+
func = func[property];
|
|
1349
|
+
}
|
|
1350
|
+
return new RegExp("(?:" + func.name + "\\s*|^)\\s*\\((.*?)\\)").exec(func.toString().replace(/\n/g, ""))?.[1].replace(/\/\*.*?\*\//g, "").replace(/ /g, "").split(",") ?? [];
|
|
1351
|
+
};
|
|
1352
|
+
FunctionUtils2.evalScript = (script, obj) => {
|
|
1353
|
+
try {
|
|
1354
|
+
if (script && obj) {
|
|
1355
|
+
return Function(`"use strict";
|
|
1356
|
+
${script}
|
|
1357
|
+
`).bind(obj)();
|
|
1358
|
+
} else if (script) {
|
|
1359
|
+
return new Function("return " + script)();
|
|
1360
|
+
} else {
|
|
1361
|
+
return null;
|
|
1362
|
+
}
|
|
1363
|
+
} catch (e) {
|
|
1364
|
+
return null;
|
|
1365
|
+
}
|
|
1366
|
+
};
|
|
1367
|
+
FunctionUtils2.execute = (params) => {
|
|
1368
|
+
const { script, context, args = {} } = params;
|
|
1369
|
+
const argNames = Object.keys(args);
|
|
1370
|
+
const argValues = Object.values(args);
|
|
1371
|
+
return new Function(...argNames, script).apply(context, argValues);
|
|
1372
|
+
};
|
|
1373
|
+
FunctionUtils2.executeReturn = (params) => {
|
|
1374
|
+
const { script, context, args = {} } = params;
|
|
1375
|
+
const argNames = Object.keys(args);
|
|
1376
|
+
const argValues = Object.values(args);
|
|
1377
|
+
return new Function(...argNames, `return ${script}`).apply(context, argValues);
|
|
1378
|
+
};
|
|
1379
|
+
})(FunctionUtils || (FunctionUtils = {}));
|
|
1338
1380
|
|
|
1339
1381
|
// src/decorators/innerHtml.ts
|
|
1340
1382
|
var INNER_HTML_METADATA_KEY = Symbol("simple-web-component:inner-html");
|
|
@@ -1362,16 +1404,15 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
1362
1404
|
|
|
1363
1405
|
// src/decorators/addEventListener.ts
|
|
1364
1406
|
var ADD_EVENT_LISTENER_METADATA_KEY = Symbol("simple-web-component:add-event-listener");
|
|
1365
|
-
function addEventListener(
|
|
1407
|
+
function addEventListener(selector, type, options = {}) {
|
|
1366
1408
|
return (target, propertyKey, descriptor) => {
|
|
1367
1409
|
const constructor = target.constructor;
|
|
1368
|
-
const options = typeof arg1 === "string" ? { type: arg1, query: arg2 } : arg1;
|
|
1369
1410
|
let listeners = ReflectUtils.getMetadata(ADD_EVENT_LISTENER_METADATA_KEY, constructor);
|
|
1370
1411
|
if (!listeners) {
|
|
1371
1412
|
listeners = [];
|
|
1372
1413
|
ReflectUtils.defineMetadata(ADD_EVENT_LISTENER_METADATA_KEY, listeners, constructor);
|
|
1373
1414
|
}
|
|
1374
|
-
listeners.push({ options, propertyKey });
|
|
1415
|
+
listeners.push({ selector, type, options, propertyKey });
|
|
1375
1416
|
};
|
|
1376
1417
|
}
|
|
1377
1418
|
var getAddEventListenerMetadata = (target) => {
|
|
@@ -1417,11 +1458,11 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
1417
1458
|
// src/decorators/emitCustomEvent.ts
|
|
1418
1459
|
var EMIT_CUSTOM_EVENT_METADATA_KEY = Symbol("simple-web-component:emit-custom-event");
|
|
1419
1460
|
function emitCustomEvent(typeOrOptions) {
|
|
1420
|
-
return (target, propertyKey
|
|
1461
|
+
return (target, propertyKey) => {
|
|
1421
1462
|
const constructor = target.constructor;
|
|
1422
1463
|
const options = typeof typeOrOptions === "string" ? { type: typeOrOptions } : typeOrOptions;
|
|
1423
1464
|
if (!options.attributeName) {
|
|
1424
|
-
options.attributeName = `on
|
|
1465
|
+
options.attributeName = `swc-on-${options.type}`;
|
|
1425
1466
|
}
|
|
1426
1467
|
if (options.bubbles === void 0) options.bubbles = true;
|
|
1427
1468
|
if (options.composed === void 0) options.composed = true;
|
|
@@ -1431,18 +1472,6 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
1431
1472
|
ReflectUtils.defineMetadata(EMIT_CUSTOM_EVENT_METADATA_KEY, list, constructor);
|
|
1432
1473
|
}
|
|
1433
1474
|
list.push({ propertyKey, options });
|
|
1434
|
-
const originalMethod = descriptor.value;
|
|
1435
|
-
descriptor.value = function(...args) {
|
|
1436
|
-
const detail = originalMethod.apply(this, args);
|
|
1437
|
-
const event = new CustomEvent(options.type, {
|
|
1438
|
-
detail,
|
|
1439
|
-
bubbles: options.bubbles,
|
|
1440
|
-
composed: options.composed,
|
|
1441
|
-
cancelable: options.cancelable
|
|
1442
|
-
});
|
|
1443
|
-
this.dispatchEvent(event);
|
|
1444
|
-
return detail;
|
|
1445
|
-
};
|
|
1446
1475
|
};
|
|
1447
1476
|
}
|
|
1448
1477
|
var getEmitCustomEventMetadataList = (target) => {
|
|
@@ -1507,183 +1536,112 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
1507
1536
|
|
|
1508
1537
|
// src/utils/Utils.ts
|
|
1509
1538
|
var SWC_NOT_FOUND = Symbol("SWC_NOT_FOUND");
|
|
1510
|
-
var SwcUtils
|
|
1511
|
-
|
|
1539
|
+
var SwcUtils;
|
|
1540
|
+
((SwcUtils2) => {
|
|
1541
|
+
SwcUtils2.getHelperSet = (win) => {
|
|
1542
|
+
const doc = win.document;
|
|
1543
|
+
return {
|
|
1544
|
+
$d: doc,
|
|
1545
|
+
$w: win,
|
|
1546
|
+
$q: (sel, root) => (root ?? doc).querySelector(sel),
|
|
1547
|
+
$qa: (sel, root) => Array.from((root ?? doc).querySelectorAll(sel)),
|
|
1548
|
+
$qi: (id, root) => (root ?? doc).getElementById(id)
|
|
1549
|
+
};
|
|
1550
|
+
};
|
|
1551
|
+
SwcUtils2.getHelperAndHostSet = (win, el) => {
|
|
1552
|
+
const helperSet = (0, SwcUtils2.getHelperSet)(win);
|
|
1553
|
+
const hostSet = (0, SwcUtils2.getHostSet)(el);
|
|
1554
|
+
return {
|
|
1555
|
+
...helperSet,
|
|
1556
|
+
...hostSet
|
|
1557
|
+
};
|
|
1558
|
+
};
|
|
1559
|
+
SwcUtils2.getValueByPath = (obj, path, rootName) => {
|
|
1512
1560
|
if (!obj || !path) return SWC_NOT_FOUND;
|
|
1513
1561
|
const parts = path.split(".");
|
|
1514
|
-
|
|
1515
|
-
const subParts = parts.slice(1);
|
|
1516
|
-
let subResult = obj;
|
|
1517
|
-
for (const part of subParts) {
|
|
1518
|
-
if (subResult === null || typeof subResult !== "object" || !(part in subResult)) return SWC_NOT_FOUND;
|
|
1519
|
-
subResult = subResult[part];
|
|
1520
|
-
}
|
|
1521
|
-
return subResult;
|
|
1522
|
-
}
|
|
1523
|
-
let result = obj;
|
|
1562
|
+
let current = obj;
|
|
1524
1563
|
for (const part of parts) {
|
|
1525
|
-
if (
|
|
1526
|
-
|
|
1527
|
-
}
|
|
1528
|
-
result = result[part];
|
|
1564
|
+
if (current === null || current === void 0) return SWC_NOT_FOUND;
|
|
1565
|
+
current = current[part];
|
|
1529
1566
|
}
|
|
1530
|
-
|
|
1531
|
-
|
|
1567
|
+
return current;
|
|
1568
|
+
};
|
|
1569
|
+
SwcUtils2.findNearestSwcHost = (el) => {
|
|
1570
|
+
if (el.__swc_host) return el.__swc_host;
|
|
1571
|
+
let current = el.parentElement || el.getRootNode?.()?.host;
|
|
1572
|
+
while (current && current !== document && current !== window) {
|
|
1573
|
+
if (current.__swc_host) return current.__swc_host;
|
|
1574
|
+
if (getElementConfig(current)) return current;
|
|
1575
|
+
current = current.parentElement || current.getRootNode?.()?.host;
|
|
1532
1576
|
}
|
|
1533
|
-
return
|
|
1534
|
-
}
|
|
1535
|
-
|
|
1536
|
-
try {
|
|
1537
|
-
const keys = Object.keys(context);
|
|
1538
|
-
const values = Object.values(context);
|
|
1539
|
-
return new Function(...keys, `return (${expr})`).apply(null, values);
|
|
1540
|
-
} catch {
|
|
1541
|
-
return SWC_NOT_FOUND;
|
|
1542
|
-
}
|
|
1543
|
-
}
|
|
1544
|
-
static applyData(node, data, options) {
|
|
1545
|
-
const { asKey, asIndexKey, index, hostContext } = options;
|
|
1546
|
-
const context = {};
|
|
1547
|
-
if (index !== void 0) {
|
|
1548
|
-
context[asIndexKey] = index;
|
|
1549
|
-
}
|
|
1550
|
-
if (data !== null && data !== void 0) {
|
|
1551
|
-
context[asKey] = data;
|
|
1552
|
-
context["value"] = data;
|
|
1553
|
-
}
|
|
1554
|
-
const fullContext = { ...hostContext || {}, ...context };
|
|
1555
|
-
const resolveExpr = (expr, match) => {
|
|
1556
|
-
expr = expr.trim();
|
|
1557
|
-
const simpleVal = _SwcUtils.getValueByPath(data, expr, asKey);
|
|
1558
|
-
if (simpleVal !== SWC_NOT_FOUND && typeof simpleVal !== "symbol") {
|
|
1559
|
-
return simpleVal === null || simpleVal === void 0 ? "" : String(simpleVal);
|
|
1560
|
-
}
|
|
1561
|
-
const exprVal = _SwcUtils.evalExpression(expr, fullContext);
|
|
1562
|
-
if (exprVal !== SWC_NOT_FOUND && typeof exprVal !== "symbol") {
|
|
1563
|
-
return exprVal === null || exprVal === void 0 ? "" : String(exprVal);
|
|
1564
|
-
}
|
|
1565
|
-
return match;
|
|
1566
|
-
};
|
|
1567
|
-
const walk = (n) => {
|
|
1568
|
-
if (n.nodeType === Node.TEXT_NODE) {
|
|
1569
|
-
if (!n._original) n._original = n.textContent;
|
|
1570
|
-
let text = n._original;
|
|
1571
|
-
text = text.replace(/{{(.*?)}}/g, (match, path) => {
|
|
1572
|
-
return resolveExpr(path, match);
|
|
1573
|
-
});
|
|
1574
|
-
if (n.textContent !== text) n.textContent = text;
|
|
1575
|
-
} else if (n.nodeType === Node.ELEMENT_NODE) {
|
|
1576
|
-
const el = n;
|
|
1577
|
-
Array.from(el.attributes).forEach((a) => {
|
|
1578
|
-
if (!a._original) a._original = a.value;
|
|
1579
|
-
let val = a._original;
|
|
1580
|
-
val = val.replace(/{{(.*?)}}/g, (match, path) => {
|
|
1581
|
-
return resolveExpr(path, match);
|
|
1582
|
-
});
|
|
1583
|
-
if (a.value !== val) a.value = val;
|
|
1584
|
-
});
|
|
1585
|
-
el.childNodes.forEach(walk);
|
|
1586
|
-
}
|
|
1587
|
-
};
|
|
1588
|
-
walk(node);
|
|
1589
|
-
}
|
|
1590
|
-
static createReactiveProxy(target, onChange, onIndexChange) {
|
|
1591
|
-
const makeRecursiveProxy = (obj) => {
|
|
1592
|
-
if (typeof obj !== "object" || obj === null || obj instanceof Node) return obj;
|
|
1593
|
-
if (obj.__swc_is_proxy) return obj;
|
|
1594
|
-
const IS_PROXY_KEY = "__swc_is_proxy";
|
|
1595
|
-
const proxy = new Proxy(obj, {
|
|
1596
|
-
get: (t, prop) => {
|
|
1597
|
-
if (prop === IS_PROXY_KEY) return true;
|
|
1598
|
-
if (typeof prop === "symbol") return t[prop];
|
|
1599
|
-
return t[prop];
|
|
1600
|
-
},
|
|
1601
|
-
set: (t, prop, val) => {
|
|
1602
|
-
if (prop === IS_PROXY_KEY) return true;
|
|
1603
|
-
if (typeof prop === "symbol") {
|
|
1604
|
-
t[prop] = val;
|
|
1605
|
-
return true;
|
|
1606
|
-
}
|
|
1607
|
-
const oldVal = t[prop];
|
|
1608
|
-
if (oldVal === val) return true;
|
|
1609
|
-
t[prop] = makeRecursiveProxy(val);
|
|
1610
|
-
const isIndex = !isNaN(Number(prop)) && Array.isArray(t);
|
|
1611
|
-
if (isIndex && onIndexChange) {
|
|
1612
|
-
onIndexChange(Number(prop), val);
|
|
1613
|
-
} else {
|
|
1614
|
-
onChange();
|
|
1615
|
-
}
|
|
1616
|
-
return true;
|
|
1617
|
-
},
|
|
1618
|
-
deleteProperty: (t, prop) => {
|
|
1619
|
-
delete t[prop];
|
|
1620
|
-
onChange();
|
|
1621
|
-
return true;
|
|
1622
|
-
}
|
|
1623
|
-
});
|
|
1624
|
-
return proxy;
|
|
1625
|
-
};
|
|
1626
|
-
return makeRecursiveProxy(target);
|
|
1627
|
-
}
|
|
1628
|
-
static findNearestSwcHost(el) {
|
|
1629
|
-
const hosts = this.findAllSwcHosts(el);
|
|
1630
|
-
return hosts.length > 0 ? hosts[hosts.length - 1] : null;
|
|
1631
|
-
}
|
|
1632
|
-
static findAllSwcHosts(el) {
|
|
1577
|
+
return void 0;
|
|
1578
|
+
};
|
|
1579
|
+
SwcUtils2.findAllSwcHosts = (el) => {
|
|
1633
1580
|
const hosts = [];
|
|
1634
|
-
let
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
curr = curr.parentElement || curr?.getRootNode()?.host;
|
|
1581
|
+
let current = (0, SwcUtils2.findNearestSwcHost)(el);
|
|
1582
|
+
while (current) {
|
|
1583
|
+
hosts.push(current);
|
|
1584
|
+
current = (0, SwcUtils2.findNearestSwcHost)(current);
|
|
1639
1585
|
}
|
|
1640
1586
|
return hosts.reverse();
|
|
1641
|
-
}
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
static getAppHosts(el) {
|
|
1654
|
-
const hosts = this.getHosts(el);
|
|
1587
|
+
};
|
|
1588
|
+
SwcUtils2.getHosts = (el) => {
|
|
1589
|
+
const ancestors = (0, SwcUtils2.findAllSwcHosts)(el);
|
|
1590
|
+
if (getElementConfig(el)) return [...ancestors, el];
|
|
1591
|
+
return ancestors;
|
|
1592
|
+
};
|
|
1593
|
+
SwcUtils2.getHost = (el) => {
|
|
1594
|
+
if (getElementConfig(el)) return el;
|
|
1595
|
+
return (0, SwcUtils2.findNearestSwcHost)(el);
|
|
1596
|
+
};
|
|
1597
|
+
SwcUtils2.getAppHosts = (el) => {
|
|
1598
|
+
const hosts = (0, SwcUtils2.getHosts)(el);
|
|
1655
1599
|
return hosts.filter((host) => host.tagName.toLowerCase() === "swc-app" || host.getAttribute("is")?.startsWith("swc-app-"));
|
|
1656
|
-
}
|
|
1657
|
-
|
|
1658
|
-
const appHosts =
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
const $
|
|
1600
|
+
};
|
|
1601
|
+
SwcUtils2.getAppHost = (el) => {
|
|
1602
|
+
const appHosts = (0, SwcUtils2.getAppHosts)(el);
|
|
1603
|
+
const appHostsWithoutSelf = appHosts.filter((h) => h !== el);
|
|
1604
|
+
return appHostsWithoutSelf.length > 0 ? appHostsWithoutSelf[appHostsWithoutSelf.length - 1] : void 0;
|
|
1605
|
+
};
|
|
1606
|
+
SwcUtils2.getHostSet = (el) => {
|
|
1607
|
+
const isSwc = !!getElementConfig(el);
|
|
1608
|
+
const ancestors = (0, SwcUtils2.findAllSwcHosts)(el);
|
|
1609
|
+
let $host;
|
|
1610
|
+
let $parentHost;
|
|
1611
|
+
if (isSwc) {
|
|
1612
|
+
$host = el;
|
|
1613
|
+
$parentHost = ancestors.length > 0 ? ancestors[ancestors.length - 1] : null;
|
|
1614
|
+
} else {
|
|
1615
|
+
$host = ancestors.length > 0 ? ancestors[ancestors.length - 1] : el;
|
|
1616
|
+
$parentHost = ancestors.length > 1 ? ancestors[ancestors.length - 2] : null;
|
|
1617
|
+
}
|
|
1618
|
+
const $hosts = isSwc ? [...ancestors, el] : ancestors;
|
|
1619
|
+
const $firstHost = $hosts.length > 0 ? $hosts[0] : null;
|
|
1620
|
+
const loopContext = {};
|
|
1621
|
+
let curr = el;
|
|
1622
|
+
while (curr && curr !== document.documentElement) {
|
|
1623
|
+
if (curr.__swc_loop_context) {
|
|
1624
|
+
Object.assign(loopContext, curr.__swc_loop_context);
|
|
1625
|
+
}
|
|
1626
|
+
curr = curr.parentElement || curr.getRootNode().host;
|
|
1627
|
+
}
|
|
1628
|
+
const $appHosts = $hosts.filter((h) => h.tagName.toLowerCase() === "swc-app" || h.getAttribute("is")?.startsWith("swc-app-"));
|
|
1629
|
+
const $appHost = $appHosts.length > 0 ? $appHosts[$appHosts.length - 1] === el ? $appHosts.length > 1 ? $appHosts[$appHosts.length - 2] : null : $appHosts[$appHosts.length - 1] : null;
|
|
1630
|
+
const $firstAppHost = $appHosts.length > 0 ? $appHosts[0] : null;
|
|
1675
1631
|
return {
|
|
1676
|
-
$host
|
|
1632
|
+
$host,
|
|
1633
|
+
$parentHost,
|
|
1677
1634
|
$hosts,
|
|
1678
1635
|
$firstHost,
|
|
1679
|
-
$lastHost,
|
|
1680
|
-
$appHost
|
|
1636
|
+
$lastHost: $parentHost,
|
|
1637
|
+
$appHost,
|
|
1681
1638
|
$appHosts,
|
|
1682
1639
|
$firstAppHost,
|
|
1683
|
-
$lastAppHost
|
|
1640
|
+
$lastAppHost: $appHost,
|
|
1641
|
+
...loopContext
|
|
1684
1642
|
};
|
|
1685
|
-
}
|
|
1686
|
-
};
|
|
1643
|
+
};
|
|
1644
|
+
})(SwcUtils || (SwcUtils = {}));
|
|
1687
1645
|
|
|
1688
1646
|
// src/config/config.ts
|
|
1689
1647
|
var HTML_TAG_ENTRIES = [
|
|
@@ -1795,6 +1753,7 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
1795
1753
|
InjectSituationType2["APP_HOST"] = "SIMPLE_WEB_COMPONENT://APPHOST";
|
|
1796
1754
|
InjectSituationType2["APP_HOSTS"] = "SIMPLE_WEB_COMPONENT://APPHOSTS";
|
|
1797
1755
|
InjectSituationType2["HOST"] = "SIMPLE_WEB_COMPONENT://HOST";
|
|
1756
|
+
InjectSituationType2["PARENT_HOST"] = "SIMPLE_WEB_COMPONENT://PARENTHOST";
|
|
1798
1757
|
InjectSituationType2["HOSTS"] = "SIMPLE_WEB_COMPONENT://HOSTS";
|
|
1799
1758
|
InjectSituationType2["FIRST_HOST"] = "SIMPLE_WEB_COMPONENT://FIRSTHOST";
|
|
1800
1759
|
InjectSituationType2["LAST_HOST"] = "SIMPLE_WEB_COMPONENT://LASTHOST";
|
|
@@ -1805,6 +1764,7 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
1805
1764
|
|
|
1806
1765
|
// src/decorators/elementDefine.ts
|
|
1807
1766
|
var ELEMENT_CONFIG_KEY = Symbol("simple-web-component:element-config");
|
|
1767
|
+
var globalDelegatedRoots = /* @__PURE__ */ new WeakSet();
|
|
1808
1768
|
function buildEnv(configWindow) {
|
|
1809
1769
|
const win = configWindow || (typeof window !== "undefined" ? window : void 0);
|
|
1810
1770
|
const doc = win?.document;
|
|
@@ -1813,13 +1773,7 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
1813
1773
|
if (win?.[cls])
|
|
1814
1774
|
builtInTagMap.set(win[cls], tag);
|
|
1815
1775
|
}
|
|
1816
|
-
const domHelpers =
|
|
1817
|
-
$d: doc,
|
|
1818
|
-
$w: win,
|
|
1819
|
-
$q: (sel, root) => (root ?? doc).querySelector(sel),
|
|
1820
|
-
$qa: (sel, root) => Array.from((root ?? doc).querySelectorAll(sel)),
|
|
1821
|
-
$qi: (id, root) => (root ?? doc).getElementById(id)
|
|
1822
|
-
};
|
|
1776
|
+
const domHelpers = SwcUtils.getHelperSet(win);
|
|
1823
1777
|
return { win, doc, builtInTagMap, domHelpers };
|
|
1824
1778
|
}
|
|
1825
1779
|
var getHandlers = (inst) => {
|
|
@@ -1831,8 +1785,6 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
1831
1785
|
const config = typeof inConfig === "string" ? { name: inConfig } : inConfig;
|
|
1832
1786
|
const { win, doc, builtInTagMap: BUILT_IN_TAG_MAP, domHelpers: SWC_DOM_HELPERS } = buildEnv(config.window);
|
|
1833
1787
|
config.window = win;
|
|
1834
|
-
const SWC_DOM_HELPER_KEYS = Object.keys(SWC_DOM_HELPERS);
|
|
1835
|
-
const SWC_DOM_HELPER_VALS = () => SWC_DOM_HELPER_KEYS.map((k) => SWC_DOM_HELPERS[k]);
|
|
1836
1788
|
let extendsTagName = config.extends;
|
|
1837
1789
|
if (!extendsTagName) {
|
|
1838
1790
|
let proto = constructor;
|
|
@@ -1858,9 +1810,7 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
1858
1810
|
if (script) {
|
|
1859
1811
|
try {
|
|
1860
1812
|
const args = { ...hostSet, ...SWC_DOM_HELPERS, ...extraArgs };
|
|
1861
|
-
|
|
1862
|
-
const argValues = Object.values(args);
|
|
1863
|
-
new Function(...argNames, script).apply(this, argValues);
|
|
1813
|
+
FunctionUtils.execute({ script, context: this, args });
|
|
1864
1814
|
} catch (e) {
|
|
1865
1815
|
console.error(`[SWC] Failed to execute ${attrName}:`, e);
|
|
1866
1816
|
}
|
|
@@ -1883,10 +1833,12 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
1883
1833
|
return this[methodName](...extraArgs);
|
|
1884
1834
|
}
|
|
1885
1835
|
}
|
|
1886
|
-
_bindAttributeEvent(el, attrName, script) {
|
|
1887
|
-
if (!
|
|
1888
|
-
|
|
1889
|
-
|
|
1836
|
+
_bindAttributeEvent(el, attrName, script, eventName) {
|
|
1837
|
+
if (!eventName) {
|
|
1838
|
+
if (!attrName.startsWith("swc-on-"))
|
|
1839
|
+
return;
|
|
1840
|
+
eventName = attrName.substring(7);
|
|
1841
|
+
}
|
|
1890
1842
|
if (swcLifecycleAttributes.includes(attrName))
|
|
1891
1843
|
return;
|
|
1892
1844
|
const elHandlers = getHandlers(this);
|
|
@@ -1900,9 +1852,13 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
1900
1852
|
el.removeEventListener(eventName, oldHandler);
|
|
1901
1853
|
const handler = (event) => {
|
|
1902
1854
|
const hostSet = SwcUtils.getHostSet(el);
|
|
1903
|
-
const
|
|
1904
|
-
|
|
1905
|
-
|
|
1855
|
+
const args = {
|
|
1856
|
+
event,
|
|
1857
|
+
$data: event.detail,
|
|
1858
|
+
...hostSet,
|
|
1859
|
+
...SWC_DOM_HELPERS
|
|
1860
|
+
};
|
|
1861
|
+
FunctionUtils.execute({ script, context: el, args });
|
|
1906
1862
|
};
|
|
1907
1863
|
el.addEventListener(eventName, handler);
|
|
1908
1864
|
handlers.set(attrName, handler);
|
|
@@ -1911,6 +1867,7 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
1911
1867
|
super(...args);
|
|
1912
1868
|
this._swcId = Math.random().toString(36).substring(2, 11);
|
|
1913
1869
|
this._emitHandlers = /* @__PURE__ */ new Map();
|
|
1870
|
+
this._boundListeners = [];
|
|
1914
1871
|
const hostSet = SwcUtils.getHostSet(this);
|
|
1915
1872
|
this._executeSwcScript("swc-on-constructor", hostSet);
|
|
1916
1873
|
if (innerHtmlList.some((it) => it.options.useShadow === true) && !this.shadowRoot) {
|
|
@@ -1921,6 +1878,9 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
1921
1878
|
return mergedObservedAttributes;
|
|
1922
1879
|
}
|
|
1923
1880
|
async connectedCallback() {
|
|
1881
|
+
const conf = getElementConfig(this);
|
|
1882
|
+
const currentWin = conf?.window || window;
|
|
1883
|
+
const currentDoc = currentWin.document;
|
|
1924
1884
|
const hostSet = SwcUtils.getHostSet(this);
|
|
1925
1885
|
this._executeSwcScript("swc-on-before-connected", hostSet);
|
|
1926
1886
|
const bMethods = findAllLifecycleMetadata(this, ON_BEFORE_CONNECTED_METADATA_KEY);
|
|
@@ -1946,19 +1906,122 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
1946
1906
|
if (lContent)
|
|
1947
1907
|
this.innerHTML = lContent;
|
|
1948
1908
|
}
|
|
1909
|
+
const createDelegationHandler = (delegateHost) => (event) => {
|
|
1910
|
+
if (event.__swc_handled)
|
|
1911
|
+
return;
|
|
1912
|
+
const path = event.composedPath();
|
|
1913
|
+
const type = event.type;
|
|
1914
|
+
const attrName = `swc-on-${type}`;
|
|
1915
|
+
for (const node of path) {
|
|
1916
|
+
if (node === delegateHost)
|
|
1917
|
+
break;
|
|
1918
|
+
if (!(node instanceof HTMLElement))
|
|
1919
|
+
continue;
|
|
1920
|
+
const script = node.getAttribute?.(attrName);
|
|
1921
|
+
if (script && !getElementConfig(node)) {
|
|
1922
|
+
const host = SwcUtils.findNearestSwcHost(node);
|
|
1923
|
+
if (host) {
|
|
1924
|
+
const childHostSet = SwcUtils.getHostSet(node);
|
|
1925
|
+
const args = {
|
|
1926
|
+
event,
|
|
1927
|
+
$data: event.detail,
|
|
1928
|
+
...childHostSet,
|
|
1929
|
+
...SWC_DOM_HELPERS
|
|
1930
|
+
};
|
|
1931
|
+
FunctionUtils.execute({ script, context: node, args });
|
|
1932
|
+
event.__swc_handled = true;
|
|
1933
|
+
break;
|
|
1934
|
+
}
|
|
1935
|
+
}
|
|
1936
|
+
}
|
|
1937
|
+
};
|
|
1938
|
+
DOM_EVENT_NAMES.forEach((type) => {
|
|
1939
|
+
this.addEventListener(type, createDelegationHandler(this));
|
|
1940
|
+
this._boundListeners.push({ target: this, type, handler: createDelegationHandler(this) });
|
|
1941
|
+
});
|
|
1942
|
+
const hasParentHost = SwcUtils.findAllSwcHosts(this).length > 0;
|
|
1943
|
+
if (!hasParentHost) {
|
|
1944
|
+
const root = this.getRootNode();
|
|
1945
|
+
if (!globalDelegatedRoots.has(root)) {
|
|
1946
|
+
DOM_EVENT_NAMES.forEach((type) => {
|
|
1947
|
+
const handler = createDelegationHandler(root);
|
|
1948
|
+
root.addEventListener(type, handler);
|
|
1949
|
+
});
|
|
1950
|
+
globalDelegatedRoots.add(root);
|
|
1951
|
+
}
|
|
1952
|
+
}
|
|
1949
1953
|
addEventListenerList.forEach((meta) => {
|
|
1950
|
-
const {
|
|
1951
|
-
const
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
+
const { selector, type, options } = meta;
|
|
1955
|
+
const { root, capture, once, passive, stopPropagation, stopImmediatePropagation, preventDefault, delegate, removeOnDisconnected } = options;
|
|
1956
|
+
const opts = { capture, once, passive };
|
|
1957
|
+
const bindTargets = [];
|
|
1958
|
+
if (selector === ":window") {
|
|
1959
|
+
bindTargets.push(currentWin);
|
|
1960
|
+
} else if (selector === ":document") {
|
|
1961
|
+
bindTargets.push(currentDoc);
|
|
1962
|
+
} else if (selector === ":parentHost") {
|
|
1963
|
+
if (hostSet.$parentHost)
|
|
1964
|
+
bindTargets.push(hostSet.$parentHost);
|
|
1965
|
+
} else if (selector === ":appHost") {
|
|
1966
|
+
if (hostSet.$appHost)
|
|
1967
|
+
bindTargets.push(hostSet.$appHost);
|
|
1968
|
+
} else if (selector === ":firstHost") {
|
|
1969
|
+
if (hostSet.$firstHost)
|
|
1970
|
+
bindTargets.push(hostSet.$firstHost);
|
|
1971
|
+
} else if (selector === ":lastHost") {
|
|
1972
|
+
if (hostSet.$lastHost)
|
|
1973
|
+
bindTargets.push(hostSet.$lastHost);
|
|
1974
|
+
} else if (selector === ":firstAppHost") {
|
|
1975
|
+
if (hostSet.$firstAppHost)
|
|
1976
|
+
bindTargets.push(hostSet.$firstAppHost);
|
|
1977
|
+
} else if (selector === ":lastAppHost") {
|
|
1978
|
+
if (hostSet.$lastAppHost)
|
|
1979
|
+
bindTargets.push(hostSet.$lastAppHost);
|
|
1980
|
+
} else if (!selector || selector === ":host") {
|
|
1981
|
+
bindTargets.push(this);
|
|
1982
|
+
} else if (delegate) {
|
|
1983
|
+
const bindRoots = [];
|
|
1984
|
+
const r = root || "auto";
|
|
1985
|
+
if (r === "auto")
|
|
1986
|
+
bindRoots.push(this.shadowRoot || this);
|
|
1987
|
+
else if (r === "light")
|
|
1988
|
+
bindRoots.push(this);
|
|
1989
|
+
else if (r === "shadow") {
|
|
1990
|
+
if (this.shadowRoot)
|
|
1991
|
+
bindRoots.push(this.shadowRoot);
|
|
1992
|
+
} else if (r === "all") {
|
|
1993
|
+
bindRoots.push(this);
|
|
1994
|
+
if (this.shadowRoot)
|
|
1995
|
+
bindRoots.push(this.shadowRoot);
|
|
1996
|
+
}
|
|
1997
|
+
bindRoots.forEach((br) => {
|
|
1998
|
+
const handler = (event) => {
|
|
1999
|
+
const matchedEl = event.target.closest(selector);
|
|
2000
|
+
if (matchedEl && br.contains(matchedEl)) {
|
|
2001
|
+
if (stopPropagation)
|
|
2002
|
+
event.stopPropagation();
|
|
2003
|
+
if (stopImmediatePropagation)
|
|
2004
|
+
event.stopImmediatePropagation();
|
|
2005
|
+
if (preventDefault)
|
|
2006
|
+
event.preventDefault();
|
|
2007
|
+
const currentHostSet = SwcUtils.getHostSet(this);
|
|
2008
|
+
this._invokeLifecycleMethod(meta.propertyKey, currentHostSet, [event, currentHostSet, matchedEl]);
|
|
2009
|
+
}
|
|
2010
|
+
};
|
|
2011
|
+
br.addEventListener(type, handler, opts);
|
|
2012
|
+
const self2 = this;
|
|
2013
|
+
if (removeOnDisconnected === true || br !== self2 && br !== self2.shadowRoot) {
|
|
2014
|
+
this._boundListeners.push({ target: br, type, handler, options: opts });
|
|
2015
|
+
}
|
|
2016
|
+
});
|
|
1954
2017
|
} else {
|
|
1955
2018
|
const searchRoots = [];
|
|
1956
2019
|
const r = root || "auto";
|
|
1957
|
-
if (r === "auto")
|
|
2020
|
+
if (r === "auto")
|
|
1958
2021
|
searchRoots.push(this.shadowRoot || this);
|
|
1959
|
-
|
|
2022
|
+
else if (r === "light")
|
|
1960
2023
|
searchRoots.push(this);
|
|
1961
|
-
|
|
2024
|
+
else if (r === "shadow") {
|
|
1962
2025
|
if (this.shadowRoot)
|
|
1963
2026
|
searchRoots.push(this.shadowRoot);
|
|
1964
2027
|
} else if (r === "all") {
|
|
@@ -1967,11 +2030,10 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
1967
2030
|
searchRoots.push(this.shadowRoot);
|
|
1968
2031
|
}
|
|
1969
2032
|
searchRoots.forEach((sr) => {
|
|
1970
|
-
|
|
1971
|
-
found.forEach((el) => targetEls.push(el));
|
|
2033
|
+
sr.querySelectorAll(selector).forEach((el) => bindTargets.push(el));
|
|
1972
2034
|
});
|
|
1973
2035
|
}
|
|
1974
|
-
|
|
2036
|
+
bindTargets.forEach((target) => {
|
|
1975
2037
|
const handler = (event) => {
|
|
1976
2038
|
if (stopPropagation)
|
|
1977
2039
|
event.stopPropagation();
|
|
@@ -1979,11 +2041,13 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
1979
2041
|
event.stopImmediatePropagation();
|
|
1980
2042
|
if (preventDefault)
|
|
1981
2043
|
event.preventDefault();
|
|
1982
|
-
const
|
|
1983
|
-
this._invokeLifecycleMethod(meta.propertyKey,
|
|
2044
|
+
const currentHostSet = SwcUtils.getHostSet(this);
|
|
2045
|
+
this._invokeLifecycleMethod(meta.propertyKey, currentHostSet, [event, currentHostSet]);
|
|
1984
2046
|
};
|
|
1985
|
-
|
|
1986
|
-
|
|
2047
|
+
target.addEventListener(type, handler, opts);
|
|
2048
|
+
if (removeOnDisconnected === true || target === currentWin || target === currentDoc) {
|
|
2049
|
+
this._boundListeners.push({ target, type, handler, options: opts });
|
|
2050
|
+
}
|
|
1987
2051
|
});
|
|
1988
2052
|
});
|
|
1989
2053
|
if (super.connectedCallback)
|
|
@@ -2002,6 +2066,8 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
2002
2066
|
const bMethods = findAllLifecycleMetadata(this, ON_BEFORE_DISCONNECTED_METADATA_KEY);
|
|
2003
2067
|
if (bMethods)
|
|
2004
2068
|
bMethods.forEach((m) => this._invokeLifecycleMethod(m, hostSet));
|
|
2069
|
+
this._boundListeners.forEach((l) => l.target.removeEventListener(l.type, l.handler, l.options));
|
|
2070
|
+
this._boundListeners = [];
|
|
2005
2071
|
if (super.disconnectedCallback)
|
|
2006
2072
|
super.disconnectedCallback();
|
|
2007
2073
|
const aMethods = findAllLifecycleMetadata(this, ON_AFTER_DISCONNECTED_METADATA_KEY);
|
|
@@ -2029,7 +2095,9 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
2029
2095
|
super.attributeChangedCallback(name, old, newVal);
|
|
2030
2096
|
if (name.startsWith("swc-on-") && !swcLifecycleAttributes.includes(name)) {
|
|
2031
2097
|
if (newVal !== null) {
|
|
2032
|
-
|
|
2098
|
+
const customEventMeta = emitCustomEventList.find((it) => it.options.attributeName === name);
|
|
2099
|
+
const eventName = customEventMeta ? customEventMeta.options.type : name.substring(7);
|
|
2100
|
+
this._bindAttributeEvent(this, name, newVal, eventName);
|
|
2033
2101
|
}
|
|
2034
2102
|
}
|
|
2035
2103
|
const mKeys = attrChangeMap.get(name);
|
|
@@ -2054,6 +2122,23 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
2054
2122
|
};
|
|
2055
2123
|
}
|
|
2056
2124
|
});
|
|
2125
|
+
emitCustomEventList.forEach((meta) => {
|
|
2126
|
+
const { propertyKey, options } = meta;
|
|
2127
|
+
const original = NewClass.prototype[propertyKey];
|
|
2128
|
+
if (typeof original === "function") {
|
|
2129
|
+
NewClass.prototype[propertyKey] = function(...args) {
|
|
2130
|
+
const detail = original.apply(this, args);
|
|
2131
|
+
const event = new CustomEvent(options.type, {
|
|
2132
|
+
detail,
|
|
2133
|
+
bubbles: options.bubbles,
|
|
2134
|
+
composed: options.composed,
|
|
2135
|
+
cancelable: options.cancelable
|
|
2136
|
+
});
|
|
2137
|
+
this.dispatchEvent(event);
|
|
2138
|
+
return detail;
|
|
2139
|
+
};
|
|
2140
|
+
}
|
|
2141
|
+
});
|
|
2057
2142
|
const originalProto = constructor.prototype;
|
|
2058
2143
|
const newProto = NewClass.prototype;
|
|
2059
2144
|
Object.getOwnPropertyNames(originalProto).forEach((name) => {
|
|
@@ -2077,48 +2162,57 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
2077
2162
|
|
|
2078
2163
|
// src/decorators/query.ts
|
|
2079
2164
|
var QUERY_METADATA_KEY = Symbol("simple-web-component:query");
|
|
2080
|
-
function query(
|
|
2081
|
-
|
|
2082
|
-
|
|
2165
|
+
function query(selector, options = {}) {
|
|
2166
|
+
return (target, propertyKey, descriptor) => {
|
|
2167
|
+
if (descriptor !== void 0) {
|
|
2168
|
+
throw new Error(`@query decorator cannot be used on methods. (Method: ${String(propertyKey)})`);
|
|
2169
|
+
}
|
|
2083
2170
|
const constructor = target.constructor;
|
|
2084
2171
|
let queries = ReflectUtils.getMetadata(QUERY_METADATA_KEY, constructor);
|
|
2085
2172
|
if (!queries) {
|
|
2086
2173
|
queries = [];
|
|
2087
2174
|
ReflectUtils.defineMetadata(QUERY_METADATA_KEY, queries, constructor);
|
|
2088
2175
|
}
|
|
2089
|
-
queries.push({ selector, options, propertyKey
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
return
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2176
|
+
queries.push({ selector, options, propertyKey });
|
|
2177
|
+
Object.defineProperty(target, propertyKey, {
|
|
2178
|
+
get() {
|
|
2179
|
+
const hostSet = SwcUtils.getHostSet(this);
|
|
2180
|
+
if (selector === ":parentHost")
|
|
2181
|
+
return hostSet.$parentHost;
|
|
2182
|
+
if (selector === ":appHost")
|
|
2183
|
+
return hostSet.$appHost;
|
|
2184
|
+
if (selector === ":firstHost")
|
|
2185
|
+
return hostSet.$firstHost;
|
|
2186
|
+
if (selector === ":lastHost")
|
|
2187
|
+
return hostSet.$lastHost;
|
|
2188
|
+
if (selector === ":firstAppHost")
|
|
2189
|
+
return hostSet.$firstAppHost;
|
|
2190
|
+
if (selector === ":lastAppHost")
|
|
2191
|
+
return hostSet.$lastAppHost;
|
|
2192
|
+
const config = getElementConfig(this);
|
|
2193
|
+
const win = config?.window || window;
|
|
2194
|
+
const doc = win.document;
|
|
2195
|
+
if (selector === ":window")
|
|
2196
|
+
return win;
|
|
2197
|
+
if (selector === ":document")
|
|
2198
|
+
return doc;
|
|
2199
|
+
if (!selector || selector === ":host")
|
|
2200
|
+
return this;
|
|
2201
|
+
const r = options.root || "auto";
|
|
2202
|
+
if (r === "shadow") {
|
|
2203
|
+
return this.shadowRoot ? this.shadowRoot.querySelector(selector) : null;
|
|
2204
|
+
}
|
|
2205
|
+
if (r === "light") {
|
|
2206
|
+
return this.querySelector(selector);
|
|
2207
|
+
}
|
|
2208
|
+
if (r === "all") {
|
|
2209
|
+
return this.shadowRoot?.querySelector(selector) || this.querySelector(selector);
|
|
2210
|
+
}
|
|
2211
|
+
return (this.shadowRoot || this).querySelector(selector);
|
|
2212
|
+
},
|
|
2213
|
+
enumerable: true,
|
|
2214
|
+
configurable: true
|
|
2215
|
+
});
|
|
2122
2216
|
};
|
|
2123
2217
|
}
|
|
2124
2218
|
var getQueryMetadata = (target) => {
|
|
@@ -2128,48 +2222,52 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
2128
2222
|
|
|
2129
2223
|
// src/decorators/queryAll.ts
|
|
2130
2224
|
var QUERY_ALL_METADATA_KEY = Symbol("simple-web-component:query-all");
|
|
2131
|
-
function queryAll(
|
|
2132
|
-
|
|
2133
|
-
|
|
2225
|
+
function queryAll(selector, options = {}) {
|
|
2226
|
+
return (target, propertyKey, descriptor) => {
|
|
2227
|
+
if (descriptor !== void 0) {
|
|
2228
|
+
throw new Error(`@queryAll decorator cannot be used on methods. (Method: ${String(propertyKey)})`);
|
|
2229
|
+
}
|
|
2134
2230
|
const constructor = target.constructor;
|
|
2135
2231
|
let queries = ReflectUtils.getMetadata(QUERY_ALL_METADATA_KEY, constructor);
|
|
2136
2232
|
if (!queries) {
|
|
2137
2233
|
queries = [];
|
|
2138
2234
|
ReflectUtils.defineMetadata(QUERY_ALL_METADATA_KEY, queries, constructor);
|
|
2139
2235
|
}
|
|
2140
|
-
queries.push({ selector, options, propertyKey
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2236
|
+
queries.push({ selector, options, propertyKey });
|
|
2237
|
+
Object.defineProperty(target, propertyKey, {
|
|
2238
|
+
get() {
|
|
2239
|
+
const hostSet = SwcUtils.getHostSet(this);
|
|
2240
|
+
if (selector === ":hosts")
|
|
2241
|
+
return hostSet.$hosts;
|
|
2242
|
+
if (selector === ":appHosts")
|
|
2243
|
+
return hostSet.$appHosts;
|
|
2244
|
+
const config = getElementConfig(this);
|
|
2245
|
+
const win = config?.window || window;
|
|
2246
|
+
const doc = win.document;
|
|
2247
|
+
if (selector === ":window")
|
|
2248
|
+
return [win];
|
|
2249
|
+
if (selector === ":document")
|
|
2250
|
+
return [doc];
|
|
2251
|
+
if (!selector || selector === ":host")
|
|
2252
|
+
return [this];
|
|
2253
|
+
const r = options.root || "auto";
|
|
2254
|
+
if (r === "shadow") {
|
|
2255
|
+
return this.shadowRoot ? this.shadowRoot.querySelectorAll(selector) : [];
|
|
2256
|
+
}
|
|
2257
|
+
if (r === "light") {
|
|
2258
|
+
return this.querySelectorAll(selector);
|
|
2259
|
+
}
|
|
2260
|
+
if (r === "all") {
|
|
2261
|
+
const sNodes = this.shadowRoot ? Array.from(this.shadowRoot.querySelectorAll(selector)) : [];
|
|
2262
|
+
const lNodes = Array.from(this.querySelectorAll(selector));
|
|
2263
|
+
return [...sNodes, ...lNodes];
|
|
2264
|
+
}
|
|
2265
|
+
const root = this.shadowRoot || this;
|
|
2266
|
+
return root.querySelectorAll(selector);
|
|
2267
|
+
},
|
|
2268
|
+
enumerable: true,
|
|
2269
|
+
configurable: true
|
|
2270
|
+
});
|
|
2173
2271
|
};
|
|
2174
2272
|
}
|
|
2175
2273
|
var getQueryAllMetadata = (target) => {
|
|
@@ -7794,7 +7892,7 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
7794
7892
|
const configStr = this.host.getAttribute("swc-get-application-config");
|
|
7795
7893
|
if (!configStr) return;
|
|
7796
7894
|
try {
|
|
7797
|
-
const userConfig =
|
|
7895
|
+
const userConfig = FunctionUtils.executeReturn({ script: configStr, context: this.host });
|
|
7798
7896
|
if (userConfig && userConfig.rootRouter) {
|
|
7799
7897
|
const _config = {
|
|
7800
7898
|
routeType: "element",
|
|
@@ -9658,6 +9756,732 @@ var dooboostoreSimpleWebComponent = (() => {
|
|
|
9658
9756
|
SwcAppBody = __decorate57([
|
|
9659
9757
|
elementDefine({ name: "swc-app-body", extends: "body" })
|
|
9660
9758
|
], SwcAppBody);
|
|
9759
|
+
|
|
9760
|
+
// src/elements/SwcSubTemplates.ts
|
|
9761
|
+
var __decorate58 = function(decorators, target, key, desc) {
|
|
9762
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
9763
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
9764
|
+
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;
|
|
9765
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
9766
|
+
};
|
|
9767
|
+
var SwcLoading = class SwcLoading2 extends HTMLTemplateElement {
|
|
9768
|
+
};
|
|
9769
|
+
SwcLoading = __decorate58([
|
|
9770
|
+
elementDefine({ name: "swc-loading", extends: "template" })
|
|
9771
|
+
], SwcLoading);
|
|
9772
|
+
var SwcError = class SwcError2 extends HTMLTemplateElement {
|
|
9773
|
+
};
|
|
9774
|
+
SwcError = __decorate58([
|
|
9775
|
+
elementDefine({ name: "swc-error", extends: "template" })
|
|
9776
|
+
], SwcError);
|
|
9777
|
+
var SwcSuccess = class SwcSuccess2 extends HTMLTemplateElement {
|
|
9778
|
+
};
|
|
9779
|
+
SwcSuccess = __decorate58([
|
|
9780
|
+
elementDefine({ name: "swc-success", extends: "template" })
|
|
9781
|
+
], SwcSuccess);
|
|
9782
|
+
var SwcWhen = class SwcWhen2 extends HTMLTemplateElement {
|
|
9783
|
+
};
|
|
9784
|
+
SwcWhen = __decorate58([
|
|
9785
|
+
elementDefine({ name: "swc-when", extends: "template" })
|
|
9786
|
+
], SwcWhen);
|
|
9787
|
+
var SwcOtherwise = class SwcOtherwise2 extends HTMLTemplateElement {
|
|
9788
|
+
};
|
|
9789
|
+
SwcOtherwise = __decorate58([
|
|
9790
|
+
elementDefine({ name: "swc-otherwise", extends: "template" })
|
|
9791
|
+
], SwcOtherwise);
|
|
9792
|
+
var SwcDefault = class SwcDefault2 extends HTMLTemplateElement {
|
|
9793
|
+
};
|
|
9794
|
+
SwcDefault = __decorate58([
|
|
9795
|
+
elementDefine({ name: "swc-default", extends: "template" })
|
|
9796
|
+
], SwcDefault);
|
|
9797
|
+
|
|
9798
|
+
// src/elements/SwcLoop.ts
|
|
9799
|
+
var __decorate59 = function(decorators, target, key, desc) {
|
|
9800
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
9801
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
9802
|
+
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;
|
|
9803
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
9804
|
+
};
|
|
9805
|
+
var __metadata = function(k, v) {
|
|
9806
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9807
|
+
};
|
|
9808
|
+
var SwcLoop = class SwcLoop2 extends HTMLTemplateElement {
|
|
9809
|
+
constructor() {
|
|
9810
|
+
super(...arguments);
|
|
9811
|
+
this._value = [];
|
|
9812
|
+
this._nodes = [];
|
|
9813
|
+
this._defaultNodes = [];
|
|
9814
|
+
}
|
|
9815
|
+
get value() {
|
|
9816
|
+
return this._value;
|
|
9817
|
+
}
|
|
9818
|
+
set value(nv) {
|
|
9819
|
+
this._value = Array.isArray(nv) ? [...nv] : [];
|
|
9820
|
+
this.render();
|
|
9821
|
+
}
|
|
9822
|
+
getNodes(index) {
|
|
9823
|
+
return this._nodes[index] || null;
|
|
9824
|
+
}
|
|
9825
|
+
_getTarget() {
|
|
9826
|
+
const script = this.getAttribute("on-get-portal");
|
|
9827
|
+
if (!script)
|
|
9828
|
+
return null;
|
|
9829
|
+
try {
|
|
9830
|
+
const res = FunctionUtils.executeReturn({
|
|
9831
|
+
script,
|
|
9832
|
+
context: this,
|
|
9833
|
+
args: SwcUtils.getHelperAndHostSet(window, this)
|
|
9834
|
+
});
|
|
9835
|
+
if (typeof res === "string")
|
|
9836
|
+
return document.querySelector(res);
|
|
9837
|
+
if (res instanceof Node)
|
|
9838
|
+
return res;
|
|
9839
|
+
} catch (e) {
|
|
9840
|
+
console.error("[SwcLoop] Portal target error:", e);
|
|
9841
|
+
}
|
|
9842
|
+
return null;
|
|
9843
|
+
}
|
|
9844
|
+
append(...items) {
|
|
9845
|
+
if (!items.length || !this.parentElement)
|
|
9846
|
+
return;
|
|
9847
|
+
if (this._defaultNodes.length > 0)
|
|
9848
|
+
this._cleanupDefault();
|
|
9849
|
+
const fragment = document.createDocumentFragment();
|
|
9850
|
+
const startIndex = this._value.length;
|
|
9851
|
+
items.forEach((item, i) => {
|
|
9852
|
+
const index = startIndex + i;
|
|
9853
|
+
const nodes = this._createItemNodes(item, index);
|
|
9854
|
+
if (nodes) {
|
|
9855
|
+
this._nodes.push(nodes);
|
|
9856
|
+
nodes.forEach((n) => fragment.appendChild(n));
|
|
9857
|
+
this._value.push(item);
|
|
9858
|
+
} else {
|
|
9859
|
+
this._nodes.push(null);
|
|
9860
|
+
this._value.push(null);
|
|
9861
|
+
}
|
|
9862
|
+
});
|
|
9863
|
+
const target = this._getTarget();
|
|
9864
|
+
if (target) {
|
|
9865
|
+
target.appendChild(fragment);
|
|
9866
|
+
} else {
|
|
9867
|
+
const lastValidIdx = this._nodes.length - items.length - 1;
|
|
9868
|
+
let refNode = this;
|
|
9869
|
+
for (let i = lastValidIdx; i >= 0; i--) {
|
|
9870
|
+
const group = this._nodes[i];
|
|
9871
|
+
if (group && group.length > 0) {
|
|
9872
|
+
refNode = group[group.length - 1];
|
|
9873
|
+
break;
|
|
9874
|
+
}
|
|
9875
|
+
}
|
|
9876
|
+
this.parentElement.insertBefore(fragment, refNode.nextSibling);
|
|
9877
|
+
}
|
|
9878
|
+
}
|
|
9879
|
+
remove(index) {
|
|
9880
|
+
const targetIdx = index !== void 0 ? index : this._nodes.length - 1;
|
|
9881
|
+
if (targetIdx < 0 || targetIdx >= this._nodes.length)
|
|
9882
|
+
return;
|
|
9883
|
+
const nodes = this._nodes[targetIdx];
|
|
9884
|
+
if (nodes) {
|
|
9885
|
+
nodes.forEach((n) => {
|
|
9886
|
+
if (n.parentElement)
|
|
9887
|
+
n.parentElement.removeChild(n);
|
|
9888
|
+
});
|
|
9889
|
+
this._nodes[targetIdx] = null;
|
|
9890
|
+
this._value[targetIdx] = null;
|
|
9891
|
+
}
|
|
9892
|
+
const activeRows = this._value.filter((v) => v !== null);
|
|
9893
|
+
if (activeRows.length === 0) {
|
|
9894
|
+
this.render();
|
|
9895
|
+
}
|
|
9896
|
+
}
|
|
9897
|
+
_createItemNodes(item, index) {
|
|
9898
|
+
const clone = this.content.cloneNode(true);
|
|
9899
|
+
Array.from(clone.querySelectorAll('template[is="swc-default"]')).forEach((t) => t.remove());
|
|
9900
|
+
const nodes = Array.from(clone.childNodes);
|
|
9901
|
+
const elements = nodes.filter((n) => n.nodeType === 1);
|
|
9902
|
+
const groupCtx = {
|
|
9903
|
+
$index: index,
|
|
9904
|
+
$item: item,
|
|
9905
|
+
$nodes: nodes,
|
|
9906
|
+
$elements: elements,
|
|
9907
|
+
$firstNode: nodes[0],
|
|
9908
|
+
$lastNode: nodes[nodes.length - 1],
|
|
9909
|
+
$firstElement: elements[0],
|
|
9910
|
+
$lastElement: elements[elements.length - 1],
|
|
9911
|
+
$isFirst: index === 0,
|
|
9912
|
+
$isLast: index === this._value.length - 1,
|
|
9913
|
+
$isEven: index % 2 === 0,
|
|
9914
|
+
$isOdd: index % 2 !== 0,
|
|
9915
|
+
$count: this._value.length
|
|
9916
|
+
};
|
|
9917
|
+
this._executeCallback("on-clone-nodes", groupCtx);
|
|
9918
|
+
nodes.forEach((node, nodeIndex) => {
|
|
9919
|
+
if (node instanceof HTMLElement)
|
|
9920
|
+
node.__swc_host = this;
|
|
9921
|
+
this._executeCallback("on-clone-node", { ...groupCtx, $node: node, $nodeIndex: nodeIndex, $isElement: node.nodeType === 1 });
|
|
9922
|
+
});
|
|
9923
|
+
return nodes;
|
|
9924
|
+
}
|
|
9925
|
+
_executeCallback(attrName, extraArgs) {
|
|
9926
|
+
const script = this.getAttribute(attrName);
|
|
9927
|
+
if (!script)
|
|
9928
|
+
return;
|
|
9929
|
+
const helperHostSet = SwcUtils.getHelperAndHostSet(window, this);
|
|
9930
|
+
try {
|
|
9931
|
+
FunctionUtils.execute({ script, context: this, args: { ...helperHostSet, ...extraArgs } });
|
|
9932
|
+
} catch (e) {
|
|
9933
|
+
console.error(`[SwcLoop] Error in ${attrName}:`, e);
|
|
9934
|
+
}
|
|
9935
|
+
}
|
|
9936
|
+
refreshValue(newValue) {
|
|
9937
|
+
const script = newValue !== void 0 ? newValue : this.getAttribute("on-get-value");
|
|
9938
|
+
if (!script) {
|
|
9939
|
+
this.value = [];
|
|
9940
|
+
return;
|
|
9941
|
+
}
|
|
9942
|
+
const helperHostSet = SwcUtils.getHelperAndHostSet(window, this);
|
|
9943
|
+
try {
|
|
9944
|
+
const res = FunctionUtils.executeReturn({ script, context: this, args: helperHostSet });
|
|
9945
|
+
if (Array.isArray(res)) {
|
|
9946
|
+
this.value = res;
|
|
9947
|
+
}
|
|
9948
|
+
} catch (e) {
|
|
9949
|
+
console.error("[SwcLoop] Failed to get value from on-get-value script:", e);
|
|
9950
|
+
this.value = [];
|
|
9951
|
+
}
|
|
9952
|
+
}
|
|
9953
|
+
render() {
|
|
9954
|
+
this._cleanup();
|
|
9955
|
+
if (!this.parentElement)
|
|
9956
|
+
return;
|
|
9957
|
+
const activeRows = this._value.filter((v) => v !== null);
|
|
9958
|
+
const target = this._getTarget();
|
|
9959
|
+
if (activeRows.length === 0) {
|
|
9960
|
+
const t = this.content.querySelector('template[is="swc-default"]');
|
|
9961
|
+
if (t) {
|
|
9962
|
+
const clone = t.content.cloneNode(true);
|
|
9963
|
+
this._defaultNodes = Array.from(clone.childNodes);
|
|
9964
|
+
this._defaultNodes.forEach((n) => {
|
|
9965
|
+
if (n instanceof HTMLElement)
|
|
9966
|
+
n.__swc_host = this;
|
|
9967
|
+
});
|
|
9968
|
+
if (target)
|
|
9969
|
+
target.appendChild(clone);
|
|
9970
|
+
else
|
|
9971
|
+
this.parentElement.insertBefore(clone, this.nextSibling);
|
|
9972
|
+
}
|
|
9973
|
+
return;
|
|
9974
|
+
}
|
|
9975
|
+
const fragment = document.createDocumentFragment();
|
|
9976
|
+
this._value.forEach((item, index) => {
|
|
9977
|
+
if (item === null) {
|
|
9978
|
+
this._nodes.push(null);
|
|
9979
|
+
return;
|
|
9980
|
+
}
|
|
9981
|
+
const nodes = this._createItemNodes(item, index);
|
|
9982
|
+
this._nodes.push(nodes);
|
|
9983
|
+
nodes.forEach((n) => fragment.appendChild(n));
|
|
9984
|
+
});
|
|
9985
|
+
if (target)
|
|
9986
|
+
target.appendChild(fragment);
|
|
9987
|
+
else
|
|
9988
|
+
this.parentElement.insertBefore(fragment, this.nextSibling);
|
|
9989
|
+
}
|
|
9990
|
+
_cleanup() {
|
|
9991
|
+
this._nodes.forEach((group) => {
|
|
9992
|
+
if (group)
|
|
9993
|
+
group.forEach((node) => node.parentElement?.removeChild(node));
|
|
9994
|
+
});
|
|
9995
|
+
this._nodes = [];
|
|
9996
|
+
this._cleanupDefault();
|
|
9997
|
+
}
|
|
9998
|
+
_cleanupDefault() {
|
|
9999
|
+
this._defaultNodes.forEach((n) => n.parentElement?.removeChild(n));
|
|
10000
|
+
this._defaultNodes = [];
|
|
10001
|
+
}
|
|
10002
|
+
connectedCallback() {
|
|
10003
|
+
this.refreshValue();
|
|
10004
|
+
}
|
|
10005
|
+
disconnectedCallback() {
|
|
10006
|
+
this._cleanup();
|
|
10007
|
+
}
|
|
10008
|
+
};
|
|
10009
|
+
__decorate59([
|
|
10010
|
+
changedAttribute("on-get-value"),
|
|
10011
|
+
__metadata("design:type", Function),
|
|
10012
|
+
__metadata("design:paramtypes", [String]),
|
|
10013
|
+
__metadata("design:returntype", void 0)
|
|
10014
|
+
], SwcLoop.prototype, "refreshValue", null);
|
|
10015
|
+
SwcLoop = __decorate59([
|
|
10016
|
+
elementDefine({ name: "swc-loop", extends: "template" })
|
|
10017
|
+
], SwcLoop);
|
|
10018
|
+
|
|
10019
|
+
// src/elements/SwcIf.ts
|
|
10020
|
+
var __decorate60 = function(decorators, target, key, desc) {
|
|
10021
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
10022
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
10023
|
+
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;
|
|
10024
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10025
|
+
};
|
|
10026
|
+
var __metadata2 = function(k, v) {
|
|
10027
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10028
|
+
};
|
|
10029
|
+
var SwcIf = class SwcIf2 extends HTMLTemplateElement {
|
|
10030
|
+
constructor() {
|
|
10031
|
+
super(...arguments);
|
|
10032
|
+
this._nodes = [];
|
|
10033
|
+
this._value = null;
|
|
10034
|
+
}
|
|
10035
|
+
get value() {
|
|
10036
|
+
return this._value;
|
|
10037
|
+
}
|
|
10038
|
+
set value(nv) {
|
|
10039
|
+
this._value = nv;
|
|
10040
|
+
this.render();
|
|
10041
|
+
}
|
|
10042
|
+
_getTarget() {
|
|
10043
|
+
const script = this.getAttribute("on-get-portal");
|
|
10044
|
+
if (!script)
|
|
10045
|
+
return null;
|
|
10046
|
+
try {
|
|
10047
|
+
const res = FunctionUtils.executeReturn({
|
|
10048
|
+
script,
|
|
10049
|
+
context: this,
|
|
10050
|
+
args: SwcUtils.getHelperAndHostSet(window, this)
|
|
10051
|
+
});
|
|
10052
|
+
if (typeof res === "string")
|
|
10053
|
+
return document.querySelector(res);
|
|
10054
|
+
if (res instanceof Node)
|
|
10055
|
+
return res;
|
|
10056
|
+
} catch (e) {
|
|
10057
|
+
console.error("[SwcIf] Portal target error:", e);
|
|
10058
|
+
}
|
|
10059
|
+
return null;
|
|
10060
|
+
}
|
|
10061
|
+
_executeCallback(attrName, extraArgs) {
|
|
10062
|
+
const script = this.getAttribute(attrName);
|
|
10063
|
+
if (!script)
|
|
10064
|
+
return;
|
|
10065
|
+
const helperHostSet = SwcUtils.getHelperAndHostSet(window, this);
|
|
10066
|
+
try {
|
|
10067
|
+
FunctionUtils.execute({ script, context: this, args: { ...helperHostSet, ...extraArgs } });
|
|
10068
|
+
} catch (e) {
|
|
10069
|
+
console.error(`[SwcIf] Error in ${attrName}:`, e);
|
|
10070
|
+
}
|
|
10071
|
+
}
|
|
10072
|
+
refresh(newValue) {
|
|
10073
|
+
const script = newValue !== void 0 ? newValue : this.getAttribute("on-get-value");
|
|
10074
|
+
if (!script) {
|
|
10075
|
+
this.value = null;
|
|
10076
|
+
return;
|
|
10077
|
+
}
|
|
10078
|
+
if (!this.parentElement)
|
|
10079
|
+
return;
|
|
10080
|
+
const helperHostSet = SwcUtils.getHelperAndHostSet(window, this);
|
|
10081
|
+
try {
|
|
10082
|
+
const result = FunctionUtils.executeReturn({
|
|
10083
|
+
script,
|
|
10084
|
+
context: this,
|
|
10085
|
+
args: helperHostSet
|
|
10086
|
+
});
|
|
10087
|
+
this.value = result;
|
|
10088
|
+
} catch (e) {
|
|
10089
|
+
console.error("[SwcIf] Error in on-get-value:", e);
|
|
10090
|
+
this.value = null;
|
|
10091
|
+
}
|
|
10092
|
+
}
|
|
10093
|
+
render() {
|
|
10094
|
+
this.cleanup();
|
|
10095
|
+
if (!this.parentElement)
|
|
10096
|
+
return;
|
|
10097
|
+
let fragment = null;
|
|
10098
|
+
const ctx = { $value: this._value, $nodes: [], $elements: [] };
|
|
10099
|
+
if (this._value) {
|
|
10100
|
+
const clone = this.content.cloneNode(true);
|
|
10101
|
+
Array.from(clone.querySelectorAll('template[is="swc-default"]')).forEach((t) => t.remove());
|
|
10102
|
+
fragment = clone;
|
|
10103
|
+
} else {
|
|
10104
|
+
const t = this.content.querySelector('template[is="swc-default"]');
|
|
10105
|
+
if (t)
|
|
10106
|
+
fragment = t.content.cloneNode(true);
|
|
10107
|
+
}
|
|
10108
|
+
if (fragment) {
|
|
10109
|
+
this.mount(fragment, ctx);
|
|
10110
|
+
}
|
|
10111
|
+
}
|
|
10112
|
+
mount(fragment, ctx) {
|
|
10113
|
+
const nodes = Array.from(fragment.childNodes);
|
|
10114
|
+
const elements = nodes.filter((n) => n.nodeType === 1);
|
|
10115
|
+
Object.assign(ctx, {
|
|
10116
|
+
$nodes: nodes,
|
|
10117
|
+
$elements: elements,
|
|
10118
|
+
$firstNode: nodes[0],
|
|
10119
|
+
$lastNode: nodes[nodes.length - 1],
|
|
10120
|
+
$firstElement: elements[0],
|
|
10121
|
+
$lastElement: elements[elements.length - 1]
|
|
10122
|
+
});
|
|
10123
|
+
this._executeCallback("on-clone-nodes", ctx);
|
|
10124
|
+
nodes.forEach((node, nodeIndex) => {
|
|
10125
|
+
if (node instanceof HTMLElement)
|
|
10126
|
+
node.__swc_host = this;
|
|
10127
|
+
this._executeCallback("on-clone-node", { ...ctx, $node: node, $nodeIndex: nodeIndex, $isElement: node.nodeType === 1 });
|
|
10128
|
+
});
|
|
10129
|
+
this._nodes = nodes;
|
|
10130
|
+
const target = this._getTarget();
|
|
10131
|
+
if (target) {
|
|
10132
|
+
target.appendChild(fragment);
|
|
10133
|
+
} else {
|
|
10134
|
+
this.parentElement?.insertBefore(fragment, this.nextSibling);
|
|
10135
|
+
}
|
|
10136
|
+
}
|
|
10137
|
+
cleanup() {
|
|
10138
|
+
this._nodes.forEach((n) => {
|
|
10139
|
+
if (n.parentElement)
|
|
10140
|
+
n.parentElement.removeChild(n);
|
|
10141
|
+
});
|
|
10142
|
+
this._nodes = [];
|
|
10143
|
+
}
|
|
10144
|
+
connectedCallback() {
|
|
10145
|
+
this.refresh();
|
|
10146
|
+
}
|
|
10147
|
+
disconnectedCallback() {
|
|
10148
|
+
this.cleanup();
|
|
10149
|
+
}
|
|
10150
|
+
};
|
|
10151
|
+
__decorate60([
|
|
10152
|
+
changedAttribute("on-get-value"),
|
|
10153
|
+
__metadata2("design:type", Function),
|
|
10154
|
+
__metadata2("design:paramtypes", [String]),
|
|
10155
|
+
__metadata2("design:returntype", void 0)
|
|
10156
|
+
], SwcIf.prototype, "refresh", null);
|
|
10157
|
+
SwcIf = __decorate60([
|
|
10158
|
+
elementDefine({ name: "swc-if", extends: "template" })
|
|
10159
|
+
], SwcIf);
|
|
10160
|
+
|
|
10161
|
+
// src/elements/SwcChoose.ts
|
|
10162
|
+
var __decorate61 = function(decorators, target, key, desc) {
|
|
10163
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
10164
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
10165
|
+
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;
|
|
10166
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10167
|
+
};
|
|
10168
|
+
var __metadata3 = function(k, v) {
|
|
10169
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10170
|
+
};
|
|
10171
|
+
var SwcChoose = class SwcChoose2 extends HTMLTemplateElement {
|
|
10172
|
+
constructor() {
|
|
10173
|
+
super(...arguments);
|
|
10174
|
+
this._nodes = [];
|
|
10175
|
+
this._value = null;
|
|
10176
|
+
}
|
|
10177
|
+
get value() {
|
|
10178
|
+
return this._value;
|
|
10179
|
+
}
|
|
10180
|
+
set value(nv) {
|
|
10181
|
+
this._value = nv;
|
|
10182
|
+
this.render();
|
|
10183
|
+
}
|
|
10184
|
+
_executeCallback(attrName, extraArgs) {
|
|
10185
|
+
const script = this.getAttribute(attrName);
|
|
10186
|
+
if (!script)
|
|
10187
|
+
return;
|
|
10188
|
+
const helperHostSet = SwcUtils.getHelperAndHostSet(window, this);
|
|
10189
|
+
try {
|
|
10190
|
+
FunctionUtils.execute({ script, context: this, args: { ...helperHostSet, ...extraArgs } });
|
|
10191
|
+
} catch (e) {
|
|
10192
|
+
console.error(`[SwcChoose] Error in ${attrName}:`, e);
|
|
10193
|
+
}
|
|
10194
|
+
}
|
|
10195
|
+
refresh(newValue) {
|
|
10196
|
+
const script = newValue !== void 0 ? newValue : this.getAttribute("on-get-value");
|
|
10197
|
+
if (!script) {
|
|
10198
|
+
this.value = null;
|
|
10199
|
+
return;
|
|
10200
|
+
}
|
|
10201
|
+
if (!this.parentElement)
|
|
10202
|
+
return;
|
|
10203
|
+
const helperHostSet = SwcUtils.getHelperAndHostSet(window, this);
|
|
10204
|
+
try {
|
|
10205
|
+
const result = FunctionUtils.executeReturn({
|
|
10206
|
+
script,
|
|
10207
|
+
context: this,
|
|
10208
|
+
args: helperHostSet
|
|
10209
|
+
});
|
|
10210
|
+
this.value = result;
|
|
10211
|
+
} catch (e) {
|
|
10212
|
+
console.error("[SwcChoose] Error in on-get-value:", e);
|
|
10213
|
+
}
|
|
10214
|
+
}
|
|
10215
|
+
render() {
|
|
10216
|
+
this.cleanup();
|
|
10217
|
+
if (!this.parentElement)
|
|
10218
|
+
return;
|
|
10219
|
+
const templates = Array.from(this.content.querySelectorAll("template"));
|
|
10220
|
+
let selected = null;
|
|
10221
|
+
let otherwise = null;
|
|
10222
|
+
let defaultTmp = null;
|
|
10223
|
+
for (const t of templates) {
|
|
10224
|
+
const is = t.getAttribute("is");
|
|
10225
|
+
if (is === "swc-when") {
|
|
10226
|
+
const whenVal = t.getAttribute("value");
|
|
10227
|
+
if (String(whenVal) === String(this._value)) {
|
|
10228
|
+
selected = t;
|
|
10229
|
+
break;
|
|
10230
|
+
}
|
|
10231
|
+
} else if (is === "swc-otherwise") {
|
|
10232
|
+
otherwise = t;
|
|
10233
|
+
} else if (is === "swc-default") {
|
|
10234
|
+
defaultTmp = t;
|
|
10235
|
+
}
|
|
10236
|
+
}
|
|
10237
|
+
const targetTemplate = (this._value == null ? defaultTmp : selected) || otherwise || defaultTmp;
|
|
10238
|
+
if (targetTemplate) {
|
|
10239
|
+
const clone = targetTemplate.content.cloneNode(true);
|
|
10240
|
+
const nodes = Array.from(clone.childNodes);
|
|
10241
|
+
const elements = nodes.filter((n) => n.nodeType === 1);
|
|
10242
|
+
const ctx = {
|
|
10243
|
+
$value: this._value,
|
|
10244
|
+
$nodes: nodes,
|
|
10245
|
+
$elements: elements,
|
|
10246
|
+
$firstNode: nodes[0],
|
|
10247
|
+
$lastNode: nodes[nodes.length - 1],
|
|
10248
|
+
$firstElement: elements[0],
|
|
10249
|
+
$lastElement: elements[elements.length - 1]
|
|
10250
|
+
};
|
|
10251
|
+
this._executeCallback("on-clone-nodes", ctx);
|
|
10252
|
+
nodes.forEach((node, nodeIndex) => {
|
|
10253
|
+
if (node instanceof HTMLElement) {
|
|
10254
|
+
node.__swc_host = this;
|
|
10255
|
+
}
|
|
10256
|
+
this._executeCallback("on-clone-node", {
|
|
10257
|
+
...ctx,
|
|
10258
|
+
$node: node,
|
|
10259
|
+
$nodeIndex: nodeIndex,
|
|
10260
|
+
$isElement: node.nodeType === 1
|
|
10261
|
+
});
|
|
10262
|
+
});
|
|
10263
|
+
this._nodes = nodes;
|
|
10264
|
+
this.parentElement.insertBefore(clone, this.nextSibling);
|
|
10265
|
+
}
|
|
10266
|
+
}
|
|
10267
|
+
cleanup() {
|
|
10268
|
+
this._nodes.forEach((n) => {
|
|
10269
|
+
if (n.parentElement)
|
|
10270
|
+
n.parentElement.removeChild(n);
|
|
10271
|
+
});
|
|
10272
|
+
this._nodes = [];
|
|
10273
|
+
}
|
|
10274
|
+
connectedCallback() {
|
|
10275
|
+
this.refresh();
|
|
10276
|
+
}
|
|
10277
|
+
disconnectedCallback() {
|
|
10278
|
+
this.cleanup();
|
|
10279
|
+
}
|
|
10280
|
+
};
|
|
10281
|
+
__decorate61([
|
|
10282
|
+
changedAttribute("on-get-value"),
|
|
10283
|
+
__metadata3("design:type", Function),
|
|
10284
|
+
__metadata3("design:paramtypes", [String]),
|
|
10285
|
+
__metadata3("design:returntype", void 0)
|
|
10286
|
+
], SwcChoose.prototype, "refresh", null);
|
|
10287
|
+
SwcChoose = __decorate61([
|
|
10288
|
+
elementDefine({ name: "swc-choose", extends: "template" })
|
|
10289
|
+
], SwcChoose);
|
|
10290
|
+
|
|
10291
|
+
// src/elements/SwcAsync.ts
|
|
10292
|
+
var __decorate62 = function(decorators, target, key, desc) {
|
|
10293
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
10294
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
10295
|
+
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;
|
|
10296
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10297
|
+
};
|
|
10298
|
+
var __metadata4 = function(k, v) {
|
|
10299
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10300
|
+
};
|
|
10301
|
+
var SwcAsync = class SwcAsync2 extends HTMLTemplateElement {
|
|
10302
|
+
constructor() {
|
|
10303
|
+
super(...arguments);
|
|
10304
|
+
this._nodes = [];
|
|
10305
|
+
this._currentPromise = null;
|
|
10306
|
+
this._value = null;
|
|
10307
|
+
}
|
|
10308
|
+
get value() {
|
|
10309
|
+
return this._value;
|
|
10310
|
+
}
|
|
10311
|
+
set value(nv) {
|
|
10312
|
+
if (nv instanceof Promise) {
|
|
10313
|
+
this.handlePromise(nv);
|
|
10314
|
+
} else {
|
|
10315
|
+
this._value = nv;
|
|
10316
|
+
this.render(nv === null ? "default" : "success", nv);
|
|
10317
|
+
}
|
|
10318
|
+
}
|
|
10319
|
+
refresh(newValue) {
|
|
10320
|
+
const script = newValue !== void 0 ? newValue : this.getAttribute("on-get-value");
|
|
10321
|
+
if (!script) {
|
|
10322
|
+
this.value = null;
|
|
10323
|
+
return;
|
|
10324
|
+
}
|
|
10325
|
+
if (!this.parentElement)
|
|
10326
|
+
return;
|
|
10327
|
+
const helperHostSet = SwcUtils.getHelperAndHostSet(window, this);
|
|
10328
|
+
try {
|
|
10329
|
+
const result = FunctionUtils.executeReturn({
|
|
10330
|
+
script,
|
|
10331
|
+
context: this,
|
|
10332
|
+
args: helperHostSet
|
|
10333
|
+
});
|
|
10334
|
+
if (result instanceof Promise) {
|
|
10335
|
+
this.handlePromise(result);
|
|
10336
|
+
} else {
|
|
10337
|
+
this.value = result;
|
|
10338
|
+
}
|
|
10339
|
+
} catch (e) {
|
|
10340
|
+
this.render("error", e);
|
|
10341
|
+
}
|
|
10342
|
+
}
|
|
10343
|
+
async handlePromise(promise) {
|
|
10344
|
+
this._currentPromise = promise;
|
|
10345
|
+
this.render("loading");
|
|
10346
|
+
try {
|
|
10347
|
+
const result = await promise;
|
|
10348
|
+
if (this._currentPromise !== promise)
|
|
10349
|
+
return;
|
|
10350
|
+
this._value = result;
|
|
10351
|
+
this.render("success", result);
|
|
10352
|
+
} catch (e) {
|
|
10353
|
+
if (this._currentPromise !== promise)
|
|
10354
|
+
return;
|
|
10355
|
+
this.render("error", e);
|
|
10356
|
+
}
|
|
10357
|
+
}
|
|
10358
|
+
render(state, data) {
|
|
10359
|
+
this.cleanup();
|
|
10360
|
+
if (!this.parentElement)
|
|
10361
|
+
return;
|
|
10362
|
+
let fragment;
|
|
10363
|
+
const ctx = {
|
|
10364
|
+
$nodes: [],
|
|
10365
|
+
$elements: [],
|
|
10366
|
+
$state: state,
|
|
10367
|
+
$value: null,
|
|
10368
|
+
$error: null
|
|
10369
|
+
};
|
|
10370
|
+
if (state === "default") {
|
|
10371
|
+
const t = this.content.querySelector('template[is="swc-default"]');
|
|
10372
|
+
fragment = t ? t.content.cloneNode(true) : document.createDocumentFragment();
|
|
10373
|
+
} else if (state === "loading") {
|
|
10374
|
+
const t = this.content.querySelector('template[is="swc-loading"]');
|
|
10375
|
+
fragment = t ? t.content.cloneNode(true) : document.createDocumentFragment();
|
|
10376
|
+
} else if (state === "error") {
|
|
10377
|
+
const t = this.content.querySelector('template[is="swc-error"]');
|
|
10378
|
+
ctx.$error = data;
|
|
10379
|
+
fragment = t ? t.content.cloneNode(true) : document.createDocumentFragment();
|
|
10380
|
+
} else {
|
|
10381
|
+
const t = this.content.querySelector('template[is="swc-success"]');
|
|
10382
|
+
ctx.$value = data;
|
|
10383
|
+
if (t) {
|
|
10384
|
+
fragment = t.content.cloneNode(true);
|
|
10385
|
+
} else {
|
|
10386
|
+
const clone = this.content.cloneNode(true);
|
|
10387
|
+
Array.from(clone.querySelectorAll('template[is="swc-loading"], template[is="swc-error"], template[is="swc-success"], template[is="swc-default"]')).forEach((tmp) => tmp.remove());
|
|
10388
|
+
fragment = clone;
|
|
10389
|
+
}
|
|
10390
|
+
}
|
|
10391
|
+
this.mount(fragment, ctx);
|
|
10392
|
+
}
|
|
10393
|
+
mount(fragment, ctx) {
|
|
10394
|
+
const nodes = Array.from(fragment.childNodes);
|
|
10395
|
+
const elements = nodes.filter((n) => n.nodeType === 1);
|
|
10396
|
+
Object.assign(ctx, {
|
|
10397
|
+
$nodes: nodes,
|
|
10398
|
+
$elements: elements,
|
|
10399
|
+
$firstNode: nodes[0],
|
|
10400
|
+
$lastNode: nodes[nodes.length - 1],
|
|
10401
|
+
$firstElement: elements[0],
|
|
10402
|
+
$lastElement: elements[elements.length - 1]
|
|
10403
|
+
});
|
|
10404
|
+
this._executeCallback("on-clone-nodes", ctx);
|
|
10405
|
+
nodes.forEach((node, nodeIndex) => {
|
|
10406
|
+
if (node instanceof HTMLElement) {
|
|
10407
|
+
node.__swc_host = this;
|
|
10408
|
+
}
|
|
10409
|
+
this._executeCallback("on-clone-node", {
|
|
10410
|
+
...ctx,
|
|
10411
|
+
$node: node,
|
|
10412
|
+
$nodeIndex: nodeIndex,
|
|
10413
|
+
$isElement: node.nodeType === 1
|
|
10414
|
+
});
|
|
10415
|
+
});
|
|
10416
|
+
this._nodes = nodes;
|
|
10417
|
+
this.parentElement?.insertBefore(fragment, this.nextSibling);
|
|
10418
|
+
}
|
|
10419
|
+
_executeCallback(attrName, extraArgs) {
|
|
10420
|
+
const script = this.getAttribute(attrName);
|
|
10421
|
+
if (!script)
|
|
10422
|
+
return;
|
|
10423
|
+
const helperHostSet = SwcUtils.getHelperAndHostSet(window, this);
|
|
10424
|
+
try {
|
|
10425
|
+
FunctionUtils.execute({ script, context: this, args: { ...helperHostSet, ...extraArgs } });
|
|
10426
|
+
} catch (e) {
|
|
10427
|
+
console.error(`[SwcAsync] Error in ${attrName}:`, e);
|
|
10428
|
+
}
|
|
10429
|
+
}
|
|
10430
|
+
cleanup() {
|
|
10431
|
+
this._nodes.forEach((n) => {
|
|
10432
|
+
if (n.parentElement)
|
|
10433
|
+
n.parentElement.removeChild(n);
|
|
10434
|
+
});
|
|
10435
|
+
this._nodes = [];
|
|
10436
|
+
}
|
|
10437
|
+
connectedCallback() {
|
|
10438
|
+
this.refresh();
|
|
10439
|
+
}
|
|
10440
|
+
disconnectedCallback() {
|
|
10441
|
+
this.cleanup();
|
|
10442
|
+
}
|
|
10443
|
+
};
|
|
10444
|
+
__decorate62([
|
|
10445
|
+
changedAttribute("on-get-value"),
|
|
10446
|
+
__metadata4("design:type", Function),
|
|
10447
|
+
__metadata4("design:paramtypes", [String]),
|
|
10448
|
+
__metadata4("design:returntype", void 0)
|
|
10449
|
+
], SwcAsync.prototype, "refresh", null);
|
|
10450
|
+
SwcAsync = __decorate62([
|
|
10451
|
+
elementDefine({ name: "swc-async", extends: "template" })
|
|
10452
|
+
], SwcAsync);
|
|
10453
|
+
|
|
10454
|
+
// src/elements/SwcApp.ts
|
|
10455
|
+
var __decorate63 = function(decorators, target, key, desc) {
|
|
10456
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
10457
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
10458
|
+
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;
|
|
10459
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10460
|
+
};
|
|
10461
|
+
var SwcApp = class SwcApp2 extends HTMLElement {
|
|
10462
|
+
constructor() {
|
|
10463
|
+
super(...arguments);
|
|
10464
|
+
this._engine = new SwcAppEngine(this);
|
|
10465
|
+
}
|
|
10466
|
+
get simpleApplication() {
|
|
10467
|
+
return this._engine.simpleApplication;
|
|
10468
|
+
}
|
|
10469
|
+
get router() {
|
|
10470
|
+
return this._engine.router;
|
|
10471
|
+
}
|
|
10472
|
+
connectedCallback() {
|
|
10473
|
+
this._engine.connect();
|
|
10474
|
+
}
|
|
10475
|
+
disconnectedCallback() {
|
|
10476
|
+
this._engine.disconnect();
|
|
10477
|
+
}
|
|
10478
|
+
async routing(path) {
|
|
10479
|
+
await this._engine.router?.go(path);
|
|
10480
|
+
}
|
|
10481
|
+
};
|
|
10482
|
+
SwcApp = __decorate63([
|
|
10483
|
+
elementDefine({ name: "swc-app", extends: void 0 })
|
|
10484
|
+
], SwcApp);
|
|
9661
10485
|
return __toCommonJS(bundle_entry_exports);
|
|
9662
10486
|
})();
|
|
9663
10487
|
/*! Bundled license information:
|