将 pageSteps/codeBlockState/dataSourceState 三套独立历史栈收敛为统一的 steps 结构 (按 stepType 分桶),并新增 registerStepType/setStepName/getStepName 支持自定义 扩展历史类型。同步重构 history 相关服务、组件、工具方法、测试与文档。
4.3 KiB
historyService事件
change
-
详情: 页面历史记录发生变化(
page类型push/undo/redo成功时触发;与code-block-history-change/data-source-history-change同构) -
事件回调函数:
(pageId: Id, step: StepValue) => void::: details 查看 StepValue 及关联类型定义 <<< @/../packages/editor/src/type.ts#StepValue{ts}
<<< @/../packages/editor/src/type.ts#BaseStepValue{ts}
<<< @/../packages/editor/src/type.ts#StepExtra{ts}
<<< @/../packages/editor/src/type.ts#HistoryOpType{ts}
<<< @/../packages/editor/src/type.ts#HistoryOpSource{ts}
<<< @/../packages/schema/src/index.ts#Id{ts}
<<< @/../packages/schema/src/index.ts#MNode{ts} :::
:::tip 回调签名已与其它历史类型统一为
(id, step)。当游标处于历史栈边界(已无法继续撤销 / 重做)时undo/redo返回null,此时不会触发该事件。 :::
marker-change
-
详情: 通过
setMarker为某个历史栈种入initial基线时触发(适用于所有类型) -
事件回调函数:
(id: Id, marker: StepValue, stepType: HistoryStepType) => void
clear
-
详情: 调用
clear清空历史栈时触发(适用于所有类型) -
事件回调函数:
(id: Id | undefined, stepType: HistoryStepType) => void:::tip
id缺省(清空stepType下全部栈)时回调的id为undefined。 :::
code-block-history-change
-
详情: 代码块历史记录发生变化(
push('codeBlock', step, codeBlockId)/undo('codeBlock', id)/redo('codeBlock', id)成功时触发) -
事件回调函数:
(codeBlockId: Id, step: CodeBlockStepValue) => void::: details 查看 CodeBlockStepValue 及关联类型定义 <<< @/../packages/editor/src/type.ts#CodeBlockStepValue{ts}
<<< @/../packages/editor/src/type.ts#BaseStepValue{ts}
<<< @/../packages/editor/src/type.ts#HistoryOpSource{ts}
<<< @/../packages/schema/src/index.ts#CodeBlockContent{ts}
<<< @/../packages/schema/src/index.ts#Id{ts} :::
:::tip
- 新增触发的 step 其 diff 项
oldSchema为null - 删除触发的 step 其 diff 项
newSchema为null undo/redo返回null(边界状态)时不会触发该事件 :::
- 新增触发的 step 其 diff 项
data-source-history-change
-
详情: 数据源历史记录发生变化(
push('dataSource', step, dataSourceId)/undo('dataSource', id)/redo('dataSource', id)成功时触发) -
事件回调函数:
(dataSourceId: Id, step: DataSourceStepValue) => void::: details 查看 DataSourceStepValue 及关联类型定义 <<< @/../packages/editor/src/type.ts#DataSourceStepValue{ts}
<<< @/../packages/editor/src/type.ts#BaseStepValue{ts}
<<< @/../packages/editor/src/type.ts#HistoryOpSource{ts}
<<< @/../packages/schema/src/index.ts#Id{ts} :::
:::tip
- 新增触发的 step 其 diff 项
oldSchema为null - 删除触发的 step 其 diff 项
newSchema为null undo/redo返回null(边界状态)时不会触发该事件 :::
- 新增触发的 step 其 diff 项
mark-saved
-
详情: 调用
markSaved标记「已保存」记录时触发 -
事件回调函数:
(payload: { kind: 'all' | HistoryStepType; id?: Id }) => void::: tip
markSaved(stepType)(缺省 id)触发时kind为all,无id(此时stepType不生效)markSaved(stepType, id)触发时kind为对应的stepType(page/codeBlock/dataSource/ 扩展),id为目标栈 id :::
save-to-indexed-db
-
详情:
saveToIndexedDB把历史记录写入本地 IndexedDB 成功时触发 -
事件回调函数:
(snapshot: PersistedHistoryState) => void::: details 查看 PersistedHistoryState 类型定义 <<< @/../packages/editor/src/type.ts#PersistedHistoryState{ts}
<<< @/../packages/editor/src/utils/undo-redo.ts#SerializedUndoRedo{ts} :::
restore-from-indexed-db
-
详情:
restoreFromIndexedDB从本地 IndexedDB 读取并重建历史记录成功时触发(找不到记录时不触发) -
事件回调函数:
(snapshot: PersistedHistoryState) => void::: details 查看 PersistedHistoryState 类型定义 <<< @/../packages/editor/src/type.ts#PersistedHistoryState{ts} :::