@anweb/nuxt-ancore 1.16.13 → 1.16.15

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "AnCore",
3
3
  "configKey": "ancore",
4
- "version": "1.16.13",
4
+ "version": "1.16.15",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
@@ -1,9 +1,9 @@
1
1
  export declare const useAnI18n: (resources?: Record<string, Record<string, string>>) => {
2
2
  t: (key: string, options?: {}) => string;
3
- readonly lang: string;
3
+ lang: import("vue").ComputedRef<string>;
4
4
  set: (value: string) => void;
5
5
  } | {
6
6
  t: import("i18next").TFunction<["translation", ...string[]], undefined>;
7
- readonly lang: string;
7
+ lang: import("vue").ComputedRef<string>;
8
8
  set: (value: string) => void;
9
9
  };
@@ -1,8 +1,7 @@
1
1
  import i18next from "i18next";
2
- import { ref } from "vue";
2
+ import { ref, computed } from "vue";
3
3
  import { useRuntimeConfig, useCookie } from "#app";
4
- const nsMap = /* @__PURE__ */ new WeakMap();
5
- let nsId = 0;
4
+ import { fnv1a } from "#imports";
6
5
  const lang = ref(i18next.language);
7
6
  export const useAnI18n = (resources) => {
8
7
  const set = (value) => {
@@ -23,12 +22,11 @@ export const useAnI18n = (resources) => {
23
22
  console.error("[AnI18n] Failed to set language:", e);
24
23
  }
25
24
  };
25
+ const langReadonly = computed(() => lang.value);
26
26
  if (resources) {
27
- let ns = nsMap.get(resources);
28
- if (!ns) {
29
- ns = `c${nsId++}`;
30
- nsMap.set(resources, ns);
31
- for (const l in resources) {
27
+ const ns = `c${fnv1a(JSON.stringify(resources))}`;
28
+ for (const l in resources) {
29
+ if (!i18next.hasResourceBundle(l, ns)) {
32
30
  try {
33
31
  i18next.addResourceBundle(l, ns, resources[l]);
34
32
  } catch (e) {
@@ -39,17 +37,13 @@ export const useAnI18n = (resources) => {
39
37
  const nsRef = ns;
40
38
  return {
41
39
  t: (key, options = {}) => i18next.t(key, { ns: [nsRef, "translation"], ...options }),
42
- get lang() {
43
- return lang.value;
44
- },
40
+ lang: langReadonly,
45
41
  set
46
42
  };
47
43
  }
48
44
  return {
49
45
  t: i18next.t,
50
- get lang() {
51
- return lang.value;
52
- },
46
+ lang: langReadonly,
53
47
  set
54
48
  };
55
49
  };
@@ -24,6 +24,7 @@ export const useAnList = (initConfig) => {
24
24
  };
25
25
  const infiniteScroll = (scrollConfig) => {
26
26
  const onLoadMore = scrollConfig?.onLoadMore || (() => {
27
+ if (!scrollConfig?.element && document.body.style.position === "fixed") return;
27
28
  if (!config.value.filter) config.value.filter = {};
28
29
  config.value.filter[config.value.skipField || "skip"] = items.length;
29
30
  });
@@ -0,0 +1 @@
1
+ export declare const fnv1a: (str: string) => number;
@@ -0,0 +1,8 @@
1
+ export const fnv1a = (str) => {
2
+ let h = 2166136261;
3
+ for (let i = 0; i < str.length; i++) {
4
+ h ^= str.charCodeAt(i);
5
+ h = Math.imul(h, 16777619);
6
+ }
7
+ return h >>> 0;
8
+ };
@@ -1,4 +1,5 @@
1
1
  export * from './asyncInit.js';
2
2
  export * from './coreApi.js';
3
+ export * from './fnv1a.js';
3
4
  export * from './toQuery.js';
4
5
  export * from './userApi.js';
@@ -1,4 +1,5 @@
1
1
  export * from "./asyncInit.js";
2
2
  export * from "./coreApi.js";
3
+ export * from "./fnv1a.js";
3
4
  export * from "./toQuery.js";
4
5
  export * from "./userApi.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anweb/nuxt-ancore",
3
- "version": "1.16.13",
3
+ "version": "1.16.15",
4
4
  "description": "AnCore Nuxt module",
5
5
  "repository": "https://github.com/ANLTD/ancore",
6
6
  "license": "MIT",