@atscript/vue-wf 0.1.164 → 0.1.165
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/{as-wf-finish-CfbsKJhX.mjs → as-wf-finish-DSlzLuDT.mjs} +5 -3
- package/dist/as-wf-finish.mjs +1 -1
- package/dist/{as-wf-form-CGWH0Hsb.mjs → as-wf-form-ah0D5Nn1.mjs} +43 -36
- package/dist/as-wf-form.d.mts +1 -1
- package/dist/as-wf-form.mjs +1 -1
- package/dist/{as-wf-form.vue-DzuRHbNd.d.mts → as-wf-form.vue-C1mPDpdy.d.mts} +11 -7
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +2 -2
- package/package.json +9 -9
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Fragment, computed, createCommentVNode, createElementBlock, createElementVNode, defineComponent, normalizeStyle, onMounted, onUnmounted, openBlock, ref, renderList, renderSlot, toDisplayString, watch } from "vue";
|
|
1
|
+
import { Fragment, computed, createCommentVNode, createElementBlock, createElementVNode, defineComponent, normalizeStyle, onMounted, onUnmounted, openBlock, ref, renderList, renderSlot, toDisplayString, unref, watch } from "vue";
|
|
2
|
+
import { useAsTexts } from "@atscript/vue-form/locale";
|
|
2
3
|
//#region src/components/defaults/as-wf-finish.vue?vue&type=script&setup=true&lang.ts
|
|
3
4
|
const _hoisted_1 = {
|
|
4
5
|
key: 0,
|
|
@@ -62,6 +63,7 @@ var as_wf_finish_default = /* @__PURE__ */ defineComponent({
|
|
|
62
63
|
}
|
|
63
64
|
if (action.type === "dismiss") emit("dismiss");
|
|
64
65
|
}
|
|
66
|
+
const { t } = useAsTexts();
|
|
65
67
|
const next = computed(() => props.payload?.next ?? null);
|
|
66
68
|
const message = computed(() => props.payload?.message ?? null);
|
|
67
69
|
let autoTimer;
|
|
@@ -149,7 +151,7 @@ var as_wf_finish_default = /* @__PURE__ */ defineComponent({
|
|
|
149
151
|
};
|
|
150
152
|
});
|
|
151
153
|
return (_ctx, _cache) => {
|
|
152
|
-
return next.value?.trigger === "immediate" ? (openBlock(), createElementBlock("span", _hoisted_1, "
|
|
154
|
+
return next.value?.trigger === "immediate" ? (openBlock(), createElementBlock("span", _hoisted_1, toDisplayString(unref(t)("UI_WF_REDIRECTING")), 1)) : (openBlock(), createElementBlock("div", {
|
|
153
155
|
key: 1,
|
|
154
156
|
class: "as-wf-finish",
|
|
155
157
|
onKeydown
|
|
@@ -175,7 +177,7 @@ var as_wf_finish_default = /* @__PURE__ */ defineComponent({
|
|
|
175
177
|
totalSeconds: totalSeconds.value,
|
|
176
178
|
skip: skipAuto,
|
|
177
179
|
cancel: cancelAuto
|
|
178
|
-
}, () => [createElementVNode("div", _hoisted_5, "
|
|
180
|
+
}, () => [createElementVNode("div", _hoisted_5, toDisplayString(unref(t)("UI_WF_CONTINUING_IN", { seconds: secondsRemaining.value })), 1)])], 64)) : createCommentVNode("v-if", true),
|
|
179
181
|
next.value?.trigger === "manual" ? (openBlock(), createElementBlock("div", _hoisted_6, [manualPrimary.value ? renderSlot(_ctx.$slots, "primary", {
|
|
180
182
|
key: 0,
|
|
181
183
|
button: manualPrimary.value,
|
package/dist/as-wf-finish.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as as_wf_finish_default } from "./as-wf-finish-
|
|
1
|
+
import { t as as_wf_finish_default } from "./as-wf-finish-DSlzLuDT.mjs";
|
|
2
2
|
export { as_wf_finish_default as default };
|
|
@@ -1,41 +1,36 @@
|
|
|
1
|
-
import { t as as_wf_finish_default } from "./as-wf-finish-
|
|
1
|
+
import { t as as_wf_finish_default } from "./as-wf-finish-DSlzLuDT.mjs";
|
|
2
2
|
import { computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createSlots, createVNode, defineComponent, guardReactiveProps, normalizeProps, onMounted, onUnmounted, openBlock, reactive, ref, renderSlot, shallowRef, toDisplayString, toRaw, unref, watch, withCtx } from "vue";
|
|
3
3
|
import { createFormData, createFormDef, getDeclaredFormActions } from "@atscript/ui";
|
|
4
|
+
import { AS_UI_MESSAGES } from "@atscript/ui/messages";
|
|
5
|
+
import { useAsTexts } from "@atscript/vue-form/locale";
|
|
4
6
|
import { deserializeAnnotatedType } from "@atscript/typescript/utils";
|
|
5
7
|
import { AsForm } from "@atscript/vue-form";
|
|
6
8
|
//#region src/use-wf-form.ts
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
};
|
|
23
|
-
function friendlyMessageForStatus(status) {
|
|
24
|
-
const mapped = FRIENDLY_STATUS_MESSAGES[status];
|
|
25
|
-
if (mapped) return mapped;
|
|
26
|
-
if (status >= 500) return FRIENDLY_STATUS_MESSAGES[500];
|
|
27
|
-
if (status >= 400) return "Something went wrong with that request. Please try again.";
|
|
28
|
-
return "Unexpected response from the server.";
|
|
9
|
+
/**
|
|
10
|
+
* A status with its own friendly text (`UI_WF_STATUS_<status>`: client errors
|
|
11
|
+
* that map to specific user actions, server errors generic but human), else a
|
|
12
|
+
* generic one.
|
|
13
|
+
*/
|
|
14
|
+
function friendlyMessageForStatus(status, t) {
|
|
15
|
+
const code = `UI_WF_STATUS_${status}`;
|
|
16
|
+
if (Object.hasOwn(AS_UI_MESSAGES, code)) return t(code);
|
|
17
|
+
if (status >= 500) return t("UI_WF_STATUS_500");
|
|
18
|
+
if (status >= 400) return t("UI_WF_REQUEST_FAILED");
|
|
19
|
+
return t("UI_WF_UNEXPECTED_RESPONSE");
|
|
20
|
+
}
|
|
21
|
+
/** The `$i18n` texts a form schema in an answer carries (`inputRequired.payload.$i18n`). */
|
|
22
|
+
function servedTexts(data) {
|
|
23
|
+
return (data?.inputRequired)?.payload?.$i18n;
|
|
29
24
|
}
|
|
30
25
|
/**
|
|
31
26
|
* A `{ error }` answer as a `WfFormError`: a string is the message; an
|
|
32
27
|
* object keeps its `message` / `status` / `code` and is the `body`.
|
|
33
28
|
*/
|
|
34
|
-
function bodyError(raw) {
|
|
29
|
+
function bodyError(raw, t) {
|
|
35
30
|
if (typeof raw === "string") return { message: raw };
|
|
36
31
|
const body = typeof raw === "object" && raw !== null ? raw : void 0;
|
|
37
32
|
const status = typeof body?.status === "number" ? body.status : void 0;
|
|
38
|
-
const failed = { message: typeof body?.message === "string" ? body.message : status !== void 0 ? friendlyMessageForStatus(status) : "
|
|
33
|
+
const failed = { message: typeof body?.message === "string" ? body.message : status !== void 0 ? friendlyMessageForStatus(status, t) : t("UI_WF_REQUEST_FAILED") };
|
|
39
34
|
if (status !== void 0) failed.status = status;
|
|
40
35
|
if (typeof body?.code === "string") failed.code = body.code;
|
|
41
36
|
if (body) failed.body = body;
|
|
@@ -45,6 +40,8 @@ function useWfForm(options) {
|
|
|
45
40
|
const tokenName = options.tokenName ?? "wfs";
|
|
46
41
|
const wfidName = options.wfidName ?? "wfid";
|
|
47
42
|
const transport = options.tokenTransport ?? "body";
|
|
43
|
+
const texts = useAsTexts();
|
|
44
|
+
const { t } = texts;
|
|
48
45
|
const formDef = shallowRef(null);
|
|
49
46
|
const formData = shallowRef(null);
|
|
50
47
|
const formContext = shallowRef({});
|
|
@@ -61,12 +58,14 @@ function useWfForm(options) {
|
|
|
61
58
|
let lastPayloadJson;
|
|
62
59
|
let abortController;
|
|
63
60
|
const { headers: extraHeaders, ...restFetchOpts } = options.fetchOptions ?? {};
|
|
61
|
+
const mergedHeaders = {
|
|
62
|
+
"Content-Type": "application/json",
|
|
63
|
+
...extraHeaders instanceof Headers ? Object.fromEntries(extraHeaders) : Array.isArray(extraHeaders) ? Object.fromEntries(extraHeaders) : extraHeaders
|
|
64
|
+
};
|
|
65
|
+
const sendsLanguage = new Headers(mergedHeaders).has("accept-language");
|
|
64
66
|
const baseFetchOpts = {
|
|
65
67
|
method: "POST",
|
|
66
|
-
headers:
|
|
67
|
-
"Content-Type": "application/json",
|
|
68
|
-
...extraHeaders instanceof Headers ? Object.fromEntries(extraHeaders) : Array.isArray(extraHeaders) ? Object.fromEntries(extraHeaders) : extraHeaders
|
|
69
|
-
},
|
|
68
|
+
headers: mergedHeaders,
|
|
70
69
|
...transport === "cookie" ? { credentials: "include" } : {},
|
|
71
70
|
...restFetchOpts
|
|
72
71
|
};
|
|
@@ -103,12 +102,12 @@ function useWfForm(options) {
|
|
|
103
102
|
return;
|
|
104
103
|
}
|
|
105
104
|
if (data.error) {
|
|
106
|
-
error.value = bodyError(data.error);
|
|
105
|
+
error.value = bodyError(data.error, t);
|
|
107
106
|
return;
|
|
108
107
|
}
|
|
109
108
|
const ir = data.inputRequired;
|
|
110
109
|
if (!ir) {
|
|
111
|
-
error.value = { message: "
|
|
110
|
+
error.value = { message: t("UI_WF_UNEXPECTED_FORMAT") };
|
|
112
111
|
return;
|
|
113
112
|
}
|
|
114
113
|
const { errors: serverErrors, ...remainingCtx } = ir.context ?? {};
|
|
@@ -132,18 +131,25 @@ function useWfForm(options) {
|
|
|
132
131
|
loading.value = true;
|
|
133
132
|
error.value = null;
|
|
134
133
|
lastRequestBody = body;
|
|
134
|
+
const locale = texts.locale();
|
|
135
|
+
const headers = locale && !sendsLanguage ? {
|
|
136
|
+
...mergedHeaders,
|
|
137
|
+
"Accept-Language": locale
|
|
138
|
+
} : mergedHeaders;
|
|
135
139
|
try {
|
|
136
140
|
const res = await (options.fetch ?? fetch)(options.path, {
|
|
137
141
|
...baseFetchOpts,
|
|
142
|
+
headers,
|
|
138
143
|
signal,
|
|
139
144
|
body: JSON.stringify(buildBody(body))
|
|
140
145
|
});
|
|
141
146
|
const data = await res.json().catch(() => null);
|
|
147
|
+
if (!sendsLanguage) texts.merge(locale, servedTexts(data));
|
|
142
148
|
if (data && typeof data === "object" && !Array.isArray(data)) extractToken(data);
|
|
143
149
|
if (!res.ok) {
|
|
144
150
|
const errData = data;
|
|
145
151
|
const failed = {
|
|
146
|
-
message: errData?.message ?? errData?.error ?? friendlyMessageForStatus(res.status),
|
|
152
|
+
message: errData?.message ?? errData?.error ?? friendlyMessageForStatus(res.status, t),
|
|
147
153
|
status: res.status
|
|
148
154
|
};
|
|
149
155
|
if (typeof errData?.code === "string") failed.code = errData.code;
|
|
@@ -152,13 +158,13 @@ function useWfForm(options) {
|
|
|
152
158
|
return;
|
|
153
159
|
}
|
|
154
160
|
if (!data) {
|
|
155
|
-
error.value = { message: "
|
|
161
|
+
error.value = { message: t("UI_WF_UNEXPECTED_FORMAT") };
|
|
156
162
|
return;
|
|
157
163
|
}
|
|
158
164
|
processResponse(data);
|
|
159
165
|
} catch (err) {
|
|
160
166
|
if (err instanceof DOMException && err.name === "AbortError") return;
|
|
161
|
-
error.value = { message: err instanceof Error ? err.message : "
|
|
167
|
+
error.value = { message: err instanceof Error ? err.message : t("UI_WF_NETWORK_ERROR") };
|
|
162
168
|
} finally {
|
|
163
169
|
loading.value = false;
|
|
164
170
|
}
|
|
@@ -313,6 +319,7 @@ var as_wf_form_default = /* @__PURE__ */ defineComponent({
|
|
|
313
319
|
const props = __props;
|
|
314
320
|
const emit = __emit;
|
|
315
321
|
const wf = useWfForm(props);
|
|
322
|
+
const { t } = useAsTexts();
|
|
316
323
|
watch(() => wf.loading.value, (v) => emit("loading", v));
|
|
317
324
|
watch(() => wf.finished.value, (v) => {
|
|
318
325
|
if (v) emit("finished", wf.response.value);
|
|
@@ -375,7 +382,7 @@ var as_wf_form_default = /* @__PURE__ */ defineComponent({
|
|
|
375
382
|
})], -1))])])) : unref(wf).error.value && !unref(wf).formDef.value ? (openBlock(), createElementBlock("div", _hoisted_2, [renderSlot(_ctx.$slots, "wf.error", {
|
|
376
383
|
error: unref(wf).error.value,
|
|
377
384
|
retry: unref(wf).retry
|
|
378
|
-
}, () => [createElementVNode("div", null, toDisplayString(unref(wf).error.value?.message ?? "
|
|
385
|
+
}, () => [createElementVNode("div", null, toDisplayString(unref(wf).error.value?.message ?? unref(t)("UI_ERROR")), 1)])])) : unref(wf).finished.value ? (openBlock(), createElementBlock("div", _hoisted_3, [renderSlot(_ctx.$slots, "wf.finished", {
|
|
379
386
|
response: unref(wf).response.value,
|
|
380
387
|
payload: unref(wf).finishedPayload.value
|
|
381
388
|
}, () => [createCommentVNode("\n Per `feedback_vue_empty_slot`: a `<template #x>` registered on a child\n short-circuits the child's default fallback even when its content is\n empty. So we only forward slot names that the AsWfForm consumer\n actually provided — otherwise AsWfFinish's defaults render.\n "), createVNode(as_wf_finish_default, {
|
|
@@ -413,7 +420,7 @@ var as_wf_form_default = /* @__PURE__ */ defineComponent({
|
|
|
413
420
|
key: 0,
|
|
414
421
|
error: unref(wf).error.value,
|
|
415
422
|
retry: unref(wf).retry
|
|
416
|
-
}, () => [createElementVNode("div", _hoisted_5, toDisplayString(unref(wf).error.value?.message ?? "
|
|
423
|
+
}, () => [createElementVNode("div", _hoisted_5, toDisplayString(unref(wf).error.value?.message ?? unref(t)("UI_ERROR")), 1)]) : createCommentVNode("v-if", true), (openBlock(), createBlock(unref(AsForm), {
|
|
417
424
|
key: unref(wf).formKey.value,
|
|
418
425
|
def: unref(wf).formDef.value,
|
|
419
426
|
"form-data": unref(wf).formData.value,
|
package/dist/as-wf-form.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as _default } from "./as-wf-form.vue-
|
|
1
|
+
import { t as _default } from "./as-wf-form.vue-C1mPDpdy.mjs";
|
|
2
2
|
export { _default as default };
|
package/dist/as-wf-form.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as as_wf_form_default } from "./as-wf-form-
|
|
1
|
+
import { t as as_wf_form_default } from "./as-wf-form-ah0D5Nn1.mjs";
|
|
2
2
|
export { as_wf_form_default as default };
|
|
@@ -29,7 +29,11 @@ interface UseWfFormOptions {
|
|
|
29
29
|
tokenName?: string;
|
|
30
30
|
/** Workflow ID parameter name (default: 'wfid') */
|
|
31
31
|
wfidName?: string;
|
|
32
|
-
/**
|
|
32
|
+
/**
|
|
33
|
+
* Custom fetch options (headers, credentials, etc.). Requests carry an
|
|
34
|
+
* `Accept-Language` of the locale `provideAsLocale` gives, unless these
|
|
35
|
+
* headers set one.
|
|
36
|
+
*/
|
|
33
37
|
fetchOptions?: RequestInit;
|
|
34
38
|
/**
|
|
35
39
|
* Override the global `fetch` — lets the host wire its own status-code
|
|
@@ -343,20 +347,20 @@ declare const __VLS_base: vue.DefineComponent<AsWfFormProps, {
|
|
|
343
347
|
action: typeof onAction;
|
|
344
348
|
supportsAction: typeof supportsAction;
|
|
345
349
|
}, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {} & {
|
|
346
|
-
|
|
350
|
+
dismiss: () => any;
|
|
351
|
+
action: (action: WfActionRequest) => any;
|
|
347
352
|
error: (error: WfFormError) => any;
|
|
353
|
+
finished: (response: unknown) => any;
|
|
348
354
|
submit: (data: unknown) => any;
|
|
349
355
|
loading: (isLoading: boolean) => any;
|
|
350
|
-
dismiss: () => any;
|
|
351
|
-
action: (action: WfActionRequest) => any;
|
|
352
356
|
form: (def: FormDef, context?: Record<string, unknown> | undefined) => any;
|
|
353
357
|
}, string, vue.PublicProps, Readonly<AsWfFormProps> & Readonly<{
|
|
354
|
-
|
|
358
|
+
onDismiss?: (() => any) | undefined;
|
|
359
|
+
onAction?: ((action: WfActionRequest) => any) | undefined;
|
|
355
360
|
onError?: ((error: WfFormError) => any) | undefined;
|
|
361
|
+
onFinished?: ((response: unknown) => any) | undefined;
|
|
356
362
|
onSubmit?: ((data: unknown) => any) | undefined;
|
|
357
363
|
onLoading?: ((isLoading: boolean) => any) | undefined;
|
|
358
|
-
onDismiss?: (() => any) | undefined;
|
|
359
|
-
onAction?: ((action: WfActionRequest) => any) | undefined;
|
|
360
364
|
onForm?: ((def: FormDef, context?: Record<string, unknown> | undefined) => any) | undefined;
|
|
361
365
|
}>, {
|
|
362
366
|
tokenTransport: "body" | "cookie" | "query";
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { a as WfNext, i as WfMessage, n as WfButton, r as WfFinished, t as WfActionRequest } from "./index-C5MmoWFB.mjs";
|
|
2
|
-
import { a as useWfForm, i as WfFormError, n as UseWfFormOptions, r as UseWfFormReturn, t as _default$1 } from "./as-wf-form.vue-
|
|
2
|
+
import { a as useWfForm, i as WfFormError, n as UseWfFormOptions, r as UseWfFormReturn, t as _default$1 } from "./as-wf-form.vue-C1mPDpdy.mjs";
|
|
3
3
|
import { t as _default } from "./as-wf-finish.vue-BhXMooP3.mjs";
|
|
4
4
|
export { _default as AsWfFinish, _default$1 as AsWfForm, type UseWfFormOptions, type UseWfFormReturn, type WfActionRequest, type WfButton, type WfFinished, type WfFormError, type WfMessage, type WfNext, useWfForm };
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { n as useWfForm, t as as_wf_form_default } from "./as-wf-form-
|
|
2
|
-
import { t as as_wf_finish_default } from "./as-wf-finish-
|
|
1
|
+
import { n as useWfForm, t as as_wf_form_default } from "./as-wf-form-ah0D5Nn1.mjs";
|
|
2
|
+
import { t as as_wf_finish_default } from "./as-wf-finish-DSlzLuDT.mjs";
|
|
3
3
|
export { as_wf_finish_default as AsWfFinish, as_wf_form_default as AsWfForm, useWfForm };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atscript/vue-wf",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.165",
|
|
4
4
|
"description": "Workflow form integration for Vue 3 — HTTP round-trip loop driven by atscript type metadata",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"atscript",
|
|
@@ -51,25 +51,25 @@
|
|
|
51
51
|
"access": "public"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@atscript/ui": "^0.1.
|
|
54
|
+
"@atscript/ui": "^0.1.165"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@atscript/core": "^0.2.
|
|
58
|
-
"@atscript/typescript": "^0.2.
|
|
57
|
+
"@atscript/core": "^0.2.7",
|
|
58
|
+
"@atscript/typescript": "^0.2.7",
|
|
59
59
|
"@vitejs/plugin-vue": "^6",
|
|
60
60
|
"@vue/test-utils": "^2",
|
|
61
61
|
"happy-dom": "^18",
|
|
62
|
-
"unplugin-atscript": "^0.2.
|
|
62
|
+
"unplugin-atscript": "^0.2.7",
|
|
63
63
|
"vitest": "npm:@voidzero-dev/vite-plus-test@0.1.14",
|
|
64
64
|
"vue": "^3",
|
|
65
65
|
"vue-tsc": "~3.2.9",
|
|
66
|
-
"@atscript/moost-wf": "^0.1.
|
|
67
|
-
"@atscript/vue-form": "^0.1.
|
|
66
|
+
"@atscript/moost-wf": "^0.1.165",
|
|
67
|
+
"@atscript/vue-form": "^0.1.165"
|
|
68
68
|
},
|
|
69
69
|
"peerDependencies": {
|
|
70
|
-
"@atscript/typescript": "^0.2.
|
|
70
|
+
"@atscript/typescript": "^0.2.7",
|
|
71
71
|
"vue": "^3",
|
|
72
|
-
"@atscript/vue-form": "^0.1.
|
|
72
|
+
"@atscript/vue-form": "^0.1.165"
|
|
73
73
|
},
|
|
74
74
|
"scripts": {
|
|
75
75
|
"build": "node ../../scripts/gen-exports.mjs && vp pack",
|