@aiquants/markdown-explorer 0.21.0 → 0.23.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 +80 -0
- package/README.md +27 -16
- package/dist/EditSurface-Bk4tdJ99.cjs +6 -0
- package/dist/EditSurface-Dhvw9IDD.js +975 -0
- package/dist/{ExplorerSplit-CdqEKz-I.cjs → ExplorerSplit-BAFiXU-V.cjs} +1 -1
- package/dist/{ExplorerSplit-3WMRDA7G.js → ExplorerSplit-Q5VqUBDE.js} +3 -3
- package/dist/{MultiLayout-BEg1X8Jx.cjs → MultiLayout-Bq_TS3ez.cjs} +1 -1
- package/dist/{MultiLayout-Gf1xT-Le.js → MultiLayout-DlATT7km.js} +22 -22
- package/dist/{NativeScrollBar-idIQsvCv.cjs → NativeScrollBar-A6-qEpz7.cjs} +1 -1
- package/dist/{NativeScrollBar-0cpp2OIu.js → NativeScrollBar-TsIcS3JZ.js} +1 -1
- package/dist/{TreeLayout-DJY_WqzP.cjs → TreeLayout-l-r2pPao.cjs} +1 -1
- package/dist/{TreeLayout-DzZCgMTt.js → TreeLayout-zrSo4MNZ.js} +3 -3
- package/dist/core/contracts.d.cts +7 -0
- package/dist/core/contracts.d.ts +7 -0
- package/dist/core/labels.d.cts +21 -27
- package/dist/core/labels.d.ts +21 -27
- package/dist/{dataRoute-CObbjNxG.js → dataRoute-Diu_7gle.js} +84 -83
- package/dist/dataRoute-vXGZMVB-.cjs +1 -0
- package/dist/index-BNFl3BsO.cjs +13 -0
- package/dist/{index-CJgHGeZs.js → index-Jz6zeO4O.js} +1500 -1529
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +9 -9
- package/dist/{location-B-m9scLf.js → location-8Ho8ZNv_.js} +1 -1
- package/dist/{location-BVEN_Ihk.cjs → location-DN0AI4ir.cjs} +1 -1
- package/dist/{merge-BOcofJN5.js → merge-BzMpSaxx.js} +1 -1
- package/dist/{merge-BVk6pvO_.cjs → merge-DlPkU2Jc.cjs} +1 -1
- package/dist/{sanitizePolicy-BWQtWhsL.js → sanitizePolicy-BvhYIqVO.js} +1 -1
- package/dist/{sanitizePolicy-gEXeavb-.cjs → sanitizePolicy-Du3lFZd-.cjs} +1 -1
- package/dist/sanitizeWorker.cjs +1 -1
- package/dist/sanitizeWorker.js +1 -1
- package/dist/server/ports.d.cts +2 -1
- package/dist/server/ports.d.ts +2 -1
- package/dist/server.cjs +1 -1
- package/dist/server.js +524 -521
- package/dist/{useSplitPersistence-Ba-v64n-.cjs → useSplitPersistence-CR4Oxtaa.cjs} +1 -1
- package/dist/{useSplitPersistence-Cc4tDxB4.js → useSplitPersistence-HfAb8Kzh.js} +1 -1
- package/docs/behavior/dom-hooks.md +3 -3
- package/docs/behavior/layout.md +11 -5
- package/docs/behavior/localization.md +9 -7
- package/docs/behavior/security.md +1 -1
- package/docs/behavior/url-contract.md +2 -2
- package/package.json +5 -5
- package/dist/EditSurface-Bwl4S1vQ.cjs +0 -7
- package/dist/EditSurface-rKoy_ndP.js +0 -880
- package/dist/dataRoute-BONacTPi.cjs +0 -1
- package/dist/index-bMaSoQTe.cjs +0 -13
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const e=require("react"),d=require("./location-
|
|
1
|
+
"use strict";const e=require("react"),d=require("./location-DN0AI4ir.cjs"),f="(pointer: coarse)",E=r=>{const n=window.matchMedia(f);return n.addEventListener("change",r),()=>n.removeEventListener("change",r)},S=()=>window.matchMedia(f).matches,m=()=>!1,C=()=>e.useSyncExternalStore(E,S,m),R=r=>{const n=e.useRef(r);e.useLayoutEffect(()=>{n.current=r},[r]);const c=e.useRef(null),t=e.useRef(null),s=e.useRef(!1),u=e.useCallback(()=>{t.current!==null&&clearTimeout(t.current),t.current=setTimeout(()=>{t.current=null,c.current!==null&&n.current(c.current)},d.SPLIT_PERSIST_DELAY_MS)},[]);e.useEffect(()=>()=>{t.current!==null&&clearTimeout(t.current)},[]);const a=e.useCallback((o,l)=>{c.current=o,l.source==="keyboard"?u():l.source==="pointer"&&(s.current=!0)},[u]),i=e.useCallback(o=>{if(o){s.current=!1;return}s.current&&(s.current=!1,u())},[u]);return e.useMemo(()=>({layoutChanged:a,draggingChanged:i}),[a,i])};exports.useCoarsePointer=C;exports.useSplitPersistence=R;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useSyncExternalStore as d, useRef as c, useLayoutEffect as E, useCallback as a, useEffect as S, useMemo as h } from "react";
|
|
2
|
-
import { S as y } from "./location-
|
|
2
|
+
import { S as y } from "./location-8Ho8ZNv_.js";
|
|
3
3
|
const m = "(pointer: coarse)", C = (e) => {
|
|
4
4
|
const t = window.matchMedia(m);
|
|
5
5
|
return t.addEventListener("change", e), () => t.removeEventListener("change", e);
|
|
@@ -20,7 +20,7 @@ Tests and host styling may rely on the `data-testid` values and `data-aqmx-*` at
|
|
|
20
20
|
| `data-testid="markdown-explorer-single"` | Single view frame | Carries `data-aqmx-content-pane` |
|
|
21
21
|
| `data-aqmx-content-pane` | The content pane the explorer's dialogs are centered over | The document column of the tree view (the bar and the document region), the single view's frame, the multi view's stage, and a maximized panel's frame (`markdown-explorer-panel-frame`, inside the stage) while it is maximized; a view's loading placeholder while its code loads. The innermost element carrying it is the pane |
|
|
22
22
|
| `data-testid="markdown-explorer-document-refresh-bar"` | The document refresh bar | In the tree and single views, above the document region (the button at its inline end; absent while the tree view shows no document); in the multi view, the first row of each panel's body, inside the panel's scroll area and pinned (sticky) to its top while the document scrolls under it. Holds the button row (the Source toggle while the document is Markdown, the Edit toggle or the external editor's link when the host offers one, then the Refresh document button) and, below it, the failure notice. While its document is edited it carries `data-aqmx-editing="true"`, and its row holds the editor's status and actions, then the Edit toggle (Source, Refresh document and the refresh notice step aside); a save that needs a grant shows `markdown-explorer-save-grant` below the row |
|
|
23
|
-
| `data-testid="markdown-explorer-document-markup"` | The Source toggle, in the bar before Refresh document | Shown only while the bar's document is a loaded Markdown document. A toggle button: `aria-pressed="true"` while the document shows as written (its source), `"false"` while it shows rendered; a press replaces the URL with the document shown the other way (`markup`, see the [URL contract](url-contract.md#shape)), so a reload or a shared link shows it the same way. The page views name it by its visible label (`showMarkupLabel`; tooltip `showMarkup`); a panel's is icon-only, with `aria-label` and `title` set to `showMarkupNamed` (the panel title) |
|
|
23
|
+
| `data-testid="markdown-explorer-document-markup"` | The Source toggle, in the bar before Refresh document | Shown only while the bar's document is a loaded Markdown document or SVG image (`imageType` `svg`; a raster image has none). A toggle button: `aria-pressed="true"` while the document shows as written (its source, an SVG image's own SVG), `"false"` while it shows rendered; a press replaces the URL with the document shown the other way (`markup`, see the [URL contract](url-contract.md#shape)), so a reload or a shared link shows it the same way. The page views name it by its visible label (`showMarkupLabel`; tooltip `showMarkup`, or `showSvgMarkup` for an SVG image); a panel's is icon-only, with `aria-label` and `title` set to `showMarkupNamed` (the panel title) |
|
|
24
24
|
| `data-testid="markdown-explorer-document-edit"` | The Edit toggle, in the bar between Source and Refresh document | Shown while the document is a loaded Markdown document whose `edit` is `inline` or `draft`, and while it is edited. A toggle button: `aria-pressed="true"` while the document is edited (its `title` is then `closeEditor`). The page views name it by its visible label (`editDocumentLabel`; tooltip `editDocument`, or `editDraftDocument` for a `draft` edit); a panel's is icon-only, named `editDocumentNamed` (`editDraftDocumentNamed` for a `draft` edit, with the panel title). The same element before and after a press |
|
|
25
25
|
| `data-testid="markdown-explorer-document-edit-external"` | Link to the document's own editor (a new tab), in place of the Edit toggle | For an `edit` of kind `external`: `href` is the host's `https:` address, with `target="_blank"` and `rel="noopener noreferrer"`; named `editExternallyLabel` in the page views and `editExternallyNamed` in a panel |
|
|
26
26
|
| `data-testid="markdown-explorer-edit-status"` | The editor's status, first in the bar's row while the document is edited | One line, ellipsed, with the whole text as its `title`; carries `data-aqmx-save` (`idle`, `saving`, `saved`, `conflicts`, `grant`, `failed`, or `draft` for a session that never saves, whose status is `draftStatus`). No live role: the announcer speaks each save's outcome |
|
|
@@ -69,7 +69,7 @@ The tree's stand-in Tab stop, present while the tab-stop row is outside the tree
|
|
|
69
69
|
|
|
70
70
|
| Hook | Element | Meaning |
|
|
71
71
|
| --- | --- | --- |
|
|
72
|
-
| `data-testid="markdown-explorer-document"` | Document region (`role="region"`) | Carries `data-aqmx-document-kind`: `empty`, `loading`, `markdown`, `text`, `image`, `media`, `file` or `failure`. A Markdown document's region also carries `data-aqmx-document-view`: `rendered`, `markup` while it shows as written (the Source toggle), or `edit` while the reader edits
|
|
72
|
+
| `data-testid="markdown-explorer-document"` | Document region (`role="region"`) | Carries `data-aqmx-document-kind`: `empty`, `loading`, `markdown`, `text`, `image`, `media`, `file` or `failure`. A Markdown document's or an SVG image's region also carries `data-aqmx-document-view`: `rendered`, `markup` while it shows as written (the Source toggle; an SVG image's region then holds the text view, its kind staying `image`), or `edit` while the reader edits a Markdown document (the region then fills a maximized panel too). A raster image's region carries none. Named by `documentRegion` in the tree and single views, and in a multi-view panel by the document's name (the last segment of its path before it loads and for a failure). Not focusable: after a click in a document's text, PageDown, the arrow keys, Space, Home and End scroll the document |
|
|
73
73
|
| `data-testid="markdown-explorer-document-empty"` | No document selected | |
|
|
74
74
|
| `data-testid="markdown-explorer-folder-empty"` | The tree view's folder without a README | The region carries `data-aqmx-document-kind="empty"`; a page view announces the text (`folderReadmeMissing`) once for each folder shown |
|
|
75
75
|
| `data-testid="markdown-explorer-folder-failure"` | Failure to list the tree view's folder, or to load the tree it lies in | Carries `data-aqmx-failure` (the reason; `not-found` for no such folder); its callout has no role: the announcer speaks the failure (`documentFailed`, with the folder's name), once for each failed attempt. A `failed` listing offers Try again (`retry`) |
|
|
@@ -85,7 +85,7 @@ The tree's stand-in Tab stop, present while the tab-stop row is outside the tree
|
|
|
85
85
|
| `data-testid="markdown-explorer-edit-skeleton"` | Placeholder while the source for editing (or the editor's chunk) loads | Hidden from assistive technology; the screen-reader text `editLoading` sits beside it |
|
|
86
86
|
| `data-testid="markdown-explorer-edit-grant"` / `-open` / `-retry` | The notice when opening the editor needs a grant, its action (a button with `onEditGrant`, else a link) and Try again | |
|
|
87
87
|
| `data-testid="markdown-explorer-edit-failure"` / `markdown-explorer-edit-load-failure` | Failure to open the source for editing, or to load the editor's chunk | Carry `data-aqmx-failure`; no role (the announcer speaks an opening failure) |
|
|
88
|
-
| `data-testid="markdown-explorer-edit-preview"` | The draft's preview (`role="region"`, named `previewRegion`) | Carries `data-aqmx-preview-tier`: `instant` (the host's draft converter renders drafts in the browser) or `server` (the server renders them: no converter, or a draft the converter cannot render). `aria-busy` until the first rendering lands and while the server renders a newer draft, never for a rendering in the browser; before the first rendering it shows the document's own rendering, or holds `-preview-skeleton` when that is not loaded; holds `-preview-failure` (a notice) after a failed rendering. While the editor shows alone, a preview already mounted keeps rendering and is `inert`: invisible in the editor's place where the surface fills the pane, `hidden` in a panel; the editor is the same while the preview shows alone. Shown alone, a double-click on a word opens the editor at that word |
|
|
88
|
+
| `data-testid="markdown-explorer-edit-preview"` | The draft's preview (`role="region"`, named `previewRegion`) | Carries `data-aqmx-preview-tier`: `instant` (the host's draft converter renders drafts in the browser) or `server` (the server renders them: no converter, or a draft the converter cannot render). `aria-busy` until the first rendering lands and while the server renders a newer draft, never for a rendering in the browser; before the first rendering it shows the document's own rendering (its ```spreadsheets tables editable while the reader has neither changed nor saved the draft, read-only otherwise), or holds `-preview-skeleton` when that is not loaded; holds `-preview-failure` (a notice) after a failed rendering. While the editor shows alone, a preview already mounted keeps rendering and is `inert`: invisible in the editor's place where the surface fills the pane, `hidden` in a panel; the editor is the same while the preview shows alone. Shown alone, a double-click on a word opens the editor at that word |
|
|
89
89
|
| `data-testid="markdown-explorer-image-view"` | Image viewer | |
|
|
90
90
|
| `data-testid="markdown-explorer-image-canvas"` | The image's scroll area | The element that scrolls. In the tree and single views it sits in `@aiquants/markdown`'s HostedScrollArea row (`data-aqmd-scroll-row`, inside its clipping cell `data-aqmd-scroll-clip`), whose bar slot (`data-aqmd-scroll-bar`) holds the explorer's pointer scroll bar; so do a medium's and a file view's stage and the failure view (`data-aqmx-document-scroller`). In a multi-view panel they have no row |
|
|
91
91
|
| `data-testid="markdown-explorer-image"` | The image (`img`) | Carries `data-aqmx-image-mode` (`fit` / `level`) |
|
package/docs/behavior/layout.md
CHANGED
|
@@ -184,19 +184,25 @@ Documents in the multi-panel view sit in `multiView.columns` logical columns (4
|
|
|
184
184
|
The region itself never takes focus, and focus outside the region, focus that was never in it, and focus the reader moved away from it are never taken. The reader moves it away by moving it to an element or into a frame outside the region, or by pressing anywhere outside the region — whenever the press happens, also after the focus had already fallen to the page, and whether or not the press moves the focus — unless the focus stays inside the region (a press whose default action the page prevented).
|
|
185
185
|
Focus that fell from the region to the page while the reader stayed with it (a press on the document's text, the browser's own fragment navigation, the focused content removed, the window losing the focus to another window or application) counts as inside.
|
|
186
186
|
So does focus in a frame inside the region (a PDF document's frame, an embedded frame of `iframeHosts`), also when it entered the frame straight from outside the region (a click from the tree, Tab), and a press outside the region moves it away from there as well.
|
|
187
|
-
- **Source of a Markdown document.** While the bar's document is a loaded Markdown document, the bar's button row holds a Source toggle before Refresh document: a toggle button (`aria-pressed`) labelled like its neighbour — visible text beside a page view's pane (`showMarkupLabel`, «Source» / 「ソース」, its accessible name; its tooltip is `showMarkup
|
|
188
|
-
|
|
187
|
+
- **Source of a Markdown document or an SVG image.** While the bar's document is a loaded Markdown document or SVG image (an image document whose `imageType` is `svg`), the bar's button row holds a Source toggle before Refresh document: a toggle button (`aria-pressed`) labelled like its neighbour — visible text beside a page view's pane (`showMarkupLabel`, «Source» / 「ソース」, its accessible name; its tooltip is `showMarkup`, or `showSvgMarkup` for an SVG image, «Show the image's SVG as written» / 「画像の SVG を書いたまま表示」),
|
|
188
|
+
icon-only in a panel and named after the panel's document (`showMarkupNamed`, «Source of a.md» / 「a.md のソース」).
|
|
189
|
+
A raster image, a media, text or file document and a failure show no toggle, and neither does a document still loading, which gets it once it is there.
|
|
189
190
|
Pressing it shows the document as written instead of rendered, in place and without moving the focus from the toggle: the pane reads the document's file through the data route's `text` operation (only once the toggle is pressed) and shows the text the way it shows a text file — the file header with Copy the text, Open (the whole file as plain text in a new tab) and Download, the note `textTruncated` when the server cut the file at its `textMaxBytes`, and the text, which wraps and is never interpreted.
|
|
190
191
|
Copy the text (an icon button, `copyText`) puts the text on the clipboard exactly as read, line endings included, and is offered only for a text read whole, so a cut file is never copied in part (Download fetches it whole). The outcome is announced (`copiedText`, or `copyTextFailed` when the browser has no asynchronous clipboard — an insecure origin — or refuses the write) and shown for 2 seconds by the button's icon and tooltip, while its accessible name stays the same; a second press counts the 2 seconds again. The same button heads every text file.
|
|
191
192
|
Until the first answer the region shows a skeleton (`markupLoading` for screen readers); a failure shows the failure callout, with Try again for a `failed` read, and is announced once (`documentFailed`), like a document's.
|
|
192
|
-
Every new answer for the document — Refresh document, Refresh tree, a background revalidation — reads the text again, the previous text staying on screen meanwhile. The next press shows the document rendered again.
|
|
193
|
-
The choice is part of the URL (`markup`, see the [URL contract](url-contract.md#shape)), written by replacing the entry: a reload, a shared link and Back and Forward show the document the same way, and the switches between the tree and multi views carry it for the document they open. It belongs to that document only: another document opens rendered, and the document still shown while the next one loads keeps the way it showed. The region tells which way a Markdown document shows with `data-aqmx-document-view` (`rendered` / `markup`).
|
|
193
|
+
Every new answer for the document — Refresh document, Refresh tree, a background revalidation — reads the text again, the previous text staying on screen meanwhile. The next press shows the document rendered again (an SVG image as the image).
|
|
194
|
+
The choice is part of the URL (`markup`, see the [URL contract](url-contract.md#shape)), written by replacing the entry: a reload, a shared link and Back and Forward show the document the same way, and the switches between the tree and multi views carry it for the document they open. It belongs to that document only: another document opens rendered, and the document still shown while the next one loads keeps the way it showed. The region tells which way a Markdown document or an SVG image shows with `data-aqmx-document-view` (`rendered` / `markup`).
|
|
195
|
+
- **Source of an SVG image inside a document.** In a rendered Markdown document — a page view's pane, a panel and the editor's preview alike — every storage SVG image that stands alone in a paragraph (as `@aiquants/markdown`'s viewer picks them: an image the converter wrote with `data-asset-src`, not inside a link or beside text) has a toolbar above it (`viewerSvgImageToolbar`) whose Source toggle (`viewerSvgImageSource`, `aria-pressed`) swaps the image for its SVG as written and back, keeping the focus on the toggle.
|
|
196
|
+
The explorer reads the SVG through the same `text` operation as a document's source, only while the source shows (a read the reader leaves is aborted), so it is refused and admitted exactly as the image itself; the block shows a loading line (`viewerSvgImageLoading`), the text named after the image (`viewerSvgImageSourceRegion`), the note `viewerSvgImageTruncated` under a file cut at `textMaxBytes`, Copy (`viewerSvgImageCopy`, its outcome `viewerSvgImageCopied` or `viewerSvgImageCopyFailed`) for a whole file,
|
|
197
|
+
and a failure (`viewerSvgImageFailed`) with Try again (`viewerSvgImageRetry`) for a `failed` read.
|
|
198
|
+
The choice is the block's own and is not part of the URL: a reload or another document shows the image, while a render that keeps the image's paragraph (a revalidation, the preview's next draft) keeps the choice. A double-click inside the shown SVG selects its text: it never opens the editor of a document the reader may edit, as a double-click on the document's words does (see **Editing a Markdown document** below).
|
|
194
199
|
- **Editing a Markdown document.** The editing surface takes the document's place in the region (`data-aqmx-document-view="edit"`). In a page view and in a maximized panel it fills the pane — in a panel the region then fills the scroll area below the pinned bar — and the editor scrolls itself; in a panel that is not maximized it grows with its text and the panel's scroll area scrolls it.
|
|
195
200
|
The bar's view switch shows the editor alone, the editor and the preview side by side, or the preview alone (`data-aqmx-edit-view`). Side by side, offered where the pane fills, they share one grid, each scrolling itself, in two columns or one above the other on a narrow pane, with a handle between them that resizes them (see [The editor's split](#the-editors-split)).
|
|
196
201
|
Alone, both sit in the grid's one cell: the hidden pane is invisible and inert but keeps its layout and its scroll position, kept in step by the scroll sync below, so switching only changes which pane shows and the block at the top of the view stays the same, by the next frame. The preview is mounted once it was shown or the reader leaned toward it (pointing at or focusing the Preview choice), and keeps rendering while hidden.
|
|
197
202
|
A panel that is not maximized offers the editor and the preview, one at a time: the hidden pane leaves the layout, and switching puts the next pane at the same place on screen, as opening and closing the editor do (the preview's block at the editor's top line, the editor's text at the preview's top block).
|
|
198
203
|
Ctrl+E (⌘E on Apple's platforms, where Ctrl+E stays the editor's move to the line's end) switches between the editor and the preview from the editor, the preview or the view switch — from side by side, to the preview alone — and moves the focus to the pane it shows (the preview's scroller, which then scrolls with the keys; the editor at its cursor), or to the switch's checked choice when pressed there. The preview's scroller is a Tab stop and takes the focus on a click, so after a click in the preview the keys scroll it and Ctrl+E reaches it.
|
|
199
|
-
A
|
|
204
|
+
A ```spreadsheets table shown full screen keeps its keys: Ctrl+E does nothing behind it, and Escape leaves full screen (the editing goes on).
|
|
205
|
+
A double-click on a word of the preview shown alone opens the editor with the cursor on that word, at the same place on screen, except inside an editable table (every table with source lines in the preview) or a table shown full screen, where a double-click edits a cell; a read-only table of the rendered document opens the editor like any other block. Where the bar is narrower than the width from which the side-by-side surface has two columns (a phone; see [The editor's split](#the-editors-split)), the view switch drops its words and keeps its 44 px targets.
|
|
200
206
|
A draft session (a document edited without saving) has the same surface and view switch; its bar shows the draft's status without Save or History.
|
|
201
207
|
Places on screen are kept through the converter's source lines, text matched to text (the top of a word's or a block's first glyphs, since the rendered prose and the editor have different line heights): Edit puts the block at the top of the reader's view, and a double-click the word, exactly where it was; closing puts the editor's top line — the first non-empty one in view — back at the same place in the rendered document, and again on the fresh copy a save made the pane read, unless the reader scrolled, pressed a key or a pointer meanwhile;
|
|
202
208
|
the editor and the preview scroll together, both ways, through a map of the blocks that carry source lines: the top of a block's first line goes with the top of its box and the bottom of its last line with the bottom of its box, positions in between are linear, both tops go together and both bottoms together, and a block whose place differs between the source and the rendering (a footnote, rendered at the end) is left out, so either pane moves continuously and on whenever the other does, crossing a block taller on its side faster.
|
|
@@ -7,13 +7,15 @@ This page is part of the host-facing contract of `@aiquants/markdown-explorer`;
|
|
|
7
7
|
- `locale` is the UI language, `"en"` (the default) or `"ja"` — never a BCP 47 region tag. `"ja-JP"`, `"EN"` and any other value throw a `RangeError` on the first render, so a mistyped locale is found in development instead of silently showing English.
|
|
8
8
|
- The catalogs are `MARKDOWN_EXPLORER_LABEL_CATALOGS.en` and `MARKDOWN_EXPLORER_LABEL_CATALOGS.ja`, frozen objects with the same keys; `MARKDOWN_EXPLORER_LABEL_KEYS` lists the keys in declaration order.
|
|
9
9
|
- The explorer passes its document-viewer strings to `@aiquants/markdown`, which names every control and status text of the viewer with them, so the viewer follows the same language:
|
|
10
|
-
its status texts (`viewerLoading`, `viewerErrorPrefix`, `viewerErrorTitle`, `viewerMissingImage`), its toolbar's buttons (`viewerSelectAlign`, `viewerSelectStyle`, `viewerOpenToc`), the alignment and style menus (`viewerAlignTitle`, `viewerAlignLeft`, `viewerAlignCenter`, `viewerAlignRight`, `viewerPinAlign`, `viewerUnpinAlign`, `viewerStyleTitle`, `viewerPinStyle`, `viewerUnpinStyle`), the table of contents (`viewerTocTitle`, which also names its navigation, `viewerPinToc`, `viewerUnpinToc`)
|
|
10
|
+
its status texts (`viewerLoading`, `viewerErrorPrefix`, `viewerErrorTitle`, `viewerMissingImage`, and `viewerBlockFailed`, the notice in place of a block that cannot render), its toolbar's buttons (`viewerSelectAlign`, `viewerSelectStyle`, `viewerOpenToc`), the alignment and style menus (`viewerAlignTitle`, `viewerAlignLeft`, `viewerAlignCenter`, `viewerAlignRight`, `viewerPinAlign`, `viewerUnpinAlign`, `viewerStyleTitle`, `viewerPinStyle`, `viewerUnpinStyle`), the table of contents (`viewerTocTitle`, which also names its navigation, `viewerPinToc`, `viewerUnpinToc`)
|
|
11
11
|
and every Mermaid diagram's controls (`viewerMermaidInteractionMode` for the mouse-interaction menu and its button, `viewerMermaidModeNone`, `viewerMermaidModeZoom`, `viewerMermaidModePan`, `viewerMermaidModePanShift`, `viewerMermaidModeBoth`, `viewerMermaidModeBothShift` for its modes, `viewerMermaidInteractionModeTouch` for the same menu and button under a coarse pointer, `viewerMermaidModeNoneTouch`, `viewerMermaidModeZoomTouch`, `viewerMermaidModePanTouch`, `viewerMermaidModeBothTouch` for its touch items, `viewerMermaidZoomIn`, `viewerMermaidZoomOut`, `viewerMermaidResetView`,
|
|
12
12
|
`viewerMermaidPanUp`, `viewerMermaidPanDown`, `viewerMermaidPanLeft`, `viewerMermaidPanRight` for the buttons that move the view while the drawing overflows its frame, `viewerMermaidRetry`, and `viewerMermaidDiagram`, the name of the diagram's focusable frame),
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
the toolbar of a storage SVG image that stands alone in a paragraph (`viewerSvgImageToolbar` naming the toolbar, `viewerSvgImageSource` its Source toggle, `viewerSvgImageSourceRegion` the shown SVG, `viewerSvgImageLoading`, `viewerSvgImageFailed` and `viewerSvgImageRetry` while it is read, `viewerSvgImageTruncated` under a file cut at `textMaxBytes`, and `viewerSvgImageCopy`, `viewerSvgImageCopied` and `viewerSvgImageCopyFailed` for its Copy button and its outcomes)
|
|
14
|
+
and the titles of embedded frames (`viewerEmbeddedVideo` and `viewerEmbeddedPost` after a provider's name, as in "YouTube: embedded video", and `viewerEmbeddedFrame` before the host of an iframe written in a document without a title).
|
|
15
|
+
A label the viewer receives carries no `lang` of its own, so it is read in the page's language.
|
|
16
|
+
- Every ```spreadsheets table's labels are `@aiquants/markdown`'s own, derived rather than copied: each label of its table block (`SPREADSHEET_BLOCK_LABEL_CATALOGS` of `@aiquants/markdown/code-blocks`, see its README) is a key prefixed with `viewerSpreadsheet` (`zoomIn` → `viewerSpreadsheetZoomIn`, `cellAnnouncement` → `viewerSpreadsheetCellAnnouncement`), its built-in text is the block's catalog of the UI language, and its placeholders are the block's (`SPREADSHEET_BLOCK_LABEL_PLACEHOLDERS`).
|
|
17
|
+
The explorer passes the viewer only the table labels a host replaced, so every other one keeps the block's text marked with the block's language, and the grid takes `locale` as its own locale, which picks the language of its own catalog, its data-validation messages and its scroll bar.
|
|
18
|
+
A label added to the block becomes a key of the explorer with it. Where the viewer's own built-in label is in a catalog's language, the catalog repeats it word for word (the English catalog the viewer's English labels, such as `Display Style` and `Zoom In`; the Japanese catalog its Japanese ones, such as `目次を開く`), writing a full-width form in half-width (`拡大縮小+移動 (左ドラッグ)` for the viewer's `拡大縮小+移動 (左ドラッグ)`).
|
|
17
19
|
- The explorer passes `treeEntryKindDirectory` and `treeEntryKindFile` (the kind words in the rows' accessible names) and `treeScrollUp`, `treeScrollDown`, `treeScrollToTop` and `treeScrollToBottom` (the tree's scroll bar) to `@aiquants/directory-tree`.
|
|
18
20
|
- The explorer passes every string the multi view's drag-and-drop layout shows to `@aiquants/drag-drop-panels`: the panel headers' buttons (`panelMove`, `panelSwitchToCustomDrag`, `panelSwitchToNormalDrag`, `panelHide`, `panelMaximize`, `panelRestore`, `panelClose`), the items of their move menus (`panelMovePreviousColumn`, `panelMoveNextColumn`, `panelMoveUp`, `panelMoveDown`) and the custom drag mode's badge (`panelCustomDragBadge`),
|
|
19
21
|
the move announcements (`panelMoved`, `panelMoveUnavailable`), a touch or pen drag's lift and cancel announcements (`panelDragStarted`, `panelDragCancelled`), the bar of hidden panels (`hiddenPanelsTitle`)
|
|
@@ -22,7 +24,7 @@ This page is part of the host-facing contract of `@aiquants/markdown-explorer`;
|
|
|
22
24
|
- `treeRegion` names the tree itself, apart from `explorerRegion`, which names the explorer's landmark (and the sheet on narrow frames).
|
|
23
25
|
- `refreshTreeLabel` is the visible text of the explorer's Refresh tree button and `refreshDocumentLabel` that of the page views' (tree and single) Refresh document button, each also its button's accessible name; `refreshTree` and `refreshDocument` are their tooltips.
|
|
24
26
|
A multi-view panel's Refresh document is icon-only, and `refreshDocumentNamed(name)` (the panel title) is its accessible name and its tooltip. A successful reload is announced with `treeRefreshed` or `documentRefreshed(name)`. A failed one is shown with `treeRefreshFailed(reason)` (an alert in the explorer) or `documentRefreshFailed(reason)` (a notice, which the announcer also speaks), where `reason` is the failure's title (the matching `failure…Title` label).
|
|
25
|
-
- `showMarkupLabel` is the visible text of the page views' Source toggle beside Refresh document (shown for a Markdown document), also its accessible name, and `showMarkup` its tooltip; a multi-view panel's toggle is icon-only, and `showMarkupNamed(name)` (the panel title) is its accessible name and its tooltip.
|
|
27
|
+
- `showMarkupLabel` is the visible text of the page views' Source toggle beside Refresh document (shown for a Markdown document and an SVG image), also its accessible name, and `showMarkup` its tooltip (`showSvgMarkup` for an SVG image); a multi-view panel's toggle is icon-only, and `showMarkupNamed(name)` (the panel title) is its accessible name and its tooltip.
|
|
26
28
|
The toggle's pressed state, not its name, tells whether the source shows. `markupLoading` is the screen-reader text while the source loads; a source that cannot be read is announced with `documentFailed(name, title)`, like a document, and a cut source shows `textTruncated`, like a cut text file.
|
|
27
29
|
- `copyText` is the accessible name and tooltip of the icon-only Copy the text button in the header of a text read whole (a text file, or a Markdown document shown as written). A copy is announced with `copiedText`, or with `copyTextFailed` when the browser has no asynchronous clipboard or refuses the write; for 2 seconds the outcome's label is also the button's tooltip, while its name stays `copyText`.
|
|
28
30
|
- `switchToTree` and `switchToMulti` name their destination with the README's view names ("Open in the tree view" / "ツリービューで開く", "Open in the multi-panel view" / "マルチビューで開く"); no label names the single view, which no control inside the explorer opens.
|
|
@@ -47,7 +49,7 @@ const HANDBOOK_LABELS = {
|
|
|
47
49
|
the path's last segment and the failure's title — the text of the matching `failure…Title` label, not the reason's code), `imageZoomLevel(percent)`, `treeRefreshFailed(reason)`, `documentRefreshed(name)`, `documentRefreshFailed(reason)`, `refreshDocumentNamed(name)` (a multi-view panel's icon-only Refresh document: its accessible name and tooltip, `name` being the panel title),
|
|
48
50
|
`showMarkupNamed(name)` (a multi-view panel's icon-only Source toggle: its accessible name and tooltip, `name` being the panel title), `panelLimit(max)`, `panelOpened(name)`, `panelClosed(name)`, `panelAlreadyOpen(name)`, `panelHidden(name)`, `panelShown(name)`, `panelMaximized(name)`, `panelRestored(name)` — so each language can place the value where its grammar needs it.
|
|
49
51
|
- The labels `@aiquants/drag-drop-panels` fills itself are templates instead, strings whose `{name}` placeholders mark where each value goes: `panelMoved` (`{title}` the panel's name, `{column}` its visible column, `{position}` its place among that column's shown panels), `panelMoveUnavailable` (`{title}`, and `{move}` the name of the move, one of the `panelMove…` labels), `panelDragStarted` and `panelDragCancelled` (`{title}`) and `multiColumnRegion` (`{column}`); columns and positions count from 1.
|
|
50
|
-
So are the table labels `@aiquants/markdown` fills
|
|
52
|
+
So are the table labels `@aiquants/markdown` fills, with the block's placeholders (`viewerSpreadsheetSize` with `{rows}` and `{cols}`, `viewerSpreadsheetCellAnnouncement` with `{cell}` and `{value}`, and so on; `SPREADSHEET_BLOCK_LABEL_PLACEHOLDERS` lists them), and `viewerSvgImageSourceRegion`, whose `{name}` is the SVG image's name (its alternative text, else its file name).
|
|
51
53
|
`MARKDOWN_EXPLORER_LABEL_TEMPLATES` lists each template's placeholders, and braces in every other label are literal text.
|
|
52
54
|
- `labels` must be a plain object. An unknown key throws a `RangeError` that lists the valid keys, a value of the wrong type (a string where a function is expected, or the reverse) throws a `TypeError`, and a blank string throws a `RangeError`, because a blank name is neither shown nor announced. A template that uses a placeholder its key does not offer (`{name}` for `{title}`, say) throws a `RangeError` naming the placeholders it accepts, because a placeholder that is never filled would be read out as it is. A key set to `undefined` keeps the catalog's string.
|
|
53
55
|
- The overrides are compared by value, key by key: writing `labels={{ … }}` inline does not re-render the explorer on every render of the host, but a function created inline is a new value each time — hoist it, or memoize the object.
|
|
@@ -29,7 +29,7 @@ The explorer renders documents that the reader did not write, from storage the r
|
|
|
29
29
|
- A `contains` that throws or answers anything but a boolean is logged (operation `boundary`) and counts as outside (a promise it answers is not awaited, and its rejection is logged the same way); a malformed `confirm` answer is logged and counts as outside; a `readPath` that is not an acceptable document path or that the deny rules refuse is logged and answered `failed`. A broken boundary therefore never opens a document.
|
|
30
30
|
- The union is exactly what the deployment exposes: a source whose boundary admits every document a reader can read in a store opens every such document through every view, link and asset URL, so documents of that store are confined only when every source over it has a confined boundary.
|
|
31
31
|
- The bytes of a file take exactly the document admission: an `asset` request passes the deny rules (a refusal is logged once with the operation `asset`), then the same union of boundaries and confirmations, and the host's `asset` receives the admitting source's `readPath`. A boundary miss answers 403 without a log, since an embedded image outside every source is ordinary.
|
|
32
|
-
- The text of a file takes the same admission: a `text` request passes the deny rules (a refusal is logged once with the operation `text`, since the explorer asks it only for a document it rendered), then the same union of boundaries and confirmations, and the host's `asset` receives the admitting source's `readPath`; a boundary miss is answered `forbidden` without a log.
|
|
32
|
+
- The text of a file takes the same admission: a `text` request passes the deny rules (a refusal is logged once with the operation `text`, since the explorer asks it only for a document it rendered — a Markdown document or an SVG image, for the document bar's Source toggle — and for a storage SVG image such a document shows, for the image's own Source toggle, whose bytes the `asset` operation serves under the same rules), then the same union of boundaries and confirmations, and the host's `asset` receives the admitting source's `readPath`; a boundary miss is answered `forbidden` without a log.
|
|
33
33
|
It serves nothing the `asset` operation does not already serve the same reader: the beginning of that file's bytes, at most `textMaxBytes`, decoded as UTF-8 and escaped as a JSON string, which the browser shows as text and never interprets.
|
|
34
34
|
|
|
35
35
|
## HTML
|
|
@@ -13,8 +13,8 @@ This page is part of the host-facing contract of `@aiquants/markdown-explorer`;
|
|
|
13
13
|
- `basePath` and the view slugs come from `defineExplorerConfig` (`tree`, `multi` and `single` by default). The data route lives at `dataPath` and is not a page.
|
|
14
14
|
- `source` names the source shown in the tree: one of the server's sources, whose ids come from `createMarkdownExplorer`'s `sources` in their order (the browser reads them from the page data's `sources`). The first is the default and is written by **omission**; it is never written explicitly. A source id is lowercase letters, digits and `-`, starting with a letter or digit (`isExplorerSourceId`).
|
|
15
15
|
- The tree view shows a document, a folder (its README, see [Folder segment](#folder-segment)) or neither: `ExplorerLocation`'s tree view has `doc` and `folder`, at most one of them not `null`.
|
|
16
|
-
- `markup` names the Markdown documents shown as written (their source
|
|
17
|
-
`ExplorerLocation`'s `markup` is a boolean in the tree and single views (always `false` in the tree view without a document or a folder) and a list in the multi-panel view; a target without it (`ExplorerHrefTarget`) shows every document rendered. A document that is
|
|
16
|
+
- `markup` names the Markdown documents and SVG images shown as written (their source — an SVG image's own SVG —, the document bar's Source toggle) instead of rendered: in the tree and single views `markup=true` for the URL's document — in the tree view a folder's README too —, and in the multi-panel view one `markup` per open document shown that way, in the order of `doc` (a maximized document included).
|
|
17
|
+
`ExplorerLocation`'s `markup` is a boolean in the tree and single views (always `false` in the tree view without a document or a folder) and a list in the multi-panel view; a target without it (`ExplorerHrefTarget`) shows every document rendered. A document that is neither Markdown nor an SVG image (a raster image, media, text, a file or a failure) ignores it and shows as it always does. The Source toggle of an SVG image inside a rendered document is the image block's own and never enters the URL.
|
|
18
18
|
- The source never limits which documents can be open: a path names one document; it may appear in several sources' trees, and it opens when the boundary of at least one source admits it, whichever source the URL names. Switching the source therefore keeps every open document, and a document no source's boundary admits is answered `forbidden` in every view.
|
|
19
19
|
- `explorerHref(config, target)` is the only function that writes explorer URLs, and `resolveExplorerLocation(config, splat, search)` is the only one that reads them. The server's loader and the browser call the same two functions, each with a configuration joined with the server's source ids by `withExplorerSources(config, sourceIds)` (an `ExplorerLocationConfig`; no ids, an invalid id or a repeated one throws a `RangeError`).
|
|
20
20
|
`explorerHref` has two forms: any target with such a configuration, and a target without `source` (`ExplorerSourcelessHrefTarget`, the default source) with a plain `ExplorerConfig`, for links built where the server's sources are not known (a host menu). A target with a `source` and a configuration without ids throws a `TypeError` naming `withExplorerSources`, and so does `resolveExplorerLocation` given such a configuration.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiquants/markdown-explorer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.0",
|
|
4
4
|
"description": "Markdown document explorer for React Router 8 (framework mode): a source tree with a single-document view and a multi-panel reading view, storage-agnostic server ports, golden-ratio layout and an en / ja UI.",
|
|
5
5
|
"sideEffects": [
|
|
6
6
|
"**/*.css"
|
|
@@ -70,9 +70,9 @@
|
|
|
70
70
|
"peerDependencies": {
|
|
71
71
|
"@aiquants/directory-tree": "^5.0.1",
|
|
72
72
|
"@aiquants/drag-drop-panels": "^0.12.0",
|
|
73
|
-
"@aiquants/markdown": "^
|
|
73
|
+
"@aiquants/markdown": "^11.1.0",
|
|
74
74
|
"@aiquants/resize-panels": "^2.2.0",
|
|
75
|
-
"@aiquants/spreadsheet": "^0.
|
|
75
|
+
"@aiquants/spreadsheet": "^0.16.0",
|
|
76
76
|
"@aiquants/virtualscroll": "^3.22.1",
|
|
77
77
|
"react": "^19.2.7",
|
|
78
78
|
"react-dom": "^19.2.7",
|
|
@@ -81,9 +81,9 @@
|
|
|
81
81
|
"devDependencies": {
|
|
82
82
|
"@aiquants/directory-tree": "5.0.1",
|
|
83
83
|
"@aiquants/drag-drop-panels": "0.12.0",
|
|
84
|
-
"@aiquants/markdown": "
|
|
84
|
+
"@aiquants/markdown": "11.1.0",
|
|
85
85
|
"@aiquants/resize-panels": "2.2.0",
|
|
86
|
-
"@aiquants/spreadsheet": "0.
|
|
86
|
+
"@aiquants/spreadsheet": "0.16.0",
|
|
87
87
|
"@aiquants/virtualscroll": "3.22.1",
|
|
88
88
|
"@heroicons/react": "^2.2.0",
|
|
89
89
|
"@playwright/test": "^1.59.1",
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const L=require("react/jsx-runtime"),h=require("react"),y=require("./index-bMaSoQTe.cjs"),G=require("@codemirror/commands"),de=require("@codemirror/lang-markdown"),le=require("@codemirror/language"),fe=require("@codemirror/search"),X=require("@codemirror/state"),P=require("@codemirror/view"),N=require("@lezer/highlight"),De=require("@aiquants/markdown"),se=require("@aiquants/markdown/source-lines"),Q=require("./dataRoute-BONacTPi.cjs"),ie=require("./sanitizePolicy-gEXeavb-.cjs"),Ve=require("isomorphic-dompurify"),te=require("@aiquants/resize-panels"),U=require("./location-BVEN_Ihk.cjs"),me=require("./useSplitPersistence-Ba-v64n-.cjs"),Re={history:G.historyField},Be=le.HighlightStyle.define([{tag:[N.tags.heading1,N.tags.heading2,N.tags.heading3,N.tags.heading4,N.tags.heading5,N.tags.heading6,N.tags.heading],color:"var(--aqmx-syntax-heading)",fontWeight:"700"},{tag:N.tags.strong,fontWeight:"700"},{tag:N.tags.emphasis,fontStyle:"italic"},{tag:N.tags.strikethrough,textDecoration:"line-through"},{tag:N.tags.link,color:"var(--aqmx-syntax-link)",textDecoration:"underline"},{tag:N.tags.url,color:"var(--aqmx-syntax-url)"},{tag:N.tags.monospace,color:"var(--aqmx-syntax-code)"},{tag:N.tags.quote,color:"var(--aqmx-syntax-quote)"},{tag:[N.tags.processingInstruction,N.tags.contentSeparator,N.tags.labelName,N.tags.meta],color:"var(--aqmx-syntax-mark)"}]),He=P.EditorView.theme({"&":{height:"100%",color:"var(--aqmx-text)",backgroundColor:"var(--aqmx-surface)",fontSize:"var(--aqmx-font-size-title)"},"&.cm-focused":{outline:"none"},".cm-scroller":{fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace',lineHeight:"var(--aqmx-line-height-prose)"},".cm-content":{caretColor:"var(--aqmx-text)",paddingBlock:"var(--aqmx-space-6)"},".cm-line":{paddingInline:"var(--aqmx-space-6)"},"&.cm-focused .cm-cursor":{borderLeftColor:"var(--aqmx-text)"},"&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection":{backgroundColor:"var(--aqmx-editor-selection)"},".cm-activeLine":{backgroundColor:"var(--aqmx-editor-active-line)"},".cm-gutters":{backgroundColor:"var(--aqmx-surface-raised)",color:"var(--aqmx-editor-gutter)",borderInlineEnd:"var(--aqmx-space-1) solid var(--aqmx-border)"},".cm-activeLineGutter":{backgroundColor:"var(--aqmx-editor-active-line)"},".cm-searchMatch":{outline:"var(--aqmx-space-1) solid var(--aqmx-border-strong)"},".cm-panels":{backgroundColor:"var(--aqmx-surface-raised)",color:"var(--aqmx-text)"}}),Oe="data-aqmx-conflict-actions",je=P.Decoration.line({attributes:{"data-aqmx-conflict-line":"marker"}}),ze=P.Decoration.line({attributes:{"data-aqmx-conflict-line":"ours"}}),Fe=P.Decoration.line({attributes:{"data-aqmx-conflict-line":"theirs"}});class We extends P.WidgetType{constructor(t,n){super(),this.index=t,this.labels=n}index;labels;eq(t){return t.index===this.index&&t.labels===this.labels}toDOM(t){const n=document.createElement("div");n.setAttribute(Oe,String(this.index));for(const[r,a]of[["ours",this.labels.useOurs],["theirs",this.labels.useTheirs],["both",this.labels.keepBoth]]){const s=document.createElement("button");s.type="button",s.textContent=a,s.setAttribute("data-aqmx-conflict-choice",r),s.addEventListener("mousedown",c=>c.preventDefault()),s.addEventListener("click",()=>{const c=ee(t.state.doc)[this.index];c!==void 0&&(qe(t,c,r),t.focus())}),n.append(s)}return n}ignoreEvent(){return!0}}const ee=e=>y.findConflictsInLines(e.iterLines()),pe=(e,t)=>{const n=new X.RangeSetBuilder;return ee(e).forEach((r,a)=>{const s=e.line(r.start);n.add(s.from,s.from,P.Decoration.widget({widget:new We(a,t),block:!0,side:-1}));for(let c=r.start;c<=r.end;c+=1){const o=e.line(c).from,f=c===r.start||c===r.separator||c===r.end?je:c<r.separator?ze:Fe;n.add(o,o,f)}}),n.finish()},Ue=e=>X.StateField.define({create:t=>pe(t.doc,e),update:(t,n)=>n.docChanged?pe(n.state.doc,e):t,provide:t=>P.EditorView.decorations.from(t)}),qe=(e,t,n)=>{const{doc:r}=e.state,a=(i,x)=>{const l=[];for(let u=i;u<=x;u+=1)l.push(r.line(u).text);return l},s=a(t.start+1,t.separator-1),c=a(t.separator+1,t.end-1),o=n==="ours"?s:n==="theirs"?c:[...s,...c];let f=r.line(t.start).from,d=r.line(t.end).to;o.length===0&&(t.end<r.lines?d+=1:t.start>1&&(f-=1));const m=o.join(`
|
|
2
|
-
`);e.dispatch({changes:{from:f,to:d,insert:m},selection:X.EditorSelection.cursor(f),scrollIntoView:!0,userEvent:"input.resolve"})},he="input.preview",$e=500,Ge=/^([ >+*\-.)\d]*?)(?:`{3}|~{3})/u,Ke=/^(?:[-+*]|\d{1,9}[.)])(?= )/u,Ie=/^[ \t]*$/u,Xe=e=>{let t="",n=0;for(;n<e.length;){const r=e.slice(n);if(r.startsWith(">"))t+="> ",n+=r.startsWith("> ")?2:1;else if(r.startsWith(" "))t+=" ",n+=1;else{const a=Ke.exec(r)?.[0];if(a===void 0)return null;t+=" ".repeat(a.length),n+=a.length}}return t},Ye=(e,t,n)=>{if(e.startsWith(t)){const r=e.slice(t.length);return n&&Ie.test(r)?"":r}return t.startsWith(e)&&e.length>=t.trimEnd().length?"":null},Je=(e,t,n)=>e.split(`
|
|
3
|
-
`).map((r,a,s)=>a===s.length-1&&r===""?"":(n?Ie.test(r):r==="")?t.trimEnd():`${t}${r}`).join(`
|
|
4
|
-
`),Qe=(e,t,n)=>{const{doc:r}=e;if(!Number.isInteger(t)||t<1||t>r.lines)return null;const a=r.line(t),s=Ge.exec(a.text)?.[1],c=s===void 0?null:Xe(s);if(s===void 0||c===null)return null;const o=Math.min(r.lines,t+n.split(`
|
|
5
|
-
`).length+1),f=le.ensureSyntaxTree(e,r.line(o).to,$e);if(f===null)return null;const d=f.resolveInner(a.from+s.length,1),m=d.parent;if(d.name!=="CodeMark"||m===null||m.name!=="FencedCode"||m.from!==d.from)return null;const[,...i]=m.getChildren("CodeMark"),x=i.at(-1),l=x===void 0?r.lineAt(m.to).number:r.lineAt(x.from).number-1;let u=m.parent;for(;u!==null&&u.name!=="ListItem"&&u.name!=="Blockquote";)u=u.parent;const g=u?.name==="ListItem";let w="";for(let b=t+1;b<=l;b+=1){const A=Ye(r.line(b).text,c,g);if(A===null)return null;w+=b<r.lines?`${A}
|
|
6
|
-
`:A}if(w!==n)return null;if(l>t){const b=l<r.lines?r.line(l+1).from:r.length;return{from:r.line(t+1).from,to:b,prefix:c,whiteSpaceLinesEmpty:g,lineBreak:!1}}if(t===r.lines)return{from:r.length,to:r.length,prefix:c,whiteSpaceLinesEmpty:g,lineBreak:!0};const p=r.line(t+1).from;return{from:p,to:p,prefix:c,whiteSpaceLinesEmpty:g,lineBreak:!1}},Ze=({parent:e,scroll:t,text:n,saved:r,labels:a,onChange:s,onGeometry:c,onSave:o})=>{let f=!1;const d=[P.EditorView.scrollHandler.of((l,u,g)=>(et(l,u.head,g,t),!0)),P.lineNumbers(),P.highlightActiveLineGutter(),G.history(),P.drawSelection(),P.highlightActiveLine(),fe.highlightSelectionMatches(),P.EditorView.lineWrapping,de.markdown({base:de.markdownLanguage}),le.syntaxHighlighting(Be),Ue(a),P.keymap.of([{key:"Mod-s",preventDefault:!0,run:()=>(o(),!0)},...fe.searchKeymap,...G.historyKeymap,...G.defaultKeymap]),P.EditorView.contentAttributes.of({"aria-label":a.editor,"aria-multiline":"true"}),P.EditorView.updateListener.of(l=>{l.docChanged&&s(l.transactions.every(u=>!u.docChanged||u.isUserEvent(he))),(l.docChanged||l.heightChanged||l.geometryChanged)&&c(l.docChanged&&!f)}),He],m=rt(r,d)??X.EditorState.create({doc:n,extensions:d}),i=new P.EditorView({state:m,parent:e}),x=l=>{f=!0;try{l()}finally{f=!1}};return{text:()=>i.state.doc.toString(),replaceText:l=>{const u=i.state.doc.toString();if(u===l)return;let g=0;const w=Math.min(u.length,l.length);for(;g<w&&u.charCodeAt(g)===l.charCodeAt(g);)g+=1;let p=0;for(;p<w-g&&u.charCodeAt(u.length-1-p)===l.charCodeAt(l.length-1-p);)p+=1;i.dispatch({changes:{from:g,to:u.length-p,insert:l.slice(g,l.length-p)},userEvent:"input.replace"})},replaceBody:(l,u,g)=>{const w=Qe(i.state,l,u);if(w===null)return!1;const p=Je(g,w.prefix,w.whiteSpaceLinesEmpty),b=w.lineBreak?`
|
|
7
|
-
${p}`:p;return x(()=>i.dispatch({changes:{from:w.from,to:w.to,insert:b},userEvent:he,annotations:G.isolateHistory.of("full")})),!0},undo:()=>x(()=>G.undo(i)),redo:()=>x(()=>G.redo(i)),reveal:({line:l,column:u},g)=>{const{doc:w}=i.state,p=w.line(Math.min(Math.max(l,1),w.lines)),b=Math.min(p.from+u,p.to);i.dispatch({selection:X.EditorSelection.cursor(b),effects:ge(i,b,g,t)})},showLine:l=>{const{doc:u}=i.state,g=u.line(Math.min(Math.max(l,1),u.lines)).from;i.dispatch({effects:ge(i,g,null,t)})},topLine:()=>{const l=t.scrollerOf(i.scrollDOM),u=y.visibleTopOf(l,i.contentDOM),g=y.frameTopOf(l)+l.clientHeight,{documentTop:w}=i,{doc:p}=i.state;let b=i.lineBlockAtHeight(Math.max(u-w,0));for(;p.lineAt(b.from).text.trim()===""&&b.to<p.length;){const D=i.lineBlockAt(b.to+1);if(w+D.top>=g)break;b=D}const A=i.coordsAtPos(b.from),C=A===null?w+b.top:A.top;return{line:i.state.doc.lineAt(b.from).number,clientTop:C,offset:C-u}},lineSpans:l=>{const u=i.scrollDOM,g=u.scrollTop+i.documentTop-y.visibleTopOf(u,i.contentDOM),{doc:w}=i.state,p=b=>w.line(Math.min(Math.max(b,1),w.lines)).from;return l.map(({first:b,last:A})=>({top:g+i.lineBlockAt(p(b)).top,bottom:g+i.lineBlockAt(p(A)).bottom}))},scrollElement:i.scrollDOM,focus:()=>i.focus(),conflicts:()=>ee(i.state.doc),resolveAtCursor:l=>{const u=ee(i.state.doc),g=i.state.doc.lineAt(i.state.selection.main.head).number,w=u.find(p=>p.end>=g);return w===void 0?!1:(qe(i,w,l),!0)},nextConflict:()=>{const l=ee(i.state.doc);if(l[0]===void 0)return!1;const g=i.state.doc.lineAt(i.state.selection.main.head).number,w=l.findIndex(C=>C.start>g),p=w<0?0:w,b=i.state.doc.line(l[p].start).from;i.dispatch({selection:X.EditorSelection.cursor(b),effects:P.EditorView.scrollIntoView(b,{y:"center"})});const A=i.contentDOM.querySelector(`[${Oe}="${String(p)}"] button`);return A instanceof HTMLElement?A.focus({preventScroll:!0}):i.focus(),!0},save:()=>i.state.toJSON(Re),destroy:()=>i.destroy()}},ge=(e,t,n,r)=>{const a=r.scrollerOf(e.scrollDOM),s=(n===null?y.visibleTopOf(a,e.contentDOM):n)-y.frameTopOf(a);return P.EditorView.scrollIntoView(t,{y:"start",yMargin:s})},et=(e,t,n,r)=>{const a=tt(e,t),s=r.scrollerOf(e.scrollDOM),c=y.frameTopOf(s),o=y.visibleTopOf(s,e.contentDOM),f=c+s.clientHeight;let d=0;switch(n.y){case"start":d=a.top-(c+n.yMargin);break;case"center":d=(a.top+a.bottom)/2-(o+f)/2;break;case"end":d=a.bottom-(f-n.yMargin);break;default:a.top<o+n.yMargin?d=a.top-(o+n.yMargin):a.bottom>f-n.yMargin&&(d=Math.min(a.bottom-(f-n.yMargin),a.top-(o+n.yMargin)))}if(d!==0&&(s.scrollTop+=d),n.y==="start")return;const m=nt(e,t);m!==null&&r.reveal(m)},tt=(e,t)=>{const{node:n,offset:r}=e.domAtPos(t);if(n.nodeType===Node.TEXT_NODE){const c=n.ownerDocument?.createRange();if(c!==void 0){c.setStart(n,r),c.setEnd(n,r);const[o]=c.getClientRects();if(o!==void 0&&o.height>0)return{top:o.top,bottom:o.bottom}}}const a=e.lineBlockAt(t),s=e.documentTop+a.top;return{top:s,bottom:s+a.height}},nt=(e,t)=>{const{node:n}=e.domAtPos(t);for(let r=n instanceof Element?n:n.parentElement;r!==null;r=r.parentElement)if(r.parentElement===e.contentDOM)return r;return null},rt=(e,t)=>{if(e==null)return null;try{return X.EditorState.fromJSON(e,{extensions:t},Re)}catch{return null}},ot=610,st=987,ve=Object.freeze({kind:"unavailable"}),it="true",lt="false",at=e=>e===it?!0:e===lt?!1:null,ct=e=>{const t=new DOMParser().parseFromString(e,"text/html"),n=[];for(const r of t.querySelectorAll("img[data-asset-src], a[data-doc-path]")){const a=r.localName==="img",s=r.getAttribute(a?"data-asset-src":"data-doc-path");s!==null&&n.push({target:{kind:a?"asset":"doc",path:s},exists:at(r.getAttribute(a?"data-asset-exists":"data-doc-exists"))})}return n},ut=({path:e,instant:t,preview:n,initial:r,onView:a})=>{const s=new AbortController,c={asset:new Map,doc:new Map};let o=r,f=null,d=!1,m=!1,i=null,x=null,l=[],u,g=!1,w,p=null;const b=T=>{T.parsed===o.parsed&&T.failure===o.failure&&T.busy===o.busy&&T.tier===o.tier||(o=T,a(T))},A=(T,k)=>{d||(d=!0,console.error(`[markdown-explorer] ${T}`,...k===void 0?[]:[k]))},C=T=>{if(t!==null)for(const{target:k,exists:O}of t.marksOf(T))c[k.kind].set(k.path,O)},D=()=>{clearTimeout(w),w=void 0,p?.abort(),p=null},j=()=>{x=null,l=[],clearTimeout(u),u=void 0},B=(T,k)=>{b({parsed:o.parsed,failure:T,busy:!1,tier:k})},W=()=>{clearTimeout(u),u=l.length===0?void 0:setTimeout(R,st)},S=()=>{if(t===null||x===null)return;const T=x,k=[],O={asset:new Set,doc:new Set};let E;try{E=t.sanitize(T.html,q=>{const H=c[q.kind].get(q.path);return H===void 0&&!O[q.kind].has(q.path)&&(O[q.kind].add(q.path),k.push(q)),H??void 0})}catch(q){j(),q instanceof ie.HtmlNestingLimitError?B(Q.failureOf("too-large"),"instant"):(A("the draft sanitizer failed",q),B(Q.failureOf("failed"),"instant"));return}l=k;const I=o.parsed!==null&&o.parsed.htmlContent===E&&o.parsed.headings===T.headings?o.parsed:{htmlContent:E,headings:T.headings};b({parsed:I,failure:null,busy:!1,tier:"instant"}),W()},R=()=>{if(u=void 0,g||x===null||l.length===0)return;g=!0;const T=l;n(e,x.text,s.signal).then(k=>{if(g=!1,!(s.signal.aborted||!("kind"in k))){k.kind==="preview"&&C(k.htmlContent);for(const O of T)c[O.kind].has(O.path)||c[O.kind].set(O.path,null);S()}})},M=T=>{D(),j(),b({...o,busy:!0,tier:"server"});const k=new AbortController;p=k,w=setTimeout(()=>{w=void 0,n(e,T,k.signal).then(O=>{if(!(k.signal.aborted||!("kind"in O))){if(p=null,O.kind==="failure"){B(O.failure,"server");return}C(O.htmlContent),b({parsed:{htmlContent:O.htmlContent,headings:O.headings},failure:null,busy:!1,tier:"server"})}})},ot)},v=async(T,k)=>{let O;try{O=await T.convert({path:e,text:k},s.signal)}catch(I){return s.signal.aborted||A("the draft converter rejected a conversion, which its contract allows only once the signal aborted",I),ve}const E=Q.draftAnswerViolation(O);return E===null?O:(A(`the draft converter answered outside its contract: ${E}`),ve)},V=(T,k)=>{switch(k.kind){case"preview":if(D(),k.headings.length>Q.EXPLORER_MAX_HEADINGS){j(),B(Q.failureOf("too-large"),"instant");return}x={text:T,html:k.htmlContent,headings:k.headings.map(({text:O,depth:E,id:I})=>({text:O,depth:E,id:I}))},S();return;case"failure":D(),j(),B(Q.failureOf(k.failure.reason,k.failure.code),"instant");return;case"unavailable":M(T);return}},z=async T=>{m=!0;try{for(;i!==null&&!s.signal.aborted;){const k=i;i=null;const O=await v(T,k);if(s.signal.aborted)return;V(k,O)}}finally{m=!1}};return t!==null&&t.seed!==null&&C(t.seed),{update:T=>{if(!(s.signal.aborted||T===f)){if(f=T,clearTimeout(u),u=void 0,t===null){M(T);return}i=T,m||z(t.converter)}},dispose:()=>{s.abort(),i=null,clearTimeout(u),u=void 0,D()}}},dt=(e,t)=>ie.createHtmlSanitizer(Ve(window),e,t,ie.MAX_HTML_NESTING_DEPTH),ft=(e,t)=>e.flatMap((n,r)=>{const a=t[r];return a===void 0?[]:[{editor:a.top,preview:n.top},{editor:a.bottom,preview:n.bottom}]}),K=(e,t)=>{const n=e[t];if(n===void 0)throw new RangeError(`[markdown-explorer] a scroll map index must be in 0..${String(e.length-1)}; got ${String(t)}`);return n},mt=e=>{const t=[];for(const r of e){let a=0,s=t.length;for(;a<s;){const c=a+s>>1;K(t,c).pair.preview<=r.preview?a=c+1:s=c}t[a]={pair:r,before:a===0?void 0:K(t,a-1)}}const n=[];for(let r=t.at(-1);r!==void 0;r=r.before)n.push(r.pair);return n.reverse()},pt=(e,t)=>{const n=Math.max(t.editorMax,0),r=Math.max(t.previewMax,0),a=n-t.editorViewport,s=r-t.previewViewport,c=e.filter(d=>d.editor>0&&d.editor<a&&d.preview>0&&d.preview<s).sort((d,m)=>d.editor-m.editor||d.preview-m.preview);let o={editor:0,preview:0};const f=[o];for(const d of mt(c))d.editor>o.editor&&d.preview>o.preview&&(f.push(d),o=d);return f.push({editor:n,preview:r}),{toPreview:d=>Ee(f,"editor","preview",d),toEditor:d=>Ee(f,"preview","editor",d)}},Ee=(e,t,n,r)=>{const a=K(e,0),s=K(e,e.length-1);if(Number.isNaN(r)||r<=a[t])return a[n];if(r>=s[t])return s[n];let c=0,o=e.length-1;for(;o-c>1;){const m=c+o>>1;K(e,m)[t]<=r?c=m:o=m}const f=K(e,c),d=K(e,o);return f[n]+(d[n]-f[n])*(r-f[t])/(d[t]-f[t])},ht=610,we=89,be=.5,gt=({editor:e,preview:t,previewBlocks:n,editorSpans:r,requestFrame:a,cancelFrame:s,now:c})=>{let o="editor",f=0,d=null,m=null,i=!1,x=null,l=null;const u={editor:0,preview:0},g={editor:null,preview:null};let w=null,p=()=>{};const b=v=>{d!==null&&v!==d||(o=v,f=c()+ht)},A=(v,V)=>{v!==o&&d===null&&c()>=f&&!C(v,V)&&(o=v),S()},C=(v,V)=>{const z=g[v];return c()<u[v]||z!==null&&Math.abs(V.position()-z)<be},D=e.onScroll(()=>A("editor",e)),j=e.onIntent(()=>b("editor")),B=()=>{const v=t();return v!==w&&(p(),w=v,p=v===null?()=>{}:W(v)),v},W=v=>{const V=v.onScroll(()=>A("preview",v)),z=v.onIntent(()=>b("preview"));return()=>{V(),z()}},S=()=>{!i&&m===null&&(m=a(R))},R=()=>{m=null;const v=B();v!==null&&(x??=n(),l??=pt(ft(x,r(x)),{editorMax:e.max(),previewMax:v.max(),editorViewport:e.viewport(),previewViewport:v.viewport()}),o==="editor"?M(v,"preview",l.toPreview(e.position())):M(e,"editor",l.toEditor(v.position())))},M=(v,V,z)=>{if(Math.abs(v.position()-z)<be){g[V]=v.position();return}u[V]=c()+we,g[V]=v.scrollTo(z)};return S(),{editorChanged:v=>{l=null,v&&b("editor"),S()},previewChanged:()=>{x=null,l=null,u.preview=c()+we,S()},showAlone:v=>{d=v,!(v===null||v===o)&&(o=v,f=0,S())},dispose:()=>{i=!0,m!==null&&s(m),m=null,D(),j(),p()}}},Se=Object.freeze(["wheel","pointerdown","keydown","focusin"]),Ae=e=>({position:()=>e.scrollTop,max:()=>Math.max(e.scrollHeight-e.clientHeight,0),viewport:()=>e.clientHeight,scrollTo:t=>(e.scrollTo({top:t,behavior:"instant"}),e.scrollTop),onScroll:t=>(e.addEventListener("scroll",t,{passive:!0}),()=>e.removeEventListener("scroll",t)),onIntent:t=>{for(const n of Se)e.addEventListener(n,t,{capture:!0,passive:!0});return()=>{for(const n of Se)e.removeEventListener(n,t,{capture:!0})}}}),Z="[data-aqmd-scroll-container]",vt="[data-aqmd-content]",Et=`[${se.SOURCE_LINES_ATTRIBUTE}]`,wt=Object.freeze(["p1","p2","p3","p4","p5","p6","p7","p8"]),Me=(e,t)=>{const n=y.loadedOf(e.peek(t));return n!==null&&n.document.kind==="markdown"?{htmlContent:n.document.htmlContent,headings:n.document.headings}:null},bt=(e,t,n,r,a)=>{if(n===void 0)return null;let s;try{s=dt(e,t)}catch(c){return console.error("[markdown-explorer] the draft sanitizer cannot run in this browser, so the server renders the preview",c),null}return{converter:n,sanitize:s,marksOf:ct,seed:Me(r,a)?.htmlContent??null}},St=e=>{const t=[];let n=null;for(const r of e.querySelectorAll(Et)){const a=se.parseSourceLines(r.getAttribute(se.SOURCE_LINES_ATTRIBUTE));if(a===null||r.getClientRects().length===0)continue;n??=e.scrollTop-y.visibleTopOf(e,r);const{top:s,bottom:c}=r.getBoundingClientRect();t.push({first:a.first,last:a.last,top:n+s,bottom:n+c})}return t},xt=({path:e,readDraft:t,viewer:n,spreadsheetEditor:r,concealed:a,onEditAt:s,onLayout:c,handleRef:o})=>{const{config:f,data:d,documents:m,draftConverter:i,labels:x}=y.useExplorer(),[l,u]=h.useState(()=>({parsed:Me(m,e),failure:null,busy:!0,tier:i===void 0?"server":"instant"})),g=h.useRef(null),w=h.useRef(null),p=h.useRef(l);h.useLayoutEffect(()=>{p.current=l});const b=h.useEffectEvent(()=>t());h.useEffect(()=>{const S=bt(f.iframeHosts,f.dataPath,i,m,e),R=ut({path:e,instant:S,preview:d.preview,initial:p.current,onView:M=>h.startTransition(()=>u(M))});return w.current=R,R.update(b()),()=>{R.dispose(),w.current=null}},[f,d,m,i,e]);const A=h.useEffectEvent(()=>c());h.useLayoutEffect(()=>{l.parsed!==null&&A()},[l.parsed]);const C=l.parsed!==null;h.useLayoutEffect(()=>{const S=C?g.current?.querySelector(Z):null;if(!(S instanceof HTMLElement))return;S.tabIndex=0;const R=new ResizeObserver(()=>A());R.observe(S);const M=S.querySelector(vt);return M!==null&&R.observe(M),()=>R.disconnect()},[C]);const D=h.useRef(null);h.useImperativeHandle(o,()=>({draft:S=>{w.current?.update(S)},scrollPort:()=>{const S=g.current?.querySelector(Z);return S instanceof HTMLElement?(D.current?.scroller!==S&&(D.current={scroller:S,port:Ae(S)}),D.current.port):null},blocks:()=>{const S=g.current?.querySelector(Z);return S instanceof HTMLElement?St(S):[]},focus:()=>{const S=g.current?.querySelector(Z);S instanceof HTMLElement&&S.focus({preventScroll:!0})},anchor:S=>{const R=g.current,M=R?.querySelector(Z);return R===null||!(M instanceof HTMLElement)?null:y.anchorOfView(R,S(M))},place:({line:S,clientTop:R},M)=>{const v=g.current,V=v===null?null:y.blockAtLine(v,S);V!==null&&(M(V).scrollTop+=y.lineTopIn(V,S)-R)}}),[]);const j=S=>{const R=g.current,{target:M}=S;if(s===void 0||R===null||!(M instanceof Element)||!y.isEditingDoubleClick(M))return;const v=y.anchorOfDoubleClick(M,R,R.ownerDocument.getSelection());v!==null&&s(v)},B=h.useMemo(()=>({...n,showToc:!1,showStyle:!1,showAlign:!1,renderScrollBar:void 0,spreadsheetEditor:r}),[n,r]),W=h.useMemo(()=>l.parsed===null?null:L.jsx("div",{className:"aqmx-document-viewer",children:L.jsx(De.MarkdownViewer,{...B,parseResult:l.parsed,content:null})}),[B,l.parsed]);return L.jsxs("section",{ref:g,className:"aqmx-edit-preview","aria-label":x.previewRegion,"aria-busy":l.busy,inert:a!==null,hidden:a==="removed","data-aqmx-preview-tier":l.tier,"data-testid":"markdown-explorer-edit-preview",onDoubleClick:s===void 0?void 0:j,children:[l.failure===null?null:L.jsx("p",{className:"aqmx-callout aqmx-document-notice","data-aqmx-tone":"warning","data-testid":"markdown-explorer-edit-preview-failure",children:x.previewFailed(y.failureTitleOf(x,l.failure.reason))}),W??(l.failure===null?L.jsx("div",{className:"aqmx-skeleton","aria-hidden":"true","data-testid":"markdown-explorer-edit-preview-skeleton",children:wt.map(S=>L.jsx("span",{},S))}):null),l.busy?L.jsx("p",{className:"aqmx-sr-only",children:x.previewUpdating}):null]})},xe="data-aqmx-edit-split",oe="--aqmx-edit-share",ye="--aqmx-edit-gutter",yt="data-aqmx-edit-split-probe",Tt="aqmx-edit-split",kt="aqmx-edit-editor",Lt="aqmx-edit-preview",Te={value:U.EDIT_SPLIT_MIN_PERCENT,unit:"percentage"},ke={value:U.EDIT_SPLIT_MAX_PERCENT,unit:"percentage"},Le=e=>{if(e.length!==2)return null;const[t=0,n=0]=e,r=t+n;return r>0?t/r*100:null},ne=e=>{const t=e.current?.parentElement;if(t==null)throw new Error("[markdown-explorer] the edit split is not mounted in its surface");return t},Rt=(e,t,n)=>{const[r,a]=h.useState(null);return h.useLayoutEffect(()=>{const s=e.current,c=t.current;if(s===null||c===null)throw new Error("[markdown-explorer] the edit split is not mounted");const o={frame:s.getBoundingClientRect().width,measure:c.getBoundingClientRect().width},f=()=>{o.frame>0&&o.measure>0&&a(U.editSplitOrientation(o.frame,o.measure,n))};f();const d=new ResizeObserver(m=>{for(const i of m){const[x]=i.borderBoxSize;x!==void 0&&(i.target===s&&(o.frame=x.inlineSize),i.target===c&&(o.measure=x.inlineSize))}f()});return d.observe(s),d.observe(c),()=>d.disconnect()},[e,t,n]),r},Ot=({editorId:e})=>{const{edits:t,labels:n}=y.useExplorer(),r=h.useRef(null),a=h.useRef(null),s=me.useCoarsePointer()?U.COARSE_TARGET_PIXELS:U.FINE_TARGET_PIXELS,c=Rt(r,a,s),[o]=h.useState(()=>t.editorShare());h.useLayoutEffect(()=>{const m=ne(r);return m.style.setProperty(ye,`${String(s)}px`),()=>{m.style.removeProperty(ye)}},[s]),h.useLayoutEffect(()=>{const m=ne(r);return m.style.setProperty(oe,`${String(o)}%`),()=>{m.style.removeProperty(oe)}},[o]),h.useLayoutEffect(()=>{if(c===null)return;const m=ne(r);return m.setAttribute(xe,c),()=>m.removeAttribute(xe)},[c]);const f=me.useSplitPersistence(h.useCallback(m=>{const i=Le(m);i!==null&&t.setEditorShare(i)},[t])),d=h.useCallback((m,i)=>{const x=Le(m);x!==null&&ne(r).style.setProperty(oe,`${String(x)}%`),f.layoutChanged(m,i)},[f]);return L.jsxs("div",{ref:r,className:"aqmx-edit-split","data-testid":"markdown-explorer-edit-split",children:[L.jsx("span",{ref:a,className:"aqmx-edit-split-probe","aria-hidden":"true",[yt]:""}),c===null?null:L.jsxs(te.PanelGroup,{id:Tt,direction:c==="beside"?"horizontal":"vertical",onLayout:d,className:"aqmx-edit-split-group",children:[L.jsx(te.Panel,{id:kt,defaultSize:{value:o,unit:"percentage"},minSize:Te,maxSize:ke,contentOverflow:"hidden"}),L.jsx(te.PanelResizeHandle,{thickness:s,indicator:{visible:!0,thickness:U.SPLIT_HANDLE_PIXELS.gripThickness,length:U.SPLIT_HANDLE_PIXELS.gripLength,barThickness:U.SPLIT_HANDLE_PIXELS.barThickness,barLength:U.SPLIT_HANDLE_PIXELS.barLength},title:n.editViewSplitResize,"aria-label":n.editViewSplitResize,"aria-controls":e,onDragging:f.draggingChanged,className:"aqmx-split-handle aqmx-edit-split-handle"}),L.jsx(te.Panel,{id:Lt,defaultSize:{value:100-o,unit:"percentage"},minSize:Te,maxSize:ke,contentOverflow:"hidden"})]})]})},Ce=144,qt="[data-aqmd-spreadsheet-fullscreen]",It=Object.freeze(["e1","e2","e3","e4","e5","e6","e7","e8"]),At=e=>{if(typeof e!="object"||e===null)return!1;const{generation:t,topLine:n}=e;return"state"in e&&typeof t=="number"&&typeof n=="number"},Mt=e=>{e.stopPropagation()},Ct=e=>{const{path:t,name:n,session:r}=e,{edits:a,labels:s,announcer:c}=y.useExplorer(),{phase:o}=r,f=h.useCallback(()=>a.retry(t),[a,t]);switch(h.useEffect(()=>{o.kind==="failed"&&c.announce(s.documentFailed(n,y.failureTitleOf(s,o.failure.reason)))},[o,c,s,n]),o.kind){case"opening":return L.jsxs(L.Fragment,{children:[L.jsx("div",{className:"aqmx-skeleton","aria-hidden":"true","data-testid":"markdown-explorer-edit-skeleton",children:It.map(d=>L.jsx("span",{},d))}),L.jsx("p",{className:"aqmx-sr-only",children:s.editLoading})]});case"grant":return L.jsx("div",{className:"aqmx-edit-message",children:L.jsx(y.EditGrantNotice,{href:o.href,onRetry:f,testId:"markdown-explorer-edit-grant"})});case"failed":return L.jsx("div",{className:"aqmx-edit-message",children:L.jsx(y.FailureView,{failure:o.failure,alert:!1,onRetry:f,testId:"markdown-explorer-edit-failure"})});case"editing":return L.jsx(_t,{...e})}},_t=({path:e,name:t,session:n,layout:r,viewer:a,region:s,paneScroll:c})=>{const{edits:o,labels:f}=y.useExplorer(),d=h.useRef(null),m=h.useId(),i=h.useRef(null),[x]=h.useState(()=>new Set),l=h.useRef(null),u=h.useRef(null),g=r==="fill",w=y.useSideBySide(),p=y.editViewOf(n,w,g),b=p!=="editor"||n.previewPrepared,A=b&&g,C=h.useRef({layout:r,region:s,paneScroll:c});h.useLayoutEffect(()=>{C.current={layout:r,region:s,paneScroll:c}});const D=h.useRef(n.generation);h.useLayoutEffect(()=>{D.current=n.generation});const j=h.useRef({view:p,previewMounted:b});h.useLayoutEffect(()=>{j.current={view:p,previewMounted:b}});const B=h.useRef(null),W=h.useRef(null),S=h.useRef(!1),R=h.useMemo(()=>({editor:f.editorLabel(t),useOurs:f.conflictUseOurs,useTheirs:f.conflictUseTheirs,keepBoth:f.conflictKeepBoth}),[f,t]),M=h.useCallback(E=>{const{region:I,paneScroll:q}=C.current,H=I();return H===null?E:q.scrollerOf(H,E)},[]);h.useLayoutEffect(()=>{const E=d.current,I=o.draft(e);if(E===null||I===null)return;const q=o.editorState.get(e),H=At(q)&&q.generation===D.current?q:null;let $=null,Y=null;const re=()=>{$!==null&&clearTimeout($),$=null,Y!==null&&o.setDraft(e,Y.text())},F=Ze({parent:E,scroll:{scrollerOf:_=>{const{layout:J,region:Pe,paneScroll:Ne}=C.current,ue=Pe();return J==="fill"||ue===null?_:Ne.scrollerOf(ue,_)},reveal:_=>C.current.paneScroll.reveal(_)},text:I,saved:H===null?void 0:H.state,labels:R,onGeometry:_=>u.current?.editorChanged(_),onChange:_=>{if($??=setTimeout(re,Ce),!_)for(const J of[...x])J();j.current.previewMounted&&Y!==null&&l.current?.draft(Y.text())},onSave:()=>{o.save(e)}});Y=F,i.current=F;const ae=()=>{const _=F.topLine();return{line:_.line,clientTop:_.clientTop}},ce=()=>l.current?.anchor(M)??null,_e=o.bindEditor(e,{flush:re,adopt:_=>F.replaceText(_),returnPoint:()=>{const _=j.current.view==="preview"&&C.current.layout==="content"?ce():null;return _===null?ae():{line:_.lines.first,clientTop:_.clientTop}},nextConflict:()=>j.current.view!=="preview"?F.nextConflict():F.conflicts().length===0?!1:(S.current=!0,o.setView(e,"editor"),!0),beforeView:_=>{if(C.current.layout==="fill")return;if(_==="preview"){B.current={to:"preview",point:ae()};return}const J=ce();B.current=J===null?null:{to:"editor",anchor:J}}});return H!==null&&F.showLine(H.topLine),()=>{re(),o.editorState.set(e,{state:F.save(),generation:D.current,topLine:F.topLine().line}),_e(),F.destroy(),Y=null,i.current=null}},[o,e,R,M,x]);const{request:v}=n;h.useLayoutEffect(()=>{const E=i.current,I=o.draft(e);E===null||I===null||v===null||(v.anchor!==null&&E.reveal(y.positionInSource(I,v.anchor),v.anchor.clientTop),E.focus(),o.consumeRequest(e))},[o,e,v,R]),h.useLayoutEffect(()=>{p!=="editor"&&!n.previewPrepared&&o.preparePreview(e)},[o,e,p,n.previewPrepared]),h.useLayoutEffect(()=>{const E=B.current,I=W.current,q=S.current;B.current=null,W.current=null,S.current=!1;const H=i.current;if(E?.to==="preview")l.current?.place(E.point,M);else if(E?.to==="editor"&&H!==null){const $=o.draft(e);$!==null&&H.reveal(y.positionInSource($,E.anchor),E.anchor.clientTop)}q?H?.nextConflict():I==="editor"?H?.focus():I==="preview"&&l.current?.focus()},[o,e,p,M]);const V=h.useMemo(()=>({write:({fenceLine:E,expected:I,text:q})=>i.current?.replaceBody(E,I,q)===!0,undo:()=>i.current?.undo(),redo:()=>i.current?.redo(),subscribe:E=>(x.add(E),()=>{x.delete(E)})}),[x]),z=h.useCallback(()=>{const E=i.current;if(E===null)throw new Error("[markdown-explorer] the preview read the draft before the editor was mounted");return E.text()},[]);h.useLayoutEffect(()=>{const E=i.current;if(!A||E===null)return;const I=gt({editor:Ae(E.scrollElement),preview:()=>l.current?.scrollPort()??null,previewBlocks:()=>l.current?.blocks()??[],editorSpans:q=>E.lineSpans(q),requestFrame:q=>requestAnimationFrame(q),cancelFrame:q=>cancelAnimationFrame(q),now:()=>performance.now()});return I.showAlone(y.paneShownAlone(j.current.view)),u.current=I,()=>{I.dispose(),u.current=null}},[A,o,e,R]),h.useLayoutEffect(()=>{u.current?.showAlone(y.paneShownAlone(p))},[p]);const T=h.useCallback(()=>u.current?.previewChanged(),[]),k=h.useCallback(E=>o.start(e,E),[o,e]),O=E=>{if(E.target instanceof Element&&E.target.closest(qt)!==null)return;if(E.key==="Escape"){y.consumeKey(E);return}if(!y.isEditViewShortcut(E.nativeEvent,y.isApplePlatform(navigator.platform)))return;y.consumeKey(E);const I=y.toggledEditView(p);W.current=I,y.chooseEditView(o,e,I,g)};return L.jsxs("div",{className:"aqmx-edit","data-aqmx-edit-layout":r,"data-aqmx-edit-view":p,"data-testid":"markdown-explorer-edit",onKeyDown:O,onDoubleClick:Mt,children:[L.jsx("div",{ref:d,id:m,className:"aqmx-edit-editor","data-testid":"markdown-explorer-editor",inert:p==="preview",hidden:p==="preview"&&!g,...y.ALLOW_KEY_REPEAT}),p==="split"?L.jsx(Ot,{editorId:m}):null,b?L.jsx(xt,{path:e,readDraft:z,viewer:a,spreadsheetEditor:V,concealed:p!=="editor"?null:g?"overlay":"removed",onEditAt:p==="preview"?k:void 0,onLayout:T,handleRef:l}):null]})};exports.DRAFT_WRITE_INTERVAL_MS=Ce;exports.default=Ct;
|