inertia-bootstrap-forms 1.0.56 → 1.0.58
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index-BNTFmIVu.js +604 -0
- package/dist/index-Cr0ZhLal.js +13183 -0
- package/dist/inertia-bootstrap-forms.es.js +29 -10748
- package/dist/inertia-bootstrap-forms.umd.js +17 -3
- package/dist/style.css +1 -1
- package/index.d.ts +41 -0
- package/package.json +9 -1
- package/src/RangeSliderInput.vue +0 -1
- package/src/UppyInput.vue +181 -0
- package/src/index.js +2 -0
package/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ import EditorInput from './src/EditorInput.vue';
|
|
|
10
10
|
import EmailInput from './src/EmailInput.vue';
|
|
11
11
|
import FileInput from './src/FileInput.vue';
|
|
12
12
|
import SimpleUploader from './src/SimpleUploader.vue';
|
|
13
|
+
import UppyInput from './src/UppyInput.vue';
|
|
13
14
|
import FormContainer from './src/FormContainer.vue';
|
|
14
15
|
import FormLabel from './src/FormLabel.vue';
|
|
15
16
|
import GroupControl from './src/GroupControl.vue';
|
|
@@ -40,6 +41,7 @@ export {
|
|
|
40
41
|
EditorInput,
|
|
41
42
|
EmailInput,
|
|
42
43
|
DropzoneInput,
|
|
44
|
+
UppyInput,
|
|
43
45
|
FileInput,
|
|
44
46
|
SimpleUploader,
|
|
45
47
|
FormContainer,
|
|
@@ -72,6 +74,7 @@ const Vue3FormComponents = {
|
|
|
72
74
|
countryCodes,
|
|
73
75
|
EditorInput,
|
|
74
76
|
DropzoneInput,
|
|
77
|
+
UppyInput,
|
|
75
78
|
EmailInput,
|
|
76
79
|
FileInput,
|
|
77
80
|
SimpleUploader,
|
|
@@ -153,6 +156,44 @@ export const EditorInput: DefineComponent<{
|
|
|
153
156
|
}, {}, any>;
|
|
154
157
|
export const EmailInput: DefineComponent<{}, {}, any>;
|
|
155
158
|
export const DropzoneInput: DefineComponent<{}, {}, any>;
|
|
159
|
+
export const UppyInput: DefineComponent<{
|
|
160
|
+
name: {
|
|
161
|
+
type: String,
|
|
162
|
+
required: true,
|
|
163
|
+
},
|
|
164
|
+
multiple: {
|
|
165
|
+
type: Boolean,
|
|
166
|
+
default: false,
|
|
167
|
+
},
|
|
168
|
+
modelValue: String,
|
|
169
|
+
url: { type: String, default: "/upload" },
|
|
170
|
+
options: { type: Object, default: () => ({}) },
|
|
171
|
+
}, {},
|
|
172
|
+
any,
|
|
173
|
+
{},
|
|
174
|
+
{},
|
|
175
|
+
{},
|
|
176
|
+
{},
|
|
177
|
+
{
|
|
178
|
+
'update:modelValue': (value: string) => void,
|
|
179
|
+
'file-added': (file) => void,
|
|
180
|
+
'file-removed': (file) => void,
|
|
181
|
+
'beforeUpload': (files) => void,
|
|
182
|
+
'progress': (progress) => void,
|
|
183
|
+
'upload': (uploadID, file) => void,
|
|
184
|
+
'upload-progress': (file, progress) => void,
|
|
185
|
+
'upload-error': (file, error, response) => void,
|
|
186
|
+
'upload-success': (file, response) => void,
|
|
187
|
+
'upload-pause': (file, isPaused) => void,
|
|
188
|
+
'complete': (result) => void,
|
|
189
|
+
'error': (error) => void,
|
|
190
|
+
'upload-retry': (file) => void,
|
|
191
|
+
'upload-stalled': (error, files) => void,
|
|
192
|
+
'retry-all': (files) => void,
|
|
193
|
+
'cancel-all': () => void,
|
|
194
|
+
'restriction-failed': (file, error) => void,
|
|
195
|
+
}
|
|
196
|
+
>;
|
|
156
197
|
export const FileInput: DefineComponent<{}, {}, any>;
|
|
157
198
|
export const SimpleUploader: DefineComponent<{}, {}, any>;
|
|
158
199
|
export const FormContainer: DefineComponent<{}, {}, any>;
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "inertia-bootstrap-forms",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.58",
|
|
4
4
|
"description": "Create bootstrap forms with inertia and twitter bootstrap",
|
|
5
5
|
"main": "dist/inertia-bootstrap-forms.cjs.js",
|
|
6
6
|
"module": "dist/inertia-bootstrap-forms.es.js",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"types": "./index.d.ts",
|
|
9
9
|
"scripts": {
|
|
10
|
+
"dev": "vite build --watch",
|
|
10
11
|
"build": "vite build"
|
|
11
12
|
},
|
|
12
13
|
"files": [
|
|
@@ -37,6 +38,13 @@
|
|
|
37
38
|
],
|
|
38
39
|
"dependencies": {
|
|
39
40
|
"@tinymce/tinymce-vue": "^6.1.0",
|
|
41
|
+
"@uppy/audio": "^3.1.0",
|
|
42
|
+
"@uppy/core": "^5.2.0",
|
|
43
|
+
"@uppy/dashboard": "^5.1.1",
|
|
44
|
+
"@uppy/drag-drop": "^5.1.0",
|
|
45
|
+
"@uppy/locales": "^5.1.1",
|
|
46
|
+
"@uppy/vue": "^3.2.0",
|
|
47
|
+
"@uppy/xhr-upload": "^5.1.1",
|
|
40
48
|
"@vitejs/plugin-vue": "^5.2.4",
|
|
41
49
|
"@vue-leaflet/vue-leaflet": "^0.10.1",
|
|
42
50
|
"choices.js": "^11.1.0",
|
package/src/RangeSliderInput.vue
CHANGED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="uppy-input-area" ref="inputEl" v-if="uppy">
|
|
3
|
+
<UppyContextProvider :name="'uu' + name" :uppy="uppy">
|
|
4
|
+
<slot :uppy="uppy">
|
|
5
|
+
<FilesList class="uppy-file-lists"/>
|
|
6
|
+
<Dropzone/>
|
|
7
|
+
</slot>
|
|
8
|
+
</UppyContextProvider>
|
|
9
|
+
</div>
|
|
10
|
+
</template>
|
|
11
|
+
|
|
12
|
+
<script setup>
|
|
13
|
+
import {computed, inject, onBeforeUnmount, onMounted, shallowRef, ref} from 'vue'
|
|
14
|
+
import {
|
|
15
|
+
Dropzone,
|
|
16
|
+
FilesList,
|
|
17
|
+
UppyContextProvider,
|
|
18
|
+
} from '@uppy/vue';
|
|
19
|
+
import Uppy from '@uppy/core';
|
|
20
|
+
|
|
21
|
+
const props = defineProps({
|
|
22
|
+
name: {type: String, required: true},
|
|
23
|
+
multiple: {type: Boolean, default: false},
|
|
24
|
+
useXHR: {type: Boolean, default: true},
|
|
25
|
+
XHRConfig: {type: Object, default: {}},
|
|
26
|
+
url: {type: String, default: '/upload'},
|
|
27
|
+
config: {type: Object, default: () => ({})},
|
|
28
|
+
errorHandler: {type: Function, default: null},
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
const emits = defineEmits([
|
|
32
|
+
'update:modelValue', 'file-added', 'file-removed', 'beforeUpload',
|
|
33
|
+
'progress', 'upload', 'upload-progress', 'upload-error',
|
|
34
|
+
'upload-success', 'upload-pause', 'complete', 'error',
|
|
35
|
+
'upload-retry', 'upload-stalled', 'retry-all', 'cancel-all',
|
|
36
|
+
'restriction-failed',
|
|
37
|
+
])
|
|
38
|
+
|
|
39
|
+
const inputEl = ref(null);
|
|
40
|
+
const uppy = shallowRef(null);
|
|
41
|
+
|
|
42
|
+
// Inject form and group contexts
|
|
43
|
+
const form = inject("form", {value: {}, errors: {}, getID: n => n});
|
|
44
|
+
const group = inject("group", null);
|
|
45
|
+
|
|
46
|
+
const modelValue = computed({
|
|
47
|
+
get() {
|
|
48
|
+
return group?.value?.name
|
|
49
|
+
? group.value.getData(props.name)
|
|
50
|
+
: form.value[props.name];
|
|
51
|
+
},
|
|
52
|
+
set(val) {
|
|
53
|
+
if (group?.value?.name) {
|
|
54
|
+
group.value.setData(props.name, val);
|
|
55
|
+
} else {
|
|
56
|
+
form.value[props.name] = val;
|
|
57
|
+
}
|
|
58
|
+
emits("update:modelValue", val);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// ایجاد اینستنس اختصاصی برای هر کامپوننت
|
|
63
|
+
uppy.value = new Uppy({
|
|
64
|
+
id: props.name, // جلوگیری از تداخل با استفاده از نام پروپ
|
|
65
|
+
autoProceed: true,
|
|
66
|
+
...props.config,
|
|
67
|
+
restrictions: {
|
|
68
|
+
maxNumberOfFiles: props.multiple ? 10 : 1,
|
|
69
|
+
...(props.config?.restrictions || {})
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
uppy.value.on('before-upload', (files) => {
|
|
74
|
+
emits('beforeUpload', files);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
uppy.value.on('upload-success', (file, response) => {
|
|
78
|
+
const result = response.body ?? response;
|
|
79
|
+
if (props.multiple) {
|
|
80
|
+
const currentValues = Array.isArray(modelValue.value) ? modelValue.value : [];
|
|
81
|
+
modelValue.value = [...currentValues, result];
|
|
82
|
+
} else {
|
|
83
|
+
modelValue.value = result;
|
|
84
|
+
}
|
|
85
|
+
emits('upload-success', file, response);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
uppy.value.on('file-added', (file) => emits('file-added', file));
|
|
89
|
+
uppy.value.on('file-removed', (file) => {
|
|
90
|
+
if (props.multiple && Array.isArray(modelValue.value)) {
|
|
91
|
+
const serverResponse = file.response?.body ?? file.response;
|
|
92
|
+
modelValue.value = modelValue.value.filter(item => {
|
|
93
|
+
// مقایسه بر اساس شناسه یا کل آبجکت (بسته به ساختار ارسالی سرور شما)
|
|
94
|
+
// اگر سرور ID برمیگرداند: return item.id !== serverResponse.id;
|
|
95
|
+
// اگر مستقیماً خود آبجکت است:
|
|
96
|
+
return JSON.stringify(item) !== JSON.stringify(serverResponse);
|
|
97
|
+
});
|
|
98
|
+
} else {
|
|
99
|
+
modelValue.value = null;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// بخش حذف از سرور
|
|
103
|
+
if (file.response) {
|
|
104
|
+
fetch(props.url, {
|
|
105
|
+
method: 'DELETE',
|
|
106
|
+
headers: {
|
|
107
|
+
'X-Requested-With': 'XMLHttpRequest',
|
|
108
|
+
'Content-Type': 'application/json',
|
|
109
|
+
},
|
|
110
|
+
body: JSON.stringify(file.response.body ?? file.response),
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
emits('file-removed', file);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
uppy.value.on('complete', (result) => emits('complete', result));
|
|
118
|
+
uppy.value.on('error', (error) => emits('error', error));
|
|
119
|
+
|
|
120
|
+
uppy.value.on('restriction-failed', (file, error) => {
|
|
121
|
+
if (props.errorHandler) {
|
|
122
|
+
props.errorHandler(error);
|
|
123
|
+
} else {
|
|
124
|
+
showError(error.message);
|
|
125
|
+
}
|
|
126
|
+
emits('restriction-failed', file, error);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
onMounted(() => {
|
|
130
|
+
let XHR;
|
|
131
|
+
if (props.useXHR) {
|
|
132
|
+
import('@uppy/xhr-upload').then(module => {
|
|
133
|
+
XHR = module.default; // چون اکثر پکیجها default export دارند
|
|
134
|
+
uppy.value.use(XHR, {
|
|
135
|
+
endpoint: props.url,
|
|
136
|
+
...props.XHRConfig
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
onBeforeUnmount(() => {
|
|
143
|
+
if (uppy.value) {
|
|
144
|
+
uppy.value.destroy();
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
function showError(message) {
|
|
149
|
+
const errorEl = document.createElement('div');
|
|
150
|
+
errorEl.textContent = message;
|
|
151
|
+
errorEl.className = 'uppy-error';
|
|
152
|
+
|
|
153
|
+
if (inputEl.value) {
|
|
154
|
+
inputEl.value.prepend(errorEl);
|
|
155
|
+
setTimeout(() => errorEl.remove(), 3000);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
</script>
|
|
159
|
+
|
|
160
|
+
<style>
|
|
161
|
+
.uppy-reset p {
|
|
162
|
+
margin-bottom: 0;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
.uppy-file-lists > ul {
|
|
166
|
+
list-style: none;
|
|
167
|
+
padding: 0;
|
|
168
|
+
margin: 0;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
.uppy-input-area .uppy-error {
|
|
172
|
+
display: block;
|
|
173
|
+
padding: 5px;
|
|
174
|
+
background-color: #f8d7da;
|
|
175
|
+
border: 1px solid #f5c2c7;
|
|
176
|
+
color: #842029;
|
|
177
|
+
text-align: center;
|
|
178
|
+
border-radius: 0.5rem;
|
|
179
|
+
margin-bottom: 5px;
|
|
180
|
+
}
|
|
181
|
+
</style>
|
package/src/index.js
CHANGED
|
@@ -25,6 +25,7 @@ import TextInput from "./TextInput.vue";
|
|
|
25
25
|
import DropzoneInput from "./DropzoneInput.vue";
|
|
26
26
|
import SimpleUploader from "./SimpleUploader.vue";
|
|
27
27
|
import RangeSliderInput from "./RangeSliderInput.vue";
|
|
28
|
+
import UppyInput from "./UppyInput.vue";
|
|
28
29
|
|
|
29
30
|
export {
|
|
30
31
|
AmountInput,
|
|
@@ -39,6 +40,7 @@ export {
|
|
|
39
40
|
DropzoneInput,
|
|
40
41
|
SimpleUploader,
|
|
41
42
|
RangeSliderInput,
|
|
43
|
+
UppyInput,
|
|
42
44
|
GroupControl,
|
|
43
45
|
FormContainer,
|
|
44
46
|
LocationInput,
|