vueless 0.0.531 → 0.0.532
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/package.json +1 -1
- package/types.ts +6 -0
- package/ui.container-group/types.ts +0 -1
- package/ui.loader/ULoader.vue +21 -41
- package/ui.loader/storybook/Docs.mdx +2 -2
- package/ui.loader/storybook/{stories.js → stories.ts} +15 -7
- package/ui.loader/types.ts +47 -0
- package/ui.loader/{useAttrs.js → useAttrs.ts} +6 -3
- package/ui.loader-overlay/ULoaderOverlay.vue +23 -35
- package/ui.loader-overlay/storybook/Docs.mdx +2 -2
- package/ui.loader-overlay/storybook/{stories.js → stories.ts} +22 -7
- package/ui.loader-overlay/types.ts +42 -0
- package/ui.loader-overlay/{useAttrs.js → useAttrs.ts} +5 -2
- package/ui.loader-overlay/useLoaderOverlay.ts +42 -0
- package/ui.loader-overlay/{utilLoaderOverlay.js → utilLoaderOverlay.ts} +2 -2
- package/ui.loader-progress/ULoaderProgress.vue +34 -49
- package/ui.loader-progress/{config.js → config.ts} +1 -0
- package/ui.loader-progress/storybook/Docs.mdx +2 -2
- package/ui.loader-progress/storybook/{stories.js → stories.ts} +24 -7
- package/ui.loader-progress/types.ts +46 -0
- package/ui.loader-progress/useAttrs.ts +36 -0
- package/ui.loader-progress/useLoaderProgress.ts +81 -0
- package/ui.loader-progress/utilLoaderProgress.ts +49 -0
- package/web-types.json +55 -8
- package/ui.loader-overlay/useLoaderOverlay.js +0 -25
- package/ui.loader-progress/useAttrs.js +0 -15
- package/ui.loader-progress/useLoaderProgress.js +0 -65
- package/ui.loader-progress/utilLoaderProgress.js +0 -49
- /package/ui.loader/{config.js → config.ts} +0 -0
- /package/ui.loader/{constants.js → constants.ts} +0 -0
- /package/ui.loader-overlay/{config.js → config.ts} +0 -0
- /package/ui.loader-overlay/{constants.js → constants.ts} +0 -0
- /package/ui.loader-progress/{constants.js → constants.ts} +0 -0
package/package.json
CHANGED
package/types.ts
CHANGED
|
@@ -32,6 +32,9 @@ import UModalConfig from "./ui.container-modal/config.ts";
|
|
|
32
32
|
import UModalConfirmConfig from "./ui.container-modal-confirm/config.ts";
|
|
33
33
|
import UPageConfig from "./ui.container-page/config.ts";
|
|
34
34
|
import URowConfig from "./ui.container-row/config.ts";
|
|
35
|
+
import ULoaderConfig from "./ui.loader/config.ts";
|
|
36
|
+
import ULoaderOverlayConfig from "./ui.loader-overlay/config.ts";
|
|
37
|
+
import ULoaderProgressConfig from "./ui.loader-progress/config.ts";
|
|
35
38
|
|
|
36
39
|
import type { ComputedRef, MaybeRef, Ref } from "vue";
|
|
37
40
|
import type { Props } from "tippy.js";
|
|
@@ -175,6 +178,9 @@ export interface Components {
|
|
|
175
178
|
UModalConfirm?: Partial<typeof UModalConfirmConfig>;
|
|
176
179
|
UPage?: Partial<typeof UPageConfig>;
|
|
177
180
|
URow?: Partial<typeof URowConfig>;
|
|
181
|
+
ULoader?: Partial<typeof ULoaderConfig>;
|
|
182
|
+
ULoaderOverlay?: Partial<typeof ULoaderOverlayConfig>;
|
|
183
|
+
ULoaderProgress?: Partial<typeof ULoaderProgressConfig>;
|
|
178
184
|
}
|
|
179
185
|
|
|
180
186
|
export interface Directives {
|
package/ui.loader/ULoader.vue
CHANGED
|
@@ -1,54 +1,34 @@
|
|
|
1
|
-
<
|
|
2
|
-
<Transition v-bind="config.transition">
|
|
3
|
-
<div v-if="loading" v-bind="loaderAttrs">
|
|
4
|
-
<!-- @slot Use it to add something instead of the default loader. -->
|
|
5
|
-
<slot>
|
|
6
|
-
<div v-for="ellipse in ELLIPSES_AMOUNT" :key="ellipse" v-bind="ellipseAttrs" />
|
|
7
|
-
</slot>
|
|
8
|
-
</div>
|
|
9
|
-
</Transition>
|
|
10
|
-
</template>
|
|
11
|
-
|
|
12
|
-
<script setup>
|
|
1
|
+
<script lang="ts" setup>
|
|
13
2
|
import { getDefault } from "../utils/ui.ts";
|
|
14
3
|
|
|
15
|
-
import { ULoader, ELLIPSES_AMOUNT } from "./constants.
|
|
16
|
-
import defaultConfig from "./config.
|
|
17
|
-
import useAttrs from "./useAttrs.
|
|
4
|
+
import { ULoader, ELLIPSES_AMOUNT } from "./constants.ts";
|
|
5
|
+
import defaultConfig from "./config.ts";
|
|
6
|
+
import useAttrs from "./useAttrs.ts";
|
|
7
|
+
|
|
8
|
+
import type { ULoaderProps } from "./types.ts";
|
|
18
9
|
|
|
19
10
|
defineOptions({ inheritAttrs: false });
|
|
20
11
|
|
|
21
|
-
const props = defineProps({
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
loading: {
|
|
26
|
-
type: Boolean,
|
|
27
|
-
default: getDefault(defaultConfig, ULoader).loading,
|
|
28
|
-
},
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Loader color.
|
|
32
|
-
* @values brand, grayscale, gray, red, orange, amber, yellow, lime, green, emerald, teal, cyan, sky, blue, indigo, violet, purple, fuchsia, pink, rose, black, white
|
|
33
|
-
*/
|
|
34
|
-
color: {
|
|
35
|
-
type: String,
|
|
36
|
-
default: getDefault(defaultConfig, ULoader).color,
|
|
37
|
-
},
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Loader size.
|
|
41
|
-
* @values sm, md, lg
|
|
42
|
-
*/
|
|
43
|
-
size: {
|
|
44
|
-
type: String,
|
|
45
|
-
default: getDefault(defaultConfig, ULoader).size,
|
|
46
|
-
},
|
|
12
|
+
const props = withDefaults(defineProps<ULoaderProps>(), {
|
|
13
|
+
loading: getDefault<ULoaderProps>(defaultConfig, ULoader).loading,
|
|
14
|
+
color: getDefault<ULoaderProps>(defaultConfig, ULoader).color,
|
|
15
|
+
size: getDefault<ULoaderProps>(defaultConfig, ULoader).size,
|
|
47
16
|
});
|
|
48
17
|
|
|
49
18
|
const { loaderAttrs, ellipseAttrs, config } = useAttrs(props);
|
|
50
19
|
</script>
|
|
51
20
|
|
|
21
|
+
<template>
|
|
22
|
+
<Transition v-bind="config?.transition">
|
|
23
|
+
<div v-if="loading" v-bind="loaderAttrs">
|
|
24
|
+
<!-- @slot Use it to add something instead of the default loader. -->
|
|
25
|
+
<slot>
|
|
26
|
+
<div v-for="ellipse in ELLIPSES_AMOUNT" :key="ellipse" v-bind="ellipseAttrs" />
|
|
27
|
+
</slot>
|
|
28
|
+
</div>
|
|
29
|
+
</Transition>
|
|
30
|
+
</template>
|
|
31
|
+
|
|
52
32
|
<style scoped lang="postcss">
|
|
53
33
|
.vueless-loader-ellipse:nth-child(1) {
|
|
54
34
|
animation: ellipse-1 0.6s infinite;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Meta, Title, Subtitle, Description, Primary, Controls, Stories, Source } from "@storybook/blocks";
|
|
2
2
|
import { getSource } from "../../utils/storybook.ts";
|
|
3
3
|
|
|
4
|
-
import * as stories from "./stories.
|
|
5
|
-
import defaultConfig from "../config.
|
|
4
|
+
import * as stories from "./stories.ts";
|
|
5
|
+
import defaultConfig from "../config.ts?raw"
|
|
6
6
|
|
|
7
7
|
<Meta of={stories} />
|
|
8
8
|
<Title of={stories} />
|
|
@@ -5,6 +5,14 @@ import URow from "../../ui.container-row/URow.vue";
|
|
|
5
5
|
import UButton from "../../ui.button/UButton.vue";
|
|
6
6
|
import { ref } from "vue";
|
|
7
7
|
|
|
8
|
+
import type { Meta, StoryFn } from "@storybook/vue3";
|
|
9
|
+
import type { ULoaderProps } from "../types.ts";
|
|
10
|
+
|
|
11
|
+
interface ULoaderArgs extends ULoaderProps {
|
|
12
|
+
slotTemplate?: string;
|
|
13
|
+
enum: "size" | "color";
|
|
14
|
+
}
|
|
15
|
+
|
|
8
16
|
/**
|
|
9
17
|
* The `ULoader` component. | [View on GitHub](https://github.com/vuelessjs/vueless/tree/main/src/ui.loader)
|
|
10
18
|
*/
|
|
@@ -18,9 +26,9 @@ export default {
|
|
|
18
26
|
argTypes: {
|
|
19
27
|
...getArgTypes(ULoader.__name),
|
|
20
28
|
},
|
|
21
|
-
};
|
|
29
|
+
} as Meta;
|
|
22
30
|
|
|
23
|
-
const DefaultTemplate = (args) => ({
|
|
31
|
+
const DefaultTemplate: StoryFn<ULoaderArgs> = (args: ULoaderArgs) => ({
|
|
24
32
|
components: { ULoader },
|
|
25
33
|
setup() {
|
|
26
34
|
const slots = getSlotNames(ULoader.__name);
|
|
@@ -29,17 +37,17 @@ const DefaultTemplate = (args) => ({
|
|
|
29
37
|
},
|
|
30
38
|
template: `
|
|
31
39
|
<ULoader v-bind="args">
|
|
32
|
-
${args.slotTemplate || getSlotsFragment()}
|
|
40
|
+
${args.slotTemplate || getSlotsFragment("")}
|
|
33
41
|
</ULoader>
|
|
34
42
|
`,
|
|
35
43
|
});
|
|
36
44
|
|
|
37
|
-
const EnumVariantTemplate = (args, { argTypes }) => ({
|
|
45
|
+
const EnumVariantTemplate: StoryFn<ULoaderArgs> = (args: ULoaderArgs, { argTypes }) => ({
|
|
38
46
|
components: { ULoader, URow },
|
|
39
47
|
setup() {
|
|
40
48
|
return {
|
|
41
49
|
args,
|
|
42
|
-
options: argTypes[args.enum]
|
|
50
|
+
options: argTypes?.[args.enum]?.options,
|
|
43
51
|
};
|
|
44
52
|
},
|
|
45
53
|
template: `
|
|
@@ -54,7 +62,7 @@ const EnumVariantTemplate = (args, { argTypes }) => ({
|
|
|
54
62
|
`,
|
|
55
63
|
});
|
|
56
64
|
|
|
57
|
-
const LoadingTemplate = (args) => ({
|
|
65
|
+
const LoadingTemplate: StoryFn<ULoaderArgs> = (args: ULoaderArgs) => ({
|
|
58
66
|
components: { ULoader, UButton, URow },
|
|
59
67
|
setup() {
|
|
60
68
|
function toggleLoader() {
|
|
@@ -66,7 +74,7 @@ const LoadingTemplate = (args) => ({
|
|
|
66
74
|
return { args, isLoading, toggleLoader };
|
|
67
75
|
},
|
|
68
76
|
template: `
|
|
69
|
-
<URow>
|
|
77
|
+
<URow align="center">
|
|
70
78
|
<ULoader v-bind="args" :loading="isLoading" />
|
|
71
79
|
<UButton @click="toggleLoader" size="sm">ToggleLoader</UButton>
|
|
72
80
|
</URow>
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import defaultConfig from "./config.ts";
|
|
2
|
+
|
|
3
|
+
export type Config = Partial<typeof defaultConfig>;
|
|
4
|
+
|
|
5
|
+
export interface ULoaderProps {
|
|
6
|
+
/**
|
|
7
|
+
* Loader state (shown / hidden).
|
|
8
|
+
*/
|
|
9
|
+
loading?: boolean;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Loader color.
|
|
13
|
+
*/
|
|
14
|
+
color?:
|
|
15
|
+
| "brand"
|
|
16
|
+
| "grayscale"
|
|
17
|
+
| "gray"
|
|
18
|
+
| "red"
|
|
19
|
+
| "orange"
|
|
20
|
+
| "amber"
|
|
21
|
+
| "yellow"
|
|
22
|
+
| "lime"
|
|
23
|
+
| "green"
|
|
24
|
+
| "emerald"
|
|
25
|
+
| "teal"
|
|
26
|
+
| "cyan"
|
|
27
|
+
| "sky"
|
|
28
|
+
| "blue"
|
|
29
|
+
| "indigo"
|
|
30
|
+
| "violet"
|
|
31
|
+
| "purple"
|
|
32
|
+
| "fuchsia"
|
|
33
|
+
| "pink"
|
|
34
|
+
| "rose"
|
|
35
|
+
| "black"
|
|
36
|
+
| "white";
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Loader size.
|
|
40
|
+
*/
|
|
41
|
+
size?: "sm" | "md" | "lg";
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Component config object.
|
|
45
|
+
*/
|
|
46
|
+
config?: Partial<typeof defaultConfig>;
|
|
47
|
+
}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { computed } from "vue";
|
|
2
2
|
import useUI from "../composables/useUI.ts";
|
|
3
3
|
|
|
4
|
-
import defaultConfig from "./config.
|
|
4
|
+
import defaultConfig from "./config.ts";
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
import type { UseAttrs } from "../types.ts";
|
|
7
|
+
import type { ULoaderProps, Config } from "./types.ts";
|
|
8
|
+
|
|
9
|
+
export default function useAttrs(props: ULoaderProps): UseAttrs<Config> {
|
|
10
|
+
const { config, getKeysAttrs, hasSlotContent } = useUI<Config>(
|
|
8
11
|
defaultConfig,
|
|
9
12
|
() => props.config,
|
|
10
13
|
"loader",
|
|
@@ -1,15 +1,4 @@
|
|
|
1
|
-
<
|
|
2
|
-
<Transition v-bind="config.transition">
|
|
3
|
-
<div v-if="showLoader" v-bind="overlayAttrs">
|
|
4
|
-
<!-- @slot Use it to add something instead of the default loader. -->
|
|
5
|
-
<slot>
|
|
6
|
-
<ULoader :loading="showLoader" size="lg" :color="loaderColor" v-bind="nestedLoaderAttrs" />
|
|
7
|
-
</slot>
|
|
8
|
-
</div>
|
|
9
|
-
</Transition>
|
|
10
|
-
</template>
|
|
11
|
-
|
|
12
|
-
<script setup>
|
|
1
|
+
<script lang="ts" setup>
|
|
13
2
|
import { computed, onMounted, onUnmounted } from "vue";
|
|
14
3
|
|
|
15
4
|
import { getDefault } from "../utils/ui.ts";
|
|
@@ -17,34 +6,22 @@ import { useDarkMode } from "../composables/useDarkMode.ts";
|
|
|
17
6
|
|
|
18
7
|
import ULoader from "../ui.loader/ULoader.vue";
|
|
19
8
|
|
|
20
|
-
import { ULoaderOverlay } from "./constants.
|
|
21
|
-
import defaultConfig from "./config.
|
|
22
|
-
import useAttrs from "./useAttrs.
|
|
23
|
-
import { useLoaderOverlay } from "./useLoaderOverlay.
|
|
9
|
+
import { ULoaderOverlay } from "./constants.ts";
|
|
10
|
+
import defaultConfig from "./config.ts";
|
|
11
|
+
import useAttrs from "./useAttrs.ts";
|
|
12
|
+
import { useLoaderOverlay } from "./useLoaderOverlay.ts";
|
|
24
13
|
|
|
25
|
-
|
|
14
|
+
import type { ULoaderOverlayProps } from "./types.ts";
|
|
26
15
|
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Loader state (shown / hidden).
|
|
30
|
-
*/
|
|
31
|
-
loading: {
|
|
32
|
-
type: Boolean,
|
|
33
|
-
default: getDefault(defaultConfig, ULoaderOverlay).loading,
|
|
34
|
-
},
|
|
16
|
+
defineOptions({ inheritAttrs: false });
|
|
35
17
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
*/
|
|
40
|
-
color: {
|
|
41
|
-
type: String,
|
|
42
|
-
default: getDefault(defaultConfig, ULoaderOverlay).color,
|
|
43
|
-
},
|
|
18
|
+
const props = withDefaults(defineProps<ULoaderOverlayProps>(), {
|
|
19
|
+
loading: getDefault<ULoaderOverlayProps>(defaultConfig, ULoaderOverlay).loading,
|
|
20
|
+
color: getDefault<ULoaderOverlayProps>(defaultConfig, ULoaderOverlay).color,
|
|
44
21
|
});
|
|
45
22
|
|
|
46
23
|
const { overlayAttrs, nestedLoaderAttrs, config } = useAttrs(props);
|
|
47
|
-
const {
|
|
24
|
+
const { loaderOverlayOn, loaderOverlayOff, isLoading } = useLoaderOverlay();
|
|
48
25
|
const { isDarkMode } = useDarkMode();
|
|
49
26
|
|
|
50
27
|
const loaderColor = computed(() => {
|
|
@@ -65,6 +42,17 @@ onUnmounted(() => {
|
|
|
65
42
|
});
|
|
66
43
|
|
|
67
44
|
const showLoader = computed(() => {
|
|
68
|
-
return props.loading === undefined ? isLoading.value : props.loading;
|
|
45
|
+
return props.loading === undefined ? (isLoading.value ?? false) : props.loading;
|
|
69
46
|
});
|
|
70
47
|
</script>
|
|
48
|
+
|
|
49
|
+
<template>
|
|
50
|
+
<Transition v-bind="config?.transition">
|
|
51
|
+
<div v-if="showLoader" v-bind="overlayAttrs">
|
|
52
|
+
<!-- @slot Use it to add something instead of the default loader. -->
|
|
53
|
+
<slot>
|
|
54
|
+
<ULoader :loading="showLoader" size="lg" :color="loaderColor" v-bind="nestedLoaderAttrs" />
|
|
55
|
+
</slot>
|
|
56
|
+
</div>
|
|
57
|
+
</Transition>
|
|
58
|
+
</template>
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Meta, Title, Subtitle, Description, Primary, Controls, Stories, Source } from "@storybook/blocks";
|
|
2
2
|
import { getSource } from "../../utils/storybook.ts";
|
|
3
3
|
|
|
4
|
-
import * as stories from "./stories.
|
|
5
|
-
import defaultConfig from "../config.
|
|
4
|
+
import * as stories from "./stories.ts";
|
|
5
|
+
import defaultConfig from "../config.ts?raw"
|
|
6
6
|
|
|
7
7
|
<Meta of={stories} />
|
|
8
8
|
<Title of={stories} />
|
|
@@ -4,7 +4,14 @@ import ULoaderOverlay from "../ULoaderOverlay.vue";
|
|
|
4
4
|
import UButton from "../../ui.button/UButton.vue";
|
|
5
5
|
import UCol from "../../ui.container-col/UCol.vue";
|
|
6
6
|
|
|
7
|
-
import { useLoaderOverlay } from "../useLoaderOverlay.
|
|
7
|
+
import { useLoaderOverlay } from "../useLoaderOverlay.ts";
|
|
8
|
+
|
|
9
|
+
import type { Meta, StoryFn } from "@storybook/vue3";
|
|
10
|
+
import type { ULoaderOverlayProps } from "../types.ts";
|
|
11
|
+
|
|
12
|
+
interface ULoaderOverlayArgs extends ULoaderOverlayProps {
|
|
13
|
+
slotTemplate?: string;
|
|
14
|
+
}
|
|
8
15
|
|
|
9
16
|
/**
|
|
10
17
|
* The `ULoaderOverlay` component. | [View on GitHub](https://github.com/vuelessjs/vueless/tree/main/src/ui.loader-overlay)
|
|
@@ -23,9 +30,9 @@ export default {
|
|
|
23
30
|
},
|
|
24
31
|
},
|
|
25
32
|
},
|
|
26
|
-
};
|
|
33
|
+
} as Meta;
|
|
27
34
|
|
|
28
|
-
const DefaultTemplate = (args) => ({
|
|
35
|
+
const DefaultTemplate: StoryFn<ULoaderOverlayArgs> = (args: ULoaderOverlayArgs) => ({
|
|
29
36
|
components: { ULoaderOverlay },
|
|
30
37
|
setup() {
|
|
31
38
|
const slots = getSlotNames(ULoaderOverlay.__name);
|
|
@@ -34,18 +41,26 @@ const DefaultTemplate = (args) => ({
|
|
|
34
41
|
},
|
|
35
42
|
template: `
|
|
36
43
|
<ULoaderOverlay v-bind="args" class="w-full h-full">
|
|
37
|
-
${args.slotTemplate || getSlotsFragment()}
|
|
44
|
+
${args.slotTemplate || getSlotsFragment("")}
|
|
38
45
|
</ULoaderOverlay>
|
|
39
46
|
`,
|
|
40
47
|
});
|
|
41
48
|
|
|
42
|
-
const LoadingTemplate = (args) => ({
|
|
49
|
+
const LoadingTemplate: StoryFn<ULoaderOverlayArgs> = (args: ULoaderOverlayArgs) => ({
|
|
43
50
|
components: { ULoaderOverlay, UButton, UCol },
|
|
44
51
|
setup() {
|
|
45
|
-
const
|
|
52
|
+
const loaderOverlay = useLoaderOverlay();
|
|
53
|
+
|
|
54
|
+
const loaderOverlayOn = loaderOverlay?.loaderOverlayOn || (() => {});
|
|
55
|
+
const loaderOverlayOff = loaderOverlay?.loaderOverlayOff || (() => {});
|
|
56
|
+
const isLoading = loaderOverlay?.isLoading || { value: false };
|
|
46
57
|
|
|
47
58
|
function toggleLoading() {
|
|
48
|
-
isLoading.value
|
|
59
|
+
if (isLoading.value) {
|
|
60
|
+
loaderOverlayOff();
|
|
61
|
+
} else {
|
|
62
|
+
loaderOverlayOn();
|
|
63
|
+
}
|
|
49
64
|
}
|
|
50
65
|
|
|
51
66
|
return { args, loaderOverlayOn, loaderOverlayOff, isLoading, toggleLoading };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import defaultConfig from "./config.ts";
|
|
2
|
+
|
|
3
|
+
export type Config = Partial<typeof defaultConfig>;
|
|
4
|
+
|
|
5
|
+
export interface ULoaderOverlayProps {
|
|
6
|
+
/**
|
|
7
|
+
* Loader state (shown / hidden).
|
|
8
|
+
*/
|
|
9
|
+
loading?: boolean;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Loader color.
|
|
13
|
+
*/
|
|
14
|
+
color?:
|
|
15
|
+
| "brand"
|
|
16
|
+
| "grayscale"
|
|
17
|
+
| "gray"
|
|
18
|
+
| "red"
|
|
19
|
+
| "orange"
|
|
20
|
+
| "amber"
|
|
21
|
+
| "yellow"
|
|
22
|
+
| "lime"
|
|
23
|
+
| "green"
|
|
24
|
+
| "emerald"
|
|
25
|
+
| "teal"
|
|
26
|
+
| "cyan"
|
|
27
|
+
| "sky"
|
|
28
|
+
| "blue"
|
|
29
|
+
| "indigo"
|
|
30
|
+
| "violet"
|
|
31
|
+
| "purple"
|
|
32
|
+
| "fuchsia"
|
|
33
|
+
| "pink"
|
|
34
|
+
| "rose"
|
|
35
|
+
| "black"
|
|
36
|
+
| "white";
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Component config object.
|
|
40
|
+
*/
|
|
41
|
+
config?: Partial<typeof defaultConfig>;
|
|
42
|
+
}
|
|
@@ -2,8 +2,11 @@ import useUI from "../composables/useUI.ts";
|
|
|
2
2
|
|
|
3
3
|
import defaultConfig from "./config.js";
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
import type { UseAttrs } from "../types.ts";
|
|
6
|
+
import type { ULoaderOverlayProps, Config } from "./types.ts";
|
|
7
|
+
|
|
8
|
+
export default function useAttrs(props: ULoaderOverlayProps): UseAttrs<Config> {
|
|
9
|
+
const { config, getKeysAttrs, hasSlotContent } = useUI<Config>(
|
|
7
10
|
defaultConfig,
|
|
8
11
|
() => props.config,
|
|
9
12
|
"overlay",
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { inject, readonly, ref } from "vue";
|
|
2
|
+
|
|
3
|
+
import type { Ref, InjectionKey } from "vue";
|
|
4
|
+
|
|
5
|
+
export const LoaderOverlaySymbol: InjectionKey<LoaderOverlay> =
|
|
6
|
+
Symbol.for("vueless:loader-overlay");
|
|
7
|
+
|
|
8
|
+
interface LoaderOverlay {
|
|
9
|
+
isLoading: Readonly<Ref<boolean, boolean>>;
|
|
10
|
+
loaderOverlayOn: () => void;
|
|
11
|
+
loaderOverlayOff: () => void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const isLoading = ref(true);
|
|
15
|
+
|
|
16
|
+
function loaderOverlayOn(): void {
|
|
17
|
+
isLoading.value = true;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function loaderOverlayOff(): void {
|
|
21
|
+
isLoading.value = false;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function createLoaderOverlay(): LoaderOverlay {
|
|
25
|
+
return {
|
|
26
|
+
isLoading: readonly(isLoading),
|
|
27
|
+
loaderOverlayOn,
|
|
28
|
+
loaderOverlayOff,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function useLoaderOverlay(): LoaderOverlay {
|
|
33
|
+
const loaderOverlay = inject(LoaderOverlaySymbol);
|
|
34
|
+
|
|
35
|
+
if (!loaderOverlay) {
|
|
36
|
+
throw new Error(
|
|
37
|
+
"LoaderOverlay not provided. Ensure you are using `provide` with `LoaderOverlaySymbol`.",
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return loaderOverlay;
|
|
42
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export function loaderOverlayOn() {
|
|
1
|
+
export function loaderOverlayOn(): void {
|
|
2
2
|
window.dispatchEvent(new Event("loaderOverlayOn"));
|
|
3
3
|
}
|
|
4
4
|
|
|
5
|
-
export function loaderOverlayOff() {
|
|
5
|
+
export function loaderOverlayOff(): void {
|
|
6
6
|
window.dispatchEvent(new Event("loaderOverlayOff"));
|
|
7
7
|
}
|
|
@@ -1,55 +1,29 @@
|
|
|
1
|
-
<
|
|
2
|
-
<Transition :css="false" @before-enter="beforeEnter" @enter="enter" @after-enter="afterEnter">
|
|
3
|
-
<div v-if="show" v-bind="stripeAttrs" :style="barStyle" />
|
|
4
|
-
</Transition>
|
|
5
|
-
</template>
|
|
6
|
-
|
|
7
|
-
<script setup>
|
|
1
|
+
<script lang="ts" setup>
|
|
8
2
|
import { computed, onBeforeUnmount, watch, ref, onMounted, onUnmounted } from "vue";
|
|
9
3
|
|
|
10
4
|
import { getDefault } from "../utils/ui.ts";
|
|
11
5
|
import { isMobileApp } from "../utils/platform.ts";
|
|
12
|
-
import { clamp, queue, getRequestWithoutQuery } from "./utilLoaderProgress.
|
|
13
|
-
import { useLoaderProgress } from "./useLoaderProgress.
|
|
14
|
-
import useAttrs from "./useAttrs.
|
|
6
|
+
import { clamp, queue, getRequestWithoutQuery } from "./utilLoaderProgress.ts";
|
|
7
|
+
import { useLoaderProgress } from "./useLoaderProgress.ts";
|
|
8
|
+
import useAttrs from "./useAttrs.ts";
|
|
15
9
|
|
|
16
|
-
import { ULoaderProgress, MAXIMUM, SPEED, INFINITY_LOADING } from "./constants.
|
|
17
|
-
import defaultConfig from "./config.
|
|
10
|
+
import { ULoaderProgress, MAXIMUM, SPEED, INFINITY_LOADING } from "./constants.ts";
|
|
11
|
+
import defaultConfig from "./config.ts";
|
|
18
12
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const props = defineProps({
|
|
22
|
-
/**
|
|
23
|
-
* Loader stripe color.
|
|
24
|
-
* @values brand, grayscale, gray, red, orange, amber, yellow, lime, green, emerald, teal, cyan, sky, blue, indigo, violet, purple, fuchsia, pink, rose, white
|
|
25
|
-
*/
|
|
26
|
-
color: {
|
|
27
|
-
type: String,
|
|
28
|
-
default: getDefault(defaultConfig, ULoaderProgress).color,
|
|
29
|
-
},
|
|
13
|
+
import type { ULoaderProgressProps } from "./types.ts";
|
|
30
14
|
|
|
31
|
-
|
|
32
|
-
* API resource names (endpoint URIs).
|
|
33
|
-
*/
|
|
34
|
-
resources: {
|
|
35
|
-
type: [String, Array],
|
|
36
|
-
default: "",
|
|
37
|
-
},
|
|
15
|
+
defineOptions({ inheritAttrs: false });
|
|
38
16
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
loading: {
|
|
43
|
-
type: Boolean,
|
|
44
|
-
default: getDefault(defaultConfig, ULoaderProgress).loading,
|
|
45
|
-
},
|
|
17
|
+
const props = withDefaults(defineProps<ULoaderProgressProps>(), {
|
|
18
|
+
color: getDefault<ULoaderProgressProps>(defaultConfig, ULoaderProgress).color,
|
|
19
|
+
loading: getDefault<ULoaderProgressProps>(defaultConfig, ULoaderProgress).loading,
|
|
46
20
|
});
|
|
47
21
|
|
|
48
22
|
const error = ref(false);
|
|
49
23
|
const show = ref(false);
|
|
50
24
|
const progress = ref(0);
|
|
51
25
|
const opacity = ref(1);
|
|
52
|
-
const status = ref(null);
|
|
26
|
+
const status = ref<number | null>(null);
|
|
53
27
|
|
|
54
28
|
const {
|
|
55
29
|
requestQueue,
|
|
@@ -59,7 +33,8 @@ const {
|
|
|
59
33
|
loaderProgressOn,
|
|
60
34
|
addRequestUrl,
|
|
61
35
|
} = useLoaderProgress();
|
|
62
|
-
|
|
36
|
+
|
|
37
|
+
const { stripeAttrs } = useAttrs(props, { isMobileApp });
|
|
63
38
|
|
|
64
39
|
const isStarted = computed(() => {
|
|
65
40
|
return typeof status.value === "number";
|
|
@@ -73,6 +48,10 @@ const barStyle = computed(() => {
|
|
|
73
48
|
});
|
|
74
49
|
|
|
75
50
|
const resourceNamesArray = computed(() => {
|
|
51
|
+
if (!props.resources) {
|
|
52
|
+
return [];
|
|
53
|
+
}
|
|
54
|
+
|
|
76
55
|
return Array.isArray(props.resources)
|
|
77
56
|
? props.resources.map(getRequestWithoutQuery)
|
|
78
57
|
: [getRequestWithoutQuery(props.resources)];
|
|
@@ -81,8 +60,8 @@ const resourceNamesArray = computed(() => {
|
|
|
81
60
|
watch(() => requestQueue.value.length, onChangeRequestsQueue);
|
|
82
61
|
|
|
83
62
|
onMounted(() => {
|
|
84
|
-
window.addEventListener("loaderProgressOn", setLoaderOnHandler);
|
|
85
|
-
window.addEventListener("loaderProgressOff", setLoaderOffHandler);
|
|
63
|
+
window.addEventListener("loaderProgressOn", setLoaderOnHandler as EventListener);
|
|
64
|
+
window.addEventListener("loaderProgressOff", setLoaderOffHandler as EventListener);
|
|
86
65
|
|
|
87
66
|
if (props.resources) {
|
|
88
67
|
onChangeRequestsQueue();
|
|
@@ -94,8 +73,8 @@ onBeforeUnmount(() => {
|
|
|
94
73
|
});
|
|
95
74
|
|
|
96
75
|
onUnmounted(() => {
|
|
97
|
-
window.removeEventListener("loaderProgressOn", setLoaderOnHandler);
|
|
98
|
-
window.removeEventListener("loaderProgressOff", setLoaderOffHandler);
|
|
76
|
+
window.removeEventListener("loaderProgressOn", setLoaderOnHandler as EventListener);
|
|
77
|
+
window.removeEventListener("loaderProgressOff", setLoaderOffHandler as EventListener);
|
|
99
78
|
});
|
|
100
79
|
|
|
101
80
|
watch(
|
|
@@ -111,11 +90,11 @@ watch(
|
|
|
111
90
|
{ immediate: true },
|
|
112
91
|
);
|
|
113
92
|
|
|
114
|
-
function setLoaderOnHandler(event) {
|
|
93
|
+
function setLoaderOnHandler(event: CustomEvent<{ resource: string }>) {
|
|
115
94
|
loaderProgressOn(event.detail.resource);
|
|
116
95
|
}
|
|
117
96
|
|
|
118
|
-
function setLoaderOffHandler(event) {
|
|
97
|
+
function setLoaderOffHandler(event: CustomEvent<{ resource: string }>) {
|
|
119
98
|
loaderProgressOff(event.detail.resource);
|
|
120
99
|
}
|
|
121
100
|
|
|
@@ -138,7 +117,7 @@ function beforeEnter() {
|
|
|
138
117
|
progress.value = 0;
|
|
139
118
|
}
|
|
140
119
|
|
|
141
|
-
function enter(el, done) {
|
|
120
|
+
function enter(el: Element, done: () => void) {
|
|
142
121
|
opacity.value = 1;
|
|
143
122
|
done();
|
|
144
123
|
}
|
|
@@ -172,7 +151,7 @@ function start() {
|
|
|
172
151
|
}
|
|
173
152
|
}
|
|
174
153
|
|
|
175
|
-
function set(amount) {
|
|
154
|
+
function set(amount: number) {
|
|
176
155
|
let currentProgress;
|
|
177
156
|
|
|
178
157
|
if (isStarted.value) {
|
|
@@ -201,7 +180,7 @@ function set(amount) {
|
|
|
201
180
|
});
|
|
202
181
|
}
|
|
203
182
|
|
|
204
|
-
function increase(amount) {
|
|
183
|
+
function increase(amount?: number) {
|
|
205
184
|
const currentProgress = progress.value;
|
|
206
185
|
|
|
207
186
|
if (currentProgress < 100 && typeof amount !== "number") {
|
|
@@ -220,10 +199,16 @@ function increase(amount) {
|
|
|
220
199
|
}
|
|
221
200
|
}
|
|
222
201
|
|
|
223
|
-
set(clamp(currentProgress + amount, 0, MAXIMUM));
|
|
202
|
+
set(clamp(currentProgress + (amount || 0), 0, MAXIMUM));
|
|
224
203
|
}
|
|
225
204
|
|
|
226
205
|
function done() {
|
|
227
206
|
set(100);
|
|
228
207
|
}
|
|
229
208
|
</script>
|
|
209
|
+
|
|
210
|
+
<template>
|
|
211
|
+
<Transition :css="false" @before-enter="beforeEnter" @enter="enter" @after-enter="afterEnter">
|
|
212
|
+
<div v-if="show" v-bind="stripeAttrs" :style="barStyle" />
|
|
213
|
+
</Transition>
|
|
214
|
+
</template>
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Meta, Title, Subtitle, Description, Primary, Controls, Stories, Source, Markdown } from "@storybook/blocks";
|
|
2
2
|
import { getSource } from "../../utils/storybook.ts";
|
|
3
3
|
|
|
4
|
-
import * as stories from "./stories.
|
|
5
|
-
import defaultConfig from "../config.
|
|
4
|
+
import * as stories from "./stories.ts";
|
|
5
|
+
import defaultConfig from "../config.ts?raw"
|
|
6
6
|
|
|
7
7
|
<Meta of={stories} />
|
|
8
8
|
<Title of={stories} />
|
|
@@ -6,8 +6,16 @@ import URow from "../../ui.container-row/URow.vue";
|
|
|
6
6
|
import UCol from "../../ui.container-col/UCol.vue";
|
|
7
7
|
import UBadge from "../../ui.text-badge/UBadge.vue";
|
|
8
8
|
|
|
9
|
-
import { useLoaderProgress } from "../useLoaderProgress.
|
|
10
|
-
import { loaderProgressOff, loaderProgressOn } from "../utilLoaderProgress.
|
|
9
|
+
import { useLoaderProgress } from "../useLoaderProgress.ts";
|
|
10
|
+
import { loaderProgressOff, loaderProgressOn } from "../utilLoaderProgress.ts";
|
|
11
|
+
|
|
12
|
+
import type { Meta, StoryFn } from "@storybook/vue3";
|
|
13
|
+
import type { ULoaderProgressProps } from "../types.ts";
|
|
14
|
+
|
|
15
|
+
interface ULoaderProgressArgs extends ULoaderProgressProps {
|
|
16
|
+
slotTemplate?: string;
|
|
17
|
+
enum: "color";
|
|
18
|
+
}
|
|
11
19
|
|
|
12
20
|
/**
|
|
13
21
|
* The `ULoaderProgress` component. | [View on GitHub](https://github.com/vuelessjs/vueless/tree/main/src/ui.loader-progress)
|
|
@@ -19,12 +27,18 @@ export default {
|
|
|
19
27
|
argTypes: {
|
|
20
28
|
...getArgTypes(ULoaderProgress.__name),
|
|
21
29
|
},
|
|
22
|
-
};
|
|
30
|
+
} as Meta;
|
|
23
31
|
|
|
24
|
-
const DefaultTemplate = (args) => ({
|
|
32
|
+
const DefaultTemplate: StoryFn<ULoaderProgressArgs> = (args: ULoaderProgressArgs) => ({
|
|
25
33
|
components: { ULoaderProgress, UButton, URow },
|
|
26
34
|
setup() {
|
|
27
|
-
const
|
|
35
|
+
const loaderProgress = useLoaderProgress();
|
|
36
|
+
|
|
37
|
+
if (!loaderProgress) {
|
|
38
|
+
throw new Error("LoaderProgress is not provided. Ensure it is properly injected.");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const { loaderProgressOn, loaderProgressOff } = loaderProgress;
|
|
28
42
|
const slots = getSlotNames(ULoaderProgress.__name);
|
|
29
43
|
|
|
30
44
|
return { args, slots, loaderProgressOn, loaderProgressOff };
|
|
@@ -39,14 +53,17 @@ const DefaultTemplate = (args) => ({
|
|
|
39
53
|
`,
|
|
40
54
|
});
|
|
41
55
|
|
|
42
|
-
const EnumVariantTemplate = (
|
|
56
|
+
const EnumVariantTemplate: StoryFn<ULoaderProgressArgs> = (
|
|
57
|
+
args: ULoaderProgressArgs,
|
|
58
|
+
{ argTypes },
|
|
59
|
+
) => ({
|
|
43
60
|
components: { ULoaderProgress, UButton, UCol, URow, UBadge },
|
|
44
61
|
setup() {
|
|
45
62
|
return {
|
|
46
63
|
args,
|
|
47
64
|
loaderProgressOff,
|
|
48
65
|
loaderProgressOn,
|
|
49
|
-
options: argTypes[args.enum]
|
|
66
|
+
options: argTypes?.[args.enum]?.options,
|
|
50
67
|
};
|
|
51
68
|
},
|
|
52
69
|
template: `
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import defaultConfig from "./config.ts";
|
|
2
|
+
|
|
3
|
+
export type Config = Partial<typeof defaultConfig>;
|
|
4
|
+
|
|
5
|
+
export interface ULoaderProgressProps {
|
|
6
|
+
/**
|
|
7
|
+
* Loader stripe color.
|
|
8
|
+
*/
|
|
9
|
+
color?:
|
|
10
|
+
| "brand"
|
|
11
|
+
| "grayscale"
|
|
12
|
+
| "gray"
|
|
13
|
+
| "red"
|
|
14
|
+
| "orange"
|
|
15
|
+
| "amber"
|
|
16
|
+
| "yellow"
|
|
17
|
+
| "lime"
|
|
18
|
+
| "green"
|
|
19
|
+
| "emerald"
|
|
20
|
+
| "teal"
|
|
21
|
+
| "cyan"
|
|
22
|
+
| "sky"
|
|
23
|
+
| "blue"
|
|
24
|
+
| "indigo"
|
|
25
|
+
| "violet"
|
|
26
|
+
| "purple"
|
|
27
|
+
| "fuchsia"
|
|
28
|
+
| "pink"
|
|
29
|
+
| "rose"
|
|
30
|
+
| "white";
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* API resource names (endpoint URIs).
|
|
34
|
+
*/
|
|
35
|
+
resources?: string | string[];
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Loader state (shown / hidden).
|
|
39
|
+
*/
|
|
40
|
+
loading?: boolean;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Component config object.
|
|
44
|
+
*/
|
|
45
|
+
config?: Partial<typeof defaultConfig>;
|
|
46
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { computed } from "vue";
|
|
2
|
+
import useUI from "../composables/useUI.ts";
|
|
3
|
+
|
|
4
|
+
import defaultConfig from "./config.ts";
|
|
5
|
+
|
|
6
|
+
import type { UseAttrs } from "../types.ts";
|
|
7
|
+
import type { ULoaderProgressProps, Config } from "./types.ts";
|
|
8
|
+
|
|
9
|
+
type ComponentState = {
|
|
10
|
+
isMobileApp: boolean;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export default function useAttrs(
|
|
14
|
+
props: ULoaderProgressProps,
|
|
15
|
+
{ isMobileApp }: ComponentState,
|
|
16
|
+
): UseAttrs<Config> {
|
|
17
|
+
const { config, getKeysAttrs, getExtendingKeysClasses, hasSlotContent } = useUI<Config>(
|
|
18
|
+
defaultConfig,
|
|
19
|
+
() => props.config,
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
const extendingKeys = ["stripeMobile"];
|
|
23
|
+
const extendingKeysClasses = getExtendingKeysClasses(extendingKeys);
|
|
24
|
+
|
|
25
|
+
const keysAttrs = getKeysAttrs({}, extendingKeys, {
|
|
26
|
+
stripe: {
|
|
27
|
+
extend: computed(() => [isMobileApp && extendingKeysClasses.linkWithChild.value]),
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
config,
|
|
33
|
+
...keysAttrs,
|
|
34
|
+
hasSlotContent,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { inject, readonly, ref } from "vue";
|
|
2
|
+
|
|
3
|
+
import type { Ref } from "vue";
|
|
4
|
+
|
|
5
|
+
import { getRequestWithoutQuery } from "./utilLoaderProgress.ts";
|
|
6
|
+
import { INFINITY_LOADING } from "./constants.ts";
|
|
7
|
+
|
|
8
|
+
export const LoaderProgressSymbol = Symbol.for("vueless:loader-progress");
|
|
9
|
+
|
|
10
|
+
type LoaderProgress = {
|
|
11
|
+
isLoading: Ref<boolean>;
|
|
12
|
+
requestQueue: Readonly<Ref<readonly string[]>>;
|
|
13
|
+
loaderProgressOn: (url: string | string[]) => void;
|
|
14
|
+
loaderProgressOff: (url: string | string[]) => void;
|
|
15
|
+
addRequestUrl: (url: string | string[]) => void;
|
|
16
|
+
removeRequestUrl: (url: string | string[]) => void;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const isLoading = ref(false);
|
|
20
|
+
const requestQueue = ref<string[]>([]);
|
|
21
|
+
const requestTimeout = ref<number | undefined>(undefined);
|
|
22
|
+
|
|
23
|
+
function loaderProgressOn(url: string | string[]): void {
|
|
24
|
+
addRequestUrl(url);
|
|
25
|
+
isLoading.value = true;
|
|
26
|
+
|
|
27
|
+
if (requestTimeout.value !== undefined) {
|
|
28
|
+
clearTimeout(requestTimeout.value);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function loaderProgressOff(url: string | string[]): void {
|
|
33
|
+
removeRequestUrl(url);
|
|
34
|
+
|
|
35
|
+
requestTimeout.value = window.setTimeout(() => {
|
|
36
|
+
if (!requestQueue.value.length) {
|
|
37
|
+
isLoading.value = false;
|
|
38
|
+
}
|
|
39
|
+
}, 50);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function addRequestUrl(url: string | string[]): void {
|
|
43
|
+
if (Array.isArray(url)) {
|
|
44
|
+
requestQueue.value.push(...url.map(getRequestWithoutQuery));
|
|
45
|
+
} else {
|
|
46
|
+
requestQueue.value.push(getRequestWithoutQuery(url));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function removeRequestUrl(url: string | string[]): void {
|
|
51
|
+
if (Array.isArray(url)) {
|
|
52
|
+
url.map(getRequestWithoutQuery).forEach(removeRequestUrl);
|
|
53
|
+
} else {
|
|
54
|
+
requestQueue.value = requestQueue.value.filter(
|
|
55
|
+
(item) => item !== getRequestWithoutQuery(url) && item !== INFINITY_LOADING,
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function createLoaderProgress(): LoaderProgress {
|
|
61
|
+
return {
|
|
62
|
+
isLoading,
|
|
63
|
+
requestQueue: readonly(requestQueue),
|
|
64
|
+
loaderProgressOn,
|
|
65
|
+
loaderProgressOff,
|
|
66
|
+
addRequestUrl,
|
|
67
|
+
removeRequestUrl,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function useLoaderProgress(): LoaderProgress {
|
|
72
|
+
const loaderProgress = inject<LoaderProgress>(LoaderProgressSymbol);
|
|
73
|
+
|
|
74
|
+
if (!loaderProgress) {
|
|
75
|
+
throw new Error(
|
|
76
|
+
"LoaderProgress not provided. Ensure you are using `provide` with `LoaderProgressSymbol`.",
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return loaderProgress;
|
|
81
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export function clamp(n: number, min: number, max: number): number {
|
|
2
|
+
if (n < min) {
|
|
3
|
+
return min;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
if (n > max) {
|
|
7
|
+
return max;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
return n;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const queue = (() => {
|
|
14
|
+
const pending: ((next: () => void) => void)[] = [];
|
|
15
|
+
|
|
16
|
+
function next(): void {
|
|
17
|
+
const fn = pending.shift();
|
|
18
|
+
|
|
19
|
+
if (fn) {
|
|
20
|
+
fn(next);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return (fn: (next: () => void) => void): void => {
|
|
25
|
+
pending.push(fn);
|
|
26
|
+
|
|
27
|
+
if (pending.length === 1) {
|
|
28
|
+
next();
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
})();
|
|
32
|
+
|
|
33
|
+
export function loaderProgressOn(resource: string): void {
|
|
34
|
+
const loaderProgressOnEvent = new CustomEvent("loaderProgressOn", { detail: { resource } });
|
|
35
|
+
|
|
36
|
+
window.dispatchEvent(loaderProgressOnEvent);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function loaderProgressOff(resource: string): void {
|
|
40
|
+
const loaderProgressOffEvent = new CustomEvent("loaderProgressOff", { detail: { resource } });
|
|
41
|
+
|
|
42
|
+
window.dispatchEvent(loaderProgressOffEvent);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function getRequestWithoutQuery(request: string | URL): string {
|
|
46
|
+
const [requestWithoutQuery] = String(request).split("?");
|
|
47
|
+
|
|
48
|
+
return requestWithoutQuery;
|
|
49
|
+
}
|
package/web-types.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"framework": "vue",
|
|
3
3
|
"name": "vueless",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.532",
|
|
5
5
|
"contributions": {
|
|
6
6
|
"html": {
|
|
7
7
|
"description-markup": "markdown",
|
|
@@ -7433,6 +7433,7 @@
|
|
|
7433
7433
|
"attributes": [
|
|
7434
7434
|
{
|
|
7435
7435
|
"name": "loading",
|
|
7436
|
+
"required": false,
|
|
7436
7437
|
"description": "Loader state (shown / hidden).",
|
|
7437
7438
|
"value": {
|
|
7438
7439
|
"kind": "expression",
|
|
@@ -7442,6 +7443,7 @@
|
|
|
7442
7443
|
},
|
|
7443
7444
|
{
|
|
7444
7445
|
"name": "color",
|
|
7446
|
+
"required": false,
|
|
7445
7447
|
"description": "Loader color.",
|
|
7446
7448
|
"enum": [
|
|
7447
7449
|
"brand",
|
|
@@ -7469,12 +7471,13 @@
|
|
|
7469
7471
|
],
|
|
7470
7472
|
"value": {
|
|
7471
7473
|
"kind": "expression",
|
|
7472
|
-
"type": "
|
|
7474
|
+
"type": "union"
|
|
7473
7475
|
},
|
|
7474
7476
|
"default": "brand"
|
|
7475
7477
|
},
|
|
7476
7478
|
{
|
|
7477
7479
|
"name": "size",
|
|
7480
|
+
"required": false,
|
|
7478
7481
|
"description": "Loader size.",
|
|
7479
7482
|
"enum": [
|
|
7480
7483
|
"sm",
|
|
@@ -7483,9 +7486,21 @@
|
|
|
7483
7486
|
],
|
|
7484
7487
|
"value": {
|
|
7485
7488
|
"kind": "expression",
|
|
7486
|
-
"type": "
|
|
7489
|
+
"type": "union"
|
|
7487
7490
|
},
|
|
7488
7491
|
"default": "md"
|
|
7492
|
+
},
|
|
7493
|
+
{
|
|
7494
|
+
"name": "config",
|
|
7495
|
+
"required": false,
|
|
7496
|
+
"description": "Component config object.",
|
|
7497
|
+
"enum": [
|
|
7498
|
+
"TSTypeQuery"
|
|
7499
|
+
],
|
|
7500
|
+
"value": {
|
|
7501
|
+
"kind": "expression",
|
|
7502
|
+
"type": "Partial"
|
|
7503
|
+
}
|
|
7489
7504
|
}
|
|
7490
7505
|
],
|
|
7491
7506
|
"slots": [
|
|
@@ -7505,6 +7520,7 @@
|
|
|
7505
7520
|
"attributes": [
|
|
7506
7521
|
{
|
|
7507
7522
|
"name": "loading",
|
|
7523
|
+
"required": false,
|
|
7508
7524
|
"description": "Loader state (shown / hidden).",
|
|
7509
7525
|
"value": {
|
|
7510
7526
|
"kind": "expression",
|
|
@@ -7513,6 +7529,7 @@
|
|
|
7513
7529
|
},
|
|
7514
7530
|
{
|
|
7515
7531
|
"name": "color",
|
|
7532
|
+
"required": false,
|
|
7516
7533
|
"description": "Loader color.",
|
|
7517
7534
|
"enum": [
|
|
7518
7535
|
"brand",
|
|
@@ -7540,9 +7557,21 @@
|
|
|
7540
7557
|
],
|
|
7541
7558
|
"value": {
|
|
7542
7559
|
"kind": "expression",
|
|
7543
|
-
"type": "
|
|
7560
|
+
"type": "union"
|
|
7544
7561
|
},
|
|
7545
7562
|
"default": "brand"
|
|
7563
|
+
},
|
|
7564
|
+
{
|
|
7565
|
+
"name": "config",
|
|
7566
|
+
"required": false,
|
|
7567
|
+
"description": "Component config object.",
|
|
7568
|
+
"enum": [
|
|
7569
|
+
"TSTypeQuery"
|
|
7570
|
+
],
|
|
7571
|
+
"value": {
|
|
7572
|
+
"kind": "expression",
|
|
7573
|
+
"type": "Partial"
|
|
7574
|
+
}
|
|
7546
7575
|
}
|
|
7547
7576
|
],
|
|
7548
7577
|
"slots": [
|
|
@@ -7562,6 +7591,7 @@
|
|
|
7562
7591
|
"attributes": [
|
|
7563
7592
|
{
|
|
7564
7593
|
"name": "color",
|
|
7594
|
+
"required": false,
|
|
7565
7595
|
"description": "Loader stripe color.",
|
|
7566
7596
|
"enum": [
|
|
7567
7597
|
"brand",
|
|
@@ -7588,27 +7618,44 @@
|
|
|
7588
7618
|
],
|
|
7589
7619
|
"value": {
|
|
7590
7620
|
"kind": "expression",
|
|
7591
|
-
"type": "
|
|
7621
|
+
"type": "union"
|
|
7592
7622
|
},
|
|
7593
7623
|
"default": "brand"
|
|
7594
7624
|
},
|
|
7595
7625
|
{
|
|
7596
7626
|
"name": "resources",
|
|
7627
|
+
"required": false,
|
|
7597
7628
|
"description": "API resource names (endpoint URIs).",
|
|
7629
|
+
"enum": [
|
|
7630
|
+
"string",
|
|
7631
|
+
"Array"
|
|
7632
|
+
],
|
|
7598
7633
|
"value": {
|
|
7599
7634
|
"kind": "expression",
|
|
7600
|
-
"type": "
|
|
7601
|
-
}
|
|
7602
|
-
"default": "\"\""
|
|
7635
|
+
"type": "union"
|
|
7636
|
+
}
|
|
7603
7637
|
},
|
|
7604
7638
|
{
|
|
7605
7639
|
"name": "loading",
|
|
7640
|
+
"required": false,
|
|
7606
7641
|
"description": "Loader state (shown / hidden).",
|
|
7607
7642
|
"value": {
|
|
7608
7643
|
"kind": "expression",
|
|
7609
7644
|
"type": "boolean"
|
|
7610
7645
|
},
|
|
7611
7646
|
"default": "false"
|
|
7647
|
+
},
|
|
7648
|
+
{
|
|
7649
|
+
"name": "config",
|
|
7650
|
+
"required": false,
|
|
7651
|
+
"description": "Component config object.",
|
|
7652
|
+
"enum": [
|
|
7653
|
+
"TSTypeQuery"
|
|
7654
|
+
],
|
|
7655
|
+
"value": {
|
|
7656
|
+
"kind": "expression",
|
|
7657
|
+
"type": "Partial"
|
|
7658
|
+
}
|
|
7612
7659
|
}
|
|
7613
7660
|
],
|
|
7614
7661
|
"source": {
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { inject, readonly, ref } from "vue";
|
|
2
|
-
|
|
3
|
-
export const LoaderOverlaySymbol = Symbol.for("vueless:loader-overlay");
|
|
4
|
-
|
|
5
|
-
const isLoading = ref(true);
|
|
6
|
-
|
|
7
|
-
function loaderOverlayOn() {
|
|
8
|
-
isLoading.value = true;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
function loaderOverlayOff() {
|
|
12
|
-
isLoading.value = false;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function createLoaderOverlay() {
|
|
16
|
-
return {
|
|
17
|
-
isLoading: readonly(isLoading),
|
|
18
|
-
loaderOverlayOn,
|
|
19
|
-
loaderOverlayOff,
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function useLoaderOverlay() {
|
|
24
|
-
return inject(LoaderOverlaySymbol);
|
|
25
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import useUI from "../composables/useUI.ts";
|
|
2
|
-
|
|
3
|
-
import defaultConfig from "./config.js";
|
|
4
|
-
|
|
5
|
-
export default function useAttrs(props) {
|
|
6
|
-
const { config, getKeysAttrs, hasSlotContent } = useUI(defaultConfig, () => props.config);
|
|
7
|
-
|
|
8
|
-
const keysAttrs = getKeysAttrs();
|
|
9
|
-
|
|
10
|
-
return {
|
|
11
|
-
config,
|
|
12
|
-
...keysAttrs,
|
|
13
|
-
hasSlotContent,
|
|
14
|
-
};
|
|
15
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { inject, readonly, ref } from "vue";
|
|
2
|
-
|
|
3
|
-
import { getRequestWithoutQuery } from "./utilLoaderProgress.js";
|
|
4
|
-
import { INFINITY_LOADING } from "./constants.js";
|
|
5
|
-
|
|
6
|
-
export const LoaderProgressSymbol = Symbol.for("vueless:loader-progress");
|
|
7
|
-
|
|
8
|
-
const isLoading = ref(false);
|
|
9
|
-
const requestQueue = ref([]);
|
|
10
|
-
const requestTimeout = ref(0);
|
|
11
|
-
|
|
12
|
-
function loaderProgressOn(url) {
|
|
13
|
-
addRequestUrl(url);
|
|
14
|
-
|
|
15
|
-
isLoading.value = true;
|
|
16
|
-
|
|
17
|
-
clearTimeout(requestTimeout.value);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function loaderProgressOff(url) {
|
|
21
|
-
removeRequestUrl(url);
|
|
22
|
-
|
|
23
|
-
requestTimeout.value = setTimeout(() => {
|
|
24
|
-
if (!requestQueue.value.length) {
|
|
25
|
-
isLoading.value = false;
|
|
26
|
-
}
|
|
27
|
-
}, 50);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function addRequestUrl(url) {
|
|
31
|
-
if (Array.isArray(url)) {
|
|
32
|
-
requestQueue.value.push(...url.map(getRequestWithoutQuery));
|
|
33
|
-
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
requestQueue.value.push(getRequestWithoutQuery(url));
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function removeRequestUrl(url) {
|
|
41
|
-
if (Array.isArray(url)) {
|
|
42
|
-
url.map(getRequestWithoutQuery).forEach(removeRequestUrl);
|
|
43
|
-
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
requestQueue.value = requestQueue.value.filter(
|
|
48
|
-
(item) => item !== getRequestWithoutQuery(url) && item !== INFINITY_LOADING,
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export function createLoaderProgress() {
|
|
53
|
-
return {
|
|
54
|
-
isLoading: isLoading,
|
|
55
|
-
requestQueue: readonly(requestQueue),
|
|
56
|
-
loaderProgressOn,
|
|
57
|
-
loaderProgressOff,
|
|
58
|
-
addRequestUrl,
|
|
59
|
-
removeRequestUrl,
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export function useLoaderProgress() {
|
|
64
|
-
return inject(LoaderProgressSymbol);
|
|
65
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
export function clamp(n, min, max) {
|
|
2
|
-
if (n < min) {
|
|
3
|
-
return min;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
if (n > max) {
|
|
7
|
-
return max;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
return n;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export const queue = (() => {
|
|
14
|
-
let pending = [];
|
|
15
|
-
|
|
16
|
-
function next() {
|
|
17
|
-
let fn = pending.shift();
|
|
18
|
-
|
|
19
|
-
if (fn) {
|
|
20
|
-
fn(next);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return (fn) => {
|
|
25
|
-
pending.push(fn);
|
|
26
|
-
|
|
27
|
-
if (pending.length === 1) {
|
|
28
|
-
next();
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
})();
|
|
32
|
-
|
|
33
|
-
export function loaderProgressOn(resource) {
|
|
34
|
-
const loaderProgressOnEvent = new CustomEvent("loaderProgressOn", { detail: { resource } });
|
|
35
|
-
|
|
36
|
-
window.dispatchEvent(loaderProgressOnEvent);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function loaderProgressOff(resource) {
|
|
40
|
-
const loaderProgressOfEvent = new CustomEvent("loaderProgressOff", { detail: { resource } });
|
|
41
|
-
|
|
42
|
-
window.dispatchEvent(loaderProgressOfEvent);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function getRequestWithoutQuery(request) {
|
|
46
|
-
const [requestWithoutQuery] = String(request).split("?");
|
|
47
|
-
|
|
48
|
-
return requestWithoutQuery;
|
|
49
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|