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.
package/dist/Artalk.es.js CHANGED
@@ -565,13 +565,13 @@ function getDefaultExportFromCjs(x) {
565
565
  }
566
566
  var Request = NativeRequest;
567
567
  if (Request && !Request.prototype.hasOwnProperty("signal") || __FORCE_INSTALL_ABORTCONTROLLER_POLYFILL) {
568
- Request = function Request2(input, init) {
568
+ Request = function Request2(input, init2) {
569
569
  var signal;
570
- if (init && init.signal) {
571
- signal = init.signal;
572
- delete init.signal;
570
+ if (init2 && init2.signal) {
571
+ signal = init2.signal;
572
+ delete init2.signal;
573
573
  }
574
- var request = new NativeRequest(input, init);
574
+ var request = new NativeRequest(input, init2);
575
575
  if (signal) {
576
576
  Object.defineProperty(request, "signal", {
577
577
  writable: false,
@@ -585,8 +585,8 @@ function getDefaultExportFromCjs(x) {
585
585
  Request.prototype = NativeRequest.prototype;
586
586
  }
587
587
  var realFetch = fetch2;
588
- var abortableFetch = function abortableFetch2(input, init) {
589
- var signal = Request && Request.prototype.isPrototypeOf(input) ? input.signal : init ? init.signal : void 0;
588
+ var abortableFetch = function abortableFetch2(input, init2) {
589
+ var signal = Request && Request.prototype.isPrototypeOf(input) ? input.signal : init2 ? init2.signal : void 0;
590
590
  if (signal) {
591
591
  var abortError;
592
592
  try {
@@ -605,12 +605,12 @@ function getDefaultExportFromCjs(x) {
605
605
  once: true
606
606
  });
607
607
  });
608
- if (init && init.signal) {
609
- delete init.signal;
608
+ if (init2 && init2.signal) {
609
+ delete init2.signal;
610
610
  }
611
- return Promise.race([cancellation, realFetch(input, init)]);
611
+ return Promise.race([cancellation, realFetch(input, init2)]);
612
612
  }
613
- return realFetch(input, init);
613
+ return realFetch(input, init2);
614
614
  };
615
615
  return {
616
616
  fetch: abortableFetch,
@@ -757,7 +757,10 @@ const en = {
757
757
  deleting: "Deleting",
758
758
  deleteFail: "Delete Failed",
759
759
  reqGot: "Request got",
760
- reqAborted: "Request timed out or terminated unexpectedly"
760
+ reqAborted: "Request timed out or terminated unexpectedly",
761
+ updateMsg: "Please update Artalk {name} to get the full experience",
762
+ currentVersion: "Current Version",
763
+ ignore: "Ignore"
761
764
  };
762
765
  const zhCN = {
763
766
  /* Editor */
@@ -832,7 +835,10 @@ const zhCN = {
832
835
  deleting: "删除中",
833
836
  deleteFail: "删除失败",
834
837
  reqGot: "请求响应",
835
- reqAborted: "请求超时或意外终止"
838
+ reqAborted: "请求超时或意外终止",
839
+ updateMsg: "请更新 Artalk {name} 以获得完整体验",
840
+ currentVersion: "当前版本",
841
+ ignore: "忽略"
836
842
  };
837
843
  const GLOBAL_LOCALES_KEY = "ArtalkI18n";
838
844
  const internal = {
@@ -866,15 +872,15 @@ function t(key, args = {}) {
866
872
  str = str.replace(/\{\s*(\w+?)\s*\}/g, (_, token) => args[token] || "");
867
873
  return str;
868
874
  }
869
- function Fetch$1(opts, input, init, timeout) {
875
+ function Fetch$1(opts, input, init2, timeout) {
870
876
  return __async(this, null, function* () {
871
877
  var _a, _b;
872
878
  if (UserInstance.data.token) {
873
- const headers = new Headers(init.headers);
879
+ const headers = new Headers(init2.headers);
874
880
  headers.set("Authorization", `Bearer ${UserInstance.data.token}`);
875
- init.headers = headers;
881
+ init2.headers = headers;
876
882
  }
877
- const resp = yield timeoutFetch(input, timeout || opts.timeout || 15e3, init);
883
+ const resp = yield timeoutFetch(input, timeout || opts.timeout || 15e3, init2);
878
884
  const respHttpCode = resp.status;
879
885
  const noAccessCodes = [401, 400];
880
886
  const isNoAccess = noAccessCodes.includes(respHttpCode);
@@ -882,7 +888,7 @@ function Fetch$1(opts, input, init, timeout) {
882
888
  throw new Error(`${t("reqGot")} ${respHttpCode}`);
883
889
  let json = yield resp.json();
884
890
  const recall = (resolve, reject) => {
885
- Fetch$1(opts, input, init).then((d) => {
891
+ Fetch$1(opts, input, init2).then((d) => {
886
892
  resolve(d);
887
893
  }).catch((e) => {
888
894
  reject(e);
@@ -919,12 +925,12 @@ function Fetch$1(opts, input, init, timeout) {
919
925
  }
920
926
  function POST(opts, url, data) {
921
927
  return __async(this, null, function* () {
922
- const init = {
928
+ const init2 = {
923
929
  method: "POST"
924
930
  };
925
931
  data = __spreadValues({ site_name: opts.siteName || "" }, data || {});
926
- init.body = ToFormData(data);
927
- const json = yield Fetch$1(opts, url, init);
932
+ init2.body = ToFormData(data);
933
+ const json = yield Fetch$1(opts, url, init2);
928
934
  return json.data || {};
929
935
  });
930
936
  }
@@ -958,9 +964,9 @@ class ApiBase {
958
964
  return POST(this.options, this.options.baseURL + path, data);
959
965
  });
960
966
  }
961
- Fetch(path, init, timeout) {
967
+ Fetch(path, init2, timeout) {
962
968
  return __async(this, null, function* () {
963
- return Fetch$1(this.options, this.options.baseURL + path, init, timeout);
969
+ return Fetch$1(this.options, this.options.baseURL + path, init2, timeout);
964
970
  });
965
971
  }
966
972
  }
@@ -1366,11 +1372,11 @@ class UploadApi extends ApiBase {
1366
1372
  };
1367
1373
  const form = ToFormData(params);
1368
1374
  form.set("file", file);
1369
- const init = {
1375
+ const init2 = {
1370
1376
  method: "POST",
1371
1377
  body: form
1372
1378
  };
1373
- const json = yield this.Fetch("/img-upload", init);
1379
+ const json = yield this.Fetch("/img-upload", init2);
1374
1380
  return json.data || {};
1375
1381
  });
1376
1382
  }
@@ -8292,7 +8298,7 @@ function extractCommentID() {
8292
8298
  }
8293
8299
  return commentId || null;
8294
8300
  }
8295
- const version = "2.7.0";
8301
+ const version = "2.7.1";
8296
8302
  const Copyright = (ctx) => {
8297
8303
  ctx.on("conf-loaded", () => {
8298
8304
  const list = ctx.get("list");
@@ -8566,12 +8572,15 @@ function initCountWidget(opt) {
8566
8572
  if (opt.countEl && document.querySelector(opt.countEl)) {
8567
8573
  refreshStatCount(opt, { query: "page_comment", numEl: opt.countEl });
8568
8574
  }
8569
- const curtPagePvNum = opt.pvAdd ? yield opt.getApi().page.pv() : NaN;
8575
+ const initialData = opt.pvAdd ? {
8576
+ [opt.pageKey]: yield opt.getApi().page.pv()
8577
+ // pv+1 and get pv count
8578
+ } : void 0;
8570
8579
  if (opt.pvEl && document.querySelector(opt.pvEl)) {
8571
8580
  refreshStatCount(opt, {
8572
8581
  query: "page_pv",
8573
8582
  numEl: opt.pvEl,
8574
- data: { [opt.pageKey]: curtPagePvNum }
8583
+ data: initialData
8575
8584
  });
8576
8585
  }
8577
8586
  });
@@ -8579,10 +8588,10 @@ function initCountWidget(opt) {
8579
8588
  function refreshStatCount(opt, args) {
8580
8589
  return __async(this, null, function* () {
8581
8590
  let data = args.data || {};
8582
- let pageKeys = Array.from(document.querySelectorAll(args.numEl)).map((e) => e.getAttribute("data-page-key") || opt.pageKey).filter((e) => Number.isNaN(data[e]));
8583
- pageKeys = [...new Set(pageKeys)];
8584
- if (pageKeys.length > 0) {
8585
- const res = yield opt.getApi().page.stat(args.query, pageKeys);
8591
+ let queryPageKeys = Array.from(document.querySelectorAll(args.numEl)).map((e) => e.getAttribute("data-page-key") || opt.pageKey).filter((k) => typeof data[k] !== "number");
8592
+ queryPageKeys = [...new Set(queryPageKeys)];
8593
+ if (queryPageKeys.length > 0) {
8594
+ const res = yield opt.getApi().page.stat(args.query, queryPageKeys);
8586
8595
  data = __spreadValues(__spreadValues({}, data), res);
8587
8596
  }
8588
8597
  applyCountData(args.numEl, data, data[opt.pageKey]);
@@ -8609,9 +8618,9 @@ function versionCheck(list, feVer, beVer) {
8609
8618
  if (sameVer)
8610
8619
  return;
8611
8620
  const errEl = createElement(
8612
- `<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>`
8621
+ `<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>`
8613
8622
  );
8614
- const ignoreBtn = createElement('<span style="cursor:pointer">忽略</span>');
8623
+ const ignoreBtn = createElement(`<span style="cursor:pointer">${t("ignore")}</span>`);
8615
8624
  ignoreBtn.onclick = () => {
8616
8625
  setError(list.$el.parentElement, null);
8617
8626
  IgnoreVersionCheck = true;
@@ -8693,7 +8702,7 @@ const DefaultPlugins = [
8693
8702
  DarkMode
8694
8703
  ];
8695
8704
  const GlobalPlugins = [...DefaultPlugins];
8696
- const _Artalk = class _Artalk {
8705
+ class Artalk {
8697
8706
  constructor(conf) {
8698
8707
  __publicField(this, "conf");
8699
8708
  __publicField(this, "ctx");
@@ -8745,9 +8754,12 @@ const _Artalk = class _Artalk {
8745
8754
  setDarkMode(darkMode) {
8746
8755
  this.ctx.setDarkMode(darkMode);
8747
8756
  }
8757
+ // ===========================
8758
+ // Static Members
8759
+ // ===========================
8748
8760
  /** Init Artalk */
8749
8761
  static init(conf) {
8750
- return new _Artalk(conf);
8762
+ return new Artalk(conf);
8751
8763
  }
8752
8764
  /** Use plugin, the plugin will be used when Artalk.init */
8753
8765
  static use(plugin) {
@@ -8766,17 +8778,18 @@ const _Artalk = class _Artalk {
8766
8778
  pvAdd: false
8767
8779
  });
8768
8780
  }
8769
- };
8770
- // ===========================
8771
- // Static Members
8772
- // ===========================
8773
- /** Default Configs */
8774
- __publicField(_Artalk, "defaults", defaults);
8775
- let Artalk = _Artalk;
8781
+ }
8776
8782
  const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
8777
8783
  __proto__: null
8778
8784
  }, Symbol.toStringTag, { value: "Module" }));
8785
+ const init = Artalk.init;
8786
+ const use = Artalk.use;
8787
+ const loadCountWidget = Artalk.loadCountWidget;
8779
8788
  export {
8780
8789
  index as ArtalkType,
8781
- Artalk as default
8790
+ Artalk as default,
8791
+ init,
8792
+ loadCountWidget,
8793
+ use
8782
8794
  };
8795
+ //# sourceMappingURL=Artalk.es.js.map