ant-design-x-vue-next
Version:
Ant Design X for Vue — community continuation aligned with @ant-design/x
99 lines (98 loc) • 2.37 kB
JavaScript
const e = {
N: 78,
UP: 38,
DOWN: 40,
ONE: 49,
TWO: 50,
THREE: 51,
FOUR: 52,
FIVE: 53,
SIX: 54,
SEVEN: 55,
EIGHT: 56,
NINE: 57
}, S = {
Alt: "altKey",
Ctrl: "ctrlKey",
Meta: "metaKey",
Shift: "shiftKey"
}, m = {
Alt: ["⌥", "Alt"],
Ctrl: ["⌃", "Ctrl"],
Meta: ["⌘", "Win"],
Shift: ["⇧", "Shift"]
}, I = typeof navigator < "u" && /(mac|iphone|ipod|ipad)/i.test(navigator.platform || ""), h = [
e.ONE,
e.TWO,
e.THREE,
e.FOUR,
e.FIVE,
e.SIX,
e.SEVEN,
e.EIGHT,
e.NINE
], O = {
[e.N]: "N",
[e.UP]: "↑",
[e.DOWN]: "↓",
...Object.fromEntries(h.map((t, r) => [t, String(r + 1)]))
}, K = (t) => t === "number" ? "number" : typeof t == "string" && t in m ? m[t][I ? 0 : 1] : typeof t == "number" ? O[t] || String(t) : "", C = (t, r) => {
const a = [...t], c = a.pop();
if (!a.every((d) => !!r[S[d]]) || c !== r.keyCode)
return !1;
const s = h.indexOf(c);
return {
actionShortcutKey: t,
actionKeyCodeNumber: s > -1 ? s : !1,
actionKeyCode: r.keyCode,
timeStamp: r.timeStamp
};
}, g = (t, r) => {
const a = { ...r || {}, ...t || {} }, c = [], f = {};
return Object.keys(a).forEach((n) => {
const s = a[n];
if (!Array.isArray(s)) return;
if (f[n] = {
shortcutKeys: s,
shortcutKeysIcon: []
}, s.every((y) => Array.isArray(y)))
s.forEach((y, p) => {
const o = y;
if (o[o.length - 1] === "number") {
const u = o.slice(0, -1);
h.forEach((i, l) => {
c.push({
name: n,
shortcutKey: [...u, i],
index: l
});
}), f[n].shortcutKeysIcon.push(
o.map((i) => K(i))
);
} else
c.push({
name: n,
shortcutKey: o,
index: p
}), f[n].shortcutKeysIcon.push(
o.map((u) => K(u))
);
});
else {
const y = s, p = [...y], o = p.pop(), E = p;
(o === "number" ? h : [o]).forEach((i, l) => {
c.push({
name: n,
shortcutKey: [...E, i],
index: o === "number" ? l : void 0
});
}), f[n].shortcutKeysIcon = y.map((i) => K(i));
}
}), { flatten: c, info: f };
};
export {
e as ShortcutKeyCode,
g as flattenShortcutKeys,
C as getShortcutAction,
K as getShortcutKeysIcon
};