Skip to content

Commit 5e73886

Browse files
committed
fix: improve deprecation message
1 parent 9a89669 commit 5e73886

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/index.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ const JsonViewerInner: FC<JsonViewerProps> = (props) => {
125125
}
126126

127127
export const JsonViewer = function JsonViewer<Value> (props: JsonViewerProps<Value>): ReactElement {
128+
if (process.env.NODE_ENV !== 'production') {
129+
if ('displayObjectSize' in props) {
130+
console.error('`displayObjectSize` is deprecated. Use `displaySize` instead.\nSee https://viewer.textea.io/migration/migration-v3#raname-displayobjectsize-to-displaysize for more information.')
131+
}
132+
}
128133
const isAutoDarkTheme = useThemeDetector()
129134
const themeType = useMemo(() => props.theme === 'auto'
130135
? (isAutoDarkTheme ? 'light' : 'dark')

src/utils/index.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ export function createDataType<ValueType = unknown> (
7474
is: (value: unknown, path: Path) => boolean
7575
Component: ComponentType<DataItemProps<ValueType>>
7676
}
77+
/**
78+
* @deprecated use `defineDataType` instead
79+
*/
7780
// case 2: you only render with a single component with editor
7881
export function createDataType<ValueType = unknown> (
7982
is: (value: unknown, path: Path) => boolean,
@@ -84,6 +87,9 @@ export function createDataType<ValueType = unknown> (
8487
Component: ComponentType<DataItemProps<ValueType>>
8588
Editor: ComponentType<DataItemProps<ValueType>>
8689
}
90+
/**
91+
* @deprecated use `defineDataType` instead
92+
*/
8793
// case 3: you only render with a component with pre and post.
8894
export function createDataType<ValueType = unknown> (
8995
is: (value: unknown, path: Path) => boolean,
@@ -97,6 +103,9 @@ export function createDataType<ValueType = unknown> (
97103
PreComponent: ComponentType<DataItemProps<ValueType>>
98104
PostComponent: ComponentType<DataItemProps<ValueType>>
99105
}
106+
/**
107+
* @deprecated use `defineDataType` instead
108+
*/
100109
// case 4: need all of these
101110
export function createDataType<ValueType = unknown> (
102111
is: (value: unknown, path: Path) => boolean,
@@ -111,6 +120,9 @@ export function createDataType<ValueType = unknown> (
111120
PreComponent: ComponentType<DataItemProps<ValueType>>
112121
PostComponent: ComponentType<DataItemProps<ValueType>>
113122
}
123+
/**
124+
* @deprecated use `defineDataType` instead
125+
*/
114126
export function createDataType<ValueType = unknown> (
115127
is: (value: unknown, path: Path) => boolean,
116128
Component: ComponentType<DataItemProps<ValueType>>,
@@ -119,7 +131,7 @@ export function createDataType<ValueType = unknown> (
119131
PostComponent?: ComponentType<DataItemProps<ValueType>> | undefined
120132
): any {
121133
if (process.env.NODE_ENV !== 'production') {
122-
console.warn('createDataType is deprecated, please use `defineDataType` instead')
134+
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.')
123135
}
124136
return {
125137
is,
@@ -139,6 +151,9 @@ export function defineDataType<ValueType = unknown> ({
139151
PreComponent,
140152
PostComponent
141153
}: {
154+
/**
155+
* Type matcher - Whether the value belongs to the data type
156+
*/
142157
is: (value: unknown, path: Path) => boolean
143158
/**
144159
* transform the value to a string for editing
@@ -151,6 +166,12 @@ export function defineDataType<ValueType = unknown> ({
151166
*/
152167
deserialize?: (value: string) => ValueType
153168
Component: ComponentType<DataItemProps<ValueType>>
169+
/**
170+
* if you want to provide a custom editor
171+
* you can use this prop to provide a custom editor
172+
*
173+
* _Note: You need to pass `serialize` and `deserialize` to enable this feature_
174+
*/
154175
Editor?: ComponentType<EditorProps<string>>
155176
PreComponent?: ComponentType<DataItemProps<ValueType>>
156177
PostComponent?: ComponentType<DataItemProps<ValueType>>

0 commit comments

Comments
 (0)