@aiquants/markdown-explorer 0.19.0 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +65 -1
- package/README.md +18 -9
- package/dist/EditSurface-Bwl4S1vQ.cjs +7 -0
- package/dist/EditSurface-rKoy_ndP.js +880 -0
- package/dist/{ExplorerSplit-LiI3IUZn.js → ExplorerSplit-3WMRDA7G.js} +1 -1
- package/dist/{ExplorerSplit-BDkBN8A0.cjs → ExplorerSplit-CdqEKz-I.cjs} +1 -1
- package/dist/{MultiLayout-BOaQK8fp.cjs → MultiLayout-BEg1X8Jx.cjs} +1 -1
- package/dist/{MultiLayout-KWacTPP8.js → MultiLayout-Gf1xT-Le.js} +2 -2
- package/dist/{NativeScrollBar-zzpty31a.js → NativeScrollBar-0cpp2OIu.js} +1 -1
- package/dist/{NativeScrollBar-BPgV3kp-.cjs → NativeScrollBar-idIQsvCv.cjs} +1 -1
- package/dist/{TreeLayout-S5TMf8_A.cjs → TreeLayout-DJY_WqzP.cjs} +1 -1
- package/dist/{TreeLayout-C8IP4cjY.js → TreeLayout-DzZCgMTt.js} +2 -2
- package/dist/core/labels.d.cts +26 -0
- package/dist/core/labels.d.ts +26 -0
- package/dist/{index-Dz01kBab.js → index-CJgHGeZs.js} +1323 -1238
- package/dist/index-bMaSoQTe.cjs +13 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/{merge-ClVgYrkS.js → merge-BOcofJN5.js} +1 -1
- package/dist/{merge-B7Lkcdz0.cjs → merge-BVk6pvO_.cjs} +1 -1
- package/dist/sanitizePolicy-BWQtWhsL.js +98 -0
- package/dist/sanitizePolicy-gEXeavb-.cjs +1 -0
- package/dist/sanitizeWorker.cjs +1 -1
- package/dist/sanitizeWorker.js +1 -1
- package/docs/behavior/localization.md +5 -1
- package/docs/behavior/security.md +18 -8
- package/package.json +9 -7
- package/dist/EditSurface-4VX20isB.cjs +0 -2
- package/dist/EditSurface-Ckg-3iTA.js +0 -786
- package/dist/index-DrKHJNY4.cjs +0 -13
- package/dist/sanitizePolicy-DlrakwA4.js +0 -96
- package/dist/sanitizePolicy-DrIMuYCb.cjs +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,70 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## 0.21.0 (2026-10-26) — Tables inside list items and quotes write back from the preview, and a table follows every change of the editor's text
|
|
4
|
+
|
|
5
|
+
### Breaking
|
|
6
|
+
|
|
7
|
+
- **The peer floor is `@aiquants/markdown` ^10.0.0.** markdown 10 hands the editor to tables inside list items and
|
|
8
|
+
quotes and requires `SpreadsheetEditor.subscribe`, which the explorer's editor implements; the other peer floors stay
|
|
9
|
+
as in 0.20.0.
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- **Tables inside list items and quotes, and behind an indented fence, write back from the preview.** The editor finds
|
|
14
|
+
a table's block in its Markdown parse (to the closing fence, or to the end of the list item, the quote or the text) and
|
|
15
|
+
writes each line with the head the block's lines carry: the item's indentation, `>` with its space, the fence's own
|
|
16
|
+
indentation. Inside a list item a row whose cells are all empty or white space is written as an empty line, which is
|
|
17
|
+
how the converter reads such a line there. A block written by hand whose lines do not all carry that head refuses the
|
|
18
|
+
write-back as an edit conflict, as before.
|
|
19
|
+
|
|
20
|
+
### Fixed
|
|
21
|
+
|
|
22
|
+
- **An undo in the editor right after a table's edit shows the undone value in the table.** An undo that landed before
|
|
23
|
+
the edit's echo was drawn left the table showing its edit, because the preview's body was then the one the table last
|
|
24
|
+
received. The editor now tells the preview's tables of every change of its text that is not a write-back (typing, an
|
|
25
|
+
undo or a redo, a text the store hands in), and the tables drop their write-backs not yet drawn.
|
|
26
|
+
|
|
27
|
+
## 0.20.0 (2026-10-26) — ```spreadsheets tables, read-only in documents and editable in the preview
|
|
28
|
+
|
|
29
|
+
### Breaking
|
|
30
|
+
|
|
31
|
+
- **`@aiquants/spreadsheet` ^0.15.0 is a new required peer, and the peer floors are `@aiquants/markdown` ^9.0.1,
|
|
32
|
+
`@aiquants/directory-tree` ^5.0.1 and `@aiquants/virtualscroll` ^3.22.1.** markdown 9 draws a ```spreadsheets code
|
|
33
|
+
block as a table with `@aiquants/spreadsheet` (loaded only for a document that holds one), and 9.0.1 sets a table back
|
|
34
|
+
to the document's body when Ctrl+Z or Ctrl+Y in it reaches the editor, so an undo that lands before the edit's echo is
|
|
35
|
+
drawn shows the undone value. A host installs `@aiquants/spreadsheet` and loads its stylesheet with the others:
|
|
36
|
+
`@aiquants/spreadsheet/styles/spreadsheet.standalone.css`, or `spreadsheet.css` in a Tailwind v4 host's entry with an
|
|
37
|
+
`@source` over its build output (see README "Load the styles"). directory-tree 5.0.1 and virtualscroll 3.22.1 change
|
|
38
|
+
their documentation only.
|
|
39
|
+
- **The viewer labels have 26 more keys, `viewerSpreadsheet…`** (markdown 9's `spreadsheet…` viewer keys): a host that
|
|
40
|
+
overrides every viewer label adds them. Six are templates (`MARKDOWN_EXPLORER_LABEL_TEMPLATES`):
|
|
41
|
+
`viewerSpreadsheetSize` (`{rows}`, `{cols}`), `viewerSpreadsheetCopyFailed` (`{reason}`),
|
|
42
|
+
`viewerSpreadsheetCellAnnouncement` (`{cell}`, `{value}`), `viewerSpreadsheetSelectionAnnouncement` (`{range}`),
|
|
43
|
+
`viewerSpreadsheetOptionsError` and `viewerSpreadsheetLoadFailed` (`{message}`).
|
|
44
|
+
|
|
45
|
+
### Added
|
|
46
|
+
|
|
47
|
+
- **```spreadsheets tables.** The rendered document shows each table read-only (selection, copy, zoom, the row and
|
|
48
|
+
column bands, copying the whole table, saving it as TSV and full screen). In the editor's preview every table with
|
|
49
|
+
source lines outside list items and quotes is editable: each transaction (a committed cell, a paste, a delete, a fill)
|
|
50
|
+
is written back into the editor's text as its block's new body, one undo step of its own, refused — and the table
|
|
51
|
+
says so — when the editor's block no longer reads what the table knows; Ctrl+Z and Ctrl+Y in a table undo and redo
|
|
52
|
+
the editor's history, and Save saves the tables' edits with the rest of the draft. A write-back, an undo or a redo
|
|
53
|
+
from a table leaves the scroll sync's lead with the preview. The grid takes the explorer's `locale` as its own.
|
|
54
|
+
- **The sanitizer keeps `data-code-meta` on `code`**, the info string after a fenced block's language that holds a
|
|
55
|
+
table's options (an inert value, as `@aiquants/markdown/code-blocks` names it).
|
|
56
|
+
- **The demo** writes `data-code-meta` as the Go converter does (the info string after the language, without its
|
|
57
|
+
trailing white space), loads the spreadsheet stylesheet and holds `notes/spreadsheets.md`.
|
|
58
|
+
|
|
59
|
+
### Changed
|
|
60
|
+
|
|
61
|
+
- **A double-click in an editable table or in a table shown full screen is the table's**: it edits a cell, or stays in
|
|
62
|
+
the full-screen layer, instead of opening the editor. A double-click on a read-only table of the rendered document
|
|
63
|
+
opens the editor there, as on any other block.
|
|
64
|
+
- **The keys of a table shown full screen are the table's**: the editing surface leaves them alone, so Ctrl+E does not
|
|
65
|
+
switch the panes behind it and Escape leaves full screen (the table takes that Escape itself).
|
|
66
|
+
|
|
67
|
+
## 0.19.0 (2026-10-26)
|
|
4
68
|
|
|
5
69
|
### Breaking
|
|
6
70
|
|
package/README.md
CHANGED
|
@@ -39,10 +39,10 @@ A single-view (embedding) page never downloads the tree and multi-panel views, w
|
|
|
39
39
|
|
|
40
40
|
- React 19.2.7 or later and React Router 8 in framework mode (route modules with `loader` / `headers`).
|
|
41
41
|
- Node.js 22.22 or later (the floor React Router 8 declares). The package ships ES modules and CommonJS; the CommonJS entries load the ESM-only `react-router` through `require(esm)`.
|
|
42
|
-
- The peer packages, at these versions or later within the caret ranges the package declares: `@aiquants/markdown` ^
|
|
42
|
+
- The peer packages, at these versions or later within the caret ranges the package declares: `@aiquants/markdown` ^10.0.0 (document rendering; its components' stylesheet without utilities, its controls' 44 px targets under every pointer, ```spreadsheets tables — inside list items and quotes too — and their write-back through an editor that tells them of its other changes, so an undo before an edit is drawn shows the undone value, the React-free `@aiquants/markdown/code-blocks` that names the `data-code-meta` the sanitizer keeps on `code`,
|
|
43
43
|
its Mermaid labels and drawings that finish inside the document when a diagram's text changes or it unmounts mid-drawing, its math diagnostics, gantt sizing, embeds, link cards and their sizes, the React-free `@aiquants/markdown/embeds` the sanitizer worker loads and `@aiquants/markdown/source-lines` the editor and the sanitizer read, and the Node-only link-card handler of `@aiquants/markdown/server`, which needs Node.js 22.13 or later — below the explorer's own floor),
|
|
44
|
-
`@aiquants/directory-tree` ^5.0.
|
|
45
|
-
`@aiquants/drag-drop-panels` ^0.12.0 (the panel headers' move menu, named by the explorer's `panelMove`, their 44 px buttons under every pointer and the header arrangement the behavior docs follow), `@aiquants/resize-panels` ^2.2.0 (the source of each layout change, by which the tree pane's width is saved) and `@aiquants/virtualscroll` ^3.22.
|
|
44
|
+
`@aiquants/directory-tree` ^5.0.1 (rows that take paint and text styles only and have no vertical padding, a `removeRootIndent` shift that keeps the root's icon whole, and reveals of rows under the scroll bar's buttons),
|
|
45
|
+
`@aiquants/drag-drop-panels` ^0.12.0 (the panel headers' move menu, named by the explorer's `panelMove`, their 44 px buttons under every pointer and the header arrangement the behavior docs follow), `@aiquants/resize-panels` ^2.2.0 (the source of each layout change, by which the tree pane's width is saved), `@aiquants/spreadsheet` ^0.15.0 (the grid of those tables, which markdown loads only for a document that holds one) and `@aiquants/virtualscroll` ^3.22.1 (44 px scroll-to-edge pills and tap-scroll circles, the pills' text at the body step).
|
|
46
46
|
The client depends on these floors, while a package manager may only warn about an older peer.
|
|
47
47
|
- A Markdown parser of your choice on the server that produces HTML and its headings (the explorer sanitizes the HTML before it is sent).
|
|
48
48
|
- Browsers: the multi view's panel-limit notice and the panel headers' move menu use the Popover API (Chrome and Edge 114, Firefox 125, Safari 17 and later). In browsers without it (for example iOS 16), the notice is drawn in place at the stage's corner instead of in the top layer (while the sheet is open it spans the sheet's header, as in every browser), and the move menu does not open: Alt + Shift + an arrow moves a panel there.
|
|
@@ -199,6 +199,7 @@ import resizePanels from "@aiquants/resize-panels/styles/resize-panels.standalon
|
|
|
199
199
|
import dragDropPanels from "@aiquants/drag-drop-panels/styles/drag-drop-panels.standalone.css?url"
|
|
200
200
|
import virtualscroll from "@aiquants/virtualscroll/styles/virtualscroll.standalone.css?url"
|
|
201
201
|
import directoryTree from "@aiquants/directory-tree/styles/directory-tree.standalone.css?url"
|
|
202
|
+
import spreadsheet from "@aiquants/spreadsheet/styles/spreadsheet.standalone.css?url"
|
|
202
203
|
import katex from "@aiquants/markdown/styles/katex.min.css?url"
|
|
203
204
|
import markdown from "@aiquants/markdown/styles/markdown.standalone.css?url"
|
|
204
205
|
import githubMarkdown from "@aiquants/markdown/styles/github-markdown.css?url"
|
|
@@ -208,7 +209,7 @@ import details from "@aiquants/markdown/styles/details.css?url"
|
|
|
208
209
|
import markdownExplorer from "@aiquants/markdown-explorer/styles/markdown-explorer.css?url"
|
|
209
210
|
import app from "./app.css?url"
|
|
210
211
|
|
|
211
|
-
export const links = () => [resizePanels, dragDropPanels, virtualscroll, directoryTree, katex, markdown, githubMarkdown, zennContent, message, details, markdownExplorer, app].map((href) => ({ rel: "stylesheet", href }))
|
|
212
|
+
export const links = () => [resizePanels, dragDropPanels, virtualscroll, directoryTree, spreadsheet, katex, markdown, githubMarkdown, zennContent, message, details, markdownExplorer, app].map((href) => ({ rel: "stylesheet", href }))
|
|
212
213
|
```
|
|
213
214
|
|
|
214
215
|
Your own stylesheet gives the explorer the definite block size it fills (see [Sizing](docs/behavior/layout.md#sizing)):
|
|
@@ -234,7 +235,7 @@ body {
|
|
|
234
235
|
```
|
|
235
236
|
|
|
236
237
|
- `html` and `body` take the viewport's height (React Router's default root renders the page straight into `body`; give any element your own root puts between them `height: 100%` as well), and `margin: 0` keeps the page from ending below the viewport. The page is a flex column of that height, and the explorer's wrapper takes what the header leaves (`flex: 1`) and may be shorter than its content (`min-height: 0`).
|
|
237
|
-
- The `.standalone.css` builds, `@aiquants/markdown/styles/markdown.standalone.css` among them, suit hosts without Tailwind CSS (or with Tailwind v3). A Tailwind v4 host loads the plain builds (`resize-panels.css`, `@aiquants/drag-drop-panels/css`, `virtualscroll.css`, `directory-tree.css`) and lets Tailwind scan the peers' `dist` with `@source`.
|
|
238
|
+
- The `.standalone.css` builds, `@aiquants/markdown/styles/markdown.standalone.css` among them, suit hosts without Tailwind CSS (or with Tailwind v3). `spreadsheet.standalone.css` carries virtualscroll's rules too, so beside `virtualscroll.standalone.css` the same rules come twice, with the same effect. A Tailwind v4 host loads the plain builds (`resize-panels.css`, `@aiquants/drag-drop-panels/css`, `virtualscroll.css`, `directory-tree.css`, `spreadsheet.css`) and lets Tailwind scan the peers' `dist` with `@source`.
|
|
238
239
|
For `@aiquants/markdown` it links no components sheet (the document styles below are still linked): its Tailwind entry imports `markdown.css` without `layer()` (the sheet's link and link-card rules and the diagram's focus ring must stay outside every cascade layer), scans the package's build output so that its own build generates the utilities the document viewer uses (the path of `@source` is relative to the CSS file that declares it), and declares the `dark` variant those utilities follow.
|
|
239
240
|
Without a declaration Tailwind's `dark` is the `prefers-color-scheme` media query; declare the one that matches how your page signals dark mode. The one below is the standalone sheet's: a `.dark` ancestor, or the `[data-theme="dark"]` the viewer sets from its `theme`:
|
|
240
241
|
|
|
@@ -406,7 +407,7 @@ Only the browser can say which, so the server's HTML holds neither, and a browse
|
|
|
406
407
|
A markdown document lists at most `EXPLORER_MAX_HEADINGS` (10,000) headings; one that lists more is answered `too-large`, because every listed heading travels with the document (in the data response, the browser's document cache and the viewer's table of contents, one entry each) and a parser can list headings its HTML never renders (`#` lines inside a math block), so none of the HTML's limits bounds the list. A cache of your parser's results can rely on the same bound.
|
|
407
408
|
|
|
408
409
|
Markdown links the viewer should follow inside the explorer carry `data-link-kind="doc"` and `data-doc-path="<document path>"` (plus `data-doc-exists="false"` for a missing target); a `doc` link without a path, or with one that is not an acceptable document path (`isAcceptableDocumentPath`: non-empty, at most `MAX_DOCUMENT_PATH_LENGTH` characters, no lone surrogates, control characters or backslashes), renders as an inert link.
|
|
409
|
-
The sanitizer keeps only the `data-*` attributes of this contract: `data-link-kind`, `data-doc-path`, `data-doc-exists`, `data-footnote-ref` and `data-footnote-backref` on links, `data-asset-src` and `data-asset-exists` on images, and `data-
|
|
410
|
+
The sanitizer keeps only the `data-*` attributes of this contract: `data-link-kind`, `data-doc-path`, `data-doc-exists`, `data-footnote-ref` and `data-footnote-backref` on links, `data-asset-src` and `data-asset-exists` on images, `data-footnotes` on sections, and `data-code-meta` on code (a fenced block's info string after its language, which holds a ```spreadsheets table's options); every other one is removed, including the `data-plugin-type` iframe trigger of `@aiquants/markdown` and the `<div data-plugin-type>` placeholders its 5.x converter wrote.
|
|
410
411
|
The one exception is the converter's embed placeholder: a paragraph whose only content is one absolute `http(s)` link without a user name or password (besides white space, U+00A0 and U+3000) carries the link's `href`, byte for byte, in `data-embed-url` on the `<p>`, and the paragraph and its link stay as written.
|
|
411
412
|
The sanitizer keeps that attribute only where `placeholderLinkOf` of `@aiquants/markdown/embeds` accepts it against the paragraph's children with the link's sanitized `href`; a forged or altered placeholder leaves the plain paragraph (see [Security](docs/behavior/security.md#html)). Mark such paragraphs in your parser as the Go converter does to get embeds and cards (the demo's parser shows how); without the mark the link stays its paragraph.
|
|
412
413
|
The viewer (`@aiquants/markdown`) renders an external link itself, in a new tab with `rel="noreferrer"`: one marked `data-link-kind="external"`, or, without `data-link-kind`, one whose `href` names a scheme in any case (`https:`, `HTTPS:`, `mailto:`) or another host (`//host/…`), so links to other sites need no mark.
|
|
@@ -447,6 +448,7 @@ editMaxBytes: 2 * 1024 * 1024, // the largest source and draft, the default
|
|
|
447
448
|
- **Grants.** Answer `{ kind: "grant", href }` from `source` or `save` when the reader must first allow writing (an OAuth consent for a wider scope, for example); `href` is a root-relative address of your own. The explorer shows a notice whose action calls `<MarkdownExplorer onEditGrant>` with it, or, without that prop, links to it in a new tab beside Try again.
|
|
448
449
|
- **Operations.** The data route answers `GET <dataPath>/edit?path=`, `POST <dataPath>/save?path=&base=<version>`, `POST <dataPath>/preview?path=`, `GET <dataPath>/revisions?path=` and `GET <dataPath>/revision?path=&revision=<id>`. `save` and `preview` carry `X-Markdown-Explorer: edit` and must pass the shared cross-origin check, like a refresh. Without `edit`, these operations answer as unknown ones (404), and `editMaxBytes` alone throws.
|
|
449
450
|
- **Source lines.** The editor opens at the place the reader was reading, or at the word they double-clicked, and the editor and the preview scroll together block by block, through the source lines your converter writes on every block: `data-source-lines="<first>-<last>"` (1-based, both inclusive), `@aiquants/markdown`'s `includeSourceLines`. Without them the editor opens at the start of the document and the two panes scroll together in proportion alone, top with top and bottom with bottom; the sanitizer keeps the attribute only in that form.
|
|
451
|
+
A ```spreadsheets table needs its source lines to be editable in the preview, and its options need the info string after the language as `data-code-meta` on the `code` element, as `@aiquants/markdown`'s converter writes it.
|
|
450
452
|
|
|
451
453
|
### Revealing the open document
|
|
452
454
|
|
|
@@ -716,7 +718,8 @@ A folder met again among its own ancestors (a shortcut inside its own target, or
|
|
|
716
718
|
#### The editor
|
|
717
719
|
|
|
718
720
|
A markdown document whose `edit` is `inline` gets an **Edit** toggle (`aria-pressed`) in the document bar, between Source and Refresh document: labelled beside a page view's pane, icon-only and named after the document in a multi-view panel. One whose `edit` is `draft` gets the same toggle, its tooltip and its name in a panel saying the document is edited without saving. One whose `edit` is `external` gets a link to its own editor in a new tab instead.
|
|
719
|
-
Pressing Edit opens the editor with the block at the top of the reader's view at the same place on screen;
|
|
721
|
+
Pressing Edit opens the editor with the block at the top of the reader's view at the same place on screen;
|
|
722
|
+
a double-click on a word of the rendered document opens it with the cursor on that word, which stays where it was, in the tree and single views and in a maximized panel (a panel that is not maximized maximizes on its first double-click, as before; links, controls, media and drawings keep their own double-click, and so do an editable table and a table shown full screen). Pressed again, Edit closes the editor — asking first when the draft is unsaved — and the rendered document shows the editor's top line at the same place.
|
|
720
723
|
The toggle is one element in both states, so the focus stays on it.
|
|
721
724
|
While a document is edited, the bar shows the draft's status on one line and the editor's actions instead of Source and Refresh document: Next conflict while conflicts wait, the view switch (Editor, Side by side where the pane has room — a page view or a maximized panel —, and Preview), History when the host keeps revisions, and Save (Ctrl/⌘+S in the editor), which is `aria-disabled` until the draft changes; the announcer speaks each save's outcome.
|
|
722
725
|
The editor (CodeMirror 6, loaded when the reader first points at or focuses Edit) fills the pane where it can and grows with its text in a panel that is not maximized; Escape inside it is consumed, so a maximized panel stays maximized, and Tab leaves it.
|
|
@@ -724,6 +727,10 @@ A save writes the draft back with the line endings of the file it opened (`\r\n`
|
|
|
724
727
|
A save that meets changes saved elsewhere merges them line by line: changes on different lines are saved at once; lines both sides changed differently are written between git-style markers with buttons above each conflict (keep my lines, the saved lines, or both), and Next conflict moves the focus to those buttons. A draft with markers left is not saved.
|
|
725
728
|
The preview renders the draft as the document would be: on every keystroke with a `draftConverter`, else once the reader pauses typing (SERVER_PREVIEW_DELAY_MS, 610 ms).
|
|
726
729
|
The view switch shows the editor alone, the two side by side (the preview below the editor on a narrow pane), or the preview alone; Ctrl+E (⌘E on a Mac) switches between the editor and the preview from the editor, the preview or the switch and moves the focus there, and a double-click on a word of the preview shown alone opens the editor at that word.
|
|
730
|
+
```spreadsheets tables (see `@aiquants/markdown`'s README, "Spreadsheets") are read-only in the rendered document and editable in the preview: every table with source lines writes each transaction (a committed cell, a paste, a delete, a fill) back into the editor's text as its block's new body, one undo step of its own, which the editor refuses — and the table says so — when the block no longer reads what the table knows.
|
|
731
|
+
The editor finds the block in its Markdown parse (to the closing fence, or to the end of the list item, the quote or the text), so a table inside a list item or a quote, or behind an indented fence, writes back too: each line keeps the head the block's lines carry (the item's indentation, `>`, the fence's indentation), and a block whose lines do not all carry it is refused like an edited one.
|
|
732
|
+
Ctrl+Z and Ctrl+Y in a table undo and redo the editor's history, and Save saves the tables' edits with the rest of the draft. A write-back, an undo or a redo from a table leaves the scroll sync's lead with the preview. Any other change of the editor's text — an undo in the editor right after a table's edit included — makes the tables drop their write-backs not yet drawn and show the preview's body again.
|
|
733
|
+
A double-click in an editable table edits a cell instead of opening the editor (a read-only table of the rendered document opens it there, like any other block), and a table shown full screen keeps its keys: Ctrl+E does not switch the panes behind it, and Escape leaves full screen.
|
|
727
734
|
Side by side, a handle on the gutter between the two resizes them, as the explorer's handle resizes the explorer: drag it, or focus it and press the arrow keys (10 px, 50 px with Shift); either side keeps at least 1/φ³ (≈ 23.6 %) of the surface, and the reader's share (an even split by default) is kept in browser storage under `storageNamespace`, for beside and below alike.
|
|
728
735
|
Switching is instant: the hidden pane stays rendered and in step, so the block at the top of the view stays the same; a panel that is not maximized shows one pane at a time and puts the next one at the same place on screen. Where the bar is narrower than two reading columns (a phone), the switch shows its icons alone, keeping its 44 px targets.
|
|
729
736
|
The two scroll together, both ways: the pane the reader works in (the wheel, a press, a key, the focus, typing) leads — the shown one alone while the other is hidden —, and the other keeps the same blocks at the top of its view, moving on continuously — a block taller on one side, such as an image or a heading, is crossed faster there, never with a jump or a step back — and both reach their tops and their bottoms together.
|
|
@@ -795,8 +802,9 @@ export const draftConverter: ExplorerDraftConverter = {
|
|
|
795
802
|
### Localization
|
|
796
803
|
|
|
797
804
|
`locale` selects a built-in catalog (`MARKDOWN_EXPLORER_LABEL_CATALOGS.en` / `.ja`); `labels` overrides single keys.
|
|
798
|
-
The catalogs also name every control of the document viewer (the `viewer…` keys: its toolbar, the table of contents, the style and alignment menus, each Mermaid diagram's controls
|
|
799
|
-
|
|
805
|
+
The catalogs also name every control of the document viewer (the `viewer…` keys: its toolbar, the table of contents, the style and alignment menus, each Mermaid diagram's controls, every name, notice and announcement of a ```spreadsheets table, whose grid also takes `locale` as its own, and the titles of embedded frames)
|
|
806
|
+
and everything the multi view's drag-and-drop layout shows (the panel headers' buttons and the custom drag mode's badge, the move announcements and a touch or pen drag's lift and cancel announcements, the bar of hidden panels, the columns' names and the drop placeholders), which therefore follow `locale` too.
|
|
807
|
+
The labels the layout or a table fills with a value are templates with `{name}` placeholders (`MARKDOWN_EXPLORER_LABEL_TEMPLATES`). An unknown key, a blank string, a value of the wrong type, a template placeholder its key does not offer or a regional tag such as `"ja-JP"` throws — see [Localization](docs/behavior/localization.md).
|
|
800
808
|
|
|
801
809
|
## Layout
|
|
802
810
|
|
|
@@ -866,6 +874,7 @@ Tests and host styling may rely on the `data-testid` and `data-aqmx-*` attribute
|
|
|
866
874
|
- A held Enter acts once on every control inside the explorer, those of other packages included (the tree's rows, the panel headers' buttons, the document viewer's toolbar and the controls inside a document), except Zoom in and Zoom out, which keep stepping while a press that began on them is held (see [Held keys](docs/behavior/layout.md#held-keys)): a press that hands the focus to them, such as following a link to an image, does not step them.
|
|
867
875
|
The repeated keydowns end at the explorer's root, so a keydown listener the host attaches outside the explorer for the bubbling phase does not receive them either.
|
|
868
876
|
- A loop row (a folder met again among its own ancestors) shows an expand glyph and `aria-expanded="false"` like any closed folder, because `@aiquants/directory-tree` has no row that cannot expand; it never opens. The 4 listings in flight are counted per explorer, not across browser tabs.
|
|
877
|
+
- A ```spreadsheets table writes back only when every line of its block carries the head its opening fence line gives its continuation lines (a list item's indentation, `>` with its space, the fence's own indentation); a block written by hand with lines indented less than its fence, `>` without its space, or a tab in that head refuses every write-back as an edit conflict. Inside a list item, a line of spaces and tabs only reads as an empty line (CommonMark), so a row whose cells are all empty or white space is written as an empty line and keeps no cells.
|
|
869
878
|
- Document kinds are the five above; `createFileSystemSource` previews only files with a known text extension or name as text and offers any other file as a `file` document (a download).
|
|
870
879
|
- HTML larger than `sanitizer.maxHtmlBytes` (4 MiB), placed deeper than 512 levels while it is parsed, making the parser create more elements than it has characters, more nodes than the worker's heap holds (81,920 elements, attributes and comments by default) or more than 4,096 comments, holding a tag with more than 1,024 attributes (counted before parsing for every `<` or `</` followed by a letter, so text in a script, a comment or an attribute value that looks like such a tag counts too), giving `html` or `body` more than 1,024 attributes through repeated tags,
|
|
871
880
|
carrying attributes whose characters, counting every copy of a reopened formatting element, exceed `maxHtmlBytes`, sanitizing to HTML longer than four characters per byte of `maxHtmlBytes`, or not sanitized within `sanitizer.deadlineMs` (30 s) shows as `too-large`.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const L=require("react/jsx-runtime"),h=require("react"),y=require("./index-bMaSoQTe.cjs"),G=require("@codemirror/commands"),de=require("@codemirror/lang-markdown"),le=require("@codemirror/language"),fe=require("@codemirror/search"),X=require("@codemirror/state"),P=require("@codemirror/view"),N=require("@lezer/highlight"),De=require("@aiquants/markdown"),se=require("@aiquants/markdown/source-lines"),Q=require("./dataRoute-BONacTPi.cjs"),ie=require("./sanitizePolicy-gEXeavb-.cjs"),Ve=require("isomorphic-dompurify"),te=require("@aiquants/resize-panels"),U=require("./location-BVEN_Ihk.cjs"),me=require("./useSplitPersistence-Ba-v64n-.cjs"),Re={history:G.historyField},Be=le.HighlightStyle.define([{tag:[N.tags.heading1,N.tags.heading2,N.tags.heading3,N.tags.heading4,N.tags.heading5,N.tags.heading6,N.tags.heading],color:"var(--aqmx-syntax-heading)",fontWeight:"700"},{tag:N.tags.strong,fontWeight:"700"},{tag:N.tags.emphasis,fontStyle:"italic"},{tag:N.tags.strikethrough,textDecoration:"line-through"},{tag:N.tags.link,color:"var(--aqmx-syntax-link)",textDecoration:"underline"},{tag:N.tags.url,color:"var(--aqmx-syntax-url)"},{tag:N.tags.monospace,color:"var(--aqmx-syntax-code)"},{tag:N.tags.quote,color:"var(--aqmx-syntax-quote)"},{tag:[N.tags.processingInstruction,N.tags.contentSeparator,N.tags.labelName,N.tags.meta],color:"var(--aqmx-syntax-mark)"}]),He=P.EditorView.theme({"&":{height:"100%",color:"var(--aqmx-text)",backgroundColor:"var(--aqmx-surface)",fontSize:"var(--aqmx-font-size-title)"},"&.cm-focused":{outline:"none"},".cm-scroller":{fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace',lineHeight:"var(--aqmx-line-height-prose)"},".cm-content":{caretColor:"var(--aqmx-text)",paddingBlock:"var(--aqmx-space-6)"},".cm-line":{paddingInline:"var(--aqmx-space-6)"},"&.cm-focused .cm-cursor":{borderLeftColor:"var(--aqmx-text)"},"&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection":{backgroundColor:"var(--aqmx-editor-selection)"},".cm-activeLine":{backgroundColor:"var(--aqmx-editor-active-line)"},".cm-gutters":{backgroundColor:"var(--aqmx-surface-raised)",color:"var(--aqmx-editor-gutter)",borderInlineEnd:"var(--aqmx-space-1) solid var(--aqmx-border)"},".cm-activeLineGutter":{backgroundColor:"var(--aqmx-editor-active-line)"},".cm-searchMatch":{outline:"var(--aqmx-space-1) solid var(--aqmx-border-strong)"},".cm-panels":{backgroundColor:"var(--aqmx-surface-raised)",color:"var(--aqmx-text)"}}),Oe="data-aqmx-conflict-actions",je=P.Decoration.line({attributes:{"data-aqmx-conflict-line":"marker"}}),ze=P.Decoration.line({attributes:{"data-aqmx-conflict-line":"ours"}}),Fe=P.Decoration.line({attributes:{"data-aqmx-conflict-line":"theirs"}});class We extends P.WidgetType{constructor(t,n){super(),this.index=t,this.labels=n}index;labels;eq(t){return t.index===this.index&&t.labels===this.labels}toDOM(t){const n=document.createElement("div");n.setAttribute(Oe,String(this.index));for(const[r,a]of[["ours",this.labels.useOurs],["theirs",this.labels.useTheirs],["both",this.labels.keepBoth]]){const s=document.createElement("button");s.type="button",s.textContent=a,s.setAttribute("data-aqmx-conflict-choice",r),s.addEventListener("mousedown",c=>c.preventDefault()),s.addEventListener("click",()=>{const c=ee(t.state.doc)[this.index];c!==void 0&&(qe(t,c,r),t.focus())}),n.append(s)}return n}ignoreEvent(){return!0}}const ee=e=>y.findConflictsInLines(e.iterLines()),pe=(e,t)=>{const n=new X.RangeSetBuilder;return ee(e).forEach((r,a)=>{const s=e.line(r.start);n.add(s.from,s.from,P.Decoration.widget({widget:new We(a,t),block:!0,side:-1}));for(let c=r.start;c<=r.end;c+=1){const o=e.line(c).from,f=c===r.start||c===r.separator||c===r.end?je:c<r.separator?ze:Fe;n.add(o,o,f)}}),n.finish()},Ue=e=>X.StateField.define({create:t=>pe(t.doc,e),update:(t,n)=>n.docChanged?pe(n.state.doc,e):t,provide:t=>P.EditorView.decorations.from(t)}),qe=(e,t,n)=>{const{doc:r}=e.state,a=(i,x)=>{const l=[];for(let u=i;u<=x;u+=1)l.push(r.line(u).text);return l},s=a(t.start+1,t.separator-1),c=a(t.separator+1,t.end-1),o=n==="ours"?s:n==="theirs"?c:[...s,...c];let f=r.line(t.start).from,d=r.line(t.end).to;o.length===0&&(t.end<r.lines?d+=1:t.start>1&&(f-=1));const m=o.join(`
|
|
2
|
+
`);e.dispatch({changes:{from:f,to:d,insert:m},selection:X.EditorSelection.cursor(f),scrollIntoView:!0,userEvent:"input.resolve"})},he="input.preview",$e=500,Ge=/^([ >+*\-.)\d]*?)(?:`{3}|~{3})/u,Ke=/^(?:[-+*]|\d{1,9}[.)])(?= )/u,Ie=/^[ \t]*$/u,Xe=e=>{let t="",n=0;for(;n<e.length;){const r=e.slice(n);if(r.startsWith(">"))t+="> ",n+=r.startsWith("> ")?2:1;else if(r.startsWith(" "))t+=" ",n+=1;else{const a=Ke.exec(r)?.[0];if(a===void 0)return null;t+=" ".repeat(a.length),n+=a.length}}return t},Ye=(e,t,n)=>{if(e.startsWith(t)){const r=e.slice(t.length);return n&&Ie.test(r)?"":r}return t.startsWith(e)&&e.length>=t.trimEnd().length?"":null},Je=(e,t,n)=>e.split(`
|
|
3
|
+
`).map((r,a,s)=>a===s.length-1&&r===""?"":(n?Ie.test(r):r==="")?t.trimEnd():`${t}${r}`).join(`
|
|
4
|
+
`),Qe=(e,t,n)=>{const{doc:r}=e;if(!Number.isInteger(t)||t<1||t>r.lines)return null;const a=r.line(t),s=Ge.exec(a.text)?.[1],c=s===void 0?null:Xe(s);if(s===void 0||c===null)return null;const o=Math.min(r.lines,t+n.split(`
|
|
5
|
+
`).length+1),f=le.ensureSyntaxTree(e,r.line(o).to,$e);if(f===null)return null;const d=f.resolveInner(a.from+s.length,1),m=d.parent;if(d.name!=="CodeMark"||m===null||m.name!=="FencedCode"||m.from!==d.from)return null;const[,...i]=m.getChildren("CodeMark"),x=i.at(-1),l=x===void 0?r.lineAt(m.to).number:r.lineAt(x.from).number-1;let u=m.parent;for(;u!==null&&u.name!=="ListItem"&&u.name!=="Blockquote";)u=u.parent;const g=u?.name==="ListItem";let w="";for(let b=t+1;b<=l;b+=1){const A=Ye(r.line(b).text,c,g);if(A===null)return null;w+=b<r.lines?`${A}
|
|
6
|
+
`:A}if(w!==n)return null;if(l>t){const b=l<r.lines?r.line(l+1).from:r.length;return{from:r.line(t+1).from,to:b,prefix:c,whiteSpaceLinesEmpty:g,lineBreak:!1}}if(t===r.lines)return{from:r.length,to:r.length,prefix:c,whiteSpaceLinesEmpty:g,lineBreak:!0};const p=r.line(t+1).from;return{from:p,to:p,prefix:c,whiteSpaceLinesEmpty:g,lineBreak:!1}},Ze=({parent:e,scroll:t,text:n,saved:r,labels:a,onChange:s,onGeometry:c,onSave:o})=>{let f=!1;const d=[P.EditorView.scrollHandler.of((l,u,g)=>(et(l,u.head,g,t),!0)),P.lineNumbers(),P.highlightActiveLineGutter(),G.history(),P.drawSelection(),P.highlightActiveLine(),fe.highlightSelectionMatches(),P.EditorView.lineWrapping,de.markdown({base:de.markdownLanguage}),le.syntaxHighlighting(Be),Ue(a),P.keymap.of([{key:"Mod-s",preventDefault:!0,run:()=>(o(),!0)},...fe.searchKeymap,...G.historyKeymap,...G.defaultKeymap]),P.EditorView.contentAttributes.of({"aria-label":a.editor,"aria-multiline":"true"}),P.EditorView.updateListener.of(l=>{l.docChanged&&s(l.transactions.every(u=>!u.docChanged||u.isUserEvent(he))),(l.docChanged||l.heightChanged||l.geometryChanged)&&c(l.docChanged&&!f)}),He],m=rt(r,d)??X.EditorState.create({doc:n,extensions:d}),i=new P.EditorView({state:m,parent:e}),x=l=>{f=!0;try{l()}finally{f=!1}};return{text:()=>i.state.doc.toString(),replaceText:l=>{const u=i.state.doc.toString();if(u===l)return;let g=0;const w=Math.min(u.length,l.length);for(;g<w&&u.charCodeAt(g)===l.charCodeAt(g);)g+=1;let p=0;for(;p<w-g&&u.charCodeAt(u.length-1-p)===l.charCodeAt(l.length-1-p);)p+=1;i.dispatch({changes:{from:g,to:u.length-p,insert:l.slice(g,l.length-p)},userEvent:"input.replace"})},replaceBody:(l,u,g)=>{const w=Qe(i.state,l,u);if(w===null)return!1;const p=Je(g,w.prefix,w.whiteSpaceLinesEmpty),b=w.lineBreak?`
|
|
7
|
+
${p}`:p;return x(()=>i.dispatch({changes:{from:w.from,to:w.to,insert:b},userEvent:he,annotations:G.isolateHistory.of("full")})),!0},undo:()=>x(()=>G.undo(i)),redo:()=>x(()=>G.redo(i)),reveal:({line:l,column:u},g)=>{const{doc:w}=i.state,p=w.line(Math.min(Math.max(l,1),w.lines)),b=Math.min(p.from+u,p.to);i.dispatch({selection:X.EditorSelection.cursor(b),effects:ge(i,b,g,t)})},showLine:l=>{const{doc:u}=i.state,g=u.line(Math.min(Math.max(l,1),u.lines)).from;i.dispatch({effects:ge(i,g,null,t)})},topLine:()=>{const l=t.scrollerOf(i.scrollDOM),u=y.visibleTopOf(l,i.contentDOM),g=y.frameTopOf(l)+l.clientHeight,{documentTop:w}=i,{doc:p}=i.state;let b=i.lineBlockAtHeight(Math.max(u-w,0));for(;p.lineAt(b.from).text.trim()===""&&b.to<p.length;){const D=i.lineBlockAt(b.to+1);if(w+D.top>=g)break;b=D}const A=i.coordsAtPos(b.from),C=A===null?w+b.top:A.top;return{line:i.state.doc.lineAt(b.from).number,clientTop:C,offset:C-u}},lineSpans:l=>{const u=i.scrollDOM,g=u.scrollTop+i.documentTop-y.visibleTopOf(u,i.contentDOM),{doc:w}=i.state,p=b=>w.line(Math.min(Math.max(b,1),w.lines)).from;return l.map(({first:b,last:A})=>({top:g+i.lineBlockAt(p(b)).top,bottom:g+i.lineBlockAt(p(A)).bottom}))},scrollElement:i.scrollDOM,focus:()=>i.focus(),conflicts:()=>ee(i.state.doc),resolveAtCursor:l=>{const u=ee(i.state.doc),g=i.state.doc.lineAt(i.state.selection.main.head).number,w=u.find(p=>p.end>=g);return w===void 0?!1:(qe(i,w,l),!0)},nextConflict:()=>{const l=ee(i.state.doc);if(l[0]===void 0)return!1;const g=i.state.doc.lineAt(i.state.selection.main.head).number,w=l.findIndex(C=>C.start>g),p=w<0?0:w,b=i.state.doc.line(l[p].start).from;i.dispatch({selection:X.EditorSelection.cursor(b),effects:P.EditorView.scrollIntoView(b,{y:"center"})});const A=i.contentDOM.querySelector(`[${Oe}="${String(p)}"] button`);return A instanceof HTMLElement?A.focus({preventScroll:!0}):i.focus(),!0},save:()=>i.state.toJSON(Re),destroy:()=>i.destroy()}},ge=(e,t,n,r)=>{const a=r.scrollerOf(e.scrollDOM),s=(n===null?y.visibleTopOf(a,e.contentDOM):n)-y.frameTopOf(a);return P.EditorView.scrollIntoView(t,{y:"start",yMargin:s})},et=(e,t,n,r)=>{const a=tt(e,t),s=r.scrollerOf(e.scrollDOM),c=y.frameTopOf(s),o=y.visibleTopOf(s,e.contentDOM),f=c+s.clientHeight;let d=0;switch(n.y){case"start":d=a.top-(c+n.yMargin);break;case"center":d=(a.top+a.bottom)/2-(o+f)/2;break;case"end":d=a.bottom-(f-n.yMargin);break;default:a.top<o+n.yMargin?d=a.top-(o+n.yMargin):a.bottom>f-n.yMargin&&(d=Math.min(a.bottom-(f-n.yMargin),a.top-(o+n.yMargin)))}if(d!==0&&(s.scrollTop+=d),n.y==="start")return;const m=nt(e,t);m!==null&&r.reveal(m)},tt=(e,t)=>{const{node:n,offset:r}=e.domAtPos(t);if(n.nodeType===Node.TEXT_NODE){const c=n.ownerDocument?.createRange();if(c!==void 0){c.setStart(n,r),c.setEnd(n,r);const[o]=c.getClientRects();if(o!==void 0&&o.height>0)return{top:o.top,bottom:o.bottom}}}const a=e.lineBlockAt(t),s=e.documentTop+a.top;return{top:s,bottom:s+a.height}},nt=(e,t)=>{const{node:n}=e.domAtPos(t);for(let r=n instanceof Element?n:n.parentElement;r!==null;r=r.parentElement)if(r.parentElement===e.contentDOM)return r;return null},rt=(e,t)=>{if(e==null)return null;try{return X.EditorState.fromJSON(e,{extensions:t},Re)}catch{return null}},ot=610,st=987,ve=Object.freeze({kind:"unavailable"}),it="true",lt="false",at=e=>e===it?!0:e===lt?!1:null,ct=e=>{const t=new DOMParser().parseFromString(e,"text/html"),n=[];for(const r of t.querySelectorAll("img[data-asset-src], a[data-doc-path]")){const a=r.localName==="img",s=r.getAttribute(a?"data-asset-src":"data-doc-path");s!==null&&n.push({target:{kind:a?"asset":"doc",path:s},exists:at(r.getAttribute(a?"data-asset-exists":"data-doc-exists"))})}return n},ut=({path:e,instant:t,preview:n,initial:r,onView:a})=>{const s=new AbortController,c={asset:new Map,doc:new Map};let o=r,f=null,d=!1,m=!1,i=null,x=null,l=[],u,g=!1,w,p=null;const b=T=>{T.parsed===o.parsed&&T.failure===o.failure&&T.busy===o.busy&&T.tier===o.tier||(o=T,a(T))},A=(T,k)=>{d||(d=!0,console.error(`[markdown-explorer] ${T}`,...k===void 0?[]:[k]))},C=T=>{if(t!==null)for(const{target:k,exists:O}of t.marksOf(T))c[k.kind].set(k.path,O)},D=()=>{clearTimeout(w),w=void 0,p?.abort(),p=null},j=()=>{x=null,l=[],clearTimeout(u),u=void 0},B=(T,k)=>{b({parsed:o.parsed,failure:T,busy:!1,tier:k})},W=()=>{clearTimeout(u),u=l.length===0?void 0:setTimeout(R,st)},S=()=>{if(t===null||x===null)return;const T=x,k=[],O={asset:new Set,doc:new Set};let E;try{E=t.sanitize(T.html,q=>{const H=c[q.kind].get(q.path);return H===void 0&&!O[q.kind].has(q.path)&&(O[q.kind].add(q.path),k.push(q)),H??void 0})}catch(q){j(),q instanceof ie.HtmlNestingLimitError?B(Q.failureOf("too-large"),"instant"):(A("the draft sanitizer failed",q),B(Q.failureOf("failed"),"instant"));return}l=k;const I=o.parsed!==null&&o.parsed.htmlContent===E&&o.parsed.headings===T.headings?o.parsed:{htmlContent:E,headings:T.headings};b({parsed:I,failure:null,busy:!1,tier:"instant"}),W()},R=()=>{if(u=void 0,g||x===null||l.length===0)return;g=!0;const T=l;n(e,x.text,s.signal).then(k=>{if(g=!1,!(s.signal.aborted||!("kind"in k))){k.kind==="preview"&&C(k.htmlContent);for(const O of T)c[O.kind].has(O.path)||c[O.kind].set(O.path,null);S()}})},M=T=>{D(),j(),b({...o,busy:!0,tier:"server"});const k=new AbortController;p=k,w=setTimeout(()=>{w=void 0,n(e,T,k.signal).then(O=>{if(!(k.signal.aborted||!("kind"in O))){if(p=null,O.kind==="failure"){B(O.failure,"server");return}C(O.htmlContent),b({parsed:{htmlContent:O.htmlContent,headings:O.headings},failure:null,busy:!1,tier:"server"})}})},ot)},v=async(T,k)=>{let O;try{O=await T.convert({path:e,text:k},s.signal)}catch(I){return s.signal.aborted||A("the draft converter rejected a conversion, which its contract allows only once the signal aborted",I),ve}const E=Q.draftAnswerViolation(O);return E===null?O:(A(`the draft converter answered outside its contract: ${E}`),ve)},V=(T,k)=>{switch(k.kind){case"preview":if(D(),k.headings.length>Q.EXPLORER_MAX_HEADINGS){j(),B(Q.failureOf("too-large"),"instant");return}x={text:T,html:k.htmlContent,headings:k.headings.map(({text:O,depth:E,id:I})=>({text:O,depth:E,id:I}))},S();return;case"failure":D(),j(),B(Q.failureOf(k.failure.reason,k.failure.code),"instant");return;case"unavailable":M(T);return}},z=async T=>{m=!0;try{for(;i!==null&&!s.signal.aborted;){const k=i;i=null;const O=await v(T,k);if(s.signal.aborted)return;V(k,O)}}finally{m=!1}};return t!==null&&t.seed!==null&&C(t.seed),{update:T=>{if(!(s.signal.aborted||T===f)){if(f=T,clearTimeout(u),u=void 0,t===null){M(T);return}i=T,m||z(t.converter)}},dispose:()=>{s.abort(),i=null,clearTimeout(u),u=void 0,D()}}},dt=(e,t)=>ie.createHtmlSanitizer(Ve(window),e,t,ie.MAX_HTML_NESTING_DEPTH),ft=(e,t)=>e.flatMap((n,r)=>{const a=t[r];return a===void 0?[]:[{editor:a.top,preview:n.top},{editor:a.bottom,preview:n.bottom}]}),K=(e,t)=>{const n=e[t];if(n===void 0)throw new RangeError(`[markdown-explorer] a scroll map index must be in 0..${String(e.length-1)}; got ${String(t)}`);return n},mt=e=>{const t=[];for(const r of e){let a=0,s=t.length;for(;a<s;){const c=a+s>>1;K(t,c).pair.preview<=r.preview?a=c+1:s=c}t[a]={pair:r,before:a===0?void 0:K(t,a-1)}}const n=[];for(let r=t.at(-1);r!==void 0;r=r.before)n.push(r.pair);return n.reverse()},pt=(e,t)=>{const n=Math.max(t.editorMax,0),r=Math.max(t.previewMax,0),a=n-t.editorViewport,s=r-t.previewViewport,c=e.filter(d=>d.editor>0&&d.editor<a&&d.preview>0&&d.preview<s).sort((d,m)=>d.editor-m.editor||d.preview-m.preview);let o={editor:0,preview:0};const f=[o];for(const d of mt(c))d.editor>o.editor&&d.preview>o.preview&&(f.push(d),o=d);return f.push({editor:n,preview:r}),{toPreview:d=>Ee(f,"editor","preview",d),toEditor:d=>Ee(f,"preview","editor",d)}},Ee=(e,t,n,r)=>{const a=K(e,0),s=K(e,e.length-1);if(Number.isNaN(r)||r<=a[t])return a[n];if(r>=s[t])return s[n];let c=0,o=e.length-1;for(;o-c>1;){const m=c+o>>1;K(e,m)[t]<=r?c=m:o=m}const f=K(e,c),d=K(e,o);return f[n]+(d[n]-f[n])*(r-f[t])/(d[t]-f[t])},ht=610,we=89,be=.5,gt=({editor:e,preview:t,previewBlocks:n,editorSpans:r,requestFrame:a,cancelFrame:s,now:c})=>{let o="editor",f=0,d=null,m=null,i=!1,x=null,l=null;const u={editor:0,preview:0},g={editor:null,preview:null};let w=null,p=()=>{};const b=v=>{d!==null&&v!==d||(o=v,f=c()+ht)},A=(v,V)=>{v!==o&&d===null&&c()>=f&&!C(v,V)&&(o=v),S()},C=(v,V)=>{const z=g[v];return c()<u[v]||z!==null&&Math.abs(V.position()-z)<be},D=e.onScroll(()=>A("editor",e)),j=e.onIntent(()=>b("editor")),B=()=>{const v=t();return v!==w&&(p(),w=v,p=v===null?()=>{}:W(v)),v},W=v=>{const V=v.onScroll(()=>A("preview",v)),z=v.onIntent(()=>b("preview"));return()=>{V(),z()}},S=()=>{!i&&m===null&&(m=a(R))},R=()=>{m=null;const v=B();v!==null&&(x??=n(),l??=pt(ft(x,r(x)),{editorMax:e.max(),previewMax:v.max(),editorViewport:e.viewport(),previewViewport:v.viewport()}),o==="editor"?M(v,"preview",l.toPreview(e.position())):M(e,"editor",l.toEditor(v.position())))},M=(v,V,z)=>{if(Math.abs(v.position()-z)<be){g[V]=v.position();return}u[V]=c()+we,g[V]=v.scrollTo(z)};return S(),{editorChanged:v=>{l=null,v&&b("editor"),S()},previewChanged:()=>{x=null,l=null,u.preview=c()+we,S()},showAlone:v=>{d=v,!(v===null||v===o)&&(o=v,f=0,S())},dispose:()=>{i=!0,m!==null&&s(m),m=null,D(),j(),p()}}},Se=Object.freeze(["wheel","pointerdown","keydown","focusin"]),Ae=e=>({position:()=>e.scrollTop,max:()=>Math.max(e.scrollHeight-e.clientHeight,0),viewport:()=>e.clientHeight,scrollTo:t=>(e.scrollTo({top:t,behavior:"instant"}),e.scrollTop),onScroll:t=>(e.addEventListener("scroll",t,{passive:!0}),()=>e.removeEventListener("scroll",t)),onIntent:t=>{for(const n of Se)e.addEventListener(n,t,{capture:!0,passive:!0});return()=>{for(const n of Se)e.removeEventListener(n,t,{capture:!0})}}}),Z="[data-aqmd-scroll-container]",vt="[data-aqmd-content]",Et=`[${se.SOURCE_LINES_ATTRIBUTE}]`,wt=Object.freeze(["p1","p2","p3","p4","p5","p6","p7","p8"]),Me=(e,t)=>{const n=y.loadedOf(e.peek(t));return n!==null&&n.document.kind==="markdown"?{htmlContent:n.document.htmlContent,headings:n.document.headings}:null},bt=(e,t,n,r,a)=>{if(n===void 0)return null;let s;try{s=dt(e,t)}catch(c){return console.error("[markdown-explorer] the draft sanitizer cannot run in this browser, so the server renders the preview",c),null}return{converter:n,sanitize:s,marksOf:ct,seed:Me(r,a)?.htmlContent??null}},St=e=>{const t=[];let n=null;for(const r of e.querySelectorAll(Et)){const a=se.parseSourceLines(r.getAttribute(se.SOURCE_LINES_ATTRIBUTE));if(a===null||r.getClientRects().length===0)continue;n??=e.scrollTop-y.visibleTopOf(e,r);const{top:s,bottom:c}=r.getBoundingClientRect();t.push({first:a.first,last:a.last,top:n+s,bottom:n+c})}return t},xt=({path:e,readDraft:t,viewer:n,spreadsheetEditor:r,concealed:a,onEditAt:s,onLayout:c,handleRef:o})=>{const{config:f,data:d,documents:m,draftConverter:i,labels:x}=y.useExplorer(),[l,u]=h.useState(()=>({parsed:Me(m,e),failure:null,busy:!0,tier:i===void 0?"server":"instant"})),g=h.useRef(null),w=h.useRef(null),p=h.useRef(l);h.useLayoutEffect(()=>{p.current=l});const b=h.useEffectEvent(()=>t());h.useEffect(()=>{const S=bt(f.iframeHosts,f.dataPath,i,m,e),R=ut({path:e,instant:S,preview:d.preview,initial:p.current,onView:M=>h.startTransition(()=>u(M))});return w.current=R,R.update(b()),()=>{R.dispose(),w.current=null}},[f,d,m,i,e]);const A=h.useEffectEvent(()=>c());h.useLayoutEffect(()=>{l.parsed!==null&&A()},[l.parsed]);const C=l.parsed!==null;h.useLayoutEffect(()=>{const S=C?g.current?.querySelector(Z):null;if(!(S instanceof HTMLElement))return;S.tabIndex=0;const R=new ResizeObserver(()=>A());R.observe(S);const M=S.querySelector(vt);return M!==null&&R.observe(M),()=>R.disconnect()},[C]);const D=h.useRef(null);h.useImperativeHandle(o,()=>({draft:S=>{w.current?.update(S)},scrollPort:()=>{const S=g.current?.querySelector(Z);return S instanceof HTMLElement?(D.current?.scroller!==S&&(D.current={scroller:S,port:Ae(S)}),D.current.port):null},blocks:()=>{const S=g.current?.querySelector(Z);return S instanceof HTMLElement?St(S):[]},focus:()=>{const S=g.current?.querySelector(Z);S instanceof HTMLElement&&S.focus({preventScroll:!0})},anchor:S=>{const R=g.current,M=R?.querySelector(Z);return R===null||!(M instanceof HTMLElement)?null:y.anchorOfView(R,S(M))},place:({line:S,clientTop:R},M)=>{const v=g.current,V=v===null?null:y.blockAtLine(v,S);V!==null&&(M(V).scrollTop+=y.lineTopIn(V,S)-R)}}),[]);const j=S=>{const R=g.current,{target:M}=S;if(s===void 0||R===null||!(M instanceof Element)||!y.isEditingDoubleClick(M))return;const v=y.anchorOfDoubleClick(M,R,R.ownerDocument.getSelection());v!==null&&s(v)},B=h.useMemo(()=>({...n,showToc:!1,showStyle:!1,showAlign:!1,renderScrollBar:void 0,spreadsheetEditor:r}),[n,r]),W=h.useMemo(()=>l.parsed===null?null:L.jsx("div",{className:"aqmx-document-viewer",children:L.jsx(De.MarkdownViewer,{...B,parseResult:l.parsed,content:null})}),[B,l.parsed]);return L.jsxs("section",{ref:g,className:"aqmx-edit-preview","aria-label":x.previewRegion,"aria-busy":l.busy,inert:a!==null,hidden:a==="removed","data-aqmx-preview-tier":l.tier,"data-testid":"markdown-explorer-edit-preview",onDoubleClick:s===void 0?void 0:j,children:[l.failure===null?null:L.jsx("p",{className:"aqmx-callout aqmx-document-notice","data-aqmx-tone":"warning","data-testid":"markdown-explorer-edit-preview-failure",children:x.previewFailed(y.failureTitleOf(x,l.failure.reason))}),W??(l.failure===null?L.jsx("div",{className:"aqmx-skeleton","aria-hidden":"true","data-testid":"markdown-explorer-edit-preview-skeleton",children:wt.map(S=>L.jsx("span",{},S))}):null),l.busy?L.jsx("p",{className:"aqmx-sr-only",children:x.previewUpdating}):null]})},xe="data-aqmx-edit-split",oe="--aqmx-edit-share",ye="--aqmx-edit-gutter",yt="data-aqmx-edit-split-probe",Tt="aqmx-edit-split",kt="aqmx-edit-editor",Lt="aqmx-edit-preview",Te={value:U.EDIT_SPLIT_MIN_PERCENT,unit:"percentage"},ke={value:U.EDIT_SPLIT_MAX_PERCENT,unit:"percentage"},Le=e=>{if(e.length!==2)return null;const[t=0,n=0]=e,r=t+n;return r>0?t/r*100:null},ne=e=>{const t=e.current?.parentElement;if(t==null)throw new Error("[markdown-explorer] the edit split is not mounted in its surface");return t},Rt=(e,t,n)=>{const[r,a]=h.useState(null);return h.useLayoutEffect(()=>{const s=e.current,c=t.current;if(s===null||c===null)throw new Error("[markdown-explorer] the edit split is not mounted");const o={frame:s.getBoundingClientRect().width,measure:c.getBoundingClientRect().width},f=()=>{o.frame>0&&o.measure>0&&a(U.editSplitOrientation(o.frame,o.measure,n))};f();const d=new ResizeObserver(m=>{for(const i of m){const[x]=i.borderBoxSize;x!==void 0&&(i.target===s&&(o.frame=x.inlineSize),i.target===c&&(o.measure=x.inlineSize))}f()});return d.observe(s),d.observe(c),()=>d.disconnect()},[e,t,n]),r},Ot=({editorId:e})=>{const{edits:t,labels:n}=y.useExplorer(),r=h.useRef(null),a=h.useRef(null),s=me.useCoarsePointer()?U.COARSE_TARGET_PIXELS:U.FINE_TARGET_PIXELS,c=Rt(r,a,s),[o]=h.useState(()=>t.editorShare());h.useLayoutEffect(()=>{const m=ne(r);return m.style.setProperty(ye,`${String(s)}px`),()=>{m.style.removeProperty(ye)}},[s]),h.useLayoutEffect(()=>{const m=ne(r);return m.style.setProperty(oe,`${String(o)}%`),()=>{m.style.removeProperty(oe)}},[o]),h.useLayoutEffect(()=>{if(c===null)return;const m=ne(r);return m.setAttribute(xe,c),()=>m.removeAttribute(xe)},[c]);const f=me.useSplitPersistence(h.useCallback(m=>{const i=Le(m);i!==null&&t.setEditorShare(i)},[t])),d=h.useCallback((m,i)=>{const x=Le(m);x!==null&&ne(r).style.setProperty(oe,`${String(x)}%`),f.layoutChanged(m,i)},[f]);return L.jsxs("div",{ref:r,className:"aqmx-edit-split","data-testid":"markdown-explorer-edit-split",children:[L.jsx("span",{ref:a,className:"aqmx-edit-split-probe","aria-hidden":"true",[yt]:""}),c===null?null:L.jsxs(te.PanelGroup,{id:Tt,direction:c==="beside"?"horizontal":"vertical",onLayout:d,className:"aqmx-edit-split-group",children:[L.jsx(te.Panel,{id:kt,defaultSize:{value:o,unit:"percentage"},minSize:Te,maxSize:ke,contentOverflow:"hidden"}),L.jsx(te.PanelResizeHandle,{thickness:s,indicator:{visible:!0,thickness:U.SPLIT_HANDLE_PIXELS.gripThickness,length:U.SPLIT_HANDLE_PIXELS.gripLength,barThickness:U.SPLIT_HANDLE_PIXELS.barThickness,barLength:U.SPLIT_HANDLE_PIXELS.barLength},title:n.editViewSplitResize,"aria-label":n.editViewSplitResize,"aria-controls":e,onDragging:f.draggingChanged,className:"aqmx-split-handle aqmx-edit-split-handle"}),L.jsx(te.Panel,{id:Lt,defaultSize:{value:100-o,unit:"percentage"},minSize:Te,maxSize:ke,contentOverflow:"hidden"})]})]})},Ce=144,qt="[data-aqmd-spreadsheet-fullscreen]",It=Object.freeze(["e1","e2","e3","e4","e5","e6","e7","e8"]),At=e=>{if(typeof e!="object"||e===null)return!1;const{generation:t,topLine:n}=e;return"state"in e&&typeof t=="number"&&typeof n=="number"},Mt=e=>{e.stopPropagation()},Ct=e=>{const{path:t,name:n,session:r}=e,{edits:a,labels:s,announcer:c}=y.useExplorer(),{phase:o}=r,f=h.useCallback(()=>a.retry(t),[a,t]);switch(h.useEffect(()=>{o.kind==="failed"&&c.announce(s.documentFailed(n,y.failureTitleOf(s,o.failure.reason)))},[o,c,s,n]),o.kind){case"opening":return L.jsxs(L.Fragment,{children:[L.jsx("div",{className:"aqmx-skeleton","aria-hidden":"true","data-testid":"markdown-explorer-edit-skeleton",children:It.map(d=>L.jsx("span",{},d))}),L.jsx("p",{className:"aqmx-sr-only",children:s.editLoading})]});case"grant":return L.jsx("div",{className:"aqmx-edit-message",children:L.jsx(y.EditGrantNotice,{href:o.href,onRetry:f,testId:"markdown-explorer-edit-grant"})});case"failed":return L.jsx("div",{className:"aqmx-edit-message",children:L.jsx(y.FailureView,{failure:o.failure,alert:!1,onRetry:f,testId:"markdown-explorer-edit-failure"})});case"editing":return L.jsx(_t,{...e})}},_t=({path:e,name:t,session:n,layout:r,viewer:a,region:s,paneScroll:c})=>{const{edits:o,labels:f}=y.useExplorer(),d=h.useRef(null),m=h.useId(),i=h.useRef(null),[x]=h.useState(()=>new Set),l=h.useRef(null),u=h.useRef(null),g=r==="fill",w=y.useSideBySide(),p=y.editViewOf(n,w,g),b=p!=="editor"||n.previewPrepared,A=b&&g,C=h.useRef({layout:r,region:s,paneScroll:c});h.useLayoutEffect(()=>{C.current={layout:r,region:s,paneScroll:c}});const D=h.useRef(n.generation);h.useLayoutEffect(()=>{D.current=n.generation});const j=h.useRef({view:p,previewMounted:b});h.useLayoutEffect(()=>{j.current={view:p,previewMounted:b}});const B=h.useRef(null),W=h.useRef(null),S=h.useRef(!1),R=h.useMemo(()=>({editor:f.editorLabel(t),useOurs:f.conflictUseOurs,useTheirs:f.conflictUseTheirs,keepBoth:f.conflictKeepBoth}),[f,t]),M=h.useCallback(E=>{const{region:I,paneScroll:q}=C.current,H=I();return H===null?E:q.scrollerOf(H,E)},[]);h.useLayoutEffect(()=>{const E=d.current,I=o.draft(e);if(E===null||I===null)return;const q=o.editorState.get(e),H=At(q)&&q.generation===D.current?q:null;let $=null,Y=null;const re=()=>{$!==null&&clearTimeout($),$=null,Y!==null&&o.setDraft(e,Y.text())},F=Ze({parent:E,scroll:{scrollerOf:_=>{const{layout:J,region:Pe,paneScroll:Ne}=C.current,ue=Pe();return J==="fill"||ue===null?_:Ne.scrollerOf(ue,_)},reveal:_=>C.current.paneScroll.reveal(_)},text:I,saved:H===null?void 0:H.state,labels:R,onGeometry:_=>u.current?.editorChanged(_),onChange:_=>{if($??=setTimeout(re,Ce),!_)for(const J of[...x])J();j.current.previewMounted&&Y!==null&&l.current?.draft(Y.text())},onSave:()=>{o.save(e)}});Y=F,i.current=F;const ae=()=>{const _=F.topLine();return{line:_.line,clientTop:_.clientTop}},ce=()=>l.current?.anchor(M)??null,_e=o.bindEditor(e,{flush:re,adopt:_=>F.replaceText(_),returnPoint:()=>{const _=j.current.view==="preview"&&C.current.layout==="content"?ce():null;return _===null?ae():{line:_.lines.first,clientTop:_.clientTop}},nextConflict:()=>j.current.view!=="preview"?F.nextConflict():F.conflicts().length===0?!1:(S.current=!0,o.setView(e,"editor"),!0),beforeView:_=>{if(C.current.layout==="fill")return;if(_==="preview"){B.current={to:"preview",point:ae()};return}const J=ce();B.current=J===null?null:{to:"editor",anchor:J}}});return H!==null&&F.showLine(H.topLine),()=>{re(),o.editorState.set(e,{state:F.save(),generation:D.current,topLine:F.topLine().line}),_e(),F.destroy(),Y=null,i.current=null}},[o,e,R,M,x]);const{request:v}=n;h.useLayoutEffect(()=>{const E=i.current,I=o.draft(e);E===null||I===null||v===null||(v.anchor!==null&&E.reveal(y.positionInSource(I,v.anchor),v.anchor.clientTop),E.focus(),o.consumeRequest(e))},[o,e,v,R]),h.useLayoutEffect(()=>{p!=="editor"&&!n.previewPrepared&&o.preparePreview(e)},[o,e,p,n.previewPrepared]),h.useLayoutEffect(()=>{const E=B.current,I=W.current,q=S.current;B.current=null,W.current=null,S.current=!1;const H=i.current;if(E?.to==="preview")l.current?.place(E.point,M);else if(E?.to==="editor"&&H!==null){const $=o.draft(e);$!==null&&H.reveal(y.positionInSource($,E.anchor),E.anchor.clientTop)}q?H?.nextConflict():I==="editor"?H?.focus():I==="preview"&&l.current?.focus()},[o,e,p,M]);const V=h.useMemo(()=>({write:({fenceLine:E,expected:I,text:q})=>i.current?.replaceBody(E,I,q)===!0,undo:()=>i.current?.undo(),redo:()=>i.current?.redo(),subscribe:E=>(x.add(E),()=>{x.delete(E)})}),[x]),z=h.useCallback(()=>{const E=i.current;if(E===null)throw new Error("[markdown-explorer] the preview read the draft before the editor was mounted");return E.text()},[]);h.useLayoutEffect(()=>{const E=i.current;if(!A||E===null)return;const I=gt({editor:Ae(E.scrollElement),preview:()=>l.current?.scrollPort()??null,previewBlocks:()=>l.current?.blocks()??[],editorSpans:q=>E.lineSpans(q),requestFrame:q=>requestAnimationFrame(q),cancelFrame:q=>cancelAnimationFrame(q),now:()=>performance.now()});return I.showAlone(y.paneShownAlone(j.current.view)),u.current=I,()=>{I.dispose(),u.current=null}},[A,o,e,R]),h.useLayoutEffect(()=>{u.current?.showAlone(y.paneShownAlone(p))},[p]);const T=h.useCallback(()=>u.current?.previewChanged(),[]),k=h.useCallback(E=>o.start(e,E),[o,e]),O=E=>{if(E.target instanceof Element&&E.target.closest(qt)!==null)return;if(E.key==="Escape"){y.consumeKey(E);return}if(!y.isEditViewShortcut(E.nativeEvent,y.isApplePlatform(navigator.platform)))return;y.consumeKey(E);const I=y.toggledEditView(p);W.current=I,y.chooseEditView(o,e,I,g)};return L.jsxs("div",{className:"aqmx-edit","data-aqmx-edit-layout":r,"data-aqmx-edit-view":p,"data-testid":"markdown-explorer-edit",onKeyDown:O,onDoubleClick:Mt,children:[L.jsx("div",{ref:d,id:m,className:"aqmx-edit-editor","data-testid":"markdown-explorer-editor",inert:p==="preview",hidden:p==="preview"&&!g,...y.ALLOW_KEY_REPEAT}),p==="split"?L.jsx(Ot,{editorId:m}):null,b?L.jsx(xt,{path:e,readDraft:z,viewer:a,spreadsheetEditor:V,concealed:p!=="editor"?null:g?"overlay":"removed",onEditAt:p==="preview"?k:void 0,onLayout:T,handleRef:l}):null]})};exports.DRAFT_WRITE_INTERVAL_MS=Ce;exports.default=Ct;
|