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