@folijs/react 0.0.0-stage → 0.2.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 +46 -0
- package/LICENSE +21 -0
- package/README.md +48 -2
- package/dist/FoliCanvas.d.ts +23 -0
- package/dist/FoliCanvas.d.ts.map +1 -0
- package/dist/FoliCanvas.js +32 -0
- package/dist/FoliCanvas.js.map +1 -0
- package/dist/FoliEditor.d.ts +44 -0
- package/dist/FoliEditor.d.ts.map +1 -0
- package/dist/FoliEditor.js +38 -0
- package/dist/FoliEditor.js.map +1 -0
- package/dist/FoliToolbar.d.ts +28 -0
- package/dist/FoliToolbar.d.ts.map +1 -0
- package/dist/FoliToolbar.js +466 -0
- package/dist/FoliToolbar.js.map +1 -0
- package/dist/editor.d.ts +40 -0
- package/dist/editor.d.ts.map +1 -0
- package/dist/editor.js +63 -0
- package/dist/editor.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/package.json +44 -3
- package/src/FoliCanvas.tsx +68 -0
- package/src/FoliEditor.tsx +103 -0
- package/src/FoliToolbar.tsx +756 -0
- package/src/editor.tsx +105 -0
- package/src/index.ts +16 -0
- package/styles.css +317 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# @folijs/react
|
|
2
|
+
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Rich content (schema v2): bulleted and numbered lists (nested, across pages), links, text color, highlight, alignment and horizontal rules, with toolbar controls and keyboard shortcuts; HTML paste from Word, Google Docs and web pages keeps them. Documents saved by 0.1.0 load unchanged; 0.1.0 cannot read documents saved by 0.2.0.
|
|
8
|
+
|
|
9
|
+
Known risks, besides those of 0.1.0 (manual IME, screen-reader and real-paste checks not run): Word and Google Docs lists are read from hand-written fixtures; long documents made of lists miss the editing-speed targets (Enter near the top, first layout, full re-flow). See [Known limitations](https://github.com/josep-audenis/foli/blob/main/docs/limitations.md).
|
|
10
|
+
|
|
11
|
+
Breaking (pre-1.0 minor): upgrade every app that reads your documents before saving with 0.2.0, since 0.1.0 cannot read version 2. `Transform.split(pos, after)` is now `split(pos, depth, typesAfter)` (`split(pos, 1, [after])`); `StepMap.side` is now `sides`; `MARK_TYPES` now lists every mark, `link`, `textColor` and `highlight` included (for attribute-free toggles use `SIMPLE_MARK_TYPES`); JSON no longer writes attributes equal to their default; `setBlockType` returns false when nothing changes, and `toggleMark` with invalid attributes returns false instead of throwing.
|
|
12
|
+
|
|
13
|
+
- 069f986: Alignment, colors and horizontal rules. Core: `setAlign`, `setTextColor`, `setHighlight` (null removes; at a caret, for the next typed text), `insertHorizontalRule`, `alignAt`, `colorAt`, `Transform.setBlockAttrs`, and `editor.commands` for each; typing over a selected rule replaces it with a paragraph, Enter adds one after it; arrow keys select a rule from the text beside it and leave it again (`arrowAcrossLeaf`). View: Up/Down onto a rule from a textblock's first or last line. React: toolbar alignment group, text color and highlight menu buttons (accessible menus, fixed palette), horizontal rule button; CSS variables `--foli-link-color`, `--foli-marker-color`, `--foli-rule-color`, `--foli-rule-thickness`; a rule is a taller box (easier to click) with its line in the middle.
|
|
14
|
+
- c0290aa: Links. Core: `setLink(href)`, `removeLink`, `insertLink(href, text?)`, `linkAt(state)`, `normalizeHref` (trim, `\` to `/`, spaces percent-encoded, `mailto:` for an email address and `https://` for a host name) and `autolinkHref`; the commands, the dialog and plain-text paste normalize the href, and every entry (including document load and paste) validates it, so unsafe protocols never apply; `editor.commands.setLink` and `removeLink`. Mod-K runs `openLinkEditor`, a request (`linkEditorRequest` transaction metadata, `requestsLinkEditor(tr)`) that a link UI answers. View: Ctrl+click (Cmd+click on Apple platforms) opens a link in a new tab with `noopener,noreferrer`; pasting plain text that is one URL makes a link (over selected text, links it), except paste as plain text; `view.paste(data, autolink?)`. React: a Link toolbar button (pressed in a link) and Mod-K open an accessible link dialog (URL field, Apply, Remove link, Cancel, Escape; an invalid URL is announced and not applied); new CSS variable `--foli-error-color`.
|
|
15
|
+
- ed66e43: List editing. Core: `toggleList`, `wrapInList`, `splitListItem`, `sinkListItem`, `liftListItem`, `liftListItemAtStart`, `listTypeAt` and `listKeymap()` (in every editor): Enter splits an item and leaves the list on an empty one, Tab and Shift+Tab nest and lift items (outside a list Tab is left to the browser), Backspace at an item's start lifts it, Ctrl/Cmd+Shift+7 and +8 toggle numbered and bulleted lists; `editor.commands.toggleList`, `wrapInList`, `indentListItem`, `outdentListItem`. Backspace after a list and Delete before one join into it; Delete at the end of a list item pulls in the next item's text (or what follows the list). Toggling a list off takes the selected items out of every list of that type they are in, leaving unselected items of outer lists; a numbered list split by lifting items goes on counting. Enter over a range across items deletes it, then splits. Each list change is its own undo step. View: Ctrl/Cmd+Shift+digit shortcuts work on every layout; `insertParagraph` and one-character delete inputs (keyboards without keydown) go through the same key bindings. React: toolbar buttons for bulleted and numbered lists (pressed inside one, disabled where no list can be made), decrease and increase indent.
|
|
16
|
+
- a034e62: The view renders document format v2: bulleted and numbered lists (nested, rebuilt on each page they are on, numbering continued across pages, no repeated marker on an item continued from the previous page), horizontal rules (a click selects one; shown with the class `foli-selected-node`, outlined by the default theme), links (`<a href>` that does not navigate on click), text color, highlight and alignment. Copy writes real nested lists.
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- Updated dependencies [cb92eb4]
|
|
21
|
+
- Updated dependencies [069f986]
|
|
22
|
+
- Updated dependencies [c0290aa]
|
|
23
|
+
- Updated dependencies [ed66e43]
|
|
24
|
+
- Updated dependencies [ef157b2]
|
|
25
|
+
- Updated dependencies [f09aefe]
|
|
26
|
+
- Updated dependencies [a034e62]
|
|
27
|
+
- @folijs/view@0.2.0
|
|
28
|
+
- @folijs/core@0.2.0
|
|
29
|
+
|
|
30
|
+
## 0.1.0
|
|
31
|
+
|
|
32
|
+
### Minor Changes
|
|
33
|
+
|
|
34
|
+
- First release: a document editor for the web with its own editing engine, on real pages.
|
|
35
|
+
- **Documents** (`@folijs/core`): a versioned JSON format (`schemaVersion: 1`) with page size and margins in millimetres; `parseDocument` validates untrusted input and never drops document content silently. Schema v1: paragraphs, headings 1–6, line breaks, page breaks; bold, italic, underline, strikethrough.
|
|
36
|
+
- **Engine** (`@folijs/core`): immutable state, steps and transactions, undo/redo history, commands, key bindings, a headless `createEditor`. No DOM.
|
|
37
|
+
- **View** (`@folijs/view`): `EditorView` renders the document on A4 or Letter pages in one `contenteditable` host. Paragraphs split across pages at a line, with widow/orphan and keep-with-next rules, explicit page breaks, incremental reflow, and print with one sheet per page (PDF output checked in Chromium). Typing, IME composition, copy, cut and paste (Foli JSON, HTML mapped to the schema, plain text), read-only mode, placeholder.
|
|
38
|
+
- **React** (`@folijs/react`, React 18.2+ and 19): `FoliEditor` with a formatting toolbar and `onChange`; `useFoliEditor`, `FoliEditorProvider`, `FoliCanvas`, `FoliToolbar`, `useCurrentEditor`, `useEditorState`. Server rendering gives the editor's shell; the document appears on hydration. Default theme in `@folijs/react/styles.css` (CSS variables).
|
|
39
|
+
|
|
40
|
+
Known risks: real IME and dead keys (Windows, macOS, Android, iOS input methods), NVDA and VoiceOver, macOS key bindings, spellcheck at a page break, and pastes from real Word, Google Docs and LibreOffice have not been checked by hand. Automated tests run in Chromium, Firefox and WebKit on Windows (IME only through Chromium's emulation, paste not in WebKit, no screen-reader tests); Safari on macOS and iOS is not tested. See [Known limitations](https://github.com/josep-audenis/foli/blob/main/docs/limitations.md).
|
|
41
|
+
|
|
42
|
+
### Patch Changes
|
|
43
|
+
|
|
44
|
+
- Updated dependencies
|
|
45
|
+
- @folijs/core@0.1.0
|
|
46
|
+
- @folijs/view@0.1.0
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Josep Audenis
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,49 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @folijs/react
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
React components for [Foli](https://github.com/josep-audenis/foli), a document editor for the
|
|
4
|
+
web: documents on real pages (A4, Letter), edited in the browser, stored as JSON. Its own
|
|
5
|
+
editing engine, no ProseMirror or similar underneath.
|
|
6
|
+
|
|
7
|
+
> Early release: the API may change in any 0.x minor version (changes in `CHANGELOG.md`).
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @folijs/react @folijs/core react react-dom
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Keep all `@folijs/*` packages on the same version.
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { createDocument, parseDocument } from "@folijs/core";
|
|
17
|
+
import { type FoliChange, FoliEditor } from "@folijs/react";
|
|
18
|
+
import "@folijs/react/styles.css";
|
|
19
|
+
|
|
20
|
+
// Load: parseDocument validates the saved JSON (throws FoliDocumentError when invalid).
|
|
21
|
+
const saved = localStorage.getItem("doc");
|
|
22
|
+
const initial = saved ? parseDocument(JSON.parse(saved)) : createDocument();
|
|
23
|
+
|
|
24
|
+
// Save once typing pauses: reading `change.document` serializes the whole document.
|
|
25
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
26
|
+
function onChange(change: FoliChange) {
|
|
27
|
+
clearTimeout(timer);
|
|
28
|
+
timer = setTimeout(() => localStorage.setItem("doc", JSON.stringify(change.document)), 300);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function App() {
|
|
32
|
+
return <FoliEditor initialContent={initial} onChange={onChange} />;
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Browser-only as written; for server rendering (Next.js) and saving on page close, see
|
|
37
|
+
[Getting started](https://github.com/josep-audenis/foli/blob/main/docs/getting-started.md).
|
|
38
|
+
|
|
39
|
+
`FoliEditor` shows the pages with a formatting toolbar. For your own layout: `useFoliEditor`,
|
|
40
|
+
`FoliEditorProvider`, `FoliCanvas`, `FoliToolbar`, `useCurrentEditor` and
|
|
41
|
+
`useEditorState(selector)`. React 18.2+ and 19; server rendering gives the editor's shell, the
|
|
42
|
+
document appears on hydration.
|
|
43
|
+
|
|
44
|
+
- [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
|
+
- [Styling](https://github.com/josep-audenis/foli/blob/main/docs/styling.md): CSS variables, dark theme, print
|
|
47
|
+
- [Known limitations](https://github.com/josep-audenis/foli/blob/main/docs/limitations.md)
|
|
48
|
+
|
|
49
|
+
MIT
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Editor } from "@folijs/core";
|
|
2
|
+
export interface FoliCanvasProps {
|
|
3
|
+
/** Default: the editor of the nearest `FoliEditorProvider`. */
|
|
4
|
+
editor?: Editor | undefined;
|
|
5
|
+
/** The user can read, select and copy, but not change the document. */
|
|
6
|
+
readOnly?: boolean | undefined;
|
|
7
|
+
/** Shown while the document is empty. */
|
|
8
|
+
placeholder?: string | undefined;
|
|
9
|
+
/** Accessible name of the editable area (default "Document"). */
|
|
10
|
+
label?: string | undefined;
|
|
11
|
+
className?: string | undefined;
|
|
12
|
+
}
|
|
13
|
+
/** What a `ref` on `FoliCanvas` gives. */
|
|
14
|
+
export interface FoliCanvasHandle {
|
|
15
|
+
/** Focuses the document and shows the editor's selection in it. */
|
|
16
|
+
focus(): void;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The editable document on real pages (size and margins from the document settings). The view
|
|
20
|
+
* owns the DOM inside it; React never renders children there.
|
|
21
|
+
*/
|
|
22
|
+
export declare const FoliCanvas: import("react").ForwardRefExoticComponent<FoliCanvasProps & import("react").RefAttributes<FoliCanvasHandle>>;
|
|
23
|
+
//# sourceMappingURL=FoliCanvas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FoliCanvas.d.ts","sourceRoot":"","sources":["../src/FoliCanvas.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAK3C,MAAM,WAAW,eAAe;IAC9B,+DAA+D;IAC/D,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,uEAAuE;IACvE,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC/B,yCAAyC;IACzC,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,iEAAiE;IACjE,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAChC;AAED,0CAA0C;AAC1C,MAAM,WAAW,gBAAgB;IAC/B,mEAAmE;IACnE,KAAK,IAAI,IAAI,CAAC;CACf;AAED;;;GAGG;AACH,eAAO,MAAM,UAAU,8GAwCrB,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { EditorView } from "@folijs/view";
|
|
3
|
+
import { forwardRef, useImperativeHandle, useRef } from "react";
|
|
4
|
+
import { useEditorOrContext, useIsomorphicLayoutEffect } from "./editor.js";
|
|
5
|
+
/**
|
|
6
|
+
* The editable document on real pages (size and margins from the document settings). The view
|
|
7
|
+
* owns the DOM inside it; React never renders children there.
|
|
8
|
+
*/
|
|
9
|
+
export const FoliCanvas = forwardRef(function FoliCanvas({ editor: given, readOnly = false, placeholder = "", label = "Document", className }, ref) {
|
|
10
|
+
const editor = useEditorOrContext(given, "FoliCanvas");
|
|
11
|
+
const contentRef = useRef(null);
|
|
12
|
+
const viewRef = useRef(null);
|
|
13
|
+
useImperativeHandle(ref, () => ({ focus: () => viewRef.current?.focus() }), []);
|
|
14
|
+
useIsomorphicLayoutEffect(() => {
|
|
15
|
+
const host = contentRef.current;
|
|
16
|
+
if (!host)
|
|
17
|
+
return;
|
|
18
|
+
const view = new EditorView(host, editor);
|
|
19
|
+
viewRef.current = view;
|
|
20
|
+
return () => {
|
|
21
|
+
view.destroy();
|
|
22
|
+
viewRef.current = null;
|
|
23
|
+
};
|
|
24
|
+
}, [editor]);
|
|
25
|
+
// Runs after the view is created (effects run in order): for a new view, and when the props change.
|
|
26
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: a new editor means a new view, which needs the options too.
|
|
27
|
+
useIsomorphicLayoutEffect(() => {
|
|
28
|
+
viewRef.current?.setOptions({ editable: !readOnly, placeholder });
|
|
29
|
+
}, [editor, readOnly, placeholder]);
|
|
30
|
+
return (_jsx("div", { className: className ? `foli-canvas ${className}` : "foli-canvas", children: _jsx("div", { ref: contentRef, className: "foli-content", role: "textbox", "aria-multiline": "true", "aria-label": label, tabIndex: 0 }) }));
|
|
31
|
+
});
|
|
32
|
+
//# sourceMappingURL=FoliCanvas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FoliCanvas.js","sourceRoot":"","sources":["../src/FoliCanvas.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAoB5E;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,UAAU,CAAoC,SAAS,UAAU,CACzF,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,GAAG,KAAK,EAAE,WAAW,GAAG,EAAE,EAAE,KAAK,GAAG,UAAU,EAAE,SAAS,EAAE,EACpF,GAAG;IAEH,MAAM,MAAM,GAAG,kBAAkB,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;IACvD,MAAM,UAAU,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAC;IAChD,MAAM,OAAO,GAAG,MAAM,CAAoB,IAAI,CAAC,CAAC;IAEhD,mBAAmB,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;IAEhF,yBAAyB,CAAC,GAAG,EAAE;QAC7B,MAAM,IAAI,GAAG,UAAU,CAAC,OAAO,CAAC;QAChC,IAAI,CAAC,IAAI;YAAE,OAAO;QAClB,MAAM,IAAI,GAAG,IAAI,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAC1C,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;QACvB,OAAO,GAAG,EAAE;YACV,IAAI,CAAC,OAAO,EAAE,CAAC;YACf,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;QACzB,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;IAEb,oGAAoG;IACpG,uHAAuH;IACvH,yBAAyB,CAAC,GAAG,EAAE;QAC7B,OAAO,CAAC,OAAO,EAAE,UAAU,CAAC,EAAE,QAAQ,EAAE,CAAC,QAAQ,EAAE,WAAW,EAAE,CAAC,CAAC;IACpE,CAAC,EAAE,CAAC,MAAM,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAC;IAEpC,OAAO,CACL,cAAK,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,eAAe,SAAS,EAAE,CAAC,CAAC,CAAC,aAAa,YAEpE,cACE,GAAG,EAAE,UAAU,EACf,SAAS,EAAC,cAAc,EACxB,IAAI,EAAC,SAAS,oBACC,MAAM,gBACT,KAAK,EACjB,QAAQ,EAAE,CAAC,GACX,GACE,CACP,CAAC;AACJ,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type Editor, type FoliDocument, type Plugin, type Transaction } from "@folijs/core";
|
|
2
|
+
import { type ReactNode } from "react";
|
|
3
|
+
import { type FoliCanvasHandle, type FoliCanvasProps } from "./FoliCanvas.js";
|
|
4
|
+
/**
|
|
5
|
+
* A change to the document's content, as `FoliEditor` reports it. `document` is a getter:
|
|
6
|
+
* spreading the object or `JSON.stringify(change)` serializes the document (and walks `editor`).
|
|
7
|
+
*/
|
|
8
|
+
export interface FoliChange {
|
|
9
|
+
readonly editor: Editor;
|
|
10
|
+
/** The transactions of this change (several when plugins append their own). */
|
|
11
|
+
readonly transactions: readonly Transaction[];
|
|
12
|
+
/**
|
|
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).
|
|
15
|
+
*/
|
|
16
|
+
readonly document: FoliDocument;
|
|
17
|
+
}
|
|
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;
|
|
21
|
+
/** Read once on mount. */
|
|
22
|
+
plugins?: readonly Plugin[] | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Called after every change to the document's content made through transactions (typing,
|
|
25
|
+
* commands, undo). Not for selection changes, and not for `editor.setDocument()`, whose
|
|
26
|
+
* caller already has the document.
|
|
27
|
+
*/
|
|
28
|
+
onChange?: ((change: FoliChange) => void) | undefined;
|
|
29
|
+
/** Show the default `FoliToolbar` above the pages (default true). */
|
|
30
|
+
toolbar?: boolean | undefined;
|
|
31
|
+
/** Rendered between the toolbar and the pages, inside the editor's context. */
|
|
32
|
+
children?: ReactNode | undefined;
|
|
33
|
+
}
|
|
34
|
+
/** What a `ref` on `FoliEditor` gives: its editor (commands, `setDocument`…) and focus. */
|
|
35
|
+
export interface FoliEditorHandle extends FoliCanvasHandle {
|
|
36
|
+
readonly editor: Editor;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* An editable document on real pages with a toolbar: creates its editor, provides it to
|
|
40
|
+
* `children` and shows it. Uncontrolled: the editor owns the document; React observes it
|
|
41
|
+
* through `onChange`, a parent reaches it through a `ref`.
|
|
42
|
+
*/
|
|
43
|
+
export declare const FoliEditor: import("react").ForwardRefExoticComponent<FoliEditorProps & import("react").RefAttributes<FoliEditorHandle>>;
|
|
44
|
+
//# sourceMappingURL=FoliEditor.d.ts.map
|
|
@@ -0,0 +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;IAC9C;;;OAGG;IACH,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC;CACjC;AAED,MAAM,WAAW,eAAgB,SAAQ,IAAI,CAAC,eAAe,EAAE,QAAQ,CAAC;IACtE,iGAAiG;IACjG,cAAc,CAAC,EAAE,YAAY,GAAG,SAAS,CAAC;IAC1C,0BAA0B;IAC1B,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,CAAC;IACxC;;;;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,+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,8GA+CrB,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { createDocument, } from "@folijs/core";
|
|
3
|
+
import { forwardRef, useImperativeHandle, useRef } from "react";
|
|
4
|
+
import { FoliEditorProvider, useFoliEditor, useIsomorphicLayoutEffect } from "./editor.js";
|
|
5
|
+
import { FoliCanvas } from "./FoliCanvas.js";
|
|
6
|
+
import { FoliToolbar } from "./FoliToolbar.js";
|
|
7
|
+
/**
|
|
8
|
+
* An editable document on real pages with a toolbar: creates its editor, provides it to
|
|
9
|
+
* `children` and shows it. Uncontrolled: the editor owns the document; React observes it
|
|
10
|
+
* through `onChange`, a parent reaches it through a `ref`.
|
|
11
|
+
*/
|
|
12
|
+
export const FoliEditor = forwardRef(function FoliEditor({ initialContent, plugins, onChange, toolbar = true, children, ...canvas }, ref) {
|
|
13
|
+
const editor = useFoliEditor({ initialContent, plugins });
|
|
14
|
+
const onChangeRef = useRef(onChange);
|
|
15
|
+
const canvasRef = useRef(null);
|
|
16
|
+
useImperativeHandle(ref, () => ({ editor, focus: () => canvasRef.current?.focus() }), [editor]);
|
|
17
|
+
useIsomorphicLayoutEffect(() => {
|
|
18
|
+
onChangeRef.current = onChange;
|
|
19
|
+
});
|
|
20
|
+
useIsomorphicLayoutEffect(() => editor.subscribe((state, transactions) => {
|
|
21
|
+
const listener = onChangeRef.current;
|
|
22
|
+
if (!listener || !transactions.some((tr) => tr.docChanged))
|
|
23
|
+
return;
|
|
24
|
+
// The state is immutable: keeping it makes a later read give this change's document.
|
|
25
|
+
const { settings } = editor;
|
|
26
|
+
let document;
|
|
27
|
+
listener({
|
|
28
|
+
editor,
|
|
29
|
+
transactions,
|
|
30
|
+
get document() {
|
|
31
|
+
document ??= createDocument(state.doc.toJSON(), settings);
|
|
32
|
+
return document;
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
}), [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 })] }));
|
|
37
|
+
});
|
|
38
|
+
//# sourceMappingURL=FoliEditor.js.map
|
|
@@ -0,0 +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,QAAQ,CAAC;IACjC,CAAC,CAAC,CAAC;IAEH,yBAAyB,CACvB,GAAG,EAAE,CACH,MAAM,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,YAAY,EAAE,EAAE;QACvC,MAAM,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAC;QACrC,IAAI,CAAC,QAAQ,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,UAAU,CAAC;YAAE,OAAO;QACnE,qFAAqF;QACrF,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAC;QAC5B,IAAI,QAAkC,CAAC;QACvC,QAAQ,CAAC;YACP,MAAM;YACN,YAAY;YACZ,IAAI,QAAQ;gBACV,QAAQ,KAAK,cAAc,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,EAAa,EAAE,QAAQ,CAAC,CAAC;gBACrE,OAAO,QAAQ,CAAC;YAClB,CAAC;SACF,CAAC,CAAC;IACL,CAAC,CAAC,EACJ,CAAC,MAAM,CAAC,CACT,CAAC;IAEF,OAAO,CACL,MAAC,kBAAkB,IAAC,MAAM,EAAE,MAAM,aAC/B,OAAO,IAAI,CACV,KAAC,WAAW,IACV,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,CAAC,QAAQ,EACzB,cAAc,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,OAAO,EAAE,KAAK,EAAE,GAChD,CACH,EACA,QAAQ,EACT,KAAC,UAAU,IAAC,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,KAAM,MAAM,GAAI,IACvC,CACtB,CAAC;AACJ,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type Editor } from "@folijs/core";
|
|
2
|
+
export interface FoliToolbarProps {
|
|
3
|
+
/** Default: the editor of the nearest `FoliEditorProvider`. */
|
|
4
|
+
editor?: Editor | undefined;
|
|
5
|
+
/**
|
|
6
|
+
* Every button is disabled. Pass it whenever the canvas is `readOnly`: commands run through
|
|
7
|
+
* the editor, which code may always change (`FoliEditor` does this for you).
|
|
8
|
+
*/
|
|
9
|
+
disabled?: boolean | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* Called after a click ran a command, to show its result in the document (`FoliEditor`
|
|
12
|
+
* focuses its canvas). Keyboard activation keeps the focus in the toolbar.
|
|
13
|
+
*/
|
|
14
|
+
onClickCommand?: (() => void) | undefined;
|
|
15
|
+
/** Accessible name of the toolbar (default "Formatting"). */
|
|
16
|
+
label?: string | undefined;
|
|
17
|
+
className?: string | undefined;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
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
|
|
24
|
+
* `aria-pressed`; a button whose command cannot run now is `aria-disabled` (still focusable).
|
|
25
|
+
* Clicks leave the focus and selection in the document.
|
|
26
|
+
*/
|
|
27
|
+
export declare function FoliToolbar({ editor: given, disabled, onClickCommand, label, className, }: FoliToolbarProps): import("react").JSX.Element;
|
|
28
|
+
//# sourceMappingURL=FoliToolbar.d.ts.map
|
|
@@ -0,0 +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,MAAM,IAAI,CAAC,GAAG,SAAS,CAAC;IAC1C,6DAA6D;IAC7D,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAChC;AA+TD;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,EAC1B,MAAM,EAAE,KAAK,EACb,QAAgB,EAChB,cAAc,EACd,KAAoB,EACpB,SAAS,GACV,EAAE,gBAAgB,+BAqLlB"}
|