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 +237 -111
- package/dist/Artalk.iife.js +1 -1
- package/dist/Artalk.js +1 -1
- package/dist/ArtalkLite.es.js +237 -111
- package/dist/ArtalkLite.iife.js +1 -1
- package/dist/ArtalkLite.js +1 -1
- package/dist/src/api/index.d.ts +1 -1
- package/dist/src/api/system.d.ts +7 -0
- package/dist/src/api/user.d.ts +16 -2
- package/dist/src/artalk.d.ts +0 -6
- package/dist/src/context.d.ts +4 -0
- package/dist/src/list/list-lite.d.ts +17 -7
- package/dist/src/list/list.d.ts +1 -0
- package/dist/types/artalk-config.d.ts +5 -1
- package/dist/types/artalk-data.d.ts +23 -0
- package/dist/types/context.d.ts +3 -0
- package/dist/types/event.d.ts +1 -1
- package/package.json +3 -3
- package/src/api/index.ts +3 -2
- package/src/api/system.ts +7 -0
- package/src/api/user.ts +59 -2
- package/src/artalk.ts +0 -35
- package/src/comment/render.ts +2 -1
- package/src/context.ts +31 -3
- package/src/defaults.ts +2 -2
- package/src/editor/editor.ts +9 -8
- package/src/editor/plugs/upload-plug.ts +1 -1
- package/src/layer/sidebar-layer.ts +10 -8
- package/src/lib/checker/admin-checker.ts +4 -1
- package/src/lib/checker/captcha-checker.ts +1 -0
- package/src/lib/stat.ts +9 -1
- package/src/lib/utils.ts +8 -1
- package/src/list/list-lite.ts +68 -26
- package/src/list/list.ts +10 -18
- package/types/artalk-config.d.ts +5 -1
- package/types/artalk-data.d.ts +23 -0
- package/types/context.d.ts +3 -0
- package/types/event.d.ts +1 -1
package/dist/ArtalkLite.es.js
CHANGED
|
@@ -237,18 +237,6 @@ class User {
|
|
|
237
237
|
return !!this.data.nick && !!this.data.email;
|
|
238
238
|
}
|
|
239
239
|
}
|
|
240
|
-
class Component {
|
|
241
|
-
constructor(ctx) {
|
|
242
|
-
__publicField(this, "$el");
|
|
243
|
-
__publicField(this, "ctx");
|
|
244
|
-
__publicField(this, "conf");
|
|
245
|
-
this.ctx = ctx;
|
|
246
|
-
this.conf = ctx.conf;
|
|
247
|
-
}
|
|
248
|
-
$t(key, args = {}) {
|
|
249
|
-
return this.ctx.$t(key, args);
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
240
|
var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
|
|
253
241
|
var escapes = {
|
|
254
242
|
"&": "&",
|
|
@@ -856,7 +844,12 @@ function marked(ctx, src) {
|
|
|
856
844
|
}
|
|
857
845
|
let dest = insane_1(markedContent, {
|
|
858
846
|
allowedClasses: {},
|
|
859
|
-
allowedSchemes: [
|
|
847
|
+
allowedSchemes: [
|
|
848
|
+
"http",
|
|
849
|
+
"https",
|
|
850
|
+
"mailto",
|
|
851
|
+
"data"
|
|
852
|
+
],
|
|
860
853
|
allowedTags: [
|
|
861
854
|
"a",
|
|
862
855
|
"abbr",
|
|
@@ -993,6 +986,18 @@ function mergeDeep(target, source) {
|
|
|
993
986
|
});
|
|
994
987
|
return target;
|
|
995
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
|
+
}
|
|
996
1001
|
function showLoading(parentElem, conf) {
|
|
997
1002
|
let $loading = parentElem.querySelector(":scope > .atk-loading");
|
|
998
1003
|
if (!$loading) {
|
|
@@ -1272,6 +1277,9 @@ function GetLayerWrap(ctx) {
|
|
|
1272
1277
|
_defineProperties(Constructor.prototype, protoProps);
|
|
1273
1278
|
if (staticProps)
|
|
1274
1279
|
_defineProperties(Constructor, staticProps);
|
|
1280
|
+
Object.defineProperty(Constructor, "prototype", {
|
|
1281
|
+
writable: false
|
|
1282
|
+
});
|
|
1275
1283
|
return Constructor;
|
|
1276
1284
|
}
|
|
1277
1285
|
function _inherits(subClass, superClass) {
|
|
@@ -1285,17 +1293,20 @@ function GetLayerWrap(ctx) {
|
|
|
1285
1293
|
configurable: true
|
|
1286
1294
|
}
|
|
1287
1295
|
});
|
|
1296
|
+
Object.defineProperty(subClass, "prototype", {
|
|
1297
|
+
writable: false
|
|
1298
|
+
});
|
|
1288
1299
|
if (superClass)
|
|
1289
1300
|
_setPrototypeOf(subClass, superClass);
|
|
1290
1301
|
}
|
|
1291
1302
|
function _getPrototypeOf(o) {
|
|
1292
|
-
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf2(o2) {
|
|
1303
|
+
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf2(o2) {
|
|
1293
1304
|
return o2.__proto__ || Object.getPrototypeOf(o2);
|
|
1294
1305
|
};
|
|
1295
1306
|
return _getPrototypeOf(o);
|
|
1296
1307
|
}
|
|
1297
1308
|
function _setPrototypeOf(o, p) {
|
|
1298
|
-
_setPrototypeOf = Object.setPrototypeOf
|
|
1309
|
+
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf2(o2, p2) {
|
|
1299
1310
|
o2.__proto__ = p2;
|
|
1300
1311
|
return o2;
|
|
1301
1312
|
};
|
|
@@ -1325,6 +1336,8 @@ function GetLayerWrap(ctx) {
|
|
|
1325
1336
|
function _possibleConstructorReturn(self2, call) {
|
|
1326
1337
|
if (call && (typeof call === "object" || typeof call === "function")) {
|
|
1327
1338
|
return call;
|
|
1339
|
+
} else if (call !== void 0) {
|
|
1340
|
+
throw new TypeError("Derived constructors may only return object or undefined");
|
|
1328
1341
|
}
|
|
1329
1342
|
return _assertThisInitialized(self2);
|
|
1330
1343
|
}
|
|
@@ -1349,22 +1362,22 @@ function GetLayerWrap(ctx) {
|
|
|
1349
1362
|
}
|
|
1350
1363
|
return object;
|
|
1351
1364
|
}
|
|
1352
|
-
function _get(
|
|
1365
|
+
function _get() {
|
|
1353
1366
|
if (typeof Reflect !== "undefined" && Reflect.get) {
|
|
1354
|
-
_get = Reflect.get;
|
|
1367
|
+
_get = Reflect.get.bind();
|
|
1355
1368
|
} else {
|
|
1356
|
-
_get = function _get2(
|
|
1357
|
-
var base = _superPropBase(
|
|
1369
|
+
_get = function _get2(target, property, receiver) {
|
|
1370
|
+
var base = _superPropBase(target, property);
|
|
1358
1371
|
if (!base)
|
|
1359
1372
|
return;
|
|
1360
|
-
var desc = Object.getOwnPropertyDescriptor(base,
|
|
1373
|
+
var desc = Object.getOwnPropertyDescriptor(base, property);
|
|
1361
1374
|
if (desc.get) {
|
|
1362
|
-
return desc.get.call(
|
|
1375
|
+
return desc.get.call(arguments.length < 3 ? target : receiver);
|
|
1363
1376
|
}
|
|
1364
1377
|
return desc.value;
|
|
1365
1378
|
};
|
|
1366
1379
|
}
|
|
1367
|
-
return _get(
|
|
1380
|
+
return _get.apply(this, arguments);
|
|
1368
1381
|
}
|
|
1369
1382
|
var Emitter = /* @__PURE__ */ function() {
|
|
1370
1383
|
function Emitter2() {
|
|
@@ -1446,6 +1459,11 @@ function GetLayerWrap(ctx) {
|
|
|
1446
1459
|
writable: true,
|
|
1447
1460
|
configurable: true
|
|
1448
1461
|
});
|
|
1462
|
+
Object.defineProperty(_assertThisInitialized(_this), "reason", {
|
|
1463
|
+
value: void 0,
|
|
1464
|
+
writable: true,
|
|
1465
|
+
configurable: true
|
|
1466
|
+
});
|
|
1449
1467
|
return _this;
|
|
1450
1468
|
}
|
|
1451
1469
|
_createClass(AbortSignal2, [{
|
|
@@ -1478,7 +1496,7 @@ function GetLayerWrap(ctx) {
|
|
|
1478
1496
|
}
|
|
1479
1497
|
_createClass(AbortController3, [{
|
|
1480
1498
|
key: "abort",
|
|
1481
|
-
value: function abort() {
|
|
1499
|
+
value: function abort(reason) {
|
|
1482
1500
|
var event;
|
|
1483
1501
|
try {
|
|
1484
1502
|
event = new Event("abort");
|
|
@@ -1499,6 +1517,21 @@ function GetLayerWrap(ctx) {
|
|
|
1499
1517
|
};
|
|
1500
1518
|
}
|
|
1501
1519
|
}
|
|
1520
|
+
var signalReason = reason;
|
|
1521
|
+
if (signalReason === void 0) {
|
|
1522
|
+
if (typeof document === "undefined") {
|
|
1523
|
+
signalReason = new Error("This operation was aborted");
|
|
1524
|
+
signalReason.name = "AbortError";
|
|
1525
|
+
} else {
|
|
1526
|
+
try {
|
|
1527
|
+
signalReason = new DOMException("signal is aborted without reason");
|
|
1528
|
+
} catch (err) {
|
|
1529
|
+
signalReason = new Error("This operation was aborted");
|
|
1530
|
+
signalReason.name = "AbortError";
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
}
|
|
1534
|
+
this.signal.reason = signalReason;
|
|
1502
1535
|
this.signal.dispatchEvent(event);
|
|
1503
1536
|
}
|
|
1504
1537
|
}, {
|
|
@@ -1910,7 +1943,7 @@ class UserApi extends ApiBase {
|
|
|
1910
1943
|
if (this.ctx.conf.site)
|
|
1911
1944
|
params.site_name = this.ctx.conf.site;
|
|
1912
1945
|
const data = yield this.POST("/login", params);
|
|
1913
|
-
return data
|
|
1946
|
+
return data;
|
|
1914
1947
|
});
|
|
1915
1948
|
}
|
|
1916
1949
|
userGet(name, email) {
|
|
@@ -1964,6 +1997,58 @@ class UserApi extends ApiBase {
|
|
|
1964
1997
|
}
|
|
1965
1998
|
return this.POST(`/mark-read`, params);
|
|
1966
1999
|
}
|
|
2000
|
+
userList(offset, limit, type) {
|
|
2001
|
+
return __async(this, null, function* () {
|
|
2002
|
+
const params = {
|
|
2003
|
+
offset: offset || 0,
|
|
2004
|
+
limit: limit || 15
|
|
2005
|
+
};
|
|
2006
|
+
if (type)
|
|
2007
|
+
params.type = type;
|
|
2008
|
+
const d = yield this.POST("/admin/user-get", params);
|
|
2009
|
+
return d;
|
|
2010
|
+
});
|
|
2011
|
+
}
|
|
2012
|
+
userAdd(user, password) {
|
|
2013
|
+
return __async(this, null, function* () {
|
|
2014
|
+
const params = {
|
|
2015
|
+
name: user.name || "",
|
|
2016
|
+
email: user.email || "",
|
|
2017
|
+
password: password || "",
|
|
2018
|
+
link: user.link || "",
|
|
2019
|
+
is_admin: user.is_admin || false,
|
|
2020
|
+
site_names: user.site_names_raw || "",
|
|
2021
|
+
receive_email: user.receive_email || true,
|
|
2022
|
+
badge_name: user.badge_name || "",
|
|
2023
|
+
badge_color: user.badge_color || ""
|
|
2024
|
+
};
|
|
2025
|
+
const d = yield this.POST("/admin/user-add", params);
|
|
2026
|
+
return d.user;
|
|
2027
|
+
});
|
|
2028
|
+
}
|
|
2029
|
+
userEdit(user, password) {
|
|
2030
|
+
return __async(this, null, function* () {
|
|
2031
|
+
const params = {
|
|
2032
|
+
id: user.id,
|
|
2033
|
+
name: user.name || "",
|
|
2034
|
+
email: user.email || "",
|
|
2035
|
+
password: password || "",
|
|
2036
|
+
link: user.link || "",
|
|
2037
|
+
is_admin: user.is_admin || false,
|
|
2038
|
+
site_names: user.site_names_raw || "",
|
|
2039
|
+
receive_email: user.receive_email || true,
|
|
2040
|
+
badge_name: user.badge_name || "",
|
|
2041
|
+
badge_color: user.badge_color || ""
|
|
2042
|
+
};
|
|
2043
|
+
const d = yield this.POST("/admin/user-edit", params);
|
|
2044
|
+
return d.user;
|
|
2045
|
+
});
|
|
2046
|
+
}
|
|
2047
|
+
userDel(userID) {
|
|
2048
|
+
return this.POST("/admin/user-del", {
|
|
2049
|
+
id: String(userID)
|
|
2050
|
+
});
|
|
2051
|
+
}
|
|
1967
2052
|
}
|
|
1968
2053
|
class SystemApi extends ApiBase {
|
|
1969
2054
|
conf() {
|
|
@@ -1995,6 +2080,13 @@ class SystemApi extends ApiBase {
|
|
|
1995
2080
|
return data;
|
|
1996
2081
|
});
|
|
1997
2082
|
}
|
|
2083
|
+
version() {
|
|
2084
|
+
return __async(this, null, function* () {
|
|
2085
|
+
const resp = yield fetch(`${this.api.baseURL}/version`, { method: "POST" });
|
|
2086
|
+
const data = yield resp.json();
|
|
2087
|
+
return data;
|
|
2088
|
+
});
|
|
2089
|
+
}
|
|
1998
2090
|
}
|
|
1999
2091
|
class CaptchaApi extends ApiBase {
|
|
2000
2092
|
captchaGet() {
|
|
@@ -2060,16 +2152,17 @@ const ApiComponents = {
|
|
|
2060
2152
|
class Api {
|
|
2061
2153
|
constructor(ctx) {
|
|
2062
2154
|
__publicField(this, "ctx");
|
|
2063
|
-
__publicField(this, "baseURL");
|
|
2064
2155
|
this.ctx = ctx;
|
|
2065
|
-
this.baseURL = `${ctx.conf.server}/api`;
|
|
2066
2156
|
Object.entries(ApiComponents).forEach(([key, ApiComponent]) => {
|
|
2067
2157
|
this[key] = new ApiComponent(this, this.ctx);
|
|
2068
2158
|
});
|
|
2069
2159
|
}
|
|
2160
|
+
get baseURL() {
|
|
2161
|
+
return `${this.ctx.conf.server}/api`;
|
|
2162
|
+
}
|
|
2070
2163
|
}
|
|
2071
|
-
const version = "2.4.
|
|
2072
|
-
const backendMinVersion = "2.
|
|
2164
|
+
const version = "2.4.4";
|
|
2165
|
+
const backendMinVersion = "2.3.0";
|
|
2073
2166
|
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';
|
|
2074
2167
|
const win = window || {};
|
|
2075
2168
|
const nav = navigator || {};
|
|
@@ -2428,7 +2521,8 @@ class CommentRender {
|
|
|
2428
2521
|
renderAvatar() {
|
|
2429
2522
|
const $avatar = this.$el.querySelector(".atk-avatar");
|
|
2430
2523
|
const $avatarImg = createElement("<img />");
|
|
2431
|
-
|
|
2524
|
+
const avatarURLBuilder = this.ctx.conf.avatarURLBuilder;
|
|
2525
|
+
$avatarImg.src = avatarURLBuilder ? avatarURLBuilder(this.data) : this.comment.getGravatarURL();
|
|
2432
2526
|
if (this.data.link) {
|
|
2433
2527
|
const $avatarA = createElement('<a target="_blank" rel="noreferrer noopener nofollow"></a>');
|
|
2434
2528
|
$avatarA.href = isValidURL(this.data.link) ? this.data.link : `https://${this.data.link}`;
|
|
@@ -3214,10 +3308,10 @@ class ListLite extends Component {
|
|
|
3214
3308
|
__publicField(this, "data");
|
|
3215
3309
|
__publicField(this, "isLoading", false);
|
|
3216
3310
|
__publicField(this, "noCommentText");
|
|
3217
|
-
__publicField(this, "
|
|
3218
|
-
__publicField(this, "
|
|
3219
|
-
__publicField(this, "
|
|
3220
|
-
__publicField(this, "
|
|
3311
|
+
__publicField(this, "_nestSortBy");
|
|
3312
|
+
__publicField(this, "_flatMode");
|
|
3313
|
+
__publicField(this, "_pageMode");
|
|
3314
|
+
__publicField(this, "_pageSize");
|
|
3221
3315
|
__publicField(this, "scrollListenerAt");
|
|
3222
3316
|
__publicField(this, "repositionAt");
|
|
3223
3317
|
__publicField(this, "pagination");
|
|
@@ -3228,20 +3322,53 @@ class ListLite extends Component {
|
|
|
3228
3322
|
__publicField(this, "onAfterLoad");
|
|
3229
3323
|
__publicField(this, "unread", []);
|
|
3230
3324
|
__publicField(this, "unreadHighlight");
|
|
3325
|
+
__publicField(this, "confLoaded", false);
|
|
3231
3326
|
this.$el = createElement(
|
|
3232
3327
|
`<div class="atk-list-lite">
|
|
3233
3328
|
<div class="atk-list-comments-wrap"></div>
|
|
3234
3329
|
</div>`
|
|
3235
3330
|
);
|
|
3236
3331
|
this.$commentsWrap = this.$el.querySelector(".atk-list-comments-wrap");
|
|
3237
|
-
this.noCommentText = ctx.conf.noComment || ctx.$t("noComment");
|
|
3238
|
-
this.nestSortBy = this.ctx.conf.nestSort || "DATE_ASC";
|
|
3239
3332
|
window.setInterval(() => {
|
|
3240
3333
|
this.$el.querySelectorAll("[data-atk-comment-date]").forEach((el) => {
|
|
3241
3334
|
const date = el.getAttribute("data-atk-comment-date");
|
|
3242
3335
|
el.innerText = timeAgo(new Date(Number(date)), this.ctx);
|
|
3243
3336
|
});
|
|
3244
3337
|
}, 30 * 1e3);
|
|
3338
|
+
this.ctx.on("conf-loaded", () => {
|
|
3339
|
+
});
|
|
3340
|
+
}
|
|
3341
|
+
get nestSortBy() {
|
|
3342
|
+
if (this._nestSortBy !== void 0)
|
|
3343
|
+
return this._nestSortBy;
|
|
3344
|
+
return this.ctx.conf.nestSort || "DATE_ASC";
|
|
3345
|
+
}
|
|
3346
|
+
set nestSortBy(val) {
|
|
3347
|
+
this._nestSortBy = val;
|
|
3348
|
+
}
|
|
3349
|
+
get flatMode() {
|
|
3350
|
+
if (this._flatMode !== void 0)
|
|
3351
|
+
return this._flatMode;
|
|
3352
|
+
if (this.ctx.conf.flatMode === true || Number(this.ctx.conf.nestMax) <= 1)
|
|
3353
|
+
return true;
|
|
3354
|
+
if (this.ctx.conf.flatMode === "auto" && window.matchMedia("(max-width: 768px)").matches)
|
|
3355
|
+
return true;
|
|
3356
|
+
return false;
|
|
3357
|
+
}
|
|
3358
|
+
set flatMode(val) {
|
|
3359
|
+
this._flatMode = val;
|
|
3360
|
+
}
|
|
3361
|
+
get pageMode() {
|
|
3362
|
+
return this._pageMode || (this.conf.pagination.readMore ? "read-more" : "pagination");
|
|
3363
|
+
}
|
|
3364
|
+
set pageMode(val) {
|
|
3365
|
+
this._pageMode = val;
|
|
3366
|
+
}
|
|
3367
|
+
get pageSize() {
|
|
3368
|
+
return this._pageSize || this.conf.pagination.pageSize;
|
|
3369
|
+
}
|
|
3370
|
+
set pageSize(val) {
|
|
3371
|
+
this._pageSize = val;
|
|
3245
3372
|
}
|
|
3246
3373
|
getData() {
|
|
3247
3374
|
return this.data;
|
|
@@ -3269,7 +3396,7 @@ class ListLite extends Component {
|
|
|
3269
3396
|
const setLoading2 = (val) => this.setLoading(val, isFirstLoad);
|
|
3270
3397
|
setLoading2(true);
|
|
3271
3398
|
this.ctx.trigger("list-load");
|
|
3272
|
-
if (
|
|
3399
|
+
if (this.pageMode === "read-more" && isFirstLoad || this.pageMode === "pagination") {
|
|
3273
3400
|
this.ctx.clearAllComments();
|
|
3274
3401
|
}
|
|
3275
3402
|
let listData;
|
|
@@ -3294,24 +3421,24 @@ class ListLite extends Component {
|
|
|
3294
3421
|
}
|
|
3295
3422
|
onLoad(data, offset) {
|
|
3296
3423
|
var _a, _b;
|
|
3297
|
-
if (this.pageMode === "pagination") {
|
|
3298
|
-
this.ctx.clearAllComments();
|
|
3299
|
-
}
|
|
3300
3424
|
this.data = data;
|
|
3425
|
+
if (!this.confLoaded) {
|
|
3426
|
+
if (this.conf.useBackendConf)
|
|
3427
|
+
this.ctx.updateConf(data.conf.frontend_conf);
|
|
3428
|
+
else
|
|
3429
|
+
this.ctx.updateConf({});
|
|
3430
|
+
this.confLoaded = true;
|
|
3431
|
+
}
|
|
3301
3432
|
const feMinVersion = ((_a = data.api_version) == null ? void 0 : _a.fe_min_version) || "0.0.0";
|
|
3302
3433
|
if (this.ctx.conf.versionCheck && this.versionCheck("frontend", feMinVersion, version))
|
|
3303
3434
|
return;
|
|
3304
3435
|
if (this.ctx.conf.versionCheck && this.versionCheck("backend", backendMinVersion, (_b = data.api_version) == null ? void 0 : _b.version))
|
|
3305
3436
|
return;
|
|
3306
|
-
if (data.conf && typeof data.conf.img_upload === "boolean") {
|
|
3307
|
-
this.ctx.conf.imgUpload = data.conf.img_upload;
|
|
3308
|
-
}
|
|
3309
3437
|
this.importComments(data.comments);
|
|
3310
3438
|
this.refreshPagination(offset, this.flatMode ? data.total : data.total_roots);
|
|
3311
3439
|
this.refreshUI();
|
|
3312
3440
|
this.ctx.updateNotifies(data.unread || []);
|
|
3313
3441
|
this.ctx.trigger("list-loaded");
|
|
3314
|
-
this.ctx.trigger("conf-updated");
|
|
3315
3442
|
if (this.onAfterLoad)
|
|
3316
3443
|
this.onAfterLoad(data);
|
|
3317
3444
|
}
|
|
@@ -3375,6 +3502,9 @@ class ListLite extends Component {
|
|
|
3375
3502
|
}
|
|
3376
3503
|
onError(msg, offset, errData) {
|
|
3377
3504
|
var _a;
|
|
3505
|
+
if (!this.confLoaded) {
|
|
3506
|
+
this.ctx.updateConf({});
|
|
3507
|
+
}
|
|
3378
3508
|
msg = String(msg);
|
|
3379
3509
|
console.error(msg);
|
|
3380
3510
|
if (offset !== 0 && this.pageMode === "read-more") {
|
|
@@ -3408,7 +3538,7 @@ class ListLite extends Component {
|
|
|
3408
3538
|
if (isNoComment) {
|
|
3409
3539
|
if (!$noComment) {
|
|
3410
3540
|
$noComment = createElement('<div class="atk-list-no-comment"></div>');
|
|
3411
|
-
$noComment.innerHTML = this.noCommentText;
|
|
3541
|
+
$noComment.innerHTML = this.noCommentText || this.ctx.conf.noComment || this.ctx.$t("noComment");
|
|
3412
3542
|
this.$commentsWrap.appendChild($noComment);
|
|
3413
3543
|
}
|
|
3414
3544
|
} else {
|
|
@@ -3538,7 +3668,6 @@ class ListLite extends Component {
|
|
|
3538
3668
|
ignoreBtn.onclick = () => {
|
|
3539
3669
|
setError(this.$el.parentElement, null);
|
|
3540
3670
|
this.ctx.conf.versionCheck = false;
|
|
3541
|
-
this.ctx.trigger("conf-updated");
|
|
3542
3671
|
this.fetchComments(0);
|
|
3543
3672
|
};
|
|
3544
3673
|
errEl.append(ignoreBtn);
|
|
@@ -3559,18 +3688,9 @@ class List extends ListLite {
|
|
|
3559
3688
|
__publicField(this, "$dropdownWrap");
|
|
3560
3689
|
__publicField(this, "goToCommentFounded", false);
|
|
3561
3690
|
__publicField(this, "goToCommentDelay", true);
|
|
3691
|
+
__publicField(this, "dropdownLoaded", false);
|
|
3562
3692
|
el.querySelector(".atk-list-body").append(this.$el);
|
|
3563
3693
|
this.$el = el;
|
|
3564
|
-
if (this.ctx.conf.flatMode === true) {
|
|
3565
|
-
this.flatMode = true;
|
|
3566
|
-
} else if (this.conf.nestMax && this.conf.nestMax <= 1) {
|
|
3567
|
-
this.flatMode = true;
|
|
3568
|
-
} else if (this.ctx.conf.flatMode === "auto") {
|
|
3569
|
-
if (window.matchMedia("(max-width: 768px)").matches)
|
|
3570
|
-
this.flatMode = true;
|
|
3571
|
-
}
|
|
3572
|
-
this.pageMode = this.conf.pagination.readMore ? "read-more" : "pagination";
|
|
3573
|
-
this.pageSize = this.conf.pagination.pageSize || 20;
|
|
3574
3694
|
this.repositionAt = this.$el;
|
|
3575
3695
|
this.initListActionBtn();
|
|
3576
3696
|
this.$commentCount = this.$el.querySelector(".atk-comment-count");
|
|
@@ -3578,9 +3698,6 @@ class List extends ListLite {
|
|
|
3578
3698
|
count: '<span class="atk-comment-count-num">0</span>'
|
|
3579
3699
|
});
|
|
3580
3700
|
this.$commentCountNum = this.$commentCount.querySelector(".atk-comment-count-num");
|
|
3581
|
-
if (this.ctx.conf.listSort) {
|
|
3582
|
-
this.initDropdown();
|
|
3583
|
-
}
|
|
3584
3701
|
this.$el.querySelector(".atk-copyright").innerHTML = `Powered By <a href="https://artalk.js.org" target="_blank" title="Artalk v${version}">Artalk</a>`;
|
|
3585
3702
|
}
|
|
3586
3703
|
initListActionBtn() {
|
|
@@ -3615,6 +3732,9 @@ class List extends ListLite {
|
|
|
3615
3732
|
this.ctx.editorOpen();
|
|
3616
3733
|
this.$closeCommentBtn.innerHTML = this.$t("closeComment");
|
|
3617
3734
|
}
|
|
3735
|
+
if (this.ctx.conf.listSort) {
|
|
3736
|
+
this.initDropdown();
|
|
3737
|
+
}
|
|
3618
3738
|
}
|
|
3619
3739
|
onLoad(data, offset) {
|
|
3620
3740
|
super.onLoad(data, offset);
|
|
@@ -3688,6 +3808,9 @@ class List extends ListLite {
|
|
|
3688
3808
|
}
|
|
3689
3809
|
}
|
|
3690
3810
|
initDropdown() {
|
|
3811
|
+
if (this.dropdownLoaded)
|
|
3812
|
+
return;
|
|
3813
|
+
this.dropdownLoaded = true;
|
|
3691
3814
|
this.$dropdownWrap = this.$commentCount;
|
|
3692
3815
|
this.$commentCount.classList.add("atk-dropdown-wrap");
|
|
3693
3816
|
this.$dropdownWrap.append(createElement(`<span class="atk-arrow-down-icon"></span>`));
|
|
@@ -3768,6 +3891,8 @@ class Context {
|
|
|
3768
3891
|
__publicField(this, "markedReplacers", []);
|
|
3769
3892
|
__publicField(this, "commentList", []);
|
|
3770
3893
|
__publicField(this, "eventList", []);
|
|
3894
|
+
__publicField(this, "darkModeMedia", window.matchMedia("(prefers-color-scheme: dark)"));
|
|
3895
|
+
__publicField(this, "darkModeAutoFunc");
|
|
3771
3896
|
this.cid = +new Date();
|
|
3772
3897
|
this.conf = conf;
|
|
3773
3898
|
this.user = new User(this);
|
|
@@ -3776,6 +3901,9 @@ class Context {
|
|
|
3776
3901
|
this.$root.classList.add("artalk");
|
|
3777
3902
|
this.$root.innerHTML = "";
|
|
3778
3903
|
this.api = new Api(this);
|
|
3904
|
+
this.on("conf-loaded", () => {
|
|
3905
|
+
this.refreshDarkModeConf();
|
|
3906
|
+
});
|
|
3779
3907
|
}
|
|
3780
3908
|
setApi(api) {
|
|
3781
3909
|
this.api = api;
|
|
@@ -3939,19 +4067,38 @@ class Context {
|
|
|
3939
4067
|
setDarkMode(darkMode) {
|
|
3940
4068
|
const darkModeClassName = "atk-dark-mode";
|
|
3941
4069
|
this.conf.darkMode = darkMode;
|
|
3942
|
-
|
|
3943
|
-
if (this.conf.darkMode)
|
|
4070
|
+
if (darkMode)
|
|
3944
4071
|
this.$root.classList.add(darkModeClassName);
|
|
3945
4072
|
else
|
|
3946
4073
|
this.$root.classList.remove(darkModeClassName);
|
|
3947
4074
|
const { $wrap: $layerWrap } = GetLayerWrap(this);
|
|
3948
4075
|
if ($layerWrap) {
|
|
3949
|
-
if (
|
|
4076
|
+
if (darkMode)
|
|
3950
4077
|
$layerWrap.classList.add(darkModeClassName);
|
|
3951
4078
|
else
|
|
3952
4079
|
$layerWrap.classList.remove(darkModeClassName);
|
|
3953
4080
|
}
|
|
3954
4081
|
}
|
|
4082
|
+
refreshDarkModeConf() {
|
|
4083
|
+
if (this.conf.darkMode === "auto") {
|
|
4084
|
+
this.setDarkMode(this.darkModeMedia.matches);
|
|
4085
|
+
if (!this.darkModeAutoFunc) {
|
|
4086
|
+
this.darkModeAutoFunc = (evt) => {
|
|
4087
|
+
this.setDarkMode(evt.matches);
|
|
4088
|
+
};
|
|
4089
|
+
this.darkModeMedia.addEventListener("change", this.darkModeAutoFunc);
|
|
4090
|
+
}
|
|
4091
|
+
} else {
|
|
4092
|
+
if (this.darkModeAutoFunc) {
|
|
4093
|
+
this.darkModeMedia.removeEventListener("change", this.darkModeAutoFunc);
|
|
4094
|
+
}
|
|
4095
|
+
this.setDarkMode(this.conf.darkMode || false);
|
|
4096
|
+
}
|
|
4097
|
+
}
|
|
4098
|
+
updateConf(conf) {
|
|
4099
|
+
this.conf = mergeDeep(this.conf, conf);
|
|
4100
|
+
this.trigger("conf-loaded");
|
|
4101
|
+
}
|
|
3955
4102
|
}
|
|
3956
4103
|
const defaults = {
|
|
3957
4104
|
el: "",
|
|
@@ -3977,7 +4124,7 @@ const defaults = {
|
|
|
3977
4124
|
pvEl: "#ArtalkPV",
|
|
3978
4125
|
gravatar: {
|
|
3979
4126
|
default: "mp",
|
|
3980
|
-
mirror: "https://
|
|
4127
|
+
mirror: "https://cravatar.cn/avatar/"
|
|
3981
4128
|
},
|
|
3982
4129
|
pagination: {
|
|
3983
4130
|
pageSize: 20,
|
|
@@ -3991,7 +4138,7 @@ const defaults = {
|
|
|
3991
4138
|
imgUpload: true,
|
|
3992
4139
|
reqTimeout: 15e3,
|
|
3993
4140
|
versionCheck: true,
|
|
3994
|
-
useBackendConf:
|
|
4141
|
+
useBackendConf: true,
|
|
3995
4142
|
locale: "zh-CN"
|
|
3996
4143
|
};
|
|
3997
4144
|
{
|
|
@@ -4112,6 +4259,7 @@ const CaptchaChecker = {
|
|
|
4112
4259
|
},
|
|
4113
4260
|
onError(that, ctx, err, inputVal, formEl) {
|
|
4114
4261
|
formEl.querySelector(".atk-captcha-img").click();
|
|
4262
|
+
formEl.querySelector('input[type="text"]').value = "";
|
|
4115
4263
|
}
|
|
4116
4264
|
};
|
|
4117
4265
|
const AdminChecker = {
|
|
@@ -4122,7 +4270,10 @@ const AdminChecker = {
|
|
|
4122
4270
|
email: that.ctx.user.data.email,
|
|
4123
4271
|
password: inputVal
|
|
4124
4272
|
};
|
|
4125
|
-
return
|
|
4273
|
+
return (() => __async(this, null, function* () {
|
|
4274
|
+
const resp = yield that.ctx.getApi().user.login(data.name, data.email, data.password);
|
|
4275
|
+
return resp.token;
|
|
4276
|
+
}))();
|
|
4126
4277
|
},
|
|
4127
4278
|
body(that, ctx) {
|
|
4128
4279
|
return createElement(`<span>${that.ctx.$t("adminCheck")}</span>`);
|
|
@@ -4536,7 +4687,7 @@ class UploadPlug extends EditorPlug {
|
|
|
4536
4687
|
};
|
|
4537
4688
|
$input.click();
|
|
4538
4689
|
};
|
|
4539
|
-
this.ctx.on("conf-
|
|
4690
|
+
this.ctx.on("conf-loaded", () => {
|
|
4540
4691
|
if (!this.ctx.conf.imgUpload) {
|
|
4541
4692
|
this.getBtn().setAttribute("atk-only-admin-show", "");
|
|
4542
4693
|
this.ctx.checkAdminShowEl();
|
|
@@ -4731,12 +4882,12 @@ class Editor extends Component {
|
|
|
4731
4882
|
this.$notifyWrap = this.$el.querySelector(".atk-notify-wrap");
|
|
4732
4883
|
this.$plugBtnWrap = this.$el.querySelector(".atk-plug-btn-wrap");
|
|
4733
4884
|
this.$plugPanelWrap = this.$el.querySelector(".atk-plug-panel-wrap");
|
|
4734
|
-
this.
|
|
4735
|
-
|
|
4736
|
-
|
|
4737
|
-
|
|
4738
|
-
|
|
4739
|
-
|
|
4885
|
+
this.ctx.on("conf-loaded", () => {
|
|
4886
|
+
this.initLocalStorage();
|
|
4887
|
+
this.initHeader();
|
|
4888
|
+
this.initTextarea();
|
|
4889
|
+
this.initSubmitBtn();
|
|
4890
|
+
this.initPlugs();
|
|
4740
4891
|
});
|
|
4741
4892
|
}
|
|
4742
4893
|
get user() {
|
|
@@ -5032,6 +5183,8 @@ class Editor extends Component {
|
|
|
5032
5183
|
this.openedPlugName = null;
|
|
5033
5184
|
this.$plugBtnWrap.innerHTML = "";
|
|
5034
5185
|
const disabledPlugs = [];
|
|
5186
|
+
if (!this.conf.imgUpload)
|
|
5187
|
+
disabledPlugs.push("upload");
|
|
5035
5188
|
if (!this.conf.emoticons)
|
|
5036
5189
|
disabledPlugs.push("emoticons");
|
|
5037
5190
|
if (!this.conf.preview)
|
|
@@ -5126,9 +5279,6 @@ class SidebarLayer extends Component {
|
|
|
5126
5279
|
};
|
|
5127
5280
|
}
|
|
5128
5281
|
this.layer.show();
|
|
5129
|
-
setTimeout(() => {
|
|
5130
|
-
this.$el.style.transform = "translate(0, 0)";
|
|
5131
|
-
}, 20);
|
|
5132
5282
|
(() => __async(this, null, function* () {
|
|
5133
5283
|
var _a;
|
|
5134
5284
|
const resp = yield this.ctx.getApi().user.loginStatus();
|
|
@@ -5146,7 +5296,6 @@ class SidebarLayer extends Component {
|
|
|
5146
5296
|
});
|
|
5147
5297
|
}
|
|
5148
5298
|
}))();
|
|
5149
|
-
this.ctx.updateNotifies([]);
|
|
5150
5299
|
if (this.firstShow) {
|
|
5151
5300
|
this.$iframeWrap.innerHTML = "";
|
|
5152
5301
|
this.$iframe = createElement("<iframe></iframe>");
|
|
@@ -5172,6 +5321,12 @@ class SidebarLayer extends Component {
|
|
|
5172
5321
|
if (!this.conf.darkMode && isIframeSrcDarkMode)
|
|
5173
5322
|
this.iframeLoad(this.$iframe.src.replace("&darkMode=1", ""));
|
|
5174
5323
|
}
|
|
5324
|
+
setTimeout(() => {
|
|
5325
|
+
this.$el.style.transform = "translate(0, 0)";
|
|
5326
|
+
}, 100);
|
|
5327
|
+
setTimeout(() => {
|
|
5328
|
+
this.ctx.updateNotifies([]);
|
|
5329
|
+
}, 0);
|
|
5175
5330
|
this.ctx.trigger("sidebar-show");
|
|
5176
5331
|
});
|
|
5177
5332
|
}
|
|
@@ -5192,7 +5347,13 @@ class SidebarLayer extends Component {
|
|
|
5192
5347
|
}
|
|
5193
5348
|
}
|
|
5194
5349
|
const PvCountWidget = (ctx) => {
|
|
5195
|
-
|
|
5350
|
+
if (!ctx.conf.useBackendConf) {
|
|
5351
|
+
initCountWidget({ ctx, pvAdd: true });
|
|
5352
|
+
} else {
|
|
5353
|
+
ctx.on("list-loaded", () => {
|
|
5354
|
+
initCountWidget({ ctx, pvAdd: true });
|
|
5355
|
+
});
|
|
5356
|
+
}
|
|
5196
5357
|
};
|
|
5197
5358
|
function initCountWidget(p) {
|
|
5198
5359
|
return __async(this, null, function* () {
|
|
@@ -5239,14 +5400,11 @@ const _Artalk = class {
|
|
|
5239
5400
|
if (this.conf.el instanceof HTMLElement)
|
|
5240
5401
|
this.$root = this.conf.el;
|
|
5241
5402
|
this.ctx = new Context(this.conf, this.$root);
|
|
5242
|
-
if (this.conf.useBackendConf)
|
|
5243
|
-
return this.loadConfRemoteAndInitComponents();
|
|
5244
5403
|
this.initComponents();
|
|
5245
5404
|
}
|
|
5246
5405
|
initComponents() {
|
|
5247
5406
|
this.initLocale();
|
|
5248
5407
|
this.initLayer();
|
|
5249
|
-
this.initDarkMode();
|
|
5250
5408
|
initMarked(this.ctx);
|
|
5251
5409
|
const Components = {
|
|
5252
5410
|
checkerLauncher: () => {
|
|
@@ -5267,7 +5425,6 @@ const _Artalk = class {
|
|
|
5267
5425
|
sidebarLayer: () => {
|
|
5268
5426
|
const sidebarLayer = new SidebarLayer(this.ctx);
|
|
5269
5427
|
this.ctx.setSidebarLayer(sidebarLayer);
|
|
5270
|
-
this.$root.appendChild(sidebarLayer.$el);
|
|
5271
5428
|
},
|
|
5272
5429
|
eventsDefault: () => {
|
|
5273
5430
|
this.initEventBind();
|
|
@@ -5305,26 +5462,6 @@ const _Artalk = class {
|
|
|
5305
5462
|
}
|
|
5306
5463
|
return conf;
|
|
5307
5464
|
}
|
|
5308
|
-
loadConfRemoteAndInitComponents() {
|
|
5309
|
-
return __async(this, null, function* () {
|
|
5310
|
-
yield this.loadConfRemote();
|
|
5311
|
-
this.initComponents();
|
|
5312
|
-
return this;
|
|
5313
|
-
});
|
|
5314
|
-
}
|
|
5315
|
-
loadConfRemote() {
|
|
5316
|
-
return __async(this, null, function* () {
|
|
5317
|
-
showLoading(this.$root);
|
|
5318
|
-
let backendConf = {};
|
|
5319
|
-
try {
|
|
5320
|
-
backendConf = yield this.ctx.getApi().system.conf();
|
|
5321
|
-
} catch (err) {
|
|
5322
|
-
console.error("Load config from remote err", err);
|
|
5323
|
-
}
|
|
5324
|
-
this.ctx.conf = mergeDeep(this.ctx.conf, backendConf);
|
|
5325
|
-
hideLoading(this.$root);
|
|
5326
|
-
});
|
|
5327
|
-
}
|
|
5328
5465
|
initEventBind() {
|
|
5329
5466
|
window.addEventListener("hashchange", () => {
|
|
5330
5467
|
this.ctx.listHashGotoCheck();
|
|
@@ -5343,17 +5480,6 @@ const _Artalk = class {
|
|
|
5343
5480
|
Layer.BodyOrgOverflow = document.body.style.overflow;
|
|
5344
5481
|
Layer.BodyOrgPaddingRight = document.body.style.paddingRight;
|
|
5345
5482
|
}
|
|
5346
|
-
initDarkMode() {
|
|
5347
|
-
if (this.conf.darkMode === "auto") {
|
|
5348
|
-
const darkModeMedia = window.matchMedia("(prefers-color-scheme: dark)");
|
|
5349
|
-
darkModeMedia.addEventListener("change", (e) => {
|
|
5350
|
-
this.setDarkMode(e.matches);
|
|
5351
|
-
});
|
|
5352
|
-
this.setDarkMode(darkModeMedia.matches);
|
|
5353
|
-
} else {
|
|
5354
|
-
this.setDarkMode(this.conf.darkMode || false);
|
|
5355
|
-
}
|
|
5356
|
-
}
|
|
5357
5483
|
on(name, handler) {
|
|
5358
5484
|
this.ctx.on(name, handler, "external");
|
|
5359
5485
|
}
|