@measured/puck 0.15.0-canary.480467a → 0.15.0-canary.91dff22

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -60,10 +60,7 @@ const config = {
60
60
  };
61
61
 
62
62
  // Describe the initial data
63
- const initialData = {
64
- content: [],
65
- root: {},
66
- };
63
+ const initialData = {};
67
64
 
68
65
  // Save the data to your database
69
66
  const save = (data) => {};
@@ -21,9 +21,6 @@ type Viewport = {
21
21
  };
22
22
  type Viewports = Viewport[];
23
23
 
24
- type WithPuckProps<Props> = Props & {
25
- id: string;
26
- };
27
24
  type FieldOption = {
28
25
  label: string;
29
26
  value: string | number | boolean;
@@ -114,17 +111,36 @@ type CustomField<Props extends any = {}> = BaseField & {
114
111
  type: "custom";
115
112
  render: (props: {
116
113
  field: CustomField<Props>;
117
- name: string;
114
+ name?: string;
115
+ id: string;
118
116
  value: Props;
119
117
  onChange: (value: Props) => void;
120
118
  readOnly?: boolean;
121
119
  }) => ReactElement;
122
120
  };
123
- type Field<Props extends {
121
+ type Field<Props extends any = any> = TextField | NumberField | TextareaField | SelectField | RadioField | ArrayField<Props extends {
124
122
  [key: string]: any;
125
- } = {
123
+ } ? Props : any> | ObjectField<Props extends {
124
+ [key: string]: any;
125
+ } ? Props : any> | ExternalField<Props extends {
126
126
  [key: string]: any;
127
- }> = TextField | NumberField | TextareaField | SelectField | RadioField | ArrayField<Props> | ObjectField<Props> | ExternalField<Props> | ExternalFieldWithAdaptor<Props> | CustomField<Props>;
127
+ } ? Props : any> | ExternalFieldWithAdaptor<Props extends {
128
+ [key: string]: any;
129
+ } ? Props : any> | CustomField<Props>;
130
+ type Fields<ComponentProps extends DefaultComponentProps = DefaultComponentProps> = {
131
+ [PropName in keyof Omit<Required<ComponentProps>, "children" | "editMode">]: Field<ComponentProps[PropName]>;
132
+ };
133
+ type FieldProps<ValueType = any, F = Field<any>> = {
134
+ field: F;
135
+ value: ValueType;
136
+ id?: string;
137
+ onChange: (value: ValueType, uiState?: Partial<UiState>) => void;
138
+ readOnly?: boolean;
139
+ };
140
+
141
+ type WithPuckProps<Props> = Props & {
142
+ id: string;
143
+ };
128
144
  type DefaultRootProps = {
129
145
  title?: string;
130
146
  [key: string]: any;
@@ -133,9 +149,6 @@ type DefaultComponentProps = {
133
149
  [key: string]: any;
134
150
  editMode?: boolean;
135
151
  };
136
- type Fields<ComponentProps extends DefaultComponentProps = DefaultComponentProps> = {
137
- [PropName in keyof Omit<Required<ComponentProps>, "children" | "editMode">]: Field<ComponentProps[PropName]>;
138
- };
139
152
  type Content<Props extends {
140
153
  [key: string]: any;
141
154
  } = {
@@ -152,8 +165,16 @@ type ComponentConfig<ComponentProps extends DefaultComponentProps = DefaultCompo
152
165
  label?: string;
153
166
  defaultProps?: DefaultProps;
154
167
  fields?: Fields<ComponentProps>;
168
+ resolveFields?: (data: DataShape, params: {
169
+ changed: Partial<Record<keyof ComponentProps, boolean>>;
170
+ fields: Fields<ComponentProps>;
171
+ lastFields: Fields<ComponentProps>;
172
+ lastData: DataShape;
173
+ appState: AppState;
174
+ }) => Promise<Fields<ComponentProps>> | Fields<ComponentProps>;
155
175
  resolveData?: (data: DataShape, params: {
156
176
  changed: Partial<Record<keyof ComponentProps, boolean>>;
177
+ lastData: DataShape;
157
178
  }) => Promise<{
158
179
  props?: Partial<ComponentProps>;
159
180
  readOnly?: Partial<Record<keyof ComponentProps, boolean>>;
@@ -179,7 +200,7 @@ type Config<Props extends Record<string, any> = Record<string, any>, RootProps e
179
200
  children?: ReactNode;
180
201
  }, Partial<RootProps & {
181
202
  children?: ReactNode;
182
- }>, RootDataWithProps>>;
203
+ }>, RootData>>;
183
204
  };
184
205
  type BaseData<Props extends {
185
206
  [key: string]: any;
@@ -192,11 +213,11 @@ type ComponentData<Props extends DefaultComponentProps = DefaultComponentProps>
192
213
  type: keyof Props;
193
214
  props: WithPuckProps<Props>;
194
215
  } & BaseData<Props>;
195
- type RootDataWithProps<Props extends DefaultRootProps = DefaultRootProps> = {
216
+ type RootDataWithProps<Props extends DefaultRootProps = DefaultRootProps> = BaseData<Props> & {
196
217
  props: Props;
197
218
  };
198
219
  type RootDataWithoutProps<Props extends DefaultRootProps = DefaultRootProps> = Props;
199
- type RootData<Props extends DefaultRootProps = DefaultRootProps> = BaseData<Props> & Partial<RootDataWithProps<Props>> & Partial<RootDataWithoutProps<Props>>;
220
+ type RootData<Props extends DefaultRootProps = DefaultRootProps> = Partial<RootDataWithProps<Props>> & Partial<RootDataWithoutProps<Props>>;
200
221
  type MappedItem = ComponentData;
201
222
  type Data<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultRootProps = DefaultRootProps> = {
202
223
  root: RootData<RootProps>;
@@ -237,4 +258,4 @@ type AppState = {
237
258
  ui: UiState;
238
259
  };
239
260
 
240
- 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, 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 };
261
+ export { AppState as A, BaseData 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, FieldProps as a, DefaultRootProps as b, DropZoneProps as c, DefaultComponentProps as d, RootData as e, ComponentData as f, Content as g, PuckContext as h, ComponentConfig as i, RootDataWithoutProps as j, ItemWithId as k, ArrayState as l, BaseField as m, TextareaField as n, RadioField as o, ArrayField as p, Adaptor as q, ExternalField as r, CustomField as s, Fields as t };