@whitesev/pops 3.3.2 → 3.3.4

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.
@@ -296,6 +296,13 @@ System.register('pops', [], (function (exports) {
296
296
  isDOM(target) {
297
297
  return target instanceof Node;
298
298
  }
299
+ /**
300
+ * 判断是否是元素列表
301
+ * @param $ele
302
+ */
303
+ isNodeList($ele) {
304
+ return Array.isArray($ele) || $ele instanceof NodeList;
305
+ }
299
306
  /**
300
307
  * 删除对象上的属性
301
308
  * @param target
@@ -1028,7 +1035,7 @@ System.register('pops', [], (function (exports) {
1028
1035
  */
1029
1036
  emit(element, eventType, details, useDispatchToEmitEvent = true) {
1030
1037
  if (typeof element === "string") {
1031
- element = PopsCore.document.querySelector(element);
1038
+ element = this.selector(element);
1032
1039
  }
1033
1040
  if (element == null) {
1034
1041
  return;
@@ -1090,18 +1097,18 @@ System.register('pops', [], (function (exports) {
1090
1097
  * })
1091
1098
  * */
1092
1099
  click(element, handler, details, useDispatchToEmitEvent) {
1093
- const DOMUtilsContext = this;
1094
1100
  if (typeof element === "string") {
1095
- element = PopsCore.document.querySelector(element);
1101
+ element = this.selector(element);
1096
1102
  }
1097
1103
  if (element == null) {
1098
1104
  return;
1099
1105
  }
1100
1106
  if (handler == null) {
1101
- DOMUtilsContext.emit(element, "click", details, useDispatchToEmitEvent);
1107
+ this.emit(element, "click", details, useDispatchToEmitEvent);
1102
1108
  }
1103
1109
  else {
1104
- DOMUtilsContext.on(element, "click", null, handler);
1110
+ const listener = this.on(element, "click", handler);
1111
+ return listener;
1105
1112
  }
1106
1113
  }
1107
1114
  /**
@@ -1119,18 +1126,18 @@ System.register('pops', [], (function (exports) {
1119
1126
  * })
1120
1127
  * */
1121
1128
  blur(element, handler, details, useDispatchToEmitEvent) {
1122
- const DOMUtilsContext = this;
1123
1129
  if (typeof element === "string") {
1124
- element = PopsCore.document.querySelector(element);
1130
+ element = this.selector(element);
1125
1131
  }
1126
1132
  if (element == null) {
1127
1133
  return;
1128
1134
  }
1129
1135
  if (handler === null) {
1130
- DOMUtilsContext.emit(element, "blur", details, useDispatchToEmitEvent);
1136
+ this.emit(element, "blur", details, useDispatchToEmitEvent);
1131
1137
  }
1132
1138
  else {
1133
- DOMUtilsContext.on(element, "blur", null, handler);
1139
+ const listener = this.on(element, "blur", handler);
1140
+ return listener;
1134
1141
  }
1135
1142
  }
1136
1143
  /**
@@ -1148,18 +1155,18 @@ System.register('pops', [], (function (exports) {
1148
1155
  * })
1149
1156
  * */
1150
1157
  focus(element, handler, details, useDispatchToEmitEvent) {
1151
- const DOMUtilsContext = this;
1152
1158
  if (typeof element === "string") {
1153
- element = PopsCore.document.querySelector(element);
1159
+ element = this.selector(element);
1154
1160
  }
1155
1161
  if (element == null) {
1156
1162
  return;
1157
1163
  }
1158
1164
  if (handler == null) {
1159
- DOMUtilsContext.emit(element, "focus", details, useDispatchToEmitEvent);
1165
+ this.emit(element, "focus", details, useDispatchToEmitEvent);
1160
1166
  }
1161
1167
  else {
1162
- DOMUtilsContext.on(element, "focus", null, handler);
1168
+ const listener = this.on(element, "focus", handler);
1169
+ return listener;
1163
1170
  }
1164
1171
  }
1165
1172
  /**
@@ -1177,15 +1184,39 @@ System.register('pops', [], (function (exports) {
1177
1184
  * })
1178
1185
  */
1179
1186
  onHover(element, handler, option) {
1180
- const DOMUtilsContext = this;
1187
+ const that = this;
1181
1188
  if (typeof element === "string") {
1182
- element = PopsCore.document.querySelector(element);
1189
+ element = that.selectorAll(element);
1183
1190
  }
1184
1191
  if (element == null) {
1185
1192
  return;
1186
1193
  }
1187
- DOMUtilsContext.on(element, "mouseenter", null, handler, option);
1188
- DOMUtilsContext.on(element, "mouseleave", null, handler, option);
1194
+ if (popsUtils.isNodeList(element)) {
1195
+ // 设置
1196
+ const listenerList = [];
1197
+ element.forEach(($ele) => {
1198
+ const listener = that.onHover($ele, handler, option);
1199
+ listenerList.push(listener);
1200
+ });
1201
+ return {
1202
+ off() {
1203
+ listenerList.forEach((listener) => {
1204
+ if (!listener) {
1205
+ return;
1206
+ }
1207
+ listener.off();
1208
+ });
1209
+ },
1210
+ };
1211
+ }
1212
+ const mouseenter_listener = that.on(element, "mouseenter", null, handler, option);
1213
+ const mouseleave_listener = that.on(element, "mouseleave", null, handler, option);
1214
+ return {
1215
+ off() {
1216
+ mouseenter_listener.off();
1217
+ mouseleave_listener.off();
1218
+ },
1219
+ };
1189
1220
  }
1190
1221
  /**
1191
1222
  * 当按键松开时触发事件
@@ -1203,14 +1234,14 @@ System.register('pops', [], (function (exports) {
1203
1234
  * })
1204
1235
  */
1205
1236
  onKeyup(target, handler, option) {
1206
- const DOMUtilsContext = this;
1207
1237
  if (target == null) {
1208
1238
  return;
1209
1239
  }
1210
1240
  if (typeof target === "string") {
1211
- target = PopsCore.document.querySelector(target);
1241
+ target = this.selector(target);
1212
1242
  }
1213
- DOMUtilsContext.on(target, "keyup", null, handler, option);
1243
+ const listener = this.on(target, "keyup", handler, option);
1244
+ return listener;
1214
1245
  }
1215
1246
  /**
1216
1247
  * 当按键按下时触发事件
@@ -1228,14 +1259,14 @@ System.register('pops', [], (function (exports) {
1228
1259
  * })
1229
1260
  */
1230
1261
  onKeydown(target, handler, option) {
1231
- const DOMUtilsContext = this;
1232
1262
  if (target == null) {
1233
1263
  return;
1234
1264
  }
1235
1265
  if (typeof target === "string") {
1236
- target = PopsCore.document.querySelector(target);
1266
+ target = this.selector(target);
1237
1267
  }
1238
- DOMUtilsContext.on(target, "keydown", null, handler, option);
1268
+ const listener = this.on(target, "keydown", handler, option);
1269
+ return listener;
1239
1270
  }
1240
1271
  /**
1241
1272
  * 当按键按下时触发事件
@@ -1253,38 +1284,69 @@ System.register('pops', [], (function (exports) {
1253
1284
  * })
1254
1285
  */
1255
1286
  onKeypress(target, handler, option) {
1256
- const DOMUtilsContext = this;
1257
1287
  if (target == null) {
1258
1288
  return;
1259
1289
  }
1260
1290
  if (typeof target === "string") {
1261
- target = PopsCore.document.querySelector(target);
1291
+ target = this.selector(target);
1262
1292
  }
1263
- DOMUtilsContext.on(target, "keypress", null, handler, option);
1293
+ const listener = this.on(target, "keypress", handler, option);
1294
+ return listener;
1264
1295
  }
1265
- preventEvent(element, eventNameList = [], capture) {
1266
- function stopEvent(event) {
1267
- // 阻止事件的默认行为发生。例如,当点击一个链接时,浏览器会默认打开链接的URL
1296
+ preventEvent(...args) {
1297
+ /**
1298
+ * 阻止事件的默认行为发生,并阻止事件传播
1299
+ */
1300
+ const stopEvent = (event, onlyStopPropagation) => {
1301
+ if (typeof onlyStopPropagation === "boolean" && onlyStopPropagation) {
1302
+ // 停止事件的传播,阻止它继续向更上层的元素冒泡,事件将不会再传播给其他的元素
1303
+ event?.stopPropagation();
1304
+ // 阻止事件传播,并且还能阻止元素上的其他事件处理程序被触发
1305
+ event?.stopImmediatePropagation();
1306
+ return;
1307
+ }
1308
+ // 阻止事件的默认行为发生。例如,当点击一个链接时,浏览器会默认打开链接的URL,或者在输入框内输入文字
1268
1309
  event?.preventDefault();
1269
- // 停止事件的传播,阻止它继续向更上层的元素冒泡,事件将不会再传播给其他的元素
1270
- event?.stopPropagation();
1271
- // 阻止事件传播,并且还能阻止元素上的其他事件处理程序被触发
1272
- event?.stopImmediatePropagation();
1273
1310
  return false;
1274
- }
1275
- if (arguments.length === 1) {
1311
+ };
1312
+ if (args[0] instanceof Event) {
1276
1313
  // 直接阻止事件
1277
- // eslint-disable-next-line prefer-rest-params
1278
- return stopEvent(arguments[0]);
1314
+ const onlyStopPropagation = args[1];
1315
+ return stopEvent(args[0], onlyStopPropagation);
1279
1316
  }
1280
1317
  else {
1318
+ const $el = args[0];
1319
+ let eventNameList = args[1];
1320
+ let selector = void 0;
1321
+ let capture = false;
1322
+ let onlyStopPropagation = false;
1281
1323
  // 添加对应的事件来阻止触发
1282
1324
  if (typeof eventNameList === "string") {
1283
1325
  eventNameList = [eventNameList];
1284
1326
  }
1285
- eventNameList.forEach((eventName) => {
1286
- this.on(element, eventName, stopEvent, { capture: Boolean(capture) });
1287
- });
1327
+ let option = void 0;
1328
+ if (typeof args[2] === "string" || Array.isArray(args[2])) {
1329
+ // selector
1330
+ selector = args[2];
1331
+ if (typeof args[3] === "object" && args[3] != null) {
1332
+ option = args[3];
1333
+ }
1334
+ }
1335
+ else if (typeof args[2] === "object" && args[2] != null && !Array.isArray(args[2])) {
1336
+ // option
1337
+ option = args[2];
1338
+ }
1339
+ else {
1340
+ throw new TypeError("Invalid argument");
1341
+ }
1342
+ if (option) {
1343
+ capture = Boolean(option.capture);
1344
+ onlyStopPropagation = Boolean(option.onlyStopPropagation);
1345
+ }
1346
+ const listener = this.on($el, eventNameList, selector, (evt) => {
1347
+ return stopEvent(evt, onlyStopPropagation);
1348
+ }, { capture: capture });
1349
+ return listener;
1288
1350
  }
1289
1351
  }
1290
1352
  selector(selector) {
@@ -1470,7 +1532,7 @@ System.register('pops', [], (function (exports) {
1470
1532
  width(element, isShow = false, parent) {
1471
1533
  const DOMUtilsContext = this;
1472
1534
  if (typeof element === "string") {
1473
- element = PopsCore.document.querySelector(element);
1535
+ element = this.selector(element);
1474
1536
  }
1475
1537
  if (element == null) {
1476
1538
  return;
@@ -1521,7 +1583,7 @@ System.register('pops', [], (function (exports) {
1521
1583
  return PopsCore.window.document.documentElement.clientHeight;
1522
1584
  }
1523
1585
  if (typeof element === "string") {
1524
- element = PopsCore.document.querySelector(element);
1586
+ element = this.selector(element);
1525
1587
  }
1526
1588
  if (element == null) {
1527
1589
  return;
@@ -1569,7 +1631,7 @@ System.register('pops', [], (function (exports) {
1569
1631
  return PopsCore.window.innerWidth;
1570
1632
  }
1571
1633
  if (typeof element === "string") {
1572
- element = PopsCore.document.querySelector(element);
1634
+ element = this.selector(element);
1573
1635
  }
1574
1636
  if (element == null) {
1575
1637
  return;
@@ -1594,7 +1656,7 @@ System.register('pops', [], (function (exports) {
1594
1656
  return PopsCore.window.innerHeight;
1595
1657
  }
1596
1658
  if (typeof element === "string") {
1597
- element = PopsCore.document.querySelector(element);
1659
+ element = this.selector(element);
1598
1660
  }
1599
1661
  element = element;
1600
1662
  if (isShow || (!isShow && popsDOMUtils.isShow(element))) {
@@ -2016,12 +2078,12 @@ System.register('pops', [], (function (exports) {
2016
2078
  * @param content 子元素或HTML字符串
2017
2079
  * @example
2018
2080
  * // 元素a.xx的内部末尾添加一个元素
2019
- * DOMUtils.append(document.querySelector("a.xx"),document.querySelector("b.xx"))
2081
+ * DOMUtils.append(document.querySelector("a.xx"), document.querySelector("b.xx"))
2020
2082
  * DOMUtils.append("a.xx","'<b class="xx"></b>")
2021
2083
  * */
2022
2084
  append(element, content) {
2023
2085
  if (typeof element === "string") {
2024
- element = PopsCore.document.querySelector(element);
2086
+ element = this.selector(element);
2025
2087
  }
2026
2088
  if (element == null) {
2027
2089
  return;
@@ -2157,7 +2219,7 @@ System.register('pops', [], (function (exports) {
2157
2219
  * */
2158
2220
  before(element, content) {
2159
2221
  if (typeof element === "string") {
2160
- element = PopsCore.document.querySelector(element);
2222
+ element = this.selector(element);
2161
2223
  }
2162
2224
  if (element == null) {
2163
2225
  return;
@@ -2180,7 +2242,7 @@ System.register('pops', [], (function (exports) {
2180
2242
  * */
2181
2243
  after(element, content) {
2182
2244
  if (typeof element === "string") {
2183
- element = PopsCore.document.querySelector(element);
2245
+ element = this.selector(element);
2184
2246
  }
2185
2247
  if (element == null) {
2186
2248
  return;
@@ -5291,10 +5353,13 @@ System.register('pops', [], (function (exports) {
5291
5353
  </div>`);
5292
5354
  // 存储原来的值
5293
5355
  Reflect.set($fileName, "__value__", folderData);
5294
- Reflect.set($folder, "folderData", folderData);
5356
+ Reflect.set($folder, "__value__", folderData);
5295
5357
  $folder.appendChild($fileName);
5296
5358
  return {
5297
5359
  folderElement: $folder,
5360
+ /**
5361
+ * 超链接标签的容器
5362
+ */
5298
5363
  fileNameElement: $fileName,
5299
5364
  };
5300
5365
  }
@@ -5383,8 +5448,17 @@ System.register('pops', [], (function (exports) {
5383
5448
  },
5384
5449
  addIndexCSS: false,
5385
5450
  });
5451
+ let childConfig;
5386
5452
  if (typeof dataConfig.clickEvent === "function") {
5387
- const childConfig = await dataConfig.clickEvent(clickEvent, dataConfig);
5453
+ const result = await dataConfig.clickEvent(clickEvent, dataConfig);
5454
+ if (Array.isArray(result)) {
5455
+ childConfig = result;
5456
+ }
5457
+ }
5458
+ else if (Array.isArray(dataConfig.clickEvent)) {
5459
+ childConfig = dataConfig.clickEvent;
5460
+ }
5461
+ if (childConfig) {
5388
5462
  // 添加顶部导航的箭头
5389
5463
  folderFileListBreadcrumbPrimaryElement.appendChild(this.createHeaderArrowIcon());
5390
5464
  // 添加顶部导航的链接文字
@@ -5398,50 +5472,65 @@ System.register('pops', [], (function (exports) {
5398
5472
  }
5399
5473
  loadingMask.close();
5400
5474
  }
5475
+ /**
5476
+ * 更新文件的显示的链接信息
5477
+ *
5478
+ * 这里主要用于鼠标中键或者右键触发,左键触发方式会根据mode进行处理
5479
+ * @returns 更新的文件的下载链接
5480
+ */
5481
+ updateFileLink($row, downloadInfo) {
5482
+ const downloadUrl = typeof downloadInfo?.url === "string" ? downloadInfo.url.trim() : "";
5483
+ if (downloadUrl !== "" && downloadUrl !== "null" && downloadUrl !== "undefined") {
5484
+ const $link = $row.querySelector("a");
5485
+ $link.setAttribute("href", downloadUrl);
5486
+ return downloadUrl;
5487
+ }
5488
+ }
5401
5489
  /**
5402
5490
  * 文件的点击事件 - 下载文件
5403
- * @param $target
5491
+ * @param evt 点击事件
5492
+ * @param $row 列表项
5404
5493
  * @param dataConfig
5405
5494
  */
5406
- async downloadFile(clickEvent, $row, dataConfig) {
5407
- popsDOMUtils.preventEvent(clickEvent);
5408
- const $link = $row.querySelector("a");
5495
+ async onFileClick(evt, $row, dataConfig) {
5496
+ let downloadInfo;
5409
5497
  if (typeof dataConfig.clickEvent === "function") {
5410
- const downloadInfo = await dataConfig.clickEvent(clickEvent, dataConfig);
5411
- if (downloadInfo != null &&
5412
- typeof downloadInfo === "object" &&
5413
- !Array.isArray(downloadInfo) &&
5414
- typeof downloadInfo.url === "string" &&
5415
- downloadInfo.url.trim() !== "") {
5416
- $link.setAttribute("href", downloadInfo.url);
5417
- $link.setAttribute("target", "_blank");
5418
- if (downloadInfo.autoDownload) {
5419
- if (downloadInfo.mode == null || String(downloadInfo.mode) === "") {
5420
- // 未设置mode的话默认为aBlank
5421
- downloadInfo.mode = "aBlank";
5422
- }
5498
+ const result = await dataConfig.clickEvent(evt, dataConfig);
5499
+ if (typeof result === "object" && result != null && !Array.isArray(result)) {
5500
+ downloadInfo = result;
5501
+ }
5502
+ }
5503
+ else if (typeof dataConfig.clickEvent === "object" &&
5504
+ dataConfig.clickEvent != null &&
5505
+ !Array.isArray(dataConfig.clickEvent)) {
5506
+ downloadInfo = dataConfig.clickEvent;
5507
+ }
5508
+ if (downloadInfo) {
5509
+ const downloadUrl = this.updateFileLink($row, downloadInfo);
5510
+ if (downloadUrl) {
5511
+ if (typeof downloadInfo.mode === "string") {
5423
5512
  if (downloadInfo.mode === "a" || downloadInfo.mode === "aBlank") {
5424
5513
  // a标签下载
5425
5514
  const $anchor = popsDOMUtils.createElement("a");
5426
5515
  if (downloadInfo.mode === "aBlank") {
5427
5516
  $anchor.setAttribute("target", "_blank");
5428
5517
  }
5429
- $anchor.href = downloadInfo.url;
5518
+ $anchor.href = downloadUrl;
5430
5519
  $anchor.click();
5431
5520
  }
5432
5521
  else if (downloadInfo.mode === "open" || downloadInfo.mode === "openBlank") {
5433
5522
  // window.open下载
5434
5523
  if (downloadInfo.mode === "openBlank") {
5435
- globalThis.open(downloadInfo.url, "_blank");
5524
+ globalThis.open(downloadUrl, "_blank");
5436
5525
  }
5437
5526
  else {
5438
- globalThis.open(downloadInfo.url);
5527
+ globalThis.open(downloadUrl);
5439
5528
  }
5440
5529
  }
5441
5530
  else if (downloadInfo.mode === "iframe") {
5442
5531
  // iframe下载
5443
5532
  const $downloadIframe = popsDOMUtils.createElement("iframe");
5444
- $downloadIframe.src = downloadInfo.url;
5533
+ $downloadIframe.src = downloadUrl;
5445
5534
  $downloadIframe.onload = function () {
5446
5535
  popsUtils.setTimeout(() => {
5447
5536
  $downloadIframe.remove();
@@ -5623,8 +5712,14 @@ System.register('pops', [], (function (exports) {
5623
5712
  // 文件 - 点击事件
5624
5713
  popsDOMUtils.on(fileNameElement, "click", (event) => {
5625
5714
  // 下载文件
5626
- this.downloadFile(event, fileNameElement, item);
5715
+ popsDOMUtils.preventEvent(event);
5716
+ this.onFileClick(event, fileNameElement, item);
5627
5717
  });
5718
+ // 如果clickEvent不是函数,那么现在就可以进行配置
5719
+ if (typeof item.clickEvent === "object" && item.clickEvent !== null && !Array.isArray(item.clickEvent)) {
5720
+ // {} 单文件配置
5721
+ this.updateFileLink(fileNameElement, item.clickEvent);
5722
+ }
5628
5723
  folderListBodyElement.appendChild(folderElement);
5629
5724
  }
5630
5725
  });
@@ -5831,7 +5926,7 @@ System.register('pops', [], (function (exports) {
5831
5926
  */
5832
5927
  const $anim = PopsElementHandler.parseElement(animHTML);
5833
5928
  const { $pops: $pops, $headerBtnClose: headerCloseBtnElement, $headerControls: headerControlsElement, $title: $title, $iframe: $iframe, $loading: loadingElement, $contentLoading: $contentLoading, $headerBtnMin: headerMinBtnElement, $headerBtnMax: headerMaxBtnElement, $headerBtnMise: headerMiseBtnElement, } = PopsHandler.handleQueryElement($anim, popsType);
5834
- let $iframeContainer = PopsCore.document.querySelector(".pops-iframe-container");
5929
+ let $iframeContainer = popsDOMUtils.selector(".pops-iframe-container");
5835
5930
  if (!$iframeContainer) {
5836
5931
  $iframeContainer = popsDOMUtils.createElement("div", {
5837
5932
  className: "pops-iframe-container",
@@ -13309,7 +13404,7 @@ System.register('pops', [], (function (exports) {
13309
13404
  },
13310
13405
  };
13311
13406
 
13312
- const version = "3.3.2";
13407
+ const version = "3.3.4";
13313
13408
 
13314
13409
  class Pops {
13315
13410
  /** 配置 */