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
@@ -184,15 +184,19 @@ const internal = {
184
184
  "en-US": en,
185
185
  "zh-CN": zhCN
186
186
  };
187
+ const GLOBAL_LOCALES_KEY = "ArtalkI18n";
187
188
  function getLocaleSet(lang) {
188
189
  lang = lang.replace(
189
190
  /^([a-zA-Z]+)(-[a-zA-Z]+)?$/,
190
191
  (_, p1, p2) => p1.toLowerCase() + (p2 || "").toUpperCase()
191
192
  );
192
- if (!internal[lang]) {
193
- return internal.en;
193
+ if (internal[lang]) {
194
+ return internal[lang];
194
195
  }
195
- return internal[lang];
196
+ if (window[GLOBAL_LOCALES_KEY] && window[GLOBAL_LOCALES_KEY][lang]) {
197
+ return window[GLOBAL_LOCALES_KEY][lang];
198
+ }
199
+ return internal.en;
196
200
  }
197
201
  function getI18n(locale, key, args = {}) {
198
202
  if (typeof locale === "string") {
@@ -233,18 +237,6 @@ class User {
233
237
  return !!this.data.nick && !!this.data.email;
234
238
  }
235
239
  }
236
- class Component {
237
- constructor(ctx) {
238
- __publicField(this, "$el");
239
- __publicField(this, "ctx");
240
- __publicField(this, "conf");
241
- this.ctx = ctx;
242
- this.conf = ctx.conf;
243
- }
244
- $t(key, args = {}) {
245
- return this.ctx.$t(key, args);
246
- }
247
- }
248
240
  var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
249
241
  var escapes = {
250
242
  "&": "&",
@@ -852,7 +844,12 @@ function marked(ctx, src) {
852
844
  }
853
845
  let dest = insane_1(markedContent, {
854
846
  allowedClasses: {},
855
- allowedSchemes: ["http", "https", "mailto"],
847
+ allowedSchemes: [
848
+ "http",
849
+ "https",
850
+ "mailto",
851
+ "data"
852
+ ],
856
853
  allowedTags: [
857
854
  "a",
858
855
  "abbr",
@@ -989,6 +986,18 @@ function mergeDeep(target, source) {
989
986
  });
990
987
  return target;
991
988
  }
989
+ class Component {
990
+ constructor(ctx) {
991
+ __publicField(this, "$el");
992
+ __publicField(this, "ctx");
993
+ __publicField(this, "conf");
994
+ this.ctx = ctx;
995
+ this.conf = ctx.conf;
996
+ }
997
+ $t(key, args = {}) {
998
+ return this.ctx.$t(key, args);
999
+ }
1000
+ }
992
1001
  function showLoading(parentElem, conf) {
993
1002
  let $loading = parentElem.querySelector(":scope > .atk-loading");
994
1003
  if (!$loading) {
@@ -1906,7 +1915,7 @@ class UserApi extends ApiBase {
1906
1915
  if (this.ctx.conf.site)
1907
1916
  params.site_name = this.ctx.conf.site;
1908
1917
  const data = yield this.POST("/login", params);
1909
- return data.token;
1918
+ return data;
1910
1919
  });
1911
1920
  }
1912
1921
  userGet(name, email) {
@@ -1960,6 +1969,58 @@ class UserApi extends ApiBase {
1960
1969
  }
1961
1970
  return this.POST(`/mark-read`, params);
1962
1971
  }
1972
+ userList(offset, limit, type) {
1973
+ return __async(this, null, function* () {
1974
+ const params = {
1975
+ offset: offset || 0,
1976
+ limit: limit || 15
1977
+ };
1978
+ if (type)
1979
+ params.type = type;
1980
+ const d = yield this.POST("/admin/user-get", params);
1981
+ return d;
1982
+ });
1983
+ }
1984
+ userAdd(user, password) {
1985
+ return __async(this, null, function* () {
1986
+ const params = {
1987
+ name: user.name || "",
1988
+ email: user.email || "",
1989
+ password: password || "",
1990
+ link: user.link || "",
1991
+ is_admin: user.is_admin || false,
1992
+ site_names: user.site_names_raw || "",
1993
+ receive_email: user.receive_email || true,
1994
+ badge_name: user.badge_name || "",
1995
+ badge_color: user.badge_color || ""
1996
+ };
1997
+ const d = yield this.POST("/admin/user-add", params);
1998
+ return d.user;
1999
+ });
2000
+ }
2001
+ userEdit(user, password) {
2002
+ return __async(this, null, function* () {
2003
+ const params = {
2004
+ id: user.id,
2005
+ name: user.name || "",
2006
+ email: user.email || "",
2007
+ password: password || "",
2008
+ link: user.link || "",
2009
+ is_admin: user.is_admin || false,
2010
+ site_names: user.site_names_raw || "",
2011
+ receive_email: user.receive_email || true,
2012
+ badge_name: user.badge_name || "",
2013
+ badge_color: user.badge_color || ""
2014
+ };
2015
+ const d = yield this.POST("/admin/user-edit", params);
2016
+ return d.user;
2017
+ });
2018
+ }
2019
+ userDel(userID) {
2020
+ return this.POST("/admin/user-del", {
2021
+ id: String(userID)
2022
+ });
2023
+ }
1963
2024
  }
1964
2025
  class SystemApi extends ApiBase {
1965
2026
  conf() {
@@ -1991,6 +2052,13 @@ class SystemApi extends ApiBase {
1991
2052
  return data;
1992
2053
  });
1993
2054
  }
2055
+ version() {
2056
+ return __async(this, null, function* () {
2057
+ const resp = yield fetch(`${this.api.baseURL}/version`, { method: "POST" });
2058
+ const data = yield resp.json();
2059
+ return data;
2060
+ });
2061
+ }
1994
2062
  }
1995
2063
  class CaptchaApi extends ApiBase {
1996
2064
  captchaGet() {
@@ -2056,16 +2124,17 @@ const ApiComponents = {
2056
2124
  class Api {
2057
2125
  constructor(ctx) {
2058
2126
  __publicField(this, "ctx");
2059
- __publicField(this, "baseURL");
2060
2127
  this.ctx = ctx;
2061
- this.baseURL = `${ctx.conf.server}/api`;
2062
2128
  Object.entries(ApiComponents).forEach(([key, ApiComponent]) => {
2063
2129
  this[key] = new ApiComponent(this, this.ctx);
2064
2130
  });
2065
2131
  }
2132
+ get baseURL() {
2133
+ return `${this.ctx.conf.server}/api`;
2134
+ }
2066
2135
  }
2067
- const version = "2.4.1";
2068
- const backendMinVersion = "2.2.0";
2136
+ const version = "2.4.3";
2137
+ const backendMinVersion = "2.3.0";
2069
2138
  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';
2070
2139
  const win = window || {};
2071
2140
  const nav = navigator || {};
@@ -2424,7 +2493,8 @@ class CommentRender {
2424
2493
  renderAvatar() {
2425
2494
  const $avatar = this.$el.querySelector(".atk-avatar");
2426
2495
  const $avatarImg = createElement("<img />");
2427
- $avatarImg.src = this.comment.getGravatarURL();
2496
+ const avatarURLBuilder = this.ctx.conf.avatarURLBuilder;
2497
+ $avatarImg.src = avatarURLBuilder ? avatarURLBuilder(this.data) : this.comment.getGravatarURL();
2428
2498
  if (this.data.link) {
2429
2499
  const $avatarA = createElement('<a target="_blank" rel="noreferrer noopener nofollow"></a>');
2430
2500
  $avatarA.href = isValidURL(this.data.link) ? this.data.link : `https://${this.data.link}`;
@@ -3210,10 +3280,10 @@ class ListLite extends Component {
3210
3280
  __publicField(this, "data");
3211
3281
  __publicField(this, "isLoading", false);
3212
3282
  __publicField(this, "noCommentText");
3213
- __publicField(this, "flatMode", false);
3214
- __publicField(this, "nestSortBy");
3215
- __publicField(this, "pageMode", "pagination");
3216
- __publicField(this, "pageSize", 20);
3283
+ __publicField(this, "_nestSortBy");
3284
+ __publicField(this, "_flatMode");
3285
+ __publicField(this, "_pageMode");
3286
+ __publicField(this, "_pageSize");
3217
3287
  __publicField(this, "scrollListenerAt");
3218
3288
  __publicField(this, "repositionAt");
3219
3289
  __publicField(this, "pagination");
@@ -3224,20 +3294,53 @@ class ListLite extends Component {
3224
3294
  __publicField(this, "onAfterLoad");
3225
3295
  __publicField(this, "unread", []);
3226
3296
  __publicField(this, "unreadHighlight");
3297
+ __publicField(this, "confLoaded", false);
3227
3298
  this.$el = createElement(
3228
3299
  `<div class="atk-list-lite">
3229
3300
  <div class="atk-list-comments-wrap"></div>
3230
3301
  </div>`
3231
3302
  );
3232
3303
  this.$commentsWrap = this.$el.querySelector(".atk-list-comments-wrap");
3233
- this.noCommentText = ctx.conf.noComment || ctx.$t("noComment");
3234
- this.nestSortBy = this.ctx.conf.nestSort || "DATE_ASC";
3235
3304
  window.setInterval(() => {
3236
3305
  this.$el.querySelectorAll("[data-atk-comment-date]").forEach((el) => {
3237
3306
  const date = el.getAttribute("data-atk-comment-date");
3238
3307
  el.innerText = timeAgo(new Date(Number(date)), this.ctx);
3239
3308
  });
3240
3309
  }, 30 * 1e3);
3310
+ this.ctx.on("conf-loaded", () => {
3311
+ });
3312
+ }
3313
+ get nestSortBy() {
3314
+ if (this._nestSortBy !== void 0)
3315
+ return this._nestSortBy;
3316
+ return this.ctx.conf.nestSort || "DATE_ASC";
3317
+ }
3318
+ set nestSortBy(val) {
3319
+ this._nestSortBy = val;
3320
+ }
3321
+ get flatMode() {
3322
+ if (this._flatMode !== void 0)
3323
+ return this._flatMode;
3324
+ if (this.ctx.conf.flatMode === true || Number(this.ctx.conf.nestMax) <= 1)
3325
+ return true;
3326
+ if (this.ctx.conf.flatMode === "auto" && window.matchMedia("(max-width: 768px)").matches)
3327
+ return true;
3328
+ return false;
3329
+ }
3330
+ set flatMode(val) {
3331
+ this._flatMode = val;
3332
+ }
3333
+ get pageMode() {
3334
+ return this._pageMode || (this.conf.pagination.readMore ? "read-more" : "pagination");
3335
+ }
3336
+ set pageMode(val) {
3337
+ this._pageMode = val;
3338
+ }
3339
+ get pageSize() {
3340
+ return this._pageSize || this.conf.pagination.pageSize;
3341
+ }
3342
+ set pageSize(val) {
3343
+ this._pageSize = val;
3241
3344
  }
3242
3345
  getData() {
3243
3346
  return this.data;
@@ -3265,7 +3368,7 @@ class ListLite extends Component {
3265
3368
  const setLoading2 = (val) => this.setLoading(val, isFirstLoad);
3266
3369
  setLoading2(true);
3267
3370
  this.ctx.trigger("list-load");
3268
- if (isFirstLoad && this.pageMode === "read-more") {
3371
+ if (this.pageMode === "read-more" && isFirstLoad || this.pageMode === "pagination") {
3269
3372
  this.ctx.clearAllComments();
3270
3373
  }
3271
3374
  let listData;
@@ -3290,24 +3393,24 @@ class ListLite extends Component {
3290
3393
  }
3291
3394
  onLoad(data, offset) {
3292
3395
  var _a, _b;
3293
- if (this.pageMode === "pagination") {
3294
- this.ctx.clearAllComments();
3295
- }
3296
3396
  this.data = data;
3397
+ if (!this.confLoaded) {
3398
+ if (this.conf.useBackendConf)
3399
+ this.ctx.updateConf(data.conf.frontend_conf);
3400
+ else
3401
+ this.ctx.updateConf({});
3402
+ this.confLoaded = true;
3403
+ }
3297
3404
  const feMinVersion = ((_a = data.api_version) == null ? void 0 : _a.fe_min_version) || "0.0.0";
3298
3405
  if (this.ctx.conf.versionCheck && this.versionCheck("frontend", feMinVersion, version))
3299
3406
  return;
3300
3407
  if (this.ctx.conf.versionCheck && this.versionCheck("backend", backendMinVersion, (_b = data.api_version) == null ? void 0 : _b.version))
3301
3408
  return;
3302
- if (data.conf && typeof data.conf.img_upload === "boolean") {
3303
- this.ctx.conf.imgUpload = data.conf.img_upload;
3304
- }
3305
3409
  this.importComments(data.comments);
3306
3410
  this.refreshPagination(offset, this.flatMode ? data.total : data.total_roots);
3307
3411
  this.refreshUI();
3308
3412
  this.ctx.updateNotifies(data.unread || []);
3309
3413
  this.ctx.trigger("list-loaded");
3310
- this.ctx.trigger("conf-updated");
3311
3414
  if (this.onAfterLoad)
3312
3415
  this.onAfterLoad(data);
3313
3416
  }
@@ -3371,6 +3474,9 @@ class ListLite extends Component {
3371
3474
  }
3372
3475
  onError(msg, offset, errData) {
3373
3476
  var _a;
3477
+ if (!this.confLoaded) {
3478
+ this.ctx.updateConf({});
3479
+ }
3374
3480
  msg = String(msg);
3375
3481
  console.error(msg);
3376
3482
  if (offset !== 0 && this.pageMode === "read-more") {
@@ -3404,7 +3510,7 @@ class ListLite extends Component {
3404
3510
  if (isNoComment) {
3405
3511
  if (!$noComment) {
3406
3512
  $noComment = createElement('<div class="atk-list-no-comment"></div>');
3407
- $noComment.innerHTML = this.noCommentText;
3513
+ $noComment.innerHTML = this.noCommentText || this.ctx.conf.noComment || this.ctx.$t("noComment");
3408
3514
  this.$commentsWrap.appendChild($noComment);
3409
3515
  }
3410
3516
  } else {
@@ -3534,7 +3640,6 @@ class ListLite extends Component {
3534
3640
  ignoreBtn.onclick = () => {
3535
3641
  setError(this.$el.parentElement, null);
3536
3642
  this.ctx.conf.versionCheck = false;
3537
- this.ctx.trigger("conf-updated");
3538
3643
  this.fetchComments(0);
3539
3644
  };
3540
3645
  errEl.append(ignoreBtn);
@@ -3555,18 +3660,9 @@ class List extends ListLite {
3555
3660
  __publicField(this, "$dropdownWrap");
3556
3661
  __publicField(this, "goToCommentFounded", false);
3557
3662
  __publicField(this, "goToCommentDelay", true);
3663
+ __publicField(this, "dropdownLoaded", false);
3558
3664
  el.querySelector(".atk-list-body").append(this.$el);
3559
3665
  this.$el = el;
3560
- if (this.ctx.conf.flatMode === true) {
3561
- this.flatMode = true;
3562
- } else if (this.conf.nestMax && this.conf.nestMax <= 1) {
3563
- this.flatMode = true;
3564
- } else if (this.ctx.conf.flatMode === "auto") {
3565
- if (window.matchMedia("(max-width: 768px)").matches)
3566
- this.flatMode = true;
3567
- }
3568
- this.pageMode = this.conf.pagination.readMore ? "read-more" : "pagination";
3569
- this.pageSize = this.conf.pagination.pageSize || 20;
3570
3666
  this.repositionAt = this.$el;
3571
3667
  this.initListActionBtn();
3572
3668
  this.$commentCount = this.$el.querySelector(".atk-comment-count");
@@ -3574,9 +3670,6 @@ class List extends ListLite {
3574
3670
  count: '<span class="atk-comment-count-num">0</span>'
3575
3671
  });
3576
3672
  this.$commentCountNum = this.$commentCount.querySelector(".atk-comment-count-num");
3577
- if (this.ctx.conf.listSort) {
3578
- this.initDropdown();
3579
- }
3580
3673
  this.$el.querySelector(".atk-copyright").innerHTML = `Powered By <a href="https://artalk.js.org" target="_blank" title="Artalk v${version}">Artalk</a>`;
3581
3674
  }
3582
3675
  initListActionBtn() {
@@ -3611,6 +3704,9 @@ class List extends ListLite {
3611
3704
  this.ctx.editorOpen();
3612
3705
  this.$closeCommentBtn.innerHTML = this.$t("closeComment");
3613
3706
  }
3707
+ if (this.ctx.conf.listSort) {
3708
+ this.initDropdown();
3709
+ }
3614
3710
  }
3615
3711
  onLoad(data, offset) {
3616
3712
  super.onLoad(data, offset);
@@ -3684,6 +3780,9 @@ class List extends ListLite {
3684
3780
  }
3685
3781
  }
3686
3782
  initDropdown() {
3783
+ if (this.dropdownLoaded)
3784
+ return;
3785
+ this.dropdownLoaded = true;
3687
3786
  this.$dropdownWrap = this.$commentCount;
3688
3787
  this.$commentCount.classList.add("atk-dropdown-wrap");
3689
3788
  this.$dropdownWrap.append(createElement(`<span class="atk-arrow-down-icon"></span>`));
@@ -3764,6 +3863,8 @@ class Context {
3764
3863
  __publicField(this, "markedReplacers", []);
3765
3864
  __publicField(this, "commentList", []);
3766
3865
  __publicField(this, "eventList", []);
3866
+ __publicField(this, "darkModeMedia", window.matchMedia("(prefers-color-scheme: dark)"));
3867
+ __publicField(this, "darkModeAutoFunc");
3767
3868
  this.cid = +new Date();
3768
3869
  this.conf = conf;
3769
3870
  this.user = new User(this);
@@ -3772,6 +3873,9 @@ class Context {
3772
3873
  this.$root.classList.add("artalk");
3773
3874
  this.$root.innerHTML = "";
3774
3875
  this.api = new Api(this);
3876
+ this.on("conf-loaded", () => {
3877
+ this.refreshDarkModeConf();
3878
+ });
3775
3879
  }
3776
3880
  setApi(api) {
3777
3881
  this.api = api;
@@ -3933,21 +4037,42 @@ class Context {
3933
4037
  return getI18n(this.conf.locale, key, args);
3934
4038
  }
3935
4039
  setDarkMode(darkMode) {
4040
+ if (this.conf.darkMode === darkMode)
4041
+ return;
3936
4042
  const darkModeClassName = "atk-dark-mode";
3937
4043
  this.conf.darkMode = darkMode;
3938
- this.trigger("conf-updated");
3939
- if (this.conf.darkMode)
4044
+ if (darkMode)
3940
4045
  this.$root.classList.add(darkModeClassName);
3941
4046
  else
3942
4047
  this.$root.classList.remove(darkModeClassName);
3943
4048
  const { $wrap: $layerWrap } = GetLayerWrap(this);
3944
4049
  if ($layerWrap) {
3945
- if (this.conf.darkMode)
4050
+ if (darkMode)
3946
4051
  $layerWrap.classList.add(darkModeClassName);
3947
4052
  else
3948
4053
  $layerWrap.classList.remove(darkModeClassName);
3949
4054
  }
3950
4055
  }
4056
+ refreshDarkModeConf() {
4057
+ if (this.conf.darkMode === "auto") {
4058
+ this.setDarkMode(this.darkModeMedia.matches);
4059
+ if (!this.darkModeAutoFunc) {
4060
+ this.darkModeAutoFunc = (evt) => {
4061
+ this.setDarkMode(evt.matches);
4062
+ };
4063
+ this.darkModeMedia.addEventListener("change", this.darkModeAutoFunc);
4064
+ }
4065
+ } else {
4066
+ if (this.darkModeAutoFunc) {
4067
+ this.darkModeMedia.removeEventListener("change", this.darkModeAutoFunc);
4068
+ }
4069
+ this.setDarkMode(this.conf.darkMode || false);
4070
+ }
4071
+ }
4072
+ updateConf(conf) {
4073
+ this.conf = mergeDeep(this.conf, conf);
4074
+ this.trigger("conf-loaded");
4075
+ }
3951
4076
  }
3952
4077
  const defaults = {
3953
4078
  el: "",
@@ -3973,7 +4098,7 @@ const defaults = {
3973
4098
  pvEl: "#ArtalkPV",
3974
4099
  gravatar: {
3975
4100
  default: "mp",
3976
- mirror: "https://sdn.geekzu.org/avatar/"
4101
+ mirror: "https://cravatar.cn/avatar/"
3977
4102
  },
3978
4103
  pagination: {
3979
4104
  pageSize: 20,
@@ -3987,7 +4112,7 @@ const defaults = {
3987
4112
  imgUpload: true,
3988
4113
  reqTimeout: 15e3,
3989
4114
  versionCheck: true,
3990
- useBackendConf: false,
4115
+ useBackendConf: true,
3991
4116
  locale: "zh-CN"
3992
4117
  };
3993
4118
  {
@@ -4108,6 +4233,7 @@ const CaptchaChecker = {
4108
4233
  },
4109
4234
  onError(that, ctx, err, inputVal, formEl) {
4110
4235
  formEl.querySelector(".atk-captcha-img").click();
4236
+ formEl.querySelector('input[type="text"]').value = "";
4111
4237
  }
4112
4238
  };
4113
4239
  const AdminChecker = {
@@ -4118,7 +4244,10 @@ const AdminChecker = {
4118
4244
  email: that.ctx.user.data.email,
4119
4245
  password: inputVal
4120
4246
  };
4121
- return that.ctx.getApi().user.login(data.name, data.email, data.password);
4247
+ return (() => __async(this, null, function* () {
4248
+ const resp = yield that.ctx.getApi().user.login(data.name, data.email, data.password);
4249
+ return resp.token;
4250
+ }))();
4122
4251
  },
4123
4252
  body(that, ctx) {
4124
4253
  return createElement(`<span>${that.ctx.$t("adminCheck")}</span>`);
@@ -4532,7 +4661,7 @@ class UploadPlug extends EditorPlug {
4532
4661
  };
4533
4662
  $input.click();
4534
4663
  };
4535
- this.ctx.on("conf-updated", () => {
4664
+ this.ctx.on("conf-loaded", () => {
4536
4665
  if (!this.ctx.conf.imgUpload) {
4537
4666
  this.getBtn().setAttribute("atk-only-admin-show", "");
4538
4667
  this.ctx.checkAdminShowEl();
@@ -4727,12 +4856,12 @@ class Editor extends Component {
4727
4856
  this.$notifyWrap = this.$el.querySelector(".atk-notify-wrap");
4728
4857
  this.$plugBtnWrap = this.$el.querySelector(".atk-plug-btn-wrap");
4729
4858
  this.$plugPanelWrap = this.$el.querySelector(".atk-plug-panel-wrap");
4730
- this.initLocalStorage();
4731
- this.initHeader();
4732
- this.initTextarea();
4733
- this.initPlugs();
4734
- this.initSubmitBtn();
4735
- this.ctx.on("conf-updated", () => {
4859
+ this.ctx.on("conf-loaded", () => {
4860
+ this.initLocalStorage();
4861
+ this.initHeader();
4862
+ this.initTextarea();
4863
+ this.initSubmitBtn();
4864
+ this.initPlugs();
4736
4865
  });
4737
4866
  }
4738
4867
  get user() {
@@ -5122,9 +5251,6 @@ class SidebarLayer extends Component {
5122
5251
  };
5123
5252
  }
5124
5253
  this.layer.show();
5125
- setTimeout(() => {
5126
- this.$el.style.transform = "translate(0, 0)";
5127
- }, 20);
5128
5254
  (() => __async(this, null, function* () {
5129
5255
  var _a;
5130
5256
  const resp = yield this.ctx.getApi().user.loginStatus();
@@ -5142,7 +5268,6 @@ class SidebarLayer extends Component {
5142
5268
  });
5143
5269
  }
5144
5270
  }))();
5145
- this.ctx.updateNotifies([]);
5146
5271
  if (this.firstShow) {
5147
5272
  this.$iframeWrap.innerHTML = "";
5148
5273
  this.$iframe = createElement("<iframe></iframe>");
@@ -5168,6 +5293,12 @@ class SidebarLayer extends Component {
5168
5293
  if (!this.conf.darkMode && isIframeSrcDarkMode)
5169
5294
  this.iframeLoad(this.$iframe.src.replace("&darkMode=1", ""));
5170
5295
  }
5296
+ setTimeout(() => {
5297
+ this.$el.style.transform = "translate(0, 0)";
5298
+ }, 100);
5299
+ setTimeout(() => {
5300
+ this.ctx.updateNotifies([]);
5301
+ }, 0);
5171
5302
  this.ctx.trigger("sidebar-show");
5172
5303
  });
5173
5304
  }
@@ -5188,7 +5319,13 @@ class SidebarLayer extends Component {
5188
5319
  }
5189
5320
  }
5190
5321
  const PvCountWidget = (ctx) => {
5191
- initCountWidget({ ctx, pvAdd: true });
5322
+ if (!ctx.conf.useBackendConf) {
5323
+ initCountWidget({ ctx, pvAdd: true });
5324
+ } else {
5325
+ ctx.on("list-loaded", () => {
5326
+ initCountWidget({ ctx, pvAdd: true });
5327
+ });
5328
+ }
5192
5329
  };
5193
5330
  function initCountWidget(p) {
5194
5331
  return __async(this, null, function* () {
@@ -5235,14 +5372,11 @@ const _Artalk = class {
5235
5372
  if (this.conf.el instanceof HTMLElement)
5236
5373
  this.$root = this.conf.el;
5237
5374
  this.ctx = new Context(this.conf, this.$root);
5238
- if (this.conf.useBackendConf)
5239
- return this.loadConfRemoteAndInitComponents();
5240
5375
  this.initComponents();
5241
5376
  }
5242
5377
  initComponents() {
5243
5378
  this.initLocale();
5244
5379
  this.initLayer();
5245
- this.initDarkMode();
5246
5380
  initMarked(this.ctx);
5247
5381
  const Components = {
5248
5382
  checkerLauncher: () => {
@@ -5263,7 +5397,6 @@ const _Artalk = class {
5263
5397
  sidebarLayer: () => {
5264
5398
  const sidebarLayer = new SidebarLayer(this.ctx);
5265
5399
  this.ctx.setSidebarLayer(sidebarLayer);
5266
- this.$root.appendChild(sidebarLayer.$el);
5267
5400
  },
5268
5401
  eventsDefault: () => {
5269
5402
  this.initEventBind();
@@ -5301,26 +5434,6 @@ const _Artalk = class {
5301
5434
  }
5302
5435
  return conf;
5303
5436
  }
5304
- loadConfRemoteAndInitComponents() {
5305
- return __async(this, null, function* () {
5306
- yield this.loadConfRemote();
5307
- this.initComponents();
5308
- return this;
5309
- });
5310
- }
5311
- loadConfRemote() {
5312
- return __async(this, null, function* () {
5313
- showLoading(this.$root);
5314
- let backendConf = {};
5315
- try {
5316
- backendConf = yield this.ctx.getApi().system.conf();
5317
- } catch (err) {
5318
- console.error("Load config from remote err", err);
5319
- }
5320
- this.ctx.conf = mergeDeep(this.ctx.conf, backendConf);
5321
- hideLoading(this.$root);
5322
- });
5323
- }
5324
5437
  initEventBind() {
5325
5438
  window.addEventListener("hashchange", () => {
5326
5439
  this.ctx.listHashGotoCheck();
@@ -5339,17 +5452,6 @@ const _Artalk = class {
5339
5452
  Layer.BodyOrgOverflow = document.body.style.overflow;
5340
5453
  Layer.BodyOrgPaddingRight = document.body.style.paddingRight;
5341
5454
  }
5342
- initDarkMode() {
5343
- if (this.conf.darkMode === "auto") {
5344
- const darkModeMedia = window.matchMedia("(prefers-color-scheme: dark)");
5345
- darkModeMedia.addEventListener("change", (e) => {
5346
- this.setDarkMode(e.matches);
5347
- });
5348
- this.setDarkMode(darkModeMedia.matches);
5349
- } else {
5350
- this.setDarkMode(this.conf.darkMode || false);
5351
- }
5352
- }
5353
5455
  on(name, handler) {
5354
5456
  this.ctx.on(name, handler, "external");
5355
5457
  }