{"version":3,"sources":["jsdelivr-header.js","/npm/@flowgram.ai/history-node-plugin@1.0.6/src/index.ts","/npm/@flowgram.ai/history-node-plugin@1.0.6/src/create-history-node-plugin.ts","/npm/@flowgram.ai/history-node-plugin@1.0.6/src/utils/index.ts","/npm/@flowgram.ai/history-node-plugin@1.0.6/src/history-node-registers.ts","/npm/@flowgram.ai/history-node-plugin@1.0.6/src/operation-metas/change-form-values.ts","/npm/@flowgram.ai/history-node-plugin@1.0.6/src/operation-metas/index.ts"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,qtBCNA,cAAA,GAAA,SAAA,cAAA,CAAA,wBAAA,IAAA,0BAAA,OAAA,QAAA,aAAA,eCKA,IAAA,iBAA6B,QAAA,yBAC7B,YAAuD,QAAA,qBACvD,eAA8E,QAAA,wBCF9E,iBAAoB,QAAA,aACpB,YAA2C,QAAA,qBAG3C,iBAAiC,QAAA,0BAU1B,SAAS,eAAe,GAC7B,IAAK,EACH,OAGF,MAAM,EAAY,GAAM,QAAQ,iBAAA,mBAAmB,eAEnD,OAAK,IAAa,EAAC,YAAA,eAAc,GAI1B,OAJP,CAKF,CASO,SAAS,4BACd,EACA,EACA,GAEA,QAAK,IAID,KAAK,MAAQ,EAAQ,eAAiB,MAEtC,EAAG,OAAS,EAAK,MACjB,EAAG,OAAO,KAAO,EAAK,OAAO,IAC7B,EAAG,OAAO,OAAS,EAAK,OAAO,MAExB,CACL,KAAM,EAAG,KACT,MAAO,IACF,EAAG,MACN,MAAO,EAAG,OAAO,MACjB,SAAU,EAAK,OAAO,YAOhC,CAQO,SAAS,uBACd,EACA,EACA,GAEA,EAAU,oBAAoB,IAC5B,EAAe,cACb,CACE,KAAA,mBACA,MAAO,CACL,GAAI,EAAK,GACT,KAAM,EAAM,KACZ,MAAO,EAAM,MAAA,EAAO,iBAAA,KAAI,EAAM,OAAQ,EAAM,MAAQ,EAAM,OAC1D,SAAU,EAAM,MAAA,EAAO,iBAAA,KAAI,EAAM,WAAY,EAAM,MAAQ,EAAM,aAGrE,CAAE,SAAS,GACb,GAEJ,CCzFA,IAAA,iBAA2B,QAAA,aCC3B,gBAA6B,QAAA,yBAShB,6BAIT,CACF,KAAA,mBACA,QAAU,IAAA,IACL,EACH,MAAO,IACF,EAAG,MACN,MAAO,EAAG,MAAM,SAChB,SAAU,EAAG,MAAM,SAGvB,MAAO,EAAG,OAAS,QAAO,OAAM,OAAQ,KACtC,MACM,EAAY,eADD,EAAI,IAAkB,gBAAA,cACG,QAAQ,IAE7C,IAGA,EAGH,EAAU,WAAW,EAAM,GAF3B,EAAU,iBAAiB,GAG7B,EAEF,YAAa,6BCjCF,eAAkC,CAAC,8BFKnC,qBAAN,MACL,qBAAA,CAAsB,GACpB,eAAe,SAAQ,IACrB,EAAkB,sBAAsB,EAAa,GAEzD,GALW,qBAAN,gBAAA,IADN,iBAAA,eACY,sBFCN,IAAM,yBAAA,EAA0B,YAAA,qBAAoB,CACzD,OAAQ,EAAG,YACT,EAAA,YAAA,mBAAkB,EAAM,qBAAsB,CAAC,eAAA,uBAAsB,EAEvE,OAAQ,CAAC,EAAK,KACZ,MAAM,EAAW,EAAI,IAAkB,iBAAA,cACjC,EAAiB,EAAI,IAAoB,eAAA,gBAE/C,EAAS,cAAa,EAAG,WACvB,MAAM,EAAY,eAAe,GAE5B,GAIL,uBAAuB,EAAW,EAAM,EAAc,GACvD,EAEH,iBAAkB,CAAC,eAAA","file":"/npm/@flowgram.ai/history-node-plugin@1.0.6/dist/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@flowgram.ai/history-node-plugin@1.0.6/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 './create-history-node-plugin';\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { FlowDocument } from '@flowgram.ai/document';\nimport { bindContributions, definePluginCreator } from '@flowgram.ai/core';\nimport { HistoryContainerModule, HistoryService, OperationContribution } from '@flowgram.ai/history';\n\nimport { attachFormValuesChange, getFormModelV2 } from './utils';\nimport { HistoryNodeRegisters } from './history-node-registers';\n\n/**\n * 表单历史插件\n */\nexport const createHistoryNodePlugin = definePluginCreator({\n  onBind: ({ bind }) => {\n    bindContributions(bind, HistoryNodeRegisters, [OperationContribution]);\n  },\n  onInit: (ctx, _opts) => {\n    const document = ctx.get<FlowDocument>(FlowDocument);\n    const historyService = ctx.get<HistoryService>(HistoryService);\n\n    document.onNodeCreate(({ node }) => {\n      const formModel = getFormModelV2(node);\n\n      if (!formModel) {\n        return;\n      }\n\n      attachFormValuesChange(formModel, node, historyService);\n    });\n  },\n  containerModules: [HistoryContainerModule],\n});\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { get } from 'lodash-es';\nimport { FormModelV2, isFormModelV2 } from '@flowgram.ai/node';\nimport { HistoryService, Operation } from '@flowgram.ai/history';\nimport { StackOperation } from '@flowgram.ai/history';\nimport { FlowNodeFormData } from '@flowgram.ai/form-core';\nimport { FlowNodeEntity } from '@flowgram.ai/document';\n\nimport { ChangeFormValuesOperationValue, NodeOperationType } from '../types';\n\n/**\n * 获取v2版本的formModel\n * @param node 节点\n * @returns\n */\nexport function getFormModelV2(node: FlowNodeEntity | undefined): FormModelV2 | undefined {\n  if (!node) {\n    return undefined;\n  }\n\n  const formModel = node?.getData(FlowNodeFormData)?.getFormModel<FormModelV2>();\n\n  if (!formModel || !isFormModelV2(formModel)) {\n    return undefined;\n  }\n\n  return formModel;\n}\n\n/**\n * 表单合并策略\n * @param op 操作\n * @param prev 上一个操作\n * @param element 操作栈元素\n * @returns\n */\nexport function shouldChangeFormValuesMerge(\n  op: Operation<ChangeFormValuesOperationValue | undefined>,\n  prev: Operation<ChangeFormValuesOperationValue | undefined>,\n  element: StackOperation\n) {\n  if (!prev) {\n    return false;\n  }\n\n  if (Date.now() - element.getTimestamp() < 500) {\n    if (\n      op.type === prev.type && // 相同类型\n      op.value?.id === prev.value?.id && // 相同节点\n      op.value?.path === prev.value?.path // 相同路径\n    ) {\n      return {\n        type: op.type,\n        value: {\n          ...op.value,\n          value: op.value?.value,\n          oldValue: prev.value?.oldValue,\n        },\n      };\n    }\n    return true;\n  }\n  return false;\n}\n\n/**\n * 监听表单值变化\n * @param formModel 表单模型\n * @param node 节点\n * @param historyService 历史服务\n */\nexport function attachFormValuesChange(\n  formModel: FormModelV2,\n  node: FlowNodeEntity,\n  historyService: HistoryService\n) {\n  formModel.onFormValuesChange((event) => {\n    historyService.pushOperation(\n      {\n        type: NodeOperationType.changeFormValues,\n        value: {\n          id: node.id,\n          path: event.name,\n          value: event.name ? get(event.values, event.name) : event.values,\n          oldValue: event.name ? get(event.prevValues, event.name) : event.prevValues,\n        },\n      },\n      { noApply: true }\n    );\n  });\n}\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { injectable } from 'inversify';\nimport { type OperationContribution, type OperationRegistry } from '@flowgram.ai/history';\n\nimport { operationMetas } from './operation-metas';\n\n/**\n * 表单历史操作\n */\n@injectable()\nexport class HistoryNodeRegisters implements OperationContribution {\n  registerOperationMeta(operationRegistry: OperationRegistry): void {\n    operationMetas.forEach(operationMeta => {\n      operationRegistry.registerOperationMeta(operationMeta);\n    });\n  }\n}\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { type OperationMeta } from '@flowgram.ai/history';\nimport { FlowDocument } from '@flowgram.ai/document';\nimport { type PluginContext } from '@flowgram.ai/core';\n\nimport { getFormModelV2, shouldChangeFormValuesMerge } from '../utils';\nimport { ChangeFormValuesOperationValue, NodeOperationType } from '../types';\n\n/**\n * 表单修改操作\n */\nexport const changeFormValueOperationMeta: OperationMeta<\n  ChangeFormValuesOperationValue,\n  PluginContext,\n  void\n> = {\n  type: NodeOperationType.changeFormValues,\n  inverse: (op) => ({\n    ...op,\n    value: {\n      ...op.value,\n      value: op.value.oldValue,\n      oldValue: op.value.value,\n    },\n  }),\n  apply: ({ value: { value, path, id } }, ctx: PluginContext) => {\n    const document = ctx.get<FlowDocument>(FlowDocument);\n    const formModel = getFormModelV2(document.getNode(id));\n\n    if (!formModel) {\n      return;\n    }\n    if (!path) {\n      formModel.updateFormValues(value);\n    } else {\n      formModel.setValueIn(path, value);\n    }\n  },\n  shouldMerge: shouldChangeFormValuesMerge as OperationMeta['shouldMerge'],\n};\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { OperationMeta } from '@flowgram.ai/history';\n\nimport { changeFormValueOperationMeta } from './change-form-values';\n\nexport const operationMetas: OperationMeta[] = [changeFormValueOperationMeta];\n"]}