@frontlit/text-editor 0.1.0-alpha.1
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/LICENSE +21 -0
- package/README.md +60 -0
- package/dist/index.d.ts +135 -0
- package/dist/index.js +1474 -0
- package/dist/index.js.map +1 -0
- package/dist/prose.css +403 -0
- package/dist/styles.css +1058 -0
- package/dist/tokens.css +58 -0
- package/package.json +91 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 FrontLit
|
|
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
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# @frontlit/text-editor
|
|
2
|
+
|
|
3
|
+
A TipTap-based rich text editor and static renderer for React. Framework-agnostic: it depends only on `react` / `react-dom`. No Next.js, no backend, and no media-upload service.
|
|
4
|
+
|
|
5
|
+
Uploaded images are embedded as data URLs by default. Hosts can replace that with their own picker via `ImagePickerContextProvider`.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm i @frontlit/text-editor
|
|
11
|
+
# or
|
|
12
|
+
pnpm add @frontlit/text-editor
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Peer dependencies: `react` and `react-dom` (^18 or ^19).
|
|
16
|
+
|
|
17
|
+
### CSS
|
|
18
|
+
|
|
19
|
+
Import the compiled stylesheet. It includes Tailwind utilities, fallback
|
|
20
|
+
tokens for the editor chrome, ProseMirror/renderer rules, and a small
|
|
21
|
+
highlight.js theme. Tailwind is **not** required in the host:
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import "@frontlit/text-editor/styles.css";
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
If you already run Tailwind CSS v4 and want to generate the utilities yourself,
|
|
28
|
+
skip `styles.css`, scan the package, and import the prose rules (lists,
|
|
29
|
+
blockquotes, code blocks — these are not utilities):
|
|
30
|
+
|
|
31
|
+
```css
|
|
32
|
+
@import "@frontlit/text-editor/tokens.css";
|
|
33
|
+
@import "@frontlit/text-editor/prose.css";
|
|
34
|
+
@source "./node_modules/@frontlit/text-editor";
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Usage
|
|
38
|
+
|
|
39
|
+
```tsx
|
|
40
|
+
import { Editor, TextRenderer, emptyDoc } from "@frontlit/text-editor";
|
|
41
|
+
import "@frontlit/text-editor/styles.css";
|
|
42
|
+
|
|
43
|
+
<Editor initialContent={emptyDoc} onChange={(json) => save(json)} />;
|
|
44
|
+
<TextRenderer json={savedJson} />;
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## What's inside
|
|
48
|
+
|
|
49
|
+
- `Editor` — the WYSIWYG editing surface (toolbar, bubble menu, tables, code blocks with syntax highlighting, images, links).
|
|
50
|
+
- `TextRenderer` — renders saved `TextEditorContent` (TipTap JSON) as static React elements. Accepts an optional, loosely-typed `theme` prop (see `TextRendererTheme`) to theme headings/paragraphs/links; without one it falls back to plain semantic HTML tags.
|
|
51
|
+
- `TextEditorContent` — the TipTap doc-JSON type both of the above operate on.
|
|
52
|
+
- `normalizeTextEditorContent`, `extractTextFromTextEditorContent`, `truncateTextEditorContent` — content utilities (e.g. for building excerpts).
|
|
53
|
+
- `emptyDoc`, `createExtensions`, `createId`, `extractHeadings`, `extractTextFromNode` — lower-level building blocks, exported for advanced use.
|
|
54
|
+
- `ImagePickerContextProvider` — optional hook so a host can supply its own image-upload UI.
|
|
55
|
+
|
|
56
|
+
`TextRenderer` is structurally typed against a small `TextRendererTheme` instead of importing `@frontlit/page-builder`, so this package stays usable on its own.
|
|
57
|
+
|
|
58
|
+
## License
|
|
59
|
+
|
|
60
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import React__default, { FC, PropsWithChildren, ReactNode } from 'react';
|
|
3
|
+
import { JSONContent, Extensions } from '@tiptap/core';
|
|
4
|
+
|
|
5
|
+
interface ReactEditorProps {
|
|
6
|
+
initialContent?: JSONContent | string | null;
|
|
7
|
+
editable?: boolean;
|
|
8
|
+
autoFocus?: boolean;
|
|
9
|
+
placeholder?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface EditorProps {
|
|
13
|
+
onChange: (json: JSONContent) => void;
|
|
14
|
+
showToolbar?: boolean;
|
|
15
|
+
editable?: boolean;
|
|
16
|
+
refresh?: number;
|
|
17
|
+
url?: string;
|
|
18
|
+
initialContent?: ReactEditorProps["initialContent"];
|
|
19
|
+
placeholder?: string;
|
|
20
|
+
autoFocus?: boolean;
|
|
21
|
+
imageSizeLimit?: number;
|
|
22
|
+
onError?: (...args: any[]) => void;
|
|
23
|
+
className?: string;
|
|
24
|
+
editorClassName?: string;
|
|
25
|
+
contentClassName?: string;
|
|
26
|
+
beforeContent?: React__default.ReactNode;
|
|
27
|
+
}
|
|
28
|
+
interface EditorType extends FC<PropsWithChildren<EditorProps>> {
|
|
29
|
+
getPlainText: (doc: JSONContent) => string;
|
|
30
|
+
emptyDoc: JSONContent;
|
|
31
|
+
}
|
|
32
|
+
declare const Editor: EditorType;
|
|
33
|
+
|
|
34
|
+
type PickedImage = {
|
|
35
|
+
src: string;
|
|
36
|
+
alt?: string;
|
|
37
|
+
};
|
|
38
|
+
declare function ImagePickerContextProvider({ pickImage, children, }: {
|
|
39
|
+
pickImage: () => Promise<PickedImage | null>;
|
|
40
|
+
children: ReactNode;
|
|
41
|
+
}): React.JSX.Element;
|
|
42
|
+
declare function useImagePicker(): () => Promise<PickedImage | null>;
|
|
43
|
+
|
|
44
|
+
declare const emptyDoc: JSONContent;
|
|
45
|
+
|
|
46
|
+
interface Heading {
|
|
47
|
+
level: number;
|
|
48
|
+
text: string;
|
|
49
|
+
id: string;
|
|
50
|
+
}
|
|
51
|
+
declare function extractHeadings(json: JSONContent | null | undefined): Heading[];
|
|
52
|
+
|
|
53
|
+
interface ExtensionOptions {
|
|
54
|
+
placeholder?: string;
|
|
55
|
+
}
|
|
56
|
+
declare const createExtensions: ({ placeholder, }?: ExtensionOptions) => Extensions;
|
|
57
|
+
|
|
58
|
+
declare function createId(textContent: string): string;
|
|
59
|
+
|
|
60
|
+
declare function extractTextFromNode(node: any): string;
|
|
61
|
+
|
|
62
|
+
interface TextEditorContent {
|
|
63
|
+
type: "doc";
|
|
64
|
+
content: Record<string, unknown>[];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* A loose, structural subset of a design system's theme — just enough for
|
|
69
|
+
* `TextRenderer` to apply theme-aware typography to rendered headings,
|
|
70
|
+
* paragraphs and links.
|
|
71
|
+
*
|
|
72
|
+
* This package intentionally has no dependency on `@frontlit/page-builder`
|
|
73
|
+
* (that would create a circular dependency, since page-builder depends on
|
|
74
|
+
* this package for editing/rendering). Any object shaped like this —
|
|
75
|
+
* including page-builder's full `ThemeStyle` — is structurally assignable
|
|
76
|
+
* here without either package needing to import the other's types.
|
|
77
|
+
*/
|
|
78
|
+
interface RendererTypography {
|
|
79
|
+
fontFamily?: string;
|
|
80
|
+
fontSize?: string;
|
|
81
|
+
fontWeight?: string;
|
|
82
|
+
lineHeight?: string;
|
|
83
|
+
letterSpacing?: string;
|
|
84
|
+
textTransform?: string;
|
|
85
|
+
textDecoration?: string;
|
|
86
|
+
textOverflow?: string;
|
|
87
|
+
}
|
|
88
|
+
interface RendererLinkInteractiveStyle {
|
|
89
|
+
padding?: {
|
|
90
|
+
x?: string;
|
|
91
|
+
y?: string;
|
|
92
|
+
};
|
|
93
|
+
border?: {
|
|
94
|
+
width?: string;
|
|
95
|
+
radius?: string;
|
|
96
|
+
style?: string;
|
|
97
|
+
};
|
|
98
|
+
textShadow?: string;
|
|
99
|
+
custom?: string;
|
|
100
|
+
}
|
|
101
|
+
interface TextRendererTheme {
|
|
102
|
+
typography?: {
|
|
103
|
+
header1?: RendererTypography;
|
|
104
|
+
header2?: RendererTypography;
|
|
105
|
+
header3?: RendererTypography;
|
|
106
|
+
text1?: RendererTypography;
|
|
107
|
+
link?: RendererTypography;
|
|
108
|
+
};
|
|
109
|
+
interactives?: {
|
|
110
|
+
link?: RendererLinkInteractiveStyle;
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
interface TextRendererProps {
|
|
115
|
+
json: TextEditorContent;
|
|
116
|
+
className?: string;
|
|
117
|
+
theme?: TextRendererTheme;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Renders TipTap `TextEditorContent` JSON as static React elements — used to
|
|
121
|
+
* display rich text saved by the `Editor` (e.g. inside a block's body). When
|
|
122
|
+
* a `theme` is provided, headings/paragraphs/links pick up its typography;
|
|
123
|
+
* otherwise plain semantic HTML tags are used.
|
|
124
|
+
*/
|
|
125
|
+
declare function TextRenderer({ json, className, theme }: TextRendererProps): React__default.JSX.Element;
|
|
126
|
+
|
|
127
|
+
/** Normalizes a plain string or an already-valid TipTap doc into `TextEditorContent`. */
|
|
128
|
+
declare function normalizeTextEditorContent(json: TextEditorContent | string): TextEditorContent;
|
|
129
|
+
|
|
130
|
+
/** Recursively concatenates all plain text out of a TipTap JSON content tree. */
|
|
131
|
+
declare function extractTextFromTextEditorContent(content: unknown): string;
|
|
132
|
+
|
|
133
|
+
declare function truncateTextEditorContent(json: TextEditorContent, characterLimit?: number): TextEditorContent;
|
|
134
|
+
|
|
135
|
+
export { Editor, type EditorProps, ImagePickerContextProvider, type PickedImage, type RendererLinkInteractiveStyle, type RendererTypography, type TextEditorContent, TextRenderer, type TextRendererTheme, createExtensions, createId, emptyDoc, extractHeadings, extractTextFromNode, extractTextFromTextEditorContent, normalizeTextEditorContent, truncateTextEditorContent, useImagePicker };
|