@folijs/react 0.6.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 +144 -0
- package/README.md +11 -7
- 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 +15 -8
- package/dist/FoliEditor.js.map +1 -1
- package/dist/FoliNavigation.d.ts.map +1 -1
- package/dist/FoliNavigation.js +2 -1
- package/dist/FoliNavigation.js.map +1 -1
- package/dist/FoliToolbar.d.ts +81 -6
- package/dist/FoliToolbar.d.ts.map +1 -1
- package/dist/FoliToolbar.js +100 -66
- package/dist/FoliToolbar.js.map +1 -1
- package/dist/editor.d.ts +38 -12
- package/dist/editor.d.ts.map +1 -1
- package/dist/editor.js +57 -3
- package/dist/editor.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
- package/src/FoliComments.tsx +3 -1
- package/src/FoliEditor.tsx +39 -17
- package/src/FoliNavigation.tsx +1 -2
- package/src/FoliToolbar.tsx +248 -91
- package/src/editor.tsx +127 -4
- package/src/index.ts +14 -1
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EACzB,gBAAgB,EAChB,cAAc,EACd,aAAa,GACd,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,UAAU,EAAE,KAAK,gBAAgB,EAAE,KAAK,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAC1F,OAAO,EAAE,YAAY,EAAE,KAAK,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,EACL,KAAK,UAAU,EACf,UAAU,EACV,KAAK,gBAAgB,EACrB,KAAK,eAAe,GACrB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,cAAc,EAAE,KAAK,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC/E,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,YAAY,EACjB,kBAAkB,EAClB,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EACzB,UAAU,EACV,gBAAgB,EAChB,cAAc,EACd,aAAa,GACd,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,UAAU,EAAE,KAAK,gBAAgB,EAAE,KAAK,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAC1F,OAAO,EAAE,YAAY,EAAE,KAAK,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,EACL,KAAK,UAAU,EACf,UAAU,EACV,KAAK,gBAAgB,EACrB,KAAK,eAAe,GACrB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,cAAc,EAAE,KAAK,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC/E,OAAO,EACL,mBAAmB,EACnB,WAAW,EACX,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,YAAY,GACb,MAAM,kBAAkB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { FoliEditorProvider, useCurrentEditor, useEditorState, useFoliEditor, } from "./editor.js";
|
|
1
|
+
export { FoliEditorProvider, useCommand, useCurrentEditor, useEditorState, useFoliEditor, } from "./editor.js";
|
|
2
2
|
export { FoliCanvas } from "./FoliCanvas.js";
|
|
3
3
|
export { FoliComments } from "./FoliComments.js";
|
|
4
4
|
export { FoliEditor, } from "./FoliEditor.js";
|
|
5
5
|
export { FoliNavigation } from "./FoliNavigation.js";
|
|
6
|
-
export { FoliToolbar } from "./FoliToolbar.js";
|
|
6
|
+
export { defaultToolbarItems, FoliToolbar, toolbarItems, } from "./FoliToolbar.js";
|
|
7
7
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,kBAAkB,EAIlB,UAAU,EACV,gBAAgB,EAChB,cAAc,EACd,aAAa,GACd,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,UAAU,EAA+C,MAAM,iBAAiB,CAAC;AAC1F,OAAO,EAAE,YAAY,EAA0B,MAAM,mBAAmB,CAAC;AACzE,OAAO,EAEL,UAAU,GAGX,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,cAAc,EAA4B,MAAM,qBAAqB,CAAC;AAC/E,OAAO,EACL,mBAAmB,EACnB,WAAW,EAOX,YAAY,GACb,MAAM,kBAAkB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@folijs/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "React components for the Foli document editor.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -28,17 +28,17 @@
|
|
|
28
28
|
"styles.css",
|
|
29
29
|
"!src/**/*.test.*"
|
|
30
30
|
],
|
|
31
|
-
"dependencies": {
|
|
32
|
-
"@folijs/core": "^0.6.0",
|
|
33
|
-
"@folijs/view": "^0.6.0"
|
|
34
|
-
},
|
|
35
31
|
"peerDependencies": {
|
|
36
32
|
"react": "^18.2.0 || ^19.0.0",
|
|
37
|
-
"react-dom": "^18.2.0 || ^19.0.0"
|
|
33
|
+
"react-dom": "^18.2.0 || ^19.0.0",
|
|
34
|
+
"@folijs/core": "1.0.0",
|
|
35
|
+
"@folijs/view": "1.0.0"
|
|
38
36
|
},
|
|
39
37
|
"devDependencies": {
|
|
40
38
|
"react": "^19.3.1",
|
|
41
|
-
"react-dom": "^19.3.1"
|
|
39
|
+
"react-dom": "^19.3.1",
|
|
40
|
+
"@folijs/core": "1.0.0",
|
|
41
|
+
"@folijs/view": "1.0.0"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
44
|
"build": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.build.json",
|
package/src/FoliComments.tsx
CHANGED
|
@@ -8,8 +8,8 @@ import {
|
|
|
8
8
|
type NodeJSON,
|
|
9
9
|
replyToComment,
|
|
10
10
|
resolveComment,
|
|
11
|
-
wordContext,
|
|
12
11
|
} from "@folijs/core";
|
|
12
|
+
import { wordContext } from "@folijs/core/internal";
|
|
13
13
|
import { type FormEvent, type KeyboardEvent, useEffect, useId, useRef, useState } from "react";
|
|
14
14
|
import { useEditorOrContext, useEditorState, useIsomorphicLayoutEffect } from "./editor.js";
|
|
15
15
|
|
|
@@ -39,6 +39,8 @@ const EMPTY: readonly CommentJSON[] = [];
|
|
|
39
39
|
|
|
40
40
|
/** The comments of the editor's document, as threads in document order. */
|
|
41
41
|
function threadsOf(state: EditorState, comments: readonly CommentJSON[]): Thread[] {
|
|
42
|
+
// No document scan per change when there is nothing to anchor (12.11).
|
|
43
|
+
if (!comments.length) return [];
|
|
42
44
|
const anchors = commentAnchors(state.doc);
|
|
43
45
|
const byId = new Map(comments.map((c) => [c.id, c]));
|
|
44
46
|
const rootOf = (c: CommentJSON) => {
|
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,
|
|
@@ -17,7 +18,7 @@ import {
|
|
|
17
18
|
import { FoliCanvas, type FoliCanvasHandle, type FoliCanvasProps } from "./FoliCanvas.js";
|
|
18
19
|
import { FoliComments } from "./FoliComments.js";
|
|
19
20
|
import { FoliNavigation } from "./FoliNavigation.js";
|
|
20
|
-
import { FoliToolbar } from "./FoliToolbar.js";
|
|
21
|
+
import { FoliToolbar, type ToolbarItem } from "./FoliToolbar.js";
|
|
21
22
|
|
|
22
23
|
/**
|
|
23
24
|
* A change to the document's content, as `FoliEditor` reports it. `document` is a getter:
|
|
@@ -40,8 +41,17 @@ export interface FoliEditorProps extends Omit<FoliCanvasProps, "editor"> {
|
|
|
40
41
|
* schema v3). To load another document later: `editor.setDocument()` or a new `key`.
|
|
41
42
|
*/
|
|
42
43
|
initialContent?: EditorDocument | undefined;
|
|
43
|
-
/**
|
|
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
|
+
*/
|
|
44
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;
|
|
45
55
|
/** Read once on mount: who edits (tracked changes are made in this name). */
|
|
46
56
|
author?: string | undefined;
|
|
47
57
|
/** Read once on mount: record edits as tracked changes (the toolbar turns it on and off). */
|
|
@@ -54,8 +64,11 @@ export interface FoliEditorProps extends Omit<FoliCanvasProps, "editor"> {
|
|
|
54
64
|
* caller already has the document.
|
|
55
65
|
*/
|
|
56
66
|
onChange?: ((change: FoliChange) => void) | undefined;
|
|
57
|
-
/**
|
|
58
|
-
|
|
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;
|
|
59
72
|
/**
|
|
60
73
|
* Show the comments pane (`FoliComments`) beside the pages: `"auto"` (the default) while the
|
|
61
74
|
* document has comments, `true` always, `false` never.
|
|
@@ -79,6 +92,7 @@ export const FoliEditor = forwardRef<FoliEditorHandle, FoliEditorProps>(function
|
|
|
79
92
|
{
|
|
80
93
|
initialContent,
|
|
81
94
|
plugins,
|
|
95
|
+
extensions,
|
|
82
96
|
author,
|
|
83
97
|
trackChanges,
|
|
84
98
|
reviewView,
|
|
@@ -90,7 +104,14 @@ export const FoliEditor = forwardRef<FoliEditorHandle, FoliEditorProps>(function
|
|
|
90
104
|
},
|
|
91
105
|
ref,
|
|
92
106
|
) {
|
|
93
|
-
const editor = useFoliEditor({
|
|
107
|
+
const editor = useFoliEditor({
|
|
108
|
+
initialContent,
|
|
109
|
+
plugins,
|
|
110
|
+
extensions,
|
|
111
|
+
author,
|
|
112
|
+
trackChanges,
|
|
113
|
+
reviewView,
|
|
114
|
+
});
|
|
94
115
|
const hasComments = useEditorState(
|
|
95
116
|
(state) => (wordContext(state)?.envelope.comments.length ?? 0) > 0,
|
|
96
117
|
{ editor },
|
|
@@ -115,10 +136,10 @@ export const FoliEditor = forwardRef<FoliEditorHandle, FoliEditorProps>(function
|
|
|
115
136
|
editor,
|
|
116
137
|
transactions,
|
|
117
138
|
get document() {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
139
|
+
const envelope = wordContext(state)?.envelope;
|
|
140
|
+
document ??= envelope
|
|
141
|
+
? documentJSON(envelope, state.doc)
|
|
142
|
+
: ({ content: state.doc.toJSON() } as FoliDocument);
|
|
122
143
|
return document;
|
|
123
144
|
},
|
|
124
145
|
});
|
|
@@ -134,6 +155,7 @@ export const FoliEditor = forwardRef<FoliEditorHandle, FoliEditorProps>(function
|
|
|
134
155
|
disabled={canvas.readOnly}
|
|
135
156
|
comments={comments !== false}
|
|
136
157
|
upload={canvas.upload}
|
|
158
|
+
items={toolbar === true ? undefined : toolbar}
|
|
137
159
|
onClickCommand={() => canvasRef.current?.focus()}
|
|
138
160
|
/>
|
|
139
161
|
)}
|
package/src/FoliNavigation.tsx
CHANGED
|
@@ -18,11 +18,10 @@ import {
|
|
|
18
18
|
renameBookmark,
|
|
19
19
|
replace,
|
|
20
20
|
replaceAll,
|
|
21
|
-
StoryStep,
|
|
22
21
|
type Transaction,
|
|
23
22
|
trackState,
|
|
24
|
-
wordContext,
|
|
25
23
|
} from "@folijs/core";
|
|
24
|
+
import { StoryStep, wordContext } from "@folijs/core/internal";
|
|
26
25
|
import { keyName } from "@folijs/view";
|
|
27
26
|
import {
|
|
28
27
|
type FormEvent,
|