@brett_lamy/docstream-editor 0.3.5 → 0.3.6
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 +4 -0
- package/package.json +1 -1
- package/src/editor/Editor.tsx +10 -0
package/README.md
CHANGED
|
@@ -73,11 +73,15 @@ export function EditorPage() {
|
|
|
73
73
|
export interface GitbookEditorProps {
|
|
74
74
|
markdown: string
|
|
75
75
|
onChange: (markdown: string) => void
|
|
76
|
+
onKeyDown?: (event: KeyboardEvent) => boolean
|
|
77
|
+
onPaste?: (event: ClipboardEvent) => boolean
|
|
76
78
|
}
|
|
77
79
|
```
|
|
78
80
|
|
|
79
81
|
- `markdown`: Source markdown to load into the editor.
|
|
80
82
|
- `onChange`: Called with serialized markdown whenever TipTap content changes.
|
|
83
|
+
- `onKeyDown` / `onPaste`: Optional host hooks that run before the built-in editor behavior;
|
|
84
|
+
return `true` when the application handled the event.
|
|
81
85
|
|
|
82
86
|
The editor tracks the last markdown it emitted so normal controlled updates do not continuously reset the TipTap document. Passing a different external `markdown` value replaces the editor content.
|
|
83
87
|
|
package/package.json
CHANGED
package/src/editor/Editor.tsx
CHANGED
|
@@ -39,6 +39,10 @@ export interface GitbookEditorProps {
|
|
|
39
39
|
disableHistory?: boolean
|
|
40
40
|
/** Extra TipTap extensions appended last (e.g. Collaboration, CollaborationCursor). */
|
|
41
41
|
extensions?: AnyExtension[]
|
|
42
|
+
/** Handle a key before the editor's built-in keymaps. Return true when handled. */
|
|
43
|
+
onKeyDown?: (event: KeyboardEvent) => boolean
|
|
44
|
+
/** Handle clipboard content before the editor's built-in paste behavior. Return true when handled. */
|
|
45
|
+
onPaste?: (event: ClipboardEvent) => boolean
|
|
42
46
|
/** Receive the underlying TipTap editor instance (and null on teardown). */
|
|
43
47
|
onEditorReady?: (editor: TiptapEditor | null) => void
|
|
44
48
|
}
|
|
@@ -114,6 +118,8 @@ export function GitbookEditor({
|
|
|
114
118
|
autofocus = false,
|
|
115
119
|
disableHistory,
|
|
116
120
|
extensions,
|
|
121
|
+
onKeyDown,
|
|
122
|
+
onPaste,
|
|
117
123
|
onEditorReady,
|
|
118
124
|
}: GitbookEditorProps) {
|
|
119
125
|
// Tracks the markdown the editor itself produced, so external updates
|
|
@@ -130,6 +136,10 @@ export function GitbookEditor({
|
|
|
130
136
|
...(disableHistory !== undefined ? { disableHistory } : {}),
|
|
131
137
|
...(extensions ? { extensions } : {}),
|
|
132
138
|
}),
|
|
139
|
+
editorProps: {
|
|
140
|
+
handleKeyDown: (_view, event) => onKeyDown?.(event) ?? false,
|
|
141
|
+
handlePaste: (_view, event) => onPaste?.(event) ?? false,
|
|
142
|
+
},
|
|
133
143
|
...(controlled ? { content: astToTiptap(parseMarkdown(markdown as string)) } : {}),
|
|
134
144
|
onUpdate({ editor }) {
|
|
135
145
|
if (!onChange) return
|