@measured/puck 0.21.0-canary.5333fc7e → 0.21.0-canary.5c2364c5
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/dist/{chunk-KNAV6QTS.mjs → chunk-JB4ZAK5S.mjs} +54 -267
- package/dist/{chunk-X7YZ3YE7.mjs → chunk-TC25DCTQ.mjs} +9 -8
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +72 -288
- package/dist/index.mjs +2 -2
- package/dist/no-external.d.mts +1 -1
- package/dist/no-external.d.ts +1 -1
- package/dist/no-external.js +69 -285
- package/dist/no-external.mjs +2 -2
- package/dist/rsc.d.mts +2 -2
- package/dist/rsc.d.ts +2 -2
- package/dist/rsc.js +8 -8
- package/dist/rsc.mjs +1 -1
- package/dist/{walk-tree-Ctf3FZQI.d.mts → walk-tree-BMbIeiqs.d.mts} +55 -43
- package/dist/{walk-tree-Ctf3FZQI.d.ts → walk-tree-BMbIeiqs.d.ts} +55 -43
- package/package.json +1 -1
package/dist/no-external.mjs
CHANGED
|
@@ -18,14 +18,14 @@ import {
|
|
|
18
18
|
setDeep,
|
|
19
19
|
useGetPuck,
|
|
20
20
|
usePuck
|
|
21
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-JB4ZAK5S.mjs";
|
|
22
22
|
import {
|
|
23
23
|
init_react_import,
|
|
24
24
|
migrate,
|
|
25
25
|
resolveAllData,
|
|
26
26
|
transformProps,
|
|
27
27
|
walkTree
|
|
28
|
-
} from "./chunk-
|
|
28
|
+
} from "./chunk-TC25DCTQ.mjs";
|
|
29
29
|
|
|
30
30
|
// bundle/no-external.ts
|
|
31
31
|
init_react_import();
|
package/dist/rsc.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { C as Config, U as UserGenerics, M as Metadata } from './walk-tree-
|
|
3
|
-
export { m as migrate, r as resolveAllData, t as transformProps, w as walkTree } from './walk-tree-
|
|
2
|
+
import { C as Config, U as UserGenerics, M as Metadata } from './walk-tree-BMbIeiqs.mjs';
|
|
3
|
+
export { m as migrate, r as resolveAllData, t as transformProps, w as walkTree } from './walk-tree-BMbIeiqs.mjs';
|
|
4
4
|
import 'react';
|
|
5
5
|
|
|
6
6
|
declare function Render<UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>>({ config, data, metadata, }: {
|
package/dist/rsc.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { C as Config, U as UserGenerics, M as Metadata } from './walk-tree-
|
|
3
|
-
export { m as migrate, r as resolveAllData, t as transformProps, w as walkTree } from './walk-tree-
|
|
2
|
+
import { C as Config, U as UserGenerics, M as Metadata } from './walk-tree-BMbIeiqs.js';
|
|
3
|
+
export { m as migrate, r as resolveAllData, t as transformProps, w as walkTree } from './walk-tree-BMbIeiqs.js';
|
|
4
4
|
import 'react';
|
|
5
5
|
|
|
6
6
|
declare function Render<UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>>({ config, data, metadata, }: {
|
package/dist/rsc.js
CHANGED
|
@@ -474,7 +474,7 @@ var getChanged = (newItem, oldItem) => {
|
|
|
474
474
|
// lib/resolve-component-data.ts
|
|
475
475
|
var import_fast_equals2 = require("fast-equals");
|
|
476
476
|
var cache = { lastChange: {} };
|
|
477
|
-
var resolveComponentData = (_0, _1, ..._2) => __async(
|
|
477
|
+
var resolveComponentData = (_0, _1, ..._2) => __async(null, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace") {
|
|
478
478
|
const configForItem = "type" in item && item.type !== "root" ? config.components[item.type] : config.root;
|
|
479
479
|
const resolvedItem = __spreadValues({}, item);
|
|
480
480
|
const shouldRunResolver = (configForItem == null ? void 0 : configForItem.resolveData) && item.props;
|
|
@@ -502,11 +502,11 @@ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], f
|
|
|
502
502
|
let itemWithResolvedChildren = yield mapFields(
|
|
503
503
|
resolvedItem,
|
|
504
504
|
{
|
|
505
|
-
slot: (_02) => __async(
|
|
505
|
+
slot: (_02) => __async(null, [_02], function* ({ value }) {
|
|
506
506
|
const content = value;
|
|
507
507
|
return yield Promise.all(
|
|
508
508
|
content.map(
|
|
509
|
-
(childItem) => __async(
|
|
509
|
+
(childItem) => __async(null, null, function* () {
|
|
510
510
|
return (yield resolveComponentData(
|
|
511
511
|
childItem,
|
|
512
512
|
config,
|
|
@@ -554,7 +554,7 @@ function resolveAllData(_0, _1) {
|
|
|
554
554
|
return __async(this, arguments, function* (data, config, metadata = {}, onResolveStart, onResolveEnd) {
|
|
555
555
|
var _a;
|
|
556
556
|
const defaultedData = defaultData(data);
|
|
557
|
-
const resolveNode = (_node) => __async(
|
|
557
|
+
const resolveNode = (_node) => __async(null, null, function* () {
|
|
558
558
|
const node = toComponent(_node);
|
|
559
559
|
onResolveStart == null ? void 0 : onResolveStart(node);
|
|
560
560
|
const resolved = (yield resolveComponentData(
|
|
@@ -575,13 +575,13 @@ function resolveAllData(_0, _1) {
|
|
|
575
575
|
onResolveEnd == null ? void 0 : onResolveEnd(toComponent(resolvedDeep));
|
|
576
576
|
return resolvedDeep;
|
|
577
577
|
});
|
|
578
|
-
const processContent = (content) => __async(
|
|
578
|
+
const processContent = (content) => __async(null, null, function* () {
|
|
579
579
|
return Promise.all(content.map(resolveNode));
|
|
580
580
|
});
|
|
581
|
-
const processZones = () => __async(
|
|
581
|
+
const processZones = () => __async(null, null, function* () {
|
|
582
582
|
var _a2;
|
|
583
583
|
const zones = (_a2 = data.zones) != null ? _a2 : {};
|
|
584
|
-
Object.entries(zones).forEach((_02) => __async(
|
|
584
|
+
Object.entries(zones).forEach((_02) => __async(null, [_02], function* ([zoneKey, content]) {
|
|
585
585
|
zones[zoneKey] = yield Promise.all(content.map(resolveNode));
|
|
586
586
|
}));
|
|
587
587
|
return zones;
|
|
@@ -591,7 +591,7 @@ function resolveAllData(_0, _1) {
|
|
|
591
591
|
content: yield processContent(defaultedData.content),
|
|
592
592
|
zones: yield processZones()
|
|
593
593
|
};
|
|
594
|
-
Object.keys((_a = defaultedData.zones) != null ? _a : {}).forEach((zoneKey) => __async(
|
|
594
|
+
Object.keys((_a = defaultedData.zones) != null ? _a : {}).forEach((zoneKey) => __async(null, null, function* () {
|
|
595
595
|
const content = defaultedData.zones[zoneKey];
|
|
596
596
|
dynamic.zones[zoneKey] = yield processContent(content);
|
|
597
597
|
}), {});
|
package/dist/rsc.mjs
CHANGED
|
@@ -10,63 +10,63 @@ type FieldOption = {
|
|
|
10
10
|
value: string | number | boolean | undefined | null | object;
|
|
11
11
|
};
|
|
12
12
|
type FieldOptions = Array<FieldOption> | ReadonlyArray<FieldOption>;
|
|
13
|
-
|
|
13
|
+
interface BaseField {
|
|
14
14
|
label?: string;
|
|
15
15
|
labelIcon?: ReactElement;
|
|
16
|
-
metadata?:
|
|
16
|
+
metadata?: FieldMetadata;
|
|
17
17
|
visible?: boolean;
|
|
18
|
-
}
|
|
19
|
-
|
|
18
|
+
}
|
|
19
|
+
interface TextField extends BaseField {
|
|
20
20
|
type: "text";
|
|
21
21
|
placeholder?: string;
|
|
22
22
|
contentEditable?: boolean;
|
|
23
|
-
}
|
|
24
|
-
|
|
23
|
+
}
|
|
24
|
+
interface NumberField extends BaseField {
|
|
25
25
|
type: "number";
|
|
26
26
|
placeholder?: string;
|
|
27
27
|
min?: number;
|
|
28
28
|
max?: number;
|
|
29
29
|
step?: number;
|
|
30
|
-
}
|
|
31
|
-
|
|
30
|
+
}
|
|
31
|
+
interface TextareaField extends BaseField {
|
|
32
32
|
type: "textarea";
|
|
33
33
|
placeholder?: string;
|
|
34
34
|
contentEditable?: boolean;
|
|
35
|
-
}
|
|
36
|
-
|
|
35
|
+
}
|
|
36
|
+
interface SelectField extends BaseField {
|
|
37
37
|
type: "select";
|
|
38
38
|
options: FieldOptions;
|
|
39
|
-
}
|
|
40
|
-
|
|
39
|
+
}
|
|
40
|
+
interface RadioField extends BaseField {
|
|
41
41
|
type: "radio";
|
|
42
42
|
options: FieldOptions;
|
|
43
|
-
}
|
|
44
|
-
|
|
43
|
+
}
|
|
44
|
+
interface ArrayField<Props extends {
|
|
45
45
|
[key: string]: any;
|
|
46
46
|
}[] = {
|
|
47
47
|
[key: string]: any;
|
|
48
|
-
}[], UserField extends {} = {}>
|
|
48
|
+
}[], UserField extends {} = {}> extends BaseField {
|
|
49
49
|
type: "array";
|
|
50
50
|
arrayFields: {
|
|
51
51
|
[SubPropName in keyof Props[0]]: UserField extends {
|
|
52
52
|
type: PropertyKey;
|
|
53
53
|
} ? Field<Props[0][SubPropName], UserField> | UserField : Field<Props[0][SubPropName], UserField>;
|
|
54
54
|
};
|
|
55
|
-
defaultItemProps?: Props[0];
|
|
55
|
+
defaultItemProps?: Props[0] | ((index: number) => Props[0]);
|
|
56
56
|
getItemSummary?: (item: Props[0], index?: number) => string;
|
|
57
57
|
max?: number;
|
|
58
58
|
min?: number;
|
|
59
|
-
}
|
|
60
|
-
|
|
59
|
+
}
|
|
60
|
+
interface ObjectField<Props extends any = {
|
|
61
61
|
[key: string]: any;
|
|
62
|
-
}, UserField extends {} = {}>
|
|
62
|
+
}, UserField extends {} = {}> extends BaseField {
|
|
63
63
|
type: "object";
|
|
64
64
|
objectFields: {
|
|
65
65
|
[SubPropName in keyof Props]: UserField extends {
|
|
66
66
|
type: PropertyKey;
|
|
67
67
|
} ? Field<Props[SubPropName]> | UserField : Field<Props[SubPropName]>;
|
|
68
68
|
};
|
|
69
|
-
}
|
|
69
|
+
}
|
|
70
70
|
type Adaptor<AdaptorParams = {}, TableShape extends Record<string, any> = {}, PropShape = TableShape> = {
|
|
71
71
|
name: string;
|
|
72
72
|
fetchList: (adaptorParams?: AdaptorParams) => Promise<TableShape[] | null>;
|
|
@@ -82,10 +82,14 @@ type ExternalFieldWithAdaptor<Props extends any = {
|
|
|
82
82
|
adaptorParams?: object;
|
|
83
83
|
getItemSummary: (item: NotUndefined<Props>, index?: number) => string;
|
|
84
84
|
};
|
|
85
|
-
type
|
|
85
|
+
type CacheOpts = {
|
|
86
|
+
enabled?: boolean;
|
|
87
|
+
};
|
|
88
|
+
interface ExternalField<Props extends any = {
|
|
86
89
|
[key: string]: any;
|
|
87
|
-
}>
|
|
90
|
+
}> extends BaseField {
|
|
88
91
|
type: "external";
|
|
92
|
+
cache?: CacheOpts;
|
|
89
93
|
placeholder?: string;
|
|
90
94
|
fetchList: (params: {
|
|
91
95
|
query: string;
|
|
@@ -101,7 +105,7 @@ type ExternalField<Props extends any = {
|
|
|
101
105
|
initialQuery?: string;
|
|
102
106
|
filterFields?: Record<string, Field>;
|
|
103
107
|
initialFilters?: Record<string, any>;
|
|
104
|
-
}
|
|
108
|
+
}
|
|
105
109
|
type CustomFieldRender<Value extends any> = (props: {
|
|
106
110
|
field: CustomField<Value>;
|
|
107
111
|
name: string;
|
|
@@ -110,16 +114,16 @@ type CustomFieldRender<Value extends any> = (props: {
|
|
|
110
114
|
onChange: (value: Value) => void;
|
|
111
115
|
readOnly?: boolean;
|
|
112
116
|
}) => ReactElement;
|
|
113
|
-
|
|
117
|
+
interface CustomField<Value extends any> extends BaseField {
|
|
114
118
|
type: "custom";
|
|
115
119
|
render: CustomFieldRender<Value>;
|
|
116
120
|
contentEditable?: boolean;
|
|
117
|
-
}
|
|
118
|
-
|
|
121
|
+
}
|
|
122
|
+
interface SlotField extends BaseField {
|
|
119
123
|
type: "slot";
|
|
120
124
|
allow?: string[];
|
|
121
125
|
disallow?: string[];
|
|
122
|
-
}
|
|
126
|
+
}
|
|
123
127
|
type Field<ValueType = any, UserField extends {} = {}> = TextField | NumberField | TextareaField | SelectField | RadioField | ArrayField<ValueType extends {
|
|
124
128
|
[key: string]: any;
|
|
125
129
|
}[] ? ValueType : never, UserField> | ObjectField<ValueType, UserField> | ExternalField<ValueType> | ExternalFieldWithAdaptor<ValueType> | CustomField<ValueType> | SlotField;
|
|
@@ -147,7 +151,7 @@ type DropZoneProps = {
|
|
|
147
151
|
};
|
|
148
152
|
|
|
149
153
|
type PuckContext = {
|
|
150
|
-
renderDropZone: React.
|
|
154
|
+
renderDropZone: (props: DropZoneProps) => React.ReactNode;
|
|
151
155
|
metadata: Metadata;
|
|
152
156
|
isEditing: boolean;
|
|
153
157
|
dragRef: ((element: Element | null) => void) | null;
|
|
@@ -197,6 +201,8 @@ type ResolveDataTrigger = "insert" | "replace" | "load" | "force";
|
|
|
197
201
|
type WithPartialProps<T, Props extends DefaultComponentProps> = Omit<T, "props"> & {
|
|
198
202
|
props?: Partial<Props>;
|
|
199
203
|
};
|
|
204
|
+
interface ComponentConfigExtensions {
|
|
205
|
+
}
|
|
200
206
|
type ComponentConfigInternal<RenderProps extends DefaultComponentProps, FieldProps extends DefaultComponentProps, DataShape = Omit<ComponentData<FieldProps>, "type">, // NB this doesn't include AllProps, so types will not contain deep slot types. To fix, we require a breaking change.
|
|
201
207
|
UserField extends BaseField = {}> = {
|
|
202
208
|
render: PuckComponent<RenderProps>;
|
|
@@ -212,7 +218,7 @@ UserField extends BaseField = {}> = {
|
|
|
212
218
|
fields: Fields<FieldProps>;
|
|
213
219
|
lastFields: Fields<FieldProps>;
|
|
214
220
|
lastData: DataShape | null;
|
|
215
|
-
metadata:
|
|
221
|
+
metadata: ComponentMetadata;
|
|
216
222
|
appState: AppState;
|
|
217
223
|
parent: ComponentData | null;
|
|
218
224
|
}) => Promise<Fields<FieldProps>> | Fields<FieldProps>;
|
|
@@ -221,7 +227,7 @@ UserField extends BaseField = {}> = {
|
|
|
221
227
|
id: string;
|
|
222
228
|
}>;
|
|
223
229
|
lastData: DataShape | null;
|
|
224
|
-
metadata:
|
|
230
|
+
metadata: ComponentMetadata;
|
|
225
231
|
trigger: ResolveDataTrigger;
|
|
226
232
|
}) => Promise<WithPartialProps<DataShape, FieldProps>> | WithPartialProps<DataShape, FieldProps>;
|
|
227
233
|
resolvePermissions?: (data: DataShape, params: {
|
|
@@ -233,8 +239,8 @@ UserField extends BaseField = {}> = {
|
|
|
233
239
|
appState: AppState;
|
|
234
240
|
lastData: DataShape | null;
|
|
235
241
|
}) => Promise<Partial<Permissions>> | Partial<Permissions>;
|
|
236
|
-
metadata?:
|
|
237
|
-
};
|
|
242
|
+
metadata?: ComponentMetadata;
|
|
243
|
+
} & ComponentConfigExtensions;
|
|
238
244
|
type ComponentConfig<RenderPropsOrParams extends LeftOrExactRight<RenderPropsOrParams, DefaultComponentProps, ComponentConfigParams> = DefaultComponentProps, FieldProps extends DefaultComponentProps = RenderPropsOrParams extends {
|
|
239
245
|
props: any;
|
|
240
246
|
} ? RenderPropsOrParams["props"] : RenderPropsOrParams, DataShape = Omit<ComponentData<FieldProps>, "type">> = RenderPropsOrParams extends ComponentConfigParams<infer ParamsRenderProps, never> ? ComponentConfigInternal<ParamsRenderProps, FieldProps, DataShape, {}> : RenderPropsOrParams extends ComponentConfigParams<infer ParamsRenderProps, infer ParamsFields> ? ComponentConfigInternal<ParamsRenderProps, FieldProps, DataShape, ParamsFields[keyof ParamsFields] & BaseField> : ComponentConfigInternal<RenderPropsOrParams, FieldProps, DataShape>;
|
|
@@ -265,6 +271,16 @@ type ExtractConfigParams<UserConfig extends ConfigInternal> = UserConfig extends
|
|
|
265
271
|
type: string;
|
|
266
272
|
} ? UserField : Field;
|
|
267
273
|
} : never;
|
|
274
|
+
type ConfigParams<Components extends DefaultComponents = DefaultComponents, RootProps extends DefaultComponentProps = any, CategoryNames extends string[] = string[], UserFields extends FieldsExtension = FieldsExtension> = {
|
|
275
|
+
components?: Components;
|
|
276
|
+
root?: RootProps;
|
|
277
|
+
categories?: CategoryNames;
|
|
278
|
+
fields?: AssertHasValue<UserFields>;
|
|
279
|
+
};
|
|
280
|
+
type ComponentConfigParams<Props extends DefaultComponentProps = DefaultComponentProps, UserFields extends FieldsExtension = never> = {
|
|
281
|
+
props: Props;
|
|
282
|
+
fields?: AssertHasValue<UserFields>;
|
|
283
|
+
};
|
|
268
284
|
|
|
269
285
|
type BaseData<Props extends {
|
|
270
286
|
[key: string]: any;
|
|
@@ -305,6 +321,12 @@ type Data<Components extends DefaultComponents = DefaultComponents, RootProps ex
|
|
|
305
321
|
type Metadata = {
|
|
306
322
|
[key: string]: any;
|
|
307
323
|
};
|
|
324
|
+
interface PuckMetadata extends Metadata {
|
|
325
|
+
}
|
|
326
|
+
interface ComponentMetadata extends PuckMetadata {
|
|
327
|
+
}
|
|
328
|
+
interface FieldMetadata extends Metadata {
|
|
329
|
+
}
|
|
308
330
|
|
|
309
331
|
type ItemWithId = {
|
|
310
332
|
_arrayId: string;
|
|
@@ -373,21 +395,11 @@ type BuiltinTypes = Date | RegExp | Error | Function | symbol | null | undefined
|
|
|
373
395
|
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 BuiltinTypes ? T : T extends object ? {
|
|
374
396
|
[K in keyof T]: WithDeepSlots<T[K], SlotType>;
|
|
375
397
|
} : T;
|
|
376
|
-
type ConfigParams<Components extends DefaultComponents = DefaultComponents, RootProps extends DefaultComponentProps = any, CategoryNames extends string[] = string[], UserFields extends FieldsExtension = FieldsExtension> = {
|
|
377
|
-
components?: Components;
|
|
378
|
-
root?: RootProps;
|
|
379
|
-
categories?: CategoryNames;
|
|
380
|
-
fields?: AssertHasValue<UserFields>;
|
|
381
|
-
};
|
|
382
398
|
type FieldsExtension = {
|
|
383
399
|
[Type in string]: {
|
|
384
400
|
type: Type;
|
|
385
401
|
};
|
|
386
402
|
};
|
|
387
|
-
type ComponentConfigParams<Props extends DefaultComponentProps = DefaultComponentProps, UserFields extends FieldsExtension = never> = {
|
|
388
|
-
props: Props;
|
|
389
|
-
fields?: AssertHasValue<UserFields>;
|
|
390
|
-
};
|
|
391
403
|
type Exact<T, Target> = Record<Exclude<keyof T, keyof Target>, never>;
|
|
392
404
|
type LeftOrExactRight<Union, Left, Right> = (Left & Union extends Right ? Exact<Union, Right> : Left) | (Right & Exact<Union, Right>);
|
|
393
405
|
type AssertHasValue<T, True = T, False = never> = [keyof T] extends [
|
|
@@ -631,4 +643,4 @@ type WalkTreeOptions = {
|
|
|
631
643
|
};
|
|
632
644
|
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;
|
|
633
645
|
|
|
634
|
-
export { type
|
|
646
|
+
export { type MappedItem as $, type AppState as A, type ArrayState as B, type Config as C, type DropZoneProps as D, type SlotComponent as E, type Fields as F, type PuckComponent as G, type History as H, type IframeConfig as I, type ComponentConfigExtensions as J, type RootConfig as K, type DefaultComponents as L, type Metadata as M, type ExtractConfigParams as N, type Overrides as O, type Permissions as P, type ConfigParams as Q, type RootDataWithProps as R, type Slot as S, type ComponentConfigParams as T, type UserGenerics as U, type Viewports as V, type WithSlotProps as W, type BaseData as X, type RootDataWithoutProps as Y, type RootData as Z, type ComponentDataOptionalId as _, type ComponentData as a, type ComponentDataMap as a0, type Content as a1, type PuckMetadata as a2, type ComponentMetadata as a3, type FieldMetadata as a4, type BaseField as a5, type TextField as a6, type NumberField as a7, type TextareaField as a8, type SelectField as a9, type RadioField as aa, type ArrayField as ab, type ObjectField as ac, type Adaptor as ad, type ExternalFieldWithAdaptor as ae, type CacheOpts as af, type ExternalField as ag, type CustomFieldRender as ah, type CustomField as ai, type SlotField as aj, type PuckContext as ak, type DefaultRootFieldProps as al, type DefaultRootRenderProps as am, type DefaultRootProps as an, type DefaultComponentProps as ao, type WithId as ap, type WithPuckProps as aq, type AsFieldProps as ar, type WithChildren as as, type ExtractField as at, type PuckAction as b, type ResolveDataTrigger as c, type Plugin as d, type UiState as e, type ComponentConfig as f, type FieldTransforms as g, type Field as h, type FieldProps as i, type Data as j, type OnAction as k, type InitialHistory as l, migrate as m, type ItemSelector as n, type Direction as o, type DragAxis as p, type Viewport as q, resolveAllData as r, type FieldTransformFnParams as s, transformProps as t, type FieldTransformFn as u, overrideKeys as v, walkTree as w, type OverrideKey as x, type FieldRenderFunctions as y, type ItemWithId as z };
|
|
@@ -10,63 +10,63 @@ type FieldOption = {
|
|
|
10
10
|
value: string | number | boolean | undefined | null | object;
|
|
11
11
|
};
|
|
12
12
|
type FieldOptions = Array<FieldOption> | ReadonlyArray<FieldOption>;
|
|
13
|
-
|
|
13
|
+
interface BaseField {
|
|
14
14
|
label?: string;
|
|
15
15
|
labelIcon?: ReactElement;
|
|
16
|
-
metadata?:
|
|
16
|
+
metadata?: FieldMetadata;
|
|
17
17
|
visible?: boolean;
|
|
18
|
-
}
|
|
19
|
-
|
|
18
|
+
}
|
|
19
|
+
interface TextField extends BaseField {
|
|
20
20
|
type: "text";
|
|
21
21
|
placeholder?: string;
|
|
22
22
|
contentEditable?: boolean;
|
|
23
|
-
}
|
|
24
|
-
|
|
23
|
+
}
|
|
24
|
+
interface NumberField extends BaseField {
|
|
25
25
|
type: "number";
|
|
26
26
|
placeholder?: string;
|
|
27
27
|
min?: number;
|
|
28
28
|
max?: number;
|
|
29
29
|
step?: number;
|
|
30
|
-
}
|
|
31
|
-
|
|
30
|
+
}
|
|
31
|
+
interface TextareaField extends BaseField {
|
|
32
32
|
type: "textarea";
|
|
33
33
|
placeholder?: string;
|
|
34
34
|
contentEditable?: boolean;
|
|
35
|
-
}
|
|
36
|
-
|
|
35
|
+
}
|
|
36
|
+
interface SelectField extends BaseField {
|
|
37
37
|
type: "select";
|
|
38
38
|
options: FieldOptions;
|
|
39
|
-
}
|
|
40
|
-
|
|
39
|
+
}
|
|
40
|
+
interface RadioField extends BaseField {
|
|
41
41
|
type: "radio";
|
|
42
42
|
options: FieldOptions;
|
|
43
|
-
}
|
|
44
|
-
|
|
43
|
+
}
|
|
44
|
+
interface ArrayField<Props extends {
|
|
45
45
|
[key: string]: any;
|
|
46
46
|
}[] = {
|
|
47
47
|
[key: string]: any;
|
|
48
|
-
}[], UserField extends {} = {}>
|
|
48
|
+
}[], UserField extends {} = {}> extends BaseField {
|
|
49
49
|
type: "array";
|
|
50
50
|
arrayFields: {
|
|
51
51
|
[SubPropName in keyof Props[0]]: UserField extends {
|
|
52
52
|
type: PropertyKey;
|
|
53
53
|
} ? Field<Props[0][SubPropName], UserField> | UserField : Field<Props[0][SubPropName], UserField>;
|
|
54
54
|
};
|
|
55
|
-
defaultItemProps?: Props[0];
|
|
55
|
+
defaultItemProps?: Props[0] | ((index: number) => Props[0]);
|
|
56
56
|
getItemSummary?: (item: Props[0], index?: number) => string;
|
|
57
57
|
max?: number;
|
|
58
58
|
min?: number;
|
|
59
|
-
}
|
|
60
|
-
|
|
59
|
+
}
|
|
60
|
+
interface ObjectField<Props extends any = {
|
|
61
61
|
[key: string]: any;
|
|
62
|
-
}, UserField extends {} = {}>
|
|
62
|
+
}, UserField extends {} = {}> extends BaseField {
|
|
63
63
|
type: "object";
|
|
64
64
|
objectFields: {
|
|
65
65
|
[SubPropName in keyof Props]: UserField extends {
|
|
66
66
|
type: PropertyKey;
|
|
67
67
|
} ? Field<Props[SubPropName]> | UserField : Field<Props[SubPropName]>;
|
|
68
68
|
};
|
|
69
|
-
}
|
|
69
|
+
}
|
|
70
70
|
type Adaptor<AdaptorParams = {}, TableShape extends Record<string, any> = {}, PropShape = TableShape> = {
|
|
71
71
|
name: string;
|
|
72
72
|
fetchList: (adaptorParams?: AdaptorParams) => Promise<TableShape[] | null>;
|
|
@@ -82,10 +82,14 @@ type ExternalFieldWithAdaptor<Props extends any = {
|
|
|
82
82
|
adaptorParams?: object;
|
|
83
83
|
getItemSummary: (item: NotUndefined<Props>, index?: number) => string;
|
|
84
84
|
};
|
|
85
|
-
type
|
|
85
|
+
type CacheOpts = {
|
|
86
|
+
enabled?: boolean;
|
|
87
|
+
};
|
|
88
|
+
interface ExternalField<Props extends any = {
|
|
86
89
|
[key: string]: any;
|
|
87
|
-
}>
|
|
90
|
+
}> extends BaseField {
|
|
88
91
|
type: "external";
|
|
92
|
+
cache?: CacheOpts;
|
|
89
93
|
placeholder?: string;
|
|
90
94
|
fetchList: (params: {
|
|
91
95
|
query: string;
|
|
@@ -101,7 +105,7 @@ type ExternalField<Props extends any = {
|
|
|
101
105
|
initialQuery?: string;
|
|
102
106
|
filterFields?: Record<string, Field>;
|
|
103
107
|
initialFilters?: Record<string, any>;
|
|
104
|
-
}
|
|
108
|
+
}
|
|
105
109
|
type CustomFieldRender<Value extends any> = (props: {
|
|
106
110
|
field: CustomField<Value>;
|
|
107
111
|
name: string;
|
|
@@ -110,16 +114,16 @@ type CustomFieldRender<Value extends any> = (props: {
|
|
|
110
114
|
onChange: (value: Value) => void;
|
|
111
115
|
readOnly?: boolean;
|
|
112
116
|
}) => ReactElement;
|
|
113
|
-
|
|
117
|
+
interface CustomField<Value extends any> extends BaseField {
|
|
114
118
|
type: "custom";
|
|
115
119
|
render: CustomFieldRender<Value>;
|
|
116
120
|
contentEditable?: boolean;
|
|
117
|
-
}
|
|
118
|
-
|
|
121
|
+
}
|
|
122
|
+
interface SlotField extends BaseField {
|
|
119
123
|
type: "slot";
|
|
120
124
|
allow?: string[];
|
|
121
125
|
disallow?: string[];
|
|
122
|
-
}
|
|
126
|
+
}
|
|
123
127
|
type Field<ValueType = any, UserField extends {} = {}> = TextField | NumberField | TextareaField | SelectField | RadioField | ArrayField<ValueType extends {
|
|
124
128
|
[key: string]: any;
|
|
125
129
|
}[] ? ValueType : never, UserField> | ObjectField<ValueType, UserField> | ExternalField<ValueType> | ExternalFieldWithAdaptor<ValueType> | CustomField<ValueType> | SlotField;
|
|
@@ -147,7 +151,7 @@ type DropZoneProps = {
|
|
|
147
151
|
};
|
|
148
152
|
|
|
149
153
|
type PuckContext = {
|
|
150
|
-
renderDropZone: React.
|
|
154
|
+
renderDropZone: (props: DropZoneProps) => React.ReactNode;
|
|
151
155
|
metadata: Metadata;
|
|
152
156
|
isEditing: boolean;
|
|
153
157
|
dragRef: ((element: Element | null) => void) | null;
|
|
@@ -197,6 +201,8 @@ type ResolveDataTrigger = "insert" | "replace" | "load" | "force";
|
|
|
197
201
|
type WithPartialProps<T, Props extends DefaultComponentProps> = Omit<T, "props"> & {
|
|
198
202
|
props?: Partial<Props>;
|
|
199
203
|
};
|
|
204
|
+
interface ComponentConfigExtensions {
|
|
205
|
+
}
|
|
200
206
|
type ComponentConfigInternal<RenderProps extends DefaultComponentProps, FieldProps extends DefaultComponentProps, DataShape = Omit<ComponentData<FieldProps>, "type">, // NB this doesn't include AllProps, so types will not contain deep slot types. To fix, we require a breaking change.
|
|
201
207
|
UserField extends BaseField = {}> = {
|
|
202
208
|
render: PuckComponent<RenderProps>;
|
|
@@ -212,7 +218,7 @@ UserField extends BaseField = {}> = {
|
|
|
212
218
|
fields: Fields<FieldProps>;
|
|
213
219
|
lastFields: Fields<FieldProps>;
|
|
214
220
|
lastData: DataShape | null;
|
|
215
|
-
metadata:
|
|
221
|
+
metadata: ComponentMetadata;
|
|
216
222
|
appState: AppState;
|
|
217
223
|
parent: ComponentData | null;
|
|
218
224
|
}) => Promise<Fields<FieldProps>> | Fields<FieldProps>;
|
|
@@ -221,7 +227,7 @@ UserField extends BaseField = {}> = {
|
|
|
221
227
|
id: string;
|
|
222
228
|
}>;
|
|
223
229
|
lastData: DataShape | null;
|
|
224
|
-
metadata:
|
|
230
|
+
metadata: ComponentMetadata;
|
|
225
231
|
trigger: ResolveDataTrigger;
|
|
226
232
|
}) => Promise<WithPartialProps<DataShape, FieldProps>> | WithPartialProps<DataShape, FieldProps>;
|
|
227
233
|
resolvePermissions?: (data: DataShape, params: {
|
|
@@ -233,8 +239,8 @@ UserField extends BaseField = {}> = {
|
|
|
233
239
|
appState: AppState;
|
|
234
240
|
lastData: DataShape | null;
|
|
235
241
|
}) => Promise<Partial<Permissions>> | Partial<Permissions>;
|
|
236
|
-
metadata?:
|
|
237
|
-
};
|
|
242
|
+
metadata?: ComponentMetadata;
|
|
243
|
+
} & ComponentConfigExtensions;
|
|
238
244
|
type ComponentConfig<RenderPropsOrParams extends LeftOrExactRight<RenderPropsOrParams, DefaultComponentProps, ComponentConfigParams> = DefaultComponentProps, FieldProps extends DefaultComponentProps = RenderPropsOrParams extends {
|
|
239
245
|
props: any;
|
|
240
246
|
} ? RenderPropsOrParams["props"] : RenderPropsOrParams, DataShape = Omit<ComponentData<FieldProps>, "type">> = RenderPropsOrParams extends ComponentConfigParams<infer ParamsRenderProps, never> ? ComponentConfigInternal<ParamsRenderProps, FieldProps, DataShape, {}> : RenderPropsOrParams extends ComponentConfigParams<infer ParamsRenderProps, infer ParamsFields> ? ComponentConfigInternal<ParamsRenderProps, FieldProps, DataShape, ParamsFields[keyof ParamsFields] & BaseField> : ComponentConfigInternal<RenderPropsOrParams, FieldProps, DataShape>;
|
|
@@ -265,6 +271,16 @@ type ExtractConfigParams<UserConfig extends ConfigInternal> = UserConfig extends
|
|
|
265
271
|
type: string;
|
|
266
272
|
} ? UserField : Field;
|
|
267
273
|
} : never;
|
|
274
|
+
type ConfigParams<Components extends DefaultComponents = DefaultComponents, RootProps extends DefaultComponentProps = any, CategoryNames extends string[] = string[], UserFields extends FieldsExtension = FieldsExtension> = {
|
|
275
|
+
components?: Components;
|
|
276
|
+
root?: RootProps;
|
|
277
|
+
categories?: CategoryNames;
|
|
278
|
+
fields?: AssertHasValue<UserFields>;
|
|
279
|
+
};
|
|
280
|
+
type ComponentConfigParams<Props extends DefaultComponentProps = DefaultComponentProps, UserFields extends FieldsExtension = never> = {
|
|
281
|
+
props: Props;
|
|
282
|
+
fields?: AssertHasValue<UserFields>;
|
|
283
|
+
};
|
|
268
284
|
|
|
269
285
|
type BaseData<Props extends {
|
|
270
286
|
[key: string]: any;
|
|
@@ -305,6 +321,12 @@ type Data<Components extends DefaultComponents = DefaultComponents, RootProps ex
|
|
|
305
321
|
type Metadata = {
|
|
306
322
|
[key: string]: any;
|
|
307
323
|
};
|
|
324
|
+
interface PuckMetadata extends Metadata {
|
|
325
|
+
}
|
|
326
|
+
interface ComponentMetadata extends PuckMetadata {
|
|
327
|
+
}
|
|
328
|
+
interface FieldMetadata extends Metadata {
|
|
329
|
+
}
|
|
308
330
|
|
|
309
331
|
type ItemWithId = {
|
|
310
332
|
_arrayId: string;
|
|
@@ -373,21 +395,11 @@ type BuiltinTypes = Date | RegExp | Error | Function | symbol | null | undefined
|
|
|
373
395
|
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 BuiltinTypes ? T : T extends object ? {
|
|
374
396
|
[K in keyof T]: WithDeepSlots<T[K], SlotType>;
|
|
375
397
|
} : T;
|
|
376
|
-
type ConfigParams<Components extends DefaultComponents = DefaultComponents, RootProps extends DefaultComponentProps = any, CategoryNames extends string[] = string[], UserFields extends FieldsExtension = FieldsExtension> = {
|
|
377
|
-
components?: Components;
|
|
378
|
-
root?: RootProps;
|
|
379
|
-
categories?: CategoryNames;
|
|
380
|
-
fields?: AssertHasValue<UserFields>;
|
|
381
|
-
};
|
|
382
398
|
type FieldsExtension = {
|
|
383
399
|
[Type in string]: {
|
|
384
400
|
type: Type;
|
|
385
401
|
};
|
|
386
402
|
};
|
|
387
|
-
type ComponentConfigParams<Props extends DefaultComponentProps = DefaultComponentProps, UserFields extends FieldsExtension = never> = {
|
|
388
|
-
props: Props;
|
|
389
|
-
fields?: AssertHasValue<UserFields>;
|
|
390
|
-
};
|
|
391
403
|
type Exact<T, Target> = Record<Exclude<keyof T, keyof Target>, never>;
|
|
392
404
|
type LeftOrExactRight<Union, Left, Right> = (Left & Union extends Right ? Exact<Union, Right> : Left) | (Right & Exact<Union, Right>);
|
|
393
405
|
type AssertHasValue<T, True = T, False = never> = [keyof T] extends [
|
|
@@ -631,4 +643,4 @@ type WalkTreeOptions = {
|
|
|
631
643
|
};
|
|
632
644
|
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;
|
|
633
645
|
|
|
634
|
-
export { type
|
|
646
|
+
export { type MappedItem as $, type AppState as A, type ArrayState as B, type Config as C, type DropZoneProps as D, type SlotComponent as E, type Fields as F, type PuckComponent as G, type History as H, type IframeConfig as I, type ComponentConfigExtensions as J, type RootConfig as K, type DefaultComponents as L, type Metadata as M, type ExtractConfigParams as N, type Overrides as O, type Permissions as P, type ConfigParams as Q, type RootDataWithProps as R, type Slot as S, type ComponentConfigParams as T, type UserGenerics as U, type Viewports as V, type WithSlotProps as W, type BaseData as X, type RootDataWithoutProps as Y, type RootData as Z, type ComponentDataOptionalId as _, type ComponentData as a, type ComponentDataMap as a0, type Content as a1, type PuckMetadata as a2, type ComponentMetadata as a3, type FieldMetadata as a4, type BaseField as a5, type TextField as a6, type NumberField as a7, type TextareaField as a8, type SelectField as a9, type RadioField as aa, type ArrayField as ab, type ObjectField as ac, type Adaptor as ad, type ExternalFieldWithAdaptor as ae, type CacheOpts as af, type ExternalField as ag, type CustomFieldRender as ah, type CustomField as ai, type SlotField as aj, type PuckContext as ak, type DefaultRootFieldProps as al, type DefaultRootRenderProps as am, type DefaultRootProps as an, type DefaultComponentProps as ao, type WithId as ap, type WithPuckProps as aq, type AsFieldProps as ar, type WithChildren as as, type ExtractField as at, type PuckAction as b, type ResolveDataTrigger as c, type Plugin as d, type UiState as e, type ComponentConfig as f, type FieldTransforms as g, type Field as h, type FieldProps as i, type Data as j, type OnAction as k, type InitialHistory as l, migrate as m, type ItemSelector as n, type Direction as o, type DragAxis as p, type Viewport as q, resolveAllData as r, type FieldTransformFnParams as s, transformProps as t, type FieldTransformFn as u, overrideKeys as v, walkTree as w, type OverrideKey as x, type FieldRenderFunctions as y, type ItemWithId as z };
|
package/package.json
CHANGED