@bendyline/squisq-editor-react

中文文档
2.13.21发布于 2026/11/08MITTypeScriptES Module构建来源已验证近 30 天下载 6507

React editor shell with raw/WYSIWYG/preview modes for Squisq documents

原始使用文档
文档目录10 节
  1. Install
  2. Quick Start
  3. Editor Views
  4. Components
  5. Notable EditorShell features
  6. Context API
  7. Styles
  8. Full API Reference
  9. Related Packages
  10. License

@bendyline/squisq-editor-react

React editor shell for Squisq documents with three integrated views: a Monaco-powered raw Markdown editor, a Tiptap WYSIWYG rich text editor, and a live block preview. Switching between views keeps the document in sync automatically.

Part of the Squisq monorepo.

npm MIT License

Install

npm install @bendyline/squisq-editor-react @bendyline/squisq @bendyline/squisq-react monaco-editor

Peer dependencies: react and react-dom (v18 or v19), plus monaco-editor (~0.50.0). Monaco is loaded lazily at runtime, but it is a required peer because the package's public TypeScript declarations expose Monaco editor types. Tiptap is bundled as a regular dependency — you don't need to install it yourself.

Quick Start

import { EditorShell } from '@bendyline/squisq-editor-react';
import '@bendyline/squisq-editor-react/styles';

function App() {
  return <EditorShell initialMarkdown="# Hello World" />;
}

Editor Views

ViewPowered ByDescription
RawMonaco EditorFull Markdown source editing with syntax highlighting
WYSIWYGTiptapRich text editing with a formatting toolbar
PreviewDocPlayerLive rendered block preview with theme selection

Components

ComponentDescription
EditorShellTop-level editor — combines all three views with a view switcher
EditorProviderContext provider for editor state management
RawEditor / WysiwygEditor / PreviewPanelThe individual views, exported for custom layouts
JsonEditorEditable form for JSON values bound to a Squisq-annotated schema
ImageEditor / ImageViewerLayered raster authoring surface + read-only viewer
RecorderPanel / RecorderButton / RecorderModalBrowser audio/camera/screen recording (MediaRecorder)
FolderViewStandalone folder browser surface

Beyond components, the package also exports Tiptap extensions for authored ASCII diagrams, trees, and timelines. Timeline fences become a shared-scale rail canvas in WYSIWYG mode: click the line or a keyboard-accessible Add button to add a point, select any dot to edit its label/callout, and keep multiple tracks and branches visible. Every safe edit is written back as regenerated, verified fence text, so Raw Markdown stays the source of truth; visual mutation pauses if unmodeled source would be lost. The package also exports heading template annotations, the markdown ↔ Tiptap bridge (markdownToTiptap / tiptapToMarkdown), drag-and-drop helpers (useFileDrop, processMediaFiles), file-kind detection (resolveFileKind), and block-at-a-time / timeline editing primitives (useBlockNavigator, BlockCardView, TimelineTrack).

Notable EditorShell features

  • Versioning — pass allowVersioning + workspaceContainer to auto-save snapshots on idle (versioningAutoSaveIdleMs, default 5000ms) with pruning (versioningPrunePolicy, default keep-last-50); a Version History panel appears in the toolbar.
  • Recording — with a mediaProvider wired, a record button appears in the toolbar (allowRecording, default true). Screen capture exposes What to record above Advanced settings: a surface preference, a screen/window picker action, and whole-surface or coordinate-region capture. Coordinates are pixels relative to the chosen surface's top-left; the live preview and encoded video use the same crop, leaving audio unchanged. Invalid or out-of-bounds regions fail visibly and release capture. Region recording uses a canvas at 30 fps; shrinking a window past the region or stopping screen sharing ends the take. The browser or host still owns the source picker and available surface types. The recorder's Advanced device settings expando discovers microphones/cameras, shows only capture constraints advertised by the browser, separates camera and screen constraints for dual recordings, and exposes MediaRecorder codec, bitrate, and keyframe hints. Preferred constraints use the closest available setting; Required microphone/camera constraints fail when the selected input cannot satisfy them (screen settings remain preferences, as required by getDisplayMedia).
  • Presentation mode — every Use view can fill the Squisq control, open a synchronized audience window, or take over the entire screen. Slideshow/video playback, Page/Document scrolling, and the Narrate surface remain linked to the main view.
  • Flashcards mode — the Use menu can project the original nested block tree as progressively revealed study cards and multiple-choice quizzes. Ordinary headings are inferred automatically; {study=flashcard} disambiguates a card boundary and {study=multiple-choice-flashcard} makes child one the question, child two the default correct answer, and remaining children distractors.
  • Panels — outline (heading outline pane) and inlinePreview (per-block SVG preview gutter, inlinePreviewWidth default 320). Block previews include ordinary sections and heading-less introductory text; template tags are optional. Below ~720px, where those panes hide, the navigation sheet stands in: a popover from the right edge with Outline and Block previews tabs. On touch, swipe in from the right edge for the outline, or turn the swipe downward for previews; choosing a section closes it. Control it with navigationSheet / onNavigationSheetChange to close it from host input such as a Back button.
  • Code & image modes — pass fileName / language to get a Monaco-only code editor, or imageSrc (+ imageMode: 'edit') for the image surface. .jsonc files, language="jsonc", and fenced jsonc snippets use JSON highlighting with line and block comment support.
  • Host-triggered Find mode — control findMode and onFindModeChange (or call setFindMode from context) to replace the toolbar's editing actions with live search, Match case / Whole word, previous/next navigation, highlighted matches, and Replace / Replace all in editable documents. findRequest opens Find at a given query and match; findShortcut opts in to Ctrl/Cmd+F and Ctrl+H (Cmd+Option+F on Apple). No Find trigger button is added unless the host supplies one.
  • Embedding — readOnly, placeholder, submitOnEnter, fullWidth, thinMargins, minHeight/maxHeight auto-grow for chat-composer use, plus host-controlled Write typography through writeCanvasSettings (textSize and lineSpacing). Set hostMode="chat" to keep the shell in Write view, remove its view tabs, and hide Custom layouts, Transform, View options, and Document settings. showCodeCopyButton opts Document/Page previews into a subtle fenced-code Copy control; use onCopyCode to bridge clipboard writes in Electron or native hosts (browser hosts fall back to navigator.clipboard.writeText).
  • Color scheme — pass colorScheme="light" | "dark" for the editor chrome (v1.5: renamed from the old theme prop; RawEditor's own theme prop is now monacoTheme).

Also exported (v1.5): useMonacoLoader (share the load-once Monaco bootstrap), and the custom theme / template provider stacks — CustomThemeProvider / useCustomThemes / useDocCustomThemes and CustomTemplateProvider / useCustomTemplates / useDocCustomTemplates.

Context API

Use useEditorContext() to access editor state and actions from child components. The context value is flat — state fields and action methods live side by side:

import { useEditorContext } from '@bendyline/squisq-editor-react';

function MyComponent() {
  const { markdownSource, doc, activeView, setMarkdownSource, setActiveView, setFindMode } =
    useEditorContext();
  // markdownSource: string, doc: Doc | null, activeView: 'raw' | 'wysiwyg' | 'preview'
}

Styles

Import the editor CSS:

import '@bendyline/squisq-editor-react/styles';

Full API Reference

See docs/API.md for the complete EditorShellProps reference, context API, and every exported component, hook, and helper.

PackageDescription
@bendyline/squisqHeadless core — schemas, templates, spatial, markdown, storage
@bendyline/squisq-reactReact components for rendering docs
@bendyline/squisq-formatsDOCX, PDF, HTML import/export

License

MIT

版本与发布记录

@bendyline/squisq-editor-react 共发布 109 个版本,首次发布于 2026/03/16;过去 12 个月发布了 109 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.13.21latest2026/11/08今天
2.13.202026/11/07今天
2.13.192026/11/052 天前
2.13.182026/11/053 天前
2.13.172026/11/035 天前
2.13.162026/11/017 天前

关于 @bendyline/squisq-editor-react 的常见问题

@bendyline/squisq-editor-react 是什么?

React editor shell with raw/WYSIWYG/preview modes for Squisq documents

如何安装 @bendyline/squisq-editor-react?

在项目目录运行 npm install @bendyline/squisq-editor-react,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^18.0.0 || ^19.0.0)、react-dom(^18.0.0 || ^19.0.0)、monaco-editor(~0.50.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@bendyline/squisq-editor-react 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@bendyline/squisq-editor-react 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@bendyline/squisq-editor-react 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js ^22.22.2 || ^24.15.0 || >=26.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@bendyline/squisq-editor-react 可以商用吗?

@bendyline/squisq-editor-react 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@bendyline/squisq-editor-react 的下载量有多少?

根据 npm 官方下载统计,@bendyline/squisq-editor-react 在 2026/10/08 – 2026/11/06 这 30 天内被下载 6,507 次,日均约 217 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@bendyline/squisq-editor-react 还在维护吗?

最新版本 2.13.21 发布于 2026/11/08(今天);至今共发布 109 个版本,其中过去 12 个月发布了 109 个;首次发布于 2026/03/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。