layer.tsx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /**
  2. * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
  3. * SPDX-License-Identifier: MIT
  4. */
  5. import React from 'react';
  6. import { inject, injectable } from 'inversify';
  7. import { domUtils } from '@flowgram.ai/utils';
  8. import {
  9. FlowNodeEntity,
  10. FlowNodeTransformData,
  11. FlowDocumentTransformerEntity,
  12. } from '@flowgram.ai/document';
  13. import {
  14. Layer,
  15. observeEntityDatas,
  16. observeEntity,
  17. PlaygroundConfigEntity,
  18. } from '@flowgram.ai/core';
  19. import { MinimapLayerOptions } from './type';
  20. import { FlowMinimapService } from './service';
  21. import { MinimapRender } from './component';
  22. @injectable()
  23. export class FlowMinimapLayer extends Layer<MinimapLayerOptions> {
  24. public static type = 'FlowMinimapLayer';
  25. @inject(FlowMinimapService) private readonly service: FlowMinimapService;
  26. @observeEntityDatas(FlowNodeEntity, FlowNodeTransformData)
  27. transformDatas: FlowNodeTransformData[];
  28. @observeEntity(PlaygroundConfigEntity) configEntity: PlaygroundConfigEntity;
  29. @observeEntity(FlowDocumentTransformerEntity)
  30. readonly documentTransformer: FlowDocumentTransformerEntity;
  31. public readonly node: HTMLElement;
  32. private readonly className = 'gedit-minimap-layer gedit-playground-layer';
  33. constructor() {
  34. super();
  35. this.node = domUtils.createDivWithClass(this.className);
  36. this.node.style.zIndex = '9999';
  37. }
  38. public render(): JSX.Element {
  39. if (this.documentTransformer.loading) return <></>;
  40. this.documentTransformer.refresh();
  41. this.service.render();
  42. if (this.options.disableLayer) {
  43. return <></>;
  44. }
  45. return (
  46. <MinimapRender
  47. service={this.service}
  48. panelStyles={this.options.panelStyles}
  49. containerStyles={this.options.containerStyles}
  50. inactiveStyle={this.options.inactiveStyle}
  51. />
  52. );
  53. }
  54. }