|
1 | 1 | import type React from 'react'
|
2 | 2 |
|
3 |
| -import type { DataItemProps, EditorProps } from '../type' |
| 3 | +import type { DataItemProps, EditorProps, Path } from '../type' |
4 | 4 |
|
5 | 5 | export const applyValue = (obj: any, path: (string | number)[], value: any) => {
|
6 | 6 | if (typeof obj !== 'object' || obj === null) {
|
@@ -28,52 +28,52 @@ export const applyValue = (obj: any, path: (string | number)[], value: any) => {
|
28 | 28 |
|
29 | 29 | // case 1: you only render with a single component
|
30 | 30 | export function createDataType<ValueType = unknown> (
|
31 |
| - is: (value: unknown) => boolean, |
| 31 | + is: (value: unknown, path: Path) => boolean, |
32 | 32 | Component: React.ComponentType<DataItemProps<ValueType>>
|
33 | 33 | ): {
|
34 |
| - is: (value: unknown) => boolean |
| 34 | + is: (value: unknown, path: Path) => boolean |
35 | 35 | Component: React.ComponentType<DataItemProps<ValueType>>
|
36 | 36 | }
|
37 | 37 | // case 2: you only render with a single component with editor
|
38 | 38 | export function createDataType<ValueType = unknown> (
|
39 |
| - is: (value: unknown) => boolean, |
| 39 | + is: (value: unknown, path: Path) => boolean, |
40 | 40 | Component: React.ComponentType<DataItemProps<ValueType>>,
|
41 | 41 | Editor: React.ComponentType<EditorProps<ValueType>>
|
42 | 42 | ): {
|
43 |
| - is: (value: unknown) => boolean |
| 43 | + is: (value: unknown, path: Path) => boolean |
44 | 44 | Component: React.ComponentType<DataItemProps<ValueType>>
|
45 | 45 | Editor: React.ComponentType<DataItemProps<ValueType>>
|
46 | 46 | }
|
47 | 47 | // case 3: you only render with a component with pre and post.
|
48 | 48 | export function createDataType<ValueType = unknown> (
|
49 |
| - is: (value: unknown) => boolean, |
| 49 | + is: (value: unknown, path: Path) => boolean, |
50 | 50 | Component: React.ComponentType<DataItemProps<ValueType>>,
|
51 | 51 | Editor: undefined,
|
52 | 52 | PreComponent: React.ComponentType<DataItemProps<ValueType>>,
|
53 | 53 | PostComponent: React.ComponentType<DataItemProps<ValueType>>
|
54 | 54 | ): {
|
55 |
| - is: (value: unknown) => boolean |
| 55 | + is: (value: unknown, path: Path) => boolean |
56 | 56 | Component: React.ComponentType<DataItemProps<ValueType>>
|
57 | 57 | PreComponent: React.ComponentType<DataItemProps<ValueType>>
|
58 | 58 | PostComponent: React.ComponentType<DataItemProps<ValueType>>
|
59 | 59 | }
|
60 | 60 | // case 4: need all of these
|
61 | 61 | export function createDataType<ValueType = unknown> (
|
62 |
| - is: (value: unknown) => boolean, |
| 62 | + is: (value: unknown, path: Path) => boolean, |
63 | 63 | Component: React.ComponentType<DataItemProps<ValueType>>,
|
64 | 64 | Editor: React.ComponentType<EditorProps<ValueType>>,
|
65 | 65 | PreComponent: React.ComponentType<DataItemProps<ValueType>>,
|
66 | 66 | PostComponent: React.ComponentType<DataItemProps<ValueType>>
|
67 | 67 | ): {
|
68 |
| - is: (value: unknown) => boolean |
| 68 | + is: (value: unknown, path: Path) => boolean |
69 | 69 | Component: React.ComponentType<DataItemProps<ValueType>>
|
70 | 70 | Editor: React.ComponentType<DataItemProps<ValueType>>
|
71 | 71 | PreComponent: React.ComponentType<DataItemProps<ValueType>>
|
72 | 72 | PostComponent: React.ComponentType<DataItemProps<ValueType>>
|
73 | 73 | }
|
74 | 74 |
|
75 | 75 | export function createDataType<ValueType = unknown> (
|
76 |
| - is: (value: unknown) => boolean, |
| 76 | + is: (value: unknown, path: Path) => boolean, |
77 | 77 | Component: React.ComponentType<DataItemProps<ValueType>>,
|
78 | 78 | Editor?: React.ComponentType<EditorProps<ValueType>> | undefined,
|
79 | 79 | PreComponent?: React.ComponentType<DataItemProps<ValueType>> | undefined,
|
|
0 commit comments