@inpageedit/core 0.4.1 → 0.5.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/dist/ActionButton-BgbTKTg7.js +24 -0
- package/dist/ActionButton-BgbTKTg7.js.map +1 -0
- package/dist/{RadioBox-BZFhTEo5.js → RadioBox-CaA8VgLu.js} +16 -16
- package/dist/{RadioBox-BZFhTEo5.js.map → RadioBox-CaA8VgLu.js.map} +1 -1
- package/dist/components/TwinSwapInput/index.d.ts +1 -0
- package/dist/components/index.js +21 -22
- package/dist/components/index.js.map +1 -1
- package/dist/index-BIgWRk98.js +4826 -0
- package/dist/index-BIgWRk98.js.map +1 -0
- package/dist/index-BMmKF_kG.js +165 -0
- package/dist/index-BMmKF_kG.js.map +1 -0
- package/dist/{index-BPsDFq9U.js → index-Bh70Udzi.js} +14 -13
- package/dist/index-Bh70Udzi.js.map +1 -0
- package/dist/index-CBphMyYJ.js +5170 -0
- package/dist/index-CBphMyYJ.js.map +1 -0
- package/dist/{index-X1X416tZ.js → index-CJLKdEqr.js} +41 -25
- package/dist/index-CJLKdEqr.js.map +1 -0
- package/dist/{index-BsYzf3Yw.js → index-CX5H4xCe.js} +12 -12
- package/dist/index-CX5H4xCe.js.map +1 -0
- package/dist/{index-BByzm2Fz.js → index-DNm9SNqM.js} +128 -120
- package/dist/{index-BByzm2Fz.js.map → index-DNm9SNqM.js.map} +1 -1
- package/dist/{index-Ch5DJDZZ.js → index-Djd6Ddcm.js} +125 -121
- package/dist/index-Djd6Ddcm.js.map +1 -0
- package/dist/index-Dk3xR25y.js +96 -0
- package/dist/index-Dk3xR25y.js.map +1 -0
- package/dist/{index-D-zQLFuZ.js → index-QF8lvEam.js} +14 -21
- package/dist/index-QF8lvEam.js.map +1 -0
- package/dist/index.js +9 -4639
- package/dist/index.js.map +1 -1
- package/dist/models/WikiPage/index.d.ts +5 -4
- package/dist/plugins/BasePlugin.d.ts +12 -4
- package/dist/plugins/_debug/index.d.ts +1 -1
- package/dist/plugins/quick-diff/PluginQuickDiffCore.d.ts +2 -1
- package/dist/plugins/quick-edit/index.d.ts +2 -1
- package/dist/plugins/quick-move/index.d.ts +1 -1
- package/dist/plugins/quick-preview/index.d.ts +4 -3
- package/dist/plugins/quick-redirect/index.d.ts +1 -1
- package/dist/plugins/toolbox/index.d.ts +2 -2
- package/dist/services/ModalService/IPEModal.d.ts +235 -0
- package/dist/services/ModalService/index.d.ts +35 -0
- package/dist/style.css +1 -1
- package/dist/utils/interpolate.d.ts +20 -0
- package/dist/utils/interpolate.spec.d.ts +1 -0
- package/lib/index.umd.js +32 -32
- package/lib/index.umd.js.map +1 -1
- package/lib/style.css +1 -1
- package/package.json +24 -25
- package/dist/ActionButton-ByMKIthQ.js +0 -24
- package/dist/ActionButton-ByMKIthQ.js.map +0 -1
- package/dist/index-BPsDFq9U.js.map +0 -1
- package/dist/index-BTngTj1f.js +0 -4682
- package/dist/index-BTngTj1f.js.map +0 -1
- package/dist/index-BsYzf3Yw.js.map +0 -1
- package/dist/index-Ch5DJDZZ.js.map +0 -1
- package/dist/index-Cq9xxVsu.js +0 -149
- package/dist/index-Cq9xxVsu.js.map +0 -1
- package/dist/index-D-zQLFuZ.js.map +0 -1
- package/dist/index-HyxA2rYz.js +0 -87
- package/dist/index-HyxA2rYz.js.map +0 -1
- package/dist/index-X1X416tZ.js.map +0 -1
- package/dist/services/SsiModalService.d.ts +0 -36
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { j as i, P as y } from "./index-CvhkVj_L.js";
|
|
2
|
+
import { B as S, a as q } from "./index-CBphMyYJ.js";
|
|
3
|
+
import { T as F } from "./index-Bh70Udzi.js";
|
|
4
|
+
import { C as u, I as j } from "./InputBox-FIzJ-rPN.js";
|
|
5
|
+
var E = Object.create, h = Object.defineProperty, B = Object.getOwnPropertyDescriptor, w = (t, e) => (e = Symbol[t]) ? e : Symbol.for("Symbol." + t), k = (t) => {
|
|
6
|
+
throw TypeError(t);
|
|
7
|
+
}, I = (t, e, o) => e in t ? h(t, e, { enumerable: !0, configurable: !0, writable: !0, value: o }) : t[e] = o, C = (t, e) => h(t, "name", { value: e, configurable: !0 }), T = (t) => [, , , E(t?.[w("metadata")] ?? null)], z = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"], _ = (t) => t !== void 0 && typeof t != "function" ? k("Function expected") : t, D = (t, e, o, a, r) => ({ kind: z[t], name: e, metadata: a, addInitializer: (n) => o._ ? k("Already initialized") : r.push(_(n || null)) }), O = (t, e) => I(e, w("metadata"), t[3]), N = (t, e, o, a) => {
|
|
8
|
+
for (var r = 0, n = t[e >> 1], s = n && n.length; r < s; r++) n[r].call(o);
|
|
9
|
+
return a;
|
|
10
|
+
}, Q = (t, e, o, a, r, n) => {
|
|
11
|
+
var s, c, p, l = e & 7, f = !1, b = 0, P = t[b] || (t[b] = []), d = l && (r = r.prototype, l < 5 && (l > 3 || !f) && B(r, o));
|
|
12
|
+
C(r, o);
|
|
13
|
+
for (var m = a.length - 1; m >= 0; m--)
|
|
14
|
+
p = D(l, o, c = {}, t[3], P), s = (0, a[m])(r, p), c._ = 1, _(s) && (r = s);
|
|
15
|
+
return O(t, r), d && h(r, o, d), f ? l ^ 4 ? n : d : r;
|
|
16
|
+
}, M, g, x;
|
|
17
|
+
M = [q(["modal", "sitemeta"])];
|
|
18
|
+
class v extends (x = S) {
|
|
19
|
+
constructor(e) {
|
|
20
|
+
super(e, {}, "quick-move"), this.ctx = e, e.set("quickMove", this.quickMove.bind(this)), e.set("movePage", this.movePage.bind(this));
|
|
21
|
+
}
|
|
22
|
+
start() {
|
|
23
|
+
this.ctx.inject(["toolbox"], (e) => {
|
|
24
|
+
this.injectToolbox(e);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
injectToolbox(e) {
|
|
28
|
+
const o = window.mw?.config.get("wgPageName") || "", a = window.mw?.config.get("wgIsProbablyEditable");
|
|
29
|
+
e.toolbox.addButton({
|
|
30
|
+
id: "quick-move",
|
|
31
|
+
icon: /* @__PURE__ */ i(
|
|
32
|
+
"svg",
|
|
33
|
+
{
|
|
34
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
35
|
+
width: "24",
|
|
36
|
+
height: "24",
|
|
37
|
+
viewBox: "0 0 24 24",
|
|
38
|
+
fill: "none",
|
|
39
|
+
stroke: "currentColor",
|
|
40
|
+
"stroke-width": "2",
|
|
41
|
+
"stroke-linecap": "round",
|
|
42
|
+
"stroke-linejoin": "round",
|
|
43
|
+
class: "icon icon-tabler icons-tabler-outline icon-tabler-forms",
|
|
44
|
+
children: [
|
|
45
|
+
/* @__PURE__ */ i("path", { stroke: "none", d: "M0 0h24v24H0z", fill: "none" }),
|
|
46
|
+
/* @__PURE__ */ i("path", { d: "M12 3a3 3 0 0 0 -3 3v12a3 3 0 0 0 3 3" }),
|
|
47
|
+
/* @__PURE__ */ i("path", { d: "M6 3a3 3 0 0 1 3 3v12a3 3 0 0 1 -3 3" }),
|
|
48
|
+
/* @__PURE__ */ i("path", { d: "M13 7h7a1 1 0 0 1 1 1v8a1 1 0 0 1 -1 1h-7" }),
|
|
49
|
+
/* @__PURE__ */ i("path", { d: "M5 7h-1a1 1 0 0 0 -1 1v8a1 1 0 0 0 1 1h1" }),
|
|
50
|
+
/* @__PURE__ */ i("path", { d: "M17 12h.01" }),
|
|
51
|
+
/* @__PURE__ */ i("path", { d: "M13 12h.01" })
|
|
52
|
+
]
|
|
53
|
+
}
|
|
54
|
+
),
|
|
55
|
+
tooltip: "Quick Move",
|
|
56
|
+
group: "group2",
|
|
57
|
+
onClick: () => {
|
|
58
|
+
this.quickMove(
|
|
59
|
+
a ? {
|
|
60
|
+
lockFromField: !0,
|
|
61
|
+
from: o
|
|
62
|
+
} : {}
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
quickMove(e) {
|
|
68
|
+
const o = this.ctx.modal.createObject({
|
|
69
|
+
title: "Quick Move",
|
|
70
|
+
content: /* @__PURE__ */ i(y, {}),
|
|
71
|
+
className: "quick-move compact-buttons",
|
|
72
|
+
sizeClass: "medium",
|
|
73
|
+
center: !0
|
|
74
|
+
}).init();
|
|
75
|
+
let a = null;
|
|
76
|
+
return o.setContent(
|
|
77
|
+
/* @__PURE__ */ i(
|
|
78
|
+
"form",
|
|
79
|
+
{
|
|
80
|
+
ref: (r) => a = r,
|
|
81
|
+
style: {
|
|
82
|
+
display: "flex",
|
|
83
|
+
flexDirection: "column",
|
|
84
|
+
gap: "1rem"
|
|
85
|
+
},
|
|
86
|
+
onSubmit: (r) => {
|
|
87
|
+
if (r.preventDefault(), a?.checkValidity(), !a?.reportValidity())
|
|
88
|
+
return;
|
|
89
|
+
const n = new FormData(a), s = {
|
|
90
|
+
from: n.get("from")?.toString().trim(),
|
|
91
|
+
to: n.get("to")?.toString().trim(),
|
|
92
|
+
reason: n.get("reason") || "",
|
|
93
|
+
movetalk: n.get("movetalk") === "on",
|
|
94
|
+
movesubpages: n.get("movesubpages") === "on",
|
|
95
|
+
noredirect: n.get("noredirect") === "on"
|
|
96
|
+
};
|
|
97
|
+
if (!s.from || !s.to) {
|
|
98
|
+
this.ctx.modal.notify("error", {
|
|
99
|
+
title: "Failed to move",
|
|
100
|
+
content: "From and to are required."
|
|
101
|
+
});
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
o.setLoadingState(!0), this.movePage(s).then(() => {
|
|
105
|
+
location.reload();
|
|
106
|
+
}).catch((c) => {
|
|
107
|
+
o.setLoadingState(!1), this.ctx.modal.notify("error", {
|
|
108
|
+
title: "Failed to move",
|
|
109
|
+
content: c instanceof Error ? c.message : String(c)
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
},
|
|
113
|
+
children: [
|
|
114
|
+
/* @__PURE__ */ i(
|
|
115
|
+
F,
|
|
116
|
+
{
|
|
117
|
+
inputs: [
|
|
118
|
+
{
|
|
119
|
+
label: "Move from",
|
|
120
|
+
name: "from",
|
|
121
|
+
value: e?.from,
|
|
122
|
+
required: !0
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
label: "Move to",
|
|
126
|
+
name: "to",
|
|
127
|
+
value: e?.to,
|
|
128
|
+
required: !0
|
|
129
|
+
}
|
|
130
|
+
]
|
|
131
|
+
}
|
|
132
|
+
),
|
|
133
|
+
/* @__PURE__ */ i("div", { children: /* @__PURE__ */ i(u, { name: "movetalk", id: "movetalk", checked: e?.movetalk, children: "Move talk page" }) }),
|
|
134
|
+
/* @__PURE__ */ i("div", { children: /* @__PURE__ */ i(u, { name: "movesubpages", id: "movesubpages", checked: e?.movesubpages, children: "Move subpage(s) (up to 100)" }) }),
|
|
135
|
+
this.ctx.sitemeta.hasRight("suppressredirect") && /* @__PURE__ */ i("div", { children: /* @__PURE__ */ i(u, { name: "noredirect", id: "noredirect", checked: e?.noredirect, children: "Move without leaving a redirect" }) }),
|
|
136
|
+
/* @__PURE__ */ i(j, { label: "Reason", id: "reason", name: "reason", value: e?.reason })
|
|
137
|
+
]
|
|
138
|
+
}
|
|
139
|
+
)
|
|
140
|
+
), o.setButtons([
|
|
141
|
+
{
|
|
142
|
+
label: "Move",
|
|
143
|
+
className: "is-primary is-ghost",
|
|
144
|
+
method: () => {
|
|
145
|
+
a?.dispatchEvent(new Event("submit"));
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
]), o.show();
|
|
149
|
+
}
|
|
150
|
+
async movePage(e) {
|
|
151
|
+
const { from: o, to: a, reason: r = "", ...n } = e;
|
|
152
|
+
if (!o || !a)
|
|
153
|
+
throw new Error("From and to titles are required.");
|
|
154
|
+
if (o === a)
|
|
155
|
+
throw new Error("From and to titles cannot be the same.");
|
|
156
|
+
return (await this.ctx.wikiPage.newFromTitle(o)).moveTo(a, r, n);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
g = T(x);
|
|
160
|
+
v = Q(g, 0, "PluginQuickMove", M, v);
|
|
161
|
+
N(g, 1, v);
|
|
162
|
+
export {
|
|
163
|
+
v as PluginQuickMove
|
|
164
|
+
};
|
|
165
|
+
//# sourceMappingURL=index-BMmKF_kG.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-BMmKF_kG.js","sources":["../src/plugins/quick-move/index.tsx"],"sourcesContent":["import { Inject, InPageEdit } from '@/InPageEdit'\r\n\r\ndeclare module '@/InPageEdit' {\r\n interface InPageEdit {\r\n quickMove: PluginQuickMove['quickMove']\r\n movePage: PluginQuickMove['movePage']\r\n }\r\n}\r\n\r\nexport interface MovePageOptions {\r\n from: string\r\n to: string\r\n reason?: string\r\n movetalk?: boolean\r\n movesubpages?: boolean\r\n noredirect?: boolean\r\n}\r\nexport interface QuickMoveOptions extends Partial<MovePageOptions> {\r\n lockFromField?: boolean\r\n lockToField?: boolean\r\n}\r\n\r\n@Inject(['modal', 'sitemeta'])\r\nexport class PluginQuickMove extends BasePlugin {\r\n constructor(public ctx: InPageEdit) {\r\n super(ctx, {}, 'quick-move')\r\n ctx.set('quickMove', this.quickMove.bind(this))\r\n ctx.set('movePage', this.movePage.bind(this))\r\n }\r\n\r\n protected start(): Promise<void> | void {\r\n this.ctx.inject(['toolbox'], (ctx) => {\r\n this.injectToolbox(ctx)\r\n })\r\n }\r\n\r\n private injectToolbox(ctx: InPageEdit) {\r\n const curPageName = window.mw?.config.get('wgPageName') || ''\r\n const canEdit = window.mw?.config.get('wgIsProbablyEditable')\r\n ctx.toolbox.addButton({\r\n id: 'quick-move',\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-forms\"\r\n >\r\n <path stroke=\"none\" d=\"M0 0h24v24H0z\" fill=\"none\" />\r\n <path d=\"M12 3a3 3 0 0 0 -3 3v12a3 3 0 0 0 3 3\" />\r\n <path d=\"M6 3a3 3 0 0 1 3 3v12a3 3 0 0 1 -3 3\" />\r\n <path d=\"M13 7h7a1 1 0 0 1 1 1v8a1 1 0 0 1 -1 1h-7\" />\r\n <path d=\"M5 7h-1a1 1 0 0 0 -1 1v8a1 1 0 0 0 1 1h1\" />\r\n <path d=\"M17 12h.01\" />\r\n <path d=\"M13 12h.01\" />\r\n </svg>\r\n ),\r\n tooltip: 'Quick Move',\r\n group: 'group2',\r\n onClick: () => {\r\n this.quickMove(\r\n canEdit\r\n ? {\r\n lockFromField: true,\r\n from: curPageName,\r\n }\r\n : {}\r\n )\r\n },\r\n })\r\n }\r\n\r\n quickMove(options?: Partial<QuickMoveOptions>) {\r\n const modal = this.ctx.modal\r\n .createObject({\r\n title: 'Quick Move',\r\n content: (<ProgressBar />) as HTMLElement,\r\n className: 'quick-move 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 movetalk: formData.get('movetalk') === 'on',\r\n movesubpages: formData.get('movesubpages') === 'on',\r\n noredirect: formData.get('noredirect') === 'on',\r\n }\r\n if (!options.from || !options.to) {\r\n this.ctx.modal.notify('error', {\r\n title: 'Failed to move',\r\n content: 'From and to are required.',\r\n })\r\n return\r\n }\r\n modal.setLoadingState(true)\r\n this.movePage(options)\r\n .then(() => {\r\n location.reload()\r\n })\r\n .catch((error) => {\r\n modal.setLoadingState(false)\r\n this.ctx.modal.notify('error', {\r\n title: 'Failed to move',\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: 'Move from',\r\n name: 'from',\r\n value: options?.from,\r\n required: true,\r\n },\r\n {\r\n label: 'Move to',\r\n name: 'to',\r\n value: options?.to,\r\n required: true,\r\n },\r\n ]}\r\n />\r\n <div>\r\n <CheckBox name=\"movetalk\" id=\"movetalk\" checked={options?.movetalk}>\r\n Move talk page\r\n </CheckBox>\r\n </div>\r\n <div>\r\n <CheckBox name=\"movesubpages\" id=\"movesubpages\" checked={options?.movesubpages}>\r\n Move subpage(s) (up to 100)\r\n </CheckBox>\r\n </div>\r\n {this.ctx.sitemeta.hasRight('suppressredirect') && (\r\n <div>\r\n <CheckBox name=\"noredirect\" id=\"noredirect\" checked={options?.noredirect}>\r\n Move without leaving a redirect\r\n </CheckBox>\r\n </div>\r\n )}\r\n <InputBox label=\"Reason\" id=\"reason\" name=\"reason\" value={options?.reason} />\r\n </form>\r\n ) as HTMLElement\r\n )\r\n\r\n modal.setButtons([\r\n {\r\n label: 'Move',\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 movePage(options: MovePageOptions) {\r\n const { from, to, reason = '', ...rest } = options\r\n\r\n if (!from || !to) {\r\n throw new Error('From and to titles are required.')\r\n }\r\n if (from === to) {\r\n throw new Error('From and to titles cannot be the same.')\r\n }\r\n\r\n const wikiPage = await this.ctx.wikiPage.newFromTitle(from)\r\n return wikiPage.moveTo(to, reason, rest)\r\n }\r\n}\r\n"],"names":["_PluginQuickMove_decorators","_init","_a","Inject","PluginQuickMove","BasePlugin","ctx","curPageName","canEdit","jsxs","jsx","options","modal","ProgressBar","formRef","el","e","formData","error","TwinSwapInput","CheckBox","InputBox","from","to","reason","rest","__decoratorStart","__decorate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,gBAAAD,EAACW,GAAA,EAAS,OAAM,UAAS,IAAG,UAAS,MAAK,UAAS,OAAOV,GAAS,OAAA,CAAQ;AAAA,UAAA;AAAA,QAAA;AAAA,MAAA;AAAA,IAC7E,GAIJC,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,SAASD,GAA0B;AACvC,UAAM,EAAE,MAAAW,GAAM,IAAAC,GAAI,QAAAC,IAAS,IAAI,GAAGC,MAASd;AAE3C,QAAI,CAACW,KAAQ,CAACC;AACZ,YAAM,IAAI,MAAM,kCAAkC;AAEpD,QAAID,MAASC;AACX,YAAM,IAAI,MAAM,wCAAwC;AAI1D,YADiB,MAAM,KAAK,IAAI,SAAS,aAAaD,CAAI,GAC1C,OAAOC,GAAIC,GAAQC,CAAI;AAAA,EACzC;AACF;AAhLOxB,IAAAyB,EAAAxB,CAAA;AAAME,IAANuB,2BADP3B,GACaI,CAAA;AAANwB,EAAA3B,GAAA,GAAMG,CAAA;"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { j as n } from "./index-CvhkVj_L.js";
|
|
2
|
-
const
|
|
3
|
-
twinSwapInput:
|
|
4
|
-
inputWrapper:
|
|
5
|
-
inputLeft:
|
|
6
|
-
inputRight:
|
|
7
|
-
swapButton:
|
|
8
|
-
},
|
|
2
|
+
const y = "_twinSwapInput_1gdgl_9", L = "_inputWrapper_1gdgl_23", W = "_inputLeft_1gdgl_27", $ = "_inputRight_1gdgl_30", j = "_swapButton_1gdgl_46", i = {
|
|
3
|
+
twinSwapInput: y,
|
|
4
|
+
inputWrapper: L,
|
|
5
|
+
inputLeft: W,
|
|
6
|
+
inputRight: $,
|
|
7
|
+
swapButton: j
|
|
8
|
+
}, M = (f) => {
|
|
9
9
|
const { inputs: l, enableSwap: b = !0, ...v } = f, _ = l?.length === 2 ? l : [l?.[0] ?? {}, l?.[1] ?? {}], s = [null, null];
|
|
10
10
|
let c = 0, o = null, p = null;
|
|
11
11
|
const d = () => s.some((t) => t && t.disabled), w = () => {
|
|
@@ -50,23 +50,24 @@ const x = "_twinSwapInput_1gdgl_9", y = "_inputWrapper_1gdgl_23", L = "_inputLef
|
|
|
50
50
|
}
|
|
51
51
|
), r = /* @__PURE__ */ n("div", { className: `twin-swap-input ${i.twinSwapInput}`, ...v, children: [
|
|
52
52
|
_.map((t, e) => {
|
|
53
|
-
const { label: a, id: u, name: h, value: S, disabled: k,
|
|
53
|
+
const { label: a, id: u, name: h, value: S, disabled: k, required: B, inputProps: E } = t, R = e === 0, g = u || h;
|
|
54
54
|
return /* @__PURE__ */ n(
|
|
55
55
|
"div",
|
|
56
56
|
{
|
|
57
|
-
className: `${i.inputWrapper} ${
|
|
57
|
+
className: `${i.inputWrapper} ${R ? i.inputLeft : i.inputRight}`,
|
|
58
58
|
children: [
|
|
59
59
|
a && /* @__PURE__ */ n("label", { htmlFor: g, children: a }),
|
|
60
60
|
/* @__PURE__ */ n(
|
|
61
61
|
"input",
|
|
62
62
|
{
|
|
63
|
-
ref: (
|
|
63
|
+
ref: (x) => s[e] = x,
|
|
64
64
|
type: "text",
|
|
65
65
|
id: g,
|
|
66
66
|
name: h,
|
|
67
67
|
value: S,
|
|
68
68
|
disabled: k,
|
|
69
|
-
|
|
69
|
+
required: B,
|
|
70
|
+
...E
|
|
70
71
|
}
|
|
71
72
|
)
|
|
72
73
|
]
|
|
@@ -78,6 +79,6 @@ const x = "_twinSwapInput_1gdgl_9", y = "_inputWrapper_1gdgl_23", L = "_inputLef
|
|
|
78
79
|
return r.swap = w, r.toggleEnableSwap = m, r;
|
|
79
80
|
};
|
|
80
81
|
export {
|
|
81
|
-
|
|
82
|
+
M as T
|
|
82
83
|
};
|
|
83
|
-
//# sourceMappingURL=index-
|
|
84
|
+
//# sourceMappingURL=index-Bh70Udzi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-Bh70Udzi.js","sources":["../src/components/TwinSwapInput/index.tsx"],"sourcesContent":["import { JSX } from 'jsx-dom/jsx-runtime'\r\nimport styles from './styles.module.sass'\r\n\r\nexport type TwinSwapInputProps = {\r\n inputs: [TwinSwapInputInput, TwinSwapInputInput]\r\n enableSwap?: boolean\r\n} & JSX.IntrinsicElements['div']\r\n\r\nexport interface TwinSwapInputInput {\r\n label?: string\r\n id?: string\r\n name: string\r\n value?: string\r\n disabled?: boolean\r\n required?: boolean\r\n inputProps?: Omit<JSX.IntrinsicElements['input'], 'name' | 'value'>\r\n}\r\n\r\nexport type TwinSwapElement = HTMLDivElement & {\r\n swap: () => void\r\n toggleEnableSwap: (enable?: boolean) => void\r\n}\r\n\r\nexport const TwinSwapInput = (props: TwinSwapInputProps) => {\r\n const { inputs, enableSwap = true, ...rest } = props\r\n\r\n const normalizedInputs =\r\n inputs?.length === 2\r\n ? inputs\r\n : ([inputs?.[0] ?? {}, inputs?.[1] ?? {}] as [TwinSwapInputInput, TwinSwapInputInput])\r\n\r\n // 内部稳定引用\r\n const inputRefs: [HTMLInputElement | null, HTMLInputElement | null] = [null, null]\r\n\r\n let swapCount = 0\r\n let swapBtnRef: HTMLButtonElement | null = null\r\n let svgRef: SVGElement | null = null\r\n\r\n const checkIfInputDisabled = () => inputRefs.some((el) => el && el.disabled)\r\n\r\n const swap = () => {\r\n if (!inputRefs[0] || !inputRefs[1]) return\r\n if (checkIfInputDisabled()) return\r\n\r\n const a = inputRefs[0]\r\n const b = inputRefs[1]\r\n const va = a.value\r\n const vb = b.value\r\n a.value = vb\r\n b.value = va\r\n\r\n // 与原实现一致:派发 change(不冒泡)\r\n a.dispatchEvent(new Event('change'))\r\n b.dispatchEvent(new Event('change'))\r\n\r\n swapCount++\r\n if (svgRef) {\r\n svgRef.style.transform = `rotateY(${swapCount * -180}deg)`\r\n svgRef.style.transition = 'transform 200ms ease'\r\n }\r\n }\r\n\r\n const toggleEnableSwap = (enable?: boolean) => {\r\n if (!swapBtnRef) return\r\n const next = enable ?? !swapBtnRef.disabled\r\n swapBtnRef.disabled = !next\r\n if (next) {\r\n // 与原实现一致:开启时把 inputs 解禁\r\n inputRefs.forEach((el) => {\r\n if (el) el.disabled = false\r\n })\r\n }\r\n }\r\n\r\n const swapButton = (\r\n <button\r\n type=\"button\"\r\n aria-label=\"Swap values\"\r\n onClick={swap}\r\n disabled={checkIfInputDisabled() || !enableSwap}\r\n ref={(el) => (swapBtnRef = el as HTMLButtonElement)}\r\n >\r\n <svg\r\n ref={(el) => (svgRef = el as unknown as SVGElement)}\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-tabler icons-tabler-outline icon-tabler-transfer\"\r\n >\r\n <path stroke=\"none\" d=\"M0 0h24v24H0z\" fill=\"none\" />\r\n <path d=\"M20 10h-16l5.5 -6\" />\r\n <path d=\"M4 14h16l-5.5 6\" />\r\n </svg>\r\n </button>\r\n ) as HTMLButtonElement\r\n\r\n const container = (\r\n <div className={`twin-swap-input ${styles.twinSwapInput}`} {...rest}>\r\n {normalizedInputs.map((input, index) => {\r\n const { label, id, name, value, disabled, required, inputProps } = input\r\n const isLeft = index === 0\r\n const inputId = id || name\r\n\r\n return (\r\n <div\r\n className={`${styles.inputWrapper} ${isLeft ? styles.inputLeft : styles.inputRight}`}\r\n >\r\n {label && <label htmlFor={inputId}>{label}</label>}\r\n <input\r\n ref={(el) => (inputRefs[index] = el as HTMLInputElement)}\r\n type=\"text\"\r\n id={inputId}\r\n name={name}\r\n value={value}\r\n disabled={disabled}\r\n required={required}\r\n {...inputProps}\r\n />\r\n </div>\r\n )\r\n })}\r\n\r\n <div className={styles.swapButton}>{swapButton}</div>\r\n </div>\r\n ) as TwinSwapElement\r\n\r\n container.swap = swap\r\n container.toggleEnableSwap = toggleEnableSwap\r\n\r\n return container\r\n}\r\n"],"names":["TwinSwapInput","props","inputs","enableSwap","rest","normalizedInputs","inputRefs","swapCount","swapBtnRef","svgRef","checkIfInputDisabled","el","swap","a","b","va","vb","toggleEnableSwap","enable","next","swapButton","jsx","jsxs","container","styles","input","index","label","id","name","value","disabled","required","inputProps","isLeft","inputId"],"mappings":";;;;;;;GAuBaA,IAAgB,CAACC,MAA8B;AAC1D,QAAM,EAAE,QAAAC,GAAQ,YAAAC,IAAa,IAAM,GAAGC,MAASH,GAEzCI,IACJH,GAAQ,WAAW,IACfA,IACC,CAACA,IAAS,CAAC,KAAK,CAAA,GAAIA,IAAS,CAAC,KAAK,CAAA,CAAE,GAGtCI,IAAgE,CAAC,MAAM,IAAI;AAEjF,MAAIC,IAAY,GACZC,IAAuC,MACvCC,IAA4B;AAEhC,QAAMC,IAAuB,MAAMJ,EAAU,KAAK,CAACK,MAAOA,KAAMA,EAAG,QAAQ,GAErEC,IAAO,MAAM;AAEjB,QADI,CAACN,EAAU,CAAC,KAAK,CAACA,EAAU,CAAC,KAC7BI,IAAwB;AAE5B,UAAMG,IAAIP,EAAU,CAAC,GACfQ,IAAIR,EAAU,CAAC,GACfS,IAAKF,EAAE,OACPG,IAAKF,EAAE;AACb,IAAAD,EAAE,QAAQG,GACVF,EAAE,QAAQC,GAGVF,EAAE,cAAc,IAAI,MAAM,QAAQ,CAAC,GACnCC,EAAE,cAAc,IAAI,MAAM,QAAQ,CAAC,GAEnCP,KACIE,MACFA,EAAO,MAAM,YAAY,WAAWF,IAAY,IAAI,QACpDE,EAAO,MAAM,aAAa;AAAA,EAE9B,GAEMQ,IAAmB,CAACC,MAAqB;AAC7C,QAAI,CAACV,EAAY;AACjB,UAAMW,IAAOD,KAAU,CAACV,EAAW;AACnC,IAAAA,EAAW,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