@measured/puck 0.14.3-canary.9df6633 → 0.15.0-canary.47a27ed

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) => {};
@@ -110,16 +110,12 @@ type ExternalField<Props extends {
110
110
  filterFields?: Record<string, Field>;
111
111
  initialFilters?: Record<string, any>;
112
112
  };
113
- type CustomField<Props extends {
114
- [key: string]: any;
115
- } = {
116
- [key: string]: any;
117
- }> = BaseField & {
113
+ type CustomField<Props extends any = {}> = BaseField & {
118
114
  type: "custom";
119
115
  render: (props: {
120
- field: CustomField;
116
+ field: CustomField<Props>;
121
117
  name: string;
122
- value: any;
118
+ value: Props;
123
119
  onChange: (value: Props) => void;
124
120
  readOnly?: boolean;
125
121
  }) => ReactElement;
@@ -128,7 +124,7 @@ type Field<Props extends {
128
124
  [key: string]: any;
129
125
  } = {
130
126
  [key: string]: any;
131
- }> = TextField | NumberField | TextareaField | SelectField | RadioField | ArrayField<Props> | ObjectField<Props> | ExternalField<Props> | ExternalFieldWithAdaptor<Props> | CustomField;
127
+ }> = TextField | NumberField | TextareaField | SelectField | RadioField | ArrayField<Props> | ObjectField<Props> | ExternalField<Props> | ExternalFieldWithAdaptor<Props> | CustomField<Props>;
132
128
  type DefaultRootProps = {
133
129
  title?: string;
134
130
  [key: string]: any;
@@ -156,8 +152,16 @@ type ComponentConfig<ComponentProps extends DefaultComponentProps = DefaultCompo
156
152
  label?: string;
157
153
  defaultProps?: DefaultProps;
158
154
  fields?: Fields<ComponentProps>;
155
+ resolveFields?: (data: DataShape, params: {
156
+ changed: Partial<Record<keyof ComponentProps, boolean>>;
157
+ fields: Fields<ComponentProps>;
158
+ lastFields: Fields<ComponentProps>;
159
+ lastData: DataShape;
160
+ appState: AppState;
161
+ }) => Promise<Fields<ComponentProps>> | Fields<ComponentProps>;
159
162
  resolveData?: (data: DataShape, params: {
160
163
  changed: Partial<Record<keyof ComponentProps, boolean>>;
164
+ lastData: DataShape;
161
165
  }) => Promise<{
162
166
  props?: Partial<ComponentProps>;
163
167
  readOnly?: Partial<Record<keyof ComponentProps, boolean>>;
@@ -183,7 +187,7 @@ type Config<Props extends Record<string, any> = Record<string, any>, RootProps e
183
187
  children?: ReactNode;
184
188
  }, Partial<RootProps & {
185
189
  children?: ReactNode;
186
- }>, RootDataWithProps>>;
190
+ }>, RootData>>;
187
191
  };
188
192
  type BaseData<Props extends {
189
193
  [key: string]: any;
@@ -196,11 +200,11 @@ type ComponentData<Props extends DefaultComponentProps = DefaultComponentProps>
196
200
  type: keyof Props;
197
201
  props: WithPuckProps<Props>;
198
202
  } & BaseData<Props>;
199
- type RootDataWithProps<Props extends DefaultRootProps = DefaultRootProps> = {
203
+ type RootDataWithProps<Props extends DefaultRootProps = DefaultRootProps> = BaseData<Props> & {
200
204
  props: Props;
201
205
  };
202
206
  type RootDataWithoutProps<Props extends DefaultRootProps = DefaultRootProps> = Props;
203
- type RootData<Props extends DefaultRootProps = DefaultRootProps> = BaseData<Props> & Partial<RootDataWithProps<Props>> & Partial<RootDataWithoutProps<Props>>;
207
+ type RootData<Props extends DefaultRootProps = DefaultRootProps> = Partial<RootDataWithProps<Props>> & Partial<RootDataWithoutProps<Props>>;
204
208
  type MappedItem = ComponentData;
205
209
  type Data<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultRootProps = DefaultRootProps> = {
206
210
  root: RootData<RootProps>;
package/dist/index.css CHANGED
@@ -1462,11 +1462,14 @@ textarea._Input-input_1qi5b_46 {
1462
1462
  }
1463
1463
 
1464
1464
  /* css-module:/home/runner/work/puck/puck/packages/core/components/Puck/components/Fields/styles.module.css/#css-module-data */
1465
- ._PuckFields_17k3p_1 {
1465
+ ._PuckFields_1o0if_1 {
1466
1466
  position: relative;
1467
1467
  font-family: var(--puck-font-family);
1468
1468
  }
1469
- ._PuckFields-loadingOverlay_17k3p_6 {
1469
+ ._PuckFields--isLoading_1o0if_6 {
1470
+ min-height: 48px;
1471
+ }
1472
+ ._PuckFields-loadingOverlay_1o0if_10 {
1470
1473
  background: var(--puck-color-white);
1471
1474
  display: flex;
1472
1475
  justify-content: center;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { U as UiState, D as Data, A as AppState, C as Config, a as DefaultRootProps, I as ItemSelector, b as DropZoneProps, F as Field, V as Viewports, c as DefaultComponentProps, M as MappedItem, R as RootDataWithProps, d as RootData, e as ComponentData } from './Config-09628f3c.js';
2
- export { i as Adaptor, h as ArrayField, s as ArrayState, p as BaseData, B as BaseField, o as ComponentConfig, m as Content, k as CustomField, j as ExternalField, E as ExternalFieldWithAdaptor, l as Fields, r as ItemWithId, N as NumberField, O as ObjectField, P as PuckComponent, n as PuckContext, g as RadioField, q as RootDataWithoutProps, S as SelectField, T as TextField, f as TextareaField } from './Config-09628f3c.js';
1
+ import { U as UiState, D as Data, A as AppState, C as Config, a as DefaultRootProps, I as ItemSelector, b as DropZoneProps, F as Field, V as Viewports, c as DefaultComponentProps, M as MappedItem, R as RootDataWithProps, d as RootData, e as ComponentData } from './Config-25917005.js';
2
+ export { i as Adaptor, h as ArrayField, s as ArrayState, p as BaseData, B as BaseField, o as ComponentConfig, m as Content, k as CustomField, j as ExternalField, E as ExternalFieldWithAdaptor, l as Fields, r as ItemWithId, N as NumberField, O as ObjectField, P as PuckComponent, n as PuckContext, g as RadioField, q as RootDataWithoutProps, S as SelectField, T as TextField, f as TextareaField } from './Config-25917005.js';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
  import * as react from 'react';
5
5
  import { ReactNode, ReactElement, CSSProperties, SyntheticEvent } from 'react';
@@ -185,7 +185,7 @@ type Overrides = OverridesGeneric<{
185
185
  children: ReactNode;
186
186
  }>;
187
187
  headerActions: RenderFunc<{
188
- children?: ReactNode;
188
+ children: ReactNode;
189
189
  }>;
190
190
  preview: RenderFunc;
191
191
  fields: RenderFunc<{
@@ -232,7 +232,7 @@ type IframeConfig = {
232
232
  declare function Puck<UserConfig extends Config = Config>({ children, config, data: initialData, ui: initialUi, onChange, onPublish, plugins, overrides, renderHeader, renderHeaderActions, headerTitle, headerPath, viewports, iframe, dnd, }: {
233
233
  children?: ReactNode;
234
234
  config: UserConfig;
235
- data: Data;
235
+ data: Partial<Data>;
236
236
  ui?: Partial<UiState>;
237
237
  onChange?: (data: Data) => void;
238
238
  onPublish?: (data: Data) => void;
@@ -266,7 +266,7 @@ declare namespace Puck {
266
266
 
267
267
  declare function Render<UserConfig extends Config = Config>({ config, data, }: {
268
268
  config: UserConfig;
269
- data: Data;
269
+ data: Partial<Data>;
270
270
  }): react_jsx_runtime.JSX.Element;
271
271
 
272
272
  declare function migrate(data: Data): Data;
@@ -280,9 +280,9 @@ type PropTransform<Props extends DefaultComponentProps = DefaultComponentProps,
280
280
  [key: string]: any;
281
281
  }) => RootProps;
282
282
  }>;
283
- declare function transformProps<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultComponentProps = DefaultComponentProps>(data: Data, propTransforms: PropTransform<Props, RootProps>): Data;
283
+ declare function transformProps<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultComponentProps = DefaultComponentProps>(data: Partial<Data>, propTransforms: PropTransform<Props, RootProps>): Data;
284
284
 
285
- declare function resolveAllData(data: Data, config: Config, onResolveStart?: (item: MappedItem) => void, onResolveEnd?: (item: MappedItem) => void): Promise<{
285
+ declare function resolveAllData(data: Partial<Data>, config: Config, onResolveStart?: (item: MappedItem) => void, onResolveEnd?: (item: MappedItem) => void): Promise<{
286
286
  root: RootDataWithProps<DefaultRootProps> | RootData<DefaultRootProps>;
287
287
  content: any[];
288
288
  zones: Record<string, MappedItem[]>;