@measured/puck 0.11.0-canary.c8c02fd → 0.11.0-canary.d22150a
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +204 -23
- package/dist/index.css +258 -170
- package/dist/index.d.ts +112 -53
- package/dist/index.js +30677 -1033
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
@@ -8,61 +8,106 @@ type ItemSelector = {
|
|
8
8
|
zone?: string;
|
9
9
|
};
|
10
10
|
|
11
|
-
type
|
12
|
-
name: string;
|
13
|
-
fetchList: (adaptorParams?: AdaptorParams) => Promise<Record<string, any>[] | null>;
|
14
|
-
};
|
15
|
-
type WithId<T> = T & {
|
11
|
+
type WithPuckProps<Props> = Props & {
|
16
12
|
id: string;
|
17
13
|
};
|
18
|
-
type
|
14
|
+
type BaseField = {
|
15
|
+
label?: string;
|
16
|
+
};
|
17
|
+
type TextField = BaseField & {
|
18
|
+
type: "text" | "number" | "textarea";
|
19
|
+
};
|
20
|
+
type SelectField = BaseField & {
|
21
|
+
type: "select" | "radio";
|
22
|
+
options: {
|
23
|
+
label: string;
|
24
|
+
value: string | number | boolean;
|
25
|
+
}[];
|
26
|
+
};
|
27
|
+
type ArrayField<Props extends {
|
19
28
|
[key: string]: any;
|
20
29
|
} = {
|
21
30
|
[key: string]: any;
|
22
|
-
}> = {
|
23
|
-
type: "
|
24
|
-
|
25
|
-
|
26
|
-
adaptorParams?: object;
|
27
|
-
arrayFields?: {
|
28
|
-
[SubPropName in keyof Props]: Field<Props[SubPropName][0]>;
|
31
|
+
}> = BaseField & {
|
32
|
+
type: "array";
|
33
|
+
arrayFields: {
|
34
|
+
[SubPropName in keyof Props[0]]: Field<Props[0][SubPropName]>;
|
29
35
|
};
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
36
|
+
defaultItemProps?: Props[0];
|
37
|
+
getItemSummary?: (item: Props[0], index?: number) => string;
|
38
|
+
};
|
39
|
+
type Adaptor<AdaptorParams = {}, TableShape extends Record<string, any> = {}, PropShape = TableShape> = {
|
40
|
+
name: string;
|
41
|
+
fetchList: (adaptorParams?: AdaptorParams) => Promise<TableShape[] | null>;
|
42
|
+
mapProp?: (value: TableShape) => PropShape;
|
43
|
+
};
|
44
|
+
type ExternalFieldWithAdaptor<Props extends {
|
45
|
+
[key: string]: any;
|
46
|
+
} = {
|
47
|
+
[key: string]: any;
|
48
|
+
}> = BaseField & {
|
49
|
+
type: "external";
|
50
|
+
placeholder?: string;
|
51
|
+
adaptor: Adaptor<any, any, Props>;
|
52
|
+
adaptorParams?: object;
|
53
|
+
getItemSummary: (item: Props, index?: number) => string;
|
54
|
+
};
|
55
|
+
type ExternalField<Props extends {
|
56
|
+
[key: string]: any;
|
57
|
+
} = {
|
58
|
+
[key: string]: any;
|
59
|
+
}> = BaseField & {
|
60
|
+
type: "external";
|
61
|
+
placeholder?: string;
|
62
|
+
fetchList: () => Promise<any[] | null>;
|
63
|
+
mapProp?: (value: any) => Props;
|
64
|
+
getItemSummary: (item: Props, index?: number) => string;
|
65
|
+
};
|
66
|
+
type CustomField<Props extends {
|
67
|
+
[key: string]: any;
|
68
|
+
} = {
|
69
|
+
[key: string]: any;
|
70
|
+
}> = BaseField & {
|
71
|
+
type: "custom";
|
72
|
+
render: (props: {
|
73
|
+
field: CustomField;
|
34
74
|
name: string;
|
35
75
|
value: any;
|
36
|
-
onChange: (value:
|
76
|
+
onChange: (value: Props) => void;
|
37
77
|
readOnly?: boolean;
|
38
78
|
}) => ReactElement;
|
39
|
-
options?: {
|
40
|
-
label: string;
|
41
|
-
value: string | number | boolean;
|
42
|
-
}[];
|
43
79
|
};
|
80
|
+
type Field<Props extends {
|
81
|
+
[key: string]: any;
|
82
|
+
} = {
|
83
|
+
[key: string]: any;
|
84
|
+
}> = TextField | SelectField | ArrayField<Props> | ExternalField<Props> | ExternalFieldWithAdaptor<Props> | CustomField;
|
44
85
|
type DefaultRootProps = {
|
45
|
-
|
46
|
-
title: string;
|
47
|
-
editMode: boolean;
|
86
|
+
title?: string;
|
48
87
|
[key: string]: any;
|
49
88
|
};
|
89
|
+
type DefaultRootRenderProps = {
|
90
|
+
editMode: boolean;
|
91
|
+
} & DefaultRootProps;
|
50
92
|
type DefaultComponentProps = {
|
51
93
|
[key: string]: any;
|
52
94
|
editMode?: boolean;
|
53
95
|
};
|
54
96
|
type Fields<ComponentProps extends DefaultComponentProps = DefaultComponentProps> = {
|
55
|
-
[PropName in keyof Omit<Required<ComponentProps>, "children" | "editMode">]: Field<ComponentProps[PropName]
|
97
|
+
[PropName in keyof Omit<Required<ComponentProps>, "children" | "editMode">]: Field<ComponentProps[PropName]>;
|
56
98
|
};
|
57
99
|
type Content<Props extends {
|
58
100
|
[key: string]: any;
|
59
101
|
} = {
|
60
102
|
[key: string]: any;
|
61
|
-
}> =
|
62
|
-
type ComponentConfig<ComponentProps extends DefaultComponentProps = DefaultComponentProps, DefaultProps = ComponentProps
|
63
|
-
render: (props:
|
103
|
+
}> = ComponentData<Props>[];
|
104
|
+
type ComponentConfig<ComponentProps extends DefaultComponentProps = DefaultComponentProps, DefaultProps = ComponentProps, DataShape = ComponentData<ComponentProps>> = {
|
105
|
+
render: (props: WithPuckProps<ComponentProps>) => ReactElement;
|
64
106
|
defaultProps?: DefaultProps;
|
65
107
|
fields?: Fields<ComponentProps>;
|
108
|
+
resolveData?: (data: DataShape, params: {
|
109
|
+
changed: Partial<Record<keyof ComponentProps, boolean>>;
|
110
|
+
}) => Promise<Partial<ComponentDataWithOptionalProps<ComponentProps>>> | Partial<ComponentDataWithOptionalProps<ComponentProps>>;
|
66
111
|
};
|
67
112
|
type Category<ComponentName> = {
|
68
113
|
components?: ComponentName[];
|
@@ -79,38 +124,42 @@ type Config<Props extends {
|
|
79
124
|
other?: Category<Props>;
|
80
125
|
};
|
81
126
|
components: {
|
82
|
-
[ComponentName in keyof Props]: ComponentConfig<Props[ComponentName], Props[ComponentName]>;
|
127
|
+
[ComponentName in keyof Props]: Omit<ComponentConfig<Props[ComponentName], Props[ComponentName]>, "type">;
|
83
128
|
};
|
84
|
-
root?: ComponentConfig<RootProps & {
|
129
|
+
root?: Partial<ComponentConfig<RootProps & {
|
85
130
|
children: ReactNode;
|
86
131
|
}, Partial<RootProps & {
|
87
132
|
children: ReactNode;
|
88
|
-
}
|
133
|
+
}>, RootDataWithProps<RootProps>>>;
|
89
134
|
};
|
90
|
-
type
|
135
|
+
type BaseData<Props extends {
|
91
136
|
[key: string]: any;
|
92
137
|
} = {
|
93
138
|
[key: string]: any;
|
94
139
|
}> = {
|
140
|
+
readOnly?: Partial<Record<keyof Props, boolean>>;
|
141
|
+
};
|
142
|
+
type ComponentData<Props extends DefaultComponentProps = DefaultComponentProps> = {
|
95
143
|
type: keyof Props;
|
96
|
-
props:
|
97
|
-
|
98
|
-
|
144
|
+
props: WithPuckProps<Props>;
|
145
|
+
} & BaseData<Props>;
|
146
|
+
type RootDataWithProps<Props extends DefaultRootProps = DefaultRootProps> = {
|
147
|
+
props: Props;
|
99
148
|
};
|
100
|
-
type
|
101
|
-
|
102
|
-
|
103
|
-
[key: string]: any;
|
104
|
-
}, RootProps extends {
|
105
|
-
title: string;
|
149
|
+
type RootDataWithoutProps<Props extends DefaultRootProps = DefaultRootProps> = Props;
|
150
|
+
type RootData<Props extends DefaultRootProps = DefaultRootProps> = BaseData<Props> & Partial<RootDataWithProps<Props>> & Partial<RootDataWithoutProps<Props>>;
|
151
|
+
type ComponentDataWithOptionalProps<Props extends {
|
106
152
|
[key: string]: any;
|
107
153
|
} = {
|
108
|
-
title: string;
|
109
154
|
[key: string]: any;
|
110
|
-
}> = {
|
111
|
-
|
112
|
-
|
113
|
-
|
155
|
+
}> = Omit<ComponentData, "props"> & {
|
156
|
+
props: Partial<WithPuckProps<Props>>;
|
157
|
+
};
|
158
|
+
type MappedItem = ComponentData;
|
159
|
+
type Data<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultRootProps = DefaultRootProps> = {
|
160
|
+
root: RootData<RootProps>;
|
161
|
+
content: Content<WithPuckProps<Props>>;
|
162
|
+
zones?: Record<string, Content<WithPuckProps<Props>>>;
|
114
163
|
};
|
115
164
|
type ItemWithId = {
|
116
165
|
_arrayId: string;
|
@@ -185,13 +234,13 @@ type RemoveAction = {
|
|
185
234
|
index: number;
|
186
235
|
zone: string;
|
187
236
|
};
|
188
|
-
type
|
237
|
+
type SetUiAction = {
|
189
238
|
type: "setUi";
|
190
|
-
ui: Partial<UiState
|
239
|
+
ui: Partial<UiState> | ((previous: UiState) => Partial<UiState>);
|
191
240
|
};
|
192
241
|
type SetDataAction = {
|
193
242
|
type: "setData";
|
194
|
-
data: Partial<Data
|
243
|
+
data: Partial<Data> | ((previous: Data) => Partial<Data>);
|
195
244
|
};
|
196
245
|
type SetAction = {
|
197
246
|
type: "set";
|
@@ -207,7 +256,7 @@ type UnregisterZoneAction = {
|
|
207
256
|
};
|
208
257
|
type PuckAction = {
|
209
258
|
recordHistory?: boolean;
|
210
|
-
} & (ReorderAction | InsertAction | MoveAction | ReplaceAction | RemoveAction | DuplicateAction | SetAction | SetDataAction |
|
259
|
+
} & (ReorderAction | InsertAction | MoveAction | ReplaceAction | RemoveAction | DuplicateAction | SetAction | SetDataAction | SetUiAction | RegisterZoneAction | UnregisterZoneAction);
|
211
260
|
|
212
261
|
type PathData = Record<string, {
|
213
262
|
path: string[];
|
@@ -216,6 +265,7 @@ type PathData = Record<string, {
|
|
216
265
|
type DropZoneContext = {
|
217
266
|
data: Data;
|
218
267
|
config: Config;
|
268
|
+
componentState?: Record<string, any>;
|
219
269
|
itemSelector?: ItemSelector | null;
|
220
270
|
setItemSelector?: (newIndex: ItemSelector | null) => void;
|
221
271
|
dispatch?: (action: PuckAction) => void;
|
@@ -309,10 +359,19 @@ declare function Render({ config, data }: {
|
|
309
359
|
data: Data;
|
310
360
|
}): react_jsx_runtime.JSX.Element;
|
311
361
|
|
312
|
-
declare const
|
362
|
+
declare const resolveAllData: (data: Data, config: Config, onResolveStart?: ((item: MappedItem) => void) | undefined, onResolveEnd?: ((item: MappedItem) => void) | undefined) => Promise<{
|
363
|
+
root: RootDataWithProps<DefaultRootProps> | RootData<DefaultRootProps>;
|
364
|
+
content: any[];
|
365
|
+
zones: Record<string, MappedItem[]>;
|
366
|
+
}>;
|
367
|
+
|
368
|
+
declare const FieldLabel: ({ children, icon, label, el, readOnly, className, }: {
|
313
369
|
children?: ReactNode;
|
314
370
|
icon?: ReactNode;
|
315
371
|
label: string;
|
372
|
+
el?: "div" | "label" | undefined;
|
373
|
+
readOnly?: boolean | undefined;
|
374
|
+
className?: string | undefined;
|
316
375
|
}) => react_jsx_runtime.JSX.Element;
|
317
376
|
|
318
|
-
export { Adaptor, AppState, ArrayState, Button, ComponentConfig, Config, Content, Data, DefaultComponentProps, DefaultRootProps, DropZone, DropZoneProvider, Field, FieldLabel, Fields, IconButton, ItemWithId, MappedItem, Puck, Render, UiState, dropZoneContext };
|
377
|
+
export { Adaptor, AppState, ArrayField, ArrayState, BaseData, BaseField, Button, ComponentConfig, ComponentData, Config, Content, CustomField, Data, DefaultComponentProps, DefaultRootProps, DefaultRootRenderProps, DropZone, DropZoneProvider, ExternalField, ExternalFieldWithAdaptor, Field, FieldLabel, Fields, IconButton, ItemWithId, MappedItem, Puck, Render, RootData, RootDataWithProps, RootDataWithoutProps, SelectField, TextField, UiState, dropZoneContext, resolveAllData };
|