najm-kit 2.9.0 → 2.10.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 +192 -174
- package/README.md +477 -349
- package/dist/{NajmUIProvider-CI_73GEp.d.ts → NajmUIProvider-BnReyojl.d.ts} +95 -2
- package/dist/adapters/app.d.ts +4 -1
- package/dist/adapters/app.mjs +3 -3
- package/dist/adapters/next.d.ts +27 -2
- package/dist/adapters/next.mjs +2 -2
- package/dist/{chunk-IRFFSAO2.mjs → chunk-EUQOTPLV.mjs} +26 -2
- package/dist/{chunk-USZUOJMK.mjs → chunk-FDONJASN.mjs} +163 -3
- package/dist/{chunk-GHMR45H3.mjs → chunk-HML2JZXT.mjs} +1 -1
- package/dist/index.d.ts +57 -62
- package/dist/index.mjs +196 -216
- package/package.json +1 -1
|
@@ -3,6 +3,8 @@ import * as React from 'react';
|
|
|
3
3
|
import React__default from 'react';
|
|
4
4
|
import { e as NajmMode, a as NajmDesignConfig } from './design-types-Rkpt8Pg1.js';
|
|
5
5
|
import { b as NTablePaginationLabels, N as NajmTranslate } from './paginationLabels-dZLSNxfo.js';
|
|
6
|
+
import * as class_variance_authority_types from 'class-variance-authority/types';
|
|
7
|
+
import { VariantProps } from 'class-variance-authority';
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* Defaults every `NTable` beneath the provider inherits.
|
|
@@ -28,6 +30,89 @@ declare function NTableDefaultsProvider({ children, value, }: {
|
|
|
28
30
|
}): react_jsx_runtime.JSX.Element;
|
|
29
31
|
declare function useNTableDefaults(): NTableDefaults;
|
|
30
32
|
|
|
33
|
+
type NIconSource = React__default.ReactElement | React__default.ComponentType<any> | React__default.ExoticComponent<any> | string | {
|
|
34
|
+
src: string;
|
|
35
|
+
alt?: string;
|
|
36
|
+
};
|
|
37
|
+
type NIconProps = Omit<React__default.HTMLAttributes<HTMLElement>, "children"> & {
|
|
38
|
+
size?: string | number;
|
|
39
|
+
icon: NIconSource;
|
|
40
|
+
alt?: string;
|
|
41
|
+
color?: string;
|
|
42
|
+
className?: string;
|
|
43
|
+
strokeWidth?: number;
|
|
44
|
+
stroke?: string;
|
|
45
|
+
fill?: string;
|
|
46
|
+
onClick?: React__default.MouseEventHandler<HTMLElement>;
|
|
47
|
+
style?: React__default.CSSProperties;
|
|
48
|
+
};
|
|
49
|
+
declare const NIcon: React__default.FC<NIconProps>;
|
|
50
|
+
|
|
51
|
+
declare const badgeVariants: (props?: {
|
|
52
|
+
variant?: "secondary" | "destructive" | "default" | "outline" | "success" | "warning";
|
|
53
|
+
} & class_variance_authority_types.ClassProp) => string;
|
|
54
|
+
declare const badgeColorVariants: (props?: {
|
|
55
|
+
color?: "neutral" | "primary" | "accent" | "secondary" | "destructive" | "success" | "warning" | "info";
|
|
56
|
+
look?: "solid" | "outline" | "soft" | "dash";
|
|
57
|
+
size?: "sm" | "md" | "lg";
|
|
58
|
+
shape?: "default" | "square" | "pill";
|
|
59
|
+
} & class_variance_authority_types.ClassProp) => string;
|
|
60
|
+
type BadgeVariantProps = VariantProps<typeof badgeVariants>;
|
|
61
|
+
type BadgeColorVariantProps = VariantProps<typeof badgeColorVariants>;
|
|
62
|
+
type BadgeColor = NonNullable<BadgeColorVariantProps["color"]>;
|
|
63
|
+
type BadgeLook = NonNullable<BadgeColorVariantProps["look"]>;
|
|
64
|
+
type BadgeDisplayLook = BadgeLook | "minimal" | "text";
|
|
65
|
+
type BadgeSize = NonNullable<BadgeColorVariantProps["size"]>;
|
|
66
|
+
type BadgeShape = NonNullable<BadgeColorVariantProps["shape"]>;
|
|
67
|
+
type BadgeVariant = NonNullable<BadgeVariantProps["variant"]>;
|
|
68
|
+
type BadgeIcon = NIconSource;
|
|
69
|
+
type BadgeProps = React.ComponentProps<"span"> & {
|
|
70
|
+
asChild?: boolean;
|
|
71
|
+
variant?: BadgeVariantProps["variant"];
|
|
72
|
+
status?: string;
|
|
73
|
+
statusMap?: Record<string, BadgeColor>;
|
|
74
|
+
label?: string;
|
|
75
|
+
showIcon?: boolean;
|
|
76
|
+
color?: BadgeColor;
|
|
77
|
+
look?: BadgeDisplayLook;
|
|
78
|
+
size?: BadgeSize;
|
|
79
|
+
shape?: BadgeShape;
|
|
80
|
+
icon?: BadgeIcon;
|
|
81
|
+
iconMap?: Record<string, BadgeIcon>;
|
|
82
|
+
iconPosition?: "left" | "right";
|
|
83
|
+
};
|
|
84
|
+
declare function Badge({ className, variant, status, statusMap, label, showIcon, color, look, size, shape, icon, iconMap, iconPosition, asChild, children, style, ...props }: BadgeProps): react_jsx_runtime.JSX.Element;
|
|
85
|
+
declare const NBadge: typeof Badge;
|
|
86
|
+
type NBadgeLook = BadgeDisplayLook;
|
|
87
|
+
type NBadgeProps = BadgeProps;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Application-wide presentation policy for `<NBadge status="…" />`.
|
|
91
|
+
*
|
|
92
|
+
* This is the whole reason a project ends up with a `StatusBadge` wrapper: the
|
|
93
|
+
* badge itself is already correct, but every call site has to repeat the same
|
|
94
|
+
* look, the same shape, and the same translation lookup. Declared once on the
|
|
95
|
+
* provider, none of that reaches a call site.
|
|
96
|
+
*
|
|
97
|
+
* What stays in the application: the vocabulary and the catalog. `statusMap`
|
|
98
|
+
* and `statusLabelKeys` take *its* status tokens and *its* catalog keys — this
|
|
99
|
+
* package ships neither.
|
|
100
|
+
*/
|
|
101
|
+
interface NBadgeDefaults {
|
|
102
|
+
look?: NBadgeLook;
|
|
103
|
+
shape?: BadgeShape;
|
|
104
|
+
size?: BadgeSize;
|
|
105
|
+
showIcon?: boolean;
|
|
106
|
+
/** Status token to badge color. Merged over the packaged vocabulary. */
|
|
107
|
+
statusMap?: Record<string, BadgeColor>;
|
|
108
|
+
/** Badge color to icon, used when `showIcon` is on. */
|
|
109
|
+
iconMap?: Record<string, BadgeIcon>;
|
|
110
|
+
/** Status token to finished label text. Wins over `statusLabelKeys`. */
|
|
111
|
+
statusLabels?: Record<string, string>;
|
|
112
|
+
/** Status token to catalog key, resolved through the provider's `t`. */
|
|
113
|
+
statusLabelKeys?: Record<string, string>;
|
|
114
|
+
}
|
|
115
|
+
|
|
31
116
|
/**
|
|
32
117
|
* Theme and time zone, the two preferences that outlive a render.
|
|
33
118
|
*
|
|
@@ -136,6 +221,14 @@ interface NajmUIProviderProps extends Omit<NajmPreferencesProviderProps, "childr
|
|
|
136
221
|
* same reason as `t`.
|
|
137
222
|
*/
|
|
138
223
|
tableDefaults?: NTableDefaults;
|
|
224
|
+
/**
|
|
225
|
+
* Presentation policy for `<NBadge status="…" />`: the look, the shape, and
|
|
226
|
+
* the map from the application's status tokens to its catalog keys.
|
|
227
|
+
*
|
|
228
|
+
* This is the prop that deletes a project's `StatusBadge` wrapper. Memoize it
|
|
229
|
+
* for the same reason as `t`.
|
|
230
|
+
*/
|
|
231
|
+
badgeDefaults?: NBadgeDefaults;
|
|
139
232
|
}
|
|
140
233
|
/**
|
|
141
234
|
* The one provider a Najm application mounts for UI concerns.
|
|
@@ -156,6 +249,6 @@ interface NajmUIProviderProps extends Omit<NajmPreferencesProviderProps, "childr
|
|
|
156
249
|
* an application with a runtime theme editor hoist preferences above its
|
|
157
250
|
* design context without forking this component.
|
|
158
251
|
*/
|
|
159
|
-
declare function NajmUIProvider({ children, design, initialDesign, className, t, paginationKeyPrefix, tableDefaults, initialTheme, initialTimeZone, onThemeChange, onTimeZoneChange, normalizeTimeZone, }: NajmUIProviderProps): react_jsx_runtime.JSX.Element;
|
|
252
|
+
declare function NajmUIProvider({ children, design, initialDesign, className, t, paginationKeyPrefix, tableDefaults, badgeDefaults, initialTheme, initialTimeZone, onThemeChange, onTimeZoneChange, normalizeTimeZone, }: NajmUIProviderProps): react_jsx_runtime.JSX.Element;
|
|
160
253
|
|
|
161
|
-
export { DEFAULT_TIME_ZONE as D, type NajmUIProviderProps as N, type
|
|
254
|
+
export { type BadgeColor as B, DEFAULT_TIME_ZONE as D, type NajmUIProviderProps as N, type NIconSource as a, type BadgeShape as b, Badge as c, type BadgeIcon as d, type BadgeLook as e, type BadgeProps as f, type BadgeSize as g, type BadgeVariant as h, NBadge as i, type NBadgeDefaults as j, type NBadgeLook as k, type NBadgeProps as l, NIcon as m, type NIconProps as n, type NTableDefaults as o, NTableDefaultsProvider as p, type NajmPreferencesContextValue as q, NajmPreferencesProvider as r, type NajmPreferencesProviderProps as s, NajmUIProvider as t, badgeColorVariants as u, badgeVariants as v, useNTableDefaults as w, useNajmPreferencesContext as x, useNajmTheme as y, useNajmTimeZone as z };
|
package/dist/adapters/app.d.ts
CHANGED
|
@@ -4,9 +4,12 @@ import { F as FormDevToolsOptions, N as NBrandingInput } from '../formFill-BcH-m
|
|
|
4
4
|
import { NajmNextUIProviderProps } from './next.js';
|
|
5
5
|
import 'react';
|
|
6
6
|
import 'zod';
|
|
7
|
-
import '
|
|
7
|
+
import 'next/image';
|
|
8
|
+
import '../NajmUIProvider-BnReyojl.js';
|
|
8
9
|
import '../design-types-Rkpt8Pg1.js';
|
|
9
10
|
import '../paginationLabels-dZLSNxfo.js';
|
|
11
|
+
import 'class-variance-authority/types';
|
|
12
|
+
import 'class-variance-authority';
|
|
10
13
|
|
|
11
14
|
/** Branding shown by the kit's chrome. Purely presentational values. */
|
|
12
15
|
interface NajmAppBranding {
|
package/dist/adapters/app.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { FormDevToolsProvider, NBrandingStateProvider, NajmFormatProvider } from '../chunk-
|
|
3
|
-
import { NajmNextUIProvider } from '../chunk-
|
|
4
|
-
import '../chunk-
|
|
2
|
+
import { FormDevToolsProvider, NBrandingStateProvider, NajmFormatProvider } from '../chunk-HML2JZXT.mjs';
|
|
3
|
+
import { NajmNextUIProvider } from '../chunk-EUQOTPLV.mjs';
|
|
4
|
+
import '../chunk-FDONJASN.mjs';
|
|
5
5
|
import '../chunk-KVZACF4G.mjs';
|
|
6
6
|
import '../chunk-JABLSOQN.mjs';
|
|
7
7
|
import * as React from 'react';
|
package/dist/adapters/next.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import React__default from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import { ImageProps } from 'next/image';
|
|
4
|
+
import { N as NajmUIProviderProps } from '../NajmUIProvider-BnReyojl.js';
|
|
4
5
|
import '../design-types-Rkpt8Pg1.js';
|
|
5
6
|
import '../paginationLabels-dZLSNxfo.js';
|
|
7
|
+
import 'class-variance-authority/types';
|
|
8
|
+
import 'class-variance-authority';
|
|
6
9
|
|
|
7
10
|
interface NextLinkAdapterProps extends Record<string, any> {
|
|
8
11
|
href: string;
|
|
@@ -20,6 +23,28 @@ declare function useNextNavigationAdapter(): {
|
|
|
20
23
|
push: (path: string) => void;
|
|
21
24
|
replace: (path: string) => void;
|
|
22
25
|
};
|
|
26
|
+
interface NNextImageProps extends Omit<ImageProps, 'src' | 'onError'> {
|
|
27
|
+
src: string;
|
|
28
|
+
/** Swapped in once `src` fails to load. Tried exactly once. */
|
|
29
|
+
fallbackSrc?: string;
|
|
30
|
+
onError?: ImageProps['onError'];
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* `next/image` with the fallback behavior of `NImage`, for applications that
|
|
34
|
+
* want the optimizer, the layout reservation, and `fill`/`sizes`.
|
|
35
|
+
*
|
|
36
|
+
* Lives only in `najm-kit/next`. The root entry must stay installable without
|
|
37
|
+
* Next, which is why this cannot be a prop on `NImage`.
|
|
38
|
+
*
|
|
39
|
+
* It classifies nothing. An application that serves an asset from a route the
|
|
40
|
+
* browser must reach directly — an authenticated one, say — passes
|
|
41
|
+
* `unoptimized` at the call site, because whether a route is protected is the
|
|
42
|
+
* application's fact and not something a URL shape can be read for. Note also
|
|
43
|
+
* what `unoptimized` is not: it changes delivery mechanics only. Session
|
|
44
|
+
* validation, permissions, and what bytes come back remain entirely the
|
|
45
|
+
* backend's.
|
|
46
|
+
*/
|
|
47
|
+
declare function NNextImage({ src, fallbackSrc, loading, priority, onError, ...props }: NNextImageProps): react_jsx_runtime.JSX.Element;
|
|
23
48
|
/** Where `NajmNextUIProvider` POSTs each preference. */
|
|
24
49
|
interface NajmNextUIEndpoints {
|
|
25
50
|
/** Defaults to `/api/ui-theme`. Receives `{ theme }`. */
|
|
@@ -50,4 +75,4 @@ interface NajmNextUIProviderProps extends Omit<NajmUIProviderProps, 'onThemeChan
|
|
|
50
75
|
*/
|
|
51
76
|
declare function NajmNextUIProvider({ endpoints, refreshOnChange, ...props }: NajmNextUIProviderProps): react_jsx_runtime.JSX.Element;
|
|
52
77
|
|
|
53
|
-
export { type NajmNextUIEndpoints, NajmNextUIProvider, type NajmNextUIProviderProps, NextLinkAdapter, type NextLinkAdapterProps, useNextNavigationAdapter };
|
|
78
|
+
export { NNextImage, type NNextImageProps, type NajmNextUIEndpoints, NajmNextUIProvider, type NajmNextUIProviderProps, NextLinkAdapter, type NextLinkAdapterProps, useNextNavigationAdapter };
|
package/dist/adapters/next.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { NajmNextUIProvider, NextLinkAdapter, useNextNavigationAdapter } from '../chunk-
|
|
2
|
-
import '../chunk-
|
|
1
|
+
export { NNextImage, NajmNextUIProvider, NextLinkAdapter, useNextNavigationAdapter } from '../chunk-EUQOTPLV.mjs';
|
|
2
|
+
import '../chunk-FDONJASN.mjs';
|
|
3
3
|
import '../chunk-KVZACF4G.mjs';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { NajmUIProvider } from './chunk-
|
|
1
|
+
import { useImageChain, normalizeImageSources, NajmUIProvider } from './chunk-FDONJASN.mjs';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { useRouter } from 'next/navigation';
|
|
4
|
+
import NextImage from 'next/image';
|
|
4
5
|
import { jsx } from 'react/jsx-runtime';
|
|
5
6
|
|
|
6
7
|
function NextLinkAdapter({ children, ...props }) {
|
|
@@ -21,6 +22,29 @@ function useNextNavigationAdapter() {
|
|
|
21
22
|
}
|
|
22
23
|
};
|
|
23
24
|
}
|
|
25
|
+
function NNextImage({
|
|
26
|
+
src,
|
|
27
|
+
fallbackSrc,
|
|
28
|
+
loading,
|
|
29
|
+
priority,
|
|
30
|
+
onError,
|
|
31
|
+
...props
|
|
32
|
+
}) {
|
|
33
|
+
const chain = useImageChain(normalizeImageSources([src, fallbackSrc]));
|
|
34
|
+
return /* @__PURE__ */ jsx(
|
|
35
|
+
NextImage,
|
|
36
|
+
{
|
|
37
|
+
...props,
|
|
38
|
+
priority,
|
|
39
|
+
loading: loading ?? (priority ? void 0 : "lazy"),
|
|
40
|
+
src: chain.src ?? src,
|
|
41
|
+
onError: (event) => {
|
|
42
|
+
chain.markFailed();
|
|
43
|
+
onError?.(event);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
);
|
|
47
|
+
}
|
|
24
48
|
var DEFAULT_THEME_ENDPOINT = "/api/ui-theme";
|
|
25
49
|
var DEFAULT_TIME_ZONE_ENDPOINT = "/api/ui-timezone";
|
|
26
50
|
async function postPreference(endpoint, body) {
|
|
@@ -68,4 +92,4 @@ function NajmNextUIProvider({
|
|
|
68
92
|
);
|
|
69
93
|
}
|
|
70
94
|
|
|
71
|
-
export { NajmNextUIProvider, NextLinkAdapter, useNextNavigationAdapter };
|
|
95
|
+
export { NNextImage, NajmNextUIProvider, NextLinkAdapter, useNextNavigationAdapter };
|
|
@@ -3,6 +3,76 @@ import * as React2 from 'react';
|
|
|
3
3
|
import React2__default from 'react';
|
|
4
4
|
import { jsx } from 'react/jsx-runtime';
|
|
5
5
|
|
|
6
|
+
// src/components/Badge/status.ts
|
|
7
|
+
var NAJM_STATUS_COLORS = {
|
|
8
|
+
active: "success",
|
|
9
|
+
approved: "success",
|
|
10
|
+
completed: "success",
|
|
11
|
+
confirmed: "success",
|
|
12
|
+
delivered: "success",
|
|
13
|
+
paid: "success",
|
|
14
|
+
published: "success",
|
|
15
|
+
succeeded: "success",
|
|
16
|
+
validated: "success",
|
|
17
|
+
verified: "success",
|
|
18
|
+
in_preparation: "warning",
|
|
19
|
+
in_progress: "warning",
|
|
20
|
+
out_for_delivery: "warning",
|
|
21
|
+
pending: "warning",
|
|
22
|
+
pending_email_verification: "warning",
|
|
23
|
+
pending_review: "warning",
|
|
24
|
+
processing: "warning",
|
|
25
|
+
submitted: "warning",
|
|
26
|
+
paused: "info",
|
|
27
|
+
purchased: "info",
|
|
28
|
+
scheduled: "info",
|
|
29
|
+
archived: "neutral",
|
|
30
|
+
cancelled: "neutral",
|
|
31
|
+
canceled: "neutral",
|
|
32
|
+
closed: "neutral",
|
|
33
|
+
draft: "neutral",
|
|
34
|
+
inactive: "neutral",
|
|
35
|
+
stopped: "neutral",
|
|
36
|
+
unknown: "neutral",
|
|
37
|
+
blocked: "destructive",
|
|
38
|
+
expired: "destructive",
|
|
39
|
+
failed: "destructive",
|
|
40
|
+
refunded: "destructive",
|
|
41
|
+
rejected: "destructive",
|
|
42
|
+
suspended: "destructive"
|
|
43
|
+
};
|
|
44
|
+
var NAJM_COLOR_TEXT_CLASSES = {
|
|
45
|
+
primary: "text-primary",
|
|
46
|
+
secondary: "text-secondary-foreground",
|
|
47
|
+
accent: "text-accent-foreground",
|
|
48
|
+
neutral: "text-muted-foreground",
|
|
49
|
+
info: "text-info",
|
|
50
|
+
success: "text-success",
|
|
51
|
+
warning: "text-warning",
|
|
52
|
+
destructive: "text-destructive"
|
|
53
|
+
};
|
|
54
|
+
function normalizeStatusToken(status) {
|
|
55
|
+
return status.trim().toLowerCase().replace(/[\s-]+/g, "_");
|
|
56
|
+
}
|
|
57
|
+
function lookup(map, status, normalized) {
|
|
58
|
+
if (!map) return void 0;
|
|
59
|
+
return map[status] ?? map[normalized];
|
|
60
|
+
}
|
|
61
|
+
function findStatusColor(status, statusMap) {
|
|
62
|
+
if (!status) return void 0;
|
|
63
|
+
const normalized = normalizeStatusToken(status);
|
|
64
|
+
return lookup(statusMap, status, normalized) ?? lookup(NAJM_STATUS_COLORS, status, normalized);
|
|
65
|
+
}
|
|
66
|
+
function resolveStatusColor(status, statusMap, fallback = "neutral") {
|
|
67
|
+
return findStatusColor(status, statusMap) ?? fallback;
|
|
68
|
+
}
|
|
69
|
+
function colorTextClass(color) {
|
|
70
|
+
return NAJM_COLOR_TEXT_CLASSES[color] ?? "text-foreground";
|
|
71
|
+
}
|
|
72
|
+
function statusTextClass(status, statusMap, fallback) {
|
|
73
|
+
const color = findStatusColor(status, statusMap) ?? fallback;
|
|
74
|
+
return color ? colorTextClass(color) : "";
|
|
75
|
+
}
|
|
6
76
|
var NTableDefaultsContext = React2__default.createContext({});
|
|
7
77
|
function NTableDefaultsProvider({
|
|
8
78
|
children,
|
|
@@ -190,12 +260,41 @@ function NajmDesignEditorProvider({
|
|
|
190
260
|
}
|
|
191
261
|
function noop() {
|
|
192
262
|
}
|
|
263
|
+
var NBadgeDefaultsContext = React2.createContext(null);
|
|
264
|
+
function NBadgeDefaultsProvider({
|
|
265
|
+
defaults,
|
|
266
|
+
t,
|
|
267
|
+
children
|
|
268
|
+
}) {
|
|
269
|
+
const value = React2.useMemo(
|
|
270
|
+
() => ({ defaults, t }),
|
|
271
|
+
[defaults, t]
|
|
272
|
+
);
|
|
273
|
+
return /* @__PURE__ */ jsx(NBadgeDefaultsContext.Provider, { value, children });
|
|
274
|
+
}
|
|
275
|
+
function useNBadgeDefaults() {
|
|
276
|
+
return React2.useContext(NBadgeDefaultsContext);
|
|
277
|
+
}
|
|
278
|
+
function resolveBadgeStatusLabel(status, defaults, t) {
|
|
279
|
+
if (!defaults) return void 0;
|
|
280
|
+
const normalized = normalizeStatusToken(status);
|
|
281
|
+
const literal = defaults.statusLabels?.[status] ?? defaults.statusLabels?.[normalized];
|
|
282
|
+
if (literal !== void 0) return literal;
|
|
283
|
+
const key = defaults.statusLabelKeys?.[status] ?? defaults.statusLabelKeys?.[normalized];
|
|
284
|
+
return key !== void 0 && t ? t(key) : void 0;
|
|
285
|
+
}
|
|
286
|
+
function mergeBadgeMaps(base, overrides) {
|
|
287
|
+
if (!base) return overrides;
|
|
288
|
+
if (!overrides) return base;
|
|
289
|
+
return { ...base, ...overrides };
|
|
290
|
+
}
|
|
193
291
|
function NajmUICore({
|
|
194
292
|
children,
|
|
195
293
|
className,
|
|
196
294
|
t,
|
|
197
295
|
paginationKeyPrefix = DEFAULT_PAGINATION_KEY_PREFIX,
|
|
198
|
-
tableDefaults
|
|
296
|
+
tableDefaults,
|
|
297
|
+
badgeDefaults
|
|
199
298
|
}) {
|
|
200
299
|
const { theme } = useNajmTheme();
|
|
201
300
|
const design = useNajmDesignEditor()?.design ?? EMPTY_DESIGN;
|
|
@@ -211,7 +310,7 @@ function NajmUICore({
|
|
|
211
310
|
config: design,
|
|
212
311
|
mode: theme,
|
|
213
312
|
className: cn("min-h-full", className),
|
|
214
|
-
children: /* @__PURE__ */ jsx(NTableDefaultsProvider, { value: defaults, children })
|
|
313
|
+
children: /* @__PURE__ */ jsx(NTableDefaultsProvider, { value: defaults, children: /* @__PURE__ */ jsx(NBadgeDefaultsProvider, { defaults: badgeDefaults, t, children }) })
|
|
215
314
|
}
|
|
216
315
|
);
|
|
217
316
|
}
|
|
@@ -223,6 +322,7 @@ function NajmUIProvider({
|
|
|
223
322
|
t,
|
|
224
323
|
paginationKeyPrefix,
|
|
225
324
|
tableDefaults,
|
|
325
|
+
badgeDefaults,
|
|
226
326
|
initialTheme,
|
|
227
327
|
initialTimeZone,
|
|
228
328
|
onThemeChange,
|
|
@@ -237,6 +337,7 @@ function NajmUIProvider({
|
|
|
237
337
|
t,
|
|
238
338
|
paginationKeyPrefix,
|
|
239
339
|
tableDefaults,
|
|
340
|
+
badgeDefaults,
|
|
240
341
|
children
|
|
241
342
|
}
|
|
242
343
|
) });
|
|
@@ -254,4 +355,63 @@ function NajmUIProvider({
|
|
|
254
355
|
);
|
|
255
356
|
}
|
|
256
357
|
|
|
257
|
-
|
|
358
|
+
// src/lib/imageSource.ts
|
|
359
|
+
var INLINE_SOURCE = /^(?:data|blob):/i;
|
|
360
|
+
function withSrcVersion(src, version) {
|
|
361
|
+
if (version === null || version === void 0 || version === "") return src;
|
|
362
|
+
if (INLINE_SOURCE.test(src)) return src;
|
|
363
|
+
const separator = src.includes("?") ? "&" : "?";
|
|
364
|
+
return `${src}${separator}v=${encodeURIComponent(String(version))}`;
|
|
365
|
+
}
|
|
366
|
+
function normalizeImageSources(candidates, version) {
|
|
367
|
+
const sources = [];
|
|
368
|
+
for (const candidate of candidates) {
|
|
369
|
+
const trimmed = candidate?.trim();
|
|
370
|
+
if (!trimmed) continue;
|
|
371
|
+
const stamped = withSrcVersion(trimmed, version);
|
|
372
|
+
if (!sources.includes(stamped)) sources.push(stamped);
|
|
373
|
+
}
|
|
374
|
+
return sources;
|
|
375
|
+
}
|
|
376
|
+
function selectImageSource(sources, failed) {
|
|
377
|
+
return sources.find((source) => !failed.includes(source));
|
|
378
|
+
}
|
|
379
|
+
var NO_FAILURES = [];
|
|
380
|
+
function useImageChain(sources) {
|
|
381
|
+
const key = JSON.stringify(sources);
|
|
382
|
+
const [state, setState] = React2.useState(() => ({
|
|
383
|
+
key,
|
|
384
|
+
failed: NO_FAILURES,
|
|
385
|
+
loaded: null
|
|
386
|
+
}));
|
|
387
|
+
const fresh = { key, failed: NO_FAILURES, loaded: null };
|
|
388
|
+
const current = state.key === key ? state : fresh;
|
|
389
|
+
if (state.key !== key) setState(fresh);
|
|
390
|
+
const active = selectImageSource(sources, current.failed);
|
|
391
|
+
const markLoaded = React2.useCallback(() => {
|
|
392
|
+
if (active === void 0) return;
|
|
393
|
+
setState(
|
|
394
|
+
(prev) => prev.key !== key || prev.loaded === active ? prev : { ...prev, loaded: active }
|
|
395
|
+
);
|
|
396
|
+
}, [key, active]);
|
|
397
|
+
const markFailed = React2.useCallback(() => {
|
|
398
|
+
if (active === void 0) return;
|
|
399
|
+
setState((prev) => {
|
|
400
|
+
if (prev.key !== key || prev.failed.includes(active)) return prev;
|
|
401
|
+
return {
|
|
402
|
+
...prev,
|
|
403
|
+
failed: [...prev.failed, active],
|
|
404
|
+
loaded: prev.loaded === active ? null : prev.loaded
|
|
405
|
+
};
|
|
406
|
+
});
|
|
407
|
+
}, [key, active]);
|
|
408
|
+
return {
|
|
409
|
+
src: active ?? sources[sources.length - 1],
|
|
410
|
+
exhausted: sources.length > 0 && active === void 0,
|
|
411
|
+
loaded: active !== void 0 && current.loaded === active,
|
|
412
|
+
markLoaded,
|
|
413
|
+
markFailed
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
export { DEFAULT_PAGINATION_KEY_PREFIX, DEFAULT_TIME_ZONE, EMPTY_DESIGN, NAJM_COLOR_TEXT_CLASSES, NAJM_STATUS_COLORS, NTableDefaultsProvider, NajmDesignEditorProvider, NajmPreferencesProvider, NajmUIProvider, buildPaginationLabels, colorTextClass, findStatusColor, mergeBadgeMaps, normalizeImageSources, normalizeStatusToken, resolveBadgeStatusLabel, resolveStatusColor, statusTextClass, useImageChain, useNBadgeDefaults, useNTableDefaults, useNajmDesignEditor, useNajmPreferencesContext, useNajmTheme, useNajmTimeZone, useResolvedPaginationLabels };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useNajmPreferencesContext } from './chunk-
|
|
1
|
+
import { useNajmPreferencesContext } from './chunk-FDONJASN.mjs';
|
|
2
2
|
import { humanizeToken, DEFAULT_PLACEHOLDER, formatRelativeTime, formatTime, formatDateTime, formatDate, formatPercent, formatNumber, formatCurrency } from './chunk-JABLSOQN.mjs';
|
|
3
3
|
import * as React2 from 'react';
|
|
4
4
|
import { createContext, useContext, useMemo, useState, useCallback } from 'react';
|