@aiquants/markdown-explorer 0.25.0 → 0.27.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.
Files changed (53) hide show
  1. package/CHANGELOG.md +77 -0
  2. package/README.md +40 -25
  3. package/dist/{EditSurface-Co4Rvfa1.cjs → EditSurface-B1yD7ywF.cjs} +1 -1
  4. package/dist/{EditSurface-Blymamic.js → EditSurface-sUNqYw9o.js} +5 -5
  5. package/dist/{ExplorerSplit-WApgYMPb.cjs → ExplorerSplit-Bn3ZnEMZ.cjs} +1 -1
  6. package/dist/{ExplorerSplit-BZ0PA3z3.js → ExplorerSplit-pClUl3-e.js} +3 -3
  7. package/dist/{MultiLayout-dAW_JCzg.cjs → MultiLayout-0Jh08fxo.cjs} +1 -1
  8. package/dist/{MultiLayout-B5-1N3JD.js → MultiLayout-B-ft4_Vs.js} +4 -4
  9. package/dist/{NativeScrollBar-BraWuZvN.js → NativeScrollBar-ByawerpG.js} +1 -1
  10. package/dist/{NativeScrollBar-ThVMbI0Y.cjs → NativeScrollBar-D9QrjRJa.cjs} +1 -1
  11. package/dist/{TreeLayout-C60lb9hP.cjs → TreeLayout-CXHbKdxy.cjs} +1 -1
  12. package/dist/{TreeLayout-CChoxh9W.js → TreeLayout-DjIVKBG4.js} +3 -3
  13. package/dist/core/config.d.cts +7 -0
  14. package/dist/core/config.d.ts +7 -0
  15. package/dist/core/contracts.d.cts +8 -2
  16. package/dist/core/contracts.d.ts +8 -2
  17. package/dist/core/dataRoute.d.cts +40 -0
  18. package/dist/core/dataRoute.d.ts +40 -0
  19. package/dist/core/labels.d.cts +10 -1
  20. package/dist/core/labels.d.ts +10 -1
  21. package/dist/{dataRoute-BEvesOvN.js → dataRoute-DLhQfdoW.js} +111 -103
  22. package/dist/dataRoute-DwYtgyt6.cjs +1 -0
  23. package/dist/index-BNAkC0g3.js +4800 -0
  24. package/dist/index-DRMNpWDJ.cjs +15 -0
  25. package/dist/index.cjs +1 -1
  26. package/dist/index.d.cts +2 -2
  27. package/dist/index.d.ts +2 -2
  28. package/dist/index.js +27 -26
  29. package/dist/{location-DIxIjqs7.js → location-BNFdxzhn.js} +134 -130
  30. package/dist/location-yvU5HUY1.cjs +1 -0
  31. package/dist/{merge-DRWmjC24.cjs → merge-BBU1pDoT.cjs} +1 -1
  32. package/dist/{merge-CgSp-0Dd.js → merge-DhHzRcAI.js} +1 -1
  33. package/dist/{sanitizePolicy-gVKBhabq.js → sanitizePolicy-By0tKOpZ.js} +1 -1
  34. package/dist/{sanitizePolicy-CZwOaJ92.cjs → sanitizePolicy-T5T-3vV5.cjs} +1 -1
  35. package/dist/sanitizeWorker.cjs +1 -1
  36. package/dist/sanitizeWorker.js +1 -1
  37. package/dist/server/ports.d.cts +4 -3
  38. package/dist/server/ports.d.ts +4 -3
  39. package/dist/server.cjs +1 -1
  40. package/dist/server.js +500 -493
  41. package/dist/styles/markdown-explorer.css +1 -1
  42. package/dist/{useSplitPersistence-Df63lnQZ.js → useSplitPersistence-D5EjJwCg.js} +1 -1
  43. package/dist/{useSplitPersistence-D-T75Hlh.cjs → useSplitPersistence-xGOSwpLM.cjs} +1 -1
  44. package/docs/behavior/dom-hooks.md +10 -6
  45. package/docs/behavior/layout.md +8 -3
  46. package/docs/behavior/localization.md +5 -2
  47. package/docs/behavior/security.md +7 -2
  48. package/docs/behavior/url-contract.md +3 -3
  49. package/package.json +5 -5
  50. package/dist/dataRoute-Cv7fgCW7.cjs +0 -1
  51. package/dist/index-B6FkGD-p.cjs +0 -13
  52. package/dist/index-Bd6hgisa.js +0 -4097
  53. package/dist/location-D3DgoELB.cjs +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,82 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.27.0 (2026-10-27) — Workbooks shown sheet by sheet: Excel and OpenDocument read in the browser
4
+
5
+ ### Breaking
6
+
7
+ - **A spreadsheet document's `firstSheetOnly` is replaced by `firstSheetText` (hosts).** `format` is `"csv"`, `"tsv"`
8
+ or the new `"workbook"` (an Office Open XML workbook or an OpenDocument spreadsheet, which the browser reads), and
9
+ `firstSheetText` (`"csv"`, `"tsv"` or `null`; `null` for every CSV or TSV file and for a stored workbook) names the text
10
+ of the first sheet your storage delivers when it converts the file on read and cannot deliver the workbook. An answer
11
+ that still carries `firstSheetOnly` breaks the contract (logged, `failed`). A host that exported a Google Sheets
12
+ spreadsheet as CSV with `firstSheetOnly: true` answers `{ format: "workbook", firstSheetText: "csv" }` and exports it as
13
+ `.xlsx` when the `asset` port is asked for a workbook (below).
14
+ - **The `asset` port's fourth argument is `{ delivery }` instead of `{ redirect }` (hosts).** `delivery` is `"file"` for
15
+ the stored file (the only delivery a redirect may answer, where `redirect` was `true`), `"text"` for `&as=text` and the
16
+ `text` operation, and `"workbook"` for the new `&as=workbook`, for which a storage that converts the file on read
17
+ delivers a workbook.
18
+ - **The label `spreadsheetFirstSheetOnly` is gone (hosts).** A host that overrode it overrides
19
+ `spreadsheetWorkbookFirstSheet`, which says the whole workbook could not be read.
20
+ - **The peers `@aiquants/markdown` and `@aiquants/spreadsheet` are `^11.6.3` and `^0.17.2` (hosts).**
21
+
22
+ ### Added
23
+
24
+ - **Workbooks show every shown sheet (readers).** An `.xlsx`, `.xlsm` or `.ods` file, and a workbook a storage converts
25
+ on read, is read whole through the workbook delivery and opened in the browser by the explorer's own reader (the
26
+ browser's built-ins only: no dependency); its shown sheets are tabs above the table (manual activation: the arrow keys,
27
+ Home and End move the focus, Enter, Space or a press selects; 44 px targets in a row that wraps), each read when first
28
+ shown and kept, the chosen one kept across a refresh. Hidden sheets and sheets without a table are left out and
29
+ counted in a note; a cell shows its stored value through its number format (dates and times in both date systems,
30
+ percentages, fixed decimals with grouping); a password-protected workbook, bytes that are no workbook (a legacy `.xls`
31
+ included) and a workbook past the budget show a note with the download. A document with `firstSheetText` whose
32
+ delivery brings no workbook shows its first sheet's text as before, below the note `spreadsheetWorkbookFirstSheet`.
33
+ - **`spreadsheets.maxWorkbookBytes`** (a positive integer up to 256 MiB, default 8 MiB, `WORKBOOK_BYTE_LIMITS`): the
34
+ most bytes the browser reads of a workbook.
35
+ - **The asset's workbook delivery (`&as=workbook`)**: the whole file the port delivers for `delivery: "workbook"`, as an
36
+ `application/octet-stream` attachment with the ETag `"workbook;<version>"` (a `Range` is ignored).
37
+ - **`createFileSystemSource` answers `.xlsx`, `.xlsm` and `.ods` files as `workbook` spreadsheet documents**, where they
38
+ were `file` documents (downloads).
39
+ - Exports: `WORKBOOK_BYTE_LIMITS` and the type `ExplorerSheetTextFormat`.
40
+ - Labels: `spreadsheetSheets`, `spreadsheetSheetName`, `spreadsheetUnshownSheets`, `spreadsheetUnlistedSheets`,
41
+ `spreadsheetSheetLoading`, `spreadsheetSheetEmpty`, `spreadsheetWorkbookEncrypted`, `spreadsheetNotWorkbook`,
42
+ `spreadsheetWorkbookTooLarge` and `spreadsheetWorkbookFirstSheet`.
43
+
44
+ ### Changed
45
+
46
+ - **A workbook has no Source toggle, and its Open in a new tab opens the file itself (readers)**, unless the document
47
+ names its first sheet's text, which opens as plain text.
48
+ - **Tables take the 11.6.3 block and the 0.17.2 grid (readers).** A block without its toolbar starts with no highlight
49
+ bands; a refit of the columns reads a quoted font family name that holds a comma; a press into a tall grid keeps the
50
+ page still, and PageUp and PageDown measure what the reader sees and always move a row.
51
+
52
+ ### Demo
53
+
54
+ - **`notes/tables/workbook.xlsx` (three sheets, a hidden sheet and a chart sheet) and `notes/tables/workbook.ods` (two
55
+ tables and a hidden one)**, linked from the guide; the guide's file the explorer cannot show is now
56
+ `notes/report.xls`, a legacy Excel workbook.
57
+
58
+ ## 0.26.0 (2026-10-27) — Tables drawn as their original print, on @aiquants/markdown 11.6.1 and @aiquants/spreadsheet 0.17.1
59
+
60
+ ### Breaking
61
+
62
+ - **The peers `@aiquants/markdown` and `@aiquants/spreadsheet` are `^11.6.1` and `^0.17.1` (hosts).** The explorer is
63
+ built and tested on the table block's display options and the grid's content size; a `^` range in 0.x does not span
64
+ 0.16 and 0.17, so a host updates the three packages together.
65
+
66
+ ### Changed
67
+
68
+ - **A document's ```spreadsheets tables and a table file's preview take the 11.6.1 block (readers).** A table narrower
69
+ than its column keeps its box at the table's width while the toolbar keeps the column's; a table whose `height` (15 when
70
+ not given) reaches the rows its grid shows, an editable table's spare row included, shows every row in a box the document
71
+ scrolls past, under a wheel or a finger too; a keyboard move in a table taller than the document's view scrolls the view to
72
+ the active cell, and PageUp / PageDown move by the part of the table the view shows; and a writer can draw a table as its
73
+ original print (`toolbar=0 headings=0 autofit=1 zoom=71 height=1000`).
74
+
75
+ ### Demo
76
+
77
+ - **`notes/spreadsheets.md` gains "As printed" and "Narrow"**: a 60-row table with
78
+ `header=1 footer=1 toolbar=0 headings=0 autofit=1 zoom=71 height=1000`, and a two-column table with its toolbar.
79
+
3
80
  ## 0.25.0 (2026-10-27) — Open in a new tab names the encoding the explorer reads a file in
4
81
 
5
82
  ### Breaking
package/README.md CHANGED
@@ -28,10 +28,11 @@ Inside a rendered document, a storage SVG image that stands alone in a paragraph
28
28
  a toolbar above it, at the row's end: the toggle shows the image's SVG in its place through the same operation, and the
29
29
  image again on a second press, and Copy copies the image as a PNG that pastes as an image while the image shows, and the
30
30
  SVG as written while the source shows.
31
- A table file — a CSV or TSV file, or a workbook the host exports as one, such as a Google Sheets spreadsheet's first
32
- sheet — shows as a read-only grid under its file header, named after the file: the browser reads the file itself in its
33
- encoding (a byte order mark's, UTF-8 or the configured legacy encoding) and stops once the table holds as much as a
34
- grid shows, saying so (see [Table files](#table-files)).
31
+ A table file — a CSV or TSV file, or a workbook: Excel `.xlsx` and `.xlsm`, OpenDocument `.ods`, and one the host
32
+ converts on read, such as a Google Sheets spreadsheet — shows as a read-only grid under its file header, named after
33
+ the file: the browser reads the file itself, a text file in its encoding (a byte order mark's, UTF-8 or the configured
34
+ legacy encoding) and a workbook with every shown sheet behind a tab, and stops once the table holds as much as a grid
35
+ shows, saying so (see [Table files](#table-files)).
35
36
  With the server's `edit` ports, a Markdown document also offers **Edit**: the reader edits its Markdown in place
36
37
  (CodeMirror, loaded on demand), from where they were reading or from the word they double-clicked, saves over the
37
38
  version the draft started from (changes saved elsewhere are merged line by line, and conflicts are resolved in the
@@ -48,12 +49,12 @@ A single-view (embedding) page never downloads the tree and multi-panel views, w
48
49
 
49
50
  - React 19.2.7 or later and React Router 8 in framework mode (route modules with `loader` / `headers`).
50
51
  - Node.js 22.22 or later (the floor React Router 8 declares). The package ships ES modules and CommonJS; the CommonJS entries load the ESM-only `react-router` through `require(esm)`.
51
- - The peer packages, at these versions or later within the caret ranges the package declares: `@aiquants/markdown` ^11.3.0 (document rendering; the Source toggle of a storage SVG image that stands alone in a paragraph, read through `imageSource`, and a Copy that copies the image as a PNG image or its source, the source readable in every display style, a notice in place of a block that cannot render and plain text for a fence in a language it does not know; its components' stylesheet without utilities,
52
- its controls' 44 px targets under every pointer, ```spreadsheets tables — inside list items and quotes too, and in a pane of their own (`layout="fill"`) never fewer than three rows — and their write-back through an editor that answers what came of each write (written, changed, a line that would close the fence, unwritable), reads a block's body back and tells them of its other changes,
52
+ - The peer packages, at these versions or later within the caret ranges the package declares: `@aiquants/markdown` ^11.6.3 (document rendering; the Source toggle of a storage SVG image that stands alone in a paragraph, read through `imageSource`, and a Copy that copies the image as a PNG image or its source, the source readable in every display style, a notice in place of a block that cannot render and plain text for a fence in a language it does not know; its components' stylesheet without utilities,
53
+ its controls' 44 px targets under every pointer, ```spreadsheets tables — inside list items and quotes too, and in a pane of their own (`layout="fill"`) never fewer than three rows, with the display options `toolbar=`, `zoom=`, `headings=` and `autofit=`, every row shown when `height` reaches the table's, and boxes no wider than the table — and their write-back through an editor that answers what came of each write (written, changed, a line that would close the fence, unwritable), reads a block's body back and tells them of its other changes,
53
54
  the React-free `@aiquants/markdown/code-blocks` that names the `data-code-meta` the sanitizer keeps on `code`, holds the converter's reading of a fenced block's lines and the table labels with their placeholders,
54
55
  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),
55
56
  `@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),
56
- `@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.16.1 (the grid of those tables — one `role="grid"` with header rows,
57
+ `@aiquants/drag-drop-panels` ^0.12.0 (the panel headers' move menu, named by the explorer's `panelMove`, their 44 px buttons under every pointer and the header arrangement the behavior docs follow), `@aiquants/resize-panels` ^2.2.0 (the source of each layout change, by which the tree pane's width is saved), `@aiquants/spreadsheet` ^0.17.2 (the grid of those tables — one `role="grid"` with header rows, the content size a box is fitted to and a keyboard move the document follows,
57
58
  read-only where it cannot write and named by its block — which markdown loads only for a document that holds one, and the grid of a table file's preview, whose TSV grammar (`@aiquants/spreadsheet/tsv`) reads a TSV file — `iterateTsvPrefixRows` the rows of a file read partway — and whose operation budget (`SPREADSHEET_MAX_OPERATION_CELLS` of `@aiquants/spreadsheet/view`) bounds its table) and `@aiquants/virtualscroll` ^3.22.1 (44 px scroll-to-edge pills and tap-scroll circles, the pills' text at the body step).
58
59
  The client depends on these floors, while a package manager may only warn about an older peer.
59
60
  - A Markdown parser of your choice on the server that produces HTML and its headings (the explorer sanitizes the HTML before it is sent).
@@ -103,7 +104,7 @@ The source ids are not part of it: they are the ids of the server's `sources` (a
103
104
  | `embeds?` | `{ providers?, linkCards?, linkCardSize? }` | What `@aiquants/markdown` makes of a link alone in a paragraph. `providers` lists the ids (`EMBED_PROVIDER_IDS` of `@aiquants/markdown/embeds`: `youtube`, `x`, `instagram`, `threads`, `tiktok`, `bluesky`, `linkedin`, `reddit`, `note`, `niconico`) whose posts and videos documents embed as cross-origin frames, whatever the link's text. `linkCards: true` turns a link written as its own URL into a card, which the data route's own `link-card` operation serves (see [Link cards](#link-cards)): no route of yours is needed. `linkCardSize` picks the size of every card, `compact`, `banner` or `full` (`LINK_CARD_SIZES` of `@aiquants/markdown/embeds`; `@aiquants/markdown`'s `banner` when omitted), and needs `linkCards: true`. Each field defaults to none (`[]`, `false`, omitted), also when given as `undefined`, so without the option such a link stays its paragraph. Repeated ids are removed. An unknown id, a `linkCards` that is not a boolean, an unknown size, a size without `linkCards: true` or an unknown key (`linkCardEndpoint` included) throws a `RangeError` (`[markdown-explorer] embeds…`), and anything but a plain object a `TypeError`. The resolved `config.embeds` is the `MarkdownEmbeds` the viewer takes: `linkCardEndpoint` is `<dataPath>/link-card` when link cards are on and `null` otherwise, and `linkCardSize` is present only when given. See `@aiquants/markdown`'s README (Embeds) for the URLs each provider recognizes, the frames' sizes and the cards' sizes. |
104
105
  | `defaultTreeSettings?` | `Partial<TreeSettings>` | The reader's tree settings before they change any, merged over the package's `DEFAULT_TREE_SETTINGS` (the source's own order, folders and READMEs mixed among the files, Single selection, a recursive double click, 8 px expand icons, nothing kept expanded, the open document not revealed, the root indent kept, lines, expand icons and folder and file icons on). Each value is one the settings menu offers: `sortMode` `"native"`, `"asc"`, `"desc"`, `"oldest"` or `"newest"` (by the entries' `modifiedAt`); `folderPlacement` `"mixed"`, `"first"` or `"last"`; `readmePlacement` `"mixed"`, `"first"` or `"last"`; `selectionMode` `"single"`, `"multiple"` or `"none"`; `doubleClickAction` `"recursive"` or `"toggle"`; `expandIconSize` `8`, `13` or `5`; the other settings (`alwaysExpanded`, `revealDocument`, `removeRootIndent`, `lines`, `expandIcons`, `directoryIcons`, `fileIcons`) `true` or `false`. An unknown key or any other value throws a `RangeError`, and anything but a plain object (a `Map`, a class instance, an object inheriting its settings) throws a `TypeError`; a setting given as `undefined` keeps the package default. The server render and the hydration draw these defaults (see [Tree settings](#tree-settings)). |
105
106
  | `legacyTextEncoding?` | `string` | The legacy encoding of the files the explorer reads as text: a WHATWG label `TextDecoder` knows (for example `Shift_JIS`, `sjis` or `windows-1252`), resolved to the encoding's written name (`Shift_JIS`; `legacyTextEncodingOf`). UTF-8 and UTF-16 (read before it, and only by a byte order mark), ISO-2022-JP (seven-bit, so UTF-8 always reads it first) and x-user-defined (no text encoding) are refused with a `RangeError` naming why. The explorer reads a file's bytes in it when they carry no byte order mark and are not UTF-8 — a table file it shows as a table and a document it shows as written alike (see [Table files](#table-files)); give `createFileSystemSource` the same encoding for its text and Markdown files. None when omitted: a table file of such bytes is then not shown as a table, and a document shown as written shows them as UTF-8, with U+FFFD for each sequence UTF-8 cannot read. |
106
- | `spreadsheets?` | `{ maxBytes? }` | A table file's preview: the most bytes the browser reads of the file (a positive integer up to 256 MiB; default 2 MiB, the most a Source view reads by default; `SPREADSHEET_BYTE_LIMITS`), which stops sooner once the table holds as many cells as a preview shows (see [Table files](#table-files)). The browser parses what it reads on its main thread, at a cost that grows with the bytes rather than with the cells it shows, so a larger value costs a pathological file (one long row, one long cell) more time. The field defaults on its own, also when given as `undefined`. |
107
+ | `spreadsheets?` | `{ maxBytes?, maxWorkbookBytes? }` | A table file's preview (see [Table files](#table-files)). `maxBytes`: the most bytes the browser reads of a CSV or TSV file (a positive integer up to 256 MiB; default 2 MiB, the most a Source view reads by default; `SPREADSHEET_BYTE_LIMITS`), which stops sooner once the table holds as many cells as a preview shows; the browser parses what it reads on its main thread, at a cost that grows with the bytes rather than with the cells it shows, so a larger value costs a pathological file (one long row, one long cell) more time. `maxWorkbookBytes`: the most bytes the browser reads of a workbook, which it needs whole (a positive integer up to 256 MiB; default 8 MiB; `WORKBOOK_BYTE_LIMITS`); a larger workbook shows a note with the download, or its first sheet as text when the document names one. Each field defaults on its own, also when given as `undefined`. |
107
108
 
108
109
  For example, `defaultTreeSettings: { sortMode: "desc" }` lists every folder's entries by name, Z to A, until the reader picks another order.
109
110
 
@@ -327,7 +328,7 @@ In the tree view a folder can be selected as GitHub's file tree does, and the vi
327
328
  | `scopeSecret` | `string` | The deployment's secret for the readers' scopes: at least 32 characters (a shorter one throws a `RangeError`) and the same on every server instance. |
328
329
  | `sources` | `ExplorerSource<P>[]` | The sources in switcher order (at least one; the first is the default): `id` (lowercase letters, digits and `-`, starting with a letter or digit, unique; the URL's `source` value), `label` (a string, or a function of the principal), `boundary` (where the source's documents may lie, see [Source boundaries](#source-boundaries)), `tree(context)` (lists the source's roots), `children?(context, path, readPath)` for lazy folders (asked only while the tree shows the folder open — the reader opened it, Expand all opened it (a press keeps opening folders as their listings land, within `expandAll`), or a remembered expansion opened it — and only for a path inside the source's boundary; a listing no tree wants any more is aborted through `context.signal`, which the source should honour), `ancestors?(context, path, readPath, options)` (the folders down to a document, for the reader's reveal; see [Revealing the open document](#revealing-the-open-document)), `cacheScope?` (`"principal"`, the default, or `"shared"`). The `context` is described under [Entries and notices](#entries-and-notices). |
329
330
  | `document` | `(context, path, readPath) => Promise<ExplorerHostDocument>` | Resolves a document path. Called only for a path inside at least one source's boundary; `readPath` is what the admitting source's `confirm` answered (`path` when that source has no `confirm`), so read `readPath` and show the document as `path`. An image, media, text or file document reports its file's `version`; the explorer writes its URL (see [Documents](#documents)). |
330
- | `asset` | `(context, path, readPath, options) => Promise<ExplorerAssetFile \| ExplorerAssetRedirect>` | Finds the file behind the data route's `asset` operation (and its `text` operation, which reads a Markdown document's source through it): any regular file the document admission admits, whatever its kind. Called only after the path passed the deny rules and the same union admission as a document, with the same `readPath`; see [Serving files](#serving-files). With `options.redirect` true it may answer a short-lived URL instead, see [Redirecting to the storage](#redirecting-to-the-storage). |
331
+ | `asset` | `(context, path, readPath, options) => Promise<ExplorerAssetFile \| ExplorerAssetRedirect>` | Finds the file behind the data route's `asset` operation (and its `text` operation, which reads a Markdown document's source through it): any regular file the document admission admits, whatever its kind. Called only after the path passed the deny rules and the same union admission as a document, with the same `readPath`; see [Serving files](#serving-files). `options.delivery` says what the explorer delivers of the file (`"file"`, `"text"` or `"workbook"`): with `"file"` it may answer a short-lived URL instead, see [Redirecting to the storage](#redirecting-to-the-storage), and with `"workbook"` a storage that converts the file on read delivers a workbook, see [Serving files](#serving-files). |
331
332
  | `signedOutPage` | `(request, headers) => Response` | The page response for a signed-out reader, usually a redirect to sign-in. Data requests answer 401 instead. |
332
333
  | `forbiddenPage?` | `(request, headers) => Response` | The page response for a reader without access (default: a 403 for the route's error boundary). |
333
334
  | `notices?` | `(context) => Promise<ExplorerNotice[]>` | Callouts above the tree (a missing permission with a link that grants it, for example). |
@@ -404,18 +405,19 @@ type ExplorerDocument =
404
405
  | { kind: "text"; name: string; text: string; truncated: boolean; url: string }
405
406
  | { kind: "image"; name: string; url: string; imageType: "raster" | "svg" }
406
407
  | { kind: "media"; name: string; url: string; mediaType: "video" | "audio" | "pdf" }
407
- | { kind: "spreadsheet"; name: string; url: string; format: "csv" | "tsv"; firstSheetOnly: boolean; edit: ExplorerExternalEdit | null }
408
+ | { kind: "spreadsheet"; name: string; url: string; format: "csv" | "tsv" | "workbook"; firstSheetText: "csv" | "tsv" | null; edit: ExplorerExternalEdit | null }
408
409
  | { kind: "file"; name: string; url: string }
409
410
  | ExplorerFailureDocument // { kind: "failure"; failure: { reason: ExplorerFailureReason; code?: string } }
410
411
  ```
411
412
 
412
413
  This is the document the browser receives. Your `document` port answers `ExplorerHostDocument` (exported from the server entry), which is the same except that an image, media, text, spreadsheet or file document carries its file's `version` instead of a `url`:
413
- `{ kind: "image"; name; imageType; version }`, `{ kind: "media"; name; mediaType; version }`, `{ kind: "text"; name; text; truncated; version }`, `{ kind: "spreadsheet"; name; format; firstSheetOnly; edit; version }` and `{ kind: "file"; name; version }`.
414
+ `{ kind: "image"; name; imageType; version }`, `{ kind: "media"; name; mediaType; version }`, `{ kind: "text"; name; text; truncated; version }`, `{ kind: "spreadsheet"; name; format; firstSheetText; edit; version }` and `{ kind: "file"; name; version }`.
414
415
  `version` is an opaque validator of 1 to 256 visible ASCII characters other than `"`, the same one your `asset` port reports for the file; the explorer writes the document's `url` as its own asset URL with that version (`<dataPath>/asset?path=…&v=<version>`, see [URL contract](docs/behavior/url-contract.md#asset-urls)).
415
416
  An answer of those kinds that carries a `url` key, or lacks a valid `version`, breaks the contract: it is logged and the reader sees `failed`.
416
417
  An image document names its type in `imageType` (`ExplorerImageType`): `"svg"` for an SVG file, whose SVG the Source toggle shows as written, and `"raster"` for every other image format. Answer it from what your storage knows of the file's type, the type your `asset` port serves it with; the explorer never guesses it from the name, and an image answer without one of the two breaks the contract the same way.
417
- A spreadsheet document is a table file the explorer shows as a table (see [Table files](#table-files)); it names the format of the bytes your `asset` port delivers for it in `format` (`ExplorerSpreadsheetFormat`: `"csv"` or `"tsv"`), whether those bytes are only the first sheet of a workbook your storage exports (`firstSheetOnly`, which adds a note above the table; a Google Sheets spreadsheet exported as CSV is), and the file's own editor in `edit` (`ExplorerExternalEdit`:
418
- `null`, or `{ kind: "external", href }` with an absolute `https:` URL the bar opens in a new tab, as for a markdown document; the explorer edits no table file itself). Answer them from what your storage knows of the file, as for an image; a spreadsheet answer without a known `format`, a boolean `firstSheetOnly` and such an `edit` breaks the contract the same way.
418
+ A spreadsheet document is a table file the explorer shows as a table (see [Table files](#table-files)); it names the format of the bytes your `asset` port delivers for it in `format` (`ExplorerSpreadsheetFormat`: `"csv"`, `"tsv"` or `"workbook"`, an Office Open XML workbook or an OpenDocument spreadsheet, which the browser tells apart by its bytes),
419
+ for a workbook your storage converts on read the format of the first sheet's text it delivers when it cannot deliver the workbook (`firstSheetText`, `ExplorerSheetTextFormat`: `"csv"` or `"tsv"`; a Google Sheets spreadsheet is `"csv"`; `null` for a stored workbook and for every CSV or TSV file), and the file's own editor in `edit` (`ExplorerExternalEdit`:
420
+ `null`, or `{ kind: "external", href }` with an absolute `https:` URL the bar opens in a new tab, as for a markdown document; the explorer edits no table file itself). Answer them from what your storage knows of the file, as for an image; a spreadsheet answer without a known `format`, with a `firstSheetText` other than those (or one on a CSV or TSV file) or without such an `edit` breaks the contract the same way.
419
421
  `failureDocument(reason, code?)` returns an `ExplorerFailureDocument`, which both unions accept.
420
422
  A markdown document says how the reader may edit it in `edit` (`ExplorerDocumentEdit`), which every markdown answer must carry: `null` (no editing), `{ kind: "inline" }` (in the explorer, through the server's `edit` ports; without them the answer breaks the contract), `{ kind: "draft" }` (in the explorer without saving, to try changes in the preview: the ports' `source` and `preview` only, and the same contract) or `{ kind: "external", href }` (the document's own editor, an absolute `https:` URL the bar opens in a new tab).
421
423
  Decide it per document and per reader (see [Editing](#editing)); `createFileSystemSource` answers `null`.
@@ -443,7 +445,7 @@ The deny rules are checked on the document's path only: a parser that expands in
443
445
 
444
446
  ### Table files
445
447
 
446
- A spreadsheet document shows its file under the file header (its name; Open in a new tab, which shows the file as plain text; Download) as a read-only table: `@aiquants/markdown`'s table block — the grid of `@aiquants/spreadsheet`, with its zoom, copy, save as TSV and full screen —, named after the file, in the UI language and the explorer's colour scheme, filling a page pane (the block's `fill` layout, never fewer than three rows at the grid's zoom) and taking the height of its rows in a multi-view panel.
448
+ A spreadsheet document shows its file under the file header (its name; Open in a new tab, which shows the file as plain text — a workbook's opens the file itself unless the document names its first sheet's text; Download) as a read-only table: `@aiquants/markdown`'s table block — the grid of `@aiquants/spreadsheet`, with its zoom, copy, save as TSV and full screen —, named after the file, in the UI language and the explorer's colour scheme, filling a page pane (the block's `fill` layout, never fewer than three rows at the grid's zoom) and taking the height of its rows in a multi-view panel.
447
449
  The file's notes and its table share one scroller under the file header, the document's scroller: in a page pane the table fills what the notes leave, and the body scrolls only when the pane is shorter than the file header, the notes, the stage's padding and the table block at its fewest — its toolbar and notice line and those three rows (at a 400 % zoom, for example).
448
450
 
449
451
  - **Reading**: the browser reads the file itself, through the asset's plain-text delivery (`&as=text`: one request on the page's origin, never redirected to the storage), as a stream. At looks that each wait for twice the bytes the one before saw (the first after 64 KiB) it makes the table of what it has, so the looks together parse less than twice the bytes read, and it stops reading — cancelling the rest of the request — once the cell budget refuses a row (the 100,000 cells a grid operates on at once, `SPREADSHEET_MAX_OPERATION_CELLS`)
@@ -456,9 +458,14 @@ The file's notes and its table share one scroller under the file header, the doc
456
458
  - **States**: the skeleton until the first reading, after which a page view announces the document; a failure before anything was read (the asset answering one, or the connection breaking) shows the failure view with its retry and is announced as a document's failure, alone (in a multi-view panel through the panel's announcer), and a retry that succeeds moves the focus into the table's body and, in a page view, announces the document, as the pane does for a document that replaces a failure;
457
459
  every new answer for the document reads the file again with the previous table on screen and the region busy (its progress line and `aria-busy`). Refresh document waits for that reading and reports it once: as reloaded, or, when the reading fails, in the bar's notice (`documentRefreshFailed`) with the table kept; a background answer whose reading fails keeps the table without a word, as a background failure keeps a loaded document. Leaving the view aborts the reading. A document shown as written (its Source) behaves the same way.
458
460
  - **As written**: the document bar's Source toggle shows the file's CSV or TSV as written (its tooltip names which), read through the `text` operation by the same rule.
459
- - **Workbooks**: a `firstSheetOnly` document shows the note `spreadsheetFirstSheetOnly` above the table, and an `external` edit puts the link to the workbook's own editor in the bar.
461
+ - **Workbooks**: a `workbook` document is read through the asset's workbook delivery (`&as=workbook`: one request on the page's origin, for which a storage that converts the file on read is asked for a workbook), whole up to `spreadsheets.maxWorkbookBytes` (default 8 MiB), and opened in the browser by the explorer's own reader, with no dependency: an Office Open XML workbook (`.xlsx`, `.xlsm`, a Google Sheets spreadsheet exported as `.xlsx`) or an OpenDocument spreadsheet (`.ods`), told apart by its bytes.
462
+ Its shown sheets are tabs above the table — hidden sheets and sheets without a table (chart, dialog and macro sheets) are left out and counted in a note (`spreadsheetUnshownSheets`), and at most 256 are listed (`spreadsheetUnlistedSheets`) —, in the APG tabs pattern with manual activation: the arrow keys, Home and End move the focus, Enter, Space or a press selects, every tab a 44 px target in a row that wraps.
463
+ Each sheet is read when first shown, within the same cell budget as a text file's table, and kept, so going back to it shows it at once; a reading again (Refresh document, a retry) shows the sheet the reader chose, by its name. A sheet's table is named after the file and the sheet (`spreadsheetSheetName`), and a sheet without data shows `spreadsheetSheetEmpty`.
464
+ A cell shows its stored value: a string (rich text joined, phonetic readings left out), a formula's last result (formulas are never evaluated), `TRUE` or `FALSE`, an error as written, and a number through its cell's number format — dates and times in the 1900 and the 1904 date systems (Excel's 29 February 1900 included), elapsed times, percentages, fixed decimals with grouping and scaling, and otherwise up to 15 significant digits; an OpenDocument cell shows the text its writer shows.
465
+ A password-protected workbook (`spreadsheetWorkbookEncrypted`), bytes that are no workbook the reader reads, a legacy `.xls` included (`spreadsheetNotWorkbook`), and a workbook past `spreadsheets.maxWorkbookBytes` or with a part that inflates past 64 MiB (`spreadsheetWorkbookTooLarge`) show a note with the download.
466
+ A document that names its first sheet's text (`firstSheetText`) is a workbook your storage converts on read: when the delivery brings no workbook package within the budget (your storage's own text when it could not convert the workbook) or one the reader refuses, the view reads that text (`&as=text`) instead and shows it as a CSV or TSV file's table, below the note `spreadsheetWorkbookFirstSheet`. An `external` edit puts the link to the workbook's own editor in the bar. A workbook has no Source toggle (its bytes are no text).
460
467
 
461
- `createFileSystemSource` answers `.csv` files as `csv` and `.tsv` and `.tab` files as `tsv`, never `firstSheetOnly` and without an editor. Excel and OpenDocument workbooks stay `file` documents (downloads): the explorer reads no workbook format.
468
+ `createFileSystemSource` answers `.csv` files as `csv`, `.tsv` and `.tab` files as `tsv`, and `.xlsx`, `.xlsm` and `.ods` files as `workbook`, always without a `firstSheetText` and without an editor. A legacy `.xls` stays a `file` document (a download).
462
469
 
463
470
  ### Editing
464
471
 
@@ -576,9 +583,9 @@ export const explorer = createMarkdownExplorer({
576
583
 
577
584
  ### Serving files
578
585
 
579
- The explorer serves every file it shows or offers for download itself, through the `asset` operation of its data route: `<dataPath>/asset?path=<document path>[&v=<version>][&as=text]` (GET and HEAD; see [URL contract](docs/behavior/url-contract.md#asset-urls)).
580
- Images, audio, video and PDF are shown in place; every other file (Markdown, text, table files, workbooks, anything else) is delivered as a download, except that `&as=text` asks for any file as plain text shown in place (`text/plain; charset=<encoding>`, the encoding the explorer's one text rule reads the file's first 64 KiB in, under the same `nosniff` and sandboxing policy).
581
- That is where a text viewer's Open in a new tab goes, since a browser downloads Markdown or cannot show it, and what a table file's preview reads (one request on the page's origin, since the operation reads the bytes itself and never redirects).
586
+ The explorer serves every file it shows or offers for download itself, through the `asset` operation of its data route: `<dataPath>/asset?path=<document path>[&v=<version>][&as=text|&as=workbook]` (GET and HEAD; see [URL contract](docs/behavior/url-contract.md#asset-urls)).
587
+ Images, audio, video and PDF are shown in place; every other file (Markdown, text, table files, workbooks, anything else) is delivered as a download, except that `&as=text` asks for any file as plain text shown in place (`text/plain; charset=<encoding>`, the encoding the explorer's one text rule reads the file's first 64 KiB in, under the same `nosniff` and sandboxing policy), and `&as=workbook` for a workbook's preview (always a download).
588
+ That is where a text viewer's Open in a new tab goes, since a browser downloads Markdown or cannot show it, and what a table file's preview reads (`&as=text` for a CSV or TSV file and `&as=workbook` for a workbook: one request on the page's origin, since the operation reads the bytes itself and never redirects).
582
589
  The host supplies only the bytes, through the `asset` port:
583
590
 
584
591
  | `ExplorerAssetFile` field | Type | Meaning |
@@ -621,6 +628,13 @@ The body of a 200 or 206 with a `Content-Length` carries exactly that many bytes
621
628
  - A GET of the whole file opens it once and sends the bytes read to name the encoding first; a HEAD and a range read the first 64 KiB on their own (a range then opens its own bytes), so a ranged part carries the `charset` of the file's beginning.
622
629
  The server holds the host's chunks that carry those 64 KiB until they are sent, and a beginning that ends before `size` is answered `failed` (logged) before any header, rather than with a body that breaks.
623
630
 
631
+ `&as=workbook` answers by the same table too, with these differences:
632
+
633
+ - The port is asked with `delivery: "workbook"`, so a storage that converts the file on read delivers a workbook (a Google Sheets spreadsheet as `.xlsx`, with every sheet); a stored file is delivered as stored.
634
+ - Every 200 and 304 carries `Content-Type: application/octet-stream` and `Content-Disposition: attachment; filename*=UTF-8''<name>`, whatever the declared type, with the same security and cache headers.
635
+ - The answer is always the whole file: a `Range` is ignored (the reader needs the whole package), so it is 200 or 304, never 206 or 416.
636
+ - The ETag is `"workbook;<version>"`, so a cached copy of the stored file never answers it, nor the other way round.
637
+
624
638
  The URL carries the path in its query, so no name needs an extra escape and the request's own path never ends in `.data`; a document's URL carries `v=<version>` as a cache-buster, which the server never reads (the ETag always names the current version).
625
639
 
626
640
  The data route's `text` operation reads a file through the same port for the Source toggles (the document bar's — a Markdown document, an SVG image, a table file — and that of an SVG image inside a rendered document) and that image's Copy:
@@ -632,18 +646,18 @@ It sends no refresh mark: the port receives `refresh: false`.
632
646
  ### Redirecting to the storage
633
647
 
634
648
  A host whose storage issues short-lived URLs (a storage-api `gcs://` signed URL, for example) can let the browser read a file's bytes from the storage instead of through the explorer.
635
- The `asset` port receives a fourth argument, `{ redirect }`: it is `true` only when the `asset` operation delivers the stored file, and `false` for `&as=text` and the `text` operation, which read the bytes themselves.
636
- When it is `true` the port may answer an `ExplorerAssetRedirect`, `{ kind: "redirect", url }`, instead of an `ExplorerAssetFile`:
649
+ The `asset` port receives a fourth argument, `{ delivery }`: it is `"file"` only when the `asset` operation delivers the stored file, `"text"` for `&as=text` and the `text` operation, and `"workbook"` for `&as=workbook`, which read the bytes themselves.
650
+ When it is `"file"` the port may answer an `ExplorerAssetRedirect`, `{ kind: "redirect", url }`, instead of an `ExplorerAssetFile`:
637
651
 
638
652
  ```ts
639
- asset: async (context, path, readPath, { redirect }) =>
640
- redirect ? { kind: "redirect", url: await signedUrlOf(readPath, context.signal) } : fileOf(readPath, context.signal),
653
+ asset: async (context, path, readPath, { delivery }) =>
654
+ delivery === "file" ? { kind: "redirect", url: await signedUrlOf(readPath, context.signal) } : fileOf(readPath, delivery, context.signal),
641
655
  ```
642
656
 
643
657
  The explorer then answers `302` with `Location: <url>`, `Cache-Control: private, no-store` and `Referrer-Policy: no-referrer` (plus the headers authentication returned), for GET and HEAD alike and with or without `Range`: the storage answers ranges itself.
644
658
  The deny rules and the source admission run before the port exactly as for a file, so a denied or unadmitted path never reaches the port and is never redirected; `If-None-Match` is not read for a redirect.
645
659
  The page's HTML keeps pointing at the explorer's own `asset` operation.
646
- The URL must be absolute `https:` without credentials (it is written as the URL parser serializes it); any other URL, a redirect when `redirect` is `false`, or an answer whose `kind` is not `"redirect"` is a contract violation, logged and answered `failed` (500).
660
+ The URL must be absolute `https:` without credentials (it is written as the URL parser serializes it); any other URL, a redirect for any other `delivery`, or an answer whose `kind` is not `"redirect"` is a contract violation, logged and answered `failed` (500).
647
661
  A host that never answers a redirect keeps streaming through `open`, unchanged.
648
662
 
649
663
  What a host that redirects must allow and decide:
@@ -934,7 +948,8 @@ Tests and host styling may rely on the `data-testid` and `data-aqmx-*` attribute
934
948
  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.
935
949
  - 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.
936
950
  - A ```spreadsheets table stays read-only in the preview, and says so, when its block holds a line the converter reads with a tab split at a container's edge or a tab right after `>`, or an info string whose first word holds a backslash or an ampersand: readings the editor does not reproduce, so it never writes such a block in a way the converter would read differently. Inside a list item, a line of spaces and tabs only reads as an empty line (CommonMark), so a row whose cells are all white space is written as an empty line and keeps no cells; the table then shows the row as the editor reads it.
937
- - Document kinds are the six above; `createFileSystemSource` previews only files with a known text extension or name as text, shows `.csv`, `.tsv` and `.tab` files as tables, and offers any other file as a `file` document (a download). The explorer reads no workbook format (Excel, OpenDocument): a workbook shows as a table only when the host exports it as CSV or TSV, and then as one sheet.
951
+ - Document kinds are the six above; `createFileSystemSource` previews only files with a known text extension or name as text, shows `.csv`, `.tsv` and `.tab` files and `.xlsx`, `.xlsm` and `.ods` workbooks as tables, and offers any other file as a `file` document (a download).
952
+ - A workbook's preview shows stored values only: formulas are not evaluated, so a cell whose writer saved no result (some generators write formulas alone) shows empty, and the reader shows no cell styles, conditional formats, merged spans, comments, pictures or charts. It reads no legacy `.xls` (Excel 97–2003), no password-protected workbook, no `.xlsb` and no ZIP64 package, and it reads the whole workbook (at most `spreadsheets.maxWorkbookBytes`) before it shows a sheet.
938
953
  - A table file's preview shows at most the 100,000 cells a grid operates on at once, 1,000 columns and 32,767 characters of a cell, and reads at most `spreadsheets.maxBytes` of the file, which it parses on the browser's main thread (a row of more cells than a preview shows is still read whole: a single 2 MiB row of commas or tabs takes a few tenths of a second, where 2 MiB of ordinary rows stops at the cell budget in about a hundredth). It reads no encoding the file does not mark or the configuration does not name:
939
954
  a UTF-8 file with a few stray bytes shows the encoding note instead of a table (or, with a legacy encoding configured, is read in that encoding). The encoding is decided on the bytes each view reads, so the table and the Source view of a file whose encoding changes past where one of them stopped reading may read it differently.
940
955
  - A TSV file read partway shows only the rows before the first cell that opens a quote the bytes read do not close (a lone `"` used as a ditto mark, for example), since the rest of the file could still close it: a TSV larger than `spreadsheets.maxBytes` with such a cell near its start shows only the rows above it — or, with no row above it, the note that no row ends within the part read (`spreadsheetLongRow`) —, where read whole it shows every row (an unclosed quote is literal in a whole TSV). A CSV is not affected (an unclosed quote holds the rest of a whole CSV too).
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const q=require("react/jsx-runtime"),h=require("react"),y=require("./index-B6FkGD-p.cjs"),J=require("@aiquants/markdown/code-blocks"),K=require("@codemirror/commands"),pe=require("@codemirror/lang-markdown"),oe=require("@codemirror/language"),ge=require("@codemirror/search"),$=require("@codemirror/state"),P=require("@codemirror/view"),V=require("@lezer/highlight"),je=require("@aiquants/markdown"),ue=require("@aiquants/markdown/source-lines"),ee=require("./dataRoute-Cv7fgCW7.cjs"),de=require("./sanitizePolicy-CZwOaJ92.cjs"),ze=require("isomorphic-dompurify"),se=require("@aiquants/resize-panels"),X=require("./location-D3DgoELB.cjs"),ve=require("./useSplitPersistence-D-T75Hlh.cjs"),qe={history:K.historyField},Fe=oe.HighlightStyle.define([{tag:[V.tags.heading1,V.tags.heading2,V.tags.heading3,V.tags.heading4,V.tags.heading5,V.tags.heading6,V.tags.heading],color:"var(--aqmx-syntax-heading)",fontWeight:"700"},{tag:V.tags.strong,fontWeight:"700"},{tag:V.tags.emphasis,fontStyle:"italic"},{tag:V.tags.strikethrough,textDecoration:"line-through"},{tag:V.tags.link,color:"var(--aqmx-syntax-link)",textDecoration:"underline"},{tag:V.tags.url,color:"var(--aqmx-syntax-url)"},{tag:V.tags.monospace,color:"var(--aqmx-syntax-code)"},{tag:V.tags.quote,color:"var(--aqmx-syntax-quote)"},{tag:[V.tags.processingInstruction,V.tags.contentSeparator,V.tags.labelName,V.tags.meta],color:"var(--aqmx-syntax-mark)"}]),Ue=P.EditorView.theme({"&":{height:"100%",color:"var(--aqmx-text)",backgroundColor:"var(--aqmx-surface)",fontSize:"var(--aqmx-font-size-title)"},"&.cm-focused":{outline:"none"},".cm-scroller":{fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace',lineHeight:"var(--aqmx-line-height-prose)"},".cm-content":{caretColor:"var(--aqmx-text)",paddingBlock:"var(--aqmx-space-6)"},".cm-line":{paddingInline:"var(--aqmx-space-6)"},"&.cm-focused .cm-cursor":{borderLeftColor:"var(--aqmx-text)"},"&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection":{backgroundColor:"var(--aqmx-editor-selection)"},".cm-activeLine":{backgroundColor:"var(--aqmx-editor-active-line)"},".cm-gutters":{backgroundColor:"var(--aqmx-surface-raised)",color:"var(--aqmx-editor-gutter)",borderInlineEnd:"var(--aqmx-space-1) solid var(--aqmx-border)"},".cm-activeLineGutter":{backgroundColor:"var(--aqmx-editor-active-line)"},".cm-searchMatch":{outline:"var(--aqmx-space-1) solid var(--aqmx-border-strong)"},".cm-panels":{backgroundColor:"var(--aqmx-surface-raised)",color:"var(--aqmx-text)"}}),Me="data-aqmx-conflict-actions",Ge=P.Decoration.line({attributes:{"data-aqmx-conflict-line":"marker"}}),We=P.Decoration.line({attributes:{"data-aqmx-conflict-line":"ours"}}),Xe=P.Decoration.line({attributes:{"data-aqmx-conflict-line":"theirs"}});class $e extends P.WidgetType{constructor(t,n){super(),this.index=t,this.labels=n}index;labels;eq(t){return t.index===this.index&&t.labels===this.labels}toDOM(t){const n=document.createElement("div");n.setAttribute(Me,String(this.index));for(const[r,i]of[["ours",this.labels.useOurs],["theirs",this.labels.useTheirs],["both",this.labels.keepBoth]]){const o=document.createElement("button");o.type="button",o.textContent=i,o.setAttribute("data-aqmx-conflict-choice",r),o.addEventListener("mousedown",l=>l.preventDefault()),o.addEventListener("click",()=>{const l=re(t.state.doc)[this.index];l!==void 0&&(_e(t,l,r),t.focus())}),n.append(o)}return n}ignoreEvent(){return!0}}const re=e=>y.findConflictsInLines(e.iterLines()),we=(e,t)=>{const n=new $.RangeSetBuilder;return re(e).forEach((r,i)=>{const o=e.line(r.start);n.add(o.from,o.from,P.Decoration.widget({widget:new $e(i,t),block:!0,side:-1}));for(let l=r.start;l<=r.end;l+=1){const s=e.line(l).from,d=l===r.start||l===r.separator||l===r.end?Ge:l<r.separator?We:Xe;n.add(s,s,d)}}),n.finish()},Ke=e=>$.StateField.define({create:t=>we(t.doc,e),update:(t,n)=>n.docChanged?we(n.state.doc,e):t,provide:t=>P.EditorView.decorations.from(t)}),_e=(e,t,n)=>{const{doc:r}=e.state,i=(k,c)=>{const E=[];for(let u=k;u<=c;u+=1)E.push(r.line(u).text);return E},o=i(t.start+1,t.separator-1),l=i(t.separator+1,t.end-1),s=n==="ours"?o:n==="theirs"?l:[...o,...l];let d=r.line(t.start).from,f=r.line(t.end).to;s.length===0&&(t.end<r.lines?f+=1:t.start>1&&(d-=1));const p=s.join(`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const q=require("react/jsx-runtime"),h=require("react"),y=require("./index-DRMNpWDJ.cjs"),J=require("@aiquants/markdown/code-blocks"),K=require("@codemirror/commands"),pe=require("@codemirror/lang-markdown"),oe=require("@codemirror/language"),ge=require("@codemirror/search"),$=require("@codemirror/state"),P=require("@codemirror/view"),V=require("@lezer/highlight"),je=require("@aiquants/markdown"),ue=require("@aiquants/markdown/source-lines"),ee=require("./dataRoute-DwYtgyt6.cjs"),de=require("./sanitizePolicy-T5T-3vV5.cjs"),ze=require("isomorphic-dompurify"),se=require("@aiquants/resize-panels"),X=require("./location-yvU5HUY1.cjs"),ve=require("./useSplitPersistence-xGOSwpLM.cjs"),qe={history:K.historyField},Fe=oe.HighlightStyle.define([{tag:[V.tags.heading1,V.tags.heading2,V.tags.heading3,V.tags.heading4,V.tags.heading5,V.tags.heading6,V.tags.heading],color:"var(--aqmx-syntax-heading)",fontWeight:"700"},{tag:V.tags.strong,fontWeight:"700"},{tag:V.tags.emphasis,fontStyle:"italic"},{tag:V.tags.strikethrough,textDecoration:"line-through"},{tag:V.tags.link,color:"var(--aqmx-syntax-link)",textDecoration:"underline"},{tag:V.tags.url,color:"var(--aqmx-syntax-url)"},{tag:V.tags.monospace,color:"var(--aqmx-syntax-code)"},{tag:V.tags.quote,color:"var(--aqmx-syntax-quote)"},{tag:[V.tags.processingInstruction,V.tags.contentSeparator,V.tags.labelName,V.tags.meta],color:"var(--aqmx-syntax-mark)"}]),Ue=P.EditorView.theme({"&":{height:"100%",color:"var(--aqmx-text)",backgroundColor:"var(--aqmx-surface)",fontSize:"var(--aqmx-font-size-title)"},"&.cm-focused":{outline:"none"},".cm-scroller":{fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace',lineHeight:"var(--aqmx-line-height-prose)"},".cm-content":{caretColor:"var(--aqmx-text)",paddingBlock:"var(--aqmx-space-6)"},".cm-line":{paddingInline:"var(--aqmx-space-6)"},"&.cm-focused .cm-cursor":{borderLeftColor:"var(--aqmx-text)"},"&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection":{backgroundColor:"var(--aqmx-editor-selection)"},".cm-activeLine":{backgroundColor:"var(--aqmx-editor-active-line)"},".cm-gutters":{backgroundColor:"var(--aqmx-surface-raised)",color:"var(--aqmx-editor-gutter)",borderInlineEnd:"var(--aqmx-space-1) solid var(--aqmx-border)"},".cm-activeLineGutter":{backgroundColor:"var(--aqmx-editor-active-line)"},".cm-searchMatch":{outline:"var(--aqmx-space-1) solid var(--aqmx-border-strong)"},".cm-panels":{backgroundColor:"var(--aqmx-surface-raised)",color:"var(--aqmx-text)"}}),Me="data-aqmx-conflict-actions",Ge=P.Decoration.line({attributes:{"data-aqmx-conflict-line":"marker"}}),We=P.Decoration.line({attributes:{"data-aqmx-conflict-line":"ours"}}),Xe=P.Decoration.line({attributes:{"data-aqmx-conflict-line":"theirs"}});class $e extends P.WidgetType{constructor(t,n){super(),this.index=t,this.labels=n}index;labels;eq(t){return t.index===this.index&&t.labels===this.labels}toDOM(t){const n=document.createElement("div");n.setAttribute(Me,String(this.index));for(const[r,i]of[["ours",this.labels.useOurs],["theirs",this.labels.useTheirs],["both",this.labels.keepBoth]]){const o=document.createElement("button");o.type="button",o.textContent=i,o.setAttribute("data-aqmx-conflict-choice",r),o.addEventListener("mousedown",l=>l.preventDefault()),o.addEventListener("click",()=>{const l=re(t.state.doc)[this.index];l!==void 0&&(_e(t,l,r),t.focus())}),n.append(o)}return n}ignoreEvent(){return!0}}const re=e=>y.findConflictsInLines(e.iterLines()),we=(e,t)=>{const n=new $.RangeSetBuilder;return re(e).forEach((r,i)=>{const o=e.line(r.start);n.add(o.from,o.from,P.Decoration.widget({widget:new $e(i,t),block:!0,side:-1}));for(let l=r.start;l<=r.end;l+=1){const s=e.line(l).from,d=l===r.start||l===r.separator||l===r.end?Ge:l<r.separator?We:Xe;n.add(s,s,d)}}),n.finish()},Ke=e=>$.StateField.define({create:t=>we(t.doc,e),update:(t,n)=>n.docChanged?we(n.state.doc,e):t,provide:t=>P.EditorView.decorations.from(t)}),_e=(e,t,n)=>{const{doc:r}=e.state,i=(k,c)=>{const E=[];for(let u=k;u<=c;u+=1)E.push(r.line(u).text);return E},o=i(t.start+1,t.separator-1),l=i(t.separator+1,t.end-1),s=n==="ours"?o:n==="theirs"?l:[...o,...l];let d=r.line(t.start).from,f=r.line(t.end).to;s.length===0&&(t.end<r.lines?f+=1:t.start>1&&(d-=1));const p=s.join(`
2
2
  `);e.dispatch({changes:{from:d,to:f,insert:p},selection:$.EditorSelection.cursor(d),scrollIntoView:!0,userEvent:"input.resolve"})},Ee="input.preview",Ye=20,Je=P.ViewPlugin.fromClass(class{constructor(e){this.view=e,this.schedule()}view;cancel=null;update(e){e.docChanged&&this.schedule()}schedule(){if(this.cancel!==null||oe.syntaxTreeAvailable(this.view.state))return;const e=this.view.dom.ownerDocument.defaultView;if(e===null)return;const t=()=>{this.cancel=null,oe.ensureSyntaxTree(this.view.state,this.view.state.doc.length,Ye),this.schedule()};if(typeof e.requestIdleCallback=="function"){const n=e.requestIdleCallback(t);this.cancel=()=>e.cancelIdleCallback(n)}else{const n=e.setTimeout(t,0);this.cancel=()=>e.clearTimeout(n)}}destroy(){this.cancel?.(),this.cancel=null}}),Qe=/`{3,}|~{3,}/u,te=Object.freeze({kind:"absent"}),ce=Object.freeze({kind:"unreadable"}),Ze=(e,t,n)=>{const r=[];for(let d=t.parent;d!==null;d=d.parent)(d.name==="Blockquote"||d.name==="ListItem")&&r.unshift(d);const i=[],o=[],l=d=>{const f=o.indexOf(d);return f===-1?o.length:f};for(const d of r){const f=e.lineAt(d.from).number;if(d.name==="ListItem"){const p=J.listItemWidthOn(e.line(f).text,i,l(f));if(p===null)return null;i.push({kind:"listItem",width:p})}else i.push({kind:"quote"});o.push(f)}const s=J.openingFenceOn(n.text,i,l(n.number));return s===null?null:{containers:i,...s}},et=(e,t)=>{const{doc:n}=e;let r=n.lineAt(t).to;for(;;){const i=oe.ensureSyntaxTree(e,r,Number.POSITIVE_INFINITY);if(i===null)return null;const o=i.resolveInner(t,1),l=o.parent;if(o.name!=="CodeMark"||l===null||l.name!=="FencedCode"||l.from!==o.from)return null;if(l.to<r||r>=n.length)return l;r=Math.min(n.length,l.to+Math.max(l.to-t,1))}},be=(e,t)=>{const{doc:n}=e;if(!Number.isInteger(t)||t<1||t>n.lines)return te;const r=n.line(t),i=Qe.exec(r.text);if(i===null)return te;const o=et(e,r.from+i.index);if(o===null)return te;const l=o.getChild("CodeInfo");if(l===null)return te;const s=J.fencedCodeLanguageOf(n.sliceString(l.from,l.to));if(s===null)return ce;if(s!==J.SPREADSHEETS_LANGUAGE)return te;const d=Ze(n,o,r);if(d===null)return ce;const[,...f]=o.getChildren("CodeMark"),p=f.at(-1),k=p===void 0?n.lineAt(o.to).number:n.lineAt(p.from).number-1,c=[];let E="";for(let u=t+1;u<=k;u+=1){const m=n.line(u).text,v=J.readFencedLine(m,d);if(v===null)return ce;c.push(m),E+=u<n.lines?`${v.content}
3
3
  `:v.content}return{kind:"found",firstLine:t+1,lines:c,layout:d,body:E}},tt=({parent:e,scroll:t,text:n,saved:r,labels:i,revisions:o,onChange:l,onGeometry:s,onSave:d})=>{let f=!1;const p=[P.EditorView.scrollHandler.of((u,m,v)=>(nt(u,m.head,v,t),!0)),P.lineNumbers(),P.highlightActiveLineGutter(),K.history(),P.drawSelection(),P.highlightActiveLine(),ge.highlightSelectionMatches(),P.EditorView.lineWrapping,pe.markdown({base:pe.markdownLanguage}),Je,oe.syntaxHighlighting(Fe),Ke(i),P.keymap.of([{key:"Mod-s",preventDefault:!0,run:()=>(d(),!0)},...ge.searchKeymap,...K.historyKeymap,...K.defaultKeymap]),P.EditorView.contentAttributes.of({"aria-label":i.editor,"aria-multiline":"true"}),P.EditorView.updateListener.of(u=>{for(const m of u.transactions)m.docChanged&&o.record(m.changes,m.newDoc);u.docChanged&&l(u.transactions.every(m=>!m.docChanged||m.isUserEvent(Ee))),(u.docChanged||u.heightChanged||u.geometryChanged)&&s(u.docChanged&&!f)}),Ue],k=st(r,p)??$.EditorState.create({doc:n,extensions:p}),c=new P.EditorView({state:k,parent:e});o.mount(c.state.doc);const E=u=>{f=!0;try{u()}finally{f=!1}};return{text:()=>c.state.doc.toString(),replaceText:u=>{const m=c.state.doc.toString();if(m===u)return;let v=0;const S=Math.min(m.length,u.length);for(;v<S&&m.charCodeAt(v)===u.charCodeAt(v);)v+=1;let g=0;for(;g<S-v&&m.charCodeAt(m.length-1-g)===u.charCodeAt(u.length-1-g);)g+=1;c.dispatch({changes:{from:v,to:m.length-g,insert:u.slice(v,u.length-g)},userEvent:"input.replace"})},replaceBody:(u,m,v,S)=>{const{doc:g}=c.state,L=o.lineOf(S,u);if(L===null)return"changed";const O=be(c.state,L);if(O.kind==="absent")return"changed";if(O.kind==="unreadable")return"unwritable";if(O.body!==J.fencedBodyAsRead(m,O.layout))return"changed";const I=J.planFencedBodyEdit(O.lines,O.layout,v);if(I.kind!=="edit")return I.kind;if(I.from===I.to&&I.lines.length===0)return"written";const D=j=>{const H=O.firstLine+j;return H<=g.lines?g.line(H).from:g.length},M=D(I.from),B=`${M===g.length&&g.sliceString(g.length-1)!==`
4
4
  `?`
@@ -1,6 +1,6 @@
1
1
  import { jsx as R, jsxs as le } from "react/jsx-runtime";
2
2
  import { useState as te, useRef as D, useLayoutEffect as B, useEffectEvent as ve, useEffect as Pe, useImperativeHandle as je, useMemo as J, startTransition as Ye, useCallback as X, useId as Je } from "react";
3
- import { v as ne, g as me, h as Qe, u as se, i as Ze, l as et, j as tt, k as De, m as nt, n as rt, o as ot, p as it, E as lt, q as st, s as ct, t as at, w as we, x as be, A as ut, y as Ee, z as dt, B as ft, G as mt, H as pt } from "./index-Bd6hgisa.js";
3
+ import { v as ne, g as me, h as Qe, u as se, i as Ze, l as et, j as tt, k as De, m as nt, n as rt, o as ot, p as it, E as lt, q as st, s as ct, t as at, w as we, x as be, A as ut, y as Ee, z as dt, B as ft, G as mt, H as pt } from "./index-BNAkC0g3.js";
4
4
  import { fencedBodyAsRead as ht, planFencedBodyEdit as gt, fencedCodeLanguageOf as vt, SPREADSHEETS_LANGUAGE as wt, readFencedLine as bt, listItemWidthOn as Et, openingFenceOn as xt } from "@aiquants/markdown/code-blocks";
5
5
  import { history as St, historyKeymap as yt, defaultKeymap as kt, historyField as Tt, redo as At, undo as It, isolateHistory as Lt } from "@codemirror/commands";
6
6
  import { markdown as Ct, markdownLanguage as Ot } from "@codemirror/lang-markdown";
@@ -11,12 +11,12 @@ import { EditorView as $, lineNumbers as Vt, highlightActiveLineGutter as Ht, dr
11
11
  import { tags as N } from "@lezer/highlight";
12
12
  import { MarkdownViewer as $t } from "@aiquants/markdown";
13
13
  import { SOURCE_LINES_ATTRIBUTE as He, parseSourceLines as Kt } from "@aiquants/markdown/source-lines";
14
- import { d as Xt, f as re, E as jt } from "./dataRoute-BEvesOvN.js";
15
- import { H as Yt, c as Jt, M as Qt } from "./sanitizePolicy-gVKBhabq.js";
14
+ import { d as Xt, f as re, E as jt } from "./dataRoute-DLhQfdoW.js";
15
+ import { H as Yt, c as Jt, M as Qt } from "./sanitizePolicy-By0tKOpZ.js";
16
16
  import Zt from "isomorphic-dompurify";
17
17
  import { PanelGroup as en, Panel as xe, PanelResizeHandle as tn } from "@aiquants/resize-panels";
18
- import { C as nn, F as rn, E as on, a as ln, b as oe, d as sn } from "./location-DIxIjqs7.js";
19
- import { u as cn, a as an } from "./useSplitPersistence-Df63lnQZ.js";
18
+ import { C as nn, F as rn, E as on, a as ln, b as oe, d as sn } from "./location-BNFdxzhn.js";
19
+ import { u as cn, a as an } from "./useSplitPersistence-D5EjJwCg.js";
20
20
  const ze = { history: Tt }, un = Rt.define([
21
21
  { tag: [N.heading1, N.heading2, N.heading3, N.heading4, N.heading5, N.heading6, N.heading], color: "var(--aqmx-syntax-heading)", fontWeight: "700" },
22
22
  { tag: N.strong, fontWeight: "700" },