diff --git a/packages/toolpad-app/src/appDom/index.ts b/packages/toolpad-app/src/appDom/index.ts index c3d9b0b05e3..bb6ef3675e9 100644 --- a/packages/toolpad-app/src/appDom/index.ts +++ b/packages/toolpad-app/src/appDom/index.ts @@ -13,9 +13,9 @@ import invariant from 'invariant'; import { BoxProps, ThemeOptions as MuiThemeOptions } from '@mui/material'; import { guessTitle, pascalCase, removeDiacritics, uncapitalize } from '@mui/toolpad-utils/strings'; import { mapProperties, mapValues, hasOwnProperty } from '@mui/toolpad-utils/collections'; +import { ExactEntriesOf, Maybe } from '@mui/toolpad-utils/types'; import { AuthProviderConfig, ConnectionStatus } from '../types'; import { omit, update, updateOrCreate } from '../utils/immutability'; -import { ExactEntriesOf, Maybe } from '../utils/types'; import { envBindingSchema } from '../server/schema'; export const CURRENT_APPDOM_VERSION = 7; diff --git a/packages/toolpad-app/src/components/MapEntriesEditor.tsx b/packages/toolpad-app/src/components/MapEntriesEditor.tsx index f626acbf2e4..175553e1041 100644 --- a/packages/toolpad-app/src/components/MapEntriesEditor.tsx +++ b/packages/toolpad-app/src/components/MapEntriesEditor.tsx @@ -1,7 +1,7 @@ import { Box, TextField, IconButton, SxProps } from '@mui/material'; import * as React from 'react'; import DeleteIcon from '@mui/icons-material/Delete'; -import { WithControlledProp } from '../utils/types'; +import { WithControlledProp } from '@mui/toolpad-utils/types'; function renderStringValueEditor({ label, diff --git a/packages/toolpad-app/src/components/MuiThemeEditor.tsx b/packages/toolpad-app/src/components/MuiThemeEditor.tsx index 929c42ab1d4..6640314c81b 100644 --- a/packages/toolpad-app/src/components/MuiThemeEditor.tsx +++ b/packages/toolpad-app/src/components/MuiThemeEditor.tsx @@ -16,7 +16,7 @@ import { } from '@mui/material'; import LightModeIcon from '@mui/icons-material/LightMode'; import DarkModeIcon from '@mui/icons-material/DarkMode'; -import { WithControlledProp } from '../utils/types'; +import { WithControlledProp } from '@mui/toolpad-utils/types'; import ColorTool from './ColorTool'; import FlexFill from './FlexFill'; diff --git a/packages/toolpad-app/src/server/EnvManager.ts b/packages/toolpad-app/src/server/EnvManager.ts index 23d09787d43..45bbd0b35bc 100644 --- a/packages/toolpad-app/src/server/EnvManager.ts +++ b/packages/toolpad-app/src/server/EnvManager.ts @@ -4,8 +4,8 @@ import * as dotenv from 'dotenv'; import { Emitter } from '@mui/toolpad-utils/events'; import chalk from 'chalk'; import { truncate } from '@mui/toolpad-utils/strings'; +import { Awaitable } from '@mui/toolpad-utils/types'; import { ProjectEvents, ToolpadProjectOptions } from '../types'; -import { Awaitable } from '../utils/types'; interface IToolpadProject { options: ToolpadProjectOptions; diff --git a/packages/toolpad-app/src/server/FunctionsManager.ts b/packages/toolpad-app/src/server/FunctionsManager.ts index 5ca79621cba..ebf8e67b6d6 100644 --- a/packages/toolpad-app/src/server/FunctionsManager.ts +++ b/packages/toolpad-app/src/server/FunctionsManager.ts @@ -19,11 +19,11 @@ import { ToolpadDataProviderIntrospection } from '@mui/toolpad-core/runtime'; import * as url from 'node:url'; import type { GridRowId } from '@mui/x-data-grid'; import invariant from 'invariant'; +import { Awaitable } from '@mui/toolpad-utils/types'; import EnvManager from './EnvManager'; import { ProjectEvents, ToolpadProjectOptions } from '../types'; import * as functionsRuntime from './functionsRuntime'; import type { ExtractTypesParams, IntrospectionResult } from './functionsTypesWorker'; -import { Awaitable } from '../utils/types'; import { format } from '../utils/prettier'; import { compilerOptions } from './functionsShared'; diff --git a/packages/toolpad-app/src/server/localMode.ts b/packages/toolpad-app/src/server/localMode.ts index 3e01bc3e62f..d3c51f44347 100644 --- a/packages/toolpad-app/src/server/localMode.ts +++ b/packages/toolpad-app/src/server/localMode.ts @@ -24,6 +24,7 @@ import { readJsonFile, } from '@mui/toolpad-utils/fs'; import { z } from 'zod'; +import { Awaitable } from '@mui/toolpad-utils/types'; import * as appDom from '../appDom'; import insecureHash from '../utils/insecureHash'; import { @@ -57,7 +58,6 @@ import type { ToolpadProjectOptions, CodeEditorFileType, } from '../types'; -import { Awaitable } from '../utils/types'; import EnvManager from './EnvManager'; import FunctionsManager, { CreateDataProviderOptions } from './FunctionsManager'; import { VersionInfo, checkVersion } from './versionInfo'; diff --git a/packages/toolpad-app/src/toolpad/AppEditor/BindingEditor.tsx b/packages/toolpad-app/src/toolpad/AppEditor/BindingEditor.tsx index 035d2511462..0c02bd0f4dd 100644 --- a/packages/toolpad-app/src/toolpad/AppEditor/BindingEditor.tsx +++ b/packages/toolpad-app/src/toolpad/AppEditor/BindingEditor.tsx @@ -38,11 +38,11 @@ import { TabContext, TabList } from '@mui/lab'; import useDebounced from '@mui/toolpad-utils/hooks/useDebounced'; import { errorFrom } from '@mui/toolpad-utils/errors'; import useLatest from '@mui/toolpad-utils/hooks/useLatest'; +import { WithControlledProp, Maybe } from '@mui/toolpad-utils/types'; import { JsExpressionEditor } from './PageEditor/JsExpressionEditor'; import JsonView from '../../components/JsonView'; import { useEvaluateLiveBinding } from './useEvaluateLiveBinding'; import GlobalScopeExplorer from './GlobalScopeExplorer'; -import { WithControlledProp, Maybe } from '../../utils/types'; import { tryFormatExpression } from '../../utils/prettier'; import useShortcut from '../../utils/useShortcut'; diff --git a/packages/toolpad-app/src/toolpad/AppEditor/NoPageFound.tsx b/packages/toolpad-app/src/toolpad/AppEditor/NoPageFound.tsx index ece6e837f32..05bdaf949c1 100644 --- a/packages/toolpad-app/src/toolpad/AppEditor/NoPageFound.tsx +++ b/packages/toolpad-app/src/toolpad/AppEditor/NoPageFound.tsx @@ -1,6 +1,6 @@ import { Grid, Typography, Button } from '@mui/material'; import * as React from 'react'; -import useBoolean from '../../utils/useBoolean'; +import useBoolean from '@mui/toolpad-utils/hooks/useBoolean'; import CreatePageNodeDialog from './PagesExplorer/CreatePageNodeDialog'; export default function NoPageFound() { diff --git a/packages/toolpad-app/src/toolpad/AppEditor/PageEditor/BindableEditor.tsx b/packages/toolpad-app/src/toolpad/AppEditor/PageEditor/BindableEditor.tsx index 882e878b8ee..b36968d01e4 100644 --- a/packages/toolpad-app/src/toolpad/AppEditor/PageEditor/BindableEditor.tsx +++ b/packages/toolpad-app/src/toolpad/AppEditor/PageEditor/BindableEditor.tsx @@ -14,7 +14,7 @@ import { ScopeMeta, EnvAttrValue, } from '@mui/toolpad-core'; -import { WithControlledProp } from '../../../utils/types'; +import { WithControlledProp } from '@mui/toolpad-utils/types'; import { getBindingType } from '../../../runtime/bindings'; import { getDefaultControl, usePropControlsContext } from '../../propertyControls'; diff --git a/packages/toolpad-app/src/toolpad/AppEditor/PageEditor/ComponentEditor.tsx b/packages/toolpad-app/src/toolpad/AppEditor/PageEditor/ComponentEditor.tsx index 51bf95c18c5..a385c84009b 100644 --- a/packages/toolpad-app/src/toolpad/AppEditor/PageEditor/ComponentEditor.tsx +++ b/packages/toolpad-app/src/toolpad/AppEditor/PageEditor/ComponentEditor.tsx @@ -9,7 +9,7 @@ import { ComponentConfig, LiveBinding, } from '@mui/toolpad-core'; -import { ExactEntriesOf } from '../../../utils/types'; +import { ExactEntriesOf } from '@mui/toolpad-utils/types'; import * as appDom from '../../../appDom'; import NodeAttributeEditor from './NodeAttributeEditor'; import { usePageEditorState } from './PageEditorProvider'; diff --git a/packages/toolpad-app/src/toolpad/AppEditor/PageEditor/ConnectionSelect.tsx b/packages/toolpad-app/src/toolpad/AppEditor/PageEditor/ConnectionSelect.tsx index 612adf88525..a0e9c55c035 100644 --- a/packages/toolpad-app/src/toolpad/AppEditor/PageEditor/ConnectionSelect.tsx +++ b/packages/toolpad-app/src/toolpad/AppEditor/PageEditor/ConnectionSelect.tsx @@ -2,8 +2,8 @@ import { TextField, MenuItem, SxProps } from '@mui/material'; import * as React from 'react'; import { NodeId } from '@mui/toolpad-core'; import { asArray } from '@mui/toolpad-utils/collections'; +import { Maybe, WithControlledProp } from '@mui/toolpad-utils/types'; import * as appDom from '../../../appDom'; -import { Maybe, WithControlledProp } from '../../../utils/types'; import { useAppState } from '../../AppState'; import dataSources from '../../../toolpadDataSources/client'; diff --git a/packages/toolpad-app/src/toolpad/AppEditor/PageEditor/JsExpressionEditor.tsx b/packages/toolpad-app/src/toolpad/AppEditor/PageEditor/JsExpressionEditor.tsx index 36d84b87cc6..5a76e6f2832 100644 --- a/packages/toolpad-app/src/toolpad/AppEditor/PageEditor/JsExpressionEditor.tsx +++ b/packages/toolpad-app/src/toolpad/AppEditor/PageEditor/JsExpressionEditor.tsx @@ -3,7 +3,7 @@ import jsonToTs from 'json-to-ts'; import { Skeleton, styled, SxProps } from '@mui/material'; import { ScopeMeta } from '@mui/toolpad-core'; import { getCircularReplacer, replaceRecursive } from '@mui/toolpad-utils/json'; -import { WithControlledProp } from '../../../utils/types'; +import { WithControlledProp } from '@mui/toolpad-utils/types'; import lazyComponent from '../../../utils/lazyComponent'; import ElementContext from '../ElementContext'; diff --git a/packages/toolpad-app/src/toolpad/AppEditor/PageEditor/ParametersEditor.tsx b/packages/toolpad-app/src/toolpad/AppEditor/PageEditor/ParametersEditor.tsx index fd3ce40bd8b..f651e6fb504 100644 --- a/packages/toolpad-app/src/toolpad/AppEditor/PageEditor/ParametersEditor.tsx +++ b/packages/toolpad-app/src/toolpad/AppEditor/PageEditor/ParametersEditor.tsx @@ -2,7 +2,7 @@ import { Box, TextField, IconButton, SxProps, inputLabelClasses } from '@mui/mat import * as React from 'react'; import DeleteIcon from '@mui/icons-material/Delete'; import { BindableAttrValue, ScopeMeta, JsRuntime, LiveBinding } from '@mui/toolpad-core'; -import { WithControlledProp } from '../../../utils/types'; +import { WithControlledProp } from '@mui/toolpad-utils/types'; import BindableEditor from './BindableEditor'; export interface StringRecordEntriesEditorProps diff --git a/packages/toolpad-app/src/toolpad/AppEditor/PageEditor/QueriesExplorer/index.tsx b/packages/toolpad-app/src/toolpad/AppEditor/PageEditor/QueriesExplorer/index.tsx index b48bee1bd1d..f600f848eee 100644 --- a/packages/toolpad-app/src/toolpad/AppEditor/PageEditor/QueriesExplorer/index.tsx +++ b/packages/toolpad-app/src/toolpad/AppEditor/PageEditor/QueriesExplorer/index.tsx @@ -18,11 +18,11 @@ import AddIcon from '@mui/icons-material/Add'; import MoreVertIcon from '@mui/icons-material/MoreVert'; import ExpandMoreIcon from '@mui/icons-material/ExpandMore'; import ChevronRightIcon from '@mui/icons-material/ChevronRight'; +import useBoolean from '@mui/toolpad-utils/hooks/useBoolean'; import * as appDom from '../../../../appDom'; import dataSources from '../../../../toolpadDataSources/client'; import QueryIcon from '../../QueryIcon'; import { useAppState, useAppStateApi } from '../../../AppState'; -import useBoolean from '../../../../utils/useBoolean'; import EditableTreeItem, { EditableTreeItemProps } from '../../../../components/EditableTreeItem'; import NodeMenu from '../../NodeMenu'; import ExplorerHeader from '../../ExplorerHeader'; diff --git a/packages/toolpad-app/src/toolpad/AppEditor/PageEditor/UrlQueryEditor.tsx b/packages/toolpad-app/src/toolpad/AppEditor/PageEditor/UrlQueryEditor.tsx index 9c11e07e5a9..fd545773012 100644 --- a/packages/toolpad-app/src/toolpad/AppEditor/PageEditor/UrlQueryEditor.tsx +++ b/packages/toolpad-app/src/toolpad/AppEditor/PageEditor/UrlQueryEditor.tsx @@ -11,10 +11,10 @@ import { import * as React from 'react'; import AddIcon from '@mui/icons-material/Add'; import { NodeId } from '@mui/toolpad-core'; +import useBoolean from '@mui/toolpad-utils/hooks/useBoolean'; import * as appDom from '../../../appDom'; import { useAppState, useDomApi, useAppStateApi } from '../../AppState'; import MapEntriesEditor from '../../../components/MapEntriesEditor'; -import useBoolean from '../../../utils/useBoolean'; import useUnsavedChangesConfirm from '../../hooks/useUnsavedChangesConfirm'; export interface UrlQueryEditorProps { diff --git a/packages/toolpad-app/src/toolpad/AppEditor/PagesExplorer/index.tsx b/packages/toolpad-app/src/toolpad/AppEditor/PagesExplorer/index.tsx index ff42fa79b70..f955dcd27bd 100644 --- a/packages/toolpad-app/src/toolpad/AppEditor/PagesExplorer/index.tsx +++ b/packages/toolpad-app/src/toolpad/AppEditor/PagesExplorer/index.tsx @@ -8,13 +8,13 @@ import { NodeId } from '@mui/toolpad-core'; import clsx from 'clsx'; import invariant from 'invariant'; import { alphabeticComparator, createPropComparator } from '@mui/toolpad-utils/comparators'; +import useBoolean from '@mui/toolpad-utils/hooks/useBoolean'; import * as appDom from '../../../appDom'; import { useAppStateApi, useAppState, useDomApi } from '../../AppState'; import useLocalStorageState from '../../../utils/useLocalStorageState'; import NodeMenu from '../NodeMenu'; import { DomView } from '../../../utils/domView'; import { useProjectApi } from '../../../projectApi'; -import useBoolean from '../../../utils/useBoolean'; import EditableTreeItem, { EditableTreeItemProps } from '../../../components/EditableTreeItem'; import { scrollIntoViewIfNeeded } from '../../../utils/dom'; import ExplorerHeader from '../ExplorerHeader'; diff --git a/packages/toolpad-app/src/toolpad/AppOptions/index.tsx b/packages/toolpad-app/src/toolpad/AppOptions/index.tsx index ddf0df0572d..cec8e93cd57 100644 --- a/packages/toolpad-app/src/toolpad/AppOptions/index.tsx +++ b/packages/toolpad-app/src/toolpad/AppOptions/index.tsx @@ -3,8 +3,8 @@ import { Divider, ListItemIcon, ListItemText, Menu, MenuItem } from '@mui/materi import IconButton from '@mui/material/IconButton'; import MoreVertIcon from '@mui/icons-material/MoreVert'; import CodeIcon from '@mui/icons-material/Code'; +import useBoolean from '@mui/toolpad-utils/hooks/useBoolean'; import useMenu from '../../utils/useMenu'; -import useBoolean from '../../utils/useBoolean'; import AppExportDialog from './AppExportDialog'; import * as appDom from '../../appDom'; diff --git a/packages/toolpad-app/src/toolpad/Toolpad.tsx b/packages/toolpad-app/src/toolpad/Toolpad.tsx index 9f4200becf1..b7c4803b92b 100644 --- a/packages/toolpad-app/src/toolpad/Toolpad.tsx +++ b/packages/toolpad-app/src/toolpad/Toolpad.tsx @@ -7,6 +7,7 @@ import CloudDoneIcon from '@mui/icons-material/CloudDone'; import SyncIcon from '@mui/icons-material/Sync'; import SyncProblemIcon from '@mui/icons-material/SyncProblem'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; +import useBoolean from '@mui/toolpad-utils/hooks/useBoolean'; import AppEditor from './AppEditor'; import ErrorAlert from './AppEditor/PageEditor/ErrorAlert'; import { ThemeProvider } from '../ThemeContext'; @@ -17,7 +18,6 @@ import AppProvider, { AppState, useAppStateContext } from './AppState'; import { FEATURE_FLAG_AUTHORIZATION, FEATURE_FLAG_GLOBAL_FUNCTIONS } from '../constants'; import { ProjectProvider } from '../project'; import AppAuthorizationDialog from './AppEditor/AppAuthorizationEditor'; -import useBoolean from '../utils/useBoolean'; const Centered = styled('div')({ height: '100%', diff --git a/packages/toolpad-app/src/toolpad/ToolpadShell/Header/UserFeedback/index.tsx b/packages/toolpad-app/src/toolpad/ToolpadShell/Header/UserFeedback/index.tsx index 927d1b2f6dc..66938fe2318 100644 --- a/packages/toolpad-app/src/toolpad/ToolpadShell/Header/UserFeedback/index.tsx +++ b/packages/toolpad-app/src/toolpad/ToolpadShell/Header/UserFeedback/index.tsx @@ -18,10 +18,10 @@ import { import HelpOutlinedIcon from '@mui/icons-material/HelpOutlined'; import OpenInNewIcon from '@mui/icons-material/OpenInNew'; import invariant from 'invariant'; +import useBoolean from '@mui/toolpad-utils/hooks/useBoolean'; import useMenu from '../../../../utils/useMenu'; import { DOCUMENTATION_URL, VERSION_CHECK_INTERVAL } from '../../../../constants'; import { useProjectApi } from '../../../../projectApi'; -import useBoolean from '../../../../utils/useBoolean'; import type { PackageManager } from '../../../../server/versionInfo'; const REPORT_BUG_URL = diff --git a/packages/toolpad-app/src/toolpadDataSources/googleSheets/server.ts b/packages/toolpad-app/src/toolpadDataSources/googleSheets/server.ts index 75899fb03dd..109646d7f71 100644 --- a/packages/toolpad-app/src/toolpadDataSources/googleSheets/server.ts +++ b/packages/toolpad-app/src/toolpadDataSources/googleSheets/server.ts @@ -4,6 +4,7 @@ import { OAuth2Client } from 'google-auth-library'; import { match } from 'path-to-regexp'; import { asArray } from '@mui/toolpad-utils/collections'; import * as express from 'express'; +import { Maybe } from '@mui/toolpad-utils/types'; import { ServerDataSource, CreateHandlerApi } from '../../types'; import config from '../../server/config'; import { @@ -12,7 +13,6 @@ import { GoogleSheetsApiQuery, GoogleSheetsResult, } from './types'; -import { Maybe } from '../../utils/types'; import type { IToolpadProject } from '../server'; /** diff --git a/packages/toolpad-app/src/toolpadDataSources/local/server.ts b/packages/toolpad-app/src/toolpadDataSources/local/server.ts index ba55c61293a..c901f8e540a 100644 --- a/packages/toolpad-app/src/toolpadDataSources/local/server.ts +++ b/packages/toolpad-app/src/toolpadDataSources/local/server.ts @@ -1,7 +1,7 @@ import { ExecFetchResult } from '@mui/toolpad-core'; +import { Maybe } from '@mui/toolpad-utils/types'; import { ServerDataSource } from '../../types'; import { LocalQuery, LocalConnectionParams, LocalPrivateApi } from './types'; -import { Maybe } from '../../utils/types'; import { parseLegacyFunctionId } from './shared'; import type { IToolpadProject } from '../server'; diff --git a/packages/toolpad-app/src/toolpadDataSources/mysql/server.ts b/packages/toolpad-app/src/toolpadDataSources/mysql/server.ts index c80c0063270..2639c8ad85e 100644 --- a/packages/toolpad-app/src/toolpadDataSources/mysql/server.ts +++ b/packages/toolpad-app/src/toolpadDataSources/mysql/server.ts @@ -1,6 +1,6 @@ import { createConnection, OkPacket, ResultSetHeader } from 'mysql2/promise'; import { errorFrom } from '@mui/toolpad-utils/errors'; -import { Maybe } from '../../utils/types'; +import { Maybe } from '@mui/toolpad-utils/types'; import { SqlConnectionParams, SqlQuery, SqlResult } from '../sql/types'; import { createSqlServerDatasource } from '../sql/server'; diff --git a/packages/toolpad-app/src/toolpadDataSources/postgres/server.ts b/packages/toolpad-app/src/toolpadDataSources/postgres/server.ts index 18708a9ced5..9e5d41c4d88 100644 --- a/packages/toolpad-app/src/toolpadDataSources/postgres/server.ts +++ b/packages/toolpad-app/src/toolpadDataSources/postgres/server.ts @@ -1,6 +1,6 @@ import pg from 'pg'; import { errorFrom } from '@mui/toolpad-utils/errors'; -import { Maybe } from '../../utils/types'; +import { Maybe } from '@mui/toolpad-utils/types'; import { SqlConnectionParams, SqlQuery, SqlResult } from '../sql/types'; import { createSqlServerDatasource } from '../sql/server'; diff --git a/packages/toolpad-app/src/toolpadDataSources/rest/AuthenticationEditor.tsx b/packages/toolpad-app/src/toolpadDataSources/rest/AuthenticationEditor.tsx index 8c69efb2bab..5141f2836e1 100644 --- a/packages/toolpad-app/src/toolpadDataSources/rest/AuthenticationEditor.tsx +++ b/packages/toolpad-app/src/toolpadDataSources/rest/AuthenticationEditor.tsx @@ -1,7 +1,7 @@ import * as React from 'react'; import { Grid, MenuItem, Stack, TextField } from '@mui/material'; +import { Maybe, WithControlledProp } from '@mui/toolpad-utils/types'; import { ApiKeyAuth, Authentication, BasicAuth, BearerTokenAuth } from './types'; -import { Maybe, WithControlledProp } from '../../utils/types'; interface AuthMethodEditorProps extends WithControlledProp { disabled?: boolean; diff --git a/packages/toolpad-app/src/toolpadDataSources/rest/BodyEditor.tsx b/packages/toolpad-app/src/toolpadDataSources/rest/BodyEditor.tsx index 4181b7d9cc2..21601c10842 100644 --- a/packages/toolpad-app/src/toolpadDataSources/rest/BodyEditor.tsx +++ b/packages/toolpad-app/src/toolpadDataSources/rest/BodyEditor.tsx @@ -16,8 +16,8 @@ import { import { TabContext } from '@mui/lab'; import { BindableAttrValue, LiveBinding, ScopeMeta } from '@mui/toolpad-core'; import { useServerJsRuntime } from '@mui/toolpad-core/jsServerRuntime'; +import { Maybe, WithControlledProp } from '@mui/toolpad-utils/types'; import { Body, RawBody, UrlEncodedBody } from './types'; -import { Maybe, WithControlledProp } from '../../utils/types'; import { useEvaluateLiveBinding, useEvaluateLiveBindingEntries, diff --git a/packages/toolpad-app/src/toolpadDataSources/rest/client.tsx b/packages/toolpad-app/src/toolpadDataSources/rest/client.tsx index cb5503b5e78..4ca4731196b 100644 --- a/packages/toolpad-app/src/toolpadDataSources/rest/client.tsx +++ b/packages/toolpad-app/src/toolpadDataSources/rest/client.tsx @@ -21,6 +21,7 @@ import PlayArrowIcon from '@mui/icons-material/PlayArrow'; import { Controller, useForm } from 'react-hook-form'; import { TabContext, TabList } from '@mui/lab'; import { createServerJsRuntime } from '@mui/toolpad-core/jsServerRuntime'; +import { Maybe } from '@mui/toolpad-utils/types'; import { Panel, PanelGroup, PanelResizeHandle } from '../../components/resizablePanels'; import { ClientDataSource, ConnectionEditorProps, QueryEditorProps } from '../../types'; import { @@ -41,7 +42,6 @@ import { useEvaluateLiveBindingEntries, } from '../../toolpad/AppEditor/useEvaluateLiveBinding'; import MapEntriesEditor from '../../components/MapEntriesEditor'; -import { Maybe } from '../../utils/types'; import AuthenticationEditor from './AuthenticationEditor'; import { isSaveDisabled, validation } from '../../utils/forms'; import { useAppState, useAppStateApi } from '../../toolpad/AppState'; diff --git a/packages/toolpad-app/src/toolpadDataSources/rest/server.ts b/packages/toolpad-app/src/toolpadDataSources/rest/server.ts index bf490d91609..8f82a77692e 100644 --- a/packages/toolpad-app/src/toolpadDataSources/rest/server.ts +++ b/packages/toolpad-app/src/toolpadDataSources/rest/server.ts @@ -10,6 +10,7 @@ import { createServerJsRuntime } from '@mui/toolpad-core/jsServerRuntime'; import { SerializedError, errorFrom, serializeError } from '@mui/toolpad-utils/errors'; import { evaluateBindable } from '@mui/toolpad-core/jsRuntime'; import { removePrefix } from '@mui/toolpad-utils/strings'; +import { Maybe } from '@mui/toolpad-utils/types'; import { withHarInstrumentation, createHarLog } from '../../server/har'; import { ServerDataSource } from '../../types'; import { @@ -21,7 +22,6 @@ import { RestConnectionParams, UrlEncodedBody, } from './types'; -import { Maybe } from '../../utils/types'; import applyTransform from '../applyTransform'; import { HTTP_NO_BODY, getAuthenticationHeaders, getDefaultUrl, parseBaseUrl } from './shared'; import type { IToolpadProject } from '../server'; diff --git a/packages/toolpad-app/src/toolpadDataSources/rest/shared.ts b/packages/toolpad-app/src/toolpadDataSources/rest/shared.ts index 283abef15bc..33cc8513d08 100644 --- a/packages/toolpad-app/src/toolpadDataSources/rest/shared.ts +++ b/packages/toolpad-app/src/toolpadDataSources/rest/shared.ts @@ -1,6 +1,6 @@ import { BindableAttrValue } from '@mui/toolpad-core'; import { ensureSuffix } from '@mui/toolpad-utils/strings'; -import { Maybe } from '../../utils/types'; +import { Maybe } from '@mui/toolpad-utils/types'; import { Authentication, RestConnectionParams } from './types'; import type { RuntimeConfig } from '../../types'; diff --git a/packages/toolpad-app/src/toolpadDataSources/rest/types.ts b/packages/toolpad-app/src/toolpadDataSources/rest/types.ts index b9a3651977d..ed5d7c5f1a9 100644 --- a/packages/toolpad-app/src/toolpadDataSources/rest/types.ts +++ b/packages/toolpad-app/src/toolpadDataSources/rest/types.ts @@ -1,6 +1,6 @@ import { BindableAttrValue, ExecFetchResult } from '@mui/toolpad-core'; import type { Har } from 'har-format'; -import { Maybe } from '../../utils/types'; +import { Maybe } from '@mui/toolpad-utils/types'; interface AuthenticationBase { type: 'basic' | 'bearerToken' | 'apiKey'; diff --git a/packages/toolpad-app/src/toolpadDataSources/sql/client.tsx b/packages/toolpad-app/src/toolpadDataSources/sql/client.tsx index 06880d8acfc..8bf507aacd7 100644 --- a/packages/toolpad-app/src/toolpadDataSources/sql/client.tsx +++ b/packages/toolpad-app/src/toolpadDataSources/sql/client.tsx @@ -20,13 +20,13 @@ import { getObjectKey } from '@mui/toolpad-utils/objectKey'; import { BindableAttrEntries, BindableAttrValue, ExecFetchResult } from '@mui/toolpad-core'; import { useBrowserJsRuntime } from '@mui/toolpad-core/jsBrowserRuntime'; import { serializeError, errorFrom } from '@mui/toolpad-utils/errors'; +import { Maybe } from '@mui/toolpad-utils/types'; import { Panel, PanelGroup, PanelResizeHandle } from '../../components/resizablePanels'; import ParametersEditor from '../../toolpad/AppEditor/PageEditor/ParametersEditor'; import { useEvaluateLiveBindingEntries } from '../../toolpad/AppEditor/useEvaluateLiveBinding'; import { QueryEditorProps } from '../../types'; import { isSaveDisabled, validation } from '../../utils/forms'; import lazyComponent from '../../utils/lazyComponent'; -import { Maybe } from '../../utils/types'; import QueryInputPanel from '../QueryInputPanel'; import useFetchPrivate from '../useFetchPrivate'; import useQueryPreview from '../useQueryPreview'; diff --git a/packages/toolpad-app/src/toolpadDataSources/sql/types.ts b/packages/toolpad-app/src/toolpadDataSources/sql/types.ts index 9e9e7af3c58..30a072cf88c 100644 --- a/packages/toolpad-app/src/toolpadDataSources/sql/types.ts +++ b/packages/toolpad-app/src/toolpadDataSources/sql/types.ts @@ -1,5 +1,5 @@ import { ExecFetchResult } from '@mui/toolpad-core'; -import type { Maybe, WithControlledProp } from '../../utils/types'; +import type { Maybe, WithControlledProp } from '@mui/toolpad-utils/types'; export interface SqlConnectionParams { host: string; diff --git a/packages/toolpad-app/src/types.ts b/packages/toolpad-app/src/types.ts index dc584845c69..9bb3e8ae50d 100644 --- a/packages/toolpad-app/src/types.ts +++ b/packages/toolpad-app/src/types.ts @@ -11,8 +11,8 @@ import { NodeHashes, } from '@mui/toolpad-core'; import { PaletteMode } from '@mui/material'; +import type { Awaitable, Maybe, WithControlledProp } from '@mui/toolpad-utils/types'; import type * as appDom from './appDom'; -import type { Awaitable, Maybe, WithControlledProp } from './utils/types'; import type { Rectangle } from './utils/geometry'; import type { RuntimeState } from './runtime'; diff --git a/packages/toolpad-app/src/utils/express.ts b/packages/toolpad-app/src/utils/express.ts index 069a1510a65..46a0bc3db52 100644 --- a/packages/toolpad-app/src/utils/express.ts +++ b/packages/toolpad-app/src/utils/express.ts @@ -1,5 +1,5 @@ import * as express from 'express'; -import { Awaitable } from './types'; +import { Awaitable } from '@mui/toolpad-utils/types'; export function asyncHandler( handler: ( diff --git a/packages/toolpad-app/src/utils/types.ts b/packages/toolpad-app/src/utils/types.ts deleted file mode 100644 index ee36a78725f..00000000000 --- a/packages/toolpad-app/src/utils/types.ts +++ /dev/null @@ -1,83 +0,0 @@ -export type WithControlledProp< - V, - K extends string = 'value', - O extends string = K extends 'value' ? 'onChange' : `on${Capitalize}Change`, -> = Record & Record void>; - -export type ExactEntriesOf

= Exclude<{ [K in keyof P]: [K, P[K]] }[keyof P], undefined>[]; - -/** - * The inverse of Awaited. - */ -export type Awaitable = T | Promise | PromiseLike; - -/** - * @example - * type T0 = Join<[1, 2, 3, 4], '.'>; // '1.2.3.4' - * type T1 = Join<['foo', 'bar', 'baz'], '-'>; // 'foo-bar-baz' - * type T2 = Join<[], '.'>; // '' - */ -export type Join = T extends [] - ? '' - : T extends [string | number | boolean | bigint] - ? `${T[0]}` - : T extends [string | number | boolean | bigint, ...infer U] - ? `${T[0]}${D}${Join}` - : string; - -/** - * @example - * type T0 = Split<'foo', '.'>; // ['foo'] - * type T1 = Split<'foo.bar.baz', '.'>; // ['foo', 'bar', 'baz'] - * type T2 = Split<'foo.bar', ''>; // ['f', 'o', 'o', '.', 'b', 'a', 'r'] - */ -export type Split = string extends S - ? string[] - : S extends '' - ? [] - : S extends `${infer T}${D}${infer U}` - ? [T, ...Split] - : [S]; - -/** - * @example - * type T0 = CapitalizeAll<['foo', 'bar']>; // ['Foo', 'Bar'] - * type T1 = CapitalizeAll<[]>; // [] - */ -export type CapitalizeAll = T extends [] - ? [] - : T extends [string, ...infer U] - ? U extends string[] - ? [Capitalize, ...CapitalizeAll] - : never - : never; - -/** - * @example - * type T0 = CapitalizeAll<['foo', 'bar', 'baz']>; // ['foo', 'Bar', 'Baz'] - * type T1 = CapitalizeAll<['foo']>; // ['foo'] - * type T2 = CapitalizeAll<[]>; // [] - */ -export type CapitalizeTail = T extends [] - ? [] - : T extends [string, ...infer U] - ? U extends string[] - ? [T[0], ...CapitalizeAll] - : never - : never; - -/** - * sString template type that converts snake-case to camel-case - * @example - * type T0 = SnakeToCamel<'foo-bar-baz'>; // 'fooBarBaz' - * type T1 = CapitalizeAll<'foo'>; // 'foo' - * type T2 = CapitalizeAll<''>; // '' - */ -export type SnakeToCamel = Join>, ''>; - -/** - * The inverso of NonNullable - */ -export type Maybe = T | undefined | null; - -export type ValueOf = T[keyof T]; diff --git a/packages/toolpad-app/src/utils/useBoolean.ts b/packages/toolpad-app/src/utils/useBoolean.ts deleted file mode 100644 index f142ca4fc16..00000000000 --- a/packages/toolpad-app/src/utils/useBoolean.ts +++ /dev/null @@ -1,2 +0,0 @@ -// TODO: replace references to this file with the '@mui/toolpad-utils/hooks/useBoolean' -export { default } from '@mui/toolpad-utils/hooks/useBoolean'; diff --git a/packages/toolpad-utils/src/types.ts b/packages/toolpad-utils/src/types.ts index cac600044da..36af6f0ef9f 100644 --- a/packages/toolpad-utils/src/types.ts +++ b/packages/toolpad-utils/src/types.ts @@ -1,5 +1,89 @@ declare const brand: unique symbol; +export type WithControlledProp< + V, + K extends string = 'value', + O extends string = K extends 'value' ? 'onChange' : `on${Capitalize}Change`, +> = Record & Record void>; + +export type ExactEntriesOf

= Exclude<{ [K in keyof P]: [K, P[K]] }[keyof P], undefined>[]; + +/** + * The inverse of Awaited. + */ +export type Awaitable = T | Promise | PromiseLike; + +/** + * @example + * type T0 = Join<[1, 2, 3, 4], '.'>; // '1.2.3.4' + * type T1 = Join<['foo', 'bar', 'baz'], '-'>; // 'foo-bar-baz' + * type T2 = Join<[], '.'>; // '' + */ +export type Join = T extends [] + ? '' + : T extends [string | number | boolean | bigint] + ? `${T[0]}` + : T extends [string | number | boolean | bigint, ...infer U] + ? `${T[0]}${D}${Join}` + : string; + +/** + * @example + * type T0 = Split<'foo', '.'>; // ['foo'] + * type T1 = Split<'foo.bar.baz', '.'>; // ['foo', 'bar', 'baz'] + * type T2 = Split<'foo.bar', ''>; // ['f', 'o', 'o', '.', 'b', 'a', 'r'] + */ +export type Split = string extends S + ? string[] + : S extends '' + ? [] + : S extends `${infer T}${D}${infer U}` + ? [T, ...Split] + : [S]; + +/** + * @example + * type T0 = CapitalizeAll<['foo', 'bar']>; // ['Foo', 'Bar'] + * type T1 = CapitalizeAll<[]>; // [] + */ +export type CapitalizeAll = T extends [] + ? [] + : T extends [string, ...infer U] + ? U extends string[] + ? [Capitalize, ...CapitalizeAll] + : never + : never; + +/** + * @example + * type T0 = CapitalizeAll<['foo', 'bar', 'baz']>; // ['foo', 'Bar', 'Baz'] + * type T1 = CapitalizeAll<['foo']>; // ['foo'] + * type T2 = CapitalizeAll<[]>; // [] + */ +export type CapitalizeTail = T extends [] + ? [] + : T extends [string, ...infer U] + ? U extends string[] + ? [T[0], ...CapitalizeAll] + : never + : never; + +/** + * sString template type that converts snake-case to camel-case + * @example + * type T0 = SnakeToCamel<'foo-bar-baz'>; // 'fooBarBaz' + * type T1 = CapitalizeAll<'foo'>; // 'foo' + * type T2 = CapitalizeAll<''>; // '' + */ +export type SnakeToCamel = Join>, ''>; + +/** + * The inverso of NonNullable + */ +export type Maybe = T | undefined | null; + +export type ValueOf = T[keyof T]; + export interface Brand { readonly [brand]: B; } @@ -11,9 +95,4 @@ export type Branded = A & Brand; export type Expand = T extends infer O ? { [K in keyof O]: O[K] } : never; export type ExpandNested = T extends infer O ? { [K in keyof O]: Expand } : never; -/** - * The inverse of Awaited. - */ -export type Awaitable = T | Promise | PromiseLike; - export {};