@shwfed/nuxt 0.6.0 → 0.7.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.d.mts CHANGED
@@ -1,5 +1,18 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
2
 
3
+ type Wrap<T> = T extends object ? Readonly<{
4
+ [P in keyof T]?: Wrap<T[P]>;
5
+ }> : T;
6
+ type Config = Wrap<{
7
+ api: {
8
+ /**
9
+ * 配置 API 请求额外头
10
+ *
11
+ * @type DSL - Record<string, string>
12
+ */
13
+ header: string;
14
+ };
15
+ }>;
3
16
  interface Env {
4
17
  git: Readonly<{
5
18
  commit?: string;
@@ -16,6 +29,7 @@ interface Env {
16
29
  headers: Readonly<{
17
30
  token?: string;
18
31
  }>;
32
+ config?: Config;
19
33
  }
20
34
  declare module 'nuxt/schema' {
21
35
  interface PublicRuntimeConfig {
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@shwfed/nuxt",
3
- "configKey": "@shwfed/nuxt",
4
- "version": "0.6.0",
3
+ "configKey": "shwfed",
4
+ "version": "0.7.0",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -5,7 +5,20 @@ import defu from 'defu';
5
5
 
6
6
  const module$1 = defineNuxtModule({
7
7
  meta: {
8
- name: "@shwfed/nuxt"
8
+ name: "@shwfed/nuxt",
9
+ configKey: "shwfed"
10
+ },
11
+ moduleDependencies: {
12
+ "@nuxt/fonts": {
13
+ defaults: {
14
+ families: [
15
+ { name: "Noto Sans", provider: "google" },
16
+ { name: "Noto Sans SC", provider: "google" },
17
+ { name: "Noto Sans JP", provider: "google" },
18
+ { name: "Fira Mono", provider: "google" }
19
+ ]
20
+ }
21
+ }
9
22
  },
10
23
  setup(options, nuxt) {
11
24
  const resolver = createResolver(import.meta.url);
@@ -24,7 +37,8 @@ const module$1 = defineNuxtModule({
24
37
  },
25
38
  headers: {
26
39
  token: process.env.NUXT_PUBLIC_TOKEN_HEADER_NAME
27
- }
40
+ },
41
+ config: options
28
42
  });
29
43
  nuxt.options.runtimeConfig.public.shwfed = resolvedConfig;
30
44
  nuxt.options.css ||= [];
@@ -0,0 +1,14 @@
1
+ interface LocaleItem {
2
+ locale: string;
3
+ message: string;
4
+ }
5
+ type __VLS_ModelProps = {
6
+ modelValue?: Array<LocaleItem>;
7
+ };
8
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_ModelProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
9
+ "update:modelValue": (value: LocaleItem[] | undefined) => any;
10
+ }, string, import("vue").PublicProps, Readonly<__VLS_ModelProps> & Readonly<{
11
+ "onUpdate:modelValue"?: ((value: LocaleItem[] | undefined) => any) | undefined;
12
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
13
+ declare const _default: typeof __VLS_export;
14
+ export default _default;
@@ -0,0 +1,89 @@
1
+ <script setup>
2
+ import { Icon } from "@iconify/vue";
3
+ import { useSortable } from "@vueuse/integrations/useSortable";
4
+ import { useTemplateRef } from "vue";
5
+ import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupText } from "./ui/input-group";
6
+ import {
7
+ DropdownMenu,
8
+ DropdownMenuContent,
9
+ DropdownMenuItem,
10
+ DropdownMenuTrigger
11
+ } from "./ui/dropdown-menu";
12
+ const list = defineModel({ type: Array });
13
+ const ul = useTemplateRef("ul");
14
+ useSortable(ul, list);
15
+ const allLocales = ["zh", "ja", "en"];
16
+ const localeNames = {
17
+ zh: "\u4E2D\u6587",
18
+ ja: "\u65E5\u672C\u8A9E",
19
+ en: "English"
20
+ };
21
+ const getAvailableLocales = (currentItem) => {
22
+ const selectedLocales = new Set(list.value?.map((i) => i.locale) ?? []);
23
+ return allLocales.filter((locale) => !selectedLocales.has(locale) || locale === currentItem.locale);
24
+ };
25
+ const removeItem = (item) => {
26
+ if (list.value === void 0) {
27
+ return;
28
+ }
29
+ const index = list.value.indexOf(item);
30
+ if (index > -1) {
31
+ list.value.splice(index, 1);
32
+ }
33
+ };
34
+ </script>
35
+
36
+ <template>
37
+ <div
38
+ ref="ul"
39
+ class="flex flex-col gap-2"
40
+ >
41
+ <InputGroup
42
+ v-for="item in list"
43
+ :key="item.locale"
44
+ class="bg-white/90"
45
+ >
46
+ <InputGroupAddon
47
+ align="inline-start"
48
+ data-drag-handle
49
+ >
50
+ <Icon icon="fluent:re-order-dots-vertical-20-regular" />
51
+ </InputGroupAddon>
52
+ <InputGroupAddon align="inline-start">
53
+ <DropdownMenu>
54
+ <DropdownMenuTrigger as-child>
55
+ <InputGroupAddon
56
+ align="inline-start"
57
+ class="cursor-pointer"
58
+ >
59
+ <Icon :icon="`circle-flags:lang-${item.locale}`" />
60
+ </InputGroupAddon>
61
+ </DropdownMenuTrigger>
62
+ <DropdownMenuContent>
63
+ <DropdownMenuItem
64
+ v-for="locale in getAvailableLocales(item)"
65
+ :key="locale"
66
+ @select="item.locale = locale"
67
+ >
68
+ <Icon :icon="`circle-flags:lang-${locale}`" />
69
+ {{ localeNames[locale] }}
70
+ </DropdownMenuItem>
71
+ </DropdownMenuContent>
72
+ </DropdownMenu>
73
+ </InputGroupAddon>
74
+ <InputGroupAddon align="inline-end">
75
+ <InputGroupButton
76
+ align="inline-end"
77
+ variant="destructive"
78
+ @click="removeItem(item)"
79
+ >
80
+ <Icon icon="fluent:delete-20-regular" />
81
+ </InputGroupButton>
82
+ </InputGroupAddon>
83
+ <InputGroupText
84
+ v-model="item.message"
85
+ class="flex-1"
86
+ />
87
+ </InputGroup>
88
+ </div>
89
+ </template>
@@ -0,0 +1,14 @@
1
+ interface LocaleItem {
2
+ locale: string;
3
+ message: string;
4
+ }
5
+ type __VLS_ModelProps = {
6
+ modelValue?: Array<LocaleItem>;
7
+ };
8
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_ModelProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
9
+ "update:modelValue": (value: LocaleItem[] | undefined) => any;
10
+ }, string, import("vue").PublicProps, Readonly<__VLS_ModelProps> & Readonly<{
11
+ "onUpdate:modelValue"?: ((value: LocaleItem[] | undefined) => any) | undefined;
12
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
13
+ declare const _default: typeof __VLS_export;
14
+ export default _default;
@@ -10,10 +10,11 @@ import { useCheating, useId } from "#imports";
10
10
  import { defu } from "defu";
11
11
  import { Dialog, DialogScrollContent, DialogHeader, DialogTitle, DialogDescription } from "./ui/dialog";
12
12
  import { Skeleton } from "./ui/skeleton";
13
- import { ref, watch } from "vue";
13
+ import { ref, useTemplateRef, watch } from "vue";
14
14
  import { Effect, Either, Schema } from "effect";
15
- import { computedAsync } from "@vueuse/core";
15
+ import { computedAsync, createReusableTemplate } from "@vueuse/core";
16
16
  import { getRead } from "../utilities/query-config/global";
17
+ import { useSortable } from "@vueuse/integrations/useSortable";
17
18
  import { FieldSchema } from "../utilities/query-config/schema";
18
19
  </script>
19
20
 
@@ -63,6 +64,10 @@ const modelValue = defineModel("modelValue", { type: Object, ...{
63
64
  } });
64
65
  const isCheating = useCheating();
65
66
  const isDialogOpen = ref(false);
67
+ const [DefineTextConfiguration, TextConfiguration] = createReusableTemplate();
68
+ const [DefineNumberConfiguration, NumberConfiguration] = createReusableTemplate();
69
+ const sortableFields = useTemplateRef("sortableFields");
70
+ useSortable(sortableFields, [], {});
66
71
  </script>
67
72
 
68
73
  <template>
@@ -89,7 +94,24 @@ const isDialogOpen = ref(false);
89
94
  <DialogDescription class="sr-only">
90
95
  <DialogTitle>Configure query fields dynamically</DialogTitle>
91
96
  </DialogDescription>
92
- <pre class="text-xs overflow-auto">{{ JSON.stringify(fields, null, 2) }}</pre>
97
+ <ul
98
+ ref="sortableFields"
99
+ class="flex flex-col gap-2"
100
+ >
101
+ <template
102
+ v-for="field of fields"
103
+ :key="field.path"
104
+ >
105
+ <TextConfiguration
106
+ v-if="field.type === 'string'"
107
+ v-bind="field"
108
+ />
109
+ <NumberConfiguration
110
+ v-if="field.type === 'number'"
111
+ v-bind="field"
112
+ />
113
+ </template>
114
+ </ul>
93
115
  </DialogScrollContent>
94
116
  </Dialog>
95
117
 
@@ -98,6 +120,34 @@ const isDialogOpen = ref(false);
98
120
  class="absolute inset-0 z-10 w-full h-full"
99
121
  />
100
122
 
123
+ <DefineTextConfiguration #="{ path }">
124
+ <InputGroup>
125
+ <InputGroupAddon>
126
+ <Icon
127
+ icon="fluent:re-order-dots-20-regular"
128
+ />
129
+ </InputGroupAddon>
130
+ <InputGroupInput
131
+ :model-value="path"
132
+ class="font-mono"
133
+ />
134
+ </InputGroup>
135
+ </DefineTextConfiguration>
136
+
137
+ <DefineNumberConfiguration #="{ path }">
138
+ <InputGroup>
139
+ <InputGroupAddon>
140
+ <Icon
141
+ icon="fluent:re-order-dots-20-regular"
142
+ />
143
+ </InputGroupAddon>
144
+ <InputGroupInput
145
+ :model-value="path"
146
+ class="font-mono"
147
+ />
148
+ </InputGroup>
149
+ </DefineNumberConfiguration>
150
+
101
151
  <Field
102
152
  v-for="(field, i) in fields"
103
153
  :key="field.path"
@@ -1,10 +1,13 @@
1
- import { defineNuxtPlugin, useRuntimeConfig } from "#app";
1
+ import { defineNuxtPlugin, useNuxtApp, useRuntimeConfig } from "#app";
2
2
  import { useNavigatorLanguage } from "@vueuse/core";
3
+ import z from "zod";
3
4
  export default defineNuxtPlugin({
4
5
  name: "shwfed-nuxt:api",
6
+ dependsOn: ["shwfed-nuxt:cel"],
5
7
  setup: () => {
6
8
  const locale = useNavigatorLanguage();
7
9
  const config = useRuntimeConfig().public.shwfed;
10
+ const { $dsl } = useNuxtApp();
8
11
  const api = $fetch.create({
9
12
  baseURL: config.api.host,
10
13
  onRequest: ({
@@ -13,7 +16,18 @@ export default defineNuxtPlugin({
13
16
  if (locale.isSupported && locale.language.value) {
14
17
  options.headers.set("Accept-Language", locale.language.value);
15
18
  }
16
- const name = config.headers.token ?? "Authorization";
19
+ if (typeof config.config?.api?.header === "string") {
20
+ try {
21
+ for (const [key, value] of Object.entries(
22
+ z.record(z.string(), z.string()).parse($dsl.evaluate`${config.config.api.header}`())
23
+ )) {
24
+ options.headers.set(key, value);
25
+ }
26
+ } catch (e) {
27
+ console.error(e);
28
+ }
29
+ }
30
+ const name = config.headers.token || "Authorization";
17
31
  options.headers.set(name, sessionStorage.getItem("token") ?? "");
18
32
  }
19
33
  });
@@ -1 +1 @@
1
- @import "tailwindcss";@plugin "@tailwindcss/typography";@source "components";
1
+ @import "tailwindcss";@plugin "@tailwindcss/typography";@source "components";@theme{--font-sans:"Noto Sans","Noto Sans SC","Noto Sans JP","sans-serif";--font-mono:"Berkeley Mono","Fira Mono","monospace"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shwfed/nuxt",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -40,6 +40,7 @@
40
40
  "@iconify/vue": "^5.0.0",
41
41
  "@intlify/unplugin-vue-i18n": "^11.0.3",
42
42
  "@marcbachmann/cel-js": "^7.2.1",
43
+ "@nuxt/fonts": "^0.14.0",
43
44
  "@nuxt/kit": "^4.3.0",
44
45
  "@tailwindcss/typography": "^0.5.19",
45
46
  "@tailwindcss/vite": "^4.2.1",