interface.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. filterTreeNode?: boolean | ((inputValue: string, treeNodeString: string, data?: TreeNodeData) => boolean);
  59. searchRender?: ((searchRenderProps: SearchRenderProps) => ReactNode) | false;
  60. searchStyle?: React.CSSProperties;
  61. style?: React.CSSProperties;
  62. treeData?: TreeNodeData[];
  63. value?: Value;
  64. icon?: ReactNode;
  65. loadData?: (treeNode?: TreeNodeData) => Promise<void>;
  66. onChange?: (value?: Value) => void;
  67. onDoubleClick?: (e: MouseEvent, node: TreeNodeData) => void;
  68. onDragEnd?: (dragProps: DragProps) => void;
  69. onDragLeave?: (dragProps: DragProps) => void;
  70. onDragOver?: (dragProps: DragProps) => void;
  71. onDragStart?: (dragProps: DragProps) => void;
  72. onDragEnter?: (dragEnterProps: DragEnterProps) => void;
  73. onDrop?: (onDragProps: OnDragProps) => void;
  74. onExpand?: (expandedKeys: string[], expandedOtherProps: ExpandedOtherProps) => void;
  75. onLoad?: (loadedKeys?: Set<string>, treeNode?: TreeNodeData) => void;
  76. onContextMenu?: (e: MouseEvent, node: TreeNodeData) => void;
  77. onSelect?: (selectedKeys: string, selected: boolean, selectedNode: TreeNodeData) => void;
  78. renderDraggingNode?: (nodeInstance: HTMLElement, node: TreeNodeData) => HTMLElement;
  79. renderFullLabel?: (renderFullLabelProps: RenderFullLabelProps) => ReactNode;
  80. renderLabel?: (label?: ReactNode, treeNode?: TreeNodeData) => ReactNode
  81. }
  82. export interface OptionProps {
  83. index: number;
  84. style: React.CSSProperties;
  85. data: KeyEntity
  86. }
  87. export interface KeyEntities extends BasicKeyEntities {
  88. [key: string]: KeyEntity
  89. }
  90. export interface KeyEntity extends BasicKeyEntity {
  91. children?: KeyEntities;
  92. data?: TreeNodeData;
  93. parent?: undefined | KeyEntity
  94. }
  95. export interface TreeState extends BasicTreeInnerData {
  96. keyEntities: KeyEntities;
  97. treeData: TreeNodeData[];
  98. flattenNodes: FlattenNode[];
  99. prevProps: null | TreeProps;
  100. cachedFlattenNodes: FlattenNode[] | undefined
  101. }
  102. /* TreeNode */
  103. export interface TreeNodeProps extends BasicTreeNodeProps{
  104. children?: TreeNodeData[];
  105. icon?: ReactNode
  106. }
  107. export interface TreeNodeState {
  108. [x: string]: any
  109. }
  110. /* NodeList */
  111. export interface TreeNodeData extends BasicTreeNodeData{
  112. label?: ReactNode;
  113. icon?: ReactNode;
  114. children?: TreeNodeData[]
  115. }
  116. export interface FlattenNode extends BasicFlattenNode {
  117. children?: FlattenNode[];
  118. data?: BasicTreeNodeData;
  119. label?: ReactNode;
  120. parent?: null | FlattenNode
  121. }
  122. export interface NodeListProps {
  123. [x: string]: any;
  124. flattenNodes: FlattenNode[];
  125. motionKeys: Set<string>;
  126. motionType: string;
  127. flattenList: FlattenNode[] | undefined;
  128. searchTargetIsDeep?: boolean;
  129. renderTreeNode: (treeNode: FlattenNode, ind?: number, style?: React.CSSProperties) => ReactNode
  130. }
  131. export type TransitionNodes<T> = Array<T | Array<T>>;
  132. export interface NodeListState {
  133. transitionNodes: TransitionNodes<FlattenNode>;
  134. cachedMotionKeys?: Set<string>;
  135. cachedData?: FlattenNode[]
  136. }
  137. export interface ScrollData {
  138. key: string;
  139. // The align parameter is consistent with react-window
  140. align?: 'center' | 'start' | 'end' | 'smart' | 'auto'
  141. }