@asteby/metacore-runtime-react 53.12.0 → 53.13.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @asteby/metacore-runtime-react
2
2
 
3
+ ## 53.13.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 68effb9: Galería: la imagen original del padre como «Principal» cuando la galería está vacía. Si la columna de imagen declara `display_config.main_from_parent: "<campo>"` (p. ej. `image` en el producto) y la galería no tiene ninguna foto, el panel muestra esa imagen como tarjeta «Principal» de solo lectura, con la leyenda «Imagen original del producto»: es la que la tienda sirve cuando no hay galería. Con una o más fotos la tienda sirve primero la galería, así que no hay tarjeta extra y la primera foto es la principal (la imagen original entra a la galería cuando el addon la siembra al crear la primera foto). Sin el hint no cambia nada.
8
+
3
9
  ## 53.12.0
4
10
 
5
11
  ### Minor Changes
@@ -15,6 +15,9 @@ export type RelationDerive = 'image_width' | 'image_height' | 'next_position';
15
15
  * ("Para todas las variantes").
16
16
  * - `gallery: true` (on the image column) → the relation renders as a
17
17
  * thumbnail gallery instead of a table.
18
+ * - `main_from_parent: <k>` (on the image column) → the parent's `<k>` image
19
+ * is the gallery's main photo; while no gallery row holds it, it shows as a
20
+ * read-only first tile.
18
21
  * A column with none of them behaves exactly as before.
19
22
  */
20
23
  export interface RelationColumnUi {
@@ -23,6 +26,8 @@ export interface RelationColumnUi {
23
26
  defaultFromParent?: string;
24
27
  emptyLabel?: string;
25
28
  gallery?: boolean;
29
+ /** Campo del padre cuya imagen es la principal de la galería (p. ej. `image`). */
30
+ mainFromParent?: string;
26
31
  }
27
32
  export declare function relationColumnUi(col: ColumnDefinition): RelationColumnUi;
28
33
  /** The gallery image column (media + `display_config.gallery: true`), if any. */
@@ -141,4 +146,12 @@ export declare function diffSelection(prev: ReadonlyArray<string>, next: Readonl
141
146
  * non-FK string-ish value. Falls back to the row id, then to '—'.
142
147
  */
143
148
  export declare function pickOptionLabel(row: TargetRowLike | null | undefined, displayKey: string | undefined, columns: ReadonlyArray<ColumnDefinition> | null | undefined): string;
149
+ /**
150
+ * The parent's own image (e.g. `Product.image`) when it is the one the store
151
+ * serves first: the image column declares `main_from_parent`, the parent has
152
+ * that image and the gallery has NO rows at all (variant photos included). With
153
+ * any row, the store serves the gallery first, so the first photo is the main
154
+ * one and showing the parent's image as «Principal» would be wrong.
155
+ */
156
+ export declare function galleryLeadImage(imageColumn: ColumnDefinition | undefined, parent: Record<string, unknown> | null | undefined, rows: Array<Record<string, any>>): string | undefined;
144
157
  //# sourceMappingURL=dynamic-relation-helpers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"dynamic-relation-helpers.d.ts","sourceRoot":"","sources":["../src/dynamic-relation-helpers.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAiB9E,MAAM,MAAM,mBAAmB,GAAG,aAAa,GAAG,cAAc,CAAA;AAuBhE,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAI5D;AAUD,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,gBAAgB,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,CAQrF;AAED,MAAM,MAAM,cAAc,GAAG,aAAa,GAAG,cAAc,GAAG,eAAe,CAAA;AAE7E;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,gBAAgB;IAC7B,IAAI,CAAC,EAAE,QAAQ,GAAG,UAAU,CAAA;IAC5B,MAAM,CAAC,EAAE,cAAc,CAAA;IACvB,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,OAAO,CAAC,EAAE,OAAO,CAAA;CACpB;AAID,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,gBAAgB,GAAG,gBAAgB,CAaxE;AAED,iFAAiF;AACjF,wBAAgB,qBA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KAAK,EAAE,MAAM,EAAE,CAAC;IAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;CAAE,CAYzC;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAC3B,GAAG,EAAE,aAAa,GAAG,IAAI,GAAG,SAAS,EACrC,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,OAAO,EAAE,aAAa,CAAC,gBAAgB,CAAC,GAAG,IAAI,GAAG,SAAS,GAC5D,MAAM,CAiBR;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC5B,WAAW,EAAE,gBAAgB,GAAG,SAAS,EACzC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,GAAG,SAAS,EAClD,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,GACjC,MAAM,GAAG,SAAS,CAOpB"}
@@ -75,6 +75,9 @@ export function relationColumnUi(col) {
75
75
  out.emptyLabel = empty;
76
76
  if (sc.gallery === true)
77
77
  out.gallery = true;
78
+ const mfp = sc.main_from_parent ?? sc.mainFromParent;
79
+ if (typeof mfp === 'string' && mfp.trim() !== '')
80
+ out.mainFromParent = mfp.trim();
78
81
  return out;
79
82
  }
80
83
  /** The gallery image column (media + `display_config.gallery: true`), if any. */
@@ -479,3 +482,20 @@ export function pickOptionLabel(row, displayKey, columns) {
479
482
  return String(row.id);
480
483
  return '—';
481
484
  }
485
+ /**
486
+ * The parent's own image (e.g. `Product.image`) when it is the one the store
487
+ * serves first: the image column declares `main_from_parent`, the parent has
488
+ * that image and the gallery has NO rows at all (variant photos included). With
489
+ * any row, the store serves the gallery first, so the first photo is the main
490
+ * one and showing the parent's image as «Principal» would be wrong.
491
+ */
492
+ export function galleryLeadImage(imageColumn, parent, rows) {
493
+ if (!imageColumn || !parent || rows.length > 0)
494
+ return undefined;
495
+ const field = relationColumnUi(imageColumn).mainFromParent;
496
+ if (!field)
497
+ return undefined;
498
+ const raw = parent[field];
499
+ const url = typeof raw === 'string' ? raw.trim() : '';
500
+ return url || undefined;
501
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"dynamic-relation.d.ts","sourceRoot":"","sources":["../src/dynamic-relation.tsx"],"names":[],"mappings":"AAgFA,YAAY,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAA;AACrE,OAAO,EACH,kBAAkB,EAClB,uBAAuB,EACvB,kBAAkB,EAClB,yBAAyB,EACzB,wBAAwB,EACxB,aAAa,EACb,wBAAwB,EACxB,kBAAkB,EAClB,WAAW,EACX,eAAe,EACf,cAAc,GACjB,MAAM,4BAA4B,CAAA;AAEnC,MAAM,WAAW,sBAAsB;IACnC,KAAK,EAAE,MAAM,CAAA;IACb,UAAU,EAAE,MAAM,CAAA;IAClB,oGAAoG;IACpG,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,0GAA0G;IAC1G,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,MAAM,CAAA;IACnB,kBAAkB,EAAE,MAAM,CAAA;IAC1B,wBAAwB,EAAE,MAAM,CAAA;IAChC,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;IACjB,iBAAiB,EAAE,MAAM,CAAA;IACzB,uBAAuB,EAAE,MAAM,CAAA;IAC/B,WAAW,EAAE,MAAM,CAAA;IACnB,oDAAoD;IACpD,iBAAiB,EAAE,MAAM,CAAA;IACzB,sDAAsD;IACtD,UAAU,EAAE,MAAM,CAAA;IAClB,uEAAuE;IACvE,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,qDAAqD;IACrD,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,0CAA0C;IAC1C,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,kCAAkC;IAClC,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,mIAAmI;IACnI,6BAA6B,CAAC,EAAE,MAAM,CAA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AG,IAAI,CAAA;CAChD;AAED,MAAM,WAAW,8BAA+B,SAAQ,WAAW;IAC/D,IAAI,EAAE,cAAc,CAAA;IACpB,wEAAwE;IACxE,OAAO,EAAE,MAAM,CAAA;IACf,sEAAsE;IACtE,UAAU,EAAE,MAAM,CAAA;IAClB,6BAA6B;IAC7B,UAAU,EAAE,MAAM,CAAA;IAClB,oEAAoE;IACpE,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,mEAAmE;IACnE,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,uEAAuE;IACvE,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;CACtB;AAED,MAAM,MAAM,oBAAoB,GAC1B,6BAA6B,GAC7B,8BAA8B,CAAA;AAEpC,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,+BAK1D"}
@@ -24,7 +24,7 @@ import { dedupeById, useInfiniteScrollSentinel } from './use-infinite-scroll';
24
24
  import { toast } from 'sonner';
25
25
  import { RelationGallery } from './relation-gallery';
26
26
  import { extractUploadedValue, readImageSize } from './upload-field';
27
- import { buildCreatePayload, buildPivotAttachPayload, buildPivotRowIndex, buildRelationFilterParams, deriveRelationFormFields, diffSelection, extractSelectedTargetIds, pickOptionLabel, relationColumnUi, relationDerivedValues, contiguousPositionUpdates, relationGalleryColumn, relationInitialValues, relationPositionKey, relationPositionSortable, relationRowKey, sortRelationRows, } from './dynamic-relation-helpers';
27
+ import { buildCreatePayload, buildPivotAttachPayload, buildPivotRowIndex, buildRelationFilterParams, deriveRelationFormFields, diffSelection, extractSelectedTargetIds, pickOptionLabel, relationColumnUi, relationDerivedValues, galleryLeadImage, contiguousPositionUpdates, relationGalleryColumn, relationInitialValues, relationPositionKey, relationPositionSortable, relationRowKey, sortRelationRows, } from './dynamic-relation-helpers';
28
28
  export { buildCreatePayload, buildPivotAttachPayload, buildPivotRowIndex, buildRelationFilterParams, deriveRelationFormFields, diffSelection, extractSelectedTargetIds, formatRelationCell, objectLabel, pickOptionLabel, relationRowKey, } from './dynamic-relation-helpers';
29
29
  const DEFAULT_STRINGS = {
30
30
  title: '',
@@ -241,6 +241,7 @@ function OneToManyRelation({ kind, model, foreignKey, parentId, filters, endpoin
241
241
  const positionKey = useMemo(() => relationPositionKey(metadata), [metadata]);
242
242
  const orderedRows = useMemo(() => sortRelationRows(rows, positionKey), [rows, positionKey]);
243
243
  const galleryColumn = useMemo(() => relationGalleryColumn(metadata), [metadata]);
244
+ const galleryLead = useMemo(() => galleryLeadImage(galleryColumn, parentRecord, rows), [galleryColumn, parentRecord, rows]);
244
245
  const captionKey = useMemo(() => metadata?.columns?.find((c) => relationColumnUi(c).defaultFromParent)?.key, [metadata]);
245
246
  const createInitialValues = useMemo(() => relationInitialValues(metadata, parentRecord), [metadata, parentRecord]);
246
247
  // Size of the image uploaded in the open form (fills derived width/height).
@@ -559,7 +560,7 @@ function OneToManyRelation({ kind, model, foreignKey, parentId, filters, endpoin
559
560
  const sc = (galleryColumn.styleConfig ?? {});
560
561
  const n = Number(sc.max_size ?? sc.maxSize);
561
562
  return Number.isFinite(n) && n > 0 ? n : undefined;
562
- })(), canCreate: canCreate, canEdit: canEdit, canReorder: canEdit && !!positionKey, canDelete: canDelete, hiddenKeys: pendingDelete, onUpload: galleryUpload, onUploadsSettled: () => { void normalizePositions().then(() => refreshSilently()); onChange?.(); }, onReorder: galleryReorder, onEdit: canEdit ? (row) => { setEditingRow(row); uploadedImageRef.current = null; setFormOpen(true); } : undefined, onDelete: canDelete ? (row) => setRowToDelete(row) : undefined })) : rows.length === 0 ? (_jsx("div", { className: "text-center text-sm text-muted-foreground py-8 border rounded-md bg-muted/30", children: fetchErrorStatus === 403
563
+ })(), canCreate: canCreate, canEdit: canEdit, canReorder: canEdit && !!positionKey, canDelete: canDelete, hiddenKeys: pendingDelete, lead: galleryLead ? { src: getImageUrl(galleryLead) } : undefined, onUpload: galleryUpload, onUploadsSettled: () => { void normalizePositions().then(() => refreshSilently()); onChange?.(); }, onReorder: galleryReorder, onEdit: canEdit ? (row) => { setEditingRow(row); uploadedImageRef.current = null; setFormOpen(true); } : undefined, onDelete: canDelete ? (row) => setRowToDelete(row) : undefined })) : rows.length === 0 ? (_jsx("div", { className: "text-center text-sm text-muted-foreground py-8 border rounded-md bg-muted/30", children: fetchErrorStatus === 403
563
564
  ? (labels.forbiddenState ?? 'Sin permiso para ver estos registros.')
564
565
  : fetchErrorStatus !== null
565
566
  ? (labels.errorState ?? 'No se pudieron cargar los registros relacionados.')
@@ -26,6 +26,14 @@ export interface RelationGalleryProps {
26
26
  onDelete?: (row: Record<string, any>) => void;
27
27
  /** Keys of rows pending deletion (hidden while «Deshacer» is offered). */
28
28
  hiddenKeys?: Set<string>;
29
+ /**
30
+ * The parent's own image, shown as a read-only first tile marked «Principal»
31
+ * while no gallery row holds it. Gallery rows are then additional photos:
32
+ * none of them is the main one, so «Hacer principal» is not offered.
33
+ */
34
+ lead?: {
35
+ src: string;
36
+ };
29
37
  }
30
- export declare function RelationGallery({ rows, rowKey, imageKey, captionKey, getImageUrl, accept, maxSize, canCreate, canEdit, canReorder, canDelete, onUpload, onUploadsSettled, onReorder, onEdit, onDelete, hiddenKeys, }: RelationGalleryProps): import("react").JSX.Element;
38
+ export declare function RelationGallery({ rows, rowKey, imageKey, captionKey, getImageUrl, accept, maxSize, canCreate, canEdit, canReorder, canDelete, onUpload, onUploadsSettled, onReorder, onEdit, onDelete, hiddenKeys, lead, }: RelationGalleryProps): import("react").JSX.Element;
31
39
  //# sourceMappingURL=relation-gallery.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"relation-gallery.d.ts","sourceRoot":"","sources":["../src/relation-gallery.tsx"],"names":[],"mappings":"AAoCA,MAAM,WAAW,qBAAqB;IAClC,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;CAC3B;AAED,MAAM,WAAW,oBAAoB;IACjC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,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AO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;IACnE,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,IAAI,CAAA;IAC3C,yEAAyE;IACzE,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,IAAI,CAAA;IAC7C,0EAA0E;IAC1E,UAAU,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IACxB;;;;OAIG;IACH,IAAI,CAAC,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,CAAA;CACzB;AAgBD,wBAAgB,eAAe,CAAC,EAC5B,IAAI,EACJ,MAAM,EACN,QAAQ,EACR,UAAU,EACV,WAAW,EACX,MAAkB,EAClB,OAAO,EACP,SAAgB,EAChB,OAAc,EACd,UAAU,EACV,SAAgB,EAChB,QAAQ,EACR,gBAAgB,EAChB,SAAS,EACT,MAAM,EACN,QAAQ,EACR,UAAU,EACV,IAAI,GACP,EAAE,oBAAoB,+BA+RtB"}
@@ -21,7 +21,7 @@ import { Button } from '@asteby/metacore-ui/primitives';
21
21
  import { ArrowLeft, ArrowRight, ImagePlus, Loader2, Pencil, RotateCcw, Star, Trash2, X } from 'lucide-react';
22
22
  import { validateUploadFile } from './upload-field';
23
23
  let uploadSeq = 0;
24
- export function RelationGallery({ rows, rowKey, imageKey, captionKey, getImageUrl, accept = 'image/*', maxSize, canCreate = true, canEdit = true, canReorder, canDelete = true, onUpload, onUploadsSettled, onReorder, onEdit, onDelete, hiddenKeys, }) {
24
+ export function RelationGallery({ rows, rowKey, imageKey, captionKey, getImageUrl, accept = 'image/*', maxSize, canCreate = true, canEdit = true, canReorder, canDelete = true, onUpload, onUploadsSettled, onReorder, onEdit, onDelete, hiddenKeys, lead, }) {
25
25
  const { t } = useTranslation();
26
26
  const inputRef = useRef(null);
27
27
  const [dragOver, setDragOver] = useState(false);
@@ -144,11 +144,11 @@ export function RelationGallery({ rows, rowKey, imageKey, captionKey, getImageUr
144
144
  : t('dynamic.gallery.hint', { defaultValue: 'Arrastra aquí o elige varias a la vez · JPG, PNG o WebP' }) }), _jsx("input", { ref: inputRef, type: "file", accept: accept, multiple: true, className: "hidden", "data-testid": "gallery-input", onChange: (e) => {
145
145
  void addFiles(e.target.files);
146
146
  e.target.value = '';
147
- } })] })), pending.length > 0 && (_jsx("ul", { className: "grid gap-2", "aria-live": "polite", "data-testid": "gallery-uploads", children: pending.map((u) => (_jsxs("li", { className: "flex items-center gap-3 rounded-md border bg-card p-2", children: [u.preview ? (_jsx("img", { src: u.preview, alt: "", className: "h-12 w-12 shrink-0 rounded object-cover" })) : (_jsx("div", { className: "h-12 w-12 shrink-0 rounded bg-muted" })), _jsxs("div", { className: "min-w-0 flex-1", children: [_jsx("div", { className: "truncate text-sm", children: u.file.name }), u.status === 'error' ? (_jsx("div", { className: "text-xs text-destructive", role: "alert", children: u.error })) : (_jsx("div", { className: "mt-1 h-1.5 w-full overflow-hidden rounded bg-muted", role: "progressbar", "aria-label": u.file.name, "aria-valuemin": 0, "aria-valuemax": 100, "aria-valuenow": Math.round(u.progress * 100), children: _jsx("div", { className: "h-full bg-primary transition-all", style: { width: `${Math.round(u.progress * 100)}%` } }) }))] }), u.status === 'uploading' && _jsx(Loader2, { className: "h-4 w-4 animate-spin text-muted-foreground", "aria-hidden": true }), u.status === 'error' && !validateUploadFile(u.file, { accept, maxSize }) && (_jsx(Button, { type: "button", size: "sm", variant: "ghost", disabled: busy, onClick: () => void retry(u), "aria-label": t('dynamic.gallery.retry', { defaultValue: 'Reintentar' }), children: _jsx(RotateCcw, { className: "h-4 w-4" }) })), u.status === 'error' && (_jsx(Button, { type: "button", size: "sm", variant: "ghost", onClick: () => dismiss(u.id), "aria-label": t('dynamic.gallery.dismiss', { defaultValue: 'Quitar' }), children: _jsx(X, { className: "h-4 w-4" }) }))] }, u.id))) })), keyed.length === 0 && !canCreate && pending.length === 0 && (_jsx("div", { className: "rounded-md border bg-muted/30 py-8 text-center text-sm text-muted-foreground", children: t('dynamic.gallery.empty', { defaultValue: 'Sin fotos.' }) })), keyed.length > 0 && (_jsx(DndContext, { sensors: sensors, collisionDetection: closestCenter, onDragEnd: handleDragEnd, children: _jsx(SortableContext, { items: ids, strategy: rectSortingStrategy, children: _jsx("ul", { className: "grid grid-cols-2 gap-3 sm:grid-cols-3 md:grid-cols-4", "data-testid": "gallery-grid", children: keyed.map(({ row, key }, index) => (_jsx(GalleryTile, { id: key, src: row[imageKey] ? getImageUrl(String(row[imageKey])) : '', caption: captionKey ? String(row[captionKey] ?? '') : '', index: index, total: keyed.length, isMain: index === 0, mainLabel: mainLabel, canEdit: canEdit, canReorder: reorderable, canDelete: canDelete, onMove: (to) => move(index, to), onEdit: onEdit ? () => onEdit(row) : undefined, onDelete: onDelete ? () => onDelete(row) : undefined }, key))) }) }) }))] }));
147
+ } })] })), pending.length > 0 && (_jsx("ul", { className: "grid gap-2", "aria-live": "polite", "data-testid": "gallery-uploads", children: pending.map((u) => (_jsxs("li", { className: "flex items-center gap-3 rounded-md border bg-card p-2", children: [u.preview ? (_jsx("img", { src: u.preview, alt: "", className: "h-12 w-12 shrink-0 rounded object-cover" })) : (_jsx("div", { className: "h-12 w-12 shrink-0 rounded bg-muted" })), _jsxs("div", { className: "min-w-0 flex-1", children: [_jsx("div", { className: "truncate text-sm", children: u.file.name }), u.status === 'error' ? (_jsx("div", { className: "text-xs text-destructive", role: "alert", children: u.error })) : (_jsx("div", { className: "mt-1 h-1.5 w-full overflow-hidden rounded bg-muted", role: "progressbar", "aria-label": u.file.name, "aria-valuemin": 0, "aria-valuemax": 100, "aria-valuenow": Math.round(u.progress * 100), children: _jsx("div", { className: "h-full bg-primary transition-all", style: { width: `${Math.round(u.progress * 100)}%` } }) }))] }), u.status === 'uploading' && _jsx(Loader2, { className: "h-4 w-4 animate-spin text-muted-foreground", "aria-hidden": true }), u.status === 'error' && !validateUploadFile(u.file, { accept, maxSize }) && (_jsx(Button, { type: "button", size: "sm", variant: "ghost", disabled: busy, onClick: () => void retry(u), "aria-label": t('dynamic.gallery.retry', { defaultValue: 'Reintentar' }), children: _jsx(RotateCcw, { className: "h-4 w-4" }) })), u.status === 'error' && (_jsx(Button, { type: "button", size: "sm", variant: "ghost", onClick: () => dismiss(u.id), "aria-label": t('dynamic.gallery.dismiss', { defaultValue: 'Quitar' }), children: _jsx(X, { className: "h-4 w-4" }) }))] }, u.id))) })), keyed.length === 0 && !canCreate && pending.length === 0 && (_jsx("div", { className: "rounded-md border bg-muted/30 py-8 text-center text-sm text-muted-foreground", children: t('dynamic.gallery.empty', { defaultValue: 'Sin fotos.' }) })), (keyed.length > 0 || lead) && (_jsx(DndContext, { sensors: sensors, collisionDetection: closestCenter, onDragEnd: handleDragEnd, children: _jsx(SortableContext, { items: ids, strategy: rectSortingStrategy, children: _jsxs("ul", { className: "grid grid-cols-2 gap-3 sm:grid-cols-3 md:grid-cols-4", "data-testid": "gallery-grid", children: [lead && (_jsxs("li", { className: "relative min-w-0 overflow-hidden rounded-lg border bg-card ring-2 ring-primary", "data-testid": "gallery-lead", "data-main": "true", children: [_jsx("div", { className: "aspect-square w-full bg-muted", "aria-label": `${t('dynamic.gallery.original', { defaultValue: 'Imagen original del producto' })} · ${mainLabel}`, children: _jsx("img", { src: lead.src, alt: "", className: "h-full w-full min-h-24 object-cover", draggable: false }) }), _jsxs("span", { className: "absolute start-2 top-2 inline-flex items-center gap-1 rounded-full bg-primary px-2 py-0.5 text-xs font-medium text-primary-foreground", children: [_jsx(Star, { className: "h-3 w-3", "aria-hidden": true }), mainLabel] }), _jsx("div", { className: "border-t bg-card px-2 py-1 text-xs text-muted-foreground", children: t('dynamic.gallery.original', { defaultValue: 'Imagen original del producto' }) })] })), keyed.map(({ row, key }, index) => (_jsx(GalleryTile, { id: key, src: row[imageKey] ? getImageUrl(String(row[imageKey])) : '', caption: captionKey ? String(row[captionKey] ?? '') : '', index: index, total: keyed.length, isMain: !lead && index === 0, canMakeMain: !lead, mainLabel: mainLabel, canEdit: canEdit, canReorder: reorderable, canDelete: canDelete, onMove: (to) => move(index, to), onEdit: onEdit ? () => onEdit(row) : undefined, onDelete: onDelete ? () => onDelete(row) : undefined }, key)))] }) }) }))] }));
148
148
  }
149
- function GalleryTile({ id, src, caption, index, total, isMain, mainLabel, canEdit, canReorder, canDelete, onMove, onEdit, onDelete, }) {
149
+ function GalleryTile({ id, src, caption, index, total, isMain, canMakeMain, mainLabel, canEdit, canReorder, canDelete, onMove, onEdit, onDelete, }) {
150
150
  const { t } = useTranslation();
151
151
  const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({ id, disabled: !canReorder });
152
152
  const label = caption || t('dynamic.gallery.photo', { n: index + 1, defaultValue: `Foto ${index + 1}` });
153
- return (_jsxs("li", { ref: setNodeRef, style: { transform: CSS.Transform.toString(transform), transition }, className: cn('group relative min-w-0 overflow-hidden rounded-lg border bg-card', isMain && 'ring-2 ring-primary', isDragging && 'z-10 opacity-80 shadow-lg'), "data-testid": "gallery-tile", "data-main": isMain ? 'true' : undefined, children: [_jsx("div", { className: "aspect-square w-full touch-none bg-muted outline-none focus-visible:ring-2 focus-visible:ring-ring", ...attributes, ...listeners, "aria-roledescription": t('dynamic.gallery.sortable', { defaultValue: 'foto reordenable' }), "aria-label": `${label}${isMain ? ` · ${mainLabel}` : ''}`, children: src ? (_jsx("img", { src: src, alt: caption, className: "h-full w-full min-h-24 object-cover", draggable: false })) : null }), isMain && (_jsxs("span", { className: "absolute start-2 top-2 inline-flex items-center gap-1 rounded-full bg-primary px-2 py-0.5 text-xs font-medium text-primary-foreground", children: [_jsx(Star, { className: "h-3 w-3", "aria-hidden": true }), mainLabel] })), _jsxs("div", { className: "flex flex-wrap items-center justify-between gap-x-1 border-t bg-card px-1 py-0.5", "data-testid": "gallery-tile-actions", children: [_jsx("div", { className: "flex flex-wrap items-center", children: canReorder && (_jsxs(_Fragment, { children: [_jsx(Button, { type: "button", size: "sm", variant: "ghost", className: "h-8 w-8 p-0", disabled: index === 0, onClick: () => onMove(index - 1), "aria-label": t('dynamic.gallery.move_before', { defaultValue: 'Mover antes' }), children: _jsx(ArrowLeft, { className: "h-4 w-4 rtl:rotate-180" }) }), _jsx(Button, { type: "button", size: "sm", variant: "ghost", className: "h-8 w-8 p-0", disabled: index === total - 1, onClick: () => onMove(index + 1), "aria-label": t('dynamic.gallery.move_after', { defaultValue: 'Mover después' }), children: _jsx(ArrowRight, { className: "h-4 w-4 rtl:rotate-180" }) }), !isMain && (_jsx(Button, { type: "button", size: "sm", variant: "ghost", className: "h-8 w-8 p-0", onClick: () => onMove(0), "aria-label": t('dynamic.gallery.make_main', { defaultValue: 'Hacer principal' }), title: t('dynamic.gallery.make_main', { defaultValue: 'Hacer principal' }), children: _jsx(Star, { className: "h-4 w-4" }) }))] })) }), _jsxs("div", { className: "flex flex-wrap items-center", children: [canEdit && onEdit && (_jsx(Button, { type: "button", size: "sm", variant: "ghost", className: "h-8 w-8 p-0", onClick: onEdit, "aria-label": t('dynamic.gallery.edit', { defaultValue: 'Editar foto' }), children: _jsx(Pencil, { className: "h-4 w-4" }) })), canDelete && onDelete && (_jsx(Button, { type: "button", size: "sm", variant: "ghost", className: "h-8 w-8 p-0 text-destructive", onClick: onDelete, "aria-label": t('dynamic.gallery.delete', { defaultValue: 'Eliminar foto' }), children: _jsx(Trash2, { className: "h-4 w-4" }) }))] })] })] }));
153
+ return (_jsxs("li", { ref: setNodeRef, style: { transform: CSS.Transform.toString(transform), transition }, className: cn('group relative min-w-0 overflow-hidden rounded-lg border bg-card', isMain && 'ring-2 ring-primary', isDragging && 'z-10 opacity-80 shadow-lg'), "data-testid": "gallery-tile", "data-main": isMain ? 'true' : undefined, children: [_jsx("div", { className: "aspect-square w-full touch-none bg-muted outline-none focus-visible:ring-2 focus-visible:ring-ring", ...attributes, ...listeners, "aria-roledescription": t('dynamic.gallery.sortable', { defaultValue: 'foto reordenable' }), "aria-label": `${label}${isMain ? ` · ${mainLabel}` : ''}`, children: src ? (_jsx("img", { src: src, alt: caption, className: "h-full w-full min-h-24 object-cover", draggable: false })) : null }), isMain && (_jsxs("span", { className: "absolute start-2 top-2 inline-flex items-center gap-1 rounded-full bg-primary px-2 py-0.5 text-xs font-medium text-primary-foreground", children: [_jsx(Star, { className: "h-3 w-3", "aria-hidden": true }), mainLabel] })), _jsxs("div", { className: "flex flex-wrap items-center justify-between gap-x-1 border-t bg-card px-1 py-0.5", "data-testid": "gallery-tile-actions", children: [_jsx("div", { className: "flex flex-wrap items-center", children: canReorder && (_jsxs(_Fragment, { children: [_jsx(Button, { type: "button", size: "sm", variant: "ghost", className: "h-8 w-8 p-0", disabled: index === 0, onClick: () => onMove(index - 1), "aria-label": t('dynamic.gallery.move_before', { defaultValue: 'Mover antes' }), children: _jsx(ArrowLeft, { className: "h-4 w-4 rtl:rotate-180" }) }), _jsx(Button, { type: "button", size: "sm", variant: "ghost", className: "h-8 w-8 p-0", disabled: index === total - 1, onClick: () => onMove(index + 1), "aria-label": t('dynamic.gallery.move_after', { defaultValue: 'Mover después' }), children: _jsx(ArrowRight, { className: "h-4 w-4 rtl:rotate-180" }) }), !isMain && canMakeMain && (_jsx(Button, { type: "button", size: "sm", variant: "ghost", className: "h-8 w-8 p-0", onClick: () => onMove(0), "aria-label": t('dynamic.gallery.make_main', { defaultValue: 'Hacer principal' }), title: t('dynamic.gallery.make_main', { defaultValue: 'Hacer principal' }), children: _jsx(Star, { className: "h-4 w-4" }) }))] })) }), _jsxs("div", { className: "flex flex-wrap items-center", children: [canEdit && onEdit && (_jsx(Button, { type: "button", size: "sm", variant: "ghost", className: "h-8 w-8 p-0", onClick: onEdit, "aria-label": t('dynamic.gallery.edit', { defaultValue: 'Editar foto' }), children: _jsx(Pencil, { className: "h-4 w-4" }) })), canDelete && onDelete && (_jsx(Button, { type: "button", size: "sm", variant: "ghost", className: "h-8 w-8 p-0 text-destructive", onClick: onDelete, "aria-label": t('dynamic.gallery.delete', { defaultValue: 'Eliminar foto' }), children: _jsx(Trash2, { className: "h-4 w-4" }) }))] })] })] }));
154
154
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@asteby/metacore-runtime-react",
3
- "version": "53.12.0",
3
+ "version": "53.13.0",
4
4
  "description": "React runtime for metacore hosts — renders addon contributions dynamically",
5
5
  "repository": {
6
6
  "type": "git",
@@ -23,13 +23,13 @@ beforeEach(() => {
23
23
 
24
24
  const col = (c: Record<string, unknown>) => ({ label: c.key, type: 'text', sortable: false, filterable: false, ...c })
25
25
 
26
- function meta(gallery: boolean) {
26
+ function meta(gallery: boolean, mainFromParent = false) {
27
27
  return {
28
28
  name: 'product_images',
29
29
  columns: [
30
30
  col({ key: 'id', hidden: true }),
31
31
  col({ key: 'product_id', ref: 'products' }),
32
- col({ key: 'url', label: 'Imagen', cellStyle: 'image_stack', ...(gallery ? { styleConfig: { gallery: true, max_size: 1024 } } : {}) }),
32
+ col({ key: 'url', label: 'Imagen', cellStyle: 'image_stack', ...(gallery ? { styleConfig: { gallery: true, max_size: 1024, ...(mainFromParent ? { main_from_parent: 'image' } : {}) } } : {}) }),
33
33
  col({ key: 'alt', label: 'Texto alternativo', ...(gallery ? { styleConfig: { default_from_parent: 'name' } } : {}) }),
34
34
  col({ key: 'width', type: 'number', ...(gallery ? { styleConfig: { derive: 'image_width' } } : {}) }),
35
35
  col({ key: 'height', type: 'number', ...(gallery ? { styleConfig: { derive: 'image_height' } } : {}) }),
@@ -47,11 +47,11 @@ const BASE_ROWS = [
47
47
  { id: 'img_a', product_id: 'p1', url: '/storage/a.png', alt: 'Frente', position: 0 },
48
48
  ]
49
49
 
50
- function mockApi(gallery: boolean) {
50
+ function mockApi(gallery: boolean, mainFromParent = false) {
51
51
  let n = 0
52
52
  const api = {
53
53
  get: vi.fn((url: string) =>
54
- Promise.resolve({ data: url.startsWith('/metadata/table/') ? { success: true, data: meta(gallery) } : { success: true, data: ROWS } }),
54
+ Promise.resolve({ data: url.startsWith('/metadata/table/') ? { success: true, data: meta(gallery, mainFromParent) } : { success: true, data: ROWS } }),
55
55
  ),
56
56
  post: vi.fn((url: string, _body?: any, cfg?: any) => {
57
57
  if (url === '/upload') {
@@ -66,7 +66,7 @@ function mockApi(gallery: boolean) {
66
66
  return api as unknown as ApiClient & typeof api
67
67
  }
68
68
 
69
- function renderPanel(api: ApiClient, model = 'product_images') {
69
+ function renderPanel(api: ApiClient, model = 'product_images', parentRecord: Record<string, unknown> = { id: 'p1', name: 'BALATA DISCO' }) {
70
70
  return render(
71
71
  <ApiProvider client={api}>
72
72
  <DynamicRelation
@@ -74,7 +74,7 @@ function renderPanel(api: ApiClient, model = 'product_images') {
74
74
  model={model}
75
75
  foreignKey="product_id"
76
76
  parentId="p1"
77
- parentRecord={{ id: 'p1', name: 'BALATA DISCO' }}
77
+ parentRecord={parentRecord}
78
78
  />
79
79
  </ApiProvider>,
80
80
  )
@@ -94,6 +94,31 @@ describe('DynamicRelation — galería', () => {
94
94
  expect(screen.queryByRole('table')).toBeNull()
95
95
  })
96
96
 
97
+ it('galería vacía: la imagen original del producto se muestra como «Principal» de solo lectura', async () => {
98
+ ROWS = []
99
+ renderPanel(mockApi(true, true), 'product_images_lead', { id: 'p1', name: 'BALATA', image: '/storage/original.jpg' })
100
+ const lead = await screen.findByTestId('gallery-lead')
101
+ expect(lead.getAttribute('data-main')).toBe('true')
102
+ expect(lead.querySelector('img')?.getAttribute('src')).toContain('original.jpg')
103
+ expect(within(lead).getByText('Principal')).toBeTruthy()
104
+ expect(within(lead).queryByRole('button')).toBeNull()
105
+ })
106
+
107
+ it('con filas en la galería no hay tarjeta extra: la primera de la galería es la principal (como en la tienda)', async () => {
108
+ renderPanel(mockApi(true, true), 'product_images_lead2', { id: 'p1', name: 'BALATA', image: '/storage/original-que-no-esta.jpg' })
109
+ await waitFor(() => expect(screen.getAllByTestId('gallery-tile')).toHaveLength(2))
110
+ expect(screen.queryByTestId('gallery-lead')).toBeNull()
111
+ expect(screen.getAllByTestId('gallery-tile')[0].getAttribute('data-main')).toBe('true')
112
+ expect(screen.getByLabelText('Hacer principal')).toBeTruthy()
113
+ })
114
+
115
+ it('sin el hint main_from_parent no hay tarjeta de imagen original', async () => {
116
+ ROWS = []
117
+ renderPanel(mockApi(true), 'product_images_lead3', { id: 'p1', name: 'BALATA', image: '/storage/original.jpg' })
118
+ await screen.findByTestId('gallery-dropzone')
119
+ expect(screen.queryByTestId('gallery-lead')).toBeNull()
120
+ })
121
+
97
122
  it('sube varias fotos: una fila por foto con posición siguiente, tamaño y alt sugerido; rechaza la pesada', async () => {
98
123
  const api = mockApi(true)
99
124
  renderPanel(api)
@@ -79,6 +79,9 @@ export type RelationDerive = 'image_width' | 'image_height' | 'next_position'
79
79
  * ("Para todas las variantes").
80
80
  * - `gallery: true` (on the image column) → the relation renders as a
81
81
  * thumbnail gallery instead of a table.
82
+ * - `main_from_parent: <k>` (on the image column) → the parent's `<k>` image
83
+ * is the gallery's main photo; while no gallery row holds it, it shows as a
84
+ * read-only first tile.
82
85
  * A column with none of them behaves exactly as before.
83
86
  */
84
87
  export interface RelationColumnUi {
@@ -87,6 +90,8 @@ export interface RelationColumnUi {
87
90
  defaultFromParent?: string
88
91
  emptyLabel?: string
89
92
  gallery?: boolean
93
+ /** Campo del padre cuya imagen es la principal de la galería (p. ej. `image`). */
94
+ mainFromParent?: string
90
95
  }
91
96
 
92
97
  const DERIVES = new Set<RelationDerive>(['image_width', 'image_height', 'next_position'])
@@ -103,6 +108,8 @@ export function relationColumnUi(col: ColumnDefinition): RelationColumnUi {
103
108
  const empty = sc.empty_label ?? sc.emptyLabel
104
109
  if (typeof empty === 'string' && empty.trim() !== '') out.emptyLabel = empty
105
110
  if (sc.gallery === true) out.gallery = true
111
+ const mfp = sc.main_from_parent ?? sc.mainFromParent
112
+ if (typeof mfp === 'string' && mfp.trim() !== '') out.mainFromParent = mfp.trim()
106
113
  return out
107
114
  }
108
115
 
@@ -552,3 +559,23 @@ export function pickOptionLabel(
552
559
  if (row.id !== undefined && row.id !== null && row.id !== '') return String(row.id)
553
560
  return '—'
554
561
  }
562
+
563
+ /**
564
+ * The parent's own image (e.g. `Product.image`) when it is the one the store
565
+ * serves first: the image column declares `main_from_parent`, the parent has
566
+ * that image and the gallery has NO rows at all (variant photos included). With
567
+ * any row, the store serves the gallery first, so the first photo is the main
568
+ * one and showing the parent's image as «Principal» would be wrong.
569
+ */
570
+ export function galleryLeadImage(
571
+ imageColumn: ColumnDefinition | undefined,
572
+ parent: Record<string, unknown> | null | undefined,
573
+ rows: Array<Record<string, any>>,
574
+ ): string | undefined {
575
+ if (!imageColumn || !parent || rows.length > 0) return undefined
576
+ const field = relationColumnUi(imageColumn).mainFromParent
577
+ if (!field) return undefined
578
+ const raw = parent[field]
579
+ const url = typeof raw === 'string' ? raw.trim() : ''
580
+ return url || undefined
581
+ }
@@ -67,6 +67,7 @@ import {
67
67
  pickOptionLabel,
68
68
  relationColumnUi,
69
69
  relationDerivedValues,
70
+ galleryLeadImage,
70
71
  contiguousPositionUpdates,
71
72
  relationGalleryColumn,
72
73
  relationInitialValues,
@@ -456,6 +457,10 @@ function OneToManyRelation({
456
457
  const positionKey = useMemo(() => relationPositionKey(metadata), [metadata])
457
458
  const orderedRows = useMemo(() => sortRelationRows(rows, positionKey), [rows, positionKey])
458
459
  const galleryColumn = useMemo(() => relationGalleryColumn(metadata), [metadata])
460
+ const galleryLead = useMemo(
461
+ () => galleryLeadImage(galleryColumn, parentRecord, rows),
462
+ [galleryColumn, parentRecord, rows],
463
+ )
459
464
  const captionKey = useMemo(
460
465
  () => metadata?.columns?.find((c) => relationColumnUi(c).defaultFromParent)?.key,
461
466
  [metadata],
@@ -859,6 +864,7 @@ function OneToManyRelation({
859
864
  canReorder={canEdit && !!positionKey}
860
865
  canDelete={canDelete}
861
866
  hiddenKeys={pendingDelete}
867
+ lead={galleryLead ? { src: getImageUrl(galleryLead) } : undefined}
862
868
  onUpload={galleryUpload}
863
869
  onUploadsSettled={() => { void normalizePositions().then(() => refreshSilently()); onChange?.() }}
864
870
  onReorder={galleryReorder}
@@ -63,6 +63,12 @@ export interface RelationGalleryProps {
63
63
  onDelete?: (row: Record<string, any>) => void
64
64
  /** Keys of rows pending deletion (hidden while «Deshacer» is offered). */
65
65
  hiddenKeys?: Set<string>
66
+ /**
67
+ * The parent's own image, shown as a read-only first tile marked «Principal»
68
+ * while no gallery row holds it. Gallery rows are then additional photos:
69
+ * none of them is the main one, so «Hacer principal» is not offered.
70
+ */
71
+ lead?: { src: string }
66
72
  }
67
73
 
68
74
  interface UploadItem {
@@ -97,6 +103,7 @@ export function RelationGallery({
97
103
  onEdit,
98
104
  onDelete,
99
105
  hiddenKeys,
106
+ lead,
100
107
  }: RelationGalleryProps) {
101
108
  const { t } = useTranslation()
102
109
  const inputRef = useRef<HTMLInputElement>(null)
@@ -337,10 +344,28 @@ export function RelationGallery({
337
344
  </div>
338
345
  )}
339
346
 
340
- {keyed.length > 0 && (
347
+ {(keyed.length > 0 || lead) && (
341
348
  <DndContext sensors={sensors} collisionDetection={closestCenter} onDragEnd={handleDragEnd}>
342
349
  <SortableContext items={ids} strategy={rectSortingStrategy}>
343
350
  <ul className="grid grid-cols-2 gap-3 sm:grid-cols-3 md:grid-cols-4" data-testid="gallery-grid">
351
+ {lead && (
352
+ <li
353
+ className="relative min-w-0 overflow-hidden rounded-lg border bg-card ring-2 ring-primary"
354
+ data-testid="gallery-lead"
355
+ data-main="true"
356
+ >
357
+ <div className="aspect-square w-full bg-muted" aria-label={`${t('dynamic.gallery.original', { defaultValue: 'Imagen original del producto' })} · ${mainLabel}`}>
358
+ <img src={lead.src} alt="" className="h-full w-full min-h-24 object-cover" draggable={false} />
359
+ </div>
360
+ <span className="absolute start-2 top-2 inline-flex items-center gap-1 rounded-full bg-primary px-2 py-0.5 text-xs font-medium text-primary-foreground">
361
+ <Star className="h-3 w-3" aria-hidden />
362
+ {mainLabel}
363
+ </span>
364
+ <div className="border-t bg-card px-2 py-1 text-xs text-muted-foreground">
365
+ {t('dynamic.gallery.original', { defaultValue: 'Imagen original del producto' })}
366
+ </div>
367
+ </li>
368
+ )}
344
369
  {keyed.map(({ row, key }, index) => (
345
370
  <GalleryTile
346
371
  key={key}
@@ -349,7 +374,8 @@ export function RelationGallery({
349
374
  caption={captionKey ? String(row[captionKey] ?? '') : ''}
350
375
  index={index}
351
376
  total={keyed.length}
352
- isMain={index === 0}
377
+ isMain={!lead && index === 0}
378
+ canMakeMain={!lead}
353
379
  mainLabel={mainLabel}
354
380
  canEdit={canEdit}
355
381
  canReorder={reorderable}
@@ -374,6 +400,7 @@ function GalleryTile({
374
400
  index,
375
401
  total,
376
402
  isMain,
403
+ canMakeMain,
377
404
  mainLabel,
378
405
  canEdit,
379
406
  canReorder,
@@ -388,6 +415,7 @@ function GalleryTile({
388
415
  index: number
389
416
  total: number
390
417
  isMain: boolean
418
+ canMakeMain: boolean
391
419
  mainLabel: string
392
420
  canEdit: boolean
393
421
  canReorder: boolean
@@ -455,7 +483,7 @@ function GalleryTile({
455
483
  >
456
484
  <ArrowRight className="h-4 w-4 rtl:rotate-180" />
457
485
  </Button>
458
- {!isMain && (
486
+ {!isMain && canMakeMain && (
459
487
  <Button
460
488
  type="button"
461
489
  size="sm"