@revolist/revogrid
Version:
Virtual reactive data grid spreadsheet component - RevoGrid.
4 lines • 2.59 kB
JavaScript
/*!
* Built by Revolist OU ❤️
*/
import{proxyCustomElement as t,HTMLElement as e,createEvent as s,transformTag as i}from"@stencil/core/internal/client";const r=t(class extends e{constructor(t){super(),!1!==t&&this.__registerHost(),this.beforePaste=s(this,"beforepaste",7),this.beforePasteApply=s(this,"beforepasteapply",7),this.pasteRegion=s(this,"pasteregion",7),this.afterPasteApply=s(this,"afterpasteapply",7),this.beforeCut=s(this,"beforecut",7),this.clearRegion=s(this,"clearregion",7),this.beforeCopy=s(this,"beforecopy",7),this.beforeCopyApply=s(this,"beforecopyapply",7),this.copyRegion=s(this,"copyregion",7)}onPaste(t){if(this.readonly)return;const e=this.getData(t),s=((null==e?void 0:e.types.indexOf("text/html"))||-1)>-1,i=(s?null==e?void 0:e.getData("text/html"):null==e?void 0:e.getData("text"))||"",r=(null==e?void 0:e.getData("text"))||"",o=this.beforePaste.emit({raw:i,dataText:r,isHTML:s,event:t});if(o.defaultPrevented)return;let n;n=o.detail.isHTML?this.htmlParse(o.detail.raw)||this.textParse(r||""):this.textParse(o.detail.raw);const a=this.beforePasteApply.emit({raw:i,parsed:n,dataText:r,event:t});a.defaultPrevented||(this.pasteRegion.emit(a.detail.parsed),this.afterPasteApply.emit({raw:i,parsed:n,dataText:r,event:t}).defaultPrevented||t.preventDefault())}copyStarted(t){const e=this.beforeCopy.emit({event:t});if(e.defaultPrevented)return;const s=this.getData(e.detail.event);this.copyRegion.emit(s||void 0),t.preventDefault()}cutStarted(t){const e=this.beforeCut.emit({event:t});if(e.defaultPrevented)return;const s=this.getData(e.detail.event);this.copyStarted(t),this.readonly||(this.clearRegion.emit(s||void 0),t.preventDefault())}async doCopy(t,e){if(this.beforeCopyApply.emit({event:t,data:e}).defaultPrevented)return;const s=e?this.parserCopy(e):"";t.setData("text/plain",s)}parserCopy(t){return t.map((t=>t.join("\t"))).join("\n")}textParse(t){const e=[],s=t.split(/\r\n|\n|\r/);for(let t in s)e.push(s[t].split("\t"));return e}htmlParse(t){const e=[],s=document.createRange().createContextualFragment(t).querySelector("table");if(!s)return null;for(const t of Array.from(s.rows))e.push(Array.from(t.cells).map((t=>t.innerText)));return e}getData(t){return t.clipboardData||(null===window||void 0===window?void 0:window.clipboardData)}},[0,"revogr-clipboard",{readonly:[4],doCopy:[64]},[[4,"paste","onPaste"],[4,"copy","copyStarted"],[4,"cut","cutStarted"]]]);function o(){"undefined"!=typeof customElements&&["revogr-clipboard"].forEach((t=>{"revogr-clipboard"===t&&(customElements.get(i(t))||customElements.define(i(t),r))}))}export{r as C,o as d}