@dataloop-ai/components 0.19.113 → 0.19.114

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.19.113",
3
+ "version": "0.19.114",
4
4
  "exports": {
5
5
  ".": "./index.ts",
6
6
  "./models": "./models.ts",
@@ -160,7 +160,7 @@
160
160
  no-focus
161
161
  :offset="[0, 3]"
162
162
  style="border-radius: 0"
163
- :style="menuStyle"
163
+ :style="computedMenuStyle"
164
164
  :menu-class="menuClass"
165
165
  :disabled="disabled || readonly"
166
166
  :arrow-nav-items="options"
@@ -195,6 +195,8 @@
195
195
  :model-value="allFiltersModel"
196
196
  :count="totalCount"
197
197
  :highlight-selected="highlightSelected"
198
+ :filter-term="searchTerm"
199
+ :fit-content="fitContent"
198
200
  total-items
199
201
  @update:model-value="selectAll"
200
202
  @depth-change="handleDepthChange"
@@ -212,8 +214,7 @@
212
214
  :virtual-scroll-item-size="28"
213
215
  :virtual-scroll-sticky-size-start="28"
214
216
  :virtual-scroll-sticky-size-end="20"
215
- separator
216
- :style="multiselect ? `width: max-content` : ''"
217
+ :style="`width: 100%; max-height: calc(${dropdownMaxHeight} - 20px);`"
217
218
  >
218
219
  <dl-select-option
219
220
  :key="getKeyForOption(item)"
@@ -228,6 +229,8 @@
228
229
  ? 'background-color: var(--dl-color-fill)'
229
230
  : ''
230
231
  "
232
+ :fit-content="fitContent"
233
+ :filter-term="searchTerm"
231
234
  :with-wave="withWave"
232
235
  :model-value="modelValue"
233
236
  :value="getOptionValue(item)"
@@ -277,6 +280,8 @@
277
280
  ? 'background-color: var(--dl-color-fill)'
278
281
  : ''
279
282
  "
283
+ :fit-content="fitContent"
284
+ :filter-term="searchTerm"
280
285
  :with-wave="withWave"
281
286
  :model-value="modelValue"
282
287
  :value="getOptionValue(option)"
@@ -296,6 +301,7 @@
296
301
  :opt="option"
297
302
  name="option"
298
303
  >
304
+ tetestestes
299
305
  <span
300
306
  v-if="fitContent"
301
307
  class="inner-option"
@@ -357,8 +363,9 @@ import {
357
363
  getLabelOfSelectedOption,
358
364
  getCaseInsensitiveInput
359
365
  } from './utils'
366
+ import { DlSelectOption as DlSelectOptionEntry } from '../types'
360
367
  import DlSelectOption from './components/DlSelectOption.vue'
361
- import { isEqual } from 'lodash'
368
+ import { cloneDeep, isEqual } from 'lodash'
362
369
  import { getColor } from '../../../utils'
363
370
  import { v4 } from 'uuid'
364
371
 
@@ -493,15 +500,98 @@ export default defineComponent({
493
500
  return this.options
494
501
  }
495
502
 
496
- return this.options.filter((option) => {
497
- const label = getLabel(option)
498
- return (
499
- label &&
500
- label
501
- .toLowerCase()
502
- .includes(this.searchTerm.toLowerCase().trim())
503
- )
504
- })
503
+ // alternate version here it shows from child down
504
+ // const labelIncluded = (
505
+ // options: DlSelectOptionType[],
506
+ // term: string
507
+ // ): DlSelectOptionType[] => {
508
+ // const filteredNodes: DlSelectOptionType[] = []
509
+
510
+ // for (const op of options) {
511
+ // const queue: DlSelectOptionType[] = [op]
512
+ // while (queue.length) {
513
+ // const node = queue.shift()
514
+ // let shouldPush = false
515
+
516
+ // const label = getLabel(node)
517
+
518
+ // if (
519
+ // label &&
520
+ // label
521
+ // .toLowerCase()
522
+ // .includes(term.toLowerCase().trim())
523
+ // ) {
524
+ // filteredNodes.push(node)
525
+ // shouldPush = true
526
+ // }
527
+
528
+ // if (
529
+ // !shouldPush &&
530
+ // (node as DlSelectOptionEntry)?.children?.length
531
+ // ) {
532
+ // queue.push(
533
+ // ...(node as DlSelectOptionEntry).children
534
+ // )
535
+ // }
536
+ // }
537
+ // }
538
+
539
+ // return filteredNodes
540
+ // }
541
+
542
+ const labelIncluded = (
543
+ options: DlSelectOptionType[],
544
+ term: string
545
+ ): DlSelectOptionType[] => {
546
+ const filteredNodes: DlSelectOptionType[] = []
547
+
548
+ for (const op of options) {
549
+ const queue: DlSelectOptionType[] = [op]
550
+ const filteredRoots: DlSelectOptionType[] = []
551
+ while (queue.length) {
552
+ const node = queue.shift()
553
+ let shouldPush = false
554
+ if ((node as DlSelectOptionEntry)?.children?.length) {
555
+ const filteredChildren: DlSelectOptionType[] =
556
+ labelIncluded(
557
+ (node as DlSelectOptionEntry).children,
558
+ term
559
+ )
560
+ if (filteredChildren.length) {
561
+ // @ts-ignore
562
+ node.children = filteredChildren
563
+ shouldPush = true
564
+ }
565
+ }
566
+
567
+ const label = getLabel(node)
568
+
569
+ if (
570
+ shouldPush ||
571
+ (label &&
572
+ label
573
+ .toLowerCase()
574
+ .includes(term.toLowerCase().trim()))
575
+ ) {
576
+ filteredRoots.push(node)
577
+ }
578
+ }
579
+ for (const root of filteredRoots) {
580
+ filteredNodes.push(root)
581
+ }
582
+ }
583
+
584
+ return filteredNodes
585
+ }
586
+
587
+ return labelIncluded(cloneDeep(this.options), this.searchTerm)
588
+ },
589
+ computedMenuStyle(): string {
590
+ let style = this.menuStyle ?? ''
591
+ if (this.optionsCount > this.MAX_ITEMS_PER_LIST) {
592
+ style += '; overflow-y: hidden'
593
+ }
594
+ return style
505
595
  },
506
596
  optionsCount(): number {
507
597
  return this.options?.length ?? 0
@@ -778,7 +868,11 @@ export default defineComponent({
778
868
  return option?.count ?? null
779
869
  },
780
870
  getKeyForOption(
781
- option: string | number | Record<string, string | number>
871
+ option:
872
+ | string
873
+ | number
874
+ | Record<string, string | number>
875
+ | DlSelectOptionType
782
876
  ) {
783
877
  if (typeof option === 'string' || typeof option === 'number') {
784
878
  return option
@@ -96,24 +96,40 @@
96
96
  :capitalized="capitalized"
97
97
  :readonly="isReadonlyOption(child)"
98
98
  :is-expanded="isExpanded"
99
+ :filter-term="filterTerm"
100
+ :fit-content="fitContent"
99
101
  @update:model-value="handleCheckboxUpdate"
100
102
  @selected="handleSingleSelect"
101
103
  @deselected="handleSingleDeselect"
102
104
  @depth-change="$emit('depth-change')"
103
- />
105
+ >
106
+ <span
107
+ v-if="fitContent"
108
+ class="inner-option"
109
+ v-html="getOptionHtml(child)"
110
+ />
111
+ <dl-ellipsis v-else>
112
+ <span
113
+ class="inner-option"
114
+ v-html="getOptionHtml(child)"
115
+ />
116
+ </dl-ellipsis>
117
+ </dl-select-option>
104
118
  </div>
105
119
  </div>
106
120
  </div>
107
121
  </template>
108
122
 
109
123
  <script lang="ts">
110
- import { defineComponent } from 'vue-demi'
124
+ import { defineComponent, PropType } from 'vue-demi'
111
125
  import { DlListItem } from '../../../basic'
112
126
  import { DlIcon, DlCheckbox } from '../../../essential'
113
127
  import { DlItemSection } from '../../../shared'
114
128
  import { v4 } from 'uuid'
115
129
  import { debounce } from 'lodash'
116
130
  import { stateManager } from '../../../../StateManager'
131
+ import { DlSelectOptionType, getCaseInsensitiveInput, getLabel } from '../utils'
132
+ import { DlSelectedValueType } from '../../types'
117
133
 
118
134
  const ValueTypes = [Array, Boolean, String, Number, Object, Function]
119
135
 
@@ -135,7 +151,10 @@ export default defineComponent({
135
151
  defaultStyles: { type: Boolean, default: true },
136
152
  multiselect: { type: Boolean, default: false },
137
153
  value: { type: ValueTypes, default: null },
138
- children: { type: Array, default: null },
154
+ children: {
155
+ type: Array as PropType<DlSelectedValueType[]>,
156
+ default: null
157
+ },
139
158
  highlightSelected: { type: Boolean, default: false },
140
159
  count: { type: Number, default: null },
141
160
  totalItems: { type: Boolean, default: false },
@@ -150,6 +169,14 @@ export default defineComponent({
150
169
  isExpanded: {
151
170
  type: Boolean,
152
171
  default: false
172
+ },
173
+ filterTerm: {
174
+ type: String,
175
+ default: null
176
+ },
177
+ fitContent: {
178
+ type: Boolean,
179
+ default: false
153
180
  }
154
181
  },
155
182
  emits: [
@@ -199,6 +226,32 @@ export default defineComponent({
199
226
  }
200
227
  },
201
228
  methods: {
229
+ getOptionValue(option: any) {
230
+ return option?.value ?? option
231
+ },
232
+ getOptionLabel(option: any) {
233
+ return getLabel(option) ?? this.getOptionValue(option)
234
+ },
235
+ getOptionHtml(option: DlSelectOptionType) {
236
+ const label = `${this.getOptionLabel(option)}`
237
+ let highlightedHtml = label
238
+
239
+ if (this.filterTerm?.length) {
240
+ const toReplace = new RegExp(this.filterTerm, 'gi')
241
+
242
+ highlightedHtml = label.replace(
243
+ toReplace,
244
+ `<span style="background: var(--dl-color-warning)">${getCaseInsensitiveInput(
245
+ label,
246
+ this.filterTerm
247
+ )}</span>`
248
+ )
249
+ }
250
+
251
+ const html = `<span>${highlightedHtml}</span>`
252
+
253
+ return html
254
+ },
202
255
  handleSingleSelect(value?: any) {
203
256
  this.$emit('selected', value ?? this.value)
204
257
  },
@@ -1,6 +1,7 @@
1
1
  export interface DlSelectOption {
2
2
  label: string
3
3
  value: any
4
+ key?: string
4
5
  expanded?: boolean
5
6
  children?: DlSelectOption[]
6
7
  readonly?: boolean
@@ -576,44 +576,24 @@
576
576
  v-model="selectedWithChildrenAndReadonly"
577
577
  :options="treeOptionsExpanded"
578
578
  multiselect
579
+ searchable
579
580
  style="margin-bottom: 150px; width: 200px"
580
- >
581
- <template #option="scope">
582
- <div style="padding: 5px 0px">
583
- <div>{{ scope.opt.label }}</div>
584
- <div>{{ scope.opt.subLabel }}</div>
585
- </div>
586
- </template>
587
- </dl-select>
588
-
581
+ />
589
582
  Select with multiselect auto expanded and fixed width and virtual scroll
590
583
  <dl-select
591
584
  v-model="selectedWithChildrenAndReadonly"
592
585
  :options="alotOfOptionsExpanded"
593
586
  multiselect
587
+ searchable
594
588
  style="margin-bottom: 150px; width: 200px"
595
- >
596
- <template #option="scope">
597
- <div style="padding: 5px 0px">
598
- <div>{{ scope.opt.label }}</div>
599
- <div>{{ scope.opt.subLabel }}</div>
600
- </div>
601
- </template>
602
- </dl-select>
589
+ />
603
590
  Select with multiselect auto expanded and fixed width and virtual scroll
604
591
  <dl-select
605
592
  v-model="selectedWithChildrenAndReadonly"
606
593
  :options="alotOfOptionsExpanded"
607
594
  multiselect
608
595
  style="margin-bottom: 150px"
609
- >
610
- <template #option="scope">
611
- <div style="padding: 5px 0px">
612
- <div>{{ scope.opt.label }}</div>
613
- <div>{{ scope.opt.subLabel }}</div>
614
- </div>
615
- </template>
616
- </dl-select>
596
+ />
617
597
  </div>
618
598
  </template>
619
599