@measured/puck 0.15.1-canary.fb9aa4e → 0.16.0-canary.2c52d27

Sign up to get free protection for your applications and to get access to all the features.
@@ -68,7 +68,7 @@ type ObjectField<Props extends {
68
68
  [key: string]: any;
69
69
  }> = BaseField & {
70
70
  type: "object";
71
- objectFields: {
71
+ objectFields: Props extends any[] ? never : {
72
72
  [SubPropName in keyof Props]: Field<Props[SubPropName]>;
73
73
  };
74
74
  };
@@ -259,4 +259,4 @@ type AppState = {
259
259
  ui: UiState;
260
260
  };
261
261
 
262
- export { AppState as A, BaseData as B, Config as C, Data as D, ExternalFieldWithAdaptor as E, Field as F, ItemSelector as I, MappedItem as M, NumberField as N, ObjectField as O, PuckComponent as P, RootDataWithProps as R, SelectField as S, TextField as T, UiState as U, Viewports as V, FieldProps as a, DefaultRootProps as b, DropZoneProps as c, DefaultComponentProps as d, RootData as e, ComponentData as f, Content as g, PuckContext as h, ComponentConfig as i, RootDataWithoutProps as j, ItemWithId as k, ArrayState as l, BaseField as m, TextareaField as n, RadioField as o, ArrayField as p, Adaptor as q, ExternalField as r, CustomField as s, Fields as t };
262
+ export type { AppState as A, BaseData as B, Config as C, Data as D, ExternalFieldWithAdaptor as E, Field as F, ItemSelector as I, MappedItem as M, NumberField as N, ObjectField as O, PuckComponent as P, RootData as R, SelectField as S, TextField as T, UiState as U, Viewports as V, FieldProps as a, DropZoneProps as b, DefaultComponentProps as c, DefaultRootProps as d, RootDataWithProps as e, ComponentData as f, Content as g, PuckContext as h, ComponentConfig as i, RootDataWithoutProps as j, ItemWithId as k, ArrayState as l, BaseField as m, TextareaField as n, RadioField as o, ArrayField as p, Adaptor as q, ExternalField as r, CustomField as s, Fields as t };
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, 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';
4
3
  import * as react from 'react';
5
4
  import { ReactNode, ReactElement, CSSProperties, SyntheticEvent } 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 = {
@@ -64,13 +64,72 @@ type PuckAction = {
64
64
  recordHistory?: boolean;
65
65
  } & (ReorderAction | InsertAction | MoveAction | ReplaceAction | RemoveAction | DuplicateAction | SetAction | SetDataAction | SetUiAction | RegisterZoneAction | UnregisterZoneAction);
66
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<{
93
+ 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> & {
117
+ children: ReactNode;
118
+ name: string;
119
+ }>;
120
+ };
121
+
122
+ type Plugin = {
123
+ overrides: Partial<Overrides>;
124
+ };
125
+
67
126
  declare const FieldLabel: ({ children, icon, label, el, readOnly, className, }: {
68
127
  children?: ReactNode;
69
128
  icon?: ReactNode;
70
129
  label: string;
71
- el?: "label" | "div" | undefined;
72
- readOnly?: boolean | undefined;
73
- className?: string | undefined;
130
+ el?: "label" | "div";
131
+ readOnly?: boolean;
132
+ className?: string;
74
133
  }) => react_jsx_runtime.JSX.Element;
75
134
  type FieldLabelPropsInternal = {
76
135
  children?: ReactNode;
@@ -98,37 +157,58 @@ declare function AutoField<ValueType = any, FieldType extends Field<ValueType> =
98
157
 
99
158
  declare const Button: ({ children, href, onClick, variant, type, disabled, tabIndex, newTab, fullWidth, icon, size, loading: loadingProp, }: {
100
159
  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;
160
+ href?: string;
161
+ onClick?: (e: any) => void | Promise<void>;
162
+ variant?: "primary" | "secondary";
163
+ type?: "button" | "submit" | "reset";
164
+ disabled?: boolean;
165
+ tabIndex?: number;
166
+ newTab?: boolean;
167
+ fullWidth?: boolean;
109
168
  icon?: ReactNode;
110
- size?: "medium" | "large" | undefined;
111
- loading?: boolean | undefined;
169
+ size?: "medium" | "large";
170
+ loading?: boolean;
112
171
  }) => react_jsx_runtime.JSX.Element;
113
172
 
114
173
  declare const Drawer: {
115
174
  ({ children, droppableId: _droppableId, direction, }: {
116
175
  children: ReactNode;
117
- droppableId?: string | undefined;
118
- direction?: "vertical" | "horizontal" | undefined;
176
+ droppableId?: string;
177
+ direction?: "vertical" | "horizontal";
119
178
  }): react_jsx_runtime.JSX.Element;
120
179
  Item: ({ name, children, id, label, index, }: {
121
180
  name: string;
122
- children?: ((props: {
181
+ children?: (props: {
123
182
  children: ReactNode;
124
183
  name: string;
125
- }) => ReactElement) | undefined;
126
- id?: string | undefined;
127
- label?: string | undefined;
184
+ }) => ReactElement;
185
+ id?: string;
186
+ label?: string;
128
187
  index: number;
129
188
  }) => react_jsx_runtime.JSX.Element;
130
189
  };
131
190
 
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
+ type OnAction = (action: PuckAction, appState: AppState, prevAppState: AppState) => void;
211
+
132
212
  type PathData = Record<string, {
133
213
  path: string[];
134
214
  label: string;
@@ -160,7 +240,7 @@ type DropZoneContext<UserConfig extends Config = Config> = {
160
240
  zoneWillDrag?: string;
161
241
  setZoneWillDrag?: (zone: string) => void;
162
242
  } | null;
163
- declare const dropZoneContext: react.Context<DropZoneContext<Config<Record<string, any>, DefaultRootProps, string>>>;
243
+ declare const dropZoneContext: react.Context<DropZoneContext<Config>>;
164
244
  declare const DropZoneProvider: ({ children, value, }: {
165
245
  children: ReactNode;
166
246
  value: DropZoneContext;
@@ -170,87 +250,29 @@ declare function DropZone(props: DropZoneProps): react_jsx_runtime.JSX.Element;
170
250
 
171
251
  declare const IconButton: ({ children, href, onClick, variant, type, disabled, tabIndex, newTab, fullWidth, title, }: {
172
252
  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;
253
+ href?: string;
254
+ onClick?: (e: SyntheticEvent) => void | Promise<void>;
255
+ variant?: "primary" | "secondary";
256
+ type?: "button" | "submit" | "reset";
257
+ disabled?: boolean;
258
+ tabIndex?: number;
259
+ newTab?: boolean;
260
+ fullWidth?: boolean;
181
261
  title: string;
182
262
  }) => react_jsx_runtime.JSX.Element;
183
263
 
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
264
  type IframeConfig = {
244
265
  enabled?: boolean;
245
266
  };
246
267
 
247
- declare function Puck<UserConfig extends Config = Config>({ children, config, data: initialData, ui: initialUi, onChange, onPublish, plugins, overrides, renderHeader, renderHeaderActions, headerTitle, headerPath, viewports, iframe, dnd, }: {
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, }: {
248
269
  children?: ReactNode;
249
270
  config: UserConfig;
250
271
  data: Partial<Data>;
251
272
  ui?: Partial<UiState>;
252
273
  onChange?: (data: Data) => void;
253
274
  onPublish?: (data: Data) => void;
275
+ onAction?: OnAction;
254
276
  plugins?: Plugin[];
255
277
  overrides?: Partial<Overrides>;
256
278
  renderHeader?: (props: {
@@ -269,13 +291,17 @@ declare function Puck<UserConfig extends Config = Config>({ children, config, da
269
291
  dnd?: {
270
292
  disableAutoScroll?: boolean;
271
293
  };
294
+ initialHistory?: {
295
+ histories: History<any>[];
296
+ index: number;
297
+ };
272
298
  }): react_jsx_runtime.JSX.Element;
273
299
  declare namespace Puck {
274
300
  var Components: () => react_jsx_runtime.JSX.Element;
275
301
  var Fields: () => react_jsx_runtime.JSX.Element;
276
302
  var Outline: () => react_jsx_runtime.JSX.Element;
277
303
  var Preview: ({ id }: {
278
- id?: string | undefined;
304
+ id?: string;
279
305
  }) => react_jsx_runtime.JSX.Element;
280
306
  }
281
307
 
@@ -298,42 +324,29 @@ type PropTransform<Props extends DefaultComponentProps = DefaultComponentProps,
298
324
  declare function transformProps<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultComponentProps = DefaultComponentProps>(data: Partial<Data>, propTransforms: PropTransform<Props, RootProps>): Data;
299
325
 
300
326
  declare function resolveAllData(data: Partial<Data>, config: Config, onResolveStart?: (item: MappedItem) => void, onResolveEnd?: (item: MappedItem) => void): Promise<{
301
- root: RootDataWithProps<DefaultRootProps> | RootData<DefaultRootProps>;
302
- content: any[];
327
+ root: RootData<DefaultRootProps> | RootDataWithProps;
328
+ content: any;
303
329
  zones: Record<string, MappedItem[]>;
304
330
  }>;
305
331
 
306
- type History<D = any> = {
307
- id: string;
308
- data: D;
309
- };
310
- type HistoryStore<D = any> = {
311
- index: number;
312
- currentHistory: History;
313
- hasPast: boolean;
314
- hasFuture: boolean;
315
- record: (data: D) => void;
316
- back: VoidFunction;
317
- forward: VoidFunction;
318
- nextHistory: History<D> | null;
319
- prevHistory: History<D> | null;
320
- histories: History<D>[];
321
- };
322
-
323
- type PuckHistory = {
324
- back: VoidFunction;
325
- forward: VoidFunction;
326
- historyStore: HistoryStore;
327
- };
328
-
329
332
  declare const usePuck: () => {
330
333
  appState: AppState;
331
- config: Config<Record<string, any>, DefaultRootProps, string>;
334
+ config: Config;
332
335
  dispatch: (action: PuckAction) => void;
333
- history: Partial<PuckHistory>;
336
+ history: {
337
+ back: VoidFunction;
338
+ forward: VoidFunction;
339
+ setHistories: (histories: History[]) => void;
340
+ setHistoryIndex: (index: number) => void;
341
+ hasPast: boolean;
342
+ hasFuture: boolean;
343
+ histories: History<any>[];
344
+ index: number;
345
+ historyStore: HistoryStore | undefined;
346
+ };
334
347
  selectedItem: ComponentData<DefaultComponentProps & {
335
348
  id: string;
336
349
  }> | null;
337
350
  };
338
351
 
339
- 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 };
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 };