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.57 kB
JavaScript
/*! 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 r=Object.defineProperty;var i=(s,t,e)=>t in s?r(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e;var n=(s,t,e)=>i(s,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class a{constructor(){n(this,"states",[{content:"",timestamp:0}]);n(this,"currentIndex",0);n(this,"maxStates",100);this.clear()}addState(t){var e;((e=this.getCurrentState())==null?void 0:e.content)!==t&&(this.currentIndex<this.states.length-1&&(this.states=this.states.slice(0,this.currentIndex+1)),this.states.push({content:t,timestamp:Date.now()}),this.currentIndex++,this.states.length>this.maxStates&&(this.states=this.states.slice(-this.maxStates),this.currentIndex=this.states.length-1))}undo(){if(this.currentIndex<=0)return null;this.currentIndex--;const t=this.getCurrentState();return t===null?null:t.content}redo(){if(this.currentIndex>=this.states.length-1)return null;this.currentIndex++;const t=this.getCurrentState();return t===null?null:t.content}getCurrentState(){return this.states[this.currentIndex]||null}getCurrentIndex(){return this.currentIndex}clear(){this.states=[{content:"",timestamp:Date.now()}],this.currentIndex=0}getStates(){return this.states}canUndo(){return this.currentIndex>0}canRedo(){return this.currentIndex<this.states.length-1}}exports.HistoryManager=a;