@central-design-system/components 3.0.0-alpha.5 → 3.0.0-alpha.7

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 (59) hide show
  1. package/dist/cds.css +1 -1
  2. package/dist/cds.d.ts +51 -48
  3. package/dist/cds.es.js +3841 -3315
  4. package/dist/cds.umd.js +1 -1
  5. package/dist/components/CdsButton/CdsButton.vue.d.ts +6 -5
  6. package/dist/components/CdsCombobox/CdsCombobox.vue.d.ts +98 -80
  7. package/dist/components/CdsDropdown/CdsDropdown.vue.d.ts +134 -54
  8. package/dist/components/CdsGrid/composable/grid.d.ts +2 -1
  9. package/dist/components/CdsInput/CdsInput.vue.d.ts +14 -0
  10. package/dist/components/CdsMenu/CdsMenu.vue.d.ts +24 -18
  11. package/dist/components/CdsOverlay/CdsOverlay.vue.d.ts +9 -13
  12. package/dist/components/CdsOverlay/composable/locationStrategies.d.ts +3 -0
  13. package/dist/components/CdsPagination/CdsPagination.vue.d.ts +142 -0
  14. package/dist/components/CdsSelect/CdsSelect.vue.d.ts +40 -22
  15. package/dist/components/CdsTextArea/CdsTextArea.vue.d.ts +15 -3
  16. package/dist/components/CdsTextInput/CdsTextInput.vue.d.ts +64 -10
  17. package/dist/components/CdsTooltip/CdsTooltip.vue.d.ts +765 -0
  18. package/dist/components/index.d.ts +3 -1
  19. package/dist/composable/dimensions.d.ts +23 -5
  20. package/dist/composable/display.d.ts +56 -0
  21. package/dist/composable/index.d.ts +3 -0
  22. package/dist/composable/overlay.d.ts +1 -1
  23. package/dist/composable/refs.d.ts +6 -0
  24. package/dist/composable/resizeObserver.d.ts +7 -0
  25. package/dist/create.d.ts +21 -0
  26. package/dist/globals.d.ts +2 -0
  27. package/dist/utils/helpers.d.ts +2 -0
  28. package/package.json +1 -2
  29. package/src/scss/themes/index.ts +1 -1
  30. package/src/scss/utility/lists.scss +1 -0
  31. package/dist/types/CdsOptions.d.ts +0 -3
  32. package/src/utils/__test__/helper.test.ts +0 -59
  33. package/src/utils/__test__/mocks/helper.mock.ts +0 -362
  34. package/src/utils/__test__/mocks/propFactory.mock.ts +0 -88
  35. package/src/utils/__test__/propFactory.test.ts +0 -9
  36. package/src/utils/anchor.ts +0 -76
  37. package/src/utils/animation.ts +0 -62
  38. package/src/utils/box.ts +0 -39
  39. package/src/utils/cache.ts +0 -12
  40. package/src/utils/changeCase/__test__/lowerCase.test.ts +0 -12
  41. package/src/utils/changeCase/__test__/mocks/lowerCase.mock.ts +0 -80
  42. package/src/utils/changeCase/__test__/mocks/noCase.mock.ts +0 -131
  43. package/src/utils/changeCase/__test__/mocks/paramCase.mock.ts +0 -39
  44. package/src/utils/changeCase/__test__/mocks/pascalCase.mock.ts +0 -46
  45. package/src/utils/changeCase/__test__/noCase.test.ts +0 -8
  46. package/src/utils/changeCase/__test__/paramCase.test.ts +0 -8
  47. package/src/utils/changeCase/__test__/pascalCase.test.ts +0 -8
  48. package/src/utils/changeCase/lowerCase.ts +0 -56
  49. package/src/utils/changeCase/noCase.ts +0 -45
  50. package/src/utils/changeCase/paramCase.ts +0 -11
  51. package/src/utils/changeCase/pascalCase.ts +0 -24
  52. package/src/utils/date.ts +0 -1106
  53. package/src/utils/dom.ts +0 -24
  54. package/src/utils/getCurrentInstance.ts +0 -43
  55. package/src/utils/getScrollParent.ts +0 -29
  56. package/src/utils/globals.ts +0 -8
  57. package/src/utils/helpers.ts +0 -312
  58. package/src/utils/index.ts +0 -19
  59. package/src/utils/propsFactory.ts +0 -92
package/src/utils/dom.ts DELETED
@@ -1,24 +0,0 @@
1
- /**
2
- * Returns:
3
- * - 'null' if the node is not attached to the DOM
4
- * - the root node (HTMLDocument | ShadowRoot) otherwise
5
- */
6
- export function attachedRoot(node: Node): null | HTMLDocument | ShadowRoot {
7
- /* istanbul ignore next */
8
- if (typeof node.getRootNode !== 'function') {
9
- // Shadow DOM not supported (IE11), lets find the root of this node
10
- while (node.parentNode) node = node.parentNode;
11
-
12
- // The root parent is the document if the node is attached to the DOM
13
- if (node !== document) return null;
14
-
15
- return document;
16
- }
17
-
18
- const root = node.getRootNode();
19
-
20
- // The composed root node is the document if the node is attached to the DOM
21
- if (root !== document && root.getRootNode({ composed: true }) !== document) return null;
22
-
23
- return root as HTMLDocument | ShadowRoot;
24
- }
@@ -1,43 +0,0 @@
1
- import { getCurrentInstance as _getCurrentInstance } from 'vue';
2
- import { paramCase } from './';
3
-
4
- import type { ComponentInternalInstance } from 'vue';
5
-
6
- /**
7
- * This is a wrapper around Vue's getCurrentInstance
8
- * WARNING! It's not a public API and can be removed in the future
9
- * @param name
10
- * @param message
11
- */
12
- export function getCurrentInstance(name: string, message?: string) {
13
- const vm = _getCurrentInstance();
14
-
15
- if (!vm) {
16
- throw new Error(`[CDS] ${name} ${message || 'must be called from inside a setup function'}`);
17
- }
18
-
19
- return vm;
20
- }
21
-
22
- export function getCurrentInstanceName(name = 'composable') {
23
- const vm = getCurrentInstance(name);
24
- return paramCase(vm.type?.name || '');
25
- }
26
-
27
- let _uid = 0;
28
- let _map = new WeakMap<ComponentInternalInstance, number>();
29
- export function getUid() {
30
- const vm = getCurrentInstance('getUid');
31
-
32
- if (_map.has(vm)) {
33
- return _map.get(vm)!;
34
- } else {
35
- const uid = _uid++;
36
- _map.set(vm, uid);
37
- return uid;
38
- }
39
- }
40
- getUid.reset = () => {
41
- _uid = 0;
42
- _map = new WeakMap();
43
- };
@@ -1,29 +0,0 @@
1
- export function getScrollParent(el?: HTMLElement) {
2
- while (el) {
3
- if (hasScrollbar(el)) return el;
4
- el = el.parentElement!;
5
- }
6
-
7
- return document.scrollingElement as HTMLElement;
8
- }
9
-
10
- export function getScrollParents(el?: Element | null, stopAt?: Element | null) {
11
- const elements: HTMLElement[] = [];
12
-
13
- if (stopAt && el && !stopAt.contains(el)) return elements;
14
-
15
- while (el) {
16
- if (hasScrollbar(el)) elements.push(el as HTMLElement);
17
- if (el === stopAt) break;
18
- el = el.parentElement!;
19
- }
20
-
21
- return elements;
22
- }
23
-
24
- export function hasScrollbar(el?: Element | null) {
25
- if (!el || el.nodeType !== Node.ELEMENT_NODE) return false;
26
-
27
- const style = window.getComputedStyle(el);
28
- return style.overflowY === 'scroll' || (style.overflowY === 'auto' && el.scrollHeight > el.clientHeight);
29
- }
@@ -1,8 +0,0 @@
1
- export const IN_BROWSER = typeof window !== 'undefined';
2
- export const SUPPORTS_INTERSECTION = IN_BROWSER && 'IntersectionObserver' in window;
3
- export const SUPPORTS_TOUCH = IN_BROWSER && ('ontouchstart' in window || window.navigator.maxTouchPoints > 0);
4
- export const SUPPORTS_FOCUS_VISIBLE =
5
- IN_BROWSER &&
6
- typeof CSS !== 'undefined' &&
7
- typeof CSS.supports !== 'undefined' &&
8
- CSS.supports('selector(:focus-visible)');
@@ -1,312 +0,0 @@
1
- import { computed, reactive, watchEffect, toRefs } from 'vue';
2
-
3
- import type { ComponentPublicInstance, ComputedGetter, PropType, Ref, ToRefs } from 'vue';
4
- import type { TItemKey } from '@components/composable';
5
-
6
- export const keyNames = Object.freeze({
7
- enter: 'Enter',
8
- tab: 'Tab',
9
- delete: 'Delete',
10
- esc: 'Escape',
11
- space: ' ',
12
- up: 'ArrowUp',
13
- down: 'ArrowDown',
14
- left: 'ArrowLeft',
15
- right: 'ArrowRight',
16
- end: 'End',
17
- home: 'Home',
18
- del: 'Del',
19
- backspace: 'Backspace',
20
- insert: 'Insert',
21
- pageup: 'PageUp',
22
- pagedown: 'PageDown',
23
- shift: 'Shift'
24
- });
25
-
26
- export const classesStates = Object.freeze({
27
- hover: 'cds-state-hover',
28
- focus: 'cds-state-focus',
29
- active: 'cds-state-active',
30
- visited: 'cds-state-visited',
31
- disabled: 'cds-state-disabled',
32
- checked: 'cds-state-checked',
33
- indeterminate: 'cds-state-indeterminate',
34
- invalid: 'cds-state-invalid',
35
- empty: 'cds-state-empty',
36
- loading: 'cds-state-loading',
37
- readonly: 'cds-state-readonly'
38
- });
39
-
40
- /**
41
- * Check if value is a object.
42
- * @param obj
43
- */
44
- export function isObject(obj: any): obj is object {
45
- return obj !== null && typeof obj === 'object' && !Array.isArray(obj);
46
- }
47
-
48
- /**
49
- * Check if value is a Date.
50
- * @param value
51
- */
52
- export function isDate(value: any) {
53
- return Object.prototype.toString.call(value) === '[object Date]';
54
- }
55
-
56
- /**
57
- * Deep merge two objects.
58
- * @param source
59
- * @param target
60
- * @param arrayFn
61
- */
62
- export function mergeDeep(
63
- source: Record<string, any> = {},
64
- target: Record<string, any> = {},
65
- arrayFn?: (a: unknown[], b: unknown[]) => unknown[]
66
- ) {
67
- const out: Record<string, any> = {};
68
-
69
- for (const key in source) {
70
- out[key] = source[key];
71
- }
72
-
73
- for (const key in target) {
74
- const sourceProperty = source[key];
75
- const targetProperty = target[key];
76
-
77
- // Only continue deep merging if
78
- // both properties are objects
79
- if (isObject(sourceProperty) && isObject(targetProperty)) {
80
- out[key] = mergeDeep(sourceProperty, targetProperty, arrayFn);
81
-
82
- continue;
83
- }
84
-
85
- if (Array.isArray(sourceProperty) && Array.isArray(targetProperty) && arrayFn) {
86
- out[key] = arrayFn(sourceProperty, targetProperty);
87
-
88
- continue;
89
- }
90
-
91
- out[key] = targetProperty;
92
- }
93
-
94
- return out;
95
- }
96
-
97
- /**
98
- * Deep compare two values to determine if they are equivalent.
99
- * @param a
100
- * @param b
101
- */
102
- export function deepEqual(a: any, b: any): boolean {
103
- if (a === b) return true;
104
-
105
- if (a instanceof Date && b instanceof Date && a.getTime() !== b.getTime()) {
106
- // If the values are Date, compare them as timestamps
107
- return false;
108
- }
109
-
110
- if (a !== Object(a) || b !== Object(b)) {
111
- // If the values aren't objects, they were already checked for equality
112
- return false;
113
- }
114
-
115
- const props = Object.keys(a);
116
-
117
- if (props.length !== Object.keys(b).length) {
118
- // Different number of props, don't bother to check
119
- return false;
120
- }
121
-
122
- return props.every((p) => deepEqual(a[p], b[p]));
123
- }
124
-
125
- /**
126
- * Wrap value in array if it's not already an array
127
- * @param value
128
- */
129
- export function wrapInArray<T>(value: T | T[] | null | undefined): T[] {
130
- return value == null ? [] : Array.isArray(value) ? value : [value];
131
- }
132
-
133
- /**
134
- * Get the nested value of an object at a given path.
135
- * @param obj
136
- * @param path
137
- * @param fallback
138
- */
139
- export function getNestedValue(obj: any, path: (string | number)[], fallback?: any): any {
140
- const last = path.length - 1;
141
-
142
- if (last < 0) return obj === undefined ? fallback : obj;
143
-
144
- for (let i = 0; i < last; i++) {
145
- if (obj == null) {
146
- return fallback;
147
- }
148
- obj = obj[path[i]];
149
- }
150
-
151
- if (obj == null) return fallback;
152
-
153
- return obj[path[last]] === undefined ? fallback : obj[path[last]];
154
- }
155
-
156
- /**
157
- * Get the value of an object at a given path.
158
- * @param obj
159
- * @param path
160
- * @param fallback
161
- */
162
- export function getObjectValueByPath(obj: any, path: string, fallback?: any) {
163
- if (obj == null || !path || typeof path !== 'string') return fallback;
164
- if (obj[path] !== undefined) return obj[path];
165
- path = path.replace(/\[(\w+)\]/g, '.$1'); // convert indexes to properties
166
- path = path.replace(/^\./, ''); // strip a leading dot
167
- return getNestedValue(obj, path.split('.'), fallback);
168
- }
169
-
170
- export function getPropertyFromItem(item: any, property: SelectItemKey, fallback?: any): any {
171
- if (property == null) return item === undefined ? fallback : item;
172
- if (item !== Object(item)) return fallback;
173
- if (typeof property === 'string') return getObjectValueByPath(item, property, fallback);
174
- if (Array.isArray(property)) return getNestedValue(item, property, fallback);
175
- if (typeof property !== 'function') return fallback;
176
-
177
- const value = property(item, fallback);
178
- return typeof value === 'undefined' ? fallback : value;
179
- }
180
-
181
- /**
182
- * @description This function is used to return a copy of the object that is composed of the picked object properties.
183
- * @param obj
184
- * @param paths
185
- */
186
- export function pick<T extends object, U extends Extract<keyof T, string>>(
187
- obj: T,
188
- paths: U[]
189
- ): [yes: MaybePick<T, U>, no: Omit<T, U>];
190
- export function pick<T extends object, U extends Extract<keyof T, string>>(
191
- obj: T,
192
- paths: (U | RegExp)[]
193
- ): [yes: Partial<T>, no: Partial<T>] {
194
- const found = Object.create(null);
195
- const rest = Object.create(null);
196
-
197
- for (const key in obj) {
198
- if (paths.some((path) => (path instanceof RegExp ? path.test(key) : path === key))) {
199
- found[key] = obj[key];
200
- } else {
201
- rest[key] = obj[key];
202
- }
203
- }
204
-
205
- return [found, rest];
206
- }
207
-
208
- /**
209
- * Convert a computed ref to a record of refs.
210
- * The getter function must always return an object with the same keys.
211
- */
212
- export function destructComputed<T extends object>(getter: ComputedGetter<T & NotAUnion<T>>): ToRefs<T>;
213
- export function destructComputed<T extends object>(getter: ComputedGetter<T>) {
214
- const refs = reactive({}) as T;
215
- const base = computed(getter);
216
- watchEffect(
217
- () => {
218
- for (const key in base.value) {
219
- refs[key] = base.value[key];
220
- }
221
- },
222
- { flush: 'sync' }
223
- );
224
- return toRefs(refs);
225
- }
226
-
227
- /**
228
- * Array.includes but value can be any type
229
- * @param arr
230
- * @param val
231
- */
232
- export function includes(arr: readonly any[], val: any) {
233
- return arr.includes(val);
234
- }
235
-
236
- export function convertToUnit(str: number, unit?: string): string;
237
- export function convertToUnit(str: string | number | null | undefined, unit?: string): string | undefined;
238
- export function convertToUnit(str: string | number | null | undefined, unit = 'px'): string | undefined {
239
- if (str == null || str === '') {
240
- return undefined;
241
- } else if (isNaN(+str!)) {
242
- return String(str);
243
- } else if (!isFinite(+str!)) {
244
- return undefined;
245
- } else {
246
- return `${Number(str)}${unit}`;
247
- }
248
- }
249
-
250
- /**
251
- * Clamp a value between a min and max
252
- * @param value
253
- * @param min
254
- * @param max
255
- */
256
- export function clamp(value: number, min = 0, max = 1) {
257
- return Math.max(min, Math.min(max, value));
258
- }
259
-
260
- /**
261
- * Is value an like event
262
- * @param key
263
- */
264
- export const isOn = (key: string) => key.startsWith('on');
265
-
266
- export const EventProp = [Function, Array] as PropType<EventProp>;
267
-
268
- export function isComponentInstance(obj: any): obj is ComponentPublicInstance {
269
- return obj?.$el;
270
- }
271
-
272
- export function isFixedPosition(el?: HTMLElement) {
273
- while (el) {
274
- if (window.getComputedStyle(el).position === 'fixed') {
275
- return true;
276
- }
277
- el = el.offsetParent as HTMLElement;
278
- }
279
- return false;
280
- }
281
-
282
- export function padStart(string: number | string, targetLength: number, padString: string) {
283
- targetLength = targetLength >> 0;
284
- string = String(string);
285
- padString = String(padString);
286
- if (string.length > targetLength) {
287
- return String(string);
288
- }
289
-
290
- targetLength = targetLength - string.length;
291
- if (targetLength > padString.length) {
292
- padString += padString.repeat(targetLength / padString.length);
293
- }
294
- return padString.slice(0, targetLength) + String(string);
295
- }
296
-
297
- export function pad(n: string | number, length = 2) {
298
- return padStart(n, length, '0');
299
- }
300
-
301
- /**
302
- * Types
303
- */
304
- export type MaybeRef<T> = T | Ref<T>;
305
- export type SelectItemKey = TItemKey;
306
- export type MaybePick<T extends object, U extends Extract<keyof T, string>> = Record<string, unknown> extends T
307
- ? Partial<Pick<T, U>>
308
- : Pick<T, U>;
309
- export type EventProp<T = (...args: any[]) => any> = T;
310
- // Only allow a single return type
311
- type NotAUnion<T> = [T] extends [infer U] ? _NotAUnion<U, U> : never;
312
- type _NotAUnion<T, U> = U extends any ? ([T] extends [U] ? unknown : never) : never;
@@ -1,19 +0,0 @@
1
- export * from './propsFactory';
2
- export * from './helpers';
3
- export * from './getCurrentInstance';
4
- export * from './getScrollParent';
5
- export * from './globals';
6
- export * from './dom';
7
- export * from './anchor';
8
- export * from './box';
9
- export * from './animation';
10
- export * from './cache';
11
-
12
- // change case
13
- export * from './changeCase/noCase';
14
- export * from './changeCase/lowerCase';
15
- export * from './changeCase/pascalCase';
16
- export * from './changeCase/paramCase';
17
-
18
- // date
19
- export * from './date';
@@ -1,92 +0,0 @@
1
- import type { PropType } from 'vue';
2
- import type { Prop, ComponentObjectPropsOptions } from '../shims-vue';
3
-
4
- /**
5
- * Creates a factory function for props definitions.
6
- * This is used to define props in a composable then override
7
- * default values in an implementing component.
8
- *
9
- * @example Simplified signature
10
- * (props: Props) => (defaults?: Record<keyof props, any>) => Props
11
- *
12
- * @example Usage
13
- * const makeProps = propsFactory({
14
- * foo: String,
15
- * })
16
- *
17
- * defineComponent({
18
- * props: {
19
- * ...makeProps({
20
- * foo: 'a',
21
- * }),
22
- * },
23
- * setup (props) {
24
- * // would be "string | undefined", now "string" because a default has been provided
25
- * props.foo
26
- * },
27
- * }
28
- */
29
- export function propsFactory<PropsOptions extends ComponentObjectPropsOptions = ComponentObjectPropsOptions>(
30
- props: PropsOptions,
31
- source: string
32
- ) {
33
- return <Defaults extends PartialKeys<PropsOptions> = {}>(
34
- defaults?: Defaults
35
- ): AppendDefault<PropsOptions, Defaults> => {
36
- return Object.keys(props).reduce<any>((obj, prop) => {
37
- const isObjectDefinition = typeof props[prop] === 'object' && props[prop] != null && !Array.isArray(props[prop]);
38
- const definition = isObjectDefinition ? props[prop] : { type: props[prop] };
39
-
40
- if (defaults && prop in defaults) {
41
- obj[prop] = {
42
- ...definition,
43
- default: defaults[prop]
44
- };
45
- } else {
46
- obj[prop] = definition;
47
- }
48
-
49
- if (source && !obj[prop].source) {
50
- obj[prop].source = source;
51
- }
52
-
53
- return obj;
54
- }, {});
55
- };
56
- }
57
-
58
- export type AppendDefault<T extends ComponentObjectPropsOptions, D extends PartialKeys<T>> = {
59
- [P in keyof T]-?: unknown extends D[P]
60
- ? T[P]
61
- : T[P] extends Record<string, unknown>
62
- ? Omit<T[P], 'type' | 'default'> & {
63
- type: PropType<MergeDefaults<T[P], D[P]>>;
64
- default: MergeDefaults<T[P], D[P]>;
65
- }
66
- : {
67
- type: PropType<MergeDefaults<T[P], D[P]>>;
68
- default: MergeDefaults<T[P], D[P]>;
69
- };
70
- };
71
-
72
- type MergeDefaults<T, D> = unknown extends D ? InferPropType<T> : NonNullable<InferPropType<T>> | D;
73
-
74
- /**
75
- * Like `Partial<T>` but doesn't care what the value is
76
- */
77
- type PartialKeys<T> = { [P in keyof T]?: unknown };
78
-
79
- // Copied from Vue
80
- type InferPropType<T> = T extends null
81
- ? any // null & true would fail to infer
82
- : T extends { type: null | true }
83
- ? any // As TS issue https://github.com/Microsoft/TypeScript/issues/14829 // somehow `ObjectConstructor` when inferred from { (): T } becomes `any` // `BooleanConstructor` when inferred from PropConstructor(with PropMethod) becomes `Boolean`
84
- : T extends ObjectConstructor | { type: ObjectConstructor }
85
- ? Record<string, any>
86
- : T extends BooleanConstructor | { type: BooleanConstructor }
87
- ? boolean
88
- : T extends Prop<infer V, infer D>
89
- ? unknown extends V
90
- ? D
91
- : V
92
- : T;