cnhis-design-vue 3.1.51-beta.14 → 3.1.51-beta.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- import{defineComponent as e,inject as l,ref as t,computed as o,createVNode as n,toRaw as a,Fragment as u,createTextVNode as i}from"vue";import{keywordMatcher as r,arrayed as d}from"../../../../../../../shared/utils/index.js";import{NSelect as s,NTooltip as p,NIcon as c,NTag as v,NButton as f}from"naive-ui";import{HelpCircleSharp as m}from"@vicons/ionicons5";import{InjectionIhoTableUUID as y}from"../../../../constants/index.js";import{getSelectOptions as h,selectOptionsMap as b}from"../hooks/useSelectOption.js";import{useIhoTableFormEvent as F}from"../../../../utils/index.js";import{useDebounceFn as w}from"@vueuse/core";import{isEmpty as g,isFunction as S,isArray as O,isObject as q,omit as x,cloneDeep as C}from"lodash-es";var $=e({name:"EditSelect",props:{value:{type:[Array,String,Number]},column:{type:Object,required:!0},row:{type:Object,required:!0},rowIndex:{type:Number,required:!0},options:{type:Array,default:()=>[]},queryOptions:{type:Function},placeholder:{type:String,default:"请选择"},allowCreate:{type:Boolean,default:!1},shouldSave:{type:Boolean,default:!1},consistentMenuWidth:{type:Boolean,default:!0},labelField:{type:String,default:"label"},valueField:{type:String,default:"value"},aliasField:{type:String},menuProps:{type:Object},multiple:{type:Boolean,default:!1},deletable:{type:Boolean,default:!0},selectAll:{type:Boolean,default:!0}},emits:["update:value"],setup(e,{emit:$}){const _=l("$xetable"),j=t(null);function k(e){j.value=e}const P=t(!1),{emitFormChangeWithParams:B}=F({...e,$table:_}),W=t("");function A(){return I()}const D=t([]),E=o((()=>{let l=g(D.value)?e.options:D.value;return W.value?(l=l.filter((l=>l[e.labelField]&&l[e.labelField].includes(W.value)||r(W.value,l.keyword))),!e.allowCreate||l.some((l=>l[e.labelField]===W.value))?l:[...l,{[e.labelField]:W.value,[e.valueField]:W.value,created:!0,shouldSave:e.shouldSave}]):l})),M=t(!1),I=w((async function(l=""){W.value=l;try{if(M.value=!0,!S(e.queryOptions)||!g(e.options))return;D.value=await e.queryOptions({keyword:l,row:e.row,column:e.column,rowIndex:e.rowIndex})}catch(l){console.log(`获取${e.column.field}options错误`)}finally{M.value=!1}}),400),U=l(y);function V(l,t){var o,n;const u=e.value;$("update:value",l);const i=h(U,e.column.field,e.row,_);U&&O(i)&&d(t).forEach((e=>{if(!q(e))return;const l=e;l.created&&l.shouldSave&&i.push(x(a(l),["created","shouldSave"]))}));const r=null==(o=e.column.editRender)?void 0:o.props;if(U&&(null==r?void 0:r.connectField)){const t=null==(n=r.connectField)?void 0:n.split(","),o=b.get(U);t.forEach((async t=>{var n;const{tableColumn:a}=_.reactData,u=a.find((e=>e.field===t)),i=null==(n=null==u?void 0:u.editRender)?void 0:n.props;if(null==i?void 0:i.queryOptions){const n=l?`${t}__${e.column.field}-${l}`:t;if(o[n])return;const a=await i.queryOptions({row:e.row,column:u,isFullData:!0});o[n]=a}}))}B({oldValue:u,option:C(t)})}function z(e){var l,t;"Tab"===e.key&&j.value&&(null==(t=(l=j.value).handleKeydown)||t.call(l,{...e,key:"Enter",preventDefault:e.preventDefault.bind(e)}))}function K(l){const t=l?E.value.map((l=>l[e.valueField])):[],o=e.value,n=O(o)?o.length:0;t.length!==n&&($("update:value",t),B({oldValue:o,option:l?C(E.value):[]}))}function N({node:e,option:l}){return l.desc?n("div",{class:"iho-table__selectOptionWrapper"},[[e,n(p,null,{trigger:()=>n(c,{component:m},null),default:()=>l.desc})]]):e}function R({option:l,handleClose:t}){var o;const a=null!=(o=e.aliasField&&l[e.aliasField])?o:l[e.labelField];return O(e.value)?e.deletable?n(v,{closable:!0,onClose:e=>{e.stopPropagation(),t()}},{default:()=>a}):`${a} ;`:n(u,null,[a])}function T(){return n(u,null,[n(f,{quaternary:!0,type:"primary",size:"tiny",onClick:()=>K(!0)},{default:()=>[i("全选")]}),n(f,{quaternary:!0,type:"primary",size:"tiny",onClick:()=>K(!1)},{default:()=>[i("清空")]})])}const G=()=>({class:"iho-table__selectOption"}),H=o((()=>{var l,t;return{...e.menuProps,class:`iho-table__selectMenu ${null!=(t=null==(l=e.menuProps)?void 0:l.class)?t:""}`}}));return()=>{const l={};return e.multiple&&e.selectAll&&(l.action=T),n(s,{ref:k,show:P.value,"onUpdate:show":e=>P.value=e,consistentMenuWidth:e.consistentMenuWidth,placeholder:e.placeholder,labelField:e.labelField,valueField:e.valueField,loading:M.value,options:E.value,multiple:e.multiple,value:e.value,remote:!0,onSearch:I,clearable:!0,filterable:!0,nodeProps:G,menuProps:H.value,renderTag:R,renderOption:N,onUpdateShow:A,onUpdateValue:V,onKeydown:z},l)}}});export{$ as default};
1
+ import{defineComponent as e,inject as l,ref as t,computed as o,createVNode as n,toRaw as a,Fragment as u,createTextVNode as i}from"vue";import{keywordMatcher as r,arrayed as d}from"../../../../../../../shared/utils/index.js";import{NSelect as s,NTooltip as c,NIcon as p,NTag as v,NButton as f}from"naive-ui";import{HelpCircleSharp as m}from"@vicons/ionicons5";import{InjectionIhoTableUUID as y}from"../../../../constants/index.js";import{getSelectOptions as h,selectOptionsMap as b}from"../hooks/useSelectOption.js";import{useIhoTableFormEvent as F}from"../../../../utils/index.js";import{useDebounceFn as w}from"@vueuse/core";import{isEmpty as g,isFunction as S,isArray as O,isObject as q,omit as C,cloneDeep as x}from"lodash-es";var $=e({name:"EditSelect",props:{value:{type:[Array,String,Number]},column:{type:Object,required:!0},row:{type:Object,required:!0},rowIndex:{type:Number,required:!0},options:{type:Array,default:()=>[]},queryOptions:{type:Function},placeholder:{type:String,default:"请选择"},allowCreate:{type:Boolean,default:!1},shouldSave:{type:Boolean,default:!1},consistentMenuWidth:{type:Boolean,default:!0},labelField:{type:String,default:"label"},valueField:{type:String,default:"value"},aliasField:{type:String},menuProps:{type:Object},multiple:{type:Boolean,default:!1},deletable:{type:Boolean,default:!0},selectAll:{type:Boolean,default:!0}},emits:["update:value"],setup(e,{emit:$}){const _=l("$xetable"),j=t(null);function k(e){j.value=e}const P=t(!1),{emitFormChangeWithParams:B}=F({...e,$table:_}),W=t("");function A(){return I()}const D=t([]),E=o((()=>{let l=g(D.value)?e.options:D.value;return W.value?(l=l.filter((l=>l[e.labelField]&&l[e.labelField].includes(W.value)||r(W.value,l.keyword))),!e.allowCreate||l.some((l=>l[e.labelField]===W.value))?l:[...l,{[e.labelField]:W.value,[e.valueField]:W.value,created:!0,shouldSave:e.shouldSave}]):l})),M=t(!1),I=w((async function(l=""){W.value=l;try{if(M.value=!0,!S(e.queryOptions)||!g(e.options))return;D.value=await e.queryOptions({keyword:l,row:e.row,column:e.column,rowIndex:e.rowIndex})}catch(l){console.log(`获取${e.column.field}options错误`)}finally{M.value=!1}}),400),U=l(y);function V(l,t){var o,n;const u=e.value;$("update:value",l);const i=h(U,e.column.field,e.row,_);U&&O(i)&&d(t).forEach((e=>{if(!q(e))return;const l=e;l.created&&l.shouldSave&&i.push(C(a(l),["created","shouldSave"]))}));const r=null==(o=e.column.editRender)?void 0:o.props;if(U&&(null==r?void 0:r.connectField)){const t=null==(n=r.connectField)?void 0:n.split(","),o=b.get(U);t.forEach((async t=>{var n;const{tableColumn:a}=_.reactData,u=a.find((e=>e.field===t)),i=null==(n=null==u?void 0:u.editRender)?void 0:n.props;if(null==i?void 0:i.queryOptions){const n=l?`${t}__${e.column.field}-${l}`:t;if(o[n])return;const a=await i.queryOptions({row:e.row,column:u,isFullData:!0,connectColumn:e.column});o[n]=a}}))}B({oldValue:u,option:x(t)})}function z(e){var l,t;"Tab"===e.key&&j.value&&(null==(t=(l=j.value).handleKeydown)||t.call(l,{...e,key:"Enter",preventDefault:e.preventDefault.bind(e)}))}function K(l){const t=l?E.value.map((l=>l[e.valueField])):[],o=e.value,n=O(o)?o.length:0;t.length!==n&&($("update:value",t),B({oldValue:o,option:l?x(E.value):[]}))}function N({node:e,option:l}){return l.desc?n("div",{class:"iho-table__selectOptionWrapper"},[[e,n(c,null,{trigger:()=>n(p,{component:m},null),default:()=>l.desc})]]):e}function R({option:l,handleClose:t}){var o;const a=null!=(o=e.aliasField&&l[e.aliasField])?o:l[e.labelField];return O(e.value)?e.deletable?n(v,{closable:!0,onClose:e=>{e.stopPropagation(),t()}},{default:()=>a}):`${a} ;`:n(u,null,[a])}function T(){return n(u,null,[n(f,{quaternary:!0,type:"primary",size:"tiny",onClick:()=>K(!0)},{default:()=>[i("全选")]}),n(f,{quaternary:!0,type:"primary",size:"tiny",onClick:()=>K(!1)},{default:()=>[i("清空")]})])}const G=()=>({class:"iho-table__selectOption"}),H=o((()=>{var l,t;return{...e.menuProps,class:`iho-table__selectMenu ${null!=(t=null==(l=e.menuProps)?void 0:l.class)?t:""}`}}));return()=>{const l={};return e.multiple&&e.selectAll&&(l.action=T),n(s,{ref:k,show:P.value,"onUpdate:show":e=>P.value=e,consistentMenuWidth:e.consistentMenuWidth,placeholder:e.placeholder,labelField:e.labelField,valueField:e.valueField,loading:M.value,options:E.value,multiple:e.multiple,value:e.value,remote:!0,onSearch:I,clearable:!0,filterable:!0,nodeProps:G,menuProps:H.value,renderTag:R,renderOption:N,onUpdateShow:A,onUpdateValue:V,onKeydown:z},l)}}});export{$ as default};
@@ -1 +1 @@
1
- import{reactive as e,inject as o,createVNode as t,mergeProps as n,onBeforeUnmount as l}from"vue";import{arrayed as i}from"../../../../../../../shared/utils/index.js";import"../../../../../index.js";import{EDITABLE_WIDGET_TYPE as r,InjectionIhoTableUUID as s}from"../../../../constants/index.js";import{useAutoFocus as d}from"../hooks/useAutoFocus.js";import{createIhoTableClearActivedInterceptor as u,getTitle as a,IhoTableRenderHelper as c,IhoTableUtils as p}from"../../../../utils/index.js";import f from"./editSelect.js";import{getDefaultValue as m,isConnectField as v,getArray as E}from"./selectUtils.js";import{getSelectOptions as g,selectOptionsMap as b}from"../hooks/useSelectOption.js";import{cloneDeep as h,isEqual as w}from"lodash-es";import{defineTablePlugin as C}from"../../../../hooks/useTablePlugin.js";function x(){const x="selectRendererPlugin",k=e(new Map);return C({name:x,vxe(e){e.interceptor.add("event.clearActived",u(r.SELECT,(e=>e.classList.contains("iho-table__selectMenu")))),e.renderer.add(r.SELECT,{renderCell({props:e},{row:n,column:l,$table:r}){var d;const u=o(s),c=g(u,l.field,n,r),p=m(n,e,c),f=i(p).join(","),v=e&&(!0===(E=e.variableHeight)||"1"===E||(null==(d=e.componentProps)?void 0:d.indexedText));var E;return[t("span",{title:a(l,f)},[v?i(p).filter((e=>null!=e)).map(((e,o)=>[o+1,".",e,";",t("br",null,null)])):f])]},renderEdit:c.createRenderEdit((({fieldItem:e,emitFormClick:l,row:i,column:r,$rowIndex:d,$table:u})=>{const a=o(s),c=g(a,r.field,i,u);return[t(f,n({queryOptions:e.queryOptions},e.componentProps,{options:c,column:r,row:i,"row-index":d,value:i[r.field],"onUpdate:value":e=>i[r.field]=e,onClick:l}),null)]}))})},apply(e){async function o(e,o={}){var t,n,l;const i=null==(t=e.editRender)?void 0:t.props;if(!i)return[];let r=E(i.options)||E(null==(n=i.componentProps)?void 0:n.options)||[];if(i.queryOptions)try{const t={column:e,isFullData:!0,...o};r=await(null==(l=i.queryOptions)?void 0:l.call(i,t))}catch(e){console.log(`获取${i.field}_options错误`)}return r}d(e).bindAutoFocusConfig(x,r.SELECT,".n-base-selection-input"),e.fieldHooks.fieldList.tap(x,((e,{uuid:o})=>(o&&(b.get(o)||b.set(o,{}),k.set(o,h(e))),e))),e.dataHooks.data.tap(x,((e,{uuid:t},n)=>{if(!t)return;const l=k.get(t);if(!l||!l.length)return;const i=b.get(t);l.forEach((async t=>{var n;const r=null==(n=t.editRender)?void 0:n.props;if(t.field&&r&&"SELECT"===p.getCellType(r)){if(null==r?void 0:r.connectField){const t=r.connectField.split(","),n=e[r.columnName];t.forEach((async t=>{const s=null==l?void 0:l.find((e=>e.field===t));if(!s)return;const d=n?`${t}__${r.columnName}-${n}`:t;i[d]||(i[d]=[],i[d]=await o(s,{row:e}))}))}i[t.field]||v(l,t.field)||(i[t.field]=[],i[t.field]=await o(t))}}))})),e.setupHooks.setup.tap(x,(e=>{l((()=>{var o;const t=null==(o=e.value)?void 0:o.uuid;t&&(b.delete(t),k.delete(t))}))})),e.eventHooks.onCellDblclick.tap(x,(({$table:e},o,{emits:t})=>{var n;const{column:l,row:i}=e.reactData.editStore.actived,s=null==(n=l.editRender)?void 0:n.props,{cellDblclickSelectable:d=!1,multiple:u=!1,valueField:a="value"}=s.componentProps||{};if(!d||!l||!function(e){return e&&p.getCellType(e)===r.SELECT}(s))return;const c=o.uuid&&g(o.uuid,l.field,i,e);if(1!==(null==c?void 0:c.length))return;const f=u?[c[0][a]]:c[0][a],m=i[l.field];e.clearEdit(),w(f,m)||(i[l.field]=f,t("formChange",{column:l,row:i,oldValue:m,value:f,index:e.getRowIndex(i),$table:e,option:c[0]}))}))}})}export{x as selectRendererPlugin};
1
+ import{reactive as e,inject as o,createVNode as t,mergeProps as n,onBeforeUnmount as l}from"vue";import{arrayed as i}from"../../../../../../../shared/utils/index.js";import"../../../../../index.js";import{EDITABLE_WIDGET_TYPE as r,InjectionIhoTableUUID as s}from"../../../../constants/index.js";import{useAutoFocus as d}from"../hooks/useAutoFocus.js";import{createIhoTableClearActivedInterceptor as u,getTitle as c,IhoTableRenderHelper as a,IhoTableUtils as p}from"../../../../utils/index.js";import f from"./editSelect.js";import{getDefaultValue as m,isConnectField as v,getArray as E}from"./selectUtils.js";import{getSelectOptions as g,selectOptionsMap as w}from"../hooks/useSelectOption.js";import{cloneDeep as C,isEqual as b}from"lodash-es";import{defineTablePlugin as h}from"../../../../hooks/useTablePlugin.js";function x(){const x="selectRendererPlugin",k=e(new Map);return h({name:x,vxe(e){e.interceptor.add("event.clearActived",u(r.SELECT,(e=>e.classList.contains("iho-table__selectMenu")))),e.renderer.add(r.SELECT,{renderCell({props:e},{row:n,column:l,$table:r}){var d;const u=o(s),a=g(u,l.field,n,r),p=m(n,e,a),f=i(p).join(","),v=e&&(!0===(E=e.variableHeight)||"1"===E||(null==(d=e.componentProps)?void 0:d.indexedText));var E;return[t("span",{title:c(l,f)},[v?i(p).filter((e=>null!=e)).map(((e,o)=>[o+1,".",e,";",t("br",null,null)])):f])]},renderEdit:a.createRenderEdit((({fieldItem:e,emitFormClick:l,row:i,column:r,$rowIndex:d,$table:u})=>{const c=o(s),a=g(c,r.field,i,u);return[t(f,n({queryOptions:e.queryOptions},e.componentProps,{options:a,column:r,row:i,"row-index":d,value:i[r.field],"onUpdate:value":e=>i[r.field]=e,onClick:l}),null)]}))})},apply(e){async function o(e,o={}){var t,n,l;const i=null==(t=e.editRender)?void 0:t.props;if(!i)return[];let r=E(i.options)||E(null==(n=i.componentProps)?void 0:n.options)||[];if(i.queryOptions)try{const t={column:e,isFullData:!0,...o};r=await(null==(l=i.queryOptions)?void 0:l.call(i,t))}catch(e){console.log(`获取${i.field}_options错误`)}return r}d(e).bindAutoFocusConfig(x,r.SELECT,".n-base-selection-input"),e.fieldHooks.fieldList.tap(x,((e,{uuid:o})=>(o&&(w.get(o)||w.set(o,{}),k.set(o,C(e))),e))),e.dataHooks.data.tap(x,((e,{uuid:t},n)=>{if(!t)return;const l=k.get(t);if(!l||!l.length)return;const i=w.get(t);l.forEach((async t=>{var n;const r=null==(n=t.editRender)?void 0:n.props;if(t.field&&r&&"SELECT"===p.getCellType(r)){if(null==r?void 0:r.connectField){const n=r.connectField.split(","),s=e[r.columnName];n.forEach((async n=>{const d=null==l?void 0:l.find((e=>e.field===n));if(!d)return;const u=s?`${n}__${r.columnName}-${s}`:n;i[u]||(i[u]=[],i[u]=await o(d,{row:e,connectColumn:t}))}))}i[t.field]||v(l,t.field)||(i[t.field]=[],i[t.field]=await o(t,{row:e}))}}))})),e.setupHooks.setup.tap(x,(e=>{l((()=>{var o;const t=null==(o=e.value)?void 0:o.uuid;t&&(w.delete(t),k.delete(t))}))})),e.eventHooks.onCellDblclick.tap(x,(({$table:e},o,{emits:t})=>{var n;const{column:l,row:i}=e.reactData.editStore.actived,s=null==(n=l.editRender)?void 0:n.props,{cellDblclickSelectable:d=!1,multiple:u=!1,valueField:c="value"}=s.componentProps||{};if(!d||!l||!function(e){return e&&p.getCellType(e)===r.SELECT}(s))return;const a=o.uuid&&g(o.uuid,l.field,i,e);if(1!==(null==a?void 0:a.length))return;const f=u?[a[0][c]]:a[0][c],m=i[l.field];e.clearEdit(),b(f,m)||(i[l.field]=f,t("formChange",{column:l,row:i,oldValue:m,value:f,index:e.getRowIndex(i),$table:e,option:a[0]}))}))}})}export{x as selectRendererPlugin};
@@ -89,6 +89,7 @@ export declare namespace IhoTableLowCodeField {
89
89
  column: VxeTableDefines.ColumnInfo;
90
90
  rowIndex?: number;
91
91
  isFullData?: boolean;
92
+ connectColumn?: VxeTableDefines.ColumnInfo;
92
93
  }) => Promise<AnyObject[]>;
93
94
  }
94
95
  export declare type LowCodeTableFieldItem = {
@@ -25,6 +25,7 @@ export declare function useShortcuts(scope?: MaybeRef<string | Symbol | undefine
25
25
  register: (shortcut: ShortcutOption) => {
26
26
  stop: () => void;
27
27
  signature: () => string;
28
+ start: () => void;
28
29
  };
29
30
  traverse: () => Omit<ShortcutItem, "callback">[];
30
31
  clear: () => void;
@@ -1 +1 @@
1
- import{findAncestor as t}from"../../../../shared/utils/index.js";import{useEventListener as e,useDebounceFn as r}from"@vueuse/core";import{once as s,pick as a,omit as n,isFunction as u,isString as c}from"lodash-es";import{reactive as o,ref as i,unref as l,computed as h,getCurrentInstance as d,inject as p,onBeforeUnmount as g,onDeactivated as b,onActivated as v}from"vue";import{ShortcutStatus as f,InjectionShortcutManager as k}from"../constants/index.js";import{normalizeSignatureInfo as y,getKeySignature as C,getDisplaySignature as m,isInvalidSignature as S,isKeyboardEvent as w,isInvalidKeyboardEvent as E,isShortcutProvider as M}from"../utils/index.js";const K=Symbol("Glob"),j=new Map;class ${constructor(t,e=K){this.shortcutCallbackMap=o(new Map),this.shortcutCache=i({}),this.disabled=!1,this.environmentEle=t||window,j.set(e,this)}static log(t,e=!1){const r=`[ShortcutManager] ${t}`;return!e&&console.warn(r),r}get traverse(){return[...Object.values(this.shortcutCache.value)].sort(((t,e)=>(t.order||0)-(e.order||0)))}query(t){return this.shortcutCache.value[t]}async update(t,e){var r,s;const a=null==(r=this.query(t))?void 0:r.currentKeySignature;e&&u(this.shortcutCache,e);const n=this.query(t);function u(t,e){if(a!==C(e)){if(Object.values(t.value).some((t=>t.currentKeySignature===C(e))))throw`重复的快捷键=> ${m(e)}`;if(S(e))throw`非法的快捷键=>${e.key}`}}n&&(await(null==(s=n.onUpdate)?void 0:s.call(n,t,e?y(e):void 0)),u(this.shortcutCache,e),n.currentKeySignature=C(e),n.shortcutSignature=y(e),this.shortcutCallbackMap.set(n.currentKeySignature,this.shortcutCallbackMap.get(a)),this.shortcutCallbackMap.delete(a))}register(t){const e=this.query(t.key);return e?(e.status=f.ACTIVE,this.shortcutCallbackMap.set(e.currentKeySignature,t.callback),Object.assign(e,a(t,["debounce","debounceOption","label","order","key"])),r(e)):(this.shortcutCache.value[t.key]=n(t,["callback"]),this.shortcutCallbackMap.set(t.currentKeySignature,t.callback),r(this.shortcutCache.value[t.key]));function r(t){return{stop:()=>{t.status=f.INACTIVE},start:()=>{t.status=f.ACTIVE},signature:()=>t.currentKeySignature}}}start(){return this.handle?($.log(`请勿重复启动=>${this}`),this):(this.handle=async e=>{if(!w(e)||this.disabled)return;const r=t(e.target,M);if(r&&r!==l(this.environmentEle)||E(e))return;const s=C(e),a=this.shortcutCallbackMap.get(s);if(!a)return;e.preventDefault();const n=Object.values(this.shortcutCache.value).find((t=>t.currentKeySignature===s));n&&n.status===f.ACTIVE&&!n.disabled&&a(e)},e(this.environmentEle,"keyup",this.handle,{capture:!0}),this)}destroy(){var t;this.handle&&(null==(t=l(this.environmentEle))||t.removeEventListener("keyup",this.handle,{capture:!0})),this.handle=void 0,this.clear()}clear(){this.shortcutCallbackMap.clear(),this.shortcutCache.value={}}}const I=(new $).start(),O=s((()=>$.log("非setup语境下的shortcut将影响全局"))),A=s((()=>$.log("在非setup语境下使用register函数,组件销毁时可能需要手动调用stop函数使快捷键失活")));function T(t){const e=h((()=>{if(l(t)){const e=j.get(l(t));return e||$.log(`不存在的scope=>${t}, 将使用全局快捷键`),e||I}return d()?p(k,I):(O(),I)}));return{register:function(t){const{stop:s,signature:a,start:n}=l(e).register(function(t){return{...t,shortcutSignature:y(t.shortcutSignature),currentKeySignature:C(t.shortcutSignature),key:function(t){const e=t.key||t.label;if(!c(e))throw new Error($.log(`非法的key类型=>${e}`,!0));return e}(t),status:f.ACTIVE,callback:function(t){var e,s;if(!u(t.callback))throw new Error($.log(`非法的callback类型=>${t.callback}`,!0));return t.debounce?r(t.callback,null!=(s=null==(e=t.debounceOption)?void 0:e.duration)?s:300):t.callback}(t)}}(t));return d()?(g(s),b(s),v(n)):A(),{stop:s,signature:a}},traverse:function(){return l(e).traverse},clear:function(){l(e).clear()},update:function(t,r){return l(e).update(t,r)},updateManagerDisabled:function(t){l(e).disabled=!!t}}}export{K as GlobalShortcutProvider,$ as ShortcutManager,T as useShortcuts};
1
+ import{findAncestor as t}from"../../../../shared/utils/index.js";import{useEventListener as e,useDebounceFn as r}from"@vueuse/core";import{once as s,pick as a,omit as n,isFunction as u,isString as c}from"lodash-es";import{reactive as o,ref as i,unref as l,computed as h,getCurrentInstance as d,inject as p,onBeforeUnmount as g,onDeactivated as b,onActivated as v}from"vue";import{ShortcutStatus as f,InjectionShortcutManager as k}from"../constants/index.js";import{normalizeSignatureInfo as y,getKeySignature as C,getDisplaySignature as m,isInvalidSignature as S,isKeyboardEvent as w,isInvalidKeyboardEvent as E,isShortcutProvider as M}from"../utils/index.js";const K=Symbol("Glob"),j=new Map;class ${constructor(t,e=K){this.shortcutCallbackMap=o(new Map),this.shortcutCache=i({}),this.disabled=!1,this.environmentEle=t||window,j.set(e,this)}static log(t,e=!1){const r=`[ShortcutManager] ${t}`;return!e&&console.warn(r),r}get traverse(){return[...Object.values(this.shortcutCache.value)].sort(((t,e)=>(t.order||0)-(e.order||0)))}query(t){return this.shortcutCache.value[t]}async update(t,e){var r,s;const a=null==(r=this.query(t))?void 0:r.currentKeySignature;e&&u(this.shortcutCache,e);const n=this.query(t);function u(t,e){if(a!==C(e)){if(Object.values(t.value).some((t=>t.currentKeySignature===C(e))))throw`重复的快捷键=> ${m(e)}`;if(S(e))throw`非法的快捷键=>${e.key}`}}n&&(await(null==(s=n.onUpdate)?void 0:s.call(n,t,e?y(e):void 0)),u(this.shortcutCache,e),n.currentKeySignature=C(e),n.shortcutSignature=y(e),this.shortcutCallbackMap.set(n.currentKeySignature,this.shortcutCallbackMap.get(a)),this.shortcutCallbackMap.delete(a))}register(t){const e=this.query(t.key);return e?(e.status=f.ACTIVE,this.shortcutCallbackMap.set(e.currentKeySignature,t.callback),Object.assign(e,a(t,["debounce","debounceOption","label","order","key"])),r(e)):(this.shortcutCache.value[t.key]=n(t,["callback"]),this.shortcutCallbackMap.set(t.currentKeySignature,t.callback),r(this.shortcutCache.value[t.key]));function r(t){return{stop:()=>{t.status=f.INACTIVE},start:()=>{t.status=f.ACTIVE},signature:()=>t.currentKeySignature}}}start(){return this.handle?($.log(`请勿重复启动=>${this}`),this):(this.handle=async e=>{if(!w(e)||this.disabled)return;const r=t(e.target,M);if(r&&r!==l(this.environmentEle)||E(e))return;const s=C(e),a=this.shortcutCallbackMap.get(s);if(!a)return;e.preventDefault();const n=Object.values(this.shortcutCache.value).find((t=>t.currentKeySignature===s));n&&n.status===f.ACTIVE&&!n.disabled&&a(e)},e(this.environmentEle,"keyup",this.handle,{capture:!0}),this)}destroy(){var t;this.handle&&(null==(t=l(this.environmentEle))||t.removeEventListener("keyup",this.handle,{capture:!0})),this.handle=void 0,this.clear()}clear(){this.shortcutCallbackMap.clear(),this.shortcutCache.value={}}}const I=(new $).start(),O=s((()=>$.log("非setup语境下的shortcut将影响全局"))),A=s((()=>$.log("在非setup语境下使用register函数,组件销毁时可能需要手动调用stop函数使快捷键失活")));function T(t){const e=h((()=>{if(l(t)){const e=j.get(l(t));return e||$.log(`不存在的scope=>${t}, 将使用全局快捷键`),e||I}return d()?p(k,I):(O(),I)}));return{register:function(t){const{stop:s,signature:a,start:n}=l(e).register(function(t){return{...t,shortcutSignature:y(t.shortcutSignature),currentKeySignature:C(t.shortcutSignature),key:function(t){const e=t.key||t.label;if(!c(e))throw new Error($.log(`非法的key类型=>${e}`,!0));return e}(t),status:f.ACTIVE,callback:function(t){var e,s;if(!u(t.callback))throw new Error($.log(`非法的callback类型=>${t.callback}`,!0));return t.debounce?r(t.callback,null!=(s=null==(e=t.debounceOption)?void 0:e.duration)?s:300):t.callback}(t)}}(t));return d()?(g(s),b(s),v(n)):A(),{stop:s,signature:a,start:n}},traverse:function(){return l(e).traverse},clear:function(){l(e).clear()},update:function(t,r){return l(e).update(t,r)},updateManagerDisabled:function(t){l(e).disabled=!!t}}}export{K as GlobalShortcutProvider,$ as ShortcutManager,T as useShortcuts};
@@ -29,6 +29,7 @@ declare const ShortcutSetter: SFCWithInstall<import("vue").DefineComponent<{
29
29
  register: (shortcut: import("..").ShortcutOption) => {
30
30
  stop: () => void;
31
31
  signature: () => string;
32
+ start: () => void;
32
33
  };
33
34
  traverse: () => Omit<import("..").ShortcutItem, "callback">[];
34
35
  clear: () => void;
@@ -31,6 +31,7 @@ declare const _default: import("vue").DefineComponent<{
31
31
  register: (shortcut: import("../../../../es/components/shortcut-provider").ShortcutOption) => {
32
32
  stop: () => void;
33
33
  signature: () => string;
34
+ start: () => void;
34
35
  };
35
36
  traverse: () => Omit<import("../../../../es/components/shortcut-provider").ShortcutItem, "callback">[];
36
37
  clear: () => void;
@@ -1 +1 @@
1
- var e="@cnhis-design-vue/shared",i="3.1.51-beta.14",s="index.ts",n={"naive-ui":"^2.30.0",vue:"^3.2.0"},a={"@vicons/ionicons5":"^0.12.0","lodash-es":"^4.17.21",moment:"^2.29.1","video.js":"^7.19.2","videojs-contrib-hls":"^5.15.0",viewerjs:"^1.10.5","xe-utils":"^3.5.4"},d={name:e,version:"3.1.51-beta.14",private:!0,main:"index.ts",peerDependencies:n,dependencies:a};export{d as default,a as dependencies,s as main,e as name,n as peerDependencies,i as version};
1
+ var e="@cnhis-design-vue/shared",i="3.1.51-beta.16",s="index.ts",n={"naive-ui":"^2.30.0",vue:"^3.2.0"},a={"@vicons/ionicons5":"^0.12.0","lodash-es":"^4.17.21",moment:"^2.29.1","video.js":"^7.19.2","videojs-contrib-hls":"^5.15.0",viewerjs:"^1.10.5","xe-utils":"^3.5.4"},d={name:e,version:"3.1.51-beta.16",private:!0,main:"index.ts",peerDependencies:n,dependencies:a};export{d as default,a as dependencies,s as main,e as name,n as peerDependencies,i as version};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cnhis-design-vue",
3
- "version": "3.1.51-beta.14",
3
+ "version": "3.1.51-beta.16",
4
4
  "license": "ISC",
5
5
  "module": "./es/components/index.js",
6
6
  "main": "./es/components/index.js",