@onereach/ui-components-common 19.3.0-beta.5083.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.
- package/dist/assets/index.d.ts +2 -0
- package/dist/assets.js +5 -0
- package/dist/directives/dropdown-close.d.ts +4 -0
- package/dist/directives/dropdown-open.d.ts +4 -0
- package/dist/directives/index.d.ts +2 -0
- package/dist/directives.js +5 -0
- package/dist/dom-CwV-xS38.js +95 -0
- package/dist/dropdown-open-k6cFnrqA.js +20 -0
- package/dist/extractCssVarName-IHa2pGlF.js +160 -0
- package/dist/helpers/getItemByValue.d.ts +2 -0
- package/dist/helpers/getItemsByValue.d.ts +2 -0
- package/dist/helpers/index.d.ts +3 -0
- package/dist/helpers/searchItemsByLabel.d.ts +2 -0
- package/dist/helpers.js +6 -0
- package/dist/hooks/index.d.ts +15 -0
- package/dist/hooks/useControlAttributes.d.ts +7 -0
- package/dist/hooks/useDateFormat.d.ts +4 -0
- package/dist/hooks/useDateMask.d.ts +4 -0
- package/dist/hooks/useElevation.d.ts +3 -0
- package/dist/hooks/useIdAttribute.d.ts +3 -0
- package/dist/hooks/useLocale.d.ts +4 -0
- package/dist/hooks/useOverflow.d.ts +11 -0
- package/dist/hooks/usePopoverState.d.ts +12 -0
- package/dist/hooks/useProxyModelValue.d.ts +8 -0
- package/dist/hooks/useResponsive/index.d.ts +1 -0
- package/dist/hooks/useResponsive/useResponsive.d.ts +6 -0
- package/dist/hooks/useTheme.d.ts +3 -0
- package/dist/hooks/useTimeFormat.d.ts +4 -0
- package/dist/hooks/useTimeMask.d.ts +4 -0
- package/dist/hooks/useToggle.d.ts +8 -0
- package/dist/hooks/useValidationAttributes.d.ts +11 -0
- package/dist/hooks.js +18 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +138 -0
- package/dist/isUndefined-B5qXrATz.js +4 -0
- package/dist/isVisible-BuGrjvTY.js +4 -0
- package/dist/searchItemsByLabel-BhinsABA.js +13 -0
- package/dist/tokens/DATE_FORMAT.d.ts +3 -0
- package/dist/tokens/LOCALE.d.ts +3 -0
- package/dist/tokens/TIME_FORMAT.d.ts +3 -0
- package/dist/tokens/index.d.ts +3 -0
- package/dist/types/DataModel.d.ts +6 -0
- package/dist/types/DateFormat.d.ts +5 -0
- package/dist/types/FilterFunction.d.ts +1 -0
- package/dist/types/FormatFunction.d.ts +2 -0
- package/dist/types/Group.d.ts +5 -0
- package/dist/types/GroupFunction.d.ts +1 -0
- package/dist/types/Id.d.ts +1 -0
- package/dist/types/Item.d.ts +5 -0
- package/dist/types/Locale.d.ts +1 -0
- package/dist/types/ModelValue.d.ts +1 -0
- package/dist/types/SearchFunction.d.ts +1 -0
- package/dist/types/TimeFormat.d.ts +5 -0
- package/dist/types/index.d.ts +12 -0
- package/dist/types.js +5 -0
- package/dist/useValidationAttributes-DxhcSj_h.js +217 -0
- package/dist/utils/constants/color.d.ts +14 -0
- package/dist/utils/constants/key-codes.d.ts +14 -0
- package/dist/utils/constants/poper.d.ts +8 -0
- package/dist/utils/constants/regex.d.ts +42 -0
- package/dist/utils/exclude.d.ts +4 -0
- package/dist/utils/extractCssVarName.d.ts +1 -0
- package/dist/utils/functions/color.d.ts +23 -0
- package/dist/utils/functions/dom.d.ts +30 -0
- package/dist/utils/functions/flattenDeep.d.ts +2 -0
- package/dist/utils/functions/hash.d.ts +2 -0
- package/dist/utils/functions/px-to-rem.d.ts +1 -0
- package/dist/utils/functions/text.d.ts +1 -0
- package/dist/utils/include.d.ts +4 -0
- package/dist/utils/index.d.ts +26 -0
- package/dist/utils/isAncestor.d.ts +4 -0
- package/dist/utils/isArray.d.ts +4 -0
- package/dist/utils/isDescendant.d.ts +4 -0
- package/dist/utils/isEmpty.d.ts +4 -0
- package/dist/utils/isEqual.d.ts +4 -0
- package/dist/utils/isNil.d.ts +4 -0
- package/dist/utils/isNull.d.ts +4 -0
- package/dist/utils/isNumber.d.ts +4 -0
- package/dist/utils/isObject.d.ts +4 -0
- package/dist/utils/isString.d.ts +4 -0
- package/dist/utils/isUndefined.d.ts +4 -0
- package/dist/utils/isVisible.d.ts +1 -0
- package/dist/utils/toArray.d.ts +4 -0
- package/dist/utils.js +109 -0
- package/package.json +77 -0
- package/src/assets/error.png +0 -0
- package/src/assets/index.ts +2 -0
- package/src/assets/success.png +0 -0
- package/src/directives/dropdown-close.ts +14 -0
- package/src/directives/dropdown-open.ts +21 -0
- package/src/directives/index.ts +2 -0
- package/src/helpers/getItemByValue.ts +12 -0
- package/src/helpers/getItemsByValue.ts +6 -0
- package/src/helpers/index.ts +3 -0
- package/src/helpers/searchItemsByLabel.ts +5 -0
- package/src/hooks/index.ts +15 -0
- package/src/hooks/useControlAttributes.ts +19 -0
- package/src/hooks/useDateFormat.ts +13 -0
- package/src/hooks/useDateMask.ts +54 -0
- package/src/hooks/useElevation.ts +32 -0
- package/src/hooks/useIdAttribute.ts +11 -0
- package/src/hooks/useLocale.ts +13 -0
- package/src/hooks/useOverflow.ts +83 -0
- package/src/hooks/usePopoverState.ts +67 -0
- package/src/hooks/useProxyModelValue.ts +50 -0
- package/src/hooks/useResponsive/index.ts +1 -0
- package/src/hooks/useResponsive/useResponsive.ts +58 -0
- package/src/hooks/useTheme.ts +8 -0
- package/src/hooks/useTimeFormat.ts +13 -0
- package/src/hooks/useTimeMask.ts +41 -0
- package/src/hooks/useToggle.ts +32 -0
- package/src/hooks/useValidationAttributes.ts +25 -0
- package/src/index.ts +6 -0
- package/src/tokens/DATE_FORMAT.ts +4 -0
- package/src/tokens/LOCALE.ts +4 -0
- package/src/tokens/TIME_FORMAT.ts +4 -0
- package/src/tokens/index.ts +3 -0
- package/src/types/DataModel.ts +3 -0
- package/src/types/DateFormat.ts +5 -0
- package/src/types/FilterFunction.ts +1 -0
- package/src/types/FormatFunction.ts +3 -0
- package/src/types/Group.ts +6 -0
- package/src/types/GroupFunction.ts +1 -0
- package/src/types/Id.ts +1 -0
- package/src/types/Item.ts +5 -0
- package/src/types/Locale.ts +1 -0
- package/src/types/ModelValue.ts +1 -0
- package/src/types/SearchFunction.ts +1 -0
- package/src/types/TimeFormat.ts +5 -0
- package/src/types/index.ts +12 -0
- package/src/utils/constants/color.ts +14 -0
- package/src/utils/constants/key-codes.ts +14 -0
- package/src/utils/constants/poper.ts +8 -0
- package/src/utils/constants/regex.ts +57 -0
- package/src/utils/exclude.ts +6 -0
- package/src/utils/extractCssVarName.ts +5 -0
- package/src/utils/functions/color.ts +55 -0
- package/src/utils/functions/dom.ts +206 -0
- package/src/utils/functions/flattenDeep.ts +5 -0
- package/src/utils/functions/hash.ts +10 -0
- package/src/utils/functions/px-to-rem.ts +2 -0
- package/src/utils/functions/text.ts +8 -0
- package/src/utils/include.ts +6 -0
- package/src/utils/index.ts +28 -0
- package/src/utils/isAncestor.ts +16 -0
- package/src/utils/isArray.ts +6 -0
- package/src/utils/isDescendant.ts +16 -0
- package/src/utils/isEmpty.ts +24 -0
- package/src/utils/isEqual.ts +23 -0
- package/src/utils/isNil.ts +8 -0
- package/src/utils/isNull.ts +6 -0
- package/src/utils/isNumber.ts +6 -0
- package/src/utils/isObject.ts +6 -0
- package/src/utils/isString.ts +6 -0
- package/src/utils/isUndefined.ts +6 -0
- package/src/utils/isVisible.ts +3 -0
- package/src/utils/toArray.ts +16 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { refDebounced } from '@vueuse/core';
|
|
2
|
+
import { Ref, ref, watch } from 'vue';
|
|
3
|
+
|
|
4
|
+
export type UsePopoverStateEmit = (event: 'update:state' | 'open' | 'close', value?: 'open' | 'closed') => void;
|
|
5
|
+
|
|
6
|
+
export type UsePopoverStateOptions = {
|
|
7
|
+
debounce?: Ref<number>;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export type UsePopoverStateReturn = {
|
|
11
|
+
state: Readonly<Ref<'open' | 'closed'>>;
|
|
12
|
+
|
|
13
|
+
open: () => void;
|
|
14
|
+
close: () => void;
|
|
15
|
+
toggle: () => void;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// TODO: Use `defineEmits` after migration to Vue 3
|
|
19
|
+
export const usePopoverState = (
|
|
20
|
+
isOpen: Ref<boolean>,
|
|
21
|
+
emit: UsePopoverStateEmit,
|
|
22
|
+
options: UsePopoverStateOptions = {}
|
|
23
|
+
): UsePopoverStateReturn => {
|
|
24
|
+
// State
|
|
25
|
+
const state = ref<'open' | 'closed'>(isOpen.value ? 'open' : 'closed');
|
|
26
|
+
|
|
27
|
+
watch(isOpen, (value) => {
|
|
28
|
+
state.value = value ? 'open' : 'closed';
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const debouncedState = refDebounced(state, options.debounce ?? 0);
|
|
32
|
+
|
|
33
|
+
watch(debouncedState, (value) => {
|
|
34
|
+
emit('update:state', value);
|
|
35
|
+
|
|
36
|
+
switch (value) {
|
|
37
|
+
case 'open':
|
|
38
|
+
emit('open');
|
|
39
|
+
break;
|
|
40
|
+
|
|
41
|
+
case 'closed':
|
|
42
|
+
emit('close');
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// Methods
|
|
48
|
+
function open(): void {
|
|
49
|
+
state.value = 'open';
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function close(): void {
|
|
53
|
+
state.value = 'closed';
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function toggle(): void {
|
|
57
|
+
state.value = state.value === 'open' ? 'closed' : 'open';
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
state: debouncedState,
|
|
62
|
+
|
|
63
|
+
open,
|
|
64
|
+
close,
|
|
65
|
+
toggle,
|
|
66
|
+
};
|
|
67
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Ref, WritableComputedRef, computed } from 'vue';
|
|
2
|
+
|
|
3
|
+
export type UseProxyModelValueEmit<T> = (event: 'update:modelValue', value: T) => void;
|
|
4
|
+
|
|
5
|
+
export type UseProxyModelValueOptions<T> = {
|
|
6
|
+
defaultValue?: Ref<NonNullable<T>>;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export type UseProxyModelValueReturn<T> = WritableComputedRef<T>;
|
|
10
|
+
|
|
11
|
+
export function useProxyModelValue<T>(
|
|
12
|
+
modelValue: Ref<T>,
|
|
13
|
+
emit: UseProxyModelValueEmit<T>
|
|
14
|
+
): UseProxyModelValueReturn<T>;
|
|
15
|
+
|
|
16
|
+
export function useProxyModelValue<T>(
|
|
17
|
+
modelValue: Ref<T>,
|
|
18
|
+
emit: UseProxyModelValueEmit<T>,
|
|
19
|
+
options: Required<Pick<UseProxyModelValueOptions<T>, 'defaultValue'>>
|
|
20
|
+
): UseProxyModelValueReturn<NonNullable<T>>;
|
|
21
|
+
|
|
22
|
+
export function useProxyModelValue<T>(
|
|
23
|
+
modelValue: Ref<T>,
|
|
24
|
+
emit: UseProxyModelValueEmit<T>,
|
|
25
|
+
options: UseProxyModelValueOptions<T> = {}
|
|
26
|
+
): UseProxyModelValueReturn<T> {
|
|
27
|
+
const { defaultValue } = options;
|
|
28
|
+
|
|
29
|
+
if (defaultValue) {
|
|
30
|
+
return computed({
|
|
31
|
+
get: () => {
|
|
32
|
+
return modelValue.value ?? defaultValue.value;
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
set: (value) => {
|
|
36
|
+
emit('update:modelValue', value);
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return computed({
|
|
42
|
+
get: () => {
|
|
43
|
+
return modelValue.value;
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
set: (value) => {
|
|
47
|
+
emit('update:modelValue', value);
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as useResponsive } from './useResponsive';
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import screens from '@onereach/styles/screens.json';
|
|
2
|
+
import { useMediaQuery } from '@vueuse/core';
|
|
3
|
+
import { Ref, computed, getCurrentInstance, onMounted, ref, watch } from 'vue';
|
|
4
|
+
import { isVue3 } from '@/constants';
|
|
5
|
+
|
|
6
|
+
function useResponsive(element?: Ref<Element | undefined>) {
|
|
7
|
+
const currentInstance = getCurrentInstance();
|
|
8
|
+
const currentRootElement = ref<Element>();
|
|
9
|
+
|
|
10
|
+
if (element) {
|
|
11
|
+
watch(element, (value) => {
|
|
12
|
+
currentRootElement.value = value;
|
|
13
|
+
});
|
|
14
|
+
} else {
|
|
15
|
+
onMounted(() => {
|
|
16
|
+
if (currentInstance) {
|
|
17
|
+
const element = (currentInstance.vnode as any)[isVue3 ? 'el' : 'elm'] as unknown;
|
|
18
|
+
|
|
19
|
+
if (element instanceof Element) {
|
|
20
|
+
currentRootElement.value = element as Element;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// State
|
|
27
|
+
const isDesktop = computed(() => {
|
|
28
|
+
return isForcedDesktop(currentRootElement.value) || desktopQuery.value;
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const isMobile = computed(() => {
|
|
32
|
+
return !isDesktop.value;
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const desktopQuery = useMediaQuery(`(min-width: ${screens.md})`);
|
|
36
|
+
|
|
37
|
+
// Helpers
|
|
38
|
+
function isForcedDesktop(element?: Element): boolean {
|
|
39
|
+
if (!element) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const forcedScreens = element.getAttribute('force-screen')?.split(/\s+/);
|
|
44
|
+
|
|
45
|
+
if (forcedScreens?.some((forcedScreen) => ['md', 'lg', 'xl'].includes(forcedScreen))) {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return isForcedDesktop(element.parentElement ?? undefined);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
isDesktop,
|
|
54
|
+
isMobile,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export default useResponsive;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import defaultConfig from '@onereach/styles/tailwind.config.json';
|
|
2
|
+
import { Config } from 'tailwindcss';
|
|
3
|
+
|
|
4
|
+
export type UseThemeReturn = Record<keyof NonNullable<Config['theme']>, Record<string, string>>;
|
|
5
|
+
|
|
6
|
+
export const useTheme = (): UseThemeReturn => {
|
|
7
|
+
return (defaultConfig as unknown as Config).theme as UseThemeReturn;
|
|
8
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ComputedRef, Ref, computed, inject } from 'vue';
|
|
2
|
+
import { TIME_FORMAT } from '../tokens';
|
|
3
|
+
import { FormatFunction, ModelValue, TimeFormat } from '../types';
|
|
4
|
+
|
|
5
|
+
export type UseTimeFormatReturn = ComputedRef<`${TimeFormat}` | FormatFunction<ModelValue<Date>>>;
|
|
6
|
+
|
|
7
|
+
export const useTimeFormat = (
|
|
8
|
+
format: Ref<`${TimeFormat}` | FormatFunction<ModelValue<Date>> | undefined>
|
|
9
|
+
): UseTimeFormatReturn => {
|
|
10
|
+
return computed(() => {
|
|
11
|
+
return format.value ?? inject(TIME_FORMAT, TimeFormat.Auto);
|
|
12
|
+
});
|
|
13
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ComputedRef, Ref, computed } from 'vue';
|
|
2
|
+
import { FormatFunction, Locale, ModelValue, TimeFormat } from '../types';
|
|
3
|
+
|
|
4
|
+
export type UseTimeMaskReturn = ComputedRef<string>;
|
|
5
|
+
|
|
6
|
+
export const useTimeMask = (
|
|
7
|
+
format: Ref<`${TimeFormat}` | FormatFunction<ModelValue<Date>>>,
|
|
8
|
+
locale: Ref<`${Locale}`>
|
|
9
|
+
): UseTimeMaskReturn => {
|
|
10
|
+
return computed(() => {
|
|
11
|
+
if (typeof format.value !== 'function') {
|
|
12
|
+
const formatter = new Intl.DateTimeFormat(locale.value, {
|
|
13
|
+
timeStyle: 'short',
|
|
14
|
+
hourCycle: format.value !== TimeFormat.Auto ? format.value : undefined,
|
|
15
|
+
timeZone: 'UTC',
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
return formatter.formatToParts(Date.UTC(1, 0, 1, 1, 1)).reduce((mask, part) => {
|
|
19
|
+
switch (part.type) {
|
|
20
|
+
case 'hour':
|
|
21
|
+
return mask + part.value
|
|
22
|
+
.replace(/^\d{1}$/, 'H')
|
|
23
|
+
.replace(/^\d{2}$/, 'HH');
|
|
24
|
+
|
|
25
|
+
case 'minute':
|
|
26
|
+
return mask + part.value
|
|
27
|
+
.replace(/^\d{1}$/, 'M')
|
|
28
|
+
.replace(/^\d{2}$/, 'MM');
|
|
29
|
+
|
|
30
|
+
case 'dayPeriod':
|
|
31
|
+
return mask + 'A';
|
|
32
|
+
|
|
33
|
+
default:
|
|
34
|
+
return mask + part.value;
|
|
35
|
+
}
|
|
36
|
+
}, '');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return format.value(undefined, locale.value);
|
|
40
|
+
});
|
|
41
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ref, Ref } from 'vue';
|
|
2
|
+
|
|
3
|
+
export type UseToggleReturn = {
|
|
4
|
+
isActiveToggle: Ref<boolean>;
|
|
5
|
+
|
|
6
|
+
show(): void;
|
|
7
|
+
hide(): void;
|
|
8
|
+
toggle(): void;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export default function useToggle(defaultValue = false): UseToggleReturn {
|
|
12
|
+
const isActiveToggle = ref(defaultValue);
|
|
13
|
+
|
|
14
|
+
function show(): void {
|
|
15
|
+
isActiveToggle.value = true;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function hide(): void {
|
|
19
|
+
isActiveToggle.value = false;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function toggle(): void {
|
|
23
|
+
isActiveToggle.value = !isActiveToggle.value;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
isActiveToggle,
|
|
28
|
+
show,
|
|
29
|
+
hide,
|
|
30
|
+
toggle,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { computed, ComputedRef, useAttrs } from 'vue';
|
|
2
|
+
|
|
3
|
+
export type UseValidationAttributesReturn = {
|
|
4
|
+
required: ComputedRef<boolean | undefined>;
|
|
5
|
+
minlength: ComputedRef<number | undefined>;
|
|
6
|
+
maxlength: ComputedRef<number | undefined>;
|
|
7
|
+
pattern: ComputedRef<string | undefined>;
|
|
8
|
+
min: ComputedRef<number | undefined>;
|
|
9
|
+
max: ComputedRef<number | undefined>;
|
|
10
|
+
step: ComputedRef<number | undefined>;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const useValidationAttributes = (): UseValidationAttributesReturn => {
|
|
14
|
+
const attributes = useAttrs();
|
|
15
|
+
|
|
16
|
+
return {
|
|
17
|
+
required: computed(() => attributes['required'] as boolean | undefined),
|
|
18
|
+
minlength: computed(() => attributes['minlength'] as number | undefined),
|
|
19
|
+
maxlength: computed(() => attributes['maxlength'] as number | undefined),
|
|
20
|
+
pattern: computed(() => attributes['pattern'] as string | undefined),
|
|
21
|
+
min: computed(() => attributes['min'] as number | undefined),
|
|
22
|
+
max: computed(() => attributes['max'] as number | undefined),
|
|
23
|
+
step: computed(() => attributes['step'] as number | undefined),
|
|
24
|
+
};
|
|
25
|
+
};
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type FilterFunction<T> = (value: T) => boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type GroupFunction<T> = (value: T) => string;
|
package/src/types/Id.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type Id = string | number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type Locale = string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type ModelValue<T> = T | null | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type SearchFunction<T> = (value: string, items: T[]) => Promise<T[]>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from './DataModel';
|
|
2
|
+
export * from './DateFormat';
|
|
3
|
+
export * from './FilterFunction';
|
|
4
|
+
export * from './FormatFunction';
|
|
5
|
+
export * from './Group';
|
|
6
|
+
export * from './GroupFunction';
|
|
7
|
+
export * from './Id';
|
|
8
|
+
export * from './Item';
|
|
9
|
+
export * from './Locale';
|
|
10
|
+
export * from './ModelValue';
|
|
11
|
+
export * from './SearchFunction';
|
|
12
|
+
export * from './TimeFormat';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const CODE_BACKSPACE = 8;
|
|
2
|
+
export const CODE_BREAK = 19;
|
|
3
|
+
export const CODE_DELETE = 46;
|
|
4
|
+
export const CODE_DOWN = 40;
|
|
5
|
+
export const CODE_END = 35;
|
|
6
|
+
export const CODE_ENTER = 13;
|
|
7
|
+
export const CODE_ESC = 27;
|
|
8
|
+
export const CODE_HOME = 36;
|
|
9
|
+
export const CODE_LEFT = 37;
|
|
10
|
+
export const CODE_PAGEDOWN = 34;
|
|
11
|
+
export const CODE_PAGEUP = 33;
|
|
12
|
+
export const CODE_RIGHT = 39;
|
|
13
|
+
export const CODE_SPACE = 32;
|
|
14
|
+
export const CODE_UP = 38;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const PLACEMENT_TOP_START = 'top-start';
|
|
2
|
+
export const PLACEMENT_TOP_END = 'top-end';
|
|
3
|
+
export const PLACEMENT_BOTTOM_START = 'bottom-start';
|
|
4
|
+
export const PLACEMENT_BOTTOM_END = 'bottom-end';
|
|
5
|
+
export const PLACEMENT_RIGHT_START = 'right-start';
|
|
6
|
+
export const PLACEMENT_RIGHT_END = 'right-end';
|
|
7
|
+
export const PLACEMENT_LEFT_START = 'left-start';
|
|
8
|
+
export const PLACEMENT_LEFT_END = 'left-end';
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export const RX_ARRAY_NOTATION = /\[(\d+)]/g;
|
|
6
|
+
export const RX_BV_PREFIX = /^(BV?)/;
|
|
7
|
+
export const RX_DIGITS = /^\d+$/;
|
|
8
|
+
export const RX_EXTENSION = /^\..+/;
|
|
9
|
+
export const RX_HASH = /^#/;
|
|
10
|
+
export const RX_HASH_ID = /^#[A-Za-z]+[\w\-:.]*$/;
|
|
11
|
+
export const RX_HTML_TAGS = /(<([^>]+)>)/gi;
|
|
12
|
+
export const RX_HYPHENATE = /\B([A-Z])/g;
|
|
13
|
+
export const RX_LOWER_UPPER = /([a-z])([A-Z])/g;
|
|
14
|
+
export const RX_NUMBER = /^[0-9]*\.?[0-9]+$/;
|
|
15
|
+
export const RX_PLUS = /\+/g;
|
|
16
|
+
export const RX_REGEXP_REPLACE = /[-/\\^$*+?.()|[\]{}]/g;
|
|
17
|
+
export const RX_SPACES = /[\s\uFEFF\xA0]+/g;
|
|
18
|
+
export const RX_SPACE_SPLIT = /\s+/;
|
|
19
|
+
export const RX_STAR = /\/\*$/;
|
|
20
|
+
export const RX_START_SPACE_WORD = /(\s|^)(\w)/g;
|
|
21
|
+
export const RX_TRIM_LEFT = /^\s+/;
|
|
22
|
+
export const RX_TRIM_RIGHT = /\s+$/;
|
|
23
|
+
export const RX_UNDERSCORE = /_/g;
|
|
24
|
+
export const RX_UN_KEBAB = /-(\w)/g;
|
|
25
|
+
export const RX_ABBREVIATION_FROM_STRING = /[\p{Alpha}\p{Nd}]+/gu;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Date
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
// Loose YYYY-MM-DD matching, ignores any appended time inforation
|
|
32
|
+
// Matches '1999-12-20', '1999-1-1', '1999-01-20T22:51:49.118Z', '1999-01-02 13:00:00'
|
|
33
|
+
export const RX_DATE = /^\d+-\d\d?-\d\d?(?:\s|T|$)/;
|
|
34
|
+
|
|
35
|
+
// Used to split off the date parts of the YYYY-MM-DD string
|
|
36
|
+
export const RX_DATE_SPLIT = /-|\s|T/;
|
|
37
|
+
|
|
38
|
+
// Time string RegEx (optional seconds)
|
|
39
|
+
export const RX_TIME = /^([0-1]?[0-9]|2[0-3]):[0-5]?[0-9](:[0-5]?[0-9])?$/;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* URL
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
// HREFs must end with a hash followed by at least one non-hash character
|
|
46
|
+
export const RX_HREF = /^.*(#[^#]+)$/;
|
|
47
|
+
|
|
48
|
+
export const RX_ENCODED_COMMA = /%2C/g;
|
|
49
|
+
export const RX_ENCODE_REVERSE = /[!'()*]/g;
|
|
50
|
+
export const RX_QUERY_START = /^(\?|#|&)/;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Color
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
export const RX_SHORT_COLOR = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
|
|
57
|
+
export const RX_LONG_COLOR = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { RX_SHORT_COLOR, RX_LONG_COLOR } from '../constants/regex';
|
|
2
|
+
import { getHashOfString, normalize } from './hash';
|
|
3
|
+
import { HSL_LIMITS } from '../constants/color';
|
|
4
|
+
|
|
5
|
+
export function hexToRgb(hex: string) {
|
|
6
|
+
hex = hex.replace(RX_SHORT_COLOR, (m, r, g, b) => r + r + g + g + b + b);
|
|
7
|
+
|
|
8
|
+
const result = RX_LONG_COLOR.exec(hex);
|
|
9
|
+
return result ? {
|
|
10
|
+
r: parseInt(result[1], 16),
|
|
11
|
+
g: parseInt(result[2], 16),
|
|
12
|
+
b: parseInt(result[3], 16),
|
|
13
|
+
} : null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function componentToHex(c: number) {
|
|
17
|
+
const hex = c.toString(16);
|
|
18
|
+
return hex.length == 1 ? '0' + hex : hex;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function rgbToHex(r: number, g: number, b: number) {
|
|
22
|
+
return '#' + componentToHex(r) + componentToHex(g) + componentToHex(b);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function generateHslFromString(
|
|
26
|
+
str: string,
|
|
27
|
+
limits: Partial<Record<'h'|'s'|'l', { min: number; max: number; }>> = HSL_LIMITS,
|
|
28
|
+
) {
|
|
29
|
+
const hRange = (limits?.h ? [limits.h.min, limits.h.max] : [0, 360]) as [number, number];
|
|
30
|
+
const sRange = (limits?.s ? [limits.s.min, limits.s.max] : [0, 100]) as [number, number];
|
|
31
|
+
const lRange = (limits?.l ? [limits.l.min, limits.l.max] : [0, 100]) as [number, number];
|
|
32
|
+
|
|
33
|
+
const hash = getHashOfString(str);
|
|
34
|
+
|
|
35
|
+
const h = normalize(hash, ...hRange);
|
|
36
|
+
const s = normalize(hash, ...sRange);
|
|
37
|
+
const l = normalize(hash, ...lRange);
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
h,
|
|
41
|
+
s,
|
|
42
|
+
l,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function hslToColorString(hsl: { h: number; s: number; l: number; }): string {
|
|
47
|
+
return `hsl(${hsl.h}, ${hsl.s}%, ${hsl.l}%)`;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function generateColorFromString(
|
|
51
|
+
str: string,
|
|
52
|
+
limits: Partial<Record<'h'|'s'|'l', { min: number; max: number; }>> = HSL_LIMITS,
|
|
53
|
+
): string {
|
|
54
|
+
return hslToColorString(generateHslFromString(str, limits));
|
|
55
|
+
}
|