@folijs/view 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 +44 -0
- package/LICENSE +21 -0
- package/README.md +33 -2
- package/dist/clipboard.d.ts +45 -0
- package/dist/clipboard.d.ts.map +1 -0
- package/dist/clipboard.js +668 -0
- package/dist/clipboard.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/layout/flow.d.ts +91 -0
- package/dist/layout/flow.d.ts.map +1 -0
- package/dist/layout/flow.js +200 -0
- package/dist/layout/flow.js.map +1 -0
- package/dist/render.d.ts +45 -0
- package/dist/render.d.ts.map +1 -0
- package/dist/render.js +166 -0
- package/dist/render.js.map +1 -0
- package/dist/view.d.ts +261 -0
- package/dist/view.d.ts.map +1 -0
- package/dist/view.js +1810 -0
- package/dist/view.js.map +1 -0
- package/package.json +31 -3
- package/src/clipboard.ts +708 -0
- package/src/index.ts +2 -0
- package/src/layout/flow.ts +281 -0
- package/src/render.ts +197 -0
- package/src/view.ts +1885 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# @folijs/view
|
|
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
|
+
- cb92eb4: HTML paste reads schema v2: lists at any depth (`ul`/`ol`/`li`, `start`, a list nested directly in a list), Word list paragraphs (`mso-list` levels, numbered or bulleted from their marker) and Google Docs lists, rules (`hr`), links from `a[href]` when the href is safe (in-page `#…` anchors dropped), text color and highlight from inline styles and `<font color>` (black or white text and white highlight are dropped), and block alignment (`text-align`, `align`). Lists and rules that cannot be pasted as a slice go in as whole blocks at the caret (a list pasted into a list item joins it). Copy writes the same structures, so Foli's HTML reads back as the same document.
|
|
14
|
+
- 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.
|
|
15
|
+
- 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`.
|
|
16
|
+
- 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.
|
|
17
|
+
- ef157b2: Document format v2 (`schemaVersion: 2`): bullet and ordered lists (`bulletList`, `orderedList` with `start`, `listItem`), `horizontalRule`, `align` on paragraphs and headings (`start`, `center`, `end`, `justify`; changing a block's type keeps it), and the marks `link` (`href` limited to relative URLs and http, https, mailto, tel: see `isSafeHref`), `textColor` and `highlight` (lowercase `#rrggbb`: see `isColor`). Documents saved by 0.1.0 (v1) load unchanged through a migration; 0.1.0 cannot read v2 documents. Attributes equal to their default are no longer written to JSON. `MARK_TYPES` now lists every mark (attribute-free ones are `SIMPLE_MARK_TYPES`). `setBlockType` no longer applies (or records undo) when nothing changes; `toggleMark` with invalid attributes (a link with an unsafe href) does not apply instead of throwing.
|
|
18
|
+
- 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.
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- Updated dependencies [069f986]
|
|
23
|
+
- Updated dependencies [c0290aa]
|
|
24
|
+
- Updated dependencies [ed66e43]
|
|
25
|
+
- Updated dependencies [ef157b2]
|
|
26
|
+
- Updated dependencies [f09aefe]
|
|
27
|
+
- @folijs/core@0.2.0
|
|
28
|
+
|
|
29
|
+
## 0.1.0
|
|
30
|
+
|
|
31
|
+
### Minor Changes
|
|
32
|
+
|
|
33
|
+
- First release: a document editor for the web with its own editing engine, on real pages.
|
|
34
|
+
- **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.
|
|
35
|
+
- **Engine** (`@folijs/core`): immutable state, steps and transactions, undo/redo history, commands, key bindings, a headless `createEditor`. No DOM.
|
|
36
|
+
- **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.
|
|
37
|
+
- **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).
|
|
38
|
+
|
|
39
|
+
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).
|
|
40
|
+
|
|
41
|
+
### Patch Changes
|
|
42
|
+
|
|
43
|
+
- Updated dependencies
|
|
44
|
+
- @folijs/core@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,34 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @folijs/view
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The editable view of [Foli](https://github.com/josep-audenis/foli), without a framework: renders
|
|
4
|
+
a `@folijs/core` editor into an element as real pages and turns keyboard, IME, clipboard and
|
|
5
|
+
mouse input into editor commands. For React, use [`@folijs/react`](https://www.npmjs.com/package/@folijs/react).
|
|
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/view @folijs/core
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { createDocument, createEditor } from "@folijs/core";
|
|
15
|
+
import { EditorView } from "@folijs/view";
|
|
16
|
+
|
|
17
|
+
const editor = createEditor({ document: createDocument() });
|
|
18
|
+
const host = document.getElementById("editor")!;
|
|
19
|
+
host.classList.add("foli-content"); // the default theme's selection color
|
|
20
|
+
host.setAttribute("aria-label", "Document");
|
|
21
|
+
const view = new EditorView(host, editor, { placeholder: "Start writing…" });
|
|
22
|
+
// later: view.destroy();
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
The view sets page size and margins from the document settings; the page look (background,
|
|
26
|
+
shadow, gap, fonts) comes from your CSS or a copy of
|
|
27
|
+
[`@folijs/react`'s `styles.css`](https://github.com/josep-audenis/foli/blob/main/packages/react/styles.css).
|
|
28
|
+
|
|
29
|
+
- [Getting started](https://github.com/josep-audenis/foli/blob/main/docs/getting-started.md#using-the-view-without-react)
|
|
30
|
+
- [API reference](https://github.com/josep-audenis/foli/blob/main/docs/api.md#foliview)
|
|
31
|
+
- [Styling](https://github.com/josep-audenis/foli/blob/main/docs/styling.md)
|
|
32
|
+
- [Known limitations](https://github.com/josep-audenis/foli/blob/main/docs/limitations.md)
|
|
33
|
+
|
|
34
|
+
MIT
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type DocJSON, type MarkJSON, type Node as ModelNode } from "@folijs/core";
|
|
2
|
+
/**
|
|
3
|
+
* Clipboard type for Foli content, read back first on paste: `{ open, content }`, the copied
|
|
4
|
+
* blocks as `DocJSON` and whether they were cut out of one block (see `Pasted.open`).
|
|
5
|
+
*/
|
|
6
|
+
export declare const FOLI_MIME = "application/x-foli+json";
|
|
7
|
+
/** Validated clipboard content. */
|
|
8
|
+
export interface Pasted {
|
|
9
|
+
doc: ModelNode;
|
|
10
|
+
/**
|
|
11
|
+
* True when no block boundary was copied (text from inside one block, plain text, inline
|
|
12
|
+
* HTML): the content always joins the block it is pasted into, which keeps its type. Closed
|
|
13
|
+
* content (whole blocks) replaces an empty block instead.
|
|
14
|
+
*/
|
|
15
|
+
open: boolean;
|
|
16
|
+
}
|
|
17
|
+
export interface ClipboardContent {
|
|
18
|
+
text: string;
|
|
19
|
+
html: string;
|
|
20
|
+
json: string;
|
|
21
|
+
}
|
|
22
|
+
/** Serializes `from..to` of `doc` for the clipboard. Hard breaks and block ends become "\n". */
|
|
23
|
+
export declare function serializeRange(doc: ModelNode, from: number, to: number, ownerDocument: Document): ClipboardContent;
|
|
24
|
+
/**
|
|
25
|
+
* The content of clipboard data, validated, or null. Priority: Foli JSON, then HTML, then plain
|
|
26
|
+
* text. Every format is validated by the schema (`parseContent`); a format that fails falls
|
|
27
|
+
* through to the next. `marks` are given to plain text (the marks typing would get at the
|
|
28
|
+
* insertion point).
|
|
29
|
+
*/
|
|
30
|
+
export declare function docFromClipboard(data: Pick<DataTransfer, "getData">, marks?: readonly MarkJSON[]): Pasted | null;
|
|
31
|
+
/** Plain text: one paragraph per line. */
|
|
32
|
+
export declare function textToDoc(text: string, marks?: readonly MarkJSON[]): DocJSON;
|
|
33
|
+
/**
|
|
34
|
+
* A CSS color as the schema stores it (lowercase `#rrggbb`), or null: transparent, unknown
|
|
35
|
+
* (system colors such as Word's `windowtext`) or empty. Hex (3 or 6 digits), `rgb()`/`rgba()`
|
|
36
|
+
* and the basic named colors.
|
|
37
|
+
*/
|
|
38
|
+
export declare function parseColor(value: string): string | null;
|
|
39
|
+
/**
|
|
40
|
+
* Own HTML reader: maps known tags and inline styles to the schema (paragraphs, headings,
|
|
41
|
+
* lists, rules; bold, italic, underline, strike, links, colors; alignment), drops everything
|
|
42
|
+
* else. The HTML is parsed into an inert document and never inserted.
|
|
43
|
+
*/
|
|
44
|
+
export declare function htmlToDoc(html: string): DocJSON | null;
|
|
45
|
+
//# sourceMappingURL=clipboard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clipboard.d.ts","sourceRoot":"","sources":["../src/clipboard.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,OAAO,EAIZ,KAAK,QAAQ,EACb,KAAK,IAAI,IAAI,SAAS,EAIvB,MAAM,cAAc,CAAC;AAGtB;;;GAGG;AACH,eAAO,MAAM,SAAS,4BAA4B,CAAC;AAEnD,mCAAmC;AACnC,MAAM,WAAW,MAAM;IACrB,GAAG,EAAE,SAAS,CAAC;IACf;;;;OAIG;IACH,IAAI,EAAE,OAAO,CAAC;CACf;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED,gGAAgG;AAChG,wBAAgB,cAAc,CAC5B,GAAG,EAAE,SAAS,EACd,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,EACV,aAAa,EAAE,QAAQ,GACtB,gBAAgB,CA8BlB;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,IAAI,CAAC,YAAY,EAAE,SAAS,CAAC,EACnC,KAAK,GAAE,SAAS,QAAQ,EAAO,GAC9B,MAAM,GAAG,IAAI,CAyBf;AAED,0CAA0C;AAC1C,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,GAAE,SAAS,QAAQ,EAAO,GAAG,OAAO,CAahF;AA0GD;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAiBvD;AAoJD;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,IAAI,CAEtD"}
|