@lacqjs/nuxt-dict 0.0.3 → 0.0.4

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/README.md CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  <p align="center">
3
2
  <h1 align="center">@lacqjs/nuxt-dict</h1>
4
3
  </p>
@@ -26,7 +25,7 @@ pnpm add @lacqjs/nuxt-dict
26
25
  // nuxt.config.ts
27
26
  export default defineNuxtConfig({
28
27
  modules: ['@lacqjs/nuxt-dict'],
29
- })
28
+ });
30
29
  ```
31
30
 
32
31
  ```vue
@@ -37,8 +36,8 @@ export default defineNuxtConfig({
37
36
  </template>
38
37
 
39
38
  <script setup lang="ts">
40
- const { data: options } = useDict('gender')
41
- const value = ref('')
39
+ const { data: options } = useDict('gender');
40
+ const value = ref('');
42
41
  </script>
43
42
  ```
44
43
 
package/dist/module.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lacqjs/nuxt-dict",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "configKey": "dict",
5
5
  "compatibility": {
6
6
  "nuxt": "^4.4.8"
package/dist/module.mjs CHANGED
@@ -1,11 +1,10 @@
1
- import { fileURLToPath } from 'url';
2
1
  import { defineNuxtModule, useLogger, createResolver, addPlugin, addImportsDir, addTypeTemplate } from '@nuxt/kit';
3
2
  import { defaultOptions } from '../dist/runtime/options.js';
4
3
  import { createLogger } from '../dist/runtime/utils/logger.js';
5
4
  export { createDictTranslator } from '../dist/runtime/utils/dict-translator.js';
6
5
 
7
6
  const name = "@lacqjs/nuxt-dict";
8
- const version = "0.0.3";
7
+ const version = "0.0.4";
9
8
  const devDependencies = {
10
9
  nuxt: "^4.4.8"};
11
10
  const pkg = {
@@ -181,11 +180,10 @@ const module$1 = defineNuxtModule().with({
181
180
  return;
182
181
  }
183
182
  const resolver = createResolver(import.meta.url);
184
- const runtimeDir = fileURLToPath(new URL("./runtime", import.meta.url));
185
183
  _nuxt.options.runtimeConfig.public.dict = _options;
186
- _nuxt.options.build.transpile.push(resolver.resolve(runtimeDir));
187
- addPlugin({ src: resolver.resolve(runtimeDir, "plugins", "dict.ts") });
188
- addImportsDir(resolver.resolve(runtimeDir, "composables"));
184
+ _nuxt.options.build.transpile.push(resolver.resolve("./runtime"));
185
+ addPlugin(resolver.resolve("./runtime/plugins/dict"));
186
+ addImportsDir(resolver.resolve("./runtime/composables"));
189
187
  registerTypeTemplates(resolver, _options.stores);
190
188
  _nuxt.hook("prepare:types", ({ references }) => {
191
189
  references.push({ types: pkg.name });
@@ -77,5 +77,12 @@ export function useDict(storeOrType, maybeType) {
77
77
  fetchDictData(manager, dictType, storeName, data, loading, error, "load", itemMap);
78
78
  }
79
79
  );
80
- return { data, translate, getDictItem, loading, error, refresh };
80
+ return {
81
+ data,
82
+ translate,
83
+ getDictItem,
84
+ loading,
85
+ error,
86
+ refresh
87
+ };
81
88
  }
@@ -47,7 +47,13 @@ export function useDictTree(storeOrType, maybeType) {
47
47
  }
48
48
  onMounted(load);
49
49
  watch(() => manager.locale.value, load);
50
- return { tree, translate, findPath, loading, refresh };
50
+ return {
51
+ tree,
52
+ translate,
53
+ findPath,
54
+ loading,
55
+ refresh
56
+ };
51
57
  }
52
58
  function buildMaps(nodes, nodeMap, pathMap, ancestors = []) {
53
59
  for (const node of nodes) {
@@ -20,7 +20,9 @@ async function fetchDictImpl(_storeName, config, types, locale) {
20
20
  }
21
21
  return response.json();
22
22
  } catch (e) {
23
- throw new Error(`Failed to fetch dictionary: ${e instanceof Error ? e.message : String(e)}`, { cause: e });
23
+ throw new Error(`Failed to fetch dictionary: ${e instanceof Error ? e.message : String(e)}`, {
24
+ cause: e
25
+ });
24
26
  }
25
27
  }
26
28
  async function fetchVersionImpl(_storeName, config) {
@@ -36,7 +38,9 @@ async function fetchVersionImpl(_storeName, config) {
36
38
  }
37
39
  return data.version;
38
40
  } catch (e) {
39
- throw new Error(`Failed to fetch version: ${e instanceof Error ? e.message : String(e)}`, { cause: e });
41
+ throw new Error(`Failed to fetch version: ${e instanceof Error ? e.message : String(e)}`, {
42
+ cause: e
43
+ });
40
44
  }
41
45
  }
42
46
  export function createDefaultAdapter(options) {
@@ -27,7 +27,9 @@ export class IndexedDBCache {
27
27
  resolve();
28
28
  });
29
29
  request.addEventListener("error", () => {
30
- reject(new Error("Failed to open IndexedDB: " + (request.error?.message || "unknown error")));
30
+ reject(
31
+ new Error("Failed to open IndexedDB: " + (request.error?.message || "unknown error"))
32
+ );
31
33
  });
32
34
  request.addEventListener("blocked", () => {
33
35
  reject(new Error("IndexedDB is blocked by another tab"));
@@ -1,5 +1,5 @@
1
- import { IndexedDBCache } from './cache/indexeddb-cache.js';
2
1
  import type { DictAdapter, DictEntry, DictItem, TranslateOptions, TranslatePathOptions, GetDictItemOptions } from '../types/index.js';
2
+ import { IndexedDBCache } from './cache/indexeddb-cache.js';
3
3
  /**
4
4
  * DictManager 构造参数。
5
5
  *
@@ -1,6 +1,6 @@
1
1
  import { shallowRef } from "vue";
2
- import { MemoryCache } from "./cache/memory-cache.js";
3
2
  import { DEFAULT_STORE_NAME } from "./cache/indexeddb-cache.js";
3
+ import { MemoryCache } from "./cache/memory-cache.js";
4
4
  import { VersionCheck } from "./cache/version-check.js";
5
5
  export class DictManager {
6
6
  memoryCache;
@@ -1,11 +1,11 @@
1
1
  import { watch } from "vue";
2
2
  import { defineNuxtPlugin, useRequestEvent, useCookie, useRoute } from "#imports";
3
- import { DictManager } from "../core/dict-manager.js";
4
- import { IndexedDBCache, DEFAULT_STORE_NAME } from "../core/cache/indexeddb-cache.js";
5
3
  import { createDefaultAdapter } from "../core/adapter.js";
4
+ import { IndexedDBCache, DEFAULT_STORE_NAME } from "../core/cache/indexeddb-cache.js";
5
+ import { DictManager } from "../core/dict-manager.js";
6
+ import { defaultOptions } from "../options.js";
6
7
  import { createDictTranslator } from "../utils/dict-translator.js";
7
8
  import { createLogger } from "../utils/logger.js";
8
- import { defaultOptions } from "../options.js";
9
9
  function resolveServerLocale(options) {
10
10
  const event = useRequestEvent();
11
11
  if (!event) return options.locale.default;
@@ -78,7 +78,9 @@ function createAdapters(options, logger) {
78
78
  apiHeaderKey: options.locale.apiHeaderKey
79
79
  });
80
80
  adapters.set(DEFAULT_STORE_NAME, defaultAdapter);
81
- logger.debug(`Dict adapter created for default store '${DEFAULT_STORE_NAME}': ${options.api.baseURL}${options.api.dictEndpoint}`);
81
+ logger.debug(
82
+ `Dict adapter created for default store '${DEFAULT_STORE_NAME}': ${options.api.baseURL}${options.api.dictEndpoint}`
83
+ );
82
84
  for (const [storeName, storeApi] of Object.entries(options.stores)) {
83
85
  const adapter = storeApi.adapter ?? createDefaultAdapter({
84
86
  baseURL: resolveBaseURL(storeApi.baseURL ?? options.api.baseURL),
package/package.json CHANGED
@@ -1,22 +1,21 @@
1
1
  {
2
2
  "name": "@lacqjs/nuxt-dict",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "Nuxt 数据字典模块,提供扁平/树形字典翻译、多语言国际化、三级缓存与 SSR 预取。",
5
5
  "keywords": [
6
6
  "@lacqjs/nuxt-dict",
7
+ "dict",
7
8
  "nuxt",
8
- "nuxt-dict",
9
- "dict"
9
+ "nuxt-dict"
10
10
  ],
11
+ "homepage": "https://miaozhongfei.github.io/nuxt-dict/",
11
12
  "license": "MIT",
12
13
  "author": {
13
14
  "name": "miaozhongfei",
14
15
  "email": "miaozhongfei@example.com"
15
16
  },
16
- "repository": "miaozhongfei/nuxt-dict",
17
- "homepage": "https://miaozhongfei.github.io/nuxt-dict/",
18
- "documentation": "https://miaozhongfei.github.io/nuxt-dict/",
19
17
  "contributors": [],
18
+ "repository": "miaozhongfei/nuxt-dict",
20
19
  "files": [
21
20
  "dist"
22
21
  ],
@@ -67,6 +66,7 @@
67
66
  "pnpm": ">=10.22.0",
68
67
  "yarn": ">=1.22.22"
69
68
  },
69
+ "documentation": "https://miaozhongfei.github.io/nuxt-dict/",
70
70
  "scripts": {
71
71
  "cleanup": "pnpx nuxt cleanup || npx nuxt cleanup",
72
72
  "clean:install": "pnpm run cleanup && pnpm run docs:cleanup && pnpm run playground:cleanup && pnpm install",
@@ -78,10 +78,11 @@
78
78
  "docs:generate": "nuxi generate docs",
79
79
  "docs:cleanup": "pnpx rimraf docs/.nuxt docs/.output docs/dist docs/node_modules docs/.data",
80
80
  "playground:cleanup": "pnpx rimraf playground/.nuxt playground/.output playground/dist playground/node_modules",
81
- "release": "pnpm lint && pnpm typecheck && pnpm prepack && changelogen --release && pnpm publish && git push --follow-tags",
82
- "release:major": "pnpm lint && pnpm typecheck && pnpm prepack && changelogen --release --major && pnpm publish && git push --follow-tags",
83
- "release:e2e": "pnpm lint && pnpm e2e && pnpm typecheck && pnpm prepack && changelogen --release && pnpm publish && git push --follow-tags",
84
- "release:e2e:major": "pnpm lint && pnpm e2e && pnpm typecheck && pnpm prepack && changelogen --release --major && pnpm publish && git push --follow-tags",
81
+ "demo:base-api:dev": "nuxi dev examples/demo-base-api",
82
+ "release": "pnpm lint && pnpm typecheck && pnpm prepack && changelogen --release && pnpm publish && git push origin dev --follow-tags",
83
+ "release:major": "pnpm lint && pnpm typecheck && pnpm prepack && changelogen --release --major && pnpm publish && git push origin dev --follow-tags",
84
+ "release:e2e": "pnpm lint && pnpm e2e && pnpm typecheck && pnpm prepack && changelogen --release && pnpm publish && git push origin dev --follow-tags",
85
+ "release:e2e:major": "pnpm lint && pnpm e2e && pnpm typecheck && pnpm prepack && changelogen --release --major && pnpm publish && git push origin dev --follow-tags",
85
86
  "lint": "oxlint . && oxlint docs --no-error-on-unmatched-pattern",
86
87
  "lint:fix": "oxlint --fix . && oxlint --fix docs --no-error-on-unmatched-pattern",
87
88
  "fmt": "oxfmt",