12 lines
18 KiB
JavaScript
12 lines
18 KiB
JavaScript
|
|
import{aS as fe,a3 as he,U as c,b0 as pe,b2 as D,a$ as j,ac as _,a4 as ge,N as me,O as ve,Q as ye,R as ke,bX as be,a as q,c as y,w as Ce,o as Te,a1 as Se,a5 as we,H as ze,bu as xe}from"./index-3a2b6cd5.js";import{Q as Pe}from"./QBtnDropdown-f0b2b9e5.js";import{Q as qe}from"./QTooltip-5ceb1b84.js";import{a as Q,Q as Le}from"./QItemSection-843d83e6.js";import{u as Oe,a as $e,b as Be}from"./use-fullscreen-273d7265.js";function M(t,e){if(e&&t===e)return null;const o=t.nodeName.toLowerCase();if(["div","li","ul","ol","blockquote"].includes(o)===!0)return t;const r=window.getComputedStyle?window.getComputedStyle(t):t.currentStyle,l=r.display;return l==="block"||l==="table"?t:M(t.parentNode)}function E(t,e,o){return!t||t===document.body?!1:o===!0&&t===e||(e===document?document.body:e).contains(t.parentNode)}function K(t,e,o){if(o||(o=document.createRange(),o.selectNode(t),o.setStart(t,0)),e.count===0)o.setEnd(t,e.count);else if(e.count>0)if(t.nodeType===Node.TEXT_NODE)t.textContent.length<e.count?e.count-=t.textContent.length:(o.setEnd(t,e.count),e.count=0);else for(let r=0;e.count!==0&&r<t.childNodes.length;r++)o=K(t.childNodes[r],e,o);return o}const Ne=/^https?:\/\//;class Ee{constructor(e,o){this.el=e,this.eVm=o,this._range=null}get selection(){if(this.el){const e=document.getSelection();if(E(e.anchorNode,this.el,!0)&&E(e.focusNode,this.el,!0))return e}return null}get hasSelection(){return this.selection!==null?this.selection.toString().length>0:!1}get range(){const e=this.selection;return e!==null&&e.rangeCount?e.getRangeAt(0):this._range}get parent(){const e=this.range;if(e!==null){const o=e.startContainer;return o.nodeType===document.ELEMENT_NODE?o:o.parentNode}return null}get blockParent(){const e=this.parent;return e!==null?M(e,this.el):null}save(e=this.range){e!==null&&(this._range=e)}restore(e=this._range){const o=document.createRange(),r=document.getSelection();e!==null?(o.setStart(e.startContainer,e.startOffset),o.setEnd(e.endContainer,e.endOffset),r.removeAllRanges(),r.addRange(o)):(r.selectAllChildren(this.el),r.collapseToEnd())}savePosition(){let e=-1,o;const r=document.getSelection(),l=this.el.parentNode;if(r.focusNode&&E(r.focusNode,l))for(o=r.focusNode,e=r.focusOffset;o&&o!==l;)o!==this.el&&o.previousSibling?(o=o.previousSibling,e+=o.textContent.length):o=o.parentNode;this.savedPos=e}restorePosition(e=0){if(this.savedPos>0&&this.savedPos<e){const o=window.getSelection(),r=K(this.el,{count:this.savedPos});r&&(r.collapse(!1),o.removeAllRanges(),o.addRange(r))}}hasParent(e,o){const r=o?this.parent:this.blockParent;return r!==null?r.nodeName.toLowerCase()===e.toLowerCase():!1}hasParents(e,o,r=this.parent){return r===null?!1:e.includes(r.nodeName.toLowerCase())===!0?!0:o===!0?this.hasParents(e,o,r.parentNode):!1}is(e,o){if(this.selection===null)return!1;switch(e){case"formatBlock":return o==="DIV"&&this.parent===this.el||this.hasParent(o,o==="PRE");case"link":return this.hasParent("A",!0);case"fontSize":return document.queryCommandValue(e)===o;case"fontName":const r=document.queryCommandValue(e);return r===`"${o}"`||r===o;case"fullscreen":return this.eVm.inFullscreen.value;case"viewsource":return this.eVm.isViewingSource.value;case void 0:return!1;default:const l=document.queryCommandState(e);return o!==void 0?l===o:l}}getParentAttribute(e){return this.parent!==null?this.parent.getAttribute(e):null}can(e){if(e==="outdent")return this.hasParents(["blockquote","li"],!0);if(e==="indent")return this.hasParents(["li"],!0);if(e==="link")return this.selection!==null||this.is("link")}apply(e,o,r=fe){if(e==="formatBlock")["BLOCKQUOTE","H1","H2","H3","H4","H5","H6"].includes(o)&&this.is(e,o)&&(e="outdent",o=null),o==="PRE"&&this.is(e,"PRE")&&(o="P");else if(e==="print"){r();const l=window.open();l.document.write(`
|
||
|
|
<!doctype html>
|
||
|
|
<html>
|
||
|
|
<head>
|
||
|
|
<title>Print - ${document.title}</title>
|
||
|
|
</head>
|
||
|
|
<body>
|
||
|
|
<div>${this.el.innerHTML}</div>
|
||
|
|
</body>
|
||
|
|
</html>
|
||
|
|
`),l.print(),l.close();return}else if(e==="link"){const l=this.getParentAttribute("href");if(l===null){const u=this.selectWord(this.selection),a=u?u.toString():"";if(!a.length&&(!this.range||!this.range.cloneContents().querySelector("img")))return;this.eVm.editLinkUrl.value=Ne.test(a)?a:"https://",document.execCommand("createLink",!1,this.eVm.editLinkUrl.value),this.save(u.getRangeAt(0))}else this.eVm.editLinkUrl.value=l,this.range.selectNodeContents(this.parent),this.save();return}else if(e==="fullscreen"){this.eVm.toggleFullscreen(),r();return}else if(e==="viewsource"){this.eVm.isViewingSource.value=this.eVm.isViewingSource.value===!1,this.eVm.setContent(this.eVm.props.modelValue),r();return}document.execCommand(e,!1,o),r()}selectWord(e){if(e===null||e.isCollapsed!==!0||e.modify===void 0)return e;const o=document.createRange();o.setStart(e.anchorNode,e.anchorOffset),o.setEnd(e.focusNode,e.focusOffset);const r=o.collapsed?["backward","forward"]:["forward","backward"];o.detach();const l=e.focusNode,u=e.focusOffset;return e.collapse(e.anchorNode,e.anchorOffset),e.modify("move",r[0],"character"),e.modify("move",r[1],"word"),e.extend(l,u),e.modify("extend",r[1],"character"),e.modify("extend",r[0],"word"),e}}function W(t,e,o){e.handler?e.handler(t,o,o.caret):o.runCmd(e.cmd,e.param)}function R(t){return c("div",{class:"q-editor__toolbar-group"},t)}function X(t,e,o,r=!1){const l=r||(e.type==="toggle"?e.toggled?e.toggled(t):e.cmd&&t.caret.is(e.cmd,e.param):!1),u=[];if(e.tip&&t.$q.platform.is.desktop){const a=e.key?c("div",[c("small",`(CTRL + ${String.fromCharCode(e.key)})`)]):null;u.push(c(qe,{delay:1e3},()=>[c("div",{innerHTML:e.tip}),a]))}return c(_,{...t.buttonProps.value,icon:e.icon!==null?e.icon:void 0,color:l?e.toggleColor||t.props.toolbarToggleColor:e.color||t.props.toolbarColor,textColor:l&&!t.props.toolbarPush?null:e.textColor||t.props.toolbarTextColor,label:e.label,disable:e.disable?typeof e.disable=="function"?e.disable(t):!0:!1,size:"sm",onClick(a){o&&o(),W(a,e,t)}},()=>u)}function He(t,e){const o=e.list==="only-icons";let r=e.label,l=e.icon!==null?e.icon:void 0,u,a;function p(){T.component.proxy.hide()}if(o)a=e.options.map(v=>{const k=v.type===void 0?t.caret.is(v.cmd,v.param):!1;return k&&(r=v.tip,l=v.icon!==null?v.icon:void 0),X(t,v,p,k)}),u=t.toolbarBackgroundClass.value,a=[R(a)];else{const v=t.props.toolbarToggleColor!==void 0?`text-${t.props.toolbarToggleColor}`:null,k=t.props.toolbarTextColor!==void 0?`text-${t.props.toolbarTextColor}`:null,d=e.list==="no-icons";a=e.options.map(f=>{const S=f.disable?f.disable(t):!1,w=f.type===void 0?t.caret.is(f.cmd,f.param):!1;w&&(r=f.tip,l=f.icon!==null?f.icon:void 0);const x=f.htmlTip;return c(Le,{active:w,activeClass:v,clickable:!0,disable:S,dense:!0,onClick(z){p(),t.contentRef.value!==null&&t.contentRef.value.focus(),t.caret.restore(),W(z,f,t)}},()=>[d===!0?null:c(Q,{class:w?v:k,side:!0},()=>c(ge,{name:f.icon!==null?f.icon:void 0})),c(Q,x?()=>c("div",{class:"text-no-wrap",innerHTML:f.htmlTip}):f.tip?()=>c("div",{class:"text-no-wrap"},f.tip):void 0)])}),u=[t.toolbarBackgroundClass.value,k]}const g=e.highlight&&r!==e.label,T=c(Pe,{...t.buttonProps.value,noCaps:!0,noWrap:!0,color:g?t.props.toolbarToggleColor:t.props.toolbarColor,textColor:g&&!t.props.toolbarPush?null:t.props.toolbarTextColor,label:e.fixedLabel?e.label:r,icon:e.fixedIcon?e.icon!==null?e.icon:void 0:l,contentClass:u},()=>a);return T}function _e(t){if(t.caret)return t.buttons.value.filter(e=>!t.isViewingSource.value||e.find(o=>o.cmd==="viewsource")).map(e=>R(e.map(o=>t.isViewingSource.value&&o.cmd!=="viewsource"?!1:o.type==="slot"?he(t.slots[o.slot]):o.type==="dropdown"?He(t,o):X(t,o))))}function Re(t,e,o,r={}){const l=Object.keys(r);if(l.length===0)return{};const u={default_font:{cmd:"fontName",param:t,icon:o,tip:e}};return l.forEach(a=>{const p=r[a];u[a]={cmd:"fontName",param:p,icon:o,tip:p,htmlTip:`<font face="${p}">${p}</font>`}}),u}function Fe(t){if(t.caret){const e=t.props.toolbarColor||t.props.toolbarTextColor;let o=t.editLinkUrl.value;const r=()=>{t.caret.restore(),o!==t.editLinkUrl.value&&docume
|