@vesperjs/vue 0.7.2 → 0.8.1
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/index.mjs +103 -2
- package/package.json +7 -7
package/dist/index.mjs
CHANGED
|
@@ -3,9 +3,12 @@ import { computed, ref } from "@vue/reactivity";
|
|
|
3
3
|
import { persistentAtom } from "@nanostores/persistent";
|
|
4
4
|
import { ofetch } from "ofetch";
|
|
5
5
|
import { createI18n } from "vue-i18n";
|
|
6
|
+
import { format, parse, tzDate } from "@formkit/tempo";
|
|
6
7
|
//#region src/stores/nano/base-url.ts
|
|
7
8
|
const $baseUrl = persistentAtom("baseURL", "");
|
|
8
|
-
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/stores/nano/time-zone.ts
|
|
11
|
+
const $timeZone = persistentAtom("timeZone", void 0);
|
|
9
12
|
//#endregion
|
|
10
13
|
//#region src/stores/use-base-url-store.ts
|
|
11
14
|
const useBaseUrlStore = function() {
|
|
@@ -75,13 +78,111 @@ const useLocale = function() {
|
|
|
75
78
|
};
|
|
76
79
|
};
|
|
77
80
|
//#endregion
|
|
81
|
+
//#region src/stores/use-time-zone-store.ts
|
|
82
|
+
const useTimeZoneStore = function() {
|
|
83
|
+
return { serverTZ: computed({
|
|
84
|
+
get() {
|
|
85
|
+
return $timeZone.get();
|
|
86
|
+
},
|
|
87
|
+
set(value) {
|
|
88
|
+
$timeZone.set(value);
|
|
89
|
+
}
|
|
90
|
+
}) };
|
|
91
|
+
};
|
|
92
|
+
//#endregion
|
|
93
|
+
//#region src/composables/use-datetime-local.ts
|
|
94
|
+
const useDatetimeLocal = function(fmtDT = "YYYY/MM/DD HH:mm") {
|
|
95
|
+
const { locale } = useLocale();
|
|
96
|
+
const fmtISO8601 = "YYYY-MM-DDTHH:mm";
|
|
97
|
+
const parseDT = (datetime, format) => {
|
|
98
|
+
return parse(datetime, format, locale.value);
|
|
99
|
+
};
|
|
100
|
+
const toISO8601 = (datetime) => {
|
|
101
|
+
return format(parseDT(datetime, fmtDT), fmtISO8601, locale.value);
|
|
102
|
+
};
|
|
103
|
+
const fromISO8601 = (datetime) => {
|
|
104
|
+
return format(parseDT(datetime, fmtISO8601), fmtDT, locale.value);
|
|
105
|
+
};
|
|
106
|
+
const upDTL = (datetime) => {
|
|
107
|
+
return datetime ? toISO8601(datetime) : null;
|
|
108
|
+
};
|
|
109
|
+
const downDTL = (datetime) => {
|
|
110
|
+
return datetime ? fromISO8601(datetime) : "";
|
|
111
|
+
};
|
|
112
|
+
const formatHTML = (datetime, fmt) => {
|
|
113
|
+
return datetime ? format(parseDT(datetime, fmtDT), fmt, locale.value) : "";
|
|
114
|
+
};
|
|
115
|
+
return {
|
|
116
|
+
upDTL,
|
|
117
|
+
downDTL,
|
|
118
|
+
toISO8601,
|
|
119
|
+
formatHTML
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
//#endregion
|
|
123
|
+
//#region src/composables/use-time-zone.ts
|
|
124
|
+
const useTimeZone = function(fmtDT = "YYYY/MM/DD HH:mm") {
|
|
125
|
+
const { locale } = useLocale();
|
|
126
|
+
const { toISO8601, formatHTML } = useDatetimeLocal(fmtDT);
|
|
127
|
+
const { serverTZ } = useTimeZoneStore();
|
|
128
|
+
const clientTZ = computed(() => Intl.DateTimeFormat().resolvedOptions().timeZone);
|
|
129
|
+
const timeZone = computed(() => ({
|
|
130
|
+
client: clientTZ.value,
|
|
131
|
+
server: serverTZ.value ? serverTZ.value : clientTZ.value
|
|
132
|
+
}));
|
|
133
|
+
const tzOptions = computed(() => Intl.supportedValuesOf("timeZone").map((e) => ({
|
|
134
|
+
text: e,
|
|
135
|
+
value: e
|
|
136
|
+
})));
|
|
137
|
+
const tzServerDate = (datetime) => {
|
|
138
|
+
return tzDate(toISO8601(datetime), timeZone.value.server);
|
|
139
|
+
};
|
|
140
|
+
const tzClientDate = (datetime) => {
|
|
141
|
+
return tzDate(toISO8601(datetime), timeZone.value.client);
|
|
142
|
+
};
|
|
143
|
+
const upTZ = (datetime) => {
|
|
144
|
+
return timeZone.value.client === timeZone.value.server ? datetime ?? "" : datetime ? format({
|
|
145
|
+
date: tzServerDate(datetime),
|
|
146
|
+
format: fmtDT,
|
|
147
|
+
locale: locale.value,
|
|
148
|
+
tz: timeZone.value.client
|
|
149
|
+
}) : "";
|
|
150
|
+
};
|
|
151
|
+
const downTZ = (datetime) => {
|
|
152
|
+
return timeZone.value.client === timeZone.value.server ? datetime ?? "" : datetime ? format({
|
|
153
|
+
date: tzClientDate(datetime),
|
|
154
|
+
format: fmtDT,
|
|
155
|
+
locale: locale.value,
|
|
156
|
+
tz: timeZone.value.server
|
|
157
|
+
}) : "";
|
|
158
|
+
};
|
|
159
|
+
const formatHtmlTZ = (datetime, fmt) => {
|
|
160
|
+
return timeZone.value.client === timeZone.value.server ? formatHTML(datetime, fmt) : datetime ? format({
|
|
161
|
+
date: tzServerDate(datetime),
|
|
162
|
+
format: fmt,
|
|
163
|
+
locale: locale.value,
|
|
164
|
+
tz: timeZone.value.client
|
|
165
|
+
}) : "";
|
|
166
|
+
};
|
|
167
|
+
return {
|
|
168
|
+
timeZone,
|
|
169
|
+
serverTZ,
|
|
170
|
+
tzOptions,
|
|
171
|
+
upTZ,
|
|
172
|
+
downTZ,
|
|
173
|
+
formatHtmlTZ
|
|
174
|
+
};
|
|
175
|
+
};
|
|
176
|
+
//#endregion
|
|
78
177
|
//#region src/composables/backend/api/use-http-headers.ts
|
|
79
178
|
const useHttpHeaders = function() {
|
|
80
179
|
const { locale } = useLocale();
|
|
180
|
+
const { timeZone } = useTimeZone();
|
|
81
181
|
return { commonHeaders: computed(() => ({
|
|
82
182
|
"X-Requested-With": "XMLHttpRequest",
|
|
83
183
|
Accept: "application/json",
|
|
84
|
-
"Accept-Language": locale.value
|
|
184
|
+
"Accept-Language": locale.value,
|
|
185
|
+
"Time-Zone": timeZone.value.client
|
|
85
186
|
})) };
|
|
86
187
|
};
|
|
87
188
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vesperjs/vue",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"vue.js"
|
|
6
6
|
],
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"@formkit/tempo": "^1.1.0",
|
|
23
23
|
"@nanostores/persistent": "^1.3.4",
|
|
24
24
|
"@nanostores/router": "^1.0.0",
|
|
25
|
-
"@vesperjs/shared": "0.
|
|
25
|
+
"@vesperjs/shared": "0.8.1",
|
|
26
26
|
"nanostores": "^1.3.0",
|
|
27
27
|
"ofetch": "^1.5.1",
|
|
28
28
|
"undici": "^8.2.0",
|
|
@@ -35,16 +35,16 @@
|
|
|
35
35
|
"@vue/eslint-config-typescript": "^14.7.0",
|
|
36
36
|
"eslint": "^10.3.0",
|
|
37
37
|
"eslint-plugin-vue": "^10.9.1",
|
|
38
|
-
"oxfmt": "^0.
|
|
38
|
+
"oxfmt": "^0.50.0",
|
|
39
39
|
"tsdown": "^0.22.0",
|
|
40
40
|
"typescript": "^6.0.3"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"@vue/reactivity": "^3.5.34 || ^3.6.0-beta.
|
|
44
|
-
"@vue/runtime-core": "^3.5.34 || ^3.6.0-beta.
|
|
45
|
-
"@vue/runtime-dom": "^3.5.34 || ^3.6.0-beta.
|
|
43
|
+
"@vue/reactivity": "^3.5.34 || ^3.6.0-beta.12",
|
|
44
|
+
"@vue/runtime-core": "^3.5.34 || ^3.6.0-beta.12",
|
|
45
|
+
"@vue/runtime-dom": "^3.5.34 || ^3.6.0-beta.12",
|
|
46
46
|
"typescript-eslint": "^8.59.3",
|
|
47
|
-
"vue": "^3.5.34 || ^3.6.0-beta.
|
|
47
|
+
"vue": "^3.5.34 || ^3.6.0-beta.12"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
50
|
"build": "tsdown --dts",
|