@measured/puck 0.21.0-canary.e310a175 → 0.21.0-canary.e9d5c0ea

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.
@@ -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];
55
+ defaultItemProps?: Props[0] | ((index: number) => Props[0]);
56
56
  getItemSummary?: (item: Props[0], index?: number) => string;
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>;
@@ -85,9 +85,9 @@ type ExternalFieldWithAdaptor<Props extends any = {
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;
@@ -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,16 @@ 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
+ }
122
+ interface SlotField extends BaseField {
123
123
  type: "slot";
124
124
  allow?: string[];
125
125
  disallow?: string[];
126
- };
126
+ }
127
127
  type Field<ValueType = any, UserField extends {} = {}> = TextField | NumberField | TextareaField | SelectField | RadioField | ArrayField<ValueType extends {
128
128
  [key: string]: any;
129
129
  }[] ? ValueType : never, UserField> | ObjectField<ValueType, UserField> | ExternalField<ValueType> | ExternalFieldWithAdaptor<ValueType> | CustomField<ValueType> | SlotField;
@@ -151,7 +151,7 @@ type DropZoneProps = {
151
151
  };
152
152
 
153
153
  type PuckContext = {
154
- renderDropZone: React.FC<DropZoneProps>;
154
+ renderDropZone: (props: DropZoneProps) => React.ReactNode;
155
155
  metadata: Metadata;
156
156
  isEditing: boolean;
157
157
  dragRef: ((element: Element | null) => void) | null;
@@ -201,6 +201,8 @@ type ResolveDataTrigger = "insert" | "replace" | "load" | "force";
201
201
  type WithPartialProps<T, Props extends DefaultComponentProps> = Omit<T, "props"> & {
202
202
  props?: Partial<Props>;
203
203
  };
204
+ interface ComponentConfigExtensions {
205
+ }
204
206
  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
207
  UserField extends BaseField = {}> = {
206
208
  render: PuckComponent<RenderProps>;
@@ -216,7 +218,7 @@ UserField extends BaseField = {}> = {
216
218
  fields: Fields<FieldProps>;
217
219
  lastFields: Fields<FieldProps>;
218
220
  lastData: DataShape | null;
219
- metadata: Metadata;
221
+ metadata: ComponentMetadata;
220
222
  appState: AppState;
221
223
  parent: ComponentData | null;
222
224
  }) => Promise<Fields<FieldProps>> | Fields<FieldProps>;
@@ -225,7 +227,7 @@ UserField extends BaseField = {}> = {
225
227
  id: string;
226
228
  }>;
227
229
  lastData: DataShape | null;
228
- metadata: Metadata;
230
+ metadata: ComponentMetadata;
229
231
  trigger: ResolveDataTrigger;
230
232
  }) => Promise<WithPartialProps<DataShape, FieldProps>> | WithPartialProps<DataShape, FieldProps>;
231
233
  resolvePermissions?: (data: DataShape, params: {
@@ -237,8 +239,8 @@ UserField extends BaseField = {}> = {
237
239
  appState: AppState;
238
240
  lastData: DataShape | null;
239
241
  }) => Promise<Partial<Permissions>> | Partial<Permissions>;
240
- metadata?: Metadata;
241
- };
242
+ metadata?: ComponentMetadata;
243
+ } & ComponentConfigExtensions;
242
244
  type ComponentConfig<RenderPropsOrParams extends LeftOrExactRight<RenderPropsOrParams, DefaultComponentProps, ComponentConfigParams> = DefaultComponentProps, FieldProps extends DefaultComponentProps = RenderPropsOrParams extends {
243
245
  props: any;
244
246
  } ? 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 +271,16 @@ type ExtractConfigParams<UserConfig extends ConfigInternal> = UserConfig extends
269
271
  type: string;
270
272
  } ? UserField : Field;
271
273
  } : never;
274
+ type ConfigParams<Components extends DefaultComponents = DefaultComponents, RootProps extends DefaultComponentProps = any, CategoryNames extends string[] = string[], UserFields extends FieldsExtension = FieldsExtension> = {
275
+ components?: Components;
276
+ root?: RootProps;
277
+ categories?: CategoryNames;
278
+ fields?: AssertHasValue<UserFields>;
279
+ };
280
+ type ComponentConfigParams<Props extends DefaultComponentProps = DefaultComponentProps, UserFields extends FieldsExtension = never> = {
281
+ props: Props;
282
+ fields?: AssertHasValue<UserFields>;
283
+ };
272
284
 
273
285
  type BaseData<Props extends {
274
286
  [key: string]: any;
@@ -309,10 +321,17 @@ type Data<Components extends DefaultComponents = DefaultComponents, RootProps ex
309
321
  type Metadata = {
310
322
  [key: string]: any;
311
323
  };
324
+ interface PuckMetadata extends Metadata {
325
+ }
326
+ interface ComponentMetadata extends PuckMetadata {
327
+ }
328
+ interface FieldMetadata extends Metadata {
329
+ }
312
330
 
313
331
  type ItemWithId = {
314
332
  _arrayId: string;
315
333
  _originalIndex: number;
334
+ _currentIndex: number;
316
335
  };
317
336
  type ArrayState = {
318
337
  items: ItemWithId[];
@@ -323,6 +342,7 @@ type UiState = {
323
342
  rightSideBarVisible: boolean;
324
343
  leftSideBarWidth?: number | null;
325
344
  rightSideBarWidth?: number | null;
345
+ mobilePanelExpanded?: boolean;
326
346
  itemSelector: ItemSelector | null;
327
347
  arrayState: Record<string, ArrayState | undefined>;
328
348
  previewMode: "interactive" | "edit";
@@ -335,7 +355,7 @@ type UiState = {
335
355
  isDragging: boolean;
336
356
  viewports: {
337
357
  current: {
338
- width: number;
358
+ width: number | "100%";
339
359
  height: number | "auto";
340
360
  };
341
361
  controlsVisible: boolean;
@@ -344,6 +364,9 @@ type UiState = {
344
364
  field: {
345
365
  focus?: string | null;
346
366
  };
367
+ plugin: {
368
+ current: string | null;
369
+ };
347
370
  };
348
371
  type AppState<UserData extends Data = Data> = {
349
372
  data: UserData;
@@ -377,26 +400,24 @@ type BuiltinTypes = Date | RegExp | Error | Function | symbol | null | undefined
377
400
  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
401
  [K in keyof T]: WithDeepSlots<T[K], SlotType>;
379
402
  } : 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
403
  type FieldsExtension = {
387
404
  [Type in string]: {
388
405
  type: Type;
389
406
  };
390
407
  };
391
- type ComponentConfigParams<Props extends DefaultComponentProps = DefaultComponentProps, UserFields extends FieldsExtension = never> = {
392
- props: Props;
393
- fields?: AssertHasValue<UserFields>;
394
- };
395
408
  type Exact<T, Target> = Record<Exclude<keyof T, keyof Target>, never>;
396
409
  type LeftOrExactRight<Union, Left, Right> = (Left & Union extends Right ? Exact<Union, Right> : Left) | (Right & Exact<Union, Right>);
397
410
  type AssertHasValue<T, True = T, False = never> = [keyof T] extends [
398
411
  never
399
412
  ] ? False : True;
413
+ type RenderFunc<Props extends {
414
+ [key: string]: any;
415
+ } = {
416
+ children: ReactNode;
417
+ }> = (props: Props) => ReactElement;
418
+ type PluginInternal = Plugin & {
419
+ mobileOnly?: boolean;
420
+ };
400
421
 
401
422
  type MapFnParams<ThisField = Field> = {
402
423
  value: any;
@@ -420,11 +441,6 @@ G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>, UserField extends
420
441
  [Type in UserField["type"]]: FieldTransformFn<ExtractField<UserField, Type>>;
421
442
  }>;
422
443
 
423
- type RenderFunc<Props extends {
424
- [key: string]: any;
425
- } = {
426
- children: ReactNode;
427
- }> = (props: Props) => ReactElement;
428
444
  declare const overrideKeys: readonly ["header", "headerActions", "fields", "fieldLabel", "drawer", "drawerItem", "componentOverlay", "outline", "puck", "preview"];
429
445
  type OverrideKey = (typeof overrideKeys)[number];
430
446
  type OverridesGeneric<Shape extends {
@@ -496,7 +512,7 @@ type DragAxis = "dynamic" | "y" | "x";
496
512
 
497
513
  type iconTypes = "Smartphone" | "Monitor" | "Tablet";
498
514
  type Viewport = {
499
- width: number;
515
+ width: number | "100%";
500
516
  height?: number | "auto";
501
517
  label?: string;
502
518
  icon?: iconTypes | ReactNode;
@@ -516,8 +532,13 @@ type IframeConfig = {
516
532
  };
517
533
  type OnAction<UserData extends Data = Data> = (action: PuckAction, appState: AppState<UserData>, prevAppState: AppState<UserData>) => void;
518
534
  type Plugin<UserConfig extends Config = Config> = {
535
+ name?: string;
536
+ label?: string;
537
+ icon?: ReactNode;
538
+ render?: () => ReactElement;
519
539
  overrides?: Partial<Overrides<UserConfig>>;
520
540
  fieldTransforms?: FieldTransforms<UserConfig>;
541
+ mobilePanelHeight?: "toggle" | "min-content";
521
542
  };
522
543
  type History<D = any> = {
523
544
  state: D;
@@ -635,4 +656,4 @@ type WalkTreeOptions = {
635
656
  };
636
657
  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
658
 
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 };
659
+ export { type ComponentDataOptionalId as $, type AppState as A, type ItemWithId as B, type Config as C, type DropZoneProps as D, type ArrayState as E, type Fields as F, type SlotComponent as G, type History as H, type IframeConfig as I, type PuckComponent as J, type ComponentConfigExtensions as K, type RootConfig as L, type Metadata as M, type DefaultComponents as N, type Overrides as O, type Permissions as P, type ExtractConfigParams as Q, type RootDataWithProps as R, type Slot as S, type ConfigParams as T, type UserGenerics as U, type Viewports as V, type WithSlotProps as W, type ComponentConfigParams as X, type BaseData as Y, type RootDataWithoutProps as Z, type RootData as _, type ComponentData as a, type MappedItem as a0, type ComponentDataMap as a1, type Content 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 DefaultRootFieldProps as am, type DefaultRootRenderProps as an, type DefaultRootProps as ao, type DefaultComponentProps as ap, type WithId as aq, type WithPuckProps as ar, type AsFieldProps as as, type WithChildren as at, type ExtractField as au, 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 PluginInternal as o, type Direction as p, type DragAxis as q, resolveAllData as r, type Viewport as s, transformProps as t, type FieldTransformFnParams as u, type FieldTransformFn as v, walkTree as w, overrideKeys as x, type OverrideKey as y, type FieldRenderFunctions as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@measured/puck",
3
- "version": "0.21.0-canary.e310a175",
3
+ "version": "0.21.0-canary.e9d5c0ea",
4
4
  "description": "The open-source visual editor for React",
5
5
  "author": "Chris Villa <chris@puckeditor.com>",
6
6
  "repository": "measuredco/puck",