@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,277 @@
1
+ import {
2
+ ref,
3
+ computed,
4
+ onBeforeUnmount,
5
+ getCurrentInstance,
6
+ Ref
7
+ } from 'vue-demi'
8
+
9
+ import { useFormProps, FormProps } from '../../hooks/useForm'
10
+
11
+ import { includes, keyCodes, between, position } from '../../utils'
12
+
13
+ export interface SliderProps extends FormProps {
14
+ text: string
15
+ width: string
16
+ min: number
17
+ max: number
18
+ step: number
19
+ snap: boolean
20
+ color: string
21
+ textColor: string
22
+ thumbSize: string
23
+ trackSize: string
24
+ readonly: boolean
25
+ disabled: boolean
26
+ tabindex: number | string
27
+ }
28
+
29
+ export type Dragging = DOMRect & {
30
+ ratioMin: number
31
+ ratioMax: number
32
+ valueMin: number
33
+ valueMax: number
34
+ offsetRatio: number
35
+ rangeRatio: number
36
+ offsetModel: number
37
+ rangeValue: number
38
+ type?: typeof dragType[keyof typeof dragType]
39
+ }
40
+
41
+ export const dragType = {
42
+ MIN: 0,
43
+ RANGE: 1,
44
+ MAX: 2
45
+ }
46
+
47
+ export const useSliderProps = {
48
+ ...useFormProps,
49
+ text: {
50
+ type: String,
51
+ required: true,
52
+ default: ''
53
+ },
54
+ width: {
55
+ type: String,
56
+ default: '100%'
57
+ },
58
+ min: {
59
+ type: Number,
60
+ default: 0
61
+ },
62
+ max: {
63
+ type: Number,
64
+ default: 100
65
+ },
66
+ step: {
67
+ type: Number,
68
+ default: 1,
69
+ validator: (v: number) => v >= 0
70
+ },
71
+ snap: {
72
+ type: Boolean,
73
+ default: false
74
+ },
75
+ color: {
76
+ type: String,
77
+ default: 'dl-color-secondary'
78
+ },
79
+ textColor: {
80
+ type: String,
81
+ default: 'dl-color-darker'
82
+ },
83
+ thumbSize: {
84
+ type: String,
85
+ default: '10px'
86
+ },
87
+ trackSize: {
88
+ type: String,
89
+ default: '3px'
90
+ },
91
+ disabled: {
92
+ type: Boolean,
93
+ default: false
94
+ },
95
+ readonly: {
96
+ type: Boolean,
97
+ default: false
98
+ },
99
+ tabindex: {
100
+ type: [String, Number],
101
+ default: '0'
102
+ }
103
+ }
104
+
105
+ export const useSliderEmits = ['pan', 'update:model-value', 'change']
106
+
107
+ export default function ({
108
+ updateValue,
109
+ updatePosition,
110
+ getDragging
111
+ }: {
112
+ updateValue: Function
113
+ updatePosition: Function
114
+ getDragging: Function
115
+ }) {
116
+ const { props, emit }: { props: any; emit: any } = getCurrentInstance()!
117
+
118
+ const active: Ref<boolean> = ref(false)
119
+ const focus: Ref<'min' | 'max' | boolean> = ref(false)
120
+ const dragging: Ref<Dragging | boolean | undefined> = ref(false)
121
+
122
+ const editable = computed(
123
+ () =>
124
+ props.disabled !== true &&
125
+ props.readonly !== true &&
126
+ props.min < props.max
127
+ )
128
+
129
+ const decimals = computed(
130
+ () => (String(props.step).trim().split('.')[1] || '').length
131
+ )
132
+ const step = computed(() => (props.step === 0 ? 1 : props.step))
133
+ const tabindex = computed(() =>
134
+ editable.value === true ? props.tabindex || 0 : -1
135
+ )
136
+
137
+ const trackLen = computed(() => props.max - props.min)
138
+
139
+ const minRatio = computed(() => convertModelToRatio(props.min))
140
+ const maxRatio = computed(() => convertModelToRatio(props.max))
141
+
142
+ const attributes: Record<string, any> = computed(() => {
143
+ const acc: Record<string, any> = {
144
+ role: 'slider',
145
+ 'aria-valuemin': props.min,
146
+ 'aria-valuemax': props.max,
147
+ 'aria-orientation': 'horizontal',
148
+ 'data-step': props.step
149
+ }
150
+
151
+ if (props.disabled === true) {
152
+ acc['aria-disabled'] = 'true'
153
+ } else if (props.readonly === true) {
154
+ acc['aria-readonly'] = 'true'
155
+ }
156
+
157
+ return acc
158
+ })
159
+
160
+ function convertRatioToModel(ratio: number) {
161
+ const { min, max, step } = props
162
+
163
+ let model = min + ratio * (max - min)
164
+
165
+ if (step > 0) {
166
+ const modulo = (model - min) % step
167
+ model +=
168
+ (Math.abs(modulo) >= step / 2
169
+ ? (modulo < 0 ? -1 : 1) * step
170
+ : 0) - modulo
171
+ }
172
+
173
+ if (decimals.value > 0) {
174
+ model = parseFloat(model.toFixed(decimals.value))
175
+ }
176
+
177
+ return between(model, min, max)
178
+ }
179
+
180
+ function convertModelToRatio(model: number) {
181
+ return trackLen.value === 0 ? 0 : (model - props.min) / trackLen.value
182
+ }
183
+
184
+ function getDraggingRatio(evt: MouseEvent, dragging: Dragging) {
185
+ const pos = position(evt)
186
+ const val = between((pos.left - dragging.left) / dragging.width, 0, 1)
187
+
188
+ return between(val, minRatio.value, maxRatio.value)
189
+ }
190
+
191
+ function onPan(event: any) {
192
+ if (event.isFinal === true) {
193
+ if (dragging.value !== void 0) {
194
+ updatePosition(event.evt)
195
+ // only if touch, because we also have mousedown/up:
196
+ if (event.touch === true) {
197
+ updateValue(true)
198
+ }
199
+ dragging.value = void 0
200
+ emit('pan', 'end')
201
+ }
202
+ active.value = false
203
+ focus.value = false
204
+ } else if (event.isFirst === true) {
205
+ dragging.value = getDragging(event.evt)
206
+ updatePosition(event.evt)
207
+ updateValue()
208
+ active.value = true
209
+ emit('pan', 'start')
210
+ } else {
211
+ updatePosition(event.evt)
212
+ updateValue()
213
+ }
214
+ }
215
+
216
+ function onBlur() {
217
+ focus.value = false
218
+ }
219
+
220
+ function onActivate(evt: any) {
221
+ updatePosition(evt, getDragging(evt))
222
+ updateValue()
223
+
224
+ active.value = true
225
+
226
+ document.addEventListener('mouseup', onDeactivate, true)
227
+ }
228
+
229
+ function onDeactivate() {
230
+ active.value = false
231
+
232
+ updateValue(true)
233
+ onBlur()
234
+
235
+ document.removeEventListener('mouseup', onDeactivate, true)
236
+ }
237
+
238
+ function onMobileClick(evt: any) {
239
+ updatePosition(evt, getDragging(evt))
240
+ updateValue(true)
241
+ }
242
+
243
+ function onKeyup(evt: KeyboardEvent) {
244
+ if (includes(keyCodes, Number(evt.code))) {
245
+ updateValue(true)
246
+ }
247
+ }
248
+
249
+ onBeforeUnmount(() => {
250
+ document.removeEventListener('mouseup', onDeactivate, true)
251
+ })
252
+
253
+ return {
254
+ state: {
255
+ active,
256
+ focus,
257
+ dragging,
258
+ editable,
259
+ tabindex,
260
+ attributes,
261
+ step,
262
+ decimals
263
+ },
264
+
265
+ methods: {
266
+ onActivate,
267
+ onDeactivate,
268
+ onMobileClick,
269
+ onBlur,
270
+ onKeyup,
271
+ convertRatioToModel,
272
+ convertModelToRatio,
273
+ getDraggingRatio,
274
+ onPan
275
+ }
276
+ }
277
+ }
@@ -0,0 +1,7 @@
1
+ export const getInputValue = (value: string, min: number, max: number) => {
2
+ if (parseInt(value) > max || parseInt(value) < min) {
3
+ return { value: (parseInt(value) > max ? max : min).toString() }
4
+ }
5
+
6
+ return { value }
7
+ }
@@ -0,0 +1,309 @@
1
+ <template>
2
+ <div class="json-editor-layout">
3
+ <dl-dialog-box
4
+ :model-value="modelValue"
5
+ :width="800"
6
+ >
7
+ <template #header>
8
+ <dl-dialog-box-header
9
+ title="DQL Search"
10
+ :close-button="true"
11
+ style="font-weight: 200"
12
+ @onClose="$emit('update:modelValue', false)"
13
+ />
14
+ </template>
15
+ <template #body>
16
+ <div class="json-query">
17
+ <div class="json-query-menu">
18
+ <dl-select
19
+ :model-value="selectedOption"
20
+ width="200px"
21
+ :options="selectOptions"
22
+ placeholder="New Query"
23
+ @update:model-value="updateActiveQuery"
24
+ />
25
+ <dl-button
26
+ icon="icon-dl-align-left"
27
+ label="Align Left"
28
+ flat
29
+ color="secondary"
30
+ @click="alignText"
31
+ />
32
+ </div>
33
+ <div
34
+ ref="jsonEditorRef"
35
+ class="json-editor"
36
+ />
37
+ <dl-typography
38
+ style="margin-top: 5px"
39
+ variant="p"
40
+ color="red"
41
+ >
42
+ {{ message }}
43
+ </dl-typography>
44
+ </div>
45
+ </template>
46
+ <template #footer>
47
+ <div class="footer-menu">
48
+ <div class="footer-delete">
49
+ <dl-button
50
+ :disabled="deleteButtonState"
51
+ icon="icon-dl-delete"
52
+ label="Delete Query"
53
+ flat
54
+ color="secondary"
55
+ @click="$emit('remove', activeQuery)"
56
+ />
57
+ </div>
58
+ <div class="footer-save">
59
+ <dl-button
60
+ :disabled="message !== ''"
61
+ outlined
62
+ label="Save As"
63
+ @click="save"
64
+ />
65
+ <dl-button
66
+ :disabled="message !== ''"
67
+ label="Search"
68
+ @click="$emit('search', activeQuery)"
69
+ />
70
+ </div>
71
+ </div>
72
+ </template>
73
+ </dl-dialog-box>
74
+ </div>
75
+ </template>
76
+
77
+ <script lang="ts">
78
+ import { defineComponent, PropType } from 'vue-demi'
79
+ import { JSONEditor, JSONValue, Mode } from 'vanilla-jsoneditor'
80
+ import { debounce } from 'lodash'
81
+ import { Query } from './types'
82
+ import DlDialogBox from '../DlDialogBox/DlDialogBox.vue'
83
+ import DlDialogBoxHeader from '../DlDialogBox/DlDialogBoxHeader.vue'
84
+ import DlSelect from '../DlSelect/DlSelect.vue'
85
+ import DlButton from '../DlButton/DlButton.vue'
86
+ import DlTypography from '../DlTypography.vue'
87
+
88
+ interface JSONContent {
89
+ json: JSONValue
90
+ text: string
91
+ }
92
+
93
+ export default defineComponent({
94
+ components: {
95
+ DlDialogBox,
96
+ DlDialogBoxHeader,
97
+ DlSelect,
98
+ DlButton,
99
+ DlTypography
100
+ },
101
+ props: {
102
+ modelValue: { type: Boolean, default: false },
103
+ query: {
104
+ type: Object as PropType<Query>,
105
+ default: () =>
106
+ ({
107
+ name: 'New Query',
108
+ query: null
109
+ } as Query)
110
+ },
111
+ queries: {
112
+ type: Array as PropType<Query[]>,
113
+ default: () => [] as Query[]
114
+ }
115
+ },
116
+ emits: ['update:modelValue', 'save', 'remove'],
117
+ data() {
118
+ return {
119
+ preventOnChange: false,
120
+ preventUpdate: false,
121
+ jsonEditor: {} as JSONEditor,
122
+ activeQuery: this.query,
123
+ selectedOption: {
124
+ label: this.query?.name,
125
+ value: this.query?.query
126
+ },
127
+ message: ''
128
+ }
129
+ },
130
+ computed: {
131
+ selectOptions(): Record<string, string>[] {
132
+ return [
133
+ {
134
+ label: 'New Query',
135
+ value: ''
136
+ },
137
+ ...this.queries.map((q: Query) => ({
138
+ label: q.name,
139
+ value: q.query
140
+ }))
141
+ ]
142
+ },
143
+ deleteButtonState(): boolean {
144
+ return !this.queries.filter(
145
+ (q: Query) => q.name === this.activeQuery?.name
146
+ ).length
147
+ }
148
+ },
149
+ watch: {
150
+ modelValue(value) {
151
+ this.$nextTick(() => {
152
+ if (value) this.initJsonEditor()
153
+ else this.jsonEditor?.destroy()
154
+ this.activeQuery = this.query
155
+ })
156
+ },
157
+ queries() {
158
+ this.resetEditor()
159
+ },
160
+ query(val) {
161
+ this.$nextTick(() => {
162
+ if (val.name === 'New Query') return
163
+ this.selectedOption = {
164
+ label: val.name,
165
+ value: val.query
166
+ }
167
+ if (val.query && this.jsonEditor.set) {
168
+ this.jsonEditor.set({
169
+ text: val.query
170
+ })
171
+ }
172
+ this.alignText()
173
+ })
174
+ },
175
+ activeQuery(val) {
176
+ try {
177
+ if (val.query) JSON.parse(val.query)
178
+ this.message = ''
179
+ } catch {
180
+ this.message = 'Invalid Query.'
181
+ }
182
+ }
183
+ },
184
+ mounted() {
185
+ this.initJsonEditor()
186
+ },
187
+ methods: {
188
+ updateActiveQuery(option: Record<string, string>) {
189
+ this.activeQuery = {
190
+ name: option.label,
191
+ query: option.value
192
+ }
193
+ this.jsonEditor?.destroy()
194
+ this.initJsonEditor()
195
+ },
196
+ alignText() {
197
+ if (!(this.jsonEditor.get && this.jsonEditor.get())) return
198
+ try {
199
+ const parsed = JSON.parse(
200
+ (
201
+ this.jsonEditor.get &&
202
+ (this.jsonEditor?.get() as JSONContent)
203
+ )?.text
204
+ )
205
+ const newText = JSON.stringify(parsed, null, 2)
206
+ this.jsonEditor?.set({ text: newText })
207
+ } catch (error) {}
208
+ },
209
+ resetEditor() {
210
+ if (this.jsonEditor.set) {
211
+ this.jsonEditor.set({
212
+ text: '{}'
213
+ })
214
+ }
215
+ this.selectedOption = {
216
+ label: 'New Query',
217
+ value: ''
218
+ }
219
+ },
220
+ initJsonEditor() {
221
+ const initialAttrs: any = {
222
+ onChange: debounce(
223
+ (updatedContent: { text: string; json: any }) => {
224
+ if (this.preventOnChange) {
225
+ this.preventOnChange = false
226
+ return
227
+ }
228
+ this.activeQuery = {
229
+ name: this.activeQuery
230
+ ? this.activeQuery.name
231
+ : 'New Query',
232
+ query: updatedContent.text
233
+ }
234
+ this.preventUpdate = true
235
+ },
236
+ 100
237
+ ),
238
+ mode: Mode.text,
239
+ mainMenuBar: false,
240
+ navigationBar: false,
241
+ statusBar: false,
242
+ ...(this.activeQuery !== undefined && {
243
+ content: {
244
+ text: this.activeQuery?.query
245
+ ? this.activeQuery.query
246
+ : '{}'
247
+ }
248
+ })
249
+ }
250
+
251
+ // There is type instantiation issue with JSONEditor,
252
+ // it gives excessively deep and possibly infinite error
253
+ // @ts-ignore
254
+ this.jsonEditor = new JSONEditor({
255
+ target: this.$refs.jsonEditorRef
256
+ ? (this.$refs.jsonEditorRef as Element)
257
+ : document.createElement('div'),
258
+ props: initialAttrs
259
+ })
260
+ this.alignText()
261
+ },
262
+ save() {
263
+ this.$emit(
264
+ 'save',
265
+ this.activeQuery
266
+ ? this.activeQuery
267
+ : {
268
+ name: 'New Query',
269
+ query: (this.jsonEditor?.get() as any).text || ''
270
+ }
271
+ )
272
+ }
273
+ }
274
+ })
275
+ </script>
276
+
277
+ <style lang="scss">
278
+ .json-editor {
279
+ --jse-text-color: var(--dl-color-tooltip-background);
280
+ --jse-delimiter-color: var(--dl-color-tooltip-background);
281
+ --jse-key-color: var(--dl-color-negative);
282
+ --jse-background-color: var(--dl-color-tooltip-text);
283
+ --jse-value-color-boolean: #ae6307;
284
+ --jse-value-color-string: #337433;
285
+ .jse-error {
286
+ display: none !important;
287
+ }
288
+ .cm-gutters {
289
+ display: none !important;
290
+ }
291
+ }
292
+
293
+ .json-query-menu {
294
+ display: flex;
295
+ justify-content: space-between;
296
+ align-items: center;
297
+ margin-bottom: 10px;
298
+ }
299
+
300
+ .footer-save button {
301
+ margin: 0px 10px;
302
+ }
303
+
304
+ .footer-menu {
305
+ width: 100%;
306
+ display: flex;
307
+ justify-content: space-between;
308
+ }
309
+ </style>