You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
3 lines
24 KiB
3 lines
24 KiB
4 weeks ago
|
import{d as T,c as O,w as oe,z as ue,R as de,h as ye,a3 as q,a4 as P,u as K,B as ne,_ as B,a0 as D,m as L,n as H,Q as M,ac as J,U as Q,$ as W,F as ee,A as Ae,V as _,a5 as ie,a9 as ce}from"./vue-Cj9QYd7Z.js";import{k as V,s as o,c as De,aE as z,a7 as ae,e as j,Q as fe,aF as Te,_ as me}from"./index-D9S4mNPt.js";import{M as pe}from"./index-_1HmtNlW.js";import"./mxcad-Din5fhsn.js";import"./mapbox-gl-DQAr7S0z.js";import{L as G,g as Ie,a as ve,V as Pe,a8 as _e,a9 as Ne,c as Fe,b as U,h as Be,aa as Me,j as Ue,i as je,S as ze,d as te}from"./vuetify-BqCp6y38.js";import"./mxdraw-CvD1WFQ5.js";import"./handsontable-Ch5RdAT_.js";const Oe=navigator.platform.toLowerCase().includes("win")||navigator.userAgent.includes("Windows"),Re=()=>{const l=T([]),p=T(new Map),r=T({isLoading:!1,hasChanges:!1,lastError:null}),f=e=>{const n=l.value.find(s=>s.id===e);if(!n)return!1;const t=V.isKeySuspended(e),a=n.isSuspended;return t!==a&&(console.warn("Shortcut suspension state mismatch:",{id:e,managerState:t,localState:a}),a?V.suspendKey(e):V.resumeKey(e)),!0},d=(e,n)=>{const t=Array.isArray(e)?e:[e],a=[];return l.value.forEach(s=>{if(n&&s.id===n||s.isSuspended)return;const y=[];Array.isArray(s.key)?y.push(...s.key):s.key&&y.push(s.key),Oe&&s.winKey&&(Array.isArray(s.winKey)?y.push(...s.winKey):y.push(s.winKey));const k=($,g)=>{const I={ctrlKey:!!$.ctrlKey,shiftKey:!!$.shiftKey,altKey:!!$.altKey,metaKey:!!$.metaKey,keyCode:$.keyCode},N={ctrlKey:!!g.ctrlKey,shiftKey:!!g.shiftKey,altKey:!!g.altKey,metaKey:!!g.metaKey,keyCode:g.keyCode},h=I.ctrlKey===N.ctrlKey&&I.shiftKey===N.shiftKey&&I.altKey===N.altKey&&I.metaKey===N.metaKey,b=I.keyCode===N.keyCode;if(I.keyCode==="*"||N.keyCode==="*")return h;const S=h&&b;return S&&console.debug("Key comparison details:",{key1:I,key2:N,modifiersMatch:h,keyCodeMatch:b}),S};t.some($=>y.some(g=>{const I=k($,g);return I&&console.debug("Conflict detected:",{new:{keyCode:$.keyCode,ctrlKey:!!$.ctrlKey,shiftKey:!!$.shiftKey,altKey:!!$.altKey,metaKey:!!$.metaKey},existing:{keyCode:g.keyCode,ctrlKey:!!g.ctrlKey,shiftKey:!!g.shiftKey,altKey:!!g.altKey,metaKey:!!g.metaKey},shortcut:{id:s.id,label:s.info.label,command:s.info.command}}),I}))&&a.push(s)}),a.length>0&&console.warn("Shortcut conflicts found:",{newKeys:t.map(s=>({keyCode:s.keyCode,ctrlKey:!!s.ctrlKey,shiftKey:!!s.shiftKey,altKey:!!s.altKey,metaKey:!!s.metaKey})),conflicts:a.map(s=>({id:s.id,label:s.info.label,command:s.info.command,key:Array.isArray(s.key)?s.key.map(y=>({keyCode:y.keyCode,ctrlKey:!!y.ctrlKey,shiftKey:!!y.shiftKey,altKey:!!y.altKey,metaKey:!!y.metaKey})):s.key?{keyCode:s.key.keyCode,ctrlKey:!!s.key.ctrlKey,shiftKey:!!s.key.shiftKey,altKey:!!s.key.altKey,metaKey:!!s.key.metaKey}:null}))}),a},C=async e=>{const n=l.value.findIndex(t=>t.id===e);n!==-1&&(l.value.splice(n,1),V.unregister(e),r.value.hasChanges=!0)},i=()=>{try{const e=V.getRegisteredShortcuts(),n=V.getSuspendedKeys();l.value=e.filter(t=>!!(t.info&&typeof t.info.label=="string"&&typeof t.info.command=="string"&&typeof t.info.category=="string"&&typeof t.info.description=="string")).map(t=>{p.value.set(t.id,{key:t.key,winKey:t.winKey,when:t.when,action:t.action,isNoPreventDefault:t.isNoPreventDefault,info:t.info});const a=n.includes(t.id);return{...t,isSuspended:a}});for(const t of l.value)t.isSuspended&&V.suspendKey(t.id);l.value.forEach(t=>{f(t.id)})}catch(e){console.error(o("760")+":",e),r.value.lastError=e}},u=async(e,n)=>{try{r.value.isLoading=!0;const t=l.value.findIndex(A=>A.id===e);if(t===-1)return;const a=p.value.get(e);if(!a)return;const{skipConflictCheck:s,...y}=n;if(!s&&y.key){if(Array.isArray(y.key)){if(y.key.length===0)throw new Error(o("761"));y.key.forEach(($,g)=>{if(!$.keyCode)throw new Error(`${o("762")}${o("763")}${o("764")} ${g+1} ${o("207")}${o("765")}`)})}else if(!y.key.keyCode)throw new Error(o("766"));const A=d(y.key,e);if(A.length>0){const $=A.map(g=>({label:g.info.label,command:g.info.command,key:Array.isArray(g.key)?g.key[0]:g.key}));throw console.warn("Shortcut conflict detected:",{newKey:y.key,conflicts:$}),new Error(`${o("767")}:${o("437")}${o("395")} "${A.map(g=>
|
||
|
${t}`,defineTitle:o("229")});return}await l(r.value.id,{key:c,winKey:void 0}),w()}catch(c){console.error(o("769")+":",c),await ae().open({title:o("774"),text:o("769"),defineTitle:o("229")})}finally{C=!1}},u=x=>{d&&(d(),d=null),r.value=x,f.value=!0,C=!1;const c=n=>{f.value&&(n.preventDefault(),n.stopPropagation(),i(n))};document.addEventListener("keydown",c,!0);const e=n=>{const a=n.target.closest(".shortcut-input");a&&a.classList.contains("editing")?(n.preventDefault(),n.stopPropagation()):w()};document.addEventListener("click",e,!0),d=()=>{document.removeEventListener("keydown",c,!0),document.removeEventListener("click",e,!0),C=!1}},w=()=>{d&&(d(),d=null),r.value=null,f.value=!1,C=!1,setTimeout(()=>{C=!1},100)};return{editingShortcut:r,isEditing:f,handleKeyPress:i,startEdit:u,cancelEdit:w}},se=[{id:"all",name:o("全部"),icon:"$mdi-folder-multiple-outline",description:o("显示所有快捷键")},{id:"common",name:o("常用命令"),icon:"$mdi-star-outline",description:o("常用的基础操作命令")},{id:"draw",name:o("绘图命令"),icon:"$mdi-pencil-outline",description:o("绘制图形相关的命令")},{id:"edit",name:o("编辑命令"),icon:"$mdi-pencil-ruler",description:o("编辑修改图形的命令")},{id:"view",name:o("视图命令"),icon:"$mdi-eye-outline",description:o("视图操作相关的命令")},{id:"dim",name:o("标注命令"),icon:"$mdi-ruler",description:o("尺寸标注相关的命令")},{id:"custom",name:o("自定义命令"),icon:"$mdi-cog-outline",description:o("用户自定义的命令")}],He=l=>{const p=T("all"),r=T(se),f=O(()=>{const c=new Map;return r.value.forEach(e=>{c.set(e.id,0)}),l.value.forEach(e=>{const n=e.info.category;c.set(n,(c.get(n)||0)+1)}),c.set("all",l.value.length),c}),d=c=>{c!=="all"&&f.value.get(c)===0||(p.value=c)},C=c=>r.value.find(e=>e.id===c),i=()=>{p.value="all"},u=c=>C(c)?.icon||se[0].icon,w=c=>C(c)?.name||c,x=c=>p.value==="all"?c:c.filter(e=>e.info.category===p.value);return{categories:r.value,currentCategory:p,categoryCounts:f,switchCategory:d,getCategoryInfo:C,getCategoryIcon:u,getCategoryName:w,filterByCategory:x,resetCategory:i}};function Je(l,p,r=!1){let f=null,d=!0;return{exec:function(...u){const w=this;if(r&&d){l.apply(w,u),d=!1;return}f&&clearTimeout(f),f=setTimeout(()=>{l.apply(w,u),f=null,r&&(d=!0)},p)},cancel:()=>{f&&(clearTimeout(f),f=null),r&&(d=!0)}}}const Qe=(l,p)=>{const r=T(!1),f=T(!1),d=T({lastSyncTime:null,isSyncing:!1,syncError:null}),C=new Map,i=()=>{l.value.forEach(t=>{C.set(t.id,{when:t.when,action:t.action,isNoPreventDefault:t.isNoPreventDefault})})},{exec:u,cancel:w}=Je(async()=>{try{d.value.isSyncing=!0,await e(),d.value.lastSyncTime=new Date}catch(t){d.value.syncError=t,console.error(o("779")+":",t)}finally{d.value.isSyncing=!1}},1e3),x=async()=>{try{f.value=!0;const t={version:"1.0.0",shortcuts:l.value.map(k=>({id:k.id,key:k.key,winKey:k.winKey,info:{label:k.info.label,command:k.info.command,category:k.info.category,description:k.info.description},isSuspended:!!k.isSuspended}))},a=new Blob([JSON.stringify(t,null,2)],{type:"application/json"}),s=URL.createObjectURL(a),y=document.createElement("a");y.href=s,y.download=`shortcuts-${new Date().toISOString().slice(0,10)}.json`,document.body.appendChild(y),y.click(),document.body.removeChild(y),URL.revokeObjectURL(s)}catch(t){console.error(o("780")+":",t),ae().open({title:o("774"),text:o("780"),defineTitle:o("229")})}finally{f.value=!1}},c=async()=>{try{r.value=!0;const t=document.createElement("input");t.type="file",t.accept=".json";const s=await(await new Promise((A,$)=>{t.onchange=g=>{const I=g.target.files;I&&I.length>0?A(I[0]):$(new Error("未选择文件"))},t.click()})).text(),y=JSON.parse(s);if(!y.version||!Array.isArray(y.shortcuts))throw new Error("无效的配置文件格式");for(const A of y.shortcuts)if(l.value.find(g=>g.id===A.id)){const g=C.get(A.id);g&&await p(A.id,{key:A.key,winKey:A.winKey,isSuspended:A.isSuspended,...g,skipConflictCheck:!0})}j().success("快捷键配置导入成功")}catch(t){console.error("导入快捷键配置失败:",t),j().error("导入快捷键配置失败
|