UNPKG

on-codemerge

Version:

A WYSIWYG editor for on-codemerge is a user-friendly interface that allows users to edit and view their code in real time, exactly as it will appear in the final product

3 lines (2 loc) 1.71 kB
/*! on-codemerge v1.3.1 @author Pavel Kuzmin @license MIT @homepage https://s00d.github.io/on-codemerge/ @repository git+https://github.com/s00d/on-codemerge.git Copyright (c) 2026 Pavel Kuzmin - Built on 2026-07-02T13:39:17.947Z */ "use strict";var c=Object.defineProperty;var i=(l,e,t)=>e in l?c(l,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):l[e]=t;var n=(l,e,t)=>i(l,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class o{constructor(e){n(this,"container");n(this,"lastSelection",null);n(this,"lastTable",null);n(this,"selectedCells",[]);this.container=e}saveSelection(){const e=window.getSelection();if(e&&e.rangeCount>0)this.lastSelection=e.getRangeAt(0).cloneRange();else{const t=document.createRange(),s=this.container;s&&s.childNodes.length>0?(t.selectNodeContents(s),t.collapse(!1)):(t.setStart(s,0),t.collapse(!0)),e==null||e.removeAllRanges(),e==null||e.addRange(t),this.lastSelection=t.cloneRange()}}saveTable(e){this.lastTable=e}selectCell(e){this.selectedCells.push(e),e.classList.add("selected")}clearSelectedCells(){this.selectedCells.forEach(e=>e.classList.remove("selected")),this.selectedCells=[]}getSelectedCells(){return this.selectedCells}getSelection(){return this.lastSelection}restoreSelection(e){if(!this.lastSelection)return null;const t=this.lastSelection.startContainer,s=this.lastSelection.endContainer;if(!e.contains(t)||!e.contains(s))return this.clearSelection(),null;const a=window.getSelection();return a&&(a.removeAllRanges(),a.addRange(this.lastSelection)),this.lastSelection}restoreTable(){return this.lastTable}clearSelection(){this.lastSelection=null}clearTable(){this.lastTable=null}}exports.Selector=o;