najm-kit 2.8.0 → 2.8.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 +9 -0
- package/README.md +37 -2
- package/dist/adapters/app.d.ts +8 -2
- package/dist/adapters/app.mjs +7 -4
- package/dist/chunk-GHMR45H3.mjs +333 -0
- package/dist/{NBrandingContext-dkADu8JS.d.ts → formFill-BcH-m9Kf.d.ts} +16 -1
- package/dist/index.d.ts +11 -7
- package/dist/index.mjs +42 -9
- package/package.json +1 -1
- package/dist/chunk-PCPMAEKP.mjs +0 -116
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 2.8.1 - 2026-08-08
|
|
4
|
+
|
|
5
|
+
- Added schema-driven form development tools to `NajmAppProvider`. Passing
|
|
6
|
+
`formDevTools` enables F8 filling for every `NForm` and `WizardForm` without
|
|
7
|
+
an application helper or additional provider.
|
|
8
|
+
- Added built-in Zod 4 form-value generation with per-form overrides for
|
|
9
|
+
relation fields and other application-owned values. Existing explicit
|
|
10
|
+
`devTools.enabled` and `devTools.fill` usage remains supported.
|
|
11
|
+
|
|
3
12
|
## 2.8.0 - 2026-08-08
|
|
4
13
|
|
|
5
14
|
- Added server-safe `najm-kit/format` helpers for currency minor units,
|
package/README.md
CHANGED
|
@@ -123,7 +123,7 @@ Changing the state updates the complete theme immediately. Use
|
|
|
123
123
|
`stringifyNajmThemeConfig(theme)` when persisting it, and parse settings loaded
|
|
124
124
|
from an API or local storage with `parseNajmThemeConfig` before applying them.
|
|
125
125
|
|
|
126
|
-
## Components
|
|
126
|
+
## Components
|
|
127
127
|
|
|
128
128
|
Import from `najm-kit`:
|
|
129
129
|
|
|
@@ -145,7 +145,42 @@ import { Form, FormInput, useNForm } from 'najm-kit';
|
|
|
145
145
|
| Feedback | Alert, Badge, Progress, Spinner, Toast |
|
|
146
146
|
| Layout | Card, Sheet, Dialog, Popover, DropdownMenu, Tabs |
|
|
147
147
|
| Data | Table (NTable), StatCard, DetailList |
|
|
148
|
-
| Overlays | Command palette, Tooltip, Toast |
|
|
148
|
+
| Overlays | Command palette, Tooltip, Toast |
|
|
149
|
+
|
|
150
|
+
## Global form development tools
|
|
151
|
+
|
|
152
|
+
Enable schema-driven test values once on the full application provider. Every
|
|
153
|
+
`NForm` and `WizardForm` below it then fills from its Zod schema when F8 is
|
|
154
|
+
pressed; applications do not need a second provider or a form-fill helper.
|
|
155
|
+
|
|
156
|
+
```tsx
|
|
157
|
+
import { NajmAppProvider } from "najm-kit/app";
|
|
158
|
+
|
|
159
|
+
<NajmAppProvider formDevTools>
|
|
160
|
+
<App />
|
|
161
|
+
</NajmAppProvider>;
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Pass a boolean to control it from application settings:
|
|
165
|
+
|
|
166
|
+
```tsx
|
|
167
|
+
<NajmAppProvider formDevTools={formFillEnabled}>
|
|
168
|
+
<App />
|
|
169
|
+
</NajmAppProvider>
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Forms with live relation options can override only those fields. The provider
|
|
173
|
+
still owns enablement and Najm Kit still owns schema traversal and generation.
|
|
174
|
+
|
|
175
|
+
```tsx
|
|
176
|
+
<NForm
|
|
177
|
+
schema={orderSchema}
|
|
178
|
+
devTools={{ overrides: { customerId: customerOptions } }}
|
|
179
|
+
onSubmit={saveOrder}
|
|
180
|
+
>
|
|
181
|
+
{/* fields */}
|
|
182
|
+
</NForm>
|
|
183
|
+
```
|
|
149
184
|
|
|
150
185
|
## ImageInput and AvatarInput
|
|
151
186
|
|
package/dist/adapters/app.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { Translations } from 'najm-i18n';
|
|
3
|
-
import { N as NBrandingInput } from '../
|
|
3
|
+
import { F as FormDevToolsOptions, N as NBrandingInput } from '../formFill-BcH-m9Kf.js';
|
|
4
4
|
import { NajmNextUIProviderProps } from './next.js';
|
|
5
5
|
import 'react';
|
|
6
|
+
import 'zod';
|
|
6
7
|
import '../NajmUIProvider-BSbXaqak.js';
|
|
7
8
|
import '../paginationLabels-dZLSNxfo.js';
|
|
8
9
|
|
|
@@ -13,6 +14,11 @@ interface NajmAppBranding {
|
|
|
13
14
|
logoCollapsed?: string | null;
|
|
14
15
|
}
|
|
15
16
|
interface NajmAppProviderProps extends Omit<NajmNextUIProviderProps, 't'> {
|
|
17
|
+
/**
|
|
18
|
+
* Enables schema-driven form filling for every `NForm` and `WizardForm`.
|
|
19
|
+
* `true` uses F8; an options object can choose another shortcut.
|
|
20
|
+
*/
|
|
21
|
+
formDevTools?: boolean | FormDevToolsOptions;
|
|
16
22
|
/**
|
|
17
23
|
* Catalog for `najm-i18n`. Supplying it mounts an `I18nProvider` and derives
|
|
18
24
|
* the pagination labels from it, so `t` is not a prop here — the provider
|
|
@@ -99,6 +105,6 @@ interface NajmAppProviderProps extends Omit<NajmNextUIProviderProps, 't'> {
|
|
|
99
105
|
* state machine of its own above this provider. The controlled `design` and
|
|
100
106
|
* `branding` props still work for applications that already do.
|
|
101
107
|
*/
|
|
102
|
-
declare function NajmAppProvider({ translations, initialLanguage, defaultLanguage, languageEndpoint, appName, initialBranding, ...props }: NajmAppProviderProps): react_jsx_runtime.JSX.Element;
|
|
108
|
+
declare function NajmAppProvider({ translations, initialLanguage, defaultLanguage, languageEndpoint, appName, initialBranding, formDevTools, ...props }: NajmAppProviderProps): react_jsx_runtime.JSX.Element;
|
|
103
109
|
|
|
104
110
|
export { type NajmAppBranding, NajmAppProvider, type NajmAppProviderProps };
|
package/dist/adapters/app.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { NBrandingStateProvider, NajmFormatProvider } from '../chunk-
|
|
2
|
+
import { FormDevToolsProvider, NBrandingStateProvider, NajmFormatProvider } from '../chunk-GHMR45H3.mjs';
|
|
3
3
|
import { NajmNextUIProvider } from '../chunk-IRFFSAO2.mjs';
|
|
4
4
|
import '../chunk-USZUOJMK.mjs';
|
|
5
5
|
import '../chunk-KVZACF4G.mjs';
|
|
@@ -72,6 +72,7 @@ function NajmAppProvider({
|
|
|
72
72
|
languageEndpoint = DEFAULT_LANGUAGE_ENDPOINT,
|
|
73
73
|
appName,
|
|
74
74
|
initialBranding,
|
|
75
|
+
formDevTools,
|
|
75
76
|
...props
|
|
76
77
|
}) {
|
|
77
78
|
const persistLanguage = React.useCallback(
|
|
@@ -91,8 +92,10 @@ function NajmAppProvider({
|
|
|
91
92
|
[languageEndpoint]
|
|
92
93
|
);
|
|
93
94
|
const seeded = appName ? { appName, ...initialBranding } : initialBranding;
|
|
94
|
-
if (!translations)
|
|
95
|
-
|
|
95
|
+
if (!translations) {
|
|
96
|
+
return /* @__PURE__ */ jsx(FormDevToolsProvider, { value: formDevTools, children: /* @__PURE__ */ jsx(NajmAppNoI18n, { ...props, initialBranding: seeded }) });
|
|
97
|
+
}
|
|
98
|
+
return /* @__PURE__ */ jsx(FormDevToolsProvider, { value: formDevTools, children: /* @__PURE__ */ jsx(
|
|
96
99
|
I18nProvider,
|
|
97
100
|
{
|
|
98
101
|
translations,
|
|
@@ -101,7 +104,7 @@ function NajmAppProvider({
|
|
|
101
104
|
onLanguageChange: persistLanguage,
|
|
102
105
|
children: /* @__PURE__ */ jsx(NajmAppUI, { ...props, initialBranding: seeded })
|
|
103
106
|
}
|
|
104
|
-
);
|
|
107
|
+
) });
|
|
105
108
|
}
|
|
106
109
|
|
|
107
110
|
export { NajmAppProvider };
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
import { useNajmPreferencesContext } from './chunk-USZUOJMK.mjs';
|
|
2
|
+
import { humanizeToken, DEFAULT_PLACEHOLDER, formatRelativeTime, formatTime, formatDateTime, formatDate, formatPercent, formatNumber, formatCurrency } from './chunk-JABLSOQN.mjs';
|
|
3
|
+
import * as React2 from 'react';
|
|
4
|
+
import { createContext, useContext, useMemo, useState, useCallback } from 'react';
|
|
5
|
+
import { jsx } from 'react/jsx-runtime';
|
|
6
|
+
|
|
7
|
+
function normalizeBranding(input) {
|
|
8
|
+
if (!input) return {};
|
|
9
|
+
const value = {};
|
|
10
|
+
const expanded = input.logoExpanded ?? input.sidebarLogoExpandedPath;
|
|
11
|
+
const collapsed = input.logoCollapsed ?? input.sidebarLogoCollapsedPath;
|
|
12
|
+
if (input.appName !== void 0) value.appName = input.appName;
|
|
13
|
+
if (input.logoFallback !== void 0) value.logoFallback = input.logoFallback;
|
|
14
|
+
if (input.logoHref !== void 0) value.logoHref = input.logoHref;
|
|
15
|
+
if (expanded !== void 0) value.logoExpanded = expanded;
|
|
16
|
+
if (collapsed !== void 0) value.logoCollapsed = collapsed;
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
var NBrandingContext = createContext(null);
|
|
20
|
+
function useNBranding() {
|
|
21
|
+
return useContext(NBrandingContext);
|
|
22
|
+
}
|
|
23
|
+
function NBrandingProvider({
|
|
24
|
+
children,
|
|
25
|
+
appName,
|
|
26
|
+
logoExpanded,
|
|
27
|
+
logoCollapsed,
|
|
28
|
+
logoFallback,
|
|
29
|
+
logoHref
|
|
30
|
+
}) {
|
|
31
|
+
const value = useMemo(
|
|
32
|
+
() => ({ appName, logoExpanded, logoCollapsed, logoFallback, logoHref }),
|
|
33
|
+
[appName, logoExpanded, logoCollapsed, logoFallback, logoHref]
|
|
34
|
+
);
|
|
35
|
+
return /* @__PURE__ */ jsx(NBrandingContext.Provider, { value, children });
|
|
36
|
+
}
|
|
37
|
+
var NBrandingEditorContext = createContext(null);
|
|
38
|
+
function useNBrandingEditor() {
|
|
39
|
+
return useContext(NBrandingEditorContext);
|
|
40
|
+
}
|
|
41
|
+
function NBrandingStateProvider({
|
|
42
|
+
children,
|
|
43
|
+
branding,
|
|
44
|
+
initialBranding
|
|
45
|
+
}) {
|
|
46
|
+
const [state, setState] = useState(
|
|
47
|
+
() => normalizeBranding(initialBranding ?? branding)
|
|
48
|
+
);
|
|
49
|
+
const setBranding = useCallback((patch) => {
|
|
50
|
+
const marks = normalizeBranding(patch);
|
|
51
|
+
setState((current) => ({ ...current, ...marks }));
|
|
52
|
+
}, []);
|
|
53
|
+
const controlled = useMemo(
|
|
54
|
+
() => branding ? normalizeBranding(branding) : void 0,
|
|
55
|
+
[branding]
|
|
56
|
+
);
|
|
57
|
+
const resolved = controlled ?? state;
|
|
58
|
+
const editor = useMemo(
|
|
59
|
+
() => ({ branding: resolved, setBranding: branding ? noop : setBranding }),
|
|
60
|
+
[resolved, branding, setBranding]
|
|
61
|
+
);
|
|
62
|
+
return /* @__PURE__ */ jsx(NBrandingEditorContext.Provider, { value: editor, children: /* @__PURE__ */ jsx(NBrandingProvider, { ...resolved, children }) });
|
|
63
|
+
}
|
|
64
|
+
function noop() {
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// src/components/form/formFill.ts
|
|
68
|
+
var CITIES = ["Casablanca", "Rabat", "Marrakesh", "Tangier"];
|
|
69
|
+
var SCHOOL_LEVELS = ["Primary", "Middle school", "Secondary school"];
|
|
70
|
+
var CLOTHING_SIZES = ["6 years", "8 years", "10 years", "12 years"];
|
|
71
|
+
function pick(values) {
|
|
72
|
+
if (values.length === 0) return void 0;
|
|
73
|
+
return values[Math.floor(Math.random() * values.length)];
|
|
74
|
+
}
|
|
75
|
+
function randomDigits(length) {
|
|
76
|
+
return Array.from({ length }, () => Math.floor(Math.random() * 10)).join("");
|
|
77
|
+
}
|
|
78
|
+
function randomToken(length = 8) {
|
|
79
|
+
const alphabet = "abcdefghijklmnopqrstuvwxyz0123456789";
|
|
80
|
+
return Array.from(
|
|
81
|
+
{ length },
|
|
82
|
+
() => alphabet[Math.floor(Math.random() * alphabet.length)]
|
|
83
|
+
).join("");
|
|
84
|
+
}
|
|
85
|
+
function asZodLike(schema) {
|
|
86
|
+
return schema && typeof schema === "object" ? schema : void 0;
|
|
87
|
+
}
|
|
88
|
+
function definition(schema) {
|
|
89
|
+
const current = asZodLike(schema);
|
|
90
|
+
return current?._def ?? current?.def ?? {};
|
|
91
|
+
}
|
|
92
|
+
function schemaKind(schema) {
|
|
93
|
+
const currentDefinition = definition(schema);
|
|
94
|
+
const raw = currentDefinition.typeName ?? currentDefinition.type;
|
|
95
|
+
if (typeof raw !== "string") return "";
|
|
96
|
+
return raw.replace(/^Zod/, "").toLowerCase();
|
|
97
|
+
}
|
|
98
|
+
function unwrap(schema) {
|
|
99
|
+
const seen = /* @__PURE__ */ new Set();
|
|
100
|
+
let current = asZodLike(schema);
|
|
101
|
+
while (current && !seen.has(current)) {
|
|
102
|
+
seen.add(current);
|
|
103
|
+
const kind = schemaKind(current);
|
|
104
|
+
const currentDefinition = definition(current);
|
|
105
|
+
const inner = currentDefinition.innerType ?? currentDefinition.schema ?? (kind === "pipe" ? currentDefinition.out ?? currentDefinition.in : void 0);
|
|
106
|
+
if (!inner || typeof inner !== "object") break;
|
|
107
|
+
current = inner;
|
|
108
|
+
}
|
|
109
|
+
return current;
|
|
110
|
+
}
|
|
111
|
+
function objectShape(schema) {
|
|
112
|
+
const current = unwrap(schema);
|
|
113
|
+
if (schemaKind(current) !== "object") return null;
|
|
114
|
+
const shape = current?.shape ?? definition(current).shape;
|
|
115
|
+
return typeof shape === "function" ? shape() : shape ?? null;
|
|
116
|
+
}
|
|
117
|
+
function arrayElement(schema) {
|
|
118
|
+
const current = unwrap(schema);
|
|
119
|
+
if (schemaKind(current) !== "array") return null;
|
|
120
|
+
const currentDefinition = definition(current);
|
|
121
|
+
const element = current?.element ?? currentDefinition.element ?? currentDefinition.type;
|
|
122
|
+
return element && typeof element === "object" ? element : null;
|
|
123
|
+
}
|
|
124
|
+
function enumValues(schema) {
|
|
125
|
+
const current = unwrap(schema);
|
|
126
|
+
const currentDefinition = definition(current);
|
|
127
|
+
const kind = schemaKind(current);
|
|
128
|
+
if (kind === "literal") {
|
|
129
|
+
const values2 = currentDefinition.values;
|
|
130
|
+
if (Array.isArray(values2)) return values2;
|
|
131
|
+
return "value" in currentDefinition ? [currentDefinition.value] : [];
|
|
132
|
+
}
|
|
133
|
+
if (kind !== "enum" && kind !== "nativeenum") return [];
|
|
134
|
+
const entries = currentDefinition.entries;
|
|
135
|
+
if (entries && typeof entries === "object") return Object.values(entries);
|
|
136
|
+
const values = currentDefinition.values;
|
|
137
|
+
if (Array.isArray(values)) return values;
|
|
138
|
+
return Array.isArray(current?.options) ? [...current.options] : [];
|
|
139
|
+
}
|
|
140
|
+
function stringFormat(schema) {
|
|
141
|
+
const currentDefinition = definition(unwrap(schema));
|
|
142
|
+
if (typeof currentDefinition.format === "string") return currentDefinition.format;
|
|
143
|
+
const checks = Array.isArray(currentDefinition.checks) ? currentDefinition.checks : [];
|
|
144
|
+
for (const check of checks) {
|
|
145
|
+
if (!check || typeof check !== "object") continue;
|
|
146
|
+
const value = check;
|
|
147
|
+
const format = value.format ?? value.kind;
|
|
148
|
+
if (typeof format === "string") return format;
|
|
149
|
+
}
|
|
150
|
+
return "";
|
|
151
|
+
}
|
|
152
|
+
function resolveOverride(override, fieldName) {
|
|
153
|
+
if (typeof override === "function") return override(fieldName);
|
|
154
|
+
if (Array.isArray(override)) {
|
|
155
|
+
const value = pick(override);
|
|
156
|
+
if (value && typeof value === "object" && "value" in value) {
|
|
157
|
+
return value.value;
|
|
158
|
+
}
|
|
159
|
+
return value;
|
|
160
|
+
}
|
|
161
|
+
return override;
|
|
162
|
+
}
|
|
163
|
+
function localDateInput(date = /* @__PURE__ */ new Date()) {
|
|
164
|
+
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}`;
|
|
165
|
+
}
|
|
166
|
+
function birthDate(child) {
|
|
167
|
+
const date = /* @__PURE__ */ new Date();
|
|
168
|
+
date.setFullYear(date.getFullYear() - (child ? 10 : 35));
|
|
169
|
+
return localDateInput(date);
|
|
170
|
+
}
|
|
171
|
+
function fieldValue(fieldName, schema, siblingFields) {
|
|
172
|
+
const key = fieldName.toLowerCase();
|
|
173
|
+
const current = unwrap(schema);
|
|
174
|
+
const kind = schemaKind(current);
|
|
175
|
+
const format = stringFormat(current);
|
|
176
|
+
const values = enumValues(current);
|
|
177
|
+
if (values.length) return pick(values);
|
|
178
|
+
if (kind === "boolean") return true;
|
|
179
|
+
if (kind === "number" || kind === "bigint") {
|
|
180
|
+
if (key.includes("sortorder")) return 1;
|
|
181
|
+
if (key.includes("quantity")) return 5;
|
|
182
|
+
return 10;
|
|
183
|
+
}
|
|
184
|
+
if (format === "uuid" || key.endsWith("uuid")) {
|
|
185
|
+
return "9cc2c93f-f545-4e07-9f77-f79f08a71dd5";
|
|
186
|
+
}
|
|
187
|
+
if (format === "email" || key.includes("email")) {
|
|
188
|
+
return `test-${randomToken()}@example.com`;
|
|
189
|
+
}
|
|
190
|
+
if (format === "url" || key === "image" || key.includes("imageurl") || key.endsWith("url")) {
|
|
191
|
+
return `https://picsum.photos/seed/${randomToken()}/800/600`;
|
|
192
|
+
}
|
|
193
|
+
if (key === "month") return `${localDateInput().slice(0, 7)}-01`;
|
|
194
|
+
if (key === "registrationdate") return localDateInput();
|
|
195
|
+
if (format === "date" || key.includes("dateofbirth")) {
|
|
196
|
+
const child = siblingFields.has("schoolLevel") || siblingFields.has("clothingSize");
|
|
197
|
+
return birthDate(child);
|
|
198
|
+
}
|
|
199
|
+
if (key.endsWith("id") || key.endsWith("by")) return "";
|
|
200
|
+
if (key === "name") {
|
|
201
|
+
if (siblingFields.has("sku")) return `Test product ${randomToken(4)}`;
|
|
202
|
+
if (siblingFields.has("slug")) return `Test category ${randomToken(4)}`;
|
|
203
|
+
return "Test User";
|
|
204
|
+
}
|
|
205
|
+
if (key.includes("legalname")) return "Test User";
|
|
206
|
+
if (key.includes("phone")) return `+2126${randomDigits(8)}`;
|
|
207
|
+
if (key.endsWith("cin")) return `AB${randomDigits(6)}`;
|
|
208
|
+
if (key.includes("address")) return `10 Test Street, ${pick(CITIES)}`;
|
|
209
|
+
if (key.includes("schoollevel")) return pick(SCHOOL_LEVELS);
|
|
210
|
+
if (key.includes("clothingsize")) return pick(CLOTHING_SIZES);
|
|
211
|
+
if (key.includes("shoesize")) return "36";
|
|
212
|
+
if (key.includes("relationship")) return "Legal guardian";
|
|
213
|
+
if (key.includes("activationtargetmad")) return "7500";
|
|
214
|
+
if (key === "slug") return `test-${randomToken(6)}`;
|
|
215
|
+
if (key === "sku") return `TEST-${randomToken(8).toUpperCase()}`;
|
|
216
|
+
if (key.includes("amountmad") || key.includes("pricemad") || key.includes("limitmad") || key.includes("targetmad")) {
|
|
217
|
+
return "100.00";
|
|
218
|
+
}
|
|
219
|
+
if (key.includes("reason")) return "Generated for form testing.";
|
|
220
|
+
if (key.includes("notes")) return "Generated form testing note.";
|
|
221
|
+
if (key.includes("description")) return "Generated description for form testing.";
|
|
222
|
+
if (key.includes("code")) return randomToken(8).toUpperCase();
|
|
223
|
+
return `Test ${fieldName}`;
|
|
224
|
+
}
|
|
225
|
+
function buildFormFill(schema, overrides = {}) {
|
|
226
|
+
const shape = objectShape(schema) ?? {};
|
|
227
|
+
const siblingFields = new Set(Object.keys(shape));
|
|
228
|
+
const output = {};
|
|
229
|
+
for (const [fieldName, fieldSchema] of Object.entries(shape)) {
|
|
230
|
+
if (Object.prototype.hasOwnProperty.call(overrides, fieldName)) {
|
|
231
|
+
output[fieldName] = resolveOverride(overrides[fieldName], fieldName);
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
const nestedShape = objectShape(fieldSchema);
|
|
235
|
+
if (nestedShape) {
|
|
236
|
+
output[fieldName] = buildFormFill(fieldSchema);
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
const element = arrayElement(fieldSchema);
|
|
240
|
+
if (element) {
|
|
241
|
+
output[fieldName] = objectShape(element) ? [buildFormFill(element)] : [fieldValue(fieldName, element, siblingFields)];
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
output[fieldName] = fieldValue(fieldName, fieldSchema, siblingFields);
|
|
245
|
+
}
|
|
246
|
+
return output;
|
|
247
|
+
}
|
|
248
|
+
var DEFAULT_FORM_DEV_TOOLS = {
|
|
249
|
+
enabled: false,
|
|
250
|
+
shortcut: "F8"
|
|
251
|
+
};
|
|
252
|
+
var FormDevToolsContext = createContext(
|
|
253
|
+
DEFAULT_FORM_DEV_TOOLS
|
|
254
|
+
);
|
|
255
|
+
function normalizeFormDevTools(value) {
|
|
256
|
+
if (typeof value === "boolean") {
|
|
257
|
+
return { ...DEFAULT_FORM_DEV_TOOLS, enabled: value };
|
|
258
|
+
}
|
|
259
|
+
if (!value) return DEFAULT_FORM_DEV_TOOLS;
|
|
260
|
+
return {
|
|
261
|
+
enabled: value.enabled ?? true,
|
|
262
|
+
shortcut: value.shortcut ?? DEFAULT_FORM_DEV_TOOLS.shortcut
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
function FormDevToolsProvider({
|
|
266
|
+
children,
|
|
267
|
+
value
|
|
268
|
+
}) {
|
|
269
|
+
const resolved = useMemo(
|
|
270
|
+
() => normalizeFormDevTools(value),
|
|
271
|
+
[value]
|
|
272
|
+
);
|
|
273
|
+
return /* @__PURE__ */ jsx(FormDevToolsContext.Provider, { value: resolved, children });
|
|
274
|
+
}
|
|
275
|
+
function useResolvedFormDevTools(schema, local) {
|
|
276
|
+
const global = useContext(FormDevToolsContext);
|
|
277
|
+
const options = typeof local === "object" ? local : void 0;
|
|
278
|
+
const enabled = typeof local === "boolean" ? local : options?.enabled ?? global.enabled;
|
|
279
|
+
const shortcut = options?.shortcut ?? global.shortcut;
|
|
280
|
+
const fill = options?.fill ?? (schema ? () => buildFormFill(schema, options?.overrides) : void 0);
|
|
281
|
+
return { enabled, shortcut, fill };
|
|
282
|
+
}
|
|
283
|
+
var NajmFormatContext = React2.createContext(
|
|
284
|
+
null
|
|
285
|
+
);
|
|
286
|
+
function NajmFormatProvider({
|
|
287
|
+
children,
|
|
288
|
+
locale,
|
|
289
|
+
currency,
|
|
290
|
+
timeZone,
|
|
291
|
+
placeholder = DEFAULT_PLACEHOLDER
|
|
292
|
+
}) {
|
|
293
|
+
const preferences = useNajmPreferencesContext();
|
|
294
|
+
const resolvedTimeZone = timeZone ?? preferences?.timeZone ?? Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
295
|
+
const value = React2.useMemo(() => {
|
|
296
|
+
const config = {
|
|
297
|
+
locale,
|
|
298
|
+
timeZone: resolvedTimeZone,
|
|
299
|
+
currency,
|
|
300
|
+
placeholder
|
|
301
|
+
};
|
|
302
|
+
return {
|
|
303
|
+
locale,
|
|
304
|
+
timeZone: resolvedTimeZone,
|
|
305
|
+
currency,
|
|
306
|
+
placeholder,
|
|
307
|
+
config,
|
|
308
|
+
money: (minorUnits) => formatCurrency(minorUnits, config),
|
|
309
|
+
number: (value_, options) => formatNumber(value_, config, options),
|
|
310
|
+
percent: (value_, digits) => formatPercent(value_, config, digits),
|
|
311
|
+
date: (value_, options) => formatDate(value_, config, options),
|
|
312
|
+
dateTime: (value_) => formatDateTime(value_, config),
|
|
313
|
+
time: (value_) => formatTime(value_, config),
|
|
314
|
+
relativeTime: (value_) => formatRelativeTime(value_, config),
|
|
315
|
+
humanize: humanizeToken
|
|
316
|
+
};
|
|
317
|
+
}, [locale, resolvedTimeZone, currency, placeholder]);
|
|
318
|
+
return /* @__PURE__ */ jsx(NajmFormatContext.Provider, { value, children });
|
|
319
|
+
}
|
|
320
|
+
function useNajmFormatContext() {
|
|
321
|
+
return React2.useContext(NajmFormatContext);
|
|
322
|
+
}
|
|
323
|
+
function useNajmFormat() {
|
|
324
|
+
const value = React2.useContext(NajmFormatContext);
|
|
325
|
+
if (!value) {
|
|
326
|
+
throw new Error(
|
|
327
|
+
"useNajmFormat must be rendered under a NajmFormatProvider or NajmAppProvider."
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
return value;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
export { FormDevToolsProvider, NBrandingProvider, NBrandingStateProvider, NajmFormatProvider, buildFormFill, normalizeBranding, useNBranding, useNBrandingEditor, useNajmFormat, useNajmFormatContext, useResolvedFormDevTools };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
|
+
import { ZodTypeAny, TypeOf } from 'zod';
|
|
3
4
|
|
|
4
5
|
interface NBrandingValue {
|
|
5
6
|
/** Used as the logo's `alt` when the logo does not set one. */
|
|
@@ -79,4 +80,18 @@ interface NBrandingStateProviderProps {
|
|
|
79
80
|
/** `NBrandingProvider` with the marks held as state an editor can write. */
|
|
80
81
|
declare function NBrandingStateProvider({ children, branding, initialBranding, }: Readonly<NBrandingStateProviderProps>): react_jsx_runtime.JSX.Element;
|
|
81
82
|
|
|
82
|
-
|
|
83
|
+
type FormFillOverride = unknown | readonly unknown[] | ((fieldName: string) => unknown);
|
|
84
|
+
type FormFillOverrides = Record<string, FormFillOverride>;
|
|
85
|
+
interface FormDevToolsOptions {
|
|
86
|
+
enabled?: boolean;
|
|
87
|
+
shortcut?: string;
|
|
88
|
+
}
|
|
89
|
+
interface FormDevToolsConfig<T extends ZodTypeAny = ZodTypeAny> extends FormDevToolsOptions {
|
|
90
|
+
fill?: () => Partial<TypeOf<T>>;
|
|
91
|
+
overrides?: FormFillOverrides;
|
|
92
|
+
}
|
|
93
|
+
type FormDevTools<T extends ZodTypeAny = ZodTypeAny> = boolean | FormDevToolsConfig<T>;
|
|
94
|
+
/** Build form-shaped test values from a Zod object schema. */
|
|
95
|
+
declare function buildFormFill<TSchema extends ZodTypeAny>(schema: TSchema, overrides?: FormFillOverrides): Partial<TypeOf<TSchema>>;
|
|
96
|
+
|
|
97
|
+
export { type FormDevToolsOptions as F, type NBrandingInput as N, type FormDevTools as a, type FormDevToolsConfig as b, type FormFillOverride as c, type FormFillOverrides as d, type NBrandingEditorValue as e, type NBrandingPayload as f, NBrandingProvider as g, NBrandingStateProvider as h, type NBrandingStateProviderProps as i, type NBrandingValue as j, buildFormFill as k, useNBrandingEditor as l, normalizeBranding as n, useNBranding as u };
|
package/dist/index.d.ts
CHANGED
|
@@ -22,7 +22,8 @@ import * as TooltipPrimitive from '@radix-ui/react-tooltip';
|
|
|
22
22
|
import * as ProgressPrimitive from '@radix-ui/react-progress';
|
|
23
23
|
import * as SeparatorPrimitive from '@radix-ui/react-separator';
|
|
24
24
|
import { OverlayScrollbarsComponentProps } from 'overlayscrollbars-react';
|
|
25
|
-
|
|
25
|
+
import { a as FormDevTools, F as FormDevToolsOptions } from './formFill-BcH-m9Kf.js';
|
|
26
|
+
export { b as FormDevToolsConfig, c as FormFillOverride, d as FormFillOverrides, e as NBrandingEditorValue, N as NBrandingInput, f as NBrandingPayload, g as NBrandingProvider, h as NBrandingStateProvider, i as NBrandingStateProviderProps, j as NBrandingValue, k as buildFormFill, n as normalizeBranding, u as useNBranding, l as useNBrandingEditor } from './formFill-BcH-m9Kf.js';
|
|
26
27
|
import * as AvatarPrimitive from '@radix-ui/react-avatar';
|
|
27
28
|
import { Command as Command$1 } from 'cmdk';
|
|
28
29
|
import * as CollapsiblePrimitive from '@radix-ui/react-collapsible';
|
|
@@ -2648,10 +2649,7 @@ type FormProps<T extends ZodTypeAny = ZodTypeAny> = {
|
|
|
2648
2649
|
as?: "form" | "div";
|
|
2649
2650
|
className?: string;
|
|
2650
2651
|
id?: string;
|
|
2651
|
-
devTools?:
|
|
2652
|
-
enabled?: boolean;
|
|
2653
|
-
fill?: () => Partial<TypeOf<T>>;
|
|
2654
|
-
};
|
|
2652
|
+
devTools?: FormDevTools<T>;
|
|
2655
2653
|
children: React.ReactNode;
|
|
2656
2654
|
};
|
|
2657
2655
|
|
|
@@ -2701,6 +2699,11 @@ interface UseNFormOptions<T extends ZodTypeAny> extends Omit<UseFormProps<TypeOf
|
|
|
2701
2699
|
}
|
|
2702
2700
|
declare function useNForm<T extends ZodTypeAny>(options: UseNFormOptions<T>): UseFormReturn<TypeOf<T>>;
|
|
2703
2701
|
|
|
2702
|
+
declare function FormDevToolsProvider({ children, value, }: {
|
|
2703
|
+
children: React__default.ReactNode;
|
|
2704
|
+
value?: boolean | FormDevToolsOptions;
|
|
2705
|
+
}): react_jsx_runtime.JSX.Element;
|
|
2706
|
+
|
|
2704
2707
|
interface StepConfig {
|
|
2705
2708
|
id: string;
|
|
2706
2709
|
title: string;
|
|
@@ -2741,6 +2744,7 @@ interface WizardFormProps {
|
|
|
2741
2744
|
footerSlot?: ReactNode;
|
|
2742
2745
|
footerDivider?: WizardFooterDivider;
|
|
2743
2746
|
footerDividerClassName?: string;
|
|
2747
|
+
devTools?: FormDevTools;
|
|
2744
2748
|
children?: ReactNode;
|
|
2745
2749
|
}
|
|
2746
2750
|
interface StepMeta {
|
|
@@ -2749,7 +2753,7 @@ interface StepMeta {
|
|
|
2749
2753
|
title: string;
|
|
2750
2754
|
}
|
|
2751
2755
|
|
|
2752
|
-
declare function WizardForm({ steps, schema, defaultValues, onSubmit, currentStep: controlledStep, onCurrentStepChange, onStepComplete, showHeader, showFooter, nextLabel, previousLabel, submitLabel, variant, bordered, className, classNames, footerSlot, footerDivider, footerDividerClassName, }: WizardFormProps): react_jsx_runtime.JSX.Element;
|
|
2756
|
+
declare function WizardForm({ steps, schema, defaultValues, onSubmit, currentStep: controlledStep, onCurrentStepChange, onStepComplete, showHeader, showFooter, nextLabel, previousLabel, submitLabel, variant, bordered, className, classNames, footerSlot, footerDivider, footerDividerClassName, devTools, }: WizardFormProps): react_jsx_runtime.JSX.Element;
|
|
2753
2757
|
|
|
2754
2758
|
interface StepIndicatorProps {
|
|
2755
2759
|
stepNumber: number;
|
|
@@ -4269,4 +4273,4 @@ interface NGridItemProps extends Omit<React$1.AllHTMLAttributes<HTMLDivElement>,
|
|
|
4269
4273
|
declare function NGrid({ as: Comp, children, cols, smCols, mdCols, lgCols, xlCols, gap, className, style, ...props }: NGridProps): react_jsx_runtime.JSX.Element;
|
|
4270
4274
|
declare function NGridItem({ children, span, smSpan, mdSpan, lgSpan, xlSpan, className, ...props }: NGridItemProps): react_jsx_runtime.JSX.Element;
|
|
4271
4275
|
|
|
4272
|
-
export { Alert, type AlertLook, type AlertOrientation, type AlertProps, type AlertSize, type AlertTone, type AlertVariant, NCard as AsyncCard, Avatar, AvatarFallback, AvatarFormInput, type AvatarFormInputProps, AvatarGroup, type AvatarGroupProps, AvatarImage, AvatarInput, type AvatarInputProps, type AvatarInputRadius, type AvatarProps$1 as AvatarProps, type AvatarShape$1 as AvatarShape, type AvatarSize, AvatarStatus, type AvatarStatusType, Badge, type BadgeColor, type BadgeIcon, type BadgeLook, type BadgeProps, type BadgeShape, type BadgeSize, type BadgeVariant, BaseInput, type BuildDefaultFileColumnsOptions, Button, type ButtonConfig, type ButtonIcon, type ButtonLoaderPosition, type ButtonProps, type ButtonRounded, type ButtonSize, type ButtonVariant, Calendar, Card, CardAction, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, Checkbox, CheckboxGroupInput, type CheckboxGroupInputProps, CheckboxInput, type CheckboxInputProps, Collapsible, CollapsibleContent, CollapsibleTrigger, ColorArrayInput, type ColorArrayInputProps, type ColorFormat, ColorPickerInput, type ColorPickerInputProps, Combobox, ComboboxInput, type ComboboxInputProps, type ComboboxOption, type ComboboxProps, Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut, type ContextMenuItem, DEFAULT_CARD_BREAKPOINT, DEFAULT_THEME_FILE_NAME, DateInput, type DateInputProps, type DeleteDialogOptions, Dialog, type DialogActionMode, type DialogApi, DialogClose, type DialogConfig, DialogContent, type DialogContentProps, DialogDescription, DialogFooter, DialogHeader, type DialogHeight, DialogOverlay, type DialogPadding, DialogPortal, type DialogRenderContext, type DialogRenderer, type DialogSize, type DialogStore, DialogTitle, DialogTrigger, type DialogVariant, type DialogWidth, DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, DynamicArray, type DynamicArrayProps, EMPTY_DESIGN, EmojiInput, type EmojiInputProps, type FileBrowserMode, FileImportButton, FileInput, type FileInputProps, type FileNode, Form, FormControl, FormDescription, FormField, FormInput, type FormInputBackground, type FormInputProps, FormItem, FormLabel, FormMessage, type FormProps, type FormSlotClassNames, type FormVariant, IconButton, type IconButtonProps, type IconButtonSize, type IconButtonVariant, ImageInput, type ImageInputPreviewError, type ImageInputPreviewSource, type ImageInputProps, Indicator, type IndicatorHorizontal, type IndicatorOverlay, type IndicatorPosition, type IndicatorProps, type IndicatorResponsivePosition, type IndicatorSize, type IndicatorVertical, Input, type InputIcon, Label, LangInput, type LangInputProps, type LinkComponentType, MultiSelectInput, type MultiSelectInputProps, NAJM_COLOR_TEXT_CLASSES, NAJM_SAVED_THEME_VALUE, NAJM_STATUS_COLORS, NAlert, type NAppCommandItem, NAppShell, type NAppShellAction, type NAppShellClassNames, type NAppShellProps, type NAppShellUser, NCard as NAsyncCard, type CardClassNames as NAsyncCardClassNames, type CardProps as NAsyncCardProps, NAvatar, type NAvatarClassNames, type NAvatarProps, type AvatarShape as NAvatarShape, NBadge, type NBadgeLook, type NBadgeProps, NBarChart, type NBarChartProps, type NBulkAction, type NBulkActionButton, type NBulkActionSelect, NBulkActionsBar, type NBulkActionsBarProps, NButton, type NButtonProps, NCard, NCardAction, type CardClassNames as NCardClassNames, type NCardDensity, NCardFooter, NCardInfo, type NCardInfoProps, NCardMedia, type NCardMediaAspect, type NCardMediaPlacement, type NCardMediaProps, type NCardMediaSize, type NCardMediaVariant, type CardProps as NCardProps, NCardSection, type NCardSectionProps, type NCardSectionSurface, type NCartesianChartProps, type NChartCardProps, type NChartDatum, type NChartItem, type NChartSeries, type NChartSize, NChartSkeleton, type NChartSkeletonProps, type NChartSkeletonVariant, NCommandPalette, type NCommandPaletteProps, NConfirmDialog, type NConfirmDialogProps, NContextMenu, type NContextMenuItem, type NContextMenuProps, NDataCardShell, type NDataCardShellActions, type NDataCardShellProps, NDeleteDialog, NDeleteDialogContent, type NDeleteDialogContentProps, type NDeleteDialogProps, NDetailCard, type NDetailCardClassNames, type NDetailCardProps, NDetailItem, type NDetailItemProps, NDetailList, type NDetailListItem, type NDetailListProps, NDialog, type NDialogActionProps, NDialogDescription, type NDialogDescriptionProps, type NDialogDirectProps, NDialogHeader, type NDialogHeaderProps, NDialogPrimaryButton, type NDialogProps, NDialogSecondaryButton, NDonutCard, type NDonutCardClassNames, type NDonutCardItem, type NDonutCardLayout, type NDonutCardLegendMarker, type NDonutCardProps, type NDonutCardVariant, type NEditorTab, NEditorTabs, type NEditorTabsProps, NEmptyState, type NEmptyStateProps, NErrorBoundary, NErrorState, type NErrorStateProps, NFileBrowser, type NFileBrowserCardProps, type NFileBrowserProps, type NFileBrowserRenderThumbProps, NFileTypeIcon, type NFileTypeIconProps, NFilterBar, NFolderIcon, type NFolderIconProps, NForm, NFormSectionHeader, type NFormSectionHeaderProps, NGrid, type NGridCols, NGridItem, type NGridItemProps, type NGridProps, type NGridSpan, NIcon, type NIconProps, type NIconSource, NImage, type NImageProps, NIndicator, NInspectorSheet, NLineChart, type NLineChartProps, NLoadingState, type NLoadingStateProps, NMultiDialog, type NMultiDialogProps, NNavbar, NPageHeader, NPageHeaderActions, type NPageHeaderBreakpoint, NPageHeaderCompactActions, NPageHeaderFilters, type NPageHeaderProps, NPageHeaderTop, NPageLayout, type NPageLayoutProps, NPieChart, type NPieChartProps, NPortalScopeProvider, NProgress, type NProgressProps, NRowActions, NSection, NSectionHeader, type NSectionHeaderActionsProps, type NSectionHeaderContentProps, type NSectionHeaderProps, type NSectionHeaderSubtitleProps, type NSectionHeaderTitleProps, NSectionInfo, type NSectionInfoProps, type NSectionProps, NSectionWithInfo, type NSectionWithInfoItem, type NSectionWithInfoProps, NSheet, type NSheetClassNames, type NSheetProps, NSidebar, NSidebarBrand, type NSidebarBrandProps, NSidebarContent, type NSidebarContentProps, type NSidebarContextValue, NSidebarFooter, type NSidebarFooterProps, NSidebarHeader, type NSidebarHeaderProps, NSidebarItem, NSidebarMobile, type NSidebarMobileProps, NSidebarProvider, NSidebarSection, type NSidebarSectionProps, NSkeleton, NSkeletonCalendar, NSkeletonChart, NSkeletonDonut, NSkeletonEventList, NSkeletonWidget, NSkeletonWidgets, NSlider, type NSliderProps, NSmartPasteDialog, type NSmartPasteDialogProps, NSpinner, type NSpinnerProps, NStatCard, type NStatCardClassNames, type NStatCardProps, NStatCardSkeleton, type NStatCardVariant, NStatusBreakdown, type NStatusBreakdownProps, Swap as NSwap, type NSwapProps, NTable, NTableCardPagination, NTableCardRoot, type NTableCardRootProps, NTableCards, type NTableClassNames, type NTableColumnBreakpoint, type NTableColumnDef, type NTableColumnMeta, NTableContent, NTableHeader, NTableLoadingSkeleton, type NTableMenu, type NTableMenuProp, type NTablePageItem, NTablePagination, NTablePaginationLabels, NTablePaginationVariant, type NTableProps, NTableRowSkeleton, NTableSkeleton, type NTableState, NTabs, type NTabsClassNames, type NTabsColor, type NTabsItem, type NTabsProps, type NTabsStyles, NThemeCustomizer, type NThemeCustomizerFontOption, type NThemeCustomizerLabels, type NThemeCustomizerProps, type NThemeCustomizerTab, type NThemePreset, NThemePresets, type NThemePresetsLabels, type NThemePresetsProps, type NThemePresetsStatus, NUploader, type NUploaderItem, type NUploaderItemStatus, type NUploaderProps, NViewBody, NViewToggle, NajmAccent, NajmAppearance, type NajmBorderSide, NajmComponentName, NajmComponentStyleConfig, NajmComponentThemeConfig, NajmDesignConfig, NajmDesignEditorProvider, type NajmDesignEditorProviderProps, type NajmDesignEditorValue, NajmDesignProvider, type NajmDesignProviderProps, NajmFormatConfig, type NajmFormatContextValue, NajmFormatProvider, type NajmFormatProviderProps, NajmLayoutConfig, NajmMode, NajmPreset, NajmResponsiveBreakpoint, NajmResponsiveValue, NajmScroll, type NajmScrollProps, NajmThemeConfig, NajmThemeProvider, NajmThemeProviderProps, NajmThemeTokens, NajmTypographyConfig, NajmVariantStyle, NativeSelect, type NativeSelectOption, type NativeSelectProps, type NavItem, type NavItemGroup, NumberInput, type NumberInputProps, OtpInput, type OtpInputProps, PasswordInput, type PasswordInputProps, PhoneInput, type PhoneInputProps, Popover, PopoverAnchor, PopoverContent, PopoverTrigger, PrefixProvider, Progress, type ProgressColor, type ProgressLabelPosition, type ProgressProps, type ProgressSize, type PushDialogOptions, RadioGroup, RadioGroupInput, type RadioGroupInputProps, RadioGroupItem, type RenderSlot, RepeatingFields, type RepeatingFieldsProps, ScrollArea, type ScrollAreaProps, SearchField, SearchField as SearchInput, SegmentedControl, type SegmentedControlOption, type SegmentedControlProps, Select, SelectContent, SelectGroup, SelectInput, type SelectInputProps, SelectItem, type SelectItemType$1 as SelectItemDataType, type SelectItemType, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, Separator, Sheet, SheetClose, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetOverlay, SheetPortal, SheetTitle, SheetTrigger, type SidebarItemProps, type SidebarLogo, type SidebarLogoRender, type SidebarProps, type SidebarWidth, type SidebarWidths, SimpleTooltip, type SimpleTooltipProps, NSkeleton as Skeleton, Slider, SliderInput, type SliderInputProps, type SliderOrientation, type SliderProps, type SliderSize, type SliderVariant, type SmartPastePreview, type SpinnerVariant, StarRatingInput, type StarRatingInputProps, StatusPill, type StatusPillProps, type StatusPillTone, type StepConfig, StepIndicator, type StepMeta, StepsHeader, StepsProgress, type StorageMenuAction, type StorageSortOption, type StorageTarget, Swap, type SwapEffect, SwapIndeterminate, SwapOff, SwapOn, type SwapProps, type SwapSize, type SwapState, Switch, type SwitchColor, SwitchInput, type SwitchInputProps, type SwitchSize, TAB_COLORS, Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, type TableHeaderColor, TableRow, type TableState, type TableStore, TableStoreContext, Tabs, TabsContent, TabsList, type TabsListProps, type TabsOrientation, type TabsProps, TabsTrigger, type TabsTriggerProps, type TabsVariant, TextAreaInput, type TextAreaInputProps, TextInput, type TextInputProps, Textarea, TimeInput, type TimeInputProps, TimeZoneInput, type TimeZoneInputProps, Toaster, Toggle, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, type UseContextMenuResult, type UseNFormOptions, type UseStorageContextMenuOptions, type UseStorageContextMenuResult, type UserMenuAction, VariantProvider, type WizardClassNames, WizardForm, type WizardFormProps, alertVariants, avatarVariants, badgeColorVariants, badgeVariants, buildDefaultFileColumns, buildPageItems, buttonVariants, cn, colorTextClass, composePreset, createDialogStore, createTableStore, defineNajmDesignConfig, defineNajmThemeConfig, detectFormat, dialogVariants, filterResponsiveColumns, findStatusColor, formatColor, formatFileBytes, formatFileRelative, getIconColorProps, getNChartColor, getNextEditorTabValue, hiddenBelowClasses, indicatorVariants, inputBorderClasses, isPlaceholderAvatar, normalizeThemeFileName, parseColor, parseNajmDesignConfig, parseNajmThemeConfig, parseThemeFile, resolveAvatarSrc, resolveHiddenBelowClass, resolvePreset, resolveSlot, resolveStatusColor, resolveVariantAlias, sidebarBorderClasses, sliderVariants, statusTextClass, stringifyNajmDesignConfig, stringifyNajmThemeConfig, stringifyThemeFile, surfaceBorderClasses, swapVariants, toPickerHex, toggleVariants, tooltipContentVariants, truncateByCharacters, useCardViewport, useClickOutside, useContextMenu, useDebouncedValue, useDelayedLoading, useDesktopTableMode, useDialog, useDialogStore, useDynamicPageSize, useFormField, useFormSubmission, useInfiniteScroll, useKeyboard, useLocalStorageState, useMediaQuery, useNForm, useNPortalScope, useNSidebar, useNajmAppearance, useNajmComponentStyle, useNajmDesign, useNajmDesignEditor, useNajmFormat, useNajmFormatContext, useNajmThemeMode, usePrefix, useSelection, useStepNavigation, useStorageContextMenu, useStoreSync, useTable, useTableKeyboard, useTableStore, useVariant, useVariantPreset };
|
|
4276
|
+
export { Alert, type AlertLook, type AlertOrientation, type AlertProps, type AlertSize, type AlertTone, type AlertVariant, NCard as AsyncCard, Avatar, AvatarFallback, AvatarFormInput, type AvatarFormInputProps, AvatarGroup, type AvatarGroupProps, AvatarImage, AvatarInput, type AvatarInputProps, type AvatarInputRadius, type AvatarProps$1 as AvatarProps, type AvatarShape$1 as AvatarShape, type AvatarSize, AvatarStatus, type AvatarStatusType, Badge, type BadgeColor, type BadgeIcon, type BadgeLook, type BadgeProps, type BadgeShape, type BadgeSize, type BadgeVariant, BaseInput, type BuildDefaultFileColumnsOptions, Button, type ButtonConfig, type ButtonIcon, type ButtonLoaderPosition, type ButtonProps, type ButtonRounded, type ButtonSize, type ButtonVariant, Calendar, Card, CardAction, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, Checkbox, CheckboxGroupInput, type CheckboxGroupInputProps, CheckboxInput, type CheckboxInputProps, Collapsible, CollapsibleContent, CollapsibleTrigger, ColorArrayInput, type ColorArrayInputProps, type ColorFormat, ColorPickerInput, type ColorPickerInputProps, Combobox, ComboboxInput, type ComboboxInputProps, type ComboboxOption, type ComboboxProps, Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut, type ContextMenuItem, DEFAULT_CARD_BREAKPOINT, DEFAULT_THEME_FILE_NAME, DateInput, type DateInputProps, type DeleteDialogOptions, Dialog, type DialogActionMode, type DialogApi, DialogClose, type DialogConfig, DialogContent, type DialogContentProps, DialogDescription, DialogFooter, DialogHeader, type DialogHeight, DialogOverlay, type DialogPadding, DialogPortal, type DialogRenderContext, type DialogRenderer, type DialogSize, type DialogStore, DialogTitle, DialogTrigger, type DialogVariant, type DialogWidth, DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, DynamicArray, type DynamicArrayProps, EMPTY_DESIGN, EmojiInput, type EmojiInputProps, type FileBrowserMode, FileImportButton, FileInput, type FileInputProps, type FileNode, Form, FormControl, FormDescription, FormDevTools, FormDevToolsOptions, FormDevToolsProvider, FormField, FormInput, type FormInputBackground, type FormInputProps, FormItem, FormLabel, FormMessage, type FormProps, type FormSlotClassNames, type FormVariant, IconButton, type IconButtonProps, type IconButtonSize, type IconButtonVariant, ImageInput, type ImageInputPreviewError, type ImageInputPreviewSource, type ImageInputProps, Indicator, type IndicatorHorizontal, type IndicatorOverlay, type IndicatorPosition, type IndicatorProps, type IndicatorResponsivePosition, type IndicatorSize, type IndicatorVertical, Input, type InputIcon, Label, LangInput, type LangInputProps, type LinkComponentType, MultiSelectInput, type MultiSelectInputProps, NAJM_COLOR_TEXT_CLASSES, NAJM_SAVED_THEME_VALUE, NAJM_STATUS_COLORS, NAlert, type NAppCommandItem, NAppShell, type NAppShellAction, type NAppShellClassNames, type NAppShellProps, type NAppShellUser, NCard as NAsyncCard, type CardClassNames as NAsyncCardClassNames, type CardProps as NAsyncCardProps, NAvatar, type NAvatarClassNames, type NAvatarProps, type AvatarShape as NAvatarShape, NBadge, type NBadgeLook, type NBadgeProps, NBarChart, type NBarChartProps, type NBulkAction, type NBulkActionButton, type NBulkActionSelect, NBulkActionsBar, type NBulkActionsBarProps, NButton, type NButtonProps, NCard, NCardAction, type CardClassNames as NCardClassNames, type NCardDensity, NCardFooter, NCardInfo, type NCardInfoProps, NCardMedia, type NCardMediaAspect, type NCardMediaPlacement, type NCardMediaProps, type NCardMediaSize, type NCardMediaVariant, type CardProps as NCardProps, NCardSection, type NCardSectionProps, type NCardSectionSurface, type NCartesianChartProps, type NChartCardProps, type NChartDatum, type NChartItem, type NChartSeries, type NChartSize, NChartSkeleton, type NChartSkeletonProps, type NChartSkeletonVariant, NCommandPalette, type NCommandPaletteProps, NConfirmDialog, type NConfirmDialogProps, NContextMenu, type NContextMenuItem, type NContextMenuProps, NDataCardShell, type NDataCardShellActions, type NDataCardShellProps, NDeleteDialog, NDeleteDialogContent, type NDeleteDialogContentProps, type NDeleteDialogProps, NDetailCard, type NDetailCardClassNames, type NDetailCardProps, NDetailItem, type NDetailItemProps, NDetailList, type NDetailListItem, type NDetailListProps, NDialog, type NDialogActionProps, NDialogDescription, type NDialogDescriptionProps, type NDialogDirectProps, NDialogHeader, type NDialogHeaderProps, NDialogPrimaryButton, type NDialogProps, NDialogSecondaryButton, NDonutCard, type NDonutCardClassNames, type NDonutCardItem, type NDonutCardLayout, type NDonutCardLegendMarker, type NDonutCardProps, type NDonutCardVariant, type NEditorTab, NEditorTabs, type NEditorTabsProps, NEmptyState, type NEmptyStateProps, NErrorBoundary, NErrorState, type NErrorStateProps, NFileBrowser, type NFileBrowserCardProps, type NFileBrowserProps, type NFileBrowserRenderThumbProps, NFileTypeIcon, type NFileTypeIconProps, NFilterBar, NFolderIcon, type NFolderIconProps, NForm, NFormSectionHeader, type NFormSectionHeaderProps, NGrid, type NGridCols, NGridItem, type NGridItemProps, type NGridProps, type NGridSpan, NIcon, type NIconProps, type NIconSource, NImage, type NImageProps, NIndicator, NInspectorSheet, NLineChart, type NLineChartProps, NLoadingState, type NLoadingStateProps, NMultiDialog, type NMultiDialogProps, NNavbar, NPageHeader, NPageHeaderActions, type NPageHeaderBreakpoint, NPageHeaderCompactActions, NPageHeaderFilters, type NPageHeaderProps, NPageHeaderTop, NPageLayout, type NPageLayoutProps, NPieChart, type NPieChartProps, NPortalScopeProvider, NProgress, type NProgressProps, NRowActions, NSection, NSectionHeader, type NSectionHeaderActionsProps, type NSectionHeaderContentProps, type NSectionHeaderProps, type NSectionHeaderSubtitleProps, type NSectionHeaderTitleProps, NSectionInfo, type NSectionInfoProps, type NSectionProps, NSectionWithInfo, type NSectionWithInfoItem, type NSectionWithInfoProps, NSheet, type NSheetClassNames, type NSheetProps, NSidebar, NSidebarBrand, type NSidebarBrandProps, NSidebarContent, type NSidebarContentProps, type NSidebarContextValue, NSidebarFooter, type NSidebarFooterProps, NSidebarHeader, type NSidebarHeaderProps, NSidebarItem, NSidebarMobile, type NSidebarMobileProps, NSidebarProvider, NSidebarSection, type NSidebarSectionProps, NSkeleton, NSkeletonCalendar, NSkeletonChart, NSkeletonDonut, NSkeletonEventList, NSkeletonWidget, NSkeletonWidgets, NSlider, type NSliderProps, NSmartPasteDialog, type NSmartPasteDialogProps, NSpinner, type NSpinnerProps, NStatCard, type NStatCardClassNames, type NStatCardProps, NStatCardSkeleton, type NStatCardVariant, NStatusBreakdown, type NStatusBreakdownProps, Swap as NSwap, type NSwapProps, NTable, NTableCardPagination, NTableCardRoot, type NTableCardRootProps, NTableCards, type NTableClassNames, type NTableColumnBreakpoint, type NTableColumnDef, type NTableColumnMeta, NTableContent, NTableHeader, NTableLoadingSkeleton, type NTableMenu, type NTableMenuProp, type NTablePageItem, NTablePagination, NTablePaginationLabels, NTablePaginationVariant, type NTableProps, NTableRowSkeleton, NTableSkeleton, type NTableState, NTabs, type NTabsClassNames, type NTabsColor, type NTabsItem, type NTabsProps, type NTabsStyles, NThemeCustomizer, type NThemeCustomizerFontOption, type NThemeCustomizerLabels, type NThemeCustomizerProps, type NThemeCustomizerTab, type NThemePreset, NThemePresets, type NThemePresetsLabels, type NThemePresetsProps, type NThemePresetsStatus, NUploader, type NUploaderItem, type NUploaderItemStatus, type NUploaderProps, NViewBody, NViewToggle, NajmAccent, NajmAppearance, type NajmBorderSide, NajmComponentName, NajmComponentStyleConfig, NajmComponentThemeConfig, NajmDesignConfig, NajmDesignEditorProvider, type NajmDesignEditorProviderProps, type NajmDesignEditorValue, NajmDesignProvider, type NajmDesignProviderProps, NajmFormatConfig, type NajmFormatContextValue, NajmFormatProvider, type NajmFormatProviderProps, NajmLayoutConfig, NajmMode, NajmPreset, NajmResponsiveBreakpoint, NajmResponsiveValue, NajmScroll, type NajmScrollProps, NajmThemeConfig, NajmThemeProvider, NajmThemeProviderProps, NajmThemeTokens, NajmTypographyConfig, NajmVariantStyle, NativeSelect, type NativeSelectOption, type NativeSelectProps, type NavItem, type NavItemGroup, NumberInput, type NumberInputProps, OtpInput, type OtpInputProps, PasswordInput, type PasswordInputProps, PhoneInput, type PhoneInputProps, Popover, PopoverAnchor, PopoverContent, PopoverTrigger, PrefixProvider, Progress, type ProgressColor, type ProgressLabelPosition, type ProgressProps, type ProgressSize, type PushDialogOptions, RadioGroup, RadioGroupInput, type RadioGroupInputProps, RadioGroupItem, type RenderSlot, RepeatingFields, type RepeatingFieldsProps, ScrollArea, type ScrollAreaProps, SearchField, SearchField as SearchInput, SegmentedControl, type SegmentedControlOption, type SegmentedControlProps, Select, SelectContent, SelectGroup, SelectInput, type SelectInputProps, SelectItem, type SelectItemType$1 as SelectItemDataType, type SelectItemType, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, Separator, Sheet, SheetClose, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetOverlay, SheetPortal, SheetTitle, SheetTrigger, type SidebarItemProps, type SidebarLogo, type SidebarLogoRender, type SidebarProps, type SidebarWidth, type SidebarWidths, SimpleTooltip, type SimpleTooltipProps, NSkeleton as Skeleton, Slider, SliderInput, type SliderInputProps, type SliderOrientation, type SliderProps, type SliderSize, type SliderVariant, type SmartPastePreview, type SpinnerVariant, StarRatingInput, type StarRatingInputProps, StatusPill, type StatusPillProps, type StatusPillTone, type StepConfig, StepIndicator, type StepMeta, StepsHeader, StepsProgress, type StorageMenuAction, type StorageSortOption, type StorageTarget, Swap, type SwapEffect, SwapIndeterminate, SwapOff, SwapOn, type SwapProps, type SwapSize, type SwapState, Switch, type SwitchColor, SwitchInput, type SwitchInputProps, type SwitchSize, TAB_COLORS, Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, type TableHeaderColor, TableRow, type TableState, type TableStore, TableStoreContext, Tabs, TabsContent, TabsList, type TabsListProps, type TabsOrientation, type TabsProps, TabsTrigger, type TabsTriggerProps, type TabsVariant, TextAreaInput, type TextAreaInputProps, TextInput, type TextInputProps, Textarea, TimeInput, type TimeInputProps, TimeZoneInput, type TimeZoneInputProps, Toaster, Toggle, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, type UseContextMenuResult, type UseNFormOptions, type UseStorageContextMenuOptions, type UseStorageContextMenuResult, type UserMenuAction, VariantProvider, type WizardClassNames, WizardForm, type WizardFormProps, alertVariants, avatarVariants, badgeColorVariants, badgeVariants, buildDefaultFileColumns, buildPageItems, buttonVariants, cn, colorTextClass, composePreset, createDialogStore, createTableStore, defineNajmDesignConfig, defineNajmThemeConfig, detectFormat, dialogVariants, filterResponsiveColumns, findStatusColor, formatColor, formatFileBytes, formatFileRelative, getIconColorProps, getNChartColor, getNextEditorTabValue, hiddenBelowClasses, indicatorVariants, inputBorderClasses, isPlaceholderAvatar, normalizeThemeFileName, parseColor, parseNajmDesignConfig, parseNajmThemeConfig, parseThemeFile, resolveAvatarSrc, resolveHiddenBelowClass, resolvePreset, resolveSlot, resolveStatusColor, resolveVariantAlias, sidebarBorderClasses, sliderVariants, statusTextClass, stringifyNajmDesignConfig, stringifyNajmThemeConfig, stringifyThemeFile, surfaceBorderClasses, swapVariants, toPickerHex, toggleVariants, tooltipContentVariants, truncateByCharacters, useCardViewport, useClickOutside, useContextMenu, useDebouncedValue, useDelayedLoading, useDesktopTableMode, useDialog, useDialogStore, useDynamicPageSize, useFormField, useFormSubmission, useInfiniteScroll, useKeyboard, useLocalStorageState, useMediaQuery, useNForm, useNPortalScope, useNSidebar, useNajmAppearance, useNajmComponentStyle, useNajmDesign, useNajmDesignEditor, useNajmFormat, useNajmFormatContext, useNajmThemeMode, usePrefix, useSelection, useStepNavigation, useStorageContextMenu, useStoreSync, useTable, useTableKeyboard, useTableStore, useVariant, useVariantPreset };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useNBranding } from './chunk-
|
|
2
|
-
export { NBrandingProvider, NBrandingStateProvider, NajmFormatProvider, normalizeBranding, useNBranding, useNBrandingEditor, useNajmFormat, useNajmFormatContext } from './chunk-
|
|
1
|
+
import { useResolvedFormDevTools, useNBranding } from './chunk-GHMR45H3.mjs';
|
|
2
|
+
export { FormDevToolsProvider, NBrandingProvider, NBrandingStateProvider, NajmFormatProvider, buildFormFill, normalizeBranding, useNBranding, useNBrandingEditor, useNajmFormat, useNajmFormatContext } from './chunk-GHMR45H3.mjs';
|
|
3
3
|
import { useResolvedPaginationLabels } from './chunk-USZUOJMK.mjs';
|
|
4
4
|
export { DEFAULT_PAGINATION_KEY_PREFIX, DEFAULT_TIME_ZONE, EMPTY_DESIGN, NTableDefaultsProvider, NajmDesignEditorProvider, NajmPreferencesProvider, NajmUIProvider, buildPaginationLabels, useNTableDefaults, useNajmDesignEditor, useNajmPreferencesContext, useNajmTheme, useNajmTimeZone } from './chunk-USZUOJMK.mjs';
|
|
5
5
|
import { resolveRadiusValue, inputBorderClasses, Button, NIcon, NajmScroll, surfaceBorderClasses, useNajmScrollViewport, resolveVariantAlias, buttonVariants, NButton, parseNajmDesignConfig, useTableStore, TableStoreContext, sidebarBorderClasses, NTableJson } from './chunk-6OOBAEH2.mjs';
|
|
@@ -10631,6 +10631,7 @@ var useVariant = () => useContext(VariantContext).variant;
|
|
|
10631
10631
|
var useBordered = () => useContext(VariantContext).bordered;
|
|
10632
10632
|
var useVariantPreset = () => VARIANT_PRESETS[useContext(VariantContext).variant];
|
|
10633
10633
|
function NFormInner({ schema, defaultValues, onSubmit, form: externalForm, variant = "default", bordered, as = "form", className = "", id, devTools, children }) {
|
|
10634
|
+
const resolvedDevTools = useResolvedFormDevTools(schema, devTools);
|
|
10634
10635
|
const resolver = useMemo(() => schema ? zodResolver(schema) : void 0, [schema]);
|
|
10635
10636
|
const internalForm = useForm({
|
|
10636
10637
|
resolver,
|
|
@@ -10638,21 +10639,21 @@ function NFormInner({ schema, defaultValues, onSubmit, form: externalForm, varia
|
|
|
10638
10639
|
});
|
|
10639
10640
|
const form = externalForm ?? internalForm;
|
|
10640
10641
|
const handleFill = useCallback(() => {
|
|
10641
|
-
if (
|
|
10642
|
-
form.reset(
|
|
10642
|
+
if (resolvedDevTools.fill) {
|
|
10643
|
+
form.reset(resolvedDevTools.fill());
|
|
10643
10644
|
}
|
|
10644
|
-
}, [
|
|
10645
|
+
}, [resolvedDevTools.fill, form]);
|
|
10645
10646
|
useEffect(() => {
|
|
10646
|
-
if (!
|
|
10647
|
+
if (!resolvedDevTools.enabled || !resolvedDevTools.fill) return;
|
|
10647
10648
|
const handler = (e) => {
|
|
10648
|
-
if (e.key ===
|
|
10649
|
+
if (e.key === resolvedDevTools.shortcut) {
|
|
10649
10650
|
e.preventDefault();
|
|
10650
10651
|
handleFill();
|
|
10651
10652
|
}
|
|
10652
10653
|
};
|
|
10653
10654
|
document.addEventListener("keydown", handler);
|
|
10654
10655
|
return () => document.removeEventListener("keydown", handler);
|
|
10655
|
-
}, [
|
|
10656
|
+
}, [resolvedDevTools.enabled, resolvedDevTools.fill, resolvedDevTools.shortcut, handleFill]);
|
|
10656
10657
|
useEffect(() => {
|
|
10657
10658
|
const proc = globalThis.process;
|
|
10658
10659
|
if (proc?.env?.NODE_ENV !== "development") return;
|
|
@@ -11130,8 +11131,10 @@ function WizardForm({
|
|
|
11130
11131
|
classNames,
|
|
11131
11132
|
footerSlot,
|
|
11132
11133
|
footerDivider = "none",
|
|
11133
|
-
footerDividerClassName
|
|
11134
|
+
footerDividerClassName,
|
|
11135
|
+
devTools
|
|
11134
11136
|
}) {
|
|
11137
|
+
const resolvedDevTools = useResolvedFormDevTools(schema, devTools);
|
|
11135
11138
|
const nav = useStepNavigation({
|
|
11136
11139
|
steps,
|
|
11137
11140
|
currentStep: controlledStep,
|
|
@@ -11171,6 +11174,36 @@ function WizardForm({
|
|
|
11171
11174
|
resolver: stepSchema ? zodResolver(stepSchema) : void 0,
|
|
11172
11175
|
defaultValues: stepDefaults
|
|
11173
11176
|
});
|
|
11177
|
+
const fillWizard = useCallback(() => {
|
|
11178
|
+
if (!resolvedDevTools.fill) return;
|
|
11179
|
+
const values = {
|
|
11180
|
+
...defaultValues ?? {},
|
|
11181
|
+
...resolvedDevTools.fill()
|
|
11182
|
+
};
|
|
11183
|
+
formDataRef.current = values;
|
|
11184
|
+
pendingIssuesRef.current = null;
|
|
11185
|
+
nav.reset();
|
|
11186
|
+
const firstStep = steps[0];
|
|
11187
|
+
const firstValues = firstStep?.fields ? Object.fromEntries(
|
|
11188
|
+
firstStep.fields.filter((field) => field in values).map((field) => [field, values[field]])
|
|
11189
|
+
) : values;
|
|
11190
|
+
form.reset(firstValues);
|
|
11191
|
+
}, [defaultValues, form, formDataRef, nav, resolvedDevTools.fill, steps]);
|
|
11192
|
+
useEffect(() => {
|
|
11193
|
+
if (!resolvedDevTools.enabled || !resolvedDevTools.fill) return;
|
|
11194
|
+
const handler = (event) => {
|
|
11195
|
+
if (event.key !== resolvedDevTools.shortcut) return;
|
|
11196
|
+
event.preventDefault();
|
|
11197
|
+
fillWizard();
|
|
11198
|
+
};
|
|
11199
|
+
document.addEventListener("keydown", handler);
|
|
11200
|
+
return () => document.removeEventListener("keydown", handler);
|
|
11201
|
+
}, [
|
|
11202
|
+
fillWizard,
|
|
11203
|
+
resolvedDevTools.enabled,
|
|
11204
|
+
resolvedDevTools.fill,
|
|
11205
|
+
resolvedDevTools.shortcut
|
|
11206
|
+
]);
|
|
11174
11207
|
useEffect(() => {
|
|
11175
11208
|
const newDefaults = getStepDefaultValues(currentStepConfig.id);
|
|
11176
11209
|
form.reset(newDefaults);
|
package/package.json
CHANGED
package/dist/chunk-PCPMAEKP.mjs
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { useNajmPreferencesContext } from './chunk-USZUOJMK.mjs';
|
|
2
|
-
import { humanizeToken, DEFAULT_PLACEHOLDER, formatRelativeTime, formatTime, formatDateTime, formatDate, formatPercent, formatNumber, formatCurrency } from './chunk-JABLSOQN.mjs';
|
|
3
|
-
import * as React from 'react';
|
|
4
|
-
import { createContext, useContext, useMemo, useState, useCallback } from 'react';
|
|
5
|
-
import { jsx } from 'react/jsx-runtime';
|
|
6
|
-
|
|
7
|
-
function normalizeBranding(input) {
|
|
8
|
-
if (!input) return {};
|
|
9
|
-
const value = {};
|
|
10
|
-
const expanded = input.logoExpanded ?? input.sidebarLogoExpandedPath;
|
|
11
|
-
const collapsed = input.logoCollapsed ?? input.sidebarLogoCollapsedPath;
|
|
12
|
-
if (input.appName !== void 0) value.appName = input.appName;
|
|
13
|
-
if (input.logoFallback !== void 0) value.logoFallback = input.logoFallback;
|
|
14
|
-
if (input.logoHref !== void 0) value.logoHref = input.logoHref;
|
|
15
|
-
if (expanded !== void 0) value.logoExpanded = expanded;
|
|
16
|
-
if (collapsed !== void 0) value.logoCollapsed = collapsed;
|
|
17
|
-
return value;
|
|
18
|
-
}
|
|
19
|
-
var NBrandingContext = createContext(null);
|
|
20
|
-
function useNBranding() {
|
|
21
|
-
return useContext(NBrandingContext);
|
|
22
|
-
}
|
|
23
|
-
function NBrandingProvider({
|
|
24
|
-
children,
|
|
25
|
-
appName,
|
|
26
|
-
logoExpanded,
|
|
27
|
-
logoCollapsed,
|
|
28
|
-
logoFallback,
|
|
29
|
-
logoHref
|
|
30
|
-
}) {
|
|
31
|
-
const value = useMemo(
|
|
32
|
-
() => ({ appName, logoExpanded, logoCollapsed, logoFallback, logoHref }),
|
|
33
|
-
[appName, logoExpanded, logoCollapsed, logoFallback, logoHref]
|
|
34
|
-
);
|
|
35
|
-
return /* @__PURE__ */ jsx(NBrandingContext.Provider, { value, children });
|
|
36
|
-
}
|
|
37
|
-
var NBrandingEditorContext = createContext(null);
|
|
38
|
-
function useNBrandingEditor() {
|
|
39
|
-
return useContext(NBrandingEditorContext);
|
|
40
|
-
}
|
|
41
|
-
function NBrandingStateProvider({
|
|
42
|
-
children,
|
|
43
|
-
branding,
|
|
44
|
-
initialBranding
|
|
45
|
-
}) {
|
|
46
|
-
const [state, setState] = useState(
|
|
47
|
-
() => normalizeBranding(initialBranding ?? branding)
|
|
48
|
-
);
|
|
49
|
-
const setBranding = useCallback((patch) => {
|
|
50
|
-
const marks = normalizeBranding(patch);
|
|
51
|
-
setState((current) => ({ ...current, ...marks }));
|
|
52
|
-
}, []);
|
|
53
|
-
const controlled = useMemo(
|
|
54
|
-
() => branding ? normalizeBranding(branding) : void 0,
|
|
55
|
-
[branding]
|
|
56
|
-
);
|
|
57
|
-
const resolved = controlled ?? state;
|
|
58
|
-
const editor = useMemo(
|
|
59
|
-
() => ({ branding: resolved, setBranding: branding ? noop : setBranding }),
|
|
60
|
-
[resolved, branding, setBranding]
|
|
61
|
-
);
|
|
62
|
-
return /* @__PURE__ */ jsx(NBrandingEditorContext.Provider, { value: editor, children: /* @__PURE__ */ jsx(NBrandingProvider, { ...resolved, children }) });
|
|
63
|
-
}
|
|
64
|
-
function noop() {
|
|
65
|
-
}
|
|
66
|
-
var NajmFormatContext = React.createContext(
|
|
67
|
-
null
|
|
68
|
-
);
|
|
69
|
-
function NajmFormatProvider({
|
|
70
|
-
children,
|
|
71
|
-
locale,
|
|
72
|
-
currency,
|
|
73
|
-
timeZone,
|
|
74
|
-
placeholder = DEFAULT_PLACEHOLDER
|
|
75
|
-
}) {
|
|
76
|
-
const preferences = useNajmPreferencesContext();
|
|
77
|
-
const resolvedTimeZone = timeZone ?? preferences?.timeZone ?? Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
78
|
-
const value = React.useMemo(() => {
|
|
79
|
-
const config = {
|
|
80
|
-
locale,
|
|
81
|
-
timeZone: resolvedTimeZone,
|
|
82
|
-
currency,
|
|
83
|
-
placeholder
|
|
84
|
-
};
|
|
85
|
-
return {
|
|
86
|
-
locale,
|
|
87
|
-
timeZone: resolvedTimeZone,
|
|
88
|
-
currency,
|
|
89
|
-
placeholder,
|
|
90
|
-
config,
|
|
91
|
-
money: (minorUnits) => formatCurrency(minorUnits, config),
|
|
92
|
-
number: (value_, options) => formatNumber(value_, config, options),
|
|
93
|
-
percent: (value_, digits) => formatPercent(value_, config, digits),
|
|
94
|
-
date: (value_, options) => formatDate(value_, config, options),
|
|
95
|
-
dateTime: (value_) => formatDateTime(value_, config),
|
|
96
|
-
time: (value_) => formatTime(value_, config),
|
|
97
|
-
relativeTime: (value_) => formatRelativeTime(value_, config),
|
|
98
|
-
humanize: humanizeToken
|
|
99
|
-
};
|
|
100
|
-
}, [locale, resolvedTimeZone, currency, placeholder]);
|
|
101
|
-
return /* @__PURE__ */ jsx(NajmFormatContext.Provider, { value, children });
|
|
102
|
-
}
|
|
103
|
-
function useNajmFormatContext() {
|
|
104
|
-
return React.useContext(NajmFormatContext);
|
|
105
|
-
}
|
|
106
|
-
function useNajmFormat() {
|
|
107
|
-
const value = React.useContext(NajmFormatContext);
|
|
108
|
-
if (!value) {
|
|
109
|
-
throw new Error(
|
|
110
|
-
"useNajmFormat must be rendered under a NajmFormatProvider or NajmAppProvider."
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
return value;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export { NBrandingProvider, NBrandingStateProvider, NajmFormatProvider, normalizeBranding, useNBranding, useNBrandingEditor, useNajmFormat, useNajmFormatContext };
|