@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,438 @@
1
+ <template>
2
+ <dl-teleport
3
+ v-if="portalIsActive"
4
+ :to="portalEl"
5
+ >
6
+ <transition
7
+ name="fade"
8
+ appear
9
+ >
10
+ <div
11
+ v-if="showing"
12
+ :id="uuid"
13
+ ref="innerRef"
14
+ tabIndex="-1"
15
+ :class="classes"
16
+ :style="styles"
17
+ @click="onClick"
18
+ >
19
+ <slot />
20
+ </div>
21
+ </transition>
22
+ </dl-teleport>
23
+ </template>
24
+
25
+ <script lang="ts">
26
+ import {
27
+ h as _h,
28
+ defineComponent,
29
+ onBeforeUnmount,
30
+ getCurrentInstance,
31
+ ref,
32
+ watch,
33
+ computed,
34
+ PropType,
35
+ Ref,
36
+ isVue2
37
+ } from 'vue-demi'
38
+
39
+ import useWindowSize from '../../hooks/use-window-size'
40
+ import useAnchor, { useAnchorProps } from '../../hooks/use-anchor'
41
+ import useScrollTarget from '../../hooks/use-scroll-target'
42
+ import useModelToggle, {
43
+ useModelToggleProps,
44
+ useModelToggleEmits,
45
+ AnchorEvent
46
+ } from '../../hooks/use-model-toggle'
47
+ import usePortal from '../../hooks/use-portal'
48
+ import useTransition, { useTransitionProps } from '../../hooks/use-transition'
49
+ import useTick from '../../hooks/use-tick'
50
+ import useTimeout from '../../hooks/use-timeout'
51
+
52
+ import { closePortalMenus } from '../../utils/portal'
53
+ import { getScrollTarget } from '../../utils/scroll'
54
+ import DlTeleport from '../../utils/teleport'
55
+ import { removeEscapeKey } from '../../utils/escape-key'
56
+ import {
57
+ removeClickOutside,
58
+ ClickOutsideEvent
59
+ } from '../../utils/click-outside'
60
+ import { addFocusFn } from '../../utils/focus-manager'
61
+
62
+ import {
63
+ validatePosition,
64
+ validateOffset,
65
+ setPosition,
66
+ parsePosition
67
+ } from '../../utils/position-engine'
68
+ import {
69
+ handleClickOutside,
70
+ getAnchorOrigin,
71
+ handleWatcherEvents,
72
+ setOffsetOnShow,
73
+ avoidAutoCloseFn,
74
+ updateUnwatchPosition,
75
+ refocusTargetFn,
76
+ conditionalHandler
77
+ } from './utils'
78
+ import { isMobileOrTablet } from '../../utils'
79
+ import { v4 } from 'uuid'
80
+
81
+ export default defineComponent({
82
+ name: 'DlMenu',
83
+ components: {
84
+ DlTeleport
85
+ },
86
+ inheritAttrs: false,
87
+ model: {
88
+ prop: 'modelValue',
89
+ event: 'update:model-value'
90
+ },
91
+ props: {
92
+ ...useAnchorProps,
93
+ ...useModelToggleProps,
94
+ ...useTransitionProps,
95
+ disabled: Boolean,
96
+ persistent: Boolean,
97
+ autoClose: Boolean,
98
+
99
+ noRefocus: Boolean,
100
+
101
+ fit: Boolean,
102
+ cover: Boolean,
103
+
104
+ square: Boolean,
105
+
106
+ anchor: {
107
+ type: String,
108
+ default: 'bottom left',
109
+ validator: validatePosition
110
+ },
111
+ self: {
112
+ type: String,
113
+ default: 'top left',
114
+ validator: validatePosition
115
+ },
116
+ offset: {
117
+ type: Array,
118
+ default: () => [0, 0],
119
+ validator: validateOffset
120
+ },
121
+
122
+ scrollTarget: {
123
+ type: String as PropType<Element | string>,
124
+ default: void 0
125
+ },
126
+
127
+ touchPosition: Boolean,
128
+
129
+ maxHeight: {
130
+ type: String,
131
+ default: null
132
+ },
133
+ maxWidth: {
134
+ type: String,
135
+ default: null
136
+ },
137
+ menuClass: {
138
+ type: String,
139
+ default: ''
140
+ }
141
+ },
142
+
143
+ emits: [...useModelToggleEmits, 'click', 'escape-key'],
144
+
145
+ setup(props, { attrs }) {
146
+ const vm = getCurrentInstance()
147
+
148
+ let refocusTarget: HTMLElement | Element | null = null
149
+ let absoluteOffset: Record<any, any> | undefined
150
+ let unwatchPosition: Function | undefined
151
+ let avoidAutoClose: boolean = false
152
+
153
+ const proxy = vm!.proxy!
154
+ const emit = vm!.emit!
155
+
156
+ const innerRef: Ref<HTMLElement | null> = ref(null)
157
+ const showing = ref(false)
158
+
159
+ const { registerTick, removeTick } = useTick()
160
+ const { registerTimeout, removeTimeout } = useTimeout()
161
+ const { transitionStyle } = useTransition(props, showing)
162
+ const {
163
+ localScrollTarget,
164
+ changeScrollEvent,
165
+ unconfigureScrollTarget
166
+ } = useScrollTarget(props, configureScrollTarget)
167
+
168
+ const { anchorEl, canShow } = useAnchor({})
169
+
170
+ const screen = useWindowSize()
171
+
172
+ const classes = computed(
173
+ () =>
174
+ ' ' +
175
+ props.menuClass +
176
+ (props.square === true ? ' dl-menu--square' : '')
177
+ )
178
+
179
+ const { hide } = useModelToggle({
180
+ showing,
181
+ canShow,
182
+ handleShow,
183
+ handleHide,
184
+ processOnMount: true
185
+ })
186
+
187
+ const {
188
+ showPortal,
189
+ hidePortal,
190
+ portalEl,
191
+ portalIsActive,
192
+ portalIsAccessible
193
+ } = usePortal(vm, innerRef)
194
+
195
+ const clickOutsideProps = {
196
+ anchorEl,
197
+ innerRef,
198
+ onClickOutside: (e: AnchorEvent) =>
199
+ handleClickOutside(e, {
200
+ persistent: props.persistent,
201
+ showing: showing.value,
202
+ fn: hide
203
+ })
204
+ }
205
+
206
+ const anchorOrigin = computed(() =>
207
+ getAnchorOrigin(props.anchor, props.cover)
208
+ )
209
+
210
+ const selfOrigin = computed(() =>
211
+ props.cover === true
212
+ ? anchorOrigin.value
213
+ : parsePosition(props.self || 'top start')
214
+ )
215
+
216
+ const onClick = props.autoClose === true ? onAutoClose : () => {}
217
+
218
+ const handlesFocus = computed(
219
+ () => showing.value === true && props.persistent !== true
220
+ )
221
+
222
+ watch(handlesFocus, (val) =>
223
+ handleWatcherEvents(val, onEscapeKey, clickOutsideProps)
224
+ )
225
+
226
+ function focus() {
227
+ addFocusFn(() => {
228
+ let node = innerRef.value as unknown as HTMLElement
229
+
230
+ if (node && node.contains(document.activeElement) !== true) {
231
+ node =
232
+ node.querySelector('[autofocus], [data-autofocus]') ||
233
+ node
234
+ node.focus({ preventScroll: true })
235
+ }
236
+ })
237
+ }
238
+
239
+ const isMobile = computed(() => isMobileOrTablet())
240
+
241
+ function handleShow(evt: MouseEvent | TouchEvent) {
242
+ removeTick()
243
+ removeTimeout()
244
+
245
+ refocusTarget =
246
+ props.noRefocus === false ? document.activeElement : null
247
+
248
+ showPortal()
249
+ configureScrollTarget()
250
+
251
+ absoluteOffset = void 0
252
+
253
+ const offsetOnShow = setOffsetOnShow(evt as TouchEvent, {
254
+ contextMenu: props.contextMenu,
255
+ touchPosition: props.touchPosition,
256
+ anchorEl,
257
+ absoluteOffset
258
+ })
259
+
260
+ absoluteOffset = offsetOnShow as Record<any, any> | undefined
261
+
262
+ if (unwatchPosition === void 0) {
263
+ unwatchPosition = watch(() => screen, updatePosition, {
264
+ deep: true
265
+ })
266
+ }
267
+
268
+ registerTick(() => {
269
+ updatePosition()
270
+ })
271
+
272
+ registerTimeout(() => {
273
+ // required in order to avoid the "double-tap needed" issue
274
+ avoidAutoClose = avoidAutoCloseFn(isMobile.value, {
275
+ avoidAutoClose,
276
+ autoClose: props.autoClose,
277
+ innerRef
278
+ })
279
+
280
+ updatePosition()
281
+ showPortal(true) // done showing portal
282
+ emit('show', evt)
283
+ }, props.transitionDuration)
284
+ }
285
+
286
+ function handleHide(evt: ClickOutsideEvent) {
287
+ removeTick()
288
+ removeTimeout()
289
+ hidePortal()
290
+
291
+ anchorCleanup(true)
292
+ refocusTarget = refocusTargetFn(evt, refocusTarget as HTMLElement)
293
+
294
+ registerTimeout(() => {
295
+ hidePortal(true) // done hiding, now destroy
296
+ emit('hide', evt)
297
+ }, props.transitionDuration)
298
+ }
299
+
300
+ function anchorCleanup(hiding: boolean) {
301
+ absoluteOffset = void 0
302
+
303
+ unwatchPosition = updateUnwatchPosition(unwatchPosition)
304
+
305
+ conditionalHandler(hiding || showing.value, () => {
306
+ unconfigureScrollTarget()
307
+ removeClickOutside(clickOutsideProps)
308
+ removeEscapeKey(onEscapeKey)
309
+ })
310
+
311
+ conditionalHandler(!hiding, () => {
312
+ refocusTarget = null
313
+ })
314
+ }
315
+
316
+ function configureScrollTarget() {
317
+ if (anchorEl.value !== null || props.scrollTarget !== void 0) {
318
+ (localScrollTarget as Ref<any>).value = getScrollTarget(
319
+ anchorEl.value as HTMLElement,
320
+ props.scrollTarget
321
+ )
322
+ changeScrollEvent(
323
+ (localScrollTarget as Ref<any>).value,
324
+ updatePosition
325
+ )
326
+ }
327
+ }
328
+
329
+ function onAutoClose(e: MouseEvent) {
330
+ // if auto-close, then the ios double-tap fix which
331
+ // issues a click should not close the menu
332
+ avoidAutoClose = conditionalHandler(
333
+ !avoidAutoClose,
334
+ () => {
335
+ closePortalMenus(proxy, e)
336
+ emit('click', e)
337
+ },
338
+ avoidAutoClose
339
+ ) as boolean
340
+ }
341
+
342
+ function onEscapeKey(evt: AnchorEvent) {
343
+ emit('escape-key')
344
+ hide(evt)
345
+ }
346
+
347
+ function updatePosition() {
348
+ const el = innerRef.value
349
+
350
+ if (el === null || anchorEl.value === null) {
351
+ return
352
+ }
353
+
354
+ setPosition({
355
+ el,
356
+ offset: props.offset as number[],
357
+ anchorEl: anchorEl.value as HTMLElement,
358
+ anchorOrigin: anchorOrigin.value,
359
+ selfOrigin: selfOrigin.value,
360
+ absoluteOffset,
361
+ fit: props.fit,
362
+ cover: props.cover,
363
+ maxHeight: props.maxHeight,
364
+ maxWidth: props.maxWidth
365
+ })
366
+ }
367
+
368
+ onBeforeUnmount(anchorCleanup as any)
369
+
370
+ // expose public methods
371
+ Object.assign(proxy, { focus, updatePosition })
372
+
373
+ return {
374
+ uuid: `dl-menu-${v4()}`,
375
+ onClick,
376
+ portalIsAccessible,
377
+ anchorEl,
378
+ showing,
379
+ innerRef,
380
+ portalEl: isVue2 ? '[data-test-id="portal"]' : portalEl,
381
+ portalIsActive,
382
+ classes: 'dl-menu dl-position-engine scroll' + classes.value,
383
+ styles: [attrs.style, transitionStyle.value] as any
384
+ }
385
+ }
386
+ })
387
+ </script>
388
+
389
+ <style scoped lang="scss">
390
+ .dl-menu {
391
+ position: fixed !important;
392
+ display: inline-block;
393
+ max-width: 95vw;
394
+ border: 1px solid var(--dl-color-separator);
395
+
396
+ box-shadow: var(--dl-menu-shadow);
397
+ background: var(--dl-color-panel-background);
398
+ border-radius: 2px;
399
+ overflow-y: auto;
400
+ overflow-x: hidden;
401
+ outline: 0;
402
+ max-height: 65vh;
403
+ z-index: var(--dl-z-index-menu);
404
+
405
+ &--square {
406
+ border-radius: 0;
407
+ }
408
+ }
409
+
410
+ .dl-position-engine {
411
+ margin-top: var(--dl-pe-top, 0) !important;
412
+ margin-left: var(--dl-pe-left, 0) !important;
413
+ will-change: auto;
414
+ visibility: collapse; // needed for animation - is removed on first positioning
415
+ }
416
+
417
+ .scroll {
418
+ overflow: auto;
419
+ }
420
+
421
+ .fade-enter,
422
+ .fade-enter-active {
423
+ animation: fade-in var(--dl-transition-duration);
424
+ }
425
+
426
+ .fade-leave-active,
427
+ .fade-leave-to {
428
+ animation: fade-in var(--dl-transition-duration) reverse;
429
+ }
430
+ @keyframes fade-in {
431
+ 0% {
432
+ opacity: 0;
433
+ }
434
+ 100% {
435
+ opacity: 1;
436
+ }
437
+ }
438
+ </style>
@@ -0,0 +1,3 @@
1
+ import DlMenu from './DlMenu.vue'
2
+
3
+ export { DlMenu }
@@ -0,0 +1,138 @@
1
+ import { AnchorEvent } from '../../hooks/use-model-toggle'
2
+ import { position, stopAndPrevent } from '../../utils/events'
3
+ import { parsePosition } from '../../utils/position-engine'
4
+ import { Ref } from 'vue-demi'
5
+ import { addEscapeKey, removeEscapeKey } from '../../utils/escape-key'
6
+ import {
7
+ addClickOutside,
8
+ removeClickOutside,
9
+ ClickOutsideEvent
10
+ } from '../../utils/click-outside'
11
+
12
+ interface ClickOutsideProps {
13
+ persistent: boolean
14
+ showing: boolean
15
+ fn: Function
16
+ }
17
+
18
+ interface OffsetOnShowProps {
19
+ contextMenu: boolean
20
+ touchPosition: boolean
21
+ anchorEl: Ref<Element | HTMLElement | null>
22
+ absoluteOffset: Record<any, any> | undefined
23
+ }
24
+
25
+ export const handleClickOutside = (
26
+ e: AnchorEvent,
27
+ { persistent, showing, fn }: ClickOutsideProps
28
+ ) => {
29
+ if (!persistent && showing) {
30
+ fn(e)
31
+
32
+ if (
33
+ // always prevent touch event
34
+ e.type === 'touchstart' ||
35
+ // prevent click if it's on a dialog backdrop
36
+ (e.target as HTMLElement).classList.contains('dl-dialog__backdrop')
37
+ ) {
38
+ stopAndPrevent(e)
39
+ }
40
+
41
+ return true
42
+ }
43
+ }
44
+
45
+ export const getAnchorOrigin = (anchor: string, cover: boolean) =>
46
+ parsePosition(anchor || (cover ? 'center middle' : 'bottom start'))
47
+
48
+ export const handleWatcherEvents = (
49
+ val: boolean,
50
+ escapeFn: Function,
51
+ props: any
52
+ ) => {
53
+ if (val) {
54
+ addEscapeKey(escapeFn)
55
+ addClickOutside(props)
56
+ } else {
57
+ removeEscapeKey(escapeFn)
58
+ removeClickOutside(props)
59
+ }
60
+ }
61
+ export const setOffsetOnShow = (
62
+ evt: TouchEvent,
63
+ { contextMenu, touchPosition, anchorEl, absoluteOffset }: OffsetOnShowProps
64
+ ) => {
65
+ if (evt !== void 0 && (touchPosition || contextMenu)) {
66
+ const pos = position(evt)
67
+
68
+ if (pos.top !== void 0 && pos.left !== void 0 && anchorEl.value) {
69
+ const { top, left } = anchorEl.value.getBoundingClientRect()
70
+ if (top !== void 0 && left !== void 0) {
71
+ return {
72
+ left: pos.left - left,
73
+ top: pos.top - top
74
+ }
75
+ }
76
+ }
77
+ }
78
+ return absoluteOffset
79
+ }
80
+
81
+ export const avoidAutoCloseFn = (
82
+ isIOS: boolean,
83
+ data: {
84
+ avoidAutoClose: boolean
85
+ autoClose: boolean
86
+ innerRef: Ref<HTMLElement | null>
87
+ }
88
+ ) => {
89
+ if (isIOS) {
90
+ // if auto-close, then this click should
91
+ // not close the menu
92
+ data.innerRef.value?.click()
93
+ return data.autoClose
94
+ }
95
+
96
+ return data.avoidAutoClose
97
+ }
98
+
99
+ export const updateUnwatchPosition = (
100
+ unwatchPosition: Function | undefined
101
+ ): undefined => {
102
+ if (unwatchPosition !== void 0) {
103
+ unwatchPosition()
104
+ }
105
+
106
+ return void 0
107
+ }
108
+
109
+ export const refocusTargetFn = (
110
+ evt: ClickOutsideEvent,
111
+ refocusTarget: HTMLElement | null
112
+ ): null => {
113
+ if (
114
+ refocusTarget !== null &&
115
+ // menu was hidden from code or ESC plugin
116
+ (evt === void 0 ||
117
+ // menu was not closed from a mouse or touch clickOutside
118
+ evt.dlClickOutside !== true)
119
+ ) {
120
+ (refocusTarget as HTMLElement).focus()
121
+ }
122
+
123
+ return null
124
+ }
125
+
126
+ export const conditionalHandler = (
127
+ condition: boolean,
128
+ fn: Function,
129
+ returnCondition?: boolean
130
+ ) => {
131
+ if (condition) {
132
+ fn()
133
+ }
134
+
135
+ if (returnCondition) {
136
+ return condition as boolean
137
+ }
138
+ }