@measured/puck 0.16.0-canary.ef2e5ec → 0.16.0-canary.f761e5f

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/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 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';
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,37 +56,57 @@ 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
 
91
+ type History<D = any> = {
92
+ id: string;
93
+ data: D;
94
+ };
95
+ type HistoryStore<D = any> = {
96
+ index: number;
97
+ hasPast: boolean;
98
+ hasFuture: boolean;
99
+ histories: History<D>[];
100
+ record: (data: D) => void;
101
+ back: VoidFunction;
102
+ forward: VoidFunction;
103
+ currentHistory: History;
104
+ nextHistory: History<D> | null;
105
+ prevHistory: History<D> | null;
106
+ setHistories: (histories: History[]) => void;
107
+ setHistoryIndex: (index: number) => void;
108
+ };
109
+
132
110
  type PathData = Record<string, {
133
111
  path: string[];
134
112
  label: string;
@@ -160,7 +138,7 @@ type DropZoneContext<UserConfig extends Config = Config> = {
160
138
  zoneWillDrag?: string;
161
139
  setZoneWillDrag?: (zone: string) => void;
162
140
  } | null;
163
- declare const dropZoneContext: react.Context<DropZoneContext<Config<Record<string, any>, DefaultRootProps, string>>>;
141
+ declare const dropZoneContext: react.Context<DropZoneContext<Config>>;
164
142
  declare const DropZoneProvider: ({ children, value, }: {
165
143
  children: ReactNode;
166
144
  value: DropZoneContext;
@@ -170,113 +148,35 @@ declare function DropZone(props: DropZoneProps): react_jsx_runtime.JSX.Element;
170
148
 
171
149
  declare const IconButton: ({ children, href, onClick, variant, type, disabled, tabIndex, newTab, fullWidth, title, }: {
172
150
  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;
151
+ href?: string;
152
+ onClick?: (e: SyntheticEvent) => void | Promise<void>;
153
+ variant?: "primary" | "secondary";
154
+ type?: "button" | "submit" | "reset";
155
+ disabled?: boolean;
156
+ tabIndex?: number;
157
+ newTab?: boolean;
158
+ fullWidth?: boolean;
181
159
  title: string;
182
160
  }) => react_jsx_runtime.JSX.Element;
183
161
 
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, }: {
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, }: {
265
163
  children?: ReactNode;
266
164
  config: UserConfig;
267
- data: Partial<Data>;
165
+ data: Partial<UserData>;
268
166
  ui?: Partial<UiState>;
269
- onChange?: (data: Data) => void;
270
- onPublish?: (data: Data) => void;
167
+ onChange?: (data: UserData) => void;
168
+ onPublish?: (data: UserData) => void;
169
+ onAction?: OnAction<UserData>;
170
+ permissions?: Partial<Permissions>;
271
171
  plugins?: Plugin[];
272
172
  overrides?: Partial<Overrides>;
273
173
  renderHeader?: (props: {
274
174
  children: ReactNode;
275
175
  dispatch: (action: PuckAction) => void;
276
- state: AppState;
176
+ state: AppState<UserData>;
277
177
  }) => ReactElement;
278
178
  renderHeaderActions?: (props: {
279
- state: AppState;
179
+ state: AppState<UserData>;
280
180
  dispatch: (action: PuckAction) => void;
281
181
  }) => ReactElement;
282
182
  headerTitle?: string;
@@ -286,7 +186,7 @@ declare function Puck<UserConfig extends Config = Config>({ children, config, da
286
186
  dnd?: {
287
187
  disableAutoScroll?: boolean;
288
188
  };
289
- initialHistories?: {
189
+ initialHistory?: {
290
190
  histories: History<any>[];
291
191
  index: number;
292
192
  };
@@ -296,18 +196,18 @@ declare namespace Puck {
296
196
  var Fields: () => react_jsx_runtime.JSX.Element;
297
197
  var Outline: () => react_jsx_runtime.JSX.Element;
298
198
  var Preview: ({ id }: {
299
- id?: string | undefined;
199
+ id?: string;
300
200
  }) => react_jsx_runtime.JSX.Element;
301
201
  }
302
202
 
303
- 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 }: {
304
204
  config: UserConfig;
305
- data: Partial<Data>;
205
+ data: Partial<UserData>;
306
206
  }): react_jsx_runtime.JSX.Element;
307
207
 
308
208
  declare function migrate(data: Data): Data;
309
209
 
310
- type PropTransform<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultRootProps = DefaultRootProps> = Partial<{
210
+ type PropTransform<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultComponentProps = DefaultRootFieldProps> = Partial<{
311
211
  [ComponentName in keyof Props]: (props: Props[ComponentName] & {
312
212
  [key: string]: any;
313
213
  }) => Props[ComponentName];
@@ -316,28 +216,37 @@ type PropTransform<Props extends DefaultComponentProps = DefaultComponentProps,
316
216
  [key: string]: any;
317
217
  }) => RootProps;
318
218
  }>;
319
- declare function transformProps<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultComponentProps = DefaultComponentProps>(data: Partial<Data>, propTransforms: PropTransform<Props, RootProps>): Data;
320
-
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
- }>;
219
+ declare function transformProps<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultComponentProps = DefaultRootFieldProps>(data: Partial<Data>, propTransforms: PropTransform<Props, RootProps>): Data;
326
220
 
327
- type PuckHistory = {
328
- back: VoidFunction;
329
- forward: VoidFunction;
330
- historyStore: HistoryStore;
331
- };
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>>;
332
222
 
333
223
  declare const usePuck: () => {
334
224
  appState: AppState;
335
- config: Config<Record<string, any>, DefaultRootProps, string>;
225
+ config: Config;
336
226
  dispatch: (action: PuckAction) => void;
337
- history: Partial<PuckHistory>;
338
- selectedItem: ComponentData<DefaultComponentProps & {
339
- id: string;
340
- }> | null;
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
+ };
238
+ history: {
239
+ back: VoidFunction;
240
+ forward: VoidFunction;
241
+ setHistories: (histories: History[]) => void;
242
+ setHistoryIndex: (index: number) => void;
243
+ hasPast: boolean;
244
+ hasFuture: boolean;
245
+ histories: History<any>[];
246
+ index: number;
247
+ historyStore: HistoryStore | undefined;
248
+ };
249
+ selectedItem: ComponentData<any, string> | null;
341
250
  };
342
251
 
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 };
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 };