@measured/puck 0.16.0-canary.0c7fc83 → 0.16.0-canary.257e4be

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.d.ts CHANGED
@@ -1,76 +1,34 @@
1
- import { U as UiState, D as Data, A as AppState, F as Field, a as FieldProps, C as Config, b as DefaultRootProps, I as ItemSelector, c as DropZoneProps, V as Viewports, d as DefaultComponentProps, M as MappedItem, R as RootDataWithProps, e as RootData, f as ComponentData } from './Config-041c35a2.js';
2
- export { q as Adaptor, p as ArrayField, l as ArrayState, B as BaseData, m as BaseField, i as ComponentConfig, g as Content, s as CustomField, r as ExternalField, E as ExternalFieldWithAdaptor, t as Fields, k as ItemWithId, N as NumberField, O as ObjectField, P as PuckComponent, h as PuckContext, o as RadioField, j as RootDataWithoutProps, S as SelectField, T as TextField, n as TextareaField } from './Config-041c35a2.js';
1
+ import { F as Field, a as FieldProps, C as Config, D as Data, I as ItemSelector, P as PuckAction, b as DropZoneProps, E as ExtractPropsFromConfig, c as ExtractRootPropsFromConfig, U as UiState, O as OnAction, d as Permissions, e as Plugin, f as Overrides, A as AppState, V as Viewports, g as IframeConfig, h as InitialHistory, i as DefaultComponentProps, j as DefaultRootFieldProps, k as ComponentData, H as History } from './actions-Dyg9ei4T.js';
2
+ export { K as Adaptor, G as ArrayField, q as ArrayState, a1 as AsFieldProps, B as BaseData, x as BaseField, s as ComponentConfig, v as ComponentDataMap, w as Content, W as CustomField, _ as DefaultRootProps, Z as DefaultRootRenderProps, Q as ExternalField, L as ExternalFieldWithAdaptor, n as FieldRenderFunctions, X as Fields, p as ItemWithId, M as MappedItem, N as NumberField, J as ObjectField, m as OverrideKey, r as PuckComponent, Y as PuckContext, z as RadioField, u as RootData, R as RootDataWithProps, t as RootDataWithoutProps, S as SelectField, T as TextField, y as TextareaField, l as Viewport, a2 as WithChildren, $ as WithId, a0 as WithPuckProps, o as overrideKeys } from './actions-Dyg9ei4T.js';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
  import * as react from 'react';
5
- import { ReactNode, ReactElement, CSSProperties, SyntheticEvent } from 'react';
5
+ import { ReactNode, SyntheticEvent, ReactElement, CSSProperties } from 'react';
6
6
  import { DragStart, DragUpdate } from '@measured/dnd';
7
7
 
8
- type InsertAction = {
9
- type: "insert";
10
- componentType: string;
11
- destinationIndex: number;
12
- destinationZone: string;
13
- };
14
- type DuplicateAction = {
15
- type: "duplicate";
16
- sourceIndex: number;
17
- sourceZone: string;
18
- };
19
- type ReplaceAction = {
20
- type: "replace";
21
- destinationIndex: number;
22
- destinationZone: string;
23
- data: any;
24
- };
25
- type ReorderAction = {
26
- type: "reorder";
27
- sourceIndex: number;
28
- destinationIndex: number;
29
- destinationZone: string;
30
- };
31
- type MoveAction = {
32
- type: "move";
33
- sourceIndex: number;
34
- sourceZone: string;
35
- destinationIndex: number;
36
- destinationZone: string;
37
- };
38
- type RemoveAction = {
39
- type: "remove";
40
- index: number;
41
- zone: string;
42
- };
43
- type SetUiAction = {
44
- type: "setUi";
45
- ui: Partial<UiState> | ((previous: UiState) => Partial<UiState>);
46
- };
47
- type SetDataAction = {
48
- type: "setData";
49
- data: Partial<Data> | ((previous: Data) => Partial<Data>);
50
- };
51
- type SetAction = {
52
- type: "set";
53
- state: Partial<AppState> | ((previous: AppState) => Partial<AppState>);
54
- };
55
- type RegisterZoneAction = {
56
- type: "registerZone";
57
- zone: string;
58
- };
59
- type UnregisterZoneAction = {
60
- type: "unregisterZone";
61
- zone: string;
8
+ declare const ActionBar: {
9
+ ({ label, children, }: {
10
+ label?: string;
11
+ children?: ReactNode;
12
+ }): react_jsx_runtime.JSX.Element;
13
+ Action: ({ children, label, onClick, }: {
14
+ children: ReactNode;
15
+ label?: string;
16
+ onClick: (e: SyntheticEvent) => void;
17
+ }) => react_jsx_runtime.JSX.Element;
62
18
  };
63
- type PuckAction = {
64
- recordHistory?: boolean;
65
- } & (ReorderAction | InsertAction | MoveAction | ReplaceAction | RemoveAction | DuplicateAction | SetAction | SetDataAction | SetUiAction | RegisterZoneAction | UnregisterZoneAction);
19
+ declare const Action: ({ children, label, onClick, }: {
20
+ children: ReactNode;
21
+ label?: string;
22
+ onClick: (e: SyntheticEvent) => void;
23
+ }) => react_jsx_runtime.JSX.Element;
66
24
 
67
25
  declare const FieldLabel: ({ children, icon, label, el, readOnly, className, }: {
68
26
  children?: ReactNode;
69
27
  icon?: ReactNode;
70
28
  label: string;
71
- el?: "label" | "div" | undefined;
72
- readOnly?: boolean | undefined;
73
- className?: string | undefined;
29
+ el?: "label" | "div";
30
+ readOnly?: boolean;
31
+ className?: string;
74
32
  }) => react_jsx_runtime.JSX.Element;
75
33
  type FieldLabelPropsInternal = {
76
34
  children?: ReactNode;
@@ -98,34 +56,35 @@ declare function AutoField<ValueType = any, FieldType extends Field<ValueType> =
98
56
 
99
57
  declare const Button: ({ children, href, onClick, variant, type, disabled, tabIndex, newTab, fullWidth, icon, size, loading: loadingProp, }: {
100
58
  children: ReactNode;
101
- href?: string | undefined;
102
- onClick?: ((e: any) => void | Promise<void>) | undefined;
103
- variant?: "primary" | "secondary" | undefined;
104
- type?: "button" | "submit" | "reset" | undefined;
105
- disabled?: boolean | undefined;
106
- tabIndex?: number | undefined;
107
- newTab?: boolean | undefined;
108
- fullWidth?: boolean | undefined;
59
+ href?: string;
60
+ onClick?: (e: any) => void | Promise<void>;
61
+ variant?: "primary" | "secondary";
62
+ type?: "button" | "submit" | "reset";
63
+ disabled?: boolean;
64
+ tabIndex?: number;
65
+ newTab?: boolean;
66
+ fullWidth?: boolean;
109
67
  icon?: ReactNode;
110
- size?: "medium" | "large" | undefined;
111
- loading?: boolean | undefined;
68
+ size?: "medium" | "large";
69
+ loading?: boolean;
112
70
  }) => react_jsx_runtime.JSX.Element;
113
71
 
114
72
  declare const Drawer: {
115
73
  ({ children, droppableId: _droppableId, direction, }: {
116
74
  children: ReactNode;
117
- droppableId?: string | undefined;
118
- direction?: "vertical" | "horizontal" | undefined;
75
+ droppableId?: string;
76
+ direction?: "vertical" | "horizontal";
119
77
  }): react_jsx_runtime.JSX.Element;
120
- Item: ({ name, children, id, label, index, }: {
78
+ Item: ({ name, children, id, label, index, isDragDisabled, }: {
121
79
  name: string;
122
- children?: ((props: {
80
+ children?: (props: {
123
81
  children: ReactNode;
124
82
  name: string;
125
- }) => ReactElement) | undefined;
126
- id?: string | undefined;
127
- label?: string | undefined;
83
+ }) => ReactElement;
84
+ id?: string;
85
+ label?: string;
128
86
  index: number;
87
+ isDragDisabled?: boolean;
129
88
  }) => react_jsx_runtime.JSX.Element;
130
89
  };
131
90
 
@@ -160,7 +119,7 @@ type DropZoneContext<UserConfig extends Config = Config> = {
160
119
  zoneWillDrag?: string;
161
120
  setZoneWillDrag?: (zone: string) => void;
162
121
  } | null;
163
- declare const dropZoneContext: react.Context<DropZoneContext<Config<Record<string, any>, DefaultRootProps, string>>>;
122
+ declare const dropZoneContext: react.Context<DropZoneContext<Config>>;
164
123
  declare const DropZoneProvider: ({ children, value, }: {
165
124
  children: ReactNode;
166
125
  value: DropZoneContext;
@@ -170,113 +129,35 @@ declare function DropZone(props: DropZoneProps): react_jsx_runtime.JSX.Element;
170
129
 
171
130
  declare const IconButton: ({ children, href, onClick, variant, type, disabled, tabIndex, newTab, fullWidth, title, }: {
172
131
  children: ReactNode;
173
- href?: string | undefined;
174
- onClick?: ((e: SyntheticEvent) => void | Promise<void>) | undefined;
175
- variant?: "primary" | "secondary" | undefined;
176
- type?: "button" | "submit" | "reset" | undefined;
177
- disabled?: boolean | undefined;
178
- tabIndex?: number | undefined;
179
- newTab?: boolean | undefined;
180
- fullWidth?: boolean | undefined;
132
+ href?: string;
133
+ onClick?: (e: SyntheticEvent) => void | Promise<void>;
134
+ variant?: "primary" | "secondary";
135
+ type?: "button" | "submit" | "reset";
136
+ disabled?: boolean;
137
+ tabIndex?: number;
138
+ newTab?: boolean;
139
+ fullWidth?: boolean;
181
140
  title: string;
182
141
  }) => react_jsx_runtime.JSX.Element;
183
142
 
184
- type RenderFunc<Props extends {
185
- [key: string]: any;
186
- } = {
187
- children: ReactNode;
188
- }> = (props: Props) => ReactElement;
189
- declare const overrideKeys: readonly ["header", "headerActions", "fields", "fieldLabel", "components", "componentItem", "outline", "puck", "preview"];
190
- type OverrideKey = (typeof overrideKeys)[number];
191
- type OverridesGeneric<Shape extends {
192
- [key in OverrideKey]: any;
193
- }> = Shape;
194
- type Overrides = OverridesGeneric<{
195
- fieldTypes: Partial<FieldRenderFunctions>;
196
- header: RenderFunc<{
197
- actions: ReactNode;
198
- children: ReactNode;
199
- }>;
200
- headerActions: RenderFunc<{
201
- children: ReactNode;
202
- }>;
203
- preview: RenderFunc;
204
- fields: RenderFunc<{
205
- children: ReactNode;
206
- isLoading: boolean;
207
- itemSelector?: ItemSelector | null;
208
- }>;
209
- fieldLabel: RenderFunc<{
210
- children?: ReactNode;
211
- icon?: ReactNode;
212
- label: string;
213
- el?: "label" | "div";
214
- readOnly?: boolean;
215
- className?: string;
216
- }>;
217
- components: RenderFunc;
218
- componentItem: RenderFunc<{
219
- children: ReactNode;
220
- name: string;
221
- }>;
222
- outline: RenderFunc;
223
- puck: RenderFunc;
224
- }>;
225
- type FieldRenderFunctions = Omit<{
226
- [Type in Field["type"]]: React.FunctionComponent<FieldProps<Extract<Field, {
227
- type: Type;
228
- }>> & {
229
- children: ReactNode;
230
- name: string;
231
- }>;
232
- }, "custom"> & {
233
- [key: string]: React.FunctionComponent<FieldProps<any> & {
234
- children: ReactNode;
235
- name: string;
236
- }>;
237
- };
238
-
239
- type Plugin = {
240
- overrides: Partial<Overrides>;
241
- };
242
-
243
- type History<D = any> = {
244
- id: string;
245
- data: D;
246
- };
247
- type HistoryStore<D = any> = {
248
- index: number;
249
- currentHistory: History;
250
- hasPast: boolean;
251
- hasFuture: boolean;
252
- record: (data: D) => void;
253
- back: VoidFunction;
254
- forward: VoidFunction;
255
- nextHistory: History<D> | null;
256
- prevHistory: History<D> | null;
257
- histories: History<D>[];
258
- };
259
-
260
- type IframeConfig = {
261
- enabled?: boolean;
262
- };
263
-
264
- declare function Puck<UserConfig extends Config = Config>({ children, config, data: initialData, ui: initialUi, onChange, onPublish, plugins, overrides, renderHeader, renderHeaderActions, headerTitle, headerPath, viewports, iframe, dnd, initialHistories, }: {
143
+ declare function Puck<UserConfig extends Config = Config, UserProps extends ExtractPropsFromConfig<UserConfig> = ExtractPropsFromConfig<UserConfig>, UserRootProps extends ExtractRootPropsFromConfig<UserConfig> = ExtractRootPropsFromConfig<UserConfig>, UserData extends Data<UserProps, UserRootProps> | Data = Data<UserProps, UserRootProps>>({ children, config, data: initialData, ui: initialUi, onChange, onPublish, onAction, permissions, plugins, overrides, renderHeader, renderHeaderActions, headerTitle, headerPath, viewports, iframe, dnd, initialHistory: _initialHistory, }: {
265
144
  children?: ReactNode;
266
145
  config: UserConfig;
267
- data: Partial<Data>;
146
+ data: Partial<UserData>;
268
147
  ui?: Partial<UiState>;
269
- onChange?: (data: Data) => void;
270
- onPublish?: (data: Data) => void;
148
+ onChange?: (data: UserData) => void;
149
+ onPublish?: (data: UserData) => void;
150
+ onAction?: OnAction<UserData>;
151
+ permissions?: Partial<Permissions>;
271
152
  plugins?: Plugin[];
272
153
  overrides?: Partial<Overrides>;
273
154
  renderHeader?: (props: {
274
155
  children: ReactNode;
275
156
  dispatch: (action: PuckAction) => void;
276
- state: AppState;
157
+ state: AppState<UserData>;
277
158
  }) => ReactElement;
278
159
  renderHeaderActions?: (props: {
279
- state: AppState;
160
+ state: AppState<UserData>;
280
161
  dispatch: (action: PuckAction) => void;
281
162
  }) => ReactElement;
282
163
  headerTitle?: string;
@@ -286,28 +167,25 @@ declare function Puck<UserConfig extends Config = Config>({ children, config, da
286
167
  dnd?: {
287
168
  disableAutoScroll?: boolean;
288
169
  };
289
- initialHistories?: {
290
- histories: History<any>[];
291
- index: number;
292
- };
170
+ initialHistory?: InitialHistory;
293
171
  }): react_jsx_runtime.JSX.Element;
294
172
  declare namespace Puck {
295
173
  var Components: () => react_jsx_runtime.JSX.Element;
296
174
  var Fields: () => react_jsx_runtime.JSX.Element;
297
175
  var Outline: () => react_jsx_runtime.JSX.Element;
298
176
  var Preview: ({ id }: {
299
- id?: string | undefined;
177
+ id?: string;
300
178
  }) => react_jsx_runtime.JSX.Element;
301
179
  }
302
180
 
303
- declare function Render<UserConfig extends Config = Config>({ config, data, }: {
181
+ declare function Render<UserConfig extends Config = Config, UserProps extends ExtractPropsFromConfig<UserConfig> = ExtractPropsFromConfig<UserConfig>, UserRootProps extends ExtractRootPropsFromConfig<UserConfig> = ExtractRootPropsFromConfig<UserConfig>, UserData extends Data<UserProps, UserRootProps> | Data = Data<UserProps, UserRootProps>>({ config, data }: {
304
182
  config: UserConfig;
305
- data: Partial<Data>;
183
+ data: Partial<UserData>;
306
184
  }): react_jsx_runtime.JSX.Element;
307
185
 
308
186
  declare function migrate(data: Data): Data;
309
187
 
310
- type PropTransform<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultRootProps = DefaultRootProps> = Partial<{
188
+ type PropTransform<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultComponentProps = DefaultRootFieldProps> = Partial<{
311
189
  [ComponentName in keyof Props]: (props: Props[ComponentName] & {
312
190
  [key: string]: any;
313
191
  }) => Props[ComponentName];
@@ -316,28 +194,52 @@ type PropTransform<Props extends DefaultComponentProps = DefaultComponentProps,
316
194
  [key: string]: any;
317
195
  }) => RootProps;
318
196
  }>;
319
- declare function transformProps<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultComponentProps = DefaultComponentProps>(data: Partial<Data>, propTransforms: PropTransform<Props, RootProps>): Data;
197
+ declare function transformProps<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultComponentProps = DefaultRootFieldProps>(data: Partial<Data>, propTransforms: PropTransform<Props, RootProps>): Data;
320
198
 
321
- declare function resolveAllData(data: Partial<Data>, config: Config, onResolveStart?: (item: MappedItem) => void, onResolveEnd?: (item: MappedItem) => void): Promise<{
322
- root: RootDataWithProps<DefaultRootProps> | RootData<DefaultRootProps>;
323
- content: any[];
324
- zones: Record<string, MappedItem[]>;
325
- }>;
199
+ declare function resolveAllData<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends Record<string, any> = DefaultRootFieldProps>(data: Partial<Data>, config: Config, onResolveStart?: (item: ComponentData) => void, onResolveEnd?: (item: ComponentData) => void): Promise<Data<Props, RootProps>>;
326
200
 
327
- type PuckHistory = {
201
+ type HistoryStore<D = any> = {
202
+ index: number;
203
+ hasPast: boolean;
204
+ hasFuture: boolean;
205
+ histories: History<D>[];
206
+ record: (data: D) => void;
328
207
  back: VoidFunction;
329
208
  forward: VoidFunction;
330
- historyStore: HistoryStore;
209
+ currentHistory: History;
210
+ nextHistory: History<D> | null;
211
+ prevHistory: History<D> | null;
212
+ setHistories: (histories: History[]) => void;
213
+ setHistoryIndex: (index: number) => void;
331
214
  };
332
215
 
333
216
  declare const usePuck: () => {
334
217
  appState: AppState;
335
- config: Config<Record<string, any>, DefaultRootProps, string>;
218
+ config: Config;
336
219
  dispatch: (action: PuckAction) => void;
337
- history: Partial<PuckHistory>;
338
- selectedItem: ComponentData<DefaultComponentProps & {
339
- id: string;
340
- }> | null;
220
+ getPermissions: ({ item, type, }?: {
221
+ item?: ComponentData;
222
+ type?: keyof DefaultComponentProps;
223
+ }) => {
224
+ [x: string]: boolean | undefined;
225
+ drag?: boolean | undefined;
226
+ duplicate?: boolean | undefined;
227
+ delete?: boolean | undefined;
228
+ edit?: boolean | undefined;
229
+ insert?: boolean | undefined;
230
+ };
231
+ history: {
232
+ back: VoidFunction;
233
+ forward: VoidFunction;
234
+ setHistories: (histories: History[]) => void;
235
+ setHistoryIndex: (index: number) => void;
236
+ hasPast: boolean;
237
+ hasFuture: boolean;
238
+ histories: History<any>[];
239
+ index: number;
240
+ historyStore: HistoryStore | undefined;
241
+ };
242
+ selectedItem: ComponentData<any, string> | null;
341
243
  };
342
244
 
343
- export { AppState, AutoField, AutoFieldPrivate, Button, ComponentData, Config, Data, DefaultComponentProps, DefaultRootProps, Drawer, DropZone, DropZoneProvider, Field, FieldLabel, FieldLabelInternal, FieldProps, FieldPropsInternal, IconButton, MappedItem, Puck, PuckAction, Render, RootData, RootDataWithProps, UiState, dropZoneContext, migrate, resolveAllData, transformProps, usePuck };
245
+ export { Action, ActionBar, AppState, AutoField, AutoFieldPrivate, Button, ComponentData, Config, Data, DefaultComponentProps, DefaultRootFieldProps, Drawer, DropZone, DropZoneProvider, ExtractPropsFromConfig, ExtractRootPropsFromConfig, Field, FieldLabel, FieldLabelInternal, FieldProps, type FieldPropsInternal, History, IconButton, IframeConfig, InitialHistory, OnAction, Overrides, Permissions, Plugin, Puck, PuckAction, Render, UiState, Viewports, dropZoneContext, migrate, resolveAllData, transformProps, usePuck };