@dataloop-ai/components 0.17.92 → 0.17.94

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dataloop-ai/components",
3
- "version": "0.17.92",
3
+ "version": "0.17.94",
4
4
  "exports": {
5
5
  ".": "./index.ts",
6
6
  "./models": "./models.ts",
@@ -4,11 +4,9 @@
4
4
  ref="dlEllipsisRef"
5
5
  class="dl-ellipsis__left"
6
6
  >
7
- <slot
8
- v-if="hasDefaultSlot"
9
- name="default"
10
- />
11
- <span v-else>{{ leftText }}</span>
7
+ <slot>
8
+ <span>{{ leftText }}</span>
9
+ </slot>
12
10
  </span>
13
11
  <span
14
12
  v-if="rightText"
@@ -23,17 +21,15 @@
23
21
  :anchor="tooltipPosition"
24
22
  :offset="tooltipOffset"
25
23
  >
26
- <slot
27
- v-if="hasDefaultSlot"
28
- name="default"
29
- />
30
- <span v-else>{{ fullText }}</span>
24
+ <slot>
25
+ <span>{{ fullText }}</span>
26
+ </slot>
31
27
  </dl-tooltip>
32
28
  </div>
33
29
  </template>
34
30
 
35
31
  <script lang="ts">
36
- import { defineComponent, ref, computed } from 'vue-demi'
32
+ import { defineComponent, ref, computed, toRef } from 'vue-demi'
37
33
  import DlTooltip from '../../essential/DlTooltip/DlTooltip.vue'
38
34
  import { useSizeObserver } from '../../../hooks/use-size-observer'
39
35
 
@@ -84,31 +80,31 @@ export default defineComponent({
84
80
  // TODO: fix type issue here
85
81
  setup(props: any, { slots }: any) {
86
82
  const dlEllipsisRef = ref(null)
83
+ const textRef = toRef(props, 'text')
87
84
  const { hasEllipsis } = useSizeObserver(dlEllipsisRef)
88
-
89
85
  const hasDefaultSlot = computed(() => !!slots.default)
90
86
  const splitIndex = computed(() => {
91
- if (!props.text.length) return null
87
+ if (!textRef.value.length) return null
92
88
  return props.split
93
- ? Math.round(props.text.length * props.splitPosition)
94
- : props.text.length
89
+ ? Math.round(textRef.value.length * props.splitPosition)
90
+ : textRef.value.length
95
91
  })
96
92
  const leftText = computed(() => {
97
93
  if (splitIndex.value !== null) {
98
- return props.text.slice(0, splitIndex.value)
94
+ return textRef.value.slice(0, splitIndex.value)
99
95
  }
100
96
  return ''
101
97
  })
102
98
  const rightText = computed(() => {
103
99
  if (splitIndex.value !== null) {
104
- return props.text.slice(splitIndex.value)
100
+ return textRef.value.slice(splitIndex.value)
105
101
  }
106
102
  return ''
107
103
  })
108
104
  const shouldShowTooltip = computed(
109
105
  () => hasEllipsis.value && props.tooltip
110
106
  )
111
- const fullText = computed(() => props.text)
107
+ const fullText = computed(() => textRef.value)
112
108
 
113
109
  return {
114
110
  hasDefaultSlot,
@@ -394,10 +394,18 @@ export default defineComponent({
394
394
  modelValue(value: string) {
395
395
  const target = this.$refs['input'] as HTMLInputElement
396
396
  value = value?.replaceAll(' ', ' ') ?? ''
397
- if (!this.isTyping) target.innerHTML = value
397
+ /*
398
+ * I commented out this line because it was blocking arrow navigation
399
+ * */
400
+ // if (!this.isTyping) target.innerHTML = value
401
+ target.innerHTML = value
398
402
  updateEditor(this.styleModel)
399
403
  this.setMenuOffset(isEligibleToChange(target, this.expanded))
400
- if (!this.isTyping) setCaret(target)
404
+ /*
405
+ * I commented out this line because it was blocking arrow navigation
406
+ * */
407
+ // if (!this.isTyping) setCaret(target)
408
+ setCaret(target)
401
409
  if (!this.expanded) {
402
410
  this.isOverflow =
403
411
  isEllipsisActive(this.$refs['input'] as Element) ||
@@ -286,7 +286,6 @@
286
286
  :label="arrowNavigationLabel"
287
287
  main-button-style="width: 150px;"
288
288
  :overflow="true"
289
- disabled
290
289
  :no-wrap="true"
291
290
  tooltip="Tooltip message"
292
291
  :arrow-nav-items="listItems"
@@ -524,6 +524,8 @@ import {
524
524
  import { defineComponent, onMounted, ref, watch } from 'vue-demi'
525
525
  import { useArrowNavigation } from '../hooks/use-arrow-navigation'
526
526
 
527
+ type ItemType = Record<string, any> | string
528
+
527
529
  export default defineComponent({
528
530
  name: 'DlMenuDemo',
529
531
  components: {
@@ -537,7 +539,7 @@ export default defineComponent({
537
539
  setup() {
538
540
  const showing = ref(false)
539
541
  const isMenuOpen = ref(false)
540
- const arrowNavigationLabel = ref('Arrow Navigation Label')
542
+ const arrowNavigationLabel = ref<ItemType>('Arrow Navigation Label')
541
543
 
542
544
  const listItems = ref([
543
545
  'New tab',
@@ -560,7 +562,7 @@ export default defineComponent({
560
562
  isMenuOpen
561
563
  )
562
564
 
563
- watch(selectedItem, (value: string) => {
565
+ watch(selectedItem, (value: ItemType | string) => {
564
566
  arrowNavigationLabel.value = value
565
567
  })
566
568
 
@@ -1,41 +1,84 @@
1
- import { ref, onMounted, onBeforeUnmount } from 'vue-demi'
1
+ import { ref, isRef, onMounted, onBeforeUnmount, computed } from 'vue-demi'
2
+
3
+ type ItemType = Record<string, any> | string
2
4
 
3
5
  export function useArrowNavigation(items: any, isOpen: any) {
4
- const selectedItem = ref(null)
5
- const highlightedIndex = ref(-1)
6
+ const selectItem = ref<ItemType | null>(null)
7
+ const highlightIndex = ref<number>(-1)
8
+
9
+ const itemsData = computed(() => (isRef(items) ? items.value : items))
10
+ const isMenuOpen = computed(() => (isRef(isOpen) ? isOpen.value : isOpen))
6
11
 
7
- const handleArrowUp = () => {
8
- if (highlightedIndex.value > 0) {
9
- highlightedIndex.value--
12
+ const selectedItem = computed({
13
+ get: () => selectItem.value,
14
+ set: (value: ItemType) => {
15
+ selectItem.value = value
10
16
  }
11
- }
12
- const handleArrowDown = () => {
13
- if (highlightedIndex.value < items.value.length - 1) {
14
- highlightedIndex.value++
17
+ })
18
+ const highlightedIndex = computed({
19
+ get: () => highlightIndex.value,
20
+ set: (value: number) => {
21
+ highlightIndex.value = value
15
22
  }
23
+ })
24
+
25
+ const itemsLength = computed<number>(() => itemsData.value.length)
26
+
27
+ const decrementHighlightedIndex = (): void => {
28
+ highlightedIndex.value -= 1
16
29
  }
17
- const handleEnter = () => {
18
- if (
30
+ const incrementHighlightedIndex = (): void => {
31
+ highlightedIndex.value += 1
32
+ }
33
+ const resetHighlightedIndex = (): void => {
34
+ highlightedIndex.value = -1
35
+ }
36
+
37
+ const isEligibleToHandleEnter = computed<boolean>(() => {
38
+ return (
19
39
  highlightedIndex.value >= 0 &&
20
- highlightedIndex.value < items.value.length
21
- ) {
22
- selectedItem.value = items.value[highlightedIndex.value]
23
- resetNavigation()
40
+ highlightedIndex.value < itemsLength.value
41
+ )
42
+ })
43
+ const isEligibleToIncrementHighlightedIndex = computed<boolean>(() => {
44
+ return highlightedIndex.value < itemsLength.value - 1
45
+ })
46
+ const isEligibleToDecrementHighlightedIndex = computed<boolean>(() => {
47
+ return highlightedIndex.value > 0
48
+ })
49
+ const isNotEligibleToHandleArrows = computed<boolean>(() => {
50
+ return !itemsLength.value || !isMenuOpen.value
51
+ })
52
+
53
+ const handleArrowUp = (event: KeyboardEvent) => {
54
+ event.preventDefault()
55
+ if (isEligibleToDecrementHighlightedIndex.value) {
56
+ decrementHighlightedIndex()
24
57
  }
25
58
  }
26
- const resetNavigation = () => {
27
- highlightedIndex.value = -1
59
+ const handleArrowDown = (event: KeyboardEvent) => {
60
+ event.preventDefault()
61
+ if (isEligibleToIncrementHighlightedIndex.value) {
62
+ incrementHighlightedIndex()
63
+ }
28
64
  }
65
+ const handleEnter = () => {
66
+ if (isEligibleToHandleEnter.value) {
67
+ selectedItem.value = itemsData.value[highlightedIndex.value]
68
+ resetHighlightedIndex()
69
+ }
70
+ }
71
+
29
72
  const navigateList = (event: KeyboardEvent) => {
30
- if (!items.value?.length || !isOpen.value) {
73
+ if (isNotEligibleToHandleArrows.value) {
31
74
  return
32
75
  }
33
76
  switch (event.key) {
34
77
  case 'ArrowUp':
35
- handleArrowUp()
78
+ handleArrowUp(event)
36
79
  break
37
80
  case 'ArrowDown':
38
- handleArrowDown()
81
+ handleArrowDown(event)
39
82
  break
40
83
  case 'Enter':
41
84
  handleEnter()