@teammodlr/ui-kit 2.1.45 → 2.1.47

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.
@@ -1,21 +1,26 @@
1
- <template>
2
- <MSelect
3
- v-model="value"
4
- :options="options"
5
- :option-value="'id'"
6
- :option-label="'name'"
7
- blank
8
- />
9
- </template>
10
-
11
- <script lang="ts" setup>
12
- import { ref } from "vue";
13
-
14
- // make list of options with 1000 items
15
- const options = Array.from({ length: 50 }, (_, i) => ({
16
- id: i,
17
- name: `Option ${i+1}`
18
- }));
19
-
20
- const value = ref();
21
- </script>
1
+ <template>
2
+ <MSelect
3
+ v-model="value"
4
+ :options="options"
5
+ :option-value="'id'"
6
+ :option-label="'name'"
7
+ blank
8
+ @update:value="testThis"
9
+ />
10
+ </template>
11
+
12
+ <script lang="ts" setup>
13
+ import { ref } from "vue";
14
+
15
+ // make list of options with 1000 items
16
+ const options = Array.from({ length: 50 }, (_, i) => ({
17
+ id: i,
18
+ name: `Option ${i+1}`
19
+ }));
20
+
21
+ const value = ref();
22
+
23
+ function testThis(value: any, option: any) {
24
+ alert('value: ' + value);
25
+ }
26
+ </script>
@@ -0,0 +1,27 @@
1
+ export type ValueAtom = string | number
2
+ export type Value = ValueAtom | string[] | number[] | ValueAtom[]
3
+ export type OnUpdateValue = (
4
+ value: string &
5
+ number &
6
+ ValueAtom &
7
+ string[] &
8
+ number[] &
9
+ ValueAtom[] &
10
+ (ValueAtom | null) &
11
+ (string[] | null) &
12
+ (number[] | null) &
13
+ (ValueAtom[] | null),
14
+ option: object & null
15
+ ) => void
16
+ export type OnUpdateValueImpl = (
17
+ value:
18
+ | ValueAtom
19
+ | string[]
20
+ | number[]
21
+ | ValueAtom[]
22
+ | (ValueAtom | null)
23
+ | (string[] | null)
24
+ | (number[] | null)
25
+ | (ValueAtom[] | null),
26
+ option: object | null
27
+ ) => void
@@ -1,4 +1,4 @@
1
- import {inject} from 'vue';
1
+ import { injectConfigProviderContext } from '../components/configprovider/ConfigProvider.vue';
2
2
 
3
3
  let count = 0
4
4
 
@@ -6,7 +6,7 @@ export function useId(deterministicId?: string | null | undefined, prefix = 'ui'
6
6
  if (deterministicId) {
7
7
  return deterministicId;
8
8
  }
9
- const {useId} = inject('m-config', {useId: undefined});
9
+ const { useId } = injectConfigProviderContext({ useId: undefined })
10
10
  if (useId && typeof useId === 'function') {
11
11
  // @ts-ignore
12
12
  return `${prefix}-${useId()}`;
@@ -1,151 +1,151 @@
1
- // inspired by indielayer ui
2
- import type { PropType } from 'vue';
3
- import { ref, watch, inject, computed, onMounted, onUnmounted } from 'vue';
4
- import { useId } from './useCachedUid';
5
- import { FORM_STATE } from '../components/form/symbol';
6
-
7
- export interface FormInput {
8
- focus: () => void;
9
- validate: (value: any) => void;
10
- setError: (value: string) => void;
11
- }
12
-
13
- export const useInput = (
14
- props: any,
15
- {
16
- focus,
17
- emit,
18
- withListeners = true
19
- }: {
20
- focus: () => void;
21
- emit: any;
22
- withListeners?: boolean;
23
- }
24
- ) => {
25
- const isFirstValidation = ref(true);
26
- const formError = ref(props.error);
27
-
28
- const id = useId(null, 'input');
29
- const name = props.name ? props.name : id;
30
- const _name = ref(name);
31
-
32
- watch(
33
- () => props.error,
34
- value => (formError.value = value)
35
- );
36
- watch(
37
- () => props.name,
38
- value => (name.value = value)
39
- );
40
-
41
- const form = inject(FORM_STATE, null);
42
-
43
- const reset = () => {
44
- formError.value = '';
45
- isFirstValidation.value = true;
46
- emit('update:modelValue', '');
47
- };
48
-
49
- const setError = (value: string) => {
50
- formError.value = value;
51
- };
52
-
53
- const validate = (value: any): boolean => {
54
- value = value || props.modelValue;
55
-
56
- isFirstValidation.value = false;
57
-
58
- for (let i = 0; i < props.rules.length; i++) {
59
- const item = props.rules[i];
60
-
61
- let valid = true;
62
-
63
- if (typeof item === 'function') {
64
- valid = item(value);
65
- } else if (Array.isArray(item) && item.length === 2) {
66
- const { 0: rule, 1: options } = item;
67
- valid = rule(value, options);
68
- } else {
69
- const rule = item.fn;
70
- const { options } = item;
71
-
72
- valid = rule(value, options);
73
- }
74
-
75
- if (valid !== true) {
76
- formError.value = valid;
77
- return false;
78
- }
79
- }
80
-
81
- formError.value = '';
82
- return true;
83
- };
84
-
85
- const inputListeners = withListeners
86
- ? computed(() => {
87
- return {
88
- blur: (event: Event) => emit('blur', event),
89
- focus: (event: Event) => emit('focus', event),
90
- input: (event: Event) => {
91
- emit(
92
- 'update:modelValue',
93
- (event.target as HTMLInputElement).value
94
- );
95
- },
96
- change: (event: Event) => emit('change', event)
97
- };
98
- })
99
- : {};
100
-
101
- onMounted(() => {
102
- form?.add(
103
- _name.value,
104
- focus,
105
- // @ts-ignore
106
- validate,
107
- // @ts-ignore
108
- setError
109
- );
110
- });
111
-
112
- onUnmounted(() => {
113
- form?.remove(_name.value);
114
- });
115
-
116
- return {
117
- id,
118
- isFirstValidation,
119
- formError,
120
- insideForm: form?.insideForm ?? false,
121
- inputListeners,
122
- reset,
123
- validate,
124
- setError,
125
- //@ts-ignore
126
- formDisabled: form?.disabled.value || false,
127
- //@ts-ignore
128
- formLoading: form?.loading.value || false
129
- };
130
- };
131
-
132
- useInput.emits = (withListeners = true): string[] => {
133
- return withListeners
134
- ? ['update:modelValue', 'blur', 'focus', 'input', 'change']
135
- : ['update:modelValue'];
136
- };
137
-
138
- useInput.props = () =>
139
- ({
140
- modelValue: [String, Number, Boolean, Object, Array] as PropType<
141
- string | number | boolean | object | any[] | any[] | undefined
142
- >,
143
- name: String,
144
- readonly: Boolean,
145
- required: Boolean,
146
- error: String,
147
- rules: {
148
- type: Array,
149
- default: () => []
150
- }
151
- }) as const;
1
+ // inspired by indielayer ui
2
+ import type { PropType } from 'vue';
3
+ import { ref, watch, inject, computed, onMounted, onUnmounted } from 'vue';
4
+ import { useId } from './useCachedUid';
5
+ import { FORM_STATE } from '../components/form/symbol';
6
+
7
+ export interface FormInput {
8
+ focus: () => void;
9
+ validate: (value: any) => void;
10
+ setError: (value: string) => void;
11
+ }
12
+
13
+ export const useInput = (
14
+ props: any,
15
+ {
16
+ focus,
17
+ emit,
18
+ withListeners = true
19
+ }: {
20
+ focus: () => void;
21
+ emit: any;
22
+ withListeners?: boolean;
23
+ }
24
+ ) => {
25
+ const isFirstValidation = ref(true);
26
+ const formError = ref(props.error);
27
+
28
+ const id = useId(null, 'input');
29
+ const name = props.name ? props.name : id;
30
+ const _name = ref(name);
31
+
32
+ watch(
33
+ () => props.error,
34
+ value => (formError.value = value)
35
+ );
36
+ watch(
37
+ () => props.name,
38
+ value => (name.value = value)
39
+ );
40
+
41
+ const form = inject(FORM_STATE, null);
42
+
43
+ const reset = () => {
44
+ formError.value = '';
45
+ isFirstValidation.value = true;
46
+ emit('update:modelValue', '');
47
+ };
48
+
49
+ const setError = (value: string) => {
50
+ formError.value = value;
51
+ };
52
+
53
+ const validate = (value: any): boolean => {
54
+ value = value || props.modelValue;
55
+
56
+ isFirstValidation.value = false;
57
+
58
+ for (let i = 0; i < props.rules.length; i++) {
59
+ const item = props.rules[i];
60
+
61
+ let valid = true;
62
+
63
+ if (typeof item === 'function') {
64
+ valid = item(value);
65
+ } else if (Array.isArray(item) && item.length === 2) {
66
+ const { 0: rule, 1: options } = item;
67
+ valid = rule(value, options);
68
+ } else {
69
+ const rule = item.fn;
70
+ const { options } = item;
71
+
72
+ valid = rule(value, options);
73
+ }
74
+
75
+ if (valid !== true) {
76
+ formError.value = valid;
77
+ return false;
78
+ }
79
+ }
80
+
81
+ formError.value = '';
82
+ return true;
83
+ };
84
+
85
+ const inputListeners = withListeners
86
+ ? computed(() => {
87
+ return {
88
+ blur: (event: Event) => emit('blur', event),
89
+ focus: (event: Event) => emit('focus', event),
90
+ input: (event: Event) => {
91
+ emit(
92
+ 'update:modelValue',
93
+ (event.target as HTMLInputElement).value
94
+ );
95
+ },
96
+ change: (event: Event) => emit('change', event)
97
+ };
98
+ })
99
+ : {};
100
+
101
+ onMounted(() => {
102
+ form?.add(
103
+ _name.value,
104
+ focus,
105
+ // @ts-ignore
106
+ validate,
107
+ // @ts-ignore
108
+ setError
109
+ );
110
+ });
111
+
112
+ onUnmounted(() => {
113
+ form?.remove(_name.value);
114
+ });
115
+
116
+ return {
117
+ id,
118
+ isFirstValidation,
119
+ formError,
120
+ insideForm: form?.insideForm ?? false,
121
+ inputListeners,
122
+ reset,
123
+ validate,
124
+ setError,
125
+ //@ts-ignore
126
+ formDisabled: form?.disabled.value || false,
127
+ //@ts-ignore
128
+ formLoading: form?.loading.value || false
129
+ };
130
+ };
131
+
132
+ useInput.emits = (withListeners = true): string[] => {
133
+ return withListeners
134
+ ? ['update:modelValue', 'blur', 'focus', 'input', 'change']
135
+ : ['update:modelValue'];
136
+ };
137
+
138
+ useInput.props = () =>
139
+ ({
140
+ modelValue: [String, Number, Boolean, Object, Array] as PropType<
141
+ string | number | boolean | object | any[] | any[] | undefined
142
+ >,
143
+ name: String,
144
+ readonly: Boolean,
145
+ required: Boolean,
146
+ error: String,
147
+ rules: {
148
+ type: Array,
149
+ default: () => []
150
+ }
151
+ }) as const;
@@ -1,19 +1,21 @@
1
- export type Size = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
2
-
3
- export type Color =
4
- | 'white'
5
- | 'black'
6
- | 'blue'
7
- | 'green'
8
- | 'red'
9
- | 'yellow'
10
- | 'gray';
11
-
12
- export type Variant =
13
- | 'default'
14
- | 'tertiary'
15
- | 'primary'
16
- | 'dark'
17
- | 'success'
18
- | 'warning'
19
- | 'error';
1
+ export type Size = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
2
+
3
+ export type Color =
4
+ | 'white'
5
+ | 'black'
6
+ | 'blue'
7
+ | 'green'
8
+ | 'red'
9
+ | 'yellow'
10
+ | 'gray';
11
+
12
+ export type Variant =
13
+ | 'default'
14
+ | 'tertiary'
15
+ | 'primary'
16
+ | 'dark'
17
+ | 'success'
18
+ | 'warning'
19
+ | 'error';
20
+
21
+ export type MaybeArray<T> = T | T[];
@@ -0,0 +1,34 @@
1
+ type AnyFunction = (...args: any[]) => any
2
+
3
+ function call(funcs: MaybeArray<() => void>): void
4
+ function call<A1>(funcs: MaybeArray<(a1: A1) => void>, a1: A1): void
5
+ function call<A1, A2>(
6
+ funcs: MaybeArray<(a1: A1, a2: A2) => void>,
7
+ a1: A1,
8
+ a2: A2
9
+ ): void
10
+ function call<A1, A2, A3>(
11
+ funcs: MaybeArray<(a1: A1, a2: A2, a3: A3) => void>,
12
+ a1: A1,
13
+ a2: A2,
14
+ a3: A3
15
+ ): void
16
+ function call<A1, A2, A3, A4>(
17
+ funcs: MaybeArray<(a1: A1, a2: A2, a3: A3, a4: A4) => void>,
18
+ a1: A1,
19
+ a2: A2,
20
+ a3: A3,
21
+ a4: A4
22
+ ): void
23
+ function call<A extends any[]>(
24
+ funcs: AnyFunction[] | AnyFunction,
25
+ ...args: A
26
+ ): void {
27
+ if (Array.isArray(funcs)) {
28
+ funcs.forEach((func) => (call as any)(func, ...args))
29
+ } else return funcs(...args)
30
+ }
31
+
32
+ export { call }
33
+
34
+ export type MaybeArray<T> = T | T[]
@@ -1,5 +1,49 @@
1
- import type { InjectionKey } from 'vue';
1
+ import { type InjectionKey, inject, provide } from 'vue';
2
2
 
3
3
  export function createInjectionKey<T>(key: string): InjectionKey<T> {
4
4
  return key as any;
5
5
  }
6
+
7
+ export function createContext<ContextValue>(
8
+ providerComponentName: string | string[],
9
+ contextName?: string
10
+ ) {
11
+ const symbolDescription
12
+ = typeof providerComponentName === 'string' && !contextName
13
+ ? `${providerComponentName}Context`
14
+ : contextName
15
+
16
+ const injectionKey: InjectionKey<ContextValue | null> = Symbol(symbolDescription);
17
+
18
+ const injectContext = <
19
+ T extends ContextValue | null | undefined = ContextValue,
20
+ >(
21
+ fallback?: T,
22
+ ): T extends null ? ContextValue | null : ContextValue => {
23
+ const context = inject(injectionKey, fallback);
24
+ if (context) {
25
+ return context;
26
+ }
27
+
28
+ if (context === null) {
29
+ return context as any;
30
+ }
31
+
32
+ throw new Error(
33
+ `Injection \`${injectionKey.toString()}\` not found. Component must be used within ${
34
+ Array.isArray(providerComponentName)
35
+ ? `one of the following components: ${providerComponentName.join(
36
+ ', ',
37
+ )}`
38
+ : `\`${providerComponentName}\``
39
+ }`,
40
+ )
41
+ }
42
+
43
+ const provideContext = (contextValue: ContextValue) => {
44
+ provide(injectionKey, contextValue);
45
+ return contextValue;
46
+ }
47
+
48
+ return [injectContext, provideContext] as const;
49
+ }