index.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. import * as arrow from "./arrow";
  2. import * as rectangle from "./rectangle";
  3. import * as circle from "./circle";
  4. import * as triangle from "./triangle";
  5. import * as polygon from "./polygon";
  6. import * as line from "./line";
  7. import * as lineChunk from "./line-chunk";
  8. import * as lineIcon from "./line-icon/index";
  9. import * as text from "./text";
  10. import * as icon from "./icon";
  11. import * as image from "./image";
  12. import * as table from "./table";
  13. import * as serial from "./serial";
  14. import * as group from "./group";
  15. import * as sequentLine from "./sequent-line";
  16. import { SLineData } from "./sequent-line";
  17. import { ArrowData } from "./arrow";
  18. import { TableData } from "./table";
  19. import { RectangleData } from "./rectangle";
  20. import { CircleData } from "./circle";
  21. import { TriangleData } from "./triangle";
  22. import { PolygonData } from "./polygon";
  23. import { LineData } from "./line";
  24. import { LineChunkData } from "./line-chunk";
  25. import { LineIconData } from "./line-icon/index";
  26. import { TextData } from "./text";
  27. import { IconData } from "./icon";
  28. import { ImageData } from "./image";
  29. import { SerialData } from "./serial";
  30. import { GroupData } from "./group";
  31. import { Pos } from "@/utils/math";
  32. import { AddMessage } from "../hook/use-draw";
  33. import { Transform } from "konva/lib/Util";
  34. import { DrawStore } from "../store";
  35. import { DrawHistory } from "../hook/use-history";
  36. import { TransformerVectorType } from "../hook/use-transformer";
  37. import { UseGetSelectionManage } from "../hook/use-selection";
  38. const _components = {
  39. arrow,
  40. rectangle,
  41. circle,
  42. triangle,
  43. polygon,
  44. line,
  45. lineChunk,
  46. lineIcon,
  47. text,
  48. icon,
  49. image,
  50. table,
  51. serial,
  52. group,
  53. sequentLine,
  54. };
  55. export const components = _components as any as Components;
  56. type CompAttach<key extends ShapeType> = {
  57. delItem?: (
  58. store: DrawStore,
  59. data: DrawItem<key>,
  60. childrenId?: string
  61. ) => void;
  62. checkItemData?: (item: DrawItem<key>) => boolean
  63. useDraw?: () => void;
  64. getSnapInfos?: (items: DrawItem<key>) => ComponentSnapInfo[];
  65. GroupComponent: (props: { data: DrawItem[] }) => any;
  66. getPredefine?: (attrKey: keyof DrawItem<key>) => any;
  67. useGetSelectionManage?: UseGetSelectionManage
  68. startMatResponse?: () => void
  69. endMatResponse?: () => void
  70. childrenDataGetter?: (data: DrawItem<key>, id: string) => any
  71. };
  72. type _Components = {
  73. [key in keyof typeof _components]: (typeof _components)[key];
  74. };
  75. export type Components = {
  76. [key in keyof _Components]: {
  77. [a in
  78. | keyof _Components[key]
  79. | keyof CompAttach<key>]: a extends keyof CompAttach<key>
  80. ? CompAttach<key>[a]
  81. : a extends keyof _Components[key] ? _Components[key][a] : never;
  82. };
  83. };
  84. export type ComponentValue<
  85. T extends ShapeType,
  86. K extends keyof Components[T]
  87. > = Components[T][K];
  88. export type DrawDataItem = {
  89. arrow: ArrowData;
  90. rectangle: RectangleData;
  91. circle: CircleData;
  92. triangle: TriangleData;
  93. polygon: PolygonData;
  94. line: LineData;
  95. lineChunk: LineChunkData;
  96. lineIcon: LineIconData,
  97. text: TextData;
  98. icon: IconData;
  99. image: ImageData;
  100. table: TableData;
  101. serial: SerialData;
  102. group: GroupData;
  103. sequentLine: SLineData;
  104. };
  105. export type ShapeType = keyof DrawDataItem;
  106. export type DrawData = {
  107. [k in ShapeType]?: DrawDataItem[k][];
  108. };
  109. export type DrawItem<T extends ShapeType = ShapeType> = DrawDataItem[T];
  110. export type SnapPoint = Pos & { view?: boolean };
  111. export type ComponentSnapInfo = {
  112. point: SnapPoint;
  113. links: Pos[];
  114. linkDirections: Pos[];
  115. linkAngle: number[];
  116. };
  117. export type InteractiveTo<T extends ShapeType> = (args: {
  118. info: AddMessage<T>;
  119. preset?: Partial<DrawItem<T>>;
  120. viewTransform: Transform;
  121. store: DrawStore;
  122. history: DrawHistory;
  123. drawing?: boolean;
  124. }) => DrawItem<T> | undefined;
  125. export type InteractiveFix<T extends ShapeType> = (args: {
  126. data: DrawItem<T>;
  127. info: AddMessage<T>;
  128. notdraw?: boolean;
  129. viewTransform: Transform;
  130. store: DrawStore;
  131. history: DrawHistory;
  132. }) => DrawItem<T> | undefined;
  133. export type MatResponseProps<T extends ShapeType> = {
  134. data: DrawItem<T>;
  135. mat: Transform;
  136. increment?: boolean;
  137. operType?: TransformerVectorType;
  138. store?: DrawStore;
  139. operId?: string
  140. };
  141. export const shapeTypes = Object.keys(components) as ShapeType[]