@asteby/metacore-runtime-react 53.4.0 → 53.4.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 +6 -0
- package/dist/display-value.d.ts +11 -0
- package/dist/display-value.d.ts.map +1 -1
- package/dist/display-value.js +26 -1
- package/dist/dynamic-columns.d.ts.map +1 -1
- package/dist/dynamic-columns.js +17 -6
- package/package.json +1 -1
- package/src/__tests__/image-stack.test.tsx +58 -1
- package/src/display-value.tsx +30 -1
- package/src/dynamic-columns.tsx +21 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @asteby/metacore-runtime-react
|
|
2
2
|
|
|
3
|
+
## 53.4.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- e27588d: Columnas de imagen (`display: "image_stack"` y `type: image`): si el host reescribe el `src` de la `<img>` al fallar (respaldo miniatura -> derivado principal de ops), el SDK ya no marca la imagen como rota ni cae a iniciales; solo lo hace cuando el fallo no tiene respaldo. En `image_stack` la URL ahora pasa por `resolveImageSrc` igual que `type: image` (`/storage/...` y http(s) intactos, `base_path` respetado).
|
|
8
|
+
|
|
3
9
|
## 53.4.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
package/dist/display-value.d.ts
CHANGED
|
@@ -27,6 +27,17 @@ export declare function statusColorFor(value: string): string;
|
|
|
27
27
|
* an addon-arbitrary Tailwind class never gets dropped by a consuming app's
|
|
28
28
|
* class scan). Rendered inline alongside a label — never alone.
|
|
29
29
|
*/
|
|
30
|
+
/**
|
|
31
|
+
* Manejador de `onError` para <img> que un host puede reescribir (p. ej. el
|
|
32
|
+
* respaldo miniatura -> derivado principal que ops instala en `document` en
|
|
33
|
+
* fase de captura, ANTES que React). Si al llegar el error el `src` del DOM ya
|
|
34
|
+
* no es el que React conocía, el host cambió la URL y la nueva carga sigue en
|
|
35
|
+
* curso: NO se debe marcar la imagen como rota (antes se desmontaba y quedaban
|
|
36
|
+
* las iniciales aunque el respaldo cargara). Solo un fallo sin reescritura
|
|
37
|
+
* (el `src` no cambió desde el último error) invoca `onFail`.
|
|
38
|
+
* Exportado para pruebas.
|
|
39
|
+
*/
|
|
40
|
+
export declare function useImageErrorGuard(resolved: string | undefined, onFail: () => void): (e: React.SyntheticEvent<HTMLImageElement>) => void;
|
|
30
41
|
export declare const RelationThumbnail: React.FC<{
|
|
31
42
|
src: string;
|
|
32
43
|
alt: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"display-value.d.ts","sourceRoot":"","sources":["../src/display-value.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,MAAM,OAAO,CAAA;AASzB;;;GAGG;AACH,wBAAgB,cAAc,IAAI,OAAO,CAmBxC;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAepD;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAAC;IACrC,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;IACX,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAA;IACtC,IAAI,CAAC,EAAE,MAAM,CAAA;CAChB,CAiBA,CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC;IAC9B,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACnB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACrB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAA;IACtC,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,CAAA;IACzB,SAAS,CAAC,EAAE,MA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AC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;CACpB;AAED;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC;IAC/B,MAAM,EAAE,aAAa,CAAA;IACrB,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAA;IACtC,uFAAuF;IACvF,QAAQ,CAAC,EAAE,MAAM,CAAA;CACpB,CA8BA,CAAA"}
|
package/dist/display-value.js
CHANGED
|
@@ -58,6 +58,30 @@ export function statusColorFor(value) {
|
|
|
58
58
|
* an addon-arbitrary Tailwind class never gets dropped by a consuming app's
|
|
59
59
|
* class scan). Rendered inline alongside a label — never alone.
|
|
60
60
|
*/
|
|
61
|
+
/**
|
|
62
|
+
* Manejador de `onError` para <img> que un host puede reescribir (p. ej. el
|
|
63
|
+
* respaldo miniatura -> derivado principal que ops instala en `document` en
|
|
64
|
+
* fase de captura, ANTES que React). Si al llegar el error el `src` del DOM ya
|
|
65
|
+
* no es el que React conocía, el host cambió la URL y la nueva carga sigue en
|
|
66
|
+
* curso: NO se debe marcar la imagen como rota (antes se desmontaba y quedaban
|
|
67
|
+
* las iniciales aunque el respaldo cargara). Solo un fallo sin reescritura
|
|
68
|
+
* (el `src` no cambió desde el último error) invoca `onFail`.
|
|
69
|
+
* Exportado para pruebas.
|
|
70
|
+
*/
|
|
71
|
+
export function useImageErrorGuard(resolved, onFail) {
|
|
72
|
+
const seen = React.useRef(resolved);
|
|
73
|
+
React.useEffect(() => {
|
|
74
|
+
seen.current = resolved;
|
|
75
|
+
}, [resolved]);
|
|
76
|
+
return React.useCallback((e) => {
|
|
77
|
+
const cur = e.currentTarget.getAttribute('src') ?? undefined;
|
|
78
|
+
if (cur !== undefined && cur !== seen.current) {
|
|
79
|
+
seen.current = cur;
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
onFail();
|
|
83
|
+
}, [onFail]);
|
|
84
|
+
}
|
|
61
85
|
export const RelationThumbnail = ({ src, alt, getImageUrl, size = 20 }) => (_jsxs(Avatar, { className: "shrink-0 rounded-md", style: { width: size, height: size }, children: [_jsx(AvatarImage, { src: getImageUrl ? getImageUrl(src) : src, alt: alt, className: "object-contain" }), _jsx(AvatarFallback, { className: "rounded-md bg-transparent text-[8px] font-bold text-muted-foreground", children: getInitials(alt) })] }));
|
|
62
86
|
/**
|
|
63
87
|
* Landscape-friendly identity block: wide image ON TOP, label (and optional
|
|
@@ -90,7 +114,8 @@ export const ImageStack = ({ src, label, subtitle, getImageUrl, size = 'md', cla
|
|
|
90
114
|
React.useEffect(() => {
|
|
91
115
|
setBroken(false);
|
|
92
116
|
}, [resolved]);
|
|
93
|
-
|
|
117
|
+
const onImgError = useImageErrorGuard(resolved, () => setBroken(true));
|
|
118
|
+
return (_jsxs("span", { className: `inline-flex max-w-[220px] flex-col items-start gap-0.5 ${className ?? ''}`, title: subtitle ? `${alt} · ${subtitle}` : alt || undefined, children: [resolved && !broken ? (_jsx("img", { src: resolved, alt: alt, className: "block object-contain", style: { maxWidth: dims.w, maxHeight: dims.h, width: 'auto', height: 'auto' }, onError: onImgError })) : (_jsx("span", { className: "flex items-center text-[10px] font-semibold tracking-wide text-muted-foreground", style: { minHeight: Math.round(dims.h * 0.55) }, children: getInitials(alt || '?') })), (label || subtitle) && (_jsxs("span", { className: `flex w-full min-w-0 flex-col items-start leading-tight ${dims.text}`, children: [label ? (_jsx("span", { className: "w-full truncate text-left font-medium text-foreground/90", children: label })) : null, subtitle ? (_jsx("span", { className: "w-full truncate text-left text-[0.7em] text-muted-foreground", children: subtitle })) : null] }))] }));
|
|
94
119
|
};
|
|
95
120
|
/**
|
|
96
121
|
* Colored option badge — the canonical "pro" pill for a select/status/badge
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamic-columns.d.ts","sourceRoot":"","sources":["../src/dynamic-columns.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|
26
26
|
import { AuthorshipCell, hasSpecialAuthorship } from './provenance';
|
|
27
27
|
import { humanizeToken, resolveColumnOptions, translateMetadataLabel } from './dynamic-columns-helpers';
|
|
28
28
|
import { objectLabel } from './dynamic-relation-helpers';
|
|
29
|
-
import { OptionBadge, RelationThumbnail, ImageStack, statusColorFor, useIsDarkTheme, } from './display-value';
|
|
29
|
+
import { OptionBadge, RelationThumbnail, ImageStack, statusColorFor, useIsDarkTheme, useImageErrorGuard, } from './display-value';
|
|
30
30
|
import { MediaValue } from './rich-url';
|
|
31
31
|
import { OptionsContext } from './options-context';
|
|
32
32
|
import { DynamicIcon, Icon, isLucideIconName } from './dynamic-icon';
|
|
@@ -678,10 +678,16 @@ export const ImageCell = ({ value, getImageUrl, label, stack = false }) => {
|
|
|
678
678
|
}
|
|
679
679
|
if (!value)
|
|
680
680
|
return _jsx("span", { className: "text-muted-foreground", children: "-" });
|
|
681
|
-
return
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
681
|
+
return _jsx(ThumbImage, { src: getImageUrl(String(value)) });
|
|
682
|
+
};
|
|
683
|
+
/** <img> 40x40 de `type: image`; se oculta solo si la carga falla sin respaldo del host. */
|
|
684
|
+
const ThumbImage = ({ src }) => {
|
|
685
|
+
const [broken, setBroken] = React.useState(false);
|
|
686
|
+
React.useEffect(() => {
|
|
687
|
+
setBroken(false);
|
|
688
|
+
}, [src]);
|
|
689
|
+
const onImgError = useImageErrorGuard(src, () => setBroken(true));
|
|
690
|
+
return (_jsx("div", { className: "h-10 w-10 relative rounded overflow-hidden bg-muted flex items-center justify-center", children: _jsx("img", { src: src, alt: "Thumbnail", className: "h-full w-full object-contain", style: broken ? { display: 'none' } : undefined, onError: onImgError }) }));
|
|
685
691
|
};
|
|
686
692
|
export function makeDefaultGetDynamicColumns(helpers = {}) {
|
|
687
693
|
const getImageUrl = helpers.getImageUrl ?? defaultGetImageUrl;
|
|
@@ -833,7 +839,12 @@ export function makeDefaultGetDynamicColumns(helpers = {}) {
|
|
|
833
839
|
const caption = labelField
|
|
834
840
|
? String(getNestedValue(row.original, labelField) ?? '')
|
|
835
841
|
: undefined;
|
|
836
|
-
|
|
842
|
+
// Misma resolución que `type: image` (base_path,
|
|
843
|
+
// normalizeImagePath); `/storage/...` y http(s) pasan intactos.
|
|
844
|
+
const stackSrc = value && !isLucideIconName(value)
|
|
845
|
+
? resolveImageSrc(col, String(value), apiBaseUrl, normalizeImagePath)
|
|
846
|
+
: value;
|
|
847
|
+
return (_jsx(ImageCell, { value: stackSrc, getImageUrl: getImageUrl, label: caption || undefined, stack: true }));
|
|
837
848
|
}
|
|
838
849
|
// Resolved FK relation chip. Triggers on an explicit
|
|
839
850
|
// `cellStyle: 'relation'` or on any column carrying a `ref`
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// @vitest-environment happy-dom
|
|
2
2
|
|
|
3
3
|
import { afterEach, describe, expect, it } from 'vitest'
|
|
4
|
-
import { cleanup, render } from '@testing-library/react'
|
|
4
|
+
import { cleanup, fireEvent, render } from '@testing-library/react'
|
|
5
5
|
import { ImageStack } from '../display-value'
|
|
6
6
|
import { ImageCell } from '../dynamic-columns'
|
|
7
7
|
|
|
@@ -50,3 +50,60 @@ describe('ImageCell stack mode', () => {
|
|
|
50
50
|
expect((container.firstElementChild as HTMLElement).className).toContain('flex-col')
|
|
51
51
|
})
|
|
52
52
|
})
|
|
53
|
+
|
|
54
|
+
describe('ImageStack: URL y errores de carga', () => {
|
|
55
|
+
const SHA = 'a'.repeat(64)
|
|
56
|
+
const ORG = '0170734c-f096-4ed9-b656-7a124917a257'
|
|
57
|
+
|
|
58
|
+
it('pinta la foto con URL /storage relativa', () => {
|
|
59
|
+
const url = `/storage/catalog/${ORG}/${SHA}.png`
|
|
60
|
+
const { container } = render(<ImageStack src={url} label="CILINDRO MAESTRO" />)
|
|
61
|
+
expect(container.querySelector('img')?.getAttribute('src')).toBe(url)
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
it('pinta la foto con URL absoluta', () => {
|
|
65
|
+
const url = 'https://panel.example.com/storage/p.png'
|
|
66
|
+
const { container } = render(<ImageStack src={url} label="X" />)
|
|
67
|
+
expect(container.querySelector('img')?.getAttribute('src')).toBe(url)
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
it('vacío: iniciales, sin <img>', () => {
|
|
71
|
+
const { container, getByText } = render(<ImageStack src="" label="CILINDRO MAESTRO" />)
|
|
72
|
+
expect(container.querySelector('img')).toBeNull()
|
|
73
|
+
expect(getByText('CM')).toBeTruthy()
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
it('error de carga sin respaldo: cae a iniciales', () => {
|
|
77
|
+
const { container, getByText } = render(
|
|
78
|
+
<ImageStack src="/storage/catalog/x.png" label="CILINDRO MAESTRO" />,
|
|
79
|
+
)
|
|
80
|
+
fireEvent.error(container.querySelector('img')!)
|
|
81
|
+
expect(container.querySelector('img')).toBeNull()
|
|
82
|
+
expect(getByText('CM')).toBeTruthy()
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
it('si el host reescribe el src al fallar (miniatura -> principal), NO cae a iniciales', () => {
|
|
86
|
+
const thumb = `/storage/catalog/${ORG}/${SHA}_320.webp`
|
|
87
|
+
const main = `/storage/catalog/${ORG}/${SHA}.png`
|
|
88
|
+
const { container } = render(<ImageStack src={thumb} label="CILINDRO MAESTRO" />)
|
|
89
|
+
const img = container.querySelector('img')!
|
|
90
|
+
// el host (captura en document) cambia el src antes que React
|
|
91
|
+
img.setAttribute('src', main)
|
|
92
|
+
fireEvent.error(img)
|
|
93
|
+
expect(container.querySelector('img')?.getAttribute('src')).toBe(main)
|
|
94
|
+
// si el respaldo tambien falla y el host ya no tiene mas, entonces si
|
|
95
|
+
fireEvent.error(container.querySelector('img')!)
|
|
96
|
+
expect(container.querySelector('img')).toBeNull()
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
it('ImageCell plano: /storage, vacio y error', () => {
|
|
100
|
+
const url = `/storage/catalog/${ORG}/${SHA}.png`
|
|
101
|
+
const { container, rerender } = render(<ImageCell value={url} getImageUrl={(p) => p} />)
|
|
102
|
+
const img = container.querySelector('img')!
|
|
103
|
+
expect(img.getAttribute('src')).toBe(url)
|
|
104
|
+
fireEvent.error(img)
|
|
105
|
+
expect((container.querySelector('img') as HTMLElement).style.display).toBe('none')
|
|
106
|
+
rerender(<ImageCell value="" getImageUrl={(p) => p} />)
|
|
107
|
+
expect(container.querySelector('img')).toBeNull()
|
|
108
|
+
})
|
|
109
|
+
})
|
package/src/display-value.tsx
CHANGED
|
@@ -71,6 +71,34 @@ export function statusColorFor(value: string): string {
|
|
|
71
71
|
* an addon-arbitrary Tailwind class never gets dropped by a consuming app's
|
|
72
72
|
* class scan). Rendered inline alongside a label — never alone.
|
|
73
73
|
*/
|
|
74
|
+
/**
|
|
75
|
+
* Manejador de `onError` para <img> que un host puede reescribir (p. ej. el
|
|
76
|
+
* respaldo miniatura -> derivado principal que ops instala en `document` en
|
|
77
|
+
* fase de captura, ANTES que React). Si al llegar el error el `src` del DOM ya
|
|
78
|
+
* no es el que React conocía, el host cambió la URL y la nueva carga sigue en
|
|
79
|
+
* curso: NO se debe marcar la imagen como rota (antes se desmontaba y quedaban
|
|
80
|
+
* las iniciales aunque el respaldo cargara). Solo un fallo sin reescritura
|
|
81
|
+
* (el `src` no cambió desde el último error) invoca `onFail`.
|
|
82
|
+
* Exportado para pruebas.
|
|
83
|
+
*/
|
|
84
|
+
export function useImageErrorGuard(resolved: string | undefined, onFail: () => void) {
|
|
85
|
+
const seen = React.useRef<string | undefined>(resolved)
|
|
86
|
+
React.useEffect(() => {
|
|
87
|
+
seen.current = resolved
|
|
88
|
+
}, [resolved])
|
|
89
|
+
return React.useCallback(
|
|
90
|
+
(e: React.SyntheticEvent<HTMLImageElement>) => {
|
|
91
|
+
const cur = e.currentTarget.getAttribute('src') ?? undefined
|
|
92
|
+
if (cur !== undefined && cur !== seen.current) {
|
|
93
|
+
seen.current = cur
|
|
94
|
+
return
|
|
95
|
+
}
|
|
96
|
+
onFail()
|
|
97
|
+
},
|
|
98
|
+
[onFail],
|
|
99
|
+
)
|
|
100
|
+
}
|
|
101
|
+
|
|
74
102
|
export const RelationThumbnail: React.FC<{
|
|
75
103
|
src: string
|
|
76
104
|
alt: string
|
|
@@ -134,6 +162,7 @@ export const ImageStack: React.FC<{
|
|
|
134
162
|
React.useEffect(() => {
|
|
135
163
|
setBroken(false)
|
|
136
164
|
}, [resolved])
|
|
165
|
+
const onImgError = useImageErrorGuard(resolved, () => setBroken(true))
|
|
137
166
|
|
|
138
167
|
return (
|
|
139
168
|
<span
|
|
@@ -146,7 +175,7 @@ export const ImageStack: React.FC<{
|
|
|
146
175
|
alt={alt}
|
|
147
176
|
className="block object-contain"
|
|
148
177
|
style={{ maxWidth: dims.w, maxHeight: dims.h, width: 'auto', height: 'auto' }}
|
|
149
|
-
onError={
|
|
178
|
+
onError={onImgError}
|
|
150
179
|
/>
|
|
151
180
|
) : (
|
|
152
181
|
<span
|
package/src/dynamic-columns.tsx
CHANGED
|
@@ -49,6 +49,7 @@ import {
|
|
|
49
49
|
ImageStack,
|
|
50
50
|
statusColorFor,
|
|
51
51
|
useIsDarkTheme,
|
|
52
|
+
useImageErrorGuard,
|
|
52
53
|
} from './display-value'
|
|
53
54
|
import { MediaValue } from './rich-url'
|
|
54
55
|
import { OptionsContext } from './options-context'
|
|
@@ -958,15 +959,24 @@ export const ImageCell: React.FC<{
|
|
|
958
959
|
)
|
|
959
960
|
}
|
|
960
961
|
if (!value) return <span className="text-muted-foreground">-</span>
|
|
962
|
+
return <ThumbImage src={getImageUrl(String(value))} />
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
/** <img> 40x40 de `type: image`; se oculta solo si la carga falla sin respaldo del host. */
|
|
966
|
+
const ThumbImage: React.FC<{ src: string }> = ({ src }) => {
|
|
967
|
+
const [broken, setBroken] = React.useState(false)
|
|
968
|
+
React.useEffect(() => {
|
|
969
|
+
setBroken(false)
|
|
970
|
+
}, [src])
|
|
971
|
+
const onImgError = useImageErrorGuard(src, () => setBroken(true))
|
|
961
972
|
return (
|
|
962
973
|
<div className="h-10 w-10 relative rounded overflow-hidden bg-muted flex items-center justify-center">
|
|
963
974
|
<img
|
|
964
|
-
src={
|
|
975
|
+
src={src}
|
|
965
976
|
alt="Thumbnail"
|
|
966
977
|
className="h-full w-full object-contain"
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
}}
|
|
978
|
+
style={broken ? { display: 'none' } : undefined}
|
|
979
|
+
onError={onImgError}
|
|
970
980
|
/>
|
|
971
981
|
</div>
|
|
972
982
|
)
|
|
@@ -1173,9 +1183,15 @@ export function makeDefaultGetDynamicColumns(
|
|
|
1173
1183
|
const caption = labelField
|
|
1174
1184
|
? String(getNestedValue(row.original, labelField) ?? '')
|
|
1175
1185
|
: undefined
|
|
1186
|
+
// Misma resolución que `type: image` (base_path,
|
|
1187
|
+
// normalizeImagePath); `/storage/...` y http(s) pasan intactos.
|
|
1188
|
+
const stackSrc =
|
|
1189
|
+
value && !isLucideIconName(value)
|
|
1190
|
+
? resolveImageSrc(col, String(value), apiBaseUrl, normalizeImagePath)
|
|
1191
|
+
: value
|
|
1176
1192
|
return (
|
|
1177
1193
|
<ImageCell
|
|
1178
|
-
value={
|
|
1194
|
+
value={stackSrc}
|
|
1179
1195
|
getImageUrl={getImageUrl}
|
|
1180
1196
|
label={caption || undefined}
|
|
1181
1197
|
stack
|