@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,439 @@
1
+ <template>
2
+ <div
3
+ :id="uuid"
4
+ class="slider non-editable slider-content"
5
+ :style="rangeStyles"
6
+ >
7
+ <div class="header">
8
+ <div class="text capitalize">
9
+ {{ text }}
10
+ </div>
11
+ <div class="right-container">
12
+ <dl-button
13
+ flat
14
+ size="m"
15
+ :disabled="disabled || readonly"
16
+ data-test="reset-btn"
17
+ @click="handleResetButtonClick"
18
+ >
19
+ Reset
20
+ </dl-button>
21
+ <div class="value-container">
22
+ {{ resetValueString }}
23
+ </div>
24
+ </div>
25
+ </div>
26
+ <div class="slider-bar-container">
27
+ <div
28
+ ref="rootRef"
29
+ class="slider-bar"
30
+ v-bind="attributes"
31
+ :aria-valuenow="attributeDisplayValue"
32
+ data-test="slider-bar"
33
+ >
34
+ <div
35
+ v-touch-pan:horizontal.prevent.stop.mouse.mouseAllDir="
36
+ onTouchPan
37
+ "
38
+ class="track-container"
39
+ :class="{ readonly, disabled: disabled }"
40
+ data-test="track-container"
41
+ v-on="trackContainerEvents"
42
+ >
43
+ <div
44
+ class="track"
45
+ :style="trackStyle"
46
+ >
47
+ <div
48
+ class="selection"
49
+ :style="selectionBarStyle"
50
+ />
51
+ <div
52
+ key="tmin"
53
+ ref="minThumbRef"
54
+ class="thumb"
55
+ :style="minThumbStyle"
56
+ data-test="min-thumb"
57
+ v-on="minEvents"
58
+ />
59
+ <div
60
+ key="tmax"
61
+ class="thumb"
62
+ :style="maxThumbStyle"
63
+ v-on="maxEvents"
64
+ />
65
+ <input
66
+ v-if="name !== null && disabled !== true"
67
+ type="hidden"
68
+ :name="name"
69
+ :value="displayValue"
70
+ >
71
+ </div>
72
+ </div>
73
+ </div>
74
+ </div>
75
+ </div>
76
+ </template>
77
+
78
+ <script lang="ts">
79
+ import { defineComponent, watch, ref, computed, Ref } from 'vue-demi'
80
+ import useSlider, {
81
+ SliderProps,
82
+ useSliderProps,
83
+ useSliderEmits
84
+ } from '../DlSlider/useSlider'
85
+ import { DlButton } from '../DlButton'
86
+ import {
87
+ stopAndPrevent,
88
+ getColor,
89
+ KEY_CODE,
90
+ includes,
91
+ between,
92
+ isMobileOrTablet
93
+ } from '../../utils'
94
+ import touchPanDirective from '../../directives/TouchPan'
95
+ import * as rangeUtils from './utils'
96
+ import { v4 } from 'uuid'
97
+
98
+ type DlRangeModelValue = {
99
+ min: number | null
100
+ max: number | null
101
+ }
102
+
103
+ interface DlRangeProps extends SliderProps {
104
+ modelValue: DlRangeModelValue
105
+ }
106
+
107
+ export default defineComponent({
108
+ name: 'DlRange',
109
+ components: {
110
+ DlButton
111
+ },
112
+ directives: {
113
+ touchPan: touchPanDirective as any // force any type cause of the vue version
114
+ },
115
+ model: {
116
+ prop: 'modelValue',
117
+ event: 'update:model-value'
118
+ },
119
+ props: {
120
+ ...useSliderProps,
121
+ modelValue: {
122
+ type: Object as () => DlRangeModelValue,
123
+ default: (): { min: number; max: number } => ({
124
+ min: null,
125
+ max: null
126
+ }),
127
+ validator: (v: DlRangeModelValue) => 'min' in v && 'max' in v
128
+ }
129
+ },
130
+ emits: useSliderEmits,
131
+ setup(props, { emit }) {
132
+ const { state, methods } = useSlider({
133
+ updateValue,
134
+ updatePosition,
135
+ getDragging
136
+ })
137
+
138
+ const rootRef = ref(null)
139
+ const curMinRatio = ref(0)
140
+ const curMaxRatio = ref(0)
141
+ const model = ref<DlRangeModelValue>({
142
+ min: 0,
143
+ max: 0
144
+ })
145
+
146
+ const displayValue = computed<string>(() => {
147
+ return `${model.value.min}|${model.value.max}`
148
+ })
149
+
150
+ const attributeDisplayValue = computed<string>(() => {
151
+ return `${props.modelValue.min}|${props.modelValue.max}`
152
+ })
153
+
154
+ const resetValueString = computed<string>(() => {
155
+ return `${model.value.min} - ${model.value.max}`
156
+ })
157
+
158
+ function normalizeModel() {
159
+ model.value.min =
160
+ props.modelValue.min === null
161
+ ? props.min
162
+ : between(props.modelValue.min, props.min, props.max)
163
+
164
+ model.value.max =
165
+ props.modelValue.max === null
166
+ ? props.max
167
+ : between(props.modelValue.max, props.min, props.max)
168
+ }
169
+
170
+ watch(
171
+ () =>
172
+ `${props.modelValue.min}|${props.modelValue.max}|${props.min}|${props.max}`,
173
+ normalizeModel
174
+ )
175
+
176
+ normalizeModel()
177
+
178
+ const initialValue = {
179
+ min:
180
+ props.modelValue.min === null
181
+ ? props.min
182
+ : between(props.modelValue.min, props.min, props.max),
183
+ max:
184
+ props.modelValue.max === null
185
+ ? props.max
186
+ : between(props.modelValue.max, props.min, props.max)
187
+ }
188
+
189
+ const modelMinRatio = computed(() =>
190
+ methods.convertModelToRatio(model.value.min)
191
+ )
192
+
193
+ const modelMaxRatio = computed(() =>
194
+ methods.convertModelToRatio(model.value.max)
195
+ )
196
+
197
+ const ratioMin = computed(() =>
198
+ state.active.value === true
199
+ ? curMinRatio.value
200
+ : modelMinRatio.value
201
+ )
202
+
203
+ const ratioMax = computed(() =>
204
+ state.active.value === true
205
+ ? curMaxRatio.value
206
+ : modelMaxRatio.value
207
+ )
208
+
209
+ const selectionBarStyle = computed(() => {
210
+ const acc = {
211
+ left: `${100 * ratioMin.value}%`,
212
+ width: `${100 * (ratioMax.value - ratioMin.value)}%`,
213
+ color:
214
+ props.disabled !== true
215
+ ? getColor(props.color, 'dl-color-secondary')
216
+ : 'var(--dl-color-separator)'
217
+ }
218
+ return acc
219
+ })
220
+
221
+ const isMobile = isMobileOrTablet()
222
+
223
+ const trackContainerEvents = computed(() => {
224
+ if (state.editable.value !== true) {
225
+ return {}
226
+ }
227
+
228
+ if (isMobile === true) {
229
+ return { onClick: methods.onMobileClick }
230
+ }
231
+
232
+ const evt = { onMousedown: methods.onActivate }
233
+
234
+ return evt
235
+ })
236
+
237
+ function getEvents(side: 'min' | 'max') {
238
+ return isMobile !== true && state.editable.value === true
239
+ ? {
240
+ onFocus: () => {
241
+ state.focus.value = side
242
+ },
243
+ onBlur: methods.onBlur,
244
+ onKeydown,
245
+ onKeyup: methods.onKeyup
246
+ }
247
+ : {}
248
+ }
249
+
250
+ const minThumbStyle = computed(() => ({
251
+ width: props.thumbSize,
252
+ height: props.thumbSize,
253
+ left: `${100 * ratioMin.value}%`,
254
+ backgroundColor:
255
+ props.disabled !== true
256
+ ? getColor(props.color, 'dl-color-secondary')
257
+ : 'var(--dl-color-separator)',
258
+ zIndex: state.focus.value === 'min' ? 2 : void 0
259
+ }))
260
+
261
+ const maxThumbStyle = computed(() => ({
262
+ width: props.thumbSize,
263
+ height: props.thumbSize,
264
+ left: `${100 * ratioMax.value}%`,
265
+ backgroundColor:
266
+ props.disabled !== true
267
+ ? getColor(props.color, 'dl-color-secondary')
268
+ : 'var(--dl-color-separator)',
269
+ zIndex: state.focus.value === 'max' ? 2 : void 0
270
+ }))
271
+
272
+ const minThumbRef = ref(null)
273
+
274
+ const minEvents = computed(() => getEvents('min'))
275
+
276
+ const maxEvents = computed(() => getEvents('max'))
277
+
278
+ const onTouchPan = computed(() => {
279
+ return state.editable.value ? methods.onPan : null
280
+ })
281
+
282
+ const trackStyle = computed(() => ({
283
+ height: props.trackSize
284
+ }))
285
+
286
+ const rangeStyles = computed(() => ({
287
+ '--text-color': getColor(props.textColor, 'dl-color-darker'),
288
+ '--width': props.width,
289
+ '--color': getColor(props.color, 'dl-color-secondary')
290
+ }))
291
+
292
+ function updateValue(change?: boolean) {
293
+ rangeUtils.updateValue(
294
+ {
295
+ min: model.value.min,
296
+ max: model.value.max
297
+ },
298
+ {
299
+ min: props.min,
300
+ max: props.max
301
+ },
302
+ emit,
303
+ change
304
+ )
305
+ }
306
+
307
+ function getDragging(event: any) {
308
+ const { left, top, width, height } = (
309
+ rootRef as Ref<HTMLElement | null>
310
+ ).value!.getBoundingClientRect()
311
+
312
+ const sensitivity =
313
+ (minThumbRef as Ref<HTMLElement | null>).value!.offsetWidth /
314
+ (2 * width)
315
+
316
+ return rangeUtils.getDragging(
317
+ event,
318
+ {
319
+ left,
320
+ top,
321
+ width,
322
+ height
323
+ },
324
+ sensitivity,
325
+ { min: model.value.min, max: model.value.max },
326
+ {
327
+ min: modelMinRatio.value,
328
+ max: modelMaxRatio.value
329
+ },
330
+ methods.getDraggingRatio
331
+ )
332
+ }
333
+
334
+ function updatePosition(
335
+ event: MouseEvent,
336
+ dragging = state.dragging.value
337
+ ) {
338
+ if (
339
+ typeof dragging === 'boolean' ||
340
+ typeof dragging === 'undefined'
341
+ )
342
+ return
343
+
344
+ const {
345
+ model: newModel,
346
+ focus: newFocus,
347
+ curRatio
348
+ } = rangeUtils.updatePosition(
349
+ event,
350
+ dragging,
351
+ methods.getDraggingRatio,
352
+ methods.convertRatioToModel,
353
+ methods.convertModelToRatio,
354
+ {
355
+ min: props.min,
356
+ max: props.max,
357
+ snap: props.snap
358
+ },
359
+ {
360
+ step: state.step.value,
361
+ decimals: state.decimals.value
362
+ },
363
+ {
364
+ min: model.value.min,
365
+ max: model.value.max
366
+ }
367
+ )
368
+
369
+ state.focus.value = newFocus
370
+ model.value = newModel
371
+ curMinRatio.value = curRatio.min
372
+ curMaxRatio.value = curRatio.max
373
+ }
374
+
375
+ function onKeydown(evt: KeyboardEvent) {
376
+ if (!includes(Object.values(KEY_CODE), Number(evt.code))) {
377
+ return
378
+ }
379
+
380
+ if (typeof state.focus.value === 'boolean') return
381
+
382
+ stopAndPrevent(evt)
383
+
384
+ const { model: newModel } = rangeUtils.onKeydown(
385
+ evt,
386
+ {
387
+ step: state.step.value,
388
+ focus: state.focus.value,
389
+ decimals: state.decimals.value
390
+ },
391
+ { min: props.min, max: props.max },
392
+ { min: model.value.min, max: model.value.max }
393
+ )
394
+
395
+ model.value = newModel
396
+ updateValue()
397
+ }
398
+
399
+ function handleResetButtonClick() {
400
+ if (props.modelValue === initialValue) return
401
+
402
+ model.value.min = initialValue.min!
403
+ model.value.max = initialValue.max!
404
+ emit('update:model-value', { ...model.value })
405
+ }
406
+
407
+ return {
408
+ uuid: `dl-range-${v4()}`,
409
+ resetValueString,
410
+ attributeDisplayValue,
411
+ displayValue,
412
+ rangeStyles,
413
+ attributes: state.attributes,
414
+ minThumbStyle,
415
+ maxThumbStyle,
416
+ selectionBarStyle,
417
+ trackContainerEvents,
418
+ minEvents,
419
+ maxEvents,
420
+ trackStyle,
421
+ onTouchPan,
422
+ rootRef,
423
+ minThumbRef,
424
+ handleResetButtonClick
425
+ }
426
+ },
427
+ template: 'dl-range'
428
+ })
429
+ </script>
430
+
431
+ <style scoped lang="scss">
432
+ @import '../DlSlider/sliderStyles.scss';
433
+
434
+ .value-container {
435
+ padding-left: 10px;
436
+ min-width: 38px;
437
+ text-align: right;
438
+ }
439
+ </style>
@@ -0,0 +1,209 @@
1
+ import { between, includes, KEY_CODE } from '../../utils'
2
+ import { Dragging, dragType } from '../DlSlider/useSlider'
3
+
4
+ type RangeValue = {
5
+ min: number
6
+ max: number
7
+ }
8
+
9
+ export function updateValue(
10
+ state: RangeValue,
11
+ props: RangeValue,
12
+ emitFn: (...args: any[]) => any,
13
+ change?: boolean
14
+ ) {
15
+ if (state.min !== props.min || state.max !== props.max) {
16
+ emitFn('update:model-value', { ...state })
17
+ }
18
+
19
+ if (change === true) {
20
+ emitFn('change', { ...state })
21
+ }
22
+ }
23
+
24
+ type RangeBoundings = {
25
+ left: number
26
+ top: number
27
+ width: number
28
+ height: number
29
+ }
30
+
31
+ export function getDragging(
32
+ event: any,
33
+ boundings: RangeBoundings,
34
+ sensitivity: number,
35
+ state: RangeValue,
36
+ stateRatio: RangeValue,
37
+ getDraggingRatioFn: (event: MouseEvent, dragging: Dragging) => number
38
+ ): Dragging {
39
+ const { left, top, width, height } = boundings
40
+
41
+ const dragging = {
42
+ left,
43
+ top,
44
+ width,
45
+ height,
46
+ valueMin: state.min,
47
+ valueMax: state.max,
48
+ ratioMin: stateRatio.min,
49
+ ratioMax: stateRatio.max
50
+ } as unknown as Dragging
51
+
52
+ const ratio = getDraggingRatioFn(event, dragging)
53
+
54
+ if (ratio < dragging.ratioMin + sensitivity) {
55
+ dragging.type = dragType.MIN
56
+ } else if (ratio < dragging.ratioMax - sensitivity) {
57
+ dragging.type =
58
+ dragging.ratioMax - ratio < ratio - dragging.ratioMin
59
+ ? dragType.MAX
60
+ : dragType.MIN
61
+ } else {
62
+ dragging.type = dragType.MAX
63
+ }
64
+
65
+ return dragging
66
+ }
67
+
68
+ export function updatePosition(
69
+ event: MouseEvent,
70
+ dragging: Dragging,
71
+ getDraggingRatioFn: (event: MouseEvent, dragging: Dragging) => number,
72
+ convertRatioToModelFn: (ratio: number) => number,
73
+ convertModelToRatioFn: (model: number) => number,
74
+ props: {
75
+ min: number
76
+ max: number
77
+ snap: boolean
78
+ },
79
+ state: {
80
+ step: number
81
+ decimals: number
82
+ },
83
+ model: {
84
+ min: number | null
85
+ max: number | null
86
+ }
87
+ ): {
88
+ model: RangeValue
89
+ focus: 'min' | 'max'
90
+ curRatio: RangeValue
91
+ } {
92
+ let pos: {
93
+ minR: number
94
+ maxR: number
95
+ min: number
96
+ max: number
97
+ }
98
+
99
+ let focus: 'min' | 'max'
100
+ let curRatio: RangeValue
101
+
102
+ const ratio = getDraggingRatioFn(event, dragging)
103
+ const localModel = convertRatioToModelFn(ratio)
104
+
105
+ switch (dragging.type) {
106
+ case dragType.MIN:
107
+ if (ratio <= dragging.ratioMax) {
108
+ pos = {
109
+ minR: ratio,
110
+ maxR: dragging.ratioMax,
111
+ min: localModel,
112
+ max: dragging.valueMax
113
+ }
114
+ focus = 'min'
115
+ } else {
116
+ pos = {
117
+ minR: dragging.ratioMax,
118
+ maxR: ratio,
119
+ min: dragging.valueMax,
120
+ max: localModel
121
+ }
122
+ focus = 'max'
123
+ }
124
+ break
125
+
126
+ case dragType.MAX:
127
+ if (ratio >= dragging.ratioMin) {
128
+ pos = {
129
+ minR: dragging.ratioMin,
130
+ maxR: ratio,
131
+ min: dragging.valueMin,
132
+ max: localModel
133
+ }
134
+ focus = 'max'
135
+ } else {
136
+ pos = {
137
+ minR: ratio,
138
+ maxR: dragging.ratioMin,
139
+ min: localModel,
140
+ max: dragging.valueMin
141
+ }
142
+ focus = 'min'
143
+ }
144
+ break
145
+ }
146
+
147
+ const newModel =
148
+ model.min === null || model.max === null
149
+ ? { min: pos!.min || props.min, max: pos!.max || props.max }
150
+ : { min: pos!.min, max: pos!.max }
151
+
152
+ if (props.snap !== true || state.step === 0) {
153
+ curRatio = {
154
+ min: pos!.minR,
155
+ max: pos!.maxR
156
+ }
157
+ } else {
158
+ curRatio = {
159
+ min: convertModelToRatioFn(model.min!),
160
+ max: convertModelToRatioFn(model.max!)
161
+ }
162
+ }
163
+
164
+ return {
165
+ model: newModel,
166
+ // @ts-ignore
167
+ focus,
168
+ curRatio
169
+ }
170
+ }
171
+
172
+ export function onKeydown(
173
+ evt: KeyboardEvent,
174
+ state: {
175
+ step: number
176
+ focus: 'min' | 'max'
177
+ decimals: number
178
+ },
179
+ props: RangeValue,
180
+ model: RangeValue
181
+ ): { model: RangeValue } {
182
+ const stepVal =
183
+ (includes([KEY_CODE.PGDOWN, KEY_CODE.PGUP], Number(evt.code))
184
+ ? 10
185
+ : 1) * state.step
186
+
187
+ const offset =
188
+ (includes(
189
+ [KEY_CODE.PGDOWN, KEY_CODE.LEFT, KEY_CODE.DOWN],
190
+ Number(evt.code)
191
+ )
192
+ ? -1
193
+ : 1) * stepVal
194
+
195
+ const which: 'min' | 'max' = state.focus
196
+
197
+ const newModel = {
198
+ ...model,
199
+ [which]: between(
200
+ parseFloat((model[which] + offset).toFixed(state.decimals)),
201
+ which === 'min' ? props.min : model.min,
202
+ which === 'max' ? props.max : model.max
203
+ )
204
+ }
205
+
206
+ return {
207
+ model: newModel
208
+ }
209
+ }