@weconstudio/nuxt 0.0.0-stage → 1.72.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/LICENSE +1 -0
- package/README.md +115 -2
- package/dist/module.d.mts +7 -0
- package/dist/module.json +12 -0
- package/dist/module.mjs +250 -0
- package/dist/runtime/components/We/Autocomplete.d.vue.ts +13 -0
- package/dist/runtime/components/We/Autocomplete.vue +91 -0
- package/dist/runtime/components/We/Autocomplete.vue.d.ts +13 -0
- package/dist/runtime/components/We/BoldText.d.vue.ts +17 -0
- package/dist/runtime/components/We/BoldText.vue +29 -0
- package/dist/runtime/components/We/BoldText.vue.d.ts +17 -0
- package/dist/runtime/components/We/ColorPicker.d.vue.ts +11 -0
- package/dist/runtime/components/We/ColorPicker.vue +199 -0
- package/dist/runtime/components/We/ColorPicker.vue.d.ts +11 -0
- package/dist/runtime/components/We/ConfirmDialog.d.vue.ts +104 -0
- package/dist/runtime/components/We/ConfirmDialog.vue +143 -0
- package/dist/runtime/components/We/ConfirmDialog.vue.d.ts +104 -0
- package/dist/runtime/components/We/Datatable.d.vue.ts +40 -0
- package/dist/runtime/components/We/Datatable.vue +87 -0
- package/dist/runtime/components/We/Datatable.vue.d.ts +40 -0
- package/dist/runtime/components/We/DatatableInternal.d.vue.ts +194 -0
- package/dist/runtime/components/We/DatatableInternal.vue +638 -0
- package/dist/runtime/components/We/DatatableInternal.vue.d.ts +194 -0
- package/dist/runtime/components/We/DatePicker.d.vue.ts +51 -0
- package/dist/runtime/components/We/DatePicker.vue +901 -0
- package/dist/runtime/components/We/DatePicker.vue.d.ts +51 -0
- package/dist/runtime/components/We/Dt/Actions.d.vue.ts +51 -0
- package/dist/runtime/components/We/Dt/Actions.vue +106 -0
- package/dist/runtime/components/We/Dt/Actions.vue.d.ts +51 -0
- package/dist/runtime/components/We/Dt/BooleanFormatter.d.vue.ts +8 -0
- package/dist/runtime/components/We/Dt/BooleanFormatter.vue +26 -0
- package/dist/runtime/components/We/Dt/BooleanFormatter.vue.d.ts +8 -0
- package/dist/runtime/components/We/Dt/CardFilterContainer.d.vue.ts +17 -0
- package/dist/runtime/components/We/Dt/CardFilterContainer.vue +60 -0
- package/dist/runtime/components/We/Dt/CardFilterContainer.vue.d.ts +17 -0
- package/dist/runtime/components/We/Dt/CheckboxFilter.d.vue.ts +16 -0
- package/dist/runtime/components/We/Dt/CheckboxFilter.vue +47 -0
- package/dist/runtime/components/We/Dt/CheckboxFilter.vue.d.ts +16 -0
- package/dist/runtime/components/We/Dt/ChipGroupSelect.d.vue.ts +7 -0
- package/dist/runtime/components/We/Dt/ChipGroupSelect.vue +35 -0
- package/dist/runtime/components/We/Dt/ChipGroupSelect.vue.d.ts +7 -0
- package/dist/runtime/components/We/Dt/ClusterFilter.d.vue.ts +18 -0
- package/dist/runtime/components/We/Dt/ClusterFilter.vue +68 -0
- package/dist/runtime/components/We/Dt/ClusterFilter.vue.d.ts +18 -0
- package/dist/runtime/components/We/Dt/DatasetFormatter.d.vue.ts +19 -0
- package/dist/runtime/components/We/Dt/DatasetFormatter.vue +65 -0
- package/dist/runtime/components/We/Dt/DatasetFormatter.vue.d.ts +19 -0
- package/dist/runtime/components/We/Dt/DaterangeFilter.d.vue.ts +28 -0
- package/dist/runtime/components/We/Dt/DaterangeFilter.vue +140 -0
- package/dist/runtime/components/We/Dt/DaterangeFilter.vue.d.ts +28 -0
- package/dist/runtime/components/We/Dt/Filter.d.vue.ts +7 -0
- package/dist/runtime/components/We/Dt/Filter.vue +234 -0
- package/dist/runtime/components/We/Dt/Filter.vue.d.ts +7 -0
- package/dist/runtime/components/We/Dt/Filters.d.vue.ts +6 -0
- package/dist/runtime/components/We/Dt/Filters.vue +24 -0
- package/dist/runtime/components/We/Dt/Filters.vue.d.ts +6 -0
- package/dist/runtime/components/We/Dt/LuxonFormatter.d.vue.ts +12 -0
- package/dist/runtime/components/We/Dt/LuxonFormatter.vue +23 -0
- package/dist/runtime/components/We/Dt/LuxonFormatter.vue.d.ts +12 -0
- package/dist/runtime/components/We/Dt/SelectFilter.d.vue.ts +60 -0
- package/dist/runtime/components/We/Dt/SelectFilter.vue +333 -0
- package/dist/runtime/components/We/Dt/SelectFilter.vue.d.ts +60 -0
- package/dist/runtime/components/We/Dt/SelectResourceFilter.d.vue.ts +43 -0
- package/dist/runtime/components/We/Dt/SelectResourceFilter.vue +127 -0
- package/dist/runtime/components/We/Dt/SelectResourceFilter.vue.d.ts +43 -0
- package/dist/runtime/components/We/Dt/dt.types.d.ts +8 -0
- package/dist/runtime/components/We/EndpointSwitcher.d.vue.ts +12 -0
- package/dist/runtime/components/We/EndpointSwitcher.vue +256 -0
- package/dist/runtime/components/We/EndpointSwitcher.vue.d.ts +12 -0
- package/dist/runtime/components/We/Import.d.vue.ts +118 -0
- package/dist/runtime/components/We/Import.vue +730 -0
- package/dist/runtime/components/We/Import.vue.d.ts +118 -0
- package/dist/runtime/components/We/ImportDefaultValues.d.vue.ts +3666 -0
- package/dist/runtime/components/We/ImportDefaultValues.vue +115 -0
- package/dist/runtime/components/We/ImportDefaultValues.vue.d.ts +3666 -0
- package/dist/runtime/components/We/ImportMatchColumns.d.vue.ts +66 -0
- package/dist/runtime/components/We/ImportMatchColumns.vue +172 -0
- package/dist/runtime/components/We/ImportMatchColumns.vue.d.ts +66 -0
- package/dist/runtime/components/We/ImportPreviewResults.d.vue.ts +38 -0
- package/dist/runtime/components/We/ImportPreviewResults.vue +165 -0
- package/dist/runtime/components/We/ImportPreviewResults.vue.d.ts +38 -0
- package/dist/runtime/components/We/ImportSelectStart.d.vue.ts +47 -0
- package/dist/runtime/components/We/ImportSelectStart.vue +106 -0
- package/dist/runtime/components/We/ImportSelectStart.vue.d.ts +47 -0
- package/dist/runtime/components/We/Notification.d.vue.ts +7 -0
- package/dist/runtime/components/We/Notification.vue +49 -0
- package/dist/runtime/components/We/Notification.vue.d.ts +7 -0
- package/dist/runtime/components/We/S3Dropzone.d.vue.ts +17 -0
- package/dist/runtime/components/We/S3Dropzone.vue +527 -0
- package/dist/runtime/components/We/S3Dropzone.vue.d.ts +17 -0
- package/dist/runtime/components/We/Select.d.vue.ts +39 -0
- package/dist/runtime/components/We/Select.vue +354 -0
- package/dist/runtime/components/We/Select.vue.d.ts +39 -0
- package/dist/runtime/components/We/TipTap.d.vue.ts +26 -0
- package/dist/runtime/components/We/TipTap.vue +362 -0
- package/dist/runtime/components/We/TipTap.vue.d.ts +26 -0
- package/dist/runtime/components/We/datatable.props.d.ts +57 -0
- package/dist/runtime/components/We/datatable.props.js +60 -0
- package/dist/runtime/composables/datatable/useAutoFillHeight.d.ts +31 -0
- package/dist/runtime/composables/datatable/useAutoFillHeight.js +57 -0
- package/dist/runtime/composables/datatable/useDataTable.d.ts +33 -0
- package/dist/runtime/composables/datatable/useDataTable.js +161 -0
- package/dist/runtime/composables/datatable/useDatatableColumns.d.ts +12 -0
- package/dist/runtime/composables/datatable/useDatatableColumns.js +96 -0
- package/dist/runtime/composables/useApi.d.ts +56 -0
- package/dist/runtime/composables/useApi.js +230 -0
- package/dist/runtime/composables/useApiFetch.d.ts +2 -0
- package/dist/runtime/composables/useApiFetch.js +9 -0
- package/dist/runtime/composables/useApiUrl.d.ts +10 -0
- package/dist/runtime/composables/useApiUrl.js +37 -0
- package/dist/runtime/composables/useAuth.d.ts +9 -0
- package/dist/runtime/composables/useAuth.js +22 -0
- package/dist/runtime/composables/useBus.d.ts +8 -0
- package/dist/runtime/composables/useBus.js +18 -0
- package/dist/runtime/composables/useDateRangePresets.d.ts +21 -0
- package/dist/runtime/composables/useDateRangePresets.js +90 -0
- package/dist/runtime/composables/useForm.d.ts +29 -0
- package/dist/runtime/composables/useForm.js +74 -0
- package/dist/runtime/composables/useFormLock.d.ts +11 -0
- package/dist/runtime/composables/useFormLock.js +8 -0
- package/dist/runtime/composables/useFormWrapper.d.ts +16 -0
- package/dist/runtime/composables/useFormWrapper.js +36 -0
- package/dist/runtime/composables/useImportJob.d.ts +55 -0
- package/dist/runtime/composables/useImportJob.js +94 -0
- package/dist/runtime/composables/useLux.d.ts +1 -0
- package/dist/runtime/composables/useLux.js +8 -0
- package/dist/runtime/composables/useNotify.d.ts +12 -0
- package/dist/runtime/composables/useNotify.js +24 -0
- package/dist/runtime/composables/usePaginatedFetch.d.ts +24 -0
- package/dist/runtime/composables/usePaginatedFetch.js +154 -0
- package/dist/runtime/composables/useServerErrors.d.ts +16 -0
- package/dist/runtime/composables/useServerErrors.js +60 -0
- package/dist/runtime/composables/useValidators.d.ts +18 -0
- package/dist/runtime/composables/useValidators.js +56 -0
- package/dist/runtime/generator/code/dt.d.ts +8 -0
- package/dist/runtime/generator/code/dt.js +97 -0
- package/dist/runtime/generator/code/edit.d.ts +4 -0
- package/dist/runtime/generator/code/edit.js +41 -0
- package/dist/runtime/generator/code/form.d.ts +6 -0
- package/dist/runtime/generator/code/form.js +229 -0
- package/dist/runtime/generator/code/i18n.d.ts +5 -0
- package/dist/runtime/generator/code/i18n.js +43 -0
- package/dist/runtime/generator/code/index.d.ts +11 -0
- package/dist/runtime/generator/code/index.js +90 -0
- package/dist/runtime/generator/components/CodeSnippet.d.vue.ts +14 -0
- package/dist/runtime/generator/components/CodeSnippet.vue +49 -0
- package/dist/runtime/generator/components/CodeSnippet.vue.d.ts +14 -0
- package/dist/runtime/generator/components/Configuration.d.vue.ts +16 -0
- package/dist/runtime/generator/components/Configuration.vue +154 -0
- package/dist/runtime/generator/components/Configuration.vue.d.ts +16 -0
- package/dist/runtime/generator/components/GeneratorPage.d.vue.ts +50 -0
- package/dist/runtime/generator/components/GeneratorPage.vue +226 -0
- package/dist/runtime/generator/components/GeneratorPage.vue.d.ts +50 -0
- package/dist/runtime/generator/fs.d.ts +16 -0
- package/dist/runtime/generator/fs.js +79 -0
- package/dist/runtime/generator/index.d.vue.ts +52 -0
- package/dist/runtime/generator/index.vue +17 -0
- package/dist/runtime/generator/index.vue.d.ts +52 -0
- package/dist/runtime/internals/api.d.ts +3 -0
- package/dist/runtime/internals/api.js +16 -0
- package/dist/runtime/internals/bus.d.ts +1 -0
- package/dist/runtime/internals/bus.js +2 -0
- package/dist/runtime/internals/dt.d.ts +24 -0
- package/dist/runtime/internals/dt.js +57 -0
- package/dist/runtime/lang/en.json +211 -0
- package/dist/runtime/lang/it.json +211 -0
- package/dist/runtime/mixins/formValidator.d.ts +38 -0
- package/dist/runtime/mixins/formValidator.js +118 -0
- package/dist/runtime/plugins/api-legacy.d.ts +76 -0
- package/dist/runtime/plugins/api-legacy.js +11 -0
- package/dist/runtime/plugins/auth-legacy.d.ts +22 -0
- package/dist/runtime/plugins/auth-legacy.js +14 -0
- package/dist/runtime/plugins/bus-legacy.d.ts +6 -0
- package/dist/runtime/plugins/bus-legacy.js +9 -0
- package/dist/runtime/plugins/notify-legacy.d.ts +25 -0
- package/dist/runtime/plugins/notify-legacy.js +35 -0
- package/dist/runtime/plugins/portal.d.ts +2 -0
- package/dist/runtime/plugins/portal.js +5 -0
- package/dist/runtime/plugins/update-sanctum-app-config.d.ts +2 -0
- package/dist/runtime/plugins/update-sanctum-app-config.js +44 -0
- package/dist/runtime/plugins/vuetify-nuxt-icon.d.ts +4 -0
- package/dist/runtime/plugins/vuetify-nuxt-icon.js +30 -0
- package/dist/runtime/types/app-config.d.ts +24 -0
- package/dist/runtime/types/app-config.js +1 -0
- package/dist/runtime/types/icons.d.ts +82 -0
- package/dist/runtime/types/icons.js +84 -0
- package/dist/runtime/types/index.d.ts +2 -0
- package/dist/runtime/types/index.js +2 -0
- package/dist/runtime/types/module-options.d.ts +29 -0
- package/dist/runtime/types/module-options.js +0 -0
- package/dist/runtime/types/runtime-hooks.d.ts +17 -0
- package/dist/runtime/types/runtime-hooks.js +1 -0
- package/dist/runtime/utils/color.d.ts +10 -0
- package/dist/runtime/utils/color.js +38 -0
- package/dist/runtime/utils/file.d.ts +17 -0
- package/dist/runtime/utils/file.js +108 -0
- package/dist/runtime/utils/format.d.ts +1 -0
- package/dist/runtime/utils/format.js +14 -0
- package/dist/runtime/utils/make-enum.d.ts +15 -0
- package/dist/runtime/utils/make-enum.js +27 -0
- package/dist/runtime/utils/mergeDefaults.d.ts +1 -0
- package/dist/runtime/utils/mergeDefaults.js +18 -0
- package/dist/runtime/utils/object-to-formdata.d.ts +10 -0
- package/dist/runtime/utils/object-to-formdata.js +82 -0
- package/dist/runtime/utils/uuid.d.ts +1 -0
- package/dist/runtime/utils/uuid.js +9 -0
- package/dist/types.d.mts +9 -0
- package/package.json +92 -4
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ComputedRef } from 'vue';
|
|
2
|
+
export type ServerErrors<T> = {
|
|
3
|
+
[key in keyof T]?: string[];
|
|
4
|
+
};
|
|
5
|
+
export type UnTrackedServerErrors<T> = ServerErrors<T> & {
|
|
6
|
+
[key: string]: string[];
|
|
7
|
+
};
|
|
8
|
+
export declare function useServerErrors<T>(): {
|
|
9
|
+
serverErrors: ServerErrors<T>;
|
|
10
|
+
untrackedServerErrors: ComputedRef<UnTrackedServerErrors<T>>;
|
|
11
|
+
checkServerErrors: (error: any, options?: {
|
|
12
|
+
scroll: string;
|
|
13
|
+
notifyUntracked: boolean;
|
|
14
|
+
}) => Promise<boolean>;
|
|
15
|
+
clearServerErrors: () => void;
|
|
16
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { computed, nextTick, reactive } from "vue";
|
|
2
|
+
import { useNotify } from "./useNotify.js";
|
|
3
|
+
export function useServerErrors() {
|
|
4
|
+
const allServerErrors = reactive({});
|
|
5
|
+
const trackedErrors = reactive(/* @__PURE__ */ new Set());
|
|
6
|
+
const serverErrors = new Proxy(allServerErrors, {
|
|
7
|
+
get(target, key) {
|
|
8
|
+
if (typeof key !== "symbol" && (typeof key === "string" && !key.startsWith("__v_"))) {
|
|
9
|
+
trackedErrors.add(key);
|
|
10
|
+
}
|
|
11
|
+
return target[key];
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
const untrackedServerErrors = computed(() => {
|
|
15
|
+
return Object.fromEntries(
|
|
16
|
+
Object.entries(allServerErrors).filter(([key]) => !trackedErrors.has(key))
|
|
17
|
+
);
|
|
18
|
+
});
|
|
19
|
+
function decode(error) {
|
|
20
|
+
if (error?.response?.status === 422) {
|
|
21
|
+
const { errors } = error.response._data;
|
|
22
|
+
Object.assign(allServerErrors, errors ?? {});
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
function checkUntrackedServerErrors(notify = true) {
|
|
28
|
+
const hasUntrackedServerErrors = Object.keys(untrackedServerErrors.value).length > 0;
|
|
29
|
+
const errors = Object.values(serverErrors).map((e) => e.join(", ")).flat();
|
|
30
|
+
if (hasUntrackedServerErrors && errors.length > 0) {
|
|
31
|
+
notify && useNotify().error(errors.join(", "));
|
|
32
|
+
}
|
|
33
|
+
return errors;
|
|
34
|
+
}
|
|
35
|
+
async function checkServerErrors(error, options = { scroll: ".v-input.error--text", notifyUntracked: true }) {
|
|
36
|
+
clearServerErrors();
|
|
37
|
+
const errors = decode(error);
|
|
38
|
+
await nextTick(() => {
|
|
39
|
+
checkUntrackedServerErrors(options.notifyUntracked);
|
|
40
|
+
if (options.scroll) {
|
|
41
|
+
const selector = typeof options.scroll === "boolean" ? ".v-input.error--text" : options.scroll;
|
|
42
|
+
const inputsWithErrors = document.querySelectorAll(selector);
|
|
43
|
+
if (inputsWithErrors.length > 0) {
|
|
44
|
+
inputsWithErrors[0].scrollIntoView({ block: "center", behavior: "smooth" });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
return errors;
|
|
49
|
+
}
|
|
50
|
+
function clearServerErrors() {
|
|
51
|
+
Object.keys(allServerErrors).forEach((key) => delete allServerErrors[key]);
|
|
52
|
+
trackedErrors.clear();
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
serverErrors,
|
|
56
|
+
untrackedServerErrors,
|
|
57
|
+
checkServerErrors,
|
|
58
|
+
clearServerErrors
|
|
59
|
+
};
|
|
60
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
type InputValue = string | number | boolean | null | undefined;
|
|
2
|
+
type LengthValue = string | unknown[] | null | undefined;
|
|
3
|
+
export declare function useValidators(): {
|
|
4
|
+
validatorRequired: (value: InputValue) => string | true;
|
|
5
|
+
validatorRequiredArray: (val: InputValue | unknown[]) => string | true;
|
|
6
|
+
validatorRequiredArrayNotEmpty: (val: InputValue | unknown[]) => string | true;
|
|
7
|
+
validatorNotNull: (val: InputValue) => string | true;
|
|
8
|
+
validatorMin: (length: number) => (v: LengthValue) => string | true;
|
|
9
|
+
validatorMax: (length: number) => (v: LengthValue) => string | true;
|
|
10
|
+
validatorMaxFileSize: (size: number) => (v?: {
|
|
11
|
+
size: number;
|
|
12
|
+
} | null) => string | true;
|
|
13
|
+
validatorRequiredNumber: (val: InputValue) => string | true;
|
|
14
|
+
validatorEmail: (val: InputValue) => string | true;
|
|
15
|
+
validatorPhone: (val: InputValue) => string | true;
|
|
16
|
+
validatorEquals: (match: InputValue, message: string) => (v: InputValue) => string | true;
|
|
17
|
+
};
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { useI18n } from "#imports";
|
|
2
|
+
import { humanFileSize } from "../utils/format.js";
|
|
3
|
+
const EMAIL_PATTERN = /^(?:[^<>()[\]\\.,;:\s@"]+(?:\.[^<>()[\]\\.,;:\s@"]+)*|".+")@(?:\[\d{1,3}(?:\.\d{1,3}){3}\]|(?:[a-z0-9-]+\.)+[a-z]{2,})$/i;
|
|
4
|
+
export function useValidators() {
|
|
5
|
+
const { t } = useI18n();
|
|
6
|
+
function validatorRequired(value) {
|
|
7
|
+
return !!value || t("validators.required");
|
|
8
|
+
}
|
|
9
|
+
function validatorRequiredArray(val) {
|
|
10
|
+
return Array.isArray(val) || t("validators.required");
|
|
11
|
+
}
|
|
12
|
+
function validatorRequiredArrayNotEmpty(val) {
|
|
13
|
+
return Array.isArray(val) && val.length > 0 || t("validators.required");
|
|
14
|
+
}
|
|
15
|
+
function validatorNotNull(val) {
|
|
16
|
+
return val != null || t("validators.required");
|
|
17
|
+
}
|
|
18
|
+
function validatorMin(length) {
|
|
19
|
+
return (v) => !v || (v || "").length >= length || t("validators.minLength", { length });
|
|
20
|
+
}
|
|
21
|
+
function validatorMax(length) {
|
|
22
|
+
return (v) => (v || "").length <= length || t("validators.maxLength", { length });
|
|
23
|
+
}
|
|
24
|
+
function validatorMaxFileSize(size) {
|
|
25
|
+
return (v) => !v || v.size <= size || t("validators.maxFileSize", { size: humanFileSize(size, true) });
|
|
26
|
+
}
|
|
27
|
+
function validatorRequiredNumber(val) {
|
|
28
|
+
const n = Number.parseInt(String(val ?? ""), 10);
|
|
29
|
+
return !Number.isNaN(n) && typeof n === "number" || t("validators.required");
|
|
30
|
+
}
|
|
31
|
+
function validatorEmail(val) {
|
|
32
|
+
return !val || EMAIL_PATTERN.test(String(val)) || t("validators.email");
|
|
33
|
+
}
|
|
34
|
+
function validatorPhone(val) {
|
|
35
|
+
const pattern = /^\d+$/;
|
|
36
|
+
return !val || pattern.test(String(val)) || t("validators.phone");
|
|
37
|
+
}
|
|
38
|
+
function validatorEquals(match, message) {
|
|
39
|
+
return (v) => {
|
|
40
|
+
return match === v || message;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
validatorRequired,
|
|
45
|
+
validatorRequiredArray,
|
|
46
|
+
validatorRequiredArrayNotEmpty,
|
|
47
|
+
validatorNotNull,
|
|
48
|
+
validatorMin,
|
|
49
|
+
validatorMax,
|
|
50
|
+
validatorMaxFileSize,
|
|
51
|
+
validatorRequiredNumber,
|
|
52
|
+
validatorEmail,
|
|
53
|
+
validatorPhone,
|
|
54
|
+
validatorEquals
|
|
55
|
+
};
|
|
56
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { i18nRenderString } from './index.js'
|
|
2
|
+
|
|
3
|
+
function indexCode({ resourceName, url, editMode, formName, fields, i18n }) {
|
|
4
|
+
let dialogTemplate = ''
|
|
5
|
+
let actionsTemplate = ''
|
|
6
|
+
let dtProps = ''
|
|
7
|
+
let script = ''
|
|
8
|
+
|
|
9
|
+
switch (editMode) {
|
|
10
|
+
case 'form-wrapper':
|
|
11
|
+
dtProps = `
|
|
12
|
+
@click:row="edit"
|
|
13
|
+
@new="create"
|
|
14
|
+
`
|
|
15
|
+
script = `
|
|
16
|
+
const dt = useTemplateRef('dt')
|
|
17
|
+
const form = useTemplateRef('form')
|
|
18
|
+
|
|
19
|
+
const { dialog, formModel, loadingFormModel, create, edit } = useFormWrapper({
|
|
20
|
+
load: ({ id }) => {
|
|
21
|
+
return form.value.load(id)
|
|
22
|
+
const params = { with: '${fields.filter(f => f.paginate).map(f => f.fk_name ?? f.name).join(',')}' }
|
|
23
|
+
return useApi().$get(\`${resourceName}/\${id}\`, { params })
|
|
24
|
+
},
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
function closeAndRefresh() {
|
|
28
|
+
dialog.value = false
|
|
29
|
+
dt.value.reloadData()
|
|
30
|
+
}`
|
|
31
|
+
actionsTemplate = `<template #[\`item.actions\`]="{ item }">
|
|
32
|
+
<v-btn :loading="loadingFormModel === item.id" variant="tonal" icon @click="edit(item)"> <v-icon>$edit</v-icon> </v-btn>
|
|
33
|
+
</template>`
|
|
34
|
+
|
|
35
|
+
dialogTemplate = `
|
|
36
|
+
<form-wrapper v-model="dialog" scrollable max-width="700" form-name="form-${formName}">
|
|
37
|
+
<form-${formName}
|
|
38
|
+
ref="form"
|
|
39
|
+
v-model="formModel"
|
|
40
|
+
@update:model-value="closeAndRefresh"
|
|
41
|
+
@deleted="closeAndRefresh"
|
|
42
|
+
/>
|
|
43
|
+
</form-wrapper>`
|
|
44
|
+
break
|
|
45
|
+
|
|
46
|
+
case 'none':
|
|
47
|
+
dtProps = ':add-button="false"'
|
|
48
|
+
break
|
|
49
|
+
case 'page':
|
|
50
|
+
default:
|
|
51
|
+
dtProps = `
|
|
52
|
+
@click:row="edit"
|
|
53
|
+
@new="create"
|
|
54
|
+
`
|
|
55
|
+
|
|
56
|
+
script = `
|
|
57
|
+
function create() {
|
|
58
|
+
useRouter().push("${url}/new")
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function edit(item) {
|
|
62
|
+
useRouter().push(\`${url}/\${item.id}\`)
|
|
63
|
+
}
|
|
64
|
+
`
|
|
65
|
+
actionsTemplate = `<template #[\`item.actions\`]="{ item }">
|
|
66
|
+
<v-btn @click="edit(item)" variant="tonal" icon> <v-icon>$edit</v-icon> </v-btn>
|
|
67
|
+
</template>`
|
|
68
|
+
break
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return `<template>
|
|
72
|
+
<v-container fluid>
|
|
73
|
+
<v-row>
|
|
74
|
+
<v-col cols="12">
|
|
75
|
+
<we-header>
|
|
76
|
+
${i18nRenderString(i18n, `${resourceName}.title`)}
|
|
77
|
+
</we-header>
|
|
78
|
+
</v-col>
|
|
79
|
+
<v-col cols="12">
|
|
80
|
+
<we-datatable
|
|
81
|
+
ref="dt"
|
|
82
|
+
resource="${resourceName}"
|
|
83
|
+
${dtProps}
|
|
84
|
+
>
|
|
85
|
+
${actionsTemplate}
|
|
86
|
+
</we-datatable>
|
|
87
|
+
</v-col>
|
|
88
|
+
</v-row>
|
|
89
|
+
${dialogTemplate}
|
|
90
|
+
</v-container>
|
|
91
|
+
</template>
|
|
92
|
+
<script setup>
|
|
93
|
+
${script}
|
|
94
|
+
</script>`
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export { indexCode }
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
function editCode({ formName, url }) {
|
|
2
|
+
return `<template>
|
|
3
|
+
<v-container fluid>
|
|
4
|
+
<v-row>
|
|
5
|
+
<v-col cols="12">
|
|
6
|
+
<we-header>
|
|
7
|
+
<portal-target name="form-${formName}-title" />
|
|
8
|
+
</we-header>
|
|
9
|
+
</v-col>
|
|
10
|
+
<v-col cols="12">
|
|
11
|
+
<form-${formName} ref="form" @update:model-value="saved" @deleted="deleted" v-model="model" />
|
|
12
|
+
</v-col>
|
|
13
|
+
<v-col cols="12">
|
|
14
|
+
<portal-target name="form-${formName}-actions" />
|
|
15
|
+
</v-col>
|
|
16
|
+
</v-row>
|
|
17
|
+
</v-container>
|
|
18
|
+
</template>
|
|
19
|
+
|
|
20
|
+
<script setup>
|
|
21
|
+
const form = useTemplateRef('form')
|
|
22
|
+
const model = ref(null)
|
|
23
|
+
|
|
24
|
+
const id = computed(() => useRoute().params.id)
|
|
25
|
+
const isNew = computed(() => id.value === 'new')
|
|
26
|
+
|
|
27
|
+
onMounted(async () => {
|
|
28
|
+
if (!isNew.value) { model.value = await form.value.load(id.value) }
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
function saved({ id }) {
|
|
32
|
+
if (id) { useRouter().replace(\`${url}/\${id}\`) }
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function deleted() {
|
|
36
|
+
useRouter().back()
|
|
37
|
+
}
|
|
38
|
+
</script>`
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { editCode }
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { i18nRenderString } from './index.js'
|
|
2
|
+
|
|
3
|
+
function wrapCol(code) {
|
|
4
|
+
return `<v-col cols="12">
|
|
5
|
+
${code}
|
|
6
|
+
</v-col>`
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function templateFieldCode(f, resourceName, i18n) {
|
|
10
|
+
const { type, name } = f
|
|
11
|
+
|
|
12
|
+
const label = i18nRenderString(i18n, `${resourceName}.form.fields.${name}.label`, null, { inTemplate: true, raw: false })
|
|
13
|
+
|
|
14
|
+
const modelName = f.paginate ? f.fk_name ?? f.name : f.name
|
|
15
|
+
|
|
16
|
+
const common = `v-model="model.${modelName}"
|
|
17
|
+
:error-messages="serverErrors.${name}"
|
|
18
|
+
:rules="rules.${name}"
|
|
19
|
+
:label="${label}"`
|
|
20
|
+
|
|
21
|
+
if (f.foreignKeys?.length > 0) {
|
|
22
|
+
const { table } = f.foreignKeys.at(0)
|
|
23
|
+
return `<we-select
|
|
24
|
+
resource="${table}"
|
|
25
|
+
${common}
|
|
26
|
+
${f.paginate ? 'paginate' : ''}
|
|
27
|
+
/>`
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
switch (type) {
|
|
31
|
+
case 'string':
|
|
32
|
+
case 'text':
|
|
33
|
+
case 'varchar':
|
|
34
|
+
return `<v-text-field
|
|
35
|
+
${common}
|
|
36
|
+
/>`
|
|
37
|
+
|
|
38
|
+
case 'integer':
|
|
39
|
+
case 'number':
|
|
40
|
+
case 'float':
|
|
41
|
+
case 'double':
|
|
42
|
+
case 'decimal':
|
|
43
|
+
return `<v-text-field
|
|
44
|
+
type="number"
|
|
45
|
+
${common}
|
|
46
|
+
/>`
|
|
47
|
+
|
|
48
|
+
case 'datetime':
|
|
49
|
+
case 'timestamp':
|
|
50
|
+
return `<we-date-picker
|
|
51
|
+
type="datetime"
|
|
52
|
+
${common}
|
|
53
|
+
/>`
|
|
54
|
+
|
|
55
|
+
case 'date':
|
|
56
|
+
return `<we-date-picker
|
|
57
|
+
${common}
|
|
58
|
+
/>`
|
|
59
|
+
|
|
60
|
+
case 'boolean':
|
|
61
|
+
return `<v-checkbox
|
|
62
|
+
${common}
|
|
63
|
+
/>`
|
|
64
|
+
|
|
65
|
+
default:
|
|
66
|
+
return `<!-- unkown ${f.name} ${f.type} -->
|
|
67
|
+
<v-textarea
|
|
68
|
+
${common}
|
|
69
|
+
/>`
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function join(arr, separator = ', ', addLastSeparator = true) {
|
|
74
|
+
const res = arr.join(separator)
|
|
75
|
+
return addLastSeparator && arr.length ? res + separator : res
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function fieldCode(f) {
|
|
79
|
+
const { name, default: defaultValue, notnull, length, type } = f
|
|
80
|
+
|
|
81
|
+
const modelName = f.paginate ? f.fk_name ?? f.name : f.name
|
|
82
|
+
const usedValidators = []
|
|
83
|
+
|
|
84
|
+
const validators = []
|
|
85
|
+
if (notnull) {
|
|
86
|
+
if (type !== 'boolean') {
|
|
87
|
+
validators.push('validatorRequired')
|
|
88
|
+
usedValidators.push('validatorRequired')
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (length && !f.foreignKeys) {
|
|
93
|
+
validators.push(`validatorMax(${length})`)
|
|
94
|
+
usedValidators.push(`validatorMax`)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const data = `${modelName}: ${defaultValue},`
|
|
98
|
+
const rules = `${name}: [${validators.join(', ')}],`
|
|
99
|
+
const mapping = f.paginate ? `${name}: ${modelName}?.id,` : ''
|
|
100
|
+
|
|
101
|
+
return { data, rules, mapping, usedValidators }
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function formCode({ fields, resourceName, formName, i18n }) {
|
|
105
|
+
const fieldsCode = fields.map(f => templateFieldCode(f, resourceName, i18n)).map(wrapCol).join('\n\n')
|
|
106
|
+
const template = `<template>
|
|
107
|
+
<v-form ref="form">
|
|
108
|
+
<v-row>
|
|
109
|
+
<portal to="form-${formName}-title">
|
|
110
|
+
<span v-if="isNew">${i18nRenderString(i18n, `${resourceName}.form.actions.create.title`)}</span>
|
|
111
|
+
<span v-else>${i18nRenderString(i18n, `${resourceName}.form.actions.edit.title`)}</span>
|
|
112
|
+
</portal>
|
|
113
|
+
${fieldsCode}
|
|
114
|
+
</v-row>
|
|
115
|
+
<portal to="form-${formName}-actions">
|
|
116
|
+
<we-btn-delete-confirm
|
|
117
|
+
v-if="!isNew"
|
|
118
|
+
class="mr-2"
|
|
119
|
+
:on-delete="deleteModel"
|
|
120
|
+
/>
|
|
121
|
+
|
|
122
|
+
<v-btn color="primary" size="large" :loading="loading" @click="save"
|
|
123
|
+
><v-icon start>$save</v-icon> ${i18nRenderString(i18n, 'forms.buttons.save', 'Salva')}</v-btn
|
|
124
|
+
>
|
|
125
|
+
</portal>
|
|
126
|
+
</v-form>
|
|
127
|
+
</template>
|
|
128
|
+
`
|
|
129
|
+
const _fieldsCode = fields.map(fieldCode)
|
|
130
|
+
|
|
131
|
+
const { model, validators, mappings } = _fieldsCode.reduce((ret, { data, rules, mapping }, index) => {
|
|
132
|
+
const terminator = index < fields.length - 1 ? '\n' : ''
|
|
133
|
+
ret.model += `${data}${terminator}`
|
|
134
|
+
ret.validators += `${rules}${terminator}`
|
|
135
|
+
if (mapping) {
|
|
136
|
+
ret.mappings += `${mapping}${terminator}`
|
|
137
|
+
}
|
|
138
|
+
return ret
|
|
139
|
+
}, { model: '', validators: '', mappings: '' })
|
|
140
|
+
|
|
141
|
+
const usedValidators = [...new Set(_fieldsCode.flatMap(f => f.usedValidators))].join(', ')
|
|
142
|
+
|
|
143
|
+
const script = `
|
|
144
|
+
<script setup>
|
|
145
|
+
const props = defineProps({
|
|
146
|
+
extraParams: {
|
|
147
|
+
type: Object,
|
|
148
|
+
default: () => ({}),
|
|
149
|
+
},
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
const emit = defineEmits(['deleted'])
|
|
153
|
+
|
|
154
|
+
${i18n ? 'const { t } = useI18n()' : ''}
|
|
155
|
+
|
|
156
|
+
const defaultValues = {
|
|
157
|
+
${model}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function load(id) {
|
|
161
|
+
const params = { with: '${fields.filter(f => f.paginate).map(f => f.fk_name ?? f.name).join(',')}' }
|
|
162
|
+
return useApi().$get(\`${resourceName}/\${id}\`, { params })
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
defineExpose({ load })
|
|
166
|
+
|
|
167
|
+
const modelValue = defineModel('modelValue', { type: Object, default: undefined })
|
|
168
|
+
const id = computed(() => modelValue.value?.id)
|
|
169
|
+
const isNew = computed(() => !id.value)
|
|
170
|
+
|
|
171
|
+
const { ${usedValidators} } = useValidators()
|
|
172
|
+
|
|
173
|
+
const {
|
|
174
|
+
save,
|
|
175
|
+
loading,
|
|
176
|
+
model,
|
|
177
|
+
updateModel,
|
|
178
|
+
resetValidation,
|
|
179
|
+
serverErrors,
|
|
180
|
+
} = useForm({
|
|
181
|
+
form: useTemplateRef('form'),
|
|
182
|
+
initialValues: defaultValues,
|
|
183
|
+
onSubmit,
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
const rules = computed(() => {
|
|
188
|
+
return {
|
|
189
|
+
${validators}
|
|
190
|
+
}
|
|
191
|
+
})
|
|
192
|
+
|
|
193
|
+
watch(modelValue, (val) => {
|
|
194
|
+
resetValidation()
|
|
195
|
+
updateModel(val)
|
|
196
|
+
}, { immediate: true })
|
|
197
|
+
|
|
198
|
+
async function onSubmit() {
|
|
199
|
+
const {${join(fields.filter(f => f.paginate).map(f => f.fk_name))} ...values } = model.value
|
|
200
|
+
|
|
201
|
+
const data = {
|
|
202
|
+
...props.extraParams,
|
|
203
|
+
...values,
|
|
204
|
+
${mappings}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const method = isNew.value ? 'post' : 'put'
|
|
208
|
+
const url = isNew.value ? '${resourceName}' : \`${resourceName}/\${id.value}\`
|
|
209
|
+
|
|
210
|
+
const res = await useApi().$request({ method, url, data })
|
|
211
|
+
useNotify().success(${i18nRenderString(i18n, `${resourceName}.form.messages.saveSuccess`, null, { inTemplate: false, raw: false })})
|
|
212
|
+
modelValue.value = res
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
async function deleteModel() {
|
|
216
|
+
await useApi().$delete(\`${resourceName}/\${id.value}\`)
|
|
217
|
+
useNotify().success(${i18nRenderString(i18n, `${resourceName}.form.messages.delete`, null, { inTemplate: false, raw: false })})
|
|
218
|
+
emit('deleted')
|
|
219
|
+
}
|
|
220
|
+
</script>
|
|
221
|
+
`
|
|
222
|
+
|
|
223
|
+
const vue = `${template}
|
|
224
|
+
${script}`
|
|
225
|
+
|
|
226
|
+
return vue
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export { formCode }
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
function i18nCode({ fields, resourceName, flat = true }) {
|
|
2
|
+
fields = fields.reduce((ret, { name }) => ({ ...ret, [name]: { label: name } }), {})
|
|
3
|
+
let keys = {
|
|
4
|
+
[resourceName]: {
|
|
5
|
+
title: resourceName,
|
|
6
|
+
form: {
|
|
7
|
+
actions: {
|
|
8
|
+
edit: {
|
|
9
|
+
title: `Modifica ${resourceName}`,
|
|
10
|
+
},
|
|
11
|
+
create: {
|
|
12
|
+
title: `Nuova ${resourceName}`,
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
fields: { ...fields },
|
|
16
|
+
messages: {
|
|
17
|
+
saveSuccess: `${resourceName} salvato con successo`,
|
|
18
|
+
delete: `${resourceName} eliminato con successo`,
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (flat) {
|
|
25
|
+
keys = flattenJson(keys)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return JSON.stringify(keys, null, 2)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function flattenJson(json, prefix = '') {
|
|
32
|
+
let ret = {}
|
|
33
|
+
for (const key in json) {
|
|
34
|
+
if (typeof json[key] === 'object') {
|
|
35
|
+
ret = { ...ret, ...flattenJson(json[key], `${prefix}${key}.`) }
|
|
36
|
+
} else {
|
|
37
|
+
ret[`${prefix}${key}`] = json[key]
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return ret
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export { i18nCode }
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export function cleanResourceName(name?: string): string;
|
|
2
|
+
export default generate;
|
|
3
|
+
export function i18nRenderString(i18n: any, key: any, value: any, options?: {
|
|
4
|
+
inTemplate: boolean;
|
|
5
|
+
raw: boolean;
|
|
6
|
+
}): any;
|
|
7
|
+
declare function generate(fields: any, conf: any): (boolean | {
|
|
8
|
+
name: string;
|
|
9
|
+
mode: string;
|
|
10
|
+
code: string;
|
|
11
|
+
})[];
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { indexCode } from './dt.js'
|
|
2
|
+
import { editCode } from './edit.js'
|
|
3
|
+
import { formCode } from './form.js'
|
|
4
|
+
import { i18nCode } from './i18n.js'
|
|
5
|
+
|
|
6
|
+
let generatedI18n = null
|
|
7
|
+
|
|
8
|
+
function componentName(name) {
|
|
9
|
+
return cleanResourceName(name)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function makeUrl(name = '', prefix = '/') {
|
|
13
|
+
name = cleanResourceName(name)
|
|
14
|
+
return `${prefix}${name}`
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function cleanResourceName(name = '') {
|
|
18
|
+
name = name.replaceAll('_', '-')
|
|
19
|
+
return name
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function toPascalCase(text) {
|
|
23
|
+
return text.replace(/(^\w|-\w)/g, clearAndUpper)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function clearAndUpper(text) {
|
|
27
|
+
return text.replace(/-/, '').toUpperCase()
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function generate(fields, conf) {
|
|
31
|
+
if (!conf.prefix.endsWith('/')) { conf.prefix += '/' }
|
|
32
|
+
|
|
33
|
+
const { part, resourceName, prefix, editMode, i18n: i18nMode } = conf
|
|
34
|
+
|
|
35
|
+
const formName = componentName(resourceName)
|
|
36
|
+
const url = makeUrl(part, prefix)
|
|
37
|
+
const pagePrefix = `app/pages/${url.substring(1)}`
|
|
38
|
+
const editInPage = editMode === 'page'
|
|
39
|
+
|
|
40
|
+
const pascalComponentName = toPascalCase(`form-${formName}`)
|
|
41
|
+
|
|
42
|
+
generatedI18n = {
|
|
43
|
+
name: 'i18n/locales/it.json',
|
|
44
|
+
mode: 'append-json',
|
|
45
|
+
code: i18nCode({ fields, resourceName, flat: conf.i18n === 'flat' }),
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const index = {
|
|
49
|
+
name: `${pagePrefix}${editInPage ? '/index' : ''}.vue`,
|
|
50
|
+
mode: 'write',
|
|
51
|
+
code: indexCode({ resourceName, url, editMode, formName, fields, i18n: i18nMode }),
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const edit = {
|
|
55
|
+
name: `${pagePrefix}/[id].vue`,
|
|
56
|
+
mode: 'write',
|
|
57
|
+
code: editCode({ resourceName, formName, url, fields, i18n: i18nMode }),
|
|
58
|
+
}
|
|
59
|
+
const form = {
|
|
60
|
+
name: `app/components/${pascalComponentName}.vue`,
|
|
61
|
+
mode: 'write',
|
|
62
|
+
code: formCode({ fields, resourceName, formName, i18n: i18nMode }),
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return [
|
|
66
|
+
index,
|
|
67
|
+
form,
|
|
68
|
+
editInPage ? edit : false,
|
|
69
|
+
i18nMode ? generatedI18n : false,
|
|
70
|
+
].filter(Boolean)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function i18nRenderString(i18n, key, value, options = { inTemplate: true, raw: true }) {
|
|
74
|
+
if (!i18n) {
|
|
75
|
+
if (value) {
|
|
76
|
+
return !options.raw ? `'${value}'` : value
|
|
77
|
+
}
|
|
78
|
+
const text = key.split('.').reduce((acc, part) => acc && acc[part], JSON.parse(generatedI18n.code))
|
|
79
|
+
return !options.raw ? `'${text}'` : text
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (options.inTemplate) {
|
|
83
|
+
return options.raw ? `{{ $t('${key}') }}` : `$t('${key}')`
|
|
84
|
+
} else {
|
|
85
|
+
return `t('${key}')`
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export { i18nRenderString }
|
|
90
|
+
export default generate
|