@anweb/nuxt-ancore 1.16.1 → 1.16.3
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.d.mts +7 -2
- package/dist/module.d.ts +7 -2
- package/dist/module.json +1 -1
- package/dist/runtime/components/An/Dialogs/Dialogs.vue +26 -7
- package/dist/runtime/components/An/Dropdown.vue +1 -2
- package/dist/runtime/composables/useAnData.d.ts +9 -10
- package/dist/runtime/composables/useAnData.js +21 -6
- package/dist/runtime/composables/useAnDialogs.js +1 -2
- package/dist/runtime/composables/useAnI18n.js +10 -6
- package/dist/runtime/composables/useAnList.d.ts +10 -11
- package/dist/runtime/composables/useAnList.js +28 -14
- package/dist/runtime/types/global.d.ts +1 -1
- package/package.json +12 -12
package/dist/module.d.mts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
|
-
import {
|
|
2
|
+
import { InitOptions } from 'i18next';
|
|
3
3
|
|
|
4
4
|
interface ModuleOptions {
|
|
5
5
|
api?: string;
|
|
6
|
-
i18n?:
|
|
6
|
+
i18n?: InitOptions<unknown> & {
|
|
7
|
+
cookie?: string;
|
|
8
|
+
resources?: Record<string, {
|
|
9
|
+
translation: string | Record<string, unknown>;
|
|
10
|
+
}>;
|
|
11
|
+
};
|
|
7
12
|
}
|
|
8
13
|
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
9
14
|
|
package/dist/module.d.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
|
-
import {
|
|
2
|
+
import { InitOptions } from 'i18next';
|
|
3
3
|
|
|
4
4
|
interface ModuleOptions {
|
|
5
5
|
api?: string;
|
|
6
|
-
i18n?:
|
|
6
|
+
i18n?: InitOptions<unknown> & {
|
|
7
|
+
cookie?: string;
|
|
8
|
+
resources?: Record<string, {
|
|
9
|
+
translation: string | Record<string, unknown>;
|
|
10
|
+
}>;
|
|
11
|
+
};
|
|
7
12
|
}
|
|
8
13
|
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
9
14
|
|
package/dist/module.json
CHANGED
|
@@ -1,12 +1,34 @@
|
|
|
1
1
|
<script setup>
|
|
2
|
-
import {
|
|
2
|
+
import { watch } from "vue";
|
|
3
3
|
import { useAnDialogs } from "#imports";
|
|
4
4
|
import { AnDialogsItem } from "#components";
|
|
5
5
|
const Dialogs = useAnDialogs();
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
6
|
+
let scrollY = 0;
|
|
7
|
+
const lockScroll = () => {
|
|
8
|
+
scrollY = window.scrollY;
|
|
9
|
+
document.documentElement.style.overflowY = "scroll";
|
|
10
|
+
document.body.style.position = "fixed";
|
|
11
|
+
document.body.style.top = `-${scrollY}px`;
|
|
12
|
+
document.body.style.left = "0";
|
|
13
|
+
document.body.style.width = "100%";
|
|
9
14
|
};
|
|
15
|
+
const unlockScroll = () => {
|
|
16
|
+
document.body.style.position = "";
|
|
17
|
+
document.body.style.top = "";
|
|
18
|
+
document.body.style.left = "";
|
|
19
|
+
document.body.style.width = "";
|
|
20
|
+
document.documentElement.style.overflowY = "";
|
|
21
|
+
window.scrollTo(0, scrollY);
|
|
22
|
+
};
|
|
23
|
+
if (import.meta.client) {
|
|
24
|
+
watch(
|
|
25
|
+
() => Dialogs.items.length,
|
|
26
|
+
(count, prev) => {
|
|
27
|
+
if (count > 0 && (!prev || prev === 0)) lockScroll();
|
|
28
|
+
else if (count === 0 && prev && prev > 0) unlockScroll();
|
|
29
|
+
}
|
|
30
|
+
);
|
|
31
|
+
}
|
|
10
32
|
</script>
|
|
11
33
|
|
|
12
34
|
<template>
|
|
@@ -15,9 +37,6 @@ const onAnimation = () => {
|
|
|
15
37
|
name="an-dialogs"
|
|
16
38
|
tag="div"
|
|
17
39
|
aria-live="polite"
|
|
18
|
-
|
|
19
|
-
@before-enter="onAnimation"
|
|
20
|
-
@after-leave="onAnimation"
|
|
21
40
|
>
|
|
22
41
|
<AnDialogsItem
|
|
23
42
|
v-for="dialog of Dialogs.items"
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
<script setup>
|
|
2
|
-
import { v4 } from "uuid";
|
|
3
2
|
import { computed, onMounted, ref, useTemplateRef } from "vue";
|
|
4
3
|
import { onClickOutside, useEventListener } from "@vueuse/core";
|
|
5
4
|
const props = defineProps({
|
|
@@ -25,7 +24,7 @@ const name = computed(() => {
|
|
|
25
24
|
});
|
|
26
25
|
const menuId = computed(() => id.value ? `an-dropdown-menu-${id.value}` : void 0);
|
|
27
26
|
onMounted(() => {
|
|
28
|
-
id.value =
|
|
27
|
+
id.value = crypto.randomUUID();
|
|
29
28
|
});
|
|
30
29
|
onClickOutside(refTarget, close);
|
|
31
30
|
useEventListener(document, "keydown", onKeydown);
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type { NitroFetchOptions, NitroFetchRequest } from 'nitropack';
|
|
2
|
-
import { type Ref, type ComputedRef } from 'vue';
|
|
1
|
+
import type { NitroFetchOptions, NitroFetchRequest, TypedInternalResponse } from 'nitropack';
|
|
3
2
|
import { type AsyncDataRequestStatus } from '#app';
|
|
4
|
-
interface TConfig {
|
|
5
|
-
request:
|
|
3
|
+
interface TConfig<Route extends NitroFetchRequest = NitroFetchRequest> {
|
|
4
|
+
request: Route;
|
|
6
5
|
apiConfig?: NitroFetchOptions<string>;
|
|
7
6
|
params: Record<string, unknown>;
|
|
8
7
|
}
|
|
@@ -10,12 +9,12 @@ interface TUseAnData<TData, TError> {
|
|
|
10
9
|
init: () => Promise<void>;
|
|
11
10
|
set: (data: TData) => void;
|
|
12
11
|
refresh: () => void;
|
|
13
|
-
config:
|
|
12
|
+
config: TConfig;
|
|
14
13
|
params: TConfig['params'];
|
|
15
|
-
data:
|
|
16
|
-
status:
|
|
17
|
-
loading:
|
|
18
|
-
error:
|
|
14
|
+
readonly data: TData | undefined;
|
|
15
|
+
readonly status: AsyncDataRequestStatus;
|
|
16
|
+
readonly loading: boolean;
|
|
17
|
+
readonly error: TError | undefined;
|
|
19
18
|
}
|
|
20
|
-
export declare const useAnData: <TData =
|
|
19
|
+
export declare const useAnData: <TData = void, TError = unknown, Route extends NitroFetchRequest = NitroFetchRequest, _TData = TData extends void ? TypedInternalResponse<Route, unknown, "get"> : TData>(initConfig: Omit<TConfig<Route>, "params"> & Partial<Pick<TConfig<Route>, "params">>) => TUseAnData<_TData, TError>;
|
|
21
20
|
export {};
|
|
@@ -64,12 +64,27 @@ export const useAnData = (initConfig) => {
|
|
|
64
64
|
return {
|
|
65
65
|
init,
|
|
66
66
|
set,
|
|
67
|
-
refresh: () =>
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
refresh: () => {
|
|
68
|
+
time.value = Date.now();
|
|
69
|
+
},
|
|
70
|
+
get data() {
|
|
71
|
+
return data.value;
|
|
72
|
+
},
|
|
73
|
+
get config() {
|
|
74
|
+
return config.value;
|
|
75
|
+
},
|
|
76
|
+
set config(val) {
|
|
77
|
+
config.value = val;
|
|
78
|
+
},
|
|
70
79
|
params: config.value.params,
|
|
71
|
-
status
|
|
72
|
-
|
|
73
|
-
|
|
80
|
+
get status() {
|
|
81
|
+
return status.value;
|
|
82
|
+
},
|
|
83
|
+
get loading() {
|
|
84
|
+
return loading.value || status.value === "idle";
|
|
85
|
+
},
|
|
86
|
+
get error() {
|
|
87
|
+
return error.value;
|
|
88
|
+
}
|
|
74
89
|
};
|
|
75
90
|
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { v4 } from "uuid";
|
|
2
1
|
import { useState } from "#app";
|
|
3
2
|
import { markRaw } from "vue";
|
|
4
3
|
export const useAnDialogs = () => {
|
|
@@ -6,7 +5,7 @@ export const useAnDialogs = () => {
|
|
|
6
5
|
const open = (component, params = {}, config = {}) => {
|
|
7
6
|
const data = {
|
|
8
7
|
...config,
|
|
9
|
-
id:
|
|
8
|
+
id: crypto.randomUUID(),
|
|
10
9
|
component: markRaw(component),
|
|
11
10
|
params
|
|
12
11
|
};
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import i18next from "i18next";
|
|
2
2
|
import { useRuntimeConfig, useCookie } from "#app";
|
|
3
|
+
const nsMap = /* @__PURE__ */ new WeakMap();
|
|
4
|
+
let nsId = 0;
|
|
3
5
|
export const useAnI18n = (resources) => {
|
|
4
6
|
const returnObj = {
|
|
5
7
|
lang: i18next.language,
|
|
@@ -23,14 +25,16 @@ export const useAnI18n = (resources) => {
|
|
|
23
25
|
}
|
|
24
26
|
};
|
|
25
27
|
if (!resources) return { t: i18next.t, ...returnObj };
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
let ns = nsMap.get(resources);
|
|
29
|
+
if (!ns) {
|
|
30
|
+
ns = `c${nsId++}`;
|
|
31
|
+
nsMap.set(resources, ns);
|
|
32
|
+
for (const lang in resources) {
|
|
33
|
+
try {
|
|
30
34
|
i18next.addResourceBundle(lang, ns, resources[lang]);
|
|
35
|
+
} catch (e) {
|
|
36
|
+
console.error(`[AnI18n] Failed to add resource bundle for ${lang}:`, e);
|
|
31
37
|
}
|
|
32
|
-
} catch (e) {
|
|
33
|
-
console.error(`[AnI18n] Failed to add resource bundle for ${lang}:`, e);
|
|
34
38
|
}
|
|
35
39
|
}
|
|
36
40
|
const t = (key, options = {}) => i18next.t(key, { ns: [ns, "translation"], ...options });
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { NitroFetchOptions, NitroFetchRequest } from 'nitropack';
|
|
2
|
-
import {
|
|
3
|
-
import type { TInfiniteScroll } from '#ancore/types';
|
|
1
|
+
import type { NitroFetchOptions, NitroFetchRequest, TypedInternalResponse } from 'nitropack';
|
|
2
|
+
import type { TInfiniteScroll, TResponseList } from '#ancore/types';
|
|
4
3
|
import { type AsyncDataRequestStatus } from '#app';
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
type ExtractListItem<T> = T extends TResponseList<infer U> ? U : unknown;
|
|
5
|
+
interface TConfig<TFilter, Route extends NitroFetchRequest = NitroFetchRequest> {
|
|
6
|
+
request: Route;
|
|
7
7
|
apiConfig?: NitroFetchOptions<string>;
|
|
8
8
|
filter?: TFilter;
|
|
9
9
|
params?: Record<string, string>;
|
|
@@ -16,11 +16,10 @@ interface TUseAnList<TData, TFilter> {
|
|
|
16
16
|
filter: TFilter;
|
|
17
17
|
params: Record<string, string> | undefined;
|
|
18
18
|
items: TData[];
|
|
19
|
-
count:
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
error: Readonly<Ref<unknown | undefined>>;
|
|
19
|
+
readonly count: number | null;
|
|
20
|
+
readonly status: AsyncDataRequestStatus;
|
|
21
|
+
readonly loading: boolean;
|
|
22
|
+
readonly error: unknown | undefined;
|
|
24
23
|
}
|
|
25
|
-
export declare const useAnList: <TData, TFilter extends object = {}>(initConfig: TConfig<TFilter>) => TUseAnList<
|
|
24
|
+
export declare const useAnList: <TData = void, TFilter extends object = {}, Route extends NitroFetchRequest = NitroFetchRequest, _TData = TData extends void ? ExtractListItem<TypedInternalResponse<Route, unknown, "get">> : TData>(initConfig: TConfig<TFilter, Route>) => TUseAnList<_TData, TFilter>;
|
|
26
25
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ref, reactive, watch
|
|
1
|
+
import { ref, reactive, watch } from "vue";
|
|
2
2
|
import { useInfiniteScroll } from "@vueuse/core";
|
|
3
3
|
import { useAnData } from "#imports";
|
|
4
4
|
export const useAnList = (initConfig) => {
|
|
@@ -10,17 +10,17 @@ export const useAnList = (initConfig) => {
|
|
|
10
10
|
await refresh();
|
|
11
11
|
};
|
|
12
12
|
const refresh = () => {
|
|
13
|
-
if (!data.data
|
|
13
|
+
if (!data.data) return;
|
|
14
14
|
if (!config.value.apiConfig?.query?.[config.value.skipField || "skip"]) {
|
|
15
15
|
count.value = null;
|
|
16
16
|
items.length = 0;
|
|
17
17
|
}
|
|
18
18
|
if (config.value.reverse) {
|
|
19
|
-
items.unshift(...data.data.
|
|
19
|
+
items.unshift(...data.data.items);
|
|
20
20
|
} else {
|
|
21
|
-
items.push(...data.data.
|
|
21
|
+
items.push(...data.data.items);
|
|
22
22
|
}
|
|
23
|
-
count.value = data.data.
|
|
23
|
+
count.value = data.data.count;
|
|
24
24
|
};
|
|
25
25
|
const infiniteScroll = (scrollConfig) => {
|
|
26
26
|
const onLoadMore = scrollConfig?.onLoadMore || (() => {
|
|
@@ -28,7 +28,7 @@ export const useAnList = (initConfig) => {
|
|
|
28
28
|
config.value.filter[config.value.skipField || "skip"] = items.length;
|
|
29
29
|
});
|
|
30
30
|
const canLoadMore = scrollConfig?.options?.canLoadMore || (() => {
|
|
31
|
-
return (scrollConfig?.canLoadMore?.() ?? true) &&
|
|
31
|
+
return (scrollConfig?.canLoadMore?.() ?? true) && data.status !== "idle" && data.status !== "pending" && items.length < (count.value || 0) && !!config.value.filter?.limit;
|
|
32
32
|
});
|
|
33
33
|
const { reset } = useInfiniteScroll(
|
|
34
34
|
scrollConfig?.element || window,
|
|
@@ -40,7 +40,6 @@ export const useAnList = (initConfig) => {
|
|
|
40
40
|
);
|
|
41
41
|
return reset;
|
|
42
42
|
};
|
|
43
|
-
const inited = computed(() => data.status.value !== "idle");
|
|
44
43
|
if (!config.value.apiConfig) {
|
|
45
44
|
config.value.apiConfig = {};
|
|
46
45
|
}
|
|
@@ -50,17 +49,32 @@ export const useAnList = (initConfig) => {
|
|
|
50
49
|
apiConfig: config.value.apiConfig,
|
|
51
50
|
params: config.value.params
|
|
52
51
|
});
|
|
53
|
-
watch(data.data, refresh);
|
|
52
|
+
watch(() => data.data, refresh);
|
|
54
53
|
return {
|
|
55
54
|
init,
|
|
56
55
|
infiniteScroll,
|
|
57
|
-
filter
|
|
56
|
+
get filter() {
|
|
57
|
+
return config.value.filter;
|
|
58
|
+
},
|
|
59
|
+
set filter(val) {
|
|
60
|
+
config.value.filter = val;
|
|
61
|
+
if (config.value.apiConfig) {
|
|
62
|
+
config.value.apiConfig.query = val;
|
|
63
|
+
}
|
|
64
|
+
},
|
|
58
65
|
params: config.value.params,
|
|
59
66
|
items,
|
|
60
|
-
count
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
67
|
+
get count() {
|
|
68
|
+
return count.value;
|
|
69
|
+
},
|
|
70
|
+
get status() {
|
|
71
|
+
return data.status;
|
|
72
|
+
},
|
|
73
|
+
get loading() {
|
|
74
|
+
return data.loading;
|
|
75
|
+
},
|
|
76
|
+
get error() {
|
|
77
|
+
return data.error;
|
|
78
|
+
}
|
|
65
79
|
};
|
|
66
80
|
};
|
|
@@ -14,7 +14,7 @@ declare module 'nuxt/schema' {
|
|
|
14
14
|
interface PublicRuntimeConfig {
|
|
15
15
|
i18n?: InitOptions<unknown> & {
|
|
16
16
|
cookie?: string
|
|
17
|
-
resources?: Record<string, { translation:
|
|
17
|
+
resources?: Record<string, { translation: Record<string, unknown> }>
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anweb/nuxt-ancore",
|
|
3
|
-
"version": "1.16.
|
|
3
|
+
"version": "1.16.3",
|
|
4
4
|
"description": "AnCore Nuxt module",
|
|
5
5
|
"repository": "https://github.com/ANLTD/ancore",
|
|
6
6
|
"license": "MIT",
|
|
@@ -27,25 +27,25 @@
|
|
|
27
27
|
"dev": "npm run dev:prepare && nuxi dev playground",
|
|
28
28
|
"dev:build": "nuxi build playground",
|
|
29
29
|
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
|
|
30
|
-
"release:patch": "npm run prepack && changelogen --patch --release && npm publish --access public && git push --follow-tags",
|
|
31
|
-
"release:minor": "npm run prepack && changelogen --minor --release && npm publish --access public && git push --follow-tags",
|
|
32
|
-
"release:major": "npm run prepack && changelogen --major --release && npm publish --access public && git push --follow-tags"
|
|
30
|
+
"release:patch": "npm run prepack && changelogen --patch --release && npm login && npm publish --access public && git push --follow-tags",
|
|
31
|
+
"release:minor": "npm run prepack && changelogen --minor --release && npm login && npm publish --access public && git push --follow-tags",
|
|
32
|
+
"release:major": "npm run prepack && changelogen --major --release && npm login && npm publish --access public && git push --follow-tags",
|
|
33
|
+
"update": "npx -y npm-check-updates -u"
|
|
33
34
|
},
|
|
34
35
|
"dependencies": {
|
|
35
|
-
"@vueuse/core": "^14.2.
|
|
36
|
-
"@vueuse/integrations": "^14.2.
|
|
36
|
+
"@vueuse/core": "^14.2.1",
|
|
37
|
+
"@vueuse/integrations": "^14.2.1",
|
|
37
38
|
"async-validator": "^4.2.5",
|
|
38
|
-
"i18next": "^25.8.
|
|
39
|
-
"uuid": "^13.0.0"
|
|
39
|
+
"i18next": "^25.8.17"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@nuxt/devtools": "^3.
|
|
43
|
-
"@nuxt/kit": "^4.3.
|
|
42
|
+
"@nuxt/devtools": "^3.2.3",
|
|
43
|
+
"@nuxt/kit": "^4.3.1",
|
|
44
44
|
"@nuxt/module-builder": "^1.0.2",
|
|
45
|
-
"@nuxt/schema": "^4.3.
|
|
45
|
+
"@nuxt/schema": "^4.3.1",
|
|
46
46
|
"@types/node": "latest",
|
|
47
47
|
"changelogen": "^0.6.2",
|
|
48
|
-
"nuxt": "^4.3.
|
|
48
|
+
"nuxt": "^4.3.1",
|
|
49
49
|
"typescript": "~5.9.3"
|
|
50
50
|
}
|
|
51
51
|
}
|