inertia-bootstrap-forms 1.0.81 → 1.0.84

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
@@ -200,7 +200,55 @@ export const UppyInput: DefineComponent<{
200
200
  >;
201
201
  export const FileInput: DefineComponent<{}, {}, any>;
202
202
  export const SimpleUploader: DefineComponent<{}, {}, any>;
203
- export const FormContainer: DefineComponent<{}, {}, any>;
203
+ export const FormContainer: DefineComponent<{
204
+ url: {
205
+ type: String,
206
+ default: '',
207
+ required: false,
208
+ },
209
+ method: {
210
+ default: 'post'
211
+ },
212
+ only: {
213
+ type: Array,
214
+ default: [],
215
+ required: false,
216
+ },
217
+ modelValue: {
218
+ type: Object,
219
+ default: {},
220
+ required: false,
221
+ },
222
+ options: {
223
+ type: Object,
224
+ default: {},
225
+ required: false,
226
+ },
227
+ resetOnSuccess: {
228
+ type: Boolean,
229
+ default: true,
230
+ },
231
+ submitHandler: {
232
+ type: Function,
233
+ default: null,
234
+ required: false,
235
+ },
236
+ }, {}, any,
237
+ {},
238
+ {},
239
+ {},
240
+ {},
241
+ {
242
+ 'update:modelValue': (data) => void,
243
+ 'submit': (event) => void,
244
+ 'reset': (file) => void,
245
+ 'onStart': () => void,
246
+ 'onFinish': (data) => void,
247
+ 'onSuccess': (data) => void,
248
+ 'onError': (errors) => void,
249
+ 'change': (data) => void,
250
+ }
251
+ >;
204
252
  export const FormLabel: DefineComponent<{}, {}, any>;
205
253
  export const GroupControl: DefineComponent<{}, {}, any>;
206
254
  export const LocationInput: DefineComponent<{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inertia-bootstrap-forms",
3
- "version": "1.0.81",
3
+ "version": "1.0.84",
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",
@@ -25,6 +25,15 @@ export default defineComponent({
25
25
  default: {},
26
26
  required: false,
27
27
  },
28
+ options: {
29
+ type: Object,
30
+ default: {},
31
+ required: false,
32
+ },
33
+ resetOnSuccess: {
34
+ type: Boolean,
35
+ default: true,
36
+ },
28
37
  submitHandler: {
29
38
  type: Function,
30
39
  default: null,
@@ -37,6 +46,7 @@ export default defineComponent({
37
46
  const form = useForm({
38
47
  hasMessage: false,
39
48
  successMessage: null,
49
+ ...props.options,
40
50
  ...formData
41
51
  });
42
52
 
@@ -132,6 +142,10 @@ export default defineComponent({
132
142
  this.form.successMessage = data?.props?.message;
133
143
  }
134
144
 
145
+ if (this.resetOnSuccess) {
146
+ this.form?.reset();
147
+ }
148
+
135
149
  this.$emit('onSuccess', data);
136
150
  }
137
151
  });
package/src/UppyInput.vue CHANGED
@@ -3,10 +3,10 @@
3
3
  <UppyContextProvider :name="'uu' + name" :uppy="uppy">
4
4
  <slot :uppy="uppy">
5
5
  <FilesList class="uppy-file-lists"/>
6
- <Dropzone/>
6
+ <Dropzone class="uppy-drop-zone"/>
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
+ <div class="uppy-input-area--caption small text-body-secondary fst-italic" v-if="restrictionCaption">{{ restrictionCaption }}</div>
10
10
  </div>
11
11
  </template>
12
12
 
@@ -45,6 +45,7 @@ const inputEl = ref(null);
45
45
  const uppy = shallowRef(null);
46
46
  const isResetting = ref(false);
47
47
  const isUnmounting = ref(false);
48
+ const uploadingFiles = ref(0);
48
49
 
49
50
  // Inject form and group contexts
50
51
  const form = inject("form", {value: {}, errors: {}, getID: n => n});
@@ -76,11 +77,18 @@ uppy.value = new Uppy({
76
77
  },
77
78
  });
78
79
 
80
+ uppy.value.on('upload', () => {
81
+ uploadingFiles.value = uppy.value.getFiles().filter(f => !f.progress.uploadComplete).length;
82
+ emits('upload');
83
+ });
84
+
79
85
  uppy.value.on('before-upload', (files) => {
80
86
  emits('beforeUpload', files);
81
87
  });
82
88
 
83
89
  uppy.value.on('upload-success', (file, response) => {
90
+ uploadingFiles.value = Math.max(0, uploadingFiles.value - 1);
91
+
84
92
  const result = response.body ?? response;
85
93
  if (props.multiple) {
86
94
  const currentValues = Array.isArray(modelValue.value) ? modelValue.value : [];
@@ -119,7 +127,15 @@ uppy.value.on('file-removed', (file) => {
119
127
  });
120
128
 
121
129
  uppy.value.on('progress', (progress) => {
122
- form.value['uploading'] = (progress >= 100 || progress <= 0) ? null : progress;
130
+ if (progress <= 0) {
131
+ form.value['uploading'] = null;
132
+ } else if (progress >= 100) {
133
+ // هنوز منتظر جواب سرور - uploading رو null نکن
134
+ form.value['uploading'] = uploadingFiles.value > 0 ? 99 : null;
135
+ } else {
136
+ form.value['uploading'] = progress;
137
+ }
138
+
123
139
  emits('progress', progress)
124
140
  });
125
141
  uppy.value.on('upload-progress', (file, progress) => emits('upload-progress', file, progress));
@@ -128,13 +144,20 @@ uppy.value.on('cancel-all', () => emits('cancel-all'));
128
144
  uppy.value.on('retry-all', () => emits('retry-all'));
129
145
  uppy.value.on('upload-stalled', (error, files) => emits('upload-stalled', error, files));
130
146
  uppy.value.on('upload-retry', (file) => emits('upload-retry', file));
131
- uppy.value.on('complete', (result) => emits('complete', result));
147
+
148
+ uppy.value.on('complete', (result) => {
149
+ uploadingFiles.value = 0;
150
+ form.value['uploading'] = null;
151
+ emits('complete', result);
152
+ });
132
153
 
133
154
  uppy.value.on('error', (error) => {
134
155
  emits('error', error)
135
156
  });
136
157
 
137
158
  uppy.value.on('upload-error', (file, error, response) => {
159
+ uploadingFiles.value = Math.max(0, uploadingFiles.value - 1);
160
+
138
161
  const errorMessage = JSON.parse(response.response)?.message ?? error;
139
162
  handleError(errorMessage);
140
163
  emits('upload-error', file, error, response, errorMessage)
@@ -169,6 +192,13 @@ onMounted(() => {
169
192
  if (uppy.value?.opts?.restrictions) {
170
193
  restrictionCaption.value = buildRestrictionsCaption(uppy.value.opts.restrictions)
171
194
  }
195
+
196
+
197
+ if (inputEl && uppy.value?.opts?.locale?.strings?.dropzoneText) {
198
+ inputEl.value?.querySelectorAll('[data-uppy-element="dropzone"]>div>div>p')?.forEach(el => {
199
+ el.innerHTML = uppy.value?.opts?.locale?.strings?.dropzoneText;
200
+ });
201
+ }
172
202
  });
173
203
 
174
204
  onBeforeUnmount(() => {
@@ -207,6 +237,7 @@ function showError(message) {
207
237
  }
208
238
 
209
239
  const niceBytesUnits = ['bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
240
+
210
241
  function niceBytes(x) {
211
242
  let l = 0, n = parseInt(x, 10) || 0;
212
243
  while (n >= 1024 && ++l) {
@@ -236,7 +267,7 @@ function buildRestrictionsCaption(restrictions) {
236
267
  parts.push(`فقط فایل‌های ${types}`);
237
268
  }
238
269
 
239
- if (maxNumberOfFiles) {
270
+ if (maxNumberOfFiles && maxNumberOfFiles > 1) {
240
271
  parts.push(`امکان انتخاب حداکثر ${maxNumberOfFiles} فایل`);
241
272
  }
242
273