@teammodlr/ui-kit 2.1.46 → 2.1.49
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/lib/components/configprovider/ConfigProvider.vue.d.ts +10 -0
- package/lib/index.cjs.js +10 -10
- package/lib/index.es.js +1499 -1483
- package/lib/utils/injection.d.ts +2 -1
- package/package.json +1 -1
- package/src/components/configprovider/ConfigProvider.vue +38 -26
- package/src/components/confirm/ConfirmProvider.vue +82 -83
- package/src/composables/useCachedUid.ts +2 -3
- package/src/utils/injection.ts +45 -5
package/lib/utils/injection.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type InjectionKey } from 'vue';
|
|
2
2
|
export declare function createInjectionKey<T>(key: string): InjectionKey<T>;
|
|
3
|
+
export declare function createContext<ContextValue>(providerComponentName: string | string[], contextName?: string): readonly [<T extends ContextValue | null | undefined = ContextValue>(fallback?: T) => T extends null ? ContextValue | null : ContextValue, (contextValue: ContextValue) => ContextValue];
|
package/package.json
CHANGED
|
@@ -1,26 +1,38 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
<
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
<
|
|
25
|
-
|
|
26
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { createContext } from "../../utils/injection";
|
|
3
|
+
import { type Ref, toRefs } from 'vue';
|
|
4
|
+
interface ConfigProviderContextValue {
|
|
5
|
+
useId?: () => string,
|
|
6
|
+
dir?: Ref<string>
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const [injectConfigProviderContext, provideConfigProviderContext]
|
|
10
|
+
= createContext<ConfigProviderContextValue>('ConfigProvider')
|
|
11
|
+
|
|
12
|
+
export interface ConfigProviderProps {
|
|
13
|
+
useId?: () => string,
|
|
14
|
+
dir?: string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default {
|
|
18
|
+
name: 'ConfigProvider',
|
|
19
|
+
}
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
<script setup lang="ts">
|
|
23
|
+
|
|
24
|
+
const props = withDefaults(defineProps<ConfigProviderProps>(), {
|
|
25
|
+
useId: undefined,
|
|
26
|
+
dir: 'ltr'
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
const { dir } = toRefs(props)
|
|
30
|
+
|
|
31
|
+
provideConfigProviderContext({
|
|
32
|
+
useId: props.useId,
|
|
33
|
+
dir
|
|
34
|
+
})
|
|
35
|
+
</script>
|
|
36
|
+
<template>
|
|
37
|
+
<slot />
|
|
38
|
+
</template>
|
|
@@ -1,83 +1,82 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<slot />
|
|
3
|
-
<template v-if="dialogList.length > 0">
|
|
4
|
-
<Teleport :to="teleportTo ?? 'body'">
|
|
5
|
-
<MConfirm
|
|
6
|
-
v-for="dialog in dialogList"
|
|
7
|
-
:key="dialog.key"
|
|
8
|
-
:internalKey="dialog.key"
|
|
9
|
-
:title="dialog.title"
|
|
10
|
-
:content="dialog.content"
|
|
11
|
-
:okText="dialog.okText"
|
|
12
|
-
:cancelText="dialog.cancelText"
|
|
13
|
-
:on-ok="dialog.onOk"
|
|
14
|
-
:on-cancel="dialog.onCancel"
|
|
15
|
-
:ok-variant="dialog.okVariant"
|
|
16
|
-
ref="dialogRefs" />
|
|
17
|
-
</Teleport>
|
|
18
|
-
</template>
|
|
19
|
-
</template>
|
|
20
|
-
|
|
21
|
-
<script lang="ts">
|
|
22
|
-
import { defineComponent, provide, ref } from 'vue';
|
|
23
|
-
import { useId } from '../../composables/useCachedUid';
|
|
24
|
-
import { providerProps } from './providerProps';
|
|
25
|
-
import type { Confirm, ConfirmApiInjection, ConfirmOptions } from './types';
|
|
26
|
-
import MConfirm from './Confirm.vue';
|
|
27
|
-
|
|
28
|
-
interface PrivateConfirm extends Confirm {
|
|
29
|
-
key: string;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
interface PrivateConfirmRef extends Confirm {
|
|
33
|
-
key: string;
|
|
34
|
-
hide: () => void;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export default defineComponent({
|
|
38
|
-
name: 'ConfirmProvider',
|
|
39
|
-
props: providerProps,
|
|
40
|
-
components: {
|
|
41
|
-
MConfirm
|
|
42
|
-
},
|
|
43
|
-
setup(props, { slots }) {
|
|
44
|
-
const dialogListRef = ref<PrivateConfirm[]>([]);
|
|
45
|
-
const dialogRefs: Record<string, PrivateConfirmRef> = {};
|
|
46
|
-
|
|
47
|
-
function create(options: ConfirmOptions): Confirm {
|
|
48
|
-
const
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
</script>
|
|
1
|
+
<template>
|
|
2
|
+
<slot />
|
|
3
|
+
<template v-if="dialogList.length > 0">
|
|
4
|
+
<Teleport :to="teleportTo ?? 'body'">
|
|
5
|
+
<MConfirm
|
|
6
|
+
v-for="dialog in dialogList"
|
|
7
|
+
:key="dialog.key"
|
|
8
|
+
:internalKey="dialog.key"
|
|
9
|
+
:title="dialog.title"
|
|
10
|
+
:content="dialog.content"
|
|
11
|
+
:okText="dialog.okText"
|
|
12
|
+
:cancelText="dialog.cancelText"
|
|
13
|
+
:on-ok="dialog.onOk"
|
|
14
|
+
:on-cancel="dialog.onCancel"
|
|
15
|
+
:ok-variant="dialog.okVariant"
|
|
16
|
+
ref="dialogRefs" />
|
|
17
|
+
</Teleport>
|
|
18
|
+
</template>
|
|
19
|
+
</template>
|
|
20
|
+
|
|
21
|
+
<script lang="ts">
|
|
22
|
+
import { defineComponent, provide, ref } from 'vue';
|
|
23
|
+
import { useId } from '../../composables/useCachedUid';
|
|
24
|
+
import { providerProps } from './providerProps';
|
|
25
|
+
import type { Confirm, ConfirmApiInjection, ConfirmOptions } from './types';
|
|
26
|
+
import MConfirm from './Confirm.vue';
|
|
27
|
+
|
|
28
|
+
interface PrivateConfirm extends Confirm {
|
|
29
|
+
key: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface PrivateConfirmRef extends Confirm {
|
|
33
|
+
key: string;
|
|
34
|
+
hide: () => void;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export default defineComponent({
|
|
38
|
+
name: 'ConfirmProvider',
|
|
39
|
+
props: providerProps,
|
|
40
|
+
components: {
|
|
41
|
+
MConfirm
|
|
42
|
+
},
|
|
43
|
+
setup(props, { slots }) {
|
|
44
|
+
const dialogListRef = ref<PrivateConfirm[]>([]);
|
|
45
|
+
const dialogRefs: Record<string, PrivateConfirmRef> = {};
|
|
46
|
+
const id = useId(null, 'm-confirm');
|
|
47
|
+
function create(options: ConfirmOptions): Confirm {
|
|
48
|
+
const key = id;
|
|
49
|
+
const dialog: PrivateConfirm = {
|
|
50
|
+
...options,
|
|
51
|
+
key,
|
|
52
|
+
destroy: () => {
|
|
53
|
+
dialogRefs[key].hide();
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
dialogListRef.value.push(dialog);
|
|
58
|
+
return dialog;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function destroyAll(): void {
|
|
62
|
+
// @ts-ignore
|
|
63
|
+
Object.values(dialogRefs.value).forEach(dialog => {
|
|
64
|
+
dialog.hide();
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const api: ConfirmApiInjection = {
|
|
69
|
+
create,
|
|
70
|
+
destroyAll
|
|
71
|
+
} as const;
|
|
72
|
+
|
|
73
|
+
provide('m-confirm', api);
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
...api,
|
|
77
|
+
dialogRefs,
|
|
78
|
+
dialogList: dialogListRef
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
</script>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { injectConfigProviderContext } from '../components/configprovider/ConfigProvider.vue';
|
|
2
2
|
|
|
3
3
|
let count = 0
|
|
4
4
|
|
|
@@ -6,9 +6,8 @@ export function useId(deterministicId?: string | null | undefined, prefix = 'ui'
|
|
|
6
6
|
if (deterministicId) {
|
|
7
7
|
return deterministicId;
|
|
8
8
|
}
|
|
9
|
-
const {useId} =
|
|
9
|
+
const { useId } = injectConfigProviderContext({ useId: undefined })
|
|
10
10
|
if (useId && typeof useId === 'function') {
|
|
11
|
-
// @ts-ignore
|
|
12
11
|
return `${prefix}-${useId()}`;
|
|
13
12
|
}
|
|
14
13
|
|
package/src/utils/injection.ts
CHANGED
|
@@ -1,5 +1,45 @@
|
|
|
1
|
-
import type
|
|
2
|
-
|
|
3
|
-
export function createInjectionKey<T>(key: string): InjectionKey<T> {
|
|
4
|
-
return key as any;
|
|
5
|
-
}
|
|
1
|
+
import { type InjectionKey, inject, provide } from 'vue';
|
|
2
|
+
|
|
3
|
+
export function createInjectionKey<T>(key: string): InjectionKey<T> {
|
|
4
|
+
return key as any;
|
|
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
|
+
const injectContext = <
|
|
18
|
+
T extends ContextValue | null | undefined = ContextValue,
|
|
19
|
+
>(
|
|
20
|
+
fallback?: T,
|
|
21
|
+
): T extends null ? ContextValue | null : ContextValue => {
|
|
22
|
+
const context = inject(injectionKey, fallback)
|
|
23
|
+
if (context)
|
|
24
|
+
return context
|
|
25
|
+
|
|
26
|
+
if (context === null)
|
|
27
|
+
return context as any
|
|
28
|
+
|
|
29
|
+
throw new Error(
|
|
30
|
+
`Injection \`${injectionKey.toString()}\` not found. Component must be used within ${Array.isArray(providerComponentName)
|
|
31
|
+
? `one of the following components: ${providerComponentName.join(
|
|
32
|
+
', ',
|
|
33
|
+
)}`
|
|
34
|
+
: `\`${providerComponentName}\``
|
|
35
|
+
}`,
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const provideContext = (contextValue: ContextValue) => {
|
|
40
|
+
provide(injectionKey, contextValue)
|
|
41
|
+
return contextValue
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return [injectContext, provideContext] as const
|
|
45
|
+
}
|