artalk 2.7.0 → 2.7.1

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.
@@ -552,13 +552,13 @@ function getDefaultExportFromCjs(x) {
552
552
  }
553
553
  var Request = NativeRequest;
554
554
  if (Request && !Request.prototype.hasOwnProperty("signal") || __FORCE_INSTALL_ABORTCONTROLLER_POLYFILL) {
555
- Request = function Request2(input, init) {
555
+ Request = function Request2(input, init2) {
556
556
  var signal;
557
- if (init && init.signal) {
558
- signal = init.signal;
559
- delete init.signal;
557
+ if (init2 && init2.signal) {
558
+ signal = init2.signal;
559
+ delete init2.signal;
560
560
  }
561
- var request = new NativeRequest(input, init);
561
+ var request = new NativeRequest(input, init2);
562
562
  if (signal) {
563
563
  Object.defineProperty(request, "signal", {
564
564
  writable: false,
@@ -572,8 +572,8 @@ function getDefaultExportFromCjs(x) {
572
572
  Request.prototype = NativeRequest.prototype;
573
573
  }
574
574
  var realFetch = fetch2;
575
- var abortableFetch = function abortableFetch2(input, init) {
576
- var signal = Request && Request.prototype.isPrototypeOf(input) ? input.signal : init ? init.signal : void 0;
575
+ var abortableFetch = function abortableFetch2(input, init2) {
576
+ var signal = Request && Request.prototype.isPrototypeOf(input) ? input.signal : init2 ? init2.signal : void 0;
577
577
  if (signal) {
578
578
  var abortError;
579
579
  try {
@@ -592,12 +592,12 @@ function getDefaultExportFromCjs(x) {
592
592
  once: true
593
593
  });
594
594
  });
595
- if (init && init.signal) {
596
- delete init.signal;
595
+ if (init2 && init2.signal) {
596
+ delete init2.signal;
597
597
  }
598
- return Promise.race([cancellation, realFetch(input, init)]);
598
+ return Promise.race([cancellation, realFetch(input, init2)]);
599
599
  }
600
- return realFetch(input, init);
600
+ return realFetch(input, init2);
601
601
  };
602
602
  return {
603
603
  fetch: abortableFetch,
@@ -744,7 +744,10 @@ const en = {
744
744
  deleting: "Deleting",
745
745
  deleteFail: "Delete Failed",
746
746
  reqGot: "Request got",
747
- reqAborted: "Request timed out or terminated unexpectedly"
747
+ reqAborted: "Request timed out or terminated unexpectedly",
748
+ updateMsg: "Please update Artalk {name} to get the full experience",
749
+ currentVersion: "Current Version",
750
+ ignore: "Ignore"
748
751
  };
749
752
  const zhCN = {
750
753
  /* Editor */
@@ -819,7 +822,10 @@ const zhCN = {
819
822
  deleting: "删除中",
820
823
  deleteFail: "删除失败",
821
824
  reqGot: "请求响应",
822
- reqAborted: "请求超时或意外终止"
825
+ reqAborted: "请求超时或意外终止",
826
+ updateMsg: "请更新 Artalk {name} 以获得完整体验",
827
+ currentVersion: "当前版本",
828
+ ignore: "忽略"
823
829
  };
824
830
  const GLOBAL_LOCALES_KEY = "ArtalkI18n";
825
831
  const internal = {
@@ -853,15 +859,15 @@ function t(key, args = {}) {
853
859
  str = str.replace(/\{\s*(\w+?)\s*\}/g, (_, token) => args[token] || "");
854
860
  return str;
855
861
  }
856
- function Fetch$1(opts, input, init, timeout) {
862
+ function Fetch$1(opts, input, init2, timeout) {
857
863
  return __async(this, null, function* () {
858
864
  var _a, _b;
859
865
  if (UserInstance.data.token) {
860
- const headers = new Headers(init.headers);
866
+ const headers = new Headers(init2.headers);
861
867
  headers.set("Authorization", `Bearer ${UserInstance.data.token}`);
862
- init.headers = headers;
868
+ init2.headers = headers;
863
869
  }
864
- const resp = yield timeoutFetch(input, timeout || opts.timeout || 15e3, init);
870
+ const resp = yield timeoutFetch(input, timeout || opts.timeout || 15e3, init2);
865
871
  const respHttpCode = resp.status;
866
872
  const noAccessCodes = [401, 400];
867
873
  const isNoAccess = noAccessCodes.includes(respHttpCode);
@@ -869,7 +875,7 @@ function Fetch$1(opts, input, init, timeout) {
869
875
  throw new Error(`${t("reqGot")} ${respHttpCode}`);
870
876
  let json = yield resp.json();
871
877
  const recall = (resolve, reject) => {
872
- Fetch$1(opts, input, init).then((d) => {
878
+ Fetch$1(opts, input, init2).then((d) => {
873
879
  resolve(d);
874
880
  }).catch((e) => {
875
881
  reject(e);
@@ -906,12 +912,12 @@ function Fetch$1(opts, input, init, timeout) {
906
912
  }
907
913
  function POST(opts, url, data) {
908
914
  return __async(this, null, function* () {
909
- const init = {
915
+ const init2 = {
910
916
  method: "POST"
911
917
  };
912
918
  data = __spreadValues({ site_name: opts.siteName || "" }, data || {});
913
- init.body = ToFormData(data);
914
- const json = yield Fetch$1(opts, url, init);
919
+ init2.body = ToFormData(data);
920
+ const json = yield Fetch$1(opts, url, init2);
915
921
  return json.data || {};
916
922
  });
917
923
  }
@@ -945,9 +951,9 @@ class ApiBase {
945
951
  return POST(this.options, this.options.baseURL + path, data);
946
952
  });
947
953
  }
948
- Fetch(path, init, timeout) {
954
+ Fetch(path, init2, timeout) {
949
955
  return __async(this, null, function* () {
950
- return Fetch$1(this.options, this.options.baseURL + path, init, timeout);
956
+ return Fetch$1(this.options, this.options.baseURL + path, init2, timeout);
951
957
  });
952
958
  }
953
959
  }
@@ -1353,11 +1359,11 @@ class UploadApi extends ApiBase {
1353
1359
  };
1354
1360
  const form = ToFormData(params);
1355
1361
  form.set("file", file);
1356
- const init = {
1362
+ const init2 = {
1357
1363
  method: "POST",
1358
1364
  body: form
1359
1365
  };
1360
- const json = yield this.Fetch("/img-upload", init);
1366
+ const json = yield this.Fetch("/img-upload", init2);
1361
1367
  return json.data || {};
1362
1368
  });
1363
1369
  }
@@ -6077,7 +6083,7 @@ function extractCommentID() {
6077
6083
  }
6078
6084
  return commentId || null;
6079
6085
  }
6080
- const version = "2.7.0";
6086
+ const version = "2.7.1";
6081
6087
  const Copyright = (ctx) => {
6082
6088
  ctx.on("conf-loaded", () => {
6083
6089
  const list = ctx.get("list");
@@ -6351,12 +6357,15 @@ function initCountWidget(opt) {
6351
6357
  if (opt.countEl && document.querySelector(opt.countEl)) {
6352
6358
  refreshStatCount(opt, { query: "page_comment", numEl: opt.countEl });
6353
6359
  }
6354
- const curtPagePvNum = opt.pvAdd ? yield opt.getApi().page.pv() : NaN;
6360
+ const initialData = opt.pvAdd ? {
6361
+ [opt.pageKey]: yield opt.getApi().page.pv()
6362
+ // pv+1 and get pv count
6363
+ } : void 0;
6355
6364
  if (opt.pvEl && document.querySelector(opt.pvEl)) {
6356
6365
  refreshStatCount(opt, {
6357
6366
  query: "page_pv",
6358
6367
  numEl: opt.pvEl,
6359
- data: { [opt.pageKey]: curtPagePvNum }
6368
+ data: initialData
6360
6369
  });
6361
6370
  }
6362
6371
  });
@@ -6364,10 +6373,10 @@ function initCountWidget(opt) {
6364
6373
  function refreshStatCount(opt, args) {
6365
6374
  return __async(this, null, function* () {
6366
6375
  let data = args.data || {};
6367
- let pageKeys = Array.from(document.querySelectorAll(args.numEl)).map((e) => e.getAttribute("data-page-key") || opt.pageKey).filter((e) => Number.isNaN(data[e]));
6368
- pageKeys = [...new Set(pageKeys)];
6369
- if (pageKeys.length > 0) {
6370
- const res = yield opt.getApi().page.stat(args.query, pageKeys);
6376
+ let queryPageKeys = Array.from(document.querySelectorAll(args.numEl)).map((e) => e.getAttribute("data-page-key") || opt.pageKey).filter((k) => typeof data[k] !== "number");
6377
+ queryPageKeys = [...new Set(queryPageKeys)];
6378
+ if (queryPageKeys.length > 0) {
6379
+ const res = yield opt.getApi().page.stat(args.query, queryPageKeys);
6371
6380
  data = __spreadValues(__spreadValues({}, data), res);
6372
6381
  }
6373
6382
  applyCountData(args.numEl, data, data[opt.pageKey]);
@@ -6394,9 +6403,9 @@ function versionCheck(list, feVer, beVer) {
6394
6403
  if (sameVer)
6395
6404
  return;
6396
6405
  const errEl = createElement(
6397
- `<div>请更新 Artalk ${comp < 0 ? t("frontend") : t("backend")}以获得完整体验 (<a href="https://artalk.js.org/" target="_blank">帮助文档</a>)<br/><br/><span style="color: var(--at-color-meta);">当前版本:${t("frontend")} ${feVer} / ${t("backend")} ${beVer}</span><br/><br/></div>`
6406
+ `<div>${t("updateMsg", { name: comp < 0 ? t("frontend") : t("backend") })}<br/><br/><span style="color: var(--at-color-meta);">${t("currentVersion")}: ${t("frontend")} ${feVer} / ${t("backend")} ${beVer}</span><br/><br/></div>`
6398
6407
  );
6399
- const ignoreBtn = createElement('<span style="cursor:pointer">忽略</span>');
6408
+ const ignoreBtn = createElement(`<span style="cursor:pointer">${t("ignore")}</span>`);
6400
6409
  ignoreBtn.onclick = () => {
6401
6410
  setError(list.$el.parentElement, null);
6402
6411
  IgnoreVersionCheck = true;
@@ -6478,7 +6487,7 @@ const DefaultPlugins = [
6478
6487
  DarkMode
6479
6488
  ];
6480
6489
  const GlobalPlugins = [...DefaultPlugins];
6481
- const _Artalk = class _Artalk {
6490
+ class Artalk {
6482
6491
  constructor(conf) {
6483
6492
  __publicField(this, "conf");
6484
6493
  __publicField(this, "ctx");
@@ -6530,9 +6539,12 @@ const _Artalk = class _Artalk {
6530
6539
  setDarkMode(darkMode) {
6531
6540
  this.ctx.setDarkMode(darkMode);
6532
6541
  }
6542
+ // ===========================
6543
+ // Static Members
6544
+ // ===========================
6533
6545
  /** Init Artalk */
6534
6546
  static init(conf) {
6535
- return new _Artalk(conf);
6547
+ return new Artalk(conf);
6536
6548
  }
6537
6549
  /** Use plugin, the plugin will be used when Artalk.init */
6538
6550
  static use(plugin) {
@@ -6551,17 +6563,18 @@ const _Artalk = class _Artalk {
6551
6563
  pvAdd: false
6552
6564
  });
6553
6565
  }
6554
- };
6555
- // ===========================
6556
- // Static Members
6557
- // ===========================
6558
- /** Default Configs */
6559
- __publicField(_Artalk, "defaults", defaults);
6560
- let Artalk = _Artalk;
6566
+ }
6561
6567
  const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
6562
6568
  __proto__: null
6563
6569
  }, Symbol.toStringTag, { value: "Module" }));
6570
+ const init = Artalk.init;
6571
+ const use = Artalk.use;
6572
+ const loadCountWidget = Artalk.loadCountWidget;
6564
6573
  export {
6565
6574
  index as ArtalkType,
6566
- Artalk as default
6575
+ Artalk as default,
6576
+ init,
6577
+ loadCountWidget,
6578
+ use
6567
6579
  };
6580
+ //# sourceMappingURL=ArtalkLite.es.js.map