@dataloop-ai/components 0.17.10 → 0.17.12

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.10",
3
+ "version": "0.17.12",
4
4
  "exports": {
5
5
  ".": "./index.ts",
6
6
  "./models": "./models.ts",
@@ -115,11 +115,11 @@ export class Stepper {
115
115
  const { step } = options
116
116
  const stepToFail = step ?? this.currentStep
117
117
 
118
- if (stepToFail) {
118
+ if (!stepToFail) {
119
119
  return
120
120
  }
121
121
 
122
- this.currentStep.error = message ?? ''
122
+ stepToFail.error = message ?? ''
123
123
  }
124
124
 
125
125
  /**
@@ -136,11 +136,11 @@ export class Stepper {
136
136
  const { step, preventNext } = options
137
137
  const stepToWarn = step ?? this.currentStep
138
138
 
139
- if (stepToWarn) {
139
+ if (!stepToWarn) {
140
140
  return
141
141
  }
142
142
 
143
- this.currentStep.warning = message ?? ''
143
+ stepToWarn.warning = message ?? ''
144
144
 
145
145
  if (!preventNext) {
146
146
  this.moveToNextStep()
@@ -157,10 +157,10 @@ export class Stepper {
157
157
  const { step } = options
158
158
  const stepToReset = step ?? this.currentStep
159
159
 
160
- if (stepToReset) {
160
+ if (!stepToReset) {
161
161
  return
162
162
  }
163
163
 
164
- this.currentStep.reset()
164
+ stepToReset.reset()
165
165
  }
166
166
  }
@@ -2,6 +2,7 @@ import { isVue3 } from 'vue-demi'
2
2
  import toastComponent from '../components/ToastComponent.vue'
3
3
  import { createComponent } from '../utils/render'
4
4
  import { v4 } from 'uuid'
5
+ import { DlToastProps, DlToastTypes } from '../types'
5
6
 
6
7
  const state: { prevToastId: any; toasts: { [key: string]: any } } = {
7
8
  prevToastId: null,
@@ -10,7 +11,7 @@ const state: { prevToastId: any; toasts: { [key: string]: any } } = {
10
11
 
11
12
  export const useToast = (globalProps = {}) => {
12
13
  return {
13
- open(options: Object | string) {
14
+ open(options: DlToastProps | string) {
14
15
  let message = null
15
16
  if (typeof options === 'string') message = options
16
17
 
@@ -55,6 +56,46 @@ export const useToast = (globalProps = {}) => {
55
56
  propsData,
56
57
  document.body
57
58
  )
59
+ },
60
+ success(options: DlToastProps | string) {
61
+ let props: Partial<DlToastProps> = {}
62
+ if (typeof options === 'string') {
63
+ props.message = options
64
+ } else {
65
+ props = options
66
+ }
67
+
68
+ this.open({ ...props, type: DlToastTypes.SUCCESS } as DlToastProps)
69
+ },
70
+ error(options: DlToastProps | string) {
71
+ let props: Partial<DlToastProps> = {}
72
+ if (typeof options === 'string') {
73
+ props.message = options
74
+ } else {
75
+ props = options
76
+ }
77
+
78
+ this.open({ ...props, type: DlToastTypes.ERROR } as DlToastProps)
79
+ },
80
+ info(options: DlToastProps | string) {
81
+ let props: Partial<DlToastProps> = {}
82
+ if (typeof options === 'string') {
83
+ props.message = options
84
+ } else {
85
+ props = options
86
+ }
87
+
88
+ this.open({ ...props, type: DlToastTypes.INFO } as DlToastProps)
89
+ },
90
+ warn(options: DlToastProps | string) {
91
+ let props: Partial<DlToastProps> = {}
92
+ if (typeof options === 'string') {
93
+ props.message = options
94
+ } else {
95
+ props = options
96
+ }
97
+
98
+ this.open({ ...props, type: DlToastTypes.WARNING } as DlToastProps)
58
99
  }
59
100
  }
60
101
  }
@@ -8,11 +8,7 @@
8
8
  :id="`DlToastContainer-${uuid}`"
9
9
  ref="root"
10
10
  class="toast-item DlToastContainer"
11
- :class="[
12
- `toast-item--${type}`,
13
- `toast-item--${position}`,
14
- classItem
15
- ]"
11
+ :class="[`toast-item--${type}`, `toast-item--${position}`]"
16
12
  :style="{ width }"
17
13
  >
18
14
  <dl-alert
@@ -64,7 +60,7 @@ import {
64
60
  ref
65
61
  } from 'vue-demi'
66
62
  import { DlAlert, DlBadge } from '../../../'
67
- import { Positions, Types } from '../utils/config'
63
+ import { DlToastTypes, DlToastPositions } from '../types'
68
64
  import { removeElement } from '../utils/render'
69
65
  import { Animation } from '../types'
70
66
  import { v4 } from 'uuid'
@@ -79,15 +75,11 @@ export default defineComponent({
79
75
  },
80
76
  type: {
81
77
  type: String,
82
- default: 'success',
83
- validator(value: string): boolean {
84
- return Object.values(Types as unknown).includes(value)
78
+ required: true,
79
+ validator(value: DlToastTypes): boolean {
80
+ return Object.values(DlToastTypes).includes(value)
85
81
  }
86
82
  },
87
- classItem: {
88
- type: String,
89
- default: ''
90
- },
91
83
  width: {
92
84
  type: String,
93
85
  default: 'auto'
@@ -98,9 +90,9 @@ export default defineComponent({
98
90
  },
99
91
  position: {
100
92
  type: String,
101
- default: Positions.bottom,
102
- validator(value: string): boolean {
103
- return Object.values(Positions as unknown).includes(value)
93
+ default: DlToastPositions.BOTTOM,
94
+ validator(value: DlToastPositions): boolean {
95
+ return Object.values(DlToastPositions).includes(value)
104
96
  }
105
97
  },
106
98
  closable: {
@@ -151,14 +143,14 @@ export default defineComponent({
151
143
 
152
144
  const correctParent = computed(() => {
153
145
  switch (position) {
154
- case Positions.top:
155
- case Positions.top_right:
156
- case Positions.top_left:
146
+ case DlToastPositions.TOP:
147
+ case DlToastPositions.TOP_RIGHT:
148
+ case DlToastPositions.TOP_LEFT:
157
149
  toastParentPosition.value = 'top'
158
150
  return parentTop
159
- case Positions.bottom:
160
- case Positions.bottom_right:
161
- case Positions.bottom_left:
151
+ case DlToastPositions.BOTTOM:
152
+ case DlToastPositions.BOTTOM_RIGHT:
153
+ case DlToastPositions.BOTTOM_LEFT:
162
154
  toastParentPosition.value = 'bottom'
163
155
  return parentBottom
164
156
  }
@@ -166,16 +158,16 @@ export default defineComponent({
166
158
 
167
159
  const transition = computed((): Animation => {
168
160
  switch (position) {
169
- case Positions.top:
170
- case Positions.top_right:
171
- case Positions.top_left:
161
+ case DlToastPositions.TOP:
162
+ case DlToastPositions.TOP_RIGHT:
163
+ case DlToastPositions.TOP_LEFT:
172
164
  return {
173
165
  enter: 'dl-toast--fade-in-down',
174
166
  leave: 'dl-toast--fade-out'
175
167
  }
176
- case Positions.bottom:
177
- case Positions.bottom_right:
178
- case Positions.bottom_left:
168
+ case DlToastPositions.BOTTOM:
169
+ case DlToastPositions.BOTTOM_RIGHT:
170
+ case DlToastPositions.BOTTOM_LEFT:
179
171
  return {
180
172
  enter: 'dl-toast--fade-in-up',
181
173
  leave: 'dl-toast--fade-out'
@@ -231,13 +223,13 @@ export default defineComponent({
231
223
 
232
224
  const badgeColor = computed(() => {
233
225
  switch (props.type) {
234
- case Types.success:
226
+ case DlToastTypes.SUCCESS:
235
227
  return 'var(--dl-color-alert-success)'
236
- case Types.warning:
228
+ case DlToastTypes.WARNING:
237
229
  return 'var(--dl-color-alert-warn)'
238
- case Types.error:
230
+ case DlToastTypes.ERROR:
239
231
  return 'var(--dl-color-alert-error)'
240
- case Types.info:
232
+ case DlToastTypes.INFO:
241
233
  return 'var(--dl-color-alert-info)'
242
234
  }
243
235
  })
@@ -2,3 +2,55 @@ export interface Animation {
2
2
  enter: string
3
3
  leave: string
4
4
  }
5
+
6
+ export enum DlToastPositions {
7
+ TOP_RIGHT = 'top-right',
8
+ TOP = 'top',
9
+ TOP_LEFT = 'top-left',
10
+ BOTTOM_RIGHT = 'bottom-right',
11
+ BOTTOM = 'bottom',
12
+ BOTTOM_LEFT = 'bottom-left'
13
+ }
14
+
15
+ export enum DlToastTypes {
16
+ SUCCESS = 'success',
17
+ WARNING = 'warning',
18
+ ERROR = 'error',
19
+ INFO = 'info'
20
+ }
21
+
22
+ export interface DlToastProps {
23
+ /**
24
+ * The message to display in the toast
25
+ */
26
+ message: string
27
+ /**
28
+ * The type of the toast
29
+ */
30
+ type: DlToastTypes
31
+ /**
32
+ * The width of the toast
33
+ * @default 'auto'
34
+ */
35
+ width?: string
36
+ /**
37
+ * The duration of the toast in seconds
38
+ * @default 10
39
+ */
40
+ duration?: number
41
+ /**
42
+ * The position of the toast
43
+ * @default DlToastPositions.BOTTOM
44
+ */
45
+ position?: DlToastPositions
46
+ /**
47
+ * Whether the toast is closable
48
+ * @default true
49
+ */
50
+ closable?: boolean
51
+ /**
52
+ * The number of toasts to collapse after
53
+ * @default 5
54
+ */
55
+ collapseCount?: number
56
+ }
@@ -43,31 +43,40 @@ export default defineComponent({
43
43
 
44
44
  virtualScrollSliceRatioBefore: {
45
45
  type: [Number, String],
46
+ required: false,
46
47
  default: 1
47
48
  },
48
49
 
49
50
  virtualScrollSliceRatioAfter: {
50
51
  type: [Number, String],
52
+ required: false,
51
53
  default: 1
52
54
  },
53
55
 
54
56
  virtualScrollItemSize: {
55
57
  type: [Number, String],
58
+ required: false,
56
59
  default: 0
57
60
  },
58
61
 
59
62
  virtualScrollStickySizeStart: {
60
63
  type: [Number, String],
64
+ required: false,
61
65
  default: 0
62
66
  },
63
67
 
64
68
  virtualScrollStickySizeEnd: {
65
69
  type: [Number, String],
70
+ required: false,
66
71
  default: 0
67
72
  },
68
- tableColspan: [Number, String],
69
- virtualScrollHorizontal: Boolean,
70
- onVirtualScroll: Function,
73
+ tableColspan: { type: [Number, String], required: false, default: 1 },
74
+ virtualScrollHorizontal: {
75
+ type: Boolean,
76
+ required: false,
77
+ default: false
78
+ },
79
+ onVirtualScroll: { type: Function, default: null },
71
80
  items: {
72
81
  type: Array,
73
82
  default: () => [] as Record<string, any>[]
@@ -80,11 +89,12 @@ export default defineComponent({
80
89
  typeOptions.includes(v)
81
90
  },
82
91
 
83
- itemsFn: { type: Function, default: void 0 },
92
+ itemsFn: { type: Function, default: null },
84
93
  itemsSize: { type: Number, default: 0 },
85
94
 
86
95
  scrollTarget: {
87
- default: void 0
96
+ type: [String, Object],
97
+ default: null
88
98
  }
89
99
  },
90
100
  emits: ['virtual-scroll'],
@@ -92,8 +102,10 @@ export default defineComponent({
92
102
  let localScrollTarget: HTMLElement | undefined
93
103
  const rootRef: Ref<HTMLElement | null> = ref(null)
94
104
 
105
+ const isDefined = (v: any) => v !== undefined && v !== null
106
+
95
107
  const virtualScrollLength = computed(() => {
96
- return props.itemsSize >= 0 && props.itemsFn !== void 0
108
+ return props.itemsSize >= 0 && isDefined(props.itemsFn)
97
109
  ? parseInt(props.itemsSize as unknown as string, 10)
98
110
  : Array.isArray(props.items)
99
111
  ? props.items.length
@@ -121,20 +133,21 @@ export default defineComponent({
121
133
  item
122
134
  })
123
135
 
124
- return props.itemsFn === void 0
125
- ? props.items
136
+ const itemsFn = props.itemsFn as Function
137
+ const items = props.items as Record<string, any>[]
138
+
139
+ return isDefined(itemsFn)
140
+ ? itemsFn(
141
+ virtualScrollSliceRange.value.from,
142
+ virtualScrollSliceRange.value.to -
143
+ virtualScrollSliceRange.value.from
144
+ ).map(mapFn)
145
+ : items
126
146
  .slice(
127
147
  virtualScrollSliceRange.value.from,
128
148
  virtualScrollSliceRange.value.to
129
149
  )
130
150
  .map(mapFn)
131
- : props
132
- .itemsFn(
133
- virtualScrollSliceRange.value.from,
134
- virtualScrollSliceRange.value.to -
135
- virtualScrollSliceRange.value.from
136
- )
137
- .map(mapFn)
138
151
  })
139
152
 
140
153
  const classes = computed(
@@ -143,11 +156,11 @@ export default defineComponent({
143
156
  (props.virtualScrollHorizontal === true
144
157
  ? '--horizontal'
145
158
  : '--vertical') +
146
- (props.scrollTarget !== void 0 ? '' : ' scroll')
159
+ (isDefined(props.scrollTarget) ? '' : ' scroll')
147
160
  )
148
161
 
149
162
  const attributes = computed(() =>
150
- props.scrollTarget !== void 0 ? {} : { tabindex: 0 }
163
+ isDefined(props.scrollTarget) ? {} : { tabindex: 0 }
151
164
  )
152
165
 
153
166
  watch(virtualScrollLength, () => {
@@ -173,7 +186,7 @@ export default defineComponent({
173
186
  function configureScrollTarget() {
174
187
  localScrollTarget = getScrollTarget(
175
188
  getVirtualScrollEl(),
176
- props.scrollTarget
189
+ props.scrollTarget as any
177
190
  )
178
191
 
179
192
  localScrollTarget!.addEventListener(
@@ -184,13 +197,13 @@ export default defineComponent({
184
197
  }
185
198
 
186
199
  function unconfigureScrollTarget() {
187
- if (localScrollTarget !== void 0) {
200
+ if (isDefined(localScrollTarget)) {
188
201
  localScrollTarget.removeEventListener(
189
202
  'scroll',
190
203
  onVirtualScrollEvt,
191
204
  listenOpts.passive
192
205
  )
193
- localScrollTarget = void 0
206
+ localScrollTarget = null
194
207
  }
195
208
  }
196
209
 
@@ -203,7 +216,7 @@ export default defineComponent({
203
216
  create
204
217
  )
205
218
 
206
- if (slots.before !== void 0) {
219
+ if (isDefined(slots.before)) {
207
220
  child = slots.before().concat(child)
208
221
  }
209
222
 
@@ -245,6 +258,12 @@ export default defineComponent({
245
258
  }
246
259
  },
247
260
  render(createElement: Function) {
261
+ /**
262
+ * Had to do some general Typescript hackery here to get this to work in webpack based builder project.
263
+ * The original code is written in Vue 2, but this project is using Vue 3.
264
+ * Some of the types are not compatible, so I had to cast some of the types to any.
265
+ */
266
+
248
267
  const renderFn = isVue2 ? createElement : h
249
268
  const renderSlot = (fn: Function) => (isVue2 ? fn() : () => fn())
250
269
 
@@ -255,25 +274,36 @@ export default defineComponent({
255
274
  return
256
275
  }
257
276
 
258
- return this.$props.type === '__dltable'
259
- ? getTableMiddle(
260
- {
261
- ref: 'rootRef',
262
- class: 'dl-table__middle ' + this.classes
263
- },
264
- this.getVirtualChildren(renderFn),
265
- renderFn
266
- )
267
- : renderFn(
268
- this.tag,
269
- {
270
- ...this.attrs,
271
- ref: 'rootRef',
272
- class: [this.attrs.class, this.classes],
273
- ...this.attributes
274
- },
275
- renderSlot(() => this.getVirtualChildren(renderFn))
276
- )
277
+ const isDlTable = (this.$props as any).type === '__dltable'
278
+ const getVirtualChildren = (this as any).getVirtualChildren as Function
279
+
280
+ if (isDlTable) {
281
+ return getTableMiddle(
282
+ {
283
+ ref: 'rootRef',
284
+ class: 'dl-table__middle ' + this.classes
285
+ },
286
+ getVirtualChildren(renderFn),
287
+ renderFn
288
+ )
289
+ }
290
+
291
+ const attrs = this.attrs as Record<string, any>
292
+ const attributes = this.attributes as Record<string, any>
293
+ const classes = this.classes as string // todo: does this have to be casted to an object?
294
+ const attributeClasses = attrs.class as Record<string, any>
295
+ const tag = this.tag as string
296
+
297
+ return renderFn(
298
+ tag,
299
+ {
300
+ ...attrs,
301
+ ref: 'rootRef',
302
+ class: [attributeClasses, classes],
303
+ ...attributes
304
+ },
305
+ renderSlot(() => getVirtualChildren(renderFn))
306
+ )
277
307
  }
278
308
  })
279
309
  </script>
@@ -16,10 +16,6 @@
16
16
  type="number"
17
17
  title="Collapse count"
18
18
  />
19
- <dl-input
20
- v-model="classItem"
21
- title="Custom class for toast item"
22
- />
23
19
  <dl-input
24
20
  v-model="width"
25
21
  title="Custom width for toast item"
@@ -106,6 +102,7 @@ import {
106
102
  DlTextArea,
107
103
  DlToast
108
104
  } from '../components'
105
+ import { DlToastPositions, DlToastTypes } from '../components/types'
109
106
 
110
107
  export default defineComponent({
111
108
  name: 'DlToast',
@@ -124,16 +121,14 @@ export default defineComponent({
124
121
  const type = ref('success')
125
122
  const position = ref('bottom')
126
123
  const closable = ref(true)
127
- const classItem = ref('demo-toast')
128
124
  const width = ref('auto')
129
125
  const collapseCount = ref(null)
130
126
  function showToastMessage() {
131
127
  DlToast.open({
132
128
  message: message.value,
133
- position: position.value,
134
- type: type.value,
129
+ position: position.value as DlToastPositions,
130
+ type: type.value as DlToastTypes,
135
131
  duration: Number(duration.value) || 1000,
136
- classItem: classItem.value,
137
132
  closable: closable.value,
138
133
  width: width.value,
139
134
  collapseCount: collapseCount.value
@@ -145,7 +140,6 @@ export default defineComponent({
145
140
  duration,
146
141
  type,
147
142
  position,
148
- classItem,
149
143
  closable,
150
144
  width,
151
145
  collapseCount
@@ -1,17 +0,0 @@
1
- const Positions = Object.freeze({
2
- top_right: 'top-right',
3
- top: 'top',
4
- top_left: 'top-left',
5
- bottom_right: 'bottom-right',
6
- bottom: 'bottom',
7
- bottom_left: 'bottom-left'
8
- })
9
-
10
- const Types = Object.freeze({
11
- success: 'success',
12
- warning: 'warning',
13
- error: 'error',
14
- info: 'info'
15
- })
16
-
17
- export { Positions, Types }