@measured/puck 0.16.0-canary.c7007ac → 0.16.0-canary.cfecf54

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.d.ts CHANGED
@@ -1,127 +1,26 @@
1
- import { U as UiState, D as Data, A as AppState, I as ItemSelector, F as Field, a as FieldProps, C as Config, b as DropZoneProps, V as Viewports, c as DefaultComponentProps, d as DefaultRootProps, M as MappedItem, R as RootData, e as RootDataWithProps, f as ComponentData } from './Config-VOJqVbHe.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-VOJqVbHe.js';
3
- import * as react from 'react';
4
- import { ReactNode, ReactElement, CSSProperties, SyntheticEvent } from 'react';
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 DefaultComponentProps, i as DefaultRootFieldProps, j as ComponentData } from './actions-DDAd8cys.js';
2
+ export { H as Adaptor, z as ArrayField, p as ArrayState, $ as AsFieldProps, B as BaseData, w as BaseField, r as ComponentConfig, u as ComponentDataMap, v as Content, L as CustomField, Y as DefaultRootProps, X as DefaultRootRenderProps, K as ExternalField, J as ExternalFieldWithAdaptor, m as FieldRenderFunctions, Q as Fields, n as ItemWithId, M as MappedItem, N as NumberField, G as ObjectField, l as OverrideKey, q as PuckComponent, W as PuckContext, y as RadioField, t as RootData, R as RootDataWithProps, s as RootDataWithoutProps, S as SelectField, T as TextField, x as TextareaField, k as Viewport, a0 as WithChildren, Z as WithId, _ as WithPuckProps, o as overrideKeys } from './actions-DDAd8cys.js';
5
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
+ import * as react 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;
62
- };
63
- type PuckAction = {
64
- recordHistory?: boolean;
65
- } & (ReorderAction | InsertAction | MoveAction | ReplaceAction | RemoveAction | DuplicateAction | SetAction | SetDataAction | SetUiAction | RegisterZoneAction | UnregisterZoneAction);
66
-
67
- type RenderFunc<Props extends {
68
- [key: string]: any;
69
- } = {
70
- children: ReactNode;
71
- }> = (props: Props) => ReactElement;
72
- declare const overrideKeys: readonly ["header", "headerActions", "fields", "fieldLabel", "components", "componentItem", "outline", "puck", "preview"];
73
- type OverrideKey = (typeof overrideKeys)[number];
74
- type OverridesGeneric<Shape extends {
75
- [key in OverrideKey]: any;
76
- }> = Shape;
77
- type Overrides = OverridesGeneric<{
78
- fieldTypes: Partial<FieldRenderFunctions>;
79
- header: RenderFunc<{
80
- actions: ReactNode;
81
- children: ReactNode;
82
- }>;
83
- headerActions: RenderFunc<{
84
- children: ReactNode;
85
- }>;
86
- preview: RenderFunc;
87
- fields: RenderFunc<{
88
- children: ReactNode;
89
- isLoading: boolean;
90
- itemSelector?: ItemSelector | null;
91
- }>;
92
- fieldLabel: RenderFunc<{
8
+ declare const ActionBar: {
9
+ ({ label, children, }: {
10
+ label?: string;
93
11
  children?: ReactNode;
94
- icon?: ReactNode;
95
- label: string;
96
- el?: "label" | "div";
97
- readOnly?: boolean;
98
- className?: string;
99
- }>;
100
- components: RenderFunc;
101
- componentItem: RenderFunc<{
102
- children: ReactNode;
103
- name: string;
104
- }>;
105
- outline: RenderFunc;
106
- puck: RenderFunc;
107
- }>;
108
- type FieldRenderFunctions = Omit<{
109
- [Type in Field["type"]]: React.FunctionComponent<FieldProps<Extract<Field, {
110
- type: Type;
111
- }>> & {
112
- children: ReactNode;
113
- name: string;
114
- }>;
115
- }, "custom"> & {
116
- [key: string]: React.FunctionComponent<FieldProps<any> & {
12
+ }): react_jsx_runtime.JSX.Element;
13
+ Action: ({ children, label, onClick, }: {
117
14
  children: ReactNode;
118
- name: string;
119
- }>;
120
- };
121
-
122
- type Plugin = {
123
- overrides: Partial<Overrides>;
15
+ label?: string;
16
+ onClick: (e: SyntheticEvent) => void;
17
+ }) => react_jsx_runtime.JSX.Element;
124
18
  };
19
+ declare const Action: ({ children, label, onClick, }: {
20
+ children: ReactNode;
21
+ label?: string;
22
+ onClick: (e: SyntheticEvent) => void;
23
+ }) => react_jsx_runtime.JSX.Element;
125
24
 
126
25
  declare const FieldLabel: ({ children, icon, label, el, readOnly, className, }: {
127
26
  children?: ReactNode;
@@ -176,7 +75,7 @@ declare const Drawer: {
176
75
  droppableId?: string;
177
76
  direction?: "vertical" | "horizontal";
178
77
  }): react_jsx_runtime.JSX.Element;
179
- Item: ({ name, children, id, label, index, }: {
78
+ Item: ({ name, children, id, label, index, isDragDisabled, }: {
180
79
  name: string;
181
80
  children?: (props: {
182
81
  children: ReactNode;
@@ -185,6 +84,7 @@ declare const Drawer: {
185
84
  id?: string;
186
85
  label?: string;
187
86
  index: number;
87
+ isDragDisabled?: boolean;
188
88
  }) => react_jsx_runtime.JSX.Element;
189
89
  };
190
90
 
@@ -207,8 +107,6 @@ type HistoryStore<D = any> = {
207
107
  setHistoryIndex: (index: number) => void;
208
108
  };
209
109
 
210
- type OnAction = (action: PuckAction, appState: AppState, prevAppState: AppState) => void;
211
-
212
110
  type PathData = Record<string, {
213
111
  path: string[];
214
112
  label: string;
@@ -261,27 +159,24 @@ declare const IconButton: ({ children, href, onClick, variant, type, disabled, t
261
159
  title: string;
262
160
  }) => react_jsx_runtime.JSX.Element;
263
161
 
264
- type IframeConfig = {
265
- enabled?: boolean;
266
- };
267
-
268
- declare function Puck<UserConfig extends Config = Config>({ children, config, data: initialData, ui: initialUi, onChange, onPublish, onAction, plugins, overrides, renderHeader, renderHeaderActions, headerTitle, headerPath, viewports, iframe, dnd, initialHistory, }: {
162
+ 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, }: {
269
163
  children?: ReactNode;
270
164
  config: UserConfig;
271
- data: Partial<Data>;
165
+ data: Partial<UserData>;
272
166
  ui?: Partial<UiState>;
273
- onChange?: (data: Data) => void;
274
- onPublish?: (data: Data) => void;
275
- onAction?: OnAction;
167
+ onChange?: (data: UserData) => void;
168
+ onPublish?: (data: UserData) => void;
169
+ onAction?: OnAction<UserData>;
170
+ permissions?: Partial<Permissions>;
276
171
  plugins?: Plugin[];
277
172
  overrides?: Partial<Overrides>;
278
173
  renderHeader?: (props: {
279
174
  children: ReactNode;
280
175
  dispatch: (action: PuckAction) => void;
281
- state: AppState;
176
+ state: AppState<UserData>;
282
177
  }) => ReactElement;
283
178
  renderHeaderActions?: (props: {
284
- state: AppState;
179
+ state: AppState<UserData>;
285
180
  dispatch: (action: PuckAction) => void;
286
181
  }) => ReactElement;
287
182
  headerTitle?: string;
@@ -305,14 +200,14 @@ declare namespace Puck {
305
200
  }) => react_jsx_runtime.JSX.Element;
306
201
  }
307
202
 
308
- declare function Render<UserConfig extends Config = Config>({ config, data, }: {
203
+ 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 }: {
309
204
  config: UserConfig;
310
- data: Partial<Data>;
205
+ data: Partial<UserData>;
311
206
  }): react_jsx_runtime.JSX.Element;
312
207
 
313
208
  declare function migrate(data: Data): Data;
314
209
 
315
- type PropTransform<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultRootProps = DefaultRootProps> = Partial<{
210
+ type PropTransform<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultComponentProps = DefaultRootFieldProps> = Partial<{
316
211
  [ComponentName in keyof Props]: (props: Props[ComponentName] & {
317
212
  [key: string]: any;
318
213
  }) => Props[ComponentName];
@@ -321,18 +216,25 @@ type PropTransform<Props extends DefaultComponentProps = DefaultComponentProps,
321
216
  [key: string]: any;
322
217
  }) => RootProps;
323
218
  }>;
324
- declare function transformProps<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultComponentProps = DefaultComponentProps>(data: Partial<Data>, propTransforms: PropTransform<Props, RootProps>): Data;
219
+ declare function transformProps<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultComponentProps = DefaultRootFieldProps>(data: Partial<Data>, propTransforms: PropTransform<Props, RootProps>): Data;
325
220
 
326
- declare function resolveAllData(data: Partial<Data>, config: Config, onResolveStart?: (item: MappedItem) => void, onResolveEnd?: (item: MappedItem) => void): Promise<{
327
- root: RootData<DefaultRootProps> | RootDataWithProps;
328
- content: any;
329
- zones: Record<string, MappedItem[]>;
330
- }>;
221
+ 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>>;
331
222
 
332
223
  declare const usePuck: () => {
333
224
  appState: AppState;
334
225
  config: Config;
335
226
  dispatch: (action: PuckAction) => void;
227
+ getPermissions: ({ item, type, }?: {
228
+ item?: ComponentData;
229
+ type?: keyof DefaultComponentProps;
230
+ }) => {
231
+ [x: string]: boolean | undefined;
232
+ drag?: boolean | undefined;
233
+ duplicate?: boolean | undefined;
234
+ delete?: boolean | undefined;
235
+ edit?: boolean | undefined;
236
+ insert?: boolean | undefined;
237
+ };
336
238
  history: {
337
239
  back: VoidFunction;
338
240
  forward: VoidFunction;
@@ -344,9 +246,7 @@ declare const usePuck: () => {
344
246
  index: number;
345
247
  historyStore: HistoryStore | undefined;
346
248
  };
347
- selectedItem: ComponentData<DefaultComponentProps & {
348
- id: string;
349
- }> | null;
249
+ selectedItem: ComponentData<any, string> | null;
350
250
  };
351
251
 
352
- export { AppState, AutoField, AutoFieldPrivate, Button, ComponentData, Config, Data, DefaultComponentProps, DefaultRootProps, Drawer, DropZone, DropZoneProvider, Field, FieldLabel, FieldLabelInternal, FieldProps, type FieldPropsInternal, type History, IconButton, MappedItem, type Plugin, Puck, type PuckAction, Render, RootData, RootDataWithProps, UiState, dropZoneContext, migrate, resolveAllData, transformProps, usePuck };
252
+ export { Action, ActionBar, AppState, AutoField, AutoFieldPrivate, Button, ComponentData, Config, Data, DefaultComponentProps, DefaultRootFieldProps, Drawer, DropZone, DropZoneProvider, ExtractPropsFromConfig, ExtractRootPropsFromConfig, Field, FieldLabel, FieldLabelInternal, FieldProps, type FieldPropsInternal, type History, IconButton, IframeConfig, OnAction, Overrides, Permissions, Plugin, Puck, PuckAction, Render, UiState, Viewports, dropZoneContext, migrate, resolveAllData, transformProps, usePuck };