@pixerate/editor 0.14.2 → 0.14.3
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 +108 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# @pixerate/editor
|
|
2
|
+
|
|
3
|
+
UI-agnostic core of the Pixerate editor toolkit: a prompt-template grammar with recursive resolution and sourcemaps, plain-text and markdown serializers, headless [TipTap](https://tiptap.dev) extensions, and framework-free controllers for rich text, spreadsheets, images and node-graph canvases.
|
|
4
|
+
|
|
5
|
+
Framework bindings: [`@pixerate/editor-react`](https://www.npmjs.com/package/@pixerate/editor-react) · [`@pixerate/editor-svelte`](https://www.npmjs.com/package/@pixerate/editor-svelte)
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @pixerate/editor
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Prompt grammar
|
|
12
|
+
|
|
13
|
+
Prompts use three token types:
|
|
14
|
+
|
|
15
|
+
| Syntax | Token | Example |
|
|
16
|
+
| :--- | :--- | :--- |
|
|
17
|
+
| `{{name}}` | template, replaced by its body (recursively) | `{{golden_hour}}` |
|
|
18
|
+
| `{variable}` | variable, filled from a values map | `{subject}` |
|
|
19
|
+
| `__instruction__` | instruction, a styled directive for the model | `__award_winning__` |
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import {
|
|
23
|
+
tokenizePrompt,
|
|
24
|
+
resolveTemplates,
|
|
25
|
+
resolveVariables,
|
|
26
|
+
resolveTemplatesWithMapping,
|
|
27
|
+
mapResolvedOffsetToRaw,
|
|
28
|
+
TEMPLATE_LOOP_ERROR,
|
|
29
|
+
} from "@pixerate/editor/grammar";
|
|
30
|
+
|
|
31
|
+
const templates = [
|
|
32
|
+
{ name: "mood", body: "cinematic cyber-noir" },
|
|
33
|
+
{ name: "scene", body: "rainy street, {{mood}}" },
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
tokenizePrompt("Shot of {{scene}} with {subject}");
|
|
37
|
+
// [{ type: "text", … }, { type: "template", value: "scene", start: 8, end: 17, … }, …]
|
|
38
|
+
|
|
39
|
+
resolveTemplates("Shot of {{scene}}", templates);
|
|
40
|
+
// "Shot of rainy street, cinematic cyber-noir"
|
|
41
|
+
|
|
42
|
+
resolveVariables("Hello {user}", { user: "Ada" }); // "Hello Ada"
|
|
43
|
+
|
|
44
|
+
// Map offsets in the resolved text back to the source (for error highlighting, carets, …)
|
|
45
|
+
const { text, map } = resolveTemplatesWithMapping("Shot of {{scene}}", templates);
|
|
46
|
+
mapResolvedOffsetToRaw(text.length, map); // 17, the end of "{{scene}}"
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
- **Cycles and depth.** A tag that would recurse into itself is replaced with `TEMPLATE_LOOP_ERROR` (`"[Template loop detected]"`), and tags nested deeper than `maxDepth` (default `10`) with `TEMPLATE_DEPTH_ERROR`. The rest of the prompt still resolves, so check with `result.includes(TEMPLATE_LOOP_ERROR)`.
|
|
50
|
+
- **Versions.** Templates may carry `versions` and `latestVersion`. Pin specific versions with `resolveTemplates(text, templates, { bindings: { name: "v1" } })`.
|
|
51
|
+
|
|
52
|
+
## Serializers
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import {
|
|
56
|
+
plainTextToTipTapHtml,
|
|
57
|
+
htmlToPlainText,
|
|
58
|
+
getEditorText,
|
|
59
|
+
markdownToTipTapHtml,
|
|
60
|
+
getEditorMarkdown,
|
|
61
|
+
extractMentionsFromDoc,
|
|
62
|
+
} from "@pixerate/editor/serializers";
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
- `plainTextToTipTapHtml` / `htmlToPlainText` round-trip multi-line plain text through TipTap paragraphs without leaking HTML.
|
|
66
|
+
- `markdownToTipTapHtml` renders markdown for TipTap. Raw HTML embedded in the markdown is sanitized against an allowlist (event handlers, `style` and `javascript:` URLs are removed). Pass `{ allowUnsafeHtml: true }` only for fully trusted input.
|
|
67
|
+
|
|
68
|
+
## Editor controller and extensions
|
|
69
|
+
|
|
70
|
+
`createEditor` wraps a TipTap `Editor` with plain-text / markdown modes, token callbacks and dirty tracking. It works with any view layer, or with none.
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import { createEditor, createRichTextPreset, GradientText } from "@pixerate/editor";
|
|
74
|
+
|
|
75
|
+
const controller = createEditor({
|
|
76
|
+
element: document.querySelector("#editor"),
|
|
77
|
+
plainTextMode: true,
|
|
78
|
+
content: "A photo of {subject} in {{golden_hour}}",
|
|
79
|
+
extensions: [...createRichTextPreset(), GradientText],
|
|
80
|
+
onTokensChange: (tokens) => console.log(tokens),
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
controller.insertText("__award_winning__ "); // at the selection; literal text, never parsed as HTML
|
|
84
|
+
controller.isDirty(); // true
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Extensions (`@pixerate/editor/extensions`): `createRichTextPreset`, `GradientText`, `TemplateSuggestions`, `SlashCommands`, `LoadingNode`, `Mention` / `createMentionExtension`, `Image`, `Markdown`, `SmilieReplacer`, `ColorHighlighter`, `FontSize`.
|
|
88
|
+
|
|
89
|
+
## Other modules
|
|
90
|
+
|
|
91
|
+
Each module is also available as a subpath import:
|
|
92
|
+
|
|
93
|
+
| Import | Contents |
|
|
94
|
+
| :--- | :--- |
|
|
95
|
+
| `@pixerate/editor/grammar` | Tokenizer, resolver, sourcemaps. No TipTap or DOM dependencies, so it is safe for Node.js, workers and serverless functions. |
|
|
96
|
+
| `@pixerate/editor/serializers` | Plain text, markdown and mention serializers |
|
|
97
|
+
| `@pixerate/editor/extensions` | Headless TipTap extensions |
|
|
98
|
+
| `@pixerate/editor/history` | `HistoryManager`: a command-pattern undo/redo stack |
|
|
99
|
+
| `@pixerate/editor/spreadsheet` | `SpreadsheetController`, formula parser/evaluator and dependency graph |
|
|
100
|
+
| `@pixerate/editor/image-editor` | `ImageEditorController` and Canvas 2D renderer: crop, adjustments, annotations, depth masks and AI hooks. Needs a DOM/canvas environment. |
|
|
101
|
+
| `@pixerate/editor/canvas` | Node-graph layout (dagre), placement, trajectories, displacement, clipboard and streaming layout helpers |
|
|
102
|
+
| `@pixerate/editor/agent` | MCP tool schemas and a planner for agent-driven canvas edits |
|
|
103
|
+
|
|
104
|
+
The root entry (`@pixerate/editor`) re-exports everything, including TipTap. In backends, import from `@pixerate/editor/grammar` to keep the dependency graph small.
|
|
105
|
+
|
|
106
|
+
## License
|
|
107
|
+
|
|
108
|
+
MIT
|