@aiquants/markdown-explorer 0.27.0 → 0.29.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 +34 -0
- package/README.md +12 -5
- package/dist/{EditSurface-B1yD7ywF.cjs → EditSurface-B9IpZlBX.cjs} +2 -2
- package/dist/{EditSurface-sUNqYw9o.js → EditSurface-BrdChI9n.js} +54 -54
- package/dist/{ExplorerSplit-pClUl3-e.js → ExplorerSplit-B-fr2nlU.js} +99 -99
- package/dist/{ExplorerSplit-Bn3ZnEMZ.cjs → ExplorerSplit-B99KbYXc.cjs} +1 -1
- package/dist/MultiLayout-BZ0zTAoi.cjs +1 -0
- package/dist/{MultiLayout-B-ft4_Vs.js → MultiLayout-Pf-6yPif.js} +167 -168
- package/dist/NativeScrollBar-Bj5_LmwY.cjs +1 -0
- package/dist/{NativeScrollBar-ByawerpG.js → NativeScrollBar-ybJw3OHE.js} +6 -7
- package/dist/{TreeLayout-DjIVKBG4.js → TreeLayout-C4l591Nc.js} +9 -9
- package/dist/{TreeLayout-CXHbKdxy.cjs → TreeLayout-CblPMzQi.cjs} +1 -1
- package/dist/index-CnX313Ss.cjs +15 -0
- package/dist/{index-BNAkC0g3.js → index-awodBw8r.js} +1054 -1021
- package/dist/index.cjs +1 -1
- package/dist/index.js +10 -10
- package/dist/{location-BNFdxzhn.js → location-CKuabtKl.js} +83 -82
- package/dist/location-l_HysaZR.cjs +1 -0
- package/dist/{merge-BBU1pDoT.cjs → merge-DffWW96L.cjs} +1 -1
- package/dist/{merge-DhHzRcAI.js → merge-qfptirid.js} +1 -1
- package/dist/server.cjs +1 -1
- package/dist/server.js +2 -2
- package/dist/styles/markdown-explorer.css +1 -1
- package/dist/tapScrollCircle-CDBXEKvI.cjs +1 -0
- package/dist/tapScrollCircle-DYmzWI-8.js +12 -0
- package/dist/{useSplitPersistence-xGOSwpLM.cjs → useSplitPersistence-9Nu6J1WF.cjs} +1 -1
- package/dist/{useSplitPersistence-D5EjJwCg.js → useSplitPersistence-Bf4M35Il.js} +1 -1
- package/docs/behavior/layout.md +6 -2
- package/package.json +5 -5
- package/dist/MultiLayout-0Jh08fxo.cjs +0 -1
- package/dist/NativeScrollBar-D9QrjRJa.cjs +0 -1
- package/dist/index-DRMNpWDJ.cjs +0 -15
- package/dist/location-yvU5HUY1.cjs +0 -1
- package/dist/scrollBarGeometry-C46jBtmM.cjs +0 -1
- package/dist/scrollBarGeometry-DOBdGNV-.js +0 -4
- package/dist/tapScrollCircle-C5DGI-0H.cjs +0 -1
- package/dist/tapScrollCircle-u4EXeLhx.js +0 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,39 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.29.0 (2026-10-28) — The tables' tap-scroll circle in the explorer's blue, and only where a document asks for it
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
|
|
7
|
+
- **A table's tap-scroll circle takes the look and the speeds of the explorer's bars (readers).** A table file's
|
|
8
|
+
preview drew the grid's own grey circle; it now draws the blue sample visual and the speeds every circle of the
|
|
9
|
+
explorer has (a quarter of the base speed at the centre, 18 times at the rim), one control across (44 px), where the
|
|
10
|
+
grid places its circle (`TABLE_TAP_SCROLL_CIRCLE`, passed as `@aiquants/markdown`'s `tapScrollCircle`). The look loads
|
|
11
|
+
with the bars' circle module on first use, as the bars do, so a single-view page's static part still leaves out
|
|
12
|
+
`@aiquants/virtualscroll`.
|
|
13
|
+
- **A document's ```` ```spreadsheets ```` tables show no tap-scroll circle unless `tapscroll=1` asks for one
|
|
14
|
+
(readers, writers).** With markdown 11.8.0 the document's tables take the same look (`spreadsheetTapScrollCircle` on
|
|
15
|
+
the viewer, the edit preview's included), and a table shows the circle, half a control across (22 px), only when its
|
|
16
|
+
options say `tapscroll=1`; a reader scrolling the page past the other tables meets none.
|
|
17
|
+
- **The peers `@aiquants/markdown` and `@aiquants/spreadsheet` are `^11.8.0` and `^0.18.0` (hosts),** which also bring
|
|
18
|
+
a table's frame (`frame=N`): the demo's table drawn as printed carries `frame=2`, its prices table `tapscroll=1`, and
|
|
19
|
+
a last table shows rows that scroll without the circle.
|
|
20
|
+
|
|
21
|
+
## 0.28.0 (2026-10-28) — The tap-scroll circle in a gutter of its own, clear of the document
|
|
22
|
+
|
|
23
|
+
### Changed
|
|
24
|
+
|
|
25
|
+
- **The tap-scroll circle sits in a gutter beside its bar, and no content lies under it (readers).** Every document
|
|
26
|
+
scroller with a circle — the viewer's scroll container, the image, media, file and failure views and each multi-view
|
|
27
|
+
panel's scroll area — keeps a 54 px gutter at its inline end, outside its own padding: the circle (one control,
|
|
28
|
+
44 px) with 5 px on each side, so the circle now sits 49 px before its bar instead of 80 px. A right-aligned toolbar
|
|
29
|
+
(a Mermaid diagram's, a table block's, an SVG image's), a code block's copy button or a focused link is no longer
|
|
30
|
+
covered when the reader scrolls it to the circle's height; only an image zoomed wider than its canvas still passes
|
|
31
|
+
beneath the circle while it pans sideways. The wheel and touch scroll over the gutter as over the document, and the
|
|
32
|
+
gutter is kept while the content fits, so the text never re-wraps when the bar appears. The document's text column
|
|
33
|
+
is 54 px narrower for it. The tree's circle moves with the same setting and still lies over the rows (a gutter would
|
|
34
|
+
take 54 px from a 13rem pane); the stage keeps its bar without a circle.
|
|
35
|
+
- **The peer `@aiquants/markdown` is `^11.7.0` (hosts),** whose `scrollBarGutter` the explorer gives the viewer.
|
|
36
|
+
|
|
3
37
|
## 0.27.0 (2026-10-27) — Workbooks shown sheet by sheet: Excel and OpenDocument read in the browser
|
|
4
38
|
|
|
5
39
|
### Breaking
|
package/README.md
CHANGED
|
@@ -49,12 +49,14 @@ A single-view (embedding) page never downloads the tree and multi-panel views, w
|
|
|
49
49
|
|
|
50
50
|
- React 19.2.7 or later and React Router 8 in framework mode (route modules with `loader` / `headers`).
|
|
51
51
|
- 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)`.
|
|
52
|
-
- The peer packages, at these versions or later within the caret ranges the package declares: `@aiquants/markdown` ^11.
|
|
53
|
-
|
|
52
|
+
- The peer packages, at these versions or later within the caret ranges the package declares: `@aiquants/markdown` ^11.8.0 (document rendering;
|
|
53
|
+
the gutter its scroll container keeps beside the explorer's bar for the tap-scroll circle (`scrollBarGutter`); the Source toggle of a storage SVG image that stands alone in a paragraph, read through `imageSource`, and a Copy that copies the image as a PNG image or its source, the source readable in every display style, a notice in place of a block that cannot render and plain text for a fence in a language it does not know; its components' stylesheet without utilities,
|
|
54
|
+
its controls' 44 px targets under every pointer, ```spreadsheets tables — inside list items and quotes too, and in a pane of their own (`layout="fill"`) never fewer than three rows, with the display options `toolbar=`, `zoom=`, `headings=`, `autofit=`, `frame=` and `tapscroll=` (the circle in the look the explorer passes as `spreadsheetTapScrollCircle`, or `tapScrollCircle` on a table file's block),
|
|
55
|
+
every row shown when `height` reaches the table's, and boxes no wider than the table — and their write-back through an editor that answers what came of each write (written, changed, a line that would close the fence, unwritable), reads a block's body back and tells them of its other changes,
|
|
54
56
|
the React-free `@aiquants/markdown/code-blocks` that names the `data-code-meta` the sanitizer keeps on `code`, holds the converter's reading of a fenced block's lines and the table labels with their placeholders,
|
|
55
57
|
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),
|
|
56
58
|
`@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),
|
|
57
|
-
`@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.
|
|
59
|
+
`@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.18.0 (the grid of those tables — one `role="grid"` with header rows, the content size a box is fitted to, a keyboard move the document follows and a frame around a range,
|
|
58
60
|
read-only where it cannot write and named by its block — which markdown loads only for a document that holds one, and the grid of a table file's preview, whose TSV grammar (`@aiquants/spreadsheet/tsv`) reads a TSV file — `iterateTsvPrefixRows` the rows of a file read partway — and whose operation budget (`SPREADSHEET_MAX_OPERATION_CELLS` of `@aiquants/spreadsheet/view`) bounds its table) and `@aiquants/virtualscroll` ^3.22.1 (44 px scroll-to-edge pills and tap-scroll circles, the pills' text at the body step).
|
|
59
61
|
The client depends on these floors, while a package manager may only warn about an older peer.
|
|
60
62
|
- A Markdown parser of your choice on the server that produces HTML and its headings (the explorer sanitizes the HTML before it is sent).
|
|
@@ -909,8 +911,13 @@ Every scroller of the explorer that the reader browses gets one pointer scroll b
|
|
|
909
911
|
| Multi view | The stage (bar without a circle) | drag-drop-panels' `renderStageScrollBar`, over the stage's inline-end edge, in 8 px the stage adds to its inline-end padding |
|
|
910
912
|
|
|
911
913
|
- Press the circle and pull it up or down: the scroller scrolls while the pointer is held, faster the farther it is pulled, and stops on release and at either end. A plain tap scrolls nothing.
|
|
912
|
-
- A circle sits
|
|
913
|
-
- The
|
|
914
|
+
- A circle is one control wide (44 px) and sits 49 px before its bar, at the middle of the scroller's height. It scrolls the same with a Mermaid diagram or an embedded frame at its height, and a drag that starts on it selects no text.
|
|
915
|
+
- The tables' grids take the same look and speeds (`TABLE_TAP_SCROLL_CIRCLE`): a table file's preview shows the grid's circle one control wide where the grid places it (toward the bottom-right quarter of its box), once the table scrolls on either axis, and a document's ```` ```spreadsheets ```` table shows one, 22 px across (half a control's 44 px target), only where its options say `tapscroll=1` (`@aiquants/markdown`'s `spreadsheetTapScrollCircle`).
|
|
916
|
+
The look loads with the bars' circle module on first use, as the bars do, so a single-view page's static part stays without `@aiquants/virtualscroll`; a circle drawn before it arrives shows it once it has.
|
|
917
|
+
- Every document scroller with a circle (the viewer's scroller, the image, medium, file and failure views, and each multi-view panel's scroll area) keeps a 54 px gutter at its inline end, outside its own padding: the circle with 5 px on each side.
|
|
918
|
+
So no content (a diagram's or a table's toolbar, a code block's copy button, a focused link) lies under the circle at any scroll position; only an image zoomed wider than its canvas passes beneath it while it pans sideways. The wheel and touch scroll over the gutter as over the rest of the document.
|
|
919
|
+
The gutter is kept while the content fits as well, so the text never re-wraps when the bar appears. For the viewer the explorer passes it as `@aiquants/markdown`'s `scrollBarGutter`. The tree's rows reach under the tree's circle, which has no gutter.
|
|
920
|
+
- The stage's bar has no circle: 49 px before the stage's bar a circle would cover the right-most panel's own bar and circle, and a gutter that holds it (54 px more of the stage's inline-end padding) would cost the stage a column (4 to 3 at a 1920 px window, 3 to 2 at 1440 px). The stage keeps its thumb, track and arrows, the plain wheel (which the panels hand to the stage), touch and the keyboard.
|
|
914
921
|
- Each bar drives its scroller's native scrolling, of which only the vertical scrollbar is hidden: a zoomed image keeps its native horizontal scrollbar, and the wheel, the keyboard, touch, find in page, fragments and the table of contents, the reading position a panel keeps, Ctrl/⌘ + wheel over a panel, and the browser's scroll anchoring work as without it, with the bar following each of them. The viewer's toolbar keeps clear of the document's bar.
|
|
915
922
|
- In a multi-view panel the document follows its content's height and the panel's scroll area scrolls, so the panel's viewer, image, medium, file and failure views have no bar of their own; the panel's bar is exempt from panel drags (`data-aqdd-no-panel-drag`). The stage's bar is not shown while a panel is maximized.
|
|
916
923
|
- Menus and popovers (the tree settings, the table of contents, the toolbars), the scrollers nested in a document (code blocks, tables, inline math) and embedded frames, a PDF's included, keep their native scrollbars and get no circle.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const q=require("react/jsx-runtime"),h=require("react"),y=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const q=require("react/jsx-runtime"),h=require("react"),y=require("./index-CnX313Ss.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"),je=require("@aiquants/markdown"),ue=require("@aiquants/markdown/source-lines"),ee=require("./dataRoute-DwYtgyt6.cjs"),de=require("./sanitizePolicy-T5T-3vV5.cjs"),ze=require("isomorphic-dompurify"),se=require("@aiquants/resize-panels"),X=require("./location-l_HysaZR.cjs"),ve=require("./useSplitPersistence-9Nu6J1WF.cjs"),qe={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)"}}),Me="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(Me,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&&(_e(t,l,r),t.focus())}),n.append(o)}return n}ignoreEvent(){return!0}}const re=e=>y.findConflictsInLines(e.iterLines()),we=(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=>we(t.doc,e),update:(t,n)=>n.docChanged?we(n.state.doc,e):t,provide:t=>P.EditorView.decorations.from(t)}),_e=(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
2
|
`);e.dispatch({changes:{from:d,to:f,insert:p},selection:$.EditorSelection.cursor(d),scrollIntoView:!0,userEvent:"input.resolve"})},Ee="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))}},be=(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
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(Ee))),(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 S=Math.min(m.length,u.length);for(;v<S&&m.charCodeAt(v)===u.charCodeAt(v);)v+=1;let g=0;for(;g<S-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,S)=>{const{doc:g}=c.state,L=o.lineOf(S,u);if(L===null)return"changed";const O=be(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 I=J.planFencedBodyEdit(O.lines,O.layout,v);if(I.kind!=="edit")return I.kind;if(I.from===I.to&&I.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(I.from),B=`${M===g.length&&g.sliceString(g.length-1)!==`
|
|
4
4
|
`?`
|
|
5
5
|
`:""}${I.lines.map(j=>`${j}
|
|
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 S=be(c.state,v);return S.kind==="found"?S.body:null},undo:()=>E(()=>K.undo(c)),redo:()=>E(()=>K.redo(c)),reveal:({line:u,column:m},v)=>{const{doc:S}=c.state,g=S.line(Math.min(Math.max(u,1),S.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=y.visibleTopOf(u,c.contentDOM),v=y.frameTopOf(u)+u.clientHeight,{documentTop:S}=c,{doc:g}=c.state;let L=c.lineBlockAtHeight(Math.max(m-S,0));for(;g.lineAt(L.from).text.trim()===""&&L.to<g.length;){const D=c.lineBlockAt(L.to+1);if(S+D.top>=v)break;L=D}const O=c.coordsAtPos(L.from),I=O===null?S+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-y.visibleTopOf(m,c.contentDOM),{doc:S}=c.state,g=L=>S.line(Math.min(Math.max(L,1),S.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,S=m.find(g=>g.end>=v);return S===void 0?!1:(_e(c,S,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,S=u.findIndex(I=>I.start>v),g=S<0?0:S,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?y.visibleTopOf(i,e.contentDOM):n)-y.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=y.frameTopOf(o),s=y.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,S=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,S?.abort(),S=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;S=T,v=setTimeout(()=>{v=void 0,n(e,w.text,T.signal).then(C=>{if(!(T.signal.aborted||!("kind"in C))){if(S=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,S=()=>{};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&&(S(),v=a,S=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(),S()}}},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=y.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-y.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}=y.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),S=h.useRef(E);h.useLayoutEffect(()=>{S.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:S.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:y.anchorOfView(A,a(R))},place:({line:a,clientTop:A},R)=>{const w=m.current,T=w===null?null:y.blockAtLine(w,a);T!==null&&(R(T).scrollTop+=y.lineTopIn(T,a)-A)}}),[]);const D=a=>{const A=m.current,{target:R}=a;if(o===void 0||A===null||!(R instanceof Element)||!y.isEditingDoubleClick(R))return;const w=y.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,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(y.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}=y.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="[data-aqmd-spreadsheet-fullscreen]",_t=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"},Pt=e=>{e.stopPropagation()},Nt=e=>{const{path:t,name:n,session:r}=e,{edits:i,labels:o,announcer:l}=y.useExplorer(),{phase:s}=r,d=h.useCallback(()=>i.retry(t),[i,t]);switch(h.useEffect(()=>{s.kind==="failed"&&l.announce(o.documentFailed(n,y.failureTitleOf(o,s.failure.reason)))},[s,l,o,n]),s.kind){case"opening":return q.jsx(y.ContentSkeleton,{label:o.editLoading,testId:"markdown-explorer-edit-skeleton"});case"grant":return q.jsx("div",{className:"aqmx-edit-message",children:q.jsx(y.EditGrantNotice,{href:s.href,onRetry:d,testId:"markdown-explorer-edit-grant"})});case"failed":return q.jsx("div",{className:"aqmx-edit-message",children:q.jsx(y.FailureView,{failure:s.failure,alert:!1,onRetry:d,testId:"markdown-explorer-edit-failure"})});case"editing":return q.jsx(Dt,{...e})}},Dt=({path:e,name:t,session:n,layout:r,viewer:i,region:o,paneScroll:l})=>{const{edits:s,labels:d}=y.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",S=y.useSideBySide(),g=y.editViewOf(n,S,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=_t(_)&&_.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(y.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(y.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(y.paneShownAlone(M.current.view)),m.current=x,()=>{x.dispose(),m.current=null}},[O,s,e,H]),h.useLayoutEffect(()=>{m.current?.showAlone(y.paneShownAlone(g))},[g]);const T=h.useCallback(()=>m.current?.previewChanged(),[]),C=h.useCallback(b=>s.start(e,b),[s,e]),U=b=>{if(b.target instanceof Element&&b.target.closest(Mt)!==null)return;if(b.key==="Escape"){y.consumeKey(b);return}if(!y.isEditViewShortcut(b.nativeEvent,y.isApplePlatform(navigator.platform)))return;y.consumeKey(b);const x=y.toggledEditView(g);B.current=x,y.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:Pt,children:[q.jsx("div",{ref:f,id:p,className:"aqmx-edit-editor","data-testid":"markdown-explorer-editor",inert:g==="preview",hidden:g==="preview"&&!v,...y.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=Nt;
|
|
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 S=be(c.state,v);return S.kind==="found"?S.body:null},undo:()=>E(()=>K.undo(c)),redo:()=>E(()=>K.redo(c)),reveal:({line:u,column:m},v)=>{const{doc:S}=c.state,g=S.line(Math.min(Math.max(u,1),S.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=y.visibleTopOf(u,c.contentDOM),v=y.frameTopOf(u)+u.clientHeight,{documentTop:S}=c,{doc:g}=c.state;let L=c.lineBlockAtHeight(Math.max(m-S,0));for(;g.lineAt(L.from).text.trim()===""&&L.to<g.length;){const D=c.lineBlockAt(L.to+1);if(S+D.top>=v)break;L=D}const O=c.coordsAtPos(L.from),I=O===null?S+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-y.visibleTopOf(m,c.contentDOM),{doc:S}=c.state,g=L=>S.line(Math.min(Math.max(L,1),S.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,S=m.find(g=>g.end>=v);return S===void 0?!1:(_e(c,S,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,S=u.findIndex(I=>I.start>v),g=S<0?0:S,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?y.visibleTopOf(i,e.contentDOM):n)-y.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=y.frameTopOf(o),s=y.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,S=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,S?.abort(),S=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;S=T,v=setTimeout(()=>{v=void 0,n(e,w.text,T.signal).then(C=>{if(!(T.signal.aborted||!("kind"in C))){if(S=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,S=()=>{};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&&(S(),v=a,S=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(),S()}}},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=y.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-y.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}=y.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),S=h.useRef(E);h.useLayoutEffect(()=>{S.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:S.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:y.anchorOfView(A,a(R))},place:({line:a,clientTop:A},R)=>{const w=m.current,T=w===null?null:y.blockAtLine(w,a);T!==null&&(R(T).scrollTop+=y.lineTopIn(T,a)-A)}}),[]);const D=a=>{const A=m.current,{target:R}=a;if(o===void 0||A===null||!(R instanceof Element)||!y.isEditingDoubleClick(R))return;const w=y.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(y.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}=y.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="[data-aqmd-spreadsheet-fullscreen]",_t=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"},Pt=e=>{e.stopPropagation()},Nt=e=>{const{path:t,name:n,session:r}=e,{edits:i,labels:o,announcer:l}=y.useExplorer(),{phase:s}=r,d=h.useCallback(()=>i.retry(t),[i,t]);switch(h.useEffect(()=>{s.kind==="failed"&&l.announce(o.documentFailed(n,y.failureTitleOf(o,s.failure.reason)))},[s,l,o,n]),s.kind){case"opening":return q.jsx(y.ContentSkeleton,{label:o.editLoading,testId:"markdown-explorer-edit-skeleton"});case"grant":return q.jsx("div",{className:"aqmx-edit-message",children:q.jsx(y.EditGrantNotice,{href:s.href,onRetry:d,testId:"markdown-explorer-edit-grant"})});case"failed":return q.jsx("div",{className:"aqmx-edit-message",children:q.jsx(y.FailureView,{failure:s.failure,alert:!1,onRetry:d,testId:"markdown-explorer-edit-failure"})});case"editing":return q.jsx(Dt,{...e})}},Dt=({path:e,name:t,session:n,layout:r,viewer:i,region:o,paneScroll:l})=>{const{edits:s,labels:d}=y.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",S=y.useSideBySide(),g=y.editViewOf(n,S,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=_t(_)&&_.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(y.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(y.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(y.paneShownAlone(M.current.view)),m.current=x,()=>{x.dispose(),m.current=null}},[O,s,e,H]),h.useLayoutEffect(()=>{m.current?.showAlone(y.paneShownAlone(g))},[g]);const T=h.useCallback(()=>m.current?.previewChanged(),[]),C=h.useCallback(b=>s.start(e,b),[s,e]),U=b=>{if(b.target instanceof Element&&b.target.closest(Mt)!==null)return;if(b.key==="Escape"){y.consumeKey(b);return}if(!y.isEditViewShortcut(b.nativeEvent,y.isApplePlatform(navigator.platform)))return;y.consumeKey(b);const x=y.toggledEditView(g);B.current=x,y.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:Pt,children:[q.jsx("div",{ref:f,id:p,className:"aqmx-edit-editor","data-testid":"markdown-explorer-editor",inert:g==="preview",hidden:g==="preview"&&!v,...y.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=Nt;
|
|
@@ -1,22 +1,22 @@
|
|
|
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 Pe, useImperativeHandle as je, useMemo as J, startTransition as Ye, useCallback as X, useId as Je } from "react";
|
|
3
|
-
import { v as ne,
|
|
3
|
+
import { v as ne, j as me, k as Qe, u as se, l as Ze, m as et, n as tt, o as De, p as nt, q as rt, s as ot, t as it, E as lt, w as st, x as ct, y as at, z as we, A as be, B as ut, G as Ee, H as dt, I as ft, J as mt, K as pt } from "./index-awodBw8r.js";
|
|
4
4
|
import { fencedBodyAsRead as ht, planFencedBodyEdit as gt, fencedCodeLanguageOf as vt, SPREADSHEETS_LANGUAGE as wt, readFencedLine as bt, listItemWidthOn as Et, openingFenceOn as xt } from "@aiquants/markdown/code-blocks";
|
|
5
5
|
import { history as St, historyKeymap as yt, defaultKeymap as kt, historyField as Tt, redo as At, undo as It, isolateHistory as Lt } from "@codemirror/commands";
|
|
6
6
|
import { markdown as Ct, markdownLanguage as Ot } from "@codemirror/lang-markdown";
|
|
7
7
|
import { syntaxHighlighting as Mt, syntaxTreeAvailable as qt, HighlightStyle as Rt, ensureSyntaxTree as Be } from "@codemirror/language";
|
|
8
8
|
import { highlightSelectionMatches as _t, searchKeymap as Nt } from "@codemirror/search";
|
|
9
9
|
import { EditorState as Ve, EditorSelection as fe, StateField as Pt, RangeSetBuilder as Dt, MapMode as Bt } from "@codemirror/state";
|
|
10
|
-
import { EditorView as
|
|
10
|
+
import { EditorView as K, lineNumbers as Vt, highlightActiveLineGutter as Ht, drawSelection as zt, highlightActiveLine as Ft, keymap as Gt, ViewPlugin as Ut, Decoration as ce, WidgetType as Wt } from "@codemirror/view";
|
|
11
11
|
import { tags as N } from "@lezer/highlight";
|
|
12
|
-
import { MarkdownViewer as
|
|
13
|
-
import { SOURCE_LINES_ATTRIBUTE as He, parseSourceLines as
|
|
12
|
+
import { MarkdownViewer as Kt } from "@aiquants/markdown";
|
|
13
|
+
import { SOURCE_LINES_ATTRIBUTE as He, parseSourceLines as $t } from "@aiquants/markdown/source-lines";
|
|
14
14
|
import { d as Xt, f as re, E as jt } from "./dataRoute-DLhQfdoW.js";
|
|
15
15
|
import { H as Yt, c as Jt, M as Qt } from "./sanitizePolicy-By0tKOpZ.js";
|
|
16
16
|
import Zt from "isomorphic-dompurify";
|
|
17
17
|
import { PanelGroup as en, Panel as xe, PanelResizeHandle as tn } from "@aiquants/resize-panels";
|
|
18
|
-
import { C as nn, F as rn, E as on, a as ln, b as oe, d as sn } from "./location-
|
|
19
|
-
import { u as cn, a as an } from "./useSplitPersistence-
|
|
18
|
+
import { C as nn, F as rn, E as on, a as ln, b as oe, d as sn } from "./location-CKuabtKl.js";
|
|
19
|
+
import { u as cn, a as an } from "./useSplitPersistence-Bf4M35Il.js";
|
|
20
20
|
const ze = { history: Tt }, un = Rt.define([
|
|
21
21
|
{ tag: [N.heading1, N.heading2, N.heading3, N.heading4, N.heading5, N.heading6, N.heading], color: "var(--aqmx-syntax-heading)", fontWeight: "700" },
|
|
22
22
|
{ tag: N.strong, fontWeight: "700" },
|
|
@@ -27,7 +27,7 @@ const ze = { history: Tt }, un = Rt.define([
|
|
|
27
27
|
{ tag: N.monospace, color: "var(--aqmx-syntax-code)" },
|
|
28
28
|
{ tag: N.quote, color: "var(--aqmx-syntax-quote)" },
|
|
29
29
|
{ tag: [N.processingInstruction, N.contentSeparator, N.labelName, N.meta], color: "var(--aqmx-syntax-mark)" }
|
|
30
|
-
]), dn =
|
|
30
|
+
]), dn = K.theme({
|
|
31
31
|
"&": { height: "100%", color: "var(--aqmx-text)", backgroundColor: "var(--aqmx-surface)", fontSize: "var(--aqmx-font-size-title)" },
|
|
32
32
|
"&.cm-focused": { outline: "none" },
|
|
33
33
|
".cm-scroller": { fontFamily: 'ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace', lineHeight: "var(--aqmx-line-height-prose)" },
|
|
@@ -61,7 +61,7 @@ class hn extends Wt {
|
|
|
61
61
|
const o = document.createElement("button");
|
|
62
62
|
o.type = "button", o.textContent = l, o.setAttribute("data-aqmx-conflict-choice", r), o.addEventListener("mousedown", (s) => s.preventDefault()), o.addEventListener("click", () => {
|
|
63
63
|
const s = ee(t.state.doc)[this.index];
|
|
64
|
-
s !== void 0 && (
|
|
64
|
+
s !== void 0 && (Ge(t, s, r), t.focus());
|
|
65
65
|
}), n.append(o);
|
|
66
66
|
}
|
|
67
67
|
return n;
|
|
@@ -83,8 +83,8 @@ const ee = (e) => Qe(e.iterLines()), Se = (e, t) => {
|
|
|
83
83
|
}, gn = (e) => Pt.define({
|
|
84
84
|
create: (t) => Se(t.doc, e),
|
|
85
85
|
update: (t, n) => n.docChanged ? Se(n.state.doc, e) : t,
|
|
86
|
-
provide: (t) =>
|
|
87
|
-
}),
|
|
86
|
+
provide: (t) => K.decorations.from(t)
|
|
87
|
+
}), Ge = (e, t, n) => {
|
|
88
88
|
const { doc: r } = e.state, l = (y, c) => {
|
|
89
89
|
const w = [];
|
|
90
90
|
for (let u = y; u <= c; u += 1) w.push(r.line(u).text);
|
|
@@ -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", vn = 20, wn =
|
|
98
|
+
}, ye = "input.preview", vn = 20, wn = Ut.fromClass(
|
|
99
99
|
class {
|
|
100
100
|
constructor(e) {
|
|
101
101
|
this.view = e, this.schedule();
|
|
@@ -181,19 +181,19 @@ const ee = (e) => Qe(e.iterLines()), Se = (e, t) => {
|
|
|
181
181
|
}, Sn = ({ parent: e, scroll: t, text: n, saved: r, labels: l, revisions: o, onChange: s, onGeometry: i, onSave: d }) => {
|
|
182
182
|
let f = !1;
|
|
183
183
|
const p = [
|
|
184
|
-
|
|
184
|
+
K.scrollHandler.of((u, m, g) => (yn(u, m.head, g, t), !0)),
|
|
185
185
|
Vt(),
|
|
186
186
|
Ht(),
|
|
187
187
|
St(),
|
|
188
188
|
zt(),
|
|
189
189
|
Ft(),
|
|
190
190
|
_t(),
|
|
191
|
-
|
|
191
|
+
K.lineWrapping,
|
|
192
192
|
Ct({ base: Ot }),
|
|
193
193
|
wn,
|
|
194
194
|
Mt(un),
|
|
195
195
|
gn(l),
|
|
196
|
-
|
|
196
|
+
Gt.of([
|
|
197
197
|
{
|
|
198
198
|
key: "Mod-s",
|
|
199
199
|
preventDefault: !0,
|
|
@@ -203,13 +203,13 @@ const ee = (e) => Qe(e.iterLines()), Se = (e, t) => {
|
|
|
203
203
|
...yt,
|
|
204
204
|
...kt
|
|
205
205
|
]),
|
|
206
|
-
|
|
207
|
-
|
|
206
|
+
K.contentAttributes.of({ "aria-label": l.editor, "aria-multiline": "true" }),
|
|
207
|
+
K.updateListener.of((u) => {
|
|
208
208
|
for (const m of u.transactions) m.docChanged && o.record(m.changes, m.newDoc);
|
|
209
209
|
u.docChanged && s(u.transactions.every((m) => !m.docChanged || m.isUserEvent(ye))), (u.docChanged || u.heightChanged || u.geometryChanged) && i(u.docChanged && !f);
|
|
210
210
|
}),
|
|
211
211
|
dn
|
|
212
|
-
], y = An(r, p) ?? Ve.create({ doc: n, extensions: p }), c = new
|
|
212
|
+
], y = An(r, p) ?? Ve.create({ doc: n, extensions: p }), c = new K({ state: y, parent: e });
|
|
213
213
|
o.mount(c.state.doc);
|
|
214
214
|
const w = (u) => {
|
|
215
215
|
f = !0;
|
|
@@ -286,13 +286,13 @@ const ee = (e) => Qe(e.iterLines()), Se = (e, t) => {
|
|
|
286
286
|
conflicts: () => ee(c.state.doc),
|
|
287
287
|
resolveAtCursor: (u) => {
|
|
288
288
|
const m = ee(c.state.doc), g = c.state.doc.lineAt(c.state.selection.main.head).number, x = m.find((h) => h.end >= g);
|
|
289
|
-
return x === void 0 ? !1 : (
|
|
289
|
+
return x === void 0 ? !1 : (Ge(c, x, u), !0);
|
|
290
290
|
},
|
|
291
291
|
nextConflict: () => {
|
|
292
292
|
const u = ee(c.state.doc);
|
|
293
293
|
if (u[0] === void 0) return !1;
|
|
294
294
|
const g = c.state.doc.lineAt(c.state.selection.main.head).number, x = u.findIndex((A) => A.start > g), h = x < 0 ? 0 : x, k = c.state.doc.line(u[h].start).from;
|
|
295
|
-
c.dispatch({ selection: fe.cursor(k), effects:
|
|
295
|
+
c.dispatch({ selection: fe.cursor(k), effects: K.scrollIntoView(k, { y: "center" }) });
|
|
296
296
|
const I = c.contentDOM.querySelector(`[${Fe}="${String(h)}"] button`);
|
|
297
297
|
return I instanceof HTMLElement ? I.focus({ preventScroll: !0 }) : c.focus(), !0;
|
|
298
298
|
},
|
|
@@ -301,7 +301,7 @@ const ee = (e) => Qe(e.iterLines()), Se = (e, t) => {
|
|
|
301
301
|
};
|
|
302
302
|
}, Te = (e, t, n, r) => {
|
|
303
303
|
const l = r.scrollerOf(e.scrollDOM), o = (n === null ? ne(l, e.contentDOM) : n) - me(l);
|
|
304
|
-
return
|
|
304
|
+
return K.scrollIntoView(t, { y: "start", yMargin: o });
|
|
305
305
|
}, yn = (e, t, n, r) => {
|
|
306
306
|
const l = kn(e, t), o = r.scrollerOf(e.scrollDOM), s = me(o), i = ne(o, e.contentDOM), d = s + o.clientHeight;
|
|
307
307
|
let f = 0;
|
|
@@ -373,9 +373,9 @@ const ee = (e) => Qe(e.iterLines()), Se = (e, t) => {
|
|
|
373
373
|
}, P = () => {
|
|
374
374
|
if (t === null || c === null) return;
|
|
375
375
|
const v = c, S = [], C = { asset: /* @__PURE__ */ new Set(), doc: /* @__PURE__ */ new Set() };
|
|
376
|
-
let
|
|
376
|
+
let U;
|
|
377
377
|
try {
|
|
378
|
-
|
|
378
|
+
U = t.sanitize(v.html, (E) => {
|
|
379
379
|
const M = s[E.kind].get(E.path);
|
|
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
|
});
|
|
@@ -384,7 +384,7 @@ const ee = (e) => Qe(e.iterLines()), Se = (e, t) => {
|
|
|
384
384
|
return;
|
|
385
385
|
}
|
|
386
386
|
w = S;
|
|
387
|
-
const b = i.parsed !== null && i.parsed.htmlContent ===
|
|
387
|
+
const b = i.parsed !== null && i.parsed.htmlContent === U && i.parsed.headings === v.headings ? i.parsed : { htmlContent: U, headings: v.headings };
|
|
388
388
|
h({ parsed: b, source: v.draft, failure: null, busy: !1, tier: "instant" }), F();
|
|
389
389
|
}, H = () => {
|
|
390
390
|
if (u = void 0, m || c === null || w.length === 0) return;
|
|
@@ -418,8 +418,8 @@ 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
|
|
422
|
-
return
|
|
421
|
+
const U = Xt(C);
|
|
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":
|
|
@@ -427,7 +427,7 @@ const ee = (e) => Qe(e.iterLines()), Se = (e, t) => {
|
|
|
427
427
|
_(), O(re("too-large"), "instant");
|
|
428
428
|
return;
|
|
429
429
|
}
|
|
430
|
-
c = { draft: v, html: S.htmlContent, headings: S.headings.map(({ text: C, depth:
|
|
430
|
+
c = { draft: v, html: S.htmlContent, headings: S.headings.map(({ text: C, depth: U, id: b }) => ({ text: C, depth: U, id: b })) }, P();
|
|
431
431
|
return;
|
|
432
432
|
case "failure":
|
|
433
433
|
A(), _(), O(re(S.failure.reason, S.failure.code), "instant");
|
|
@@ -470,7 +470,7 @@ const ee = (e) => Qe(e.iterLines()), Se = (e, t) => {
|
|
|
470
470
|
{ editor: l.top, preview: n.top },
|
|
471
471
|
{ editor: l.bottom, preview: n.bottom }
|
|
472
472
|
];
|
|
473
|
-
}),
|
|
473
|
+
}), $ = (e, t) => {
|
|
474
474
|
const n = e[t];
|
|
475
475
|
if (n === void 0) throw new RangeError(`[markdown-explorer] a scroll map index must be in 0..${String(e.length - 1)}; got ${String(t)}`);
|
|
476
476
|
return n;
|
|
@@ -480,9 +480,9 @@ const ee = (e) => Qe(e.iterLines()), Se = (e, t) => {
|
|
|
480
480
|
let l = 0, o = t.length;
|
|
481
481
|
for (; l < o; ) {
|
|
482
482
|
const s = l + o >> 1;
|
|
483
|
-
|
|
483
|
+
$(t, s).pair.preview <= r.preview ? l = s + 1 : o = s;
|
|
484
484
|
}
|
|
485
|
-
t[l] = { pair: r, before: l === 0 ? void 0 :
|
|
485
|
+
t[l] = { pair: r, before: l === 0 ? void 0 : $(t, l - 1) };
|
|
486
486
|
}
|
|
487
487
|
const n = [];
|
|
488
488
|
for (let r = t.at(-1); r !== void 0; r = r.before) n.push(r.pair);
|
|
@@ -498,15 +498,15 @@ const ee = (e) => Qe(e.iterLines()), Se = (e, t) => {
|
|
|
498
498
|
toEditor: (f) => Ie(d, "preview", "editor", f)
|
|
499
499
|
};
|
|
500
500
|
}, Ie = (e, t, n, r) => {
|
|
501
|
-
const l =
|
|
501
|
+
const l = $(e, 0), o = $(e, e.length - 1);
|
|
502
502
|
if (Number.isNaN(r) || r <= l[t]) return l[n];
|
|
503
503
|
if (r >= o[t]) return o[n];
|
|
504
504
|
let s = 0, i = e.length - 1;
|
|
505
505
|
for (; i - s > 1; ) {
|
|
506
506
|
const p = s + i >> 1;
|
|
507
|
-
|
|
507
|
+
$(e, p)[t] <= r ? s = p : i = p;
|
|
508
508
|
}
|
|
509
|
-
const d =
|
|
509
|
+
const d = $(e, s), f = $(e, i);
|
|
510
510
|
return d[n] + (f[n] - d[n]) * (r - d[t]) / (f[t] - d[t]);
|
|
511
511
|
}, Bn = 610, Le = 89, Ce = 0.5, Vn = ({ editor: e, preview: t, previewBlocks: n, editorSpans: r, requestFrame: l, cancelFrame: o, now: s }) => {
|
|
512
512
|
let i = "editor", d = 0, f = null, p = null, y = !1, c = null, w = null;
|
|
@@ -556,7 +556,7 @@ const ee = (e) => Qe(e.iterLines()), Se = (e, t) => {
|
|
|
556
556
|
y = !0, p !== null && o(p), p = null, A(), _(), x();
|
|
557
557
|
}
|
|
558
558
|
};
|
|
559
|
-
}, Oe = Object.freeze(["wheel", "pointerdown", "keydown", "focusin"]),
|
|
559
|
+
}, Oe = Object.freeze(["wheel", "pointerdown", "keydown", "focusin"]), Ue = (e) => ({
|
|
560
560
|
position: () => e.scrollTop,
|
|
561
561
|
max: () => Math.max(e.scrollHeight - e.clientHeight, 0),
|
|
562
562
|
viewport: () => e.clientHeight,
|
|
@@ -571,7 +571,7 @@ const ee = (e) => Qe(e.iterLines()), Se = (e, t) => {
|
|
|
571
571
|
}), Z = "[data-aqmd-scroll-container]", Hn = "[data-aqmd-content]", zn = `[${He}]`, Fn = Object.freeze(["p1", "p2", "p3", "p4", "p5", "p6", "p7", "p8"]), We = (e, t) => {
|
|
572
572
|
const n = nt(e.peek(t));
|
|
573
573
|
return n !== null && n.document.kind === "markdown" ? { htmlContent: n.document.htmlContent, headings: n.document.headings } : null;
|
|
574
|
-
},
|
|
574
|
+
}, Gn = (e, t, n, r, l) => {
|
|
575
575
|
if (n === void 0) return null;
|
|
576
576
|
let o;
|
|
577
577
|
try {
|
|
@@ -580,11 +580,11 @@ const ee = (e) => Qe(e.iterLines()), Se = (e, t) => {
|
|
|
580
580
|
return console.error("[markdown-explorer] the draft sanitizer cannot run in this browser, so the server renders the preview", s), null;
|
|
581
581
|
}
|
|
582
582
|
return { converter: n, sanitize: o, marksOf: qn, seed: We(r, l)?.htmlContent ?? null };
|
|
583
|
-
},
|
|
583
|
+
}, Un = (e) => {
|
|
584
584
|
const t = [];
|
|
585
585
|
let n = null;
|
|
586
586
|
for (const r of e.querySelectorAll(zn)) {
|
|
587
|
-
const l =
|
|
587
|
+
const l = $t(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();
|
|
@@ -598,7 +598,7 @@ const ee = (e) => Qe(e.iterLines()), Se = (e, t) => {
|
|
|
598
598
|
});
|
|
599
599
|
const h = ve(() => t());
|
|
600
600
|
Pe(() => {
|
|
601
|
-
const a =
|
|
601
|
+
const a = Gn(d.iframeHosts, d.dataPath, y, p, e), T = h(), L = Rn({ path: e, instant: a, preview: f.preview, initial: x.current, onView: (v) => Ye(() => u(v)) });
|
|
602
602
|
return g.current = L, L.update(T), () => {
|
|
603
603
|
L.dispose(), g.current = null;
|
|
604
604
|
};
|
|
@@ -626,11 +626,11 @@ const ee = (e) => Qe(e.iterLines()), Se = (e, t) => {
|
|
|
626
626
|
},
|
|
627
627
|
scrollPort: () => {
|
|
628
628
|
const a = m.current?.querySelector(Z);
|
|
629
|
-
return a instanceof HTMLElement ? (A.current?.scroller !== a && (A.current = { scroller: a, port:
|
|
629
|
+
return a instanceof HTMLElement ? (A.current?.scroller !== a && (A.current = { scroller: a, port: Ue(a) }), A.current.port) : null;
|
|
630
630
|
},
|
|
631
631
|
blocks: () => {
|
|
632
632
|
const a = m.current?.querySelector(Z);
|
|
633
|
-
return a instanceof HTMLElement ?
|
|
633
|
+
return a instanceof HTMLElement ? Un(a) : [];
|
|
634
634
|
},
|
|
635
635
|
focus: () => {
|
|
636
636
|
const a = m.current?.querySelector(Z);
|
|
@@ -662,10 +662,10 @@ const ee = (e) => Qe(e.iterLines()), Se = (e, t) => {
|
|
|
662
662
|
},
|
|
663
663
|
[r, O]
|
|
664
664
|
), P = J(() => ({ ...n.labels, spreadsheetReadOnly: c.previewTablePending }), [n.labels, c.previewTablePending]), H = J(
|
|
665
|
-
() => ({ ...n, labels: F === void 0 ? P : n.labels, showToc: !1, showStyle: !1, showAlign: !1, renderScrollBar: void 0, spreadsheetEditor: F }),
|
|
665
|
+
() => ({ ...n, labels: F === void 0 ? P : n.labels, showToc: !1, showStyle: !1, showAlign: !1, renderScrollBar: void 0, scrollBarGutter: void 0, spreadsheetEditor: F }),
|
|
666
666
|
[n, P, F]
|
|
667
667
|
), V = J(
|
|
668
|
-
() => w.parsed === null ? null : /* @__PURE__ */ R("div", { className: "aqmx-document-viewer", children: /* @__PURE__ */ R(
|
|
668
|
+
() => w.parsed === null ? null : /* @__PURE__ */ R("div", { className: "aqmx-document-viewer", children: /* @__PURE__ */ R(Kt, { ...H, parseResult: w.parsed, content: null }) }),
|
|
669
669
|
[H, w.parsed]
|
|
670
670
|
);
|
|
671
671
|
return /* @__PURE__ */ le(
|
|
@@ -687,7 +687,7 @@ const ee = (e) => Qe(e.iterLines()), Se = (e, t) => {
|
|
|
687
687
|
]
|
|
688
688
|
}
|
|
689
689
|
);
|
|
690
|
-
}, Me = "data-aqmx-edit-split", de = "--aqmx-edit-share", qe = "--aqmx-edit-gutter",
|
|
690
|
+
}, Me = "data-aqmx-edit-split", de = "--aqmx-edit-share", qe = "--aqmx-edit-gutter", Kn = "data-aqmx-edit-split-probe", $n = "aqmx-edit-split", Xn = "aqmx-edit-editor", jn = "aqmx-edit-preview", Re = { value: ln, unit: "percentage" }, _e = { value: on, unit: "percentage" }, Ne = (e) => {
|
|
691
691
|
if (e.length !== 2) return null;
|
|
692
692
|
const [t = 0, n = 0] = e, r = t + n;
|
|
693
693
|
return r > 0 ? t / r * 100 : null;
|
|
@@ -746,8 +746,8 @@ const ee = (e) => Qe(e.iterLines()), Se = (e, t) => {
|
|
|
746
746
|
[d]
|
|
747
747
|
);
|
|
748
748
|
return /* @__PURE__ */ le("div", { ref: r, className: "aqmx-edit-split", "data-testid": "markdown-explorer-edit-split", children: [
|
|
749
|
-
/* @__PURE__ */ R("span", { ref: l, className: "aqmx-edit-split-probe", "aria-hidden": "true", [
|
|
750
|
-
s === null ? null : /* @__PURE__ */ le(en, { id:
|
|
749
|
+
/* @__PURE__ */ R("span", { ref: l, className: "aqmx-edit-split-probe", "aria-hidden": "true", [Kn]: "" }),
|
|
750
|
+
s === null ? null : /* @__PURE__ */ le(en, { id: $n, direction: s === "beside" ? "horizontal" : "vertical", onLayout: f, className: "aqmx-edit-split-group", children: [
|
|
751
751
|
/* @__PURE__ */ R(xe, { id: Xn, defaultSize: { value: i, unit: "percentage" }, minSize: Re, maxSize: _e, contentOverflow: "hidden" }),
|
|
752
752
|
/* @__PURE__ */ R(
|
|
753
753
|
tn,
|
|
@@ -843,11 +843,11 @@ const ee = (e) => Qe(e.iterLines()), Se = (e, t) => {
|
|
|
843
843
|
let W = null, j = null;
|
|
844
844
|
const ae = () => {
|
|
845
845
|
W !== null && clearTimeout(W), W = null, j !== null && i.setDraft(e, j.text());
|
|
846
|
-
},
|
|
846
|
+
}, G = Sn({
|
|
847
847
|
parent: b,
|
|
848
848
|
scroll: {
|
|
849
849
|
scrollerOf: (q) => {
|
|
850
|
-
const { layout: Y, region:
|
|
850
|
+
const { layout: Y, region: $e, paneScroll: Xe } = A.current, ge = $e();
|
|
851
851
|
return Y === "fill" || ge === null ? q : Xe.scrollerOf(ge, q);
|
|
852
852
|
},
|
|
853
853
|
reveal: (q) => A.current.paneScroll.reveal(q)
|
|
@@ -866,18 +866,18 @@ const ee = (e) => Qe(e.iterLines()), Se = (e, t) => {
|
|
|
866
866
|
i.save(e);
|
|
867
867
|
}
|
|
868
868
|
});
|
|
869
|
-
j =
|
|
869
|
+
j = G, y.current = G;
|
|
870
870
|
const pe = () => {
|
|
871
|
-
const q =
|
|
871
|
+
const q = G.topLine();
|
|
872
872
|
return { line: q.line, clientTop: q.clientTop };
|
|
873
|
-
}, he = () => u.current?.anchor(a) ?? null,
|
|
873
|
+
}, he = () => u.current?.anchor(a) ?? null, Ke = i.bindEditor(e, {
|
|
874
874
|
flush: ae,
|
|
875
|
-
adopt: (q) =>
|
|
875
|
+
adopt: (q) => G.replaceText(q),
|
|
876
876
|
returnPoint: () => {
|
|
877
877
|
const q = O.current.view === "preview" && A.current.layout === "content" ? he() : null;
|
|
878
878
|
return q === null ? pe() : { line: q.lines.first, clientTop: q.clientTop };
|
|
879
879
|
},
|
|
880
|
-
nextConflict: () => O.current.view !== "preview" ?
|
|
880
|
+
nextConflict: () => O.current.view !== "preview" ? G.nextConflict() : G.conflicts().length === 0 ? !1 : (H.current = !0, i.setView(e, "editor"), !0),
|
|
881
881
|
beforeView: (q) => {
|
|
882
882
|
if (A.current.layout === "fill") return;
|
|
883
883
|
if (q === "preview") {
|
|
@@ -888,8 +888,8 @@ const ee = (e) => Qe(e.iterLines()), Se = (e, t) => {
|
|
|
888
888
|
F.current = Y === null ? null : { to: "editor", anchor: Y };
|
|
889
889
|
}
|
|
890
890
|
});
|
|
891
|
-
return z !== null &&
|
|
892
|
-
ae(), i.editorState.set(e, { state:
|
|
891
|
+
return z !== null && G.showLine(z.topLine), () => {
|
|
892
|
+
ae(), i.editorState.set(e, { state: G.save(), generation: _.current, topLine: G.topLine().line }), Ke(), G.destroy(), j = null, y.current = null;
|
|
893
893
|
};
|
|
894
894
|
}, [i, e, V, a, c, w]);
|
|
895
895
|
const { request: T } = n;
|
|
@@ -933,7 +933,7 @@ const ee = (e) => Qe(e.iterLines()), Se = (e, t) => {
|
|
|
933
933
|
const b = y.current;
|
|
934
934
|
if (!I || b === null) return;
|
|
935
935
|
const E = Vn({
|
|
936
|
-
editor:
|
|
936
|
+
editor: Ue(b.scrollElement),
|
|
937
937
|
preview: () => u.current?.scrollPort() ?? null,
|
|
938
938
|
previewBlocks: () => u.current?.blocks() ?? [],
|
|
939
939
|
editorSpans: (M) => b.lineSpans(M),
|