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