Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions dev-notes/knowledge/editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@

调用链:`React (NoteEditor) → createEditor() → CM6 EditorView → ySync extension ↔ Y.Text`

### Plugin SDK (v0.1)

`@swarmnote/editor-core` v0.1 起以 plugin SDK 形式重构。8 个功能(math / table / mermaid / admonition / codeBlock / blockImage / rawHtml / smartPaste)**默认不启用**,宿主必须通过 `createEditor(..., { plugins: [...] })` 显式传入。

**关键约束**:
- Plugin 工厂从 subpath import:`@swarmnote/editor-core/plugins/<name>`,main 入口不再 re-export
- 宿主能力(resolveImage / uploadFile / openLink)通过 `host: EditorHostCapabilities` 注入;旧顶层 `imageResolver` / `uploadFile` 已 `@deprecated`(仍工作但会桥接)
- Plugin 启用状态在 `createEditor` 时 freeze,**切换 plugin 启用状态后必须新开文档 / 重启应用才能生效**
- `refreshBlockImagesEffect` 从 main 入口下架,改从 `@swarmnote/editor-core/plugins/blockImage` 拿
- `EditorFeatureToggles` 仅保留 5 个字段:`markdownHighlight` / `markdownDecorations` / `inlineRendering` / `search` / `collaboration`

**宿主侧 plugin 配置**:`src/stores/preferencesStore.ts::enabledPlugins` + `codeBlockMode` 持久化用户启用状态;`migrateLegacyFeatures` 防御性处理 v0.0.x 旧 `features.*` key(idempotent)。

**详见**:[dev-notes/plans/editor-plugin-architecture.md](../plans/editor-plugin-architecture.md)、`openspec/changes/add-editor-plugin-sdk-v01/`

- 编辑器内核:`@swarmnote/editor-core`(独立仓 [`swarm-apps/swarmnote-editor`](https://github.com/swarm-apps/swarmnote-editor),pnpm workspace monorepo),桌面端和移动端共享
- 桌面端 React 容器:`src/components/editor/NoteEditor.tsx`
- 文档大纲:`src/components/editor/DocumentOutline.tsx`(基于 `extractHeadings`)
Expand Down
2 changes: 2 additions & 0 deletions dev-notes/plans/editor-core-host-boundary.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Editor Core / Interaction / Host Boundary 清单

> **更新(2026-05-12)**:本文档下方"interaction core"是否单独成包的问题已在 [editor-plugin-architecture.md](./editor-plugin-architecture.md) 中闭环——**interaction 作为 first-party plugin 留在 `editor-core/plugins/interactions/`**,与第三方插件共用同一 `EditorPlugin` API。本文档其余分层归类仍有效。

## 目的

这份清单用于回答一个非常具体的问题:
Expand Down
5 changes: 4 additions & 1 deletion dev-notes/plans/editor-event-model-draft.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# EditorEventType 演进草案

> **更新(2026-05-12)**:v0.1 采纳本文提出的"三层分类"路线。最终类型形态、`MermaidZoomRequest` 归类、`SlashTriggerChange` / `WikiLinkTriggerChange` / `SelectionToolbarChange` 三个 interaction event 的 `@unstable` 标记,均已在 [editor-plugin-architecture.md #editor-event-三层分类-v01](./editor-plugin-architecture.md#editorevent-三层分类v01) 中收敛。本文档保留为推导过程。

## 目的

这份草案回答的问题是:
Expand Down Expand Up @@ -464,8 +466,9 @@ type SelectionPopoverAnchorEvent = {
| `SearchStateChange` | Core Event | 保留 |
| `CollaborationUpdate` | Core Event | 保留 |
| `LinkOpen` | Core Event | 保留 |
| `Remove` | Core Event / 待确认 | 需要确认长期定位 |
| `Remove` | Platform Convenience Event | 2026-05-12 定位:作为 platform convenience |
| `TableContextMenu` | Platform Convenience Event | 不建议当成核心协议代表 |
| `MermaidZoomRequest` | Platform Convenience Event | 2026-05-12 补:携带 `renderedSvg: string` HTML,Web 假设强,跨端不稳定 |

---

Expand Down
12 changes: 12 additions & 0 deletions dev-notes/plans/editor-extension-points-draft.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Editor Extension Points Draft

> ⚠️ **SUPERSEDED(2026-05-12)**
>
> 本文档抽象出的"六类扩展点"已被具体的 `EditorPluginContext` 接口取代。**最终架构请见 [editor-plugin-architecture.md](./editor-plugin-architecture.md)**。
>
> 主要变化:
>
> - 六类抽象 → `registerCommands` / `registerCmExtensions` / `registerMarkdownRenderer` / `host` (stable)+ `registerSlashItems` / `registerTrigger` / `on` (@unstable)的具体接口
> - "Phase A 应用内可扩展 → Phase B 包级扩展 → Phase C 运行时插件"路线 → 直接走 **Model B 全量**,内置 plugin 一步到位按 `EditorPlugin` 重写
> - "EditorHostCapabilities 草案"已 finalize 并写入 plugin architecture 文档
>
> 本文档保留为思考过程(thinking trail),不再作为最终架构来源。

## 目的

这份草案回答的问题是:
Expand Down
12 changes: 9 additions & 3 deletions dev-notes/plans/editor-open-source-rfc.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# RFC: 将 SwarmNote 编辑器重构为可开箱即用的开源 Markdown 编辑器

> **更新(2026-05-12)**:本 RFC 仍是顶层路线说明。具体的 plugin 架构、包边界、`EditorPluginContext` 形状、内置 plugin 清单与分阶段实施细节已在 [editor-plugin-architecture.md](./editor-plugin-architecture.md) 中收敛。下方"包结构建议"与"分阶段实施建议"两节按该决定对齐。

## 背景

当前 SwarmNote 编辑器已经具备一套比较完整的能力:
Expand Down Expand Up @@ -262,6 +264,8 @@ graph TD

## 包结构建议

> **2026-05-12 收敛**:v0.1 选择**单包 + subpath export** 路线——所有内置插件(math/table/mermaid 等)以 `@swarmnote/editor-core/plugins/<name>` 形式提供,未来抽成独立 npm 包仅需改 import 路径。`editor-react` / `editor-react-native` 仍作为后续 sibling 包推进。详见 [editor-plugin-architecture.md](./editor-plugin-architecture.md#subpath-export-策略)。

第一阶段不一定立即拆成独立仓库,但建议先按以下逻辑收敛目录边界。

### 候选结构
Expand Down Expand Up @@ -592,6 +596,8 @@ createEditor(parent, {

## 分阶段实施建议

> **2026-05-12 收敛**:原 Phase 1-5 描述偏边界整理路线;实际选择走 **Model B 全量 + 内置 plugin 全部重写** 的更激进路线。最终 Phase 表见 [editor-plugin-architecture.md 后续路线](./editor-plugin-architecture.md#后续路线均为无破坏性扩展)。本节保留为思考记录。

### Phase 1:清理边界

目标:先让 core / host / UI 的职责更干净。
Expand Down Expand Up @@ -674,9 +680,9 @@ createEditor(parent, {

## 开放问题

1. `packages/editor` 是否继续沿用 submodule 形式,还是在开源前迁移为独立 monorepo/workspace?
2. interaction core 是放进 `editor-core`,还是单独拆成 `editor-interactions`?
3. React Web 默认 UI 是否要内置一套官方工具栏/菜单,还是只提供 hooks 与 headless 状态?
1. ~~`packages/editor` 是否继续沿用 submodule 形式,还是在开源前迁移为独立 monorepo/workspace?~~ **已闭环**:迁移为 sibling 仓 `swarmnote-editor` 的 pnpm workspace monorepo(见 [README](../../../swarmnote-editor/README.md))。
2. ~~interaction core 是放进 `editor-core`,还是单独拆成 `editor-interactions`?~~ **已闭环(2026-05-12)**:作为 first-party plugin 留在 `editor-core/plugins/interactions/`,与第三方插件共用 `EditorPlugin` API。详见 [editor-plugin-architecture.md](./editor-plugin-architecture.md)。
3. React Web 默认 UI 是否要内置一套"官方工具栏/菜单",还是只提供 hooks 与 headless 状态?
4. RN 端是否需要与 Web 保持相同交互形态,还是只共享语义、不共享视觉表现?
5. collaboration 是否作为第一版开源能力公开,还是放到第二阶段?
6. 是否需要在第一版就提供受控(controlled)模式与非受控(uncontrolled)模式两套 API?
Expand Down
Loading
Loading