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

Sign up to get free protection for your applications and to get access to all the features.
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,93 @@ 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
+ outline: RenderFunc;
111
+ puck: RenderFunc;
112
+ }>;
113
+ type FieldRenderFunctions = Omit<{
114
+ [Type in Field["type"]]: React.FunctionComponent<FieldProps<Extract<Field, {
115
+ type: Type;
116
+ }>> & {
117
+ children: ReactNode;
118
+ name: string;
119
+ }>;
120
+ }, "custom"> & {
121
+ [key: string]: React.FunctionComponent<FieldProps<any> & {
122
+ children: ReactNode;
123
+ name: string;
124
+ }>;
125
+ };
126
+
127
+ type Plugin = {
128
+ overrides: Partial<Overrides>;
129
+ };
130
+
131
+ declare const ActionBar: {
132
+ ({ label, children, }: {
133
+ label?: string;
134
+ children?: ReactNode;
135
+ }): react_jsx_runtime.JSX.Element;
136
+ Action: ({ children, label, onClick, }: {
137
+ children: ReactNode;
138
+ label?: string;
139
+ onClick: (e: SyntheticEvent) => void;
140
+ }) => react_jsx_runtime.JSX.Element;
141
+ };
142
+ declare const Action: ({ children, label, onClick, }: {
143
+ children: ReactNode;
144
+ label?: string;
145
+ onClick: (e: SyntheticEvent) => void;
146
+ }) => react_jsx_runtime.JSX.Element;
147
+
67
148
  declare const FieldLabel: ({ children, icon, label, el, readOnly, className, }: {
68
149
  children?: ReactNode;
69
150
  icon?: ReactNode;
70
151
  label: string;
71
- el?: "label" | "div" | undefined;
72
- readOnly?: boolean | undefined;
73
- className?: string | undefined;
152
+ el?: "label" | "div";
153
+ readOnly?: boolean;
154
+ className?: string;
74
155
  }) => react_jsx_runtime.JSX.Element;
75
156
  type FieldLabelPropsInternal = {
76
157
  children?: ReactNode;
@@ -98,37 +179,59 @@ declare function AutoField<ValueType = any, FieldType extends Field<ValueType> =
98
179
 
99
180
  declare const Button: ({ children, href, onClick, variant, type, disabled, tabIndex, newTab, fullWidth, icon, size, loading: loadingProp, }: {
100
181
  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;
182
+ href?: string;
183
+ onClick?: (e: any) => void | Promise<void>;
184
+ variant?: "primary" | "secondary";
185
+ type?: "button" | "submit" | "reset";
186
+ disabled?: boolean;
187
+ tabIndex?: number;
188
+ newTab?: boolean;
189
+ fullWidth?: boolean;
109
190
  icon?: ReactNode;
110
- size?: "medium" | "large" | undefined;
111
- loading?: boolean | undefined;
191
+ size?: "medium" | "large";
192
+ loading?: boolean;
112
193
  }) => react_jsx_runtime.JSX.Element;
113
194
 
114
195
  declare const Drawer: {
115
196
  ({ children, droppableId: _droppableId, direction, }: {
116
197
  children: ReactNode;
117
- droppableId?: string | undefined;
118
- direction?: "vertical" | "horizontal" | undefined;
198
+ droppableId?: string;
199
+ direction?: "vertical" | "horizontal";
119
200
  }): react_jsx_runtime.JSX.Element;
120
- Item: ({ name, children, id, label, index, }: {
201
+ Item: ({ name, children, id, label, index, isDragDisabled, }: {
121
202
  name: string;
122
- children?: ((props: {
203
+ children?: (props: {
123
204
  children: ReactNode;
124
205
  name: string;
125
- }) => ReactElement) | undefined;
126
- id?: string | undefined;
127
- label?: string | undefined;
206
+ }) => ReactElement;
207
+ id?: string;
208
+ label?: string;
128
209
  index: number;
210
+ isDragDisabled?: boolean;
129
211
  }) => react_jsx_runtime.JSX.Element;
130
212
  };
131
213
 
214
+ type History<D = any> = {
215
+ id: string;
216
+ data: D;
217
+ };
218
+ type HistoryStore<D = any> = {
219
+ index: number;
220
+ hasPast: boolean;
221
+ hasFuture: boolean;
222
+ histories: History<D>[];
223
+ record: (data: D) => void;
224
+ back: VoidFunction;
225
+ forward: VoidFunction;
226
+ currentHistory: History;
227
+ nextHistory: History<D> | null;
228
+ prevHistory: History<D> | null;
229
+ setHistories: (histories: History[]) => void;
230
+ setHistoryIndex: (index: number) => void;
231
+ };
232
+
233
+ type OnAction = (action: PuckAction, appState: AppState, prevAppState: AppState) => void;
234
+
132
235
  type PathData = Record<string, {
133
236
  path: string[];
134
237
  label: string;
@@ -160,7 +263,7 @@ type DropZoneContext<UserConfig extends Config = Config> = {
160
263
  zoneWillDrag?: string;
161
264
  setZoneWillDrag?: (zone: string) => void;
162
265
  } | null;
163
- declare const dropZoneContext: react.Context<DropZoneContext<Config<Record<string, any>, DefaultRootProps, string>>>;
266
+ declare const dropZoneContext: react.Context<DropZoneContext<Config>>;
164
267
  declare const DropZoneProvider: ({ children, value, }: {
165
268
  children: ReactNode;
166
269
  value: DropZoneContext;
@@ -170,104 +273,30 @@ declare function DropZone(props: DropZoneProps): react_jsx_runtime.JSX.Element;
170
273
 
171
274
  declare const IconButton: ({ children, href, onClick, variant, type, disabled, tabIndex, newTab, fullWidth, title, }: {
172
275
  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;
276
+ href?: string;
277
+ onClick?: (e: SyntheticEvent) => void | Promise<void>;
278
+ variant?: "primary" | "secondary";
279
+ type?: "button" | "submit" | "reset";
280
+ disabled?: boolean;
281
+ tabIndex?: number;
282
+ newTab?: boolean;
283
+ fullWidth?: boolean;
181
284
  title: string;
182
285
  }) => react_jsx_runtime.JSX.Element;
183
286
 
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
287
  type IframeConfig = {
261
288
  enabled?: boolean;
262
289
  };
263
290
 
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, }: {
291
+ 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
292
  children?: ReactNode;
266
293
  config: UserConfig;
267
294
  data: Partial<Data>;
268
295
  ui?: Partial<UiState>;
269
296
  onChange?: (data: Data) => void;
270
297
  onPublish?: (data: Data) => void;
298
+ onAction?: OnAction;
299
+ permissions?: Partial<Permissions>;
271
300
  plugins?: Plugin[];
272
301
  overrides?: Partial<Overrides>;
273
302
  renderHeader?: (props: {
@@ -286,7 +315,7 @@ declare function Puck<UserConfig extends Config = Config>({ children, config, da
286
315
  dnd?: {
287
316
  disableAutoScroll?: boolean;
288
317
  };
289
- initialHistories?: {
318
+ initialHistory?: {
290
319
  histories: History<any>[];
291
320
  index: number;
292
321
  };
@@ -296,7 +325,7 @@ declare namespace Puck {
296
325
  var Fields: () => react_jsx_runtime.JSX.Element;
297
326
  var Outline: () => react_jsx_runtime.JSX.Element;
298
327
  var Preview: ({ id }: {
299
- id?: string | undefined;
328
+ id?: string;
300
329
  }) => react_jsx_runtime.JSX.Element;
301
330
  }
302
331
 
@@ -319,25 +348,40 @@ type PropTransform<Props extends DefaultComponentProps = DefaultComponentProps,
319
348
  declare function transformProps<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultComponentProps = DefaultComponentProps>(data: Partial<Data>, propTransforms: PropTransform<Props, RootProps>): Data;
320
349
 
321
350
  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[];
351
+ root: RootData<DefaultRootProps> | RootDataWithProps;
352
+ content: any;
324
353
  zones: Record<string, MappedItem[]>;
325
354
  }>;
326
355
 
327
- type PuckHistory = {
328
- back: VoidFunction;
329
- forward: VoidFunction;
330
- historyStore: HistoryStore;
331
- };
332
-
333
356
  declare const usePuck: () => {
334
357
  appState: AppState;
335
- config: Config<Record<string, any>, DefaultRootProps, string>;
358
+ config: Config;
336
359
  dispatch: (action: PuckAction) => void;
337
- history: Partial<PuckHistory>;
360
+ getPermissions: ({ item, type, }?: {
361
+ item?: ComponentData;
362
+ type?: keyof DefaultComponentProps;
363
+ }) => {
364
+ [x: string]: boolean | undefined;
365
+ drag?: boolean | undefined;
366
+ duplicate?: boolean | undefined;
367
+ delete?: boolean | undefined;
368
+ edit?: boolean | undefined;
369
+ insert?: boolean | undefined;
370
+ };
371
+ history: {
372
+ back: VoidFunction;
373
+ forward: VoidFunction;
374
+ setHistories: (histories: History[]) => void;
375
+ setHistoryIndex: (index: number) => void;
376
+ hasPast: boolean;
377
+ hasFuture: boolean;
378
+ histories: History<any>[];
379
+ index: number;
380
+ historyStore: HistoryStore | undefined;
381
+ };
338
382
  selectedItem: ComponentData<DefaultComponentProps & {
339
383
  id: string;
340
384
  }> | null;
341
385
  };
342
386
 
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 };
387
+ 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 };