@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/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # toolpad
2
+
3
+ Reusable React components and hooks extracted from this repository.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pnpm add @iowas/toolpad
9
+ ```
10
+
11
+ Peer dependencies are required in the consuming app (`react`, `react-dom`, MUI, emotion, and optionally `next` for `toolpad/nextjs`).
12
+
13
+ ## Usage
14
+
15
+ ```tsx
16
+ import { AppProvider, DashboardLayout } from '@iowas/toolpad';
17
+ ```
18
+
19
+ Use subpath exports when you only need a subset:
20
+
21
+ ```tsx
22
+ import { AppProvider } from '@iowas/toolpad/core';
23
+ import { useBoolean } from '@iowas/toolpad/utils';
24
+ import { NextAppProvider } from '@iowas/toolpad/nextjs';
25
+ ```
26
+
27
+ ## Build
28
+
29
+ ```bash
30
+ pnpm install
31
+ pnpm build
32
+ ```
33
+
34
+ Build output is generated in `dist/`.
35
+
36
+ ## Reuse Locally In Another Project
37
+
38
+ From this repository:
39
+
40
+ ```bash
41
+ pnpm build
42
+ pnpm pack
43
+ ```
44
+
45
+ Then in another project:
46
+
47
+ ```bash
48
+ pnpm add /absolute/path/to/@iowas%2ftoolpad-1.0.0.tgz
49
+ ```
50
+
51
+ ## Published Exports
52
+
53
+ - `@iowas/toolpad`
54
+ - `@iowas/toolpad/core`
55
+ - `@iowas/toolpad/utils`
56
+ - `@iowas/toolpad/nextjs`
57
+
@@ -0,0 +1,201 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as React from 'react';
3
+ import { Theme } from '@mui/material/styles';
4
+
5
+ /**
6
+ * @ignore - internal component.
7
+ */
8
+ interface LinkProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> {
9
+ history?: 'auto' | 'push' | 'replace';
10
+ href: string;
11
+ }
12
+
13
+ interface LocaleText {
14
+ accountSignInLabel: string;
15
+ accountSignOutLabel: string;
16
+ accountPreviewIconButtonLabel: string;
17
+ accountPreviewTitle: string;
18
+ signInTitle: string | ((brandingTitle?: string) => string);
19
+ signInSubtitle: string;
20
+ providerSignInTitle: (provider: string) => string;
21
+ signInRememberMe: string;
22
+ email: string;
23
+ passkey: string;
24
+ username: string;
25
+ password: string;
26
+ or: string;
27
+ to: string;
28
+ with: string;
29
+ save: string;
30
+ cancel: string;
31
+ ok: string;
32
+ close: string;
33
+ delete: string;
34
+ alert: string;
35
+ confirm: string;
36
+ loading: string;
37
+ createNewButtonLabel: string;
38
+ reloadButtonLabel: string;
39
+ createLabel: string;
40
+ createSuccessMessage: string;
41
+ createErrorMessage: string;
42
+ editLabel: string;
43
+ editSuccessMessage: string;
44
+ editErrorMessage: string;
45
+ deleteLabel: string;
46
+ deleteConfirmTitle: string;
47
+ deleteConfirmMessage: string;
48
+ deleteConfirmLabel: string;
49
+ deleteCancelLabel: string;
50
+ deleteSuccessMessage: string;
51
+ deleteErrorMessage: string;
52
+ deletedItemMessage: string;
53
+ }
54
+ interface LocalizationProviderProps {
55
+ children?: React.ReactNode;
56
+ /**
57
+ * Locale for components texts
58
+ */
59
+ localeText?: Partial<LocaleText>;
60
+ }
61
+ declare const LocalizationContext: React.Context<Partial<LocaleText>>;
62
+ declare const LocalizationProvider: {
63
+ (props: LocalizationProviderProps): react_jsx_runtime.JSX.Element;
64
+ propTypes: any;
65
+ };
66
+
67
+ /**
68
+ *
69
+ * Demos:
70
+ *
71
+ * - [Sign-in Page](https://mui.com/toolpad/core/react-sign-in-page/)
72
+ *
73
+ * API:
74
+ *
75
+ * - [LocalizationProvider API](https://mui.com/toolpad/core/api/localization-provider)
76
+ */
77
+ declare function useLocaleText(): Partial<LocaleText>;
78
+
79
+ interface NavigateOptions {
80
+ history?: 'auto' | 'push' | 'replace';
81
+ }
82
+ interface Navigate {
83
+ (url: string | URL, options?: NavigateOptions): void;
84
+ }
85
+ /**
86
+ * Abstract router used by Toolpad components.
87
+ */
88
+ interface Router {
89
+ pathname: string;
90
+ searchParams: URLSearchParams;
91
+ navigate: Navigate;
92
+ Link?: React.ComponentType<LinkProps>;
93
+ }
94
+ interface Branding {
95
+ title?: string;
96
+ logo?: React.ReactNode;
97
+ homeUrl?: string;
98
+ }
99
+ interface NavigationPageItem {
100
+ kind?: 'page';
101
+ segment?: string;
102
+ title?: string;
103
+ icon?: React.ReactNode;
104
+ pattern?: string;
105
+ action?: React.ReactNode;
106
+ children?: Navigation;
107
+ }
108
+ interface NavigationSubheaderItem {
109
+ kind: 'header';
110
+ title: string;
111
+ }
112
+ interface NavigationDividerItem {
113
+ kind: 'divider';
114
+ }
115
+ type NavigationItem = NavigationPageItem | NavigationSubheaderItem | NavigationDividerItem;
116
+ type Navigation = NavigationItem[];
117
+ interface Session {
118
+ user?: {
119
+ id?: string | null;
120
+ name?: string | null;
121
+ image?: string | null;
122
+ email?: string | null;
123
+ };
124
+ }
125
+ interface Authentication {
126
+ signIn: () => void;
127
+ signOut: () => void;
128
+ }
129
+ declare const AuthenticationContext: React.Context<Authentication | null>;
130
+ declare const SessionContext: React.Context<Session | null>;
131
+ type AppTheme = Theme | {
132
+ light: Theme;
133
+ dark: Theme;
134
+ };
135
+ interface AppProviderProps {
136
+ /**
137
+ * The content of the app provider.
138
+ */
139
+ children: React.ReactNode;
140
+ /**
141
+ * [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.
142
+ * @default createDefaultTheme()
143
+ */
144
+ theme?: AppTheme;
145
+ /**
146
+ * Branding options for the app.
147
+ * @default null
148
+ */
149
+ branding?: Branding | null;
150
+ /**
151
+ * Navigation definition for the app. [Find out more](https://mui.com/toolpad/core/react-app-provider/#navigation).
152
+ * @default []
153
+ */
154
+ navigation?: Navigation;
155
+ /**
156
+ * Router implementation used inside Toolpad components.
157
+ * @default null
158
+ */
159
+ router?: Router;
160
+ /**
161
+ * Locale text for components
162
+ */
163
+ localeText?: Partial<LocaleText>;
164
+ /**
165
+ * Session info about the current user.
166
+ * @default null
167
+ */
168
+ session?: Session | null;
169
+ /**
170
+ * Authentication methods.
171
+ * @default null
172
+ */
173
+ authentication?: Authentication | null;
174
+ /**
175
+ * The window where the application is rendered.
176
+ * This is needed when rendering the app inside an iframe, for example.
177
+ * @default window
178
+ */
179
+ window?: Window;
180
+ /**
181
+ * The nonce to be used for inline scripts.
182
+ */
183
+ nonce?: string;
184
+ }
185
+ /**
186
+ *
187
+ * Demos:
188
+ *
189
+ * - [App Provider](https://mui.com/toolpad/core/react-app-provider/)
190
+ * - [Dashboard Layout](https://mui.com/toolpad/core/react-dashboard-layout/)
191
+ *
192
+ * API:
193
+ *
194
+ * - [AppProvider API](https://mui.com/toolpad/core/api/app-provider)
195
+ */
196
+ declare function AppProvider(props: AppProviderProps): react_jsx_runtime.JSX.Element;
197
+ declare namespace AppProvider {
198
+ var propTypes: any;
199
+ }
200
+
201
+ export { AppProvider as A, type Branding as B, type LocaleText as L, type Navigate as N, type Router as R, type Session as S, type AppProviderProps as a, type AppTheme as b, type Authentication as c, AuthenticationContext as d, LocalizationContext as e, LocalizationProvider as f, type LocalizationProviderProps as g, type NavigateOptions as h, type Navigation as i, type NavigationDividerItem as j, type NavigationItem as k, type NavigationPageItem as l, type NavigationSubheaderItem as m, SessionContext as n, useLocaleText as u };
@@ -0,0 +1,201 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as React from 'react';
3
+ import { Theme } from '@mui/material/styles';
4
+
5
+ /**
6
+ * @ignore - internal component.
7
+ */
8
+ interface LinkProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> {
9
+ history?: 'auto' | 'push' | 'replace';
10
+ href: string;
11
+ }
12
+
13
+ interface LocaleText {
14
+ accountSignInLabel: string;
15
+ accountSignOutLabel: string;
16
+ accountPreviewIconButtonLabel: string;
17
+ accountPreviewTitle: string;
18
+ signInTitle: string | ((brandingTitle?: string) => string);
19
+ signInSubtitle: string;
20
+ providerSignInTitle: (provider: string) => string;
21
+ signInRememberMe: string;
22
+ email: string;
23
+ passkey: string;
24
+ username: string;
25
+ password: string;
26
+ or: string;
27
+ to: string;
28
+ with: string;
29
+ save: string;
30
+ cancel: string;
31
+ ok: string;
32
+ close: string;
33
+ delete: string;
34
+ alert: string;
35
+ confirm: string;
36
+ loading: string;
37
+ createNewButtonLabel: string;
38
+ reloadButtonLabel: string;
39
+ createLabel: string;
40
+ createSuccessMessage: string;
41
+ createErrorMessage: string;
42
+ editLabel: string;
43
+ editSuccessMessage: string;
44
+ editErrorMessage: string;
45
+ deleteLabel: string;
46
+ deleteConfirmTitle: string;
47
+ deleteConfirmMessage: string;
48
+ deleteConfirmLabel: string;
49
+ deleteCancelLabel: string;
50
+ deleteSuccessMessage: string;
51
+ deleteErrorMessage: string;
52
+ deletedItemMessage: string;
53
+ }
54
+ interface LocalizationProviderProps {
55
+ children?: React.ReactNode;
56
+ /**
57
+ * Locale for components texts
58
+ */
59
+ localeText?: Partial<LocaleText>;
60
+ }
61
+ declare const LocalizationContext: React.Context<Partial<LocaleText>>;
62
+ declare const LocalizationProvider: {
63
+ (props: LocalizationProviderProps): react_jsx_runtime.JSX.Element;
64
+ propTypes: any;
65
+ };
66
+
67
+ /**
68
+ *
69
+ * Demos:
70
+ *
71
+ * - [Sign-in Page](https://mui.com/toolpad/core/react-sign-in-page/)
72
+ *
73
+ * API:
74
+ *
75
+ * - [LocalizationProvider API](https://mui.com/toolpad/core/api/localization-provider)
76
+ */
77
+ declare function useLocaleText(): Partial<LocaleText>;
78
+
79
+ interface NavigateOptions {
80
+ history?: 'auto' | 'push' | 'replace';
81
+ }
82
+ interface Navigate {
83
+ (url: string | URL, options?: NavigateOptions): void;
84
+ }
85
+ /**
86
+ * Abstract router used by Toolpad components.
87
+ */
88
+ interface Router {
89
+ pathname: string;
90
+ searchParams: URLSearchParams;
91
+ navigate: Navigate;
92
+ Link?: React.ComponentType<LinkProps>;
93
+ }
94
+ interface Branding {
95
+ title?: string;
96
+ logo?: React.ReactNode;
97
+ homeUrl?: string;
98
+ }
99
+ interface NavigationPageItem {
100
+ kind?: 'page';
101
+ segment?: string;
102
+ title?: string;
103
+ icon?: React.ReactNode;
104
+ pattern?: string;
105
+ action?: React.ReactNode;
106
+ children?: Navigation;
107
+ }
108
+ interface NavigationSubheaderItem {
109
+ kind: 'header';
110
+ title: string;
111
+ }
112
+ interface NavigationDividerItem {
113
+ kind: 'divider';
114
+ }
115
+ type NavigationItem = NavigationPageItem | NavigationSubheaderItem | NavigationDividerItem;
116
+ type Navigation = NavigationItem[];
117
+ interface Session {
118
+ user?: {
119
+ id?: string | null;
120
+ name?: string | null;
121
+ image?: string | null;
122
+ email?: string | null;
123
+ };
124
+ }
125
+ interface Authentication {
126
+ signIn: () => void;
127
+ signOut: () => void;
128
+ }
129
+ declare const AuthenticationContext: React.Context<Authentication | null>;
130
+ declare const SessionContext: React.Context<Session | null>;
131
+ type AppTheme = Theme | {
132
+ light: Theme;
133
+ dark: Theme;
134
+ };
135
+ interface AppProviderProps {
136
+ /**
137
+ * The content of the app provider.
138
+ */
139
+ children: React.ReactNode;
140
+ /**
141
+ * [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.
142
+ * @default createDefaultTheme()
143
+ */
144
+ theme?: AppTheme;
145
+ /**
146
+ * Branding options for the app.
147
+ * @default null
148
+ */
149
+ branding?: Branding | null;
150
+ /**
151
+ * Navigation definition for the app. [Find out more](https://mui.com/toolpad/core/react-app-provider/#navigation).
152
+ * @default []
153
+ */
154
+ navigation?: Navigation;
155
+ /**
156
+ * Router implementation used inside Toolpad components.
157
+ * @default null
158
+ */
159
+ router?: Router;
160
+ /**
161
+ * Locale text for components
162
+ */
163
+ localeText?: Partial<LocaleText>;
164
+ /**
165
+ * Session info about the current user.
166
+ * @default null
167
+ */
168
+ session?: Session | null;
169
+ /**
170
+ * Authentication methods.
171
+ * @default null
172
+ */
173
+ authentication?: Authentication | null;
174
+ /**
175
+ * The window where the application is rendered.
176
+ * This is needed when rendering the app inside an iframe, for example.
177
+ * @default window
178
+ */
179
+ window?: Window;
180
+ /**
181
+ * The nonce to be used for inline scripts.
182
+ */
183
+ nonce?: string;
184
+ }
185
+ /**
186
+ *
187
+ * Demos:
188
+ *
189
+ * - [App Provider](https://mui.com/toolpad/core/react-app-provider/)
190
+ * - [Dashboard Layout](https://mui.com/toolpad/core/react-dashboard-layout/)
191
+ *
192
+ * API:
193
+ *
194
+ * - [AppProvider API](https://mui.com/toolpad/core/api/app-provider)
195
+ */
196
+ declare function AppProvider(props: AppProviderProps): react_jsx_runtime.JSX.Element;
197
+ declare namespace AppProvider {
198
+ var propTypes: any;
199
+ }
200
+
201
+ export { AppProvider as A, type Branding as B, type LocaleText as L, type Navigate as N, type Router as R, type Session as S, type AppProviderProps as a, type AppTheme as b, type Authentication as c, AuthenticationContext as d, LocalizationContext as e, LocalizationProvider as f, type LocalizationProviderProps as g, type NavigateOptions as h, type Navigation as i, type NavigationDividerItem as j, type NavigationItem as k, type NavigationPageItem as l, type NavigationSubheaderItem as m, SessionContext as n, useLocaleText as u };
@@ -0,0 +1,125 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __objRest = (source, exclude) => {
21
+ var target = {};
22
+ for (var prop in source)
23
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
+ target[prop] = source[prop];
25
+ if (source != null && __getOwnPropSymbols)
26
+ for (var prop of __getOwnPropSymbols(source)) {
27
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
+ target[prop] = source[prop];
29
+ }
30
+ return target;
31
+ };
32
+
33
+ // src/toolpad-utils/react.tsx
34
+ import * as React from "react";
35
+ import * as ReactIs from "react-is";
36
+ import { jsx } from "react/jsx-runtime";
37
+ function interleave(items, separator) {
38
+ const result = [];
39
+ for (let i = 0; i < items.length; i += 1) {
40
+ if (i > 0) {
41
+ if (ReactIs.isElement(separator)) {
42
+ result.push(React.cloneElement(separator, { key: `separator-${i}` }));
43
+ } else {
44
+ result.push(separator);
45
+ }
46
+ }
47
+ const item = items[i];
48
+ result.push(item);
49
+ }
50
+ return /* @__PURE__ */ jsx(React.Fragment, { children: result });
51
+ }
52
+ function useNonNullableContext(context, name) {
53
+ const maybeContext = React.useContext(context);
54
+ if (maybeContext === null || maybeContext === void 0) {
55
+ throw new Error(`context "${name}" was used without a Provider`);
56
+ }
57
+ return maybeContext;
58
+ }
59
+ function createProvidedContext(name) {
60
+ const context = React.createContext(void 0);
61
+ const useContext2 = () => useNonNullableContext(context, name);
62
+ return [useContext2, context.Provider];
63
+ }
64
+ function useAssertedContext(context) {
65
+ const value = React.useContext(context);
66
+ if (value === void 0) {
67
+ throw new Error("context was used without a Provider");
68
+ }
69
+ return value;
70
+ }
71
+ function useTraceUpdates(prefix, props) {
72
+ const prev = React.useRef(props);
73
+ React.useEffect(() => {
74
+ const changedProps = {};
75
+ for (const key of Object.keys(props)) {
76
+ if (!Object.is(prev.current[key], props[key])) {
77
+ changedProps[key] = props[key];
78
+ }
79
+ }
80
+ if (Object.keys(changedProps).length > 0) {
81
+ console.log(`${prefix} changed props:`, changedProps);
82
+ }
83
+ prev.current = props;
84
+ });
85
+ }
86
+ function createGlobalState(initialState) {
87
+ let state = initialState;
88
+ const listeners = [];
89
+ const subscribe = (cb) => {
90
+ listeners.push(cb);
91
+ return () => {
92
+ const index = listeners.indexOf(cb);
93
+ listeners.splice(index, 1);
94
+ };
95
+ };
96
+ const getState = () => state;
97
+ const setState = (newState) => {
98
+ state = typeof newState === "function" ? newState(state) : newState;
99
+ listeners.forEach((cb) => cb(state));
100
+ };
101
+ const useValue = () => React.useSyncExternalStore(subscribe, getState, getState);
102
+ const useState = () => {
103
+ const value = useValue();
104
+ return [value, setState];
105
+ };
106
+ return {
107
+ getState,
108
+ setState,
109
+ useValue,
110
+ useState,
111
+ subscribe
112
+ };
113
+ }
114
+
115
+ export {
116
+ __spreadValues,
117
+ __spreadProps,
118
+ __objRest,
119
+ interleave,
120
+ useNonNullableContext,
121
+ createProvidedContext,
122
+ useAssertedContext,
123
+ useTraceUpdates,
124
+ createGlobalState
125
+ };
@@ -0,0 +1,26 @@
1
+ // src/toolpad-utils/hooks/useBoolean.ts
2
+ import * as React from "react";
3
+ function useBoolean(initialValue) {
4
+ const [value, setValue] = React.useState(initialValue);
5
+ const toggle = React.useCallback(() => setValue((existing) => !existing), []);
6
+ const setTrue = React.useCallback(() => setValue(true), []);
7
+ const setFalse = React.useCallback(() => setValue(false), []);
8
+ return { value, setValue, toggle, setTrue, setFalse };
9
+ }
10
+
11
+ // src/toolpad-utils/hooks/usePageTitle.ts
12
+ import * as React2 from "react";
13
+ function usePageTitle(title) {
14
+ React2.useEffect(() => {
15
+ const original = document.title;
16
+ document.title = title;
17
+ return () => {
18
+ document.title = original;
19
+ };
20
+ }, [title]);
21
+ }
22
+
23
+ export {
24
+ useBoolean,
25
+ usePageTitle
26
+ };
@@ -0,0 +1,12 @@
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 {
11
+ warnOnce
12
+ };