├── .gitattributes ├── images ├── tex_logo.png └── screenshot.jpg ├── LICENSE ├── src ├── tex.min.css ├── tex.css ├── tex.min.js └── tex.js ├── examples ├── plugin.html └── index.html └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /images/tex_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcellov7/tex/HEAD/images/tex_logo.png -------------------------------------------------------------------------------- /images/screenshot.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcellov7/tex/HEAD/images/screenshot.jpg -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2024 Marcello Violini (marcellov7) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /src/tex.min.css: -------------------------------------------------------------------------------- 1 | .tex-container{border:1px solid #efefef;box-sizing:border-box;border-radius:4px;overflow:hidden}.tex-container.theme-dark{border-color:#383838}.htmlContent,.tex-content{box-sizing:border-box;background-color:#fff;height:300px;width:100%;outline:0;overflow-y:auto;padding:10px}.theme-dark .htmlContent,.theme-dark .tex-content{background-color:#10131a;color:#fff}.tex-actionbar{background-color:#fff;border-bottom:1px solid #efefef;padding:5px}.theme-dark .tex-actionbar{background-color:#10131a;border-color:#383838}.tex-button{position:relative;background-color:#f7f7f7;border:none;cursor:pointer;height:30px;outline:0;min-width:30px;vertical-align:bottom;color:#000;margin-right:3px;border-radius:4px;border-bottom:1px solid #d3d3d3}.theme-dark .tex-button{background-color:#181d27;color:#fff;border-bottom:1px solid #383838}.tex-button:hover{background-color:#f2f2f2}.theme-dark .tex-button:hover{background-color:#353434}.tex-button-selected{background-color:#f0f0f0}.tex-modal{position:absolute;background-color:#fff;border:1px solid #ccc;padding:5px}.tex-button>:nth-child(2){position:absolute;top:0;left:0;opacity:0;height:30px;width:30px;-webkit-appearance:none;-moz-appearance:none;appearance:none;background:0 0;cursor:pointer;border:0;padding:0} -------------------------------------------------------------------------------- /examples/plugin.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 |")},quote:{icon:"“ ”",title:"Quote",result:()=>s(r,"
")},olist:{icon:"#",title:"Ordered List",result:()=>s("insertOrderedList")},ulist:{icon:"•",title:"Unordered List",result:()=>s("insertUnorderedList")},code:{icon:"</>",title:"Code",result:()=>s(r,"")},line:{icon:"―",title:"Horizontal Line",result:()=>s("insertHorizontalRule")},link:{icon:"🔗",title:"Link",result(){let e=window.prompt("Enter the link URL");e&&s("createLink",e)}},image:{icon:"Img",title:"Image",result(){let e=window.prompt("Enter the image URL");e&&s("insertImage",e)}},html:{icon:"HTML",title:"Html",result({content:e}){let t=e.parentNode,n=t.querySelector(".htmlContent"),i=t.querySelector(".tex-content");n&&("none"===n.style.display?(n.style.display="block",i.style.display="none"):(n.style.display="none",i.style.display="block"))}},textColor:{icon:"A",title:"Text Color",result(){}},textBackColor:{icon:'A',title:"Text Color",result(){}},indent:{icon:"›",title:"Indent",result:()=>s("indent")},outdent:{icon:"‹",title:"Outdent",result:()=>s("outdent")},undo:{icon:"↶",title:"Undo",result:()=>s("undo")},redo:{icon:"↷",title:"Redo",result:()=>s("redo")},justifyCenter:{icon:"⇥⇤",title:"Justify Center",result:()=>s("justifyCenter")},justifyFull:{icon:"⇤⇥",title:"Justify Full",result:()=>s("justifyFull")},justifyLeft:{icon:"⇤",title:"Justify Left",result:()=>s("justifyLeft")},justifyRight:{icon:"⇥",title:"Justify Right",result:()=>s("justifyRight")}},d=e=>{var t=document.querySelector(`[tex-id="${e.id}"]`),n=document.getElementById(e.id),i=t.querySelector(".tex-content"),r=t.querySelector(".tex-actionbar");if(t){var l=i.cloneNode(!0);i.parentNode.replaceChild(l,i);var o=r.cloneNode(!0);r.parentNode.replaceChild(o,r),o.remove(),"textarea"===n.tagName.toLowerCase()?(n.style.display="block",t.remove()):(t.innerHTML=l.innerHTML,t.removeAttribute("tex-id"),t.classList.remove("theme-light","theme-dark","tex-container"))}},m=e=>{let t=document.querySelector(`[tex-id="${e.id}"]`),n=t.querySelector(".tex-content");return n.innerHTML},y=e=>{var u=e.theme||"light",d=e[i]||"div",m=a("div");m.className="tex-container",m.classList.add(`theme-${u}`),m.setAttribute("tex-id",e.element.id);var y=a("div");y.className="tex-actionbar",o(m,y);var p=e.element.content=a("div");p.contentEditable=!0,p.className="tex-content tex-editor","textarea"===e.element.tagName.toLowerCase()?p.innerHTML=e.element.value:p.innerHTML=e.element.innerHTML,p.onkeydown=e=>{var t;"Enter"===e.key&&"blockquote"===(t=r,document.queryCommandValue(t))&&setTimeout(()=>s(r,`<${d}>`),0)},o(m,p),e.element.parentNode.insertBefore(m,e.element.nextSibling);let f=[];e.buttons?(e.plugins&&(console.log(e.plugins),e.plugins.forEach(function(e){c[e.name]=e})),f=e.buttons.map(e=>{var t=c[e];if(t)return{icon:t.icon,title:t.title,key:e,result:t.result}}).filter(e=>void 0!==e)):e.actions&&(f=e.actions.map(e=>"string"==typeof e?c[e]:"custom"===e.name?{icon:e.icon,title:e.title,result:e.result}:c[e.name]?{...c[e.name],...e}:e)),f.forEach(e=>{var i=a("button");if(i.className="tex-button",i.innerHTML=""+e.icon+"",i.title=e.title,i.setAttribute("type","button"),i.onclick=()=>e.result({action:e,content:p,button:i})&&p.focus(),e.state){var r=()=>i.classList[e.state()?"add":"remove"]("tex-button-selected");l(p,"keyup",r),l(p,"mouseup",r),l(i,"click",r)}o(y,i),"fontSize"==e.key&&n(i),"textColor"==e.key&&t(i,"textColor"),"textBackColor"==e.key&&t(i,"textBackColor")}),e.cssStyle&&s("styleWithCSS"),s(i,d),"textarea"===e.element.tagName.toLowerCase()?e.element.style.display="none":(document.getElementById(e.element.id).remove(),m.id=e.element.id);var g=a("textarea");return g.setAttribute("class","htmlContent"),o(m,g),g.value=p.innerHTML,g.style.display="none",p.oninput=({target:{firstChild:t}})=>{t&&3===t.nodeType?s(r,`<${d}>`):"
"===p.innerHTML&&(p.innerHTML=""),e.onChange(p.innerHTML),"textarea"===e.element.tagName.toLowerCase()&&(e.element.value=p.innerHTML),g.value=p.innerHTML},g.oninput=({target:{firstChild:t}})=>{p.innerHTML=g.value,e.element.value=p.innerHTML,e.onChange(p.innerHTML)},e.element};e.exec=s,e.init=y,e.destroy=d,e.getContent=m,e.default={exec:s,init:y,destroy:d,getContent:m},Object.defineProperty(e,"__esModule",{value:!0})});
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | TEX is a ultra-lightweight and straightforward JavaScript library for creating rich text editors (WYSIWYG) directly in the browser. It is designed to work with both `