@folijs/react 0.2.0 → 0.4.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 CHANGED
@@ -1,5 +1,62 @@
1
1
  # @folijs/react
2
2
 
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - e2a6e23: Review as in Word: tracked changes recorded, shown, accepted and rejected; comments written, answered and resolved; both round-trip with Word.
8
+ - **Tracked changes** (`@folijs/core`): with tracking on (`createEditor({ author, trackChanges })`, `editor.commands.setTrackChanges`), every edit is recorded as Word records it: what is removed stays marked deleted, what is added is marked inserted, paragraph marks removed or added are recorded on the paragraph, formatting changes keep the properties from before the first change (`formatChange`), and deleting your own insertion removes it. Commands need no tracking code: the editor rebuilds each transaction it dispatches (`trackTransaction`). Accept and reject (`acceptChange`, `rejectChange` at the caret or in the selection, `acceptAllChanges(author?)`, `rejectAllChanges(author?)`, `nextChange`, `previousChange`, `trackedChanges(doc)`), each its own undo step; both ends of a move together. A property test checks that accepting everything gives the same document as the edits made untracked and rejecting everything gives the original.
9
+ - **Comments** (`@folijs/core`): `addComment`, `replyToComment`, `editComment`, `resolveComment`, `deleteComment`, `deleteAllComments`, with Word's anchors; comment changes are part of undo history (`CommentStep`); a comment whose text is deleted with its reference goes with it.
10
+ - **Review view** (`@folijs/core` state, drawn by `@folijs/view`): tracked changes shown as all markup (author colors, a bar beside changed paragraphs), simple markup or no markup while editing (`setReviewView`, `createEditor({ reviewView })`); while tracking, or where it is hidden, Backspace and Delete step over deleted text; the caret never goes into hidden text.
11
+ - **React** (`@folijs/react`): a review group in `FoliToolbar` (New comment, Track changes, Show changes as, previous and next change, Accept, Reject, Accept all, Reject all); `FoliComments`, a comments pane beside the pages (threads level with their text; reply, edit, resolve, delete), shown by `FoliEditor` while the document has comments (`comments` prop); `FoliEditor` props `author`, `trackChanges`, `reviewView`.
12
+ - **DOCX** (`@folijs/docx`): `DocxImport.trackRevisions` and `exportDocx(document, package?, { trackRevisions })` read and write Word's tracking setting. Checked with Word on the corpus: files with changes and comments made in Foli open without a repair prompt with those changes, authors and threads; Word's accepted and rejected text equals Foli's (case aside; table paragraphs, fields and content controls aside; one corpus document, with a content control around paragraphs, not compared); Foli reads Word's own changes and replies back.
13
+
14
+ No document format change (schema 3): 0.3.0 and 0.4.0 read each other's documents. Known limits are in [Known limitations](https://github.com/josep-audenis/foli/blob/main/docs/limitations.md) (tables are not tracked yet; dates are written in UTC).
15
+
16
+ Changed behaviour (pre-1.0 minor):
17
+ - A paragraph left with nothing by a join or by a deletion from its start is removed whole: the next paragraph keeps its own properties (before, the merged paragraph took the first one's).
18
+ - `closeHistory` makes a transaction an undo step of its own on both sides: typing right after a paste, cut or drop is now its own step.
19
+ - `FoliToolbar` shows a review group by default (Track changes, Show changes as, previous and next change, Accept, Reject, Accept all, Reject all); New comment only with its new `comments` prop (`FoliEditor` passes it).
20
+ - Tracked changes in markup are drawn in each author's color (was one fixed red), with a bar beside changed paragraphs; commented text carries `data-foli-comments`.
21
+ - `withEnvelope` ignores comments: change them with `setComments` (or the comment commands).
22
+ - `FoliEditor` puts the canvas inside a `.foli-editor-body` element (beside the comments pane): CSS that relied on `.foli-canvas` being a direct child of the editor's parent needs updating.
23
+ - Imported `w:rPrChange` properties are in canonical form (default attributes left out); inserted and deleted text in `renderDocument` and the editor is titled "Inserted by …" / "Deleted by …".
24
+
25
+ ### Patch Changes
26
+
27
+ - Updated dependencies [e2a6e23]
28
+ - @folijs/core@0.4.0
29
+ - @folijs/view@0.4.0
30
+
31
+ ## 0.3.0
32
+
33
+ ### Minor Changes
34
+
35
+ - 8da5b98: Word documents (schema v3): Foli opens a `.docx`, shows it with the file's own styles on real pages, edits it, and saves it back without losing what it does not edit.
36
+ - **Model** (`@folijs/core`, schema v3, Word-shaped): paragraph properties as attributes (style, justification, indentation, spacing, keep and widow rules, page break before, outline level, numbering, tab stops, borders, shading); run properties as marks (character style, bold, italic, underline styles, strike, font, size, color, highlight, shading, vertical alignment, caps); headings as Word's heading styles; lists as Word's numbering (formats, starts, restarts, levels, legal numbering); sections with their own page size, orientation and margins; styles with `basedOn`, document defaults and the theme in the envelope; tracked insertions and deletions and comment anchors, with the comments; content the model does not hold kept as opaque nodes. Effective formatting and list numbers resolved as Word resolves them. Documents saved by 0.1.0 and 0.2.0 load through a migration without content loss.
37
+ - **DOCX** (`@folijs/docx`, new; browser, worker and Node, no third-party dependencies): `importDocx` to schema v3 with a report of what stayed opaque; `exportDocx` rewriting only the parts the editor owns, so a document saved without edits is the original under a canonical comparison, and parts the editor does not own are written back byte for byte. Checked with Word: every corpus document, exported unchanged and edited, opens without a repair prompt.
38
+ - **View** (`@folijs/view`): `renderDocument` lays a document out read-only on Word-like pages (tracked changes as markup or final); `EditorView` edits on the same pages, each section on pages of its own size and margins, and prints one sheet per page with each section's size. A font the machine lacks falls back to a metric-compatible substitute when one is installed (Carlito, Caladea, Liberation…).
39
+ - **React** (`@folijs/react`): `FoliEditor` and `useFoliEditor` take a document of any version and edit and report it as v3; the toolbar has a style box (the document's paragraph styles, headings included), font, size, line spacing and a page break, with Word-numbered bulleted and numbered lists.
40
+ - **Fidelity with Word** (corpus of five Word-written documents; `corpus/README.md`): 106 of 106 paragraphs start on Word's page and 103 on Word's line; pages scored against Word's PDF at 0.544.
41
+
42
+ Known risks, besides those of 0.2.0 (manual IME, screen-reader and real-paste checks not run): headers, footers, footnotes and floating pictures are kept and exported but not shown; tables are shown from their XML but are not editable or split across pages; page setups and section breaks cannot be edited yet; tracked changes are shown but not recorded, accepted or rejected (Phase 9). See [Known limitations](https://github.com/josep-audenis/foli/blob/main/docs/limitations.md).
43
+
44
+ Breaking (pre-1.0 minor): upgrade every app that reads your documents before saving with 0.3.0, since 0.2.0 cannot read version 3.
45
+ - Documents persist as v3: `FoliChange.document`, `getDocument()` and `useFoliEditor` give v3; `createEditor`, `setDocument` and `FoliEditor`'s `initialContent` take a document of any version (`EditorDocument`) and migrate it.
46
+ - Names: schema v3 takes the plain ones (`FoliDocument`, `parseDocument`, `parseContent`, `schema`, `SCHEMA_VERSION` 3). `createDocument(content?, section?)` makes a v3 document: its content is v3 and its second argument a section in twips (0.2.0's took v2 content and settings in millimetres; both still type-check, so a 0.2.0 call such as `createDocument(htmlToDoc(html))` fails in `createEditor` or gives a wrong page size). v2's are `FoliDocumentV2` and `parseContentV2`, and `htmlToDoc` still returns v2 content; v2's `schema`, `parseDocument` and `SCHEMA_VERSION` are no longer exported (`parseDocument` reads v1 and v2 documents and migrates them). `MARK_TYPES`, `HEADING_LEVELS` and the JSON types such as `DocJSON` still describe v2.
47
+ - Marks follow Word: text color is the `color` mark (`value`), and `highlight` takes a Word color name (the palette is Word's); there is no `textColor` mark. Use `setTextColor`, `setHighlight` and `colorAt(state, "textColor" | "highlight")` rather than `toggleMark` or `isMarkActive` with these marks.
48
+ - Links: `parseDocument` keeps any link target a file has (a `.docx` may hold `file:` links, say), where 0.2.0 rejected unsafe ones. Foli's view only makes a link of a safe target (`isSafeHref`); check it too wherever you turn a document's links into HTML yourself. Commands still refuse an unsafe href.
49
+ - Keyboard: Tab types a tab outside lists, as in Word (in 0.2.0 it moved the focus); Escape, then Tab, moves the focus out of the editor.
50
+ - Lists: `toggleList(kind)` and `wrapInList(kind)` take no attributes; `splitListItem`, `sinkListItem`, `liftListItem` and `liftListItemAtStart` are commands, not factories.
51
+ - On a state without a v3 envelope, `setBlockType` and the list and format commands do not apply.
52
+ - Removed: `insertHorizontalRule` (and `commands.insertHorizontalRule`), `listTypeAt`, the ¶, H1–H3 and rule toolbar buttons (the style box replaces them), and the CSS variables `--foli-font-family`, `--foli-font-size`, `--foli-line-height`, `--foli-link-color`, `--foli-marker-color`, `--foli-rule-color` and `--foli-rule-thickness` (the document's styles set them now).
53
+
54
+ ### Patch Changes
55
+
56
+ - Updated dependencies [8da5b98]
57
+ - @folijs/core@0.3.0
58
+ - @folijs/view@0.3.0
59
+
3
60
  ## 0.2.0
4
61
 
5
62
  ### Minor Changes
package/README.md CHANGED
@@ -17,7 +17,8 @@ import { createDocument, parseDocument } from "@folijs/core";
17
17
  import { type FoliChange, FoliEditor } from "@folijs/react";
18
18
  import "@folijs/react/styles.css";
19
19
 
20
- // Load: parseDocument validates the saved JSON (throws FoliDocumentError when invalid).
20
+ // Load: parseDocument validates the saved JSON, migrating an older document (throws
21
+ // FoliDocumentError when invalid).
21
22
  const saved = localStorage.getItem("doc");
22
23
  const initial = saved ? parseDocument(JSON.parse(saved)) : createDocument();
23
24
 
@@ -42,7 +43,7 @@ Browser-only as written; for server rendering (Next.js) and saving on page close
42
43
  document appears on hydration.
43
44
 
44
45
  - [Getting started](https://github.com/josep-audenis/foli/blob/main/docs/getting-started.md): loading and saving, read-only, Next.js, your own toolbar
45
- - [API reference](https://github.com/josep-audenis/foli/blob/main/docs/api.md#folireact)
46
+ - [API reference](https://github.com/josep-audenis/foli/blob/main/docs/api.md#folijsreact)
46
47
  - [Styling](https://github.com/josep-audenis/foli/blob/main/docs/styling.md): CSS variables, dark theme, print
47
48
  - [Known limitations](https://github.com/josep-audenis/foli/blob/main/docs/limitations.md)
48
49
 
@@ -0,0 +1,22 @@
1
+ import { type Editor } from "@folijs/core";
2
+ export interface FoliCommentsProps {
3
+ /** Default: the editor of the nearest `FoliEditorProvider`. */
4
+ editor?: Editor | undefined;
5
+ /** Comments can be read, not changed (pass it with a `readOnly` canvas). */
6
+ readOnly?: boolean | undefined;
7
+ /** Accessible name of the pane (default "Comments"). */
8
+ label?: string | undefined;
9
+ className?: string | undefined;
10
+ /** Not shown (still following the editor: a comment made meanwhile opens for writing). */
11
+ hidden?: boolean | undefined;
12
+ }
13
+ /**
14
+ * The comments pane: the document's comment threads beside the pages, each next to its text,
15
+ * moved down when they would overlap. Focusing a thread marks its text in the document; a
16
+ * caret in commented text marks its thread. Reply, edit (plain text), resolve, reopen and
17
+ * delete; a comment made empty while the pane shows (the toolbar's "New comment") opens for
18
+ * writing, and goes when cancelled empty. Render it beside the pages (`FoliEditor` does): it
19
+ * finds the comments' text in the nearest ancestor holding them.
20
+ */
21
+ export declare function FoliComments({ editor: editorProp, readOnly, label, className, hidden, }: FoliCommentsProps): import("react").JSX.Element;
22
+ //# sourceMappingURL=FoliComments.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FoliComments.d.ts","sourceRoot":"","sources":["../src/FoliComments.tsx"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,MAAM,EAOZ,MAAM,cAAc,CAAC;AAItB,MAAM,WAAW,iBAAiB;IAChC,+DAA+D;IAC/D,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,4EAA4E;IAC5E,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC/B,wDAAwD;IACxD,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,0FAA0F;IAC1F,MAAM,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAC9B;AAkGD;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,EAC3B,MAAM,EAAE,UAAU,EAClB,QAAgB,EAChB,KAAkB,EAClB,SAAS,EACT,MAAc,GACf,EAAE,iBAAiB,+BAyNnB"}
@@ -0,0 +1,275 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { commentAnchors, deleteComment, editComment, replyToComment, resolveComment, wordContext, } from "@folijs/core";
3
+ import { useEffect, useId, useRef, useState } from "react";
4
+ import { useEditorOrContext, useEditorState, useIsomorphicLayoutEffect } from "./editor.js";
5
+ const EMPTY = [];
6
+ /** The comments of the editor's document, as threads in document order. */
7
+ function threadsOf(state, comments) {
8
+ const anchors = commentAnchors(state.doc);
9
+ const byId = new Map(comments.map((c) => [c.id, c]));
10
+ const rootOf = (c) => {
11
+ let root = c;
12
+ const seen = new Set();
13
+ while (root.parent !== undefined && byId.has(root.parent) && !seen.has(root.id)) {
14
+ seen.add(root.id);
15
+ root = byId.get(root.parent);
16
+ }
17
+ return root;
18
+ };
19
+ const threads = new Map();
20
+ for (const c of comments) {
21
+ const root = rootOf(c);
22
+ let thread = threads.get(root.id);
23
+ if (!thread) {
24
+ const a = anchors.get(root.id);
25
+ const pos = a?.start ?? a?.reference ?? Number.MAX_SAFE_INTEGER;
26
+ thread = { comment: root, replies: [], pos, end: a?.end ?? a?.reference ?? pos };
27
+ threads.set(root.id, thread);
28
+ }
29
+ if (c !== root)
30
+ thread.replies.push(c);
31
+ }
32
+ return [...threads.values()].sort((a, b) => a.pos - b.pos || a.comment.id - b.comment.id);
33
+ }
34
+ /** A paragraph's text as shown: tabs and line breaks kept. */
35
+ const paragraphText = (p) => (p.content ?? [])
36
+ .map((n) => n.type === "text"
37
+ ? (n.text ?? "")
38
+ : n.type === "tab"
39
+ ? "\t"
40
+ : n.type === "hardBreak"
41
+ ? "\n"
42
+ : "")
43
+ .join("");
44
+ /** A comment's text: its paragraphs' text, a line each. */
45
+ const textOf = (c) => c.content.map(paragraphText).join("\n");
46
+ /**
47
+ * Whether the pane edits a comment as text without losing anything: paragraphs of unformatted
48
+ * text, all in one paragraph style or none (Word gives its comments the CommentText style).
49
+ */
50
+ function plain(c) {
51
+ const styles = new Set(c.content.map((p) => p.attrs?.style));
52
+ return (styles.size <= 1 &&
53
+ c.content.every((p) => p.type === "paragraph" &&
54
+ Object.keys(p.attrs ?? {}).every((key) => key === "style") &&
55
+ (p.content ?? []).every((n) => n.type === "text" && !n.marks?.length)));
56
+ }
57
+ /** `text` as `c`'s content: a paragraph per line, in `c`'s paragraph style. */
58
+ function contentLike(c, text) {
59
+ const style = c.content[0]?.attrs?.style;
60
+ return text.split(/\r\n|\r|\n/).map((line) => ({
61
+ type: "paragraph",
62
+ ...(style ? { attrs: { style } } : {}),
63
+ ...(line ? { content: [{ type: "text", text: line }] } : {}),
64
+ }));
65
+ }
66
+ const isEmpty = (c) => textOf(c).trim() === "";
67
+ /** The nearest ancestor of the pane that holds the editor's pages. */
68
+ function pagesAround(pane) {
69
+ let element = pane.parentElement;
70
+ while (element && !element.querySelector(".foli-page"))
71
+ element = element.parentElement;
72
+ return element;
73
+ }
74
+ const dateOf = (date) => (date ? date.slice(0, 10) : "");
75
+ const nameOf = (c) => c.author || "an unknown author";
76
+ /**
77
+ * The comments pane: the document's comment threads beside the pages, each next to its text,
78
+ * moved down when they would overlap. Focusing a thread marks its text in the document; a
79
+ * caret in commented text marks its thread. Reply, edit (plain text), resolve, reopen and
80
+ * delete; a comment made empty while the pane shows (the toolbar's "New comment") opens for
81
+ * writing, and goes when cancelled empty. Render it beside the pages (`FoliEditor` does): it
82
+ * finds the comments' text in the nearest ancestor holding them.
83
+ */
84
+ export function FoliComments({ editor: editorProp, readOnly = false, label = "Comments", className, hidden = false, }) {
85
+ const editor = useEditorOrContext(editorProp, "FoliComments");
86
+ const comments = useEditorState((state) => wordContext(state)?.envelope.comments ?? EMPTY, {
87
+ editor,
88
+ });
89
+ const documentId = useEditorState((state) => wordContext(state)?.id ?? "", { editor });
90
+ const doc = useEditorState((state) => state.doc, { editor });
91
+ const head = useEditorState((state) => state.selection.head, { editor });
92
+ const threads = threadsOf(editor.state, comments);
93
+ const pane = useRef(null);
94
+ const [tops, setTops] = useState([]);
95
+ const [height, setHeight] = useState(0);
96
+ const [writing, setWriting] = useState(null);
97
+ const [focused, setFocused] = useState(null);
98
+ /** The comments the pane has seen, per document: only ones made later open for writing. */
99
+ const known = useRef(null);
100
+ /** The comments the pane opened for writing: cancelled while empty, they go. */
101
+ const created = useRef(new Set());
102
+ /** After a change, the element to focus (the next thread, the button that opened a form). */
103
+ const refocus = useRef(null);
104
+ useEffect(() => {
105
+ const seen = known.current;
106
+ const same = seen?.document === documentId;
107
+ const objects = same ? seen.objects : new WeakSet();
108
+ known.current = { document: documentId, objects, ids: new Set(comments.map((c) => c.id)) };
109
+ // New: an id that was not there, and an object never seen (not one undo brought back).
110
+ const fresh = same ? comments.find((c) => !seen.ids.has(c.id) && !objects.has(c)) : undefined;
111
+ for (const c of comments)
112
+ objects.add(c);
113
+ // The first render, or another document: what is there was not made here, and nothing
114
+ // open for writing belongs to it.
115
+ if (!same) {
116
+ if (seen) {
117
+ created.current.clear();
118
+ setWriting(null);
119
+ }
120
+ return;
121
+ }
122
+ // A comment that comes back (undo) is the very object seen before: not new.
123
+ if (fresh && !readOnly && isEmpty(fresh) && plain(fresh)) {
124
+ created.current.add(fresh.id);
125
+ setWriting({ id: fresh.id, reply: false });
126
+ }
127
+ }, [comments, documentId, readOnly]);
128
+ // Each thread next to its text, pushed down below the one before.
129
+ const measure = () => {
130
+ const root = pane.current;
131
+ const container = root && pagesAround(root);
132
+ if (!root || !container)
133
+ return;
134
+ const paneTop = root.getBoundingClientRect().top;
135
+ // The first text of each comment, in one pass.
136
+ const anchors = new Map();
137
+ for (const element of container.querySelectorAll("[data-foli-comments], [data-foli-comment-reference]")) {
138
+ const ids = (element.dataset.foliComments ?? element.dataset.foliCommentReference ?? "")
139
+ .split(" ")
140
+ .filter(Boolean);
141
+ for (const id of ids)
142
+ if (!anchors.has(id))
143
+ anchors.set(id, element);
144
+ }
145
+ const items = [...root.querySelectorAll(":scope > .foli-comment-thread")];
146
+ const next = [];
147
+ let bottom = 0;
148
+ threads.forEach((thread, i) => {
149
+ const anchor = anchors.get(String(thread.comment.id));
150
+ const wanted = anchor ? anchor.getBoundingClientRect().top - paneTop : bottom;
151
+ const top = Math.max(wanted, bottom);
152
+ next.push(top);
153
+ bottom = top + (items[i]?.offsetHeight ?? 0) + 8;
154
+ });
155
+ setTops((old) => old.length === next.length && old.every((t, i) => Math.abs(t - next[i]) < 0.5)
156
+ ? old
157
+ : next);
158
+ setHeight(bottom);
159
+ };
160
+ const measureRef = useRef(measure);
161
+ measureRef.current = measure;
162
+ // biome-ignore lint/correctness/useExhaustiveDependencies: measured after every change of what it shows.
163
+ useIsomorphicLayoutEffect(measure, [doc, comments, writing, threads.length]);
164
+ useEffect(() => {
165
+ const container = pane.current && pagesAround(pane.current);
166
+ if (!container || typeof ResizeObserver === "undefined")
167
+ return;
168
+ const observer = new ResizeObserver(() => measureRef.current());
169
+ observer.observe(container);
170
+ return () => observer.disconnect();
171
+ }, []);
172
+ // Focus where the last action left it (after React drew the change).
173
+ useEffect(() => {
174
+ const focus = refocus.current;
175
+ refocus.current = null;
176
+ focus?.();
177
+ });
178
+ // The focused thread's text marked in the document (again after the view redraws it).
179
+ // biome-ignore lint/correctness/useExhaustiveDependencies: `doc` changes mean redrawn text to mark.
180
+ useEffect(() => {
181
+ const container = pane.current && pagesAround(pane.current);
182
+ if (!container || focused === null)
183
+ return;
184
+ const marked = [
185
+ ...container.querySelectorAll(`[data-foli-comments~="${focused}"]`),
186
+ ];
187
+ for (const element of marked)
188
+ element.classList.add("foli-comment-active");
189
+ return () => {
190
+ for (const element of marked)
191
+ element.classList.remove("foli-comment-active");
192
+ };
193
+ }, [focused, doc]);
194
+ const run = (command) => editor.run(command);
195
+ /** Focus the thread of `id` (its first button), else the pane, else the document. */
196
+ const focusThread = (id) => {
197
+ refocus.current = () => {
198
+ const root = pane.current;
199
+ const thread = id === undefined ? null : root?.querySelector(`[data-thread="${id}"]`);
200
+ const document = root && pagesAround(root)?.querySelector('[role="textbox"]');
201
+ (thread?.querySelector("button") ??
202
+ thread ??
203
+ (root?.hidden ? document : root))?.focus();
204
+ };
205
+ };
206
+ return (_jsxs("aside", { ref: pane, tabIndex: -1, className: `foli-comments${className ? ` ${className}` : ""}`, "aria-label": label, hidden: hidden, style: height ? { minHeight: height } : undefined, children: [threads.length === 0 && _jsx("p", { className: "foli-comments-empty", children: "No comments" }), threads.map((thread, i) => {
207
+ const { comment } = thread;
208
+ const active = head >= thread.pos && head <= thread.end + 1;
209
+ const after = threads[i + 1] ?? threads[i - 1];
210
+ const canReply = !readOnly && editor.can(replyToComment(comment.id, "x"));
211
+ return (_jsxs("article", { "data-thread": comment.id, tabIndex: -1, className: "foli-comment-thread", "data-active": active || undefined, "data-done": comment.done || undefined, style: { top: tops[i] ?? 0 }, "aria-label": `Comment by ${nameOf(comment)}${comment.done ? ", resolved" : ""}`, onFocus: () => setFocused(comment.id), onBlur: (e) => {
212
+ if (!e.currentTarget.contains(e.relatedTarget))
213
+ setFocused(null);
214
+ }, children: [[comment, ...thread.replies].map((c) => (_jsx(CommentView, { comment: c, root: c === comment, readOnly: readOnly, canReply: canReply, canDelete: !readOnly && editor.can(deleteComment(c.id)), editing: writing?.id === c.id && !writing.reply, onEdit: () => setWriting({ id: c.id, reply: false }), onReply: () => setWriting({ id: comment.id, reply: true }), onResolve: () => {
215
+ run(resolveComment(comment.id, !comment.done));
216
+ focusThread(comment.id);
217
+ }, onDelete: () => {
218
+ run(deleteComment(c.id));
219
+ focusThread(c === comment ? after?.comment.id : comment.id);
220
+ }, onSave: (text) => {
221
+ if (!run(editComment(c.id, contentLike(c, text))))
222
+ return false;
223
+ created.current.delete(c.id);
224
+ setWriting(null);
225
+ focusThread(comment.id);
226
+ return true;
227
+ }, onCancel: () => {
228
+ // A comment made here and left empty goes.
229
+ const gone = created.current.has(c.id) && isEmpty(c);
230
+ created.current.delete(c.id);
231
+ if (gone)
232
+ run(deleteComment(c.id));
233
+ setWriting(null);
234
+ focusThread(gone ? after?.comment.id : comment.id);
235
+ } }, c.id))), writing?.reply && writing.id === comment.id && (_jsx(CommentForm, { label: "Reply", initial: "", onSave: (text) => {
236
+ if (text.trim() && !run(replyToComment(comment.id, text)))
237
+ return false;
238
+ setWriting(null);
239
+ focusThread(comment.id);
240
+ return true;
241
+ }, onCancel: () => {
242
+ setWriting(null);
243
+ focusThread(comment.id);
244
+ } }))] }, comment.id));
245
+ })] }));
246
+ }
247
+ function CommentView({ comment, root, readOnly, canReply, canDelete, editing, onEdit, onReply, onResolve, onDelete, onSave, onCancel, }) {
248
+ const author = comment.author || "Unknown author";
249
+ const what = root ? "comment" : "reply";
250
+ return (_jsxs("div", { className: "foli-comment", children: [_jsxs("p", { className: "foli-comment-meta", children: [_jsx("strong", { children: author }), " ", _jsx("span", { children: dateOf(comment.date) })] }), editing ? (_jsx(CommentForm, { label: "Comment", initial: textOf(comment), onSave: onSave, onCancel: onCancel })) : (_jsx("div", { className: "foli-comment-text", children: comment.content.map((p, i) => (_jsx("p", { children: paragraphText(p) }, i))) })), !readOnly && !editing && (_jsxs("div", { className: "foli-comment-actions", children: [root && canReply && (_jsx("button", { type: "button", onClick: onReply, children: "Reply" })), plain(comment) && (_jsx("button", { type: "button", onClick: onEdit, "aria-label": `Edit ${what} by ${nameOf(comment)}`, children: "Edit" })), root && (_jsx("button", { type: "button", onClick: onResolve, children: comment.done ? "Reopen" : "Resolve" })), canDelete && (_jsx("button", { type: "button", onClick: onDelete, "aria-label": `Delete ${what} by ${nameOf(comment)}`, children: "Delete" }))] }))] }));
251
+ }
252
+ function CommentForm({ label, initial, onSave, onCancel, }) {
253
+ const id = useId();
254
+ const [text, setText] = useState(initial);
255
+ const [failed, setFailed] = useState(false);
256
+ const field = useRef(null);
257
+ useEffect(() => field.current?.focus(), []);
258
+ const save = () => setFailed(!onSave(text));
259
+ const submit = (e) => {
260
+ e.preventDefault();
261
+ save();
262
+ };
263
+ const keys = (e) => {
264
+ if (e.key === "Escape") {
265
+ e.preventDefault();
266
+ onCancel();
267
+ }
268
+ else if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
269
+ e.preventDefault();
270
+ save();
271
+ }
272
+ };
273
+ return (_jsxs("form", { className: "foli-comment-form", onSubmit: submit, children: [_jsx("label", { htmlFor: id, children: label }), _jsx("textarea", { id: id, ref: field, value: text, rows: 3, onChange: (e) => setText(e.target.value), onKeyDown: keys, "aria-invalid": failed || undefined, "aria-describedby": failed ? `${id}-error` : undefined }), failed && (_jsx("p", { id: `${id}-error`, className: "foli-comment-error", role: "alert", children: "Could not be saved here." })), _jsxs("div", { className: "foli-comment-actions", children: [_jsx("button", { type: "submit", children: "Save" }), _jsx("button", { type: "button", onClick: onCancel, children: "Cancel" })] })] }));
274
+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AE,YAAG,KAAK,GAAS,EACnC,mBACE,EAAE,EAAE,EAAE,EACN,GAAG,EAAE,KAAK,EACV,KAAK,EAAE,IAAI,EACX,IAAI,EAAE,CAAC,EACP,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EACxC,SAAS,EAAE,IAAI,kBACD,MAAM,IAAI,SAAS,sBACf,MAAM,CAAC,CAAC,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,SAAS,GACpD,EACD,MAAM,IAAI,CACT,YAAG,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,SAAS,EAAC,oBAAoB,EAAC,IAAI,EAAC,OAAO,yCAE7D,CACL,EACD,eAAK,SAAS,EAAC,sBAAsB,aACnC,iBAAQ,IAAI,EAAC,QAAQ,qBAAc,EACnC,iBAAQ,IAAI,EAAC,QAAQ,EAAC,OAAO,EAAE,QAAQ,uBAE9B,IACL,IACD,CACR,CAAC;AACJ,CAAC"}
@@ -1,4 +1,4 @@
1
- import { type Editor, type FoliDocument, type Plugin, type Transaction } from "@folijs/core";
1
+ import { type Editor, type EditorDocument, type FoliDocument, type Plugin, type ReviewView, type Transaction } from "@folijs/core";
2
2
  import { type ReactNode } from "react";
3
3
  import { type FoliCanvasHandle, type FoliCanvasProps } from "./FoliCanvas.js";
4
4
  /**
@@ -11,15 +11,24 @@ export interface FoliChange {
11
11
  readonly transactions: readonly Transaction[];
12
12
  /**
13
13
  * The whole document right after this change, serialized on first read (keep reads out of
14
- * the hot path of typing: a debounced save reads only the last change's).
14
+ * the hot path of typing: a debounced save reads only the last change's). Schema v3.
15
15
  */
16
16
  readonly document: FoliDocument;
17
17
  }
18
18
  export interface FoliEditorProps extends Omit<FoliCanvasProps, "editor"> {
19
- /** Read once on mount. To load another document later: `editor.setDocument()` or a new `key`. */
20
- initialContent?: FoliDocument | undefined;
19
+ /**
20
+ * Read once on mount: a document of any version (0.1.0 and 0.2.0 documents are migrated to
21
+ * schema v3). To load another document later: `editor.setDocument()` or a new `key`.
22
+ */
23
+ initialContent?: EditorDocument | undefined;
21
24
  /** Read once on mount. */
22
25
  plugins?: readonly Plugin[] | undefined;
26
+ /** Read once on mount: who edits (tracked changes are made in this name). */
27
+ author?: string | undefined;
28
+ /** Read once on mount: record edits as tracked changes (the toolbar turns it on and off). */
29
+ trackChanges?: boolean | undefined;
30
+ /** Read once on mount: how tracked changes show (the toolbar changes it). */
31
+ reviewView?: ReviewView | undefined;
23
32
  /**
24
33
  * Called after every change to the document's content made through transactions (typing,
25
34
  * commands, undo). Not for selection changes, and not for `editor.setDocument()`, whose
@@ -28,6 +37,11 @@ export interface FoliEditorProps extends Omit<FoliCanvasProps, "editor"> {
28
37
  onChange?: ((change: FoliChange) => void) | undefined;
29
38
  /** Show the default `FoliToolbar` above the pages (default true). */
30
39
  toolbar?: boolean | undefined;
40
+ /**
41
+ * Show the comments pane (`FoliComments`) beside the pages: `"auto"` (the default) while the
42
+ * document has comments, `true` always, `false` never.
43
+ */
44
+ comments?: boolean | "auto" | undefined;
31
45
  /** Rendered between the toolbar and the pages, inside the editor's context. */
32
46
  children?: ReactNode | undefined;
33
47
  }
@@ -1 +1 @@
1
- {"version":3,"file":"FoliEditor.d.ts","sourceRoot":"","sources":["../src/FoliEditor.tsx"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,MAAM,EACX,KAAK,YAAY,EACjB,KAAK,MAAM,EACX,KAAK,WAAW,EACjB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAc,KAAK,SAAS,EAA+B,MAAM,OAAO,CAAC;AAEhF,OAAO,EAAc,KAAK,gBAAgB,EAAE,KAAK,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAG1F;;;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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Y,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,8GA2ErB,CAAC"}
@@ -1,16 +1,18 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { createDocument, } from "@folijs/core";
2
+ import { wordContext, } from "@folijs/core";
3
3
  import { forwardRef, useImperativeHandle, useRef } from "react";
4
- import { FoliEditorProvider, useFoliEditor, useIsomorphicLayoutEffect } from "./editor.js";
4
+ import { FoliEditorProvider, useEditorState, useFoliEditor, useIsomorphicLayoutEffect, } from "./editor.js";
5
5
  import { FoliCanvas } from "./FoliCanvas.js";
6
+ import { FoliComments } from "./FoliComments.js";
6
7
  import { FoliToolbar } from "./FoliToolbar.js";
7
8
  /**
8
9
  * An editable document on real pages with a toolbar: creates its editor, provides it to
9
10
  * `children` and shows it. Uncontrolled: the editor owns the document; React observes it
10
11
  * through `onChange`, a parent reaches it through a `ref`.
11
12
  */
12
- export const FoliEditor = forwardRef(function FoliEditor({ initialContent, plugins, onChange, toolbar = true, children, ...canvas }, ref) {
13
- const editor = useFoliEditor({ initialContent, plugins });
13
+ export const FoliEditor = forwardRef(function FoliEditor({ initialContent, plugins, author, trackChanges, reviewView, onChange, toolbar = true, comments = "auto", children, ...canvas }, ref) {
14
+ const editor = useFoliEditor({ initialContent, plugins, author, trackChanges, reviewView });
15
+ const hasComments = useEditorState((state) => (wordContext(state)?.envelope.comments.length ?? 0) > 0, { editor });
14
16
  const onChangeRef = useRef(onChange);
15
17
  const canvasRef = useRef(null);
16
18
  useImperativeHandle(ref, () => ({ editor, focus: () => canvasRef.current?.focus() }), [editor]);
@@ -22,17 +24,19 @@ export const FoliEditor = forwardRef(function FoliEditor({ initialContent, plugi
22
24
  if (!listener || !transactions.some((tr) => tr.docChanged))
23
25
  return;
24
26
  // The state is immutable: keeping it makes a later read give this change's document.
25
- const { settings } = editor;
26
27
  let document;
27
28
  listener({
28
29
  editor,
29
30
  transactions,
30
31
  get document() {
31
- document ??= createDocument(state.doc.toJSON(), settings);
32
+ document ??= {
33
+ ...structuredClone(wordContext(state)?.envelope),
34
+ content: state.doc.toJSON(),
35
+ };
32
36
  return document;
33
37
  },
34
38
  });
35
39
  }), [editor]);
36
- return (_jsxs(FoliEditorProvider, { editor: editor, children: [toolbar && (_jsx(FoliToolbar, { editor: editor, disabled: canvas.readOnly, onClickCommand: () => canvasRef.current?.focus() })), children, _jsx(FoliCanvas, { ref: canvasRef, editor: editor, ...canvas })] }));
40
+ return (_jsxs(FoliEditorProvider, { editor: editor, children: [toolbar && (_jsx(FoliToolbar, { editor: editor, disabled: canvas.readOnly, comments: comments !== false, 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 }))] })] }));
37
41
  });
38
42
  //# sourceMappingURL=FoliEditor.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"FoliEditor.js","sourceRoot":"","sources":["../src/FoliEditor.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,cAAc,GAMf,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,UAAU,EAAkB,mBAAmB,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAChF,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAC3F,OAAO,EAAE,UAAU,EAA+C,MAAM,iBAAiB,CAAC;AAC1F,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAuC/C;;;;GAIG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,UAAU,CAAoC,SAAS,UAAU,CACzF,EAAE,cAAc,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,GAAG,IAAI,EAAE,QAAQ,EAAE,GAAG,MAAM,EAAE,EAC1E,GAAG;IAEH,MAAM,MAAM,GAAG,aAAa,CAAC,EAAE,cAAc,EAAE,OAAO,EAAE,CAAC,CAAC;IAC1D,MAAM,WAAW,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;IACrC,MAAM,SAAS,GAAG,MAAM,CAAmB,IAAI,CAAC,CAAC;IAEjD,mBAAmB,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;IAEhG,yBAAyB,CAAC,GAAG,EAAE;QAC7B,WAAW,CAAC,OAAO,GAAG,Q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AC"}
@@ -14,15 +14,20 @@ export interface FoliToolbarProps {
14
14
  onClickCommand?: (() => void) | undefined;
15
15
  /** Accessible name of the toolbar (default "Formatting"). */
16
16
  label?: string | undefined;
17
+ /**
18
+ * Show "New comment": only where a comments pane (`FoliComments`) lets the comment be written
19
+ * (`FoliEditor` passes it). Default false.
20
+ */
21
+ comments?: boolean | undefined;
17
22
  className?: string | undefined;
18
23
  }
19
24
  /**
20
- * Formatting buttons for an editor: marks, link (a dialog, also on Mod-K in the document), text
21
- * color and highlight menus, paragraph and heading levels, alignment, lists (bulleted,
22
- * numbered, decrease and increase indent), undo, redo, horizontal rule, page break. One tab stop (arrow keys,
23
- * Home and End move between buttons); toggles carry
25
+ * Word's formatting controls for an editor: paragraph style, font and size boxes, marks, link (a
26
+ * dialog, also on Mod-K in the document), text color and highlight menus, alignment and line
27
+ * spacing, lists (bulleted, numbered, decrease and increase indent), undo, redo, page break.
28
+ * One tab stop (arrow keys, Home and End move between buttons); toggles carry
24
29
  * `aria-pressed`; a button whose command cannot run now is `aria-disabled` (still focusable).
25
30
  * Clicks leave the focus and selection in the document.
26
31
  */
27
- export declare function FoliToolbar({ editor: given, disabled, onClickCommand, label, className, }: FoliToolbarProps): import("react").JSX.Element;
32
+ export declare function FoliToolbar({ editor: given, disabled, onClickCommand, label, className, comments, }: FoliToolbarProps): import("react").JSX.Element;
28
33
  //# sourceMappingURL=FoliToolbar.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FoliToolbar.d.ts","sourceRoot":"","sources":["../src/FoliToolbar.tsx"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,MAAM,EA0BZ,MAAM,cAAc,CAAC;AActB,MAAM,WAAW,gBAAgB;IAC/B,+DAA+D;IAC/D,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC/B;;;OAGG;IACH,cAAc,CAAC,EAAE,CAAC,M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