@measured/puck 0.19.0-canary.56f23e8 → 0.19.0-canary.5bf4fccf
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.
- package/README.md +2 -4
- package/dist/chunk-COT3ZFIM.mjs +576 -0
- package/dist/index.css +82 -67
- package/dist/index.d.mts +113 -120
- package/dist/index.d.ts +113 -120
- package/dist/index.js +2310 -1731
- package/dist/index.mjs +1957 -1630
- package/dist/rsc.d.mts +2 -2
- package/dist/rsc.d.ts +2 -2
- package/dist/rsc.js +329 -135
- package/dist/rsc.mjs +7 -104
- package/dist/{resolve-all-data-DleIzc4N.d.mts → walk-tree-CM-cu7GU.d.mts} +105 -26
- package/dist/{resolve-all-data-DleIzc4N.d.ts → walk-tree-CM-cu7GU.d.ts} +105 -26
- package/package.json +4 -4
- package/dist/chunk-T6VJEBJD.mjs +0 -272
@@ -1,4 +1,4 @@
|
|
1
|
-
import { CSSProperties, ReactElement,
|
1
|
+
import { CSSProperties, ReactElement, ReactNode, JSX } from 'react';
|
2
2
|
|
3
3
|
type ItemSelector = {
|
4
4
|
index: number;
|
@@ -23,6 +23,7 @@ type FieldOptions = Array<FieldOption> | ReadonlyArray<FieldOption>;
|
|
23
23
|
type BaseField = {
|
24
24
|
label?: string;
|
25
25
|
labelIcon?: ReactElement;
|
26
|
+
metadata?: Metadata;
|
26
27
|
};
|
27
28
|
type TextField = BaseField & {
|
28
29
|
type: "text";
|
@@ -109,16 +110,22 @@ type ExternalField<Props extends {
|
|
109
110
|
filterFields?: Record<string, Field>;
|
110
111
|
initialFilters?: Record<string, any>;
|
111
112
|
};
|
112
|
-
type
|
113
|
+
type CustomFieldRender<Value extends any> = (props: {
|
114
|
+
field: CustomField<Value>;
|
115
|
+
name: string;
|
116
|
+
id: string;
|
117
|
+
value: Value;
|
118
|
+
onChange: (value: Value) => void;
|
119
|
+
readOnly?: boolean;
|
120
|
+
}) => ReactElement;
|
121
|
+
type CustomField<Value extends any> = BaseField & {
|
113
122
|
type: "custom";
|
114
|
-
render:
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
readOnly?: boolean;
|
121
|
-
}) => ReactElement;
|
123
|
+
render: CustomFieldRender<Value>;
|
124
|
+
};
|
125
|
+
type SlotField = BaseField & {
|
126
|
+
type: "slot";
|
127
|
+
allow?: string[];
|
128
|
+
disallow?: string[];
|
122
129
|
};
|
123
130
|
type Field<Props extends any = any> = TextField | NumberField | TextareaField | SelectField | RadioField | ArrayField<Props extends {
|
124
131
|
[key: string]: any;
|
@@ -128,7 +135,7 @@ type Field<Props extends any = any> = TextField | NumberField | TextareaField |
|
|
128
135
|
[key: string]: any;
|
129
136
|
} ? Props : any> | ExternalFieldWithAdaptor<Props extends {
|
130
137
|
[key: string]: any;
|
131
|
-
} ? Props : any> | CustomField<Props
|
138
|
+
} ? Props : any> | CustomField<Props> | SlotField;
|
132
139
|
type Fields<ComponentProps extends DefaultComponentProps = DefaultComponentProps> = {
|
133
140
|
[PropName in keyof Omit<ComponentProps, "editMode">]: Field<ComponentProps[PropName]>;
|
134
141
|
};
|
@@ -140,7 +147,10 @@ type FieldProps<F = Field<any>, ValueType = any> = {
|
|
140
147
|
readOnly?: boolean;
|
141
148
|
};
|
142
149
|
|
143
|
-
type PuckComponent<Props> = (props: WithId<WithPuckProps<
|
150
|
+
type PuckComponent<Props> = (props: WithId<WithPuckProps<{
|
151
|
+
[PropName in keyof Props]: Props[PropName] extends Slot ? (props?: Omit<DropZoneProps, "zone">) => ReactNode : Props[PropName];
|
152
|
+
}>>) => JSX.Element;
|
153
|
+
type ResolveDataTrigger = "insert" | "replace" | "load" | "force";
|
144
154
|
type ComponentConfig<RenderProps extends DefaultComponentProps = DefaultComponentProps, FieldProps extends DefaultComponentProps = RenderProps, DataShape = Omit<ComponentData<FieldProps>, "type">> = {
|
145
155
|
render: PuckComponent<RenderProps>;
|
146
156
|
label?: string;
|
@@ -149,7 +159,9 @@ type ComponentConfig<RenderProps extends DefaultComponentProps = DefaultComponen
|
|
149
159
|
permissions?: Partial<Permissions>;
|
150
160
|
inline?: boolean;
|
151
161
|
resolveFields?: (data: DataShape, params: {
|
152
|
-
changed: Partial<Record<keyof FieldProps, boolean
|
162
|
+
changed: Partial<Record<keyof FieldProps, boolean> & {
|
163
|
+
id: string;
|
164
|
+
}>;
|
153
165
|
fields: Fields<FieldProps>;
|
154
166
|
lastFields: Fields<FieldProps>;
|
155
167
|
lastData: DataShape | null;
|
@@ -157,9 +169,12 @@ type ComponentConfig<RenderProps extends DefaultComponentProps = DefaultComponen
|
|
157
169
|
parent: ComponentData | null;
|
158
170
|
}) => Promise<Fields<FieldProps>> | Fields<FieldProps>;
|
159
171
|
resolveData?: (data: DataShape, params: {
|
160
|
-
changed: Partial<Record<keyof FieldProps, boolean
|
172
|
+
changed: Partial<Record<keyof FieldProps, boolean> & {
|
173
|
+
id: string;
|
174
|
+
}>;
|
161
175
|
lastData: DataShape | null;
|
162
176
|
metadata: Metadata;
|
177
|
+
trigger: ResolveDataTrigger;
|
163
178
|
}) => Promise<{
|
164
179
|
props?: Partial<FieldProps>;
|
165
180
|
readOnly?: Partial<Record<keyof FieldProps, boolean>>;
|
@@ -168,13 +183,17 @@ type ComponentConfig<RenderProps extends DefaultComponentProps = DefaultComponen
|
|
168
183
|
readOnly?: Partial<Record<keyof FieldProps, boolean>>;
|
169
184
|
};
|
170
185
|
resolvePermissions?: (data: DataShape, params: {
|
171
|
-
changed: Partial<Record<keyof FieldProps, boolean
|
186
|
+
changed: Partial<Record<keyof FieldProps, boolean> & {
|
187
|
+
id: string;
|
188
|
+
}>;
|
172
189
|
lastPermissions: Partial<Permissions>;
|
173
190
|
permissions: Partial<Permissions>;
|
174
191
|
appState: AppState;
|
175
192
|
lastData: DataShape | null;
|
176
193
|
}) => Promise<Partial<Permissions>> | Partial<Permissions>;
|
194
|
+
metadata?: Metadata;
|
177
195
|
};
|
196
|
+
type RootConfig<RootProps extends DefaultComponentProps = any> = Partial<ComponentConfig<WithChildren<RootProps>, AsFieldProps<RootProps>, RootData<AsFieldProps<RootProps>>>>;
|
178
197
|
type Category<ComponentName> = {
|
179
198
|
components?: ComponentName[];
|
180
199
|
title?: string;
|
@@ -188,7 +207,7 @@ type Config<Props extends DefaultComponentProps = DefaultComponentProps, RootPro
|
|
188
207
|
components: {
|
189
208
|
[ComponentName in keyof Props]: Omit<ComponentConfig<Props[ComponentName], Props[ComponentName]>, "type">;
|
190
209
|
};
|
191
|
-
root?:
|
210
|
+
root?: RootConfig<RootProps>;
|
192
211
|
};
|
193
212
|
|
194
213
|
type WithId<Props> = Props & {
|
@@ -204,7 +223,7 @@ type WithChildren<Props> = Props & {
|
|
204
223
|
};
|
205
224
|
type ExtractPropsFromConfig<UserConfig> = UserConfig extends Config<infer P, any, any> ? P : never;
|
206
225
|
type ExtractRootPropsFromConfig<UserConfig> = UserConfig extends Config<any, infer P, any> ? P : never;
|
207
|
-
type UserGenerics<UserConfig extends Config = Config, UserProps extends ExtractPropsFromConfig<UserConfig> = ExtractPropsFromConfig<UserConfig>, UserRootProps extends ExtractRootPropsFromConfig<UserConfig> = ExtractRootPropsFromConfig<UserConfig>, UserData extends Data<UserProps, UserRootProps> | Data = Data<UserProps, UserRootProps>, UserAppState extends
|
226
|
+
type UserGenerics<UserConfig extends Config = Config, UserProps extends ExtractPropsFromConfig<UserConfig> = ExtractPropsFromConfig<UserConfig>, UserRootProps extends ExtractRootPropsFromConfig<UserConfig> = ExtractRootPropsFromConfig<UserConfig>, UserData extends Data<UserProps, UserRootProps> | Data = Data<UserProps, UserRootProps>, UserAppState extends PrivateAppState<UserData> = PrivateAppState<UserData>, UserComponentData extends ComponentData = UserData["content"][0]> = {
|
208
227
|
UserConfig: UserConfig;
|
209
228
|
UserProps: UserProps;
|
210
229
|
UserRootProps: UserRootProps;
|
@@ -236,22 +255,28 @@ type BaseData<Props extends {
|
|
236
255
|
readOnly?: Partial<Record<keyof Props, boolean>>;
|
237
256
|
};
|
238
257
|
type RootDataWithProps<Props extends DefaultComponentProps = DefaultRootFieldProps> = BaseData<Props> & {
|
239
|
-
props: Props
|
258
|
+
props: WithPopulatedSlots<Props>;
|
240
259
|
};
|
241
260
|
type RootDataWithoutProps<Props extends DefaultComponentProps = DefaultRootFieldProps> = Props;
|
242
261
|
type RootData<Props extends DefaultComponentProps = DefaultRootFieldProps> = Partial<RootDataWithProps<AsFieldProps<Props>>> & Partial<RootDataWithoutProps<Props>>;
|
243
262
|
type ComponentData<Props extends DefaultComponentProps = DefaultComponentProps, Name = string> = {
|
244
263
|
type: Name;
|
245
|
-
props: WithId<Props
|
264
|
+
props: WithId<WithPopulatedSlots<Props>>;
|
265
|
+
} & BaseData<Props>;
|
266
|
+
type ComponentDataOptionalId<Props extends DefaultComponentProps = DefaultComponentProps, Name = string> = {
|
267
|
+
type: Name;
|
268
|
+
props: Props & {
|
269
|
+
id?: string;
|
270
|
+
};
|
246
271
|
} & BaseData<Props>;
|
247
272
|
type MappedItem = ComponentData;
|
248
273
|
type ComponentDataMap<Props extends Record<string, DefaultComponentProps> = DefaultComponentProps> = {
|
249
274
|
[K in keyof Props]: ComponentData<Props[K], K extends string ? K : never>;
|
250
275
|
}[keyof Props];
|
251
276
|
type Content<PropsMap extends {
|
252
|
-
[key: string]:
|
277
|
+
[key: string]: DefaultComponentProps;
|
253
278
|
} = {
|
254
|
-
[key: string]:
|
279
|
+
[key: string]: DefaultComponentProps;
|
255
280
|
}> = ComponentDataMap<PropsMap>[];
|
256
281
|
type Data<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultComponentProps = DefaultRootFieldProps> = {
|
257
282
|
root: RootData<RootProps>;
|
@@ -300,6 +325,30 @@ type AppState<UserData extends Data = Data> = {
|
|
300
325
|
ui: UiState;
|
301
326
|
};
|
302
327
|
|
328
|
+
type ZoneType = "root" | "dropzone" | "slot";
|
329
|
+
type PuckNodeData = {
|
330
|
+
data: ComponentData;
|
331
|
+
flatData: ComponentData;
|
332
|
+
parentId: string | null;
|
333
|
+
zone: string;
|
334
|
+
path: string[];
|
335
|
+
};
|
336
|
+
type PuckZoneData = {
|
337
|
+
contentIds: string[];
|
338
|
+
type: ZoneType;
|
339
|
+
};
|
340
|
+
type NodeIndex = Record<string, PuckNodeData>;
|
341
|
+
type ZoneIndex = Record<string, PuckZoneData>;
|
342
|
+
type PrivateAppState<UserData extends Data = Data> = AppState<UserData> & {
|
343
|
+
indexes: {
|
344
|
+
nodes: NodeIndex;
|
345
|
+
zones: ZoneIndex;
|
346
|
+
};
|
347
|
+
};
|
348
|
+
type WithPopulatedSlots<Props extends DefaultComponentProps = DefaultComponentProps, SlotProps extends DefaultComponentProps = Props> = Props extends any ? any : {
|
349
|
+
[PropName in keyof Props]: Props[PropName] extends Slot<SlotProps> ? Content<SlotProps> : Props[PropName];
|
350
|
+
};
|
351
|
+
|
303
352
|
type RenderFunc<Props extends {
|
304
353
|
[key: string]: any;
|
305
354
|
} = {
|
@@ -406,6 +455,13 @@ type InitialHistoryNoAppend<AS = Partial<AppState>> = {
|
|
406
455
|
appendData?: false;
|
407
456
|
};
|
408
457
|
type InitialHistory<AS = Partial<AppState>> = InitialHistoryAppend<AS> | InitialHistoryNoAppend<AS>;
|
458
|
+
type Slot<Props extends {
|
459
|
+
[key: string]: DefaultComponentProps;
|
460
|
+
} = {
|
461
|
+
[key: string]: DefaultComponentProps;
|
462
|
+
}> = {
|
463
|
+
[K in keyof Props]: ComponentDataOptionalId<Props[K], K extends string ? K : never>;
|
464
|
+
}[keyof Props][];
|
409
465
|
|
410
466
|
type InsertAction = {
|
411
467
|
type: "insert";
|
@@ -419,11 +475,17 @@ type DuplicateAction = {
|
|
419
475
|
sourceIndex: number;
|
420
476
|
sourceZone: string;
|
421
477
|
};
|
422
|
-
type ReplaceAction = {
|
478
|
+
type ReplaceAction<UserData extends Data = Data> = {
|
423
479
|
type: "replace";
|
424
480
|
destinationIndex: number;
|
425
481
|
destinationZone: string;
|
426
|
-
data:
|
482
|
+
data: ComponentData;
|
483
|
+
ui?: Partial<AppState<UserData>["ui"]>;
|
484
|
+
};
|
485
|
+
type ReplaceRootAction<UserData extends Data = Data> = {
|
486
|
+
type: "replaceRoot";
|
487
|
+
root: RootData;
|
488
|
+
ui?: Partial<AppState<UserData>["ui"]>;
|
427
489
|
};
|
428
490
|
type ReorderAction = {
|
429
491
|
type: "reorder";
|
@@ -453,7 +515,7 @@ type SetDataAction = {
|
|
453
515
|
};
|
454
516
|
type SetAction<UserData extends Data = Data> = {
|
455
517
|
type: "set";
|
456
|
-
state: Partial<
|
518
|
+
state: Partial<PrivateAppState<UserData>> | ((previous: PrivateAppState<UserData>) => Partial<PrivateAppState<UserData>>);
|
457
519
|
};
|
458
520
|
type RegisterZoneAction = {
|
459
521
|
type: "registerZone";
|
@@ -465,8 +527,25 @@ type UnregisterZoneAction = {
|
|
465
527
|
};
|
466
528
|
type PuckAction = {
|
467
529
|
recordHistory?: boolean;
|
468
|
-
} & (ReorderAction | InsertAction | MoveAction | ReplaceAction | RemoveAction | DuplicateAction | SetAction | SetDataAction | SetUiAction | RegisterZoneAction | UnregisterZoneAction);
|
530
|
+
} & (ReorderAction | InsertAction | MoveAction | ReplaceAction | ReplaceRootAction | RemoveAction | DuplicateAction | SetAction | SetDataAction | SetUiAction | RegisterZoneAction | UnregisterZoneAction);
|
531
|
+
|
532
|
+
type PropTransform<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultComponentProps = DefaultRootFieldProps> = Partial<{
|
533
|
+
[ComponentName in keyof Props]: (props: Props[ComponentName] & {
|
534
|
+
[key: string]: any;
|
535
|
+
}) => Props[ComponentName];
|
536
|
+
} & {
|
537
|
+
root: (props: RootProps & {
|
538
|
+
[key: string]: any;
|
539
|
+
}) => RootProps;
|
540
|
+
}>;
|
541
|
+
declare function transformProps<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultComponentProps = DefaultRootFieldProps>(data: Partial<Data>, propTransforms: PropTransform<Props, RootProps>): Data;
|
469
542
|
|
470
543
|
declare function resolveAllData<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends Record<string, any> = DefaultRootFieldProps>(data: Partial<Data>, config: Config, metadata?: Metadata, onResolveStart?: (item: ComponentData) => void, onResolveEnd?: (item: ComponentData) => void): Promise<Data<Props, RootProps>>;
|
471
544
|
|
472
|
-
|
545
|
+
type WalkTreeOptions = {
|
546
|
+
parentId: string;
|
547
|
+
propName: string;
|
548
|
+
};
|
549
|
+
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;
|
550
|
+
|
551
|
+
export { type ExternalField as $, type AppState as A, type BaseData as B, type ComponentData as C, type DropZoneProps as D, type MappedItem as E, type Fields as F, type ComponentDataMap as G, type History as H, type IframeConfig as I, type Content as J, type BaseField as K, type TextareaField as L, type Metadata as M, type NumberField as N, type Overrides as O, type Permissions as P, type SelectField as Q, type RootDataWithProps as R, type Slot as S, type TextField as T, type UserGenerics as U, type Viewports as V, type RadioField as W, type ArrayField as X, type ObjectField as Y, type Adaptor as Z, type ExternalFieldWithAdaptor as _, type Config as a, type CustomFieldRender as a0, type CustomField as a1, type SlotField as a2, type PuckContext as a3, type DefaultRootFieldProps as a4, type DefaultRootRenderProps as a5, type DefaultRootProps as a6, type DefaultComponentProps as a7, type WithId as a8, type WithPuckProps as a9, type AsFieldProps as aa, type WithChildren as ab, type ExtractPropsFromConfig as ac, type ExtractRootPropsFromConfig as ad, transformProps as ae, resolveAllData as af, type PuckAction as b, type ResolveDataTrigger as c, type Plugin as d, type UiState as e, type ComponentConfig as f, type Field as g, type FieldProps as h, type Data as i, type OnAction as j, type InitialHistory as k, type ItemSelector as l, type Direction as m, type DragAxis as n, type Viewport as o, overrideKeys as p, type OverrideKey as q, type FieldRenderFunctions as r, type ItemWithId as s, type ArrayState as t, type PuckComponent as u, type RootConfig as v, walkTree as w, type RootDataWithoutProps as x, type RootData as y, type ComponentDataOptionalId as z };
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { CSSProperties, ReactElement,
|
1
|
+
import { CSSProperties, ReactElement, ReactNode, JSX } from 'react';
|
2
2
|
|
3
3
|
type ItemSelector = {
|
4
4
|
index: number;
|
@@ -23,6 +23,7 @@ type FieldOptions = Array<FieldOption> | ReadonlyArray<FieldOption>;
|
|
23
23
|
type BaseField = {
|
24
24
|
label?: string;
|
25
25
|
labelIcon?: ReactElement;
|
26
|
+
metadata?: Metadata;
|
26
27
|
};
|
27
28
|
type TextField = BaseField & {
|
28
29
|
type: "text";
|
@@ -109,16 +110,22 @@ type ExternalField<Props extends {
|
|
109
110
|
filterFields?: Record<string, Field>;
|
110
111
|
initialFilters?: Record<string, any>;
|
111
112
|
};
|
112
|
-
type
|
113
|
+
type CustomFieldRender<Value extends any> = (props: {
|
114
|
+
field: CustomField<Value>;
|
115
|
+
name: string;
|
116
|
+
id: string;
|
117
|
+
value: Value;
|
118
|
+
onChange: (value: Value) => void;
|
119
|
+
readOnly?: boolean;
|
120
|
+
}) => ReactElement;
|
121
|
+
type CustomField<Value extends any> = BaseField & {
|
113
122
|
type: "custom";
|
114
|
-
render:
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
readOnly?: boolean;
|
121
|
-
}) => ReactElement;
|
123
|
+
render: CustomFieldRender<Value>;
|
124
|
+
};
|
125
|
+
type SlotField = BaseField & {
|
126
|
+
type: "slot";
|
127
|
+
allow?: string[];
|
128
|
+
disallow?: string[];
|
122
129
|
};
|
123
130
|
type Field<Props extends any = any> = TextField | NumberField | TextareaField | SelectField | RadioField | ArrayField<Props extends {
|
124
131
|
[key: string]: any;
|
@@ -128,7 +135,7 @@ type Field<Props extends any = any> = TextField | NumberField | TextareaField |
|
|
128
135
|
[key: string]: any;
|
129
136
|
} ? Props : any> | ExternalFieldWithAdaptor<Props extends {
|
130
137
|
[key: string]: any;
|
131
|
-
} ? Props : any> | CustomField<Props
|
138
|
+
} ? Props : any> | CustomField<Props> | SlotField;
|
132
139
|
type Fields<ComponentProps extends DefaultComponentProps = DefaultComponentProps> = {
|
133
140
|
[PropName in keyof Omit<ComponentProps, "editMode">]: Field<ComponentProps[PropName]>;
|
134
141
|
};
|
@@ -140,7 +147,10 @@ type FieldProps<F = Field<any>, ValueType = any> = {
|
|
140
147
|
readOnly?: boolean;
|
141
148
|
};
|
142
149
|
|
143
|
-
type PuckComponent<Props> = (props: WithId<WithPuckProps<
|
150
|
+
type PuckComponent<Props> = (props: WithId<WithPuckProps<{
|
151
|
+
[PropName in keyof Props]: Props[PropName] extends Slot ? (props?: Omit<DropZoneProps, "zone">) => ReactNode : Props[PropName];
|
152
|
+
}>>) => JSX.Element;
|
153
|
+
type ResolveDataTrigger = "insert" | "replace" | "load" | "force";
|
144
154
|
type ComponentConfig<RenderProps extends DefaultComponentProps = DefaultComponentProps, FieldProps extends DefaultComponentProps = RenderProps, DataShape = Omit<ComponentData<FieldProps>, "type">> = {
|
145
155
|
render: PuckComponent<RenderProps>;
|
146
156
|
label?: string;
|
@@ -149,7 +159,9 @@ type ComponentConfig<RenderProps extends DefaultComponentProps = DefaultComponen
|
|
149
159
|
permissions?: Partial<Permissions>;
|
150
160
|
inline?: boolean;
|
151
161
|
resolveFields?: (data: DataShape, params: {
|
152
|
-
changed: Partial<Record<keyof FieldProps, boolean
|
162
|
+
changed: Partial<Record<keyof FieldProps, boolean> & {
|
163
|
+
id: string;
|
164
|
+
}>;
|
153
165
|
fields: Fields<FieldProps>;
|
154
166
|
lastFields: Fields<FieldProps>;
|
155
167
|
lastData: DataShape | null;
|
@@ -157,9 +169,12 @@ type ComponentConfig<RenderProps extends DefaultComponentProps = DefaultComponen
|
|
157
169
|
parent: ComponentData | null;
|
158
170
|
}) => Promise<Fields<FieldProps>> | Fields<FieldProps>;
|
159
171
|
resolveData?: (data: DataShape, params: {
|
160
|
-
changed: Partial<Record<keyof FieldProps, boolean
|
172
|
+
changed: Partial<Record<keyof FieldProps, boolean> & {
|
173
|
+
id: string;
|
174
|
+
}>;
|
161
175
|
lastData: DataShape | null;
|
162
176
|
metadata: Metadata;
|
177
|
+
trigger: ResolveDataTrigger;
|
163
178
|
}) => Promise<{
|
164
179
|
props?: Partial<FieldProps>;
|
165
180
|
readOnly?: Partial<Record<keyof FieldProps, boolean>>;
|
@@ -168,13 +183,17 @@ type ComponentConfig<RenderProps extends DefaultComponentProps = DefaultComponen
|
|
168
183
|
readOnly?: Partial<Record<keyof FieldProps, boolean>>;
|
169
184
|
};
|
170
185
|
resolvePermissions?: (data: DataShape, params: {
|
171
|
-
changed: Partial<Record<keyof FieldProps, boolean
|
186
|
+
changed: Partial<Record<keyof FieldProps, boolean> & {
|
187
|
+
id: string;
|
188
|
+
}>;
|
172
189
|
lastPermissions: Partial<Permissions>;
|
173
190
|
permissions: Partial<Permissions>;
|
174
191
|
appState: AppState;
|
175
192
|
lastData: DataShape | null;
|
176
193
|
}) => Promise<Partial<Permissions>> | Partial<Permissions>;
|
194
|
+
metadata?: Metadata;
|
177
195
|
};
|
196
|
+
type RootConfig<RootProps extends DefaultComponentProps = any> = Partial<ComponentConfig<WithChildren<RootProps>, AsFieldProps<RootProps>, RootData<AsFieldProps<RootProps>>>>;
|
178
197
|
type Category<ComponentName> = {
|
179
198
|
components?: ComponentName[];
|
180
199
|
title?: string;
|
@@ -188,7 +207,7 @@ type Config<Props extends DefaultComponentProps = DefaultComponentProps, RootPro
|
|
188
207
|
components: {
|
189
208
|
[ComponentName in keyof Props]: Omit<ComponentConfig<Props[ComponentName], Props[ComponentName]>, "type">;
|
190
209
|
};
|
191
|
-
root?:
|
210
|
+
root?: RootConfig<RootProps>;
|
192
211
|
};
|
193
212
|
|
194
213
|
type WithId<Props> = Props & {
|
@@ -204,7 +223,7 @@ type WithChildren<Props> = Props & {
|
|
204
223
|
};
|
205
224
|
type ExtractPropsFromConfig<UserConfig> = UserConfig extends Config<infer P, any, any> ? P : never;
|
206
225
|
type ExtractRootPropsFromConfig<UserConfig> = UserConfig extends Config<any, infer P, any> ? P : never;
|
207
|
-
type UserGenerics<UserConfig extends Config = Config, UserProps extends ExtractPropsFromConfig<UserConfig> = ExtractPropsFromConfig<UserConfig>, UserRootProps extends ExtractRootPropsFromConfig<UserConfig> = ExtractRootPropsFromConfig<UserConfig>, UserData extends Data<UserProps, UserRootProps> | Data = Data<UserProps, UserRootProps>, UserAppState extends
|
226
|
+
type UserGenerics<UserConfig extends Config = Config, UserProps extends ExtractPropsFromConfig<UserConfig> = ExtractPropsFromConfig<UserConfig>, UserRootProps extends ExtractRootPropsFromConfig<UserConfig> = ExtractRootPropsFromConfig<UserConfig>, UserData extends Data<UserProps, UserRootProps> | Data = Data<UserProps, UserRootProps>, UserAppState extends PrivateAppState<UserData> = PrivateAppState<UserData>, UserComponentData extends ComponentData = UserData["content"][0]> = {
|
208
227
|
UserConfig: UserConfig;
|
209
228
|
UserProps: UserProps;
|
210
229
|
UserRootProps: UserRootProps;
|
@@ -236,22 +255,28 @@ type BaseData<Props extends {
|
|
236
255
|
readOnly?: Partial<Record<keyof Props, boolean>>;
|
237
256
|
};
|
238
257
|
type RootDataWithProps<Props extends DefaultComponentProps = DefaultRootFieldProps> = BaseData<Props> & {
|
239
|
-
props: Props
|
258
|
+
props: WithPopulatedSlots<Props>;
|
240
259
|
};
|
241
260
|
type RootDataWithoutProps<Props extends DefaultComponentProps = DefaultRootFieldProps> = Props;
|
242
261
|
type RootData<Props extends DefaultComponentProps = DefaultRootFieldProps> = Partial<RootDataWithProps<AsFieldProps<Props>>> & Partial<RootDataWithoutProps<Props>>;
|
243
262
|
type ComponentData<Props extends DefaultComponentProps = DefaultComponentProps, Name = string> = {
|
244
263
|
type: Name;
|
245
|
-
props: WithId<Props
|
264
|
+
props: WithId<WithPopulatedSlots<Props>>;
|
265
|
+
} & BaseData<Props>;
|
266
|
+
type ComponentDataOptionalId<Props extends DefaultComponentProps = DefaultComponentProps, Name = string> = {
|
267
|
+
type: Name;
|
268
|
+
props: Props & {
|
269
|
+
id?: string;
|
270
|
+
};
|
246
271
|
} & BaseData<Props>;
|
247
272
|
type MappedItem = ComponentData;
|
248
273
|
type ComponentDataMap<Props extends Record<string, DefaultComponentProps> = DefaultComponentProps> = {
|
249
274
|
[K in keyof Props]: ComponentData<Props[K], K extends string ? K : never>;
|
250
275
|
}[keyof Props];
|
251
276
|
type Content<PropsMap extends {
|
252
|
-
[key: string]:
|
277
|
+
[key: string]: DefaultComponentProps;
|
253
278
|
} = {
|
254
|
-
[key: string]:
|
279
|
+
[key: string]: DefaultComponentProps;
|
255
280
|
}> = ComponentDataMap<PropsMap>[];
|
256
281
|
type Data<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultComponentProps = DefaultRootFieldProps> = {
|
257
282
|
root: RootData<RootProps>;
|
@@ -300,6 +325,30 @@ type AppState<UserData extends Data = Data> = {
|
|
300
325
|
ui: UiState;
|
301
326
|
};
|
302
327
|
|
328
|
+
type ZoneType = "root" | "dropzone" | "slot";
|
329
|
+
type PuckNodeData = {
|
330
|
+
data: ComponentData;
|
331
|
+
flatData: ComponentData;
|
332
|
+
parentId: string | null;
|
333
|
+
zone: string;
|
334
|
+
path: string[];
|
335
|
+
};
|
336
|
+
type PuckZoneData = {
|
337
|
+
contentIds: string[];
|
338
|
+
type: ZoneType;
|
339
|
+
};
|
340
|
+
type NodeIndex = Record<string, PuckNodeData>;
|
341
|
+
type ZoneIndex = Record<string, PuckZoneData>;
|
342
|
+
type PrivateAppState<UserData extends Data = Data> = AppState<UserData> & {
|
343
|
+
indexes: {
|
344
|
+
nodes: NodeIndex;
|
345
|
+
zones: ZoneIndex;
|
346
|
+
};
|
347
|
+
};
|
348
|
+
type WithPopulatedSlots<Props extends DefaultComponentProps = DefaultComponentProps, SlotProps extends DefaultComponentProps = Props> = Props extends any ? any : {
|
349
|
+
[PropName in keyof Props]: Props[PropName] extends Slot<SlotProps> ? Content<SlotProps> : Props[PropName];
|
350
|
+
};
|
351
|
+
|
303
352
|
type RenderFunc<Props extends {
|
304
353
|
[key: string]: any;
|
305
354
|
} = {
|
@@ -406,6 +455,13 @@ type InitialHistoryNoAppend<AS = Partial<AppState>> = {
|
|
406
455
|
appendData?: false;
|
407
456
|
};
|
408
457
|
type InitialHistory<AS = Partial<AppState>> = InitialHistoryAppend<AS> | InitialHistoryNoAppend<AS>;
|
458
|
+
type Slot<Props extends {
|
459
|
+
[key: string]: DefaultComponentProps;
|
460
|
+
} = {
|
461
|
+
[key: string]: DefaultComponentProps;
|
462
|
+
}> = {
|
463
|
+
[K in keyof Props]: ComponentDataOptionalId<Props[K], K extends string ? K : never>;
|
464
|
+
}[keyof Props][];
|
409
465
|
|
410
466
|
type InsertAction = {
|
411
467
|
type: "insert";
|
@@ -419,11 +475,17 @@ type DuplicateAction = {
|
|
419
475
|
sourceIndex: number;
|
420
476
|
sourceZone: string;
|
421
477
|
};
|
422
|
-
type ReplaceAction = {
|
478
|
+
type ReplaceAction<UserData extends Data = Data> = {
|
423
479
|
type: "replace";
|
424
480
|
destinationIndex: number;
|
425
481
|
destinationZone: string;
|
426
|
-
data:
|
482
|
+
data: ComponentData;
|
483
|
+
ui?: Partial<AppState<UserData>["ui"]>;
|
484
|
+
};
|
485
|
+
type ReplaceRootAction<UserData extends Data = Data> = {
|
486
|
+
type: "replaceRoot";
|
487
|
+
root: RootData;
|
488
|
+
ui?: Partial<AppState<UserData>["ui"]>;
|
427
489
|
};
|
428
490
|
type ReorderAction = {
|
429
491
|
type: "reorder";
|
@@ -453,7 +515,7 @@ type SetDataAction = {
|
|
453
515
|
};
|
454
516
|
type SetAction<UserData extends Data = Data> = {
|
455
517
|
type: "set";
|
456
|
-
state: Partial<
|
518
|
+
state: Partial<PrivateAppState<UserData>> | ((previous: PrivateAppState<UserData>) => Partial<PrivateAppState<UserData>>);
|
457
519
|
};
|
458
520
|
type RegisterZoneAction = {
|
459
521
|
type: "registerZone";
|
@@ -465,8 +527,25 @@ type UnregisterZoneAction = {
|
|
465
527
|
};
|
466
528
|
type PuckAction = {
|
467
529
|
recordHistory?: boolean;
|
468
|
-
} & (ReorderAction | InsertAction | MoveAction | ReplaceAction | RemoveAction | DuplicateAction | SetAction | SetDataAction | SetUiAction | RegisterZoneAction | UnregisterZoneAction);
|
530
|
+
} & (ReorderAction | InsertAction | MoveAction | ReplaceAction | ReplaceRootAction | RemoveAction | DuplicateAction | SetAction | SetDataAction | SetUiAction | RegisterZoneAction | UnregisterZoneAction);
|
531
|
+
|
532
|
+
type PropTransform<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultComponentProps = DefaultRootFieldProps> = Partial<{
|
533
|
+
[ComponentName in keyof Props]: (props: Props[ComponentName] & {
|
534
|
+
[key: string]: any;
|
535
|
+
}) => Props[ComponentName];
|
536
|
+
} & {
|
537
|
+
root: (props: RootProps & {
|
538
|
+
[key: string]: any;
|
539
|
+
}) => RootProps;
|
540
|
+
}>;
|
541
|
+
declare function transformProps<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultComponentProps = DefaultRootFieldProps>(data: Partial<Data>, propTransforms: PropTransform<Props, RootProps>): Data;
|
469
542
|
|
470
543
|
declare function resolveAllData<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends Record<string, any> = DefaultRootFieldProps>(data: Partial<Data>, config: Config, metadata?: Metadata, onResolveStart?: (item: ComponentData) => void, onResolveEnd?: (item: ComponentData) => void): Promise<Data<Props, RootProps>>;
|
471
544
|
|
472
|
-
|
545
|
+
type WalkTreeOptions = {
|
546
|
+
parentId: string;
|
547
|
+
propName: string;
|
548
|
+
};
|
549
|
+
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;
|
550
|
+
|
551
|
+
export { type ExternalField as $, type AppState as A, type BaseData as B, type ComponentData as C, type DropZoneProps as D, type MappedItem as E, type Fields as F, type ComponentDataMap as G, type History as H, type IframeConfig as I, type Content as J, type BaseField as K, type TextareaField as L, type Metadata as M, type NumberField as N, type Overrides as O, type Permissions as P, type SelectField as Q, type RootDataWithProps as R, type Slot as S, type TextField as T, type UserGenerics as U, type Viewports as V, type RadioField as W, type ArrayField as X, type ObjectField as Y, type Adaptor as Z, type ExternalFieldWithAdaptor as _, type Config as a, type CustomFieldRender as a0, type CustomField as a1, type SlotField as a2, type PuckContext as a3, type DefaultRootFieldProps as a4, type DefaultRootRenderProps as a5, type DefaultRootProps as a6, type DefaultComponentProps as a7, type WithId as a8, type WithPuckProps as a9, type AsFieldProps as aa, type WithChildren as ab, type ExtractPropsFromConfig as ac, type ExtractRootPropsFromConfig as ad, transformProps as ae, resolveAllData as af, type PuckAction as b, type ResolveDataTrigger as c, type Plugin as d, type UiState as e, type ComponentConfig as f, type Field as g, type FieldProps as h, type Data as i, type OnAction as j, type InitialHistory as k, type ItemSelector as l, type Direction as m, type DragAxis as n, type Viewport as o, overrideKeys as p, type OverrideKey as q, type FieldRenderFunctions as r, type ItemWithId as s, type ArrayState as t, type PuckComponent as u, type RootConfig as v, walkTree as w, type RootDataWithoutProps as x, type RootData as y, type ComponentDataOptionalId as z };
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@measured/puck",
|
3
|
-
"version": "0.19.0-canary.
|
4
|
-
"author": "
|
3
|
+
"version": "0.19.0-canary.5bf4fccf",
|
4
|
+
"author": "Chris Villa <chris@puckeditor.com>",
|
5
5
|
"repository": "measuredco/puck",
|
6
6
|
"bugs": "https://github.com/measuredco/puck/issues",
|
7
7
|
"homepage": "https://puckeditor.com",
|
@@ -77,9 +77,9 @@
|
|
77
77
|
"react-hotkeys-hook": "^4.6.1",
|
78
78
|
"use-debounce": "^9.0.4",
|
79
79
|
"uuid": "^9.0.1",
|
80
|
-
"zustand": "^
|
80
|
+
"zustand": "^5.0.3"
|
81
81
|
},
|
82
82
|
"peerDependencies": {
|
83
|
-
"react": "^
|
83
|
+
"react": "^18.0.0 || ^19.0.0"
|
84
84
|
}
|
85
85
|
}
|