create-editor.ts 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /**
  2. * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
  3. * SPDX-License-Identifier: MIT
  4. */
  5. import { interfaces } from 'inversify';
  6. import {
  7. createPlaygroundContainer,
  8. Playground,
  9. loadPlugins,
  10. PluginContext,
  11. createPluginContextDefault,
  12. FlowDocument,
  13. } from '@flowgram.ai/editor';
  14. import { FreeLayoutPluginContext, FreeLayoutProps, createFreeLayoutPreset } from '../src';
  15. export function createEditor(opts: FreeLayoutProps): interfaces.Container {
  16. const container = createPlaygroundContainer();
  17. const playground = container.get(Playground);
  18. const preset = createFreeLayoutPreset(opts);
  19. const customPluginContext = (container: interfaces.Container) =>
  20. ({
  21. ...createPluginContextDefault(container),
  22. get document(): FlowDocument {
  23. return container.get<FlowDocument>(FlowDocument);
  24. },
  25. } as FreeLayoutPluginContext);
  26. const ctx = customPluginContext(container);
  27. container.rebind(PluginContext).toConstantValue(ctx);
  28. loadPlugins(preset(ctx), container);
  29. playground.init();
  30. return container;
  31. }