@measured/puck 0.19.0-canary.1fc19b5 → 0.19.0-canary.226c08da

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;
@@ -235,22 +255,28 @@ type BaseData<Props extends {
235
255
  readOnly?: Partial<Record<keyof Props, boolean>>;
236
256
  };
237
257
  type RootDataWithProps<Props extends DefaultComponentProps = DefaultRootFieldProps> = BaseData<Props> & {
238
- props: Props;
258
+ props: WithPopulatedSlots<Props>;
239
259
  };
240
260
  type RootDataWithoutProps<Props extends DefaultComponentProps = DefaultRootFieldProps> = Props;
241
261
  type RootData<Props extends DefaultComponentProps = DefaultRootFieldProps> = Partial<RootDataWithProps<AsFieldProps<Props>>> & Partial<RootDataWithoutProps<Props>>;
242
262
  type ComponentData<Props extends DefaultComponentProps = DefaultComponentProps, Name = string> = {
243
263
  type: Name;
244
- props: WithId<Props>;
264
+ props: WithId<WithPopulatedSlots<Props>>;
265
+ } & BaseData<Props>;
266
+ type ComponentDataOptionalId<Props extends DefaultComponentProps = DefaultComponentProps, Name = string> = {
267
+ type: Name;
268
+ props: Props & {
269
+ id?: string;
270
+ };
245
271
  } & BaseData<Props>;
246
272
  type MappedItem = ComponentData;
247
273
  type ComponentDataMap<Props extends Record<string, DefaultComponentProps> = DefaultComponentProps> = {
248
274
  [K in keyof Props]: ComponentData<Props[K], K extends string ? K : never>;
249
275
  }[keyof Props];
250
276
  type Content<PropsMap extends {
251
- [key: string]: any;
277
+ [key: string]: DefaultComponentProps;
252
278
  } = {
253
- [key: string]: any;
279
+ [key: string]: DefaultComponentProps;
254
280
  }> = ComponentDataMap<PropsMap>[];
255
281
  type Data<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultComponentProps = DefaultRootFieldProps> = {
256
282
  root: RootData<RootProps>;
@@ -299,6 +325,30 @@ type AppState<UserData extends Data = Data> = {
299
325
  ui: UiState;
300
326
  };
301
327
 
328
+ type ZoneType = "root" | "dropzone" | "slot";
329
+ type PuckNodeData = {
330
+ data: ComponentData;
331
+ flatData: ComponentData;
332
+ parentId: string | null;
333
+ zone: string;
334
+ path: string[];
335
+ };
336
+ type PuckZoneData = {
337
+ contentIds: string[];
338
+ type: ZoneType;
339
+ };
340
+ type NodeIndex = Record<string, PuckNodeData>;
341
+ type ZoneIndex = Record<string, PuckZoneData>;
342
+ type PrivateAppState<UserData extends Data = Data> = AppState<UserData> & {
343
+ indexes: {
344
+ nodes: NodeIndex;
345
+ zones: ZoneIndex;
346
+ };
347
+ };
348
+ type WithPopulatedSlots<Props extends DefaultComponentProps = DefaultComponentProps, SlotProps extends DefaultComponentProps = Props> = Props extends any ? any : {
349
+ [PropName in keyof Props]: Props[PropName] extends Slot<SlotProps> ? Content<SlotProps> : Props[PropName];
350
+ };
351
+
302
352
  type RenderFunc<Props extends {
303
353
  [key: string]: any;
304
354
  } = {
@@ -405,6 +455,13 @@ type InitialHistoryNoAppend<AS = Partial<AppState>> = {
405
455
  appendData?: false;
406
456
  };
407
457
  type InitialHistory<AS = Partial<AppState>> = InitialHistoryAppend<AS> | InitialHistoryNoAppend<AS>;
458
+ type Slot<Props extends {
459
+ [key: string]: DefaultComponentProps;
460
+ } = {
461
+ [key: string]: DefaultComponentProps;
462
+ }> = {
463
+ [K in keyof Props]: ComponentDataOptionalId<Props[K], K extends string ? K : never>;
464
+ }[keyof Props][];
408
465
 
409
466
  type InsertAction = {
410
467
  type: "insert";
@@ -418,11 +475,17 @@ type DuplicateAction = {
418
475
  sourceIndex: number;
419
476
  sourceZone: string;
420
477
  };
421
- type ReplaceAction = {
478
+ type ReplaceAction<UserData extends Data = Data> = {
422
479
  type: "replace";
423
480
  destinationIndex: number;
424
481
  destinationZone: string;
425
- data: any;
482
+ data: ComponentData;
483
+ ui?: Partial<AppState<UserData>["ui"]>;
484
+ };
485
+ type ReplaceRootAction<UserData extends Data = Data> = {
486
+ type: "replaceRoot";
487
+ root: RootData;
488
+ ui?: Partial<AppState<UserData>["ui"]>;
426
489
  };
427
490
  type ReorderAction = {
428
491
  type: "reorder";
@@ -452,7 +515,7 @@ type SetDataAction = {
452
515
  };
453
516
  type SetAction<UserData extends Data = Data> = {
454
517
  type: "set";
455
- state: Partial<AppState<UserData>> | ((previous: AppState<UserData>) => Partial<AppState<UserData>>);
518
+ state: Partial<PrivateAppState<UserData>> | ((previous: PrivateAppState<UserData>) => Partial<PrivateAppState<UserData>>);
456
519
  };
457
520
  type RegisterZoneAction = {
458
521
  type: "registerZone";
@@ -464,8 +527,25 @@ type UnregisterZoneAction = {
464
527
  };
465
528
  type PuckAction = {
466
529
  recordHistory?: boolean;
467
- } & (ReorderAction | InsertAction | MoveAction | ReplaceAction | RemoveAction | DuplicateAction | SetAction | SetDataAction | SetUiAction | RegisterZoneAction | UnregisterZoneAction);
530
+ } & (ReorderAction | InsertAction | MoveAction | ReplaceAction | ReplaceRootAction | RemoveAction | DuplicateAction | SetAction | SetDataAction | SetUiAction | RegisterZoneAction | UnregisterZoneAction);
531
+
532
+ type PropTransform<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultComponentProps = DefaultRootFieldProps> = Partial<{
533
+ [ComponentName in keyof Props]: (props: Props[ComponentName] & {
534
+ [key: string]: any;
535
+ }) => Props[ComponentName];
536
+ } & {
537
+ root: (props: RootProps & {
538
+ [key: string]: any;
539
+ }) => RootProps;
540
+ }>;
541
+ declare function transformProps<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultComponentProps = DefaultRootFieldProps>(data: Partial<Data>, propTransforms: PropTransform<Props, RootProps>): Data;
468
542
 
469
543
  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
544
 
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 };
545
+ type WalkTreeOptions = {
546
+ parentId: string;
547
+ propName: string;
548
+ };
549
+ declare function walkTree<T extends ComponentData | RootData | G["UserData"], UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>>(data: T, config: UserConfig, callbackFn: (data: Content, options: WalkTreeOptions) => Content | null | void): T;
550
+
551
+ export { type ExternalField as $, type AppState as A, type BaseData as B, type ComponentData as C, type DropZoneProps as D, type MappedItem as E, type Fields as F, type ComponentDataMap as G, type History as H, type IframeConfig as I, type Content as J, type BaseField as K, type TextareaField as L, type Metadata as M, type NumberField as N, type Overrides as O, type Permissions as P, type SelectField as Q, type RootDataWithProps as R, type Slot as S, type TextField as T, type UserGenerics as U, type Viewports as V, type RadioField as W, type ArrayField as X, type ObjectField as Y, type Adaptor as Z, type ExternalFieldWithAdaptor as _, type Config as a, type CustomFieldRender as a0, type CustomField as a1, type SlotField as a2, type PuckContext as a3, type DefaultRootFieldProps as a4, type DefaultRootRenderProps as a5, type DefaultRootProps as a6, type DefaultComponentProps as a7, type WithId as a8, type WithPuckProps as a9, type AsFieldProps as aa, type WithChildren as ab, type ExtractPropsFromConfig as ac, type ExtractRootPropsFromConfig as ad, transformProps as ae, resolveAllData as af, 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 ItemSelector 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 RootConfig as v, walkTree as w, type RootDataWithoutProps as x, type RootData as y, type ComponentDataOptionalId 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;
@@ -235,22 +255,28 @@ type BaseData<Props extends {
235
255
  readOnly?: Partial<Record<keyof Props, boolean>>;
236
256
  };
237
257
  type RootDataWithProps<Props extends DefaultComponentProps = DefaultRootFieldProps> = BaseData<Props> & {
238
- props: Props;
258
+ props: WithPopulatedSlots<Props>;
239
259
  };
240
260
  type RootDataWithoutProps<Props extends DefaultComponentProps = DefaultRootFieldProps> = Props;
241
261
  type RootData<Props extends DefaultComponentProps = DefaultRootFieldProps> = Partial<RootDataWithProps<AsFieldProps<Props>>> & Partial<RootDataWithoutProps<Props>>;
242
262
  type ComponentData<Props extends DefaultComponentProps = DefaultComponentProps, Name = string> = {
243
263
  type: Name;
244
- props: WithId<Props>;
264
+ props: WithId<WithPopulatedSlots<Props>>;
265
+ } & BaseData<Props>;
266
+ type ComponentDataOptionalId<Props extends DefaultComponentProps = DefaultComponentProps, Name = string> = {
267
+ type: Name;
268
+ props: Props & {
269
+ id?: string;
270
+ };
245
271
  } & BaseData<Props>;
246
272
  type MappedItem = ComponentData;
247
273
  type ComponentDataMap<Props extends Record<string, DefaultComponentProps> = DefaultComponentProps> = {
248
274
  [K in keyof Props]: ComponentData<Props[K], K extends string ? K : never>;
249
275
  }[keyof Props];
250
276
  type Content<PropsMap extends {
251
- [key: string]: any;
277
+ [key: string]: DefaultComponentProps;
252
278
  } = {
253
- [key: string]: any;
279
+ [key: string]: DefaultComponentProps;
254
280
  }> = ComponentDataMap<PropsMap>[];
255
281
  type Data<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultComponentProps = DefaultRootFieldProps> = {
256
282
  root: RootData<RootProps>;
@@ -299,6 +325,30 @@ type AppState<UserData extends Data = Data> = {
299
325
  ui: UiState;
300
326
  };
301
327
 
328
+ type ZoneType = "root" | "dropzone" | "slot";
329
+ type PuckNodeData = {
330
+ data: ComponentData;
331
+ flatData: ComponentData;
332
+ parentId: string | null;
333
+ zone: string;
334
+ path: string[];
335
+ };
336
+ type PuckZoneData = {
337
+ contentIds: string[];
338
+ type: ZoneType;
339
+ };
340
+ type NodeIndex = Record<string, PuckNodeData>;
341
+ type ZoneIndex = Record<string, PuckZoneData>;
342
+ type PrivateAppState<UserData extends Data = Data> = AppState<UserData> & {
343
+ indexes: {
344
+ nodes: NodeIndex;
345
+ zones: ZoneIndex;
346
+ };
347
+ };
348
+ type WithPopulatedSlots<Props extends DefaultComponentProps = DefaultComponentProps, SlotProps extends DefaultComponentProps = Props> = Props extends any ? any : {
349
+ [PropName in keyof Props]: Props[PropName] extends Slot<SlotProps> ? Content<SlotProps> : Props[PropName];
350
+ };
351
+
302
352
  type RenderFunc<Props extends {
303
353
  [key: string]: any;
304
354
  } = {
@@ -405,6 +455,13 @@ type InitialHistoryNoAppend<AS = Partial<AppState>> = {
405
455
  appendData?: false;
406
456
  };
407
457
  type InitialHistory<AS = Partial<AppState>> = InitialHistoryAppend<AS> | InitialHistoryNoAppend<AS>;
458
+ type Slot<Props extends {
459
+ [key: string]: DefaultComponentProps;
460
+ } = {
461
+ [key: string]: DefaultComponentProps;
462
+ }> = {
463
+ [K in keyof Props]: ComponentDataOptionalId<Props[K], K extends string ? K : never>;
464
+ }[keyof Props][];
408
465
 
409
466
  type InsertAction = {
410
467
  type: "insert";
@@ -418,11 +475,17 @@ type DuplicateAction = {
418
475
  sourceIndex: number;
419
476
  sourceZone: string;
420
477
  };
421
- type ReplaceAction = {
478
+ type ReplaceAction<UserData extends Data = Data> = {
422
479
  type: "replace";
423
480
  destinationIndex: number;
424
481
  destinationZone: string;
425
- data: any;
482
+ data: ComponentData;
483
+ ui?: Partial<AppState<UserData>["ui"]>;
484
+ };
485
+ type ReplaceRootAction<UserData extends Data = Data> = {
486
+ type: "replaceRoot";
487
+ root: RootData;
488
+ ui?: Partial<AppState<UserData>["ui"]>;
426
489
  };
427
490
  type ReorderAction = {
428
491
  type: "reorder";
@@ -452,7 +515,7 @@ type SetDataAction = {
452
515
  };
453
516
  type SetAction<UserData extends Data = Data> = {
454
517
  type: "set";
455
- state: Partial<AppState<UserData>> | ((previous: AppState<UserData>) => Partial<AppState<UserData>>);
518
+ state: Partial<PrivateAppState<UserData>> | ((previous: PrivateAppState<UserData>) => Partial<PrivateAppState<UserData>>);
456
519
  };
457
520
  type RegisterZoneAction = {
458
521
  type: "registerZone";
@@ -464,8 +527,25 @@ type UnregisterZoneAction = {
464
527
  };
465
528
  type PuckAction = {
466
529
  recordHistory?: boolean;
467
- } & (ReorderAction | InsertAction | MoveAction | ReplaceAction | RemoveAction | DuplicateAction | SetAction | SetDataAction | SetUiAction | RegisterZoneAction | UnregisterZoneAction);
530
+ } & (ReorderAction | InsertAction | MoveAction | ReplaceAction | ReplaceRootAction | RemoveAction | DuplicateAction | SetAction | SetDataAction | SetUiAction | RegisterZoneAction | UnregisterZoneAction);
531
+
532
+ type PropTransform<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultComponentProps = DefaultRootFieldProps> = Partial<{
533
+ [ComponentName in keyof Props]: (props: Props[ComponentName] & {
534
+ [key: string]: any;
535
+ }) => Props[ComponentName];
536
+ } & {
537
+ root: (props: RootProps & {
538
+ [key: string]: any;
539
+ }) => RootProps;
540
+ }>;
541
+ declare function transformProps<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultComponentProps = DefaultRootFieldProps>(data: Partial<Data>, propTransforms: PropTransform<Props, RootProps>): Data;
468
542
 
469
543
  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
544
 
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 };
545
+ type WalkTreeOptions = {
546
+ parentId: string;
547
+ propName: string;
548
+ };
549
+ declare function walkTree<T extends ComponentData | RootData | G["UserData"], UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>>(data: T, config: UserConfig, callbackFn: (data: Content, options: WalkTreeOptions) => Content | null | void): T;
550
+
551
+ export { type ExternalField as $, type AppState as A, type BaseData as B, type ComponentData as C, type DropZoneProps as D, type MappedItem as E, type Fields as F, type ComponentDataMap as G, type History as H, type IframeConfig as I, type Content as J, type BaseField as K, type TextareaField as L, type Metadata as M, type NumberField as N, type Overrides as O, type Permissions as P, type SelectField as Q, type RootDataWithProps as R, type Slot as S, type TextField as T, type UserGenerics as U, type Viewports as V, type RadioField as W, type ArrayField as X, type ObjectField as Y, type Adaptor as Z, type ExternalFieldWithAdaptor as _, type Config as a, type CustomFieldRender as a0, type CustomField as a1, type SlotField as a2, type PuckContext as a3, type DefaultRootFieldProps as a4, type DefaultRootRenderProps as a5, type DefaultRootProps as a6, type DefaultComponentProps as a7, type WithId as a8, type WithPuckProps as a9, type AsFieldProps as aa, type WithChildren as ab, type ExtractPropsFromConfig as ac, type ExtractRootPropsFromConfig as ad, transformProps as ae, resolveAllData as af, 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 ItemSelector 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 RootConfig as v, walkTree as w, type RootDataWithoutProps as x, type RootData as y, type ComponentDataOptionalId as z };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@measured/puck",
3
- "version": "0.19.0-canary.1fc19b5",
4
- "author": "Measured Corporation Ltd <hello@measured.co>",
3
+ "version": "0.19.0-canary.226c08da",
4
+ "author": "Chris Villa <chris@puckeditor.com>",
5
5
  "repository": "measuredco/puck",
6
6
  "bugs": "https://github.com/measuredco/puck/issues",
7
7
  "homepage": "https://puckeditor.com",
@@ -27,7 +27,8 @@
27
27
  "require": "./dist/rsc.js"
28
28
  },
29
29
  "./puck.css": "./dist/index.css",
30
- "./dist/index.css": "./dist/index.css"
30
+ "./dist/index.css": "./dist/index.css",
31
+ "./package.json": "./package.json"
31
32
  },
32
33
  "typesVersions": {
33
34
  "*": {
@@ -68,17 +69,17 @@
68
69
  "typescript": "^5.5.4"
69
70
  },
70
71
  "dependencies": {
71
- "@dnd-kit/helpers": "0.0.7-beta-20250130032138",
72
- "@dnd-kit/react": "0.0.7-beta-20250130032138",
72
+ "@dnd-kit/helpers": "0.1.17",
73
+ "@dnd-kit/react": "0.1.17",
73
74
  "deep-diff": "^1.0.2",
74
75
  "fast-deep-equal": "^3.1.3",
75
76
  "object-hash": "^3.0.0",
76
77
  "react-hotkeys-hook": "^4.6.1",
77
78
  "use-debounce": "^9.0.4",
78
79
  "uuid": "^9.0.1",
79
- "zustand": "^5.0.2"
80
+ "zustand": "^5.0.3"
80
81
  },
81
82
  "peerDependencies": {
82
- "react": "^17.0.0 || ^18.0.0 || ^19.0.0"
83
+ "react": "^18.0.0 || ^19.0.0"
83
84
  }
84
85
  }