@edc-motor/admin-kit 0.2.0 → 0.3.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edc-motor/admin-kit",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
4
4
  "description": "EdC Motor — kit del panel de administración: layout, gestores CRUD, imágenes, PDF, páginas, configuración, usuarios y copias (paquete fuente: lo compila el consumidor con Vite)",
5
5
  "license": "GPL-3.0-only",
6
6
  "type": "module",
@@ -33,7 +33,7 @@
33
33
  "access": "public"
34
34
  },
35
35
  "dependencies": {
36
- "@edc-motor/ui": "^0.2.0",
36
+ "@edc-motor/ui": "^0.3.0",
37
37
  "axios": "^1.7.0",
38
38
  "vue-draggable-plus": "^0.6.1"
39
39
  },
@@ -85,15 +85,28 @@ function selectOptions(field: FieldSchema): SelectOption[] {
85
85
  }
86
86
 
87
87
  /** Sube la imagen al momento; en settings queda la URL pública. */
88
- async function upload(file: File): Promise<string> {
88
+ async function upload(file: File, replaces?: string | null): Promise<string> {
89
89
  const form = new FormData()
90
90
  form.append('image', file)
91
+ // El backend borra el fichero sustituido: sin huérfanos.
92
+ if (replaces) form.append('replaces', replaces)
91
93
  const { data } = await props.api.post('/admin/content/uploads', form)
92
94
  return data.url
93
95
  }
94
96
 
97
+ /** Borra la subida del disco (el botón "quitar"); en silencio si falla. */
98
+ async function removeUpload(url: string): Promise<void> {
99
+ await props.api.delete('/admin/content/uploads', { data: { url } }).catch(() => {})
100
+ }
101
+
95
102
  async function uploadImage(field: FieldSchema, file: File | null) {
96
- set(field.key, file ? await upload(file) : null)
103
+ const current = (props.modelValue[field.key] as string | null) ?? null
104
+ if (!file) {
105
+ if (current) removeUpload(current)
106
+ set(field.key, null)
107
+ return
108
+ }
109
+ set(field.key, await upload(file, current))
97
110
  }
98
111
 
99
112
  // --- Anidados (group / repeater) ---
@@ -291,6 +304,7 @@ function addLabel(): string {
291
304
  :label="label(field)"
292
305
  :required="field.required"
293
306
  :upload="upload"
307
+ :remove-file="removeUpload"
294
308
  @update:model-value="(v) => set(field.key, v)"
295
309
  />
296
310
 
@@ -300,7 +314,7 @@ function addLabel(): string {
300
314
  :model-value="null"
301
315
  :current-url="(modelValue[field.key] as string) ?? null"
302
316
  @update:model-value="(f: File | null) => uploadImage(field, f)"
303
- @remove="set(field.key, null)"
317
+ @remove="uploadImage(field, null)"
304
318
  />
305
319
  </div>
306
320
  </template>