@iowas/toolpad 1.0.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/dist/nextjs.js ADDED
@@ -0,0 +1,858 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __defProps = Object.defineProperties;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
+ var __getProtoOf = Object.getPrototypeOf;
10
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
11
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
12
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
+ var __spreadValues = (a, b) => {
14
+ for (var prop in b || (b = {}))
15
+ if (__hasOwnProp.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ if (__getOwnPropSymbols)
18
+ for (var prop of __getOwnPropSymbols(b)) {
19
+ if (__propIsEnum.call(b, prop))
20
+ __defNormalProp(a, prop, b[prop]);
21
+ }
22
+ return a;
23
+ };
24
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
25
+ var __objRest = (source, exclude) => {
26
+ var target = {};
27
+ for (var prop in source)
28
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
29
+ target[prop] = source[prop];
30
+ if (source != null && __getOwnPropSymbols)
31
+ for (var prop of __getOwnPropSymbols(source)) {
32
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
33
+ target[prop] = source[prop];
34
+ }
35
+ return target;
36
+ };
37
+ var __export = (target, all) => {
38
+ for (var name in all)
39
+ __defProp(target, name, { get: all[name], enumerable: true });
40
+ };
41
+ var __copyProps = (to, from, except, desc) => {
42
+ if (from && typeof from === "object" || typeof from === "function") {
43
+ for (let key of __getOwnPropNames(from))
44
+ if (!__hasOwnProp.call(to, key) && key !== except)
45
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
46
+ }
47
+ return to;
48
+ };
49
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
50
+ // If the importer is in node compatibility mode or this is not an ESM
51
+ // file that has been converted to a CommonJS file using a Babel-
52
+ // compatible transform (i.e. "__esModule" has not been set), then set
53
+ // "default" to the CommonJS "module.exports" for node compatibility.
54
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
55
+ mod
56
+ ));
57
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
58
+
59
+ // src/nextjs.ts
60
+ var nextjs_exports = {};
61
+ __export(nextjs_exports, {
62
+ NextAppProvider: () => NextAppProvider
63
+ });
64
+ module.exports = __toCommonJS(nextjs_exports);
65
+
66
+ // src/toolpad-core/nextjs/NextAppProvider.tsx
67
+ var import_router2 = require("next/compat/router.js");
68
+
69
+ // src/toolpad-core/nextjs/NextAppProviderApp.tsx
70
+ var React11 = __toESM(require("react"));
71
+ var import_link = __toESM(require("next/link.js"));
72
+ var import_navigation = require("next/navigation.js");
73
+
74
+ // src/toolpad-core/AppProvider/AppProvider.tsx
75
+ var React10 = __toESM(require("react"));
76
+ var import_prop_types2 = __toESM(require("prop-types"));
77
+ var import_styles3 = require("@mui/material/styles");
78
+
79
+ // src/toolpad-core/useNotifications/NotificationsContext.ts
80
+ var React = __toESM(require("react"));
81
+ var NotificationsContext = React.createContext(null);
82
+
83
+ // src/toolpad-core/useNotifications/NotificationsProvider.tsx
84
+ var React4 = __toESM(require("react"));
85
+ var import_material = require("@mui/material");
86
+ var import_Close = __toESM(require("@mui/icons-material/Close"));
87
+ var import_useSlotProps = __toESM(require("@mui/utils/useSlotProps"));
88
+
89
+ // src/toolpad-core/AppProvider/LocalizationProvider.tsx
90
+ var React2 = __toESM(require("react"));
91
+ var import_prop_types = __toESM(require("prop-types"));
92
+ var import_styles = require("@mui/material/styles");
93
+
94
+ // src/toolpad-core/locales/getLocalization.ts
95
+ var getLocalization = (translations) => {
96
+ return {
97
+ components: {
98
+ MuiLocalizationProvider: {
99
+ defaultProps: {
100
+ localeText: __spreadValues({}, translations)
101
+ }
102
+ }
103
+ }
104
+ };
105
+ };
106
+
107
+ // src/toolpad-core/locales/en.tsx
108
+ var enLabels = {
109
+ // Account
110
+ accountSignInLabel: "Sign In",
111
+ accountSignOutLabel: "Sign Out",
112
+ // AccountPreview
113
+ accountPreviewTitle: "Account",
114
+ accountPreviewIconButtonLabel: "Current User",
115
+ // SignInPage
116
+ signInTitle: (brandingTitle) => brandingTitle ? `Sign in to ${brandingTitle}` : "Sign in",
117
+ signInSubtitle: "Welcome user, please sign in to continue",
118
+ signInRememberMe: "Remember Me",
119
+ providerSignInTitle: (provider) => `Sign in with ${provider}`,
120
+ // Common authentication labels
121
+ email: "Email",
122
+ password: "Password",
123
+ username: "Username",
124
+ passkey: "Passkey",
125
+ // Common action labels
126
+ save: "Save",
127
+ cancel: "Cancel",
128
+ ok: "Ok",
129
+ or: "Or",
130
+ to: "To",
131
+ with: "With",
132
+ close: "Close",
133
+ delete: "Delete",
134
+ alert: "Alert",
135
+ confirm: "Confirm",
136
+ loading: "Loading...",
137
+ // CRUD
138
+ createNewButtonLabel: "Create new",
139
+ reloadButtonLabel: "Reload data",
140
+ createLabel: "Create",
141
+ createSuccessMessage: "Item created successfully.",
142
+ createErrorMessage: "Failed to create item. Reason:",
143
+ editLabel: "Edit",
144
+ editSuccessMessage: "Item edited successfully.",
145
+ editErrorMessage: "Failed to edit item. Reason:",
146
+ deleteLabel: "Delete",
147
+ deleteConfirmTitle: "Delete item?",
148
+ deleteConfirmMessage: "Do you wish to delete this item?",
149
+ deleteConfirmLabel: "Delete",
150
+ deleteCancelLabel: "Cancel",
151
+ deleteSuccessMessage: "Item deleted successfully.",
152
+ deleteErrorMessage: "Failed to delete item. Reason:",
153
+ deletedItemMessage: "This item has been deleted."
154
+ };
155
+ var en_default = getLocalization(enLabels);
156
+
157
+ // src/toolpad-core/AppProvider/LocalizationProvider.tsx
158
+ var import_jsx_runtime = require("react/jsx-runtime");
159
+ var LocalizationContext = React2.createContext({});
160
+ var LocalizationProvider = function LocalizationProvider2(props) {
161
+ var _a, _b, _c;
162
+ const { localeText: propsLocaleText, children } = props;
163
+ const theme = (0, import_styles.useTheme)();
164
+ const themeLocaleText = (_c = (_b = (_a = theme == null ? void 0 : theme.components) == null ? void 0 : _a.MuiLocalizationProvider) == null ? void 0 : _b.defaultProps) == null ? void 0 : _c.localeText;
165
+ const defaultLocaleText2 = en_default.components.MuiLocalizationProvider.defaultProps.localeText;
166
+ const localeText = React2.useMemo(
167
+ () => __spreadValues(__spreadValues(__spreadValues({}, defaultLocaleText2), themeLocaleText), propsLocaleText),
168
+ [defaultLocaleText2, themeLocaleText, propsLocaleText]
169
+ );
170
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LocalizationContext.Provider, { value: localeText, children });
171
+ };
172
+ LocalizationProvider.propTypes = {
173
+ // ┌────────────────────────────── Warning ──────────────────────────────┐
174
+ // │ These PropTypes are generated from the TypeScript type definitions. │
175
+ // │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
176
+ // └─────────────────────────────────────────────────────────────────────┘
177
+ /**
178
+ * @ignore
179
+ */
180
+ children: import_prop_types.default.node,
181
+ /**
182
+ * Locale for components texts
183
+ */
184
+ localeText: import_prop_types.default.object
185
+ };
186
+ function useLocaleText() {
187
+ return React2.useContext(LocalizationContext);
188
+ }
189
+
190
+ // src/toolpad-utils/react.tsx
191
+ var React3 = __toESM(require("react"));
192
+ var ReactIs = __toESM(require("react-is"));
193
+ var import_jsx_runtime2 = require("react/jsx-runtime");
194
+ function useNonNullableContext(context, name) {
195
+ const maybeContext = React3.useContext(context);
196
+ if (maybeContext === null || maybeContext === void 0) {
197
+ throw new Error(`context "${name}" was used without a Provider`);
198
+ }
199
+ return maybeContext;
200
+ }
201
+
202
+ // src/toolpad-core/useNotifications/NotificationsProvider.tsx
203
+ var import_jsx_runtime3 = require("react/jsx-runtime");
204
+ var RootPropsContext = React4.createContext(null);
205
+ var defaultLocaleText = {
206
+ close: "Close"
207
+ };
208
+ function Notification({ notificationKey, open, message, options, badge }) {
209
+ var _a, _b, _c;
210
+ const globalLocaleText = useLocaleText();
211
+ const localeText = __spreadValues(__spreadValues({}, defaultLocaleText), globalLocaleText);
212
+ const { close } = useNonNullableContext(NotificationsContext);
213
+ const { severity, actionText, onAction, autoHideDuration } = options;
214
+ const handleClose = React4.useCallback(
215
+ (event, reason) => {
216
+ if (reason === "clickaway") {
217
+ return;
218
+ }
219
+ close(notificationKey);
220
+ },
221
+ [notificationKey, close]
222
+ );
223
+ const action = /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(React4.Fragment, { children: [
224
+ onAction ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_material.Button, { color: "inherit", size: "small", onClick: onAction, children: actionText != null ? actionText : "Action" }) : null,
225
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
226
+ import_material.IconButton,
227
+ {
228
+ size: "small",
229
+ "aria-label": localeText == null ? void 0 : localeText.close,
230
+ title: localeText == null ? void 0 : localeText.close,
231
+ color: "inherit",
232
+ onClick: handleClose,
233
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_Close.default, { fontSize: "small" })
234
+ }
235
+ )
236
+ ] });
237
+ const props = React4.useContext(RootPropsContext);
238
+ const SnackbarComponent = (_b = (_a = props == null ? void 0 : props.slots) == null ? void 0 : _a.snackbar) != null ? _b : import_material.Snackbar;
239
+ const snackbarSlotProps = (0, import_useSlotProps.default)({
240
+ elementType: SnackbarComponent,
241
+ ownerState: props,
242
+ externalSlotProps: (_c = props == null ? void 0 : props.slotProps) == null ? void 0 : _c.snackbar,
243
+ additionalProps: {
244
+ open,
245
+ autoHideDuration,
246
+ onClose: handleClose,
247
+ action
248
+ }
249
+ });
250
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(SnackbarComponent, __spreadProps(__spreadValues({}, snackbarSlotProps), { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_material.Badge, { badgeContent: badge, color: "primary", sx: { width: "100%" }, children: severity ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_material.Alert, { severity, sx: { width: "100%" }, action, children: message }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_material.SnackbarContent, { message, action }) }) }), notificationKey);
251
+ }
252
+ function Notifications({ state }) {
253
+ var _a;
254
+ const currentNotification = (_a = state.queue[0]) != null ? _a : null;
255
+ return currentNotification ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
256
+ Notification,
257
+ __spreadProps(__spreadValues({}, currentNotification), {
258
+ badge: state.queue.length > 1 ? String(state.queue.length) : null
259
+ })
260
+ ) : null;
261
+ }
262
+ var nextId = 0;
263
+ var generateId = () => {
264
+ const id = nextId;
265
+ nextId += 1;
266
+ return id;
267
+ };
268
+ function NotificationsProvider(props) {
269
+ const { children } = props;
270
+ const [state, setState] = React4.useState({ queue: [] });
271
+ const show = React4.useCallback((message, options = {}) => {
272
+ var _a;
273
+ const notificationKey = (_a = options.key) != null ? _a : `::toolpad-internal::notification::${generateId()}`;
274
+ setState((prev) => {
275
+ if (prev.queue.some((n) => n.notificationKey === notificationKey)) {
276
+ return prev;
277
+ }
278
+ return __spreadProps(__spreadValues({}, prev), {
279
+ queue: [...prev.queue, { message, options, notificationKey, open: true }]
280
+ });
281
+ });
282
+ return notificationKey;
283
+ }, []);
284
+ const close = React4.useCallback((key) => {
285
+ setState((prev) => __spreadProps(__spreadValues({}, prev), {
286
+ queue: prev.queue.filter((n) => n.notificationKey !== key)
287
+ }));
288
+ }, []);
289
+ const contextValue = React4.useMemo(() => ({ show, close }), [show, close]);
290
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(RootPropsContext.Provider, { value: props, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(NotificationsContext.Provider, { value: contextValue, children: [
291
+ children,
292
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Notifications, { state })
293
+ ] }) });
294
+ }
295
+
296
+ // src/toolpad-core/useDialogs/DialogsContext.tsx
297
+ var React5 = __toESM(require("react"));
298
+ var DialogsContext = React5.createContext(null);
299
+
300
+ // src/toolpad-core/shared/context.ts
301
+ var React6 = __toESM(require("react"));
302
+ var BrandingContext = React6.createContext(null);
303
+ var NavigationContext = React6.createContext([]);
304
+ var PaletteModeContext = React6.createContext({
305
+ paletteMode: "light",
306
+ setPaletteMode: () => {
307
+ },
308
+ isDualTheme: false
309
+ });
310
+ var RouterContext = React6.createContext(null);
311
+ var DashboardSidebarPageItemContext = React6.createContext(null);
312
+ var WindowContext = React6.createContext(void 0);
313
+
314
+ // src/toolpad-core/useDialogs/DialogsProvider.tsx
315
+ var import_invariant = __toESM(require("invariant"));
316
+ var React7 = __toESM(require("react"));
317
+ var import_useEventCallback = __toESM(require("@mui/utils/useEventCallback"));
318
+ var import_jsx_runtime4 = require("react/jsx-runtime");
319
+ function DialogsProvider(props) {
320
+ const { children, unmountAfter = 1e3 } = props;
321
+ const [stack, setStack] = React7.useState([]);
322
+ const keyPrefix = React7.useId();
323
+ const nextId2 = React7.useRef(0);
324
+ const dialogMetadata = React7.useRef(/* @__PURE__ */ new WeakMap());
325
+ const requestDialog = (0, import_useEventCallback.default)(function open(Component, payload, options = {}) {
326
+ const { onClose = async () => {
327
+ } } = options;
328
+ let resolve;
329
+ const promise = new Promise((resolveImpl) => {
330
+ resolve = resolveImpl;
331
+ });
332
+ (0, import_invariant.default)(resolve, "resolve not set");
333
+ const key = `${keyPrefix}-${nextId2.current}`;
334
+ nextId2.current += 1;
335
+ const newEntry = {
336
+ key,
337
+ open: true,
338
+ promise,
339
+ Component,
340
+ payload,
341
+ onClose,
342
+ resolve
343
+ };
344
+ dialogMetadata.current.set(promise, newEntry);
345
+ setStack((prevStack) => [...prevStack, newEntry]);
346
+ return promise;
347
+ });
348
+ const closeDialogUi = (0, import_useEventCallback.default)(function closeDialogUi2(dialog) {
349
+ setStack(
350
+ (prevStack) => prevStack.map((entry) => entry.promise === dialog ? __spreadProps(__spreadValues({}, entry), { open: false }) : entry)
351
+ );
352
+ setTimeout(() => {
353
+ setStack((prevStack) => prevStack.filter((entry) => entry.promise !== dialog));
354
+ }, unmountAfter);
355
+ });
356
+ const closeDialog = (0, import_useEventCallback.default)(async function closeDialog2(dialog, result) {
357
+ const entryToClose = dialogMetadata.current.get(dialog);
358
+ (0, import_invariant.default)(entryToClose, "dialog not found");
359
+ try {
360
+ await entryToClose.onClose(result);
361
+ } finally {
362
+ entryToClose.resolve(result);
363
+ closeDialogUi(dialog);
364
+ }
365
+ return dialog;
366
+ });
367
+ const contextValue = React7.useMemo(
368
+ () => ({ open: requestDialog, close: closeDialog }),
369
+ [requestDialog, closeDialog]
370
+ );
371
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(DialogsContext.Provider, { value: contextValue, children: [
372
+ children,
373
+ stack.map(({ key, open, Component, payload, promise }) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
374
+ Component,
375
+ {
376
+ payload,
377
+ open,
378
+ onClose: async (result) => {
379
+ await closeDialog(promise, result);
380
+ }
381
+ },
382
+ key
383
+ ))
384
+ ] });
385
+ }
386
+
387
+ // src/toolpad-core/AppProvider/AppThemeProvider.tsx
388
+ var React9 = __toESM(require("react"));
389
+ var import_material2 = require("@mui/material");
390
+ var import_styles2 = require("@mui/material/styles");
391
+ var import_InitColorSchemeScript = __toESM(require("@mui/material/InitColorSchemeScript"));
392
+ var import_CssBaseline = __toESM(require("@mui/material/CssBaseline"));
393
+ var import_invariant2 = __toESM(require("invariant"));
394
+
395
+ // src/toolpad-core/persistence/useStorageState.tsx
396
+ var React8 = __toESM(require("react"));
397
+
398
+ // src/toolpad-core/persistence/codec.tsx
399
+ var CODEC_STRING = {
400
+ parse: (value) => value,
401
+ stringify: (value) => value
402
+ };
403
+
404
+ // src/toolpad-core/persistence/useStorageState.tsx
405
+ var currentTabChangeListeners = /* @__PURE__ */ new Map();
406
+ function onCurrentTabStorageChange(key, handler) {
407
+ let listeners = currentTabChangeListeners.get(key);
408
+ if (!listeners) {
409
+ listeners = /* @__PURE__ */ new Set();
410
+ currentTabChangeListeners.set(key, listeners);
411
+ }
412
+ listeners.add(handler);
413
+ }
414
+ function offCurrentTabStorageChange(key, handler) {
415
+ const listeners = currentTabChangeListeners.get(key);
416
+ if (!listeners) {
417
+ return;
418
+ }
419
+ listeners.delete(handler);
420
+ if (listeners.size === 0) {
421
+ currentTabChangeListeners.delete(key);
422
+ }
423
+ }
424
+ function emitCurrentTabStorageChange(key) {
425
+ const listeners = currentTabChangeListeners.get(key);
426
+ if (listeners) {
427
+ listeners.forEach((listener) => listener());
428
+ }
429
+ }
430
+ if (typeof window !== "undefined") {
431
+ const origSetItem = window.localStorage.setItem;
432
+ window.localStorage.setItem = function setItem(key, value) {
433
+ const result = origSetItem.call(this, key, value);
434
+ emitCurrentTabStorageChange(key);
435
+ return result;
436
+ };
437
+ }
438
+ function subscribe(area, key, callback) {
439
+ if (!key) {
440
+ return () => {
441
+ };
442
+ }
443
+ const storageHandler = (event) => {
444
+ if (event.storageArea === area && event.key === key) {
445
+ callback();
446
+ }
447
+ };
448
+ window.addEventListener("storage", storageHandler);
449
+ onCurrentTabStorageChange(key, callback);
450
+ return () => {
451
+ window.removeEventListener("storage", storageHandler);
452
+ offCurrentTabStorageChange(key, callback);
453
+ };
454
+ }
455
+ function getSnapshot(area, key) {
456
+ if (!key) {
457
+ return null;
458
+ }
459
+ try {
460
+ return area.getItem(key);
461
+ } catch (e) {
462
+ return null;
463
+ }
464
+ }
465
+ function setValue(area, key, value) {
466
+ if (!key) {
467
+ return;
468
+ }
469
+ try {
470
+ if (value === null) {
471
+ area.removeItem(key);
472
+ } else {
473
+ area.setItem(key, String(value));
474
+ }
475
+ } catch (e) {
476
+ return;
477
+ }
478
+ emitCurrentTabStorageChange(key);
479
+ }
480
+ var serverValue = [null, () => {
481
+ }];
482
+ function useStorageStateServer() {
483
+ return serverValue;
484
+ }
485
+ function encode(codec, value) {
486
+ return value === null ? null : codec.stringify(value);
487
+ }
488
+ function decode(codec, value) {
489
+ return value === null ? null : codec.parse(value);
490
+ }
491
+ var getKeyServerSnapshot = () => null;
492
+ function useStorageState(area, key, initializer = null, options) {
493
+ var _a;
494
+ const codec = (_a = options == null ? void 0 : options.codec) != null ? _a : CODEC_STRING;
495
+ const [initialValue] = React8.useState(initializer);
496
+ const encodedInitialValue = React8.useMemo(
497
+ () => encode(codec, initialValue),
498
+ [codec, initialValue]
499
+ );
500
+ const subscribeKey = React8.useCallback(
501
+ (callback) => subscribe(area, key, callback),
502
+ [area, key]
503
+ );
504
+ const getKeySnapshot = React8.useCallback(
505
+ () => {
506
+ var _a2;
507
+ return (_a2 = getSnapshot(area, key)) != null ? _a2 : encodedInitialValue;
508
+ },
509
+ [area, encodedInitialValue, key]
510
+ );
511
+ const encodedStoredValue = React8.useSyncExternalStore(
512
+ subscribeKey,
513
+ getKeySnapshot,
514
+ getKeyServerSnapshot
515
+ );
516
+ const storedValue = React8.useMemo(
517
+ () => decode(codec, encodedStoredValue),
518
+ [codec, encodedStoredValue]
519
+ );
520
+ const setStoredValue = React8.useCallback(
521
+ (value) => {
522
+ const valueToStore = value instanceof Function ? value(storedValue) : value;
523
+ const encodedValueToStore = encode(codec, valueToStore);
524
+ setValue(area, key, encodedValueToStore);
525
+ },
526
+ [area, codec, storedValue, key]
527
+ );
528
+ const [nonStoredValue, setNonStoredValue] = React8.useState(initialValue);
529
+ if (!key) {
530
+ return [nonStoredValue, setNonStoredValue];
531
+ }
532
+ return [storedValue, setStoredValue];
533
+ }
534
+
535
+ // src/toolpad-core/useLocalStorageState/useLocalStorageState.tsx
536
+ var useLocalStorageStateBrowser = (...args) => useStorageState(window.localStorage, ...args);
537
+ var useLocalStorageState = typeof window === "undefined" ? useStorageStateServer : useLocalStorageStateBrowser;
538
+
539
+ // src/toolpad-core/AppProvider/AppThemeProvider.tsx
540
+ var import_jsx_runtime5 = require("react/jsx-runtime");
541
+ var COLOR_SCHEME_STORAGE_KEY = "toolpad-color-scheme";
542
+ var MODE_STORAGE_KEY = "toolpad-mode";
543
+ function usePreferredMode(window2) {
544
+ const prefersDarkMode = (0, import_material2.useMediaQuery)(
545
+ "(prefers-color-scheme: dark)",
546
+ window2 && {
547
+ matchMedia: window2.matchMedia
548
+ }
549
+ );
550
+ return prefersDarkMode ? "dark" : "light";
551
+ }
552
+ function isCssVarsTheme(theme) {
553
+ return "vars" in theme;
554
+ }
555
+ function LegacyThemeProvider(props) {
556
+ const { children, theme, window: appWindow } = props;
557
+ (0, import_invariant2.default)(!isCssVarsTheme(theme), "This provider only accepts legacy themes.");
558
+ const isDualTheme = "light" in theme || "dark" in theme;
559
+ const preferredMode = usePreferredMode(appWindow);
560
+ const [userMode, setUserMode] = useLocalStorageState(MODE_STORAGE_KEY, "system");
561
+ const paletteMode = !userMode || userMode === "system" ? preferredMode : userMode;
562
+ const dualAwareTheme = React9.useMemo(
563
+ () => {
564
+ var _a;
565
+ return isDualTheme ? (_a = theme[paletteMode === "dark" ? "dark" : "light"]) != null ? _a : theme[paletteMode === "dark" ? "light" : "dark"] : theme;
566
+ },
567
+ [isDualTheme, paletteMode, theme]
568
+ );
569
+ const paletteModeContextValue = React9.useMemo(
570
+ () => ({
571
+ paletteMode,
572
+ setPaletteMode: setUserMode,
573
+ isDualTheme
574
+ }),
575
+ [isDualTheme, paletteMode, setUserMode]
576
+ );
577
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_styles2.ThemeProvider, { theme: dualAwareTheme, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(PaletteModeContext.Provider, { value: paletteModeContextValue, children: [
578
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_CssBaseline.default, { enableColorScheme: true }),
579
+ children
580
+ ] }) });
581
+ }
582
+ function CssVarsPaletteModeProvider(props) {
583
+ const { children, window: appWindow } = props;
584
+ const preferredMode = usePreferredMode(appWindow);
585
+ const { mode, setMode, allColorSchemes } = (0, import_styles2.useColorScheme)();
586
+ const paletteModeContextValue = React9.useMemo(() => {
587
+ return {
588
+ paletteMode: !mode || mode === "system" ? preferredMode : mode,
589
+ setPaletteMode: setMode,
590
+ isDualTheme: allColorSchemes.length > 1
591
+ };
592
+ }, [allColorSchemes, mode, preferredMode, setMode]);
593
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(PaletteModeContext.Provider, { value: paletteModeContextValue, children });
594
+ }
595
+ function CssVarsThemeProvider(props) {
596
+ const { children, theme, window: appWindow, nonce } = props;
597
+ (0, import_invariant2.default)(isCssVarsTheme(theme), "This provider only accepts CSS vars themes.");
598
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
599
+ import_styles2.ThemeProvider,
600
+ {
601
+ theme,
602
+ documentNode: appWindow == null ? void 0 : appWindow.document,
603
+ colorSchemeNode: appWindow == null ? void 0 : appWindow.document.documentElement,
604
+ disableNestedContext: true,
605
+ colorSchemeStorageKey: COLOR_SCHEME_STORAGE_KEY,
606
+ modeStorageKey: MODE_STORAGE_KEY,
607
+ children: [
608
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
609
+ import_InitColorSchemeScript.default,
610
+ {
611
+ attribute: theme.colorSchemeSelector,
612
+ colorSchemeStorageKey: COLOR_SCHEME_STORAGE_KEY,
613
+ modeStorageKey: MODE_STORAGE_KEY,
614
+ nonce
615
+ }
616
+ ),
617
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(CssVarsPaletteModeProvider, { window: appWindow, children: [
618
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_CssBaseline.default, { enableColorScheme: true }),
619
+ children
620
+ ] })
621
+ ]
622
+ }
623
+ );
624
+ }
625
+ function AppThemeProvider(props) {
626
+ const _a = props, { children, theme } = _a, rest = __objRest(_a, ["children", "theme"]);
627
+ const useCssVarsProvider = isCssVarsTheme(theme);
628
+ return useCssVarsProvider ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(CssVarsThemeProvider, __spreadProps(__spreadValues({ theme }, rest), { children })) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(LegacyThemeProvider, __spreadProps(__spreadValues({ theme }, rest), { children }));
629
+ }
630
+
631
+ // src/toolpad-core/AppProvider/AppProvider.tsx
632
+ var import_jsx_runtime6 = require("react/jsx-runtime");
633
+ var AuthenticationContext = React10.createContext(null);
634
+ var SessionContext = React10.createContext(null);
635
+ function createDefaultTheme() {
636
+ return (0, import_styles3.createTheme)({
637
+ cssVariables: {
638
+ colorSchemeSelector: "data-toolpad-color-scheme"
639
+ },
640
+ colorSchemes: { dark: true }
641
+ });
642
+ }
643
+ function AppProvider(props) {
644
+ const {
645
+ children,
646
+ theme = createDefaultTheme(),
647
+ branding = null,
648
+ navigation = [],
649
+ localeText,
650
+ router = null,
651
+ authentication = null,
652
+ session = null,
653
+ window: appWindow,
654
+ nonce
655
+ } = props;
656
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(WindowContext.Provider, { value: appWindow, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(AuthenticationContext.Provider, { value: authentication, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(SessionContext.Provider, { value: session, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(RouterContext.Provider, { value: router, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(AppThemeProvider, { theme, window: appWindow, nonce, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(LocalizationProvider, { localeText, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(NotificationsProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(DialogsProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(BrandingContext.Provider, { value: branding, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(NavigationContext.Provider, { value: navigation, children }) }) }) }) }) }) }) }) }) });
657
+ }
658
+ AppProvider.propTypes = {
659
+ // ┌────────────────────────────── Warning ──────────────────────────────┐
660
+ // │ These PropTypes are generated from the TypeScript type definitions. │
661
+ // │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
662
+ // └─────────────────────────────────────────────────────────────────────┘
663
+ /**
664
+ * Authentication methods.
665
+ * @default null
666
+ */
667
+ authentication: import_prop_types2.default.shape({
668
+ signIn: import_prop_types2.default.func.isRequired,
669
+ signOut: import_prop_types2.default.func.isRequired
670
+ }),
671
+ /**
672
+ * Branding options for the app.
673
+ * @default null
674
+ */
675
+ branding: import_prop_types2.default.shape({
676
+ homeUrl: import_prop_types2.default.string,
677
+ logo: import_prop_types2.default.node,
678
+ title: import_prop_types2.default.string
679
+ }),
680
+ /**
681
+ * The content of the app provider.
682
+ */
683
+ children: import_prop_types2.default.node,
684
+ /**
685
+ * Locale text for components
686
+ */
687
+ localeText: import_prop_types2.default.object,
688
+ /**
689
+ * Navigation definition for the app. [Find out more](https://mui.com/toolpad/core/react-app-provider/#navigation).
690
+ * @default []
691
+ */
692
+ navigation: import_prop_types2.default.arrayOf(
693
+ import_prop_types2.default.oneOfType([
694
+ import_prop_types2.default.shape({
695
+ action: import_prop_types2.default.node,
696
+ children: import_prop_types2.default.arrayOf(
697
+ import_prop_types2.default.oneOfType([
698
+ import_prop_types2.default.object,
699
+ import_prop_types2.default.shape({
700
+ kind: import_prop_types2.default.oneOf(["header"]).isRequired,
701
+ title: import_prop_types2.default.string.isRequired
702
+ }),
703
+ import_prop_types2.default.shape({
704
+ kind: import_prop_types2.default.oneOf(["divider"]).isRequired
705
+ })
706
+ ]).isRequired
707
+ ),
708
+ icon: import_prop_types2.default.node,
709
+ kind: import_prop_types2.default.oneOf(["page"]),
710
+ pattern: import_prop_types2.default.string,
711
+ segment: import_prop_types2.default.string,
712
+ title: import_prop_types2.default.string
713
+ }),
714
+ import_prop_types2.default.shape({
715
+ kind: import_prop_types2.default.oneOf(["header"]).isRequired,
716
+ title: import_prop_types2.default.string.isRequired
717
+ }),
718
+ import_prop_types2.default.shape({
719
+ kind: import_prop_types2.default.oneOf(["divider"]).isRequired
720
+ })
721
+ ]).isRequired
722
+ ),
723
+ /**
724
+ * The nonce to be used for inline scripts.
725
+ */
726
+ nonce: import_prop_types2.default.string,
727
+ /**
728
+ * Router implementation used inside Toolpad components.
729
+ * @default null
730
+ */
731
+ router: import_prop_types2.default.shape({
732
+ Link: import_prop_types2.default.elementType,
733
+ navigate: import_prop_types2.default.func.isRequired,
734
+ pathname: import_prop_types2.default.string.isRequired,
735
+ searchParams: import_prop_types2.default.instanceOf(URLSearchParams).isRequired
736
+ }),
737
+ /**
738
+ * Session info about the current user.
739
+ * @default null
740
+ */
741
+ session: import_prop_types2.default.shape({
742
+ user: import_prop_types2.default.shape({
743
+ email: import_prop_types2.default.string,
744
+ id: import_prop_types2.default.string,
745
+ image: import_prop_types2.default.string,
746
+ name: import_prop_types2.default.string
747
+ })
748
+ }),
749
+ /**
750
+ * [Theme or themes](https://mui.com/toolpad/core/react-app-provider/#theming) to be used by the app in light/dark mode. A [CSS variables theme](https://mui.com/material-ui/customization/css-theme-variables/overview/) is recommended.
751
+ * @default createDefaultTheme()
752
+ */
753
+ theme: import_prop_types2.default.object,
754
+ /**
755
+ * The window where the application is rendered.
756
+ * This is needed when rendering the app inside an iframe, for example.
757
+ * @default window
758
+ */
759
+ window: import_prop_types2.default.object
760
+ };
761
+
762
+ // src/toolpad-core/nextjs/NextAppProviderApp.tsx
763
+ var import_jsx_runtime7 = require("react/jsx-runtime");
764
+ var Link = React11.forwardRef((props, ref) => {
765
+ const _a = props, { href, history } = _a, rest = __objRest(_a, ["href", "history"]);
766
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_link.default, __spreadValues({ ref, href, replace: history === "replace" }, rest));
767
+ });
768
+ function NextAppProviderApp(props) {
769
+ const pathname = (0, import_navigation.usePathname)();
770
+ const searchParams = (0, import_navigation.useSearchParams)();
771
+ const { push, replace } = (0, import_navigation.useRouter)();
772
+ const navigate = React11.useCallback(
773
+ (url, { history = "auto" } = {}) => {
774
+ if (history === "auto" || history === "push") {
775
+ return push(String(url));
776
+ }
777
+ if (history === "replace") {
778
+ return replace(String(url));
779
+ }
780
+ throw new Error(`Invalid history option: ${history}`);
781
+ },
782
+ [push, replace]
783
+ );
784
+ const routerImpl = React11.useMemo(
785
+ () => ({
786
+ pathname,
787
+ searchParams,
788
+ navigate,
789
+ Link
790
+ }),
791
+ [pathname, navigate, searchParams]
792
+ );
793
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(AppProvider, __spreadValues({ router: routerImpl }, props));
794
+ }
795
+
796
+ // src/toolpad-core/nextjs/NextAppProviderPages.tsx
797
+ var React12 = __toESM(require("react"));
798
+ var import_link2 = __toESM(require("next/link.js"));
799
+ var import_router = require("next/router.js");
800
+
801
+ // src/toolpad-utils/collections.ts
802
+ function asArray(maybeArray) {
803
+ return Array.isArray(maybeArray) ? maybeArray : [maybeArray];
804
+ }
805
+
806
+ // src/toolpad-core/nextjs/NextAppProviderPages.tsx
807
+ var import_jsx_runtime8 = require("react/jsx-runtime");
808
+ var Link2 = React12.forwardRef((props, ref) => {
809
+ const _a = props, { href, history } = _a, rest = __objRest(_a, ["href", "history"]);
810
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_link2.default, __spreadValues({ ref, href, replace: history === "replace" }, rest));
811
+ });
812
+ function NextAppProviderPages(props) {
813
+ const { push, replace, asPath, query } = (0, import_router.useRouter)();
814
+ const search = React12.useMemo(() => {
815
+ const params = new URLSearchParams();
816
+ Object.entries(query != null ? query : {}).forEach(([key, value]) => {
817
+ asArray(value != null ? value : []).forEach((v) => {
818
+ params.append(key, v);
819
+ });
820
+ });
821
+ return params.toString();
822
+ }, [query]);
823
+ const searchParams = React12.useMemo(() => new URLSearchParams(search), [search]);
824
+ const navigate = React12.useCallback(
825
+ (url, { history = "auto" } = {}) => {
826
+ if (history === "auto" || history === "push") {
827
+ return push(String(url));
828
+ }
829
+ if (history === "replace") {
830
+ return replace(String(url));
831
+ }
832
+ throw new Error(`Invalid history option: ${history}`);
833
+ },
834
+ [push, replace]
835
+ );
836
+ const routerImpl = React12.useMemo(
837
+ () => ({
838
+ pathname: asPath.split("?")[0],
839
+ searchParams,
840
+ navigate,
841
+ Link: Link2
842
+ }),
843
+ [asPath, navigate, searchParams]
844
+ );
845
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(AppProvider, __spreadValues({ router: routerImpl }, props));
846
+ }
847
+
848
+ // src/toolpad-core/nextjs/NextAppProvider.tsx
849
+ var import_jsx_runtime9 = require("react/jsx-runtime");
850
+ function NextAppProvider(props) {
851
+ const router = (0, import_router2.useRouter)();
852
+ const AppProvider2 = router ? NextAppProviderPages : NextAppProviderApp;
853
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(AppProvider2, __spreadValues({}, props));
854
+ }
855
+ // Annotate the CommonJS export names for ESM import in node:
856
+ 0 && (module.exports = {
857
+ NextAppProvider
858
+ });