@measured/puck 0.16.0-canary.39e7f40 → 0.16.0-canary.464aa1e

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.d.ts CHANGED
@@ -1,135 +1,34 @@
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 DefaultRootProps, 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';
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 InitialHistory, i as DefaultComponentProps, j as DefaultRootFieldProps, k as ComponentData, H as History } from './actions-CBAJO1CV.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-CBAJO1CV.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;
128
27
  icon?: ReactNode;
129
28
  label: string;
130
- el?: "label" | "div" | undefined;
131
- readOnly?: boolean | undefined;
132
- className?: string | undefined;
29
+ el?: "label" | "div";
30
+ readOnly?: boolean;
31
+ className?: string;
133
32
  }) => react_jsx_runtime.JSX.Element;
134
33
  type FieldLabelPropsInternal = {
135
34
  children?: ReactNode;
@@ -157,56 +56,38 @@ declare function AutoField<ValueType = any, FieldType extends Field<ValueType> =
157
56
 
158
57
  declare const Button: ({ children, href, onClick, variant, type, disabled, tabIndex, newTab, fullWidth, icon, size, loading: loadingProp, }: {
159
58
  children: ReactNode;
160
- href?: string | undefined;
161
- onClick?: ((e: any) => void | Promise<void>) | undefined;
162
- variant?: "primary" | "secondary" | undefined;
163
- type?: "button" | "submit" | "reset" | undefined;
164
- disabled?: boolean | undefined;
165
- tabIndex?: number | undefined;
166
- newTab?: boolean | undefined;
167
- 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;
168
67
  icon?: ReactNode;
169
- size?: "medium" | "large" | undefined;
170
- loading?: boolean | undefined;
68
+ size?: "medium" | "large";
69
+ loading?: boolean;
171
70
  }) => react_jsx_runtime.JSX.Element;
172
71
 
173
72
  declare const Drawer: {
174
73
  ({ children, droppableId: _droppableId, direction, }: {
175
74
  children: ReactNode;
176
- droppableId?: string | undefined;
177
- direction?: "vertical" | "horizontal" | undefined;
75
+ droppableId?: string;
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
- children?: ((props: {
80
+ children?: (props: {
182
81
  children: ReactNode;
183
82
  name: string;
184
- }) => ReactElement) | undefined;
185
- id?: string | undefined;
186
- label?: string | undefined;
83
+ }) => ReactElement;
84
+ id?: string;
85
+ label?: string;
187
86
  index: number;
87
+ isDragDisabled?: boolean;
188
88
  }) => react_jsx_runtime.JSX.Element;
189
89
  };
190
90
 
191
- type History<D = any> = {
192
- id: string;
193
- data: D;
194
- };
195
- type HistoryStore<D = any> = {
196
- index: number;
197
- hasPast: boolean;
198
- hasFuture: boolean;
199
- histories: History<D>[];
200
- record: (data: D) => void;
201
- back: VoidFunction;
202
- forward: VoidFunction;
203
- currentHistory: History;
204
- nextHistory: History<D> | null;
205
- prevHistory: History<D> | null;
206
- setHistories: (histories: History[]) => void;
207
- setHistoryIndex: (index: number) => void;
208
- };
209
-
210
91
  type PathData = Record<string, {
211
92
  path: string[];
212
93
  label: string;
@@ -238,7 +119,7 @@ type DropZoneContext<UserConfig extends Config = Config> = {
238
119
  zoneWillDrag?: string;
239
120
  setZoneWillDrag?: (zone: string) => void;
240
121
  } | null;
241
- declare const dropZoneContext: react.Context<DropZoneContext<Config<Record<string, any>, DefaultRootProps, string>>>;
122
+ declare const dropZoneContext: react.Context<DropZoneContext<Config>>;
242
123
  declare const DropZoneProvider: ({ children, value, }: {
243
124
  children: ReactNode;
244
125
  value: DropZoneContext;
@@ -248,37 +129,35 @@ declare function DropZone(props: DropZoneProps): react_jsx_runtime.JSX.Element;
248
129
 
249
130
  declare const IconButton: ({ children, href, onClick, variant, type, disabled, tabIndex, newTab, fullWidth, title, }: {
250
131
  children: ReactNode;
251
- href?: string | undefined;
252
- onClick?: ((e: SyntheticEvent) => void | Promise<void>) | undefined;
253
- variant?: "primary" | "secondary" | undefined;
254
- type?: "button" | "submit" | "reset" | undefined;
255
- disabled?: boolean | undefined;
256
- tabIndex?: number | undefined;
257
- newTab?: boolean | undefined;
258
- 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;
259
140
  title: string;
260
141
  }) => react_jsx_runtime.JSX.Element;
261
142
 
262
- type IframeConfig = {
263
- enabled?: boolean;
264
- };
265
-
266
- declare function Puck<UserConfig extends Config = Config>({ children, config, data: initialData, ui: initialUi, onChange, onPublish, plugins, overrides, renderHeader, renderHeaderActions, headerTitle, headerPath, viewports, iframe, dnd, initialHistory, }: {
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, }: {
267
144
  children?: ReactNode;
268
145
  config: UserConfig;
269
- data: Partial<Data>;
146
+ data: Partial<UserData>;
270
147
  ui?: Partial<UiState>;
271
- onChange?: (data: Data) => void;
272
- onPublish?: (data: Data) => void;
148
+ onChange?: (data: UserData) => void;
149
+ onPublish?: (data: UserData) => void;
150
+ onAction?: OnAction<UserData>;
151
+ permissions?: Partial<Permissions>;
273
152
  plugins?: Plugin[];
274
153
  overrides?: Partial<Overrides>;
275
154
  renderHeader?: (props: {
276
155
  children: ReactNode;
277
156
  dispatch: (action: PuckAction) => void;
278
- state: AppState;
157
+ state: AppState<UserData>;
279
158
  }) => ReactElement;
280
159
  renderHeaderActions?: (props: {
281
- state: AppState;
160
+ state: AppState<UserData>;
282
161
  dispatch: (action: PuckAction) => void;
283
162
  }) => ReactElement;
284
163
  headerTitle?: string;
@@ -288,28 +167,25 @@ declare function Puck<UserConfig extends Config = Config>({ children, config, da
288
167
  dnd?: {
289
168
  disableAutoScroll?: boolean;
290
169
  };
291
- initialHistory?: {
292
- histories: History<any>[];
293
- index: number;
294
- };
170
+ initialHistory?: InitialHistory;
295
171
  }): react_jsx_runtime.JSX.Element;
296
172
  declare namespace Puck {
297
173
  var Components: () => react_jsx_runtime.JSX.Element;
298
174
  var Fields: () => react_jsx_runtime.JSX.Element;
299
175
  var Outline: () => react_jsx_runtime.JSX.Element;
300
176
  var Preview: ({ id }: {
301
- id?: string | undefined;
177
+ id?: string;
302
178
  }) => react_jsx_runtime.JSX.Element;
303
179
  }
304
180
 
305
- 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 }: {
306
182
  config: UserConfig;
307
- data: Partial<Data>;
183
+ data: Partial<UserData>;
308
184
  }): react_jsx_runtime.JSX.Element;
309
185
 
310
186
  declare function migrate(data: Data): Data;
311
187
 
312
- type PropTransform<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultRootProps = DefaultRootProps> = Partial<{
188
+ type PropTransform<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultComponentProps = DefaultRootFieldProps> = Partial<{
313
189
  [ComponentName in keyof Props]: (props: Props[ComponentName] & {
314
190
  [key: string]: any;
315
191
  }) => Props[ComponentName];
@@ -318,32 +194,52 @@ type PropTransform<Props extends DefaultComponentProps = DefaultComponentProps,
318
194
  [key: string]: any;
319
195
  }) => RootProps;
320
196
  }>;
321
- 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;
322
198
 
323
- declare function resolveAllData(data: Partial<Data>, config: Config, onResolveStart?: (item: MappedItem) => void, onResolveEnd?: (item: MappedItem) => void): Promise<{
324
- root: RootDataWithProps<DefaultRootProps> | RootData<DefaultRootProps>;
325
- content: any[];
326
- zones: Record<string, MappedItem[]>;
327
- }>;
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>>;
200
+
201
+ type HistoryStore<D = any> = {
202
+ index: number;
203
+ hasPast: boolean;
204
+ hasFuture: boolean;
205
+ histories: History<D>[];
206
+ record: (data: D) => void;
207
+ back: VoidFunction;
208
+ forward: VoidFunction;
209
+ currentHistory: History;
210
+ nextHistory: History<D> | null;
211
+ prevHistory: History<D> | null;
212
+ setHistories: (histories: History[]) => void;
213
+ setHistoryIndex: (index: number) => void;
214
+ };
328
215
 
329
216
  declare const usePuck: () => {
330
217
  appState: AppState;
331
- config: Config<Record<string, any>, DefaultRootProps, string>;
218
+ config: Config;
332
219
  dispatch: (action: PuckAction) => void;
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
+ };
333
231
  history: {
334
232
  back: VoidFunction;
335
233
  forward: VoidFunction;
336
- setHistories: (histories: History<any>[]) => void;
234
+ setHistories: (histories: History[]) => void;
337
235
  setHistoryIndex: (index: number) => void;
338
236
  hasPast: boolean;
339
237
  hasFuture: boolean;
340
238
  histories: History<any>[];
341
239
  index: number;
342
- historyStore: HistoryStore<any> | undefined;
240
+ historyStore: HistoryStore | undefined;
343
241
  };
344
- selectedItem: ComponentData<DefaultComponentProps & {
345
- id: string;
346
- }> | null;
242
+ selectedItem: ComponentData<any, string> | null;
347
243
  };
348
244
 
349
- export { AppState, AutoField, AutoFieldPrivate, Button, ComponentData, Config, Data, DefaultComponentProps, DefaultRootProps, Drawer, DropZone, DropZoneProvider, Field, FieldLabel, FieldLabelInternal, FieldProps, FieldPropsInternal, History, IconButton, MappedItem, Plugin, 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 };