@anweb/nuxt-ancore 1.14.3 → 1.15.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/module.json +1 -1
- package/dist/runtime/components/An/Dialogs/Dialogs.vue +19 -0
- package/dist/runtime/components/An/Dialogs/Dialogs.vue.d.ts +2 -0
- package/dist/runtime/components/An/Dialogs/Item.vue +81 -0
- package/dist/runtime/components/An/Dialogs/Item.vue.d.ts +2 -0
- package/dist/runtime/composables/useAnDialogs.d.ts +7 -0
- package/dist/runtime/composables/useAnDialogs.js +31 -0
- package/dist/runtime/types/dialogs.d.ts +9 -0
- package/dist/runtime/types/dialogs.js +0 -0
- package/dist/runtime/types/index.d.ts +1 -0
- package/dist/runtime/types/index.js +1 -0
- package/package.json +3 -2
package/dist/module.json
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { useScrollLock } from "@vueuse/core";
|
|
3
|
+
import { watch } from "vue";
|
|
4
|
+
import { useAnDialogs } from "#imports";
|
|
5
|
+
import { AnDialogsItem } from "#components";
|
|
6
|
+
const Dialogs = useAnDialogs();
|
|
7
|
+
const isLocked = useScrollLock(window);
|
|
8
|
+
watch(() => Dialogs.items.length, (value) => {
|
|
9
|
+
isLocked.value = !!value;
|
|
10
|
+
});
|
|
11
|
+
</script>
|
|
12
|
+
|
|
13
|
+
<template>
|
|
14
|
+
<AnDialogsItem
|
|
15
|
+
v-for="dialog of Dialogs.items"
|
|
16
|
+
:key="dialog.id"
|
|
17
|
+
:dialog="dialog"
|
|
18
|
+
/>
|
|
19
|
+
</template>
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { computed, ref, onMounted } from "vue";
|
|
3
|
+
import {
|
|
4
|
+
onClickOutside,
|
|
5
|
+
useSwipe,
|
|
6
|
+
useElementSize,
|
|
7
|
+
useScroll
|
|
8
|
+
} from "@vueuse/core";
|
|
9
|
+
import { useAnDialogs, useTemplateRef } from "#imports";
|
|
10
|
+
const props = defineProps({
|
|
11
|
+
dialog: { type: Object, required: true }
|
|
12
|
+
});
|
|
13
|
+
const Dialogs = useAnDialogs();
|
|
14
|
+
const refDialog = useTemplateRef("refDialog");
|
|
15
|
+
let Scroll;
|
|
16
|
+
let Swipe;
|
|
17
|
+
let ElementSize;
|
|
18
|
+
const top = ref(0);
|
|
19
|
+
const active = ref(false);
|
|
20
|
+
const target = ref(null);
|
|
21
|
+
let raf = 0;
|
|
22
|
+
const onSwipeStart = () => {
|
|
23
|
+
active.value = canSwipe.value;
|
|
24
|
+
};
|
|
25
|
+
const onSwipe = () => {
|
|
26
|
+
if (!active.value) return;
|
|
27
|
+
cancelAnimationFrame(raf);
|
|
28
|
+
raf = requestAnimationFrame(() => {
|
|
29
|
+
top.value = Math.max(0, -Swipe.lengthY.value);
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
const onSwipeEnd = () => {
|
|
33
|
+
if (Math.abs(top.value) > ElementSize.height.value / 2) {
|
|
34
|
+
Dialogs.close(props.dialog);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
top.value = 0;
|
|
38
|
+
active.value = false;
|
|
39
|
+
};
|
|
40
|
+
const config = computed(() => {
|
|
41
|
+
return {
|
|
42
|
+
...props.dialog,
|
|
43
|
+
...refDialog.value?.config ? refDialog.value.config : {}
|
|
44
|
+
};
|
|
45
|
+
});
|
|
46
|
+
const canSwipe = computed(() => Scroll.arrivedState.top && !config.value.fullscreen);
|
|
47
|
+
onMounted(() => {
|
|
48
|
+
target.value = refDialog.value?.$el || null;
|
|
49
|
+
if (!config.value.fullscreen) {
|
|
50
|
+
onClickOutside(refDialog, () => Dialogs.close(props.dialog));
|
|
51
|
+
}
|
|
52
|
+
Swipe = useSwipe(target, {
|
|
53
|
+
onSwipeStart,
|
|
54
|
+
onSwipe,
|
|
55
|
+
onSwipeEnd,
|
|
56
|
+
threshold: 0
|
|
57
|
+
});
|
|
58
|
+
Scroll = useScroll(target);
|
|
59
|
+
ElementSize = useElementSize(target);
|
|
60
|
+
});
|
|
61
|
+
</script>
|
|
62
|
+
|
|
63
|
+
<template>
|
|
64
|
+
<div
|
|
65
|
+
class="dialog -flex -flex__column"
|
|
66
|
+
:class="[{ '-fullscreen': config.fullscreen }, config.class]"
|
|
67
|
+
>
|
|
68
|
+
<component
|
|
69
|
+
ref="refDialog"
|
|
70
|
+
:is="props.dialog.component"
|
|
71
|
+
:params="props.dialog.params"
|
|
72
|
+
class="dialog__component"
|
|
73
|
+
:style="{ transform: `translateY(${top}px)` }"
|
|
74
|
+
@close="Dialogs.close(props.dialog)"
|
|
75
|
+
/>
|
|
76
|
+
</div>
|
|
77
|
+
</template>
|
|
78
|
+
|
|
79
|
+
<style scoped>
|
|
80
|
+
.dialog{--an-dialogs-background:inherit;--an-dialogs-close:inherit;--an-dialogs-backdrop-filter:inherit;box-sizing:border-box;height:100%;left:0;position:fixed;top:0;width:100%;z-index:200}.dialog:not(.-fullscreen){align-items:center;backdrop-filter:var(--an-dialogs-backdrop-filter,blur(6px));-webkit-backdrop-filter:var(--an-dialogs-backdrop-filter,blur(6px));background:var(--an-dialogs-background,rgba(0,0,0,.3));display:flex;justify-content:center}@media (width < 768px){.dialog:not(.-fullscreen) .dialog__component{margin-top:auto;max-height:calc(100vh - 48px);position:relative;width:100%}.dialog:not(.-fullscreen) .dialog__component:before{background:var(--an-dialogs-close,rgba(0,0,0,.5));border-radius:100px;content:"";display:block;height:4px;margin:10px auto;width:50px}}@media (width >= 768px){.dialog:not(.-fullscreen) .dialog__component{margin:auto}}.dialog.-fullscreen .dialog__component{height:100%;width:100%}.dialog__component{box-sizing:border-box;overflow-y:scroll;position:relative;-ms-overflow-style:none;scrollbar-width:none}
|
|
81
|
+
</style>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { TDialog } from '#ancore/types';
|
|
2
|
+
export declare const useAnDialogs: () => {
|
|
3
|
+
open: (component: any, params?: Record<string, unknown>, config?: Partial<TDialog>) => TDialog;
|
|
4
|
+
close: (dialog: TDialog) => void;
|
|
5
|
+
closeAll: () => void;
|
|
6
|
+
items: TDialog[];
|
|
7
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { v4 } from "uuid";
|
|
2
|
+
import { useState } from "#app";
|
|
3
|
+
import { markRaw } from "vue";
|
|
4
|
+
export const useAnDialogs = () => {
|
|
5
|
+
const StateDialogs = useState("an-dialogs", () => []);
|
|
6
|
+
const open = (component, params = {}, config = {}) => {
|
|
7
|
+
const data = {
|
|
8
|
+
...config,
|
|
9
|
+
id: v4(),
|
|
10
|
+
component: markRaw(component),
|
|
11
|
+
params
|
|
12
|
+
};
|
|
13
|
+
StateDialogs.value.push(data);
|
|
14
|
+
return data;
|
|
15
|
+
};
|
|
16
|
+
const close = (dialog) => {
|
|
17
|
+
StateDialogs.value.splice(StateDialogs.value.indexOf(dialog), 1);
|
|
18
|
+
if (dialog.onClose) dialog.onClose();
|
|
19
|
+
};
|
|
20
|
+
const closeAll = () => {
|
|
21
|
+
while (StateDialogs.value.length) {
|
|
22
|
+
StateDialogs.value[0] && close(StateDialogs.value[0]);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
return {
|
|
26
|
+
open,
|
|
27
|
+
close,
|
|
28
|
+
closeAll,
|
|
29
|
+
items: StateDialogs.value
|
|
30
|
+
};
|
|
31
|
+
};
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anweb/nuxt-ancore",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.15.0",
|
|
4
4
|
"description": "AnCore Nuxt module",
|
|
5
5
|
"repository": "https://github.com/ANLTD/ancore",
|
|
6
6
|
"license": "MIT",
|
|
@@ -36,7 +36,8 @@
|
|
|
36
36
|
"@vueuse/core": "^14.1.0",
|
|
37
37
|
"@vueuse/integrations": "^14.1.0",
|
|
38
38
|
"async-validator": "^4.2.5",
|
|
39
|
-
"i18next": "^25.6.3"
|
|
39
|
+
"i18next": "^25.6.3",
|
|
40
|
+
"uuid": "^13.0.0"
|
|
40
41
|
},
|
|
41
42
|
"devDependencies": {
|
|
42
43
|
"@nuxt/devtools": "^3.1.1",
|