@aiquants/markdown-explorer 0.32.0 → 0.34.0
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/CHANGELOG.md +327 -0
- package/README.md +33 -19
- package/dist/{EditSurface-BPqqykro.cjs → EditSurface-CF82jZQg.cjs} +5 -5
- package/dist/{EditSurface-BmbDSrrw.js → EditSurface-CqHk2R3k.js} +73 -63
- package/dist/ExplorerSplit-D325YGEf.cjs +1 -0
- package/dist/ExplorerSplit-DGH9bckm.js +1500 -0
- package/dist/MultiLayout-CzR7yJ0m.cjs +1 -0
- package/dist/{MultiLayout-DKgZ1sBK.js → MultiLayout-kcZyVnvK.js} +176 -176
- package/dist/NativeScrollBar-UNed10Na.js +62 -0
- package/dist/NativeScrollBar-pUbA4Zq3.cjs +1 -0
- package/dist/TreeLayout-BnIU87HX.js +96 -0
- package/dist/TreeLayout-DtvIpuOe.cjs +1 -0
- package/dist/core/geometry.d.cts +1 -0
- package/dist/core/geometry.d.ts +1 -0
- package/dist/core/labels.d.cts +10 -0
- package/dist/core/labels.d.ts +10 -0
- package/dist/core/location.d.cts +2 -0
- package/dist/core/location.d.ts +2 -0
- package/dist/core/viewSettings.d.cts +2 -0
- package/dist/core/viewSettings.d.ts +2 -0
- package/dist/{dataRoute-DLhQfdoW.js → dataRoute-D6KiSHIc.js} +20 -20
- package/dist/index-BDCbvHDs.cjs +15 -0
- package/dist/{index-CcXMPCRS.js → index-DR31S_-4.js} +2029 -1929
- package/dist/index.cjs +1 -1
- package/dist/index.js +17 -17
- package/dist/{location-perTmwct.js → location-C44b9H1S.js} +291 -278
- package/dist/location-hGLhCCg4.cjs +1 -0
- package/dist/{merge-DZI4pkWI.cjs → merge-BziXxZkE.cjs} +1 -1
- package/dist/{merge-3xGYZqbE.js → merge-C1MWvhCS.js} +1 -1
- package/dist/{sanitizePolicy-By0tKOpZ.js → sanitizePolicy-CwvyPpp5.js} +1 -1
- package/dist/sanitizeWorker.js +1 -1
- package/dist/server.cjs +1 -1
- package/dist/server.js +4 -4
- package/dist/styles/markdown-explorer.css +1 -1
- package/dist/tapScrollCircle-D_BpaLwY.js +14 -0
- package/dist/tapScrollCircle-DigcJCsu.cjs +1 -0
- package/dist/useSplitPersistence-DCeYbJMx.js +38 -0
- package/dist/useSplitPersistence-QGcvyMAa.cjs +1 -0
- package/docs/behavior/dom-hooks.md +12 -3
- package/docs/behavior/layout.md +73 -23
- package/docs/behavior/localization.md +4 -3
- package/docs/behavior/security.md +2 -1
- package/docs/behavior/url-contract.md +11 -5
- package/package.json +11 -11
- package/dist/ExplorerSplit-CQxr6b0v.cjs +0 -1
- package/dist/ExplorerSplit-DPuXOBqs.js +0 -1493
- package/dist/MultiLayout-TXbet9k3.cjs +0 -1
- package/dist/NativeScrollBar-C1CtjwBm.js +0 -64
- package/dist/NativeScrollBar-UpjxjLlB.cjs +0 -1
- package/dist/TreeLayout-BpazybVQ.js +0 -72
- package/dist/TreeLayout-C0O1OGi4.cjs +0 -1
- package/dist/index-DSkK8iLE.cjs +0 -15
- package/dist/location-BxiJRTyw.cjs +0 -1
- package/dist/tapScrollCircle-Cbf17x8g.cjs +0 -1
- package/dist/tapScrollCircle-DacgW2F_.js +0 -12
- package/dist/useSplitPersistence-Du01PHNg.js +0 -42
- package/dist/useSplitPersistence-pPmE4GTT.cjs +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const q=require("react/jsx-runtime"),h=require("react"),
|
|
2
|
-
`);e.dispatch({changes:{from:d,to:f,insert:p},selection:$.EditorSelection.cursor(d),scrollIntoView:!0,userEvent:"input.resolve"})},
|
|
3
|
-
`:v.content}return{kind:"found",firstLine:t+1,lines:c,layout:d,body:E}},tt=({parent:e,scroll:t,text:n,saved:r,labels:i,revisions:o,onChange:l,onGeometry:s,onSave:d})=>{let f=!1;const p=[P.EditorView.scrollHandler.of((u,m,v)=>(nt(u,m.head,v,t),!0)),P.lineNumbers(),P.highlightActiveLineGutter(),K.history(),P.drawSelection(),P.highlightActiveLine(),ge.highlightSelectionMatches(),P.EditorView.lineWrapping,pe.markdown({base:pe.markdownLanguage}),Je,oe.syntaxHighlighting(Fe),Ke(i),P.keymap.of([{key:"Mod-s",preventDefault:!0,run:()=>(d(),!0)},...ge.searchKeymap,...K.historyKeymap,...K.defaultKeymap]),P.EditorView.contentAttributes.of({"aria-label":i.editor,"aria-multiline":"true"}),P.EditorView.updateListener.of(u=>{for(const m of u.transactions)m.docChanged&&o.record(m.changes,m.newDoc);u.docChanged&&l(u.transactions.every(m=>!m.docChanged||m.isUserEvent(
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const q=require("react/jsx-runtime"),h=require("react"),x=require("./index-BDCbvHDs.cjs"),J=require("@aiquants/markdown/code-blocks"),K=require("@codemirror/commands"),pe=require("@codemirror/lang-markdown"),oe=require("@codemirror/language"),ge=require("@codemirror/search"),$=require("@codemirror/state"),P=require("@codemirror/view"),V=require("@lezer/highlight"),He=require("@aiquants/markdown"),ue=require("@aiquants/markdown/source-lines"),ee=require("./dataRoute-DwYtgyt6.cjs"),de=require("./sanitizePolicy-T5T-3vV5.cjs"),je=require("isomorphic-dompurify"),se=require("@aiquants/resize-panels"),X=require("./location-hGLhCCg4.cjs"),ze=require("./useSplitPersistence-QGcvyMAa.cjs"),Ce={history:K.historyField},Fe=oe.HighlightStyle.define([{tag:[V.tags.heading1,V.tags.heading2,V.tags.heading3,V.tags.heading4,V.tags.heading5,V.tags.heading6,V.tags.heading],color:"var(--aqmx-syntax-heading)",fontWeight:"700"},{tag:V.tags.strong,fontWeight:"700"},{tag:V.tags.emphasis,fontStyle:"italic"},{tag:V.tags.strikethrough,textDecoration:"line-through"},{tag:V.tags.link,color:"var(--aqmx-syntax-link)",textDecoration:"underline"},{tag:V.tags.url,color:"var(--aqmx-syntax-url)"},{tag:V.tags.monospace,color:"var(--aqmx-syntax-code)"},{tag:V.tags.quote,color:"var(--aqmx-syntax-quote)"},{tag:[V.tags.processingInstruction,V.tags.contentSeparator,V.tags.labelName,V.tags.meta],color:"var(--aqmx-syntax-mark)"}]),Ue=P.EditorView.theme({"&":{height:"100%",color:"var(--aqmx-text)",backgroundColor:"var(--aqmx-surface)",fontSize:"var(--aqmx-font-size-title)"},"&.cm-focused":{outline:"none"},".cm-scroller":{fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace',lineHeight:"var(--aqmx-line-height-prose)"},".cm-content":{caretColor:"var(--aqmx-text)",paddingBlock:"var(--aqmx-space-6)"},".cm-line":{paddingInline:"var(--aqmx-space-6)"},"&.cm-focused .cm-cursor":{borderLeftColor:"var(--aqmx-text)"},"&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection":{backgroundColor:"var(--aqmx-editor-selection)"},".cm-activeLine":{backgroundColor:"var(--aqmx-editor-active-line)"},".cm-gutters":{backgroundColor:"var(--aqmx-surface-raised)",color:"var(--aqmx-editor-gutter)",borderInlineEnd:"var(--aqmx-space-1) solid var(--aqmx-border)"},".cm-activeLineGutter":{backgroundColor:"var(--aqmx-editor-active-line)"},".cm-searchMatch":{outline:"var(--aqmx-space-1) solid var(--aqmx-border-strong)"},".cm-panels":{backgroundColor:"var(--aqmx-surface-raised)",color:"var(--aqmx-text)"}}),qe="data-aqmx-conflict-actions",Ge=P.Decoration.line({attributes:{"data-aqmx-conflict-line":"marker"}}),We=P.Decoration.line({attributes:{"data-aqmx-conflict-line":"ours"}}),Xe=P.Decoration.line({attributes:{"data-aqmx-conflict-line":"theirs"}});class $e extends P.WidgetType{constructor(t,n){super(),this.index=t,this.labels=n}index;labels;eq(t){return t.index===this.index&&t.labels===this.labels}toDOM(t){const n=document.createElement("div");n.setAttribute(qe,String(this.index));for(const[r,i]of[["ours",this.labels.useOurs],["theirs",this.labels.useTheirs],["both",this.labels.keepBoth]]){const o=document.createElement("button");o.type="button",o.textContent=i,o.setAttribute("data-aqmx-conflict-choice",r),o.addEventListener("mousedown",l=>l.preventDefault()),o.addEventListener("click",()=>{const l=re(t.state.doc)[this.index];l!==void 0&&(Me(t,l,r),t.focus())}),n.append(o)}return n}ignoreEvent(){return!0}}const re=e=>x.findConflictsInLines(e.iterLines()),ve=(e,t)=>{const n=new $.RangeSetBuilder;return re(e).forEach((r,i)=>{const o=e.line(r.start);n.add(o.from,o.from,P.Decoration.widget({widget:new $e(i,t),block:!0,side:-1}));for(let l=r.start;l<=r.end;l+=1){const s=e.line(l).from,d=l===r.start||l===r.separator||l===r.end?Ge:l<r.separator?We:Xe;n.add(s,s,d)}}),n.finish()},Ke=e=>$.StateField.define({create:t=>ve(t.doc,e),update:(t,n)=>n.docChanged?ve(n.state.doc,e):t,provide:t=>P.EditorView.decorations.from(t)}),Me=(e,t,n)=>{const{doc:r}=e.state,i=(k,c)=>{const E=[];for(let u=k;u<=c;u+=1)E.push(r.line(u).text);return E},o=i(t.start+1,t.separator-1),l=i(t.separator+1,t.end-1),s=n==="ours"?o:n==="theirs"?l:[...o,...l];let d=r.line(t.start).from,f=r.line(t.end).to;s.length===0&&(t.end<r.lines?f+=1:t.start>1&&(d-=1));const p=s.join(`
|
|
2
|
+
`);e.dispatch({changes:{from:d,to:f,insert:p},selection:$.EditorSelection.cursor(d),scrollIntoView:!0,userEvent:"input.resolve"})},we="input.preview",Ye=20,Je=P.ViewPlugin.fromClass(class{constructor(e){this.view=e,this.schedule()}view;cancel=null;update(e){e.docChanged&&this.schedule()}schedule(){if(this.cancel!==null||oe.syntaxTreeAvailable(this.view.state))return;const e=this.view.dom.ownerDocument.defaultView;if(e===null)return;const t=()=>{this.cancel=null,oe.ensureSyntaxTree(this.view.state,this.view.state.doc.length,Ye),this.schedule()};if(typeof e.requestIdleCallback=="function"){const n=e.requestIdleCallback(t);this.cancel=()=>e.cancelIdleCallback(n)}else{const n=e.setTimeout(t,0);this.cancel=()=>e.clearTimeout(n)}}destroy(){this.cancel?.(),this.cancel=null}}),Qe=/`{3,}|~{3,}/u,te=Object.freeze({kind:"absent"}),ce=Object.freeze({kind:"unreadable"}),Ze=(e,t,n)=>{const r=[];for(let d=t.parent;d!==null;d=d.parent)(d.name==="Blockquote"||d.name==="ListItem")&&r.unshift(d);const i=[],o=[],l=d=>{const f=o.indexOf(d);return f===-1?o.length:f};for(const d of r){const f=e.lineAt(d.from).number;if(d.name==="ListItem"){const p=J.listItemWidthOn(e.line(f).text,i,l(f));if(p===null)return null;i.push({kind:"listItem",width:p})}else i.push({kind:"quote"});o.push(f)}const s=J.openingFenceOn(n.text,i,l(n.number));return s===null?null:{containers:i,...s}},et=(e,t)=>{const{doc:n}=e;let r=n.lineAt(t).to;for(;;){const i=oe.ensureSyntaxTree(e,r,Number.POSITIVE_INFINITY);if(i===null)return null;const o=i.resolveInner(t,1),l=o.parent;if(o.name!=="CodeMark"||l===null||l.name!=="FencedCode"||l.from!==o.from)return null;if(l.to<r||r>=n.length)return l;r=Math.min(n.length,l.to+Math.max(l.to-t,1))}},Ee=(e,t)=>{const{doc:n}=e;if(!Number.isInteger(t)||t<1||t>n.lines)return te;const r=n.line(t),i=Qe.exec(r.text);if(i===null)return te;const o=et(e,r.from+i.index);if(o===null)return te;const l=o.getChild("CodeInfo");if(l===null)return te;const s=J.fencedCodeLanguageOf(n.sliceString(l.from,l.to));if(s===null)return ce;if(s!==J.SPREADSHEETS_LANGUAGE)return te;const d=Ze(n,o,r);if(d===null)return ce;const[,...f]=o.getChildren("CodeMark"),p=f.at(-1),k=p===void 0?n.lineAt(o.to).number:n.lineAt(p.from).number-1,c=[];let E="";for(let u=t+1;u<=k;u+=1){const m=n.line(u).text,v=J.readFencedLine(m,d);if(v===null)return ce;c.push(m),E+=u<n.lines?`${v.content}
|
|
3
|
+
`:v.content}return{kind:"found",firstLine:t+1,lines:c,layout:d,body:E}},tt=({parent:e,scroll:t,text:n,saved:r,labels:i,revisions:o,onChange:l,onGeometry:s,onSave:d})=>{let f=!1;const p=[P.EditorView.scrollHandler.of((u,m,v)=>(nt(u,m.head,v,t),!0)),P.lineNumbers(),P.highlightActiveLineGutter(),K.history(),P.drawSelection(),P.highlightActiveLine(),ge.highlightSelectionMatches(),P.EditorView.lineWrapping,pe.markdown({base:pe.markdownLanguage}),Je,oe.syntaxHighlighting(Fe),Ke(i),P.keymap.of([{key:"Mod-s",preventDefault:!0,run:()=>(d(),!0)},...ge.searchKeymap,...K.historyKeymap,...K.defaultKeymap]),P.EditorView.contentAttributes.of({"aria-label":i.editor,"aria-multiline":"true"}),P.EditorView.updateListener.of(u=>{for(const m of u.transactions)m.docChanged&&o.record(m.changes,m.newDoc);u.docChanged&&l(u.transactions.every(m=>!m.docChanged||m.isUserEvent(we))),(u.docChanged||u.heightChanged||u.geometryChanged)&&s(u.docChanged&&!f)}),Ue],k=st(r,p)??$.EditorState.create({doc:n,extensions:p}),c=new P.EditorView({state:k,parent:e});o.mount(c.state.doc);const E=u=>{f=!0;try{u()}finally{f=!1}};return{text:()=>c.state.doc.toString(),replaceText:u=>{const m=c.state.doc.toString();if(m===u)return;let v=0;const y=Math.min(m.length,u.length);for(;v<y&&m.charCodeAt(v)===u.charCodeAt(v);)v+=1;let g=0;for(;g<y-v&&m.charCodeAt(m.length-1-g)===u.charCodeAt(u.length-1-g);)g+=1;c.dispatch({changes:{from:v,to:m.length-g,insert:u.slice(v,u.length-g)},userEvent:"input.replace"})},replaceBody:(u,m,v,y)=>{const{doc:g}=c.state,L=o.lineOf(y,u);if(L===null)return"changed";const O=Ee(c.state,L);if(O.kind==="absent")return"changed";if(O.kind==="unreadable")return"unwritable";if(O.body!==J.fencedBodyAsRead(m,O.layout))return"changed";const A=J.planFencedBodyEdit(O.lines,O.layout,v);if(A.kind!=="edit")return A.kind;if(A.from===A.to&&A.lines.length===0)return"written";const D=j=>{const H=O.firstLine+j;return H<=g.lines?g.line(H).from:g.length},M=D(A.from),B=`${M===g.length&&g.sliceString(g.length-1)!==`
|
|
4
4
|
`?`
|
|
5
|
-
`:""}${
|
|
6
|
-
`).join("")}`;return E(()=>c.dispatch({changes:{from:M,to:D(I.to),insert:B},userEvent:Ee,annotations:K.isolateHistory.of("full")})),"written"},readBody:(u,m)=>{const v=o.lineOf(m,u);if(v===null)return null;const y=be(c.state,v);return y.kind==="found"?y.body:null},undo:()=>E(()=>K.undo(c)),redo:()=>E(()=>K.redo(c)),reveal:({line:u,column:m},v)=>{const{doc:y}=c.state,g=y.line(Math.min(Math.max(u,1),y.lines)),L=Math.min(g.from+m,g.to);c.dispatch({selection:$.EditorSelection.cursor(L),effects:xe(c,L,v,t)})},showLine:u=>{const{doc:m}=c.state,v=m.line(Math.min(Math.max(u,1),m.lines)).from;c.dispatch({effects:xe(c,v,null,t)})},topLine:()=>{const u=t.scrollerOf(c.scrollDOM),m=S.visibleTopOf(u,c.contentDOM),v=S.frameTopOf(u)+u.clientHeight,{documentTop:y}=c,{doc:g}=c.state;let L=c.lineBlockAtHeight(Math.max(m-y,0));for(;g.lineAt(L.from).text.trim()===""&&L.to<g.length;){const D=c.lineBlockAt(L.to+1);if(y+D.top>=v)break;L=D}const O=c.coordsAtPos(L.from),I=O===null?y+L.top:O.top;return{line:c.state.doc.lineAt(L.from).number,clientTop:I,offset:I-m}},lineSpans:u=>{const m=c.scrollDOM,v=m.scrollTop+c.documentTop-S.visibleTopOf(m,c.contentDOM),{doc:y}=c.state,g=L=>y.line(Math.min(Math.max(L,1),y.lines)).from;return u.map(({first:L,last:O})=>({top:v+c.lineBlockAt(g(L)).top,bottom:v+c.lineBlockAt(g(O)).bottom}))},scrollElement:c.scrollDOM,focus:()=>c.focus(),conflicts:()=>re(c.state.doc),resolveAtCursor:u=>{const m=re(c.state.doc),v=c.state.doc.lineAt(c.state.selection.main.head).number,y=m.find(g=>g.end>=v);return y===void 0?!1:(_e(c,y,u),!0)},nextConflict:()=>{const u=re(c.state.doc);if(u[0]===void 0)return!1;const v=c.state.doc.lineAt(c.state.selection.main.head).number,y=u.findIndex(I=>I.start>v),g=y<0?0:y,L=c.state.doc.line(u[g].start).from;c.dispatch({selection:$.EditorSelection.cursor(L),effects:P.EditorView.scrollIntoView(L,{y:"center"})});const O=c.contentDOM.querySelector(`[${Me}="${String(g)}"] button`);return O instanceof HTMLElement?O.focus({preventScroll:!0}):c.focus(),!0},save:()=>c.state.toJSON(qe),destroy:()=>c.destroy()}},xe=(e,t,n,r)=>{const i=r.scrollerOf(e.scrollDOM),o=(n===null?S.visibleTopOf(i,e.contentDOM):n)-S.frameTopOf(i);return P.EditorView.scrollIntoView(t,{y:"start",yMargin:o})},nt=(e,t,n,r)=>{const i=rt(e,t),o=r.scrollerOf(e.scrollDOM),l=S.frameTopOf(o),s=S.visibleTopOf(o,e.contentDOM),d=l+o.clientHeight;let f=0;switch(n.y){case"start":f=i.top-(l+n.yMargin);break;case"center":f=(i.top+i.bottom)/2-(s+d)/2;break;case"end":f=i.bottom-(d-n.yMargin);break;default:i.top<s+n.yMargin?f=i.top-(s+n.yMargin):i.bottom>d-n.yMargin&&(f=Math.min(i.bottom-(d-n.yMargin),i.top-(s+n.yMargin)))}if(f!==0&&(o.scrollTop+=f),n.y==="start")return;const p=ot(e,t);p!==null&&r.reveal(p)},rt=(e,t)=>{const{node:n,offset:r}=e.domAtPos(t);if(n.nodeType===Node.TEXT_NODE){const l=n.ownerDocument?.createRange();if(l!==void 0){l.setStart(n,r),l.setEnd(n,r);const[s]=l.getClientRects();if(s!==void 0&&s.height>0)return{top:s.top,bottom:s.bottom}}}const i=e.lineBlockAt(t),o=e.documentTop+i.top;return{top:o,bottom:o+i.height}},ot=(e,t)=>{const{node:n}=e.domAtPos(t);for(let r=n instanceof Element?n:n.parentElement;r!==null;r=r.parentElement)if(r.parentElement===e.contentDOM)return r;return null},st=(e,t)=>{if(e==null)return null;try{return $.EditorState.fromJSON(e,{extensions:t},qe)}catch{return null}},it=610,lt=987,Se=Object.freeze({kind:"unavailable"}),ct="true",at="false",ut=e=>e===ct?!0:e===at?!1:null,dt=e=>{const t=new DOMParser().parseFromString(e,"text/html"),n=[];for(const r of t.querySelectorAll("img[data-asset-src], a[data-doc-path]")){const i=r.localName==="img",o=r.getAttribute(i?"data-asset-src":"data-doc-path");o!==null&&n.push({target:{kind:i?"asset":"doc",path:o},exists:ut(r.getAttribute(i?"data-asset-exists":"data-doc-exists"))})}return n},ft=({path:e,instant:t,preview:n,initial:r,onView:i})=>{const o=new AbortController,l={asset:new Map,doc:new Map};let s=r,d=null,f=!1,p=!1,k=null,c=null,E=[],u,m=!1,v,y=null;const g=w=>{w.parsed===s.parsed&&w.source===s.source&&w.failure===s.failure&&w.busy===s.busy&&w.tier===s.tier||(s=w,i(w))},L=(w,T)=>{f||(f=!0,console.error(`[markdown-explorer] ${w}`,...T===void 0?[]:[T]))},O=w=>{if(t!==null)for(const{target:T,exists:C}of t.marksOf(w))l[T.kind].set(T.path,C)},I=()=>{clearTimeout(v),v=void 0,y?.abort(),y=null},D=()=>{c=null,E=[],clearTimeout(u),u=void 0},M=(w,T)=>{g({...s,failure:w,busy:!1,tier:T})},F=()=>{clearTimeout(u),u=E.length===0?void 0:setTimeout(j,lt)},B=()=>{if(t===null||c===null)return;const w=c,T=[],C={asset:new Set,doc:new Set};let U;try{U=t.sanitize(w.html,x=>{const _=l[x.kind].get(x.path);return _===void 0&&!C[x.kind].has(x.path)&&(C[x.kind].add(x.path),T.push(x)),_??void 0})}catch(x){D(),x instanceof de.HtmlNestingLimitError?M(ee.failureOf("too-large"),"instant"):(L("the draft sanitizer failed",x),M(ee.failureOf("failed"),"instant"));return}E=T;const b=s.parsed!==null&&s.parsed.htmlContent===U&&s.parsed.headings===w.headings?s.parsed:{htmlContent:U,headings:w.headings};g({parsed:b,source:w.draft,failure:null,busy:!1,tier:"instant"}),F()},j=()=>{if(u=void 0,m||c===null||E.length===0)return;m=!0;const w=E;n(e,c.draft.text,o.signal).then(T=>{if(m=!1,!(o.signal.aborted||!("kind"in T))){T.kind==="preview"&&O(T.htmlContent);for(const C of w)l[C.kind].has(C.path)||l[C.kind].set(C.path,null);B()}})},H=w=>{I(),D(),g({...s,busy:!0,tier:"server"});const T=new AbortController;y=T,v=setTimeout(()=>{v=void 0,n(e,w.text,T.signal).then(C=>{if(!(T.signal.aborted||!("kind"in C))){if(y=null,C.kind==="failure"){M(C.failure,"server");return}O(C.htmlContent),g({parsed:{htmlContent:C.htmlContent,headings:C.headings},source:w,failure:null,busy:!1,tier:"server"})}})},it)},a=async(w,T)=>{let C;try{C=await w.convert({path:e,text:T},o.signal)}catch(b){return o.signal.aborted||L("the draft converter rejected a conversion, which its contract allows only once the signal aborted",b),Se}const U=ee.draftAnswerViolation(C);return U===null?C:(L(`the draft converter answered outside its contract: ${U}`),Se)},A=(w,T)=>{switch(T.kind){case"preview":if(I(),T.headings.length>ee.EXPLORER_MAX_HEADINGS){D(),M(ee.failureOf("too-large"),"instant");return}c={draft:w,html:T.htmlContent,headings:T.headings.map(({text:C,depth:U,id:b})=>({text:C,depth:U,id:b}))},B();return;case"failure":I(),D(),M(ee.failureOf(T.failure.reason,T.failure.code),"instant");return;case"unavailable":H(w);return}},R=async w=>{p=!0;try{for(;k!==null&&!o.signal.aborted;){const T=k;k=null;const C=await a(w,T.text);if(o.signal.aborted)return;A(T,C)}}finally{p=!1}};return t!==null&&t.seed!==null&&O(t.seed),{update:w=>{if(!(o.signal.aborted||w.text===d?.text)){if(d=w,clearTimeout(u),u=void 0,t===null){H(w);return}k=w,p||R(t.converter)}},dispose:()=>{o.abort(),k=null,clearTimeout(u),u=void 0,I()}}},mt=(e,t)=>de.createHtmlSanitizer(ze(window),e,t,de.MAX_HTML_NESTING_DEPTH),ht=(e,t)=>e.flatMap((n,r)=>{const i=t[r];return i===void 0?[]:[{editor:i.top,preview:n.top},{editor:i.bottom,preview:n.bottom}]}),Y=(e,t)=>{const n=e[t];if(n===void 0)throw new RangeError(`[markdown-explorer] a scroll map index must be in 0..${String(e.length-1)}; got ${String(t)}`);return n},pt=e=>{const t=[];for(const r of e){let i=0,o=t.length;for(;i<o;){const l=i+o>>1;Y(t,l).pair.preview<=r.preview?i=l+1:o=l}t[i]={pair:r,before:i===0?void 0:Y(t,i-1)}}const n=[];for(let r=t.at(-1);r!==void 0;r=r.before)n.push(r.pair);return n.reverse()},gt=(e,t)=>{const n=Math.max(t.editorMax,0),r=Math.max(t.previewMax,0),i=n-t.editorViewport,o=r-t.previewViewport,l=e.filter(f=>f.editor>0&&f.editor<i&&f.preview>0&&f.preview<o).sort((f,p)=>f.editor-p.editor||f.preview-p.preview);let s={editor:0,preview:0};const d=[s];for(const f of pt(l))f.editor>s.editor&&f.preview>s.preview&&(d.push(f),s=f);return d.push({editor:n,preview:r}),{toPreview:f=>ye(d,"editor","preview",f),toEditor:f=>ye(d,"preview","editor",f)}},ye=(e,t,n,r)=>{const i=Y(e,0),o=Y(e,e.length-1);if(Number.isNaN(r)||r<=i[t])return i[n];if(r>=o[t])return o[n];let l=0,s=e.length-1;for(;s-l>1;){const p=l+s>>1;Y(e,p)[t]<=r?l=p:s=p}const d=Y(e,l),f=Y(e,s);return d[n]+(f[n]-d[n])*(r-d[t])/(f[t]-d[t])},vt=610,Te=89,ke=.5,wt=({editor:e,preview:t,previewBlocks:n,editorSpans:r,requestFrame:i,cancelFrame:o,now:l})=>{let s="editor",d=0,f=null,p=null,k=!1,c=null,E=null;const u={editor:0,preview:0},m={editor:null,preview:null};let v=null,y=()=>{};const g=a=>{f!==null&&a!==f||(s=a,d=l()+vt)},L=(a,A)=>{a!==s&&f===null&&l()>=d&&!O(a,A)&&(s=a),B()},O=(a,A)=>{const R=m[a];return l()<u[a]||R!==null&&Math.abs(A.position()-R)<ke},I=e.onScroll(()=>L("editor",e)),D=e.onIntent(()=>g("editor")),M=()=>{const a=t();return a!==v&&(y(),v=a,y=a===null?()=>{}:F(a)),a},F=a=>{const A=a.onScroll(()=>L("preview",a)),R=a.onIntent(()=>g("preview"));return()=>{A(),R()}},B=()=>{!k&&p===null&&(p=i(j))},j=()=>{p=null;const a=M();a!==null&&(c??=n(),E??=gt(ht(c,r(c)),{editorMax:e.max(),previewMax:a.max(),editorViewport:e.viewport(),previewViewport:a.viewport()}),s==="editor"?H(a,"preview",E.toPreview(e.position())):H(e,"editor",E.toEditor(a.position())))},H=(a,A,R)=>{if(Math.abs(a.position()-R)<ke){m[A]=a.position();return}u[A]=l()+Te,m[A]=a.scrollTo(R)};return B(),{editorChanged:a=>{E=null,a&&g("editor"),B()},previewChanged:()=>{c=null,E=null,u.preview=l()+Te,B()},showAlone:a=>{f=a,!(a===null||a===s)&&(s=a,d=0,B())},dispose:()=>{k=!0,p!==null&&o(p),p=null,I(),D(),y()}}},Le=Object.freeze(["wheel","pointerdown","keydown","focusin"]),Pe=e=>({position:()=>e.scrollTop,max:()=>Math.max(e.scrollHeight-e.clientHeight,0),viewport:()=>e.clientHeight,scrollTo:t=>(e.scrollTo({top:t,behavior:"instant"}),e.scrollTop),onScroll:t=>(e.addEventListener("scroll",t,{passive:!0}),()=>e.removeEventListener("scroll",t)),onIntent:t=>{for(const n of Le)e.addEventListener(n,t,{capture:!0,passive:!0});return()=>{for(const n of Le)e.removeEventListener(n,t,{capture:!0})}}}),ne="[data-aqmd-scroll-container]",Et="[data-aqmd-content]",bt=`[${ue.SOURCE_LINES_ATTRIBUTE}]`,xt=Object.freeze(["p1","p2","p3","p4","p5","p6","p7","p8"]),Ne=(e,t)=>{const n=S.loadedOf(e.peek(t));return n!==null&&n.document.kind==="markdown"?{htmlContent:n.document.htmlContent,headings:n.document.headings}:null},St=(e,t,n,r,i)=>{if(n===void 0)return null;let o;try{o=mt(e,t)}catch(l){return console.error("[markdown-explorer] the draft sanitizer cannot run in this browser, so the server renders the preview",l),null}return{converter:n,sanitize:o,marksOf:dt,seed:Ne(r,i)?.htmlContent??null}},yt=e=>{const t=[];let n=null;for(const r of e.querySelectorAll(bt)){const i=ue.parseSourceLines(r.getAttribute(ue.SOURCE_LINES_ATTRIBUTE));if(i===null||r.getClientRects().length===0)continue;n??=e.scrollTop-S.visibleTopOf(e,r);const{top:o,bottom:l}=r.getBoundingClientRect();t.push({first:i.first,last:i.last,top:n+o,bottom:n+l})}return t},Tt=({path:e,readDraft:t,viewer:n,tables:r,concealed:i,onEditAt:o,onLayout:l,handleRef:s})=>{const{config:d,data:f,documents:p,draftConverter:k,labels:c}=S.useExplorer(),[E,u]=h.useState(()=>({parsed:Ne(p,e),source:null,failure:null,busy:!0,tier:k===void 0?"server":"instant"})),m=h.useRef(null),v=h.useRef(null),y=h.useRef(E);h.useLayoutEffect(()=>{y.current=E});const g=h.useEffectEvent(()=>t());h.useEffect(()=>{const a=St(d.iframeHosts,d.dataPath,k,p,e),A=g(),R=ft({path:e,instant:a,preview:f.preview,initial:y.current,onView:w=>h.startTransition(()=>u(w))});return v.current=R,R.update(A),()=>{R.dispose(),v.current=null}},[d,f,p,k,e]);const L=h.useEffectEvent(()=>l());h.useLayoutEffect(()=>{E.parsed!==null&&L()},[E.parsed]);const O=E.parsed!==null;h.useLayoutEffect(()=>{const a=O?m.current?.querySelector(ne):null;if(!(a instanceof HTMLElement))return;a.tabIndex=0;const A=new ResizeObserver(()=>L());A.observe(a);const R=a.querySelector(Et);return R!==null&&A.observe(R),()=>A.disconnect()},[O]);const I=h.useRef(null);h.useImperativeHandle(s,()=>({draft:a=>{v.current?.update(a)},scrollPort:()=>{const a=m.current?.querySelector(ne);return a instanceof HTMLElement?(I.current?.scroller!==a&&(I.current={scroller:a,port:Pe(a)}),I.current.port):null},blocks:()=>{const a=m.current?.querySelector(ne);return a instanceof HTMLElement?yt(a):[]},focus:()=>{const a=m.current?.querySelector(ne);a instanceof HTMLElement&&a.focus({preventScroll:!0})},anchor:a=>{const A=m.current,R=A?.querySelector(ne);return A===null||!(R instanceof HTMLElement)?null:S.anchorOfView(A,a(R))},place:({line:a,clientTop:A},R)=>{const w=m.current,T=w===null?null:S.blockAtLine(w,a);T!==null&&(R(T).scrollTop+=S.lineTopIn(T,a)-A)}}),[]);const D=a=>{const A=m.current,{target:R}=a;if(o===void 0||A===null||!(R instanceof Element)||!S.isEditingDoubleClick(R))return;const w=S.anchorOfDoubleClick(R,A,A.ownerDocument.getSelection());w!==null&&o(w)},M=E.source===null?null:E.source.revision,F=h.useMemo(()=>M===null?void 0:{write:a=>r.write(M,a),read:a=>r.read(M,a),undo:r.undo,redo:r.redo,subscribe:r.subscribe},[r,M]),B=h.useMemo(()=>({...n.labels,spreadsheetReadOnly:c.previewTablePending}),[n.labels,c.previewTablePending]),j=h.useMemo(()=>({...n,labels:F===void 0?B:n.labels,showToc:!1,showStyle:!1,showAlign:!1,renderScrollBar:void 0,scrollBarGutter:void 0,spreadsheetEditor:F}),[n,B,F]),H=h.useMemo(()=>E.parsed===null?null:q.jsx("div",{className:"aqmx-document-viewer",children:q.jsx(je.MarkdownViewer,{...j,parseResult:E.parsed,content:null})}),[j,E.parsed]);return q.jsxs("section",{ref:m,className:"aqmx-edit-preview","aria-label":c.previewRegion,"aria-busy":E.busy,inert:i!==null,hidden:i==="removed","data-aqmx-preview-tier":E.tier,"data-testid":"markdown-explorer-edit-preview",onDoubleClick:o===void 0?void 0:D,children:[E.failure===null?null:q.jsx("p",{className:"aqmx-callout aqmx-document-notice","data-aqmx-tone":"warning","data-testid":"markdown-explorer-edit-preview-failure",children:c.previewFailed(S.failureTitleOf(c,E.failure.reason))}),H??(E.failure===null?q.jsx("div",{className:"aqmx-skeleton","aria-hidden":"true","data-testid":"markdown-explorer-edit-preview-skeleton",children:xt.map(a=>q.jsx("span",{},a))}):null),E.busy?q.jsx("p",{className:"aqmx-sr-only",children:c.previewUpdating}):null]})},Ae="data-aqmx-edit-split",ae="--aqmx-edit-share",Ie="--aqmx-edit-gutter",kt="data-aqmx-edit-split-probe",Lt="aqmx-edit-split",At="aqmx-edit-editor",It="aqmx-edit-preview",Oe={value:X.EDIT_SPLIT_MIN_PERCENT,unit:"percentage"},Re={value:X.EDIT_SPLIT_MAX_PERCENT,unit:"percentage"},Ce=e=>{if(e.length!==2)return null;const[t=0,n=0]=e,r=t+n;return r>0?t/r*100:null},ie=e=>{const t=e.current?.parentElement;if(t==null)throw new Error("[markdown-explorer] the edit split is not mounted in its surface");return t},Ot=(e,t,n)=>{const[r,i]=h.useState(null);return h.useLayoutEffect(()=>{const o=e.current,l=t.current;if(o===null||l===null)throw new Error("[markdown-explorer] the edit split is not mounted");const s={frame:o.getBoundingClientRect().width,measure:l.getBoundingClientRect().width},d=()=>{s.frame>0&&s.measure>0&&i(X.editSplitOrientation(s.frame,s.measure,n))};d();const f=new ResizeObserver(p=>{for(const k of p){const[c]=k.borderBoxSize;c!==void 0&&(k.target===o&&(s.frame=c.inlineSize),k.target===l&&(s.measure=c.inlineSize))}d()});return f.observe(o),f.observe(l),()=>f.disconnect()},[e,t,n]),r},Rt=({editorId:e})=>{const{edits:t,labels:n}=S.useExplorer(),r=h.useRef(null),i=h.useRef(null),o=ve.useCoarsePointer()?X.COARSE_TARGET_PIXELS:X.FINE_TARGET_PIXELS,l=Ot(r,i,o),[s]=h.useState(()=>t.editorShare());h.useLayoutEffect(()=>{const p=ie(r);return p.style.setProperty(Ie,`${String(o)}px`),()=>{p.style.removeProperty(Ie)}},[o]),h.useLayoutEffect(()=>{const p=ie(r);return p.style.setProperty(ae,`${String(s)}%`),()=>{p.style.removeProperty(ae)}},[s]),h.useLayoutEffect(()=>{if(l===null)return;const p=ie(r);return p.setAttribute(Ae,l),()=>p.removeAttribute(Ae)},[l]);const d=ve.useSplitPersistence(h.useCallback(p=>{const k=Ce(p);k!==null&&t.setEditorShare(k)},[t])),f=h.useCallback((p,k)=>{const c=Ce(p);c!==null&&ie(r).style.setProperty(ae,`${String(c)}%`),d.layoutChanged(p,k)},[d]);return q.jsxs("div",{ref:r,className:"aqmx-edit-split","data-testid":"markdown-explorer-edit-split",children:[q.jsx("span",{ref:i,className:"aqmx-edit-split-probe","aria-hidden":"true",[kt]:""}),l===null?null:q.jsxs(se.PanelGroup,{id:Lt,direction:l==="beside"?"horizontal":"vertical",onLayout:f,className:"aqmx-edit-split-group",children:[q.jsx(se.Panel,{id:At,defaultSize:{value:s,unit:"percentage"},minSize:Oe,maxSize:Re,contentOverflow:"hidden"}),q.jsx(se.PanelResizeHandle,{thickness:o,indicator:{visible:!0,thickness:X.SPLIT_HANDLE_PIXELS.gripThickness,length:X.SPLIT_HANDLE_PIXELS.gripLength,barThickness:X.SPLIT_HANDLE_PIXELS.barThickness,barLength:X.SPLIT_HANDLE_PIXELS.barLength},title:n.editViewSplitResize,"aria-label":n.editViewSplitResize,"aria-controls":e,onDragging:d.draggingChanged,className:"aqmx-split-handle aqmx-edit-split-handle"}),q.jsx(se.Panel,{id:It,defaultSize:{value:100-s,unit:"percentage"},minSize:Oe,maxSize:Re,contentOverflow:"hidden"})]})]})},Ct=512,qt=()=>{const e=[];let t=0,n=null;const r=i=>{if(n===null||!Number.isInteger(i)||i<t)return null;if(i===t+e.length)return n;const o=e[i-t];return o===void 0?null:o.before};return{revision:()=>t+e.length,mount:i=>{if(n!==null&&(n===i||n.eq(i))){n=i;return}const o=t+e.length;e.length=0,t=n===null?o:o+1,n=i},record:(i,o)=>{if(n===null)throw new Error("[markdown-explorer] a change of the editor's text was recorded before an editor mounted");e.push({before:n,changes:i}),n=o,e.length>Ct&&(e.shift(),t+=1)},lineOf:(i,o)=>{const l=r(i);if(l===null||n===null||!Number.isInteger(o)||o<1||o>l.lines)return null;let s=l.line(o).from;for(const d of e.slice(i-t)){const f=d.changes.mapPos(s,1,$.MapMode.TrackAfter);if(f===null)return null;s=f}return n.lineAt(s).number}}},De=144,Mt=e=>{if(typeof e!="object"||e===null)return!1;const{generation:t,topLine:n}=e;return"state"in e&&typeof t=="number"&&typeof n=="number"},_t=e=>{e.stopPropagation()},Pt=e=>{const{path:t,name:n,session:r}=e,{edits:i,labels:o,announcer:l}=S.useExplorer(),{phase:s}=r,d=h.useCallback(()=>i.retry(t),[i,t]);switch(h.useEffect(()=>{s.kind==="failed"&&l.announce(o.documentFailed(n,S.failureTitleOf(o,s.failure.reason)))},[s,l,o,n]),s.kind){case"opening":return q.jsx(S.ContentSkeleton,{label:o.editLoading,testId:"markdown-explorer-edit-skeleton"});case"grant":return q.jsx("div",{className:"aqmx-edit-message",children:q.jsx(S.EditGrantNotice,{href:s.href,onRetry:d,testId:"markdown-explorer-edit-grant"})});case"failed":return q.jsx("div",{className:"aqmx-edit-message",children:q.jsx(S.FailureView,{failure:s.failure,alert:!1,onRetry:d,testId:"markdown-explorer-edit-failure"})});case"editing":return q.jsx(Nt,{...e})}},Nt=({path:e,name:t,session:n,layout:r,viewer:i,region:o,paneScroll:l})=>{const{edits:s,labels:d}=S.useExplorer(),f=h.useRef(null),p=h.useId(),k=h.useRef(null),[c]=h.useState(()=>new Set),[E]=h.useState(qt),u=h.useRef(null),m=h.useRef(null),v=r==="fill",y=S.useSideBySide(),g=S.editViewOf(n,y,v),L=g!=="editor"||n.previewPrepared,O=L&&v,I=h.useRef({layout:r,region:o,paneScroll:l});h.useLayoutEffect(()=>{I.current={layout:r,region:o,paneScroll:l}});const D=h.useRef(n.generation);h.useLayoutEffect(()=>{D.current=n.generation});const M=h.useRef({view:g,previewMounted:L});h.useLayoutEffect(()=>{M.current={view:g,previewMounted:L}});const F=h.useRef(null),B=h.useRef(null),j=h.useRef(!1),H=h.useMemo(()=>({editor:d.editorLabel(t),useOurs:d.conflictUseOurs,useTheirs:d.conflictUseTheirs,keepBoth:d.conflictKeepBoth}),[d,t]),a=h.useCallback(b=>{const{region:x,paneScroll:_}=I.current,z=x();return z===null?b:_.scrollerOf(z,b)},[]);h.useLayoutEffect(()=>{const b=f.current,x=s.draft(e);if(b===null||x===null)return;const _=s.editorState.get(e),z=Mt(_)&&_.generation===D.current?_:null;let W=null,Q=null;const le=()=>{W!==null&&clearTimeout(W),W=null,Q!==null&&s.setDraft(e,Q.text())},G=tt({parent:b,scroll:{scrollerOf:N=>{const{layout:Z,region:Be,paneScroll:He}=I.current,he=Be();return Z==="fill"||he===null?N:He.scrollerOf(he,N)},reveal:N=>I.current.paneScroll.reveal(N)},text:x,saved:z===null?void 0:z.state,labels:H,revisions:E,onGeometry:N=>m.current?.editorChanged(N),onChange:N=>{if(W??=setTimeout(le,De),!N)for(const Z of[...c])Z();M.current.previewMounted&&Q!==null&&u.current?.draft({text:Q.text(),revision:E.revision()})},onSave:()=>{s.save(e)}});Q=G,k.current=G;const fe=()=>{const N=G.topLine();return{line:N.line,clientTop:N.clientTop}},me=()=>u.current?.anchor(a)??null,Ve=s.bindEditor(e,{flush:le,adopt:N=>G.replaceText(N),returnPoint:()=>{const N=M.current.view==="preview"&&I.current.layout==="content"?me():null;return N===null?fe():{line:N.lines.first,clientTop:N.clientTop}},nextConflict:()=>M.current.view!=="preview"?G.nextConflict():G.conflicts().length===0?!1:(j.current=!0,s.setView(e,"editor"),!0),beforeView:N=>{if(I.current.layout==="fill")return;if(N==="preview"){F.current={to:"preview",point:fe()};return}const Z=me();F.current=Z===null?null:{to:"editor",anchor:Z}}});return z!==null&&G.showLine(z.topLine),()=>{le(),s.editorState.set(e,{state:G.save(),generation:D.current,topLine:G.topLine().line}),Ve(),G.destroy(),Q=null,k.current=null}},[s,e,H,a,c,E]);const{request:A}=n;h.useLayoutEffect(()=>{const b=k.current,x=s.draft(e);b===null||x===null||A===null||(A.anchor!==null&&b.reveal(S.positionInSource(x,A.anchor),A.anchor.clientTop),b.focus(),s.consumeRequest(e))},[s,e,A,H]),h.useLayoutEffect(()=>{g!=="editor"&&!n.previewPrepared&&s.preparePreview(e)},[s,e,g,n.previewPrepared]),h.useLayoutEffect(()=>{const b=F.current,x=B.current,_=j.current;F.current=null,B.current=null,j.current=!1;const z=k.current;if(b?.to==="preview")u.current?.place(b.point,a);else if(b?.to==="editor"&&z!==null){const W=s.draft(e);W!==null&&z.reveal(S.positionInSource(W,b.anchor),b.anchor.clientTop)}_?z?.nextConflict():x==="editor"?z?.focus():x==="preview"&&u.current?.focus()},[s,e,g,a]);const R=h.useMemo(()=>{const b=()=>{const x=k.current;if(x===null)throw new Error("[markdown-explorer] a table of the preview wrote back while no editor was mounted");return x};return{write:(x,{fenceLine:_,expected:z,text:W})=>b().replaceBody(_,z,W,x),read:(x,_)=>b().readBody(_,x),undo:()=>b().undo(),redo:()=>b().redo(),subscribe:x=>(c.add(x),()=>{c.delete(x)})}},[c]),w=h.useCallback(()=>{const b=k.current;if(b===null)throw new Error("[markdown-explorer] the preview read the draft before the editor was mounted");return{text:b.text(),revision:E.revision()}},[E]);h.useLayoutEffect(()=>{const b=k.current;if(!O||b===null)return;const x=wt({editor:Pe(b.scrollElement),preview:()=>u.current?.scrollPort()??null,previewBlocks:()=>u.current?.blocks()??[],editorSpans:_=>b.lineSpans(_),requestFrame:_=>requestAnimationFrame(_),cancelFrame:_=>cancelAnimationFrame(_),now:()=>performance.now()});return x.showAlone(S.paneShownAlone(M.current.view)),m.current=x,()=>{x.dispose(),m.current=null}},[O,s,e,H]),h.useLayoutEffect(()=>{m.current?.showAlone(S.paneShownAlone(g))},[g]);const T=h.useCallback(()=>m.current?.previewChanged(),[]),C=h.useCallback(b=>s.start(e,b),[s,e]),U=b=>{if(S.isInFullscreenBlock(b.target))return;if(b.key==="Escape"){S.consumeKey(b);return}if(!S.isEditViewShortcut(b.nativeEvent,S.isApplePlatform(navigator.platform)))return;S.consumeKey(b);const x=S.toggledEditView(g);B.current=x,S.chooseEditView(s,e,x,v)};return q.jsxs("div",{className:"aqmx-edit","data-aqmx-edit-layout":r,"data-aqmx-edit-view":g,"data-testid":"markdown-explorer-edit",onKeyDown:U,onDoubleClick:_t,children:[q.jsx("div",{ref:f,id:p,className:"aqmx-edit-editor","data-testid":"markdown-explorer-editor",inert:g==="preview",hidden:g==="preview"&&!v,...S.ALLOW_KEY_REPEAT}),g==="split"?q.jsx(Rt,{editorId:p}):null,L?q.jsx(Tt,{path:e,readDraft:w,viewer:i,tables:R,concealed:g!=="editor"?null:v?"overlay":"removed",onEditAt:g==="preview"?C:void 0,onLayout:T,handleRef:u}):null]})};exports.DRAFT_WRITE_INTERVAL_MS=De;exports.default=Pt;
|
|
5
|
+
`:""}${A.lines.map(j=>`${j}
|
|
6
|
+
`).join("")}`;return E(()=>c.dispatch({changes:{from:M,to:D(A.to),insert:B},userEvent:we,annotations:K.isolateHistory.of("full")})),"written"},readBody:(u,m)=>{const v=o.lineOf(m,u);if(v===null)return null;const y=Ee(c.state,v);return y.kind==="found"?y.body:null},undo:()=>E(()=>K.undo(c)),redo:()=>E(()=>K.redo(c)),reveal:({line:u,column:m},v)=>{const{doc:y}=c.state,g=y.line(Math.min(Math.max(u,1),y.lines)),L=Math.min(g.from+m,g.to);c.dispatch({selection:$.EditorSelection.cursor(L),effects:be(c,L,v,t)})},showLine:u=>{const{doc:m}=c.state,v=m.line(Math.min(Math.max(u,1),m.lines)).from;c.dispatch({effects:be(c,v,null,t)})},topLine:()=>{const u=t.scrollerOf(c.scrollDOM),m=x.visibleTopOf(u,c.contentDOM),v=x.frameTopOf(u)+u.clientHeight,{documentTop:y}=c,{doc:g}=c.state;let L=c.lineBlockAtHeight(Math.max(m-y,0));for(;g.lineAt(L.from).text.trim()===""&&L.to<g.length;){const D=c.lineBlockAt(L.to+1);if(y+D.top>=v)break;L=D}const O=c.coordsAtPos(L.from),A=O===null?y+L.top:O.top;return{line:c.state.doc.lineAt(L.from).number,clientTop:A,offset:A-m}},lineSpans:u=>{const m=c.scrollDOM,v=m.scrollTop+c.documentTop-x.visibleTopOf(m,c.contentDOM),{doc:y}=c.state,g=L=>y.line(Math.min(Math.max(L,1),y.lines)).from;return u.map(({first:L,last:O})=>({top:v+c.lineBlockAt(g(L)).top,bottom:v+c.lineBlockAt(g(O)).bottom}))},scrollElement:c.scrollDOM,focus:()=>c.focus(),conflicts:()=>re(c.state.doc),resolveAtCursor:u=>{const m=re(c.state.doc),v=c.state.doc.lineAt(c.state.selection.main.head).number,y=m.find(g=>g.end>=v);return y===void 0?!1:(Me(c,y,u),!0)},nextConflict:()=>{const u=re(c.state.doc);if(u[0]===void 0)return!1;const v=c.state.doc.lineAt(c.state.selection.main.head).number,y=u.findIndex(A=>A.start>v),g=y<0?0:y,L=c.state.doc.line(u[g].start).from;c.dispatch({selection:$.EditorSelection.cursor(L),effects:P.EditorView.scrollIntoView(L,{y:"center"})});const O=c.contentDOM.querySelector(`[${qe}="${String(g)}"] button`);return O instanceof HTMLElement?O.focus({preventScroll:!0}):c.focus(),!0},save:()=>c.state.toJSON(Ce),destroy:()=>c.destroy()}},be=(e,t,n,r)=>{const i=r.scrollerOf(e.scrollDOM),o=(n===null?x.visibleTopOf(i,e.contentDOM):n)-x.frameTopOf(i);return P.EditorView.scrollIntoView(t,{y:"start",yMargin:o})},nt=(e,t,n,r)=>{const i=rt(e,t),o=r.scrollerOf(e.scrollDOM),l=x.frameTopOf(o),s=x.visibleTopOf(o,e.contentDOM),d=l+o.clientHeight;let f=0;switch(n.y){case"start":f=i.top-(l+n.yMargin);break;case"center":f=(i.top+i.bottom)/2-(s+d)/2;break;case"end":f=i.bottom-(d-n.yMargin);break;default:i.top<s+n.yMargin?f=i.top-(s+n.yMargin):i.bottom>d-n.yMargin&&(f=Math.min(i.bottom-(d-n.yMargin),i.top-(s+n.yMargin)))}if(f!==0&&(o.scrollTop+=f),n.y==="start")return;const p=ot(e,t);p!==null&&r.reveal(p)},rt=(e,t)=>{const{node:n,offset:r}=e.domAtPos(t);if(n.nodeType===Node.TEXT_NODE){const l=n.ownerDocument?.createRange();if(l!==void 0){l.setStart(n,r),l.setEnd(n,r);const[s]=l.getClientRects();if(s!==void 0&&s.height>0)return{top:s.top,bottom:s.bottom}}}const i=e.lineBlockAt(t),o=e.documentTop+i.top;return{top:o,bottom:o+i.height}},ot=(e,t)=>{const{node:n}=e.domAtPos(t);for(let r=n instanceof Element?n:n.parentElement;r!==null;r=r.parentElement)if(r.parentElement===e.contentDOM)return r;return null},st=(e,t)=>{if(e==null)return null;try{return $.EditorState.fromJSON(e,{extensions:t},Ce)}catch{return null}},it=610,lt=987,xe=Object.freeze({kind:"unavailable"}),ct="true",at="false",ut=e=>e===ct?!0:e===at?!1:null,dt=e=>{const t=new DOMParser().parseFromString(e,"text/html"),n=[];for(const r of t.querySelectorAll("img[data-asset-src], a[data-doc-path]")){const i=r.localName==="img",o=r.getAttribute(i?"data-asset-src":"data-doc-path");o!==null&&n.push({target:{kind:i?"asset":"doc",path:o},exists:ut(r.getAttribute(i?"data-asset-exists":"data-doc-exists"))})}return n},ft=({path:e,instant:t,preview:n,initial:r,onView:i})=>{const o=new AbortController,l={asset:new Map,doc:new Map};let s=r,d=null,f=!1,p=!1,k=null,c=null,E=[],u,m=!1,v,y=null;const g=w=>{w.parsed===s.parsed&&w.source===s.source&&w.failure===s.failure&&w.busy===s.busy&&w.tier===s.tier||(s=w,i(w))},L=(w,T)=>{f||(f=!0,console.error(`[markdown-explorer] ${w}`,...T===void 0?[]:[T]))},O=w=>{if(t!==null)for(const{target:T,exists:C}of t.marksOf(w))l[T.kind].set(T.path,C)},A=()=>{clearTimeout(v),v=void 0,y?.abort(),y=null},D=()=>{c=null,E=[],clearTimeout(u),u=void 0},M=(w,T)=>{g({...s,failure:w,busy:!1,tier:T})},F=()=>{clearTimeout(u),u=E.length===0?void 0:setTimeout(j,lt)},B=()=>{if(t===null||c===null)return;const w=c,T=[],C={asset:new Set,doc:new Set};let U;try{U=t.sanitize(w.html,S=>{const _=l[S.kind].get(S.path);return _===void 0&&!C[S.kind].has(S.path)&&(C[S.kind].add(S.path),T.push(S)),_??void 0})}catch(S){D(),S instanceof de.HtmlNestingLimitError?M(ee.failureOf("too-large"),"instant"):(L("the draft sanitizer failed",S),M(ee.failureOf("failed"),"instant"));return}E=T;const b=s.parsed!==null&&s.parsed.htmlContent===U&&s.parsed.headings===w.headings?s.parsed:{htmlContent:U,headings:w.headings};g({parsed:b,source:w.draft,failure:null,busy:!1,tier:"instant"}),F()},j=()=>{if(u=void 0,m||c===null||E.length===0)return;m=!0;const w=E;n(e,c.draft.text,o.signal).then(T=>{if(m=!1,!(o.signal.aborted||!("kind"in T))){T.kind==="preview"&&O(T.htmlContent);for(const C of w)l[C.kind].has(C.path)||l[C.kind].set(C.path,null);B()}})},H=w=>{A(),D(),g({...s,busy:!0,tier:"server"});const T=new AbortController;y=T,v=setTimeout(()=>{v=void 0,n(e,w.text,T.signal).then(C=>{if(!(T.signal.aborted||!("kind"in C))){if(y=null,C.kind==="failure"){M(C.failure,"server");return}O(C.htmlContent),g({parsed:{htmlContent:C.htmlContent,headings:C.headings},source:w,failure:null,busy:!1,tier:"server"})}})},it)},a=async(w,T)=>{let C;try{C=await w.convert({path:e,text:T},o.signal)}catch(b){return o.signal.aborted||L("the draft converter rejected a conversion, which its contract allows only once the signal aborted",b),xe}const U=ee.draftAnswerViolation(C);return U===null?C:(L(`the draft converter answered outside its contract: ${U}`),xe)},I=(w,T)=>{switch(T.kind){case"preview":if(A(),T.headings.length>ee.EXPLORER_MAX_HEADINGS){D(),M(ee.failureOf("too-large"),"instant");return}c={draft:w,html:T.htmlContent,headings:T.headings.map(({text:C,depth:U,id:b})=>({text:C,depth:U,id:b}))},B();return;case"failure":A(),D(),M(ee.failureOf(T.failure.reason,T.failure.code),"instant");return;case"unavailable":H(w);return}},R=async w=>{p=!0;try{for(;k!==null&&!o.signal.aborted;){const T=k;k=null;const C=await a(w,T.text);if(o.signal.aborted)return;I(T,C)}}finally{p=!1}};return t!==null&&t.seed!==null&&O(t.seed),{update:w=>{if(!(o.signal.aborted||w.text===d?.text)){if(d=w,clearTimeout(u),u=void 0,t===null){H(w);return}k=w,p||R(t.converter)}},dispose:()=>{o.abort(),k=null,clearTimeout(u),u=void 0,A()}}},mt=(e,t)=>de.createHtmlSanitizer(je(window),e,t,de.MAX_HTML_NESTING_DEPTH),ht=(e,t)=>e.flatMap((n,r)=>{const i=t[r];return i===void 0?[]:[{editor:i.top,preview:n.top},{editor:i.bottom,preview:n.bottom}]}),Y=(e,t)=>{const n=e[t];if(n===void 0)throw new RangeError(`[markdown-explorer] a scroll map index must be in 0..${String(e.length-1)}; got ${String(t)}`);return n},pt=e=>{const t=[];for(const r of e){let i=0,o=t.length;for(;i<o;){const l=i+o>>1;Y(t,l).pair.preview<=r.preview?i=l+1:o=l}t[i]={pair:r,before:i===0?void 0:Y(t,i-1)}}const n=[];for(let r=t.at(-1);r!==void 0;r=r.before)n.push(r.pair);return n.reverse()},gt=(e,t)=>{const n=Math.max(t.editorMax,0),r=Math.max(t.previewMax,0),i=n-t.editorViewport,o=r-t.previewViewport,l=e.filter(f=>f.editor>0&&f.editor<i&&f.preview>0&&f.preview<o).sort((f,p)=>f.editor-p.editor||f.preview-p.preview);let s={editor:0,preview:0};const d=[s];for(const f of pt(l))f.editor>s.editor&&f.preview>s.preview&&(d.push(f),s=f);return d.push({editor:n,preview:r}),{toPreview:f=>Se(d,"editor","preview",f),toEditor:f=>Se(d,"preview","editor",f)}},Se=(e,t,n,r)=>{const i=Y(e,0),o=Y(e,e.length-1);if(Number.isNaN(r)||r<=i[t])return i[n];if(r>=o[t])return o[n];let l=0,s=e.length-1;for(;s-l>1;){const p=l+s>>1;Y(e,p)[t]<=r?l=p:s=p}const d=Y(e,l),f=Y(e,s);return d[n]+(f[n]-d[n])*(r-d[t])/(f[t]-d[t])},vt=610,ye=89,Te=.5,wt=({editor:e,preview:t,previewBlocks:n,editorSpans:r,requestFrame:i,cancelFrame:o,now:l})=>{let s="editor",d=0,f=null,p=null,k=!1,c=null,E=null;const u={editor:0,preview:0},m={editor:null,preview:null};let v=null,y=()=>{};const g=a=>{f!==null&&a!==f||(s=a,d=l()+vt)},L=(a,I)=>{a!==s&&f===null&&l()>=d&&!O(a,I)&&(s=a),B()},O=(a,I)=>{const R=m[a];return l()<u[a]||R!==null&&Math.abs(I.position()-R)<Te},A=e.onScroll(()=>L("editor",e)),D=e.onIntent(()=>g("editor")),M=()=>{const a=t();return a!==v&&(y(),v=a,y=a===null?()=>{}:F(a)),a},F=a=>{const I=a.onScroll(()=>L("preview",a)),R=a.onIntent(()=>g("preview"));return()=>{I(),R()}},B=()=>{!k&&p===null&&(p=i(j))},j=()=>{p=null;const a=M();a!==null&&(c??=n(),E??=gt(ht(c,r(c)),{editorMax:e.max(),previewMax:a.max(),editorViewport:e.viewport(),previewViewport:a.viewport()}),s==="editor"?H(a,"preview",E.toPreview(e.position())):H(e,"editor",E.toEditor(a.position())))},H=(a,I,R)=>{if(Math.abs(a.position()-R)<Te){m[I]=a.position();return}u[I]=l()+ye,m[I]=a.scrollTo(R)};return B(),{editorChanged:a=>{E=null,a&&g("editor"),B()},previewChanged:()=>{c=null,E=null,u.preview=l()+ye,B()},showAlone:a=>{f=a,!(a===null||a===s)&&(s=a,d=0,B())},dispose:()=>{k=!0,p!==null&&o(p),p=null,A(),D(),y()}}},ke=Object.freeze(["wheel","pointerdown","keydown","focusin"]),_e=e=>({position:()=>e.scrollTop,max:()=>Math.max(e.scrollHeight-e.clientHeight,0),viewport:()=>e.clientHeight,scrollTo:t=>(e.scrollTo({top:t,behavior:"instant"}),e.scrollTop),onScroll:t=>(e.addEventListener("scroll",t,{passive:!0}),()=>e.removeEventListener("scroll",t)),onIntent:t=>{for(const n of ke)e.addEventListener(n,t,{capture:!0,passive:!0});return()=>{for(const n of ke)e.removeEventListener(n,t,{capture:!0})}}}),ne="[data-aqmd-scroll-container]",Et="[data-aqmd-content]",bt=`[${ue.SOURCE_LINES_ATTRIBUTE}]`,xt=Object.freeze(["p1","p2","p3","p4","p5","p6","p7","p8"]),Pe=(e,t)=>{const n=x.loadedOf(e.peek(t));return n!==null&&n.document.kind==="markdown"?{htmlContent:n.document.htmlContent,headings:n.document.headings}:null},St=(e,t,n,r,i)=>{if(n===void 0)return null;let o;try{o=mt(e,t)}catch(l){return console.error("[markdown-explorer] the draft sanitizer cannot run in this browser, so the server renders the preview",l),null}return{converter:n,sanitize:o,marksOf:dt,seed:Pe(r,i)?.htmlContent??null}},yt=e=>{const t=[];let n=null;for(const r of e.querySelectorAll(bt)){const i=ue.parseSourceLines(r.getAttribute(ue.SOURCE_LINES_ATTRIBUTE));if(i===null||r.getClientRects().length===0)continue;n??=e.scrollTop-x.visibleTopOf(e,r);const{top:o,bottom:l}=r.getBoundingClientRect();t.push({first:i.first,last:i.last,top:n+o,bottom:n+l})}return t},Tt=({path:e,readDraft:t,viewer:n,tables:r,concealed:i,onEditAt:o,onLayout:l,handleRef:s})=>{const{config:d,data:f,documents:p,draftConverter:k,labels:c}=x.useExplorer(),[E,u]=h.useState(()=>({parsed:Pe(p,e),source:null,failure:null,busy:!0,tier:k===void 0?"server":"instant"})),m=h.useRef(null),v=h.useRef(null),y=h.useRef(E);h.useLayoutEffect(()=>{y.current=E});const g=h.useEffectEvent(()=>t());h.useEffect(()=>{const a=St(d.iframeHosts,d.dataPath,k,p,e),I=g(),R=ft({path:e,instant:a,preview:f.preview,initial:y.current,onView:w=>h.startTransition(()=>u(w))});return v.current=R,R.update(I),()=>{R.dispose(),v.current=null}},[d,f,p,k,e]);const L=h.useEffectEvent(()=>l());h.useLayoutEffect(()=>{E.parsed!==null&&L()},[E.parsed]);const O=E.parsed!==null;h.useLayoutEffect(()=>{const a=O?m.current?.querySelector(ne):null;if(!(a instanceof HTMLElement))return;a.tabIndex=0;const I=new ResizeObserver(()=>L());I.observe(a);const R=a.querySelector(Et);return R!==null&&I.observe(R),()=>I.disconnect()},[O]);const A=h.useRef(null);h.useImperativeHandle(s,()=>({draft:a=>{v.current?.update(a)},scrollPort:()=>{const a=m.current?.querySelector(ne);return a instanceof HTMLElement?(A.current?.scroller!==a&&(A.current={scroller:a,port:_e(a)}),A.current.port):null},blocks:()=>{const a=m.current?.querySelector(ne);return a instanceof HTMLElement?yt(a):[]},focus:()=>{const a=m.current?.querySelector(ne);a instanceof HTMLElement&&a.focus({preventScroll:!0})},anchor:a=>{const I=m.current,R=I?.querySelector(ne);return I===null||!(R instanceof HTMLElement)?null:x.anchorOfView(I,a(R))},place:({line:a,clientTop:I},R)=>{const w=m.current,T=w===null?null:x.blockAtLine(w,a);T!==null&&(R(T).scrollTop+=x.lineTopIn(T,a)-I)}}),[]);const D=a=>{const I=m.current,{target:R}=a;if(o===void 0||I===null||!(R instanceof Element)||!x.isEditingDoubleClick(R))return;const w=x.anchorOfDoubleClick(R,I,I.ownerDocument.getSelection());w!==null&&o(w)},M=E.source===null?null:E.source.revision,F=h.useMemo(()=>M===null?void 0:{write:a=>r.write(M,a),read:a=>r.read(M,a),undo:r.undo,redo:r.redo,subscribe:r.subscribe},[r,M]),B=h.useMemo(()=>({...n.labels,spreadsheetReadOnly:c.previewTablePending}),[n.labels,c.previewTablePending]),j=h.useMemo(()=>({...n,labels:F===void 0?B:n.labels,showToc:!1,showStyle:!1,showAlign:!1,renderScrollBar:void 0,scrollBarGutter:void 0,scrollBarInlineSize:void 0,spreadsheetEditor:F}),[n,B,F]),H=h.useMemo(()=>E.parsed===null?null:q.jsx("div",{className:"aqmx-document-viewer",children:q.jsx(He.MarkdownViewer,{...j,parseResult:E.parsed,content:null})}),[j,E.parsed]);return q.jsxs("section",{ref:m,className:"aqmx-edit-preview","aria-label":c.previewRegion,"aria-busy":E.busy,inert:i!==null,hidden:i==="removed","data-aqmx-preview-tier":E.tier,"data-testid":"markdown-explorer-edit-preview",onDoubleClick:o===void 0?void 0:D,children:[E.failure===null?null:q.jsx("p",{className:"aqmx-callout aqmx-document-notice","data-aqmx-tone":"warning","data-testid":"markdown-explorer-edit-preview-failure",children:c.previewFailed(x.failureTitleOf(c,E.failure.reason))}),H??(E.failure===null?q.jsx("div",{className:"aqmx-skeleton","aria-hidden":"true","data-testid":"markdown-explorer-edit-preview-skeleton",children:xt.map(a=>q.jsx("span",{},a))}):null),E.busy?q.jsx("p",{className:"aqmx-sr-only",children:c.previewUpdating}):null]})},Le="data-aqmx-edit-split",ae="--aqmx-edit-share",Ie="--aqmx-edit-gutter",kt="data-aqmx-edit-split-probe",Lt="aqmx-edit-split",It="aqmx-edit-editor",At="aqmx-edit-preview",Ae={value:X.EDIT_SPLIT_MIN_PERCENT,unit:"percentage"},Oe={value:X.EDIT_SPLIT_MAX_PERCENT,unit:"percentage"},Re=e=>{if(e.length!==2)return null;const[t=0,n=0]=e,r=t+n;return r>0?t/r*100:null},ie=e=>{const t=e.current?.parentElement;if(t==null)throw new Error("[markdown-explorer] the edit split is not mounted in its surface");return t},Ot=(e,t,n)=>{const[r,i]=h.useState(null);return h.useLayoutEffect(()=>{const o=e.current,l=t.current;if(o===null||l===null)throw new Error("[markdown-explorer] the edit split is not mounted");const s={frame:o.getBoundingClientRect().width,measure:l.getBoundingClientRect().width},d=()=>{s.frame>0&&s.measure>0&&i(X.editSplitOrientation(s.frame,s.measure,n))};d();const f=new ResizeObserver(p=>{for(const k of p){const[c]=k.borderBoxSize;c!==void 0&&(k.target===o&&(s.frame=c.inlineSize),k.target===l&&(s.measure=c.inlineSize))}d()});return f.observe(o),f.observe(l),()=>f.disconnect()},[e,t,n]),r},Rt=({editorId:e})=>{const{edits:t,labels:n}=x.useExplorer(),r=h.useRef(null),i=h.useRef(null),o=x.useCoarsePointer()?X.COARSE_TARGET_PIXELS:X.FINE_TARGET_PIXELS,l=Ot(r,i,o),[s]=h.useState(()=>t.editorShare());h.useLayoutEffect(()=>{const p=ie(r);return p.style.setProperty(Ie,`${String(o)}px`),()=>{p.style.removeProperty(Ie)}},[o]),h.useLayoutEffect(()=>{const p=ie(r);return p.style.setProperty(ae,`${String(s)}%`),()=>{p.style.removeProperty(ae)}},[s]),h.useLayoutEffect(()=>{if(l===null)return;const p=ie(r);return p.setAttribute(Le,l),()=>p.removeAttribute(Le)},[l]);const d=ze.useSplitPersistence(h.useCallback(p=>{const k=Re(p);k!==null&&t.setEditorShare(k)},[t])),f=h.useCallback((p,k)=>{const c=Re(p);c!==null&&ie(r).style.setProperty(ae,`${String(c)}%`),d.layoutChanged(p,k)},[d]);return q.jsxs("div",{ref:r,className:"aqmx-edit-split","data-testid":"markdown-explorer-edit-split",children:[q.jsx("span",{ref:i,className:"aqmx-edit-split-probe","aria-hidden":"true",[kt]:""}),l===null?null:q.jsxs(se.PanelGroup,{id:Lt,direction:l==="beside"?"horizontal":"vertical",onLayout:f,className:"aqmx-edit-split-group",children:[q.jsx(se.Panel,{id:It,defaultSize:{value:s,unit:"percentage"},minSize:Ae,maxSize:Oe,contentOverflow:"hidden"}),q.jsx(se.PanelResizeHandle,{thickness:o,indicator:{visible:!0,thickness:X.SPLIT_HANDLE_PIXELS.gripThickness,length:X.SPLIT_HANDLE_PIXELS.gripLength,barThickness:X.SPLIT_HANDLE_PIXELS.barThickness,barLength:X.SPLIT_HANDLE_PIXELS.barLength},title:n.editViewSplitResize,"aria-label":n.editViewSplitResize,"aria-controls":e,onDragging:d.draggingChanged,className:"aqmx-split-handle aqmx-edit-split-handle"}),q.jsx(se.Panel,{id:At,defaultSize:{value:100-s,unit:"percentage"},minSize:Ae,maxSize:Oe,contentOverflow:"hidden"})]})]})},Ct=512,qt=()=>{const e=[];let t=0,n=null;const r=i=>{if(n===null||!Number.isInteger(i)||i<t)return null;if(i===t+e.length)return n;const o=e[i-t];return o===void 0?null:o.before};return{revision:()=>t+e.length,mount:i=>{if(n!==null&&(n===i||n.eq(i))){n=i;return}const o=t+e.length;e.length=0,t=n===null?o:o+1,n=i},record:(i,o)=>{if(n===null)throw new Error("[markdown-explorer] a change of the editor's text was recorded before an editor mounted");e.push({before:n,changes:i}),n=o,e.length>Ct&&(e.shift(),t+=1)},lineOf:(i,o)=>{const l=r(i);if(l===null||n===null||!Number.isInteger(o)||o<1||o>l.lines)return null;let s=l.line(o).from;for(const d of e.slice(i-t)){const f=d.changes.mapPos(s,1,$.MapMode.TrackAfter);if(f===null)return null;s=f}return n.lineAt(s).number}}},Ne=144,Mt=e=>{if(typeof e!="object"||e===null)return!1;const{generation:t,topLine:n}=e;return"state"in e&&typeof t=="number"&&typeof n=="number"},_t=e=>{e.stopPropagation()},Pt=e=>{const{path:t,name:n,session:r}=e,{edits:i,labels:o,announcer:l}=x.useExplorer(),{phase:s}=r,d=h.useCallback(()=>i.retry(t),[i,t]);switch(h.useEffect(()=>{s.kind==="failed"&&l.announce(o.documentFailed(n,x.failureTitleOf(o,s.failure.reason)))},[s,l,o,n]),s.kind){case"opening":return q.jsx(x.ContentSkeleton,{label:o.editLoading,testId:"markdown-explorer-edit-skeleton"});case"grant":return q.jsx("div",{className:"aqmx-edit-message",children:q.jsx(x.EditGrantNotice,{href:s.href,onRetry:d,testId:"markdown-explorer-edit-grant"})});case"failed":return q.jsx("div",{className:"aqmx-edit-message",children:q.jsx(x.FailureView,{failure:s.failure,alert:!1,onRetry:d,testId:"markdown-explorer-edit-failure"})});case"editing":return q.jsx(Nt,{...e})}},Nt=({path:e,name:t,session:n,layout:r,viewer:i,region:o,paneScroll:l})=>{const{edits:s,labels:d}=x.useExplorer(),f=h.useRef(null),p=h.useId(),k=h.useRef(null),[c]=h.useState(()=>new Set),[E]=h.useState(qt),u=h.useRef(null),m=h.useRef(null),v=r==="fill",y=x.useSideBySide(),g=x.editViewOf(n,y,v),L=g!=="editor"||n.previewPrepared,O=L&&v,A=h.useRef({layout:r,region:o,paneScroll:l});h.useLayoutEffect(()=>{A.current={layout:r,region:o,paneScroll:l}});const D=h.useRef(n.generation);h.useLayoutEffect(()=>{D.current=n.generation});const M=h.useRef({view:g,previewMounted:L});h.useLayoutEffect(()=>{M.current={view:g,previewMounted:L}});const F=h.useRef(null),B=h.useRef(null),j=h.useRef(!1),H=h.useMemo(()=>({editor:d.editorLabel(t),useOurs:d.conflictUseOurs,useTheirs:d.conflictUseTheirs,keepBoth:d.conflictKeepBoth}),[d,t]),a=h.useCallback(b=>{const{region:S,paneScroll:_}=A.current,z=S();return z===null?b:_.scrollerOf(z,b)},[]);h.useLayoutEffect(()=>{const b=f.current,S=s.draft(e);if(b===null||S===null)return;const _=s.editorState.get(e),z=Mt(_)&&_.generation===D.current?_:null;let W=null,Q=null;const le=()=>{W!==null&&clearTimeout(W),W=null,Q!==null&&s.setDraft(e,Q.text())},G=tt({parent:b,scroll:{scrollerOf:N=>{const{layout:Z,region:Ve,paneScroll:Be}=A.current,he=Ve();return Z==="fill"||he===null?N:Be.scrollerOf(he,N)},reveal:N=>A.current.paneScroll.reveal(N)},text:S,saved:z===null?void 0:z.state,labels:H,revisions:E,onGeometry:N=>m.current?.editorChanged(N),onChange:N=>{if(W??=setTimeout(le,Ne),!N)for(const Z of[...c])Z();M.current.previewMounted&&Q!==null&&u.current?.draft({text:Q.text(),revision:E.revision()})},onSave:()=>{s.save(e)}});Q=G,k.current=G;const fe=()=>{const N=G.topLine();return{line:N.line,clientTop:N.clientTop}},me=()=>u.current?.anchor(a)??null,De=s.bindEditor(e,{flush:le,adopt:N=>G.replaceText(N),returnPoint:()=>{const N=M.current.view==="preview"&&A.current.layout==="content"?me():null;return N===null?fe():{line:N.lines.first,clientTop:N.clientTop}},nextConflict:()=>M.current.view!=="preview"?G.nextConflict():G.conflicts().length===0?!1:(j.current=!0,s.setView(e,"editor"),!0),beforeView:N=>{if(A.current.layout==="fill")return;if(N==="preview"){F.current={to:"preview",point:fe()};return}const Z=me();F.current=Z===null?null:{to:"editor",anchor:Z}}});return z!==null&&G.showLine(z.topLine),()=>{le(),s.editorState.set(e,{state:G.save(),generation:D.current,topLine:G.topLine().line}),De(),G.destroy(),Q=null,k.current=null}},[s,e,H,a,c,E]);const{request:I}=n;h.useLayoutEffect(()=>{const b=k.current,S=s.draft(e);b===null||S===null||I===null||(I.anchor!==null&&b.reveal(x.positionInSource(S,I.anchor),I.anchor.clientTop),b.focus(),s.consumeRequest(e))},[s,e,I,H]),h.useLayoutEffect(()=>{g!=="editor"&&!n.previewPrepared&&s.preparePreview(e)},[s,e,g,n.previewPrepared]),h.useLayoutEffect(()=>{const b=F.current,S=B.current,_=j.current;F.current=null,B.current=null,j.current=!1;const z=k.current;if(b?.to==="preview")u.current?.place(b.point,a);else if(b?.to==="editor"&&z!==null){const W=s.draft(e);W!==null&&z.reveal(x.positionInSource(W,b.anchor),b.anchor.clientTop)}_?z?.nextConflict():S==="editor"?z?.focus():S==="preview"&&u.current?.focus()},[s,e,g,a]);const R=h.useMemo(()=>{const b=()=>{const S=k.current;if(S===null)throw new Error("[markdown-explorer] a table of the preview wrote back while no editor was mounted");return S};return{write:(S,{fenceLine:_,expected:z,text:W})=>b().replaceBody(_,z,W,S),read:(S,_)=>b().readBody(_,S),undo:()=>b().undo(),redo:()=>b().redo(),subscribe:S=>(c.add(S),()=>{c.delete(S)})}},[c]),w=h.useCallback(()=>{const b=k.current;if(b===null)throw new Error("[markdown-explorer] the preview read the draft before the editor was mounted");return{text:b.text(),revision:E.revision()}},[E]);h.useLayoutEffect(()=>{const b=k.current;if(!O||b===null)return;const S=wt({editor:_e(b.scrollElement),preview:()=>u.current?.scrollPort()??null,previewBlocks:()=>u.current?.blocks()??[],editorSpans:_=>b.lineSpans(_),requestFrame:_=>requestAnimationFrame(_),cancelFrame:_=>cancelAnimationFrame(_),now:()=>performance.now()});return S.showAlone(x.paneShownAlone(M.current.view)),m.current=S,()=>{S.dispose(),m.current=null}},[O,s,e,H]),h.useLayoutEffect(()=>{m.current?.showAlone(x.paneShownAlone(g))},[g]);const T=h.useCallback(()=>m.current?.previewChanged(),[]),C=h.useCallback(b=>s.start(e,b),[s,e]),U=b=>{if(x.isInFullscreenBlock(b.target))return;if(b.key==="Escape"){x.consumeKey(b);return}if(!x.isEditViewShortcut(b.nativeEvent,x.isApplePlatform(navigator.platform)))return;x.consumeKey(b);const S=x.toggledEditView(g);B.current=S,x.chooseEditView(s,e,S,v)};return q.jsxs("div",{className:"aqmx-edit","data-aqmx-edit-layout":r,"data-aqmx-edit-view":g,"data-testid":"markdown-explorer-edit",onKeyDown:U,onDoubleClick:_t,children:[q.jsx("div",{ref:f,id:p,className:"aqmx-edit-editor","data-testid":"markdown-explorer-editor",inert:g==="preview",hidden:g==="preview"&&!v,...x.ALLOW_KEY_REPEAT}),g==="split"?q.jsx(Rt,{editorId:p}):null,L?q.jsx(Tt,{path:e,readDraft:w,viewer:i,tables:R,concealed:g!=="editor"?null:v?"overlay":"removed",onEditAt:g==="preview"?C:void 0,onLayout:T,handleRef:u}):null]})};exports.DRAFT_WRITE_INTERVAL_MS=Ne;exports.default=Pt;
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import { jsx as R, jsxs as le } from "react/jsx-runtime";
|
|
2
2
|
import { useState as te, useRef as D, useLayoutEffect as B, useEffectEvent as ve, useEffect as Ne, useImperativeHandle as je, useMemo as J, startTransition as Ye, useCallback as X, useId as Je } from "react";
|
|
3
|
-
import { v as ne,
|
|
4
|
-
import { fencedBodyAsRead as
|
|
5
|
-
import { history as
|
|
6
|
-
import { markdown as
|
|
7
|
-
import { syntaxHighlighting as
|
|
8
|
-
import { highlightSelectionMatches as
|
|
9
|
-
import { EditorState as Ve, EditorSelection as fe, StateField as
|
|
10
|
-
import { EditorView as K, lineNumbers as
|
|
3
|
+
import { v as ne, k as me, l as Qe, u as se, m as Ze, n as et, o as tt, p as De, q as nt, t as rt, w as ot, c as it, x as lt, E as st, y as ct, z as at, A as ut, B as we, G as be, H as dt, I as ft, J as Ee, K as mt, L as pt, M as ht, O as gt } from "./index-DR31S_-4.js";
|
|
4
|
+
import { fencedBodyAsRead as vt, planFencedBodyEdit as wt, fencedCodeLanguageOf as bt, SPREADSHEETS_LANGUAGE as Et, readFencedLine as xt, listItemWidthOn as St, openingFenceOn as yt } from "@aiquants/markdown/code-blocks";
|
|
5
|
+
import { history as kt, historyKeymap as Tt, defaultKeymap as At, historyField as It, redo as Ot, undo as Ct, isolateHistory as Lt } from "@codemirror/commands";
|
|
6
|
+
import { markdown as Mt, markdownLanguage as qt } from "@codemirror/lang-markdown";
|
|
7
|
+
import { syntaxHighlighting as Rt, syntaxTreeAvailable as _t, HighlightStyle as Pt, ensureSyntaxTree as Be } from "@codemirror/language";
|
|
8
|
+
import { highlightSelectionMatches as Nt, searchKeymap as Dt } from "@codemirror/search";
|
|
9
|
+
import { EditorState as Ve, EditorSelection as fe, StateField as Bt, RangeSetBuilder as Vt, MapMode as Ht } from "@codemirror/state";
|
|
10
|
+
import { EditorView as K, lineNumbers as zt, highlightActiveLineGutter as Ft, drawSelection as Gt, highlightActiveLine as Ut, keymap as Wt, ViewPlugin as Kt, Decoration as ce, WidgetType as $t } from "@codemirror/view";
|
|
11
11
|
import { tags as P } from "@lezer/highlight";
|
|
12
|
-
import { MarkdownViewer as
|
|
13
|
-
import { SOURCE_LINES_ATTRIBUTE as He, parseSourceLines as
|
|
14
|
-
import { d as
|
|
15
|
-
import { H as
|
|
16
|
-
import
|
|
17
|
-
import { PanelGroup as
|
|
18
|
-
import { C as
|
|
19
|
-
import { u as
|
|
20
|
-
const ze = { history:
|
|
12
|
+
import { MarkdownViewer as Xt } from "@aiquants/markdown";
|
|
13
|
+
import { SOURCE_LINES_ATTRIBUTE as He, parseSourceLines as jt } from "@aiquants/markdown/source-lines";
|
|
14
|
+
import { d as Yt, f as re, E as Jt } from "./dataRoute-D6KiSHIc.js";
|
|
15
|
+
import { H as Qt, c as Zt, M as en } from "./sanitizePolicy-CwvyPpp5.js";
|
|
16
|
+
import tn from "isomorphic-dompurify";
|
|
17
|
+
import { PanelGroup as nn, Panel as xe, PanelResizeHandle as rn } from "@aiquants/resize-panels";
|
|
18
|
+
import { C as on, F as ln, E as sn, a as cn, b as oe, d as an } from "./location-C44b9H1S.js";
|
|
19
|
+
import { u as un } from "./useSplitPersistence-DCeYbJMx.js";
|
|
20
|
+
const ze = { history: It }, dn = Pt.define([
|
|
21
21
|
{ tag: [P.heading1, P.heading2, P.heading3, P.heading4, P.heading5, P.heading6, P.heading], color: "var(--aqmx-syntax-heading)", fontWeight: "700" },
|
|
22
22
|
{ tag: P.strong, fontWeight: "700" },
|
|
23
23
|
{ tag: P.emphasis, fontStyle: "italic" },
|
|
@@ -41,7 +41,7 @@ const ze = { history: At }, dn = _t.define([
|
|
|
41
41
|
".cm-searchMatch": { outline: "var(--aqmx-space-1) solid var(--aqmx-border-strong)" },
|
|
42
42
|
".cm-panels": { backgroundColor: "var(--aqmx-surface-raised)", color: "var(--aqmx-text)" }
|
|
43
43
|
}), Fe = "data-aqmx-conflict-actions", mn = ce.line({ attributes: { "data-aqmx-conflict-line": "marker" } }), pn = ce.line({ attributes: { "data-aqmx-conflict-line": "ours" } }), hn = ce.line({ attributes: { "data-aqmx-conflict-line": "theirs" } });
|
|
44
|
-
class gn extends
|
|
44
|
+
class gn extends $t {
|
|
45
45
|
constructor(t, n) {
|
|
46
46
|
super(), this.index = t, this.labels = n;
|
|
47
47
|
}
|
|
@@ -71,7 +71,7 @@ class gn extends Kt {
|
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
const ee = (e) => Qe(e.iterLines()), Se = (e, t) => {
|
|
74
|
-
const n = new
|
|
74
|
+
const n = new Vt();
|
|
75
75
|
return ee(e).forEach((r, l) => {
|
|
76
76
|
const o = e.line(r.start);
|
|
77
77
|
n.add(o.from, o.from, ce.widget({ widget: new gn(l, t), block: !0, side: -1 }));
|
|
@@ -80,7 +80,7 @@ const ee = (e) => Qe(e.iterLines()), Se = (e, t) => {
|
|
|
80
80
|
n.add(i, i, d);
|
|
81
81
|
}
|
|
82
82
|
}), n.finish();
|
|
83
|
-
}, vn = (e) =>
|
|
83
|
+
}, vn = (e) => Bt.define({
|
|
84
84
|
create: (t) => Se(t.doc, e),
|
|
85
85
|
update: (t, n) => n.docChanged ? Se(n.state.doc, e) : t,
|
|
86
86
|
provide: (t) => K.decorations.from(t)
|
|
@@ -95,7 +95,7 @@ const ee = (e) => Qe(e.iterLines()), Se = (e, t) => {
|
|
|
95
95
|
const p = i.join(`
|
|
96
96
|
`);
|
|
97
97
|
e.dispatch({ changes: { from: d, to: f, insert: p }, selection: fe.cursor(d), scrollIntoView: !0, userEvent: "input.resolve" });
|
|
98
|
-
}, ye = "input.preview", wn = 20, bn =
|
|
98
|
+
}, ye = "input.preview", wn = 20, bn = Kt.fromClass(
|
|
99
99
|
class {
|
|
100
100
|
constructor(e) {
|
|
101
101
|
this.view = e, this.schedule();
|
|
@@ -106,7 +106,7 @@ const ee = (e) => Qe(e.iterLines()), Se = (e, t) => {
|
|
|
106
106
|
e.docChanged && this.schedule();
|
|
107
107
|
}
|
|
108
108
|
schedule() {
|
|
109
|
-
if (this.cancel !== null ||
|
|
109
|
+
if (this.cancel !== null || _t(this.view.state)) return;
|
|
110
110
|
const e = this.view.dom.ownerDocument.defaultView;
|
|
111
111
|
if (e === null) return;
|
|
112
112
|
const t = () => {
|
|
@@ -135,14 +135,14 @@ const ee = (e) => Qe(e.iterLines()), Se = (e, t) => {
|
|
|
135
135
|
for (const d of r) {
|
|
136
136
|
const f = e.lineAt(d.from).number;
|
|
137
137
|
if (d.name === "ListItem") {
|
|
138
|
-
const p =
|
|
138
|
+
const p = St(e.line(f).text, l, s(f));
|
|
139
139
|
if (p === null) return null;
|
|
140
140
|
l.push({ kind: "listItem", width: p });
|
|
141
141
|
} else
|
|
142
142
|
l.push({ kind: "quote" });
|
|
143
143
|
o.push(f);
|
|
144
144
|
}
|
|
145
|
-
const i =
|
|
145
|
+
const i = yt(n.text, l, s(n.number));
|
|
146
146
|
return i === null ? null : { containers: l, ...i };
|
|
147
147
|
}, Sn = (e, t) => {
|
|
148
148
|
const { doc: n } = e;
|
|
@@ -164,15 +164,15 @@ const ee = (e) => Qe(e.iterLines()), Se = (e, t) => {
|
|
|
164
164
|
if (o === null) return Q;
|
|
165
165
|
const s = o.getChild("CodeInfo");
|
|
166
166
|
if (s === null) return Q;
|
|
167
|
-
const i =
|
|
167
|
+
const i = bt(n.sliceString(s.from, s.to));
|
|
168
168
|
if (i === null) return ue;
|
|
169
|
-
if (i !==
|
|
169
|
+
if (i !== Et) return Q;
|
|
170
170
|
const d = xn(n, o, r);
|
|
171
171
|
if (d === null) return ue;
|
|
172
172
|
const [, ...f] = o.getChildren("CodeMark"), p = f.at(-1), y = p === void 0 ? n.lineAt(o.to).number : n.lineAt(p.from).number - 1, c = [];
|
|
173
173
|
let w = "";
|
|
174
174
|
for (let u = t + 1; u <= y; u += 1) {
|
|
175
|
-
const m = n.line(u).text, g =
|
|
175
|
+
const m = n.line(u).text, g = xt(m, d);
|
|
176
176
|
if (g === null) return ue;
|
|
177
177
|
c.push(m), w += u < n.lines ? `${g.content}
|
|
178
178
|
` : g.content;
|
|
@@ -182,26 +182,26 @@ const ee = (e) => Qe(e.iterLines()), Se = (e, t) => {
|
|
|
182
182
|
let f = !1;
|
|
183
183
|
const p = [
|
|
184
184
|
K.scrollHandler.of((u, m, g) => (kn(u, m.head, g, t), !0)),
|
|
185
|
-
Ht(),
|
|
186
185
|
zt(),
|
|
187
|
-
yt(),
|
|
188
186
|
Ft(),
|
|
187
|
+
kt(),
|
|
189
188
|
Gt(),
|
|
190
|
-
|
|
189
|
+
Ut(),
|
|
190
|
+
Nt(),
|
|
191
191
|
K.lineWrapping,
|
|
192
|
-
|
|
192
|
+
Mt({ base: qt }),
|
|
193
193
|
bn,
|
|
194
|
-
|
|
194
|
+
Rt(dn),
|
|
195
195
|
vn(l),
|
|
196
|
-
|
|
196
|
+
Wt.of([
|
|
197
197
|
{
|
|
198
198
|
key: "Mod-s",
|
|
199
199
|
preventDefault: !0,
|
|
200
200
|
run: () => (d(), !0)
|
|
201
201
|
},
|
|
202
|
-
...
|
|
203
|
-
...
|
|
204
|
-
...
|
|
202
|
+
...Dt,
|
|
203
|
+
...Tt,
|
|
204
|
+
...At
|
|
205
205
|
]),
|
|
206
206
|
K.contentAttributes.of({ "aria-label": l.editor, "aria-multiline": "true" }),
|
|
207
207
|
K.updateListener.of((u) => {
|
|
@@ -237,8 +237,8 @@ const ee = (e) => Qe(e.iterLines()), Se = (e, t) => {
|
|
|
237
237
|
const I = ke(c.state, k);
|
|
238
238
|
if (I.kind === "absent") return "changed";
|
|
239
239
|
if (I.kind === "unreadable") return "unwritable";
|
|
240
|
-
if (I.body !==
|
|
241
|
-
const A =
|
|
240
|
+
if (I.body !== vt(m, I.layout)) return "changed";
|
|
241
|
+
const A = wt(I.lines, I.layout, g);
|
|
242
242
|
if (A.kind !== "edit") return A.kind;
|
|
243
243
|
if (A.from === A.to && A.lines.length === 0) return "written";
|
|
244
244
|
const _ = (H) => {
|
|
@@ -248,7 +248,7 @@ const ee = (e) => Qe(e.iterLines()), Se = (e, t) => {
|
|
|
248
248
|
` ? `
|
|
249
249
|
` : ""}${A.lines.map((H) => `${H}
|
|
250
250
|
`).join("")}`;
|
|
251
|
-
return w(() => c.dispatch({ changes: { from: L, to: _(A.to), insert: N }, userEvent: ye, annotations:
|
|
251
|
+
return w(() => c.dispatch({ changes: { from: L, to: _(A.to), insert: N }, userEvent: ye, annotations: Lt.of("full") })), "written";
|
|
252
252
|
},
|
|
253
253
|
readBody: (u, m) => {
|
|
254
254
|
const g = o.lineOf(m, u);
|
|
@@ -256,8 +256,8 @@ const ee = (e) => Qe(e.iterLines()), Se = (e, t) => {
|
|
|
256
256
|
const x = ke(c.state, g);
|
|
257
257
|
return x.kind === "found" ? x.body : null;
|
|
258
258
|
},
|
|
259
|
-
undo: () => w(() =>
|
|
260
|
-
redo: () => w(() =>
|
|
259
|
+
undo: () => w(() => Ct(c)),
|
|
260
|
+
redo: () => w(() => Ot(c)),
|
|
261
261
|
reveal: ({ line: u, column: m }, g) => {
|
|
262
262
|
const { doc: x } = c.state, h = x.line(Math.min(Math.max(u, 1), x.lines)), k = Math.min(h.from + m, h.to);
|
|
263
263
|
c.dispatch({ selection: fe.cursor(k), effects: Te(c, k, g, t) });
|
|
@@ -380,7 +380,7 @@ const ee = (e) => Qe(e.iterLines()), Se = (e, t) => {
|
|
|
380
380
|
return M === void 0 && !C[E.kind].has(E.path) && (C[E.kind].add(E.path), S.push(E)), M ?? void 0;
|
|
381
381
|
});
|
|
382
382
|
} catch (E) {
|
|
383
|
-
_(), E instanceof
|
|
383
|
+
_(), E instanceof Qt ? L(re("too-large"), "instant") : (k("the draft sanitizer failed", E), L(re("failed"), "instant"));
|
|
384
384
|
return;
|
|
385
385
|
}
|
|
386
386
|
w = S;
|
|
@@ -418,12 +418,12 @@ const ee = (e) => Qe(e.iterLines()), Se = (e, t) => {
|
|
|
418
418
|
} catch (b) {
|
|
419
419
|
return o.signal.aborted || k("the draft converter rejected a conversion, which its contract allows only once the signal aborted", b), Ae;
|
|
420
420
|
}
|
|
421
|
-
const U =
|
|
421
|
+
const U = Yt(C);
|
|
422
422
|
return U === null ? C : (k(`the draft converter answered outside its contract: ${U}`), Ae);
|
|
423
423
|
}, T = (v, S) => {
|
|
424
424
|
switch (S.kind) {
|
|
425
425
|
case "preview":
|
|
426
|
-
if (A(), S.headings.length >
|
|
426
|
+
if (A(), S.headings.length > Jt) {
|
|
427
427
|
_(), L(re("too-large"), "instant");
|
|
428
428
|
return;
|
|
429
429
|
}
|
|
@@ -464,7 +464,7 @@ const ee = (e) => Qe(e.iterLines()), Se = (e, t) => {
|
|
|
464
464
|
o.abort(), y = null, clearTimeout(u), u = void 0, A();
|
|
465
465
|
}
|
|
466
466
|
};
|
|
467
|
-
}, Pn = (e, t) =>
|
|
467
|
+
}, Pn = (e, t) => Zt(tn(window), e, t, en), Nn = (e, t) => e.flatMap((n, r) => {
|
|
468
468
|
const l = t[r];
|
|
469
469
|
return l === void 0 ? [] : [
|
|
470
470
|
{ editor: l.top, preview: n.top },
|
|
@@ -584,7 +584,7 @@ const ee = (e) => Qe(e.iterLines()), Se = (e, t) => {
|
|
|
584
584
|
const t = [];
|
|
585
585
|
let n = null;
|
|
586
586
|
for (const r of e.querySelectorAll(Fn)) {
|
|
587
|
-
const l =
|
|
587
|
+
const l = jt(r.getAttribute(He));
|
|
588
588
|
if (l === null || r.getClientRects().length === 0) continue;
|
|
589
589
|
n ??= e.scrollTop - ne(e, r);
|
|
590
590
|
const { top: o, bottom: s } = r.getBoundingClientRect();
|
|
@@ -662,10 +662,20 @@ const ee = (e) => Qe(e.iterLines()), Se = (e, t) => {
|
|
|
662
662
|
},
|
|
663
663
|
[r, L]
|
|
664
664
|
), N = J(() => ({ ...n.labels, spreadsheetReadOnly: c.previewTablePending }), [n.labels, c.previewTablePending]), H = J(
|
|
665
|
-
() => ({
|
|
665
|
+
() => ({
|
|
666
|
+
...n,
|
|
667
|
+
labels: F === void 0 ? N : n.labels,
|
|
668
|
+
showToc: !1,
|
|
669
|
+
showStyle: !1,
|
|
670
|
+
showAlign: !1,
|
|
671
|
+
renderScrollBar: void 0,
|
|
672
|
+
scrollBarGutter: void 0,
|
|
673
|
+
scrollBarInlineSize: void 0,
|
|
674
|
+
spreadsheetEditor: F
|
|
675
|
+
}),
|
|
666
676
|
[n, N, F]
|
|
667
677
|
), V = J(
|
|
668
|
-
() => w.parsed === null ? null : /* @__PURE__ */ R("div", { className: "aqmx-document-viewer", children: /* @__PURE__ */ R(
|
|
678
|
+
() => w.parsed === null ? null : /* @__PURE__ */ R("div", { className: "aqmx-document-viewer", children: /* @__PURE__ */ R(Xt, { ...H, parseResult: w.parsed, content: null }) }),
|
|
669
679
|
[H, w.parsed]
|
|
670
680
|
);
|
|
671
681
|
return /* @__PURE__ */ le(
|
|
@@ -687,7 +697,7 @@ const ee = (e) => Qe(e.iterLines()), Se = (e, t) => {
|
|
|
687
697
|
]
|
|
688
698
|
}
|
|
689
699
|
);
|
|
690
|
-
}, Me = "data-aqmx-edit-split", de = "--aqmx-edit-share", qe = "--aqmx-edit-gutter", $n = "data-aqmx-edit-split-probe", Xn = "aqmx-edit-split", jn = "aqmx-edit-editor", Yn = "aqmx-edit-preview", Re = { value:
|
|
700
|
+
}, Me = "data-aqmx-edit-split", de = "--aqmx-edit-share", qe = "--aqmx-edit-gutter", $n = "data-aqmx-edit-split-probe", Xn = "aqmx-edit-split", jn = "aqmx-edit-editor", Yn = "aqmx-edit-preview", Re = { value: cn, unit: "percentage" }, _e = { value: sn, unit: "percentage" }, Pe = (e) => {
|
|
691
701
|
if (e.length !== 2) return null;
|
|
692
702
|
const [t = 0, n = 0] = e, r = t + n;
|
|
693
703
|
return r > 0 ? t / r * 100 : null;
|
|
@@ -701,7 +711,7 @@ const ee = (e) => Qe(e.iterLines()), Se = (e, t) => {
|
|
|
701
711
|
const o = e.current, s = t.current;
|
|
702
712
|
if (o === null || s === null) throw new Error("[markdown-explorer] the edit split is not mounted");
|
|
703
713
|
const i = { frame: o.getBoundingClientRect().width, measure: s.getBoundingClientRect().width }, d = () => {
|
|
704
|
-
i.frame > 0 && i.measure > 0 && l(
|
|
714
|
+
i.frame > 0 && i.measure > 0 && l(an(i.frame, i.measure, n));
|
|
705
715
|
};
|
|
706
716
|
d();
|
|
707
717
|
const f = new ResizeObserver((p) => {
|
|
@@ -714,7 +724,7 @@ const ee = (e) => Qe(e.iterLines()), Se = (e, t) => {
|
|
|
714
724
|
return f.observe(o), f.observe(s), () => f.disconnect();
|
|
715
725
|
}, [e, t, n]), r;
|
|
716
726
|
}, Qn = ({ editorId: e }) => {
|
|
717
|
-
const { edits: t, labels: n } = se(), r = D(null), l = D(null), o =
|
|
727
|
+
const { edits: t, labels: n } = se(), r = D(null), l = D(null), o = it() ? on : ln, s = Jn(r, l, o), [i] = te(() => t.editorShare());
|
|
718
728
|
B(() => {
|
|
719
729
|
const p = ie(r);
|
|
720
730
|
return p.style.setProperty(qe, `${String(o)}px`), () => {
|
|
@@ -747,10 +757,10 @@ const ee = (e) => Qe(e.iterLines()), Se = (e, t) => {
|
|
|
747
757
|
);
|
|
748
758
|
return /* @__PURE__ */ le("div", { ref: r, className: "aqmx-edit-split", "data-testid": "markdown-explorer-edit-split", children: [
|
|
749
759
|
/* @__PURE__ */ R("span", { ref: l, className: "aqmx-edit-split-probe", "aria-hidden": "true", [$n]: "" }),
|
|
750
|
-
s === null ? null : /* @__PURE__ */ le(
|
|
760
|
+
s === null ? null : /* @__PURE__ */ le(nn, { id: Xn, direction: s === "beside" ? "horizontal" : "vertical", onLayout: f, className: "aqmx-edit-split-group", children: [
|
|
751
761
|
/* @__PURE__ */ R(xe, { id: jn, defaultSize: { value: i, unit: "percentage" }, minSize: Re, maxSize: _e, contentOverflow: "hidden" }),
|
|
752
762
|
/* @__PURE__ */ R(
|
|
753
|
-
|
|
763
|
+
rn,
|
|
754
764
|
{
|
|
755
765
|
thickness: o,
|
|
756
766
|
indicator: { visible: !0, thickness: oe.gripThickness, length: oe.gripLength, barThickness: oe.barThickness, barLength: oe.barLength },
|
|
@@ -792,7 +802,7 @@ const ee = (e) => Qe(e.iterLines()), Se = (e, t) => {
|
|
|
792
802
|
if (s === null || n === null || !Number.isInteger(o) || o < 1 || o > s.lines) return null;
|
|
793
803
|
let i = s.line(o).from;
|
|
794
804
|
for (const d of e.slice(l - t)) {
|
|
795
|
-
const f = d.changes.mapPos(i, 1,
|
|
805
|
+
const f = d.changes.mapPos(i, 1, Ht.TrackAfter);
|
|
796
806
|
if (f === null) return null;
|
|
797
807
|
i = f;
|
|
798
808
|
}
|
|
@@ -811,16 +821,16 @@ const ee = (e) => Qe(e.iterLines()), Se = (e, t) => {
|
|
|
811
821
|
i.kind === "failed" && s.announce(o.documentFailed(n, De(o, i.failure.reason)));
|
|
812
822
|
}, [i, s, o, n]), i.kind) {
|
|
813
823
|
case "opening":
|
|
814
|
-
return /* @__PURE__ */ R(
|
|
824
|
+
return /* @__PURE__ */ R(ct, { label: o.editLoading, testId: "markdown-explorer-edit-skeleton" });
|
|
815
825
|
case "grant":
|
|
816
|
-
return /* @__PURE__ */ R("div", { className: "aqmx-edit-message", children: /* @__PURE__ */ R(
|
|
826
|
+
return /* @__PURE__ */ R("div", { className: "aqmx-edit-message", children: /* @__PURE__ */ R(st, { href: i.href, onRetry: d, testId: "markdown-explorer-edit-grant" }) });
|
|
817
827
|
case "failed":
|
|
818
|
-
return /* @__PURE__ */ R("div", { className: "aqmx-edit-message", children: /* @__PURE__ */ R(
|
|
828
|
+
return /* @__PURE__ */ R("div", { className: "aqmx-edit-message", children: /* @__PURE__ */ R(lt, { failure: i.failure, alert: !1, onRetry: d, testId: "markdown-explorer-edit-failure" }) });
|
|
819
829
|
case "editing":
|
|
820
830
|
return /* @__PURE__ */ R(or, { ...e });
|
|
821
831
|
}
|
|
822
832
|
}, or = ({ path: e, name: t, session: n, layout: r, viewer: l, region: o, paneScroll: s }) => {
|
|
823
|
-
const { edits: i, labels: d } = se(), f = D(null), p = Je(), y = D(null), [c] = te(() => /* @__PURE__ */ new Set()), [w] = te(er), u = D(null), m = D(null), g = r === "fill", x =
|
|
833
|
+
const { edits: i, labels: d } = se(), f = D(null), p = Je(), y = D(null), [c] = te(() => /* @__PURE__ */ new Set()), [w] = te(er), u = D(null), m = D(null), g = r === "fill", x = at(), h = ut(n, x, g), k = h !== "editor" || n.previewPrepared, I = k && g, A = D({ layout: r, region: o, paneScroll: s });
|
|
824
834
|
B(() => {
|
|
825
835
|
A.current = { layout: r, region: o, paneScroll: s };
|
|
826
836
|
});
|
|
@@ -950,17 +960,17 @@ const ee = (e) => Qe(e.iterLines()), Se = (e, t) => {
|
|
|
950
960
|
const S = X(() => m.current?.previewChanged(), []), C = X((b) => i.start(e, b), [i, e]);
|
|
951
961
|
return (
|
|
952
962
|
/* @__PURE__ */ le("div", { className: "aqmx-edit", "data-aqmx-edit-layout": r, "data-aqmx-edit-view": h, "data-testid": "markdown-explorer-edit", onKeyDown: (b) => {
|
|
953
|
-
if (
|
|
963
|
+
if (ft(b.target)) return;
|
|
954
964
|
if (b.key === "Escape") {
|
|
955
965
|
Ee(b);
|
|
956
966
|
return;
|
|
957
967
|
}
|
|
958
|
-
if (!
|
|
968
|
+
if (!mt(b.nativeEvent, pt(navigator.platform))) return;
|
|
959
969
|
Ee(b);
|
|
960
|
-
const E =
|
|
961
|
-
N.current = E,
|
|
970
|
+
const E = gt(h);
|
|
971
|
+
N.current = E, ht(i, e, E, g);
|
|
962
972
|
}, onDoubleClick: rr, children: [
|
|
963
|
-
/* @__PURE__ */ R("div", { ref: f, id: p, className: "aqmx-edit-editor", "data-testid": "markdown-explorer-editor", inert: h === "preview", hidden: h === "preview" && !g, ...
|
|
973
|
+
/* @__PURE__ */ R("div", { ref: f, id: p, className: "aqmx-edit-editor", "data-testid": "markdown-explorer-editor", inert: h === "preview", hidden: h === "preview" && !g, ...dt }),
|
|
964
974
|
h === "split" ? /* @__PURE__ */ R(Qn, { editorId: p }) : null,
|
|
965
975
|
k ? /* @__PURE__ */ R(Kn, { path: e, readDraft: v, viewer: l, tables: O, concealed: h !== "editor" ? null : g ? "overlay" : "removed", onEditAt: h === "preview" ? C : void 0, onLayout: S, handleRef: u }) : null
|
|
966
976
|
] })
|