@dataloop-ai/components 0.17.1 → 0.17.2

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.
@@ -14,6 +14,7 @@ import {
14
14
  ComputedRef,
15
15
  Ref
16
16
  } from 'vue-demi'
17
+ import { noop } from '../../../utils/events'
17
18
 
18
19
  export interface ScrollDetails {
19
20
  scrollStart: number
@@ -38,19 +39,26 @@ const filterProto = Array.prototype.filter
38
39
 
39
40
  const setOverflowAnchor =
40
41
  window.getComputedStyle(document.body).overflowAnchor === void 0
41
- ? () => {}
42
+ ? noop
42
43
  : function (contentEl: HTMLElement | null, index: number) {
43
44
  if (contentEl === null) {
44
45
  return
45
46
  }
46
47
 
47
- cancelAnimationFrame((contentEl as any)._dlOverflowAnimationFrame)
48
- ;(contentEl as any)._dlOverflowAnimationFrame =
48
+ if ((contentEl as any)._dlOverflowAnimationFrame !== void 0) {
49
+ cancelAnimationFrame(
50
+ (contentEl as any)._dlOverflowAnimationFrame
51
+ )
52
+ }
53
+
54
+ (contentEl as any)._dlOverflowAnimationFrame =
49
55
  requestAnimationFrame(() => {
50
56
  if (contentEl === null) {
51
57
  return
52
58
  }
53
59
 
60
+ (contentEl as any)._dlOverflowAnimationFrame = void 0
61
+
54
62
  const children = (contentEl.children ||
55
63
  []) as HTMLCollection
56
64
 
@@ -80,6 +88,7 @@ function getScrollDetails(
80
88
  child: any,
81
89
  beforeRef: HTMLElement | null,
82
90
  afterRef: HTMLElement | null,
91
+ horizontal: boolean,
83
92
  stickyStart: number,
84
93
  stickyEnd: number
85
94
  ): ScrollDetails {
@@ -87,7 +96,7 @@ function getScrollDetails(
87
96
  parent === window
88
97
  ? document.scrollingElement || document.documentElement
89
98
  : parent
90
- const propElSize = 'offsetHeight'
99
+ const propElSize = horizontal === true ? 'offsetWidth' : 'offsetHeight'
91
100
  const details = {
92
101
  scrollStart: 0,
93
102
  scrollViewSize: -stickyStart - stickyEnd,
@@ -96,15 +105,33 @@ function getScrollDetails(
96
105
  offsetEnd: -stickyEnd
97
106
  }
98
107
 
99
- if (parent === window) {
100
- details.scrollStart =
101
- window.pageYOffset || window.scrollY || document.body.scrollTop || 0
102
- details.scrollViewSize += document.documentElement.clientHeight
108
+ if (horizontal === true) {
109
+ if (parent === window) {
110
+ details.scrollStart =
111
+ window.pageXOffset ||
112
+ window.scrollX ||
113
+ document.body.scrollLeft ||
114
+ 0
115
+ details.scrollViewSize += document.documentElement.clientWidth
116
+ } else {
117
+ details.scrollStart = parentCalc.scrollLeft
118
+ details.scrollViewSize += parentCalc.clientWidth
119
+ }
120
+ details.scrollMaxSize = parentCalc.scrollWidth
103
121
  } else {
104
- details.scrollStart = parentCalc.scrollTop
105
- details.scrollViewSize += parentCalc.clientHeight
122
+ if (parent === window) {
123
+ details.scrollStart =
124
+ window.pageYOffset ||
125
+ window.scrollY ||
126
+ document.body.scrollTop ||
127
+ 0
128
+ details.scrollViewSize += document.documentElement.clientHeight
129
+ } else {
130
+ details.scrollStart = parentCalc.scrollTop
131
+ details.scrollViewSize += parentCalc.clientHeight
132
+ }
133
+ details.scrollMaxSize = parentCalc.scrollHeight
106
134
  }
107
- details.scrollMaxSize = parentCalc.scrollHeight
108
135
 
109
136
  if (beforeRef !== null) {
110
137
  for (
@@ -132,10 +159,17 @@ function getScrollDetails(
132
159
 
133
160
  if (child !== parent) {
134
161
  const parentRect = parentCalc.getBoundingClientRect()
135
- const childRect = child.getBoundingClientRect()
162
+ const childRect = child?.getBoundingClientRect()
136
163
 
137
- details.offsetStart += childRect.top - parentRect.top
138
- details.offsetEnd -= childRect.height
164
+ if (childRect) {
165
+ if (horizontal === true) {
166
+ details.offsetStart += childRect.left - parentRect.left
167
+ details.offsetEnd -= childRect.width
168
+ } else {
169
+ details.offsetStart += childRect.top - parentRect.top
170
+ details.offsetEnd -= childRect.height
171
+ }
172
+ }
139
173
 
140
174
  if (parent !== window) {
141
175
  details.offsetStart += details.scrollStart
@@ -146,19 +180,33 @@ function getScrollDetails(
146
180
  return details
147
181
  }
148
182
 
149
- function setScroll(parent: any, scroll: string | number) {
183
+ function setScroll(parent: any, scroll: string | number, horizontal: boolean) {
150
184
  if (scroll === 'end') {
151
- scroll = (parent === window ? document.body : parent)['scrollHeight']
185
+ scroll = (parent === window ? document.body : parent)[
186
+ horizontal === true ? 'scrollWidth' : 'scrollHeight'
187
+ ]
152
188
  }
153
189
 
154
190
  if (parent === window) {
155
- window.scrollTo(
156
- window.pageXOffset ||
157
- window.scrollX ||
158
- document.body.scrollLeft ||
159
- 0,
160
- scroll as number
161
- )
191
+ if (horizontal === true) {
192
+ window.scrollTo(
193
+ scroll as number,
194
+ window.pageYOffset ||
195
+ window.scrollY ||
196
+ document.body.scrollTop ||
197
+ 0
198
+ )
199
+ } else {
200
+ window.scrollTo(
201
+ window.pageXOffset ||
202
+ window.scrollX ||
203
+ document.body.scrollLeft ||
204
+ 0,
205
+ scroll as number
206
+ )
207
+ }
208
+ } else if (horizontal === true) {
209
+ parent.scrollLeft = scroll
162
210
  } else {
163
211
  parent.scrollTop = scroll
164
212
  }
@@ -222,6 +270,7 @@ export const commonVirtScrollProps = {
222
270
  export const commonVirtPropsList = Object.keys(commonVirtScrollProps)
223
271
 
224
272
  export const useVirtualScrollProps = {
273
+ virtualScrollHorizontal: Boolean,
225
274
  onVirtualScroll: Function,
226
275
  ...commonVirtScrollProps
227
276
  }
@@ -307,6 +356,7 @@ export function useVirtualScroll({
307
356
  getVirtualScrollEl(),
308
357
  beforeRef.value,
309
358
  afterRef.value,
359
+ props.virtualScrollHorizontal as boolean,
310
360
  props.virtualScrollStickySizeStart as number,
311
361
  props.virtualScrollStickySizeEnd as number
312
362
  )
@@ -347,6 +397,7 @@ export function useVirtualScroll({
347
397
  getVirtualScrollEl(),
348
398
  beforeRef.value,
349
399
  afterRef.value,
400
+ props.virtualScrollHorizontal as boolean,
350
401
  props.virtualScrollStickySizeStart as number,
351
402
  props.virtualScrollStickySizeEnd as number
352
403
  )
@@ -447,7 +498,7 @@ export function useVirtualScroll({
447
498
  const alignForce =
448
499
  typeof align === 'string' && align.indexOf('-force') > -1
449
500
  const alignEnd =
450
- alignForce === true ? align?.replace('-force', '') : align
501
+ alignForce === true ? align.replace('-force', '') : align
451
502
  const alignRange = alignEnd !== void 0 ? alignEnd : 'start'
452
503
 
453
504
  let from = Math.max(
@@ -483,9 +534,8 @@ export function useVirtualScroll({
483
534
  contentEl.addEventListener('focusout', onBlurRefocusFn)
484
535
 
485
536
  setTimeout(() => {
486
- if (contentEl !== null) {
537
+ contentEl !== null &&
487
538
  contentEl.removeEventListener('focusout', onBlurRefocusFn)
488
- }
489
539
  })
490
540
  }
491
541
 
@@ -585,7 +635,11 @@ export function useVirtualScroll({
585
635
 
586
636
  prevScrollStart = scrollPosition
587
637
 
588
- setScroll(scrollEl, scrollPosition)
638
+ setScroll(
639
+ scrollEl,
640
+ scrollPosition,
641
+ props.virtualScrollHorizontal as boolean
642
+ )
589
643
 
590
644
  emitScroll(toIndex)
591
645
  })
@@ -602,7 +656,10 @@ export function useVirtualScroll({
602
656
  el.classList.contains('dl-virtual-scroll--skip') === false
603
657
  )
604
658
  const childrenLength = children.length
605
- const sizeFn = (el: HTMLElement) => el.offsetHeight
659
+ const sizeFn =
660
+ props.virtualScrollHorizontal === true
661
+ ? (el: HTMLElement) => el.getBoundingClientRect().width
662
+ : (el: HTMLElement) => el.offsetHeight
606
663
 
607
664
  let index = from
608
665
  let size
@@ -636,13 +693,13 @@ export function useVirtualScroll({
636
693
  }
637
694
 
638
695
  function onBlurRefocusFn() {
639
- if (contentRef.value !== null && contentRef.value !== void 0) {
696
+ contentRef.value !== null &&
697
+ contentRef.value !== void 0 &&
640
698
  contentRef.value.focus()
641
- }
642
699
  }
643
700
 
644
701
  function localResetVirtualScroll(toIndex?: number, fullReset?: boolean) {
645
- const defaultSize = 1 * virtualScrollItemSizeComputed!.value
702
+ const defaultSize = 1 * virtualScrollItemSizeComputed.value
646
703
 
647
704
  if (fullReset === true || Array.isArray(virtualScrollSizes) === false) {
648
705
  virtualScrollSizes = []
@@ -690,7 +747,7 @@ export function useVirtualScroll({
690
747
  virtualScrollLength.value
691
748
  )
692
749
 
693
- if (toIndex && toIndex >= 0) {
750
+ if (toIndex >= 0) {
694
751
  updateVirtualScrollSizes(virtualScrollSliceRange.value.from)
695
752
  nextTick(() => {
696
753
  scrollTo(toIndex)
@@ -714,6 +771,7 @@ export function useVirtualScroll({
714
771
  getVirtualScrollEl(),
715
772
  beforeRef.value,
716
773
  afterRef.value,
774
+ props.virtualScrollHorizontal as boolean,
717
775
  props.virtualScrollStickySizeStart as number,
718
776
  props.virtualScrollStickySizeEnd as number
719
777
  ).scrollViewSize
@@ -754,6 +812,95 @@ export function useVirtualScroll({
754
812
  }
755
813
  }
756
814
 
815
+ function padVirtualScroll(tag: string, content: any[], create: Function) {
816
+ const paddingSize =
817
+ props.virtualScrollHorizontal === true ? 'width' : 'height'
818
+
819
+ const style = {
820
+ ['--dl-virtual-scroll-item-' + paddingSize]:
821
+ virtualScrollItemSizeComputed.value + 'px'
822
+ }
823
+
824
+ return [
825
+ tag === 'tbody'
826
+ ? create(
827
+ tag,
828
+ {
829
+ class: 'dl-virtual-scroll__padding',
830
+ key: 'before',
831
+ ref: beforeRef
832
+ },
833
+ [
834
+ create('tr', [
835
+ create('td', {
836
+ style: {
837
+ [paddingSize]: `${virtualScrollPaddingBefore.value}px`,
838
+ ...style
839
+ },
840
+ colspan: colspanAttr.value,
841
+ attrs: {
842
+ colspan: colspanAttr.value
843
+ }
844
+ })
845
+ ])
846
+ ]
847
+ )
848
+ : create(tag, {
849
+ class: 'dl-virtual-scroll__padding',
850
+ key: 'before',
851
+ ref: beforeRef,
852
+ style: {
853
+ [paddingSize]: `${virtualScrollPaddingBefore.value}px`,
854
+ ...style
855
+ }
856
+ }),
857
+
858
+ create(
859
+ tag,
860
+ {
861
+ class: 'dl-virtual-scroll__content',
862
+ key: 'content',
863
+ ref: contentRef,
864
+ tabindex: -1
865
+ },
866
+ content.flat()
867
+ ),
868
+
869
+ tag === 'tbody'
870
+ ? create(
871
+ tag,
872
+ {
873
+ class: 'dl-virtual-scroll__padding',
874
+ key: 'after',
875
+ ref: afterRef
876
+ },
877
+ [
878
+ create('tr', [
879
+ create('td', {
880
+ style: {
881
+ [paddingSize]: `${virtualScrollPaddingAfter.value}px`,
882
+ ...style
883
+ },
884
+ colspan: colspanAttr.value,
885
+ attrs: {
886
+ colspan: colspanAttr.value
887
+ }
888
+ })
889
+ ])
890
+ ]
891
+ )
892
+ : create(tag, {
893
+ class: 'dl-virtual-scroll__padding',
894
+ key: 'after',
895
+ ref: afterRef,
896
+ style: {
897
+ [paddingSize]: `${virtualScrollPaddingAfter.value}px`,
898
+ ...style
899
+ }
900
+ })
901
+ ]
902
+ }
903
+
757
904
  function emitScroll(index: number) {
758
905
  if (prevToIndex !== index) {
759
906
  emit('virtual-scroll', {
@@ -794,7 +941,11 @@ export function useVirtualScroll({
794
941
  scrollEl !== null &&
795
942
  scrollEl.nodeType !== 8
796
943
  ) {
797
- setScroll(scrollEl, prevScrollStart)
944
+ setScroll(
945
+ scrollEl,
946
+ prevScrollStart,
947
+ props.virtualScrollHorizontal as boolean
948
+ )
798
949
  } else {
799
950
  scrollTo(prevToIndex)
800
951
  }
@@ -814,18 +965,10 @@ export function useVirtualScroll({
814
965
  setVirtualScrollSize,
815
966
  onVirtualScrollEvt,
816
967
  localResetVirtualScroll,
968
+ padVirtualScroll,
817
969
 
818
970
  scrollTo,
819
971
  reset,
820
- refresh,
821
-
822
- virtualScrollPaddingBefore,
823
- virtualScrollPaddingAfter,
824
-
825
- beforeRef,
826
- afterRef,
827
- contentRef,
828
-
829
- colspanAttr
972
+ refresh
830
973
  }
831
974
  }
@@ -0,0 +1,167 @@
1
+ <template>
2
+ <div class="q-pa-md">
3
+ <dl-option-group
4
+ v-model="separator"
5
+ inline
6
+ :options="separatorOptions"
7
+ />
8
+
9
+ <dl-markup-table
10
+ :separator="separator"
11
+ flat
12
+ bordered
13
+ >
14
+ <thead>
15
+ <dl-tr>
16
+ <dl-th class="text-left">
17
+ Dessert (100g serving)
18
+ </dl-th>
19
+ <dl-th class="text-right">
20
+ Calories
21
+ </dl-th>
22
+ <dl-th class="text-right">
23
+ Fat (g)
24
+ </dl-th>
25
+ <dl-th class="text-right">
26
+ Carbs (g)
27
+ </dl-th>
28
+ <dl-th class="text-right">
29
+ Protein (g)
30
+ </dl-th>
31
+ <dl-th class="text-right">
32
+ Sodium (mg)
33
+ </dl-th>
34
+ </dl-tr>
35
+ </thead>
36
+ <tbody>
37
+ <dl-tr>
38
+ <dl-td class="text-left">
39
+ Frozen Yogurt
40
+ </dl-td>
41
+ <dl-td class="text-right">
42
+ 159
43
+ </dl-td>
44
+ <dl-td class="text-right">
45
+ 6
46
+ </dl-td>
47
+ <dl-td class="text-right">
48
+ 24
49
+ </dl-td>
50
+ <dl-td class="text-right">
51
+ 4
52
+ </dl-td>
53
+ <dl-td class="text-right">
54
+ 87
55
+ </dl-td>
56
+ </dl-tr>
57
+ <dl-tr>
58
+ <dl-td class="text-left">
59
+ Ice cream sandwich
60
+ </dl-td>
61
+ <dl-td class="text-right">
62
+ 237
63
+ </dl-td>
64
+ <dl-td class="text-right">
65
+ 9
66
+ </dl-td>
67
+ <dl-td class="text-right">
68
+ 37
69
+ </dl-td>
70
+ <dl-td class="text-right">
71
+ 4.3
72
+ </dl-td>
73
+ <dl-td class="text-right">
74
+ 129
75
+ </dl-td>
76
+ </dl-tr>
77
+ <dl-tr>
78
+ <dl-td class="text-left">
79
+ Eclair
80
+ </dl-td>
81
+ <dl-td class="text-right">
82
+ 262
83
+ </dl-td>
84
+ <dl-td class="text-right">
85
+ 16
86
+ </dl-td>
87
+ <dl-td class="text-right">
88
+ 23
89
+ </dl-td>
90
+ <dl-td class="text-right">
91
+ 6
92
+ </dl-td>
93
+ <dl-td class="text-right">
94
+ 337
95
+ </dl-td>
96
+ </dl-tr>
97
+ <dl-tr>
98
+ <dl-td class="text-left">
99
+ Cupcake
100
+ </dl-td>
101
+ <dl-td class="text-right">
102
+ 305
103
+ </dl-td>
104
+ <dl-td class="text-right">
105
+ 3.7
106
+ </dl-td>
107
+ <dl-td class="text-right">
108
+ 67
109
+ </dl-td>
110
+ <dl-td class="text-right">
111
+ 4.3
112
+ </dl-td>
113
+ <dl-td class="text-right">
114
+ 413
115
+ </dl-td>
116
+ </dl-tr>
117
+ <dl-tr>
118
+ <dl-td class="text-left">
119
+ Gingerbread
120
+ </dl-td>
121
+ <dl-td class="text-right">
122
+ 356
123
+ </dl-td>
124
+ <dl-td class="text-right">
125
+ 16
126
+ </dl-td>
127
+ <dl-td class="text-right">
128
+ 49
129
+ </dl-td>
130
+ <dl-td class="text-right">
131
+ 3.9
132
+ </dl-td>
133
+ <dl-td class="text-right">
134
+ 327
135
+ </dl-td>
136
+ </dl-tr>
137
+ </tbody>
138
+ </dl-markup-table>
139
+ </div>
140
+ </template>
141
+
142
+ <script lang="ts">
143
+ import { ref, defineComponent } from 'vue-demi'
144
+ import { DlMarkupTable, DlOptionGroup, DlTd, DlTr, DlTh } from '../components'
145
+
146
+ export default defineComponent({
147
+ name: 'DlMarkupTableDemo',
148
+ components: {
149
+ DlMarkupTable,
150
+ DlOptionGroup,
151
+ DlTd,
152
+ DlTr,
153
+ DlTh
154
+ },
155
+ setup() {
156
+ return {
157
+ separator: ref('vertical'),
158
+ separatorOptions: [
159
+ { label: 'Horizontal', value: 'horizontal' },
160
+ { label: 'Vertical', value: 'vertical' },
161
+ { label: 'Cell', value: 'cell' },
162
+ { label: 'None', value: 'none' }
163
+ ]
164
+ }
165
+ }
166
+ })
167
+ </script>