{"version":3,"sources":["jsdelivr-header.js","/npm/@flowgram.ai/history@1.0.3/src/index.ts","/npm/@flowgram.ai/history@1.0.3/src/operation/operation-contribution.ts","/npm/@flowgram.ai/history@1.0.3/src/operation/operation-registry.ts","/npm/@flowgram.ai/history@1.0.3/src/operation/operation-service.ts","/npm/@flowgram.ai/history@1.0.3/src/history-context.ts","/npm/@flowgram.ai/history@1.0.3/src/history-config.ts","/npm/@flowgram.ai/history@1.0.3/src/history/undo-redo-service.ts","/npm/@flowgram.ai/history@1.0.3/src/history/types.ts","/npm/@flowgram.ai/history@1.0.3/src/history/history-service.ts","/npm/@flowgram.ai/history@1.0.3/src/history/stack-operation.ts","/npm/@flowgram.ai/history@1.0.3/src/history/history-manager.ts","/npm/@flowgram.ai/history@1.0.3/src/history/history-stack.ts","/npm/@flowgram.ai/history@1.0.3/src/history-container-module.ts","/npm/@flowgram.ai/history@1.0.3/src/create-history-plugin.ts"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,qtBCNA,cAAA,GAAA,SAAA,cAAA,CAAA,cAAA,IAAA,cAAA,uBAAA,IAAA,uBAAA,eAAA,IAAA,eAAA,eAAA,IAAA,eAAA,sBAAA,IAAA,sBAAA,eAAA,IAAA,eAAA,aAAA,IAAA,aAAA,uBAAA,IAAA,uBAAA,sBAAA,IAAA,sBAAA,kBAAA,IAAA,kBAAA,iBAAA,IAAA,iBAAA,eAAA,IAAA,eAAA,mBAAA,IAAA,mBAAA,gBAAA,IAAA,gBAAA,oBAAA,IAAA,sBAAA,OAAA,QAAA,aAAA,eCOO,IAAM,sBAAwB,OAAO,yBCF5C,iBAAiE,QAAA,aACjE,aAAiD,QAAA,sBAMpC,kBAAN,iBAAA,GACL,KAAiB,gBAA8C,IAAI,IAInE,KAAmB,cAAyC,EAAC,CAGnD,IAAA,GACR,UAAW,KAAW,KAAK,cACzB,EAAQ,wBAAwB,KAEpC,CAOA,qBAAA,CAAsB,GACpB,GAAI,KAAK,gBAAgB,I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C3E,OAAQ,CAAC,EAAK,KACR,EAAK,SACP,EAAI,IAAI,kBAAkB,QAAQ,EAAK,QAAQ,KAAK,KAAM,GAC5D,EAEF,iBAAkB,CAAC","file":"/npm/@flowgram.ai/history@1.0.3/dist/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@flowgram.ai/history@1.0.3/dist/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nexport * from './operation';\nexport * from './history';\nexport * from './history-container-module';\nexport * from './create-history-plugin';\nexport * from './history-context';\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { OperationRegistry } from './operation-registry';\n\nexport const OperationContribution = Symbol('OperationContribution');\n\nexport interface OperationContribution {\n  registerOperationMeta?(operationRegistry: OperationRegistry): void;\n}\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { injectable, multiInject, optional, postConstruct } from 'inversify';\nimport { Disposable, DisposableCollection } from '@flowgram.ai/utils';\n\nimport { OperationMeta } from './types';\nimport { OperationContribution } from './operation-contribution';\n\n@injectable()\nexport class OperationRegistry {\n  private readonly _operationMetas: Map<string, OperationMeta> = new Map();\n\n  @multiInject(OperationContribution)\n  @optional()\n  protected readonly contributions: OperationContribution[] = [];\n\n  @postConstruct()\n  protected init() {\n    for (const contrib of this.contributions) {\n      contrib.registerOperationMeta?.(this);\n    }\n  }\n\n  /**\n   * 注册操作的元数据\n   * @param operationMeta 操作的元数据\n   * @returns 销毁函数\n   */\n  registerOperationMeta(operationMeta: OperationMeta): Disposable {\n    if (this._operationMetas.has(operationMeta.type)) {\n      console.warn(`A operation meta ${operationMeta.type} is already registered.`);\n      return Disposable.NULL;\n    }\n    const toDispose = new DisposableCollection(this._doRegisterOperationMetaMeta(operationMeta));\n    return toDispose;\n  }\n\n  /**\n   * 获取操作的元数据\n   * @param type 操作类型\n   * @returns 操作的元数据\n   */\n  getOperationMeta(type: string): OperationMeta | undefined {\n    return this._operationMetas.get(type);\n  }\n\n  private _doRegisterOperationMetaMeta(operationMeta: OperationMeta): Disposable {\n    this._operationMetas.set(operationMeta.type, operationMeta);\n    return {\n      dispose: () => {\n        this._operationMetas.delete(operationMeta.type);\n      },\n    };\n  }\n}\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { injectable, inject, postConstruct } from 'inversify';\nimport { DisposableCollection, Emitter } from '@flowgram.ai/utils';\n\nimport { HistoryContext } from '../history-context';\nimport { HistoryConfig } from '../history-config';\nimport { Operation } from './types';\nimport { OperationRegistry } from './operation-registry';\n\n@injectable()\nexport class OperationService {\n  @inject(OperationRegistry)\n  readonly operationRegistry: OperationRegistry;\n\n  @inject(HistoryContext)\n  readonly context: HistoryContext;\n\n  @inject(HistoryConfig)\n  config: HistoryConfig;\n\n  readonly applyEmitter = new Emitter<Operation>();\n\n  readonly onApply = this.applyEmitter.event;\n\n  private _toDispose = new DisposableCollection();\n\n  @postConstruct()\n  init() {\n    this._toDispose.push(this.applyEmitter);\n  }\n\n  /**\n   * 执行操作\n   * @param op\n   * @returns\n   */\n  applyOperation(op: Operation, options?: { noApply?: boolean }): any {\n    const meta = this.operationRegistry.getOperationMeta(op.type);\n\n    if (!meta) {\n      throw new Error(`Operation meta ${op.type} has not registered.`);\n    }\n\n    let res;\n    if (!options?.noApply) {\n      res = meta.apply(op, this.context.source);\n    }\n\n    this.applyEmitter.fire(op);\n\n    return res;\n  }\n\n  /**\n   * 根据操作类型获取操作的label\n   * @param operation 操作\n   * @returns\n   */\n  getOperationLabel(operation: Operation): string | undefined {\n    const operationMeta = this.operationRegistry.getOperationMeta(operation.type);\n\n    if (operationMeta && operationMeta.getLabel) {\n      return operationMeta.getLabel(operation, this.context.source);\n    }\n  }\n\n  /**\n   * 根据操作类型获取操作的description\n   * @param operation 操作\n   * @returns\n   */\n  getOperationDescription(operation: Operation): string | undefined {\n    const operationMeta = this.operationRegistry.getOperationMeta(operation.type);\n\n    if (operationMeta && operationMeta.getDescription) {\n      return operationMeta.getDescription(operation, this.context.source);\n    }\n  }\n\n  /**\n   * 操作取反\n   * @param operations\n   * @returns\n   */\n  inverseOperations(operations: Operation[]) {\n    return operations.map(op => this.inverseOperation(op)).reverse();\n  }\n\n  inverseOperation(op: Operation): Operation {\n    const meta = this.operationRegistry.getOperationMeta(op.type);\n\n    if (!meta) {\n      throw new Error(`Operation meta ${op.type} has not registered.`);\n    }\n    return meta.inverse(op);\n  }\n\n  dispose() {\n    this._toDispose.dispose();\n  }\n}\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { injectable } from 'inversify';\n\n@injectable()\nexport class HistoryContext {\n  /**\n   * 所属uri\n   */\n  uri?: string;\n\n  /**\n   * 操作触发的源对象，如编辑器对象\n   */\n  source?: unknown;\n}\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { nanoid } from 'nanoid';\nimport { injectable } from 'inversify';\n\n@injectable()\nexport class HistoryConfig {\n  generateId: () => string = () => nanoid();\n\n  getSnapshot: () => unknown = () => '';\n}\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { injectable } from 'inversify';\nimport { Emitter, DisposableCollection } from '@flowgram.ai/utils';\n\nimport {\n  IUndoRedoElement,\n  IUndoRedoService,\n  UndoRedoChangeType,\n  UndoRedoChangeEvent,\n  UndoRedoClearEvent,\n} from './types';\n\n@injectable()\nexport class UndoRedoService implements IUndoRedoService {\n  private _undoStack: IUndoRedoElement[];\n\n  private _redoStack: IUndoRedoElement[];\n\n  private _undoing: boolean = false;\n\n  private _redoing: boolean = false;\n\n  private _limit: number = 100;\n\n  protected onChangeEmitter = new Emitter<UndoRedoChangeEvent>();\n\n  readonly onChange = this.onChangeEmitter.event;\n\n  readonly _toDispose = new DisposableCollection();\n\n  constructor() {\n    this._undoStack = [];\n    this._redoStack = [];\n    this._toDispose.push(this.onChangeEmitter);\n  }\n\n  setLimit(limit: number) {\n    this._limit = limit;\n  }\n\n  pushElement(element: IUndoRedoElement): void {\n    this._redoStack = [];\n    this._stackPush(this._undoStack, element);\n    this._toDispose.push(element);\n    this._emitChange(UndoRedoChangeType.PUSH, element);\n  }\n\n  getUndoStack() {\n    return this._undoStack;\n  }\n\n  getRedoStack() {\n    return this._redoStack;\n  }\n\n  getLastElement() {\n    return this._undoStack[this._undoStack.length - 1];\n  }\n\n  /**\n   * 执行undo\n   * @returns void\n   */\n  async undo(): Promise<void> {\n    if (!this.canUndo()) {\n      return;\n    }\n\n    if (this._undoing) {\n      return;\n    }\n    this._undoing = true;\n\n    const item = this._undoStack.pop() as IUndoRedoElement;\n\n    try {\n      await item.undo();\n    } finally {\n      this._stackPush(this._redoStack, item);\n      this._emitChange(UndoRedoChangeType.UNDO, item);\n      this._undoing = false;\n    }\n  }\n\n  /**\n   * 执行redo\n   * @returns void\n   */\n  async redo(): Promise<void> {\n    if (!this.canRedo()) {\n      return;\n    }\n\n    if (this._redoing) {\n      return;\n    }\n    this._redoing = true;\n\n    const item = this._redoStack.pop() as IUndoRedoElement;\n\n    try {\n      await item.redo();\n    } finally {\n      this._stackPush(this._undoStack, item);\n      this._emitChange(UndoRedoChangeType.REDO, item);\n      this._redoing = false;\n    }\n  }\n\n  /**\n   * 是否可undo\n   * @returns true代表可以，false代表不可以\n   */\n  canUndo(): boolean {\n    return this._undoStack.length > 0;\n  }\n\n  /**\n   * 是否可redo\n   * @returns true代表可以，false代表不可以\n   */\n  canRedo(): boolean {\n    return this._redoStack.length > 0;\n  }\n\n  /**\n   * 是否可以push\n   * @returns true代表可以，false代表不可以\n   */\n  canPush(): boolean {\n    return !this._redoing && !this._undoing;\n  }\n\n  /**\n   * 清空\n   */\n  clear() {\n    this.clearRedoStack();\n    this.clearUndoStack();\n    this._emitChange(UndoRedoChangeType.CLEAR);\n  }\n\n  /**\n   * 清空redo栈\n   */\n  clearRedoStack(): void {\n    this._redoStack.forEach(element => {\n      element.dispose();\n    });\n    this._redoStack = [];\n  }\n\n  /**\n   * 清空undo栈\n   */\n  clearUndoStack(): void {\n    this._undoStack.forEach(element => {\n      element.dispose();\n    });\n    this._undoStack = [];\n  }\n\n  /**\n   * 销毁\n   */\n  dispose(): void {\n    this.clear();\n    this._toDispose.dispose();\n  }\n\n  private _stackPush(stack: IUndoRedoElement[], element: IUndoRedoElement) {\n    stack.push(element);\n    if (stack.length > this._limit) {\n      stack.shift();\n    }\n  }\n\n  private _emitChange(type: UndoRedoChangeType, element?: IUndoRedoElement) {\n    if (element) {\n      this.onChangeEmitter.fire({ type, element });\n    } else {\n      this.onChangeEmitter.fire({ type } as UndoRedoClearEvent);\n    }\n  }\n}\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { Disposable } from '@flowgram.ai/utils';\n\nimport { HistoryOperation, Operation } from '../operation';\nimport { HistoryService } from './history-service';\n\nexport interface HistoryRecord {\n  snapshot: any;\n  stack: any[];\n}\n\nexport interface HistoryItem extends HistoryStackItem {\n  id: string;\n  time: string;\n  operations: HistoryOperation[];\n}\n\n/**\n * 历史服务管理\n */\nexport interface IHistoryManager {\n  /**\n   * 注册历史服务\n   * @param service 历史服务示例\n   */\n  registerHistoryService(service: IHistoryService): void;\n  /**\n   * 取消注册历史服务\n   * @param service 历史服务示例\n   */\n  unregisterHistoryService(service: HistoryService): void;\n}\n\n/**\n * 历史服务\n */\nexport interface IHistoryService extends Disposable {\n  /**\n   * 添加操作\n   * @param operation 操作\n   */\n  pushOperation(operation: Operation): void | Promise<void>;\n  /**\n   * 获取所有历史操作\n   */\n  getHistoryOperations(): Operation[];\n  /**\n   * 撤回\n   */\n  undo(): void | Promise<void>;\n  /**\n   * 重做\n   */\n  redo(): void | Promise<void>;\n  /**\n   * 是否有可撤销的操作\n   */\n  canUndo(): boolean;\n  /**\n   * 是否有可重做的操作\n   */\n  canRedo(): boolean;\n  /**\n   * 获取历史记录\n   */\n  getRecords(): Promise<HistoryRecord[]>;\n  /**\n   * 根据历史版本重新存储历史记录\n   * @param historyRecord 历史记录\n   */\n  restore(historyRecord: HistoryRecord): Promise<void>;\n  /**\n   * 清空undo/redo\n   */\n  clear(): void;\n  /**\n   * 最大数量限制\n   * @param num 数量\n   */\n  limit(num: number): void;\n  /**\n   * 返回快照\n   */\n  getSnapshot(): unknown;\n}\n\nexport interface IOperationService {\n  pushOperation(operation: Operation): void;\n}\n\n/**\n * UndoRedo服务\n */\nexport interface IUndoRedoService extends Disposable {\n  /**\n   * 添加一个undo/redo元素\n   * @param element 可undo/redo的元素\n   */\n  pushElement(element: IUndoRedoElement): void;\n  /**\n   * 获取最后一个可undo的元素\n   */\n  getLastElement(): IUndoRedoElement;\n  /**\n   * 获取undo栈\n   */\n  getUndoStack(): IUndoRedoElement[];\n  /**\n   * 获取redo栈\n   */\n  getRedoStack(): IUndoRedoElement[];\n  /**\n   * 清空redo栈\n   */\n  clearRedoStack(): void;\n  /**\n   * 是否可undo\n   */\n  canUndo(): boolean;\n  /**\n   * 执行undo\n   */\n  undo(): Promise<void> | void;\n  /**\n   * 是否可redo\n   */\n  canRedo(): boolean;\n  /**\n   * 执行redo\n   */\n  redo(): Promise<void> | void;\n  /**\n   * 清空 undo和redo栈\n   */\n  clear(): void;\n}\n\n/**\n * UndoRedo元素\n */\nexport interface IUndoRedoElement extends Disposable {\n  /**\n   * 操作标题\n   */\n  readonly label?: string;\n  /**\n   * 操作描述\n   */\n  readonly description?: string;\n  /**\n   * 撤销\n   */\n  undo(): Promise<void> | void;\n  /**\n   * 重做\n   */\n  redo(): Promise<void> | void;\n  /**\n   * 添加一个操作\n   * @param operation 操作\n   */\n  pushOperation(operation: Operation): Operation;\n  /**\n   * 获取所有操作\n   */\n  getOperations(): Operation[];\n  /**\n   * 获取第一个操作\n   */\n  getFirstOperation(): Operation;\n  /**\n   * 获取最后一个操作\n   */\n  getLastOperation(): Operation;\n  /**\n   * 获取修改的操作\n   */\n  getChangeOperations(type: UndoRedoChangeType): Operation[];\n}\n\n/**\n * 操作注册\n */\nexport interface IOperationRegistry {\n  register(type: string, factory: IUndoRedoElementFactory<unknown>): void;\n}\n\n/**\n * 操作工厂\n */\nexport type IUndoRedoElementFactory<OperationValue> = (\n  operation: Operation<OperationValue>\n) => IUndoRedoElement;\n\n/**\n * undo redo 类型\n */\nexport enum UndoRedoChangeType {\n  UNDO = 'undo',\n  REDO = 'redo',\n  PUSH = 'push',\n  CLEAR = 'clear',\n}\n\n/**\n * 带element的事件\n */\nexport interface UndoRedoChangeElementEvent {\n  type: UndoRedoChangeType.PUSH | UndoRedoChangeType.UNDO | UndoRedoChangeType.REDO;\n  element: IUndoRedoElement;\n}\n/**\n * 清空事件\n */\nexport interface UndoRedoClearEvent {\n  type: UndoRedoChangeType.CLEAR;\n}\n/**\n * undo redo变化事件\n */\nexport type UndoRedoChangeEvent = UndoRedoChangeElementEvent | UndoRedoClearEvent;\n\nexport interface HistoryStackItem {\n  id: string;\n  type: UndoRedoChangeType;\n  timestamp: number;\n  operations: Operation[];\n  uri?: string;\n}\n\n/**\n * 历史栈变化类型\n */\nexport enum HistoryStackChangeType {\n  ADD = 'add',\n  UPDATE = 'update',\n  CLEAR = 'clear',\n  ADD_OPERATION = 'add_operation',\n  UPDATE_OPERATION = 'update_operation',\n}\n\n/**\n * 历史栈变化事件基础\n */\nexport interface HistoryStackBaseEvent {\n  type: HistoryStackChangeType;\n  value?: any;\n  service: HistoryService;\n}\n\n/**\n * 添加历史事件\n */\nexport interface HistoryStackAddEvent extends HistoryStackBaseEvent {\n  type: HistoryStackChangeType.ADD;\n  value: HistoryItem;\n}\n\n/**\n * 更新历史事件\n */\nexport interface HistoryStackUpdateEvent extends HistoryStackBaseEvent {\n  type: HistoryStackChangeType.UPDATE;\n  value: HistoryItem;\n}\n\n/**\n * 添加操作事件\n */\nexport interface HistoryStackAddOperationEvent extends HistoryStackBaseEvent {\n  type: HistoryStackChangeType.ADD_OPERATION;\n  value: {\n    historyItem: HistoryItem;\n    operation: HistoryOperation;\n  };\n}\n\n/**\n * 更新操作事件\n */\nexport interface HistoryStackUpdateOperationEvent extends HistoryStackBaseEvent {\n  type: HistoryStackChangeType.UPDATE_OPERATION;\n  value: {\n    historyItem: HistoryItem;\n    operation: HistoryOperation;\n  };\n}\n\n/**\n * 历史记录变化事件\n */\nexport type HistoryStackChangeEvent =\n  | HistoryStackAddEvent\n  | HistoryStackUpdateEvent\n  | HistoryStackAddOperationEvent\n  | HistoryStackUpdateOperationEvent;\n\nexport enum HistoryMergeEventType {\n  ADD = 'ADD',\n  UPDATE = 'UPDATE',\n}\n\n/**\n * 历史合并事件\n */\nexport type HistoryMergeEvent =\n  | {\n      type: HistoryMergeEventType.ADD;\n      value: {\n        element: IUndoRedoElement;\n        operation: Operation;\n      };\n    }\n  | {\n      type: HistoryMergeEventType.UPDATE;\n      value: {\n        element: IUndoRedoElement;\n        operation: Operation;\n        value: any;\n      };\n    };\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { pick } from 'lodash-es';\nimport { injectable, inject, postConstruct } from 'inversify';\nimport { DisposableCollection, Emitter } from '@flowgram.ai/utils';\n\nimport { OperationService } from '../operation/operation-service';\nimport { OperationMeta, OperationRegistry, PushOperationOptions } from '../operation';\nimport { Operation } from '../operation';\nimport { HistoryContext } from '../history-context';\nimport { HistoryConfig } from '../history-config';\nimport { UndoRedoService } from './undo-redo-service';\nimport {\n  HistoryMergeEvent,\n  HistoryMergeEventType,\n  HistoryRecord,\n  IHistoryService,\n  IUndoRedoElement,\n} from './types';\nimport { StackOperation } from './stack-operation';\nimport { HistoryManager } from './history-manager';\n\n@injectable()\nexport class HistoryService implements IHistoryService {\n  @inject(UndoRedoService)\n  readonly undoRedoService: UndoRedoService;\n\n  @inject(OperationRegistry)\n  readonly operationRegistry: OperationRegistry;\n\n  @inject(OperationService)\n  readonly operationService: OperationService;\n\n  @inject(HistoryContext)\n  readonly context: HistoryContext;\n\n  @inject(HistoryConfig)\n  readonly config: HistoryConfig;\n\n  @inject(HistoryManager)\n  historyManager: HistoryManager;\n\n  private _toDispose = new DisposableCollection();\n\n  private _transacting: boolean = false;\n\n  private _transactOperation: StackOperation | null = null;\n\n  private _locked: boolean = false;\n\n  private _willDisposeEmitter = new Emitter<HistoryService>();\n\n  private _mergeEmitter = new Emitter<HistoryMergeEvent>();\n\n  onWillDispose = this._willDisposeEmitter.event;\n\n  onMerge = this._mergeEmitter.event;\n\n  get onApply() {\n    return this.operationService.onApply;\n  }\n\n  @postConstruct()\n  init() {\n    this._toDispose.push(this._willDisposeEmitter);\n    this._toDispose.push(this._mergeEmitter);\n  }\n\n  start() {\n    this._locked = false;\n  }\n\n  stop() {\n    this._locked = true;\n  }\n\n  limit(num: number) {\n    this.undoRedoService.setLimit(num);\n  }\n\n  startTransaction() {\n    if (this._transacting) {\n      return;\n    }\n\n    this._transacting = true;\n    const stackOperation = new StackOperation(this.operationService, []);\n    this._transactOperation = stackOperation;\n  }\n\n  endTransaction() {\n    const stackOperation = this._transactOperation;\n    if (!stackOperation) {\n      return;\n    }\n    if (stackOperation.getOperations().length !== 0) {\n      this._pushStackOperation(stackOperation);\n    }\n\n    this._transactOperation = null;\n    this._transacting = false;\n  }\n\n  transact(transaction: () => void) {\n    if (this._transacting) {\n      return;\n    }\n    this.startTransaction();\n    transaction();\n    this.endTransaction();\n  }\n\n  pushOperation(operation: Operation, options?: PushOperationOptions): any {\n    if (!this._canPush()) {\n      return;\n    }\n\n    const prev = this._transactOperation || this.undoRedoService.getLastElement();\n    const operationMeta = this.operationRegistry.getOperationMeta(operation.type) as OperationMeta;\n\n    if (!operationMeta) {\n      throw new Error(`Operation meta ${operation.type} has not registered.`);\n    }\n\n    if (operationMeta.shouldSave && !operationMeta.shouldSave(operation)) {\n      return operationMeta.apply(operation, this.context.source);\n    }\n\n    const res = this.operationService.applyOperation(operation, { noApply: options?.noApply });\n\n    if (operationMeta.getURI && !operation.uri) {\n      operation.uri = operationMeta.getURI(operation, this.context.source);\n    }\n\n    const shouldMerge = this._shouldMerge(operation, prev, operationMeta);\n\n    if (shouldMerge) {\n      if (typeof shouldMerge === 'object') {\n        const operation = prev.getLastOperation();\n        operation.value = shouldMerge.value;\n        this._mergeEmitter.fire({\n          type: HistoryMergeEventType.UPDATE,\n          value: {\n            element: prev,\n            operation: operation,\n            value: shouldMerge.value,\n          },\n        });\n      } else {\n        const op = prev.pushOperation(operation);\n        this._mergeEmitter.fire({\n          type: HistoryMergeEventType.ADD,\n          value: {\n            element: prev,\n            operation: op,\n          },\n        });\n      }\n    } else {\n      const stackOperation = new StackOperation(this.operationService, [operation]);\n      this._pushStackOperation(stackOperation);\n    }\n\n    return res;\n  }\n\n  getHistoryOperations(): Operation<unknown>[] {\n    return this.historyManager.historyStack.items\n      .reverse()\n      .map((item) =>\n        item.operations.map((o) => ({\n          ...pick(o, ['type', 'value']),\n          label: o.label || o.type,\n        }))\n      )\n      .flat();\n  }\n\n  async undo(): Promise<void> {\n    await this.undoRedoService.undo();\n  }\n\n  async redo(): Promise<void> {\n    await this.undoRedoService.redo();\n  }\n\n  canUndo(): boolean {\n    return this.undoRedoService.canUndo();\n  }\n\n  canRedo(): boolean {\n    return this.undoRedoService.canRedo();\n  }\n\n  getSnapshot(): unknown {\n    return this.config.getSnapshot();\n  }\n\n  getRecords(): Promise<HistoryRecord[]> {\n    throw new Error('Method not implemented.');\n  }\n\n  restore(historyRecord: HistoryRecord): Promise<void> {\n    throw new Error('Method not implemented.');\n  }\n\n  clear() {\n    this.undoRedoService.clear();\n  }\n\n  dispose(): void {\n    this._willDisposeEmitter.fire(this);\n    this._toDispose.dispose();\n  }\n\n  private _canPush() {\n    if (this._locked) {\n      return false;\n    }\n    return this.undoRedoService.canPush();\n  }\n\n  private _pushStackOperation(stackOperation: StackOperation) {\n    this.undoRedoService.pushElement(stackOperation);\n    this.undoRedoService.clearRedoStack();\n  }\n\n  private _shouldMerge(operation: Operation, prev: IUndoRedoElement, operationMeta: OperationMeta) {\n    if (!prev) {\n      return false;\n    }\n\n    if (this._transacting) {\n      return true;\n    }\n    return (\n      operationMeta.shouldMerge &&\n      operationMeta.shouldMerge(operation, prev.getLastOperation(), prev as StackOperation)\n    );\n  }\n}\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { cloneDeep } from 'lodash-es';\nimport { DisposableCollection } from '@flowgram.ai/utils';\n\nimport { OperationService } from '../operation/operation-service';\nimport { Operation, OperationWithId } from '../operation';\nimport { IUndoRedoElement, UndoRedoChangeType } from './types';\n\nexport class StackOperation implements IUndoRedoElement {\n  label?: string | undefined;\n\n  description?: string | undefined;\n\n  private _operations: OperationWithId[];\n\n  private _toDispose = new DisposableCollection();\n\n  private _timestamp: number = Date.now();\n\n  private _operationService: OperationService;\n\n  private _id: string;\n\n  get id() {\n    return this._id;\n  }\n\n  constructor(operationService: OperationService, operations: Operation[] = []) {\n    this._operationService = operationService;\n    this._operations = operations.map((op) => this._operation(op));\n    this._id = operationService.config.generateId();\n  }\n\n  getTimestamp(): number {\n    return this._timestamp;\n  }\n\n  pushOperation(operation: Operation): OperationWithId {\n    const op = this._operation(operation);\n    this._operations.push(op);\n    return op;\n  }\n\n  getOperations(): Operation[] {\n    return this._operations;\n  }\n\n  getChangeOperations(type: UndoRedoChangeType): Operation[] {\n    if (type === UndoRedoChangeType.UNDO) {\n      return this._operationService.inverseOperations(this._operations);\n    }\n    return this._operations;\n  }\n\n  getFirstOperation(): Operation {\n    return this._operations[0];\n  }\n\n  getLastOperation(): Operation<unknown> {\n    return this._operations[this._operations.length - 1];\n  }\n\n  async undo(): Promise<void> {\n    const inverseOps = this._operationService.inverseOperations(this._operations);\n\n    for (const op of inverseOps) {\n      await this._apply(op);\n    }\n  }\n\n  async redo(): Promise<void> {\n    for (const op of this._operations) {\n      await this._apply(op);\n    }\n  }\n\n  revert(type: UndoRedoChangeType): void | Promise<void> {\n    let operations: Operation[] = this._operations;\n\n    if (type !== UndoRedoChangeType.UNDO) {\n      operations = this._operations.map((op) => this._inverse(op)).reverse();\n    }\n\n    for (const op of operations) {\n      this._apply(op);\n    }\n  }\n\n  private _inverse(op: Operation): Operation {\n    return this._operationService.inverseOperation(op);\n  }\n\n  private async _apply(op: Operation) {\n    await this._operationService.applyOperation(op);\n  }\n\n  private _operation(op: Operation) {\n    return {\n      ...op,\n      value: cloneDeep(op.value),\n      id: this._operationService.config.generateId(),\n    };\n  }\n\n  dispose(): void {\n    this._toDispose.dispose();\n  }\n}\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { inject, injectable } from 'inversify';\nimport { type Disposable, DisposableCollection } from '@flowgram.ai/utils';\n\nimport { OperationWithId } from '../operation';\nimport { HistoryConfig } from '../history-config';\nimport { type UndoRedoChangeEvent } from './types';\nimport {\n  type IHistoryManager,\n  type HistoryStackItem,\n  UndoRedoChangeType,\n  HistoryMergeEventType,\n  HistoryMergeEvent,\n} from './types';\nimport { StackOperation } from './stack-operation';\nimport { HistoryStack } from './history-stack';\nimport { type HistoryService } from './history-service';\n\n@injectable()\nexport class HistoryManager implements IHistoryManager {\n  @inject(HistoryStack) readonly historyStack: HistoryStack;\n\n  @inject(HistoryConfig) readonly historyConfig: HistoryConfig;\n\n  private _historyServices = new Map<HistoryService, Disposable>();\n\n  private _toDispose = new DisposableCollection();\n\n  registerHistoryService(service: HistoryService): void {\n    const toDispose = new DisposableCollection();\n    toDispose.pushAll([\n      service.undoRedoService.onChange((event: UndoRedoChangeEvent) => {\n        if (event.type === UndoRedoChangeType.CLEAR) {\n          return;\n        }\n\n        const { type, element } = event;\n        const operations = element.getChangeOperations(type);\n        const historyStackItem: HistoryStackItem = {\n          id:\n            type === UndoRedoChangeType.PUSH\n              ? (element as StackOperation).id\n              : this.historyConfig.generateId(),\n          type,\n          uri: service.context.uri,\n          operations,\n          timestamp: Date.now(),\n        };\n        this.historyStack.add(service, historyStackItem);\n      }),\n      service.onMerge((event) => {\n        this._handleMerge(service, event);\n      }),\n    ]);\n    this._historyServices.set(service, toDispose);\n\n    this._toDispose.push(\n      service.onWillDispose(() => {\n        this.unregisterHistoryService(service);\n      })\n    );\n  }\n\n  unregisterHistoryService(service: HistoryService): void {\n    const disposable = this._historyServices.get(service);\n    if (!disposable) {\n      return;\n    }\n    disposable.dispose();\n    this._historyServices.delete(service);\n  }\n\n  getHistoryServiceByURI(uri: string) {\n    for (const service of this._historyServices.keys()) {\n      if (service.context.uri === uri) {\n        return service;\n      }\n    }\n  }\n\n  getFirstHistoryService() {\n    for (const service of this._historyServices.keys()) {\n      return service;\n    }\n  }\n\n  dispose(): void {\n    this._toDispose.dispose();\n    this.historyStack.dispose();\n\n    this._historyServices.forEach((service) => service.dispose());\n    this._historyServices.clear();\n  }\n\n  _handleMerge(service: HistoryService, event: HistoryMergeEvent) {\n    const { element, operation } = event.value;\n\n    const find = this.historyStack.findById((element as StackOperation).id);\n\n    if (!find) {\n      return;\n    }\n\n    if (!(operation as OperationWithId).id) {\n      console.warn('no operation id found');\n      return;\n    }\n\n    if (event.type === HistoryMergeEventType.UPDATE) {\n      this.historyStack.updateOperation(\n        service,\n        (element as StackOperation).id,\n        operation as OperationWithId\n      );\n    }\n\n    if (event.type === HistoryMergeEventType.ADD) {\n      this.historyStack.addOperation(\n        service,\n        (element as StackOperation).id,\n        operation as OperationWithId\n      );\n    }\n  }\n}\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { cloneDeep } from 'lodash-es';\nimport { injectable, inject } from 'inversify';\nimport { DisposableCollection, Emitter } from '@flowgram.ai/utils';\n\nimport { HistoryOperation, Operation, OperationWithId } from '../operation';\nimport { HistoryConfig } from '../history-config';\nimport {\n  type HistoryItem,\n  HistoryStackChangeType,\n  type HistoryStackItem,\n  HistoryStackChangeEvent,\n  UndoRedoChangeType,\n} from './types';\nimport { type HistoryService } from './history-service';\n\n/**\n * 历史栈，聚合所有历史操作\n */\n@injectable()\nexport class HistoryStack {\n  @inject(HistoryConfig)\n  historyConfig: HistoryConfig;\n\n  private _items: HistoryItem[] = [];\n\n  readonly onChangeEmitter = new Emitter<HistoryStackChangeEvent>();\n\n  readonly onChange = this.onChangeEmitter.event;\n\n  private _toDispose: DisposableCollection = new DisposableCollection();\n\n  limit = 100;\n\n  constructor() {\n    this._toDispose.push(this.onChangeEmitter);\n  }\n\n  get items(): HistoryItem[] {\n    return this._items;\n  }\n\n  add(service: HistoryService, item: HistoryStackItem) {\n    const historyItem = this._getHistoryItem(service, item);\n    this._items.unshift(historyItem);\n    if (this._items.length > this.limit) {\n      this._items.pop();\n    }\n    this.onChangeEmitter.fire({\n      type: HistoryStackChangeType.ADD,\n      value: historyItem,\n      service,\n    });\n    return historyItem;\n  }\n\n  findById(id: string): HistoryItem | undefined {\n    return this._items.find((item) => item.id === id);\n  }\n\n  changeByIndex(index: number, service: HistoryService, item: HistoryStackItem) {\n    const historyItem = this._getHistoryItem(service, item);\n    this._items[index] = historyItem;\n    this.onChangeEmitter.fire({\n      type: HistoryStackChangeType.UPDATE,\n      value: historyItem,\n      service,\n    });\n  }\n\n  addOperation(service: HistoryService, id: string, op: OperationWithId) {\n    const historyItem = this._items.find((item) => item.id === id);\n    if (!historyItem) {\n      console.warn('no history item found');\n      return;\n    }\n\n    const newOperatopn = this._getHistoryOperation(service, op);\n    historyItem.operations.push(newOperatopn);\n\n    this.onChangeEmitter.fire({\n      type: HistoryStackChangeType.ADD_OPERATION,\n      value: {\n        historyItem,\n        operation: newOperatopn,\n      },\n      service,\n    });\n  }\n\n  updateOperation(service: HistoryService, id: string, op: OperationWithId) {\n    const historyItem = this._items.find((item) => item.id === id);\n    if (!historyItem) {\n      console.warn('no history item found');\n      return;\n    }\n    const index = historyItem.operations.findIndex((op) => op.id === op.id);\n    if (index < 0) {\n      console.warn('no operation found');\n      return;\n    }\n    const newOperatopn = this._getHistoryOperation(service, op);\n    historyItem.operations.splice(index, 1, newOperatopn);\n    this.onChangeEmitter.fire({\n      type: HistoryStackChangeType.UPDATE_OPERATION,\n      value: {\n        historyItem,\n        operation: newOperatopn,\n      },\n      service,\n    });\n  }\n\n  clear() {\n    this._items = [];\n  }\n\n  dispose() {\n    this._items = [];\n    this._toDispose.dispose();\n  }\n\n  private _getHistoryItem(service: HistoryService, item: HistoryStackItem): HistoryItem {\n    return {\n      ...item,\n      uri: service.context.uri,\n      time: HistoryStack.dateFormat(item.timestamp),\n      operations: item.operations.map((op) =>\n        this._getHistoryOperation(service, op, item.type !== UndoRedoChangeType.PUSH)\n      ),\n    };\n  }\n\n  private _getHistoryOperation(\n    service: HistoryService,\n    op: Operation,\n    generateId: boolean = false\n  ): HistoryOperation {\n    let id;\n    if (generateId) {\n      id = this.historyConfig.generateId();\n    } else {\n      const oldId = (op as OperationWithId).id;\n      if (!oldId) {\n        throw new Error('no operation id found');\n      }\n      id = oldId;\n    }\n\n    return {\n      ...cloneDeep(op),\n      id,\n      label: service.operationService.getOperationLabel(op),\n      description: service.operationService.getOperationDescription(op),\n      timestamp: Date.now(),\n    };\n  }\n\n  static dateFormat(timestamp: number) {\n    return new Date(timestamp).toLocaleString();\n  }\n}\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { ContainerModule } from 'inversify';\n\nimport { OperationRegistry, OperationService } from './operation';\nimport { HistoryContext } from './history-context';\nimport {\n  HistoryService,\n  HistoryStack,\n  HistoryManager,\n  UndoRedoService,\n  HistoryConfig,\n} from './history';\n\nexport const HistoryContainerModule = new ContainerModule(\n  (bind, _unbind, _isBound, _rebind, _unbindAsync, onActivation, _onDeactivation) => {\n    bind(OperationRegistry).toSelf().inSingletonScope();\n    bind(OperationService).toSelf().inSingletonScope();\n    bind(UndoRedoService).toSelf().inSingletonScope();\n    bind(HistoryService).toSelf().inSingletonScope();\n    bind(HistoryContext).toSelf().inSingletonScope();\n    bind(HistoryManager).toSelf().inSingletonScope();\n    bind(HistoryStack).toSelf().inSingletonScope();\n    bind(HistoryConfig).toSelf().inSingletonScope();\n\n    onActivation(HistoryService, (ctx, historyService) => {\n      let historyManager;\n\n      if (ctx.container?.parent?.isBound(HistoryManager)) {\n        historyManager = ctx.container?.parent?.get(HistoryManager);\n      } else {\n        historyManager = ctx.container.get(HistoryManager);\n      }\n\n      if (!historyManager) {\n        return historyService;\n      }\n\n      historyService.historyManager = historyManager;\n      historyManager.registerHistoryService(historyService);\n      return historyService;\n    });\n  }\n);\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { definePluginCreator, PluginContext } from '@flowgram.ai/core';\n\nimport { Operation, OperationService } from './operation';\nimport { HistoryContainerModule } from './history-container-module';\n\nexport interface HistoryPluginOptions<T = PluginContext> {\n  enable?: boolean;\n  enableChangeNode?: boolean;\n  onApply?: (ctx: T, operation: Operation) => void;\n}\n\nexport const createHistoryPlugin = definePluginCreator<HistoryPluginOptions>({\n  onInit: (ctx, opts) => {\n    if (opts.onApply) {\n      ctx.get(OperationService).onApply(opts.onApply.bind(null, ctx));\n    }\n  },\n  containerModules: [HistoryContainerModule],\n});\n"]}