@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.
@@ -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,EAAE,WAAW,EAAE,KAAK,gBAAgB,EAAE,MAAM,kBAAkB,CAAC"}
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,EACL,kBAAkB,EAGlB,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,EAAE,WAAW,EAAyB,MAAM,kBAAkB,CAAC"}
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.6.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",
@@ -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) => {
@@ -1,12 +1,13 @@
1
- import {
2
- type Editor,
3
- type EditorDocument,
4
- type FoliDocument,
5
- type Plugin,
6
- type ReviewView,
7
- type Transaction,
8
- wordContext,
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
- /** Read once on mount. */
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
- /** Show the default `FoliToolbar` above the pages (default true). */
58
- toolbar?: boolean | undefined;
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({ initialContent, plugins, author, trackChanges, reviewView });
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
- document ??= {
119
- ...(structuredClone(wordContext(state)?.envelope) as Omit<FoliDocument, "content">),
120
- content: state.doc.toJSON(),
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
  )}
@@ -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,