Skip to content

Commit 2923478

Browse files
committed
feat!: remove deprecated createDataType and displayObjectSize
1 parent 5ed7245 commit 2923478

File tree

3 files changed

+1
-206
lines changed

3 files changed

+1
-206
lines changed

src/index.tsx

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

135135
export const JsonViewer = function JsonViewer<Value> (props: JsonViewerProps<Value>): ReactElement {
136-
if (process.env.NODE_ENV !== 'production') {
137-
if ('displayObjectSize' in props) {
138-
console.error('`displayObjectSize` is deprecated. Use `displaySize` instead.\nSee https://viewer.textea.io/migration/migration-v3#raname-displayobjectsize-to-displaysize for more information.')
139-
}
140-
}
141136
const isAutoDarkTheme = useThemeDetector()
142137
const themeType = useMemo(() => props.theme === 'auto'
143138
? (isAutoDarkTheme ? 'dark' : 'light')
@@ -195,7 +190,6 @@ export * from './type'
195190
export type { PathValueCustomGetter } from './utils'
196191
export {
197192
applyValue,
198-
createDataType,
199193
defineDataType,
200194
deleteValue,
201195
getPathValue,

src/utils/index.ts

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -109,85 +109,6 @@ export function deleteValue (input: any, path: (string | number)[], value: any)
109109
return input
110110
}
111111

112-
/**
113-
* @deprecated use `defineDataType` instead
114-
*/
115-
// case 1: you only render with a single component
116-
export function createDataType<ValueType = unknown> (
117-
is: (value: unknown, path: Path) => boolean,
118-
Component: ComponentType<DataItemProps<ValueType>>
119-
): {
120-
is: (value: unknown, path: Path) => boolean
121-
Component: ComponentType<DataItemProps<ValueType>>
122-
}
123-
/**
124-
* @deprecated use `defineDataType` instead
125-
*/
126-
// case 2: you only render with a single component with editor
127-
export function createDataType<ValueType = unknown> (
128-
is: (value: unknown, path: Path) => boolean,
129-
Component: ComponentType<DataItemProps<ValueType>>,
130-
Editor: ComponentType<EditorProps<ValueType>>
131-
): {
132-
is: (value: unknown, path: Path) => boolean
133-
Component: ComponentType<DataItemProps<ValueType>>
134-
Editor: ComponentType<DataItemProps<ValueType>>
135-
}
136-
/**
137-
* @deprecated use `defineDataType` instead
138-
*/
139-
// case 3: you only render with a component with pre and post.
140-
export function createDataType<ValueType = unknown> (
141-
is: (value: unknown, path: Path) => boolean,
142-
Component: ComponentType<DataItemProps<ValueType>>,
143-
Editor: undefined,
144-
PreComponent: ComponentType<DataItemProps<ValueType>>,
145-
PostComponent: ComponentType<DataItemProps<ValueType>>
146-
): {
147-
is: (value: unknown, path: Path) => boolean
148-
Component: ComponentType<DataItemProps<ValueType>>
149-
PreComponent: ComponentType<DataItemProps<ValueType>>
150-
PostComponent: ComponentType<DataItemProps<ValueType>>
151-
}
152-
/**
153-
* @deprecated use `defineDataType` instead
154-
*/
155-
// case 4: need all of these
156-
export function createDataType<ValueType = unknown> (
157-
is: (value: unknown, path: Path) => boolean,
158-
Component: ComponentType<DataItemProps<ValueType>>,
159-
Editor: ComponentType<EditorProps<ValueType>>,
160-
PreComponent: ComponentType<DataItemProps<ValueType>>,
161-
PostComponent: ComponentType<DataItemProps<ValueType>>
162-
): {
163-
is: (value: unknown, path: Path) => boolean
164-
Component: ComponentType<DataItemProps<ValueType>>
165-
Editor: ComponentType<DataItemProps<ValueType>>
166-
PreComponent: ComponentType<DataItemProps<ValueType>>
167-
PostComponent: ComponentType<DataItemProps<ValueType>>
168-
}
169-
/**
170-
* @deprecated use `defineDataType` instead
171-
*/
172-
export function createDataType<ValueType = unknown> (
173-
is: (value: unknown, path: Path) => boolean,
174-
Component: ComponentType<DataItemProps<ValueType>>,
175-
Editor?: ComponentType<EditorProps<ValueType>> | undefined,
176-
PreComponent?: ComponentType<DataItemProps<ValueType>> | undefined,
177-
PostComponent?: ComponentType<DataItemProps<ValueType>> | undefined
178-
): any {
179-
if (process.env.NODE_ENV !== 'production') {
180-
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.')
181-
}
182-
return {
183-
is,
184-
Component,
185-
Editor,
186-
PreComponent,
187-
PostComponent
188-
}
189-
}
190-
191112
/**
192113
* Define custom data types for any data structure
193114
*/

tests/util.test.tsx

Lines changed: 1 addition & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
import { expectTypeOf } from 'expect-type'
2-
import type { ComponentType } from 'react'
31
import { describe, expect, test } from 'vitest'
42

5-
import type { DataItemProps, Path } from '../src'
6-
import { applyValue, createDataType, deleteValue, isCycleReference } from '../src'
3+
import { applyValue, deleteValue, isCycleReference } from '../src'
74
import { getPathValue, pathValueDefaultGetter, safeStringify, segmentArray } from '../src/utils'
85

96
describe('function applyValue', () => {
@@ -212,123 +209,6 @@ describe('function isCycleReference', () => {
212209
})
213210
})
214211

215-
describe('function createDataType', () => {
216-
test('case 1', () => {
217-
const dataType = createDataType<string>(
218-
(value) => {
219-
expectTypeOf(value).toBeUnknown()
220-
return true
221-
},
222-
(props) => {
223-
expectTypeOf(props.value).toBeString()
224-
return null
225-
}
226-
)
227-
expectTypeOf(dataType).toEqualTypeOf<{
228-
is:(value: unknown, path: Path) => boolean
229-
Component: ComponentType<DataItemProps<string>>
230-
}>()
231-
expectTypeOf(dataType.is).returns.toBeBoolean()
232-
expect(dataType.is).toBeTypeOf('function')
233-
expect(dataType.Component).toBeTypeOf('function')
234-
})
235-
test('case 2', () => {
236-
const dataType = createDataType<string>(
237-
(value) => {
238-
expectTypeOf(value).toBeUnknown()
239-
return true
240-
},
241-
(props) => {
242-
expectTypeOf(props.value).toBeString()
243-
return null
244-
},
245-
(props) => {
246-
expectTypeOf(props.value).toBeString()
247-
return null
248-
}
249-
)
250-
expectTypeOf(dataType).toEqualTypeOf<{
251-
is:(value: unknown, path: Path) => boolean
252-
Component: ComponentType<DataItemProps<string>>
253-
Editor: ComponentType<DataItemProps<string>>
254-
}>()
255-
expectTypeOf(dataType.is).returns.toBeBoolean()
256-
expect(dataType.is).toBeTypeOf('function')
257-
expect(dataType.Component).toBeTypeOf('function')
258-
expect(dataType.Editor).toBeTypeOf('function')
259-
})
260-
test('case 3', () => {
261-
const dataType = createDataType<string>(
262-
(value) => {
263-
expectTypeOf(value).toBeUnknown()
264-
return true
265-
},
266-
(props) => {
267-
expectTypeOf(props.value).toBeString()
268-
return null
269-
},
270-
undefined,
271-
(props) => {
272-
expectTypeOf(props.value).toBeString()
273-
return null
274-
},
275-
(props) => {
276-
expectTypeOf(props.value).toBeString()
277-
return null
278-
}
279-
)
280-
expectTypeOf(dataType).toEqualTypeOf<{
281-
is:(value: unknown, path: Path) => boolean
282-
Component: ComponentType<DataItemProps<string>>
283-
PreComponent: ComponentType<DataItemProps<string>>
284-
PostComponent: ComponentType<DataItemProps<string>>
285-
}>()
286-
expectTypeOf(dataType.is).returns.toBeBoolean()
287-
expect(dataType.is).toBeTypeOf('function')
288-
expect(dataType.Component).toBeTypeOf('function')
289-
expect(dataType.PreComponent).toBeTypeOf('function')
290-
expect(dataType.PostComponent).toBeTypeOf('function')
291-
})
292-
293-
test('case 4', () => {
294-
const dataType = createDataType<string>(
295-
(value) => {
296-
expectTypeOf(value).toBeUnknown()
297-
return true
298-
},
299-
(props) => {
300-
expectTypeOf(props.value).toBeString()
301-
return null
302-
},
303-
(props) => {
304-
expectTypeOf(props.value).toBeString()
305-
return null
306-
},
307-
(props) => {
308-
expectTypeOf(props.value).toBeString()
309-
return null
310-
},
311-
(props) => {
312-
expectTypeOf(props.value).toBeString()
313-
return null
314-
}
315-
)
316-
expectTypeOf(dataType).toEqualTypeOf<{
317-
is:(value: unknown, path: Path) => boolean
318-
Component: ComponentType<DataItemProps<string>>
319-
Editor: ComponentType<DataItemProps<string>>
320-
PreComponent: ComponentType<DataItemProps<string>>
321-
PostComponent: ComponentType<DataItemProps<string>>
322-
}>()
323-
expectTypeOf(dataType.is).returns.toBeBoolean()
324-
expect(dataType.is).toBeTypeOf('function')
325-
expect(dataType.Component).toBeTypeOf('function')
326-
expect(dataType.Editor).toBeTypeOf('function')
327-
expect(dataType.PreComponent).toBeTypeOf('function')
328-
expect(dataType.PostComponent).toBeTypeOf('function')
329-
})
330-
})
331-
332212
describe('function segmentArray', () => {
333213
test('case 1', () => {
334214
const array = [1, 2, 3, 4, 5]

0 commit comments

Comments
 (0)