@measured/puck 0.11.0-canary.c8c02fd → 0.11.0-canary.f9033e2
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +214 -22
- package/dist/index.css +228 -172
- package/dist/index.d.ts +98 -51
- package/dist/index.js +30556 -1020
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
@@ -8,61 +8,94 @@ 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;
|
17
18
|
};
|
18
|
-
type
|
19
|
+
type BaseField = {
|
20
|
+
label?: string;
|
21
|
+
};
|
22
|
+
type TextField = BaseField & {
|
23
|
+
type: "text" | "number" | "textarea";
|
24
|
+
};
|
25
|
+
type SelectField = BaseField & {
|
26
|
+
type: "select" | "radio";
|
27
|
+
options: {
|
28
|
+
label: string;
|
29
|
+
value: string | number | boolean;
|
30
|
+
}[];
|
31
|
+
};
|
32
|
+
type ArrayField<Props extends {
|
19
33
|
[key: string]: any;
|
20
34
|
} = {
|
21
35
|
[key: string]: any;
|
22
|
-
}> = {
|
23
|
-
type: "
|
24
|
-
|
25
|
-
|
26
|
-
adaptorParams?: object;
|
27
|
-
arrayFields?: {
|
28
|
-
[SubPropName in keyof Props]: Field<Props[SubPropName][0]>;
|
36
|
+
}> = BaseField & {
|
37
|
+
type: "array";
|
38
|
+
arrayFields: {
|
39
|
+
[SubPropName in keyof Props[0]]: Field<Props[0][SubPropName]>;
|
29
40
|
};
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
41
|
+
defaultItemProps?: Props[0];
|
42
|
+
getItemSummary?: (item: Props[0], index?: number) => string;
|
43
|
+
};
|
44
|
+
type ExternalField<Props extends {
|
45
|
+
[key: string]: any;
|
46
|
+
} = {
|
47
|
+
[key: string]: any;
|
48
|
+
}> = BaseField & {
|
49
|
+
type: "external";
|
50
|
+
adaptor: Adaptor<any, any, Props>;
|
51
|
+
adaptorParams?: object;
|
52
|
+
getItemSummary: (item: Props, index?: number) => string;
|
53
|
+
};
|
54
|
+
type CustomField<Props extends {
|
55
|
+
[key: string]: any;
|
56
|
+
} = {
|
57
|
+
[key: string]: any;
|
58
|
+
}> = BaseField & {
|
59
|
+
type: "custom";
|
60
|
+
render: (props: {
|
61
|
+
field: CustomField;
|
34
62
|
name: string;
|
35
63
|
value: any;
|
36
|
-
onChange: (value:
|
64
|
+
onChange: (value: Props) => void;
|
37
65
|
readOnly?: boolean;
|
38
66
|
}) => ReactElement;
|
39
|
-
options?: {
|
40
|
-
label: string;
|
41
|
-
value: string | number | boolean;
|
42
|
-
}[];
|
43
67
|
};
|
68
|
+
type Field<Props extends {
|
69
|
+
[key: string]: any;
|
70
|
+
} = {
|
71
|
+
[key: string]: any;
|
72
|
+
}> = TextField | SelectField | ArrayField<Props> | ExternalField<Props> | CustomField;
|
44
73
|
type DefaultRootProps = {
|
45
|
-
|
46
|
-
title: string;
|
47
|
-
editMode: boolean;
|
74
|
+
title?: string;
|
48
75
|
[key: string]: any;
|
49
76
|
};
|
77
|
+
type DefaultRootRenderProps = {
|
78
|
+
editMode: boolean;
|
79
|
+
} & DefaultRootProps;
|
50
80
|
type DefaultComponentProps = {
|
51
81
|
[key: string]: any;
|
52
82
|
editMode?: boolean;
|
53
83
|
};
|
54
84
|
type Fields<ComponentProps extends DefaultComponentProps = DefaultComponentProps> = {
|
55
|
-
[PropName in keyof Omit<Required<ComponentProps>, "children" | "editMode">]: Field<ComponentProps[PropName]
|
85
|
+
[PropName in keyof Omit<Required<ComponentProps>, "children" | "editMode">]: Field<ComponentProps[PropName]>;
|
56
86
|
};
|
57
87
|
type Content<Props extends {
|
58
88
|
[key: string]: any;
|
59
89
|
} = {
|
60
90
|
[key: string]: any;
|
61
|
-
}> =
|
62
|
-
type ComponentConfig<ComponentProps extends DefaultComponentProps = DefaultComponentProps, DefaultProps = ComponentProps
|
63
|
-
render: (props:
|
91
|
+
}> = ComponentData<Props>[];
|
92
|
+
type ComponentConfig<ComponentProps extends DefaultComponentProps = DefaultComponentProps, DefaultProps = ComponentProps, DataShape = ComponentData<ComponentProps>> = {
|
93
|
+
render: (props: WithPuckProps<ComponentProps>) => ReactElement;
|
64
94
|
defaultProps?: DefaultProps;
|
65
95
|
fields?: Fields<ComponentProps>;
|
96
|
+
resolveData?: (data: DataShape, params: {
|
97
|
+
changed: Partial<Record<keyof ComponentProps, boolean>>;
|
98
|
+
}) => Promise<Partial<ComponentDataWithOptionalProps<ComponentProps>>> | Partial<ComponentDataWithOptionalProps<ComponentProps>>;
|
66
99
|
};
|
67
100
|
type Category<ComponentName> = {
|
68
101
|
components?: ComponentName[];
|
@@ -79,38 +112,42 @@ type Config<Props extends {
|
|
79
112
|
other?: Category<Props>;
|
80
113
|
};
|
81
114
|
components: {
|
82
|
-
[ComponentName in keyof Props]: ComponentConfig<Props[ComponentName], Props[ComponentName]>;
|
115
|
+
[ComponentName in keyof Props]: Omit<ComponentConfig<Props[ComponentName], Props[ComponentName]>, "type">;
|
83
116
|
};
|
84
|
-
root?: ComponentConfig<RootProps & {
|
117
|
+
root?: Partial<ComponentConfig<RootProps & {
|
85
118
|
children: ReactNode;
|
86
119
|
}, Partial<RootProps & {
|
87
120
|
children: ReactNode;
|
88
|
-
}
|
121
|
+
}>, RootDataWithProps<RootProps>>>;
|
89
122
|
};
|
90
|
-
type
|
123
|
+
type BaseData<Props extends {
|
91
124
|
[key: string]: any;
|
92
125
|
} = {
|
93
126
|
[key: string]: any;
|
94
127
|
}> = {
|
128
|
+
readOnly?: Partial<Record<keyof Props, boolean>>;
|
129
|
+
};
|
130
|
+
type ComponentData<Props extends DefaultComponentProps = DefaultComponentProps> = {
|
95
131
|
type: keyof Props;
|
96
|
-
props:
|
97
|
-
|
98
|
-
|
132
|
+
props: WithPuckProps<Props>;
|
133
|
+
} & BaseData<Props>;
|
134
|
+
type RootDataWithProps<Props extends DefaultRootProps = DefaultRootProps> = {
|
135
|
+
props: Props;
|
99
136
|
};
|
100
|
-
type
|
101
|
-
|
102
|
-
|
103
|
-
[key: string]: any;
|
104
|
-
}, RootProps extends {
|
105
|
-
title: string;
|
137
|
+
type RootDataWithoutProps<Props extends DefaultRootProps = DefaultRootProps> = Props;
|
138
|
+
type RootData<Props extends DefaultRootProps = DefaultRootProps> = BaseData<Props> & Partial<RootDataWithProps<Props>> & Partial<RootDataWithoutProps<Props>>;
|
139
|
+
type ComponentDataWithOptionalProps<Props extends {
|
106
140
|
[key: string]: any;
|
107
141
|
} = {
|
108
|
-
title: string;
|
109
142
|
[key: string]: any;
|
110
|
-
}> = {
|
111
|
-
|
112
|
-
|
113
|
-
|
143
|
+
}> = Omit<ComponentData, "props"> & {
|
144
|
+
props: Partial<WithPuckProps<Props>>;
|
145
|
+
};
|
146
|
+
type MappedItem = ComponentData;
|
147
|
+
type Data<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultRootProps = DefaultRootProps> = {
|
148
|
+
root: RootData<RootProps>;
|
149
|
+
content: Content<WithPuckProps<Props>>;
|
150
|
+
zones?: Record<string, Content<WithPuckProps<Props>>>;
|
114
151
|
};
|
115
152
|
type ItemWithId = {
|
116
153
|
_arrayId: string;
|
@@ -185,13 +222,13 @@ type RemoveAction = {
|
|
185
222
|
index: number;
|
186
223
|
zone: string;
|
187
224
|
};
|
188
|
-
type
|
225
|
+
type SetUiAction = {
|
189
226
|
type: "setUi";
|
190
|
-
ui: Partial<UiState
|
227
|
+
ui: Partial<UiState> | ((previous: UiState) => Partial<UiState>);
|
191
228
|
};
|
192
229
|
type SetDataAction = {
|
193
230
|
type: "setData";
|
194
|
-
data: Partial<Data
|
231
|
+
data: Partial<Data> | ((previous: Data) => Partial<Data>);
|
195
232
|
};
|
196
233
|
type SetAction = {
|
197
234
|
type: "set";
|
@@ -207,7 +244,7 @@ type UnregisterZoneAction = {
|
|
207
244
|
};
|
208
245
|
type PuckAction = {
|
209
246
|
recordHistory?: boolean;
|
210
|
-
} & (ReorderAction | InsertAction | MoveAction | ReplaceAction | RemoveAction | DuplicateAction | SetAction | SetDataAction |
|
247
|
+
} & (ReorderAction | InsertAction | MoveAction | ReplaceAction | RemoveAction | DuplicateAction | SetAction | SetDataAction | SetUiAction | RegisterZoneAction | UnregisterZoneAction);
|
211
248
|
|
212
249
|
type PathData = Record<string, {
|
213
250
|
path: string[];
|
@@ -216,6 +253,7 @@ type PathData = Record<string, {
|
|
216
253
|
type DropZoneContext = {
|
217
254
|
data: Data;
|
218
255
|
config: Config;
|
256
|
+
componentState?: Record<string, any>;
|
219
257
|
itemSelector?: ItemSelector | null;
|
220
258
|
setItemSelector?: (newIndex: ItemSelector | null) => void;
|
221
259
|
dispatch?: (action: PuckAction) => void;
|
@@ -309,10 +347,19 @@ declare function Render({ config, data }: {
|
|
309
347
|
data: Data;
|
310
348
|
}): react_jsx_runtime.JSX.Element;
|
311
349
|
|
312
|
-
declare const
|
350
|
+
declare const resolveAllData: (data: Data, config: Config, onResolveStart?: ((item: MappedItem) => void) | undefined, onResolveEnd?: ((item: MappedItem) => void) | undefined) => Promise<{
|
351
|
+
root: RootDataWithProps<DefaultRootProps> | RootData<DefaultRootProps>;
|
352
|
+
content: any[];
|
353
|
+
zones: Record<string, MappedItem[]>;
|
354
|
+
}>;
|
355
|
+
|
356
|
+
declare const FieldLabel: ({ children, icon, label, el, readOnly, className, }: {
|
313
357
|
children?: ReactNode;
|
314
358
|
icon?: ReactNode;
|
315
359
|
label: string;
|
360
|
+
el?: "div" | "label" | undefined;
|
361
|
+
readOnly?: boolean | undefined;
|
362
|
+
className?: string | undefined;
|
316
363
|
}) => react_jsx_runtime.JSX.Element;
|
317
364
|
|
318
|
-
export { Adaptor, AppState, ArrayState, Button, ComponentConfig, Config, Content, Data, DefaultComponentProps, DefaultRootProps, DropZone, DropZoneProvider, Field, FieldLabel, Fields, IconButton, ItemWithId, MappedItem, Puck, Render, UiState, dropZoneContext };
|
365
|
+
export { Adaptor, AppState, ArrayField, ArrayState, BaseData, BaseField, Button, ComponentConfig, ComponentData, Config, Content, CustomField, Data, DefaultComponentProps, DefaultRootProps, DefaultRootRenderProps, DropZone, DropZoneProvider, ExternalField, Field, FieldLabel, Fields, IconButton, ItemWithId, MappedItem, Puck, Render, RootData, RootDataWithProps, RootDataWithoutProps, SelectField, TextField, UiState, dropZoneContext, resolveAllData };
|