@asteby/metacore-runtime-react 49.11.0 → 49.12.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 +6 -0
- package/README.md +40 -0
- package/dist/dialogs/dynamic-record.d.ts.map +1 -1
- package/dist/dialogs/dynamic-record.js +8 -1
- package/dist/dynamic-columns.d.ts.map +1 -1
- package/dist/dynamic-columns.js +11 -1
- package/dist/dynamic-icon.d.ts +16 -1
- package/dist/dynamic-icon.d.ts.map +1 -1
- package/dist/dynamic-icon.js +36 -5
- package/dist/icon-aliases.d.ts +2 -0
- package/dist/icon-aliases.d.ts.map +1 -0
- package/dist/icon-aliases.js +594 -0
- package/dist/icon-resolvers.d.ts +13 -0
- package/dist/icon-resolvers.d.ts.map +1 -0
- package/dist/icon-resolvers.js +36 -0
- package/dist/icon-spec.d.ts +17 -0
- package/dist/icon-spec.d.ts.map +1 -0
- package/dist/icon-spec.js +165 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/icon-component.test.tsx +145 -0
- package/src/__tests__/icon-spec.test.ts +155 -0
- package/src/dialogs/dynamic-record.tsx +17 -1
- package/src/dynamic-columns.tsx +22 -1
- package/src/dynamic-icon.tsx +68 -3
- package/src/icon-aliases.ts +602 -0
- package/src/icon-resolvers.ts +59 -0
- package/src/icon-spec.ts +169 -0
- package/src/index.ts +3 -0
- package/src/types.ts +3 -0
|
@@ -71,7 +71,7 @@ import { FieldCell } from '../field-grid'
|
|
|
71
71
|
import { isNilUuid, normalizeNilUuid } from '../nil-uuid'
|
|
72
72
|
import { normalizeRefFieldsForSubmit } from './normalize-submit'
|
|
73
73
|
import { validateValues, bagHasErrors, exemptUnchangedRuleIssues } from '../validator'
|
|
74
|
-
import { DynamicIcon, isLucideIconName } from '../dynamic-icon'
|
|
74
|
+
import { DynamicIcon, Icon, isLucideIconName } from '../dynamic-icon'
|
|
75
75
|
import { IconPickerField } from '../icon-picker-field'
|
|
76
76
|
import { humanizeToken, localizeFieldLabel } from '../dynamic-columns-helpers'
|
|
77
77
|
import { formatDateCell } from '../dynamic-columns'
|
|
@@ -1690,6 +1690,22 @@ export function ViewValue({
|
|
|
1690
1690
|
)
|
|
1691
1691
|
}
|
|
1692
1692
|
|
|
1693
|
+
// Explicit `type: 'icon'`: any stored icon format via the universal resolver.
|
|
1694
|
+
if (renderAs === 'icon') {
|
|
1695
|
+
const empty = <p className="text-sm py-1 text-muted-foreground">-</p>
|
|
1696
|
+
if (!value) return empty
|
|
1697
|
+
return (
|
|
1698
|
+
<div className="py-1">
|
|
1699
|
+
<Icon
|
|
1700
|
+
name={value}
|
|
1701
|
+
className="h-6 w-6"
|
|
1702
|
+
fallback={empty}
|
|
1703
|
+
resolveImageSrc={(src) => (/^(?:data:|https?:)/i.test(src) ? src : getImageUrl(src))}
|
|
1704
|
+
/>
|
|
1705
|
+
</div>
|
|
1706
|
+
)
|
|
1707
|
+
}
|
|
1708
|
+
|
|
1693
1709
|
if (field.type === 'image' || renderAs === 'image') {
|
|
1694
1710
|
if (isLucideIconName(value)) {
|
|
1695
1711
|
return <IconNameViewValue name={value} />
|
package/src/dynamic-columns.tsx
CHANGED
|
@@ -49,7 +49,7 @@ import {
|
|
|
49
49
|
} from './display-value'
|
|
50
50
|
import { MediaValue } from './rich-url'
|
|
51
51
|
import { OptionsContext } from './options-context'
|
|
52
|
-
import { DynamicIcon, isLucideIconName } from './dynamic-icon'
|
|
52
|
+
import { DynamicIcon, Icon, isLucideIconName } from './dynamic-icon'
|
|
53
53
|
import { CollectionCell } from './collection-cell'
|
|
54
54
|
import { isNilUuid, normalizeNilUuid } from './nil-uuid'
|
|
55
55
|
import { useOptionsResolver } from './use-options-resolver'
|
|
@@ -1482,6 +1482,27 @@ export function makeDefaultGetDynamicColumns(
|
|
|
1482
1482
|
return <ImageCell value={imageSrc} getImageUrl={getImageUrl} />
|
|
1483
1483
|
}
|
|
1484
1484
|
|
|
1485
|
+
case 'icon': {
|
|
1486
|
+
// Explicit `type: 'icon'` only: any stored icon format
|
|
1487
|
+
// (Lucide, FontAwesome classes, emoji, image URL).
|
|
1488
|
+
// Uninterpretable values show the dash, never raw text.
|
|
1489
|
+
if (!value) return <EmptyCell />
|
|
1490
|
+
return (
|
|
1491
|
+
<Icon
|
|
1492
|
+
name={value}
|
|
1493
|
+
className="h-5 w-5 text-foreground/80"
|
|
1494
|
+
fallback={<EmptyCell />}
|
|
1495
|
+
resolveImageSrc={(src) =>
|
|
1496
|
+
/^(?:data:|https?:)/i.test(src)
|
|
1497
|
+
? src
|
|
1498
|
+
: getImageUrl(
|
|
1499
|
+
resolveImageSrc(col, src, apiBaseUrl, normalizeImagePath),
|
|
1500
|
+
)
|
|
1501
|
+
}
|
|
1502
|
+
/>
|
|
1503
|
+
)
|
|
1504
|
+
}
|
|
1505
|
+
|
|
1485
1506
|
case 'image_stack': {
|
|
1486
1507
|
// Defensive: normally handled above before the
|
|
1487
1508
|
// switch; kept so a late `type: image_stack` without
|
package/src/dynamic-icon.tsx
CHANGED
|
@@ -2,14 +2,30 @@
|
|
|
2
2
|
// set into the shared chunk. It draws through the shared glyph registry of
|
|
3
3
|
// @asteby/metacore-ui: a glyph seen before renders in the first frame, and an
|
|
4
4
|
// unseen one holds its box until it loads, so the label next to it stays put.
|
|
5
|
+
import { useState, type ReactNode } from 'react'
|
|
5
6
|
import dynamicIconImports from 'lucide-react/dynamicIconImports'
|
|
6
7
|
import { Glyph } from '@asteby/metacore-ui/icons'
|
|
8
|
+
import { resolveIconSpec } from './icon-resolvers'
|
|
7
9
|
|
|
8
10
|
export interface DynamicIconProps {
|
|
9
11
|
name: string
|
|
10
12
|
className?: string
|
|
11
13
|
}
|
|
12
14
|
|
|
15
|
+
export interface IconProps {
|
|
16
|
+
/** Any icon value: Lucide name, FontAwesome classes, emoji, image URL... */
|
|
17
|
+
name: unknown
|
|
18
|
+
className?: string
|
|
19
|
+
/** Accessible name. Without it the icon is decorative (aria-hidden). */
|
|
20
|
+
label?: string
|
|
21
|
+
/** Drawn when the value cannot be interpreted. Default: nothing. */
|
|
22
|
+
fallback?: ReactNode
|
|
23
|
+
/** Maps an image `src` before it reaches <img> (e.g. host `getImageUrl`). */
|
|
24
|
+
resolveImageSrc?: (src: string) => string
|
|
25
|
+
/** Render image sources (default true). DynamicIcon turns it off. */
|
|
26
|
+
images?: boolean
|
|
27
|
+
}
|
|
28
|
+
|
|
13
29
|
type IconName = keyof typeof dynamicIconImports
|
|
14
30
|
|
|
15
31
|
function pascalToKebab(pascal: string): string {
|
|
@@ -35,10 +51,59 @@ function loaderFor(pascal: string) {
|
|
|
35
51
|
)
|
|
36
52
|
}
|
|
37
53
|
|
|
54
|
+
function IconImage({ src, className, label }: { src: string; className?: string; label?: string }) {
|
|
55
|
+
const [failed, setFailed] = useState<string | null>(null)
|
|
56
|
+
if (failed === src) return null
|
|
57
|
+
return (
|
|
58
|
+
<img
|
|
59
|
+
src={src}
|
|
60
|
+
alt={label ?? ''}
|
|
61
|
+
loading="lazy"
|
|
62
|
+
decoding="async"
|
|
63
|
+
className={className}
|
|
64
|
+
onError={() => setFailed(src)}
|
|
65
|
+
/>
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Icon — renders any icon value the SDK can interpret (see parseIconSpec and
|
|
70
|
+
// registerIconResolver): Lucide glyph, emoji, image or a host-rendered node.
|
|
71
|
+
// A value nobody understands renders `fallback` (default nothing), never the
|
|
72
|
+
// raw text. Decorative (aria-hidden) unless `label` is given.
|
|
73
|
+
export function Icon({ name, className, label, fallback = null, resolveImageSrc, images = true }: IconProps) {
|
|
74
|
+
const spec = resolveIconSpec(name)
|
|
75
|
+
const a11y = label ? ({ role: 'img', 'aria-label': label } as const) : ({ 'aria-hidden': true } as const)
|
|
76
|
+
switch (spec.kind) {
|
|
77
|
+
case 'lucide':
|
|
78
|
+
return <Glyph name={spec.name} className={className} {...a11y} />
|
|
79
|
+
case 'emoji':
|
|
80
|
+
return (
|
|
81
|
+
<span className={className} {...a11y}>
|
|
82
|
+
{spec.value}
|
|
83
|
+
</span>
|
|
84
|
+
)
|
|
85
|
+
case 'image':
|
|
86
|
+
if (!images) return <>{fallback}</>
|
|
87
|
+
return (
|
|
88
|
+
<IconImage
|
|
89
|
+
src={resolveImageSrc ? resolveImageSrc(spec.src) : spec.src}
|
|
90
|
+
className={className}
|
|
91
|
+
label={label}
|
|
92
|
+
/>
|
|
93
|
+
)
|
|
94
|
+
case 'node':
|
|
95
|
+
return <>{spec.node}</>
|
|
96
|
+
default:
|
|
97
|
+
return <>{fallback}</>
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// DynamicIcon keeps its { name, className } contract: Lucide names resolve
|
|
102
|
+
// exactly as before; FontAwesome classes, emoji and host resolvers now work
|
|
103
|
+
// too. Image paths still draw nothing here (icon slots in menus/buttons never
|
|
104
|
+
// showed <img>); use <Icon> or a `type: 'icon'` column for images.
|
|
38
105
|
export function DynamicIcon({ name, className }: DynamicIconProps) {
|
|
39
|
-
|
|
40
|
-
if (!resolved) return null
|
|
41
|
-
return <Glyph name={resolved} className={className} />
|
|
106
|
+
return <Icon name={name} className={className} images={false} />
|
|
42
107
|
}
|
|
43
108
|
|
|
44
109
|
// resolveLucideIconName — canonical PascalCase lucide name for a value that is
|