artalk 2.4.2 → 2.4.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.
package/dist/Artalk.es.js CHANGED
@@ -236,18 +236,6 @@ class User {
236
236
  return !!this.data.nick && !!this.data.email;
237
237
  }
238
238
  }
239
- class Component {
240
- constructor(ctx) {
241
- __publicField(this, "$el");
242
- __publicField(this, "ctx");
243
- __publicField(this, "conf");
244
- this.ctx = ctx;
245
- this.conf = ctx.conf;
246
- }
247
- $t(key, args = {}) {
248
- return this.ctx.$t(key, args);
249
- }
250
- }
251
239
  function getDefaults() {
252
240
  return {
253
241
  baseUrl: null,
@@ -2855,7 +2843,12 @@ function marked(ctx, src) {
2855
2843
  }
2856
2844
  let dest = insane_1(markedContent, {
2857
2845
  allowedClasses: {},
2858
- allowedSchemes: ["http", "https", "mailto"],
2846
+ allowedSchemes: [
2847
+ "http",
2848
+ "https",
2849
+ "mailto",
2850
+ "data"
2851
+ ],
2859
2852
  allowedTags: [
2860
2853
  "a",
2861
2854
  "abbr",
@@ -2992,6 +2985,18 @@ function mergeDeep(target, source) {
2992
2985
  });
2993
2986
  return target;
2994
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
+ }
2995
3000
  function showLoading(parentElem, conf) {
2996
3001
  let $loading = parentElem.querySelector(":scope > .atk-loading");
2997
3002
  if (!$loading) {
@@ -3271,6 +3276,9 @@ function GetLayerWrap(ctx) {
3271
3276
  _defineProperties(Constructor.prototype, protoProps);
3272
3277
  if (staticProps)
3273
3278
  _defineProperties(Constructor, staticProps);
3279
+ Object.defineProperty(Constructor, "prototype", {
3280
+ writable: false
3281
+ });
3274
3282
  return Constructor;
3275
3283
  }
3276
3284
  function _inherits(subClass, superClass) {
@@ -3284,17 +3292,20 @@ function GetLayerWrap(ctx) {
3284
3292
  configurable: true
3285
3293
  }
3286
3294
  });
3295
+ Object.defineProperty(subClass, "prototype", {
3296
+ writable: false
3297
+ });
3287
3298
  if (superClass)
3288
3299
  _setPrototypeOf(subClass, superClass);
3289
3300
  }
3290
3301
  function _getPrototypeOf(o) {
3291
- _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf2(o2) {
3302
+ _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf2(o2) {
3292
3303
  return o2.__proto__ || Object.getPrototypeOf(o2);
3293
3304
  };
3294
3305
  return _getPrototypeOf(o);
3295
3306
  }
3296
3307
  function _setPrototypeOf(o, p) {
3297
- _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf2(o2, p2) {
3308
+ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf2(o2, p2) {
3298
3309
  o2.__proto__ = p2;
3299
3310
  return o2;
3300
3311
  };
@@ -3324,6 +3335,8 @@ function GetLayerWrap(ctx) {
3324
3335
  function _possibleConstructorReturn(self2, call) {
3325
3336
  if (call && (typeof call === "object" || typeof call === "function")) {
3326
3337
  return call;
3338
+ } else if (call !== void 0) {
3339
+ throw new TypeError("Derived constructors may only return object or undefined");
3327
3340
  }
3328
3341
  return _assertThisInitialized(self2);
3329
3342
  }
@@ -3348,22 +3361,22 @@ function GetLayerWrap(ctx) {
3348
3361
  }
3349
3362
  return object;
3350
3363
  }
3351
- function _get(target, property, receiver) {
3364
+ function _get() {
3352
3365
  if (typeof Reflect !== "undefined" && Reflect.get) {
3353
- _get = Reflect.get;
3366
+ _get = Reflect.get.bind();
3354
3367
  } else {
3355
- _get = function _get2(target2, property2, receiver2) {
3356
- var base = _superPropBase(target2, property2);
3368
+ _get = function _get2(target, property, receiver) {
3369
+ var base = _superPropBase(target, property);
3357
3370
  if (!base)
3358
3371
  return;
3359
- var desc = Object.getOwnPropertyDescriptor(base, property2);
3372
+ var desc = Object.getOwnPropertyDescriptor(base, property);
3360
3373
  if (desc.get) {
3361
- return desc.get.call(receiver2);
3374
+ return desc.get.call(arguments.length < 3 ? target : receiver);
3362
3375
  }
3363
3376
  return desc.value;
3364
3377
  };
3365
3378
  }
3366
- return _get(target, property, receiver || target);
3379
+ return _get.apply(this, arguments);
3367
3380
  }
3368
3381
  var Emitter = /* @__PURE__ */ function() {
3369
3382
  function Emitter2() {
@@ -3445,6 +3458,11 @@ function GetLayerWrap(ctx) {
3445
3458
  writable: true,
3446
3459
  configurable: true
3447
3460
  });
3461
+ Object.defineProperty(_assertThisInitialized(_this), "reason", {
3462
+ value: void 0,
3463
+ writable: true,
3464
+ configurable: true
3465
+ });
3448
3466
  return _this;
3449
3467
  }
3450
3468
  _createClass(AbortSignal2, [{
@@ -3477,7 +3495,7 @@ function GetLayerWrap(ctx) {
3477
3495
  }
3478
3496
  _createClass(AbortController3, [{
3479
3497
  key: "abort",
3480
- value: function abort() {
3498
+ value: function abort(reason) {
3481
3499
  var event;
3482
3500
  try {
3483
3501
  event = new Event("abort");
@@ -3498,6 +3516,21 @@ function GetLayerWrap(ctx) {
3498
3516
  };
3499
3517
  }
3500
3518
  }
3519
+ var signalReason = reason;
3520
+ if (signalReason === void 0) {
3521
+ if (typeof document === "undefined") {
3522
+ signalReason = new Error("This operation was aborted");
3523
+ signalReason.name = "AbortError";
3524
+ } else {
3525
+ try {
3526
+ signalReason = new DOMException("signal is aborted without reason");
3527
+ } catch (err) {
3528
+ signalReason = new Error("This operation was aborted");
3529
+ signalReason.name = "AbortError";
3530
+ }
3531
+ }
3532
+ }
3533
+ this.signal.reason = signalReason;
3501
3534
  this.signal.dispatchEvent(event);
3502
3535
  }
3503
3536
  }, {
@@ -3909,7 +3942,7 @@ class UserApi extends ApiBase {
3909
3942
  if (this.ctx.conf.site)
3910
3943
  params.site_name = this.ctx.conf.site;
3911
3944
  const data = yield this.POST("/login", params);
3912
- return data.token;
3945
+ return data;
3913
3946
  });
3914
3947
  }
3915
3948
  userGet(name, email) {
@@ -3963,6 +3996,58 @@ class UserApi extends ApiBase {
3963
3996
  }
3964
3997
  return this.POST(`/mark-read`, params);
3965
3998
  }
3999
+ userList(offset, limit, type) {
4000
+ return __async(this, null, function* () {
4001
+ const params = {
4002
+ offset: offset || 0,
4003
+ limit: limit || 15
4004
+ };
4005
+ if (type)
4006
+ params.type = type;
4007
+ const d = yield this.POST("/admin/user-get", params);
4008
+ return d;
4009
+ });
4010
+ }
4011
+ userAdd(user, password) {
4012
+ return __async(this, null, function* () {
4013
+ const params = {
4014
+ name: user.name || "",
4015
+ email: user.email || "",
4016
+ password: password || "",
4017
+ link: user.link || "",
4018
+ is_admin: user.is_admin || false,
4019
+ site_names: user.site_names_raw || "",
4020
+ receive_email: user.receive_email || true,
4021
+ badge_name: user.badge_name || "",
4022
+ badge_color: user.badge_color || ""
4023
+ };
4024
+ const d = yield this.POST("/admin/user-add", params);
4025
+ return d.user;
4026
+ });
4027
+ }
4028
+ userEdit(user, password) {
4029
+ return __async(this, null, function* () {
4030
+ const params = {
4031
+ id: user.id,
4032
+ name: user.name || "",
4033
+ email: user.email || "",
4034
+ password: password || "",
4035
+ link: user.link || "",
4036
+ is_admin: user.is_admin || false,
4037
+ site_names: user.site_names_raw || "",
4038
+ receive_email: user.receive_email || true,
4039
+ badge_name: user.badge_name || "",
4040
+ badge_color: user.badge_color || ""
4041
+ };
4042
+ const d = yield this.POST("/admin/user-edit", params);
4043
+ return d.user;
4044
+ });
4045
+ }
4046
+ userDel(userID) {
4047
+ return this.POST("/admin/user-del", {
4048
+ id: String(userID)
4049
+ });
4050
+ }
3966
4051
  }
3967
4052
  class SystemApi extends ApiBase {
3968
4053
  conf() {
@@ -3994,6 +4079,13 @@ class SystemApi extends ApiBase {
3994
4079
  return data;
3995
4080
  });
3996
4081
  }
4082
+ version() {
4083
+ return __async(this, null, function* () {
4084
+ const resp = yield fetch(`${this.api.baseURL}/version`, { method: "POST" });
4085
+ const data = yield resp.json();
4086
+ return data;
4087
+ });
4088
+ }
3997
4089
  }
3998
4090
  class CaptchaApi extends ApiBase {
3999
4091
  captchaGet() {
@@ -4059,16 +4151,17 @@ const ApiComponents = {
4059
4151
  class Api {
4060
4152
  constructor(ctx) {
4061
4153
  __publicField(this, "ctx");
4062
- __publicField(this, "baseURL");
4063
4154
  this.ctx = ctx;
4064
- this.baseURL = `${ctx.conf.server}/api`;
4065
4155
  Object.entries(ApiComponents).forEach(([key, ApiComponent]) => {
4066
4156
  this[key] = new ApiComponent(this, this.ctx);
4067
4157
  });
4068
4158
  }
4159
+ get baseURL() {
4160
+ return `${this.ctx.conf.server}/api`;
4161
+ }
4069
4162
  }
4070
- const version = "2.4.2";
4071
- const backendMinVersion = "2.2.0";
4163
+ const version = "2.4.4";
4164
+ const backendMinVersion = "2.3.0";
4072
4165
  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';
4073
4166
  const win = window || {};
4074
4167
  const nav = navigator || {};
@@ -4427,7 +4520,8 @@ class CommentRender {
4427
4520
  renderAvatar() {
4428
4521
  const $avatar = this.$el.querySelector(".atk-avatar");
4429
4522
  const $avatarImg = createElement("<img />");
4430
- $avatarImg.src = this.comment.getGravatarURL();
4523
+ const avatarURLBuilder = this.ctx.conf.avatarURLBuilder;
4524
+ $avatarImg.src = avatarURLBuilder ? avatarURLBuilder(this.data) : this.comment.getGravatarURL();
4431
4525
  if (this.data.link) {
4432
4526
  const $avatarA = createElement('<a target="_blank" rel="noreferrer noopener nofollow"></a>');
4433
4527
  $avatarA.href = isValidURL(this.data.link) ? this.data.link : `https://${this.data.link}`;
@@ -5213,10 +5307,10 @@ class ListLite extends Component {
5213
5307
  __publicField(this, "data");
5214
5308
  __publicField(this, "isLoading", false);
5215
5309
  __publicField(this, "noCommentText");
5216
- __publicField(this, "flatMode", false);
5217
- __publicField(this, "nestSortBy");
5218
- __publicField(this, "pageMode", "pagination");
5219
- __publicField(this, "pageSize", 20);
5310
+ __publicField(this, "_nestSortBy");
5311
+ __publicField(this, "_flatMode");
5312
+ __publicField(this, "_pageMode");
5313
+ __publicField(this, "_pageSize");
5220
5314
  __publicField(this, "scrollListenerAt");
5221
5315
  __publicField(this, "repositionAt");
5222
5316
  __publicField(this, "pagination");
@@ -5227,20 +5321,53 @@ class ListLite extends Component {
5227
5321
  __publicField(this, "onAfterLoad");
5228
5322
  __publicField(this, "unread", []);
5229
5323
  __publicField(this, "unreadHighlight");
5324
+ __publicField(this, "confLoaded", false);
5230
5325
  this.$el = createElement(
5231
5326
  `<div class="atk-list-lite">
5232
5327
  <div class="atk-list-comments-wrap"></div>
5233
5328
  </div>`
5234
5329
  );
5235
5330
  this.$commentsWrap = this.$el.querySelector(".atk-list-comments-wrap");
5236
- this.noCommentText = ctx.conf.noComment || ctx.$t("noComment");
5237
- this.nestSortBy = this.ctx.conf.nestSort || "DATE_ASC";
5238
5331
  window.setInterval(() => {
5239
5332
  this.$el.querySelectorAll("[data-atk-comment-date]").forEach((el) => {
5240
5333
  const date = el.getAttribute("data-atk-comment-date");
5241
5334
  el.innerText = timeAgo(new Date(Number(date)), this.ctx);
5242
5335
  });
5243
5336
  }, 30 * 1e3);
5337
+ this.ctx.on("conf-loaded", () => {
5338
+ });
5339
+ }
5340
+ get nestSortBy() {
5341
+ if (this._nestSortBy !== void 0)
5342
+ return this._nestSortBy;
5343
+ return this.ctx.conf.nestSort || "DATE_ASC";
5344
+ }
5345
+ set nestSortBy(val) {
5346
+ this._nestSortBy = val;
5347
+ }
5348
+ get flatMode() {
5349
+ if (this._flatMode !== void 0)
5350
+ return this._flatMode;
5351
+ if (this.ctx.conf.flatMode === true || Number(this.ctx.conf.nestMax) <= 1)
5352
+ return true;
5353
+ if (this.ctx.conf.flatMode === "auto" && window.matchMedia("(max-width: 768px)").matches)
5354
+ return true;
5355
+ return false;
5356
+ }
5357
+ set flatMode(val) {
5358
+ this._flatMode = val;
5359
+ }
5360
+ get pageMode() {
5361
+ return this._pageMode || (this.conf.pagination.readMore ? "read-more" : "pagination");
5362
+ }
5363
+ set pageMode(val) {
5364
+ this._pageMode = val;
5365
+ }
5366
+ get pageSize() {
5367
+ return this._pageSize || this.conf.pagination.pageSize;
5368
+ }
5369
+ set pageSize(val) {
5370
+ this._pageSize = val;
5244
5371
  }
5245
5372
  getData() {
5246
5373
  return this.data;
@@ -5268,7 +5395,7 @@ class ListLite extends Component {
5268
5395
  const setLoading2 = (val) => this.setLoading(val, isFirstLoad);
5269
5396
  setLoading2(true);
5270
5397
  this.ctx.trigger("list-load");
5271
- if (isFirstLoad && this.pageMode === "read-more") {
5398
+ if (this.pageMode === "read-more" && isFirstLoad || this.pageMode === "pagination") {
5272
5399
  this.ctx.clearAllComments();
5273
5400
  }
5274
5401
  let listData;
@@ -5293,24 +5420,24 @@ class ListLite extends Component {
5293
5420
  }
5294
5421
  onLoad(data, offset) {
5295
5422
  var _a, _b;
5296
- if (this.pageMode === "pagination") {
5297
- this.ctx.clearAllComments();
5298
- }
5299
5423
  this.data = data;
5424
+ if (!this.confLoaded) {
5425
+ if (this.conf.useBackendConf)
5426
+ this.ctx.updateConf(data.conf.frontend_conf);
5427
+ else
5428
+ this.ctx.updateConf({});
5429
+ this.confLoaded = true;
5430
+ }
5300
5431
  const feMinVersion = ((_a = data.api_version) == null ? void 0 : _a.fe_min_version) || "0.0.0";
5301
5432
  if (this.ctx.conf.versionCheck && this.versionCheck("frontend", feMinVersion, version))
5302
5433
  return;
5303
5434
  if (this.ctx.conf.versionCheck && this.versionCheck("backend", backendMinVersion, (_b = data.api_version) == null ? void 0 : _b.version))
5304
5435
  return;
5305
- if (data.conf && typeof data.conf.img_upload === "boolean") {
5306
- this.ctx.conf.imgUpload = data.conf.img_upload;
5307
- }
5308
5436
  this.importComments(data.comments);
5309
5437
  this.refreshPagination(offset, this.flatMode ? data.total : data.total_roots);
5310
5438
  this.refreshUI();
5311
5439
  this.ctx.updateNotifies(data.unread || []);
5312
5440
  this.ctx.trigger("list-loaded");
5313
- this.ctx.trigger("conf-updated");
5314
5441
  if (this.onAfterLoad)
5315
5442
  this.onAfterLoad(data);
5316
5443
  }
@@ -5374,6 +5501,9 @@ class ListLite extends Component {
5374
5501
  }
5375
5502
  onError(msg, offset, errData) {
5376
5503
  var _a;
5504
+ if (!this.confLoaded) {
5505
+ this.ctx.updateConf({});
5506
+ }
5377
5507
  msg = String(msg);
5378
5508
  console.error(msg);
5379
5509
  if (offset !== 0 && this.pageMode === "read-more") {
@@ -5407,7 +5537,7 @@ class ListLite extends Component {
5407
5537
  if (isNoComment) {
5408
5538
  if (!$noComment) {
5409
5539
  $noComment = createElement('<div class="atk-list-no-comment"></div>');
5410
- $noComment.innerHTML = this.noCommentText;
5540
+ $noComment.innerHTML = this.noCommentText || this.ctx.conf.noComment || this.ctx.$t("noComment");
5411
5541
  this.$commentsWrap.appendChild($noComment);
5412
5542
  }
5413
5543
  } else {
@@ -5537,7 +5667,6 @@ class ListLite extends Component {
5537
5667
  ignoreBtn.onclick = () => {
5538
5668
  setError(this.$el.parentElement, null);
5539
5669
  this.ctx.conf.versionCheck = false;
5540
- this.ctx.trigger("conf-updated");
5541
5670
  this.fetchComments(0);
5542
5671
  };
5543
5672
  errEl.append(ignoreBtn);
@@ -5558,18 +5687,9 @@ class List extends ListLite {
5558
5687
  __publicField(this, "$dropdownWrap");
5559
5688
  __publicField(this, "goToCommentFounded", false);
5560
5689
  __publicField(this, "goToCommentDelay", true);
5690
+ __publicField(this, "dropdownLoaded", false);
5561
5691
  el.querySelector(".atk-list-body").append(this.$el);
5562
5692
  this.$el = el;
5563
- if (this.ctx.conf.flatMode === true) {
5564
- this.flatMode = true;
5565
- } else if (this.conf.nestMax && this.conf.nestMax <= 1) {
5566
- this.flatMode = true;
5567
- } else if (this.ctx.conf.flatMode === "auto") {
5568
- if (window.matchMedia("(max-width: 768px)").matches)
5569
- this.flatMode = true;
5570
- }
5571
- this.pageMode = this.conf.pagination.readMore ? "read-more" : "pagination";
5572
- this.pageSize = this.conf.pagination.pageSize || 20;
5573
5693
  this.repositionAt = this.$el;
5574
5694
  this.initListActionBtn();
5575
5695
  this.$commentCount = this.$el.querySelector(".atk-comment-count");
@@ -5577,9 +5697,6 @@ class List extends ListLite {
5577
5697
  count: '<span class="atk-comment-count-num">0</span>'
5578
5698
  });
5579
5699
  this.$commentCountNum = this.$commentCount.querySelector(".atk-comment-count-num");
5580
- if (this.ctx.conf.listSort) {
5581
- this.initDropdown();
5582
- }
5583
5700
  this.$el.querySelector(".atk-copyright").innerHTML = `Powered By <a href="https://artalk.js.org" target="_blank" title="Artalk v${version}">Artalk</a>`;
5584
5701
  }
5585
5702
  initListActionBtn() {
@@ -5614,6 +5731,9 @@ class List extends ListLite {
5614
5731
  this.ctx.editorOpen();
5615
5732
  this.$closeCommentBtn.innerHTML = this.$t("closeComment");
5616
5733
  }
5734
+ if (this.ctx.conf.listSort) {
5735
+ this.initDropdown();
5736
+ }
5617
5737
  }
5618
5738
  onLoad(data, offset) {
5619
5739
  super.onLoad(data, offset);
@@ -5687,6 +5807,9 @@ class List extends ListLite {
5687
5807
  }
5688
5808
  }
5689
5809
  initDropdown() {
5810
+ if (this.dropdownLoaded)
5811
+ return;
5812
+ this.dropdownLoaded = true;
5690
5813
  this.$dropdownWrap = this.$commentCount;
5691
5814
  this.$commentCount.classList.add("atk-dropdown-wrap");
5692
5815
  this.$dropdownWrap.append(createElement(`<span class="atk-arrow-down-icon"></span>`));
@@ -5767,6 +5890,8 @@ class Context {
5767
5890
  __publicField(this, "markedReplacers", []);
5768
5891
  __publicField(this, "commentList", []);
5769
5892
  __publicField(this, "eventList", []);
5893
+ __publicField(this, "darkModeMedia", window.matchMedia("(prefers-color-scheme: dark)"));
5894
+ __publicField(this, "darkModeAutoFunc");
5770
5895
  this.cid = +new Date();
5771
5896
  this.conf = conf;
5772
5897
  this.user = new User(this);
@@ -5775,6 +5900,9 @@ class Context {
5775
5900
  this.$root.classList.add("artalk");
5776
5901
  this.$root.innerHTML = "";
5777
5902
  this.api = new Api(this);
5903
+ this.on("conf-loaded", () => {
5904
+ this.refreshDarkModeConf();
5905
+ });
5778
5906
  }
5779
5907
  setApi(api) {
5780
5908
  this.api = api;
@@ -5938,19 +6066,38 @@ class Context {
5938
6066
  setDarkMode(darkMode) {
5939
6067
  const darkModeClassName = "atk-dark-mode";
5940
6068
  this.conf.darkMode = darkMode;
5941
- this.trigger("conf-updated");
5942
- if (this.conf.darkMode)
6069
+ if (darkMode)
5943
6070
  this.$root.classList.add(darkModeClassName);
5944
6071
  else
5945
6072
  this.$root.classList.remove(darkModeClassName);
5946
6073
  const { $wrap: $layerWrap } = GetLayerWrap(this);
5947
6074
  if ($layerWrap) {
5948
- if (this.conf.darkMode)
6075
+ if (darkMode)
5949
6076
  $layerWrap.classList.add(darkModeClassName);
5950
6077
  else
5951
6078
  $layerWrap.classList.remove(darkModeClassName);
5952
6079
  }
5953
6080
  }
6081
+ refreshDarkModeConf() {
6082
+ if (this.conf.darkMode === "auto") {
6083
+ this.setDarkMode(this.darkModeMedia.matches);
6084
+ if (!this.darkModeAutoFunc) {
6085
+ this.darkModeAutoFunc = (evt) => {
6086
+ this.setDarkMode(evt.matches);
6087
+ };
6088
+ this.darkModeMedia.addEventListener("change", this.darkModeAutoFunc);
6089
+ }
6090
+ } else {
6091
+ if (this.darkModeAutoFunc) {
6092
+ this.darkModeMedia.removeEventListener("change", this.darkModeAutoFunc);
6093
+ }
6094
+ this.setDarkMode(this.conf.darkMode || false);
6095
+ }
6096
+ }
6097
+ updateConf(conf) {
6098
+ this.conf = mergeDeep(this.conf, conf);
6099
+ this.trigger("conf-loaded");
6100
+ }
5954
6101
  }
5955
6102
  const defaults = {
5956
6103
  el: "",
@@ -5976,7 +6123,7 @@ const defaults = {
5976
6123
  pvEl: "#ArtalkPV",
5977
6124
  gravatar: {
5978
6125
  default: "mp",
5979
- mirror: "https://sdn.geekzu.org/avatar/"
6126
+ mirror: "https://cravatar.cn/avatar/"
5980
6127
  },
5981
6128
  pagination: {
5982
6129
  pageSize: 20,
@@ -5990,7 +6137,7 @@ const defaults = {
5990
6137
  imgUpload: true,
5991
6138
  reqTimeout: 15e3,
5992
6139
  versionCheck: true,
5993
- useBackendConf: false,
6140
+ useBackendConf: true,
5994
6141
  locale: "zh-CN"
5995
6142
  };
5996
6143
  class Dialog {
@@ -6106,6 +6253,7 @@ const CaptchaChecker = {
6106
6253
  },
6107
6254
  onError(that, ctx, err, inputVal, formEl) {
6108
6255
  formEl.querySelector(".atk-captcha-img").click();
6256
+ formEl.querySelector('input[type="text"]').value = "";
6109
6257
  }
6110
6258
  };
6111
6259
  const AdminChecker = {
@@ -6116,7 +6264,10 @@ const AdminChecker = {
6116
6264
  email: that.ctx.user.data.email,
6117
6265
  password: inputVal
6118
6266
  };
6119
- return that.ctx.getApi().user.login(data.name, data.email, data.password);
6267
+ return (() => __async(this, null, function* () {
6268
+ const resp = yield that.ctx.getApi().user.login(data.name, data.email, data.password);
6269
+ return resp.token;
6270
+ }))();
6120
6271
  },
6121
6272
  body(that, ctx) {
6122
6273
  return createElement(`<span>${that.ctx.$t("adminCheck")}</span>`);
@@ -6530,7 +6681,7 @@ class UploadPlug extends EditorPlug {
6530
6681
  };
6531
6682
  $input.click();
6532
6683
  };
6533
- this.ctx.on("conf-updated", () => {
6684
+ this.ctx.on("conf-loaded", () => {
6534
6685
  if (!this.ctx.conf.imgUpload) {
6535
6686
  this.getBtn().setAttribute("atk-only-admin-show", "");
6536
6687
  this.ctx.checkAdminShowEl();
@@ -6725,12 +6876,12 @@ class Editor extends Component {
6725
6876
  this.$notifyWrap = this.$el.querySelector(".atk-notify-wrap");
6726
6877
  this.$plugBtnWrap = this.$el.querySelector(".atk-plug-btn-wrap");
6727
6878
  this.$plugPanelWrap = this.$el.querySelector(".atk-plug-panel-wrap");
6728
- this.initLocalStorage();
6729
- this.initHeader();
6730
- this.initTextarea();
6731
- this.initPlugs();
6732
- this.initSubmitBtn();
6733
- this.ctx.on("conf-updated", () => {
6879
+ this.ctx.on("conf-loaded", () => {
6880
+ this.initLocalStorage();
6881
+ this.initHeader();
6882
+ this.initTextarea();
6883
+ this.initSubmitBtn();
6884
+ this.initPlugs();
6734
6885
  });
6735
6886
  }
6736
6887
  get user() {
@@ -7026,6 +7177,8 @@ class Editor extends Component {
7026
7177
  this.openedPlugName = null;
7027
7178
  this.$plugBtnWrap.innerHTML = "";
7028
7179
  const disabledPlugs = [];
7180
+ if (!this.conf.imgUpload)
7181
+ disabledPlugs.push("upload");
7029
7182
  if (!this.conf.emoticons)
7030
7183
  disabledPlugs.push("emoticons");
7031
7184
  if (!this.conf.preview)
@@ -7120,9 +7273,6 @@ class SidebarLayer extends Component {
7120
7273
  };
7121
7274
  }
7122
7275
  this.layer.show();
7123
- setTimeout(() => {
7124
- this.$el.style.transform = "translate(0, 0)";
7125
- }, 20);
7126
7276
  (() => __async(this, null, function* () {
7127
7277
  var _a;
7128
7278
  const resp = yield this.ctx.getApi().user.loginStatus();
@@ -7140,7 +7290,6 @@ class SidebarLayer extends Component {
7140
7290
  });
7141
7291
  }
7142
7292
  }))();
7143
- this.ctx.updateNotifies([]);
7144
7293
  if (this.firstShow) {
7145
7294
  this.$iframeWrap.innerHTML = "";
7146
7295
  this.$iframe = createElement("<iframe></iframe>");
@@ -7166,6 +7315,12 @@ class SidebarLayer extends Component {
7166
7315
  if (!this.conf.darkMode && isIframeSrcDarkMode)
7167
7316
  this.iframeLoad(this.$iframe.src.replace("&darkMode=1", ""));
7168
7317
  }
7318
+ setTimeout(() => {
7319
+ this.$el.style.transform = "translate(0, 0)";
7320
+ }, 100);
7321
+ setTimeout(() => {
7322
+ this.ctx.updateNotifies([]);
7323
+ }, 0);
7169
7324
  this.ctx.trigger("sidebar-show");
7170
7325
  });
7171
7326
  }
@@ -7186,7 +7341,13 @@ class SidebarLayer extends Component {
7186
7341
  }
7187
7342
  }
7188
7343
  const PvCountWidget = (ctx) => {
7189
- initCountWidget({ ctx, pvAdd: true });
7344
+ if (!ctx.conf.useBackendConf) {
7345
+ initCountWidget({ ctx, pvAdd: true });
7346
+ } else {
7347
+ ctx.on("list-loaded", () => {
7348
+ initCountWidget({ ctx, pvAdd: true });
7349
+ });
7350
+ }
7190
7351
  };
7191
7352
  function initCountWidget(p) {
7192
7353
  return __async(this, null, function* () {
@@ -7233,14 +7394,11 @@ const _Artalk = class {
7233
7394
  if (this.conf.el instanceof HTMLElement)
7234
7395
  this.$root = this.conf.el;
7235
7396
  this.ctx = new Context(this.conf, this.$root);
7236
- if (this.conf.useBackendConf)
7237
- return this.loadConfRemoteAndInitComponents();
7238
7397
  this.initComponents();
7239
7398
  }
7240
7399
  initComponents() {
7241
7400
  this.initLocale();
7242
7401
  this.initLayer();
7243
- this.initDarkMode();
7244
7402
  initMarked(this.ctx);
7245
7403
  const Components = {
7246
7404
  checkerLauncher: () => {
@@ -7261,7 +7419,6 @@ const _Artalk = class {
7261
7419
  sidebarLayer: () => {
7262
7420
  const sidebarLayer = new SidebarLayer(this.ctx);
7263
7421
  this.ctx.setSidebarLayer(sidebarLayer);
7264
- this.$root.appendChild(sidebarLayer.$el);
7265
7422
  },
7266
7423
  eventsDefault: () => {
7267
7424
  this.initEventBind();
@@ -7299,26 +7456,6 @@ const _Artalk = class {
7299
7456
  }
7300
7457
  return conf;
7301
7458
  }
7302
- loadConfRemoteAndInitComponents() {
7303
- return __async(this, null, function* () {
7304
- yield this.loadConfRemote();
7305
- this.initComponents();
7306
- return this;
7307
- });
7308
- }
7309
- loadConfRemote() {
7310
- return __async(this, null, function* () {
7311
- showLoading(this.$root);
7312
- let backendConf = {};
7313
- try {
7314
- backendConf = yield this.ctx.getApi().system.conf();
7315
- } catch (err) {
7316
- console.error("Load config from remote err", err);
7317
- }
7318
- this.ctx.conf = mergeDeep(this.ctx.conf, backendConf);
7319
- hideLoading(this.$root);
7320
- });
7321
- }
7322
7459
  initEventBind() {
7323
7460
  window.addEventListener("hashchange", () => {
7324
7461
  this.ctx.listHashGotoCheck();
@@ -7337,17 +7474,6 @@ const _Artalk = class {
7337
7474
  Layer.BodyOrgOverflow = document.body.style.overflow;
7338
7475
  Layer.BodyOrgPaddingRight = document.body.style.paddingRight;
7339
7476
  }
7340
- initDarkMode() {
7341
- if (this.conf.darkMode === "auto") {
7342
- const darkModeMedia = window.matchMedia("(prefers-color-scheme: dark)");
7343
- darkModeMedia.addEventListener("change", (e) => {
7344
- this.setDarkMode(e.matches);
7345
- });
7346
- this.setDarkMode(darkModeMedia.matches);
7347
- } else {
7348
- this.setDarkMode(this.conf.darkMode || false);
7349
- }
7350
- }
7351
7477
  on(name, handler) {
7352
7478
  this.ctx.on(name, handler, "external");
7353
7479
  }