@folijs/react 0.1.0 → 0.3.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 +56 -0
- package/README.md +3 -2
- package/dist/FoliEditor.d.ts +7 -4
- package/dist/FoliEditor.d.ts.map +1 -1
- package/dist/FoliEditor.js +5 -3
- package/dist/FoliEditor.js.map +1 -1
- package/dist/FoliToolbar.d.ts +4 -2
- package/dist/FoliToolbar.d.ts.map +1 -1
- package/dist/FoliToolbar.js +420 -52
- package/dist/FoliToolbar.js.map +1 -1
- package/dist/editor.d.ts +10 -5
- package/dist/editor.d.ts.map +1 -1
- package/dist/editor.js +3 -2
- package/dist/editor.js.map +1 -1
- package/package.json +3 -3
- package/src/FoliEditor.tsx +12 -7
- package/src/FoliToolbar.tsx +684 -81
- package/src/editor.tsx +10 -5
- package/styles.css +144 -7
package/dist/editor.js
CHANGED
|
@@ -7,8 +7,9 @@ import { createContext, useCallback, useContext, useEffect, useLayoutEffect, use
|
|
|
7
7
|
*/
|
|
8
8
|
export const useIsomorphicLayoutEffect = typeof document === "undefined" ? useEffect : useLayoutEffect;
|
|
9
9
|
/**
|
|
10
|
-
* A headless `Editor` (state, commands, history)
|
|
11
|
-
* first render and kept for its lifetime. Later changes to `options`
|
|
10
|
+
* A headless `Editor` (state, commands, history) of a schema v3 document, owned by the calling
|
|
11
|
+
* component: created on the first render and kept for its lifetime. Later changes to `options`
|
|
12
|
+
* are ignored. Throws FoliDocumentError when `initialContent` is not a valid document.
|
|
12
13
|
*/
|
|
13
14
|
export function useFoliEditor(options = {}) {
|
|
14
15
|
const [editor] = useState(() => {
|
package/dist/editor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editor.js","sourceRoot":"","sources":["../src/editor.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,YAAY,GAKb,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,aAAa,EAEb,WAAW,EACX,U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,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QACtC,MAAM,IAAI,GAAG,QAAQ,IAAI,OAAO,CAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;QACjF,IAAI,CAAC,OAAO,GAAG,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;QAChD,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;IACF,OAAO,oBAAoB,CAAC,SAAS,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC;AACnE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@folijs/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "React components for the Foli document editor.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"!src/**/*.test.*"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@folijs/
|
|
33
|
-
"@folijs/
|
|
32
|
+
"@folijs/view": "^0.3.0",
|
|
33
|
+
"@folijs/core": "^0.3.0"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"react": "^18.2.0 || ^19.0.0",
|
package/src/FoliEditor.tsx
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
|
-
createDocument,
|
|
3
|
-
type DocJSON,
|
|
4
2
|
type Editor,
|
|
3
|
+
type EditorDocument,
|
|
5
4
|
type FoliDocument,
|
|
6
5
|
type Plugin,
|
|
7
6
|
type Transaction,
|
|
7
|
+
wordContext,
|
|
8
8
|
} from "@folijs/core";
|
|
9
9
|
import { forwardRef, type ReactNode, useImperativeHandle, useRef } from "react";
|
|
10
10
|
import { FoliEditorProvider, useFoliEditor, useIsomorphicLayoutEffect } from "./editor.js";
|
|
@@ -21,14 +21,17 @@ export interface FoliChange {
|
|
|
21
21
|
readonly transactions: readonly Transaction[];
|
|
22
22
|
/**
|
|
23
23
|
* The whole document right after this change, serialized on first read (keep reads out of
|
|
24
|
-
* the hot path of typing: a debounced save reads only the last change's).
|
|
24
|
+
* the hot path of typing: a debounced save reads only the last change's). Schema v3.
|
|
25
25
|
*/
|
|
26
26
|
readonly document: FoliDocument;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
export interface FoliEditorProps extends Omit<FoliCanvasProps, "editor"> {
|
|
30
|
-
/**
|
|
31
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Read once on mount: a document of any version (0.1.0 and 0.2.0 documents are migrated to
|
|
32
|
+
* schema v3). To load another document later: `editor.setDocument()` or a new `key`.
|
|
33
|
+
*/
|
|
34
|
+
initialContent?: EditorDocument | undefined;
|
|
32
35
|
/** Read once on mount. */
|
|
33
36
|
plugins?: readonly Plugin[] | undefined;
|
|
34
37
|
/**
|
|
@@ -73,13 +76,15 @@ export const FoliEditor = forwardRef<FoliEditorHandle, FoliEditorProps>(function
|
|
|
73
76
|
const listener = onChangeRef.current;
|
|
74
77
|
if (!listener || !transactions.some((tr) => tr.docChanged)) return;
|
|
75
78
|
// The state is immutable: keeping it makes a later read give this change's document.
|
|
76
|
-
const { settings } = editor;
|
|
77
79
|
let document: FoliDocument | undefined;
|
|
78
80
|
listener({
|
|
79
81
|
editor,
|
|
80
82
|
transactions,
|
|
81
83
|
get document() {
|
|
82
|
-
document ??=
|
|
84
|
+
document ??= {
|
|
85
|
+
...(structuredClone(wordContext(state)?.envelope) as Omit<FoliDocument, "content">),
|
|
86
|
+
content: state.doc.toJSON(),
|
|
87
|
+
};
|
|
83
88
|
return document;
|
|
84
89
|
},
|
|
85
90
|
});
|