artalk 2.4.1 → 2.4.3

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.
Files changed (49) hide show
  1. package/dist/Artalk.css +1 -1
  2. package/dist/Artalk.es.js +206 -104
  3. package/dist/Artalk.iife.js +1 -1
  4. package/dist/Artalk.js +1 -1
  5. package/dist/ArtalkLite.css +1 -1
  6. package/dist/ArtalkLite.es.js +206 -104
  7. package/dist/ArtalkLite.iife.js +1 -1
  8. package/dist/ArtalkLite.js +1 -1
  9. package/dist/i18n/jp.js +1 -0
  10. package/dist/i18n/zh-TW.js +1 -0
  11. package/dist/src/api/index.d.ts +1 -1
  12. package/dist/src/api/system.d.ts +7 -0
  13. package/dist/src/api/user.d.ts +16 -2
  14. package/dist/src/artalk.d.ts +0 -6
  15. package/dist/src/context.d.ts +4 -0
  16. package/dist/src/i18n/index.d.ts +68 -74
  17. package/dist/src/list/list-lite.d.ts +17 -7
  18. package/dist/src/list/list.d.ts +1 -0
  19. package/dist/types/artalk-config.d.ts +5 -1
  20. package/dist/types/artalk-data.d.ts +23 -0
  21. package/dist/types/context.d.ts +3 -0
  22. package/dist/types/event.d.ts +1 -1
  23. package/package.json +4 -3
  24. package/scripts/build-i18n.mjs +46 -0
  25. package/src/api/index.ts +3 -2
  26. package/src/api/system.ts +7 -0
  27. package/src/api/user.ts +59 -2
  28. package/src/artalk.ts +0 -35
  29. package/src/comment/render.ts +2 -1
  30. package/src/context.ts +33 -3
  31. package/src/defaults.ts +2 -2
  32. package/src/editor/editor.ts +8 -8
  33. package/src/editor/plugs/upload-plug.ts +1 -1
  34. package/src/i18n/index.ts +18 -90
  35. package/src/i18n/jp.ts +83 -0
  36. package/src/i18n/zh-TW.ts +83 -0
  37. package/src/layer/sidebar-layer.ts +10 -8
  38. package/src/lib/checker/admin-checker.ts +4 -1
  39. package/src/lib/checker/captcha-checker.ts +1 -0
  40. package/src/lib/stat.ts +9 -1
  41. package/src/lib/utils.ts +8 -1
  42. package/src/list/list-lite.ts +68 -26
  43. package/src/list/list.ts +10 -18
  44. package/src/style/main.less +17 -0
  45. package/test/ArtalkI18n.html +1 -0
  46. package/types/artalk-config.d.ts +5 -1
  47. package/types/artalk-data.d.ts +23 -0
  48. package/types/context.d.ts +3 -0
  49. package/types/event.d.ts +1 -1
package/dist/Artalk.es.js CHANGED
@@ -183,15 +183,19 @@ const internal = {
183
183
  "en-US": en,
184
184
  "zh-CN": zhCN
185
185
  };
186
+ const GLOBAL_LOCALES_KEY = "ArtalkI18n";
186
187
  function getLocaleSet(lang) {
187
188
  lang = lang.replace(
188
189
  /^([a-zA-Z]+)(-[a-zA-Z]+)?$/,
189
190
  (_, p1, p2) => p1.toLowerCase() + (p2 || "").toUpperCase()
190
191
  );
191
- if (!internal[lang]) {
192
- return internal.en;
192
+ if (internal[lang]) {
193
+ return internal[lang];
193
194
  }
194
- return internal[lang];
195
+ if (window[GLOBAL_LOCALES_KEY] && window[GLOBAL_LOCALES_KEY][lang]) {
196
+ return window[GLOBAL_LOCALES_KEY][lang];
197
+ }
198
+ return internal.en;
195
199
  }
196
200
  function getI18n(locale, key, args = {}) {
197
201
  if (typeof locale === "string") {
@@ -232,18 +236,6 @@ class User {
232
236
  return !!this.data.nick && !!this.data.email;
233
237
  }
234
238
  }
235
- class Component {
236
- constructor(ctx) {
237
- __publicField(this, "$el");
238
- __publicField(this, "ctx");
239
- __publicField(this, "conf");
240
- this.ctx = ctx;
241
- this.conf = ctx.conf;
242
- }
243
- $t(key, args = {}) {
244
- return this.ctx.$t(key, args);
245
- }
246
- }
247
239
  function getDefaults() {
248
240
  return {
249
241
  baseUrl: null,
@@ -2851,7 +2843,12 @@ function marked(ctx, src) {
2851
2843
  }
2852
2844
  let dest = insane_1(markedContent, {
2853
2845
  allowedClasses: {},
2854
- allowedSchemes: ["http", "https", "mailto"],
2846
+ allowedSchemes: [
2847
+ "http",
2848
+ "https",
2849
+ "mailto",
2850
+ "data"
2851
+ ],
2855
2852
  allowedTags: [
2856
2853
  "a",
2857
2854
  "abbr",
@@ -2988,6 +2985,18 @@ function mergeDeep(target, source) {
2988
2985
  });
2989
2986
  return target;
2990
2987
  }
2988
+ class Component {
2989
+ constructor(ctx) {
2990
+ __publicField(this, "$el");
2991
+ __publicField(this, "ctx");
2992
+ __publicField(this, "conf");
2993
+ this.ctx = ctx;
2994
+ this.conf = ctx.conf;
2995
+ }
2996
+ $t(key, args = {}) {
2997
+ return this.ctx.$t(key, args);
2998
+ }
2999
+ }
2991
3000
  function showLoading(parentElem, conf) {
2992
3001
  let $loading = parentElem.querySelector(":scope > .atk-loading");
2993
3002
  if (!$loading) {
@@ -3905,7 +3914,7 @@ class UserApi extends ApiBase {
3905
3914
  if (this.ctx.conf.site)
3906
3915
  params.site_name = this.ctx.conf.site;
3907
3916
  const data = yield this.POST("/login", params);
3908
- return data.token;
3917
+ return data;
3909
3918
  });
3910
3919
  }
3911
3920
  userGet(name, email) {
@@ -3959,6 +3968,58 @@ class UserApi extends ApiBase {
3959
3968
  }
3960
3969
  return this.POST(`/mark-read`, params);
3961
3970
  }
3971
+ userList(offset, limit, type) {
3972
+ return __async(this, null, function* () {
3973
+ const params = {
3974
+ offset: offset || 0,
3975
+ limit: limit || 15
3976
+ };
3977
+ if (type)
3978
+ params.type = type;
3979
+ const d = yield this.POST("/admin/user-get", params);
3980
+ return d;
3981
+ });
3982
+ }
3983
+ userAdd(user, password) {
3984
+ return __async(this, null, function* () {
3985
+ const params = {
3986
+ name: user.name || "",
3987
+ email: user.email || "",
3988
+ password: password || "",
3989
+ link: user.link || "",
3990
+ is_admin: user.is_admin || false,
3991
+ site_names: user.site_names_raw || "",
3992
+ receive_email: user.receive_email || true,
3993
+ badge_name: user.badge_name || "",
3994
+ badge_color: user.badge_color || ""
3995
+ };
3996
+ const d = yield this.POST("/admin/user-add", params);
3997
+ return d.user;
3998
+ });
3999
+ }
4000
+ userEdit(user, password) {
4001
+ return __async(this, null, function* () {
4002
+ const params = {
4003
+ id: user.id,
4004
+ name: user.name || "",
4005
+ email: user.email || "",
4006
+ password: password || "",
4007
+ link: user.link || "",
4008
+ is_admin: user.is_admin || false,
4009
+ site_names: user.site_names_raw || "",
4010
+ receive_email: user.receive_email || true,
4011
+ badge_name: user.badge_name || "",
4012
+ badge_color: user.badge_color || ""
4013
+ };
4014
+ const d = yield this.POST("/admin/user-edit", params);
4015
+ return d.user;
4016
+ });
4017
+ }
4018
+ userDel(userID) {
4019
+ return this.POST("/admin/user-del", {
4020
+ id: String(userID)
4021
+ });
4022
+ }
3962
4023
  }
3963
4024
  class SystemApi extends ApiBase {
3964
4025
  conf() {
@@ -3990,6 +4051,13 @@ class SystemApi extends ApiBase {
3990
4051
  return data;
3991
4052
  });
3992
4053
  }
4054
+ version() {
4055
+ return __async(this, null, function* () {
4056
+ const resp = yield fetch(`${this.api.baseURL}/version`, { method: "POST" });
4057
+ const data = yield resp.json();
4058
+ return data;
4059
+ });
4060
+ }
3993
4061
  }
3994
4062
  class CaptchaApi extends ApiBase {
3995
4063
  captchaGet() {
@@ -4055,16 +4123,17 @@ const ApiComponents = {
4055
4123
  class Api {
4056
4124
  constructor(ctx) {
4057
4125
  __publicField(this, "ctx");
4058
- __publicField(this, "baseURL");
4059
4126
  this.ctx = ctx;
4060
- this.baseURL = `${ctx.conf.server}/api`;
4061
4127
  Object.entries(ApiComponents).forEach(([key, ApiComponent]) => {
4062
4128
  this[key] = new ApiComponent(this, this.ctx);
4063
4129
  });
4064
4130
  }
4131
+ get baseURL() {
4132
+ return `${this.ctx.conf.server}/api`;
4133
+ }
4065
4134
  }
4066
- const version = "2.4.1";
4067
- const backendMinVersion = "2.2.0";
4135
+ const version = "2.4.3";
4136
+ const backendMinVersion = "2.3.0";
4068
4137
  const ListHTML = '<div class="atk-list">\n <div class="atk-list-header">\n <div class="atk-comment-count">\n <div class="atk-text"></div>\n </div>\n <div class="atk-right-action">\n <span data-action="admin-close-comment" class="atk-hide" atk-only-admin-show></span>\n <span data-action="open-sidebar" class="atk-hide atk-on">\n <span class="atk-unread-badge" style="display: none;"></span>\n <div class="atk-text"></div>\n </span>\n </div>\n </div>\n <div class="atk-list-body"></div>\n <div class="atk-list-footer">\n <div class="atk-copyright"></div>\n </div>\n</div>\n';
4069
4138
  const win = window || {};
4070
4139
  const nav = navigator || {};
@@ -4423,7 +4492,8 @@ class CommentRender {
4423
4492
  renderAvatar() {
4424
4493
  const $avatar = this.$el.querySelector(".atk-avatar");
4425
4494
  const $avatarImg = createElement("<img />");
4426
- $avatarImg.src = this.comment.getGravatarURL();
4495
+ const avatarURLBuilder = this.ctx.conf.avatarURLBuilder;
4496
+ $avatarImg.src = avatarURLBuilder ? avatarURLBuilder(this.data) : this.comment.getGravatarURL();
4427
4497
  if (this.data.link) {
4428
4498
  const $avatarA = createElement('<a target="_blank" rel="noreferrer noopener nofollow"></a>');
4429
4499
  $avatarA.href = isValidURL(this.data.link) ? this.data.link : `https://${this.data.link}`;
@@ -5209,10 +5279,10 @@ class ListLite extends Component {
5209
5279
  __publicField(this, "data");
5210
5280
  __publicField(this, "isLoading", false);
5211
5281
  __publicField(this, "noCommentText");
5212
- __publicField(this, "flatMode", false);
5213
- __publicField(this, "nestSortBy");
5214
- __publicField(this, "pageMode", "pagination");
5215
- __publicField(this, "pageSize", 20);
5282
+ __publicField(this, "_nestSortBy");
5283
+ __publicField(this, "_flatMode");
5284
+ __publicField(this, "_pageMode");
5285
+ __publicField(this, "_pageSize");
5216
5286
  __publicField(this, "scrollListenerAt");
5217
5287
  __publicField(this, "repositionAt");
5218
5288
  __publicField(this, "pagination");
@@ -5223,20 +5293,53 @@ class ListLite extends Component {
5223
5293
  __publicField(this, "onAfterLoad");
5224
5294
  __publicField(this, "unread", []);
5225
5295
  __publicField(this, "unreadHighlight");
5296
+ __publicField(this, "confLoaded", false);
5226
5297
  this.$el = createElement(
5227
5298
  `<div class="atk-list-lite">
5228
5299
  <div class="atk-list-comments-wrap"></div>
5229
5300
  </div>`
5230
5301
  );
5231
5302
  this.$commentsWrap = this.$el.querySelector(".atk-list-comments-wrap");
5232
- this.noCommentText = ctx.conf.noComment || ctx.$t("noComment");
5233
- this.nestSortBy = this.ctx.conf.nestSort || "DATE_ASC";
5234
5303
  window.setInterval(() => {
5235
5304
  this.$el.querySelectorAll("[data-atk-comment-date]").forEach((el) => {
5236
5305
  const date = el.getAttribute("data-atk-comment-date");
5237
5306
  el.innerText = timeAgo(new Date(Number(date)), this.ctx);
5238
5307
  });
5239
5308
  }, 30 * 1e3);
5309
+ this.ctx.on("conf-loaded", () => {
5310
+ });
5311
+ }
5312
+ get nestSortBy() {
5313
+ if (this._nestSortBy !== void 0)
5314
+ return this._nestSortBy;
5315
+ return this.ctx.conf.nestSort || "DATE_ASC";
5316
+ }
5317
+ set nestSortBy(val) {
5318
+ this._nestSortBy = val;
5319
+ }
5320
+ get flatMode() {
5321
+ if (this._flatMode !== void 0)
5322
+ return this._flatMode;
5323
+ if (this.ctx.conf.flatMode === true || Number(this.ctx.conf.nestMax) <= 1)
5324
+ return true;
5325
+ if (this.ctx.conf.flatMode === "auto" && window.matchMedia("(max-width: 768px)").matches)
5326
+ return true;
5327
+ return false;
5328
+ }
5329
+ set flatMode(val) {
5330
+ this._flatMode = val;
5331
+ }
5332
+ get pageMode() {
5333
+ return this._pageMode || (this.conf.pagination.readMore ? "read-more" : "pagination");
5334
+ }
5335
+ set pageMode(val) {
5336
+ this._pageMode = val;
5337
+ }
5338
+ get pageSize() {
5339
+ return this._pageSize || this.conf.pagination.pageSize;
5340
+ }
5341
+ set pageSize(val) {
5342
+ this._pageSize = val;
5240
5343
  }
5241
5344
  getData() {
5242
5345
  return this.data;
@@ -5264,7 +5367,7 @@ class ListLite extends Component {
5264
5367
  const setLoading2 = (val) => this.setLoading(val, isFirstLoad);
5265
5368
  setLoading2(true);
5266
5369
  this.ctx.trigger("list-load");
5267
- if (isFirstLoad && this.pageMode === "read-more") {
5370
+ if (this.pageMode === "read-more" && isFirstLoad || this.pageMode === "pagination") {
5268
5371
  this.ctx.clearAllComments();
5269
5372
  }
5270
5373
  let listData;
@@ -5289,24 +5392,24 @@ class ListLite extends Component {
5289
5392
  }
5290
5393
  onLoad(data, offset) {
5291
5394
  var _a, _b;
5292
- if (this.pageMode === "pagination") {
5293
- this.ctx.clearAllComments();
5294
- }
5295
5395
  this.data = data;
5396
+ if (!this.confLoaded) {
5397
+ if (this.conf.useBackendConf)
5398
+ this.ctx.updateConf(data.conf.frontend_conf);
5399
+ else
5400
+ this.ctx.updateConf({});
5401
+ this.confLoaded = true;
5402
+ }
5296
5403
  const feMinVersion = ((_a = data.api_version) == null ? void 0 : _a.fe_min_version) || "0.0.0";
5297
5404
  if (this.ctx.conf.versionCheck && this.versionCheck("frontend", feMinVersion, version))
5298
5405
  return;
5299
5406
  if (this.ctx.conf.versionCheck && this.versionCheck("backend", backendMinVersion, (_b = data.api_version) == null ? void 0 : _b.version))
5300
5407
  return;
5301
- if (data.conf && typeof data.conf.img_upload === "boolean") {
5302
- this.ctx.conf.imgUpload = data.conf.img_upload;
5303
- }
5304
5408
  this.importComments(data.comments);
5305
5409
  this.refreshPagination(offset, this.flatMode ? data.total : data.total_roots);
5306
5410
  this.refreshUI();
5307
5411
  this.ctx.updateNotifies(data.unread || []);
5308
5412
  this.ctx.trigger("list-loaded");
5309
- this.ctx.trigger("conf-updated");
5310
5413
  if (this.onAfterLoad)
5311
5414
  this.onAfterLoad(data);
5312
5415
  }
@@ -5370,6 +5473,9 @@ class ListLite extends Component {
5370
5473
  }
5371
5474
  onError(msg, offset, errData) {
5372
5475
  var _a;
5476
+ if (!this.confLoaded) {
5477
+ this.ctx.updateConf({});
5478
+ }
5373
5479
  msg = String(msg);
5374
5480
  console.error(msg);
5375
5481
  if (offset !== 0 && this.pageMode === "read-more") {
@@ -5403,7 +5509,7 @@ class ListLite extends Component {
5403
5509
  if (isNoComment) {
5404
5510
  if (!$noComment) {
5405
5511
  $noComment = createElement('<div class="atk-list-no-comment"></div>');
5406
- $noComment.innerHTML = this.noCommentText;
5512
+ $noComment.innerHTML = this.noCommentText || this.ctx.conf.noComment || this.ctx.$t("noComment");
5407
5513
  this.$commentsWrap.appendChild($noComment);
5408
5514
  }
5409
5515
  } else {
@@ -5533,7 +5639,6 @@ class ListLite extends Component {
5533
5639
  ignoreBtn.onclick = () => {
5534
5640
  setError(this.$el.parentElement, null);
5535
5641
  this.ctx.conf.versionCheck = false;
5536
- this.ctx.trigger("conf-updated");
5537
5642
  this.fetchComments(0);
5538
5643
  };
5539
5644
  errEl.append(ignoreBtn);
@@ -5554,18 +5659,9 @@ class List extends ListLite {
5554
5659
  __publicField(this, "$dropdownWrap");
5555
5660
  __publicField(this, "goToCommentFounded", false);
5556
5661
  __publicField(this, "goToCommentDelay", true);
5662
+ __publicField(this, "dropdownLoaded", false);
5557
5663
  el.querySelector(".atk-list-body").append(this.$el);
5558
5664
  this.$el = el;
5559
- if (this.ctx.conf.flatMode === true) {
5560
- this.flatMode = true;
5561
- } else if (this.conf.nestMax && this.conf.nestMax <= 1) {
5562
- this.flatMode = true;
5563
- } else if (this.ctx.conf.flatMode === "auto") {
5564
- if (window.matchMedia("(max-width: 768px)").matches)
5565
- this.flatMode = true;
5566
- }
5567
- this.pageMode = this.conf.pagination.readMore ? "read-more" : "pagination";
5568
- this.pageSize = this.conf.pagination.pageSize || 20;
5569
5665
  this.repositionAt = this.$el;
5570
5666
  this.initListActionBtn();
5571
5667
  this.$commentCount = this.$el.querySelector(".atk-comment-count");
@@ -5573,9 +5669,6 @@ class List extends ListLite {
5573
5669
  count: '<span class="atk-comment-count-num">0</span>'
5574
5670
  });
5575
5671
  this.$commentCountNum = this.$commentCount.querySelector(".atk-comment-count-num");
5576
- if (this.ctx.conf.listSort) {
5577
- this.initDropdown();
5578
- }
5579
5672
  this.$el.querySelector(".atk-copyright").innerHTML = `Powered By <a href="https://artalk.js.org" target="_blank" title="Artalk v${version}">Artalk</a>`;
5580
5673
  }
5581
5674
  initListActionBtn() {
@@ -5610,6 +5703,9 @@ class List extends ListLite {
5610
5703
  this.ctx.editorOpen();
5611
5704
  this.$closeCommentBtn.innerHTML = this.$t("closeComment");
5612
5705
  }
5706
+ if (this.ctx.conf.listSort) {
5707
+ this.initDropdown();
5708
+ }
5613
5709
  }
5614
5710
  onLoad(data, offset) {
5615
5711
  super.onLoad(data, offset);
@@ -5683,6 +5779,9 @@ class List extends ListLite {
5683
5779
  }
5684
5780
  }
5685
5781
  initDropdown() {
5782
+ if (this.dropdownLoaded)
5783
+ return;
5784
+ this.dropdownLoaded = true;
5686
5785
  this.$dropdownWrap = this.$commentCount;
5687
5786
  this.$commentCount.classList.add("atk-dropdown-wrap");
5688
5787
  this.$dropdownWrap.append(createElement(`<span class="atk-arrow-down-icon"></span>`));
@@ -5763,6 +5862,8 @@ class Context {
5763
5862
  __publicField(this, "markedReplacers", []);
5764
5863
  __publicField(this, "commentList", []);
5765
5864
  __publicField(this, "eventList", []);
5865
+ __publicField(this, "darkModeMedia", window.matchMedia("(prefers-color-scheme: dark)"));
5866
+ __publicField(this, "darkModeAutoFunc");
5766
5867
  this.cid = +new Date();
5767
5868
  this.conf = conf;
5768
5869
  this.user = new User(this);
@@ -5771,6 +5872,9 @@ class Context {
5771
5872
  this.$root.classList.add("artalk");
5772
5873
  this.$root.innerHTML = "";
5773
5874
  this.api = new Api(this);
5875
+ this.on("conf-loaded", () => {
5876
+ this.refreshDarkModeConf();
5877
+ });
5774
5878
  }
5775
5879
  setApi(api) {
5776
5880
  this.api = api;
@@ -5932,21 +6036,42 @@ class Context {
5932
6036
  return getI18n(this.conf.locale, key, args);
5933
6037
  }
5934
6038
  setDarkMode(darkMode) {
6039
+ if (this.conf.darkMode === darkMode)
6040
+ return;
5935
6041
  const darkModeClassName = "atk-dark-mode";
5936
6042
  this.conf.darkMode = darkMode;
5937
- this.trigger("conf-updated");
5938
- if (this.conf.darkMode)
6043
+ if (darkMode)
5939
6044
  this.$root.classList.add(darkModeClassName);
5940
6045
  else
5941
6046
  this.$root.classList.remove(darkModeClassName);
5942
6047
  const { $wrap: $layerWrap } = GetLayerWrap(this);
5943
6048
  if ($layerWrap) {
5944
- if (this.conf.darkMode)
6049
+ if (darkMode)
5945
6050
  $layerWrap.classList.add(darkModeClassName);
5946
6051
  else
5947
6052
  $layerWrap.classList.remove(darkModeClassName);
5948
6053
  }
5949
6054
  }
6055
+ refreshDarkModeConf() {
6056
+ if (this.conf.darkMode === "auto") {
6057
+ this.setDarkMode(this.darkModeMedia.matches);
6058
+ if (!this.darkModeAutoFunc) {
6059
+ this.darkModeAutoFunc = (evt) => {
6060
+ this.setDarkMode(evt.matches);
6061
+ };
6062
+ this.darkModeMedia.addEventListener("change", this.darkModeAutoFunc);
6063
+ }
6064
+ } else {
6065
+ if (this.darkModeAutoFunc) {
6066
+ this.darkModeMedia.removeEventListener("change", this.darkModeAutoFunc);
6067
+ }
6068
+ this.setDarkMode(this.conf.darkMode || false);
6069
+ }
6070
+ }
6071
+ updateConf(conf) {
6072
+ this.conf = mergeDeep(this.conf, conf);
6073
+ this.trigger("conf-loaded");
6074
+ }
5950
6075
  }
5951
6076
  const defaults = {
5952
6077
  el: "",
@@ -5972,7 +6097,7 @@ const defaults = {
5972
6097
  pvEl: "#ArtalkPV",
5973
6098
  gravatar: {
5974
6099
  default: "mp",
5975
- mirror: "https://sdn.geekzu.org/avatar/"
6100
+ mirror: "https://cravatar.cn/avatar/"
5976
6101
  },
5977
6102
  pagination: {
5978
6103
  pageSize: 20,
@@ -5986,7 +6111,7 @@ const defaults = {
5986
6111
  imgUpload: true,
5987
6112
  reqTimeout: 15e3,
5988
6113
  versionCheck: true,
5989
- useBackendConf: false,
6114
+ useBackendConf: true,
5990
6115
  locale: "zh-CN"
5991
6116
  };
5992
6117
  class Dialog {
@@ -6102,6 +6227,7 @@ const CaptchaChecker = {
6102
6227
  },
6103
6228
  onError(that, ctx, err, inputVal, formEl) {
6104
6229
  formEl.querySelector(".atk-captcha-img").click();
6230
+ formEl.querySelector('input[type="text"]').value = "";
6105
6231
  }
6106
6232
  };
6107
6233
  const AdminChecker = {
@@ -6112,7 +6238,10 @@ const AdminChecker = {
6112
6238
  email: that.ctx.user.data.email,
6113
6239
  password: inputVal
6114
6240
  };
6115
- return that.ctx.getApi().user.login(data.name, data.email, data.password);
6241
+ return (() => __async(this, null, function* () {
6242
+ const resp = yield that.ctx.getApi().user.login(data.name, data.email, data.password);
6243
+ return resp.token;
6244
+ }))();
6116
6245
  },
6117
6246
  body(that, ctx) {
6118
6247
  return createElement(`<span>${that.ctx.$t("adminCheck")}</span>`);
@@ -6526,7 +6655,7 @@ class UploadPlug extends EditorPlug {
6526
6655
  };
6527
6656
  $input.click();
6528
6657
  };
6529
- this.ctx.on("conf-updated", () => {
6658
+ this.ctx.on("conf-loaded", () => {
6530
6659
  if (!this.ctx.conf.imgUpload) {
6531
6660
  this.getBtn().setAttribute("atk-only-admin-show", "");
6532
6661
  this.ctx.checkAdminShowEl();
@@ -6721,12 +6850,12 @@ class Editor extends Component {
6721
6850
  this.$notifyWrap = this.$el.querySelector(".atk-notify-wrap");
6722
6851
  this.$plugBtnWrap = this.$el.querySelector(".atk-plug-btn-wrap");
6723
6852
  this.$plugPanelWrap = this.$el.querySelector(".atk-plug-panel-wrap");
6724
- this.initLocalStorage();
6725
- this.initHeader();
6726
- this.initTextarea();
6727
- this.initPlugs();
6728
- this.initSubmitBtn();
6729
- this.ctx.on("conf-updated", () => {
6853
+ this.ctx.on("conf-loaded", () => {
6854
+ this.initLocalStorage();
6855
+ this.initHeader();
6856
+ this.initTextarea();
6857
+ this.initSubmitBtn();
6858
+ this.initPlugs();
6730
6859
  });
6731
6860
  }
6732
6861
  get user() {
@@ -7116,9 +7245,6 @@ class SidebarLayer extends Component {
7116
7245
  };
7117
7246
  }
7118
7247
  this.layer.show();
7119
- setTimeout(() => {
7120
- this.$el.style.transform = "translate(0, 0)";
7121
- }, 20);
7122
7248
  (() => __async(this, null, function* () {
7123
7249
  var _a;
7124
7250
  const resp = yield this.ctx.getApi().user.loginStatus();
@@ -7136,7 +7262,6 @@ class SidebarLayer extends Component {
7136
7262
  });
7137
7263
  }
7138
7264
  }))();
7139
- this.ctx.updateNotifies([]);
7140
7265
  if (this.firstShow) {
7141
7266
  this.$iframeWrap.innerHTML = "";
7142
7267
  this.$iframe = createElement("<iframe></iframe>");
@@ -7162,6 +7287,12 @@ class SidebarLayer extends Component {
7162
7287
  if (!this.conf.darkMode && isIframeSrcDarkMode)
7163
7288
  this.iframeLoad(this.$iframe.src.replace("&darkMode=1", ""));
7164
7289
  }
7290
+ setTimeout(() => {
7291
+ this.$el.style.transform = "translate(0, 0)";
7292
+ }, 100);
7293
+ setTimeout(() => {
7294
+ this.ctx.updateNotifies([]);
7295
+ }, 0);
7165
7296
  this.ctx.trigger("sidebar-show");
7166
7297
  });
7167
7298
  }
@@ -7182,7 +7313,13 @@ class SidebarLayer extends Component {
7182
7313
  }
7183
7314
  }
7184
7315
  const PvCountWidget = (ctx) => {
7185
- initCountWidget({ ctx, pvAdd: true });
7316
+ if (!ctx.conf.useBackendConf) {
7317
+ initCountWidget({ ctx, pvAdd: true });
7318
+ } else {
7319
+ ctx.on("list-loaded", () => {
7320
+ initCountWidget({ ctx, pvAdd: true });
7321
+ });
7322
+ }
7186
7323
  };
7187
7324
  function initCountWidget(p) {
7188
7325
  return __async(this, null, function* () {
@@ -7229,14 +7366,11 @@ const _Artalk = class {
7229
7366
  if (this.conf.el instanceof HTMLElement)
7230
7367
  this.$root = this.conf.el;
7231
7368
  this.ctx = new Context(this.conf, this.$root);
7232
- if (this.conf.useBackendConf)
7233
- return this.loadConfRemoteAndInitComponents();
7234
7369
  this.initComponents();
7235
7370
  }
7236
7371
  initComponents() {
7237
7372
  this.initLocale();
7238
7373
  this.initLayer();
7239
- this.initDarkMode();
7240
7374
  initMarked(this.ctx);
7241
7375
  const Components = {
7242
7376
  checkerLauncher: () => {
@@ -7257,7 +7391,6 @@ const _Artalk = class {
7257
7391
  sidebarLayer: () => {
7258
7392
  const sidebarLayer = new SidebarLayer(this.ctx);
7259
7393
  this.ctx.setSidebarLayer(sidebarLayer);
7260
- this.$root.appendChild(sidebarLayer.$el);
7261
7394
  },
7262
7395
  eventsDefault: () => {
7263
7396
  this.initEventBind();
@@ -7295,26 +7428,6 @@ const _Artalk = class {
7295
7428
  }
7296
7429
  return conf;
7297
7430
  }
7298
- loadConfRemoteAndInitComponents() {
7299
- return __async(this, null, function* () {
7300
- yield this.loadConfRemote();
7301
- this.initComponents();
7302
- return this;
7303
- });
7304
- }
7305
- loadConfRemote() {
7306
- return __async(this, null, function* () {
7307
- showLoading(this.$root);
7308
- let backendConf = {};
7309
- try {
7310
- backendConf = yield this.ctx.getApi().system.conf();
7311
- } catch (err) {
7312
- console.error("Load config from remote err", err);
7313
- }
7314
- this.ctx.conf = mergeDeep(this.ctx.conf, backendConf);
7315
- hideLoading(this.$root);
7316
- });
7317
- }
7318
7431
  initEventBind() {
7319
7432
  window.addEventListener("hashchange", () => {
7320
7433
  this.ctx.listHashGotoCheck();
@@ -7333,17 +7446,6 @@ const _Artalk = class {
7333
7446
  Layer.BodyOrgOverflow = document.body.style.overflow;
7334
7447
  Layer.BodyOrgPaddingRight = document.body.style.paddingRight;
7335
7448
  }
7336
- initDarkMode() {
7337
- if (this.conf.darkMode === "auto") {
7338
- const darkModeMedia = window.matchMedia("(prefers-color-scheme: dark)");
7339
- darkModeMedia.addEventListener("change", (e) => {
7340
- this.setDarkMode(e.matches);
7341
- });
7342
- this.setDarkMode(darkModeMedia.matches);
7343
- } else {
7344
- this.setDarkMode(this.conf.darkMode || false);
7345
- }
7346
- }
7347
7449
  on(name, handler) {
7348
7450
  this.ctx.on(name, handler, "external");
7349
7451
  }