@measured/puck 0.7.1-canary.9b15c6b → 0.8.0-canary.06b145b
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -0
- package/dist/index.css +277 -134
- package/dist/index.d.ts +115 -12
- package/dist/index.js +1609 -755
- package/package.json +3 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactElement, ReactNode, CSSProperties } from 'react';
|
|
2
3
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
|
+
import { DragStart, DragUpdate } from 'react-beautiful-dnd';
|
|
3
5
|
|
|
4
6
|
type Adaptor<AdaptorParams = {}> = {
|
|
5
7
|
name: string;
|
|
6
8
|
fetchList: (adaptorParams?: AdaptorParams) => Promise<Record<string, any>[] | null>;
|
|
7
9
|
};
|
|
10
|
+
type WithId<T> = T & {
|
|
11
|
+
id: string;
|
|
12
|
+
};
|
|
8
13
|
type Field<Props extends {
|
|
9
14
|
[key: string]: any;
|
|
10
15
|
} = {
|
|
@@ -15,7 +20,7 @@ type Field<Props extends {
|
|
|
15
20
|
adaptor?: Adaptor;
|
|
16
21
|
adaptorParams?: object;
|
|
17
22
|
arrayFields?: {
|
|
18
|
-
[SubPropName in keyof Props]: Field<Props[SubPropName]>;
|
|
23
|
+
[SubPropName in keyof Props]: Field<Props[SubPropName][0]>;
|
|
19
24
|
};
|
|
20
25
|
getItemSummary?: (item: Props, index?: number) => string;
|
|
21
26
|
defaultItemProps?: Props;
|
|
@@ -44,8 +49,13 @@ type DefaultComponentProps = {
|
|
|
44
49
|
type Fields<ComponentProps extends DefaultComponentProps = DefaultComponentProps> = {
|
|
45
50
|
[PropName in keyof Omit<Required<ComponentProps>, "children" | "editMode">]: Field<ComponentProps[PropName][0]>;
|
|
46
51
|
};
|
|
52
|
+
type Content<Props extends {
|
|
53
|
+
[key: string]: any;
|
|
54
|
+
} = {
|
|
55
|
+
[key: string]: any;
|
|
56
|
+
}> = MappedItem<Props>[];
|
|
47
57
|
type ComponentConfig<ComponentProps extends DefaultComponentProps = DefaultComponentProps, DefaultProps = ComponentProps> = {
|
|
48
|
-
render: (props: ComponentProps) => ReactElement;
|
|
58
|
+
render: (props: WithId<ComponentProps>) => ReactElement;
|
|
49
59
|
defaultProps?: DefaultProps;
|
|
50
60
|
fields?: Fields<ComponentProps>;
|
|
51
61
|
};
|
|
@@ -55,7 +65,7 @@ type Config<Props extends {
|
|
|
55
65
|
[key: string]: any;
|
|
56
66
|
}, RootProps extends DefaultRootProps = DefaultRootProps> = {
|
|
57
67
|
components: {
|
|
58
|
-
[ComponentName in keyof Props]: ComponentConfig<Props[ComponentName]>;
|
|
68
|
+
[ComponentName in keyof Props]: ComponentConfig<Props[ComponentName], Props[ComponentName]>;
|
|
59
69
|
};
|
|
60
70
|
root?: ComponentConfig<RootProps & {
|
|
61
71
|
children: ReactNode;
|
|
@@ -69,11 +79,9 @@ type MappedItem<Props extends {
|
|
|
69
79
|
[key: string]: any;
|
|
70
80
|
}> = {
|
|
71
81
|
type: keyof Props;
|
|
72
|
-
props: {
|
|
82
|
+
props: WithId<{
|
|
73
83
|
[key: string]: any;
|
|
74
|
-
}
|
|
75
|
-
id: string;
|
|
76
|
-
};
|
|
84
|
+
}>;
|
|
77
85
|
};
|
|
78
86
|
type Data<Props extends {
|
|
79
87
|
[key: string]: any;
|
|
@@ -87,7 +95,8 @@ type Data<Props extends {
|
|
|
87
95
|
[key: string]: any;
|
|
88
96
|
}> = {
|
|
89
97
|
root: RootProps;
|
|
90
|
-
content:
|
|
98
|
+
content: Content<Props>;
|
|
99
|
+
zones?: Record<string, Content<Props>>;
|
|
91
100
|
};
|
|
92
101
|
|
|
93
102
|
declare const Button: ({ children, href, onClick, variant, type, disabled, tabIndex, newTab, fullWidth, icon, size, }: {
|
|
@@ -104,6 +113,100 @@ declare const Button: ({ children, href, onClick, variant, type, disabled, tabIn
|
|
|
104
113
|
size?: "medium" | "large" | undefined;
|
|
105
114
|
}) => react_jsx_runtime.JSX.Element;
|
|
106
115
|
|
|
116
|
+
type ItemSelector = {
|
|
117
|
+
index: number;
|
|
118
|
+
zone?: string;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
type InsertAction = {
|
|
122
|
+
type: "insert";
|
|
123
|
+
componentType: string;
|
|
124
|
+
destinationIndex: number;
|
|
125
|
+
destinationZone: string;
|
|
126
|
+
};
|
|
127
|
+
type DuplicateAction = {
|
|
128
|
+
type: "duplicate";
|
|
129
|
+
sourceIndex: number;
|
|
130
|
+
sourceZone: string;
|
|
131
|
+
};
|
|
132
|
+
type ReplaceAction = {
|
|
133
|
+
type: "replace";
|
|
134
|
+
destinationIndex: number;
|
|
135
|
+
destinationZone: string;
|
|
136
|
+
data: any;
|
|
137
|
+
};
|
|
138
|
+
type ReorderAction = {
|
|
139
|
+
type: "reorder";
|
|
140
|
+
sourceIndex: number;
|
|
141
|
+
destinationIndex: number;
|
|
142
|
+
destinationZone: string;
|
|
143
|
+
};
|
|
144
|
+
type MoveAction = {
|
|
145
|
+
type: "move";
|
|
146
|
+
sourceIndex: number;
|
|
147
|
+
sourceZone: string;
|
|
148
|
+
destinationIndex: number;
|
|
149
|
+
destinationZone: string;
|
|
150
|
+
};
|
|
151
|
+
type RemoveAction = {
|
|
152
|
+
type: "remove";
|
|
153
|
+
index: number;
|
|
154
|
+
zone: string;
|
|
155
|
+
};
|
|
156
|
+
type SetDataAction = {
|
|
157
|
+
type: "set";
|
|
158
|
+
data: Partial<Data>;
|
|
159
|
+
};
|
|
160
|
+
type RegisterZoneAction = {
|
|
161
|
+
type: "registerZone";
|
|
162
|
+
zone: string;
|
|
163
|
+
};
|
|
164
|
+
type UnregisterZoneAction = {
|
|
165
|
+
type: "unregisterZone";
|
|
166
|
+
zone: string;
|
|
167
|
+
};
|
|
168
|
+
type PuckAction = ReorderAction | InsertAction | MoveAction | ReplaceAction | RemoveAction | DuplicateAction | SetDataAction | RegisterZoneAction | UnregisterZoneAction;
|
|
169
|
+
|
|
170
|
+
type PathData = Record<string, {
|
|
171
|
+
selector: ItemSelector | null;
|
|
172
|
+
label: string;
|
|
173
|
+
}[]>;
|
|
174
|
+
type DropZoneContext = {
|
|
175
|
+
data: Data;
|
|
176
|
+
config: Config;
|
|
177
|
+
itemSelector?: ItemSelector | null;
|
|
178
|
+
setItemSelector?: (newIndex: ItemSelector | null) => void;
|
|
179
|
+
dispatch?: (action: PuckAction) => void;
|
|
180
|
+
areaId?: string;
|
|
181
|
+
draggedItem?: DragStart & Partial<DragUpdate>;
|
|
182
|
+
placeholderStyle?: CSSProperties;
|
|
183
|
+
hoveringArea?: string | null;
|
|
184
|
+
setHoveringArea?: (area: string | null) => void;
|
|
185
|
+
hoveringZone?: string | null;
|
|
186
|
+
setHoveringZone?: (zone: string | null) => void;
|
|
187
|
+
hoveringComponent?: string | null;
|
|
188
|
+
setHoveringComponent?: (id: string | null) => void;
|
|
189
|
+
registerZoneArea?: (areaId: string) => void;
|
|
190
|
+
areasWithZones?: Record<string, boolean>;
|
|
191
|
+
registerZone?: (zoneCompound: string) => void;
|
|
192
|
+
unregisterZone?: (zoneCompound: string) => void;
|
|
193
|
+
activeZones?: Record<string, boolean>;
|
|
194
|
+
pathData?: PathData;
|
|
195
|
+
registerPath?: (selector: ItemSelector) => void;
|
|
196
|
+
mode?: "edit" | "render";
|
|
197
|
+
} | null;
|
|
198
|
+
declare const dropZoneContext: react.Context<DropZoneContext>;
|
|
199
|
+
declare const DropZoneProvider: ({ children, value, }: {
|
|
200
|
+
children: ReactNode;
|
|
201
|
+
value: DropZoneContext;
|
|
202
|
+
}) => react_jsx_runtime.JSX.Element;
|
|
203
|
+
|
|
204
|
+
type DropZoneProps = {
|
|
205
|
+
zone: string;
|
|
206
|
+
style?: CSSProperties;
|
|
207
|
+
};
|
|
208
|
+
declare function DropZone(props: DropZoneProps): react_jsx_runtime.JSX.Element;
|
|
209
|
+
|
|
107
210
|
declare const IconButton: ({ children, href, onClick, variant, type, disabled, tabIndex, newTab, fullWidth, title, }: {
|
|
108
211
|
children: ReactNode;
|
|
109
212
|
href?: string | undefined;
|
|
@@ -141,11 +244,11 @@ declare function Puck({ config, data: initialData, onChange, onPublish, plugins,
|
|
|
141
244
|
renderHeader?: (props: {
|
|
142
245
|
children: ReactNode;
|
|
143
246
|
data: Data;
|
|
144
|
-
|
|
247
|
+
dispatch: (action: PuckAction) => void;
|
|
145
248
|
}) => ReactElement;
|
|
146
249
|
renderHeaderActions?: (props: {
|
|
147
250
|
data: Data;
|
|
148
|
-
|
|
251
|
+
dispatch: (action: PuckAction) => void;
|
|
149
252
|
}) => ReactElement;
|
|
150
253
|
headerTitle?: string;
|
|
151
254
|
headerPath?: string;
|
|
@@ -162,4 +265,4 @@ declare const FieldLabel: ({ children, icon, label, }: {
|
|
|
162
265
|
label: string;
|
|
163
266
|
}) => react_jsx_runtime.JSX.Element;
|
|
164
267
|
|
|
165
|
-
export { Adaptor, Button, ComponentConfig, Config, Data, DefaultComponentProps, DefaultRootProps, Field, FieldLabel, Fields, IconButton, Puck, Render };
|
|
268
|
+
export { Adaptor, Button, ComponentConfig, Config, Content, Data, DefaultComponentProps, DefaultRootProps, DropZone, DropZoneProvider, Field, FieldLabel, Fields, IconButton, Puck, Render, dropZoneContext };
|