@aiquants/markdown-explorer 0.20.0 → 0.21.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 +24 -0
- package/README.md +5 -4
- package/dist/EditSurface-Bwl4S1vQ.cjs +7 -0
- package/dist/EditSurface-rKoy_ndP.js +880 -0
- package/dist/{ExplorerSplit-BAYa3WO3.js → ExplorerSplit-3WMRDA7G.js} +1 -1
- package/dist/{ExplorerSplit-DkE46pS0.cjs → ExplorerSplit-CdqEKz-I.cjs} +1 -1
- package/dist/{MultiLayout-DsxYURra.cjs → MultiLayout-BEg1X8Jx.cjs} +1 -1
- package/dist/{MultiLayout-BkhnkQs5.js → MultiLayout-Gf1xT-Le.js} +2 -2
- package/dist/{NativeScrollBar-CcNqDlO6.js → NativeScrollBar-0cpp2OIu.js} +1 -1
- package/dist/{NativeScrollBar-B57yWQVG.cjs → NativeScrollBar-idIQsvCv.cjs} +1 -1
- package/dist/{TreeLayout-DCGqVwt9.cjs → TreeLayout-DJY_WqzP.cjs} +1 -1
- package/dist/{TreeLayout-Cf2PzZEI.js → TreeLayout-DzZCgMTt.js} +2 -2
- package/dist/{index-DiLkl4dC.js → index-CJgHGeZs.js} +4 -4
- package/dist/{index-Bdve5EFS.cjs → index-bMaSoQTe.cjs} +3 -3
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/{merge-BIXNcrea.js → merge-BOcofJN5.js} +1 -1
- package/dist/{merge-DSfJceoQ.cjs → merge-BVk6pvO_.cjs} +1 -1
- package/docs/behavior/security.md +17 -7
- package/package.json +3 -3
- package/dist/EditSurface-D1yklbWu.js +0 -833
- package/dist/EditSurface-GxmyUeGE.cjs +0 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.21.0 (2026-10-26) — Tables inside list items and quotes write back from the preview, and a table follows every change of the editor's text
|
|
4
|
+
|
|
5
|
+
### Breaking
|
|
6
|
+
|
|
7
|
+
- **The peer floor is `@aiquants/markdown` ^10.0.0.** markdown 10 hands the editor to tables inside list items and
|
|
8
|
+
quotes and requires `SpreadsheetEditor.subscribe`, which the explorer's editor implements; the other peer floors stay
|
|
9
|
+
as in 0.20.0.
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- **Tables inside list items and quotes, and behind an indented fence, write back from the preview.** The editor finds
|
|
14
|
+
a table's block in its Markdown parse (to the closing fence, or to the end of the list item, the quote or the text) and
|
|
15
|
+
writes each line with the head the block's lines carry: the item's indentation, `>` with its space, the fence's own
|
|
16
|
+
indentation. Inside a list item a row whose cells are all empty or white space is written as an empty line, which is
|
|
17
|
+
how the converter reads such a line there. A block written by hand whose lines do not all carry that head refuses the
|
|
18
|
+
write-back as an edit conflict, as before.
|
|
19
|
+
|
|
20
|
+
### Fixed
|
|
21
|
+
|
|
22
|
+
- **An undo in the editor right after a table's edit shows the undone value in the table.** An undo that landed before
|
|
23
|
+
the edit's echo was drawn left the table showing its edit, because the preview's body was then the one the table last
|
|
24
|
+
received. The editor now tells the preview's tables of every change of its text that is not a write-back (typing, an
|
|
25
|
+
undo or a redo, a text the store hands in), and the tables drop their write-backs not yet drawn.
|
|
26
|
+
|
|
3
27
|
## 0.20.0 (2026-10-26) — ```spreadsheets tables, read-only in documents and editable in the preview
|
|
4
28
|
|
|
5
29
|
### Breaking
|
package/README.md
CHANGED
|
@@ -39,7 +39,7 @@ A single-view (embedding) page never downloads the tree and multi-panel views, w
|
|
|
39
39
|
|
|
40
40
|
- React 19.2.7 or later and React Router 8 in framework mode (route modules with `loader` / `headers`).
|
|
41
41
|
- Node.js 22.22 or later (the floor React Router 8 declares). The package ships ES modules and CommonJS; the CommonJS entries load the ESM-only `react-router` through `require(esm)`.
|
|
42
|
-
- The peer packages, at these versions or later within the caret ranges the package declares: `@aiquants/markdown` ^
|
|
42
|
+
- The peer packages, at these versions or later within the caret ranges the package declares: `@aiquants/markdown` ^10.0.0 (document rendering; its components' stylesheet without utilities, its controls' 44 px targets under every pointer, ```spreadsheets tables — inside list items and quotes too — and their write-back through an editor that tells them of its other changes, so an undo before an edit is drawn shows the undone value, the React-free `@aiquants/markdown/code-blocks` that names the `data-code-meta` the sanitizer keeps on `code`,
|
|
43
43
|
its Mermaid labels and drawings that finish inside the document when a diagram's text changes or it unmounts mid-drawing, its math diagnostics, gantt sizing, embeds, link cards and their sizes, the React-free `@aiquants/markdown/embeds` the sanitizer worker loads and `@aiquants/markdown/source-lines` the editor and the sanitizer read, and the Node-only link-card handler of `@aiquants/markdown/server`, which needs Node.js 22.13 or later — below the explorer's own floor),
|
|
44
44
|
`@aiquants/directory-tree` ^5.0.1 (rows that take paint and text styles only and have no vertical padding, a `removeRootIndent` shift that keeps the root's icon whole, and reveals of rows under the scroll bar's buttons),
|
|
45
45
|
`@aiquants/drag-drop-panels` ^0.12.0 (the panel headers' move menu, named by the explorer's `panelMove`, their 44 px buttons under every pointer and the header arrangement the behavior docs follow), `@aiquants/resize-panels` ^2.2.0 (the source of each layout change, by which the tree pane's width is saved), `@aiquants/spreadsheet` ^0.15.0 (the grid of those tables, which markdown loads only for a document that holds one) and `@aiquants/virtualscroll` ^3.22.1 (44 px scroll-to-edge pills and tap-scroll circles, the pills' text at the body step).
|
|
@@ -727,8 +727,9 @@ A save writes the draft back with the line endings of the file it opened (`\r\n`
|
|
|
727
727
|
A save that meets changes saved elsewhere merges them line by line: changes on different lines are saved at once; lines both sides changed differently are written between git-style markers with buttons above each conflict (keep my lines, the saved lines, or both), and Next conflict moves the focus to those buttons. A draft with markers left is not saved.
|
|
728
728
|
The preview renders the draft as the document would be: on every keystroke with a `draftConverter`, else once the reader pauses typing (SERVER_PREVIEW_DELAY_MS, 610 ms).
|
|
729
729
|
The view switch shows the editor alone, the two side by side (the preview below the editor on a narrow pane), or the preview alone; Ctrl+E (⌘E on a Mac) switches between the editor and the preview from the editor, the preview or the switch and moves the focus there, and a double-click on a word of the preview shown alone opens the editor at that word.
|
|
730
|
-
```spreadsheets tables (see `@aiquants/markdown`'s README, "Spreadsheets") are read-only in the rendered document and editable in the preview: every table with source lines
|
|
731
|
-
|
|
730
|
+
```spreadsheets tables (see `@aiquants/markdown`'s README, "Spreadsheets") are read-only in the rendered document and editable in the preview: every table with source lines writes each transaction (a committed cell, a paste, a delete, a fill) back into the editor's text as its block's new body, one undo step of its own, which the editor refuses — and the table says so — when the block no longer reads what the table knows.
|
|
731
|
+
The editor finds the block in its Markdown parse (to the closing fence, or to the end of the list item, the quote or the text), so a table inside a list item or a quote, or behind an indented fence, writes back too: each line keeps the head the block's lines carry (the item's indentation, `>`, the fence's indentation), and a block whose lines do not all carry it is refused like an edited one.
|
|
732
|
+
Ctrl+Z and Ctrl+Y in a table undo and redo the editor's history, and Save saves the tables' edits with the rest of the draft. A write-back, an undo or a redo from a table leaves the scroll sync's lead with the preview. Any other change of the editor's text — an undo in the editor right after a table's edit included — makes the tables drop their write-backs not yet drawn and show the preview's body again.
|
|
732
733
|
A double-click in an editable table edits a cell instead of opening the editor (a read-only table of the rendered document opens it there, like any other block), and a table shown full screen keeps its keys: Ctrl+E does not switch the panes behind it, and Escape leaves full screen.
|
|
733
734
|
Side by side, a handle on the gutter between the two resizes them, as the explorer's handle resizes the explorer: drag it, or focus it and press the arrow keys (10 px, 50 px with Shift); either side keeps at least 1/φ³ (≈ 23.6 %) of the surface, and the reader's share (an even split by default) is kept in browser storage under `storageNamespace`, for beside and below alike.
|
|
734
735
|
Switching is instant: the hidden pane stays rendered and in step, so the block at the top of the view stays the same; a panel that is not maximized shows one pane at a time and puts the next one at the same place on screen. Where the bar is narrower than two reading columns (a phone), the switch shows its icons alone, keeping its 44 px targets.
|
|
@@ -873,7 +874,7 @@ Tests and host styling may rely on the `data-testid` and `data-aqmx-*` attribute
|
|
|
873
874
|
- A held Enter acts once on every control inside the explorer, those of other packages included (the tree's rows, the panel headers' buttons, the document viewer's toolbar and the controls inside a document), except Zoom in and Zoom out, which keep stepping while a press that began on them is held (see [Held keys](docs/behavior/layout.md#held-keys)): a press that hands the focus to them, such as following a link to an image, does not step them.
|
|
874
875
|
The repeated keydowns end at the explorer's root, so a keydown listener the host attaches outside the explorer for the bubbling phase does not receive them either.
|
|
875
876
|
- A loop row (a folder met again among its own ancestors) shows an expand glyph and `aria-expanded="false"` like any closed folder, because `@aiquants/directory-tree` has no row that cannot expand; it never opens. The 4 listings in flight are counted per explorer, not across browser tabs.
|
|
876
|
-
- A ```spreadsheets table
|
|
877
|
+
- A ```spreadsheets table writes back only when every line of its block carries the head its opening fence line gives its continuation lines (a list item's indentation, `>` with its space, the fence's own indentation); a block written by hand with lines indented less than its fence, `>` without its space, or a tab in that head refuses every write-back as an edit conflict. Inside a list item, a line of spaces and tabs only reads as an empty line (CommonMark), so a row whose cells are all empty or white space is written as an empty line and keeps no cells.
|
|
877
878
|
- Document kinds are the five above; `createFileSystemSource` previews only files with a known text extension or name as text and offers any other file as a `file` document (a download).
|
|
878
879
|
- HTML larger than `sanitizer.maxHtmlBytes` (4 MiB), placed deeper than 512 levels while it is parsed, making the parser create more elements than it has characters, more nodes than the worker's heap holds (81,920 elements, attributes and comments by default) or more than 4,096 comments, holding a tag with more than 1,024 attributes (counted before parsing for every `<` or `</` followed by a letter, so text in a script, a comment or an attribute value that looks like such a tag counts too), giving `html` or `body` more than 1,024 attributes through repeated tags,
|
|
879
880
|
carrying attributes whose characters, counting every copy of a reopened formatting element, exceed `maxHtmlBytes`, sanitizing to HTML longer than four characters per byte of `maxHtmlBytes`, or not sanitized within `sanitizer.deadlineMs` (30 s) shows as `too-large`.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const L=require("react/jsx-runtime"),h=require("react"),y=require("./index-bMaSoQTe.cjs"),G=require("@codemirror/commands"),de=require("@codemirror/lang-markdown"),le=require("@codemirror/language"),fe=require("@codemirror/search"),X=require("@codemirror/state"),P=require("@codemirror/view"),N=require("@lezer/highlight"),De=require("@aiquants/markdown"),se=require("@aiquants/markdown/source-lines"),Q=require("./dataRoute-BONacTPi.cjs"),ie=require("./sanitizePolicy-gEXeavb-.cjs"),Ve=require("isomorphic-dompurify"),te=require("@aiquants/resize-panels"),U=require("./location-BVEN_Ihk.cjs"),me=require("./useSplitPersistence-Ba-v64n-.cjs"),Re={history:G.historyField},Be=le.HighlightStyle.define([{tag:[N.tags.heading1,N.tags.heading2,N.tags.heading3,N.tags.heading4,N.tags.heading5,N.tags.heading6,N.tags.heading],color:"var(--aqmx-syntax-heading)",fontWeight:"700"},{tag:N.tags.strong,fontWeight:"700"},{tag:N.tags.emphasis,fontStyle:"italic"},{tag:N.tags.strikethrough,textDecoration:"line-through"},{tag:N.tags.link,color:"var(--aqmx-syntax-link)",textDecoration:"underline"},{tag:N.tags.url,color:"var(--aqmx-syntax-url)"},{tag:N.tags.monospace,color:"var(--aqmx-syntax-code)"},{tag:N.tags.quote,color:"var(--aqmx-syntax-quote)"},{tag:[N.tags.processingInstruction,N.tags.contentSeparator,N.tags.labelName,N.tags.meta],color:"var(--aqmx-syntax-mark)"}]),He=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)"}}),Oe="data-aqmx-conflict-actions",je=P.Decoration.line({attributes:{"data-aqmx-conflict-line":"marker"}}),ze=P.Decoration.line({attributes:{"data-aqmx-conflict-line":"ours"}}),Fe=P.Decoration.line({attributes:{"data-aqmx-conflict-line":"theirs"}});class We 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(Oe,String(this.index));for(const[r,a]of[["ours",this.labels.useOurs],["theirs",this.labels.useTheirs],["both",this.labels.keepBoth]]){const s=document.createElement("button");s.type="button",s.textContent=a,s.setAttribute("data-aqmx-conflict-choice",r),s.addEventListener("mousedown",c=>c.preventDefault()),s.addEventListener("click",()=>{const c=ee(t.state.doc)[this.index];c!==void 0&&(qe(t,c,r),t.focus())}),n.append(s)}return n}ignoreEvent(){return!0}}const ee=e=>y.findConflictsInLines(e.iterLines()),pe=(e,t)=>{const n=new X.RangeSetBuilder;return ee(e).forEach((r,a)=>{const s=e.line(r.start);n.add(s.from,s.from,P.Decoration.widget({widget:new We(a,t),block:!0,side:-1}));for(let c=r.start;c<=r.end;c+=1){const o=e.line(c).from,f=c===r.start||c===r.separator||c===r.end?je:c<r.separator?ze:Fe;n.add(o,o,f)}}),n.finish()},Ue=e=>X.StateField.define({create:t=>pe(t.doc,e),update:(t,n)=>n.docChanged?pe(n.state.doc,e):t,provide:t=>P.EditorView.decorations.from(t)}),qe=(e,t,n)=>{const{doc:r}=e.state,a=(i,x)=>{const l=[];for(let u=i;u<=x;u+=1)l.push(r.line(u).text);return l},s=a(t.start+1,t.separator-1),c=a(t.separator+1,t.end-1),o=n==="ours"?s:n==="theirs"?c:[...s,...c];let f=r.line(t.start).from,d=r.line(t.end).to;o.length===0&&(t.end<r.lines?d+=1:t.start>1&&(f-=1));const m=o.join(`
|
|
2
|
+
`);e.dispatch({changes:{from:f,to:d,insert:m},selection:X.EditorSelection.cursor(f),scrollIntoView:!0,userEvent:"input.resolve"})},he="input.preview",$e=500,Ge=/^([ >+*\-.)\d]*?)(?:`{3}|~{3})/u,Ke=/^(?:[-+*]|\d{1,9}[.)])(?= )/u,Ie=/^[ \t]*$/u,Xe=e=>{let t="",n=0;for(;n<e.length;){const r=e.slice(n);if(r.startsWith(">"))t+="> ",n+=r.startsWith("> ")?2:1;else if(r.startsWith(" "))t+=" ",n+=1;else{const a=Ke.exec(r)?.[0];if(a===void 0)return null;t+=" ".repeat(a.length),n+=a.length}}return t},Ye=(e,t,n)=>{if(e.startsWith(t)){const r=e.slice(t.length);return n&&Ie.test(r)?"":r}return t.startsWith(e)&&e.length>=t.trimEnd().length?"":null},Je=(e,t,n)=>e.split(`
|
|
3
|
+
`).map((r,a,s)=>a===s.length-1&&r===""?"":(n?Ie.test(r):r==="")?t.trimEnd():`${t}${r}`).join(`
|
|
4
|
+
`),Qe=(e,t,n)=>{const{doc:r}=e;if(!Number.isInteger(t)||t<1||t>r.lines)return null;const a=r.line(t),s=Ge.exec(a.text)?.[1],c=s===void 0?null:Xe(s);if(s===void 0||c===null)return null;const o=Math.min(r.lines,t+n.split(`
|
|
5
|
+
`).length+1),f=le.ensureSyntaxTree(e,r.line(o).to,$e);if(f===null)return null;const d=f.resolveInner(a.from+s.length,1),m=d.parent;if(d.name!=="CodeMark"||m===null||m.name!=="FencedCode"||m.from!==d.from)return null;const[,...i]=m.getChildren("CodeMark"),x=i.at(-1),l=x===void 0?r.lineAt(m.to).number:r.lineAt(x.from).number-1;let u=m.parent;for(;u!==null&&u.name!=="ListItem"&&u.name!=="Blockquote";)u=u.parent;const g=u?.name==="ListItem";let w="";for(let b=t+1;b<=l;b+=1){const A=Ye(r.line(b).text,c,g);if(A===null)return null;w+=b<r.lines?`${A}
|
|
6
|
+
`:A}if(w!==n)return null;if(l>t){const b=l<r.lines?r.line(l+1).from:r.length;return{from:r.line(t+1).from,to:b,prefix:c,whiteSpaceLinesEmpty:g,lineBreak:!1}}if(t===r.lines)return{from:r.length,to:r.length,prefix:c,whiteSpaceLinesEmpty:g,lineBreak:!0};const p=r.line(t+1).from;return{from:p,to:p,prefix:c,whiteSpaceLinesEmpty:g,lineBreak:!1}},Ze=({parent:e,scroll:t,text:n,saved:r,labels:a,onChange:s,onGeometry:c,onSave:o})=>{let f=!1;const d=[P.EditorView.scrollHandler.of((l,u,g)=>(et(l,u.head,g,t),!0)),P.lineNumbers(),P.highlightActiveLineGutter(),G.history(),P.drawSelection(),P.highlightActiveLine(),fe.highlightSelectionMatches(),P.EditorView.lineWrapping,de.markdown({base:de.markdownLanguage}),le.syntaxHighlighting(Be),Ue(a),P.keymap.of([{key:"Mod-s",preventDefault:!0,run:()=>(o(),!0)},...fe.searchKeymap,...G.historyKeymap,...G.defaultKeymap]),P.EditorView.contentAttributes.of({"aria-label":a.editor,"aria-multiline":"true"}),P.EditorView.updateListener.of(l=>{l.docChanged&&s(l.transactions.every(u=>!u.docChanged||u.isUserEvent(he))),(l.docChanged||l.heightChanged||l.geometryChanged)&&c(l.docChanged&&!f)}),He],m=rt(r,d)??X.EditorState.create({doc:n,extensions:d}),i=new P.EditorView({state:m,parent:e}),x=l=>{f=!0;try{l()}finally{f=!1}};return{text:()=>i.state.doc.toString(),replaceText:l=>{const u=i.state.doc.toString();if(u===l)return;let g=0;const w=Math.min(u.length,l.length);for(;g<w&&u.charCodeAt(g)===l.charCodeAt(g);)g+=1;let p=0;for(;p<w-g&&u.charCodeAt(u.length-1-p)===l.charCodeAt(l.length-1-p);)p+=1;i.dispatch({changes:{from:g,to:u.length-p,insert:l.slice(g,l.length-p)},userEvent:"input.replace"})},replaceBody:(l,u,g)=>{const w=Qe(i.state,l,u);if(w===null)return!1;const p=Je(g,w.prefix,w.whiteSpaceLinesEmpty),b=w.lineBreak?`
|
|
7
|
+
${p}`:p;return x(()=>i.dispatch({changes:{from:w.from,to:w.to,insert:b},userEvent:he,annotations:G.isolateHistory.of("full")})),!0},undo:()=>x(()=>G.undo(i)),redo:()=>x(()=>G.redo(i)),reveal:({line:l,column:u},g)=>{const{doc:w}=i.state,p=w.line(Math.min(Math.max(l,1),w.lines)),b=Math.min(p.from+u,p.to);i.dispatch({selection:X.EditorSelection.cursor(b),effects:ge(i,b,g,t)})},showLine:l=>{const{doc:u}=i.state,g=u.line(Math.min(Math.max(l,1),u.lines)).from;i.dispatch({effects:ge(i,g,null,t)})},topLine:()=>{const l=t.scrollerOf(i.scrollDOM),u=y.visibleTopOf(l,i.contentDOM),g=y.frameTopOf(l)+l.clientHeight,{documentTop:w}=i,{doc:p}=i.state;let b=i.lineBlockAtHeight(Math.max(u-w,0));for(;p.lineAt(b.from).text.trim()===""&&b.to<p.length;){const D=i.lineBlockAt(b.to+1);if(w+D.top>=g)break;b=D}const A=i.coordsAtPos(b.from),C=A===null?w+b.top:A.top;return{line:i.state.doc.lineAt(b.from).number,clientTop:C,offset:C-u}},lineSpans:l=>{const u=i.scrollDOM,g=u.scrollTop+i.documentTop-y.visibleTopOf(u,i.contentDOM),{doc:w}=i.state,p=b=>w.line(Math.min(Math.max(b,1),w.lines)).from;return l.map(({first:b,last:A})=>({top:g+i.lineBlockAt(p(b)).top,bottom:g+i.lineBlockAt(p(A)).bottom}))},scrollElement:i.scrollDOM,focus:()=>i.focus(),conflicts:()=>ee(i.state.doc),resolveAtCursor:l=>{const u=ee(i.state.doc),g=i.state.doc.lineAt(i.state.selection.main.head).number,w=u.find(p=>p.end>=g);return w===void 0?!1:(qe(i,w,l),!0)},nextConflict:()=>{const l=ee(i.state.doc);if(l[0]===void 0)return!1;const g=i.state.doc.lineAt(i.state.selection.main.head).number,w=l.findIndex(C=>C.start>g),p=w<0?0:w,b=i.state.doc.line(l[p].start).from;i.dispatch({selection:X.EditorSelection.cursor(b),effects:P.EditorView.scrollIntoView(b,{y:"center"})});const A=i.contentDOM.querySelector(`[${Oe}="${String(p)}"] button`);return A instanceof HTMLElement?A.focus({preventScroll:!0}):i.focus(),!0},save:()=>i.state.toJSON(Re),destroy:()=>i.destroy()}},ge=(e,t,n,r)=>{const a=r.scrollerOf(e.scrollDOM),s=(n===null?y.visibleTopOf(a,e.contentDOM):n)-y.frameTopOf(a);return P.EditorView.scrollIntoView(t,{y:"start",yMargin:s})},et=(e,t,n,r)=>{const a=tt(e,t),s=r.scrollerOf(e.scrollDOM),c=y.frameTopOf(s),o=y.visibleTopOf(s,e.contentDOM),f=c+s.clientHeight;let d=0;switch(n.y){case"start":d=a.top-(c+n.yMargin);break;case"center":d=(a.top+a.bottom)/2-(o+f)/2;break;case"end":d=a.bottom-(f-n.yMargin);break;default:a.top<o+n.yMargin?d=a.top-(o+n.yMargin):a.bottom>f-n.yMargin&&(d=Math.min(a.bottom-(f-n.yMargin),a.top-(o+n.yMargin)))}if(d!==0&&(s.scrollTop+=d),n.y==="start")return;const m=nt(e,t);m!==null&&r.reveal(m)},tt=(e,t)=>{const{node:n,offset:r}=e.domAtPos(t);if(n.nodeType===Node.TEXT_NODE){const c=n.ownerDocument?.createRange();if(c!==void 0){c.setStart(n,r),c.setEnd(n,r);const[o]=c.getClientRects();if(o!==void 0&&o.height>0)return{top:o.top,bottom:o.bottom}}}const a=e.lineBlockAt(t),s=e.documentTop+a.top;return{top:s,bottom:s+a.height}},nt=(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},rt=(e,t)=>{if(e==null)return null;try{return X.EditorState.fromJSON(e,{extensions:t},Re)}catch{return null}},ot=610,st=987,ve=Object.freeze({kind:"unavailable"}),it="true",lt="false",at=e=>e===it?!0:e===lt?!1:null,ct=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 a=r.localName==="img",s=r.getAttribute(a?"data-asset-src":"data-doc-path");s!==null&&n.push({target:{kind:a?"asset":"doc",path:s},exists:at(r.getAttribute(a?"data-asset-exists":"data-doc-exists"))})}return n},ut=({path:e,instant:t,preview:n,initial:r,onView:a})=>{const s=new AbortController,c={asset:new Map,doc:new Map};let o=r,f=null,d=!1,m=!1,i=null,x=null,l=[],u,g=!1,w,p=null;const b=T=>{T.parsed===o.parsed&&T.failure===o.failure&&T.busy===o.busy&&T.tier===o.tier||(o=T,a(T))},A=(T,k)=>{d||(d=!0,console.error(`[markdown-explorer] ${T}`,...k===void 0?[]:[k]))},C=T=>{if(t!==null)for(const{target:k,exists:O}of t.marksOf(T))c[k.kind].set(k.path,O)},D=()=>{clearTimeout(w),w=void 0,p?.abort(),p=null},j=()=>{x=null,l=[],clearTimeout(u),u=void 0},B=(T,k)=>{b({parsed:o.parsed,failure:T,busy:!1,tier:k})},W=()=>{clearTimeout(u),u=l.length===0?void 0:setTimeout(R,st)},S=()=>{if(t===null||x===null)return;const T=x,k=[],O={asset:new Set,doc:new Set};let E;try{E=t.sanitize(T.html,q=>{const H=c[q.kind].get(q.path);return H===void 0&&!O[q.kind].has(q.path)&&(O[q.kind].add(q.path),k.push(q)),H??void 0})}catch(q){j(),q instanceof ie.HtmlNestingLimitError?B(Q.failureOf("too-large"),"instant"):(A("the draft sanitizer failed",q),B(Q.failureOf("failed"),"instant"));return}l=k;const I=o.parsed!==null&&o.parsed.htmlContent===E&&o.parsed.headings===T.headings?o.parsed:{htmlContent:E,headings:T.headings};b({parsed:I,failure:null,busy:!1,tier:"instant"}),W()},R=()=>{if(u=void 0,g||x===null||l.length===0)return;g=!0;const T=l;n(e,x.text,s.signal).then(k=>{if(g=!1,!(s.signal.aborted||!("kind"in k))){k.kind==="preview"&&C(k.htmlContent);for(const O of T)c[O.kind].has(O.path)||c[O.kind].set(O.path,null);S()}})},M=T=>{D(),j(),b({...o,busy:!0,tier:"server"});const k=new AbortController;p=k,w=setTimeout(()=>{w=void 0,n(e,T,k.signal).then(O=>{if(!(k.signal.aborted||!("kind"in O))){if(p=null,O.kind==="failure"){B(O.failure,"server");return}C(O.htmlContent),b({parsed:{htmlContent:O.htmlContent,headings:O.headings},failure:null,busy:!1,tier:"server"})}})},ot)},v=async(T,k)=>{let O;try{O=await T.convert({path:e,text:k},s.signal)}catch(I){return s.signal.aborted||A("the draft converter rejected a conversion, which its contract allows only once the signal aborted",I),ve}const E=Q.draftAnswerViolation(O);return E===null?O:(A(`the draft converter answered outside its contract: ${E}`),ve)},V=(T,k)=>{switch(k.kind){case"preview":if(D(),k.headings.length>Q.EXPLORER_MAX_HEADINGS){j(),B(Q.failureOf("too-large"),"instant");return}x={text:T,html:k.htmlContent,headings:k.headings.map(({text:O,depth:E,id:I})=>({text:O,depth:E,id:I}))},S();return;case"failure":D(),j(),B(Q.failureOf(k.failure.reason,k.failure.code),"instant");return;case"unavailable":M(T);return}},z=async T=>{m=!0;try{for(;i!==null&&!s.signal.aborted;){const k=i;i=null;const O=await v(T,k);if(s.signal.aborted)return;V(k,O)}}finally{m=!1}};return t!==null&&t.seed!==null&&C(t.seed),{update:T=>{if(!(s.signal.aborted||T===f)){if(f=T,clearTimeout(u),u=void 0,t===null){M(T);return}i=T,m||z(t.converter)}},dispose:()=>{s.abort(),i=null,clearTimeout(u),u=void 0,D()}}},dt=(e,t)=>ie.createHtmlSanitizer(Ve(window),e,t,ie.MAX_HTML_NESTING_DEPTH),ft=(e,t)=>e.flatMap((n,r)=>{const a=t[r];return a===void 0?[]:[{editor:a.top,preview:n.top},{editor:a.bottom,preview:n.bottom}]}),K=(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},mt=e=>{const t=[];for(const r of e){let a=0,s=t.length;for(;a<s;){const c=a+s>>1;K(t,c).pair.preview<=r.preview?a=c+1:s=c}t[a]={pair:r,before:a===0?void 0:K(t,a-1)}}const n=[];for(let r=t.at(-1);r!==void 0;r=r.before)n.push(r.pair);return n.reverse()},pt=(e,t)=>{const n=Math.max(t.editorMax,0),r=Math.max(t.previewMax,0),a=n-t.editorViewport,s=r-t.previewViewport,c=e.filter(d=>d.editor>0&&d.editor<a&&d.preview>0&&d.preview<s).sort((d,m)=>d.editor-m.editor||d.preview-m.preview);let o={editor:0,preview:0};const f=[o];for(const d of mt(c))d.editor>o.editor&&d.preview>o.preview&&(f.push(d),o=d);return f.push({editor:n,preview:r}),{toPreview:d=>Ee(f,"editor","preview",d),toEditor:d=>Ee(f,"preview","editor",d)}},Ee=(e,t,n,r)=>{const a=K(e,0),s=K(e,e.length-1);if(Number.isNaN(r)||r<=a[t])return a[n];if(r>=s[t])return s[n];let c=0,o=e.length-1;for(;o-c>1;){const m=c+o>>1;K(e,m)[t]<=r?c=m:o=m}const f=K(e,c),d=K(e,o);return f[n]+(d[n]-f[n])*(r-f[t])/(d[t]-f[t])},ht=610,we=89,be=.5,gt=({editor:e,preview:t,previewBlocks:n,editorSpans:r,requestFrame:a,cancelFrame:s,now:c})=>{let o="editor",f=0,d=null,m=null,i=!1,x=null,l=null;const u={editor:0,preview:0},g={editor:null,preview:null};let w=null,p=()=>{};const b=v=>{d!==null&&v!==d||(o=v,f=c()+ht)},A=(v,V)=>{v!==o&&d===null&&c()>=f&&!C(v,V)&&(o=v),S()},C=(v,V)=>{const z=g[v];return c()<u[v]||z!==null&&Math.abs(V.position()-z)<be},D=e.onScroll(()=>A("editor",e)),j=e.onIntent(()=>b("editor")),B=()=>{const v=t();return v!==w&&(p(),w=v,p=v===null?()=>{}:W(v)),v},W=v=>{const V=v.onScroll(()=>A("preview",v)),z=v.onIntent(()=>b("preview"));return()=>{V(),z()}},S=()=>{!i&&m===null&&(m=a(R))},R=()=>{m=null;const v=B();v!==null&&(x??=n(),l??=pt(ft(x,r(x)),{editorMax:e.max(),previewMax:v.max(),editorViewport:e.viewport(),previewViewport:v.viewport()}),o==="editor"?M(v,"preview",l.toPreview(e.position())):M(e,"editor",l.toEditor(v.position())))},M=(v,V,z)=>{if(Math.abs(v.position()-z)<be){g[V]=v.position();return}u[V]=c()+we,g[V]=v.scrollTo(z)};return S(),{editorChanged:v=>{l=null,v&&b("editor"),S()},previewChanged:()=>{x=null,l=null,u.preview=c()+we,S()},showAlone:v=>{d=v,!(v===null||v===o)&&(o=v,f=0,S())},dispose:()=>{i=!0,m!==null&&s(m),m=null,D(),j(),p()}}},Se=Object.freeze(["wheel","pointerdown","keydown","focusin"]),Ae=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 Se)e.addEventListener(n,t,{capture:!0,passive:!0});return()=>{for(const n of Se)e.removeEventListener(n,t,{capture:!0})}}}),Z="[data-aqmd-scroll-container]",vt="[data-aqmd-content]",Et=`[${se.SOURCE_LINES_ATTRIBUTE}]`,wt=Object.freeze(["p1","p2","p3","p4","p5","p6","p7","p8"]),Me=(e,t)=>{const n=y.loadedOf(e.peek(t));return n!==null&&n.document.kind==="markdown"?{htmlContent:n.document.htmlContent,headings:n.document.headings}:null},bt=(e,t,n,r,a)=>{if(n===void 0)return null;let s;try{s=dt(e,t)}catch(c){return console.error("[markdown-explorer] the draft sanitizer cannot run in this browser, so the server renders the preview",c),null}return{converter:n,sanitize:s,marksOf:ct,seed:Me(r,a)?.htmlContent??null}},St=e=>{const t=[];let n=null;for(const r of e.querySelectorAll(Et)){const a=se.parseSourceLines(r.getAttribute(se.SOURCE_LINES_ATTRIBUTE));if(a===null||r.getClientRects().length===0)continue;n??=e.scrollTop-y.visibleTopOf(e,r);const{top:s,bottom:c}=r.getBoundingClientRect();t.push({first:a.first,last:a.last,top:n+s,bottom:n+c})}return t},xt=({path:e,readDraft:t,viewer:n,spreadsheetEditor:r,concealed:a,onEditAt:s,onLayout:c,handleRef:o})=>{const{config:f,data:d,documents:m,draftConverter:i,labels:x}=y.useExplorer(),[l,u]=h.useState(()=>({parsed:Me(m,e),failure:null,busy:!0,tier:i===void 0?"server":"instant"})),g=h.useRef(null),w=h.useRef(null),p=h.useRef(l);h.useLayoutEffect(()=>{p.current=l});const b=h.useEffectEvent(()=>t());h.useEffect(()=>{const S=bt(f.iframeHosts,f.dataPath,i,m,e),R=ut({path:e,instant:S,preview:d.preview,initial:p.current,onView:M=>h.startTransition(()=>u(M))});return w.current=R,R.update(b()),()=>{R.dispose(),w.current=null}},[f,d,m,i,e]);const A=h.useEffectEvent(()=>c());h.useLayoutEffect(()=>{l.parsed!==null&&A()},[l.parsed]);const C=l.parsed!==null;h.useLayoutEffect(()=>{const S=C?g.current?.querySelector(Z):null;if(!(S instanceof HTMLElement))return;S.tabIndex=0;const R=new ResizeObserver(()=>A());R.observe(S);const M=S.querySelector(vt);return M!==null&&R.observe(M),()=>R.disconnect()},[C]);const D=h.useRef(null);h.useImperativeHandle(o,()=>({draft:S=>{w.current?.update(S)},scrollPort:()=>{const S=g.current?.querySelector(Z);return S instanceof HTMLElement?(D.current?.scroller!==S&&(D.current={scroller:S,port:Ae(S)}),D.current.port):null},blocks:()=>{const S=g.current?.querySelector(Z);return S instanceof HTMLElement?St(S):[]},focus:()=>{const S=g.current?.querySelector(Z);S instanceof HTMLElement&&S.focus({preventScroll:!0})},anchor:S=>{const R=g.current,M=R?.querySelector(Z);return R===null||!(M instanceof HTMLElement)?null:y.anchorOfView(R,S(M))},place:({line:S,clientTop:R},M)=>{const v=g.current,V=v===null?null:y.blockAtLine(v,S);V!==null&&(M(V).scrollTop+=y.lineTopIn(V,S)-R)}}),[]);const j=S=>{const R=g.current,{target:M}=S;if(s===void 0||R===null||!(M instanceof Element)||!y.isEditingDoubleClick(M))return;const v=y.anchorOfDoubleClick(M,R,R.ownerDocument.getSelection());v!==null&&s(v)},B=h.useMemo(()=>({...n,showToc:!1,showStyle:!1,showAlign:!1,renderScrollBar:void 0,spreadsheetEditor:r}),[n,r]),W=h.useMemo(()=>l.parsed===null?null:L.jsx("div",{className:"aqmx-document-viewer",children:L.jsx(De.MarkdownViewer,{...B,parseResult:l.parsed,content:null})}),[B,l.parsed]);return L.jsxs("section",{ref:g,className:"aqmx-edit-preview","aria-label":x.previewRegion,"aria-busy":l.busy,inert:a!==null,hidden:a==="removed","data-aqmx-preview-tier":l.tier,"data-testid":"markdown-explorer-edit-preview",onDoubleClick:s===void 0?void 0:j,children:[l.failure===null?null:L.jsx("p",{className:"aqmx-callout aqmx-document-notice","data-aqmx-tone":"warning","data-testid":"markdown-explorer-edit-preview-failure",children:x.previewFailed(y.failureTitleOf(x,l.failure.reason))}),W??(l.failure===null?L.jsx("div",{className:"aqmx-skeleton","aria-hidden":"true","data-testid":"markdown-explorer-edit-preview-skeleton",children:wt.map(S=>L.jsx("span",{},S))}):null),l.busy?L.jsx("p",{className:"aqmx-sr-only",children:x.previewUpdating}):null]})},xe="data-aqmx-edit-split",oe="--aqmx-edit-share",ye="--aqmx-edit-gutter",yt="data-aqmx-edit-split-probe",Tt="aqmx-edit-split",kt="aqmx-edit-editor",Lt="aqmx-edit-preview",Te={value:U.EDIT_SPLIT_MIN_PERCENT,unit:"percentage"},ke={value:U.EDIT_SPLIT_MAX_PERCENT,unit:"percentage"},Le=e=>{if(e.length!==2)return null;const[t=0,n=0]=e,r=t+n;return r>0?t/r*100:null},ne=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},Rt=(e,t,n)=>{const[r,a]=h.useState(null);return h.useLayoutEffect(()=>{const s=e.current,c=t.current;if(s===null||c===null)throw new Error("[markdown-explorer] the edit split is not mounted");const o={frame:s.getBoundingClientRect().width,measure:c.getBoundingClientRect().width},f=()=>{o.frame>0&&o.measure>0&&a(U.editSplitOrientation(o.frame,o.measure,n))};f();const d=new ResizeObserver(m=>{for(const i of m){const[x]=i.borderBoxSize;x!==void 0&&(i.target===s&&(o.frame=x.inlineSize),i.target===c&&(o.measure=x.inlineSize))}f()});return d.observe(s),d.observe(c),()=>d.disconnect()},[e,t,n]),r},Ot=({editorId:e})=>{const{edits:t,labels:n}=y.useExplorer(),r=h.useRef(null),a=h.useRef(null),s=me.useCoarsePointer()?U.COARSE_TARGET_PIXELS:U.FINE_TARGET_PIXELS,c=Rt(r,a,s),[o]=h.useState(()=>t.editorShare());h.useLayoutEffect(()=>{const m=ne(r);return m.style.setProperty(ye,`${String(s)}px`),()=>{m.style.removeProperty(ye)}},[s]),h.useLayoutEffect(()=>{const m=ne(r);return m.style.setProperty(oe,`${String(o)}%`),()=>{m.style.removeProperty(oe)}},[o]),h.useLayoutEffect(()=>{if(c===null)return;const m=ne(r);return m.setAttribute(xe,c),()=>m.removeAttribute(xe)},[c]);const f=me.useSplitPersistence(h.useCallback(m=>{const i=Le(m);i!==null&&t.setEditorShare(i)},[t])),d=h.useCallback((m,i)=>{const x=Le(m);x!==null&&ne(r).style.setProperty(oe,`${String(x)}%`),f.layoutChanged(m,i)},[f]);return L.jsxs("div",{ref:r,className:"aqmx-edit-split","data-testid":"markdown-explorer-edit-split",children:[L.jsx("span",{ref:a,className:"aqmx-edit-split-probe","aria-hidden":"true",[yt]:""}),c===null?null:L.jsxs(te.PanelGroup,{id:Tt,direction:c==="beside"?"horizontal":"vertical",onLayout:d,className:"aqmx-edit-split-group",children:[L.jsx(te.Panel,{id:kt,defaultSize:{value:o,unit:"percentage"},minSize:Te,maxSize:ke,contentOverflow:"hidden"}),L.jsx(te.PanelResizeHandle,{thickness:s,indicator:{visible:!0,thickness:U.SPLIT_HANDLE_PIXELS.gripThickness,length:U.SPLIT_HANDLE_PIXELS.gripLength,barThickness:U.SPLIT_HANDLE_PIXELS.barThickness,barLength:U.SPLIT_HANDLE_PIXELS.barLength},title:n.editViewSplitResize,"aria-label":n.editViewSplitResize,"aria-controls":e,onDragging:f.draggingChanged,className:"aqmx-split-handle aqmx-edit-split-handle"}),L.jsx(te.Panel,{id:Lt,defaultSize:{value:100-o,unit:"percentage"},minSize:Te,maxSize:ke,contentOverflow:"hidden"})]})]})},Ce=144,qt="[data-aqmd-spreadsheet-fullscreen]",It=Object.freeze(["e1","e2","e3","e4","e5","e6","e7","e8"]),At=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"},Mt=e=>{e.stopPropagation()},Ct=e=>{const{path:t,name:n,session:r}=e,{edits:a,labels:s,announcer:c}=y.useExplorer(),{phase:o}=r,f=h.useCallback(()=>a.retry(t),[a,t]);switch(h.useEffect(()=>{o.kind==="failed"&&c.announce(s.documentFailed(n,y.failureTitleOf(s,o.failure.reason)))},[o,c,s,n]),o.kind){case"opening":return L.jsxs(L.Fragment,{children:[L.jsx("div",{className:"aqmx-skeleton","aria-hidden":"true","data-testid":"markdown-explorer-edit-skeleton",children:It.map(d=>L.jsx("span",{},d))}),L.jsx("p",{className:"aqmx-sr-only",children:s.editLoading})]});case"grant":return L.jsx("div",{className:"aqmx-edit-message",children:L.jsx(y.EditGrantNotice,{href:o.href,onRetry:f,testId:"markdown-explorer-edit-grant"})});case"failed":return L.jsx("div",{className:"aqmx-edit-message",children:L.jsx(y.FailureView,{failure:o.failure,alert:!1,onRetry:f,testId:"markdown-explorer-edit-failure"})});case"editing":return L.jsx(_t,{...e})}},_t=({path:e,name:t,session:n,layout:r,viewer:a,region:s,paneScroll:c})=>{const{edits:o,labels:f}=y.useExplorer(),d=h.useRef(null),m=h.useId(),i=h.useRef(null),[x]=h.useState(()=>new Set),l=h.useRef(null),u=h.useRef(null),g=r==="fill",w=y.useSideBySide(),p=y.editViewOf(n,w,g),b=p!=="editor"||n.previewPrepared,A=b&&g,C=h.useRef({layout:r,region:s,paneScroll:c});h.useLayoutEffect(()=>{C.current={layout:r,region:s,paneScroll:c}});const D=h.useRef(n.generation);h.useLayoutEffect(()=>{D.current=n.generation});const j=h.useRef({view:p,previewMounted:b});h.useLayoutEffect(()=>{j.current={view:p,previewMounted:b}});const B=h.useRef(null),W=h.useRef(null),S=h.useRef(!1),R=h.useMemo(()=>({editor:f.editorLabel(t),useOurs:f.conflictUseOurs,useTheirs:f.conflictUseTheirs,keepBoth:f.conflictKeepBoth}),[f,t]),M=h.useCallback(E=>{const{region:I,paneScroll:q}=C.current,H=I();return H===null?E:q.scrollerOf(H,E)},[]);h.useLayoutEffect(()=>{const E=d.current,I=o.draft(e);if(E===null||I===null)return;const q=o.editorState.get(e),H=At(q)&&q.generation===D.current?q:null;let $=null,Y=null;const re=()=>{$!==null&&clearTimeout($),$=null,Y!==null&&o.setDraft(e,Y.text())},F=Ze({parent:E,scroll:{scrollerOf:_=>{const{layout:J,region:Pe,paneScroll:Ne}=C.current,ue=Pe();return J==="fill"||ue===null?_:Ne.scrollerOf(ue,_)},reveal:_=>C.current.paneScroll.reveal(_)},text:I,saved:H===null?void 0:H.state,labels:R,onGeometry:_=>u.current?.editorChanged(_),onChange:_=>{if($??=setTimeout(re,Ce),!_)for(const J of[...x])J();j.current.previewMounted&&Y!==null&&l.current?.draft(Y.text())},onSave:()=>{o.save(e)}});Y=F,i.current=F;const ae=()=>{const _=F.topLine();return{line:_.line,clientTop:_.clientTop}},ce=()=>l.current?.anchor(M)??null,_e=o.bindEditor(e,{flush:re,adopt:_=>F.replaceText(_),returnPoint:()=>{const _=j.current.view==="preview"&&C.current.layout==="content"?ce():null;return _===null?ae():{line:_.lines.first,clientTop:_.clientTop}},nextConflict:()=>j.current.view!=="preview"?F.nextConflict():F.conflicts().length===0?!1:(S.current=!0,o.setView(e,"editor"),!0),beforeView:_=>{if(C.current.layout==="fill")return;if(_==="preview"){B.current={to:"preview",point:ae()};return}const J=ce();B.current=J===null?null:{to:"editor",anchor:J}}});return H!==null&&F.showLine(H.topLine),()=>{re(),o.editorState.set(e,{state:F.save(),generation:D.current,topLine:F.topLine().line}),_e(),F.destroy(),Y=null,i.current=null}},[o,e,R,M,x]);const{request:v}=n;h.useLayoutEffect(()=>{const E=i.current,I=o.draft(e);E===null||I===null||v===null||(v.anchor!==null&&E.reveal(y.positionInSource(I,v.anchor),v.anchor.clientTop),E.focus(),o.consumeRequest(e))},[o,e,v,R]),h.useLayoutEffect(()=>{p!=="editor"&&!n.previewPrepared&&o.preparePreview(e)},[o,e,p,n.previewPrepared]),h.useLayoutEffect(()=>{const E=B.current,I=W.current,q=S.current;B.current=null,W.current=null,S.current=!1;const H=i.current;if(E?.to==="preview")l.current?.place(E.point,M);else if(E?.to==="editor"&&H!==null){const $=o.draft(e);$!==null&&H.reveal(y.positionInSource($,E.anchor),E.anchor.clientTop)}q?H?.nextConflict():I==="editor"?H?.focus():I==="preview"&&l.current?.focus()},[o,e,p,M]);const V=h.useMemo(()=>({write:({fenceLine:E,expected:I,text:q})=>i.current?.replaceBody(E,I,q)===!0,undo:()=>i.current?.undo(),redo:()=>i.current?.redo(),subscribe:E=>(x.add(E),()=>{x.delete(E)})}),[x]),z=h.useCallback(()=>{const E=i.current;if(E===null)throw new Error("[markdown-explorer] the preview read the draft before the editor was mounted");return E.text()},[]);h.useLayoutEffect(()=>{const E=i.current;if(!A||E===null)return;const I=gt({editor:Ae(E.scrollElement),preview:()=>l.current?.scrollPort()??null,previewBlocks:()=>l.current?.blocks()??[],editorSpans:q=>E.lineSpans(q),requestFrame:q=>requestAnimationFrame(q),cancelFrame:q=>cancelAnimationFrame(q),now:()=>performance.now()});return I.showAlone(y.paneShownAlone(j.current.view)),u.current=I,()=>{I.dispose(),u.current=null}},[A,o,e,R]),h.useLayoutEffect(()=>{u.current?.showAlone(y.paneShownAlone(p))},[p]);const T=h.useCallback(()=>u.current?.previewChanged(),[]),k=h.useCallback(E=>o.start(e,E),[o,e]),O=E=>{if(E.target instanceof Element&&E.target.closest(qt)!==null)return;if(E.key==="Escape"){y.consumeKey(E);return}if(!y.isEditViewShortcut(E.nativeEvent,y.isApplePlatform(navigator.platform)))return;y.consumeKey(E);const I=y.toggledEditView(p);W.current=I,y.chooseEditView(o,e,I,g)};return L.jsxs("div",{className:"aqmx-edit","data-aqmx-edit-layout":r,"data-aqmx-edit-view":p,"data-testid":"markdown-explorer-edit",onKeyDown:O,onDoubleClick:Mt,children:[L.jsx("div",{ref:d,id:m,className:"aqmx-edit-editor","data-testid":"markdown-explorer-editor",inert:p==="preview",hidden:p==="preview"&&!g,...y.ALLOW_KEY_REPEAT}),p==="split"?L.jsx(Ot,{editorId:m}):null,b?L.jsx(xt,{path:e,readDraft:z,viewer:a,spreadsheetEditor:V,concealed:p!=="editor"?null:g?"overlay":"removed",onEditAt:p==="preview"?k:void 0,onLayout:T,handleRef:l}):null]})};exports.DRAFT_WRITE_INTERVAL_MS=Ce;exports.default=Ct;
|