138a56065c9529f3c49922852fe7d6572ea63951b72fea4f255ad60a5f4b01f351ceb5ccf75783656ab2774d5b1f8ea767b3491120f1b163711af6408e674c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import type { Component, ComponentInternalInstance, Ref, SetupContext, VNode, h } from 'vue';
  2. import type Node from './model/node';
  3. import type TreeStore from './model/tree-store';
  4. export interface RootTreeType {
  5. ctx: SetupContext<any>;
  6. props: TreeComponentProps;
  7. store: Ref<TreeStore>;
  8. root: Ref<Node>;
  9. currentNode: Ref<Node>;
  10. instance: ComponentInternalInstance;
  11. }
  12. export type hType = typeof h;
  13. export type TreeData = TreeNodeData[];
  14. export type TreeKey = string | number;
  15. export interface FakeNode {
  16. data: TreeNodeData;
  17. }
  18. export type TreeNodeData = Record<string, any>;
  19. export interface TreeNodeLoadedDefaultProps {
  20. checked?: boolean;
  21. }
  22. export interface TreeNodeChildState {
  23. all: boolean;
  24. none: boolean;
  25. allWithoutDisable: boolean;
  26. half: boolean;
  27. }
  28. export interface TreeNodeOptions {
  29. data: TreeNodeData;
  30. store: TreeStore;
  31. parent?: Node;
  32. }
  33. export interface TreeStoreNodesMap {
  34. [key: string]: Node;
  35. }
  36. export interface TreeStoreOptions {
  37. key?: TreeKey;
  38. data: TreeData;
  39. lazy: boolean;
  40. props: TreeOptionProps;
  41. load?: LoadFunction;
  42. currentNodeKey?: TreeKey;
  43. checkStrictly: boolean;
  44. checkDescendants: boolean;
  45. defaultCheckedKeys?: TreeKey[];
  46. defaultExpandedKeys?: TreeKey[];
  47. autoExpandParent: boolean;
  48. defaultExpandAll: boolean;
  49. filterNodeMethod?: FilterNodeMethodFunction;
  50. }
  51. export interface TreeOptionProps {
  52. children?: string;
  53. label?: string | ((data: TreeNodeData, node: Node) => string);
  54. disabled?: string | ((data: TreeNodeData, node: Node) => boolean);
  55. isLeaf?: string | ((data: TreeNodeData, node: Node) => boolean);
  56. class?: (data: TreeNodeData, node: Node) => string | {
  57. [key: string]: boolean;
  58. };
  59. }
  60. export type RenderContentFunction = (h: hType, context: RenderContentContext) => VNode | VNode[];
  61. export interface RenderContentContext {
  62. _self: ComponentInternalInstance;
  63. node: Node;
  64. data: TreeNodeData;
  65. store: TreeStore;
  66. }
  67. export type AllowDragFunction = (node: Node) => boolean;
  68. export type AllowDropType = 'inner' | 'prev' | 'next';
  69. export type AllowDropFunction = (draggingNode: Node, dropNode: Node, type: AllowDropType) => boolean;
  70. export type LoadFunction = (rootNode: Node, loadedCallback: (data: TreeData) => void, stopLoading: () => void) => void;
  71. export type FilterValue = any;
  72. export type FilterNodeMethodFunction = (value: FilterValue, data: TreeNodeData, child: Node) => boolean;
  73. export interface TreeComponentProps {
  74. data: TreeData;
  75. emptyText: string;
  76. renderAfterExpand: boolean;
  77. nodeKey: string;
  78. checkStrictly: boolean;
  79. expandOnClickNode: boolean;
  80. defaultExpandAll: boolean;
  81. checkOnClickNode: boolean;
  82. checkOnClickLeaf: boolean;
  83. checkDescendants: boolean;
  84. autoExpandParent: boolean;
  85. defaultCheckedKeys: TreeKey[];
  86. defaultExpandedKeys: TreeKey[];
  87. currentNodeKey: TreeKey;
  88. renderContent: RenderContentFunction;
  89. showCheckbox: boolean;
  90. draggable: boolean;
  91. allowDrag: AllowDragFunction;
  92. allowDrop: AllowDropFunction;
  93. props: TreeOptionProps;
  94. lazy: boolean;
  95. highlightCurrent: boolean;
  96. load: LoadFunction;
  97. filterNodeMethod: FilterNodeMethodFunction;
  98. accordion: boolean;
  99. indent: number;
  100. icon: string | Component;
  101. }
  102. export type NodeDropType = 'before' | 'after' | 'inner' | 'none';