inertia-bootstrap-forms 1.0.65 → 1.0.66

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/index.d.ts CHANGED
@@ -165,6 +165,10 @@ export const UppyInput: DefineComponent<{
165
165
  type: Boolean,
166
166
  default: false,
167
167
  },
168
+ showRestrictionCaption: {
169
+ type: Boolean,
170
+ default: true,
171
+ },
168
172
  modelValue: String,
169
173
  url: { type: String, default: "/upload" },
170
174
  options: { type: Object, default: () => ({}) },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inertia-bootstrap-forms",
3
- "version": "1.0.65",
3
+ "version": "1.0.66",
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",
package/src/UppyInput.vue CHANGED
@@ -6,6 +6,7 @@
6
6
  <Dropzone/>
7
7
  </slot>
8
8
  </UppyContextProvider>
9
+ <div class="uppy-input-area--caption small text-body-secondary fst-italic" v-if="restrictionCaption">{{restrictionCaption}}</div>
9
10
  </div>
10
11
  </template>
11
12
 
@@ -28,6 +29,7 @@ const props = defineProps({
28
29
  url: {type: String, default: '/upload'},
29
30
  config: {type: Object, default: () => ({})},
30
31
  errorHandler: {type: Function, default: null},
32
+ showRestrictionCaption: {type: Boolean, default: true},
31
33
  })
32
34
 
33
35
  const emits = defineEmits([
@@ -38,6 +40,7 @@ const emits = defineEmits([
38
40
  'restriction-failed',
39
41
  ])
40
42
 
43
+ const restrictionCaption = ref(null);
41
44
  const inputEl = ref(null);
42
45
  const uppy = shallowRef(null);
43
46
 
@@ -67,7 +70,7 @@ uppy.value = new Uppy({
67
70
  autoProceed: true,
68
71
  ...props.config,
69
72
  restrictions: {
70
- maxNumberOfFiles: props.multiple ? 10 : 1,
73
+ maxNumberOfFiles: props.multiple ? null : 1,
71
74
  ...(props.config?.restrictions || {})
72
75
  },
73
76
  });
@@ -156,6 +159,12 @@ onMounted(() => {
156
159
  });
157
160
  });
158
161
  }
162
+
163
+ if(uppy.value?.opts?.restrictions){
164
+ console.log(uppy.value?.opts?.restrictions);
165
+ restrictionCaption.value = buildRestrictionsCaption(uppy.value.opts.restrictions)
166
+ console.log('restrictionCaption', restrictionCaption.value);
167
+ }
159
168
  });
160
169
 
161
170
  onBeforeUnmount(() => {
@@ -182,6 +191,62 @@ function showError(message) {
182
191
  setTimeout(() => errorEl.remove(), 3000);
183
192
  }
184
193
  }
194
+
195
+ function formatBytesToKB(size) {
196
+ if (!size) return null;
197
+ return Math.round(size / 1024);
198
+ }
199
+
200
+ function buildRestrictionsCaption(restrictions) {
201
+ if (!restrictions) return '';
202
+
203
+ const {
204
+ allowedFileTypes,
205
+ maxFileSize,
206
+ minFileSize,
207
+ maxNumberOfFiles,
208
+ minNumberOfFiles,
209
+ maxTotalFileSize,
210
+ } = restrictions;
211
+
212
+ const parts = [];
213
+
214
+ // پسوندها
215
+ if (allowedFileTypes && allowedFileTypes.length) {
216
+ const types = allowedFileTypes
217
+ .map(type => type.replace('.', ''))
218
+ .join('، ');
219
+ parts.push(`فقط فایل با پسوندهای ${types}`);
220
+ }
221
+
222
+ // تعداد فایل
223
+ if (maxNumberOfFiles) {
224
+ parts.push(`امکان انتخاب حداکثر ${maxNumberOfFiles} فایل`);
225
+ }
226
+
227
+ if (minNumberOfFiles) {
228
+ parts.push(`حداقل ${minNumberOfFiles} فایل نیاز است`);
229
+ }
230
+
231
+ // حجم هر فایل
232
+ if (maxFileSize) {
233
+ parts.push(`با حداکثر حجم ${formatBytesToKB(maxFileSize)} کیلوبایت برای هر فایل`);
234
+ }
235
+
236
+ if (minFileSize) {
237
+ parts.push(`با حداقل حجم ${formatBytesToKB(minFileSize)} کیلوبایت برای هر فایل`);
238
+ }
239
+
240
+ // مجموع حجم
241
+ if (maxTotalFileSize) {
242
+ parts.push(`و مجموع حجم کل حداکثر ${formatBytesToKB(maxTotalFileSize)} کیلوبایت`);
243
+ }
244
+
245
+ if (!parts.length) return '';
246
+
247
+ return parts.join('، ') + ' مجاز است.';
248
+ }
249
+
185
250
  </script>
186
251
 
187
252
  <style>