@measured/puck 0.19.0-canary.896a6279 → 0.19.0-canary.8e1d7223
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-HGAPIQP5.mjs +949 -0
- package/dist/index.css +187 -181
- package/dist/index.d.mts +21 -10
- package/dist/index.d.ts +21 -10
- package/dist/index.js +1722 -1464
- package/dist/index.mjs +6501 -1905
- package/dist/rsc.d.mts +2 -2
- package/dist/rsc.d.ts +2 -2
- package/dist/rsc.js +631 -3726
- package/dist/rsc.mjs +7 -103
- package/dist/{resolve-all-data-Cs8PfTrg.d.mts → walk-tree-DBd3aQ_5.d.mts} +68 -35
- package/dist/{resolve-all-data-Cs8PfTrg.d.ts → walk-tree-DBd3aQ_5.d.ts} +68 -35
- package/package.json +13 -8
- package/dist/chunk-LT6HN46T.mjs +0 -5350
- package/dist/rsc.css +0 -338
package/dist/rsc.mjs
CHANGED
@@ -1,114 +1,18 @@
|
|
1
1
|
import {
|
2
|
-
|
3
|
-
__spreadProps,
|
4
|
-
__spreadValues,
|
2
|
+
Render,
|
5
3
|
init_react_import,
|
4
|
+
migrate,
|
6
5
|
resolveAllData,
|
7
|
-
rootAreaId,
|
8
|
-
rootDroppableId,
|
9
|
-
rootZone,
|
10
|
-
setupZone,
|
11
6
|
transformProps,
|
12
|
-
|
13
|
-
} from "./chunk-
|
7
|
+
walkTree
|
8
|
+
} from "./chunk-HGAPIQP5.mjs";
|
14
9
|
|
15
10
|
// rsc.tsx
|
16
11
|
init_react_import();
|
17
|
-
|
18
|
-
// components/ServerRender/index.tsx
|
19
|
-
init_react_import();
|
20
|
-
import { Fragment, jsx } from "react/jsx-runtime";
|
21
|
-
function DropZoneRender({
|
22
|
-
zone,
|
23
|
-
data,
|
24
|
-
areaId = "root",
|
25
|
-
config,
|
26
|
-
metadata = {}
|
27
|
-
}) {
|
28
|
-
let zoneCompound = rootDroppableId;
|
29
|
-
let content = (data == null ? void 0 : data.content) || [];
|
30
|
-
if (!data || !config) {
|
31
|
-
return null;
|
32
|
-
}
|
33
|
-
if (areaId !== rootAreaId && zone !== rootZone) {
|
34
|
-
zoneCompound = `${areaId}:${zone}`;
|
35
|
-
content = setupZone(data, zoneCompound).zones[zoneCompound];
|
36
|
-
}
|
37
|
-
return /* @__PURE__ */ jsx(Fragment, { children: content.map((item) => {
|
38
|
-
const Component = config.components[item.type];
|
39
|
-
const props = __spreadProps(__spreadValues({}, item.props), {
|
40
|
-
puck: {
|
41
|
-
renderDropZone: ({ zone: zone2 }) => /* @__PURE__ */ jsx(
|
42
|
-
DropZoneRender,
|
43
|
-
{
|
44
|
-
zone: zone2,
|
45
|
-
data,
|
46
|
-
areaId: item.props.id,
|
47
|
-
config,
|
48
|
-
metadata
|
49
|
-
}
|
50
|
-
),
|
51
|
-
metadata
|
52
|
-
}
|
53
|
-
});
|
54
|
-
const propsWithSlots = useSlots(config.root, props, (props2) => /* @__PURE__ */ jsx(SlotRenderPure, __spreadProps(__spreadValues({}, props2), { config, metadata })));
|
55
|
-
if (Component) {
|
56
|
-
return /* @__PURE__ */ jsx(Component.render, __spreadValues({}, propsWithSlots), item.props.id);
|
57
|
-
}
|
58
|
-
return null;
|
59
|
-
}) });
|
60
|
-
}
|
61
|
-
function Render({
|
62
|
-
config,
|
63
|
-
data,
|
64
|
-
metadata = {}
|
65
|
-
}) {
|
66
|
-
var _a;
|
67
|
-
const rootProps = data.root.props || data.root;
|
68
|
-
const title = rootProps.title || "";
|
69
|
-
const props = __spreadProps(__spreadValues({}, rootProps), {
|
70
|
-
puck: {
|
71
|
-
renderDropZone: ({ zone }) => /* @__PURE__ */ jsx(
|
72
|
-
DropZoneRender,
|
73
|
-
{
|
74
|
-
zone,
|
75
|
-
data,
|
76
|
-
config,
|
77
|
-
metadata
|
78
|
-
}
|
79
|
-
),
|
80
|
-
isEditing: false,
|
81
|
-
dragRef: null,
|
82
|
-
metadata
|
83
|
-
},
|
84
|
-
title,
|
85
|
-
editMode: false,
|
86
|
-
id: "puck-root"
|
87
|
-
});
|
88
|
-
const propsWithSlots = useSlots(config.root, props, (props2) => /* @__PURE__ */ jsx(SlotRenderPure, __spreadProps(__spreadValues({}, props2), { config, metadata })));
|
89
|
-
if ((_a = config.root) == null ? void 0 : _a.render) {
|
90
|
-
return /* @__PURE__ */ jsx(config.root.render, __spreadProps(__spreadValues({}, propsWithSlots), { children: /* @__PURE__ */ jsx(
|
91
|
-
DropZoneRender,
|
92
|
-
{
|
93
|
-
config,
|
94
|
-
data,
|
95
|
-
zone: rootZone,
|
96
|
-
metadata
|
97
|
-
}
|
98
|
-
) }));
|
99
|
-
}
|
100
|
-
return /* @__PURE__ */ jsx(
|
101
|
-
DropZoneRender,
|
102
|
-
{
|
103
|
-
config,
|
104
|
-
data,
|
105
|
-
zone: rootZone,
|
106
|
-
metadata
|
107
|
-
}
|
108
|
-
);
|
109
|
-
}
|
110
12
|
export {
|
111
13
|
Render,
|
14
|
+
migrate,
|
112
15
|
resolveAllData,
|
113
|
-
transformProps
|
16
|
+
transformProps,
|
17
|
+
walkTree
|
114
18
|
};
|
@@ -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,8 @@ type FieldOptions = Array<FieldOption> | ReadonlyArray<FieldOption>;
|
|
23
23
|
type BaseField = {
|
24
24
|
label?: string;
|
25
25
|
labelIcon?: ReactElement;
|
26
|
+
metadata?: Metadata;
|
27
|
+
visible?: boolean;
|
26
28
|
};
|
27
29
|
type TextField = BaseField & {
|
28
30
|
type: "text";
|
@@ -109,19 +111,22 @@ type ExternalField<Props extends {
|
|
109
111
|
filterFields?: Record<string, Field>;
|
110
112
|
initialFilters?: Record<string, any>;
|
111
113
|
};
|
112
|
-
type
|
114
|
+
type CustomFieldRender<Value extends any> = (props: {
|
115
|
+
field: CustomField<Value>;
|
116
|
+
name: string;
|
117
|
+
id: string;
|
118
|
+
value: Value;
|
119
|
+
onChange: (value: Value) => void;
|
120
|
+
readOnly?: boolean;
|
121
|
+
}) => ReactElement;
|
122
|
+
type CustomField<Value extends any> = BaseField & {
|
113
123
|
type: "custom";
|
114
|
-
render:
|
115
|
-
field: CustomField<Props>;
|
116
|
-
name: string;
|
117
|
-
id: string;
|
118
|
-
value: Props;
|
119
|
-
onChange: (value: Props) => void;
|
120
|
-
readOnly?: boolean;
|
121
|
-
}) => ReactElement;
|
124
|
+
render: CustomFieldRender<Value>;
|
122
125
|
};
|
123
126
|
type SlotField = BaseField & {
|
124
127
|
type: "slot";
|
128
|
+
allow?: string[];
|
129
|
+
disallow?: string[];
|
125
130
|
};
|
126
131
|
type Field<Props extends any = any> = TextField | NumberField | TextareaField | SelectField | RadioField | ArrayField<Props extends {
|
127
132
|
[key: string]: any;
|
@@ -143,12 +148,16 @@ type FieldProps<F = Field<any>, ValueType = any> = {
|
|
143
148
|
readOnly?: boolean;
|
144
149
|
};
|
145
150
|
|
146
|
-
type
|
151
|
+
type SlotComponent = (props?: Omit<DropZoneProps, "zone">) => ReactNode;
|
152
|
+
type PuckComponent<Props> = (props: WithId<WithPuckProps<{
|
153
|
+
[K in keyof Props]: WithDeepSlots<Props[K], SlotComponent>;
|
154
|
+
}>>) => JSX.Element;
|
147
155
|
type ResolveDataTrigger = "insert" | "replace" | "load" | "force";
|
156
|
+
type WithPartialProps<T, Props extends DefaultComponentProps> = Omit<T, "props"> & {
|
157
|
+
props?: Partial<Props>;
|
158
|
+
};
|
148
159
|
type ComponentConfig<RenderProps extends DefaultComponentProps = DefaultComponentProps, FieldProps extends DefaultComponentProps = RenderProps, DataShape = Omit<ComponentData<FieldProps>, "type">> = {
|
149
|
-
render: PuckComponent<
|
150
|
-
[PropName in keyof RenderProps]: RenderProps[PropName] extends Slot ? (props?: Omit<DropZoneProps, "zone">) => ReactNode : RenderProps[PropName];
|
151
|
-
}>;
|
160
|
+
render: PuckComponent<RenderProps>;
|
152
161
|
label?: string;
|
153
162
|
defaultProps?: FieldProps;
|
154
163
|
fields?: Fields<FieldProps>;
|
@@ -171,13 +180,7 @@ type ComponentConfig<RenderProps extends DefaultComponentProps = DefaultComponen
|
|
171
180
|
lastData: DataShape | null;
|
172
181
|
metadata: Metadata;
|
173
182
|
trigger: ResolveDataTrigger;
|
174
|
-
}) => Promise<
|
175
|
-
props?: Partial<FieldProps>;
|
176
|
-
readOnly?: Partial<Record<keyof FieldProps, boolean>>;
|
177
|
-
}> | {
|
178
|
-
props?: Partial<FieldProps>;
|
179
|
-
readOnly?: Partial<Record<keyof FieldProps, boolean>>;
|
180
|
-
};
|
183
|
+
}) => Promise<WithPartialProps<DataShape, FieldProps>> | WithPartialProps<DataShape, FieldProps>;
|
181
184
|
resolvePermissions?: (data: DataShape, params: {
|
182
185
|
changed: Partial<Record<keyof FieldProps, boolean> & {
|
183
186
|
id: string;
|
@@ -187,6 +190,7 @@ type ComponentConfig<RenderProps extends DefaultComponentProps = DefaultComponen
|
|
187
190
|
appState: AppState;
|
188
191
|
lastData: DataShape | null;
|
189
192
|
}) => Promise<Partial<Permissions>> | Partial<Permissions>;
|
193
|
+
metadata?: Metadata;
|
190
194
|
};
|
191
195
|
type RootConfig<RootProps extends DefaultComponentProps = any> = Partial<ComponentConfig<WithChildren<RootProps>, AsFieldProps<RootProps>, RootData<AsFieldProps<RootProps>>>>;
|
192
196
|
type Category<ComponentName> = {
|
@@ -234,6 +238,7 @@ type PuckContext = {
|
|
234
238
|
dragRef: ((element: Element | null) => void) | null;
|
235
239
|
};
|
236
240
|
type DefaultRootFieldProps = {
|
241
|
+
[key: string]: any;
|
237
242
|
title?: string;
|
238
243
|
};
|
239
244
|
type DefaultRootRenderProps<Props extends DefaultComponentProps = DefaultRootFieldProps> = WithPuckProps<WithChildren<Props>>;
|
@@ -254,23 +259,29 @@ type RootDataWithProps<Props extends DefaultComponentProps = DefaultRootFieldPro
|
|
254
259
|
};
|
255
260
|
type RootDataWithoutProps<Props extends DefaultComponentProps = DefaultRootFieldProps> = Props;
|
256
261
|
type RootData<Props extends DefaultComponentProps = DefaultRootFieldProps> = Partial<RootDataWithProps<AsFieldProps<Props>>> & Partial<RootDataWithoutProps<Props>>;
|
257
|
-
type ComponentData<Props extends DefaultComponentProps = DefaultComponentProps, Name = string> = {
|
262
|
+
type ComponentData<Props extends DefaultComponentProps = DefaultComponentProps, Name = string, AllProps extends Record<string, DefaultComponentProps> = Record<string, DefaultComponentProps>> = {
|
263
|
+
type: Name;
|
264
|
+
props: WithDeepSlots<WithId<Props>, Content<AllProps>>;
|
265
|
+
} & BaseData<Props>;
|
266
|
+
type ComponentDataOptionalId<Props extends DefaultComponentProps = DefaultComponentProps, Name = string> = {
|
258
267
|
type: Name;
|
259
|
-
props:
|
268
|
+
props: Props & {
|
269
|
+
id?: string;
|
270
|
+
};
|
260
271
|
} & BaseData<Props>;
|
261
272
|
type MappedItem = ComponentData;
|
262
|
-
type ComponentDataMap<
|
263
|
-
[K in keyof
|
264
|
-
}[keyof
|
273
|
+
type ComponentDataMap<AllProps extends DefaultAllProps = DefaultAllProps> = {
|
274
|
+
[K in keyof AllProps]: ComponentData<AllProps[K], K extends string ? K : never, AllProps>;
|
275
|
+
}[keyof AllProps];
|
265
276
|
type Content<PropsMap extends {
|
266
|
-
[key: string]:
|
277
|
+
[key: string]: DefaultComponentProps;
|
267
278
|
} = {
|
268
|
-
[key: string]:
|
279
|
+
[key: string]: DefaultComponentProps;
|
269
280
|
}> = ComponentDataMap<PropsMap>[];
|
270
|
-
type Data<
|
271
|
-
root: RootData<RootProps
|
272
|
-
content: Content<
|
273
|
-
zones?: Record<string, Content<
|
281
|
+
type Data<AllProps extends DefaultAllProps = DefaultAllProps, RootProps extends DefaultComponentProps = DefaultRootFieldProps> = {
|
282
|
+
root: WithDeepSlots<RootData<RootProps>, Content<AllProps>>;
|
283
|
+
content: Content<AllProps>;
|
284
|
+
zones?: Record<string, Content<AllProps>>;
|
274
285
|
};
|
275
286
|
type Metadata = {
|
276
287
|
[key: string]: any;
|
@@ -334,6 +345,13 @@ type PrivateAppState<UserData extends Data = Data> = AppState<UserData> & {
|
|
334
345
|
zones: ZoneIndex;
|
335
346
|
};
|
336
347
|
};
|
348
|
+
type DefaultAllProps = Record<string, DefaultComponentProps>;
|
349
|
+
/**
|
350
|
+
* Recursively walk T and replace Slots with SlotComponents
|
351
|
+
*/
|
352
|
+
type WithDeepSlots<T, SlotType = T> = T extends Slot ? SlotType : T extends (infer U)[] ? Array<WithDeepSlots<U, SlotType>> : T extends (infer U)[] ? WithDeepSlots<U, SlotType>[] : T extends object ? {
|
353
|
+
[K in keyof T]: WithDeepSlots<T[K], SlotType>;
|
354
|
+
} : T;
|
337
355
|
|
338
356
|
type RenderFunc<Props extends {
|
339
357
|
[key: string]: any;
|
@@ -441,7 +459,14 @@ type InitialHistoryNoAppend<AS = Partial<AppState>> = {
|
|
441
459
|
appendData?: false;
|
442
460
|
};
|
443
461
|
type InitialHistory<AS = Partial<AppState>> = InitialHistoryAppend<AS> | InitialHistoryNoAppend<AS>;
|
444
|
-
type Slot
|
462
|
+
type Slot<Props extends {
|
463
|
+
[key: string]: DefaultComponentProps;
|
464
|
+
} = {
|
465
|
+
[key: string]: DefaultComponentProps;
|
466
|
+
}> = {
|
467
|
+
[K in keyof Props]: ComponentDataOptionalId<Props[K], K extends string ? K : never>;
|
468
|
+
}[keyof Props][];
|
469
|
+
type WithSlotProps<Target extends Record<string, any>, AllProps extends DefaultAllProps = DefaultAllProps, SlotType extends Content<AllProps> = Content<AllProps>> = WithDeepSlots<Target, SlotType>;
|
445
470
|
|
446
471
|
type InsertAction = {
|
447
472
|
type: "insert";
|
@@ -509,6 +534,8 @@ type PuckAction = {
|
|
509
534
|
recordHistory?: boolean;
|
510
535
|
} & (ReorderAction | InsertAction | MoveAction | ReplaceAction | ReplaceRootAction | RemoveAction | DuplicateAction | SetAction | SetDataAction | SetUiAction | RegisterZoneAction | UnregisterZoneAction);
|
511
536
|
|
537
|
+
declare function migrate(data: Data, config?: Config): Data;
|
538
|
+
|
512
539
|
type PropTransform<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultComponentProps = DefaultRootFieldProps> = Partial<{
|
513
540
|
[ComponentName in keyof Props]: (props: Props[ComponentName] & {
|
514
541
|
[key: string]: any;
|
@@ -518,8 +545,14 @@ type PropTransform<Props extends DefaultComponentProps = DefaultComponentProps,
|
|
518
545
|
[key: string]: any;
|
519
546
|
}) => RootProps;
|
520
547
|
}>;
|
521
|
-
declare function transformProps<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultComponentProps = DefaultRootFieldProps>(data: Partial<Data>, propTransforms: PropTransform<Props, RootProps
|
548
|
+
declare function transformProps<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultComponentProps = DefaultRootFieldProps>(data: Partial<Data>, propTransforms: PropTransform<Props, RootProps>, config?: Config): Data;
|
522
549
|
|
523
550
|
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>>;
|
524
551
|
|
525
|
-
|
552
|
+
type WalkTreeOptions = {
|
553
|
+
parentId: string;
|
554
|
+
propName: string;
|
555
|
+
};
|
556
|
+
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;
|
557
|
+
|
558
|
+
export { type ExternalFieldWithAdaptor 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 WithSlotProps as W, type RadioField as X, type ArrayField as Y, type ObjectField as Z, type Adaptor as _, type Config as a, type ExternalField as a0, type CustomFieldRender as a1, type CustomField as a2, type SlotField as a3, type PuckContext as a4, type DefaultRootFieldProps as a5, type DefaultRootRenderProps as a6, type DefaultRootProps as a7, type DefaultComponentProps as a8, type WithId as a9, type WithPuckProps as aa, type AsFieldProps as ab, type WithChildren as ac, type ExtractPropsFromConfig as ad, type ExtractRootPropsFromConfig as ae, migrate as af, transformProps as ag, resolveAllData as ah, 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,8 @@ type FieldOptions = Array<FieldOption> | ReadonlyArray<FieldOption>;
|
|
23
23
|
type BaseField = {
|
24
24
|
label?: string;
|
25
25
|
labelIcon?: ReactElement;
|
26
|
+
metadata?: Metadata;
|
27
|
+
visible?: boolean;
|
26
28
|
};
|
27
29
|
type TextField = BaseField & {
|
28
30
|
type: "text";
|
@@ -109,19 +111,22 @@ type ExternalField<Props extends {
|
|
109
111
|
filterFields?: Record<string, Field>;
|
110
112
|
initialFilters?: Record<string, any>;
|
111
113
|
};
|
112
|
-
type
|
114
|
+
type CustomFieldRender<Value extends any> = (props: {
|
115
|
+
field: CustomField<Value>;
|
116
|
+
name: string;
|
117
|
+
id: string;
|
118
|
+
value: Value;
|
119
|
+
onChange: (value: Value) => void;
|
120
|
+
readOnly?: boolean;
|
121
|
+
}) => ReactElement;
|
122
|
+
type CustomField<Value extends any> = BaseField & {
|
113
123
|
type: "custom";
|
114
|
-
render:
|
115
|
-
field: CustomField<Props>;
|
116
|
-
name: string;
|
117
|
-
id: string;
|
118
|
-
value: Props;
|
119
|
-
onChange: (value: Props) => void;
|
120
|
-
readOnly?: boolean;
|
121
|
-
}) => ReactElement;
|
124
|
+
render: CustomFieldRender<Value>;
|
122
125
|
};
|
123
126
|
type SlotField = BaseField & {
|
124
127
|
type: "slot";
|
128
|
+
allow?: string[];
|
129
|
+
disallow?: string[];
|
125
130
|
};
|
126
131
|
type Field<Props extends any = any> = TextField | NumberField | TextareaField | SelectField | RadioField | ArrayField<Props extends {
|
127
132
|
[key: string]: any;
|
@@ -143,12 +148,16 @@ type FieldProps<F = Field<any>, ValueType = any> = {
|
|
143
148
|
readOnly?: boolean;
|
144
149
|
};
|
145
150
|
|
146
|
-
type
|
151
|
+
type SlotComponent = (props?: Omit<DropZoneProps, "zone">) => ReactNode;
|
152
|
+
type PuckComponent<Props> = (props: WithId<WithPuckProps<{
|
153
|
+
[K in keyof Props]: WithDeepSlots<Props[K], SlotComponent>;
|
154
|
+
}>>) => JSX.Element;
|
147
155
|
type ResolveDataTrigger = "insert" | "replace" | "load" | "force";
|
156
|
+
type WithPartialProps<T, Props extends DefaultComponentProps> = Omit<T, "props"> & {
|
157
|
+
props?: Partial<Props>;
|
158
|
+
};
|
148
159
|
type ComponentConfig<RenderProps extends DefaultComponentProps = DefaultComponentProps, FieldProps extends DefaultComponentProps = RenderProps, DataShape = Omit<ComponentData<FieldProps>, "type">> = {
|
149
|
-
render: PuckComponent<
|
150
|
-
[PropName in keyof RenderProps]: RenderProps[PropName] extends Slot ? (props?: Omit<DropZoneProps, "zone">) => ReactNode : RenderProps[PropName];
|
151
|
-
}>;
|
160
|
+
render: PuckComponent<RenderProps>;
|
152
161
|
label?: string;
|
153
162
|
defaultProps?: FieldProps;
|
154
163
|
fields?: Fields<FieldProps>;
|
@@ -171,13 +180,7 @@ type ComponentConfig<RenderProps extends DefaultComponentProps = DefaultComponen
|
|
171
180
|
lastData: DataShape | null;
|
172
181
|
metadata: Metadata;
|
173
182
|
trigger: ResolveDataTrigger;
|
174
|
-
}) => Promise<
|
175
|
-
props?: Partial<FieldProps>;
|
176
|
-
readOnly?: Partial<Record<keyof FieldProps, boolean>>;
|
177
|
-
}> | {
|
178
|
-
props?: Partial<FieldProps>;
|
179
|
-
readOnly?: Partial<Record<keyof FieldProps, boolean>>;
|
180
|
-
};
|
183
|
+
}) => Promise<WithPartialProps<DataShape, FieldProps>> | WithPartialProps<DataShape, FieldProps>;
|
181
184
|
resolvePermissions?: (data: DataShape, params: {
|
182
185
|
changed: Partial<Record<keyof FieldProps, boolean> & {
|
183
186
|
id: string;
|
@@ -187,6 +190,7 @@ type ComponentConfig<RenderProps extends DefaultComponentProps = DefaultComponen
|
|
187
190
|
appState: AppState;
|
188
191
|
lastData: DataShape | null;
|
189
192
|
}) => Promise<Partial<Permissions>> | Partial<Permissions>;
|
193
|
+
metadata?: Metadata;
|
190
194
|
};
|
191
195
|
type RootConfig<RootProps extends DefaultComponentProps = any> = Partial<ComponentConfig<WithChildren<RootProps>, AsFieldProps<RootProps>, RootData<AsFieldProps<RootProps>>>>;
|
192
196
|
type Category<ComponentName> = {
|
@@ -234,6 +238,7 @@ type PuckContext = {
|
|
234
238
|
dragRef: ((element: Element | null) => void) | null;
|
235
239
|
};
|
236
240
|
type DefaultRootFieldProps = {
|
241
|
+
[key: string]: any;
|
237
242
|
title?: string;
|
238
243
|
};
|
239
244
|
type DefaultRootRenderProps<Props extends DefaultComponentProps = DefaultRootFieldProps> = WithPuckProps<WithChildren<Props>>;
|
@@ -254,23 +259,29 @@ type RootDataWithProps<Props extends DefaultComponentProps = DefaultRootFieldPro
|
|
254
259
|
};
|
255
260
|
type RootDataWithoutProps<Props extends DefaultComponentProps = DefaultRootFieldProps> = Props;
|
256
261
|
type RootData<Props extends DefaultComponentProps = DefaultRootFieldProps> = Partial<RootDataWithProps<AsFieldProps<Props>>> & Partial<RootDataWithoutProps<Props>>;
|
257
|
-
type ComponentData<Props extends DefaultComponentProps = DefaultComponentProps, Name = string> = {
|
262
|
+
type ComponentData<Props extends DefaultComponentProps = DefaultComponentProps, Name = string, AllProps extends Record<string, DefaultComponentProps> = Record<string, DefaultComponentProps>> = {
|
263
|
+
type: Name;
|
264
|
+
props: WithDeepSlots<WithId<Props>, Content<AllProps>>;
|
265
|
+
} & BaseData<Props>;
|
266
|
+
type ComponentDataOptionalId<Props extends DefaultComponentProps = DefaultComponentProps, Name = string> = {
|
258
267
|
type: Name;
|
259
|
-
props:
|
268
|
+
props: Props & {
|
269
|
+
id?: string;
|
270
|
+
};
|
260
271
|
} & BaseData<Props>;
|
261
272
|
type MappedItem = ComponentData;
|
262
|
-
type ComponentDataMap<
|
263
|
-
[K in keyof
|
264
|
-
}[keyof
|
273
|
+
type ComponentDataMap<AllProps extends DefaultAllProps = DefaultAllProps> = {
|
274
|
+
[K in keyof AllProps]: ComponentData<AllProps[K], K extends string ? K : never, AllProps>;
|
275
|
+
}[keyof AllProps];
|
265
276
|
type Content<PropsMap extends {
|
266
|
-
[key: string]:
|
277
|
+
[key: string]: DefaultComponentProps;
|
267
278
|
} = {
|
268
|
-
[key: string]:
|
279
|
+
[key: string]: DefaultComponentProps;
|
269
280
|
}> = ComponentDataMap<PropsMap>[];
|
270
|
-
type Data<
|
271
|
-
root: RootData<RootProps
|
272
|
-
content: Content<
|
273
|
-
zones?: Record<string, Content<
|
281
|
+
type Data<AllProps extends DefaultAllProps = DefaultAllProps, RootProps extends DefaultComponentProps = DefaultRootFieldProps> = {
|
282
|
+
root: WithDeepSlots<RootData<RootProps>, Content<AllProps>>;
|
283
|
+
content: Content<AllProps>;
|
284
|
+
zones?: Record<string, Content<AllProps>>;
|
274
285
|
};
|
275
286
|
type Metadata = {
|
276
287
|
[key: string]: any;
|
@@ -334,6 +345,13 @@ type PrivateAppState<UserData extends Data = Data> = AppState<UserData> & {
|
|
334
345
|
zones: ZoneIndex;
|
335
346
|
};
|
336
347
|
};
|
348
|
+
type DefaultAllProps = Record<string, DefaultComponentProps>;
|
349
|
+
/**
|
350
|
+
* Recursively walk T and replace Slots with SlotComponents
|
351
|
+
*/
|
352
|
+
type WithDeepSlots<T, SlotType = T> = T extends Slot ? SlotType : T extends (infer U)[] ? Array<WithDeepSlots<U, SlotType>> : T extends (infer U)[] ? WithDeepSlots<U, SlotType>[] : T extends object ? {
|
353
|
+
[K in keyof T]: WithDeepSlots<T[K], SlotType>;
|
354
|
+
} : T;
|
337
355
|
|
338
356
|
type RenderFunc<Props extends {
|
339
357
|
[key: string]: any;
|
@@ -441,7 +459,14 @@ type InitialHistoryNoAppend<AS = Partial<AppState>> = {
|
|
441
459
|
appendData?: false;
|
442
460
|
};
|
443
461
|
type InitialHistory<AS = Partial<AppState>> = InitialHistoryAppend<AS> | InitialHistoryNoAppend<AS>;
|
444
|
-
type Slot
|
462
|
+
type Slot<Props extends {
|
463
|
+
[key: string]: DefaultComponentProps;
|
464
|
+
} = {
|
465
|
+
[key: string]: DefaultComponentProps;
|
466
|
+
}> = {
|
467
|
+
[K in keyof Props]: ComponentDataOptionalId<Props[K], K extends string ? K : never>;
|
468
|
+
}[keyof Props][];
|
469
|
+
type WithSlotProps<Target extends Record<string, any>, AllProps extends DefaultAllProps = DefaultAllProps, SlotType extends Content<AllProps> = Content<AllProps>> = WithDeepSlots<Target, SlotType>;
|
445
470
|
|
446
471
|
type InsertAction = {
|
447
472
|
type: "insert";
|
@@ -509,6 +534,8 @@ type PuckAction = {
|
|
509
534
|
recordHistory?: boolean;
|
510
535
|
} & (ReorderAction | InsertAction | MoveAction | ReplaceAction | ReplaceRootAction | RemoveAction | DuplicateAction | SetAction | SetDataAction | SetUiAction | RegisterZoneAction | UnregisterZoneAction);
|
511
536
|
|
537
|
+
declare function migrate(data: Data, config?: Config): Data;
|
538
|
+
|
512
539
|
type PropTransform<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultComponentProps = DefaultRootFieldProps> = Partial<{
|
513
540
|
[ComponentName in keyof Props]: (props: Props[ComponentName] & {
|
514
541
|
[key: string]: any;
|
@@ -518,8 +545,14 @@ type PropTransform<Props extends DefaultComponentProps = DefaultComponentProps,
|
|
518
545
|
[key: string]: any;
|
519
546
|
}) => RootProps;
|
520
547
|
}>;
|
521
|
-
declare function transformProps<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultComponentProps = DefaultRootFieldProps>(data: Partial<Data>, propTransforms: PropTransform<Props, RootProps
|
548
|
+
declare function transformProps<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultComponentProps = DefaultRootFieldProps>(data: Partial<Data>, propTransforms: PropTransform<Props, RootProps>, config?: Config): Data;
|
522
549
|
|
523
550
|
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>>;
|
524
551
|
|
525
|
-
|
552
|
+
type WalkTreeOptions = {
|
553
|
+
parentId: string;
|
554
|
+
propName: string;
|
555
|
+
};
|
556
|
+
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;
|
557
|
+
|
558
|
+
export { type ExternalFieldWithAdaptor 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 WithSlotProps as W, type RadioField as X, type ArrayField as Y, type ObjectField as Z, type Adaptor as _, type Config as a, type ExternalField as a0, type CustomFieldRender as a1, type CustomField as a2, type SlotField as a3, type PuckContext as a4, type DefaultRootFieldProps as a5, type DefaultRootRenderProps as a6, type DefaultRootProps as a7, type DefaultComponentProps as a8, type WithId as a9, type WithPuckProps as aa, type AsFieldProps as ab, type WithChildren as ac, type ExtractPropsFromConfig as ad, type ExtractRootPropsFromConfig as ae, migrate as af, transformProps as ag, resolveAllData as ah, 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.8e1d7223",
|
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",
|
@@ -49,9 +49,12 @@
|
|
49
49
|
"dist"
|
50
50
|
],
|
51
51
|
"devDependencies": {
|
52
|
+
"@juggle/resize-observer": "^3.4.0",
|
53
|
+
"@testing-library/jest-dom": "^6.6.3",
|
52
54
|
"@testing-library/react": "^16.1.0",
|
53
55
|
"@types/deep-diff": "^1.0.3",
|
54
|
-
"@types/
|
56
|
+
"@types/flat": "^5.0.5",
|
57
|
+
"@types/jest": "^29.5.14",
|
55
58
|
"@types/object-hash": "^3.0.6",
|
56
59
|
"@types/react": "^19.0.1",
|
57
60
|
"@types/react-dom": "^19.0.2",
|
@@ -59,20 +62,22 @@
|
|
59
62
|
"css-box-model": "^1.2.1",
|
60
63
|
"eslint": "^7.32.0",
|
61
64
|
"eslint-config-custom": "*",
|
62
|
-
"
|
63
|
-
"jest
|
65
|
+
"identity-obj-proxy": "^3.0.0",
|
66
|
+
"jest": "^29.7.0",
|
67
|
+
"jest-environment-jsdom": "^30.0.0-beta.3",
|
64
68
|
"lucide-react": "^0.468.0",
|
65
|
-
"ts-jest": "^29.
|
69
|
+
"ts-jest": "^29.3.4",
|
66
70
|
"tsconfig": "*",
|
67
71
|
"tsup": "^8.2.4",
|
68
72
|
"tsup-config": "*",
|
69
73
|
"typescript": "^5.5.4"
|
70
74
|
},
|
71
75
|
"dependencies": {
|
72
|
-
"@dnd-kit/helpers": "0.
|
73
|
-
"@dnd-kit/react": "0.
|
76
|
+
"@dnd-kit/helpers": "0.1.18-beta-20250525014052",
|
77
|
+
"@dnd-kit/react": "0.1.18-beta-20250525014052",
|
74
78
|
"deep-diff": "^1.0.2",
|
75
79
|
"fast-deep-equal": "^3.1.3",
|
80
|
+
"flat": "^5.0.2",
|
76
81
|
"object-hash": "^3.0.0",
|
77
82
|
"react-hotkeys-hook": "^4.6.1",
|
78
83
|
"use-debounce": "^9.0.4",
|