create-container.ts 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. /**
  2. * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
  3. * SPDX-License-Identifier: MIT
  4. */
  5. import { FormModel } from '@flowgram.ai/form';
  6. import { FlowDocumentContainerModule } from '@flowgram.ai/document';
  7. import { loadPlugins, Playground, PlaygroundMockTools } from '@flowgram.ai/core';
  8. import { createHistoryPlugin, HistoryService } from '@flowgram.ai/history';
  9. import { attachFormValuesChange } from '../src/utils';
  10. import { createHistoryNodePlugin } from '../src';
  11. export const createContainer = () => {
  12. const container = PlaygroundMockTools.createContainer([FlowDocumentContainerModule]);
  13. const formModel = new FormModel();
  14. const playground = container.get(Playground);
  15. loadPlugins([createHistoryPlugin({ enable: true }), createHistoryNodePlugin({})], container);
  16. playground.init();
  17. const historyService = container.get(HistoryService);
  18. historyService.context.source = container;
  19. attachFormValuesChange(formModel as any, { id: 1 } as any, historyService);
  20. return {
  21. formModel,
  22. container,
  23. historyService,
  24. };
  25. };