@dataloop-ai/components 0.13.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 (294) hide show
  1. package/.eslintrc.js +154 -0
  2. package/.prettierrc.json +7 -0
  3. package/Dockerfile +12 -0
  4. package/LICENSE +201 -0
  5. package/README.md +43 -0
  6. package/favicon.ico +0 -0
  7. package/index.html +13 -0
  8. package/index.ts +1 -0
  9. package/jest.config.js +16 -0
  10. package/jest.setup.js +59 -0
  11. package/models.ts +1 -0
  12. package/package.json +109 -0
  13. package/src/App.vue +201 -0
  14. package/src/assets/globals.scss +253 -0
  15. package/src/assets/globalsKeys.ts +28 -0
  16. package/src/components/DlAccordion/AccordionHeader.vue +148 -0
  17. package/src/components/DlAccordion/DlAccordion.vue +108 -0
  18. package/src/components/DlAccordion/index.ts +2 -0
  19. package/src/components/DlAlert.vue +227 -0
  20. package/src/components/DlAvatar.vue +99 -0
  21. package/src/components/DlBadge.vue +127 -0
  22. package/src/components/DlButton/DlButton.vue +370 -0
  23. package/src/components/DlButton/index.ts +4 -0
  24. package/src/components/DlButton/utils.ts +169 -0
  25. package/src/components/DlButtonGroup.vue +122 -0
  26. package/src/components/DlCheckbox.vue +298 -0
  27. package/src/components/DlChip/DlChip.vue +244 -0
  28. package/src/components/DlChip/index.ts +4 -0
  29. package/src/components/DlChip/utils.ts +100 -0
  30. package/src/components/DlColorPicker/DlAlpha.vue +142 -0
  31. package/src/components/DlColorPicker/DlBox.vue +75 -0
  32. package/src/components/DlColorPicker/DlColorPicker.vue +306 -0
  33. package/src/components/DlColorPicker/DlColors.vue +139 -0
  34. package/src/components/DlColorPicker/DlHue.vue +135 -0
  35. package/src/components/DlColorPicker/DlPreview.vue +61 -0
  36. package/src/components/DlColorPicker/DlSaturation.vue +152 -0
  37. package/src/components/DlColorPicker/constants.ts +16 -0
  38. package/src/components/DlColorPicker/index.ts +20 -0
  39. package/src/components/DlColorPicker/types.ts +11 -0
  40. package/src/components/DlColorPicker/utils.ts +128 -0
  41. package/src/components/DlCounters.vue +173 -0
  42. package/src/components/DlDatePicker/DlCalendar.vue +332 -0
  43. package/src/components/DlDatePicker/DlDatePicker.vue +315 -0
  44. package/src/components/DlDatePicker/DlMonthCalendar.vue +282 -0
  45. package/src/components/DlDatePicker/classes/Calendar.ts +110 -0
  46. package/src/components/DlDatePicker/classes/CalendarDate.ts +12 -0
  47. package/src/components/DlDatePicker/classes/CustomDate.ts +218 -0
  48. package/src/components/DlDatePicker/index.ts +3 -0
  49. package/src/components/DlDatePicker/isInRange.ts +44 -0
  50. package/src/components/DlDatePicker/types.ts +4 -0
  51. package/src/components/DlDatePicker/utils.ts +39 -0
  52. package/src/components/DlDateTimeRange/DlCardSidebar.vue +109 -0
  53. package/src/components/DlDateTimeRange/DlDateInput.vue +105 -0
  54. package/src/components/DlDateTimeRange/DlDateTimeRange.vue +468 -0
  55. package/src/components/DlDateTimeRange/index.ts +3 -0
  56. package/src/components/DlDateTimeRange/types.ts +42 -0
  57. package/src/components/DlDialogBox/DlDialogBox.vue +196 -0
  58. package/src/components/DlDialogBox/DlDialogBoxFooter.vue +22 -0
  59. package/src/components/DlDialogBox/DlDialogBoxHeader.vue +75 -0
  60. package/src/components/DlDialogBox/index.ts +5 -0
  61. package/src/components/DlDropdownButton.vue +463 -0
  62. package/src/components/DlIcon.vue +147 -0
  63. package/src/components/DlInfoErrorMessage.vue +91 -0
  64. package/src/components/DlItem/DlItem.vue +35 -0
  65. package/src/components/DlItem/index.ts +2 -0
  66. package/src/components/DlItemSection.vue +88 -0
  67. package/src/components/DlLink/DlLink.vue +76 -0
  68. package/src/components/DlLink/index.ts +4 -0
  69. package/src/components/DlLink/utils.ts +4 -0
  70. package/src/components/DlList.vue +61 -0
  71. package/src/components/DlListItem/DlListItem.vue +205 -0
  72. package/src/components/DlListItem/index.ts +3 -0
  73. package/src/components/DlListItem/utils.ts +14 -0
  74. package/src/components/DlMenu/DlMenu.vue +438 -0
  75. package/src/components/DlMenu/index.ts +3 -0
  76. package/src/components/DlMenu/utils.ts +138 -0
  77. package/src/components/DlOptionGroup/DlOptionGroup.vue +201 -0
  78. package/src/components/DlOptionGroup/MenuItemWrapper.vue +48 -0
  79. package/src/components/DlOptionGroup/OptionGroup.types.ts +36 -0
  80. package/src/components/DlOptionGroup/SimpleWrapper.vue +28 -0
  81. package/src/components/DlOptionGroup/index.ts +4 -0
  82. package/src/components/DlOptionGroup/utils.ts +40 -0
  83. package/src/components/DlPagination/DlPagination.vue +184 -0
  84. package/src/components/DlPagination/PageNavigation.vue +350 -0
  85. package/src/components/DlPagination/PaginationLegend.vue +41 -0
  86. package/src/components/DlPagination/QuickNavigation.vue +146 -0
  87. package/src/components/DlPagination/RowsSelector.vue +74 -0
  88. package/src/components/DlPagination/index.ts +3 -0
  89. package/src/components/DlPanelContainer/DlPanel.vue +213 -0
  90. package/src/components/DlPanelContainer/DlPanelContainer.vue +527 -0
  91. package/src/components/DlPanelContainer/index.ts +4 -0
  92. package/src/components/DlPopup/DlPopup.vue +478 -0
  93. package/src/components/DlPopup/DraggableUpper.vue +64 -0
  94. package/src/components/DlPopup/PopupHeader.vue +129 -0
  95. package/src/components/DlPopup/index.ts +1 -0
  96. package/src/components/DlProgressBar.vue +159 -0
  97. package/src/components/DlProgressChart.vue +299 -0
  98. package/src/components/DlRadio.vue +218 -0
  99. package/src/components/DlRange/DlRange.vue +439 -0
  100. package/src/components/DlRange/utils.ts +209 -0
  101. package/src/components/DlSearch.vue +155 -0
  102. package/src/components/DlSelect/DlSelect.vue +992 -0
  103. package/src/components/DlSelect/SelectOption.vue +261 -0
  104. package/src/components/DlSelect/index.ts +4 -0
  105. package/src/components/DlSelect/utils.ts +43 -0
  106. package/src/components/DlSkeleton.vue +72 -0
  107. package/src/components/DlSlider/DlSlider.vue +243 -0
  108. package/src/components/DlSlider/components/DlSliderBase.vue +380 -0
  109. package/src/components/DlSlider/components/DlSliderInput.vue +123 -0
  110. package/src/components/DlSlider/components/index.ts +4 -0
  111. package/src/components/DlSlider/index.ts +3 -0
  112. package/src/components/DlSlider/sliderStyles.scss +109 -0
  113. package/src/components/DlSlider/useSlider.ts +277 -0
  114. package/src/components/DlSlider/utils.ts +7 -0
  115. package/src/components/DlSmartSearch/DlJsonEditor.vue +309 -0
  116. package/src/components/DlSmartSearch/DlSmartSearch.vue +333 -0
  117. package/src/components/DlSmartSearch/DlSmartSearchInput.vue +741 -0
  118. package/src/components/DlSmartSearch/DlSuggestionsDropdown.vue +73 -0
  119. package/src/components/DlSmartSearch/highlightSyntax.ts +169 -0
  120. package/src/components/DlSmartSearch/index.ts +4 -0
  121. package/src/components/DlSmartSearch/types.ts +36 -0
  122. package/src/components/DlSmartSearch/utils.ts +45 -0
  123. package/src/components/DlStepper/DlStepper.vue +196 -0
  124. package/src/components/DlStepper/DlStepperContainer.vue +55 -0
  125. package/src/components/DlStepper/DlStepperContent.vue +101 -0
  126. package/src/components/DlStepper/DlStepperFooter.vue +133 -0
  127. package/src/components/DlStepper/DlStepperHeader.vue +49 -0
  128. package/src/components/DlStepper/DlStepperSidebar.vue +167 -0
  129. package/src/components/DlStepper/Step.ts +101 -0
  130. package/src/components/DlStepper/Stepper.ts +107 -0
  131. package/src/components/DlStepper/index.ts +7 -0
  132. package/src/components/DlStepper/interfaces.ts +11 -0
  133. package/src/components/DlSwitch.vue +280 -0
  134. package/src/components/DlTabPanels/DlTabPanel.vue +22 -0
  135. package/src/components/DlTabPanels/DlTabPanels.vue +41 -0
  136. package/src/components/DlTabPanels/index.ts +4 -0
  137. package/src/components/DlTabPanels/utils.ts +19 -0
  138. package/src/components/DlTable/DlTable.vue +1264 -0
  139. package/src/components/DlTable/DlTd.vue +109 -0
  140. package/src/components/DlTable/DlTh.vue +126 -0
  141. package/src/components/DlTable/DlTr.vue +44 -0
  142. package/src/components/DlTable/ResizableManager.ts +233 -0
  143. package/src/components/DlTable/dl-table-styles.scss +466 -0
  144. package/src/components/DlTable/hooks/tableActions.ts +64 -0
  145. package/src/components/DlTable/hooks/tableColumnSelection.ts +112 -0
  146. package/src/components/DlTable/hooks/tableFilter.ts +42 -0
  147. package/src/components/DlTable/hooks/tablePagination.ts +197 -0
  148. package/src/components/DlTable/hooks/tableRowExpand.ts +55 -0
  149. package/src/components/DlTable/hooks/tableRowSelection.ts +106 -0
  150. package/src/components/DlTable/hooks/tableSort.ts +125 -0
  151. package/src/components/DlTable/index.ts +6 -0
  152. package/src/components/DlTable/types.ts +96 -0
  153. package/src/components/DlTabs/DlTab.vue +146 -0
  154. package/src/components/DlTabs/DlTabs.vue +192 -0
  155. package/src/components/DlTabs/TabsWrapper.vue +104 -0
  156. package/src/components/DlTabs/index.ts +4 -0
  157. package/src/components/DlTabs/types.ts +8 -0
  158. package/src/components/DlTextArea.vue +151 -0
  159. package/src/components/DlTextHolder.vue +65 -0
  160. package/src/components/DlTextInput.vue +753 -0
  161. package/src/components/DlThemeProvider.vue +41 -0
  162. package/src/components/DlTimePicker/DlTimeCounter.vue +81 -0
  163. package/src/components/DlTimePicker/DlTimePicker.vue +151 -0
  164. package/src/components/DlTimePicker/DlTimePickerInput.vue +311 -0
  165. package/src/components/DlTimePicker/index.ts +3 -0
  166. package/src/components/DlTimePicker/types.ts +4 -0
  167. package/src/components/DlTooltip.vue +456 -0
  168. package/src/components/DlTrend.vue +97 -0
  169. package/src/components/DlTypography.vue +87 -0
  170. package/src/components/DlVirtualScroll/DlVirtualScroll.vue +290 -0
  171. package/src/components/DlVirtualScroll/index.ts +3 -0
  172. package/src/components/DlVirtualScroll/useVirtualScroll.ts +833 -0
  173. package/src/components/DlWidget/DlWidget.vue +50 -0
  174. package/src/components/DlWidget/DlWidgetGrid.vue +360 -0
  175. package/src/components/DlWidget/index.ts +4 -0
  176. package/src/components/DlWidget/types.ts +6 -0
  177. package/src/components/DlWidget/utils.ts +30 -0
  178. package/src/components/index.ts +118 -0
  179. package/src/demo/DlAccordionDemo.vue +60 -0
  180. package/src/demo/DlAlertDemo.vue +54 -0
  181. package/src/demo/DlAvatarDemo.vue +43 -0
  182. package/src/demo/DlBadgeDemo.vue +65 -0
  183. package/src/demo/DlButtonDemo.vue +266 -0
  184. package/src/demo/DlCheckboxDemo.vue +50 -0
  185. package/src/demo/DlChipDemo.vue +181 -0
  186. package/src/demo/DlColorPickerDemo.vue +43 -0
  187. package/src/demo/DlCounterDemo.vue +53 -0
  188. package/src/demo/DlDateTimeRangeDemo.vue +217 -0
  189. package/src/demo/DlDialogBoxDemo.vue +175 -0
  190. package/src/demo/DlDropdownButtonDemo.vue +260 -0
  191. package/src/demo/DlIconDemo.vue +47 -0
  192. package/src/demo/DlLinkDemo.vue +23 -0
  193. package/src/demo/DlListDemo.vue +177 -0
  194. package/src/demo/DlMenuDemo.vue +524 -0
  195. package/src/demo/DlOptionGroupDemo.vue +79 -0
  196. package/src/demo/DlPaginationDemo.vue +44 -0
  197. package/src/demo/DlPanelContainerDemo.vue +221 -0
  198. package/src/demo/DlPopupDemo.vue +58 -0
  199. package/src/demo/DlProgressBarDemo.vue +22 -0
  200. package/src/demo/DlProgressChartDemo.vue +71 -0
  201. package/src/demo/DlRadioDemo.vue +35 -0
  202. package/src/demo/DlRangeDemo.vue +44 -0
  203. package/src/demo/DlSearchDemo.vue +27 -0
  204. package/src/demo/DlSelectDemo.vue +355 -0
  205. package/src/demo/DlSkeletonDemo.vue +20 -0
  206. package/src/demo/DlSliderDemo.vue +47 -0
  207. package/src/demo/DlStepperDemo/CenteredStepperInDialogBox.vue +260 -0
  208. package/src/demo/DlStepperDemo/SimpleStepper.vue +202 -0
  209. package/src/demo/DlStepperDemo/StepperInDialogBox.vue +261 -0
  210. package/src/demo/DlStepperDemo/index.ts +5 -0
  211. package/src/demo/DlStepperDemo/steps/AssignmentsStep.vue +97 -0
  212. package/src/demo/DlStepperDemo/steps/DataStep.vue +158 -0
  213. package/src/demo/DlStepperDemo/steps/GeneralStep.vue +106 -0
  214. package/src/demo/DlStepperDemo/steps/InstructionStep.vue +176 -0
  215. package/src/demo/DlStepperDemo/steps/QualityStep.vue +65 -0
  216. package/src/demo/DlSwitchDemo.vue +49 -0
  217. package/src/demo/DlTableDemo.vue +475 -0
  218. package/src/demo/DlTabsDemo.vue +67 -0
  219. package/src/demo/DlTdDemo.vue +19 -0
  220. package/src/demo/DlTextAreaDemo.vue +37 -0
  221. package/src/demo/DlTextHolderDemo.vue +42 -0
  222. package/src/demo/DlTextInputDemo.vue +89 -0
  223. package/src/demo/DlThDemo.vue +32 -0
  224. package/src/demo/DlTooltipDemo.vue +60 -0
  225. package/src/demo/DlTrDemo.vue +18 -0
  226. package/src/demo/DlTrendDemo.vue +25 -0
  227. package/src/demo/DlTypographyDemo.vue +93 -0
  228. package/src/demo/DlWidgetDemo.vue +157 -0
  229. package/src/demo/SmartSearchDemo/DlSmartSearchDemo.vue +202 -0
  230. package/src/demo/SmartSearchDemo/schema.ts +44 -0
  231. package/src/demo/index.ts +141 -0
  232. package/src/directives/TouchPan.ts +525 -0
  233. package/src/env.d.ts +8 -0
  234. package/src/hooks/use-anchor.ts +223 -0
  235. package/src/hooks/use-model-toggle.ts +181 -0
  236. package/src/hooks/use-portal.ts +104 -0
  237. package/src/hooks/use-scroll-target.ts +53 -0
  238. package/src/hooks/use-size-observer.ts +24 -0
  239. package/src/hooks/use-suggestions.ts +355 -0
  240. package/src/hooks/use-tick.ts +32 -0
  241. package/src/hooks/use-timeout.ts +20 -0
  242. package/src/hooks/use-transition.ts +32 -0
  243. package/src/hooks/use-window-size.ts +25 -0
  244. package/src/hooks/useForm.ts +12 -0
  245. package/src/index.ts +7 -0
  246. package/src/main.ts +4 -0
  247. package/src/models.ts +4 -0
  248. package/src/types.ts +6 -0
  249. package/src/utils/calcs.ts +18 -0
  250. package/src/utils/click-outside.ts +108 -0
  251. package/src/utils/component-name-parser.ts +1 -0
  252. package/src/utils/css-color-names.ts +150 -0
  253. package/src/utils/dom.ts +55 -0
  254. package/src/utils/draggable-table.ts +416 -0
  255. package/src/utils/escape-key.ts +54 -0
  256. package/src/utils/events.ts +67 -0
  257. package/src/utils/focus-manager.ts +33 -0
  258. package/src/utils/focusout.ts +29 -0
  259. package/src/utils/format.ts +3 -0
  260. package/src/utils/getColor.ts +17 -0
  261. package/src/utils/getLighterGradient.ts +36 -0
  262. package/src/utils/getRootStyles.ts +52 -0
  263. package/src/utils/global-config.ts +6 -0
  264. package/src/utils/global-nodes.ts +42 -0
  265. package/src/utils/includes.ts +3 -0
  266. package/src/utils/index.ts +29 -0
  267. package/src/utils/inject-object-prop.ts +21 -0
  268. package/src/utils/input-sizes.ts +7 -0
  269. package/src/utils/is-ellipsis-active.ts +3 -0
  270. package/src/utils/is-in-viewport.ts +13 -0
  271. package/src/utils/is.ts +15 -0
  272. package/src/utils/key-composition.ts +17 -0
  273. package/src/utils/keyCodes.ts +12 -0
  274. package/src/utils/logger/ConsoleLogger.ts +65 -0
  275. package/src/utils/logger/ILogger.ts +8 -0
  276. package/src/utils/logger/index.ts +8 -0
  277. package/src/utils/nav-keys-constants.ts +1 -0
  278. package/src/utils/portal.ts +55 -0
  279. package/src/utils/position-engine.ts +381 -0
  280. package/src/utils/render.ts +36 -0
  281. package/src/utils/ripple.ts +7 -0
  282. package/src/utils/scroll.ts +73 -0
  283. package/src/utils/selection.ts +15 -0
  284. package/src/utils/sort.ts +7 -0
  285. package/src/utils/splitByQuotes.ts +32 -0
  286. package/src/utils/string.ts +6 -0
  287. package/src/utils/teleport.ts +14 -0
  288. package/src/utils/theme.ts +2 -0
  289. package/src/utils/vm.ts +16 -0
  290. package/storybook.js +8 -0
  291. package/tsconfig.json +44 -0
  292. package/tsconfig.node.json +8 -0
  293. package/types.ts +1 -0
  294. package/vite.config.ts +13 -0
@@ -0,0 +1,197 @@
1
+ import {
2
+ ref,
3
+ computed,
4
+ watch,
5
+ nextTick,
6
+ Ref,
7
+ ComputedRef,
8
+ PropType
9
+ } from 'vue-demi'
10
+
11
+ export type TablePagination = {
12
+ sortBy?: string
13
+ descending?: boolean
14
+ page?: number
15
+ rowsPerPage?: number
16
+ rowsNumber?: number
17
+ maxPages?: number
18
+ }
19
+
20
+ function samePagination(oldPag: TablePagination, newPag: TablePagination) {
21
+ for (const prop in newPag) {
22
+ if (
23
+ newPag[prop as keyof TablePagination] !==
24
+ oldPag[prop as keyof TablePagination]
25
+ ) {
26
+ return false
27
+ }
28
+ }
29
+ return true
30
+ }
31
+
32
+ function fixPagination(p: TablePagination) {
33
+ if (p.page < 1) {
34
+ p.page = 1
35
+ }
36
+ if (p.rowsPerPage !== void 0 && p.rowsPerPage < 1) {
37
+ p.rowsPerPage = 0
38
+ }
39
+ return p
40
+ }
41
+
42
+ export const useTablePaginationProps = {
43
+ pagination: Object as PropType<TablePagination>,
44
+ rowsPerPageOptions: {
45
+ type: Array,
46
+ default: () => [5, 7, 10, 15, 20, 25, 50, 100]
47
+ },
48
+
49
+ 'onUpdate:pagination': [Function, Array]
50
+ }
51
+
52
+ export function useTablePaginationState(
53
+ vm: Record<string, any>,
54
+ getCellValue: Function
55
+ ) {
56
+ const { props, emit } = vm
57
+ const innerPagination = ref(
58
+ Object.assign(
59
+ {
60
+ sortBy: null,
61
+ descending: false,
62
+ page: 1,
63
+ rowsPerPage:
64
+ props.rowsPerPageOptions.length > 0
65
+ ? props.rowsPerPageOptions[0]
66
+ : 5,
67
+ min: 1,
68
+ maxPages: 0,
69
+ boundaryNumbers: true,
70
+ boundaryLinks: true,
71
+ directionLinks: true,
72
+ withQuickNavigation: true,
73
+ itemsName: 'Rows',
74
+ withLegend: true,
75
+ withRowsPerPage: true
76
+ },
77
+ props.pagination
78
+ )
79
+ )
80
+
81
+ const computedPagination = computed(() => {
82
+ const pag =
83
+ props['onUpdate:pagination'] !== void 0
84
+ ? {
85
+ ...innerPagination.value,
86
+ ...props.pagination
87
+ }
88
+ : innerPagination.value
89
+
90
+ return fixPagination(pag)
91
+ })
92
+
93
+ function requestServerInteraction(prop: Record<string, any> = {}) {
94
+ nextTick(() => {
95
+ emit('request', {
96
+ pagination: prop.pagination || computedPagination.value,
97
+ filter: prop.filter || props.filter,
98
+ getCellValue
99
+ })
100
+ })
101
+ }
102
+
103
+ function setPagination(val: Record<string, any>) {
104
+ const newPagination = fixPagination({
105
+ ...computedPagination.value,
106
+ ...val
107
+ })
108
+
109
+ if (samePagination(computedPagination.value, newPagination)) {
110
+ return
111
+ }
112
+
113
+ if (
114
+ props.pagination !== void 0 &&
115
+ props['onUpdate:pagination'] !== void 0
116
+ ) {
117
+ emit('update:pagination', newPagination)
118
+ } else {
119
+ innerPagination.value = newPagination
120
+ }
121
+ }
122
+
123
+ return {
124
+ innerPagination,
125
+ computedPagination,
126
+
127
+ requestServerInteraction,
128
+ setPagination
129
+ }
130
+ }
131
+
132
+ export function useTablePagination(
133
+ vm: Record<string, any>,
134
+ computedPagination: ComputedRef<TablePagination>,
135
+ setPagination: Function,
136
+ filteredSortedRowsNumber: Ref<number>
137
+ ) {
138
+ const { props, emit } = vm
139
+
140
+ const computedRowsNumber = computed(() => filteredSortedRowsNumber.value)
141
+
142
+ const firstRowIndex = computed(() => {
143
+ const { page, rowsPerPage } = computedPagination.value
144
+ return (page - 1) * rowsPerPage
145
+ })
146
+
147
+ const lastRowIndex = computed(() => {
148
+ const { page, rowsPerPage } = computedPagination.value
149
+ return page * rowsPerPage
150
+ })
151
+
152
+ const isFirstPage = computed(() => computedPagination.value.page === 1)
153
+
154
+ const pagesNumber = computed(() =>
155
+ computedPagination.value.rowsPerPage === 0
156
+ ? 1
157
+ : Math.max(
158
+ 1,
159
+ Math.ceil(
160
+ computedRowsNumber.value /
161
+ computedPagination.value.rowsPerPage
162
+ )
163
+ )
164
+ )
165
+
166
+ const isLastPage = computed(() =>
167
+ lastRowIndex.value === 0
168
+ ? true
169
+ : computedPagination.value.page >= pagesNumber.value
170
+ )
171
+
172
+ watch(pagesNumber, (lastPage, oldLastPage) => {
173
+ if (lastPage === oldLastPage) {
174
+ return
175
+ }
176
+
177
+ const currentPage = computedPagination.value.page
178
+ if (lastPage && !currentPage) {
179
+ setPagination({ page: 1 })
180
+ } else if (lastPage < currentPage) {
181
+ setPagination({ page: lastPage })
182
+ }
183
+ })
184
+
185
+ if (props['onUpdate:pagination'] !== void 0) {
186
+ emit('update:pagination', { ...computedPagination.value })
187
+ }
188
+
189
+ return {
190
+ firstRowIndex,
191
+ lastRowIndex,
192
+ isFirstPage,
193
+ isLastPage,
194
+ pagesNumber,
195
+ computedRowsNumber
196
+ }
197
+ }
@@ -0,0 +1,55 @@
1
+ import { ref, watch } from 'vue-demi'
2
+
3
+ function getVal(val: string[]) {
4
+ return Array.isArray(val) ? val.slice() : []
5
+ }
6
+
7
+ export const useTableRowExpandProps = {
8
+ expanded: Array // v-model:expanded
9
+ }
10
+
11
+ export const useTableRowExpandEmits = ['update:expanded']
12
+
13
+ export function useTableRowExpand(props: any, emit: Function) {
14
+ const innerExpanded = ref(getVal(props.expanded))
15
+
16
+ watch(
17
+ () => props.expanded,
18
+ (val) => {
19
+ innerExpanded.value = getVal(val)
20
+ }
21
+ )
22
+
23
+ function isRowExpanded(key: string) {
24
+ return innerExpanded.value.includes(key)
25
+ }
26
+
27
+ function setExpanded(val: string[]) {
28
+ if (props.expanded !== void 0) {
29
+ emit('update:expanded', val)
30
+ } else {
31
+ innerExpanded.value = val
32
+ }
33
+ }
34
+
35
+ function updateExpanded(key: string, add: boolean) {
36
+ const target = innerExpanded.value.slice()
37
+ const index = target.indexOf(key)
38
+
39
+ if (add === true) {
40
+ if (index === -1) {
41
+ target.push(key)
42
+ setExpanded(target)
43
+ }
44
+ } else if (index !== -1) {
45
+ target.splice(index, 1)
46
+ setExpanded(target)
47
+ }
48
+ }
49
+
50
+ return {
51
+ isRowExpanded,
52
+ setExpanded,
53
+ updateExpanded
54
+ }
55
+ }
@@ -0,0 +1,106 @@
1
+ import { computed, ComputedRef } from 'vue-demi'
2
+ import { TableProps, TableRow } from '../types'
3
+
4
+ export const useTableRowSelectionProps = {
5
+ selection: {
6
+ type: String,
7
+ default: 'none',
8
+ validator: (v: string) => ['single', 'multiple', 'none'].includes(v)
9
+ },
10
+ selected: {
11
+ type: Array,
12
+ default: () => [] as (string | TableRow)[]
13
+ }
14
+ }
15
+
16
+ export const useTableRowSelectionEmits = ['update:selected', 'selection']
17
+
18
+ export function useTableRowSelection(
19
+ props: TableProps,
20
+ emit: (event: string, val: any) => void,
21
+ computedRows: ComputedRef<TableRow[]>,
22
+ getRowKey: ComputedRef<(val: string | TableRow) => any>
23
+ ) {
24
+ const selectedKeys = computed(() => {
25
+ return props.selected
26
+ .map(getRowKey.value)
27
+ .reduce((acc, key: string) => {
28
+ acc[key] = true
29
+
30
+ return acc
31
+ }, {} as Record<string, boolean>)
32
+ })
33
+
34
+ const hasSelectionMode = computed(() => {
35
+ return props.selection !== 'none'
36
+ })
37
+
38
+ const singleSelection = computed(() => {
39
+ return props.selection === 'single'
40
+ })
41
+
42
+ const multipleSelection = computed(() => {
43
+ return props.selection === 'multiple'
44
+ })
45
+
46
+ const allRowsSelected = computed(
47
+ () =>
48
+ computedRows.value.length > 0 &&
49
+ computedRows.value.every(
50
+ (row) => selectedKeys.value[getRowKey.value(row)] === true
51
+ )
52
+ )
53
+
54
+ const someRowsSelected = computed(
55
+ () =>
56
+ allRowsSelected.value !== true &&
57
+ computedRows.value.some(
58
+ (row) => selectedKeys.value[getRowKey.value(row)] === true
59
+ )
60
+ )
61
+
62
+ const rowsSelectedNumber = computed(() => props.selected.length)
63
+
64
+ function isRowSelected(key: string) {
65
+ return selectedKeys.value[key] === true
66
+ }
67
+
68
+ function clearSelection() {
69
+ emit('update:selected', [])
70
+ }
71
+
72
+ function updateSelection(
73
+ keys: string[],
74
+ rows: (string | TableRow)[],
75
+ added: boolean,
76
+ evt?: (event: string, val: any) => void
77
+ ) {
78
+ emit('selection', { rows, added, keys, evt })
79
+
80
+ const payload =
81
+ singleSelection.value === true
82
+ ? added === true
83
+ ? rows
84
+ : []
85
+ : added === true
86
+ ? props.selected.concat(rows as string[])
87
+ : props.selected.filter(
88
+ (row) => keys.includes(getRowKey.value(row)) === false
89
+ )
90
+
91
+ emit('update:selected', payload)
92
+ }
93
+
94
+ return {
95
+ hasSelectionMode,
96
+ singleSelection,
97
+ multipleSelection,
98
+ allRowsSelected,
99
+ someRowsSelected,
100
+ rowsSelectedNumber,
101
+
102
+ isRowSelected,
103
+ clearSelection,
104
+ updateSelection
105
+ }
106
+ }
@@ -0,0 +1,125 @@
1
+ import { computed, ComputedRef } from 'vue-demi'
2
+
3
+ import { sortDate } from '../../../utils/sort'
4
+ import { isNumber, isDate, isObject } from '../../../utils/is'
5
+ import { TableProps, TableColumn, SortMethod } from '../types'
6
+ import { TablePagination } from './tablePagination'
7
+
8
+ export const useTableSortProps = {
9
+ sortMethod: Function,
10
+ binaryStateSort: Boolean,
11
+ columnSortOrder: {
12
+ type: String,
13
+ validator: (v: string) => v === 'asc' || v === 'des',
14
+ default: 'asc'
15
+ }
16
+ }
17
+
18
+ export function useTableSort(
19
+ props: TableProps,
20
+ computedPagination: ComputedRef<TablePagination>,
21
+ colList: ComputedRef<TableColumn[]>,
22
+ setPagination: Function
23
+ ) {
24
+ const columnToSort = computed(() => {
25
+ const { sortBy } = computedPagination.value
26
+
27
+ return sortBy
28
+ ? colList.value.find((def) => def.name === sortBy) || null
29
+ : null
30
+ })
31
+
32
+ const computedSortMethod = computed(() =>
33
+ props.sortMethod !== void 0
34
+ ? props.sortMethod
35
+ : (((data, sortBy, descending) => {
36
+ const col = colList.value.find((def) => def.name === sortBy)
37
+ if (col === void 0 || col.field === void 0) {
38
+ return data
39
+ }
40
+
41
+ const dir = descending === true ? -1 : 1
42
+ const val =
43
+ typeof col.field === 'function'
44
+ ? (v: string) => (col.field as Function)(v)
45
+ : (v: Record<string, any>) => v[col.field as string]
46
+
47
+ return data.sort((a: any, b: any) => {
48
+ let A = val(a)
49
+ let B = val(b)
50
+
51
+ if (A === null || A === void 0) {
52
+ return -1 * dir
53
+ }
54
+ if (B === null || B === void 0) {
55
+ return 1 * dir
56
+ }
57
+ if (col.sort !== void 0) {
58
+ return col.sort(A, B, a, b) * dir
59
+ }
60
+ if (isNumber(A) === true && isNumber(B) === true) {
61
+ return (A - B) * dir
62
+ }
63
+ if (isDate(A) === true && isDate(B) === true) {
64
+ return sortDate(A, B) * dir
65
+ }
66
+ if (typeof A === 'boolean' && typeof B === 'boolean') {
67
+ return (Number(A) - Number(B)) * dir
68
+ }
69
+
70
+ [A, B] = [A, B].map((s) =>
71
+ (s + '').toLocaleString().toLowerCase()
72
+ )
73
+
74
+ return A < B ? -1 * dir : A === B ? 0 : dir
75
+ })
76
+ }) as SortMethod)
77
+ )
78
+
79
+ function sort(col: string | TableColumn) {
80
+ let sortOrder: TableProps['columnSortOrder'] = props.columnSortOrder
81
+
82
+ if (isObject(col) === true) {
83
+ if ((col as TableColumn).sortOrder) {
84
+ sortOrder = (col as TableColumn).sortOrder
85
+ }
86
+
87
+ col = (col as TableColumn).name
88
+ } else {
89
+ const def = colList.value.find((def) => def.name === col)
90
+ if (def !== void 0 && def.sortOrder) {
91
+ sortOrder = def.sortOrder
92
+ }
93
+ }
94
+
95
+ let { sortBy, descending } = computedPagination.value
96
+
97
+ if (sortBy !== col) {
98
+ sortBy = col as string
99
+ descending = sortOrder === 'des'
100
+ } else if (props.binaryStateSort === true) {
101
+ descending = !descending
102
+ } else if (descending === true) {
103
+ if (sortOrder === 'asc') {
104
+ sortBy = null
105
+ } else {
106
+ descending = false
107
+ }
108
+ } else {
109
+ // ascending
110
+ if (sortOrder === 'asc') {
111
+ descending = true
112
+ } else {
113
+ sortBy = null
114
+ }
115
+ }
116
+
117
+ setPagination({ sortBy, descending, page: 1 })
118
+ }
119
+
120
+ return {
121
+ columnToSort,
122
+ computedSortMethod,
123
+ sort
124
+ }
125
+ }
@@ -0,0 +1,6 @@
1
+ import DlTr from './DlTr.vue'
2
+ import DlTh from './DlTh.vue'
3
+ import DlTd from './DlTd.vue'
4
+ import DlTable from './DlTable.vue'
5
+
6
+ export { DlTr, DlTh, DlTd, DlTable }
@@ -0,0 +1,96 @@
1
+ export type TableProps = {
2
+ columns: TableColumn[]
3
+ rows: TableRow[]
4
+ visibleColumns: string[]
5
+ filter: Filter
6
+ filterMethod: FilterMethod
7
+ sortMethod: SortMethod
8
+ selected: string[]
9
+ expanded: string[]
10
+ columnSortOrder: 'asc' | 'des'
11
+ [key: string]: any
12
+ }
13
+
14
+ export type TableRow = {
15
+ [key: string]: any
16
+ }
17
+
18
+ export type Filter = string | Record<string, any>
19
+
20
+ export type TableColumn = {
21
+ name: string
22
+ label: string
23
+ field: string | ((row: TableRow) => string)
24
+ required?: boolean
25
+ align?: 'right' | 'left' | 'center'
26
+ sortable?: boolean
27
+ sort?: (a: any, b: any, rowA: TableRow, rowB: TableRow) => number
28
+ sortOrder?: 'asc' | 'des'
29
+ format?: (val: any, row: TableRow) => any
30
+ style?: string | ((row: TableRow) => string)
31
+ classes?: string | ((row: TableRow) => string)
32
+ headerStyle?: string
33
+ headerClasses?: string
34
+ }
35
+
36
+ export type FilterMethod = (
37
+ rows: TableRow[],
38
+ terms: Filter,
39
+ cols: TableColumn[],
40
+ getCellValue: (col: TableColumn, row: TableRow) => any
41
+ ) => TableRow[]
42
+
43
+ export type SortMethod = (
44
+ rows: TableRow[],
45
+ sortBy: string,
46
+ descending: boolean
47
+ ) => TableRow[]
48
+
49
+ export type Pagination = {
50
+ page: number
51
+ rowsPerPage: number
52
+ rowsNumber?: number
53
+ sortBy?: string | null
54
+ descending?: boolean
55
+ }
56
+
57
+ export type RequestProp = {
58
+ pagination: Pagination
59
+ filter?: FilterMethod
60
+ getCellValue?: (col: TableColumn, row: TableRow) => any
61
+ }
62
+
63
+ export type SelectionDetails = {
64
+ rows: TableRow[]
65
+ keys: string[]
66
+ added: boolean
67
+ evt: Event
68
+ }
69
+
70
+ export type ScrollPosition = {
71
+ index: number
72
+ from: number
73
+ to: number
74
+ direction: 'increase' | 'decrease'
75
+ }
76
+
77
+ export interface EnhancedCol extends TableColumn {
78
+ iconClass: string
79
+ thClass: string
80
+ tdStyle: ((row: TableRow) => string) | (() => any)
81
+ tdClass: (row: TableRow) => string
82
+ }
83
+
84
+ export type VirtualScroll = {
85
+ [key: string]: any
86
+ reset: () => void
87
+ scrollTo: (toIndex: number | string, edge?: number | string) => void
88
+ }
89
+
90
+ export type TypographyProps = {
91
+ variant?: string
92
+ size?: string
93
+ uppercase?: boolean
94
+ bold?: boolean
95
+ color?: string
96
+ }