@pixerate/editor-react 0.9.2 → 0.9.4
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/README.md +93 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# @pixerate/editor-react
|
|
2
|
+
|
|
3
|
+
React bindings for [`@pixerate/editor`](https://www.npmjs.com/package/@pixerate/editor): a prompt editor with live template highlighting and autocomplete, a rich-text editor, a read-only token renderer, plus spreadsheet, image editor and node-graph canvas components.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install @pixerate/editor-react @pixerate/editor react react-dom
|
|
7
|
+
# only if you use @pixerate/editor-react/canvas:
|
|
8
|
+
npm install @xyflow/react
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Requires React 18 or later.
|
|
12
|
+
|
|
13
|
+
## Prompt editor
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { useState } from "react";
|
|
17
|
+
import { usePromptEditor, EditorContent, TemplateRenderer } from "@pixerate/editor-react";
|
|
18
|
+
|
|
19
|
+
const templates = [{ name: "golden_hour", body: "warm 35mm volumetric lighting" }];
|
|
20
|
+
|
|
21
|
+
export function PromptStudio() {
|
|
22
|
+
const [prompt, setPrompt] = useState("A photo of {subject} in {{golden_hour}}");
|
|
23
|
+
|
|
24
|
+
const editor = usePromptEditor({
|
|
25
|
+
content: prompt,
|
|
26
|
+
onContentChange: setPrompt,
|
|
27
|
+
templates,
|
|
28
|
+
placeholder: "Write your prompt…",
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<>
|
|
33
|
+
<EditorContent editor={editor} />
|
|
34
|
+
{/* Lightweight read-only preview, no TipTap instance */}
|
|
35
|
+
<TemplateRenderer content={prompt} templates={templates} resolve />
|
|
36
|
+
</>
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
`usePromptEditor` keeps the editor in plain-text mode. It animates `{{template}}` tags, opens template autocomplete on `{{`, detects slash commands (`onSlashCommandMatch`) and normalizes pasted text to plain paragraphs. `content` sets the initial text.
|
|
42
|
+
|
|
43
|
+
## Rich text editor
|
|
44
|
+
|
|
45
|
+
```tsx
|
|
46
|
+
import { useEditor, EditorContent, BubbleMenu } from "@pixerate/editor-react";
|
|
47
|
+
|
|
48
|
+
export function Document() {
|
|
49
|
+
const editor = useEditor({ content: "<p>Hello</p>", richTextOptions: { markdown: true } });
|
|
50
|
+
return (
|
|
51
|
+
<>
|
|
52
|
+
<BubbleMenu editor={editor}>{/* your formatting buttons */}</BubbleMenu>
|
|
53
|
+
<EditorContent editor={editor} />
|
|
54
|
+
</>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
`useEditor` is TipTap's `useEditor` preloaded with `createRichTextPreset()`: headings, lists, task lists, links, text alignment, colors and highlights, and images. Mentions and markdown are opt-in via `richTextOptions: { mention: true, markdown: true }`.
|
|
60
|
+
|
|
61
|
+
## More exports
|
|
62
|
+
|
|
63
|
+
| Import | Exports |
|
|
64
|
+
| :--- | :--- |
|
|
65
|
+
| `@pixerate/editor-react` | `usePromptEditor`, `useEditor`, `EditorContent`, `BubbleMenu`, `TemplateRenderer`, `useHistory`, `useHistoryShortcuts`, `useNavigationGuard`, `useDismissGuard`, `EditorSlotsProvider` / `useEditorSlots`, `SpreadsheetEditor` / `useSpreadsheetEditor`, `DirtyTracker` |
|
|
66
|
+
| `@pixerate/editor-react/image-editor` | `ImageEditor`, `useImageEditor`: crop, rotate/flip, adjustments, annotations, depth masks, and `onInpaint` / `onRemoveBackground` AI hooks |
|
|
67
|
+
| `@pixerate/editor-react/canvas` | `useCanvasGraph`, `useCanvasLayout`, `useCanvasClipboard`, `useCanvasDocking`, `useCanvasShortcuts`, `useCanvasExplosion`, `useStreamingCanvas`, `AgentPresenceLayer`, plus the pure layout helpers from `@pixerate/editor/canvas` |
|
|
68
|
+
|
|
69
|
+
## Styling (Tailwind CSS required)
|
|
70
|
+
|
|
71
|
+
The components are styled with [Tailwind CSS](https://tailwindcss.com) utility classes and ship no stylesheet of their own. To style them:
|
|
72
|
+
|
|
73
|
+
1. **Let Tailwind scan the package**, or the classes will be purged.
|
|
74
|
+
|
|
75
|
+
Tailwind v4, in your CSS:
|
|
76
|
+
|
|
77
|
+
```css
|
|
78
|
+
@source "../node_modules/@pixerate/editor-react/dist";
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Tailwind v3, in `tailwind.config.js`:
|
|
82
|
+
|
|
83
|
+
```js
|
|
84
|
+
content: ["./src/**/*.{ts,tsx}", "./node_modules/@pixerate/editor-react/dist/**/*.{js,cjs}"],
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
2. **Define the theme colors.** `SpreadsheetEditor`, `BubbleMenu`, `TemplateRenderer` and the slot components use [shadcn/ui](https://ui.shadcn.com)-style tokens: `background`, `foreground`, `muted`, `muted-foreground`, `border`, `input`, `primary`, `popover`, `popover-foreground` and `destructive`. Projects already using shadcn/ui have these. Otherwise, define them as colors in your Tailwind theme.
|
|
88
|
+
|
|
89
|
+
`ImageEditor` uses a fixed dark (slate) palette and only needs step 1. Without Tailwind, the components work but render unstyled. Pass `className` to override.
|
|
90
|
+
|
|
91
|
+
## License
|
|
92
|
+
|
|
93
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pixerate/editor-react",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.4",
|
|
4
4
|
"description": "React bindings and prompt/rich-text components for @pixerate/editor",
|
|
5
5
|
"author": "Pixerate",
|
|
6
6
|
"license": "MIT",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"@tiptap/pm": "^2.11.5 || ^3.0.0",
|
|
51
51
|
"@tiptap/react": "^2.11.5 || ^3.0.0",
|
|
52
52
|
"@tiptap/starter-kit": "^2.11.5 || ^3.0.0",
|
|
53
|
-
"@pixerate/editor": "0.14.
|
|
53
|
+
"@pixerate/editor": "0.14.3"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
56
|
"@xyflow/react": "^12.0.0",
|