@folijs/react 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/README.md +4 -2
- package/dist/FoliEditor.d.ts.map +1 -1
- package/dist/FoliEditor.js +2 -1
- package/dist/FoliEditor.js.map +1 -1
- package/dist/FoliNavigation.d.ts +15 -0
- package/dist/FoliNavigation.d.ts.map +1 -0
- package/dist/FoliNavigation.js +491 -0
- package/dist/FoliNavigation.js.map +1 -0
- package/dist/FoliToolbar.d.ts.map +1 -1
- package/dist/FoliToolbar.js +775 -4
- package/dist/FoliToolbar.js.map +1 -1
- package/dist/editor.d.ts +2 -0
- package/dist/editor.d.ts.map +1 -1
- package/dist/editor.js +6 -0
- package/dist/editor.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/FoliEditor.tsx +2 -0
- package/src/FoliNavigation.tsx +895 -0
- package/src/FoliToolbar.tsx +1174 -6
- package/src/editor.tsx +11 -0
- package/src/index.ts +1 -0
- package/styles.css +180 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,39 @@
|
|
|
1
1
|
# @folijs/react
|
|
2
2
|
|
|
3
|
+
## 0.6.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- cd343e4: Sections, headers and footers, notes, fields, content controls, find and replace, and PDF, as Word models them: imported, laid out on pages, edited there and written back to `.docx`.
|
|
8
|
+
- **Schema v5** (`@folijs/core`, ADR-0007): `stories` in the envelope (headers, footers, footnotes and endnotes, each a tree of blocks), `controls` (content controls' properties) and `settings` (even and odd headers, note options, `doNotUseHTMLParagraphAutoSpacing`); field markers (`fieldStart`, `fieldCode`, `fieldSeparator`, `fieldEnd`), content control markers (`controlStart`, `controlEnd`; a `controls` attribute on blocks, rows and cells), `noteReference` and `noteMark` nodes; sections gain `columns`, `pageNumbers`, note properties and a tracked setup change (`change`). `SCHEMA_VERSION` 5: v4 documents migrate on load (the version only: what was opaque stays so until the `.docx` is imported again).
|
|
9
|
+
- **Stories and undo** (`@folijs/core`): `editor.story(id)` gives an editor over a header, footer or note; its changes are `StoryStep`s of the body's history (one undo across the document), `EnvelopeStep` for the last section, settings and controls; accept and reject all reach every story.
|
|
10
|
+
- **Sections** (`@folijs/core`, `@folijs/view`, `@folijs/react`): columns (equal and set widths, the line between, column breaks), continuous, next-column and even and odd page sections with Word's blank page, balanced columns above a continuous break; `insertSectionBreak`, `removeSectionBreak`, `setSectionSetup`, `insertColumnBreak`, tracked as Word records them; a Section menu and Page setup dialog.
|
|
11
|
+
- **Headers and footers**: drawn in their margins on every page (first, even and default variants, linked to the previous section, a taller one pushing the text, page fields filled per page), edited in place (double click or the Header menu, Escape returns) with typing, formatting, pictures, tables, undo and tracking; `setDifferentFirstPage`, `setDifferentEvenPages`, `setStoryLinked`.
|
|
12
|
+
- **Footnotes and endnotes**: at their reference's page foot under a separator, continued on the next page, beneath the text or at the end of a section or the document; numbered in Word's formats with restarts (`noteNumbers`, never stored); `insertNote`, `setNoteProperties`, `convertNotes`; deleted with their reference, tracked, carried on the clipboard; edited in place (double click, Shift+Alt+N, the Notes menu and its options dialog).
|
|
13
|
+
- **Fields**: shown with their results, selected and deleted whole, codes hidden or shown (Alt+F9); `updateFields` (`PAGE`, `NUMPAGES`, `SECTIONPAGES`, `DATE`, `TIME`, `REF`, `PAGEREF`, `SEQ`, `TOC` from heading styles with their pages, `MERGEFIELD` from data; F9, Ctrl+A then F9, `view.updateFields`, `view.print()`) returning what it updated and what it left; `fieldsIn`, `insertField`, `insertPageNumber`, `insertDate`, `insertCrossReference`, `insertTableOfContents`; a Fields menu and cross-reference dialog.
|
|
14
|
+
- **Content controls**: plain and rich text, drop-down, combo box, date, check box, picture, repeating sections, with Word's locks, placeholders and what each kind holds; frames, titles, lists, a date picker and check boxes in the view (Alt+Down, Space); `insertControl`, `setControlValue` and `controlValues` (by id or tag), `setControlProperties`, `addRepeatingItem`; a Controls menu and properties dialog.
|
|
15
|
+
- **Navigation**: `findAll`, `replace`, `replaceAll` over the body and every story (match case, whole words, tracked while tracking, one undo step), `insertBookmark`, `renameBookmark`, `deleteBookmark`, `listBookmarks`, `goTo`, `documentOutline`; matches marked with the CSS Custom Highlight API; `FoliNavigation` (find, replace and go to panel, bookmarks dialog, outline), included in `FoliEditor`, with Word's keys (Ctrl+F, Ctrl+H, Ctrl+G, F3, Shift+F3, Ctrl+Shift+F5) and a Navigate menu.
|
|
16
|
+
- **DOCX** (`@folijs/docx`): headers, footers, footnotes and endnotes read and written as stories (unchanged ones byte for byte, new ones with their parts, relationships and content types), complex and simple fields, content controls at every level (properties patched into the kept `w:sdtPr`), sections' columns, page numbers and note properties, `word/settings.xml`'s even and odd headers and note options. Word reads Foli's sections, headers, notes, fields, controls and replacements back (`scripts/corpus/*-roundtrip.mjs`).
|
|
17
|
+
- **PDF** (`@folijs/pdf`, first released): `exportPdf(document, { page, resources, review, styles })` prints Foli's own pages with a headless Chromium page the app supplies (Playwright 1.42+; Puppeteer's page type fits): each section on its own sheet size, fields updated from the pages first, safe links and bookmark links as PDF links, headings as PDF bookmarks, a tagged PDF. The page loads nothing from the network (images and fonts as `data:` URLs only). Against Word's PDFs of the corpus it scores 0.954 over 24 pages.
|
|
18
|
+
- **Pages against Word**: all 158 paragraphs outside tables that the harness compares on Word's page; headers, footers and notes scored with the rest of the page (0.889 over 24 pages on screen).
|
|
19
|
+
|
|
20
|
+
0.5.0 cannot read documents saved by 0.6.0 (schema v5). Known limits are in [Known limitations](https://github.com/josep-audenis/foli/blob/main/docs/limitations.md) (content, finding and going places, print and PDF sections).
|
|
21
|
+
|
|
22
|
+
Changed behaviour (pre-1.0 minor):
|
|
23
|
+
- `.docx` headers, footers and notes import as `stories` (0.5.0 kept them as parts, never shown); note references, fields (`w:fldChar`, `w:instrText`, `w:fldSimple`) and content controls (`w:sdt`) that imported as `opaqueInline` or `opaqueBlock` now import as nodes. A v4 document's opaque content stays opaque until the `.docx` is imported again.
|
|
24
|
+
- Layout: between two paragraphs goes the larger of the first's space after and the second's space before, as in Word's PDFs (0.5.0 added them; they still add up with `w:doNotUseHTMLParagraphAutoSpacing`); a line is as tall as its runs and paragraph mark, not the paragraph style's font; a header or footer taller than its margin pushes the text. Pages break differently than in 0.5.0, closer to Word.
|
|
25
|
+
- `FoliEditor` includes `FoliNavigation` and takes Ctrl+F, Ctrl+H, Ctrl+G, F3, Shift+F3 and Ctrl+Shift+F5 while the focus is in the document or its panels (the browser's own find no longer opens there).
|
|
26
|
+
- `FoliToolbar` shows the Section, Header, Fields, Navigate, Notes and Controls menus.
|
|
27
|
+
- `view.print()` updates every field before printing; the print rules are shared with `exportPdf`.
|
|
28
|
+
- Backspace at a field's edge selects the field first, and a selection crossing a field's markers takes the whole field, as in Word; the caret steps over a field's code.
|
|
29
|
+
- `acceptAllChanges` and `rejectAllChanges` also settle the tracked changes in headers, footers and notes.
|
|
30
|
+
|
|
31
|
+
### Patch Changes
|
|
32
|
+
|
|
33
|
+
- Updated dependencies [cd343e4]
|
|
34
|
+
- @folijs/core@0.6.0
|
|
35
|
+
- @folijs/view@0.6.0
|
|
36
|
+
|
|
3
37
|
## 0.5.0
|
|
4
38
|
|
|
5
39
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -37,8 +37,10 @@ export function App() {
|
|
|
37
37
|
Browser-only as written; for server rendering (Next.js) and saving on page close, see
|
|
38
38
|
[Getting started](https://github.com/josep-audenis/foli/blob/main/docs/getting-started.md).
|
|
39
39
|
|
|
40
|
-
`FoliEditor` shows the pages with
|
|
41
|
-
|
|
40
|
+
`FoliEditor` shows the pages with Word's toolbar (formatting, review, tables, pictures,
|
|
41
|
+
sections, headers and footers, fields, notes, content controls) and the find, replace and go to
|
|
42
|
+
panel (`FoliNavigation`). For your own layout: `useFoliEditor`, `FoliEditorProvider`,
|
|
43
|
+
`FoliCanvas`, `FoliToolbar`, `FoliComments`, `FoliNavigation`, `useCurrentEditor` and
|
|
42
44
|
`useEditorState(selector)`. React 18.2+ and 19; server rendering gives the editor's shell, the
|
|
43
45
|
document appears on hydration.
|
|
44
46
|
|
package/dist/FoliEditor.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FoliEditor.d.ts","sourceRoot":"","sources":["../src/FoliEditor.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,MAAM,EACX,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,MAAM,EACX,KAAK,UAAU,EACf,KAAK,WAAW,EAEjB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAc,KAAK,SAAS,EAA+B,MAAM,OAAO,CAAC;AAOhF,OAAO,EAAc,KAAK,gBAAgB,EAAE,KAAK,eAAe,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"FoliEditor.d.ts","sourceRoot":"","sources":["../src/FoliEditor.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,MAAM,EACX,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,MAAM,EACX,KAAK,UAAU,EACf,KAAK,WAAW,EAEjB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAc,KAAK,SAAS,EAA+B,MAAM,OAAO,CAAC;AAOhF,OAAO,EAAc,KAAK,gBAAgB,EAAE,KAAK,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAK1F;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,+EAA+E;IAC/E,QAAQ,CAAC,YAAY,EAAE,SAAS,WAAW,EAAE,CAAC;IAC9C;;;OAGG;IACH,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC;CACjC;AAED,MAAM,WAAW,eAAgB,SAAQ,IAAI,CAAC,eAAe,EAAE,QAAQ,CAAC;IACtE;;;OAGG;IACH,cAAc,CAAC,EAAE,cAAc,GAAG,SAAS,CAAC;IAC5C,0BAA0B;IAC1B,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,CAAC;IACxC,6EAA6E;IAC7E,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,6FAA6F;IAC7F,YAAY,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACnC,6EAA6E;IAC7E,UAAU,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC;IACpC;;;;OAIG;IACH,QAAQ,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IACtD,qEAAqE;IACrE,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC9B;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAAC;IACxC,+EAA+E;IAC/E,QAAQ,CAAC,EAAE,SAAS,GAAG,SAAS,CAAC;CAClC;AAED,2FAA2F;AAC3F,MAAM,WAAW,gBAAiB,SAAQ,gBAAgB;IACxD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED;;;;GAIG;AACH,eAAO,MAAM,UAAU,8GA6ErB,CAAC"}
|
package/dist/FoliEditor.js
CHANGED
|
@@ -4,6 +4,7 @@ import { forwardRef, useImperativeHandle, useRef } from "react";
|
|
|
4
4
|
import { FoliEditorProvider, useEditorState, useFoliEditor, useIsomorphicLayoutEffect, } from "./editor.js";
|
|
5
5
|
import { FoliCanvas } from "./FoliCanvas.js";
|
|
6
6
|
import { FoliComments } from "./FoliComments.js";
|
|
7
|
+
import { FoliNavigation } from "./FoliNavigation.js";
|
|
7
8
|
import { FoliToolbar } from "./FoliToolbar.js";
|
|
8
9
|
/**
|
|
9
10
|
* An editable document on real pages with a toolbar: creates its editor, provides it to
|
|
@@ -37,6 +38,6 @@ export const FoliEditor = forwardRef(function FoliEditor({ initialContent, plugi
|
|
|
37
38
|
},
|
|
38
39
|
});
|
|
39
40
|
}), [editor]);
|
|
40
|
-
return (_jsxs(FoliEditorProvider, { editor: editor, children: [toolbar && (_jsx(FoliToolbar, { editor: editor, disabled: canvas.readOnly, comments: comments !== false, upload: canvas.upload, onClickCommand: () => canvasRef.current?.focus() })), children, _jsxs("div", { className: "foli-editor-body", children: [_jsx(FoliCanvas, { ref: canvasRef, editor: editor, ...canvas }), comments !== false && (_jsx(FoliComments, { editor: editor, readOnly: canvas.readOnly, hidden: comments === "auto" && !hasComments }))] })] }));
|
|
41
|
+
return (_jsxs(FoliEditorProvider, { editor: editor, children: [toolbar && (_jsx(FoliToolbar, { editor: editor, disabled: canvas.readOnly, comments: comments !== false, upload: canvas.upload, onClickCommand: () => canvasRef.current?.focus() })), children, _jsxs("div", { className: "foli-editor-body", children: [_jsx(FoliNavigation, { editor: editor, readOnly: canvas.readOnly }), _jsx(FoliCanvas, { ref: canvasRef, editor: editor, ...canvas }), comments !== false && (_jsx(FoliComments, { editor: editor, readOnly: canvas.readOnly, hidden: comments === "auto" && !hasComments }))] })] }));
|
|
41
42
|
});
|
|
42
43
|
//# sourceMappingURL=FoliEditor.js.map
|
package/dist/FoliEditor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FoliEditor.js","sourceRoot":"","sources":["../src/FoliEditor.tsx"],"names":[],"mappings":";AAAA,OAAO,EAOL,WAAW,GACZ,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,UAAU,EAAkB,mBAAmB,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAChF,OAAO,EACL,kBAAkB,EAClB,cAAc,EACd,aAAa,EACb,yBAAyB,GAC1B,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,UAAU,EAA+C,MAAM,iBAAiB,CAAC;AAC1F,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAqD/C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Y,IACX,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,CAAC,QAAQ,EACzB,MAAM,EAAE,QAAQ,KAAK,MAAM,IAAI,CAAC,WAAW,GAC3C,CACH,IACG,IACa,CACtB,CAAC;AACJ,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type Editor } from "@folijs/core";
|
|
2
|
+
export interface FoliNavigationProps {
|
|
3
|
+
/** Default: the editor of the nearest `FoliEditorProvider`. */
|
|
4
|
+
editor?: Editor | undefined;
|
|
5
|
+
/** No replacing, and no changing bookmarks. */
|
|
6
|
+
readOnly?: boolean | undefined;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Word's navigation for an editor: the find and replace panel (Ctrl+F, Ctrl+H, with Go to on
|
|
10
|
+
* Ctrl+G; F3 and Shift+F3 go to the next and previous match), the bookmarks dialog (Ctrl+Shift+F5)
|
|
11
|
+
* and the outline. The keys are taken only while the focus is in the document or in these panels:
|
|
12
|
+
* elsewhere on the page Ctrl+F stays the browser's. The toolbar's Navigate menu opens them too.
|
|
13
|
+
*/
|
|
14
|
+
export declare function FoliNavigation({ editor: given, readOnly }: FoliNavigationProps): import("react").JSX.Element;
|
|
15
|
+
//# sourceMappingURL=FoliNavigation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FoliNavigation.d.ts","sourceRoot":"","sources":["../src/FoliNavigation.tsx"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,MAAM,EAoBZ,MAAM,cAAc,CAAC;AAmBtB,MAAM,WAAW,mBAAmB;IAClC,+DAA+D;IAC/D,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,+CAA+C;IAC/C,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAChC;AA8ED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,QAAgB,EAAE,EAAE,mBAAmB,+BAwHtF"}
|
|
@@ -0,0 +1,491 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { deleteBookmark, documentOutline, fieldCodesShown, findAll, goTo, insertBookmark, listBookmarks, nextMatch, renameBookmark, replace, replaceAll, StoryStep, trackState, wordContext, } from "@folijs/core";
|
|
3
|
+
import { keyName } from "@folijs/view";
|
|
4
|
+
import { useCallback, useEffect, useId, useMemo, useRef, useState, } from "react";
|
|
5
|
+
import { useActiveEditor, useEditorOrContext, useEditorState, useIsomorphicLayoutEffect, } from "./editor.js";
|
|
6
|
+
/** What each refusal is called in the panel's report. */
|
|
7
|
+
const REFUSALS = {
|
|
8
|
+
locked: "locked content",
|
|
9
|
+
control: "a content control",
|
|
10
|
+
field: "across a field's edge",
|
|
11
|
+
"field-code": "a field code",
|
|
12
|
+
deleted: "deleted text",
|
|
13
|
+
stale: "changed text",
|
|
14
|
+
refused: "could not be changed",
|
|
15
|
+
};
|
|
16
|
+
const WHERE = {
|
|
17
|
+
header: "header",
|
|
18
|
+
footer: "footer",
|
|
19
|
+
footnote: "footnote",
|
|
20
|
+
endnote: "endnote",
|
|
21
|
+
};
|
|
22
|
+
/** The text selected now, in the story open or the body. */
|
|
23
|
+
function activeState(body) {
|
|
24
|
+
const open = body.storyView?.open?.id ?? null;
|
|
25
|
+
const story = open ? body.story(open) : null;
|
|
26
|
+
return story ? { story: open, state: story.state } : { story: null, state: body.state };
|
|
27
|
+
}
|
|
28
|
+
function isSelected(body, match) {
|
|
29
|
+
const { story, state } = activeState(body);
|
|
30
|
+
const { from, to } = state.selection;
|
|
31
|
+
return story === match.story && from === match.from && to === match.to;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* `match` where `transactions` leave it, or null when they changed it or its story: until the next
|
|
35
|
+
* search the marks follow the text and Enter goes where they are.
|
|
36
|
+
*/
|
|
37
|
+
function mapMatch(match, transactions, stories) {
|
|
38
|
+
if (match.story !== null)
|
|
39
|
+
return stories.has(match.story) ? null : match;
|
|
40
|
+
let { from, to } = match;
|
|
41
|
+
for (const tr of transactions)
|
|
42
|
+
for (const map of tr.mapping.maps) {
|
|
43
|
+
// Anything a step changes inside it (an edit of the same length too) ends it as a match.
|
|
44
|
+
let touched = false;
|
|
45
|
+
map.forEach((start, end) => {
|
|
46
|
+
if (start < to && end > from)
|
|
47
|
+
touched = true;
|
|
48
|
+
});
|
|
49
|
+
if (touched)
|
|
50
|
+
return null;
|
|
51
|
+
from = map.map(from, 1);
|
|
52
|
+
to = map.map(to, -1);
|
|
53
|
+
}
|
|
54
|
+
return from === match.from ? match : { ...match, from, to };
|
|
55
|
+
}
|
|
56
|
+
/** What the document shows has changed: another search is due. */
|
|
57
|
+
function searchKey(state) {
|
|
58
|
+
return [
|
|
59
|
+
state.doc,
|
|
60
|
+
wordContext(state)?.envelope.stories,
|
|
61
|
+
wordContext(state)?.envelope.controls,
|
|
62
|
+
trackState(state)?.view,
|
|
63
|
+
fieldCodesShown(state),
|
|
64
|
+
];
|
|
65
|
+
}
|
|
66
|
+
function reportText({ replaced, refused }) {
|
|
67
|
+
const done = `Replaced ${replaced}.`;
|
|
68
|
+
if (!refused.length)
|
|
69
|
+
return done;
|
|
70
|
+
const reasons = [...new Set(refused.map((r) => REFUSALS[r.reason]))].join(", ");
|
|
71
|
+
return `${done} ${refused.length} left as they are: ${reasons}.`;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Word's navigation for an editor: the find and replace panel (Ctrl+F, Ctrl+H, with Go to on
|
|
75
|
+
* Ctrl+G; F3 and Shift+F3 go to the next and previous match), the bookmarks dialog (Ctrl+Shift+F5)
|
|
76
|
+
* and the outline. The keys are taken only while the focus is in the document or in these panels:
|
|
77
|
+
* elsewhere on the page Ctrl+F stays the browser's. The toolbar's Navigate menu opens them too.
|
|
78
|
+
*/
|
|
79
|
+
export function FoliNavigation({ editor: given, readOnly = false }) {
|
|
80
|
+
const body = useEditorOrContext(given, "FoliNavigation");
|
|
81
|
+
const active = useActiveEditor(body);
|
|
82
|
+
const [panel, setPanel] = useState(null);
|
|
83
|
+
const [request, setRequest] = useState(0);
|
|
84
|
+
const [bookmarks, setBookmarks] = useState(false);
|
|
85
|
+
const [outline, setOutline] = useState(false);
|
|
86
|
+
const [query, setQuery] = useState("");
|
|
87
|
+
const [matchCase, setMatchCase] = useState(false);
|
|
88
|
+
const [wholeWord, setWholeWord] = useState(false);
|
|
89
|
+
/** Where the focus goes back to. */
|
|
90
|
+
const restore = useRef(null);
|
|
91
|
+
const live = useRef({ query, matchCase, wholeWord, panel });
|
|
92
|
+
live.current = { query, matchCase, wholeWord, panel };
|
|
93
|
+
const remember = useCallback(() => {
|
|
94
|
+
const element = typeof document === "undefined" ? null : document.activeElement;
|
|
95
|
+
// Inside the panels the focus already has a place to go back to.
|
|
96
|
+
if (element instanceof HTMLElement &&
|
|
97
|
+
element !== document.body &&
|
|
98
|
+
!element.closest("[data-foli-navigation]"))
|
|
99
|
+
restore.current = element;
|
|
100
|
+
}, []);
|
|
101
|
+
const giveBack = useCallback(() => {
|
|
102
|
+
const element = restore.current;
|
|
103
|
+
restore.current = null;
|
|
104
|
+
if (element?.isConnected && !element.closest("[aria-readonly=true]"))
|
|
105
|
+
element.focus();
|
|
106
|
+
else
|
|
107
|
+
body.storyView?.focus();
|
|
108
|
+
}, [body]);
|
|
109
|
+
useEffect(() => {
|
|
110
|
+
const step = (backward) => {
|
|
111
|
+
const current = live.current;
|
|
112
|
+
if (!current.query)
|
|
113
|
+
return false;
|
|
114
|
+
const target = nextMatch(body, findAll(body, current.query, current), backward);
|
|
115
|
+
if (target)
|
|
116
|
+
goTo(body, target, { focus: true });
|
|
117
|
+
return true;
|
|
118
|
+
};
|
|
119
|
+
const handler = (asked) => {
|
|
120
|
+
if (asked === "next" || asked === "previous") {
|
|
121
|
+
// With the panel open its own buttons' logic runs through the keys it handles.
|
|
122
|
+
if (step(asked === "previous"))
|
|
123
|
+
return true;
|
|
124
|
+
remember();
|
|
125
|
+
setPanel("find");
|
|
126
|
+
setRequest((n) => n + 1);
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
remember();
|
|
130
|
+
if (asked === "bookmarks") {
|
|
131
|
+
setBookmarks(true);
|
|
132
|
+
setRequest((n) => n + 1);
|
|
133
|
+
}
|
|
134
|
+
else if (asked === "outline")
|
|
135
|
+
setOutline((open) => !open);
|
|
136
|
+
else {
|
|
137
|
+
// What is selected is what to find, as in Word.
|
|
138
|
+
const { state } = activeState(body);
|
|
139
|
+
const { from, to, empty } = state.selection;
|
|
140
|
+
const text = empty ? "" : state.doc.textBetween(from, to, "\n");
|
|
141
|
+
if (text && text.length < 256 && !text.includes("\n"))
|
|
142
|
+
setQuery(text);
|
|
143
|
+
setPanel(asked === "replace" && readOnly ? "find" : asked);
|
|
144
|
+
setRequest((n) => n + 1);
|
|
145
|
+
}
|
|
146
|
+
return true;
|
|
147
|
+
};
|
|
148
|
+
body.navigation = handler;
|
|
149
|
+
return () => {
|
|
150
|
+
if (body.navigation === handler)
|
|
151
|
+
body.navigation = null;
|
|
152
|
+
};
|
|
153
|
+
}, [body, readOnly, remember]);
|
|
154
|
+
return (_jsxs("div", { className: "foli-navigation", "data-foli-navigation": "", children: [panel && (_jsx(FindPanel, { body: body, mode: panel, request: request, readOnly: readOnly, query: query, matchCase: matchCase, wholeWord: wholeWord, onQuery: setQuery, onMatchCase: setMatchCase, onWholeWord: setWholeWord, onMode: setPanel, onBookmarks: () => {
|
|
155
|
+
setBookmarks(true);
|
|
156
|
+
setRequest((n) => n + 1);
|
|
157
|
+
}, onClose: () => {
|
|
158
|
+
setPanel(null);
|
|
159
|
+
giveBack();
|
|
160
|
+
} })), bookmarks && (_jsx(BookmarksDialog, { body: body, active: active, readOnly: readOnly, request: request, onClose: (moved) => {
|
|
161
|
+
setBookmarks(false);
|
|
162
|
+
if (!moved)
|
|
163
|
+
giveBack();
|
|
164
|
+
else
|
|
165
|
+
restore.current = null;
|
|
166
|
+
} })), outline && (_jsx(OutlinePanel, { body: body, onClose: () => {
|
|
167
|
+
setOutline(false);
|
|
168
|
+
giveBack();
|
|
169
|
+
} }))] }));
|
|
170
|
+
}
|
|
171
|
+
/** How long typing in the document pauses before the matches are looked for again, in ms. */
|
|
172
|
+
const RESEARCH_DELAY = 300;
|
|
173
|
+
/** The find, replace and go to panel: not modal, the document stays usable beside it. */
|
|
174
|
+
function FindPanel({ body, mode, request, readOnly, query, matchCase, wholeWord, onQuery, onMatchCase, onWholeWord, onMode, onBookmarks, onClose, }) {
|
|
175
|
+
const id = useId();
|
|
176
|
+
const input = useRef(null);
|
|
177
|
+
const [replacement, setReplacement] = useState("");
|
|
178
|
+
const [found, setFound] = useState({ matches: [], current: null, scroll: false });
|
|
179
|
+
const [message, setMessage] = useState("");
|
|
180
|
+
const [version, setVersion] = useState(0);
|
|
181
|
+
const options = useMemo(() => ({ matchCase, wholeWord }), [matchCase, wholeWord]);
|
|
182
|
+
const [focusing, setFocusing] = useState(0);
|
|
183
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: each request focuses the panel again
|
|
184
|
+
useEffect(() => {
|
|
185
|
+
input.current?.focus();
|
|
186
|
+
input.current?.select();
|
|
187
|
+
}, [request, focusing]);
|
|
188
|
+
// Searched again when what the document shows changes, once typing there pauses.
|
|
189
|
+
useEffect(() => {
|
|
190
|
+
let key = searchKey(body.state);
|
|
191
|
+
let timer;
|
|
192
|
+
const unsubscribe = body.subscribe((state, transactions) => {
|
|
193
|
+
const next = searchKey(state);
|
|
194
|
+
if (transactions.some((tr) => tr.docChanged)) {
|
|
195
|
+
const stories = new Set();
|
|
196
|
+
for (const tr of transactions)
|
|
197
|
+
for (const step of tr.steps)
|
|
198
|
+
if (step instanceof StoryStep)
|
|
199
|
+
stories.add(step.id);
|
|
200
|
+
// Only the current match follows the text at once: the rest waits for the search, and
|
|
201
|
+
// meanwhile is not marked where it no longer is.
|
|
202
|
+
setFound((found) => {
|
|
203
|
+
if (!found.matches.length)
|
|
204
|
+
return found;
|
|
205
|
+
const current = found.current && mapMatch(found.current, transactions, stories);
|
|
206
|
+
if (found.stale && current === found.current)
|
|
207
|
+
return found;
|
|
208
|
+
return { ...found, current, scroll: false, stale: true };
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
if (next.some((value, i) => value !== key[i])) {
|
|
212
|
+
clearTimeout(timer);
|
|
213
|
+
timer = setTimeout(() => setVersion((n) => n + 1), RESEARCH_DELAY);
|
|
214
|
+
}
|
|
215
|
+
key = next;
|
|
216
|
+
});
|
|
217
|
+
return () => {
|
|
218
|
+
clearTimeout(timer);
|
|
219
|
+
unsubscribe();
|
|
220
|
+
};
|
|
221
|
+
}, [body]);
|
|
222
|
+
// A new search goes to the match at or after the selection.
|
|
223
|
+
useEffect(() => {
|
|
224
|
+
const matches = findAll(body, query, options);
|
|
225
|
+
setFound({
|
|
226
|
+
matches,
|
|
227
|
+
current: matches.find((m) => isSelected(body, m)) ?? nextMatch(body, matches),
|
|
228
|
+
scroll: true,
|
|
229
|
+
});
|
|
230
|
+
}, [body, query, options]);
|
|
231
|
+
// The document changed: the same search again, the current match kept if it is still there,
|
|
232
|
+
// and the view left where the person typing has it.
|
|
233
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: `version` stands for the document
|
|
234
|
+
useEffect(() => {
|
|
235
|
+
if (!version)
|
|
236
|
+
return;
|
|
237
|
+
const matches = findAll(body, query, options);
|
|
238
|
+
setFound(({ current }) => ({
|
|
239
|
+
matches,
|
|
240
|
+
current: (current &&
|
|
241
|
+
matches.find((m) => m.story === current.story && m.from === current.from && m.to === current.to)) ??
|
|
242
|
+
null,
|
|
243
|
+
scroll: false,
|
|
244
|
+
}));
|
|
245
|
+
}, [version]);
|
|
246
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: a new search says nothing of the last
|
|
247
|
+
useEffect(() => setMessage(""), [query, options]);
|
|
248
|
+
// With the count shown, in the same frame.
|
|
249
|
+
useIsomorphicLayoutEffect(() => {
|
|
250
|
+
const { stale, ...shown } = found;
|
|
251
|
+
const matches = stale ? (shown.current ? [shown.current] : []) : shown.matches;
|
|
252
|
+
body.storyView?.showMatches(query ? { query, ...options, ...shown, matches } : null);
|
|
253
|
+
}, [body, query, options, found]);
|
|
254
|
+
useEffect(() => () => body.storyView?.showMatches(null), [body]);
|
|
255
|
+
const show = (matches, current) => {
|
|
256
|
+
setFound({ matches, current, scroll: true });
|
|
257
|
+
if (current && !goTo(body, current))
|
|
258
|
+
setMessage(`This match is in a ${storyName(body, current)} no page shows.`);
|
|
259
|
+
else
|
|
260
|
+
setMessage("");
|
|
261
|
+
};
|
|
262
|
+
/** The matches as the document is now, and the current one among them. */
|
|
263
|
+
const now = () => {
|
|
264
|
+
if (!found.stale)
|
|
265
|
+
return found;
|
|
266
|
+
const matches = findAll(body, query, options);
|
|
267
|
+
const was = found.current;
|
|
268
|
+
const current = (was &&
|
|
269
|
+
matches.find((m) => m.story === was.story && m.from === was.from && m.to === was.to)) ??
|
|
270
|
+
null;
|
|
271
|
+
return { matches, current, scroll: false };
|
|
272
|
+
};
|
|
273
|
+
const step = (backward) => {
|
|
274
|
+
const { matches, current } = now();
|
|
275
|
+
const first = !backward && current && !isSelected(body, current);
|
|
276
|
+
show(matches, first ? current : nextMatch(body, matches, backward));
|
|
277
|
+
};
|
|
278
|
+
const replaceCurrent = () => {
|
|
279
|
+
const { matches, current } = now();
|
|
280
|
+
if (!current)
|
|
281
|
+
return;
|
|
282
|
+
if (!isSelected(body, current)) {
|
|
283
|
+
show(matches, current);
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
const report = replace(body, current, replacement, options);
|
|
287
|
+
const fresh = findAll(body, query, options);
|
|
288
|
+
show(fresh, nextMatch(body, fresh));
|
|
289
|
+
setMessage(reportText(report));
|
|
290
|
+
};
|
|
291
|
+
const all = () => {
|
|
292
|
+
const report = replaceAll(body, query, replacement, options);
|
|
293
|
+
// What is left at once, as after Replace: not the replaced text for a moment.
|
|
294
|
+
const fresh = findAll(body, query, options);
|
|
295
|
+
setFound({ matches: fresh, current: nextMatch(body, fresh), scroll: false });
|
|
296
|
+
setMessage(reportText(report));
|
|
297
|
+
};
|
|
298
|
+
const onKeyDown = (event) => {
|
|
299
|
+
const name = keyName(event.nativeEvent);
|
|
300
|
+
const modes = { "Mod-f": "find", "Mod-g": "goTo" };
|
|
301
|
+
if (!readOnly)
|
|
302
|
+
modes["Mod-h"] = "replace";
|
|
303
|
+
const next = Object.hasOwn(modes, name) ? modes[name] : undefined;
|
|
304
|
+
if (name === "Escape")
|
|
305
|
+
onClose();
|
|
306
|
+
else if (next) {
|
|
307
|
+
onMode(next);
|
|
308
|
+
setFocusing((n) => n + 1);
|
|
309
|
+
}
|
|
310
|
+
else if (name === "F3" || name === "Shift-F3")
|
|
311
|
+
step(name !== "F3");
|
|
312
|
+
else if (name === "Shift-Enter" && event.target.tagName === "INPUT")
|
|
313
|
+
step(true);
|
|
314
|
+
else if (name === "Mod-Shift-F5")
|
|
315
|
+
onBookmarks();
|
|
316
|
+
else
|
|
317
|
+
return;
|
|
318
|
+
event.preventDefault();
|
|
319
|
+
};
|
|
320
|
+
const onTabKey = (event) => {
|
|
321
|
+
const step = event.key === "ArrowRight" ? 1 : event.key === "ArrowLeft" ? -1 : 0;
|
|
322
|
+
if (!step)
|
|
323
|
+
return;
|
|
324
|
+
event.preventDefault();
|
|
325
|
+
const at = tabs.findIndex(([value]) => value === mode);
|
|
326
|
+
const [next] = tabs[(at + step + tabs.length) % tabs.length];
|
|
327
|
+
onMode(next);
|
|
328
|
+
event.currentTarget.querySelector(`[id$="-tab-${next}"]`)?.focus();
|
|
329
|
+
};
|
|
330
|
+
const position = found.current ? found.matches.indexOf(found.current) + 1 : 0;
|
|
331
|
+
const status = message ||
|
|
332
|
+
(!query
|
|
333
|
+
? ""
|
|
334
|
+
: found.matches.length && !position
|
|
335
|
+
? `${found.matches.length} found`
|
|
336
|
+
: found.matches.length
|
|
337
|
+
? `${position} of ${found.matches.length}${found.current?.story ? `, in a ${storyName(body, found.current)}` : ""}`
|
|
338
|
+
: "No results");
|
|
339
|
+
const tabs = [
|
|
340
|
+
["find", "Find"],
|
|
341
|
+
...(readOnly ? [] : [["replace", "Replace"]]),
|
|
342
|
+
["goTo", "Go to"],
|
|
343
|
+
];
|
|
344
|
+
return (_jsxs("div", { role: "dialog", "aria-label": "Find and replace", className: "foli-link-dialog foli-find-panel", onKeyDown: onKeyDown, children: [_jsxs("div", { className: "foli-find-modes", children: [_jsx("div", { role: "tablist", "aria-label": "What to do", onKeyDown: onTabKey, children: tabs.map(([value, label]) => (_jsx("button", { id: `${id}-tab-${value}`, type: "button", role: "tab", "aria-selected": mode === value, "aria-controls": `${id}-panel`, tabIndex: mode === value ? 0 : -1, onClick: () => onMode(value), children: label }, value))) }), _jsx("button", { type: "button", onClick: onClose, children: "Close" })] }), _jsx("div", { role: "tabpanel", id: `${id}-panel`, "aria-labelledby": `${id}-tab-${mode}`, children: mode === "goTo" ? (_jsx(GoToForm, { body: body, first: input, onDone: onClose })) : (_jsxs("form", { noValidate: true, onSubmit: (event) => {
|
|
345
|
+
event.preventDefault();
|
|
346
|
+
step(false);
|
|
347
|
+
}, children: [_jsx("label", { htmlFor: `${id}-find`, children: "Find what" }), _jsx("input", { ref: input, id: `${id}-find`, type: "text", value: query, onChange: (event) => onQuery(event.target.value) }), mode === "replace" && (_jsxs(_Fragment, { children: [_jsx("label", { htmlFor: `${id}-with`, children: "Replace with" }), _jsx("input", { id: `${id}-with`, type: "text", value: replacement, onChange: (event) => setReplacement(event.target.value) })] })), _jsxs("label", { className: "foli-find-option", children: [_jsx("input", { type: "checkbox", checked: matchCase, onChange: (event) => onMatchCase(event.target.checked) }), "Match case"] }), _jsxs("label", { className: "foli-find-option", children: [_jsx("input", { type: "checkbox", checked: wholeWord, onChange: (event) => onWholeWord(event.target.checked) }), "Whole words"] }), _jsx("button", { type: "button", disabled: !found.matches.length, onClick: () => step(true), children: "Previous" }), _jsx("button", { type: "submit", disabled: !found.matches.length, children: "Next" }), mode === "replace" && (_jsxs(_Fragment, { children: [_jsx("button", { type: "button", disabled: !found.current, onClick: replaceCurrent, children: "Replace" }), _jsx("button", { type: "button", disabled: !found.matches.length, onClick: all, children: "Replace all" })] })), _jsx("p", { role: "status", className: "foli-find-status", children: status })] })) })] }));
|
|
348
|
+
}
|
|
349
|
+
const storyName = (body, match) => WHERE[wordContext(body.state)?.stories.get(match.story ?? "")?.kind ?? ""] ?? "story";
|
|
350
|
+
/** Go to a page, a bookmark or a heading. */
|
|
351
|
+
function GoToForm({ body, first, onDone, }) {
|
|
352
|
+
const id = useId();
|
|
353
|
+
const [kind, setKind] = useState("page");
|
|
354
|
+
const [page, setPage] = useState("1");
|
|
355
|
+
const [failed, setFailed] = useState(false);
|
|
356
|
+
const [marks] = useState(() => listBookmarks(body));
|
|
357
|
+
const [headings] = useState(() => documentOutline(body.state));
|
|
358
|
+
const [picked, setPicked] = useState("0");
|
|
359
|
+
const go = (event) => {
|
|
360
|
+
event.preventDefault();
|
|
361
|
+
const view = body.storyView;
|
|
362
|
+
const at = Number(picked);
|
|
363
|
+
const mark = marks[at];
|
|
364
|
+
const heading = headings[at];
|
|
365
|
+
const done = kind === "page"
|
|
366
|
+
? !!view?.goToPage(Number(page), { focus: true })
|
|
367
|
+
: kind === "bookmark"
|
|
368
|
+
? !!mark && goTo(body, mark, { focus: true })
|
|
369
|
+
: !!heading &&
|
|
370
|
+
goTo(body, { story: null, from: heading.pos + 1, to: heading.pos + 1 }, { focus: true });
|
|
371
|
+
if (done)
|
|
372
|
+
onDone();
|
|
373
|
+
else
|
|
374
|
+
setFailed(true);
|
|
375
|
+
};
|
|
376
|
+
const options = kind === "bookmark" ? marks.map((m) => m.name) : headings.map((entry) => entry.text);
|
|
377
|
+
return (_jsxs("form", { noValidate: true, onSubmit: go, children: [_jsx("label", { htmlFor: `${id}-kind`, children: "Go to what" }), _jsxs("select", { id: `${id}-kind`, value: kind, onChange: (event) => {
|
|
378
|
+
setKind(event.target.value);
|
|
379
|
+
setPicked("0");
|
|
380
|
+
setFailed(false);
|
|
381
|
+
}, children: [_jsx("option", { value: "page", children: "Page" }), _jsx("option", { value: "bookmark", children: "Bookmark" }), _jsx("option", { value: "heading", children: "Heading" })] }), kind === "page" ? (_jsxs(_Fragment, { children: [_jsx("label", { htmlFor: `${id}-page`, children: "Page number" }), _jsx("input", { ref: first, id: `${id}-page`, type: "text", inputMode: "numeric", value: page, onChange: (event) => {
|
|
382
|
+
setPage(event.target.value);
|
|
383
|
+
setFailed(false);
|
|
384
|
+
} })] })) : (_jsxs(_Fragment, { children: [_jsx("label", { htmlFor: `${id}-target`, children: kind === "bookmark" ? "Bookmark" : "Heading" }), _jsx("select", { id: `${id}-target`, value: picked, onChange: (event) => setPicked(event.target.value), children: options.map((label, i) => (_jsx("option", { value: String(i), children: label }, i))) })] })), _jsx("button", { type: "submit", children: "Go to" }), failed && (_jsx("p", { className: "foli-link-error", role: "alert", children: "There is no such place." }))] }));
|
|
385
|
+
}
|
|
386
|
+
const BOOKMARK_ERRORS = {
|
|
387
|
+
"invalid-name": "A bookmark's name starts with a letter and has only letters, digits and underscores (40 at most).",
|
|
388
|
+
"no-place": "A bookmark cannot go here.",
|
|
389
|
+
missing: "That bookmark is gone.",
|
|
390
|
+
exists: "Another bookmark has that name.",
|
|
391
|
+
refused: "The content here cannot change.",
|
|
392
|
+
};
|
|
393
|
+
/** The bookmarks: add (a name used moves it, as in Word), go to, rename, delete. */
|
|
394
|
+
function BookmarksDialog({ body, active, readOnly, request, onClose, }) {
|
|
395
|
+
const id = useId();
|
|
396
|
+
const input = useRef(null);
|
|
397
|
+
const [name, setName] = useState("");
|
|
398
|
+
const [hidden, setHidden] = useState(false);
|
|
399
|
+
const [error, setError] = useState("");
|
|
400
|
+
const [list, setList] = useState(() => listBookmarks(body));
|
|
401
|
+
const [picked, setPicked] = useState("");
|
|
402
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: each request focuses it again
|
|
403
|
+
useEffect(() => {
|
|
404
|
+
input.current?.focus();
|
|
405
|
+
}, [request]);
|
|
406
|
+
useEffect(() => setList(listBookmarks(body, { hidden })), [body, hidden]);
|
|
407
|
+
const refresh = () => setList(listBookmarks(body, { hidden }));
|
|
408
|
+
const outcome = (result) => {
|
|
409
|
+
setError(result.ok ? "" : (BOOKMARK_ERRORS[result.reason ?? ""] ?? ""));
|
|
410
|
+
refresh();
|
|
411
|
+
return result.ok;
|
|
412
|
+
};
|
|
413
|
+
const chosen = list.find((b) => b.name === picked) ?? null;
|
|
414
|
+
return (_jsx("div", { role: "dialog", "aria-label": "Bookmarks", className: "foli-link-dialog foli-find-panel foli-bookmarks", onKeyDown: (event) => {
|
|
415
|
+
if (event.key !== "Escape")
|
|
416
|
+
return;
|
|
417
|
+
event.preventDefault();
|
|
418
|
+
onClose(false);
|
|
419
|
+
}, children: _jsxs("form", { noValidate: true, onSubmit: (event) => {
|
|
420
|
+
event.preventDefault();
|
|
421
|
+
if (!readOnly && outcome(insertBookmark(active, name.trim()))) {
|
|
422
|
+
setPicked(name.trim());
|
|
423
|
+
setName("");
|
|
424
|
+
}
|
|
425
|
+
}, children: [_jsx("label", { htmlFor: `${id}-name`, children: "Bookmark name" }), _jsx("input", { ref: input, id: `${id}-name`, type: "text", value: name, "aria-invalid": error ? true : undefined, onChange: (event) => {
|
|
426
|
+
setName(event.target.value);
|
|
427
|
+
setError("");
|
|
428
|
+
} }), _jsx("label", { htmlFor: `${id}-list`, children: "Bookmarks" }), _jsx("select", { id: `${id}-list`, size: 6, value: picked, onChange: (event) => {
|
|
429
|
+
setPicked(event.target.value);
|
|
430
|
+
setName(event.target.value);
|
|
431
|
+
setError("");
|
|
432
|
+
}, children: list.map((bookmark) => (_jsxs("option", { value: bookmark.name, children: [bookmark.name, bookmark.text ? `: ${bookmark.text.slice(0, 40)}` : ""] }, bookmark.name))) }), _jsxs("label", { className: "foli-find-option", children: [_jsx("input", { type: "checkbox", checked: hidden, onChange: (event) => setHidden(event.target.checked) }), "Hidden bookmarks"] }), !readOnly && _jsx("button", { type: "submit", children: "Add" }), _jsx("button", { type: "button", disabled: !chosen, onClick: () => {
|
|
433
|
+
if (chosen && goTo(body, chosen, { focus: true }))
|
|
434
|
+
onClose(true);
|
|
435
|
+
else
|
|
436
|
+
setError("No page shows that bookmark.");
|
|
437
|
+
}, children: "Go to" }), !readOnly && (_jsxs(_Fragment, { children: [_jsx("button", { type: "button", disabled: !chosen, onClick: () => {
|
|
438
|
+
if (chosen && outcome(renameBookmark(body, chosen.name, name.trim())))
|
|
439
|
+
setPicked(name.trim());
|
|
440
|
+
}, children: "Rename" }), _jsx("button", { type: "button", disabled: !chosen, onClick: () => {
|
|
441
|
+
if (chosen)
|
|
442
|
+
deleteBookmark(body, chosen.name);
|
|
443
|
+
setPicked("");
|
|
444
|
+
setName("");
|
|
445
|
+
refresh();
|
|
446
|
+
}, children: "Delete" })] })), _jsx("button", { type: "button", onClick: () => onClose(false), children: "Close" }), error && (_jsx("p", { className: "foli-link-error", role: "alert", children: error }))] }) }));
|
|
447
|
+
}
|
|
448
|
+
/** The headings of the document; a press goes there. Up and Down move between them. */
|
|
449
|
+
function OutlinePanel({ body, onClose }) {
|
|
450
|
+
const [entries, setEntries] = useState([]);
|
|
451
|
+
const list = useRef(null);
|
|
452
|
+
const caret = useEditorState((state) => state.selection.from, { editor: body });
|
|
453
|
+
useEffect(() => {
|
|
454
|
+
const read = () => setEntries(documentOutline(body.state, body.storyView?.fieldLayout ?? null));
|
|
455
|
+
read();
|
|
456
|
+
let timer;
|
|
457
|
+
let doc = body.state.doc;
|
|
458
|
+
const unsubscribe = body.subscribe((state) => {
|
|
459
|
+
if (state.doc === doc)
|
|
460
|
+
return;
|
|
461
|
+
doc = state.doc;
|
|
462
|
+
clearTimeout(timer);
|
|
463
|
+
// After the pages have settled: the entries show their numbers.
|
|
464
|
+
timer = setTimeout(read, 150);
|
|
465
|
+
});
|
|
466
|
+
return () => {
|
|
467
|
+
clearTimeout(timer);
|
|
468
|
+
unsubscribe();
|
|
469
|
+
};
|
|
470
|
+
}, [body]);
|
|
471
|
+
let current = -1;
|
|
472
|
+
entries.forEach((entry, i) => {
|
|
473
|
+
if (entry.pos < caret)
|
|
474
|
+
current = i;
|
|
475
|
+
});
|
|
476
|
+
const onKeyDown = (event) => {
|
|
477
|
+
const step = event.key === "ArrowDown" ? 1 : event.key === "ArrowUp" ? -1 : 0;
|
|
478
|
+
if (event.key === "Escape")
|
|
479
|
+
onClose();
|
|
480
|
+
else if (step) {
|
|
481
|
+
const buttons = [...(list.current?.querySelectorAll("button") ?? [])];
|
|
482
|
+
const at = buttons.indexOf(document.activeElement);
|
|
483
|
+
buttons[Math.max(0, Math.min(at + step, buttons.length - 1))]?.focus();
|
|
484
|
+
}
|
|
485
|
+
else
|
|
486
|
+
return;
|
|
487
|
+
event.preventDefault();
|
|
488
|
+
};
|
|
489
|
+
return (_jsxs("nav", { "aria-label": "Document outline", className: "foli-outline", onKeyDown: onKeyDown, children: [_jsxs("div", { className: "foli-outline-head", children: [_jsx("h2", { children: "Outline" }), _jsx("button", { type: "button", onClick: onClose, children: "Close" })] }), entries.length ? (_jsx("ol", { ref: list, children: entries.map((entry, i) => (_jsx("li", { style: { paddingInlineStart: `${(entry.level - 1) * 12}px` }, children: _jsxs("button", { type: "button", "aria-current": i === current ? "location" : undefined, onClick: () => goTo(body, { story: null, from: entry.pos + 1, to: entry.pos + 1 }, { focus: true }), children: [_jsxs("span", { children: [entry.number ? `${entry.number} ` : "", entry.text] }), entry.page && _jsx("span", { className: "foli-outline-page", children: entry.page })] }) }, entry.pos))) })) : (_jsx("p", { children: "No headings." }))] }));
|
|
490
|
+
}
|
|
491
|
+
//# sourceMappingURL=FoliNavigation.js.map
|