Просмотр исходного кода

fix(core): flow-document add options.preNodeCreate and fix node.form is undefined when form effect init (#860)

xiamidaxia 3 месяцев назад
Родитель
Сommit
ff4777d378

+ 1 - 0
packages/canvas-engine/document/src/flow-document-options.ts

@@ -32,6 +32,7 @@ export interface FlowDocumentOptions {
   constants?: Record<string, any>;
   formatNodeLines?: (node: FlowNodeEntity, lines: FlowTransitionLine[]) => FlowTransitionLine[];
   formatNodeLabels?: (node: FlowNodeEntity, lines: FlowTransitionLabel[]) => FlowTransitionLabel[];
+  preNodeCreate?: (node: FlowNodeEntity) => void;
   /**
    * 获取默认的节点配置
    */

+ 1 - 0
packages/canvas-engine/document/src/flow-document.ts

@@ -250,6 +250,7 @@ export class FlowDocument<T = FlowDocumentJSON> implements Disposable {
         originParent,
         meta,
       });
+      this.options.preNodeCreate?.(node);
       const datas = dataRegistries
         ? this.nodeDataRegistries.concat(...dataRegistries)
         : this.nodeDataRegistries;

+ 1 - 0
packages/canvas-engine/free-layout-core/src/workflow-document.ts

@@ -335,6 +335,7 @@ export class WorkflowDocument extends FlowDocument {
         originParent,
         meta,
       });
+      this.options.preNodeCreate?.(node);
       const datas = dataRegistries
         ? this.nodeDataRegistries.concat(...dataRegistries)
         : this.nodeDataRegistries;

+ 3 - 9
packages/client/editor/src/preset/editor-default-preset.ts

@@ -85,14 +85,7 @@ export function createDefaultPreset<CTX extends EditorPluginContext = EditorPlug
           if (opts.getNodeDefaultRegistry) {
             ctx.document.options.getNodeDefaultRegistry = opts.getNodeDefaultRegistry;
           }
-          // TODO
-          // if (opts.onContentChange) {
-          //   ctx.document.onContentChange(event => opts.onContentChange!(ctx, event));
-          // }
-          // TODO 这个会触发组件注册,后续要废弃这个,通过 materials 插件来做
-          ctx.get<FlowRendererRegistry>(FlowRendererRegistry).init();
-
-          ctx.document.onNodeCreate(({ node }) => {
+          ctx.document.options.preNodeCreate = (node) => {
             /**
              * Define node.form
              */
@@ -129,7 +122,8 @@ export function createDefaultPreset<CTX extends EditorPluginContext = EditorPlug
                 },
               });
             }
-          });
+          };
+          ctx.get<FlowRendererRegistry>(FlowRendererRegistry).init();
         },
         onReady(ctx) {
           if (opts.initialData) {