nuxt-unified-ui 0.2.6 → 0.2.7
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.
|
@@ -16,6 +16,7 @@ import FormElementSelect from '../elements/form-element-select.vue';
|
|
|
16
16
|
import FormElementSeries from '../elements/form-element-series.vue';
|
|
17
17
|
import FormElementCheckbox from '../elements/form-element-checkbox.vue';
|
|
18
18
|
import FormElementDate from '../elements/form-element-date.vue';
|
|
19
|
+
import FormElementMedia from '../elements/form-element-media.vue';
|
|
19
20
|
|
|
20
21
|
|
|
21
22
|
const elementsMap = {
|
|
@@ -25,6 +26,7 @@ const elementsMap = {
|
|
|
25
26
|
'series': FormElementSeries,
|
|
26
27
|
'date': FormElementDate,
|
|
27
28
|
'checkbox': FormElementCheckbox,
|
|
29
|
+
'media': FormElementMedia,
|
|
28
30
|
};
|
|
29
31
|
|
|
30
32
|
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
|
|
3
|
+
/* interface */
|
|
4
|
+
|
|
5
|
+
const props = defineProps({
|
|
6
|
+
field: Object,
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
const modelValue = defineModel();
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
/* media */
|
|
13
|
+
|
|
14
|
+
const { data: media, pending } = useUFetch(
|
|
15
|
+
computed(() => `/media/${modelValue.value}`),
|
|
16
|
+
{
|
|
17
|
+
method: computed(() => !modelValue.value ? '' : 'get'),
|
|
18
|
+
},
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
const fieldTitle = computed(() => {
|
|
23
|
+
return media.value?.name;
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
/* upload */
|
|
28
|
+
|
|
29
|
+
const isUploading = ref(false);
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
const { open: openFilePicker, onChange, reset: resetFilePicker } = useFileDialog({
|
|
33
|
+
accept: () => props.field.accept,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
onChange(async files => {
|
|
38
|
+
|
|
39
|
+
const file = files?.[0];
|
|
40
|
+
|
|
41
|
+
if (!file) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
const body = new FormData();
|
|
47
|
+
body.append('file', file);
|
|
48
|
+
|
|
49
|
+
const response = await ufetch('/media/upload', {
|
|
50
|
+
loading: isUploading,
|
|
51
|
+
method: 'post',
|
|
52
|
+
body,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
modelValue.value = response?._id;
|
|
57
|
+
resetFilePicker();
|
|
58
|
+
|
|
59
|
+
toastSuccess({
|
|
60
|
+
title: 'فایل با موفقیت آپلود شد.',
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
</script>
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
<template>
|
|
69
|
+
<u-form-field v-bind="radPick(props.field, [ 'label' ])">
|
|
70
|
+
<div class="flex items-start gap-2 ltr">
|
|
71
|
+
|
|
72
|
+
<template v-if="media?.type?.startsWith('image')">
|
|
73
|
+
<u-popover mode="hover">
|
|
74
|
+
|
|
75
|
+
<img
|
|
76
|
+
:src="makeMediaFullPath(media?.path)"
|
|
77
|
+
class="size-8 rounded object-cover"
|
|
78
|
+
/>
|
|
79
|
+
|
|
80
|
+
<template #content>
|
|
81
|
+
<img
|
|
82
|
+
:src="makeMediaFullPath(media?.path)"
|
|
83
|
+
class="w-64 rounded"
|
|
84
|
+
/>
|
|
85
|
+
</template>
|
|
86
|
+
|
|
87
|
+
</u-popover>
|
|
88
|
+
</template>
|
|
89
|
+
|
|
90
|
+
<u-input
|
|
91
|
+
class="w-full ltr"
|
|
92
|
+
icon="lucide:file"
|
|
93
|
+
v-bind="radOmit(props.field, [ 'key', 'identifier', 'label' ])"
|
|
94
|
+
readonly
|
|
95
|
+
:loading="pending || isUploading"
|
|
96
|
+
:model-value="fieldTitle"
|
|
97
|
+
@click="openFilePicker()"
|
|
98
|
+
/>
|
|
99
|
+
|
|
100
|
+
</div>
|
|
101
|
+
</u-form-field>
|
|
102
|
+
</template>
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-unified-ui",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
5
|
-
"main": "./nuxt.config.
|
|
4
|
+
"version": "0.2.7",
|
|
5
|
+
"main": "./nuxt.config.ts",
|
|
6
6
|
"exports": {
|
|
7
|
-
".": "./nuxt.config.
|
|
7
|
+
".": "./nuxt.config.ts",
|
|
8
8
|
"./nuxt-ui-fixes.css": "./app/assets/css/nuxt-ui-fixes.css"
|
|
9
9
|
},
|
|
10
10
|
"files": [
|
|
11
|
-
"nuxt.config.
|
|
11
|
+
"nuxt.config.ts",
|
|
12
12
|
"package.json",
|
|
13
13
|
"app",
|
|
14
14
|
"modules"
|
|
@@ -24,6 +24,6 @@
|
|
|
24
24
|
"unified-mongo-filter": "0.4.0"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
|
-
"nuxt": ">4.2.
|
|
27
|
+
"nuxt": ">4.2.0"
|
|
28
28
|
}
|
|
29
29
|
}
|
|
File without changes
|