@coreui/vue-pro 4.8.0-next.0 → 4.8.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 (44) hide show
  1. package/README.md +1 -1
  2. package/dist/components/form/CFormCheck.d.ts +13 -0
  3. package/dist/components/form/CFormSwitch.d.ts +13 -0
  4. package/dist/components/index.d.ts +1 -0
  5. package/dist/components/multi-select/CMultiSelect.d.ts +35 -44
  6. package/dist/components/multi-select/CMultiSelectNativeSelect.d.ts +1 -1
  7. package/dist/components/multi-select/CMultiSelectOptions.d.ts +13 -11
  8. package/dist/components/multi-select/CMultiSelectSelection.d.ts +1 -1
  9. package/dist/components/multi-select/types.d.ts +14 -0
  10. package/dist/components/multi-select/utils.d.ts +6 -0
  11. package/dist/components/smart-table/CSmartTable.d.ts +1 -1
  12. package/dist/components/smart-table/CSmartTableHead.d.ts +1 -1
  13. package/dist/components/virtual-scroller/CVirtualScroller.d.ts +23 -0
  14. package/dist/components/virtual-scroller/index.d.ts +6 -0
  15. package/dist/index.es.js +249 -135
  16. package/dist/index.es.js.map +1 -1
  17. package/dist/index.js +249 -133
  18. package/dist/index.js.map +1 -1
  19. package/dist/utils/index.d.ts +1 -3
  20. package/package.json +1 -1
  21. package/src/components/carousel/CCarousel.ts +36 -34
  22. package/src/components/form/CFormCheck.ts +7 -0
  23. package/src/components/form/CFormSwitch.ts +7 -0
  24. package/src/components/index.ts +1 -0
  25. package/src/components/multi-select/CMultiSelect.ts +33 -89
  26. package/src/components/multi-select/CMultiSelectNativeSelect.ts +2 -1
  27. package/src/components/multi-select/CMultiSelectOptions.ts +31 -17
  28. package/src/components/multi-select/CMultiSelectSelection.ts +2 -1
  29. package/src/components/multi-select/types.ts +15 -0
  30. package/src/components/multi-select/utils.ts +92 -0
  31. package/src/components/virtual-scroller/CVirtualScroller.ts +109 -0
  32. package/src/components/virtual-scroller/index.ts +10 -0
  33. package/src/utils/index.ts +1 -3
  34. package/dist/components/accordion/CAccordionCollapse.d.ts +0 -22
  35. package/dist/components/multi-select/CMultiSelect copy.d.ts +0 -305
  36. package/dist/components/pagination/CSmartPagination.d.ts +0 -257
  37. package/dist/utils/calendar.d.ts +0 -23
  38. package/dist/utils/getNextSibling.d.ts +0 -2
  39. package/dist/utils/getPreviousSibling.d.ts +0 -2
  40. package/dist/utils/isObjectInArray.d.ts +0 -2
  41. package/dist/utils/isVisible.d.ts +0 -2
  42. package/dist/utils/time.d.ts +0 -21
  43. package/src/utils/getNextSibling.ts +0 -18
  44. package/src/utils/getPreviousSibling.ts +0 -18
@@ -0,0 +1,92 @@
1
+ import type { Option, SelectedOption } from './types'
2
+
3
+ export const filterOptionsList = (search: string, _options: Option[]) => {
4
+ return search.length
5
+ ? _options &&
6
+ _options.reduce((acc: Option[], val: Option) => {
7
+ const options =
8
+ val.options &&
9
+ val.options.filter(
10
+ (element) =>
11
+ element.text && element.text.toLowerCase().includes(search.toLowerCase()),
12
+ )
13
+
14
+ if (
15
+ (val.text && val.text.toLowerCase().includes(search.toLowerCase())) ||
16
+ (options && options.length)
17
+ ) {
18
+ acc.push(Object.assign({}, val, options && options.length && { options }))
19
+ }
20
+
21
+ return acc
22
+ }, [])
23
+ : _options
24
+ }
25
+
26
+ export const flattenArray = (options: Option[]): Option[] => {
27
+ return options.reduce((acc: Option[], val: Option) => {
28
+ return acc.concat(Array.isArray(val.options) ? flattenArray(val.options) : val)
29
+ }, [])
30
+ }
31
+
32
+ export const getNextSibling = (elem: HTMLElement, selector?: string) => {
33
+ // Get the next sibling element
34
+ let sibling = elem.nextElementSibling
35
+
36
+ // If there's no selector, return the first sibling
37
+ if (!selector) return sibling
38
+
39
+ // If the sibling matches our selector, use it
40
+ // If not, jump to the next sibling and continue the loop
41
+ while (sibling) {
42
+ if (sibling.matches(selector)) return sibling
43
+ sibling = sibling.nextElementSibling
44
+ }
45
+
46
+ return
47
+ }
48
+
49
+ export const getPreviousSibling = (elem: HTMLElement, selector?: string) => {
50
+ // Get the next sibling element
51
+ let sibling = elem.previousElementSibling
52
+
53
+ // If there's no selector, return the first sibling
54
+ if (!selector) return sibling
55
+
56
+ // If the sibling matches our selector, use it
57
+ // If not, jump to the next sibling and continue the loop
58
+ while (sibling) {
59
+ if (sibling.matches(selector)) return sibling
60
+ sibling = sibling.previousElementSibling
61
+ }
62
+
63
+ return
64
+ }
65
+
66
+ export const selectOptions = (
67
+ options: Option[],
68
+ selected: SelectedOption[],
69
+ deselected?: Option[],
70
+ ) => {
71
+ let _selected = [...selected, ...options]
72
+
73
+ if (deselected) {
74
+ _selected = _selected.filter(
75
+ (selectedOption) =>
76
+ !deselected.some((deselectedOption) => deselectedOption.value === selectedOption.value),
77
+ )
78
+ }
79
+
80
+ const deduplicated = _selected.reduce((unique: Option[], option) => {
81
+ if (!unique.some((obj) => obj.value === option.value)) {
82
+ unique.push({
83
+ value: option.value,
84
+ text: option.text,
85
+ ...(option.disabled && { disabled: option.disabled }),
86
+ })
87
+ }
88
+ return unique
89
+ }, []) as SelectedOption[]
90
+
91
+ return deduplicated
92
+ }
@@ -0,0 +1,109 @@
1
+ import { cloneVNode, computed, defineComponent, h, onMounted, ref, VNode } from 'vue'
2
+
3
+ const CVirtualScroller = defineComponent({
4
+ name: 'CVirtualScroller',
5
+ props: {
6
+ /**
7
+ * Amount of visible items
8
+ */
9
+ visibleItems: {
10
+ type: Number,
11
+ default: 10,
12
+ },
13
+ },
14
+ setup(props, { slots }) {
15
+ const virtualScrollRef = ref<HTMLDivElement>()
16
+ const virtualScrollContentRef = ref<HTMLDivElement>()
17
+
18
+ const currentItemIndex = ref(1)
19
+ const itemHeight = ref<number>(0)
20
+ const itemsNumber = ref<number>(0)
21
+ const viewportPadding = ref(0)
22
+
23
+ const buffer = computed(() => Math.floor(props.visibleItems / 2))
24
+
25
+ const maxHeight = computed(
26
+ () => itemsNumber.value * itemHeight.value + 2 * viewportPadding.value,
27
+ )
28
+
29
+ const viewportHeight = computed(
30
+ () => props.visibleItems * itemHeight.value + 2 * viewportPadding.value,
31
+ )
32
+
33
+ onMounted(() => {
34
+ if (virtualScrollRef.value) {
35
+ viewportPadding.value = parseFloat(getComputedStyle(virtualScrollRef.value).paddingTop)
36
+ // It's necessary to calculate heights of items
37
+ virtualScrollRef.value.dispatchEvent(new CustomEvent('scroll'))
38
+ }
39
+ })
40
+
41
+ const handleScroll = (scrollTop: number) => {
42
+ currentItemIndex.value =
43
+ itemHeight.value && Math.max(Math.ceil(scrollTop / itemHeight.value), 1)
44
+ }
45
+
46
+ return () => {
47
+ const children: any = slots.default
48
+ ? Array.isArray(slots.default()[0].children)
49
+ ? slots.default()[0].children
50
+ : slots.default()
51
+ : []
52
+ itemsNumber.value = children && children.length ? children.length : 0
53
+ return h(
54
+ 'div',
55
+ {
56
+ class: ['virtual-scroller'],
57
+ onScroll: (event: any) => handleScroll((event.target as HTMLDivElement).scrollTop),
58
+ style: {
59
+ height: `${
60
+ maxHeight.value > viewportHeight.value ? viewportHeight.value : maxHeight.value
61
+ }px`,
62
+ overflowY: 'auto',
63
+ },
64
+ ref: virtualScrollRef,
65
+ },
66
+ h(
67
+ 'div',
68
+ {
69
+ class: 'virtual-scroller-content',
70
+ style: {
71
+ height: `${maxHeight.value}px`,
72
+ },
73
+ ref: virtualScrollContentRef,
74
+ },
75
+ children.map(
76
+ (slot: VNode, index: number) =>
77
+ index + 1 > Math.max(currentItemIndex.value - buffer.value, 0) &&
78
+ index + 1 <= currentItemIndex.value + props.visibleItems + buffer.value &&
79
+ cloneVNode(slot, {
80
+ class: [
81
+ {
82
+ 'virtual-scroller-item-preload':
83
+ index + 1 > currentItemIndex.value + props.visibleItems ||
84
+ index + 1 < currentItemIndex.value,
85
+ },
86
+ ],
87
+ style: {
88
+ ...(currentItemIndex.value > buffer.value && {
89
+ transform: `translateY(${
90
+ (currentItemIndex.value - buffer.value) * itemHeight.value
91
+ }px)`,
92
+ }),
93
+ },
94
+ ref: (node) => {
95
+ if (node && (node as HTMLElement).offsetHeight) {
96
+ itemHeight.value =
97
+ (node as HTMLElement).offsetHeight +
98
+ parseFloat(getComputedStyle(node as HTMLElement).marginTop) +
99
+ parseFloat(getComputedStyle(node as HTMLElement).marginBottom)
100
+ }
101
+ },
102
+ }),
103
+ ),
104
+ ),
105
+ )
106
+ }
107
+ },
108
+ })
109
+ export { CVirtualScroller }
@@ -0,0 +1,10 @@
1
+ import { App } from 'vue'
2
+ import { CVirtualScroller } from './CVirtualScroller'
3
+
4
+ const CVirtualScrollerPlugin = {
5
+ install: (app: App): void => {
6
+ app.component(CVirtualScroller.name, CVirtualScroller)
7
+ },
8
+ }
9
+
10
+ export { CVirtualScroller, CVirtualScrollerPlugin }
@@ -1,5 +1,3 @@
1
- import getNextSibling from './getNextSibling'
2
- import getPreviousSibling from './getPreviousSibling'
3
1
  import isInViewport from './isInViewport'
4
2
 
5
- export { getNextSibling, getPreviousSibling, isInViewport }
3
+ export { isInViewport }
@@ -1,22 +0,0 @@
1
- declare const CAccordionCollapse: import("vue").DefineComponent<{
2
- /**
3
- * Toggle the visibility of component.
4
- */
5
- visible: {
6
- type: BooleanConstructor;
7
- required: false;
8
- };
9
- }, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
10
- [key: string]: any;
11
- }>, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, Record<string, any>, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
12
- /**
13
- * Toggle the visibility of component.
14
- */
15
- visible: {
16
- type: BooleanConstructor;
17
- required: false;
18
- };
19
- }>>, {
20
- visible: boolean;
21
- }>;
22
- export { CAccordionCollapse };
@@ -1,305 +0,0 @@
1
- import { PropType } from 'vue';
2
- export interface Option {
3
- disabled?: boolean;
4
- label?: string;
5
- options?: Option[];
6
- order?: number;
7
- selected?: boolean;
8
- text: string;
9
- value: number | string;
10
- }
11
- declare const CMultiSelect: import("vue").DefineComponent<{
12
- /**
13
- * Enables selection cleaner element.
14
- *
15
- * @default true
16
- */
17
- cleaner: {
18
- type: BooleanConstructor;
19
- required: false;
20
- default: boolean;
21
- };
22
- /**
23
- * Toggle the disabled state for the component.
24
- */
25
- disabled: {
26
- type: BooleanConstructor;
27
- required: false;
28
- default: boolean;
29
- };
30
- /**
31
- * It specifies that multiple options can be selected at once.
32
- *
33
- * @default true
34
- */
35
- multiple: {
36
- type: BooleanConstructor;
37
- default: boolean;
38
- required: false;
39
- };
40
- /**
41
- * List of option elements.
42
- */
43
- options: {
44
- type: PropType<Option[]>;
45
- default: () => never[];
46
- required: false;
47
- };
48
- /**
49
- * Sets maxHeight of options list.
50
- *
51
- * @default 'auto'
52
- */
53
- optionsMaxHeight: {
54
- type: (NumberConstructor | StringConstructor)[];
55
- default: string;
56
- required: false;
57
- };
58
- /**
59
- * Sets option style.
60
- *
61
- * @values 'checkbox', 'text'
62
- * @default 'checkbox'
63
- */
64
- optionsStyle: {
65
- type: StringConstructor;
66
- default: string;
67
- required: false;
68
- validator: (value: string) => boolean;
69
- };
70
- /**
71
- * Specifies a short hint that is visible in the search input.
72
- *
73
- * @default 'Select...''
74
- */
75
- placeholder: {
76
- type: StringConstructor;
77
- default: string;
78
- required: false;
79
- };
80
- /**
81
- * Enables search input element.
82
- */
83
- search: {
84
- type: BooleanConstructor;
85
- default: boolean;
86
- required: false;
87
- };
88
- /**
89
- * Sets the label for no results when filtering.
90
- */
91
- searchNoResultsLabel: {
92
- type: StringConstructor;
93
- default: string;
94
- required: false;
95
- };
96
- /**
97
- * Enables select all button.
98
- *
99
- * @default true
100
- */
101
- selectAll: {
102
- type: BooleanConstructor;
103
- required: false;
104
- default: boolean;
105
- };
106
- /**
107
- * Sets the select all button label.
108
- *
109
- * @default 'Select all options'
110
- */
111
- selectAllLabel: {
112
- type: StringConstructor;
113
- required: false;
114
- default: string;
115
- };
116
- /**
117
- * Sets the selection style.
118
- *
119
- * @values 'counter', 'tags', 'text'
120
- * @default 'tags'
121
- */
122
- selectionType: {
123
- type: StringConstructor;
124
- default: string;
125
- required: false;
126
- validator: (value: string) => boolean;
127
- };
128
- /**
129
- * Sets the counter selection label.
130
- *
131
- * @default 'item(s) selected'
132
- */
133
- selectionTypeCounterText: {
134
- type: StringConstructor;
135
- default: string;
136
- required: false;
137
- };
138
- /**
139
- * Toggle the visibility of multi select dropdown.
140
- *
141
- * @default false
142
- */
143
- visible: {
144
- type: BooleanConstructor;
145
- default: boolean;
146
- required: false;
147
- };
148
- }, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
149
- [key: string]: any;
150
- }>[], unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, "change"[], "change", import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
151
- /**
152
- * Enables selection cleaner element.
153
- *
154
- * @default true
155
- */
156
- cleaner: {
157
- type: BooleanConstructor;
158
- required: false;
159
- default: boolean;
160
- };
161
- /**
162
- * Toggle the disabled state for the component.
163
- */
164
- disabled: {
165
- type: BooleanConstructor;
166
- required: false;
167
- default: boolean;
168
- };
169
- /**
170
- * It specifies that multiple options can be selected at once.
171
- *
172
- * @default true
173
- */
174
- multiple: {
175
- type: BooleanConstructor;
176
- default: boolean;
177
- required: false;
178
- };
179
- /**
180
- * List of option elements.
181
- */
182
- options: {
183
- type: PropType<Option[]>;
184
- default: () => never[];
185
- required: false;
186
- };
187
- /**
188
- * Sets maxHeight of options list.
189
- *
190
- * @default 'auto'
191
- */
192
- optionsMaxHeight: {
193
- type: (NumberConstructor | StringConstructor)[];
194
- default: string;
195
- required: false;
196
- };
197
- /**
198
- * Sets option style.
199
- *
200
- * @values 'checkbox', 'text'
201
- * @default 'checkbox'
202
- */
203
- optionsStyle: {
204
- type: StringConstructor;
205
- default: string;
206
- required: false;
207
- validator: (value: string) => boolean;
208
- };
209
- /**
210
- * Specifies a short hint that is visible in the search input.
211
- *
212
- * @default 'Select...''
213
- */
214
- placeholder: {
215
- type: StringConstructor;
216
- default: string;
217
- required: false;
218
- };
219
- /**
220
- * Enables search input element.
221
- */
222
- search: {
223
- type: BooleanConstructor;
224
- default: boolean;
225
- required: false;
226
- };
227
- /**
228
- * Sets the label for no results when filtering.
229
- */
230
- searchNoResultsLabel: {
231
- type: StringConstructor;
232
- default: string;
233
- required: false;
234
- };
235
- /**
236
- * Enables select all button.
237
- *
238
- * @default true
239
- */
240
- selectAll: {
241
- type: BooleanConstructor;
242
- required: false;
243
- default: boolean;
244
- };
245
- /**
246
- * Sets the select all button label.
247
- *
248
- * @default 'Select all options'
249
- */
250
- selectAllLabel: {
251
- type: StringConstructor;
252
- required: false;
253
- default: string;
254
- };
255
- /**
256
- * Sets the selection style.
257
- *
258
- * @values 'counter', 'tags', 'text'
259
- * @default 'tags'
260
- */
261
- selectionType: {
262
- type: StringConstructor;
263
- default: string;
264
- required: false;
265
- validator: (value: string) => boolean;
266
- };
267
- /**
268
- * Sets the counter selection label.
269
- *
270
- * @default 'item(s) selected'
271
- */
272
- selectionTypeCounterText: {
273
- type: StringConstructor;
274
- default: string;
275
- required: false;
276
- };
277
- /**
278
- * Toggle the visibility of multi select dropdown.
279
- *
280
- * @default false
281
- */
282
- visible: {
283
- type: BooleanConstructor;
284
- default: boolean;
285
- required: false;
286
- };
287
- }>> & {
288
- onChange?: ((...args: any[]) => any) | undefined;
289
- }, {
290
- search: boolean;
291
- visible: boolean;
292
- disabled: boolean;
293
- multiple: boolean;
294
- options: Option[];
295
- cleaner: boolean;
296
- placeholder: string;
297
- optionsMaxHeight: string | number;
298
- optionsStyle: string;
299
- searchNoResultsLabel: string;
300
- selectionType: string;
301
- selectionTypeCounterText: string;
302
- selectAll: boolean;
303
- selectAllLabel: string;
304
- }>;
305
- export { CMultiSelect };