@iowas/toolpad 1.0.5 → 1.0.6

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.
@@ -1,10 +0,0 @@
1
- // src/toolpad-utils/warnOnce.ts
2
- var history = /* @__PURE__ */ new Set();
3
- function warnOnce(msg) {
4
- if (!history.has(msg)) {
5
- history.add(msg);
6
- console.warn(msg);
7
- }
8
- }
9
-
10
- export { warnOnce };
@@ -1,636 +0,0 @@
1
- import { __spreadValues, __spreadProps, __objRest, useNonNullableContext } from './chunk-3JWXE2JW.mjs';
2
- import * as React3 from 'react';
3
- import PropTypes2 from 'prop-types';
4
- import { useTheme, createTheme, ThemeProvider, useColorScheme } from '@mui/material/styles';
5
- import { jsx, jsxs } from 'react/jsx-runtime';
6
- import { Button, IconButton, Snackbar, Badge, Alert, SnackbarContent, useMediaQuery } from '@mui/material';
7
- import CloseIcon from '@mui/icons-material/Close';
8
- import useSlotProps from '@mui/utils/useSlotProps';
9
- import invariant from 'invariant';
10
- import useEventCallback from '@mui/utils/useEventCallback';
11
- import InitColorSchemeScript from '@mui/material/InitColorSchemeScript';
12
- import CssBaseline from '@mui/material/CssBaseline';
13
-
14
- // src/toolpad-core/locales/getLocalization.ts
15
- var getLocalization = (translations) => {
16
- return {
17
- components: {
18
- MuiLocalizationProvider: {
19
- defaultProps: {
20
- localeText: __spreadValues({}, translations)
21
- }
22
- }
23
- }
24
- };
25
- };
26
-
27
- // src/toolpad-core/locales/en.tsx
28
- var enLabels = {
29
- // Account
30
- accountSignInLabel: "Sign In",
31
- accountSignOutLabel: "Sign Out",
32
- // AccountPreview
33
- accountPreviewTitle: "Account",
34
- accountPreviewIconButtonLabel: "Current User",
35
- // SignInPage
36
- signInTitle: (brandingTitle) => brandingTitle ? `Sign in to ${brandingTitle}` : "Sign in",
37
- signInSubtitle: "Welcome user, please sign in to continue",
38
- signInRememberMe: "Remember Me",
39
- providerSignInTitle: (provider) => `Sign in with ${provider}`,
40
- // Common authentication labels
41
- email: "Email",
42
- password: "Password",
43
- username: "Username",
44
- passkey: "Passkey",
45
- // Common action labels
46
- save: "Save",
47
- cancel: "Cancel",
48
- ok: "Ok",
49
- or: "Or",
50
- to: "To",
51
- with: "With",
52
- close: "Close",
53
- delete: "Delete",
54
- alert: "Alert",
55
- confirm: "Confirm",
56
- loading: "Loading...",
57
- // CRUD
58
- createNewButtonLabel: "Create new",
59
- reloadButtonLabel: "Reload data",
60
- createLabel: "Create",
61
- createSuccessMessage: "Item created successfully.",
62
- createErrorMessage: "Failed to create item. Reason:",
63
- editLabel: "Edit",
64
- editSuccessMessage: "Item edited successfully.",
65
- editErrorMessage: "Failed to edit item. Reason:",
66
- deleteLabel: "Delete",
67
- deleteConfirmTitle: "Delete item?",
68
- deleteConfirmMessage: "Do you wish to delete this item?",
69
- deleteConfirmLabel: "Delete",
70
- deleteCancelLabel: "Cancel",
71
- deleteSuccessMessage: "Item deleted successfully.",
72
- deleteErrorMessage: "Failed to delete item. Reason:",
73
- deletedItemMessage: "This item has been deleted."
74
- };
75
- var en_default = getLocalization(enLabels);
76
- var LocalizationContext = React3.createContext({});
77
- var LocalizationProvider = function LocalizationProvider2(props) {
78
- var _a, _b, _c;
79
- const { localeText: propsLocaleText, children } = props;
80
- const theme = useTheme();
81
- 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;
82
- const defaultLocaleText2 = en_default.components.MuiLocalizationProvider.defaultProps.localeText;
83
- const localeText = React3.useMemo(
84
- () => __spreadValues(__spreadValues(__spreadValues({}, defaultLocaleText2), themeLocaleText), propsLocaleText),
85
- [defaultLocaleText2, themeLocaleText, propsLocaleText]
86
- );
87
- return /* @__PURE__ */ jsx(LocalizationContext.Provider, { value: localeText, children });
88
- };
89
- LocalizationProvider.propTypes = {
90
- // ┌────────────────────────────── Warning ──────────────────────────────┐
91
- // │ These PropTypes are generated from the TypeScript type definitions. │
92
- // │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
93
- // └─────────────────────────────────────────────────────────────────────┘
94
- /**
95
- * @ignore
96
- */
97
- children: PropTypes2.node,
98
- /**
99
- * Locale for components texts
100
- */
101
- localeText: PropTypes2.object
102
- };
103
- function useLocaleText() {
104
- return React3.useContext(LocalizationContext);
105
- }
106
- var NotificationsContext = React3.createContext(null);
107
- var RootPropsContext = React3.createContext(null);
108
- var defaultLocaleText = {
109
- close: "Close"
110
- };
111
- function Notification({ notificationKey, open, message, options, badge }) {
112
- var _a, _b, _c;
113
- const globalLocaleText = useLocaleText();
114
- const localeText = __spreadValues(__spreadValues({}, defaultLocaleText), globalLocaleText);
115
- const { close } = useNonNullableContext(NotificationsContext);
116
- const { severity, actionText, onAction, autoHideDuration } = options;
117
- const handleClose = React3.useCallback(
118
- (event, reason) => {
119
- if (reason === "clickaway") {
120
- return;
121
- }
122
- close(notificationKey);
123
- },
124
- [notificationKey, close]
125
- );
126
- const action = /* @__PURE__ */ jsxs(React3.Fragment, { children: [
127
- onAction ? /* @__PURE__ */ jsx(Button, { color: "inherit", size: "small", onClick: onAction, children: actionText != null ? actionText : "Action" }) : null,
128
- /* @__PURE__ */ jsx(
129
- IconButton,
130
- {
131
- size: "small",
132
- "aria-label": localeText == null ? void 0 : localeText.close,
133
- title: localeText == null ? void 0 : localeText.close,
134
- color: "inherit",
135
- onClick: handleClose,
136
- children: /* @__PURE__ */ jsx(CloseIcon, { fontSize: "small" })
137
- }
138
- )
139
- ] });
140
- const props = React3.useContext(RootPropsContext);
141
- const SnackbarComponent = (_b = (_a = props == null ? void 0 : props.slots) == null ? void 0 : _a.snackbar) != null ? _b : Snackbar;
142
- const snackbarSlotProps = useSlotProps({
143
- elementType: SnackbarComponent,
144
- ownerState: props,
145
- externalSlotProps: (_c = props == null ? void 0 : props.slotProps) == null ? void 0 : _c.snackbar,
146
- additionalProps: {
147
- open,
148
- autoHideDuration,
149
- onClose: handleClose,
150
- action
151
- }
152
- });
153
- return /* @__PURE__ */ jsx(SnackbarComponent, __spreadProps(__spreadValues({}, snackbarSlotProps), { children: /* @__PURE__ */ jsx(Badge, { badgeContent: badge, color: "primary", sx: { width: "100%" }, children: severity ? /* @__PURE__ */ jsx(Alert, { severity, sx: { width: "100%" }, action, children: message }) : /* @__PURE__ */ jsx(SnackbarContent, { message, action }) }) }), notificationKey);
154
- }
155
- function Notifications({ state }) {
156
- var _a;
157
- const currentNotification = (_a = state.queue[0]) != null ? _a : null;
158
- return currentNotification ? /* @__PURE__ */ jsx(
159
- Notification,
160
- __spreadProps(__spreadValues({}, currentNotification), {
161
- badge: state.queue.length > 1 ? String(state.queue.length) : null
162
- })
163
- ) : null;
164
- }
165
- var nextId = 0;
166
- var generateId = () => {
167
- const id = nextId;
168
- nextId += 1;
169
- return id;
170
- };
171
- function NotificationsProvider(props) {
172
- const { children } = props;
173
- const [state, setState] = React3.useState({ queue: [] });
174
- const show = React3.useCallback((message, options = {}) => {
175
- var _a;
176
- const notificationKey = (_a = options.key) != null ? _a : `::toolpad-internal::notification::${generateId()}`;
177
- setState((prev) => {
178
- if (prev.queue.some((n) => n.notificationKey === notificationKey)) {
179
- return prev;
180
- }
181
- return __spreadProps(__spreadValues({}, prev), {
182
- queue: [...prev.queue, { message, options, notificationKey, open: true }]
183
- });
184
- });
185
- return notificationKey;
186
- }, []);
187
- const close = React3.useCallback((key) => {
188
- setState((prev) => __spreadProps(__spreadValues({}, prev), {
189
- queue: prev.queue.filter((n) => n.notificationKey !== key)
190
- }));
191
- }, []);
192
- const contextValue = React3.useMemo(() => ({ show, close }), [show, close]);
193
- return /* @__PURE__ */ jsx(RootPropsContext.Provider, { value: props, children: /* @__PURE__ */ jsxs(NotificationsContext.Provider, { value: contextValue, children: [
194
- children,
195
- /* @__PURE__ */ jsx(Notifications, { state })
196
- ] }) });
197
- }
198
- var DialogsContext = React3.createContext(null);
199
- function DialogsProvider(props) {
200
- const { children, unmountAfter = 1e3 } = props;
201
- const [stack, setStack] = React3.useState([]);
202
- const keyPrefix = React3.useId();
203
- const nextId2 = React3.useRef(0);
204
- const dialogMetadata = React3.useRef(/* @__PURE__ */ new WeakMap());
205
- const requestDialog = useEventCallback(function open(Component, payload, options = {}) {
206
- const { onClose = async () => {
207
- } } = options;
208
- let resolve;
209
- const promise = new Promise((resolveImpl) => {
210
- resolve = resolveImpl;
211
- });
212
- invariant(resolve, "resolve not set");
213
- const key = `${keyPrefix}-${nextId2.current}`;
214
- nextId2.current += 1;
215
- const newEntry = {
216
- key,
217
- open: true,
218
- promise,
219
- Component,
220
- payload,
221
- onClose,
222
- resolve
223
- };
224
- dialogMetadata.current.set(promise, newEntry);
225
- setStack((prevStack) => [...prevStack, newEntry]);
226
- return promise;
227
- });
228
- const closeDialogUi = useEventCallback(function closeDialogUi2(dialog) {
229
- setStack(
230
- (prevStack) => prevStack.map((entry) => entry.promise === dialog ? __spreadProps(__spreadValues({}, entry), { open: false }) : entry)
231
- );
232
- setTimeout(() => {
233
- setStack((prevStack) => prevStack.filter((entry) => entry.promise !== dialog));
234
- }, unmountAfter);
235
- });
236
- const closeDialog = useEventCallback(async function closeDialog2(dialog, result) {
237
- const entryToClose = dialogMetadata.current.get(dialog);
238
- invariant(entryToClose, "dialog not found");
239
- try {
240
- await entryToClose.onClose(result);
241
- } finally {
242
- entryToClose.resolve(result);
243
- closeDialogUi(dialog);
244
- }
245
- return dialog;
246
- });
247
- const contextValue = React3.useMemo(
248
- () => ({ open: requestDialog, close: closeDialog }),
249
- [requestDialog, closeDialog]
250
- );
251
- return /* @__PURE__ */ jsxs(DialogsContext.Provider, { value: contextValue, children: [
252
- children,
253
- stack.map(({ key, open, Component, payload, promise }) => /* @__PURE__ */ jsx(
254
- Component,
255
- {
256
- payload,
257
- open,
258
- onClose: async (result) => {
259
- await closeDialog(promise, result);
260
- }
261
- },
262
- key
263
- ))
264
- ] });
265
- }
266
-
267
- // src/toolpad-core/persistence/codec.tsx
268
- var CODEC_STRING = {
269
- parse: (value) => value,
270
- stringify: (value) => value
271
- };
272
-
273
- // src/toolpad-core/persistence/useStorageState.tsx
274
- var currentTabChangeListeners = /* @__PURE__ */ new Map();
275
- function onCurrentTabStorageChange(key, handler) {
276
- let listeners = currentTabChangeListeners.get(key);
277
- if (!listeners) {
278
- listeners = /* @__PURE__ */ new Set();
279
- currentTabChangeListeners.set(key, listeners);
280
- }
281
- listeners.add(handler);
282
- }
283
- function offCurrentTabStorageChange(key, handler) {
284
- const listeners = currentTabChangeListeners.get(key);
285
- if (!listeners) {
286
- return;
287
- }
288
- listeners.delete(handler);
289
- if (listeners.size === 0) {
290
- currentTabChangeListeners.delete(key);
291
- }
292
- }
293
- function emitCurrentTabStorageChange(key) {
294
- const listeners = currentTabChangeListeners.get(key);
295
- if (listeners) {
296
- listeners.forEach((listener) => listener());
297
- }
298
- }
299
- if (typeof window !== "undefined") {
300
- const origSetItem = window.localStorage.setItem;
301
- window.localStorage.setItem = function setItem(key, value) {
302
- const result = origSetItem.call(this, key, value);
303
- emitCurrentTabStorageChange(key);
304
- return result;
305
- };
306
- }
307
- function subscribe(area, key, callback) {
308
- if (!key) {
309
- return () => {
310
- };
311
- }
312
- const storageHandler = (event) => {
313
- if (event.storageArea === area && event.key === key) {
314
- callback();
315
- }
316
- };
317
- window.addEventListener("storage", storageHandler);
318
- onCurrentTabStorageChange(key, callback);
319
- return () => {
320
- window.removeEventListener("storage", storageHandler);
321
- offCurrentTabStorageChange(key, callback);
322
- };
323
- }
324
- function getSnapshot(area, key) {
325
- if (!key) {
326
- return null;
327
- }
328
- try {
329
- return area.getItem(key);
330
- } catch (e) {
331
- return null;
332
- }
333
- }
334
- function setValue(area, key, value) {
335
- if (!key) {
336
- return;
337
- }
338
- try {
339
- if (value === null) {
340
- area.removeItem(key);
341
- } else {
342
- area.setItem(key, String(value));
343
- }
344
- } catch (e) {
345
- return;
346
- }
347
- emitCurrentTabStorageChange(key);
348
- }
349
- var serverValue = [null, () => {
350
- }];
351
- function useStorageStateServer() {
352
- return serverValue;
353
- }
354
- function encode(codec, value) {
355
- return value === null ? null : codec.stringify(value);
356
- }
357
- function decode(codec, value) {
358
- return value === null ? null : codec.parse(value);
359
- }
360
- var getKeyServerSnapshot = () => null;
361
- function useStorageState(area, key, initializer = null, options) {
362
- var _a;
363
- const codec = (_a = options == null ? void 0 : options.codec) != null ? _a : CODEC_STRING;
364
- const [initialValue] = React3.useState(initializer);
365
- const encodedInitialValue = React3.useMemo(
366
- () => encode(codec, initialValue),
367
- [codec, initialValue]
368
- );
369
- const subscribeKey = React3.useCallback(
370
- (callback) => subscribe(area, key, callback),
371
- [area, key]
372
- );
373
- const getKeySnapshot = React3.useCallback(
374
- () => {
375
- var _a2;
376
- return (_a2 = getSnapshot(area, key)) != null ? _a2 : encodedInitialValue;
377
- },
378
- [area, encodedInitialValue, key]
379
- );
380
- const encodedStoredValue = React3.useSyncExternalStore(
381
- subscribeKey,
382
- getKeySnapshot,
383
- getKeyServerSnapshot
384
- );
385
- const storedValue = React3.useMemo(
386
- () => decode(codec, encodedStoredValue),
387
- [codec, encodedStoredValue]
388
- );
389
- const setStoredValue = React3.useCallback(
390
- (value) => {
391
- const valueToStore = value instanceof Function ? value(storedValue) : value;
392
- const encodedValueToStore = encode(codec, valueToStore);
393
- setValue(area, key, encodedValueToStore);
394
- },
395
- [area, codec, storedValue, key]
396
- );
397
- const [nonStoredValue, setNonStoredValue] = React3.useState(initialValue);
398
- if (!key) {
399
- return [nonStoredValue, setNonStoredValue];
400
- }
401
- return [storedValue, setStoredValue];
402
- }
403
-
404
- // src/toolpad-core/useLocalStorageState/useLocalStorageState.tsx
405
- var useLocalStorageStateBrowser = (...args) => useStorageState(window.localStorage, ...args);
406
- var useLocalStorageState = typeof window === "undefined" ? useStorageStateServer : useLocalStorageStateBrowser;
407
- var BrandingContext = React3.createContext(null);
408
- var NavigationContext = React3.createContext([]);
409
- var PaletteModeContext = React3.createContext({
410
- paletteMode: "light",
411
- setPaletteMode: () => {
412
- },
413
- isDualTheme: false
414
- });
415
- var RouterContext = React3.createContext(null);
416
- var DashboardSidebarPageItemContext = React3.createContext(null);
417
- var WindowContext = React3.createContext(void 0);
418
- var COLOR_SCHEME_STORAGE_KEY = "toolpad-color-scheme";
419
- var MODE_STORAGE_KEY = "toolpad-mode";
420
- function usePreferredMode(window2) {
421
- const prefersDarkMode = useMediaQuery(
422
- "(prefers-color-scheme: dark)",
423
- window2 && {
424
- matchMedia: window2.matchMedia
425
- }
426
- );
427
- return prefersDarkMode ? "dark" : "light";
428
- }
429
- function isCssVarsTheme(theme) {
430
- return "vars" in theme;
431
- }
432
- function LegacyThemeProvider(props) {
433
- const { children, theme, window: appWindow } = props;
434
- invariant(!isCssVarsTheme(theme), "This provider only accepts legacy themes.");
435
- const isDualTheme = "light" in theme || "dark" in theme;
436
- const preferredMode = usePreferredMode(appWindow);
437
- const [userMode, setUserMode] = useLocalStorageState(MODE_STORAGE_KEY, "system");
438
- const paletteMode = !userMode || userMode === "system" ? preferredMode : userMode;
439
- const dualAwareTheme = React3.useMemo(
440
- () => {
441
- var _a;
442
- return isDualTheme ? (_a = theme[paletteMode === "dark" ? "dark" : "light"]) != null ? _a : theme[paletteMode === "dark" ? "light" : "dark"] : theme;
443
- },
444
- [isDualTheme, paletteMode, theme]
445
- );
446
- const paletteModeContextValue = React3.useMemo(
447
- () => ({
448
- paletteMode,
449
- setPaletteMode: setUserMode,
450
- isDualTheme
451
- }),
452
- [isDualTheme, paletteMode, setUserMode]
453
- );
454
- return /* @__PURE__ */ jsx(ThemeProvider, { theme: dualAwareTheme, children: /* @__PURE__ */ jsxs(PaletteModeContext.Provider, { value: paletteModeContextValue, children: [
455
- /* @__PURE__ */ jsx(CssBaseline, { enableColorScheme: true }),
456
- children
457
- ] }) });
458
- }
459
- function CssVarsPaletteModeProvider(props) {
460
- const { children, window: appWindow } = props;
461
- const preferredMode = usePreferredMode(appWindow);
462
- const { mode, setMode, allColorSchemes } = useColorScheme();
463
- const paletteModeContextValue = React3.useMemo(() => {
464
- return {
465
- paletteMode: !mode || mode === "system" ? preferredMode : mode,
466
- setPaletteMode: setMode,
467
- isDualTheme: allColorSchemes.length > 1
468
- };
469
- }, [allColorSchemes, mode, preferredMode, setMode]);
470
- return /* @__PURE__ */ jsx(PaletteModeContext.Provider, { value: paletteModeContextValue, children });
471
- }
472
- function CssVarsThemeProvider(props) {
473
- const { children, theme, window: appWindow, nonce } = props;
474
- invariant(isCssVarsTheme(theme), "This provider only accepts CSS vars themes.");
475
- return /* @__PURE__ */ jsxs(
476
- ThemeProvider,
477
- {
478
- theme,
479
- documentNode: appWindow == null ? void 0 : appWindow.document,
480
- colorSchemeNode: appWindow == null ? void 0 : appWindow.document.documentElement,
481
- disableNestedContext: true,
482
- colorSchemeStorageKey: COLOR_SCHEME_STORAGE_KEY,
483
- modeStorageKey: MODE_STORAGE_KEY,
484
- children: [
485
- /* @__PURE__ */ jsx(
486
- InitColorSchemeScript,
487
- {
488
- attribute: theme.colorSchemeSelector,
489
- colorSchemeStorageKey: COLOR_SCHEME_STORAGE_KEY,
490
- modeStorageKey: MODE_STORAGE_KEY,
491
- nonce
492
- }
493
- ),
494
- /* @__PURE__ */ jsxs(CssVarsPaletteModeProvider, { window: appWindow, children: [
495
- /* @__PURE__ */ jsx(CssBaseline, { enableColorScheme: true }),
496
- children
497
- ] })
498
- ]
499
- }
500
- );
501
- }
502
- function AppThemeProvider(props) {
503
- const _a = props, { children, theme } = _a, rest = __objRest(_a, ["children", "theme"]);
504
- const useCssVarsProvider = isCssVarsTheme(theme);
505
- return useCssVarsProvider ? /* @__PURE__ */ jsx(CssVarsThemeProvider, __spreadProps(__spreadValues({ theme }, rest), { children })) : /* @__PURE__ */ jsx(LegacyThemeProvider, __spreadProps(__spreadValues({ theme }, rest), { children }));
506
- }
507
- var AuthenticationContext = React3.createContext(null);
508
- var SessionContext = React3.createContext(null);
509
- function createDefaultTheme() {
510
- return createTheme({
511
- cssVariables: {
512
- colorSchemeSelector: "data-toolpad-color-scheme"
513
- },
514
- colorSchemes: { dark: true }
515
- });
516
- }
517
- function AppProvider(props) {
518
- const {
519
- children,
520
- theme = createDefaultTheme(),
521
- branding = null,
522
- navigation = [],
523
- localeText,
524
- router = null,
525
- authentication = null,
526
- session = null,
527
- window: appWindow,
528
- nonce
529
- } = props;
530
- return /* @__PURE__ */ jsx(WindowContext.Provider, { value: appWindow, children: /* @__PURE__ */ jsx(AuthenticationContext.Provider, { value: authentication, children: /* @__PURE__ */ jsx(SessionContext.Provider, { value: session, children: /* @__PURE__ */ jsx(RouterContext.Provider, { value: router, children: /* @__PURE__ */ jsx(AppThemeProvider, { theme, window: appWindow, nonce, children: /* @__PURE__ */ jsx(LocalizationProvider, { localeText, children: /* @__PURE__ */ jsx(NotificationsProvider, { children: /* @__PURE__ */ jsx(DialogsProvider, { children: /* @__PURE__ */ jsx(BrandingContext.Provider, { value: branding, children: /* @__PURE__ */ jsx(NavigationContext.Provider, { value: navigation, children }) }) }) }) }) }) }) }) }) });
531
- }
532
- AppProvider.propTypes = {
533
- // ┌────────────────────────────── Warning ──────────────────────────────┐
534
- // │ These PropTypes are generated from the TypeScript type definitions. │
535
- // │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
536
- // └─────────────────────────────────────────────────────────────────────┘
537
- /**
538
- * Authentication methods.
539
- * @default null
540
- */
541
- authentication: PropTypes2.shape({
542
- signIn: PropTypes2.func.isRequired,
543
- signOut: PropTypes2.func.isRequired
544
- }),
545
- /**
546
- * Branding options for the app.
547
- * @default null
548
- */
549
- branding: PropTypes2.shape({
550
- homeUrl: PropTypes2.string,
551
- logo: PropTypes2.node,
552
- title: PropTypes2.string
553
- }),
554
- /**
555
- * The content of the app provider.
556
- */
557
- children: PropTypes2.node,
558
- /**
559
- * Locale text for components
560
- */
561
- localeText: PropTypes2.object,
562
- /**
563
- * Navigation definition for the app. [Find out more](https://mui.com/toolpad/core/react-app-provider/#navigation).
564
- * @default []
565
- */
566
- navigation: PropTypes2.arrayOf(
567
- PropTypes2.oneOfType([
568
- PropTypes2.shape({
569
- action: PropTypes2.node,
570
- children: PropTypes2.arrayOf(
571
- PropTypes2.oneOfType([
572
- PropTypes2.object,
573
- PropTypes2.shape({
574
- kind: PropTypes2.oneOf(["header"]).isRequired,
575
- title: PropTypes2.string.isRequired
576
- }),
577
- PropTypes2.shape({
578
- kind: PropTypes2.oneOf(["divider"]).isRequired
579
- })
580
- ]).isRequired
581
- ),
582
- icon: PropTypes2.node,
583
- kind: PropTypes2.oneOf(["page"]),
584
- pattern: PropTypes2.string,
585
- segment: PropTypes2.string,
586
- title: PropTypes2.string
587
- }),
588
- PropTypes2.shape({
589
- kind: PropTypes2.oneOf(["header"]).isRequired,
590
- title: PropTypes2.string.isRequired
591
- }),
592
- PropTypes2.shape({
593
- kind: PropTypes2.oneOf(["divider"]).isRequired
594
- })
595
- ]).isRequired
596
- ),
597
- /**
598
- * The nonce to be used for inline scripts.
599
- */
600
- nonce: PropTypes2.string,
601
- /**
602
- * Router implementation used inside Toolpad components.
603
- * @default null
604
- */
605
- router: PropTypes2.shape({
606
- Link: PropTypes2.elementType,
607
- navigate: PropTypes2.func.isRequired,
608
- pathname: PropTypes2.string.isRequired,
609
- searchParams: PropTypes2.instanceOf(URLSearchParams).isRequired
610
- }),
611
- /**
612
- * Session info about the current user.
613
- * @default null
614
- */
615
- session: PropTypes2.shape({
616
- user: PropTypes2.shape({
617
- email: PropTypes2.string,
618
- id: PropTypes2.string,
619
- image: PropTypes2.string,
620
- name: PropTypes2.string
621
- })
622
- }),
623
- /**
624
- * [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.
625
- * @default createDefaultTheme()
626
- */
627
- theme: PropTypes2.object,
628
- /**
629
- * The window where the application is rendered.
630
- * This is needed when rendering the app inside an iframe, for example.
631
- * @default window
632
- */
633
- window: PropTypes2.object
634
- };
635
-
636
- export { AppProvider, AuthenticationContext, BrandingContext, DashboardSidebarPageItemContext, DialogsContext, DialogsProvider, LocalizationContext, LocalizationProvider, NavigationContext, NotificationsContext, NotificationsProvider, PaletteModeContext, RouterContext, SessionContext, WindowContext, en_default, useLocalStorageState, useLocaleText, useStorageState, useStorageStateServer };
@@ -1,53 +0,0 @@
1
- import * as React from 'react';
2
-
3
- // src/toolpad-utils/collections.ts
4
- function asArray(maybeArray) {
5
- return Array.isArray(maybeArray) ? maybeArray : [maybeArray];
6
- }
7
- function hasOwnProperty(obj, prop) {
8
- return obj.hasOwnProperty(prop);
9
- }
10
- function mapProperties(obj, mapper) {
11
- return Object.fromEntries(
12
- Object.entries(obj).flatMap((entry) => {
13
- const mapped = mapper(entry);
14
- return mapped ? [mapped] : [];
15
- })
16
- );
17
- }
18
- function mapKeys(obj, mapper) {
19
- return mapProperties(obj, ([key, value]) => [mapper(key), value]);
20
- }
21
- function mapValues(obj, mapper) {
22
- return mapProperties(obj, ([key, value]) => [key, mapper(value, key)]);
23
- }
24
- function filterValues(obj, filter) {
25
- return mapProperties(obj, ([key, value]) => filter(value) ? [key, value] : null);
26
- }
27
- function filterKeys(obj, filter) {
28
- return mapProperties(obj, ([key, value]) => filter(key) ? [key, value] : null);
29
- }
30
- function equalProperties(obj1, obj2, subset) {
31
- const keysToCheck = new Set(
32
- subset != null ? subset : [...Object.keys(obj1), ...Object.keys(obj2)]
33
- );
34
- return Array.from(keysToCheck).every((key) => Object.is(obj1[key], obj2[key]));
35
- }
36
- function useBoolean(initialValue) {
37
- const [value, setValue] = React.useState(initialValue);
38
- const toggle = React.useCallback(() => setValue((existing) => !existing), []);
39
- const setTrue = React.useCallback(() => setValue(true), []);
40
- const setFalse = React.useCallback(() => setValue(false), []);
41
- return { value, setValue, toggle, setTrue, setFalse };
42
- }
43
- function usePageTitle(title) {
44
- React.useEffect(() => {
45
- const original = document.title;
46
- document.title = title;
47
- return () => {
48
- document.title = original;
49
- };
50
- }, [title]);
51
- }
52
-
53
- export { asArray, equalProperties, filterKeys, filterValues, hasOwnProperty, mapKeys, mapProperties, mapValues, useBoolean, usePageTitle };