@bendyline/squisq-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/dist/index.d.ts +269 -0
- package/dist/index.js +3825 -0
- package/dist/index.js.map +1 -0
- package/package.json +72 -0
- package/src/EditorContext.tsx +251 -0
- package/src/EditorShell.tsx +139 -0
- package/src/PreviewPanel.tsx +562 -0
- package/src/RawEditor.tsx +151 -0
- package/src/StatusBar.tsx +48 -0
- package/src/TemplateAnnotation.ts +71 -0
- package/src/Toolbar.tsx +465 -0
- package/src/ViewSwitcher.tsx +46 -0
- package/src/WysiwygEditor.tsx +134 -0
- package/src/index.ts +58 -0
- package/src/styles/editor.css +594 -0
- package/src/tiptapBridge.ts +425 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { Doc } from '@bendyline/squisq/schemas';
|
|
4
|
+
import { MarkdownDocument } from '@bendyline/squisq/markdown';
|
|
5
|
+
import * as _tiptap_core from '@tiptap/core';
|
|
6
|
+
import { Editor } from '@tiptap/core';
|
|
7
|
+
import { editor } from 'monaco-editor';
|
|
8
|
+
import * as _tiptap_extension_heading from '@tiptap/extension-heading';
|
|
9
|
+
|
|
10
|
+
/** Monaco standalone code editor instance type */
|
|
11
|
+
type MonacoEditor = editor.IStandaloneCodeEditor;
|
|
12
|
+
type EditorView = 'raw' | 'wysiwyg' | 'preview';
|
|
13
|
+
type EditorTheme = 'light' | 'dark';
|
|
14
|
+
interface EditorState {
|
|
15
|
+
/** Raw markdown source string */
|
|
16
|
+
markdownSource: string;
|
|
17
|
+
/** Parsed markdown document (JSON DOM) */
|
|
18
|
+
markdownDoc: MarkdownDocument | null;
|
|
19
|
+
/** Generated Doc (block hierarchy) */
|
|
20
|
+
doc: Doc | null;
|
|
21
|
+
/** Currently active editor view */
|
|
22
|
+
activeView: EditorView;
|
|
23
|
+
/** Parse error, if any */
|
|
24
|
+
parseError: string | null;
|
|
25
|
+
/** Whether a parse is pending */
|
|
26
|
+
isParsing: boolean;
|
|
27
|
+
/** Current color theme */
|
|
28
|
+
theme: EditorTheme;
|
|
29
|
+
}
|
|
30
|
+
interface EditorActions {
|
|
31
|
+
/** Set markdown source and trigger re-parse */
|
|
32
|
+
setMarkdownSource: (source: string) => void;
|
|
33
|
+
/** Set markdown from a MarkdownDocument (e.g. from WYSIWYG) */
|
|
34
|
+
setMarkdownDoc: (doc: MarkdownDocument) => void;
|
|
35
|
+
/** Switch the active view */
|
|
36
|
+
setActiveView: (view: EditorView) => void;
|
|
37
|
+
/** Register / unregister the Tiptap editor instance (called by WysiwygEditor) */
|
|
38
|
+
setTiptapEditor: (editor: Editor | null) => void;
|
|
39
|
+
/** Register / unregister the Monaco editor instance (called by RawEditor) */
|
|
40
|
+
setMonacoEditor: (editor: MonacoEditor | null) => void;
|
|
41
|
+
/** Set the color theme */
|
|
42
|
+
setTheme: (theme: EditorTheme) => void;
|
|
43
|
+
}
|
|
44
|
+
interface EditorContextValue extends EditorState, EditorActions {
|
|
45
|
+
/** The live Tiptap editor instance (null when WYSIWYG is not mounted) */
|
|
46
|
+
tiptapEditor: Editor | null;
|
|
47
|
+
/** The live Monaco editor instance (null when Raw is not mounted) */
|
|
48
|
+
monacoEditor: MonacoEditor | null;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Hook to access the editor context. Must be used within an EditorProvider.
|
|
52
|
+
*/
|
|
53
|
+
declare function useEditorContext(): EditorContextValue;
|
|
54
|
+
interface EditorProviderProps {
|
|
55
|
+
/** Initial markdown content */
|
|
56
|
+
initialMarkdown?: string;
|
|
57
|
+
/** Initial active view */
|
|
58
|
+
initialView?: EditorView;
|
|
59
|
+
/** Article ID used when generating the Doc */
|
|
60
|
+
articleId?: string;
|
|
61
|
+
/** Color theme */
|
|
62
|
+
theme?: EditorTheme;
|
|
63
|
+
children: ReactNode;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Provides shared editor state to all child components.
|
|
67
|
+
* Automatically parses markdown and generates a Doc whenever the source changes.
|
|
68
|
+
*/
|
|
69
|
+
declare function EditorProvider({ initialMarkdown, initialView, articleId, theme: initialTheme, children, }: EditorProviderProps): react_jsx_runtime.JSX.Element;
|
|
70
|
+
|
|
71
|
+
interface EditorShellProps {
|
|
72
|
+
/** Initial markdown content */
|
|
73
|
+
initialMarkdown?: string;
|
|
74
|
+
/** Initial active view */
|
|
75
|
+
/** Initial active view (default: 'wysiwyg') */
|
|
76
|
+
initialView?: EditorView;
|
|
77
|
+
/** Article ID for Doc generation */
|
|
78
|
+
articleId?: string;
|
|
79
|
+
/** Base path for media URLs in preview */
|
|
80
|
+
basePath?: string;
|
|
81
|
+
/** Called when markdown source changes */
|
|
82
|
+
onChange?: (source: string) => void;
|
|
83
|
+
/** Color theme: 'light' or 'dark' (default: 'light') */
|
|
84
|
+
theme?: 'light' | 'dark';
|
|
85
|
+
/** Additional class name */
|
|
86
|
+
className?: string;
|
|
87
|
+
/** CSS height for the shell container (default: '100vh') */
|
|
88
|
+
height?: string;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Complete markdown editor shell with toolbar, view switcher, and three
|
|
92
|
+
* editing modes: Raw (Monaco), WYSIWYG (Tiptap), and Preview.
|
|
93
|
+
*/
|
|
94
|
+
declare function EditorShell({ initialMarkdown, initialView, articleId, basePath, onChange, theme, className, height, }: EditorShellProps): react_jsx_runtime.JSX.Element;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* RawEditor
|
|
98
|
+
*
|
|
99
|
+
* Monaco-based raw markdown editor. Provides full VS Code-like editing
|
|
100
|
+
* experience with syntax highlighting, minimap, and bracket matching.
|
|
101
|
+
* Syncs changes back to EditorContext on every keystroke (debounced).
|
|
102
|
+
*/
|
|
103
|
+
interface RawEditorProps {
|
|
104
|
+
/** Monaco editor theme (default: 'vs-dark') */
|
|
105
|
+
theme?: string;
|
|
106
|
+
/** Show minimap (default: false) */
|
|
107
|
+
minimap?: boolean;
|
|
108
|
+
/** Font size in pixels (default: 14) */
|
|
109
|
+
fontSize?: number;
|
|
110
|
+
/** Word wrap setting (default: 'on') */
|
|
111
|
+
wordWrap?: 'on' | 'off' | 'wordWrapColumn' | 'bounded';
|
|
112
|
+
/** Additional class name for the container */
|
|
113
|
+
className?: string;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Raw markdown editor using Monaco Editor.
|
|
117
|
+
* Binds to the shared EditorContext for source synchronization.
|
|
118
|
+
*/
|
|
119
|
+
declare function RawEditor({ theme, minimap, fontSize, wordWrap, className, }: RawEditorProps): react_jsx_runtime.JSX.Element;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* WysiwygEditor
|
|
123
|
+
*
|
|
124
|
+
* Tiptap-based rich text editor that provides a WYSIWYG editing experience
|
|
125
|
+
* for markdown content. Uses squisq's parseMarkdown/stringifyMarkdown for
|
|
126
|
+
* conversion rather than Tiptap's built-in HTML serialization, ensuring
|
|
127
|
+
* perfect fidelity with the markdown format.
|
|
128
|
+
*
|
|
129
|
+
* Includes extensions for GFM features: tables, task lists, strikethrough,
|
|
130
|
+
* and code blocks.
|
|
131
|
+
*/
|
|
132
|
+
interface WysiwygEditorProps {
|
|
133
|
+
/** Placeholder text when editor is empty */
|
|
134
|
+
placeholder?: string;
|
|
135
|
+
/** Additional class name for the container */
|
|
136
|
+
className?: string;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Rich WYSIWYG markdown editor built on Tiptap (ProseMirror).
|
|
140
|
+
* Binds to the shared EditorContext for source synchronization.
|
|
141
|
+
*/
|
|
142
|
+
declare function WysiwygEditor({ placeholder, className, }: WysiwygEditorProps): react_jsx_runtime.JSX.Element;
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* PreviewPanel
|
|
146
|
+
*
|
|
147
|
+
* Renders a live preview of the current markdown document as a slideshow
|
|
148
|
+
* using the DocPlayer component from @bendyline/squisq-react.
|
|
149
|
+
*
|
|
150
|
+
* The markdown-derived Doc (from markdownToDoc) contains hierarchical blocks
|
|
151
|
+
* with template names, heading text, and body content — but no audio or
|
|
152
|
+
* visual layers. This component bridges the gap by:
|
|
153
|
+
*
|
|
154
|
+
* 1. Flattening the block tree into a linear slide sequence
|
|
155
|
+
* 2. Converting each block into a TemplateBlock-compatible object
|
|
156
|
+
* (mapping heading text → title, templateOverrides → template fields)
|
|
157
|
+
* 3. Synthesizing a dummy audio segment so DocPlayer's timing works
|
|
158
|
+
* (the player enters fallback-timer mode when audio can't load)
|
|
159
|
+
* 4. Passing the prepared Doc to DocPlayer for SVG-based rendering
|
|
160
|
+
*/
|
|
161
|
+
interface PreviewPanelProps {
|
|
162
|
+
/** Base path for resolving media URLs in DocPlayer */
|
|
163
|
+
basePath?: string;
|
|
164
|
+
/** Additional class name for the container */
|
|
165
|
+
className?: string;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Live preview panel that renders the current document as a slideshow.
|
|
169
|
+
* Uses DocPlayer from @bendyline/squisq-react for SVG block rendering
|
|
170
|
+
* with template expansion, transitions, and playback controls.
|
|
171
|
+
*
|
|
172
|
+
* Includes a viewport format dropdown above the player. The default
|
|
173
|
+
* format can be hinted via YAML frontmatter `document-render-as:`.
|
|
174
|
+
*/
|
|
175
|
+
declare function PreviewPanel({ basePath, className }: PreviewPanelProps): react_jsx_runtime.JSX.Element;
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* ViewSwitcher
|
|
179
|
+
*
|
|
180
|
+
* Tab bar for switching between Raw, WYSIWYG, and Preview editor views.
|
|
181
|
+
*/
|
|
182
|
+
interface ViewSwitcherProps {
|
|
183
|
+
/** Additional class name */
|
|
184
|
+
className?: string;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Tab-style view switcher for the three editor modes.
|
|
188
|
+
*/
|
|
189
|
+
declare function ViewSwitcher({ className }: ViewSwitcherProps): react_jsx_runtime.JSX.Element;
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Toolbar
|
|
193
|
+
*
|
|
194
|
+
* Formatting toolbar that provides common markdown editing actions.
|
|
195
|
+
* In WYSIWYG mode, uses Tiptap's chain commands to toggle marks / set nodes.
|
|
196
|
+
* In Raw mode, appends markdown syntax at the cursor (or end of source).
|
|
197
|
+
* Hidden in Preview mode.
|
|
198
|
+
*/
|
|
199
|
+
interface ToolbarProps {
|
|
200
|
+
/** Additional class name */
|
|
201
|
+
className?: string;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Formatting toolbar.
|
|
205
|
+
* - WYSIWYG: calls Tiptap chain commands (toggleBold, etc.)
|
|
206
|
+
* - Raw: appends markdown syntax to the source
|
|
207
|
+
*/
|
|
208
|
+
declare function Toolbar({ className }: ToolbarProps): react_jsx_runtime.JSX.Element;
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* StatusBar
|
|
212
|
+
*
|
|
213
|
+
* Bottom status bar showing document statistics and parse status.
|
|
214
|
+
*/
|
|
215
|
+
interface StatusBarProps {
|
|
216
|
+
/** Additional class name */
|
|
217
|
+
className?: string;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Status bar displaying document statistics: character count, word count,
|
|
221
|
+
* block count, and parse/error status.
|
|
222
|
+
*/
|
|
223
|
+
declare function StatusBar({ className }: StatusBarProps): react_jsx_runtime.JSX.Element;
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Tiptap Bridge
|
|
227
|
+
*
|
|
228
|
+
* Conversion utilities between raw markdown source and Tiptap's JSON/HTML
|
|
229
|
+
* content format. Uses a lightweight HTML-based approach: we convert markdown
|
|
230
|
+
* to a simple HTML representation that Tiptap can consume, and parse
|
|
231
|
+
* Tiptap's HTML output back to markdown.
|
|
232
|
+
*
|
|
233
|
+
* This bridge preserves markdown semantics much better than going through
|
|
234
|
+
* Tiptap's native markdown extension, since we control the conversion
|
|
235
|
+
* using squisq's own parser.
|
|
236
|
+
*/
|
|
237
|
+
/**
|
|
238
|
+
* Convert raw markdown source to Tiptap-consumable HTML content.
|
|
239
|
+
* Uses a simple markdown-to-HTML conversion that maps cleanly to
|
|
240
|
+
* Tiptap's ProseMirror schema.
|
|
241
|
+
*/
|
|
242
|
+
declare function markdownToTiptap(markdown: string): string;
|
|
243
|
+
/**
|
|
244
|
+
* Convert Tiptap HTML output back to markdown source.
|
|
245
|
+
* Extracts semantic structure from HTML and produces clean markdown.
|
|
246
|
+
*/
|
|
247
|
+
declare function tiptapToMarkdown(html: string): string;
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* TemplateAnnotation — Tiptap Heading Extension
|
|
251
|
+
*
|
|
252
|
+
* Extends Tiptap's built-in Heading node to support `data-template` and
|
|
253
|
+
* `data-template-params` HTML attributes. These attributes store which block
|
|
254
|
+
* template should be used for a heading section.
|
|
255
|
+
*
|
|
256
|
+
* When present, the heading renders a visible badge (styled CSS chip)
|
|
257
|
+
* showing the template name, e.g. `[chart]`.
|
|
258
|
+
*
|
|
259
|
+
* The tiptapBridge converts `### Title {[chart]}` markdown into
|
|
260
|
+
* `<h3 data-template="chart">Title</h3>` and back, so this extension
|
|
261
|
+
* ensures Tiptap's schema preserves those attributes through edits.
|
|
262
|
+
*/
|
|
263
|
+
/**
|
|
264
|
+
* HeadingWithTemplate — drop-in replacement for Tiptap's Heading that
|
|
265
|
+
* persists template annotation attributes.
|
|
266
|
+
*/
|
|
267
|
+
declare const HeadingWithTemplate: _tiptap_core.Node<_tiptap_extension_heading.HeadingOptions, any>;
|
|
268
|
+
|
|
269
|
+
export { type EditorActions, type EditorContextValue, EditorProvider, type EditorProviderProps, EditorShell, type EditorShellProps, type EditorState, type EditorTheme, type EditorView, HeadingWithTemplate, PreviewPanel, type PreviewPanelProps, RawEditor, type RawEditorProps, StatusBar, type StatusBarProps, Toolbar, type ToolbarProps, ViewSwitcher, type ViewSwitcherProps, WysiwygEditor, type WysiwygEditorProps, markdownToTiptap, tiptapToMarkdown, useEditorContext };
|