@asteby/metacore-runtime-react 53.12.0 → 53.13.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/CHANGELOG.md +14 -0
- package/dist/bulk-image-dialog.d.ts +0 -13
- package/dist/bulk-image-dialog.d.ts.map +1 -1
- package/dist/bulk-image-dialog.js +9 -280
- package/dist/bulk-image-import.d.ts +2 -24
- package/dist/bulk-image-import.d.ts.map +1 -1
- package/dist/bulk-image-import.js +11 -30
- package/dist/bulk-image-target.d.ts +25 -0
- package/dist/bulk-image-target.d.ts.map +1 -0
- package/dist/bulk-image-target.js +30 -0
- package/dist/bulk-image-wizard.d.ts +15 -0
- package/dist/bulk-image-wizard.d.ts.map +1 -0
- package/dist/bulk-image-wizard.js +282 -0
- package/dist/dynamic-relation-helpers.d.ts +13 -0
- package/dist/dynamic-relation-helpers.d.ts.map +1 -1
- package/dist/dynamic-relation-helpers.js +20 -0
- package/dist/dynamic-relation.d.ts.map +1 -1
- package/dist/dynamic-relation.js +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -2
- package/dist/relation-gallery.d.ts +9 -1
- package/dist/relation-gallery.d.ts.map +1 -1
- package/dist/relation-gallery.js +4 -4
- package/package.json +1 -1
- package/src/__tests__/bulk-image-dialog.test.tsx +3 -3
- package/src/__tests__/relation-gallery.test.tsx +31 -6
- package/src/bulk-image-dialog.tsx +21 -496
- package/src/bulk-image-import.ts +2 -51
- package/src/bulk-image-target.ts +55 -0
- package/src/bulk-image-wizard.tsx +494 -0
- package/src/dynamic-relation-helpers.ts +27 -0
- package/src/dynamic-relation.tsx +6 -0
- package/src/index.ts +2 -8
- package/src/relation-gallery.tsx +31 -3
|
@@ -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
|
+
}
|
package/src/dynamic-relation.tsx
CHANGED
|
@@ -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}
|
package/src/index.ts
CHANGED
|
@@ -892,13 +892,7 @@ export {
|
|
|
892
892
|
export * from './capability-providers'
|
|
893
893
|
export {
|
|
894
894
|
BulkImageImportButton,
|
|
895
|
-
BulkImageDialog,
|
|
896
895
|
type BulkImageImportButtonProps,
|
|
897
896
|
} from './bulk-image-dialog'
|
|
898
|
-
export {
|
|
899
|
-
|
|
900
|
-
parseImageName as parseBulkImageName,
|
|
901
|
-
deriveBulkImageTarget,
|
|
902
|
-
type BulkImageTarget,
|
|
903
|
-
type BatchLog as BulkImageBatchLog,
|
|
904
|
-
} from './bulk-image-import'
|
|
897
|
+
export type { BulkImageTarget } from './bulk-image-target'
|
|
898
|
+
export type { BatchLog as BulkImageBatchLog } from './bulk-image-import'
|
package/src/relation-gallery.tsx
CHANGED
|
@@ -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"
|