@measured/puck 0.10.1-canary.922a839 → 0.11.0-canary.4613df4
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +229 -18
- package/dist/index.css +70 -42
- package/dist/index.d.ts +97 -26
- package/dist/index.js +632 -374
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
@@ -8,39 +8,71 @@ type ItemSelector = {
|
|
8
8
|
zone?: string;
|
9
9
|
};
|
10
10
|
|
11
|
-
type Adaptor<AdaptorParams = {}> = {
|
11
|
+
type Adaptor<AdaptorParams = {}, TableShape extends Record<string, any> = {}, PropShape = TableShape> = {
|
12
12
|
name: string;
|
13
|
-
fetchList: (adaptorParams?: AdaptorParams) => Promise<
|
13
|
+
fetchList: (adaptorParams?: AdaptorParams) => Promise<TableShape[] | null>;
|
14
|
+
mapProp?: (value: TableShape) => PropShape;
|
14
15
|
};
|
15
|
-
type
|
16
|
+
type WithPuckProps<Props> = Props & {
|
16
17
|
id: string;
|
18
|
+
_meta?: {
|
19
|
+
readOnly: Partial<Record<keyof Props, boolean>>;
|
20
|
+
};
|
17
21
|
};
|
18
|
-
type
|
22
|
+
type BaseField = {
|
23
|
+
label?: string;
|
24
|
+
};
|
25
|
+
type TextField = BaseField & {
|
26
|
+
type: "text" | "number" | "textarea";
|
27
|
+
};
|
28
|
+
type SelectField = BaseField & {
|
29
|
+
type: "select" | "radio";
|
30
|
+
options: {
|
31
|
+
label: string;
|
32
|
+
value: string | number | boolean;
|
33
|
+
}[];
|
34
|
+
};
|
35
|
+
type ArrayField<Props extends {
|
19
36
|
[key: string]: any;
|
20
37
|
} = {
|
21
38
|
[key: string]: any;
|
22
|
-
}> = {
|
23
|
-
type: "
|
24
|
-
|
25
|
-
|
26
|
-
adaptorParams?: object;
|
27
|
-
arrayFields?: {
|
28
|
-
[SubPropName in keyof Props]: Field<Props[SubPropName][0]>;
|
39
|
+
}> = BaseField & {
|
40
|
+
type: "array";
|
41
|
+
arrayFields: {
|
42
|
+
[SubPropName in keyof Props[0]]: Field<Props[0][SubPropName]>;
|
29
43
|
};
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
44
|
+
defaultItemProps?: Props[0];
|
45
|
+
getItemSummary?: (item: Props[0], index?: number) => string;
|
46
|
+
};
|
47
|
+
type ExternalField<Props extends {
|
48
|
+
[key: string]: any;
|
49
|
+
} = {
|
50
|
+
[key: string]: any;
|
51
|
+
}> = BaseField & {
|
52
|
+
type: "external";
|
53
|
+
adaptor: Adaptor<any, any, Props>;
|
54
|
+
adaptorParams?: object;
|
55
|
+
getItemSummary: (item: Props, index?: number) => string;
|
56
|
+
};
|
57
|
+
type CustomField<Props extends {
|
58
|
+
[key: string]: any;
|
59
|
+
} = {
|
60
|
+
[key: string]: any;
|
61
|
+
}> = BaseField & {
|
62
|
+
type: "custom";
|
63
|
+
render: (props: {
|
64
|
+
field: CustomField;
|
34
65
|
name: string;
|
35
66
|
value: any;
|
36
|
-
onChange: (value:
|
67
|
+
onChange: (value: Props) => void;
|
37
68
|
readOnly?: boolean;
|
38
69
|
}) => ReactElement;
|
39
|
-
options?: {
|
40
|
-
label: string;
|
41
|
-
value: string | number | boolean;
|
42
|
-
}[];
|
43
70
|
};
|
71
|
+
type Field<Props extends {
|
72
|
+
[key: string]: any;
|
73
|
+
} = {
|
74
|
+
[key: string]: any;
|
75
|
+
}> = TextField | SelectField | ArrayField<Props> | ExternalField<Props> | CustomField;
|
44
76
|
type DefaultRootProps = {
|
45
77
|
children: ReactNode;
|
46
78
|
title: string;
|
@@ -52,7 +84,7 @@ type DefaultComponentProps = {
|
|
52
84
|
editMode?: boolean;
|
53
85
|
};
|
54
86
|
type Fields<ComponentProps extends DefaultComponentProps = DefaultComponentProps> = {
|
55
|
-
[PropName in keyof Omit<Required<ComponentProps>, "children" | "editMode">]: Field<ComponentProps[PropName]
|
87
|
+
[PropName in keyof Omit<Required<ComponentProps>, "children" | "editMode">]: Field<ComponentProps[PropName]>;
|
56
88
|
};
|
57
89
|
type Content<Props extends {
|
58
90
|
[key: string]: any;
|
@@ -60,15 +92,28 @@ type Content<Props extends {
|
|
60
92
|
[key: string]: any;
|
61
93
|
}> = MappedItem<Props>[];
|
62
94
|
type ComponentConfig<ComponentProps extends DefaultComponentProps = DefaultComponentProps, DefaultProps = ComponentProps> = {
|
63
|
-
render: (props:
|
95
|
+
render: (props: WithPuckProps<ComponentProps>) => ReactElement;
|
64
96
|
defaultProps?: DefaultProps;
|
65
97
|
fields?: Fields<ComponentProps>;
|
98
|
+
resolveProps?: (props: WithPuckProps<ComponentProps>) => Promise<{
|
99
|
+
props: WithPuckProps<ComponentProps>;
|
100
|
+
readOnly?: Partial<Record<keyof ComponentProps, boolean>>;
|
101
|
+
}>;
|
102
|
+
};
|
103
|
+
type Category<ComponentName> = {
|
104
|
+
components?: ComponentName[];
|
105
|
+
title?: string;
|
106
|
+
visible?: boolean;
|
107
|
+
defaultExpanded?: boolean;
|
66
108
|
};
|
67
109
|
type Config<Props extends {
|
68
110
|
[key: string]: any;
|
69
111
|
} = {
|
70
112
|
[key: string]: any;
|
71
|
-
}, RootProps extends DefaultRootProps = DefaultRootProps> = {
|
113
|
+
}, RootProps extends DefaultRootProps = DefaultRootProps, CategoryName extends string = string> = {
|
114
|
+
categories?: Record<CategoryName, Category<keyof Props>> & {
|
115
|
+
other?: Category<Props>;
|
116
|
+
};
|
72
117
|
components: {
|
73
118
|
[ComponentName in keyof Props]: ComponentConfig<Props[ComponentName], Props[ComponentName]>;
|
74
119
|
};
|
@@ -84,7 +129,7 @@ type MappedItem<Props extends {
|
|
84
129
|
[key: string]: any;
|
85
130
|
}> = {
|
86
131
|
type: keyof Props;
|
87
|
-
props:
|
132
|
+
props: WithPuckProps<{
|
88
133
|
[key: string]: any;
|
89
134
|
}>;
|
90
135
|
};
|
@@ -115,6 +160,12 @@ type UiState = {
|
|
115
160
|
leftSideBarVisible: boolean;
|
116
161
|
itemSelector: ItemSelector | null;
|
117
162
|
arrayState: Record<string, ArrayState | undefined>;
|
163
|
+
componentList: Record<string, {
|
164
|
+
components?: string[];
|
165
|
+
title?: string;
|
166
|
+
visible?: boolean;
|
167
|
+
expanded?: boolean;
|
168
|
+
}>;
|
118
169
|
};
|
119
170
|
type AppState = {
|
120
171
|
data: Data;
|
@@ -201,6 +252,7 @@ type PathData = Record<string, {
|
|
201
252
|
type DropZoneContext = {
|
202
253
|
data: Data;
|
203
254
|
config: Config;
|
255
|
+
dynamicProps?: Record<string, any>;
|
204
256
|
itemSelector?: ItemSelector | null;
|
205
257
|
setItemSelector?: (newIndex: ItemSelector | null) => void;
|
206
258
|
dispatch?: (action: PuckAction) => void;
|
@@ -265,12 +317,17 @@ type Plugin = {
|
|
265
317
|
}) => ReactElement<any>;
|
266
318
|
};
|
267
319
|
|
268
|
-
declare function Puck({ config, data: initialData, onChange, onPublish, plugins, renderHeader, renderHeaderActions, headerTitle, headerPath, }: {
|
320
|
+
declare function Puck({ config, data: initialData, onChange, onPublish, plugins, renderComponentList, renderHeader, renderHeaderActions, headerTitle, headerPath, }: {
|
269
321
|
config: Config;
|
270
322
|
data: Data;
|
271
323
|
onChange?: (data: Data) => void;
|
272
324
|
onPublish: (data: Data) => void;
|
273
325
|
plugins?: Plugin[];
|
326
|
+
renderComponentList?: (props: {
|
327
|
+
children: ReactNode;
|
328
|
+
dispatch: (action: PuckAction) => void;
|
329
|
+
state: AppState;
|
330
|
+
}) => ReactElement;
|
274
331
|
renderHeader?: (props: {
|
275
332
|
children: ReactNode;
|
276
333
|
dispatch: (action: PuckAction) => void;
|
@@ -289,10 +346,24 @@ declare function Render({ config, data }: {
|
|
289
346
|
data: Data;
|
290
347
|
}): react_jsx_runtime.JSX.Element;
|
291
348
|
|
349
|
+
declare const resolveData: (data: Data, config: Config) => Promise<{
|
350
|
+
content: {
|
351
|
+
props: any;
|
352
|
+
type: string | number;
|
353
|
+
}[];
|
354
|
+
zones: Record<string, MappedItem<{
|
355
|
+
[key: string]: any;
|
356
|
+
}>[]>;
|
357
|
+
root: {
|
358
|
+
[key: string]: any;
|
359
|
+
title: string;
|
360
|
+
};
|
361
|
+
}>;
|
362
|
+
|
292
363
|
declare const FieldLabel: ({ children, icon, label, }: {
|
293
364
|
children?: ReactNode;
|
294
365
|
icon?: ReactNode;
|
295
366
|
label: string;
|
296
367
|
}) => react_jsx_runtime.JSX.Element;
|
297
368
|
|
298
|
-
export { Adaptor, AppState, ArrayState, Button, ComponentConfig, Config, Content, Data, DefaultComponentProps, DefaultRootProps, DropZone, DropZoneProvider, Field, FieldLabel, Fields, IconButton, ItemWithId, MappedItem, Puck, Render, UiState, dropZoneContext };
|
369
|
+
export { Adaptor, AppState, ArrayField, ArrayState, BaseField, Button, ComponentConfig, Config, Content, CustomField, Data, DefaultComponentProps, DefaultRootProps, DropZone, DropZoneProvider, ExternalField, Field, FieldLabel, Fields, IconButton, ItemWithId, MappedItem, Puck, Render, SelectField, TextField, UiState, dropZoneContext, resolveData };
|