@pixerate/editor-react 0.1.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/LICENSE +21 -0
- package/dist/index.cjs +323 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +90 -0
- package/dist/index.d.ts +90 -0
- package/dist/index.js +293 -0
- package/dist/index.js.map +1 -0
- package/package.json +48 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jack James
|
|
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/dist/index.cjs
ADDED
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
BubbleMenu: () => BubbleMenu,
|
|
34
|
+
EditorContent: () => EditorContent,
|
|
35
|
+
TemplateRenderer: () => TemplateRenderer,
|
|
36
|
+
useEditor: () => useEditor2,
|
|
37
|
+
usePromptEditor: () => usePromptEditor
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(index_exports);
|
|
40
|
+
|
|
41
|
+
// src/hooks/usePromptEditor.ts
|
|
42
|
+
var import_react = require("react");
|
|
43
|
+
var import_react2 = require("@tiptap/react");
|
|
44
|
+
var import_starter_kit = __toESM(require("@tiptap/starter-kit"), 1);
|
|
45
|
+
var import_extension_placeholder = __toESM(require("@tiptap/extension-placeholder"), 1);
|
|
46
|
+
var import_model = require("@tiptap/pm/model");
|
|
47
|
+
var import_editor = require("@pixerate/editor");
|
|
48
|
+
var DEFAULT_TEMPLATES = [];
|
|
49
|
+
var DEFAULT_COLOR_MAP = /* @__PURE__ */ new Map([
|
|
50
|
+
["default", { from: "#f43f5e", to: "#8b5cf6" }]
|
|
51
|
+
]);
|
|
52
|
+
function usePromptEditor({
|
|
53
|
+
content,
|
|
54
|
+
onContentChange,
|
|
55
|
+
templates = DEFAULT_TEMPLATES,
|
|
56
|
+
templateColorMap: userColorMap,
|
|
57
|
+
isEditing = true,
|
|
58
|
+
placeholder = "Write a prompt, use {{template}}, {variable}, or /command...",
|
|
59
|
+
className,
|
|
60
|
+
onEscape,
|
|
61
|
+
onKeyDown,
|
|
62
|
+
onSelectionChange,
|
|
63
|
+
onSlashCommandMatch,
|
|
64
|
+
clearSlashCommand,
|
|
65
|
+
slashCommandActive = false,
|
|
66
|
+
onMilestone,
|
|
67
|
+
containerId = "editor-container",
|
|
68
|
+
jsonVariables,
|
|
69
|
+
speed = 2
|
|
70
|
+
}) {
|
|
71
|
+
const slashCommandActiveRef = (0, import_react.useRef)(slashCommandActive);
|
|
72
|
+
slashCommandActiveRef.current = slashCommandActive;
|
|
73
|
+
const clearSlashCommandRef = (0, import_react.useRef)(clearSlashCommand);
|
|
74
|
+
clearSlashCommandRef.current = clearSlashCommand;
|
|
75
|
+
const onEscapeRef = (0, import_react.useRef)(onEscape);
|
|
76
|
+
onEscapeRef.current = onEscape;
|
|
77
|
+
const onKeyDownRef = (0, import_react.useRef)(onKeyDown);
|
|
78
|
+
onKeyDownRef.current = onKeyDown;
|
|
79
|
+
const onSelectionChangeRef = (0, import_react.useRef)(onSelectionChange);
|
|
80
|
+
onSelectionChangeRef.current = onSelectionChange;
|
|
81
|
+
const onSlashCommandMatchRef = (0, import_react.useRef)(onSlashCommandMatch);
|
|
82
|
+
onSlashCommandMatchRef.current = onSlashCommandMatch;
|
|
83
|
+
const onContentChangeRef = (0, import_react.useRef)(onContentChange);
|
|
84
|
+
onContentChangeRef.current = onContentChange;
|
|
85
|
+
const onMilestoneRef = (0, import_react.useRef)(onMilestone);
|
|
86
|
+
onMilestoneRef.current = onMilestone;
|
|
87
|
+
const containerIdRef = (0, import_react.useRef)(containerId);
|
|
88
|
+
containerIdRef.current = containerId;
|
|
89
|
+
const resolvedColorMap = (0, import_react.useMemo)(() => {
|
|
90
|
+
if (userColorMap) return userColorMap;
|
|
91
|
+
const map = /* @__PURE__ */ new Map();
|
|
92
|
+
templates.forEach((t) => {
|
|
93
|
+
map.set(t.name, { from: "#f43f5e", to: "#8b5cf6" });
|
|
94
|
+
});
|
|
95
|
+
return map.size > 0 ? map : DEFAULT_COLOR_MAP;
|
|
96
|
+
}, [userColorMap, templates]);
|
|
97
|
+
const editor = (0, import_react2.useEditor)(
|
|
98
|
+
{
|
|
99
|
+
immediatelyRender: false,
|
|
100
|
+
enablePasteRules: false,
|
|
101
|
+
enableInputRules: false,
|
|
102
|
+
editable: isEditing,
|
|
103
|
+
extensions: [
|
|
104
|
+
import_starter_kit.default.configure({
|
|
105
|
+
heading: false,
|
|
106
|
+
codeBlock: false
|
|
107
|
+
}),
|
|
108
|
+
import_extension_placeholder.default.configure({ placeholder }),
|
|
109
|
+
import_editor.GradientText.configure({
|
|
110
|
+
templateColorMap: resolvedColorMap,
|
|
111
|
+
speed,
|
|
112
|
+
jsonVariables
|
|
113
|
+
}),
|
|
114
|
+
import_editor.TemplateSuggestions.configure({
|
|
115
|
+
templates
|
|
116
|
+
}),
|
|
117
|
+
import_editor.LoadingNode
|
|
118
|
+
],
|
|
119
|
+
content: (0, import_editor.plainTextToTipTapHtml)(content),
|
|
120
|
+
onUpdate: ({ editor: ed }) => {
|
|
121
|
+
const plainText = (0, import_editor.getEditorText)(ed);
|
|
122
|
+
onContentChangeRef.current?.(plainText);
|
|
123
|
+
if (onMilestoneRef.current) {
|
|
124
|
+
if (plainText.match(/(?<!\{)\{([^{}]+)\}(?!\})/g)) {
|
|
125
|
+
onMilestoneRef.current("used_variable");
|
|
126
|
+
}
|
|
127
|
+
if (plainText.match(/__([^_]+)__/g)) {
|
|
128
|
+
onMilestoneRef.current("used_magic");
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const { state, view } = ed;
|
|
132
|
+
const { selection } = state;
|
|
133
|
+
const { $from, from, to } = selection;
|
|
134
|
+
onSelectionChangeRef.current?.({ from, to });
|
|
135
|
+
if (onSlashCommandMatchRef.current && clearSlashCommandRef.current) {
|
|
136
|
+
const textBeforeCursor = $from?.parent?.textBetween ? $from.parent.textBetween(0, $from.parentOffset) : "";
|
|
137
|
+
const slashMatch = textBeforeCursor.match(
|
|
138
|
+
/(?:^|\s)\/([a-zA-Z0-9_-]*)$/
|
|
139
|
+
);
|
|
140
|
+
if (slashMatch) {
|
|
141
|
+
const coords = view.coordsAtPos($from.pos);
|
|
142
|
+
const containerEl = document.getElementById(containerIdRef.current) || document.getElementById("editor-container") || view.dom.closest?.(".relative");
|
|
143
|
+
const containerCoords = containerEl?.getBoundingClientRect();
|
|
144
|
+
if (containerCoords) {
|
|
145
|
+
onSlashCommandMatchRef.current(
|
|
146
|
+
slashMatch,
|
|
147
|
+
$from.pos - slashMatch[0].length + (slashMatch[0].startsWith(" ") ? 1 : 0),
|
|
148
|
+
$from.pos,
|
|
149
|
+
{
|
|
150
|
+
top: coords.bottom - containerCoords.top + 5,
|
|
151
|
+
left: coords.left - containerCoords.left
|
|
152
|
+
}
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
} else {
|
|
156
|
+
clearSlashCommandRef.current();
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
onSelectionUpdate: ({ editor: ed }) => {
|
|
161
|
+
const { from, to } = ed.state.selection;
|
|
162
|
+
onSelectionChangeRef.current?.({ from, to });
|
|
163
|
+
},
|
|
164
|
+
editorProps: {
|
|
165
|
+
attributes: {
|
|
166
|
+
class: className || "w-full border border-input rounded-md p-3 font-mono text-sm leading-relaxed focus:outline-none focus:ring-2 focus:ring-primary whitespace-pre-wrap break-words"
|
|
167
|
+
},
|
|
168
|
+
handleKeyDown: (view, event) => {
|
|
169
|
+
if (event.key === "Escape" && onEscapeRef.current) {
|
|
170
|
+
onEscapeRef.current();
|
|
171
|
+
return true;
|
|
172
|
+
}
|
|
173
|
+
if (onKeyDownRef.current) {
|
|
174
|
+
return onKeyDownRef.current(event);
|
|
175
|
+
}
|
|
176
|
+
return false;
|
|
177
|
+
},
|
|
178
|
+
clipboardTextParser: (text, context, _plain, view) => {
|
|
179
|
+
const schema = context?.doc?.type?.schema || context?.schema || view?.state?.schema;
|
|
180
|
+
if (!schema) return import_model.Slice.empty;
|
|
181
|
+
const blocks = text.replace(/\r\n?/g, "\n").split("\n");
|
|
182
|
+
const nodes = [];
|
|
183
|
+
blocks.forEach((line) => {
|
|
184
|
+
const nodeJson = { type: "paragraph" };
|
|
185
|
+
if (line.length > 0) {
|
|
186
|
+
nodeJson.content = [{ type: "text", text: line }];
|
|
187
|
+
}
|
|
188
|
+
try {
|
|
189
|
+
const node = import_model.Node.fromJSON(schema, nodeJson);
|
|
190
|
+
nodes.push(node);
|
|
191
|
+
} catch {
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
return import_model.Slice.maxOpen(import_model.Fragment.fromArray(nodes));
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
[templates, resolvedColorMap, isEditing, placeholder, speed]
|
|
199
|
+
);
|
|
200
|
+
return editor;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// src/hooks/useEditor.ts
|
|
204
|
+
var import_react3 = require("@tiptap/react");
|
|
205
|
+
var import_editor2 = require("@pixerate/editor");
|
|
206
|
+
function useEditor2(options = {}) {
|
|
207
|
+
const { richTextOptions, extensions = [], ...editorOptions } = options;
|
|
208
|
+
const preset = (0, import_editor2.createRichTextPreset)(richTextOptions);
|
|
209
|
+
const combinedExtensions = [...preset, ...extensions];
|
|
210
|
+
return (0, import_react3.useEditor)({
|
|
211
|
+
extensions: combinedExtensions,
|
|
212
|
+
...editorOptions
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// src/components/EditorContent.tsx
|
|
217
|
+
var import_react4 = require("@tiptap/react");
|
|
218
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
219
|
+
var EditorContent = ({
|
|
220
|
+
className,
|
|
221
|
+
editor,
|
|
222
|
+
...props
|
|
223
|
+
}) => {
|
|
224
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react4.EditorContent, { editor, ...props }) });
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
// src/components/BubbleMenu.tsx
|
|
228
|
+
var import_react5 = require("@tiptap/react");
|
|
229
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
230
|
+
var BubbleMenu = ({
|
|
231
|
+
editor,
|
|
232
|
+
className = "flex items-center gap-1 bg-popover text-popover-foreground border shadow-md rounded-md p-1",
|
|
233
|
+
children
|
|
234
|
+
}) => {
|
|
235
|
+
if (!editor) return null;
|
|
236
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
237
|
+
import_react5.BubbleMenu,
|
|
238
|
+
{
|
|
239
|
+
editor,
|
|
240
|
+
tippyOptions: { duration: 100 },
|
|
241
|
+
className,
|
|
242
|
+
children
|
|
243
|
+
}
|
|
244
|
+
);
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
// src/components/TemplateRenderer.tsx
|
|
248
|
+
var import_react6 = require("react");
|
|
249
|
+
var import_editor3 = require("@pixerate/editor");
|
|
250
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
251
|
+
var TemplateRenderer = ({
|
|
252
|
+
content,
|
|
253
|
+
templates = [],
|
|
254
|
+
templateColorMap,
|
|
255
|
+
resolve = false,
|
|
256
|
+
className = "font-mono text-sm leading-relaxed whitespace-pre-wrap break-words",
|
|
257
|
+
onTemplateClick,
|
|
258
|
+
onVariableClick
|
|
259
|
+
}) => {
|
|
260
|
+
const displayText = (0, import_react6.useMemo)(() => {
|
|
261
|
+
if (!resolve || templates.length === 0) return content;
|
|
262
|
+
return (0, import_editor3.resolveTemplates)(content, templates);
|
|
263
|
+
}, [content, templates, resolve]);
|
|
264
|
+
const tokens = (0, import_react6.useMemo)(() => {
|
|
265
|
+
return (0, import_editor3.tokenizePrompt)(displayText);
|
|
266
|
+
}, [displayText]);
|
|
267
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className, children: tokens.map((token, index) => {
|
|
268
|
+
if (token.type === "template") {
|
|
269
|
+
const colors = templateColorMap?.get(token.value) || {
|
|
270
|
+
from: "#f43f5e",
|
|
271
|
+
to: "#8b5cf6"
|
|
272
|
+
};
|
|
273
|
+
const style = {
|
|
274
|
+
"--color-from": colors.from,
|
|
275
|
+
"--color-to": colors.to
|
|
276
|
+
};
|
|
277
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
278
|
+
"span",
|
|
279
|
+
{
|
|
280
|
+
style,
|
|
281
|
+
onClick: () => onTemplateClick?.(token.value),
|
|
282
|
+
className: "inline-flex items-center px-1.5 py-0.5 mx-0.5 text-xs font-semibold rounded-md border border-[var(--color-to)]/40 bg-gradient-to-r from-[var(--color-from)]/15 to-[var(--color-to)]/15 text-[var(--color-to)] hover:brightness-110 cursor-pointer transition-all",
|
|
283
|
+
title: `Template: ${token.value}`,
|
|
284
|
+
children: `{{${token.value}}}`
|
|
285
|
+
},
|
|
286
|
+
index
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
if (token.type === "variable") {
|
|
290
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
291
|
+
"span",
|
|
292
|
+
{
|
|
293
|
+
onClick: () => onVariableClick?.(token.value),
|
|
294
|
+
className: "inline-flex items-center px-1.5 py-0.5 mx-0.5 text-xs font-medium rounded-md border border-violet-400/40 bg-violet-400/15 text-violet-600 dark:text-violet-300 hover:brightness-110 cursor-pointer transition-all",
|
|
295
|
+
title: `Variable: ${token.value}`,
|
|
296
|
+
children: `{${token.value}}`
|
|
297
|
+
},
|
|
298
|
+
index
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
if (token.type === "instruction") {
|
|
302
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
303
|
+
"span",
|
|
304
|
+
{
|
|
305
|
+
className: "inline-flex items-center px-1.5 py-0.5 mx-0.5 text-xs italic font-medium rounded-md border border-rose-400/40 bg-rose-400/15 text-rose-600 dark:text-rose-300",
|
|
306
|
+
title: `Instruction: ${token.value}`,
|
|
307
|
+
children: `__${token.value}__`
|
|
308
|
+
},
|
|
309
|
+
index
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: token.value }, index);
|
|
313
|
+
}) });
|
|
314
|
+
};
|
|
315
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
316
|
+
0 && (module.exports = {
|
|
317
|
+
BubbleMenu,
|
|
318
|
+
EditorContent,
|
|
319
|
+
TemplateRenderer,
|
|
320
|
+
useEditor,
|
|
321
|
+
usePromptEditor
|
|
322
|
+
});
|
|
323
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/hooks/usePromptEditor.ts","../src/hooks/useEditor.ts","../src/components/EditorContent.tsx","../src/components/BubbleMenu.tsx","../src/components/TemplateRenderer.tsx"],"sourcesContent":["export * from \"./hooks/usePromptEditor\";\nexport * from \"./hooks/useEditor\";\nexport * from \"./components/EditorContent\";\nexport * from \"./components/BubbleMenu\";\nexport * from \"./components/TemplateRenderer\";\n\n// Re-export core types for easy consumer access\nexport type {\n Template,\n TemplateVersion,\n Token,\n TokenType,\n ColorGradient,\n RichTextPresetOptions,\n} from \"@pixerate/editor\";\n","import { useMemo, useEffect, useRef } from \"react\";\nimport { useEditor } from \"@tiptap/react\";\nimport StarterKit from \"@tiptap/starter-kit\";\nimport Placeholder from \"@tiptap/extension-placeholder\";\nimport { Slice, Fragment, Node as ProsemirrorNode } from \"@tiptap/pm/model\";\nimport {\n Template,\n ColorGradient,\n GradientText,\n TemplateSuggestions,\n LoadingNode,\n plainTextToTipTapHtml,\n getEditorText,\n} from \"@pixerate/editor\";\n\nexport interface UsePromptEditorProps {\n /** The initial or controlled content of the editor as plain text */\n content: string;\n /** Callback fired when the editor content changes (returns plain text) */\n onContentChange: (text: string) => void;\n /** List of available templates to be suggested and highlighted */\n templates?: Template[];\n /** Custom gradient color map for templates */\n templateColorMap?: Map<string, ColorGradient>;\n /** Whether the editor is editable */\n isEditing?: boolean;\n /** Placeholder text for the editor */\n placeholder?: string;\n /** Additional CSS classes for the editor container */\n className?: string;\n /** Callback fired when the Escape key is pressed */\n onEscape?: () => void;\n /** Custom keydown handler. Return true to prevent default behavior */\n onKeyDown?: (event: KeyboardEvent) => boolean;\n /** Callback fired when text selection changes */\n onSelectionChange?: (selection: { from: number; to: number } | null) => void;\n /** Callback fired when a slash command (e.g., /template) matches */\n onSlashCommandMatch?: (\n match: RegExpMatchArray,\n from: number,\n to: number,\n coords: { top: number; left: number },\n ) => void;\n /** Callback to dismiss/clear the active slash command */\n clearSlashCommand?: () => void;\n /** Whether a slash command menu is currently active */\n slashCommandActive?: boolean;\n /** Callback fired when certain milestones are reached (e.g., used_variable, used_magic) */\n onMilestone?: (milestone: string) => void;\n /** DOM element ID of the container, used for positioning popovers */\n containerId?: string;\n /** Variable names originating from structured JSON output steps */\n jsonVariables?: string[];\n /** Animation speed for gradient decorations */\n speed?: number;\n}\n\nconst DEFAULT_TEMPLATES: Template[] = [];\nconst DEFAULT_COLOR_MAP = new Map<string, ColorGradient>([\n [\"default\", { from: \"#f43f5e\", to: \"#8b5cf6\" }],\n]);\n\nexport function usePromptEditor({\n content,\n onContentChange,\n templates = DEFAULT_TEMPLATES,\n templateColorMap: userColorMap,\n isEditing = true,\n placeholder = \"Write a prompt, use {{template}}, {variable}, or /command...\",\n className,\n onEscape,\n onKeyDown,\n onSelectionChange,\n onSlashCommandMatch,\n clearSlashCommand,\n slashCommandActive = false,\n onMilestone,\n containerId = \"editor-container\",\n jsonVariables,\n speed = 2,\n}: UsePromptEditorProps) {\n const slashCommandActiveRef = useRef(slashCommandActive);\n slashCommandActiveRef.current = slashCommandActive;\n\n const clearSlashCommandRef = useRef(clearSlashCommand);\n clearSlashCommandRef.current = clearSlashCommand;\n\n const onEscapeRef = useRef(onEscape);\n onEscapeRef.current = onEscape;\n\n const onKeyDownRef = useRef(onKeyDown);\n onKeyDownRef.current = onKeyDown;\n\n const onSelectionChangeRef = useRef(onSelectionChange);\n onSelectionChangeRef.current = onSelectionChange;\n\n const onSlashCommandMatchRef = useRef(onSlashCommandMatch);\n onSlashCommandMatchRef.current = onSlashCommandMatch;\n\n const onContentChangeRef = useRef(onContentChange);\n onContentChangeRef.current = onContentChange;\n\n const onMilestoneRef = useRef(onMilestone);\n onMilestoneRef.current = onMilestone;\n\n const containerIdRef = useRef(containerId);\n containerIdRef.current = containerId;\n\n const resolvedColorMap = useMemo(() => {\n if (userColorMap) return userColorMap;\n const map = new Map<string, ColorGradient>();\n templates.forEach((t) => {\n map.set(t.name, { from: \"#f43f5e\", to: \"#8b5cf6\" });\n });\n return map.size > 0 ? map : DEFAULT_COLOR_MAP;\n }, [userColorMap, templates]);\n\n const editor = useEditor(\n {\n immediatelyRender: false,\n enablePasteRules: false,\n enableInputRules: false,\n editable: isEditing,\n extensions: [\n StarterKit.configure({\n heading: false,\n codeBlock: false,\n }),\n Placeholder.configure({ placeholder }),\n GradientText.configure({\n templateColorMap: resolvedColorMap,\n speed,\n jsonVariables,\n }),\n TemplateSuggestions.configure({\n templates,\n }),\n LoadingNode,\n ],\n content: plainTextToTipTapHtml(content),\n onUpdate: ({ editor: ed }) => {\n const plainText = getEditorText(ed);\n onContentChangeRef.current?.(plainText);\n\n if (onMilestoneRef.current) {\n if (plainText.match(/(?<!\\{)\\{([^{}]+)\\}(?!\\})/g)) {\n onMilestoneRef.current(\"used_variable\");\n }\n if (plainText.match(/__([^_]+)__/g)) {\n onMilestoneRef.current(\"used_magic\");\n }\n }\n\n const { state, view } = ed;\n const { selection } = state;\n const { $from, from, to } = selection;\n\n onSelectionChangeRef.current?.({ from, to });\n\n if (onSlashCommandMatchRef.current && clearSlashCommandRef.current) {\n const textBeforeCursor = $from?.parent?.textBetween\n ? $from.parent.textBetween(0, $from.parentOffset)\n : \"\";\n const slashMatch = textBeforeCursor.match(\n /(?:^|\\s)\\/([a-zA-Z0-9_-]*)$/,\n );\n\n if (slashMatch) {\n const coords = view.coordsAtPos($from.pos);\n const containerEl =\n document.getElementById(containerIdRef.current) ||\n document.getElementById(\"editor-container\") ||\n (view.dom.closest?.(\".relative\") as HTMLElement | null);\n const containerCoords = containerEl?.getBoundingClientRect();\n\n if (containerCoords) {\n onSlashCommandMatchRef.current(\n slashMatch,\n $from.pos -\n slashMatch[0].length +\n (slashMatch[0].startsWith(\" \") ? 1 : 0),\n $from.pos,\n {\n top: coords.bottom - containerCoords.top + 5,\n left: coords.left - containerCoords.left,\n },\n );\n }\n } else {\n clearSlashCommandRef.current();\n }\n }\n },\n onSelectionUpdate: ({ editor: ed }) => {\n const { from, to } = ed.state.selection;\n onSelectionChangeRef.current?.({ from, to });\n },\n editorProps: {\n attributes: {\n class:\n className ||\n \"w-full border border-input rounded-md p-3 font-mono text-sm leading-relaxed focus:outline-none focus:ring-2 focus:ring-primary whitespace-pre-wrap break-words\",\n },\n handleKeyDown: (view, event) => {\n if (event.key === \"Escape\" && onEscapeRef.current) {\n onEscapeRef.current();\n return true;\n }\n if (onKeyDownRef.current) {\n return onKeyDownRef.current(event);\n }\n return false;\n },\n clipboardTextParser: (text, context, _plain, view) => {\n const schema =\n (context as any)?.doc?.type?.schema ||\n (context as any)?.schema ||\n view?.state?.schema;\n\n if (!schema) return Slice.empty;\n\n const blocks = text.replace(/\\r\\n?/g, \"\\n\").split(\"\\n\");\n const nodes: ProsemirrorNode[] = [];\n\n blocks.forEach((line) => {\n const nodeJson: any = { type: \"paragraph\" };\n if (line.length > 0) {\n nodeJson.content = [{ type: \"text\", text: line }];\n }\n try {\n const node = ProsemirrorNode.fromJSON(schema, nodeJson);\n nodes.push(node);\n } catch {\n // Ignore\n }\n });\n\n return Slice.maxOpen(Fragment.fromArray(nodes));\n },\n },\n },\n [templates, resolvedColorMap, isEditing, placeholder, speed],\n );\n\n return editor;\n}\n","import { useEditor as useTipTapEditor, UseEditorOptions } from \"@tiptap/react\";\nimport { createRichTextPreset, RichTextPresetOptions } from \"@pixerate/editor\";\n\nexport interface UseRichEditorProps extends UseEditorOptions {\n richTextOptions?: RichTextPresetOptions;\n}\n\n/**\n * Hook to initialize a TipTap rich-text editor instance with pre-configured extensions.\n */\nexport function useEditor(options: UseRichEditorProps = {}) {\n const { richTextOptions, extensions = [], ...editorOptions } = options;\n\n const preset = createRichTextPreset(richTextOptions);\n const combinedExtensions = [...preset, ...extensions];\n\n return useTipTapEditor({\n extensions: combinedExtensions,\n ...editorOptions,\n });\n}\n","import React from \"react\";\nimport {\n EditorContent as TipTapEditorContent,\n EditorContentProps as TipTapEditorContentProps,\n} from \"@tiptap/react\";\n\nexport interface EditorContentProps extends TipTapEditorContentProps {\n className?: string;\n}\n\nexport const EditorContent: React.FC<EditorContentProps> = ({\n className,\n editor,\n ...props\n}) => {\n return (\n <div className={className}>\n <TipTapEditorContent editor={editor} {...props} />\n </div>\n );\n};\n","import React from \"react\";\nimport { BubbleMenu as TipTapBubbleMenu } from \"@tiptap/react\";\nimport type { Editor } from \"@tiptap/core\";\n\nexport interface BubbleMenuProps {\n editor: Editor | null;\n className?: string;\n children: React.ReactNode;\n}\n\nexport const BubbleMenu: React.FC<BubbleMenuProps> = ({\n editor,\n className = \"flex items-center gap-1 bg-popover text-popover-foreground border shadow-md rounded-md p-1\",\n children,\n}) => {\n if (!editor) return null;\n\n return (\n <TipTapBubbleMenu\n editor={editor}\n tippyOptions={{ duration: 100 }}\n className={className}\n >\n {children}\n </TipTapBubbleMenu>\n );\n};\n","import React, { useMemo } from \"react\";\nimport {\n tokenizePrompt,\n resolveTemplates,\n Template,\n ColorGradient,\n} from \"@pixerate/editor\";\n\nexport interface TemplateRendererProps {\n /** Raw prompt or text string to render */\n content: string;\n /** Available templates for recursive resolution and custom coloring */\n templates?: Template[];\n /** Custom gradient color map for templates */\n templateColorMap?: Map<string, ColorGradient>;\n /** Whether to resolve nested templates recursively before displaying */\n resolve?: boolean;\n /** Custom class name for the wrapper */\n className?: string;\n /** Click callback for template badges */\n onTemplateClick?: (templateName: string) => void;\n /** Click callback for variable badges */\n onVariableClick?: (variableName: string) => void;\n}\n\nexport const TemplateRenderer: React.FC<TemplateRendererProps> = ({\n content,\n templates = [],\n templateColorMap,\n resolve = false,\n className = \"font-mono text-sm leading-relaxed whitespace-pre-wrap break-words\",\n onTemplateClick,\n onVariableClick,\n}) => {\n const displayText = useMemo(() => {\n if (!resolve || templates.length === 0) return content;\n return resolveTemplates(content, templates);\n }, [content, templates, resolve]);\n\n const tokens = useMemo(() => {\n return tokenizePrompt(displayText);\n }, [displayText]);\n\n return (\n <div className={className}>\n {tokens.map((token, index) => {\n if (token.type === \"template\") {\n const colors = templateColorMap?.get(token.value) || {\n from: \"#f43f5e\",\n to: \"#8b5cf6\",\n };\n const style = {\n \"--color-from\": colors.from,\n \"--color-to\": colors.to,\n } as React.CSSProperties;\n\n return (\n <span\n key={index}\n style={style}\n onClick={() => onTemplateClick?.(token.value)}\n className=\"inline-flex items-center px-1.5 py-0.5 mx-0.5 text-xs font-semibold rounded-md border border-[var(--color-to)]/40 bg-gradient-to-r from-[var(--color-from)]/15 to-[var(--color-to)]/15 text-[var(--color-to)] hover:brightness-110 cursor-pointer transition-all\"\n title={`Template: ${token.value}`}\n >\n {`{{${token.value}}}`}\n </span>\n );\n }\n\n if (token.type === \"variable\") {\n return (\n <span\n key={index}\n onClick={() => onVariableClick?.(token.value)}\n className=\"inline-flex items-center px-1.5 py-0.5 mx-0.5 text-xs font-medium rounded-md border border-violet-400/40 bg-violet-400/15 text-violet-600 dark:text-violet-300 hover:brightness-110 cursor-pointer transition-all\"\n title={`Variable: ${token.value}`}\n >\n {`{${token.value}}`}\n </span>\n );\n }\n\n if (token.type === \"instruction\") {\n return (\n <span\n key={index}\n className=\"inline-flex items-center px-1.5 py-0.5 mx-0.5 text-xs italic font-medium rounded-md border border-rose-400/40 bg-rose-400/15 text-rose-600 dark:text-rose-300\"\n title={`Instruction: ${token.value}`}\n >\n {`__${token.value}__`}\n </span>\n );\n }\n\n return <span key={index}>{token.value}</span>;\n })}\n </div>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAAA;AAAA,EAAA;AAAA;AAAA;;;ACAA,mBAA2C;AAC3C,IAAAC,gBAA0B;AAC1B,yBAAuB;AACvB,mCAAwB;AACxB,mBAAyD;AACzD,oBAQO;AA4CP,IAAM,oBAAgC,CAAC;AACvC,IAAM,oBAAoB,oBAAI,IAA2B;AAAA,EACvD,CAAC,WAAW,EAAE,MAAM,WAAW,IAAI,UAAU,CAAC;AAChD,CAAC;AAEM,SAAS,gBAAgB;AAAA,EAC9B;AAAA,EACA;AAAA,EACA,YAAY;AAAA,EACZ,kBAAkB;AAAA,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AG,CAAC,SAAS,WAAW,OAAO,CAAC;AAEhC,QAAM,aAAS,uBAAQ,MAAM;AAC3B,eAAO,+BAAe,WAAW;AAAA,EACnC,GAAG,CAAC,WAAW,CAAC;AAEhB,SACE,6CAAC,SAAI,WACF,iBAAO,IAAI,CAAC,OAAO,UAAU;AAC5B,QAAI,MAAM,SAAS,YAAY;AAC7B,YAAM,SAAS,kBAAkB,IAAI,MAAM,KAAK,KAAK;AAAA,QACnD,MAAM;AAAA,QACN,IAAI;AAAA,MACN;AACA,YAAM,QAAQ;AAAA,QACZ,gBAAgB,OAAO;AAAA,QACvB,cAAc,OAAO;AAAA,MACvB;AAEA,aACE;AAAA,QAAC;AAAA;AAAA,UAEC;AAAA,UACA,SAAS,MAAM,kBAAkB,MAAM,KAAK;AAAA,UAC5C,WAAU;AAAA,UACV,OAAO,aAAa,MAAM,KAAK;AAAA,UAE9B,eAAK,MAAM,KAAK;AAAA;AAAA,QANZ;AAAA,MAOP;AAAA,IAEJ;AAEA,QAAI,MAAM,SAAS,YAAY;AAC7B,aACE;AAAA,QAAC;AAAA;AAAA,UAEC,SAAS,MAAM,kBAAkB,MAAM,KAAK;AAAA,UAC5C,WAAU;AAAA,UACV,OAAO,aAAa,MAAM,KAAK;AAAA,UAE9B,cAAI,MAAM,KAAK;AAAA;AAAA,QALX;AAAA,MAMP;AAAA,IAEJ;AAEA,QAAI,MAAM,SAAS,eAAe;AAChC,aACE;AAAA,QAAC;AAAA;AAAA,UAEC,WAAU;AAAA,UACV,OAAO,gBAAgB,MAAM,KAAK;AAAA,UAEjC,eAAK,MAAM,KAAK;AAAA;AAAA,QAJZ;AAAA,MAKP;AAAA,IAEJ;AAEA,WAAO,6CAAC,UAAkB,gBAAM,SAAd,KAAoB;AAAA,EACxC,CAAC,GACH;AAEJ;","names":["useEditor","import_react","StarterKit","Placeholder","ProsemirrorNode","import_react","import_editor","useEditor","useTipTapEditor","import_react","TipTapEditorContent","import_react","import_jsx_runtime","TipTapBubbleMenu","import_react","import_editor","import_jsx_runtime"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import * as _tiptap_core from '@tiptap/core';
|
|
2
|
+
import { Editor } from '@tiptap/core';
|
|
3
|
+
import { Template, ColorGradient, RichTextPresetOptions } from '@pixerate/editor';
|
|
4
|
+
export { ColorGradient, RichTextPresetOptions, Template, TemplateVersion, Token, TokenType } from '@pixerate/editor';
|
|
5
|
+
import { UseEditorOptions, EditorContentProps as EditorContentProps$1 } from '@tiptap/react';
|
|
6
|
+
import React from 'react';
|
|
7
|
+
|
|
8
|
+
interface UsePromptEditorProps {
|
|
9
|
+
/** The initial or controlled content of the editor as plain text */
|
|
10
|
+
content: string;
|
|
11
|
+
/** Callback fired when the editor content changes (returns plain text) */
|
|
12
|
+
onContentChange: (text: string) => void;
|
|
13
|
+
/** List of available templates to be suggested and highlighted */
|
|
14
|
+
templates?: Template[];
|
|
15
|
+
/** Custom gradient color map for templates */
|
|
16
|
+
templateColorMap?: Map<string, ColorGradient>;
|
|
17
|
+
/** Whether the editor is editable */
|
|
18
|
+
isEditing?: boolean;
|
|
19
|
+
/** Placeholder text for the editor */
|
|
20
|
+
placeholder?: string;
|
|
21
|
+
/** Additional CSS classes for the editor container */
|
|
22
|
+
className?: string;
|
|
23
|
+
/** Callback fired when the Escape key is pressed */
|
|
24
|
+
onEscape?: () => void;
|
|
25
|
+
/** Custom keydown handler. Return true to prevent default behavior */
|
|
26
|
+
onKeyDown?: (event: KeyboardEvent) => boolean;
|
|
27
|
+
/** Callback fired when text selection changes */
|
|
28
|
+
onSelectionChange?: (selection: {
|
|
29
|
+
from: number;
|
|
30
|
+
to: number;
|
|
31
|
+
} | null) => void;
|
|
32
|
+
/** Callback fired when a slash command (e.g., /template) matches */
|
|
33
|
+
onSlashCommandMatch?: (match: RegExpMatchArray, from: number, to: number, coords: {
|
|
34
|
+
top: number;
|
|
35
|
+
left: number;
|
|
36
|
+
}) => void;
|
|
37
|
+
/** Callback to dismiss/clear the active slash command */
|
|
38
|
+
clearSlashCommand?: () => void;
|
|
39
|
+
/** Whether a slash command menu is currently active */
|
|
40
|
+
slashCommandActive?: boolean;
|
|
41
|
+
/** Callback fired when certain milestones are reached (e.g., used_variable, used_magic) */
|
|
42
|
+
onMilestone?: (milestone: string) => void;
|
|
43
|
+
/** DOM element ID of the container, used for positioning popovers */
|
|
44
|
+
containerId?: string;
|
|
45
|
+
/** Variable names originating from structured JSON output steps */
|
|
46
|
+
jsonVariables?: string[];
|
|
47
|
+
/** Animation speed for gradient decorations */
|
|
48
|
+
speed?: number;
|
|
49
|
+
}
|
|
50
|
+
declare function usePromptEditor({ content, onContentChange, templates, templateColorMap: userColorMap, isEditing, placeholder, className, onEscape, onKeyDown, onSelectionChange, onSlashCommandMatch, clearSlashCommand, slashCommandActive, onMilestone, containerId, jsonVariables, speed, }: UsePromptEditorProps): _tiptap_core.Editor | null;
|
|
51
|
+
|
|
52
|
+
interface UseRichEditorProps extends UseEditorOptions {
|
|
53
|
+
richTextOptions?: RichTextPresetOptions;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Hook to initialize a TipTap rich-text editor instance with pre-configured extensions.
|
|
57
|
+
*/
|
|
58
|
+
declare function useEditor(options?: UseRichEditorProps): _tiptap_core.Editor | null;
|
|
59
|
+
|
|
60
|
+
interface EditorContentProps extends EditorContentProps$1 {
|
|
61
|
+
className?: string;
|
|
62
|
+
}
|
|
63
|
+
declare const EditorContent: React.FC<EditorContentProps>;
|
|
64
|
+
|
|
65
|
+
interface BubbleMenuProps {
|
|
66
|
+
editor: Editor | null;
|
|
67
|
+
className?: string;
|
|
68
|
+
children: React.ReactNode;
|
|
69
|
+
}
|
|
70
|
+
declare const BubbleMenu: React.FC<BubbleMenuProps>;
|
|
71
|
+
|
|
72
|
+
interface TemplateRendererProps {
|
|
73
|
+
/** Raw prompt or text string to render */
|
|
74
|
+
content: string;
|
|
75
|
+
/** Available templates for recursive resolution and custom coloring */
|
|
76
|
+
templates?: Template[];
|
|
77
|
+
/** Custom gradient color map for templates */
|
|
78
|
+
templateColorMap?: Map<string, ColorGradient>;
|
|
79
|
+
/** Whether to resolve nested templates recursively before displaying */
|
|
80
|
+
resolve?: boolean;
|
|
81
|
+
/** Custom class name for the wrapper */
|
|
82
|
+
className?: string;
|
|
83
|
+
/** Click callback for template badges */
|
|
84
|
+
onTemplateClick?: (templateName: string) => void;
|
|
85
|
+
/** Click callback for variable badges */
|
|
86
|
+
onVariableClick?: (variableName: string) => void;
|
|
87
|
+
}
|
|
88
|
+
declare const TemplateRenderer: React.FC<TemplateRendererProps>;
|
|
89
|
+
|
|
90
|
+
export { BubbleMenu, type BubbleMenuProps, EditorContent, type EditorContentProps, TemplateRenderer, type TemplateRendererProps, type UsePromptEditorProps, type UseRichEditorProps, useEditor, usePromptEditor };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import * as _tiptap_core from '@tiptap/core';
|
|
2
|
+
import { Editor } from '@tiptap/core';
|
|
3
|
+
import { Template, ColorGradient, RichTextPresetOptions } from '@pixerate/editor';
|
|
4
|
+
export { ColorGradient, RichTextPresetOptions, Template, TemplateVersion, Token, TokenType } from '@pixerate/editor';
|
|
5
|
+
import { UseEditorOptions, EditorContentProps as EditorContentProps$1 } from '@tiptap/react';
|
|
6
|
+
import React from 'react';
|
|
7
|
+
|
|
8
|
+
interface UsePromptEditorProps {
|
|
9
|
+
/** The initial or controlled content of the editor as plain text */
|
|
10
|
+
content: string;
|
|
11
|
+
/** Callback fired when the editor content changes (returns plain text) */
|
|
12
|
+
onContentChange: (text: string) => void;
|
|
13
|
+
/** List of available templates to be suggested and highlighted */
|
|
14
|
+
templates?: Template[];
|
|
15
|
+
/** Custom gradient color map for templates */
|
|
16
|
+
templateColorMap?: Map<string, ColorGradient>;
|
|
17
|
+
/** Whether the editor is editable */
|
|
18
|
+
isEditing?: boolean;
|
|
19
|
+
/** Placeholder text for the editor */
|
|
20
|
+
placeholder?: string;
|
|
21
|
+
/** Additional CSS classes for the editor container */
|
|
22
|
+
className?: string;
|
|
23
|
+
/** Callback fired when the Escape key is pressed */
|
|
24
|
+
onEscape?: () => void;
|
|
25
|
+
/** Custom keydown handler. Return true to prevent default behavior */
|
|
26
|
+
onKeyDown?: (event: KeyboardEvent) => boolean;
|
|
27
|
+
/** Callback fired when text selection changes */
|
|
28
|
+
onSelectionChange?: (selection: {
|
|
29
|
+
from: number;
|
|
30
|
+
to: number;
|
|
31
|
+
} | null) => void;
|
|
32
|
+
/** Callback fired when a slash command (e.g., /template) matches */
|
|
33
|
+
onSlashCommandMatch?: (match: RegExpMatchArray, from: number, to: number, coords: {
|
|
34
|
+
top: number;
|
|
35
|
+
left: number;
|
|
36
|
+
}) => void;
|
|
37
|
+
/** Callback to dismiss/clear the active slash command */
|
|
38
|
+
clearSlashCommand?: () => void;
|
|
39
|
+
/** Whether a slash command menu is currently active */
|
|
40
|
+
slashCommandActive?: boolean;
|
|
41
|
+
/** Callback fired when certain milestones are reached (e.g., used_variable, used_magic) */
|
|
42
|
+
onMilestone?: (milestone: string) => void;
|
|
43
|
+
/** DOM element ID of the container, used for positioning popovers */
|
|
44
|
+
containerId?: string;
|
|
45
|
+
/** Variable names originating from structured JSON output steps */
|
|
46
|
+
jsonVariables?: string[];
|
|
47
|
+
/** Animation speed for gradient decorations */
|
|
48
|
+
speed?: number;
|
|
49
|
+
}
|
|
50
|
+
declare function usePromptEditor({ content, onContentChange, templates, templateColorMap: userColorMap, isEditing, placeholder, className, onEscape, onKeyDown, onSelectionChange, onSlashCommandMatch, clearSlashCommand, slashCommandActive, onMilestone, containerId, jsonVariables, speed, }: UsePromptEditorProps): _tiptap_core.Editor | null;
|
|
51
|
+
|
|
52
|
+
interface UseRichEditorProps extends UseEditorOptions {
|
|
53
|
+
richTextOptions?: RichTextPresetOptions;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Hook to initialize a TipTap rich-text editor instance with pre-configured extensions.
|
|
57
|
+
*/
|
|
58
|
+
declare function useEditor(options?: UseRichEditorProps): _tiptap_core.Editor | null;
|
|
59
|
+
|
|
60
|
+
interface EditorContentProps extends EditorContentProps$1 {
|
|
61
|
+
className?: string;
|
|
62
|
+
}
|
|
63
|
+
declare const EditorContent: React.FC<EditorContentProps>;
|
|
64
|
+
|
|
65
|
+
interface BubbleMenuProps {
|
|
66
|
+
editor: Editor | null;
|
|
67
|
+
className?: string;
|
|
68
|
+
children: React.ReactNode;
|
|
69
|
+
}
|
|
70
|
+
declare const BubbleMenu: React.FC<BubbleMenuProps>;
|
|
71
|
+
|
|
72
|
+
interface TemplateRendererProps {
|
|
73
|
+
/** Raw prompt or text string to render */
|
|
74
|
+
content: string;
|
|
75
|
+
/** Available templates for recursive resolution and custom coloring */
|
|
76
|
+
templates?: Template[];
|
|
77
|
+
/** Custom gradient color map for templates */
|
|
78
|
+
templateColorMap?: Map<string, ColorGradient>;
|
|
79
|
+
/** Whether to resolve nested templates recursively before displaying */
|
|
80
|
+
resolve?: boolean;
|
|
81
|
+
/** Custom class name for the wrapper */
|
|
82
|
+
className?: string;
|
|
83
|
+
/** Click callback for template badges */
|
|
84
|
+
onTemplateClick?: (templateName: string) => void;
|
|
85
|
+
/** Click callback for variable badges */
|
|
86
|
+
onVariableClick?: (variableName: string) => void;
|
|
87
|
+
}
|
|
88
|
+
declare const TemplateRenderer: React.FC<TemplateRendererProps>;
|
|
89
|
+
|
|
90
|
+
export { BubbleMenu, type BubbleMenuProps, EditorContent, type EditorContentProps, TemplateRenderer, type TemplateRendererProps, type UsePromptEditorProps, type UseRichEditorProps, useEditor, usePromptEditor };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
// src/hooks/usePromptEditor.ts
|
|
2
|
+
import { useMemo, useRef } from "react";
|
|
3
|
+
import { useEditor } from "@tiptap/react";
|
|
4
|
+
import StarterKit from "@tiptap/starter-kit";
|
|
5
|
+
import Placeholder from "@tiptap/extension-placeholder";
|
|
6
|
+
import { Slice, Fragment, Node as ProsemirrorNode } from "@tiptap/pm/model";
|
|
7
|
+
import {
|
|
8
|
+
GradientText,
|
|
9
|
+
TemplateSuggestions,
|
|
10
|
+
LoadingNode,
|
|
11
|
+
plainTextToTipTapHtml,
|
|
12
|
+
getEditorText
|
|
13
|
+
} from "@pixerate/editor";
|
|
14
|
+
var DEFAULT_TEMPLATES = [];
|
|
15
|
+
var DEFAULT_COLOR_MAP = /* @__PURE__ */ new Map([
|
|
16
|
+
["default", { from: "#f43f5e", to: "#8b5cf6" }]
|
|
17
|
+
]);
|
|
18
|
+
function usePromptEditor({
|
|
19
|
+
content,
|
|
20
|
+
onContentChange,
|
|
21
|
+
templates = DEFAULT_TEMPLATES,
|
|
22
|
+
templateColorMap: userColorMap,
|
|
23
|
+
isEditing = true,
|
|
24
|
+
placeholder = "Write a prompt, use {{template}}, {variable}, or /command...",
|
|
25
|
+
className,
|
|
26
|
+
onEscape,
|
|
27
|
+
onKeyDown,
|
|
28
|
+
onSelectionChange,
|
|
29
|
+
onSlashCommandMatch,
|
|
30
|
+
clearSlashCommand,
|
|
31
|
+
slashCommandActive = false,
|
|
32
|
+
onMilestone,
|
|
33
|
+
containerId = "editor-container",
|
|
34
|
+
jsonVariables,
|
|
35
|
+
speed = 2
|
|
36
|
+
}) {
|
|
37
|
+
const slashCommandActiveRef = useRef(slashCommandActive);
|
|
38
|
+
slashCommandActiveRef.current = slashCommandActive;
|
|
39
|
+
const clearSlashCommandRef = useRef(clearSlashCommand);
|
|
40
|
+
clearSlashCommandRef.current = clearSlashCommand;
|
|
41
|
+
const onEscapeRef = useRef(onEscape);
|
|
42
|
+
onEscapeRef.current = onEscape;
|
|
43
|
+
const onKeyDownRef = useRef(onKeyDown);
|
|
44
|
+
onKeyDownRef.current = onKeyDown;
|
|
45
|
+
const onSelectionChangeRef = useRef(onSelectionChange);
|
|
46
|
+
onSelectionChangeRef.current = onSelectionChange;
|
|
47
|
+
const onSlashCommandMatchRef = useRef(onSlashCommandMatch);
|
|
48
|
+
onSlashCommandMatchRef.current = onSlashCommandMatch;
|
|
49
|
+
const onContentChangeRef = useRef(onContentChange);
|
|
50
|
+
onContentChangeRef.current = onContentChange;
|
|
51
|
+
const onMilestoneRef = useRef(onMilestone);
|
|
52
|
+
onMilestoneRef.current = onMilestone;
|
|
53
|
+
const containerIdRef = useRef(containerId);
|
|
54
|
+
containerIdRef.current = containerId;
|
|
55
|
+
const resolvedColorMap = useMemo(() => {
|
|
56
|
+
if (userColorMap) return userColorMap;
|
|
57
|
+
const map = /* @__PURE__ */ new Map();
|
|
58
|
+
templates.forEach((t) => {
|
|
59
|
+
map.set(t.name, { from: "#f43f5e", to: "#8b5cf6" });
|
|
60
|
+
});
|
|
61
|
+
return map.size > 0 ? map : DEFAULT_COLOR_MAP;
|
|
62
|
+
}, [userColorMap, templates]);
|
|
63
|
+
const editor = useEditor(
|
|
64
|
+
{
|
|
65
|
+
immediatelyRender: false,
|
|
66
|
+
enablePasteRules: false,
|
|
67
|
+
enableInputRules: false,
|
|
68
|
+
editable: isEditing,
|
|
69
|
+
extensions: [
|
|
70
|
+
StarterKit.configure({
|
|
71
|
+
heading: false,
|
|
72
|
+
codeBlock: false
|
|
73
|
+
}),
|
|
74
|
+
Placeholder.configure({ placeholder }),
|
|
75
|
+
GradientText.configure({
|
|
76
|
+
templateColorMap: resolvedColorMap,
|
|
77
|
+
speed,
|
|
78
|
+
jsonVariables
|
|
79
|
+
}),
|
|
80
|
+
TemplateSuggestions.configure({
|
|
81
|
+
templates
|
|
82
|
+
}),
|
|
83
|
+
LoadingNode
|
|
84
|
+
],
|
|
85
|
+
content: plainTextToTipTapHtml(content),
|
|
86
|
+
onUpdate: ({ editor: ed }) => {
|
|
87
|
+
const plainText = getEditorText(ed);
|
|
88
|
+
onContentChangeRef.current?.(plainText);
|
|
89
|
+
if (onMilestoneRef.current) {
|
|
90
|
+
if (plainText.match(/(?<!\{)\{([^{}]+)\}(?!\})/g)) {
|
|
91
|
+
onMilestoneRef.current("used_variable");
|
|
92
|
+
}
|
|
93
|
+
if (plainText.match(/__([^_]+)__/g)) {
|
|
94
|
+
onMilestoneRef.current("used_magic");
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const { state, view } = ed;
|
|
98
|
+
const { selection } = state;
|
|
99
|
+
const { $from, from, to } = selection;
|
|
100
|
+
onSelectionChangeRef.current?.({ from, to });
|
|
101
|
+
if (onSlashCommandMatchRef.current && clearSlashCommandRef.current) {
|
|
102
|
+
const textBeforeCursor = $from?.parent?.textBetween ? $from.parent.textBetween(0, $from.parentOffset) : "";
|
|
103
|
+
const slashMatch = textBeforeCursor.match(
|
|
104
|
+
/(?:^|\s)\/([a-zA-Z0-9_-]*)$/
|
|
105
|
+
);
|
|
106
|
+
if (slashMatch) {
|
|
107
|
+
const coords = view.coordsAtPos($from.pos);
|
|
108
|
+
const containerEl = document.getElementById(containerIdRef.current) || document.getElementById("editor-container") || view.dom.closest?.(".relative");
|
|
109
|
+
const containerCoords = containerEl?.getBoundingClientRect();
|
|
110
|
+
if (containerCoords) {
|
|
111
|
+
onSlashCommandMatchRef.current(
|
|
112
|
+
slashMatch,
|
|
113
|
+
$from.pos - slashMatch[0].length + (slashMatch[0].startsWith(" ") ? 1 : 0),
|
|
114
|
+
$from.pos,
|
|
115
|
+
{
|
|
116
|
+
top: coords.bottom - containerCoords.top + 5,
|
|
117
|
+
left: coords.left - containerCoords.left
|
|
118
|
+
}
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
} else {
|
|
122
|
+
clearSlashCommandRef.current();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
onSelectionUpdate: ({ editor: ed }) => {
|
|
127
|
+
const { from, to } = ed.state.selection;
|
|
128
|
+
onSelectionChangeRef.current?.({ from, to });
|
|
129
|
+
},
|
|
130
|
+
editorProps: {
|
|
131
|
+
attributes: {
|
|
132
|
+
class: className || "w-full border border-input rounded-md p-3 font-mono text-sm leading-relaxed focus:outline-none focus:ring-2 focus:ring-primary whitespace-pre-wrap break-words"
|
|
133
|
+
},
|
|
134
|
+
handleKeyDown: (view, event) => {
|
|
135
|
+
if (event.key === "Escape" && onEscapeRef.current) {
|
|
136
|
+
onEscapeRef.current();
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
if (onKeyDownRef.current) {
|
|
140
|
+
return onKeyDownRef.current(event);
|
|
141
|
+
}
|
|
142
|
+
return false;
|
|
143
|
+
},
|
|
144
|
+
clipboardTextParser: (text, context, _plain, view) => {
|
|
145
|
+
const schema = context?.doc?.type?.schema || context?.schema || view?.state?.schema;
|
|
146
|
+
if (!schema) return Slice.empty;
|
|
147
|
+
const blocks = text.replace(/\r\n?/g, "\n").split("\n");
|
|
148
|
+
const nodes = [];
|
|
149
|
+
blocks.forEach((line) => {
|
|
150
|
+
const nodeJson = { type: "paragraph" };
|
|
151
|
+
if (line.length > 0) {
|
|
152
|
+
nodeJson.content = [{ type: "text", text: line }];
|
|
153
|
+
}
|
|
154
|
+
try {
|
|
155
|
+
const node = ProsemirrorNode.fromJSON(schema, nodeJson);
|
|
156
|
+
nodes.push(node);
|
|
157
|
+
} catch {
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
return Slice.maxOpen(Fragment.fromArray(nodes));
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
[templates, resolvedColorMap, isEditing, placeholder, speed]
|
|
165
|
+
);
|
|
166
|
+
return editor;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// src/hooks/useEditor.ts
|
|
170
|
+
import { useEditor as useTipTapEditor } from "@tiptap/react";
|
|
171
|
+
import { createRichTextPreset } from "@pixerate/editor";
|
|
172
|
+
function useEditor2(options = {}) {
|
|
173
|
+
const { richTextOptions, extensions = [], ...editorOptions } = options;
|
|
174
|
+
const preset = createRichTextPreset(richTextOptions);
|
|
175
|
+
const combinedExtensions = [...preset, ...extensions];
|
|
176
|
+
return useTipTapEditor({
|
|
177
|
+
extensions: combinedExtensions,
|
|
178
|
+
...editorOptions
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// src/components/EditorContent.tsx
|
|
183
|
+
import {
|
|
184
|
+
EditorContent as TipTapEditorContent
|
|
185
|
+
} from "@tiptap/react";
|
|
186
|
+
import { jsx } from "react/jsx-runtime";
|
|
187
|
+
var EditorContent = ({
|
|
188
|
+
className,
|
|
189
|
+
editor,
|
|
190
|
+
...props
|
|
191
|
+
}) => {
|
|
192
|
+
return /* @__PURE__ */ jsx("div", { className, children: /* @__PURE__ */ jsx(TipTapEditorContent, { editor, ...props }) });
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
// src/components/BubbleMenu.tsx
|
|
196
|
+
import { BubbleMenu as TipTapBubbleMenu } from "@tiptap/react";
|
|
197
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
198
|
+
var BubbleMenu = ({
|
|
199
|
+
editor,
|
|
200
|
+
className = "flex items-center gap-1 bg-popover text-popover-foreground border shadow-md rounded-md p-1",
|
|
201
|
+
children
|
|
202
|
+
}) => {
|
|
203
|
+
if (!editor) return null;
|
|
204
|
+
return /* @__PURE__ */ jsx2(
|
|
205
|
+
TipTapBubbleMenu,
|
|
206
|
+
{
|
|
207
|
+
editor,
|
|
208
|
+
tippyOptions: { duration: 100 },
|
|
209
|
+
className,
|
|
210
|
+
children
|
|
211
|
+
}
|
|
212
|
+
);
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
// src/components/TemplateRenderer.tsx
|
|
216
|
+
import { useMemo as useMemo2 } from "react";
|
|
217
|
+
import {
|
|
218
|
+
tokenizePrompt,
|
|
219
|
+
resolveTemplates
|
|
220
|
+
} from "@pixerate/editor";
|
|
221
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
222
|
+
var TemplateRenderer = ({
|
|
223
|
+
content,
|
|
224
|
+
templates = [],
|
|
225
|
+
templateColorMap,
|
|
226
|
+
resolve = false,
|
|
227
|
+
className = "font-mono text-sm leading-relaxed whitespace-pre-wrap break-words",
|
|
228
|
+
onTemplateClick,
|
|
229
|
+
onVariableClick
|
|
230
|
+
}) => {
|
|
231
|
+
const displayText = useMemo2(() => {
|
|
232
|
+
if (!resolve || templates.length === 0) return content;
|
|
233
|
+
return resolveTemplates(content, templates);
|
|
234
|
+
}, [content, templates, resolve]);
|
|
235
|
+
const tokens = useMemo2(() => {
|
|
236
|
+
return tokenizePrompt(displayText);
|
|
237
|
+
}, [displayText]);
|
|
238
|
+
return /* @__PURE__ */ jsx3("div", { className, children: tokens.map((token, index) => {
|
|
239
|
+
if (token.type === "template") {
|
|
240
|
+
const colors = templateColorMap?.get(token.value) || {
|
|
241
|
+
from: "#f43f5e",
|
|
242
|
+
to: "#8b5cf6"
|
|
243
|
+
};
|
|
244
|
+
const style = {
|
|
245
|
+
"--color-from": colors.from,
|
|
246
|
+
"--color-to": colors.to
|
|
247
|
+
};
|
|
248
|
+
return /* @__PURE__ */ jsx3(
|
|
249
|
+
"span",
|
|
250
|
+
{
|
|
251
|
+
style,
|
|
252
|
+
onClick: () => onTemplateClick?.(token.value),
|
|
253
|
+
className: "inline-flex items-center px-1.5 py-0.5 mx-0.5 text-xs font-semibold rounded-md border border-[var(--color-to)]/40 bg-gradient-to-r from-[var(--color-from)]/15 to-[var(--color-to)]/15 text-[var(--color-to)] hover:brightness-110 cursor-pointer transition-all",
|
|
254
|
+
title: `Template: ${token.value}`,
|
|
255
|
+
children: `{{${token.value}}}`
|
|
256
|
+
},
|
|
257
|
+
index
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
if (token.type === "variable") {
|
|
261
|
+
return /* @__PURE__ */ jsx3(
|
|
262
|
+
"span",
|
|
263
|
+
{
|
|
264
|
+
onClick: () => onVariableClick?.(token.value),
|
|
265
|
+
className: "inline-flex items-center px-1.5 py-0.5 mx-0.5 text-xs font-medium rounded-md border border-violet-400/40 bg-violet-400/15 text-violet-600 dark:text-violet-300 hover:brightness-110 cursor-pointer transition-all",
|
|
266
|
+
title: `Variable: ${token.value}`,
|
|
267
|
+
children: `{${token.value}}`
|
|
268
|
+
},
|
|
269
|
+
index
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
if (token.type === "instruction") {
|
|
273
|
+
return /* @__PURE__ */ jsx3(
|
|
274
|
+
"span",
|
|
275
|
+
{
|
|
276
|
+
className: "inline-flex items-center px-1.5 py-0.5 mx-0.5 text-xs italic font-medium rounded-md border border-rose-400/40 bg-rose-400/15 text-rose-600 dark:text-rose-300",
|
|
277
|
+
title: `Instruction: ${token.value}`,
|
|
278
|
+
children: `__${token.value}__`
|
|
279
|
+
},
|
|
280
|
+
index
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
return /* @__PURE__ */ jsx3("span", { children: token.value }, index);
|
|
284
|
+
}) });
|
|
285
|
+
};
|
|
286
|
+
export {
|
|
287
|
+
BubbleMenu,
|
|
288
|
+
EditorContent,
|
|
289
|
+
TemplateRenderer,
|
|
290
|
+
useEditor2 as useEditor,
|
|
291
|
+
usePromptEditor
|
|
292
|
+
};
|
|
293
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks/usePromptEditor.ts","../src/hooks/useEditor.ts","../src/components/EditorContent.tsx","../src/components/BubbleMenu.tsx","../src/components/TemplateRenderer.tsx"],"sourcesContent":["import { useMemo, useEffect, useRef } from \"react\";\nimport { useEditor } from \"@tiptap/react\";\nimport StarterKit from \"@tiptap/starter-kit\";\nimport Placeholder from \"@tiptap/extension-placeholder\";\nimport { Slice, Fragment, Node as ProsemirrorNode } from \"@tiptap/pm/model\";\nimport {\n Template,\n ColorGradient,\n GradientText,\n TemplateSuggestions,\n LoadingNode,\n plainTextToTipTapHtml,\n getEditorText,\n} from \"@pixerate/editor\";\n\nexport interface UsePromptEditorProps {\n /** The initial or controlled content of the editor as plain text */\n content: string;\n /** Callback fired when the editor content changes (returns plain text) */\n onContentChange: (text: string) => void;\n /** List of available templates to be suggested and highlighted */\n templates?: Template[];\n /** Custom gradient color map for templates */\n templateColorMap?: Map<string, ColorGradient>;\n /** Whether the editor is editable */\n isEditing?: boolean;\n /** Placeholder text for the editor */\n placeholder?: string;\n /** Additional CSS classes for the editor container */\n className?: string;\n /** Callback fired when the Escape key is pressed */\n onEscape?: () => void;\n /** Custom keydown handler. Return true to prevent default behavior */\n onKeyDown?: (event: KeyboardEvent) => boolean;\n /** Callback fired when text selection changes */\n onSelectionChange?: (selection: { from: number; to: number } | null) => void;\n /** Callback fired when a slash command (e.g., /template) matches */\n onSlashCommandMatch?: (\n match: RegExpMatchArray,\n from: number,\n to: number,\n coords: { top: number; left: number },\n ) => void;\n /** Callback to dismiss/clear the active slash command */\n clearSlashCommand?: () => void;\n /** Whether a slash command menu is currently active */\n slashCommandActive?: boolean;\n /** Callback fired when certain milestones are reached (e.g., used_variable, used_magic) */\n onMilestone?: (milestone: string) => void;\n /** DOM element ID of the container, used for positioning popovers */\n containerId?: string;\n /** Variable names originating from structured JSON output steps */\n jsonVariables?: string[];\n /** Animation speed for gradient decorations */\n speed?: number;\n}\n\nconst DEFAULT_TEMPLATES: Template[] = [];\nconst DEFAULT_COLOR_MAP = new Map<string, ColorGradient>([\n [\"default\", { from: \"#f43f5e\", to: \"#8b5cf6\" }],\n]);\n\nexport function usePromptEditor({\n content,\n onContentChange,\n templates = DEFAULT_TEMPLATES,\n templateColorMap: userColorMap,\n isEditing = true,\n placeholder = \"Write a prompt, use {{template}}, {variable}, or /command...\",\n className,\n onEscape,\n onKeyDown,\n onSelectionChange,\n onSlashCommandMatch,\n clearSlashCommand,\n slashCommandActive = false,\n onMilestone,\n containerId = \"editor-container\",\n jsonVariables,\n speed = 2,\n}: UsePromptEditorProps) {\n const slashCommandActiveRef = useRef(slashCommandActive);\n slashCommandActiveRef.current = slashCommandActive;\n\n const clearSlashCommandRef = useRef(clearSlashCommand);\n clearSlashCommandRef.current = clearSlashCommand;\n\n const onEscapeRef = useRef(onEscape);\n onEscapeRef.current = onEscape;\n\n const onKeyDownRef = useRef(onKeyDown);\n onKeyDownRef.current = onKeyDown;\n\n const onSelectionChangeRef = useRef(onSelectionChange);\n onSelectionChangeRef.current = onSelectionChange;\n\n const onSlashCommandMatchRef = useRef(onSlashCommandMatch);\n onSlashCommandMatchRef.current = onSlashCommandMatch;\n\n const onContentChangeRef = useRef(onContentChange);\n onContentChangeRef.current = onContentChange;\n\n const onMilestoneRef = useRef(onMilestone);\n onMilestoneRef.current = onMilestone;\n\n const containerIdRef = useRef(containerId);\n containerIdRef.current = containerId;\n\n const resolvedColorMap = useMemo(() => {\n if (userColorMap) return userColorMap;\n const map = new Map<string, ColorGradient>();\n templates.forEach((t) => {\n map.set(t.name, { from: \"#f43f5e\", to: \"#8b5cf6\" });\n });\n return map.size > 0 ? map : DEFAULT_COLOR_MAP;\n }, [userColorMap, templates]);\n\n const editor = useEditor(\n {\n immediatelyRender: false,\n enablePasteRules: false,\n enableInputRules: false,\n editable: isEditing,\n extensions: [\n StarterKit.configure({\n heading: false,\n codeBlock: false,\n }),\n Placeholder.configure({ placeholder }),\n GradientText.configure({\n templateColorMap: resolvedColorMap,\n speed,\n jsonVariables,\n }),\n TemplateSuggestions.configure({\n templates,\n }),\n LoadingNode,\n ],\n content: plainTextToTipTapHtml(content),\n onUpdate: ({ editor: ed }) => {\n const plainText = getEditorText(ed);\n onContentChangeRef.current?.(plainText);\n\n if (onMilestoneRef.current) {\n if (plainText.match(/(?<!\\{)\\{([^{}]+)\\}(?!\\})/g)) {\n onMilestoneRef.current(\"used_variable\");\n }\n if (plainText.match(/__([^_]+)__/g)) {\n onMilestoneRef.current(\"used_magic\");\n }\n }\n\n const { state, view } = ed;\n const { selection } = state;\n const { $from, from, to } = selection;\n\n onSelectionChangeRef.current?.({ from, to });\n\n if (onSlashCommandMatchRef.current && clearSlashCommandRef.current) {\n const textBeforeCursor = $from?.parent?.textBetween\n ? $from.parent.textBetween(0, $from.parentOffset)\n : \"\";\n const slashMatch = textBeforeCursor.match(\n /(?:^|\\s)\\/([a-zA-Z0-9_-]*)$/,\n );\n\n if (slashMatch) {\n const coords = view.coordsAtPos($from.pos);\n const containerEl =\n document.getElementById(containerIdRef.current) ||\n document.getElementById(\"editor-container\") ||\n (view.dom.closest?.(\".relative\") as HTMLElement | null);\n const containerCoords = containerEl?.getBoundingClientRect();\n\n if (containerCoords) {\n onSlashCommandMatchRef.current(\n slashMatch,\n $from.pos -\n slashMatch[0].length +\n (slashMatch[0].startsWith(\" \") ? 1 : 0),\n $from.pos,\n {\n top: coords.bottom - containerCoords.top + 5,\n left: coords.left - containerCoords.left,\n },\n );\n }\n } else {\n clearSlashCommandRef.current();\n }\n }\n },\n onSelectionUpdate: ({ editor: ed }) => {\n const { from, to } = ed.state.selection;\n onSelectionChangeRef.current?.({ from, to });\n },\n editorProps: {\n attributes: {\n class:\n className ||\n \"w-full border border-input rounded-md p-3 font-mono text-sm leading-relaxed focus:outline-none focus:ring-2 focus:ring-primary whitespace-pre-wrap break-words\",\n },\n handleKeyDown: (view, event) => {\n if (event.key === \"Escape\" && onEscapeRef.current) {\n onEscapeRef.current();\n return true;\n }\n if (onKeyDownRef.current) {\n return onKeyDownRef.current(event);\n }\n return false;\n },\n clipboardTextParser: (text, context, _plain, view) => {\n const schema =\n (context as any)?.doc?.type?.schema ||\n (context as any)?.schema ||\n view?.state?.schema;\n\n if (!schema) return Slice.empty;\n\n const blocks = text.replace(/\\r\\n?/g, \"\\n\").split(\"\\n\");\n const nodes: ProsemirrorNode[] = [];\n\n blocks.forEach((line) => {\n const nodeJson: any = { type: \"paragraph\" };\n if (line.length > 0) {\n nodeJson.content = [{ type: \"text\", text: line }];\n }\n try {\n const node = ProsemirrorNode.fromJSON(schema, nodeJson);\n nodes.push(node);\n } catch {\n // Ignore\n }\n });\n\n return Slice.maxOpen(Fragment.fromArray(nodes));\n },\n },\n },\n [templates, resolvedColorMap, isEditing, placeholder, speed],\n );\n\n return editor;\n}\n","import { useEditor as useTipTapEditor, UseEditorOptions } from \"@tiptap/react\";\nimport { createRichTextPreset, RichTextPresetOptions } from \"@pixerate/editor\";\n\nexport interface UseRichEditorProps extends UseEditorOptions {\n richTextOptions?: RichTextPresetOptions;\n}\n\n/**\n * Hook to initialize a TipTap rich-text editor instance with pre-configured extensions.\n */\nexport function useEditor(options: UseRichEditorProps = {}) {\n const { richTextOptions, extensions = [], ...editorOptions } = options;\n\n const preset = createRichTextPreset(richTextOptions);\n const combinedExtensions = [...preset, ...extensions];\n\n return useTipTapEditor({\n extensions: combinedExtensions,\n ...editorOptions,\n });\n}\n","import React from \"react\";\nimport {\n EditorContent as TipTapEditorContent,\n EditorContentProps as TipTapEditorContentProps,\n} from \"@tiptap/react\";\n\nexport interface EditorContentProps extends TipTapEditorContentProps {\n className?: string;\n}\n\nexport const EditorContent: React.FC<EditorContentProps> = ({\n className,\n editor,\n ...props\n}) => {\n return (\n <div className={className}>\n <TipTapEditorContent editor={editor} {...props} />\n </div>\n );\n};\n","import React from \"react\";\nimport { BubbleMenu as TipTapBubbleMenu } from \"@tiptap/react\";\nimport type { Editor } from \"@tiptap/core\";\n\nexport interface BubbleMenuProps {\n editor: Editor | null;\n className?: string;\n children: React.ReactNode;\n}\n\nexport const BubbleMenu: React.FC<BubbleMenuProps> = ({\n editor,\n className = \"flex items-center gap-1 bg-popover text-popover-foreground border shadow-md rounded-md p-1\",\n children,\n}) => {\n if (!editor) return null;\n\n return (\n <TipTapBubbleMenu\n editor={editor}\n tippyOptions={{ duration: 100 }}\n className={className}\n >\n {children}\n </TipTapBubbleMenu>\n );\n};\n","import React, { useMemo } from \"react\";\nimport {\n tokenizePrompt,\n resolveTemplates,\n Template,\n ColorGradient,\n} from \"@pixerate/editor\";\n\nexport interface TemplateRendererProps {\n /** Raw prompt or text string to render */\n content: string;\n /** Available templates for recursive resolution and custom coloring */\n templates?: Template[];\n /** Custom gradient color map for templates */\n templateColorMap?: Map<string, ColorGradient>;\n /** Whether to resolve nested templates recursively before displaying */\n resolve?: boolean;\n /** Custom class name for the wrapper */\n className?: string;\n /** Click callback for template badges */\n onTemplateClick?: (templateName: string) => void;\n /** Click callback for variable badges */\n onVariableClick?: (variableName: string) => void;\n}\n\nexport const TemplateRenderer: React.FC<TemplateRendererProps> = ({\n content,\n templates = [],\n templateColorMap,\n resolve = false,\n className = \"font-mono text-sm leading-relaxed whitespace-pre-wrap break-words\",\n onTemplateClick,\n onVariableClick,\n}) => {\n const displayText = useMemo(() => {\n if (!resolve || templates.length === 0) return content;\n return resolveTemplates(content, templates);\n }, [content, templates, resolve]);\n\n const tokens = useMemo(() => {\n return tokenizePrompt(displayText);\n }, [displayText]);\n\n return (\n <div className={className}>\n {tokens.map((token, index) => {\n if (token.type === \"template\") {\n const colors = templateColorMap?.get(token.value) || {\n from: \"#f43f5e\",\n to: \"#8b5cf6\",\n };\n const style = {\n \"--color-from\": colors.from,\n \"--color-to\": colors.to,\n } as React.CSSProperties;\n\n return (\n <span\n key={index}\n style={style}\n onClick={() => onTemplateClick?.(token.value)}\n className=\"inline-flex items-center px-1.5 py-0.5 mx-0.5 text-xs font-semibold rounded-md border border-[var(--color-to)]/40 bg-gradient-to-r from-[var(--color-from)]/15 to-[var(--color-to)]/15 text-[var(--color-to)] hover:brightness-110 cursor-pointer transition-all\"\n title={`Template: ${token.value}`}\n >\n {`{{${token.value}}}`}\n </span>\n );\n }\n\n if (token.type === \"variable\") {\n return (\n <span\n key={index}\n onClick={() => onVariableClick?.(token.value)}\n className=\"inline-flex items-center px-1.5 py-0.5 mx-0.5 text-xs font-medium rounded-md border border-violet-400/40 bg-violet-400/15 text-violet-600 dark:text-violet-300 hover:brightness-110 cursor-pointer transition-all\"\n title={`Variable: ${token.value}`}\n >\n {`{${token.value}}`}\n </span>\n );\n }\n\n if (token.type === \"instruction\") {\n return (\n <span\n key={index}\n className=\"inline-flex items-center px-1.5 py-0.5 mx-0.5 text-xs italic font-medium rounded-md border border-rose-400/40 bg-rose-400/15 text-rose-600 dark:text-rose-300\"\n title={`Instruction: ${token.value}`}\n >\n {`__${token.value}__`}\n </span>\n );\n }\n\n return <span key={index}>{token.value}</span>;\n })}\n </div>\n );\n};\n"],"mappings":";AAAA,SAAS,SAAoB,cAAc;AAC3C,SAAS,iBAAiB;AAC1B,OAAO,gBAAgB;AACvB,OAAO,iBAAiB;AACxB,SAAS,OAAO,UAAU,QAAQ,uBAAuB;AACzD;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AA4CP,IAAM,oBAAgC,CAAC;AACvC,IAAM,oBAAoB,oBAAI,IAA2B;AAAA,EACvD,CAAC,WAAW,EAAE,MAAM,WAAW,IAAI,UAAU,CAAC;AAChD,CAAC;AAEM,SAAS,gBAAgB;AAAA,EAC9B;AAAA,EACA;AAAA,EACA,YAAY;AAAA,EACZ,kBAAkB;AAAA,EAClB,YAAY;AAAA,EACZ,cAAc;AAAA,EACd;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,qBAAqB;AAAA,EACrB;AAAA,EACA,cAAc;AAAA,EACd;AAAA,EACA,QAAQ;AACV,GAAyB;AACvB,QAAM,wBAAwB,OAAO,kBAAkB;AACvD,wBAAsB,UAAU;AAEhC,QAAM,uBAAuB,OAAO,iBAAiB;AACrD,uBAAqB,UAAU;AAE/B,QAAM,cAAc,OAAO,QAAQ;AACnC,cAAY,UAAU;AAEtB,QAAM,eAAe,OAAO,SAAS;AACrC,eAAa,UAAU;AAEvB,QAAM,uBAAuB,OAAO,iBAAiB;AACrD,uBAAqB,UAAU;AAE/B,QAAM,yBAAyB,OAAO,mBAAmB;AACzD,yBAAuB,UAAU;AAEjC,QAAM,qBAAqB,OAAO,eAAe;AACjD,qBAAmB,UAAU;AAE7B,QAAM,iBAAiB,OAAO,WAAW;AACzC,iBAAe,UAAU;AAEzB,QAAM,iBAAiB,OAAO,WAA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aACE,gBAAAA;AAAA,QAAC;AAAA;AAAA,UAEC,SAAS,MAAM,kBAAkB,MAAM,KAAK;AAAA,UAC5C,WAAU;AAAA,UACV,OAAO,aAAa,MAAM,KAAK;AAAA,UAE9B,cAAI,MAAM,KAAK;AAAA;AAAA,QALX;AAAA,MAMP;AAAA,IAEJ;AAEA,QAAI,MAAM,SAAS,eAAe;AAChC,aACE,gBAAAA;AAAA,QAAC;AAAA;AAAA,UAEC,WAAU;AAAA,UACV,OAAO,gBAAgB,MAAM,KAAK;AAAA,UAEjC,eAAK,MAAM,KAAK;AAAA;AAAA,QAJZ;AAAA,MAKP;AAAA,IAEJ;AAEA,WAAO,gBAAAA,KAAC,UAAkB,gBAAM,SAAd,KAAoB;AAAA,EACxC,CAAC,GACH;AAEJ;","names":["useEditor","jsx","useMemo","jsx"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pixerate/editor-react",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "React bindings and prompt/rich-text components for @pixerate/editor",
|
|
5
|
+
"author": "Pixerate",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "./dist/index.cjs",
|
|
9
|
+
"module": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"require": "./dist/index.cjs"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@tiptap/core": "^2.11.5",
|
|
23
|
+
"@tiptap/extension-bubble-menu": "^2.11.5",
|
|
24
|
+
"@tiptap/extension-placeholder": "^2.11.5",
|
|
25
|
+
"@tiptap/pm": "^2.11.5",
|
|
26
|
+
"@tiptap/react": "^2.11.5",
|
|
27
|
+
"@tiptap/starter-kit": "^2.11.5",
|
|
28
|
+
"@pixerate/editor": "0.1.0"
|
|
29
|
+
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"react": ">=18.0.0",
|
|
32
|
+
"react-dom": ">=18.0.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@types/react": "^19.0.0",
|
|
36
|
+
"@types/react-dom": "^19.0.0",
|
|
37
|
+
"react": "^19.0.0",
|
|
38
|
+
"react-dom": "^19.0.0",
|
|
39
|
+
"tsup": "^8.4.0",
|
|
40
|
+
"typescript": "^5.7.3",
|
|
41
|
+
"vitest": "^3.0.5"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "tsup",
|
|
45
|
+
"typecheck": "tsc --noEmit",
|
|
46
|
+
"test": "vitest run"
|
|
47
|
+
}
|
|
48
|
+
}
|