@inpageedit/core 0.5.1 → 0.5.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 (56) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +55 -55
  3. package/dist/ActionButton-BgbTKTg7.js.map +1 -1
  4. package/dist/InputBox-FIzJ-rPN.js.map +1 -1
  5. package/dist/Preferences-Bg3J5Ur9.js.map +1 -1
  6. package/dist/RadioBox-CaA8VgLu.js.map +1 -1
  7. package/dist/components/index.js.map +1 -1
  8. package/dist/decorators/Preferences.d.ts +1 -1
  9. package/dist/{index-Dk3xR25y.js → index-6pczvrx6.js} +15 -15
  10. package/dist/index-6pczvrx6.js.map +1 -0
  11. package/dist/{index-QF8lvEam.js → index-7DsKuWsw.js} +52 -37
  12. package/dist/index-7DsKuWsw.js.map +1 -0
  13. package/dist/index-Bh70Udzi.js.map +1 -1
  14. package/dist/{index-CJLKdEqr.js → index-Bo7FhmY-.js} +3 -3
  15. package/dist/index-Bo7FhmY-.js.map +1 -0
  16. package/dist/{index-BIgWRk98.js → index-C5nqZrGe.js} +1258 -1297
  17. package/dist/{index-BIgWRk98.js.map → index-C5nqZrGe.js.map} +1 -1
  18. package/dist/{index-CBphMyYJ.js → index-CHb2WvLm.js} +1246 -1112
  19. package/dist/index-CHb2WvLm.js.map +1 -0
  20. package/dist/index-Cm67r8TX.js +458 -0
  21. package/dist/index-Cm67r8TX.js.map +1 -0
  22. package/dist/index-CvhkVj_L.js.map +1 -1
  23. package/dist/{index-BMmKF_kG.js → index-DiCrCoWT.js} +6 -6
  24. package/dist/index-DiCrCoWT.js.map +1 -0
  25. package/dist/index-Dnu9H-Aq.js +128 -0
  26. package/dist/index-Dnu9H-Aq.js.map +1 -0
  27. package/dist/{index-DNm9SNqM.js → index-Dz0VGQwY.js} +80 -80
  28. package/dist/{index-DNm9SNqM.js.map → index-Dz0VGQwY.js.map} +1 -1
  29. package/dist/index.js +1 -1
  30. package/dist/models/WikiPage/types/PageInfo.d.ts +2 -0
  31. package/dist/plugins/in-article-links/index.d.ts +29 -0
  32. package/dist/plugins/preferences/index.d.ts +5 -4
  33. package/dist/plugins/quick-edit/index.d.ts +15 -7
  34. package/dist/plugins/quick-preview/index.d.ts +2 -2
  35. package/dist/plugins/toolbox/index.d.ts +14 -4
  36. package/dist/services/ModalService/IPEModal.d.ts +4 -4
  37. package/dist/services/ModalService/index.d.ts +6 -14
  38. package/dist/services/SiteMetadataService.d.ts +3 -2
  39. package/dist/style.css +1 -1
  40. package/dist/utils/computeable.d.ts +2 -0
  41. package/dist/utils/makeCallable.d.ts +3 -0
  42. package/lib/index.umd.js +28 -28
  43. package/lib/index.umd.js.map +1 -1
  44. package/lib/style.css +1 -1
  45. package/package.json +1 -1
  46. package/dist/index-BMmKF_kG.js.map +0 -1
  47. package/dist/index-CBphMyYJ.js.map +0 -1
  48. package/dist/index-CJLKdEqr.js.map +0 -1
  49. package/dist/index-CX5H4xCe.js +0 -142
  50. package/dist/index-CX5H4xCe.js.map +0 -1
  51. package/dist/index-Djd6Ddcm.js +0 -414
  52. package/dist/index-Djd6Ddcm.js.map +0 -1
  53. package/dist/index-Dk3xR25y.js.map +0 -1
  54. package/dist/index-QF8lvEam.js.map +0 -1
  55. package/dist/sleep-DpyIipK-.js +0 -5
  56. package/dist/sleep-DpyIipK-.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"index-CJLKdEqr.js","sources":["../src/plugins/quick-redirect/index.tsx"],"sourcesContent":["import { InPageEdit } from '@/InPageEdit'\r\n\r\ndeclare module '@/InPageEdit' {\r\n interface InPageEdit {\r\n quickRedirect: PluginQuickRedirect['quickRedirect']\r\n redirectPage: PluginQuickRedirect['redirectPage']\r\n }\r\n}\r\n\r\nexport interface RedirectPageOptions {\r\n from: string\r\n to: string\r\n reason?: string\r\n overwrite?: boolean\r\n}\r\nexport interface QuickRedirectOptions extends Partial<RedirectPageOptions> {}\r\n\r\nexport class PluginQuickRedirect extends BasePlugin {\r\n static readonly inject = ['api', 'wikiPage', 'modal']\r\n\r\n constructor(public ctx: InPageEdit) {\r\n super(ctx, {}, 'quick-redirect')\r\n }\r\n\r\n protected start(): Promise<void> | void {\r\n this.ctx.set('quickRedirect', this.quickRedirect.bind(this))\r\n this.ctx.set('redirectPage', this.redirectPage.bind(this))\r\n\r\n const curPageName = window.mw?.config.get('wgPageName') || ''\r\n const canEdit = window.mw?.config.get('wgIsProbablyEditable')\r\n this.ctx.inject(['toolbox'], (ctx) => {\r\n this.ctx = ctx\r\n ctx.toolbox.addButton({\r\n id: 'quick-redirect',\r\n icon: (\r\n <svg\r\n xmlns=\"http://www.w3.org/2000/svg\"\r\n width=\"24\"\r\n height=\"24\"\r\n viewBox=\"0 0 24 24\"\r\n fill=\"none\"\r\n stroke=\"currentColor\"\r\n stroke-width=\"2\"\r\n stroke-linecap=\"round\"\r\n stroke-linejoin=\"round\"\r\n class=\"icon icon-tabler icons-tabler-outline icon-tabler-file-symlink\"\r\n >\r\n <path stroke=\"none\" d=\"M0 0h24v24H0z\" fill=\"none\" />\r\n <path d=\"M4 21v-4a3 3 0 0 1 3 -3h5\" />\r\n <path d=\"M9 17l3 -3l-3 -3\" />\r\n <path d=\"M14 3v4a1 1 0 0 0 1 1h4\" />\r\n <path d=\"M5 11v-6a2 2 0 0 1 2 -2h7l5 5v11a2 2 0 0 1 -2 2h-9.5\" />\r\n </svg>\r\n ) as HTMLElement,\r\n tooltip: 'Quick Redirect',\r\n group: 'group1',\r\n onClick: () => {\r\n this.quickRedirect(\r\n canEdit\r\n ? {\r\n to: curPageName,\r\n }\r\n : {}\r\n )\r\n },\r\n })\r\n this.addDisposeHandler((ctx) => {\r\n ctx.toolbox.removeButton('quick-redirect')\r\n })\r\n })\r\n }\r\n\r\n protected stop(): Promise<void> | void {}\r\n\r\n quickRedirect(options?: Partial<QuickRedirectOptions>) {\r\n const modal = this.ctx.modal\r\n .createObject({\r\n title: 'Quick Redirect',\r\n content: (<ProgressBar />) as HTMLElement,\r\n className: 'quick-redirect compact-buttons',\r\n sizeClass: 'medium',\r\n center: true,\r\n })\r\n .init()\r\n\r\n let formRef: HTMLFormElement | null = null\r\n modal.setContent(\r\n (\r\n <form\r\n ref={(el) => (formRef = el)}\r\n style={{\r\n display: 'flex',\r\n flexDirection: 'column',\r\n gap: '1rem',\r\n }}\r\n onSubmit={(e) => {\r\n e.preventDefault()\r\n formRef?.checkValidity()\r\n if (!formRef?.reportValidity()) {\r\n return\r\n }\r\n const formData = new FormData(formRef!)\r\n const options = {\r\n from: formData.get('from')?.toString().trim()!,\r\n to: formData.get('to')?.toString().trim()!,\r\n reason: (formData.get('reason') as string) || '',\r\n overwrite: formData.get('overwrite') === 'on',\r\n }\r\n if (!options.from || !options.to) {\r\n this.ctx.modal.notify('error', {\r\n title: 'Failed to redirect',\r\n content: 'From and to are required.',\r\n })\r\n return\r\n }\r\n modal.setLoadingState(true)\r\n this.redirectPage(options)\r\n .then((res) => {\r\n modal.close()\r\n this.ctx.modal.notify('success', {\r\n title: 'Redirect successful',\r\n content: 'The redirect has been created.',\r\n })\r\n })\r\n .catch((error) => {\r\n modal.setLoadingState(false)\r\n this.ctx.modal.notify('error', {\r\n title: 'Failed to redirect',\r\n content: error instanceof Error ? error.message : String(error),\r\n })\r\n })\r\n }}\r\n >\r\n <TwinSwapInput\r\n inputs={[\r\n {\r\n label: 'From',\r\n name: 'from',\r\n value: options?.from,\r\n required: true,\r\n },\r\n {\r\n label: 'To',\r\n name: 'to',\r\n value: options?.to,\r\n required: true,\r\n },\r\n ]}\r\n />\r\n <InputBox label=\"Reason\" id=\"reason\" name=\"reason\" value={options?.reason} />\r\n <div>\r\n <CheckBox name=\"overwrite\" id=\"overwrite\" checked={options?.overwrite}>\r\n Force create redirect even if the from page already exists\r\n </CheckBox>\r\n </div>\r\n </form>\r\n ) as HTMLFormElement\r\n )\r\n modal.setButtons([\r\n {\r\n label: 'Create Redirect',\r\n className: 'is-primary is-ghost',\r\n method: () => {\r\n formRef?.dispatchEvent(new Event('submit'))\r\n },\r\n },\r\n ])\r\n\r\n return modal.show()\r\n }\r\n\r\n async redirectPage(options: RedirectPageOptions) {\r\n const { from, to, reason = '', overwrite = false } = options\r\n const wikiPage = await this.ctx.wikiPage.newBlankPage({\r\n title: from,\r\n })\r\n const content = `#REDIRECT [[:${to}]]`\r\n const res = await wikiPage.edit(\r\n {\r\n text: content,\r\n summary: reason,\r\n },\r\n {\r\n createonly: !overwrite,\r\n }\r\n )\r\n if (res.data?.errors) {\r\n throw new Error(res.data.errors[0].text, { cause: res })\r\n }\r\n return res\r\n }\r\n}\r\n"],"names":["PluginQuickRedirect","BasePlugin","ctx","curPageName","canEdit","jsxs","jsx","options","modal","ProgressBar","formRef","el","e","formData","res","error","TwinSwapInput","InputBox","CheckBox","from","to","reason","overwrite","wikiPage","content"],"mappings":";;;;AAiBO,MAAMA,UAA4BC,EAAW;AAAA,EAGlD,YAAmBC,GAAiB;AAClC,UAAMA,GAAK,CAAA,GAAI,gBAAgB,GADd,KAAA,MAAAA;AAAA,EAEnB;AAAA,EAJA,OAAA;AAAA,SAAgB,SAAS,CAAC,OAAO,YAAY,OAAO;AAAA,EAAA;AAAA,EAM1C,QAA8B;AACtC,SAAK,IAAI,IAAI,iBAAiB,KAAK,cAAc,KAAK,IAAI,CAAC,GAC3D,KAAK,IAAI,IAAI,gBAAgB,KAAK,aAAa,KAAK,IAAI,CAAC;AAEzD,UAAMC,IAAc,OAAO,IAAI,OAAO,IAAI,YAAY,KAAK,IACrDC,IAAU,OAAO,IAAI,OAAO,IAAI,sBAAsB;AAC5D,SAAK,IAAI,OAAO,CAAC,SAAS,GAAG,CAACF,MAAQ;AACpC,WAAK,MAAMA,GACXA,EAAI,QAAQ,UAAU;AAAA,QACpB,IAAI;AAAA,QACJ,MACEG,gBAAAA;AAAAA,UAAC;AAAA,UAAA;AAAA,YACC,OAAM;AAAA,YACN,OAAM;AAAA,YACN,QAAO;AAAA,YACP,SAAQ;AAAA,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ACZ;AAAA,cACF;AAAA,YAAA;AAAA,YAEF,gBAAAD,EAACW,GAAA,EAAS,OAAM,UAAS,IAAG,UAAS,MAAK,UAAS,OAAOV,GAAS,OAAA,CAAQ;AAAA,YAC3E,gBAAAD,EAAC,OAAA,EACC,UAAA,gBAAAA,EAACY,GAAA,EAAS,MAAK,aAAY,IAAG,aAAY,SAASX,GAAS,WAAW,UAAA,6DAAA,CAEvE,EAAA,CACF;AAAA,UAAA;AAAA,QAAA;AAAA,MAAA;AAAA,IACF,GAGJC,EAAM,WAAW;AAAA,MACf;AAAA,QACE,OAAO;AAAA,QACP,WAAW;AAAA,QACX,QAAQ,MAAM;AACZ,UAAAE,GAAS,cAAc,IAAI,MAAM,QAAQ,CAAC;AAAA,QAC5C;AAAA,MAAA;AAAA,IACF,CACD,GAEMF,EAAM,KAAA;AAAA,EACf;AAAA,EAEA,MAAM,aAAaD,GAA8B;AAC/C,UAAM,EAAE,MAAAY,GAAM,IAAAC,GAAI,QAAAC,IAAS,IAAI,WAAAC,IAAY,OAAUf,GAC/CgB,IAAW,MAAM,KAAK,IAAI,SAAS,aAAa;AAAA,MACpD,OAAOJ;AAAA,IAAA,CACR,GACKK,IAAU,gBAAgBJ,CAAE,MAC5BN,IAAM,MAAMS,EAAS;AAAA,MACzB;AAAA,QACE,MAAMC;AAAA,QACN,SAASH;AAAA,MAAA;AAAA,MAEX;AAAA,QACE,YAAY,CAACC;AAAA,MAAA;AAAA,IACf;AAEF,QAAIR,EAAI,MAAM;AACZ,YAAM,IAAI,MAAMA,EAAI,KAAK,OAAO,CAAC,EAAE,MAAM,EAAE,OAAOA,GAAK;AAEzD,WAAOA;AAAA,EACT;AACF;"}
@@ -1,142 +0,0 @@
1
- import { j as n } from "./index-CvhkVj_L.js";
2
- import { b as C, a as A, S as v } from "./index-CBphMyYJ.js";
3
- import { R as B } from "./Preferences-Bg3J5Ur9.js";
4
- import { s as I } from "./sleep-DpyIipK-.js";
5
- var j = Object.create, x = Object.defineProperty, q = Object.getOwnPropertyDescriptor, w = (t, e) => (e = Symbol[t]) ? e : Symbol.for("Symbol." + t), _ = (t) => {
6
- throw TypeError(t);
7
- }, z = (t, e, o) => e in t ? x(t, e, { enumerable: !0, configurable: !0, writable: !0, value: o }) : t[e] = o, M = (t, e) => x(t, "name", { value: e, configurable: !0 }), E = (t) => [, , , j(t?.[w("metadata")] ?? null)], T = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"], y = (t) => t !== void 0 && typeof t != "function" ? _("Function expected") : t, $ = (t, e, o, i, r) => ({ kind: T[t], name: e, metadata: i, addInitializer: (l) => o._ ? _("Already initialized") : r.push(y(l || null)) }), N = (t, e) => z(e, w("metadata"), t[3]), O = (t, e, o, i) => {
8
- for (var r = 0, l = t[e >> 1], d = l && l.length; r < d; r++) l[r].call(o);
9
- return i;
10
- }, L = (t, e, o, i, r, l) => {
11
- var d, b, p, a = e & 7, s = !1, c = 0, g = t[c] || (t[c] = []), u = a && (r = r.prototype, a < 5 && (a > 3 || !s) && q(r, o));
12
- M(r, o);
13
- for (var h = i.length - 1; h >= 0; h--)
14
- p = $(a, o, b = {}, t[3], g), d = (0, i[h])(r, p), b._ = 1, y(d) && (r = d);
15
- return N(t, r), u && x(r, o, u), s ? a ^ 4 ? l : u : r;
16
- }, S, m, k;
17
- S = [B(
18
- v.object({
19
- toolboxAlwaysShow: v.boolean().description("Make the toolbox opened by default").default(!1)
20
- }).description("Toolbox preferences"),
21
- {
22
- toolboxAlwaysShow: !1
23
- }
24
- ), A(["preferences"])];
25
- class f extends (k = C) {
26
- constructor(e) {
27
- super(e, "toolbox", !1), this.ctx = e, this.container = void 0, this.forceShow = !1;
28
- }
29
- async start() {
30
- mw && mw.config.get("wgIsArticle") === !1 && !this.forceShow ? this.container = this.createIndicatorForNotArticlePage() : this.container = this.createToolbox(), document.body.appendChild(this.container), await I(0), this.ctx.preferences.get("toolboxAlwaysShow").then((e) => {
31
- e && (this.container.querySelector("#toolbox-toggle")?.classList.add("opened"), this.container.querySelectorAll(".btn-group").forEach((o) => {
32
- o.classList.add("opened");
33
- }));
34
- });
35
- }
36
- stop() {
37
- this.container?.remove();
38
- }
39
- createToolbox() {
40
- const o = /* @__PURE__ */ n("div", { id: "ipe-edit-toolbox", children: [
41
- /* @__PURE__ */ n("ul", { className: "btn-group group1", style: { display: "flex", flexDirection: "column" } }),
42
- /* @__PURE__ */ n("ul", { className: "btn-group group2", style: { display: "flex", flexDirection: "row" } }),
43
- /* @__PURE__ */ n(
44
- "button",
45
- {
46
- className: "ipe-toolbox-btn",
47
- id: "toolbox-toggle",
48
- onClick: function(i) {
49
- const r = this.classList.contains("opened");
50
- this.classList.toggle("opened", !r), o.querySelectorAll(".btn-group").forEach((l) => {
51
- l.classList.toggle("opened", !r);
52
- });
53
- },
54
- children: /* @__PURE__ */ n(
55
- "svg",
56
- {
57
- xmlns: "http://www.w3.org/2000/svg",
58
- width: "24",
59
- height: "24",
60
- viewBox: "0 0 24 24",
61
- fill: "none",
62
- stroke: "currentColor",
63
- "stroke-width": "2",
64
- "stroke-linecap": "round",
65
- "stroke-linejoin": "round",
66
- class: "icon icon-tabler icons-tabler-outline icon-tabler-plus",
67
- children: [
68
- /* @__PURE__ */ n("path", { stroke: "none", d: "M0 0h24v24H0z", fill: "none" }),
69
- /* @__PURE__ */ n("path", { d: "M12 5l0 14" }),
70
- /* @__PURE__ */ n("path", { d: "M5 12l14 0" })
71
- ]
72
- }
73
- )
74
- }
75
- )
76
- ] });
77
- return o;
78
- }
79
- createIndicatorForNotArticlePage() {
80
- return /* @__PURE__ */ n("div", { id: "ipe-edit-toolbox", children: /* @__PURE__ */ n(
81
- "div",
82
- {
83
- id: "ipe-toolbox-placeholder",
84
- style: "width: 0.75rem; height: 0.75rem; border-radius: 50%; background: #3f51b5; color: #fff; pointer-events: none;",
85
- children: /* @__PURE__ */ n(
86
- "svg",
87
- {
88
- style: "width: 0.5em; height: 0.5em; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);",
89
- xmlns: "http://www.w3.org/2000/svg",
90
- width: "24",
91
- height: "24",
92
- viewBox: "0 0 24 24",
93
- fill: "none",
94
- stroke: "currentColor",
95
- "stroke-width": "4",
96
- "stroke-linecap": "round",
97
- "stroke-linejoin": "round",
98
- class: "icon icon-tabler icons-tabler-outline icon-tabler-check",
99
- children: [
100
- /* @__PURE__ */ n("path", { stroke: "none", d: "M0 0h24v24H0z", fill: "none" }),
101
- /* @__PURE__ */ n("path", { d: "M5 12l5 5l10 -10" })
102
- ]
103
- }
104
- )
105
- }
106
- ) });
107
- }
108
- normalizeButtonId(e) {
109
- return e || (e = Math.random().toString(36).substring(2, 8)), `ipe-toolbox__${e.trim()}`.replace(/\s\.#/g, "-");
110
- }
111
- addButton(e) {
112
- let { id: o, group: i, icon: r, tooltip: l, buttonProps: d, onClick: b, index: p } = e;
113
- o = this.normalizeButtonId(o);
114
- const a = this.container.querySelector(`#${o}`);
115
- a && (this.ctx.logger("toolbox").warn(`Button with id ${o} already exists, replacing it.`), a.remove());
116
- let s = null;
117
- if (typeof i > "u" || i === "auto") {
118
- const g = this.container.querySelector(".btn-group.group1"), u = this.container.querySelector(".btn-group.group2"), h = g?.children.length || 0, P = u?.children.length || 0;
119
- s = h <= P ? g : u;
120
- } else
121
- s = this.container.querySelector(`.btn-group.${i}`);
122
- if (!s) throw new Error(`Button group ${i} not found`);
123
- const c = /* @__PURE__ */ n("li", { class: "btn-tip-group", id: o, onClick: b, children: [
124
- /* @__PURE__ */ n("div", { class: "btn-tip", children: l }),
125
- /* @__PURE__ */ n("button", { id: `${o}-btn`, class: "ipe-toolbox-btn", ...d, children: r })
126
- ] });
127
- return typeof p == "number" ? p <= 0 ? s.prepend(c) : p >= s.children.length ? s.appendChild(c) : s.children[p]?.before(c) : s.appendChild(c), this.ctx.emit("toolbox/button/added", {
128
- ctx: this.ctx,
129
- button: c
130
- }), c;
131
- }
132
- removeButton(e) {
133
- this.container.querySelector(`.ipe-toolbox-btn#${e}`)?.remove(), this.ctx.emit("toolbox/button/removed", { ctx: this.ctx, id: e });
134
- }
135
- }
136
- m = E(k);
137
- f = L(m, 0, "PluginToolbox", S, f);
138
- O(m, 1, f);
139
- export {
140
- f as PluginToolbox
141
- };
142
- //# sourceMappingURL=index-CX5H4xCe.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index-CX5H4xCe.js","sources":["../src/plugins/toolbox/index.tsx"],"sourcesContent":["import { Inject, InPageEdit, Schema, Service } from '@/InPageEdit'\r\nimport { ReactElement } from 'jsx-dom'\r\nimport './styles.scss'\r\n\r\ndeclare module '@/InPageEdit' {\r\n interface InPageEdit {\r\n toolbox: PluginToolbox\r\n }\r\n interface Events {\r\n 'toolbox/button/added'(payload: { ctx: InPageEdit; button: HTMLElement }): void\r\n 'toolbox/button/removed'(payload: { ctx: InPageEdit; id: string }): void\r\n }\r\n}\r\n\r\n@RegisterPreferences(\r\n Schema.object({\r\n toolboxAlwaysShow: Schema.boolean()\r\n .description('Make the toolbox opened by default')\r\n .default(false),\r\n }).description('Toolbox preferences'),\r\n {\r\n toolboxAlwaysShow: false,\r\n }\r\n)\r\n@Inject(['preferences'])\r\nexport class PluginToolbox extends Service {\r\n container!: HTMLElement\r\n private forceShow = false\r\n\r\n constructor(public ctx: InPageEdit) {\r\n super(ctx, 'toolbox', false)\r\n }\r\n\r\n protected async start(): Promise<void> {\r\n if (mw && mw.config.get('wgIsArticle') === false && !this.forceShow) {\r\n this.container = this.createIndicatorForNotArticlePage()\r\n } else {\r\n this.container = this.createToolbox()\r\n }\r\n document.body.appendChild(this.container)\r\n await sleep(0) // wait nextTick\r\n this.ctx.preferences.get('toolboxAlwaysShow').then((val) => {\r\n if (val) {\r\n this.container.querySelector('#toolbox-toggle')?.classList.add('opened')\r\n this.container.querySelectorAll('.btn-group').forEach((el) => {\r\n el.classList.add('opened')\r\n })\r\n }\r\n })\r\n }\r\n\r\n protected stop(): void | Promise<void> {\r\n this.container?.remove()\r\n }\r\n\r\n private createToolbox() {\r\n const toggler = (\r\n <button\r\n className=\"ipe-toolbox-btn\"\r\n id=\"toolbox-toggle\"\r\n onClick={function (e) {\r\n const isOpened = this.classList.contains('opened')\r\n this.classList.toggle('opened', !isOpened)\r\n element.querySelectorAll('.btn-group').forEach((el) => {\r\n el.classList.toggle('opened', !isOpened)\r\n })\r\n }}\r\n >\r\n <svg\r\n xmlns=\"http://www.w3.org/2000/svg\"\r\n width=\"24\"\r\n height=\"24\"\r\n viewBox=\"0 0 24 24\"\r\n fill=\"none\"\r\n stroke=\"currentColor\"\r\n stroke-width=\"2\"\r\n stroke-linecap=\"round\"\r\n stroke-linejoin=\"round\"\r\n class=\"icon icon-tabler icons-tabler-outline icon-tabler-plus\"\r\n >\r\n <path stroke=\"none\" d=\"M0 0h24v24H0z\" fill=\"none\" />\r\n <path d=\"M12 5l0 14\" />\r\n <path d=\"M5 12l14 0\" />\r\n </svg>\r\n </button>\r\n )\r\n const element = (\r\n <div id=\"ipe-edit-toolbox\">\r\n <ul className=\"btn-group group1\" style={{ display: 'flex', flexDirection: 'column' }}></ul>\r\n <ul className=\"btn-group group2\" style={{ display: 'flex', flexDirection: 'row' }}></ul>\r\n {toggler}\r\n </div>\r\n )\r\n\r\n return element as HTMLElement\r\n }\r\n\r\n private createIndicatorForNotArticlePage() {\r\n const indicator = (\r\n <div id=\"ipe-edit-toolbox\">\r\n <div\r\n id=\"ipe-toolbox-placeholder\"\r\n style=\"width: 0.75rem; height: 0.75rem; border-radius: 50%; background: #3f51b5; color: #fff; pointer-events: none;\"\r\n >\r\n <svg\r\n style=\"width: 0.5em; height: 0.5em; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);\"\r\n xmlns=\"http://www.w3.org/2000/svg\"\r\n width=\"24\"\r\n height=\"24\"\r\n viewBox=\"0 0 24 24\"\r\n fill=\"none\"\r\n stroke=\"currentColor\"\r\n stroke-width=\"4\"\r\n stroke-linecap=\"round\"\r\n stroke-linejoin=\"round\"\r\n class=\"icon icon-tabler icons-tabler-outline icon-tabler-check\"\r\n >\r\n <path stroke=\"none\" d=\"M0 0h24v24H0z\" fill=\"none\" />\r\n <path d=\"M5 12l5 5l10 -10\" />\r\n </svg>\r\n </div>\r\n </div>\r\n )\r\n return indicator as HTMLElement\r\n }\r\n\r\n private normalizeButtonId(id: string) {\r\n if (!id) {\r\n id = Math.random().toString(36).substring(2, 8)\r\n }\r\n return `ipe-toolbox__${id.trim()}`.replace(/\\s\\.#/g, '-')\r\n }\r\n\r\n addButton(payload: {\r\n id: string\r\n group?: 'auto' | 'group1' | 'group2'\r\n icon: string | HTMLElement | SVGElement | ReactElement\r\n tooltip?: string | HTMLElement\r\n buttonProps?: Record<string, any>\r\n onClick?: (event: MouseEvent) => void\r\n index?: number\r\n }) {\r\n let { id, group, icon, tooltip, buttonProps, onClick, index } = payload\r\n id = this.normalizeButtonId(id)\r\n\r\n const existingButton = this.container.querySelector(`#${id}`)\r\n if (existingButton) {\r\n this.ctx.logger('toolbox').warn(`Button with id ${id} already exists, replacing it.`)\r\n existingButton.remove()\r\n }\r\n\r\n let groupEl: HTMLElement | null = null\r\n if (typeof group === 'undefined' || group === 'auto') {\r\n // 选择按钮最少的那一组,一样多就选第一组\r\n const group1 = this.container.querySelector('.btn-group.group1') as HTMLElement\r\n const group2 = this.container.querySelector('.btn-group.group2') as HTMLElement\r\n const group1Count = group1?.children.length || 0\r\n const group2Count = group2?.children.length || 0\r\n groupEl = group1Count <= group2Count ? group1 : group2\r\n } else {\r\n groupEl = this.container.querySelector(`.btn-group.${group}`)\r\n }\r\n if (!groupEl) throw new Error(`Button group ${group} not found`)\r\n\r\n const button = (\r\n <li class=\"btn-tip-group\" id={id} onClick={onClick}>\r\n <div class=\"btn-tip\">{tooltip}</div>\r\n <button id={`${id}-btn`} class=\"ipe-toolbox-btn\" {...buttonProps}>\r\n {icon}\r\n </button>\r\n </li>\r\n )\r\n\r\n if (typeof index === 'number') {\r\n if (index <= 0) {\r\n groupEl.prepend(button)\r\n } else if (index >= groupEl.children.length) {\r\n groupEl.appendChild(button)\r\n } else {\r\n groupEl.children[index]?.before(button)\r\n }\r\n } else {\r\n groupEl.appendChild(button)\r\n }\r\n\r\n this.ctx.emit('toolbox/button/added', {\r\n ctx: this.ctx,\r\n button: button as HTMLElement,\r\n })\r\n\r\n return button as HTMLElement\r\n }\r\n\r\n removeButton(id: string) {\r\n const button = this.container.querySelector(`.ipe-toolbox-btn#${id}`)\r\n button?.remove()\r\n this.ctx.emit('toolbox/button/removed', { ctx: this.ctx, id })\r\n }\r\n}\r\n"],"names":["_PluginToolbox_decorators","_init","_a","RegisterPreferences","Schema","Inject","PluginToolbox","Service","ctx","sleep","val","el","element","jsxs","jsx","e","isOpened","id","payload","group","icon","tooltip","buttonProps","onClick","index","existingButton","groupEl","group1","group2","group1Count","group2Count","button","__decoratorStart","__decorateElement","__runInitializers"],"mappings":";;;;;;;;;;;;;;;GAAAA,GAAAC,GAAAC;AAcAF,IAAA,CAACG;AAAA,EACCC,EAAO,OAAO;AAAA,IACZ,mBAAmBA,EAAO,QAAA,EACvB,YAAY,oCAAoC,EAChD,QAAQ,EAAK;AAAA,EAAA,CACjB,EAAE,YAAY,qBAAqB;AAAA,EACpC;AAAA,IACE,mBAAmB;AAAA,EAAA;AAEvB,GACCC,EAAO,CAAC,aAAa,CAAC,CAAA;AAChB,MAAMC,WAAsBJ,IAAAK,GAAQ;AAAA,EAIzC,YAAmBC,GAAiB;AAClC,UAAMA,GAAK,WAAW,EAAK,GADV,KAAA,MAAAA,GAHnB,KAAA,YAAA,QACA,KAAQ,YAAY;AAAA,EAIpB;AAAA,EAEA,MAAgB,QAAuB;AACrC,IAAI,MAAM,GAAG,OAAO,IAAI,aAAa,MAAM,MAAS,CAAC,KAAK,YACxD,KAAK,YAAY,KAAK,iCAAA,IAEtB,KAAK,YAAY,KAAK,cAAA,GAExB,SAAS,KAAK,YAAY,KAAK,SAAS,GACxC,MAAMC,EAAM,CAAC,GACb,KAAK,IAAI,YAAY,IAAI,mBAAmB,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AK,0BAA0B,EAAE,KAAK,KAAK,KAAK,IAAAA,GAAI;AAAA,EAC/D;AACF;AA7KOhB,IAAA+B,EAAA9B,CAAA;AAAMI,IAAN2B,yBAXPjC,GAWaM,CAAA;AAAN4B,EAAAjC,GAAA,GAAMK,CAAA;"}
@@ -1,414 +0,0 @@
1
- import { j as s, F as E, P as U } from "./index-CvhkVj_L.js";
2
- import { B as I, a as A, S as h, W as m } from "./index-CBphMyYJ.js";
3
- import { R as C } from "./Preferences-Bg3J5Ur9.js";
4
- import { M as D, R as Q } from "./RadioBox-CaA8VgLu.js";
5
- import { I as z, C as y } from "./InputBox-FIzJ-rPN.js";
6
- import { s as R } from "./sleep-DpyIipK-.js";
7
- var W = Object.create, x = Object.defineProperty, H = Object.getOwnPropertyDescriptor, q = (t, e) => (e = Symbol[t]) ? e : Symbol.for("Symbol." + t), $ = (t) => {
8
- throw TypeError(t);
9
- }, X = (t, e, r) => e in t ? x(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r, Y = (t, e) => x(t, "name", { value: e, configurable: !0 }), G = (t) => [, , , W(t?.[q("metadata")] ?? null)], K = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"], L = (t) => t !== void 0 && typeof t != "function" ? $("Function expected") : t, J = (t, e, r, a, i) => ({ kind: K[t], name: e, metadata: a, addInitializer: (c) => r._ ? $("Already initialized") : i.push(L(c || null)) }), V = (t, e) => X(e, q("metadata"), t[3]), Z = (t, e, r, a) => {
10
- for (var i = 0, c = t[e >> 1], o = c && c.length; i < o; i++) c[i].call(r);
11
- return a;
12
- }, ee = (t, e, r, a, i, c) => {
13
- var o, n, u, d = e & 7, p = !1, l = 0, g = t[l] || (t[l] = []), f = d && (i = i.prototype, d < 5 && (d > 3 || !p) && H(i, r));
14
- Y(i, r);
15
- for (var v = a.length - 1; v >= 0; v--)
16
- u = J(d, r, n = {}, t[3], g), o = (0, a[v])(i, u), n._ = 1, L(o) && (i = o);
17
- return V(t, i), f && x(i, r, f), p ? d ^ 4 ? c : f : i;
18
- }, M, _, N;
19
- M = [A(["sitemeta", "quickEdit"]), C(
20
- h.object({
21
- redLinkEdit: h.boolean().description("Show quick edit entry after red links").default(!0)
22
- }).description("In-article quick edit links"),
23
- {
24
- redLinkEdit: !0
25
- }
26
- )];
27
- class w extends (N = I) {
28
- constructor(e) {
29
- const r = e.sitemeta.mwConfig, a = r.wgArticlePath.replace("$1", ""), i = `${location.protocol}//${r.wgServer.split("//")[1]}`;
30
- super(
31
- e,
32
- {
33
- wikiBaseUrl: i,
34
- wikiArticlePath: a,
35
- wikiArticleBaseUrl: `${i}${a}`,
36
- wikiScriptBaseUrl: `${i}${r.wgScriptPath}`,
37
- linkClassName: "ipe-quickEdit__in-article-link"
38
- },
39
- "QuickEditInArticleLinks"
40
- );
41
- }
42
- async start() {
43
- mw.hook("wikipage.content").add(() => {
44
- document.querySelectorAll("#mw-content-text a[href]").forEach((r) => {
45
- const a = this.checkEditAnchor(r);
46
- if (!a || r.dataset.ipeQuickEditLink)
47
- return;
48
- const i = /* @__PURE__ */ s(
49
- "a",
50
- {
51
- href: `#/IPE/quickEdit/${a.title}`,
52
- className: this.config.linkClassName,
53
- style: {
54
- userSelect: "none",
55
- marginLeft: "0.2em",
56
- verticalAlign: "middle"
57
- },
58
- onClick: (c) => {
59
- c.preventDefault(), this.ctx.quickEdit(a);
60
- },
61
- children: /* @__PURE__ */ s(
62
- "svg",
63
- {
64
- style: "width: 1em; height: 1em",
65
- xmlns: "http://www.w3.org/2000/svg",
66
- width: "24",
67
- height: "24",
68
- viewBox: "0 0 24 24",
69
- fill: "none",
70
- stroke: "currentColor",
71
- "stroke-width": "2",
72
- "stroke-linecap": "round",
73
- "stroke-linejoin": "round",
74
- class: "icon icon-tabler icons-tabler-outline icon-tabler-pencil-bolt",
75
- children: [
76
- /* @__PURE__ */ s("path", { stroke: "none", d: "M0 0h24v24H0z", fill: "none" }),
77
- /* @__PURE__ */ s("path", { d: "M4 20h4l10.5 -10.5a2.828 2.828 0 1 0 -4 -4l-10.5 10.5v4" }),
78
- /* @__PURE__ */ s("path", { d: "M13.5 6.5l4 4" }),
79
- /* @__PURE__ */ s("path", { d: "M19 16l-2 3h4l-2 3" })
80
- ]
81
- }
82
- )
83
- }
84
- );
85
- r.insertAdjacentElement("afterend", i), r.dataset.ipeQuickEditLink = "true";
86
- });
87
- });
88
- }
89
- stop() {
90
- document.querySelectorAll(`.${this.config.linkClassName}`).forEach((e) => e.remove());
91
- }
92
- checkEditAnchor(e) {
93
- if (!(e instanceof HTMLAnchorElement))
94
- return null;
95
- const r = e.href || "";
96
- if (!r.startsWith(this.config.wikiArticleBaseUrl) && !r.startsWith(this.config.wikiScriptBaseUrl))
97
- return null;
98
- const a = new URL(r), i = a.searchParams, c = i.get("action") || "view", o = i.get("title") || decodeURI(a.pathname.substring(this.config.wikiArticlePath.length)) || "", n = i.get("section")?.replace(/^T-/, "") || void 0, u = i.get("oldid");
99
- if (
100
- // 不合法的 title
101
- !o || o.endsWith(".php") || // 不是 edit 相关操作
102
- !["edit", "editsource", "editredlink", "submit"].includes(c) || // 暂时未兼容 undo
103
- i.get("undo") || // 暂时未兼容 preload
104
- i.get("preload")
105
- )
106
- return null;
107
- let d;
108
- return n === "new" ? d = "new" : n && /^\d+$/.test(n) && (d = parseInt(n, 10)), {
109
- title: o,
110
- section: d,
111
- revision: parseInt("" + u, 10) || 0,
112
- createOnly: !!i.get("redlink")
113
- };
114
- }
115
- }
116
- _ = G(N);
117
- w = ee(_, 0, "PluginQuickEditInArticleLinks", M, w);
118
- Z(_, 1, w);
119
- const P = () => {
120
- };
121
- var te = Object.create, b = Object.defineProperty, ie = Object.getOwnPropertyDescriptor, O = (t, e) => (e = Symbol[t]) ? e : Symbol.for("Symbol." + t), B = (t) => {
122
- throw TypeError(t);
123
- }, re = (t, e, r) => e in t ? b(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r, ne = (t, e) => b(t, "name", { value: e, configurable: !0 }), oe = (t) => [, , , te(t?.[O("metadata")] ?? null)], se = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"], T = (t) => t !== void 0 && typeof t != "function" ? B("Function expected") : t, ae = (t, e, r, a, i) => ({ kind: se[t], name: e, metadata: a, addInitializer: (c) => r._ ? B("Already initialized") : i.push(T(c || null)) }), ce = (t, e) => re(e, O("metadata"), t[3]), le = (t, e, r, a) => {
124
- for (var i = 0, c = t[e >> 1], o = c && c.length; i < o; i++) c[i].call(r);
125
- return a;
126
- }, de = (t, e, r, a, i, c) => {
127
- var o, n, u, d = e & 7, p = !1, l = 0, g = t[l] || (t[l] = []), f = d && (i = i.prototype, d < 5 && (d > 3 || !p) && ie(i, r));
128
- ne(i, r);
129
- for (var v = a.length - 1; v >= 0; v--)
130
- u = ae(d, r, n = {}, t[3], g), o = (0, a[v])(i, u), n._ = 1, T(o) && (i = o);
131
- return ce(t, i), f && b(i, r, f), p ? d ^ 4 ? c : f : i;
132
- }, j, S, F;
133
- j = [A(["api", "wikiPage", "modal", "preferences"]), C(
134
- h.object({
135
- editSummary: h.string().description("Default edit summary for quick edits").default("[IPE-NEXT] Quick edit"),
136
- editMinor: h.boolean().description("Whether to mark the edit as minor").default(!1),
137
- outSideClose: h.boolean().description("Whether to close the modal outside").default(!0),
138
- watchList: h.union([
139
- h.const(m.preferences).description("Follow my preferences"),
140
- h.const(m.nochange).description("Keep the current watchlist status"),
141
- h.const(m.watch).description("Add the page to watchlist"),
142
- h.const(m.unwatch).description("Remove the page from watchlist")
143
- ]).description("Watchlist options").default(m.preferences)
144
- }).description("Quick edit options").extra("category", "edit"),
145
- {
146
- editSummary: "[IPE-NEXT] Quick edit",
147
- editMinor: !1,
148
- outSideClose: !0,
149
- watchList: m.preferences
150
- }
151
- )];
152
- class k extends (F = I) {
153
- constructor(e) {
154
- super(e, {}, "quick-edit"), this.ctx = e, this.DEFAULT_OPTIONS = {
155
- title: "",
156
- pageId: 0,
157
- revision: 0,
158
- section: void 0,
159
- editMinor: !1,
160
- editSummary: "",
161
- createOnly: !1,
162
- reloadAfterSave: !0
163
- };
164
- }
165
- start() {
166
- this.ctx.root.set("quickEdit", this.quickEdit.bind(this)), this.ctx.inject(["toolbox"], (e) => {
167
- this.injectToolbox(e), e.on("dispose", () => {
168
- this.removeToolbox(e);
169
- });
170
- }), this.ctx.plugin(w);
171
- }
172
- async quickEdit(e) {
173
- typeof e > "u" ? e = {} : typeof e == "string" && (e = {
174
- title: e
175
- }), e?.page && (e.title = e.page, delete e.page), !e.title && !e.pageId && !e.revision && (this.logger.warn("None of the title, pageId or revision provided. Using defaults."), e = {
176
- ...e,
177
- title: mw.config.get("wgPageName"),
178
- pageId: mw.config.get("wgArticleId"),
179
- revision: mw.config.get("wgRevisionId")
180
- });
181
- const r = await this.ctx.preferences.get("outSideClose"), a = await this.ctx.preferences.get("watchList"), i = typeof e.editSummary == "string" ? e.editSummary : await this.ctx.preferences.get("editSummary"), c = typeof e.editMinor == "boolean" ? e.editMinor : await this.ctx.preferences.get("editMinor"), o = {
182
- ...this.DEFAULT_OPTIONS,
183
- editSummary: i,
184
- editMinor: c,
185
- ...e
186
- };
187
- o.editSummary || (o.editSummary = await this.ctx.preferences.get("editSummary") || ""), o || this.ctx.emit("quickEdit/initOptions", { ctx: this.ctx, options: o });
188
- const n = this.ctx.modal.createObject({
189
- className: "ipe-quickEdit",
190
- sizeClass: "large",
191
- // backdrop: false,
192
- // draggable: true,
193
- center: !1,
194
- outSideClose: r
195
- }).init();
196
- n.setTitle(
197
- /* @__PURE__ */ s(E, { children: [
198
- "Loading: ",
199
- /* @__PURE__ */ s("u", { children: o.title })
200
- ] })
201
- ), n.setContent(
202
- /* @__PURE__ */ s(
203
- "section",
204
- {
205
- className: "ipe-quickEdit-loading",
206
- style: {
207
- height: "70vh",
208
- display: "flex",
209
- flexDirection: "column",
210
- justifyContent: "center",
211
- alignItems: "center"
212
- },
213
- children: /* @__PURE__ */ s(U, {})
214
- }
215
- )
216
- ), n.addButton({
217
- side: "right",
218
- type: "button",
219
- className: "is-danger is-ghost",
220
- label: "Cancel",
221
- method() {
222
- n.close();
223
- }
224
- }), n.show(), this.ctx.emit("quickEdit/showModal", { ctx: this.ctx, modal: n, options: o });
225
- let u;
226
- try {
227
- u = await this.getWikiPageFromPayload(o);
228
- } catch (l) {
229
- n.close(), this.ctx.modal.notify("error", {
230
- title: "Error",
231
- content: l instanceof Error ? l.message : String(l)
232
- });
233
- return;
234
- }
235
- n.setTitle(
236
- /* @__PURE__ */ s(E, { children: [
237
- "Quick ",
238
- u.pageInfo.pageid === 0 ? "Create" : "Edit",
239
- ":",
240
- " ",
241
- /* @__PURE__ */ s("u", { children: u.pageInfo.title })
242
- ] })
243
- );
244
- const d = /* @__PURE__ */ s("form", { className: "ipe-quickEdit-form", children: [
245
- u.pageInfo.pageid === 0 && /* @__PURE__ */ s(D, { title: "Attention", type: "important", children: /* @__PURE__ */ s("p", { children: "This page does not exist." }) }),
246
- /* @__PURE__ */ s("textarea", { className: "editArea", name: "text", id: "wpTextbox1", children: u.revisions[0]?.content || "" }),
247
- /* @__PURE__ */ s(
248
- "div",
249
- {
250
- class: "ipe-quickEdit-options",
251
- style: {
252
- display: "flex",
253
- flexDirection: "column",
254
- gap: "1rem",
255
- marginTop: "1rem"
256
- },
257
- children: [
258
- /* @__PURE__ */ s(z, { label: "Summary", id: "summary", name: "summary", value: o.editSummary }),
259
- /* @__PURE__ */ s("div", { className: "ipe-input-box", children: [
260
- /* @__PURE__ */ s("label", { htmlFor: "watchlist", style: { display: "block" }, children: "Watchlist" }),
261
- /* @__PURE__ */ s("div", { style: { display: "flex", gap: "1rem" }, children: [
262
- m.preferences,
263
- m.nochange,
264
- m.watch,
265
- m.unwatch
266
- ].map((l) => /* @__PURE__ */ s(
267
- Q,
268
- {
269
- name: "watchlist",
270
- value: l,
271
- inputProps: { checked: a === l },
272
- children: l
273
- },
274
- l
275
- )) })
276
- ] }),
277
- /* @__PURE__ */ s("div", { style: { display: "flex", gap: "1rem" }, children: [
278
- /* @__PURE__ */ s(y, { name: "minor", id: "minor", checked: o.editMinor, children: "Minor edit" }),
279
- /* @__PURE__ */ s(y, { name: "reloadAfterSave", id: "reloadAfterSave", checked: o.reloadAfterSave, children: "Reload after save" })
280
- ] })
281
- ]
282
- }
283
- ),
284
- !1
285
- ] });
286
- n.setContent(d), n.addButton(
287
- {
288
- side: "left",
289
- className: "is-primary submit-btn",
290
- label: "Submit",
291
- method: () => {
292
- const l = new FormData(d);
293
- n.setLoadingState(!0), this.handleSubmit(
294
- { ctx: this.ctx, modal: n, wikiPage: u, options: o },
295
- {
296
- text: l.get("text"),
297
- summary: l.get("summary"),
298
- minor: l.get("minor") === "on"
299
- }
300
- ).then(async () => {
301
- n.setOptions({
302
- beforeClose: P
303
- }), n.close(), this.ctx.modal.notify("success", {
304
- title: "Submission Successful",
305
- content: "Your changes have been saved."
306
- }), l.get("reloadAfterSave") && (await R(500), location.reload());
307
- }).catch((g) => {
308
- this.ctx.modal.notify("error", {
309
- title: "Submission Error",
310
- content: g instanceof Error ? g.message : String(g)
311
- }), n.setLoadingState(!1);
312
- });
313
- }
314
- },
315
- 0
316
- ), n.setOptions({
317
- beforeClose: () => {
318
- const l = u.revisions[0]?.content || "";
319
- return (d.querySelector("textarea")?.value || "") === l ? !0 : (this.ctx.modal.confirm(
320
- {
321
- className: "is-primary",
322
- title: "Unsaved Changes",
323
- content: "All edit contents will be lost after closing the modal. Are you sure you want to close?",
324
- center: !0,
325
- okBtn: {
326
- label: "Give Up",
327
- className: "is-danger is-ghost"
328
- },
329
- cancelBtn: {
330
- label: "Continue",
331
- className: "is-primary is-ghost"
332
- }
333
- },
334
- (f) => (f && (n.setOptions({
335
- beforeClose: P
336
- }), n.close()), !0)
337
- ), !1);
338
- }
339
- }), this.ctx.emit("quickEdit/wikiPage", {
340
- ctx: this.ctx,
341
- options: o,
342
- modal: n,
343
- wikiPage: u
344
- });
345
- const p = (l) => d.querySelector("textarea")?.value === u.revisions[0]?.content ? !0 : (l.preventDefault(), "You have unsaved changes. Are you sure you want to leave?");
346
- window.addEventListener("beforeunload", p), n.on(n.Event.Close, () => {
347
- window.removeEventListener("beforeunload", p);
348
- });
349
- }
350
- handleSubmit(e, r) {
351
- const a = r.summary || "", i = r.text || "", c = r.minor || !1, o = r.createonly || !1, n = r.watchlist || m.nochange, u = e.options.section;
352
- return e.wikiPage.edit(
353
- {
354
- summary: a,
355
- text: i,
356
- watchlist: n,
357
- section: u
358
- },
359
- {
360
- minor: c,
361
- createonly: o
362
- }
363
- );
364
- }
365
- injectToolbox(e) {
366
- e.toolbox.addButton({
367
- id: "quick-edit",
368
- group: "group1",
369
- index: 0,
370
- icon: /* @__PURE__ */ s(
371
- "svg",
372
- {
373
- xmlns: "http://www.w3.org/2000/svg",
374
- width: "24",
375
- height: "24",
376
- viewBox: "0 0 24 24",
377
- fill: "none",
378
- stroke: "currentColor",
379
- "stroke-width": "2",
380
- "stroke-linecap": "round",
381
- "stroke-linejoin": "round",
382
- class: "icon icon-tabler icons-tabler-outline icon-tabler-edit",
383
- children: [
384
- /* @__PURE__ */ s("path", { stroke: "none", d: "M0 0h24v24H0z", fill: "none" }),
385
- /* @__PURE__ */ s("path", { d: "M7 7h-1a2 2 0 0 0 -2 2v9a2 2 0 0 0 2 2h9a2 2 0 0 0 2 -2v-1" }),
386
- /* @__PURE__ */ s("path", { d: "M20.385 6.585a2.1 2.1 0 0 0 -2.97 -2.97l-8.415 8.385v3h3l8.385 -8.415z" }),
387
- /* @__PURE__ */ s("path", { d: "M16 5l3 3" })
388
- ]
389
- }
390
- ),
391
- tooltip: "Edit this page quickly",
392
- onClick: () => this.quickEdit()
393
- });
394
- }
395
- async getWikiPageFromPayload(e) {
396
- if (e.revision)
397
- return this.ctx.wikiPage.newFromRevision(e.revision, e.section);
398
- if (e.pageId)
399
- return this.ctx.wikiPage.newFromPageId(e.pageId, e.section);
400
- if (e.title)
401
- return this.ctx.wikiPage.newFromTitle(e.title, !1, e.section);
402
- throw new Error("Invalid payload");
403
- }
404
- removeToolbox(e) {
405
- e.toolbox.removeButton("quick-edit");
406
- }
407
- }
408
- S = oe(F);
409
- k = de(S, 0, "PluginQuickEdit", j, k);
410
- le(S, 1, k);
411
- export {
412
- k as PluginQuickEdit
413
- };
414
- //# sourceMappingURL=index-Djd6Ddcm.js.map