@finema/core 1.4.220 → 2.1.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/README.md +79 -60
- package/dist/module.d.mts +4 -24
- package/dist/module.json +4 -3
- package/dist/module.mjs +75 -213
- package/dist/runtime/components/App.vue +27 -0
- package/dist/runtime/components/App.vue.d.ts +12 -0
- package/dist/runtime/components/DevToolsWindow/index.vue +312 -0
- package/dist/runtime/components/DevToolsWindow/index.vue.d.ts +2 -0
- package/dist/runtime/components/Dialog/index.vue +77 -110
- package/dist/runtime/components/Dialog/index.vue.d.ts +10 -0
- package/dist/runtime/components/Empty.vue +33 -18
- package/dist/runtime/components/Empty.vue.d.ts +12 -0
- package/dist/runtime/components/FlexDeck/Base.vue +154 -159
- package/dist/runtime/components/FlexDeck/Base.vue.d.ts +63 -0
- package/dist/runtime/components/FlexDeck/index.vue +67 -68
- package/dist/runtime/components/FlexDeck/index.vue.d.ts +43 -0
- package/dist/runtime/components/Form/FieldWrapper.vue +35 -23
- package/dist/runtime/components/Form/FieldWrapper.vue.d.ts +16 -0
- package/dist/runtime/components/Form/Fields.vue +92 -230
- package/dist/runtime/components/Form/Fields.vue.d.ts +14 -0
- package/dist/runtime/components/Form/InputCheckbox/index.vue +53 -28
- package/dist/runtime/components/Form/InputCheckbox/index.vue.d.ts +3 -0
- package/dist/runtime/components/Form/InputCheckbox/types.d.ts +5 -1
- package/dist/runtime/components/Form/InputDateTime/date_time_field.types.d.ts +1 -1
- package/dist/runtime/components/Form/InputDateTime/index.vue +97 -68
- package/dist/runtime/components/Form/InputDateTime/index.vue.d.ts +4 -0
- package/dist/runtime/components/Form/InputNumber/index.vue +61 -27
- package/dist/runtime/components/Form/InputNumber/index.vue.d.ts +5 -0
- package/dist/runtime/components/Form/InputNumber/types.d.ts +10 -5
- package/dist/runtime/components/Form/InputSelect/index.vue +95 -55
- package/dist/runtime/components/Form/InputSelect/index.vue.d.ts +5 -0
- package/dist/runtime/components/Form/InputSelect/types.d.ts +14 -8
- package/dist/runtime/components/Form/InputSelectMultiple/index.vue +108 -54
- package/dist/runtime/components/Form/InputSelectMultiple/index.vue.d.ts +3 -0
- package/dist/runtime/components/Form/InputSelectMultiple/types.d.ts +9 -8
- package/dist/runtime/components/Form/InputText/index.vue +135 -68
- package/dist/runtime/components/Form/InputText/index.vue.d.ts +5 -0
- package/dist/runtime/components/Form/InputText/types.d.ts +4 -3
- package/dist/runtime/components/Form/InputTextarea/index.vue +57 -25
- package/dist/runtime/components/Form/InputTextarea/index.vue.d.ts +3 -0
- package/dist/runtime/components/Form/InputTextarea/types.d.ts +7 -2
- package/dist/runtime/components/Form/InputToggle/index.vue +51 -27
- package/dist/runtime/components/Form/InputToggle/index.vue.d.ts +3 -0
- package/dist/runtime/components/Form/InputToggle/types.d.ts +5 -1
- package/dist/runtime/components/Form/index.vue +5 -6
- package/dist/runtime/components/Form/index.vue.d.ts +12 -0
- package/dist/runtime/components/Form/types.d.ts +13 -27
- package/dist/runtime/components/Image.vue +51 -36
- package/dist/runtime/components/Image.vue.d.ts +13 -0
- package/dist/runtime/components/Loader.vue +29 -27
- package/dist/runtime/components/Loader.vue.d.ts +22 -0
- package/dist/runtime/components/{LogItem.vue → Log/LogItem.vue} +44 -41
- package/dist/runtime/components/Log/LogItem.vue.d.ts +6 -0
- package/dist/runtime/components/Log/index.vue +28 -0
- package/dist/runtime/components/Log/index.vue.d.ts +7 -0
- package/dist/runtime/components/Table/Base.vue +166 -161
- package/dist/runtime/components/Table/Base.vue.d.ts +47 -0
- package/dist/runtime/components/Table/ColumnDate.vue +14 -16
- package/dist/runtime/components/Table/ColumnDate.vue.d.ts +8 -0
- package/dist/runtime/components/Table/ColumnDateTime.vue +16 -18
- package/dist/runtime/components/Table/ColumnDateTime.vue.d.ts +8 -0
- package/dist/runtime/components/Table/ColumnImage.vue +16 -15
- package/dist/runtime/components/Table/ColumnImage.vue.d.ts +8 -0
- package/dist/runtime/components/Table/ColumnNumber.vue +14 -14
- package/dist/runtime/components/Table/ColumnNumber.vue.d.ts +8 -0
- package/dist/runtime/components/Table/ColumnText.vue +24 -29
- package/dist/runtime/components/Table/ColumnText.vue.d.ts +8 -0
- package/dist/runtime/components/Table/Simple.vue +69 -70
- package/dist/runtime/components/Table/Simple.vue.d.ts +24 -0
- package/dist/runtime/components/Table/index.vue +178 -65
- package/dist/runtime/components/Table/index.vue.d.ts +25 -0
- package/dist/runtime/components/Table/types.d.ts +14 -18
- package/dist/runtime/components/Table/{types.mjs → types.js} +1 -0
- package/dist/runtime/components/TeleportSafe.vue +42 -40
- package/dist/runtime/components/TeleportSafe.vue.d.ts +16 -0
- package/dist/runtime/composables/loaderList.d.ts +2 -2
- package/dist/runtime/composables/loaderList.js +51 -0
- package/dist/runtime/composables/loaderObject.d.ts +1 -1
- package/dist/runtime/composables/loaderObject.js +50 -0
- package/dist/runtime/composables/loaderPage.d.ts +10 -11
- package/dist/runtime/composables/loaderPage.js +243 -0
- package/dist/runtime/composables/useApp.d.ts +4 -9
- package/dist/runtime/composables/{useApp.mjs → useApp.js} +0 -12
- package/dist/runtime/composables/useConfig.d.ts +3 -3
- package/dist/runtime/composables/useConfig.js +12 -0
- package/dist/runtime/composables/useDialog.d.ts +1 -7
- package/dist/runtime/composables/useDialog.js +53 -0
- package/dist/runtime/composables/useFlexDeck.d.ts +1 -1
- package/dist/runtime/composables/{useFlexDeck.mjs → useFlexDeck.js} +5 -5
- package/dist/runtime/composables/useForm.d.ts +5 -2
- package/dist/runtime/composables/useForm.js +37 -0
- package/dist/runtime/composables/useNotification.d.ts +6 -22
- package/dist/runtime/composables/{useNotification.mjs → useNotification.js} +5 -21
- package/dist/runtime/composables/useTable.d.ts +12 -11
- package/dist/runtime/composables/{useTable.mjs → useTable.js} +3 -8
- package/dist/runtime/composables/useUpload.d.ts +2 -2
- package/dist/runtime/composables/{useUpload.mjs → useUpload.js} +1 -1
- package/dist/runtime/helpers/apiBaseHelper.d.ts +29 -0
- package/dist/runtime/helpers/apiBaseHelper.js +63 -0
- package/dist/runtime/helpers/apiListHelper.d.ts +4 -6
- package/dist/runtime/helpers/apiListHelper.js +50 -0
- package/dist/runtime/helpers/apiObjectHelper.d.ts +19 -20
- package/dist/runtime/helpers/apiObjectHelper.js +51 -0
- package/dist/runtime/helpers/apiPageHelper.d.ts +44 -44
- package/dist/runtime/helpers/apiPageHelper.js +287 -0
- package/dist/runtime/helpers/componentHelper.d.ts +11 -12
- package/dist/runtime/helpers/{componentHelper.mjs → componentHelper.js} +2 -7
- package/dist/runtime/i18n/valibot.d.ts +69 -0
- package/dist/runtime/i18n/valibot.js +72 -0
- package/dist/runtime/plugin.d.ts +1 -1
- package/dist/runtime/plugin.js +12 -0
- package/dist/runtime/server/tsconfig.json +3 -0
- package/dist/runtime/theme/button.d.ts +5 -0
- package/dist/runtime/theme/button.js +1 -0
- package/dist/runtime/theme/dialog.d.ts +31 -0
- package/dist/runtime/theme/dialog.js +21 -0
- package/dist/runtime/theme/empty.d.ts +7 -0
- package/dist/runtime/theme/empty.js +7 -0
- package/dist/runtime/theme/form.d.ts +18 -0
- package/dist/runtime/theme/form.js +16 -0
- package/dist/runtime/theme/index.d.ts +10 -0
- package/dist/runtime/theme/index.js +10 -0
- package/dist/runtime/theme/input.d.ts +8 -0
- package/dist/runtime/theme/input.js +4 -0
- package/dist/runtime/theme/inputNumber.d.ts +8 -0
- package/dist/runtime/theme/inputNumber.js +4 -0
- package/dist/runtime/theme/loader.d.ts +28 -0
- package/dist/runtime/theme/loader.js +18 -0
- package/dist/runtime/theme/selectMenu.d.ts +17 -0
- package/dist/runtime/theme/selectMenu.js +18 -0
- package/dist/runtime/theme/table.d.ts +10 -0
- package/dist/runtime/theme/table.js +10 -0
- package/dist/runtime/theme/textarea.d.ts +5 -0
- package/dist/runtime/theme/textarea.js +1 -0
- package/dist/runtime/types/lib.d.ts +1 -1
- package/dist/runtime/utils/ArrayHelper.d.ts +1 -1
- package/dist/runtime/utils/{ArrayHelper.mjs → ArrayHelper.js} +1 -1
- package/dist/runtime/utils/ObjectHelper.d.ts +3 -3
- package/dist/runtime/utils/{ObjectHelper.mjs → ObjectHelper.js} +3 -3
- package/dist/runtime/utils/ParamHelper.d.ts +1 -1
- package/dist/runtime/utils/{ParamHelper.mjs → ParamHelper.js} +1 -1
- package/dist/types.d.mts +2 -15
- package/package.json +91 -100
- package/dist/module.cjs +0 -5
- package/dist/module.d.ts +0 -50
- package/dist/runtime/components/Alert.vue +0 -48
- package/dist/runtime/components/Avatar.vue +0 -27
- package/dist/runtime/components/Badge.vue +0 -11
- package/dist/runtime/components/Breadcrumb.vue +0 -44
- package/dist/runtime/components/Button/Group.vue +0 -37
- package/dist/runtime/components/Button/index.vue +0 -75
- package/dist/runtime/components/Card.vue +0 -38
- package/dist/runtime/components/Core.vue +0 -45
- package/dist/runtime/components/Dropdown/index.vue +0 -70
- package/dist/runtime/components/Dropdown/types.d.ts +0 -2
- package/dist/runtime/components/Dropdown/types.mjs +0 -17
- package/dist/runtime/components/Form/InputDateTimeRange/date_range_time_field.types.d.ts +0 -17
- package/dist/runtime/components/Form/InputDateTimeRange/index.vue +0 -91
- package/dist/runtime/components/Form/InputRadio/index.vue +0 -27
- package/dist/runtime/components/Form/InputRadio/types.d.ts +0 -8
- package/dist/runtime/components/Form/InputStatic/index.vue +0 -16
- package/dist/runtime/components/Form/InputStatic/types.d.ts +0 -4
- package/dist/runtime/components/Form/InputTags/index.vue +0 -141
- package/dist/runtime/components/Form/InputTags/types.d.ts +0 -11
- package/dist/runtime/components/Form/InputTextarea/types.mjs +0 -0
- package/dist/runtime/components/Form/InputToggle/types.mjs +0 -0
- package/dist/runtime/components/Form/InputUploadDropzone/index.vue +0 -206
- package/dist/runtime/components/Form/InputUploadDropzone/types.d.ts +0 -11
- package/dist/runtime/components/Form/InputUploadDropzone/types.mjs +0 -0
- package/dist/runtime/components/Form/InputUploadDropzoneAuto/index.vue +0 -362
- package/dist/runtime/components/Form/InputUploadDropzoneAuto/types.d.ts +0 -23
- package/dist/runtime/components/Form/InputUploadDropzoneAuto/types.mjs +0 -0
- package/dist/runtime/components/Form/InputUploadDropzoneAutoMultiple/ItemUpload.vue +0 -241
- package/dist/runtime/components/Form/InputUploadDropzoneAutoMultiple/ItemView.vue +0 -110
- package/dist/runtime/components/Form/InputUploadDropzoneAutoMultiple/index.vue +0 -171
- package/dist/runtime/components/Form/InputUploadDropzoneAutoMultiple/types.d.ts +0 -23
- package/dist/runtime/components/Form/InputUploadDropzoneAutoMultiple/types.mjs +0 -0
- package/dist/runtime/components/Form/InputUploadDropzoneImageAutoMultiple/ItemUpload.vue +0 -161
- package/dist/runtime/components/Form/InputUploadDropzoneImageAutoMultiple/ItemView.vue +0 -64
- package/dist/runtime/components/Form/InputUploadDropzoneImageAutoMultiple/index.vue +0 -178
- package/dist/runtime/components/Form/InputUploadDropzoneImageAutoMultiple/types.d.ts +0 -21
- package/dist/runtime/components/Form/InputUploadDropzoneImageAutoMultiple/types.mjs +0 -0
- package/dist/runtime/components/Form/InputUploadFileClassic/index.vue +0 -95
- package/dist/runtime/components/Form/InputUploadFileClassic/types.d.ts +0 -13
- package/dist/runtime/components/Form/InputUploadFileClassic/types.mjs +0 -0
- package/dist/runtime/components/Form/InputUploadFileClassicAuto/index.vue +0 -151
- package/dist/runtime/components/Form/InputUploadFileClassicAuto/types.d.ts +0 -18
- package/dist/runtime/components/Form/InputUploadFileClassicAuto/types.mjs +0 -0
- package/dist/runtime/components/Form/InputUploadImageAuto/index.vue +0 -219
- package/dist/runtime/components/Form/InputUploadImageAuto/types.d.ts +0 -20
- package/dist/runtime/components/Form/InputUploadImageAuto/types.mjs +0 -0
- package/dist/runtime/components/Form/InputWYSIWYG/UploadImageForm.vue +0 -55
- package/dist/runtime/components/Form/InputWYSIWYG/index.vue +0 -230
- package/dist/runtime/components/Form/InputWYSIWYG/types.d.ts +0 -19
- package/dist/runtime/components/Form/InputWYSIWYG/types.mjs +0 -0
- package/dist/runtime/components/Icon.vue +0 -23
- package/dist/runtime/components/Log.vue +0 -22
- package/dist/runtime/components/Modal/index.vue +0 -146
- package/dist/runtime/components/OTPInput.vue +0 -127
- package/dist/runtime/components/QRCode.vue +0 -22
- package/dist/runtime/components/SimplePagination.vue +0 -96
- package/dist/runtime/components/Slideover/index.vue +0 -110
- package/dist/runtime/components/Tabs/index.vue +0 -64
- package/dist/runtime/composables/loaderList.mjs +0 -52
- package/dist/runtime/composables/loaderObject.mjs +0 -52
- package/dist/runtime/composables/loaderPage.mjs +0 -229
- package/dist/runtime/composables/useConfig.mjs +0 -9
- package/dist/runtime/composables/useDialog.mjs +0 -81
- package/dist/runtime/composables/useForm.mjs +0 -18
- package/dist/runtime/core.config.d.ts +0 -14
- package/dist/runtime/core.config.mjs +0 -14
- package/dist/runtime/helpers/apiListHelper.mjs +0 -44
- package/dist/runtime/helpers/apiObjectHelper.mjs +0 -46
- package/dist/runtime/helpers/apiPageHelper.mjs +0 -270
- package/dist/runtime/plugin.mjs +0 -149
- package/dist/runtime/types/common.mjs +0 -0
- package/dist/runtime/types/config.d.ts +0 -1
- package/dist/runtime/types/config.mjs +0 -0
- package/dist/runtime/types/lib.mjs +0 -0
- package/dist/runtime/ui.config/alert.d.ts +0 -3
- package/dist/runtime/ui.config/alert.mjs +0 -6
- package/dist/runtime/ui.config/badge.d.ts +0 -3
- package/dist/runtime/ui.config/badge.mjs +0 -1
- package/dist/runtime/ui.config/breadcrumb.d.ts +0 -1
- package/dist/runtime/ui.config/breadcrumb.mjs +0 -7
- package/dist/runtime/ui.config/button.d.ts +0 -3
- package/dist/runtime/ui.config/button.mjs +0 -8
- package/dist/runtime/ui.config/buttonGroup.d.ts +0 -3
- package/dist/runtime/ui.config/buttonGroup.mjs +0 -1
- package/dist/runtime/ui.config/card.d.ts +0 -1
- package/dist/runtime/ui.config/card.mjs +0 -2
- package/dist/runtime/ui.config/checkbox.d.ts +0 -3
- package/dist/runtime/ui.config/checkbox.mjs +0 -1
- package/dist/runtime/ui.config/formGroup.d.ts +0 -3
- package/dist/runtime/ui.config/formGroup.mjs +0 -5
- package/dist/runtime/ui.config/icon.d.ts +0 -3
- package/dist/runtime/ui.config/icon.mjs +0 -3
- package/dist/runtime/ui.config/index.d.ts +0 -16
- package/dist/runtime/ui.config/index.mjs +0 -16
- package/dist/runtime/ui.config/input.d.ts +0 -3
- package/dist/runtime/ui.config/input.mjs +0 -5
- package/dist/runtime/ui.config/modal.d.ts +0 -1
- package/dist/runtime/ui.config/modal.mjs +0 -34
- package/dist/runtime/ui.config/notification.d.ts +0 -11
- package/dist/runtime/ui.config/notification.mjs +0 -13
- package/dist/runtime/ui.config/notifications.d.ts +0 -3
- package/dist/runtime/ui.config/notifications.mjs +0 -3
- package/dist/runtime/ui.config/pagination.d.ts +0 -3
- package/dist/runtime/ui.config/pagination.mjs +0 -37
- package/dist/runtime/ui.config/select.d.ts +0 -3
- package/dist/runtime/ui.config/select.mjs +0 -5
- package/dist/runtime/ui.config/selectMenu.d.ts +0 -3
- package/dist/runtime/ui.config/selectMenu.mjs +0 -5
- package/dist/runtime/ui.config/slideover.d.ts +0 -1
- package/dist/runtime/ui.config/slideover.mjs +0 -16
- package/dist/runtime/ui.config/table.d.ts +0 -3
- package/dist/runtime/ui.config/table.mjs +0 -47
- package/dist/runtime/ui.config/tabs.d.ts +0 -3
- package/dist/runtime/ui.config/tabs.mjs +0 -4
- package/dist/runtime/ui.config/tags.d.ts +0 -25
- package/dist/runtime/ui.config/tags.mjs +0 -25
- package/dist/runtime/ui.config/textarea.d.ts +0 -3
- package/dist/runtime/ui.config/textarea.mjs +0 -5
- package/dist/runtime/ui.config/toggle.d.ts +0 -3
- package/dist/runtime/ui.config/toggle.mjs +0 -5
- package/dist/runtime/ui.config/uploadDropzoneImage.d.ts +0 -83
- package/dist/runtime/ui.config/uploadDropzoneImage.mjs +0 -26
- package/dist/runtime/ui.config/uploadFileDropzone.d.ts +0 -61
- package/dist/runtime/ui.config/uploadFileDropzone.mjs +0 -61
- package/dist/runtime/ui.config/uploadFileInputClassicAuto.d.ts +0 -8
- package/dist/runtime/ui.config/uploadFileInputClassicAuto.mjs +0 -8
- package/dist/runtime/ui.config/uploadImage.d.ts +0 -34
- package/dist/runtime/ui.config/uploadImage.mjs +0 -36
- package/dist/runtime/ui.css +0 -1
- package/dist/runtime/utils/ArrayHelper.spec.d.ts +0 -1
- package/dist/runtime/utils/ArrayHelper.spec.mjs +0 -112
- package/dist/runtime/utils/FileHelper.spec.d.ts +0 -1
- package/dist/runtime/utils/FileHelper.spec.mjs +0 -14
- package/dist/runtime/utils/ObjectHelper.spec.d.ts +0 -1
- package/dist/runtime/utils/ObjectHelper.spec.mjs +0 -52
- package/dist/runtime/utils/ParamHelper.spec.d.ts +0 -1
- package/dist/runtime/utils/ParamHelper.spec.mjs +0 -78
- package/dist/runtime/utils/StringHelper.spec.d.ts +0 -1
- package/dist/runtime/utils/StringHelper.spec.mjs +0 -76
- package/dist/runtime/utils/TimeHelper.spec.d.ts +0 -1
- package/dist/runtime/utils/TimeHelper.spec.mjs +0 -79
- package/dist/runtime/utils/TimeHelper.thai.spec.d.ts +0 -1
- package/dist/runtime/utils/TimeHelper.thai.spec.mjs +0 -31
- package/dist/types.d.ts +0 -16
- package/dist/runtime/components/FlexDeck/{types.mjs → types.js} +0 -0
- package/dist/runtime/components/Form/InputCheckbox/{types.mjs → types.js} +0 -0
- package/dist/runtime/components/Form/InputDateTime/{date_time_field.types.mjs → date_time_field.types.js} +0 -0
- package/dist/runtime/components/Form/{InputDateTimeRange/date_range_time_field.types.mjs → InputNumber/types.js} +0 -0
- package/dist/runtime/components/Form/{InputNumber/types.mjs → InputSelect/types.js} +0 -0
- package/dist/runtime/components/Form/{InputRadio/types.mjs → InputSelectMultiple/types.js} +0 -0
- package/dist/runtime/components/Form/{InputSelect/types.mjs → InputText/types.js} +0 -0
- package/dist/runtime/components/Form/{InputSelectMultiple/types.mjs → InputTextarea/types.js} +0 -0
- package/dist/runtime/components/Form/{InputStatic/types.mjs → InputToggle/types.js} +0 -0
- package/dist/runtime/components/Form/{types.mjs → types.js} +0 -0
- package/dist/runtime/composables/{useWatch.mjs → useWatch.js} +0 -0
- package/dist/runtime/lib/{Requester.mjs → Requester.js} +0 -0
- package/dist/runtime/{components/Form/InputTags/types.mjs → types/common.js} +0 -0
- package/dist/runtime/{components/Form/InputText/types.mjs → types/lib.js} +0 -0
- package/dist/runtime/utils/{FileHelper.mjs → FileHelper.js} +0 -0
- package/dist/runtime/utils/{StringHelper.mjs → StringHelper.js} +0 -0
- package/dist/runtime/utils/{TimeHelper.mjs → TimeHelper.js} +1 -1
- /package/dist/runtime/utils/{lodash.mjs → lodash.js} +0 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import Dialog from "../components/Dialog/index.vue";
|
|
2
|
+
import { useOverlay } from "#imports";
|
|
3
|
+
export var DialogType = /* @__PURE__ */ ((DialogType2) => {
|
|
4
|
+
DialogType2["ERROR"] = "error";
|
|
5
|
+
DialogType2["INFO"] = "info";
|
|
6
|
+
DialogType2["SUCCESS"] = "success";
|
|
7
|
+
DialogType2["WARNING"] = "warning";
|
|
8
|
+
return DialogType2;
|
|
9
|
+
})(DialogType || {});
|
|
10
|
+
export const useDialog = () => {
|
|
11
|
+
const overlay = useOverlay();
|
|
12
|
+
const openDialog = async (payload) => {
|
|
13
|
+
const modal = overlay.create(Dialog, { props: payload });
|
|
14
|
+
const result = await modal.open();
|
|
15
|
+
const res = await result.result;
|
|
16
|
+
return new Promise((resolve, reject) => {
|
|
17
|
+
if (res) {
|
|
18
|
+
resolve(true);
|
|
19
|
+
}
|
|
20
|
+
reject(false);
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
const error = async (payload) => {
|
|
24
|
+
return openDialog({
|
|
25
|
+
...payload,
|
|
26
|
+
type: "error" /* ERROR */
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
const success = async (payload) => {
|
|
30
|
+
return openDialog({
|
|
31
|
+
...payload,
|
|
32
|
+
type: "success" /* SUCCESS */
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
const info = async (payload) => {
|
|
36
|
+
return openDialog({
|
|
37
|
+
...payload,
|
|
38
|
+
type: "info" /* INFO */
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
const warning = async (payload) => {
|
|
42
|
+
return openDialog({
|
|
43
|
+
...payload,
|
|
44
|
+
type: "warning" /* WARNING */
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
return {
|
|
48
|
+
error,
|
|
49
|
+
success,
|
|
50
|
+
info,
|
|
51
|
+
warning
|
|
52
|
+
};
|
|
53
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ComputedRef } from 'vue';
|
|
2
|
+
import type { Store } from 'pinia';
|
|
2
3
|
import type { IUsePageLoader } from '#core/helpers/apiPageHelper';
|
|
3
4
|
import type { IFlexDeckOptions } from '#core/components/FlexDeck/types';
|
|
4
|
-
import type { Store } from 'pinia';
|
|
5
5
|
export interface IUseFlexDeck<T = object> {
|
|
6
6
|
repo: IUsePageLoader<T> | Store<any, any>;
|
|
7
7
|
options?: (() => Partial<IFlexDeckOptions<T>>) | Partial<IFlexDeckOptions<T>>;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { computed, useCoreConfig } from "#imports";
|
|
2
1
|
import { get } from "@vueuse/core";
|
|
2
|
+
import { computed, useCoreConfig } from "#imports";
|
|
3
3
|
export const createFlexDeckOptions = (repo, options) => {
|
|
4
4
|
const config = useCoreConfig();
|
|
5
5
|
return {
|
|
6
|
-
rawData: get(repo.
|
|
7
|
-
pageOptions: get(repo.
|
|
8
|
-
status: get(repo.
|
|
9
|
-
primary: get(repo.
|
|
6
|
+
rawData: get(repo.fetch.items),
|
|
7
|
+
pageOptions: get(repo.fetch.options),
|
|
8
|
+
status: get(repo.fetch.status),
|
|
9
|
+
primary: get(repo.fetch.options).primary || config.default_primary_key,
|
|
10
10
|
isPreventRouteChange: false,
|
|
11
11
|
...options
|
|
12
12
|
};
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ComputedRef } from 'vue';
|
|
2
2
|
import { type FieldContext, type FieldOptions } from 'vee-validate';
|
|
3
|
-
import {
|
|
3
|
+
import type { IFieldProps, IFormField } from '../components/Form/types.js';
|
|
4
4
|
interface IFieldContext<TValue> extends FieldContext<TValue> {
|
|
5
5
|
wrapperProps: ComputedRef<IFieldProps>;
|
|
6
6
|
}
|
|
7
7
|
export declare const useFieldHOC: <TValue = unknown>(newFormProps: IFieldProps, opts?: Partial<FieldOptions<TValue>>) => IFieldContext<TValue>;
|
|
8
8
|
export declare const createFormFields: (fields: () => IFormField[]) => ComputedRef<IFormField[]>;
|
|
9
|
+
export declare const moveToError: ({ errors }: {
|
|
10
|
+
errors: any;
|
|
11
|
+
}) => void;
|
|
9
12
|
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { useField } from "vee-validate";
|
|
2
|
+
import { toTypedSchema } from "@vee-validate/valibot";
|
|
3
|
+
import { computed, toRef } from "#imports";
|
|
4
|
+
export const useFieldHOC = (newFormProps, opts) => {
|
|
5
|
+
const field = useField(
|
|
6
|
+
toRef(newFormProps, "name"),
|
|
7
|
+
toTypedSchema(newFormProps.rules),
|
|
8
|
+
{
|
|
9
|
+
form: newFormProps.form,
|
|
10
|
+
...opts
|
|
11
|
+
}
|
|
12
|
+
);
|
|
13
|
+
return {
|
|
14
|
+
...field,
|
|
15
|
+
wrapperProps: computed(() => ({
|
|
16
|
+
...newFormProps,
|
|
17
|
+
ui: newFormProps.containerUi || {},
|
|
18
|
+
placeholder: newFormProps.placeholder || newFormProps.label,
|
|
19
|
+
errorMessage: field.errorMessage.value
|
|
20
|
+
}))
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
export const createFormFields = (fields) => computed(fields);
|
|
24
|
+
export const moveToError = ({ errors }) => {
|
|
25
|
+
const firstErrorFieldName = Object.keys(errors)[0];
|
|
26
|
+
const el = document.querySelector(`[name="${firstErrorFieldName}"]`);
|
|
27
|
+
if (el) {
|
|
28
|
+
el.focus({ preventScroll: true });
|
|
29
|
+
const elementRect = el.getBoundingClientRect();
|
|
30
|
+
const absoluteElementTop = elementRect.top + window.scrollY;
|
|
31
|
+
const paddingTop = 60;
|
|
32
|
+
window.scrollTo({
|
|
33
|
+
top: absoluteElementTop - paddingTop,
|
|
34
|
+
behavior: "smooth"
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
};
|
|
@@ -1,24 +1,8 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { Avatar } from '#ui/types/avatar';
|
|
3
|
-
import type { Button } from '#ui/types/button';
|
|
4
|
-
export interface INotification {
|
|
5
|
-
id: string;
|
|
6
|
-
title: string;
|
|
7
|
-
description?: string;
|
|
8
|
-
icon?: string;
|
|
9
|
-
avatar?: Avatar;
|
|
10
|
-
closeButton?: Button;
|
|
11
|
-
timeout: number;
|
|
12
|
-
actions?: NotificationAction[];
|
|
13
|
-
click?: (...args: any[]) => void;
|
|
14
|
-
callback?: (...args: any[]) => void;
|
|
15
|
-
color?: NotificationColor;
|
|
16
|
-
ui?: any;
|
|
17
|
-
}
|
|
1
|
+
import type { Toast } from '#ui/composables/useToast';
|
|
18
2
|
export declare const useNotification: () => {
|
|
19
|
-
info: (notification: Partial<
|
|
20
|
-
success: (notification: Partial<
|
|
21
|
-
warning: (notification: Partial<
|
|
22
|
-
error: (notification: Partial<
|
|
23
|
-
remove:
|
|
3
|
+
info: (notification: Partial<Toast>) => void;
|
|
4
|
+
success: (notification: Partial<Toast>) => void;
|
|
5
|
+
warning: (notification: Partial<Toast>) => void;
|
|
6
|
+
error: (notification: Partial<Toast>) => void;
|
|
7
|
+
remove: (id: string | number) => void;
|
|
24
8
|
};
|
|
@@ -1,48 +1,32 @@
|
|
|
1
1
|
import { useToast } from "#imports";
|
|
2
|
-
const safeList = [
|
|
3
|
-
"bg-success-200",
|
|
4
|
-
"bg-info-200",
|
|
5
|
-
"bg-danger-200",
|
|
6
|
-
"bg-warning-200",
|
|
7
|
-
"bg-primary-200"
|
|
8
|
-
];
|
|
9
|
-
const ui = (ui2 = {}, titleClass) => ({
|
|
10
|
-
background: "bg-{color}-200",
|
|
11
|
-
title: titleClass,
|
|
12
|
-
...ui2
|
|
13
|
-
});
|
|
14
2
|
export const useNotification = () => {
|
|
15
3
|
const toast = useToast();
|
|
16
4
|
const info = (notification) => {
|
|
17
5
|
toast.add({
|
|
18
6
|
icon: "ph:info",
|
|
19
7
|
color: "info",
|
|
20
|
-
...notification
|
|
21
|
-
ui: ui(notification.ui, "text-info")
|
|
8
|
+
...notification
|
|
22
9
|
});
|
|
23
10
|
};
|
|
24
11
|
const success = (notification) => {
|
|
25
12
|
toast.add({
|
|
26
13
|
icon: "ph:check-circle",
|
|
27
14
|
color: "success",
|
|
28
|
-
...notification
|
|
29
|
-
ui: ui(notification.ui, "text-success")
|
|
15
|
+
...notification
|
|
30
16
|
});
|
|
31
17
|
};
|
|
32
18
|
const warning = (notification) => {
|
|
33
19
|
toast.add({
|
|
34
20
|
icon: "ph:warning",
|
|
35
21
|
color: "warning",
|
|
36
|
-
...notification
|
|
37
|
-
ui: ui(notification.ui, "text-warning")
|
|
22
|
+
...notification
|
|
38
23
|
});
|
|
39
24
|
};
|
|
40
25
|
const error = (notification) => {
|
|
41
26
|
toast.add({
|
|
42
27
|
icon: "ph:x-circle",
|
|
43
|
-
color: "
|
|
44
|
-
...notification
|
|
45
|
-
ui: ui(notification.ui, "text-danger")
|
|
28
|
+
color: "error",
|
|
29
|
+
...notification
|
|
46
30
|
});
|
|
47
31
|
};
|
|
48
32
|
return {
|
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { ComputedRef } from 'vue';
|
|
2
|
+
import type { Store } from 'pinia';
|
|
3
|
+
import type { TableColumn, // Using local TableColumn
|
|
4
|
+
ISimpleTableOptions, ITableOptions } from '../components/Table/types.js';
|
|
5
|
+
import type { IUsePageLoader } from '../helpers/apiPageHelper.js';
|
|
3
6
|
import { type IStatus } from '#imports';
|
|
4
|
-
|
|
5
|
-
import { type IUsePageLoader } from '../helpers/apiPageHelper';
|
|
6
|
-
export interface IUseTable<T = object> {
|
|
7
|
+
export interface IUseTable<T extends Record<string, any> = object> {
|
|
7
8
|
repo: IUsePageLoader<T> | Store<any, any>;
|
|
8
|
-
columns: () =>
|
|
9
|
+
columns: () => TableColumn<T>[];
|
|
9
10
|
options?: (() => Partial<ITableOptions<T>>) | Partial<ITableOptions<T>>;
|
|
10
11
|
transformItems?: (items: T[]) => T[];
|
|
11
12
|
}
|
|
12
|
-
export interface IUseTableSimple<T = object> {
|
|
13
|
+
export interface IUseTableSimple<T extends Record<string, any> = object> {
|
|
13
14
|
items: () => T[];
|
|
14
15
|
status?: () => IStatus;
|
|
15
|
-
columns: () =>
|
|
16
|
+
columns: () => TableColumn<T>[];
|
|
16
17
|
options?: (() => Partial<ISimpleTableOptions<T>>) | Partial<ISimpleTableOptions<T>>;
|
|
17
18
|
}
|
|
18
|
-
export declare const useTable: <T
|
|
19
|
-
export declare const useTableSimple: <T
|
|
20
|
-
export declare const createTableOptions: <T
|
|
19
|
+
export declare const useTable: <T extends Record<string, any>>(options: IUseTable<T>) => ComputedRef<ITableOptions<T>>;
|
|
20
|
+
export declare const useTableSimple: <T extends Record<string, any>>(options: IUseTableSimple<T>) => ComputedRef<ISimpleTableOptions<T>>;
|
|
21
|
+
export declare const createTableOptions: <T extends Record<string, any>>(repo: IUsePageLoader<T>, columns: TableColumn<T>[], options: Partial<ITableOptions<T>>, transformItems?: (items: T[]) => T[]) => ITableOptions<T>;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { get } from "@vueuse/core";
|
|
2
2
|
import { computed, ObjectHelper } from "#imports";
|
|
3
|
-
import { useCoreConfig } from "./useConfig.mjs";
|
|
4
3
|
export const useTable = (options) => computed(() => {
|
|
5
4
|
return createTableOptions(
|
|
6
5
|
options.repo,
|
|
@@ -10,24 +9,20 @@ export const useTable = (options) => computed(() => {
|
|
|
10
9
|
);
|
|
11
10
|
});
|
|
12
11
|
export const useTableSimple = (options) => computed(() => {
|
|
13
|
-
const config = useCoreConfig();
|
|
14
12
|
return {
|
|
15
13
|
items: options.items(),
|
|
16
14
|
columns: options.columns(),
|
|
17
15
|
rawData: options.items(),
|
|
18
16
|
status: options.status ? options.status() : ObjectHelper.createStatus(),
|
|
19
|
-
primary: config.default_primary_key,
|
|
20
17
|
...typeof options.options === "function" ? options.options() : options.options ?? {}
|
|
21
18
|
};
|
|
22
19
|
});
|
|
23
20
|
export const createTableOptions = (repo, columns, options, transformItems) => {
|
|
24
|
-
const config = useCoreConfig();
|
|
25
21
|
return {
|
|
26
|
-
rawData: transformItems ? transformItems(get(repo.
|
|
27
|
-
pageOptions: get(repo.
|
|
22
|
+
rawData: transformItems ? transformItems(get(repo.fetch.items)) : get(repo.fetch.items),
|
|
23
|
+
pageOptions: get(repo.fetch.options),
|
|
28
24
|
columns,
|
|
29
|
-
status: get(repo.
|
|
30
|
-
primary: get(repo.fetchOptions).primary ?? config.default_primary_key,
|
|
25
|
+
status: get(repo.fetch.status),
|
|
31
26
|
isPreventRouteChange: false,
|
|
32
27
|
...options
|
|
33
28
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { AxiosRequestConfig } from 'axios';
|
|
2
2
|
export interface IUploadRequest {
|
|
3
3
|
requestOptions: Omit<AxiosRequestConfig, 'baseURL'> & {
|
|
4
4
|
baseURL: string;
|
|
5
5
|
};
|
|
6
6
|
pathURL?: string;
|
|
7
7
|
}
|
|
8
|
-
export declare const useUploadLoader: (request: IUploadRequest) => import("../helpers/apiObjectHelper").IUseObjectLoader<any, any, Record<string, any>>;
|
|
8
|
+
export declare const useUploadLoader: (request: IUploadRequest) => import("../helpers/apiObjectHelper.js").IUseObjectLoader<any, any, Record<string, any>>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { AxiosRequestConfig } from 'axios';
|
|
2
|
+
import type { IAPIOptions, IStatus } from '../types/lib.js';
|
|
3
|
+
export interface IBaseLoaderOptions {
|
|
4
|
+
isMock?: boolean;
|
|
5
|
+
params?: Record<string, any>;
|
|
6
|
+
expire?: number;
|
|
7
|
+
[key: string]: any;
|
|
8
|
+
}
|
|
9
|
+
export interface IRequestContext {
|
|
10
|
+
url: string;
|
|
11
|
+
method: string;
|
|
12
|
+
data?: any;
|
|
13
|
+
options: AxiosRequestConfig;
|
|
14
|
+
}
|
|
15
|
+
export declare const checkExpiration: (timestamp: number | undefined, expire?: number) => boolean;
|
|
16
|
+
export declare const bindParamsToUrl: (urlTemplate: string, urlParams?: Record<string, any>) => string;
|
|
17
|
+
export declare const prepareRequestOptions: (baseOptions?: AxiosRequestConfig, requestOptions?: AxiosRequestConfig, params?: Record<string, any>) => AxiosRequestConfig;
|
|
18
|
+
export declare const handleApiRequest: <T>(requestContext: IRequestContext, mockData: T | T[] | null, callbacks: {
|
|
19
|
+
onSuccess: (data: T, status?: number) => void;
|
|
20
|
+
onError: (error: any) => void;
|
|
21
|
+
onComplete?: () => void;
|
|
22
|
+
}) => Promise<void>;
|
|
23
|
+
export declare const updateLoaderState: {
|
|
24
|
+
setLoading: (status: IStatus) => IStatus;
|
|
25
|
+
setSuccess: (status: IStatus) => IStatus;
|
|
26
|
+
setError: (status: IStatus, error: any) => IStatus;
|
|
27
|
+
setComplete: (status: IStatus) => IStatus;
|
|
28
|
+
setOptions: (options: IAPIOptions, updates: Partial<IAPIOptions>) => IAPIOptions;
|
|
29
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { ObjectHelper } from "../utils/ObjectHelper.js";
|
|
2
|
+
import { ParamHelper } from "../utils/ParamHelper.js";
|
|
3
|
+
import { NewRequester } from "../lib/Requester.js";
|
|
4
|
+
export const checkExpiration = (timestamp, expire) => {
|
|
5
|
+
if (!expire || !timestamp) return false;
|
|
6
|
+
return timestamp + expire > Date.now();
|
|
7
|
+
};
|
|
8
|
+
export const bindParamsToUrl = (urlTemplate, urlParams = {}) => {
|
|
9
|
+
let resultUrl = urlTemplate;
|
|
10
|
+
Object.entries(urlParams).forEach(([key, value]) => {
|
|
11
|
+
resultUrl = resultUrl.replace(`:${key}`, String(value));
|
|
12
|
+
});
|
|
13
|
+
return resultUrl;
|
|
14
|
+
};
|
|
15
|
+
export const prepareRequestOptions = (baseOptions, requestOptions, params) => {
|
|
16
|
+
const options = {
|
|
17
|
+
...baseOptions || {},
|
|
18
|
+
...requestOptions || {}
|
|
19
|
+
};
|
|
20
|
+
options.params = ParamHelper.getParams({ params }, options);
|
|
21
|
+
return options;
|
|
22
|
+
};
|
|
23
|
+
export const handleApiRequest = async (requestContext, mockData, callbacks) => {
|
|
24
|
+
const {
|
|
25
|
+
url,
|
|
26
|
+
method,
|
|
27
|
+
data,
|
|
28
|
+
options
|
|
29
|
+
} = requestContext;
|
|
30
|
+
try {
|
|
31
|
+
if (mockData) {
|
|
32
|
+
await new Promise((resolve) => setTimeout(resolve, 300));
|
|
33
|
+
callbacks.onSuccess(mockData);
|
|
34
|
+
} else {
|
|
35
|
+
const response = await NewRequester.create(method, url, data, options);
|
|
36
|
+
callbacks.onSuccess(response.data, response.status);
|
|
37
|
+
}
|
|
38
|
+
} catch (error) {
|
|
39
|
+
callbacks.onError(error);
|
|
40
|
+
} finally {
|
|
41
|
+
callbacks.onComplete?.();
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
export const updateLoaderState = {
|
|
45
|
+
setLoading: (status) => ObjectHelper.toLoadingStatus(
|
|
46
|
+
status
|
|
47
|
+
),
|
|
48
|
+
setSuccess: (status) => ObjectHelper.toSuccessStatus(
|
|
49
|
+
status
|
|
50
|
+
),
|
|
51
|
+
setError: (status, error) => ObjectHelper.toErrorStatus(
|
|
52
|
+
status,
|
|
53
|
+
error
|
|
54
|
+
),
|
|
55
|
+
setComplete: (status) => ObjectHelper.toCompleteStatus(
|
|
56
|
+
status
|
|
57
|
+
),
|
|
58
|
+
setOptions: (options, updates) => ({
|
|
59
|
+
...options,
|
|
60
|
+
...updates,
|
|
61
|
+
_timestamp: Date.now()
|
|
62
|
+
})
|
|
63
|
+
};
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import { type IAPIListState, type IAPIOptions, type IStatus } from '#core/types/lib';
|
|
2
1
|
import type { AxiosRequestConfig } from 'axios';
|
|
3
|
-
|
|
2
|
+
import type { IAPIListState, IAPIOptions, IStatus } from '../types/lib.js';
|
|
3
|
+
import { type IBaseLoaderOptions } from './apiBaseHelper.js';
|
|
4
|
+
export interface IListRunLoaderOptions<T = any, D = Record<string, any>> extends IBaseLoaderOptions {
|
|
4
5
|
mockItems?: T[];
|
|
5
|
-
isMock?: boolean;
|
|
6
|
-
params?: Record<string, any>;
|
|
7
|
-
expire?: number;
|
|
8
6
|
data?: D;
|
|
9
7
|
}
|
|
10
|
-
export interface IListLoaderOptions<T, O> {
|
|
8
|
+
export interface IListLoaderOptions<T = any, O = any> {
|
|
11
9
|
url: string;
|
|
12
10
|
primary?: string;
|
|
13
11
|
mockItems?: T[];
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { bindParamsToUrl } from "./apiBaseHelper.js";
|
|
2
|
+
import {
|
|
3
|
+
checkExpiration,
|
|
4
|
+
prepareRequestOptions,
|
|
5
|
+
handleApiRequest,
|
|
6
|
+
updateLoaderState
|
|
7
|
+
} from "./apiBaseHelper.js";
|
|
8
|
+
export const apiListHelper = async (state, onUpdateStatus, onUpdateOptions, onUpdateItems, opts) => {
|
|
9
|
+
if (checkExpiration(state().options._timestamp, opts.expire)) {
|
|
10
|
+
onUpdateStatus(updateLoaderState.setComplete(state().status));
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
onUpdateStatus(updateLoaderState.setLoading(state().status));
|
|
14
|
+
onUpdateOptions({});
|
|
15
|
+
const requestOptions = prepareRequestOptions(
|
|
16
|
+
{},
|
|
17
|
+
opts.getRequestOptions?.(opts),
|
|
18
|
+
opts.params
|
|
19
|
+
);
|
|
20
|
+
const url = bindParamsToUrl(opts.getURL ? opts.getURL(opts) : opts.url, opts.urlBind || {});
|
|
21
|
+
await handleApiRequest(
|
|
22
|
+
{
|
|
23
|
+
url,
|
|
24
|
+
method: "GET",
|
|
25
|
+
options: requestOptions
|
|
26
|
+
},
|
|
27
|
+
opts.isMock ? opts.mockItems || [] : null,
|
|
28
|
+
{
|
|
29
|
+
onSuccess: (items, status) => {
|
|
30
|
+
onUpdateItems(items);
|
|
31
|
+
onUpdateStatus(updateLoaderState.setSuccess(state().status));
|
|
32
|
+
onUpdateOptions({
|
|
33
|
+
_timestamp: Date.now(),
|
|
34
|
+
_status: status,
|
|
35
|
+
request: requestOptions
|
|
36
|
+
});
|
|
37
|
+
},
|
|
38
|
+
onError: (error) => {
|
|
39
|
+
onUpdateStatus(updateLoaderState.setError(state().status, error));
|
|
40
|
+
onUpdateOptions({
|
|
41
|
+
_status: error.response?.status,
|
|
42
|
+
request: requestOptions
|
|
43
|
+
});
|
|
44
|
+
},
|
|
45
|
+
onComplete: () => {
|
|
46
|
+
onUpdateStatus(updateLoaderState.setComplete(state().status));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
);
|
|
50
|
+
};
|
|
@@ -1,38 +1,37 @@
|
|
|
1
|
-
import { type IAPIObjectState, type IAPIOptions, type IStatus } from '#core/types/lib';
|
|
2
1
|
import type { AxiosRequestConfig, Method } from 'axios';
|
|
3
|
-
import type {
|
|
4
|
-
import {
|
|
5
|
-
|
|
2
|
+
import type { ComputedRef } from 'vue';
|
|
3
|
+
import type { IAPIObjectState, IAPIOptions, IStatus } from '../types/lib.js';
|
|
4
|
+
import { type IBaseLoaderOptions } from './apiBaseHelper.js';
|
|
5
|
+
import type { IListRunLoaderOptions } from './apiListHelper.js';
|
|
6
|
+
export interface IObjectRunLoaderOptions<T = any, B = any> extends IBaseLoaderOptions {
|
|
6
7
|
mockItem?: T;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
expire?: number;
|
|
10
|
-
data?: D;
|
|
8
|
+
data?: B;
|
|
9
|
+
urlBind?: Record<string, any>;
|
|
11
10
|
}
|
|
12
|
-
export interface IObjectLoaderOptions<T, B,
|
|
11
|
+
export interface IObjectLoaderOptions<T = any, B = any, _O = any> {
|
|
13
12
|
url: string;
|
|
14
13
|
method: Method;
|
|
15
14
|
primary?: string;
|
|
16
15
|
mockItem?: T;
|
|
17
|
-
getURL?: (data: B | undefined, opts: IObjectRunLoaderOptions<T,
|
|
18
|
-
getRequestOptions?: (data: B | undefined, opts: IObjectRunLoaderOptions<T,
|
|
16
|
+
getURL?: (data: B | undefined, opts: IObjectRunLoaderOptions<T, B>) => string;
|
|
17
|
+
getRequestOptions?: (data: B | undefined, opts: IObjectRunLoaderOptions<T, B>) => AxiosRequestConfig;
|
|
19
18
|
}
|
|
20
|
-
export interface IUseObjectLoader<T, B,
|
|
21
|
-
status:
|
|
22
|
-
data:
|
|
23
|
-
options:
|
|
24
|
-
run: (
|
|
19
|
+
export interface IUseObjectLoader<T, B, _O> {
|
|
20
|
+
status: ComputedRef<IStatus>;
|
|
21
|
+
data: ComputedRef<T | null>;
|
|
22
|
+
options: ComputedRef<IAPIOptions>;
|
|
23
|
+
run: (payload?: IObjectRunLoaderOptions<T, B>) => Promise<void>;
|
|
25
24
|
clear: () => void;
|
|
26
25
|
setLoading: () => void;
|
|
27
26
|
setData: (data: T | null) => void;
|
|
28
27
|
}
|
|
29
28
|
export interface IUseListLoader<T, O> {
|
|
30
|
-
status:
|
|
31
|
-
items:
|
|
32
|
-
options:
|
|
29
|
+
status: ComputedRef<IStatus>;
|
|
30
|
+
items: ComputedRef<T[]>;
|
|
31
|
+
options: ComputedRef<Record<string, any>>;
|
|
33
32
|
run: (opts?: IListRunLoaderOptions<T, O>) => void;
|
|
34
33
|
setItems: (items: T[]) => void;
|
|
35
34
|
clear: () => void;
|
|
36
35
|
setLoading: () => void;
|
|
37
36
|
}
|
|
38
|
-
export declare const apiObjectHelper: <T, B,
|
|
37
|
+
export declare const apiObjectHelper: <T, B, _O>(state: () => IAPIObjectState<T>, onUpdateStatus: (status: IStatus) => void, onUpdateOptions: (options: IAPIOptions) => void, onUpdateData: (data?: T) => void, payload: B | undefined, opts: IObjectLoaderOptions<T, B, _O> & IObjectRunLoaderOptions<T, B>) => Promise<void>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { bindParamsToUrl } from "./apiBaseHelper.js";
|
|
2
|
+
import {
|
|
3
|
+
checkExpiration,
|
|
4
|
+
handleApiRequest,
|
|
5
|
+
prepareRequestOptions,
|
|
6
|
+
updateLoaderState
|
|
7
|
+
} from "./apiBaseHelper.js";
|
|
8
|
+
export const apiObjectHelper = async (state, onUpdateStatus, onUpdateOptions, onUpdateData, payload, opts) => {
|
|
9
|
+
if (checkExpiration(state().options._timestamp, opts.expire)) {
|
|
10
|
+
onUpdateStatus(updateLoaderState.setComplete(state().status));
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
onUpdateStatus(updateLoaderState.setLoading(state().status));
|
|
14
|
+
onUpdateOptions({});
|
|
15
|
+
const requestOptions = prepareRequestOptions(
|
|
16
|
+
{},
|
|
17
|
+
opts.getRequestOptions?.(payload, opts),
|
|
18
|
+
opts.params
|
|
19
|
+
);
|
|
20
|
+
const url = bindParamsToUrl(opts.getURL ? opts.getURL(payload, opts) : opts.url, opts.urlBind || {});
|
|
21
|
+
await handleApiRequest(
|
|
22
|
+
{
|
|
23
|
+
url,
|
|
24
|
+
method: opts.method,
|
|
25
|
+
data: payload,
|
|
26
|
+
options: requestOptions
|
|
27
|
+
},
|
|
28
|
+
opts.isMock ? opts.mockItem || null : null,
|
|
29
|
+
{
|
|
30
|
+
onSuccess: (item, status) => {
|
|
31
|
+
onUpdateData(item);
|
|
32
|
+
onUpdateStatus(updateLoaderState.setSuccess(state().status));
|
|
33
|
+
onUpdateOptions({
|
|
34
|
+
request: requestOptions,
|
|
35
|
+
_timestamp: Date.now(),
|
|
36
|
+
_status: status
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
onError: (error) => {
|
|
40
|
+
onUpdateStatus(updateLoaderState.setError(state().status, error));
|
|
41
|
+
onUpdateOptions({
|
|
42
|
+
request: requestOptions,
|
|
43
|
+
_status: error.response?.status
|
|
44
|
+
});
|
|
45
|
+
},
|
|
46
|
+
onComplete: () => {
|
|
47
|
+
onUpdateStatus(updateLoaderState.setComplete(state().status));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
);
|
|
51
|
+
};
|