@measured/puck 0.16.0-canary.0c7fc83 → 0.16.0-canary.2bef00b

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,8 +1,8 @@
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';
3
- import * as react_jsx_runtime from 'react/jsx-runtime';
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, P as Permissions, V as Viewports, c as DefaultComponentProps, d as DefaultRootProps, M as MappedItem, R as RootData, e as RootDataWithProps, f as ComponentData } from './Config-CkVFT1_w.js';
2
+ export { r as Adaptor, q as ArrayField, m as ArrayState, B as BaseData, n as BaseField, j as ComponentConfig, g as Content, t as CustomField, s as ExternalField, E as ExternalFieldWithAdaptor, u as Fields, l as ItemWithId, N as NumberField, O as ObjectField, h as PuckComponent, i as PuckContext, p as RadioField, k as RootDataWithoutProps, S as SelectField, T as TextField, o as TextareaField } from './Config-CkVFT1_w.js';
4
3
  import * as react from 'react';
5
- import { ReactNode, ReactElement, CSSProperties, SyntheticEvent } from 'react';
4
+ import { ReactNode, ReactElement, SyntheticEvent, CSSProperties } from 'react';
5
+ import * as react_jsx_runtime from 'react/jsx-runtime';
6
6
  import { DragStart, DragUpdate } from '@measured/dnd';
7
7
 
8
8
  type InsertAction = {
@@ -10,6 +10,7 @@ type InsertAction = {
10
10
  componentType: string;
11
11
  destinationIndex: number;
12
12
  destinationZone: string;
13
+ id?: string;
13
14
  };
14
15
  type DuplicateAction = {
15
16
  type: "duplicate";
@@ -64,13 +65,97 @@ type PuckAction = {
64
65
  recordHistory?: boolean;
65
66
  } & (ReorderAction | InsertAction | MoveAction | ReplaceAction | RemoveAction | DuplicateAction | SetAction | SetDataAction | SetUiAction | RegisterZoneAction | UnregisterZoneAction);
66
67
 
68
+ type RenderFunc<Props extends {
69
+ [key: string]: any;
70
+ } = {
71
+ children: ReactNode;
72
+ }> = (props: Props) => ReactElement;
73
+ declare const overrideKeys: readonly ["header", "headerActions", "fields", "fieldLabel", "components", "componentItem", "outline", "puck", "preview"];
74
+ type OverrideKey = (typeof overrideKeys)[number];
75
+ type OverridesGeneric<Shape extends {
76
+ [key in OverrideKey]: any;
77
+ }> = Shape;
78
+ type Overrides = OverridesGeneric<{
79
+ fieldTypes: Partial<FieldRenderFunctions>;
80
+ header: RenderFunc<{
81
+ actions: ReactNode;
82
+ children: ReactNode;
83
+ }>;
84
+ actionBar: RenderFunc<{
85
+ label?: string;
86
+ children: ReactNode;
87
+ }>;
88
+ headerActions: RenderFunc<{
89
+ children: ReactNode;
90
+ }>;
91
+ preview: RenderFunc;
92
+ fields: RenderFunc<{
93
+ children: ReactNode;
94
+ isLoading: boolean;
95
+ itemSelector?: ItemSelector | null;
96
+ }>;
97
+ fieldLabel: RenderFunc<{
98
+ children?: ReactNode;
99
+ icon?: ReactNode;
100
+ label: string;
101
+ el?: "label" | "div";
102
+ readOnly?: boolean;
103
+ className?: string;
104
+ }>;
105
+ components: RenderFunc;
106
+ componentItem: RenderFunc<{
107
+ children: ReactNode;
108
+ name: string;
109
+ }>;
110
+ iframe: RenderFunc<{
111
+ children: ReactNode;
112
+ document?: Document;
113
+ }>;
114
+ outline: RenderFunc;
115
+ puck: RenderFunc;
116
+ }>;
117
+ type FieldRenderFunctions = Omit<{
118
+ [Type in Field["type"]]: React.FunctionComponent<FieldProps<Extract<Field, {
119
+ type: Type;
120
+ }>> & {
121
+ children: ReactNode;
122
+ name: string;
123
+ }>;
124
+ }, "custom"> & {
125
+ [key: string]: React.FunctionComponent<FieldProps<any> & {
126
+ children: ReactNode;
127
+ name: string;
128
+ }>;
129
+ };
130
+
131
+ type Plugin = {
132
+ overrides: Partial<Overrides>;
133
+ };
134
+
135
+ declare const ActionBar: {
136
+ ({ label, children, }: {
137
+ label?: string;
138
+ children?: ReactNode;
139
+ }): react_jsx_runtime.JSX.Element;
140
+ Action: ({ children, label, onClick, }: {
141
+ children: ReactNode;
142
+ label?: string;
143
+ onClick: (e: SyntheticEvent) => void;
144
+ }) => react_jsx_runtime.JSX.Element;
145
+ };
146
+ declare const Action: ({ children, label, onClick, }: {
147
+ children: ReactNode;
148
+ label?: string;
149
+ onClick: (e: SyntheticEvent) => void;
150
+ }) => react_jsx_runtime.JSX.Element;
151
+
67
152
  declare const FieldLabel: ({ children, icon, label, el, readOnly, className, }: {
68
153
  children?: ReactNode;
69
154
  icon?: ReactNode;
70
155
  label: string;
71
- el?: "label" | "div" | undefined;
72
- readOnly?: boolean | undefined;
73
- className?: string | undefined;
156
+ el?: "label" | "div";
157
+ readOnly?: boolean;
158
+ className?: string;
74
159
  }) => react_jsx_runtime.JSX.Element;
75
160
  type FieldLabelPropsInternal = {
76
161
  children?: ReactNode;
@@ -98,37 +183,59 @@ declare function AutoField<ValueType = any, FieldType extends Field<ValueType> =
98
183
 
99
184
  declare const Button: ({ children, href, onClick, variant, type, disabled, tabIndex, newTab, fullWidth, icon, size, loading: loadingProp, }: {
100
185
  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;
186
+ href?: string;
187
+ onClick?: (e: any) => void | Promise<void>;
188
+ variant?: "primary" | "secondary";
189
+ type?: "button" | "submit" | "reset";
190
+ disabled?: boolean;
191
+ tabIndex?: number;
192
+ newTab?: boolean;
193
+ fullWidth?: boolean;
109
194
  icon?: ReactNode;
110
- size?: "medium" | "large" | undefined;
111
- loading?: boolean | undefined;
195
+ size?: "medium" | "large";
196
+ loading?: boolean;
112
197
  }) => react_jsx_runtime.JSX.Element;
113
198
 
114
199
  declare const Drawer: {
115
200
  ({ children, droppableId: _droppableId, direction, }: {
116
201
  children: ReactNode;
117
- droppableId?: string | undefined;
118
- direction?: "vertical" | "horizontal" | undefined;
202
+ droppableId?: string;
203
+ direction?: "vertical" | "horizontal";
119
204
  }): react_jsx_runtime.JSX.Element;
120
- Item: ({ name, children, id, label, index, }: {
205
+ Item: ({ name, children, id, label, index, isDragDisabled, }: {
121
206
  name: string;
122
- children?: ((props: {
207
+ children?: (props: {
123
208
  children: ReactNode;
124
209
  name: string;
125
- }) => ReactElement) | undefined;
126
- id?: string | undefined;
127
- label?: string | undefined;
210
+ }) => ReactElement;
211
+ id?: string;
212
+ label?: string;
128
213
  index: number;
214
+ isDragDisabled?: boolean;
129
215
  }) => react_jsx_runtime.JSX.Element;
130
216
  };
131
217
 
218
+ type History<D = any> = {
219
+ id: string;
220
+ data: D;
221
+ };
222
+ type HistoryStore<D = any> = {
223
+ index: number;
224
+ hasPast: boolean;
225
+ hasFuture: boolean;
226
+ histories: History<D>[];
227
+ record: (data: D) => void;
228
+ back: VoidFunction;
229
+ forward: VoidFunction;
230
+ currentHistory: History;
231
+ nextHistory: History<D> | null;
232
+ prevHistory: History<D> | null;
233
+ setHistories: (histories: History[]) => void;
234
+ setHistoryIndex: (index: number) => void;
235
+ };
236
+
237
+ type OnAction = (action: PuckAction, appState: AppState, prevAppState: AppState) => void;
238
+
132
239
  type PathData = Record<string, {
133
240
  path: string[];
134
241
  label: string;
@@ -160,7 +267,7 @@ type DropZoneContext<UserConfig extends Config = Config> = {
160
267
  zoneWillDrag?: string;
161
268
  setZoneWillDrag?: (zone: string) => void;
162
269
  } | null;
163
- declare const dropZoneContext: react.Context<DropZoneContext<Config<Record<string, any>, DefaultRootProps, string>>>;
270
+ declare const dropZoneContext: react.Context<DropZoneContext<Config>>;
164
271
  declare const DropZoneProvider: ({ children, value, }: {
165
272
  children: ReactNode;
166
273
  value: DropZoneContext;
@@ -170,104 +277,30 @@ declare function DropZone(props: DropZoneProps): react_jsx_runtime.JSX.Element;
170
277
 
171
278
  declare const IconButton: ({ children, href, onClick, variant, type, disabled, tabIndex, newTab, fullWidth, title, }: {
172
279
  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;
280
+ href?: string;
281
+ onClick?: (e: SyntheticEvent) => void | Promise<void>;
282
+ variant?: "primary" | "secondary";
283
+ type?: "button" | "submit" | "reset";
284
+ disabled?: boolean;
285
+ tabIndex?: number;
286
+ newTab?: boolean;
287
+ fullWidth?: boolean;
181
288
  title: string;
182
289
  }) => react_jsx_runtime.JSX.Element;
183
290
 
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
291
  type IframeConfig = {
261
292
  enabled?: boolean;
262
293
  };
263
294
 
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, }: {
295
+ declare function Puck<UserConfig extends Config = Config>({ children, config, data: initialData, ui: initialUi, onChange, onPublish, onAction, permissions, plugins, overrides, renderHeader, renderHeaderActions, headerTitle, headerPath, viewports, iframe, dnd, initialHistory, }: {
265
296
  children?: ReactNode;
266
297
  config: UserConfig;
267
298
  data: Partial<Data>;
268
299
  ui?: Partial<UiState>;
269
300
  onChange?: (data: Data) => void;
270
301
  onPublish?: (data: Data) => void;
302
+ onAction?: OnAction;
303
+ permissions?: Partial<Permissions>;
271
304
  plugins?: Plugin[];
272
305
  overrides?: Partial<Overrides>;
273
306
  renderHeader?: (props: {
@@ -286,7 +319,7 @@ declare function Puck<UserConfig extends Config = Config>({ children, config, da
286
319
  dnd?: {
287
320
  disableAutoScroll?: boolean;
288
321
  };
289
- initialHistories?: {
322
+ initialHistory?: {
290
323
  histories: History<any>[];
291
324
  index: number;
292
325
  };
@@ -296,7 +329,7 @@ declare namespace Puck {
296
329
  var Fields: () => react_jsx_runtime.JSX.Element;
297
330
  var Outline: () => react_jsx_runtime.JSX.Element;
298
331
  var Preview: ({ id }: {
299
- id?: string | undefined;
332
+ id?: string;
300
333
  }) => react_jsx_runtime.JSX.Element;
301
334
  }
302
335
 
@@ -319,25 +352,40 @@ type PropTransform<Props extends DefaultComponentProps = DefaultComponentProps,
319
352
  declare function transformProps<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultComponentProps = DefaultComponentProps>(data: Partial<Data>, propTransforms: PropTransform<Props, RootProps>): Data;
320
353
 
321
354
  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[];
355
+ root: RootData<DefaultRootProps> | RootDataWithProps;
356
+ content: any;
324
357
  zones: Record<string, MappedItem[]>;
325
358
  }>;
326
359
 
327
- type PuckHistory = {
328
- back: VoidFunction;
329
- forward: VoidFunction;
330
- historyStore: HistoryStore;
331
- };
332
-
333
360
  declare const usePuck: () => {
334
361
  appState: AppState;
335
- config: Config<Record<string, any>, DefaultRootProps, string>;
362
+ config: Config;
336
363
  dispatch: (action: PuckAction) => void;
337
- history: Partial<PuckHistory>;
364
+ getPermissions: ({ item, type, }?: {
365
+ item?: ComponentData;
366
+ type?: keyof DefaultComponentProps;
367
+ }) => {
368
+ [x: string]: boolean | undefined;
369
+ drag?: boolean | undefined;
370
+ duplicate?: boolean | undefined;
371
+ delete?: boolean | undefined;
372
+ edit?: boolean | undefined;
373
+ insert?: boolean | undefined;
374
+ };
375
+ history: {
376
+ back: VoidFunction;
377
+ forward: VoidFunction;
378
+ setHistories: (histories: History[]) => void;
379
+ setHistoryIndex: (index: number) => void;
380
+ hasPast: boolean;
381
+ hasFuture: boolean;
382
+ histories: History<any>[];
383
+ index: number;
384
+ historyStore: HistoryStore | undefined;
385
+ };
338
386
  selectedItem: ComponentData<DefaultComponentProps & {
339
387
  id: string;
340
388
  }> | null;
341
389
  };
342
390
 
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 };
391
+ export { Action, ActionBar, AppState, AutoField, AutoFieldPrivate, Button, ComponentData, Config, Data, DefaultComponentProps, DefaultRootProps, Drawer, DropZone, DropZoneProvider, Field, FieldLabel, FieldLabelInternal, FieldProps, type FieldPropsInternal, type History, IconButton, MappedItem, Permissions, type Plugin, Puck, type PuckAction, Render, RootData, RootDataWithProps, UiState, dropZoneContext, migrate, resolveAllData, transformProps, usePuck };