jodit-pro
Version:
PRO Version of Jodit Editor
2 lines (1 loc) • 4.6 kB
JavaScript
var g=Object.defineProperty;var L=(c,e)=>g(c,"name",{value:e,configurable:!0});var i=function(c,e,t,s){var l=arguments.length,r=l<3?e:s===null?s=Object.getOwnPropertyDescriptor(e,t):s,p;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(c,e,t,s);else for(var _=c.length-1;_>=0;_--)(p=c[_])&&(r=(l<3?p(r):l>3?p(e,t,r):p(e,t))||r);return l>3&&r&&Object.defineProperty(e,t,r),r};import"./config.js";import{NO_EMPTY_TAGS as y}from"jodit/esm/core/constants.js";import{autobind as f,watch as a}from"jodit/esm/core/decorators/index.js";import{Dom as n}from"jodit/esm/core/dom/dom.js";import{$$ as u,attr as C}from"jodit/esm/core/helpers/utils/index.js";import{Plugin as j}from"jodit/esm/core/plugin/index.js";import{CHANGE as b,REPLACE as m,UNWRAP as E,WRAP as I}from"jodit/esm/core/selection/index.js";import{JoditPro as T}from"../../jodit-pro.js";const d=!0,h=class h extends j{constructor(){super(...arguments),this.buttons=[{name:"todoList",group:"list"}],this.__isOwnCommand=!1}afterInit(e){e.registerCommand("todoList",this.onCommand)}onCommand(){try{this.__isOwnCommand=!0,this.jodit.s.commitStyle({element:"ul",attributes:{class:this.j.o.todoList.className},hooks:d?{afterWrapList:this.__afterWrapList,afterToggleAttribute:this.__afterWrapList}:{}})}finally{this.__isOwnCommand=!1}return!1}__prependInputLabel(e){const{jodit:t}=this,{labelClassName:s,inputFactory:l}=this.j.o.todoList;if(e.querySelector("label."+s))return;const r=t.createInside.element("label",{contenteditable:"false",class:s}),p=l(t);r.appendChild(p),n.prepend(e,r)}__afterToggleList(e,t){if(d){if((e===b||e===m)&&this.__isOwnCommand)return this.__appendInputs(t);if(e===E||e===m||e===b)return this.__removeInputs(t)}}__appendInputs(e){e.querySelectorAll("li").forEach(this.__prependInputLabel)}__removeInputs(e){const{labelClassName:t}=this.j.o.todoList;e.querySelectorAll("label."+t).forEach(n.safeRemove)}__beforeToggleOrderedList(e,t,s){var l;if(!d)return;const r="__beforeToggleOrderedList";if(e!==m&&(t.classList.contains(this.j.o.todoList.className)||s.isApplied(t,r))&&(s.element==="ul"||s.element==="ol")&&((l=s.options.attributes)===null||l===void 0?void 0:l.class)!==this.j.o.todoList.className){const p=n.replace(t,s.element,this.jodit.createInside);return s.setApplied(p,r),this.__removeInputs(p),p}}__afterEnter(){u("ul."+this.j.o.todoList.className+" li",this.jodit.editor).forEach(this.__prependInputLabel)}__afterTab(){u("ul:not(."+this.j.o.todoList.className+") > li > label",this.jodit.editor).filter(this.isTodoLeafLabel).forEach(n.safeRemove)}__changeSelection(e){const t=this.j.s.current();this.isTodoLeafLabel(t)&&(e.preventDefault(),e.stopPropagation(),this.j.s.setCursorAfter(t))}__isEmptyListLeaf(e){return n.isEmpty(e,t=>t.nodeName.toLowerCase()==="input"&&this.isTodoLeafLabel(t.parentElement)?!1:y.has(t.tagName.toLowerCase()))}__backSpaceBeforeCases(e,t){if(e){const s=n.findNotEmptySibling(t,!0);this.isTodoLeafLabel(s)&&n.safeRemove(s)}}__isInvisibleForCursor(e){if(this.isTodoLeafLabel(e))return!0}__backSpaceAfterDelete(){const{labelClassName:e}=this.j.o.todoList;u("label."+e,this.jodit.editor).forEach(t=>{t.closest("ul."+this.j.o.todoList.className)?t.previousSibling&&t.parentElement&&n.prepend(t.parentElement,t):n.safeRemove(t)})}__afterWrapList(e,t){e===I&&this.__appendInputs(t)}__onClickInput(e){const t=e.target;t&&n.isTag(t,"input")&&t.type==="checkbox"&&this.isTodoLeafLabel(t.parentElement)&&C(t,"checked",t.checked?"checked":null)}isTodoLeafLabel(e){const{labelClassName:t}=this.j.o.todoList;return n.isHTMLElement(e)&&e.classList.contains(t)}beforeDestruct(e){}};L(h,"TodoList");let o=h;o.requires=["license"],i([f],o.prototype,"onCommand",null),i([f],o.prototype,"__prependInputLabel",null),i([a(":commitStyleAfterToggleList")],o.prototype,"__afterToggleList",null),i([a(":commitStyleBeforeUnwrapList")],o.prototype,"__beforeToggleOrderedList",null),i([a(":afterEnter")],o.prototype,"__afterEnter",null),i([a(":afterTab")],o.prototype,"__afterTab",null),i([a("j.ed:selectionchange"),a(":afterEnter")],o.prototype,"__changeSelection",null),i([a(":enterIsEmptyListLeaf")],o.prototype,"__isEmptyListLeaf",null),i([a(":backSpaceBeforeCases")],o.prototype,"__backSpaceBeforeCases",null),i([a(":backSpaceIsMovedIgnore"),a(":isInvisibleForCursor")],o.prototype,"__isInvisibleForCursor",null),i([a(":backSpaceAfterDelete")],o.prototype,"__backSpaceAfterDelete",null),i([f],o.prototype,"__afterWrapList",null),i([a(":click")],o.prototype,"__onClickInput",null),i([f],o.prototype,"isTodoLeafLabel",null),T.plugins.add("todo-list",o);export{o as TodoList};