@ones-editor/editor 1.0.2-beta.4 → 1.0.2-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js
CHANGED
|
@@ -680,7 +680,7 @@ ${s}
|
|
|
680
680
|
`}})}class Qj{constructor(t){g(this,"_grid",[]);g(this,"_needFixSpanData",!1);Array.from(t.rows).forEach((e,r)=>{Array.from(e.cells).forEach(i=>{this._addCell(r,i)})})}_addCell(t,e){const r=this._getNextColIndex(t),i=e.colSpan,o=e.rowSpan;for(let s=0;s<o;s++)for(let l=0;l<i;l++){const c=t+s,d=r+l;if(this._getCell({row:c,col:d})){this._needFixSpanData=!0,console.warn(`invalid table data, cell data already exists, ${c}, ${d}`);continue}this._setCell({row:c,col:d},{cell:e,virtual:!(l===0&&s===0)})}}_getNextColIndex(t){const e=this._grid[t];if(!e)return 0;let r=0;for(let i=0;i<e.length;i++)if(e[i])r+=1;else return r;return r}_setCell(t,e){if(!(e.cell.colSpan===0||e.cell.rowSpan===0)){for(;this._grid.length<=t.row;)this._grid.push([]);for(let r=0;r<this._grid.length;r++){const i=this._grid[r];for(;i.length<=t.col;)i.push(null)}this._grid[t.row][t.col]=e}}_getCell(t){var r;const e=this._grid[t.row];return e&&(r=e[t.col])!=null?r:null}get rowCount(){return this._grid.length}get colCount(){return this._grid[0].length}getCellData(t){const e=this._getCell(t);return e||null}getCellSpan(t){const e=this._getCell(t);if(!e)return{colSpan:1,rowSpan:1};if(e.virtual)return{colSpan:1,rowSpan:1};const r=()=>{let l=t.col+1;for(;;){const c=this._getCell({row:t.row,col:l});if(!c||c.cell!==e.cell)return l-t.col;l+=1}},i=()=>{let l=t.row+1;for(;;){const c=this._getCell({row:l,col:t.col});if(!c||c.cell!==e.cell)return l-t.row;l+=1}},o=r(),s=i();return o!==e.cell.colSpan&&console.warn(`invalid colSpan: ${o} -> ${e.cell.colSpan}`),s!==e.cell.rowSpan&&console.warn(`invalid rowSpan: ${s} -> ${e.cell.rowSpan}`),{colSpan:o,rowSpan:s}}getColumnWidth(t){const i=Array(this.rowCount).fill(0).map((s,l)=>{const c=this.getCellData({row:l,col:t});if(c&&!c.virtual){const d=c.cell.getAttribute("width")||c.cell.style.width;if(d){if(d.endsWith("%")){const C=d.substr(0,d.length-1),E=Number.parseInt(C,10);if(E>0&&E<=100)return Math.floor(720*E/100)}const h=Number.parseInt(d,10);if(h)return h}return c.cell.getBoundingClientRect().width}return 1e9}),o=Math.min(...i);return o===1e9||Number.isNaN(o)||o<30?0:o}}function Yj(n){return new Qj(n)}function AR(n,t){var c;const e=Yj(n),r=[],i={},o=e.rowCount,s=e.colCount,l=Array(s).fill(100);for(let d=0;d<o;d++)for(let h=0;h<s;h++){let C;const E=e.getCellData({row:d,col:h});if(E&&E.virtual)continue;E&&!E.virtual&&(C=t.htmlToBlocks(E.cell.innerHTML,t)),(!C||C.length===0)&&(C=[{id:tt(),type:"text",text:[]}]);const x=tt();r.push(x);const{colSpan:B,rowSpan:R}=e.getCellSpan({row:d,col:h});R>1&&(i[`${x}_rowSpan`]=R),B>1&&(i[`${x}_colSpan`]=B),t.doc.blocks[x]=C,E&&!E.virtual&&(l[h]=Math.max(l[h],gR((c=t.font)!=null?c:"",C)))}for(let d=0;d<e.colCount;d++)l[d]=e.getColumnWidth(d)||l[d];return r.length===0?[]:[{cols:e.colCount,rows:e.rowCount,id:tt(),type:"table",children:r,...i,colsWidth:l}]}function xR(n,t){var e;if(n.tagName==="TABLE"){const r={blocks:{root:[]},meta:{},comments:{}},i=AR(n,{doc:r,...t});if(i.length===0||((e=i[0].children)==null?void 0:e.length)===0)return;r.blocks.root=i;const o=JSON.stringify(r),s=No(o),l=document.createElement("div");l.classList.add("highlight-text-wizdoc");const c=document.createElement("pre");l.appendChild(c),c.innerText=s,n.insertAdjacentElement("beforebegin",l),n.remove();return}Array.from(n.children).forEach(r=>xR(r,t))}function bR(n){if(n instanceof HTMLStyleElement){n.remove();return}Array.from(n.children).forEach(bR)}function BR(n){if(n instanceof HTMLElement){if(n.style.display==="none"){n.remove();return}if(n.style.visibility==="hidden"){n.remove();return}}Array.from(n.children).forEach(BR)}function Zj(n,t){const e=kd(n);return e.querySelectorAll("td.js-line-number").forEach(i=>i.remove()),e.querySelectorAll("div.copy-button").forEach(i=>i.remove()),e.querySelectorAll("div.code-copy-button").forEach(i=>i.remove()),e.querySelectorAll("noscript").forEach(i=>i.remove()),Array.from(e.children).forEach(BR),Array.from(e.children).forEach(i=>xR(i,t)),Array.from(e.children).forEach(bR),ER(e),wb(e)}const Ti=new r6.default;Ti.use($j),Ti.use(Hj),Ti.use(jj),Ti.use(zj),Ti.use(Gj),Ti.use(Wj),Ti.use(qj),Ti.use(Xj),Ti.use(HL.gfm);function Jj(n,t){const e=vR(n,t);if(!e)return[];const{root:r,...i}=e.blocks;return t.doc.blocks={...t.doc.blocks,...i},r}function vR(n,t){const e=Ti.turndown(n);return CR(e,{htmlToDoc:r=>TR(r,t)})}function TR(n,t){const e=Zj(n,{font:t==null?void 0:t.font,htmlToBlocks:Jj});return vR(e)}function yR(n){return n.indexOf('xmlns:o="urn:schemas-microsoft-com:office:office"')!==-1}function dE(n){return["A","B","DEL","I","U","S","SPAN","SUB","SUP","FONT","BR"].indexOf(n.tagName)!==-1}function tz(n){return["P","H1","H2","H3","H4","H5","H6","H7","H8","LI"].indexOf(n.tagName)!==-1}function kR(n){return n.replace(/\r\n\s*/g,"").replace(/\n\s*/g,"").replace(/\r\s*/g,"")}function ez(n){if(!n.tagName)return!1;if(n.tagName.toLocaleLowerCase()==="img")return!0;const t=n.querySelectorAll("img");for(let e=0;e<t.length;e+=1){const r=t[e];if(!r.src||r.getAttribute("width")==="0"||r.getAttribute("height")==="0")return!1}return t.length}function nz(n){return(n.tagName.toLocaleLowerCase()==="img"?[n]:Array.from(n.querySelectorAll("img"))).map(i=>({id:tt(),type:"embed",embedType:"image",embedData:{src:i.src,width:i.width,height:i.height}}))}function RR(n){var e;return Array.from(((e=n.getAttribute("style"))!=null?e:"").split(" ")).findIndex(r=>r.startsWith("level"))!==-1}function rz(n){var e;const t=Array.from(((e=n.getAttribute("style"))!=null?e:"").split(" "));for(let r=0;r<t.length;r++){const i=t[r];if(i.startsWith("mso-list:"))return i}return""}function wR(n){var e,r;const t=Array.from(((e=n.getAttribute("style"))!=null?e:"").split(" "));for(let i=0;i<t.length;i++){const o=t[i];if(o.startsWith("level")){const s=(r=Number.parseInt(o.substring(5),10))!=null?r:void 0;if(s)return s}}return 1}function iz(n,t){n.setAttribute("data-group-id",t)}function oz(n){const t={},e=i=>{Array.from(Object.keys(t)).forEach(o=>{Number.parseInt(o,10)>i&&delete t[o]})};let r="";Array.from(n.children).forEach(i=>{if(RR(i)){const o=rz(i);r!==o&&(e(0),r=o);const s=wR(i);e(s);let l=t[`${s}`];l||(l=tt(),t[`${s}`]=l),iz(i,l)}})}function SR(n){const t=n.querySelector('[style="mso-list:Ignore"]');if(t){const e=t.innerText;return e&&e.trim()!=="-"}return!0}function sz(n){var r;if(!SR(n))return 1;const e=n.querySelector('[style^="mso-list:Ignore"]');if(e){const i=e.innerText;if(i)return(r=Number.parseInt(i,10))!=null?r:1}return 1}function LR(n){if(!RR(n))return{};const t=wR(n),e=n.getAttribute("data-group-id")||tt();return{start:sz(n),level:t,groupId:e,ordered:SR(n),type:"list"}}const lz=I("office-list");function IR(n){return n instanceof HTMLOListElement||n instanceof HTMLUListElement}function az(n,t){p(lz,IR(n),"not list group element");let e=!1,r=1;const i=tt();n instanceof HTMLOListElement&&(e=!0,r=n.start);const o=n,s=[];let l;return Array.from(o.children).forEach(c=>{if(c instanceof HTMLLIElement){const h=LR(c),C=t.textElementToBlocks(c,t);l||(l=h.level);const E=C[0];s.push({...E,type:"list",ordered:e,level:l,groupId:i,start:r}),r+=1,s.push(...C.slice(1));return}const d=t.blockElementToBlocks(c,t);s.push(...d)}),s}function DR(n,t){if(n.nodeName==="META")return[];if(n instanceof HTMLTableElement)return AR(n,t);if(IR(n))return[...az(n,t)];if(ez(n))return[...nz(n)];if(tz(n))return[...t.textElementToBlocks(n,t)];if(!n.children)return[];const e=[];return Array.from(n.children).forEach(r=>{const i=DR(r,t);e.push(...i)}),e}function _R(n,t){const e=[];return n.forEach(r=>{var i;if(r instanceof Element)if(dE(r)){const o=document.createElement("p");o.appendChild(r);const s=t.blockElementToBlocks(o,t);e.push(...s)}else{const o=t.blockElementToBlocks(r,t);e.push(...o)}else if(r instanceof Text){const o=hi(kR((i=r.textContent)!=null?i:""));e.push(o)}}),e}function MR(n){return n instanceof Element?dE(n):n.nodeType===Node.TEXT_NODE}function cz(n){var t;return n.nodeType===Node.TEXT_NODE&&((t=n.textContent)==null?void 0:t.trim())===""}function UR(n){const t=Array.from(n.childNodes);for(let e=0;e<t.length;e++){const r=t[e];if(!MR(r))continue;let i=e+1;for(;i<t.length&&MR(t[i]);)i+=1;if(cz(r)&&i===e+1)continue;const o=document.createElement("p");r instanceof Element?r.insertAdjacentElement("beforebegin",o):n.insertBefore(o,r);for(let s=e;s<i;s++)o.appendChild(t[s]);e=i-1}}function uz(n,t){const e=kd(n);return UR(e),_R(Array.from(e.childNodes),t)}function fz(n){if(!(n instanceof HTMLElement))return{};const t={};if(n.style.textAlign==="right"?t.align="right":n.style.textAlign==="center"&&(t.align="center"),n.style.marginLeft){const e=Math.ceil(Number.parseInt(n.style.marginLeft,10)/20);e>=1&&e<=12&&(t.padding=e)}return t}function dz(n,t){return t&&Object.keys(t).length>0?{insert:n,attributes:t}:{insert:n}}function hz(n,t){if(n.nodeName==="B")return{...t,"style-bold":!0};if(n.nodeName==="I")return{...t,"style-italic":!0};if(n.nodeName==="U")return{...t,"style-underline":!0};if(n.nodeName==="S"||n.nodeName==="DEL")return{...t,"style-strikethrough":!0};if(n.nodeName==="SUB")return{...t,"style-sub":!0};if(n.nodeName==="SUP")return{...t,"style-super":!0};if(n.nodeName==="BR")return{...t,created:Date.now(),id:tt(),box:!0,type:"br"};if(n.nodeName==="A"&&n.href){const r=n.href;if(r.startsWith("http:")||r.startsWith("https:"))return{...t,link:n.href}}const e={...t};return n instanceof HTMLSpanElement?(n.style.backgroundColor&&(e["inline-style-background-color"]=n.style.backgroundColor),n.style.color&&(e["inline-style-color"]=n.style.color),n.style.fontSize&&(e["inline-style-font-size"]=n.style.fontSize),n.style.fontFamily&&(e["inline-style-font-family"]=n.style.fontFamily),e):t}function OR(n,t,e){var i;if(n instanceof HTMLSpanElement&&n.getAttribute("style")==="mso-list:Ignore")return;const r=hz(n,t);if(n instanceof Text&&n.nodeValue||n.nodeName==="BR"){const o=kR((i=n.nodeValue)!=null?i:" ");o&&e.push(dz(o,r));return}n.childNodes.length>0&&Array.from(n.childNodes).forEach(o=>{OR(o,r,e)})}function NR(n){return n instanceof Element?dE(n):!0}function hE(n){return!NR(n)}function mz(n){if(n.length===0)return[];if(n.length===1)return[n];const t=[];let e=[n[0]],r=hE(n[0]);for(let i=1;i<n.length;i++){const o=n[i];r===hE(o)?e.push(o):(t.push(e),e=[o],r=hE(o))}return t.push(e),t}function gz(n,t){const e={};if(n.tagName.startsWith("H")){const o=Number.parseInt(n.tagName.substr(1),10);o>=1&&o<=8&&(e.heading=o)}const r=mz(Array.from(n.childNodes)),i=[];return r.forEach((o,s)=>{if(NR(o[0])){const l=[],c={};Array.from(n.childNodes).forEach(h=>{OR(h,c,l)});let d={};s===0&&(d=LR(n)),i.push({id:tt(),type:"text",text:l,...d,...e,...fz(n)})}o.forEach(l=>{const c=t.blockElementToBlocks(l,t);i.push(...c)})}),i}function pz(n,t){const e=kd(n);oz(e),UR(e);const r={blocks:{root:[]},meta:{},comments:{}},i={font:t==null?void 0:t.font,doc:r,blockElementToBlocks:DR,textElementToBlocks:gz,htmlToBlocks:uz},o=_R(Array.from(e.children),i);if(o.length!==0)return r.blocks.root=o,r}const Cz=I("html-to-doc");function PR(n,t){if(!n)return null;const e=mj(n);if(e)return e;if(yR(n)){const r=pz(n,t);if(r)return r}try{return TR(n,t)}catch(r){Cz.error(r)}return null}class Ez{async fromData(t,e){const r={},i=e.getData("text/html");if(i){const o=PR(i,{font:t.rootContainer});o&&(yR(i)?r["text/office-html"]=o:r["text/html"]=o)}return r}}class Az{async fromData(t,e){const r=e.getData("text/plain");if(!r)return;const i=CR(r,{font:t.rootContainer,htmlToDoc:PR});if(!!i)return{"text/markdown":i}}}function xz(n){return/^([\d\w\u4e00-\u9fa5\s]*[\u4e00-\u9fa5\s]{1}|)((https|http|ftp)?:\/\/)[^\s]+/.test(n)}function bz(n){const t=[],e=n.split(/https|http|ftp/)[0],r=n.substring(e.length).trim();if(e&&e.length){const o=mr(e,null);t.push(o,mr(" ",null))}const i=mr(r,{link:r});return t.push(i,mr(" ",null)),t}class Bz{async fromData(t,e,r){const{toPlainText:i=!1}=r||{},o={},s=e.getData("text/plain");if(s){const d={blocks:{root:s.replace(/\r\n/g,`
|
|
681
681
|
`).replace(/\r/g,`
|
|
682
682
|
`).split(`
|
|
683
|
-
`).map(h=>{const C={id:tt(),type:"text"};if(xz(h)&&!i)return C.text=bz(h),C;const E=h?[mr(h,null)]:[];return C.text=E,C})},meta:{},comments:{}};o["text/plain"]=d}return o}}function vz(n){const t=[];for(let e=0;e<n.length;e++){const r=n[e];r.type.toLocaleLowerCase().startsWith("image/")&&t.push(r)}return t}class mE{constructor(t){t.dataConverter.addConverter(new Ez),t.dataConverter.addConverter(new Bz),t.dataConverter.addConverter(new Az)}async handleBeforePaste(t,e,r,i){if(!e)return!1;const o=e.clipboardData;if(o){if(o.getData("text/html").indexOf("<ones-editor-doc")>0)return!1;const l=o.getData("text/plain"),c=vz(i);if(c.length>0&&!l&&!r["text/office-html"])return await this.handleInsertImages(t,c),!0}return!1}async handleInsertImages(t,e){const{start:r,end:i}=t.selection.range,o=t.selection.focusedBlock;let s=rt(o),c=bt(o);const d=nt(s);if(d&&It(d)==="code")return;if(r.blockId===i.blockId&&Ae(o))c+=1;else{t.clearSelectedContents();const{blockId:C}=t.selection.range.start,E=t.getBlockById(C);c=bt(E),s=rt(E),ae(t,E)||(c+=1),Qt(s)&&c===0&&(c+=1)}const h=ft(s);for(let C=0;C<e.length;C++){const E=e[C],x=await Ng(t,"image",h,c+C,{file:E});x&&g3(t,x,"image",{id:"replace-image",name:"Replace image",data:{block:x,image:E}})}}}class Tz extends ke.TypedEmitter{constructor(t){super(),this.editor=t}onUpdateBlockText(t,e,r){const i=this.editor.getCustom("find-dialog");if(!i||!i.isVisible())return;const o=Hi(li(this.editor,t),e);!et(this.editor,o)||!r.some(l=>l.insert||l.delete)||this.emit("onDocChanged",o)}onInsertBlock(t,e,r,i){Hi(li(this.editor,t),e),this.emit("onDocInserted")}onDeleteBlock(t,e,r){const i=Hi(li(this.editor,t),e);this.emit("onDocDeleted",i)}}function FR(n){return de.isSafari&&!!n&&Date.now()-n<100}const KR=I("highlight-data");class N0{constructor(t){g(this,"data",new Map);this.editor=t}add(t,e,r){const i={id:tt(),blockId:st(t),oldText:this.editor.getBlockText(t),start:e,end:r};return this.data.set(i.id,i),i}get(t){const e=this.data.get(t);return p(KR,e,`no highligh data: ${t}`),e}remove(t){this.data.delete(t)}clearBlockData(t){Array.from(this.data.values()).forEach(e=>{e.blockId===t&&this.data.delete(e.id)})}destroy(){}static getData(t){return t.addCustom("highligh-data",()=>new N0(t))}}function yz(n,t,e,r,i){const s=N0.getData(n).add(t,e,r);return i.setAttribute("data-highlight-id",s.id),s}function P0(n,t){const e=t.getAttribute("data-highlight-id");return p(KR,e,"invalid highlight elem, no id"),N0.getData(n).get(e)}const Ga=I("highligh-dom");function kz(n){return kt(n,"editor-highlight")}function yi(n){const t=n.rootContainer.querySelectorAll(".editor-highlight");return Array.from(t)}function Rz(n,t){p(Ga,t,"invalid block");const e=t.querySelectorAll(".editor-highlight");return Array.from(e)}function wz(n){const t=n.rootContainer.querySelectorAll(".editor-replace-result-highlight");return Array.from(t)}function F0(n){const t=n.querySelectorAll(".editor-highlight");return Array.from(t)}function Sz(n){F0(n).forEach(t=>{t.remove()})}function ao(n){return yi(n).length}function Lz(n,t){p(Ga,t>=0,`invalid highlight index: ${t}`);const e=yi(n);return e.length===0?null:(p(Ga,t<e.length,`invalid highlight index: ${t}/${e.length}`),e[t])}function Iz(n,t,{left:e,top:r,width:i,height:o},s){const l=["editor-highlight-child"];s&&l.push("editor-highlight-readonly");const c=v("div",l,n);c.style.top=`${r}px`,c.style.left=`${e}px`,c.style.width=`${i}px`,c.style.height=`${o}px`}function VR(n,t,e,r,i){p(Ga,r>0,`invalid end: ${r}`);const o=ne(t),s=t.getBoundingClientRect(),l=Gi(n,t,ve(n,t,e,r)),d=v("div",[i==="find"?"editor-highlight":"editor-replace-result-highlight"],o);l.forEach(h=>{Iz(d,t,{left:h.left-s.left,width:h.width,top:h.top-s.top,height:h.height})}),yz(n,t,e,r,d)}function Dz(n,t,e,r){return VR(n,t,e,r,"find")}function $R(n,t,e,r){return VR(n,t,e,r,"replace")}function K0(n,t){yi(n).forEach(s=>{kt(s,"active")&&ot(s,"active")}),z(t,"active"),p(Ga,t.firstChild instanceof HTMLElement,"invalid highligh dom, invalid elem child");const r=t.firstChild;let o=r.getBoundingClientRect().y;o===0&&(o=r.getBoundingClientRect().y),Is(r,{elementToScroll:n.scrollContainer})}function af(n){const t=n.rootContainer.querySelector(".editor-highlight.active");return t||null}function HR(n){return p(Ga,n,"no highlight elem"),kt(n,"editor-highlight-readonly")}const Wa=I("highligh-text");function jR(n){wz(n).forEach(e=>{e.remove()})}function V0(n,t){yi(n).forEach(r=>{r.remove()}),t!=null&&t.keepReplaceResult||jR(n)}function zR(n,t,e){Rz(n,t).forEach(i=>{i.remove()}),e!=null&&e.keepReplaceResult||jR(n)}function cf(n){const t=af(n);if(!t)return-1;const r=yi(n).indexOf(t);return p(Wa,r!==-1,`invalid highlight index: ${r}`),r}function _z(n){const t=yi(n);if(t.length===0)return 0;const e=af(n);let r=e?t.indexOf(e):-1;!e||r===-1||r===t.length-1?r=0:r+=1;const i=t[r];return K0(n,i),r}function Mz(n){const t=yi(n);if(t.length===0)return 0;const e=af(n);let r=e?t.indexOf(e):-1;!e||r===-1||r===0?r=t.length-1:r-=1;const i=t[r];return K0(n,i),r}function gE(n,t){const e=yi(n);e.length>0&&t<e.length&&K0(n,e[t])}function Uz(n,t,e){const r=af(n);if(!r)return!1;const i=nt(r);if(p(Wa,i,"no parent block"),!n.isBlockWritable(i))return!1;const o=ao(n);let s=cf(n);if(!HR(r)&&n.isBlockWritable(i)){const d=P0(n,r),h=n.getBlockText(i),{start:C,end:E}=P0(n,r),[x,B]=dn.transformOffset(d.oldText,h,[C,E]),R=d5(h,x,B-x);if(ce(R).toLowerCase()!==t.toLowerCase())return!1;const L=Yd(h,x,B,e);n.setBlockText(i,L),Sz(i),pE(n,i,t),e&&$R(n,i,x,x+e.length)}const l=ao(n);s>=l?s=0:l>o&&(s+=1);const c=Lz(n,s);return c&&K0(n,c),!0}function Oz(n,t,e,r){if(!et(n,t)||!n.isBlockWritable(t))return 0;const i=n.getBlockText(t);p(Wa,i,"no block text");const o={count:0},s=M5(i,e,r,o);return ce(i)===ce(s)?0:(n.setBlockText(t,s),o.count)}function Nz(n,t,e){if(p(Wa,kz(t),"not a highlight elem"),HR(t))return;p(Wa,e>0,"invalid highlight length");const r=P0(n,t),i=nt(t);p(Wa,i,"no parent block"),$R(n,i,r.start,r.start+e)}function Pz(n,t){yi(n).forEach(r=>{Nz(n,r,t)})}function Fz(n,t,e){if(n.readonly)return 0;const r=o=>{let s=0;return Ce(o).forEach(c=>{_t(n,c)?xn(n,c).forEach(h=>{s+=r(h)}):s+=Oz(n,c,t,e)}),s},i=r(n.rootContainer);return e.length>0&&Pz(n,e.length),i}function Kz(n){const t=n.selection.range.end,e=n.getBlockById(t.blockId),r=t.isSimple()?t.offset:1,i=F0(e);for(let l=0;l<i.length;l++){const c=i[l],{end:d}=P0(n,c);if(d>=r)return c}const o=Gg(n,{simpleBlockOnly:!0}),s=o.indexOf(e);if(s===-1)return null;for(let l=s+1;l<o.length;l++){const c=o[l],d=F0(c);if(d.length>0)return d[0]}return null}function Vz(n){const t=yi(n),e=Kz(n);return e?t.indexOf(e):0}function pE(n,t,e){if(!!e&&et(n,t)){const r=n.getBlockText(t),i=f1(r,e);i.length>0&&i.forEach(({start:o,end:s})=>{Dz(n,t,o,s)})}}function GR(n,t){if(V0(n),!t)return;Gg(n,{simpleBlockOnly:!0}).forEach(r=>{pE(n,r,t)})}class $z{constructor(t){g(this,"dialog",null);g(this,"root");g(this,"oldText","");g(this,"_compositionEndTime",0);g(this,"components");g(this,"handleFindChanged",()=>{this.doSearch({keepReplaceResult:!1,gotoFirstSearchResult:!0})});g(this,"handleCompositionEnd",()=>{this._compositionEndTime=Date.now(),this.handleFindChanged()});g(this,"handleDocChanged",t=>{setTimeout(()=>{zR(this.editor,t),pE(this.editor,t,this.components.findInput.value);const e=ao(this.editor);t.querySelectorAll(".editor-highlight").length===e&&gE(this.editor,0);const r=cf(this.editor);this.updateSearchStatus(r,e)})});g(this,"handleDocInserted",()=>{const t=setTimeout(()=>{clearTimeout(t),V0(this.editor,{keepReplaceResult:!0}),GR(this.editor,this.components.findInput.value);const e=ao(this.editor),r=cf(this.editor);this.updateSearchStatus(r,e),gE(this.editor,r)})});g(this,"handleDocDeleted",t=>{const e=setTimeout(()=>{if(!F0(t).length){clearTimeout(e);return}zR(this.editor,t);const i=ao(this.editor),o=cf(this.editor);this.updateSearchStatus(o,i)})});g(this,"handleInput",t=>{if(t.isComposing||FR(this._compositionEndTime)){this.doSearch.cancel();return}this.handleFindChanged()});g(this,"handleFind",()=>{this.findNext({keepSearchResult:!1})});g(this,"handleReplace",()=>{const t=this.components.findInput.value;if(!t||!af(this.editor))return;const r=this.components.replaceInput.value;if(t===r)return;if(Uz(this.editor,t,r)){const o=cf(this.editor),s=ao(this.editor);this.updateSearchStatus(o,s)}r.includes(t)&&this.findNext({keepSearchResult:!0})});g(this,"handleReplaceAll",()=>{const t=this.components.findInput.value;if(!t)return;const e=this.components.replaceInput.value;t!==e&&this.editor.undoManager.runInGroup(()=>{Fz(this.editor,t,e)>0&&(this.oldText="",this.doSearchNow({keepReplaceResult:!0,gotoFirstSearchResult:!0}),this.clearFind({keepReplaceResult:!0}))})});g(this,"doSearch",Ke.default(this.doSearchNow,300));this.editor=t;const e=v("div",["editor-find-dialog"],null),r=v("div",["editor-find-content"],e),i=v("div",["editor-find-dialog-row"],r),o=ws(Dh,["editor-find-dialog-button-close"],e),s=v("label",["editor-find-dialog-label"],i,D.t("find.findLabel"));s.htmlFor="";const l=v("div",["editor-find-dialog-input-container"],i),c=v("input",["editor-find-dialog-input"],l);c.type="text",c.placeholder=D.t("find.findPlaceholder");const d=v("div",["editor-find-dialog-status"],l),h=ws(v2,["editor-find-dialog-icon-button"],d),C=v("div",["editor-find-dialog-curr"],d,"0/0"),E=ws(T2,["editor-find-dialog-icon-button"],d);let x;D.t("find.moreButton")?x=v("button",["editor-find-dialog-button"],i,D.t("find.moreButton")):x=ws(Ep,["editor-find-dialog-icon-button-border"],i);const B=v("div",["editor-find-dialog-row"],r),R=v("label",["editor-find-dialog-label"],B,D.t("find.replaceLabel"));R.htmlFor="";const L=v("div",["editor-find-dialog-input-container"],B),U=v("input",["editor-find-dialog-input"],L);U.type="text",U.placeholder=D.t("find.replacePlaceholder");const M=v("div",["editor-find-dialog-row","editor-find-dialog-action"],r);v("div",["editor-find-dialog-space"],M);const F=v("button",["editor-find-dialog-button"],M,D.t("find.findButton")),G=v("button",["editor-find-dialog-button"],M,D.t("find.replaceButton")),q=v("button",["editor-find-dialog-button","editor-find-dialog-primary-button"],M,D.t("find.replaceAllButton"));x.onclick=()=>{this.showReplace()},o.onclick=()=>{this.hide()},c.onkeydown=at=>{if(at.isComposing||FR(this._compositionEndTime)){this.doSearch.cancel();return}Bb(at)?(this.doSearch.cancel(),this.doSearchNow({keepReplaceResult:!1,gotoFirstSearchResult:!0})):bg(at)&&this.hide()},c.oninput=this.handleInput,c.onpaste=this.handleFindChanged,c.oncut=this.handleFindChanged,c.addEventListener("compositionend",this.handleCompositionEnd),c.maxLength=50,F.onclick=this.handleFind,G.onclick=this.handleReplace,q.onclick=this.handleReplaceAll,U.maxLength=50,E.onclick=()=>{this.gotoNext()},h.onclick=()=>{this.gotoPrev()},this.components={findInput:c,findPrev:h,findCurrent:C,findNext:E,replaceInput:U,findButton:F,replaceButton:G,replaceAllButton:q,closeButton:o,showReplaceButton:x,rowReplace:B,rowActions:M,statusContainer:d},this.root=e;const it=new Tz(t);t.doc.registerCallback(it),it.addListener("onDocChanged",this.handleDocChanged),it.addListener("onDocInserted",this.handleDocInserted),it.addListener("onDocDeleted",this.handleDocDeleted)}findNext(t){this.doSearch.cancel(),this.doSearchNow({keepReplaceResult:t.keepSearchResult,gotoFirstSearchResult:!0})}doSearchNow(t){const e=this.components.findInput.value;if(e||this.clearFind(t),this.oldText===e){this.gotoNext();return}this.oldText=e,GR(this.editor,e);const r=ao(this.editor),i=Vz(this.editor);t.gotoFirstSearchResult&&gE(this.editor,i),this.updateSearchStatus(i,r)}gotoNext(){const t=ao(this.editor),e=_z(this.editor);this.updateSearchStatus(e,t)}gotoPrev(){const t=ao(this.editor),e=Mz(this.editor);this.updateSearchStatus(e,t)}updateSearchStatus(t,e){if(this.oldText?this.components.statusContainer.style.display="flex":this.components.statusContainer.style.display="none",e===0)this.components.findCurrent.innerText="0 / 0",this.components.replaceAllButton.disabled=!0,this.components.replaceButton.disabled=!0,this.components.findButton.disabled=!0;else{this.components.findCurrent.innerText=`${t+1} / ${e}`;const r=this.editor.readonly;this.components.replaceAllButton.disabled=r,this.components.replaceButton.disabled=r,this.components.findButton.disabled=!1}}clearFind(t){V0(this.editor),this.updateSearchStatus(0,0)}showFindOnly(){this.components.rowReplace.style.display="none",this.components.rowActions.style.display="none",this.components.showReplaceButton.style.display="flex"}showReplace(){this.components.rowReplace.style.display="flex",this.components.rowActions.style.display="flex",this.components.showReplaceButton.style.display="none",this.components.replaceInput.focus(),this.components.replaceInput.select()}hideSearchResult(){this.components.statusContainer.style.display="none"}showSearchResult(){this.components.statusContainer.style.display="flex"}show(t){const e=this.editor.getSelectedText();e.length>0&&e.length<50&&(this.components.findInput.value=e),this.root.style.display="flex",t!=null&&t.showFindAndReplace?(this.showReplace(),this.components.findInput.value&&setTimeout(()=>{this.components.replaceInput.focus()})):this.showFindOnly(),this.hideSearchResult(),this.oldText="",this.doSearchNow({keepReplaceResult:!1,gotoFirstSearchResult:!0});const r=this.editor.readonly,i=this.components.findInput.value;this.components.replaceButton.disabled=r||!i,this.components.replaceAllButton.disabled=r||!i,this.components.replaceInput.disabled=r,this.dialog||(this.dialog=new Ru(this.root,{disablePageScroll:!1}));const o=this.editor.options.componentsOptions.findDialog,s=(o==null?void 0:o.popoverTarget)||this.editor.rootContainer,l=()=>{var E,x,B,R;const c=o==null?void 0:o.getReferenceClientRect;if(c&&((x=(E=this.dialog)==null?void 0:E.tippyInstance)==null?void 0:x.popper))return c(s,(R=(B=this.dialog)==null?void 0:B.tippyInstance)==null?void 0:R.popper);const d=s.getBoundingClientRect(),h=d.top<0?12:d.top+12,C=d.right-this.root.clientWidth-12;return new DOMRect(C,h,0,0)};this.dialog.show(s,{getReferenceClientRect:l}),setTimeout(()=>{this.components.findInput.focus(),this.components.findInput.select()},300)}hide(){var t;(t=this.dialog)==null||t.close("cancelBar"),V0(this.editor)}isVisible(){return this.dialog&&this.dialog.isVisible}research(){this.oldText="",this.doSearch({keepReplaceResult:!0,gotoFirstSearchResult:!1})}destroy(){var t;(t=this.dialog)==null||t.destroy()}}const Hz={find:{findLabel:"\u67E5\u627E:",replaceLabel:"\u66FF\u6362:",findButton:"\u67E5\u627E",replaceButton:"\u66FF\u6362",replaceAllButton:"\u5168\u90E8\u66FF\u6362",moreButton:"",findPlaceholder:"\u5728\u6587\u6863\u5185\u67E5\u627E",replacePlaceholder:"\u66FF\u6362\u4E3A"}},jz={find:{findLabel:"Search:",replaceLabel:"Replace:",findButton:"Search",replaceButton:"Replace",replaceAllButton:"Replace all",moreButton:"",findPlaceholder:"Search text in document",replacePlaceholder:"Replace with"}},zz={find:{findLabel:"\u691C\u7D22\uFF1A",replaceLabel:"\u7F6E\u63DB\uFF1A",findButton:"\u691C\u7D22",replaceButton:"\u7F6E\u63DB",replaceAllButton:"\u3059\u3079\u3066\u3092\u7F6E\u63DB",moreButton:"",findPlaceholder:"\u30C9\u30AD\u30E5\u30E1\u30F3\u30C8\u3092\u691C\u7D22",replacePlaceholder:"\u306B\u7F6E\u63DB"}};D.mergeLang({"zh-CN":Hz,"en-US":jz,"ja-JP":zz});function WR(n){return n.addCustom("find-dialog",()=>new $z(n)).show(),!0}const qR={"CtrlOrCmd+F":WR},_st="";function Gz(n){WR(n)}function Wz(n,t){const e=t.getImages(),r=t.getSelectedIndex();if(r!==-1){const i=document.createElement("a");i.href=n,i.download=e[r].src,i.click()}}function qz(n){return new Promise((t,e)=>{const r=new FileReader;r.onload=()=>{const i=r.result;t(i)},r.onerror=()=>{e(new Error("Failed to read Blob as string."))},r.readAsText(n)})}async function Xz(n){try{const e=(await navigator.clipboard.read())[0],r=e.types,i=new DataTransfer;for(let l=0;l<r.length;l++){const c=r[l],d=await e.getType(c),h=await qz(d);i.setData(c,h)}const o=n.dataConverter.fromData(n,i),s=new Q1(n);o.then(async l=>{l&&s.pasteDocs(l,null,[])})}catch{}}const Qz=I("is-clipboard-empty");async function Yz(){try{const n=await navigator.clipboard.readText(),e=(await navigator.clipboard.read())[0].types;return!n.trim()&&e.length===1&&e.includes("text/plain")}catch(n){return Qz.warn(`Failed to read clipboard data: ${n}`),!1}}class Zz{constructor(t){g(this,"t",D.t);g(this,"isSecureContext",T0());g(this,"getPasteCommandItem",async()=>{const t=await Yz(),e=this.isSecureContext&&!t,r=this.t("contextMenu.paste"),i=Ge("CtrlOrCmd+V");return{id:"paste",name:r,subText:i,states:e?[]:["disabled"],disableReason:this.isSecureContext?"":this.secureEnvTips(i,r)}});g(this,"getCommandItems",async()=>{const t=await this.getPasteCommandItem(),e=this.editor.readonly?[]:[this.cutCommandItem,t];return[...this.copyTypeCommandItems,...e,this.stepItem,...this.selectionCommandItems]});g(this,"isFocusImageBlock",()=>{const t=this.editor.selection,e=t.focusedBlock;return Ae(e)&&tn(e)==="image"&&t.range.getSelectedBlocks().length===1});this.editor=t}get isRangeCollapsed(){return this.editor.selection.range.isCollapsed()}get imageTypeCommandItems(){const t=this.isSecureContext;return[{id:"copy-image",name:this.t("contextMenu.copyImage"),subText:Ge("CtrlOrCmd+C"),states:t?[]:["disabled"],disableReason:this.isSecureContext?"":this.secureEnvTips(this.t("contextMenu.copyImage"),Ge("CtrlOrCmd+C"))},{id:"copy-image-url",name:this.t("contextMenu.copyImageUrl"),states:t?[]:["disabled"]},{id:"image-save-as",name:this.t("contextMenu.imageSaveAs")},{id:"new-tab-open-image",name:this.t("contextMenu.newTabOpenImage")}]}get copyTypeCommandItems(){const t=this.isSecureContext&&!this.isRangeCollapsed;if(this.isFocusImageBlock())return this.imageTypeCommandItems;const e=this.t("copyCutProperty.copy"),r=Ge("CtrlOrCmd+C"),i=[{id:"copy",name:e,subText:r,states:t?[]:["disabled"],disableReason:this.isSecureContext?"":this.secureEnvTips(r,e)}],o=this.t("contextMenu.copyMarkdown"),s=Ge("CtrlOrCmd+Shift+C");return i.push({id:"copy-markdown",name:o,subText:s,states:t?[]:["disabled"],disableReason:this.isSecureContext?"":this.secureEnvTips(s,o)}),i}get cutCommandItem(){let t=this.isSecureContext&&!this.isRangeCollapsed;const r=this.editor.selection.range.getSelectedBlocks().some(l=>!this.editor.isBlockWritable(l.block));r&&(t=!1);const i=this.t("copyCutProperty.cut"),o=Ge("CtrlOrCmd+X");let s="";return t||(this.isSecureContext?r&&(s=this.t("contextMenu.uneditableBlockSelected")):s=this.secureEnvTips(o,i)),{id:"cut",name:this.t("copyCutProperty.cut"),subText:Ge("CtrlOrCmd+X"),states:t?[]:["disabled"],disableReason:s}}get stepItem(){return{id:"step",name:"",type:"separator"}}get selectionCommandItems(){const t=this.isFocusImageBlock(),e=[{id:"select-block",name:this.t("contextMenu.selectBlock")}];return t||e.push({id:"select-all",name:this.t("contextMenu.selectAll")}),e}secureEnvTips(t,e){return this.t("copyCutProperty.unsafeEnvTips",{shortCut:t,operation:e})}}const Mst="";I("right-context-menu");class XR{constructor(t){g(this,"contextMenu");g(this,"contextMenuCommandItems");g(this,"handleContextMenu",t=>{!this.editor.options.enableContextMenu||this.isInEditor(t)&&t.preventDefault()});g(this,"isInMenu",t=>this.contextMenu.isInCommandBar(t.target));g(this,"isInEditor",t=>{const{clientX:e,clientY:r}=t,i=this.editor.rootElement,o=i.getBoundingClientRect(),{top:s,left:l,right:c,bottom:d}=o,h=e>=l&&e<=c&&r>=s&&r<=d,C=t.target instanceof HTMLElement&&i.contains(t.target);return h&&(this.isInMenu(t)||C)});g(this,"handleContextMenuShown",async()=>{const t=this.editor.getCustom("toolbar-handler");t&&t.hide();const e=await this.contextMenuCommandItems.getCommandItems();this.contextMenu.updateItems(e)});g(this,"handleContextMenuClick",(t,e)=>{const{id:r}=e;switch(r){case"copy":case"copy-markdown":X1(this.editor,{copyAsMarkdown:r==="copy-markdown"});break;case"cut":if(this.handleImageEmbedAction(r))break;X1(this.editor),uh(this.editor);break;case"paste":Xz(this.editor);break;case"copy-image":case"copy-image-url":case"image-save-as":case"new-tab-open-image":this.handleImageEmbedAction(r);break;case"select-all":mh(this.editor,this.editor.rootContainer);break;case"select-block":j1(this.editor);break}});this.editor=t,this.contextMenu=new qo([],void 0,{id:"right-context-menu"}),this.contextMenu.on("show",this.handleContextMenuShown),this.contextMenu.on("click",this.handleContextMenuClick),document.addEventListener("contextmenu",this.handleContextMenu),this.contextMenuCommandItems=new Zz(t)}show(t){this.contextMenu.manualShow(document.body,{theme:"light",point:{x:t.clientX,y:t.clientY}})}close(){}handleImageEmbedAction(t){const e=this.editor.selection.focusedBlock;if(Ae(e)&&tn(e)==="image"){const r=e,i=Se.getImageObject(this.editor,r),o=i.getSelectedIndex();if(o!==-1){let s=r.querySelectorAll("img")[o].src;if(s){switch(s=this.editor.doc.buildResourceUrl(s),t){case"cut":U0(this.editor,null),O0(this.editor);break;case"copy-image":U0(this.editor,null);break;case"copy-image-url":Fc([{type:"text/plain",data:new Blob([s],{type:"text/plain"})}]);break;case"image-save-as":Wz(s,i);break;case"new-tab-open-image":window.open(s);break}return!0}}}return!1}}const Jz={contextMenu:{copyMarkdown:"\u590D\u5236\u4E3A Markdown",paste:"\u7C98\u8D34",copyImage:"\u590D\u5236\u56FE\u7247",copyImageUrl:"\u590D\u5236\u56FE\u7247\u5730\u5740",imageSaveAs:"\u56FE\u7247\u53E6\u5B58\u4E3A",newTabOpenImage:"\u65B0\u6807\u7B7E\u9875\u6253\u5F00\u56FE\u7247",selectBlock:"\u9009\u4E2D\u533A\u5757",selectAll:"\u9009\u4E2D\u5168\u6587",uneditableBlockSelected:"\u5F85\u8865\u5145\u8BDD\u672F"}},tG={contextMenu:{copyMarkdown:"\u590D\u5236\u4E3A Markdown",paste:"paste",copyImage:"\u590D\u5236\u56FE\u7247",copyImageUrl:"\u590D\u5236\u56FE\u7247\u5730\u5740",imageSaveAs:"\u56FE\u7247\u53E6\u5B58\u4E3A",newTabOpenImage:"\u65B0\u6807\u7B7E\u9875\u6253\u5F00\u56FE\u7247",selectBlock:"\u9009\u4E2D\u533A\u5757",selectAll:"\u9009\u4E2D\u5168\u6587",uneditableBlockSelected:"\u5F85\u8865\u5145\u8BDD\u672F"}},eG={contextMenu:{copyMarkdown:"\u590D\u5236\u4E3A Markdown",paste:"\u7C98\u8D34",copyImage:"\u590D\u5236\u56FE\u7247",copyImageUrl:"\u590D\u5236\u56FE\u7247\u5730\u5740",imageSaveAs:"\u56FE\u7247\u53E6\u5B58\u4E3A",newTabOpenImage:"\u65B0\u6807\u7B7E\u9875\u6253\u5F00\u56FE\u7247",selectBlock:"\u9009\u4E2D\u533A\u5757",selectAll:"\u9009\u4E2D\u5168\u6587",uneditableBlockSelected:"\u5F85\u8865\u5145\u8BDD\u672F"}};D.mergeLang({"zh-CN":Jz,"en-US":tG,"ja-JP":eG});function CE(n,t){return t.map(e=>{var o,s;const r=Zt(n,e),i=(o=r.getBlockProperties)==null?void 0:o.call(r,n,e);return Ae(e)||_t(n,e)?i!=null&&i.abstract?`[${i.abstract}]`:"":(s=i==null?void 0:i.abstract)!=null?s:""}).join(" ")}function $0(n){const{editor:t,commentGroupId:e,abstract:r="text"}=n,i=tt(),o=t.doc.getUser(),s=Date.now(),l=e!=null?e:i;return{id:i,groupId:l,userId:o.userId,displayName:o.displayName,avatarUrl:o.avatarUrl,abstract:r,created:s,modified:s}}function QR(n,t,e){const r=e.id,o=n.getBlockData(t).comments;let s;o?s=[...o,r]:s=[r];const l={comments:s};n.updateBlockData(t,l)}function EE(n,t,e){const r=CE(n,[t]),i=$0({editor:n,abstract:r});QR(n,t,i);const o=Ji();return e.localCreateComment(i,o),i}const nG=I("standard-block-actions");class rG{constructor(t,e){g(this,"executeCommand",(t,e,r)=>{const i=r.data;try{this.editorComments.showCommentList();const o=t.getBlockById(i);EE(t,o,this.provider)}catch(o){nG.error(`failed to execute block command: ${JSON.stringify(o)}`)}});this.provider=t,this.editorComments=e}commands(t,e){const r=st(e);return{group:"block-comment-actions",commands:[{id:"comment",name:D.t("comment.quickMenuCommand"),data:r,order:100,states:t.readonly?["disabled"]:[]}],executeCommand:this.executeCommand}}}class iG{async handleBeforePasteDoc(t,e){return Object.values(e.blocks).forEach(r=>{r.forEach(i=>{delete i.comments,i.text&&i.text.forEach(o=>{if(o.attributes){const s=o.attributes;Object.keys(s).forEach(l=>{l.startsWith("comment-")&&delete s[l]})}})})}),!1}}var Jt=(n=>(n.SwitchUp="switch-up",n.SwitchDown="switch-down",n.CommentItemReply="comment-item-reply",n.CommentItemMore="comment-item-more",n.CommentItemOk="comment-item-ok",n.CommentItemCancel="comment-item-cancel",n.CommentItemDelete="comment-item-delete",n.CommentItemEdit="comment-item-edit",n.QuickReply="quick-reply",n.QuickReplyOk="quick-reply-ok",n.QuickReplyCancel="quick-reply-cancel",n))(Jt||{});const AE="group-item-action",YR="last-comment-item",oG="disabled",ZR=500;function qa(n){return n.id!==n.groupId}function JR(n,t=".comment-item-root"){return n.querySelectorAll(t).length}function sG(n){const t=n.closest(".comment-item-root");return t?t.id:null}function co(n,t){n.setAttribute(AE,t)}function lG(n){return n.closest(`[${AE}]`)}function aG(n){var t;return(t=n.getAttribute(AE))!=null?t:""}function cG(n){return n.disabled||n.classList.contains(oG)}function tw(n,t){const e=n.rootContainer.querySelector(`[comment-${t.toLocaleLowerCase()}=${t}]`);if(!e)return null;const r=e.closest('[data-type="editor-block"]');return r?r.id:null}function ew(n){return Array.from(n.attributes).map(e=>e.name).filter(e=>e.startsWith("comment-")).map(e=>e.replace("comment-",""))}const nw=I("doc-comments");function rw(n,t,e,r){if(t.comments){const o=t.comments;Array.isArray(o)&&o.forEach(s=>{r.has(s)||(r.add(s),e.push(s))})}t.text&&t.text.forEach(s=>{if(s.attributes){const l="comment-";Object.entries(s.attributes).forEach(([c,d])=>{if(c.startsWith(l)){const h=d;r.has(h)||(r.add(h),e.push(h))}})}});const i=t.children;!i||i.forEach(o=>{n.blocks[o].forEach(l=>{rw(n,l,e,r)})})}function uG(n){const t=[],e=new Set;n.blocks.root.forEach(i=>{rw(n,i,t,e)});const r=new Map;return t.forEach((i,o)=>r.set(i,o)),r}function fG(n){const t=new Map;n.forEach(i=>{if(qa(i)){const o=t.get(i.groupId);o?o.push(i):t.set(i.groupId,[i])}});const e=[];return n.forEach(i=>{var o;if(!qa(i)){const s=(o=t.get(i.id))!=null?o:[];t.delete(i.id);const l={...i,children:s};e.push(l)}}),Array.from(t.values()).forEach(i=>{const o=i[0],s=i.slice(1),l={...o,children:s};e.push(l)}),e}function is(n,t){const e=n.doc.toJSON(),r=uG(e);return fG(t.getComments()).filter(s=>r.has(s.groupId)).sort((s,l)=>{const c=r.get(s.groupId),d=r.get(l.groupId);return p(nw,c!==void 0,`comment not exists in doc, ${s.groupId}`),p(nw,d!==void 0,`comment not exists in doc, ${l.groupId}`),c-d})}function iw(n){const{children:t,...e}=n,r=[e];return t.forEach(i=>{r.push(i)}),r}function dG(n,t){return is(n,t).length}function xE(n,t){const e=[],r=n.getBlockById(t.blockId);if(et(n,r)){const o=t.blockId,s=t.offset,l=n.getBlockById(o),c=n.getBlockText(l),d=ca(c,s);d&&Object.entries(d).forEach(([h,C])=>{h.startsWith("comment-")&&e.push(C)})}const i=r.attributes;for(let o=0;o<i.length;o++){const s=i[o];s.name.startsWith("comment-")&&e.push(s.value)}return e}function ow(n){const t=n.selection.range;if(!t.isSimple())return[];if(t.start.blockId!==t.end.blockId)return[];if(t.isCollapsed())return xE(n,t.start);const{start:e,end:r}=t,i=xE(n,e),o=xE(n,r);return cg.default(i,o)}const hG=I("active-comments");function sw(n,t){n.rootContainer.querySelectorAll(`span.text.comment[comment-${t}],[data-type=editor-block].comment[comment-${t}]`).forEach(r=>{ot(r,"active")})}function lw(n,t,e){const r=n.rootContainer.querySelector("span.text.comment.active,[data-type=editor-block].comment.active");if(!t)r&&ew(r).forEach(o=>sw(n,o));else{const i=t.toLocaleLowerCase();if(r){const s=ew(r);if(s.length===1&&s[0]===i)return;s.forEach(l=>sw(n,l))}const o=n.rootContainer.querySelectorAll(`span.text.comment[comment-${i}],[data-type=editor-block].comment[comment-${i}]`);if(o.length){o.forEach(l=>{z(l,"active")});const s=o[0];if(Os(s)){const l=lt(s,0,"normal");n.selection.setSelection(l,void 0,{noScroll:e==="next"})}else if(ow(n).indexOf(t)===-1){const c=nt(s);p(hG,c,"block not found");const d=zs(c,s),h=lt(c,d.start,"normal");n.selection.setSelection(h,void 0,{noScroll:e==="next"})}if(n.focus(),e==="next"){const l=s.getBoundingClientRect(),c=n.scrollContainer.clientHeight;l.top>c/2&&Is(s,{elementToScroll:n.scrollContainer,verticalOffset:-n.scrollContainer.clientHeight/2})}}}}const Ust="";I("comment-editor");const{t:mG}=D,bE="comment-editor-readonly",uf="comment-editor-editing";class BE{constructor(t,e,r){g(this,"root");g(this,"components");g(this,"handleEditorBlur",()=>{this.inactiveEditor()});g(this,"handleEditorFocus",()=>{this.editor.readonly||this.activeEditor()});g(this,"activeEditor",()=>{kt(this.root,uf)||z(this.root,uf)});g(this,"inactiveEditor",()=>{ot(this.root,uf)});g(this,"handleInsertImg",async()=>{const{editor:t}=this.components,e=ft(t.rootContainer),r=await na("image/*",{}),i={src:"",widthPercent:50},o={id:tt(),type:"embed",embedType:"image",embedData:i},s=t.options.componentsOptions.image;s!=null&&s.defaultAlign&&(o.align=s.defaultAlign);const l=t.getFocusedBlock(),c=t.getBlockIndex(l),d=t.insertBlock(e,c+1,o);Se.getImageObject(t,d).replaceImage(0,r)});g(this,"handleReadonlyChange",t=>{t.readonly?(ot(this.root,uf),z(this.root,bE)):(z(this.root,uf),ot(this.root,bE))});g(this,"setDoc",t=>{const{components:{editor:e}}=this;e.doc.externalDoc.setDoc(t)});g(this,"getDoc",()=>{const{components:{editor:t}}=this;return t.doc.toJSON()});g(this,"isEmpty",()=>d1(this.getDoc()));g(this,"edit",()=>{const{editor:t}=this.components;t.readonly=!1,V1(t),this.activeEditor()});g(this,"clear",()=>{const t=Ji();this.setDoc(t)});g(this,"readonly",()=>{const{editor:t}=this.components;t.readonly=!0});g(this,"destroy",()=>{const{root:t,components:{editor:e,insertImgButton:r}}=this;r.onclick=null,e.destroy(),t.remove()});this.mainEditor=t,this.commentsProvider=e,this.doc=r,this.root=v("div",["comment-editor",bE],null),this.components=this.createEditor()}createEditor(){const t=v("div",["comment-editor-root"],this.root),{commentsProvider:e,mainEditor:r}=this,i=e.createCommentEditor(t,new Y1(this.doc));i.readonly=!0,i.addListener("readonlyChanged",this.handleReadonlyChange),i.addListener("focus",this.handleEditorFocus),i.addListener("blur",this.handleEditorBlur);const o=sl(this.root,"comment-editor-img",mG("comment.image"),M2,void 0,r.clientId);return o.classList.add("comment-editor-img"),o.onclick=this.handleInsertImg,{editor:i,insertImgButton:o}}get editor(){return this.components.editor}}class gG{constructor(t){g(this,"handleBeforeKeyDown",(t,e)=>{if(oi(e,"Enter")){const{quickReply:r,updateLastCommentItem:i}=this.groupItem;return r.getReplyEditor().isEmpty()?(r.hideReplyEditor(),!0):(r.reply(),i(),!0)}return!1});this.groupItem=t}}class pG{constructor(t,e,r){g(this,"handleBeforeKeyDown",(t,e)=>{if(oi(e,"Enter")){const{quickReply:r}=this.groupItem,{comment:i,getCommentEditor:o}=this.commentItem,s=o();if(s.isEmpty())this.commentsProvider.localDeleteComment(i.id);else{const l=s.getDoc();this.commentsProvider.localUpdateComment(i,l),s.readonly()}return r.show(),!0}return!1});this.commentsProvider=t,this.groupItem=e,this.commentItem=r}}const CG=`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
683
|
+
`).map(h=>{const C={id:tt(),type:"text"};if(xz(h)&&!i)return C.text=bz(h),C;const E=h?[mr(h,null)]:[];return C.text=E,C})},meta:{},comments:{}};o["text/plain"]=d}return o}}function vz(n){const t=[];for(let e=0;e<n.length;e++){const r=n[e];r.type.toLocaleLowerCase().startsWith("image/")&&t.push(r)}return t}class mE{constructor(t){t.dataConverter.addConverter(new Ez),t.dataConverter.addConverter(new Bz),t.dataConverter.addConverter(new Az)}async handleBeforePaste(t,e,r,i){if(!e)return!1;const o=e.clipboardData;if(o){if(o.getData("text/html").indexOf("<ones-editor-doc")>0)return!1;const l=o.getData("text/plain"),c=vz(i);if(c.length>0&&!l&&!r["text/office-html"])return await this.handleInsertImages(t,c),!0}return!1}async handleInsertImages(t,e){const{start:r,end:i}=t.selection.range,o=t.selection.focusedBlock;let s=rt(o),c=bt(o);const d=nt(s);if(d&&It(d)==="code")return;if(r.blockId===i.blockId&&Ae(o))c+=1;else{t.clearSelectedContents();const{blockId:C}=t.selection.range.start,E=t.getBlockById(C);c=bt(E),s=rt(E),ae(t,E)||(c+=1),Qt(s)&&c===0&&(c+=1)}const h=ft(s);for(let C=0;C<e.length;C++){const E=e[C],x=await Ng(t,"image",h,c+C,{file:E});x&&g3(t,x,"image",{id:"replace-image",name:"Replace image",data:{block:x,image:E}})}}}class Tz extends ke.TypedEmitter{constructor(t){super(),this.editor=t}onUpdateBlockText(t,e,r){const i=this.editor.getCustom("find-dialog");if(!i||!i.isVisible())return;const o=Hi(li(this.editor,t),e);!et(this.editor,o)||!r.some(l=>l.insert||l.delete)||this.emit("onDocChanged",o)}onInsertBlock(t,e,r,i){Hi(li(this.editor,t),e),this.emit("onDocInserted")}onDeleteBlock(t,e,r){const i=Hi(li(this.editor,t),e);this.emit("onDocDeleted",i)}}function FR(n){return de.isSafari&&!!n&&Date.now()-n<100}const KR=I("highlight-data");class N0{constructor(t){g(this,"data",new Map);this.editor=t}add(t,e,r){const i={id:tt(),blockId:st(t),oldText:this.editor.getBlockText(t),start:e,end:r};return this.data.set(i.id,i),i}get(t){const e=this.data.get(t);return p(KR,e,`no highligh data: ${t}`),e}remove(t){this.data.delete(t)}clearBlockData(t){Array.from(this.data.values()).forEach(e=>{e.blockId===t&&this.data.delete(e.id)})}destroy(){}static getData(t){return t.addCustom("highligh-data",()=>new N0(t))}}function yz(n,t,e,r,i){const s=N0.getData(n).add(t,e,r);return i.setAttribute("data-highlight-id",s.id),s}function P0(n,t){const e=t.getAttribute("data-highlight-id");return p(KR,e,"invalid highlight elem, no id"),N0.getData(n).get(e)}const Ga=I("highligh-dom");function kz(n){return kt(n,"editor-highlight")}function yi(n){const t=n.rootContainer.querySelectorAll(".editor-highlight");return Array.from(t)}function Rz(n,t){p(Ga,t,"invalid block");const e=t.querySelectorAll(".editor-highlight");return Array.from(e)}function wz(n){const t=n.rootContainer.querySelectorAll(".editor-replace-result-highlight");return Array.from(t)}function F0(n){const t=n.querySelectorAll(".editor-highlight");return Array.from(t)}function Sz(n){F0(n).forEach(t=>{t.remove()})}function ao(n){return yi(n).length}function Lz(n,t){p(Ga,t>=0,`invalid highlight index: ${t}`);const e=yi(n);return e.length===0?null:(p(Ga,t<e.length,`invalid highlight index: ${t}/${e.length}`),e[t])}function Iz(n,t,{left:e,top:r,width:i,height:o},s){const l=["editor-highlight-child"];s&&l.push("editor-highlight-readonly");const c=v("div",l,n);c.style.top=`${r}px`,c.style.left=`${e}px`,c.style.width=`${i}px`,c.style.height=`${o}px`}function VR(n,t,e,r,i){p(Ga,r>0,`invalid end: ${r}`);const o=ne(t),s=t.getBoundingClientRect(),l=Gi(n,t,ve(n,t,e,r)),d=v("div",[i==="find"?"editor-highlight":"editor-replace-result-highlight"],o);l.forEach(h=>{Iz(d,t,{left:h.left-s.left,width:h.width,top:h.top-s.top,height:h.height})}),yz(n,t,e,r,d)}function Dz(n,t,e,r){return VR(n,t,e,r,"find")}function $R(n,t,e,r){return VR(n,t,e,r,"replace")}function K0(n,t){yi(n).forEach(s=>{kt(s,"active")&&ot(s,"active")}),z(t,"active"),p(Ga,t.firstChild instanceof HTMLElement,"invalid highligh dom, invalid elem child");const r=t.firstChild;let o=r.getBoundingClientRect().y;o===0&&(o=r.getBoundingClientRect().y),Is(r,{elementToScroll:n.scrollContainer})}function af(n){const t=n.rootContainer.querySelector(".editor-highlight.active");return t||null}function HR(n){return p(Ga,n,"no highlight elem"),kt(n,"editor-highlight-readonly")}const Wa=I("highligh-text");function jR(n){wz(n).forEach(e=>{e.remove()})}function V0(n,t){yi(n).forEach(r=>{r.remove()}),t!=null&&t.keepReplaceResult||jR(n)}function zR(n,t,e){Rz(n,t).forEach(i=>{i.remove()}),e!=null&&e.keepReplaceResult||jR(n)}function cf(n){const t=af(n);if(!t)return-1;const r=yi(n).indexOf(t);return p(Wa,r!==-1,`invalid highlight index: ${r}`),r}function _z(n){const t=yi(n);if(t.length===0)return 0;const e=af(n);let r=e?t.indexOf(e):-1;!e||r===-1||r===t.length-1?r=0:r+=1;const i=t[r];return K0(n,i),r}function Mz(n){const t=yi(n);if(t.length===0)return 0;const e=af(n);let r=e?t.indexOf(e):-1;!e||r===-1||r===0?r=t.length-1:r-=1;const i=t[r];return K0(n,i),r}function gE(n,t){const e=yi(n);e.length>0&&t<e.length&&K0(n,e[t])}function Uz(n,t,e){const r=af(n);if(!r)return!1;const i=nt(r);if(p(Wa,i,"no parent block"),!n.isBlockWritable(i))return!1;const o=ao(n);let s=cf(n);if(!HR(r)&&n.isBlockWritable(i)){const d=P0(n,r),h=n.getBlockText(i),{start:C,end:E}=P0(n,r),[x,B]=dn.transformOffset(d.oldText,h,[C,E]),R=d5(h,x,B-x);if(ce(R).toLowerCase()!==t.toLowerCase())return!1;const L=Yd(h,x,B,e);n.setBlockText(i,L),Sz(i),pE(n,i,t),e&&$R(n,i,x,x+e.length)}const l=ao(n);s>=l?s=0:l>o&&(s+=1);const c=Lz(n,s);return c&&K0(n,c),!0}function Oz(n,t,e,r){if(!et(n,t)||!n.isBlockWritable(t))return 0;const i=n.getBlockText(t);p(Wa,i,"no block text");const o={count:0},s=M5(i,e,r,o);return ce(i)===ce(s)?0:(n.setBlockText(t,s),o.count)}function Nz(n,t,e){if(p(Wa,kz(t),"not a highlight elem"),HR(t))return;p(Wa,e>0,"invalid highlight length");const r=P0(n,t),i=nt(t);p(Wa,i,"no parent block"),$R(n,i,r.start,r.start+e)}function Pz(n,t){yi(n).forEach(r=>{Nz(n,r,t)})}function Fz(n,t,e){if(n.readonly)return 0;const r=o=>{let s=0;return Ce(o).forEach(c=>{_t(n,c)?xn(n,c).forEach(h=>{s+=r(h)}):s+=Oz(n,c,t,e)}),s},i=r(n.rootContainer);return e.length>0&&Pz(n,e.length),i}function Kz(n){const t=n.selection.range.end,e=n.getBlockById(t.blockId),r=t.isSimple()?t.offset:1,i=F0(e);for(let l=0;l<i.length;l++){const c=i[l],{end:d}=P0(n,c);if(d>=r)return c}const o=Gg(n,{simpleBlockOnly:!0}),s=o.indexOf(e);if(s===-1)return null;for(let l=s+1;l<o.length;l++){const c=o[l],d=F0(c);if(d.length>0)return d[0]}return null}function Vz(n){const t=yi(n),e=Kz(n);return e?t.indexOf(e):0}function pE(n,t,e){if(!!e&&et(n,t)){const r=n.getBlockText(t),i=f1(r,e);i.length>0&&i.forEach(({start:o,end:s})=>{Dz(n,t,o,s)})}}function GR(n,t){if(V0(n),!t)return;Gg(n,{simpleBlockOnly:!0}).forEach(r=>{pE(n,r,t)})}class $z{constructor(t){g(this,"dialog",null);g(this,"root");g(this,"oldText","");g(this,"_compositionEndTime",0);g(this,"components");g(this,"handleFindChanged",()=>{this.doSearch({keepReplaceResult:!1,gotoFirstSearchResult:!0})});g(this,"handleCompositionEnd",()=>{this._compositionEndTime=Date.now(),this.handleFindChanged()});g(this,"handleDocChanged",t=>{setTimeout(()=>{zR(this.editor,t),pE(this.editor,t,this.components.findInput.value);const e=ao(this.editor);t.querySelectorAll(".editor-highlight").length===e&&gE(this.editor,0);const r=cf(this.editor);this.updateSearchStatus(r,e)})});g(this,"handleDocInserted",()=>{const t=setTimeout(()=>{clearTimeout(t),V0(this.editor,{keepReplaceResult:!0}),GR(this.editor,this.components.findInput.value);const e=ao(this.editor),r=cf(this.editor);this.updateSearchStatus(r,e),gE(this.editor,r)})});g(this,"handleDocDeleted",t=>{const e=setTimeout(()=>{if(!F0(t).length){clearTimeout(e);return}zR(this.editor,t);const i=ao(this.editor),o=cf(this.editor);this.updateSearchStatus(o,i)})});g(this,"handleInput",t=>{if(t.isComposing||FR(this._compositionEndTime)){this.doSearch.cancel();return}this.handleFindChanged()});g(this,"handleFind",()=>{this.findNext({keepSearchResult:!1})});g(this,"handleReplace",()=>{const t=this.components.findInput.value;if(!t||!af(this.editor))return;const r=this.components.replaceInput.value;if(t===r)return;if(Uz(this.editor,t,r)){const o=cf(this.editor),s=ao(this.editor);this.updateSearchStatus(o,s)}r.includes(t)&&this.findNext({keepSearchResult:!0})});g(this,"handleReplaceAll",()=>{const t=this.components.findInput.value;if(!t)return;const e=this.components.replaceInput.value;t!==e&&this.editor.undoManager.runInGroup(()=>{Fz(this.editor,t,e)>0&&(this.oldText="",this.doSearchNow({keepReplaceResult:!0,gotoFirstSearchResult:!0}),this.clearFind({keepReplaceResult:!0}))})});g(this,"doSearch",Ke.default(this.doSearchNow,300));this.editor=t;const e=v("div",["editor-find-dialog"],null),r=v("div",["editor-find-content"],e),i=v("div",["editor-find-dialog-row"],r),o=ws(Dh,["editor-find-dialog-button-close"],e),s=v("label",["editor-find-dialog-label"],i,D.t("find.findLabel"));s.htmlFor="";const l=v("div",["editor-find-dialog-input-container"],i),c=v("input",["editor-find-dialog-input"],l);c.type="text",c.placeholder=D.t("find.findPlaceholder");const d=v("div",["editor-find-dialog-status"],l),h=ws(v2,["editor-find-dialog-icon-button"],d),C=v("div",["editor-find-dialog-curr"],d,"0/0"),E=ws(T2,["editor-find-dialog-icon-button"],d);let x;D.t("find.moreButton")?x=v("button",["editor-find-dialog-button"],i,D.t("find.moreButton")):x=ws(Ep,["editor-find-dialog-icon-button-border"],i);const B=v("div",["editor-find-dialog-row"],r),R=v("label",["editor-find-dialog-label"],B,D.t("find.replaceLabel"));R.htmlFor="";const L=v("div",["editor-find-dialog-input-container"],B),U=v("input",["editor-find-dialog-input"],L);U.type="text",U.placeholder=D.t("find.replacePlaceholder");const M=v("div",["editor-find-dialog-row","editor-find-dialog-action"],r);v("div",["editor-find-dialog-space"],M);const F=v("button",["editor-find-dialog-button"],M,D.t("find.findButton")),G=v("button",["editor-find-dialog-button"],M,D.t("find.replaceButton")),q=v("button",["editor-find-dialog-button","editor-find-dialog-primary-button"],M,D.t("find.replaceAllButton"));x.onclick=()=>{this.showReplace()},o.onclick=()=>{this.hide()},c.onkeydown=at=>{if(at.isComposing||FR(this._compositionEndTime)){this.doSearch.cancel();return}Bb(at)?(this.doSearch.cancel(),this.doSearchNow({keepReplaceResult:!1,gotoFirstSearchResult:!0})):bg(at)&&this.hide()},c.oninput=this.handleInput,c.onpaste=this.handleFindChanged,c.oncut=this.handleFindChanged,c.addEventListener("compositionend",this.handleCompositionEnd),c.maxLength=50,F.onclick=this.handleFind,G.onclick=this.handleReplace,q.onclick=this.handleReplaceAll,U.maxLength=50,E.onclick=()=>{this.gotoNext()},h.onclick=()=>{this.gotoPrev()},this.components={findInput:c,findPrev:h,findCurrent:C,findNext:E,replaceInput:U,findButton:F,replaceButton:G,replaceAllButton:q,closeButton:o,showReplaceButton:x,rowReplace:B,rowActions:M,statusContainer:d},this.root=e;const it=new Tz(t);t.doc.registerCallback(it),it.addListener("onDocChanged",this.handleDocChanged),it.addListener("onDocInserted",this.handleDocInserted),it.addListener("onDocDeleted",this.handleDocDeleted)}findNext(t){this.doSearch.cancel(),this.doSearchNow({keepReplaceResult:t.keepSearchResult,gotoFirstSearchResult:!0})}doSearchNow(t){const e=this.components.findInput.value;if(e||this.clearFind(t),this.oldText===e){this.gotoNext();return}this.oldText=e,GR(this.editor,e);const r=ao(this.editor),i=Vz(this.editor);t.gotoFirstSearchResult&&gE(this.editor,i),this.updateSearchStatus(i,r)}gotoNext(){const t=ao(this.editor),e=_z(this.editor);this.updateSearchStatus(e,t)}gotoPrev(){const t=ao(this.editor),e=Mz(this.editor);this.updateSearchStatus(e,t)}updateSearchStatus(t,e){if(this.oldText?this.components.statusContainer.style.display="flex":this.components.statusContainer.style.display="none",e===0)this.components.findCurrent.innerText="0 / 0",this.components.replaceAllButton.disabled=!0,this.components.replaceButton.disabled=!0,this.components.findButton.disabled=!0;else{this.components.findCurrent.innerText=`${t+1} / ${e}`;const r=this.editor.readonly;this.components.replaceAllButton.disabled=r,this.components.replaceButton.disabled=r,this.components.findButton.disabled=!1}}clearFind(t){V0(this.editor),this.updateSearchStatus(0,0)}showFindOnly(){this.components.rowReplace.style.display="none",this.components.rowActions.style.display="none",this.components.showReplaceButton.style.display="flex"}showReplace(){this.components.rowReplace.style.display="flex",this.components.rowActions.style.display="flex",this.components.showReplaceButton.style.display="none",this.components.replaceInput.focus(),this.components.replaceInput.select()}hideSearchResult(){this.components.statusContainer.style.display="none"}showSearchResult(){this.components.statusContainer.style.display="flex"}show(t){const e=this.editor.getSelectedText();e.length>0&&e.length<50&&(this.components.findInput.value=e),this.root.style.display="flex",t!=null&&t.showFindAndReplace?(this.showReplace(),this.components.findInput.value&&setTimeout(()=>{this.components.replaceInput.focus()})):this.showFindOnly(),this.hideSearchResult(),this.oldText="",this.doSearchNow({keepReplaceResult:!1,gotoFirstSearchResult:!0});const r=this.editor.readonly,i=this.components.findInput.value;this.components.replaceButton.disabled=r||!i,this.components.replaceAllButton.disabled=r||!i,this.components.replaceInput.disabled=r,this.dialog||(this.dialog=new Ru(this.root,{disablePageScroll:!1}));const o=this.editor.options.componentsOptions.findDialog,s=(o==null?void 0:o.popoverTarget)||this.editor.rootContainer,l=()=>{var E,x,B,R;const c=o==null?void 0:o.getReferenceClientRect;if(c&&((x=(E=this.dialog)==null?void 0:E.tippyInstance)==null?void 0:x.popper))return c(s,(R=(B=this.dialog)==null?void 0:B.tippyInstance)==null?void 0:R.popper);const d=s.getBoundingClientRect(),h=d.top<0?12:d.top+12,C=d.right-this.root.clientWidth-12;return new DOMRect(C,h,0,0)};this.dialog.show(s,{getReferenceClientRect:l}),setTimeout(()=>{this.components.findInput.focus(),this.components.findInput.select()},300)}hide(){var t;(t=this.dialog)==null||t.close("cancelBar"),V0(this.editor)}isVisible(){return this.dialog&&this.dialog.isVisible}research(){this.oldText="",this.doSearch({keepReplaceResult:!0,gotoFirstSearchResult:!1})}destroy(){var t;(t=this.dialog)==null||t.destroy()}}const Hz={find:{findLabel:"\u67E5\u627E:",replaceLabel:"\u66FF\u6362:",findButton:"\u67E5\u627E",replaceButton:"\u66FF\u6362",replaceAllButton:"\u5168\u90E8\u66FF\u6362",moreButton:"",findPlaceholder:"\u5728\u6587\u6863\u5185\u67E5\u627E",replacePlaceholder:"\u66FF\u6362\u4E3A"}},jz={find:{findLabel:"Search:",replaceLabel:"Replace:",findButton:"Search",replaceButton:"Replace",replaceAllButton:"Replace all",moreButton:"",findPlaceholder:"Search text in document",replacePlaceholder:"Replace with"}},zz={find:{findLabel:"\u691C\u7D22\uFF1A",replaceLabel:"\u7F6E\u63DB\uFF1A",findButton:"\u691C\u7D22",replaceButton:"\u7F6E\u63DB",replaceAllButton:"\u3059\u3079\u3066\u3092\u7F6E\u63DB",moreButton:"",findPlaceholder:"\u30C9\u30AD\u30E5\u30E1\u30F3\u30C8\u3092\u691C\u7D22",replacePlaceholder:"\u306B\u7F6E\u63DB"}};D.mergeLang({"zh-CN":Hz,"en-US":jz,"ja-JP":zz});function WR(n){return n.addCustom("find-dialog",()=>new $z(n)).show(),!0}const qR={"CtrlOrCmd+F":WR},_st="";function Gz(n){WR(n)}function Wz(n,t){const e=t.getImages(),r=t.getSelectedIndex();if(r!==-1){const i=document.createElement("a");i.href=n,i.download=e[r].src,i.click()}}function qz(n){return new Promise((t,e)=>{const r=new FileReader;r.onload=()=>{const i=r.result;t(i)},r.onerror=()=>{e(new Error("Failed to read Blob as string."))},r.readAsText(n)})}async function Xz(n){try{const e=(await navigator.clipboard.read())[0],r=e.types,i=new DataTransfer;for(let l=0;l<r.length;l++){const c=r[l],d=await e.getType(c),h=await qz(d);i.setData(c,h)}const o=n.dataConverter.fromData(n,i),s=new Q1(n);o.then(async l=>{l&&s.pasteDocs(l,null,[])})}catch{}}const Qz=I("is-clipboard-empty");async function Yz(){try{const n=await navigator.clipboard.readText(),e=(await navigator.clipboard.read())[0].types;return!n.trim()&&e.length===1&&e.includes("text/plain")}catch(n){return Qz.warn(`Failed to read clipboard data: ${n}`),!1}}class Zz{constructor(t){g(this,"t",D.t);g(this,"isSecureContext",T0());g(this,"getPasteCommandItem",async()=>{const t=await Yz(),e=this.isSecureContext&&!t,r=this.t("contextMenu.paste"),i=Ge("CtrlOrCmd+V");return{id:"paste",name:r,subText:i,states:e?[]:["disabled"],disableReason:this.isSecureContext?"":this.secureEnvTips(i,r)}});g(this,"getCommandItems",async()=>{const t=await this.getPasteCommandItem(),e=this.editor.readonly?[]:[this.cutCommandItem,t];return[...this.copyTypeCommandItems,...e,this.stepItem,...this.selectionCommandItems]});g(this,"isFocusImageBlock",()=>{const t=this.editor.selection,e=t.focusedBlock;return Ae(e)&&tn(e)==="image"&&t.range.getSelectedBlocks().length===1});this.editor=t}get isRangeCollapsed(){return this.editor.selection.range.isCollapsed()}get imageTypeCommandItems(){const t=this.isSecureContext;return[{id:"copy-image",name:this.t("contextMenu.copyImage"),subText:Ge("CtrlOrCmd+C"),states:t?[]:["disabled"],disableReason:this.isSecureContext?"":this.secureEnvTips(this.t("contextMenu.copyImage"),Ge("CtrlOrCmd+C"))},{id:"copy-image-url",name:this.t("contextMenu.copyImageUrl"),states:t?[]:["disabled"]},{id:"image-save-as",name:this.t("contextMenu.imageSaveAs")},{id:"new-tab-open-image",name:this.t("contextMenu.newTabOpenImage")}]}get copyTypeCommandItems(){const t=this.isSecureContext&&!this.isRangeCollapsed;if(this.isFocusImageBlock())return this.imageTypeCommandItems;const e=this.t("copyCutProperty.copy"),r=Ge("CtrlOrCmd+C"),i=[{id:"copy",name:e,subText:r,states:t?[]:["disabled"],disableReason:this.isSecureContext?"":this.secureEnvTips(r,e)}],o=this.t("contextMenu.copyMarkdown"),s=Ge("CtrlOrCmd+Shift+C");return i.push({id:"copy-markdown",name:o,subText:s,states:t?[]:["disabled"],disableReason:this.isSecureContext?"":this.secureEnvTips(s,o)}),i}get cutCommandItem(){let t=this.isSecureContext&&!this.isRangeCollapsed;const r=this.editor.selection.range.getSelectedBlocks().some(l=>!this.editor.isBlockWritable(l.block));r&&(t=!1);const i=this.t("copyCutProperty.cut"),o=Ge("CtrlOrCmd+X");let s="";return t||(this.isSecureContext?r&&(s=this.t("contextMenu.uneditableBlockSelected")):s=this.secureEnvTips(o,i)),{id:"cut",name:this.t("copyCutProperty.cut"),subText:Ge("CtrlOrCmd+X"),states:t?[]:["disabled"],disableReason:s}}get stepItem(){return{id:"step",name:"",type:"separator"}}get selectionCommandItems(){const t=this.isFocusImageBlock(),e=[{id:"select-block",name:this.t("contextMenu.selectBlock")}];return t||e.push({id:"select-all",name:this.t("contextMenu.selectAll")}),e}secureEnvTips(t,e){return this.t("copyCutProperty.unsafeEnvTips",{shortCut:t,operation:e})}}const Mst="";class XR{constructor(t){g(this,"contextMenu");g(this,"contextMenuCommandItems");g(this,"handleContextMenu",t=>{!this.editor.options.enableContextMenu||(this.isInEditor(t)||t.target.classList.contains("editor-disable-scroll"))&&t.preventDefault()});g(this,"isInMenu",t=>this.contextMenu.isInCommandBar(t.target));g(this,"isInEditor",t=>{const{clientX:e,clientY:r}=t,i=this.editor.rootElement,o=i.getBoundingClientRect(),{top:s,left:l,right:c,bottom:d}=o,h=e>=l&&e<=c&&r>=s&&r<=d,C=t.target instanceof HTMLElement&&i.contains(t.target);return h&&(this.isInMenu(t)||C)});g(this,"handleContextMenuShown",async()=>{const t=this.editor.getCustom("toolbar-handler");t&&t.hide();const e=await this.contextMenuCommandItems.getCommandItems();this.contextMenu.updateItems(e)});g(this,"handleContextMenuClick",(t,e)=>{const{id:r}=e;switch(r){case"copy":case"copy-markdown":X1(this.editor,{copyAsMarkdown:r==="copy-markdown"});break;case"cut":if(this.handleImageEmbedAction(r))break;X1(this.editor),uh(this.editor);break;case"paste":Xz(this.editor);break;case"copy-image":case"copy-image-url":case"image-save-as":case"new-tab-open-image":this.handleImageEmbedAction(r);break;case"select-all":mh(this.editor,this.editor.rootContainer);break;case"select-block":j1(this.editor);break}});this.editor=t,this.contextMenu=new qo([],void 0,{id:"right-context-menu"}),this.contextMenu.on("show",this.handleContextMenuShown),this.contextMenu.on("click",this.handleContextMenuClick),document.addEventListener("contextmenu",this.handleContextMenu),this.contextMenuCommandItems=new Zz(t)}show(t){this.contextMenu.manualShow(document.body,{theme:"light",point:{x:t.clientX,y:t.clientY}})}handleImageEmbedAction(t){const e=this.editor.selection.focusedBlock;if(Ae(e)&&tn(e)==="image"){const r=e,i=Se.getImageObject(this.editor,r),o=i.getSelectedIndex();if(o!==-1){let s=r.querySelectorAll("img")[o].src;if(s){switch(s=this.editor.doc.buildResourceUrl(s),t){case"cut":U0(this.editor,null),O0(this.editor);break;case"copy-image":U0(this.editor,null);break;case"copy-image-url":Fc([{type:"text/plain",data:new Blob([s],{type:"text/plain"})}]);break;case"image-save-as":Wz(s,i);break;case"new-tab-open-image":window.open(s);break}return!0}}}return!1}}const Jz={contextMenu:{copyMarkdown:"\u590D\u5236\u4E3A Markdown",paste:"\u7C98\u8D34",copyImage:"\u590D\u5236\u56FE\u7247",copyImageUrl:"\u590D\u5236\u56FE\u7247\u5730\u5740",imageSaveAs:"\u56FE\u7247\u53E6\u5B58\u4E3A",newTabOpenImage:"\u65B0\u6807\u7B7E\u9875\u6253\u5F00\u56FE\u7247",selectBlock:"\u9009\u4E2D\u533A\u5757",selectAll:"\u9009\u4E2D\u5168\u6587",uneditableBlockSelected:"\u5F85\u8865\u5145\u8BDD\u672F"}},tG={contextMenu:{copyMarkdown:"\u590D\u5236\u4E3A Markdown",paste:"paste",copyImage:"\u590D\u5236\u56FE\u7247",copyImageUrl:"\u590D\u5236\u56FE\u7247\u5730\u5740",imageSaveAs:"\u56FE\u7247\u53E6\u5B58\u4E3A",newTabOpenImage:"\u65B0\u6807\u7B7E\u9875\u6253\u5F00\u56FE\u7247",selectBlock:"\u9009\u4E2D\u533A\u5757",selectAll:"\u9009\u4E2D\u5168\u6587",uneditableBlockSelected:"\u5F85\u8865\u5145\u8BDD\u672F"}},eG={contextMenu:{copyMarkdown:"\u590D\u5236\u4E3A Markdown",paste:"\u7C98\u8D34",copyImage:"\u590D\u5236\u56FE\u7247",copyImageUrl:"\u590D\u5236\u56FE\u7247\u5730\u5740",imageSaveAs:"\u56FE\u7247\u53E6\u5B58\u4E3A",newTabOpenImage:"\u65B0\u6807\u7B7E\u9875\u6253\u5F00\u56FE\u7247",selectBlock:"\u9009\u4E2D\u533A\u5757",selectAll:"\u9009\u4E2D\u5168\u6587",uneditableBlockSelected:"\u5F85\u8865\u5145\u8BDD\u672F"}};D.mergeLang({"zh-CN":Jz,"en-US":tG,"ja-JP":eG});function CE(n,t){return t.map(e=>{var o,s;const r=Zt(n,e),i=(o=r.getBlockProperties)==null?void 0:o.call(r,n,e);return Ae(e)||_t(n,e)?i!=null&&i.abstract?`[${i.abstract}]`:"":(s=i==null?void 0:i.abstract)!=null?s:""}).join(" ")}function $0(n){const{editor:t,commentGroupId:e,abstract:r="text"}=n,i=tt(),o=t.doc.getUser(),s=Date.now(),l=e!=null?e:i;return{id:i,groupId:l,userId:o.userId,displayName:o.displayName,avatarUrl:o.avatarUrl,abstract:r,created:s,modified:s}}function QR(n,t,e){const r=e.id,o=n.getBlockData(t).comments;let s;o?s=[...o,r]:s=[r];const l={comments:s};n.updateBlockData(t,l)}function EE(n,t,e){const r=CE(n,[t]),i=$0({editor:n,abstract:r});QR(n,t,i);const o=Ji();return e.localCreateComment(i,o),i}const nG=I("standard-block-actions");class rG{constructor(t,e){g(this,"executeCommand",(t,e,r)=>{const i=r.data;try{this.editorComments.showCommentList();const o=t.getBlockById(i);EE(t,o,this.provider)}catch(o){nG.error(`failed to execute block command: ${JSON.stringify(o)}`)}});this.provider=t,this.editorComments=e}commands(t,e){const r=st(e);return{group:"block-comment-actions",commands:[{id:"comment",name:D.t("comment.quickMenuCommand"),data:r,order:100,states:t.readonly?["disabled"]:[]}],executeCommand:this.executeCommand}}}class iG{async handleBeforePasteDoc(t,e){return Object.values(e.blocks).forEach(r=>{r.forEach(i=>{delete i.comments,i.text&&i.text.forEach(o=>{if(o.attributes){const s=o.attributes;Object.keys(s).forEach(l=>{l.startsWith("comment-")&&delete s[l]})}})})}),!1}}var Jt=(n=>(n.SwitchUp="switch-up",n.SwitchDown="switch-down",n.CommentItemReply="comment-item-reply",n.CommentItemMore="comment-item-more",n.CommentItemOk="comment-item-ok",n.CommentItemCancel="comment-item-cancel",n.CommentItemDelete="comment-item-delete",n.CommentItemEdit="comment-item-edit",n.QuickReply="quick-reply",n.QuickReplyOk="quick-reply-ok",n.QuickReplyCancel="quick-reply-cancel",n))(Jt||{});const AE="group-item-action",YR="last-comment-item",oG="disabled",ZR=500;function qa(n){return n.id!==n.groupId}function JR(n,t=".comment-item-root"){return n.querySelectorAll(t).length}function sG(n){const t=n.closest(".comment-item-root");return t?t.id:null}function co(n,t){n.setAttribute(AE,t)}function lG(n){return n.closest(`[${AE}]`)}function aG(n){var t;return(t=n.getAttribute(AE))!=null?t:""}function cG(n){return n.disabled||n.classList.contains(oG)}function tw(n,t){const e=n.rootContainer.querySelector(`[comment-${t.toLocaleLowerCase()}=${t}]`);if(!e)return null;const r=e.closest('[data-type="editor-block"]');return r?r.id:null}function ew(n){return Array.from(n.attributes).map(e=>e.name).filter(e=>e.startsWith("comment-")).map(e=>e.replace("comment-",""))}const nw=I("doc-comments");function rw(n,t,e,r){if(t.comments){const o=t.comments;Array.isArray(o)&&o.forEach(s=>{r.has(s)||(r.add(s),e.push(s))})}t.text&&t.text.forEach(s=>{if(s.attributes){const l="comment-";Object.entries(s.attributes).forEach(([c,d])=>{if(c.startsWith(l)){const h=d;r.has(h)||(r.add(h),e.push(h))}})}});const i=t.children;!i||i.forEach(o=>{n.blocks[o].forEach(l=>{rw(n,l,e,r)})})}function uG(n){const t=[],e=new Set;n.blocks.root.forEach(i=>{rw(n,i,t,e)});const r=new Map;return t.forEach((i,o)=>r.set(i,o)),r}function fG(n){const t=new Map;n.forEach(i=>{if(qa(i)){const o=t.get(i.groupId);o?o.push(i):t.set(i.groupId,[i])}});const e=[];return n.forEach(i=>{var o;if(!qa(i)){const s=(o=t.get(i.id))!=null?o:[];t.delete(i.id);const l={...i,children:s};e.push(l)}}),Array.from(t.values()).forEach(i=>{const o=i[0],s=i.slice(1),l={...o,children:s};e.push(l)}),e}function is(n,t){const e=n.doc.toJSON(),r=uG(e);return fG(t.getComments()).filter(s=>r.has(s.groupId)).sort((s,l)=>{const c=r.get(s.groupId),d=r.get(l.groupId);return p(nw,c!==void 0,`comment not exists in doc, ${s.groupId}`),p(nw,d!==void 0,`comment not exists in doc, ${l.groupId}`),c-d})}function iw(n){const{children:t,...e}=n,r=[e];return t.forEach(i=>{r.push(i)}),r}function dG(n,t){return is(n,t).length}function xE(n,t){const e=[],r=n.getBlockById(t.blockId);if(et(n,r)){const o=t.blockId,s=t.offset,l=n.getBlockById(o),c=n.getBlockText(l),d=ca(c,s);d&&Object.entries(d).forEach(([h,C])=>{h.startsWith("comment-")&&e.push(C)})}const i=r.attributes;for(let o=0;o<i.length;o++){const s=i[o];s.name.startsWith("comment-")&&e.push(s.value)}return e}function ow(n){const t=n.selection.range;if(!t.isSimple())return[];if(t.start.blockId!==t.end.blockId)return[];if(t.isCollapsed())return xE(n,t.start);const{start:e,end:r}=t,i=xE(n,e),o=xE(n,r);return cg.default(i,o)}const hG=I("active-comments");function sw(n,t){n.rootContainer.querySelectorAll(`span.text.comment[comment-${t}],[data-type=editor-block].comment[comment-${t}]`).forEach(r=>{ot(r,"active")})}function lw(n,t,e){const r=n.rootContainer.querySelector("span.text.comment.active,[data-type=editor-block].comment.active");if(!t)r&&ew(r).forEach(o=>sw(n,o));else{const i=t.toLocaleLowerCase();if(r){const s=ew(r);if(s.length===1&&s[0]===i)return;s.forEach(l=>sw(n,l))}const o=n.rootContainer.querySelectorAll(`span.text.comment[comment-${i}],[data-type=editor-block].comment[comment-${i}]`);if(o.length){o.forEach(l=>{z(l,"active")});const s=o[0];if(Os(s)){const l=lt(s,0,"normal");n.selection.setSelection(l,void 0,{noScroll:e==="next"})}else if(ow(n).indexOf(t)===-1){const c=nt(s);p(hG,c,"block not found");const d=zs(c,s),h=lt(c,d.start,"normal");n.selection.setSelection(h,void 0,{noScroll:e==="next"})}if(n.focus(),e==="next"){const l=s.getBoundingClientRect(),c=n.scrollContainer.clientHeight;l.top>c/2&&Is(s,{elementToScroll:n.scrollContainer,verticalOffset:-n.scrollContainer.clientHeight/2})}}}}const Ust="";I("comment-editor");const{t:mG}=D,bE="comment-editor-readonly",uf="comment-editor-editing";class BE{constructor(t,e,r){g(this,"root");g(this,"components");g(this,"handleEditorBlur",()=>{this.inactiveEditor()});g(this,"handleEditorFocus",()=>{this.editor.readonly||this.activeEditor()});g(this,"activeEditor",()=>{kt(this.root,uf)||z(this.root,uf)});g(this,"inactiveEditor",()=>{ot(this.root,uf)});g(this,"handleInsertImg",async()=>{const{editor:t}=this.components,e=ft(t.rootContainer),r=await na("image/*",{}),i={src:"",widthPercent:50},o={id:tt(),type:"embed",embedType:"image",embedData:i},s=t.options.componentsOptions.image;s!=null&&s.defaultAlign&&(o.align=s.defaultAlign);const l=t.getFocusedBlock(),c=t.getBlockIndex(l),d=t.insertBlock(e,c+1,o);Se.getImageObject(t,d).replaceImage(0,r)});g(this,"handleReadonlyChange",t=>{t.readonly?(ot(this.root,uf),z(this.root,bE)):(z(this.root,uf),ot(this.root,bE))});g(this,"setDoc",t=>{const{components:{editor:e}}=this;e.doc.externalDoc.setDoc(t)});g(this,"getDoc",()=>{const{components:{editor:t}}=this;return t.doc.toJSON()});g(this,"isEmpty",()=>d1(this.getDoc()));g(this,"edit",()=>{const{editor:t}=this.components;t.readonly=!1,V1(t),this.activeEditor()});g(this,"clear",()=>{const t=Ji();this.setDoc(t)});g(this,"readonly",()=>{const{editor:t}=this.components;t.readonly=!0});g(this,"destroy",()=>{const{root:t,components:{editor:e,insertImgButton:r}}=this;r.onclick=null,e.destroy(),t.remove()});this.mainEditor=t,this.commentsProvider=e,this.doc=r,this.root=v("div",["comment-editor",bE],null),this.components=this.createEditor()}createEditor(){const t=v("div",["comment-editor-root"],this.root),{commentsProvider:e,mainEditor:r}=this,i=e.createCommentEditor(t,new Y1(this.doc));i.readonly=!0,i.addListener("readonlyChanged",this.handleReadonlyChange),i.addListener("focus",this.handleEditorFocus),i.addListener("blur",this.handleEditorBlur);const o=sl(this.root,"comment-editor-img",mG("comment.image"),M2,void 0,r.clientId);return o.classList.add("comment-editor-img"),o.onclick=this.handleInsertImg,{editor:i,insertImgButton:o}}get editor(){return this.components.editor}}class gG{constructor(t){g(this,"handleBeforeKeyDown",(t,e)=>{if(oi(e,"Enter")){const{quickReply:r,updateLastCommentItem:i}=this.groupItem;return r.getReplyEditor().isEmpty()?(r.hideReplyEditor(),!0):(r.reply(),i(),!0)}return!1});this.groupItem=t}}class pG{constructor(t,e,r){g(this,"handleBeforeKeyDown",(t,e)=>{if(oi(e,"Enter")){const{quickReply:r}=this.groupItem,{comment:i,getCommentEditor:o}=this.commentItem,s=o();if(s.isEmpty())this.commentsProvider.localDeleteComment(i.id);else{const l=s.getDoc();this.commentsProvider.localUpdateComment(i,l),s.readonly()}return r.show(),!0}return!1});this.commentsProvider=t,this.groupItem=e,this.commentItem=r}}const CG=`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
684
684
|
<path fill-rule="evenodd" clip-rule="evenodd" d="M3.65499 6.6665C3.09433 6.6665 2.66699 7.1275 2.66699 7.67617C2.66699 8.2255 3.02633 8.64284 3.65499 8.6645C4.23833 8.6645 4.66399 8.26917 4.66399 7.67617C4.66399 7.1275 4.23899 6.6665 3.65499 6.6665ZM12.9883 6.6665C12.4277 6.6665 12.0003 7.1275 12.0003 7.67617C12.0003 8.2255 12.3597 8.64284 12.9883 8.6645C13.5717 8.6645 13.9973 8.26917 13.9973 7.67617C13.9973 7.1275 13.5723 6.6665 12.9883 6.6665ZM8.32166 6.6665C7.76099 6.6665 7.33399 7.1275 7.33399 7.67617C7.33399 8.2255 7.69299 8.64284 8.32166 8.6645C8.90499 8.6645 9.33066 8.26917 9.33066 7.67617C9.33066 7.1275 8.90566 6.6665 8.32166 6.6665Z" fill="currentColor"></path>
|
|
685
685
|
</svg>`,EG=`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
686
686
|
<path d="M2 4V11C2 11.5523 2.44772 12 3 12H10L12.5528 13.2764C13.2177 13.6088 14 13.1253 14 12.382V4C14 3.44772 13.5523 3 13 3H3C2.44772 3 2 3.44772 2 4Z" stroke="currentColor"/>
|