Skip to content

Commit

Permalink
fix: improve deprecation message
Browse files Browse the repository at this point in the history
  • Loading branch information
pionxzh committed Apr 25, 2023
1 parent 9a89669 commit 5e73886
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ const JsonViewerInner: FC<JsonViewerProps> = (props) => {
}

export const JsonViewer = function JsonViewer<Value> (props: JsonViewerProps<Value>): ReactElement {
if (process.env.NODE_ENV !== 'production') {
if ('displayObjectSize' in props) {
console.error('`displayObjectSize` is deprecated. Use `displaySize` instead.\nSee https://viewer.textea.io/migration/migration-v3#raname-displayobjectsize-to-displaysize for more information.')
}
}
const isAutoDarkTheme = useThemeDetector()
const themeType = useMemo(() => props.theme === 'auto'
? (isAutoDarkTheme ? 'light' : 'dark')
Expand Down
23 changes: 22 additions & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ export function createDataType<ValueType = unknown> (
is: (value: unknown, path: Path) => boolean
Component: ComponentType<DataItemProps<ValueType>>
}
/**
* @deprecated use `defineDataType` instead
*/
// case 2: you only render with a single component with editor
export function createDataType<ValueType = unknown> (
is: (value: unknown, path: Path) => boolean,
Expand All @@ -84,6 +87,9 @@ export function createDataType<ValueType = unknown> (
Component: ComponentType<DataItemProps<ValueType>>
Editor: ComponentType<DataItemProps<ValueType>>
}
/**
* @deprecated use `defineDataType` instead
*/
// case 3: you only render with a component with pre and post.
export function createDataType<ValueType = unknown> (
is: (value: unknown, path: Path) => boolean,
Expand All @@ -97,6 +103,9 @@ export function createDataType<ValueType = unknown> (
PreComponent: ComponentType<DataItemProps<ValueType>>
PostComponent: ComponentType<DataItemProps<ValueType>>
}
/**
* @deprecated use `defineDataType` instead
*/
// case 4: need all of these
export function createDataType<ValueType = unknown> (
is: (value: unknown, path: Path) => boolean,
Expand All @@ -111,6 +120,9 @@ export function createDataType<ValueType = unknown> (
PreComponent: ComponentType<DataItemProps<ValueType>>
PostComponent: ComponentType<DataItemProps<ValueType>>
}
/**
* @deprecated use `defineDataType` instead
*/
export function createDataType<ValueType = unknown> (
is: (value: unknown, path: Path) => boolean,
Component: ComponentType<DataItemProps<ValueType>>,
Expand All @@ -119,7 +131,7 @@ export function createDataType<ValueType = unknown> (
PostComponent?: ComponentType<DataItemProps<ValueType>> | undefined
): any {
if (process.env.NODE_ENV !== 'production') {
console.warn('createDataType is deprecated, please use `defineDataType` instead')
console.warn('createDataType is deprecated, please use `defineDataType` instead. See https://viewer.textea.io/migration/migration-v3#use-definedatatype-instead-of-createdatatype for more information.')
}
return {
is,
Expand All @@ -139,6 +151,9 @@ export function defineDataType<ValueType = unknown> ({
PreComponent,
PostComponent
}: {
/**
* Type matcher - Whether the value belongs to the data type
*/
is: (value: unknown, path: Path) => boolean
/**
* transform the value to a string for editing
Expand All @@ -151,6 +166,12 @@ export function defineDataType<ValueType = unknown> ({
*/
deserialize?: (value: string) => ValueType
Component: ComponentType<DataItemProps<ValueType>>
/**
* if you want to provide a custom editor
* you can use this prop to provide a custom editor
*
* _Note: You need to pass `serialize` and `deserialize` to enable this feature_
*/
Editor?: ComponentType<EditorProps<string>>
PreComponent?: ComponentType<DataItemProps<ValueType>>
PostComponent?: ComponentType<DataItemProps<ValueType>>
Expand Down

0 comments on commit 5e73886

Please sign in to comment.