interface.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. import React, { ReactNode, MouseEvent } from 'react';
  2. import {
  3. BasicTreeProps,
  4. BasicExpandedOtherProps,
  5. BasicRenderFullLabelProps,
  6. BasicSearchRenderProps,
  7. BasicTreeInnerData,
  8. BasicKeyEntities,
  9. BasicKeyEntity,
  10. BasicTreeNodeProps,
  11. BasicFlattenNode,
  12. BasicTreeNodeData,
  13. BasicOnDragProps,
  14. } from '@douyinfe/semi-foundation/tree/foundation';
  15. /* Tree */
  16. export type Value = string | number | TreeNodeData | Array<TreeNodeData | number | string>;
  17. export interface DragTreeNode extends TreeNodeData {
  18. expanded: boolean;
  19. /**
  20. * The positional relationship of the current node in the entire
  21. * treeData, such as the 0th node of the 2nd node of the 1st node
  22. * of the 0th layer: '0-1-2-0'
  23. */
  24. pos: string;
  25. }
  26. export interface DragProps {
  27. event: MouseEvent;
  28. node: DragTreeNode;
  29. }
  30. export interface OnDragProps extends BasicOnDragProps {
  31. event: MouseEvent;
  32. node: DragTreeNode;
  33. dragNode: DragTreeNode;
  34. }
  35. export interface DragEnterProps extends DragProps {
  36. expandedKeys?: string[];
  37. }
  38. export interface ExpandedOtherProps extends BasicExpandedOtherProps {
  39. node: TreeNodeData;
  40. }
  41. export interface RenderFullLabelProps extends BasicRenderFullLabelProps {
  42. onClick: (e: MouseEvent) => void;
  43. onContextMenu: (e: MouseEvent) => void;
  44. onDoubleClick: (e: MouseEvent) => void;
  45. onExpand: (e: MouseEvent) => void;
  46. data: TreeNodeData;
  47. style: React.CSSProperties;
  48. onCheck: (e: MouseEvent) => void;
  49. expandIcon: ReactNode;
  50. }
  51. export interface SearchRenderProps extends BasicSearchRenderProps {
  52. prefix: ReactNode;
  53. }
  54. export interface TreeProps extends BasicTreeProps {
  55. children?: ReactNode;
  56. defaultValue?: Value;
  57. emptyContent?: ReactNode;
  58. searchRender?: ((searchRenderProps: SearchRenderProps) => ReactNode) | false;
  59. searchStyle?: React.CSSProperties;
  60. style?: React.CSSProperties;
  61. treeData?: TreeNodeData[];
  62. value?: Value;
  63. icon?: ReactNode;
  64. loadData?: (treeNode?: TreeNodeData) => Promise<void>;
  65. onChange?: (value?: Value) => void;
  66. onDoubleClick?: (e: MouseEvent, node: TreeNodeData) => void;
  67. onDragEnd?: (dragProps: DragProps) => void;
  68. onDragLeave?: (dragProps: DragProps) => void;
  69. onDragOver?: (dragProps: DragProps) => void;
  70. onDragStart?: (dragProps: DragProps) => void;
  71. onDragEnter?: (dragEnterProps: DragEnterProps) => void;
  72. onDrop?: (onDragProps: OnDragProps) => void;
  73. onExpand?: (expandedKeys: string[], expandedOtherProps: ExpandedOtherProps) => void;
  74. onLoad?: (loadedKeys?: Set<string>, treeNode?: TreeNodeData) => void;
  75. onContextMenu?: (e: MouseEvent, node: TreeNodeData) => void;
  76. onSelect?: (selectedKeys: string, selected: boolean, selectedNode: TreeNodeData) => void;
  77. renderDraggingNode?: (nodeInstance: HTMLElement, node: TreeNodeData) => HTMLElement;
  78. renderFullLabel?: (renderFullLabelProps: RenderFullLabelProps) => ReactNode;
  79. renderLabel?: (label?: ReactNode, treeNode?: TreeNodeData) => ReactNode;
  80. }
  81. export interface OptionProps {
  82. index: number;
  83. style: React.CSSProperties;
  84. data: KeyEntity;
  85. }
  86. export interface KeyEntities extends BasicKeyEntities {
  87. [key: string]: KeyEntity;
  88. }
  89. export interface KeyEntity extends BasicKeyEntity {
  90. children?: KeyEntities;
  91. data?: TreeNodeData;
  92. parent?: undefined | KeyEntity;
  93. }
  94. export interface TreeState extends BasicTreeInnerData {
  95. keyEntities: KeyEntities;
  96. treeData: TreeNodeData[];
  97. flattenNodes: FlattenNode[];
  98. prevProps: null | TreeProps;
  99. cachedFlattenNodes: FlattenNode[] | undefined;
  100. }
  101. /* TreeNode */
  102. export interface TreeNodeProps extends BasicTreeNodeProps{
  103. children?: TreeNodeData[];
  104. icon?: ReactNode;
  105. }
  106. export interface TreeNodeState {
  107. [x: string]: any;
  108. }
  109. /* NodeList */
  110. export interface TreeNodeData extends BasicTreeNodeData{
  111. label?: ReactNode;
  112. icon?: ReactNode;
  113. children?: TreeNodeData[];
  114. }
  115. export interface FlattenNode extends BasicFlattenNode {
  116. children?: FlattenNode[];
  117. data?: BasicTreeNodeData;
  118. label?: ReactNode;
  119. parent?: null | FlattenNode;
  120. }
  121. export interface NodeListProps {
  122. [x: string]: any;
  123. flattenNodes: FlattenNode[];
  124. motionKeys: Set<string>;
  125. motionType: string;
  126. flattenList: FlattenNode[] | undefined;
  127. searchTargetIsDeep?: boolean;
  128. renderTreeNode: (treeNode: FlattenNode, ind?: number, style?: React.CSSProperties) => ReactNode;
  129. }
  130. export type TransitionNodes<T> = Array<T | Array<T>>;
  131. export interface NodeListState {
  132. transitionNodes: TransitionNodes<FlattenNode>;
  133. cachedMotionKeys?: Set<string>;
  134. cachedData?: FlattenNode[];
  135. }