import{registerTemplate as e,freezeTemplate as t,registerDecorators as s,registerComponent as n}from"@kdcloudjs/kwc";import o from"./kd/shadowBaseClassPrivate.js";import{c as a,u as i}from"./utilsPrivate-CI3EeA5x.js";const l=[];function c(e,t,s,n){return l}var r=e(c);c.stylesheets=[],c.stylesheetToken="kwc-13sb42r0vso",c.legacyStylesheetToken="D:\\new_workspace\\workspace\\kingdee-base-components\\src\\modules\\kd\\primitiveDatatableCell-undefined_primitiveDatatableCell",t(c);const d="kdds-has-focus",h="EXPAND_HEADER_TYPE",u={top:"kdds-datatable-cell-range-top",bottom:"kdds-datatable-cell-range-bottom",left:"kdds-datatable-cell-range-left",right:"kdds-datatable-cell-range-right",selected:"kdds-datatable-cell-range-selected"};class m extends o{constructor(...e){super(...e),this.rowKeyValue=void 0,this.colKeyValue=void 0,this._hasFocus=0,this._mode="NAVIGATION",this._currentInputIndex=0,this._internalTabIndex=-1,this._actionableElementsCount=void 0}get hasFocus(){return this._hasFocus}get keyboardMode(){return this._mode}set hasFocus(e){this._hasFocus=e,e?this.classList.add(d):this.classList.remove(d)}setMode(e,t){const s=t||{action:"none"};if(this._mode=e,"ACTION"===e){this._internalTabIndex=0,setTimeout(()=>{this.setFocusToActionableElement(this._currentInputIndex)},0);const e=this.getActionableElements();if("tab"===s.action){let t=!1;e.some(e=>!!e.getAttribute("data-action-edit")&&(t=e,!0)),t&&t.click()}else if(1===e.length){let t=e[0].getAttribute("data-action-triggers");t=t||"",-1!==t.indexOf(s.action)&&e[this._currentInputIndex].click()}}else this._internalTabIndex=-1}addFocusStyles(){this.classList.add(d)}removeFocusStyles(e){this.classList.remove(d),e&&(this._internalTabIndex=-1)}resetCurrentInputIndex(e,t){switch(e){case-1:{const e=this.getActionableElements();this._currentInputIndex="NAVIGATION"===t?0:e.length?e.length-1:0;break}case 1:case 2:this._currentInputIndex=0}"ACTION"===this._mode&&"ACTION"===t&&this.setFocusToActionableElement(this._currentInputIndex)}connectedCallback(){super.connectedCallback(),this.addEventListener("focus",this.handleFocus.bind(this)),this.addEventListener("click",this.handleClick.bind(this)),this.addEventListener("keydown",this.handleKeydown.bind(this))}get internalTabIndex(){return this._internalTabIndex}get canMoveBackward(){return this._currentInputIndex>0}get canMoveForward(){return this._actionableElementsCount>1&&this._currentInputIndex<this._actionableElementsCount-1}get canMoveLeft(){return a()?this.canMoveForward:this.canMoveBackward}get canMoveRight(){return a()?this.canMoveBackward:this.canMoveForward}moveToNextActionableElement(){this.setFocusToActionableElement(this._currentInputIndex+1)}moveToPrevActionableElement(){this.setFocusToActionableElement(this._currentInputIndex-1)}handleClick(e){this.addFocusStyles(),this.fireCellFocusByClickEvent()}handleKeydown(e){const{keyCode:t,shiftKey:s}=e;let n=t!==i.shift;if("ACTION"===this._mode)switch(t){case i.left:this.canMoveLeft&&(e.preventDefault(),a()?this.moveToNextActionableElement():this.moveToPrevActionableElement(),n=!1);break;case i.right:this.canMoveRight&&(e.preventDefault(),a()?this.moveToPrevActionableElement():this.moveToNextActionableElement(),n=!1);break;case i.tab:s?this.canMoveBackward&&(e.preventDefault(),this.moveToPrevActionableElement(),n=!1):this.canMoveForward&&(e.preventDefault(),this.moveToNextActionableElement(),n=!1)}else"NAVIGATION"===this._mode&&(t!==i.left&&t!==i.right&&t!==i.up&&t!==i.down&&t!==i.enter||this.fireCellKeydown(e));n&&"ACTION"===this._mode&&this.fireCellKeydown(e)}getActionableElements(){return Array.prototype.slice.call(this.template.querySelectorAll('[data-navigation="enable"]'))}get resizeElement(){return this.template.querySelector(".kdds-resizable")}setFocusToActionableElement(e){const t=this.getActionableElements();this._actionableElementsCount=t.length,t.length>0&&(e>0&&e<t.length?(t[e].focus(),this._currentInputIndex=e):(t[0].focus(),this._currentInputIndex=0))}handleFocus(){"ACTION"===this._mode&&this.setFocusToActionableElement(this._currentInputIndex)}fireCellKeydown(e){const{rowKeyValue:t,colKeyValue:s}=this,{keyCode:n,shiftKey:o}=e,a=new CustomEvent("privatecellkeydown",{bubbles:!0,composed:!0,cancelable:!0,detail:{rowKeyValue:t,colKeyValue:s,keyCode:n,shiftKey:o,keyEvent:e}});this.dispatchEvent(a)}fireCellFocusByClickEvent(){const{rowKeyValue:e,colKeyValue:t}=this,s=new CustomEvent("privatecellfocusedbyclick",{bubbles:!0,composed:!0,detail:{rowKeyValue:e,colKeyValue:t}});this.dispatchEvent(s)}}s(m,{publicProps:{rowKeyValue:{config:0},colKeyValue:{config:0},hasFocus:{config:3}},publicMethods:["setMode","addFocusStyles","removeFocusStyles","resetCurrentInputIndex"],fields:["_hasFocus","_mode","_currentInputIndex","_internalTabIndex","_actionableElementsCount"]});const b=n(m,{tmpl:r,sel:"D:\\new_workspace\\workspace\\kingdee-base-components\\src\\modules\\kd\\primitiveDatatableCell-",apiVersion:63});export{h as D,d as F,b as _,u as a};
