@puckeditor/plugin-heading-analyzer 0.23.0-canary.fb9392de → 0.24.0-canary.03e660bb
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/LICENSE +21 -0
- package/dist/index.d.mts +87 -21
- package/dist/index.d.ts +87 -21
- package/dist/index.js +28 -1886
- package/dist/index.mjs +28 -1886
- package/package.json +14 -12
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) The Puck Contributors.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ElementType, CSSProperties, Ref, ComponentPropsWithoutRef, ReactElement, ReactNode, JSX } from 'react';
|
|
2
2
|
import { EditorStateSnapshot, Editor, Extensions } from '@tiptap/react';
|
|
3
3
|
import { BlockquoteOptions } from '@tiptap/extension-blockquote';
|
|
4
4
|
import { BoldOptions } from '@tiptap/extension-bold';
|
|
@@ -20,6 +20,62 @@ type ItemSelector = {
|
|
|
20
20
|
zone?: string;
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
+
/**
|
|
24
|
+
* Props consumed by Puck internally that are shared between DropZones and slots.
|
|
25
|
+
*/
|
|
26
|
+
type DropZoneSharedProps<ComponentType extends ElementType = "div"> = {
|
|
27
|
+
allow?: string[];
|
|
28
|
+
disallow?: string[];
|
|
29
|
+
style?: CSSProperties;
|
|
30
|
+
minEmptyHeight?: CSSProperties["minHeight"] | number;
|
|
31
|
+
className?: string;
|
|
32
|
+
collisionAxis?: DragAxis;
|
|
33
|
+
ref?: Ref<any>;
|
|
34
|
+
as?: ComponentType;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* All props consumed by Puck for a DropZone component. `zone` lives here only.
|
|
38
|
+
*
|
|
39
|
+
* On slots `zone` is injected internally, so slots use {@link SlotProps} instead.
|
|
40
|
+
*/
|
|
41
|
+
type DropZoneOwnProps<ComponentType extends ElementType = "div"> = DropZoneSharedProps<ComponentType> & {
|
|
42
|
+
zone: string;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Unsupported additional props that are never forwarded to `as`.
|
|
46
|
+
*
|
|
47
|
+
* Omitted from the public types AND stripped at runtime.
|
|
48
|
+
*/
|
|
49
|
+
type NonForwardableProps = {
|
|
50
|
+
children?: unknown;
|
|
51
|
+
dangerouslySetInnerHTML?: unknown;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Keys internally consumed by Puck and never forwarded to `as`.
|
|
55
|
+
*/
|
|
56
|
+
type ConsumedPropKey = keyof DropZoneOwnProps | "as" | "content" | "config" | "metadata" | "fieldTransforms";
|
|
57
|
+
/**
|
|
58
|
+
* Additional props forwarded to the element or component provided via `as`,
|
|
59
|
+
* typed against it.
|
|
60
|
+
*
|
|
61
|
+
* Puck-internal/unsupported props are stripped so they don't leak onto the DOM.
|
|
62
|
+
*/
|
|
63
|
+
type ForwardedProps<ComponentType extends ElementType> = Omit<ComponentPropsWithoutRef<ComponentType>, ConsumedPropKey | keyof NonForwardableProps>;
|
|
64
|
+
/**
|
|
65
|
+
* Props for a `DropZone` component.
|
|
66
|
+
*
|
|
67
|
+
* Any additional props not consumed by Puck are forwarded to the element or
|
|
68
|
+
* component provided via `as` (defaulting to a `div`), typed against it.
|
|
69
|
+
*/
|
|
70
|
+
type DropZoneProps<ComponentType extends ElementType = "div"> = DropZoneOwnProps<ComponentType> & ForwardedProps<ComponentType>;
|
|
71
|
+
/**
|
|
72
|
+
* Props for a `slot` render component.
|
|
73
|
+
*
|
|
74
|
+
* Any additional props not consumed by Puck are forwarded to the element or
|
|
75
|
+
* component provided via `as` (defaulting to a `div`), typed against it.
|
|
76
|
+
*/
|
|
77
|
+
type SlotProps<ComponentType extends ElementType = "div"> = DropZoneSharedProps<ComponentType> & ForwardedProps<ComponentType>;
|
|
78
|
+
|
|
23
79
|
declare const defaultEditorState: (ctx: EditorStateSnapshot, readOnly: boolean) => {
|
|
24
80
|
isAlignLeft?: undefined;
|
|
25
81
|
canAlignLeft?: undefined;
|
|
@@ -216,6 +272,10 @@ interface RadioField extends BaseField {
|
|
|
216
272
|
type: "radio";
|
|
217
273
|
options: FieldOptions;
|
|
218
274
|
}
|
|
275
|
+
interface CheckboxField extends BaseField {
|
|
276
|
+
type: "checkbox";
|
|
277
|
+
options: FieldOptions;
|
|
278
|
+
}
|
|
219
279
|
interface RichtextField<UserSelector extends RichTextSelector = RichTextSelector> extends BaseField {
|
|
220
280
|
type: "richtext";
|
|
221
281
|
contentEditable?: boolean;
|
|
@@ -258,6 +318,7 @@ interface ObjectField<Props extends any = {
|
|
|
258
318
|
[key: string]: any;
|
|
259
319
|
}, UserField extends {} = {}> extends BaseField {
|
|
260
320
|
type: "object";
|
|
321
|
+
expandable?: boolean;
|
|
261
322
|
objectFields: {
|
|
262
323
|
[SubPropName in keyof Props]: UserField extends {
|
|
263
324
|
type: PropertyKey;
|
|
@@ -322,7 +383,7 @@ interface SlotField extends BaseField {
|
|
|
322
383
|
allow?: string[];
|
|
323
384
|
disallow?: string[];
|
|
324
385
|
}
|
|
325
|
-
type Field<ValueType = any, UserField extends {} = {}> = TextField | RichtextField | NumberField | TextareaField | SelectField | RadioField | ArrayField<ValueType extends {
|
|
386
|
+
type Field<ValueType = any, UserField extends {} = {}> = TextField | RichtextField | NumberField | TextareaField | SelectField | RadioField | CheckboxField | ArrayField<ValueType extends {
|
|
326
387
|
[key: string]: any;
|
|
327
388
|
}[] ? ValueType : never, UserField> | ObjectField<ValueType, UserField> | ExternalField<ValueType> | ExternalFieldWithAdaptor<ValueType> | CustomField<ValueType> | SlotField;
|
|
328
389
|
type Fields<ComponentProps extends DefaultComponentProps = DefaultComponentProps, UserField extends {} = {}> = {
|
|
@@ -338,20 +399,11 @@ type FieldProps<F = Field<any>, ValueType = any> = {
|
|
|
338
399
|
readOnly?: boolean;
|
|
339
400
|
};
|
|
340
401
|
|
|
341
|
-
type DropZoneProps = {
|
|
342
|
-
zone: string;
|
|
343
|
-
allow?: string[];
|
|
344
|
-
disallow?: string[];
|
|
345
|
-
style?: CSSProperties;
|
|
346
|
-
minEmptyHeight?: CSSProperties["minHeight"] | number;
|
|
347
|
-
className?: string;
|
|
348
|
-
collisionAxis?: DragAxis;
|
|
349
|
-
as?: ElementType;
|
|
350
|
-
ref?: Ref<any>;
|
|
351
|
-
};
|
|
352
|
-
|
|
353
402
|
type PuckContext = {
|
|
354
|
-
|
|
403
|
+
/**
|
|
404
|
+
* @deprecated Use {@link https://puckeditor.com/docs/api-reference/fields/slot Slots} instead.
|
|
405
|
+
*/
|
|
406
|
+
renderDropZone: <ComponentType extends ElementType = "div">(props: DropZoneProps<ComponentType>) => React.ReactNode;
|
|
355
407
|
metadata: Metadata;
|
|
356
408
|
isEditing: boolean;
|
|
357
409
|
dragRef: ((element: Element | null) => void) | null;
|
|
@@ -359,6 +411,12 @@ type PuckContext = {
|
|
|
359
411
|
type DefaultRootFieldProps = {
|
|
360
412
|
title?: string;
|
|
361
413
|
};
|
|
414
|
+
/**
|
|
415
|
+
* Merge the default root field props into user-provided root props, letting
|
|
416
|
+
* the user's props take precedence. Using a plain intersection would turn an
|
|
417
|
+
* overridden `title` (e.g. `number`) into `never` (`number & string`).
|
|
418
|
+
*/
|
|
419
|
+
type WithDefaultRootFieldProps<RootProps> = RootProps & Omit<DefaultRootFieldProps, keyof RootProps>;
|
|
362
420
|
type DefaultComponentProps = {
|
|
363
421
|
[key: string]: any;
|
|
364
422
|
};
|
|
@@ -378,7 +436,7 @@ type UserGenerics<UserConfig extends Config = Config, UserParams extends Extract
|
|
|
378
436
|
UserConfig: UserConfig;
|
|
379
437
|
UserParams: UserParams;
|
|
380
438
|
UserProps: UserParams["props"];
|
|
381
|
-
UserRootProps: UserParams["rootProps"]
|
|
439
|
+
UserRootProps: WithDefaultRootFieldProps<UserParams["rootProps"]>;
|
|
382
440
|
UserData: UserData;
|
|
383
441
|
UserAppState: UserAppState;
|
|
384
442
|
UserPublicAppState: UserPublicAppState;
|
|
@@ -391,7 +449,7 @@ type ExtractField<UserField extends {
|
|
|
391
449
|
type: T;
|
|
392
450
|
}>;
|
|
393
451
|
|
|
394
|
-
type SlotComponent = (props?:
|
|
452
|
+
type SlotComponent = <ComponentType extends ElementType = "div">(props?: SlotProps<ComponentType>) => ReactNode;
|
|
395
453
|
type PuckComponent<Props> = (props: WithId<WithPuckProps<{
|
|
396
454
|
[K in keyof Props]: WithDeepSlots<Props[K], SlotComponent>;
|
|
397
455
|
}>>) => JSX.Element;
|
|
@@ -407,6 +465,9 @@ UserField extends BaseField = {}> = {
|
|
|
407
465
|
label?: string;
|
|
408
466
|
defaultProps?: FieldProps;
|
|
409
467
|
fields?: Fields<FieldProps, UserField>;
|
|
468
|
+
renderFields?: RenderFunc<{
|
|
469
|
+
fields: Partial<Record<keyof FieldProps, ReactNode>>;
|
|
470
|
+
}>;
|
|
410
471
|
permissions?: Partial<Permissions>;
|
|
411
472
|
inline?: boolean;
|
|
412
473
|
resolveFields?: (data: DataShape, params: {
|
|
@@ -462,7 +523,7 @@ type DefaultComponents = Record<string, any>;
|
|
|
462
523
|
type Config<PropsOrParams extends LeftOrExactRight<PropsOrParams, DefaultComponents, ConfigParams> = DefaultComponents | ConfigParams, RootProps extends DefaultComponentProps = any, CategoryName extends string = string> = PropsOrParams extends ConfigParams<infer ParamComponents, infer ParamRoot, infer ParamCategoryName, never> ? ConfigInternal<ParamComponents, ParamRoot, ParamCategoryName[number]> : PropsOrParams extends ConfigParams<infer ParamComponents, infer ParamRoot, infer ParamCategoryName, infer ParamFields> ? ConfigInternal<ParamComponents, ParamRoot, ParamCategoryName[number], ParamFields[keyof ParamFields] & BaseField> : PropsOrParams extends ConfigParams<infer ParamComponents, infer ParamRoot, infer ParamCategoryName, any> ? ConfigInternal<ParamComponents, ParamRoot, ParamCategoryName[number], {}> : ConfigInternal<PropsOrParams, RootProps, CategoryName>;
|
|
463
524
|
type ExtractConfigParams<UserConfig extends ConfigInternal> = UserConfig extends ConfigInternal<infer PropsOrParams, infer RootProps, infer CategoryName, infer UserField> ? {
|
|
464
525
|
props: PropsOrParams;
|
|
465
|
-
rootProps: RootProps
|
|
526
|
+
rootProps: WithDefaultRootFieldProps<RootProps>;
|
|
466
527
|
categoryNames: CategoryName;
|
|
467
528
|
field: UserField extends {
|
|
468
529
|
type: string;
|
|
@@ -545,6 +606,8 @@ type UiState = {
|
|
|
545
606
|
expanded?: boolean;
|
|
546
607
|
}>;
|
|
547
608
|
isDragging: boolean;
|
|
609
|
+
/** Outline items whose children are shown, keyed by item id */
|
|
610
|
+
itemExpanded?: Record<string, boolean>;
|
|
548
611
|
viewports: {
|
|
549
612
|
current: {
|
|
550
613
|
width: number | "100%";
|
|
@@ -553,6 +616,7 @@ type UiState = {
|
|
|
553
616
|
controlsVisible: boolean;
|
|
554
617
|
options: Viewport[];
|
|
555
618
|
};
|
|
619
|
+
expandedFieldGroups: Record<string, boolean>;
|
|
556
620
|
field: {
|
|
557
621
|
focus?: string | null;
|
|
558
622
|
metadata?: Record<string, any>;
|
|
@@ -655,10 +719,12 @@ type Overrides<UserConfig extends Config = Config> = OverridesGeneric<{
|
|
|
655
719
|
children: ReactNode;
|
|
656
720
|
isLoading: boolean;
|
|
657
721
|
itemSelector?: ItemSelector | null;
|
|
722
|
+
fields: Partial<Record<string, ReactNode>>;
|
|
658
723
|
}>;
|
|
659
724
|
fieldLabel: RenderFunc<{
|
|
660
725
|
children?: ReactNode;
|
|
661
726
|
icon?: ReactNode;
|
|
727
|
+
endIcon?: ReactNode;
|
|
662
728
|
label: string;
|
|
663
729
|
el?: "label" | "div";
|
|
664
730
|
readOnly?: boolean;
|
|
@@ -690,12 +756,12 @@ type Overrides<UserConfig extends Config = Config> = OverridesGeneric<{
|
|
|
690
756
|
}>;
|
|
691
757
|
type FieldRenderFunctions<UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>, UserField extends {
|
|
692
758
|
type: string;
|
|
693
|
-
} = Field | G["UserField"]> =
|
|
759
|
+
} = Field | G["UserField"]> = {
|
|
694
760
|
[Type in UserField["type"]]: React.FunctionComponent<FieldProps<ExtractField<UserField, Type>, any> & {
|
|
695
761
|
children: ReactNode;
|
|
696
762
|
name: string;
|
|
697
|
-
}
|
|
698
|
-
}
|
|
763
|
+
}> | null;
|
|
764
|
+
};
|
|
699
765
|
|
|
700
766
|
type DragAxis = "dynamic" | "y" | "x";
|
|
701
767
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ElementType, CSSProperties, Ref, ComponentPropsWithoutRef, ReactElement, ReactNode, JSX } from 'react';
|
|
2
2
|
import { EditorStateSnapshot, Editor, Extensions } from '@tiptap/react';
|
|
3
3
|
import { BlockquoteOptions } from '@tiptap/extension-blockquote';
|
|
4
4
|
import { BoldOptions } from '@tiptap/extension-bold';
|
|
@@ -20,6 +20,62 @@ type ItemSelector = {
|
|
|
20
20
|
zone?: string;
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
+
/**
|
|
24
|
+
* Props consumed by Puck internally that are shared between DropZones and slots.
|
|
25
|
+
*/
|
|
26
|
+
type DropZoneSharedProps<ComponentType extends ElementType = "div"> = {
|
|
27
|
+
allow?: string[];
|
|
28
|
+
disallow?: string[];
|
|
29
|
+
style?: CSSProperties;
|
|
30
|
+
minEmptyHeight?: CSSProperties["minHeight"] | number;
|
|
31
|
+
className?: string;
|
|
32
|
+
collisionAxis?: DragAxis;
|
|
33
|
+
ref?: Ref<any>;
|
|
34
|
+
as?: ComponentType;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* All props consumed by Puck for a DropZone component. `zone` lives here only.
|
|
38
|
+
*
|
|
39
|
+
* On slots `zone` is injected internally, so slots use {@link SlotProps} instead.
|
|
40
|
+
*/
|
|
41
|
+
type DropZoneOwnProps<ComponentType extends ElementType = "div"> = DropZoneSharedProps<ComponentType> & {
|
|
42
|
+
zone: string;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Unsupported additional props that are never forwarded to `as`.
|
|
46
|
+
*
|
|
47
|
+
* Omitted from the public types AND stripped at runtime.
|
|
48
|
+
*/
|
|
49
|
+
type NonForwardableProps = {
|
|
50
|
+
children?: unknown;
|
|
51
|
+
dangerouslySetInnerHTML?: unknown;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Keys internally consumed by Puck and never forwarded to `as`.
|
|
55
|
+
*/
|
|
56
|
+
type ConsumedPropKey = keyof DropZoneOwnProps | "as" | "content" | "config" | "metadata" | "fieldTransforms";
|
|
57
|
+
/**
|
|
58
|
+
* Additional props forwarded to the element or component provided via `as`,
|
|
59
|
+
* typed against it.
|
|
60
|
+
*
|
|
61
|
+
* Puck-internal/unsupported props are stripped so they don't leak onto the DOM.
|
|
62
|
+
*/
|
|
63
|
+
type ForwardedProps<ComponentType extends ElementType> = Omit<ComponentPropsWithoutRef<ComponentType>, ConsumedPropKey | keyof NonForwardableProps>;
|
|
64
|
+
/**
|
|
65
|
+
* Props for a `DropZone` component.
|
|
66
|
+
*
|
|
67
|
+
* Any additional props not consumed by Puck are forwarded to the element or
|
|
68
|
+
* component provided via `as` (defaulting to a `div`), typed against it.
|
|
69
|
+
*/
|
|
70
|
+
type DropZoneProps<ComponentType extends ElementType = "div"> = DropZoneOwnProps<ComponentType> & ForwardedProps<ComponentType>;
|
|
71
|
+
/**
|
|
72
|
+
* Props for a `slot` render component.
|
|
73
|
+
*
|
|
74
|
+
* Any additional props not consumed by Puck are forwarded to the element or
|
|
75
|
+
* component provided via `as` (defaulting to a `div`), typed against it.
|
|
76
|
+
*/
|
|
77
|
+
type SlotProps<ComponentType extends ElementType = "div"> = DropZoneSharedProps<ComponentType> & ForwardedProps<ComponentType>;
|
|
78
|
+
|
|
23
79
|
declare const defaultEditorState: (ctx: EditorStateSnapshot, readOnly: boolean) => {
|
|
24
80
|
isAlignLeft?: undefined;
|
|
25
81
|
canAlignLeft?: undefined;
|
|
@@ -216,6 +272,10 @@ interface RadioField extends BaseField {
|
|
|
216
272
|
type: "radio";
|
|
217
273
|
options: FieldOptions;
|
|
218
274
|
}
|
|
275
|
+
interface CheckboxField extends BaseField {
|
|
276
|
+
type: "checkbox";
|
|
277
|
+
options: FieldOptions;
|
|
278
|
+
}
|
|
219
279
|
interface RichtextField<UserSelector extends RichTextSelector = RichTextSelector> extends BaseField {
|
|
220
280
|
type: "richtext";
|
|
221
281
|
contentEditable?: boolean;
|
|
@@ -258,6 +318,7 @@ interface ObjectField<Props extends any = {
|
|
|
258
318
|
[key: string]: any;
|
|
259
319
|
}, UserField extends {} = {}> extends BaseField {
|
|
260
320
|
type: "object";
|
|
321
|
+
expandable?: boolean;
|
|
261
322
|
objectFields: {
|
|
262
323
|
[SubPropName in keyof Props]: UserField extends {
|
|
263
324
|
type: PropertyKey;
|
|
@@ -322,7 +383,7 @@ interface SlotField extends BaseField {
|
|
|
322
383
|
allow?: string[];
|
|
323
384
|
disallow?: string[];
|
|
324
385
|
}
|
|
325
|
-
type Field<ValueType = any, UserField extends {} = {}> = TextField | RichtextField | NumberField | TextareaField | SelectField | RadioField | ArrayField<ValueType extends {
|
|
386
|
+
type Field<ValueType = any, UserField extends {} = {}> = TextField | RichtextField | NumberField | TextareaField | SelectField | RadioField | CheckboxField | ArrayField<ValueType extends {
|
|
326
387
|
[key: string]: any;
|
|
327
388
|
}[] ? ValueType : never, UserField> | ObjectField<ValueType, UserField> | ExternalField<ValueType> | ExternalFieldWithAdaptor<ValueType> | CustomField<ValueType> | SlotField;
|
|
328
389
|
type Fields<ComponentProps extends DefaultComponentProps = DefaultComponentProps, UserField extends {} = {}> = {
|
|
@@ -338,20 +399,11 @@ type FieldProps<F = Field<any>, ValueType = any> = {
|
|
|
338
399
|
readOnly?: boolean;
|
|
339
400
|
};
|
|
340
401
|
|
|
341
|
-
type DropZoneProps = {
|
|
342
|
-
zone: string;
|
|
343
|
-
allow?: string[];
|
|
344
|
-
disallow?: string[];
|
|
345
|
-
style?: CSSProperties;
|
|
346
|
-
minEmptyHeight?: CSSProperties["minHeight"] | number;
|
|
347
|
-
className?: string;
|
|
348
|
-
collisionAxis?: DragAxis;
|
|
349
|
-
as?: ElementType;
|
|
350
|
-
ref?: Ref<any>;
|
|
351
|
-
};
|
|
352
|
-
|
|
353
402
|
type PuckContext = {
|
|
354
|
-
|
|
403
|
+
/**
|
|
404
|
+
* @deprecated Use {@link https://puckeditor.com/docs/api-reference/fields/slot Slots} instead.
|
|
405
|
+
*/
|
|
406
|
+
renderDropZone: <ComponentType extends ElementType = "div">(props: DropZoneProps<ComponentType>) => React.ReactNode;
|
|
355
407
|
metadata: Metadata;
|
|
356
408
|
isEditing: boolean;
|
|
357
409
|
dragRef: ((element: Element | null) => void) | null;
|
|
@@ -359,6 +411,12 @@ type PuckContext = {
|
|
|
359
411
|
type DefaultRootFieldProps = {
|
|
360
412
|
title?: string;
|
|
361
413
|
};
|
|
414
|
+
/**
|
|
415
|
+
* Merge the default root field props into user-provided root props, letting
|
|
416
|
+
* the user's props take precedence. Using a plain intersection would turn an
|
|
417
|
+
* overridden `title` (e.g. `number`) into `never` (`number & string`).
|
|
418
|
+
*/
|
|
419
|
+
type WithDefaultRootFieldProps<RootProps> = RootProps & Omit<DefaultRootFieldProps, keyof RootProps>;
|
|
362
420
|
type DefaultComponentProps = {
|
|
363
421
|
[key: string]: any;
|
|
364
422
|
};
|
|
@@ -378,7 +436,7 @@ type UserGenerics<UserConfig extends Config = Config, UserParams extends Extract
|
|
|
378
436
|
UserConfig: UserConfig;
|
|
379
437
|
UserParams: UserParams;
|
|
380
438
|
UserProps: UserParams["props"];
|
|
381
|
-
UserRootProps: UserParams["rootProps"]
|
|
439
|
+
UserRootProps: WithDefaultRootFieldProps<UserParams["rootProps"]>;
|
|
382
440
|
UserData: UserData;
|
|
383
441
|
UserAppState: UserAppState;
|
|
384
442
|
UserPublicAppState: UserPublicAppState;
|
|
@@ -391,7 +449,7 @@ type ExtractField<UserField extends {
|
|
|
391
449
|
type: T;
|
|
392
450
|
}>;
|
|
393
451
|
|
|
394
|
-
type SlotComponent = (props?:
|
|
452
|
+
type SlotComponent = <ComponentType extends ElementType = "div">(props?: SlotProps<ComponentType>) => ReactNode;
|
|
395
453
|
type PuckComponent<Props> = (props: WithId<WithPuckProps<{
|
|
396
454
|
[K in keyof Props]: WithDeepSlots<Props[K], SlotComponent>;
|
|
397
455
|
}>>) => JSX.Element;
|
|
@@ -407,6 +465,9 @@ UserField extends BaseField = {}> = {
|
|
|
407
465
|
label?: string;
|
|
408
466
|
defaultProps?: FieldProps;
|
|
409
467
|
fields?: Fields<FieldProps, UserField>;
|
|
468
|
+
renderFields?: RenderFunc<{
|
|
469
|
+
fields: Partial<Record<keyof FieldProps, ReactNode>>;
|
|
470
|
+
}>;
|
|
410
471
|
permissions?: Partial<Permissions>;
|
|
411
472
|
inline?: boolean;
|
|
412
473
|
resolveFields?: (data: DataShape, params: {
|
|
@@ -462,7 +523,7 @@ type DefaultComponents = Record<string, any>;
|
|
|
462
523
|
type Config<PropsOrParams extends LeftOrExactRight<PropsOrParams, DefaultComponents, ConfigParams> = DefaultComponents | ConfigParams, RootProps extends DefaultComponentProps = any, CategoryName extends string = string> = PropsOrParams extends ConfigParams<infer ParamComponents, infer ParamRoot, infer ParamCategoryName, never> ? ConfigInternal<ParamComponents, ParamRoot, ParamCategoryName[number]> : PropsOrParams extends ConfigParams<infer ParamComponents, infer ParamRoot, infer ParamCategoryName, infer ParamFields> ? ConfigInternal<ParamComponents, ParamRoot, ParamCategoryName[number], ParamFields[keyof ParamFields] & BaseField> : PropsOrParams extends ConfigParams<infer ParamComponents, infer ParamRoot, infer ParamCategoryName, any> ? ConfigInternal<ParamComponents, ParamRoot, ParamCategoryName[number], {}> : ConfigInternal<PropsOrParams, RootProps, CategoryName>;
|
|
463
524
|
type ExtractConfigParams<UserConfig extends ConfigInternal> = UserConfig extends ConfigInternal<infer PropsOrParams, infer RootProps, infer CategoryName, infer UserField> ? {
|
|
464
525
|
props: PropsOrParams;
|
|
465
|
-
rootProps: RootProps
|
|
526
|
+
rootProps: WithDefaultRootFieldProps<RootProps>;
|
|
466
527
|
categoryNames: CategoryName;
|
|
467
528
|
field: UserField extends {
|
|
468
529
|
type: string;
|
|
@@ -545,6 +606,8 @@ type UiState = {
|
|
|
545
606
|
expanded?: boolean;
|
|
546
607
|
}>;
|
|
547
608
|
isDragging: boolean;
|
|
609
|
+
/** Outline items whose children are shown, keyed by item id */
|
|
610
|
+
itemExpanded?: Record<string, boolean>;
|
|
548
611
|
viewports: {
|
|
549
612
|
current: {
|
|
550
613
|
width: number | "100%";
|
|
@@ -553,6 +616,7 @@ type UiState = {
|
|
|
553
616
|
controlsVisible: boolean;
|
|
554
617
|
options: Viewport[];
|
|
555
618
|
};
|
|
619
|
+
expandedFieldGroups: Record<string, boolean>;
|
|
556
620
|
field: {
|
|
557
621
|
focus?: string | null;
|
|
558
622
|
metadata?: Record<string, any>;
|
|
@@ -655,10 +719,12 @@ type Overrides<UserConfig extends Config = Config> = OverridesGeneric<{
|
|
|
655
719
|
children: ReactNode;
|
|
656
720
|
isLoading: boolean;
|
|
657
721
|
itemSelector?: ItemSelector | null;
|
|
722
|
+
fields: Partial<Record<string, ReactNode>>;
|
|
658
723
|
}>;
|
|
659
724
|
fieldLabel: RenderFunc<{
|
|
660
725
|
children?: ReactNode;
|
|
661
726
|
icon?: ReactNode;
|
|
727
|
+
endIcon?: ReactNode;
|
|
662
728
|
label: string;
|
|
663
729
|
el?: "label" | "div";
|
|
664
730
|
readOnly?: boolean;
|
|
@@ -690,12 +756,12 @@ type Overrides<UserConfig extends Config = Config> = OverridesGeneric<{
|
|
|
690
756
|
}>;
|
|
691
757
|
type FieldRenderFunctions<UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>, UserField extends {
|
|
692
758
|
type: string;
|
|
693
|
-
} = Field | G["UserField"]> =
|
|
759
|
+
} = Field | G["UserField"]> = {
|
|
694
760
|
[Type in UserField["type"]]: React.FunctionComponent<FieldProps<ExtractField<UserField, Type>, any> & {
|
|
695
761
|
children: ReactNode;
|
|
696
762
|
name: string;
|
|
697
|
-
}
|
|
698
|
-
}
|
|
763
|
+
}> | null;
|
|
764
|
+
};
|
|
699
765
|
|
|
700
766
|
type DragAxis = "dynamic" | "y" | "x";
|
|
701
767
|
|