showai-reader 0.11.0-reader.ns6oez2y → 0.11.0-reader.q7rotyau

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/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  The [ShowAI](https://showai.renaissancemind.ai) page reader, built from ShowAI 0.11.0 as code-split ES modules. Inline conversation pages written by `render-artifact --cdn` import it and load each component's code only when the page uses it.
4
4
 
5
5
  ```js
6
- const { mount } = await import("https://cdn.jsdelivr.net/npm/showai-reader@0.11.0-reader.ns6oez2y/index.js");
6
+ const { mount } = await import("https://cdn.jsdelivr.net/npm/showai-reader@0.11.0-reader.q7rotyau/index.js");
7
7
  mount(document.getElementById("page"), { artifact });
8
8
  ```
9
9
 
@@ -151,7 +151,7 @@ ${n}
151
151
  `);if(i.length<2)return;let s=i[1];if(!/^[ \t|:]*-[ \t|:-]*$/.test(s)||!s.includes("|"))return;let l=A1(o);if(l===o)return;let a=n.blockTokens(l)[0];if(a?.type!=="table"||!a.raw)return;let u=a.raw.split(`
152
152
  `).length,c=e.split(`
153
153
  `).slice(0,u).join(`
154
- `);return{...a,raw:c}}},addCommands(){return{insertTable:({rows:e=3,cols:t=3,withHeaderRow:n=!0}={})=>({tr:r,dispatch:o,editor:i})=>{let s=E1(i.schema,e,t,n);if(o){let l=r.selection.from+1;r.replaceSelectionWith(s).scrollIntoView().setSelection(L.near(r.doc.resolve(l)))}return!0},addColumnBefore:()=>({state:e,dispatch:t})=>Mh(e,t),addColumnAfter:()=>({state:e,dispatch:t})=>Ah(e,t),deleteColumn:()=>({state:e,dispatch:t})=>{let n=Er(e.selection.$from,r=>r.type.name==="table");return Th(e,t&&(r=>{n&&$g(r,n.pos),t(r)}))},addRowBefore:()=>({state:e,dispatch:t})=>Rh(e,t),addRowAfter:()=>({state:e,dispatch:t})=>Dh(e,t),deleteRow:()=>({state:e,dispatch:t})=>{let n=Er(e.selection.$from,r=>r.type.name==="table");return Oh(e,t&&(r=>{n&&$g(r,n.pos),t(r)}))},deleteTable:()=>({state:e,dispatch:t})=>Ih(e,t),mergeCells:()=>({state:e,dispatch:t})=>Ba(e,t),splitCell:()=>({state:e,dispatch:t})=>za(e,t),toggleHeaderColumn:()=>({state:e,dispatch:t})=>Or("column")(e,t),toggleHeaderRow:()=>({state:e,dispatch:t})=>Or("row")(e,t),toggleHeaderCell:()=>({state:e,dispatch:t})=>Ph(e,t),mergeOrSplit:()=>({state:e,dispatch:t})=>Ba(e,t)?!0:za(e,t),setCellAttribute:(e,t)=>({state:n,dispatch:r})=>Lh(e,t)(n,r),goToNextCell:()=>({state:e,dispatch:t})=>Ha(1)(e,t),goToPreviousCell:()=>({state:e,dispatch:t})=>Ha(-1)(e,t),fixTables:()=>({state:e,dispatch:t})=>(t&&$a(e),!0),setCellSelection:e=>({tr:t,dispatch:n})=>{if(n){let r=se.create(t.doc,e.anchorCell,e.headCell);t.setSelection(r)}return!0}}},addKeyboardShortcuts(){return{Tab:()=>this.editor.commands.goToNextCell()?!0:this.editor.can().addRowAfter()?this.editor.chain().addRowAfter().goToNextCell().run():!1,"Shift-Tab":()=>this.editor.commands.goToPreviousCell(),Backspace:Ps,"Mod-Backspace":Ps,Delete:Ps,"Mod-Delete":Ps}},addProseMirrorPlugins(){return[...this.options.resizable&&this.editor.isEditable?[Bh({handleWidth:this.options.handleWidth,cellMinWidth:this.options.cellMinWidth,defaultCellMinWidth:this.options.cellMinWidth,View:this.options.View,lastColumnResizable:this.options.lastColumnResizable})]:[],Hh({allowTableNodeSelection:this.options.allowTableNodeSelection}),P1()]},addNodeView(){let e=this.options.resizable&&this.editor.isEditable,t=this.options.View;return e||!t?null:({node:n,view:r,HTMLAttributes:o})=>{let i=K(this.options.HTMLAttributes,o);return new t(n,this.options.cellMinWidth,r,i)}},extendNodeSchema(e){let t={name:e.name,options:e.options,storage:e.storage};return{tableRole:de(B(e,"tableRole",t))}}}),Fg=le.create({name:"tableKit",addExtensions(){let e=[];return this.options.table!==!1&&e.push(I1.configure(this.options.table)),this.options.tableCell!==!1&&e.push(k1.configure(this.options.tableCell)),this.options.tableHeader!==!1&&e.push(v1.configure(this.options.tableHeader)),this.options.tableRow!==!1&&e.push(C1.configure(this.options.tableRow)),e}});var Wg=As;var Kg=Ms;var $1=/(?:^|\s)(==(?!\s+==)((?:[^=]+))==(?!\s+==))$/,B1=/(?:^|\s)(==(?!\s+==)((?:[^=]+))==(?!\s+==))/g,z1=He.create({name:"highlight",addOptions(){return{multicolor:!1,HTMLAttributes:{}}},addAttributes(){return this.options.multicolor?{color:{default:null,parseHTML:e=>e.getAttribute("data-color")||Np(e,"background-color")||e.style.backgroundColor,renderHTML:e=>Tr(e.color)?{"data-color":e.color,style:`background-color: ${e.color}; color: inherit`}:{}}}:{}},parseHTML(){return[{tag:"mark"}]},renderHTML({HTMLAttributes:e}){return["mark",K(this.options.HTMLAttributes,e),0]},renderMarkdown:(e,t)=>`==${t.renderChildren(e)}==`,parseMarkdown:(e,t)=>t.applyMark("highlight",t.parseInline(e.tokens||[])),markdownTokenizer:{name:"highlight",level:"inline",start:e=>e.indexOf("=="),tokenize(e,t,n){let r=/^(==)([^=]+)(==)/.exec(e);if(r){let o=r[2].trim(),i=n.inlineTokens(o);return{type:"highlight",raw:r[0],text:o,tokens:i}}}},addCommands(){return{setHighlight:e=>({commands:t})=>t.setMark(this.name,e),toggleHighlight:e=>({commands:t})=>t.toggleMark(this.name,e),unsetHighlight:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-Shift-h":()=>this.editor.commands.toggleHighlight()}},addInputRules(){return[st({find:$1,type:this.type})]},addPasteRules(){return[rt({find:B1,type:this.type})]}}),Ug=z1;var qg=Ug.extend({addAttributes(){let e={...this.parent?.(),mode:{default:"lower",parseHTML:t=>t.getAttribute("data-highlight-mode")==="full"?"full":"lower",renderHTML:({mode:t})=>({"data-highlight-mode":t==="full"?"full":"lower"})}};return this.options.multicolor?{...e,color:{...e.color,renderHTML:({color:t})=>t?{"data-color":t,style:`--showai-highlight-color: ${t}`}:{}}}:e}});var H1=le.create({name:"textAlign",addOptions(){return{types:[],alignments:["left","center","right","justify"],defaultAlignment:null}},addGlobalAttributes(){return[{types:this.options.types,attributes:{textAlign:{default:this.options.defaultAlignment,parseHTML:e=>{let t=e.style.textAlign;return this.options.alignments.includes(t)?t:this.options.defaultAlignment},renderHTML:e=>!Tr(e.textAlign)||!this.options.alignments.includes(e.textAlign)?{}:{style:`text-align: ${e.textAlign}`}}}}]},addCommands(){return{setTextAlign:e=>({commands:t})=>this.options.alignments.includes(e)?this.options.types.map(n=>t.updateAttributes(n,{textAlign:e})).some(n=>n):!1,unsetTextAlign:()=>({commands:e})=>this.options.types.map(t=>e.resetAttributes(t,"textAlign")).some(t=>t),toggleTextAlign:e=>({editor:t,commands:n})=>this.options.alignments.includes(e)?t.isActive({textAlign:e})?n.unsetTextAlign():n.setTextAlign(e):!1}},addKeyboardShortcuts(){return{"Mod-Shift-l":()=>this.editor.commands.setTextAlign("left"),"Mod-Shift-e":()=>this.editor.commands.setTextAlign("center"),"Mod-Shift-r":()=>this.editor.commands.setTextAlign("right"),"Mod-Shift-j":()=>this.editor.commands.setTextAlign("justify")}}}),Gg=H1;var Jg=le.create({name:"dropCursorCleanup",addProseMirrorPlugins(){return[new q({view(e){let t=e.dom.ownerDocument,n=t.defaultView,r=()=>{let o=t.createEvent("Event");o.initEvent("dragleave",!1,!1),e.dom.dispatchEvent(o)};return t.addEventListener("drop",r,!0),t.addEventListener("dragend",r,!0),n?.addEventListener("blur",r),{destroy(){t.removeEventListener("drop",r,!0),t.removeEventListener("dragend",r,!0),n?.removeEventListener("blur",r)}}}})]}});var rr=pe(zt(),1);var fe=pe(Fe(),1);function Xg({node:e,updateAttributes:t,editor:n,selected:r,getPos:o}){let{renderWidget:i}=(0,rr.useContext)(Uo),s=fo({editor:n,selector:({editor:l})=>l.isEditable});return(0,fe.jsx)(qn,{className:`document-widget${r&&s?" is-selected":""}`,"data-widget-kind":e.attrs.kind,"data-block-id":e.attrs.id??void 0,onPointerDownCapture:l=>{if(!s||l.button!==0||l.shiftKey||l.metaKey||l.ctrlKey)return;if(rl(l.target,l.clientX,l.clientY)){let u=Dr(n.state);u&&n.view.dispatch(u);return}let a=o();!r&&typeof a=="number"&&n.commands.setNodeSelection(a)},onClick:l=>{if(!s||l.button!==0||l.shiftKey||l.metaKey||l.ctrlKey)return;if(rl(l.target,l.clientX,l.clientY)||l.target.closest('[data-text-selection="true"]')){l.stopPropagation();return}let a=o();typeof a=="number"&&(n.commands.setNodeSelection(a),l.stopPropagation())},children:(0,fe.jsx)(ju,{id:e.attrs.id,children:i({kind:e.attrs.kind,data:e.attrs.data,onChange:l=>{n.isEditable&&t({data:Ko(l)})},readOnly:!s})})})}var Pc=["\u{1F4A1}","\u{1F331}","\u{1F4CC}","\u2728","\u26A0\uFE0F","\u{1F50E}"],Ic=["sage","sand","blue","rose"];function Yg({node:e,updateAttributes:t,editor:n}){let r=Re(ze),o=fo({editor:n,selector:({editor:i})=>i.isEditable});return(0,fe.jsxs)(qn,{style:rn(e.attrs.componentStyle),className:`document-callout tone-${e.attrs.tone}`,"data-block-id":e.attrs.id??void 0,children:[(0,fe.jsxs)("div",{className:"callout-decoration",contentEditable:!1,children:[(0,fe.jsx)("button",{className:"callout-icon",disabled:!o,title:r("callout.changeIcon"),"aria-label":r("callout.changeIconLabel"),onClick:()=>t({icon:Pc[(Pc.indexOf(e.attrs.icon)+1)%Pc.length]}),children:e.attrs.icon}),o&&(0,fe.jsx)("button",{className:"callout-color",title:r("callout.changeColor"),"aria-label":r("callout.changeColorLabel"),onClick:()=>t({tone:Ic[(Ic.indexOf(e.attrs.tone)+1)%Ic.length]})})]}),(0,fe.jsxs)("div",{children:[e.attrs.title&&(0,fe.jsx)("strong",{children:e.attrs.title}),(0,fe.jsx)(Mi,{className:"callout-content"})]})]})}function Qg({node:e,updateAttributes:t,editor:n}){let r=Re(ze),o=fo({editor:n,selector:({editor:c})=>c.isEditable}),[i,s]=(0,rr.useState)(!!e.attrs.open);(0,rr.useEffect)(()=>s(!!e.attrs.open),[e.attrs.open]);let[l,a]=ol("open",!!e.attrs.open,{block:e.attrs.id??null,accept:c=>typeof c=="boolean"}),u=o?i:l;return(0,fe.jsxs)(qn,{style:rn(e.attrs.componentStyle),className:`document-toggle${u?" is-open":""}`,"data-block-id":e.attrs.id??void 0,children:[(0,fe.jsxs)("div",{className:"toggle-heading",contentEditable:!1,children:[(0,fe.jsx)("button",{"aria-label":r(u?"toggle.collapse":"toggle.expand"),"aria-expanded":u,onClick:()=>{if(!n.isEditable)return a(!u);s(!u),t({open:!u})},children:(0,fe.jsx)(Po,{size:16})}),o?(0,fe.jsx)("input",{"aria-label":r("toggle.titleLabel"),value:e.attrs.title,onChange:c=>t({title:c.target.value}),placeholder:r("toggle.titlePlaceholder")}):(0,fe.jsx)("span",{children:e.attrs.title})]}),(0,fe.jsx)("div",{className:"toggle-body",hidden:!u,children:(0,fe.jsx)(Mi,{})})]})}function Zg({node:e,editor:t,getPos:n}){let r=Re(ze),o=fo({editor:t,selector:({editor:b})=>b.isEditable}),[i,s]=ol("step",0,{block:e.attrs.id??null,accept:Number.isInteger}),l=e.childCount,a=Math.min(i,l-1),u=Array.from({length:l},(b,k)=>Gu(e.child(k).attrs.title,k)),c=()=>{let b=n();if(typeof b!="number")throw new Error("The stepper is detached.");return b+1},d=b=>{let k=c();for(let C=0;C<b;C+=1)k+=e.child(C).nodeSize;return k};(0,rr.useEffect)(()=>{let b=()=>{let k=n(),C=typeof k=="number"?t.state.doc.nodeAt(k):null;if(!C||C.type.name!=="stepper")return;let{from:S}=t.state.selection;if(S<=k||S>=k+C.nodeSize)return;let M=k+1;for(let T=0;T<C.childCount;T+=1)if(M+=C.child(T).nodeSize,S<M)return s(T)};return t.on("selectionUpdate",b),()=>{t.off("selectionUpdate",b)}},[t,n]);let f=b=>{let{tr:k}=t.state,C=b(k);return t.view.dispatch(k),s(C),C},p=b=>f(k=>(k.setNodeMarkup(d(a),void 0,{...e.child(a).attrs,title:b}),a)),h=()=>{f(b=>{let{schema:k}=t.state,C=d(a)+e.child(a).nodeSize;return b.insert(C,k.nodes.step.create({title:""},k.nodes.paragraph.create())),b.setSelection(L.create(b.doc,C+2)),a+1}),t.view.focus()},g=()=>f(b=>{let k=d(a);return b.delete(k,k+e.child(a).nodeSize),Math.max(0,a-1)}),m=b=>f(k=>{let C=a+b,S=e.child(a),M=d(a),T=b<0?d(C):d(C)+e.child(C).nodeSize;return k.delete(M,M+S.nodeSize),k.insert(k.mapping.map(T),S),C});return(0,fe.jsxs)(qn,{style:rn(e.attrs.componentStyle),className:"document-stepper","data-block-id":e.attrs.id??void 0,children:[(0,fe.jsx)(Ju,{titles:u,active:a,onSelect:s}),o&&(0,fe.jsxs)("div",{className:"stepper-edit",contentEditable:!1,children:[(0,fe.jsx)("input",{"aria-label":r("stepper.titleLabel"),placeholder:r("stepper.titlePlaceholder"),value:e.child(a).attrs.title??"",onChange:b=>p(b.target.value)}),(0,fe.jsx)("button",{type:"button",title:r("stepper.moveEarlier"),"aria-label":r("stepper.moveEarlier"),disabled:a===0,onClick:()=>m(-1),children:"\u21A4"}),(0,fe.jsx)("button",{type:"button",title:r("stepper.moveLater"),"aria-label":r("stepper.moveLater"),disabled:a===l-1,onClick:()=>m(1),children:"\u21A6"}),(0,fe.jsx)("button",{type:"button",title:r("stepper.add"),"aria-label":r("stepper.add"),disabled:l>=Iu,onClick:h,children:"+"}),(0,fe.jsx)("button",{type:"button",title:r("stepper.remove"),"aria-label":r("stepper.remove"),disabled:l<=1,onClick:g,children:"\xD7"})]}),(0,fe.jsx)(Mi,{className:"stepper-steps","data-active":a})]})}function eb({node:e,updateAttributes:t,editor:n,selected:r}){let o=Re(ze),i=e.type.name==="mathBlock"||e.attrs.display;return qu(),(0,fe.jsxs)(qn,{as:i?"div":"span",className:i?"sb-math-display":"sb-math-inline",contentEditable:!1,children:[(0,fe.jsx)("span",{dangerouslySetInnerHTML:{__html:Lu(e.attrs.latex,i)}}),r&&n.isEditable&&(0,fe.jsx)("input",{"aria-label":o("math.source"),value:e.attrs.latex,onChange:s=>t({latex:s.target.value}),onKeyDown:s=>{s.key==="Escape"&&(s.preventDefault(),n.commands.focus())}})]})}function tb({node:e}){return(0,fe.jsx)(qn,{"data-block-id":e.attrs.id,"data-drag-handle":!0,contentEditable:!1,children:(0,fe.jsx)(Wu,{attrs:e.attrs})})}var Bc=["paragraph","heading","blockquote","bulletList","orderedList","listItem","taskList","taskItem","codeBlock","hardBreak","horizontalRule","image","table","tableRow","tableCell","tableHeader","callout","toggle","stepper","step","widget","mathInline","mathBlock"],$s=new oe("showaiBlockIds");function _1(e){let t=new Set([...Bc,"region","richText","pageModule"]);return new q({key:$s,appendTransaction(n,r,o){if(!e()||!n.some(l=>l.docChanged||l.getMeta($s)||l.getMeta("editableChanged")))return null;let i=new Set,s=o.tr;return o.doc.descendants((l,a)=>{if(!t.has(l.type.name))return;let u=l.attrs.id;if(typeof u=="string"&&u.trim()&&!i.has(u)){i.add(u);return}let c;do c=globalThis.crypto.randomUUID();while(i.has(c));i.add(c),s.setNodeAttribute(a,"id",c)}),s.docChanged?s.setMeta($s,!0).setMeta("addToHistory",!1):null}})}var V1=le.create({name:"showaiStableBlockIds",addOptions:()=>({readOnly:!1}),addGlobalAttributes(){return[{types:[...Bc,"region","richText","pageModule"],attributes:{id:{default:null,parseHTML:e=>e.getAttribute("data-block-id"),renderHTML:e=>typeof e.id=="string"&&e.id.trim()?{"data-block-id":e.id}:{}}}}]},addProseMirrorPlugins(){return[_1(()=>!this.options.readOnly&&this.editor.isEditable)]},onCreate(){!this.options.readOnly&&this.editor.isEditable&&this.editor.view.dispatch(this.editor.state.tr.setMeta($s,!0).setMeta("addToHistory",!1))}}),j1=ie.create({name:"widget",group:"block",atom:!0,draggable:!0,addAttributes(){return{kind:{default:"chart"},data:{default:{},parseHTML:e=>{let t=e.getAttribute("data-widget-content");if(!t)return{};try{return JSON.parse(t)}catch{return{}}},renderHTML:e=>({"data-widget-content":JSON.stringify(e.data)})}}},parseHTML:()=>[{tag:"div[data-showai-widget]"}],renderHTML:({HTMLAttributes:e})=>["div",K(e,{"data-showai-widget":""})],addNodeView:()=>Gn(Xg)}),F1=ie.create({name:"callout",group:"block",content:"block+",defining:!0,draggable:!0,addAttributes:()=>({icon:{default:"\u{1F4A1}"},tone:{default:"sage"},title:{default:""}}),parseHTML:()=>[{tag:"aside[data-callout]"}],renderHTML:({HTMLAttributes:e})=>["aside",K(e,{"data-callout":""}),0],addNodeView:()=>Gn(Yg)}),W1=ie.create({name:"toggle",group:"block",content:"block+",defining:!0,draggable:!0,addAttributes:()=>({title:{default:"\u5C55\u5F00\u4E86\u89E3\u66F4\u591A"},open:{default:!0}}),parseHTML:()=>[{tag:"section[data-toggle]"}],renderHTML:({HTMLAttributes:e})=>["section",K(e,{"data-toggle":""}),0],addNodeView:()=>Gn(Qg)}),K1=ie.create({name:"stepper",group:"block",content:"step+",defining:!0,draggable:!0,isolating:!0,parseHTML:()=>[{tag:"section[data-stepper]"}],renderHTML:({HTMLAttributes:e})=>["section",K(e,{"data-stepper":""}),0],addNodeView:()=>Gn(Zg)}),U1=ie.create({name:"step",content:"block+",defining:!0,isolating:!0,addAttributes:()=>({title:{default:""}}),parseHTML:()=>[{tag:"section[data-step]"}],renderHTML:({HTMLAttributes:e})=>["section",K(e,{"data-step":""}),0]}),q1=ie.create({name:"richText",priority:50,group:"block",content:"block*",defining:!0,addAttributes:()=>({id:{default:null},name:{default:"\u5BCC\u6587\u672C"},data:{default:{},parseHTML:e=>JSON.parse(e.getAttribute("data-rich-text-settings")||"{}"),renderHTML:()=>({})}}),parseHTML:()=>[{tag:'div[data-component-kind="text"]'},{tag:'div[data-page-flow="richText"]'}],renderHTML:({node:e,HTMLAttributes:t})=>["div",K(t,{"data-component-kind":"text","data-rich-text-settings":JSON.stringify(e.attrs.data),class:"page-document-flow rich-text-component",style:Object.entries(rn(e.attrs.data)).filter(([,n])=>n!==void 0).map(([n,r])=>`${n.replace(/[A-Z]/g,o=>"-"+o.toLowerCase())}:${typeof r=="number"?`${r}px`:r}`).join(";")}),0]}),G1=He.create({name:"textStyle",addAttributes:()=>Object.fromEntries(["color","fontFamily","fontSize"].map(e=>[e,{default:null,parseHTML:t=>t.style[e],renderHTML:t=>t[e]?{style:`${e.replace(/[A-Z]/g,n=>"-"+n.toLowerCase())}: ${t[e]}`}:{}}])),parseHTML:()=>[{tag:"span[style]"}],renderHTML:({HTMLAttributes:e})=>["span",K(e),0]}),J1=He.create({name:"annotation",inclusive:!1,addAttributes:()=>({note:{default:"",parseHTML:e=>e.getAttribute("data-showai-note")??"",renderHTML:e=>({"data-showai-note":e.note??""})}}),parseHTML:()=>[{tag:"span[data-showai-note]"}],renderHTML:({HTMLAttributes:e})=>["span",K({class:"showai-note"},e),0]}),nb=e=>ie.create({name:e?"mathInline":"mathBlock",group:e?"inline":"block",inline:e,atom:!0,addAttributes:()=>({latex:{default:""},display:{default:!e}}),parseHTML:()=>[{tag:e?"span[data-math]":"div[data-math]"}],renderHTML:({node:t,HTMLAttributes:n})=>[e?"span":"div",{...n,"data-math":t.attrs.latex}],addNodeView:()=>Gn(eb)}),rb=ur(ze);function ob(e={}){return[X1,q1,G1,J1,nb(!0),nb(!1),V1.configure({readOnly:e.readOnly??!1}),Jg,og.configure({trailingNode:e.trailingNode===!1?!1:{},heading:{levels:[1,2,3,4,5,6]},link:{openOnClick:e.readOnly??!1,HTMLAttributes:{rel:"noopener noreferrer",target:"_blank"},isAllowedUri:(t,n)=>!!lr(t)||n.defaultValidate(t)},codeBlock:!1}),Dg,Og.configure({placeholder:({node:t,editor:n})=>t.type.name==="heading"?rb("placeholderHeading"):typeof e.placeholder=="function"?e.placeholder({empty:n.isEmpty}):e.placeholder??rb("placeholderDefault"),includeChildren:!1}),Lg.extend({addNodeView:()=>Gn(tb)}).configure({allowBase64:!0,HTMLAttributes:{class:"document-image"}}),Fg.configure({table:{resizable:!0,View:$c}}),Wh,Wg,Kg.configure({nested:!0}),qg.configure({multicolor:!0}),Gg.configure({types:["heading","paragraph"]}),F1,W1,K1,U1,j1]}var X1=le.create({name:"showaiContentAttributes",addGlobalAttributes(){let e=t=>({default:null,parseHTML:n=>{let r=n.getAttribute(`data-content-${t.toLowerCase()}`);if(r===null)return null;try{return t==="title"?r:JSON.parse(r)}catch{return null}},renderHTML:n=>n[t]==null?{}:{[`data-content-${t.toLowerCase()}`]:t==="title"?String(n[t]):JSON.stringify(n[t]),...t==="componentStyle"?{style:Object.entries({...rn(n[t]),borderTopColor:n[t]?.color}).filter(([,r])=>r!==void 0).map(([r,o])=>`${r.replace(/[A-Z]/g,i=>`-${i.toLowerCase()}`)}:${typeof o=="number"?`${o}px`:o}`).join(";")}:{}}});return[{types:Bc,attributes:{name:{...e("name"),default:"",parseHTML:t=>{let n=e("name").parseHTML(t);return typeof n=="string"?n:""}}}},{types:["image","codeBlock","table","callout","toggle","stepper","horizontalRule"],attributes:{componentStyle:e("componentStyle")}},{types:["image"],attributes:Object.fromEntries(["caption","fit","nativeInk","width","height","align"].map(t=>[t,e(t)]))},{types:["table"],attributes:{title:e("title")}}]}}),$c=class extends Lc{constructor(...t){super(...t),this.syncMetadata()}syncMetadata(){let t=rn(this.node.attrs.componentStyle);this.dom.style.cssText="",Object.assign(this.dom.style,Object.fromEntries(Object.entries(t).filter(([,r])=>r!==void 0).map(([r,o])=>[r,typeof o=="number"?`${o}px`:o]))),this.node.attrs.id&&(this.table.dataset.blockId=this.node.attrs.id);let n=this.node.attrs.title;if(n){let r=this.table.caption??this.table.createCaption();r.textContent=n}else this.table.caption?.remove();this.dom.tabIndex=0}update(t){return super.update(t)?(this.syncMetadata(),!0):!1}};var v=pe(Fe(),1),ib=new WeakSet,sb=ur(ze);function Y1({children:e,className:t,onDismiss:n}){return(0,v.jsx)("div",{className:t,onMouseDown:r=>{r.target===r.currentTarget&&n()},children:e})}function Bt({label:e,children:t,onClick:n,active:r,disabled:o}){return(0,v.jsx)("button",{type:"button",className:`editor-tool${r?" is-active":""}`,"aria-label":e,title:e,"aria-pressed":r,disabled:o,onMouseDown:i=>i.preventDefault(),onClick:n,children:t})}function Q1(e){return/^https?:\/\//i.test(e)||/^data:image\/(png|jpe?g|gif|webp|avif);base64,/i.test(e)}function lb(e){return/^(https?:\/\/|mailto:|tel:|#)/i.test(e)||!!lr(e)}function Hc(e){return e.startsWith("page-tail-")}function _c(e,t){let n=e.view.coordsAtPos(Math.min(t,e.state.doc.content.size));return{left:Math.max(12,Math.min(n.left,window.innerWidth-340)),top:Math.max(70,Math.min(n.bottom+8,window.innerHeight-370))}}function Z1({content:e,onChange:t,readOnly:n=!1,minimal:r=!0,onEditorReady:o,onInsertNative:i,onDetachBlock:s,additionalExtensions:l,trailingNode:a=!0,retentionKey:u}){let c=Re(ze),d=Re(Vu),f=Re(Go),p=(0,P.useRef)(t),h=(0,P.useId)();p.current=t;let g=(0,P.useRef)(null),m=(0,P.useRef)(null),b=(0,P.useRef)(null),k=(0,P.useRef)(null),C=(0,P.useRef)(null),S=(0,P.useRef)([]),M=(0,P.useRef)(()=>{}),T=(0,P.useRef)(0),E=(0,P.useRef)(null),[O,X]=(0,P.useState)(null),{useCatalog:he,registerComponent:Ne,assistant:$e,pageLinks:xe}=(0,P.useContext)(Uo),_e=(0,P.useRef)(xe);_e.current=xe;let Me=he(!!O),[N,_]=(0,P.useState)(!1),ee=(0,P.useRef)(0);(0,P.useEffect)(()=>()=>{ee.current++},[]);let[ue,Se]=(0,P.useState)(0),[Y,Ve]=(0,P.useState)(null),[Ze,me]=(0,P.useState)(!1),je=(0,P.useRef)(null),zr=(0,P.useRef)(Ze);zr.current=Ze;let wn=(0,P.useRef)(0),Hr=(0,P.useRef)(0);(0,P.useEffect)(()=>()=>cancelAnimationFrame(wn.current),[]);let Ct=(0,P.useCallback)(()=>{je.current!==null&&(clearTimeout(je.current),je.current=null)},[]),Do=(0,P.useCallback)(()=>{je.current===null&&(je.current=setTimeout(()=>{je.current=null;let y=g.current?.querySelector(".block-handle");zr.current||E.current!==null||y?.contains(document.activeElement)||Ve(null)},450))},[]);(0,P.useEffect)(()=>Ct,[Ct]);let[kn,tn]=(0,P.useState)(!1),[xt,at]=(0,P.useState)(!1),[U,Le]=(0,P.useState)(null),[St,J]=(0,P.useState)(null),[_r,Ce]=(0,P.useState)(""),[ge,yt]=(0,P.useState)(""),[qe,et]=(0,P.useState)(null);(0,P.useEffect)(()=>{!qe&&St&&(Le(null),J(null))},[!!qe,St]);let Et=(0,P.useRef)(null),D=(0,P.useRef)(!1),[,z]=(0,P.useState)(0),G=(0,P.useRef)(null);k.current=O,T.current=ue;let be=(0,P.useMemo)(()=>[...ob({placeholder:({empty:y})=>sb(y&&!a?"placeholderPage":"placeholder"),trailingNode:a}),...l??[]],[l,a]);(0,P.useLayoutEffect)(()=>{if(!Ze)return;let y=g.current,x=y?.querySelector(".block-menu"),A=y?.querySelector(".block-handle");if(!x||!A)return;let $=()=>{let F=A.getBoundingClientRect(),ne=x.getBoundingClientRect();Object.assign(x.style,{position:"fixed",left:`${Math.max(12,Math.min(F.right,window.innerWidth-ne.width-12))}px`,top:`${Math.max(12,Math.min(F.top,window.innerHeight-ne.height-12))}px`})};$();let I=new ResizeObserver($);return I.observe(x),window.addEventListener("resize",$),window.addEventListener("scroll",$,!0),()=>{I.disconnect(),window.removeEventListener("resize",$),window.removeEventListener("scroll",$,!0)}},[Ze,Y?.pos]);let w=sh({retentionKey:u,extensions:be,content:e,editable:!n,immediatelyRender:!1,shouldRerenderOnTransaction:!1,editorProps:{attributes:{class:"document-content","aria-label":sb("documentContent"),spellcheck:"false"},handleKeyDown:(y,x)=>{if(x.isComposing)return!1;if(x.key==="Escape"&&!k.current&&!y.state.selection.empty)return Et.current=`${y.state.selection.from}:${y.state.selection.to}`,et(null),x.preventDefault(),!0;if(!k.current)return!1;if(x.key==="Escape")return Vr(),!0;if(x.key==="ArrowDown"||x.key==="ArrowUp"){x.preventDefault();let A=S.current.length;return Se($=>A?($+(x.key==="ArrowDown"?1:-1)+A)%A:0),!0}return x.key==="Enter"&&S.current.length?(M.current(T.current),!0):!1},handleClick:(y,x,A)=>{let $=A.target.closest?.("a[href]");if(!$||!n&&!A.metaKey&&!A.ctrlKey)return!1;let I=$.getAttribute("href")??"";if(!lb(I))return!0;let F=Nu(I);return F&&Ru($,F,n?A:void 0)||(I.startsWith("#")?document.getElementById(I.slice(1))?.scrollIntoView({behavior:"smooth",block:"start"}):F||window.open(I,"_blank","noopener,noreferrer")),!0},handlePaste:(y,x)=>{let A=x.clipboardData?.getData("text/plain").trim()??"";if(lr(A)){x.preventDefault();let{empty:F,from:ne,to:ke}=y.state.selection,Z=y.state.schema.marks.link.create({href:A});return y.dispatch(F?y.state.tr.insert(ne,y.state.schema.text(jc(A),[Z])):y.state.tr.addMark(ne,ke,Z)),!0}let I=[...x.clipboardData?.files??[]].filter(F=>F.type.startsWith("image/"));return I.length?(x.preventDefault(),zs(I),!0):!1}},onUpdate:({editor:y,transaction:x})=>p.current(Aa(y.state.doc),{separateHistory:!!x.getMeta(Yn),historyGroup:x.getMeta(zu)})});(0,P.useEffect)(()=>w?Hu(w):void 0,[w]),(0,P.useEffect)(()=>{w&&o?.(w)},[w,o]),(0,P.useEffect)(()=>{w&&w.isEditable===n&&(w.setEditable(!n,!1),w.view.dispatch(w.state.tr.setMeta("editableChanged",!0))),z(y=>y+1),n&&(X(null),Ve(null),me(!1),tn(!1),at(!1),Le(null),et(null))},[w,n]);let ft=(0,P.useRef)(e);ft.current=e;let or=(0,P.useRef)(!1);(0,P.useEffect)(()=>{if(!w)return;let y=()=>{or.current=!0},x=()=>{or.current=!1};return w.on("beforeTransaction",y),w.on("transaction",x),()=>{w.off("beforeTransaction",y),w.off("transaction",x)}},[w]),(0,P.useLayoutEffect)(()=>{if(!w)return;let y,x=()=>{if(w.isDestroyed)return;if(w.view.composing||or.current){y=setTimeout(x,or.current?0:25);return}let $=dh(w.state,ft.current);if(!$)return;let I=w.state.selection instanceof j&&w.state.selection.node.type.name==="widget"?w.state.selection.node.attrs.id:null,F=w.state.selection instanceof se?w.state.selection:null;if(w.view.dispatch($),F){let ne=jh(w.state.doc,F);ne&&w.view.dispatch(w.state.tr.setSelection(ne))}if(I){let ne;if(w.state.doc.descendants((ke,Z)=>{ke.type.name==="widget"&&ke.attrs.id===I&&(ne=Z)}),ne!==void 0)w.commands.setNodeSelection(ne);else{let ke=Dr(w.state);ke&&w.view.dispatch(ke)}}},A=()=>{y=setTimeout(x,25)};return w.view.composing?w.view.dom.addEventListener("compositionend",A):x(),()=>{y&&clearTimeout(y),w.view.dom.removeEventListener("compositionend",A)}},[e,w]),(0,P.useEffect)(()=>{if(!U)return;let y=requestAnimationFrame(()=>document.querySelector(".editor-modal input, .editor-modal textarea")?.focus()),x=A=>{if(A.key==="Escape"&&(A.preventDefault(),A.stopPropagation(),Le(null),w?.commands.focus()),A.key!=="Tab")return;let $=Array.from(document.querySelectorAll(".editor-modal button:not(:disabled), .editor-modal input:not(:disabled), .editor-modal textarea:not(:disabled)")),I=$[0],F=$[$.length-1];A.shiftKey&&document.activeElement===I?(A.preventDefault(),F?.focus()):!A.shiftKey&&document.activeElement===F&&(A.preventDefault(),I?.focus())};return document.addEventListener("keydown",x,!0),()=>{cancelAnimationFrame(y),document.removeEventListener("keydown",x,!0)}},[!!U,w]),(0,P.useEffect)(()=>{if(!w||n)return;let y=()=>{let A=Dr(w.state);A&&w.view.dispatch(A)};!ib.has(w)&&!ih(w)&&(ib.add(w),w.isInitialized?y():w.on("create",y));let x=A=>{if(A.button!==0||!(A.target instanceof Element))return;let $=A.target,I=$.closest(".document-widget");if(I&&w.view.dom.contains(I)||!I&&$.closest('button, input, textarea, select, a, summary, [role="button"], [role="dialog"], .block-handle, .editor-toolbar, .editor-bubble, .editor-small-menu, .editor-modal'))return;let F=Dr(w.state);if(!F)return;let ne=document.activeElement;ne instanceof HTMLElement&&w.view.dom.contains(ne)&&ne.blur(),w.view.dispatch(F),w.view.dom.contains($)&&!$.closest("[data-block-id]")&&A.preventDefault()};return document.addEventListener("pointerdown",x,!0),()=>{w.off("create",y),document.removeEventListener("pointerdown",x,!0)}},[w,n]),(0,P.useEffect)(()=>{if(!O?.manual)return;let y=requestAnimationFrame(()=>b.current?.focus());return()=>cancelAnimationFrame(y)},[O?.manual]),(0,P.useEffect)(()=>{if(!kn&&!xt&&!Ze)return;let y=x=>{x.key==="Escape"&&(x.preventDefault(),tn(!1),at(!1),me(!1),w?.commands.focus())};return document.addEventListener("keydown",y),()=>document.removeEventListener("keydown",y)},[kn,xt,Ze,w]),(0,P.useEffect)(()=>{if(!ge)return;let y=window.setTimeout(()=>yt(""),4500);return()=>window.clearTimeout(y)},[ge]),(0,P.useEffect)(()=>{if(!w)return;let y=()=>{if((!r||!w.state.selection.empty)&&z(Sn=>Sn+1),!w.isEditable)return;let{selection:Z}=w.state,{$from:Be,from:Cn,to:nn,empty:xn}=Z;if((xn||Et.current&&Et.current!==`${Cn}:${nn}`)&&(Et.current=null),!k.current?.manual){let Sn=Be.parent.isTextblock?Be.parent.textBetween(0,Be.parentOffset,`
154
+ `);return{...a,raw:c}}},addCommands(){return{insertTable:({rows:e=3,cols:t=3,withHeaderRow:n=!0}={})=>({tr:r,dispatch:o,editor:i})=>{let s=E1(i.schema,e,t,n);if(o){let l=r.selection.from+1;r.replaceSelectionWith(s).scrollIntoView().setSelection(L.near(r.doc.resolve(l)))}return!0},addColumnBefore:()=>({state:e,dispatch:t})=>Mh(e,t),addColumnAfter:()=>({state:e,dispatch:t})=>Ah(e,t),deleteColumn:()=>({state:e,dispatch:t})=>{let n=Er(e.selection.$from,r=>r.type.name==="table");return Th(e,t&&(r=>{n&&$g(r,n.pos),t(r)}))},addRowBefore:()=>({state:e,dispatch:t})=>Rh(e,t),addRowAfter:()=>({state:e,dispatch:t})=>Dh(e,t),deleteRow:()=>({state:e,dispatch:t})=>{let n=Er(e.selection.$from,r=>r.type.name==="table");return Oh(e,t&&(r=>{n&&$g(r,n.pos),t(r)}))},deleteTable:()=>({state:e,dispatch:t})=>Ih(e,t),mergeCells:()=>({state:e,dispatch:t})=>Ba(e,t),splitCell:()=>({state:e,dispatch:t})=>za(e,t),toggleHeaderColumn:()=>({state:e,dispatch:t})=>Or("column")(e,t),toggleHeaderRow:()=>({state:e,dispatch:t})=>Or("row")(e,t),toggleHeaderCell:()=>({state:e,dispatch:t})=>Ph(e,t),mergeOrSplit:()=>({state:e,dispatch:t})=>Ba(e,t)?!0:za(e,t),setCellAttribute:(e,t)=>({state:n,dispatch:r})=>Lh(e,t)(n,r),goToNextCell:()=>({state:e,dispatch:t})=>Ha(1)(e,t),goToPreviousCell:()=>({state:e,dispatch:t})=>Ha(-1)(e,t),fixTables:()=>({state:e,dispatch:t})=>(t&&$a(e),!0),setCellSelection:e=>({tr:t,dispatch:n})=>{if(n){let r=se.create(t.doc,e.anchorCell,e.headCell);t.setSelection(r)}return!0}}},addKeyboardShortcuts(){return{Tab:()=>this.editor.commands.goToNextCell()?!0:this.editor.can().addRowAfter()?this.editor.chain().addRowAfter().goToNextCell().run():!1,"Shift-Tab":()=>this.editor.commands.goToPreviousCell(),Backspace:Ps,"Mod-Backspace":Ps,Delete:Ps,"Mod-Delete":Ps}},addProseMirrorPlugins(){return[...this.options.resizable&&this.editor.isEditable?[Bh({handleWidth:this.options.handleWidth,cellMinWidth:this.options.cellMinWidth,defaultCellMinWidth:this.options.cellMinWidth,View:this.options.View,lastColumnResizable:this.options.lastColumnResizable})]:[],Hh({allowTableNodeSelection:this.options.allowTableNodeSelection}),P1()]},addNodeView(){let e=this.options.resizable&&this.editor.isEditable,t=this.options.View;return e||!t?null:({node:n,view:r,HTMLAttributes:o})=>{let i=K(this.options.HTMLAttributes,o);return new t(n,this.options.cellMinWidth,r,i)}},extendNodeSchema(e){let t={name:e.name,options:e.options,storage:e.storage};return{tableRole:de(B(e,"tableRole",t))}}}),Fg=le.create({name:"tableKit",addExtensions(){let e=[];return this.options.table!==!1&&e.push(I1.configure(this.options.table)),this.options.tableCell!==!1&&e.push(k1.configure(this.options.tableCell)),this.options.tableHeader!==!1&&e.push(v1.configure(this.options.tableHeader)),this.options.tableRow!==!1&&e.push(C1.configure(this.options.tableRow)),e}});var Wg=As;var Kg=Ms;var $1=/(?:^|\s)(==(?!\s+==)((?:[^=]+))==(?!\s+==))$/,B1=/(?:^|\s)(==(?!\s+==)((?:[^=]+))==(?!\s+==))/g,z1=He.create({name:"highlight",addOptions(){return{multicolor:!1,HTMLAttributes:{}}},addAttributes(){return this.options.multicolor?{color:{default:null,parseHTML:e=>e.getAttribute("data-color")||Np(e,"background-color")||e.style.backgroundColor,renderHTML:e=>Tr(e.color)?{"data-color":e.color,style:`background-color: ${e.color}; color: inherit`}:{}}}:{}},parseHTML(){return[{tag:"mark"}]},renderHTML({HTMLAttributes:e}){return["mark",K(this.options.HTMLAttributes,e),0]},renderMarkdown:(e,t)=>`==${t.renderChildren(e)}==`,parseMarkdown:(e,t)=>t.applyMark("highlight",t.parseInline(e.tokens||[])),markdownTokenizer:{name:"highlight",level:"inline",start:e=>e.indexOf("=="),tokenize(e,t,n){let r=/^(==)([^=]+)(==)/.exec(e);if(r){let o=r[2].trim(),i=n.inlineTokens(o);return{type:"highlight",raw:r[0],text:o,tokens:i}}}},addCommands(){return{setHighlight:e=>({commands:t})=>t.setMark(this.name,e),toggleHighlight:e=>({commands:t})=>t.toggleMark(this.name,e),unsetHighlight:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-Shift-h":()=>this.editor.commands.toggleHighlight()}},addInputRules(){return[st({find:$1,type:this.type})]},addPasteRules(){return[rt({find:B1,type:this.type})]}}),Ug=z1;var qg=Ug.extend({addAttributes(){let e={...this.parent?.(),mode:{default:"lower",parseHTML:t=>t.getAttribute("data-highlight-mode")==="full"?"full":"lower",renderHTML:({mode:t})=>({"data-highlight-mode":t==="full"?"full":"lower"})}};return this.options.multicolor?{...e,color:{...e.color,renderHTML:({color:t})=>t?{"data-color":t,style:`--showai-highlight-color: ${t}`}:{}}}:e}});var H1=le.create({name:"textAlign",addOptions(){return{types:[],alignments:["left","center","right","justify"],defaultAlignment:null}},addGlobalAttributes(){return[{types:this.options.types,attributes:{textAlign:{default:this.options.defaultAlignment,parseHTML:e=>{let t=e.style.textAlign;return this.options.alignments.includes(t)?t:this.options.defaultAlignment},renderHTML:e=>!Tr(e.textAlign)||!this.options.alignments.includes(e.textAlign)?{}:{style:`text-align: ${e.textAlign}`}}}}]},addCommands(){return{setTextAlign:e=>({commands:t})=>this.options.alignments.includes(e)?this.options.types.map(n=>t.updateAttributes(n,{textAlign:e})).some(n=>n):!1,unsetTextAlign:()=>({commands:e})=>this.options.types.map(t=>e.resetAttributes(t,"textAlign")).some(t=>t),toggleTextAlign:e=>({editor:t,commands:n})=>this.options.alignments.includes(e)?t.isActive({textAlign:e})?n.unsetTextAlign():n.setTextAlign(e):!1}},addKeyboardShortcuts(){return{"Mod-Shift-l":()=>this.editor.commands.setTextAlign("left"),"Mod-Shift-e":()=>this.editor.commands.setTextAlign("center"),"Mod-Shift-r":()=>this.editor.commands.setTextAlign("right"),"Mod-Shift-j":()=>this.editor.commands.setTextAlign("justify")}}}),Gg=H1;var Jg=le.create({name:"dropCursorCleanup",addProseMirrorPlugins(){return[new q({view(e){let t=e.dom.ownerDocument,n=t.defaultView,r=()=>{let o=t.createEvent("Event");o.initEvent("dragleave",!1,!1),e.dom.dispatchEvent(o)};return t.addEventListener("drop",r,!0),t.addEventListener("dragend",r,!0),n?.addEventListener("blur",r),{destroy(){t.removeEventListener("drop",r,!0),t.removeEventListener("dragend",r,!0),n?.removeEventListener("blur",r)}}}})]}});var rr=pe(zt(),1);var fe=pe(Fe(),1);function Xg({node:e,updateAttributes:t,editor:n,selected:r,getPos:o}){let{renderWidget:i}=(0,rr.useContext)(Uo),s=fo({editor:n,selector:({editor:l})=>l.isEditable});return(0,fe.jsx)(qn,{className:`document-widget${r&&s?" is-selected":""}`,"data-widget-kind":e.attrs.kind,"data-block-id":e.attrs.id??void 0,onPointerDownCapture:l=>{if(!s||l.button!==0||l.shiftKey||l.metaKey||l.ctrlKey)return;if(rl(l.target,l.clientX,l.clientY)){let u=Dr(n.state);u&&n.view.dispatch(u);return}let a=o();!r&&typeof a=="number"&&n.commands.setNodeSelection(a)},onClick:l=>{if(!s||l.button!==0||l.shiftKey||l.metaKey||l.ctrlKey)return;if(rl(l.target,l.clientX,l.clientY)||l.target.closest('[data-text-selection="true"]')){l.stopPropagation();return}let a=o();typeof a=="number"&&(n.commands.setNodeSelection(a),l.stopPropagation())},children:(0,fe.jsx)(ju,{id:e.attrs.id,children:i({kind:e.attrs.kind,data:e.attrs.data,onChange:l=>{n.isEditable&&t({data:Ko(l)})},readOnly:!s})})})}var Pc=["\u{1F4A1}","\u{1F331}","\u{1F4CC}","\u2728","\u26A0\uFE0F","\u{1F50E}"],Ic=["sage","sand","blue","rose"];function Yg({node:e,updateAttributes:t,editor:n}){let r=Re(ze),o=fo({editor:n,selector:({editor:i})=>i.isEditable});return(0,fe.jsxs)(qn,{style:rn(e.attrs.componentStyle),className:`document-callout tone-${e.attrs.tone}`,"data-block-id":e.attrs.id??void 0,children:[(0,fe.jsxs)("div",{className:"callout-decoration",contentEditable:!1,children:[(0,fe.jsx)("button",{className:"callout-icon",disabled:!o,title:r("callout.changeIcon"),"aria-label":r("callout.changeIconLabel"),onClick:()=>t({icon:Pc[(Pc.indexOf(e.attrs.icon)+1)%Pc.length]}),children:e.attrs.icon}),o&&(0,fe.jsx)("button",{className:"callout-color",title:r("callout.changeColor"),"aria-label":r("callout.changeColorLabel"),onClick:()=>t({tone:Ic[(Ic.indexOf(e.attrs.tone)+1)%Ic.length]})})]}),(0,fe.jsxs)("div",{children:[e.attrs.title&&(0,fe.jsx)("strong",{children:e.attrs.title}),(0,fe.jsx)(Mi,{className:"callout-content"})]})]})}function Qg({node:e,updateAttributes:t,editor:n}){let r=Re(ze),o=fo({editor:n,selector:({editor:c})=>c.isEditable}),[i,s]=(0,rr.useState)(!!e.attrs.open);(0,rr.useEffect)(()=>s(!!e.attrs.open),[e.attrs.open]);let[l,a]=ol("open",!!e.attrs.open,{block:e.attrs.id??null,accept:c=>typeof c=="boolean"}),u=o?i:l;return(0,fe.jsxs)(qn,{style:rn(e.attrs.componentStyle),className:`document-toggle${u?" is-open":""}`,"data-block-id":e.attrs.id??void 0,children:[(0,fe.jsxs)("div",{className:"toggle-heading",contentEditable:!1,children:[(0,fe.jsx)("button",{"aria-label":r(u?"toggle.collapse":"toggle.expand"),"aria-expanded":u,onClick:()=>{if(!n.isEditable)return a(!u);s(!u),t({open:!u})},children:(0,fe.jsx)(Po,{size:16})}),o?(0,fe.jsx)("input",{"aria-label":r("toggle.titleLabel"),value:e.attrs.title,onChange:c=>t({title:c.target.value}),placeholder:r("toggle.titlePlaceholder")}):(0,fe.jsx)("span",{children:e.attrs.title})]}),(0,fe.jsx)("div",{className:"toggle-body",hidden:!u,children:(0,fe.jsx)(Mi,{})})]})}function Zg({node:e,editor:t,getPos:n}){let r=Re(ze),o=fo({editor:t,selector:({editor:b})=>b.isEditable}),[i,s]=ol("step",0,{block:e.attrs.id??null,accept:Number.isInteger}),l=e.childCount,a=Math.min(i,l-1),u=Array.from({length:l},(b,k)=>Gu(e.child(k).attrs.title,k)),c=()=>{let b=n();if(typeof b!="number")throw new Error("The stepper is detached.");return b+1},d=b=>{let k=c();for(let C=0;C<b;C+=1)k+=e.child(C).nodeSize;return k};(0,rr.useEffect)(()=>{let b=()=>{let k=n(),C=typeof k=="number"?t.state.doc.nodeAt(k):null;if(!C||C.type.name!=="stepper")return;let{from:S}=t.state.selection;if(S<=k||S>=k+C.nodeSize)return;let M=k+1;for(let T=0;T<C.childCount;T+=1)if(M+=C.child(T).nodeSize,S<M)return s(T)};return t.on("selectionUpdate",b),()=>{t.off("selectionUpdate",b)}},[t,n]);let f=b=>{let{tr:k}=t.state,C=b(k);return t.view.dispatch(k),s(C),C},p=b=>f(k=>(k.setNodeMarkup(d(a),void 0,{...e.child(a).attrs,title:b}),a)),h=()=>{f(b=>{let{schema:k}=t.state,C=d(a)+e.child(a).nodeSize;return b.insert(C,k.nodes.step.create({title:""},k.nodes.paragraph.create())),b.setSelection(L.create(b.doc,C+2)),a+1}),t.view.focus()},g=()=>f(b=>{let k=d(a);return b.delete(k,k+e.child(a).nodeSize),Math.max(0,a-1)}),m=b=>f(k=>{let C=a+b,S=e.child(a),M=d(a),T=b<0?d(C):d(C)+e.child(C).nodeSize;return k.delete(M,M+S.nodeSize),k.insert(k.mapping.map(T),S),C});return(0,fe.jsxs)(qn,{style:rn(e.attrs.componentStyle),className:"document-stepper","data-block-id":e.attrs.id??void 0,children:[(0,fe.jsx)(Ju,{titles:u,active:a,onSelect:s}),o&&(0,fe.jsxs)("div",{className:"stepper-edit",contentEditable:!1,children:[(0,fe.jsx)("input",{"aria-label":r("stepper.titleLabel"),placeholder:r("stepper.titlePlaceholder"),value:e.child(a).attrs.title??"",onChange:b=>p(b.target.value)}),(0,fe.jsx)("button",{type:"button",title:r("stepper.moveEarlier"),"aria-label":r("stepper.moveEarlier"),disabled:a===0,onClick:()=>m(-1),children:"\u21A4"}),(0,fe.jsx)("button",{type:"button",title:r("stepper.moveLater"),"aria-label":r("stepper.moveLater"),disabled:a===l-1,onClick:()=>m(1),children:"\u21A6"}),(0,fe.jsx)("button",{type:"button",title:r("stepper.add"),"aria-label":r("stepper.add"),disabled:l>=Iu,onClick:h,children:"+"}),(0,fe.jsx)("button",{type:"button",title:r("stepper.remove"),"aria-label":r("stepper.remove"),disabled:l<=1,onClick:g,children:"\xD7"})]}),(0,fe.jsx)(Mi,{className:"stepper-steps","data-active":a})]})}function eb({node:e,updateAttributes:t,editor:n,selected:r}){let o=Re(ze),i=e.type.name==="mathBlock"||e.attrs.display;return qu(),(0,fe.jsxs)(qn,{as:i?"div":"span",className:i?"sb-math-display":"sb-math-inline",contentEditable:!1,children:[(0,fe.jsx)("span",{dangerouslySetInnerHTML:{__html:Lu(e.attrs.latex,i)}}),r&&n.isEditable&&(0,fe.jsx)("input",{"aria-label":o("math.source"),value:e.attrs.latex,onChange:s=>t({latex:s.target.value}),onKeyDown:s=>{s.key==="Escape"&&(s.preventDefault(),n.commands.focus())}})]})}function tb({node:e}){return(0,fe.jsx)(qn,{"data-block-id":e.attrs.id,"data-drag-handle":!0,contentEditable:!1,children:(0,fe.jsx)(Wu,{attrs:e.attrs})})}var Bc=["paragraph","heading","blockquote","bulletList","orderedList","listItem","taskList","taskItem","codeBlock","hardBreak","horizontalRule","image","table","tableRow","tableCell","tableHeader","callout","toggle","stepper","step","widget","mathInline","mathBlock"],$s=new oe("showaiBlockIds");function _1(e){let t=new Set([...Bc,"region","richText","pageModule"]);return new q({key:$s,appendTransaction(n,r,o){if(!e()||!n.some(l=>l.docChanged||l.getMeta($s)||l.getMeta("editableChanged")))return null;let i=new Set,s=o.tr;return o.doc.descendants((l,a)=>{if(!t.has(l.type.name))return;let u=l.attrs.id;if(typeof u=="string"&&u.trim()&&!i.has(u)){i.add(u);return}let c;do c=globalThis.crypto.randomUUID();while(i.has(c));i.add(c),s.setNodeAttribute(a,"id",c)}),s.docChanged?s.setMeta($s,!0).setMeta("addToHistory",!1):null}})}var V1=le.create({name:"showaiStableBlockIds",addOptions:()=>({readOnly:!1}),addGlobalAttributes(){return[{types:[...Bc,"region","richText","pageModule"],attributes:{id:{default:null,parseHTML:e=>e.getAttribute("data-block-id"),renderHTML:e=>typeof e.id=="string"&&e.id.trim()?{"data-block-id":e.id}:{}}}}]},addProseMirrorPlugins(){return[_1(()=>!this.options.readOnly&&this.editor.isEditable)]},onCreate(){!this.options.readOnly&&this.editor.isEditable&&this.editor.view.dispatch(this.editor.state.tr.setMeta($s,!0).setMeta("addToHistory",!1))}}),j1=ie.create({name:"widget",group:"block",atom:!0,draggable:!0,addAttributes(){return{kind:{default:"chart"},data:{default:{},parseHTML:e=>{let t=e.getAttribute("data-widget-content");if(!t)return{};try{return JSON.parse(t)}catch{return{}}},renderHTML:e=>({"data-widget-content":JSON.stringify(e.data)})}}},parseHTML:()=>[{tag:"div[data-showai-widget]"}],renderHTML:({HTMLAttributes:e})=>["div",K(e,{"data-showai-widget":""})],addNodeView:()=>Gn(Xg)}),F1=ie.create({name:"callout",group:"block",content:"block+",defining:!0,draggable:!0,addAttributes:()=>({icon:{default:"\u{1F4A1}"},tone:{default:"sage"},title:{default:""}}),parseHTML:()=>[{tag:"aside[data-callout]"}],renderHTML:({HTMLAttributes:e})=>["aside",K(e,{"data-callout":""}),0],addNodeView:()=>Gn(Yg)}),W1=ie.create({name:"toggle",group:"block",content:"block+",defining:!0,draggable:!0,addAttributes:()=>({title:{default:"\u5C55\u5F00\u4E86\u89E3\u66F4\u591A"},open:{default:!0}}),parseHTML:()=>[{tag:"section[data-toggle]"}],renderHTML:({HTMLAttributes:e})=>["section",K(e,{"data-toggle":""}),0],addNodeView:()=>Gn(Qg)}),K1=ie.create({name:"stepper",group:"block",content:"step+",defining:!0,draggable:!0,isolating:!0,parseHTML:()=>[{tag:"section[data-stepper]"}],renderHTML:({HTMLAttributes:e})=>["section",K(e,{"data-stepper":""}),0],addNodeView:()=>Gn(Zg)}),U1=ie.create({name:"step",content:"block+",defining:!0,isolating:!0,addAttributes:()=>({title:{default:""}}),parseHTML:()=>[{tag:"section[data-step]"}],renderHTML:({HTMLAttributes:e})=>["section",K(e,{"data-step":""}),0]}),q1=ie.create({name:"richText",priority:50,group:"block",content:"block*",defining:!0,addAttributes:()=>({id:{default:null},name:{default:"\u5BCC\u6587\u672C"},data:{default:{},parseHTML:e=>JSON.parse(e.getAttribute("data-rich-text-settings")||"{}"),renderHTML:()=>({})}}),parseHTML:()=>[{tag:'div[data-component-kind="text"]'},{tag:'div[data-page-flow="richText"]'}],renderHTML:({node:e,HTMLAttributes:t})=>["div",K(t,{"data-component-kind":"text","data-rich-text-settings":JSON.stringify(e.attrs.data),class:"page-document-flow rich-text-component",style:Object.entries(rn(e.attrs.data)).filter(([,n])=>n!==void 0).map(([n,r])=>`${n.replace(/[A-Z]/g,o=>"-"+o.toLowerCase())}:${typeof r=="number"?`${r}px`:r}`).join(";")}),0]}),G1=He.create({name:"textStyle",addAttributes:()=>Object.fromEntries(["color","fontFamily","fontSize"].map(e=>[e,{default:null,parseHTML:t=>t.style[e],renderHTML:t=>t[e]?{style:`${e.replace(/[A-Z]/g,n=>"-"+n.toLowerCase())}: ${t[e]}`}:{}}])),parseHTML:()=>[{tag:"span[style]"}],renderHTML:({HTMLAttributes:e})=>["span",K(e),0]}),J1=He.create({name:"annotation",inclusive:!1,addAttributes:()=>({note:{default:"",parseHTML:e=>e.getAttribute("data-showai-note")??"",renderHTML:e=>({"data-showai-note":e.note??""})}}),parseHTML:()=>[{tag:"span[data-showai-note]"}],renderHTML:({HTMLAttributes:e})=>["span",K({class:"showai-note"},e),0]}),nb=e=>ie.create({name:e?"mathInline":"mathBlock",group:e?"inline":"block",inline:e,atom:!0,addAttributes:()=>({latex:{default:""},display:{default:!e}}),parseHTML:()=>[{tag:e?"span[data-math]":"div[data-math]"}],renderHTML:({node:t,HTMLAttributes:n})=>[e?"span":"div",{...n,"data-math":t.attrs.latex}],addNodeView:()=>Gn(eb)}),rb=ur(ze);function ob(e={}){return[X1,q1,G1,J1,nb(!0),nb(!1),V1.configure({readOnly:e.readOnly??!1}),Jg,og.configure({trailingNode:e.trailingNode===!1?!1:{},heading:{levels:[1,2,3,4,5,6]},link:{openOnClick:e.readOnly??!1,HTMLAttributes:{rel:"noopener noreferrer",target:"_blank"},isAllowedUri:(t,n)=>!!lr(t)||n.defaultValidate(t)},codeBlock:!1}),Dg,Og.configure({placeholder:({node:t,editor:n})=>t.type.name==="heading"?rb("placeholderHeading"):typeof e.placeholder=="function"?e.placeholder({empty:n.isEmpty}):e.placeholder??rb("placeholderDefault"),includeChildren:!1}),Lg.extend({addNodeView:()=>Gn(tb)}).configure({allowBase64:!0,HTMLAttributes:{class:"document-image"}}),Fg.configure({table:{resizable:!0,View:$c}}),Wh,Wg,Kg.configure({nested:!0}),qg.configure({multicolor:!0}),Gg.configure({types:["heading","paragraph"]}),F1,W1,K1,U1,j1]}var X1=le.create({name:"showaiContentAttributes",addGlobalAttributes(){let e=t=>({default:null,parseHTML:n=>{let r=n.getAttribute(`data-content-${t.toLowerCase()}`);if(r===null)return null;try{return t==="title"?r:JSON.parse(r)}catch{return null}},renderHTML:n=>n[t]==null?{}:{[`data-content-${t.toLowerCase()}`]:t==="title"?String(n[t]):JSON.stringify(n[t]),...t==="componentStyle"?{style:Object.entries({...rn(n[t]),borderTopColor:n[t]?.color}).filter(([,r])=>r!==void 0).map(([r,o])=>`${r.replace(/[A-Z]/g,i=>`-${i.toLowerCase()}`)}:${typeof o=="number"?`${o}px`:o}`).join(";")}:{}}});return[{types:Bc,attributes:{name:{...e("name"),default:"",parseHTML:t=>{let n=e("name").parseHTML(t);return typeof n=="string"?n:""}}}},{types:["image","codeBlock","table","callout","toggle","stepper","horizontalRule"],attributes:{componentStyle:e("componentStyle")}},{types:["image"],attributes:Object.fromEntries(["caption","fit","nativeInk","width","height","align"].map(t=>[t,e(t)]))},{types:["table"],attributes:{title:e("title")}}]}}),$c=class extends Lc{constructor(...t){super(...t),this.syncMetadata()}syncMetadata(){let t=rn(this.node.attrs.componentStyle);this.dom.style.cssText="",Object.assign(this.dom.style,Object.fromEntries(Object.entries(t).filter(([,r])=>r!==void 0).map(([r,o])=>[r,typeof o=="number"?`${o}px`:o]))),this.node.attrs.id&&(this.table.dataset.blockId=this.node.attrs.id);let n=this.node.attrs.title;if(n){let r=this.table.caption??this.table.createCaption();r.textContent=n}else this.table.caption?.remove();this.dom.tabIndex=0}update(t){return super.update(t)?(this.syncMetadata(),!0):!1}};var v=pe(Fe(),1),ib=new WeakSet,sb=ur(ze);function Y1({children:e,className:t,onDismiss:n}){return(0,v.jsx)("div",{className:t,onMouseDown:r=>{r.target===r.currentTarget&&n()},children:e})}function Bt({label:e,children:t,onClick:n,active:r,disabled:o}){return(0,v.jsx)("button",{type:"button",className:`editor-tool${r?" is-active":""}`,"aria-label":e,title:e,"aria-pressed":r,disabled:o,onMouseDown:i=>i.preventDefault(),onClick:n,children:t})}function Q1(e){return/^https?:\/\//i.test(e)||/^data:image\/(png|jpe?g|gif|webp|avif);base64,/i.test(e)}function lb(e){return/^(https?:\/\/|mailto:|tel:|#)/i.test(e)||!!lr(e)}function Hc(e){return e.startsWith("page-tail-")}function _c(e,t){let n=e.view.coordsAtPos(Math.min(t,e.state.doc.content.size));return{left:Math.max(12,Math.min(n.left,window.innerWidth-340)),top:Math.max(70,Math.min(n.bottom+8,window.innerHeight-370))}}function Z1({content:e,onChange:t,readOnly:n=!1,minimal:r=!0,onEditorReady:o,onInsertNative:i,onDetachBlock:s,additionalExtensions:l,trailingNode:a=!0,retentionKey:u}){let c=Re(ze),d=Re(Vu),f=Re(Go),p=(0,P.useRef)(t),h=(0,P.useId)();p.current=t;let g=(0,P.useRef)(null),m=(0,P.useRef)(null),b=(0,P.useRef)(null),k=(0,P.useRef)(null),C=(0,P.useRef)(null),S=(0,P.useRef)([]),M=(0,P.useRef)(()=>{}),T=(0,P.useRef)(0),E=(0,P.useRef)(null),[O,X]=(0,P.useState)(null),{useCatalog:he,registerComponent:Ne,assistant:$e,pageLinks:xe}=(0,P.useContext)(Uo),_e=(0,P.useRef)(xe);_e.current=xe;let Me=he(!!O),[N,_]=(0,P.useState)(!1),ee=(0,P.useRef)(0);(0,P.useEffect)(()=>()=>{ee.current++},[]);let[ue,Se]=(0,P.useState)(0),[Y,Ve]=(0,P.useState)(null),[Ze,me]=(0,P.useState)(!1),je=(0,P.useRef)(null),zr=(0,P.useRef)(Ze);zr.current=Ze;let wn=(0,P.useRef)(0),Hr=(0,P.useRef)(0);(0,P.useEffect)(()=>()=>cancelAnimationFrame(wn.current),[]);let Ct=(0,P.useCallback)(()=>{je.current!==null&&(clearTimeout(je.current),je.current=null)},[]),Do=(0,P.useCallback)(()=>{je.current===null&&(je.current=setTimeout(()=>{je.current=null;let y=g.current?.querySelector(".block-handle");zr.current||E.current!==null||y?.contains(document.activeElement)||Ve(null)},450))},[]);(0,P.useEffect)(()=>Ct,[Ct]);let[kn,tn]=(0,P.useState)(!1),[xt,at]=(0,P.useState)(!1),[U,Le]=(0,P.useState)(null),[St,J]=(0,P.useState)(null),[_r,Ce]=(0,P.useState)(""),[ge,yt]=(0,P.useState)(""),[qe,et]=(0,P.useState)(null);(0,P.useEffect)(()=>{!qe&&St&&(Le(null),J(null))},[!!qe,St]);let Et=(0,P.useRef)(null),D=(0,P.useRef)(!1),[,z]=(0,P.useState)(0),G=(0,P.useRef)(null);k.current=O,T.current=ue;let be=(0,P.useMemo)(()=>[...ob({placeholder:({empty:y})=>sb(y&&!a?"placeholderPage":"placeholder"),trailingNode:a}),...l??[]],[l,a]);(0,P.useLayoutEffect)(()=>{if(!Ze)return;let y=g.current,x=y?.querySelector(".block-menu"),A=y?.querySelector(".block-handle");if(!x||!A)return;let $=()=>{let F=A.getBoundingClientRect(),ne=x.getBoundingClientRect();Object.assign(x.style,{position:"fixed",left:`${Math.max(12,Math.min(F.right,window.innerWidth-ne.width-12))}px`,top:`${Math.max(12,Math.min(F.top,window.innerHeight-ne.height-12))}px`})};$();let I=new ResizeObserver($);return I.observe(x),window.addEventListener("resize",$),window.addEventListener("scroll",$,!0),()=>{I.disconnect(),window.removeEventListener("resize",$),window.removeEventListener("scroll",$,!0)}},[Ze,Y?.pos]);let w=sh({retentionKey:u,extensions:be,content:e,editable:!n,immediatelyRender:!1,shouldRerenderOnTransaction:!1,editorProps:{attributes:{class:"document-content","aria-label":sb("documentContent"),spellcheck:"false"},handleKeyDown:(y,x)=>{if(x.isComposing)return!1;if(x.key==="Escape"&&!k.current&&!y.state.selection.empty)return Et.current=`${y.state.selection.from}:${y.state.selection.to}`,et(null),x.preventDefault(),!0;if(!k.current)return!1;if(x.key==="Escape")return Vr(),!0;if(x.key==="ArrowDown"||x.key==="ArrowUp"){x.preventDefault();let A=S.current.length;return Se($=>A?($+(x.key==="ArrowDown"?1:-1)+A)%A:0),!0}return x.key==="Enter"&&S.current.length?(M.current(T.current),!0):!1},handleClick:(y,x,A)=>{let $=A.target.closest?.("a[href]");if(!$||!n&&!A.metaKey&&!A.ctrlKey||!n&&!$.isContentEditable)return!1;let I=$.getAttribute("href")??"";if(!lb(I))return!0;let F=Nu(I);return F&&Ru($,F,n?A:void 0)||(I.startsWith("#")?document.getElementById(I.slice(1))?.scrollIntoView({behavior:"smooth",block:"start"}):F||window.open(I,"_blank","noopener,noreferrer")),!0},handlePaste:(y,x)=>{let A=x.clipboardData?.getData("text/plain").trim()??"";if(lr(A)){x.preventDefault();let{empty:F,from:ne,to:ke}=y.state.selection,Z=y.state.schema.marks.link.create({href:A});return y.dispatch(F?y.state.tr.insert(ne,y.state.schema.text(jc(A),[Z])):y.state.tr.addMark(ne,ke,Z)),!0}let I=[...x.clipboardData?.files??[]].filter(F=>F.type.startsWith("image/"));return I.length?(x.preventDefault(),zs(I),!0):!1}},onUpdate:({editor:y,transaction:x})=>p.current(Aa(y.state.doc),{separateHistory:!!x.getMeta(Yn),historyGroup:x.getMeta(zu)})});(0,P.useEffect)(()=>w?Hu(w):void 0,[w]),(0,P.useEffect)(()=>{w&&o?.(w)},[w,o]),(0,P.useEffect)(()=>{w&&w.isEditable===n&&(w.setEditable(!n,!1),w.view.dispatch(w.state.tr.setMeta("editableChanged",!0))),z(y=>y+1),n&&(X(null),Ve(null),me(!1),tn(!1),at(!1),Le(null),et(null))},[w,n]);let ft=(0,P.useRef)(e);ft.current=e;let or=(0,P.useRef)(!1);(0,P.useEffect)(()=>{if(!w)return;let y=()=>{or.current=!0},x=()=>{or.current=!1};return w.on("beforeTransaction",y),w.on("transaction",x),()=>{w.off("beforeTransaction",y),w.off("transaction",x)}},[w]),(0,P.useLayoutEffect)(()=>{if(!w)return;let y,x=()=>{if(w.isDestroyed)return;if(w.view.composing||or.current){y=setTimeout(x,or.current?0:25);return}let $=dh(w.state,ft.current);if(!$)return;let I=w.state.selection instanceof j&&w.state.selection.node.type.name==="widget"?w.state.selection.node.attrs.id:null,F=w.state.selection instanceof se?w.state.selection:null;if(w.view.dispatch($),F){let ne=jh(w.state.doc,F);ne&&w.view.dispatch(w.state.tr.setSelection(ne))}if(I){let ne;if(w.state.doc.descendants((ke,Z)=>{ke.type.name==="widget"&&ke.attrs.id===I&&(ne=Z)}),ne!==void 0)w.commands.setNodeSelection(ne);else{let ke=Dr(w.state);ke&&w.view.dispatch(ke)}}},A=()=>{y=setTimeout(x,25)};return w.view.composing?w.view.dom.addEventListener("compositionend",A):x(),()=>{y&&clearTimeout(y),w.view.dom.removeEventListener("compositionend",A)}},[e,w]),(0,P.useEffect)(()=>{if(!U)return;let y=requestAnimationFrame(()=>document.querySelector(".editor-modal input, .editor-modal textarea")?.focus()),x=A=>{if(A.key==="Escape"&&(A.preventDefault(),A.stopPropagation(),Le(null),w?.commands.focus()),A.key!=="Tab")return;let $=Array.from(document.querySelectorAll(".editor-modal button:not(:disabled), .editor-modal input:not(:disabled), .editor-modal textarea:not(:disabled)")),I=$[0],F=$[$.length-1];A.shiftKey&&document.activeElement===I?(A.preventDefault(),F?.focus()):!A.shiftKey&&document.activeElement===F&&(A.preventDefault(),I?.focus())};return document.addEventListener("keydown",x,!0),()=>{cancelAnimationFrame(y),document.removeEventListener("keydown",x,!0)}},[!!U,w]),(0,P.useEffect)(()=>{if(!w||n)return;let y=()=>{let A=Dr(w.state);A&&w.view.dispatch(A)};!ib.has(w)&&!ih(w)&&(ib.add(w),w.isInitialized?y():w.on("create",y));let x=A=>{if(A.button!==0||!(A.target instanceof Element))return;let $=A.target,I=$.closest(".document-widget");if(I&&w.view.dom.contains(I)||!I&&$.closest('button, input, textarea, select, a, summary, [role="button"], [role="dialog"], .block-handle, .editor-toolbar, .editor-bubble, .editor-small-menu, .editor-modal'))return;let F=Dr(w.state);if(!F)return;let ne=document.activeElement;ne instanceof HTMLElement&&w.view.dom.contains(ne)&&ne.blur(),w.view.dispatch(F),w.view.dom.contains($)&&!$.closest("[data-block-id]")&&A.preventDefault()};return document.addEventListener("pointerdown",x,!0),()=>{w.off("create",y),document.removeEventListener("pointerdown",x,!0)}},[w,n]),(0,P.useEffect)(()=>{if(!O?.manual)return;let y=requestAnimationFrame(()=>b.current?.focus());return()=>cancelAnimationFrame(y)},[O?.manual]),(0,P.useEffect)(()=>{if(!kn&&!xt&&!Ze)return;let y=x=>{x.key==="Escape"&&(x.preventDefault(),tn(!1),at(!1),me(!1),w?.commands.focus())};return document.addEventListener("keydown",y),()=>document.removeEventListener("keydown",y)},[kn,xt,Ze,w]),(0,P.useEffect)(()=>{if(!ge)return;let y=window.setTimeout(()=>yt(""),4500);return()=>window.clearTimeout(y)},[ge]),(0,P.useEffect)(()=>{if(!w)return;let y=()=>{if((!r||!w.state.selection.empty)&&z(Sn=>Sn+1),!w.isEditable)return;let{selection:Z}=w.state,{$from:Be,from:Cn,to:nn,empty:xn}=Z;if((xn||Et.current&&Et.current!==`${Cn}:${nn}`)&&(Et.current=null),!k.current?.manual){let Sn=Be.parent.isTextblock?Be.parent.textBetween(0,Be.parentOffset,`
155
155
  `):"",En=xn&&Sn.match(/^\/([^\n/]*)$/);if(En){let Jc=Cn-En[0].length;C.current!==`${Jc}:${nn}:${En[1]}`&&(C.current=null,X({from:Jc,to:nn,query:En[1],..._c(w,Cn)}))}else X(null),C.current=null}if(!xn&&Et.current!==`${Cn}:${nn}`&&(w.isFocused||D.current)&&!w.isActive("codeBlock")&&!w.isActive("widget")&&!w.isActive("pageModule")){let Sn=w.view.coordsAtPos(Cn),En=w.view.coordsAtPos(nn);et({left:(Sn.left+En.right)/2,top:Sn.top,bottom:Math.max(Sn.bottom,En.bottom)})}else et(null)},x=Z=>Z instanceof Element&&Z.closest(".editor-bubble")?.id===h,A=Z=>{x(Z.relatedTarget)&&(D.current=!0)},$=()=>{D.current=!1,et(null)},I=Z=>{D.current=x(Z.target),!D.current&&(!(Z.target instanceof Node)||!w.view.dom.contains(Z.target))&&$()},F=({event:Z})=>{!D.current&&!x(Z.relatedTarget)&&$()},ne=Z=>{x(Z.target)||$()},ke=Z=>{!(Z.target instanceof Element)||!Z.target.contains(w.view.dom)||(et(null),X(null),me(!1),Ve(null))};return w.on("transaction",y),w.on("focus",y),w.on("blur",F),w.view.dom.addEventListener("blur",A,!0),document.addEventListener("pointerdown",I,!0),document.addEventListener("focusin",I,!0),w.view.dom.addEventListener("contextmenu",$),window.addEventListener("scroll",ne,!0),window.addEventListener("resize",y),window.addEventListener("showai:viewport-change",ke),()=>{w.off("transaction",y),w.off("focus",y),w.off("blur",F),w.view.dom.removeEventListener("blur",A,!0),document.removeEventListener("pointerdown",I,!0),document.removeEventListener("focusin",I,!0),w.view.dom.removeEventListener("contextmenu",$),window.removeEventListener("scroll",ne,!0),window.removeEventListener("resize",y),window.removeEventListener("showai:viewport-change",ke)}},[w,h,r]),(0,P.useEffect)(()=>Se(0),[O?.query]),(0,P.useEffect)(()=>{document.querySelector(".slash-menu .slash-item.is-selected")?.scrollIntoView({block:"nearest"})},[ue]);function Vr(){let y=k.current;y&&!y.manual&&(C.current=`${y.from}:${y.to}:${y.query}`),k.current=null,X(null)}function jc(y){let x=lr(y),A=_e.current;return x&&A?.projectId===x.projectId&&A.pages.find(I=>I.id===x.pageId)?.title||y}function Fc(y){w&&(G.current&&w.commands.setTextSelection(G.current),y?w.state.selection.empty&&!w.isActive("link")?w.chain().focus().insertContent({type:"text",text:jc(y),marks:[{type:"link",attrs:{href:y}}]}).run():w.chain().focus().extendMarkRange("link").setLink({href:y}).run():w.chain().focus().extendMarkRange("link").unsetLink().run(),Le(null))}let jr=U?.type==="link"&&xe&&!/^[a-z][a-z0-9+.-]*:|^#/i.test(U.value.trim())?U.value.trim().toLocaleLowerCase():null,Mt=(0,P.useMemo)(()=>jr===null||!xe?[]:xe.pages.filter(y=>y.id!==xe.pageId&&(y.title||c("dialog.untitledPage")).toLocaleLowerCase().includes(jr)).slice(0,6).map(y=>({...y,href:Tu({projectId:xe.projectId,pageId:y.id})})),[jr,xe,c]),[Oo,Bs]=(0,P.useState)(-1);(0,P.useEffect)(()=>Bs(jr?0:-1),[jr]);let ir=(0,P.useCallback)(y=>{if(!w)return;let{selection:x}=w.state;G.current={from:x.from,to:x.to};let A=y==="note"&&x instanceof j&&["mathInline","mathBlock"].includes(x.node.type.name)?x.node:null,$=A?Ou(String(A.attrs.latex??"")):null;Le({type:y,value:y==="link"?w.getAttributes("link").href??"":y==="note"?A?$?.note??"":w.getAttributes("annotation").note??"":"",alt:"",hadNote:y==="note"&&(A?!!$:w.isActive("annotation")),...A?{math:{pos:x.from,body:$?.body??String(A.attrs.latex??"")}}:{}}),Ce(""),at(!1);let I=y!=="image"?document.getElementById(h):null;J(I),I||et(null)},[w,h]);function Wc(y,x){if(!w)return!1;if(x.length>1e3)return Ce(f("dialog.noteTooLong",{max:1e3})),!1;if(y.math){let{pos:$,body:I}=y.math,F=w.state.doc.nodeAt($);return!F||!["mathInline","mathBlock"].includes(F.type.name)?(Ce(f("dialog.noteTargetMissing")),!1):(w.chain().focus().command(({tr:ne})=>(ne.setNodeMarkup($,void 0,{...F.attrs,latex:x?Du(I,x):I}),!0)).run(),!0)}if(G.current&&w.commands.setTextSelection(G.current),w.state.selection.empty&&!w.isActive("annotation"))return Ce(f("dialog.noteNeedsSelection")),!1;let A=w.chain().focus();return w.state.selection.empty&&A.extendMarkRange("annotation"),x?A.setMark("annotation",{note:x}):A.unsetMark("annotation"),A.run(),!0}async function zs(y,x=!1){if(!w||!w.isEditable)return;x&&G.current&&w.commands.setTextSelection(G.current);let A=w.state.selection.getBookmark(),$=({transaction:I})=>{A=A.map(I.mapping)};w.on("transaction",$);for(let I of y){if(!/^image\/(png|jpeg|gif|webp|avif)$/.test(I.type)){yt(c("notice.imageTypes"));continue}if(I.size>Qs.resourceBytes){yt(c("notice.imageTooLarge",{name:I.name,size:Zs(I.size),limit:Zs(Qs.resourceBytes)}));continue}let F;try{F=await new Promise((ke,Z)=>{let Be=new FileReader;Be.onload=()=>ke(String(Be.result)),Be.onerror=()=>Z(Be.error),Be.onabort=()=>Z(new Error(c("notice.readCancelled"))),Be.readAsDataURL(I)})}catch{yt(c("notice.imageUnreadable",{name:I.name}));continue}if(w.isDestroyed||!w.isEditable)break;let ne=A.resolve(w.state.doc);w.view.dispatch(w.state.tr.setSelection(ne)),w.chain().focus().setImage({src:F,alt:I.name}).run(),A=w.state.selection.getBookmark()}w.off("transaction",$),Le(null)}let Hs=(0,P.useMemo)(()=>[{id:"text",title:c("block.text"),keywords:`text paragraph ${c("block.textKeywords")}`,icon:(0,v.jsx)(zo,{size:20}),group:c("group.basic"),run:y=>{y.chain().focus().setParagraph().run()}},...[1,2,3,4,5,6].map(y=>({id:`heading-${y}`,title:c("block.heading",{level:y}),keywords:`heading h${y} ${c("block.headingKeywords")}`,icon:y===1?(0,v.jsx)(uu,{size:20}):y===2?(0,v.jsx)(du,{size:20}):(0,v.jsx)(fu,{size:20}),group:c("group.basic"),run:x=>{x.chain().focus().setHeading({level:y}).run()}})),{id:"bullet",title:c("block.bullet"),keywords:`bullet list ${c("block.bulletKeywords")}`,icon:(0,v.jsx)(Ws,{size:20}),group:c("group.basic"),run:y=>{y.chain().focus().toggleBulletList().run()}},{id:"ordered",title:c("block.ordered"),keywords:`ordered numbered list ${c("block.orderedKeywords")}`,icon:(0,v.jsx)(Fs,{size:20}),group:c("group.basic"),run:y=>{y.chain().focus().toggleOrderedList().run()}},{id:"todo",title:c("block.todo"),keywords:`todo task check ${c("block.todoKeywords")}`,icon:(0,v.jsx)(qs,{size:20}),group:c("group.basic"),run:y=>{y.chain().focus().toggleTaskList().run()}},{id:"quote",title:c("block.quote"),keywords:`blockquote quote ${c("block.quoteKeywords")}`,icon:(0,v.jsx)(Ks,{size:20}),group:c("group.basic"),run:y=>{y.chain().focus().toggleBlockquote().run()}},{id:"callout",title:c("block.callout"),keywords:`callout note ${c("block.calloutKeywords")}`,icon:(0,v.jsx)(mu,{size:20}),group:c("group.basic"),run:y=>{y.chain().focus().insertContent({type:"callout",attrs:{icon:"\u{1F4A1}",tone:"sage"},content:[{type:"paragraph",content:[{type:"text",text:"\u5728\u8FD9\u91CC\u8BB0\u5F55\u4E00\u4E2A\u503C\u5F97\u6CE8\u610F\u7684\u53D1\u73B0\u3002"}]}]}).run()}},{id:"toggle",title:c("block.toggle"),keywords:`toggle details ${c("block.toggleKeywords")}`,icon:(0,v.jsx)(Po,{size:20}),group:c("group.basic"),run:y=>{y.chain().focus().insertContent({type:"toggle",attrs:{title:"\u5C55\u5F00\u4E86\u89E3\u66F4\u591A",open:!0},content:[{type:"paragraph"}]}).run()}},{id:"stepper",title:c("block.stepper"),keywords:`stepper steps ${c("block.stepperKeywords")}`,icon:(0,v.jsx)(Yc,{size:20}),group:c("group.basic"),run:y=>{let x={type:"step",content:[{type:"paragraph"}]},{from:A}=y.state.selection;y.chain().focus().insertContent({type:"stepper",content:[x,x]}).command(({tr:$})=>{let I=-1;return $.doc.nodesBetween(Math.max(0,A-1),$.doc.content.size,(F,ne)=>(I<0&&F.type.name==="stepper"&&(I=ne),I<0)),I>=0&&$.setSelection(L.create($.doc,I+3)),!0}).run()}},{id:"divider",title:c("block.divider"),keywords:`divider hr ${c("block.dividerKeywords")}`,icon:(0,v.jsx)(gu,{size:20}),group:c("group.basic"),run:y=>{y.chain().focus().setHorizontalRule().run()}},{id:"image",title:c("block.image"),keywords:`image photo ${c("block.imageKeywords")}`,icon:(0,v.jsx)(Io,{size:20}),group:c("group.rich"),run:()=>ir("image")},{id:"code",title:c("block.code"),keywords:`code snippet ${c("block.codeKeywords")}`,icon:(0,v.jsx)(tu,{size:20}),group:c("group.rich"),run:y=>{y.chain().focus().toggleCodeBlock().run()}},{id:"table",title:c("block.table"),keywords:`table ${c("block.tableKeywords")}`,icon:(0,v.jsx)(Gs,{size:20}),group:c("group.rich"),run:y=>{y.chain().focus().insertTable({rows:3,cols:3,withHeaderRow:!0}).run()}},...Me.items.filter(y=>("kind"in y||y.role!=="page-outline")&&!("kind"in y&&el[y.kind])&&(!("kind"in y&&y.insertion)||!!i)).map(y=>({id:"catalog:"+("kind"in y?y.kind:`${y.id}@${y.version}#${y.integrity}`),title:Me.displayName(y),keywords:`${"kind"in y?y.kind:y.id} ${y.name} ${y.description} ${Me.displayDescription(y)}`,icon:(0,v.jsx)(bu,{size:20}),group:c("group.components"),component:y,run:()=>{}}))],[ir,i,Me.items,Me.displayName,Me.displayDescription,c]),vn=Hs.filter(y=>`${y.title} ${y.keywords}`.toLowerCase().includes(O?.query.toLowerCase()??""));S.current=vn;let _s=async y=>{let x=k.current,A=S.current[y];if(!(!w||!x||!A||N)){if(A.component){let $=w.state.doc,I=++ee.current;_(!0);try{let F=await Me.resolve(A.component);if(I!==ee.current||w.isDestroyed||k.current!==x||!w.state.doc.eq($))return;if(X(null),k.current=null,F.component&&Ne(F.component),F.native&&i){let ne=w.state.tr.delete(x.from,x.to);i(F.kind,F.data,nd(ne.doc,x.from))}else w.chain().focus().deleteRange({from:x.from,to:x.to}).insertContent({...el[F.kind]?Pu(F.kind,F.data):{type:"widget",attrs:{kind:F.kind,data:F.data}}}).run()}catch(F){yt(F.message)}finally{I===ee.current&&_(!1)}return}X(null),k.current=null,x.from!==x.to?w.chain().focus().deleteRange({from:x.from,to:x.to}).run():w.commands.focus(),A.run(w)}};M.current=_s;let Vs=()=>{if(!w)return;C.current=null;let{from:y,to:x}=w.state.selection;X({from:y,to:x,query:"",manual:!0,..._c(w,y)}),Se(0),at(!1)},ab=()=>{if(!w||!Y)return;let y=Y.pos+Y.size;w.chain().focus().insertContentAt(y,{type:"paragraph"}).setTextSelection(y+1).run(),X({from:y+1,to:y+1,query:"",manual:!0,..._c(w,y+1)}),me(!1)};function Kc(y,x){if(!w)return;let A=[];w.state.doc.forEach((Z,Be)=>A.push({pos:Be,size:Z.nodeSize}));let $=A.findIndex(Z=>Z.pos===y),I=A[$+x],F=w.state.doc.nodeAt(y);if(!I||!F)return;let ne=x===-1?I.pos:I.pos+I.size-F.nodeSize,ke=w.state.tr.delete(y,y+F.nodeSize).insert(ne,F);ke.setSelection(Q.near(ke.doc.resolve(ne+1))),w.view.dispatch(ke),w.view.focus(),me(!1),Ve(null)}function cb(y){if(!w||!w.isEditable)return;let x=E.current;if(x!==null){y.preventDefault(),y.stopPropagation(),E.current=null,Ve(null);let $=w.state.doc.nodeAt(x);if(!$)return;let I=w.state.doc.content.size,F=!1;if(w.state.doc.forEach((ne,ke)=>{let Z=w.view.nodeDOM(ke);if(!(Z instanceof HTMLElement)||F)return;let Be=Z.getBoundingClientRect();y.clientY<Be.top+Be.height/2&&(I=ke,F=!0)}),I!==x&&I!==x+$.nodeSize){let ne=I>x?I-$.nodeSize:I,ke=w.state.tr.delete(x,x+$.nodeSize).insert(ne,$);ke.setSelection(Q.near(ke.doc.resolve(ne+1))),w.view.dispatch(ke)}return}let A=[...y.dataTransfer.files].filter($=>$.type.startsWith("image/"));if(A.length){y.preventDefault(),y.stopPropagation();let $=w.view.posAtCoords({left:y.clientX,top:y.clientY});$&&w.commands.setTextSelection($.pos),zs(A)}}if(!w)return(0,v.jsx)("div",{className:"editor-loading","aria-label":c("openingDocument")});let Uc=Y&&Ze?w.state.doc.nodeAt(Y.pos):null,qc=Uc?.type.name==="widget"&&!td(String(Uc.attrs.kind??"")),ub=w.isActive("heading")?c("block.heading",{level:w.getAttributes("heading").level}):c("block.text"),db=qe&&$e?Ti(w.state.doc,w.state.selection.from,w.state.selection.to).length:0,fb=St?$i:Y1,Gc=(!r||qe)&&(0,v.jsx)(Xh,{editor:w,onLink:()=>ir("link"),onNote:()=>ir("note")});return(0,v.jsxs)("div",{className:`document-editor${n?" is-readonly":""}${r?" is-minimal":""}`,children:[!n&&!r&&(0,v.jsxs)("div",{className:"editor-toolbar",role:"toolbar","aria-label":c("format.toolbar"),children:[(0,v.jsxs)("div",{className:"toolbar-style",children:[(0,v.jsxs)("button",{className:"text-style-button",onMouseDown:y=>y.preventDefault(),onClick:()=>{tn(!kn),at(!1)},"aria-expanded":kn,children:[ub,(0,v.jsx)(sr,{size:13})]}),kn&&(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)("div",{className:"editor-menu-dismiss",onClick:()=>tn(!1)}),(0,v.jsx)("div",{className:"editor-small-menu style-menu",children:Hs.slice(0,7).map(y=>(0,v.jsxs)("button",{onMouseDown:x=>x.preventDefault(),onClick:()=>{y.run(w),tn(!1)},children:[y.icon,(0,v.jsx)("span",{children:y.title})]},y.id))})]})]}),(0,v.jsx)("span",{className:"toolbar-divider"}),Gc,(0,v.jsx)("span",{className:"toolbar-divider"}),(0,v.jsx)(Bt,{label:c("block.bullet"),active:w.isActive("bulletList"),onClick:()=>w.chain().focus().toggleBulletList().run(),children:(0,v.jsx)(Ws,{size:17})}),(0,v.jsx)(Bt,{label:c("block.todo"),active:w.isActive("taskList"),onClick:()=>w.chain().focus().toggleTaskList().run(),children:(0,v.jsx)(qs,{size:16})}),(0,v.jsxs)("div",{className:"toolbar-insert",children:[(0,v.jsx)(Bt,{label:c("format.more"),active:xt,onClick:()=>{at(!xt),tn(!1)},children:(0,v.jsx)(Ht,{size:17})}),xt&&(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)("div",{className:"editor-menu-dismiss",onClick:()=>at(!1)}),(0,v.jsxs)("div",{className:"editor-small-menu insert-menu",children:[(0,v.jsxs)("button",{onClick:Vs,children:[(0,v.jsx)(Ht,{size:16}),c("insert.content"),(0,v.jsx)("span",{className:"menu-key",children:"/"})]}),(0,v.jsxs)("button",{onClick:()=>{w.chain().focus().toggleOrderedList().run(),at(!1)},children:[(0,v.jsx)(Fs,{size:16}),c("block.ordered")]}),(0,v.jsxs)("button",{onClick:()=>{w.chain().focus().toggleBlockquote().run(),at(!1)},children:[(0,v.jsx)(Ks,{size:16}),c("block.quote")]}),(0,v.jsxs)("button",{onClick:()=>ir("image"),children:[(0,v.jsx)(Io,{size:16}),c("insert.image")]}),(0,v.jsxs)("button",{onClick:()=>{w.chain().focus().insertTable({rows:3,cols:3,withHeaderRow:!0}).run(),at(!1)},children:[(0,v.jsx)(Gs,{size:16}),c("insert.table")]}),(0,v.jsx)("div",{className:"menu-rule"}),(0,v.jsxs)("div",{className:"align-tools",children:[(0,v.jsx)(Bt,{label:c("format.alignLeft"),active:w.isActive({textAlign:"left"}),onClick:()=>w.chain().focus().setTextAlign("left").run(),children:(0,v.jsx)(Tn,{size:17})}),(0,v.jsx)(Bt,{label:c("format.alignCenter"),active:w.isActive({textAlign:"center"}),onClick:()=>w.chain().focus().setTextAlign("center").run(),children:(0,v.jsx)(Mn,{size:17})}),(0,v.jsx)(Bt,{label:c("format.alignRight"),active:w.isActive({textAlign:"right"}),onClick:()=>w.chain().focus().setTextAlign("right").run(),children:(0,v.jsx)(An,{size:17})})]})]})]})]}),(0,v.jsx)("div",{className:"toolbar-spacer"}),(0,v.jsx)(Bt,{label:c("format.undo"),disabled:!w.can().undo(),onClick:()=>w.chain().focus().undo().run(),children:(0,v.jsx)(Mu,{size:16})}),(0,v.jsx)(Bt,{label:c("format.redo"),disabled:!w.can().redo(),onClick:()=>w.chain().focus().redo().run(),children:(0,v.jsx)(yu,{size:16})})]}),(0,v.jsxs)("div",{className:"editor-canvas",ref:g,onKeyDown:y=>{(y.metaKey||y.ctrlKey)&&y.shiftKey&&y.key.toLowerCase()==="k"&&!n&&(y.preventDefault(),y.stopPropagation(),ir("link"))},onMouseEnter:Ct,onMouseMove:y=>{if(n||Ze||E.current!==null)return;if(y.target.closest(".block-handle")){Ct();return}let x=g.current;x&&y.target.closest(".document-editor")===x.closest(".document-editor")&&(Hr.current=y.clientY,!wn.current&&(wn.current=requestAnimationFrame(()=>{wn.current=0;let A=g.current;if(!A||E.current!==null||w.isDestroyed)return;let $=Hr.current,I=A.getBoundingClientRect(),F=I.width/A.offsetWidth||1,ne=null;w.state.doc.forEach((Z,Be,Cn)=>{let nn=w.view.nodeDOM(Be);if(!(nn instanceof HTMLElement))return;let xn=nn.getBoundingClientRect();$>=xn.top-3&&$<=xn.bottom+3&&(ne={pos:Be,size:Z.nodeSize,index:Cn,top:(xn.top-I.top)/F})});let ke=ne;ke?(Ct(),Ve(Z=>Z&&Z.pos===ke.pos&&Z.size===ke.size&&Z.index===ke.index&&Math.abs(Z.top-ke.top)<.5?Z:ke)):Do()})))},onMouseLeave:Do,onDragOver:y=>{(E.current!==null||[...y.dataTransfer.types].includes("Files"))&&y.preventDefault()},onDropCapture:cb,children:[(0,v.jsx)(Ai,{editor:w}),!n&&(0,v.jsx)(Jh,{editor:w}),!n&&Y&&(0,v.jsxs)("div",{className:"block-handle",style:{top:Y.top},onMouseEnter:Ct,onFocus:Ct,children:[(0,v.jsx)("button",{"aria-label":c("insert.addBelow"),title:c("insert.addContent"),onMouseDown:y=>y.preventDefault(),onClick:ab,children:(0,v.jsx)(Ht,{size:15})}),(0,v.jsx)("button",{"aria-label":c("block.handle"),title:c("block.handleTitle"),draggable:!0,onDragStart:y=>{Ct(),E.current=Y.pos,y.dataTransfer.effectAllowed="move",y.dataTransfer.setData("application/x-showai-block",String(Y.pos));let x=w.view.nodeDOM(Y.pos);x instanceof HTMLElement&&y.dataTransfer.setDragImage(x,0,0),me(!1)},onDragEnd:()=>{E.current=null},onClick:()=>me(!Ze),children:(0,v.jsx)(cu,{size:15})}),Ze&&(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)("div",{className:"editor-menu-dismiss",onClick:()=>me(!1)}),(0,v.jsxs)("div",{className:"editor-small-menu block-menu",children:[r&&["paragraph","heading"].includes(w.state.doc.nodeAt(Y.pos)?.type.name??"")&&(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)("div",{className:"align-tools",role:"group","aria-label":c("block.style"),children:Hs.slice(0,7).map((y,x)=>(0,v.jsx)(Bt,{label:y.title,active:x===0?w.state.doc.nodeAt(Y.pos)?.type.name==="paragraph":w.state.doc.nodeAt(Y.pos)?.attrs.level===x,onClick:()=>{w.chain().focus().setTextSelection(Y.pos+1).run(),y.run(w),me(!1)},children:y.icon},y.id))}),(0,v.jsx)("div",{className:"align-tools",children:[["left",c("format.alignLeft"),(0,v.jsx)(Tn,{size:16},"left")],["center",c("format.alignCenter"),(0,v.jsx)(Mn,{size:16},"center")],["right",c("format.alignRight"),(0,v.jsx)(An,{size:16},"right")]].map(([y,x,A])=>(0,v.jsx)(Bt,{label:x,active:w.state.doc.nodeAt(Y.pos)?.attrs.textAlign===y,onClick:()=>{w.chain().focus().setTextSelection(Y.pos+1).setTextAlign(y).run(),me(!1)},children:A},y))}),(0,v.jsx)("div",{className:"menu-rule"})]}),(0,v.jsx)(ed,{editor:w,position:Y.pos,onDone:()=>me(!1)}),s&&(0,v.jsxs)("button",{onClick:()=>{let y=w.state.doc.nodeAt(Y.pos);y&&s(y.toJSON()),me(!1),Ve(null)},children:[(0,v.jsx)(su,{size:15}),c("block.detach")]}),(0,v.jsxs)("button",{disabled:Y.index===0,onClick:()=>Kc(Y.pos,-1),children:[(0,v.jsx)(Qc,{size:15}),c("block.moveUp")]}),(0,v.jsxs)("button",{disabled:Y.index===w.state.doc.childCount-1,onClick:()=>Kc(Y.pos,1),children:[(0,v.jsx)(Xc,{size:15}),c("block.moveDown")]}),(0,v.jsxs)("button",{onClick:()=>{let y=w.state.doc.nodeAt(Y.pos);y&&w.chain().focus().insertContentAt(Y.pos+y.nodeSize,y.toJSON()).run(),me(!1)},children:[(0,v.jsx)(ru,{size:15}),c("block.duplicate")]}),qc&&(0,v.jsx)("p",{className:"block-menu-note",children:c("block.noManualEditing")}),$e&&(0,v.jsxs)("button",{onClick:y=>{let x=w.state.doc.nodeAt(Y.pos)?.attrs.id,A=y.currentTarget.closest(".block-handle").getBoundingClientRect();me(!1),typeof x=="string"&&!Hc(x)&&$e.open({kind:"blocks",blockIds:[x],anchor:{left:A.right+160,top:A.top,bottom:A.bottom}})},children:[(0,v.jsx)(Us,{size:15}),qc?c("assistant.editComponent"):d("askAgent")]}),$e&&(0,v.jsxs)("button",{onClick:y=>{let x=w.state.doc.nodeAt(Y.pos)?.attrs.id,A=y.currentTarget.closest(".block-handle").getBoundingClientRect();me(!1),typeof x=="string"&&!Hc(x)&&$e.reference({kind:"blocks",blockIds:[x],anchor:{left:A.right,top:A.top,bottom:A.bottom}})},children:[(0,v.jsx)(js,{size:15}),d("copyReference")]}),xe&&(0,v.jsxs)("button",{onClick:()=>{let y=w.state.doc.nodeAt(Y.pos)?.attrs.id;me(!1),typeof y=="string"&&!Hc(y)&&xe.copyLink([y])},children:[(0,v.jsx)(Fr,{size:15}),d("copyLink")]}),(0,v.jsx)("div",{className:"menu-rule"}),(0,v.jsxs)("button",{className:"danger",onClick:()=>{w.chain().focus().deleteRange({from:Y.pos,to:Y.pos+Y.size}).run(),me(!1),Ve(null)},children:[(0,v.jsx)(Bo,{size:15}),d("delete")]})]})]})]})]}),!n&&!r&&(0,v.jsxs)("button",{className:"document-add-block",onClick:()=>{w.chain().focus("end").run(),(w.state.selection.$from.parent.type.name!=="paragraph"||w.state.selection.$from.parent.content.size)&&w.chain().insertContentAt(w.state.doc.content.size,{type:"paragraph"}).focus("end").run(),Vs()},children:[(0,v.jsx)(Ht,{size:15}),(0,v.jsx)("span",{children:c("insert.addContent")}),(0,v.jsx)("kbd",{children:"/"})]}),(0,v.jsx)("input",{ref:m,type:"file",accept:"image/png,image/jpeg,image/gif,image/webp,image/avif",className:"editor-hidden-input",onChange:y=>{let x=y.target.files?.[0];x&&zs([x],!0),y.target.value=""}}),ge&&(0,v.jsxs)("div",{className:"editor-notice",role:"status",children:[ge,(0,v.jsx)("button",{"aria-label":c("dismissNotice"),onClick:()=>yt(""),children:(0,v.jsx)(Wr,{size:14})})]}),qe&&!n&&(0,v.jsxs)(Xu,{id:h,className:"rich-text-selection-toolbar",anchor:qe,viewportTop:Math.max(0,...Array.from(g.current?.closest(".studio")?.querySelectorAll(".studio-window-topbar, .studio-topbar")??[],y=>y.getBoundingClientRect().bottom))+8,onEscape:()=>{D.current=!1,Et.current=`${w.state.selection.from}:${w.state.selection.to}`,w.state.selection instanceof se&&w.view.dispatch(w.state.tr.setSelection(L.near(w.state.selection.$from))),et(null),w.view.focus()},children:[Gc,(0,v.jsx)(Bi,{editor:w}),$e&&(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)("span",{className:"toolbar-divider","aria-hidden":"true"}),(0,v.jsxs)("button",{type:"button",className:"editor-bubble-assistant","aria-label":d("askAgent"),title:d("askAgent"),onClick:()=>{let{from:y,to:x}=w.state.selection,A=qe;D.current=!1,et(null),$e.open({kind:"text",blockIds:Ti(w.state.doc,y,x),text:w.state.doc.textBetween(y,x,`
156
156
  `),anchor:A})},children:[(0,v.jsx)(Us,{size:15}),(0,v.jsx)("span",{children:d("askAgent")})]}),(0,v.jsx)("button",{type:"button",className:"editor-tool editor-bubble-reference","aria-label":d("copyReference"),title:c("assistant.referenceSelection",{count:db}),onClick:()=>{let{from:y,to:x}=w.state.selection,A=qe;D.current=!1,et(null),$e.reference({kind:"text",blockIds:Ti(w.state.doc,y,x),text:w.state.doc.textBetween(y,x,`
157
157
  `),anchor:A})},children:(0,v.jsx)(js,{size:16})})]}),(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)("span",{className:"toolbar-divider","aria-hidden":"true"}),(0,v.jsxs)("button",{type:"button",className:"editor-bubble-insert","aria-label":c("insert.fromSelection"),title:c("insert.fromSelectionTitle"),onMouseDown:y=>y.preventDefault(),onClick:()=>{let y=w.state.selection.$to.end();D.current=!1,et(null),w.commands.setTextSelection(y),Vs(),setTimeout(()=>b.current?.focus(),0)},children:[(0,v.jsx)(Ht,{size:15}),(0,v.jsx)("span",{children:c("insert.fromSelection")})]})]})]}),O&&!n&&(0,Vc.createPortal)((0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)("div",{className:"slash-dismiss",onClick:()=>{Vr(),w.commands.focus()}}),(0,v.jsxs)("div",{className:`slash-menu${r?" is-minimal":""}`,role:"dialog","aria-label":c("insert.content"),style:{left:O.left,top:O.top},children:[(0,v.jsxs)("div",{className:"slash-search",children:[O.manual?(0,v.jsx)(Fu,{label:c("insert.search"),placeholder:c("insert.searchPlaceholder"),defaultExpanded:!0,inputRef:b,value:O.query,onChange:y=>X({...O,query:y}),onKeyDown:y=>{y.key==="Escape"&&(Vr(),w.commands.focus()),y.key==="Enter"&&(y.preventDefault(),_s(ue)),(y.key==="ArrowDown"||y.key==="ArrowUp")&&(y.preventDefault(),Se(x=>vn.length?(x+(y.key==="ArrowDown"?1:-1)+vn.length)%vn.length:0))}}):(0,v.jsx)("span",{children:O.query||c("insert.addToDocument")}),(0,v.jsx)("kbd",{children:"esc"})]}),(0,v.jsxs)("div",{className:"slash-items",role:"listbox","aria-label":c("insert.blockTypes"),"aria-busy":N||Me.loading,children:[Me.error&&(0,v.jsx)("p",{role:"alert",className:"slash-empty",children:Me.error}),vn.length===0&&(0,v.jsx)("div",{className:"slash-empty",children:c("insert.noResults")}),vn.map((y,x)=>(0,v.jsxs)("div",{children:[(x===0||vn[x-1].group!==y.group)&&(0,v.jsx)("div",{className:"slash-group",children:y.group}),(0,v.jsxs)("button",{role:"option",disabled:N,"aria-selected":x===ue,className:`slash-item${x===ue?" is-selected":""}`,onMouseEnter:()=>Se(x),onMouseDown:A=>A.preventDefault(),onClick:()=>_s(x),children:[(0,v.jsx)("span",{className:"slash-item-icon",children:y.icon}),(0,v.jsx)("span",{children:(0,v.jsx)("strong",{children:y.title})}),x===ue&&(0,v.jsx)("span",{className:"slash-enter",children:"\u21B5"})]})]},y.id))]})]})]}),document.body),U&&(0,Vc.createPortal)((0,v.jsx)(fb,{className:St?"editor-format-panel":"editor-modal-backdrop",onDismiss:()=>{Le(null),w.commands.focus()},children:(0,v.jsxs)("form",{className:"editor-modal",role:"dialog","aria-modal":St?void 0:!0,"aria-labelledby":"editor-dialog-title",onKeyDown:y=>{y.key==="Escape"&&Le(null)},onSubmit:y=>{y.preventDefault();let x=U.value.trim();if(U.type==="image"&&!Q1(x)){Ce(c("dialog.invalidImageUrl"));return}let A=U.type==="link"?Mt[Oo]?.href??x:x;if(U.type==="link"&&A&&!lb(A)){Ce(c("dialog.invalidLinkUrl"));return}if(U.type==="note"){if(!Wc(U,x))return;Le(null);return}if(U.type==="link"){Fc(A);return}G.current&&w.commands.setTextSelection(G.current),w.chain().focus().setImage({src:x,alt:U.alt}).run(),Le(null)},children:[(0,v.jsxs)("div",{className:"editor-modal-heading",children:[(0,v.jsx)("div",{className:"editor-modal-symbol",children:U.type==="image"?(0,v.jsx)(Io,{size:21}):U.type==="note"?(0,v.jsx)($o,{size:21}):(0,v.jsx)(Fr,{size:21})}),(0,v.jsx)("h3",{id:"editor-dialog-title",children:U.type==="image"?c("insert.image"):U.type==="note"?f(U.hadNote?"dialog.editNote":"dialog.addNote"):c("dialog.addLink")}),(0,v.jsx)("button",{type:"button","aria-label":c("dialog.close"),"data-no-tooltip":!0,onClick:()=>Le(null),children:(0,v.jsx)(Wr,{size:18})})]}),U.type==="image"&&(0,v.jsxs)("button",{className:"image-upload-area",type:"button",onClick:()=>m.current?.click(),children:[(0,v.jsx)(Au,{size:23}),(0,v.jsx)("strong",{children:c("dialog.chooseImage")}),(0,v.jsx)("span",{children:c("dialog.imageFormats")})]}),U.type==="note"&&(0,v.jsxs)("label",{className:"editor-field",children:[(0,v.jsx)("span",{children:U.math?f("dialog.noteFormula"):f("dialog.noteText")}),(0,v.jsx)("textarea",{autoFocus:!0,rows:4,maxLength:1e3,placeholder:f("dialog.notePlaceholder"),value:U.value,onChange:y=>{Le({...U,value:y.target.value}),Ce("")},onKeyDown:y=>{y.key==="Enter"&&(y.metaKey||y.ctrlKey)&&(y.preventDefault(),y.currentTarget.form?.requestSubmit())}}),(0,v.jsx)("small",{children:f("dialog.noteHint")})]}),U.type!=="note"&&(0,v.jsxs)("label",{className:"editor-field",children:[(0,v.jsx)("span",{children:U.type==="image"?c("dialog.imageUrl"):c("dialog.linkUrl")}),(0,v.jsx)("input",{autoFocus:!0,type:"text",placeholder:U.type==="link"&&xe?c("dialog.linkOrPage"):"https://",value:U.value,role:Mt.length?"combobox":void 0,"aria-expanded":Mt.length?!0:void 0,"aria-controls":Mt.length?"editor-link-pages":void 0,"aria-activedescendant":Mt[Oo]?`editor-link-page-${Oo}`:void 0,onChange:y=>{Le({...U,value:y.target.value}),Ce("")},onKeyDown:y=>{if(!Mt.length||!["ArrowDown","ArrowUp"].includes(y.key))return;y.preventDefault();let x=y.key==="ArrowDown"?1:-1;Bs(A=>(A+x+Mt.length)%Mt.length)}})]}),Mt.length>0&&(0,v.jsx)("ul",{className:"editor-link-pages",id:"editor-link-pages",role:"listbox","aria-label":c("dialog.linkPages"),children:Mt.map((y,x)=>(0,v.jsxs)("li",{id:`editor-link-page-${x}`,role:"option","aria-selected":x===Oo,onMouseEnter:()=>Bs(x),onMouseDown:A=>A.preventDefault(),onClick:()=>Fc(y.href),children:[(0,v.jsx)(au,{size:14}),(0,v.jsx)("span",{children:y.title||c("dialog.untitledPage")})]},y.id))}),U.type==="image"&&(0,v.jsxs)("label",{className:"editor-field",children:[(0,v.jsxs)("span",{children:[c("dialog.imageAlt")," ",(0,v.jsx)("small",{children:c("dialog.optional")})]}),(0,v.jsx)("input",{placeholder:c("dialog.imageAltPlaceholder"),value:U.alt,onChange:y=>Le({...U,alt:y.target.value})})]}),_r&&(0,v.jsx)("p",{className:"editor-field-error",role:"alert",children:_r}),(0,v.jsxs)("div",{className:"editor-modal-actions",children:[U.type==="link"&&w.isActive("link")&&(0,v.jsx)("button",{type:"button",className:"editor-text-action",onClick:()=>{w.chain().focus().extendMarkRange("link").unsetLink().run(),Le(null)},children:c("dialog.removeLink")}),U.type==="note"&&U.hadNote&&(0,v.jsx)("button",{type:"button",className:"editor-text-action",onClick:()=>{Wc(U,"")&&Le(null)},children:f("dialog.removeNote")}),(0,v.jsx)("button",{type:"button",className:"editor-secondary",onClick:()=>Le(null),children:c("dialog.cancel")}),(0,v.jsxs)("button",{type:"submit",className:"editor-primary",disabled:(U.type==="image"||U.type==="note")&&!U.value.trim(),children:[(0,v.jsx)(eu,{size:15}),U.type==="image"?c("insert.image"):c("dialog.confirm")]})]})]})}),St??document.body),n&&(0,v.jsxs)("span",{className:"editor-readonly-note",children:[(0,v.jsx)(lu,{size:12}),c("readOnlyNote")]})]})}export{Z1 as default};
package/index.js CHANGED
@@ -1 +1 @@
1
- export * from "./reader-NS6OEZ2Y.js";
1
+ export * from "./reader-Q7ROTYAU.js";
package/manifest.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "format": "showai-cdn-reader",
3
3
  "name": "showai-reader",
4
- "version": "0.11.0-reader.ns6oez2y",
5
- "entry": "reader-NS6OEZ2Y.js",
6
- "integrity": "sha256-axX8POq2FoyFaXoAcj8RyJ8ZlyP39THokVcSP30us70=",
4
+ "version": "0.11.0-reader.q7rotyau",
5
+ "entry": "reader-Q7ROTYAU.js",
6
+ "integrity": "sha256-8MNpwjRkU35V7zbizZJVpRvzidqs8Dfv9ek2FcKeGU4=",
7
7
  "files": 52,
8
- "bytes": 13760261
8
+ "bytes": 13768145
9
9
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "showai-reader",
3
- "version": "0.11.0-reader.ns6oez2y",
3
+ "version": "0.11.0-reader.q7rotyau",
4
4
  "description": "ShowAI page reader as code-split ES modules, for inline pages loaded from a CDN.",
5
5
  "type": "module",
6
6
  "exports": {