@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.
Files changed (208) hide show
  1. package/LICENSE +1 -0
  2. package/README.md +115 -2
  3. package/dist/module.d.mts +7 -0
  4. package/dist/module.json +12 -0
  5. package/dist/module.mjs +250 -0
  6. package/dist/runtime/components/We/Autocomplete.d.vue.ts +13 -0
  7. package/dist/runtime/components/We/Autocomplete.vue +91 -0
  8. package/dist/runtime/components/We/Autocomplete.vue.d.ts +13 -0
  9. package/dist/runtime/components/We/BoldText.d.vue.ts +17 -0
  10. package/dist/runtime/components/We/BoldText.vue +29 -0
  11. package/dist/runtime/components/We/BoldText.vue.d.ts +17 -0
  12. package/dist/runtime/components/We/ColorPicker.d.vue.ts +11 -0
  13. package/dist/runtime/components/We/ColorPicker.vue +199 -0
  14. package/dist/runtime/components/We/ColorPicker.vue.d.ts +11 -0
  15. package/dist/runtime/components/We/ConfirmDialog.d.vue.ts +104 -0
  16. package/dist/runtime/components/We/ConfirmDialog.vue +143 -0
  17. package/dist/runtime/components/We/ConfirmDialog.vue.d.ts +104 -0
  18. package/dist/runtime/components/We/Datatable.d.vue.ts +40 -0
  19. package/dist/runtime/components/We/Datatable.vue +87 -0
  20. package/dist/runtime/components/We/Datatable.vue.d.ts +40 -0
  21. package/dist/runtime/components/We/DatatableInternal.d.vue.ts +194 -0
  22. package/dist/runtime/components/We/DatatableInternal.vue +638 -0
  23. package/dist/runtime/components/We/DatatableInternal.vue.d.ts +194 -0
  24. package/dist/runtime/components/We/DatePicker.d.vue.ts +51 -0
  25. package/dist/runtime/components/We/DatePicker.vue +901 -0
  26. package/dist/runtime/components/We/DatePicker.vue.d.ts +51 -0
  27. package/dist/runtime/components/We/Dt/Actions.d.vue.ts +51 -0
  28. package/dist/runtime/components/We/Dt/Actions.vue +106 -0
  29. package/dist/runtime/components/We/Dt/Actions.vue.d.ts +51 -0
  30. package/dist/runtime/components/We/Dt/BooleanFormatter.d.vue.ts +8 -0
  31. package/dist/runtime/components/We/Dt/BooleanFormatter.vue +26 -0
  32. package/dist/runtime/components/We/Dt/BooleanFormatter.vue.d.ts +8 -0
  33. package/dist/runtime/components/We/Dt/CardFilterContainer.d.vue.ts +17 -0
  34. package/dist/runtime/components/We/Dt/CardFilterContainer.vue +60 -0
  35. package/dist/runtime/components/We/Dt/CardFilterContainer.vue.d.ts +17 -0
  36. package/dist/runtime/components/We/Dt/CheckboxFilter.d.vue.ts +16 -0
  37. package/dist/runtime/components/We/Dt/CheckboxFilter.vue +47 -0
  38. package/dist/runtime/components/We/Dt/CheckboxFilter.vue.d.ts +16 -0
  39. package/dist/runtime/components/We/Dt/ChipGroupSelect.d.vue.ts +7 -0
  40. package/dist/runtime/components/We/Dt/ChipGroupSelect.vue +35 -0
  41. package/dist/runtime/components/We/Dt/ChipGroupSelect.vue.d.ts +7 -0
  42. package/dist/runtime/components/We/Dt/ClusterFilter.d.vue.ts +18 -0
  43. package/dist/runtime/components/We/Dt/ClusterFilter.vue +68 -0
  44. package/dist/runtime/components/We/Dt/ClusterFilter.vue.d.ts +18 -0
  45. package/dist/runtime/components/We/Dt/DatasetFormatter.d.vue.ts +19 -0
  46. package/dist/runtime/components/We/Dt/DatasetFormatter.vue +65 -0
  47. package/dist/runtime/components/We/Dt/DatasetFormatter.vue.d.ts +19 -0
  48. package/dist/runtime/components/We/Dt/DaterangeFilter.d.vue.ts +28 -0
  49. package/dist/runtime/components/We/Dt/DaterangeFilter.vue +140 -0
  50. package/dist/runtime/components/We/Dt/DaterangeFilter.vue.d.ts +28 -0
  51. package/dist/runtime/components/We/Dt/Filter.d.vue.ts +7 -0
  52. package/dist/runtime/components/We/Dt/Filter.vue +234 -0
  53. package/dist/runtime/components/We/Dt/Filter.vue.d.ts +7 -0
  54. package/dist/runtime/components/We/Dt/Filters.d.vue.ts +6 -0
  55. package/dist/runtime/components/We/Dt/Filters.vue +24 -0
  56. package/dist/runtime/components/We/Dt/Filters.vue.d.ts +6 -0
  57. package/dist/runtime/components/We/Dt/LuxonFormatter.d.vue.ts +12 -0
  58. package/dist/runtime/components/We/Dt/LuxonFormatter.vue +23 -0
  59. package/dist/runtime/components/We/Dt/LuxonFormatter.vue.d.ts +12 -0
  60. package/dist/runtime/components/We/Dt/SelectFilter.d.vue.ts +60 -0
  61. package/dist/runtime/components/We/Dt/SelectFilter.vue +333 -0
  62. package/dist/runtime/components/We/Dt/SelectFilter.vue.d.ts +60 -0
  63. package/dist/runtime/components/We/Dt/SelectResourceFilter.d.vue.ts +43 -0
  64. package/dist/runtime/components/We/Dt/SelectResourceFilter.vue +127 -0
  65. package/dist/runtime/components/We/Dt/SelectResourceFilter.vue.d.ts +43 -0
  66. package/dist/runtime/components/We/Dt/dt.types.d.ts +8 -0
  67. package/dist/runtime/components/We/EndpointSwitcher.d.vue.ts +12 -0
  68. package/dist/runtime/components/We/EndpointSwitcher.vue +256 -0
  69. package/dist/runtime/components/We/EndpointSwitcher.vue.d.ts +12 -0
  70. package/dist/runtime/components/We/Import.d.vue.ts +118 -0
  71. package/dist/runtime/components/We/Import.vue +730 -0
  72. package/dist/runtime/components/We/Import.vue.d.ts +118 -0
  73. package/dist/runtime/components/We/ImportDefaultValues.d.vue.ts +3666 -0
  74. package/dist/runtime/components/We/ImportDefaultValues.vue +115 -0
  75. package/dist/runtime/components/We/ImportDefaultValues.vue.d.ts +3666 -0
  76. package/dist/runtime/components/We/ImportMatchColumns.d.vue.ts +66 -0
  77. package/dist/runtime/components/We/ImportMatchColumns.vue +172 -0
  78. package/dist/runtime/components/We/ImportMatchColumns.vue.d.ts +66 -0
  79. package/dist/runtime/components/We/ImportPreviewResults.d.vue.ts +38 -0
  80. package/dist/runtime/components/We/ImportPreviewResults.vue +165 -0
  81. package/dist/runtime/components/We/ImportPreviewResults.vue.d.ts +38 -0
  82. package/dist/runtime/components/We/ImportSelectStart.d.vue.ts +47 -0
  83. package/dist/runtime/components/We/ImportSelectStart.vue +106 -0
  84. package/dist/runtime/components/We/ImportSelectStart.vue.d.ts +47 -0
  85. package/dist/runtime/components/We/Notification.d.vue.ts +7 -0
  86. package/dist/runtime/components/We/Notification.vue +49 -0
  87. package/dist/runtime/components/We/Notification.vue.d.ts +7 -0
  88. package/dist/runtime/components/We/S3Dropzone.d.vue.ts +17 -0
  89. package/dist/runtime/components/We/S3Dropzone.vue +527 -0
  90. package/dist/runtime/components/We/S3Dropzone.vue.d.ts +17 -0
  91. package/dist/runtime/components/We/Select.d.vue.ts +39 -0
  92. package/dist/runtime/components/We/Select.vue +354 -0
  93. package/dist/runtime/components/We/Select.vue.d.ts +39 -0
  94. package/dist/runtime/components/We/TipTap.d.vue.ts +26 -0
  95. package/dist/runtime/components/We/TipTap.vue +362 -0
  96. package/dist/runtime/components/We/TipTap.vue.d.ts +26 -0
  97. package/dist/runtime/components/We/datatable.props.d.ts +57 -0
  98. package/dist/runtime/components/We/datatable.props.js +60 -0
  99. package/dist/runtime/composables/datatable/useAutoFillHeight.d.ts +31 -0
  100. package/dist/runtime/composables/datatable/useAutoFillHeight.js +57 -0
  101. package/dist/runtime/composables/datatable/useDataTable.d.ts +33 -0
  102. package/dist/runtime/composables/datatable/useDataTable.js +161 -0
  103. package/dist/runtime/composables/datatable/useDatatableColumns.d.ts +12 -0
  104. package/dist/runtime/composables/datatable/useDatatableColumns.js +96 -0
  105. package/dist/runtime/composables/useApi.d.ts +56 -0
  106. package/dist/runtime/composables/useApi.js +230 -0
  107. package/dist/runtime/composables/useApiFetch.d.ts +2 -0
  108. package/dist/runtime/composables/useApiFetch.js +9 -0
  109. package/dist/runtime/composables/useApiUrl.d.ts +10 -0
  110. package/dist/runtime/composables/useApiUrl.js +37 -0
  111. package/dist/runtime/composables/useAuth.d.ts +9 -0
  112. package/dist/runtime/composables/useAuth.js +22 -0
  113. package/dist/runtime/composables/useBus.d.ts +8 -0
  114. package/dist/runtime/composables/useBus.js +18 -0
  115. package/dist/runtime/composables/useDateRangePresets.d.ts +21 -0
  116. package/dist/runtime/composables/useDateRangePresets.js +90 -0
  117. package/dist/runtime/composables/useForm.d.ts +29 -0
  118. package/dist/runtime/composables/useForm.js +74 -0
  119. package/dist/runtime/composables/useFormLock.d.ts +11 -0
  120. package/dist/runtime/composables/useFormLock.js +8 -0
  121. package/dist/runtime/composables/useFormWrapper.d.ts +16 -0
  122. package/dist/runtime/composables/useFormWrapper.js +36 -0
  123. package/dist/runtime/composables/useImportJob.d.ts +55 -0
  124. package/dist/runtime/composables/useImportJob.js +94 -0
  125. package/dist/runtime/composables/useLux.d.ts +1 -0
  126. package/dist/runtime/composables/useLux.js +8 -0
  127. package/dist/runtime/composables/useNotify.d.ts +12 -0
  128. package/dist/runtime/composables/useNotify.js +24 -0
  129. package/dist/runtime/composables/usePaginatedFetch.d.ts +24 -0
  130. package/dist/runtime/composables/usePaginatedFetch.js +154 -0
  131. package/dist/runtime/composables/useServerErrors.d.ts +16 -0
  132. package/dist/runtime/composables/useServerErrors.js +60 -0
  133. package/dist/runtime/composables/useValidators.d.ts +18 -0
  134. package/dist/runtime/composables/useValidators.js +56 -0
  135. package/dist/runtime/generator/code/dt.d.ts +8 -0
  136. package/dist/runtime/generator/code/dt.js +97 -0
  137. package/dist/runtime/generator/code/edit.d.ts +4 -0
  138. package/dist/runtime/generator/code/edit.js +41 -0
  139. package/dist/runtime/generator/code/form.d.ts +6 -0
  140. package/dist/runtime/generator/code/form.js +229 -0
  141. package/dist/runtime/generator/code/i18n.d.ts +5 -0
  142. package/dist/runtime/generator/code/i18n.js +43 -0
  143. package/dist/runtime/generator/code/index.d.ts +11 -0
  144. package/dist/runtime/generator/code/index.js +90 -0
  145. package/dist/runtime/generator/components/CodeSnippet.d.vue.ts +14 -0
  146. package/dist/runtime/generator/components/CodeSnippet.vue +49 -0
  147. package/dist/runtime/generator/components/CodeSnippet.vue.d.ts +14 -0
  148. package/dist/runtime/generator/components/Configuration.d.vue.ts +16 -0
  149. package/dist/runtime/generator/components/Configuration.vue +154 -0
  150. package/dist/runtime/generator/components/Configuration.vue.d.ts +16 -0
  151. package/dist/runtime/generator/components/GeneratorPage.d.vue.ts +50 -0
  152. package/dist/runtime/generator/components/GeneratorPage.vue +226 -0
  153. package/dist/runtime/generator/components/GeneratorPage.vue.d.ts +50 -0
  154. package/dist/runtime/generator/fs.d.ts +16 -0
  155. package/dist/runtime/generator/fs.js +79 -0
  156. package/dist/runtime/generator/index.d.vue.ts +52 -0
  157. package/dist/runtime/generator/index.vue +17 -0
  158. package/dist/runtime/generator/index.vue.d.ts +52 -0
  159. package/dist/runtime/internals/api.d.ts +3 -0
  160. package/dist/runtime/internals/api.js +16 -0
  161. package/dist/runtime/internals/bus.d.ts +1 -0
  162. package/dist/runtime/internals/bus.js +2 -0
  163. package/dist/runtime/internals/dt.d.ts +24 -0
  164. package/dist/runtime/internals/dt.js +57 -0
  165. package/dist/runtime/lang/en.json +211 -0
  166. package/dist/runtime/lang/it.json +211 -0
  167. package/dist/runtime/mixins/formValidator.d.ts +38 -0
  168. package/dist/runtime/mixins/formValidator.js +118 -0
  169. package/dist/runtime/plugins/api-legacy.d.ts +76 -0
  170. package/dist/runtime/plugins/api-legacy.js +11 -0
  171. package/dist/runtime/plugins/auth-legacy.d.ts +22 -0
  172. package/dist/runtime/plugins/auth-legacy.js +14 -0
  173. package/dist/runtime/plugins/bus-legacy.d.ts +6 -0
  174. package/dist/runtime/plugins/bus-legacy.js +9 -0
  175. package/dist/runtime/plugins/notify-legacy.d.ts +25 -0
  176. package/dist/runtime/plugins/notify-legacy.js +35 -0
  177. package/dist/runtime/plugins/portal.d.ts +2 -0
  178. package/dist/runtime/plugins/portal.js +5 -0
  179. package/dist/runtime/plugins/update-sanctum-app-config.d.ts +2 -0
  180. package/dist/runtime/plugins/update-sanctum-app-config.js +44 -0
  181. package/dist/runtime/plugins/vuetify-nuxt-icon.d.ts +4 -0
  182. package/dist/runtime/plugins/vuetify-nuxt-icon.js +30 -0
  183. package/dist/runtime/types/app-config.d.ts +24 -0
  184. package/dist/runtime/types/app-config.js +1 -0
  185. package/dist/runtime/types/icons.d.ts +82 -0
  186. package/dist/runtime/types/icons.js +84 -0
  187. package/dist/runtime/types/index.d.ts +2 -0
  188. package/dist/runtime/types/index.js +2 -0
  189. package/dist/runtime/types/module-options.d.ts +29 -0
  190. package/dist/runtime/types/module-options.js +0 -0
  191. package/dist/runtime/types/runtime-hooks.d.ts +17 -0
  192. package/dist/runtime/types/runtime-hooks.js +1 -0
  193. package/dist/runtime/utils/color.d.ts +10 -0
  194. package/dist/runtime/utils/color.js +38 -0
  195. package/dist/runtime/utils/file.d.ts +17 -0
  196. package/dist/runtime/utils/file.js +108 -0
  197. package/dist/runtime/utils/format.d.ts +1 -0
  198. package/dist/runtime/utils/format.js +14 -0
  199. package/dist/runtime/utils/make-enum.d.ts +15 -0
  200. package/dist/runtime/utils/make-enum.js +27 -0
  201. package/dist/runtime/utils/mergeDefaults.d.ts +1 -0
  202. package/dist/runtime/utils/mergeDefaults.js +18 -0
  203. package/dist/runtime/utils/object-to-formdata.d.ts +10 -0
  204. package/dist/runtime/utils/object-to-formdata.js +82 -0
  205. package/dist/runtime/utils/uuid.d.ts +1 -0
  206. package/dist/runtime/utils/uuid.js +9 -0
  207. package/dist/types.d.mts +9 -0
  208. package/package.json +92 -4
@@ -0,0 +1,21 @@
1
+ import type { ComputedRef } from 'vue';
2
+ export declare const PRESET_IDENTIFIERS: readonly ["today", "yesterday", "this-week", "last-week", "this-month", "last-month", "this-year", "last-year", "last-7-days", "last-30-days", "last-90-days"];
3
+ export type PresetIdentifier = typeof PRESET_IDENTIFIERS[number];
4
+ export interface PresetDate {
5
+ label: string;
6
+ value: string[];
7
+ }
8
+ export declare const BETWEEN_OPERATOR: "between";
9
+ export type PresetDateProp = PresetIdentifier | PresetDate;
10
+ export declare function useDateRangePresets(options?: {
11
+ withTime?: boolean;
12
+ }): {
13
+ getDateRange: (identifier: PresetIdentifier) => PresetDate | undefined;
14
+ defaultPresets: ComputedRef<PresetDate[]>;
15
+ resolvePresets: (presets: PresetDateProp[]) => PresetDate[];
16
+ getFilterValue: (preset: PresetIdentifier, noOperator?: boolean) => string[] | {
17
+ operator: "between";
18
+ value: string[];
19
+ } | undefined;
20
+ PRESET_IDENTIFIERS: readonly ["today", "yesterday", "this-week", "last-week", "this-month", "last-month", "this-year", "last-year", "last-7-days", "last-30-days", "last-90-days"];
21
+ };
@@ -0,0 +1,90 @@
1
+ import { useI18n } from "#imports";
2
+ import { DateTime } from "luxon";
3
+ import { computed } from "vue";
4
+ export const PRESET_IDENTIFIERS = [
5
+ "today",
6
+ "yesterday",
7
+ "this-week",
8
+ "last-week",
9
+ "this-month",
10
+ "last-month",
11
+ "this-year",
12
+ "last-year",
13
+ "last-7-days",
14
+ "last-30-days",
15
+ "last-90-days"
16
+ ];
17
+ export const BETWEEN_OPERATOR = "between";
18
+ export function useDateRangePresets(options = {}) {
19
+ const { t } = useI18n();
20
+ const getDateRange = (identifier) => {
21
+ const base = DateTime.now();
22
+ const ranges = [
23
+ { key: "today", value: [base.startOf("day"), base.endOf("day")], label: t("ranges.today.label") },
24
+ { key: "yesterday", value: [base.minus({ day: 1 }).startOf("day"), base.minus({ day: 1 }).endOf("day")], label: t("ranges.yesterday.label") },
25
+ { key: "this-week", value: [base.startOf("week"), base.endOf("week")], label: t("ranges.this_week.label") },
26
+ { key: "last-week", value: [base.minus({ week: 1 }).startOf("week"), base.minus({ week: 1 }).endOf("week")], label: t("ranges.last_week.label") },
27
+ { key: "this-month", value: [base.startOf("month"), base.endOf("month")], label: t("ranges.this_month.label") },
28
+ { key: "last-month", value: [base.minus({ month: 1 }).startOf("month"), base.minus({ month: 1 }).endOf("month")], label: t("ranges.last_month.label") },
29
+ { key: "this-year", value: [base.startOf("year"), base.endOf("year")], label: t("ranges.this_year.label") },
30
+ { key: "last-year", value: [base.minus({ year: 1 }).startOf("year"), base.minus({ year: 1 }).endOf("year")], label: t("ranges.last_year.label") },
31
+ { key: "last-7-days", value: [base.minus({ day: 6 }).startOf("day"), base.endOf("day")], label: t("ranges.last_7_days.label") },
32
+ { key: "last-30-days", value: [base.minus({ day: 29 }).startOf("day"), base.endOf("day")], label: t("ranges.last_30_days.label") },
33
+ { key: "last-90-days", value: [base.minus({ day: 89 }).startOf("day"), base.endOf("day")], label: t("ranges.last_90_days.label") }
34
+ ].reduce((acc, curr) => {
35
+ acc[curr.key] = {
36
+ value: curr.value.map((d) => {
37
+ if (options.withTime) {
38
+ d = d.set({ millisecond: 0 });
39
+ }
40
+ return options.withTime ? d.toISO() : d.toISODate();
41
+ }),
42
+ label: curr.label
43
+ };
44
+ return acc;
45
+ }, {});
46
+ if (!ranges[identifier]) {
47
+ console.warn(`[useDateRangePresets] Preset identifier "${identifier}" is not recognized.`);
48
+ }
49
+ return ranges[identifier];
50
+ };
51
+ const defaultPresets = computed(() => {
52
+ return [
53
+ "today",
54
+ "this-week",
55
+ "last-week",
56
+ "this-month",
57
+ "last-month",
58
+ "this-year",
59
+ "last-year"
60
+ ].map((i) => getDateRange(i)).filter(Boolean);
61
+ });
62
+ const resolvePresets = (presets) => {
63
+ return presets.map((preset) => {
64
+ if (typeof preset === "string") {
65
+ return getDateRange(preset);
66
+ }
67
+ return preset;
68
+ }).filter(Boolean);
69
+ };
70
+ const getFilterValue = (preset, noOperator = false) => {
71
+ const range = getDateRange(preset);
72
+ if (!range) {
73
+ return void 0;
74
+ }
75
+ if (noOperator) {
76
+ return range.value;
77
+ }
78
+ return {
79
+ operator: BETWEEN_OPERATOR,
80
+ value: range.value
81
+ };
82
+ };
83
+ return {
84
+ getDateRange,
85
+ defaultPresets,
86
+ resolvePresets,
87
+ getFilterValue,
88
+ PRESET_IDENTIFIERS
89
+ };
90
+ }
@@ -0,0 +1,29 @@
1
+ import type { Ref, ShallowRef } from 'vue';
2
+ import type { ServerErrors, UnTrackedServerErrors } from './useServerErrors.js';
3
+ export interface FormComponent {
4
+ validate: () => Promise<{
5
+ valid: boolean;
6
+ }>;
7
+ resetValidation: () => Promise<void> | void;
8
+ }
9
+ export interface UseFormOptions<T> {
10
+ initialValues: T;
11
+ onSubmit: (values: T) => Promise<void>;
12
+ form?: Readonly<ShallowRef<FormComponent | null>>;
13
+ }
14
+ interface UseFormReturn<T> {
15
+ model: Ref<T>;
16
+ updateModel: (value: Partial<T> | undefined) => void;
17
+ reset: () => void;
18
+ submit: () => Promise<void>;
19
+ save: () => Promise<void>;
20
+ loading: Ref<boolean>;
21
+ submitting: Ref<boolean>;
22
+ resetValidation: () => void;
23
+ serverErrors: Ref<ServerErrors<T>>;
24
+ checkServerErrors: (error: unknown) => void;
25
+ clearServerErrors: () => void;
26
+ untrackedServerErrors: Ref<UnTrackedServerErrors<T>>;
27
+ }
28
+ export declare function useForm<T>(options: UseFormOptions<T>): UseFormReturn<T>;
29
+ export {};
@@ -0,0 +1,74 @@
1
+ import { mergeDefaults } from "#imports";
2
+ import { ref } from "vue";
3
+ import { useServerErrors } from "./useServerErrors.js";
4
+ export function useForm(options) {
5
+ const model = ref({ ...options.initialValues });
6
+ const {
7
+ serverErrors,
8
+ checkServerErrors,
9
+ clearServerErrors,
10
+ untrackedServerErrors
11
+ } = useServerErrors();
12
+ const submitting = ref(false);
13
+ function updateModel(value) {
14
+ model.value = mergeDefaults(value, options.initialValues);
15
+ }
16
+ async function _callMethodOnForm(methodName, defaultReturn) {
17
+ if (!options.form) {
18
+ return Promise.resolve(defaultReturn);
19
+ }
20
+ const formRaw = options?.form?.value;
21
+ if (!formRaw) {
22
+ return Promise.resolve(defaultReturn);
23
+ }
24
+ if (typeof formRaw[methodName] !== "function") {
25
+ console.warn(`[useForm] form ref does not have a ${methodName} method (did not call ${methodName})`);
26
+ return Promise.resolve(defaultReturn);
27
+ }
28
+ return await formRaw[methodName]();
29
+ }
30
+ function validateForm() {
31
+ return _callMethodOnForm("validate", { valid: true });
32
+ }
33
+ function resetFormValidation() {
34
+ return _callMethodOnForm("resetValidation", void 0);
35
+ }
36
+ async function submit() {
37
+ if (!await validateForm().then((r) => r.valid)) {
38
+ return;
39
+ }
40
+ submitting.value = true;
41
+ try {
42
+ await options.onSubmit(model.value);
43
+ } catch (error) {
44
+ checkServerErrors(error);
45
+ console.error(error);
46
+ } finally {
47
+ submitting.value = false;
48
+ }
49
+ }
50
+ function resetValidation() {
51
+ clearServerErrors();
52
+ resetFormValidation();
53
+ }
54
+ function reset() {
55
+ updateModel(void 0);
56
+ resetValidation();
57
+ }
58
+ return {
59
+ model,
60
+ updateModel,
61
+ reset,
62
+ submit,
63
+ submitting,
64
+ save: submit,
65
+ // alias
66
+ loading: submitting,
67
+ // alias
68
+ resetValidation,
69
+ serverErrors,
70
+ checkServerErrors,
71
+ clearServerErrors,
72
+ untrackedServerErrors
73
+ };
74
+ }
@@ -0,0 +1,11 @@
1
+ import type { ComputedRef } from 'vue';
2
+ export interface UseFormLockOptions {
3
+ readonly?: boolean | null;
4
+ disabled?: boolean | null;
5
+ }
6
+ interface UseFormLockReturn {
7
+ isReadonly: ComputedRef<boolean>;
8
+ isDisabled: ComputedRef<boolean>;
9
+ }
10
+ export declare function useFormLock(options: UseFormLockOptions): UseFormLockReturn;
11
+ export {};
@@ -0,0 +1,8 @@
1
+ import { computed, inject } from "vue";
2
+ const VUETIFY_FORM_KEY = Symbol.for("vuetify:form");
3
+ export function useFormLock(options) {
4
+ const form = inject(VUETIFY_FORM_KEY, null);
5
+ const isReadonly = computed(() => !!(options.readonly ?? form?.isReadonly.value));
6
+ const isDisabled = computed(() => !!(options.disabled ?? form?.isDisabled.value));
7
+ return { isReadonly, isDisabled };
8
+ }
@@ -0,0 +1,16 @@
1
+ import type { Ref } from 'vue';
2
+ interface UseFormWrapper {
3
+ resource_id?: string;
4
+ load?: (item: any) => Promise<any>;
5
+ form?: Ref<any>;
6
+ rowSelected?: (item: any, event?: Event) => void;
7
+ }
8
+ export declare function useFormWrapper(options: UseFormWrapper): {
9
+ dialog: Ref<boolean, boolean>;
10
+ formModel: Ref<null, null>;
11
+ loadingFormModel: Ref<null, null>;
12
+ create: () => void;
13
+ createWithValues: (values?: null) => void;
14
+ edit: (item: any, _?: any, event?: Event) => Promise<void>;
15
+ };
16
+ export {};
@@ -0,0 +1,36 @@
1
+ import { ref } from "vue";
2
+ export function useFormWrapper(options) {
3
+ const dialog = ref(false);
4
+ const formModel = ref(null);
5
+ const loadingFormModel = ref(null);
6
+ function create() {
7
+ formModel.value = null;
8
+ dialog.value = true;
9
+ }
10
+ function createWithValues(values = null) {
11
+ formModel.value = values;
12
+ dialog.value = true;
13
+ }
14
+ async function edit(item, _, event) {
15
+ options.rowSelected?.(item, event);
16
+ const id = item?.[options.resource_id ?? "id"];
17
+ loadingFormModel.value = id;
18
+ try {
19
+ const loadFn = options.load ?? options.form?.value.load;
20
+ formModel.value = await loadFn(item);
21
+ dialog.value = true;
22
+ } catch (e) {
23
+ console.error(e);
24
+ } finally {
25
+ loadingFormModel.value = null;
26
+ }
27
+ }
28
+ return {
29
+ dialog,
30
+ formModel,
31
+ loadingFormModel,
32
+ create,
33
+ createWithValues,
34
+ edit
35
+ };
36
+ }
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Interrogazione di un lavoro che l'API ha accodato invece di eseguirlo nella richiesta.
3
+ *
4
+ * Il contratto è quello degli import del framework core: la chiamata che avvia il lavoro
5
+ * risponde 202 con un `job_id`, e da lì si interroga lo stesso endpoint con `action: 'status'`
6
+ * finché non arriva uno stato terminale. Il `result` di un lavoro concluso è identico al payload
7
+ * che l'endpoint sincrono avrebbe restituito, quindi da quel punto in poi il chiamante non deve
8
+ * distinguere i due casi.
9
+ */
10
+ export type ImportJobStatus = 'queued' | 'running' | 'completed' | 'failed';
11
+ export interface ImportJobProgress {
12
+ done: number;
13
+ total: number;
14
+ }
15
+ /** Risposta 202 con cui l'API comunica di aver accodato il lavoro. */
16
+ export interface ImportJobHandle {
17
+ job_id: string;
18
+ status: ImportJobStatus;
19
+ }
20
+ export interface ImportJobState<T> extends ImportJobHandle {
21
+ progress?: ImportJobProgress | null;
22
+ result?: T;
23
+ error?: string;
24
+ }
25
+ /** Il minimo che serve di `useApi()`: qui viene passata l'istanza del chiamante. */
26
+ export interface ImportJobApi {
27
+ $post: <T>(url: string, body?: any, options?: any) => Promise<T>;
28
+ }
29
+ export interface PollImportJobOptions {
30
+ jobId: string;
31
+ /** Parametri che l'endpoint si aspetta anche sulla chiamata di stato (es. il tipo di import). */
32
+ params?: Record<string, any>;
33
+ onProgress?: (progress: ImportJobProgress | null) => void;
34
+ signal?: AbortSignal;
35
+ /** Attesa totale prima di arrendersi, in ms. Default 30 minuti. */
36
+ timeout?: number;
37
+ }
38
+ export type ImportJobFailureReason = 'failed' | 'timeout' | 'aborted';
39
+ export declare class ImportJobError extends Error {
40
+ readonly reason: ImportJobFailureReason;
41
+ constructor(message: string, reason: ImportJobFailureReason);
42
+ }
43
+ /** Il backend ha accodato il lavoro invece di eseguirlo nella richiesta? */
44
+ export declare function isImportJob(response: any): response is ImportJobHandle;
45
+ /**
46
+ * Interroga il lavoro finché non si conclude e ne restituisce il risultato.
47
+ *
48
+ * @throws {ImportJobError} se il lavoro fallisce, se scade l'attesa o se il polling viene annullato.
49
+ */
50
+ export declare function pollImportJob<T>(api: ImportJobApi, url: string, options: PollImportJobOptions): Promise<T>;
51
+ export declare function useImportJob(): {
52
+ isImportJob: typeof isImportJob;
53
+ pollImportJob: typeof pollImportJob;
54
+ ImportJobError: typeof ImportJobError;
55
+ };
@@ -0,0 +1,94 @@
1
+ export class ImportJobError extends Error {
2
+ reason;
3
+ constructor(message, reason) {
4
+ super(message);
5
+ this.name = "ImportJobError";
6
+ this.reason = reason;
7
+ }
8
+ }
9
+ const DEFAULT_TIMEOUT = 30 * 60 * 1e3;
10
+ const MAX_CONSECUTIVE_ERRORS = 3;
11
+ function delayFor(elapsed) {
12
+ if (elapsed < 1e4) {
13
+ return 1e3;
14
+ }
15
+ if (elapsed < 6e4) {
16
+ return 2e3;
17
+ }
18
+ return 5e3;
19
+ }
20
+ function wait(ms, signal) {
21
+ return new Promise((resolve, reject) => {
22
+ if (signal?.aborted) {
23
+ reject(new ImportJobError("Import job polling aborted", "aborted"));
24
+ return;
25
+ }
26
+ const timer = setTimeout(() => {
27
+ signal?.removeEventListener("abort", abort);
28
+ resolve();
29
+ }, ms);
30
+ function abort() {
31
+ clearTimeout(timer);
32
+ reject(new ImportJobError("Import job polling aborted", "aborted"));
33
+ }
34
+ signal?.addEventListener("abort", abort, { once: true });
35
+ });
36
+ }
37
+ function statusOf(error) {
38
+ return error?.response?.status ?? error?.statusCode ?? error?.status;
39
+ }
40
+ export function isImportJob(response) {
41
+ return !!response && typeof response.job_id === "string";
42
+ }
43
+ export async function pollImportJob(api, url, options) {
44
+ const { jobId, params = {}, onProgress, signal, timeout = DEFAULT_TIMEOUT } = options;
45
+ const startedAt = Date.now();
46
+ let consecutiveErrors = 0;
47
+ for (; ; ) {
48
+ if (signal?.aborted) {
49
+ throw new ImportJobError("Import job polling aborted", "aborted");
50
+ }
51
+ if (Date.now() - startedAt > timeout) {
52
+ throw new ImportJobError(`Import job ${jobId} did not complete in time`, "timeout");
53
+ }
54
+ let state;
55
+ try {
56
+ state = await api.$post(
57
+ url,
58
+ { ...params, action: "status", job_id: jobId },
59
+ // gli errori di questa chiamata li gestisce il chiamante: una notifica per ogni
60
+ // tentativo di polling sommergerebbe l'utente
61
+ { notify: false, signal }
62
+ );
63
+ consecutiveErrors = 0;
64
+ } catch (error) {
65
+ if (signal?.aborted) {
66
+ throw new ImportJobError("Import job polling aborted", "aborted");
67
+ }
68
+ const status = statusOf(error);
69
+ if (status && status >= 400 && status < 500) {
70
+ throw new ImportJobError(error?.message ?? `Import job ${jobId} is not available`, "failed");
71
+ }
72
+ if (++consecutiveErrors > MAX_CONSECUTIVE_ERRORS) {
73
+ throw new ImportJobError(error?.message ?? `Import job ${jobId} is not reachable`, "failed");
74
+ }
75
+ await wait(delayFor(Date.now() - startedAt), signal);
76
+ continue;
77
+ }
78
+ onProgress?.(state.progress ?? null);
79
+ if (state.status === "completed") {
80
+ return state.result;
81
+ }
82
+ if (state.status === "failed") {
83
+ throw new ImportJobError(state.error || `Import job ${jobId} failed`, "failed");
84
+ }
85
+ await wait(delayFor(Date.now() - startedAt), signal);
86
+ }
87
+ }
88
+ export function useImportJob() {
89
+ return {
90
+ isImportJob,
91
+ pollImportJob,
92
+ ImportJobError
93
+ };
94
+ }
@@ -0,0 +1 @@
1
+ export declare function useLux(value?: any, outuputFormat?: any, inputFormat?: any): any;
@@ -0,0 +1,8 @@
1
+ import { useNuxtApp } from "#imports";
2
+ export function useLux(value, outuputFormat, inputFormat) {
3
+ const { $lux, $lp } = useNuxtApp().vueApp.config.globalProperties;
4
+ if (value !== void 0) {
5
+ return $lux(value, outuputFormat, inputFormat);
6
+ }
7
+ return { $lux, $lp, $lf: $lux };
8
+ }
@@ -0,0 +1,12 @@
1
+ import type { PushParameter } from 'notivue';
2
+ export declare function useNotify(): {
3
+ success: import("notivue").PushStatic;
4
+ error: (opts: string | Error | PushParameter | any) => void;
5
+ info: import("notivue").PushStatic;
6
+ warn: import("notivue").PushStatic;
7
+ warning: import("notivue").PushStatic;
8
+ promise: import("notivue").PushPromise;
9
+ load: import("notivue").PushPromise;
10
+ clearAll: () => void;
11
+ destroyAll: () => void;
12
+ };
@@ -0,0 +1,24 @@
1
+ import { push } from "notivue";
2
+ import { getResponseErrorMessage } from "../internals/api.js";
3
+ export function useNotify() {
4
+ function error(opts) {
5
+ const responseErrorMessage = getResponseErrorMessage(opts);
6
+ if (responseErrorMessage) {
7
+ opts = responseErrorMessage;
8
+ } else if (opts instanceof Error) {
9
+ opts = opts.message;
10
+ }
11
+ push.error(opts);
12
+ }
13
+ return {
14
+ success: push.success,
15
+ error,
16
+ info: push.info,
17
+ warn: push.warning,
18
+ warning: push.warning,
19
+ promise: push.promise,
20
+ load: push.load,
21
+ clearAll: push.clearAll,
22
+ destroyAll: push.destroyAll
23
+ };
24
+ }
@@ -0,0 +1,24 @@
1
+ import type { MaybeRefOrGetter } from 'vue';
2
+ export type PaginateOptions = boolean | {
3
+ limit: number;
4
+ };
5
+ interface PaginatedFetchParams {
6
+ search: MaybeRefOrGetter<string>;
7
+ extraParams: MaybeRefOrGetter<Record<string, any>>;
8
+ paginate: MaybeRefOrGetter<PaginateOptions>;
9
+ lazy: MaybeRefOrGetter<boolean>;
10
+ frozen?: MaybeRefOrGetter<boolean>;
11
+ resetOnSearch?: MaybeRefOrGetter<boolean>;
12
+ onError?: (error: any) => void;
13
+ }
14
+ export declare function usePaginatedFetch(resource: MaybeRefOrGetter<string>, options: PaginatedFetchParams): {
15
+ items: import("vue").Ref<any[], any[]>;
16
+ total: import("vue").Ref<number, number>;
17
+ page: Readonly<import("vue").Ref<number, number>>;
18
+ hasMore: import("vue").Ref<boolean, boolean>;
19
+ loading: import("vue").Ref<boolean, boolean>;
20
+ reloadAllPages: () => Promise<void>;
21
+ loadingAll: import("vue").Ref<boolean, boolean>;
22
+ loadMore: () => Promise<void>;
23
+ };
24
+ export {};
@@ -0,0 +1,154 @@
1
+ import { useApi } from "#imports";
2
+ import { watchDebounced } from "@vueuse/core";
3
+ import { isEqual } from "es-toolkit/predicate";
4
+ import { computed, readonly, ref, toRef, toValue, watch } from "vue";
5
+ const ABORT_REASON = "ABORT-PREV";
6
+ export function usePaginatedFetch(resource, options) {
7
+ let abortController = new AbortController();
8
+ let prevParams = {};
9
+ const { search, extraParams, paginate, lazy, frozen, resetOnSearch = false } = options;
10
+ const loading = ref(false);
11
+ const items = ref([]);
12
+ const page = ref(1);
13
+ const hasMore = ref(false);
14
+ const total = ref(0);
15
+ const loadingAll = ref(false);
16
+ const paginateParams = computed(() => {
17
+ const v = toValue(paginate);
18
+ if (!v) {
19
+ return { paginate: 0 };
20
+ }
21
+ return {
22
+ paginate: 1,
23
+ limit: typeof v === "object" && v.limit || 50
24
+ };
25
+ });
26
+ watch(() => [toValue(resource), toValue(paginate)], () => {
27
+ load(true);
28
+ }, {
29
+ immediate: true
30
+ });
31
+ watch(extraParams, () => {
32
+ load(true);
33
+ }, {
34
+ deep: true,
35
+ immediate: true
36
+ });
37
+ watch(toRef(frozen), (val) => {
38
+ if (!val && !loading.value && !items.value.length) {
39
+ load();
40
+ }
41
+ }, { immediate: false });
42
+ watchDebounced(() => toValue(search), () => {
43
+ load(toValue(resetOnSearch));
44
+ }, { debounce: 300, maxWait: 1e3 });
45
+ function setupMeta(meta) {
46
+ page.value = meta ? meta.current_page : 1;
47
+ hasMore.value = page.value < (meta?.last_page ?? 1);
48
+ }
49
+ async function load(reset = false) {
50
+ if (!toValue(resource) || toValue(frozen)) {
51
+ return;
52
+ }
53
+ const params = {
54
+ resource: toValue(resource),
55
+ ...paginateParams.value,
56
+ ...toValue(extraParams),
57
+ search: toValue(search) || void 0
58
+ };
59
+ if (isEqual(params, prevParams)) {
60
+ return;
61
+ }
62
+ if (reset) {
63
+ setupMeta(null);
64
+ items.value = [];
65
+ }
66
+ prevParams = { ...params };
67
+ if (abortController) {
68
+ abortController.abort(ABORT_REASON);
69
+ }
70
+ abortController = new AbortController();
71
+ loading.value = true;
72
+ let aborted = false;
73
+ try {
74
+ let method = "get";
75
+ if (toValue(lazy)) {
76
+ if (toValue(paginate)) {
77
+ console.warn("[WeSelect] Lazy loading is not supported with pagination");
78
+ } else {
79
+ method = "getLazy";
80
+ }
81
+ }
82
+ const { data, meta } = await useApi()[method](toValue(resource), {
83
+ params,
84
+ signal: abortController.signal
85
+ });
86
+ setupMeta(meta);
87
+ total.value = meta?.total;
88
+ items.value = data;
89
+ } catch (e) {
90
+ aborted = e.cause === ABORT_REASON;
91
+ if (!aborted) {
92
+ if (options.onError) {
93
+ options.onError(e);
94
+ } else {
95
+ console.error("[we-select] error loading data", { error: e, params });
96
+ }
97
+ }
98
+ }
99
+ if (!aborted) {
100
+ loading.value = false;
101
+ }
102
+ }
103
+ async function loadMore() {
104
+ if (!hasMore.value || loading.value) {
105
+ return;
106
+ }
107
+ const nextPage = page.value + 1;
108
+ loading.value = true;
109
+ let aborted = false;
110
+ try {
111
+ const { data, meta } = await loadPage(nextPage, abortController.signal);
112
+ setupMeta(meta);
113
+ items.value.push(...data);
114
+ } catch (e) {
115
+ aborted = e.cause === ABORT_REASON;
116
+ if (!aborted) {
117
+ if (options.onError) {
118
+ options.onError(e);
119
+ } else {
120
+ console.error("[WeSelect] error loading data", { error: e, page: nextPage });
121
+ }
122
+ }
123
+ }
124
+ if (!aborted) {
125
+ loading.value = false;
126
+ }
127
+ }
128
+ async function loadPage(page2, signal) {
129
+ return useApi().get(toValue(resource), {
130
+ params: {
131
+ ...paginateParams.value,
132
+ page: page2,
133
+ ...toValue(extraParams),
134
+ search: toValue(search)
135
+ },
136
+ signal
137
+ });
138
+ }
139
+ async function reloadAllPages() {
140
+ loadingAll.value = true;
141
+ const promises = [];
142
+ for (let i = 1; i < page.value + 1; i++) {
143
+ promises.push(loadPage(i));
144
+ }
145
+ const res = await Promise.all(promises);
146
+ items.value = res.reduce((acc, r) => {
147
+ acc.push(...r.data);
148
+ return acc;
149
+ }, []);
150
+ setupMeta(res.at(-1)?.meta);
151
+ loadingAll.value = false;
152
+ }
153
+ return { items, total, page: readonly(page), hasMore, loading, reloadAllPages, loadingAll, loadMore };
154
+ }