feat: initial commit - Phase 1 & 2 core features

This commit is contained in:
hiderfong
2026-04-22 17:07:33 +08:00
commit 1773bda06b
25005 changed files with 6252106 additions and 0 deletions
@@ -0,0 +1,12 @@
import { ObjectDirective } from "vue";
//#region ../../packages/directives/trap-focus/index.d.ts
declare const FOCUSABLE_CHILDREN = "_trap-focus-children";
declare const TRAP_FOCUS_HANDLER = "_trap-focus-handler";
interface TrapFocusElement extends HTMLElement {
[FOCUSABLE_CHILDREN]: HTMLElement[];
[TRAP_FOCUS_HANDLER]: (e: KeyboardEvent) => void;
}
declare const TrapFocus: ObjectDirective;
//#endregion
export { FOCUSABLE_CHILDREN, TRAP_FOCUS_HANDLER, TrapFocusElement, TrapFocus as default };
+60
View File
@@ -0,0 +1,60 @@
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
const require_runtime = require('../../_virtual/_rolldown/runtime.js');
const require_aria = require('../../constants/aria.js');
const require_aria$1 = require('../../utils/dom/aria.js');
const require_event = require('../../utils/dom/event.js');
let vue = require("vue");
//#region ../../packages/directives/trap-focus/index.ts
const FOCUSABLE_CHILDREN = "_trap-focus-children";
const TRAP_FOCUS_HANDLER = "_trap-focus-handler";
const FOCUS_STACK = [];
const FOCUS_HANDLER = (e) => {
if (FOCUS_STACK.length === 0) return;
const code = require_event.getEventCode(e);
const focusableElement = FOCUS_STACK[FOCUS_STACK.length - 1][FOCUSABLE_CHILDREN];
if (focusableElement.length > 0 && code === require_aria.EVENT_CODE.tab) {
if (focusableElement.length === 1) {
e.preventDefault();
if (document.activeElement !== focusableElement[0]) focusableElement[0].focus();
return;
}
const goingBackward = e.shiftKey;
const isFirst = e.target === focusableElement[0];
const isLast = e.target === focusableElement[focusableElement.length - 1];
if (isFirst && goingBackward) {
e.preventDefault();
focusableElement[focusableElement.length - 1].focus();
}
if (isLast && !goingBackward) {
e.preventDefault();
focusableElement[0].focus();
}
if (process.env.NODE_ENV === "test") {
const index = focusableElement.indexOf(e.target);
if (index !== -1) focusableElement[goingBackward ? index - 1 : index + 1]?.focus();
}
}
};
const TrapFocus = {
beforeMount(el) {
el[FOCUSABLE_CHILDREN] = require_aria$1.obtainAllFocusableElements(el);
FOCUS_STACK.push(el);
if (FOCUS_STACK.length <= 1) document.addEventListener("keydown", FOCUS_HANDLER);
},
updated(el) {
(0, vue.nextTick)(() => {
el[FOCUSABLE_CHILDREN] = require_aria$1.obtainAllFocusableElements(el);
});
},
unmounted() {
FOCUS_STACK.shift();
if (FOCUS_STACK.length === 0) document.removeEventListener("keydown", FOCUS_HANDLER);
}
};
//#endregion
exports.FOCUSABLE_CHILDREN = FOCUSABLE_CHILDREN;
exports.TRAP_FOCUS_HANDLER = TRAP_FOCUS_HANDLER;
exports.default = TrapFocus;
//# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
{"version":3,"file":"index.js","names":["getEventCode","EVENT_CODE","obtainAllFocusableElements"],"sources":["../../../../../packages/directives/trap-focus/index.ts"],"sourcesContent":["import { nextTick } from 'vue'\nimport { getEventCode, obtainAllFocusableElements } from '@element-plus/utils'\nimport { EVENT_CODE } from '@element-plus/constants'\n\nimport type { ObjectDirective } from 'vue'\n\nexport const FOCUSABLE_CHILDREN = '_trap-focus-children'\nexport const TRAP_FOCUS_HANDLER = '_trap-focus-handler'\n\nexport interface TrapFocusElement extends HTMLElement {\n [FOCUSABLE_CHILDREN]: HTMLElement[]\n [TRAP_FOCUS_HANDLER]: (e: KeyboardEvent) => void\n}\n\nconst FOCUS_STACK: TrapFocusElement[] = []\n\nconst FOCUS_HANDLER = (e: KeyboardEvent) => {\n // Getting the top layer.\n if (FOCUS_STACK.length === 0) return\n const code = getEventCode(e)\n const focusableElement =\n FOCUS_STACK[FOCUS_STACK.length - 1][FOCUSABLE_CHILDREN]\n if (focusableElement.length > 0 && code === EVENT_CODE.tab) {\n if (focusableElement.length === 1) {\n e.preventDefault()\n if (document.activeElement !== focusableElement[0]) {\n focusableElement[0].focus()\n }\n return\n }\n const goingBackward = e.shiftKey\n const isFirst = e.target === focusableElement[0]\n const isLast = e.target === focusableElement[focusableElement.length - 1]\n if (isFirst && goingBackward) {\n e.preventDefault()\n focusableElement[focusableElement.length - 1].focus()\n }\n if (isLast && !goingBackward) {\n e.preventDefault()\n focusableElement[0].focus()\n }\n\n // the is critical since jsdom did not implement user actions, you can only mock it\n // DELETE ME: when testing env switches to puppeteer\n if (process.env.NODE_ENV === 'test') {\n const index = focusableElement.indexOf(e.target as HTMLElement)\n if (index !== -1) {\n focusableElement[goingBackward ? index - 1 : index + 1]?.focus()\n }\n }\n }\n}\n\nconst TrapFocus: ObjectDirective = {\n beforeMount(el: TrapFocusElement) {\n el[FOCUSABLE_CHILDREN] = obtainAllFocusableElements(el)\n FOCUS_STACK.push(el)\n if (FOCUS_STACK.length <= 1) {\n document.addEventListener('keydown', FOCUS_HANDLER)\n }\n },\n updated(el: TrapFocusElement) {\n nextTick(() => {\n el[FOCUSABLE_CHILDREN] = obtainAllFocusableElements(el)\n })\n },\n unmounted() {\n FOCUS_STACK.shift()\n if (FOCUS_STACK.length === 0) {\n document.removeEventListener('keydown', FOCUS_HANDLER)\n }\n },\n}\n\nexport default TrapFocus\n"],"mappings":";;;;;;;;AAMA,MAAa,qBAAqB;AAClC,MAAa,qBAAqB;AAOlC,MAAM,cAAkC,EAAE;AAE1C,MAAM,iBAAiB,MAAqB;AAE1C,KAAI,YAAY,WAAW,EAAG;CAC9B,MAAM,OAAOA,2BAAa,EAAE;CAC5B,MAAM,mBACJ,YAAY,YAAY,SAAS,GAAG;AACtC,KAAI,iBAAiB,SAAS,KAAK,SAASC,wBAAW,KAAK;AAC1D,MAAI,iBAAiB,WAAW,GAAG;AACjC,KAAE,gBAAgB;AAClB,OAAI,SAAS,kBAAkB,iBAAiB,GAC9C,kBAAiB,GAAG,OAAO;AAE7B;;EAEF,MAAM,gBAAgB,EAAE;EACxB,MAAM,UAAU,EAAE,WAAW,iBAAiB;EAC9C,MAAM,SAAS,EAAE,WAAW,iBAAiB,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