interface.ts 5.1 KB

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