@folijs/react 0.5.0 → 1.0.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 +178 -0
- package/README.md +14 -8
- package/dist/FoliComments.d.ts.map +1 -1
- package/dist/FoliComments.js +5 -1
- package/dist/FoliComments.js.map +1 -1
- package/dist/FoliEditor.d.ts +17 -4
- package/dist/FoliEditor.d.ts.map +1 -1
- package/dist/FoliEditor.js +16 -8
- 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 +492 -0
- package/dist/FoliNavigation.js.map +1 -0
- package/dist/FoliToolbar.d.ts +81 -6
- package/dist/FoliToolbar.d.ts.map +1 -1
- package/dist/FoliToolbar.js +872 -67
- package/dist/FoliToolbar.js.map +1 -1
- package/dist/editor.d.ts +38 -10
- package/dist/editor.d.ts.map +1 -1
- package/dist/editor.js +62 -2
- package/dist/editor.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
- package/src/FoliComments.tsx +3 -1
- package/src/FoliEditor.tsx +41 -17
- package/src/FoliNavigation.tsx +894 -0
- package/src/FoliToolbar.tsx +1417 -92
- package/src/editor.tsx +137 -3
- package/src/index.ts +15 -1
- package/styles.css +180 -0
package/src/FoliEditor.tsx
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import type {
|
|
2
|
+
Editor,
|
|
3
|
+
EditorDocument,
|
|
4
|
+
Extension,
|
|
5
|
+
FoliDocument,
|
|
6
|
+
Plugin,
|
|
7
|
+
ReviewView,
|
|
8
|
+
Transaction,
|
|
9
9
|
} from "@folijs/core";
|
|
10
|
+
import { documentJSON, wordContext } from "@folijs/core/internal";
|
|
10
11
|
import { forwardRef, type ReactNode, useImperativeHandle, useRef } from "react";
|
|
11
12
|
import {
|
|
12
13
|
FoliEditorProvider,
|
|
@@ -16,7 +17,8 @@ import {
|
|
|
16
17
|
} from "./editor.js";
|
|
17
18
|
import { FoliCanvas, type FoliCanvasHandle, type FoliCanvasProps } from "./FoliCanvas.js";
|
|
18
19
|
import { FoliComments } from "./FoliComments.js";
|
|
19
|
-
import {
|
|
20
|
+
import { FoliNavigation } from "./FoliNavigation.js";
|
|
21
|
+
import { FoliToolbar, type ToolbarItem } from "./FoliToolbar.js";
|
|
20
22
|
|
|
21
23
|
/**
|
|
22
24
|
* A change to the document's content, as `FoliEditor` reports it. `document` is a getter:
|
|
@@ -39,8 +41,17 @@ export interface FoliEditorProps extends Omit<FoliCanvasProps, "editor"> {
|
|
|
39
41
|
* schema v3). To load another document later: `editor.setDocument()` or a new `key`.
|
|
40
42
|
*/
|
|
41
43
|
initialContent?: EditorDocument | undefined;
|
|
42
|
-
/**
|
|
44
|
+
/**
|
|
45
|
+
* Read once on mount: a different list later is ignored, with a warning unless
|
|
46
|
+
* `process.env.NODE_ENV` is `"production"` at run time (`useFoliEditor`). To change them, give
|
|
47
|
+
* `FoliEditor` a new `key`.
|
|
48
|
+
*/
|
|
43
49
|
plugins?: readonly Plugin[] | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* Read once on mount, as `plugins`: custom nodes and marks with their view hooks
|
|
52
|
+
* (`ViewExtension`).
|
|
53
|
+
*/
|
|
54
|
+
extensions?: readonly Extension[] | undefined;
|
|
44
55
|
/** Read once on mount: who edits (tracked changes are made in this name). */
|
|
45
56
|
author?: string | undefined;
|
|
46
57
|
/** Read once on mount: record edits as tracked changes (the toolbar turns it on and off). */
|
|
@@ -53,8 +64,11 @@ export interface FoliEditorProps extends Omit<FoliCanvasProps, "editor"> {
|
|
|
53
64
|
* caller already has the document.
|
|
54
65
|
*/
|
|
55
66
|
onChange?: ((change: FoliChange) => void) | undefined;
|
|
56
|
-
/**
|
|
57
|
-
|
|
67
|
+
/**
|
|
68
|
+
* Show `FoliToolbar` above the pages (default true): with `defaultToolbarItems`, or with these
|
|
69
|
+
* groups of items (`FoliToolbarProps.items`).
|
|
70
|
+
*/
|
|
71
|
+
toolbar?: boolean | readonly (readonly ToolbarItem[])[] | undefined;
|
|
58
72
|
/**
|
|
59
73
|
* Show the comments pane (`FoliComments`) beside the pages: `"auto"` (the default) while the
|
|
60
74
|
* document has comments, `true` always, `false` never.
|
|
@@ -78,6 +92,7 @@ export const FoliEditor = forwardRef<FoliEditorHandle, FoliEditorProps>(function
|
|
|
78
92
|
{
|
|
79
93
|
initialContent,
|
|
80
94
|
plugins,
|
|
95
|
+
extensions,
|
|
81
96
|
author,
|
|
82
97
|
trackChanges,
|
|
83
98
|
reviewView,
|
|
@@ -89,7 +104,14 @@ export const FoliEditor = forwardRef<FoliEditorHandle, FoliEditorProps>(function
|
|
|
89
104
|
},
|
|
90
105
|
ref,
|
|
91
106
|
) {
|
|
92
|
-
const editor = useFoliEditor({
|
|
107
|
+
const editor = useFoliEditor({
|
|
108
|
+
initialContent,
|
|
109
|
+
plugins,
|
|
110
|
+
extensions,
|
|
111
|
+
author,
|
|
112
|
+
trackChanges,
|
|
113
|
+
reviewView,
|
|
114
|
+
});
|
|
93
115
|
const hasComments = useEditorState(
|
|
94
116
|
(state) => (wordContext(state)?.envelope.comments.length ?? 0) > 0,
|
|
95
117
|
{ editor },
|
|
@@ -114,10 +136,10 @@ export const FoliEditor = forwardRef<FoliEditorHandle, FoliEditorProps>(function
|
|
|
114
136
|
editor,
|
|
115
137
|
transactions,
|
|
116
138
|
get document() {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
139
|
+
const envelope = wordContext(state)?.envelope;
|
|
140
|
+
document ??= envelope
|
|
141
|
+
? documentJSON(envelope, state.doc)
|
|
142
|
+
: ({ content: state.doc.toJSON() } as FoliDocument);
|
|
121
143
|
return document;
|
|
122
144
|
},
|
|
123
145
|
});
|
|
@@ -133,11 +155,13 @@ export const FoliEditor = forwardRef<FoliEditorHandle, FoliEditorProps>(function
|
|
|
133
155
|
disabled={canvas.readOnly}
|
|
134
156
|
comments={comments !== false}
|
|
135
157
|
upload={canvas.upload}
|
|
158
|
+
items={toolbar === true ? undefined : toolbar}
|
|
136
159
|
onClickCommand={() => canvasRef.current?.focus()}
|
|
137
160
|
/>
|
|
138
161
|
)}
|
|
139
162
|
{children}
|
|
140
163
|
<div className="foli-editor-body">
|
|
164
|
+
<FoliNavigation editor={editor} readOnly={canvas.readOnly} />
|
|
141
165
|
<FoliCanvas ref={canvasRef} editor={editor} {...canvas} />
|
|
142
166
|
{/* "auto": mounted while hidden, so a comment made from the toolbar opens for writing. */}
|
|
143
167
|
{comments !== false && (
|