@measured/puck 0.16.0-canary.0c7fc83 → 0.16.0-canary.3298831

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 = {
@@ -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,72 @@ 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
+ headerActions: RenderFunc<{
85
+ children: ReactNode;
86
+ }>;
87
+ preview: RenderFunc;
88
+ fields: RenderFunc<{
89
+ children: ReactNode;
90
+ isLoading: boolean;
91
+ itemSelector?: ItemSelector | null;
92
+ }>;
93
+ fieldLabel: RenderFunc<{
94
+ children?: ReactNode;
95
+ icon?: ReactNode;
96
+ label: string;
97
+ el?: "label" | "div";
98
+ readOnly?: boolean;
99
+ className?: string;
100
+ }>;
101
+ components: RenderFunc;
102
+ componentItem: RenderFunc<{
103
+ children: ReactNode;
104
+ name: string;
105
+ }>;
106
+ outline: RenderFunc;
107
+ puck: RenderFunc;
108
+ }>;
109
+ type FieldRenderFunctions = Omit<{
110
+ [Type in Field["type"]]: React.FunctionComponent<FieldProps<Extract<Field, {
111
+ type: Type;
112
+ }>> & {
113
+ children: ReactNode;
114
+ name: string;
115
+ }>;
116
+ }, "custom"> & {
117
+ [key: string]: React.FunctionComponent<FieldProps<any> & {
118
+ children: ReactNode;
119
+ name: string;
120
+ }>;
121
+ };
122
+
123
+ type Plugin = {
124
+ overrides: Partial<Overrides>;
125
+ };
126
+
67
127
  declare const FieldLabel: ({ children, icon, label, el, readOnly, className, }: {
68
128
  children?: ReactNode;
69
129
  icon?: ReactNode;
70
130
  label: string;
71
- el?: "label" | "div" | undefined;
72
- readOnly?: boolean | undefined;
73
- className?: string | undefined;
131
+ el?: "label" | "div";
132
+ readOnly?: boolean;
133
+ className?: string;
74
134
  }) => react_jsx_runtime.JSX.Element;
75
135
  type FieldLabelPropsInternal = {
76
136
  children?: ReactNode;
@@ -98,37 +158,58 @@ declare function AutoField<ValueType = any, FieldType extends Field<ValueType> =
98
158
 
99
159
  declare const Button: ({ children, href, onClick, variant, type, disabled, tabIndex, newTab, fullWidth, icon, size, loading: loadingProp, }: {
100
160
  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;
161
+ href?: string;
162
+ onClick?: (e: any) => void | Promise<void>;
163
+ variant?: "primary" | "secondary";
164
+ type?: "button" | "submit" | "reset";
165
+ disabled?: boolean;
166
+ tabIndex?: number;
167
+ newTab?: boolean;
168
+ fullWidth?: boolean;
109
169
  icon?: ReactNode;
110
- size?: "medium" | "large" | undefined;
111
- loading?: boolean | undefined;
170
+ size?: "medium" | "large";
171
+ loading?: boolean;
112
172
  }) => react_jsx_runtime.JSX.Element;
113
173
 
114
174
  declare const Drawer: {
115
175
  ({ children, droppableId: _droppableId, direction, }: {
116
176
  children: ReactNode;
117
- droppableId?: string | undefined;
118
- direction?: "vertical" | "horizontal" | undefined;
177
+ droppableId?: string;
178
+ direction?: "vertical" | "horizontal";
119
179
  }): react_jsx_runtime.JSX.Element;
120
180
  Item: ({ name, children, id, label, index, }: {
121
181
  name: string;
122
- children?: ((props: {
182
+ children?: (props: {
123
183
  children: ReactNode;
124
184
  name: string;
125
- }) => ReactElement) | undefined;
126
- id?: string | undefined;
127
- label?: string | undefined;
185
+ }) => ReactElement;
186
+ id?: string;
187
+ label?: string;
128
188
  index: number;
129
189
  }) => react_jsx_runtime.JSX.Element;
130
190
  };
131
191
 
192
+ type History<D = any> = {
193
+ id: string;
194
+ data: D;
195
+ };
196
+ type HistoryStore<D = any> = {
197
+ index: number;
198
+ hasPast: boolean;
199
+ hasFuture: boolean;
200
+ histories: History<D>[];
201
+ record: (data: D) => void;
202
+ back: VoidFunction;
203
+ forward: VoidFunction;
204
+ currentHistory: History;
205
+ nextHistory: History<D> | null;
206
+ prevHistory: History<D> | null;
207
+ setHistories: (histories: History[]) => void;
208
+ setHistoryIndex: (index: number) => void;
209
+ };
210
+
211
+ type OnAction = (action: PuckAction, appState: AppState, prevAppState: AppState) => void;
212
+
132
213
  type PathData = Record<string, {
133
214
  path: string[];
134
215
  label: string;
@@ -160,7 +241,7 @@ type DropZoneContext<UserConfig extends Config = Config> = {
160
241
  zoneWillDrag?: string;
161
242
  setZoneWillDrag?: (zone: string) => void;
162
243
  } | null;
163
- declare const dropZoneContext: react.Context<DropZoneContext<Config<Record<string, any>, DefaultRootProps, string>>>;
244
+ declare const dropZoneContext: react.Context<DropZoneContext<Config>>;
164
245
  declare const DropZoneProvider: ({ children, value, }: {
165
246
  children: ReactNode;
166
247
  value: DropZoneContext;
@@ -170,104 +251,29 @@ declare function DropZone(props: DropZoneProps): react_jsx_runtime.JSX.Element;
170
251
 
171
252
  declare const IconButton: ({ children, href, onClick, variant, type, disabled, tabIndex, newTab, fullWidth, title, }: {
172
253
  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;
254
+ href?: string;
255
+ onClick?: (e: SyntheticEvent) => void | Promise<void>;
256
+ variant?: "primary" | "secondary";
257
+ type?: "button" | "submit" | "reset";
258
+ disabled?: boolean;
259
+ tabIndex?: number;
260
+ newTab?: boolean;
261
+ fullWidth?: boolean;
181
262
  title: string;
182
263
  }) => react_jsx_runtime.JSX.Element;
183
264
 
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
265
  type IframeConfig = {
261
266
  enabled?: boolean;
262
267
  };
263
268
 
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, }: {
269
+ 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, }: {
265
270
  children?: ReactNode;
266
271
  config: UserConfig;
267
272
  data: Partial<Data>;
268
273
  ui?: Partial<UiState>;
269
274
  onChange?: (data: Data) => void;
270
275
  onPublish?: (data: Data) => void;
276
+ onAction?: OnAction;
271
277
  plugins?: Plugin[];
272
278
  overrides?: Partial<Overrides>;
273
279
  renderHeader?: (props: {
@@ -286,7 +292,7 @@ declare function Puck<UserConfig extends Config = Config>({ children, config, da
286
292
  dnd?: {
287
293
  disableAutoScroll?: boolean;
288
294
  };
289
- initialHistories?: {
295
+ initialHistory?: {
290
296
  histories: History<any>[];
291
297
  index: number;
292
298
  };
@@ -296,7 +302,7 @@ declare namespace Puck {
296
302
  var Fields: () => react_jsx_runtime.JSX.Element;
297
303
  var Outline: () => react_jsx_runtime.JSX.Element;
298
304
  var Preview: ({ id }: {
299
- id?: string | undefined;
305
+ id?: string;
300
306
  }) => react_jsx_runtime.JSX.Element;
301
307
  }
302
308
 
@@ -319,25 +325,29 @@ type PropTransform<Props extends DefaultComponentProps = DefaultComponentProps,
319
325
  declare function transformProps<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultComponentProps = DefaultComponentProps>(data: Partial<Data>, propTransforms: PropTransform<Props, RootProps>): Data;
320
326
 
321
327
  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[];
328
+ root: RootData<DefaultRootProps> | RootDataWithProps;
329
+ content: any;
324
330
  zones: Record<string, MappedItem[]>;
325
331
  }>;
326
332
 
327
- type PuckHistory = {
328
- back: VoidFunction;
329
- forward: VoidFunction;
330
- historyStore: HistoryStore;
331
- };
332
-
333
333
  declare const usePuck: () => {
334
334
  appState: AppState;
335
- config: Config<Record<string, any>, DefaultRootProps, string>;
335
+ config: Config;
336
336
  dispatch: (action: PuckAction) => void;
337
- history: Partial<PuckHistory>;
337
+ history: {
338
+ back: VoidFunction;
339
+ forward: VoidFunction;
340
+ setHistories: (histories: History[]) => void;
341
+ setHistoryIndex: (index: number) => void;
342
+ hasPast: boolean;
343
+ hasFuture: boolean;
344
+ histories: History<any>[];
345
+ index: number;
346
+ historyStore: HistoryStore | undefined;
347
+ };
338
348
  selectedItem: ComponentData<DefaultComponentProps & {
339
349
  id: string;
340
350
  }> | null;
341
351
  };
342
352
 
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 };
353
+ 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 };