create-group-plugin.tsx 932 B

12345678910111213141516171819202122232425262728293031
  1. /**
  2. * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
  3. * SPDX-License-Identifier: MIT
  4. */
  5. import { definePluginCreator, PluginContext } from '@flowgram.ai/core';
  6. import { CreateGroupPluginOptions } from './type';
  7. import { groupRegisters } from './registers';
  8. import { GroupPluginRegister } from './constant';
  9. /**
  10. * 分组插件
  11. */
  12. export const createGroupPlugin = definePluginCreator<CreateGroupPluginOptions>({
  13. onInit: (ctx: PluginContext, opts: CreateGroupPluginOptions) => {
  14. const { registers: registerConfs = {} } = opts;
  15. Object.entries(groupRegisters).forEach(([key, register]) => {
  16. const registerName = key as GroupPluginRegister;
  17. const registerConf = registerConfs[registerName];
  18. if (registerConf === false) {
  19. return;
  20. }
  21. if (typeof registerConf === 'function') {
  22. registerConf(ctx, opts);
  23. return;
  24. }
  25. register(ctx, opts);
  26. });
  27. },
  28. });