@measured/puck 0.19.0-canary.85ee736 → 0.19.0-canary.8d459e4e

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.
@@ -1,4 +1,4 @@
1
- import { CSSProperties, ReactElement, JSX, ReactNode } from 'react';
1
+ import { CSSProperties, ReactElement, ReactNode, JSX } from 'react';
2
2
 
3
3
  type ItemSelector = {
4
4
  index: number;
@@ -22,6 +22,8 @@ type FieldOption = {
22
22
  type FieldOptions = Array<FieldOption> | ReadonlyArray<FieldOption>;
23
23
  type BaseField = {
24
24
  label?: string;
25
+ labelIcon?: ReactElement;
26
+ metadata?: Metadata;
25
27
  };
26
28
  type TextField = BaseField & {
27
29
  type: "text";
@@ -108,16 +110,22 @@ type ExternalField<Props extends {
108
110
  filterFields?: Record<string, Field>;
109
111
  initialFilters?: Record<string, any>;
110
112
  };
111
- type CustomField<Props extends any = {}> = BaseField & {
113
+ type CustomFieldRender<Value extends any> = (props: {
114
+ field: CustomField<Value>;
115
+ name: string;
116
+ id: string;
117
+ value: Value;
118
+ onChange: (value: Value) => void;
119
+ readOnly?: boolean;
120
+ }) => ReactElement;
121
+ type CustomField<Value extends any> = BaseField & {
112
122
  type: "custom";
113
- render: (props: {
114
- field: CustomField<Props>;
115
- name: string;
116
- id: string;
117
- value: Props;
118
- onChange: (value: Props) => void;
119
- readOnly?: boolean;
120
- }) => ReactElement;
123
+ render: CustomFieldRender<Value>;
124
+ };
125
+ type SlotField = BaseField & {
126
+ type: "slot";
127
+ allow?: string[];
128
+ disallow?: string[];
121
129
  };
122
130
  type Field<Props extends any = any> = TextField | NumberField | TextareaField | SelectField | RadioField | ArrayField<Props extends {
123
131
  [key: string]: any;
@@ -127,7 +135,7 @@ type Field<Props extends any = any> = TextField | NumberField | TextareaField |
127
135
  [key: string]: any;
128
136
  } ? Props : any> | ExternalFieldWithAdaptor<Props extends {
129
137
  [key: string]: any;
130
- } ? Props : any> | CustomField<Props>;
138
+ } ? Props : any> | CustomField<Props> | SlotField;
131
139
  type Fields<ComponentProps extends DefaultComponentProps = DefaultComponentProps> = {
132
140
  [PropName in keyof Omit<ComponentProps, "editMode">]: Field<ComponentProps[PropName]>;
133
141
  };
@@ -139,7 +147,10 @@ type FieldProps<F = Field<any>, ValueType = any> = {
139
147
  readOnly?: boolean;
140
148
  };
141
149
 
142
- type PuckComponent<Props> = (props: WithId<WithPuckProps<Props>>) => JSX.Element;
150
+ type PuckComponent<Props> = (props: WithId<WithPuckProps<{
151
+ [PropName in keyof Props]: Props[PropName] extends Slot ? (props?: Omit<DropZoneProps, "zone">) => ReactNode : Props[PropName];
152
+ }>>) => JSX.Element;
153
+ type ResolveDataTrigger = "insert" | "replace" | "load" | "force";
143
154
  type ComponentConfig<RenderProps extends DefaultComponentProps = DefaultComponentProps, FieldProps extends DefaultComponentProps = RenderProps, DataShape = Omit<ComponentData<FieldProps>, "type">> = {
144
155
  render: PuckComponent<RenderProps>;
145
156
  label?: string;
@@ -148,7 +159,9 @@ type ComponentConfig<RenderProps extends DefaultComponentProps = DefaultComponen
148
159
  permissions?: Partial<Permissions>;
149
160
  inline?: boolean;
150
161
  resolveFields?: (data: DataShape, params: {
151
- changed: Partial<Record<keyof FieldProps, boolean>>;
162
+ changed: Partial<Record<keyof FieldProps, boolean> & {
163
+ id: string;
164
+ }>;
152
165
  fields: Fields<FieldProps>;
153
166
  lastFields: Fields<FieldProps>;
154
167
  lastData: DataShape | null;
@@ -156,9 +169,12 @@ type ComponentConfig<RenderProps extends DefaultComponentProps = DefaultComponen
156
169
  parent: ComponentData | null;
157
170
  }) => Promise<Fields<FieldProps>> | Fields<FieldProps>;
158
171
  resolveData?: (data: DataShape, params: {
159
- changed: Partial<Record<keyof FieldProps, boolean>>;
172
+ changed: Partial<Record<keyof FieldProps, boolean> & {
173
+ id: string;
174
+ }>;
160
175
  lastData: DataShape | null;
161
176
  metadata: Metadata;
177
+ trigger: ResolveDataTrigger;
162
178
  }) => Promise<{
163
179
  props?: Partial<FieldProps>;
164
180
  readOnly?: Partial<Record<keyof FieldProps, boolean>>;
@@ -167,13 +183,17 @@ type ComponentConfig<RenderProps extends DefaultComponentProps = DefaultComponen
167
183
  readOnly?: Partial<Record<keyof FieldProps, boolean>>;
168
184
  };
169
185
  resolvePermissions?: (data: DataShape, params: {
170
- changed: Partial<Record<keyof FieldProps, boolean>>;
186
+ changed: Partial<Record<keyof FieldProps, boolean> & {
187
+ id: string;
188
+ }>;
171
189
  lastPermissions: Partial<Permissions>;
172
190
  permissions: Partial<Permissions>;
173
191
  appState: AppState;
174
192
  lastData: DataShape | null;
175
193
  }) => Promise<Partial<Permissions>> | Partial<Permissions>;
194
+ metadata?: Metadata;
176
195
  };
196
+ type RootConfig<RootProps extends DefaultComponentProps = any> = Partial<ComponentConfig<WithChildren<RootProps>, AsFieldProps<RootProps>, RootData<AsFieldProps<RootProps>>>>;
177
197
  type Category<ComponentName> = {
178
198
  components?: ComponentName[];
179
199
  title?: string;
@@ -187,7 +207,7 @@ type Config<Props extends DefaultComponentProps = DefaultComponentProps, RootPro
187
207
  components: {
188
208
  [ComponentName in keyof Props]: Omit<ComponentConfig<Props[ComponentName], Props[ComponentName]>, "type">;
189
209
  };
190
- root?: Partial<ComponentConfig<WithChildren<RootProps>, AsFieldProps<RootProps>, RootData<AsFieldProps<RootProps>>>>;
210
+ root?: RootConfig<RootProps>;
191
211
  };
192
212
 
193
213
  type WithId<Props> = Props & {
@@ -203,7 +223,7 @@ type WithChildren<Props> = Props & {
203
223
  };
204
224
  type ExtractPropsFromConfig<UserConfig> = UserConfig extends Config<infer P, any, any> ? P : never;
205
225
  type ExtractRootPropsFromConfig<UserConfig> = UserConfig extends Config<any, infer P, any> ? P : never;
206
- type UserGenerics<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>, UserAppState extends AppState<UserData> = AppState<UserData>, UserComponentData extends ComponentData = UserData["content"][0]> = {
226
+ type UserGenerics<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>, UserAppState extends PrivateAppState<UserData> = PrivateAppState<UserData>, UserComponentData extends ComponentData = UserData["content"][0]> = {
207
227
  UserConfig: UserConfig;
208
228
  UserProps: UserProps;
209
229
  UserRootProps: UserRootProps;
@@ -299,6 +319,27 @@ type AppState<UserData extends Data = Data> = {
299
319
  ui: UiState;
300
320
  };
301
321
 
322
+ type ZoneType = "root" | "dropzone" | "slot";
323
+ type PuckNodeData = {
324
+ data: ComponentData;
325
+ flatData: ComponentData;
326
+ parentId: string | null;
327
+ zone: string;
328
+ path: string[];
329
+ };
330
+ type PuckZoneData = {
331
+ contentIds: string[];
332
+ type: ZoneType;
333
+ };
334
+ type NodeIndex = Record<string, PuckNodeData>;
335
+ type ZoneIndex = Record<string, PuckZoneData>;
336
+ type PrivateAppState<UserData extends Data = Data> = AppState<UserData> & {
337
+ indexes: {
338
+ nodes: NodeIndex;
339
+ zones: ZoneIndex;
340
+ };
341
+ };
342
+
302
343
  type RenderFunc<Props extends {
303
344
  [key: string]: any;
304
345
  } = {
@@ -405,6 +446,7 @@ type InitialHistoryNoAppend<AS = Partial<AppState>> = {
405
446
  appendData?: false;
406
447
  };
407
448
  type InitialHistory<AS = Partial<AppState>> = InitialHistoryAppend<AS> | InitialHistoryNoAppend<AS>;
449
+ type Slot = Content;
408
450
 
409
451
  type InsertAction = {
410
452
  type: "insert";
@@ -418,11 +460,17 @@ type DuplicateAction = {
418
460
  sourceIndex: number;
419
461
  sourceZone: string;
420
462
  };
421
- type ReplaceAction = {
463
+ type ReplaceAction<UserData extends Data = Data> = {
422
464
  type: "replace";
423
465
  destinationIndex: number;
424
466
  destinationZone: string;
425
- data: any;
467
+ data: ComponentData;
468
+ ui?: Partial<AppState<UserData>["ui"]>;
469
+ };
470
+ type ReplaceRootAction<UserData extends Data = Data> = {
471
+ type: "replaceRoot";
472
+ root: RootData;
473
+ ui?: Partial<AppState<UserData>["ui"]>;
426
474
  };
427
475
  type ReorderAction = {
428
476
  type: "reorder";
@@ -452,7 +500,7 @@ type SetDataAction = {
452
500
  };
453
501
  type SetAction<UserData extends Data = Data> = {
454
502
  type: "set";
455
- state: Partial<AppState<UserData>> | ((previous: AppState<UserData>) => Partial<AppState<UserData>>);
503
+ state: Partial<PrivateAppState<UserData>> | ((previous: PrivateAppState<UserData>) => Partial<PrivateAppState<UserData>>);
456
504
  };
457
505
  type RegisterZoneAction = {
458
506
  type: "registerZone";
@@ -464,8 +512,19 @@ type UnregisterZoneAction = {
464
512
  };
465
513
  type PuckAction = {
466
514
  recordHistory?: boolean;
467
- } & (ReorderAction | InsertAction | MoveAction | ReplaceAction | RemoveAction | DuplicateAction | SetAction | SetDataAction | SetUiAction | RegisterZoneAction | UnregisterZoneAction);
515
+ } & (ReorderAction | InsertAction | MoveAction | ReplaceAction | ReplaceRootAction | RemoveAction | DuplicateAction | SetAction | SetDataAction | SetUiAction | RegisterZoneAction | UnregisterZoneAction);
516
+
517
+ type PropTransform<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultComponentProps = DefaultRootFieldProps> = Partial<{
518
+ [ComponentName in keyof Props]: (props: Props[ComponentName] & {
519
+ [key: string]: any;
520
+ }) => Props[ComponentName];
521
+ } & {
522
+ root: (props: RootProps & {
523
+ [key: string]: any;
524
+ }) => RootProps;
525
+ }>;
526
+ declare function transformProps<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultComponentProps = DefaultRootFieldProps>(data: Partial<Data>, propTransforms: PropTransform<Props, RootProps>): Data;
468
527
 
469
528
  declare function resolveAllData<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends Record<string, any> = DefaultRootFieldProps>(data: Partial<Data>, config: Config, metadata?: Metadata, onResolveStart?: (item: ComponentData) => void, onResolveEnd?: (item: ComponentData) => void): Promise<Data<Props, RootProps>>;
470
529
 
471
- export { type DefaultRootProps as $, type AppState as A, type BaseData as B, type Config as C, type DropZoneProps as D, type BaseField as E, type FieldProps as F, type TextareaField as G, type History as H, type IframeConfig as I, type RadioField as J, type ArrayField as K, type ObjectField as L, type Metadata as M, type NumberField as N, type OnAction as O, type Permissions as P, type Adaptor as Q, type RootDataWithProps as R, type SelectField as S, type TextField as T, type UserGenerics as U, type Viewports as V, type ExternalFieldWithAdaptor as W, type ExternalField as X, type CustomField as Y, type PuckContext as Z, type DefaultRootRenderProps as _, type Field as a, type WithId as a0, type WithPuckProps as a1, type AsFieldProps as a2, type WithChildren as a3, type ExtractPropsFromConfig as a4, type ExtractRootPropsFromConfig as a5, resolveAllData as a6, type Data as b, type UiState as c, type Plugin as d, type Overrides as e, type PuckAction as f, type InitialHistory as g, type DefaultComponentProps as h, type DefaultRootFieldProps as i, type ComponentData as j, type Fields as k, type ComponentConfig as l, type Direction as m, type DragAxis as n, type Viewport as o, overrideKeys as p, type OverrideKey as q, type FieldRenderFunctions as r, type ItemWithId as s, type ArrayState as t, type PuckComponent as u, type RootDataWithoutProps as v, type RootData as w, type MappedItem as x, type ComponentDataMap as y, type Content as z };
530
+ export { type CustomField as $, type AppState as A, type BaseData as B, type ComponentData as C, type DropZoneProps as D, type ComponentDataMap as E, type Fields as F, type BaseField as G, type History as H, type IframeConfig as I, type TextareaField as J, type SelectField as K, type RadioField as L, type Metadata as M, type NumberField as N, type Overrides as O, type Permissions as P, type ArrayField as Q, type RootDataWithProps as R, type Slot as S, type TextField as T, type UserGenerics as U, type Viewports as V, type ObjectField as W, type Adaptor as X, type ExternalFieldWithAdaptor as Y, type ExternalField as Z, type CustomFieldRender as _, type Config as a, type SlotField as a0, type PuckContext as a1, type DefaultRootFieldProps as a2, type DefaultRootRenderProps as a3, type DefaultRootProps as a4, type DefaultComponentProps as a5, type WithId as a6, type WithPuckProps as a7, type AsFieldProps as a8, type WithChildren as a9, type ExtractPropsFromConfig as aa, type ExtractRootPropsFromConfig as ab, transformProps as ac, resolveAllData as ad, type PuckAction as b, type ResolveDataTrigger as c, type Plugin as d, type UiState as e, type ComponentConfig as f, type Field as g, type FieldProps as h, type Data as i, type OnAction as j, type InitialHistory as k, type RootData as l, type Content as m, type ItemSelector as n, type Direction as o, type DragAxis as p, type Viewport as q, overrideKeys as r, type OverrideKey as s, type FieldRenderFunctions as t, type ItemWithId as u, type ArrayState as v, type PuckComponent as w, type RootConfig as x, type RootDataWithoutProps as y, type MappedItem as z };
@@ -1,4 +1,4 @@
1
- import { CSSProperties, ReactElement, JSX, ReactNode } from 'react';
1
+ import { CSSProperties, ReactElement, ReactNode, JSX } from 'react';
2
2
 
3
3
  type ItemSelector = {
4
4
  index: number;
@@ -22,6 +22,8 @@ type FieldOption = {
22
22
  type FieldOptions = Array<FieldOption> | ReadonlyArray<FieldOption>;
23
23
  type BaseField = {
24
24
  label?: string;
25
+ labelIcon?: ReactElement;
26
+ metadata?: Metadata;
25
27
  };
26
28
  type TextField = BaseField & {
27
29
  type: "text";
@@ -108,16 +110,22 @@ type ExternalField<Props extends {
108
110
  filterFields?: Record<string, Field>;
109
111
  initialFilters?: Record<string, any>;
110
112
  };
111
- type CustomField<Props extends any = {}> = BaseField & {
113
+ type CustomFieldRender<Value extends any> = (props: {
114
+ field: CustomField<Value>;
115
+ name: string;
116
+ id: string;
117
+ value: Value;
118
+ onChange: (value: Value) => void;
119
+ readOnly?: boolean;
120
+ }) => ReactElement;
121
+ type CustomField<Value extends any> = BaseField & {
112
122
  type: "custom";
113
- render: (props: {
114
- field: CustomField<Props>;
115
- name: string;
116
- id: string;
117
- value: Props;
118
- onChange: (value: Props) => void;
119
- readOnly?: boolean;
120
- }) => ReactElement;
123
+ render: CustomFieldRender<Value>;
124
+ };
125
+ type SlotField = BaseField & {
126
+ type: "slot";
127
+ allow?: string[];
128
+ disallow?: string[];
121
129
  };
122
130
  type Field<Props extends any = any> = TextField | NumberField | TextareaField | SelectField | RadioField | ArrayField<Props extends {
123
131
  [key: string]: any;
@@ -127,7 +135,7 @@ type Field<Props extends any = any> = TextField | NumberField | TextareaField |
127
135
  [key: string]: any;
128
136
  } ? Props : any> | ExternalFieldWithAdaptor<Props extends {
129
137
  [key: string]: any;
130
- } ? Props : any> | CustomField<Props>;
138
+ } ? Props : any> | CustomField<Props> | SlotField;
131
139
  type Fields<ComponentProps extends DefaultComponentProps = DefaultComponentProps> = {
132
140
  [PropName in keyof Omit<ComponentProps, "editMode">]: Field<ComponentProps[PropName]>;
133
141
  };
@@ -139,7 +147,10 @@ type FieldProps<F = Field<any>, ValueType = any> = {
139
147
  readOnly?: boolean;
140
148
  };
141
149
 
142
- type PuckComponent<Props> = (props: WithId<WithPuckProps<Props>>) => JSX.Element;
150
+ type PuckComponent<Props> = (props: WithId<WithPuckProps<{
151
+ [PropName in keyof Props]: Props[PropName] extends Slot ? (props?: Omit<DropZoneProps, "zone">) => ReactNode : Props[PropName];
152
+ }>>) => JSX.Element;
153
+ type ResolveDataTrigger = "insert" | "replace" | "load" | "force";
143
154
  type ComponentConfig<RenderProps extends DefaultComponentProps = DefaultComponentProps, FieldProps extends DefaultComponentProps = RenderProps, DataShape = Omit<ComponentData<FieldProps>, "type">> = {
144
155
  render: PuckComponent<RenderProps>;
145
156
  label?: string;
@@ -148,7 +159,9 @@ type ComponentConfig<RenderProps extends DefaultComponentProps = DefaultComponen
148
159
  permissions?: Partial<Permissions>;
149
160
  inline?: boolean;
150
161
  resolveFields?: (data: DataShape, params: {
151
- changed: Partial<Record<keyof FieldProps, boolean>>;
162
+ changed: Partial<Record<keyof FieldProps, boolean> & {
163
+ id: string;
164
+ }>;
152
165
  fields: Fields<FieldProps>;
153
166
  lastFields: Fields<FieldProps>;
154
167
  lastData: DataShape | null;
@@ -156,9 +169,12 @@ type ComponentConfig<RenderProps extends DefaultComponentProps = DefaultComponen
156
169
  parent: ComponentData | null;
157
170
  }) => Promise<Fields<FieldProps>> | Fields<FieldProps>;
158
171
  resolveData?: (data: DataShape, params: {
159
- changed: Partial<Record<keyof FieldProps, boolean>>;
172
+ changed: Partial<Record<keyof FieldProps, boolean> & {
173
+ id: string;
174
+ }>;
160
175
  lastData: DataShape | null;
161
176
  metadata: Metadata;
177
+ trigger: ResolveDataTrigger;
162
178
  }) => Promise<{
163
179
  props?: Partial<FieldProps>;
164
180
  readOnly?: Partial<Record<keyof FieldProps, boolean>>;
@@ -167,13 +183,17 @@ type ComponentConfig<RenderProps extends DefaultComponentProps = DefaultComponen
167
183
  readOnly?: Partial<Record<keyof FieldProps, boolean>>;
168
184
  };
169
185
  resolvePermissions?: (data: DataShape, params: {
170
- changed: Partial<Record<keyof FieldProps, boolean>>;
186
+ changed: Partial<Record<keyof FieldProps, boolean> & {
187
+ id: string;
188
+ }>;
171
189
  lastPermissions: Partial<Permissions>;
172
190
  permissions: Partial<Permissions>;
173
191
  appState: AppState;
174
192
  lastData: DataShape | null;
175
193
  }) => Promise<Partial<Permissions>> | Partial<Permissions>;
194
+ metadata?: Metadata;
176
195
  };
196
+ type RootConfig<RootProps extends DefaultComponentProps = any> = Partial<ComponentConfig<WithChildren<RootProps>, AsFieldProps<RootProps>, RootData<AsFieldProps<RootProps>>>>;
177
197
  type Category<ComponentName> = {
178
198
  components?: ComponentName[];
179
199
  title?: string;
@@ -187,7 +207,7 @@ type Config<Props extends DefaultComponentProps = DefaultComponentProps, RootPro
187
207
  components: {
188
208
  [ComponentName in keyof Props]: Omit<ComponentConfig<Props[ComponentName], Props[ComponentName]>, "type">;
189
209
  };
190
- root?: Partial<ComponentConfig<WithChildren<RootProps>, AsFieldProps<RootProps>, RootData<AsFieldProps<RootProps>>>>;
210
+ root?: RootConfig<RootProps>;
191
211
  };
192
212
 
193
213
  type WithId<Props> = Props & {
@@ -203,7 +223,7 @@ type WithChildren<Props> = Props & {
203
223
  };
204
224
  type ExtractPropsFromConfig<UserConfig> = UserConfig extends Config<infer P, any, any> ? P : never;
205
225
  type ExtractRootPropsFromConfig<UserConfig> = UserConfig extends Config<any, infer P, any> ? P : never;
206
- type UserGenerics<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>, UserAppState extends AppState<UserData> = AppState<UserData>, UserComponentData extends ComponentData = UserData["content"][0]> = {
226
+ type UserGenerics<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>, UserAppState extends PrivateAppState<UserData> = PrivateAppState<UserData>, UserComponentData extends ComponentData = UserData["content"][0]> = {
207
227
  UserConfig: UserConfig;
208
228
  UserProps: UserProps;
209
229
  UserRootProps: UserRootProps;
@@ -299,6 +319,27 @@ type AppState<UserData extends Data = Data> = {
299
319
  ui: UiState;
300
320
  };
301
321
 
322
+ type ZoneType = "root" | "dropzone" | "slot";
323
+ type PuckNodeData = {
324
+ data: ComponentData;
325
+ flatData: ComponentData;
326
+ parentId: string | null;
327
+ zone: string;
328
+ path: string[];
329
+ };
330
+ type PuckZoneData = {
331
+ contentIds: string[];
332
+ type: ZoneType;
333
+ };
334
+ type NodeIndex = Record<string, PuckNodeData>;
335
+ type ZoneIndex = Record<string, PuckZoneData>;
336
+ type PrivateAppState<UserData extends Data = Data> = AppState<UserData> & {
337
+ indexes: {
338
+ nodes: NodeIndex;
339
+ zones: ZoneIndex;
340
+ };
341
+ };
342
+
302
343
  type RenderFunc<Props extends {
303
344
  [key: string]: any;
304
345
  } = {
@@ -405,6 +446,7 @@ type InitialHistoryNoAppend<AS = Partial<AppState>> = {
405
446
  appendData?: false;
406
447
  };
407
448
  type InitialHistory<AS = Partial<AppState>> = InitialHistoryAppend<AS> | InitialHistoryNoAppend<AS>;
449
+ type Slot = Content;
408
450
 
409
451
  type InsertAction = {
410
452
  type: "insert";
@@ -418,11 +460,17 @@ type DuplicateAction = {
418
460
  sourceIndex: number;
419
461
  sourceZone: string;
420
462
  };
421
- type ReplaceAction = {
463
+ type ReplaceAction<UserData extends Data = Data> = {
422
464
  type: "replace";
423
465
  destinationIndex: number;
424
466
  destinationZone: string;
425
- data: any;
467
+ data: ComponentData;
468
+ ui?: Partial<AppState<UserData>["ui"]>;
469
+ };
470
+ type ReplaceRootAction<UserData extends Data = Data> = {
471
+ type: "replaceRoot";
472
+ root: RootData;
473
+ ui?: Partial<AppState<UserData>["ui"]>;
426
474
  };
427
475
  type ReorderAction = {
428
476
  type: "reorder";
@@ -452,7 +500,7 @@ type SetDataAction = {
452
500
  };
453
501
  type SetAction<UserData extends Data = Data> = {
454
502
  type: "set";
455
- state: Partial<AppState<UserData>> | ((previous: AppState<UserData>) => Partial<AppState<UserData>>);
503
+ state: Partial<PrivateAppState<UserData>> | ((previous: PrivateAppState<UserData>) => Partial<PrivateAppState<UserData>>);
456
504
  };
457
505
  type RegisterZoneAction = {
458
506
  type: "registerZone";
@@ -464,8 +512,19 @@ type UnregisterZoneAction = {
464
512
  };
465
513
  type PuckAction = {
466
514
  recordHistory?: boolean;
467
- } & (ReorderAction | InsertAction | MoveAction | ReplaceAction | RemoveAction | DuplicateAction | SetAction | SetDataAction | SetUiAction | RegisterZoneAction | UnregisterZoneAction);
515
+ } & (ReorderAction | InsertAction | MoveAction | ReplaceAction | ReplaceRootAction | RemoveAction | DuplicateAction | SetAction | SetDataAction | SetUiAction | RegisterZoneAction | UnregisterZoneAction);
516
+
517
+ type PropTransform<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultComponentProps = DefaultRootFieldProps> = Partial<{
518
+ [ComponentName in keyof Props]: (props: Props[ComponentName] & {
519
+ [key: string]: any;
520
+ }) => Props[ComponentName];
521
+ } & {
522
+ root: (props: RootProps & {
523
+ [key: string]: any;
524
+ }) => RootProps;
525
+ }>;
526
+ declare function transformProps<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultComponentProps = DefaultRootFieldProps>(data: Partial<Data>, propTransforms: PropTransform<Props, RootProps>): Data;
468
527
 
469
528
  declare function resolveAllData<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends Record<string, any> = DefaultRootFieldProps>(data: Partial<Data>, config: Config, metadata?: Metadata, onResolveStart?: (item: ComponentData) => void, onResolveEnd?: (item: ComponentData) => void): Promise<Data<Props, RootProps>>;
470
529
 
471
- export { type DefaultRootProps as $, type AppState as A, type BaseData as B, type Config as C, type DropZoneProps as D, type BaseField as E, type FieldProps as F, type TextareaField as G, type History as H, type IframeConfig as I, type RadioField as J, type ArrayField as K, type ObjectField as L, type Metadata as M, type NumberField as N, type OnAction as O, type Permissions as P, type Adaptor as Q, type RootDataWithProps as R, type SelectField as S, type TextField as T, type UserGenerics as U, type Viewports as V, type ExternalFieldWithAdaptor as W, type ExternalField as X, type CustomField as Y, type PuckContext as Z, type DefaultRootRenderProps as _, type Field as a, type WithId as a0, type WithPuckProps as a1, type AsFieldProps as a2, type WithChildren as a3, type ExtractPropsFromConfig as a4, type ExtractRootPropsFromConfig as a5, resolveAllData as a6, type Data as b, type UiState as c, type Plugin as d, type Overrides as e, type PuckAction as f, type InitialHistory as g, type DefaultComponentProps as h, type DefaultRootFieldProps as i, type ComponentData as j, type Fields as k, type ComponentConfig as l, type Direction as m, type DragAxis as n, type Viewport as o, overrideKeys as p, type OverrideKey as q, type FieldRenderFunctions as r, type ItemWithId as s, type ArrayState as t, type PuckComponent as u, type RootDataWithoutProps as v, type RootData as w, type MappedItem as x, type ComponentDataMap as y, type Content as z };
530
+ export { type CustomField as $, type AppState as A, type BaseData as B, type ComponentData as C, type DropZoneProps as D, type ComponentDataMap as E, type Fields as F, type BaseField as G, type History as H, type IframeConfig as I, type TextareaField as J, type SelectField as K, type RadioField as L, type Metadata as M, type NumberField as N, type Overrides as O, type Permissions as P, type ArrayField as Q, type RootDataWithProps as R, type Slot as S, type TextField as T, type UserGenerics as U, type Viewports as V, type ObjectField as W, type Adaptor as X, type ExternalFieldWithAdaptor as Y, type ExternalField as Z, type CustomFieldRender as _, type Config as a, type SlotField as a0, type PuckContext as a1, type DefaultRootFieldProps as a2, type DefaultRootRenderProps as a3, type DefaultRootProps as a4, type DefaultComponentProps as a5, type WithId as a6, type WithPuckProps as a7, type AsFieldProps as a8, type WithChildren as a9, type ExtractPropsFromConfig as aa, type ExtractRootPropsFromConfig as ab, transformProps as ac, resolveAllData as ad, type PuckAction as b, type ResolveDataTrigger as c, type Plugin as d, type UiState as e, type ComponentConfig as f, type Field as g, type FieldProps as h, type Data as i, type OnAction as j, type InitialHistory as k, type RootData as l, type Content as m, type ItemSelector as n, type Direction as o, type DragAxis as p, type Viewport as q, overrideKeys as r, type OverrideKey as s, type FieldRenderFunctions as t, type ItemWithId as u, type ArrayState as v, type PuckComponent as w, type RootConfig as x, type RootDataWithoutProps as y, type MappedItem as z };
package/dist/rsc.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { C as Config, U as UserGenerics, M as Metadata } from './resolve-all-data-wwgDuTnC.mjs';
3
- export { a6 as resolveAllData } from './resolve-all-data-wwgDuTnC.mjs';
2
+ import { a as Config, U as UserGenerics, M as Metadata } from './resolve-all-data-DtB0OZRl.mjs';
3
+ export { ad as resolveAllData, ac as transformProps } from './resolve-all-data-DtB0OZRl.mjs';
4
4
  import 'react';
5
5
 
6
6
  declare function Render<UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>>({ config, data, metadata, }: {
package/dist/rsc.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { C as Config, U as UserGenerics, M as Metadata } from './resolve-all-data-wwgDuTnC.js';
3
- export { a6 as resolveAllData } from './resolve-all-data-wwgDuTnC.js';
2
+ import { a as Config, U as UserGenerics, M as Metadata } from './resolve-all-data-DtB0OZRl.js';
3
+ export { ad as resolveAllData, ac as transformProps } from './resolve-all-data-DtB0OZRl.js';
4
4
  import 'react';
5
5
 
6
6
  declare function Render<UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>>({ config, data, metadata, }: {