@byyuurin/ui 0.0.11 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (289) hide show
  1. package/README.md +170 -58
  2. package/dist/module.d.mts +4 -13
  3. package/dist/module.json +4 -4
  4. package/dist/module.mjs +54 -20
  5. package/dist/runtime/components/Accordion.vue +28 -23
  6. package/dist/runtime/components/Accordion.vue.d.ts +51 -29
  7. package/dist/runtime/components/Alert.vue +47 -27
  8. package/dist/runtime/components/Alert.vue.d.ts +37 -25
  9. package/dist/runtime/components/App.vue +9 -8
  10. package/dist/runtime/components/App.vue.d.ts +22 -20
  11. package/dist/runtime/components/Avatar.vue +65 -21
  12. package/dist/runtime/components/Avatar.vue.d.ts +27 -13
  13. package/dist/runtime/components/AvatarGroup.vue +14 -10
  14. package/dist/runtime/components/AvatarGroup.vue.d.ts +12 -9
  15. package/dist/runtime/components/Badge.vue +64 -32
  16. package/dist/runtime/components/Badge.vue.d.ts +30 -29
  17. package/dist/runtime/components/Breadcrumb.vue +40 -22
  18. package/dist/runtime/components/Breadcrumb.vue.d.ts +48 -21
  19. package/dist/runtime/components/Button.vue +113 -52
  20. package/dist/runtime/components/Button.vue.d.ts +36 -20
  21. package/dist/runtime/components/Calendar.vue +48 -39
  22. package/dist/runtime/components/Calendar.vue.d.ts +58 -31
  23. package/dist/runtime/components/Card.vue +18 -14
  24. package/dist/runtime/components/Card.vue.d.ts +18 -14
  25. package/dist/runtime/components/Carousel.vue +80 -46
  26. package/dist/runtime/components/Carousel.vue.d.ts +46 -25
  27. package/dist/runtime/components/Checkbox.vue +60 -35
  28. package/dist/runtime/components/Checkbox.vue.d.ts +35 -28
  29. package/dist/runtime/components/Chip.vue +35 -32
  30. package/dist/runtime/components/Chip.vue.d.ts +33 -15
  31. package/dist/runtime/components/Collapsible.vue +13 -9
  32. package/dist/runtime/components/Collapsible.vue.d.ts +16 -8
  33. package/dist/runtime/components/Drawer.vue +80 -70
  34. package/dist/runtime/components/Drawer.vue.d.ts +51 -28
  35. package/dist/runtime/components/DropdownMenu.vue +23 -16
  36. package/dist/runtime/components/DropdownMenu.vue.d.ts +77 -36
  37. package/dist/runtime/components/DropdownMenuContent.vue +133 -103
  38. package/dist/runtime/components/DropdownMenuContent.vue.d.ts +38 -26
  39. package/dist/runtime/components/FieldGroup.vue +33 -0
  40. package/dist/runtime/components/FieldGroup.vue.d.ts +33 -0
  41. package/dist/runtime/components/Form.vue +172 -88
  42. package/dist/runtime/components/Form.vue.d.ts +69 -44
  43. package/dist/runtime/components/FormField.vue +108 -0
  44. package/dist/runtime/components/FormField.vue.d.ts +63 -0
  45. package/dist/runtime/components/Icon.vue +20 -0
  46. package/dist/runtime/components/Icon.vue.d.ts +9 -0
  47. package/dist/runtime/components/Input.vue +82 -77
  48. package/dist/runtime/components/Input.vue.d.ts +55 -43
  49. package/dist/runtime/components/InputNumber.vue +65 -49
  50. package/dist/runtime/components/InputNumber.vue.d.ts +51 -105
  51. package/dist/runtime/components/Kbd.vue +11 -5
  52. package/dist/runtime/components/Kbd.vue.d.ts +17 -11
  53. package/dist/runtime/components/Link.vue +54 -197
  54. package/dist/runtime/components/Link.vue.d.ts +17 -17
  55. package/dist/runtime/components/LinkBase.vue +11 -33
  56. package/dist/runtime/components/LinkBase.vue.d.ts +8 -3
  57. package/dist/runtime/components/Modal.vue +53 -39
  58. package/dist/runtime/components/Modal.vue.d.ts +64 -34
  59. package/dist/runtime/components/NavigationMenu.vue +336 -0
  60. package/dist/runtime/components/NavigationMenu.vue.d.ts +181 -0
  61. package/dist/runtime/components/OverlayProvider.vue +3 -3
  62. package/dist/runtime/components/OverlayProvider.vue.d.ts +2 -1
  63. package/dist/runtime/components/Pagination.vue +39 -47
  64. package/dist/runtime/components/Pagination.vue.d.ts +54 -31
  65. package/dist/runtime/components/PinInput.vue +46 -32
  66. package/dist/runtime/components/PinInput.vue.d.ts +40 -21
  67. package/dist/runtime/components/Popover.vue +33 -19
  68. package/dist/runtime/components/Popover.vue.d.ts +57 -32
  69. package/dist/runtime/components/Progress.vue +31 -26
  70. package/dist/runtime/components/Progress.vue.d.ts +32 -23
  71. package/dist/runtime/components/RadioGroup.vue +75 -48
  72. package/dist/runtime/components/RadioGroup.vue.d.ts +58 -36
  73. package/dist/runtime/components/ScrollArea.vue +33 -31
  74. package/dist/runtime/components/ScrollArea.vue.d.ts +9 -5
  75. package/dist/runtime/components/Select.vue +166 -76
  76. package/dist/runtime/components/Select.vue.d.ts +206 -65
  77. package/dist/runtime/components/Separator.vue +42 -16
  78. package/dist/runtime/components/Separator.vue.d.ts +35 -14
  79. package/dist/runtime/components/Skeleton.vue +18 -6
  80. package/dist/runtime/components/Skeleton.vue.d.ts +4 -4
  81. package/dist/runtime/components/Slider.vue +42 -24
  82. package/dist/runtime/components/Slider.vue.d.ts +43 -27
  83. package/dist/runtime/components/Switch.vue +40 -31
  84. package/dist/runtime/components/Switch.vue.d.ts +36 -27
  85. package/dist/runtime/components/Table.vue +279 -51
  86. package/dist/runtime/components/Table.vue.d.ts +151 -65
  87. package/dist/runtime/components/Tabs.vue +70 -23
  88. package/dist/runtime/components/Tabs.vue.d.ts +61 -29
  89. package/dist/runtime/components/Textarea.vue +102 -54
  90. package/dist/runtime/components/Textarea.vue.d.ts +57 -41
  91. package/dist/runtime/components/Toast.vue +84 -38
  92. package/dist/runtime/components/Toast.vue.d.ts +48 -27
  93. package/dist/runtime/components/ToastProvider.vue +31 -22
  94. package/dist/runtime/components/ToastProvider.vue.d.ts +30 -17
  95. package/dist/runtime/components/Tooltip.vue +33 -21
  96. package/dist/runtime/components/Tooltip.vue.d.ts +37 -15
  97. package/dist/runtime/composables/defineShortcuts.d.ts +16 -0
  98. package/dist/runtime/composables/defineShortcuts.js +129 -0
  99. package/dist/runtime/composables/useAvatarGroup.d.ts +8 -3
  100. package/dist/runtime/composables/useAvatarGroup.js +10 -3
  101. package/dist/runtime/composables/useComponentIcons.d.ts +9 -6
  102. package/dist/runtime/composables/useComponentIcons.js +4 -4
  103. package/dist/runtime/composables/useFieldGroup.d.ts +8 -0
  104. package/dist/runtime/composables/useFieldGroup.js +14 -0
  105. package/dist/runtime/composables/useFormField.d.ts +62 -0
  106. package/dist/runtime/composables/useFormField.js +99 -0
  107. package/dist/runtime/composables/useKbd.d.ts +3 -2
  108. package/dist/runtime/composables/useKbd.js +3 -2
  109. package/dist/runtime/composables/useLocale.d.ts +68 -5
  110. package/dist/runtime/composables/useLocale.js +11 -11
  111. package/dist/runtime/composables/useOverlay.d.ts +51 -15
  112. package/dist/runtime/composables/useOverlay.js +44 -30
  113. package/dist/runtime/composables/usePortal.d.ts +6 -0
  114. package/dist/runtime/composables/usePortal.js +17 -0
  115. package/dist/runtime/composables/useToast.d.ts +12 -5
  116. package/dist/runtime/composables/useToast.js +12 -7
  117. package/dist/runtime/locale/en.d.ts +30 -1
  118. package/dist/runtime/locale/en.js +2 -1
  119. package/dist/runtime/locale/index.d.ts +2 -2
  120. package/dist/runtime/locale/index.js +1 -1
  121. package/dist/runtime/locale/zh_tw.d.ts +31 -0
  122. package/dist/runtime/locale/{zh-tw.js → zh_tw.js} +2 -1
  123. package/dist/runtime/plugins/colors.d.ts +2 -0
  124. package/dist/runtime/plugins/colors.js +50 -0
  125. package/dist/runtime/types/app.config.d.ts +6 -0
  126. package/dist/runtime/types/form.d.ts +58 -17
  127. package/dist/runtime/types/form.js +11 -0
  128. package/dist/runtime/types/index.d.ts +51 -8
  129. package/dist/runtime/types/index.js +45 -2
  130. package/dist/runtime/types/input.d.ts +8 -0
  131. package/dist/runtime/types/locale.d.ts +5 -0
  132. package/dist/runtime/types/style.d.ts +33 -0
  133. package/dist/runtime/types/style.js +0 -0
  134. package/dist/runtime/types/unocss.d.ts +4 -0
  135. package/dist/runtime/types/utils.d.ts +38 -37
  136. package/dist/runtime/utils/form.d.ts +5 -1
  137. package/dist/runtime/utils/form.js +49 -0
  138. package/dist/runtime/utils/index.d.ts +10 -13
  139. package/dist/runtime/utils/index.js +41 -48
  140. package/dist/runtime/utils/link.d.ts +3 -2
  141. package/dist/runtime/utils/link.js +16 -2
  142. package/dist/runtime/utils/locale.d.ts +5 -0
  143. package/dist/runtime/utils/locale.js +10 -0
  144. package/dist/runtime/utils/style.d.ts +94 -0
  145. package/dist/runtime/utils/style.js +37 -0
  146. package/dist/runtime/vue/components/Icon.vue +15 -0
  147. package/dist/runtime/vue/components/Icon.vue.d.ts +7 -0
  148. package/dist/runtime/vue/components/Link.vue +163 -0
  149. package/dist/runtime/vue/components/Link.vue.d.ts +95 -0
  150. package/dist/runtime/vue/composables/useAppConfig.d.ts +1 -0
  151. package/dist/runtime/vue/composables/useAppConfig.js +4 -0
  152. package/dist/runtime/vue/plugins/color-mode.d.ts +4 -0
  153. package/dist/runtime/vue/plugins/color-mode.js +6 -0
  154. package/dist/runtime/vue/plugins/head.d.ts +4 -0
  155. package/dist/runtime/vue/plugins/head.js +9 -0
  156. package/dist/runtime/vue/stubs.d.ts +16 -1
  157. package/dist/runtime/vue/stubs.js +32 -1
  158. package/dist/setup.d.mts +13 -0
  159. package/dist/setup.mjs +12 -0
  160. package/dist/shared/ui.CzIlLITK.mjs +51 -0
  161. package/dist/shared/ui.DSyJHSTk.mjs +3787 -0
  162. package/dist/shared/ui.DpbffTXs.d.mts +84 -0
  163. package/dist/shared/ui.IulR-OYx.d.mts +64 -0
  164. package/dist/types.d.mts +3 -1
  165. package/dist/unocss.d.mts +12 -52
  166. package/dist/unocss.mjs +144 -254
  167. package/dist/unplugin.d.mts +13 -26
  168. package/dist/unplugin.mjs +193 -18
  169. package/dist/vite.d.mts +10 -1
  170. package/dist/vite.mjs +12 -3
  171. package/package.json +154 -87
  172. package/vue-plugin.d.ts +5 -0
  173. package/dist/module.d.ts +0 -13
  174. package/dist/module.mjs.map +0 -1
  175. package/dist/runtime/app/injections.d.ts +0 -9331
  176. package/dist/runtime/app/injections.js +0 -61
  177. package/dist/runtime/components/ButtonGroup.vue +0 -26
  178. package/dist/runtime/components/ButtonGroup.vue.d.ts +0 -26
  179. package/dist/runtime/components/FormItem.vue +0 -90
  180. package/dist/runtime/components/FormItem.vue.d.ts +0 -60
  181. package/dist/runtime/composables/useButtonGroup.d.ts +0 -5
  182. package/dist/runtime/composables/useButtonGroup.js +0 -9
  183. package/dist/runtime/composables/useFormItem.d.ts +0 -27
  184. package/dist/runtime/composables/useFormItem.js +0 -64
  185. package/dist/runtime/composables/useTheme.d.ts +0 -9
  186. package/dist/runtime/composables/useTheme.js +0 -23
  187. package/dist/runtime/index.d.ts +0 -44
  188. package/dist/runtime/index.js +0 -44
  189. package/dist/runtime/locale/zh-tw.d.ts +0 -2
  190. package/dist/runtime/theme/accordion.d.ts +0 -50
  191. package/dist/runtime/theme/accordion.js +0 -28
  192. package/dist/runtime/theme/alert.d.ts +0 -119
  193. package/dist/runtime/theme/alert.js +0 -47
  194. package/dist/runtime/theme/app.d.ts +0 -19
  195. package/dist/runtime/theme/app.js +0 -19
  196. package/dist/runtime/theme/avatar-group.d.ts +0 -46
  197. package/dist/runtime/theme/avatar-group.js +0 -32
  198. package/dist/runtime/theme/avatar.d.ts +0 -50
  199. package/dist/runtime/theme/avatar.js +0 -34
  200. package/dist/runtime/theme/badge.d.ts +0 -76
  201. package/dist/runtime/theme/badge.js +0 -92
  202. package/dist/runtime/theme/breadcrumb.d.ts +0 -61
  203. package/dist/runtime/theme/breadcrumb.js +0 -44
  204. package/dist/runtime/theme/button-group.d.ts +0 -60
  205. package/dist/runtime/theme/button-group.js +0 -42
  206. package/dist/runtime/theme/button.d.ts +0 -184
  207. package/dist/runtime/theme/button.js +0 -164
  208. package/dist/runtime/theme/calendar.d.ts +0 -58
  209. package/dist/runtime/theme/calendar.js +0 -86
  210. package/dist/runtime/theme/card.d.ts +0 -56
  211. package/dist/runtime/theme/card.js +0 -37
  212. package/dist/runtime/theme/carousel.d.ts +0 -107
  213. package/dist/runtime/theme/carousel.js +0 -43
  214. package/dist/runtime/theme/checkbox.d.ts +0 -82
  215. package/dist/runtime/theme/checkbox.js +0 -54
  216. package/dist/runtime/theme/chip.d.ts +0 -61
  217. package/dist/runtime/theme/chip.js +0 -66
  218. package/dist/runtime/theme/collapsible.d.ts +0 -32
  219. package/dist/runtime/theme/collapsible.js +0 -10
  220. package/dist/runtime/theme/drawer.d.ts +0 -142
  221. package/dist/runtime/theme/drawer.js +0 -113
  222. package/dist/runtime/theme/dropdown-menu.d.ts +0 -65
  223. package/dist/runtime/theme/dropdown-menu.js +0 -83
  224. package/dist/runtime/theme/form-item.d.ts +0 -70
  225. package/dist/runtime/theme/form-item.js +0 -34
  226. package/dist/runtime/theme/form.d.ts +0 -2
  227. package/dist/runtime/theme/form.js +0 -7
  228. package/dist/runtime/theme/index.d.ts +0 -41
  229. package/dist/runtime/theme/index.js +0 -41
  230. package/dist/runtime/theme/input-number.d.ts +0 -115
  231. package/dist/runtime/theme/input-number.js +0 -95
  232. package/dist/runtime/theme/input.d.ts +0 -172
  233. package/dist/runtime/theme/input.js +0 -151
  234. package/dist/runtime/theme/kbd.d.ts +0 -33
  235. package/dist/runtime/theme/kbd.js +0 -26
  236. package/dist/runtime/theme/link.d.ts +0 -38
  237. package/dist/runtime/theme/link.js +0 -26
  238. package/dist/runtime/theme/modal.d.ts +0 -42
  239. package/dist/runtime/theme/modal.js +0 -55
  240. package/dist/runtime/theme/pagination.d.ts +0 -74
  241. package/dist/runtime/theme/pagination.js +0 -17
  242. package/dist/runtime/theme/pinInput.d.ts +0 -94
  243. package/dist/runtime/theme/pinInput.js +0 -111
  244. package/dist/runtime/theme/popover.d.ts +0 -32
  245. package/dist/runtime/theme/popover.js +0 -13
  246. package/dist/runtime/theme/progress.d.ts +0 -180
  247. package/dist/runtime/theme/progress.js +0 -95
  248. package/dist/runtime/theme/radio-group.d.ts +0 -104
  249. package/dist/runtime/theme/radio-group.js +0 -61
  250. package/dist/runtime/theme/scroll-area.d.ts +0 -67
  251. package/dist/runtime/theme/scroll-area.js +0 -33
  252. package/dist/runtime/theme/select.d.ts +0 -186
  253. package/dist/runtime/theme/select.js +0 -173
  254. package/dist/runtime/theme/separator.d.ts +0 -74
  255. package/dist/runtime/theme/separator.js +0 -53
  256. package/dist/runtime/theme/skeleton.d.ts +0 -2
  257. package/dist/runtime/theme/skeleton.js +0 -7
  258. package/dist/runtime/theme/slider.d.ts +0 -70
  259. package/dist/runtime/theme/slider.js +0 -52
  260. package/dist/runtime/theme/switch.d.ts +0 -116
  261. package/dist/runtime/theme/switch.js +0 -78
  262. package/dist/runtime/theme/table.d.ts +0 -86
  263. package/dist/runtime/theme/table.js +0 -36
  264. package/dist/runtime/theme/tabs.d.ts +0 -129
  265. package/dist/runtime/theme/tabs.js +0 -146
  266. package/dist/runtime/theme/textarea.d.ts +0 -90
  267. package/dist/runtime/theme/textarea.js +0 -116
  268. package/dist/runtime/theme/toast-provider.d.ts +0 -116
  269. package/dist/runtime/theme/toast-provider.js +0 -97
  270. package/dist/runtime/theme/toast.d.ts +0 -83
  271. package/dist/runtime/theme/toast.js +0 -35
  272. package/dist/runtime/theme/tooltip.d.ts +0 -38
  273. package/dist/runtime/theme/tooltip.js +0 -11
  274. package/dist/runtime/types/components.d.ts +0 -42
  275. package/dist/runtime/utils/extend-theme.d.ts +0 -9
  276. package/dist/runtime/utils/extend-theme.js +0 -27
  277. package/dist/runtime/utils/styler.d.ts +0 -4
  278. package/dist/runtime/utils/styler.js +0 -10
  279. package/dist/runtime/utils/translator.d.ts +0 -18
  280. package/dist/runtime/utils/translator.js +0 -8
  281. package/dist/shared/ui.D1BTWZFB.mjs +0 -5
  282. package/dist/shared/ui.D1BTWZFB.mjs.map +0 -1
  283. package/dist/unocss.d.ts +0 -52
  284. package/dist/unocss.mjs.map +0 -1
  285. package/dist/unplugin.d.ts +0 -26
  286. package/dist/unplugin.mjs.map +0 -1
  287. package/dist/vite.d.ts +0 -9
  288. package/dist/vite.mjs.map +0 -1
  289. /package/dist/runtime/types/{components.js → input.js} +0 -0
@@ -1,23 +1,47 @@
1
1
  <script>
2
-
2
+ import theme from "#build/ui/table";
3
3
  </script>
4
4
 
5
5
  <script setup>
6
6
  import { FlexRender, getCoreRowModel, getExpandedRowModel, getFilteredRowModel, getSortedRowModel, useVueTable } from "@tanstack/vue-table";
7
- import { reactiveOmit } from "@vueuse/core";
7
+ import { useVirtualizer } from "@tanstack/vue-virtual";
8
+ import { createReusableTemplate, reactiveOmit } from "@vueuse/core";
9
+ import { defu } from "defu";
8
10
  import { Primitive } from "reka-ui";
9
11
  import { upperFirst } from "scule";
10
- import { computed } from "vue";
12
+ import { computed, ref, shallowRef, toRef, watch } from "vue";
13
+ import { useAppConfig } from "#imports";
11
14
  import { useLocale } from "../composables/useLocale";
12
- import { useTheme } from "../composables/useTheme";
15
+ import { cv, merge } from "../utils/style";
16
+ defineOptions({ inheritAttrs: false });
13
17
  const props = defineProps({
14
18
  as: { type: null, required: false },
15
19
  data: { type: Array, required: false },
16
20
  columns: { type: Array, required: false },
17
21
  caption: { type: String, required: false },
22
+ meta: { type: Object, required: false },
23
+ virtualize: { type: [Boolean, Object], required: false, default: false },
18
24
  empty: { type: String, required: false },
19
- sticky: { type: Boolean, required: false },
25
+ sticky: { type: [Boolean, String], required: false },
20
26
  loading: { type: Boolean, required: false },
27
+ loadingColor: { type: null, required: false },
28
+ loadingAnimation: { type: null, required: false },
29
+ globalFilter: { type: String, required: false },
30
+ columnFilters: { type: Array, required: false },
31
+ columnOrder: { type: Array, required: false },
32
+ columnVisibility: { type: Object, required: false },
33
+ columnPinning: { type: Object, required: false },
34
+ columnSizing: { type: Object, required: false },
35
+ columnSizingInfo: { type: Object, required: false },
36
+ rowSelection: { type: Object, required: false },
37
+ rowPinning: { type: Object, required: false },
38
+ sorting: { type: Array, required: false },
39
+ grouping: { type: Array, required: false },
40
+ expanded: { type: [Boolean, Object], required: false },
41
+ pagination: { type: Object, required: false },
42
+ watchOptions: { type: Object, required: false, default: () => ({
43
+ deep: true
44
+ }) },
21
45
  globalFilterOptions: { type: Object, required: false },
22
46
  columnFiltersOptions: { type: Object, required: false },
23
47
  columnPinningOptions: { type: Object, required: false },
@@ -30,8 +54,11 @@ const props = defineProps({
30
54
  rowPinningOptions: { type: Object, required: false },
31
55
  paginationOptions: { type: Object, required: false },
32
56
  facetedOptions: { type: Object, required: false },
33
- class: { type: null, required: false },
57
+ onSelect: { type: Function, required: false },
58
+ onHover: { type: Function, required: false },
59
+ onContextmenu: { type: [Function, Array], required: false },
34
60
  ui: { type: null, required: false },
61
+ class: { type: [Object, String, Number, Boolean, null, Array], required: false, skipCheck: true },
35
62
  state: { type: Object, required: false },
36
63
  onStateChange: { type: Function, required: false },
37
64
  renderFallbackValue: { type: null, required: false },
@@ -47,10 +74,22 @@ const props = defineProps({
47
74
  getRowId: { type: Function, required: false },
48
75
  getSubRows: { type: Function, required: false },
49
76
  initialState: { type: Object, required: false },
50
- mergeOptions: { type: Function, required: false },
51
- meta: { type: Object, required: false }
77
+ mergeOptions: { type: Function, required: false }
52
78
  });
53
79
  const slots = defineSlots();
80
+ const [DefineTableTemplate, ReuseTableTemplate] = createReusableTemplate();
81
+ const [DefineRowTemplate, ReuseRowTemplate] = createReusableTemplate({
82
+ props: {
83
+ row: {
84
+ type: Object,
85
+ required: true
86
+ },
87
+ style: {
88
+ type: Object,
89
+ required: false
90
+ }
91
+ }
92
+ });
54
93
  const globalFilterState = defineModel("globalFilter", { type: String, ...{ default: void 0 } });
55
94
  const columnFiltersState = defineModel("columnFilters", { type: Array, ...{ default: [] } });
56
95
  const columnOrderState = defineModel("columnOrder", { type: Array, ...{ default: [] } });
@@ -64,16 +103,48 @@ const sortingState = defineModel("sorting", { type: Array, ...{ default: [] } })
64
103
  const groupingState = defineModel("grouping", { type: Array, ...{ default: [] } });
65
104
  const expandedState = defineModel("expanded", { type: [Boolean, Object], ...{ default: {} } });
66
105
  const paginationState = defineModel("pagination", { type: Object, ...{ default: {} } });
67
- const data = computed(() => props.data ?? []);
106
+ const rootRef = shallowRef();
107
+ const tableRef = shallowRef(null);
108
+ const data = ref(props.data ?? []);
109
+ const meta = computed(() => props.meta ?? {});
68
110
  const columns = computed(
69
- () => props.columns ?? Object.keys(data.value[0] ?? {}).map(
70
- (accessorKey) => ({ accessorKey, header: upperFirst(accessorKey) })
71
- )
111
+ () => processColumns(props.columns ?? Object.keys(data.value[0] ?? {}).map((accessorKey) => ({ accessorKey, header: upperFirst(accessorKey) })))
72
112
  );
113
+ function processColumns(columns2) {
114
+ return columns2.map((column) => {
115
+ const col = { ...column };
116
+ if ("columns" in col && col.columns)
117
+ col.columns = processColumns(col.columns);
118
+ if (!col.cell) {
119
+ col.cell = ({ getValue }) => {
120
+ const value = getValue();
121
+ if (value === "" || value === null || value === void 0)
122
+ return "\xA0";
123
+ return String(value);
124
+ };
125
+ }
126
+ return col;
127
+ });
128
+ }
129
+ const hasFooter = computed(() => {
130
+ function hasFooterRecursive(columns2) {
131
+ for (const column of columns2) {
132
+ if ("footer" in column)
133
+ return true;
134
+ if ("columns" in column && hasFooterRecursive(column.columns))
135
+ return true;
136
+ }
137
+ return false;
138
+ }
139
+ return hasFooterRecursive(columns.value);
140
+ });
73
141
  const tableApi = useVueTable({
74
- ...reactiveOmit(props, "data", "columns", "caption", "sticky", "loading", "class", "ui"),
142
+ ...reactiveOmit(props, "as", "data", "columns", "virtualize", "caption", "sticky", "loading", "loadingColor", "loadingAnimation", "class", "ui"),
75
143
  data,
76
- columns: columns.value,
144
+ get columns() {
145
+ return columns.value;
146
+ },
147
+ meta: meta.value,
77
148
  getCoreRowModel: getCoreRowModel(),
78
149
  ...props.globalFilterOptions,
79
150
  onGlobalFilterChange: (updaterOrValue) => valueUpdater(updaterOrValue, globalFilterState),
@@ -145,80 +216,237 @@ const tableApi = useVueTable({
145
216
  }
146
217
  }
147
218
  });
148
- function valueUpdater(updaterOrValue, ref) {
149
- ref.value = typeof updaterOrValue === "function" ? updaterOrValue(ref.value) : updaterOrValue;
219
+ const rows = computed(() => tableApi.getRowModel().rows);
220
+ const virtualizerProps = toRef(() => defu(typeof props.virtualize === "boolean" ? {} : props.virtualize, {
221
+ estimateSize: 65,
222
+ overscan: 12
223
+ }));
224
+ const virtualizer = !!props.virtualize && useVirtualizer({
225
+ ...virtualizerProps.value,
226
+ get count() {
227
+ return rows.value.length;
228
+ },
229
+ getScrollElement: () => rootRef.value?.$el,
230
+ estimateSize: () => virtualizerProps.value.estimateSize
231
+ });
232
+ function valueUpdater(updaterOrValue, ref2) {
233
+ ref2.value = typeof updaterOrValue === "function" ? updaterOrValue(ref2.value) : updaterOrValue;
234
+ }
235
+ function onRowSelect(e, row) {
236
+ if (!props.onSelect)
237
+ return;
238
+ const target = e.target;
239
+ const isInteractive = target.closest("button") || target.closest("a");
240
+ if (isInteractive)
241
+ return;
242
+ e.preventDefault();
243
+ e.stopPropagation();
244
+ props.onSelect(e, row);
245
+ }
246
+ function onRowHover(e, row) {
247
+ if (!props.onHover)
248
+ return;
249
+ props.onHover(e, row);
250
+ }
251
+ function onRowContextmenu(e, row) {
252
+ if (!props.onContextmenu)
253
+ return;
254
+ if (Array.isArray(props.onContextmenu))
255
+ props.onContextmenu.forEach((fn) => fn(e, row));
256
+ else
257
+ props.onContextmenu(e, row);
150
258
  }
259
+ function resolveValue(prop, arg) {
260
+ if (typeof prop === "function") {
261
+ return prop(arg);
262
+ }
263
+ return prop;
264
+ }
265
+ watch(() => props.data, () => {
266
+ data.value = props.data ? [...props.data] : [];
267
+ }, props.watchOptions);
151
268
  const { t } = useLocale();
152
- const { generateStyle } = useTheme();
153
- const style = computed(() => generateStyle("table", props));
269
+ const appConfig = useAppConfig();
270
+ const ui = computed(() => {
271
+ const styler = cv(merge(theme, appConfig.ui.table));
272
+ return styler({
273
+ ...props,
274
+ sticky: props.virtualize ? false : props.sticky,
275
+ virtualize: !!props.virtualize
276
+ });
277
+ });
154
278
  defineExpose({
279
+ get $el() {
280
+ return rootRef.value?.$el;
281
+ },
282
+ tableRef,
155
283
  tableApi
156
284
  });
157
285
  </script>
158
286
 
159
287
  <template>
160
- <Primitive :as="props.as" :class="style.root({ class: [props.class, props.ui?.root] })" data-part="root">
161
- <table :class="style.base({ class: props.ui?.base })" data-part="base">
162
- <caption v-if="props.caption || slots.caption" :class="style.caption({ class: props.caption })" data-part="caption">
288
+ <DefineRowTemplate v-slot="{ row, style }">
289
+ <tr
290
+ :role="props.onSelect ? 'button' : void 0"
291
+ :tabindex="props.onSelect ? 0 : void 0"
292
+ :class="ui.tr({
293
+ class: [
294
+ props.ui?.tr,
295
+ resolveValue(tableApi.options.meta?.class?.tr, row)
296
+ ]
297
+ })"
298
+ :data-selected="row.getIsSelected()"
299
+ :data-selectable="!!props.onSelect || !!props.onHover || !!props.onContextmenu"
300
+ :data-expanded="row.getIsExpanded()"
301
+ data-part="tr"
302
+ :style="[resolveValue(tableApi.options.meta?.style?.tr, row), style]"
303
+ @click="onRowSelect($event, row)"
304
+ @pointerenter="onRowHover($event, row)"
305
+ @pointerleave="onRowHover($event, null)"
306
+ @contextmenu="onRowContextmenu($event, row)"
307
+ >
308
+ <td
309
+ v-for="cell in row.getVisibleCells()"
310
+ :key="cell.id"
311
+ :colspan="resolveValue(cell.column.columnDef.meta?.colspan?.td, cell)"
312
+ :rowspan="resolveValue(cell.column.columnDef.meta?.rowspan?.td, cell)"
313
+ :class="ui.td({
314
+ class: [
315
+ props.ui?.td,
316
+ resolveValue(cell.column.columnDef.meta?.class?.td, cell)
317
+ ],
318
+ pinned: !!cell.column.getIsPinned()
319
+ })"
320
+ :data-pinned="cell.column.getIsPinned()"
321
+ data-part="td"
322
+ :style="resolveValue(cell.column.columnDef.meta?.style?.td, cell)"
323
+ >
324
+ <slot :name="`${cell.column.id}-cell`" v-bind="cell.getContext()">
325
+ <FlexRender :render="cell.column.columnDef.cell" :props="cell.getContext()" />
326
+ </slot>
327
+ </td>
328
+ </tr>
329
+
330
+ <tr v-if="row.getIsExpanded()" :class="ui.tr({ class: props.ui?.tr })" data-part="tr">
331
+ <td :colspan="row.getAllCells().length" :class="ui.td({ class: props.ui?.td })" data-part="td">
332
+ <slot name="expanded" :row="row"></slot>
333
+ </td>
334
+ </tr>
335
+ </DefineRowTemplate>
336
+
337
+ <DefineTableTemplate>
338
+ <table ref="tableRef" :class="ui.base({ class: props.ui?.base })" data-part="base">
339
+ <caption v-if="caption || !!slots.caption" :class="ui.caption({ class: [props.ui?.caption] })" data-part="caption">
163
340
  <slot name="caption">
164
- {{ props.caption }}
341
+ {{ caption }}
165
342
  </slot>
166
343
  </caption>
167
344
 
168
- <thead :class="style.thead({ class: props.ui?.thead })" data-part="thead">
169
- <tr v-for="headerGroup in tableApi.getHeaderGroups()" :key="headerGroup.id" :class="style.tr({ class: props.ui?.tr })" data-part="tr">
345
+ <thead :class="ui.thead({ class: [props.ui?.thead] })" data-part="thead">
346
+ <tr v-for="headerGroup in tableApi.getHeaderGroups()" :key="headerGroup.id" :class="ui.tr({ class: [props.ui?.tr] })" data-part="tr">
170
347
  <th
171
348
  v-for="header in headerGroup.headers"
172
349
  :key="header.id"
173
350
  :data-pinned="header.column.getIsPinned()"
174
- :class="style.th({ class: props.ui?.th, pinned: !!header.column.getIsPinned() })"
351
+ :scope="header.colSpan > 1 ? 'colgroup' : 'col'"
352
+ :colspan="header.colSpan > 1 ? header.colSpan : void 0"
353
+ :rowspan="header.rowSpan > 1 ? header.rowSpan : void 0"
354
+ :class="ui.th({
355
+ class: [
356
+ props.ui?.th,
357
+ resolveValue(header.column.columnDef.meta?.class?.th, header)
358
+ ],
359
+ pinned: !!header.column.getIsPinned()
360
+ })"
175
361
  data-part="th"
176
362
  >
177
363
  <slot :name="`${header.id}-header`" v-bind="header.getContext()">
178
- <FlexRender v-if="!header.isPlaceholder" :render="header.column.columnDef.header" :props="header.getContext" />
364
+ <FlexRender v-if="!header.isPlaceholder" :render="header.column.columnDef.header" :props="header.getContext()" />
179
365
  </slot>
180
366
  </th>
181
367
  </tr>
368
+
369
+ <tr :class="ui.separator({ class: [props.ui?.separator] })" data-part="separator"></tr>
182
370
  </thead>
183
371
 
184
- <tbody :class="style.tbody({ class: props.ui?.tbody })" data-part="tbody">
185
- <template v-if="tableApi.getRowModel().rows.length > 0">
186
- <template v-for="row in tableApi.getRowModel().rows" :key="row.id">
187
- <tr :data-selected="row.getIsSelected()" :data-expanded="row.getIsExpanded()" :class="style.tr({ class: props.ui?.tr })">
188
- <td
189
- v-for="cell in row.getVisibleCells()"
190
- :key="cell.id"
191
- :class="style.td({ class: props.ui?.td, pinned: !!cell.column.getIsPinned() })"
192
- data-part="td"
193
- :data-pinned="cell.column.getIsPinned()"
194
- >
195
- <slot :name="`${cell.column.id}-cell`" v-bind="cell.getContext()">
196
- <FlexRender :render="cell.column.columnDef.cell" :props="cell.getContext()" />
197
- </slot>
198
- </td>
199
- </tr>
200
- <tr v-if="row.getIsExpanded()" :class="style.tr({ class: props.ui?.tr, expanded: true })" data-part="tr">
201
- <td :colspan="row.getAllCells().length" :class="style.td({ class: props.ui?.td })" data-part="td">
202
- <slot name="expanded" :row="row"></slot>
203
- </td>
204
- </tr>
372
+ <tbody :class="ui.tbody({ class: [props.ui?.tbody] })" data-part="tbody">
373
+ <slot name="body-top"></slot>
374
+
375
+ <template v-if="rows.length">
376
+ <template v-if="virtualizer">
377
+ <template v-for="(virtualRow, index) in virtualizer.getVirtualItems()" :key="rows[virtualRow.index]?.id">
378
+ <ReuseRowTemplate
379
+ :row="rows[virtualRow.index]"
380
+ :style="{
381
+ height: `${virtualRow.size}px`,
382
+ transform: `translateY(${virtualRow.start - index * virtualRow.size}px)`
383
+ }"
384
+ />
385
+ </template>
386
+ </template>
387
+
388
+ <template v-else>
389
+ <ReuseRowTemplate v-for="row in rows" :key="row.id" :row="row" />
205
390
  </template>
206
391
  </template>
207
392
 
208
- <tr v-else-if="props.loading && slots.loading">
209
- <td :colspan="columns.length" :class="style.loading({ class: props.ui?.loading })" data-part="loading">
393
+ <tr v-else-if="props.loading && !!slots.loading">
394
+ <td :colspan="tableApi.getAllLeafColumns().length" :class="ui.loading({ class: props.ui?.loading })" data-part="loading">
210
395
  <slot name="loading"></slot>
211
396
  </td>
212
397
  </tr>
213
398
 
214
- <tr v-else :class="style.tr({ class: props.ui?.tr })" data-part="tr">
215
- <td :colspan="columns.length" :class="style.empty({ class: props.ui?.empty })" data-part="empty">
399
+ <tr v-else>
400
+ <td :colspan="tableApi.getAllLeafColumns().length" :class="ui.empty({ class: props.ui?.empty })" data-part="empty">
216
401
  <slot name="empty">
217
402
  {{ props.empty || t("table.noData") }}
218
403
  </slot>
219
404
  </td>
220
405
  </tr>
406
+
407
+ <slot name="body-bottom"></slot>
221
408
  </tbody>
409
+
410
+ <tfoot
411
+ v-if="hasFooter"
412
+ :class="ui.tfoot({ class: props.ui?.tfoot })"
413
+ data-part="tfoot"
414
+ :style="virtualizer ? {
415
+ transform: `translateY(${virtualizer.getTotalSize() - virtualizer.getVirtualItems().length * virtualizerProps.estimateSize}px)`
416
+ } : void 0"
417
+ >
418
+ <tr :class="ui.separator({ class: props.ui?.separator })" data-part="separator"></tr>
419
+
420
+ <tr v-for="footerGroup in tableApi.getFooterGroups()" :key="footerGroup.id" :class="ui.tr({ class: props.ui?.tr })" data-part="tr">
421
+ <th
422
+ v-for="header in footerGroup.headers"
423
+ :key="header.id"
424
+ :data-pinned="header.column.getIsPinned()"
425
+ :colspan="header.colSpan > 1 ? header.colSpan : void 0"
426
+ :rowspan="header.rowSpan > 1 ? header.rowSpan : void 0"
427
+ :class="ui.th({
428
+ class: [
429
+ props.ui?.th,
430
+ resolveValue(header.column.columnDef.meta?.class?.th, header)
431
+ ],
432
+ pinned: !!header.column.getIsPinned()
433
+ })"
434
+ data-part="th"
435
+ :style="resolveValue(header.column.columnDef.meta?.style?.th, header)"
436
+ >
437
+ <slot :name="`${header.id}-footer`" v-bind="header.getContext()">
438
+ <FlexRender v-if="!header.isPlaceholder" :render="header.column.columnDef.footer" :props="header.getContext()" />
439
+ </slot>
440
+ </th>
441
+ </tr>
442
+ </tfoot>
222
443
  </table>
444
+ </DefineTableTemplate>
445
+
446
+ <Primitive ref="rootRef" :as="props.as" v-bind="$attrs" :class="ui.root({ class: [props.ui?.root, props.class] })" data-part="root">
447
+ <div v-if="virtualizer" :style="{ height: `${virtualizer.getTotalSize()}px` }">
448
+ <ReuseTableTemplate />
449
+ </div>
450
+ <ReuseTableTemplate v-else />
223
451
  </Primitive>
224
452
  </template>