1
0

interface.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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;
  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) => ReactNode
  83. }
  84. export interface OptionProps {
  85. index: number;
  86. style: React.CSSProperties;
  87. data: KeyEntity
  88. }
  89. export interface KeyEntities extends BasicKeyEntities {
  90. [key: string]: KeyEntity
  91. }
  92. export interface KeyEntity extends BasicKeyEntity {
  93. children?: KeyEntities;
  94. data?: TreeNodeData;
  95. parent?: undefined | KeyEntity
  96. }
  97. export interface TreeState extends BasicTreeInnerData {
  98. keyEntities: KeyEntities;
  99. treeData: TreeNodeData[];
  100. flattenNodes: FlattenNode[];
  101. prevProps: null | TreeProps;
  102. cachedFlattenNodes: FlattenNode[] | undefined
  103. }
  104. /* TreeNode */
  105. export interface TreeNodeProps extends BasicTreeNodeProps{
  106. children?: TreeNodeData[];
  107. icon?: ReactNode
  108. }
  109. export interface TreeNodeState {
  110. [x: string]: any
  111. }
  112. /* NodeList */
  113. export interface TreeNodeData extends BasicTreeNodeData{
  114. label?: ReactNode;
  115. icon?: ReactNode;
  116. children?: TreeNodeData[]
  117. }
  118. export interface FlattenNode extends BasicFlattenNode {
  119. children?: FlattenNode[];
  120. data?: BasicTreeNodeData;
  121. label?: ReactNode;
  122. parent?: null | FlattenNode
  123. }
  124. export interface NodeListProps {
  125. [x: string]: any;
  126. flattenNodes: FlattenNode[];
  127. motionKeys: Set<string>;
  128. motionType: string;
  129. flattenList: FlattenNode[] | undefined;
  130. searchTargetIsDeep?: boolean;
  131. renderTreeNode: (treeNode: FlattenNode, ind?: number, style?: React.CSSProperties) => ReactNode
  132. }
  133. export type TransitionNodes<T> = Array<T | Array<T>>;
  134. export interface NodeListState {
  135. transitionNodes: TransitionNodes<FlattenNode>;
  136. cachedMotionKeys?: Set<string>;
  137. cachedData?: FlattenNode[]
  138. }
  139. export interface ScrollData {
  140. key: string;
  141. // The align parameter is consistent with react-window
  142. align?: 'center' | 'start' | 'end' | 'smart' | 'auto'
  143. }