@measured/puck 0.21.0-canary.b818cb1f → 0.21.0-canary.c0db75c1

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 { ReactElement, CSSProperties, ReactNode, JSX } from 'react';
1
+ import { ReactElement, ReactNode, CSSProperties, ElementType, JSX } from 'react';
2
2
 
3
3
  type ItemSelector = {
4
4
  index: number;
@@ -10,63 +10,63 @@ type FieldOption = {
10
10
  value: string | number | boolean | undefined | null | object;
11
11
  };
12
12
  type FieldOptions = Array<FieldOption> | ReadonlyArray<FieldOption>;
13
- type BaseField = {
13
+ interface BaseField {
14
14
  label?: string;
15
15
  labelIcon?: ReactElement;
16
- metadata?: Metadata;
16
+ metadata?: FieldMetadata;
17
17
  visible?: boolean;
18
- };
19
- type TextField = BaseField & {
18
+ }
19
+ interface TextField extends BaseField {
20
20
  type: "text";
21
21
  placeholder?: string;
22
22
  contentEditable?: boolean;
23
- };
24
- type NumberField = BaseField & {
23
+ }
24
+ interface NumberField extends BaseField {
25
25
  type: "number";
26
26
  placeholder?: string;
27
27
  min?: number;
28
28
  max?: number;
29
29
  step?: number;
30
- };
31
- type TextareaField = BaseField & {
30
+ }
31
+ interface TextareaField extends BaseField {
32
32
  type: "textarea";
33
33
  placeholder?: string;
34
34
  contentEditable?: boolean;
35
- };
36
- type SelectField = BaseField & {
35
+ }
36
+ interface SelectField extends BaseField {
37
37
  type: "select";
38
38
  options: FieldOptions;
39
- };
40
- type RadioField = BaseField & {
39
+ }
40
+ interface RadioField extends BaseField {
41
41
  type: "radio";
42
42
  options: FieldOptions;
43
- };
44
- type ArrayField<Props extends {
43
+ }
44
+ interface ArrayField<Props extends {
45
45
  [key: string]: any;
46
46
  }[] = {
47
47
  [key: string]: any;
48
- }[], UserField extends {} = {}> = BaseField & {
48
+ }[], UserField extends {} = {}> extends BaseField {
49
49
  type: "array";
50
50
  arrayFields: {
51
51
  [SubPropName in keyof Props[0]]: UserField extends {
52
52
  type: PropertyKey;
53
53
  } ? Field<Props[0][SubPropName], UserField> | UserField : Field<Props[0][SubPropName], UserField>;
54
54
  };
55
- defaultItemProps?: Props[0];
56
- getItemSummary?: (item: Props[0], index?: number) => string;
55
+ defaultItemProps?: Props[0] | ((index: number) => Props[0]);
56
+ getItemSummary?: (item: Props[0], index?: number) => ReactNode;
57
57
  max?: number;
58
58
  min?: number;
59
- };
60
- type ObjectField<Props extends any = {
59
+ }
60
+ interface ObjectField<Props extends any = {
61
61
  [key: string]: any;
62
- }, UserField extends {} = {}> = BaseField & {
62
+ }, UserField extends {} = {}> extends BaseField {
63
63
  type: "object";
64
64
  objectFields: {
65
65
  [SubPropName in keyof Props]: UserField extends {
66
66
  type: PropertyKey;
67
67
  } ? Field<Props[SubPropName]> | UserField : Field<Props[SubPropName]>;
68
68
  };
69
- };
69
+ }
70
70
  type Adaptor<AdaptorParams = {}, TableShape extends Record<string, any> = {}, PropShape = TableShape> = {
71
71
  name: string;
72
72
  fetchList: (adaptorParams?: AdaptorParams) => Promise<TableShape[] | null>;
@@ -80,14 +80,14 @@ type ExternalFieldWithAdaptor<Props extends any = {
80
80
  placeholder?: string;
81
81
  adaptor: Adaptor<any, any, Props>;
82
82
  adaptorParams?: object;
83
- getItemSummary: (item: NotUndefined<Props>, index?: number) => string;
83
+ getItemSummary: (item: NotUndefined<Props>, index?: number) => ReactNode;
84
84
  };
85
85
  type CacheOpts = {
86
86
  enabled?: boolean;
87
87
  };
88
- type ExternalField<Props extends any = {
88
+ interface ExternalField<Props extends any = {
89
89
  [key: string]: any;
90
- }> = BaseField & {
90
+ }> extends BaseField {
91
91
  type: "external";
92
92
  cache?: CacheOpts;
93
93
  placeholder?: string;
@@ -97,7 +97,7 @@ type ExternalField<Props extends any = {
97
97
  }) => Promise<any[] | null>;
98
98
  mapProp?: (value: any) => Props;
99
99
  mapRow?: (value: any) => Record<string, string | number | ReactElement>;
100
- getItemSummary?: (item: NotUndefined<Props>, index?: number) => string;
100
+ getItemSummary?: (item: NotUndefined<Props>, index?: number) => ReactNode;
101
101
  showSearch?: boolean;
102
102
  renderFooter?: (props: {
103
103
  items: any[];
@@ -105,7 +105,7 @@ type ExternalField<Props extends any = {
105
105
  initialQuery?: string;
106
106
  filterFields?: Record<string, Field>;
107
107
  initialFilters?: Record<string, any>;
108
- };
108
+ }
109
109
  type CustomFieldRender<Value extends any> = (props: {
110
110
  field: CustomField<Value>;
111
111
  name: string;
@@ -114,16 +114,17 @@ type CustomFieldRender<Value extends any> = (props: {
114
114
  onChange: (value: Value) => void;
115
115
  readOnly?: boolean;
116
116
  }) => ReactElement;
117
- type CustomField<Value extends any> = BaseField & {
117
+ interface CustomField<Value extends any> extends BaseField {
118
118
  type: "custom";
119
119
  render: CustomFieldRender<Value>;
120
120
  contentEditable?: boolean;
121
- };
122
- type SlotField = BaseField & {
121
+ key?: string;
122
+ }
123
+ interface SlotField extends BaseField {
123
124
  type: "slot";
124
125
  allow?: string[];
125
126
  disallow?: string[];
126
- };
127
+ }
127
128
  type Field<ValueType = any, UserField extends {} = {}> = TextField | NumberField | TextareaField | SelectField | RadioField | ArrayField<ValueType extends {
128
129
  [key: string]: any;
129
130
  }[] ? ValueType : never, UserField> | ObjectField<ValueType, UserField> | ExternalField<ValueType> | ExternalFieldWithAdaptor<ValueType> | CustomField<ValueType> | SlotField;
@@ -145,13 +146,14 @@ type DropZoneProps = {
145
146
  allow?: string[];
146
147
  disallow?: string[];
147
148
  style?: CSSProperties;
148
- minEmptyHeight?: number;
149
+ minEmptyHeight?: CSSProperties["minHeight"] | number;
149
150
  className?: string;
150
151
  collisionAxis?: DragAxis;
152
+ as?: ElementType;
151
153
  };
152
154
 
153
155
  type PuckContext = {
154
- renderDropZone: React.FC<DropZoneProps>;
156
+ renderDropZone: (props: DropZoneProps) => React.ReactNode;
155
157
  metadata: Metadata;
156
158
  isEditing: boolean;
157
159
  dragRef: ((element: Element | null) => void) | null;
@@ -201,6 +203,8 @@ type ResolveDataTrigger = "insert" | "replace" | "load" | "force";
201
203
  type WithPartialProps<T, Props extends DefaultComponentProps> = Omit<T, "props"> & {
202
204
  props?: Partial<Props>;
203
205
  };
206
+ interface ComponentConfigExtensions {
207
+ }
204
208
  type ComponentConfigInternal<RenderProps extends DefaultComponentProps, FieldProps extends DefaultComponentProps, DataShape = Omit<ComponentData<FieldProps>, "type">, // NB this doesn't include AllProps, so types will not contain deep slot types. To fix, we require a breaking change.
205
209
  UserField extends BaseField = {}> = {
206
210
  render: PuckComponent<RenderProps>;
@@ -216,7 +220,7 @@ UserField extends BaseField = {}> = {
216
220
  fields: Fields<FieldProps>;
217
221
  lastFields: Fields<FieldProps>;
218
222
  lastData: DataShape | null;
219
- metadata: Metadata;
223
+ metadata: ComponentMetadata;
220
224
  appState: AppState;
221
225
  parent: ComponentData | null;
222
226
  }) => Promise<Fields<FieldProps>> | Fields<FieldProps>;
@@ -225,7 +229,7 @@ UserField extends BaseField = {}> = {
225
229
  id: string;
226
230
  }>;
227
231
  lastData: DataShape | null;
228
- metadata: Metadata;
232
+ metadata: ComponentMetadata;
229
233
  trigger: ResolveDataTrigger;
230
234
  }) => Promise<WithPartialProps<DataShape, FieldProps>> | WithPartialProps<DataShape, FieldProps>;
231
235
  resolvePermissions?: (data: DataShape, params: {
@@ -236,9 +240,10 @@ UserField extends BaseField = {}> = {
236
240
  permissions: Partial<Permissions>;
237
241
  appState: AppState;
238
242
  lastData: DataShape | null;
243
+ parent: ComponentData | null;
239
244
  }) => Promise<Partial<Permissions>> | Partial<Permissions>;
240
- metadata?: Metadata;
241
- };
245
+ metadata?: ComponentMetadata;
246
+ } & ComponentConfigExtensions;
242
247
  type ComponentConfig<RenderPropsOrParams extends LeftOrExactRight<RenderPropsOrParams, DefaultComponentProps, ComponentConfigParams> = DefaultComponentProps, FieldProps extends DefaultComponentProps = RenderPropsOrParams extends {
243
248
  props: any;
244
249
  } ? RenderPropsOrParams["props"] : RenderPropsOrParams, DataShape = Omit<ComponentData<FieldProps>, "type">> = RenderPropsOrParams extends ComponentConfigParams<infer ParamsRenderProps, never> ? ComponentConfigInternal<ParamsRenderProps, FieldProps, DataShape, {}> : RenderPropsOrParams extends ComponentConfigParams<infer ParamsRenderProps, infer ParamsFields> ? ComponentConfigInternal<ParamsRenderProps, FieldProps, DataShape, ParamsFields[keyof ParamsFields] & BaseField> : ComponentConfigInternal<RenderPropsOrParams, FieldProps, DataShape>;
@@ -269,6 +274,16 @@ type ExtractConfigParams<UserConfig extends ConfigInternal> = UserConfig extends
269
274
  type: string;
270
275
  } ? UserField : Field;
271
276
  } : never;
277
+ type ConfigParams<Components extends DefaultComponents = DefaultComponents, RootProps extends DefaultComponentProps = any, CategoryNames extends string[] = string[], UserFields extends FieldsExtension = FieldsExtension> = {
278
+ components?: Components;
279
+ root?: RootProps;
280
+ categories?: CategoryNames;
281
+ fields?: AssertHasValue<UserFields>;
282
+ };
283
+ type ComponentConfigParams<Props extends DefaultComponentProps = DefaultComponentProps, UserFields extends FieldsExtension = never> = {
284
+ props: Props;
285
+ fields?: AssertHasValue<UserFields>;
286
+ };
272
287
 
273
288
  type BaseData<Props extends {
274
289
  [key: string]: any;
@@ -309,10 +324,17 @@ type Data<Components extends DefaultComponents = DefaultComponents, RootProps ex
309
324
  type Metadata = {
310
325
  [key: string]: any;
311
326
  };
327
+ interface PuckMetadata extends Metadata {
328
+ }
329
+ interface ComponentMetadata extends PuckMetadata {
330
+ }
331
+ interface FieldMetadata extends Metadata {
332
+ }
312
333
 
313
334
  type ItemWithId = {
314
335
  _arrayId: string;
315
336
  _originalIndex: number;
337
+ _currentIndex: number;
316
338
  };
317
339
  type ArrayState = {
318
340
  items: ItemWithId[];
@@ -323,6 +345,7 @@ type UiState = {
323
345
  rightSideBarVisible: boolean;
324
346
  leftSideBarWidth?: number | null;
325
347
  rightSideBarWidth?: number | null;
348
+ mobilePanelExpanded?: boolean;
326
349
  itemSelector: ItemSelector | null;
327
350
  arrayState: Record<string, ArrayState | undefined>;
328
351
  previewMode: "interactive" | "edit";
@@ -335,7 +358,7 @@ type UiState = {
335
358
  isDragging: boolean;
336
359
  viewports: {
337
360
  current: {
338
- width: number;
361
+ width: number | "100%";
339
362
  height: number | "auto";
340
363
  };
341
364
  controlsVisible: boolean;
@@ -344,6 +367,9 @@ type UiState = {
344
367
  field: {
345
368
  focus?: string | null;
346
369
  };
370
+ plugin: {
371
+ current: string | null;
372
+ };
347
373
  };
348
374
  type AppState<UserData extends Data = Data> = {
349
375
  data: UserData;
@@ -377,26 +403,24 @@ type BuiltinTypes = Date | RegExp | Error | Function | symbol | null | undefined
377
403
  type WithDeepSlots<T, SlotType = T> = T extends Slot ? SlotType : T extends (infer U)[] ? Array<WithDeepSlots<U, SlotType>> : T extends (infer U)[] ? WithDeepSlots<U, SlotType>[] : T extends BuiltinTypes ? T : T extends object ? {
378
404
  [K in keyof T]: WithDeepSlots<T[K], SlotType>;
379
405
  } : T;
380
- type ConfigParams<Components extends DefaultComponents = DefaultComponents, RootProps extends DefaultComponentProps = any, CategoryNames extends string[] = string[], UserFields extends FieldsExtension = FieldsExtension> = {
381
- components?: Components;
382
- root?: RootProps;
383
- categories?: CategoryNames;
384
- fields?: AssertHasValue<UserFields>;
385
- };
386
406
  type FieldsExtension = {
387
407
  [Type in string]: {
388
408
  type: Type;
389
409
  };
390
410
  };
391
- type ComponentConfigParams<Props extends DefaultComponentProps = DefaultComponentProps, UserFields extends FieldsExtension = never> = {
392
- props: Props;
393
- fields?: AssertHasValue<UserFields>;
394
- };
395
411
  type Exact<T, Target> = Record<Exclude<keyof T, keyof Target>, never>;
396
412
  type LeftOrExactRight<Union, Left, Right> = (Left & Union extends Right ? Exact<Union, Right> : Left) | (Right & Exact<Union, Right>);
397
413
  type AssertHasValue<T, True = T, False = never> = [keyof T] extends [
398
414
  never
399
415
  ] ? False : True;
416
+ type RenderFunc<Props extends {
417
+ [key: string]: any;
418
+ } = {
419
+ children: ReactNode;
420
+ }> = (props: Props) => ReactElement;
421
+ type PluginInternal = Plugin & {
422
+ mobileOnly?: boolean;
423
+ };
400
424
 
401
425
  type MapFnParams<ThisField = Field> = {
402
426
  value: any;
@@ -420,11 +444,6 @@ G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>, UserField extends
420
444
  [Type in UserField["type"]]: FieldTransformFn<ExtractField<UserField, Type>>;
421
445
  }>;
422
446
 
423
- type RenderFunc<Props extends {
424
- [key: string]: any;
425
- } = {
426
- children: ReactNode;
427
- }> = (props: Props) => ReactElement;
428
447
  declare const overrideKeys: readonly ["header", "headerActions", "fields", "fieldLabel", "drawer", "drawerItem", "componentOverlay", "outline", "puck", "preview"];
429
448
  type OverrideKey = (typeof overrideKeys)[number];
430
449
  type OverridesGeneric<Shape extends {
@@ -496,7 +515,7 @@ type DragAxis = "dynamic" | "y" | "x";
496
515
 
497
516
  type iconTypes = "Smartphone" | "Monitor" | "Tablet";
498
517
  type Viewport = {
499
- width: number;
518
+ width: number | "100%";
500
519
  height?: number | "auto";
501
520
  label?: string;
502
521
  icon?: iconTypes | ReactNode;
@@ -516,8 +535,13 @@ type IframeConfig = {
516
535
  };
517
536
  type OnAction<UserData extends Data = Data> = (action: PuckAction, appState: AppState<UserData>, prevAppState: AppState<UserData>) => void;
518
537
  type Plugin<UserConfig extends Config = Config> = {
538
+ name?: string;
539
+ label?: string;
540
+ icon?: ReactNode;
541
+ render?: () => ReactElement;
519
542
  overrides?: Partial<Overrides<UserConfig>>;
520
543
  fieldTransforms?: FieldTransforms<UserConfig>;
544
+ mobilePanelHeight?: "toggle" | "min-content";
521
545
  };
522
546
  type History<D = any> = {
523
547
  state: D;
@@ -609,30 +633,4 @@ type PuckAction = {
609
633
  recordHistory?: boolean;
610
634
  } & (ReorderAction | InsertAction | MoveAction | ReplaceAction | ReplaceRootAction | RemoveAction | DuplicateAction | SetAction | SetDataAction | SetUiAction | RegisterZoneAction | UnregisterZoneAction);
611
635
 
612
- type MigrationOptions<UserConfig extends Config> = {
613
- migrateDynamicZonesForComponent?: {
614
- [ComponentName in keyof UserConfig["components"]]: (props: WithId<UserGenerics<UserConfig>["UserProps"][ComponentName]>, zones: Record<string, Content>) => ComponentData["props"];
615
- };
616
- };
617
- declare function migrate<UserConfig extends Config = Config>(data: Data, config?: UserConfig, migrationOptions?: MigrationOptions<UserConfig>): Data;
618
-
619
- type PropTransform<Components extends DefaultComponents = DefaultComponents, RootProps extends DefaultComponentProps = DefaultRootFieldProps> = Partial<{
620
- [ComponentName in keyof Components]: (props: Components[ComponentName] & {
621
- [key: string]: any;
622
- }) => Components[ComponentName];
623
- } & {
624
- root: (props: RootProps & {
625
- [key: string]: any;
626
- }) => RootProps;
627
- }>;
628
- declare function transformProps<Components extends DefaultComponents = DefaultComponents, RootProps extends DefaultComponentProps = DefaultRootFieldProps>(data: Partial<Data>, propTransforms: PropTransform<Components, RootProps>, config?: Config): Data;
629
-
630
- declare function resolveAllData<Components extends DefaultComponents = DefaultComponents, RootProps extends Record<string, any> = DefaultRootFieldProps>(data: Partial<Data>, config: Config, metadata?: Metadata, onResolveStart?: (item: ComponentData) => void, onResolveEnd?: (item: ComponentData) => void): Promise<Data<Components, RootProps>>;
631
-
632
- type WalkTreeOptions = {
633
- parentId: string;
634
- propName: string;
635
- };
636
- 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;
637
-
638
- export { type BaseField as $, type AppState as A, type ArrayState as B, type Config as C, type DropZoneProps as D, type SlotComponent as E, type Fields as F, type PuckComponent as G, type History as H, type IframeConfig as I, type RootConfig as J, type DefaultComponents as K, type ExtractConfigParams as L, type Metadata as M, type BaseData as N, type Overrides as O, type Permissions as P, type RootDataWithoutProps as Q, type RootDataWithProps as R, type Slot as S, type RootData as T, type UserGenerics as U, type Viewports as V, type WithSlotProps as W, type ComponentDataOptionalId as X, type MappedItem as Y, type ComponentDataMap as Z, type Content as _, type ComponentData as a, type TextField as a0, type NumberField as a1, type TextareaField as a2, type SelectField as a3, type RadioField as a4, type ArrayField as a5, type ObjectField as a6, type Adaptor as a7, type ExternalFieldWithAdaptor as a8, type CacheOpts as a9, type ExternalField as aa, type CustomFieldRender as ab, type CustomField as ac, type SlotField as ad, type PuckContext as ae, type DefaultRootFieldProps as af, type DefaultRootRenderProps as ag, type DefaultRootProps as ah, type DefaultComponentProps as ai, type WithId as aj, type WithPuckProps as ak, type AsFieldProps as al, type WithChildren as am, type ExtractField as an, type PuckAction as b, type ResolveDataTrigger as c, type Plugin as d, type UiState as e, type ComponentConfig as f, type FieldTransforms as g, type Field as h, type FieldProps as i, type Data as j, type OnAction as k, type InitialHistory as l, migrate as m, type ItemSelector as n, type Direction as o, type DragAxis as p, type Viewport as q, resolveAllData as r, type FieldTransformFnParams as s, transformProps as t, type FieldTransformFn as u, overrideKeys as v, walkTree as w, type OverrideKey as x, type FieldRenderFunctions as y, type ItemWithId as z };
636
+ export { type RootDataWithoutProps as $, type AppState as A, overrideKeys as B, type Config as C, type Data as D, type OverrideKey as E, type Fields as F, type FieldRenderFunctions as G, type History as H, type IframeConfig as I, type ItemWithId as J, type ArrayState as K, type SlotComponent as L, type Metadata as M, type PuckComponent as N, type OnAction as O, type PrivateAppState as P, type ComponentConfigExtensions as Q, type RootData as R, type Slot as S, type RootConfig as T, type UserGenerics as U, type Viewports as V, type WithId as W, type ExtractConfigParams as X, type ConfigParams as Y, type ComponentConfigParams as Z, type BaseData as _, type PuckAction as a, type ComponentDataOptionalId as a0, type MappedItem as a1, type ComponentDataMap as a2, type PuckMetadata as a3, type ComponentMetadata as a4, type FieldMetadata as a5, type BaseField as a6, type TextField as a7, type NumberField as a8, type TextareaField as a9, type SelectField as aa, type RadioField as ab, type ArrayField as ac, type ObjectField as ad, type Adaptor as ae, type ExternalFieldWithAdaptor as af, type CacheOpts as ag, type ExternalField as ah, type CustomFieldRender as ai, type CustomField as aj, type SlotField as ak, type PuckContext as al, type DefaultRootRenderProps as am, type DefaultRootProps as an, type WithPuckProps as ao, type AsFieldProps as ap, type WithChildren as aq, type ExtractField as ar, type Content as b, type ComponentData as c, type DefaultComponents as d, type DefaultComponentProps as e, type DefaultRootFieldProps as f, type Permissions as g, type RootDataWithProps as h, type ResolveDataTrigger as i, type Plugin as j, type Overrides as k, type UiState as l, type ComponentConfig as m, type FieldTransforms as n, type Field as o, type FieldProps as p, type DropZoneProps as q, type InitialHistory as r, type ItemSelector as s, type PluginInternal as t, type WithSlotProps as u, type Direction as v, type DragAxis as w, type Viewport as x, type FieldTransformFnParams as y, type FieldTransformFn as z };