@measured/puck 0.11.0 → 0.12.0-canary.c85f82f

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -270,7 +270,7 @@ When the user interacts with this external field, they'll be presented with a li
270
270
 
271
271
  ## Dynamic prop resolution
272
272
 
273
- Dynamic prop resolution allows developers to resolve props for components without saving the data to the Puck data model.
273
+ Dynamic prop resolution allows developers to change the props for a component after the props have been changed by the user. This is useful for making third-party API calls, such as requesting the latest content from a headless CMS.
274
274
 
275
275
  ### resolveData()
276
276
 
@@ -0,0 +1,195 @@
1
+ import { CSSProperties, ReactElement, ReactNode } from 'react';
2
+ import * as react_jsx_runtime from 'react/jsx-runtime';
3
+
4
+ type ItemSelector = {
5
+ index: number;
6
+ zone?: string;
7
+ };
8
+
9
+ type DropZoneProps = {
10
+ zone: string;
11
+ style?: CSSProperties;
12
+ };
13
+ declare function DropZone(props: DropZoneProps): react_jsx_runtime.JSX.Element;
14
+
15
+ type WithPuckProps<Props> = Props & {
16
+ id: string;
17
+ };
18
+ type BaseField = {
19
+ label?: string;
20
+ };
21
+ type TextField = BaseField & {
22
+ type: "text" | "number" | "textarea";
23
+ };
24
+ type SelectField = BaseField & {
25
+ type: "select" | "radio";
26
+ options: {
27
+ label: string;
28
+ value: string | number | boolean;
29
+ }[];
30
+ };
31
+ type ArrayField<Props extends {
32
+ [key: string]: any;
33
+ } = {
34
+ [key: string]: any;
35
+ }> = BaseField & {
36
+ type: "array";
37
+ arrayFields: {
38
+ [SubPropName in keyof Props[0]]: Field<Props[0][SubPropName]>;
39
+ };
40
+ defaultItemProps?: Props[0];
41
+ getItemSummary?: (item: Props[0], index?: number) => string;
42
+ };
43
+ type Adaptor<AdaptorParams = {}, TableShape extends Record<string, any> = {}, PropShape = TableShape> = {
44
+ name: string;
45
+ fetchList: (adaptorParams?: AdaptorParams) => Promise<TableShape[] | null>;
46
+ mapProp?: (value: TableShape) => PropShape;
47
+ };
48
+ type ExternalFieldWithAdaptor<Props extends {
49
+ [key: string]: any;
50
+ } = {
51
+ [key: string]: any;
52
+ }> = BaseField & {
53
+ type: "external";
54
+ placeholder?: string;
55
+ adaptor: Adaptor<any, any, Props>;
56
+ adaptorParams?: object;
57
+ getItemSummary: (item: Props, index?: number) => string;
58
+ };
59
+ type ExternalField<Props extends {
60
+ [key: string]: any;
61
+ } = {
62
+ [key: string]: any;
63
+ }> = BaseField & {
64
+ type: "external";
65
+ placeholder?: string;
66
+ fetchList: () => Promise<any[] | null>;
67
+ mapProp?: (value: any) => Props;
68
+ getItemSummary: (item: Props, index?: number) => string;
69
+ };
70
+ type CustomField<Props extends {
71
+ [key: string]: any;
72
+ } = {
73
+ [key: string]: any;
74
+ }> = BaseField & {
75
+ type: "custom";
76
+ render: (props: {
77
+ field: CustomField;
78
+ name: string;
79
+ value: any;
80
+ onChange: (value: Props) => void;
81
+ readOnly?: boolean;
82
+ }) => ReactElement;
83
+ };
84
+ type Field<Props extends {
85
+ [key: string]: any;
86
+ } = {
87
+ [key: string]: any;
88
+ }> = TextField | SelectField | ArrayField<Props> | ExternalField<Props> | ExternalFieldWithAdaptor<Props> | CustomField;
89
+ type DefaultRootProps = {
90
+ title?: string;
91
+ [key: string]: any;
92
+ };
93
+ type DefaultComponentProps = {
94
+ [key: string]: any;
95
+ editMode?: boolean;
96
+ };
97
+ type Fields<ComponentProps extends DefaultComponentProps = DefaultComponentProps> = {
98
+ [PropName in keyof Omit<Required<ComponentProps>, "children" | "editMode">]: Field<ComponentProps[PropName]>;
99
+ };
100
+ type Content<Props extends {
101
+ [key: string]: any;
102
+ } = {
103
+ [key: string]: any;
104
+ }> = ComponentData<Props>[];
105
+ type PuckComponent<Props extends DefaultComponentProps = DefaultComponentProps> = (props: WithPuckProps<Props & {
106
+ puck: PuckContext;
107
+ }>) => JSX.Element;
108
+ type PuckContext = {
109
+ renderDropZone: typeof DropZone;
110
+ };
111
+ type ComponentConfig<ComponentProps extends DefaultComponentProps = DefaultComponentProps, DefaultProps = ComponentProps, DataShape = ComponentData<ComponentProps>> = {
112
+ render: PuckComponent<ComponentProps>;
113
+ defaultProps?: DefaultProps;
114
+ fields?: Fields<ComponentProps>;
115
+ resolveData?: (data: DataShape, params: {
116
+ changed: Partial<Record<keyof ComponentProps, boolean>>;
117
+ }) => Promise<Partial<ComponentDataWithOptionalProps<ComponentProps>>> | Partial<ComponentDataWithOptionalProps<ComponentProps>>;
118
+ };
119
+ type Category<ComponentName> = {
120
+ components?: ComponentName[];
121
+ title?: string;
122
+ visible?: boolean;
123
+ defaultExpanded?: boolean;
124
+ };
125
+ type Config<Props extends {
126
+ [key: string]: any;
127
+ } = {
128
+ [key: string]: any;
129
+ }, RootProps extends DefaultRootProps = DefaultRootProps, CategoryName extends string = string> = {
130
+ categories?: Record<CategoryName, Category<keyof Props>> & {
131
+ other?: Category<Props>;
132
+ };
133
+ components: {
134
+ [ComponentName in keyof Props]: Omit<ComponentConfig<Props[ComponentName], Props[ComponentName]>, "type">;
135
+ };
136
+ root?: Partial<ComponentConfig<RootProps & {
137
+ children: ReactNode;
138
+ }, Partial<RootProps & {
139
+ children: ReactNode;
140
+ }>, RootDataWithProps<RootProps>>>;
141
+ };
142
+ type BaseData<Props extends {
143
+ [key: string]: any;
144
+ } = {
145
+ [key: string]: any;
146
+ }> = {
147
+ readOnly?: Partial<Record<keyof Props, boolean>>;
148
+ };
149
+ type ComponentData<Props extends DefaultComponentProps = DefaultComponentProps> = {
150
+ type: keyof Props;
151
+ props: WithPuckProps<Props>;
152
+ } & BaseData<Props>;
153
+ type RootDataWithProps<Props extends DefaultRootProps = DefaultRootProps> = {
154
+ props: Props;
155
+ };
156
+ type RootDataWithoutProps<Props extends DefaultRootProps = DefaultRootProps> = Props;
157
+ type RootData<Props extends DefaultRootProps = DefaultRootProps> = BaseData<Props> & Partial<RootDataWithProps<Props>> & Partial<RootDataWithoutProps<Props>>;
158
+ type ComponentDataWithOptionalProps<Props extends {
159
+ [key: string]: any;
160
+ } = {
161
+ [key: string]: any;
162
+ }> = Omit<ComponentData, "props"> & {
163
+ props: Partial<WithPuckProps<Props>>;
164
+ };
165
+ type MappedItem = ComponentData;
166
+ type Data<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultRootProps = DefaultRootProps> = {
167
+ root: RootData<RootProps>;
168
+ content: Content<WithPuckProps<Props>>;
169
+ zones?: Record<string, Content<WithPuckProps<Props>>>;
170
+ };
171
+ type ItemWithId = {
172
+ _arrayId: string;
173
+ data: any;
174
+ };
175
+ type ArrayState = {
176
+ items: ItemWithId[];
177
+ openId: string;
178
+ };
179
+ type UiState = {
180
+ leftSideBarVisible: boolean;
181
+ itemSelector: ItemSelector | null;
182
+ arrayState: Record<string, ArrayState | undefined>;
183
+ componentList: Record<string, {
184
+ components?: string[];
185
+ title?: string;
186
+ visible?: boolean;
187
+ expanded?: boolean;
188
+ }>;
189
+ };
190
+ type AppState = {
191
+ data: Data;
192
+ ui: UiState;
193
+ };
194
+
195
+ 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, PuckComponent as P, RootDataWithProps as R, SelectField as S, TextField as T, UiState as U, DefaultRootProps as a, RootData as b, ArrayField as c, Adaptor as d, ExternalField as e, CustomField as f, DefaultComponentProps as g, Fields as h, Content as i, PuckContext as j, ComponentConfig as k, BaseData as l, ComponentData as m, RootDataWithoutProps as n, ItemWithId as o, ArrayState as p, DropZone as q };
package/dist/index.d.ts CHANGED
@@ -1,203 +1,9 @@
1
- import * as react from 'react';
2
- import { ReactElement, ReactNode, CSSProperties } from 'react';
1
+ import { U as UiState, D as Data, A as AppState, C as Config, I as ItemSelector, M as MappedItem, R as RootDataWithProps, a as DefaultRootProps, b as RootData } from './Config-60a50493.js';
2
+ export { d as Adaptor, c as ArrayField, p as ArrayState, l as BaseData, B as BaseField, k as ComponentConfig, m as ComponentData, i as Content, f as CustomField, g as DefaultComponentProps, q as DropZone, e as ExternalField, E as ExternalFieldWithAdaptor, F as Field, h as Fields, o as ItemWithId, P as PuckComponent, j as PuckContext, n as RootDataWithoutProps, S as SelectField, T as TextField } from './Config-60a50493.js';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
- import { DragStart, DragUpdate } from 'react-beautiful-dnd';
5
-
6
- type ItemSelector = {
7
- index: number;
8
- zone?: string;
9
- };
10
-
11
- type WithPuckProps<Props> = Props & {
12
- id: string;
13
- };
14
- type BaseField = {
15
- label?: string;
16
- };
17
- type TextField = BaseField & {
18
- type: "text" | "number" | "textarea";
19
- };
20
- type SelectField = BaseField & {
21
- type: "select" | "radio";
22
- options: {
23
- label: string;
24
- value: string | number | boolean;
25
- }[];
26
- };
27
- type ArrayField<Props extends {
28
- [key: string]: any;
29
- } = {
30
- [key: string]: any;
31
- }> = BaseField & {
32
- type: "array";
33
- arrayFields: {
34
- [SubPropName in keyof Props[0]]: Field<Props[0][SubPropName]>;
35
- };
36
- defaultItemProps?: Props[0];
37
- getItemSummary?: (item: Props[0], index?: number) => string;
38
- };
39
- type Adaptor<AdaptorParams = {}, TableShape extends Record<string, any> = {}, PropShape = TableShape> = {
40
- name: string;
41
- fetchList: (adaptorParams?: AdaptorParams) => Promise<TableShape[] | null>;
42
- mapProp?: (value: TableShape) => PropShape;
43
- };
44
- type ExternalFieldWithAdaptor<Props extends {
45
- [key: string]: any;
46
- } = {
47
- [key: string]: any;
48
- }> = BaseField & {
49
- type: "external";
50
- placeholder?: string;
51
- adaptor: Adaptor<any, any, Props>;
52
- adaptorParams?: object;
53
- getItemSummary: (item: Props, index?: number) => string;
54
- };
55
- type ExternalField<Props extends {
56
- [key: string]: any;
57
- } = {
58
- [key: string]: any;
59
- }> = BaseField & {
60
- type: "external";
61
- placeholder?: string;
62
- fetchList: () => Promise<any[] | null>;
63
- mapProp?: (value: any) => Props;
64
- getItemSummary: (item: Props, index?: number) => string;
65
- };
66
- type CustomField<Props extends {
67
- [key: string]: any;
68
- } = {
69
- [key: string]: any;
70
- }> = BaseField & {
71
- type: "custom";
72
- render: (props: {
73
- field: CustomField;
74
- name: string;
75
- value: any;
76
- onChange: (value: Props) => void;
77
- readOnly?: boolean;
78
- }) => ReactElement;
79
- };
80
- type Field<Props extends {
81
- [key: string]: any;
82
- } = {
83
- [key: string]: any;
84
- }> = TextField | SelectField | ArrayField<Props> | ExternalField<Props> | ExternalFieldWithAdaptor<Props> | CustomField;
85
- type DefaultRootProps = {
86
- title?: string;
87
- [key: string]: any;
88
- };
89
- type DefaultRootRenderProps = {
90
- editMode: boolean;
91
- } & DefaultRootProps;
92
- type DefaultComponentProps = {
93
- [key: string]: any;
94
- editMode?: boolean;
95
- };
96
- type Fields<ComponentProps extends DefaultComponentProps = DefaultComponentProps> = {
97
- [PropName in keyof Omit<Required<ComponentProps>, "children" | "editMode">]: Field<ComponentProps[PropName]>;
98
- };
99
- type Content<Props extends {
100
- [key: string]: any;
101
- } = {
102
- [key: string]: any;
103
- }> = ComponentData<Props>[];
104
- type ComponentConfig<ComponentProps extends DefaultComponentProps = DefaultComponentProps, DefaultProps = ComponentProps, DataShape = ComponentData<ComponentProps>> = {
105
- render: (props: WithPuckProps<ComponentProps>) => ReactElement;
106
- defaultProps?: DefaultProps;
107
- fields?: Fields<ComponentProps>;
108
- resolveData?: (data: DataShape, params: {
109
- changed: Partial<Record<keyof ComponentProps, boolean>>;
110
- }) => Promise<Partial<ComponentDataWithOptionalProps<ComponentProps>>> | Partial<ComponentDataWithOptionalProps<ComponentProps>>;
111
- };
112
- type Category<ComponentName> = {
113
- components?: ComponentName[];
114
- title?: string;
115
- visible?: boolean;
116
- defaultExpanded?: boolean;
117
- };
118
- type Config<Props extends {
119
- [key: string]: any;
120
- } = {
121
- [key: string]: any;
122
- }, RootProps extends DefaultRootProps = DefaultRootProps, CategoryName extends string = string> = {
123
- categories?: Record<CategoryName, Category<keyof Props>> & {
124
- other?: Category<Props>;
125
- };
126
- components: {
127
- [ComponentName in keyof Props]: Omit<ComponentConfig<Props[ComponentName], Props[ComponentName]>, "type">;
128
- };
129
- root?: Partial<ComponentConfig<RootProps & {
130
- children: ReactNode;
131
- }, Partial<RootProps & {
132
- children: ReactNode;
133
- }>, RootDataWithProps<RootProps>>>;
134
- };
135
- type BaseData<Props extends {
136
- [key: string]: any;
137
- } = {
138
- [key: string]: any;
139
- }> = {
140
- readOnly?: Partial<Record<keyof Props, boolean>>;
141
- };
142
- type ComponentData<Props extends DefaultComponentProps = DefaultComponentProps> = {
143
- type: keyof Props;
144
- props: WithPuckProps<Props>;
145
- } & BaseData<Props>;
146
- type RootDataWithProps<Props extends DefaultRootProps = DefaultRootProps> = {
147
- props: Props;
148
- };
149
- type RootDataWithoutProps<Props extends DefaultRootProps = DefaultRootProps> = Props;
150
- type RootData<Props extends DefaultRootProps = DefaultRootProps> = BaseData<Props> & Partial<RootDataWithProps<Props>> & Partial<RootDataWithoutProps<Props>>;
151
- type ComponentDataWithOptionalProps<Props extends {
152
- [key: string]: any;
153
- } = {
154
- [key: string]: any;
155
- }> = Omit<ComponentData, "props"> & {
156
- props: Partial<WithPuckProps<Props>>;
157
- };
158
- type MappedItem = ComponentData;
159
- type Data<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultRootProps = DefaultRootProps> = {
160
- root: RootData<RootProps>;
161
- content: Content<WithPuckProps<Props>>;
162
- zones?: Record<string, Content<WithPuckProps<Props>>>;
163
- };
164
- type ItemWithId = {
165
- _arrayId: string;
166
- data: any;
167
- };
168
- type ArrayState = {
169
- items: ItemWithId[];
170
- openId: string;
171
- };
172
- type UiState = {
173
- leftSideBarVisible: boolean;
174
- itemSelector: ItemSelector | null;
175
- arrayState: Record<string, ArrayState | undefined>;
176
- componentList: Record<string, {
177
- components?: string[];
178
- title?: string;
179
- visible?: boolean;
180
- expanded?: boolean;
181
- }>;
182
- };
183
- type AppState = {
184
- data: Data;
185
- ui: UiState;
186
- };
187
-
188
- declare const Button: ({ children, href, onClick, variant, type, disabled, tabIndex, newTab, fullWidth, icon, size, }: {
189
- children: ReactNode;
190
- href?: string | undefined;
191
- onClick?: ((e: any) => void | Promise<void>) | undefined;
192
- variant?: "primary" | "secondary" | undefined;
193
- type?: "button" | "submit" | "reset" | undefined;
194
- disabled?: boolean | undefined;
195
- tabIndex?: number | undefined;
196
- newTab?: boolean | undefined;
197
- fullWidth?: boolean | undefined;
198
- icon?: ReactNode;
199
- size?: "medium" | "large" | undefined;
200
- }) => react_jsx_runtime.JSX.Element;
4
+ import * as react from 'react';
5
+ import { ReactNode, CSSProperties, ReactElement } from 'react';
6
+ import { DragStart, DragUpdate } from '@hello-pangea/dnd';
201
7
 
202
8
  type InsertAction = {
203
9
  type: "insert";
@@ -293,18 +99,26 @@ declare const DropZoneProvider: ({ children, value, }: {
293
99
  value: DropZoneContext;
294
100
  }) => react_jsx_runtime.JSX.Element;
295
101
 
296
- type DropZoneProps = {
297
- zone: string;
298
- style?: CSSProperties;
299
- };
300
- declare function DropZone(props: DropZoneProps): react_jsx_runtime.JSX.Element;
102
+ declare const Button: ({ children, href, onClick, variant, type, disabled, tabIndex, newTab, fullWidth, icon, size, }: {
103
+ children: ReactNode;
104
+ href?: string | undefined;
105
+ onClick?: ((e: any) => void | Promise<void>) | undefined;
106
+ variant?: "primary" | "secondary" | undefined;
107
+ type?: "reset" | "submit" | "button" | undefined;
108
+ disabled?: boolean | undefined;
109
+ tabIndex?: number | undefined;
110
+ newTab?: boolean | undefined;
111
+ fullWidth?: boolean | undefined;
112
+ icon?: ReactNode;
113
+ size?: "medium" | "large" | undefined;
114
+ }) => react_jsx_runtime.JSX.Element;
301
115
 
302
116
  declare const IconButton: ({ children, href, onClick, variant, type, disabled, tabIndex, newTab, fullWidth, title, }: {
303
117
  children: ReactNode;
304
118
  href?: string | undefined;
305
119
  onClick?: ((e: any) => void | Promise<void>) | undefined;
306
120
  variant?: "primary" | "secondary" | undefined;
307
- type?: "button" | "submit" | "reset" | undefined;
121
+ type?: "reset" | "submit" | "button" | undefined;
308
122
  disabled?: boolean | undefined;
309
123
  tabIndex?: number | undefined;
310
124
  newTab?: boolean | undefined;
@@ -369,9 +183,9 @@ declare const FieldLabel: ({ children, icon, label, el, readOnly, className, }:
369
183
  children?: ReactNode;
370
184
  icon?: ReactNode;
371
185
  label: string;
372
- el?: "div" | "label" | undefined;
186
+ el?: "label" | "div" | undefined;
373
187
  readOnly?: boolean | undefined;
374
188
  className?: string | undefined;
375
189
  }) => react_jsx_runtime.JSX.Element;
376
190
 
377
- export { Adaptor, AppState, ArrayField, ArrayState, BaseData, BaseField, Button, ComponentConfig, ComponentData, Config, Content, CustomField, Data, DefaultComponentProps, DefaultRootProps, DefaultRootRenderProps, DropZone, DropZoneProvider, ExternalField, ExternalFieldWithAdaptor, Field, FieldLabel, Fields, IconButton, ItemWithId, MappedItem, Puck, Render, RootData, RootDataWithProps, RootDataWithoutProps, SelectField, TextField, UiState, dropZoneContext, resolveAllData };
191
+ export { AppState, Button, Config, Data, DefaultRootProps, DropZoneProvider, FieldLabel, IconButton, MappedItem, Puck, Render, RootData, RootDataWithProps, UiState, dropZoneContext, resolveAllData };