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
+6
View File
@@ -0,0 +1,6 @@
import { ShallowRef } from "vue";
//#region ../../packages/hooks/use-cursor/index.d.ts
declare function useCursor(input: ShallowRef<HTMLInputElement | undefined>): [() => void, () => void];
//#endregion
export { useCursor };
+36
View File
@@ -0,0 +1,36 @@
//#region ../../packages/hooks/use-cursor/index.ts
function useCursor(input) {
let selectionInfo;
function recordCursor() {
if (input.value == void 0) return;
const { selectionStart, selectionEnd, value } = input.value;
if (selectionStart == null || selectionEnd == null) return;
selectionInfo = {
selectionStart,
selectionEnd,
value,
beforeTxt: value.slice(0, Math.max(0, selectionStart)),
afterTxt: value.slice(Math.max(0, selectionEnd))
};
}
function setCursor() {
if (input.value == void 0 || selectionInfo == void 0) return;
const { value } = input.value;
const { beforeTxt, afterTxt, selectionStart } = selectionInfo;
if (beforeTxt == void 0 || afterTxt == void 0 || selectionStart == void 0) return;
let startPos = value.length;
if (value.endsWith(afterTxt)) startPos = value.length - afterTxt.length;
else if (value.startsWith(beforeTxt)) startPos = beforeTxt.length;
else {
const beforeLastChar = beforeTxt[selectionStart - 1];
const newIndex = value.indexOf(beforeLastChar, selectionStart - 1);
if (newIndex !== -1) startPos = newIndex + 1;
}
input.value.setSelectionRange(startPos, startPos);
}
return [recordCursor, setCursor];
}
//#endregion
export { useCursor };
//# sourceMappingURL=index.mjs.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.mjs","names":[],"sources":["../../../../../packages/hooks/use-cursor/index.ts"],"sourcesContent":["import type { ShallowRef } from 'vue'\n\ninterface SelectionInfo {\n selectionStart?: number\n selectionEnd?: number\n value?: string\n beforeTxt?: string\n afterTxt?: string\n}\n\n// Keep input cursor in the correct position when we use formatter.\nexport function useCursor(\n input: ShallowRef<HTMLInputElement | undefined>\n): [() => void, () => void] {\n let selectionInfo: SelectionInfo\n function recordCursor() {\n if (input.value == undefined) return\n\n const { selectionStart, selectionEnd, value } = input.value\n\n if (selectionStart == null || selectionEnd == null) return\n\n const beforeTxt = value.slice(0, Math.max(0, selectionStart))\n const afterTxt = value.slice(Math.max(0, selectionEnd))\n\n selectionInfo = {\n selectionStart,\n selectionEnd,\n value,\n beforeTxt,\n afterTxt,\n }\n }\n function setCursor() {\n if (input.value == undefined || selectionInfo == undefined) return\n\n const { value } = input.value\n const { beforeTxt, afterTxt, selectionStart } = selectionInfo\n\n if (\n beforeTxt == undefined ||\n afterTxt == undefined ||\n selectionStart == undefined\n )\n return\n\n let startPos = value.length\n\n if (value.endsWith(afterTxt)) {\n startPos = value.length - afterTxt.length\n } else if (value.startsWith(beforeTxt)) {\n startPos = beforeTxt.length\n } else {\n const beforeLastChar = beforeTxt[selectionStart - 1]\n const newIndex = value.indexOf(beforeLastChar, selectionStart - 1)\n if (newIndex !== -1) {\n startPos = newIndex + 1\n }\n }\n\n input.value.setSelectionRange(startPos, startPos)\n }\n\n return [recordCursor, setCursor]\n}\n"],"mappings":";AAWA,SAAgB,UACd,OAC0B;CAC1B,IAAI;CACJ,SAAS,eAAe;AACtB,MAAI,MAAM,SAAS,OAAW;EAE9B,MAAM,EAAE,gBAAgB,cAAc,UAAU,MAAM;AAEtD,MAAI,kBAAkB,QAAQ,gBAAgB,KAAM;AAKpD,kBAAgB;GACd;GACA;GACA;GACA,WAPgB,MAAM,MAAM,GAAG,KAAK,IAAI,GAAG,eAAe,CAAC;GAQ3D,UAPe,MAAM,MAAM,KAAK,IAAI,GAAG,aAAa,CAAC;GAQtD;;CAEH,SAAS,YAAY;AACnB,MAAI,MAAM,SAAS,UAAa,iBAAiB,OAAW;EAE5D,MAAM,EAAE,UAAU,MAAM;EACxB,MAAM,EAAE,WAAW,UAAU,mBAAmB;AAEhD,MACE,aAAa,UACb,YAAY,UACZ,kBAAkB,OAElB;EAEF,IAAI,WAAW,MAAM;AAErB,MAAI,MAAM,SAAS,SAAS,CAC1B,YAAW,MAAM,SAAS,SAAS;WAC1B,MAAM,WAAW,UAAU,CACpC,YAAW,UAAU;OAChB;GACL,MAAM,iBAAiB,UAAU,iBAAiB;GAClD,MAAM,WAAW,MAAM,QAAQ,gBAAgB,iBAAiB,EAAE;AAClE,OAAI,aAAa,GACf,YAAW,WAAW;;AAI1B,QAAM,MAAM,kBAAkB,UAAU,SAAS;;AAGnD,QAAO,CAAC,cAAc,UAAU"}