ant-design-x-vue-next
Version:
Ant Design X for Vue — community continuation aligned with @ant-design/x
40 lines (39 loc) • 1.17 kB
JavaScript
import { ref as c, watch as y, onMounted as p, onUnmounted as k } from "vue";
import { flattenShortcutKeys as K, getShortcutAction as b } from "../shortcut-keys.mjs";
import h from "./use-x-component-config.mjs";
function C(m, r) {
const a = h(m), i = c({}), f = c([]), o = c(null), s = c(!1);
y([r, a], () => {
var n;
const e = (n = a.value) == null ? void 0 : n.shortcutKeys, { flatten: u, info: t } = K(r.value, e);
f.value = u, i.value = t;
}, { immediate: !0, deep: !0 });
const d = (e) => {
var u;
for (const t of f.value) {
const n = b(t.shortcutKey, e);
if (!n) continue;
if (s.value) return;
s.value = !0;
const v = {
...n,
name: t.name,
index: t.index
};
(u = o.value) == null || u.call(o, v);
break;
}
}, l = () => {
s.value = !1;
};
return p(() => {
document.addEventListener("keydown", d), document.addEventListener("keyup", l);
}), k(() => {
document.removeEventListener("keydown", d), document.removeEventListener("keyup", l);
}), { shortcutKeysInfo: i, subscribe: (e) => {
o.value = e;
} };
}
export {
C as default
};