@measured/puck 0.13.2-canary.7d861f5 → 0.14.0-canary.0337c8d

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,4 @@
1
- import { CSSProperties, ReactElement, ReactNode } from 'react';
2
- import * as react_jsx_runtime from 'react/jsx-runtime';
1
+ import { CSSProperties, ReactNode, ReactElement } from 'react';
3
2
 
4
3
  type ItemSelector = {
5
4
  index: number;
@@ -12,11 +11,24 @@ type DropZoneProps = {
12
11
  disallow?: string[];
13
12
  style?: CSSProperties;
14
13
  };
15
- declare function DropZone(props: DropZoneProps): react_jsx_runtime.JSX.Element;
14
+
15
+ type iconTypes = "Smartphone" | "Monitor" | "Tablet";
16
+ type Viewport = {
17
+ width: number;
18
+ height?: number | "auto";
19
+ label?: string;
20
+ icon?: iconTypes | ReactNode;
21
+ };
22
+ type Viewports = Viewport[];
16
23
 
17
24
  type WithPuckProps<Props> = Props & {
18
25
  id: string;
19
26
  };
27
+ type FieldOption = {
28
+ label: string;
29
+ value: string | number | boolean;
30
+ };
31
+ type FieldOptions = Array<FieldOption> | ReadonlyArray<FieldOption>;
20
32
  type BaseField = {
21
33
  label?: string;
22
34
  };
@@ -25,23 +37,19 @@ type TextField = BaseField & {
25
37
  };
26
38
  type NumberField = BaseField & {
27
39
  type: "number";
40
+ min?: number;
41
+ max?: number;
28
42
  };
29
43
  type TextareaField = BaseField & {
30
44
  type: "textarea";
31
45
  };
32
46
  type SelectField = BaseField & {
33
47
  type: "select";
34
- options: {
35
- label: string;
36
- value: string | number | boolean;
37
- }[];
48
+ options: FieldOptions;
38
49
  };
39
50
  type RadioField = BaseField & {
40
51
  type: "radio";
41
- options: {
42
- label: string;
43
- value: string | number | boolean;
44
- }[];
52
+ options: FieldOptions;
45
53
  };
46
54
  type ArrayField<Props extends {
47
55
  [key: string]: any;
@@ -54,6 +62,8 @@ type ArrayField<Props extends {
54
62
  };
55
63
  defaultItemProps?: Props[0];
56
64
  getItemSummary?: (item: Props[0], index?: number) => string;
65
+ max?: number;
66
+ min?: number;
57
67
  };
58
68
  type ObjectField<Props extends {
59
69
  [key: string]: any;
@@ -62,7 +72,7 @@ type ObjectField<Props extends {
62
72
  }> = BaseField & {
63
73
  type: "object";
64
74
  objectFields: {
65
- [SubPropName in keyof Props[0]]: Field<Props[0][SubPropName]>;
75
+ [SubPropName in keyof Props]: Field<Props[SubPropName]>;
66
76
  };
67
77
  };
68
78
  type Adaptor<AdaptorParams = {}, TableShape extends Record<string, any> = {}, PropShape = TableShape> = {
@@ -90,11 +100,15 @@ type ExternalField<Props extends {
90
100
  placeholder?: string;
91
101
  fetchList: (params: {
92
102
  query: string;
103
+ filters: Record<string, any>;
93
104
  }) => Promise<any[] | null>;
94
105
  mapProp?: (value: any) => Props;
106
+ mapRow?: (value: any) => Record<string, string | number>;
95
107
  getItemSummary: (item: Props, index?: number) => string;
96
108
  showSearch?: boolean;
97
109
  initialQuery?: string;
110
+ filterFields?: Record<string, Field>;
111
+ initialFilters?: Record<string, any>;
98
112
  };
99
113
  type CustomField<Props extends {
100
114
  [key: string]: any;
@@ -131,19 +145,26 @@ type Content<Props extends {
131
145
  } = {
132
146
  [key: string]: any;
133
147
  }> = ComponentData<Props>[];
134
- type PuckComponent<Props extends DefaultComponentProps = DefaultComponentProps> = (props: WithPuckProps<Props & {
148
+ type PuckComponent<Props> = (props: WithPuckProps<Props & {
135
149
  puck: PuckContext;
136
150
  }>) => JSX.Element;
137
151
  type PuckContext = {
138
- renderDropZone: typeof DropZone;
152
+ renderDropZone: React.FC<DropZoneProps>;
139
153
  };
140
- type ComponentConfig<ComponentProps extends DefaultComponentProps = DefaultComponentProps, DefaultProps = ComponentProps, DataShape = ComponentData<ComponentProps>> = {
154
+ type ComponentConfig<ComponentProps extends DefaultComponentProps = DefaultComponentProps, DefaultProps = ComponentProps, DataShape = Omit<ComponentData<ComponentProps>, "type">> = {
141
155
  render: PuckComponent<ComponentProps>;
156
+ label?: string;
142
157
  defaultProps?: DefaultProps;
143
158
  fields?: Fields<ComponentProps>;
144
159
  resolveData?: (data: DataShape, params: {
145
160
  changed: Partial<Record<keyof ComponentProps, boolean>>;
146
- }) => Promise<Partial<ComponentDataWithOptionalProps<ComponentProps>>> | Partial<ComponentDataWithOptionalProps<ComponentProps>>;
161
+ }) => Promise<{
162
+ props?: Partial<ComponentProps>;
163
+ readOnly?: Partial<Record<keyof ComponentProps, boolean>>;
164
+ }> | {
165
+ props?: Partial<ComponentProps>;
166
+ readOnly?: Partial<Record<keyof ComponentProps, boolean>>;
167
+ };
147
168
  };
148
169
  type Category<ComponentName> = {
149
170
  components?: ComponentName[];
@@ -151,22 +172,18 @@ type Category<ComponentName> = {
151
172
  visible?: boolean;
152
173
  defaultExpanded?: boolean;
153
174
  };
154
- type Config<Props extends {
155
- [key: string]: any;
156
- } = {
157
- [key: string]: any;
158
- }, RootProps extends DefaultRootProps = DefaultRootProps, CategoryName extends string = any> = {
175
+ type Config<Props extends Record<string, any> = Record<string, any>, RootProps extends DefaultRootProps = DefaultRootProps, CategoryName extends string = string> = {
159
176
  categories?: Record<CategoryName, Category<keyof Props>> & {
160
- other?: Category<Props>;
177
+ other?: Category<keyof Props>;
161
178
  };
162
179
  components: {
163
180
  [ComponentName in keyof Props]: Omit<ComponentConfig<Props[ComponentName], Props[ComponentName]>, "type">;
164
181
  };
165
182
  root?: Partial<ComponentConfig<RootProps & {
166
- children: ReactNode;
183
+ children?: ReactNode;
167
184
  }, Partial<RootProps & {
168
- children: ReactNode;
169
- }>, RootDataWithProps<RootProps>>>;
185
+ children?: ReactNode;
186
+ }>, RootDataWithProps>>;
170
187
  };
171
188
  type BaseData<Props extends {
172
189
  [key: string]: any;
@@ -184,13 +201,6 @@ type RootDataWithProps<Props extends DefaultRootProps = DefaultRootProps> = {
184
201
  };
185
202
  type RootDataWithoutProps<Props extends DefaultRootProps = DefaultRootProps> = Props;
186
203
  type RootData<Props extends DefaultRootProps = DefaultRootProps> = BaseData<Props> & Partial<RootDataWithProps<Props>> & Partial<RootDataWithoutProps<Props>>;
187
- type ComponentDataWithOptionalProps<Props extends {
188
- [key: string]: any;
189
- } = {
190
- [key: string]: any;
191
- }> = Omit<ComponentData, "props"> & {
192
- props: Partial<WithPuckProps<Props>>;
193
- };
194
204
  type MappedItem = ComponentData;
195
205
  type Data<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultRootProps = DefaultRootProps> = {
196
206
  root: RootData<RootProps>;
@@ -217,10 +227,18 @@ type UiState = {
217
227
  expanded?: boolean;
218
228
  }>;
219
229
  isDragging: boolean;
230
+ viewports: {
231
+ current: {
232
+ width: number;
233
+ height: number | "auto";
234
+ };
235
+ controlsVisible: boolean;
236
+ options: Viewport[];
237
+ };
220
238
  };
221
239
  type AppState = {
222
240
  data: Data;
223
241
  ui: UiState;
224
242
  };
225
243
 
226
- export { AppState as A, BaseField as B, Config as C, Data as D, ExternalFieldWithAdaptor as E, Field as F, ItemSelector as I, MappedItem as M, NumberField as N, ObjectField as O, PuckComponent as P, RootDataWithProps as R, SelectField as S, TextField as T, UiState as U, DefaultComponentProps as a, DefaultRootProps as b, RootData as c, TextareaField as d, RadioField as e, ArrayField as f, Adaptor as g, ExternalField as h, CustomField as i, Fields as j, Content as k, PuckContext as l, ComponentConfig as m, BaseData as n, ComponentData as o, RootDataWithoutProps as p, ItemWithId as q, ArrayState as r, DropZone as s };
244
+ export type { AppState as A, BaseField as B, Config as C, Data as D, ExternalFieldWithAdaptor as E, Field as F, ItemSelector as I, MappedItem as M, NumberField as N, ObjectField as O, PuckComponent as P, RootDataWithProps as R, SelectField as S, TextField as T, UiState as U, Viewports as V, DefaultRootProps as a, DropZoneProps as b, DefaultComponentProps as c, RootData as d, ComponentData as e, TextareaField as f, RadioField as g, ArrayField as h, Adaptor as i, ExternalField as j, CustomField as k, Fields as l, Content as m, PuckContext as n, ComponentConfig as o, BaseData as p, RootDataWithoutProps as q, ItemWithId as r, ArrayState as s };