@inpageedit/core 0.13.1 → 0.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -20
- package/README.md +13 -4
- package/dist/{BasePlugin-Bf2UuIHF.js → BasePlugin-YOi2_vUo.js} +17 -26
- package/dist/BasePlugin-YOi2_vUo.js.map +1 -0
- package/dist/IconQuickEdit-CMCQncyj.js.map +1 -1
- package/dist/InputBox-nQKtiWtZ.js.map +1 -1
- package/dist/{PluginPrefSync-Dn1Xsiqz.js → PluginPrefSync-jTNlRQE-.js} +124 -128
- package/dist/PluginPrefSync-jTNlRQE-.js.map +1 -0
- package/dist/PluginStoreApp-CGNxKXAN.js +453 -0
- package/dist/PluginStoreApp-CGNxKXAN.js.map +1 -0
- package/dist/{endpoints-DgyuoRZd.js → Preferences-BF2fcXrn.js} +608 -576
- package/dist/Preferences-BF2fcXrn.js.map +1 -0
- package/dist/WatchlistAction-BbNAyryN.js.map +1 -1
- package/dist/components/index.js.map +1 -1
- package/dist/index-3NZkG2a3.js +116 -0
- package/dist/index-3NZkG2a3.js.map +1 -0
- package/dist/{index-BJ7_Q1mB.js → index-BBNseJXG.js} +17 -16
- package/dist/index-BBNseJXG.js.map +1 -0
- package/dist/{index-BQ-cHWkJ.js → index-Bb0FiU2c.js} +66 -48
- package/dist/index-Bb0FiU2c.js.map +1 -0
- package/dist/{index-DqA6EAM6.js → index-BgkZW91u.js} +1429 -928
- package/dist/index-BgkZW91u.js.map +1 -0
- package/dist/index-BrYKe18j.js +179 -0
- package/dist/index-BrYKe18j.js.map +1 -0
- package/dist/index-CG38LlAh.js.map +1 -1
- package/dist/index-CM_6yF2v.js.map +1 -1
- package/dist/index-D-fW3ESK.js +195 -0
- package/dist/index-D-fW3ESK.js.map +1 -0
- package/dist/index-D6zFqL2u.js +173 -0
- package/dist/index-D6zFqL2u.js.map +1 -0
- package/dist/{index-CCRMmnwk.js → index-D97lUU3h.js} +67 -66
- package/dist/index-D97lUU3h.js.map +1 -0
- package/dist/index-DD5CVCfD.js.map +1 -1
- package/dist/{index-B7c6jL9x.js → index-DELHsLHS.js} +146 -137
- package/dist/index-DELHsLHS.js.map +1 -0
- package/dist/{index-BwdWyHLe.js → index-DTHY5rAO.js} +93 -93
- package/dist/index-DTHY5rAO.js.map +1 -0
- package/dist/index-DmLoihN1.js +394 -0
- package/dist/index-DmLoihN1.js.map +1 -0
- package/dist/index.d.ts +362 -43
- package/dist/index.js +32 -26
- package/dist/index.js.map +1 -1
- package/dist/makeCallable-LDU0xZMJ.js.map +1 -1
- package/dist/models/index.js +174 -154
- package/dist/models/index.js.map +1 -1
- package/dist/noop-ClDc6zv4.js.map +1 -1
- package/dist/plugins/index.js +10 -10
- package/dist/services/index.js +1 -1
- package/dist/style.css +1 -1
- package/dist/vueHooks-l04s8cIl.js.map +1 -1
- package/lib/index.umd.js +20 -12
- package/lib/index.umd.js.map +1 -1
- package/lib/style.css +1 -1
- package/package.json +4 -4
- package/dist/BasePlugin-Bf2UuIHF.js.map +0 -1
- package/dist/PluginPrefSync-Dn1Xsiqz.js.map +0 -1
- package/dist/PluginStoreApp-CpOLArL7.js +0 -452
- package/dist/PluginStoreApp-CpOLArL7.js.map +0 -1
- package/dist/Preferences-DS4-CFWe.js +0 -9
- package/dist/Preferences-DS4-CFWe.js.map +0 -1
- package/dist/endpoints-DgyuoRZd.js.map +0 -1
- package/dist/index-2RfILgXm.js +0 -180
- package/dist/index-2RfILgXm.js.map +0 -1
- package/dist/index-B7c6jL9x.js.map +0 -1
- package/dist/index-BJ7_Q1mB.js.map +0 -1
- package/dist/index-BNh95-x2.js +0 -115
- package/dist/index-BNh95-x2.js.map +0 -1
- package/dist/index-BQ-cHWkJ.js.map +0 -1
- package/dist/index-BwdWyHLe.js.map +0 -1
- package/dist/index-CCRMmnwk.js.map +0 -1
- package/dist/index-CnIpUF9x.js +0 -173
- package/dist/index-CnIpUF9x.js.map +0 -1
- package/dist/index-CyG7_IYz.js +0 -394
- package/dist/index-CyG7_IYz.js.map +0 -1
- package/dist/index-DqA6EAM6.js.map +0 -1
- package/dist/index-eSlbrNqF.js +0 -146
- package/dist/index-eSlbrNqF.js.map +0 -1
package/dist/models/index.js
CHANGED
|
@@ -22,7 +22,7 @@ class y {
|
|
|
22
22
|
return Object.keys(this.values)[s] ?? null;
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
-
const
|
|
25
|
+
const N = () => new Proxy(new y(), {
|
|
26
26
|
set(i, s, o) {
|
|
27
27
|
return typeof s == "string" && i.setItem(s, o), !0;
|
|
28
28
|
},
|
|
@@ -32,12 +32,12 @@ const v = () => new Proxy(new y(), {
|
|
|
32
32
|
});
|
|
33
33
|
function b(i) {
|
|
34
34
|
class s {
|
|
35
|
-
constructor(
|
|
36
|
-
this._loaded = t, this.api = i,
|
|
37
|
-
typeof
|
|
35
|
+
constructor(a, t = !0) {
|
|
36
|
+
this._loaded = t, this.api = i, a.revisions?.forEach((r) => {
|
|
37
|
+
typeof r?.slots?.main == "object" && Object.assign(r, r.slots.main);
|
|
38
38
|
}), this.pageInfo = {
|
|
39
39
|
...s.DEFAULT_PAGE_INFO,
|
|
40
|
-
...
|
|
40
|
+
...a
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
43
|
static {
|
|
@@ -88,47 +88,47 @@ function b(i) {
|
|
|
88
88
|
};
|
|
89
89
|
}
|
|
90
90
|
// Utils
|
|
91
|
-
static async newFromApi(
|
|
91
|
+
static async newFromApi(a) {
|
|
92
92
|
const { data: t } = await this.api.get({
|
|
93
93
|
...s.DEFAULT_QUERY_PARAMS,
|
|
94
|
-
...
|
|
95
|
-
}),
|
|
96
|
-
if (!
|
|
94
|
+
...a
|
|
95
|
+
}), r = t?.query?.pages?.[0];
|
|
96
|
+
if (!r || !r.title)
|
|
97
97
|
throw new Error("Invalid page info", { cause: t });
|
|
98
|
-
return new s(
|
|
98
|
+
return new s(r, !0);
|
|
99
99
|
}
|
|
100
|
-
static newBlankPage(
|
|
101
|
-
return new s(
|
|
100
|
+
static newBlankPage(a = {}) {
|
|
101
|
+
return new s(a, !1);
|
|
102
102
|
}
|
|
103
|
-
static async newFromAnyKind(
|
|
104
|
-
const { title: t, pageId:
|
|
105
|
-
return e ? this.newFromApi({ revids: parseInt(e.toString(), 10) }) :
|
|
103
|
+
static async newFromAnyKind(a) {
|
|
104
|
+
const { title: t, pageId: r, revisionId: e } = a || {};
|
|
105
|
+
return e ? this.newFromApi({ revids: parseInt(e.toString(), 10) }) : r ? this.newFromApi({ pageids: parseInt(r.toString(), 10) }) : t ? this.newFromApi({ titles: t.toString() }) : null;
|
|
106
106
|
}
|
|
107
|
-
static async newBatchFromApi(
|
|
108
|
-
const { titles: t, pageids:
|
|
107
|
+
static async newBatchFromApi(a) {
|
|
108
|
+
const { titles: t, pageids: r, revids: e, ...n } = a || {}, { data: l } = await this.api.post({
|
|
109
109
|
...s.DEFAULT_QUERY_PARAMS,
|
|
110
110
|
titles: t?.join("|") ?? void 0,
|
|
111
|
-
pageids:
|
|
111
|
+
pageids: r?.join("|") ?? void 0,
|
|
112
112
|
revids: e?.join("|") ?? void 0,
|
|
113
|
-
...
|
|
113
|
+
...n
|
|
114
114
|
});
|
|
115
115
|
return l?.query?.pages?.map((c) => new s(c, !0)) || [];
|
|
116
116
|
}
|
|
117
117
|
// Page actions
|
|
118
|
-
async parse(
|
|
118
|
+
async parse(a) {
|
|
119
119
|
return this.api.post({
|
|
120
120
|
action: "parse",
|
|
121
121
|
page: this.pageInfo.title,
|
|
122
122
|
prop: "text|langlinks|categories|links|templates|images|externallinks|sections|revid|displaytitle|iwlinks|properties|parsewarnings",
|
|
123
|
-
...
|
|
123
|
+
...a
|
|
124
124
|
});
|
|
125
125
|
}
|
|
126
|
-
async preview(
|
|
126
|
+
async preview(a, t) {
|
|
127
127
|
return this.parse({
|
|
128
128
|
action: "parse",
|
|
129
129
|
page: void 0,
|
|
130
130
|
title: this.title,
|
|
131
|
-
text:
|
|
131
|
+
text: a,
|
|
132
132
|
pst: 1,
|
|
133
133
|
preview: 1,
|
|
134
134
|
disableeditsection: 1,
|
|
@@ -136,69 +136,69 @@ function b(i) {
|
|
|
136
136
|
...t
|
|
137
137
|
});
|
|
138
138
|
}
|
|
139
|
-
async edit(
|
|
139
|
+
async edit(a, t) {
|
|
140
140
|
const {
|
|
141
|
-
text:
|
|
141
|
+
text: r,
|
|
142
142
|
prependtext: e,
|
|
143
|
-
appendtext:
|
|
143
|
+
appendtext: n,
|
|
144
144
|
summary: l = "",
|
|
145
145
|
watchlist: c = I.preferences,
|
|
146
|
-
section:
|
|
147
|
-
} =
|
|
146
|
+
section: u
|
|
147
|
+
} = a;
|
|
148
148
|
return this.api.postWithEditToken({
|
|
149
149
|
action: "edit",
|
|
150
150
|
title: this.title,
|
|
151
151
|
starttimestamp: this.pageInfo.touched,
|
|
152
152
|
basetimestamp: this.revisions[0]?.timestamp,
|
|
153
|
-
text:
|
|
153
|
+
text: r,
|
|
154
154
|
prependtext: e,
|
|
155
|
-
appendtext:
|
|
155
|
+
appendtext: n,
|
|
156
156
|
summary: l,
|
|
157
157
|
watchlist: c,
|
|
158
|
-
section:
|
|
158
|
+
section: u,
|
|
159
159
|
...t
|
|
160
160
|
});
|
|
161
161
|
}
|
|
162
|
-
async createOnly(
|
|
163
|
-
return this.edit(
|
|
162
|
+
async createOnly(a, t) {
|
|
163
|
+
return this.edit(a, { createonly: 1, ...t });
|
|
164
164
|
}
|
|
165
|
-
async delete(
|
|
165
|
+
async delete(a, t) {
|
|
166
166
|
return this.api.postWithEditToken({
|
|
167
167
|
action: "delete",
|
|
168
168
|
title: this.pageInfo.title || void 0,
|
|
169
169
|
pageid: this.pageInfo.pageid || void 0,
|
|
170
|
-
reason:
|
|
170
|
+
reason: a,
|
|
171
171
|
deletetalk: t?.deletetalk,
|
|
172
172
|
...t
|
|
173
173
|
});
|
|
174
174
|
}
|
|
175
|
-
async moveTo(
|
|
175
|
+
async moveTo(a, t, r) {
|
|
176
176
|
return this.api.postWithEditToken({
|
|
177
177
|
action: "move",
|
|
178
178
|
from: this.pageInfo.title,
|
|
179
|
-
to:
|
|
179
|
+
to: a,
|
|
180
180
|
reason: t,
|
|
181
181
|
movetalk: 1,
|
|
182
182
|
movesubpages: 1,
|
|
183
|
-
...
|
|
183
|
+
...r
|
|
184
184
|
});
|
|
185
185
|
}
|
|
186
186
|
// === utilities ===
|
|
187
|
-
userCan(
|
|
188
|
-
return !!this.pageInfo?.actions?.[
|
|
187
|
+
userCan(a) {
|
|
188
|
+
return !!this.pageInfo?.actions?.[a];
|
|
189
189
|
}
|
|
190
190
|
userCanEdit() {
|
|
191
191
|
return this.userCan("edit");
|
|
192
192
|
}
|
|
193
193
|
async reloadSelfInfo() {
|
|
194
|
-
const
|
|
194
|
+
const a = await s.newFromApi({
|
|
195
195
|
pageids: this.pageInfo.pageid,
|
|
196
196
|
titles: this.pageInfo.title
|
|
197
|
-
}), t = (this.pageInfo.revisions || []).concat(
|
|
198
|
-
(
|
|
197
|
+
}), t = (this.pageInfo.revisions || []).concat(a.revisions || []).sort((r, e) => r.revid - e.revid).reduce(
|
|
198
|
+
(r, e) => (r.find((n) => n.revid === e.revid) || r.push(e), r),
|
|
199
199
|
[]
|
|
200
200
|
);
|
|
201
|
-
return this.pageInfo =
|
|
201
|
+
return this.pageInfo = a.pageInfo, this.pageInfo.revisions = t, this._loaded = !0, this;
|
|
202
202
|
}
|
|
203
203
|
// === sugar getters ===
|
|
204
204
|
get pageid() {
|
|
@@ -241,7 +241,7 @@ const m = /* @__PURE__ */ new WeakMap(), g = {
|
|
|
241
241
|
toDBKey: (i) => i.replace(/ /g, "_"),
|
|
242
242
|
toNormalText: (i) => i.replace(/_/g, " "),
|
|
243
243
|
ensureCase: (i, s) => s === "first-letter" ? i.charAt(0).toUpperCase() + i.slice(1) : i
|
|
244
|
-
},
|
|
244
|
+
}, h = {
|
|
245
245
|
/**
|
|
246
246
|
* 标准化特殊页面名称:转换为全小写
|
|
247
247
|
*/
|
|
@@ -250,29 +250,29 @@ const m = /* @__PURE__ */ new WeakMap(), g = {
|
|
|
250
250
|
* 构建特殊页面别名索引
|
|
251
251
|
*/
|
|
252
252
|
buildSpecialPageIndex: (i) => {
|
|
253
|
-
const s = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(),
|
|
253
|
+
const s = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map();
|
|
254
254
|
for (const t of i.specialpagealiases) {
|
|
255
|
-
const
|
|
256
|
-
s.set(
|
|
257
|
-
const e =
|
|
258
|
-
|
|
259
|
-
for (const
|
|
260
|
-
o.set(
|
|
261
|
-
const l =
|
|
262
|
-
|
|
255
|
+
const r = t.realname;
|
|
256
|
+
s.set(r, r);
|
|
257
|
+
const e = h.normalizeSpecialPageName(r);
|
|
258
|
+
a.set(e, r);
|
|
259
|
+
for (const n of t.aliases) {
|
|
260
|
+
o.set(n, r);
|
|
261
|
+
const l = h.normalizeSpecialPageName(n);
|
|
262
|
+
a.set(l, r);
|
|
263
263
|
}
|
|
264
264
|
}
|
|
265
|
-
return { byRealName: s, byAlias: o, byNormalized:
|
|
265
|
+
return { byRealName: s, byAlias: o, byNormalized: a };
|
|
266
266
|
},
|
|
267
267
|
/**
|
|
268
268
|
* 查找特殊页面的真实名称
|
|
269
269
|
*/
|
|
270
270
|
findSpecialPageRealName: (i, s) => {
|
|
271
271
|
const o = i.split("/")[0];
|
|
272
|
-
let
|
|
273
|
-
if (
|
|
274
|
-
return
|
|
275
|
-
const t =
|
|
272
|
+
let a = s.byRealName.get(o) ?? s.byAlias.get(o);
|
|
273
|
+
if (a !== void 0)
|
|
274
|
+
return a;
|
|
275
|
+
const t = h.normalizeSpecialPageName(o);
|
|
276
276
|
return s.byNormalized.get(t) ?? null;
|
|
277
277
|
}
|
|
278
278
|
}, p = {
|
|
@@ -281,26 +281,26 @@ const m = /* @__PURE__ */ new WeakMap(), g = {
|
|
|
281
281
|
*/
|
|
282
282
|
normalizeNamespaceText: (i) => i.replace(/[_\s]+/g, "_").toLowerCase().replace(/^_+|_+$/g, ""),
|
|
283
283
|
buildIndex: (i) => {
|
|
284
|
-
const s = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(),
|
|
285
|
-
for (const [
|
|
286
|
-
const
|
|
287
|
-
s.set(e.name,
|
|
284
|
+
const s = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Map();
|
|
285
|
+
for (const [r, e] of Object.entries(i.namespaces)) {
|
|
286
|
+
const n = parseInt(r);
|
|
287
|
+
s.set(e.name, n), o.set(e.canonical ?? "", n);
|
|
288
288
|
const l = p.normalizeNamespaceText(e.name), c = p.normalizeNamespaceText(e.canonical ?? "");
|
|
289
|
-
t.set(l,
|
|
289
|
+
t.set(l, n), t.set(c, n);
|
|
290
290
|
}
|
|
291
|
-
for (const
|
|
292
|
-
|
|
293
|
-
const e = p.normalizeNamespaceText(
|
|
294
|
-
t.set(e,
|
|
291
|
+
for (const r of i.namespacealiases) {
|
|
292
|
+
a.set(r.alias, r.id);
|
|
293
|
+
const e = p.normalizeNamespaceText(r.alias);
|
|
294
|
+
t.set(e, r.id);
|
|
295
295
|
}
|
|
296
|
-
return { byName: s, byCanonical: o, byAlias:
|
|
296
|
+
return { byName: s, byCanonical: o, byAlias: a, byNormalized: t };
|
|
297
297
|
},
|
|
298
298
|
findNamespaceId: (i, s) => {
|
|
299
299
|
let o = s.byName.get(i) ?? s.byCanonical.get(i) ?? s.byAlias.get(i);
|
|
300
300
|
if (o !== void 0)
|
|
301
301
|
return o;
|
|
302
|
-
const
|
|
303
|
-
return s.byNormalized.get(
|
|
302
|
+
const a = p.normalizeNamespaceText(i);
|
|
303
|
+
return s.byNormalized.get(a) ?? null;
|
|
304
304
|
},
|
|
305
305
|
isTalkPage: (i) => i % 2 === 1 && i > 0,
|
|
306
306
|
getDefaultNamespaceInfo: (i) => ({
|
|
@@ -317,10 +317,16 @@ function w(i) {
|
|
|
317
317
|
const s = m.get(i);
|
|
318
318
|
if (s)
|
|
319
319
|
return s;
|
|
320
|
-
const o = p.buildIndex(i),
|
|
320
|
+
const o = p.buildIndex(i), a = h.buildSpecialPageIndex(i);
|
|
321
321
|
class t {
|
|
322
|
-
constructor(e,
|
|
323
|
-
if (this.newTitle = t.create.bind(t), this.toText = this.getPrefixedText.bind(this), this.toString = this.getPrefixedDBKey.bind(this), this.#
|
|
322
|
+
constructor(e, n) {
|
|
323
|
+
if (this.newTitle = t.create.bind(t), this.toText = this.getPrefixedText.bind(this), this.toString = this.getPrefixedDBKey.bind(this), this.#t = e || "", this.#e = n ?? 0, n === void 0)
|
|
324
|
+
this.fixNSByTitle();
|
|
325
|
+
else {
|
|
326
|
+
const l = this.parseTitlePrefix(this.#t);
|
|
327
|
+
l && l.namespaceId === this.#e && (this.#t = l.mainTitle);
|
|
328
|
+
}
|
|
329
|
+
if (this.getMainText() === "")
|
|
324
330
|
throw new Error("Invalid title");
|
|
325
331
|
}
|
|
326
332
|
static {
|
|
@@ -330,85 +336,85 @@ function w(i) {
|
|
|
330
336
|
this._namespaceIndex = o;
|
|
331
337
|
}
|
|
332
338
|
static {
|
|
333
|
-
this._specialPageIndex =
|
|
339
|
+
this._specialPageIndex = a;
|
|
334
340
|
}
|
|
335
341
|
/** 缓存的 main title,不包含命名空间前缀,大小写和空格状态不确定 */
|
|
336
|
-
#e;
|
|
337
|
-
/** 缓存的 namespace ID */
|
|
338
342
|
#t;
|
|
339
|
-
|
|
340
|
-
|
|
343
|
+
/** 缓存的 namespace ID */
|
|
344
|
+
#e;
|
|
345
|
+
static create(e, n) {
|
|
346
|
+
return new t(e, n);
|
|
341
347
|
}
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
return;
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
r,
|
|
348
|
+
/**
|
|
349
|
+
* 解析标题前缀,返回匹配到的命名空间 ID 与剥离后的主标题
|
|
350
|
+
*/
|
|
351
|
+
parseTitlePrefix(e) {
|
|
352
|
+
const n = e.indexOf(":");
|
|
353
|
+
if (n <= 0)
|
|
354
|
+
return null;
|
|
355
|
+
const l = e.substring(0, n), c = e.substring(n + 1), u = p.findNamespaceId(
|
|
356
|
+
l,
|
|
352
357
|
t._namespaceIndex
|
|
353
358
|
);
|
|
354
|
-
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
359
|
+
return u === null ? null : { namespaceId: u, mainTitle: c };
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* 如果标题包含可识别命名空间,则采用该命名空间并剥离前缀
|
|
363
|
+
*/
|
|
364
|
+
adoptNamespaceFromTitle() {
|
|
365
|
+
const e = this.parseTitlePrefix(this.#t);
|
|
366
|
+
e && (this.#t = e.mainTitle, this.#e = e.namespaceId);
|
|
367
|
+
}
|
|
368
|
+
fixNSByTitle() {
|
|
369
|
+
const e = this.#t.indexOf(":");
|
|
370
|
+
if (e !== -1) {
|
|
371
|
+
if (e === 0) {
|
|
372
|
+
this.#t = this.#t.substring(1);
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
this.adoptNamespaceFromTitle();
|
|
363
376
|
}
|
|
364
|
-
const r = this.#e.substring(0, e), l = this.#e.substring(e + 1);
|
|
365
|
-
p.findNamespaceId(
|
|
366
|
-
r,
|
|
367
|
-
t._namespaceIndex
|
|
368
|
-
) !== null && (this.#e = l);
|
|
369
377
|
}
|
|
370
378
|
getNamespaceInfo() {
|
|
371
|
-
return t._meta.namespaces[this.#
|
|
379
|
+
return t._meta.namespaces[this.#e] ?? p.getDefaultNamespaceInfo(this.#e);
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* 若为特殊页面,返回解析后的真实主名(含子页面);否则返回 null
|
|
383
|
+
*/
|
|
384
|
+
resolveSpecialFullTitle() {
|
|
385
|
+
if (this.#e !== -1) return null;
|
|
386
|
+
const e = h.findSpecialPageRealName(
|
|
387
|
+
this.#t,
|
|
388
|
+
t._specialPageIndex
|
|
389
|
+
);
|
|
390
|
+
if (!e) return null;
|
|
391
|
+
const n = this.#t.includes("/") ? this.#t.substring(this.#t.indexOf("/")) : "";
|
|
392
|
+
return e + n;
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* 将主标题格式化为输出内容(文本或 DBKey),并做大小写规范化
|
|
396
|
+
*/
|
|
397
|
+
formatMainForOutput(e) {
|
|
398
|
+
const n = this.getNamespaceInfo(), c = this.resolveSpecialFullTitle() ?? this.#t, u = e === "db" ? g.toDBKey(c) : g.toNormalText(c);
|
|
399
|
+
return g.ensureCase(u, n.case);
|
|
372
400
|
}
|
|
373
401
|
getMainDBKey() {
|
|
374
|
-
|
|
375
|
-
if (this.#t === -1) {
|
|
376
|
-
const r = u.findSpecialPageRealName(
|
|
377
|
-
this.#e,
|
|
378
|
-
t._specialPageIndex
|
|
379
|
-
);
|
|
380
|
-
if (r) {
|
|
381
|
-
const l = this.#e.includes("/") ? this.#e.substring(this.#e.indexOf("/")) : "", c = r + l;
|
|
382
|
-
return g.ensureCase(g.toDBKey(c), e.case);
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
return g.ensureCase(g.toDBKey(this.#e), e.case);
|
|
402
|
+
return this.formatMainForOutput("db");
|
|
386
403
|
}
|
|
387
404
|
getMainText() {
|
|
388
|
-
|
|
389
|
-
if (this.#t === -1) {
|
|
390
|
-
const r = u.findSpecialPageRealName(
|
|
391
|
-
this.#e,
|
|
392
|
-
t._specialPageIndex
|
|
393
|
-
);
|
|
394
|
-
if (r) {
|
|
395
|
-
const l = this.#e.includes("/") ? this.#e.substring(this.#e.indexOf("/")) : "", c = r + l;
|
|
396
|
-
return g.ensureCase(g.toNormalText(c), e.case);
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
return g.ensureCase(g.toNormalText(this.#e), e.case);
|
|
405
|
+
return this.formatMainForOutput("text");
|
|
400
406
|
}
|
|
401
407
|
getMainRootText() {
|
|
402
408
|
return this.getMainText().split("/")[0];
|
|
403
409
|
}
|
|
404
410
|
getPrefixedDBKey() {
|
|
405
|
-
return this.#
|
|
411
|
+
return this.#e === 0 ? this.getMainDBKey() : `${this.getNamespaceDBKey()}:${this.getMainDBKey()}`;
|
|
406
412
|
}
|
|
407
413
|
getPrefixedText() {
|
|
408
|
-
return this.#
|
|
414
|
+
return this.#e === 0 ? this.getMainText() : `${this.getNamespaceText()}:${this.getMainText()}`;
|
|
409
415
|
}
|
|
410
416
|
getNamespaceId() {
|
|
411
|
-
return this.#
|
|
417
|
+
return this.#e;
|
|
412
418
|
}
|
|
413
419
|
getNamespaceText() {
|
|
414
420
|
return this.getNamespaceInfo().name ?? "";
|
|
@@ -418,59 +424,73 @@ function w(i) {
|
|
|
418
424
|
return g.ensureCase(g.toDBKey(this.getNamespaceText()), e.case);
|
|
419
425
|
}
|
|
420
426
|
getSubjectPage() {
|
|
421
|
-
if (p.isTalkPage(this.#
|
|
422
|
-
const e = this.#
|
|
423
|
-
return new t(this.#
|
|
427
|
+
if (p.isTalkPage(this.#e)) {
|
|
428
|
+
const e = this.#e - 1;
|
|
429
|
+
return new t(this.#t, e);
|
|
424
430
|
}
|
|
425
431
|
return this;
|
|
426
432
|
}
|
|
427
433
|
getTalkPage() {
|
|
428
|
-
if (p.isTalkPage(this.#
|
|
434
|
+
if (p.isTalkPage(this.#e))
|
|
429
435
|
return this;
|
|
430
|
-
if (this.#
|
|
436
|
+
if (this.#e < 0)
|
|
431
437
|
return null;
|
|
432
|
-
const e = this.#
|
|
433
|
-
return t._meta.namespaces[e.toString()] ? new t(this.#
|
|
438
|
+
const e = this.#e + 1;
|
|
439
|
+
return t._meta.namespaces[e.toString()] ? new t(this.#t, e) : null;
|
|
434
440
|
}
|
|
435
441
|
getURL(e) {
|
|
436
|
-
const
|
|
437
|
-
return
|
|
438
|
-
|
|
439
|
-
|
|
442
|
+
const n = this.getPrefixedDBKey();
|
|
443
|
+
return this.buildArticleURL(n, e);
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* 构建文章 URL 并附加查询参数
|
|
447
|
+
*/
|
|
448
|
+
buildArticleURL(e, n) {
|
|
449
|
+
const c = t._meta.general.articlepath.replace("$1", e), u = new URL(c, location.origin);
|
|
450
|
+
return n && (n instanceof URLSearchParams ? n : new URLSearchParams(n)).forEach((d, f) => {
|
|
451
|
+
u.searchParams.set(f, d);
|
|
452
|
+
}), u;
|
|
440
453
|
}
|
|
441
454
|
/**
|
|
442
455
|
* 设置标题,重置当前实例的 dbkey 和 ns
|
|
443
|
-
*
|
|
456
|
+
* 行为:
|
|
457
|
+
* - 如果标题包含可识别的命名空间前缀,则以该前缀为准更新 ns,并移除前缀
|
|
458
|
+
* - 如果标题前缀与当前 ns 相同,则仅移除冗余前缀并保留当前 ns
|
|
459
|
+
* - 否则(无前缀),重置为主命名空间
|
|
444
460
|
*/
|
|
445
461
|
setTitle(e) {
|
|
446
|
-
|
|
462
|
+
this.#t = e;
|
|
463
|
+
const n = this.#e;
|
|
464
|
+
this.#e = 0;
|
|
465
|
+
const l = this.parseTitlePrefix(this.#t);
|
|
466
|
+
return l ? (n !== 0 && l.namespaceId === n ? (this.#t = l.mainTitle, this.#e = n) : (this.#t = l.mainTitle, this.#e = l.namespaceId), this) : this;
|
|
447
467
|
}
|
|
448
468
|
setMainText(e) {
|
|
449
|
-
return this.#
|
|
469
|
+
return this.#t = e, this;
|
|
450
470
|
}
|
|
451
471
|
setNamespaceText(e) {
|
|
452
|
-
const
|
|
453
|
-
return
|
|
472
|
+
const n = p.findNamespaceId(e, t._namespaceIndex);
|
|
473
|
+
return n !== null && (this.#e = n), this;
|
|
454
474
|
}
|
|
455
475
|
setNamespaceId(e) {
|
|
456
|
-
return this.#
|
|
476
|
+
return this.#e = e, this;
|
|
457
477
|
}
|
|
458
478
|
equals(e) {
|
|
459
479
|
return typeof e == "string" && (e = new t(e)), this.getPrefixedDBKey() === e.getPrefixedDBKey();
|
|
460
480
|
}
|
|
461
481
|
isSpecial(e) {
|
|
462
|
-
if (this.#
|
|
482
|
+
if (this.#e !== -1)
|
|
463
483
|
return !1;
|
|
464
|
-
const
|
|
465
|
-
return this.getMainRootText() ===
|
|
484
|
+
const n = new t(e, -1);
|
|
485
|
+
return this.getMainRootText() === n.getMainRootText();
|
|
466
486
|
}
|
|
467
487
|
toJSON() {
|
|
468
488
|
return {
|
|
469
|
-
ns: this.#
|
|
489
|
+
ns: this.#e,
|
|
470
490
|
text: this.getMainText(),
|
|
471
491
|
title: this.getPrefixedText(),
|
|
472
492
|
url: this.getURL().toString(),
|
|
473
|
-
isSpecial: this.#
|
|
493
|
+
isSpecial: this.#e < 0
|
|
474
494
|
};
|
|
475
495
|
}
|
|
476
496
|
}
|
|
@@ -481,6 +501,6 @@ export {
|
|
|
481
501
|
I as WatchlistAction,
|
|
482
502
|
b as createWikiPageModel,
|
|
483
503
|
w as createWikiTitleModel,
|
|
484
|
-
|
|
504
|
+
N as useMemoryStorage
|
|
485
505
|
};
|
|
486
506
|
//# sourceMappingURL=index.js.map
|