UNPKG

@revolist/revogrid

Version:

Virtual reactive data grid spreadsheet component - RevoGrid.

4 lines 4.72 kB
/*! * Built by Revolist OU ❤️ */ import{proxyCustomElement as t,HTMLElement as i,createEvent as s,h as n,Host as e,transformTag as o}from"@stencil/core/internal/client";import{E as r}from"./consts.js";import{K as h,O as l,c as a,k as u}from"./platform.js";import{t as c}from"./index2.js";function d(t){return-1!==[h.ARROW_DOWN,h.ARROW_UP,h.ARROW_LEFT,h.ARROW_RIGHT,h.HOME,h.END,h.DELETE,h.BACKSPACE,h.F1,h.F2,h.F3,h.F4,h.F5,h.F6,h.F7,h.F8,h.F9,h.F10,h.F11,h.F12,h.TAB,h.PAGE_DOWN,h.PAGE_UP,h.ENTER,h.ESCAPE,h.SHIFT,h.CAPS_LOCK,h.ALT].indexOf(t)}function v(t,i){return i.includes(l.mac)?[h.COMMAND_LEFT,h.COMMAND_RIGHT,h.COMMAND_FIREFOX].includes(t):t===h.CONTROL}function f(t){return[h.CONTROL,h.COMMAND_LEFT,h.COMMAND_RIGHT,h.COMMAND_FIREFOX].includes(t)}function p(t){return a.BACKSPACE===t||a.DELETE===t}function y(t){return a.TAB===t}function m(t){return u.TAB===t}function g(t){return u.ENTER===t}function b(t){return t.ctrlKey&&"KeyX"===t.code||t.metaKey&&"KeyX"===t.code}function K(t){return t.ctrlKey&&"KeyC"===t.code||t.metaKey&&"KeyC"===t.code}function w(t){return t.ctrlKey&&"KeyV"===t.code||t.metaKey&&"KeyV"===t.code}function C(t){return t.ctrlKey&&"KeyA"===t.code||t.metaKey&&"KeyA"===t.code}class D{constructor(t,i){this.data=t,this.saveCallback=i,this.editInput=null,this.element=null,this.editCell=void 0}async componentDidRender(){var t;this.editInput&&(await c(),null===(t=this.editInput)||void 0===t||t.focus())}onKeyDown(t){const i=g(t.key),s=y(t.key);(s||i)&&t.target&&this.saveCallback&&!t.isComposing&&(this.beforeDisconnect(),this.saveCallback(this.getValue(),s))}beforeDisconnect(){var t;null===(t=this.editInput)||void 0===t||t.blur()}getValue(){var t;return null===(t=this.editInput)||void 0===t?void 0:t.value}render(t,i){var s,n;return t("input",{type:"text",enterKeyHint:"enter",value:null!==(n=null===(s=this.editCell)||void 0===s?void 0:s.val)&&void 0!==n?n:"",ref:t=>{this.editInput=t},onKeyDown:t=>this.onKeyDown(t)})}}function k(t){return!!(null==t?void 0:t.closest(`.${r}`))}function x(t){return"function"==typeof t&&"object"==typeof t.prototype}const j=t(class extends i{constructor(t){super(),!1!==t&&this.__registerHost(),this.cellEdit=s(this,"celleditinit",7),this.closeEdit=s(this,"closeedit",7),this.saveOnClose=!1,this.currentEditor=null,this.preventSaveOnClose=!1}async cancelChanges(){this.preventSaveOnClose=!0}async beforeDisconnect(){var t,i;null===(i=null===(t=this.currentEditor)||void 0===t?void 0:t.beforeDisconnect)||void 0===i||i.call(t)}onAutoSave(){var t,i,s;this.preventSaveOnClose=!0;const n=null===(i=null===(t=this.currentEditor)||void 0===t?void 0:t.getValue)||void 0===i?void 0:i.call(t);(null===(s=this.currentEditor)||void 0===s?void 0:s.beforeAutoSave)&&!1===this.currentEditor.beforeAutoSave(n)||this.onSave(n,!0)}onSave(t,i){this.preventSaveOnClose=!0,this.editCell&&this.cellEdit.emit({rgCol:this.editCell.x,rgRow:this.editCell.y,type:this.editCell.type,prop:this.editCell.prop,val:t,preventFocus:i})}componentWillRender(){!this.currentEditor&&this.column&&(this.preventSaveOnClose=!1,this.currentEditor=this.editor?x(this.editor)?new this.editor(this.column,((t,i)=>{this.onSave(t,i)}),(t=>{this.preventSaveOnClose=!0,this.closeEdit.emit(t)})):this.editor(this.column,((t,i)=>{this.onSave(t,i)}),(t=>{this.preventSaveOnClose=!0,this.closeEdit.emit(t)})):new D(this.column,((t,i)=>this.onSave(t,i))))}componentDidRender(){var t,i;this.currentEditor&&(this.currentEditor.element=this.element.firstElementChild,null===(i=(t=this.currentEditor).componentDidRender)||void 0===i||i.call(t))}disconnectedCallback(){var t,i;this.saveOnClose&&(this.preventSaveOnClose||this.onAutoSave()),this.preventSaveOnClose=!1,this.currentEditor&&(null===(i=(t=this.currentEditor).disconnectedCallback)||void 0===i||i.call(t),this.currentEditor.element=null,this.currentEditor=null)}render(){return this.currentEditor?(this.currentEditor.editCell=this.editCell,n(e,{class:r},this.currentEditor.render(n,this.additionalData))):""}get element(){return this}static get style(){return"revogr-edit{display:block;position:absolute;background-color:#fff}revogr-edit input{height:100%;width:100%;box-sizing:border-box}revogr-edit revo-dropdown{height:100%}revogr-edit revo-dropdown.shrink fieldset legend>span{display:none}"}},[0,"revogr-edit",{editCell:[16],column:[16],editor:[16],saveOnClose:[4,"save-on-close"],additionalData:[8,"additional-data"],cancelChanges:[64],beforeDisconnect:[64]}]);function R(){"undefined"!=typeof customElements&&["revogr-edit"].forEach((t=>{"revogr-edit"===t&&(customElements.get(o(t))||customElements.define(o(t),j))}))}export{j as R,D as T,v as a,f as b,p as c,y as d,m as e,g as f,b as g,K as h,d as i,w as j,C as k,k as l,x as m,R as n}